comparison 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
comparison
equal deleted inserted replaced
3:74e9b3baac1e 4:2c87e30c982d
125 /* Set stdout to unbuffered */ 125 /* Set stdout to unbuffered */
126 setvbuf(stdout, NULL, _IONBF, 0); 126 setvbuf(stdout, NULL, _IONBF, 0);
127 127
128 /* Say hello */ 128 /* Say hello */
129 fputs("\r\nHello world\r\n", stdout); 129 fputs("\r\nHello world\r\n", stdout);
130
131 #define Bank1_LCD_D ((uint32_t)0x60020000) //disp Data ADDR
132 #define Bank1_LCD_C ((uint32_t)0x60000000) //disp Reg ADDR
133 130
134 while (1) { 131 while (1) {
135 fputs("> ", stdout); 132 fputs("> ", stdout);
136 133
137 while (cmd.state != 255) 134 while (cmd.state != 255)
147 struct timeval tv; 144 struct timeval tv;
148 tv.tv_sec = atoi(cmd.buf + 3); 145 tv.tv_sec = atoi(cmd.buf + 3);
149 tv.tv_usec = 0; 146 tv.tv_usec = 0;
150 settimeofday(&tv, NULL); 147 settimeofday(&tv, NULL);
151 } else if (!strncmp("lcd", cmd.buf, 3)) { 148 } else if (!strncmp("lcd", cmd.buf, 3)) {
152 *(__IO uint16_t *) (Bank1_LCD_C) = 0x00; 149 printf("LCD ID = %hx\r\n", LCD_RD_Reg(0x00));
153 printf("LCD ID = %hx\r\n", *(__IO uint16_t *) (Bank1_LCD_D));
154 } else if (!strncmp("read", cmd.buf, 4)) { 150 } else if (!strncmp("read", cmd.buf, 4)) {
155 printf("PB5 = %d\r\n", GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_15)); 151 printf("PB5 = %d\r\n", GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_15));
152 } else if (!strncmp("touch", cmd.buf, 5)) {
153 for (int i = 0; i < 10; i++) {
154 uint16_t x, y, z1, z2;
155 float t, t2;
156
157 x = TPRead(TP_READ_SEL(TP_CHAN_X, TP_MODE_12, TP_REF_DIFF, TP_PD_ON));
158 y = TPRead(TP_READ_SEL(TP_CHAN_Y, TP_MODE_12, TP_REF_DIFF, TP_PD_ON));
159 z1 = TPRead(TP_READ_SEL(TP_CHAN_Z1, TP_MODE_12, TP_REF_DIFF, TP_PD_ON));
160 z2 = TPRead(TP_READ_SEL(TP_CHAN_Z2, TP_MODE_12, TP_REF_DIFF, TP_PD_ON));
161 t = ((float)x / 4096.0) * (((float)z2 / (float)z1) - 1);
162 t2 = (((float)x / 4096) * ((4096.0 / (float)z1) - 1)) - (1 - ((float)y / (float)4096.0));
163 printf("X = %5d Y = %5d Z1 = %5d Z2 = %5d T = %7.2f T2 = %7.2f\r\n", x, y, z1, z2, t, t2);
164 }
165 } else if (!strncmp("fl", cmd.buf, 2)) {
166 uint8_t status;
167 char *flstattbl[] = {
168 "BUSY",
169 "WEL",
170 "BP0",
171 "BP1",
172 "BP2",
173 "BP3",
174 "AAI",
175 "BPL"
176 };
177
178 printf("Flash ID = 0x%04hx (expect 0xbf41)\r\n", FlashReadID());
179 status = FlashReadStatus();
180
181 fputs("Status = ", stdout);
182 for (unsigned int i = 0; i < sizeof(flstattbl) / sizeof(flstattbl[0]); i++)
183 if (status & 1 << i) {
184 fputs(flstattbl[i], stdout);
185 fputs(" ", stdout);
186 }
187 printf("(0x%02x)\r\n", status);
188
189 FlashWriteStatus(0x00);
190
191 status = FlashReadStatus();
192
193 fputs("Status = ", stdout);
194 for (unsigned int i = 0; i < sizeof(flstattbl) / sizeof(flstattbl[0]); i++)
195 if (status & 1 << i) {
196 fputs(flstattbl[i], stdout);
197 fputs(" ", stdout);
198 }
199 printf("(0x%02x)\r\n", status);
156 } else if (!strncmp("zz", cmd.buf, 2)) { 200 } else if (!strncmp("zz", cmd.buf, 2)) {
157 NVIC_SystemReset(); 201 NVIC_SystemReset();
158 } else { 202 } else {
159 printf("Unknown command\r\n"); 203 printf("Unknown command\r\n");
160 } 204 }
209 253
210 /* Wait until last write operation on RTC registers has finished */ 254 /* Wait until last write operation on RTC registers has finished */
211 RTC_WaitForLastTask(); 255 RTC_WaitForLastTask();
212 256
213 /* Clock setup */ 257 /* Clock setup */
214 /* Enable clocks we need */ 258 RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
215 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
216 RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
217 RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);
218 259
219 /* Port configuration */ 260 /* Port configuration */
220 /* Configure USART1 TX (PA.09) as alternate function push-pull */ 261 /* Configure USART1 TX (PA.09) as alternate function push-pull */
221 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; 262 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
222 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 263 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
226 /* Configure USART1 RX (PA.10) as input floating */ 267 /* Configure USART1 RX (PA.10) as input floating */
227 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; 268 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
228 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; 269 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
229 GPIO_Init(GPIOA, &GPIO_InitStructure); 270 GPIO_Init(GPIOA, &GPIO_InitStructure);
230 271
231 /* Configure PB5 as output push-pull */ 272 /* Enable GPIOB clock */
273 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
274
275 /* Configure PB5 as output push-pull for LED */
232 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; 276 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
233 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 277 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
234 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 278 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
235 GPIO_Init(GPIOB, &GPIO_InitStructure); 279 GPIO_Init(GPIOB, &GPIO_InitStructure);
236 280
237 /* Configure PB15 as input pull-up push-pull */ 281 /* Configure PB15 as input pull-up push-pull for push button */
238 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15; 282 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
239 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 283 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
240 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; 284 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
241 GPIO_Init(GPIOB, &GPIO_InitStructure); 285 GPIO_Init(GPIOB, &GPIO_InitStructure);
242 286