diff main.c @ 4:2c87e30c982d

Add LCD init, touch screen writing etc.. PWM of LCD backlight doesn't work yet though..
author Daniel O'Connor <darius@dons.net.au>
date Tue, 03 Jan 2012 22:37:18 +1030
parents 74e9b3baac1e
children efa2c22266e3
line wrap: on
line diff
--- a/main.c	Sun Jan 01 11:01:13 2012 +1030
+++ b/main.c	Tue Jan 03 22:37:18 2012 +1030
@@ -128,9 +128,6 @@
     /* Say hello */
     fputs("\r\nHello world\r\n", stdout);
     
-#define Bank1_LCD_D    ((uint32_t)0x60020000)    //disp Data ADDR
-#define Bank1_LCD_C    ((uint32_t)0x60000000)    //disp Reg ADDR
-    
     while (1) {
 	fputs("> ", stdout);
 	
@@ -149,10 +146,57 @@
 		tv.tv_usec = 0;
 		settimeofday(&tv, NULL);
 	    } else if (!strncmp("lcd", cmd.buf, 3)) {
-		*(__IO uint16_t *) (Bank1_LCD_C) = 0x00;
-		printf("LCD ID = %hx\r\n", *(__IO uint16_t *) (Bank1_LCD_D));
+		printf("LCD ID = %hx\r\n", LCD_RD_Reg(0x00));
 	    } else if (!strncmp("read", cmd.buf, 4)) {
 		printf("PB5 = %d\r\n", GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_15));
+	    } else if (!strncmp("touch", cmd.buf, 5)) {
+		for (int i = 0; i < 10; i++) {
+		    uint16_t	x, y, z1, z2;
+		    float	t, t2;
+		    
+		    x = TPRead(TP_READ_SEL(TP_CHAN_X, TP_MODE_12, TP_REF_DIFF, TP_PD_ON));
+		    y = TPRead(TP_READ_SEL(TP_CHAN_Y, TP_MODE_12, TP_REF_DIFF, TP_PD_ON));
+		    z1 = TPRead(TP_READ_SEL(TP_CHAN_Z1, TP_MODE_12, TP_REF_DIFF, TP_PD_ON));
+		    z2 = TPRead(TP_READ_SEL(TP_CHAN_Z2, TP_MODE_12, TP_REF_DIFF, TP_PD_ON));
+		    t = ((float)x / 4096.0) * (((float)z2 / (float)z1) - 1);
+		    t2 = (((float)x / 4096) * ((4096.0 / (float)z1) - 1)) - (1 - ((float)y / (float)4096.0));
+		    printf("X = %5d Y = %5d Z1 = %5d Z2 = %5d T = %7.2f T2 = %7.2f\r\n", x, y, z1, z2, t, t2);
+		}
+	    } else if (!strncmp("fl", cmd.buf, 2)) {
+		uint8_t status;
+		char *flstattbl[] = {
+		    "BUSY",
+		    "WEL",
+		    "BP0",
+		    "BP1",
+		    "BP2",
+		    "BP3",
+		    "AAI",
+		    "BPL"
+		};
+		
+		printf("Flash ID = 0x%04hx (expect 0xbf41)\r\n", FlashReadID());
+		status = FlashReadStatus();
+
+		fputs("Status = ", stdout);
+		for (unsigned int i = 0; i < sizeof(flstattbl) / sizeof(flstattbl[0]); i++)
+		    if (status & 1 << i) {
+			fputs(flstattbl[i], stdout);
+			fputs(" ", stdout);
+		    }
+		printf("(0x%02x)\r\n", status);
+
+		FlashWriteStatus(0x00);
+		
+		status = FlashReadStatus();
+
+		fputs("Status = ", stdout);
+		for (unsigned int i = 0; i < sizeof(flstattbl) / sizeof(flstattbl[0]); i++)
+		    if (status & 1 << i) {
+			fputs(flstattbl[i], stdout);
+			fputs(" ", stdout);
+		    }
+		printf("(0x%02x)\r\n", status);
 	    } else if (!strncmp("zz", cmd.buf, 2)) {
 		NVIC_SystemReset();
 	    } else {
@@ -211,10 +255,7 @@
     RTC_WaitForLastTask();
 
     /* Clock setup */
-    /* Enable clocks we need */
-    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
-    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
-			   RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);
+    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
 
     /* Port configuration */
     /* Configure USART1 TX (PA.09) as alternate function push-pull */
@@ -228,13 +269,16 @@
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
     GPIO_Init(GPIOA, &GPIO_InitStructure);
 
-    /* Configure PB5 as output push-pull */
+    /* Enable GPIOB clock */
+    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
+
+    /* Configure PB5 as output push-pull for LED */
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
     GPIO_Init(GPIOB, &GPIO_InitStructure);
 
-    /* Configure PB15 as input pull-up push-pull */
+    /* Configure PB15 as input pull-up push-pull for push button */
     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;