Mercurial > public > ostc4
annotate Small_CPU/Src/stm32f4xx_hal_msp_v3.c @ 471:73da921869d9 fix-bat-2
bugfix: implement battery charge percentage in dive header
This commit is (much) less trivial than the related 919e5cb51c92.
First, rename the CCRmode attribute (corresponding to byte Ox59) of
the SLogbookHeaderOSTC3. This byte (according to the hwOS interface
document) does not contain any CCR related value, but it contains
"battery information". Already since 2017, this byte is used from
libdivecomputer to interface the charge percentage. So, its
renamed from CCRmode to batteryCharge, to reflect its true purpose.
Now, simply add a batteryCharge attribute to the SLogbookHeader
(and see below why that is possible, without breaking things).
The remaining changes are trivial to implement battery charge
percentage in dive header.
Caveat: do not get confused by the exact role of the individual
logbook header types. SLogbookHeaderOSTC3 is the formal type of
the logbook format that the OSTC4 produces. This format is
supposed to identical to the format, as is used in hwOS for the
series of small OSTCs. Only some values of attributes are different.
For example, the OSTC4 supports VPM, so byte 0x79 (deco model used
for this dive) also has a value for VPM. But the SLogbookHeader
type, despite its name and structure, is *not* a true logbook
header, as it includes attributes that are not available in the
SLogbookHeaderOSTC3 formal header type.
Signed-off-by: Jan Mulder <jan@jlmulder.nl>
author | Jan Mulder <jlmulder@xs4all.nl> |
---|---|
date | Wed, 22 Apr 2020 13:08:57 +0200 |
parents | abec171c2c4b |
children | 1b995079c045 |
rev | line source |
---|---|
38 | 1 /** |
2 ****************************************************************************** | |
3 * @file UART/UART_Printf/Src/stm32f4xx_hal_msp.c | |
4 * @author MCD Application Team | |
5 * @version V1.1.0 | |
6 * @date 26-June-2014 | |
7 * @brief HAL MSP module. | |
8 ****************************************************************************** | |
9 * @attention | |
10 * | |
11 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> | |
12 * | |
13 * Redistribution and use in source and binary forms, with or without modification, | |
14 * are permitted provided that the following conditions are met: | |
15 * 1. Redistributions of source code must retain the above copyright notice, | |
16 * this list of conditions and the following disclaimer. | |
17 * 2. Redistributions in binary form must reproduce the above copyright notice, | |
18 * this list of conditions and the following disclaimer in the documentation | |
19 * and/or other materials provided with the distribution. | |
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors | |
21 * may be used to endorse or promote products derived from this software | |
22 * without specific prior written permission. | |
23 * | |
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
34 * | |
35 ****************************************************************************** | |
36 */ | |
37 | |
38 /* Includes ------------------------------------------------------------------*/ | |
39 #include "baseCPU2.h" | |
40 | |
41 #include "stm32f4xx_hal.h" | |
42 | |
43 /** @addtogroup STM32F4xx_HAL_Examples | |
44 * @{ | |
45 */ | |
46 | |
47 /** @defgroup HAL_MSP | |
48 * @brief HAL MSP module. | |
49 * @{ | |
50 */ | |
51 | |
52 /* Private typedef -----------------------------------------------------------*/ | |
53 /* Private define ------------------------------------------------------------*/ | |
54 /* Private macro -------------------------------------------------------------*/ | |
55 /* Private variables ---------------------------------------------------------*/ | |
56 /* Private function prototypes -----------------------------------------------*/ | |
57 /* Private functions ---------------------------------------------------------*/ | |
58 | |
59 /** @defgroup HAL_MSP_Private_Functions | |
60 * @{ | |
61 */ | |
62 | |
63 void HAL_I2C_ManualControl_MspInit(void) | |
64 { | |
65 GPIO_InitTypeDef GPIO_InitStruct; | |
66 | |
67 /*##-1- Enable peripherals and GPIO Clocks #################################*/ | |
68 /* Enable GPIO TX/RX clock */ | |
69 I2Cx_SCL_GPIO_CLK_ENABLE(); | |
70 I2Cx_SDA_GPIO_CLK_ENABLE(); | |
71 | |
72 /*##-2- Configure peripheral GPIO ##########################################*/ | |
73 /* I2C CLOCK GPIO pin configuration */ | |
74 GPIO_InitStruct.Pin = I2Cx_SCL_PIN; | |
75 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; | |
76 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
77 GPIO_InitStruct.Speed = GPIO_SPEED_FAST; | |
78 | |
79 HAL_GPIO_Init(I2Cx_SCL_GPIO_PORT, &GPIO_InitStruct); | |
80 | |
81 /* I2C DATA GPIO pin configuration */ | |
82 GPIO_InitStruct.Pin = I2Cx_SDA_PIN; | |
83 GPIO_InitStruct.Alternate = GPIO_MODE_INPUT; | |
84 | |
85 HAL_GPIO_Init(I2Cx_SDA_GPIO_PORT, &GPIO_InitStruct); | |
86 } | |
87 | |
88 /** | |
89 * @brief I2C MSP Initialization | |
90 * This function configures the hardware resources used in this example: | |
91 * - Peripheral's clock enable | |
92 * - Peripheral's GPIO Configuration | |
93 * - DMA configuration for transmission request by peripheral | |
94 * - NVIC configuration for DMA interrupt request enable | |
95 * @param hi2c: I2C handle pointer | |
96 * @retval None | |
97 */ | |
98 void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c) | |
99 { | |
100 GPIO_InitTypeDef GPIO_InitStruct; | |
101 | |
102 /*##-1- Enable peripherals and GPIO Clocks #################################*/ | |
103 /* Enable GPIO TX/RX clock */ | |
104 I2Cx_SCL_GPIO_CLK_ENABLE(); | |
105 I2Cx_SDA_GPIO_CLK_ENABLE(); | |
106 /* Enable I2C1 clock */ | |
107 I2Cx_CLK_ENABLE(); | |
108 | |
109 /*##-2- Configure peripheral GPIO ##########################################*/ | |
110 /* I2C TX GPIO pin configuration */ | |
111 GPIO_InitStruct.Pin = I2Cx_SCL_PIN; | |
112 GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; | |
327
abec171c2c4b
Deactivated internal pullups and I2C interrupt callback
ideenmodellierer
parents:
38
diff
changeset
|
113 GPIO_InitStruct.Pull = GPIO_NOPULL; |
38 | 114 GPIO_InitStruct.Speed = GPIO_SPEED_FAST; |
115 GPIO_InitStruct.Alternate = I2Cx_SCL_AF; | |
116 | |
117 HAL_GPIO_Init(I2Cx_SCL_GPIO_PORT, &GPIO_InitStruct); | |
118 | |
119 /* I2C RX GPIO pin configuration */ | |
120 GPIO_InitStruct.Pin = I2Cx_SDA_PIN; | |
121 GPIO_InitStruct.Alternate = I2Cx_SDA_AF; | |
122 | |
123 HAL_GPIO_Init(I2Cx_SDA_GPIO_PORT, &GPIO_InitStruct); | |
124 | |
125 /*##-3- Configure the NVIC for I2C #########################################*/ | |
126 /* NVIC for I2C1 */ | |
327
abec171c2c4b
Deactivated internal pullups and I2C interrupt callback
ideenmodellierer
parents:
38
diff
changeset
|
127 |
abec171c2c4b
Deactivated internal pullups and I2C interrupt callback
ideenmodellierer
parents:
38
diff
changeset
|
128 /* The callbacks are not used => no need to activate the interrupts */ |
abec171c2c4b
Deactivated internal pullups and I2C interrupt callback
ideenmodellierer
parents:
38
diff
changeset
|
129 /* |
38 | 130 HAL_NVIC_SetPriority(I2Cx_ER_IRQn, 1, 2); |
131 HAL_NVIC_EnableIRQ(I2Cx_ER_IRQn); | |
132 HAL_NVIC_SetPriority(I2Cx_EV_IRQn, 1, 3); | |
133 HAL_NVIC_EnableIRQ(I2Cx_EV_IRQn); | |
327
abec171c2c4b
Deactivated internal pullups and I2C interrupt callback
ideenmodellierer
parents:
38
diff
changeset
|
134 */ |
38 | 135 } |
136 | |
137 /** | |
138 * @brief I2C MSP De-Initialization | |
139 * This function frees the hardware resources used in this example: | |
140 * - Disable the Peripheral's clock | |
141 * - Revert GPIO, DMA and NVIC configuration to their default state | |
142 * @param hi2c: I2C handle pointer | |
143 * @retval None | |
144 */ | |
145 void HAL_I2C_MspDeInit(I2C_HandleTypeDef *hi2c) | |
146 { | |
147 /*##-1- Reset peripherals ##################################################*/ | |
148 I2Cx_FORCE_RESET(); | |
149 I2Cx_RELEASE_RESET(); | |
150 | |
151 /*##-2- Disable peripherals and GPIO Clocks ################################*/ | |
152 /* Configure I2C Tx as alternate function */ | |
153 HAL_GPIO_DeInit(I2Cx_SCL_GPIO_PORT, I2Cx_SCL_PIN); | |
154 /* Configure I2C Rx as alternate function */ | |
155 HAL_GPIO_DeInit(I2Cx_SDA_GPIO_PORT, I2Cx_SDA_PIN); | |
156 | |
157 /*##-3- Disable the NVIC for I2C ###########################################*/ | |
158 HAL_NVIC_DisableIRQ(I2Cx_ER_IRQn); | |
159 HAL_NVIC_DisableIRQ(I2Cx_EV_IRQn); | |
160 } | |
161 | |
162 | |
163 /** | |
164 * @brief RTC MSP Initialization | |
165 * This function configures the hardware resources used in this example | |
166 * @param hrtc: RTC handle pointer | |
167 * | |
168 * @note Care must be taken when HAL_RCCEx_PeriphCLKConfig() is used to select | |
169 * the RTC clock source; in this case the Backup domain will be reset in | |
170 * order to modify the RTC Clock source, as consequence RTC registers (including | |
171 * the backup registers) and RCC_BDCR register are set to their reset values. | |
172 * | |
173 * @retval None | |
174 */ | |
175 void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc) | |
176 { | |
177 | |
178 if(hrtc->Instance==RTC) | |
179 { | |
180 /* USER CODE BEGIN RTC_MspInit 0 */ | |
181 RCC_OscInitTypeDef RCC_OscInitStruct; | |
182 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; | |
183 | |
184 /*##-1- Configue LSI as RTC clock soucre ###################################*/ | |
185 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE; | |
186 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; | |
187 RCC_OscInitStruct.LSEState = RCC_LSE_ON; | |
188 HAL_RCC_OscConfig(&RCC_OscInitStruct); | |
189 | |
190 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC; | |
191 PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE; | |
192 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); | |
193 | |
194 /* USER CODE END RTC_MspInit 0 */ | |
195 /* Peripheral clock enable */ | |
196 __HAL_RCC_RTC_ENABLE(); | |
197 /* USER CODE BEGIN RTC_MspInit 1 */ | |
198 | |
199 /*##-3- Configure the NVIC for RTC WakeUp Timer ############################*/ | |
200 HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 0x0F, 0); | |
201 HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn); | |
202 | |
203 /* USER CODE END RTC_MspInit 1 */ | |
204 } | |
205 | |
206 } | |
207 | |
208 | |
209 void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc) | |
210 { | |
211 | |
212 if(hrtc->Instance==RTC) | |
213 { | |
214 /* USER CODE BEGIN RTC_MspDeInit 0 */ | |
215 | |
216 /* USER CODE END RTC_MspDeInit 0 */ | |
217 /* Peripheral clock disable */ | |
218 __HAL_RCC_RTC_DISABLE(); | |
219 /* USER CODE BEGIN RTC_MspDeInit 1 */ | |
220 | |
221 /* USER CODE END RTC_MspDeInit 1 */ | |
222 } | |
223 | |
224 } | |
225 | |
226 | |
227 | |
228 void HAL_UART_MspInit(UART_HandleTypeDef* huart) | |
229 { | |
230 | |
231 GPIO_InitTypeDef GPIO_InitStruct; | |
232 if(huart->Instance==USART2) | |
233 { | |
234 __USART2_CLK_ENABLE(); | |
235 GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3; | |
236 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; | |
237 GPIO_InitStruct.Pull = GPIO_PULLUP; | |
238 GPIO_InitStruct.Speed = GPIO_SPEED_LOW; | |
239 GPIO_InitStruct.Alternate = GPIO_AF7_USART2; | |
240 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); | |
241 } | |
242 } | |
243 | |
244 | |
245 void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) | |
246 { | |
247 if(huart->Instance==USART2) | |
248 { | |
249 __USART2_CLK_DISABLE(); | |
250 HAL_GPIO_DeInit(GPIOA, GPIO_PIN_2|GPIO_PIN_3); | |
251 } | |
252 } | |
253 | |
254 | |
255 | |
256 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |