Beispiel #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);
	}
}
Beispiel #2
0
/**
* @brief 可充电电池监测
*/
static void BatteryMonitor(void)
{
#define VOL_CHARGE		4800
#define VOL_UNCHARGE	5700
#define VOL_BATLOW		3000
#define VOL_BATBAD		5810
#define BATCAP_CHK		((VOL_UNCHARGE-VOL_CHARGE)/8)

	int batv = ReadBatVol();

	if(batv < VOL_BATLOW) {  // 没插电池
		BatCapacityStatus = 0;
		//GpioSetValue(GPIO_BAT_CHARGE, 0);  //停止充电
		if(0 == RunState.batbad) {
			PrintLog(LOGTYPE_ALARM, "battery disconnected!\n");
			RunStateModify()->batbad = 1;
		}
		/*if(RunState.batcharge) {
			PrintLog(LOGTYPE_ALARM, "battery stop charge\n");
			RunStateModify()->batcharge = 0;
		}*/
		return;
	}
	else if(RunState.batbad) {
		PrintLog(LOGTYPE_ALARM, "battery connected!\n");
		RunStateModify()->batbad = 0;
	}

	

	if(batv < VOL_UNCHARGE) {
		GpioSetValue(GPIO_BAT_CHARGE, 1);  //充电
		if(0 == RunState.batcharge) {
			PrintLog(LOGTYPE_ALARM, "battery start charge\n");
			RunStateModify()->batcharge = 1;
		}
	}
	else {
		GpioSetValue(GPIO_BAT_CHARGE, 0);  //停止充电
		if(RunState.batcharge) {
			PrintLog(LOGTYPE_ALARM, "battery stop charge\n");
			RunStateModify()->batcharge = 0;
		}
	}

	if(batv <= (VOL_CHARGE+BATCAP_CHK)) BatCapacityStatus = 0;
	else if(batv >= (VOL_UNCHARGE-BATCAP_CHK)) BatCapacityStatus = 3;
	else if(batv < ((VOL_UNCHARGE+VOL_CHARGE)/2)) BatCapacityStatus = 1;
	else BatCapacityStatus = 2;
}
Beispiel #3
0
void SysPowerDown(void)
{
	SysCycleSave(1);
	SysLockHalt();

	EnableFeedWatchdog(0);
	GpioSetValue(GPIO_POWER_12V, 0);
	GpioSetValue(GPIO_POWER_BAT, 0);

	Sleep(500);
	reboot(LINUX_REBOOT_CMD_RESTART);

	Sleep(500);
	exit(0);
}
Beispiel #4
0
uint8_t LcdWriteImagePng(LcdSpi* lcd, const char *filename)
{
	uint16_t x = 100;
	uint16_t y = 100;
	uint16_t xm = 0;
	uint16_t ym = 0;
	uint16_t i = 0;
	int c;
	gdImagePtr img;
	FILE *filePtr;
	uint8_t b;
	
	if (!lcd) {
		return 1;
	}
	if (!filename) {
		return 2;
	}

	filePtr = fopen(filename, "rb");
	if (filePtr == NULL) {
		return 3;
	}
	img = gdImageCreateFromPng(filePtr);
	if (img == NULL) {
		return 4;
	}
	xm = gdImageSX(img);
	ym = gdImageSY(img);
	printf("%i x %i\n", xm, ym);
	
	if (xm != 132 || ym != 32) {
		return 5;
	}
	
	for (y = 0; y < ym; y += 8) {
		LcdSetPos(lcd, y / 8, 0);
		
		GpioSetValue(PIN_LCD_A0, 1);
		for (x = 0; x < xm; x++) {
			b = 0;
			for (i = 0; i < 8; i++) {
				c = gdImageGetPixel(img, x, y + i);
				if (img->red[c] < 0x7f || img->green[c] < 0x7f || img->blue[c] < 0x7f) {
				//if (c) {
					b |= (1 << i);
				}
			}
			LcdWriteByte(lcd->mS0, b);
		}
	}
	fclose(filePtr);
	gdImageDestroy(img);
	
	return 0;
}
Beispiel #5
0
void LcdSetPos(LcdSpi* lcd, uint8_t page, uint8_t col)
{
	if (!lcd) {
		return;
	}
	GpioSetValue(PIN_LCD_A0, 0);
	LcdWriteByte(lcd->mS0, 0xB0 + page);
	LcdWriteByte(lcd->mS0, 0x10 + ((col >> 4) & 0xf0));
	LcdWriteByte(lcd->mS0, 0x00 + (col & 0x0f));
}
Beispiel #6
0
void LcdCls(LcdSpi* lcd)
{
	uint8_t i;
	uint8_t j;
	
	if (!lcd) {
		return;
	}
	
	for (i = 0; i < 8; i++) {
		LcdSetPos(lcd, i, 0);
		
		GpioSetValue(PIN_LCD_A0, 1);
		for (j = 0; j < 132; j++) {
			LcdWriteByte(lcd->mS0, 0x00);
		}
	}
}
Beispiel #7
0
uint8_t LcdWriteImageScreen(LcdSpi* lcd, ScreenData *screen)
{
	uint8_t x = 0;
	uint8_t y = 0;
	uint16_t i = 0;
	uint8_t c;
	uint8_t b;
	uint8_t xScreen;
	uint8_t yScreen;
	
	if (!lcd) {
		return 1;
	}
	if (!screen) {
		return 2;
	}
	xScreen = screen->mX;
	yScreen = screen->mY;
	
	for (y = 0; y < yScreen; y += 8) {
		LcdSetPos(lcd, y / 8, 0);
		
		GpioSetValue(PIN_LCD_A0, 1);
		for (x = 0; x < xScreen; x++) {
			b = 0;
			for (i = 0; i < 8; i++) {
				c = screen->mData[((y + i) * xScreen) + x];
				if (c) {
					b |= (1 << i);
				}
			}
			LcdWriteByte(lcd->mS0, b);
		}
	}
	if (gDebuglevel >= 100) {
		DebugWriteScreen(lcd, screen->mData, xScreen, yScreen);
	}
	
	return 0;
}
Beispiel #8
0
void LcdSetBgLight(LcdSpi* lcd, uint8_t r, uint8_t g, uint8_t b)
{
	if (!lcd) {
		return;
	}
	lcd->mRed = r ? 0xFF : 0x00;
	lcd->mGreen = g ? 0xFF : 0x00;
	lcd->mBlue = b ? 0xFF : 0x00;	
	if (r) {
		GpioSetValue(PIN_LED_RED, 1);
	} else {
		GpioSetValue(PIN_LED_RED, 0);
	}
	if (g) {
		GpioSetValue(PIN_LED_GREEN, 1);
	} else {
		GpioSetValue(PIN_LED_GREEN, 0);
	}
	if (b) {
		GpioSetValue(PIN_LED_BLUE, 1);
	} else {
		GpioSetValue(PIN_LED_BLUE, 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;
}