Skip to content

Commit 4358b44

Browse files
authored
Merge pull request #10819 from dhalbert/improved-settings-toml-fetching
add supervisor.get_setting(); change os.getenv() behavior
2 parents 8d17d0c + 4b2111e commit 4358b44

File tree

33 files changed

+723
-610
lines changed

33 files changed

+723
-610
lines changed

devices/ble_hci/common-hal/_bleio/Adapter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include "shared-bindings/_bleio/ScanEntry.h"
3030
#include "shared-bindings/time/__init__.h"
3131

32-
#if CIRCUITPY_OS_GETENV
32+
#if CIRCUITPY_SETTINGS_TOML
3333
#include "shared-bindings/os/__init__.h"
3434
#endif
3535

@@ -261,7 +261,7 @@ static void _adapter_set_name(bleio_adapter_obj_t *self, mp_obj_str_t *name_obj)
261261
static void bleio_adapter_hci_init(bleio_adapter_obj_t *self) {
262262
mp_int_t name_len = 0;
263263

264-
#if CIRCUITPY_OS_GETENV
264+
#if CIRCUITPY_SETTINGS_TOML
265265
mp_obj_t name = common_hal_os_getenv("CIRCUITPY_BLE_NAME", mp_const_none);
266266
if (name != mp_const_none) {
267267
mp_arg_validate_type_string(name, MP_QSTR_CIRCUITPY_BLE_NAME);

docs/environment.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ Allows the entry of a display scaling factor used during the terminalio console
187187
The entered scaling factor only affects the terminalio console and has no impact on
188188
the UART, Web Workflow, BLE Workflow, etc consoles.
189189

190-
This feature is not enabled on boards that the CIRCUITPY_OS_GETENV (os CIRCUIPTY_FULL_BUILD)
190+
This feature is not enabled on boards that the CIRCUITPY_SETTINGS_TOML (or CIRCUITPY_FULL_BUILD)
191191
flag has been set to 0. Currently this is primarily boards with limited flash including some
192192
of the Atmel_samd boards based on the SAMD21/M0 microprocessor.
193193

@@ -197,7 +197,7 @@ Specifies a custom font file path to use for the terminalio console instead of t
197197
``/fonts/terminal.lvfontbin``. This allows users to create and use custom fonts for the
198198
CircuitPython console.
199199

200-
This feature requires both CIRCUITPY_OS_GETENV and CIRCUITPY_LVFONTIO to be enabled.
200+
This feature requires both CIRCUITPY_SETTINGS_TOML and CIRCUITPY_LVFONTIO to be enabled.
201201

202202
Example:
203203

docs/shared_bindings_matrix.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@
8484
"keypad.Keys": "CIRCUITPY_KEYPAD_KEYS",
8585
"keypad.ShiftRegisterKeys": "CIRCUITPY_KEYPAD_SHIFTREGISTERKEYS",
8686
"keypad_demux.DemuxKeyMatrix": "CIRCUITPY_KEYPAD_DEMUX",
87-
"os.getenv": "CIRCUITPY_OS_GETENV",
87+
"os.getenv": "CIRCUITPY_SETTINGS_TOML",
8888
"select": "MICROPY_PY_SELECT_SELECT",
89+
"supervisor.get_setting": "CIRCUITPY_SETTINGS_TOML",
8990
"sys": "CIRCUITPY_SYS",
9091
"terminalio": "CIRCUITPY_DISPLAYIO",
9192
"usb": "CIRCUITPY_PYUSB",

locale/circuitpython.pot

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ msgstr ""
583583
msgid "Already scanning for wifi networks"
584584
msgstr ""
585585

586-
#: shared-module/os/getenv.c
586+
#: supervisor/shared/settings.c
587587
#, c-format
588588
msgid "An error occurred while retrieving '%s':\n"
589589
msgstr ""
@@ -1092,7 +1092,6 @@ msgid "File exists"
10921092
msgstr ""
10931093

10941094
#: shared-bindings/supervisor/__init__.c shared-module/lvfontio/OnDiskFont.c
1095-
#: shared-module/os/getenv.c
10961095
msgid "File not found"
10971096
msgstr ""
10981097

@@ -1243,7 +1242,7 @@ msgstr ""
12431242
msgid "Internal define error"
12441243
msgstr ""
12451244

1246-
#: shared-bindings/pwmio/PWMOut.c shared-module/os/getenv.c
1245+
#: shared-bindings/pwmio/PWMOut.c supervisor/shared/settings.c
12471246
msgid "Internal error"
12481247
msgstr ""
12491248

@@ -1340,17 +1339,12 @@ msgstr ""
13401339
msgid "Invalid bits per value"
13411340
msgstr ""
13421341

1343-
#: shared-module/os/getenv.c
1344-
#, c-format
1345-
msgid "Invalid byte %.*s"
1346-
msgstr ""
1347-
13481342
#: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c
13491343
#, c-format
13501344
msgid "Invalid data_pins[%d]"
13511345
msgstr ""
13521346

1353-
#: shared-module/msgpack/__init__.c
1347+
#: shared-module/msgpack/__init__.c supervisor/shared/settings.c
13541348
msgid "Invalid format"
13551349
msgstr ""
13561350

@@ -1381,18 +1375,14 @@ msgstr ""
13811375
msgid "Invalid state"
13821376
msgstr ""
13831377

1384-
#: shared-module/os/getenv.c
1378+
#: supervisor/shared/settings.c
13851379
msgid "Invalid unicode escape"
13861380
msgstr ""
13871381

13881382
#: shared-bindings/aesio/aes.c
13891383
msgid "Key must be 16, 24, or 32 bytes long"
13901384
msgstr ""
13911385

1392-
#: shared-module/os/getenv.c
1393-
msgid "Key not found"
1394-
msgstr ""
1395-
13961386
#: shared-module/is31fl3741/FrameBuffer.c
13971387
msgid "LED mappings must match display size"
13981388
msgstr ""

main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@
113113
uint8_t value_out = 0;
114114
#endif
115115

116-
#if MICROPY_ENABLE_PYSTACK && CIRCUITPY_OS_GETENV
117-
#include "shared-module/os/__init__.h"
116+
#if CIRCUITPY_SETTINGS_TOML
117+
#include "supervisor/shared/settings.h"
118118
#endif
119119

120120
static void reset_devices(void) {
@@ -132,17 +132,17 @@ static const char line_clear[] = "\x1b[2K\x1b[0G";
132132
#if MICROPY_ENABLE_PYSTACK || MICROPY_ENABLE_GC
133133
static uint8_t *_allocate_memory(safe_mode_t safe_mode, const char *env_key, size_t default_size, size_t *final_size) {
134134
*final_size = default_size;
135-
#if CIRCUITPY_OS_GETENV
135+
#if CIRCUITPY_SETTINGS_TOML
136136
if (safe_mode == SAFE_MODE_NONE) {
137137
mp_int_t size;
138-
if (common_hal_os_getenv_int(env_key, &size) == GETENV_OK && size > 0) {
138+
if (settings_get_int(env_key, &size) == SETTINGS_OK && size > 0) {
139139
*final_size = size;
140140
}
141141
}
142142
#endif
143143
uint8_t *ptr = port_malloc(*final_size, false);
144144

145-
#if CIRCUITPY_OS_GETENV
145+
#if CIRCUITPY_SETTINGS_TOML
146146
if (ptr == NULL) {
147147
// Fallback to the build size.
148148
ptr = port_malloc(default_size, false);

ports/atmel-samd/mpconfigport.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ CIRCUITPY_I2CTARGET ?= 0
4848
CIRCUITPY_JSON ?= 0
4949
CIRCUITPY_KEYPAD ?= 0
5050
CIRCUITPY_MSGPACK ?= 0
51-
CIRCUITPY_OS_GETENV ?= 0
5251
CIRCUITPY_PIXELMAP ?= 0
5352
CIRCUITPY_RE ?= 0
5453
CIRCUITPY_SDCARDIO ?= 0
54+
CIRCUITPY_SETTINGS_TOML ?= 0
5555
CIRCUITPY_SPITARGET ?= 0
5656
CIRCUITPY_SYNTHIO ?= 0
5757
CIRCUITPY_TOUCHIO_USE_NATIVE ?= 1

ports/espressif/boards/makerfabs_tft7/board.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77
#include "supervisor/board.h"
88
#include "mpconfigboard.h"
9+
910
#include "shared-bindings/board/__init__.h"
1011
#include "shared-bindings/dotclockframebuffer/DotClockFramebuffer.h"
1112
#include "shared-bindings/dotclockframebuffer/__init__.h"
1213
#include "shared-bindings/framebufferio/FramebufferDisplay.h"
1314
#include "shared-bindings/microcontroller/Pin.h"
1415
#include "shared-module/displayio/__init__.h"
15-
#include "shared-module/os/__init__.h"
16+
#include "supervisor/shared/settings.h"
1617

1718
static const mcu_pin_obj_t *blue_pins[] = {
1819
&pin_GPIO8,
@@ -40,14 +41,14 @@ static const mcu_pin_obj_t *red_pins[] = {
4041
static void display_init(void) {
4142

4243
mp_int_t height = 0, width = 0, frequency = 0;
43-
os_getenv_err_t result;
44+
settings_err_t result;
4445

45-
result = common_hal_os_getenv_int("CIRCUITPY_DISPLAY_WIDTH", &width);
46-
if (result == GETENV_OK && width == 800) {
46+
result = settings_get_int("CIRCUITPY_DISPLAY_WIDTH", &width);
47+
if (result == SETTINGS_OK && width == 800) {
4748
width = 800;
4849
height = 480;
4950
frequency = 6500000;
50-
} else if (result == GETENV_OK && width == 1024) {
51+
} else if (result == SETTINGS_OK && width == 1024) {
5152
width = 1024;
5253
height = 600;
5354
frequency = 10000000;

ports/espressif/boards/sunton_esp32_2432S024C/board.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77
#include "supervisor/board.h"
88
#include "mpconfigboard.h"
9+
10+
#include "common-hal/microcontroller/Pin.h"
11+
#include "driver/gpio.h"
912
#include "shared-bindings/board/__init__.h"
1013
#include "shared-bindings/microcontroller/Pin.h"
1114
#include "shared-module/displayio/__init__.h"
1215
#include "shared-module/displayio/mipi_constants.h"
13-
#include "driver/gpio.h"
14-
#include "common-hal/microcontroller/Pin.h"
15-
#include "shared-module/os/__init__.h"
16+
#include "supervisor/shared/settings.h"
1617

1718
uint8_t display_init_sequence[] = {
1819
0x01, 0x80, 0x80, // # Software reset then delay 0x80 (128ms)
@@ -59,8 +60,8 @@ static void display_init(void) {
5960

6061
busdisplay_busdisplay_obj_t *display = &allocate_display()->display;
6162
display->base.type = &busdisplay_busdisplay_type;
62-
os_getenv_err_t result = common_hal_os_getenv_int("CIRCUITPY_DISPLAY_ROTATION", &rotation);
63-
if (result != GETENV_OK) {
63+
settings_err_t result = settings_get_int("CIRCUITPY_DISPLAY_ROTATION", &rotation);
64+
if (result != SETTINGS_OK) {
6465
rotation = 0;
6566
}
6667

ports/espressif/boards/sunton_esp32_2432S028/board.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77
#include "supervisor/board.h"
88
#include "mpconfigboard.h"
9+
10+
#include "common-hal/microcontroller/Pin.h"
11+
#include "driver/gpio.h"
912
#include "shared-bindings/board/__init__.h"
1013
#include "shared-bindings/microcontroller/Pin.h"
1114
#include "shared-module/displayio/__init__.h"
1215
#include "shared-module/displayio/mipi_constants.h"
13-
#include "driver/gpio.h"
14-
#include "common-hal/microcontroller/Pin.h"
15-
#include "shared-module/os/__init__.h"
16+
#include "supervisor/shared/settings.h"
1617

1718
uint8_t display_init_sequence[] = {
1819
0x01, 0x80, 0x80, // # Software reset then delay 0x80 (128ms)
@@ -59,8 +60,8 @@ static void display_init(void) {
5960

6061
busdisplay_busdisplay_obj_t *display = &allocate_display()->display;
6162
display->base.type = &busdisplay_busdisplay_type;
62-
os_getenv_err_t result = common_hal_os_getenv_int("CIRCUITPY_DISPLAY_ROTATION", &rotation);
63-
if (result != GETENV_OK) {
63+
settings_err_t result = settings_get_int("CIRCUITPY_DISPLAY_ROTATION", &rotation);
64+
if (result != SETTINGS_OK) {
6465
rotation = 0;
6566
}
6667

ports/espressif/boards/sunton_esp32_8048S050/board.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77
#include "supervisor/board.h"
88
#include "mpconfigboard.h"
9+
910
#include "shared-bindings/board/__init__.h"
1011
#include "shared-bindings/dotclockframebuffer/DotClockFramebuffer.h"
1112
#include "shared-bindings/dotclockframebuffer/__init__.h"
1213
#include "shared-bindings/framebufferio/FramebufferDisplay.h"
1314
#include "shared-bindings/microcontroller/Pin.h"
1415
#include "shared-module/displayio/__init__.h"
15-
#include "shared-module/os/__init__.h"
16+
#include "supervisor/shared/settings.h"
1617

1718
static const mcu_pin_obj_t *blue_pins[] = {
1819
&pin_GPIO8,
@@ -47,8 +48,8 @@ static void display_init(void) {
4748

4849
dotclockframebuffer_framebuffer_obj_t *framebuffer = &allocate_display_bus_or_raise()->dotclock;
4950
framebuffer->base.type = &dotclockframebuffer_framebuffer_type;
50-
os_getenv_err_t result = common_hal_os_getenv_int("CIRCUITPY_DISPLAY_FREQUENCY", &frequency);
51-
if (result != GETENV_OK) {
51+
settings_err_t result = settings_get_int("CIRCUITPY_DISPLAY_FREQUENCY", &frequency);
52+
if (result != SETTINGS_OK) {
5253
frequency = 12500000;
5354
}
5455

0 commit comments

Comments
 (0)