Mercurial > public > ostc4
annotate Discovery/Src/ostc.c @ 309:b0045281cb2d cleanup-4
cleanup: factor out SHelper typedef (and more)
It is totally useless to carry some data around in the SLifeData
global data, that is never used in a significant way. All data
in the SHelper typedef can trivially be changed to static
data in the new setAvgDepth code.
Further, cleanup the setAvgDepth code. Reset to 0 instead of 1,
adapt the references to the new local and static data instead
of pointers to the external data.
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Fri, 24 May 2019 09:29:29 +0200 |
parents | 5ca177d2df5d |
children | 37ee61f93124 |
rev | line source |
---|---|
38 | 1 /////////////////////////////////////////////////////////////////////////////// |
2 /// -*- coding: UTF-8 -*- | |
3 /// | |
4 /// \file Discovery/Src/ostc.c | |
5 /// \brief Hardware specific configuration | |
6 /// \author Heinrichs Weikamp gmbh | |
7 /// \date 05-Dec-2014 | |
8 /// | |
9 /// \details | |
10 /// | |
11 /// $Id$ | |
12 /////////////////////////////////////////////////////////////////////////////// | |
13 /// \par Copyright (c) 2014-2018 Heinrichs Weikamp gmbh | |
14 /// | |
15 /// This program is free software: you can redistribute it and/or modify | |
16 /// it under the terms of the GNU General Public License as published by | |
17 /// the Free Software Foundation, either version 3 of the License, or | |
18 /// (at your option) any later version. | |
19 /// | |
20 /// This program is distributed in the hope that it will be useful, | |
21 /// but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 /// GNU General Public License for more details. | |
24 /// | |
25 /// You should have received a copy of the GNU General Public License | |
26 /// along with this program. If not, see <http://www.gnu.org/licenses/>. | |
27 ////////////////////////////////////////////////////////////////////////////// | |
28 | |
29 /* Includes ------------------------------------------------------------------*/ | |
30 #include "ostc.h" | |
31 #include "stm32f4xx_hal.h" | |
32 | |
33 #ifndef BOOTLOADER_STANDALONE | |
34 #include "tCCR.h" | |
35 #endif | |
36 | |
37 /* Exported variables --------------------------------------------------------*/ | |
38 SPI_HandleTypeDef hspiDisplay; | |
39 SPI_HandleTypeDef cpu2DmaSpi; | |
40 | |
41 | |
42 UART_HandleTypeDef UartHandle; | |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
140
diff
changeset
|
43 #ifdef USART_PIEZO |
38 | 44 UART_HandleTypeDef UartPiezoTxHandle; |
300
5ca177d2df5d
cleanup: remove commented/unused code, make static
Jan Mulder <jlmulder@xs4all.nl>
parents:
140
diff
changeset
|
45 #endif |
38 | 46 UART_HandleTypeDef UartIR_HUD_Handle; |
47 | |
48 __IO ITStatus UartReady = RESET; | |
49 __IO ITStatus UartReadyHUD = RESET; | |
50 | |
51 /* Private types -------------------------------------------------------------*/ | |
52 | |
53 /* Private variables ---------------------------------------------------------*/ | |
54 | |
55 /* Private variables with external access via get_xxx() function -------------*/ | |
56 | |
57 /* Private function prototypes -----------------------------------------------*/ | |
58 | |
59 /* Exported functions --------------------------------------------------------*/ | |
60 | |
61 /** SPI init function | |
62 * called from HAL | |
63 */ | |
64 void MX_SPI_Init(void) | |
65 { | |
66 hspiDisplay.Instance = SPI5; | |
67 hspiDisplay.Init.Mode = SPI_MODE_MASTER; | |
68 hspiDisplay.Init.Direction = SPI_DIRECTION_2LINES; | |
69 hspiDisplay.Init.DataSize = SPI_DATASIZE_8BIT; | |
70 hspiDisplay.Init.CLKPolarity = SPI_POLARITY_LOW; | |
71 hspiDisplay.Init.CLKPhase = SPI_PHASE_1EDGE; | |
72 hspiDisplay.Init.NSS = SPI_NSS_SOFT; | |
73 hspiDisplay.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;//SPI_BAUDRATEPRESCALER_4;//SPI_BAUDRATEPRESCALER_256; | |
74 hspiDisplay.Init.FirstBit = SPI_FIRSTBIT_MSB; | |
75 hspiDisplay.Init.TIMode = SPI_TIMODE_DISABLED; | |
76 hspiDisplay.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED; | |
77 HAL_SPI_Init(&hspiDisplay); | |
78 | |
79 cpu2DmaSpi.Instance = SPI1; | |
80 cpu2DmaSpi.Init.Mode = SPI_MODE_MASTER; | |
81 cpu2DmaSpi.Init.Direction = SPI_DIRECTION_2LINES; | |
82 cpu2DmaSpi.Init.DataSize = SPI_DATASIZE_8BIT; | |
83 cpu2DmaSpi.Init.CLKPolarity = SPI_POLARITY_LOW; | |
84 cpu2DmaSpi.Init.CLKPhase = SPI_PHASE_1EDGE; | |
85 cpu2DmaSpi.Init.NSS = SPI_NSS_SOFT;//SPI_NSS_HARD_OUTPUT;//SPI_NSS_SOFT; | |
140
f6c52eb0e25d
Increase prescalar => frame takes about 4ms.
Ideenmodellierer
parents:
104
diff
changeset
|
86 cpu2DmaSpi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128; |
38 | 87 cpu2DmaSpi.Init.FirstBit = SPI_FIRSTBIT_MSB; |
88 cpu2DmaSpi.Init.TIMode = SPI_TIMODE_DISABLED; | |
89 cpu2DmaSpi.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED; | |
90 cpu2DmaSpi.Init.CRCPolynomial = 7; | |
91 | |
92 HAL_SPI_Init(&cpu2DmaSpi); | |
93 } | |
94 | |
95 void MX_GPIO_Init(void) | |
96 { | |
97 GPIO_InitTypeDef GPIO_InitStruct; | |
98 | |
99 DISPLAY_CSB_GPIO_ENABLE(); | |
100 DISPLAY_RESETB_GPIO_ENABLE(); | |
101 EXTFLASH_CSB_GPIO_ENABLE(); | |
102 SMALLCPU_CSB_GPIO_ENABLE(); | |
103 OSCILLOSCOPE_GPIO_ENABLE(); | |
104 OSCILLOSCOPE2_GPIO_ENABLE(); | |
105 | |
106 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
107 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
108 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
109 | |
110 GPIO_InitStruct.Pin = DISPLAY_CSB_PIN; | |
111 HAL_GPIO_Init(DISPLAY_CSB_GPIO_PORT, &GPIO_InitStruct); | |
112 | |
113 GPIO_InitStruct.Pin = DISPLAY_RESETB_PIN; | |
114 HAL_GPIO_Init(DISPLAY_RESETB_GPIO_PORT, &GPIO_InitStruct); | |
115 | |
116 GPIO_InitStruct.Pin = EXTFLASH_CSB_PIN; | |
117 HAL_GPIO_Init(EXTFLASH_CSB_GPIO_PORT, &GPIO_InitStruct); | |
118 | |
119 GPIO_InitStruct.Pin = OSCILLOSCOPE_PIN; | |
120 HAL_GPIO_Init(OSCILLOSCOPE_GPIO_PORT, &GPIO_InitStruct); | |
121 | |
122 GPIO_InitStruct.Pin = OSCILLOSCOPE2_PIN; | |
123 HAL_GPIO_Init(OSCILLOSCOPE2_GPIO_PORT, &GPIO_InitStruct); | |
124 | |
125 #ifdef DISPLAY_BACKLIGHT_PIN | |
126 DISPLAY_BACKLIGHT_GPIO_ENABLE(); | |
127 GPIO_InitStruct.Pin = DISPLAY_BACKLIGHT_PIN; | |
128 HAL_GPIO_Init(DISPLAY_BACKLIGHT_GPIO_PORT, &GPIO_InitStruct); | |
129 HAL_GPIO_WritePin(DISPLAY_BACKLIGHT_GPIO_PORT,DISPLAY_BACKLIGHT_PIN,GPIO_PIN_SET); | |
130 #endif | |
131 | |
132 #ifdef SMALLCPU_CSB_PIN | |
133 SMALLCPU_CSB_GPIO_ENABLE(); | |
134 GPIO_InitStruct.Pin = SMALLCPU_CSB_PIN; | |
135 HAL_GPIO_Init(SMALLCPU_CSB_GPIO_PORT, &GPIO_InitStruct); | |
136 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET); | |
137 #endif | |
138 | |
139 #ifdef SMALLCPU_BOOT0_PIN | |
140 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
141 SMALLCPU_BOOT0_GPIO_ENABLE(); | |
142 GPIO_InitStruct.Pin = SMALLCPU_BOOT0_PIN; | |
143 HAL_GPIO_Init(SMALLCPU_BOOT0_GPIO_PORT, &GPIO_InitStruct); | |
144 HAL_GPIO_WritePin(SMALLCPU_BOOT0_GPIO_PORT,SMALLCPU_BOOT0_PIN,GPIO_PIN_RESET); | |
145 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
146 #endif | |
147 | |
148 #ifdef IR_HUD_ENABLE_PIN | |
149 IR_HUD_ENABLE_GPIO_ENABLE(); | |
150 GPIO_InitStruct.Pin = IR_HUD_ENABLE_PIN; | |
151 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
152 HAL_GPIO_Init(IR_HUD_ENABLE_GPIO_PORT, &GPIO_InitStruct); | |
153 HAL_GPIO_WritePin(IR_HUD_ENABLE_GPIO_PORT,IR_HUD_ENABLE_PIN,GPIO_PIN_SET); | |
154 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
155 #endif | |
156 | |
157 #ifdef BLE_NENABLE_PIN | |
158 BLE_NENABLE_GPIO_ENABLE(); | |
159 MX_Bluetooth_PowerOff(); | |
160 #endif | |
161 | |
162 #ifdef TESTPIN | |
163 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
164 TEST_GPIO_ENABLE(); | |
165 GPIO_InitStruct.Pin = TEST_PIN; | |
166 HAL_GPIO_Init(TEST_GPIO_PORT, &GPIO_InitStruct); | |
167 HAL_GPIO_WritePin(TEST_GPIO_PORT,TEST_PIN,GPIO_PIN_SET); | |
168 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
169 #endif | |
170 } | |
171 | |
172 | |
173 void MX_TestPin_High(void) | |
174 { | |
175 #ifdef TESTPIN | |
176 HAL_GPIO_WritePin(TEST_GPIO_PORT,TEST_PIN,GPIO_PIN_SET); | |
177 #endif | |
178 } | |
179 | |
180 | |
181 void MX_TestPin_Low(void) | |
182 { | |
183 #ifdef TESTPIN | |
184 HAL_GPIO_WritePin(TEST_GPIO_PORT,TEST_PIN,GPIO_PIN_RESET); | |
185 #endif | |
186 } | |
187 | |
188 void MX_Bluetooth_PowerOn(void) | |
189 { | |
190 GPIO_InitTypeDef GPIO_InitStruct; | |
191 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
192 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
193 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
194 GPIO_InitStruct.Pin = BLE_NENABLE_PIN; | |
195 HAL_GPIO_Init(BLE_NENABLE_GPIO_PORT, &GPIO_InitStruct); | |
196 HAL_GPIO_WritePin(BLE_NENABLE_GPIO_PORT,BLE_NENABLE_PIN,GPIO_PIN_RESET); | |
197 } | |
198 | |
199 | |
200 void MX_Bluetooth_PowerOff(void) | |
201 { | |
202 GPIO_InitTypeDef GPIO_InitStruct; | |
203 GPIO_InitStruct.Mode = GPIO_MODE_INPUT; | |
204 GPIO_InitStruct.Pin = BLE_NENABLE_PIN; | |
205 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
206 HAL_GPIO_Init(BLE_NENABLE_GPIO_PORT, &GPIO_InitStruct); | |
207 } | |
208 | |
209 | |
210 void MX_SmallCPU_Reset_To_Boot(void) | |
211 { | |
212 #ifdef SMALLCPU_NRESET_PIN | |
213 GPIO_InitTypeDef GPIO_InitStruct; | |
214 | |
215 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
216 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
217 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
218 | |
219 SMALLCPU_NRESET_GPIO_ENABLE(); | |
220 GPIO_InitStruct.Pin = SMALLCPU_NRESET_PIN; | |
221 HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct); | |
222 HAL_GPIO_WritePin(SMALLCPU_NRESET_GPIO_PORT,SMALLCPU_NRESET_PIN,GPIO_PIN_RESET); | |
223 HAL_GPIO_WritePin(SMALLCPU_BOOT0_GPIO_PORT,SMALLCPU_BOOT0_PIN,GPIO_PIN_SET); | |
224 HAL_Delay(2); | |
225 GPIO_InitStruct.Mode = GPIO_MODE_INPUT; | |
226 HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct); | |
227 HAL_Delay(100); | |
228 HAL_GPIO_WritePin(SMALLCPU_BOOT0_GPIO_PORT,SMALLCPU_BOOT0_PIN,GPIO_PIN_RESET); | |
229 #endif | |
230 } | |
231 | |
232 void MX_SmallCPU_Reset_To_Standard(void) | |
233 { | |
234 #ifdef SMALLCPU_NRESET_PIN | |
235 GPIO_InitTypeDef GPIO_InitStruct; | |
236 | |
237 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
238 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
239 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
240 | |
241 SMALLCPU_NRESET_GPIO_ENABLE(); | |
242 GPIO_InitStruct.Pin = SMALLCPU_NRESET_PIN; | |
243 HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct); | |
244 HAL_GPIO_WritePin(SMALLCPU_NRESET_GPIO_PORT,SMALLCPU_NRESET_PIN,GPIO_PIN_RESET); | |
245 HAL_GPIO_WritePin(SMALLCPU_BOOT0_GPIO_PORT,SMALLCPU_BOOT0_PIN,GPIO_PIN_RESET); | |
246 HAL_Delay(2); | |
247 GPIO_InitStruct.Mode = GPIO_MODE_INPUT; | |
248 HAL_GPIO_Init(SMALLCPU_NRESET_GPIO_PORT, &GPIO_InitStruct); | |
249 #endif | |
250 } | |
251 | |
252 void MX_UART_Init(void) | |
253 { | |
254 /*##-1- Configure the UART peripheral ######################################*/ | |
255 /* Put the USART peripheral in the Asynchronous mode (UART Mode) */ | |
256 /* UART1 configured as follow: | |
257 - Word Length = 8 Bits | |
258 - Stop Bit = One Stop bit | |
259 - Parity = None | |
260 - BaudRate = 9600 baud | |
261 - Hardware flow control disabled (RTS and CTS signals) */ | |
262 | |
263 #ifdef USARTx_CTS_PIN | |
264 UartHandle.Init.HwFlowCtl = UART_HWCONTROL_RTS_CTS; | |
265 #else | |
266 UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
267 #endif | |
268 UartHandle.Instance = USARTx; | |
269 UartHandle.Init.BaudRate = 115200; | |
270 UartHandle.Init.WordLength = UART_WORDLENGTH_8B; | |
271 UartHandle.Init.StopBits = UART_STOPBITS_1; | |
272 UartHandle.Init.Parity = UART_PARITY_NONE; | |
273 UartHandle.Init.Mode = UART_MODE_TX_RX; | |
274 HAL_UART_Init(&UartHandle); | |
275 | |
276 #ifdef USART_PIEZO | |
277 UartPiezoTxHandle.Instance = USART_PIEZO; | |
278 UartPiezoTxHandle.Init.BaudRate = 1200; | |
279 UartPiezoTxHandle.Init.WordLength = UART_WORDLENGTH_8B; | |
280 UartPiezoTxHandle.Init.StopBits = UART_STOPBITS_1; | |
281 UartPiezoTxHandle.Init.Parity = UART_PARITY_NONE; | |
282 UartPiezoTxHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
283 UartPiezoTxHandle.Init.Mode = UART_MODE_TX_RX; | |
284 | |
285 HAL_UART_Init(&UartPiezoTxHandle); | |
286 #endif | |
287 | |
288 #ifdef USART_IR_HUD | |
289 UartIR_HUD_Handle.Instance = USART_IR_HUD; | |
290 UartIR_HUD_Handle.Init.BaudRate = 2400; | |
291 UartIR_HUD_Handle.Init.WordLength = UART_WORDLENGTH_8B; | |
292 UartIR_HUD_Handle.Init.StopBits = UART_STOPBITS_1; | |
293 UartIR_HUD_Handle.Init.Parity = UART_PARITY_NONE; | |
294 UartIR_HUD_Handle.Init.HwFlowCtl = UART_HWCONTROL_NONE; | |
295 UartIR_HUD_Handle.Init.Mode = UART_MODE_TX_RX; | |
296 | |
297 HAL_UART_Init(&UartIR_HUD_Handle); | |
298 #endif | |
299 } | |
300 | |
301 void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) | |
302 { | |
303 if(huart == &UartHandle) | |
304 UartReady = SET; | |
305 } | |
306 | |
307 //void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) | |
308 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) | |
309 { | |
310 if(huart == &UartHandle) | |
311 UartReady = SET; | |
312 else | |
313 if(huart == &UartIR_HUD_Handle) | |
314 { | |
315 UartReadyHUD = SET; | |
316 } | |
317 } | |
318 | |
319 void MX_tell_reset_logik_alles_ok(void) | |
320 { | |
321 #ifdef RESET_LOGIC_ALLES_OK_PIN | |
322 GPIO_InitTypeDef GPIO_InitStruct; | |
323 | |
324 RESET_LOGIC_ALLES_OK_GPIO_ENABLE(); | |
325 | |
326 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; | |
327 GPIO_InitStruct.Pull = GPIO_NOPULL; | |
328 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
329 GPIO_InitStruct.Pin = RESET_LOGIC_ALLES_OK_PIN; | |
330 HAL_GPIO_Init(RESET_LOGIC_ALLES_OK_GPIO_PORT, &GPIO_InitStruct); | |
331 | |
332 HAL_GPIO_WritePin(RESET_LOGIC_ALLES_OK_GPIO_PORT,RESET_LOGIC_ALLES_OK_PIN,GPIO_PIN_RESET); | |
333 HAL_Delay(1); | |
334 HAL_GPIO_WritePin(RESET_LOGIC_ALLES_OK_GPIO_PORT,RESET_LOGIC_ALLES_OK_PIN,GPIO_PIN_SET); | |
335 | |
336 GPIO_InitStruct.Mode = GPIO_MODE_INPUT; | |
337 HAL_GPIO_Init(RESET_LOGIC_ALLES_OK_GPIO_PORT, &GPIO_InitStruct); | |
338 #endif | |
339 } | |
340 | |
341 | |
342 #ifndef BOOTLOADER_STANDALONE | |
343 void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) | |
344 { | |
345 if(huart == &UartIR_HUD_Handle) | |
346 tCCR_restart(); | |
347 } | |
348 #endif |