Mercurial > ~darius > hgwebdir.cgi > stm32temp
annotate main.c @ 16:db6011aa94d6
Use new delay routine on pin 2 so it doesn't interfere with 1 wire.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Wed, 14 Nov 2012 12:30:05 +1030 |
parents | 96c345d304af |
children | d078651f5353 |
rev | line source |
---|---|
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
1 #include <ctype.h> |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
2 #include <malloc.h> |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
3 #include <stdio.h> |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
4 #include <stdint.h> |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
5 #include <time.h> |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
6 #include <string.h> |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
7 #include <sys/time.h> |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
8 #include <stdlib.h> |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
9 |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
10 #include "stm32f10x.h" |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
7
diff
changeset
|
11 |
13 | 12 #include "1wire.h" |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
7
diff
changeset
|
13 #include "comm.h" |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
7
diff
changeset
|
14 #include "delay.h" |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
7
diff
changeset
|
15 #include "flash.h" |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
7
diff
changeset
|
16 #include "hw.h" |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
17 #include "lcd.h" |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
18 #include "main.h" |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
7
diff
changeset
|
19 #include "touch.h" |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
20 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
21 typedef struct { |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
22 char buf[40]; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
23 volatile uint8_t state; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
24 uint8_t len; |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
25 } consbuf_t; |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
26 |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
27 void NVIC_Configuration(void); |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
28 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
29 |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
30 /* Called every 1 / TICK_FREQ */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
31 #define TICK_FREQ 10000 |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
32 RAMFUNC void |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
33 SysTick_Handler(void) { |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
34 static uint32_t tick = 0; |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
35 static int led = 0; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
36 |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
37 tick++; |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
38 if (tick % 10000 == 0) { |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
39 led = !led; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
40 if (led) |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
41 GPIO_SetBits(GPIOB, GPIO_Pin_5); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
42 else |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
43 GPIO_ResetBits(GPIOB, GPIO_Pin_5); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
44 } |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
45 |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
46 } |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
47 |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
48 consbuf_t cmd; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
49 |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
50 RAMFUNC void |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
51 USART1_IRQHandler(void) { |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
52 char c; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
53 int i; |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
54 |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
55 /* Recieved data */ |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
56 while (USART_GetITStatus(USART1, USART_IT_RXNE) != RESET) { |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
57 c = USART_ReceiveData(USART1); |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
58 |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
59 /* End of line? */ |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
60 if (c == '\n' || c == '\r') { |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
61 cmd.buf[cmd.state] = '\0'; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
62 fputs("\r\n", stdout); |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
63 cmd.len = cmd.state; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
64 cmd.state = 255; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
65 continue; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
66 } |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
67 |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
68 /* Ctrl-w / Ctrl-u */ |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
69 if (c == 0x17 || c == 0x15) { |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
70 for (i = 0; i < cmd.state; i++) |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
71 fputs("\010\040\010", stdout); |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
72 cmd.state = 0; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
73 continue; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
74 } |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
75 |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
76 /* Backspace/delete */ |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
77 if (c == 0x08 || c == 0x7f) { |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
78 if (cmd.state > 0) { |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
79 cmd.state--; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
80 fputs("\010\040\010", stdout); |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
81 } |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
82 continue; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
83 } |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
84 |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
85 /* Anything unprintable just ignore it */ |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
86 if (!isprint(c)) |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
87 continue; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
88 |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
89 cmd.buf[cmd.state] = tolower(c); |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
90 |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
91 /* Echo back to the user */ |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
92 comm_put(cmd.buf[cmd.state]); |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
93 |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
94 cmd.state++; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
95 /* Over flow? */ |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
96 if (cmd.state == ((sizeof(cmd.buf) / sizeof(cmd.buf[0])) - 1)) { |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
97 fputs("\r\nLine too long", stdout); |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
98 cmd.state = 0; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
99 continue; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
100 } |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
101 } |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
102 } |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
103 |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
104 |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
105 int |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
106 main(void) { |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
107 char buf[40]; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
108 struct tm nowtm; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
109 time_t now; |
12
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
110 uint16_t x, y, x1, y1, z1, z2, r, c, rx, ry; |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
111 float t, t2; |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
112 char col; |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
113 |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
114 cmd.state = cmd.len = 0; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
115 |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
7
diff
changeset
|
116 /* Init hardware - configure IO ports and external peripherals */ |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
7
diff
changeset
|
117 hw_init(); |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
118 |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
119 /* NVIC configuration */ |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
120 NVIC_Configuration(); |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
121 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
122 /* Setup SysTick Timer rate, also enables Systick and Systick-Interrupt */ |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
123 if (SysTick_Config(SystemCoreClock / TICK_FREQ)) { |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
124 /* Capture error */ |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
125 comm_puts("Can't setup SysTick\r\n"); |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
126 while (1) |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
127 ; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
128 } |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
129 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
130 /* Set stdout to unbuffered */ |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
131 setvbuf(stdout, NULL, _IONBF, 0); |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
132 |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
133 /* Say hello */ |
7
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
134 fputs("\r\n\r\n\r\nHello world\r\n", stdout); |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
135 |
12
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
136 lcd_stripes(); |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
137 |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
138 lcd_circle(20, 20, 20, 1, LCD_RED); /* Bottom left */ |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
139 lcd_circle(300, 220, 20, 1, LCD_WHITE); /* Top right */ |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
140 lcd_circle(20, 220, 20, 1, LCD_BLUE); /* Top left */ |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
141 lcd_circle(300, 20, 20, 1, LCD_GREEN); /* Bottom right */ |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
142 |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
143 lcd_line(20, 20, 20, 220, LCD_BLACK); |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
144 lcd_line(20, 220, 300, 220, LCD_BLACK); |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
145 lcd_line(300, 220, 300, 20, LCD_BLACK); |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
146 lcd_line(300, 20, 20, 20, LCD_BLACK); |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
147 |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
148 lcd_ellipse(160, 120, 50, 30, 1, LCD_WHITE); |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
149 lcd_ellipse(160, 120, 30, 50, 1, LCD_WHITE); |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
150 |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
151 while (1) { |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
152 fputs("> ", stdout); |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
153 |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
154 while (cmd.state != 255) |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
155 ; |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
156 |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
157 if (cmd.len > 0) { |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
158 if (!strncmp("gc", cmd.buf, 2)) { |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
159 now = time(NULL); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
160 gmtime_r(&now, &nowtm); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
161 strftime(buf, sizeof(buf) - 1, "Time is %Y/%m/%d %H:%M:%S UTC", &nowtm); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
162 printf("Time is %s (%d)\r\n", buf, (int)now); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
163 } else if (!strncmp("sc ", cmd.buf, 3)) { |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
164 struct timeval tv; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
165 tv.tv_sec = atoi(cmd.buf + 3); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
166 tv.tv_usec = 0; |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
167 settimeofday(&tv, NULL); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
168 } else if (!strncmp("read", cmd.buf, 4)) { |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
169 printf("PB5 = %d\r\n", GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_15)); |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
170 } else if (!strncmp("touch", cmd.buf, 5)) { |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
171 for (int i = 0; i < 10; i++) { |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
7
diff
changeset
|
172 tp_getcoords(&x, &y, &z1, &z2, &t, &t2); |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
173 printf("X = %5d Y = %5d Z1 = %5d Z2 = %5d T = %7.2f T2 = %7.2f\r\n", x, y, z1, z2, t, t2); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
174 } |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
175 } else if (!strncmp("fl", cmd.buf, 2)) { |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
176 uint8_t status; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
177 char *flstattbl[] = { |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
178 "BUSY", |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
179 "WEL", |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
180 "BP0", |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
181 "BP1", |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
182 "BP2", |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
183 "BP3", |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
184 "AAI", |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
185 "BPL" |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
186 }; |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
187 |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
7
diff
changeset
|
188 printf("Flash ID = 0x%04hx (expect 0xbf41)\r\n", flashreadid()); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
7
diff
changeset
|
189 status = flashreadstatus(); |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
190 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
191 fputs("Status = ", stdout); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
192 for (unsigned int i = 0; i < sizeof(flstattbl) / sizeof(flstattbl[0]); i++) |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
193 if (status & 1 << i) { |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
194 fputs(flstattbl[i], stdout); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
195 fputs(" ", stdout); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
196 } |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
197 printf("(0x%02x)\r\n", status); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
198 |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
7
diff
changeset
|
199 flashwritestatus(0x00); |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
200 |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
7
diff
changeset
|
201 status = flashreadstatus(); |
4
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
202 |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
203 fputs("Status = ", stdout); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
204 for (unsigned int i = 0; i < sizeof(flstattbl) / sizeof(flstattbl[0]); i++) |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
205 if (status & 1 << i) { |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
206 fputs(flstattbl[i], stdout); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
207 fputs(" ", stdout); |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
208 } |
2c87e30c982d
Add LCD init, touch screen writing etc..
Daniel O'Connor <darius@dons.net.au>
parents:
3
diff
changeset
|
209 printf("(0x%02x)\r\n", status); |
5
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
210 } else if (!strncmp("pwm ", cmd.buf, 4)) { |
efa2c22266e3
PWM control LED backlight.
Daniel O'Connor <darius@dons.net.au>
parents:
4
diff
changeset
|
211 lcd_setpwm(atoi(cmd.buf + 4)); |
7
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
212 } else if (!strncmp("timing", cmd.buf, 6)) { |
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
213 fputs("Timing..\r\n", stdout); |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
7
diff
changeset
|
214 delay(10000); |
7
9404b9869c27
Make the LCD panel work (timings, GPIOE clock needs to be on, etc)
Daniel O'Connor <darius@dons.net.au>
parents:
5
diff
changeset
|
215 fputs("Done\r\n", stdout); |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
7
diff
changeset
|
216 } else if (!strncmp("circ ", cmd.buf, 5)) { |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
7
diff
changeset
|
217 if (sscanf(cmd.buf, "circ %hu %hu %hu %c", &x, &y, &r, &col) != 4) { |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
7
diff
changeset
|
218 printf("Unable to parse circ args\r\n"); |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
7
diff
changeset
|
219 goto out; |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
7
diff
changeset
|
220 } |
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
7
diff
changeset
|
221 |
12
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
222 c = lcd_parsecol(col); |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
223 lcd_circle(x, y, r, 0, c); |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
224 } else if (!strncmp("ellip ", cmd.buf, 6)) { |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
225 if (sscanf(cmd.buf, "ellip %hu %hu %hu %hu %c", &x, &y, &rx, &ry, &col) != 5) { |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
226 printf("Unable to parse circ args\r\n"); |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
227 goto out; |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
228 } |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
229 |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
230 c = lcd_parsecol(col); |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
231 lcd_ellipse(x, y, rx, ry, 0, c); |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
232 } else if (!strncmp("line ", cmd.buf, 5)) { |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
233 if (sscanf(cmd.buf, "line %hu %hu %hu %hu %c", &x, &y, &x1, &y1, &col) != 5) { |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
234 printf("Unable to parse line args\r\n"); |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
235 goto out; |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
236 } |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
237 |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
238 c = lcd_parsecol(col); |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
239 lcd_line(x, y, x1, y1, c); |
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
240 } else if (!strncmp("delay", cmd.buf, 5)) { |
16
db6011aa94d6
Use new delay routine on pin 2 so it doesn't interfere with 1 wire.
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
241 GPIO_InitTypeDef GPIO_InitStructure; |
db6011aa94d6
Use new delay routine on pin 2 so it doesn't interfere with 1 wire.
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
242 |
db6011aa94d6
Use new delay routine on pin 2 so it doesn't interfere with 1 wire.
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
243 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; |
db6011aa94d6
Use new delay routine on pin 2 so it doesn't interfere with 1 wire.
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
244 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; |
db6011aa94d6
Use new delay routine on pin 2 so it doesn't interfere with 1 wire.
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
245 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; |
db6011aa94d6
Use new delay routine on pin 2 so it doesn't interfere with 1 wire.
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
246 GPIO_Init(GPIOE, &GPIO_InitStructure); |
db6011aa94d6
Use new delay routine on pin 2 so it doesn't interfere with 1 wire.
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
247 |
12
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
248 for (x = 0; x < 100; x++) { |
16
db6011aa94d6
Use new delay routine on pin 2 so it doesn't interfere with 1 wire.
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
249 GPIO_SetBits(GPIOE, GPIO_Pin_2); |
db6011aa94d6
Use new delay routine on pin 2 so it doesn't interfere with 1 wire.
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
250 delay(30); |
db6011aa94d6
Use new delay routine on pin 2 so it doesn't interfere with 1 wire.
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
251 GPIO_ResetBits(GPIOE, GPIO_Pin_2); |
db6011aa94d6
Use new delay routine on pin 2 so it doesn't interfere with 1 wire.
Daniel O'Connor <darius@dons.net.au>
parents:
13
diff
changeset
|
252 delay(60); |
12
093bc0c3b1cc
Add delay, ellipse and line demos.
Daniel O'Connor <darius@dons.net.au>
parents:
8
diff
changeset
|
253 } |
13 | 254 } else if (!strncmp("rs", cmd.buf, 2)) { |
255 printf("Reset got %d\r\n", OWTouchReset()); | |
256 } else if (!strncmp("sr", cmd.buf, 2)) { | |
257 uint8_t ROM[8]; | |
258 int8_t i; | |
259 | |
260 memset(ROM, 0, 8); | |
261 | |
262 i = OWFirst(ROM, 1, 0); | |
263 do { | |
264 switch (i) { | |
265 case OW_NOMODULES: | |
266 case OW_FOUND: | |
267 break; | |
268 | |
269 case OW_BADWIRE: | |
270 case OW_NOPRESENCE: | |
271 case OW_BADCRC: | |
272 default: | |
273 printf("Err %d\r\n", i); | |
274 break; | |
275 } | |
276 | |
277 if (i != OW_FOUND) | |
278 break; | |
279 | |
280 for (i = 0; i < 8; i++) | |
281 printf("%02x%s", ROM[i], i == 7 ? "\r\n" : ":"); | |
282 | |
283 i = OWNext(ROM, 1, 0); | |
284 } while (1); | |
285 } else if (!strncmp("rb", cmd.buf, 2)) { | |
286 printf("Read bit returned %d\r\n", OWReadBit()); | |
287 } else if (!strncmp("wb ", cmd.buf, 3)) { | |
288 x = atoi(cmd.buf + 3); | |
289 OWWriteBit(x); | |
290 printf("Wrote %d\r\n", x); | |
291 } else if (!strncasecmp(cmd.buf, "te ", 3)) { | |
292 uint8_t ROM[8]; | |
293 int16_t res; | |
294 | |
295 if (sscanf(cmd.buf, "te %hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", | |
296 &ROM[0], &ROM[1], &ROM[2], &ROM[3], | |
297 &ROM[4], &ROM[5], &ROM[6], &ROM[7]) != 8) { | |
298 printf("Unable to parse ROM ID\r\n"); | |
299 goto out; | |
300 } | |
301 | |
302 res = OWGetTemp(ROM); | |
303 switch (res) { | |
304 case OW_TEMP_WRONG_FAM: | |
305 printf("ROM specified isn't a temperature sensor\r\n"); | |
306 break; | |
307 | |
308 case OW_TEMP_CRC_ERR: | |
309 printf("CRC mismatch\r\n"); | |
310 break; | |
311 | |
312 case OW_TEMP_NO_ROM: | |
313 printf("No ROM found\r\n"); | |
314 break; | |
315 | |
316 default: | |
317 printf("%hd.%02hd\r\n", GETWHOLE(res), GETFRAC(res)); | |
318 break; | |
319 } | |
3
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
320 } else if (!strncmp("zz", cmd.buf, 2)) { |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
321 NVIC_SystemReset(); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
322 } else { |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
323 printf("Unknown command\r\n"); |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
324 } |
74e9b3baac1e
Jumbo commit to make things work.
Daniel O'Connor <darius@dons.net.au>
parents:
2
diff
changeset
|
325 } |
8
58d76cf522ff
Split out code into separate files.
Daniel O'Connor <darius@dons.net.au>
parents:
7
diff
changeset
|
326 out: |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
327 cmd.state = 0; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
328 } |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
329 } |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
330 |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
331 /* Configure interrupt controller */ |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
332 #ifdef VECT_TAB_RAM |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
333 /* vector-offset (TBLOFF) from bottom of SRAM. defined in linker script */ |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
334 extern uint32_t _isr_vectorsram_offs; |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
335 #else |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
336 extern uint32_t _isr_vectorsflash_offs; |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
337 #endif |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
338 |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
339 void |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
340 NVIC_Configuration(void) { |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
341 NVIC_InitTypeDef NVIC_InitStructure; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
342 |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
343 #ifdef VECT_TAB_RAM |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
344 /* Set the Vector Table base location at 0x20000000+_isr_vectorsram_offs */ |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
345 NVIC_SetVectorTable(NVIC_VectTab_RAM, (uint32_t)&_isr_vectorsram_offs); |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
346 #else |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
347 /* Set the Vector Table base location at 0x08000000+_isr_vectorsflash_offs */ |
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
348 NVIC_SetVectorTable(NVIC_VectTab_FLASH, (uint32_t)&_isr_vectorsflash_offs); |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
349 #endif |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
350 |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
351 /* Enable the USART1 Interrupt */ |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
352 NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
353 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
354 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; |
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
355 NVIC_Init(&NVIC_InitStructure); |
0
c59513fd84fb
Initial commit of STM32 test code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
356 } |
2
274e01fa5a4c
- Do console IO with RX IRQs.
Daniel O'Connor <darius@dons.net.au>
parents:
0
diff
changeset
|
357 |