lol

Dependencies:   MMA8451Q

Fork of Application by Mateusz Kowalik

Committer:
danix
Date:
Sun Jan 21 22:28:30 2018 +0000
Revision:
12:3a30cdffa27c
Parent:
10:41552d038a69
Working acelerometer and mouse

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Zaitsev 10:41552d038a69 1 /* mbed Microcontroller Library
Zaitsev 10:41552d038a69 2 *******************************************************************************
Zaitsev 10:41552d038a69 3 * Copyright (c) 2016, STMicroelectronics
Zaitsev 10:41552d038a69 4 * All rights reserved.
Zaitsev 10:41552d038a69 5 *
Zaitsev 10:41552d038a69 6 * Redistribution and use in source and binary forms, with or without
Zaitsev 10:41552d038a69 7 * modification, are permitted provided that the following conditions are met:
Zaitsev 10:41552d038a69 8 *
Zaitsev 10:41552d038a69 9 * 1. Redistributions of source code must retain the above copyright notice,
Zaitsev 10:41552d038a69 10 * this list of conditions and the following disclaimer.
Zaitsev 10:41552d038a69 11 * 2. Redistributions in binary form must reproduce the above copyright notice,
Zaitsev 10:41552d038a69 12 * this list of conditions and the following disclaimer in the documentation
Zaitsev 10:41552d038a69 13 * and/or other materials provided with the distribution.
Zaitsev 10:41552d038a69 14 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Zaitsev 10:41552d038a69 15 * may be used to endorse or promote products derived from this software
Zaitsev 10:41552d038a69 16 * without specific prior written permission.
Zaitsev 10:41552d038a69 17 *
Zaitsev 10:41552d038a69 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Zaitsev 10:41552d038a69 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Zaitsev 10:41552d038a69 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Zaitsev 10:41552d038a69 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Zaitsev 10:41552d038a69 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Zaitsev 10:41552d038a69 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Zaitsev 10:41552d038a69 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Zaitsev 10:41552d038a69 25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Zaitsev 10:41552d038a69 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Zaitsev 10:41552d038a69 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Zaitsev 10:41552d038a69 28 *******************************************************************************
Zaitsev 10:41552d038a69 29 */
Zaitsev 10:41552d038a69 30 #if DEVICE_RTC
Zaitsev 10:41552d038a69 31
Zaitsev 10:41552d038a69 32 #include "rtc_api.h"
Zaitsev 10:41552d038a69 33 #include "rtc_api_hal.h"
Zaitsev 10:41552d038a69 34 #include "mbed_error.h"
Zaitsev 10:41552d038a69 35
Zaitsev 10:41552d038a69 36 static RTC_HandleTypeDef RtcHandle;
Zaitsev 10:41552d038a69 37
Zaitsev 10:41552d038a69 38 #if RTC_LSI
Zaitsev 10:41552d038a69 39 #define RTC_CLOCK LSI_VALUE
Zaitsev 10:41552d038a69 40 #else
Zaitsev 10:41552d038a69 41 #define RTC_CLOCK LSE_VALUE
Zaitsev 10:41552d038a69 42 #endif
Zaitsev 10:41552d038a69 43
Zaitsev 10:41552d038a69 44 #if DEVICE_LOWPOWERTIMER
Zaitsev 10:41552d038a69 45 #define RTC_ASYNCH_PREDIV ((RTC_CLOCK - 1) / 0x8000)
Zaitsev 10:41552d038a69 46 #define RTC_SYNCH_PREDIV (RTC_CLOCK / (RTC_ASYNCH_PREDIV + 1) - 1)
Zaitsev 10:41552d038a69 47 #else
Zaitsev 10:41552d038a69 48 #define RTC_ASYNCH_PREDIV (0x007F)
Zaitsev 10:41552d038a69 49 #define RTC_SYNCH_PREDIV (RTC_CLOCK / (RTC_ASYNCH_PREDIV + 1) - 1)
Zaitsev 10:41552d038a69 50 #endif
Zaitsev 10:41552d038a69 51
Zaitsev 10:41552d038a69 52 #if DEVICE_LOWPOWERTIMER
Zaitsev 10:41552d038a69 53 static void (*irq_handler)(void);
Zaitsev 10:41552d038a69 54 static void RTC_IRQHandler(void);
Zaitsev 10:41552d038a69 55 #endif
Zaitsev 10:41552d038a69 56
Zaitsev 10:41552d038a69 57 void rtc_init(void)
Zaitsev 10:41552d038a69 58 {
Zaitsev 10:41552d038a69 59 RCC_OscInitTypeDef RCC_OscInitStruct;
Zaitsev 10:41552d038a69 60 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct;
Zaitsev 10:41552d038a69 61
Zaitsev 10:41552d038a69 62 // Enable access to Backup domain
Zaitsev 10:41552d038a69 63 HAL_PWR_EnableBkUpAccess();
Zaitsev 10:41552d038a69 64
Zaitsev 10:41552d038a69 65 RtcHandle.Instance = RTC;
Zaitsev 10:41552d038a69 66
Zaitsev 10:41552d038a69 67 #if !RTC_LSI
Zaitsev 10:41552d038a69 68 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE;
Zaitsev 10:41552d038a69 69 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
Zaitsev 10:41552d038a69 70 RCC_OscInitStruct.LSEState = RCC_LSE_ON;
Zaitsev 10:41552d038a69 71 RCC_OscInitStruct.LSIState = RCC_LSI_OFF;
Zaitsev 10:41552d038a69 72
Zaitsev 10:41552d038a69 73 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) == HAL_OK) {
Zaitsev 10:41552d038a69 74 __HAL_RCC_RTC_CLKPRESCALER(RCC_RTCCLKSOURCE_LSE);
Zaitsev 10:41552d038a69 75 __HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSE);
Zaitsev 10:41552d038a69 76 } else {
Zaitsev 10:41552d038a69 77 error("Cannot initialize RTC with LSE\n");
Zaitsev 10:41552d038a69 78 }
Zaitsev 10:41552d038a69 79
Zaitsev 10:41552d038a69 80 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
Zaitsev 10:41552d038a69 81 PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
Zaitsev 10:41552d038a69 82 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
Zaitsev 10:41552d038a69 83 error("PeriphClkInitStruct RTC failed with LSE\n");
Zaitsev 10:41552d038a69 84 }
Zaitsev 10:41552d038a69 85
Zaitsev 10:41552d038a69 86 #else /* !RTC_LSI */
Zaitsev 10:41552d038a69 87
Zaitsev 10:41552d038a69 88 __PWR_CLK_ENABLE();
Zaitsev 10:41552d038a69 89
Zaitsev 10:41552d038a69 90 // Reset Backup domain
Zaitsev 10:41552d038a69 91 __HAL_RCC_BACKUPRESET_FORCE();
Zaitsev 10:41552d038a69 92 __HAL_RCC_BACKUPRESET_RELEASE();
Zaitsev 10:41552d038a69 93
Zaitsev 10:41552d038a69 94 // Enable LSI clock
Zaitsev 10:41552d038a69 95 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI;
Zaitsev 10:41552d038a69 96 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE; // Mandatory, otherwise the PLL is reconfigured!
Zaitsev 10:41552d038a69 97 RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
Zaitsev 10:41552d038a69 98 RCC_OscInitStruct.LSIState = RCC_LSI_ON;
Zaitsev 10:41552d038a69 99 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
Zaitsev 10:41552d038a69 100 error("Cannot initialize RTC with LSI\n");
Zaitsev 10:41552d038a69 101 }
Zaitsev 10:41552d038a69 102
Zaitsev 10:41552d038a69 103 __HAL_RCC_RTC_CLKPRESCALER(RCC_RTCCLKSOURCE_LSI);
Zaitsev 10:41552d038a69 104 __HAL_RCC_RTC_CONFIG(RCC_RTCCLKSOURCE_LSI);
Zaitsev 10:41552d038a69 105
Zaitsev 10:41552d038a69 106 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;
Zaitsev 10:41552d038a69 107 PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
Zaitsev 10:41552d038a69 108 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK) {
Zaitsev 10:41552d038a69 109 error("PeriphClkInitStruct RTC failed with LSI\n");
Zaitsev 10:41552d038a69 110 }
Zaitsev 10:41552d038a69 111
Zaitsev 10:41552d038a69 112 #endif /* !RTC_LSI */
Zaitsev 10:41552d038a69 113
Zaitsev 10:41552d038a69 114 // Enable RTC
Zaitsev 10:41552d038a69 115 __HAL_RCC_RTC_ENABLE();
Zaitsev 10:41552d038a69 116
Zaitsev 10:41552d038a69 117 #if TARGET_STM32F1
Zaitsev 10:41552d038a69 118 RtcHandle.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
Zaitsev 10:41552d038a69 119 #else /* TARGET_STM32F1 */
Zaitsev 10:41552d038a69 120 RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
Zaitsev 10:41552d038a69 121 RtcHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
Zaitsev 10:41552d038a69 122 RtcHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
Zaitsev 10:41552d038a69 123 RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
Zaitsev 10:41552d038a69 124 RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
Zaitsev 10:41552d038a69 125 RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
Zaitsev 10:41552d038a69 126 #endif /* TARGET_STM32F1 */
Zaitsev 10:41552d038a69 127
Zaitsev 10:41552d038a69 128 if (HAL_RTC_Init(&RtcHandle) != HAL_OK) {
Zaitsev 10:41552d038a69 129 error("RTC error: RTC initialization failed.");
Zaitsev 10:41552d038a69 130 }
Zaitsev 10:41552d038a69 131
Zaitsev 10:41552d038a69 132 #if DEVICE_LOWPOWERTIMER
Zaitsev 10:41552d038a69 133
Zaitsev 10:41552d038a69 134 #if !RTC_LSI
Zaitsev 10:41552d038a69 135 if (!rtc_isenabled())
Zaitsev 10:41552d038a69 136 #endif /* !RTC_LSI */
Zaitsev 10:41552d038a69 137 {
Zaitsev 10:41552d038a69 138 rtc_write(0);
Zaitsev 10:41552d038a69 139 }
Zaitsev 10:41552d038a69 140
Zaitsev 10:41552d038a69 141 NVIC_ClearPendingIRQ(RTC_WKUP_IRQn);
Zaitsev 10:41552d038a69 142 NVIC_DisableIRQ(RTC_WKUP_IRQn);
Zaitsev 10:41552d038a69 143 NVIC_SetVector(RTC_WKUP_IRQn, (uint32_t)RTC_IRQHandler);
Zaitsev 10:41552d038a69 144 NVIC_EnableIRQ(RTC_WKUP_IRQn);
Zaitsev 10:41552d038a69 145
Zaitsev 10:41552d038a69 146 #endif /* DEVICE_LOWPOWERTIMER */
Zaitsev 10:41552d038a69 147 }
Zaitsev 10:41552d038a69 148
Zaitsev 10:41552d038a69 149 void rtc_free(void)
Zaitsev 10:41552d038a69 150 {
Zaitsev 10:41552d038a69 151 #if RTC_LSI
Zaitsev 10:41552d038a69 152 // Enable Power clock
Zaitsev 10:41552d038a69 153 __PWR_CLK_ENABLE();
Zaitsev 10:41552d038a69 154
Zaitsev 10:41552d038a69 155 // Enable access to Backup domain
Zaitsev 10:41552d038a69 156 HAL_PWR_EnableBkUpAccess();
Zaitsev 10:41552d038a69 157
Zaitsev 10:41552d038a69 158 // Reset Backup domain
Zaitsev 10:41552d038a69 159 __HAL_RCC_BACKUPRESET_FORCE();
Zaitsev 10:41552d038a69 160 __HAL_RCC_BACKUPRESET_RELEASE();
Zaitsev 10:41552d038a69 161
Zaitsev 10:41552d038a69 162 // Disable access to Backup domain
Zaitsev 10:41552d038a69 163 HAL_PWR_DisableBkUpAccess();
Zaitsev 10:41552d038a69 164 #endif
Zaitsev 10:41552d038a69 165
Zaitsev 10:41552d038a69 166 // Disable LSI and LSE clocks
Zaitsev 10:41552d038a69 167 RCC_OscInitTypeDef RCC_OscInitStruct;
Zaitsev 10:41552d038a69 168 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI | RCC_OSCILLATORTYPE_LSE;
Zaitsev 10:41552d038a69 169 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
Zaitsev 10:41552d038a69 170 RCC_OscInitStruct.LSIState = RCC_LSI_OFF;
Zaitsev 10:41552d038a69 171 RCC_OscInitStruct.LSEState = RCC_LSE_OFF;
Zaitsev 10:41552d038a69 172 HAL_RCC_OscConfig(&RCC_OscInitStruct);
Zaitsev 10:41552d038a69 173 }
Zaitsev 10:41552d038a69 174
Zaitsev 10:41552d038a69 175 /*
Zaitsev 10:41552d038a69 176 RTC Registers
Zaitsev 10:41552d038a69 177 RTC_WeekDay 1=monday, 2=tuesday, ..., 7=sunday
Zaitsev 10:41552d038a69 178 RTC_Month 1=january, 2=february, ..., 12=december
Zaitsev 10:41552d038a69 179 RTC_Date day of the month 1-31
Zaitsev 10:41552d038a69 180 RTC_Year year 0-99
Zaitsev 10:41552d038a69 181 struct tm
Zaitsev 10:41552d038a69 182 tm_sec seconds after the minute 0-61
Zaitsev 10:41552d038a69 183 tm_min minutes after the hour 0-59
Zaitsev 10:41552d038a69 184 tm_hour hours since midnight 0-23
Zaitsev 10:41552d038a69 185 tm_mday day of the month 1-31
Zaitsev 10:41552d038a69 186 tm_mon months since January 0-11
Zaitsev 10:41552d038a69 187 tm_year years since 1900
Zaitsev 10:41552d038a69 188 tm_wday days since Sunday 0-6
Zaitsev 10:41552d038a69 189 tm_yday days since January 1 0-365
Zaitsev 10:41552d038a69 190 tm_isdst Daylight Saving Time flag
Zaitsev 10:41552d038a69 191 */
Zaitsev 10:41552d038a69 192 time_t rtc_read(void)
Zaitsev 10:41552d038a69 193 {
Zaitsev 10:41552d038a69 194 RTC_DateTypeDef dateStruct;
Zaitsev 10:41552d038a69 195 RTC_TimeTypeDef timeStruct;
Zaitsev 10:41552d038a69 196 struct tm timeinfo;
Zaitsev 10:41552d038a69 197
Zaitsev 10:41552d038a69 198 RtcHandle.Instance = RTC;
Zaitsev 10:41552d038a69 199
Zaitsev 10:41552d038a69 200 // Read actual date and time
Zaitsev 10:41552d038a69 201 // Warning: the time must be read first!
Zaitsev 10:41552d038a69 202 HAL_RTC_GetTime(&RtcHandle, &timeStruct, FORMAT_BIN);
Zaitsev 10:41552d038a69 203 HAL_RTC_GetDate(&RtcHandle, &dateStruct, FORMAT_BIN);
Zaitsev 10:41552d038a69 204
Zaitsev 10:41552d038a69 205 // Setup a tm structure based on the RTC
Zaitsev 10:41552d038a69 206 timeinfo.tm_wday = dateStruct.WeekDay;
Zaitsev 10:41552d038a69 207 timeinfo.tm_mon = dateStruct.Month - 1;
Zaitsev 10:41552d038a69 208 timeinfo.tm_mday = dateStruct.Date;
Zaitsev 10:41552d038a69 209 timeinfo.tm_year = dateStruct.Year + 68;
Zaitsev 10:41552d038a69 210 timeinfo.tm_hour = timeStruct.Hours;
Zaitsev 10:41552d038a69 211 timeinfo.tm_min = timeStruct.Minutes;
Zaitsev 10:41552d038a69 212 timeinfo.tm_sec = timeStruct.Seconds;
Zaitsev 10:41552d038a69 213 // Daylight Saving Time information is not available
Zaitsev 10:41552d038a69 214 timeinfo.tm_isdst = -1;
Zaitsev 10:41552d038a69 215
Zaitsev 10:41552d038a69 216 // Convert to timestamp
Zaitsev 10:41552d038a69 217 time_t t = mktime(&timeinfo);
Zaitsev 10:41552d038a69 218
Zaitsev 10:41552d038a69 219 return t;
Zaitsev 10:41552d038a69 220 }
Zaitsev 10:41552d038a69 221
Zaitsev 10:41552d038a69 222 void rtc_write(time_t t)
Zaitsev 10:41552d038a69 223 {
Zaitsev 10:41552d038a69 224 RTC_DateTypeDef dateStruct;
Zaitsev 10:41552d038a69 225 RTC_TimeTypeDef timeStruct;
Zaitsev 10:41552d038a69 226
Zaitsev 10:41552d038a69 227 RtcHandle.Instance = RTC;
Zaitsev 10:41552d038a69 228
Zaitsev 10:41552d038a69 229 // Convert the time into a tm
Zaitsev 10:41552d038a69 230 struct tm *timeinfo = localtime(&t);
Zaitsev 10:41552d038a69 231
Zaitsev 10:41552d038a69 232 // Fill RTC structures
Zaitsev 10:41552d038a69 233 dateStruct.WeekDay = timeinfo->tm_wday;
Zaitsev 10:41552d038a69 234 dateStruct.Month = timeinfo->tm_mon + 1;
Zaitsev 10:41552d038a69 235 dateStruct.Date = timeinfo->tm_mday;
Zaitsev 10:41552d038a69 236 dateStruct.Year = timeinfo->tm_year - 68;
Zaitsev 10:41552d038a69 237 timeStruct.Hours = timeinfo->tm_hour;
Zaitsev 10:41552d038a69 238 timeStruct.Minutes = timeinfo->tm_min;
Zaitsev 10:41552d038a69 239 timeStruct.Seconds = timeinfo->tm_sec;
Zaitsev 10:41552d038a69 240
Zaitsev 10:41552d038a69 241 #if !(TARGET_STM32F1)
Zaitsev 10:41552d038a69 242 timeStruct.TimeFormat = RTC_HOURFORMAT_24;
Zaitsev 10:41552d038a69 243 timeStruct.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
Zaitsev 10:41552d038a69 244 timeStruct.StoreOperation = RTC_STOREOPERATION_RESET;
Zaitsev 10:41552d038a69 245 #endif /* TARGET_STM32F1 */
Zaitsev 10:41552d038a69 246
Zaitsev 10:41552d038a69 247 // Change the RTC current date/time
Zaitsev 10:41552d038a69 248 HAL_RTC_SetDate(&RtcHandle, &dateStruct, FORMAT_BIN);
Zaitsev 10:41552d038a69 249 HAL_RTC_SetTime(&RtcHandle, &timeStruct, FORMAT_BIN);
Zaitsev 10:41552d038a69 250 }
Zaitsev 10:41552d038a69 251
Zaitsev 10:41552d038a69 252 int rtc_isenabled(void)
Zaitsev 10:41552d038a69 253 {
Zaitsev 10:41552d038a69 254 #if DEVICE_LOWPOWERTIMER
Zaitsev 10:41552d038a69 255 if ((RTC->ISR & RTC_ISR_INITS) == RTC_ISR_INITS) {
Zaitsev 10:41552d038a69 256 return 1;
Zaitsev 10:41552d038a69 257 } else {
Zaitsev 10:41552d038a69 258 return 0;
Zaitsev 10:41552d038a69 259 }
Zaitsev 10:41552d038a69 260 #else /* DEVICE_LOWPOWERTIMER */
Zaitsev 10:41552d038a69 261 return 1;
Zaitsev 10:41552d038a69 262 #endif /* DEVICE_LOWPOWERTIMER */
Zaitsev 10:41552d038a69 263 }
Zaitsev 10:41552d038a69 264
Zaitsev 10:41552d038a69 265 #if DEVICE_LOWPOWERTIMER
Zaitsev 10:41552d038a69 266
Zaitsev 10:41552d038a69 267 static void RTC_IRQHandler(void)
Zaitsev 10:41552d038a69 268 {
Zaitsev 10:41552d038a69 269 HAL_RTCEx_WakeUpTimerIRQHandler(&RtcHandle);
Zaitsev 10:41552d038a69 270 }
Zaitsev 10:41552d038a69 271
Zaitsev 10:41552d038a69 272 void HAL_RTCEx_WakeUpTimerEventCallback(RTC_HandleTypeDef *hrtc)
Zaitsev 10:41552d038a69 273 {
Zaitsev 10:41552d038a69 274 if (irq_handler) {
Zaitsev 10:41552d038a69 275 // Fire the user callback
Zaitsev 10:41552d038a69 276 irq_handler();
Zaitsev 10:41552d038a69 277 }
Zaitsev 10:41552d038a69 278 }
Zaitsev 10:41552d038a69 279
Zaitsev 10:41552d038a69 280 void rtc_set_irq_handler(uint32_t handler)
Zaitsev 10:41552d038a69 281 {
Zaitsev 10:41552d038a69 282 irq_handler = (void (*)(void))handler;
Zaitsev 10:41552d038a69 283 }
Zaitsev 10:41552d038a69 284
Zaitsev 10:41552d038a69 285 uint32_t rtc_read_subseconds(void)
Zaitsev 10:41552d038a69 286 {
Zaitsev 10:41552d038a69 287 return 1000000.f * ((double)(RTC_SYNCH_PREDIV - RTC->SSR) / (RTC_SYNCH_PREDIV + 1));
Zaitsev 10:41552d038a69 288 }
Zaitsev 10:41552d038a69 289
Zaitsev 10:41552d038a69 290 void rtc_set_wake_up_timer(uint32_t delta)
Zaitsev 10:41552d038a69 291 {
Zaitsev 10:41552d038a69 292 uint32_t wake_up_counter = delta / (2000000 / RTC_CLOCK);
Zaitsev 10:41552d038a69 293
Zaitsev 10:41552d038a69 294 if (HAL_RTCEx_SetWakeUpTimer_IT(&RtcHandle, wake_up_counter,
Zaitsev 10:41552d038a69 295 RTC_WAKEUPCLOCK_RTCCLK_DIV2) != HAL_OK) {
Zaitsev 10:41552d038a69 296 error("Set wake up timer failed\n");
Zaitsev 10:41552d038a69 297 }
Zaitsev 10:41552d038a69 298 }
Zaitsev 10:41552d038a69 299
Zaitsev 10:41552d038a69 300 void rtc_deactivate_wake_up_timer(void)
Zaitsev 10:41552d038a69 301 {
Zaitsev 10:41552d038a69 302 HAL_RTCEx_DeactivateWakeUpTimer(&RtcHandle);
Zaitsev 10:41552d038a69 303 }
Zaitsev 10:41552d038a69 304
Zaitsev 10:41552d038a69 305 void rtc_synchronize(void)
Zaitsev 10:41552d038a69 306 {
Zaitsev 10:41552d038a69 307 HAL_RTC_WaitForSynchro(&RtcHandle);
Zaitsev 10:41552d038a69 308 }
Zaitsev 10:41552d038a69 309 #endif /* DEVICE_LOWPOWERTIMER */
Zaitsev 10:41552d038a69 310
Zaitsev 10:41552d038a69 311
Zaitsev 10:41552d038a69 312 #endif /* DEVICE_RTC */