Skip to content

Commit 12be7b1

Browse files
committed
Merge remote-tracking branch 'origin/main'
2 parents 9286446 + 5192082 commit 12be7b1

File tree

53 files changed

+722
-235
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+722
-235
lines changed

docs/shared_bindings_matrix.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import re
2828
import subprocess
2929
import sys
30+
import functools
3031

3132
from concurrent.futures import ThreadPoolExecutor
3233

@@ -80,12 +81,11 @@
8081
repository_urls = {}
8182
"""Cache of repository URLs for frozen modules."""
8283

84+
root_dir = pathlib.Path(__file__).resolve().parent.parent
85+
8386
def get_circuitpython_root_dir():
8487
""" The path to the root './circuitpython' directory.
8588
"""
86-
file_path = pathlib.Path(__file__).resolve()
87-
root_dir = file_path.parent.parent
88-
8989
return root_dir
9090

9191
def get_shared_bindings():
@@ -102,7 +102,7 @@ def get_board_mapping():
102102
"""
103103
boards = {}
104104
for port in SUPPORTED_PORTS:
105-
board_path = os.path.join("../ports", port, "boards")
105+
board_path = root_dir / "ports" / port / "boards"
106106
for board_path in os.scandir(board_path):
107107
if board_path.is_dir():
108108
board_files = os.listdir(board_path.path)
@@ -276,6 +276,7 @@ def lookup_setting(settings, key, default=''):
276276
key = value[2:-1]
277277
return value
278278

279+
@functools.cache
279280
def all_ports_all_boards(ports=SUPPORTED_PORTS):
280281
for port in ports:
281282

extmod/moduselect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include <stdio.h>
1111

12-
#include "py/ioctl.h"
12+
#include "py/stream.h"
1313
#include "py/runtime.h"
1414
#include "py/obj.h"
1515
#include "py/objlist.h"

extmod/vfs_fat.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,35 @@ STATIC mp_obj_t vfs_fat_umount(mp_obj_t self_in) {
400400
}
401401
STATIC MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_umount_obj, vfs_fat_umount);
402402

403+
STATIC mp_obj_t vfs_fat_utime(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t times_in) {
404+
mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in);
405+
const char *path = mp_obj_str_get_str(path_in);
406+
if (!mp_obj_is_tuple_compatible(times_in)) {
407+
mp_raise_type_arg(&mp_type_TypeError, times_in);
408+
}
409+
410+
mp_obj_t *otimes;
411+
mp_obj_get_array_fixed_n(times_in, 2, &otimes);
412+
413+
// Validate that both elements of the tuple are int and discard the second one
414+
int time[2];
415+
time[0] = mp_obj_get_int(otimes[0]);
416+
time[1] = mp_obj_get_int(otimes[1]);
417+
timeutils_struct_time_t tm;
418+
timeutils_seconds_since_epoch_to_struct_time(time[0], &tm);
419+
420+
FILINFO fno;
421+
fno.fdate = (WORD)(((tm.tm_year - 1980) * 512U) | tm.tm_mon * 32U | tm.tm_mday);
422+
fno.ftime = (WORD)(tm.tm_hour * 2048U | tm.tm_min * 32U | tm.tm_sec / 2U);
423+
FRESULT res = f_utime(&self->fatfs, path, &fno);
424+
if (res != FR_OK) {
425+
mp_raise_OSError_fresult(res);
426+
}
427+
428+
return mp_const_none;
429+
}
430+
STATIC MP_DEFINE_CONST_FUN_OBJ_3(fat_vfs_utime_obj, vfs_fat_utime);
431+
403432
#if MICROPY_FATFS_USE_LABEL
404433
STATIC mp_obj_t vfs_fat_getlabel(mp_obj_t self_in) {
405434
fs_user_mount_t *self = MP_OBJ_TO_PTR(self_in);
@@ -451,6 +480,7 @@ STATIC const mp_rom_map_elem_t fat_vfs_locals_dict_table[] = {
451480
{ MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&fat_vfs_statvfs_obj) },
452481
{ MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&vfs_fat_mount_obj) },
453482
{ MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&fat_vfs_umount_obj) },
483+
{ MP_ROM_QSTR(MP_QSTR_utime), MP_ROM_PTR(&fat_vfs_utime_obj) },
454484
#if MICROPY_FATFS_USE_LABEL
455485
{ MP_ROM_QSTR(MP_QSTR_label), MP_ROM_PTR(&fat_vfs_label_obj) },
456486
#endif

locale/circuitpython.pot

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ msgstr ""
117117
msgid "%q init failed"
118118
msgstr ""
119119

120+
#: shared-bindings/dualbank/__init__.c
121+
msgid "%q is %q"
122+
msgstr ""
123+
120124
#: py/argcheck.c
121125
msgid "%q length must be %d"
122126
msgstr ""
@@ -211,7 +215,7 @@ msgstr ""
211215
msgid "%q, %q, and %q must all be the same length"
212216
msgstr ""
213217

214-
#: py/objint.c
218+
#: py/objint.c shared-bindings/storage/__init__.c
215219
msgid "%q=%q"
216220
msgstr ""
217221

@@ -1001,7 +1005,15 @@ msgid "Filters too complex"
10011005
msgstr ""
10021006

10031007
#: ports/espressif/common-hal/dualbank/__init__.c
1004-
msgid "Firmware image is invalid"
1008+
msgid "Firmware is duplicate"
1009+
msgstr ""
1010+
1011+
#: ports/espressif/common-hal/dualbank/__init__.c
1012+
msgid "Firmware is invalid"
1013+
msgstr ""
1014+
1015+
#: ports/espressif/common-hal/dualbank/__init__.c
1016+
msgid "Firmware is too big"
10051017
msgstr ""
10061018

10071019
#: shared-bindings/bitmaptools/__init__.c
@@ -4151,7 +4163,7 @@ msgstr ""
41514163
msgid "unexpected keyword argument"
41524164
msgstr ""
41534165

4154-
#: py/bc.c py/objnamedtuple.c
4166+
#: py/bc.c py/objnamedtuple.c shared-bindings/traceback/__init__.c
41554167
msgid "unexpected keyword argument '%q'"
41564168
msgstr ""
41574169

ports/atmel-samd/boards/arduino_mkr1300/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ CIRCUITPY_BUILD_EXTENSIONS = bin,uf2
1111
INTERNAL_FLASH_FILESYSTEM = 1
1212
LONGINT_IMPL = NONE
1313
CIRCUITPY_FULL_BUILD = 0
14+
15+
CIRCUITPY_RAINBOWIO = 0

ports/atmel-samd/boards/arduino_nano_33_iot/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ CIRCUITPY_BUILD_EXTENSIONS = bin,uf2
1111
INTERNAL_FLASH_FILESYSTEM = 1
1212
LONGINT_IMPL = NONE
1313
CIRCUITPY_FULL_BUILD = 0
14+
1415
CIRCUITPY_RAINBOWIO = 0

ports/atmel-samd/boards/feather_m0_rfm69/mpconfigboard.mk

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ CIRCUITPY_FULL_BUILD = 0
1515
# A number of modules are removed for RFM69 to make room for frozen libraries.
1616
# Many I/O functions are not available.
1717
CIRCUITPY_ANALOGIO = 1
18+
CIRCUITPY_BUSDEVICE = 1
19+
CIRCUITPY_RAINBOWIO = 0
1820
CIRCUITPY_ROTARYIO = 0
1921
CIRCUITPY_RTC = 0
22+
CIRCUITPY_TOUCHIO = 0
2023
CIRCUITPY_USB_MIDI = 0
2124
CIRCUITPY_USB_HID = 0
22-
CIRCUITPY_TOUCHIO = 0
23-
CIRCUITPY_BUSDEVICE = 1
2425

2526
# Include these Python libraries in firmware.
2627
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_RFM69

ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ CIRCUITPY_BITBANG_APA102 = 0
2020
CIRCUITPY_FREQUENCYIO = 0
2121
CIRCUITPY_I2CTARGET = 0
2222
CIRCUITPY_NEOPIXEL_WRITE = 0
23+
CIRCUITPY_ONEWIREIO = 0
2324
CIRCUITPY_PARALLELDISPLAY = 0
2425
CIRCUITPY_PIXELBUF = 0
2526
CIRCUITPY_PS2IO = 0
2627
CIRCUITPY_PULSEIO = 0
2728
CIRCUITPY_PWMIO = 0
29+
CIRCUITPY_RAINBOWIO = 0
2830
CIRCUITPY_ROTARYIO = 0
2931
CIRCUITPY_RTC = 0
3032
CIRCUITPY_SAMD = 0

ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ CHIP_FAMILY = samd21
99
SPI_FLASH_FILESYSTEM = 1
1010
EXTERNAL_FLASH_DEVICES = "W25Q32FV"
1111
LONGINT_IMPL = MPZ
12+
13+
CIRCUITPY_RAINBOWIO = 0

ports/atmel-samd/common-hal/microcontroller/Processor.c

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -73,101 +73,99 @@
7373
#include "peripheral_clk_config.h"
7474

7575
#define ADC_TEMP_SAMPLE_LENGTH 4
76-
#define INT1V_VALUE_FLOAT 1.0
77-
#define INT1V_DIVIDER_1000 1000.0
78-
#define ADC_12BIT_FULL_SCALE_VALUE_FLOAT 4095.0
76+
#define INT1V_VALUE_FLOAT MICROPY_FLOAT_CONST(1.0)
77+
#define INT1V_DIVIDER_1000 MICROPY_FLOAT_CONST(1000.0)
78+
#define ADC_12BIT_FULL_SCALE_VALUE_FLOAT MICROPY_FLOAT_CONST(4095.0)
7979

8080
// channel argument (ignored in calls below)
8181
#define IGNORED_CHANNEL 0
8282

83-
// Decimal to fraction conversion. (adapted from ASF sample).
84-
STATIC float convert_dec_to_frac(uint8_t val) {
85-
float float_val = (float)val;
86-
if (val < 10) {
87-
return float_val / 10.0;
88-
} else if (val < 100) {
89-
return float_val / 100.0;
90-
} else {
91-
return float_val / 1000.0;
92-
}
93-
}
9483

9584
// Extract the production calibration data information from NVM (adapted from ASF sample),
9685
// then calculate the temperature
86+
//
87+
// This code performs almost all operations with scaled integers. For
88+
// instance, tempR is in units of 1/10°C, INT1VR is in units of 1mV, etc,
89+
// This is important to reduce the code size of the function. The effect on
90+
// precision is a ~.9°C difference vs the floating point algorithm on an
91+
// approximate 0..60°C range with a difference of ~.5°C at 25°C. When the fine
92+
// calculation step is skipped, the additional error approximately doubles.
93+
//
94+
// To save code size, rounding is neglected. However, trying to add back rounding
95+
// (by computing (a + b/2) / b instead of just a / b) actually didn't help
96+
// accuracy anyway.
9797
#ifdef SAMD21
9898
STATIC float calculate_temperature(uint16_t raw_value) {
99-
volatile uint32_t val1; /* Temperature Log Row Content first 32 bits */
100-
volatile uint32_t val2; /* Temperature Log Row Content another 32 bits */
101-
uint8_t room_temp_val_int; /* Integer part of room temperature in °C */
102-
uint8_t room_temp_val_dec; /* Decimal part of room temperature in °C */
103-
uint8_t hot_temp_val_int; /* Integer part of hot temperature in °C */
104-
uint8_t hot_temp_val_dec; /* Decimal part of hot temperature in °C */
105-
int8_t room_int1v_val; /* internal 1V reference drift at room temperature */
106-
int8_t hot_int1v_val; /* internal 1V reference drift at hot temperature*/
107-
108-
float tempR; // Production Room temperature
109-
float tempH; // Production Hot temperature
110-
float INT1VR; // Room temp 2's complement of the internal 1V reference value
111-
float INT1VH; // Hot temp 2's complement of the internal 1V reference value
112-
uint16_t ADCR; // Production Room temperature ADC value
113-
uint16_t ADCH; // Production Hot temperature ADC value
114-
float VADCR; // Room temperature ADC voltage
115-
float VADCH; // Hot temperature ADC voltage
99+
uint32_t val1; /* Temperature Log Row Content first 32 bits */
100+
uint32_t val2; /* Temperature Log Row Content another 32 bits */
101+
int room_temp_val_int; /* Integer part of room temperature in °C */
102+
int room_temp_val_dec; /* Decimal part of room temperature in °C */
103+
int hot_temp_val_int; /* Integer part of hot temperature in °C */
104+
int hot_temp_val_dec; /* Decimal part of hot temperature in °C */
105+
int room_int1v_val; /* internal 1V reference drift at room temperature */
106+
int hot_int1v_val; /* internal 1V reference drift at hot temperature*/
116107

117108
uint32_t *temp_log_row_ptr = (uint32_t *)NVMCTRL_TEMP_LOG;
118109

119110
val1 = *temp_log_row_ptr;
120111
temp_log_row_ptr++;
121112
val2 = *temp_log_row_ptr;
122113

123-
room_temp_val_int = (uint8_t)((val1 & FUSES_ROOM_TEMP_VAL_INT_Msk) >> FUSES_ROOM_TEMP_VAL_INT_Pos);
124-
room_temp_val_dec = (uint8_t)((val1 & FUSES_ROOM_TEMP_VAL_DEC_Msk) >> FUSES_ROOM_TEMP_VAL_DEC_Pos);
114+
room_temp_val_int = ((val1 & FUSES_ROOM_TEMP_VAL_INT_Msk) >> FUSES_ROOM_TEMP_VAL_INT_Pos);
115+
room_temp_val_dec = ((val1 & FUSES_ROOM_TEMP_VAL_DEC_Msk) >> FUSES_ROOM_TEMP_VAL_DEC_Pos);
125116

126-
hot_temp_val_int = (uint8_t)((val1 & FUSES_HOT_TEMP_VAL_INT_Msk) >> FUSES_HOT_TEMP_VAL_INT_Pos);
127-
hot_temp_val_dec = (uint8_t)((val1 & FUSES_HOT_TEMP_VAL_DEC_Msk) >> FUSES_HOT_TEMP_VAL_DEC_Pos);
117+
hot_temp_val_int = ((val1 & FUSES_HOT_TEMP_VAL_INT_Msk) >> FUSES_HOT_TEMP_VAL_INT_Pos);
118+
hot_temp_val_dec = ((val1 & FUSES_HOT_TEMP_VAL_DEC_Msk) >> FUSES_HOT_TEMP_VAL_DEC_Pos);
128119

120+
// necessary casts: must interpret 8 bits as signed
129121
room_int1v_val = (int8_t)((val1 & FUSES_ROOM_INT1V_VAL_Msk) >> FUSES_ROOM_INT1V_VAL_Pos);
130122
hot_int1v_val = (int8_t)((val2 & FUSES_HOT_INT1V_VAL_Msk) >> FUSES_HOT_INT1V_VAL_Pos);
131123

132-
ADCR = (uint16_t)((val2 & FUSES_ROOM_ADC_VAL_Msk) >> FUSES_ROOM_ADC_VAL_Pos);
133-
ADCH = (uint16_t)((val2 & FUSES_HOT_ADC_VAL_Msk) >> FUSES_HOT_ADC_VAL_Pos);
134-
135-
tempR = room_temp_val_int + convert_dec_to_frac(room_temp_val_dec);
136-
tempH = hot_temp_val_int + convert_dec_to_frac(hot_temp_val_dec);
124+
int ADCR = ((val2 & FUSES_ROOM_ADC_VAL_Msk) >> FUSES_ROOM_ADC_VAL_Pos);
125+
int ADCH = ((val2 & FUSES_HOT_ADC_VAL_Msk) >> FUSES_HOT_ADC_VAL_Pos);
137126

138-
INT1VR = 1 - ((float)room_int1v_val / INT1V_DIVIDER_1000);
139-
INT1VH = 1 - ((float)hot_int1v_val / INT1V_DIVIDER_1000);
127+
int tempR = 10 * room_temp_val_int + room_temp_val_dec;
128+
int tempH = 10 * hot_temp_val_int + hot_temp_val_dec;
140129

141-
VADCR = ((float)ADCR * INT1VR) / ADC_12BIT_FULL_SCALE_VALUE_FLOAT;
142-
VADCH = ((float)ADCH * INT1VH) / ADC_12BIT_FULL_SCALE_VALUE_FLOAT;
130+
int INT1VR = 1000 - room_int1v_val;
131+
int INT1VH = 1000 - hot_int1v_val;
143132

144-
float VADC; /* Voltage calculation using ADC result for Coarse Temp calculation */
145-
float VADCM; /* Voltage calculation using ADC result for Fine Temp calculation. */
146-
float INT1VM; /* Voltage calculation for reality INT1V value during the ADC conversion */
133+
int VADCR = ADCR * INT1VR;
134+
int VADCH = ADCH * INT1VH;
147135

148-
VADC = ((float)raw_value * INT1V_VALUE_FLOAT) / ADC_12BIT_FULL_SCALE_VALUE_FLOAT;
136+
int VADC = raw_value * 1000;
149137

150138
// Hopefully compiler will remove common subepxressions here.
151139

152140
// calculate fine temperature using Equation1 and Equation
153141
// 1b as mentioned in data sheet section "Temperature Sensor Characteristics"
154142
// of Electrical Characteristics. (adapted from ASF sample code).
155143
// Coarse Temp Calculation by assume INT1V=1V for this ADC conversion
156-
float coarse_temp = tempR + (((tempH - tempR) / (VADCH - VADCR)) * (VADC - VADCR));
144+
int coarse_temp = tempR + (tempH - tempR) * (VADC - VADCR) / (VADCH - VADCR);
157145

146+
#if CIRCUITPY_FULL_BUILD
158147
// Calculation to find the real INT1V value during the ADC conversion
148+
int INT1VM; /* Voltage calculation for reality INT1V value during the ADC conversion */
149+
159150
INT1VM = INT1VR + (((INT1VH - INT1VR) * (coarse_temp - tempR)) / (tempH - tempR));
160151

161-
VADCM = ((float)raw_value * INT1VM) / ADC_12BIT_FULL_SCALE_VALUE_FLOAT;
152+
int VADCM = raw_value * INT1VM;
162153

163154
// Fine Temp Calculation by replace INT1V=1V by INT1V = INT1Vm for ADC conversion
164-
float fine_temp = tempR + (((tempH - tempR) / (VADCH - VADCR)) * (VADCM - VADCR));
155+
float fine_temp = tempR + (((tempH - tempR) * (VADCM - VADCR)) / (VADCH - VADCR));
165156

166-
return fine_temp;
157+
return fine_temp / 10;
158+
#else
159+
return coarse_temp / 10.;
160+
#endif
167161
}
168162
#endif // SAMD21
169163

170164
#ifdef SAM_D5X_E5X
165+
// Decimal to fraction conversion. (adapted from ASF sample).
166+
STATIC float convert_dec_to_frac(uint8_t val) {
167+
return val / MICROPY_FLOAT_CONST(10.);
168+
}
171169
STATIC float calculate_temperature(uint16_t TP, uint16_t TC) {
172170
uint32_t TLI = (*(uint32_t *)FUSES_ROOM_TEMP_VAL_INT_ADDR & FUSES_ROOM_TEMP_VAL_INT_Msk) >> FUSES_ROOM_TEMP_VAL_INT_Pos;
173171
uint32_t TLD = (*(uint32_t *)FUSES_ROOM_TEMP_VAL_DEC_ADDR & FUSES_ROOM_TEMP_VAL_DEC_Msk) >> FUSES_ROOM_TEMP_VAL_DEC_Pos;

0 commit comments

Comments
 (0)