feat(swan_r5): adds a basic RTC implementation.
This commit is contained in:
parent
6925a00138
commit
a889638468
@ -70,3 +70,4 @@ CIRCUITPY_BLEIO = 0
|
||||
CIRCUITPY_BUSDEVICE = 0
|
||||
CIRCUITPY_KEYPAD = 1
|
||||
CIRCUITPY_RGBMATRIX = 0
|
||||
CIRCUITPY_RTC = 1
|
||||
|
54
ports/stm/common-hal/rtc/RTC.c
Normal file
54
ports/stm/common-hal/rtc/RTC.c
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 20212 Matthew McGowan for Blues Wireless Inc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "py/obj.h"
|
||||
#include "py/runtime.h"
|
||||
#include "shared/timeutils/timeutils.h"
|
||||
#include "shared-bindings/rtc/__init__.h"
|
||||
#include "common-hal/rtc/RTC.h"
|
||||
#include "shared-bindings/rtc/RTC.h"
|
||||
#include "supervisor/port.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
#include "peripherals/rtc.h"
|
||||
|
||||
|
||||
void common_hal_rtc_set_time(timeutils_struct_time_t *tm) {
|
||||
stm32_peripherals_rtc_set_time(tm);
|
||||
}
|
||||
|
||||
void common_hal_rtc_get_time(timeutils_struct_time_t *tm) {
|
||||
stm32_peripherals_rtc_get_time(tm);
|
||||
}
|
||||
|
||||
int common_hal_rtc_get_calibration(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void common_hal_rtc_set_calibration(int calibration) {
|
||||
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_calibration);
|
||||
}
|
33
ports/stm/common-hal/rtc/RTC.h
Normal file
33
ports/stm/common-hal/rtc/RTC.h
Normal file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2022 Matthew McGowan for Blues Wireless Inc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_STM_COMMON_HAL_RTC_RTC_H
|
||||
#define MICROPY_INCLUDED_STM_COMMON_HAL_RTC_RTC_H
|
||||
|
||||
extern void rtc_init(void);
|
||||
extern void rtc_reset(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_STM_COMMON_HAL_RTC_RTC_H
|
0
ports/stm/common-hal/rtc/__init__.c
Normal file
0
ports/stm/common-hal/rtc/__init__.c
Normal file
0
ports/stm/common-hal/rtc/__init__.h
Normal file
0
ports/stm/common-hal/rtc/__init__.h
Normal file
@ -4,6 +4,7 @@
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2021 Lucian Copeland for Adafruit Industries
|
||||
* Copyright (c) 2022 Matthew McGowan for Blues Wireless Inc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@ -76,6 +77,46 @@ void stm32_peripherals_rtc_init(void) {
|
||||
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
|
||||
}
|
||||
|
||||
#if CIRCUITPY_RTC
|
||||
void stm32_peripherals_rtc_get_time(timeutils_struct_time_t *tm) {
|
||||
RTC_DateTypeDef date = {0};
|
||||
RTC_TimeTypeDef time = {0};
|
||||
|
||||
int code;
|
||||
if ((code = HAL_RTC_GetTime(&hrtc, &time, RTC_FORMAT_BIN)) == HAL_OK &&
|
||||
(code = HAL_RTC_GetDate(&hrtc, &date, RTC_FORMAT_BIN)) == HAL_OK) {
|
||||
tm->tm_hour = time.Hours;
|
||||
tm->tm_min = time.Minutes;
|
||||
tm->tm_sec = time.Seconds;
|
||||
tm->tm_wday = date.WeekDay - 1;
|
||||
tm->tm_mday = date.Date;
|
||||
tm->tm_mon = date.Month;
|
||||
tm->tm_year = date.Year + 2000;
|
||||
tm->tm_yday = -1;
|
||||
}
|
||||
}
|
||||
|
||||
void stm32_peripherals_rtc_set_time(timeutils_struct_time_t *tm) {
|
||||
RTC_DateTypeDef date = {0};
|
||||
RTC_TimeTypeDef time = {0};
|
||||
|
||||
time.Hours = tm->tm_hour;
|
||||
time.Minutes = tm->tm_min;
|
||||
time.Seconds = tm->tm_sec;
|
||||
date.WeekDay = tm->tm_wday + 1;
|
||||
date.Date = tm->tm_mday;
|
||||
date.Month = tm->tm_mon;
|
||||
date.Year = tm->tm_year - 2000;
|
||||
time.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
|
||||
time.StoreOperation = RTC_STOREOPERATION_RESET;
|
||||
|
||||
if (HAL_RTC_SetTime(&hrtc, &time, RTC_FORMAT_BIN) != HAL_OK ||
|
||||
HAL_RTC_SetDate(&hrtc, &date, RTC_FORMAT_BIN) != HAL_OK) {
|
||||
// todo - throw an exception
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// This function is called often for timing so we cache the seconds elapsed computation based on the
|
||||
// register value. The STM HAL always does shifts and conversion if we use it directly.
|
||||
uint64_t stm32_peripherals_rtc_raw_ticks(uint8_t *subticks) {
|
||||
|
@ -4,6 +4,7 @@
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2021 Lucian Copeland for Adafruit Industries
|
||||
* Copyright (c) 2022 Matthew McGowan for Blues Wireless Inc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@ -48,4 +49,10 @@ void stm32_peripherals_rtc_assign_alarm_callback(uint8_t alarm_idx, void (*callb
|
||||
void stm32_peripherals_rtc_set_alarm(uint8_t alarm_idx, uint32_t ticks);
|
||||
bool stm32_peripherals_rtc_alarm_triggered(uint8_t alarm_idx);
|
||||
|
||||
#if CIRCUITPY_RTC
|
||||
typedef struct _timeutils_struct_time_t timeutils_struct_time_t;
|
||||
void stm32_peripherals_rtc_get_time(timeutils_struct_time_t *tm);
|
||||
void stm32_peripherals_rtc_set_time(timeutils_struct_time_t *tm);
|
||||
#endif
|
||||
|
||||
#endif // __MICROPY_INCLUDED_STM32_PERIPHERALS_RTC_H__
|
||||
|
@ -61,6 +61,9 @@
|
||||
#if CIRCUITPY_ALARM
|
||||
#include "common-hal/alarm/__init__.h"
|
||||
#endif
|
||||
#if CIRCUITPY_RTC
|
||||
#include "shared-bindings/rtc/__init__.h"
|
||||
#endif
|
||||
|
||||
#include "peripherals/clocks.h"
|
||||
#include "peripherals/gpio.h"
|
||||
@ -241,6 +244,10 @@ void SysTick_Handler(void) {
|
||||
|
||||
void reset_port(void) {
|
||||
reset_all_pins();
|
||||
#if CIRCUITPY_RTC
|
||||
rtc_reset();
|
||||
#endif
|
||||
|
||||
#if CIRCUITPY_AUDIOPWMIO
|
||||
audiopwmout_reset();
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user