Mercurial > public > ostc4
annotate Discovery/Src/display.c @ 686:b1e24513b83e Betatest
Bugfix Battery charge complete event:
In previous version it could happen that the battery charge state was set to 100% even the battery was not completly charged. Rootcause was that the external charger IC signals sometimes completion because e.g. the connection between charger unit and OSTC is disconnected within a short time slot. This may happen while the user is trying to get the OSTC in a good charging position. To avoid this the state machine now checks the voltage everytime for valid charging complete range before a charging complete is signaled.
author | Ideenmodellierer |
---|---|
date | Fri, 05 Aug 2022 14:56:17 +0200 |
parents | 5ca177d2df5d |
children | f7318457df4d |
rev | line source |
---|---|
38 | 1 |
2 #include "stm32f4xx_hal.h" /* for HAL_Delay() */ | |
3 #include "ostc.h" | |
4 #include "display.h" | |
5 | |
6 #define ENABLE_EXTENDED_COMMANDS 0xB9 | |
7 #define SET_POWER 0xB1 | |
8 #define SLEEP_OUT 0x11 | |
9 #define DISPLAY_INVERSION_OFF 0x20 | |
10 #define MEMORY_ACCESS_ONTROL 0x36 | |
11 #define INTERFACE_PIXEL_FORMAT 0x3A | |
12 #define SET_RGB_INTERFACE_RELATED 0xB3 | |
13 #define SET_DISPLAY_WAVEFORM 0xB4 | |
14 #define SET_PANEL 0xCC | |
15 #define SET_GAMMA_CURVE_RELATED 0xE0 | |
16 #define DISPLAY_ON 0x29 | |
17 #define DISPLAY_OFF 0x28 | |
18 #define SLEEP_IN 0x10 | |
19 | |
20 | |
21 static void Display_Error_Handler(void); | |
22 | |
23 void display_power_on__1_of_2__pre_RGB(void) | |
24 { | |
25 /* reset system */ | |
26 HAL_GPIO_WritePin(DISPLAY_CSB_GPIO_PORT,DISPLAY_CSB_PIN,GPIO_PIN_SET); // chip select | |
27 | |
28 HAL_GPIO_WritePin(DISPLAY_RESETB_GPIO_PORT,DISPLAY_RESETB_PIN,GPIO_PIN_RESET); | |
29 HAL_Delay(10); | |
30 HAL_GPIO_WritePin(DISPLAY_RESETB_GPIO_PORT,DISPLAY_RESETB_PIN,GPIO_PIN_SET); | |
31 HAL_Delay(10); | |
32 | |
33 /* RGB signals should be now for 2 frames or more (datasheet) */ | |
34 } | |
35 | |
36 | |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
37 static void send(uint8_t *pData, uint16_t inputlength) |
38 | 38 { |
39 HAL_GPIO_WritePin(DISPLAY_CSB_GPIO_PORT,DISPLAY_CSB_PIN,GPIO_PIN_RESET); // chip select | |
40 | |
41 if(HAL_SPI_Transmit(&hspiDisplay,(uint8_t*)pData, inputlength, 10000) != HAL_OK) | |
42 Display_Error_Handler(); | |
43 | |
44 while (HAL_SPI_GetState(&hspiDisplay) != HAL_SPI_STATE_READY) | |
45 { | |
46 } | |
47 HAL_GPIO_WritePin(DISPLAY_CSB_GPIO_PORT,DISPLAY_CSB_PIN,GPIO_PIN_SET); // chip select | |
48 } | |
49 | |
50 | |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
38
diff
changeset
|
51 static uint16_t convert8to9to8(uint8_t *pInput, uint8_t *pOutput,uint16_t inputlength) |
38 | 52 { |
53 uint16_t outputlength; | |
54 uint8_t readbit = 0x80;//0b1000000; | |
55 uint8_t writebit = 0x40;//0b0100000; | |
56 uint16_t i,j,k; | |
57 | |
58 outputlength = ((inputlength+7)/8)*9; | |
59 | |
60 for(i=0;i<outputlength;i++) | |
61 pOutput[i] = 0; | |
62 | |
63 k = 0; | |
64 for(i=0;i<inputlength;i++) | |
65 { | |
66 if(i != 0) | |
67 { | |
68 pOutput[k] |= writebit; // 9. bit | |
69 writebit = writebit >> 1; | |
70 if(writebit == 0) | |
71 { | |
72 writebit = 0x80; | |
73 k++; | |
74 } | |
75 } | |
76 for(j=0;j<8;j++) | |
77 { | |
78 if((pInput[i] & readbit) != 0) | |
79 { | |
80 pOutput[k] |= writebit; | |
81 } | |
82 readbit = readbit >> 1; | |
83 if(readbit == 0) | |
84 readbit = 0x80; | |
85 writebit = writebit >> 1; | |
86 if(writebit == 0) | |
87 { | |
88 writebit = 0x80; | |
89 k++; | |
90 } | |
91 } | |
92 } | |
93 return outputlength; | |
94 } | |
95 | |
96 void display_power_on__2_of_2__post_RGB(void) | |
97 { | |
98 uint8_t aTxBuffer[32]; | |
99 uint8_t bTxBuffer[36]; | |
100 uint16_t i,length; | |
101 | |
102 for(i=0;i<32;i++) | |
103 aTxBuffer[i] = 0; | |
104 for(i=0;i<36;i++) | |
105 bTxBuffer[i] = 0; | |
106 | |
107 aTxBuffer[0] = ENABLE_EXTENDED_COMMANDS; | |
108 aTxBuffer[1] = 0xFF; | |
109 aTxBuffer[2] = 0x83; | |
110 aTxBuffer[3] = 0x63; | |
111 length = convert8to9to8((uint8_t*)aTxBuffer,(uint8_t*)bTxBuffer,4); | |
112 send((uint8_t*)bTxBuffer, length); | |
113 | |
114 aTxBuffer[0] = SET_POWER; | |
115 aTxBuffer[1] = 0x81; | |
116 aTxBuffer[2] = 0x24; | |
117 aTxBuffer[3] = 0x04; | |
118 aTxBuffer[4] = 0x02; | |
119 aTxBuffer[5] = 0x02; | |
120 aTxBuffer[6] = 0x03; | |
121 aTxBuffer[7] = 0x10; | |
122 aTxBuffer[8] = 0x10; | |
123 aTxBuffer[9] = 0x34; | |
124 aTxBuffer[10] = 0x3C; | |
125 aTxBuffer[11] = 0x3F; | |
126 aTxBuffer[12] = 0x3F; | |
127 length = convert8to9to8((uint8_t*)aTxBuffer,(uint8_t*)bTxBuffer,13); | |
128 send((uint8_t*)bTxBuffer, length); | |
129 | |
130 aTxBuffer[0] = SLEEP_OUT; | |
131 length = convert8to9to8((uint8_t*)aTxBuffer,(uint8_t*)bTxBuffer,1); | |
132 send((uint8_t*)bTxBuffer, length); | |
133 HAL_Delay(5+1); | |
134 | |
135 aTxBuffer[0] = DISPLAY_INVERSION_OFF; | |
136 length = convert8to9to8((uint8_t*)aTxBuffer,(uint8_t*)bTxBuffer,1); | |
137 send((uint8_t*)bTxBuffer, length); | |
138 | |
139 aTxBuffer[0] = MEMORY_ACCESS_ONTROL; | |
140 aTxBuffer[1] = 0x00; | |
141 length = convert8to9to8((uint8_t*)aTxBuffer,(uint8_t*)bTxBuffer,2); | |
142 send((uint8_t*)bTxBuffer, length); | |
143 | |
144 aTxBuffer[0] = INTERFACE_PIXEL_FORMAT; | |
145 aTxBuffer[1] = 0x70; | |
146 length = convert8to9to8((uint8_t*)aTxBuffer,(uint8_t*)bTxBuffer,2); | |
147 send((uint8_t*)bTxBuffer, length); | |
148 HAL_Delay(120+20); | |
149 | |
150 aTxBuffer[0] = SET_POWER; | |
151 aTxBuffer[1] = 0x78; | |
152 aTxBuffer[2] = 0x24; | |
153 aTxBuffer[3] = 0x04, | |
154 aTxBuffer[4] = 0x02; | |
155 aTxBuffer[5] = 0x02; | |
156 aTxBuffer[6] = 0x03; | |
157 aTxBuffer[7] = 0x10; | |
158 aTxBuffer[8] = 0x10; | |
159 aTxBuffer[9] = 0x34; | |
160 aTxBuffer[10] = 0x3C; | |
161 aTxBuffer[11] = 0x3F; | |
162 aTxBuffer[12] = 0x3F; | |
163 length = convert8to9to8((uint8_t*)aTxBuffer,(uint8_t*)bTxBuffer,13); | |
164 send((uint8_t*)bTxBuffer, length); | |
165 | |
166 aTxBuffer[0] = SET_RGB_INTERFACE_RELATED; | |
167 aTxBuffer[1] = 0x01; | |
168 length = convert8to9to8((uint8_t*)aTxBuffer,(uint8_t*)bTxBuffer,2); | |
169 send((uint8_t*)bTxBuffer, length); | |
170 | |
171 aTxBuffer[0] = SET_DISPLAY_WAVEFORM; | |
172 aTxBuffer[1] = 0x00; | |
173 aTxBuffer[2] = 0x08; | |
174 aTxBuffer[3] = 0x56; | |
175 aTxBuffer[4] = 0x07; | |
176 aTxBuffer[5] = 0x01; | |
177 aTxBuffer[6] = 0x01; | |
178 aTxBuffer[7] = 0x4D; | |
179 aTxBuffer[8] = 0x01; | |
180 aTxBuffer[9] = 0x42; | |
181 length = convert8to9to8((uint8_t*)aTxBuffer,(uint8_t*)bTxBuffer,10); | |
182 send((uint8_t*)bTxBuffer, length); | |
183 | |
184 aTxBuffer[0] = SET_PANEL; | |
185 aTxBuffer[1] = 0x0B; | |
186 length = convert8to9to8((uint8_t*)aTxBuffer,(uint8_t*)bTxBuffer,2); | |
187 send((uint8_t*)bTxBuffer, length); | |
188 | |
189 aTxBuffer[0] = SET_GAMMA_CURVE_RELATED; | |
190 aTxBuffer[1] = 0x01; | |
191 aTxBuffer[2] = 0x48; | |
192 aTxBuffer[3] = 0x4D; | |
193 aTxBuffer[4] = 0x4E; | |
194 aTxBuffer[5] = 0x58; | |
195 aTxBuffer[6] = 0xF6; | |
196 aTxBuffer[7] = 0x0B; | |
197 aTxBuffer[8] = 0x4E; | |
198 aTxBuffer[9] = 0x12; | |
199 aTxBuffer[10] = 0xD5; | |
200 aTxBuffer[11] = 0x15; | |
201 aTxBuffer[12] = 0x95; | |
202 aTxBuffer[13] = 0x55; | |
203 aTxBuffer[14] = 0x8E; | |
204 aTxBuffer[15] = 0x11; | |
205 aTxBuffer[16] = 0x01; | |
206 aTxBuffer[17] = 0x48; | |
207 aTxBuffer[18] = 0x4D; | |
208 aTxBuffer[19] = 0x55; | |
209 aTxBuffer[20] = 0x5F; | |
210 aTxBuffer[21] = 0xFD; | |
211 aTxBuffer[22] = 0x0A; | |
212 aTxBuffer[23] = 0x4E; | |
213 aTxBuffer[24] = 0x51; | |
214 aTxBuffer[25] = 0xD3; | |
215 aTxBuffer[26] = 0x17; | |
216 aTxBuffer[27] = 0x95; | |
217 aTxBuffer[28] = 0x96; | |
218 aTxBuffer[29] = 0x4E; | |
219 aTxBuffer[30] = 0x11; | |
220 length = convert8to9to8((uint8_t*)aTxBuffer,(uint8_t*)bTxBuffer,31); | |
221 send((uint8_t*)bTxBuffer, length); | |
222 HAL_Delay(5+1); | |
223 | |
224 aTxBuffer[0] = DISPLAY_ON; | |
225 length = convert8to9to8((uint8_t*)aTxBuffer,(uint8_t*)bTxBuffer,1); | |
226 send((uint8_t*)bTxBuffer, length); | |
227 } | |
228 | |
229 | |
230 static void Display_Error_Handler(void) | |
231 { | |
232 while(1) | |
233 { | |
234 } | |
235 } |