Esempio n. 1
0
void LcdInit(LcdSpi* lcd)
{
	uint8_t i;
	// 132x32
	uint8_t initSeqTx[] = {0x40, 0xA1, 0xC0, 0xA6, 0xA2, 0x2F, 0xF8, 0x00, 0x23, 0x81, 0x1F, 0xAC, 0x00, 0xAF};
	// 128x64
	//uint8_t initSeqTx[] = {0x40, 0xA1, 0xC0, 0xA6, 0xA2, 0x2F, 0xF8, 0x00, 0x27, 0x81, 0x10, 0xAC, 0x00, 0xAF};
	
	if (!lcd) {
		return;
	}
	
	GpioExport(PIN_LCD_nRST);
	GpioExport(PIN_LCD_A0);
	
	GpioSetDirection(PIN_LCD_nRST, 1);
	GpioSetDirection(PIN_LCD_A0, 1);

	GpioSetValue(PIN_LCD_nRST, 0);
	usleep(10000);
	GpioSetValue(PIN_LCD_nRST, 1);
	usleep(10000);	
	GpioSetValue(PIN_LCD_A0, 0);
	for (i = 0; i < sizeof(initSeqTx); i++) {
		LcdWriteByte(lcd->mS0, initSeqTx[i]);
		usleep(10000);
	}
}
Esempio n. 2
0
void ButtonInit(void)
{
	GpioExport(PIN_KEY_1);
	GpioExport(PIN_KEY_2);
	GpioExport(PIN_KEY_3);
	GpioSetDirection(PIN_KEY_1, 0);
	GpioSetDirection(PIN_KEY_2, 0);
	GpioSetDirection(PIN_KEY_3, 0);
	GpioSetEdge(PIN_KEY_1, edge_falling);
	GpioSetEdge(PIN_KEY_2, edge_falling);
	GpioSetEdge(PIN_KEY_3, edge_falling);
	
#ifdef RPI_PULLUP
	GpioRpiSetup();
	GpioRpiSetPullUpDown(PIN_KEY_1, PUD_UP);
	GpioRpiSetPullUpDown(PIN_KEY_2, PUD_UP);
	GpioRpiSetPullUpDown(PIN_KEY_3, PUD_UP);
#endif

#ifdef BPI_PULLUP
	GpioSetPullResistor(PIN_KEY_1, pull_up);
	GpioSetPullResistor(PIN_KEY_2, pull_up);
	GpioSetPullResistor(PIN_KEY_3, pull_up);
#endif
}
Esempio n. 3
0
LcdSpi* LcdOpen(Spi* s0)
{
	LcdSpi *lcd;

	lcd = (LcdSpi*)malloc(sizeof(LcdSpi));
	if (!lcd) {
		return NULL;
	}
	lcd->mS0 = s0;
	lcd->mRed = 0;
	lcd->mGreen = 0;
	lcd->mBlue = 0;
	
	// Export Kernel GPIO into Userspace
	GpioExport(PIN_LED_RED);
	GpioExport(PIN_LED_GREEN);
	GpioExport(PIN_LED_BLUE);
	
	GpioSetDirection(PIN_LED_RED, 1);
	GpioSetDirection(PIN_LED_GREEN, 1);
	GpioSetDirection(PIN_LED_BLUE, 1);
	
	return lcd;
}
Esempio n. 4
0
/*
 * Main
 */
int main(int argc, char **argv, char **envp)
{
	struct pollfd fdset[2];
	int nfds = 2;
	int gpioFd, timeout, rc;
	char *buf[maxBuff];
	unsigned int gpio, led;
	bool toggleLED = true;
	int len;

	if (argc < 2) {
		printf("Usage: gpio-int <gpio-pin>\n\n");
		printf("Waits for a change in the GPIO pin voltage level or input on stdin\n");
		exit(-1);
	}

	gpio = atoi(argv[1]);
	led = atoi(argv[2]);
	GpioExport(gpio);
	GpioExport(led);
	GpioSetDir(gpio, 0);
	GpioSetDir(led, 1);
	GpioSetEdge(gpio, "rising");
	gpioFd = GpioFdOpen(gpio);

	timeout = pollTimeout;

	while (1) {
		memset((void*)fdset, 0, sizeof(fdset));

		fdset[0].fd = STDIN_FILENO;
		fdset[0].events = POLLIN;

		fdset[1].fd = gpioFd;
		fdset[1].events = POLLPRI;

		rc = poll(fdset, nfds, timeout);

		if (rc < 0) {
			printf("\npoll() failed!\n");
			return -1;
		}

		if (rc == 0) {
			printf(".");
		}

		if (fdset[1].revents & POLLPRI) {
			len = read(fdset[1].fd, buf, maxBuff);
			printf("\npoll() GPIO %d interrupt occurred\n", gpio);
			if (toggleLED) GpioSetValue(led,0);
			else GpioSetValue(led,1);
			toggleLED =! toggleLED;
		}

		if (fdset[0].revents & POLLIN) {
			(void)read(fdset[0].fd, buf, 1);
			printf("\npoll() stdin read 0x%2.2X\n", (unsigned int) buf[0]);
		}

		fflush(stdout);
	}

	GpioFdClose(gpioFd);
	return 0;
}