Skip to content

Commit 0c418e9

Browse files
committed
Merge remote-tracking branch 'adafruit/main' into auto_wifi
2 parents dc794f9 + ab346a2 commit 0c418e9

File tree

15 files changed

+258
-88
lines changed

15 files changed

+258
-88
lines changed

locale/cs.po

Lines changed: 62 additions & 57 deletions
Large diffs are not rendered by default.

ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ CIRCUITPY_PS2IO = 0
2727
CIRCUITPY_RGBMATRIX = 0
2828
CIRCUITPY_ROTARYIO = 0
2929
CIRCUITPY_TOUCHIO = 0
30+
CIRCUITPY_USB_HID = 0
31+
CIRCUITPY_USB_MIDI = 0
3032

3133
CIRCUITPY_ULAB = 0
3234

ports/atmel-samd/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#define MICROPY_PY_BUILTINS_NOTIMPLEMENTED (0)
4747
#define MICROPY_PY_FUNCTION_ATTRS (0)
4848
#define MICROPY_PY_REVERSE_SPECIAL_METHODS (0)
49+
#define MICROPY_PY_COLLECTIONS_DEQUE (0)
4950
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (0)
5051
#define MICROPY_PY_UERRNO_LIST \
5152
X(EPERM) \

ports/espressif/common-hal/busio/UART.c

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
108108
bool have_rx = rx != NULL;
109109
bool have_rts = rts != NULL;
110110
bool have_cts = cts != NULL;
111+
112+
uart_config_t uart_config = {0};
111113
bool have_rs485_dir = rs485_dir != NULL;
112114
if (!have_tx && !have_rx) {
113115
mp_raise_ValueError(translate("tx and rx cannot both be None"));
@@ -135,25 +137,26 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
135137
}
136138

137139
uart_mode_t mode = UART_MODE_UART;
138-
uart_hw_flowcontrol_t flow_control = UART_HW_FLOWCTRL_DISABLE;
140+
uart_config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
139141
if (have_rs485_dir) {
140142
mode = UART_MODE_RS485_HALF_DUPLEX;
141143
if (!rs485_invert) {
144+
// This one is not in the set
142145
uart_set_line_inverse(self->uart_num, UART_SIGNAL_DTR_INV);
143146
}
144147
} else if (have_rts && have_cts) {
145-
flow_control = UART_HW_FLOWCTRL_CTS_RTS;
148+
uart_config.flow_ctrl = UART_HW_FLOWCTRL_CTS_RTS;
146149
} else if (have_rts) {
147-
flow_control = UART_HW_FLOWCTRL_RTS;
150+
uart_config.flow_ctrl = UART_HW_FLOWCTRL_RTS;
148151
} else if (have_rts) {
149-
flow_control = UART_HW_FLOWCTRL_CTS;
152+
uart_config.flow_ctrl = UART_HW_FLOWCTRL_CTS;
150153
}
151154

152155
if (receiver_buffer_size <= UART_FIFO_LEN) {
153156
receiver_buffer_size = UART_FIFO_LEN + 8;
154157
}
155158

156-
uint8_t rx_threshold = UART_FIFO_LEN - 8;
159+
uart_config.rx_flow_ctrl_thresh = UART_FIFO_LEN - 8;
157160
// Install the driver before we change the settings.
158161
if (uart_driver_install(self->uart_num, receiver_buffer_size, 0, 20, &self->event_queue, 0) != ESP_OK ||
159162
uart_set_mode(self->uart_num, mode) != ESP_OK) {
@@ -175,55 +178,62 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
175178
CONFIG_PTHREAD_TASK_PRIO_DEFAULT,
176179
&self->event_task,
177180
xPortGetCoreID());
178-
uart_set_hw_flow_ctrl(self->uart_num, flow_control, rx_threshold);
181+
// uart_set_hw_flow_ctrl(self->uart_num, uart_config.flow_control, uart_config.rx_flow_ctrl_thresh);
179182

180183
// Set baud rate
181-
common_hal_busio_uart_set_baudrate(self, baudrate);
184+
// common_hal_busio_uart_set_baudrate(self, baudrate);
185+
uart_config.baud_rate = baudrate;
182186

183-
uart_word_length_t word_length = UART_DATA_8_BITS;
187+
uart_config.data_bits = UART_DATA_8_BITS;
184188
switch (bits) {
185189
// Shared bindings prevents data < 7 bits.
186190
// case 5:
187-
// word_length = UART_DATA_5_BITS;
191+
// uart_config.data_bits = UART_DATA_5_BITS;
188192
// break;
189193
// case 6:
190-
// word_length = UART_DATA_6_BITS;
194+
// uart_config.data_bits = UART_DATA_6_BITS;
191195
// break;
192196
case 7:
193-
word_length = UART_DATA_7_BITS;
197+
uart_config.data_bits = UART_DATA_7_BITS;
194198
break;
195199
case 8:
196-
word_length = UART_DATA_8_BITS;
200+
uart_config.data_bits = UART_DATA_8_BITS;
197201
break;
198202
default:
199203
// Won't hit this because shared-bindings limits to 7-9 bits. We error on 9 above.
200204
break;
201205
}
202-
uart_set_word_length(self->uart_num, word_length);
206+
// uart_set_word_length(self->uart_num, uart_config.data_bits);
203207

204-
uart_parity_t parity_mode = UART_PARITY_DISABLE;
208+
uart_config.parity = UART_PARITY_DISABLE;
205209
switch (parity) {
206210
case BUSIO_UART_PARITY_NONE:
207-
parity_mode = UART_PARITY_DISABLE;
211+
uart_config.parity = UART_PARITY_DISABLE;
208212
break;
209213
case BUSIO_UART_PARITY_EVEN:
210-
parity_mode = UART_PARITY_EVEN;
214+
uart_config.parity = UART_PARITY_EVEN;
211215
break;
212216
case BUSIO_UART_PARITY_ODD:
213-
parity_mode = UART_PARITY_ODD;
217+
uart_config.parity = UART_PARITY_ODD;
214218
break;
215219
default:
216220
// Won't reach here because the input is an enum that is completely handled.
217221
break;
218222
}
219-
uart_set_parity(self->uart_num, parity_mode);
223+
// uart_set_parity(self->uart_num, uart_config.parity);
220224

221225
// Stop is 1 or 2 always.
222-
uart_stop_bits_t stop_bits = UART_STOP_BITS_1;
226+
uart_config.stop_bits = UART_STOP_BITS_1;
223227
if (stop == 2) {
224-
stop_bits = UART_STOP_BITS_2;
228+
uart_config.stop_bits = UART_STOP_BITS_2;
229+
}
230+
// uart_set_stop_bits(self->uart_num, stop_bits);
231+
uart_config.source_clk = UART_SCLK_APB; // guessing here...
232+
233+
// config all in one?
234+
if (uart_param_config(self->uart_num, &uart_config) != ESP_OK) {
235+
mp_raise_RuntimeError(translate("UART init"));
225236
}
226-
uart_set_stop_bits(self->uart_num, stop_bits);
227237

228238
self->tx_pin = NULL;
229239
self->rx_pin = NULL;

ports/stm/boards/swan_r5/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ CIRCUITPY_BLEIO = 0
7070
CIRCUITPY_BUSDEVICE = 0
7171
CIRCUITPY_KEYPAD = 1
7272
CIRCUITPY_RGBMATRIX = 0
73+
CIRCUITPY_RTC = 1

ports/stm/common-hal/rtc/RTC.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 20212 Matthew McGowan for Blues Wireless Inc
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include <stdio.h>
28+
29+
#include "py/obj.h"
30+
#include "py/runtime.h"
31+
#include "shared/timeutils/timeutils.h"
32+
#include "shared-bindings/rtc/__init__.h"
33+
#include "common-hal/rtc/RTC.h"
34+
#include "shared-bindings/rtc/RTC.h"
35+
#include "supervisor/port.h"
36+
#include "supervisor/shared/translate/translate.h"
37+
#include "peripherals/rtc.h"
38+
39+
40+
void common_hal_rtc_set_time(timeutils_struct_time_t *tm) {
41+
stm32_peripherals_rtc_set_time(tm);
42+
}
43+
44+
void common_hal_rtc_get_time(timeutils_struct_time_t *tm) {
45+
stm32_peripherals_rtc_get_time(tm);
46+
}
47+
48+
int common_hal_rtc_get_calibration(void) {
49+
return 0;
50+
}
51+
52+
void common_hal_rtc_set_calibration(int calibration) {
53+
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_calibration);
54+
}

ports/stm/common-hal/rtc/RTC.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2022 Matthew McGowan for Blues Wireless Inc
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_STM_COMMON_HAL_RTC_RTC_H
28+
#define MICROPY_INCLUDED_STM_COMMON_HAL_RTC_RTC_H
29+
30+
extern void rtc_init(void);
31+
extern void rtc_reset(void);
32+
33+
#endif // MICROPY_INCLUDED_STM_COMMON_HAL_RTC_RTC_H

ports/stm/common-hal/rtc/__init__.c

Whitespace-only changes.

ports/stm/common-hal/rtc/__init__.h

Whitespace-only changes.

ports/stm/mpconfigport.mk

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ifeq ($(MCU_SERIES),F4)
2424
CIRCUITPY_I2CPERIPHERAL ?= 0
2525
CIRCUITPY_NVM ?= 0
2626
CIRCUITPY_ROTARYIO ?= 0
27-
CIRCUITPY_RTC ?= 0
27+
CIRCUITPY_RTC ?= 1
2828
USB_NUM_ENDPOINT_PAIRS = 4
2929
UF2_FAMILY_ID ?= 0x57755a57
3030
endif
@@ -42,7 +42,7 @@ ifeq ($(MCU_SERIES),H7)
4242
CIRCUITPY_PULSEIO ?= 0
4343
CIRCUITPY_PWMIO ?= 0
4444
CIRCUITPY_ROTARYIO ?= 0
45-
CIRCUITPY_RTC ?= 0
45+
CIRCUITPY_RTC ?= 1
4646

4747
USB_NUM_ENDPOINT_PAIRS = 9
4848
UF2_FAMILY_ID ?= 0x6db66082
@@ -59,7 +59,7 @@ ifeq ($(MCU_SERIES),F7)
5959
CIRCUITPY_NEOPIXEL_WRITE ?= 0
6060
CIRCUITPY_NVM ?= 0
6161
CIRCUITPY_ROTARYIO ?= 0
62-
CIRCUITPY_RTC ?= 0
62+
CIRCUITPY_RTC ?= 1
6363

6464
USB_NUM_ENDPOINT_PAIRS = 6
6565
UF2_FAMILY_ID ?= 0x53b80f00
@@ -76,7 +76,7 @@ ifeq ($(MCU_SERIES),L4)
7676
CIRCUITPY_NEOPIXEL_WRITE ?= 0
7777
CIRCUITPY_NVM ?= 0
7878
CIRCUITPY_ROTARYIO ?= 0
79-
CIRCUITPY_RTC ?= 0
79+
CIRCUITPY_RTC ?= 1
8080
# todo - this varies between devices in the series
8181
# This slide deck https://www.st.com/content/ccc/resource/training/technical/product_training/98/89/c8/6c/3e/e9/49/79/STM32L4_Peripheral_USB.pdf/files/STM32L4_Peripheral_USB.pdf/jcr:content/translations/en.STM32L4_Peripheral_USB.pdf
8282
# cites 16 endpoints, 8 endpoint pairs, while section 3.39 of the L4R5 datasheet states 6 endpoint pairs.

ports/stm/peripherals/rtc.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* The MIT License (MIT)
55
*
66
* Copyright (c) 2021 Lucian Copeland for Adafruit Industries
7+
* Copyright (c) 2022 Matthew McGowan for Blues Wireless Inc
78
*
89
* Permission is hereby granted, free of charge, to any person obtaining a copy
910
* of this software and associated documentation files (the "Software"), to deal
@@ -76,6 +77,46 @@ void stm32_peripherals_rtc_init(void) {
7677
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
7778
}
7879

80+
#if CIRCUITPY_RTC
81+
void stm32_peripherals_rtc_get_time(timeutils_struct_time_t *tm) {
82+
RTC_DateTypeDef date = {0};
83+
RTC_TimeTypeDef time = {0};
84+
85+
int code;
86+
if ((code = HAL_RTC_GetTime(&hrtc, &time, RTC_FORMAT_BIN)) == HAL_OK &&
87+
(code = HAL_RTC_GetDate(&hrtc, &date, RTC_FORMAT_BIN)) == HAL_OK) {
88+
tm->tm_hour = time.Hours;
89+
tm->tm_min = time.Minutes;
90+
tm->tm_sec = time.Seconds;
91+
tm->tm_wday = date.WeekDay - 1;
92+
tm->tm_mday = date.Date;
93+
tm->tm_mon = date.Month;
94+
tm->tm_year = date.Year + 2000;
95+
tm->tm_yday = -1;
96+
}
97+
}
98+
99+
void stm32_peripherals_rtc_set_time(timeutils_struct_time_t *tm) {
100+
RTC_DateTypeDef date = {0};
101+
RTC_TimeTypeDef time = {0};
102+
103+
time.Hours = tm->tm_hour;
104+
time.Minutes = tm->tm_min;
105+
time.Seconds = tm->tm_sec;
106+
date.WeekDay = tm->tm_wday + 1;
107+
date.Date = tm->tm_mday;
108+
date.Month = tm->tm_mon;
109+
date.Year = tm->tm_year - 2000;
110+
time.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
111+
time.StoreOperation = RTC_STOREOPERATION_RESET;
112+
113+
if (HAL_RTC_SetTime(&hrtc, &time, RTC_FORMAT_BIN) != HAL_OK ||
114+
HAL_RTC_SetDate(&hrtc, &date, RTC_FORMAT_BIN) != HAL_OK) {
115+
// todo - throw an exception
116+
}
117+
}
118+
#endif
119+
79120
// This function is called often for timing so we cache the seconds elapsed computation based on the
80121
// register value. The STM HAL always does shifts and conversion if we use it directly.
81122
uint64_t stm32_peripherals_rtc_raw_ticks(uint8_t *subticks) {

ports/stm/peripherals/rtc.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* The MIT License (MIT)
55
*
66
* Copyright (c) 2021 Lucian Copeland for Adafruit Industries
7+
* Copyright (c) 2022 Matthew McGowan for Blues Wireless Inc
78
*
89
* Permission is hereby granted, free of charge, to any person obtaining a copy
910
* 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
4849
void stm32_peripherals_rtc_set_alarm(uint8_t alarm_idx, uint32_t ticks);
4950
bool stm32_peripherals_rtc_alarm_triggered(uint8_t alarm_idx);
5051

52+
#if CIRCUITPY_RTC
53+
typedef struct _timeutils_struct_time_t timeutils_struct_time_t;
54+
void stm32_peripherals_rtc_get_time(timeutils_struct_time_t *tm);
55+
void stm32_peripherals_rtc_set_time(timeutils_struct_time_t *tm);
56+
#endif
57+
5158
#endif // __MICROPY_INCLUDED_STM32_PERIPHERALS_RTC_H__

ports/stm/supervisor/port.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
#if CIRCUITPY_ALARM
6262
#include "common-hal/alarm/__init__.h"
6363
#endif
64+
#if CIRCUITPY_RTC
65+
#include "shared-bindings/rtc/__init__.h"
66+
#endif
6467

6568
#include "peripherals/clocks.h"
6669
#include "peripherals/gpio.h"
@@ -241,6 +244,10 @@ void SysTick_Handler(void) {
241244

242245
void reset_port(void) {
243246
reset_all_pins();
247+
#if CIRCUITPY_RTC
248+
rtc_reset();
249+
#endif
250+
244251
#if CIRCUITPY_AUDIOPWMIO
245252
audiopwmout_reset();
246253
#endif

py/circuitpy_mpconfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ typedef long mp_off_t;
226226
#ifndef MICROPY_PY_COLLECTIONS_ORDEREDDICT
227227
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (CIRCUITPY_FULL_BUILD)
228228
#endif
229+
#ifndef MICROPY_PY_COLLECTIONS_DEQUE
230+
#define MICROPY_PY_COLLECTIONS_DEQUE (CIRCUITPY_FULL_BUILD)
231+
#endif
229232
#define MICROPY_PY_URE_MATCH_GROUPS (CIRCUITPY_RE)
230233
#define MICROPY_PY_URE_MATCH_SPAN_START_END (CIRCUITPY_RE)
231234
#define MICROPY_PY_URE_SUB (CIRCUITPY_RE)

0 commit comments

Comments
 (0)