From 9e626fdd5cec32fbd3761af5683d58a47fe32194 Mon Sep 17 00:00:00 2001 From: Seth Kerr Date: Sun, 14 Feb 2021 20:00:32 -0500 Subject: [PATCH 001/103] new cp sapling board --- .../boards/cp_sapling_m0_revb/board.c | 40 +++++++++++++ .../boards/cp_sapling_m0_revb/mpconfigboard.h | 54 +++++++++++++++++ .../cp_sapling_m0_revb/mpconfigboard.mk | 24 ++++++++ .../boards/cp_sapling_m0_revb/pins.c | 60 +++++++++++++++++++ 4 files changed, 178 insertions(+) create mode 100644 ports/atmel-samd/boards/cp_sapling_m0_revb/board.c create mode 100644 ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.h create mode 100644 ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk create mode 100644 ports/atmel-samd/boards/cp_sapling_m0_revb/pins.c diff --git a/ports/atmel-samd/boards/cp_sapling_m0_revb/board.c b/ports/atmel-samd/boards/cp_sapling_m0_revb/board.c new file mode 100644 index 0000000000..cde441b3d9 --- /dev/null +++ b/ports/atmel-samd/boards/cp_sapling_m0_revb/board.c @@ -0,0 +1,40 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * 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 "supervisor/board.h" +#include "common-hal/microcontroller/Pin.h" +#include "supervisor/shared/board.h" +#include "hal/include/hal_gpio.h" + +void board_init(void) { +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} diff --git a/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.h b/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.h new file mode 100644 index 0000000000..7e216598fe --- /dev/null +++ b/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.h @@ -0,0 +1,54 @@ +#define MICROPY_HW_BOARD_NAME "CP Sapling M0" +#define MICROPY_HW_MCU_NAME "samd21e18" + +#define MICROPY_HW_NEOPIXEL (&pin_PA15) + +#define MICROPY_PORT_A (0) +#define MICROPY_PORT_B (0) +#define MICROPY_PORT_C (0) + +#define IGNORE_PIN_PA04 1 +#define IGNORE_PIN_PA05 1 +#define IGNORE_PIN_PA06 1 +#define IGNORE_PIN_PA12 1 +#define IGNORE_PIN_PA13 1 +#define IGNORE_PIN_PA20 1 +#define IGNORE_PIN_PA21 1 +// USB is always used internally so skip the pin objects for it. +#define IGNORE_PIN_PA24 1 +#define IGNORE_PIN_PA25 1 +#define IGNORE_PIN_PA30 1 +#define IGNORE_PIN_PA31 1 +#define IGNORE_PIN_PB01 1 +#define IGNORE_PIN_PB02 1 +#define IGNORE_PIN_PB03 1 +#define IGNORE_PIN_PB04 1 +#define IGNORE_PIN_PB05 1 +#define IGNORE_PIN_PB06 1 +#define IGNORE_PIN_PB07 1 +#define IGNORE_PIN_PB08 1 +#define IGNORE_PIN_PB09 1 +#define IGNORE_PIN_PB10 1 +#define IGNORE_PIN_PB11 1 +#define IGNORE_PIN_PB12 1 +#define IGNORE_PIN_PB13 1 +#define IGNORE_PIN_PB14 1 +#define IGNORE_PIN_PB15 1 +#define IGNORE_PIN_PB16 1 +#define IGNORE_PIN_PB17 1 +#define IGNORE_PIN_PB22 1 +#define IGNORE_PIN_PB23 1 +#define IGNORE_PIN_PB30 1 +#define IGNORE_PIN_PB31 1 +#define IGNORE_PIN_PB00 1 + +#define DEFAULT_I2C_BUS_SCL (&pin_PA09) +#define DEFAULT_I2C_BUS_SDA (&pin_PA08) + +#define DEFAULT_SPI_BUS_SS (&pin_PA22) +#define DEFAULT_SPI_BUS_SCK (&pin_PA19) +#define DEFAULT_SPI_BUS_MOSI (&pin_PA18) +#define DEFAULT_SPI_BUS_MISO (&pin_PA17) + +#define DEFAULT_UART_BUS_RX (&pin_PA00) +#define DEFAULT_UART_BUX_TX (&pin_PA01) diff --git a/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk b/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk new file mode 100644 index 0000000000..b94a5335eb --- /dev/null +++ b/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk @@ -0,0 +1,24 @@ +USB_VID = 0x1209 +USB_PID = 0x4DDF +USB_PRODUCT = "CP Sapling Rev B" +USB_MANUFACTURER = "Oak Development Technologies" + +CHIP_VARIANT = SAMD21E18A +CHIP_FAMILY = samd21 + +INTERNAL_FLASH_FILESYSTEM = 1 +LONGINT_IMPL = NONE +CIRCUITPY_FULL_BUILD = 0 + +SUPEROPT_GC = 0 + +CFLAGS_BOARD = --param max-inline-insns-auto=15 +ifeq ($(TRANSLATION), zh_Latn_pinyin) +RELEASE_NEEDS_CLEAN_BUILD = 1 +CFLAGS_INLINE_LIMIT = 35 +endif +ifeq ($(TRANSLATION), de_DE) +RELEASE_NEEDS_CLEAN_BUILD = 1 +CFLAGS_INLINE_LIMIT = 35 +SUPEROPT_VM = 0 +endif diff --git a/ports/atmel-samd/boards/cp_sapling_m0_revb/pins.c b/ports/atmel-samd/boards/cp_sapling_m0_revb/pins.c new file mode 100644 index 0000000000..81ed8722c5 --- /dev/null +++ b/ports/atmel-samd/boards/cp_sapling_m0_revb/pins.c @@ -0,0 +1,60 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PA22) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA22) }, + { MP_ROM_QSTR(MP_QSTR_SS), MP_ROM_PTR(&pin_PA22) }, + + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PA19) }, + { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA19) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pon_PA19 }, + + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PA18) }, + { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PA18) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA18) }. + + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PA17) }, + { MP_ROM_QSTR(MP_QSTR_A6), MP_ROM_PTR(&pin_PA17) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA17) }. + + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PA07) }, + { MP_ROM_QSTR(MP_QSTR_A7), MP_ROM_PTR(&pin_PA07) }, + + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PA00) }, + { MP_ROM_QSTR(MP_QSTR_A8), MP_ROM_PTR(&pin_PA00) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA00) }, + + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA01) }, + { MP_ROM_QSTR(MP_QSTR_A9), MP_ROM_PTR(&pin_PA01) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA01) }, + + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA02) }, + { MP_ROM_QSTR(MP_QSTR_A10), MP_ROM_PTR(&pin_PA02) }, + + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA03) }, + { MP_ROM_QSTR(MP_QSTR_A11), MP_ROM_PTR(&pin_PA03) }, + + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA09) }, + { MP_ROM_QSTR(MP_QSTR_A12), MP_ROM_PTR(&pin_PA09) }, + { MP_ROM+QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA09) }, + + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA08) }, + { MP_ROM_QSTR(MP_QSTR_A13), MP_ROM_PTR(&pin_PA08),}, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA08) }, + + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA17) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA17) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA17) }, + + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PA18) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA18) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA18) }, + + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA15) }, + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_uart), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); From e6350ff8341510ccaaf0ae74502bea1040dca27b Mon Sep 17 00:00:00 2001 From: jun2sak Date: Wed, 17 Feb 2021 20:53:18 +0900 Subject: [PATCH 002/103] Initial commit. --- main.c | 3 + ports/nrf/Makefile | 8 + ports/nrf/common-hal/alarm/SleepMemory.c | 48 ++++ ports/nrf/common-hal/alarm/SleepMemory.h | 41 +++ ports/nrf/common-hal/alarm/__init__.c | 204 ++++++++++++++ ports/nrf/common-hal/alarm/__init__.h | 45 +++ ports/nrf/common-hal/alarm/pin/PinAlarm.c | 260 ++++++++++++++++++ ports/nrf/common-hal/alarm/pin/PinAlarm.h | 41 +++ ports/nrf/common-hal/alarm/pin/__init__.c | 38 +++ ports/nrf/common-hal/alarm/time/TimeAlarm.c | 101 +++++++ ports/nrf/common-hal/alarm/time/TimeAlarm.h | 40 +++ ports/nrf/common-hal/alarm/touch/TouchAlarm.c | 185 +++++++++++++ ports/nrf/common-hal/alarm/touch/TouchAlarm.h | 46 ++++ ports/nrf/mpconfigport.mk | 3 + ports/nrf/nrfx_config.h | 2 +- ports/nrf/supervisor/port.c | 43 ++- supervisor/serial.h | 3 + supervisor/shared/serial.c | 110 ++++++++ 18 files changed, 1218 insertions(+), 3 deletions(-) create mode 100644 ports/nrf/common-hal/alarm/SleepMemory.c create mode 100644 ports/nrf/common-hal/alarm/SleepMemory.h create mode 100644 ports/nrf/common-hal/alarm/__init__.c create mode 100644 ports/nrf/common-hal/alarm/__init__.h create mode 100644 ports/nrf/common-hal/alarm/pin/PinAlarm.c create mode 100644 ports/nrf/common-hal/alarm/pin/PinAlarm.h create mode 100644 ports/nrf/common-hal/alarm/pin/__init__.c create mode 100644 ports/nrf/common-hal/alarm/time/TimeAlarm.c create mode 100644 ports/nrf/common-hal/alarm/time/TimeAlarm.h create mode 100644 ports/nrf/common-hal/alarm/touch/TouchAlarm.c create mode 100644 ports/nrf/common-hal/alarm/touch/TouchAlarm.h diff --git a/main.c b/main.c index 7bfa565df4..054c6b4f53 100755 --- a/main.c +++ b/main.c @@ -214,6 +214,7 @@ STATIC bool maybe_run_list(const char * const * filenames, pyexec_result_t* exec decompress(compressed, decompressed); mp_hal_stdout_tx_str(decompressed); pyexec_file(filename, exec_result); + dbg_printf("pyexec_file end result=(code=%d, line=%d)\r\n", exec_result->return_code, exec_result->exception_line); return true; } @@ -259,6 +260,7 @@ STATIC void print_code_py_status_message(safe_mode_t safe_mode) { } STATIC bool run_code_py(safe_mode_t safe_mode) { + dbg_printf("run_code_py (%d)\r\n", (int)safe_mode); bool serial_connected_at_start = serial_connected(); #if CIRCUITPY_AUTORELOAD_DELAY_MS > 0 serial_write("\n"); @@ -434,6 +436,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { FIL* boot_output_file; STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { + dbg_printf("run_boot_py (%d)\r\n", (int)safe_mode); // If not in safe mode, run boot before initing USB and capture output in a // file. if (filesystem_present() && safe_mode == NO_SAFE_MODE && MP_STATE_VM(vfs_mount_table) != NULL) { diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 278625e92d..c78a5dc503 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -87,6 +87,7 @@ INC += -I../../supervisor/shared/usb #Debugging/Optimization ifeq ($(DEBUG), 1) CFLAGS += -ggdb3 + CFLAGS += -DNDEBUG OPTIMIZATION_FLAGS = -Og else OPTIMIZATION_FLAGS ?= -O2 -fno-inline-functions @@ -94,6 +95,13 @@ else CFLAGS += -flto -flto-partition=none endif +ifeq ($(MY_DBG), 1) + CFLAGS += -DMY_DBG +endif +ifeq ($(MY_DEBUGUART), 1) + CFLAGS += -DMY_DEBUGUART=1 +endif + # option to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk CFLAGS += $(OPTIMIZATION_FLAGS) diff --git a/ports/nrf/common-hal/alarm/SleepMemory.c b/ports/nrf/common-hal/alarm/SleepMemory.c new file mode 100644 index 0000000000..dd87b31b17 --- /dev/null +++ b/ports/nrf/common-hal/alarm/SleepMemory.c @@ -0,0 +1,48 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 microDev + * Copyright (c) 2020 Dan Halbert for Adafruit Industries + * + * 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 + +#include "py/runtime.h" +#include "common-hal/alarm/SleepMemory.h" + +//static RTC_DATA_ATTR uint8_t _sleep_mem[SLEEP_MEMORY_LENGTH]; + +void alarm_sleep_memory_reset(void) { +} + +uint32_t common_hal_alarm_sleep_memory_get_length(alarm_sleep_memory_obj_t *self) { + return 0; +} + +bool common_hal_alarm_sleep_memory_set_bytes(alarm_sleep_memory_obj_t *self, uint32_t start_index, const uint8_t* values, uint32_t len) { + return false; +} + +void common_hal_alarm_sleep_memory_get_bytes(alarm_sleep_memory_obj_t *self, uint32_t start_index, uint8_t* values, uint32_t len) { + return; +} diff --git a/ports/nrf/common-hal/alarm/SleepMemory.h b/ports/nrf/common-hal/alarm/SleepMemory.h new file mode 100644 index 0000000000..ea3d40c35a --- /dev/null +++ b/ports/nrf/common-hal/alarm/SleepMemory.h @@ -0,0 +1,41 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Dan Halbert for Adafruit Industries + * + * 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_NRF_COMMON_HAL_ALARM_SLEEPMEMORY_H +#define MICROPY_INCLUDED_NRF_COMMON_HAL_ALARM_SLEEPMEMORY_H + +#include "py/obj.h" + +// not implemented yet +#define SLEEP_MEMORY_LENGTH (4) + +typedef struct { + mp_obj_base_t base; +} alarm_sleep_memory_obj_t; + +extern void alarm_sleep_memory_reset(void); + +#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_ALARM_SLEEPMEMORY_H diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c new file mode 100644 index 0000000000..d5a4aec3c8 --- /dev/null +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -0,0 +1,204 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2020 Dan Halbert for Adafruit Industries + * + * 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 "py/gc.h" +#include "py/obj.h" +#include "py/objtuple.h" +#include "py/runtime.h" +#include +#include + +#include "shared-bindings/alarm/__init__.h" +#include "shared-bindings/alarm/SleepMemory.h" +#include "shared-bindings/alarm/pin/PinAlarm.h" +#include "shared-bindings/alarm/time/TimeAlarm.h" +#include "shared-bindings/alarm/touch/TouchAlarm.h" + +//#include "shared-bindings/wifi/__init__.h" +//#include "shared-bindings/microcontroller/__init__.h" + +#include "supervisor/port.h" + +#include "nrf.h" +#include "nrf_power.h" +#include "nrfx.h" +#include "nrfx_gpiote.h" + +extern void _debug_print(const char* s); +extern void _xxx_dumpRTC(void);//XXXX + +#define DEBUG_LED_PIN (NRF_GPIO_PIN_MAP(1, 11)) // P1_11 = LED +void _debug_led_init(void) { + nrf_gpio_cfg_output(DEBUG_LED_PIN); +} +void _debug_led_set(int v) { + nrf_gpio_pin_write(DEBUG_LED_PIN, v); +} + + +// Singleton instance of SleepMemory. +const alarm_sleep_memory_obj_t alarm_sleep_memory_obj = { + .base = { + .type = &alarm_sleep_memory_type, + }, +}; + +void alarm_reset(void) { + //alarm_sleep_memory_reset(); + alarm_pin_pinalarm_reset(); + alarm_time_timealarm_reset(); + //alarm_touch_touchalarm_reset(); +} + +extern uint32_t reset_reason_saved; +STATIC uint32_t _get_wakeup_cause(void) { + if (alarm_pin_pinalarm_woke_us_up()) { + return NRF_SLEEP_WAKEUP_GPIO; + } + if (alarm_time_timealarm_woke_us_up()) { + return NRF_SLEEP_WAKEUP_TIMER; + } +#if 0 + if (alarm_touch_touchalarm_woke_us_up()) { + return ESP_SLEEP_WAKEUP_TOUCHPAD; + } + return esp_sleep_get_wakeup_cause(); +#endif + if (reset_reason_saved & NRF_POWER_RESETREAS_RESETPIN_MASK) { + return NRF_SLEEP_WAKEUP_RESETPIN; + } + else if (reset_reason_saved & NRF_POWER_RESETREAS_OFF_MASK) { + return NRF_SLEEP_WAKEUP_GPIO; + } + else if (reset_reason_saved & NRF_POWER_RESETREAS_VBUS_MASK) { + return NRF_SLEEP_WAKEUP_VBUS; + } + return NRF_SLEEP_WAKEUP_UNDEFINED; +} + +bool alarm_woken_from_sleep(void) { + uint32_t cause = _get_wakeup_cause(); + return (cause == NRF_SLEEP_WAKEUP_GPIO || cause == NRF_SLEEP_WAKEUP_TIMER + || cause == NRF_SLEEP_WAKEUP_TOUCHPAD + || cause == NRF_SLEEP_WAKEUP_RESETPIN); +} + +STATIC mp_obj_t _get_wake_alarm(size_t n_alarms, const mp_obj_t *alarms) { + uint32_t cause = _get_wakeup_cause(); + if (cause & 0x80000000) { + printf("wakeup cause = 0x%08X\r\n", (int)cause); + } + switch (cause) { + case NRF_SLEEP_WAKEUP_TIMER: { + return alarm_time_timealarm_get_wakeup_alarm(n_alarms, alarms); + } + case NRF_SLEEP_WAKEUP_TOUCHPAD: { + return mp_const_none; + } + case NRF_SLEEP_WAKEUP_GPIO: { + return alarm_pin_pinalarm_get_wakeup_alarm(n_alarms, alarms); + } + } + return mp_const_none; +} + +mp_obj_t common_hal_alarm_get_wake_alarm(void) { + mp_obj_t obj = _get_wake_alarm(0, NULL); + //_xxx_dumpRTC();//XXX + return obj; +} + +// Set up light sleep or deep sleep alarms. +STATIC void _setup_sleep_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms) { + alarm_pin_pinalarm_set_alarms(deep_sleep, n_alarms, alarms); + alarm_time_timealarm_set_alarms(deep_sleep, n_alarms, alarms); +#if 0 + alarm_touch_touchalarm_set_alarm(deep_sleep, n_alarms, alarms); +#endif + //_xxx_dumpRTC(); +} + +STATIC void _idle_until_alarm(void) { + int ct = 40; + // Poll for alarms. + while (!mp_hal_is_interrupted()) { + RUN_BACKGROUND_TASKS; + // Allow ctrl-C interrupt. + if (alarm_woken_from_sleep()) { + alarm_save_wake_alarm(); + int cause = _get_wakeup_cause(); + printf("wakeup(%d)\r\n", cause); //XXX + return; + } + port_idle_until_interrupt(); + if (ct > 0) { + printf("_"); --ct; + } + } +} + +mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj_t *alarms) { + mp_obj_t r_obj = mp_const_none; + _setup_sleep_alarms(false, n_alarms, alarms); + _debug_print("\r\nsleep..."); + + _idle_until_alarm(); + + if (mp_hal_is_interrupted()) { + _debug_print("mp_hal_is_interrupted\r\n"); + r_obj = mp_const_none; + } + else { + r_obj = _get_wake_alarm(n_alarms, alarms); + alarm_reset(); + } + return r_obj; +} + +void common_hal_alarm_set_deep_sleep_alarms(size_t n_alarms, const mp_obj_t *alarms) { + _setup_sleep_alarms(true, n_alarms, alarms); +} + +void nrf_deep_sleep_start(void) { + _debug_print("go system off..\r\n"); + sd_power_system_off(); +} + +void NORETURN alarm_enter_deep_sleep(void) { + alarm_pin_pinalarm_prepare_for_deep_sleep(); + //alarm_touch_touchalarm_prepare_for_deep_sleep(); + + nrf_deep_sleep_start(); + + // should not reach here.. + while(1) ; +} + +void common_hal_alarm_gc_collect(void) { + void* p = alarm_get_wake_alarm(); + gc_collect_ptr(p); +} diff --git a/ports/nrf/common-hal/alarm/__init__.h b/ports/nrf/common-hal/alarm/__init__.h new file mode 100644 index 0000000000..11652ec828 --- /dev/null +++ b/ports/nrf/common-hal/alarm/__init__.h @@ -0,0 +1,45 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Dan Halbert for Adafruit Industries. + * + * 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_NRF_COMMON_HAL_ALARM__INIT__H +#define MICROPY_INCLUDED_NRF_COMMON_HAL_ALARM__INIT__H + +#include "common-hal/alarm/SleepMemory.h" + +typedef enum { + NRF_SLEEP_WAKEUP_UNDEFINED, + NRF_SLEEP_WAKEUP_GPIO, + NRF_SLEEP_WAKEUP_TIMER, + NRF_SLEEP_WAKEUP_TOUCHPAD, + NRF_SLEEP_WAKEUP_VBUS, + NRF_SLEEP_WAKEUP_RESETPIN, +} nrf_sleep_source_t; + +extern const alarm_sleep_memory_obj_t alarm_sleep_memory_obj; + +extern void alarm_reset(void); + +#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_ALARM__INIT__H diff --git a/ports/nrf/common-hal/alarm/pin/PinAlarm.c b/ports/nrf/common-hal/alarm/pin/PinAlarm.c new file mode 100644 index 0000000000..0e0f6c4832 --- /dev/null +++ b/ports/nrf/common-hal/alarm/pin/PinAlarm.c @@ -0,0 +1,260 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Dan Halbert for Adafruit Industries + * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries + * + * 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 "py/runtime.h" +#include + +#include "shared-bindings/alarm/pin/PinAlarm.h" +#include "shared-bindings/microcontroller/__init__.h" +#include "shared-bindings/microcontroller/Pin.h" + +#include "nrfx.h" +#include "nrf_gpio.h" +#include "nrfx_gpiote.h" +#include "nrf_soc.h" +#include + +#include "supervisor/serial.h" // dbg_print + +#define WPIN_UNUSED 0xFF +volatile char _pinhandler_gpiote_count; +volatile nrfx_gpiote_pin_t _pinhandler_ev_pin; +#define MYGPIOTE_EV_PIN_UNDEF 0xFF + +void common_hal_alarm_pin_pinalarm_construct(alarm_pin_pinalarm_obj_t *self, mcu_pin_obj_t *pin, bool value, bool edge, bool pull) { +#if 0 + if (edge) { + mp_raise_ValueError(translate("Cannot wake on pin edge. Only level.")); + } + + if (pull && !GPIO_IS_VALID_OUTPUT_GPIO(pin->number)) { + mp_raise_ValueError(translate("Cannot pull on input-only pin.")); + } +#endif + self->pin = pin; + self->value = value; + self->pull = pull; +} + +mcu_pin_obj_t *common_hal_alarm_pin_pinalarm_get_pin(alarm_pin_pinalarm_obj_t *self) { + return self->pin; +} + +bool common_hal_alarm_pin_pinalarm_get_value(alarm_pin_pinalarm_obj_t *self) { + return self->value; +} + +bool common_hal_alarm_pin_pinalarm_get_edge(alarm_pin_pinalarm_obj_t *self) { + return false; +} + +bool common_hal_alarm_pin_pinalarm_get_pull(alarm_pin_pinalarm_obj_t *self) { + return self->pull; +} + + +static void pinalarm_gpiote_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { + ++_pinhandler_gpiote_count; + _pinhandler_ev_pin = pin; +} + +bool alarm_pin_pinalarm_woke_us_up(void) { + return (_pinhandler_gpiote_count > 0 && _pinhandler_ev_pin != MYGPIOTE_EV_PIN_UNDEF); +} + +mp_obj_t alarm_pin_pinalarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *alarms) { + // First, check to see if we match any given alarms. + for (size_t i = 0; i < n_alarms; i++) { + if (!MP_OBJ_IS_TYPE(alarms[i], &alarm_pin_pinalarm_type)) { + continue; + } + alarm_pin_pinalarm_obj_t *alarm = MP_OBJ_TO_PTR(alarms[i]); + if (alarm->pin->number == _pinhandler_ev_pin) { + return alarms[i]; + } + } + + alarm_pin_pinalarm_obj_t *alarm = m_new_obj(alarm_pin_pinalarm_obj_t); + alarm->base.type = &alarm_pin_pinalarm_type; + alarm->pin = NULL; + // Map the pin number back to a pin object. + for (size_t i = 0; i < mcu_pin_globals.map.used; i++) { + const mcu_pin_obj_t* pin_obj = MP_OBJ_TO_PTR(mcu_pin_globals.map.table[i].value); + if ((size_t) pin_obj->number == _pinhandler_ev_pin) { + alarm->pin = mcu_pin_globals.map.table[i].value; + break; + } + } + return alarm; +} + +// These must be static because we need to configure pulls later, right before +// deep sleep. +static uint64_t high_alarms = 0; +static uint64_t low_alarms = 0; +static uint64_t pull_pins = 0; + +void alarm_pin_pinalarm_reset(void) { + for (size_t i = 0; i < 64; i++) { + uint64_t mask = 1ull << i; + bool high = (high_alarms & mask) != 0; + bool low = (low_alarms & mask) != 0; + if (!(high || low)) { + continue; + } + reset_pin_number(i); + nrfx_gpiote_in_event_disable((nrfx_gpiote_pin_t)i); + nrfx_gpiote_in_uninit((nrfx_gpiote_pin_t)i); + } + + high_alarms = 0; + low_alarms = 0; + pull_pins = 0; +} + +void _setup2(void) { + nrfx_gpiote_in_config_t cfg = { + .sense = NRF_GPIOTE_POLARITY_TOGGLE, + .pull = NRF_GPIO_PIN_PULLUP, + .is_watcher = false, + .hi_accuracy = true, + .skip_gpio_setup = false + }; + for(size_t i = 0; i < 64; ++i) { + uint64_t mask = 1ull << i; + int pull = 0; + int sense = 0; + if (((high_alarms & mask) == 0) && ((low_alarms & mask) == 0)) { + continue; + } + if (((high_alarms & mask) != 0) && ((low_alarms & mask) == 0)) { + cfg.sense = NRF_GPIOTE_POLARITY_LOTOHI; + cfg.pull = ((pull_pins & mask) != 0) ? NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_NOPULL; + pull = -1; sense = 1; + } + else + if (((high_alarms & mask) == 0) && ((low_alarms & mask) != 0)) { + cfg.sense = NRF_GPIOTE_POLARITY_HITOLO; + cfg.pull = ((pull_pins & mask) != 0) ? NRF_GPIO_PIN_PULLUP : NRF_GPIO_PIN_NOPULL; + pull = 1; sense = -1; + } + else { + cfg.sense = NRF_GPIOTE_POLARITY_TOGGLE; + cfg.pull = NRF_GPIO_PIN_NOPULL; + sense = 9; + } + nrfx_gpiote_in_init((nrfx_gpiote_pin_t)i, &cfg, pinalarm_gpiote_handler); + nrfx_gpiote_in_event_enable((nrfx_gpiote_pin_t)i, true); + printf("pin=%d, sense=%d, pull=%d\r\n", i, sense, pull); + } +} + +void _setup_pin1_for_lightsleep(void) { + if ( nrfx_gpiote_is_init() ) { + nrfx_gpiote_uninit(); + } + nrfx_gpiote_init(NRFX_GPIOTE_CONFIG_IRQ_PRIORITY); + + _pinhandler_gpiote_count = 0; + _pinhandler_ev_pin = MYGPIOTE_EV_PIN_UNDEF; + _setup2(); +} + +void _setup_pin1_for_deepsleep(void) { + for(size_t i = 0; i < 64; ++i) { + uint64_t mask = 1ull << i; + int pull = 0; + int sense = 0; + if (((high_alarms & mask) == 0) && ((low_alarms & mask) == 0)) { + continue; + } + if (((high_alarms & mask) != 0) && ((low_alarms & mask) == 0)) { + pull = ((pull_pins & mask) != 0) ? NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_NOPULL; + nrf_gpio_cfg_input((uint32_t)i, (nrf_gpio_pin_pull_t)pull); + nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_HIGH); + sense = NRF_GPIO_PIN_SENSE_HIGH; + } + else + if (((high_alarms & mask) == 0) && ((low_alarms & mask) != 0)) { + pull = ((pull_pins & mask) != 0) ? NRF_GPIO_PIN_PULLUP : NRF_GPIO_PIN_NOPULL; + nrf_gpio_cfg_input((uint32_t)i, (nrf_gpio_pin_pull_t)pull); + nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_LOW); + sense = NRF_GPIO_PIN_SENSE_LOW; + } + printf("pin=%d, sense=%d, pull=%d\r\n", i, sense, pull); + } +#if 0 + uint32_t pin_number = 2; + NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number); + dbg_printf(" 2 PIN_CNF=0x%08X\r\n", (unsigned int)(reg->PIN_CNF[pin_number])); + pin_number = 28; + reg = nrf_gpio_pin_port_decode(&pin_number); + dbg_printf("28 PIN_CNF=0x%08X\r\n", (unsigned int)(reg->PIN_CNF[pin_number])); +#endif +} + +void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms) { + // Bitmask of wake up settings. + size_t high_count = 0; + size_t low_count = 0; + int pin_number = -1; + + for (size_t i = 0; i < n_alarms; i++) { + if (!MP_OBJ_IS_TYPE(alarms[i], &alarm_pin_pinalarm_type)) { + continue; + } + alarm_pin_pinalarm_obj_t *alarm = MP_OBJ_TO_PTR(alarms[i]); + + pin_number = alarm->pin->number; + dbg_printf("alarm_pin_pinalarm_set_alarms(pin#=%d, val=%d, pull=%d)\r\n", pin_number, alarm->value, alarm->pull); + if (alarm->value) { + high_alarms |= 1ull << pin_number; + high_count++; + } else { + low_alarms |= 1ull << pin_number; + low_count++; + } + if (alarm->pull) { + pull_pins |= 1ull << pin_number; + } + } + if (pin_number != -1) { + if (!deep_sleep) { + _setup_pin1_for_lightsleep(); + } + else { + //_setup_pin1_for_deepsleep(pin_number); + } + } + else { + dbg_printf("alarm_pin_pinalarm_set_alarms() no valid pins\r\n"); + } +} + +void alarm_pin_pinalarm_prepare_for_deep_sleep(void) { + _setup_pin1_for_deepsleep(); +} diff --git a/ports/nrf/common-hal/alarm/pin/PinAlarm.h b/ports/nrf/common-hal/alarm/pin/PinAlarm.h new file mode 100644 index 0000000000..93672c1f2d --- /dev/null +++ b/ports/nrf/common-hal/alarm/pin/PinAlarm.h @@ -0,0 +1,41 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Dan Halbert for Adafruit Industries + * + * 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 "py/obj.h" +#include "py/objtuple.h" + +typedef struct { + mp_obj_base_t base; + mcu_pin_obj_t *pin; + bool value; + bool pull; +} alarm_pin_pinalarm_obj_t; + +void alarm_pin_pinalarm_reset(void); +void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms); +void alarm_pin_pinalarm_prepare_for_deep_sleep(void); +mp_obj_t alarm_pin_pinalarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *alarms); +bool alarm_pin_pinalarm_woke_us_up(void); diff --git a/ports/nrf/common-hal/alarm/pin/__init__.c b/ports/nrf/common-hal/alarm/pin/__init__.c new file mode 100644 index 0000000000..d2ce00a3e3 --- /dev/null +++ b/ports/nrf/common-hal/alarm/pin/__init__.c @@ -0,0 +1,38 @@ +//#include "shared-bindings/alarm_io/__init__.h" + +//#include "esp_sleep.h" +//#include "driver/rtc_io.h" + +mp_obj_t common_hal_alarm_io_pin_state (alarm_io_obj_t *self_in) { +#if 0 + if (!rtc_gpio_is_valid_gpio(self_in->gpio)) { + mp_raise_ValueError(translate("io must be rtc io")); + } + + if (self_in->pull && !self_in->level) { + for (uint8_t i = 0; i<=4; i+=2) { + if (self_in->gpio == i) { + mp_raise_ValueError(translate("IOs 0, 2 & 4 do not support internal pullup in sleep")); + } + } + } + + switch(esp_sleep_enable_ext0_wakeup(self_in->gpio, self_in->level)) { + case ESP_ERR_INVALID_ARG: + mp_raise_ValueError(translate("trigger level must be 0 or 1")); + case ESP_ERR_INVALID_STATE: + mp_raise_RuntimeError(translate("wakeup conflict")); + default: + break; + } + + if (self_in->pull) { (self_in->level) ? rtc_gpio_pulldown_en(self_in->gpio) : rtc_gpio_pullup_en(self_in->gpio); } +#endif + return self_in; +} + +void common_hal_alarm_io_disable (void) { +#if 0 + esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_EXT0 | ESP_SLEEP_WAKEUP_EXT1); +#endif +} diff --git a/ports/nrf/common-hal/alarm/time/TimeAlarm.c b/ports/nrf/common-hal/alarm/time/TimeAlarm.c new file mode 100644 index 0000000000..220ed2f4df --- /dev/null +++ b/ports/nrf/common-hal/alarm/time/TimeAlarm.c @@ -0,0 +1,101 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Dan Halbert for Adafruit Industries + * + * 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 "esp_sleep.h" + +#include "py/runtime.h" +//#include "supervisor/esp_port.h" +#include + +#include "shared-bindings/alarm/time/TimeAlarm.h" +#include "shared-bindings/time/__init__.h" + +void common_hal_alarm_time_timealarm_construct(alarm_time_timealarm_obj_t *self, mp_float_t monotonic_time) { + self->monotonic_time = monotonic_time; +} + +mp_float_t common_hal_alarm_time_timealarm_get_monotonic_time(alarm_time_timealarm_obj_t *self) { + return self->monotonic_time; +} + +mp_obj_t alarm_time_timealarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *alarms) { + // First, check to see if we match + for (size_t i = 0; i < n_alarms; i++) { + if (MP_OBJ_IS_TYPE(alarms[i], &alarm_time_timealarm_type)) { + return alarms[i]; + } + } + alarm_time_timealarm_obj_t *timer = m_new_obj(alarm_time_timealarm_obj_t); + timer->base.type = &alarm_time_timealarm_type; + // TODO: Set monotonic_time based on the RTC state. + timer->monotonic_time = 0.0f; + return timer; +} + +extern volatile int rtc_woke_up_counter; +bool alarm_time_timealarm_woke_us_up(void) { + return rtc_woke_up_counter; +} + +extern void port_disable_interrupt_after_ticks_ch(uint32_t channel); +void alarm_time_timealarm_reset(void) { + port_disable_interrupt_after_ticks_ch(1); + rtc_woke_up_counter = 0; +} + +extern void port_interrupt_after_ticks_ch(uint32_t channel, uint32_t ticks);//XXX in port.c + +void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms) { + bool timealarm_set = false; + alarm_time_timealarm_obj_t *timealarm = MP_OBJ_NULL; + + for (size_t i = 0; i < n_alarms; i++) { + if (!MP_OBJ_IS_TYPE(alarms[i], &alarm_time_timealarm_type)) { + continue; + } + if (timealarm_set) { + mp_raise_ValueError(translate("Only one alarm.time alarm can be set.")); + } + timealarm = MP_OBJ_TO_PTR(alarms[i]); + timealarm_set = true; + } + if (!timealarm_set) { + return; + } + + // Compute how long to actually sleep, considering the time now. + mp_float_t now_secs = uint64_to_float(common_hal_time_monotonic_ms()) / 1000.0f; + mp_float_t wakeup_in_secs = MAX(0.0f, timealarm->monotonic_time - now_secs); + int wsecs = (int)(wakeup_in_secs); + if (wsecs > 510) { //XXX + mp_raise_ValueError(translate("Alarm time is too far.")); + } + + uint32_t wakeup_in_ticks = (uint32_t)(wakeup_in_secs * 1024.0f); + //printf("alarm_time_timealarm_set_alarms() %d secs 0x%08X ticks\r\n", wsecs, (int)wakeup_in_ticks); + port_interrupt_after_ticks_ch(1, wakeup_in_ticks); + rtc_woke_up_counter = 0; +} diff --git a/ports/nrf/common-hal/alarm/time/TimeAlarm.h b/ports/nrf/common-hal/alarm/time/TimeAlarm.h new file mode 100644 index 0000000000..dfd75524fd --- /dev/null +++ b/ports/nrf/common-hal/alarm/time/TimeAlarm.h @@ -0,0 +1,40 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Dan Halbert for Adafruit Industries + * + * 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 "py/obj.h" + +typedef struct { + mp_obj_base_t base; + mp_float_t monotonic_time; // values compatible with time.monotonic_time() +} alarm_time_timealarm_obj_t; + +// Find the alarm object that caused us to wake up or create an equivalent one. +mp_obj_t alarm_time_timealarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *alarms); +// Check for the wake up alarm from pretend deep sleep. +bool alarm_time_timealarm_woke_us_up(void); +void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms); +void alarm_time_timealarm_reset(void); diff --git a/ports/nrf/common-hal/alarm/touch/TouchAlarm.c b/ports/nrf/common-hal/alarm/touch/TouchAlarm.c new file mode 100644 index 0000000000..4db178c56e --- /dev/null +++ b/ports/nrf/common-hal/alarm/touch/TouchAlarm.c @@ -0,0 +1,185 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 microDev + * + * 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 "shared-bindings/alarm/touch/TouchAlarm.h" +#include "shared-bindings/microcontroller/__init__.h" + +//#include "esp_sleep.h" +//#include "peripherals/touch.h" +//#include "supervisor/esp_port.h" + +static uint16_t touch_channel_mask; +static volatile bool woke_up = false; + +void common_hal_alarm_touch_touchalarm_construct(alarm_touch_touchalarm_obj_t *self, const mcu_pin_obj_t *pin) { +#if 0 + if (pin->touch_channel == TOUCH_PAD_MAX) { + mp_raise_ValueError(translate("Invalid pin")); + } + claim_pin(pin); +#endif + self->pin = pin; +} + +mp_obj_t alarm_touch_touchalarm_get_wakeup_alarm(const size_t n_alarms, const mp_obj_t *alarms) { + // First, check to see if we match any given alarms. + for (size_t i = 0; i < n_alarms; i++) { + if (MP_OBJ_IS_TYPE(alarms[i], &alarm_touch_touchalarm_type)) { + return alarms[i]; + } + } + + // Create TouchAlarm object. + alarm_touch_touchalarm_obj_t *alarm = m_new_obj(alarm_touch_touchalarm_obj_t); + alarm->base.type = &alarm_touch_touchalarm_type; + alarm->pin = NULL; +#if 0 + touch_pad_t wake_channel = touch_pad_get_current_meas_channel(); + if (wake_channel == TOUCH_PAD_MAX) { + return alarm; + } + + // Map the pin number back to a pin object. + for (size_t i = 0; i < mcu_pin_globals.map.used; i++) { + const mcu_pin_obj_t* pin_obj = MP_OBJ_TO_PTR(mcu_pin_globals.map.table[i].value); + if (pin_obj->touch_channel == wake_channel) { + alarm->pin = mcu_pin_globals.map.table[i].value; + break; + } + } +#endif + return alarm; +} + +// This is used to wake the main CircuitPython task. +void touch_interrupt(void *arg) { + (void) arg; +#if 0 + woke_up = true; + BaseType_t task_wakeup; + vTaskNotifyGiveFromISR(circuitpython_task, &task_wakeup); + if (task_wakeup) { + portYIELD_FROM_ISR(); + } +#endif +} + +void alarm_touch_touchalarm_set_alarm(const bool deep_sleep, const size_t n_alarms, const mp_obj_t *alarms) { +#if 0 + bool touch_alarm_set = false; + alarm_touch_touchalarm_obj_t *touch_alarm = MP_OBJ_NULL; + + for (size_t i = 0; i < n_alarms; i++) { + if (MP_OBJ_IS_TYPE(alarms[i], &alarm_touch_touchalarm_type)) { + if (deep_sleep && touch_alarm_set) { + mp_raise_ValueError(translate("Only one TouchAlarm can be set in deep sleep.")); + } + touch_alarm = MP_OBJ_TO_PTR(alarms[i]); + touch_channel_mask |= 1 << touch_alarm->pin->number; + touch_alarm_set = true; + } + } + + if (!touch_alarm_set) { + return; + } + + // configure interrupt for pretend to deep sleep + // this will be disabled if we actually deep sleep + + // reset touch peripheral + peripherals_touch_reset(); + peripherals_touch_never_reset(true); + + for (uint8_t i = 1; i <= 14; i++) { + if ((touch_channel_mask & 1 << i) != 0) { + touch_pad_t touch_channel = (touch_pad_t)i; + // intialize touchpad + peripherals_touch_init(touch_channel); + + // wait for touch data to reset + mp_hal_delay_ms(10); + + // configure trigger threshold + uint32_t touch_value; + touch_pad_read_benchmark(touch_channel, &touch_value); + touch_pad_set_thresh(touch_channel, touch_value * 0.1); //10% + } + } + + // configure touch interrupt + touch_pad_timeout_set(true, SOC_TOUCH_PAD_THRESHOLD_MAX); + touch_pad_isr_register(touch_interrupt, NULL, TOUCH_PAD_INTR_MASK_ALL); + touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE); +} + +void alarm_touch_touchalarm_prepare_for_deep_sleep(void) { + if (!touch_channel_mask) { + return; + } + + touch_pad_t touch_channel = TOUCH_PAD_MAX; + for (uint8_t i = 1; i <= 14; i++) { + if ((touch_channel_mask & 1 << i) != 0) { + touch_channel = (touch_pad_t)i; + break; + } + } + + // reset touch peripheral + peripherals_touch_never_reset(false); + peripherals_touch_reset(); + + // intialize touchpad + peripherals_touch_init(touch_channel); + + // configure touchpad for sleep + touch_pad_sleep_channel_enable(touch_channel, true); + touch_pad_sleep_channel_enable_proximity(touch_channel, false); + + // wait for touch data to reset + mp_hal_delay_ms(10); + + // configure trigger threshold + uint32_t touch_value; + touch_pad_sleep_channel_read_smooth(touch_channel, &touch_value); + touch_pad_sleep_set_threshold(touch_channel, touch_value * 0.1); //10% + + // enable touchpad wakeup + esp_sleep_enable_touchpad_wakeup(); + esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); +#endif +} + +bool alarm_touch_touchalarm_woke_us_up(void) { + return woke_up; +} + +void alarm_touch_touchalarm_reset(void) { + woke_up = false; + touch_channel_mask = 0; +// peripherals_touch_never_reset(false); +} diff --git a/ports/nrf/common-hal/alarm/touch/TouchAlarm.h b/ports/nrf/common-hal/alarm/touch/TouchAlarm.h new file mode 100644 index 0000000000..755a3977ad --- /dev/null +++ b/ports/nrf/common-hal/alarm/touch/TouchAlarm.h @@ -0,0 +1,46 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 microDev + * + * 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_COMMON_HAL_ALARM_TOUCH_TOUCHALARM_H +#define MICROPY_INCLUDED_COMMON_HAL_ALARM_TOUCH_TOUCHALARM_H + +#include "py/obj.h" +#include "common-hal/microcontroller/Pin.h" + +typedef struct { + mp_obj_base_t base; + const mcu_pin_obj_t *pin; +} alarm_touch_touchalarm_obj_t; + +// Find the alarm object that caused us to wake up or create an equivalent one. +mp_obj_t alarm_touch_touchalarm_get_wakeup_alarm(const size_t n_alarms, const mp_obj_t *alarms); +// Check for the wake up alarm from pretend deep sleep. +void alarm_touch_touchalarm_set_alarm(const bool deep_sleep, const size_t n_alarms, const mp_obj_t *alarms); +void alarm_touch_touchalarm_prepare_for_deep_sleep(void); +bool alarm_touch_touchalarm_woke_us_up(void); +void alarm_touch_touchalarm_reset(void); + +#endif // MICROPY_INCLUDED_COMMON_HAL_ALARM_TOUCH_TOUCHALARM_H diff --git a/ports/nrf/mpconfigport.mk b/ports/nrf/mpconfigport.mk index 9560064fbc..3e3f30d350 100644 --- a/ports/nrf/mpconfigport.mk +++ b/ports/nrf/mpconfigport.mk @@ -42,6 +42,9 @@ CIRCUITPY_FRAMEBUFFERIO ?= 1 CIRCUITPY_COUNTIO = 0 CIRCUITPY_WATCHDOG ?= 1 +# Sleep and Wakeup +CIRCUITPY_ALARM = 1 + # nRF52840-specific ifeq ($(MCU_CHIP),nrf52840) diff --git a/ports/nrf/nrfx_config.h b/ports/nrf/nrfx_config.h index 94812d5913..1becad813d 100644 --- a/ports/nrf/nrfx_config.h +++ b/ports/nrf/nrfx_config.h @@ -116,7 +116,7 @@ // GPIO interrupt #define NRFX_GPIOTE_ENABLED 1 -#define NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS 1 +#define NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS 2 #define NRFX_GPIOTE_CONFIG_IRQ_PRIORITY 7 // NVM controller diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c index 78bb20ce6c..3ed822ed76 100644 --- a/ports/nrf/supervisor/port.c +++ b/ports/nrf/supervisor/port.c @@ -27,6 +27,10 @@ #include #include "supervisor/port.h" #include "supervisor/board.h" +#ifdef MY_DEBUGUART +#include "supervisor/serial.h" // dbg_printf() +extern void _debug_uart_init(void); +#endif #include "nrfx/hal/nrf_clock.h" #include "nrfx/hal/nrf_power.h" @@ -90,6 +94,9 @@ static volatile struct { uint32_t suffix; } overflow_tracker __attribute__((section(".uninitialized"))); +uint32_t reset_reason_saved = 0; +volatile int rtc_woke_up_counter = 0; + void rtc_handler(nrfx_rtc_int_type_t int_type) { if (int_type == NRFX_RTC_INT_OVERFLOW) { // Our RTC is 24 bits and we're clocking it at 32.768khz which is 32 (2 ** 5) subticks per @@ -100,9 +107,25 @@ void rtc_handler(nrfx_rtc_int_type_t int_type) { supervisor_tick(); } else if (int_type == NRFX_RTC_INT_COMPARE0) { nrfx_rtc_cc_set(&rtc_instance, 0, 0, false); + } else if (int_type == NRFX_RTC_INT_COMPARE1) { + // used in light sleep + ++rtc_woke_up_counter; + nrfx_rtc_cc_set(&rtc_instance, 1, 0, false); } } +void _xxx_dumpRTC(void) { + dbg_printf("\r\nRTC2\r\n"); + NRF_RTC_Type *r = rtc_instance.p_reg; + dbg_printf("PRESCALER=%08X, ", (int)r->PRESCALER); + dbg_printf("COUNTER=%08X ", (int)r->COUNTER); + dbg_printf("INTENSET=%08X ", (int)r->INTENSET); + dbg_printf("EVTENSET=%08X\r\n", (int)r->EVTENSET); + dbg_printf("EVENTS_COMPARE[0..3]=%X,%X,%X,%X ", (int)r->EVENTS_COMPARE[0], (int)r->EVENTS_COMPARE[1], (int)r->EVENTS_COMPARE[2], (int)r->EVENTS_COMPARE[3]); + dbg_printf("CC[0..3]=%08X,%08X,%08X,%08X\r\n", (int)r->CC[0], (int)r->CC[1], (int)r->CC[2], (int)r->CC[3]); + dbg_printf("woke_up=%d\r\n", rtc_woke_up_counter); +} + void tick_init(void) { if (!nrf_clock_lf_is_running(NRF_CLOCK)) { nrf_clock_task_trigger(NRF_CLOCK, NRF_CLOCK_TASK_LFCLKSTART); @@ -124,6 +147,7 @@ void tick_init(void) { } } + safe_mode_t port_init(void) { nrf_peripherals_clocks_init(); @@ -153,6 +177,8 @@ safe_mode_t port_init(void) { analogin_init(); #endif + reset_reason_saved = NRF_POWER->RESETREAS; + // If the board was reset by the WatchDogTimer, we may // need to boot into safe mode. Reset the RESETREAS bit // for the WatchDogTimer so we don't encounter this the @@ -171,6 +197,7 @@ safe_mode_t port_init(void) { return NO_SAFE_MODE; } + void reset_port(void) { #ifdef CIRCUITPY_GAMEPAD_TICKS gamepad_reset(); @@ -219,6 +246,10 @@ void reset_port(void) { #endif reset_all_pins(); + +#ifdef MY_DEBUGUART + _debug_uart_init(); +#endif } void reset_to_bootloader(void) { @@ -295,7 +326,7 @@ void port_disable_tick(void) { nrfx_rtc_tick_disable(&rtc_instance); } -void port_interrupt_after_ticks(uint32_t ticks) { +void port_interrupt_after_ticks_ch(uint32_t channel, uint32_t ticks) { uint32_t current_ticks = nrfx_rtc_counter_get(&rtc_instance); uint32_t diff = 3; if (ticks > diff) { @@ -304,7 +335,15 @@ void port_interrupt_after_ticks(uint32_t ticks) { if (diff > 0xffffff) { diff = 0xffffff; } - nrfx_rtc_cc_set(&rtc_instance, 0, current_ticks + diff, true); + nrfx_rtc_cc_set(&rtc_instance, channel, current_ticks + diff, true); +} + +void port_disable_interrupt_after_ticks_ch(uint32_t channel) { + nrfx_rtc_cc_disable(&rtc_instance, channel); +} + +void port_interrupt_after_ticks(uint32_t ticks) { + port_interrupt_after_ticks_ch(0, ticks); } void port_idle_until_interrupt(void) { diff --git a/supervisor/serial.h b/supervisor/serial.h index 066886303e..6cd8530b36 100644 --- a/supervisor/serial.h +++ b/supervisor/serial.h @@ -29,6 +29,7 @@ #include #include +#include #include "py/mpconfig.h" @@ -47,4 +48,6 @@ char serial_read(void); bool serial_bytes_available(void); bool serial_connected(void); +int dbg_printf(const char *fmt, ...)__attribute__((format (printf, 1, 2))); + #endif // MICROPY_INCLUDED_SUPERVISOR_SERIAL_H diff --git a/supervisor/shared/serial.c b/supervisor/shared/serial.c index b9feb04f25..2db4c6b2ec 100644 --- a/supervisor/shared/serial.c +++ b/supervisor/shared/serial.c @@ -36,6 +36,103 @@ #include "tusb.h" +#ifdef MY_DEBUGUART +#include +#include +#include "nrfx.h" +#include "nrf_uart.h" +#include "nrfx_uart.h" +const nrfx_uarte_t _dbg_uart_inst = NRFX_UARTE_INSTANCE(1); +static int _dbg_uart_initialized = 0; +#define DBG_PBUF_LEN 80 +static char _dbg_pbuf[DBG_PBUF_LEN+1]; + +void _debug_uart_init(void) { + //if (_dbg_uart_initialized) return; + nrfx_uarte_config_t config = { + .pseltxd = 26, + .pselrxd = 15, + .pselcts = NRF_UARTE_PSEL_DISCONNECTED, + .pselrts = NRF_UARTE_PSEL_DISCONNECTED, + .p_context = NULL, + .baudrate = NRF_UART_BAUDRATE_115200, + .interrupt_priority = 7, + .hal_cfg = { + .hwfc = NRF_UARTE_HWFC_DISABLED, + .parity = NRF_UARTE_PARITY_EXCLUDED + } + }; + nrfx_uarte_init(&_dbg_uart_inst, &config, NULL); + // drive config + nrf_gpio_cfg(config.pseltxd, + NRF_GPIO_PIN_DIR_OUTPUT, + NRF_GPIO_PIN_INPUT_DISCONNECT, + NRF_GPIO_PIN_PULLUP, // orig=NOPULL + NRF_GPIO_PIN_H0H1, // orig=S0S1 + NRF_GPIO_PIN_NOSENSE); + _dbg_uart_initialized = 1; + return; +} + +void _debug_printbuf(char* data) { + int siz, l; + while((l = strlen(data)) != 0) { + if (l <= DBG_PBUF_LEN) { + siz = l; + } + else { + siz = DBG_PBUF_LEN; + } + memcpy(_dbg_pbuf, data, siz); + _dbg_pbuf[siz] = 0; + nrfx_uarte_tx(&_dbg_uart_inst, (uint8_t const*)_dbg_pbuf, siz); + data += siz; + } +} + +void _debug_print_substr(const char* text, uint32_t length) { + char* data = (char*)text; + int siz; + while(length != 0) { + if (length <= DBG_PBUF_LEN) { + siz = length; + } + else { + siz = DBG_PBUF_LEN; + } + memcpy(_dbg_pbuf, data, siz); + _dbg_pbuf[siz] = 0; + nrfx_uarte_tx(&_dbg_uart_inst, (uint8_t const*)_dbg_pbuf, siz); + data += siz; + length -= siz; + } +} + +void _debug_print(const char* s) { + _debug_printbuf((char*)s); +} + +void _debug_uart_deinit(void) { + nrfx_uarte_uninit(&_dbg_uart_inst); +} + +int dbg_printf(const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + int ret = vprintf(fmt, ap); + va_end(ap); + return ret; +} + +extern void _debug_led_init(void); +extern void _debug_led_set(int v); +#else /*!MY_DEBUGUART*/ +int dbg_printf(const char *fmt, ...) { + return 0; +} +#endif + + /* * Note: DEBUG_UART currently only works on STM32, * enabling on another platform will cause a crash. @@ -63,10 +160,19 @@ void serial_early_init(void) { buf_array, true); common_hal_busio_uart_never_reset(&debug_uart); #endif + +#ifdef MY_DEBUGUART + _debug_uart_init(); + _debug_led_init(); + _debug_print("\r\ndebug_uart start\r\n"); +#endif } void serial_init(void) { usb_init(); +#ifdef MY_DEBUGUART + _debug_uart_init(); +#endif } bool serial_connected(void) { @@ -144,6 +250,10 @@ void serial_write_substring(const char* text, uint32_t length) { int uart_errcode; common_hal_busio_uart_write(&debug_uart, (const uint8_t*) text, length, &uart_errcode); #endif + +#ifdef MY_DEBUGUART + _debug_print_substr(text, length); +#endif } void serial_write(const char* text) { From cf2427c5618339fa248c41064796f5c39a4e5bf2 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Wed, 17 Feb 2021 21:51:28 +0900 Subject: [PATCH 003/103] light sleep reason fix. --- ports/nrf/common-hal/alarm/__init__.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index d5a4aec3c8..c91593861a 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -144,6 +144,7 @@ STATIC void _setup_sleep_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t STATIC void _idle_until_alarm(void) { int ct = 40; + reset_reason_saved = 0; // Poll for alarms. while (!mp_hal_is_interrupted()) { RUN_BACKGROUND_TASKS; From 26f8f532f126bb0b66e3a812d46e78fabf73f5f6 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 21 Feb 2021 00:47:07 +0900 Subject: [PATCH 004/103] safe mode fix. --- .gitignore | 6 ++ main.c | 15 +++- ports/nrf/common-hal/alarm/SleepMemory.c | 69 +++++++++++++++++-- ports/nrf/common-hal/alarm/__init__.c | 57 +++++++++++---- ports/nrf/common-hal/alarm/__init__.h | 1 + ports/nrf/common-hal/alarm/pin/PinAlarm.c | 26 +++++-- .../common-hal/microcontroller/Processor.c | 22 +++++- ports/nrf/supervisor/port.c | 8 ++- supervisor/shared/serial.c | 21 ------ 9 files changed, 175 insertions(+), 50 deletions(-) diff --git a/.gitignore b/.gitignore index a8814be45e..6f27970f89 100644 --- a/.gitignore +++ b/.gitignore @@ -86,3 +86,9 @@ TAGS #################### .venv .env + +1FILES +2FILES +TAG +ports/nrf/LOG*.txt +ports/nrf/boards/pg8c diff --git a/main.c b/main.c index 054c6b4f53..b3c783bf79 100755 --- a/main.c +++ b/main.c @@ -214,7 +214,7 @@ STATIC bool maybe_run_list(const char * const * filenames, pyexec_result_t* exec decompress(compressed, decompressed); mp_hal_stdout_tx_str(decompressed); pyexec_file(filename, exec_result); - dbg_printf("pyexec_file end result=(code=%d, line=%d)\r\n", exec_result->return_code, exec_result->exception_line); + //dbg_printf("pyexec_file end result=(code=%d, line=%d)\r\n", exec_result->return_code, exec_result->exception_line); return true; } @@ -260,7 +260,7 @@ STATIC void print_code_py_status_message(safe_mode_t safe_mode) { } STATIC bool run_code_py(safe_mode_t safe_mode) { - dbg_printf("run_code_py (%d)\r\n", (int)safe_mode); + //dbg_printf("run_code_py (%d)\r\n", (int)safe_mode); bool serial_connected_at_start = serial_connected(); #if CIRCUITPY_AUTORELOAD_DELAY_MS > 0 serial_write("\n"); @@ -436,7 +436,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { FIL* boot_output_file; STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { - dbg_printf("run_boot_py (%d)\r\n", (int)safe_mode); + //dbg_printf("run_boot_py (%d)\r\n", (int)safe_mode); // If not in safe mode, run boot before initing USB and capture output in a // file. if (filesystem_present() && safe_mode == NO_SAFE_MODE && MP_STATE_VM(vfs_mount_table) != NULL) { @@ -583,6 +583,15 @@ int __attribute__((used)) main(void) { // Start serial and HID after giving boot.py a chance to tweak behavior. serial_init(); +#if 0 //XXX + int rr = (int)common_hal_mcu_processor_get_reset_reason(); + const char* rrstr[] = { + "POWER_ON", "BROWNOUT", "SOFTWARE", "DEEPSLEEPALARM", + "RESET_PIN", "WATCHDOG", "UNKNOWN" + }; + dbg_printf("reset_reason=%s\r\n", rrstr[rr]); +#endif + #if CIRCUITPY_BLEIO supervisor_start_bluetooth(); #endif diff --git a/ports/nrf/common-hal/alarm/SleepMemory.c b/ports/nrf/common-hal/alarm/SleepMemory.c index dd87b31b17..a867b17b13 100644 --- a/ports/nrf/common-hal/alarm/SleepMemory.c +++ b/ports/nrf/common-hal/alarm/SleepMemory.c @@ -26,23 +26,84 @@ */ #include +#ifdef MY_DEBUGUART +#include "supervisor/serial.h" // dbg_printf() +#endif #include "py/runtime.h" #include "common-hal/alarm/SleepMemory.h" -//static RTC_DATA_ATTR uint8_t _sleep_mem[SLEEP_MEMORY_LENGTH]; +#define RTC_DATA_ATTR __attribute__((section(".uninitialized"))) +static RTC_DATA_ATTR uint8_t _sleep_mem[SLEEP_MEMORY_LENGTH]; +static RTC_DATA_ATTR uint32_t _sleep_mem_magicnum; +#define SLEEP_MEMORY_DATA_GUARD 0xad0000af +#define SLEEP_MEMORY_DATA_GUARD_MASK 0xff0000ff + +static int is_sleep_memory_valid(void) { + if ((_sleep_mem_magicnum & SLEEP_MEMORY_DATA_GUARD_MASK) + == SLEEP_MEMORY_DATA_GUARD) { + return 1; + } + return 0; +} + +static void dumpRAMreg(void) { +#ifdef MY_DEBUGUART + int i; + for(i = 0; i <= 8; ++i) { + dbg_printf(" RAM%d:%08X", i, (int)(NRF_POWER->RAM[i].POWER)); + if (i==4) dbg_printf("\r\n"); + } + dbg_printf("\r\n"); +#endif +} + +static void initialize_sleep_memory(void) { + memset((uint8_t *)_sleep_mem, 0, SLEEP_MEMORY_LENGTH); + + // also, set RAM[n].POWER register for RAM retention + // nRF52840 has RAM[0..7].Section[0..1] and RAM[8].Section[0..5] + // nRF52833 has RAM[0..7].Section[0..1] and RAM[8].Section[0,1] + dumpRAMreg(); + for(int ram = 0; ram <= 7; ++ram) { + NRF_POWER->RAM[ram].POWERSET = 0x00030000; // RETENTION for section 0,1 + }; +#ifdef NRF52840 + NRF_POWER->RAM[8].POWERSET = 0x001F0000; // RETENTION for section 0..5 +#endif +#ifdef NRF52833 + NRF_POWER->RAM[8].POWERSET = 0x00030000; // RETENTION for section 0,1 +#endif + dumpRAMreg(); + + _sleep_mem_magicnum = SLEEP_MEMORY_DATA_GUARD; +} void alarm_sleep_memory_reset(void) { + if (!is_sleep_memory_valid()) { + initialize_sleep_memory(); +#ifdef MY_DEBUGUART + dbg_printf("_sleep_mem[] initialized\r\n"); +#endif + } } uint32_t common_hal_alarm_sleep_memory_get_length(alarm_sleep_memory_obj_t *self) { - return 0; + return sizeof(_sleep_mem); } bool common_hal_alarm_sleep_memory_set_bytes(alarm_sleep_memory_obj_t *self, uint32_t start_index, const uint8_t* values, uint32_t len) { - return false; + if (start_index + len > sizeof(_sleep_mem)) { + return false; + } + + memcpy((uint8_t *) (_sleep_mem + start_index), values, len); + return true; } void common_hal_alarm_sleep_memory_get_bytes(alarm_sleep_memory_obj_t *self, uint32_t start_index, uint8_t* values, uint32_t len) { - return; + if (start_index + len > sizeof(_sleep_mem)) { + return; + } + memcpy(values, (uint8_t *) (_sleep_mem + start_index), len); } diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index c91593861a..1823bf4649 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -42,14 +42,15 @@ //#include "shared-bindings/microcontroller/__init__.h" #include "supervisor/port.h" +#ifdef MY_DEBUGUART +#include "supervisor/serial.h" // dbg_printf() +#endif #include "nrf.h" #include "nrf_power.h" #include "nrfx.h" #include "nrfx_gpiote.h" -extern void _debug_print(const char* s); -extern void _xxx_dumpRTC(void);//XXXX #define DEBUG_LED_PIN (NRF_GPIO_PIN_MAP(1, 11)) // P1_11 = LED void _debug_led_init(void) { @@ -68,14 +69,14 @@ const alarm_sleep_memory_obj_t alarm_sleep_memory_obj = { }; void alarm_reset(void) { - //alarm_sleep_memory_reset(); + alarm_sleep_memory_reset(); alarm_pin_pinalarm_reset(); alarm_time_timealarm_reset(); //alarm_touch_touchalarm_reset(); } extern uint32_t reset_reason_saved; -STATIC uint32_t _get_wakeup_cause(void) { +STATIC nrf_sleep_source_t _get_wakeup_cause(void) { if (alarm_pin_pinalarm_woke_us_up()) { return NRF_SLEEP_WAKEUP_GPIO; } @@ -101,17 +102,30 @@ STATIC uint32_t _get_wakeup_cause(void) { } bool alarm_woken_from_sleep(void) { - uint32_t cause = _get_wakeup_cause(); + nrf_sleep_source_t cause = _get_wakeup_cause(); return (cause == NRF_SLEEP_WAKEUP_GPIO || cause == NRF_SLEEP_WAKEUP_TIMER || cause == NRF_SLEEP_WAKEUP_TOUCHPAD || cause == NRF_SLEEP_WAKEUP_RESETPIN); } +#ifdef MY_DEBUGUART +static const char* cause_str[] = { + "UNDEFINED", + "GPIO", + "TIMER", + "TOUCHPAD", + "VBUS", + "RESETPIN", +}; +#endif + STATIC mp_obj_t _get_wake_alarm(size_t n_alarms, const mp_obj_t *alarms) { - uint32_t cause = _get_wakeup_cause(); - if (cause & 0x80000000) { - printf("wakeup cause = 0x%08X\r\n", (int)cause); + nrf_sleep_source_t cause = _get_wakeup_cause(); +#if 0 + if (cause >= 0 && cause < NRF_SLEEP_WAKEUP_ZZZ) { + printf("wakeup cause = NRF_SLEEP_WAKEUP_%s\r\n", cause_str[(int)cause]); } +#endif switch (cause) { case NRF_SLEEP_WAKEUP_TIMER: { return alarm_time_timealarm_get_wakeup_alarm(n_alarms, alarms); @@ -122,13 +136,14 @@ STATIC mp_obj_t _get_wake_alarm(size_t n_alarms, const mp_obj_t *alarms) { case NRF_SLEEP_WAKEUP_GPIO: { return alarm_pin_pinalarm_get_wakeup_alarm(n_alarms, alarms); } + default: + break; } return mp_const_none; } mp_obj_t common_hal_alarm_get_wake_alarm(void) { mp_obj_t obj = _get_wake_alarm(0, NULL); - //_xxx_dumpRTC();//XXX return obj; } @@ -139,11 +154,12 @@ STATIC void _setup_sleep_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t #if 0 alarm_touch_touchalarm_set_alarm(deep_sleep, n_alarms, alarms); #endif - //_xxx_dumpRTC(); } STATIC void _idle_until_alarm(void) { +#ifdef MY_DEBUGUART int ct = 40; +#endif reset_reason_saved = 0; // Poll for alarms. while (!mp_hal_is_interrupted()) { @@ -151,26 +167,35 @@ STATIC void _idle_until_alarm(void) { // Allow ctrl-C interrupt. if (alarm_woken_from_sleep()) { alarm_save_wake_alarm(); +#ifdef MY_DEBUGUART int cause = _get_wakeup_cause(); - printf("wakeup(%d)\r\n", cause); //XXX + printf("wakeup(%d)\r\n", cause); +#endif return; } port_idle_until_interrupt(); +#ifdef MY_DEBUGUART if (ct > 0) { - printf("_"); --ct; + printf("_"); + --ct; } +#endif } } mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj_t *alarms) { mp_obj_t r_obj = mp_const_none; _setup_sleep_alarms(false, n_alarms, alarms); - _debug_print("\r\nsleep..."); +#ifdef MY_DEBUGUART + dbg_printf("\r\nsleep..."); +#endif _idle_until_alarm(); if (mp_hal_is_interrupted()) { - _debug_print("mp_hal_is_interrupted\r\n"); +#ifdef MY_DEBUGUART + dbg_printf("mp_hal_is_interrupted\r\n"); +#endif r_obj = mp_const_none; } else { @@ -185,7 +210,9 @@ void common_hal_alarm_set_deep_sleep_alarms(size_t n_alarms, const mp_obj_t *ala } void nrf_deep_sleep_start(void) { - _debug_print("go system off..\r\n"); +#ifdef MY_DEBUGUART + dbg_printf("go system off..\r\n"); +#endif sd_power_system_off(); } diff --git a/ports/nrf/common-hal/alarm/__init__.h b/ports/nrf/common-hal/alarm/__init__.h index 11652ec828..6fa07bcd29 100644 --- a/ports/nrf/common-hal/alarm/__init__.h +++ b/ports/nrf/common-hal/alarm/__init__.h @@ -36,6 +36,7 @@ typedef enum { NRF_SLEEP_WAKEUP_TOUCHPAD, NRF_SLEEP_WAKEUP_VBUS, NRF_SLEEP_WAKEUP_RESETPIN, + NRF_SLEEP_WAKEUP_ZZZ } nrf_sleep_source_t; extern const alarm_sleep_memory_obj_t alarm_sleep_memory_obj; diff --git a/ports/nrf/common-hal/alarm/pin/PinAlarm.c b/ports/nrf/common-hal/alarm/pin/PinAlarm.c index 0e0f6c4832..1945beaaf8 100644 --- a/ports/nrf/common-hal/alarm/pin/PinAlarm.c +++ b/ports/nrf/common-hal/alarm/pin/PinAlarm.c @@ -146,30 +146,40 @@ void _setup2(void) { }; for(size_t i = 0; i < 64; ++i) { uint64_t mask = 1ull << i; +#ifdef MY_DEBUGUART int pull = 0; int sense = 0; +#endif if (((high_alarms & mask) == 0) && ((low_alarms & mask) == 0)) { continue; } if (((high_alarms & mask) != 0) && ((low_alarms & mask) == 0)) { cfg.sense = NRF_GPIOTE_POLARITY_LOTOHI; cfg.pull = ((pull_pins & mask) != 0) ? NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_NOPULL; +#ifdef MY_DEBUGUART pull = -1; sense = 1; +#endif } else if (((high_alarms & mask) == 0) && ((low_alarms & mask) != 0)) { cfg.sense = NRF_GPIOTE_POLARITY_HITOLO; cfg.pull = ((pull_pins & mask) != 0) ? NRF_GPIO_PIN_PULLUP : NRF_GPIO_PIN_NOPULL; +#ifdef MY_DEBUGUART pull = 1; sense = -1; +#endif } else { cfg.sense = NRF_GPIOTE_POLARITY_TOGGLE; cfg.pull = NRF_GPIO_PIN_NOPULL; +#ifdef MY_DEBUGUART sense = 9; +#endif } nrfx_gpiote_in_init((nrfx_gpiote_pin_t)i, &cfg, pinalarm_gpiote_handler); nrfx_gpiote_in_event_enable((nrfx_gpiote_pin_t)i, true); - printf("pin=%d, sense=%d, pull=%d\r\n", i, sense, pull); +#ifdef MY_DEBUGUART + dbg_printf("pin=%d, sense=%d, pull=%d\r\n", i, sense, pull); +#endif } } @@ -188,7 +198,9 @@ void _setup_pin1_for_deepsleep(void) { for(size_t i = 0; i < 64; ++i) { uint64_t mask = 1ull << i; int pull = 0; +#ifdef MY_DEBUGUART int sense = 0; +#endif if (((high_alarms & mask) == 0) && ((low_alarms & mask) == 0)) { continue; } @@ -196,16 +208,22 @@ void _setup_pin1_for_deepsleep(void) { pull = ((pull_pins & mask) != 0) ? NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_NOPULL; nrf_gpio_cfg_input((uint32_t)i, (nrf_gpio_pin_pull_t)pull); nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_HIGH); +#ifdef MY_DEBUGUART sense = NRF_GPIO_PIN_SENSE_HIGH; +#endif } else if (((high_alarms & mask) == 0) && ((low_alarms & mask) != 0)) { pull = ((pull_pins & mask) != 0) ? NRF_GPIO_PIN_PULLUP : NRF_GPIO_PIN_NOPULL; nrf_gpio_cfg_input((uint32_t)i, (nrf_gpio_pin_pull_t)pull); nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_LOW); +#ifdef MY_DEBUGUART sense = NRF_GPIO_PIN_SENSE_LOW; +#endif } - printf("pin=%d, sense=%d, pull=%d\r\n", i, sense, pull); +#ifdef MY_DEBUGUART + dbg_printf("pin=%d, sense=%d, pull=%d\r\n", i, sense, pull); +#endif } #if 0 uint32_t pin_number = 2; @@ -230,7 +248,7 @@ void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ob alarm_pin_pinalarm_obj_t *alarm = MP_OBJ_TO_PTR(alarms[i]); pin_number = alarm->pin->number; - dbg_printf("alarm_pin_pinalarm_set_alarms(pin#=%d, val=%d, pull=%d)\r\n", pin_number, alarm->value, alarm->pull); + //dbg_printf("alarm_pin_pinalarm_set_alarms(pin#=%d, val=%d, pull=%d)\r\n", pin_number, alarm->value, alarm->pull); if (alarm->value) { high_alarms |= 1ull << pin_number; high_count++; @@ -251,7 +269,7 @@ void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ob } } else { - dbg_printf("alarm_pin_pinalarm_set_alarms() no valid pins\r\n"); + //dbg_printf("alarm_pin_pinalarm_set_alarms() no valid pins\r\n"); } } diff --git a/ports/nrf/common-hal/microcontroller/Processor.c b/ports/nrf/common-hal/microcontroller/Processor.c index ab5f29b5db..5564c86c54 100644 --- a/ports/nrf/common-hal/microcontroller/Processor.c +++ b/ports/nrf/common-hal/microcontroller/Processor.c @@ -122,6 +122,26 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { } } +extern uint32_t reset_reason_saved; mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { - return RESET_REASON_UNKNOWN; + mcu_reset_reason_t r = RESET_REASON_UNKNOWN; + if (reset_reason_saved == 0) { + r = RESET_REASON_POWER_ON; + } + else if (reset_reason_saved & POWER_RESETREAS_RESETPIN_Msk) { + r = RESET_REASON_RESET_PIN; + } + else if (reset_reason_saved & POWER_RESETREAS_DOG_Msk) { + r = RESET_REASON_WATCHDOG; + } + else if (reset_reason_saved & POWER_RESETREAS_SREQ_Msk) { + r = RESET_REASON_SOFTWARE; + } + else if ((reset_reason_saved & POWER_RESETREAS_OFF_Msk) || + (reset_reason_saved & POWER_RESETREAS_LPCOMP_Msk) || + (reset_reason_saved & POWER_RESETREAS_NFC_Msk) || + (reset_reason_saved & POWER_RESETREAS_VBUS_Msk)) { + r = RESET_REASON_DEEP_SLEEP_ALARM; + } + return r; } diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c index 3ed822ed76..6e19e7645e 100644 --- a/ports/nrf/supervisor/port.c +++ b/ports/nrf/supervisor/port.c @@ -114,7 +114,8 @@ void rtc_handler(nrfx_rtc_int_type_t int_type) { } } -void _xxx_dumpRTC(void) { +#ifdef MY_DEBUGUART +void dbg_dumpRTC(void) { dbg_printf("\r\nRTC2\r\n"); NRF_RTC_Type *r = rtc_instance.p_reg; dbg_printf("PRESCALER=%08X, ", (int)r->PRESCALER); @@ -125,6 +126,7 @@ void _xxx_dumpRTC(void) { dbg_printf("CC[0..3]=%08X,%08X,%08X,%08X\r\n", (int)r->CC[0], (int)r->CC[1], (int)r->CC[2], (int)r->CC[3]); dbg_printf("woke_up=%d\r\n", rtc_woke_up_counter); } +#endif void tick_init(void) { if (!nrf_clock_lf_is_running(NRF_CLOCK)) { @@ -178,12 +180,14 @@ safe_mode_t port_init(void) { #endif reset_reason_saved = NRF_POWER->RESETREAS; + // clear all RESET reason bits + NRF_POWER->RESETREAS = reset_reason_saved; // If the board was reset by the WatchDogTimer, we may // need to boot into safe mode. Reset the RESETREAS bit // for the WatchDogTimer so we don't encounter this the // next time we reboot. - if (NRF_POWER->RESETREAS & POWER_RESETREAS_DOG_Msk) { + if (reset_reason_saved & POWER_RESETREAS_DOG_Msk) { NRF_POWER->RESETREAS = POWER_RESETREAS_DOG_Msk; uint32_t usb_reg = NRF_POWER->USBREGSTATUS; diff --git a/supervisor/shared/serial.c b/supervisor/shared/serial.c index 2db4c6b2ec..b5d4ef919c 100644 --- a/supervisor/shared/serial.c +++ b/supervisor/shared/serial.c @@ -74,22 +74,6 @@ void _debug_uart_init(void) { return; } -void _debug_printbuf(char* data) { - int siz, l; - while((l = strlen(data)) != 0) { - if (l <= DBG_PBUF_LEN) { - siz = l; - } - else { - siz = DBG_PBUF_LEN; - } - memcpy(_dbg_pbuf, data, siz); - _dbg_pbuf[siz] = 0; - nrfx_uarte_tx(&_dbg_uart_inst, (uint8_t const*)_dbg_pbuf, siz); - data += siz; - } -} - void _debug_print_substr(const char* text, uint32_t length) { char* data = (char*)text; int siz; @@ -108,10 +92,6 @@ void _debug_print_substr(const char* text, uint32_t length) { } } -void _debug_print(const char* s) { - _debug_printbuf((char*)s); -} - void _debug_uart_deinit(void) { nrfx_uarte_uninit(&_dbg_uart_inst); } @@ -164,7 +144,6 @@ void serial_early_init(void) { #ifdef MY_DEBUGUART _debug_uart_init(); _debug_led_init(); - _debug_print("\r\ndebug_uart start\r\n"); #endif } From 41d9d4e0ab2398d2f851269e9771bd0458de8ec5 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 21 Feb 2021 08:17:57 +0900 Subject: [PATCH 005/103] call sd API only when sd enabled. --- ports/nrf/common-hal/alarm/__init__.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index 1823bf4649..4fe8432a1f 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -109,6 +109,7 @@ bool alarm_woken_from_sleep(void) { } #ifdef MY_DEBUGUART +#if 0 static const char* cause_str[] = { "UNDEFINED", "GPIO", @@ -118,6 +119,7 @@ static const char* cause_str[] = { "RESETPIN", }; #endif +#endif STATIC mp_obj_t _get_wake_alarm(size_t n_alarms, const mp_obj_t *alarms) { nrf_sleep_source_t cause = _get_wakeup_cause(); @@ -209,18 +211,21 @@ void common_hal_alarm_set_deep_sleep_alarms(size_t n_alarms, const mp_obj_t *ala _setup_sleep_alarms(true, n_alarms, alarms); } -void nrf_deep_sleep_start(void) { -#ifdef MY_DEBUGUART - dbg_printf("go system off..\r\n"); -#endif - sd_power_system_off(); -} - void NORETURN alarm_enter_deep_sleep(void) { alarm_pin_pinalarm_prepare_for_deep_sleep(); //alarm_touch_touchalarm_prepare_for_deep_sleep(); - nrf_deep_sleep_start(); + uint8_t sd_enabled; + sd_softdevice_is_enabled(&sd_enabled); +#ifdef MY_DEBUGUART + dbg_printf("go system off.. %d\r\n", sd_enabled); +#endif + if (sd_enabled) { + sd_power_system_off(); + } + else { + NRF_POWER->SYSTEMOFF = 1; + } // should not reach here.. while(1) ; From 793198909eff7dee17fd79b2f5d6b6eceb1978c9 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 21 Feb 2021 08:19:39 +0900 Subject: [PATCH 006/103] set SleepMemory size to 256 bytes. --- ports/nrf/common-hal/alarm/SleepMemory.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ports/nrf/common-hal/alarm/SleepMemory.h b/ports/nrf/common-hal/alarm/SleepMemory.h index ea3d40c35a..24fe0065d0 100644 --- a/ports/nrf/common-hal/alarm/SleepMemory.h +++ b/ports/nrf/common-hal/alarm/SleepMemory.h @@ -29,8 +29,7 @@ #include "py/obj.h" -// not implemented yet -#define SLEEP_MEMORY_LENGTH (4) +#define SLEEP_MEMORY_LENGTH (256) typedef struct { mp_obj_base_t base; From d659c2ce3401c3a33b73d5e6074dd7c93a9deffc Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 21 Feb 2021 09:55:10 +0900 Subject: [PATCH 007/103] move port-specific debug functions from supervisor/shared/serial.c to ports/nrf/supervisor/port.c --- ports/nrf/supervisor/port.c | 78 ++++++++++++++++++++++++++++++++++++- supervisor/serial.h | 1 + supervisor/shared/serial.c | 78 ++----------------------------------- 3 files changed, 80 insertions(+), 77 deletions(-) diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c index 6e19e7645e..d3c31b51a6 100644 --- a/ports/nrf/supervisor/port.c +++ b/ports/nrf/supervisor/port.c @@ -77,6 +77,82 @@ static void power_warning_handler(void) { reset_into_safe_mode(BROWNOUT); } +#ifdef MY_DEBUGUART +#include +#include +#include "nrfx.h" +#include "nrf_uart.h" +#include "nrfx_uart.h" +const nrfx_uarte_t _dbg_uart_inst = NRFX_UARTE_INSTANCE(1); +static int _dbg_uart_initialized = 0; +#define DBG_PBUF_LEN 80 +static char _dbg_pbuf[DBG_PBUF_LEN+1]; + +void _debug_uart_init(void) { + //if (_dbg_uart_initialized) return; + nrfx_uarte_config_t config = { + .pseltxd = 26, + .pselrxd = 15, + .pselcts = NRF_UARTE_PSEL_DISCONNECTED, + .pselrts = NRF_UARTE_PSEL_DISCONNECTED, + .p_context = NULL, + .baudrate = NRF_UART_BAUDRATE_115200, + .interrupt_priority = 7, + .hal_cfg = { + .hwfc = NRF_UARTE_HWFC_DISABLED, + .parity = NRF_UARTE_PARITY_EXCLUDED + } + }; + nrfx_uarte_init(&_dbg_uart_inst, &config, NULL); + // drive config + nrf_gpio_cfg(config.pseltxd, + NRF_GPIO_PIN_DIR_OUTPUT, + NRF_GPIO_PIN_INPUT_DISCONNECT, + NRF_GPIO_PIN_PULLUP, // orig=NOPULL + NRF_GPIO_PIN_H0H1, // orig=S0S1 + NRF_GPIO_PIN_NOSENSE); + _dbg_uart_initialized = 1; + return; +} + +void _debug_print_substr(const char* text, uint32_t length) { + char* data = (char*)text; + int siz; + while(length != 0) { + if (length <= DBG_PBUF_LEN) { + siz = length; + } + else { + siz = DBG_PBUF_LEN; + } + memcpy(_dbg_pbuf, data, siz); + _dbg_pbuf[siz] = 0; + nrfx_uarte_tx(&_dbg_uart_inst, (uint8_t const*)_dbg_pbuf, siz); + data += siz; + length -= siz; + } +} + +void _debug_uart_deinit(void) { + nrfx_uarte_uninit(&_dbg_uart_inst); +} + +int dbg_printf(const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + int ret = vprintf(fmt, ap); + va_end(ap); + return ret; +} + +extern void _debug_led_init(void); +extern void _debug_led_set(int v); +#else /*!MY_DEBUGUART*/ +int dbg_printf(const char *fmt, ...) { + return 0; +} +#endif + const nrfx_rtc_t rtc_instance = NRFX_RTC_INSTANCE(2); const nrfx_rtc_config_t rtc_config = { @@ -149,7 +225,6 @@ void tick_init(void) { } } - safe_mode_t port_init(void) { nrf_peripherals_clocks_init(); @@ -201,7 +276,6 @@ safe_mode_t port_init(void) { return NO_SAFE_MODE; } - void reset_port(void) { #ifdef CIRCUITPY_GAMEPAD_TICKS gamepad_reset(); diff --git a/supervisor/serial.h b/supervisor/serial.h index 6cd8530b36..457ee5336a 100644 --- a/supervisor/serial.h +++ b/supervisor/serial.h @@ -48,6 +48,7 @@ char serial_read(void); bool serial_bytes_available(void); bool serial_connected(void); +// XXX used in nrf52-sleep debug int dbg_printf(const char *fmt, ...)__attribute__((format (printf, 1, 2))); #endif // MICROPY_INCLUDED_SUPERVISOR_SERIAL_H diff --git a/supervisor/shared/serial.c b/supervisor/shared/serial.c index b5d4ef919c..d2fde39a64 100644 --- a/supervisor/shared/serial.c +++ b/supervisor/shared/serial.c @@ -37,82 +37,11 @@ #include "tusb.h" #ifdef MY_DEBUGUART -#include -#include -#include "nrfx.h" -#include "nrf_uart.h" -#include "nrfx_uart.h" -const nrfx_uarte_t _dbg_uart_inst = NRFX_UARTE_INSTANCE(1); -static int _dbg_uart_initialized = 0; -#define DBG_PBUF_LEN 80 -static char _dbg_pbuf[DBG_PBUF_LEN+1]; - -void _debug_uart_init(void) { - //if (_dbg_uart_initialized) return; - nrfx_uarte_config_t config = { - .pseltxd = 26, - .pselrxd = 15, - .pselcts = NRF_UARTE_PSEL_DISCONNECTED, - .pselrts = NRF_UARTE_PSEL_DISCONNECTED, - .p_context = NULL, - .baudrate = NRF_UART_BAUDRATE_115200, - .interrupt_priority = 7, - .hal_cfg = { - .hwfc = NRF_UARTE_HWFC_DISABLED, - .parity = NRF_UARTE_PARITY_EXCLUDED - } - }; - nrfx_uarte_init(&_dbg_uart_inst, &config, NULL); - // drive config - nrf_gpio_cfg(config.pseltxd, - NRF_GPIO_PIN_DIR_OUTPUT, - NRF_GPIO_PIN_INPUT_DISCONNECT, - NRF_GPIO_PIN_PULLUP, // orig=NOPULL - NRF_GPIO_PIN_H0H1, // orig=S0S1 - NRF_GPIO_PIN_NOSENSE); - _dbg_uart_initialized = 1; - return; -} - -void _debug_print_substr(const char* text, uint32_t length) { - char* data = (char*)text; - int siz; - while(length != 0) { - if (length <= DBG_PBUF_LEN) { - siz = length; - } - else { - siz = DBG_PBUF_LEN; - } - memcpy(_dbg_pbuf, data, siz); - _dbg_pbuf[siz] = 0; - nrfx_uarte_tx(&_dbg_uart_inst, (uint8_t const*)_dbg_pbuf, siz); - data += siz; - length -= siz; - } -} - -void _debug_uart_deinit(void) { - nrfx_uarte_uninit(&_dbg_uart_inst); -} - -int dbg_printf(const char *fmt, ...) { - va_list ap; - va_start(ap, fmt); - int ret = vprintf(fmt, ap); - va_end(ap); - return ret; -} - -extern void _debug_led_init(void); -extern void _debug_led_set(int v); -#else /*!MY_DEBUGUART*/ -int dbg_printf(const char *fmt, ...) { - return 0; -} +// XXX these functions are in nrf/supervisor/port.c +extern void _debug_uart_init(void); +extern void _debug_print_substr(const char* text, uint32_t length); #endif - /* * Note: DEBUG_UART currently only works on STM32, * enabling on another platform will cause a crash. @@ -143,7 +72,6 @@ void serial_early_init(void) { #ifdef MY_DEBUGUART _debug_uart_init(); - _debug_led_init(); #endif } From 36c59250dde158d8b123ba8c20091fb04b3f5160 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 21 Feb 2021 09:57:14 +0900 Subject: [PATCH 008/103] some cleanups. --- ports/nrf/common-hal/alarm/__init__.c | 34 +++-- ports/nrf/common-hal/alarm/pin/PinAlarm.c | 175 +++++++++++----------- 2 files changed, 107 insertions(+), 102 deletions(-) diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index 4fe8432a1f..d39c38fe44 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -51,7 +51,8 @@ #include "nrfx.h" #include "nrfx_gpiote.h" - +#if 0 +// XXX #define DEBUG_LED_PIN (NRF_GPIO_PIN_MAP(1, 11)) // P1_11 = LED void _debug_led_init(void) { nrf_gpio_cfg_output(DEBUG_LED_PIN); @@ -59,7 +60,7 @@ void _debug_led_init(void) { void _debug_led_set(int v) { nrf_gpio_pin_write(DEBUG_LED_PIN, v); } - +#endif // Singleton instance of SleepMemory. const alarm_sleep_memory_obj_t alarm_sleep_memory_obj = { @@ -84,10 +85,10 @@ STATIC nrf_sleep_source_t _get_wakeup_cause(void) { return NRF_SLEEP_WAKEUP_TIMER; } #if 0 + // XXX not implemented yet if (alarm_touch_touchalarm_woke_us_up()) { return ESP_SLEEP_WAKEUP_TOUCHPAD; } - return esp_sleep_get_wakeup_cause(); #endif if (reset_reason_saved & NRF_POWER_RESETREAS_RESETPIN_MASK) { return NRF_SLEEP_WAKEUP_RESETPIN; @@ -130,16 +131,16 @@ STATIC mp_obj_t _get_wake_alarm(size_t n_alarms, const mp_obj_t *alarms) { #endif switch (cause) { case NRF_SLEEP_WAKEUP_TIMER: { - return alarm_time_timealarm_get_wakeup_alarm(n_alarms, alarms); + return alarm_time_timealarm_get_wakeup_alarm(n_alarms, alarms); } case NRF_SLEEP_WAKEUP_TOUCHPAD: { - return mp_const_none; + return mp_const_none; } case NRF_SLEEP_WAKEUP_GPIO: { - return alarm_pin_pinalarm_get_wakeup_alarm(n_alarms, alarms); + return alarm_pin_pinalarm_get_wakeup_alarm(n_alarms, alarms); } default: - break; + break; } return mp_const_none; } @@ -154,6 +155,7 @@ STATIC void _setup_sleep_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t alarm_pin_pinalarm_set_alarms(deep_sleep, n_alarms, alarms); alarm_time_timealarm_set_alarms(deep_sleep, n_alarms, alarms); #if 0 + // XXX not implemented yet alarm_touch_touchalarm_set_alarm(deep_sleep, n_alarms, alarms); #endif } @@ -170,17 +172,17 @@ STATIC void _idle_until_alarm(void) { if (alarm_woken_from_sleep()) { alarm_save_wake_alarm(); #ifdef MY_DEBUGUART - int cause = _get_wakeup_cause(); - printf("wakeup(%d)\r\n", cause); + int cause = _get_wakeup_cause(); + printf("wakeup(%d)\r\n", cause); #endif return; } port_idle_until_interrupt(); #ifdef MY_DEBUGUART - if (ct > 0) { - printf("_"); - --ct; - } + if (ct > 0) { + printf("_"); + --ct; + } #endif } } @@ -201,8 +203,8 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj r_obj = mp_const_none; } else { - r_obj = _get_wake_alarm(n_alarms, alarms); - alarm_reset(); + r_obj = _get_wake_alarm(n_alarms, alarms); + alarm_reset(); } return r_obj; } @@ -213,7 +215,7 @@ void common_hal_alarm_set_deep_sleep_alarms(size_t n_alarms, const mp_obj_t *ala void NORETURN alarm_enter_deep_sleep(void) { alarm_pin_pinalarm_prepare_for_deep_sleep(); - //alarm_touch_touchalarm_prepare_for_deep_sleep(); + //alarm_touch_touchalarm_prepare_for_deep_sleep(); // XXX uint8_t sd_enabled; sd_softdevice_is_enabled(&sd_enabled); diff --git a/ports/nrf/common-hal/alarm/pin/PinAlarm.c b/ports/nrf/common-hal/alarm/pin/PinAlarm.c index 1945beaaf8..9ccc79db92 100644 --- a/ports/nrf/common-hal/alarm/pin/PinAlarm.c +++ b/ports/nrf/common-hal/alarm/pin/PinAlarm.c @@ -78,8 +78,8 @@ bool common_hal_alarm_pin_pinalarm_get_pull(alarm_pin_pinalarm_obj_t *self) { static void pinalarm_gpiote_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { - ++_pinhandler_gpiote_count; - _pinhandler_ev_pin = pin; + ++_pinhandler_gpiote_count; + _pinhandler_ev_pin = pin; } bool alarm_pin_pinalarm_woke_us_up(void) { @@ -136,93 +136,95 @@ void alarm_pin_pinalarm_reset(void) { pull_pins = 0; } -void _setup2(void) { - nrfx_gpiote_in_config_t cfg = { - .sense = NRF_GPIOTE_POLARITY_TOGGLE, - .pull = NRF_GPIO_PIN_PULLUP, - .is_watcher = false, - .hi_accuracy = true, - .skip_gpio_setup = false - }; - for(size_t i = 0; i < 64; ++i) { - uint64_t mask = 1ull << i; -#ifdef MY_DEBUGUART - int pull = 0; - int sense = 0; -#endif - if (((high_alarms & mask) == 0) && ((low_alarms & mask) == 0)) { - continue; +static void setup_pin1_for_lightsleep(void) { + if ( nrfx_gpiote_is_init() ) { + nrfx_gpiote_uninit(); } - if (((high_alarms & mask) != 0) && ((low_alarms & mask) == 0)) { - cfg.sense = NRF_GPIOTE_POLARITY_LOTOHI; - cfg.pull = ((pull_pins & mask) != 0) ? NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_NOPULL; -#ifdef MY_DEBUGUART - pull = -1; sense = 1; -#endif - } - else - if (((high_alarms & mask) == 0) && ((low_alarms & mask) != 0)) { - cfg.sense = NRF_GPIOTE_POLARITY_HITOLO; - cfg.pull = ((pull_pins & mask) != 0) ? NRF_GPIO_PIN_PULLUP : NRF_GPIO_PIN_NOPULL; -#ifdef MY_DEBUGUART - pull = 1; sense = -1; -#endif - } - else { - cfg.sense = NRF_GPIOTE_POLARITY_TOGGLE; - cfg.pull = NRF_GPIO_PIN_NOPULL; -#ifdef MY_DEBUGUART - sense = 9; -#endif - } - nrfx_gpiote_in_init((nrfx_gpiote_pin_t)i, &cfg, pinalarm_gpiote_handler); - nrfx_gpiote_in_event_enable((nrfx_gpiote_pin_t)i, true); -#ifdef MY_DEBUGUART - dbg_printf("pin=%d, sense=%d, pull=%d\r\n", i, sense, pull); -#endif - } -} + nrfx_gpiote_init(NRFX_GPIOTE_CONFIG_IRQ_PRIORITY); -void _setup_pin1_for_lightsleep(void) { - if ( nrfx_gpiote_is_init() ) { - nrfx_gpiote_uninit(); - } - nrfx_gpiote_init(NRFX_GPIOTE_CONFIG_IRQ_PRIORITY); + _pinhandler_gpiote_count = 0; + _pinhandler_ev_pin = MYGPIOTE_EV_PIN_UNDEF; - _pinhandler_gpiote_count = 0; - _pinhandler_ev_pin = MYGPIOTE_EV_PIN_UNDEF; - _setup2(); -} - -void _setup_pin1_for_deepsleep(void) { + nrfx_gpiote_in_config_t cfg = { + .sense = NRF_GPIOTE_POLARITY_TOGGLE, + .pull = NRF_GPIO_PIN_PULLUP, + .is_watcher = false, + .hi_accuracy = true, + .skip_gpio_setup = false + }; for(size_t i = 0; i < 64; ++i) { - uint64_t mask = 1ull << i; - int pull = 0; + uint64_t mask = 1ull << i; #ifdef MY_DEBUGUART - int sense = 0; + int pull = 0; + int sense = 0; #endif - if (((high_alarms & mask) == 0) && ((low_alarms & mask) == 0)) { - continue; - } - if (((high_alarms & mask) != 0) && ((low_alarms & mask) == 0)) { - pull = ((pull_pins & mask) != 0) ? NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_NOPULL; - nrf_gpio_cfg_input((uint32_t)i, (nrf_gpio_pin_pull_t)pull); - nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_HIGH); + if (((high_alarms & mask) == 0) && ((low_alarms & mask) == 0)) { + continue; + } + if (((high_alarms & mask) != 0) && ((low_alarms & mask) == 0)) { + cfg.sense = NRF_GPIOTE_POLARITY_LOTOHI; + cfg.pull = ((pull_pins & mask) != 0) ? + NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_NOPULL; #ifdef MY_DEBUGUART - sense = NRF_GPIO_PIN_SENSE_HIGH; + pull = -1; sense = 1; #endif - } - else - if (((high_alarms & mask) == 0) && ((low_alarms & mask) != 0)) { - pull = ((pull_pins & mask) != 0) ? NRF_GPIO_PIN_PULLUP : NRF_GPIO_PIN_NOPULL; - nrf_gpio_cfg_input((uint32_t)i, (nrf_gpio_pin_pull_t)pull); - nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_LOW); + } + else + if (((high_alarms & mask) == 0) && ((low_alarms & mask) != 0)) { + cfg.sense = NRF_GPIOTE_POLARITY_HITOLO; + cfg.pull = ((pull_pins & mask) != 0) ? + NRF_GPIO_PIN_PULLUP : NRF_GPIO_PIN_NOPULL; #ifdef MY_DEBUGUART - sense = NRF_GPIO_PIN_SENSE_LOW; + pull = 1; sense = -1; #endif - } + } + else { + cfg.sense = NRF_GPIOTE_POLARITY_TOGGLE; + cfg.pull = NRF_GPIO_PIN_NOPULL; #ifdef MY_DEBUGUART - dbg_printf("pin=%d, sense=%d, pull=%d\r\n", i, sense, pull); + sense = 9; +#endif + } + nrfx_gpiote_in_init((nrfx_gpiote_pin_t)i, &cfg, + pinalarm_gpiote_handler); + nrfx_gpiote_in_event_enable((nrfx_gpiote_pin_t)i, true); +#ifdef MY_DEBUGUART + dbg_printf("pin=%d, sense=%d, pull=%d\r\n", i, sense, pull); +#endif + } +} + +static void setup_pin1_for_deepsleep(void) { + for(size_t i = 0; i < 64; ++i) { + uint64_t mask = 1ull << i; + int pull = 0; +#ifdef MY_DEBUGUART + int sense = 0; +#endif + if (((high_alarms & mask) == 0) && ((low_alarms & mask) == 0)) { + continue; + } + if (((high_alarms & mask) != 0) && ((low_alarms & mask) == 0)) { + pull = ((pull_pins & mask) != 0) ? + NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_NOPULL; + nrf_gpio_cfg_input((uint32_t)i, (nrf_gpio_pin_pull_t)pull); + nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_HIGH); +#ifdef MY_DEBUGUART + sense = NRF_GPIO_PIN_SENSE_HIGH; +#endif + } + else + if (((high_alarms & mask) == 0) && ((low_alarms & mask) != 0)) { + pull = ((pull_pins & mask) != 0) ? + NRF_GPIO_PIN_PULLUP : NRF_GPIO_PIN_NOPULL; + nrf_gpio_cfg_input((uint32_t)i, (nrf_gpio_pin_pull_t)pull); + nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_LOW); +#ifdef MY_DEBUGUART + sense = NRF_GPIO_PIN_SENSE_LOW; +#endif + } +#ifdef MY_DEBUGUART + dbg_printf("pin=%d, sense=%d, pull=%d\r\n", i, sense, pull); #endif } #if 0 @@ -261,18 +263,19 @@ void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ob } } if (pin_number != -1) { - if (!deep_sleep) { - _setup_pin1_for_lightsleep(); - } - else { - //_setup_pin1_for_deepsleep(pin_number); - } + if (!deep_sleep) { + setup_pin1_for_lightsleep(); + } + else { + // we don't setup gpio HW here but do them in + // alarm_pin_pinalarm_prepare_for_deep_sleep() below + } } else { - //dbg_printf("alarm_pin_pinalarm_set_alarms() no valid pins\r\n"); + //dbg_printf("alarm_pin_pinalarm_set_alarms() no valid pins\r\n"); } } void alarm_pin_pinalarm_prepare_for_deep_sleep(void) { - _setup_pin1_for_deepsleep(); + setup_pin1_for_deepsleep(); } From 62b38e273b2aff3c250d3fb87986fba8a199c16d Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 21 Feb 2021 15:37:51 +0900 Subject: [PATCH 009/103] update translation file. --- locale/circuitpython.pot | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 0a79520b88..e90883582c 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -307,6 +307,10 @@ msgstr "" msgid "Address type out of range" msgstr "" +#: ports/nrf/common-hal/alarm/time/TimeAlarm.c +msgid "Alarm time is too far." +msgstr "" + #: ports/esp32s2/common-hal/canio/CAN.c msgid "All CAN peripherals are in use" msgstr "" @@ -609,6 +613,7 @@ msgid "Cannot output both channels on the same pin" msgstr "" #: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c msgid "Cannot pull on input-only pin." msgstr "" @@ -660,6 +665,7 @@ msgid "Cannot vary frequency on a timer that is already in use" msgstr "" #: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge. Only level." msgstr "" @@ -1066,6 +1072,7 @@ msgid "I2SOut not available" msgstr "" #: ports/esp32s2/common-hal/alarm/pin/__init__.c +#: ports/nrf/common-hal/alarm/pin/__init__.c msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" msgstr "" @@ -1251,7 +1258,8 @@ msgstr "" #: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c #: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c -#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c +#: ports/esp32s2/common-hal/touchio/TouchIn.c +#: ports/nrf/common-hal/alarm/touch/TouchAlarm.c shared-bindings/pwmio/PWMOut.c #: shared-module/rgbmatrix/RGBMatrix.c msgid "Invalid pin" msgstr "" @@ -1633,10 +1641,12 @@ msgid "" msgstr "" #: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c +#: ports/nrf/common-hal/alarm/touch/TouchAlarm.c msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" #: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c +#: ports/nrf/common-hal/alarm/time/TimeAlarm.c msgid "Only one alarm.time alarm can be set." msgstr "" @@ -3207,6 +3217,7 @@ msgid "invalid syntax for number" msgstr "" #: ports/esp32s2/common-hal/alarm/pin/__init__.c +#: ports/nrf/common-hal/alarm/pin/__init__.c msgid "io must be rtc io" msgstr "" @@ -3958,6 +3969,7 @@ msgid "trapz is defined for 1D arrays of equal length" msgstr "" #: ports/esp32s2/common-hal/alarm/pin/__init__.c +#: ports/nrf/common-hal/alarm/pin/__init__.c msgid "trigger level must be 0 or 1" msgstr "" @@ -4100,6 +4112,7 @@ msgid "vectors must have same lengths" msgstr "" #: ports/esp32s2/common-hal/alarm/pin/__init__.c +#: ports/nrf/common-hal/alarm/pin/__init__.c msgid "wakeup conflict" msgstr "" From 5c858a192562bf854beb2cd9c3c59ce5d8f9da54 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 21 Feb 2021 16:27:21 +0900 Subject: [PATCH 010/103] add weak board_deinit(). --- ports/nrf/supervisor/port.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c index d3c31b51a6..264fb81982 100644 --- a/ports/nrf/supervisor/port.c +++ b/ports/nrf/supervisor/port.c @@ -472,3 +472,9 @@ void HardFault_Handler(void) { asm("nop;"); } } + +#if CIRCUITPY_ALARM +// in case boards/xxx/board.c does not provide board_deinit() +MP_WEAK void board_deinit(void) { +} +#endif From 9df0f439f300f81c28d28473097cb9b897513b2b Mon Sep 17 00:00:00 2001 From: jun2sak Date: Tue, 23 Feb 2021 10:31:49 +0900 Subject: [PATCH 011/103] alarm/pin/__init__.c is no longer used. --- ports/nrf/common-hal/alarm/pin/__init__.c | 34 +++-------------------- 1 file changed, 4 insertions(+), 30 deletions(-) diff --git a/ports/nrf/common-hal/alarm/pin/__init__.c b/ports/nrf/common-hal/alarm/pin/__init__.c index d2ce00a3e3..94778f5eb1 100644 --- a/ports/nrf/common-hal/alarm/pin/__init__.c +++ b/ports/nrf/common-hal/alarm/pin/__init__.c @@ -1,38 +1,12 @@ //#include "shared-bindings/alarm_io/__init__.h" -//#include "esp_sleep.h" -//#include "driver/rtc_io.h" +// these are in esp32s2 implementation, +// but not used in nrf -mp_obj_t common_hal_alarm_io_pin_state (alarm_io_obj_t *self_in) { #if 0 - if (!rtc_gpio_is_valid_gpio(self_in->gpio)) { - mp_raise_ValueError(translate("io must be rtc io")); - } - - if (self_in->pull && !self_in->level) { - for (uint8_t i = 0; i<=4; i+=2) { - if (self_in->gpio == i) { - mp_raise_ValueError(translate("IOs 0, 2 & 4 do not support internal pullup in sleep")); - } - } - } - - switch(esp_sleep_enable_ext0_wakeup(self_in->gpio, self_in->level)) { - case ESP_ERR_INVALID_ARG: - mp_raise_ValueError(translate("trigger level must be 0 or 1")); - case ESP_ERR_INVALID_STATE: - mp_raise_RuntimeError(translate("wakeup conflict")); - default: - break; - } - - if (self_in->pull) { (self_in->level) ? rtc_gpio_pulldown_en(self_in->gpio) : rtc_gpio_pullup_en(self_in->gpio); } -#endif - return self_in; +mp_obj_t common_hal_alarm_io_pin_state (alarm_io_obj_t *self_in) { } void common_hal_alarm_io_disable (void) { -#if 0 - esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_EXT0 | ESP_SLEEP_WAKEUP_EXT1); -#endif } +#endif From 372c98626a8e0cc7031d89e803a40ecb4746f7da Mon Sep 17 00:00:00 2001 From: jun2sak Date: Tue, 23 Feb 2021 11:56:40 +0900 Subject: [PATCH 012/103] move all the debug codes from port.c to debug_uart.c. --- ports/nrf/Makefile | 4 +- ports/nrf/supervisor/debug_uart.c | 106 ++++++++++++++++++++++++++++++ ports/nrf/supervisor/port.c | 97 +-------------------------- 3 files changed, 110 insertions(+), 97 deletions(-) create mode 100644 ports/nrf/supervisor/debug_uart.c diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index c78a5dc503..6a22e62195 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -95,11 +95,9 @@ else CFLAGS += -flto -flto-partition=none endif -ifeq ($(MY_DBG), 1) - CFLAGS += -DMY_DBG -endif ifeq ($(MY_DEBUGUART), 1) CFLAGS += -DMY_DEBUGUART=1 + SRC_SUPERVISOR += supervisor/debug_uart.c endif # option to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk diff --git a/ports/nrf/supervisor/debug_uart.c b/ports/nrf/supervisor/debug_uart.c new file mode 100644 index 0000000000..2bd6be39c6 --- /dev/null +++ b/ports/nrf/supervisor/debug_uart.c @@ -0,0 +1,106 @@ +/* + * debug functions + * (will be removed) + */ + +#include +#include +#include +#include + +#ifdef MY_DEBUGUART + +#define DEBUG_UART_TXPIN 26 +#define DEBUG_UART_RXPIN 15 + +#include "nrfx.h" +#include "nrf_uart.h" +#include "nrf_gpio.h" +#include "nrf_rtc.h" +#include "nrfx_uarte.h" +#include "nrfx_rtc.h" +#include "supervisor/serial.h" // dbg_printf() + +extern const nrfx_rtc_t rtc_instance; // port.c +extern volatile int rtc_woke_up_counter; // port.c + +const nrfx_uarte_t _dbg_uart_inst = NRFX_UARTE_INSTANCE(1); +static int _dbg_uart_initialized = 0; +#define DBG_PBUF_LEN 80 +static char _dbg_pbuf[DBG_PBUF_LEN+1]; + +void _debug_uart_init(void) { + //if (_dbg_uart_initialized) return; + nrfx_uarte_config_t config = { + .pseltxd = DEBUG_UART_TXPIN, + .pselrxd = DEBUG_UART_RXPIN, + .pselcts = NRF_UARTE_PSEL_DISCONNECTED, + .pselrts = NRF_UARTE_PSEL_DISCONNECTED, + .p_context = NULL, + .baudrate = NRF_UART_BAUDRATE_115200, + .interrupt_priority = 7, + .hal_cfg = { + .hwfc = NRF_UARTE_HWFC_DISABLED, + .parity = NRF_UARTE_PARITY_EXCLUDED + } + }; + nrfx_uarte_init(&_dbg_uart_inst, &config, NULL); + // drive config + nrf_gpio_cfg(config.pseltxd, + NRF_GPIO_PIN_DIR_OUTPUT, + NRF_GPIO_PIN_INPUT_DISCONNECT, + NRF_GPIO_PIN_PULLUP, // orig=NOPULL + NRF_GPIO_PIN_H0H1, // orig=S0S1 + NRF_GPIO_PIN_NOSENSE); + _dbg_uart_initialized = 1; + return; +} + +void _debug_print_substr(const char* text, uint32_t length) { + char* data = (char*)text; + int siz; + while(length != 0) { + if (length <= DBG_PBUF_LEN) { + siz = length; + } + else { + siz = DBG_PBUF_LEN; + } + memcpy(_dbg_pbuf, data, siz); + _dbg_pbuf[siz] = 0; + nrfx_uarte_tx(&_dbg_uart_inst, (uint8_t const*)_dbg_pbuf, siz); + data += siz; + length -= siz; + } +} + +void _debug_uart_deinit(void) { + nrfx_uarte_uninit(&_dbg_uart_inst); +} + +int dbg_printf(const char *fmt, ...) { + va_list ap; + va_start(ap, fmt); + int ret = vprintf(fmt, ap); + va_end(ap); + return ret; +} + + +void dbg_dumpRTC(void) { + dbg_printf("\r\nRTC2\r\n"); + NRF_RTC_Type *r = rtc_instance.p_reg; + dbg_printf("PRESCALER=%08X, ", (int)r->PRESCALER); + dbg_printf("COUNTER=%08X ", (int)r->COUNTER); + dbg_printf("INTENSET=%08X ", (int)r->INTENSET); + dbg_printf("EVTENSET=%08X\r\n", (int)r->EVTENSET); + dbg_printf("EVENTS_COMPARE[0..3]=%X,%X,%X,%X ", (int)r->EVENTS_COMPARE[0], (int)r->EVENTS_COMPARE[1], (int)r->EVENTS_COMPARE[2], (int)r->EVENTS_COMPARE[3]); + dbg_printf("CC[0..3]=%08X,%08X,%08X,%08X\r\n", (int)r->CC[0], (int)r->CC[1], (int)r->CC[2], (int)r->CC[3]); + dbg_printf("woke_up=%d\r\n", rtc_woke_up_counter); +} + +#else /*!MY_DEBUGUART*/ +int dbg_printf(const char *fmt, ...) { + return 0; +} +#endif /*!MY_DEBUGUART*/ diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c index 264fb81982..d29659bf8d 100644 --- a/ports/nrf/supervisor/port.c +++ b/ports/nrf/supervisor/port.c @@ -27,10 +27,6 @@ #include #include "supervisor/port.h" #include "supervisor/board.h" -#ifdef MY_DEBUGUART -#include "supervisor/serial.h" // dbg_printf() -extern void _debug_uart_init(void); -#endif #include "nrfx/hal/nrf_clock.h" #include "nrfx/hal/nrf_power.h" @@ -78,82 +74,12 @@ static void power_warning_handler(void) { } #ifdef MY_DEBUGUART -#include -#include -#include "nrfx.h" -#include "nrf_uart.h" -#include "nrfx_uart.h" -const nrfx_uarte_t _dbg_uart_inst = NRFX_UARTE_INSTANCE(1); -static int _dbg_uart_initialized = 0; -#define DBG_PBUF_LEN 80 -static char _dbg_pbuf[DBG_PBUF_LEN+1]; - -void _debug_uart_init(void) { - //if (_dbg_uart_initialized) return; - nrfx_uarte_config_t config = { - .pseltxd = 26, - .pselrxd = 15, - .pselcts = NRF_UARTE_PSEL_DISCONNECTED, - .pselrts = NRF_UARTE_PSEL_DISCONNECTED, - .p_context = NULL, - .baudrate = NRF_UART_BAUDRATE_115200, - .interrupt_priority = 7, - .hal_cfg = { - .hwfc = NRF_UARTE_HWFC_DISABLED, - .parity = NRF_UARTE_PARITY_EXCLUDED - } - }; - nrfx_uarte_init(&_dbg_uart_inst, &config, NULL); - // drive config - nrf_gpio_cfg(config.pseltxd, - NRF_GPIO_PIN_DIR_OUTPUT, - NRF_GPIO_PIN_INPUT_DISCONNECT, - NRF_GPIO_PIN_PULLUP, // orig=NOPULL - NRF_GPIO_PIN_H0H1, // orig=S0S1 - NRF_GPIO_PIN_NOSENSE); - _dbg_uart_initialized = 1; - return; -} - -void _debug_print_substr(const char* text, uint32_t length) { - char* data = (char*)text; - int siz; - while(length != 0) { - if (length <= DBG_PBUF_LEN) { - siz = length; - } - else { - siz = DBG_PBUF_LEN; - } - memcpy(_dbg_pbuf, data, siz); - _dbg_pbuf[siz] = 0; - nrfx_uarte_tx(&_dbg_uart_inst, (uint8_t const*)_dbg_pbuf, siz); - data += siz; - length -= siz; - } -} - -void _debug_uart_deinit(void) { - nrfx_uarte_uninit(&_dbg_uart_inst); -} - -int dbg_printf(const char *fmt, ...) { - va_list ap; - va_start(ap, fmt); - int ret = vprintf(fmt, ap); - va_end(ap); - return ret; -} - -extern void _debug_led_init(void); -extern void _debug_led_set(int v); -#else /*!MY_DEBUGUART*/ -int dbg_printf(const char *fmt, ...) { - return 0; -} +extern void _debug_uart_init(void); #endif +uint32_t reset_reason_saved = 0; const nrfx_rtc_t rtc_instance = NRFX_RTC_INSTANCE(2); +volatile int rtc_woke_up_counter = 0; const nrfx_rtc_config_t rtc_config = { .prescaler = RTC_FREQ_TO_PRESCALER(0x8000), @@ -170,9 +96,6 @@ static volatile struct { uint32_t suffix; } overflow_tracker __attribute__((section(".uninitialized"))); -uint32_t reset_reason_saved = 0; -volatile int rtc_woke_up_counter = 0; - void rtc_handler(nrfx_rtc_int_type_t int_type) { if (int_type == NRFX_RTC_INT_OVERFLOW) { // Our RTC is 24 bits and we're clocking it at 32.768khz which is 32 (2 ** 5) subticks per @@ -190,20 +113,6 @@ void rtc_handler(nrfx_rtc_int_type_t int_type) { } } -#ifdef MY_DEBUGUART -void dbg_dumpRTC(void) { - dbg_printf("\r\nRTC2\r\n"); - NRF_RTC_Type *r = rtc_instance.p_reg; - dbg_printf("PRESCALER=%08X, ", (int)r->PRESCALER); - dbg_printf("COUNTER=%08X ", (int)r->COUNTER); - dbg_printf("INTENSET=%08X ", (int)r->INTENSET); - dbg_printf("EVTENSET=%08X\r\n", (int)r->EVTENSET); - dbg_printf("EVENTS_COMPARE[0..3]=%X,%X,%X,%X ", (int)r->EVENTS_COMPARE[0], (int)r->EVENTS_COMPARE[1], (int)r->EVENTS_COMPARE[2], (int)r->EVENTS_COMPARE[3]); - dbg_printf("CC[0..3]=%08X,%08X,%08X,%08X\r\n", (int)r->CC[0], (int)r->CC[1], (int)r->CC[2], (int)r->CC[3]); - dbg_printf("woke_up=%d\r\n", rtc_woke_up_counter); -} -#endif - void tick_init(void) { if (!nrf_clock_lf_is_running(NRF_CLOCK)) { nrf_clock_task_trigger(NRF_CLOCK, NRF_CLOCK_TASK_LFCLKSTART); From ec64fa6a291d2f7449f6ef1fc0313b53a889a6aa Mon Sep 17 00:00:00 2001 From: jun2sak Date: Tue, 23 Feb 2021 12:16:37 +0900 Subject: [PATCH 013/103] move dump_xxx functions to debug_uart.c. --- main.c | 10 ++++------ ports/nrf/common-hal/alarm/SleepMemory.c | 22 +++++----------------- ports/nrf/common-hal/alarm/__init__.c | 11 ----------- ports/nrf/supervisor/debug_uart.c | 22 +++++++++++++++++++++- 4 files changed, 30 insertions(+), 35 deletions(-) diff --git a/main.c b/main.c index 2a256f5b5d..0ca6684356 100755 --- a/main.c +++ b/main.c @@ -588,12 +588,10 @@ int __attribute__((used)) main(void) { serial_init(); #if 0 //XXX - int rr = (int)common_hal_mcu_processor_get_reset_reason(); - const char* rrstr[] = { - "POWER_ON", "BROWNOUT", "SOFTWARE", "DEEPSLEEPALARM", - "RESET_PIN", "WATCHDOG", "UNKNOWN" - }; - dbg_printf("reset_reason=%s\r\n", rrstr[rr]); + { + extern void dbg_dump_reset_reason(void); + dbg_dump_reset_reason(); + } #endif #if CIRCUITPY_BLEIO diff --git a/ports/nrf/common-hal/alarm/SleepMemory.c b/ports/nrf/common-hal/alarm/SleepMemory.c index a867b17b13..62afd37379 100644 --- a/ports/nrf/common-hal/alarm/SleepMemory.c +++ b/ports/nrf/common-hal/alarm/SleepMemory.c @@ -47,26 +47,15 @@ static int is_sleep_memory_valid(void) { return 0; } -static void dumpRAMreg(void) { -#ifdef MY_DEBUGUART - int i; - for(i = 0; i <= 8; ++i) { - dbg_printf(" RAM%d:%08X", i, (int)(NRF_POWER->RAM[i].POWER)); - if (i==4) dbg_printf("\r\n"); - } - dbg_printf("\r\n"); -#endif -} - +extern void dbg_dump_RAMreg(void); static void initialize_sleep_memory(void) { memset((uint8_t *)_sleep_mem, 0, SLEEP_MEMORY_LENGTH); // also, set RAM[n].POWER register for RAM retention // nRF52840 has RAM[0..7].Section[0..1] and RAM[8].Section[0..5] // nRF52833 has RAM[0..7].Section[0..1] and RAM[8].Section[0,1] - dumpRAMreg(); for(int ram = 0; ram <= 7; ++ram) { - NRF_POWER->RAM[ram].POWERSET = 0x00030000; // RETENTION for section 0,1 + NRF_POWER->RAM[ram].POWERSET = 0x00030000; // RETENTION for section 0,1 }; #ifdef NRF52840 NRF_POWER->RAM[8].POWERSET = 0x001F0000; // RETENTION for section 0..5 @@ -74,7 +63,9 @@ static void initialize_sleep_memory(void) { #ifdef NRF52833 NRF_POWER->RAM[8].POWERSET = 0x00030000; // RETENTION for section 0,1 #endif - dumpRAMreg(); +#ifdef MY_DEBUGUART + dbg_dump_RAMreg(); +#endif _sleep_mem_magicnum = SLEEP_MEMORY_DATA_GUARD; } @@ -82,9 +73,6 @@ static void initialize_sleep_memory(void) { void alarm_sleep_memory_reset(void) { if (!is_sleep_memory_valid()) { initialize_sleep_memory(); -#ifdef MY_DEBUGUART - dbg_printf("_sleep_mem[] initialized\r\n"); -#endif } } diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index d39c38fe44..dfdcb76889 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -51,17 +51,6 @@ #include "nrfx.h" #include "nrfx_gpiote.h" -#if 0 -// XXX -#define DEBUG_LED_PIN (NRF_GPIO_PIN_MAP(1, 11)) // P1_11 = LED -void _debug_led_init(void) { - nrf_gpio_cfg_output(DEBUG_LED_PIN); -} -void _debug_led_set(int v) { - nrf_gpio_pin_write(DEBUG_LED_PIN, v); -} -#endif - // Singleton instance of SleepMemory. const alarm_sleep_memory_obj_t alarm_sleep_memory_obj = { .base = { diff --git a/ports/nrf/supervisor/debug_uart.c b/ports/nrf/supervisor/debug_uart.c index 2bd6be39c6..53a3baebf9 100644 --- a/ports/nrf/supervisor/debug_uart.c +++ b/ports/nrf/supervisor/debug_uart.c @@ -20,9 +20,11 @@ #include "nrfx_uarte.h" #include "nrfx_rtc.h" #include "supervisor/serial.h" // dbg_printf() +#include "shared-bindings/microcontroller/Processor.h" extern const nrfx_rtc_t rtc_instance; // port.c extern volatile int rtc_woke_up_counter; // port.c +extern uint32_t reset_reason_saved; const nrfx_uarte_t _dbg_uart_inst = NRFX_UARTE_INSTANCE(1); static int _dbg_uart_initialized = 0; @@ -87,7 +89,7 @@ int dbg_printf(const char *fmt, ...) { } -void dbg_dumpRTC(void) { +void dbg_dump_RTCreg(void) { dbg_printf("\r\nRTC2\r\n"); NRF_RTC_Type *r = rtc_instance.p_reg; dbg_printf("PRESCALER=%08X, ", (int)r->PRESCALER); @@ -99,6 +101,24 @@ void dbg_dumpRTC(void) { dbg_printf("woke_up=%d\r\n", rtc_woke_up_counter); } +void dbg_dump_RAMreg(void) { + int i; + for(i = 0; i <= 8; ++i) { + dbg_printf(" RAM%d:%08X", i, (int)(NRF_POWER->RAM[i].POWER)); + if (i==4) dbg_printf("\r\n"); + } + dbg_printf("\r\n"); +} + +void dbg_dump_reset_reason(void) { + int reset_reason = (int)common_hal_mcu_processor_get_reset_reason(); + const char* rr_str[] = { + "POWER_ON", "BROWNOUT", "SOFTWARE", "DEEPSLEEPALARM", + "RESET_PIN", "WATCHDOG", "UNKNOWN" + }; + dbg_printf("reset_reason=%s\r\n", rr_str[reset_reason]); +} + #else /*!MY_DEBUGUART*/ int dbg_printf(const char *fmt, ...) { return 0; From 105042e870529092113ecfee24d8790a21f45f7b Mon Sep 17 00:00:00 2001 From: jun2sak Date: Tue, 23 Feb 2021 12:22:33 +0900 Subject: [PATCH 014/103] move dump_xxx functions to debug_uart.c. --- supervisor/shared/serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supervisor/shared/serial.c b/supervisor/shared/serial.c index 832242214a..262fe706bd 100644 --- a/supervisor/shared/serial.c +++ b/supervisor/shared/serial.c @@ -37,7 +37,7 @@ #include "tusb.h" #ifdef MY_DEBUGUART -// XXX these functions are in nrf/supervisor/port.c +// XXX these functions are in nrf/supervisor/debug_uart.c extern void _debug_uart_init(void); extern void _debug_print_substr(const char* text, uint32_t length); #endif From 0f188befb6c115ad9bee9dee80ae47840cb560ab Mon Sep 17 00:00:00 2001 From: jun2sak Date: Wed, 24 Feb 2021 00:12:25 +0900 Subject: [PATCH 015/103] set RAM retention just before deep sleep --- ports/nrf/common-hal/alarm/SleepMemory.c | 21 ++++++++++++--------- ports/nrf/common-hal/alarm/__init__.c | 5 +++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/ports/nrf/common-hal/alarm/SleepMemory.c b/ports/nrf/common-hal/alarm/SleepMemory.c index 62afd37379..89430f2937 100644 --- a/ports/nrf/common-hal/alarm/SleepMemory.c +++ b/ports/nrf/common-hal/alarm/SleepMemory.c @@ -26,13 +26,13 @@ */ #include -#ifdef MY_DEBUGUART -#include "supervisor/serial.h" // dbg_printf() -#endif - #include "py/runtime.h" #include "common-hal/alarm/SleepMemory.h" +#ifdef MY_DEBUGUART +extern void dbg_dump_RAMreg(void); +#endif + #define RTC_DATA_ATTR __attribute__((section(".uninitialized"))) static RTC_DATA_ATTR uint8_t _sleep_mem[SLEEP_MEMORY_LENGTH]; static RTC_DATA_ATTR uint32_t _sleep_mem_magicnum; @@ -47,11 +47,8 @@ static int is_sleep_memory_valid(void) { return 0; } -extern void dbg_dump_RAMreg(void); -static void initialize_sleep_memory(void) { - memset((uint8_t *)_sleep_mem, 0, SLEEP_MEMORY_LENGTH); - - // also, set RAM[n].POWER register for RAM retention +void set_memory_retention(void) { + // set RAM[n].POWER register for RAM retention // nRF52840 has RAM[0..7].Section[0..1] and RAM[8].Section[0..5] // nRF52833 has RAM[0..7].Section[0..1] and RAM[8].Section[0,1] for(int ram = 0; ram <= 7; ++ram) { @@ -63,6 +60,12 @@ static void initialize_sleep_memory(void) { #ifdef NRF52833 NRF_POWER->RAM[8].POWERSET = 0x00030000; // RETENTION for section 0,1 #endif +} + +static void initialize_sleep_memory(void) { + memset((uint8_t *)_sleep_mem, 0, SLEEP_MEMORY_LENGTH); + + set_memory_retention(); #ifdef MY_DEBUGUART dbg_dump_RAMreg(); #endif diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index dfdcb76889..14f6e041f9 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -202,12 +202,17 @@ void common_hal_alarm_set_deep_sleep_alarms(size_t n_alarms, const mp_obj_t *ala _setup_sleep_alarms(true, n_alarms, alarms); } +extern void set_memory_retention(void); + void NORETURN alarm_enter_deep_sleep(void) { alarm_pin_pinalarm_prepare_for_deep_sleep(); //alarm_touch_touchalarm_prepare_for_deep_sleep(); // XXX uint8_t sd_enabled; sd_softdevice_is_enabled(&sd_enabled); + + set_memory_retention(); + #ifdef MY_DEBUGUART dbg_printf("go system off.. %d\r\n", sd_enabled); #endif From 057682f776c52500cfbbdd5f7fbe70d4010d1ad1 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Wed, 24 Feb 2021 00:13:11 +0900 Subject: [PATCH 016/103] cleanup. --- main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index 0ca6684356..d6ad3ac2c1 100755 --- a/main.c +++ b/main.c @@ -537,6 +537,10 @@ STATIC int run_repl(void) { return exit_code; } +#ifdef MY_DEBUGUART +extern void dbg_dump_reset_reason(void); +#endif + int __attribute__((used)) main(void) { // initialise the cpu and peripherals safe_mode_t safe_mode = port_init(); @@ -589,7 +593,6 @@ int __attribute__((used)) main(void) { #if 0 //XXX { - extern void dbg_dump_reset_reason(void); dbg_dump_reset_reason(); } #endif From 72b5f1a9a62d05330571f0e8e4bf0c5f1ffe0d7a Mon Sep 17 00:00:00 2001 From: jun2sak Date: Thu, 25 Feb 2021 01:38:23 +0900 Subject: [PATCH 017/103] clean up my personal settings. --- .gitignore | 6 ------ ports/nrf/Makefile | 1 - 2 files changed, 7 deletions(-) diff --git a/.gitignore b/.gitignore index 6f27970f89..a8814be45e 100644 --- a/.gitignore +++ b/.gitignore @@ -86,9 +86,3 @@ TAGS #################### .venv .env - -1FILES -2FILES -TAG -ports/nrf/LOG*.txt -ports/nrf/boards/pg8c diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 6a22e62195..d48b788cba 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -87,7 +87,6 @@ INC += -I../../supervisor/shared/usb #Debugging/Optimization ifeq ($(DEBUG), 1) CFLAGS += -ggdb3 - CFLAGS += -DNDEBUG OPTIMIZATION_FLAGS = -Og else OPTIMIZATION_FLAGS ?= -O2 -fno-inline-functions From 9661d67cd37964afe66fdfced5620ac8c0c195bc Mon Sep 17 00:00:00 2001 From: jun2sak Date: Thu, 25 Feb 2021 01:49:57 +0900 Subject: [PATCH 018/103] replace MY_DEBUG_UART -> NRF_DEBUG_PRINT. --- main.c | 2 +- ports/nrf/Makefile | 4 ++-- ports/nrf/common-hal/alarm/SleepMemory.c | 4 ++-- ports/nrf/common-hal/alarm/__init__.c | 16 ++++++++-------- ports/nrf/common-hal/alarm/pin/PinAlarm.c | 18 +++++++++--------- ports/nrf/supervisor/debug_uart.c | 6 +++--- ports/nrf/supervisor/port.c | 4 ++-- supervisor/shared/serial.c | 8 ++++---- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/main.c b/main.c index d6ad3ac2c1..c15d5810b0 100755 --- a/main.c +++ b/main.c @@ -537,7 +537,7 @@ STATIC int run_repl(void) { return exit_code; } -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT extern void dbg_dump_reset_reason(void); #endif diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index d48b788cba..8925189f56 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -94,8 +94,8 @@ else CFLAGS += -flto -flto-partition=none endif -ifeq ($(MY_DEBUGUART), 1) - CFLAGS += -DMY_DEBUGUART=1 +ifeq ($(NRF_DEBUG_PRINT), 1) + CFLAGS += -DNRF_DEBUG_PRINT=1 SRC_SUPERVISOR += supervisor/debug_uart.c endif diff --git a/ports/nrf/common-hal/alarm/SleepMemory.c b/ports/nrf/common-hal/alarm/SleepMemory.c index 89430f2937..fc7453beb4 100644 --- a/ports/nrf/common-hal/alarm/SleepMemory.c +++ b/ports/nrf/common-hal/alarm/SleepMemory.c @@ -29,7 +29,7 @@ #include "py/runtime.h" #include "common-hal/alarm/SleepMemory.h" -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT extern void dbg_dump_RAMreg(void); #endif @@ -66,7 +66,7 @@ static void initialize_sleep_memory(void) { memset((uint8_t *)_sleep_mem, 0, SLEEP_MEMORY_LENGTH); set_memory_retention(); -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT dbg_dump_RAMreg(); #endif diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index 14f6e041f9..9c64e8e119 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -42,7 +42,7 @@ //#include "shared-bindings/microcontroller/__init__.h" #include "supervisor/port.h" -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT #include "supervisor/serial.h" // dbg_printf() #endif @@ -98,7 +98,7 @@ bool alarm_woken_from_sleep(void) { || cause == NRF_SLEEP_WAKEUP_RESETPIN); } -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT #if 0 static const char* cause_str[] = { "UNDEFINED", @@ -150,7 +150,7 @@ STATIC void _setup_sleep_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t } STATIC void _idle_until_alarm(void) { -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT int ct = 40; #endif reset_reason_saved = 0; @@ -160,14 +160,14 @@ STATIC void _idle_until_alarm(void) { // Allow ctrl-C interrupt. if (alarm_woken_from_sleep()) { alarm_save_wake_alarm(); -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT int cause = _get_wakeup_cause(); printf("wakeup(%d)\r\n", cause); #endif return; } port_idle_until_interrupt(); -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT if (ct > 0) { printf("_"); --ct; @@ -179,14 +179,14 @@ STATIC void _idle_until_alarm(void) { mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj_t *alarms) { mp_obj_t r_obj = mp_const_none; _setup_sleep_alarms(false, n_alarms, alarms); -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT dbg_printf("\r\nsleep..."); #endif _idle_until_alarm(); if (mp_hal_is_interrupted()) { -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT dbg_printf("mp_hal_is_interrupted\r\n"); #endif r_obj = mp_const_none; @@ -213,7 +213,7 @@ void NORETURN alarm_enter_deep_sleep(void) { set_memory_retention(); -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT dbg_printf("go system off.. %d\r\n", sd_enabled); #endif if (sd_enabled) { diff --git a/ports/nrf/common-hal/alarm/pin/PinAlarm.c b/ports/nrf/common-hal/alarm/pin/PinAlarm.c index 9ccc79db92..bdc268d512 100644 --- a/ports/nrf/common-hal/alarm/pin/PinAlarm.c +++ b/ports/nrf/common-hal/alarm/pin/PinAlarm.c @@ -154,7 +154,7 @@ static void setup_pin1_for_lightsleep(void) { }; for(size_t i = 0; i < 64; ++i) { uint64_t mask = 1ull << i; -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT int pull = 0; int sense = 0; #endif @@ -165,7 +165,7 @@ static void setup_pin1_for_lightsleep(void) { cfg.sense = NRF_GPIOTE_POLARITY_LOTOHI; cfg.pull = ((pull_pins & mask) != 0) ? NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_NOPULL; -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT pull = -1; sense = 1; #endif } @@ -174,21 +174,21 @@ static void setup_pin1_for_lightsleep(void) { cfg.sense = NRF_GPIOTE_POLARITY_HITOLO; cfg.pull = ((pull_pins & mask) != 0) ? NRF_GPIO_PIN_PULLUP : NRF_GPIO_PIN_NOPULL; -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT pull = 1; sense = -1; #endif } else { cfg.sense = NRF_GPIOTE_POLARITY_TOGGLE; cfg.pull = NRF_GPIO_PIN_NOPULL; -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT sense = 9; #endif } nrfx_gpiote_in_init((nrfx_gpiote_pin_t)i, &cfg, pinalarm_gpiote_handler); nrfx_gpiote_in_event_enable((nrfx_gpiote_pin_t)i, true); -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT dbg_printf("pin=%d, sense=%d, pull=%d\r\n", i, sense, pull); #endif } @@ -198,7 +198,7 @@ static void setup_pin1_for_deepsleep(void) { for(size_t i = 0; i < 64; ++i) { uint64_t mask = 1ull << i; int pull = 0; -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT int sense = 0; #endif if (((high_alarms & mask) == 0) && ((low_alarms & mask) == 0)) { @@ -209,7 +209,7 @@ static void setup_pin1_for_deepsleep(void) { NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_NOPULL; nrf_gpio_cfg_input((uint32_t)i, (nrf_gpio_pin_pull_t)pull); nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_HIGH); -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT sense = NRF_GPIO_PIN_SENSE_HIGH; #endif } @@ -219,11 +219,11 @@ static void setup_pin1_for_deepsleep(void) { NRF_GPIO_PIN_PULLUP : NRF_GPIO_PIN_NOPULL; nrf_gpio_cfg_input((uint32_t)i, (nrf_gpio_pin_pull_t)pull); nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_LOW); -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT sense = NRF_GPIO_PIN_SENSE_LOW; #endif } -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT dbg_printf("pin=%d, sense=%d, pull=%d\r\n", i, sense, pull); #endif } diff --git a/ports/nrf/supervisor/debug_uart.c b/ports/nrf/supervisor/debug_uart.c index 53a3baebf9..79cc33b198 100644 --- a/ports/nrf/supervisor/debug_uart.c +++ b/ports/nrf/supervisor/debug_uart.c @@ -8,7 +8,7 @@ #include #include -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT #define DEBUG_UART_TXPIN 26 #define DEBUG_UART_RXPIN 15 @@ -119,8 +119,8 @@ void dbg_dump_reset_reason(void) { dbg_printf("reset_reason=%s\r\n", rr_str[reset_reason]); } -#else /*!MY_DEBUGUART*/ +#else /*!NRF_DEBUG_PRINT*/ int dbg_printf(const char *fmt, ...) { return 0; } -#endif /*!MY_DEBUGUART*/ +#endif /*!NRF_DEBUG_PRINT*/ diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c index d29659bf8d..5908683008 100644 --- a/ports/nrf/supervisor/port.c +++ b/ports/nrf/supervisor/port.c @@ -73,7 +73,7 @@ static void power_warning_handler(void) { reset_into_safe_mode(BROWNOUT); } -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT extern void _debug_uart_init(void); #endif @@ -234,7 +234,7 @@ void reset_port(void) { reset_all_pins(); -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT _debug_uart_init(); #endif } diff --git a/supervisor/shared/serial.c b/supervisor/shared/serial.c index 262fe706bd..479a996553 100644 --- a/supervisor/shared/serial.c +++ b/supervisor/shared/serial.c @@ -36,7 +36,7 @@ #include "tusb.h" -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT // XXX these functions are in nrf/supervisor/debug_uart.c extern void _debug_uart_init(void); extern void _debug_print_substr(const char* text, uint32_t length); @@ -70,14 +70,14 @@ void serial_early_init(void) { common_hal_busio_uart_never_reset(&debug_uart); #endif -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT _debug_uart_init(); #endif } void serial_init(void) { usb_init(); -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT _debug_uart_init(); #endif } @@ -157,7 +157,7 @@ void serial_write_substring(const char* text, uint32_t length) { common_hal_busio_uart_write(&debug_uart, (const uint8_t*) text, length, &uart_errcode); #endif -#ifdef MY_DEBUGUART +#ifdef NRF_DEBUG_PRINT _debug_print_substr(text, length); #endif } From f66896ce32351e0992d6d3417d1a8af1038c5d4b Mon Sep 17 00:00:00 2001 From: jun2sak Date: Thu, 25 Feb 2021 02:34:43 +0900 Subject: [PATCH 019/103] use nRF SDK function to set up memory retention. --- ports/nrf/common-hal/alarm/SleepMemory.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ports/nrf/common-hal/alarm/SleepMemory.c b/ports/nrf/common-hal/alarm/SleepMemory.c index fc7453beb4..e78e9fdd76 100644 --- a/ports/nrf/common-hal/alarm/SleepMemory.c +++ b/ports/nrf/common-hal/alarm/SleepMemory.c @@ -28,6 +28,7 @@ #include #include "py/runtime.h" #include "common-hal/alarm/SleepMemory.h" +#include "nrf_power.h" #ifdef NRF_DEBUG_PRINT extern void dbg_dump_RAMreg(void); @@ -51,14 +52,24 @@ void set_memory_retention(void) { // set RAM[n].POWER register for RAM retention // nRF52840 has RAM[0..7].Section[0..1] and RAM[8].Section[0..5] // nRF52833 has RAM[0..7].Section[0..1] and RAM[8].Section[0,1] - for(int ram = 0; ram <= 7; ++ram) { - NRF_POWER->RAM[ram].POWERSET = 0x00030000; // RETENTION for section 0,1 + for(int block = 0; block <= 7; ++block) { + nrf_power_rampower_mask_on(NRF_POWER, block, + NRF_POWER_RAMPOWER_S0RETENTION_MASK | + NRF_POWER_RAMPOWER_S1RETENTION_MASK); }; #ifdef NRF52840 - NRF_POWER->RAM[8].POWERSET = 0x001F0000; // RETENTION for section 0..5 + nrf_power_rampower_mask_on(NRF_POWER, 8, + NRF_POWER_RAMPOWER_S0RETENTION_MASK | + NRF_POWER_RAMPOWER_S1RETENTION_MASK | + NRF_POWER_RAMPOWER_S2RETENTION_MASK | + NRF_POWER_RAMPOWER_S3RETENTION_MASK | + NRF_POWER_RAMPOWER_S4RETENTION_MASK | + NRF_POWER_RAMPOWER_S5RETENTION_MASK); #endif #ifdef NRF52833 - NRF_POWER->RAM[8].POWERSET = 0x00030000; // RETENTION for section 0,1 + nrf_power_rampower_mask_on(NRF_POWER, 8, + NRF_POWER_RAMPOWER_S0RETENTION_MASK | + NRF_POWER_RAMPOWER_S1RETENTION_MASK); #endif } From 61a69daae1fd6460b830b7fd6707c74adbcd3f23 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Thu, 25 Feb 2021 08:19:03 +0900 Subject: [PATCH 020/103] raise NotImplementedError when construct TouchAlarm. --- ports/nrf/common-hal/alarm/touch/TouchAlarm.c | 142 +----------------- 1 file changed, 5 insertions(+), 137 deletions(-) diff --git a/ports/nrf/common-hal/alarm/touch/TouchAlarm.c b/ports/nrf/common-hal/alarm/touch/TouchAlarm.c index 4db178c56e..1878b78b33 100644 --- a/ports/nrf/common-hal/alarm/touch/TouchAlarm.c +++ b/ports/nrf/common-hal/alarm/touch/TouchAlarm.c @@ -24,162 +24,30 @@ * THE SOFTWARE. */ +#include "py/runtime.h" #include "shared-bindings/alarm/touch/TouchAlarm.h" #include "shared-bindings/microcontroller/__init__.h" -//#include "esp_sleep.h" -//#include "peripherals/touch.h" -//#include "supervisor/esp_port.h" - -static uint16_t touch_channel_mask; static volatile bool woke_up = false; void common_hal_alarm_touch_touchalarm_construct(alarm_touch_touchalarm_obj_t *self, const mcu_pin_obj_t *pin) { -#if 0 - if (pin->touch_channel == TOUCH_PAD_MAX) { - mp_raise_ValueError(translate("Invalid pin")); - } - claim_pin(pin); -#endif - self->pin = pin; + mp_raise_NotImplementedError(NULL); + (void)pin; } mp_obj_t alarm_touch_touchalarm_get_wakeup_alarm(const size_t n_alarms, const mp_obj_t *alarms) { - // First, check to see if we match any given alarms. - for (size_t i = 0; i < n_alarms; i++) { - if (MP_OBJ_IS_TYPE(alarms[i], &alarm_touch_touchalarm_type)) { - return alarms[i]; - } - } - - // Create TouchAlarm object. - alarm_touch_touchalarm_obj_t *alarm = m_new_obj(alarm_touch_touchalarm_obj_t); - alarm->base.type = &alarm_touch_touchalarm_type; - alarm->pin = NULL; -#if 0 - touch_pad_t wake_channel = touch_pad_get_current_meas_channel(); - if (wake_channel == TOUCH_PAD_MAX) { - return alarm; - } - - // Map the pin number back to a pin object. - for (size_t i = 0; i < mcu_pin_globals.map.used; i++) { - const mcu_pin_obj_t* pin_obj = MP_OBJ_TO_PTR(mcu_pin_globals.map.table[i].value); - if (pin_obj->touch_channel == wake_channel) { - alarm->pin = mcu_pin_globals.map.table[i].value; - break; - } - } -#endif - return alarm; -} - -// This is used to wake the main CircuitPython task. -void touch_interrupt(void *arg) { - (void) arg; -#if 0 - woke_up = true; - BaseType_t task_wakeup; - vTaskNotifyGiveFromISR(circuitpython_task, &task_wakeup); - if (task_wakeup) { - portYIELD_FROM_ISR(); - } -#endif + return mp_const_none; } void alarm_touch_touchalarm_set_alarm(const bool deep_sleep, const size_t n_alarms, const mp_obj_t *alarms) { -#if 0 - bool touch_alarm_set = false; - alarm_touch_touchalarm_obj_t *touch_alarm = MP_OBJ_NULL; - - for (size_t i = 0; i < n_alarms; i++) { - if (MP_OBJ_IS_TYPE(alarms[i], &alarm_touch_touchalarm_type)) { - if (deep_sleep && touch_alarm_set) { - mp_raise_ValueError(translate("Only one TouchAlarm can be set in deep sleep.")); - } - touch_alarm = MP_OBJ_TO_PTR(alarms[i]); - touch_channel_mask |= 1 << touch_alarm->pin->number; - touch_alarm_set = true; - } - } - - if (!touch_alarm_set) { - return; - } - - // configure interrupt for pretend to deep sleep - // this will be disabled if we actually deep sleep - - // reset touch peripheral - peripherals_touch_reset(); - peripherals_touch_never_reset(true); - - for (uint8_t i = 1; i <= 14; i++) { - if ((touch_channel_mask & 1 << i) != 0) { - touch_pad_t touch_channel = (touch_pad_t)i; - // intialize touchpad - peripherals_touch_init(touch_channel); - - // wait for touch data to reset - mp_hal_delay_ms(10); - - // configure trigger threshold - uint32_t touch_value; - touch_pad_read_benchmark(touch_channel, &touch_value); - touch_pad_set_thresh(touch_channel, touch_value * 0.1); //10% - } - } - - // configure touch interrupt - touch_pad_timeout_set(true, SOC_TOUCH_PAD_THRESHOLD_MAX); - touch_pad_isr_register(touch_interrupt, NULL, TOUCH_PAD_INTR_MASK_ALL); - touch_pad_intr_enable(TOUCH_PAD_INTR_MASK_ACTIVE | TOUCH_PAD_INTR_MASK_INACTIVE); } void alarm_touch_touchalarm_prepare_for_deep_sleep(void) { - if (!touch_channel_mask) { - return; - } - - touch_pad_t touch_channel = TOUCH_PAD_MAX; - for (uint8_t i = 1; i <= 14; i++) { - if ((touch_channel_mask & 1 << i) != 0) { - touch_channel = (touch_pad_t)i; - break; - } - } - - // reset touch peripheral - peripherals_touch_never_reset(false); - peripherals_touch_reset(); - - // intialize touchpad - peripherals_touch_init(touch_channel); - - // configure touchpad for sleep - touch_pad_sleep_channel_enable(touch_channel, true); - touch_pad_sleep_channel_enable_proximity(touch_channel, false); - - // wait for touch data to reset - mp_hal_delay_ms(10); - - // configure trigger threshold - uint32_t touch_value; - touch_pad_sleep_channel_read_smooth(touch_channel, &touch_value); - touch_pad_sleep_set_threshold(touch_channel, touch_value * 0.1); //10% - - // enable touchpad wakeup - esp_sleep_enable_touchpad_wakeup(); - esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON); -#endif } bool alarm_touch_touchalarm_woke_us_up(void) { - return woke_up; + return false; } void alarm_touch_touchalarm_reset(void) { - woke_up = false; - touch_channel_mask = 0; -// peripherals_touch_never_reset(false); } From 9328d09a7a7a3cddc1ca0c346c781f3cb55203ee Mon Sep 17 00:00:00 2001 From: jun2sak Date: Fri, 26 Feb 2021 00:50:44 +0900 Subject: [PATCH 021/103] re-enable parameters check. --- ports/nrf/common-hal/alarm/pin/PinAlarm.c | 7 ++----- ports/nrf/common-hal/alarm/pin/__init__.c | 12 ------------ 2 files changed, 2 insertions(+), 17 deletions(-) delete mode 100644 ports/nrf/common-hal/alarm/pin/__init__.c diff --git a/ports/nrf/common-hal/alarm/pin/PinAlarm.c b/ports/nrf/common-hal/alarm/pin/PinAlarm.c index bdc268d512..606a7125fa 100644 --- a/ports/nrf/common-hal/alarm/pin/PinAlarm.c +++ b/ports/nrf/common-hal/alarm/pin/PinAlarm.c @@ -46,15 +46,12 @@ volatile nrfx_gpiote_pin_t _pinhandler_ev_pin; #define MYGPIOTE_EV_PIN_UNDEF 0xFF void common_hal_alarm_pin_pinalarm_construct(alarm_pin_pinalarm_obj_t *self, mcu_pin_obj_t *pin, bool value, bool edge, bool pull) { -#if 0 if (edge) { mp_raise_ValueError(translate("Cannot wake on pin edge. Only level.")); } - - if (pull && !GPIO_IS_VALID_OUTPUT_GPIO(pin->number)) { - mp_raise_ValueError(translate("Cannot pull on input-only pin.")); + if (pin->number >= NUMBER_OF_PINS) { + mp_raise_ValueError(translate("Invalid pin")); } -#endif self->pin = pin; self->value = value; self->pull = pull; diff --git a/ports/nrf/common-hal/alarm/pin/__init__.c b/ports/nrf/common-hal/alarm/pin/__init__.c deleted file mode 100644 index 94778f5eb1..0000000000 --- a/ports/nrf/common-hal/alarm/pin/__init__.c +++ /dev/null @@ -1,12 +0,0 @@ -//#include "shared-bindings/alarm_io/__init__.h" - -// these are in esp32s2 implementation, -// but not used in nrf - -#if 0 -mp_obj_t common_hal_alarm_io_pin_state (alarm_io_obj_t *self_in) { -} - -void common_hal_alarm_io_disable (void) { -} -#endif From c86ca2a4ff7e23feeb77fbbfcee1a9ea61178851 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Fri, 26 Feb 2021 00:51:52 +0900 Subject: [PATCH 022/103] move externs to .h --- ports/nrf/common-hal/alarm/time/TimeAlarm.c | 4 ---- ports/nrf/common-hal/alarm/time/TimeAlarm.h | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ports/nrf/common-hal/alarm/time/TimeAlarm.c b/ports/nrf/common-hal/alarm/time/TimeAlarm.c index 220ed2f4df..2a9a0fcd33 100644 --- a/ports/nrf/common-hal/alarm/time/TimeAlarm.c +++ b/ports/nrf/common-hal/alarm/time/TimeAlarm.c @@ -55,19 +55,15 @@ mp_obj_t alarm_time_timealarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t * return timer; } -extern volatile int rtc_woke_up_counter; bool alarm_time_timealarm_woke_us_up(void) { return rtc_woke_up_counter; } -extern void port_disable_interrupt_after_ticks_ch(uint32_t channel); void alarm_time_timealarm_reset(void) { port_disable_interrupt_after_ticks_ch(1); rtc_woke_up_counter = 0; } -extern void port_interrupt_after_ticks_ch(uint32_t channel, uint32_t ticks);//XXX in port.c - void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms) { bool timealarm_set = false; alarm_time_timealarm_obj_t *timealarm = MP_OBJ_NULL; diff --git a/ports/nrf/common-hal/alarm/time/TimeAlarm.h b/ports/nrf/common-hal/alarm/time/TimeAlarm.h index dfd75524fd..14a2ff80cf 100644 --- a/ports/nrf/common-hal/alarm/time/TimeAlarm.h +++ b/ports/nrf/common-hal/alarm/time/TimeAlarm.h @@ -32,6 +32,10 @@ typedef struct { mp_float_t monotonic_time; // values compatible with time.monotonic_time() } alarm_time_timealarm_obj_t; +extern volatile int rtc_woke_up_counter; +extern void port_disable_interrupt_after_ticks_ch(uint32_t channel); +extern void port_interrupt_after_ticks_ch(uint32_t channel, uint32_t ticks); + // Find the alarm object that caused us to wake up or create an equivalent one. mp_obj_t alarm_time_timealarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *alarms); // Check for the wake up alarm from pretend deep sleep. From c713d31d0d77e461c97efa95229467e311b7e35b Mon Sep 17 00:00:00 2001 From: jun2sak Date: Fri, 26 Feb 2021 01:20:55 +0900 Subject: [PATCH 023/103] move externs to .h --- ports/nrf/common-hal/microcontroller/Processor.c | 1 - ports/nrf/common-hal/microcontroller/Processor.h | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ports/nrf/common-hal/microcontroller/Processor.c b/ports/nrf/common-hal/microcontroller/Processor.c index 5564c86c54..edff0fa076 100644 --- a/ports/nrf/common-hal/microcontroller/Processor.c +++ b/ports/nrf/common-hal/microcontroller/Processor.c @@ -122,7 +122,6 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { } } -extern uint32_t reset_reason_saved; mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { mcu_reset_reason_t r = RESET_REASON_UNKNOWN; if (reset_reason_saved == 0) { diff --git a/ports/nrf/common-hal/microcontroller/Processor.h b/ports/nrf/common-hal/microcontroller/Processor.h index 4049c165fb..1abbe1e4eb 100644 --- a/ports/nrf/common-hal/microcontroller/Processor.h +++ b/ports/nrf/common-hal/microcontroller/Processor.h @@ -36,4 +36,6 @@ typedef struct { // Stores no state currently. } mcu_processor_obj_t; +extern uint32_t reset_reason_saved; + #endif // MICROPY_INCLUDED_NRF_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H From 5b3c6ed0c3cb923a597da1221cb4386f033bb741 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Fri, 26 Feb 2021 01:28:13 +0900 Subject: [PATCH 024/103] update translation file. --- locale/circuitpython.pot | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index e90883582c..dc0ec9fb7e 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -613,7 +613,6 @@ msgid "Cannot output both channels on the same pin" msgstr "" #: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c -#: ports/nrf/common-hal/alarm/pin/PinAlarm.c msgid "Cannot pull on input-only pin." msgstr "" @@ -1072,7 +1071,6 @@ msgid "I2SOut not available" msgstr "" #: ports/esp32s2/common-hal/alarm/pin/__init__.c -#: ports/nrf/common-hal/alarm/pin/__init__.c msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" msgstr "" @@ -1259,7 +1257,7 @@ msgstr "" #: ports/atmel-samd/common-hal/touchio/TouchIn.c #: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c #: ports/esp32s2/common-hal/touchio/TouchIn.c -#: ports/nrf/common-hal/alarm/touch/TouchAlarm.c shared-bindings/pwmio/PWMOut.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c #: shared-module/rgbmatrix/RGBMatrix.c msgid "Invalid pin" msgstr "" @@ -1641,7 +1639,6 @@ msgid "" msgstr "" #: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c -#: ports/nrf/common-hal/alarm/touch/TouchAlarm.c msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" @@ -3217,7 +3214,6 @@ msgid "invalid syntax for number" msgstr "" #: ports/esp32s2/common-hal/alarm/pin/__init__.c -#: ports/nrf/common-hal/alarm/pin/__init__.c msgid "io must be rtc io" msgstr "" @@ -3969,7 +3965,6 @@ msgid "trapz is defined for 1D arrays of equal length" msgstr "" #: ports/esp32s2/common-hal/alarm/pin/__init__.c -#: ports/nrf/common-hal/alarm/pin/__init__.c msgid "trigger level must be 0 or 1" msgstr "" @@ -4112,7 +4107,6 @@ msgid "vectors must have same lengths" msgstr "" #: ports/esp32s2/common-hal/alarm/pin/__init__.c -#: ports/nrf/common-hal/alarm/pin/__init__.c msgid "wakeup conflict" msgstr "" From 2aa5aec0d5b9c3b9c11ecf0f1d728cc7891f0ca6 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Fri, 26 Feb 2021 01:45:12 +0900 Subject: [PATCH 025/103] cleanup. --- ports/nrf/common-hal/alarm/__init__.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index 9c64e8e119..c719deb876 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -38,9 +38,6 @@ #include "shared-bindings/alarm/time/TimeAlarm.h" #include "shared-bindings/alarm/touch/TouchAlarm.h" -//#include "shared-bindings/wifi/__init__.h" -//#include "shared-bindings/microcontroller/__init__.h" - #include "supervisor/port.h" #ifdef NRF_DEBUG_PRINT #include "supervisor/serial.h" // dbg_printf() @@ -73,12 +70,9 @@ STATIC nrf_sleep_source_t _get_wakeup_cause(void) { if (alarm_time_timealarm_woke_us_up()) { return NRF_SLEEP_WAKEUP_TIMER; } -#if 0 - // XXX not implemented yet if (alarm_touch_touchalarm_woke_us_up()) { - return ESP_SLEEP_WAKEUP_TOUCHPAD; + return NRF_SLEEP_WAKEUP_TOUCHPAD; } -#endif if (reset_reason_saved & NRF_POWER_RESETREAS_RESETPIN_MASK) { return NRF_SLEEP_WAKEUP_RESETPIN; } @@ -99,7 +93,6 @@ bool alarm_woken_from_sleep(void) { } #ifdef NRF_DEBUG_PRINT -#if 0 static const char* cause_str[] = { "UNDEFINED", "GPIO", @@ -108,15 +101,18 @@ static const char* cause_str[] = { "VBUS", "RESETPIN", }; -#endif +void print_wakeup_cause(nrf_sleep_source_t cause) { + if (cause >= 0 && cause < NRF_SLEEP_WAKEUP_ZZZ) { + dbg_printf("wakeup cause = NRF_SLEEP_WAKEUP_%s\r\n", + cause_str[(int)cause]); + } +} #endif STATIC mp_obj_t _get_wake_alarm(size_t n_alarms, const mp_obj_t *alarms) { nrf_sleep_source_t cause = _get_wakeup_cause(); -#if 0 - if (cause >= 0 && cause < NRF_SLEEP_WAKEUP_ZZZ) { - printf("wakeup cause = NRF_SLEEP_WAKEUP_%s\r\n", cause_str[(int)cause]); - } +#ifdef NRF_DEBUG_PRINT + //print_wakeup_cause(cause); #endif switch (cause) { case NRF_SLEEP_WAKEUP_TIMER: { @@ -143,10 +139,7 @@ mp_obj_t common_hal_alarm_get_wake_alarm(void) { STATIC void _setup_sleep_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms) { alarm_pin_pinalarm_set_alarms(deep_sleep, n_alarms, alarms); alarm_time_timealarm_set_alarms(deep_sleep, n_alarms, alarms); -#if 0 - // XXX not implemented yet alarm_touch_touchalarm_set_alarm(deep_sleep, n_alarms, alarms); -#endif } STATIC void _idle_until_alarm(void) { @@ -206,7 +199,7 @@ extern void set_memory_retention(void); void NORETURN alarm_enter_deep_sleep(void) { alarm_pin_pinalarm_prepare_for_deep_sleep(); - //alarm_touch_touchalarm_prepare_for_deep_sleep(); // XXX + //alarm_touch_touchalarm_prepare_for_deep_sleep(); uint8_t sd_enabled; sd_softdevice_is_enabled(&sd_enabled); From 277a67d8767b6b297bc0ce375c44bf3fdd38c617 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Fri, 26 Feb 2021 08:11:50 +0900 Subject: [PATCH 026/103] call touchalarm funcs as well as pin/timealarm. --- ports/nrf/common-hal/alarm/__init__.c | 6 +++--- ports/nrf/common-hal/alarm/touch/TouchAlarm.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index c719deb876..8042855a61 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -59,7 +59,7 @@ void alarm_reset(void) { alarm_sleep_memory_reset(); alarm_pin_pinalarm_reset(); alarm_time_timealarm_reset(); - //alarm_touch_touchalarm_reset(); + alarm_touch_touchalarm_reset(); } extern uint32_t reset_reason_saved; @@ -119,7 +119,7 @@ STATIC mp_obj_t _get_wake_alarm(size_t n_alarms, const mp_obj_t *alarms) { return alarm_time_timealarm_get_wakeup_alarm(n_alarms, alarms); } case NRF_SLEEP_WAKEUP_TOUCHPAD: { - return mp_const_none; + return alarm_touch_touchalarm_get_wakeup_alarm(n_alarms, alarms); } case NRF_SLEEP_WAKEUP_GPIO: { return alarm_pin_pinalarm_get_wakeup_alarm(n_alarms, alarms); @@ -199,7 +199,7 @@ extern void set_memory_retention(void); void NORETURN alarm_enter_deep_sleep(void) { alarm_pin_pinalarm_prepare_for_deep_sleep(); - //alarm_touch_touchalarm_prepare_for_deep_sleep(); + alarm_touch_touchalarm_prepare_for_deep_sleep(); uint8_t sd_enabled; sd_softdevice_is_enabled(&sd_enabled); diff --git a/ports/nrf/common-hal/alarm/touch/TouchAlarm.c b/ports/nrf/common-hal/alarm/touch/TouchAlarm.c index 1878b78b33..e85797e692 100644 --- a/ports/nrf/common-hal/alarm/touch/TouchAlarm.c +++ b/ports/nrf/common-hal/alarm/touch/TouchAlarm.c @@ -28,7 +28,7 @@ #include "shared-bindings/alarm/touch/TouchAlarm.h" #include "shared-bindings/microcontroller/__init__.h" -static volatile bool woke_up = false; +//static volatile bool woke_up = false; void common_hal_alarm_touch_touchalarm_construct(alarm_touch_touchalarm_obj_t *self, const mcu_pin_obj_t *pin) { mp_raise_NotImplementedError(NULL); From 7fd4648cd5ce467520920d58dd7518e7beace08d Mon Sep 17 00:00:00 2001 From: jun2sak Date: Fri, 26 Feb 2021 09:06:11 +0900 Subject: [PATCH 027/103] rase error if Alarm time >= 512 sec. --- locale/circuitpython.pot | 2 +- ports/nrf/common-hal/alarm/time/TimeAlarm.c | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index dc0ec9fb7e..39bc4d74e1 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -308,7 +308,7 @@ msgid "Address type out of range" msgstr "" #: ports/nrf/common-hal/alarm/time/TimeAlarm.c -msgid "Alarm time is too far." +msgid "Alarm time must be < 512 seconds." msgstr "" #: ports/esp32s2/common-hal/canio/CAN.c diff --git a/ports/nrf/common-hal/alarm/time/TimeAlarm.c b/ports/nrf/common-hal/alarm/time/TimeAlarm.c index 2a9a0fcd33..e9c536414b 100644 --- a/ports/nrf/common-hal/alarm/time/TimeAlarm.c +++ b/ports/nrf/common-hal/alarm/time/TimeAlarm.c @@ -86,12 +86,13 @@ void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ mp_float_t now_secs = uint64_to_float(common_hal_time_monotonic_ms()) / 1000.0f; mp_float_t wakeup_in_secs = MAX(0.0f, timealarm->monotonic_time - now_secs); int wsecs = (int)(wakeup_in_secs); - if (wsecs > 510) { //XXX - mp_raise_ValueError(translate("Alarm time is too far.")); + // timealarm is implemented by RTC, which is a 24bit counter + // running at 32768Hz. So, 2^24 / 32768 = 512sec is an upper limit. + if (wsecs >= 512) { + mp_raise_ValueError(translate("Alarm time must be < 512 seconds.")); } uint32_t wakeup_in_ticks = (uint32_t)(wakeup_in_secs * 1024.0f); - //printf("alarm_time_timealarm_set_alarms() %d secs 0x%08X ticks\r\n", wsecs, (int)wakeup_in_ticks); port_interrupt_after_ticks_ch(1, wakeup_in_ticks); rtc_woke_up_counter = 0; } From 0f8c96f424c08d5bdfcec565d5718c5151955ab6 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Fri, 26 Feb 2021 09:11:35 +0900 Subject: [PATCH 028/103] remove trailing whitespaces. --- ports/nrf/common-hal/alarm/SleepMemory.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/nrf/common-hal/alarm/SleepMemory.c b/ports/nrf/common-hal/alarm/SleepMemory.c index e78e9fdd76..f29ac07f67 100644 --- a/ports/nrf/common-hal/alarm/SleepMemory.c +++ b/ports/nrf/common-hal/alarm/SleepMemory.c @@ -53,12 +53,12 @@ void set_memory_retention(void) { // nRF52840 has RAM[0..7].Section[0..1] and RAM[8].Section[0..5] // nRF52833 has RAM[0..7].Section[0..1] and RAM[8].Section[0,1] for(int block = 0; block <= 7; ++block) { - nrf_power_rampower_mask_on(NRF_POWER, block, + nrf_power_rampower_mask_on(NRF_POWER, block, NRF_POWER_RAMPOWER_S0RETENTION_MASK | NRF_POWER_RAMPOWER_S1RETENTION_MASK); }; #ifdef NRF52840 - nrf_power_rampower_mask_on(NRF_POWER, 8, + nrf_power_rampower_mask_on(NRF_POWER, 8, NRF_POWER_RAMPOWER_S0RETENTION_MASK | NRF_POWER_RAMPOWER_S1RETENTION_MASK | NRF_POWER_RAMPOWER_S2RETENTION_MASK | @@ -67,7 +67,7 @@ void set_memory_retention(void) { NRF_POWER_RAMPOWER_S5RETENTION_MASK); #endif #ifdef NRF52833 - nrf_power_rampower_mask_on(NRF_POWER, 8, + nrf_power_rampower_mask_on(NRF_POWER, 8, NRF_POWER_RAMPOWER_S0RETENTION_MASK | NRF_POWER_RAMPOWER_S1RETENTION_MASK); #endif From fac86c8277bca2002c8ed8983c8a8e4055c1c31a Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 28 Feb 2021 15:34:55 +0900 Subject: [PATCH 029/103] remove unused debug printf's. --- main.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/main.c b/main.c index c15d5810b0..7df6e293aa 100755 --- a/main.c +++ b/main.c @@ -218,7 +218,6 @@ STATIC bool maybe_run_list(const char * const * filenames, pyexec_result_t* exec decompress(compressed, decompressed); mp_hal_stdout_tx_str(decompressed); pyexec_file(filename, exec_result); - //dbg_printf("pyexec_file end result=(code=%d, line=%d)\r\n", exec_result->return_code, exec_result->exception_line); return true; } @@ -264,7 +263,6 @@ STATIC void print_code_py_status_message(safe_mode_t safe_mode) { } STATIC bool run_code_py(safe_mode_t safe_mode) { - //dbg_printf("run_code_py (%d)\r\n", (int)safe_mode); bool serial_connected_at_start = serial_connected(); #if CIRCUITPY_AUTORELOAD_DELAY_MS > 0 serial_write("\n"); @@ -440,7 +438,6 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { FIL* boot_output_file; STATIC void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) { - //dbg_printf("run_boot_py (%d)\r\n", (int)safe_mode); // If not in safe mode, run boot before initing USB and capture output in a // file. if (filesystem_present() && safe_mode == NO_SAFE_MODE && MP_STATE_VM(vfs_mount_table) != NULL) { @@ -537,10 +534,6 @@ STATIC int run_repl(void) { return exit_code; } -#ifdef NRF_DEBUG_PRINT -extern void dbg_dump_reset_reason(void); -#endif - int __attribute__((used)) main(void) { // initialise the cpu and peripherals safe_mode_t safe_mode = port_init(); @@ -591,12 +584,6 @@ int __attribute__((used)) main(void) { // Start serial and HID after giving boot.py a chance to tweak behavior. serial_init(); -#if 0 //XXX - { - dbg_dump_reset_reason(); - } -#endif - #if CIRCUITPY_BLEIO supervisor_start_bluetooth(); #endif From 9b34726c0d5b2a5a79deec8132828199ba5ff25a Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 28 Feb 2021 15:36:14 +0900 Subject: [PATCH 030/103] GPIO and GPIOTE reg dump for debug. --- ports/nrf/supervisor/debug_uart.c | 55 ++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/ports/nrf/supervisor/debug_uart.c b/ports/nrf/supervisor/debug_uart.c index 79cc33b198..dda03a00af 100644 --- a/ports/nrf/supervisor/debug_uart.c +++ b/ports/nrf/supervisor/debug_uart.c @@ -88,7 +88,6 @@ int dbg_printf(const char *fmt, ...) { return ret; } - void dbg_dump_RTCreg(void) { dbg_printf("\r\nRTC2\r\n"); NRF_RTC_Type *r = rtc_instance.p_reg; @@ -110,6 +109,60 @@ void dbg_dump_RAMreg(void) { dbg_printf("\r\n"); } +void dbg_dump_GPIOregs(void) { + int i, port, col; + + NRF_GPIO_Type *gpio[] = { NRF_P0, NRF_P1 }; + const char cnf_pull_chr[] = "-D*U"; // pull down, pull up + const char cnf_sense_chr[] = "-?HL"; // sense high, sense low + for(port=0, col=0; port<=1; ++port) { + for(i=0; i<32; ++i) { + uint32_t cnf = gpio[port]->PIN_CNF[i]; + if (cnf != 0x0002) { // changed from default value + dbg_printf("[%d_%02d]:%c%c%c%d%c ", port, i, + (cnf & 1) ? 'O' : 'I', // output, input + (cnf & 2) ? 'd' : 'c', // disconnected, connected + cnf_pull_chr[(cnf >> 2) & 3], + (int)((cnf >> 8) & 7), // drive config 0-7 + cnf_sense_chr[(cnf >> 16) & 3]); + if (++col >= 6) { + dbg_printf("\r\n"); + col = 0; + } + } + } + } + if (col > 0) dbg_printf("\r\n"); + + dbg_printf("GPIOTE\r\n"); + NRF_GPIOTE_Type const *reg = NRF_GPIOTE; + const char config_mode_chr[] = "-E-T"; // event, task + const char config_pol_chr[] = "-HLT"; // low-to-Hi, hi-to-Low, Toggle + const char config_outinit_chr[] = "01"; // initial value is 0 or 1 + for(i=0, col=0; i<8; ++i) { + uint32_t conf = reg->CONFIG[i]; + if (conf != 0) { // changed from default value + dbg_printf("CONFIG[%d]:%d_%02d,%c%c%c ", i, + (int)((conf >> 13) & 1), (int)((conf >> 8) & 0x1F), + config_mode_chr[conf & 3], + config_pol_chr[(conf >> 16) & 3], + (conf & 3) == 3 ? + config_outinit_chr[(conf >> 20) & 1] : '-'); + if (++col >= 4) { + dbg_printf("\r\n"); + col = 0; + } + } + } + if (col > 0) dbg_printf("\r\n"); + for(i=0; i<8; ++i) { + dbg_printf("EVENTS_IN[%d]:%X ", i, (int)(reg->EVENTS_IN[i])); + if ((i & 3) == 3) dbg_printf("\r\n"); + } + dbg_printf("EVENTS_PORT:%X INTENSET:%08X\r\n", + (int)(reg->EVENTS_PORT), (int)(reg->INTENSET)); +} + void dbg_dump_reset_reason(void) { int reset_reason = (int)common_hal_mcu_processor_get_reset_reason(); const char* rr_str[] = { From 498debc82621efb12f45f14a15b4282636f78299 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 28 Feb 2021 15:37:25 +0900 Subject: [PATCH 031/103] remove unused debug printf's. --- ports/nrf/common-hal/alarm/SleepMemory.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ports/nrf/common-hal/alarm/SleepMemory.c b/ports/nrf/common-hal/alarm/SleepMemory.c index f29ac07f67..49eb0b2594 100644 --- a/ports/nrf/common-hal/alarm/SleepMemory.c +++ b/ports/nrf/common-hal/alarm/SleepMemory.c @@ -32,6 +32,7 @@ #ifdef NRF_DEBUG_PRINT extern void dbg_dump_RAMreg(void); +#include "supervisor/serial.h" // dbg_printf() #endif #define RTC_DATA_ATTR __attribute__((section(".uninitialized"))) @@ -78,7 +79,7 @@ static void initialize_sleep_memory(void) { set_memory_retention(); #ifdef NRF_DEBUG_PRINT - dbg_dump_RAMreg(); + //dbg_dump_RAMreg(); #endif _sleep_mem_magicnum = SLEEP_MEMORY_DATA_GUARD; @@ -87,6 +88,9 @@ static void initialize_sleep_memory(void) { void alarm_sleep_memory_reset(void) { if (!is_sleep_memory_valid()) { initialize_sleep_memory(); +#ifdef NRF_DEBUG_PRINT + dbg_printf("sleep memory initialized\r\n"); +#endif } } From 3e47e00291909e13260482e18a0814da7dbf39ff Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 28 Feb 2021 15:57:37 +0900 Subject: [PATCH 032/103] address the pretending-to-deep-sleep issue. --- main.c | 2 +- ports/nrf/common-hal/alarm/__init__.c | 48 +++++++----- ports/nrf/common-hal/alarm/pin/PinAlarm.c | 89 +++++++---------------- shared-bindings/alarm/__init__.c | 5 ++ shared-bindings/alarm/__init__.h | 1 + 5 files changed, 62 insertions(+), 83 deletions(-) diff --git a/main.c b/main.c index 7df6e293aa..2aebfa062f 100755 --- a/main.c +++ b/main.c @@ -430,7 +430,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { // it may also return due to another interrupt, that's why we check // for deep sleep alarms above. If it wasn't a deep sleep alarm, // then we'll idle here again. - port_idle_until_interrupt(); + alarm_pretending_deep_sleep(); } } } diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index 8042855a61..f54b54a3f9 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -85,13 +85,6 @@ STATIC nrf_sleep_source_t _get_wakeup_cause(void) { return NRF_SLEEP_WAKEUP_UNDEFINED; } -bool alarm_woken_from_sleep(void) { - nrf_sleep_source_t cause = _get_wakeup_cause(); - return (cause == NRF_SLEEP_WAKEUP_GPIO || cause == NRF_SLEEP_WAKEUP_TIMER - || cause == NRF_SLEEP_WAKEUP_TOUCHPAD - || cause == NRF_SLEEP_WAKEUP_RESETPIN); -} - #ifdef NRF_DEBUG_PRINT static const char* cause_str[] = { "UNDEFINED", @@ -109,6 +102,17 @@ void print_wakeup_cause(nrf_sleep_source_t cause) { } #endif +bool alarm_woken_from_sleep(void) { + nrf_sleep_source_t cause = _get_wakeup_cause(); +#ifdef NRF_DEBUG_PRINT + if (cause != NRF_SLEEP_WAKEUP_UNDEFINED) { + //print_wakeup_cause(cause); + } +#endif + return (cause == NRF_SLEEP_WAKEUP_GPIO || cause == NRF_SLEEP_WAKEUP_TIMER + || cause == NRF_SLEEP_WAKEUP_TOUCHPAD); +} + STATIC mp_obj_t _get_wake_alarm(size_t n_alarms, const mp_obj_t *alarms) { nrf_sleep_source_t cause = _get_wakeup_cause(); #ifdef NRF_DEBUG_PRINT @@ -152,19 +156,15 @@ STATIC void _idle_until_alarm(void) { RUN_BACKGROUND_TASKS; // Allow ctrl-C interrupt. if (alarm_woken_from_sleep()) { - alarm_save_wake_alarm(); -#ifdef NRF_DEBUG_PRINT - int cause = _get_wakeup_cause(); - printf("wakeup(%d)\r\n", cause); -#endif - return; - } + alarm_save_wake_alarm(); + return; + } port_idle_until_interrupt(); #ifdef NRF_DEBUG_PRINT - if (ct > 0) { - printf("_"); - --ct; - } + if (ct > 0) { + dbg_printf("_"); + --ct; + } #endif } } @@ -186,8 +186,8 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj } else { r_obj = _get_wake_alarm(n_alarms, alarms); - alarm_reset(); } + alarm_reset(); return r_obj; } @@ -220,6 +220,16 @@ void NORETURN alarm_enter_deep_sleep(void) { while(1) ; } +void alarm_pretending_deep_sleep(void) { + alarm_pin_pinalarm_prepare_for_deep_sleep(); + alarm_touch_touchalarm_prepare_for_deep_sleep(); + + port_idle_until_interrupt(); + if (alarm_woken_from_sleep()) { + alarm_reset(); + } +} + void common_hal_alarm_gc_collect(void) { void* p = alarm_get_wake_alarm(); gc_collect_ptr(p); diff --git a/ports/nrf/common-hal/alarm/pin/PinAlarm.c b/ports/nrf/common-hal/alarm/pin/PinAlarm.c index 606a7125fa..5ed6fb725c 100644 --- a/ports/nrf/common-hal/alarm/pin/PinAlarm.c +++ b/ports/nrf/common-hal/alarm/pin/PinAlarm.c @@ -27,6 +27,7 @@ #include "py/runtime.h" #include +#include #include "shared-bindings/alarm/pin/PinAlarm.h" #include "shared-bindings/microcontroller/__init__.h" @@ -44,6 +45,10 @@ volatile char _pinhandler_gpiote_count; volatile nrfx_gpiote_pin_t _pinhandler_ev_pin; #define MYGPIOTE_EV_PIN_UNDEF 0xFF +static bool pins_configured = false; + +extern uint32_t reset_reason_saved; +extern void dbg_dump_GPIOregs(void); void common_hal_alarm_pin_pinalarm_construct(alarm_pin_pinalarm_obj_t *self, mcu_pin_obj_t *pin, bool value, bool edge, bool pull) { if (edge) { @@ -94,7 +99,6 @@ mp_obj_t alarm_pin_pinalarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *al return alarms[i]; } } - alarm_pin_pinalarm_obj_t *alarm = m_new_obj(alarm_pin_pinalarm_obj_t); alarm->base.type = &alarm_pin_pinalarm_type; alarm->pin = NULL; @@ -133,11 +137,14 @@ void alarm_pin_pinalarm_reset(void) { pull_pins = 0; } -static void setup_pin1_for_lightsleep(void) { +static void configure_pins_for_sleep(void) { + nrfx_err_t err; if ( nrfx_gpiote_is_init() ) { - nrfx_gpiote_uninit(); + nrfx_gpiote_uninit(); } - nrfx_gpiote_init(NRFX_GPIOTE_CONFIG_IRQ_PRIORITY); + err = nrfx_gpiote_init(NRFX_GPIOTE_CONFIG_IRQ_PRIORITY); + assert(err == NRFX_SUCCESS); + (void)err; // to suppress unused warning _pinhandler_gpiote_count = 0; _pinhandler_ev_pin = MYGPIOTE_EV_PIN_UNDEF; @@ -151,10 +158,6 @@ static void setup_pin1_for_lightsleep(void) { }; for(size_t i = 0; i < 64; ++i) { uint64_t mask = 1ull << i; -#ifdef NRF_DEBUG_PRINT - int pull = 0; - int sense = 0; -#endif if (((high_alarms & mask) == 0) && ((low_alarms & mask) == 0)) { continue; } @@ -162,76 +165,28 @@ static void setup_pin1_for_lightsleep(void) { cfg.sense = NRF_GPIOTE_POLARITY_LOTOHI; cfg.pull = ((pull_pins & mask) != 0) ? NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_NOPULL; -#ifdef NRF_DEBUG_PRINT - pull = -1; sense = 1; -#endif } else if (((high_alarms & mask) == 0) && ((low_alarms & mask) != 0)) { cfg.sense = NRF_GPIOTE_POLARITY_HITOLO; cfg.pull = ((pull_pins & mask) != 0) ? NRF_GPIO_PIN_PULLUP : NRF_GPIO_PIN_NOPULL; -#ifdef NRF_DEBUG_PRINT - pull = 1; sense = -1; -#endif } else { cfg.sense = NRF_GPIOTE_POLARITY_TOGGLE; cfg.pull = NRF_GPIO_PIN_NOPULL; -#ifdef NRF_DEBUG_PRINT - sense = 9; -#endif } - nrfx_gpiote_in_init((nrfx_gpiote_pin_t)i, &cfg, - pinalarm_gpiote_handler); + err = nrfx_gpiote_in_init((nrfx_gpiote_pin_t)i, &cfg, + pinalarm_gpiote_handler); + assert(err == NRFX_SUCCESS); nrfx_gpiote_in_event_enable((nrfx_gpiote_pin_t)i, true); -#ifdef NRF_DEBUG_PRINT - dbg_printf("pin=%d, sense=%d, pull=%d\r\n", i, sense, pull); -#endif - } -} - -static void setup_pin1_for_deepsleep(void) { - for(size_t i = 0; i < 64; ++i) { - uint64_t mask = 1ull << i; - int pull = 0; -#ifdef NRF_DEBUG_PRINT - int sense = 0; -#endif - if (((high_alarms & mask) == 0) && ((low_alarms & mask) == 0)) { - continue; - } if (((high_alarms & mask) != 0) && ((low_alarms & mask) == 0)) { - pull = ((pull_pins & mask) != 0) ? - NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_NOPULL; - nrf_gpio_cfg_input((uint32_t)i, (nrf_gpio_pin_pull_t)pull); nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_HIGH); -#ifdef NRF_DEBUG_PRINT - sense = NRF_GPIO_PIN_SENSE_HIGH; -#endif - } - else + } if (((high_alarms & mask) == 0) && ((low_alarms & mask) != 0)) { - pull = ((pull_pins & mask) != 0) ? - NRF_GPIO_PIN_PULLUP : NRF_GPIO_PIN_NOPULL; - nrf_gpio_cfg_input((uint32_t)i, (nrf_gpio_pin_pull_t)pull); nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_LOW); -#ifdef NRF_DEBUG_PRINT - sense = NRF_GPIO_PIN_SENSE_LOW; -#endif - } -#ifdef NRF_DEBUG_PRINT - dbg_printf("pin=%d, sense=%d, pull=%d\r\n", i, sense, pull); -#endif + } } -#if 0 - uint32_t pin_number = 2; - NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number); - dbg_printf(" 2 PIN_CNF=0x%08X\r\n", (unsigned int)(reg->PIN_CNF[pin_number])); - pin_number = 28; - reg = nrf_gpio_pin_port_decode(&pin_number); - dbg_printf("28 PIN_CNF=0x%08X\r\n", (unsigned int)(reg->PIN_CNF[pin_number])); -#endif } void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms) { @@ -261,11 +216,13 @@ void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ob } if (pin_number != -1) { if (!deep_sleep) { - setup_pin1_for_lightsleep(); + configure_pins_for_sleep(); } else { // we don't setup gpio HW here but do them in // alarm_pin_pinalarm_prepare_for_deep_sleep() below + reset_reason_saved = 0; + pins_configured = false; } } else { @@ -274,5 +231,11 @@ void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ob } void alarm_pin_pinalarm_prepare_for_deep_sleep(void) { - setup_pin1_for_deepsleep(); + if (!pins_configured) { + configure_pins_for_sleep(); + pins_configured = true; +#ifdef NRF_DEBUG_PRINT + dbg_dump_GPIOregs(); +#endif + } } diff --git a/shared-bindings/alarm/__init__.c b/shared-bindings/alarm/__init__.c index 7023c70e5d..509e0acebd 100644 --- a/shared-bindings/alarm/__init__.c +++ b/shared-bindings/alarm/__init__.c @@ -242,3 +242,8 @@ const mp_obj_module_t alarm_module = { .base = { &mp_type_module }, .globals = (mp_obj_dict_t*)&alarm_module_globals, }; + +extern void port_idle_until_interrupt(void); +MP_WEAK void alarm_pretending_deep_sleep(void) { + port_idle_until_interrupt(); +} diff --git a/shared-bindings/alarm/__init__.h b/shared-bindings/alarm/__init__.h index 154f91e265..37e8b98ecc 100644 --- a/shared-bindings/alarm/__init__.h +++ b/shared-bindings/alarm/__init__.h @@ -42,6 +42,7 @@ extern mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const extern void common_hal_alarm_set_deep_sleep_alarms(size_t n_alarms, const mp_obj_t *alarms); // Deep sleep is entered outside of the VM so we omit the `common_hal_` prefix. extern NORETURN void alarm_enter_deep_sleep(void); +extern void alarm_pretending_deep_sleep(void); // Fetches value from module dict. extern mp_obj_t alarm_get_wake_alarm(void); From 7cecd996584d819a99b3a09cc1dc1c86d6514041 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 28 Feb 2021 16:04:29 +0900 Subject: [PATCH 033/103] remove unused debug printf's. --- ports/nrf/common-hal/alarm/pin/PinAlarm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/nrf/common-hal/alarm/pin/PinAlarm.c b/ports/nrf/common-hal/alarm/pin/PinAlarm.c index 5ed6fb725c..47d7ce8360 100644 --- a/ports/nrf/common-hal/alarm/pin/PinAlarm.c +++ b/ports/nrf/common-hal/alarm/pin/PinAlarm.c @@ -235,7 +235,7 @@ void alarm_pin_pinalarm_prepare_for_deep_sleep(void) { configure_pins_for_sleep(); pins_configured = true; #ifdef NRF_DEBUG_PRINT - dbg_dump_GPIOregs(); + //dbg_dump_GPIOregs(); #endif } } From 7bb789625ed8713334c24c1d78460bf5c2f03492 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 28 Feb 2021 16:27:37 +0900 Subject: [PATCH 034/103] use the original port_idle_until_interrupt() if not CIRCUITPY_ALARM. --- main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/main.c b/main.c index 2aebfa062f..e6e5a6d2a8 100755 --- a/main.c +++ b/main.c @@ -430,7 +430,11 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { // it may also return due to another interrupt, that's why we check // for deep sleep alarms above. If it wasn't a deep sleep alarm, // then we'll idle here again. + #if CIRCUITPY_ALARM alarm_pretending_deep_sleep(); + #else + port_idle_until_interrupt(); + #endif } } } From 3fab9f8b1b8e86d0c9224ea4c79b4ba35da6ade1 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 7 Mar 2021 01:09:54 +0900 Subject: [PATCH 035/103] new wait-until-alarm design, don't use System OFF. --- main.c | 1 + ports/nrf/common-hal/alarm/SleepMemory.c | 26 +-- ports/nrf/common-hal/alarm/SleepMemory.h | 1 + ports/nrf/common-hal/alarm/__init__.c | 184 +++++++++++++++++--- ports/nrf/common-hal/alarm/__init__.h | 9 + ports/nrf/common-hal/alarm/pin/PinAlarm.c | 14 +- ports/nrf/common-hal/alarm/time/TimeAlarm.c | 36 ++-- ports/nrf/common-hal/alarm/time/TimeAlarm.h | 6 + ports/nrf/supervisor/debug_uart.c | 32 +++- ports/nrf/supervisor/port.c | 32 +++- 10 files changed, 274 insertions(+), 67 deletions(-) diff --git a/main.c b/main.c index e6e5a6d2a8..0f7ca8860e 100755 --- a/main.c +++ b/main.c @@ -435,6 +435,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { #else port_idle_until_interrupt(); #endif + return false; // to go REPL } } } diff --git a/ports/nrf/common-hal/alarm/SleepMemory.c b/ports/nrf/common-hal/alarm/SleepMemory.c index 49eb0b2594..367f305972 100644 --- a/ports/nrf/common-hal/alarm/SleepMemory.c +++ b/ports/nrf/common-hal/alarm/SleepMemory.c @@ -27,6 +27,7 @@ #include #include "py/runtime.h" +#include "common-hal/alarm/__init__.h" #include "common-hal/alarm/SleepMemory.h" #include "nrf_power.h" @@ -35,14 +36,15 @@ extern void dbg_dump_RAMreg(void); #include "supervisor/serial.h" // dbg_printf() #endif -#define RTC_DATA_ATTR __attribute__((section(".uninitialized"))) -static RTC_DATA_ATTR uint8_t _sleep_mem[SLEEP_MEMORY_LENGTH]; -static RTC_DATA_ATTR uint32_t _sleep_mem_magicnum; +__attribute__((section(".uninitialized"))) static uint8_t _sleepmem[SLEEP_MEMORY_LENGTH]; +__attribute__((section(".uninitialized"))) uint8_t sleepmem_wakeup_event; +__attribute__((section(".uninitialized"))) uint8_t sleepmem_wakeup_pin; +__attribute__((section(".uninitialized"))) static uint32_t _sleepmem_magicnum; #define SLEEP_MEMORY_DATA_GUARD 0xad0000af #define SLEEP_MEMORY_DATA_GUARD_MASK 0xff0000ff static int is_sleep_memory_valid(void) { - if ((_sleep_mem_magicnum & SLEEP_MEMORY_DATA_GUARD_MASK) + if ((_sleepmem_magicnum & SLEEP_MEMORY_DATA_GUARD_MASK) == SLEEP_MEMORY_DATA_GUARD) { return 1; } @@ -75,14 +77,16 @@ void set_memory_retention(void) { } static void initialize_sleep_memory(void) { - memset((uint8_t *)_sleep_mem, 0, SLEEP_MEMORY_LENGTH); + memset((uint8_t *)_sleepmem, 0, SLEEP_MEMORY_LENGTH); + sleepmem_wakeup_event = 0; + sleepmem_wakeup_pin = 0; set_memory_retention(); #ifdef NRF_DEBUG_PRINT //dbg_dump_RAMreg(); #endif - _sleep_mem_magicnum = SLEEP_MEMORY_DATA_GUARD; + _sleepmem_magicnum = SLEEP_MEMORY_DATA_GUARD; } void alarm_sleep_memory_reset(void) { @@ -95,21 +99,21 @@ void alarm_sleep_memory_reset(void) { } uint32_t common_hal_alarm_sleep_memory_get_length(alarm_sleep_memory_obj_t *self) { - return sizeof(_sleep_mem); + return sizeof(_sleepmem); } bool common_hal_alarm_sleep_memory_set_bytes(alarm_sleep_memory_obj_t *self, uint32_t start_index, const uint8_t* values, uint32_t len) { - if (start_index + len > sizeof(_sleep_mem)) { + if (start_index + len > sizeof(_sleepmem)) { return false; } - memcpy((uint8_t *) (_sleep_mem + start_index), values, len); + memcpy((uint8_t *) (_sleepmem + start_index), values, len); return true; } void common_hal_alarm_sleep_memory_get_bytes(alarm_sleep_memory_obj_t *self, uint32_t start_index, uint8_t* values, uint32_t len) { - if (start_index + len > sizeof(_sleep_mem)) { + if (start_index + len > sizeof(_sleepmem)) { return; } - memcpy(values, (uint8_t *) (_sleep_mem + start_index), len); + memcpy(values, (uint8_t *) (_sleepmem + start_index), len); } diff --git a/ports/nrf/common-hal/alarm/SleepMemory.h b/ports/nrf/common-hal/alarm/SleepMemory.h index 24fe0065d0..11cc4a8fb9 100644 --- a/ports/nrf/common-hal/alarm/SleepMemory.h +++ b/ports/nrf/common-hal/alarm/SleepMemory.h @@ -35,6 +35,7 @@ typedef struct { mp_obj_base_t base; } alarm_sleep_memory_obj_t; +extern void set_memory_retention(void); extern void alarm_sleep_memory_reset(void); #endif // MICROPY_INCLUDED_NRF_COMMON_HAL_ALARM_SLEEPMEMORY_H diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index f54b54a3f9..12bb2a40c4 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -37,10 +37,13 @@ #include "shared-bindings/alarm/pin/PinAlarm.h" #include "shared-bindings/alarm/time/TimeAlarm.h" #include "shared-bindings/alarm/touch/TouchAlarm.h" +#include "shared-bindings/time/__init__.h" #include "supervisor/port.h" +#include "supervisor/serial.h" // serial_connected() #ifdef NRF_DEBUG_PRINT #include "supervisor/serial.h" // dbg_printf() +extern int dbg_check_RTCprescaler(void); #endif #include "nrf.h" @@ -113,6 +116,23 @@ bool alarm_woken_from_sleep(void) { || cause == NRF_SLEEP_WAKEUP_TOUCHPAD); } +nrf_sleep_source_t alarm_woken_from_sleep_2(void) { + nrf_sleep_source_t cause = _get_wakeup_cause(); +#ifdef NRF_DEBUG_PRINT + if (cause != NRF_SLEEP_WAKEUP_UNDEFINED) { + //print_wakeup_cause(cause); + } +#endif + if (cause == NRF_SLEEP_WAKEUP_GPIO || + cause == NRF_SLEEP_WAKEUP_TIMER || + cause == NRF_SLEEP_WAKEUP_TOUCHPAD) { + return cause; + } + else { + return NRF_SLEEP_WAKEUP_UNDEFINED; + } +} + STATIC mp_obj_t _get_wake_alarm(size_t n_alarms, const mp_obj_t *alarms) { nrf_sleep_source_t cause = _get_wakeup_cause(); #ifdef NRF_DEBUG_PRINT @@ -146,19 +166,74 @@ STATIC void _setup_sleep_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t alarm_touch_touchalarm_set_alarm(deep_sleep, n_alarms, alarms); } -STATIC void _idle_until_alarm(void) { +nrf_sleep_source_t system_on_idle_until_alarm(int64_t timediff_ms, uint32_t prescaler) { + bool have_timeout = false; + uint64_t start_tick = 0, end_tick = 0; + + if (timediff_ms != -1) { + have_timeout = true; +#if 0 + int64_t now = common_hal_time_monotonic_ms(); + dbg_printf("now_ms=%ld timediff_ms=%ld\r\n", (long)now, (long)timediff_ms); +#endif + if (timediff_ms < 0) timediff_ms = 0; + int64_t tickdiff; + if (prescaler == 0) { + // 1 tick = 1/1024 sec = 1000/1024 ms + // -> 1 ms = 1024/1000 ticks + tickdiff = (mp_uint_t)(timediff_ms * 1024 / 1000); // ms -> ticks + } + else { + // 1 tick = prescaler/1024 sec = prescaler*1000/1024 ms + // -> 1ms = 1024/(1000*prescaler) ticks + tickdiff = (mp_uint_t)(timediff_ms * 1024 / (1000 * prescaler)); + } + start_tick = port_get_raw_ticks(NULL); + end_tick = start_tick + tickdiff; + } +#if 0 + dbg_printf("start_tick=%ld end_tick=%ld have_timeout=%c\r\n", (long)start_tick, (long)end_tick, have_timeout ? 'T' : 'F'); +#endif + + int64_t remaining; + nrf_sleep_source_t wakeup_cause = NRF_SLEEP_WAKEUP_UNDEFINED; + sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_NONE; + sleepmem_wakeup_pin = WAKEUP_PIN_UNDEF; + #ifdef NRF_DEBUG_PRINT int ct = 40; + char reason = '?'; +#define WAKEUP_REASON(x) reason = (x) +#else +#define WAKEUP_REASON(x) #endif - reset_reason_saved = 0; - // Poll for alarms. - while (!mp_hal_is_interrupted()) { - RUN_BACKGROUND_TASKS; - // Allow ctrl-C interrupt. - if (alarm_woken_from_sleep()) { - alarm_save_wake_alarm(); - return; + + while(1) { + if (mp_hal_is_interrupted()) { + WAKEUP_REASON('I'); + break; } + if (serial_connected() && serial_bytes_available()) { + WAKEUP_REASON('S'); + break; + } + RUN_BACKGROUND_TASKS; + wakeup_cause = alarm_woken_from_sleep_2(); + if (wakeup_cause != NRF_SLEEP_WAKEUP_UNDEFINED) { + WAKEUP_REASON('0'+wakeup_cause); + break; + } + if (have_timeout) { + remaining = end_tick - port_get_raw_ticks(NULL); + // We break a bit early so we don't risk setting the alarm before the time when we call + // sleep. + if (remaining < 1) { + WAKEUP_REASON('t'); + break; + } + port_interrupt_after_ticks(remaining); + } + // Idle until an interrupt happens. port_idle_until_interrupt(); #ifdef NRF_DEBUG_PRINT if (ct > 0) { @@ -166,17 +241,39 @@ STATIC void _idle_until_alarm(void) { --ct; } #endif + if (have_timeout) { + remaining = end_tick - port_get_raw_ticks(NULL); + if (remaining <= 0) { + wakeup_cause = NRF_SLEEP_WAKEUP_TIMER; + sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_TIMER; + WAKEUP_REASON('T'); + break; + } + } } +#ifdef NRF_DEBUG_PRINT + dbg_printf("%c\r\n", reason); +#endif + return wakeup_cause; } mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj_t *alarms) { mp_obj_t r_obj = mp_const_none; + alarm_time_timealarm_clear_wakeup_time(); _setup_sleep_alarms(false, n_alarms, alarms); + #ifdef NRF_DEBUG_PRINT - dbg_printf("\r\nsleep..."); + dbg_printf("\r\nlight sleep..."); #endif - _idle_until_alarm(); + int64_t timediff_ms = alarm_time_timealarm_get_wakeup_timediff_ms(); + nrf_sleep_source_t cause = system_on_idle_until_alarm(timediff_ms, 0); + (void)cause; + +#ifdef NRF_DEBUG_PRINT + //dbg_printf("wakeup! "); + print_wakeup_cause(cause); +#endif if (mp_hal_is_interrupted()) { #ifdef NRF_DEBUG_PRINT @@ -192,29 +289,47 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj } void common_hal_alarm_set_deep_sleep_alarms(size_t n_alarms, const mp_obj_t *alarms) { + alarm_time_timealarm_clear_wakeup_time(); _setup_sleep_alarms(true, n_alarms, alarms); } -extern void set_memory_retention(void); +#if defined(MICROPY_QSPI_CS) +extern void qspi_disable(void); +#endif + +#define PRESCALER_VALUE_IN_DEEP_SLEEP (1024) +extern void _debug_uart_init(void); +extern void _debug_uart_uninit(void); void NORETURN alarm_enter_deep_sleep(void) { alarm_pin_pinalarm_prepare_for_deep_sleep(); - alarm_touch_touchalarm_prepare_for_deep_sleep(); + alarm_time_timealarm_prepare_for_deep_sleep(); - uint8_t sd_enabled; - sd_softdevice_is_enabled(&sd_enabled); - - set_memory_retention(); +#if defined(MICROPY_QSPI_CS) + qspi_disable(); +#endif #ifdef NRF_DEBUG_PRINT - dbg_printf("go system off.. %d\r\n", sd_enabled); + dbg_printf("\r\ndeep sleep..."); #endif - if (sd_enabled) { - sd_power_system_off(); - } - else { - NRF_POWER->SYSTEMOFF = 1; - } + int64_t timediff_ms = alarm_time_timealarm_get_wakeup_timediff_ms(); + tick_set_prescaler(PRESCALER_VALUE_IN_DEEP_SLEEP -1); +#ifdef NRF_DEBUG_PRINT + dbg_dump_RTCreg(); //XXX + dbg_check_RTCprescaler(); //XXX +#endif + nrf_sleep_source_t cause; + cause = system_on_idle_until_alarm(timediff_ms, + PRESCALER_VALUE_IN_DEEP_SLEEP); + (void)cause; + +#ifdef NRF_DEBUG_PRINT + dbg_printf("wakeup! "); + print_wakeup_cause(cause); + dbg_printf("RESET...\r\n\r\n"); +#endif + + reset_cpu(); // should not reach here.. while(1) ; @@ -222,12 +337,23 @@ void NORETURN alarm_enter_deep_sleep(void) { void alarm_pretending_deep_sleep(void) { alarm_pin_pinalarm_prepare_for_deep_sleep(); - alarm_touch_touchalarm_prepare_for_deep_sleep(); + alarm_time_timealarm_prepare_for_deep_sleep(); - port_idle_until_interrupt(); - if (alarm_woken_from_sleep()) { - alarm_reset(); - } +#ifdef NRF_DEBUG_PRINT + dbg_printf("\r\npretending to deep sleep..."); +#endif + + int64_t timediff_ms = alarm_time_timealarm_get_wakeup_timediff_ms(); + nrf_sleep_source_t cause = system_on_idle_until_alarm(timediff_ms, 0); + (void)cause; + +#ifdef NRF_DEBUG_PRINT + dbg_printf("wakeup! "); + print_wakeup_cause(cause); + dbg_printf("continue..\r\n"); +#endif + + alarm_reset(); } void common_hal_alarm_gc_collect(void) { diff --git a/ports/nrf/common-hal/alarm/__init__.h b/ports/nrf/common-hal/alarm/__init__.h index 6fa07bcd29..7df3aaf4c3 100644 --- a/ports/nrf/common-hal/alarm/__init__.h +++ b/ports/nrf/common-hal/alarm/__init__.h @@ -41,6 +41,15 @@ typedef enum { extern const alarm_sleep_memory_obj_t alarm_sleep_memory_obj; +enum { + SLEEPMEM_WAKEUP_BY_NONE = 0, + SLEEPMEM_WAKEUP_BY_PIN = 1, + SLEEPMEM_WAKEUP_BY_TIMER = 2, +}; +#define WAKEUP_PIN_UNDEF 0xFF +extern uint8_t sleepmem_wakeup_event; +extern uint8_t sleepmem_wakeup_pin; + extern void alarm_reset(void); #endif // MICROPY_INCLUDED_NRF_COMMON_HAL_ALARM__INIT__H diff --git a/ports/nrf/common-hal/alarm/pin/PinAlarm.c b/ports/nrf/common-hal/alarm/pin/PinAlarm.c index 47d7ce8360..1f00dc0c33 100644 --- a/ports/nrf/common-hal/alarm/pin/PinAlarm.c +++ b/ports/nrf/common-hal/alarm/pin/PinAlarm.c @@ -32,6 +32,7 @@ #include "shared-bindings/alarm/pin/PinAlarm.h" #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" +#include "common-hal/alarm/__init__.h" #include "nrfx.h" #include "nrf_gpio.h" @@ -43,8 +44,6 @@ #define WPIN_UNUSED 0xFF volatile char _pinhandler_gpiote_count; -volatile nrfx_gpiote_pin_t _pinhandler_ev_pin; -#define MYGPIOTE_EV_PIN_UNDEF 0xFF static bool pins_configured = false; extern uint32_t reset_reason_saved; @@ -81,11 +80,13 @@ bool common_hal_alarm_pin_pinalarm_get_pull(alarm_pin_pinalarm_obj_t *self) { static void pinalarm_gpiote_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { ++_pinhandler_gpiote_count; - _pinhandler_ev_pin = pin; + sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_PIN; + sleepmem_wakeup_pin = pin & 0xFF; } bool alarm_pin_pinalarm_woke_us_up(void) { - return (_pinhandler_gpiote_count > 0 && _pinhandler_ev_pin != MYGPIOTE_EV_PIN_UNDEF); + return (sleepmem_wakeup_event == SLEEPMEM_WAKEUP_BY_PIN && + sleepmem_wakeup_pin != WAKEUP_PIN_UNDEF); } mp_obj_t alarm_pin_pinalarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *alarms) { @@ -95,7 +96,7 @@ mp_obj_t alarm_pin_pinalarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *al continue; } alarm_pin_pinalarm_obj_t *alarm = MP_OBJ_TO_PTR(alarms[i]); - if (alarm->pin->number == _pinhandler_ev_pin) { + if (alarm->pin->number == sleepmem_wakeup_pin) { return alarms[i]; } } @@ -105,7 +106,7 @@ mp_obj_t alarm_pin_pinalarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *al // Map the pin number back to a pin object. for (size_t i = 0; i < mcu_pin_globals.map.used; i++) { const mcu_pin_obj_t* pin_obj = MP_OBJ_TO_PTR(mcu_pin_globals.map.table[i].value); - if ((size_t) pin_obj->number == _pinhandler_ev_pin) { + if ((size_t) pin_obj->number == sleepmem_wakeup_pin) { alarm->pin = mcu_pin_globals.map.table[i].value; break; } @@ -147,7 +148,6 @@ static void configure_pins_for_sleep(void) { (void)err; // to suppress unused warning _pinhandler_gpiote_count = 0; - _pinhandler_ev_pin = MYGPIOTE_EV_PIN_UNDEF; nrfx_gpiote_in_config_t cfg = { .sense = NRF_GPIOTE_POLARITY_TOGGLE, diff --git a/ports/nrf/common-hal/alarm/time/TimeAlarm.c b/ports/nrf/common-hal/alarm/time/TimeAlarm.c index e9c536414b..c4b06982bf 100644 --- a/ports/nrf/common-hal/alarm/time/TimeAlarm.c +++ b/ports/nrf/common-hal/alarm/time/TimeAlarm.c @@ -30,6 +30,7 @@ //#include "supervisor/esp_port.h" #include +#include "common-hal/alarm/__init__.h" #include "shared-bindings/alarm/time/TimeAlarm.h" #include "shared-bindings/time/__init__.h" @@ -56,17 +57,31 @@ mp_obj_t alarm_time_timealarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t * } bool alarm_time_timealarm_woke_us_up(void) { - return rtc_woke_up_counter; + return sleepmem_wakeup_event == SLEEPMEM_WAKEUP_BY_TIMER; +} + +int64_t wakeup_time_saved =0; + +int64_t alarm_time_timealarm_get_wakeup_timediff_ms(void) { + if (wakeup_time_saved == 0) { + return -1; + } + return wakeup_time_saved - common_hal_time_monotonic_ms(); +} + +void alarm_time_timealarm_clear_wakeup_time(void) { + wakeup_time_saved = 0; } void alarm_time_timealarm_reset(void) { port_disable_interrupt_after_ticks_ch(1); - rtc_woke_up_counter = 0; + wakeup_time_saved = 0; } void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms) { bool timealarm_set = false; alarm_time_timealarm_obj_t *timealarm = MP_OBJ_NULL; + wakeup_time_saved = 0; for (size_t i = 0; i < n_alarms; i++) { if (!MP_OBJ_IS_TYPE(alarms[i], &alarm_time_timealarm_type)) { @@ -82,17 +97,8 @@ void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ return; } - // Compute how long to actually sleep, considering the time now. - mp_float_t now_secs = uint64_to_float(common_hal_time_monotonic_ms()) / 1000.0f; - mp_float_t wakeup_in_secs = MAX(0.0f, timealarm->monotonic_time - now_secs); - int wsecs = (int)(wakeup_in_secs); - // timealarm is implemented by RTC, which is a 24bit counter - // running at 32768Hz. So, 2^24 / 32768 = 512sec is an upper limit. - if (wsecs >= 512) { - mp_raise_ValueError(translate("Alarm time must be < 512 seconds.")); - } - - uint32_t wakeup_in_ticks = (uint32_t)(wakeup_in_secs * 1024.0f); - port_interrupt_after_ticks_ch(1, wakeup_in_ticks); - rtc_woke_up_counter = 0; + wakeup_time_saved = (int64_t)(timealarm->monotonic_time * 1000.0f); +} + +void alarm_time_timealarm_prepare_for_deep_sleep(void) { } diff --git a/ports/nrf/common-hal/alarm/time/TimeAlarm.h b/ports/nrf/common-hal/alarm/time/TimeAlarm.h index 14a2ff80cf..a824c52535 100644 --- a/ports/nrf/common-hal/alarm/time/TimeAlarm.h +++ b/ports/nrf/common-hal/alarm/time/TimeAlarm.h @@ -42,3 +42,9 @@ mp_obj_t alarm_time_timealarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t * bool alarm_time_timealarm_woke_us_up(void); void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t *alarms); void alarm_time_timealarm_reset(void); + +extern void alarm_time_timealarm_prepare_for_deep_sleep(void); +extern int64_t alarm_time_timealarm_get_wakeup_timediff_ms(void); +extern void alarm_time_timealarm_clear_wakeup_time(void); +extern void dbg_dump_RTCreg(void); +extern void tick_set_prescaler(uint32_t prescaler_val); diff --git a/ports/nrf/supervisor/debug_uart.c b/ports/nrf/supervisor/debug_uart.c index dda03a00af..f920cdae32 100644 --- a/ports/nrf/supervisor/debug_uart.c +++ b/ports/nrf/supervisor/debug_uart.c @@ -21,9 +21,9 @@ #include "nrfx_rtc.h" #include "supervisor/serial.h" // dbg_printf() #include "shared-bindings/microcontroller/Processor.h" +#include "common-hal/alarm/__init__.h" extern const nrfx_rtc_t rtc_instance; // port.c -extern volatile int rtc_woke_up_counter; // port.c extern uint32_t reset_reason_saved; const nrfx_uarte_t _dbg_uart_inst = NRFX_UARTE_INSTANCE(1); @@ -31,6 +31,16 @@ static int _dbg_uart_initialized = 0; #define DBG_PBUF_LEN 80 static char _dbg_pbuf[DBG_PBUF_LEN+1]; +void _debug_uart_uninit(void) { + nrf_gpio_cfg(DEBUG_UART_TXPIN, + NRF_GPIO_PIN_DIR_INPUT, + NRF_GPIO_PIN_INPUT_DISCONNECT, + NRF_GPIO_PIN_NOPULL, + NRF_GPIO_PIN_S0S1, + NRF_GPIO_PIN_NOSENSE); + nrfx_uarte_uninit(&_dbg_uart_inst); +} + void _debug_uart_init(void) { //if (_dbg_uart_initialized) return; nrfx_uarte_config_t config = { @@ -55,6 +65,16 @@ void _debug_uart_init(void) { NRF_GPIO_PIN_H0H1, // orig=S0S1 NRF_GPIO_PIN_NOSENSE); _dbg_uart_initialized = 1; +#if 1 //XXX + #define DBGPIN 6+32 + nrf_gpio_cfg(DBGPIN, + NRF_GPIO_PIN_DIR_OUTPUT, + NRF_GPIO_PIN_INPUT_DISCONNECT, + NRF_GPIO_PIN_NOPULL, + NRF_GPIO_PIN_H0H1, + NRF_GPIO_PIN_NOSENSE); + nrf_gpio_pin_write(DBGPIN, 1); +#endif return; } @@ -97,7 +117,15 @@ void dbg_dump_RTCreg(void) { dbg_printf("EVTENSET=%08X\r\n", (int)r->EVTENSET); dbg_printf("EVENTS_COMPARE[0..3]=%X,%X,%X,%X ", (int)r->EVENTS_COMPARE[0], (int)r->EVENTS_COMPARE[1], (int)r->EVENTS_COMPARE[2], (int)r->EVENTS_COMPARE[3]); dbg_printf("CC[0..3]=%08X,%08X,%08X,%08X\r\n", (int)r->CC[0], (int)r->CC[1], (int)r->CC[2], (int)r->CC[3]); - dbg_printf("woke_up=%d\r\n", rtc_woke_up_counter); +} + +int dbg_check_RTCprescaler(void) { + NRF_RTC_Type *r = rtc_instance.p_reg; + if ((int)r->PRESCALER == 0) { + dbg_printf("****** PRESCALER == 0\r\n"); + return -1; + } + return 0; } void dbg_dump_RAMreg(void) { diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c index 5908683008..d5efa92b46 100644 --- a/ports/nrf/supervisor/port.c +++ b/ports/nrf/supervisor/port.c @@ -51,6 +51,7 @@ #include "common-hal/rtc/RTC.h" #include "common-hal/neopixel_write/__init__.h" #include "common-hal/watchdog/WatchDogTimer.h" +#include "common-hal/alarm/__init__.h" #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/rtc/__init__.h" @@ -75,13 +76,13 @@ static void power_warning_handler(void) { #ifdef NRF_DEBUG_PRINT extern void _debug_uart_init(void); +#define DBGPIN 6+32 //XXX P1_06 = TP1 #endif uint32_t reset_reason_saved = 0; const nrfx_rtc_t rtc_instance = NRFX_RTC_INSTANCE(2); -volatile int rtc_woke_up_counter = 0; -const nrfx_rtc_config_t rtc_config = { +nrfx_rtc_config_t rtc_config = { .prescaler = RTC_FREQ_TO_PRESCALER(0x8000), .reliable = 0, .tick_latency = 0, @@ -97,6 +98,11 @@ static volatile struct { } overflow_tracker __attribute__((section(".uninitialized"))); void rtc_handler(nrfx_rtc_int_type_t int_type) { +#ifdef NRF_DEBUG_PRINT + if (int_type == NRFX_RTC_INT_TICK) { + nrf_gpio_pin_toggle(DBGPIN); //XXX + } +#endif if (int_type == NRFX_RTC_INT_OVERFLOW) { // Our RTC is 24 bits and we're clocking it at 32.768khz which is 32 (2 ** 5) subticks per // tick. @@ -108,7 +114,7 @@ void rtc_handler(nrfx_rtc_int_type_t int_type) { nrfx_rtc_cc_set(&rtc_instance, 0, 0, false); } else if (int_type == NRFX_RTC_INT_COMPARE1) { // used in light sleep - ++rtc_woke_up_counter; + sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_TIMER; nrfx_rtc_cc_set(&rtc_instance, 1, 0, false); } } @@ -134,6 +140,22 @@ void tick_init(void) { } } +void tick_uninit(void) { + nrfx_rtc_counter_clear(&rtc_instance); + nrfx_rtc_disable(&rtc_instance); + nrfx_rtc_uninit(&rtc_instance); +} + +void tick_set_prescaler(uint32_t prescaler_val) { + tick_uninit(); + // update of prescaler value sometimes fails if we skip this delay.. + NRFX_DELAY_US(1000); + uint16_t prescaler_saved = rtc_config.prescaler; + rtc_config.prescaler = prescaler_val; + tick_init(); + rtc_config.prescaler = prescaler_saved; +} + safe_mode_t port_init(void) { nrf_peripherals_clocks_init(); @@ -166,6 +188,10 @@ safe_mode_t port_init(void) { reset_reason_saved = NRF_POWER->RESETREAS; // clear all RESET reason bits NRF_POWER->RESETREAS = reset_reason_saved; + // clear wakeup event/pin when reset by reset-pin + if (reset_reason_saved & NRF_POWER_RESETREAS_RESETPIN_MASK) { + sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_NONE; + } // If the board was reset by the WatchDogTimer, we may // need to boot into safe mode. Reset the RESETREAS bit From cd5c0e99f797a5d21156c1f6d421b8c8e7fbf090 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 7 Mar 2021 19:09:01 +0900 Subject: [PATCH 036/103] Clean up. --- ports/nrf/supervisor/debug_uart.c | 26 ++++++++++++++++---------- ports/nrf/supervisor/port.c | 6 ------ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/ports/nrf/supervisor/debug_uart.c b/ports/nrf/supervisor/debug_uart.c index f920cdae32..f770b661fc 100644 --- a/ports/nrf/supervisor/debug_uart.c +++ b/ports/nrf/supervisor/debug_uart.c @@ -65,16 +65,6 @@ void _debug_uart_init(void) { NRF_GPIO_PIN_H0H1, // orig=S0S1 NRF_GPIO_PIN_NOSENSE); _dbg_uart_initialized = 1; -#if 1 //XXX - #define DBGPIN 6+32 - nrf_gpio_cfg(DBGPIN, - NRF_GPIO_PIN_DIR_OUTPUT, - NRF_GPIO_PIN_INPUT_DISCONNECT, - NRF_GPIO_PIN_NOPULL, - NRF_GPIO_PIN_H0H1, - NRF_GPIO_PIN_NOSENSE); - nrf_gpio_pin_write(DBGPIN, 1); -#endif return; } @@ -191,6 +181,22 @@ void dbg_dump_GPIOregs(void) { (int)(reg->EVENTS_PORT), (int)(reg->INTENSET)); } +void dbg_dumpQSPIreg(void) { + uint32_t r; + dbg_printf("QSPI\r\n"); + r = NRF_QSPI->IFCONFIG0; + dbg_printf("IFCONFIG0 READ=%ld write=%ld ADDR=%ld DPM=%ld PPSIZE=%ld\r\n", + r & 7, (r >> 3) & 7, (r >> 6) & 1, (r >> 7) & 1, (r >> 12) & 1); + r = NRF_QSPI->IFCONFIG1; + dbg_printf("IFCONFIG1 SCKDELAY=%ld SPIMODE=%ld SCKFREQ=%ld\r\n", + r & 0xFF, (r >> 25) & 1, (r >> 28) & 0xF); + r = NRF_QSPI->STATUS; + dbg_printf("STATUS DPM=%ld READY=%ld SREG=0x%02lX\r\n", + (r >> 2) & 1, (r >> 3) & 1, (r >> 24) & 0xFF); + r = NRF_QSPI->DPMDUR; + dbg_printf("DPMDUR ENTER=%ld EXIT=%ld\r\n", r & 0xFFFF, (r >> 16) & 0xFFFF); +} + void dbg_dump_reset_reason(void) { int reset_reason = (int)common_hal_mcu_processor_get_reset_reason(); const char* rr_str[] = { diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c index d5efa92b46..1ae3cb29ab 100644 --- a/ports/nrf/supervisor/port.c +++ b/ports/nrf/supervisor/port.c @@ -76,7 +76,6 @@ static void power_warning_handler(void) { #ifdef NRF_DEBUG_PRINT extern void _debug_uart_init(void); -#define DBGPIN 6+32 //XXX P1_06 = TP1 #endif uint32_t reset_reason_saved = 0; @@ -98,11 +97,6 @@ static volatile struct { } overflow_tracker __attribute__((section(".uninitialized"))); void rtc_handler(nrfx_rtc_int_type_t int_type) { -#ifdef NRF_DEBUG_PRINT - if (int_type == NRFX_RTC_INT_TICK) { - nrf_gpio_pin_toggle(DBGPIN); //XXX - } -#endif if (int_type == NRFX_RTC_INT_OVERFLOW) { // Our RTC is 24 bits and we're clocking it at 32.768khz which is 32 (2 ** 5) subticks per // tick. From 2795c002adbaa4bdac90c87159cd00eed31792bb Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 7 Mar 2021 19:14:04 +0900 Subject: [PATCH 037/103] disable QSPI while system ON idle loop. --- ports/nrf/common-hal/alarm/__init__.c | 21 ++++--- ports/nrf/supervisor/qspi_flash.c | 86 +++++++++++++++++++++++++++ ports/nrf/supervisor/qspi_flash.h | 2 + 3 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 ports/nrf/supervisor/qspi_flash.h diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index 12bb2a40c4..10d3bcc4fb 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -45,6 +45,7 @@ #include "supervisor/serial.h" // dbg_printf() extern int dbg_check_RTCprescaler(void); #endif +#include "supervisor/qspi_flash.h" #include "nrf.h" #include "nrf_power.h" @@ -170,6 +171,10 @@ nrf_sleep_source_t system_on_idle_until_alarm(int64_t timediff_ms, uint32_t pres bool have_timeout = false; uint64_t start_tick = 0, end_tick = 0; +#if defined(MICROPY_QSPI_CS) + qspi_flash_enter_sleep(); +#endif + if (timediff_ms != -1) { have_timeout = true; #if 0 @@ -254,6 +259,11 @@ nrf_sleep_source_t system_on_idle_until_alarm(int64_t timediff_ms, uint32_t pres #ifdef NRF_DEBUG_PRINT dbg_printf("%c\r\n", reason); #endif + +#if defined(MICROPY_QSPI_CS) + qspi_flash_exit_sleep(); +#endif + return wakeup_cause; } @@ -293,29 +303,18 @@ void common_hal_alarm_set_deep_sleep_alarms(size_t n_alarms, const mp_obj_t *ala _setup_sleep_alarms(true, n_alarms, alarms); } -#if defined(MICROPY_QSPI_CS) -extern void qspi_disable(void); -#endif - #define PRESCALER_VALUE_IN_DEEP_SLEEP (1024) -extern void _debug_uart_init(void); -extern void _debug_uart_uninit(void); void NORETURN alarm_enter_deep_sleep(void) { alarm_pin_pinalarm_prepare_for_deep_sleep(); alarm_time_timealarm_prepare_for_deep_sleep(); -#if defined(MICROPY_QSPI_CS) - qspi_disable(); -#endif - #ifdef NRF_DEBUG_PRINT dbg_printf("\r\ndeep sleep..."); #endif int64_t timediff_ms = alarm_time_timealarm_get_wakeup_timediff_ms(); tick_set_prescaler(PRESCALER_VALUE_IN_DEEP_SLEEP -1); #ifdef NRF_DEBUG_PRINT - dbg_dump_RTCreg(); //XXX dbg_check_RTCprescaler(); //XXX #endif nrf_sleep_source_t cause; diff --git a/ports/nrf/supervisor/qspi_flash.c b/ports/nrf/supervisor/qspi_flash.c index 7ca27d56c4..00a88d52b9 100644 --- a/ports/nrf/supervisor/qspi_flash.c +++ b/ports/nrf/supervisor/qspi_flash.c @@ -37,6 +37,9 @@ #include "supervisor/shared/external_flash/common_commands.h" #include "supervisor/shared/external_flash/qspi_flash.h" +#ifdef NRF_DEBUG_PRINT +#include "supervisor/serial.h" // dbg_printf() +#endif // When USB is disconnected, disable QSPI in sleep mode to save energy void qspi_disable(void) @@ -190,7 +193,11 @@ void spi_flash_init(void) { .readoc = NRF_QSPI_READOC_FASTREAD, .writeoc = NRF_QSPI_WRITEOC_PP, .addrmode = NRF_QSPI_ADDRMODE_24BIT, +#ifdef QSPI_FLASH_POWERDOWN + .dpmconfig = true +#else .dpmconfig = false +#endif }, .phy_if = { .sck_freq = NRF_QSPI_FREQ_32MDIV16, // Start at a slow 2MHz and speed up once we know what we're talking to. @@ -238,3 +245,82 @@ void spi_flash_init_device(const external_flash_device* device) { NRF_QSPI->IFCONFIG1 &= ~QSPI_IFCONFIG1_SCKFREQ_Msk; NRF_QSPI->IFCONFIG1 |= sckfreq << QSPI_IFCONFIG1_SCKFREQ_Pos; } + +#ifdef QSPI_FLASH_POWERDOWN +// Parameters for external QSPI Flash power-down +// for W25Q128FV, +// tDP (nCS high to Power-down mode) = 3us +// tRES (nCS high to Standby mode) = 3us +// sck_delay = max(tDP, tRES) / 62.5ns = 48 -> 50 (w/ margin) +#define DUR_DPM_ENTER 1 // tDP in (256*62.5ns) units +#define DUR_DPM_EXIT 1 // tRES in (256*62.5ns) units +#define SCK_DELAY 50 // max(tDP, tRES) in (62.5ns) units +// wait necessary just after DPM enter/exit (cut and try) +#define WAIT_AFTER_DPM_ENTER 10 // usec +#define WAIT_AFTER_DPM_EXIT 50 // usec +#endif + +static int sck_delay_saved = 0; +#ifdef NRF_DEBUG_PRINT +extern void dbg_dumpQSPIreg(void); +#else +#define dbg_dumpQSPIreg(...) +#endif + +void qspi_flash_enter_sleep(void) { +#ifdef QSPI_FLASH_POWERDOWN + uint32_t r; + NRF_QSPI->DPMDUR = + ((DUR_DPM_ENTER & 0xFFFF) << 16) | (DUR_DPM_EXIT & 0xFFFF); + // set sck_delay tempolarily + r = NRF_QSPI->IFCONFIG1; + sck_delay_saved = (r & QSPI_IFCONFIG1_SCKDELAY_Msk) + >> QSPI_IFCONFIG1_SCKDELAY_Pos; + NRF_QSPI->IFCONFIG1 + = (NRF_QSPI->IFCONFIG1 & ~QSPI_IFCONFIG1_SCKDELAY_Msk) + | (SCK_DELAY << QSPI_IFCONFIG1_SCKDELAY_Pos); + + // enabling IFCONFIG0.DPMENABLE here won't work. + // -> do it in spi_flash_init() + //NRF_QSPI->IFCONFIG0 |= QSPI_IFCONFIG0_DPMENABLE_Msk; + //dbg_dumpQSPIreg(); + + // enter deep power-down mode (DPM) + NRF_QSPI->IFCONFIG1 |= QSPI_IFCONFIG1_DPMEN_Msk; + NRFX_DELAY_US(WAIT_AFTER_DPM_ENTER); + if (!(NRF_QSPI->STATUS & QSPI_STATUS_DPM_Msk)) { +#ifdef NRF_DEBUG_PRINT + dbg_printf("qspi flash: DPM failed\r\n"); +#endif + } +#endif + + qspi_disable(); + //dbg_dumpQSPIreg(); +} + +void qspi_flash_exit_sleep(void) { + qspi_enable(); + +#ifdef QSPI_FLASH_POWERDOWN + if (NRF_QSPI->STATUS & QSPI_STATUS_DPM_Msk) { + // exit deep power-down mode + NRF_QSPI->IFCONFIG1 &= ~QSPI_IFCONFIG1_DPMEN_Msk; + NRFX_DELAY_US(WAIT_AFTER_DPM_EXIT); + + if (NRF_QSPI->STATUS & QSPI_STATUS_DPM_Msk) { +#ifdef NRF_DEBUG_PRINT + dbg_printf("qspi flash: exiting DPM failed\r\n"); +#endif + } + // restore sck_delay + if (sck_delay_saved == 0) { + sck_delay_saved = 10; // default + } + NRF_QSPI->IFCONFIG1 + = (NRF_QSPI->IFCONFIG1 & ~QSPI_IFCONFIG1_SCKDELAY_Msk) + | (sck_delay_saved << QSPI_IFCONFIG1_SCKDELAY_Pos); + } + //dbg_dumpQSPIreg(); +#endif +} diff --git a/ports/nrf/supervisor/qspi_flash.h b/ports/nrf/supervisor/qspi_flash.h new file mode 100644 index 0000000000..527f3cec39 --- /dev/null +++ b/ports/nrf/supervisor/qspi_flash.h @@ -0,0 +1,2 @@ +extern void qspi_flash_enter_sleep(void); +extern void qspi_flash_exit_sleep(void); From 7430b92d27c912cf2e43337b4c4a45dac73100b0 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 7 Mar 2021 20:20:29 +0900 Subject: [PATCH 038/103] address hw pin-reset while sleep. --- ports/nrf/supervisor/qspi_flash.c | 49 ++++++++++++++++++------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/ports/nrf/supervisor/qspi_flash.c b/ports/nrf/supervisor/qspi_flash.c index 00a88d52b9..d2bf9678da 100644 --- a/ports/nrf/supervisor/qspi_flash.c +++ b/ports/nrf/supervisor/qspi_flash.c @@ -41,6 +41,27 @@ #include "supervisor/serial.h" // dbg_printf() #endif +#ifdef QSPI_FLASH_POWERDOWN +// Parameters for external QSPI Flash power-down +// for W25Q128FV, +// tDP (nCS high to Power-down mode) = 3us +// tRES (nCS high to Standby mode) = 3us +// sck_delay = max(tDP, tRES) / 62.5ns = 48 -> 50 (w/ margin) +#define DUR_DPM_ENTER 1 // tDP in (256*62.5ns) units +#define DUR_DPM_EXIT 1 // tRES in (256*62.5ns) units +#define SCK_DELAY 50 // max(tDP, tRES) in (62.5ns) units +// wait necessary just after DPM enter/exit (cut and try) +#define WAIT_AFTER_DPM_ENTER 10 // usec +#define WAIT_AFTER_DPM_EXIT 50 // usec +#endif + +static int sck_delay_saved = 0; +#ifdef NRF_DEBUG_PRINT +extern void dbg_dumpQSPIreg(void); +#else +#define dbg_dumpQSPIreg(...) +#endif + // When USB is disconnected, disable QSPI in sleep mode to save energy void qspi_disable(void) { @@ -222,6 +243,13 @@ void spi_flash_init(void) { // No callback for blocking API nrfx_qspi_init(&qspi_cfg, NULL, NULL); + +#ifdef QSPI_FLASH_POWERDOWN + // If pin-reset while flash is in power-down mode, + // the flash cannot accept any commands. Send CMD_WAKE to release it. + spi_flash_write_command(CMD_WAKE, NULL, 0); + NRFX_DELAY_US(WAIT_AFTER_DPM_EXIT); +#endif } void spi_flash_init_device(const external_flash_device* device) { @@ -246,27 +274,6 @@ void spi_flash_init_device(const external_flash_device* device) { NRF_QSPI->IFCONFIG1 |= sckfreq << QSPI_IFCONFIG1_SCKFREQ_Pos; } -#ifdef QSPI_FLASH_POWERDOWN -// Parameters for external QSPI Flash power-down -// for W25Q128FV, -// tDP (nCS high to Power-down mode) = 3us -// tRES (nCS high to Standby mode) = 3us -// sck_delay = max(tDP, tRES) / 62.5ns = 48 -> 50 (w/ margin) -#define DUR_DPM_ENTER 1 // tDP in (256*62.5ns) units -#define DUR_DPM_EXIT 1 // tRES in (256*62.5ns) units -#define SCK_DELAY 50 // max(tDP, tRES) in (62.5ns) units -// wait necessary just after DPM enter/exit (cut and try) -#define WAIT_AFTER_DPM_ENTER 10 // usec -#define WAIT_AFTER_DPM_EXIT 50 // usec -#endif - -static int sck_delay_saved = 0; -#ifdef NRF_DEBUG_PRINT -extern void dbg_dumpQSPIreg(void); -#else -#define dbg_dumpQSPIreg(...) -#endif - void qspi_flash_enter_sleep(void) { #ifdef QSPI_FLASH_POWERDOWN uint32_t r; From 2eed9a173555e837f2b33178346c42374379fa0e Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 7 Mar 2021 20:21:33 +0900 Subject: [PATCH 039/103] old System OFF sleep code for future reference. --- ports/nrf/common-hal/alarm/__init__.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index 10d3bcc4fb..5544cdeb59 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -334,6 +334,25 @@ void NORETURN alarm_enter_deep_sleep(void) { while(1) ; } +// old version deep sleep code that was used in alarm_enter_deep_sleep() +// for anyone who might want true System OFF sleep .. +#if 0 +void OLD_go_system_off(void) { + sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_NONE; + sleepmem_wakeup_pin = WAKEUP_PIN_UNDEF; + uint8_t sd_enabled; + sd_softdevice_is_enabled(&sd_enabled); + set_memory_retention(); + dbg_printf("OLD go system off.. %d\r\n", sd_enabled); + if (sd_enabled) { + sd_power_system_off(); + } + else { + NRF_POWER->SYSTEMOFF = 1; + } +} +#endif + void alarm_pretending_deep_sleep(void) { alarm_pin_pinalarm_prepare_for_deep_sleep(); alarm_time_timealarm_prepare_for_deep_sleep(); From 5bd1107feca0eb3e1d0e59f50d3e6d6d88753832 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 7 Mar 2021 20:38:04 +0900 Subject: [PATCH 040/103] Clean up. --- ports/nrf/supervisor/qspi_flash.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ports/nrf/supervisor/qspi_flash.c b/ports/nrf/supervisor/qspi_flash.c index d2bf9678da..e4449bcba0 100644 --- a/ports/nrf/supervisor/qspi_flash.c +++ b/ports/nrf/supervisor/qspi_flash.c @@ -53,9 +53,10 @@ // wait necessary just after DPM enter/exit (cut and try) #define WAIT_AFTER_DPM_ENTER 10 // usec #define WAIT_AFTER_DPM_EXIT 50 // usec -#endif static int sck_delay_saved = 0; +#endif + #ifdef NRF_DEBUG_PRINT extern void dbg_dumpQSPIreg(void); #else From c8f36e604cc8d9f566e1f68f0fffb1ad828204ce Mon Sep 17 00:00:00 2001 From: jun2sak Date: Tue, 9 Mar 2021 00:42:22 +0900 Subject: [PATCH 041/103] reset myself, not go REPL, after wakeup from deep sleep. --- ports/nrf/common-hal/alarm/__init__.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index 5544cdeb59..b9b39b84a4 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -170,6 +170,7 @@ STATIC void _setup_sleep_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t nrf_sleep_source_t system_on_idle_until_alarm(int64_t timediff_ms, uint32_t prescaler) { bool have_timeout = false; uint64_t start_tick = 0, end_tick = 0; + int64_t tickdiff; #if defined(MICROPY_QSPI_CS) qspi_flash_enter_sleep(); @@ -182,7 +183,6 @@ nrf_sleep_source_t system_on_idle_until_alarm(int64_t timediff_ms, uint32_t pres dbg_printf("now_ms=%ld timediff_ms=%ld\r\n", (long)now, (long)timediff_ms); #endif if (timediff_ms < 0) timediff_ms = 0; - int64_t tickdiff; if (prescaler == 0) { // 1 tick = 1/1024 sec = 1000/1024 ms // -> 1 ms = 1024/1000 ticks @@ -264,6 +264,18 @@ nrf_sleep_source_t system_on_idle_until_alarm(int64_t timediff_ms, uint32_t pres qspi_flash_exit_sleep(); #endif + tickdiff = port_get_raw_ticks(NULL) - start_tick; + if (prescaler == 0) { + timediff_ms = tickdiff / 1024; + } + else { + timediff_ms = tickdiff * prescaler / 1024; + } + (void)timediff_ms; +#ifdef NRF_DEBUG_PRINT + dbg_printf("lapse %6.1f sec\r\n", (double)(timediff_ms)); +#endif + return wakeup_cause; } @@ -368,10 +380,17 @@ void alarm_pretending_deep_sleep(void) { #ifdef NRF_DEBUG_PRINT dbg_printf("wakeup! "); print_wakeup_cause(cause); - dbg_printf("continue..\r\n"); #endif alarm_reset(); + + // if one of Alarm event occurred, reset myself + if (cause == NRF_SLEEP_WAKEUP_GPIO || + cause == NRF_SLEEP_WAKEUP_TIMER || + cause == NRF_SLEEP_WAKEUP_TOUCHPAD) { + reset_cpu(); + } + // else, just return and go into REPL } void common_hal_alarm_gc_collect(void) { From 6e9429d779f01c823ca4e0d0b277e20533d6ada3 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Mon, 12 Apr 2021 20:53:14 +0900 Subject: [PATCH 042/103] soft reboot for pretending deep sleep. --- main.c | 19 +++++++++++++++---- ports/nrf/common-hal/alarm/__init__.c | 7 ++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index b311db39dd..755f8d5362 100755 --- a/main.c +++ b/main.c @@ -404,10 +404,10 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { new_status_color(BLACK); board_deinit(); if (!supervisor_workflow_active()) { - // Enter true deep sleep. When we wake up we'll be back at the - // top of main(), not in this loop. + // Enter deep sleep. When we wake up we'll return from + // this loop. common_hal_alarm_enter_deep_sleep(); - // Does not return. + // Does not return. } else { serial_write_compressed(translate("Pretending to deep sleep until alarm, CTRL-C or file write.\n")); } @@ -426,10 +426,21 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { #if CIRCUITPY_ALARM common_hal_alarm_pretending_deep_sleep(); + bool serial_in = (serial_connected() && + serial_bytes_available()); + supervisor_set_run_reason(RUN_REASON_STARTUP); + board_init(); + if (serial_in) { + bool ctrl_d = serial_read() == CHAR_CTRL_D; + if (ctrl_d) { + supervisor_set_run_reason(RUN_REASON_REPL_RELOAD); + } + return ctrl_d; + } + return true; #else port_idle_until_interrupt(); #endif - //return false; // to go REPL } } } diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index 2baec6b433..c8180fb2e0 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -346,7 +346,7 @@ void NORETURN common_hal_alarm_enter_deep_sleep(void) { while(1) ; } -// old version deep sleep code that was used in alarm_enter_deep_sleep() +// old version deep sleep code that was used in common_hal_alarm_enter_deep_sleep() // for anyone who might want true System OFF sleep .. #if 0 void OLD_go_system_off(void) { @@ -384,6 +384,7 @@ void common_hal_alarm_pretending_deep_sleep(void) { alarm_reset(); +#if 0 // if one of Alarm event occurred, reset myself if (cause == NRF_SLEEP_WAKEUP_GPIO || cause == NRF_SLEEP_WAKEUP_TIMER || @@ -391,9 +392,9 @@ void common_hal_alarm_pretending_deep_sleep(void) { reset_cpu(); } // else, just return and go into REPL +#endif } void common_hal_alarm_gc_collect(void) { - void* p = shared_alarm_get_wake_alarm(); - gc_collect_ptr(p); + gc_collect_ptr(shared_alarm_get_wake_alarm()); } From 436e33e7ecd7af42ac52e94b6604c728d296bffe Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Tue, 20 Apr 2021 15:04:52 -0400 Subject: [PATCH 043/103] Fix CI formatting issues --- locale/circuitpython.pot | 5 +---- supervisor/shared/serial.c | 10 +++++----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index a5a4da90f8..2a43daf014 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -309,10 +309,6 @@ msgstr "" msgid "Address type out of range" msgstr "" -#: ports/nrf/common-hal/alarm/time/TimeAlarm.c -msgid "Alarm time must be < 512 seconds." -msgstr "" - #: ports/esp32s2/common-hal/canio/CAN.c msgid "All CAN peripherals are in use" msgstr "" @@ -3722,6 +3718,7 @@ msgstr "" #: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h #: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h #: ports/esp32s2/boards/artisense_rd00/mpconfigboard.h +#: ports/esp32s2/boards/atmegazero_esp32s2/mpconfigboard.h #: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h #: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h #: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h diff --git a/supervisor/shared/serial.c b/supervisor/shared/serial.c index dc3a37e116..beb2541a15 100644 --- a/supervisor/shared/serial.c +++ b/supervisor/shared/serial.c @@ -40,7 +40,7 @@ #ifdef NRF_DEBUG_PRINT // XXX these functions are in nrf/supervisor/debug_uart.c extern void _debug_uart_init(void); -extern void _debug_print_substr(const char* text, uint32_t length); +extern void _debug_print_substr(const char *text, uint32_t length); #endif /* @@ -72,15 +72,15 @@ void serial_early_init(void) { #endif #ifdef NRF_DEBUG_PRINT - _debug_uart_init(); + _debug_uart_init(); #endif } void serial_init(void) { usb_init(); -#ifdef NRF_DEBUG_PRINT + #ifdef NRF_DEBUG_PRINT _debug_uart_init(); -#endif + #endif } bool serial_connected(void) { @@ -160,7 +160,7 @@ void serial_write_substring(const char *text, uint32_t length) { #if defined(DEBUG_UART_TX) && defined(DEBUG_UART_RX) int uart_errcode; - common_hal_busio_uart_write(&debug_uart, (const uint8_t*) text, length, &uart_errcode); + common_hal_busio_uart_write(&debug_uart, (const uint8_t *)text, length, &uart_errcode); #endif #ifdef NRF_DEBUG_PRINT From a1dc423569c94b994aaa7ee21cd4d3bbdb59fbc8 Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Tue, 20 Apr 2021 17:20:53 -0400 Subject: [PATCH 044/103] Remove Alarm from small boards --- ports/nrf/boards/pca10100/mpconfigboard.mk | 1 + ports/nrf/boards/simmel/mpconfigboard.mk | 1 + ports/nrf/mpconfigport.mk | 2 +- ports/nrf/supervisor/port.c | 4 ++++ 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ports/nrf/boards/pca10100/mpconfigboard.mk b/ports/nrf/boards/pca10100/mpconfigboard.mk index 74080a1ed9..dd59eb96c9 100644 --- a/ports/nrf/boards/pca10100/mpconfigboard.mk +++ b/ports/nrf/boards/pca10100/mpconfigboard.mk @@ -7,6 +7,7 @@ MCU_CHIP = nrf52833 INTERNAL_FLASH_FILESYSTEM = 1 +CIRCUITPY_ALARM = 0 CIRCUITPY_AUDIOMP3 = 0 CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITMAPTOOLS = 0 diff --git a/ports/nrf/boards/simmel/mpconfigboard.mk b/ports/nrf/boards/simmel/mpconfigboard.mk index 005ec8af2f..e6750877b2 100644 --- a/ports/nrf/boards/simmel/mpconfigboard.mk +++ b/ports/nrf/boards/simmel/mpconfigboard.mk @@ -10,6 +10,7 @@ MCU_CHIP = nrf52833 INTERNAL_FLASH_FILESYSTEM = 1 +CIRCUITPY_ALARM = 0 CIRCUITPY_AESIO = 1 CIRCUITPY_AUDIOMP3 = 0 CIRCUITPY_BITMAPTOOLS = 0 diff --git a/ports/nrf/mpconfigport.mk b/ports/nrf/mpconfigport.mk index a5766cf1fe..132aba208f 100644 --- a/ports/nrf/mpconfigport.mk +++ b/ports/nrf/mpconfigport.mk @@ -47,7 +47,7 @@ CIRCUITPY_COUNTIO = 0 CIRCUITPY_WATCHDOG ?= 1 # Sleep and Wakeup -CIRCUITPY_ALARM = 1 +CIRCUITPY_ALARM ?= 1 # nRF52840-specific diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c index 5cad994c0d..8026e51d84 100644 --- a/ports/nrf/supervisor/port.c +++ b/ports/nrf/supervisor/port.c @@ -108,7 +108,9 @@ void rtc_handler(nrfx_rtc_int_type_t int_type) { nrfx_rtc_cc_set(&rtc_instance, 0, 0, false); } else if (int_type == NRFX_RTC_INT_COMPARE1) { // used in light sleep + #if CIRCUITPY_ALARM sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_TIMER; + #endif nrfx_rtc_cc_set(&rtc_instance, 1, 0, false); } } @@ -184,7 +186,9 @@ safe_mode_t port_init(void) { NRF_POWER->RESETREAS = reset_reason_saved; // clear wakeup event/pin when reset by reset-pin if (reset_reason_saved & NRF_POWER_RESETREAS_RESETPIN_MASK) { + #if CIRCUITPY_ALARM sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_NONE; + #endif } // If the board was reset by the WatchDogTimer, we may From 39b7d9bcf2098d8402392dd5f237787cf8d75d86 Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Tue, 20 Apr 2021 18:03:37 -0400 Subject: [PATCH 045/103] Fix indentation --- main.c | 12 +- ports/nrf/common-hal/alarm/SleepMemory.c | 22 ++-- ports/nrf/common-hal/alarm/__init__.c | 106 +++++++++--------- ports/nrf/common-hal/alarm/__init__.h | 14 +-- ports/nrf/common-hal/alarm/pin/PinAlarm.c | 26 ++--- .../common-hal/microcontroller/Processor.c | 6 +- ports/nrf/supervisor/debug_uart.c | 104 ++++++++--------- ports/nrf/supervisor/qspi_flash.c | 24 ++-- 8 files changed, 157 insertions(+), 157 deletions(-) diff --git a/main.c b/main.c index 755f8d5362..d16db235e8 100755 --- a/main.c +++ b/main.c @@ -407,7 +407,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { // Enter deep sleep. When we wake up we'll return from // this loop. common_hal_alarm_enter_deep_sleep(); - // Does not return. + // Does not return. } else { serial_write_compressed(translate("Pretending to deep sleep until alarm, CTRL-C or file write.\n")); } @@ -431,11 +431,11 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { supervisor_set_run_reason(RUN_REASON_STARTUP); board_init(); if (serial_in) { - bool ctrl_d = serial_read() == CHAR_CTRL_D; - if (ctrl_d) { - supervisor_set_run_reason(RUN_REASON_REPL_RELOAD); - } - return ctrl_d; + bool ctrl_d = serial_read() == CHAR_CTRL_D; + if (ctrl_d) { + supervisor_set_run_reason(RUN_REASON_REPL_RELOAD); + } + return ctrl_d; } return true; #else diff --git a/ports/nrf/common-hal/alarm/SleepMemory.c b/ports/nrf/common-hal/alarm/SleepMemory.c index 367f305972..e87fcd7991 100644 --- a/ports/nrf/common-hal/alarm/SleepMemory.c +++ b/ports/nrf/common-hal/alarm/SleepMemory.c @@ -57,22 +57,22 @@ void set_memory_retention(void) { // nRF52833 has RAM[0..7].Section[0..1] and RAM[8].Section[0,1] for(int block = 0; block <= 7; ++block) { nrf_power_rampower_mask_on(NRF_POWER, block, - NRF_POWER_RAMPOWER_S0RETENTION_MASK | - NRF_POWER_RAMPOWER_S1RETENTION_MASK); + NRF_POWER_RAMPOWER_S0RETENTION_MASK | + NRF_POWER_RAMPOWER_S1RETENTION_MASK); }; #ifdef NRF52840 nrf_power_rampower_mask_on(NRF_POWER, 8, - NRF_POWER_RAMPOWER_S0RETENTION_MASK | - NRF_POWER_RAMPOWER_S1RETENTION_MASK | - NRF_POWER_RAMPOWER_S2RETENTION_MASK | - NRF_POWER_RAMPOWER_S3RETENTION_MASK | - NRF_POWER_RAMPOWER_S4RETENTION_MASK | - NRF_POWER_RAMPOWER_S5RETENTION_MASK); + NRF_POWER_RAMPOWER_S0RETENTION_MASK | + NRF_POWER_RAMPOWER_S1RETENTION_MASK | + NRF_POWER_RAMPOWER_S2RETENTION_MASK | + NRF_POWER_RAMPOWER_S3RETENTION_MASK | + NRF_POWER_RAMPOWER_S4RETENTION_MASK | + NRF_POWER_RAMPOWER_S5RETENTION_MASK); #endif #ifdef NRF52833 nrf_power_rampower_mask_on(NRF_POWER, 8, - NRF_POWER_RAMPOWER_S0RETENTION_MASK | - NRF_POWER_RAMPOWER_S1RETENTION_MASK); + NRF_POWER_RAMPOWER_S0RETENTION_MASK | + NRF_POWER_RAMPOWER_S1RETENTION_MASK); #endif } @@ -93,7 +93,7 @@ void alarm_sleep_memory_reset(void) { if (!is_sleep_memory_valid()) { initialize_sleep_memory(); #ifdef NRF_DEBUG_PRINT - dbg_printf("sleep memory initialized\r\n"); + dbg_printf("sleep memory initialized\r\n"); #endif } } diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index c8180fb2e0..aabb27ef25 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -101,7 +101,7 @@ static const char* cause_str[] = { void print_wakeup_cause(nrf_sleep_source_t cause) { if (cause >= 0 && cause < NRF_SLEEP_WAKEUP_ZZZ) { dbg_printf("wakeup cause = NRF_SLEEP_WAKEUP_%s\r\n", - cause_str[(int)cause]); + cause_str[(int)cause]); } } #endif @@ -114,7 +114,7 @@ bool common_hal_alarm_woken_from_sleep(void) { } #endif return (cause == NRF_SLEEP_WAKEUP_GPIO || cause == NRF_SLEEP_WAKEUP_TIMER - || cause == NRF_SLEEP_WAKEUP_TOUCHPAD); + || cause == NRF_SLEEP_WAKEUP_TOUCHPAD); } nrf_sleep_source_t alarm_woken_from_sleep_2(void) { @@ -125,8 +125,8 @@ nrf_sleep_source_t alarm_woken_from_sleep_2(void) { } #endif if (cause == NRF_SLEEP_WAKEUP_GPIO || - cause == NRF_SLEEP_WAKEUP_TIMER || - cause == NRF_SLEEP_WAKEUP_TOUCHPAD) { + cause == NRF_SLEEP_WAKEUP_TIMER || + cause == NRF_SLEEP_WAKEUP_TOUCHPAD) { return cause; } else { @@ -179,22 +179,22 @@ nrf_sleep_source_t system_on_idle_until_alarm(int64_t timediff_ms, uint32_t pres if (timediff_ms != -1) { have_timeout = true; #if 0 - int64_t now = common_hal_time_monotonic_ms(); - dbg_printf("now_ms=%ld timediff_ms=%ld\r\n", (long)now, (long)timediff_ms); + int64_t now = common_hal_time_monotonic_ms(); + dbg_printf("now_ms=%ld timediff_ms=%ld\r\n", (long)now, (long)timediff_ms); #endif - if (timediff_ms < 0) timediff_ms = 0; - if (prescaler == 0) { - // 1 tick = 1/1024 sec = 1000/1024 ms - // -> 1 ms = 1024/1000 ticks - tickdiff = (mp_uint_t)(timediff_ms * 1024 / 1000); // ms -> ticks - } - else { - // 1 tick = prescaler/1024 sec = prescaler*1000/1024 ms - // -> 1ms = 1024/(1000*prescaler) ticks - tickdiff = (mp_uint_t)(timediff_ms * 1024 / (1000 * prescaler)); - } - start_tick = port_get_raw_ticks(NULL); - end_tick = start_tick + tickdiff; + if (timediff_ms < 0) timediff_ms = 0; + if (prescaler == 0) { + // 1 tick = 1/1024 sec = 1000/1024 ms + // -> 1 ms = 1024/1000 ticks + tickdiff = (mp_uint_t)(timediff_ms * 1024 / 1000); // ms -> ticks + } + else { + // 1 tick = prescaler/1024 sec = prescaler*1000/1024 ms + // -> 1ms = 1024/(1000*prescaler) ticks + tickdiff = (mp_uint_t)(timediff_ms * 1024 / (1000 * prescaler)); + } + start_tick = port_get_raw_ticks(NULL); + end_tick = start_tick + tickdiff; } #if 0 dbg_printf("start_tick=%ld end_tick=%ld have_timeout=%c\r\n", (long)start_tick, (long)end_tick, have_timeout ? 'T' : 'F'); @@ -214,30 +214,30 @@ nrf_sleep_source_t system_on_idle_until_alarm(int64_t timediff_ms, uint32_t pres #endif while(1) { - if (mp_hal_is_interrupted()) { - WAKEUP_REASON('I'); - break; - } + if (mp_hal_is_interrupted()) { + WAKEUP_REASON('I'); + break; + } if (serial_connected() && serial_bytes_available()) { - WAKEUP_REASON('S'); - break; - } + WAKEUP_REASON('S'); + break; + } RUN_BACKGROUND_TASKS; - wakeup_cause = alarm_woken_from_sleep_2(); - if (wakeup_cause != NRF_SLEEP_WAKEUP_UNDEFINED) { - WAKEUP_REASON('0'+wakeup_cause); - break; - } - if (have_timeout) { - remaining = end_tick - port_get_raw_ticks(NULL); - // We break a bit early so we don't risk setting the alarm before the time when we call - // sleep. - if (remaining < 1) { - WAKEUP_REASON('t'); - break; - } - port_interrupt_after_ticks(remaining); - } + wakeup_cause = alarm_woken_from_sleep_2(); + if (wakeup_cause != NRF_SLEEP_WAKEUP_UNDEFINED) { + WAKEUP_REASON('0'+wakeup_cause); + break; + } + if (have_timeout) { + remaining = end_tick - port_get_raw_ticks(NULL); + // We break a bit early so we don't risk setting the alarm before the time when we call + // sleep. + if (remaining < 1) { + WAKEUP_REASON('t'); + break; + } + port_interrupt_after_ticks(remaining); + } // Idle until an interrupt happens. port_idle_until_interrupt(); #ifdef NRF_DEBUG_PRINT @@ -246,15 +246,15 @@ nrf_sleep_source_t system_on_idle_until_alarm(int64_t timediff_ms, uint32_t pres --ct; } #endif - if (have_timeout) { - remaining = end_tick - port_get_raw_ticks(NULL); - if (remaining <= 0) { - wakeup_cause = NRF_SLEEP_WAKEUP_TIMER; - sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_TIMER; - WAKEUP_REASON('T'); - break; - } - } + if (have_timeout) { + remaining = end_tick - port_get_raw_ticks(NULL); + if (remaining <= 0) { + wakeup_cause = NRF_SLEEP_WAKEUP_TIMER; + sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_TIMER; + WAKEUP_REASON('T'); + break; + } + } } #ifdef NRF_DEBUG_PRINT dbg_printf("%c\r\n", reason); @@ -331,7 +331,7 @@ void NORETURN common_hal_alarm_enter_deep_sleep(void) { #endif nrf_sleep_source_t cause; cause = system_on_idle_until_alarm(timediff_ms, - PRESCALER_VALUE_IN_DEEP_SLEEP); + PRESCALER_VALUE_IN_DEEP_SLEEP); (void)cause; #ifdef NRF_DEBUG_PRINT @@ -387,8 +387,8 @@ void common_hal_alarm_pretending_deep_sleep(void) { #if 0 // if one of Alarm event occurred, reset myself if (cause == NRF_SLEEP_WAKEUP_GPIO || - cause == NRF_SLEEP_WAKEUP_TIMER || - cause == NRF_SLEEP_WAKEUP_TOUCHPAD) { + cause == NRF_SLEEP_WAKEUP_TIMER || + cause == NRF_SLEEP_WAKEUP_TOUCHPAD) { reset_cpu(); } // else, just return and go into REPL diff --git a/ports/nrf/common-hal/alarm/__init__.h b/ports/nrf/common-hal/alarm/__init__.h index 7df3aaf4c3..ce8ca5f327 100644 --- a/ports/nrf/common-hal/alarm/__init__.h +++ b/ports/nrf/common-hal/alarm/__init__.h @@ -30,13 +30,13 @@ #include "common-hal/alarm/SleepMemory.h" typedef enum { - NRF_SLEEP_WAKEUP_UNDEFINED, - NRF_SLEEP_WAKEUP_GPIO, - NRF_SLEEP_WAKEUP_TIMER, - NRF_SLEEP_WAKEUP_TOUCHPAD, - NRF_SLEEP_WAKEUP_VBUS, - NRF_SLEEP_WAKEUP_RESETPIN, - NRF_SLEEP_WAKEUP_ZZZ + NRF_SLEEP_WAKEUP_UNDEFINED, + NRF_SLEEP_WAKEUP_GPIO, + NRF_SLEEP_WAKEUP_TIMER, + NRF_SLEEP_WAKEUP_TOUCHPAD, + NRF_SLEEP_WAKEUP_VBUS, + NRF_SLEEP_WAKEUP_RESETPIN, + NRF_SLEEP_WAKEUP_ZZZ } nrf_sleep_source_t; extern const alarm_sleep_memory_obj_t alarm_sleep_memory_obj; diff --git a/ports/nrf/common-hal/alarm/pin/PinAlarm.c b/ports/nrf/common-hal/alarm/pin/PinAlarm.c index 1f00dc0c33..89ec2ad30f 100644 --- a/ports/nrf/common-hal/alarm/pin/PinAlarm.c +++ b/ports/nrf/common-hal/alarm/pin/PinAlarm.c @@ -86,7 +86,7 @@ static void pinalarm_gpiote_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t bool alarm_pin_pinalarm_woke_us_up(void) { return (sleepmem_wakeup_event == SLEEPMEM_WAKEUP_BY_PIN && - sleepmem_wakeup_pin != WAKEUP_PIN_UNDEF); + sleepmem_wakeup_pin != WAKEUP_PIN_UNDEF); } mp_obj_t alarm_pin_pinalarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *alarms) { @@ -96,7 +96,7 @@ mp_obj_t alarm_pin_pinalarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *al continue; } alarm_pin_pinalarm_obj_t *alarm = MP_OBJ_TO_PTR(alarms[i]); - if (alarm->pin->number == sleepmem_wakeup_pin) { + if (alarm->pin->number == sleepmem_wakeup_pin) { return alarms[i]; } } @@ -129,8 +129,8 @@ void alarm_pin_pinalarm_reset(void) { continue; } reset_pin_number(i); - nrfx_gpiote_in_event_disable((nrfx_gpiote_pin_t)i); - nrfx_gpiote_in_uninit((nrfx_gpiote_pin_t)i); + nrfx_gpiote_in_event_disable((nrfx_gpiote_pin_t)i); + nrfx_gpiote_in_uninit((nrfx_gpiote_pin_t)i); } high_alarms = 0; @@ -177,15 +177,15 @@ static void configure_pins_for_sleep(void) { cfg.pull = NRF_GPIO_PIN_NOPULL; } err = nrfx_gpiote_in_init((nrfx_gpiote_pin_t)i, &cfg, - pinalarm_gpiote_handler); - assert(err == NRFX_SUCCESS); + pinalarm_gpiote_handler); + assert(err == NRFX_SUCCESS); nrfx_gpiote_in_event_enable((nrfx_gpiote_pin_t)i, true); if (((high_alarms & mask) != 0) && ((low_alarms & mask) == 0)) { nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_HIGH); - } + } if (((high_alarms & mask) == 0) && ((low_alarms & mask) != 0)) { nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_LOW); - } + } } } @@ -202,7 +202,7 @@ void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ob alarm_pin_pinalarm_obj_t *alarm = MP_OBJ_TO_PTR(alarms[i]); pin_number = alarm->pin->number; - //dbg_printf("alarm_pin_pinalarm_set_alarms(pin#=%d, val=%d, pull=%d)\r\n", pin_number, alarm->value, alarm->pull); + //dbg_printf("alarm_pin_pinalarm_set_alarms(pin#=%d, val=%d, pull=%d)\r\n", pin_number, alarm->value, alarm->pull); if (alarm->value) { high_alarms |= 1ull << pin_number; high_count++; @@ -221,8 +221,8 @@ void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ob else { // we don't setup gpio HW here but do them in // alarm_pin_pinalarm_prepare_for_deep_sleep() below - reset_reason_saved = 0; - pins_configured = false; + reset_reason_saved = 0; + pins_configured = false; } } else { @@ -233,9 +233,9 @@ void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ob void alarm_pin_pinalarm_prepare_for_deep_sleep(void) { if (!pins_configured) { configure_pins_for_sleep(); - pins_configured = true; + pins_configured = true; #ifdef NRF_DEBUG_PRINT - //dbg_dump_GPIOregs(); + //dbg_dump_GPIOregs(); #endif } } diff --git a/ports/nrf/common-hal/microcontroller/Processor.c b/ports/nrf/common-hal/microcontroller/Processor.c index 4baa4eaace..bcad002ffe 100644 --- a/ports/nrf/common-hal/microcontroller/Processor.c +++ b/ports/nrf/common-hal/microcontroller/Processor.c @@ -141,9 +141,9 @@ mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { r = RESET_REASON_SOFTWARE; } else if ((reset_reason_saved & POWER_RESETREAS_OFF_Msk) || - (reset_reason_saved & POWER_RESETREAS_LPCOMP_Msk) || - (reset_reason_saved & POWER_RESETREAS_NFC_Msk) || - (reset_reason_saved & POWER_RESETREAS_VBUS_Msk)) { + (reset_reason_saved & POWER_RESETREAS_LPCOMP_Msk) || + (reset_reason_saved & POWER_RESETREAS_NFC_Msk) || + (reset_reason_saved & POWER_RESETREAS_VBUS_Msk)) { r = RESET_REASON_DEEP_SLEEP_ALARM; } return r; diff --git a/ports/nrf/supervisor/debug_uart.c b/ports/nrf/supervisor/debug_uart.c index f770b661fc..420ba14b82 100644 --- a/ports/nrf/supervisor/debug_uart.c +++ b/ports/nrf/supervisor/debug_uart.c @@ -33,11 +33,11 @@ static char _dbg_pbuf[DBG_PBUF_LEN+1]; void _debug_uart_uninit(void) { nrf_gpio_cfg(DEBUG_UART_TXPIN, - NRF_GPIO_PIN_DIR_INPUT, - NRF_GPIO_PIN_INPUT_DISCONNECT, - NRF_GPIO_PIN_NOPULL, - NRF_GPIO_PIN_S0S1, - NRF_GPIO_PIN_NOSENSE); + NRF_GPIO_PIN_DIR_INPUT, + NRF_GPIO_PIN_INPUT_DISCONNECT, + NRF_GPIO_PIN_NOPULL, + NRF_GPIO_PIN_S0S1, + NRF_GPIO_PIN_NOSENSE); nrfx_uarte_uninit(&_dbg_uart_inst); } @@ -59,11 +59,11 @@ void _debug_uart_init(void) { nrfx_uarte_init(&_dbg_uart_inst, &config, NULL); // drive config nrf_gpio_cfg(config.pseltxd, - NRF_GPIO_PIN_DIR_OUTPUT, - NRF_GPIO_PIN_INPUT_DISCONNECT, - NRF_GPIO_PIN_PULLUP, // orig=NOPULL - NRF_GPIO_PIN_H0H1, // orig=S0S1 - NRF_GPIO_PIN_NOSENSE); + NRF_GPIO_PIN_DIR_OUTPUT, + NRF_GPIO_PIN_INPUT_DISCONNECT, + NRF_GPIO_PIN_PULLUP, // orig=NOPULL + NRF_GPIO_PIN_H0H1, // orig=S0S1 + NRF_GPIO_PIN_NOSENSE); _dbg_uart_initialized = 1; return; } @@ -73,16 +73,16 @@ void _debug_print_substr(const char* text, uint32_t length) { int siz; while(length != 0) { if (length <= DBG_PBUF_LEN) { - siz = length; - } - else { - siz = DBG_PBUF_LEN; - } - memcpy(_dbg_pbuf, data, siz); - _dbg_pbuf[siz] = 0; - nrfx_uarte_tx(&_dbg_uart_inst, (uint8_t const*)_dbg_pbuf, siz); - data += siz; - length -= siz; + siz = length; + } + else { + siz = DBG_PBUF_LEN; + } + memcpy(_dbg_pbuf, data, siz); + _dbg_pbuf[siz] = 0; + nrfx_uarte_tx(&_dbg_uart_inst, (uint8_t const*)_dbg_pbuf, siz); + data += siz; + length -= siz; } } @@ -113,7 +113,7 @@ int dbg_check_RTCprescaler(void) { NRF_RTC_Type *r = rtc_instance.p_reg; if ((int)r->PRESCALER == 0) { dbg_printf("****** PRESCALER == 0\r\n"); - return -1; + return -1; } return 0; } @@ -135,20 +135,20 @@ void dbg_dump_GPIOregs(void) { const char cnf_sense_chr[] = "-?HL"; // sense high, sense low for(port=0, col=0; port<=1; ++port) { for(i=0; i<32; ++i) { - uint32_t cnf = gpio[port]->PIN_CNF[i]; - if (cnf != 0x0002) { // changed from default value - dbg_printf("[%d_%02d]:%c%c%c%d%c ", port, i, - (cnf & 1) ? 'O' : 'I', // output, input - (cnf & 2) ? 'd' : 'c', // disconnected, connected - cnf_pull_chr[(cnf >> 2) & 3], - (int)((cnf >> 8) & 7), // drive config 0-7 - cnf_sense_chr[(cnf >> 16) & 3]); - if (++col >= 6) { - dbg_printf("\r\n"); - col = 0; - } - } - } + uint32_t cnf = gpio[port]->PIN_CNF[i]; + if (cnf != 0x0002) { // changed from default value + dbg_printf("[%d_%02d]:%c%c%c%d%c ", port, i, + (cnf & 1) ? 'O' : 'I', // output, input + (cnf & 2) ? 'd' : 'c', // disconnected, connected + cnf_pull_chr[(cnf >> 2) & 3], + (int)((cnf >> 8) & 7), // drive config 0-7 + cnf_sense_chr[(cnf >> 16) & 3]); + if (++col >= 6) { + dbg_printf("\r\n"); + col = 0; + } + } + } } if (col > 0) dbg_printf("\r\n"); @@ -159,26 +159,26 @@ void dbg_dump_GPIOregs(void) { const char config_outinit_chr[] = "01"; // initial value is 0 or 1 for(i=0, col=0; i<8; ++i) { uint32_t conf = reg->CONFIG[i]; - if (conf != 0) { // changed from default value - dbg_printf("CONFIG[%d]:%d_%02d,%c%c%c ", i, - (int)((conf >> 13) & 1), (int)((conf >> 8) & 0x1F), - config_mode_chr[conf & 3], - config_pol_chr[(conf >> 16) & 3], - (conf & 3) == 3 ? - config_outinit_chr[(conf >> 20) & 1] : '-'); - if (++col >= 4) { - dbg_printf("\r\n"); - col = 0; - } - } + if (conf != 0) { // changed from default value + dbg_printf("CONFIG[%d]:%d_%02d,%c%c%c ", i, + (int)((conf >> 13) & 1), (int)((conf >> 8) & 0x1F), + config_mode_chr[conf & 3], + config_pol_chr[(conf >> 16) & 3], + (conf & 3) == 3 ? + config_outinit_chr[(conf >> 20) & 1] : '-'); + if (++col >= 4) { + dbg_printf("\r\n"); + col = 0; + } + } } if (col > 0) dbg_printf("\r\n"); for(i=0; i<8; ++i) { dbg_printf("EVENTS_IN[%d]:%X ", i, (int)(reg->EVENTS_IN[i])); - if ((i & 3) == 3) dbg_printf("\r\n"); + if ((i & 3) == 3) dbg_printf("\r\n"); } dbg_printf("EVENTS_PORT:%X INTENSET:%08X\r\n", - (int)(reg->EVENTS_PORT), (int)(reg->INTENSET)); + (int)(reg->EVENTS_PORT), (int)(reg->INTENSET)); } void dbg_dumpQSPIreg(void) { @@ -186,13 +186,13 @@ void dbg_dumpQSPIreg(void) { dbg_printf("QSPI\r\n"); r = NRF_QSPI->IFCONFIG0; dbg_printf("IFCONFIG0 READ=%ld write=%ld ADDR=%ld DPM=%ld PPSIZE=%ld\r\n", - r & 7, (r >> 3) & 7, (r >> 6) & 1, (r >> 7) & 1, (r >> 12) & 1); + r & 7, (r >> 3) & 7, (r >> 6) & 1, (r >> 7) & 1, (r >> 12) & 1); r = NRF_QSPI->IFCONFIG1; dbg_printf("IFCONFIG1 SCKDELAY=%ld SPIMODE=%ld SCKFREQ=%ld\r\n", - r & 0xFF, (r >> 25) & 1, (r >> 28) & 0xF); + r & 0xFF, (r >> 25) & 1, (r >> 28) & 0xF); r = NRF_QSPI->STATUS; dbg_printf("STATUS DPM=%ld READY=%ld SREG=0x%02lX\r\n", - (r >> 2) & 1, (r >> 3) & 1, (r >> 24) & 0xFF); + (r >> 2) & 1, (r >> 3) & 1, (r >> 24) & 0xFF); r = NRF_QSPI->DPMDUR; dbg_printf("DPMDUR ENTER=%ld EXIT=%ld\r\n", r & 0xFFFF, (r >> 16) & 0xFFFF); } diff --git a/ports/nrf/supervisor/qspi_flash.c b/ports/nrf/supervisor/qspi_flash.c index f2beb3e3a9..6d1bec4422 100644 --- a/ports/nrf/supervisor/qspi_flash.c +++ b/ports/nrf/supervisor/qspi_flash.c @@ -281,7 +281,7 @@ void qspi_flash_enter_sleep(void) { // set sck_delay tempolarily r = NRF_QSPI->IFCONFIG1; sck_delay_saved = (r & QSPI_IFCONFIG1_SCKDELAY_Msk) - >> QSPI_IFCONFIG1_SCKDELAY_Pos; + >> QSPI_IFCONFIG1_SCKDELAY_Pos; NRF_QSPI->IFCONFIG1 = (NRF_QSPI->IFCONFIG1 & ~QSPI_IFCONFIG1_SCKDELAY_Msk) | (SCK_DELAY << QSPI_IFCONFIG1_SCKDELAY_Pos); @@ -312,20 +312,20 @@ void qspi_flash_exit_sleep(void) { if (NRF_QSPI->STATUS & QSPI_STATUS_DPM_Msk) { // exit deep power-down mode NRF_QSPI->IFCONFIG1 &= ~QSPI_IFCONFIG1_DPMEN_Msk; - NRFX_DELAY_US(WAIT_AFTER_DPM_EXIT); + NRFX_DELAY_US(WAIT_AFTER_DPM_EXIT); - if (NRF_QSPI->STATUS & QSPI_STATUS_DPM_Msk) { + if (NRF_QSPI->STATUS & QSPI_STATUS_DPM_Msk) { #ifdef NRF_DEBUG_PRINT - dbg_printf("qspi flash: exiting DPM failed\r\n"); + dbg_printf("qspi flash: exiting DPM failed\r\n"); #endif - } - // restore sck_delay - if (sck_delay_saved == 0) { - sck_delay_saved = 10; // default - } - NRF_QSPI->IFCONFIG1 - = (NRF_QSPI->IFCONFIG1 & ~QSPI_IFCONFIG1_SCKDELAY_Msk) - | (sck_delay_saved << QSPI_IFCONFIG1_SCKDELAY_Pos); + } + // restore sck_delay + if (sck_delay_saved == 0) { + sck_delay_saved = 10; // default + } + NRF_QSPI->IFCONFIG1 + = (NRF_QSPI->IFCONFIG1 & ~QSPI_IFCONFIG1_SCKDELAY_Msk) + | (sck_delay_saved << QSPI_IFCONFIG1_SCKDELAY_Pos); } //dbg_dumpQSPIreg(); #endif From 779169da266cc52759596cf8e25ae18e5e8f7e8d Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Wed, 21 Apr 2021 13:43:10 -0400 Subject: [PATCH 046/103] Reduce Simmel size --- ports/nrf/boards/simmel/mpconfigboard.mk | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ports/nrf/boards/simmel/mpconfigboard.mk b/ports/nrf/boards/simmel/mpconfigboard.mk index e6750877b2..e235fd1051 100644 --- a/ports/nrf/boards/simmel/mpconfigboard.mk +++ b/ports/nrf/boards/simmel/mpconfigboard.mk @@ -16,6 +16,7 @@ CIRCUITPY_AUDIOMP3 = 0 CIRCUITPY_BITMAPTOOLS = 0 CIRCUITPY_BUSDEVICE = 0 CIRCUITPY_BUSIO = 1 +CIRCUITPY_COUNTIO = 0 CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_ERRNO = 0 CIRCUITPY_FRAMEBUFFERIO = 0 @@ -24,10 +25,13 @@ CIRCUITPY_MSGPACK = 0 CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_NVM = 0 CIRCUITPY_PIXELBUF = 0 +CIRCUITPY_PULSEIO = 0 +CIRCUITPY_PWMIO = 1 CIRCUITPY_RGBMATRIX = 0 CIRCUITPY_ROTARYIO = 0 CIRCUITPY_RTC = 1 CIRCUITPY_SDCARDIO = 0 +CIRCUITPY_SYNTHIO = 0 CIRCUITPY_TOUCHIO = 0 CIRCUITPY_ULAB = 0 CIRCUITPY_USB_CDC = 0 From beb7e33db333fdb21653e81f56ae8a676120fa82 Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Wed, 21 Apr 2021 16:34:03 -0400 Subject: [PATCH 047/103] Fix attribution and revert changes to main --- main.c | 16 ++----------- ports/nrf/common-hal/alarm/SleepMemory.c | 3 +-- ports/nrf/common-hal/alarm/SleepMemory.h | 2 +- ports/nrf/common-hal/alarm/__init__.c | 8 ++++--- ports/nrf/common-hal/alarm/__init__.h | 2 +- ports/nrf/common-hal/alarm/pin/PinAlarm.c | 3 +-- ports/nrf/common-hal/alarm/pin/PinAlarm.h | 2 +- ports/nrf/common-hal/alarm/time/TimeAlarm.c | 2 +- ports/nrf/common-hal/alarm/time/TimeAlarm.h | 2 +- ports/nrf/supervisor/debug_uart.c | 25 +++++++++++++++++++-- 10 files changed, 37 insertions(+), 28 deletions(-) diff --git a/main.c b/main.c index d16db235e8..7020ab3851 100755 --- a/main.c +++ b/main.c @@ -404,8 +404,8 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { new_status_color(BLACK); board_deinit(); if (!supervisor_workflow_active()) { - // Enter deep sleep. When we wake up we'll return from - // this loop. + // Enter true deep sleep. When we wake up we'll be back at the + // top of main(), not in this loop. common_hal_alarm_enter_deep_sleep(); // Does not return. } else { @@ -426,18 +426,6 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { #if CIRCUITPY_ALARM common_hal_alarm_pretending_deep_sleep(); - bool serial_in = (serial_connected() && - serial_bytes_available()); - supervisor_set_run_reason(RUN_REASON_STARTUP); - board_init(); - if (serial_in) { - bool ctrl_d = serial_read() == CHAR_CTRL_D; - if (ctrl_d) { - supervisor_set_run_reason(RUN_REASON_REPL_RELOAD); - } - return ctrl_d; - } - return true; #else port_idle_until_interrupt(); #endif diff --git a/ports/nrf/common-hal/alarm/SleepMemory.c b/ports/nrf/common-hal/alarm/SleepMemory.c index e87fcd7991..a27fb88e4c 100644 --- a/ports/nrf/common-hal/alarm/SleepMemory.c +++ b/ports/nrf/common-hal/alarm/SleepMemory.c @@ -3,8 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2020 microDev - * Copyright (c) 2020 Dan Halbert for Adafruit Industries + * Copyright (c) 2021 Jun2Sak * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/alarm/SleepMemory.h b/ports/nrf/common-hal/alarm/SleepMemory.h index 11cc4a8fb9..816f4f492b 100644 --- a/ports/nrf/common-hal/alarm/SleepMemory.h +++ b/ports/nrf/common-hal/alarm/SleepMemory.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2020 Dan Halbert for Adafruit Industries + * Copyright (c) 2021 Jun2Sak * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index aabb27ef25..f60a33ca4c 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -3,8 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries - * Copyright (c) 2020 Dan Halbert for Adafruit Industries + * Copyright (c) 2021 Jun2Sak * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -167,6 +166,9 @@ STATIC void _setup_sleep_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t alarm_touch_touchalarm_set_alarm(deep_sleep, n_alarms, alarms); } +// TODO: this handles all possible types of wakeup, which is redundant with main. +// revise to extract all parts essential to enabling sleep wakeup, but leave the +// alarm/non-alarm sorting to the existing main loop. nrf_sleep_source_t system_on_idle_until_alarm(int64_t timediff_ms, uint32_t prescaler) { bool have_timeout = false; uint64_t start_tick = 0, end_tick = 0; @@ -382,7 +384,7 @@ void common_hal_alarm_pretending_deep_sleep(void) { print_wakeup_cause(cause); #endif - alarm_reset(); + // alarm_reset(); #if 0 // if one of Alarm event occurred, reset myself diff --git a/ports/nrf/common-hal/alarm/__init__.h b/ports/nrf/common-hal/alarm/__init__.h index ce8ca5f327..2473ab64a1 100644 --- a/ports/nrf/common-hal/alarm/__init__.h +++ b/ports/nrf/common-hal/alarm/__init__.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2020 Dan Halbert for Adafruit Industries. + * Copyright (c) 2021 Jun2Sak * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/alarm/pin/PinAlarm.c b/ports/nrf/common-hal/alarm/pin/PinAlarm.c index 89ec2ad30f..b6293ad1c5 100644 --- a/ports/nrf/common-hal/alarm/pin/PinAlarm.c +++ b/ports/nrf/common-hal/alarm/pin/PinAlarm.c @@ -3,8 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2020 Dan Halbert for Adafruit Industries - * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2021 Jun2Sak * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/alarm/pin/PinAlarm.h b/ports/nrf/common-hal/alarm/pin/PinAlarm.h index 93672c1f2d..0b7401669f 100644 --- a/ports/nrf/common-hal/alarm/pin/PinAlarm.h +++ b/ports/nrf/common-hal/alarm/pin/PinAlarm.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2020 Dan Halbert for Adafruit Industries + * Copyright (c) 2021 Jun2Sak * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/alarm/time/TimeAlarm.c b/ports/nrf/common-hal/alarm/time/TimeAlarm.c index c4b06982bf..c6a79cbbc9 100644 --- a/ports/nrf/common-hal/alarm/time/TimeAlarm.c +++ b/ports/nrf/common-hal/alarm/time/TimeAlarm.c @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2020 Dan Halbert for Adafruit Industries + * Copyright (c) 2021 Jun2Sak * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/alarm/time/TimeAlarm.h b/ports/nrf/common-hal/alarm/time/TimeAlarm.h index a824c52535..61938210a2 100644 --- a/ports/nrf/common-hal/alarm/time/TimeAlarm.h +++ b/ports/nrf/common-hal/alarm/time/TimeAlarm.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2020 Dan Halbert for Adafruit Industries + * Copyright (c) 2021 Jun2Sak * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/supervisor/debug_uart.c b/ports/nrf/supervisor/debug_uart.c index 420ba14b82..9cf33279f7 100644 --- a/ports/nrf/supervisor/debug_uart.c +++ b/ports/nrf/supervisor/debug_uart.c @@ -1,6 +1,27 @@ /* - * debug functions - * (will be removed) + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Jun2Sak + * + * 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 From 07059dd373ccc7d58452bc23c4d4c373132b3436 Mon Sep 17 00:00:00 2001 From: James Carr Date: Fri, 23 Apr 2021 12:56:44 +0100 Subject: [PATCH 048/103] Minor docs fixes in displayio.Bitmap --- shared-bindings/displayio/Bitmap.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index 900428b6e4..db9b430ba7 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -45,11 +45,11 @@ //| the bitmap data is packed into the memoryview with unspecified padding. //| //| A Bitmap can be treated as a buffer, allowing its content to be -//| viewed and modified using e.g., with ``ulab.numpy.frombuffer``, +//| viewed and modified using e.g., with `ulab.numpy.frombuffer`, //| but the `displayio.Bitmap.dirty` method must be used to inform //| displayio when a bitmap was modified through the buffer interface. //| -//| `bitmaptools.arrayblit` can also be useful to omve data efficiently +//| `bitmaptools.arrayblit` can also be useful to move data efficiently //| into a Bitmap. //| """ //| @@ -125,7 +125,7 @@ const mp_obj_property_t displayio_bitmap_height_obj = { //| def __getitem__(self, index: Union[Tuple[int, int], int]) -> int: //| """Returns the value at the given index. The index can either be an x,y tuple or an int equal -//| to ``y * width + x``. +//| to `y * width + x`. //| //| This allows you to:: //| @@ -134,7 +134,7 @@ const mp_obj_property_t displayio_bitmap_height_obj = { //| //| def __setitem__(self, index: Union[Tuple[int, int], int], value: int) -> None: //| """Sets the value at the given index. The index can either be an x,y tuple or an int equal -//| to ``y * width + x``. +//| to `y * width + x`. //| //| This allows you to:: //| From 0be610fd2bce8465ad5ab25ce0bf3723673374fa Mon Sep 17 00:00:00 2001 From: James Carr Date: Fri, 23 Apr 2021 14:41:47 +0100 Subject: [PATCH 049/103] Changes as requested for Bitmap docs. --- shared-bindings/displayio/Bitmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index db9b430ba7..f85666cae6 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -45,7 +45,7 @@ //| the bitmap data is packed into the memoryview with unspecified padding. //| //| A Bitmap can be treated as a buffer, allowing its content to be -//| viewed and modified using e.g., with `ulab.numpy.frombuffer`, +//| viewed and modified using e.g., with ``ulab.numpy.frombuffer``, //| but the `displayio.Bitmap.dirty` method must be used to inform //| displayio when a bitmap was modified through the buffer interface. //| @@ -125,7 +125,7 @@ const mp_obj_property_t displayio_bitmap_height_obj = { //| def __getitem__(self, index: Union[Tuple[int, int], int]) -> int: //| """Returns the value at the given index. The index can either be an x,y tuple or an int equal -//| to `y * width + x`. +//| to ``y * width + x``. //| //| This allows you to:: //| @@ -134,7 +134,7 @@ const mp_obj_property_t displayio_bitmap_height_obj = { //| //| def __setitem__(self, index: Union[Tuple[int, int], int], value: int) -> None: //| """Sets the value at the given index. The index can either be an x,y tuple or an int equal -//| to `y * width + x`. +//| to ``y * width + x``. //| //| This allows you to:: //| From 901e6ab5b031493ce79c6a9f23da9bb8644f9e10 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Fri, 23 Apr 2021 10:02:24 -0400 Subject: [PATCH 050/103] Referencing_documentation_other_libraries --- docs/design_guide.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index 1bac4df61b..5bd6bbd387 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -383,6 +383,14 @@ Renders as: :param float degrees: Degrees to turn right +Documentation References to other Libraries +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +When you need to make references to documentation in other libraries you should refer the class using single +backticks ``:class:`~adafruit_motor.servo.Servo```. You must add also the reference in the ``conf.py`` file in the +``intersphinx_mapping section`` adding a new entry:: + + "adafruit_motor": ("https://circuitpython.readthedocs.io/projects/motor/en/latest/", None,), + Use BusDevice -------------------------------------------------------------------------------- From a17fcb6d1ab05ff2e6a984e992462130c17812fc Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 25 Apr 2021 19:19:11 +0900 Subject: [PATCH 052/103] add copyright notice. remove obsolete comments. --- ports/nrf/common-hal/alarm/__init__.c | 19 ++++++------------- ports/nrf/common-hal/alarm/__init__.h | 1 + ports/nrf/common-hal/alarm/pin/PinAlarm.c | 1 + ports/nrf/common-hal/alarm/time/TimeAlarm.c | 4 +--- ports/nrf/supervisor/port.c | 1 + supervisor/shared/serial.c | 6 +++--- 6 files changed, 13 insertions(+), 19 deletions(-) diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index c8180fb2e0..f678b5f22b 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -5,6 +5,7 @@ * * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries * Copyright (c) 2020 Dan Halbert for Adafruit Industries + * Copyright (c) 2021 Junji Sakai * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -119,11 +120,6 @@ bool common_hal_alarm_woken_from_sleep(void) { nrf_sleep_source_t alarm_woken_from_sleep_2(void) { nrf_sleep_source_t cause = _get_wakeup_cause(); -#ifdef NRF_DEBUG_PRINT - if (cause != NRF_SLEEP_WAKEUP_UNDEFINED) { - //print_wakeup_cause(cause); - } -#endif if (cause == NRF_SLEEP_WAKEUP_GPIO || cause == NRF_SLEEP_WAKEUP_TIMER || cause == NRF_SLEEP_WAKEUP_TOUCHPAD) { @@ -136,9 +132,6 @@ nrf_sleep_source_t alarm_woken_from_sleep_2(void) { STATIC mp_obj_t _get_wake_alarm(size_t n_alarms, const mp_obj_t *alarms) { nrf_sleep_source_t cause = _get_wakeup_cause(); -#ifdef NRF_DEBUG_PRINT - //print_wakeup_cause(cause); -#endif switch (cause) { case NRF_SLEEP_WAKEUP_TIMER: { return alarm_time_timealarm_get_wakeup_alarm(n_alarms, alarms); @@ -264,16 +257,16 @@ nrf_sleep_source_t system_on_idle_until_alarm(int64_t timediff_ms, uint32_t pres qspi_flash_exit_sleep(); #endif +#ifdef NRF_DEBUG_PRINT tickdiff = port_get_raw_ticks(NULL) - start_tick; + double sec; if (prescaler == 0) { - timediff_ms = tickdiff / 1024; + sec = (double)tickdiff / 1024; } else { - timediff_ms = tickdiff * prescaler / 1024; + sec = (double)(tickdiff * prescaler) / 1024; } - (void)timediff_ms; -#ifdef NRF_DEBUG_PRINT - dbg_printf("lapse %6.1f sec\r\n", (double)(timediff_ms)); + dbg_printf("lapse %6.1f sec\r\n", sec); #endif return wakeup_cause; diff --git a/ports/nrf/common-hal/alarm/__init__.h b/ports/nrf/common-hal/alarm/__init__.h index 7df3aaf4c3..642fb7d93a 100644 --- a/ports/nrf/common-hal/alarm/__init__.h +++ b/ports/nrf/common-hal/alarm/__init__.h @@ -4,6 +4,7 @@ * The MIT License (MIT) * * Copyright (c) 2020 Dan Halbert for Adafruit Industries. + * Copyright (c) 2021 Junji Sakai * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/alarm/pin/PinAlarm.c b/ports/nrf/common-hal/alarm/pin/PinAlarm.c index 1f00dc0c33..fcfd02f84c 100644 --- a/ports/nrf/common-hal/alarm/pin/PinAlarm.c +++ b/ports/nrf/common-hal/alarm/pin/PinAlarm.c @@ -5,6 +5,7 @@ * * Copyright (c) 2020 Dan Halbert for Adafruit Industries * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2021 Junji Sakai * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/alarm/time/TimeAlarm.c b/ports/nrf/common-hal/alarm/time/TimeAlarm.c index c4b06982bf..09409e7ce4 100644 --- a/ports/nrf/common-hal/alarm/time/TimeAlarm.c +++ b/ports/nrf/common-hal/alarm/time/TimeAlarm.c @@ -4,6 +4,7 @@ * The MIT License (MIT) * * Copyright (c) 2020 Dan Halbert for Adafruit Industries + * Copyright (c) 2021 Junji Sakai * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -24,10 +25,7 @@ * THE SOFTWARE. */ -//#include "esp_sleep.h" - #include "py/runtime.h" -//#include "supervisor/esp_port.h" #include #include "common-hal/alarm/__init__.h" diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c index 5cad994c0d..c984feb77d 100644 --- a/ports/nrf/supervisor/port.c +++ b/ports/nrf/supervisor/port.c @@ -4,6 +4,7 @@ * The MIT License (MIT) * * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2021 Junji Sakai * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/supervisor/shared/serial.c b/supervisor/shared/serial.c index 41bb200afc..c73d702c9c 100644 --- a/supervisor/shared/serial.c +++ b/supervisor/shared/serial.c @@ -39,7 +39,7 @@ #ifdef NRF_DEBUG_PRINT // XXX these functions are in nrf/supervisor/debug_uart.c extern void _debug_uart_init(void); -extern void _debug_print_substr(const char* text, uint32_t length); +extern void _debug_print_substr(const char *text, uint32_t length); #endif /* @@ -71,7 +71,7 @@ void serial_early_init(void) { #endif #ifdef NRF_DEBUG_PRINT - _debug_uart_init(); + _debug_uart_init(); #endif } @@ -155,7 +155,7 @@ void serial_write_substring(const char *text, uint32_t length) { #if defined(DEBUG_UART_TX) && defined(DEBUG_UART_RX) int uart_errcode; - common_hal_busio_uart_write(&debug_uart, (const uint8_t*) text, length, &uart_errcode); + common_hal_busio_uart_write(&debug_uart, (const uint8_t *) text, length, &uart_errcode); #endif #ifdef NRF_DEBUG_PRINT From 7accb8b173ce97979e466bf3d2dc1e7f56300332 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 25 Apr 2021 19:57:21 +0900 Subject: [PATCH 053/103] modify copyright notice. --- .github/workflows/build.yml | 19 +- .github/workflows/match-build-fail.json | 14 ++ .gitmodules | 6 + conf.py | 2 + .../common-hal/_bleio/Characteristic.c | 4 + .../ble_hci/common-hal/_bleio/PacketBuffer.c | 16 +- .../ble_hci/common-hal/_bleio/PacketBuffer.h | 1 + docs/static/filter.css | 17 ++ docs/static/filter.js | 86 +++++++ frozen/Adafruit_CircuitPython_MIDI | 1 + frozen/Adafruit_CircuitPython_SimpleMath | 1 + lib/protomatter | 2 +- locale/ID.po | 74 +++--- locale/circuitpython.pot | 66 +++--- locale/cs.po | 59 +++-- locale/de_DE.po | 81 ++++--- locale/el.po | 59 +++-- locale/en_GB.po | 95 +++++--- locale/es.po | 97 +++++--- locale/fil.po | 62 ++--- locale/fr.po | 169 ++++++++------ locale/hi.po | 59 +++-- locale/it_IT.po | 64 +++--- locale/ja.po | 73 +++--- locale/ko.po | 59 +++-- locale/nl.po | 85 ++++--- locale/pl.po | 75 ++++--- locale/pt_BR.po | 92 +++++--- locale/sv.po | 89 +++++--- locale/zh_Latn_pinyin.po | 103 +++++---- main.c | 18 +- .../board.c | 0 .../mpconfigboard.h | 58 +++++ .../mpconfigboard.mk | 34 +++ .../boards/adafruit_neokey_trinkey_m0/pins.c | 8 + .../adafruit_proxlight_trinkey_m0/board.c | 40 ++++ .../mpconfigboard.h | 58 +++++ .../mpconfigboard.mk | 33 +++ .../adafruit_proxlight_trinkey_m0/pins.c | 15 ++ .../boards/adafruit_rotary_trinkey_m0/board.c | 40 ++++ .../mpconfigboard.h | 0 .../mpconfigboard.mk | 2 +- .../pins.c | 0 .../boards/adafruit_slide_trinkey_m0/board.c | 40 ++++ .../adafruit_slide_trinkey_m0/mpconfigboard.h | 58 +++++ .../mpconfigboard.mk | 35 +++ .../boards/adafruit_slide_trinkey_m0/pins.c | 8 + .../feather_m0_adalogger/mpconfigboard.h | 4 +- .../neopixel_trinkey_m0/mpconfigboard.mk | 2 +- ports/atmel-samd/boards/sensebox_mcu/board.c | 39 ++++ .../boards/sensebox_mcu/mpconfigboard.h | 24 ++ .../boards/sensebox_mcu/mpconfigboard.mk | 14 ++ ports/atmel-samd/boards/sensebox_mcu/pins.c | 71 ++++++ ports/atmel-samd/mpconfigport.mk | 20 ++ .../esp32s2/boards/atmegazero_esp32s2/board.c | 61 +++++ .../boards/atmegazero_esp32s2/mpconfigboard.h | 47 ++++ .../atmegazero_esp32s2/mpconfigboard.mk | 15 ++ .../esp32s2/boards/atmegazero_esp32s2/pins.c | 80 +++++++ .../boards/atmegazero_esp32s2/sdkconfig | 39 ++++ ports/nrf/boards/aramcon2_badge/board.c | 40 ++++ .../nrf/boards/aramcon2_badge/mpconfigboard.h | 68 ++++++ .../boards/aramcon2_badge/mpconfigboard.mk | 11 + ports/nrf/boards/aramcon2_badge/pins.c | 42 ++++ ports/nrf/boards/pca10100/mpconfigboard.mk | 1 + ports/nrf/boards/simmel/mpconfigboard.mk | 5 + ports/nrf/common-hal/_bleio/Characteristic.c | 4 + ports/nrf/common-hal/_bleio/PacketBuffer.c | 34 ++- ports/nrf/common-hal/_bleio/PacketBuffer.h | 1 + ports/nrf/common-hal/alarm/SleepMemory.c | 25 +-- ports/nrf/common-hal/alarm/SleepMemory.h | 2 +- ports/nrf/common-hal/alarm/__init__.c | 111 ++++----- ports/nrf/common-hal/alarm/__init__.h | 14 +- ports/nrf/common-hal/alarm/pin/PinAlarm.c | 26 +-- ports/nrf/common-hal/alarm/pin/PinAlarm.h | 2 +- ports/nrf/common-hal/alarm/time/TimeAlarm.h | 2 +- .../common-hal/microcontroller/Processor.c | 6 +- ports/nrf/mpconfigport.mk | 2 +- ports/nrf/supervisor/debug_uart.c | 129 ++++++----- ports/nrf/supervisor/port.c | 4 + ports/nrf/supervisor/qspi_flash.c | 24 +- .../boards/pimoroni_picolipo_16mb/board.c | 37 +++ .../pimoroni_picolipo_16mb/mpconfigboard.h | 10 + .../pimoroni_picolipo_16mb/mpconfigboard.mk | 11 + .../boards/pimoroni_picolipo_16mb/pins.c | 52 +++++ .../boards/pimoroni_picolipo_4mb/board.c | 37 +++ .../pimoroni_picolipo_4mb/mpconfigboard.h | 10 + .../pimoroni_picolipo_4mb/mpconfigboard.mk | 11 + .../boards/pimoroni_picolipo_4mb/pins.c | 52 +++++ .../boards/raspberry_pi_pico/pins.c | 10 + .../boards/sparkfun_micromod_rp2040/board.c | 40 ++++ .../sparkfun_micromod_rp2040/mpconfigboard.h | 12 + .../sparkfun_micromod_rp2040/mpconfigboard.mk | 9 + .../boards/sparkfun_micromod_rp2040/pins.c | 105 +++++++++ ports/raspberrypi/mpconfigport.mk | 3 +- .../mpconfigboard.mk | 2 + py/binary.c | 6 +- py/circuitpy_defns.mk | 5 + py/circuitpy_mpconfig.h | 8 + py/circuitpy_mpconfig.mk | 3 + py/compile.c | 2 +- py/makeqstrdata.py | 50 ++--- py/modstruct.c | 6 +- py/mpstate.h | 2 +- py/qstr.c | 130 ++++++----- py/qstr.h | 20 +- py/repl.c | 13 +- shared-bindings/_bleio/Characteristic.c | 17 ++ shared-bindings/_bleio/Characteristic.h | 1 + shared-bindings/_bleio/PacketBuffer.c | 20 +- shared-bindings/_bleio/PacketBuffer.h | 2 +- shared-bindings/_typing/__init__.pyi | 3 +- shared-bindings/audiocore/RawSample.c | 26 +-- shared-bindings/audiocore/RawSample.h | 1 - shared-bindings/audiocore/WaveFile.c | 2 +- shared-bindings/support_matrix.rst | 5 + shared-bindings/synthio/MidiTrack.c | 169 ++++++++++++++ shared-bindings/synthio/MidiTrack.h | 43 ++++ shared-bindings/synthio/__init__.c | 136 +++++++++++ shared-bindings/synthio/__init__.h | 34 +++ shared-module/audiomixer/Mixer.c | 45 ++++ shared-module/struct/__init__.c | 6 +- shared-module/synthio/MidiTrack.c | 212 ++++++++++++++++++ shared-module/synthio/MidiTrack.h | 65 ++++++ shared-module/synthio/__init__.c | 0 shared-module/synthio/__init__.h | 32 +++ supervisor/shared/cpu.c | 40 ++++ supervisor/shared/cpu.h | 36 +++ supervisor/shared/safe_mode.c | 6 +- supervisor/shared/serial.c | 11 +- supervisor/shared/translate.c | 2 +- supervisor/supervisor.mk | 1 + tests/basics/struct1.py | 2 + .../audiocore/single-track.midi | Bin 0 -> 5123 bytes tools/build_board_info.py | 2 +- tools/mpy-tool.py | 27 ++- 135 files changed, 3646 insertions(+), 992 deletions(-) create mode 100644 .github/workflows/match-build-fail.json create mode 100644 docs/static/filter.css create mode 100644 docs/static/filter.js create mode 160000 frozen/Adafruit_CircuitPython_MIDI create mode 160000 frozen/Adafruit_CircuitPython_SimpleMath rename ports/atmel-samd/boards/{rotary_trinkey_m0 => adafruit_neokey_trinkey_m0}/board.c (100%) create mode 100644 ports/atmel-samd/boards/adafruit_neokey_trinkey_m0/mpconfigboard.h create mode 100644 ports/atmel-samd/boards/adafruit_neokey_trinkey_m0/mpconfigboard.mk create mode 100644 ports/atmel-samd/boards/adafruit_neokey_trinkey_m0/pins.c create mode 100644 ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/board.c create mode 100644 ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/mpconfigboard.h create mode 100644 ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/mpconfigboard.mk create mode 100644 ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/pins.c create mode 100644 ports/atmel-samd/boards/adafruit_rotary_trinkey_m0/board.c rename ports/atmel-samd/boards/{rotary_trinkey_m0 => adafruit_rotary_trinkey_m0}/mpconfigboard.h (100%) rename ports/atmel-samd/boards/{rotary_trinkey_m0 => adafruit_rotary_trinkey_m0}/mpconfigboard.mk (97%) rename ports/atmel-samd/boards/{rotary_trinkey_m0 => adafruit_rotary_trinkey_m0}/pins.c (100%) create mode 100644 ports/atmel-samd/boards/adafruit_slide_trinkey_m0/board.c create mode 100644 ports/atmel-samd/boards/adafruit_slide_trinkey_m0/mpconfigboard.h create mode 100644 ports/atmel-samd/boards/adafruit_slide_trinkey_m0/mpconfigboard.mk create mode 100644 ports/atmel-samd/boards/adafruit_slide_trinkey_m0/pins.c create mode 100644 ports/atmel-samd/boards/sensebox_mcu/board.c create mode 100644 ports/atmel-samd/boards/sensebox_mcu/mpconfigboard.h create mode 100644 ports/atmel-samd/boards/sensebox_mcu/mpconfigboard.mk create mode 100644 ports/atmel-samd/boards/sensebox_mcu/pins.c create mode 100644 ports/esp32s2/boards/atmegazero_esp32s2/board.c create mode 100644 ports/esp32s2/boards/atmegazero_esp32s2/mpconfigboard.h create mode 100644 ports/esp32s2/boards/atmegazero_esp32s2/mpconfigboard.mk create mode 100644 ports/esp32s2/boards/atmegazero_esp32s2/pins.c create mode 100644 ports/esp32s2/boards/atmegazero_esp32s2/sdkconfig create mode 100644 ports/nrf/boards/aramcon2_badge/board.c create mode 100644 ports/nrf/boards/aramcon2_badge/mpconfigboard.h create mode 100644 ports/nrf/boards/aramcon2_badge/mpconfigboard.mk create mode 100644 ports/nrf/boards/aramcon2_badge/pins.c create mode 100644 ports/raspberrypi/boards/pimoroni_picolipo_16mb/board.c create mode 100644 ports/raspberrypi/boards/pimoroni_picolipo_16mb/mpconfigboard.h create mode 100644 ports/raspberrypi/boards/pimoroni_picolipo_16mb/mpconfigboard.mk create mode 100644 ports/raspberrypi/boards/pimoroni_picolipo_16mb/pins.c create mode 100644 ports/raspberrypi/boards/pimoroni_picolipo_4mb/board.c create mode 100644 ports/raspberrypi/boards/pimoroni_picolipo_4mb/mpconfigboard.h create mode 100644 ports/raspberrypi/boards/pimoroni_picolipo_4mb/mpconfigboard.mk create mode 100644 ports/raspberrypi/boards/pimoroni_picolipo_4mb/pins.c create mode 100644 ports/raspberrypi/boards/sparkfun_micromod_rp2040/board.c create mode 100644 ports/raspberrypi/boards/sparkfun_micromod_rp2040/mpconfigboard.h create mode 100644 ports/raspberrypi/boards/sparkfun_micromod_rp2040/mpconfigboard.mk create mode 100644 ports/raspberrypi/boards/sparkfun_micromod_rp2040/pins.c create mode 100644 shared-bindings/synthio/MidiTrack.c create mode 100644 shared-bindings/synthio/MidiTrack.h create mode 100644 shared-bindings/synthio/__init__.c create mode 100644 shared-bindings/synthio/__init__.h create mode 100644 shared-module/synthio/MidiTrack.c create mode 100644 shared-module/synthio/MidiTrack.h create mode 100644 shared-module/synthio/__init__.c create mode 100644 shared-module/synthio/__init__.h create mode 100644 supervisor/shared/cpu.c create mode 100644 supervisor/shared/cpu.h create mode 100755 tests/circuitpython-manual/audiocore/single-track.midi diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dce5388211..6d58085929 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -178,8 +178,13 @@ jobs: - "TG-Watch" - "adafruit_feather_rp2040" - "adafruit_itsybitsy_rp2040" + - "adafruit_neokey_trinkey_m0" + - "adafruit_proxlight_trinkey_m0" - "adafruit_qtpy_rp2040" + - "adafruit_rotary_trinkey_m0" + - "adafruit_slide_trinkey_m0" - "aloriumtech_evo_m51" + - "aramcon2_badge" - "aramcon_badge_2019" - "arduino_mkr1300" - "arduino_mkrzero" @@ -285,6 +290,8 @@ jobs: - "pewpew_m4" - "picoplanet" - "pimoroni_keybow2040" + - "pimoroni_picolipo_16mb" + - "pimoroni_picolipo_4mb" - "pimoroni_picosystem" - "pimoroni_tiny2040" - "pirkey_m0" @@ -305,17 +312,18 @@ jobs: - "raspberry_pi_pico" - "raytac_mdbt50q-db-40" - "robohatmm1_m4" - - "rotary_trinkey_m0" - "sam32" - "same54_xplained" - "seeeduino_wio_terminal" - "seeeduino_xiao" + - "sensebox_mcu" - "serpente" - "shirtty" - "silicognition-m4-shim" - "simmel" - "snekboard" - "sparkfun_lumidrive" + - "sparkfun_micromod_rp2040" - "sparkfun_nrf52840_micromod" - "sparkfun_nrf52840_mini" - "sparkfun_pro_micro_rp2040" @@ -375,6 +383,8 @@ jobs: python3 --version - name: mpy-cross run: make -C mpy-cross -j2 + - name: Setup build failure matcher + run: echo "::add-matcher::$GITHUB_WORKSPACE/.github/workflows/match-build-fail.json" - name: build run: python3 -u build_release_files.py working-directory: tools @@ -424,6 +434,8 @@ jobs: python3 --version - name: mpy-cross run: make -C mpy-cross -j2 + - name: Setup build failure matcher + run: echo "::add-matcher::$GITHUB_WORKSPACE/.github/workflows/match-build-fail.json" - name: build run: python3 -u build_release_files.py working-directory: tools @@ -453,6 +465,7 @@ jobs: - "adafruit_magtag_2.9_grayscale" - "adafruit_metro_esp32s2" - "artisense_rd00" + - "atmegazero_esp32s2" - "electroniccats_bastwifi" - "espressif_kaluga_1" - "espressif_saola_1_wroom" @@ -485,7 +498,7 @@ jobs: id: idf-cache with: path: ${{ github.workspace }}/.idf_tools - key: ${{ runner.os }}-idf-tools-${{ hashFiles('.git/modules/ports/esp32s2/esp-idf/HEAD') }}-20210304 + key: ${{ runner.os }}-idf-tools-${{ hashFiles('.git/modules/ports/esp32s2/esp-idf/HEAD') }}-20210415 - name: Clone IDF submodules run: | (cd $IDF_PATH && git submodule update --init) @@ -522,6 +535,8 @@ jobs: IDF_TOOLS_PATH: ${{ github.workspace }}/.idf_tools - name: mpy-cross run: make -C mpy-cross -j2 + - name: Setup build failure matcher + run: echo "::add-matcher::$GITHUB_WORKSPACE/.github/workflows/match-build-fail.json" - name: build run: | source $IDF_PATH/export.sh diff --git a/.github/workflows/match-build-fail.json b/.github/workflows/match-build-fail.json new file mode 100644 index 0000000000..938c484f26 --- /dev/null +++ b/.github/workflows/match-build-fail.json @@ -0,0 +1,14 @@ +{ + "problemMatcher": [ + { + "severity": "error", + "pattern": [ + { + "regexp": "^(Build .+ and \\x1b\\[31mfailed\\x1b\\[0m)$", + "message": 1 + } + ], + "owner": "build-failed" + } + ] +} diff --git a/.gitmodules b/.gitmodules index 52abb02a99..da5b5835a6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -171,6 +171,9 @@ [submodule "frozen/Adafruit_CircuitPython_LC709203F"] path = frozen/Adafruit_CircuitPython_LC709203F url = https://github.com/adafruit/Adafruit_CircuitPython_LC709203F +[submodule "frozen/Adafruit_CircuitPython_SimpleMath"] + path = frozen/Adafruit_CircuitPython_SimpleMath + url = https://github.com/adafruit/Adafruit_CircuitPython_SimpleMath [submodule "ports/raspberrypi/sdk"] path = ports/raspberrypi/sdk url = https://github.com/adafruit/pico-sdk.git @@ -178,3 +181,6 @@ path = data/nvm.toml url = https://github.com/adafruit/nvm.toml.git branch = main +[submodule "frozen/Adafruit_CircuitPython_MIDI"] + path = frozen/Adafruit_CircuitPython_MIDI + url = https://github.com/adafruit/Adafruit_CircuitPython_MIDI diff --git a/conf.py b/conf.py index 44f86f6361..2625ad63c1 100644 --- a/conf.py +++ b/conf.py @@ -489,6 +489,8 @@ class CoreModuleTransform(SphinxTransform): def setup(app): app.add_css_file("customstyle.css") + app.add_css_file("filter.css") + app.add_js_file("filter.js") app.add_config_value('redirects_file', 'redirects', 'env') app.connect('builder-inited', generate_redirects) app.add_transform(CoreModuleTransform) diff --git a/devices/ble_hci/common-hal/_bleio/Characteristic.c b/devices/ble_hci/common-hal/_bleio/Characteristic.c index 7255661576..db1317f4c8 100644 --- a/devices/ble_hci/common-hal/_bleio/Characteristic.c +++ b/devices/ble_hci/common-hal/_bleio/Characteristic.c @@ -78,6 +78,10 @@ bleio_service_obj_t *common_hal_bleio_characteristic_get_service(bleio_character return self->service; } +size_t common_hal_bleio_characteristic_get_max_length(bleio_characteristic_obj_t *self) { + return self->max_length; +} + size_t common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self, uint8_t *buf, size_t len) { // Do GATT operations only if this characteristic has been added to a registered service. if (self->handle != BLE_GATT_HANDLE_INVALID) { diff --git a/devices/ble_hci/common-hal/_bleio/PacketBuffer.c b/devices/ble_hci/common-hal/_bleio/PacketBuffer.c index 9d8a21601d..cb14f4044b 100644 --- a/devices/ble_hci/common-hal/_bleio/PacketBuffer.c +++ b/devices/ble_hci/common-hal/_bleio/PacketBuffer.c @@ -81,7 +81,7 @@ void bleio_packet_buffer_update(bleio_packet_buffer_obj_t *self, mp_buffer_info_ void common_hal_bleio_packet_buffer_construct( bleio_packet_buffer_obj_t *self, bleio_characteristic_obj_t *characteristic, - size_t buffer_size) { + size_t buffer_size, size_t max_packet_size) { self->characteristic = characteristic; self->client = self->characteristic->service->is_remote; @@ -101,7 +101,7 @@ void common_hal_bleio_packet_buffer_construct( } if (incoming) { - if (!ringbuf_alloc(&self->ringbuf, buffer_size * (sizeof(uint16_t) + characteristic->max_length), false)) { + if (!ringbuf_alloc(&self->ringbuf, buffer_size * (sizeof(uint16_t) + max_packet_size), false)) { mp_raise_ValueError(translate("Buffer too large and unable to allocate")); } } @@ -110,12 +110,13 @@ void common_hal_bleio_packet_buffer_construct( self->packet_queued = false; self->pending_index = 0; self->pending_size = 0; - self->outgoing[0] = m_malloc(characteristic->max_length, false); - self->outgoing[1] = m_malloc(characteristic->max_length, false); + self->outgoing[0] = m_malloc(max_packet_size, false); + self->outgoing[1] = m_malloc(max_packet_size, false); } else { self->outgoing[0] = NULL; self->outgoing[1] = NULL; } + self->max_packet_size = max_packet_size; bleio_characteristic_set_observer(self->characteristic, self); } @@ -243,15 +244,16 @@ mp_int_t common_hal_bleio_packet_buffer_get_outgoing_packet_length(bleio_packet_ if (self->conn_handle != BLE_CONN_HANDLE_INVALID) { bleio_connection_internal_t *connection = bleio_conn_handle_to_connection(self->conn_handle); if (connection) { - return MIN(common_hal_bleio_connection_get_max_packet_length(connection), - self->characteristic->max_length); + return MIN(MIN(common_hal_bleio_connection_get_max_packet_length(connection), + self->max_packet_size), + self->characteristic->max_length); } } // There's no current connection, so we don't know the MTU, and // we can't tell what the largest outgoing packet length would be. return -1; } - return self->characteristic->max_length; + return MIN(self->characteristic->max_length, self->max_packet_size); } bool common_hal_bleio_packet_buffer_deinited(bleio_packet_buffer_obj_t *self) { diff --git a/devices/ble_hci/common-hal/_bleio/PacketBuffer.h b/devices/ble_hci/common-hal/_bleio/PacketBuffer.h index 7f351929d5..34471741fe 100644 --- a/devices/ble_hci/common-hal/_bleio/PacketBuffer.h +++ b/devices/ble_hci/common-hal/_bleio/PacketBuffer.h @@ -42,6 +42,7 @@ typedef struct { // We remember the conn_handle so we can do a NOTIFY/INDICATE to a client. // We can find out the conn_handle on a Characteristic write or a CCCD write (but not a read). volatile uint16_t conn_handle; + uint16_t max_packet_size; uint8_t pending_index; uint8_t write_type; bool client; diff --git a/docs/static/filter.css b/docs/static/filter.css new file mode 100644 index 0000000000..12efe14a40 --- /dev/null +++ b/docs/static/filter.css @@ -0,0 +1,17 @@ +#support-matrix-filter-block { position: relative; } +#support-matrix-filter { + width: 100%; +} +#support-matrix-filter-num { + position: absolute; + right: 10px; + top: 4px; +} +.support-matrix-table .this_module code, +.support-matrix-table .this_module span { + background: black; + color: white; +} +.support-matrix-table .board_hidden { + display: none; +} diff --git a/docs/static/filter.js b/docs/static/filter.js new file mode 100644 index 0000000000..9dc46a9eed --- /dev/null +++ b/docs/static/filter.js @@ -0,0 +1,86 @@ +$(() => { + var urlTimeout = null; + function setURL(query, value) { + clearTimeout(urlTimeout); + + urlTimeout = setTimeout(function() { + var url = new URL(window.location.href); + console.log(query,value,value.length,!value.length); + if (!value.length) { + console.log + url.searchParams.delete(query); + } else if (Array.isArray(value)) { + url.searchParams.delete(query); + value.forEach(function(v) { + url.searchParams.append(query, v); + }) + } else { + url.searchParams.set(query, value); + } + + window.history.pushState(null, document.title, url.href); + }, 1000); + } + + function handlePageLoad() { + var url = new URL(window.location.href); + //get values from URL + var filters = url.searchParams.getAll('filter'); + search_terms = filters.join(" "); + $("#support-matrix-filter").val(search_terms); + run_filter(); + } + + function filter_boards(search_string) { + $(".board_hidden").removeClass("board_hidden"); + $(".this_module").removeClass("this_module"); + var nboards = $(".support-matrix-table tbody tr").length; + if(search_string.trim() == "") { + $("#support-matrix-filter-num").html("(all)"); + setURL("filter",[]); + return; + } + var list_search = search_string.split(" ").filter(i => i); + var nvisible = 0; + $(".support-matrix-table tbody tr").each( (index,item) => { + var name = $(item).find("td:first-child p").html(); + var modules = $(item).find("a.reference.internal"); + var matching_all = true; + // + list_search.forEach((sstring) => { + var matching = (sstring[0] == "-"); + for(var modi = 0; modi < modules.length; ++modi) { + module = modules[modi]; + var mod_name = module.firstChild.firstChild.textContent; + if(sstring[0] == "-") { + if(mod_name.match(sstring.substr(1))) { + matching = false; + break; + } + } else { + if(mod_name.match(sstring)) { + $(module).addClass("this_module"); + matching = true; + } + } + } + matching_all = matching_all && matching; + }); + if(!matching_all) { + $(item).addClass("board_hidden"); + } else { + nvisible += 1; + } + }); + $("#support-matrix-filter-num").html(`(${nvisible}/${nboards})`); + setURL("filter",list_search); + } + + function run_filter() { + var search_string = $("#support-matrix-filter").val(); + filter_boards(search_string); + } + $("#support-matrix-filter").on("keyup", run_filter); + // $(document).on("keyup", "#support-matrix-filter", run_filter); + handlePageLoad(); +}); diff --git a/frozen/Adafruit_CircuitPython_MIDI b/frozen/Adafruit_CircuitPython_MIDI new file mode 160000 index 0000000000..669ab7b752 --- /dev/null +++ b/frozen/Adafruit_CircuitPython_MIDI @@ -0,0 +1 @@ +Subproject commit 669ab7b752d6c863577312560faf505656e5e603 diff --git a/frozen/Adafruit_CircuitPython_SimpleMath b/frozen/Adafruit_CircuitPython_SimpleMath new file mode 160000 index 0000000000..cdf9944730 --- /dev/null +++ b/frozen/Adafruit_CircuitPython_SimpleMath @@ -0,0 +1 @@ +Subproject commit cdf99447307473080b2f2e95e7c3667247095ac0 diff --git a/lib/protomatter b/lib/protomatter index c2c81ded11..98017c5734 160000 --- a/lib/protomatter +++ b/lib/protomatter @@ -1 +1 @@ -Subproject commit c2c81ded118484f8925bf81e270b416739cd72d9 +Subproject commit 98017c57349e259fab70c6a7830436b19a55f6f4 diff --git a/locale/ID.po b/locale/ID.po index ad5700cb99..ea16feddb8 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -445,8 +445,8 @@ msgid "Attempt to allocate %d blocks" msgstr "" #: supervisor/shared/safe_mode.c -msgid "Attempted heap allocation when MicroPython VM not running." -msgstr "Mencoba alokasi heap ketika MicroPython VM tidak berjalan." +msgid "Attempted heap allocation when VM not running." +msgstr "" #: shared-bindings/wifi/Radio.c msgid "Authentication failure" @@ -899,6 +899,11 @@ msgstr "" msgid "EXTINT channel already in use" msgstr "Channel EXTINT sedang digunakan" +#: shared-module/synthio/MidiTrack.c +#, c-format +msgid "Error in MIDI stream at position %d" +msgstr "" + #: extmod/modure.c msgid "Error in regex" msgstr "Error pada regex" @@ -1028,6 +1033,10 @@ msgstr "Gagal melepaskan mutex, err 0x%04x" msgid "Failed to write internal flash." msgstr "Gagal menulis flash internal." +#: supervisor/shared/safe_mode.c +msgid "Fatal error." +msgstr "" + #: py/moduerrno.c msgid "File exists" msgstr "File sudah ada" @@ -1100,10 +1109,6 @@ msgstr "" msgid "I2SOut not available" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" -msgstr "" - #: shared-bindings/aesio/aes.c #, c-format msgid "IV must be %d bytes long" @@ -1229,6 +1234,10 @@ msgstr "" msgid "Invalid DAC pin supplied" msgstr "Pin DAC yang diberikan tidak valid" +#: shared-bindings/synthio/__init__.c +msgid "Invalid MIDI file" +msgstr "" + #: ports/atmel-samd/common-hal/pwmio/PWMOut.c #: ports/cxd56/common-hal/pwmio/PWMOut.c #: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c @@ -1420,14 +1429,6 @@ msgstr "Nilai x maksimum ketika dicerminkan adalah %d" msgid "Messages limited to 8 bytes" msgstr "" -#: supervisor/shared/safe_mode.c -msgid "MicroPython NLR jump failed. Likely memory corruption." -msgstr "Lompatan NLR MicroPython gagal. Kemungkinan kerusakan memori." - -#: supervisor/shared/safe_mode.c -msgid "MicroPython fatal error." -msgstr "Kesalahan fatal MicroPython." - #: shared-bindings/audiobusio/PDMIn.c msgid "Microphone startup delay must be in range 0.0 to 1.0" msgstr "Penundaan mulai mikrofon harus dalam kisaran 0,0 hingga 1,0" @@ -1479,6 +1480,10 @@ msgstr "Harus menyediakan pin MISO atau MOSI" msgid "Must use a multiple of 6 rgb pins, not %d" msgstr "Harus menggunakan kelipatan 6 pin rgb, bukan %d" +#: supervisor/shared/safe_mode.c +msgid "NLR jump failed. Likely memory corruption." +msgstr "" + #: ports/esp32s2/common-hal/nvm/ByteArray.c msgid "NVS Error" msgstr "" @@ -1623,6 +1628,7 @@ msgstr "" msgid "Not a valid IP string" msgstr "" +#: ports/nrf/common-hal/_bleio/PacketBuffer.c #: ports/nrf/common-hal/_bleio/__init__.c #: shared-bindings/_bleio/CharacteristicBuffer.c msgid "Not connected" @@ -1847,8 +1853,8 @@ msgstr "Buffer awalan harus ada di heap" #: main.c msgid "Press any key to enter the REPL. Use CTRL-D to reload.\n" msgstr "" -"Tekan sembarang tombol untuk masuk ke REPL. Tekan CTRL-D untuk memuat ulang." -"\n" +"Tekan sembarang tombol untuk masuk ke REPL. Tekan CTRL-D untuk memuat " +"ulang.\n" #: main.c msgid "Pretending to deep sleep until alarm, CTRL-C or file write.\n" @@ -2543,10 +2549,6 @@ msgstr "" msgid "buffer is smaller than requested size" msgstr "" -#: shared-bindings/audiocore/RawSample.c -msgid "buffer must be a bytes-like object" -msgstr "" - #: extmod/ulab/code/ulab_create.c extmod/ulab/code/utils/utils.c msgid "buffer size must be a multiple of element size" msgstr "" @@ -2988,7 +2990,7 @@ msgid "f-string: single '}' is not allowed" msgstr "" #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c -#: shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" msgstr "" @@ -3244,6 +3246,10 @@ msgstr "" msgid "invalid cert" msgstr "cert tidak valid" +#: py/compile.c +msgid "invalid decorator" +msgstr "" + #: extmod/uos_dupterm.c msgid "invalid dupterm index" msgstr "indeks dupterm tidak valid" @@ -3299,10 +3305,6 @@ msgstr "" msgid "invalid syntax for number" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "io must be rtc io" -msgstr "" - #: py/objtype.c msgid "issubclass() arg 1 must be a class" msgstr "" @@ -3763,6 +3765,7 @@ msgstr "" #: ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h #: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h #: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h +#: ports/esp32s2/boards/artisense_rd00/mpconfigboard.h #: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h #: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h #: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h @@ -3788,6 +3791,10 @@ msgstr "" msgid "pressing both buttons at start up.\n" msgstr "" +#: ports/nrf/boards/aramcon2_badge/mpconfigboard.h +msgid "pressing the left button at start up\n" +msgstr "" + #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "pull masks conflict with direction masks" msgstr "" @@ -4061,10 +4068,6 @@ msgstr "" msgid "trapz is defined for 1D arrays of equal length" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "trigger level must be 0 or 1" -msgstr "" - #: py/obj.c msgid "tuple/list has wrong length" msgstr "" @@ -4199,10 +4202,6 @@ msgstr "" msgid "value_count must be > 0" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "wakeup conflict" -msgstr "" - #: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c msgid "watchdog not initialized" msgstr "" @@ -4289,6 +4288,15 @@ msgstr "zi harus berjenis float" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "Attempted heap allocation when MicroPython VM not running." +#~ msgstr "Mencoba alokasi heap ketika MicroPython VM tidak berjalan." + +#~ msgid "MicroPython NLR jump failed. Likely memory corruption." +#~ msgstr "Lompatan NLR MicroPython gagal. Kemungkinan kerusakan memori." + +#~ msgid "MicroPython fatal error." +#~ msgstr "Kesalahan fatal MicroPython." + #~ msgid "Nordic Soft Device failure assertion." #~ msgstr "Pernyataan kegagalan Perangkat Lunak Nordic." diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 1245f17840..2a43daf014 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -309,10 +309,6 @@ msgstr "" msgid "Address type out of range" msgstr "" -#: ports/nrf/common-hal/alarm/time/TimeAlarm.c -msgid "Alarm time must be < 512 seconds." -msgstr "" - #: ports/esp32s2/common-hal/canio/CAN.c msgid "All CAN peripherals are in use" msgstr "" @@ -442,7 +438,7 @@ msgid "Attempt to allocate %d blocks" msgstr "" #: supervisor/shared/safe_mode.c -msgid "Attempted heap allocation when MicroPython VM not running." +msgid "Attempted heap allocation when VM not running." msgstr "" #: shared-bindings/wifi/Radio.c @@ -884,6 +880,11 @@ msgstr "" msgid "EXTINT channel already in use" msgstr "" +#: shared-module/synthio/MidiTrack.c +#, c-format +msgid "Error in MIDI stream at position %d" +msgstr "" + #: extmod/modure.c msgid "Error in regex" msgstr "" @@ -1013,6 +1014,10 @@ msgstr "" msgid "Failed to write internal flash." msgstr "" +#: supervisor/shared/safe_mode.c +msgid "Fatal error." +msgstr "" + #: py/moduerrno.c msgid "File exists" msgstr "" @@ -1085,10 +1090,6 @@ msgstr "" msgid "I2SOut not available" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" -msgstr "" - #: shared-bindings/aesio/aes.c #, c-format msgid "IV must be %d bytes long" @@ -1212,6 +1213,10 @@ msgstr "" msgid "Invalid DAC pin supplied" msgstr "" +#: shared-bindings/synthio/__init__.c +msgid "Invalid MIDI file" +msgstr "" + #: ports/atmel-samd/common-hal/pwmio/PWMOut.c #: ports/cxd56/common-hal/pwmio/PWMOut.c #: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c @@ -1404,14 +1409,6 @@ msgstr "" msgid "Messages limited to 8 bytes" msgstr "" -#: supervisor/shared/safe_mode.c -msgid "MicroPython NLR jump failed. Likely memory corruption." -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "MicroPython fatal error." -msgstr "" - #: shared-bindings/audiobusio/PDMIn.c msgid "Microphone startup delay must be in range 0.0 to 1.0" msgstr "" @@ -1463,6 +1460,10 @@ msgstr "" msgid "Must use a multiple of 6 rgb pins, not %d" msgstr "" +#: supervisor/shared/safe_mode.c +msgid "NLR jump failed. Likely memory corruption." +msgstr "" + #: ports/esp32s2/common-hal/nvm/ByteArray.c msgid "NVS Error" msgstr "" @@ -1607,6 +1608,7 @@ msgstr "" msgid "Not a valid IP string" msgstr "" +#: ports/nrf/common-hal/_bleio/PacketBuffer.c #: ports/nrf/common-hal/_bleio/__init__.c #: shared-bindings/_bleio/CharacteristicBuffer.c msgid "Not connected" @@ -2133,7 +2135,7 @@ msgid "Too many displays" msgstr "" #: ports/nrf/common-hal/_bleio/PacketBuffer.c -msgid "Total data to write is larger than outgoing_packet_length" +msgid "Total data to write is larger than %q" msgstr "" #: py/obj.c @@ -2500,10 +2502,6 @@ msgstr "" msgid "buffer is smaller than requested size" msgstr "" -#: shared-bindings/audiocore/RawSample.c -msgid "buffer must be a bytes-like object" -msgstr "" - #: extmod/ulab/code/ulab_create.c extmod/ulab/code/utils/utils.c msgid "buffer size must be a multiple of element size" msgstr "" @@ -2945,7 +2943,7 @@ msgid "f-string: single '}' is not allowed" msgstr "" #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c -#: shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" msgstr "" @@ -3201,6 +3199,10 @@ msgstr "" msgid "invalid cert" msgstr "" +#: py/compile.c +msgid "invalid decorator" +msgstr "" + #: extmod/uos_dupterm.c msgid "invalid dupterm index" msgstr "" @@ -3256,10 +3258,6 @@ msgstr "" msgid "invalid syntax for number" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "io must be rtc io" -msgstr "" - #: py/objtype.c msgid "issubclass() arg 1 must be a class" msgstr "" @@ -3719,6 +3717,8 @@ msgstr "" #: ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h #: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h #: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h +#: ports/esp32s2/boards/artisense_rd00/mpconfigboard.h +#: ports/esp32s2/boards/atmegazero_esp32s2/mpconfigboard.h #: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h #: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h #: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h @@ -3744,6 +3744,10 @@ msgstr "" msgid "pressing both buttons at start up.\n" msgstr "" +#: ports/nrf/boards/aramcon2_badge/mpconfigboard.h +msgid "pressing the left button at start up\n" +msgstr "" + #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "pull masks conflict with direction masks" msgstr "" @@ -4017,10 +4021,6 @@ msgstr "" msgid "trapz is defined for 1D arrays of equal length" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "trigger level must be 0 or 1" -msgstr "" - #: py/obj.c msgid "tuple/list has wrong length" msgstr "" @@ -4155,10 +4155,6 @@ msgstr "" msgid "value_count must be > 0" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "wakeup conflict" -msgstr "" - #: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c msgid "watchdog not initialized" msgstr "" diff --git a/locale/cs.po b/locale/cs.po index 654023f1f5..9bed9ec3c6 100644 --- a/locale/cs.po +++ b/locale/cs.po @@ -441,7 +441,7 @@ msgid "Attempt to allocate %d blocks" msgstr "" #: supervisor/shared/safe_mode.c -msgid "Attempted heap allocation when MicroPython VM not running." +msgid "Attempted heap allocation when VM not running." msgstr "" #: shared-bindings/wifi/Radio.c @@ -882,6 +882,11 @@ msgstr "" msgid "EXTINT channel already in use" msgstr "" +#: shared-module/synthio/MidiTrack.c +#, c-format +msgid "Error in MIDI stream at position %d" +msgstr "" + #: extmod/modure.c msgid "Error in regex" msgstr "" @@ -1011,6 +1016,10 @@ msgstr "" msgid "Failed to write internal flash." msgstr "" +#: supervisor/shared/safe_mode.c +msgid "Fatal error." +msgstr "" + #: py/moduerrno.c msgid "File exists" msgstr "" @@ -1083,10 +1092,6 @@ msgstr "" msgid "I2SOut not available" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" -msgstr "" - #: shared-bindings/aesio/aes.c #, c-format msgid "IV must be %d bytes long" @@ -1210,6 +1215,10 @@ msgstr "" msgid "Invalid DAC pin supplied" msgstr "" +#: shared-bindings/synthio/__init__.c +msgid "Invalid MIDI file" +msgstr "" + #: ports/atmel-samd/common-hal/pwmio/PWMOut.c #: ports/cxd56/common-hal/pwmio/PWMOut.c #: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c @@ -1401,14 +1410,6 @@ msgstr "" msgid "Messages limited to 8 bytes" msgstr "" -#: supervisor/shared/safe_mode.c -msgid "MicroPython NLR jump failed. Likely memory corruption." -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "MicroPython fatal error." -msgstr "" - #: shared-bindings/audiobusio/PDMIn.c msgid "Microphone startup delay must be in range 0.0 to 1.0" msgstr "" @@ -1460,6 +1461,10 @@ msgstr "" msgid "Must use a multiple of 6 rgb pins, not %d" msgstr "" +#: supervisor/shared/safe_mode.c +msgid "NLR jump failed. Likely memory corruption." +msgstr "" + #: ports/esp32s2/common-hal/nvm/ByteArray.c msgid "NVS Error" msgstr "" @@ -1604,6 +1609,7 @@ msgstr "" msgid "Not a valid IP string" msgstr "" +#: ports/nrf/common-hal/_bleio/PacketBuffer.c #: ports/nrf/common-hal/_bleio/__init__.c #: shared-bindings/_bleio/CharacteristicBuffer.c msgid "Not connected" @@ -2496,10 +2502,6 @@ msgstr "" msgid "buffer is smaller than requested size" msgstr "" -#: shared-bindings/audiocore/RawSample.c -msgid "buffer must be a bytes-like object" -msgstr "" - #: extmod/ulab/code/ulab_create.c extmod/ulab/code/utils/utils.c msgid "buffer size must be a multiple of element size" msgstr "" @@ -2941,7 +2943,7 @@ msgid "f-string: single '}' is not allowed" msgstr "" #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c -#: shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" msgstr "" @@ -3197,6 +3199,10 @@ msgstr "" msgid "invalid cert" msgstr "" +#: py/compile.c +msgid "invalid decorator" +msgstr "" + #: extmod/uos_dupterm.c msgid "invalid dupterm index" msgstr "" @@ -3252,10 +3258,6 @@ msgstr "" msgid "invalid syntax for number" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "io must be rtc io" -msgstr "" - #: py/objtype.c msgid "issubclass() arg 1 must be a class" msgstr "" @@ -3715,6 +3717,7 @@ msgstr "" #: ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h #: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h #: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h +#: ports/esp32s2/boards/artisense_rd00/mpconfigboard.h #: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h #: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h #: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h @@ -3740,6 +3743,10 @@ msgstr "" msgid "pressing both buttons at start up.\n" msgstr "" +#: ports/nrf/boards/aramcon2_badge/mpconfigboard.h +msgid "pressing the left button at start up\n" +msgstr "" + #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "pull masks conflict with direction masks" msgstr "" @@ -4013,10 +4020,6 @@ msgstr "" msgid "trapz is defined for 1D arrays of equal length" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "trigger level must be 0 or 1" -msgstr "" - #: py/obj.c msgid "tuple/list has wrong length" msgstr "" @@ -4151,10 +4154,6 @@ msgstr "" msgid "value_count must be > 0" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "wakeup conflict" -msgstr "" - #: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c msgid "watchdog not initialized" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index e3e2ddbd45..3a64342366 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -447,10 +447,8 @@ msgid "Attempt to allocate %d blocks" msgstr "Versuche %d Blöcke zu allokieren" #: supervisor/shared/safe_mode.c -msgid "Attempted heap allocation when MicroPython VM not running." +msgid "Attempted heap allocation when VM not running." msgstr "" -"Versuch einer Heap Reservierung, wenn die MicroPython-VM nicht ausgeführt " -"wird." #: shared-bindings/wifi/Radio.c msgid "Authentication failure" @@ -899,6 +897,11 @@ msgstr "ESP-IDF Speicherallozierung fehlgeschlagen" msgid "EXTINT channel already in use" msgstr "EXTINT Kanal ist schon in Benutzung" +#: shared-module/synthio/MidiTrack.c +#, c-format +msgid "Error in MIDI stream at position %d" +msgstr "" + #: extmod/modure.c msgid "Error in regex" msgstr "Fehler in regex" @@ -1029,6 +1032,10 @@ msgstr "Mutex konnte nicht freigegeben werden. Status: 0x%04x" msgid "Failed to write internal flash." msgstr "Interner Flash konnte nicht geschrieben werden." +#: supervisor/shared/safe_mode.c +msgid "Fatal error." +msgstr "" + #: py/moduerrno.c msgid "File exists" msgstr "Datei existiert" @@ -1103,10 +1110,6 @@ msgstr "I2C Peripherie in Verwendung" msgid "I2SOut not available" msgstr "I2SOut nicht verfügbar" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" -msgstr "IOs 0, 2 & 4 unterstützen keinen internen Pull up im sleep-Modus" - #: shared-bindings/aesio/aes.c #, c-format msgid "IV must be %d bytes long" @@ -1232,6 +1235,10 @@ msgstr "Ungültige BSSID" msgid "Invalid DAC pin supplied" msgstr "Ungültiger DAC-Pin angegeben" +#: shared-bindings/synthio/__init__.c +msgid "Invalid MIDI file" +msgstr "" + #: ports/atmel-samd/common-hal/pwmio/PWMOut.c #: ports/cxd56/common-hal/pwmio/PWMOut.c #: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c @@ -1423,15 +1430,6 @@ msgstr "Maximaler x-Wert beim Spiegeln ist %d" msgid "Messages limited to 8 bytes" msgstr "" -#: supervisor/shared/safe_mode.c -msgid "MicroPython NLR jump failed. Likely memory corruption." -msgstr "" -"MicroPython NLR-Sprung fehlgeschlagen. Wahrscheinlich Speicherbeschädigung." - -#: supervisor/shared/safe_mode.c -msgid "MicroPython fatal error." -msgstr "Schwerwiegender MicroPython-Fehler." - #: shared-bindings/audiobusio/PDMIn.c msgid "Microphone startup delay must be in range 0.0 to 1.0" msgstr "" @@ -1484,6 +1482,10 @@ msgstr "Muss MISO- oder MOSI-Pin bereitstellen" msgid "Must use a multiple of 6 rgb pins, not %d" msgstr "Muss ein Vielfaches von 6 RGB-Pins verwenden, nicht %d" +#: supervisor/shared/safe_mode.c +msgid "NLR jump failed. Likely memory corruption." +msgstr "" + #: ports/esp32s2/common-hal/nvm/ByteArray.c msgid "NVS Error" msgstr "" @@ -1628,6 +1630,7 @@ msgstr "" msgid "Not a valid IP string" msgstr "" +#: ports/nrf/common-hal/_bleio/PacketBuffer.c #: ports/nrf/common-hal/_bleio/__init__.c #: shared-bindings/_bleio/CharacteristicBuffer.c msgid "Not connected" @@ -2560,10 +2563,6 @@ msgstr "Zweig ist außerhalb der Reichweite" msgid "buffer is smaller than requested size" msgstr "" -#: shared-bindings/audiocore/RawSample.c -msgid "buffer must be a bytes-like object" -msgstr "Puffer muss ein bytes-artiges Objekt sein" - #: extmod/ulab/code/ulab_create.c extmod/ulab/code/utils/utils.c msgid "buffer size must be a multiple of element size" msgstr "" @@ -3017,7 +3016,7 @@ msgid "f-string: single '}' is not allowed" msgstr "f-string: einzelne '}' nicht erlaubt" #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c -#: shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" msgstr "Die Datei muss eine im Byte-Modus geöffnete Datei sein" @@ -3275,6 +3274,10 @@ msgstr "" msgid "invalid cert" msgstr "ungültiges cert" +#: py/compile.c +msgid "invalid decorator" +msgstr "" + #: extmod/uos_dupterm.c msgid "invalid dupterm index" msgstr "ungültiger dupterm index" @@ -3330,10 +3333,6 @@ msgstr "ungültige Syntax für integer mit Basis %d" msgid "invalid syntax for number" msgstr "ungültige Syntax für number" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "io must be rtc io" -msgstr "" - #: py/objtype.c msgid "issubclass() arg 1 must be a class" msgstr "issubclass() arg 1 muss eine Klasse sein" @@ -3803,6 +3802,7 @@ msgstr "pow () mit 3 Argumenten erfordert Integer" #: ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h #: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h #: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h +#: ports/esp32s2/boards/artisense_rd00/mpconfigboard.h #: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h #: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h #: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h @@ -3828,6 +3828,10 @@ msgstr "" msgid "pressing both buttons at start up.\n" msgstr "" +#: ports/nrf/boards/aramcon2_badge/mpconfigboard.h +msgid "pressing the left button at start up\n" +msgstr "" + #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "pull masks conflict with direction masks" msgstr "" @@ -4104,10 +4108,6 @@ msgstr "" msgid "trapz is defined for 1D arrays of equal length" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "trigger level must be 0 or 1" -msgstr "" - #: py/obj.c msgid "tuple/list has wrong length" msgstr "tupel/list hat falsche Länge" @@ -4246,10 +4246,6 @@ msgstr "Wert muss in %d Byte(s) passen" msgid "value_count must be > 0" msgstr "value_count muss größer als 0 sein" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "wakeup conflict" -msgstr "" - #: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c msgid "watchdog not initialized" msgstr "" @@ -4336,6 +4332,25 @@ msgstr "" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" +#~ msgstr "IOs 0, 2 & 4 unterstützen keinen internen Pull up im sleep-Modus" + +#~ msgid "buffer must be a bytes-like object" +#~ msgstr "Puffer muss ein bytes-artiges Objekt sein" + +#~ msgid "Attempted heap allocation when MicroPython VM not running." +#~ msgstr "" +#~ "Versuch einer Heap Reservierung, wenn die MicroPython-VM nicht ausgeführt " +#~ "wird." + +#~ msgid "MicroPython NLR jump failed. Likely memory corruption." +#~ msgstr "" +#~ "MicroPython NLR-Sprung fehlgeschlagen. Wahrscheinlich " +#~ "Speicherbeschädigung." + +#~ msgid "MicroPython fatal error." +#~ msgstr "Schwerwiegender MicroPython-Fehler." + #~ msgid "argument must be ndarray" #~ msgstr "Argument muss ein ndarray sein" diff --git a/locale/el.po b/locale/el.po index 1f7fabf381..c150ef8258 100644 --- a/locale/el.po +++ b/locale/el.po @@ -438,7 +438,7 @@ msgid "Attempt to allocate %d blocks" msgstr "" #: supervisor/shared/safe_mode.c -msgid "Attempted heap allocation when MicroPython VM not running." +msgid "Attempted heap allocation when VM not running." msgstr "" #: shared-bindings/wifi/Radio.c @@ -879,6 +879,11 @@ msgstr "" msgid "EXTINT channel already in use" msgstr "" +#: shared-module/synthio/MidiTrack.c +#, c-format +msgid "Error in MIDI stream at position %d" +msgstr "" + #: extmod/modure.c msgid "Error in regex" msgstr "" @@ -1008,6 +1013,10 @@ msgstr "" msgid "Failed to write internal flash." msgstr "" +#: supervisor/shared/safe_mode.c +msgid "Fatal error." +msgstr "" + #: py/moduerrno.c msgid "File exists" msgstr "" @@ -1080,10 +1089,6 @@ msgstr "" msgid "I2SOut not available" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" -msgstr "" - #: shared-bindings/aesio/aes.c #, c-format msgid "IV must be %d bytes long" @@ -1207,6 +1212,10 @@ msgstr "" msgid "Invalid DAC pin supplied" msgstr "" +#: shared-bindings/synthio/__init__.c +msgid "Invalid MIDI file" +msgstr "" + #: ports/atmel-samd/common-hal/pwmio/PWMOut.c #: ports/cxd56/common-hal/pwmio/PWMOut.c #: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c @@ -1398,14 +1407,6 @@ msgstr "" msgid "Messages limited to 8 bytes" msgstr "" -#: supervisor/shared/safe_mode.c -msgid "MicroPython NLR jump failed. Likely memory corruption." -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "MicroPython fatal error." -msgstr "" - #: shared-bindings/audiobusio/PDMIn.c msgid "Microphone startup delay must be in range 0.0 to 1.0" msgstr "" @@ -1457,6 +1458,10 @@ msgstr "" msgid "Must use a multiple of 6 rgb pins, not %d" msgstr "" +#: supervisor/shared/safe_mode.c +msgid "NLR jump failed. Likely memory corruption." +msgstr "" + #: ports/esp32s2/common-hal/nvm/ByteArray.c msgid "NVS Error" msgstr "" @@ -1601,6 +1606,7 @@ msgstr "" msgid "Not a valid IP string" msgstr "" +#: ports/nrf/common-hal/_bleio/PacketBuffer.c #: ports/nrf/common-hal/_bleio/__init__.c #: shared-bindings/_bleio/CharacteristicBuffer.c msgid "Not connected" @@ -2493,10 +2499,6 @@ msgstr "" msgid "buffer is smaller than requested size" msgstr "" -#: shared-bindings/audiocore/RawSample.c -msgid "buffer must be a bytes-like object" -msgstr "" - #: extmod/ulab/code/ulab_create.c extmod/ulab/code/utils/utils.c msgid "buffer size must be a multiple of element size" msgstr "" @@ -2938,7 +2940,7 @@ msgid "f-string: single '}' is not allowed" msgstr "" #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c -#: shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" msgstr "" @@ -3194,6 +3196,10 @@ msgstr "" msgid "invalid cert" msgstr "" +#: py/compile.c +msgid "invalid decorator" +msgstr "" + #: extmod/uos_dupterm.c msgid "invalid dupterm index" msgstr "" @@ -3249,10 +3255,6 @@ msgstr "" msgid "invalid syntax for number" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "io must be rtc io" -msgstr "" - #: py/objtype.c msgid "issubclass() arg 1 must be a class" msgstr "" @@ -3712,6 +3714,7 @@ msgstr "" #: ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h #: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h #: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h +#: ports/esp32s2/boards/artisense_rd00/mpconfigboard.h #: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h #: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h #: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h @@ -3737,6 +3740,10 @@ msgstr "" msgid "pressing both buttons at start up.\n" msgstr "" +#: ports/nrf/boards/aramcon2_badge/mpconfigboard.h +msgid "pressing the left button at start up\n" +msgstr "" + #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "pull masks conflict with direction masks" msgstr "" @@ -4010,10 +4017,6 @@ msgstr "" msgid "trapz is defined for 1D arrays of equal length" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "trigger level must be 0 or 1" -msgstr "" - #: py/obj.c msgid "tuple/list has wrong length" msgstr "" @@ -4148,10 +4151,6 @@ msgstr "" msgid "value_count must be > 0" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "wakeup conflict" -msgstr "" - #: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c msgid "watchdog not initialized" msgstr "" diff --git a/locale/en_GB.po b/locale/en_GB.po index 135f738872..d3859c7c9e 100644 --- a/locale/en_GB.po +++ b/locale/en_GB.po @@ -7,15 +7,15 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"PO-Revision-Date: 2021-03-25 23:30+0000\n" -"Last-Translator: Gareth Coleman \n" +"PO-Revision-Date: 2021-04-11 01:30+0000\n" +"Last-Translator: Hugo Dahl \n" "Language-Team: none\n" "Language: en_GB\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 4.5.2-dev\n" +"X-Generator: Weblate 4.6-dev\n" #: main.c msgid "" @@ -447,9 +447,8 @@ msgid "Attempt to allocate %d blocks" msgstr "Attempt to allocate %d blocks" #: supervisor/shared/safe_mode.c -#, fuzzy -msgid "Attempted heap allocation when MicroPython VM not running." -msgstr "Attempted heap allocation when CircuitPython VM not running." +msgid "Attempted heap allocation when VM not running." +msgstr "" #: shared-bindings/wifi/Radio.c msgid "Authentication failure" @@ -895,6 +894,11 @@ msgstr "ESP-IDF memory allocation failed" msgid "EXTINT channel already in use" msgstr "EXTINT channel already in use" +#: shared-module/synthio/MidiTrack.c +#, c-format +msgid "Error in MIDI stream at position %d" +msgstr "" + #: extmod/modure.c msgid "Error in regex" msgstr "Error in regex" @@ -1024,6 +1028,10 @@ msgstr "Failed to release mutex, err 0x%04x" msgid "Failed to write internal flash." msgstr "Failed to write internal flash." +#: supervisor/shared/safe_mode.c +msgid "Fatal error." +msgstr "" + #: py/moduerrno.c msgid "File exists" msgstr "File exists" @@ -1096,10 +1104,6 @@ msgstr "I2C peripheral in use" msgid "I2SOut not available" msgstr "I2SOut not available" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" -msgstr "IOs 0, 2 & 4 do not support internal pullup in sleep" - #: shared-bindings/aesio/aes.c #, c-format msgid "IV must be %d bytes long" @@ -1225,6 +1229,10 @@ msgstr "Invalid BSSID" msgid "Invalid DAC pin supplied" msgstr "Invalid DAC pin supplied" +#: shared-bindings/synthio/__init__.c +msgid "Invalid MIDI file" +msgstr "" + #: ports/atmel-samd/common-hal/pwmio/PWMOut.c #: ports/cxd56/common-hal/pwmio/PWMOut.c #: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c @@ -1416,16 +1424,6 @@ msgstr "Maximum x value when mirrored is %d" msgid "Messages limited to 8 bytes" msgstr "Messages limited to 8 bytes" -#: supervisor/shared/safe_mode.c -#, fuzzy -msgid "MicroPython NLR jump failed. Likely memory corruption." -msgstr "CircuitPython NLR jump failed. Likely memory corruption." - -#: supervisor/shared/safe_mode.c -#, fuzzy -msgid "MicroPython fatal error." -msgstr "CircuitPython fatal error." - #: shared-bindings/audiobusio/PDMIn.c msgid "Microphone startup delay must be in range 0.0 to 1.0" msgstr "Microphone startup delay must be in range 0.0 to 1.0" @@ -1477,6 +1475,10 @@ msgstr "Must provide MISO or MOSI pin" msgid "Must use a multiple of 6 rgb pins, not %d" msgstr "Must use a multiple of 6 rgb pins, not %d" +#: supervisor/shared/safe_mode.c +msgid "NLR jump failed. Likely memory corruption." +msgstr "" + #: ports/esp32s2/common-hal/nvm/ByteArray.c msgid "NVS Error" msgstr "NVS Error" @@ -1621,6 +1623,7 @@ msgstr "" msgid "Not a valid IP string" msgstr "Not a valid IP string" +#: ports/nrf/common-hal/_bleio/PacketBuffer.c #: ports/nrf/common-hal/_bleio/__init__.c #: shared-bindings/_bleio/CharacteristicBuffer.c msgid "Not connected" @@ -2540,10 +2543,6 @@ msgstr "Branch not in range" msgid "buffer is smaller than requested size" msgstr "Buffer is smaller than requested size" -#: shared-bindings/audiocore/RawSample.c -msgid "buffer must be a bytes-like object" -msgstr "Buffer must be a bytes-like object" - #: extmod/ulab/code/ulab_create.c extmod/ulab/code/utils/utils.c msgid "buffer size must be a multiple of element size" msgstr "Buffer size must be a multiple of element size" @@ -2988,7 +2987,7 @@ msgid "f-string: single '}' is not allowed" msgstr "f-string: single '}' is not allowed" #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c -#: shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" msgstr "file must be a file opened in byte mode" @@ -3244,6 +3243,10 @@ msgstr "invalid bits_per_pixel %d, must be, 1, 4, 8, 16, 24, or 32" msgid "invalid cert" msgstr "invalid cert" +#: py/compile.c +msgid "invalid decorator" +msgstr "" + #: extmod/uos_dupterm.c msgid "invalid dupterm index" msgstr "invalid dupterm index" @@ -3300,10 +3303,6 @@ msgstr "invalid syntax for integer with base %d" msgid "invalid syntax for number" msgstr "invalid syntax for number" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "io must be rtc io" -msgstr "io must be rtc io" - #: py/objtype.c msgid "issubclass() arg 1 must be a class" msgstr "issubclass() arg 1 must be a class" @@ -3763,6 +3762,7 @@ msgstr "pow() with 3 arguments requires integers" #: ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h #: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h #: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h +#: ports/esp32s2/boards/artisense_rd00/mpconfigboard.h #: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h #: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h #: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h @@ -3788,6 +3788,10 @@ msgstr "pressing boot button at start up.\n" msgid "pressing both buttons at start up.\n" msgstr "pressing both buttons at start up.\n" +#: ports/nrf/boards/aramcon2_badge/mpconfigboard.h +msgid "pressing the left button at start up\n" +msgstr "" + #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "pull masks conflict with direction masks" msgstr "pull masks conflict with direction masks" @@ -4063,10 +4067,6 @@ msgstr "trapz is defined for 1D arrays" msgid "trapz is defined for 1D arrays of equal length" msgstr "trapz is defined for 1D arrays of equal length" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "trigger level must be 0 or 1" -msgstr "trigger level must be 0 or 1" - #: py/obj.c msgid "tuple/list has wrong length" msgstr "tuple/list has wrong length" @@ -4201,10 +4201,6 @@ msgstr "value must fit in %d byte(s)" msgid "value_count must be > 0" msgstr "value_count must be > 0" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "wakeup conflict" -msgstr "wakeup conflict" - #: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c msgid "watchdog not initialized" msgstr "WatchDog not initialised" @@ -4291,6 +4287,31 @@ msgstr "zi must be of float type" msgid "zi must be of shape (n_section, 2)" msgstr "zi must be of shape (n_section, 2)" +#~ msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" +#~ msgstr "IOs 0, 2 & 4 do not support internal pullup in sleep" + +#~ msgid "buffer must be a bytes-like object" +#~ msgstr "Buffer must be a bytes-like object" + +#~ msgid "io must be rtc io" +#~ msgstr "io must be rtc io" + +#~ msgid "trigger level must be 0 or 1" +#~ msgstr "trigger level must be 0 or 1" + +#~ msgid "wakeup conflict" +#~ msgstr "wakeup conflict" + +#~ msgid "Attempted heap allocation when MicroPython VM not running." +#~ msgstr "Attempted heap allocation when MicroPython VM not running." + +#~ msgid "MicroPython NLR jump failed. Likely memory corruption." +#~ msgstr "MicroPython NLR jump failed. Likely memory corruption." + +#, fuzzy +#~ msgid "MicroPython fatal error." +#~ msgstr "CircuitPython fatal error." + #~ msgid "argument must be ndarray" #~ msgstr "argument must be ndarray" diff --git a/locale/es.po b/locale/es.po index 2f7a7a7b9c..6339727b8c 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,8 +8,8 @@ msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2021-04-05 22:35+0000\n" -"Last-Translator: Jose David M \n" +"PO-Revision-Date: 2021-04-15 14:26+0000\n" +"Last-Translator: Alvaro Figueroa \n" "Language-Team: \n" "Language: es\n" "MIME-Version: 1.0\n" @@ -426,7 +426,7 @@ msgstr "El pin proporcionado no soporta AnalogOut" #: ports/stm/common-hal/audiopwmio/PWMAudioOut.c msgid "Another PWMAudioOut is already active" -msgstr "" +msgstr "Otra salida PWMAudioOut esta ya activada" #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/cxd56/common-hal/pulseio/PulseOut.c @@ -451,10 +451,8 @@ msgid "Attempt to allocate %d blocks" msgstr "Tratando de localizar %d bloques" #: supervisor/shared/safe_mode.c -msgid "Attempted heap allocation when MicroPython VM not running." -msgstr "" -"Se intentó asignación del montículo, sin que la VM de MicroPython esté " -"ejecutando." +msgid "Attempted heap allocation when VM not running." +msgstr "Asignación del montículo mientras la VM no esta ejecutándose." #: shared-bindings/wifi/Radio.c msgid "Authentication failure" @@ -905,6 +903,11 @@ msgstr "Fallo ESP-IDF al tomar la memoria" msgid "EXTINT channel already in use" msgstr "El canal EXTINT ya está siendo utilizado" +#: shared-module/synthio/MidiTrack.c +#, c-format +msgid "Error in MIDI stream at position %d" +msgstr "Error en el flujo MIDI en la posición %d" + #: extmod/modure.c msgid "Error in regex" msgstr "Error en regex" @@ -1007,7 +1010,7 @@ msgstr "Fallo al tomar memoria para búsqueda wifi" #: ports/stm/common-hal/audiopwmio/PWMAudioOut.c msgid "Failed to buffer the sample" -msgstr "" +msgstr "Fallo al hacer el búfer de la muestra" #: ports/nrf/common-hal/_bleio/Adapter.c msgid "Failed to connect: internal error" @@ -1034,6 +1037,10 @@ msgstr "No se puede liberar el mutex, err 0x%04x" msgid "Failed to write internal flash." msgstr "Error al escribir el flash interno." +#: supervisor/shared/safe_mode.c +msgid "Fatal error." +msgstr "Error grave." + #: py/moduerrno.c msgid "File exists" msgstr "El archivo ya existe" @@ -1107,10 +1114,6 @@ msgstr "Dispositivo I2C en uso" msgid "I2SOut not available" msgstr "I2SOut no disponible" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" -msgstr "IOs 0, 2 y 4 no soportan pullup interno durante sleep" - #: shared-bindings/aesio/aes.c #, c-format msgid "IV must be %d bytes long" @@ -1243,6 +1246,10 @@ msgstr "BSSID inválido" msgid "Invalid DAC pin supplied" msgstr "Pin suministrado inválido para DAC" +#: shared-bindings/synthio/__init__.c +msgid "Invalid MIDI file" +msgstr "Archivo MIDI inválido" + #: ports/atmel-samd/common-hal/pwmio/PWMOut.c #: ports/cxd56/common-hal/pwmio/PWMOut.c #: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c @@ -1434,14 +1441,6 @@ msgstr "Valor máximo de x cuando se refleja es %d" msgid "Messages limited to 8 bytes" msgstr "Mensajes limitados a 8 bytes" -#: supervisor/shared/safe_mode.c -msgid "MicroPython NLR jump failed. Likely memory corruption." -msgstr "MicroPython NLR jump falló. Probable corrupción de la memoria." - -#: supervisor/shared/safe_mode.c -msgid "MicroPython fatal error." -msgstr "Error fatal de MicroPython." - #: shared-bindings/audiobusio/PDMIn.c msgid "Microphone startup delay must be in range 0.0 to 1.0" msgstr "Micrófono demora de inicio debe estar en el rango 0.0 a 1.0" @@ -1497,6 +1496,10 @@ msgstr "Debe proporcionar un pin MISO o MOSI" msgid "Must use a multiple of 6 rgb pins, not %d" msgstr "Debe usar un múltiplo de 6 pines rgb, no %d" +#: supervisor/shared/safe_mode.c +msgid "NLR jump failed. Likely memory corruption." +msgstr "Salto NLR falló. Probablemente corrupción de memoria." + #: ports/esp32s2/common-hal/nvm/ByteArray.c msgid "NVS Error" msgstr "Error NVS" @@ -1641,6 +1644,7 @@ msgstr "El firmware del sistema Nordic no tiene memoria" msgid "Not a valid IP string" msgstr "No es una cadena de IP válida" +#: ports/nrf/common-hal/_bleio/PacketBuffer.c #: ports/nrf/common-hal/_bleio/__init__.c #: shared-bindings/_bleio/CharacteristicBuffer.c msgid "Not connected" @@ -2573,10 +2577,6 @@ msgstr "la rama no está dentro del rango" msgid "buffer is smaller than requested size" msgstr "El buffer es mas pequeño que el requerido" -#: shared-bindings/audiocore/RawSample.c -msgid "buffer must be a bytes-like object" -msgstr "buffer debe de ser un objeto bytes-like" - #: extmod/ulab/code/ulab_create.c extmod/ulab/code/utils/utils.c msgid "buffer size must be a multiple of element size" msgstr "El tamaño del buffer debe ser un múltiplo del tamaño del elemento" @@ -3025,7 +3025,7 @@ msgid "f-string: single '}' is not allowed" msgstr "cadena-f: solo '}' no está permitido" #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c -#: shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" msgstr "el archivo deberia ser una archivo abierto en modo byte" @@ -3281,6 +3281,10 @@ msgstr "los bits_per_pixel %d no son validos, deben ser 1, 4, 8, 16, 24 o 32" msgid "invalid cert" msgstr "certificado inválido" +#: py/compile.c +msgid "invalid decorator" +msgstr "decorador invalido" + #: extmod/uos_dupterm.c msgid "invalid dupterm index" msgstr "index dupterm inválido" @@ -3336,10 +3340,6 @@ msgstr "sintaxis inválida para entero con base %d" msgid "invalid syntax for number" msgstr "sintaxis inválida para número" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "io must be rtc io" -msgstr "io debe ser rtc io" - #: py/objtype.c msgid "issubclass() arg 1 must be a class" msgstr "issubclass() arg 1 debe ser una clase" @@ -3806,6 +3806,7 @@ msgstr "pow() con 3 argumentos requiere enteros" #: ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h #: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h #: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h +#: ports/esp32s2/boards/artisense_rd00/mpconfigboard.h #: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h #: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h #: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h @@ -3831,6 +3832,10 @@ msgstr "presionando botón de arranque al inicio.\n" msgid "pressing both buttons at start up.\n" msgstr "presionando ambos botones al inicio.\n" +#: ports/nrf/boards/aramcon2_badge/mpconfigboard.h +msgid "pressing the left button at start up\n" +msgstr "" + #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "pull masks conflict with direction masks" msgstr "máscara de pull en conflicto con máscara de dirección" @@ -4107,10 +4112,6 @@ msgstr "trapz esta definido para matrices 1D" msgid "trapz is defined for 1D arrays of equal length" msgstr "trapz está definido para arreglos 1D de igual tamaño" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "trigger level must be 0 or 1" -msgstr "nivel de accionamiento debe ser 0 o 1" - #: py/obj.c msgid "tuple/list has wrong length" msgstr "tupla/lista tiene una longitud incorrecta" @@ -4245,10 +4246,6 @@ msgstr "el valor debe caber en %d byte(s)" msgid "value_count must be > 0" msgstr "value_count debe ser > 0" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "wakeup conflict" -msgstr "conflicto de wakeup" - #: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c msgid "watchdog not initialized" msgstr "watchdog no inicializado" @@ -4335,6 +4332,32 @@ msgstr "zi debe ser de tipo flotante" msgid "zi must be of shape (n_section, 2)" msgstr "zi debe ser una forma (n_section,2)" +#~ msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" +#~ msgstr "IOs 0, 2 y 4 no soportan pullup interno durante sleep" + +#~ msgid "buffer must be a bytes-like object" +#~ msgstr "buffer debe de ser un objeto bytes-like" + +#~ msgid "io must be rtc io" +#~ msgstr "io debe ser rtc io" + +#~ msgid "trigger level must be 0 or 1" +#~ msgstr "nivel de accionamiento debe ser 0 o 1" + +#~ msgid "wakeup conflict" +#~ msgstr "conflicto de wakeup" + +#~ msgid "Attempted heap allocation when MicroPython VM not running." +#~ msgstr "" +#~ "Se intentó asignación del montículo, sin que la VM de MicroPython esté " +#~ "ejecutando." + +#~ msgid "MicroPython NLR jump failed. Likely memory corruption." +#~ msgstr "MicroPython NLR jump falló. Probable corrupción de la memoria." + +#~ msgid "MicroPython fatal error." +#~ msgstr "Error fatal de MicroPython." + #~ msgid "argument must be ndarray" #~ msgstr "argumento debe ser ndarray" diff --git a/locale/fil.po b/locale/fil.po index 23d1be9718..3248eb0ce2 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -441,7 +441,7 @@ msgid "Attempt to allocate %d blocks" msgstr "" #: supervisor/shared/safe_mode.c -msgid "Attempted heap allocation when MicroPython VM not running." +msgid "Attempted heap allocation when VM not running." msgstr "" #: shared-bindings/wifi/Radio.c @@ -890,6 +890,11 @@ msgstr "" msgid "EXTINT channel already in use" msgstr "Ginagamit na ang EXTINT channel" +#: shared-module/synthio/MidiTrack.c +#, c-format +msgid "Error in MIDI stream at position %d" +msgstr "" + #: extmod/modure.c msgid "Error in regex" msgstr "May pagkakamali sa REGEX" @@ -1021,6 +1026,10 @@ msgstr "Nabigo sa pagrelease ng mutex, status: 0x%08lX" msgid "Failed to write internal flash." msgstr "" +#: supervisor/shared/safe_mode.c +msgid "Fatal error." +msgstr "" + #: py/moduerrno.c msgid "File exists" msgstr "Mayroong file" @@ -1093,10 +1102,6 @@ msgstr "" msgid "I2SOut not available" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" -msgstr "" - #: shared-bindings/aesio/aes.c #, c-format msgid "IV must be %d bytes long" @@ -1222,6 +1227,10 @@ msgstr "" msgid "Invalid DAC pin supplied" msgstr "" +#: shared-bindings/synthio/__init__.c +msgid "Invalid MIDI file" +msgstr "" + #: ports/atmel-samd/common-hal/pwmio/PWMOut.c #: ports/cxd56/common-hal/pwmio/PWMOut.c #: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c @@ -1413,14 +1422,6 @@ msgstr "" msgid "Messages limited to 8 bytes" msgstr "" -#: supervisor/shared/safe_mode.c -msgid "MicroPython NLR jump failed. Likely memory corruption." -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "MicroPython fatal error." -msgstr "" - #: shared-bindings/audiobusio/PDMIn.c msgid "Microphone startup delay must be in range 0.0 to 1.0" msgstr "Ang delay ng startup ng mikropono ay dapat na nasa 0.0 hanggang 1.0" @@ -1472,6 +1473,10 @@ msgstr "" msgid "Must use a multiple of 6 rgb pins, not %d" msgstr "" +#: supervisor/shared/safe_mode.c +msgid "NLR jump failed. Likely memory corruption." +msgstr "" + #: ports/esp32s2/common-hal/nvm/ByteArray.c msgid "NVS Error" msgstr "" @@ -1616,6 +1621,7 @@ msgstr "" msgid "Not a valid IP string" msgstr "" +#: ports/nrf/common-hal/_bleio/PacketBuffer.c #: ports/nrf/common-hal/_bleio/__init__.c #: shared-bindings/_bleio/CharacteristicBuffer.c #, fuzzy @@ -2523,10 +2529,6 @@ msgstr "branch wala sa range" msgid "buffer is smaller than requested size" msgstr "" -#: shared-bindings/audiocore/RawSample.c -msgid "buffer must be a bytes-like object" -msgstr "buffer ay dapat bytes-like object" - #: extmod/ulab/code/ulab_create.c extmod/ulab/code/utils/utils.c msgid "buffer size must be a multiple of element size" msgstr "" @@ -2980,7 +2982,7 @@ msgid "f-string: single '}' is not allowed" msgstr "" #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c -#: shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" msgstr "file ay dapat buksan sa byte mode" @@ -3237,6 +3239,10 @@ msgstr "" msgid "invalid cert" msgstr "mali ang cert" +#: py/compile.c +msgid "invalid decorator" +msgstr "" + #: extmod/uos_dupterm.c msgid "invalid dupterm index" msgstr "mali ang dupterm index" @@ -3292,10 +3298,6 @@ msgstr "maling sintaks sa integer na may base %d" msgid "invalid syntax for number" msgstr "maling sintaks sa number" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "io must be rtc io" -msgstr "" - #: py/objtype.c msgid "issubclass() arg 1 must be a class" msgstr "issubclass() arg 1 ay dapat na class" @@ -3761,6 +3763,7 @@ msgstr "pow() na may 3 argumento kailangan ng integers" #: ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h #: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h #: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h +#: ports/esp32s2/boards/artisense_rd00/mpconfigboard.h #: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h #: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h #: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h @@ -3786,6 +3789,10 @@ msgstr "" msgid "pressing both buttons at start up.\n" msgstr "" +#: ports/nrf/boards/aramcon2_badge/mpconfigboard.h +msgid "pressing the left button at start up\n" +msgstr "" + #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "pull masks conflict with direction masks" msgstr "" @@ -4063,10 +4070,6 @@ msgstr "" msgid "trapz is defined for 1D arrays of equal length" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "trigger level must be 0 or 1" -msgstr "" - #: py/obj.c msgid "tuple/list has wrong length" msgstr "mali ang haba ng tuple/list" @@ -4201,10 +4204,6 @@ msgstr "" msgid "value_count must be > 0" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "wakeup conflict" -msgstr "" - #: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c msgid "watchdog not initialized" msgstr "" @@ -4293,6 +4292,9 @@ msgstr "" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "buffer must be a bytes-like object" +#~ msgstr "buffer ay dapat bytes-like object" + #~ msgid "Group full" #~ msgstr "Puno ang group" diff --git a/locale/fr.po b/locale/fr.po index 19d98f770a..eb56894ff2 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2021-04-03 21:57+0000\n" +"PO-Revision-Date: 2021-04-17 03:26+0000\n" "Last-Translator: Hugo Dahl \n" "Language: fr\n" "MIME-Version: 1.0\n" @@ -426,7 +426,7 @@ msgstr "'AnalogOut' n'est pas supporté sur la broche indiquée" #: ports/stm/common-hal/audiopwmio/PWMAudioOut.c msgid "Another PWMAudioOut is already active" -msgstr "" +msgstr "Un autre PWMAudioOut est déjà actif" #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/cxd56/common-hal/pulseio/PulseOut.c @@ -435,11 +435,11 @@ msgstr "Un autre envoi est déjà actif" #: shared-bindings/pulseio/PulseOut.c msgid "Array must contain halfwords (type 'H')" -msgstr "Le tableau doit contenir des demi-mots (type 'H')" +msgstr "La matrice doit contenir des demi-mots (type 'H')" #: shared-bindings/alarm/SleepMemory.c shared-bindings/nvm/ByteArray.c msgid "Array values should be single bytes." -msgstr "Les valeurs du tableau doivent être des octets singuliers." +msgstr "Les valeurs de la matrice doivent être des octets singuliers." #: shared-bindings/microcontroller/Pin.c msgid "At most %d %q may be specified (not %d)" @@ -451,10 +451,10 @@ msgid "Attempt to allocate %d blocks" msgstr "Tentative d'allocation de %d blocs" #: supervisor/shared/safe_mode.c -msgid "Attempted heap allocation when MicroPython VM not running." +msgid "Attempted heap allocation when VM not running." msgstr "" -"Tentative d'allocation de segments lorsque la machine virtuelle MicroPython " -"n'est pas en cours d'exécution." +"Tentative d'allocation à la pile quand la Machine Virtuelle n'est pas en " +"exécution." #: shared-bindings/wifi/Radio.c msgid "Authentication failure" @@ -911,6 +911,11 @@ msgstr "ESP-IDF échec d'allocation de la mémoire" msgid "EXTINT channel already in use" msgstr "Canal EXTINT déjà utilisé" +#: shared-module/synthio/MidiTrack.c +#, c-format +msgid "Error in MIDI stream at position %d" +msgstr "Erreur dans le flot MIDI à la position %d" + #: extmod/modure.c msgid "Error in regex" msgstr "Erreur dans l'expression régulière" @@ -973,7 +978,7 @@ msgstr "La FFT est définie uniquement pour les ndarrays" #: extmod/ulab/code/numpy/fft/fft_tools.c msgid "FFT is implemented for linear arrays only" -msgstr "FFT n'est implémenté que pour les tableaux linéaires" +msgstr "FFT n'est implémenté que pour les matrices linéaires" #: ports/esp32s2/common-hal/ssl/SSLSocket.c msgid "Failed SSL handshake" @@ -1014,7 +1019,7 @@ msgstr "Impossible d'allouer la mémoire pour le scan wifi" #: ports/stm/common-hal/audiopwmio/PWMAudioOut.c msgid "Failed to buffer the sample" -msgstr "" +msgstr "Échec du tamponage de l'échantillon" #: ports/nrf/common-hal/_bleio/Adapter.c msgid "Failed to connect: internal error" @@ -1041,6 +1046,10 @@ msgstr "Impossible de libérer mutex, err 0x%04x" msgid "Failed to write internal flash." msgstr "Échec de l'écriture vers flash interne." +#: supervisor/shared/safe_mode.c +msgid "Fatal error." +msgstr "Erreurre fatale." + #: py/moduerrno.c msgid "File exists" msgstr "Le fichier existe" @@ -1115,10 +1124,6 @@ msgstr "périphérique I2C utilisé" msgid "I2SOut not available" msgstr "I2SOut n'est pas disponible" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" -msgstr "IOs 0, 2 & 4 ne supportent pas l'éleveuse interne en mode someil" - #: shared-bindings/aesio/aes.c #, c-format msgid "IV must be %d bytes long" @@ -1253,6 +1258,10 @@ msgstr "BSSID invalide" msgid "Invalid DAC pin supplied" msgstr "Broche DAC non valide fournie" +#: shared-bindings/synthio/__init__.c +msgid "Invalid MIDI file" +msgstr "Fichier MIDI invalide" + #: ports/atmel-samd/common-hal/pwmio/PWMOut.c #: ports/cxd56/common-hal/pwmio/PWMOut.c #: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c @@ -1444,14 +1453,6 @@ msgstr "La valeur maximale de x est %d lors d'une opération miroir" msgid "Messages limited to 8 bytes" msgstr "Messages limités à 8 octets" -#: supervisor/shared/safe_mode.c -msgid "MicroPython NLR jump failed. Likely memory corruption." -msgstr "Échec du saut MicroPython NLR. Corruption de la mémoire probable." - -#: supervisor/shared/safe_mode.c -msgid "MicroPython fatal error." -msgstr "Erreur fatale MicroPython." - #: shared-bindings/audiobusio/PDMIn.c msgid "Microphone startup delay must be in range 0.0 to 1.0" msgstr "Le délais au démarrage du micro doit être entre 0.0 et 1.0" @@ -1505,6 +1506,10 @@ msgstr "Doit fournir une broche MISO ou MOSI" msgid "Must use a multiple of 6 rgb pins, not %d" msgstr "Doit utiliser un multiple de 6 broches RVB, pas %d" +#: supervisor/shared/safe_mode.c +msgid "NLR jump failed. Likely memory corruption." +msgstr "Saut NLR échoué. Corruption de mémoire probable." + #: ports/esp32s2/common-hal/nvm/ByteArray.c msgid "NVS Error" msgstr "Erreur NVS" @@ -1649,6 +1654,7 @@ msgstr "Logiciel systême Nordic hors de mémoire" msgid "Not a valid IP string" msgstr "Chaîne IP non valide" +#: ports/nrf/common-hal/_bleio/PacketBuffer.c #: ports/nrf/common-hal/_bleio/__init__.c #: shared-bindings/_bleio/CharacteristicBuffer.c msgid "Not connected" @@ -2494,11 +2500,11 @@ msgstr "l'argument est une séquence vide" #: extmod/ulab/code/numpy/numerical/numerical.c msgid "argsort argument must be an ndarray" -msgstr "L'argument argsort doit être un ndarray" +msgstr "Le paramêtre argsort doit être un ndarray" #: extmod/ulab/code/numpy/numerical/numerical.c msgid "argsort is not implemented for flattened arrays" -msgstr "argsort n'est pas mis en œuvre pour les tableaux aplatis" +msgstr "argsort n'est pas mis en œuvre pour les matrices aplatis" #: py/runtime.c msgid "argument has wrong type" @@ -2520,12 +2526,12 @@ msgstr "les paramètres doivent être des ndarrays" #: extmod/ulab/code/ndarray.c msgid "array and index length must be equal" -msgstr "la longueur du tableau et de l'index doivent être égaux" +msgstr "la taille de la matrice et de l'index doivent être égaux" #: py/objarray.c shared-bindings/alarm/SleepMemory.c #: shared-bindings/nvm/ByteArray.c msgid "array/bytes required on right side" -msgstr "tableau/octets requis à droite" +msgstr "matrice/octets requis à la droite" #: extmod/ulab/code/numpy/numerical/numerical.c msgid "attempt to get (arg)min/(arg)max of empty sequence" @@ -2587,10 +2593,6 @@ msgstr "branche hors-bornes" msgid "buffer is smaller than requested size" msgstr "tampon est plus petit que la taille demandée" -#: shared-bindings/audiocore/RawSample.c -msgid "buffer must be a bytes-like object" -msgstr "le tampon doit être un objet bytes-like" - #: extmod/ulab/code/ulab_create.c extmod/ulab/code/utils/utils.c msgid "buffer size must be a multiple of element size" msgstr "taille du tampon doit être un multiple de la taille de l'élement" @@ -2828,8 +2830,7 @@ msgstr "" #: shared-bindings/displayio/Palette.c msgid "color buffer must be a bytearray or array of type 'b' or 'B'" -msgstr "" -"le tampon de couleur doit être un bytearray ou un tableau de type 'b' ou 'B'" +msgstr "tampon color doit être un bytearray ou une matrice de type 'b' ou 'B'" #: shared-bindings/displayio/Palette.c msgid "color must be between 0x000000 and 0xffffff" @@ -2861,11 +2862,11 @@ msgstr "conversion en objet" #: extmod/ulab/code/numpy/filter/filter.c msgid "convolve arguments must be linear arrays" -msgstr "les arguments convolve doivent être des tableaux linéaires" +msgstr "les paramêtres pour convolve doivent être des matrices linéaires" #: extmod/ulab/code/numpy/filter/filter.c msgid "convolve arguments must be ndarrays" -msgstr "les arguments convolve doivent être des ndarrays" +msgstr "les paramêtres pour convolve doivent être des ndarrays" #: extmod/ulab/code/numpy/filter/filter.c msgid "convolve arguments must not be empty" @@ -2881,7 +2882,7 @@ msgstr "impossible de déterminer la version de la carte SD" #: extmod/ulab/code/numpy/numerical/numerical.c msgid "cross is defined for 1D arrays of length 3" -msgstr "cross est défini pour les tableaux 1D de longueur 3" +msgstr "cross est défini pour les matrices 1D de longueur 3" #: extmod/ulab/code/scipy/optimize/optimize.c msgid "data must be iterable" @@ -2911,12 +2912,13 @@ msgstr "default n'est pas une fonction" msgid "" "destination buffer must be a bytearray or array of type 'B' for bit_depth = 8" msgstr "" -"le tampon de destination doit être un tableau de type 'B' pour bit_depth = 8" +"le tampon de destination doit être une matrice de type 'B' pour bit_depth = 8" #: shared-bindings/audiobusio/PDMIn.c msgid "destination buffer must be an array of type 'H' for bit_depth = 16" msgstr "" -"le tampon de destination doit être un tableau de type 'H' pour bit_depth = 16" +"le tampon de destination doit être une matrice de type 'H' pour bit_depth = " +"16" #: shared-bindings/audiobusio/PDMIn.c msgid "destination_length must be an int >= 0" @@ -2928,7 +2930,7 @@ msgstr "la séquence de mise à jour de dict a une mauvaise longueur" #: extmod/ulab/code/numpy/numerical/numerical.c msgid "diff argument must be an ndarray" -msgstr "l'argument diff doit être un ndarray" +msgstr "le paramêtre diff doit être un ndarray" #: extmod/ulab/code/numpy/numerical/numerical.c msgid "differentiation order out of range" @@ -3047,7 +3049,7 @@ msgid "f-string: single '}' is not allowed" msgstr "f-string : single '}' n'est pas autorisé" #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c -#: shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" msgstr "le fichier doit être un fichier ouvert en mode 'byte'" @@ -3065,11 +3067,11 @@ msgstr "le premier argument doit être une fonction" #: extmod/ulab/code/ulab_create.c msgid "first argument must be a tuple of ndarrays" -msgstr "le premier argument doit être un tuple de ndarrays" +msgstr "le premier paramêtre doit être un tuple de ndarrays" #: extmod/ulab/code/numpy/vector/vector.c msgid "first argument must be an ndarray" -msgstr "le premier argument doit être un ndarray" +msgstr "le premier paramêtre doit être un ndarray" #: py/objtype.c msgid "first argument to super() must be type" @@ -3081,7 +3083,7 @@ msgstr "l'ordre d'aplatissement doit être «C» ou «F»" #: extmod/ulab/code/numpy/numerical/numerical.c msgid "flip argument must be an ndarray" -msgstr "l'argument flip doit être un ndarray" +msgstr "le paramêtre flip doit être un ndarray" #: py/objint.c msgid "float too big" @@ -3118,7 +3120,7 @@ msgstr "la fonction a le même signe aux extrémités de l’intervalle" #: extmod/ulab/code/ndarray.c msgid "function is defined for ndarrays only" -msgstr "La fonction n'est définie que pour les ndarrays" +msgstr "fonction définie que pour les ndarrays" #: py/argcheck.c #, c-format @@ -3224,11 +3226,11 @@ msgstr "Paramètre entrant doit être un chiffre entier, un tuple, ou une liste" #: extmod/ulab/code/numpy/fft/fft_tools.c msgid "input array length must be power of 2" -msgstr "la longueur du tableau d'entrée doit être une puissance de 2" +msgstr "longueur de la matrice d'entrée doit être une puissance de 2" #: extmod/ulab/code/ulab_create.c msgid "input arrays are not compatible" -msgstr "les tableaux d'entrée ne sont pas compatibles" +msgstr "les matrices d'entrée ne sont pas compatibles" #: extmod/ulab/code/numpy/poly/poly.c msgid "input data must be an iterable" @@ -3244,7 +3246,7 @@ msgstr "la matrice d'entrée est singulière" #: extmod/ulab/code/user/user.c msgid "input must be a dense ndarray" -msgstr "l'entrée doit être un tableau dense" +msgstr "l'entrée doit être un ndarray dense" #: extmod/ulab/code/ulab_create.c msgid "input must be a tensor of rank 2" @@ -3284,7 +3286,7 @@ msgstr "entier requis" #: extmod/ulab/code/numpy/approx/approx.c msgid "interp is defined for 1D arrays of equal length" -msgstr "interp est défini pour les tableaux 1D de longueur égale" +msgstr "interp est défini pour les matrices 1D de longueur égale" #: shared-bindings/_bleio/Adapter.c #, c-format @@ -3304,6 +3306,10 @@ msgstr "bits_per_pixel %d est invalid, doit être 1, 4, 8, 16, 24 ou 32" msgid "invalid cert" msgstr "certificat invalide" +#: py/compile.c +msgid "invalid decorator" +msgstr "décorateur invalide" + #: extmod/uos_dupterm.c msgid "invalid dupterm index" msgstr "index invalide pour dupterm" @@ -3359,10 +3365,6 @@ msgstr "syntaxe invalide pour un entier de base %d" msgid "invalid syntax for number" msgstr "syntaxe invalide pour un nombre" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "io must be rtc io" -msgstr "io doit être rtc io" - #: py/objtype.c msgid "issubclass() arg 1 must be a class" msgstr "l'argument 1 de issubclass() doit être une classe" @@ -3718,11 +3720,11 @@ msgstr "les opérandes ne pouvaient pas être diffusés ensemble" #: extmod/ulab/code/ndarray.c msgid "operation is implemented for 1D Boolean arrays only" -msgstr "opération implémentée que pour des tableaux 1D booléennes" +msgstr "opération implémentée que pour les matrices 1D booléennes" #: extmod/ulab/code/numpy/numerical/numerical.c msgid "operation is not implemented on ndarrays" -msgstr "l'opération n'est pas implémentée sur les ndarrays" +msgstr "l'opération n'est pas implémentée pour les ndarrays" #: extmod/ulab/code/ndarray.c msgid "operation is not supported for given type" @@ -3741,11 +3743,11 @@ msgstr "" #: extmod/ulab/code/utils/utils.c msgid "out array is too small" -msgstr "" +msgstr "matrice de sortie est trop petite" #: extmod/ulab/code/utils/utils.c msgid "out must be a float dense array" -msgstr "" +msgstr "la matrice sortante doit être de type float" #: shared-bindings/displayio/Bitmap.c msgid "out of range of source" @@ -3831,6 +3833,7 @@ msgstr "pow() avec 3 arguments nécessite des entiers" #: ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h #: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h #: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h +#: ports/esp32s2/boards/artisense_rd00/mpconfigboard.h #: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h #: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h #: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h @@ -3856,6 +3859,10 @@ msgstr "bouton boot appuyé lors du démarrage.\n" msgid "pressing both buttons at start up.\n" msgstr "les deux boutons appuyés lors du démarrage.\n" +#: ports/nrf/boards/aramcon2_badge/mpconfigboard.h +msgid "pressing the left button at start up\n" +msgstr "" + #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "pull masks conflict with direction masks" msgstr "masque pull est en conflit avec les masques de direction" @@ -3924,8 +3931,8 @@ msgid "" "sample_source buffer must be a bytearray or array of type 'h', 'H', 'b' or " "'B'" msgstr "" -"le tampon de sample_source doit être un bytearray ou un tableau de type " -"'h','H', 'b' ou 'B'" +"tampon sample_source doit être un bytearray ou une matrice de type 'h', 'H', " +"'b' ou 'B'" #: ports/atmel-samd/common-hal/audiobusio/PDMIn.c #: ports/raspberrypi/common-hal/audiobusio/PDMIn.c @@ -3962,7 +3969,7 @@ msgstr "'}' seule rencontrée dans une chaîne de format" #: extmod/ulab/code/ulab_tools.c msgid "size is defined for ndarrays only" -msgstr "la taille est définie pour les ndarrays uniquement" +msgstr "la taille n'est définie que pour les ndarrays" #: shared-bindings/time/__init__.c msgid "sleep length must be non-negative" @@ -3986,11 +3993,11 @@ msgstr "redémarrage logiciel\n" #: extmod/ulab/code/numpy/numerical/numerical.c msgid "sort argument must be an ndarray" -msgstr "l'argument de «sort» doit être un ndarray" +msgstr "le paramètre de «sort» doit être un ndarray" #: extmod/ulab/code/scipy/signal/signal.c msgid "sos array must be of shape (n_section, 6)" -msgstr "le tableau sos doit être de forme (n_section, 6)" +msgstr "la matrice sos doit être de forme (n_section, 6)" #: extmod/ulab/code/scipy/signal/signal.c msgid "sos[:, 3] should be all ones" @@ -4035,7 +4042,7 @@ msgstr "les indices d'une chaîne doivent être des entiers, pas %q" #: py/stream.c msgid "string not supported; use bytes or bytearray" msgstr "" -"chaîne de carac. non supportée ; utilisez des bytes ou un tableau de bytes" +"chaîne de carac. non supportée; utilisez des bytes ou une matrice de bytes" #: extmod/moductypes.c msgid "struct: cannot index" @@ -4105,7 +4112,7 @@ msgstr "timestamp hors bornes pour 'time_t' de la plateforme" #: extmod/ulab/code/ndarray.c msgid "tobytes can be invoked for dense arrays only" -msgstr "tobytes ne peut être appelé que pour des tableaux dense" +msgstr "tobytes ne peut être appelée que pour des matrices dense" #: shared-module/struct/__init__.c msgid "too many arguments provided with the given format" @@ -4126,15 +4133,11 @@ msgstr "trop de valeur à dégrouper (%d attendues)" #: extmod/ulab/code/numpy/approx/approx.c msgid "trapz is defined for 1D arrays" -msgstr "trapz est défini pour tableaux à une dimension" +msgstr "trapz est définie pour matrices à une dimension" #: extmod/ulab/code/numpy/approx/approx.c msgid "trapz is defined for 1D arrays of equal length" -msgstr "trapz n'est défini que pour des tableaux 1D de longueur égale" - -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "trigger level must be 0 or 1" -msgstr "niveau du déclencheur doit être 0 ou 1" +msgstr "trapz n'est défini que pour des matrices 1D de longueur égales" #: py/obj.c msgid "tuple/list has wrong length" @@ -4270,10 +4273,6 @@ msgstr "la valeur doit tenir dans %d octet(s)" msgid "value_count must be > 0" msgstr "'value_count' doit être > 0" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "wakeup conflict" -msgstr "conflit au réveil" - #: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c msgid "watchdog not initialized" msgstr "chien de garde (watchdog) non initialisé" @@ -4350,7 +4349,7 @@ msgstr "'step' nul" #: extmod/ulab/code/scipy/signal/signal.c msgid "zi must be an ndarray" -msgstr "zi doit être ndarray" +msgstr "zi doit être un ndarray" #: extmod/ulab/code/scipy/signal/signal.c msgid "zi must be of float type" @@ -4360,6 +4359,32 @@ msgstr "zi doit être de type float" msgid "zi must be of shape (n_section, 2)" msgstr "zi doit être de forme (n_section, 2)" +#~ msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" +#~ msgstr "IOs 0, 2 & 4 ne supportent pas l'éleveuse interne en mode someil" + +#~ msgid "buffer must be a bytes-like object" +#~ msgstr "le tampon doit être un objet bytes-like" + +#~ msgid "io must be rtc io" +#~ msgstr "io doit être rtc io" + +#~ msgid "trigger level must be 0 or 1" +#~ msgstr "niveau du déclencheur doit être 0 ou 1" + +#~ msgid "wakeup conflict" +#~ msgstr "conflit au réveil" + +#~ msgid "Attempted heap allocation when MicroPython VM not running." +#~ msgstr "" +#~ "Tentative d'allocation de segments lorsque la machine virtuelle " +#~ "MicroPython n'est pas en cours d'exécution." + +#~ msgid "MicroPython NLR jump failed. Likely memory corruption." +#~ msgstr "Échec du saut MicroPython NLR. Corruption de la mémoire probable." + +#~ msgid "MicroPython fatal error." +#~ msgstr "Erreur fatale MicroPython." + #~ msgid "argument must be ndarray" #~ msgstr "l'argument doit être un ndarray" diff --git a/locale/hi.po b/locale/hi.po index 388a85472b..b1a5c0d5dd 100644 --- a/locale/hi.po +++ b/locale/hi.po @@ -438,7 +438,7 @@ msgid "Attempt to allocate %d blocks" msgstr "" #: supervisor/shared/safe_mode.c -msgid "Attempted heap allocation when MicroPython VM not running." +msgid "Attempted heap allocation when VM not running." msgstr "" #: shared-bindings/wifi/Radio.c @@ -879,6 +879,11 @@ msgstr "" msgid "EXTINT channel already in use" msgstr "" +#: shared-module/synthio/MidiTrack.c +#, c-format +msgid "Error in MIDI stream at position %d" +msgstr "" + #: extmod/modure.c msgid "Error in regex" msgstr "" @@ -1008,6 +1013,10 @@ msgstr "" msgid "Failed to write internal flash." msgstr "" +#: supervisor/shared/safe_mode.c +msgid "Fatal error." +msgstr "" + #: py/moduerrno.c msgid "File exists" msgstr "" @@ -1080,10 +1089,6 @@ msgstr "" msgid "I2SOut not available" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" -msgstr "" - #: shared-bindings/aesio/aes.c #, c-format msgid "IV must be %d bytes long" @@ -1207,6 +1212,10 @@ msgstr "" msgid "Invalid DAC pin supplied" msgstr "" +#: shared-bindings/synthio/__init__.c +msgid "Invalid MIDI file" +msgstr "" + #: ports/atmel-samd/common-hal/pwmio/PWMOut.c #: ports/cxd56/common-hal/pwmio/PWMOut.c #: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c @@ -1398,14 +1407,6 @@ msgstr "" msgid "Messages limited to 8 bytes" msgstr "" -#: supervisor/shared/safe_mode.c -msgid "MicroPython NLR jump failed. Likely memory corruption." -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "MicroPython fatal error." -msgstr "" - #: shared-bindings/audiobusio/PDMIn.c msgid "Microphone startup delay must be in range 0.0 to 1.0" msgstr "" @@ -1457,6 +1458,10 @@ msgstr "" msgid "Must use a multiple of 6 rgb pins, not %d" msgstr "" +#: supervisor/shared/safe_mode.c +msgid "NLR jump failed. Likely memory corruption." +msgstr "" + #: ports/esp32s2/common-hal/nvm/ByteArray.c msgid "NVS Error" msgstr "" @@ -1601,6 +1606,7 @@ msgstr "" msgid "Not a valid IP string" msgstr "" +#: ports/nrf/common-hal/_bleio/PacketBuffer.c #: ports/nrf/common-hal/_bleio/__init__.c #: shared-bindings/_bleio/CharacteristicBuffer.c msgid "Not connected" @@ -2493,10 +2499,6 @@ msgstr "" msgid "buffer is smaller than requested size" msgstr "" -#: shared-bindings/audiocore/RawSample.c -msgid "buffer must be a bytes-like object" -msgstr "" - #: extmod/ulab/code/ulab_create.c extmod/ulab/code/utils/utils.c msgid "buffer size must be a multiple of element size" msgstr "" @@ -2938,7 +2940,7 @@ msgid "f-string: single '}' is not allowed" msgstr "" #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c -#: shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" msgstr "" @@ -3194,6 +3196,10 @@ msgstr "" msgid "invalid cert" msgstr "" +#: py/compile.c +msgid "invalid decorator" +msgstr "" + #: extmod/uos_dupterm.c msgid "invalid dupterm index" msgstr "" @@ -3249,10 +3255,6 @@ msgstr "" msgid "invalid syntax for number" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "io must be rtc io" -msgstr "" - #: py/objtype.c msgid "issubclass() arg 1 must be a class" msgstr "" @@ -3712,6 +3714,7 @@ msgstr "" #: ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h #: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h #: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h +#: ports/esp32s2/boards/artisense_rd00/mpconfigboard.h #: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h #: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h #: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h @@ -3737,6 +3740,10 @@ msgstr "" msgid "pressing both buttons at start up.\n" msgstr "" +#: ports/nrf/boards/aramcon2_badge/mpconfigboard.h +msgid "pressing the left button at start up\n" +msgstr "" + #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "pull masks conflict with direction masks" msgstr "" @@ -4010,10 +4017,6 @@ msgstr "" msgid "trapz is defined for 1D arrays of equal length" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "trigger level must be 0 or 1" -msgstr "" - #: py/obj.c msgid "tuple/list has wrong length" msgstr "" @@ -4148,10 +4151,6 @@ msgstr "" msgid "value_count must be > 0" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "wakeup conflict" -msgstr "" - #: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c msgid "watchdog not initialized" msgstr "" diff --git a/locale/it_IT.po b/locale/it_IT.po index 241b07d7ec..a9865b99bf 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -450,8 +450,8 @@ msgid "Attempt to allocate %d blocks" msgstr "Provo ad allocare %d blocchi" #: supervisor/shared/safe_mode.c -msgid "Attempted heap allocation when MicroPython VM not running." -msgstr "Provo l'allocazione quando MicroPython VM non è attivo." +msgid "Attempted heap allocation when VM not running." +msgstr "" #: shared-bindings/wifi/Radio.c msgid "Authentication failure" @@ -899,6 +899,11 @@ msgstr "" msgid "EXTINT channel already in use" msgstr "Canale EXTINT già in uso" +#: shared-module/synthio/MidiTrack.c +#, c-format +msgid "Error in MIDI stream at position %d" +msgstr "" + #: extmod/modure.c msgid "Error in regex" msgstr "Errore nella regex" @@ -1030,6 +1035,10 @@ msgstr "Impossibile rilasciare il mutex, err 0x%04x" msgid "Failed to write internal flash." msgstr "" +#: supervisor/shared/safe_mode.c +msgid "Fatal error." +msgstr "" + #: py/moduerrno.c msgid "File exists" msgstr "File esistente" @@ -1102,10 +1111,6 @@ msgstr "" msgid "I2SOut not available" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" -msgstr "" - #: shared-bindings/aesio/aes.c #, c-format msgid "IV must be %d bytes long" @@ -1231,6 +1236,10 @@ msgstr "" msgid "Invalid DAC pin supplied" msgstr "" +#: shared-bindings/synthio/__init__.c +msgid "Invalid MIDI file" +msgstr "" + #: ports/atmel-samd/common-hal/pwmio/PWMOut.c #: ports/cxd56/common-hal/pwmio/PWMOut.c #: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c @@ -1425,14 +1434,6 @@ msgstr "Valore massimo di x quando rispachiato è %d" msgid "Messages limited to 8 bytes" msgstr "" -#: supervisor/shared/safe_mode.c -msgid "MicroPython NLR jump failed. Likely memory corruption." -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "MicroPython fatal error." -msgstr "" - #: shared-bindings/audiobusio/PDMIn.c msgid "Microphone startup delay must be in range 0.0 to 1.0" msgstr "" @@ -1485,6 +1486,10 @@ msgstr "" msgid "Must use a multiple of 6 rgb pins, not %d" msgstr "" +#: supervisor/shared/safe_mode.c +msgid "NLR jump failed. Likely memory corruption." +msgstr "" + #: ports/esp32s2/common-hal/nvm/ByteArray.c msgid "NVS Error" msgstr "" @@ -1629,6 +1634,7 @@ msgstr "" msgid "Not a valid IP string" msgstr "" +#: ports/nrf/common-hal/_bleio/PacketBuffer.c #: ports/nrf/common-hal/_bleio/__init__.c #: shared-bindings/_bleio/CharacteristicBuffer.c #, fuzzy @@ -2538,10 +2544,6 @@ msgstr "argomento di chr() non è in range(256)" msgid "buffer is smaller than requested size" msgstr "" -#: shared-bindings/audiocore/RawSample.c -msgid "buffer must be a bytes-like object" -msgstr "" - #: extmod/ulab/code/ulab_create.c extmod/ulab/code/utils/utils.c msgid "buffer size must be a multiple of element size" msgstr "" @@ -2991,7 +2993,7 @@ msgid "f-string: single '}' is not allowed" msgstr "" #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c -#: shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" msgstr "" @@ -3248,6 +3250,10 @@ msgstr "" msgid "invalid cert" msgstr "certificato non valido" +#: py/compile.c +msgid "invalid decorator" +msgstr "" + #: extmod/uos_dupterm.c msgid "invalid dupterm index" msgstr "indice dupterm non valido" @@ -3303,10 +3309,6 @@ msgstr "sintassi invalida per l'intero con base %d" msgid "invalid syntax for number" msgstr "sintassi invalida per il numero" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "io must be rtc io" -msgstr "" - #: py/objtype.c msgid "issubclass() arg 1 must be a class" msgstr "il primo argomento di issubclass() deve essere una classe" @@ -3778,6 +3780,7 @@ msgstr "pow() con 3 argomenti richiede interi" #: ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h #: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h #: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h +#: ports/esp32s2/boards/artisense_rd00/mpconfigboard.h #: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h #: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h #: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h @@ -3803,6 +3806,10 @@ msgstr "" msgid "pressing both buttons at start up.\n" msgstr "" +#: ports/nrf/boards/aramcon2_badge/mpconfigboard.h +msgid "pressing the left button at start up\n" +msgstr "" + #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "pull masks conflict with direction masks" msgstr "" @@ -4080,10 +4087,6 @@ msgstr "" msgid "trapz is defined for 1D arrays of equal length" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "trigger level must be 0 or 1" -msgstr "" - #: py/obj.c msgid "tuple/list has wrong length" msgstr "tupla/lista ha la lunghezza sbagliata" @@ -4218,10 +4221,6 @@ msgstr "" msgid "value_count must be > 0" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "wakeup conflict" -msgstr "" - #: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c msgid "watchdog not initialized" msgstr "" @@ -4310,6 +4309,9 @@ msgstr "" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "Attempted heap allocation when MicroPython VM not running." +#~ msgstr "Provo l'allocazione quando MicroPython VM non è attivo." + #~ msgid "Group full" #~ msgstr "Gruppo pieno" diff --git a/locale/ja.po b/locale/ja.po index e2b5d926af..36b19d14c5 100644 --- a/locale/ja.po +++ b/locale/ja.po @@ -443,8 +443,8 @@ msgid "Attempt to allocate %d blocks" msgstr "%d個のブロックの確保を試みました" #: supervisor/shared/safe_mode.c -msgid "Attempted heap allocation when MicroPython VM not running." -msgstr "MicroPython VMの非実行時にヒープ確保を試みました" +msgid "Attempted heap allocation when VM not running." +msgstr "" #: shared-bindings/wifi/Radio.c msgid "Authentication failure" @@ -890,6 +890,11 @@ msgstr "" msgid "EXTINT channel already in use" msgstr "EXTINTチャネルはすでに使用されています" +#: shared-module/synthio/MidiTrack.c +#, c-format +msgid "Error in MIDI stream at position %d" +msgstr "" + #: extmod/modure.c msgid "Error in regex" msgstr "正規表現にエラーがあります" @@ -1019,6 +1024,10 @@ msgstr "ミューテックスの開放に失敗。エラー 0x%04x" msgid "Failed to write internal flash." msgstr "内部フラッシュ書き込みに失敗" +#: supervisor/shared/safe_mode.c +msgid "Fatal error." +msgstr "" + #: py/moduerrno.c msgid "File exists" msgstr "ファイルが存在します" @@ -1091,10 +1100,6 @@ msgstr "" msgid "I2SOut not available" msgstr "I2SOutが利用できません" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" -msgstr "" - #: shared-bindings/aesio/aes.c #, c-format msgid "IV must be %d bytes long" @@ -1220,6 +1225,10 @@ msgstr "不正なBSSID" msgid "Invalid DAC pin supplied" msgstr "不正なDACピンが与えられました" +#: shared-bindings/synthio/__init__.c +msgid "Invalid MIDI file" +msgstr "" + #: ports/atmel-samd/common-hal/pwmio/PWMOut.c #: ports/cxd56/common-hal/pwmio/PWMOut.c #: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c @@ -1411,14 +1420,6 @@ msgstr "" msgid "Messages limited to 8 bytes" msgstr "" -#: supervisor/shared/safe_mode.c -msgid "MicroPython NLR jump failed. Likely memory corruption." -msgstr "MicroPython NLRジャンプ失敗。メモリ破壊の可能性あり" - -#: supervisor/shared/safe_mode.c -msgid "MicroPython fatal error." -msgstr "MicroPython致命的エラー" - #: shared-bindings/audiobusio/PDMIn.c msgid "Microphone startup delay must be in range 0.0 to 1.0" msgstr "マイクのスタートアップディレイは 0.0 から 1.0 の間でなければなりません" @@ -1470,6 +1471,10 @@ msgstr "MISOピンまたはMOSIピンが必要" msgid "Must use a multiple of 6 rgb pins, not %d" msgstr "%d個でなく6の倍数個のrgbピンを使ってください" +#: supervisor/shared/safe_mode.c +msgid "NLR jump failed. Likely memory corruption." +msgstr "" + #: ports/esp32s2/common-hal/nvm/ByteArray.c msgid "NVS Error" msgstr "" @@ -1614,6 +1619,7 @@ msgstr "" msgid "Not a valid IP string" msgstr "不正なIP文字列です" +#: ports/nrf/common-hal/_bleio/PacketBuffer.c #: ports/nrf/common-hal/_bleio/__init__.c #: shared-bindings/_bleio/CharacteristicBuffer.c msgid "Not connected" @@ -2516,10 +2522,6 @@ msgstr "" msgid "buffer is smaller than requested size" msgstr "" -#: shared-bindings/audiocore/RawSample.c -msgid "buffer must be a bytes-like object" -msgstr "バッファはbytes-likeオブジェクトでなければなりません" - #: extmod/ulab/code/ulab_create.c extmod/ulab/code/utils/utils.c msgid "buffer size must be a multiple of element size" msgstr "" @@ -2965,7 +2967,7 @@ msgid "f-string: single '}' is not allowed" msgstr "f-string: 1つだけの'}'は許されません" #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c -#: shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" msgstr "fileはバイトモードで開かれたファイルでなければなりません" @@ -3222,6 +3224,10 @@ msgstr "" msgid "invalid cert" msgstr "不正な証明書" +#: py/compile.c +msgid "invalid decorator" +msgstr "" + #: extmod/uos_dupterm.c msgid "invalid dupterm index" msgstr "不正なduptermインデクス" @@ -3277,10 +3283,6 @@ msgstr "" msgid "invalid syntax for number" msgstr "数字として不正な構文" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "io must be rtc io" -msgstr "" - #: py/objtype.c msgid "issubclass() arg 1 must be a class" msgstr "issubclass()の第1引数はクラスでなければなりません" @@ -3742,6 +3744,7 @@ msgstr "pow()の第3引数には整数が必要" #: ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h #: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h #: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h +#: ports/esp32s2/boards/artisense_rd00/mpconfigboard.h #: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h #: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h #: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h @@ -3767,6 +3770,10 @@ msgstr "" msgid "pressing both buttons at start up.\n" msgstr "" +#: ports/nrf/boards/aramcon2_badge/mpconfigboard.h +msgid "pressing the left button at start up\n" +msgstr "" + #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "pull masks conflict with direction masks" msgstr "" @@ -4041,10 +4048,6 @@ msgstr "" msgid "trapz is defined for 1D arrays of equal length" msgstr "trapzは同じ長さの1次元arrayに対して定義されています" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "trigger level must be 0 or 1" -msgstr "" - #: py/obj.c msgid "tuple/list has wrong length" msgstr "タプル/リストの長さが正しくありません" @@ -4179,10 +4182,6 @@ msgstr "値は%dバイトに収まらなければなりません" msgid "value_count must be > 0" msgstr "value_countは0より大きくなければなりません" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "wakeup conflict" -msgstr "" - #: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c msgid "watchdog not initialized" msgstr "" @@ -4269,6 +4268,18 @@ msgstr "ziはfloat値でなければなりません" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "buffer must be a bytes-like object" +#~ msgstr "バッファはbytes-likeオブジェクトでなければなりません" + +#~ msgid "Attempted heap allocation when MicroPython VM not running." +#~ msgstr "MicroPython VMの非実行時にヒープ確保を試みました" + +#~ msgid "MicroPython NLR jump failed. Likely memory corruption." +#~ msgstr "MicroPython NLRジャンプ失敗。メモリ破壊の可能性あり" + +#~ msgid "MicroPython fatal error." +#~ msgstr "MicroPython致命的エラー" + #~ msgid "argument must be ndarray" #~ msgstr "引数はndarrayでなければなりません" diff --git a/locale/ko.po b/locale/ko.po index 3b8eeebe6d..fe5ce58d9a 100644 --- a/locale/ko.po +++ b/locale/ko.po @@ -439,7 +439,7 @@ msgid "Attempt to allocate %d blocks" msgstr "" #: supervisor/shared/safe_mode.c -msgid "Attempted heap allocation when MicroPython VM not running." +msgid "Attempted heap allocation when VM not running." msgstr "" #: shared-bindings/wifi/Radio.c @@ -882,6 +882,11 @@ msgstr "" msgid "EXTINT channel already in use" msgstr "" +#: shared-module/synthio/MidiTrack.c +#, c-format +msgid "Error in MIDI stream at position %d" +msgstr "" + #: extmod/modure.c msgid "Error in regex" msgstr "Regex에 오류가 있습니다." @@ -1011,6 +1016,10 @@ msgstr "" msgid "Failed to write internal flash." msgstr "" +#: supervisor/shared/safe_mode.c +msgid "Fatal error." +msgstr "" + #: py/moduerrno.c msgid "File exists" msgstr "" @@ -1083,10 +1092,6 @@ msgstr "" msgid "I2SOut not available" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" -msgstr "" - #: shared-bindings/aesio/aes.c #, c-format msgid "IV must be %d bytes long" @@ -1210,6 +1215,10 @@ msgstr "" msgid "Invalid DAC pin supplied" msgstr "" +#: shared-bindings/synthio/__init__.c +msgid "Invalid MIDI file" +msgstr "" + #: ports/atmel-samd/common-hal/pwmio/PWMOut.c #: ports/cxd56/common-hal/pwmio/PWMOut.c #: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c @@ -1401,14 +1410,6 @@ msgstr "" msgid "Messages limited to 8 bytes" msgstr "" -#: supervisor/shared/safe_mode.c -msgid "MicroPython NLR jump failed. Likely memory corruption." -msgstr "" - -#: supervisor/shared/safe_mode.c -msgid "MicroPython fatal error." -msgstr "" - #: shared-bindings/audiobusio/PDMIn.c msgid "Microphone startup delay must be in range 0.0 to 1.0" msgstr "" @@ -1460,6 +1461,10 @@ msgstr "" msgid "Must use a multiple of 6 rgb pins, not %d" msgstr "" +#: supervisor/shared/safe_mode.c +msgid "NLR jump failed. Likely memory corruption." +msgstr "" + #: ports/esp32s2/common-hal/nvm/ByteArray.c msgid "NVS Error" msgstr "" @@ -1604,6 +1609,7 @@ msgstr "" msgid "Not a valid IP string" msgstr "" +#: ports/nrf/common-hal/_bleio/PacketBuffer.c #: ports/nrf/common-hal/_bleio/__init__.c #: shared-bindings/_bleio/CharacteristicBuffer.c msgid "Not connected" @@ -2497,10 +2503,6 @@ msgstr "" msgid "buffer is smaller than requested size" msgstr "" -#: shared-bindings/audiocore/RawSample.c -msgid "buffer must be a bytes-like object" -msgstr "" - #: extmod/ulab/code/ulab_create.c extmod/ulab/code/utils/utils.c msgid "buffer size must be a multiple of element size" msgstr "" @@ -2942,7 +2944,7 @@ msgid "f-string: single '}' is not allowed" msgstr "" #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c -#: shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" msgstr "" @@ -3198,6 +3200,10 @@ msgstr "" msgid "invalid cert" msgstr "cert가 유효하지 않습니다" +#: py/compile.c +msgid "invalid decorator" +msgstr "" + #: extmod/uos_dupterm.c msgid "invalid dupterm index" msgstr "Dupterm index가 유효하지 않습니다" @@ -3253,10 +3259,6 @@ msgstr "구문(syntax)가 정수가 유효하지 않습니다" msgid "invalid syntax for number" msgstr "숫자에 대한 구문(syntax)가 유효하지 않습니다" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "io must be rtc io" -msgstr "" - #: py/objtype.c msgid "issubclass() arg 1 must be a class" msgstr "" @@ -3716,6 +3718,7 @@ msgstr "" #: ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h #: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h #: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h +#: ports/esp32s2/boards/artisense_rd00/mpconfigboard.h #: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h #: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h #: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h @@ -3741,6 +3744,10 @@ msgstr "" msgid "pressing both buttons at start up.\n" msgstr "" +#: ports/nrf/boards/aramcon2_badge/mpconfigboard.h +msgid "pressing the left button at start up\n" +msgstr "" + #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "pull masks conflict with direction masks" msgstr "" @@ -4014,10 +4021,6 @@ msgstr "" msgid "trapz is defined for 1D arrays of equal length" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "trigger level must be 0 or 1" -msgstr "" - #: py/obj.c msgid "tuple/list has wrong length" msgstr "" @@ -4152,10 +4155,6 @@ msgstr "" msgid "value_count must be > 0" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "wakeup conflict" -msgstr "" - #: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c msgid "watchdog not initialized" msgstr "" diff --git a/locale/nl.po b/locale/nl.po index 3285f52150..27f12fba3a 100644 --- a/locale/nl.po +++ b/locale/nl.po @@ -441,8 +441,8 @@ msgid "Attempt to allocate %d blocks" msgstr "Poging om %d blokken toe te wijzen" #: supervisor/shared/safe_mode.c -msgid "Attempted heap allocation when MicroPython VM not running." -msgstr "heap allocatie geprobeerd terwijl MicroPython VM niet draait." +msgid "Attempted heap allocation when VM not running." +msgstr "" #: shared-bindings/wifi/Radio.c msgid "Authentication failure" @@ -890,6 +890,11 @@ msgstr "ESP-IDF geheugen toewijzing mislukt" msgid "EXTINT channel already in use" msgstr "EXTINT kanaal al in gebruik" +#: shared-module/synthio/MidiTrack.c +#, c-format +msgid "Error in MIDI stream at position %d" +msgstr "" + #: extmod/modure.c msgid "Error in regex" msgstr "Fout in regex" @@ -1019,6 +1024,10 @@ msgstr "Mislukt mutex los te laten, err 0x%04x" msgid "Failed to write internal flash." msgstr "Schrijven naar interne flash mislukt." +#: supervisor/shared/safe_mode.c +msgid "Fatal error." +msgstr "" + #: py/moduerrno.c msgid "File exists" msgstr "Bestand bestaat" @@ -1092,10 +1101,6 @@ msgstr "" msgid "I2SOut not available" msgstr "I2SOut is niet beschikbaar" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" -msgstr "IO's 0, 2 en 4 ondersteunen geen interne pullup in slaapstand" - #: shared-bindings/aesio/aes.c #, c-format msgid "IV must be %d bytes long" @@ -1221,6 +1226,10 @@ msgstr "Ongeldig BSSID" msgid "Invalid DAC pin supplied" msgstr "Ongeldige DAC pin opgegeven" +#: shared-bindings/synthio/__init__.c +msgid "Invalid MIDI file" +msgstr "" + #: ports/atmel-samd/common-hal/pwmio/PWMOut.c #: ports/cxd56/common-hal/pwmio/PWMOut.c #: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c @@ -1412,14 +1421,6 @@ msgstr "Maximale x waarde indien gespiegeld is %d" msgid "Messages limited to 8 bytes" msgstr "Berichten zijn beperkt tot 8 bytes" -#: supervisor/shared/safe_mode.c -msgid "MicroPython NLR jump failed. Likely memory corruption." -msgstr "MicroPython NLR sprong mislukt. Waarschijnlijk geheugen corruptie." - -#: supervisor/shared/safe_mode.c -msgid "MicroPython fatal error." -msgstr "MicroPython fatale fout." - #: shared-bindings/audiobusio/PDMIn.c msgid "Microphone startup delay must be in range 0.0 to 1.0" msgstr "Microfoon opstart vertraging moet in bereik van 0.0 tot 1.0 zijn" @@ -1471,6 +1472,10 @@ msgstr "MISO of MOSI moeten worden gegeven" msgid "Must use a multiple of 6 rgb pins, not %d" msgstr "Een meervoud van 6 rgb pinnen moet worden gebruikt, niet %d" +#: supervisor/shared/safe_mode.c +msgid "NLR jump failed. Likely memory corruption." +msgstr "" + #: ports/esp32s2/common-hal/nvm/ByteArray.c msgid "NVS Error" msgstr "NVS-fout" @@ -1615,6 +1620,7 @@ msgstr "" msgid "Not a valid IP string" msgstr "Geen geldige IP string" +#: ports/nrf/common-hal/_bleio/PacketBuffer.c #: ports/nrf/common-hal/_bleio/__init__.c #: shared-bindings/_bleio/CharacteristicBuffer.c msgid "Not connected" @@ -2544,10 +2550,6 @@ msgstr "pad (branch) niet binnen bereik" msgid "buffer is smaller than requested size" msgstr "" -#: shared-bindings/audiocore/RawSample.c -msgid "buffer must be a bytes-like object" -msgstr "buffer moet een byte-achtig object zijn" - #: extmod/ulab/code/ulab_create.c extmod/ulab/code/utils/utils.c msgid "buffer size must be a multiple of element size" msgstr "" @@ -2993,7 +2995,7 @@ msgid "f-string: single '}' is not allowed" msgstr "f-string: enkele '}' is niet toegestaan" #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c -#: shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" msgstr "bestand moet een bestand zijn geopend in byte modus" @@ -3250,6 +3252,10 @@ msgstr "" msgid "invalid cert" msgstr "ongeldig certificaat" +#: py/compile.c +msgid "invalid decorator" +msgstr "" + #: extmod/uos_dupterm.c msgid "invalid dupterm index" msgstr "ongeldige dupterm index" @@ -3305,10 +3311,6 @@ msgstr "ongeldige syntax voor integer met grondtal %d" msgid "invalid syntax for number" msgstr "ongeldige syntax voor nummer" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "io must be rtc io" -msgstr "io moet rtc io zijn" - #: py/objtype.c msgid "issubclass() arg 1 must be a class" msgstr "issubclass() argument 1 moet een klasse zijn" @@ -3772,6 +3774,7 @@ msgstr "pow() met 3 argumenten vereist integers" #: ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h #: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h #: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h +#: ports/esp32s2/boards/artisense_rd00/mpconfigboard.h #: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h #: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h #: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h @@ -3797,6 +3800,10 @@ msgstr "druk bootknop in bij opstarten.\n" msgid "pressing both buttons at start up.\n" msgstr "druk beide knoppen in bij opstarten.\n" +#: ports/nrf/boards/aramcon2_badge/mpconfigboard.h +msgid "pressing the left button at start up\n" +msgstr "" + #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "pull masks conflict with direction masks" msgstr "" @@ -4072,10 +4079,6 @@ msgstr "" msgid "trapz is defined for 1D arrays of equal length" msgstr "trapz is gedefinieerd voor eendimensionale arrays van gelijke lengte" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "trigger level must be 0 or 1" -msgstr "triggerniveau moet 0 of 1 zijn" - #: py/obj.c msgid "tuple/list has wrong length" msgstr "tuple of lijst heeft onjuiste lengte" @@ -4210,10 +4213,6 @@ msgstr "waarde moet in %d byte(s) passen" msgid "value_count must be > 0" msgstr "value_count moet groter dan 0 zijn" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "wakeup conflict" -msgstr "conflict bij ontwaken" - #: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c msgid "watchdog not initialized" msgstr "watchdog niet geïnitialiseerd" @@ -4300,6 +4299,30 @@ msgstr "zi moet van type float zijn" msgid "zi must be of shape (n_section, 2)" msgstr "zi moet vorm (n_section, 2) hebben" +#~ msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" +#~ msgstr "IO's 0, 2 en 4 ondersteunen geen interne pullup in slaapstand" + +#~ msgid "buffer must be a bytes-like object" +#~ msgstr "buffer moet een byte-achtig object zijn" + +#~ msgid "io must be rtc io" +#~ msgstr "io moet rtc io zijn" + +#~ msgid "trigger level must be 0 or 1" +#~ msgstr "triggerniveau moet 0 of 1 zijn" + +#~ msgid "wakeup conflict" +#~ msgstr "conflict bij ontwaken" + +#~ msgid "Attempted heap allocation when MicroPython VM not running." +#~ msgstr "heap allocatie geprobeerd terwijl MicroPython VM niet draait." + +#~ msgid "MicroPython NLR jump failed. Likely memory corruption." +#~ msgstr "MicroPython NLR sprong mislukt. Waarschijnlijk geheugen corruptie." + +#~ msgid "MicroPython fatal error." +#~ msgstr "MicroPython fatale fout." + #~ msgid "argument must be ndarray" #~ msgstr "argument moet ndarray zijn" diff --git a/locale/pl.po b/locale/pl.po index 295901c994..234c2ba998 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -443,8 +443,8 @@ msgid "Attempt to allocate %d blocks" msgstr "Próba przydzielenia %d bloków" #: supervisor/shared/safe_mode.c -msgid "Attempted heap allocation when MicroPython VM not running." -msgstr "Próba przydziału sterty, gdy MicroPython VM nie działa." +msgid "Attempted heap allocation when VM not running." +msgstr "" #: shared-bindings/wifi/Radio.c msgid "Authentication failure" @@ -890,6 +890,11 @@ msgstr "" msgid "EXTINT channel already in use" msgstr "Kanał EXTINT w użyciu" +#: shared-module/synthio/MidiTrack.c +#, c-format +msgid "Error in MIDI stream at position %d" +msgstr "" + #: extmod/modure.c msgid "Error in regex" msgstr "Błąd w regex" @@ -1019,6 +1024,10 @@ msgstr "Nie udało się zwolnić blokady, błąd 0x%04x" msgid "Failed to write internal flash." msgstr "Nie udało się zapisać wewnętrznej pamięci flash." +#: supervisor/shared/safe_mode.c +msgid "Fatal error." +msgstr "" + #: py/moduerrno.c msgid "File exists" msgstr "Plik istnieje" @@ -1091,10 +1100,6 @@ msgstr "" msgid "I2SOut not available" msgstr "I2SOut niedostępne" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" -msgstr "" - #: shared-bindings/aesio/aes.c #, c-format msgid "IV must be %d bytes long" @@ -1220,6 +1225,10 @@ msgstr "" msgid "Invalid DAC pin supplied" msgstr "" +#: shared-bindings/synthio/__init__.c +msgid "Invalid MIDI file" +msgstr "" + #: ports/atmel-samd/common-hal/pwmio/PWMOut.c #: ports/cxd56/common-hal/pwmio/PWMOut.c #: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c @@ -1411,15 +1420,6 @@ msgstr "Największa wartość x przy odwróceniu to %d" msgid "Messages limited to 8 bytes" msgstr "Wiadomości ograniczone do 8 bajtów" -#: supervisor/shared/safe_mode.c -msgid "MicroPython NLR jump failed. Likely memory corruption." -msgstr "" -"Skok MicroRython NLR nie powiódł się. Prawdopodobne uszkodzenie pamięci." - -#: supervisor/shared/safe_mode.c -msgid "MicroPython fatal error." -msgstr "Błąd krytyczny MicroPython." - #: shared-bindings/audiobusio/PDMIn.c msgid "Microphone startup delay must be in range 0.0 to 1.0" msgstr "Opóźnienie włączenia mikrofonu musi być w zakresie od 0.0 do 1.0" @@ -1471,6 +1471,10 @@ msgstr "Należy podać pin MISO lub MOSI" msgid "Must use a multiple of 6 rgb pins, not %d" msgstr "" +#: supervisor/shared/safe_mode.c +msgid "NLR jump failed. Likely memory corruption." +msgstr "" + #: ports/esp32s2/common-hal/nvm/ByteArray.c msgid "NVS Error" msgstr "" @@ -1615,6 +1619,7 @@ msgstr "" msgid "Not a valid IP string" msgstr "" +#: ports/nrf/common-hal/_bleio/PacketBuffer.c #: ports/nrf/common-hal/_bleio/__init__.c #: shared-bindings/_bleio/CharacteristicBuffer.c msgid "Not connected" @@ -2513,10 +2518,6 @@ msgstr "skok poza zakres" msgid "buffer is smaller than requested size" msgstr "" -#: shared-bindings/audiocore/RawSample.c -msgid "buffer must be a bytes-like object" -msgstr "bufor mysi być typu bytes" - #: extmod/ulab/code/ulab_create.c extmod/ulab/code/utils/utils.c msgid "buffer size must be a multiple of element size" msgstr "" @@ -2959,7 +2960,7 @@ msgid "f-string: single '}' is not allowed" msgstr "" #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c -#: shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" msgstr "file musi być otwarte w trybie bajtowym" @@ -3215,6 +3216,10 @@ msgstr "" msgid "invalid cert" msgstr "zły ceryfikat" +#: py/compile.c +msgid "invalid decorator" +msgstr "" + #: extmod/uos_dupterm.c msgid "invalid dupterm index" msgstr "zły indeks dupterm" @@ -3270,10 +3275,6 @@ msgstr "zła składnia dla liczby całkowitej w bazie %d" msgid "invalid syntax for number" msgstr "zła składnia dla liczby" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "io must be rtc io" -msgstr "" - #: py/objtype.c msgid "issubclass() arg 1 must be a class" msgstr "argument 1 dla issubclass() musi być klasą" @@ -3734,6 +3735,7 @@ msgstr "trzyargumentowe pow() wymaga liczb całkowitych" #: ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h #: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h #: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h +#: ports/esp32s2/boards/artisense_rd00/mpconfigboard.h #: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h #: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h #: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h @@ -3759,6 +3761,10 @@ msgstr "" msgid "pressing both buttons at start up.\n" msgstr "" +#: ports/nrf/boards/aramcon2_badge/mpconfigboard.h +msgid "pressing the left button at start up\n" +msgstr "" + #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "pull masks conflict with direction masks" msgstr "" @@ -4033,10 +4039,6 @@ msgstr "" msgid "trapz is defined for 1D arrays of equal length" msgstr "" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "trigger level must be 0 or 1" -msgstr "" - #: py/obj.c msgid "tuple/list has wrong length" msgstr "krotka/lista ma złą długość" @@ -4171,10 +4173,6 @@ msgstr "wartość musi mieścić się w %d bajtach" msgid "value_count must be > 0" msgstr "value_count musi być > 0" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "wakeup conflict" -msgstr "" - #: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c msgid "watchdog not initialized" msgstr "" @@ -4261,6 +4259,19 @@ msgstr "" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "buffer must be a bytes-like object" +#~ msgstr "bufor mysi być typu bytes" + +#~ msgid "Attempted heap allocation when MicroPython VM not running." +#~ msgstr "Próba przydziału sterty, gdy MicroPython VM nie działa." + +#~ msgid "MicroPython NLR jump failed. Likely memory corruption." +#~ msgstr "" +#~ "Skok MicroRython NLR nie powiódł się. Prawdopodobne uszkodzenie pamięci." + +#~ msgid "MicroPython fatal error." +#~ msgstr "Błąd krytyczny MicroPython." + #~ msgid "vectors must have same lengths" #~ msgstr "wektory muszą mieć identyczną długość" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 7643bcfb0d..adb54556be 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2021-04-07 12:23+0000\n" +"PO-Revision-Date: 2021-04-19 21:50+0000\n" "Last-Translator: Wellington Terumi Uemura \n" "Language-Team: \n" "Language: pt_BR\n" @@ -14,7 +14,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n > 1;\n" -"X-Generator: Weblate 4.6-dev\n" +"X-Generator: Weblate 4.7-dev\n" #: main.c msgid "" @@ -451,10 +451,9 @@ msgid "Attempt to allocate %d blocks" msgstr "Tentativa de alocar %d blocos" #: supervisor/shared/safe_mode.c -msgid "Attempted heap allocation when MicroPython VM not running." +msgid "Attempted heap allocation when VM not running." msgstr "" -"A tentativa da área de alocação dinâmica de variáveis (heap) quando o " -"MicroPython VM não está em execução." +"Tentativa de alocação das pilhas quando o VM não estiver em funcionamento." #: shared-bindings/wifi/Radio.c msgid "Authentication failure" @@ -908,6 +907,11 @@ msgstr "Houve uma falha na alocação da memória ESP-IDF" msgid "EXTINT channel already in use" msgstr "Canal EXTINT em uso" +#: shared-module/synthio/MidiTrack.c +#, c-format +msgid "Error in MIDI stream at position %d" +msgstr "Houve um erro no fluxo MIDI na posição %d" + #: extmod/modure.c msgid "Error in regex" msgstr "Erro no regex" @@ -1037,6 +1041,10 @@ msgstr "Houve uma falha ao liberar o mutex, err 0x%04x" msgid "Failed to write internal flash." msgstr "Falha ao gravar o flash interno." +#: supervisor/shared/safe_mode.c +msgid "Fatal error." +msgstr "Erro fatal." + #: py/moduerrno.c msgid "File exists" msgstr "Arquivo já existe" @@ -1110,10 +1118,6 @@ msgstr "Periférico I2C em uso" msgid "I2SOut not available" msgstr "O I2SOut não está disponível" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" -msgstr "IOs 0, 2 e 4 não suportam pullup interno em repouso (sleep)" - #: shared-bindings/aesio/aes.c #, c-format msgid "IV must be %d bytes long" @@ -1245,6 +1249,10 @@ msgstr "BSSID Inválido" msgid "Invalid DAC pin supplied" msgstr "O pino DAC informado é inválido" +#: shared-bindings/synthio/__init__.c +msgid "Invalid MIDI file" +msgstr "O arquivo MIDI é inválido" + #: ports/atmel-samd/common-hal/pwmio/PWMOut.c #: ports/cxd56/common-hal/pwmio/PWMOut.c #: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c @@ -1436,14 +1444,6 @@ msgstr "O valor máximo de x quando espelhado é %d" msgid "Messages limited to 8 bytes" msgstr "As mensagens estão limitadas a 8 bytes" -#: supervisor/shared/safe_mode.c -msgid "MicroPython NLR jump failed. Likely memory corruption." -msgstr "O salto do MicroPython NLR falhou. Possível corrupção de memória." - -#: supervisor/shared/safe_mode.c -msgid "MicroPython fatal error." -msgstr "Houve um erro fatal do MicroPython." - #: shared-bindings/audiobusio/PDMIn.c msgid "Microphone startup delay must be in range 0.0 to 1.0" msgstr "O atraso na inicialização do microfone deve estar entre 0,0 e 1,0" @@ -1495,6 +1495,10 @@ msgstr "Deve informar os pinos MISO ou MOSI" msgid "Must use a multiple of 6 rgb pins, not %d" msgstr "Deve utilizar um múltiplo de 6 pinos rgb, não %d" +#: supervisor/shared/safe_mode.c +msgid "NLR jump failed. Likely memory corruption." +msgstr "O salto NLR falhou. Possível corrupção da memória." + #: ports/esp32s2/common-hal/nvm/ByteArray.c msgid "NVS Error" msgstr "Erro NVS" @@ -1641,6 +1645,7 @@ msgstr "O firmware do sistema nórdico está sem memória" msgid "Not a valid IP string" msgstr "Não é uma sequência válida de IP" +#: ports/nrf/common-hal/_bleio/PacketBuffer.c #: ports/nrf/common-hal/_bleio/__init__.c #: shared-bindings/_bleio/CharacteristicBuffer.c msgid "Not connected" @@ -2579,10 +2584,6 @@ msgstr "ramo fora do alcance" msgid "buffer is smaller than requested size" msgstr "o tamanho do buffer é menor do que o tamanho que foi solicitado" -#: shared-bindings/audiocore/RawSample.c -msgid "buffer must be a bytes-like object" -msgstr "o buffer deve ser um objeto como bytes" - #: extmod/ulab/code/ulab_create.c extmod/ulab/code/utils/utils.c msgid "buffer size must be a multiple of element size" msgstr "o tamanho do buffer deve ser um múltiplo do tamanho do elemento" @@ -3033,7 +3034,7 @@ msgid "f-string: single '}' is not allowed" msgstr "f-string: um único '}' não é permitido" #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c -#: shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" msgstr "o arquivo deve ser um arquivo aberto no modo byte" @@ -3290,6 +3291,10 @@ msgstr "bits_per_pixel %d é inválido, deve ser, 1, 4, 8, 16, 24, ou 32" msgid "invalid cert" msgstr "certificado inválido" +#: py/compile.c +msgid "invalid decorator" +msgstr "decorador inválido" + #: extmod/uos_dupterm.c msgid "invalid dupterm index" msgstr "Índice de dupterm inválido" @@ -3345,10 +3350,6 @@ msgstr "sintaxe inválida para o número inteiro com base %d" msgid "invalid syntax for number" msgstr "sintaxe inválida para o número" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "io must be rtc io" -msgstr "O io deve ser rtc io" - #: py/objtype.c msgid "issubclass() arg 1 must be a class" msgstr "issubclass() arg 1 deve ser uma classe" @@ -3818,6 +3819,7 @@ msgstr "o pow() com 3 argumentos requer números inteiros" #: ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h #: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h #: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h +#: ports/esp32s2/boards/artisense_rd00/mpconfigboard.h #: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h #: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h #: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h @@ -3843,6 +3845,10 @@ msgstr "pressionando o botão de boot na inicialização.\n" msgid "pressing both buttons at start up.\n" msgstr "pressionando ambos os botões durante a inicialização.\n" +#: ports/nrf/boards/aramcon2_badge/mpconfigboard.h +msgid "pressing the left button at start up\n" +msgstr "pressionando o botão esquerdo durante a inicialização\n" + #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "pull masks conflict with direction masks" msgstr "puxe as máscaras em conflito com as máscaras de direção" @@ -4118,10 +4124,6 @@ msgstr "Trapz está definido para arrays 1D" msgid "trapz is defined for 1D arrays of equal length" msgstr "o trapz está definido para 1D arrays de igual tamanho" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "trigger level must be 0 or 1" -msgstr "nível do gatilho deve ser 0 ou 1" - #: py/obj.c msgid "tuple/list has wrong length" msgstr "a tupla/lista está com tamanho incorreto" @@ -4256,10 +4258,6 @@ msgstr "o valor deve caber em %d byte(s)" msgid "value_count must be > 0" msgstr "o value_count deve ser > 0" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "wakeup conflict" -msgstr "conflito de wakeup" - #: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c msgid "watchdog not initialized" msgstr "o watchdog não foi inicializado" @@ -4346,6 +4344,32 @@ msgstr "zi deve ser de um tipo float" msgid "zi must be of shape (n_section, 2)" msgstr "zi deve estar na forma (n_section, 2)" +#~ msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" +#~ msgstr "IOs 0, 2 e 4 não suportam pullup interno em repouso (sleep)" + +#~ msgid "buffer must be a bytes-like object" +#~ msgstr "o buffer deve ser um objeto como bytes" + +#~ msgid "io must be rtc io" +#~ msgstr "O io deve ser rtc io" + +#~ msgid "trigger level must be 0 or 1" +#~ msgstr "nível do gatilho deve ser 0 ou 1" + +#~ msgid "wakeup conflict" +#~ msgstr "conflito de wakeup" + +#~ msgid "Attempted heap allocation when MicroPython VM not running." +#~ msgstr "" +#~ "A tentativa da área de alocação dinâmica de variáveis (heap) quando o " +#~ "MicroPython VM não está em execução." + +#~ msgid "MicroPython NLR jump failed. Likely memory corruption." +#~ msgstr "O salto do MicroPython NLR falhou. Possível corrupção de memória." + +#~ msgid "MicroPython fatal error." +#~ msgstr "Houve um erro fatal do MicroPython." + #~ msgid "argument must be ndarray" #~ msgstr "o argumento deve ser ndarray" diff --git a/locale/sv.po b/locale/sv.po index 5feb28845d..69fe35736d 100644 --- a/locale/sv.po +++ b/locale/sv.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2021-04-06 14:41+0000\n" +"PO-Revision-Date: 2021-04-19 21:50+0000\n" "Last-Translator: Jonny Bergdahl \n" "Language-Team: LANGUAGE \n" "Language: sv\n" @@ -14,7 +14,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 4.6-dev\n" +"X-Generator: Weblate 4.7-dev\n" #: main.c msgid "" @@ -446,8 +446,8 @@ msgid "Attempt to allocate %d blocks" msgstr "Försök att tilldela %d block" #: supervisor/shared/safe_mode.c -msgid "Attempted heap allocation when MicroPython VM not running." -msgstr "Försökte tilldela heap när MicroPython VM inte körs." +msgid "Attempted heap allocation when VM not running." +msgstr "Försök till heap-allokering när den virtuella maskinen inte är igång." #: shared-bindings/wifi/Radio.c msgid "Authentication failure" @@ -896,6 +896,11 @@ msgstr "ESP-IDF-minnetilldelning misslyckades" msgid "EXTINT channel already in use" msgstr "EXTINT-kanalen används redan" +#: shared-module/synthio/MidiTrack.c +#, c-format +msgid "Error in MIDI stream at position %d" +msgstr "Fel i MIDI-ström vid position %d" + #: extmod/modure.c msgid "Error in regex" msgstr "Fel i regex" @@ -1025,6 +1030,10 @@ msgstr "Det gick inte att frigöra mutex, fel 0x%04x" msgid "Failed to write internal flash." msgstr "Det gick inte att skriva till intern flash." +#: supervisor/shared/safe_mode.c +msgid "Fatal error." +msgstr "Fatalt fel." + #: py/moduerrno.c msgid "File exists" msgstr "Filen finns redan" @@ -1097,10 +1106,6 @@ msgstr "I2C-enhet används redan" msgid "I2SOut not available" msgstr "I2SOut är inte tillgängligt" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" -msgstr "IO 0, 2 & 4 stöder inte intern pullup för sovläge" - #: shared-bindings/aesio/aes.c #, c-format msgid "IV must be %d bytes long" @@ -1228,6 +1233,10 @@ msgstr "Ogiltig BSSID" msgid "Invalid DAC pin supplied" msgstr "Ogiltig DAC-pinne angiven" +#: shared-bindings/synthio/__init__.c +msgid "Invalid MIDI file" +msgstr "Ogiltig MIDI-fil" + #: ports/atmel-samd/common-hal/pwmio/PWMOut.c #: ports/cxd56/common-hal/pwmio/PWMOut.c #: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c @@ -1419,14 +1428,6 @@ msgstr "Maximum x-värde vid spegling är %d" msgid "Messages limited to 8 bytes" msgstr "Meddelanden begränsad till 8 byte" -#: supervisor/shared/safe_mode.c -msgid "MicroPython NLR jump failed. Likely memory corruption." -msgstr "MicroPython NLR jump misslyckades. Troligen korrupt minne." - -#: supervisor/shared/safe_mode.c -msgid "MicroPython fatal error." -msgstr "MicroPython fatalt fel." - #: shared-bindings/audiobusio/PDMIn.c msgid "Microphone startup delay must be in range 0.0 to 1.0" msgstr "" @@ -1479,6 +1480,10 @@ msgstr "Måste ange MISO- eller MOSI-pinne" msgid "Must use a multiple of 6 rgb pins, not %d" msgstr "Måste använda ett multipel av 6 rgb-pinnar, inte %d" +#: supervisor/shared/safe_mode.c +msgid "NLR jump failed. Likely memory corruption." +msgstr "NLR jump misslyckades. Troligen korrupt minne." + #: ports/esp32s2/common-hal/nvm/ByteArray.c msgid "NVS Error" msgstr "NVS-fel" @@ -1623,6 +1628,7 @@ msgstr "Nordic systemfirmware fick slut på minne" msgid "Not a valid IP string" msgstr "Inte en giltig IP-sträng" +#: ports/nrf/common-hal/_bleio/PacketBuffer.c #: ports/nrf/common-hal/_bleio/__init__.c #: shared-bindings/_bleio/CharacteristicBuffer.c msgid "Not connected" @@ -2547,10 +2553,6 @@ msgstr "branch utanför räckvidd" msgid "buffer is smaller than requested size" msgstr "bufferten är mindre än begärd storlek" -#: shared-bindings/audiocore/RawSample.c -msgid "buffer must be a bytes-like object" -msgstr "buffer måste vara en byte-liknande objekt" - #: extmod/ulab/code/ulab_create.c extmod/ulab/code/utils/utils.c msgid "buffer size must be a multiple of element size" msgstr "buffertstorlek måste vara en multipel av elementstorlek" @@ -2997,7 +2999,7 @@ msgid "f-string: single '}' is not allowed" msgstr "f-string: singel '}' är inte tillåten" #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c -#: shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" msgstr "filen måste vara en fil som öppnats i byte-läge" @@ -3253,6 +3255,10 @@ msgstr "ogiltig bits_per_pixel %d, måste vara 1, 4, 8, 16, 24 eller 32" msgid "invalid cert" msgstr "ogiltigt certifikat" +#: py/compile.c +msgid "invalid decorator" +msgstr "ogiltig dekorator" + #: extmod/uos_dupterm.c msgid "invalid dupterm index" msgstr "ogiltigt dupterm index" @@ -3308,10 +3314,6 @@ msgstr "ogiltig syntax för heltal med bas %d" msgid "invalid syntax for number" msgstr "ogiltig syntax för tal" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "io must be rtc io" -msgstr "io måste vara rtc io" - #: py/objtype.c msgid "issubclass() arg 1 must be a class" msgstr "issubclass() arg 1 måste vara en klass" @@ -3775,6 +3777,7 @@ msgstr "pow() med 3 argument kräver heltal" #: ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h #: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h #: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h +#: ports/esp32s2/boards/artisense_rd00/mpconfigboard.h #: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h #: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h #: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h @@ -3800,6 +3803,10 @@ msgstr "trycka på startknappen vid start.\n" msgid "pressing both buttons at start up.\n" msgstr "trycka båda knapparna vid uppstart.\n" +#: ports/nrf/boards/aramcon2_badge/mpconfigboard.h +msgid "pressing the left button at start up\n" +msgstr "håll ner vänster knapp vid start\n" + #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "pull masks conflict with direction masks" msgstr "pull-mask är i konflikt med riktnings-mask" @@ -4075,10 +4082,6 @@ msgstr "trapz är definierat för 1D-matriser" msgid "trapz is defined for 1D arrays of equal length" msgstr "trapz är definierad för 1D-matriser med samma längd" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "trigger level must be 0 or 1" -msgstr "triggernivå måste vara 0 eller 1" - #: py/obj.c msgid "tuple/list has wrong length" msgstr "tupel/lista har fel längd" @@ -4213,10 +4216,6 @@ msgstr "värdet måste passa i %d byte(s)" msgid "value_count must be > 0" msgstr "value_count måste vara > 0" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "wakeup conflict" -msgstr "wakeup-konflikt" - #: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c msgid "watchdog not initialized" msgstr "watchdog är inte initierad" @@ -4303,6 +4302,30 @@ msgstr "zi måste vara av typ float" msgid "zi must be of shape (n_section, 2)" msgstr "zi måste vara i formen (n_section, 2)" +#~ msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" +#~ msgstr "IO 0, 2 & 4 stöder inte intern pullup för sovläge" + +#~ msgid "buffer must be a bytes-like object" +#~ msgstr "buffer måste vara en byte-liknande objekt" + +#~ msgid "io must be rtc io" +#~ msgstr "io måste vara rtc io" + +#~ msgid "trigger level must be 0 or 1" +#~ msgstr "triggernivå måste vara 0 eller 1" + +#~ msgid "wakeup conflict" +#~ msgstr "wakeup-konflikt" + +#~ msgid "Attempted heap allocation when MicroPython VM not running." +#~ msgstr "Försökte tilldela heap när MicroPython VM inte körs." + +#~ msgid "MicroPython NLR jump failed. Likely memory corruption." +#~ msgstr "MicroPython NLR jump misslyckades. Troligen korrupt minne." + +#~ msgid "MicroPython fatal error." +#~ msgstr "MicroPython fatalt fel." + #~ msgid "argument must be ndarray" #~ msgstr "argument måste vara ndarray" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index 14c0a9eca0..c8a2d8cf83 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -7,7 +7,7 @@ msgstr "" "Project-Id-Version: circuitpython-cn\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2021-03-29 08:26+0000\n" +"PO-Revision-Date: 2021-04-19 19:15+0000\n" "Last-Translator: hexthat \n" "Language-Team: Chinese Hanyu Pinyin\n" "Language: zh_Latn_pinyin\n" @@ -15,7 +15,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" -"X-Generator: Weblate 4.6-dev\n" +"X-Generator: Weblate 4.7-dev\n" #: main.c msgid "" @@ -423,7 +423,7 @@ msgstr "Wèi zhīchí zhǐdìng de yǐn jiǎo AnalogOut" #: ports/stm/common-hal/audiopwmio/PWMAudioOut.c msgid "Another PWMAudioOut is already active" -msgstr "" +msgstr "lìng yí gè PWMAudioOut yǐ jīng chǔ yú huó dòng zhuàng tài" #: ports/atmel-samd/common-hal/pulseio/PulseOut.c #: ports/cxd56/common-hal/pulseio/PulseOut.c @@ -448,8 +448,8 @@ msgid "Attempt to allocate %d blocks" msgstr "cháng shì fēn pèi %d kuài" #: supervisor/shared/safe_mode.c -msgid "Attempted heap allocation when MicroPython VM not running." -msgstr "MicroPython VM zài wèi yùnxíng shí chángshì fēnpèi duī." +msgid "Attempted heap allocation when VM not running." +msgstr "dāng VM bú yùn xíng shí, cháng shì duī fēn pèi." #: shared-bindings/wifi/Radio.c msgid "Authentication failure" @@ -895,6 +895,11 @@ msgstr "ESP-IDF nèicún fēnpèi shībài" msgid "EXTINT channel already in use" msgstr "EXTINT píndào yǐjīng shǐyòng" +#: shared-module/synthio/MidiTrack.c +#, c-format +msgid "Error in MIDI stream at position %d" +msgstr "wèi yú %d wèi zhì de MIDI liú zhōng de cuò wù" + #: extmod/modure.c msgid "Error in regex" msgstr "Zhèngzé biǎodá shì cuòwù" @@ -997,7 +1002,7 @@ msgstr "Wúfǎ fēnpèi wifi sǎomiáo nèicún" #: ports/stm/common-hal/audiopwmio/PWMAudioOut.c msgid "Failed to buffer the sample" -msgstr "" +msgstr "wèi néng huǎn chōng yàng běn" #: ports/nrf/common-hal/_bleio/Adapter.c msgid "Failed to connect: internal error" @@ -1024,6 +1029,10 @@ msgstr "Wúfǎ shìfàng mutex, err 0x%04x" msgid "Failed to write internal flash." msgstr "Wúfǎ xiě rù nèibù shǎncún." +#: supervisor/shared/safe_mode.c +msgid "Fatal error." +msgstr "zhì mìng cuò wù." + #: py/moduerrno.c msgid "File exists" msgstr "Wénjiàn cúnzài" @@ -1096,10 +1105,6 @@ msgstr "I2C wài shè zhèng zài shǐ yòng zhōng" msgid "I2SOut not available" msgstr "I2SOut bù kě yòng" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" -msgstr "IOS 0, 2 + 4 bù zhī chí shuì mián zhōng de nèi bù shàng lā" - #: shared-bindings/aesio/aes.c #, c-format msgid "IV must be %d bytes long" @@ -1230,6 +1235,10 @@ msgstr "Wúxiào de BSSID" msgid "Invalid DAC pin supplied" msgstr "Tí gōng liǎo wúxiào de DAC yǐn jiǎo" +#: shared-bindings/synthio/__init__.c +msgid "Invalid MIDI file" +msgstr "wú xiào de MIDI wén jiàn" + #: ports/atmel-samd/common-hal/pwmio/PWMOut.c #: ports/cxd56/common-hal/pwmio/PWMOut.c #: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c @@ -1421,14 +1430,6 @@ msgstr "Jìngxiàng shí de zuìdà X zhí wèi%d" msgid "Messages limited to 8 bytes" msgstr "Yóujiàn xiànzhì wèi 8 gè zì jié" -#: supervisor/shared/safe_mode.c -msgid "MicroPython NLR jump failed. Likely memory corruption." -msgstr "MicroPython NLR tiào zhuǎn shībài. Kěnéng shì nèicún sǔnhuài." - -#: supervisor/shared/safe_mode.c -msgid "MicroPython fatal error." -msgstr "MicroPython zhìmìng cuòwù." - #: shared-bindings/audiobusio/PDMIn.c msgid "Microphone startup delay must be in range 0.0 to 1.0" msgstr "Màikèfēng qǐdòng yánchí bìxū zài 0.0 Dào 1.0 De fànwéi nèi" @@ -1481,6 +1482,10 @@ msgstr "Bìxū tígōng MISO huò MOSI yǐn jiǎo" msgid "Must use a multiple of 6 rgb pins, not %d" msgstr "bì xū shǐ yòng 6 RGB yǐn jiǎo de bèi shù, ér bù shì %d" +#: supervisor/shared/safe_mode.c +msgid "NLR jump failed. Likely memory corruption." +msgstr "NLR tiào zhuǎn shī bài. kě néng shì nèi cún sǔn huài." + #: ports/esp32s2/common-hal/nvm/ByteArray.c msgid "NVS Error" msgstr "NVS cuò wù" @@ -1615,16 +1620,17 @@ msgstr "Méiyǒu jìshí qì" #: supervisor/shared/safe_mode.c msgid "Nordic system firmware failure assertion." -msgstr "" +msgstr "běi ōu xì tǒng gù jiàn gù zhàng duàn yán." #: ports/nrf/common-hal/_bleio/__init__.c msgid "Nordic system firmware out of memory" -msgstr "" +msgstr "běi ōu xì tǒng gù jiàn chū nèi cún" #: shared-bindings/ipaddress/IPv4Address.c shared-bindings/ipaddress/__init__.c msgid "Not a valid IP string" msgstr "Wúxiào de IP zìfú chuàn" +#: ports/nrf/common-hal/_bleio/PacketBuffer.c #: ports/nrf/common-hal/_bleio/__init__.c #: shared-bindings/_bleio/CharacteristicBuffer.c msgid "Not connected" @@ -2288,7 +2294,7 @@ msgstr "Wèizhī de ānquán cuòwù: 0x%04x" #: ports/nrf/common-hal/_bleio/__init__.c #, c-format msgid "Unknown system firmware error: %04x" -msgstr "" +msgstr "wèi zhī xì tǒng gù jiàn cuò wù: %04x" #: shared-bindings/_pixelbuf/PixelBuf.c #, c-format @@ -2545,10 +2551,6 @@ msgstr "fēnzhī bùzài fànwéi nèi" msgid "buffer is smaller than requested size" msgstr "huǎn chōng qū xiǎo yú qǐng qiú de dà xiǎo" -#: shared-bindings/audiocore/RawSample.c -msgid "buffer must be a bytes-like object" -msgstr "huǎnchōng qū bìxū shì zì jié lèi duìxiàng" - #: extmod/ulab/code/ulab_create.c extmod/ulab/code/utils/utils.c msgid "buffer size must be a multiple of element size" msgstr "huǎn chōng qū dà xiǎo bì xū shì yuán sù dà xiǎo de bèi shù" @@ -2996,7 +2998,7 @@ msgid "f-string: single '}' is not allowed" msgstr "f-string: bù yǔnxǔ shǐyòng dāngè '}'" #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c -#: shared-bindings/displayio/OnDiskBitmap.c +#: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" msgstr "wénjiàn bìxū shì zài zì jié móshì xià dǎkāi de wénjiàn" @@ -3252,6 +3254,10 @@ msgstr "wú xiào bits_per_pixel %d, bì xū shì, 1, 4, 8, 16, 24, huò 32" msgid "invalid cert" msgstr "zhèngshū wúxiào" +#: py/compile.c +msgid "invalid decorator" +msgstr "wú xiào zhuāng shì" + #: extmod/uos_dupterm.c msgid "invalid dupterm index" msgstr "dupterm suǒyǐn wúxiào" @@ -3307,10 +3313,6 @@ msgstr "jīshù wèi %d de zhěng shǔ de yǔfǎ wúxiào" msgid "invalid syntax for number" msgstr "wúxiào de hàomǎ yǔfǎ" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "io must be rtc io" -msgstr "IO bì xū shì RTC IO" - #: py/objtype.c msgid "issubclass() arg 1 must be a class" msgstr "issubclass() cānshù 1 bìxū shì yīgè lèi" @@ -3682,11 +3684,11 @@ msgstr "ord() yùqí zìfú, dàn chángdù zìfú chuàn %d" #: extmod/ulab/code/utils/utils.c msgid "out array is too small" -msgstr "" +msgstr "chū zhèn liè tài xiǎo" #: extmod/ulab/code/utils/utils.c msgid "out must be a float dense array" -msgstr "" +msgstr "chū bì xū shì yí gè fú dòng mì jí zhèn liè" #: shared-bindings/displayio/Bitmap.c msgid "out of range of source" @@ -3771,6 +3773,7 @@ msgstr "pow() yǒu 3 cānshù xūyào zhěngshù" #: ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h #: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h #: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h +#: ports/esp32s2/boards/artisense_rd00/mpconfigboard.h #: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h #: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h #: ports/esp32s2/boards/espressif_saola_1_wroom/mpconfigboard.h @@ -3796,6 +3799,10 @@ msgstr "Zài qǐdòng shí àn qǐdòng ànniǔ.\n" msgid "pressing both buttons at start up.\n" msgstr "zài qǐdòng shí tóngshí àn xià liǎng gè ànniǔ.\n" +#: ports/nrf/boards/aramcon2_badge/mpconfigboard.h +msgid "pressing the left button at start up\n" +msgstr "" + #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "pull masks conflict with direction masks" msgstr "lā kǒu zhào yǔ fāng xiàng miàn mó chōng tū" @@ -4071,10 +4078,6 @@ msgstr "wéi 1D shù zǔ dìng yì xiàn jǐng" msgid "trapz is defined for 1D arrays of equal length" msgstr "Trapz shì wèi děng zhǎng de 1D shùzǔ dìngyì de" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "trigger level must be 0 or 1" -msgstr "chù fā jí bié bì xū wéi 0 huò 1" - #: py/obj.c msgid "tuple/list has wrong length" msgstr "yuán zǔ/lièbiǎo chángdù cuòwù" @@ -4209,10 +4212,6 @@ msgstr "Zhí bìxū fúhé %d zì jié" msgid "value_count must be > 0" msgstr "zhí jìshù bìxū wèi > 0" -#: ports/esp32s2/common-hal/alarm/pin/__init__.c -msgid "wakeup conflict" -msgstr "huàn xǐng chōng tū" - #: ports/esp32s2/common-hal/watchdog/WatchDogTimer.c msgid "watchdog not initialized" msgstr "wèi chū shǐ huà jiān shì qì" @@ -4299,6 +4298,30 @@ msgstr "zi bìxū wèi fú diǎn xíng" msgid "zi must be of shape (n_section, 2)" msgstr "zi bìxū jùyǒu xíngzhuàng (n_section,2)" +#~ msgid "IOs 0, 2 & 4 do not support internal pullup in sleep" +#~ msgstr "IOS 0, 2 + 4 bù zhī chí shuì mián zhōng de nèi bù shàng lā" + +#~ msgid "buffer must be a bytes-like object" +#~ msgstr "huǎnchōng qū bìxū shì zì jié lèi duìxiàng" + +#~ msgid "io must be rtc io" +#~ msgstr "IO bì xū shì RTC IO" + +#~ msgid "trigger level must be 0 or 1" +#~ msgstr "chù fā jí bié bì xū wéi 0 huò 1" + +#~ msgid "wakeup conflict" +#~ msgstr "huàn xǐng chōng tū" + +#~ msgid "Attempted heap allocation when MicroPython VM not running." +#~ msgstr "MicroPython VM zài wèi yùnxíng shí chángshì fēnpèi duī." + +#~ msgid "MicroPython NLR jump failed. Likely memory corruption." +#~ msgstr "MicroPython NLR tiào zhuǎn shībài. Kěnéng shì nèicún sǔnhuài." + +#~ msgid "MicroPython fatal error." +#~ msgstr "MicroPython zhìmìng cuòwù." + #~ msgid "argument must be ndarray" #~ msgstr "Cānshù bìxū shì ndarray" diff --git a/main.c b/main.c index 755f8d5362..7020ab3851 100755 --- a/main.c +++ b/main.c @@ -404,10 +404,10 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { new_status_color(BLACK); board_deinit(); if (!supervisor_workflow_active()) { - // Enter deep sleep. When we wake up we'll return from - // this loop. + // Enter true deep sleep. When we wake up we'll be back at the + // top of main(), not in this loop. common_hal_alarm_enter_deep_sleep(); - // Does not return. + // Does not return. } else { serial_write_compressed(translate("Pretending to deep sleep until alarm, CTRL-C or file write.\n")); } @@ -426,18 +426,6 @@ STATIC bool run_code_py(safe_mode_t safe_mode) { #if CIRCUITPY_ALARM common_hal_alarm_pretending_deep_sleep(); - bool serial_in = (serial_connected() && - serial_bytes_available()); - supervisor_set_run_reason(RUN_REASON_STARTUP); - board_init(); - if (serial_in) { - bool ctrl_d = serial_read() == CHAR_CTRL_D; - if (ctrl_d) { - supervisor_set_run_reason(RUN_REASON_REPL_RELOAD); - } - return ctrl_d; - } - return true; #else port_idle_until_interrupt(); #endif diff --git a/ports/atmel-samd/boards/rotary_trinkey_m0/board.c b/ports/atmel-samd/boards/adafruit_neokey_trinkey_m0/board.c similarity index 100% rename from ports/atmel-samd/boards/rotary_trinkey_m0/board.c rename to ports/atmel-samd/boards/adafruit_neokey_trinkey_m0/board.c diff --git a/ports/atmel-samd/boards/adafruit_neokey_trinkey_m0/mpconfigboard.h b/ports/atmel-samd/boards/adafruit_neokey_trinkey_m0/mpconfigboard.h new file mode 100644 index 0000000000..3cd85ac1bc --- /dev/null +++ b/ports/atmel-samd/boards/adafruit_neokey_trinkey_m0/mpconfigboard.h @@ -0,0 +1,58 @@ +#define MICROPY_HW_BOARD_NAME "Adafruit NeoKey Trinkey M0" +#define MICROPY_HW_MCU_NAME "samd21e18" + +#define MICROPY_HW_NEOPIXEL (&pin_PA15) + +#define MICROPY_PORT_A (0) +#define MICROPY_PORT_B (0) +#define MICROPY_PORT_C (0) + +#define IGNORE_PIN_PA00 1 +#define IGNORE_PIN_PA01 1 +#define IGNORE_PIN_PA02 1 +#define IGNORE_PIN_PA03 1 +#define IGNORE_PIN_PA04 1 +#define IGNORE_PIN_PA05 1 +#define IGNORE_PIN_PA06 1 +#define IGNORE_PIN_PA08 1 +#define IGNORE_PIN_PA09 1 +#define IGNORE_PIN_PA10 1 +#define IGNORE_PIN_PA11 1 +#define IGNORE_PIN_PA12 1 +#define IGNORE_PIN_PA13 1 +#define IGNORE_PIN_PA14 1 +#define IGNORE_PIN_PA16 1 +#define IGNORE_PIN_PA17 1 +#define IGNORE_PIN_PA18 1 +#define IGNORE_PIN_PA19 1 +#define IGNORE_PIN_PA20 1 +#define IGNORE_PIN_PA21 1 +// USB is always used internally so skip the pin objects for it. +#define IGNORE_PIN_PA24 1 +#define IGNORE_PIN_PA25 1 +#define IGNORE_PIN_PA27 1 +#define IGNORE_PIN_PA29 1 +#define IGNORE_PIN_PA30 1 +#define IGNORE_PIN_PA31 1 +#define IGNORE_PIN_PB00 1 +#define IGNORE_PIN_PB01 1 +#define IGNORE_PIN_PB02 1 +#define IGNORE_PIN_PB03 1 +#define IGNORE_PIN_PB04 1 +#define IGNORE_PIN_PB05 1 +#define IGNORE_PIN_PB06 1 +#define IGNORE_PIN_PB07 1 +#define IGNORE_PIN_PB08 1 +#define IGNORE_PIN_PB09 1 +#define IGNORE_PIN_PB10 1 +#define IGNORE_PIN_PB11 1 +#define IGNORE_PIN_PB12 1 +#define IGNORE_PIN_PB13 1 +#define IGNORE_PIN_PB14 1 +#define IGNORE_PIN_PB15 1 +#define IGNORE_PIN_PB16 1 +#define IGNORE_PIN_PB17 1 +#define IGNORE_PIN_PB22 1 +#define IGNORE_PIN_PB23 1 +#define IGNORE_PIN_PB30 1 +#define IGNORE_PIN_PB31 1 diff --git a/ports/atmel-samd/boards/adafruit_neokey_trinkey_m0/mpconfigboard.mk b/ports/atmel-samd/boards/adafruit_neokey_trinkey_m0/mpconfigboard.mk new file mode 100644 index 0000000000..56cbede39f --- /dev/null +++ b/ports/atmel-samd/boards/adafruit_neokey_trinkey_m0/mpconfigboard.mk @@ -0,0 +1,34 @@ +USB_VID = 0x239A +USB_PID = 0x8100 +USB_PRODUCT = "NeoKey Trinkey M0" +USB_MANUFACTURER = "Adafruit Industries LLC" + +CHIP_VARIANT = SAMD21E18A +CHIP_FAMILY = samd21 + +INTERNAL_FLASH_FILESYSTEM = 1 +LONGINT_IMPL = NONE + +CIRCUITPY_ANALOGIO = 0 +CIRCUITPY_ROTARYIO = 0 +CIRCUITPY_RTC = 0 +CIRCUITPY_SAMD = 0 +CIRCUITPY_PS2IO = 0 +CIRCUITPY_PULSEIO = 0 +CIRCUITPY_PWMIO = 0 +CIRCUITPY_AUDIOCORE = 0 +CIRCUITPY_BUSIO = 0 +CIRCUITPY_STORAGE = 1 + +CIRCUITPY_MATH = 1 +CIRCUITPY_PIXELBUF = 1 +CIRCUITPY_USB_MIDI = 1 +CIRCUITPY_TOUCHIO = 1 +CIRCUITPY_FULL_BUILD = 0 + +SUPEROPT_GC = 0 +SUPEROPT_VM = 0 + +# Include these Python libraries in firmware. +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_HID diff --git a/ports/atmel-samd/boards/adafruit_neokey_trinkey_m0/pins.c b/ports/atmel-samd/boards/adafruit_neokey_trinkey_m0/pins.c new file mode 100644 index 0000000000..df8dfb0bfa --- /dev/null +++ b/ports/atmel-samd/boards/adafruit_neokey_trinkey_m0/pins.c @@ -0,0 +1,8 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_TOUCH), MP_ROM_PTR(&pin_PA07) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA15) }, + { MP_ROM_QSTR(MP_QSTR_SWITCH), MP_ROM_PTR(&pin_PA28) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/board.c b/ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/board.c new file mode 100644 index 0000000000..cde441b3d9 --- /dev/null +++ b/ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/board.c @@ -0,0 +1,40 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * 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 "supervisor/board.h" +#include "common-hal/microcontroller/Pin.h" +#include "supervisor/shared/board.h" +#include "hal/include/hal_gpio.h" + +void board_init(void) { +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} diff --git a/ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/mpconfigboard.h b/ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/mpconfigboard.h new file mode 100644 index 0000000000..a760fbe376 --- /dev/null +++ b/ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/mpconfigboard.h @@ -0,0 +1,58 @@ +#define MICROPY_HW_BOARD_NAME "Adafruit ProxLight Trinkey M0" +#define MICROPY_HW_MCU_NAME "samd21e18" + +#define MICROPY_HW_NEOPIXEL (&pin_PA15) + +#define MICROPY_PORT_A (0) +#define MICROPY_PORT_B (0) +#define MICROPY_PORT_C (0) + +#define IGNORE_PIN_PA01 1 +#define IGNORE_PIN_PA02 1 +#define IGNORE_PIN_PA04 1 +#define IGNORE_PIN_PA05 1 +#define IGNORE_PIN_PA06 1 +#define IGNORE_PIN_PA08 1 +#define IGNORE_PIN_PA09 1 +#define IGNORE_PIN_PA10 1 +#define IGNORE_PIN_PA11 1 +#define IGNORE_PIN_PA12 1 +#define IGNORE_PIN_PA13 1 +#define IGNORE_PIN_PA14 1 +#define IGNORE_PIN_PA18 1 +#define IGNORE_PIN_PA19 1 +#define IGNORE_PIN_PA20 1 +#define IGNORE_PIN_PA21 1 +// USB is always used internally so skip the pin objects for it. +#define IGNORE_PIN_PA24 1 +#define IGNORE_PIN_PA25 1 +#define IGNORE_PIN_PA27 1 +#define IGNORE_PIN_PA28 1 +#define IGNORE_PIN_PA29 1 +#define IGNORE_PIN_PA30 1 +#define IGNORE_PIN_PA31 1 +#define IGNORE_PIN_PB00 1 +#define IGNORE_PIN_PB01 1 +#define IGNORE_PIN_PB02 1 +#define IGNORE_PIN_PB03 1 +#define IGNORE_PIN_PB04 1 +#define IGNORE_PIN_PB05 1 +#define IGNORE_PIN_PB06 1 +#define IGNORE_PIN_PB07 1 +#define IGNORE_PIN_PB08 1 +#define IGNORE_PIN_PB09 1 +#define IGNORE_PIN_PB10 1 +#define IGNORE_PIN_PB11 1 +#define IGNORE_PIN_PB12 1 +#define IGNORE_PIN_PB13 1 +#define IGNORE_PIN_PB14 1 +#define IGNORE_PIN_PB15 1 +#define IGNORE_PIN_PB16 1 +#define IGNORE_PIN_PB17 1 +#define IGNORE_PIN_PB22 1 +#define IGNORE_PIN_PB23 1 +#define IGNORE_PIN_PB30 1 +#define IGNORE_PIN_PB31 1 + +#define DEFAULT_I2C_BUS_SCL (&pin_PA17) +#define DEFAULT_I2C_BUS_SDA (&pin_PA16) diff --git a/ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/mpconfigboard.mk b/ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/mpconfigboard.mk new file mode 100644 index 0000000000..92e7a17f3e --- /dev/null +++ b/ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/mpconfigboard.mk @@ -0,0 +1,33 @@ +USB_VID = 0x239A +USB_PID = 0x8104 +USB_PRODUCT = "ProxLight Trinkey M0" +USB_MANUFACTURER = "Adafruit Industries LLC" + +CHIP_VARIANT = SAMD21E18A +CHIP_FAMILY = samd21 + +INTERNAL_FLASH_FILESYSTEM = 1 +LONGINT_IMPL = NONE + +CIRCUITPY_ANALOGIO = 0 +CIRCUITPY_ROTARYIO = 0 +CIRCUITPY_RTC = 0 +CIRCUITPY_SAMD = 0 +CIRCUITPY_PS2IO = 0 +CIRCUITPY_PULSEIO = 0 +CIRCUITPY_PWMIO = 0 +CIRCUITPY_AUDIOCORE = 0 +CIRCUITPY_BUSIO = 1 +CIRCUITPY_STORAGE = 1 + +CIRCUITPY_MATH = 1 +CIRCUITPY_PIXELBUF = 0 +CIRCUITPY_USB_MIDI = 1 +CIRCUITPY_TOUCHIO = 1 +CIRCUITPY_FULL_BUILD = 0 + +SUPEROPT_GC = 0 +SUPEROPT_VM = 0 + +# Include these Python libraries in firmware. +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_HID diff --git a/ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/pins.c b/ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/pins.c new file mode 100644 index 0000000000..21410f8ad1 --- /dev/null +++ b/ports/atmel-samd/boards/adafruit_proxlight_trinkey_m0/pins.c @@ -0,0 +1,15 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_INTERRUPT), MP_ROM_PTR(&pin_PA00) }, + + { MP_ROM_QSTR(MP_QSTR_TOUCH2), MP_ROM_PTR(&pin_PA03) }, + { MP_ROM_QSTR(MP_QSTR_TOUCH1), MP_ROM_PTR(&pin_PA07) }, + + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA15) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA16) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA17) }, + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/adafruit_rotary_trinkey_m0/board.c b/ports/atmel-samd/boards/adafruit_rotary_trinkey_m0/board.c new file mode 100644 index 0000000000..cde441b3d9 --- /dev/null +++ b/ports/atmel-samd/boards/adafruit_rotary_trinkey_m0/board.c @@ -0,0 +1,40 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * 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 "supervisor/board.h" +#include "common-hal/microcontroller/Pin.h" +#include "supervisor/shared/board.h" +#include "hal/include/hal_gpio.h" + +void board_init(void) { +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} diff --git a/ports/atmel-samd/boards/rotary_trinkey_m0/mpconfigboard.h b/ports/atmel-samd/boards/adafruit_rotary_trinkey_m0/mpconfigboard.h similarity index 100% rename from ports/atmel-samd/boards/rotary_trinkey_m0/mpconfigboard.h rename to ports/atmel-samd/boards/adafruit_rotary_trinkey_m0/mpconfigboard.h diff --git a/ports/atmel-samd/boards/rotary_trinkey_m0/mpconfigboard.mk b/ports/atmel-samd/boards/adafruit_rotary_trinkey_m0/mpconfigboard.mk similarity index 97% rename from ports/atmel-samd/boards/rotary_trinkey_m0/mpconfigboard.mk rename to ports/atmel-samd/boards/adafruit_rotary_trinkey_m0/mpconfigboard.mk index b071378c1d..29cc9ee195 100644 --- a/ports/atmel-samd/boards/rotary_trinkey_m0/mpconfigboard.mk +++ b/ports/atmel-samd/boards/adafruit_rotary_trinkey_m0/mpconfigboard.mk @@ -18,7 +18,7 @@ CIRCUITPY_PULSEIO = 0 CIRCUITPY_PWMIO = 0 CIRCUITPY_AUDIOCORE = 0 CIRCUITPY_BUSIO = 0 -CIRCUITPY_STORAGE = 0 +CIRCUITPY_STORAGE = 1 CIRCUITPY_MATH = 0 CIRCUITPY_PIXELBUF = 1 diff --git a/ports/atmel-samd/boards/rotary_trinkey_m0/pins.c b/ports/atmel-samd/boards/adafruit_rotary_trinkey_m0/pins.c similarity index 100% rename from ports/atmel-samd/boards/rotary_trinkey_m0/pins.c rename to ports/atmel-samd/boards/adafruit_rotary_trinkey_m0/pins.c diff --git a/ports/atmel-samd/boards/adafruit_slide_trinkey_m0/board.c b/ports/atmel-samd/boards/adafruit_slide_trinkey_m0/board.c new file mode 100644 index 0000000000..cde441b3d9 --- /dev/null +++ b/ports/atmel-samd/boards/adafruit_slide_trinkey_m0/board.c @@ -0,0 +1,40 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * 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 "supervisor/board.h" +#include "common-hal/microcontroller/Pin.h" +#include "supervisor/shared/board.h" +#include "hal/include/hal_gpio.h" + +void board_init(void) { +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} diff --git a/ports/atmel-samd/boards/adafruit_slide_trinkey_m0/mpconfigboard.h b/ports/atmel-samd/boards/adafruit_slide_trinkey_m0/mpconfigboard.h new file mode 100644 index 0000000000..1d9a4122df --- /dev/null +++ b/ports/atmel-samd/boards/adafruit_slide_trinkey_m0/mpconfigboard.h @@ -0,0 +1,58 @@ +#define MICROPY_HW_BOARD_NAME "Adafruit Slide Trinkey M0" +#define MICROPY_HW_MCU_NAME "samd21e18" + +#define MICROPY_HW_NEOPIXEL (&pin_PA06) + +#define MICROPY_PORT_A (0) +#define MICROPY_PORT_B (0) +#define MICROPY_PORT_C (0) + +#define IGNORE_PIN_PA00 1 +#define IGNORE_PIN_PA01 1 +#define IGNORE_PIN_PA02 1 +#define IGNORE_PIN_PA03 1 +#define IGNORE_PIN_PA04 1 +#define IGNORE_PIN_PA05 1 +#define IGNORE_PIN_PA08 1 +#define IGNORE_PIN_PA09 1 +#define IGNORE_PIN_PA10 1 +#define IGNORE_PIN_PA11 1 +#define IGNORE_PIN_PA12 1 +#define IGNORE_PIN_PA13 1 +#define IGNORE_PIN_PA14 1 +#define IGNORE_PIN_PA15 1 +#define IGNORE_PIN_PA16 1 +#define IGNORE_PIN_PA17 1 +#define IGNORE_PIN_PA18 1 +#define IGNORE_PIN_PA19 1 +#define IGNORE_PIN_PA20 1 +#define IGNORE_PIN_PA21 1 +// USB is always used internally so skip the pin objects for it. +#define IGNORE_PIN_PA24 1 +#define IGNORE_PIN_PA25 1 +#define IGNORE_PIN_PA27 1 +#define IGNORE_PIN_PA29 1 +#define IGNORE_PIN_PA30 1 +#define IGNORE_PIN_PA31 1 +#define IGNORE_PIN_PB00 1 +#define IGNORE_PIN_PB01 1 +#define IGNORE_PIN_PB02 1 +#define IGNORE_PIN_PB03 1 +#define IGNORE_PIN_PB04 1 +#define IGNORE_PIN_PB05 1 +#define IGNORE_PIN_PB06 1 +#define IGNORE_PIN_PB07 1 +#define IGNORE_PIN_PB08 1 +#define IGNORE_PIN_PB09 1 +#define IGNORE_PIN_PB10 1 +#define IGNORE_PIN_PB11 1 +#define IGNORE_PIN_PB12 1 +#define IGNORE_PIN_PB13 1 +#define IGNORE_PIN_PB14 1 +#define IGNORE_PIN_PB15 1 +#define IGNORE_PIN_PB16 1 +#define IGNORE_PIN_PB17 1 +#define IGNORE_PIN_PB22 1 +#define IGNORE_PIN_PB23 1 +#define IGNORE_PIN_PB30 1 +#define IGNORE_PIN_PB31 1 diff --git a/ports/atmel-samd/boards/adafruit_slide_trinkey_m0/mpconfigboard.mk b/ports/atmel-samd/boards/adafruit_slide_trinkey_m0/mpconfigboard.mk new file mode 100644 index 0000000000..2bc2def52e --- /dev/null +++ b/ports/atmel-samd/boards/adafruit_slide_trinkey_m0/mpconfigboard.mk @@ -0,0 +1,35 @@ +USB_VID = 0x239A +USB_PID = 0x8102 +USB_PRODUCT = "Slide Trinkey M0" +USB_MANUFACTURER = "Adafruit Industries LLC" + +CHIP_VARIANT = SAMD21E18A +CHIP_FAMILY = samd21 + +INTERNAL_FLASH_FILESYSTEM = 1 +LONGINT_IMPL = NONE + +CIRCUITPY_ANALOGIO = 1 +CIRCUITPY_ROTARYIO = 0 +CIRCUITPY_RTC = 0 +CIRCUITPY_SAMD = 0 +CIRCUITPY_PS2IO = 0 +CIRCUITPY_PULSEIO = 0 +CIRCUITPY_PWMIO = 0 +CIRCUITPY_AUDIOCORE = 0 +CIRCUITPY_BUSIO = 0 +CIRCUITPY_STORAGE = 1 + +CIRCUITPY_MATH = 1 +CIRCUITPY_PIXELBUF = 1 +CIRCUITPY_USB_MIDI = 1 +CIRCUITPY_TOUCHIO = 1 +CIRCUITPY_FULL_BUILD = 0 + +SUPEROPT_GC = 0 +SUPEROPT_VM = 0 + +# Include these Python libraries in firmware. +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_SimpleMath +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_HID diff --git a/ports/atmel-samd/boards/adafruit_slide_trinkey_m0/pins.c b/ports/atmel-samd/boards/adafruit_slide_trinkey_m0/pins.c new file mode 100644 index 0000000000..c48c69206a --- /dev/null +++ b/ports/atmel-samd/boards/adafruit_slide_trinkey_m0/pins.c @@ -0,0 +1,8 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + //{ MP_ROM_QSTR(MP_QSTR_TOUCH), MP_ROM_PTR(&pin_PA07) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_POTENTIOMETER), MP_ROM_PTR(&pin_PA07) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h index a0fde67ef6..704c0552d3 100644 --- a/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h +++ b/ports/atmel-samd/boards/feather_m0_adalogger/mpconfigboard.h @@ -8,8 +8,8 @@ #define MICROPY_PORT_B (0) #define MICROPY_PORT_C (0) -#define DEFAULT_I2C_BUS_SCL (&pin_PA22) -#define DEFAULT_I2C_BUS_SDA (&pin_PA23) +#define DEFAULT_I2C_BUS_SDA (&pin_PA22) +#define DEFAULT_I2C_BUS_SCL (&pin_PA23) #define DEFAULT_SPI_BUS_SCK (&pin_PB11) #define DEFAULT_SPI_BUS_MOSI (&pin_PB10) diff --git a/ports/atmel-samd/boards/neopixel_trinkey_m0/mpconfigboard.mk b/ports/atmel-samd/boards/neopixel_trinkey_m0/mpconfigboard.mk index 8607385d22..0f90dba6a1 100644 --- a/ports/atmel-samd/boards/neopixel_trinkey_m0/mpconfigboard.mk +++ b/ports/atmel-samd/boards/neopixel_trinkey_m0/mpconfigboard.mk @@ -18,7 +18,7 @@ CIRCUITPY_PULSEIO = 0 CIRCUITPY_PWMIO = 0 CIRCUITPY_AUDIOCORE = 0 CIRCUITPY_BUSIO = 0 -CIRCUITPY_STORAGE = 0 +CIRCUITPY_STORAGE = 1 CIRCUITPY_MATH = 1 CIRCUITPY_PIXELBUF = 1 diff --git a/ports/atmel-samd/boards/sensebox_mcu/board.c b/ports/atmel-samd/boards/sensebox_mcu/board.c new file mode 100644 index 0000000000..7af05ba45a --- /dev/null +++ b/ports/atmel-samd/boards/sensebox_mcu/board.c @@ -0,0 +1,39 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * + * 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 "supervisor/board.h" +#include "mpconfigboard.h" +#include "hal/include/hal_gpio.h" + +void board_init(void) { +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} diff --git a/ports/atmel-samd/boards/sensebox_mcu/mpconfigboard.h b/ports/atmel-samd/boards/sensebox_mcu/mpconfigboard.h new file mode 100644 index 0000000000..13aca289f6 --- /dev/null +++ b/ports/atmel-samd/boards/sensebox_mcu/mpconfigboard.h @@ -0,0 +1,24 @@ +#define MICROPY_HW_BOARD_NAME "senseBox MCU" +#define MICROPY_HW_MCU_NAME "senseBox" + +#define MICROPY_HW_LED_STATUS (&pin_PA27) + +#define MICROPY_PORT_A (0) +#define MICROPY_PORT_B (0) +#define MICROPY_PORT_C (0) + +#define DEFAULT_I2C_BUS_SCL (&pin_PA09) +#define DEFAULT_I2C_BUS_SDA (&pin_PA08) + +#define DEFAULT_SPI_BUS_SCK (&pin_PA17) +#define DEFAULT_SPI_BUS_MOSI (&pin_PA16) +#define DEFAULT_SPI_BUS_MISO (&pin_PA19) + +#define DEFAULT_UART_BUS_RX (&pin_PA23) +#define DEFAULT_UART_BUS_TX (&pin_PA22) + +#define SAMD21_BOD33_LEVEL (6) + +// USB is always used internally so skip the pin objects for it. +#define IGNORE_PIN_PA24 1 +#define IGNORE_PIN_PA25 1 diff --git a/ports/atmel-samd/boards/sensebox_mcu/mpconfigboard.mk b/ports/atmel-samd/boards/sensebox_mcu/mpconfigboard.mk new file mode 100644 index 0000000000..f5ce4a5d13 --- /dev/null +++ b/ports/atmel-samd/boards/sensebox_mcu/mpconfigboard.mk @@ -0,0 +1,14 @@ +USB_VID = 0x04D8 +USB_PID = 0xEF67 +USB_PRODUCT = "senseBox MCU" +USB_MANUFACTURER = "senseBox" + +CHIP_VARIANT = SAMD21G18A +CHIP_FAMILY = samd21 + +INTERNAL_FLASH_FILESYSTEM = 1 +LONGINT_IMPL = NONE +CIRCUITPY_FULL_BUILD = 0 + +SUPEROPT_GC = 0 +SUPEROPT_VM = 0 diff --git a/ports/atmel-samd/boards/sensebox_mcu/pins.c b/ports/atmel-samd/boards/sensebox_mcu/pins.c new file mode 100644 index 0000000000..55afcc989e --- /dev/null +++ b/ports/atmel-samd/boards/sensebox_mcu/pins.c @@ -0,0 +1,71 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + + // Analog pins + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA04) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA05) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA07) }, + { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PA03) }, + { MP_ROM_QSTR(MP_QSTR_A6), MP_ROM_PTR(&pin_PA02) }, + + // Digital pins + // { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PA20) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA04) }, + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PA05) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PA06) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PA07) }, + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PA03) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PA02) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PA27) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_PA28) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PB02) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA22) }, + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA23) }, + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PB08) }, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PB09) }, + + // UART pins + { MP_ROM_QSTR(MP_QSTR_UART_PWR), MP_ROM_PTR(&pin_PB02) }, + { MP_ROM_QSTR(MP_QSTR_TX1), MP_ROM_PTR(&pin_PA22) }, + { MP_ROM_QSTR(MP_QSTR_RX1), MP_ROM_PTR(&pin_PA23) }, + { MP_ROM_QSTR(MP_QSTR_TX2), MP_ROM_PTR(&pin_PB08) }, + { MP_ROM_QSTR(MP_QSTR_RX2), MP_ROM_PTR(&pin_PB09) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PA22) }, // alias of TX1 + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PA23) }, // alias of RX1 + + // SPI pins + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA16) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PA17) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA19) }, + + // I2C pins + { MP_ROM_QSTR(MP_QSTR_I2C_PWR), MP_ROM_PTR(&pin_PB11) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA09) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA08) }, + + // LED pins + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_PA27) }, + { MP_ROM_QSTR(MP_QSTR_RED_LED), MP_ROM_PTR(&pin_PA27) }, + { MP_ROM_QSTR(MP_QSTR_GREEN_LED), MP_ROM_PTR(&pin_PA28) }, + + // XBEE pins + { MP_ROM_QSTR(MP_QSTR_XB1_PWR), MP_ROM_PTR(&pin_PB03) }, + { MP_ROM_QSTR(MP_QSTR_XB2_PWR), MP_ROM_PTR(&pin_PB10) }, + { MP_ROM_QSTR(MP_QSTR_XB1_CS), MP_ROM_PTR(&pin_PA18) }, + { MP_ROM_QSTR(MP_QSTR_XB2_CS), MP_ROM_PTR(&pin_PA14) }, + { MP_ROM_QSTR(MP_QSTR_XB1_INT), MP_ROM_PTR(&pin_PA21) }, + { MP_ROM_QSTR(MP_QSTR_XB2_INT), MP_ROM_PTR(&pin_PA15) }, + { MP_ROM_QSTR(MP_QSTR_XB1_RX), MP_ROM_PTR(&pin_PA23) }, + { MP_ROM_QSTR(MP_QSTR_XB1_TX), MP_ROM_PTR(&pin_PA22) }, + { MP_ROM_QSTR(MP_QSTR_XB2_RX), MP_ROM_PTR(&pin_PA11) }, + { MP_ROM_QSTR(MP_QSTR_XB2_TX), MP_ROM_PTR(&pin_PA10) }, + + + // Comm objects + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/atmel-samd/mpconfigport.mk b/ports/atmel-samd/mpconfigport.mk index 2962035cb9..f04055d43b 100644 --- a/ports/atmel-samd/mpconfigport.mk +++ b/ports/atmel-samd/mpconfigport.mk @@ -41,6 +41,7 @@ CIRCUITPY_BUILTINS_POW3 ?= 0 CIRCUITPY_COMPUTED_GOTO_SAVE_SPACE ?= 1 CIRCUITPY_FREQUENCYIO ?= 0 CIRCUITPY_JSON ?= 0 +CIRCUITPY_SYNTHIO ?= 0 CIRCUITPY_TOUCHIO_USE_NATIVE ?= 1 # No room for HCI _bleio on SAMD21. @@ -87,3 +88,22 @@ CIRCUITPY_FRAMEBUFFERIO ?= $(CIRCUITPY_FULL_BUILD) endif # samd51 ###################################################################### + +###################################################################### +# Put same51-only choices here. + +ifeq ($(CHIP_FAMILY),same51) + +# No native touchio on SAMD51. +CIRCUITPY_TOUCHIO_USE_NATIVE = 0 + +# The ?='s allow overriding in mpconfigboard.mk. + +CIRCUITPY_NETWORK ?= 0 +CIRCUITPY_PS2IO ?= 1 +CIRCUITPY_SAMD ?= 1 +CIRCUITPY_RGBMATRIX ?= $(CIRCUITPY_FULL_BUILD) +CIRCUITPY_FRAMEBUFFERIO ?= $(CIRCUITPY_FULL_BUILD) + +endif # same51 +###################################################################### diff --git a/ports/esp32s2/boards/atmegazero_esp32s2/board.c b/ports/esp32s2/boards/atmegazero_esp32s2/board.c new file mode 100644 index 0000000000..d8fd3a0a2b --- /dev/null +++ b/ports/esp32s2/boards/atmegazero_esp32s2/board.c @@ -0,0 +1,61 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries + * + * 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 "supervisor/board.h" +#include "mpconfigboard.h" +#include "shared-bindings/microcontroller/Pin.h" + +void board_init(void) { + // USB + common_hal_never_reset_pin(&pin_GPIO19); + common_hal_never_reset_pin(&pin_GPIO20); + + // Debug UART +#ifdef DEBUG + common_hal_never_reset_pin(&pin_GPIO43); + common_hal_never_reset_pin(&pin_GPIO44); +#endif /* DEBUG */ + + // SPI Flash and RAM + common_hal_never_reset_pin(&pin_GPIO26); + common_hal_never_reset_pin(&pin_GPIO27); + common_hal_never_reset_pin(&pin_GPIO28); + common_hal_never_reset_pin(&pin_GPIO29); + common_hal_never_reset_pin(&pin_GPIO30); + common_hal_never_reset_pin(&pin_GPIO31); + common_hal_never_reset_pin(&pin_GPIO32); +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { + +} + +void board_deinit(void) { +} diff --git a/ports/esp32s2/boards/atmegazero_esp32s2/mpconfigboard.h b/ports/esp32s2/boards/atmegazero_esp32s2/mpconfigboard.h new file mode 100644 index 0000000000..3ef4e7eede --- /dev/null +++ b/ports/esp32s2/boards/atmegazero_esp32s2/mpconfigboard.h @@ -0,0 +1,47 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries + * + * 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. + */ + +//Micropython setup + +#define MICROPY_HW_BOARD_NAME "ATMegaZero ESP32-S2" +#define MICROPY_HW_MCU_NAME "ESP32S2" + +#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0) +#define BOARD_USER_SAFE_MODE_ACTION translate("pressing boot button at start up.\n") + +#define AUTORESET_DELAY_MS 500 + +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO9) +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO8) + +#define DEFAULT_SPI_BUS_SCK (&pin_GPIO36) +#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO35) +#define DEFAULT_SPI_BUS_MISO (&pin_GPIO37) + +#define DEFAULT_UART_BUS_RX (&pin_GPIO44) +#define DEFAULT_UART_BUS_TX (&pin_GPIO43) + +#define MICROPY_HW_NEOPIXEL (&pin_GPIO40) diff --git a/ports/esp32s2/boards/atmegazero_esp32s2/mpconfigboard.mk b/ports/esp32s2/boards/atmegazero_esp32s2/mpconfigboard.mk new file mode 100644 index 0000000000..9a5d947e6c --- /dev/null +++ b/ports/esp32s2/boards/atmegazero_esp32s2/mpconfigboard.mk @@ -0,0 +1,15 @@ +USB_VID = 0x239A +USB_PID = 0x8009 +USB_PRODUCT = "ATMegaZero ESP32-S2" +USB_MANUFACTURER = "ATMegaZero" + +INTERNAL_FLASH_FILESYSTEM = 1 +LONGINT_IMPL = MPZ + +# The default queue depth of 16 overflows on release builds, +# so increase it to 32. +CFLAGS += -DCFG_TUD_TASK_QUEUE_SZ=32 + +CIRCUITPY_ESP_FLASH_MODE=qio +CIRCUITPY_ESP_FLASH_FREQ=40m +CIRCUITPY_ESP_FLASH_SIZE=16MB diff --git a/ports/esp32s2/boards/atmegazero_esp32s2/pins.c b/ports/esp32s2/boards/atmegazero_esp32s2/pins.c new file mode 100644 index 0000000000..cfc4ef6223 --- /dev/null +++ b/ports/esp32s2/boards/atmegazero_esp32s2/pins.c @@ -0,0 +1,80 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_IO6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_IO10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_IO11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_IO12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_IO13), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_IO14), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_IO17), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_IO18), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_IO33), MP_ROM_PTR(&pin_GPIO33) }, + { MP_ROM_QSTR(MP_QSTR_IO34), MP_ROM_PTR(&pin_GPIO34) }, + { MP_ROM_QSTR(MP_QSTR_IO35), MP_ROM_PTR(&pin_GPIO35) }, + { MP_ROM_QSTR(MP_QSTR_IO36), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_IO37), MP_ROM_PTR(&pin_GPIO37) }, + { MP_ROM_QSTR(MP_QSTR_IO38), MP_ROM_PTR(&pin_GPIO38) }, + { MP_ROM_QSTR(MP_QSTR_IO40), MP_ROM_PTR(&pin_GPIO40) }, + { MP_ROM_QSTR(MP_QSTR_IO43), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_IO44), MP_ROM_PTR(&pin_GPIO44) }, + + { MP_ROM_QSTR(MP_QSTR_PD5), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_HWD), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_AREF), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO33) }, + { MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_GPIO34) }, + { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_GPIO35) }, + { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_GPIO37) }, + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_GPIO38) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO44) }, + + { MP_ROM_QSTR(MP_QSTR_SD_CS), MP_ROM_PTR(&pin_GPIO0) }, + + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO9) }, + + { MP_ROM_QSTR(MP_QSTR_DAC1), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_DAC2), MP_ROM_PTR(&pin_GPIO18) }, + + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO35) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO37) }, + + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO40) }, + + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) }, + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/esp32s2/boards/atmegazero_esp32s2/sdkconfig b/ports/esp32s2/boards/atmegazero_esp32s2/sdkconfig new file mode 100644 index 0000000000..f42e0784c4 --- /dev/null +++ b/ports/esp32s2/boards/atmegazero_esp32s2/sdkconfig @@ -0,0 +1,39 @@ +CONFIG_ESP32S2_SPIRAM_SUPPORT=y + +# +# SPI RAM config +# +# CONFIG_SPIRAM_TYPE_AUTO is not set +# CONFIG_SPIRAM_TYPE_ESPPSRAM16 is not set +# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set +CONFIG_SPIRAM_TYPE_ESPPSRAM64=y +CONFIG_SPIRAM_SIZE=8388608 + +# +# PSRAM clock and cs IO for ESP32S2 +# +CONFIG_DEFAULT_PSRAM_CLK_IO=30 +CONFIG_DEFAULT_PSRAM_CS_IO=26 +# end of PSRAM clock and cs IO for ESP32S2 + +# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set +# CONFIG_SPIRAM_RODATA is not set +# CONFIG_SPIRAM_SPEED_80M is not set +CONFIG_SPIRAM_SPEED_40M=y +# CONFIG_SPIRAM_SPEED_26M is not set +# CONFIG_SPIRAM_SPEED_20M is not set +CONFIG_SPIRAM=y +CONFIG_SPIRAM_BOOT_INIT=y +# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set +CONFIG_SPIRAM_USE_MEMMAP=y +# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set +# CONFIG_SPIRAM_USE_MALLOC is not set +CONFIG_SPIRAM_MEMTEST=y +# CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY is not set +# end of SPI RAM config + +# +# LWIP +# +CONFIG_LWIP_LOCAL_HOSTNAME="ATMegaZero-Esp32s2" +# end of LWIP diff --git a/ports/nrf/boards/aramcon2_badge/board.c b/ports/nrf/boards/aramcon2_badge/board.c new file mode 100644 index 0000000000..1759822a2a --- /dev/null +++ b/ports/nrf/boards/aramcon2_badge/board.c @@ -0,0 +1,40 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Uri Shaked + * Copyright (c) 2021 Benjamin Meisels + * + * 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 "supervisor/board.h" +#include "common-hal/microcontroller/Pin.h" + +void board_init(void) { +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { + +} diff --git a/ports/nrf/boards/aramcon2_badge/mpconfigboard.h b/ports/nrf/boards/aramcon2_badge/mpconfigboard.h new file mode 100644 index 0000000000..7691d1e461 --- /dev/null +++ b/ports/nrf/boards/aramcon2_badge/mpconfigboard.h @@ -0,0 +1,68 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Uri Shaked + * Copyright (c) 2021 Benjamin Meisels + * + * 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 "nrfx/hal/nrf_gpio.h" + +#define MICROPY_HW_BOARD_NAME "ARAMCON2 Badge" +#define MICROPY_HW_MCU_NAME "nRF52840" + +#define MICROPY_HW_LED_STATUS (&pin_P1_11) + +// Board does not have a 32kHz crystal. It does have a 32MHz crystal. +#define BOARD_HAS_32KHZ_XTAL (0) + +#ifdef QSPI_FLASH_FILESYSTEM +#define MICROPY_QSPI_DATA0 NRF_GPIO_PIN_MAP(0, 22) +#define MICROPY_QSPI_DATA1 NRF_GPIO_PIN_MAP(0, 20) +#define MICROPY_QSPI_DATA2 NRF_GPIO_PIN_MAP(1, 4) +#define MICROPY_QSPI_DATA3 NRF_GPIO_PIN_MAP(1, 6) +#define MICROPY_QSPI_SCK NRF_GPIO_PIN_MAP(1, 0) +#define MICROPY_QSPI_CS NRF_GPIO_PIN_MAP(1, 2) +#endif + +#ifdef SPI_FLASH_FILESYSTEM +#define SPI_FLASH_MOSI_PIN &pin_P0_20 +#define SPI_FLASH_MISO_PIN &pin_P0_22 +#define SPI_FLASH_SCK_PIN &pin_P1_00 +#define SPI_FLASH_CS_PIN &pin_P1_02 +#endif + +#define CIRCUITPY_BOOT_BUTTON (&pin_P0_29) + +#define BOARD_USER_SAFE_MODE_ACTION translate("pressing the left button at start up\n") + +#define CIRCUITPY_AUTORELOAD_DELAY_MS 500 + +#define CIRCUITPY_INTERNAL_NVM_SIZE (4096) + +#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000 - CIRCUITPY_INTERNAL_NVM_SIZE) + +#define DEFAULT_I2C_BUS_SCL (&pin_P0_28) +#define DEFAULT_I2C_BUS_SDA (&pin_P0_03) + +#define DEFAULT_SPI_BUS_SCK (&pin_P0_01) +#define DEFAULT_SPI_BUS_MOSI (&pin_P1_10) +#define DEFAULT_SPI_BUS_MISO (&pin_P1_09) diff --git a/ports/nrf/boards/aramcon2_badge/mpconfigboard.mk b/ports/nrf/boards/aramcon2_badge/mpconfigboard.mk new file mode 100644 index 0000000000..514712f489 --- /dev/null +++ b/ports/nrf/boards/aramcon2_badge/mpconfigboard.mk @@ -0,0 +1,11 @@ +USB_VID = 0x239A +USB_PID = 0x807C +USB_PRODUCT = "ARAMCON2 Badge" +USB_MANUFACTURER = "ARAMCON Badge Team" + +MCU_CHIP = nrf52840 + +QSPI_FLASH_FILESYSTEM = 1 +EXTERNAL_FLASH_DEVICES = "W25Q128JVxQ" + +CIRCUITPY_DISPLAYIO = 1 diff --git a/ports/nrf/boards/aramcon2_badge/pins.c b/ports/nrf/boards/aramcon2_badge/pins.c new file mode 100644 index 0000000000..0a44f0d5a9 --- /dev/null +++ b/ports/nrf/boards/aramcon2_badge/pins.c @@ -0,0 +1,42 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR_UP_BUTTON), MP_ROM_PTR(&pin_P0_31) }, + { MP_ROM_QSTR(MP_QSTR_LEFT_BUTTON), MP_ROM_PTR(&pin_P0_29) }, + { MP_ROM_QSTR(MP_QSTR_DOWN_BUTTON), MP_ROM_PTR(&pin_P1_13) }, + { MP_ROM_QSTR(MP_QSTR_RIGHT_BUTTON), MP_ROM_PTR(&pin_P0_02) }, + { MP_ROM_QSTR(MP_QSTR_ACTION_BUTTON), MP_ROM_PTR(&pin_P0_10) }, + + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_P1_11) }, + + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_P0_28) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_P0_03) }, + + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_P0_01) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_P1_10) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_P1_09) }, + + { MP_ROM_QSTR(MP_QSTR_GPIO1), MP_ROM_PTR(&pin_P0_04) }, + { MP_ROM_QSTR(MP_QSTR_GPIO2), MP_ROM_PTR(&pin_P0_05) }, + + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_P0_15) }, + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_P0_00) }, + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_P0_13) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_P0_24) }, + + { MP_ROM_QSTR(MP_QSTR_DISP_BUSY), MP_ROM_PTR(&pin_P0_26) }, + { MP_ROM_QSTR(MP_QSTR_DISP_CS), MP_ROM_PTR(&pin_P0_07) }, + { MP_ROM_QSTR(MP_QSTR_DISP_DC), MP_ROM_PTR(&pin_P0_12) }, + { MP_ROM_QSTR(MP_QSTR_DISP_RESET), MP_ROM_PTR(&pin_P0_06) }, + + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_P0_08) }, + + { MP_ROM_QSTR(MP_QSTR_VIBRATION_MOTOR), MP_ROM_PTR(&pin_P0_17) }, + + { MP_ROM_QSTR(MP_QSTR_BATTERY_SENSE), MP_ROM_PTR(&pin_P0_30) }, + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, +}; + +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/nrf/boards/pca10100/mpconfigboard.mk b/ports/nrf/boards/pca10100/mpconfigboard.mk index 74080a1ed9..dd59eb96c9 100644 --- a/ports/nrf/boards/pca10100/mpconfigboard.mk +++ b/ports/nrf/boards/pca10100/mpconfigboard.mk @@ -7,6 +7,7 @@ MCU_CHIP = nrf52833 INTERNAL_FLASH_FILESYSTEM = 1 +CIRCUITPY_ALARM = 0 CIRCUITPY_AUDIOMP3 = 0 CIRCUITPY_BITBANGIO = 0 CIRCUITPY_BITMAPTOOLS = 0 diff --git a/ports/nrf/boards/simmel/mpconfigboard.mk b/ports/nrf/boards/simmel/mpconfigboard.mk index 005ec8af2f..e235fd1051 100644 --- a/ports/nrf/boards/simmel/mpconfigboard.mk +++ b/ports/nrf/boards/simmel/mpconfigboard.mk @@ -10,11 +10,13 @@ MCU_CHIP = nrf52833 INTERNAL_FLASH_FILESYSTEM = 1 +CIRCUITPY_ALARM = 0 CIRCUITPY_AESIO = 1 CIRCUITPY_AUDIOMP3 = 0 CIRCUITPY_BITMAPTOOLS = 0 CIRCUITPY_BUSDEVICE = 0 CIRCUITPY_BUSIO = 1 +CIRCUITPY_COUNTIO = 0 CIRCUITPY_DISPLAYIO = 0 CIRCUITPY_ERRNO = 0 CIRCUITPY_FRAMEBUFFERIO = 0 @@ -23,10 +25,13 @@ CIRCUITPY_MSGPACK = 0 CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_NVM = 0 CIRCUITPY_PIXELBUF = 0 +CIRCUITPY_PULSEIO = 0 +CIRCUITPY_PWMIO = 1 CIRCUITPY_RGBMATRIX = 0 CIRCUITPY_ROTARYIO = 0 CIRCUITPY_RTC = 1 CIRCUITPY_SDCARDIO = 0 +CIRCUITPY_SYNTHIO = 0 CIRCUITPY_TOUCHIO = 0 CIRCUITPY_ULAB = 0 CIRCUITPY_USB_CDC = 0 diff --git a/ports/nrf/common-hal/_bleio/Characteristic.c b/ports/nrf/common-hal/_bleio/Characteristic.c index 4c5de3124e..f651b93b6b 100644 --- a/ports/nrf/common-hal/_bleio/Characteristic.c +++ b/ports/nrf/common-hal/_bleio/Characteristic.c @@ -131,6 +131,10 @@ size_t common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *sel return 0; } +size_t common_hal_bleio_characteristic_get_max_length(bleio_characteristic_obj_t *self) { + return self->max_length; +} + void common_hal_bleio_characteristic_set_value(bleio_characteristic_obj_t *self, mp_buffer_info_t *bufinfo) { // Do GATT operations only if this characteristic has been added to a registered service. if (self->handle != BLE_GATT_HANDLE_INVALID) { diff --git a/ports/nrf/common-hal/_bleio/PacketBuffer.c b/ports/nrf/common-hal/_bleio/PacketBuffer.c index 42fc3475d6..260e20514b 100644 --- a/ports/nrf/common-hal/_bleio/PacketBuffer.c +++ b/ports/nrf/common-hal/_bleio/PacketBuffer.c @@ -42,7 +42,8 @@ STATIC void write_to_ringbuf(bleio_packet_buffer_obj_t *self, uint8_t *data, uint16_t len) { if (len + sizeof(uint16_t) > ringbuf_capacity(&self->ringbuf)) { - // This shouldn't happen. + // This shouldn't happen but can if our buffer size was much smaller than + // the writes the client actually makes. return; } // Push all the data onto the ring buffer. @@ -189,7 +190,7 @@ STATIC bool packet_buffer_on_ble_server_evt(ble_evt_t *ble_evt, void *param) { void common_hal_bleio_packet_buffer_construct( bleio_packet_buffer_obj_t *self, bleio_characteristic_obj_t *characteristic, - size_t buffer_size) { + size_t buffer_size, size_t max_packet_size) { self->characteristic = characteristic; self->client = self->characteristic->service->is_remote; @@ -206,8 +207,11 @@ void common_hal_bleio_packet_buffer_construct( self->conn_handle = BLE_CONN_HANDLE_INVALID; } + // Cap the packet size to our implementation limits. + self->max_packet_size = MIN(max_packet_size, BLE_GATTS_VAR_ATTR_LEN_MAX - 3); + if (incoming) { - if (!ringbuf_alloc(&self->ringbuf, buffer_size * (sizeof(uint16_t) + characteristic->max_length), false)) { + if (!ringbuf_alloc(&self->ringbuf, buffer_size * (sizeof(uint16_t) + self->max_packet_size), false)) { mp_raise_ValueError(translate("Buffer too large and unable to allocate")); } } @@ -216,8 +220,8 @@ void common_hal_bleio_packet_buffer_construct( self->packet_queued = false; self->pending_index = 0; self->pending_size = 0; - self->outgoing[0] = m_malloc(characteristic->max_length, false); - self->outgoing[1] = m_malloc(characteristic->max_length, false); + self->outgoing[0] = m_malloc(self->max_packet_size, false); + self->outgoing[1] = m_malloc(self->max_packet_size, false); } else { self->outgoing[0] = NULL; self->outgoing[1] = NULL; @@ -296,10 +300,16 @@ mp_int_t common_hal_bleio_packet_buffer_write(bleio_packet_buffer_obj_t *self, u } uint16_t outgoing_packet_length = common_hal_bleio_packet_buffer_get_outgoing_packet_length(self); - if (len + header_len > outgoing_packet_length) { + uint16_t total_len = len + header_len; + if (total_len > outgoing_packet_length) { // Supplied data will not fit in a single BLE packet. - mp_raise_ValueError(translate("Total data to write is larger than outgoing_packet_length")); + mp_raise_ValueError_varg(translate("Total data to write is larger than %q"), MP_QSTR_outgoing_packet_length); } + if (total_len > self->max_packet_size) { + // Supplied data will not fit in a single BLE packet. + mp_raise_ValueError_varg(translate("Total data to write is larger than %q"), MP_QSTR_max_packet_size); + } + outgoing_packet_length = MIN(outgoing_packet_length, self->max_packet_size); if (len + self->pending_size > outgoing_packet_length) { // No room to append len bytes to packet. Wait until we get a free buffer, @@ -390,8 +400,9 @@ mp_int_t common_hal_bleio_packet_buffer_get_outgoing_packet_length(bleio_packet_ if (self->conn_handle != BLE_CONN_HANDLE_INVALID) { bleio_connection_internal_t *connection = bleio_conn_handle_to_connection(self->conn_handle); if (connection) { - return MIN(common_hal_bleio_connection_get_max_packet_length(connection), - self->characteristic->max_length); + return MIN(MIN(common_hal_bleio_connection_get_max_packet_length(connection), + self->max_packet_size), + self->characteristic->max_length); } } // There's no current connection, so we don't know the MTU, and @@ -406,11 +417,12 @@ mp_int_t common_hal_bleio_packet_buffer_get_outgoing_packet_length(bleio_packet_ if (self->conn_handle != BLE_CONN_HANDLE_INVALID) { bleio_connection_internal_t *connection = bleio_conn_handle_to_connection(self->conn_handle); if (connection) { - return common_hal_bleio_connection_get_max_packet_length(connection); + return MIN(common_hal_bleio_connection_get_max_packet_length(connection), + self->max_packet_size); } } } - return self->characteristic->max_length; + return MIN(self->characteristic->max_length, self->max_packet_size); } bool common_hal_bleio_packet_buffer_deinited(bleio_packet_buffer_obj_t *self) { diff --git a/ports/nrf/common-hal/_bleio/PacketBuffer.h b/ports/nrf/common-hal/_bleio/PacketBuffer.h index 94e0f11d80..6f2626565b 100644 --- a/ports/nrf/common-hal/_bleio/PacketBuffer.h +++ b/ports/nrf/common-hal/_bleio/PacketBuffer.h @@ -44,6 +44,7 @@ typedef struct { // We remember the conn_handle so we can do a NOTIFY/INDICATE to a client. // We can find out the conn_handle on a Characteristic write or a CCCD write (but not a read). volatile uint16_t conn_handle; + uint16_t max_packet_size; uint8_t pending_index; uint8_t write_type; bool client; diff --git a/ports/nrf/common-hal/alarm/SleepMemory.c b/ports/nrf/common-hal/alarm/SleepMemory.c index 367f305972..e20f893567 100644 --- a/ports/nrf/common-hal/alarm/SleepMemory.c +++ b/ports/nrf/common-hal/alarm/SleepMemory.c @@ -3,8 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2020 microDev - * Copyright (c) 2020 Dan Halbert for Adafruit Industries + * Copyright (c) 2021 Junji Sakai * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -57,22 +56,22 @@ void set_memory_retention(void) { // nRF52833 has RAM[0..7].Section[0..1] and RAM[8].Section[0,1] for(int block = 0; block <= 7; ++block) { nrf_power_rampower_mask_on(NRF_POWER, block, - NRF_POWER_RAMPOWER_S0RETENTION_MASK | - NRF_POWER_RAMPOWER_S1RETENTION_MASK); + NRF_POWER_RAMPOWER_S0RETENTION_MASK | + NRF_POWER_RAMPOWER_S1RETENTION_MASK); }; #ifdef NRF52840 nrf_power_rampower_mask_on(NRF_POWER, 8, - NRF_POWER_RAMPOWER_S0RETENTION_MASK | - NRF_POWER_RAMPOWER_S1RETENTION_MASK | - NRF_POWER_RAMPOWER_S2RETENTION_MASK | - NRF_POWER_RAMPOWER_S3RETENTION_MASK | - NRF_POWER_RAMPOWER_S4RETENTION_MASK | - NRF_POWER_RAMPOWER_S5RETENTION_MASK); + NRF_POWER_RAMPOWER_S0RETENTION_MASK | + NRF_POWER_RAMPOWER_S1RETENTION_MASK | + NRF_POWER_RAMPOWER_S2RETENTION_MASK | + NRF_POWER_RAMPOWER_S3RETENTION_MASK | + NRF_POWER_RAMPOWER_S4RETENTION_MASK | + NRF_POWER_RAMPOWER_S5RETENTION_MASK); #endif #ifdef NRF52833 nrf_power_rampower_mask_on(NRF_POWER, 8, - NRF_POWER_RAMPOWER_S0RETENTION_MASK | - NRF_POWER_RAMPOWER_S1RETENTION_MASK); + NRF_POWER_RAMPOWER_S0RETENTION_MASK | + NRF_POWER_RAMPOWER_S1RETENTION_MASK); #endif } @@ -93,7 +92,7 @@ void alarm_sleep_memory_reset(void) { if (!is_sleep_memory_valid()) { initialize_sleep_memory(); #ifdef NRF_DEBUG_PRINT - dbg_printf("sleep memory initialized\r\n"); + dbg_printf("sleep memory initialized\r\n"); #endif } } diff --git a/ports/nrf/common-hal/alarm/SleepMemory.h b/ports/nrf/common-hal/alarm/SleepMemory.h index 11cc4a8fb9..8fd702ea83 100644 --- a/ports/nrf/common-hal/alarm/SleepMemory.h +++ b/ports/nrf/common-hal/alarm/SleepMemory.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2020 Dan Halbert for Adafruit Industries + * Copyright (c) 2021 Junji Sakai * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index f678b5f22b..4c00cc4216 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -102,7 +102,7 @@ static const char* cause_str[] = { void print_wakeup_cause(nrf_sleep_source_t cause) { if (cause >= 0 && cause < NRF_SLEEP_WAKEUP_ZZZ) { dbg_printf("wakeup cause = NRF_SLEEP_WAKEUP_%s\r\n", - cause_str[(int)cause]); + cause_str[(int)cause]); } } #endif @@ -115,14 +115,14 @@ bool common_hal_alarm_woken_from_sleep(void) { } #endif return (cause == NRF_SLEEP_WAKEUP_GPIO || cause == NRF_SLEEP_WAKEUP_TIMER - || cause == NRF_SLEEP_WAKEUP_TOUCHPAD); + || cause == NRF_SLEEP_WAKEUP_TOUCHPAD); } nrf_sleep_source_t alarm_woken_from_sleep_2(void) { nrf_sleep_source_t cause = _get_wakeup_cause(); if (cause == NRF_SLEEP_WAKEUP_GPIO || - cause == NRF_SLEEP_WAKEUP_TIMER || - cause == NRF_SLEEP_WAKEUP_TOUCHPAD) { + cause == NRF_SLEEP_WAKEUP_TIMER || + cause == NRF_SLEEP_WAKEUP_TOUCHPAD) { return cause; } else { @@ -160,6 +160,9 @@ STATIC void _setup_sleep_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t alarm_touch_touchalarm_set_alarm(deep_sleep, n_alarms, alarms); } +// TODO: this handles all possible types of wakeup, which is redundant with main. +// revise to extract all parts essential to enabling sleep wakeup, but leave the +// alarm/non-alarm sorting to the existing main loop. nrf_sleep_source_t system_on_idle_until_alarm(int64_t timediff_ms, uint32_t prescaler) { bool have_timeout = false; uint64_t start_tick = 0, end_tick = 0; @@ -172,22 +175,22 @@ nrf_sleep_source_t system_on_idle_until_alarm(int64_t timediff_ms, uint32_t pres if (timediff_ms != -1) { have_timeout = true; #if 0 - int64_t now = common_hal_time_monotonic_ms(); - dbg_printf("now_ms=%ld timediff_ms=%ld\r\n", (long)now, (long)timediff_ms); + int64_t now = common_hal_time_monotonic_ms(); + dbg_printf("now_ms=%ld timediff_ms=%ld\r\n", (long)now, (long)timediff_ms); #endif - if (timediff_ms < 0) timediff_ms = 0; - if (prescaler == 0) { - // 1 tick = 1/1024 sec = 1000/1024 ms - // -> 1 ms = 1024/1000 ticks - tickdiff = (mp_uint_t)(timediff_ms * 1024 / 1000); // ms -> ticks - } - else { - // 1 tick = prescaler/1024 sec = prescaler*1000/1024 ms - // -> 1ms = 1024/(1000*prescaler) ticks - tickdiff = (mp_uint_t)(timediff_ms * 1024 / (1000 * prescaler)); - } - start_tick = port_get_raw_ticks(NULL); - end_tick = start_tick + tickdiff; + if (timediff_ms < 0) timediff_ms = 0; + if (prescaler == 0) { + // 1 tick = 1/1024 sec = 1000/1024 ms + // -> 1 ms = 1024/1000 ticks + tickdiff = (mp_uint_t)(timediff_ms * 1024 / 1000); // ms -> ticks + } + else { + // 1 tick = prescaler/1024 sec = prescaler*1000/1024 ms + // -> 1ms = 1024/(1000*prescaler) ticks + tickdiff = (mp_uint_t)(timediff_ms * 1024 / (1000 * prescaler)); + } + start_tick = port_get_raw_ticks(NULL); + end_tick = start_tick + tickdiff; } #if 0 dbg_printf("start_tick=%ld end_tick=%ld have_timeout=%c\r\n", (long)start_tick, (long)end_tick, have_timeout ? 'T' : 'F'); @@ -207,30 +210,30 @@ nrf_sleep_source_t system_on_idle_until_alarm(int64_t timediff_ms, uint32_t pres #endif while(1) { - if (mp_hal_is_interrupted()) { - WAKEUP_REASON('I'); - break; - } + if (mp_hal_is_interrupted()) { + WAKEUP_REASON('I'); + break; + } if (serial_connected() && serial_bytes_available()) { - WAKEUP_REASON('S'); - break; - } + WAKEUP_REASON('S'); + break; + } RUN_BACKGROUND_TASKS; - wakeup_cause = alarm_woken_from_sleep_2(); - if (wakeup_cause != NRF_SLEEP_WAKEUP_UNDEFINED) { - WAKEUP_REASON('0'+wakeup_cause); - break; - } - if (have_timeout) { - remaining = end_tick - port_get_raw_ticks(NULL); - // We break a bit early so we don't risk setting the alarm before the time when we call - // sleep. - if (remaining < 1) { - WAKEUP_REASON('t'); - break; - } - port_interrupt_after_ticks(remaining); - } + wakeup_cause = alarm_woken_from_sleep_2(); + if (wakeup_cause != NRF_SLEEP_WAKEUP_UNDEFINED) { + WAKEUP_REASON('0'+wakeup_cause); + break; + } + if (have_timeout) { + remaining = end_tick - port_get_raw_ticks(NULL); + // We break a bit early so we don't risk setting the alarm before the time when we call + // sleep. + if (remaining < 1) { + WAKEUP_REASON('t'); + break; + } + port_interrupt_after_ticks(remaining); + } // Idle until an interrupt happens. port_idle_until_interrupt(); #ifdef NRF_DEBUG_PRINT @@ -239,15 +242,15 @@ nrf_sleep_source_t system_on_idle_until_alarm(int64_t timediff_ms, uint32_t pres --ct; } #endif - if (have_timeout) { - remaining = end_tick - port_get_raw_ticks(NULL); - if (remaining <= 0) { - wakeup_cause = NRF_SLEEP_WAKEUP_TIMER; - sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_TIMER; - WAKEUP_REASON('T'); - break; - } - } + if (have_timeout) { + remaining = end_tick - port_get_raw_ticks(NULL); + if (remaining <= 0) { + wakeup_cause = NRF_SLEEP_WAKEUP_TIMER; + sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_TIMER; + WAKEUP_REASON('T'); + break; + } + } } #ifdef NRF_DEBUG_PRINT dbg_printf("%c\r\n", reason); @@ -324,7 +327,7 @@ void NORETURN common_hal_alarm_enter_deep_sleep(void) { #endif nrf_sleep_source_t cause; cause = system_on_idle_until_alarm(timediff_ms, - PRESCALER_VALUE_IN_DEEP_SLEEP); + PRESCALER_VALUE_IN_DEEP_SLEEP); (void)cause; #ifdef NRF_DEBUG_PRINT @@ -375,13 +378,13 @@ void common_hal_alarm_pretending_deep_sleep(void) { print_wakeup_cause(cause); #endif - alarm_reset(); + // alarm_reset(); #if 0 // if one of Alarm event occurred, reset myself if (cause == NRF_SLEEP_WAKEUP_GPIO || - cause == NRF_SLEEP_WAKEUP_TIMER || - cause == NRF_SLEEP_WAKEUP_TOUCHPAD) { + cause == NRF_SLEEP_WAKEUP_TIMER || + cause == NRF_SLEEP_WAKEUP_TOUCHPAD) { reset_cpu(); } // else, just return and go into REPL diff --git a/ports/nrf/common-hal/alarm/__init__.h b/ports/nrf/common-hal/alarm/__init__.h index 642fb7d93a..47051dbd72 100644 --- a/ports/nrf/common-hal/alarm/__init__.h +++ b/ports/nrf/common-hal/alarm/__init__.h @@ -31,13 +31,13 @@ #include "common-hal/alarm/SleepMemory.h" typedef enum { - NRF_SLEEP_WAKEUP_UNDEFINED, - NRF_SLEEP_WAKEUP_GPIO, - NRF_SLEEP_WAKEUP_TIMER, - NRF_SLEEP_WAKEUP_TOUCHPAD, - NRF_SLEEP_WAKEUP_VBUS, - NRF_SLEEP_WAKEUP_RESETPIN, - NRF_SLEEP_WAKEUP_ZZZ + NRF_SLEEP_WAKEUP_UNDEFINED, + NRF_SLEEP_WAKEUP_GPIO, + NRF_SLEEP_WAKEUP_TIMER, + NRF_SLEEP_WAKEUP_TOUCHPAD, + NRF_SLEEP_WAKEUP_VBUS, + NRF_SLEEP_WAKEUP_RESETPIN, + NRF_SLEEP_WAKEUP_ZZZ } nrf_sleep_source_t; extern const alarm_sleep_memory_obj_t alarm_sleep_memory_obj; diff --git a/ports/nrf/common-hal/alarm/pin/PinAlarm.c b/ports/nrf/common-hal/alarm/pin/PinAlarm.c index fcfd02f84c..59bb4a84a1 100644 --- a/ports/nrf/common-hal/alarm/pin/PinAlarm.c +++ b/ports/nrf/common-hal/alarm/pin/PinAlarm.c @@ -87,7 +87,7 @@ static void pinalarm_gpiote_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t bool alarm_pin_pinalarm_woke_us_up(void) { return (sleepmem_wakeup_event == SLEEPMEM_WAKEUP_BY_PIN && - sleepmem_wakeup_pin != WAKEUP_PIN_UNDEF); + sleepmem_wakeup_pin != WAKEUP_PIN_UNDEF); } mp_obj_t alarm_pin_pinalarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *alarms) { @@ -97,7 +97,7 @@ mp_obj_t alarm_pin_pinalarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *al continue; } alarm_pin_pinalarm_obj_t *alarm = MP_OBJ_TO_PTR(alarms[i]); - if (alarm->pin->number == sleepmem_wakeup_pin) { + if (alarm->pin->number == sleepmem_wakeup_pin) { return alarms[i]; } } @@ -130,8 +130,8 @@ void alarm_pin_pinalarm_reset(void) { continue; } reset_pin_number(i); - nrfx_gpiote_in_event_disable((nrfx_gpiote_pin_t)i); - nrfx_gpiote_in_uninit((nrfx_gpiote_pin_t)i); + nrfx_gpiote_in_event_disable((nrfx_gpiote_pin_t)i); + nrfx_gpiote_in_uninit((nrfx_gpiote_pin_t)i); } high_alarms = 0; @@ -178,15 +178,15 @@ static void configure_pins_for_sleep(void) { cfg.pull = NRF_GPIO_PIN_NOPULL; } err = nrfx_gpiote_in_init((nrfx_gpiote_pin_t)i, &cfg, - pinalarm_gpiote_handler); - assert(err == NRFX_SUCCESS); + pinalarm_gpiote_handler); + assert(err == NRFX_SUCCESS); nrfx_gpiote_in_event_enable((nrfx_gpiote_pin_t)i, true); if (((high_alarms & mask) != 0) && ((low_alarms & mask) == 0)) { nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_HIGH); - } + } if (((high_alarms & mask) == 0) && ((low_alarms & mask) != 0)) { nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_LOW); - } + } } } @@ -203,7 +203,7 @@ void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ob alarm_pin_pinalarm_obj_t *alarm = MP_OBJ_TO_PTR(alarms[i]); pin_number = alarm->pin->number; - //dbg_printf("alarm_pin_pinalarm_set_alarms(pin#=%d, val=%d, pull=%d)\r\n", pin_number, alarm->value, alarm->pull); + //dbg_printf("alarm_pin_pinalarm_set_alarms(pin#=%d, val=%d, pull=%d)\r\n", pin_number, alarm->value, alarm->pull); if (alarm->value) { high_alarms |= 1ull << pin_number; high_count++; @@ -222,8 +222,8 @@ void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ob else { // we don't setup gpio HW here but do them in // alarm_pin_pinalarm_prepare_for_deep_sleep() below - reset_reason_saved = 0; - pins_configured = false; + reset_reason_saved = 0; + pins_configured = false; } } else { @@ -234,9 +234,9 @@ void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ob void alarm_pin_pinalarm_prepare_for_deep_sleep(void) { if (!pins_configured) { configure_pins_for_sleep(); - pins_configured = true; + pins_configured = true; #ifdef NRF_DEBUG_PRINT - //dbg_dump_GPIOregs(); + //dbg_dump_GPIOregs(); #endif } } diff --git a/ports/nrf/common-hal/alarm/pin/PinAlarm.h b/ports/nrf/common-hal/alarm/pin/PinAlarm.h index 93672c1f2d..69684386fa 100644 --- a/ports/nrf/common-hal/alarm/pin/PinAlarm.h +++ b/ports/nrf/common-hal/alarm/pin/PinAlarm.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2020 Dan Halbert for Adafruit Industries + * Copyright (c) 2021 Junji Sakai * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/alarm/time/TimeAlarm.h b/ports/nrf/common-hal/alarm/time/TimeAlarm.h index a824c52535..2f65764e19 100644 --- a/ports/nrf/common-hal/alarm/time/TimeAlarm.h +++ b/ports/nrf/common-hal/alarm/time/TimeAlarm.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * Copyright (c) 2020 Dan Halbert for Adafruit Industries + * Copyright (c) 2021 Junji Sakai * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/ports/nrf/common-hal/microcontroller/Processor.c b/ports/nrf/common-hal/microcontroller/Processor.c index 4baa4eaace..bcad002ffe 100644 --- a/ports/nrf/common-hal/microcontroller/Processor.c +++ b/ports/nrf/common-hal/microcontroller/Processor.c @@ -141,9 +141,9 @@ mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { r = RESET_REASON_SOFTWARE; } else if ((reset_reason_saved & POWER_RESETREAS_OFF_Msk) || - (reset_reason_saved & POWER_RESETREAS_LPCOMP_Msk) || - (reset_reason_saved & POWER_RESETREAS_NFC_Msk) || - (reset_reason_saved & POWER_RESETREAS_VBUS_Msk)) { + (reset_reason_saved & POWER_RESETREAS_LPCOMP_Msk) || + (reset_reason_saved & POWER_RESETREAS_NFC_Msk) || + (reset_reason_saved & POWER_RESETREAS_VBUS_Msk)) { r = RESET_REASON_DEEP_SLEEP_ALARM; } return r; diff --git a/ports/nrf/mpconfigport.mk b/ports/nrf/mpconfigport.mk index a5766cf1fe..132aba208f 100644 --- a/ports/nrf/mpconfigport.mk +++ b/ports/nrf/mpconfigport.mk @@ -47,7 +47,7 @@ CIRCUITPY_COUNTIO = 0 CIRCUITPY_WATCHDOG ?= 1 # Sleep and Wakeup -CIRCUITPY_ALARM = 1 +CIRCUITPY_ALARM ?= 1 # nRF52840-specific diff --git a/ports/nrf/supervisor/debug_uart.c b/ports/nrf/supervisor/debug_uart.c index f770b661fc..9cf33279f7 100644 --- a/ports/nrf/supervisor/debug_uart.c +++ b/ports/nrf/supervisor/debug_uart.c @@ -1,6 +1,27 @@ /* - * debug functions - * (will be removed) + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Jun2Sak + * + * 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 @@ -33,11 +54,11 @@ static char _dbg_pbuf[DBG_PBUF_LEN+1]; void _debug_uart_uninit(void) { nrf_gpio_cfg(DEBUG_UART_TXPIN, - NRF_GPIO_PIN_DIR_INPUT, - NRF_GPIO_PIN_INPUT_DISCONNECT, - NRF_GPIO_PIN_NOPULL, - NRF_GPIO_PIN_S0S1, - NRF_GPIO_PIN_NOSENSE); + NRF_GPIO_PIN_DIR_INPUT, + NRF_GPIO_PIN_INPUT_DISCONNECT, + NRF_GPIO_PIN_NOPULL, + NRF_GPIO_PIN_S0S1, + NRF_GPIO_PIN_NOSENSE); nrfx_uarte_uninit(&_dbg_uart_inst); } @@ -59,11 +80,11 @@ void _debug_uart_init(void) { nrfx_uarte_init(&_dbg_uart_inst, &config, NULL); // drive config nrf_gpio_cfg(config.pseltxd, - NRF_GPIO_PIN_DIR_OUTPUT, - NRF_GPIO_PIN_INPUT_DISCONNECT, - NRF_GPIO_PIN_PULLUP, // orig=NOPULL - NRF_GPIO_PIN_H0H1, // orig=S0S1 - NRF_GPIO_PIN_NOSENSE); + NRF_GPIO_PIN_DIR_OUTPUT, + NRF_GPIO_PIN_INPUT_DISCONNECT, + NRF_GPIO_PIN_PULLUP, // orig=NOPULL + NRF_GPIO_PIN_H0H1, // orig=S0S1 + NRF_GPIO_PIN_NOSENSE); _dbg_uart_initialized = 1; return; } @@ -73,16 +94,16 @@ void _debug_print_substr(const char* text, uint32_t length) { int siz; while(length != 0) { if (length <= DBG_PBUF_LEN) { - siz = length; - } - else { - siz = DBG_PBUF_LEN; - } - memcpy(_dbg_pbuf, data, siz); - _dbg_pbuf[siz] = 0; - nrfx_uarte_tx(&_dbg_uart_inst, (uint8_t const*)_dbg_pbuf, siz); - data += siz; - length -= siz; + siz = length; + } + else { + siz = DBG_PBUF_LEN; + } + memcpy(_dbg_pbuf, data, siz); + _dbg_pbuf[siz] = 0; + nrfx_uarte_tx(&_dbg_uart_inst, (uint8_t const*)_dbg_pbuf, siz); + data += siz; + length -= siz; } } @@ -113,7 +134,7 @@ int dbg_check_RTCprescaler(void) { NRF_RTC_Type *r = rtc_instance.p_reg; if ((int)r->PRESCALER == 0) { dbg_printf("****** PRESCALER == 0\r\n"); - return -1; + return -1; } return 0; } @@ -135,20 +156,20 @@ void dbg_dump_GPIOregs(void) { const char cnf_sense_chr[] = "-?HL"; // sense high, sense low for(port=0, col=0; port<=1; ++port) { for(i=0; i<32; ++i) { - uint32_t cnf = gpio[port]->PIN_CNF[i]; - if (cnf != 0x0002) { // changed from default value - dbg_printf("[%d_%02d]:%c%c%c%d%c ", port, i, - (cnf & 1) ? 'O' : 'I', // output, input - (cnf & 2) ? 'd' : 'c', // disconnected, connected - cnf_pull_chr[(cnf >> 2) & 3], - (int)((cnf >> 8) & 7), // drive config 0-7 - cnf_sense_chr[(cnf >> 16) & 3]); - if (++col >= 6) { - dbg_printf("\r\n"); - col = 0; - } - } - } + uint32_t cnf = gpio[port]->PIN_CNF[i]; + if (cnf != 0x0002) { // changed from default value + dbg_printf("[%d_%02d]:%c%c%c%d%c ", port, i, + (cnf & 1) ? 'O' : 'I', // output, input + (cnf & 2) ? 'd' : 'c', // disconnected, connected + cnf_pull_chr[(cnf >> 2) & 3], + (int)((cnf >> 8) & 7), // drive config 0-7 + cnf_sense_chr[(cnf >> 16) & 3]); + if (++col >= 6) { + dbg_printf("\r\n"); + col = 0; + } + } + } } if (col > 0) dbg_printf("\r\n"); @@ -159,26 +180,26 @@ void dbg_dump_GPIOregs(void) { const char config_outinit_chr[] = "01"; // initial value is 0 or 1 for(i=0, col=0; i<8; ++i) { uint32_t conf = reg->CONFIG[i]; - if (conf != 0) { // changed from default value - dbg_printf("CONFIG[%d]:%d_%02d,%c%c%c ", i, - (int)((conf >> 13) & 1), (int)((conf >> 8) & 0x1F), - config_mode_chr[conf & 3], - config_pol_chr[(conf >> 16) & 3], - (conf & 3) == 3 ? - config_outinit_chr[(conf >> 20) & 1] : '-'); - if (++col >= 4) { - dbg_printf("\r\n"); - col = 0; - } - } + if (conf != 0) { // changed from default value + dbg_printf("CONFIG[%d]:%d_%02d,%c%c%c ", i, + (int)((conf >> 13) & 1), (int)((conf >> 8) & 0x1F), + config_mode_chr[conf & 3], + config_pol_chr[(conf >> 16) & 3], + (conf & 3) == 3 ? + config_outinit_chr[(conf >> 20) & 1] : '-'); + if (++col >= 4) { + dbg_printf("\r\n"); + col = 0; + } + } } if (col > 0) dbg_printf("\r\n"); for(i=0; i<8; ++i) { dbg_printf("EVENTS_IN[%d]:%X ", i, (int)(reg->EVENTS_IN[i])); - if ((i & 3) == 3) dbg_printf("\r\n"); + if ((i & 3) == 3) dbg_printf("\r\n"); } dbg_printf("EVENTS_PORT:%X INTENSET:%08X\r\n", - (int)(reg->EVENTS_PORT), (int)(reg->INTENSET)); + (int)(reg->EVENTS_PORT), (int)(reg->INTENSET)); } void dbg_dumpQSPIreg(void) { @@ -186,13 +207,13 @@ void dbg_dumpQSPIreg(void) { dbg_printf("QSPI\r\n"); r = NRF_QSPI->IFCONFIG0; dbg_printf("IFCONFIG0 READ=%ld write=%ld ADDR=%ld DPM=%ld PPSIZE=%ld\r\n", - r & 7, (r >> 3) & 7, (r >> 6) & 1, (r >> 7) & 1, (r >> 12) & 1); + r & 7, (r >> 3) & 7, (r >> 6) & 1, (r >> 7) & 1, (r >> 12) & 1); r = NRF_QSPI->IFCONFIG1; dbg_printf("IFCONFIG1 SCKDELAY=%ld SPIMODE=%ld SCKFREQ=%ld\r\n", - r & 0xFF, (r >> 25) & 1, (r >> 28) & 0xF); + r & 0xFF, (r >> 25) & 1, (r >> 28) & 0xF); r = NRF_QSPI->STATUS; dbg_printf("STATUS DPM=%ld READY=%ld SREG=0x%02lX\r\n", - (r >> 2) & 1, (r >> 3) & 1, (r >> 24) & 0xFF); + (r >> 2) & 1, (r >> 3) & 1, (r >> 24) & 0xFF); r = NRF_QSPI->DPMDUR; dbg_printf("DPMDUR ENTER=%ld EXIT=%ld\r\n", r & 0xFFFF, (r >> 16) & 0xFFFF); } diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c index c984feb77d..e162c64837 100644 --- a/ports/nrf/supervisor/port.c +++ b/ports/nrf/supervisor/port.c @@ -109,7 +109,9 @@ void rtc_handler(nrfx_rtc_int_type_t int_type) { nrfx_rtc_cc_set(&rtc_instance, 0, 0, false); } else if (int_type == NRFX_RTC_INT_COMPARE1) { // used in light sleep + #if CIRCUITPY_ALARM sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_TIMER; + #endif nrfx_rtc_cc_set(&rtc_instance, 1, 0, false); } } @@ -185,7 +187,9 @@ safe_mode_t port_init(void) { NRF_POWER->RESETREAS = reset_reason_saved; // clear wakeup event/pin when reset by reset-pin if (reset_reason_saved & NRF_POWER_RESETREAS_RESETPIN_MASK) { + #if CIRCUITPY_ALARM sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_NONE; + #endif } // If the board was reset by the WatchDogTimer, we may diff --git a/ports/nrf/supervisor/qspi_flash.c b/ports/nrf/supervisor/qspi_flash.c index f2beb3e3a9..6d1bec4422 100644 --- a/ports/nrf/supervisor/qspi_flash.c +++ b/ports/nrf/supervisor/qspi_flash.c @@ -281,7 +281,7 @@ void qspi_flash_enter_sleep(void) { // set sck_delay tempolarily r = NRF_QSPI->IFCONFIG1; sck_delay_saved = (r & QSPI_IFCONFIG1_SCKDELAY_Msk) - >> QSPI_IFCONFIG1_SCKDELAY_Pos; + >> QSPI_IFCONFIG1_SCKDELAY_Pos; NRF_QSPI->IFCONFIG1 = (NRF_QSPI->IFCONFIG1 & ~QSPI_IFCONFIG1_SCKDELAY_Msk) | (SCK_DELAY << QSPI_IFCONFIG1_SCKDELAY_Pos); @@ -312,20 +312,20 @@ void qspi_flash_exit_sleep(void) { if (NRF_QSPI->STATUS & QSPI_STATUS_DPM_Msk) { // exit deep power-down mode NRF_QSPI->IFCONFIG1 &= ~QSPI_IFCONFIG1_DPMEN_Msk; - NRFX_DELAY_US(WAIT_AFTER_DPM_EXIT); + NRFX_DELAY_US(WAIT_AFTER_DPM_EXIT); - if (NRF_QSPI->STATUS & QSPI_STATUS_DPM_Msk) { + if (NRF_QSPI->STATUS & QSPI_STATUS_DPM_Msk) { #ifdef NRF_DEBUG_PRINT - dbg_printf("qspi flash: exiting DPM failed\r\n"); + dbg_printf("qspi flash: exiting DPM failed\r\n"); #endif - } - // restore sck_delay - if (sck_delay_saved == 0) { - sck_delay_saved = 10; // default - } - NRF_QSPI->IFCONFIG1 - = (NRF_QSPI->IFCONFIG1 & ~QSPI_IFCONFIG1_SCKDELAY_Msk) - | (sck_delay_saved << QSPI_IFCONFIG1_SCKDELAY_Pos); + } + // restore sck_delay + if (sck_delay_saved == 0) { + sck_delay_saved = 10; // default + } + NRF_QSPI->IFCONFIG1 + = (NRF_QSPI->IFCONFIG1 & ~QSPI_IFCONFIG1_SCKDELAY_Msk) + | (sck_delay_saved << QSPI_IFCONFIG1_SCKDELAY_Pos); } //dbg_dumpQSPIreg(); #endif diff --git a/ports/raspberrypi/boards/pimoroni_picolipo_16mb/board.c b/ports/raspberrypi/boards/pimoroni_picolipo_16mb/board.c new file mode 100644 index 0000000000..67486d4c23 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_picolipo_16mb/board.c @@ -0,0 +1,37 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Scott Shawcroft for Adafruit Industries + * + * 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 "supervisor/board.h" + +void board_init(void) { +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} diff --git a/ports/raspberrypi/boards/pimoroni_picolipo_16mb/mpconfigboard.h b/ports/raspberrypi/boards/pimoroni_picolipo_16mb/mpconfigboard.h new file mode 100644 index 0000000000..4261b9e006 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_picolipo_16mb/mpconfigboard.h @@ -0,0 +1,10 @@ +#define MICROPY_HW_BOARD_NAME "Pimoroni Pico LiPo (16MB)" +#define MICROPY_HW_MCU_NAME "rp2040" + +#define MICROPY_HW_VBUS_DETECT (&pin_GPIO24) +#define MICROPY_HW_BAT_SENSE (&pin_GPIO29) + +#define MICROPY_HW_USER_SW (&pin_GPIO23) + +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO5) +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO4) diff --git a/ports/raspberrypi/boards/pimoroni_picolipo_16mb/mpconfigboard.mk b/ports/raspberrypi/boards/pimoroni_picolipo_16mb/mpconfigboard.mk new file mode 100644 index 0000000000..129f408e5e --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_picolipo_16mb/mpconfigboard.mk @@ -0,0 +1,11 @@ +USB_VID = 0x2E8A +USB_PID = 0x1003 +USB_PRODUCT = "Pimoroni Pico LiPo (16MB)" +USB_MANUFACTURER = "Pimoroni" + +CHIP_VARIANT = RP2040 +CHIP_FAMILY = rp2 + +EXTERNAL_FLASH_DEVICES = "W25Q128JVxQ" + +CIRCUITPY__EVE = 1 diff --git a/ports/raspberrypi/boards/pimoroni_picolipo_16mb/pins.c b/ports/raspberrypi/boards/pimoroni_picolipo_16mb/pins.c new file mode 100644 index 0000000000..229d510ead --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_picolipo_16mb/pins.c @@ -0,0 +1,52 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_GP1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_GP2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_GP3), MP_ROM_PTR(&pin_GPIO3) }, + + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_GP4), MP_ROM_PTR(&pin_GPIO4) }, + + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_GP5), MP_ROM_PTR(&pin_GPIO5) }, + + { MP_ROM_QSTR(MP_QSTR_GP6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_GP7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_GP8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_GP9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_GP10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_GP11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_GP12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_GP13), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_GP14), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_GP15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_GP16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_GP17), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_GP18), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_GP19), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_GP20), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_GP21), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_GP22), MP_ROM_PTR(&pin_GPIO22) }, + + { MP_ROM_QSTR(MP_QSTR_USER_SW), MP_ROM_PTR(&pin_GPIO23) }, + { MP_ROM_QSTR(MP_QSTR_VBUS_DETECT), MP_ROM_PTR(&pin_GPIO24) }, + + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO25) }, + { MP_ROM_QSTR(MP_QSTR_GP25), MP_ROM_PTR(&pin_GPIO25) }, + { MP_ROM_QSTR(MP_QSTR_GP26_A0), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_GP26), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_GP27_A1), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_GP27), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_GP28_A2), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_GP28), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) }, + { MP_ROM_QSTR(MP_QSTR_BAT_SENSE), MP_ROM_PTR(&pin_GPIO29) }, + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/raspberrypi/boards/pimoroni_picolipo_4mb/board.c b/ports/raspberrypi/boards/pimoroni_picolipo_4mb/board.c new file mode 100644 index 0000000000..67486d4c23 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_picolipo_4mb/board.c @@ -0,0 +1,37 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Scott Shawcroft for Adafruit Industries + * + * 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 "supervisor/board.h" + +void board_init(void) { +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} diff --git a/ports/raspberrypi/boards/pimoroni_picolipo_4mb/mpconfigboard.h b/ports/raspberrypi/boards/pimoroni_picolipo_4mb/mpconfigboard.h new file mode 100644 index 0000000000..e34a05abf2 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_picolipo_4mb/mpconfigboard.h @@ -0,0 +1,10 @@ +#define MICROPY_HW_BOARD_NAME "Pimoroni Pico LiPo (4MB)" +#define MICROPY_HW_MCU_NAME "rp2040" + +#define MICROPY_HW_VBUS_DETECT (&pin_GPIO24) +#define MICROPY_HW_BAT_SENSE (&pin_GPIO29) + +#define MICROPY_HW_USER_SW (&pin_GPIO23) + +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO5) +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO4) diff --git a/ports/raspberrypi/boards/pimoroni_picolipo_4mb/mpconfigboard.mk b/ports/raspberrypi/boards/pimoroni_picolipo_4mb/mpconfigboard.mk new file mode 100644 index 0000000000..a82ee9c0ea --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_picolipo_4mb/mpconfigboard.mk @@ -0,0 +1,11 @@ +USB_VID = 0x2E8A +USB_PID = 0x1002 +USB_PRODUCT = "Pimoroni Pico LiPo (4MB)" +USB_MANUFACTURER = "Pimoroni" + +CHIP_VARIANT = RP2040 +CHIP_FAMILY = rp2 + +EXTERNAL_FLASH_DEVICES = "W25Q32JVxQ" + +CIRCUITPY__EVE = 1 diff --git a/ports/raspberrypi/boards/pimoroni_picolipo_4mb/pins.c b/ports/raspberrypi/boards/pimoroni_picolipo_4mb/pins.c new file mode 100644 index 0000000000..229d510ead --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_picolipo_4mb/pins.c @@ -0,0 +1,52 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_GP1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_GP2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_GP3), MP_ROM_PTR(&pin_GPIO3) }, + + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_GP4), MP_ROM_PTR(&pin_GPIO4) }, + + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_GP5), MP_ROM_PTR(&pin_GPIO5) }, + + { MP_ROM_QSTR(MP_QSTR_GP6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_GP7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_GP8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_GP9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_GP10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_GP11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_GP12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_GP13), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_GP14), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_GP15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_GP16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_GP17), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_GP18), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_GP19), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_GP20), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_GP21), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_GP22), MP_ROM_PTR(&pin_GPIO22) }, + + { MP_ROM_QSTR(MP_QSTR_USER_SW), MP_ROM_PTR(&pin_GPIO23) }, + { MP_ROM_QSTR(MP_QSTR_VBUS_DETECT), MP_ROM_PTR(&pin_GPIO24) }, + + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO25) }, + { MP_ROM_QSTR(MP_QSTR_GP25), MP_ROM_PTR(&pin_GPIO25) }, + { MP_ROM_QSTR(MP_QSTR_GP26_A0), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_GP26), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_GP27_A1), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_GP27), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_GP28_A2), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_GP28), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) }, + { MP_ROM_QSTR(MP_QSTR_BAT_SENSE), MP_ROM_PTR(&pin_GPIO29) }, + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/raspberrypi/boards/raspberry_pi_pico/pins.c b/ports/raspberrypi/boards/raspberry_pi_pico/pins.c index e1927bc80c..057eaec2af 100644 --- a/ports/raspberrypi/boards/raspberry_pi_pico/pins.c +++ b/ports/raspberrypi/boards/raspberry_pi_pico/pins.c @@ -24,18 +24,28 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_GP20), MP_ROM_PTR(&pin_GPIO20) }, { MP_ROM_QSTR(MP_QSTR_GP21), MP_ROM_PTR(&pin_GPIO21) }, { MP_ROM_QSTR(MP_QSTR_GP22), MP_ROM_PTR(&pin_GPIO22) }, + { MP_ROM_QSTR(MP_QSTR_SMPS_MODE), MP_ROM_PTR(&pin_GPIO23) }, + { MP_ROM_QSTR(MP_QSTR_GP23), MP_ROM_PTR(&pin_GPIO23) }, + + { MP_ROM_QSTR(MP_QSTR_VBUS_SENSE), MP_ROM_PTR(&pin_GPIO24) }, + { MP_ROM_QSTR(MP_QSTR_GP24), MP_ROM_PTR(&pin_GPIO24) }, + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO25) }, { MP_ROM_QSTR(MP_QSTR_GP25), MP_ROM_PTR(&pin_GPIO25) }, + { MP_ROM_QSTR(MP_QSTR_GP26_A0), MP_ROM_PTR(&pin_GPIO26) }, { MP_ROM_QSTR(MP_QSTR_GP26), MP_ROM_PTR(&pin_GPIO26) }, { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_GP27_A1), MP_ROM_PTR(&pin_GPIO27) }, { MP_ROM_QSTR(MP_QSTR_GP27), MP_ROM_PTR(&pin_GPIO27) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_GP28_A2), MP_ROM_PTR(&pin_GPIO28) }, { MP_ROM_QSTR(MP_QSTR_GP28), MP_ROM_PTR(&pin_GPIO28) }, { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) }, { MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_GPIO29) }, }; diff --git a/ports/raspberrypi/boards/sparkfun_micromod_rp2040/board.c b/ports/raspberrypi/boards/sparkfun_micromod_rp2040/board.c new file mode 100644 index 0000000000..c4021a83e9 --- /dev/null +++ b/ports/raspberrypi/boards/sparkfun_micromod_rp2040/board.c @@ -0,0 +1,40 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Scott Shawcroft for Adafruit Industries + * + * 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 "supervisor/board.h" + +#include "shared-bindings/microcontroller/Pin.h" +#include "src/rp2_common/hardware_gpio/include/hardware/gpio.h" + +void board_init(void) { +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { +} diff --git a/ports/raspberrypi/boards/sparkfun_micromod_rp2040/mpconfigboard.h b/ports/raspberrypi/boards/sparkfun_micromod_rp2040/mpconfigboard.h new file mode 100644 index 0000000000..d7dd7a6376 --- /dev/null +++ b/ports/raspberrypi/boards/sparkfun_micromod_rp2040/mpconfigboard.h @@ -0,0 +1,12 @@ +#define MICROPY_HW_BOARD_NAME "SparkFun MicroMod ATP - RP2040" +#define MICROPY_HW_MCU_NAME "rp2040" + +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO5) +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO4) + +#define DEFAULT_SPI_BUS_SCK (&pin_GPIO14) +#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO15) +#define DEFAULT_SPI_BUS_MISO (&pin_GPIO12) + +#define DEFAULT_UART_BUS_RX (&pin_GPIO1) +#define DEFAULT_UART_BUS_TX (&pin_GPIO0) diff --git a/ports/raspberrypi/boards/sparkfun_micromod_rp2040/mpconfigboard.mk b/ports/raspberrypi/boards/sparkfun_micromod_rp2040/mpconfigboard.mk new file mode 100644 index 0000000000..2ed559d8db --- /dev/null +++ b/ports/raspberrypi/boards/sparkfun_micromod_rp2040/mpconfigboard.mk @@ -0,0 +1,9 @@ +USB_VID = 0x1B4F +USB_PID = 0x0024 +USB_PRODUCT = "MicroMod RP2040" +USB_MANUFACTURER = "SparkFun" + +CHIP_VARIANT = RP2040 +CHIP_FAMILY = rp2 + +EXTERNAL_FLASH_DEVICES = "W25Q128JVxM" diff --git a/ports/raspberrypi/boards/sparkfun_micromod_rp2040/pins.c b/ports/raspberrypi/boards/sparkfun_micromod_rp2040/pins.c new file mode 100644 index 0000000000..00d6c30cb8 --- /dev/null +++ b/ports/raspberrypi/boards/sparkfun_micromod_rp2040/pins.c @@ -0,0 +1,105 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_global_dict_table[] = { + // D (Digital only) pins (D0,D1) + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO7) }, // GPIO6 - D0 + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO7) }, // GPIO7 - D1 + + // A (ADC) pins (A0,A1) + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) }, // GPIO26 - A0 | ADC0 + { MP_ROM_QSTR(MP_QSTR_ADC0), MP_ROM_PTR(&pin_GPIO26) }, // ADC0 alias + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, // GPIO27 - A1 | ADC1 + { MP_ROM_QSTR(MP_QSTR_ADC1), MP_ROM_PTR(&pin_GPIO27) }, // ADC1 alias + + // G (General/BUS) pins (G0-G7, G8 NC, G9-G10, G11 NC) + { MP_ROM_QSTR(MP_QSTR_G0), MP_ROM_PTR(&pin_GPIO16) }, // GPIO16 - G0 | BUS0 + { MP_ROM_QSTR(MP_QSTR_BUS0), MP_ROM_PTR(&pin_GPIO16) }, // BUS0 alias + { MP_ROM_QSTR(MP_QSTR_G1), MP_ROM_PTR(&pin_GPIO17) }, // GPIO17 - G1 | BUS1 + { MP_ROM_QSTR(MP_QSTR_BUS1), MP_ROM_PTR(&pin_GPIO17) }, // BUS1 alias + { MP_ROM_QSTR(MP_QSTR_G2), MP_ROM_PTR(&pin_GPIO18) }, // GPIO18 - G2 | BUS2 + { MP_ROM_QSTR(MP_QSTR_BUS2), MP_ROM_PTR(&pin_GPIO18) }, // BUS2 alias + { MP_ROM_QSTR(MP_QSTR_G3), MP_ROM_PTR(&pin_GPIO19) }, // GPIO19 - G3 | BUS3 + { MP_ROM_QSTR(MP_QSTR_BUS3), MP_ROM_PTR(&pin_GPIO19) }, // BUS3 alias + { MP_ROM_QSTR(MP_QSTR_G4), MP_ROM_PTR(&pin_GPIO20) }, // GPIO20 - G4 | BUS4 | SPI_CIPO + { MP_ROM_QSTR(MP_QSTR_BUS4), MP_ROM_PTR(&pin_GPIO20) }, // BUS4 alias + { MP_ROM_QSTR(MP_QSTR_G5), MP_ROM_PTR(&pin_GPIO21) }, // GPIO21 - G5 | BUS5 | SPI_CS + { MP_ROM_QSTR(MP_QSTR_BUS5), MP_ROM_PTR(&pin_GPIO21) }, // BUS5 alias + { MP_ROM_QSTR(MP_QSTR_G6), MP_ROM_PTR(&pin_GPIO22) }, // GPIO22 - G6 | BUS6 | SPI_SCK + { MP_ROM_QSTR(MP_QSTR_BUS6), MP_ROM_PTR(&pin_GPIO22) }, // BUS6 alias + { MP_ROM_QSTR(MP_QSTR_G7), MP_ROM_PTR(&pin_GPIO23) }, // GPIO23 - G7 | BUS7 | SPI_COPI + { MP_ROM_QSTR(MP_QSTR_BUS7), MP_ROM_PTR(&pin_GPIO23) }, // BUS7 alias + // NC - G8 + { MP_ROM_QSTR(MP_QSTR_G9), MP_ROM_PTR(&pin_GPIO28) }, // GPIO28- G9 | BUS9 | ADC_D- | CAM_HSYNC + { MP_ROM_QSTR(MP_QSTR_BUS9), MP_ROM_PTR(&pin_GPIO28) }, // BUS9 alias + { MP_ROM_QSTR(MP_QSTR_ADC_DM), MP_ROM_PTR(&pin_GPIO28) }, // ADC_DM alias + { MP_ROM_QSTR(MP_QSTR_CAM_HSYNC), MP_ROM_PTR(&pin_GPIO28) }, // CAM_HSYNC alias + { MP_ROM_QSTR(MP_QSTR_G10), MP_ROM_PTR(&pin_GPIO25) }, // GPIO25 - G10 | BUS10 | ADC_D+ | CAM_VSYNC + { MP_ROM_QSTR(MP_QSTR_BUS10), MP_ROM_PTR(&pin_GPIO25) }, // BUS10 alias + { MP_ROM_QSTR(MP_QSTR_ADC_DP), MP_ROM_PTR(&pin_GPIO25) }, // ADC_DP alias + { MP_ROM_QSTR(MP_QSTR_CAM_VSYNC), MP_ROM_PTR(&pin_GPIO25) }, // CAM_VSYNC alias + // NC - G11 + + // PWM pins (PWM0,PWM1) + { MP_ROM_QSTR(MP_QSTR_PWM0), MP_ROM_PTR(&pin_GPIO13) }, // GPIO13 - PWM0 + { MP_ROM_QSTR(MP_QSTR_PWM1), MP_ROM_PTR(&pin_GPIO24) }, // GPIO24 - PWM1 | AUD_MCLK + + // AUD (audio) + { MP_ROM_QSTR(MP_QSTR_AUD_MCLK), MP_ROM_PTR(&pin_GPIO24) }, // GPIO24 - AUD_MCLK | PWM1 + { MP_ROM_QSTR(MP_QSTR_AUD_OUT), MP_ROM_PTR(&pin_GPIO10) }, // GPIO10 - AUD_OUT | SDIO_DAT2 + { MP_ROM_QSTR(MP_QSTR_AUD_IN), MP_ROM_PTR(&pin_GPIO11) }, // GPIO11 - AUD_IN | SDIO_DAT1 + { MP_ROM_QSTR(MP_QSTR_AUD_LRCLK), MP_ROM_PTR(&pin_GPIO2) }, // GPIO2 - AUD_LRCLK | CTS1 + { MP_ROM_QSTR(MP_QSTR_AUD_BCLK), MP_ROM_PTR(&pin_GPIO3) }, // GPIO3 - AUD_BCLK | UART_RTS1 + + // Battery Voltage Monitor + { MP_ROM_QSTR(MP_QSTR_BATT_VIN3), MP_ROM_PTR(&pin_GPIO29) }, // GPIO29 - BATT_VIN/3 (ADC03) + + + // I2C + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO4) }, // GPIO4 - SDA + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO5) }, // GPIO5 - SCL + + { MP_ROM_QSTR(MP_QSTR_I2C_INT), MP_ROM_PTR(&pin_GPIO8) }, // GPIO9 - I2C_INT | TX2 + + // SPI + { MP_ROM_QSTR(MP_QSTR_CIPO), MP_ROM_PTR(&pin_GPIO20) }, // GPIO20 - CIPO | SPI_CIPO | G4 + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO20) }, // MISO alias + { MP_ROM_QSTR(MP_QSTR_COPI), MP_ROM_PTR(&pin_GPIO23) }, // GPIO23 - COPI | SPI_COPI | G7 + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO23) }, // MOSI alias + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO22) }, // GPIO22 - SCK | SPI_SCK | G6 + { MP_ROM_QSTR(MP_QSTR_CS), MP_ROM_PTR(&pin_GPIO21) }, // GPIO21 - /CS | SPI_/CS | G5 + + // SDI/SPI1 + { MP_ROM_QSTR(MP_QSTR_SDIO_CLK), MP_ROM_PTR(&pin_GPIO14) }, // GPIO14 - SDIO SCK | SDIO_CLK + { MP_ROM_QSTR(MP_QSTR_SPI_SCK1), MP_ROM_PTR(&pin_GPIO14) }, // SPI_SCK1 alias + { MP_ROM_QSTR(MP_QSTR_SDIO_CMD), MP_ROM_PTR(&pin_GPIO15) }, // GPIO15 - SDIO CMD | SDIO_CMD + { MP_ROM_QSTR(MP_QSTR_SPI_COPI1), MP_ROM_PTR(&pin_GPIO15) },// SPI_COPI1 alias + { MP_ROM_QSTR(MP_QSTR_SDIO_DATA0), MP_ROM_PTR(&pin_GPIO12) },// GPIO12 - SDIO DATA0 | SDIO_DATA0 + { MP_ROM_QSTR(MP_QSTR_SPI_CIPO1), MP_ROM_PTR(&pin_GPIO12) }, // SPI_CIPO1 alias + { MP_ROM_QSTR(MP_QSTR_SDIO_DATA1), MP_ROM_PTR(&pin_GPIO11) },// GPIO11 - SDIO DATA1 | SDIO_DATA1 | AUD_IN + { MP_ROM_QSTR(MP_QSTR_SDIO_DATA2), MP_ROM_PTR(&pin_GPIO10) },// GPIO10 - SDIO DATA2 | SDIO_DATA2 | AUD_OUT + { MP_ROM_QSTR(MP_QSTR_SDIO_DATA3), MP_ROM_PTR(&pin_GPIO9) },// GPIO9 - SDIO DATA3 | SDIO_DATA3 | SPI_CS1 + { MP_ROM_QSTR(MP_QSTR_SPI_CS1), MP_ROM_PTR(&pin_GPIO9) }, // SPI_CS1 alias + + // Status LED + { MP_ROM_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_GPIO25) }, // GPIO25 - LED_BUILTIN | STAT | Blue LED | G10 + + // UART + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO1) }, // GPIO1 - UART RX | UART_RX1 | RX1 + { MP_ROM_QSTR(MP_QSTR_RX1), MP_ROM_PTR(&pin_GPIO1) }, // RX1 alias + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO0) }, // GPIO0 - UART TX | UART_TX1 | TX1 + { MP_ROM_QSTR(MP_QSTR_TX1), MP_ROM_PTR(&pin_GPIO0) }, // TX1 alias + { MP_ROM_QSTR(MP_QSTR_CTS), MP_ROM_PTR(&pin_GPIO2) }, // GPIO2 - UART CTS | CTS1 (TRACEDATA3) + { MP_ROM_QSTR(MP_QSTR_CTS1), MP_ROM_PTR(&pin_GPIO2) }, // CTS1 alias + { MP_ROM_QSTR(MP_QSTR_RTS), MP_ROM_PTR(&pin_GPIO3) }, // GPIO3 - UART RTS | RTS1 + { MP_ROM_QSTR(MP_QSTR_RTS1), MP_ROM_PTR(&pin_GPIO3) }, // RTS1 alias + + { MP_ROM_QSTR(MP_QSTR_RX2), MP_ROM_PTR(&pin_GPIO9) }, // GPIO9 - UART RX | UART_RX2 | RX2 | SDIO_DAT3 | SPI_CS1 + { MP_ROM_QSTR(MP_QSTR_TX2), MP_ROM_PTR(&pin_GPIO8) }, // GPIO8 - UART TX | UART_TX2 | TX2 | I2C_INT + + // Board objects + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, + +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/raspberrypi/mpconfigport.mk b/ports/raspberrypi/mpconfigport.mk index cece99afa9..635f1a75e7 100644 --- a/ports/raspberrypi/mpconfigport.mk +++ b/ports/raspberrypi/mpconfigport.mk @@ -43,8 +43,7 @@ CIRCUITPY_AUDIOBUSIO ?= 1 CIRCUITPY_AUDIOCORE ?= 1 CIRCUITPY_AUDIOPWMIO ?= 1 -# These libraries require Cortex M4+ for fancy math instructions. -CIRCUITPY_AUDIOMIXER ?= 0 +CIRCUITPY_AUDIOMIXER = 1 INTERNAL_LIBM = 1 diff --git a/ports/stm/boards/stm32f411ce_blackpill_with_flash/mpconfigboard.mk b/ports/stm/boards/stm32f411ce_blackpill_with_flash/mpconfigboard.mk index 76acd7ed1e..211a658967 100644 --- a/ports/stm/boards/stm32f411ce_blackpill_with_flash/mpconfigboard.mk +++ b/ports/stm/boards/stm32f411ce_blackpill_with_flash/mpconfigboard.mk @@ -16,3 +16,5 @@ MCU_PACKAGE = UFQFPN48 LD_COMMON = boards/common_default.ld LD_FILE = boards/STM32F411_nvm_nofs.ld + +CIRCUITPY_SYNTHIO = 0 diff --git a/py/binary.c b/py/binary.c index 846058525f..cd61d74fa8 100644 --- a/py/binary.c +++ b/py/binary.c @@ -371,11 +371,7 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte ** } } - if (val_type == 'x') { - memset(p, 0, 1); - } else { - mp_binary_set_int(MIN((size_t)size, sizeof(val)), struct_type == '>', p, val); - } + mp_binary_set_int(MIN((size_t)size, sizeof(val)), struct_type == '>', p, val); } void mp_binary_set_val_array(char typecode, void *p, mp_uint_t index, mp_obj_t val_in) { diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 0eedfe5249..5745c4f1d2 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -280,6 +280,9 @@ endif ifeq ($(CIRCUITPY_SUPERVISOR),1) SRC_PATTERNS += supervisor/% endif +ifeq ($(CIRCUITPY_SYNTHIO),1) +SRC_PATTERNS += synthio/% +endif ifeq ($(CIRCUITPY_TERMINALIO),1) SRC_PATTERNS += terminalio/% fontio/% endif @@ -524,6 +527,8 @@ SRC_SHARED_MODULE_ALL = \ socket/__init__.c \ storage/__init__.c \ struct/__init__.c \ + synthio/MidiTrack.c \ + synthio/__init__.c \ terminalio/Terminal.c \ terminalio/__init__.c \ time/__init__.c \ diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index eedda7ad73..801e1867e7 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -728,6 +728,13 @@ extern const struct _mp_obj_module_t supervisor_module; #define SUPERVISOR_MODULE #endif +#if CIRCUITPY_SYNTHIO +#define SYNTHIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_synthio), (mp_obj_t)&synthio_module }, +extern const struct _mp_obj_module_t synthio_module; +#else +#define SYNTHIO_MODULE +#endif + #if CIRCUITPY_TIME extern const struct _mp_obj_module_t time_module; #define TIME_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module }, @@ -897,6 +904,7 @@ extern const struct _mp_obj_module_t msgpack_module; STORAGE_MODULE \ STRUCT_MODULE \ SUPERVISOR_MODULE \ + SYNTHIO_MODULE \ TOUCHIO_MODULE \ UHEAP_MODULE \ USB_CDC_MODULE \ diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 51b590dcf3..600e56ee23 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -311,6 +311,9 @@ CFLAGS += -DCIRCUITPY_STRUCT=$(CIRCUITPY_STRUCT) CIRCUITPY_SUPERVISOR ?= 1 CFLAGS += -DCIRCUITPY_SUPERVISOR=$(CIRCUITPY_SUPERVISOR) +CIRCUITPY_SYNTHIO ?= $(CIRCUITPY_AUDIOCORE) +CFLAGS += -DCIRCUITPY_SYNTHIO=$(CIRCUITPY_SYNTHIO) + CIRCUITPY_TERMINALIO ?= $(CIRCUITPY_DISPLAYIO) CFLAGS += -DCIRCUITPY_TERMINALIO=$(CIRCUITPY_TERMINALIO) diff --git a/py/compile.c b/py/compile.c index 4a9fdc7db8..7971690d6d 100644 --- a/py/compile.c +++ b/py/compile.c @@ -768,7 +768,7 @@ STATIC bool compile_built_in_decorator(compiler_t *comp, int name_len, mp_parse_ } if (name_len != 2) { - compile_syntax_error(comp, name_nodes[0], translate("invalid micropython decorator")); + compile_syntax_error(comp, name_nodes[0], translate("invalid decorator")); return true; } diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py index 0ad749005c..6a6125fe20 100644 --- a/py/makeqstrdata.py +++ b/py/makeqstrdata.py @@ -12,7 +12,6 @@ from __future__ import print_function import re import sys -from math import log import collections import gettext import os.path @@ -167,7 +166,7 @@ def compute_huffman_coding(translations, compression_filename): sum_len = 0 while True: # Until the dictionary is filled to capacity, use a heuristic to find - # the best "word" (2- to 9-gram) to add to it. + # the best "word" (3- to 9-gram) to add to it. # # The TextSplitter allows us to avoid considering parts of the text # that are already covered by a previously chosen word, for example @@ -179,32 +178,25 @@ def compute_huffman_coding(translations, compression_filename): for t in texts: for (found, word) in extractor.iter_words(t): if not found: - for substr in iter_substrings(word, minlen=2, maxlen=9): + for substr in iter_substrings(word, minlen=3, maxlen=9): counter[substr] += 1 # Score the candidates we found. This is an empirical formula only, # chosen for its effectiveness. scores = sorted( - ((s, (len(s) - 1) ** log(max(occ - 2, 1)), occ) for (s, occ) in counter.items()), + ((s, (len(s) - 1) ** (occ + 4)) for (s, occ) in counter.items() if occ > 4), key=lambda x: x[1], reverse=True, ) - # Do we have a "word" that occurred 5 times and got a score of at least - # 5? Horray. Pick the one with the highest score. - word = None - for (s, score, occ) in scores: - if occ < 5: - continue - if score < 5: - break - word = s + # Pick the one with the highest score. + if not scores: break + word = scores[0][0] + # If we can successfully add it to the dictionary, do so. Otherwise, # we've filled the dictionary to capacity and are done. - if not word: - break if sum_len + len(word) - 2 > max_words_len: break if len(words) == max_words: @@ -456,27 +448,24 @@ def parse_input_headers(infiles): return qcfgs, qstrs, i18ns +def escape_bytes(qstr): + if all(32 <= ord(c) <= 126 and c != "\\" and c != '"' for c in qstr): + # qstr is all printable ASCII so render it as-is (for easier debugging) + return qstr + else: + # qstr contains non-printable codes so render entire thing as hex pairs + qbytes = bytes_cons(qstr, "utf8") + return "".join(("\\x%02x" % b) for b in qbytes) def make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr): qbytes = bytes_cons(qstr, "utf8") qlen = len(qbytes) qhash = compute_hash(qbytes, cfg_bytes_hash) - if all(32 <= ord(c) <= 126 and c != "\\" and c != '"' for c in qstr): - # qstr is all printable ASCII so render it as-is (for easier debugging) - qdata = qstr - else: - # qstr contains non-printable codes so render entire thing as hex pairs - qdata = "".join(("\\x%02x" % b) for b in qbytes) if qlen >= (1 << (8 * cfg_bytes_len)): print("qstr is too long:", qstr) assert False - qlen_str = ("\\x%02x" * cfg_bytes_len) % tuple( - ((qlen >> (8 * i)) & 0xFF) for i in range(cfg_bytes_len) - ) - qhash_str = ("\\x%02x" * cfg_bytes_hash) % tuple( - ((qhash >> (8 * i)) & 0xFF) for i in range(cfg_bytes_hash) - ) - return '(const byte*)"%s%s" "%s"' % (qhash_str, qlen_str, qdata) + qdata = escape_bytes(qstr) + return '%d, %d, "%s"' % (qhash, qlen, qdata) def print_qstr_data(encoding_table, qcfgs, qstrs, i18ns): @@ -489,10 +478,7 @@ def print_qstr_data(encoding_table, qcfgs, qstrs, i18ns): print("") # add NULL qstr with no hash or data - print( - 'QDEF(MP_QSTR_NULL, (const byte*)"%s%s" "")' - % ("\\x00" * cfg_bytes_hash, "\\x00" * cfg_bytes_len) - ) + print('QDEF(MP_QSTR_NULL, 0, 0, "")') total_qstr_size = 0 total_qstr_compressed_size = 0 diff --git a/py/modstruct.c b/py/modstruct.c index 1c5319608d..8f78fa234a 100644 --- a/py/modstruct.c +++ b/py/modstruct.c @@ -214,9 +214,11 @@ STATIC void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, size_t n_args, c p += cnt; } else { while (cnt--) { - mp_binary_set_val(fmt_type, *fmt, args[i], &p); // Pad bytes don't have a corresponding argument. - if (*fmt != 'x') { + if (*fmt == 'x') { + mp_binary_set_val(fmt_type, *fmt, MP_OBJ_NEW_SMALL_INT(0), &p); + } else { + mp_binary_set_val(fmt_type, *fmt, args[i], &p); i++; } } diff --git a/py/mpstate.h b/py/mpstate.h index 139f23cb4f..1f6a2d00a1 100644 --- a/py/mpstate.h +++ b/py/mpstate.h @@ -197,7 +197,7 @@ typedef struct _mp_state_vm_t { // pointer and sizes to store interned string data // (qstr_last_chunk can be root pointer but is also stored in qstr pool) - byte *qstr_last_chunk; + char *qstr_last_chunk; size_t qstr_last_alloc; size_t qstr_last_used; diff --git a/py/qstr.c b/py/qstr.c index 2ae65379c7..af5ea58686 100644 --- a/py/qstr.c +++ b/py/qstr.c @@ -37,7 +37,6 @@ // NOTE: we are using linear arrays to store and search for qstr's (unique strings, interned strings) // ultimately we will replace this with a static hash table of some kind -// also probably need to include the length in the string data, to allow null bytes in the string #if MICROPY_DEBUG_VERBOSE // print debugging info #define DEBUG_printf DEBUG_printf @@ -46,34 +45,9 @@ #endif // A qstr is an index into the qstr pool. -// The data for a qstr contains (hash, length, data): -// - hash (configurable number of bytes) -// - length (configurable number of bytes) -// - data ("length" number of bytes) -// - \0 terminated (so they can be printed using printf) +// The data for a qstr is \0 terminated (so they can be printed using printf) -#if MICROPY_QSTR_BYTES_IN_HASH == 1 - #define Q_HASH_MASK (0xff) - #define Q_GET_HASH(q) ((mp_uint_t)(q)[0]) - #define Q_SET_HASH(q, hash) do { (q)[0] = (hash); } while (0) -#elif MICROPY_QSTR_BYTES_IN_HASH == 2 - #define Q_HASH_MASK (0xffff) - #define Q_GET_HASH(q) ((mp_uint_t)(q)[0] | ((mp_uint_t)(q)[1] << 8)) - #define Q_SET_HASH(q, hash) do { (q)[0] = (hash); (q)[1] = (hash) >> 8; } while (0) -#else - #error unimplemented qstr hash decoding -#endif -#define Q_GET_ALLOC(q) (MICROPY_QSTR_BYTES_IN_HASH + MICROPY_QSTR_BYTES_IN_LEN + Q_GET_LENGTH(q) + 1) -#define Q_GET_DATA(q) ((q) + MICROPY_QSTR_BYTES_IN_HASH + MICROPY_QSTR_BYTES_IN_LEN) -#if MICROPY_QSTR_BYTES_IN_LEN == 1 - #define Q_GET_LENGTH(q) ((q)[MICROPY_QSTR_BYTES_IN_HASH]) - #define Q_SET_LENGTH(q, len) do { (q)[MICROPY_QSTR_BYTES_IN_HASH] = (len); } while (0) -#elif MICROPY_QSTR_BYTES_IN_LEN == 2 - #define Q_GET_LENGTH(q) ((q)[MICROPY_QSTR_BYTES_IN_HASH] | ((q)[MICROPY_QSTR_BYTES_IN_HASH + 1] << 8)) - #define Q_SET_LENGTH(q, len) do { (q)[MICROPY_QSTR_BYTES_IN_HASH] = (len); (q)[MICROPY_QSTR_BYTES_IN_HASH + 1] = (len) >> 8; } while (0) -#else - #error unimplemented qstr length decoding -#endif +#define Q_HASH_MASK ((1 << (8 * MICROPY_QSTR_BYTES_IN_HASH)) - 1) #if MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL #define QSTR_ENTER() mp_thread_mutex_lock(&MP_STATE_VM(qstr_mutex), 1) @@ -98,14 +72,25 @@ mp_uint_t qstr_compute_hash(const byte *data, size_t len) { return hash; } +const qstr_attr_t mp_qstr_const_attr[] = { + #ifndef NO_QSTR +#define QDEF(id, hash, len, str) { hash, len }, +#define TRANSLATION(id, length, compressed ...) + #include "genhdr/qstrdefs.generated.h" +#undef TRANSLATION +#undef QDEF + #endif +}; + const qstr_pool_t mp_qstr_const_pool = { NULL, // no previous pool 0, // no previous pool 10, // set so that the first dynamically allocated pool is twice this size; must be <= the len (just below) MP_QSTRnumber_of, // corresponds to number of strings in array just below + (qstr_attr_t *)mp_qstr_const_attr, { #ifndef NO_QSTR -#define QDEF(id, str) str, +#define QDEF(id, hash, len, str) str, #define TRANSLATION(id, length, compressed ...) #include "genhdr/qstrdefs.generated.h" #undef TRANSLATION @@ -130,20 +115,22 @@ void qstr_init(void) { #endif } -STATIC const byte *find_qstr(qstr q) { +STATIC const char *find_qstr(qstr q, qstr_attr_t *attr) { // search pool for this qstr // total_prev_len==0 in the final pool, so the loop will always terminate qstr_pool_t *pool = MP_STATE_VM(last_pool); while (q < pool->total_prev_len) { pool = pool->prev; } - assert(q - pool->total_prev_len < pool->len); - return pool->qstrs[q - pool->total_prev_len]; + q -= pool->total_prev_len; + assert(q < pool->len); + *attr = pool->attrs[q]; + return pool->qstrs[q]; } // qstr_mutex must be taken while in this function -STATIC qstr qstr_add(const byte *q_ptr) { - DEBUG_printf("QSTR: add hash=%d len=%d data=%.*s\n", Q_GET_HASH(q_ptr), Q_GET_LENGTH(q_ptr), Q_GET_LENGTH(q_ptr), Q_GET_DATA(q_ptr)); +STATIC qstr qstr_add(mp_uint_t hash, mp_uint_t len, const char *q_ptr) { + DEBUG_printf("QSTR: add hash=%d len=%d data=%.*s\n", hash, len, len, q_ptr); // make sure we have room in the pool for a new qstr if (MP_STATE_VM(last_pool)->len >= MP_STATE_VM(last_pool)->alloc) { @@ -151,11 +138,14 @@ STATIC qstr qstr_add(const byte *q_ptr) { if (new_pool_length > MICROPY_QSTR_POOL_MAX_ENTRIES) { new_pool_length = MICROPY_QSTR_POOL_MAX_ENTRIES; } - qstr_pool_t *pool = m_new_ll_obj_var_maybe(qstr_pool_t, const char *, new_pool_length); - if (pool == NULL) { + mp_uint_t pool_size = sizeof(qstr_pool_t) + sizeof(const char *) * new_pool_length; + void *chunk = m_malloc_maybe(pool_size + sizeof(qstr_attr_t) * new_pool_length, true); + if (chunk == NULL) { QSTR_EXIT(); m_malloc_fail(new_pool_length); } + qstr_pool_t *pool = (qstr_pool_t *)chunk; + pool->attrs = (qstr_attr_t *)(void *)((char *)chunk + pool_size); pool->prev = MP_STATE_VM(last_pool); pool->total_prev_len = MP_STATE_VM(last_pool)->total_prev_len + MP_STATE_VM(last_pool)->len; pool->alloc = new_pool_length; @@ -165,10 +155,14 @@ STATIC qstr qstr_add(const byte *q_ptr) { } // add the new qstr - MP_STATE_VM(last_pool)->qstrs[MP_STATE_VM(last_pool)->len++] = q_ptr; + mp_uint_t at = MP_STATE_VM(last_pool)->len; + MP_STATE_VM(last_pool)->attrs[at].hash = hash; + MP_STATE_VM(last_pool)->attrs[at].len = len; + MP_STATE_VM(last_pool)->qstrs[at] = q_ptr; + MP_STATE_VM(last_pool)->len++; // return id for the newly-added qstr - return MP_STATE_VM(last_pool)->total_prev_len + MP_STATE_VM(last_pool)->len - 1; + return MP_STATE_VM(last_pool)->total_prev_len + at; } qstr qstr_find_strn(const char *str, size_t str_len) { @@ -177,9 +171,10 @@ qstr qstr_find_strn(const char *str, size_t str_len) { // search pools for the data for (qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL; pool = pool->prev) { - for (const byte **q = pool->qstrs, **q_top = pool->qstrs + pool->len; q < q_top; q++) { - if (Q_GET_HASH(*q) == str_hash && Q_GET_LENGTH(*q) == str_len && memcmp(Q_GET_DATA(*q), str, str_len) == 0) { - return pool->total_prev_len + (q - pool->qstrs); + qstr_attr_t *attrs = pool->attrs; + for (mp_uint_t at = 0, top = pool->len; at < top; at++) { + if (attrs[at].hash == str_hash && attrs[at].len == str_len && memcmp(pool->qstrs[at], str, str_len) == 0) { + return pool->total_prev_len + at; } } } @@ -200,14 +195,14 @@ qstr qstr_from_strn(const char *str, size_t len) { // qstr does not exist in interned pool so need to add it // compute number of bytes needed to intern this string - size_t n_bytes = MICROPY_QSTR_BYTES_IN_HASH + MICROPY_QSTR_BYTES_IN_LEN + len + 1; + size_t n_bytes = len + 1; if (MP_STATE_VM(qstr_last_chunk) != NULL && MP_STATE_VM(qstr_last_used) + n_bytes > MP_STATE_VM(qstr_last_alloc)) { // not enough room at end of previously interned string so try to grow - byte *new_p = m_renew_maybe(byte, MP_STATE_VM(qstr_last_chunk), MP_STATE_VM(qstr_last_alloc), MP_STATE_VM(qstr_last_alloc) + n_bytes, false); + char *new_p = m_renew_maybe(char, MP_STATE_VM(qstr_last_chunk), MP_STATE_VM(qstr_last_alloc), MP_STATE_VM(qstr_last_alloc) + n_bytes, false); if (new_p == NULL) { // could not grow existing memory; shrink it to fit previous - (void)m_renew_maybe(byte, MP_STATE_VM(qstr_last_chunk), MP_STATE_VM(qstr_last_alloc), MP_STATE_VM(qstr_last_used), false); + (void)m_renew_maybe(char, MP_STATE_VM(qstr_last_chunk), MP_STATE_VM(qstr_last_alloc), MP_STATE_VM(qstr_last_used), false); MP_STATE_VM(qstr_last_chunk) = NULL; } else { // could grow existing memory @@ -221,10 +216,10 @@ qstr qstr_from_strn(const char *str, size_t len) { if (al < MICROPY_ALLOC_QSTR_CHUNK_INIT) { al = MICROPY_ALLOC_QSTR_CHUNK_INIT; } - MP_STATE_VM(qstr_last_chunk) = m_new_ll_maybe(byte, al); + MP_STATE_VM(qstr_last_chunk) = m_new_ll_maybe(char, al); if (MP_STATE_VM(qstr_last_chunk) == NULL) { // failed to allocate a large chunk so try with exact size - MP_STATE_VM(qstr_last_chunk) = m_new_ll_maybe(byte, n_bytes); + MP_STATE_VM(qstr_last_chunk) = m_new_ll_maybe(char, n_bytes); if (MP_STATE_VM(qstr_last_chunk) == NULL) { QSTR_EXIT(); m_malloc_fail(n_bytes); @@ -236,39 +231,41 @@ qstr qstr_from_strn(const char *str, size_t len) { } // allocate memory from the chunk for this new interned string's data - byte *q_ptr = MP_STATE_VM(qstr_last_chunk) + MP_STATE_VM(qstr_last_used); + char *q_ptr = MP_STATE_VM(qstr_last_chunk) + MP_STATE_VM(qstr_last_used); MP_STATE_VM(qstr_last_used) += n_bytes; // store the interned strings' data mp_uint_t hash = qstr_compute_hash((const byte *)str, len); - Q_SET_HASH(q_ptr, hash); - Q_SET_LENGTH(q_ptr, len); - memcpy(q_ptr + MICROPY_QSTR_BYTES_IN_HASH + MICROPY_QSTR_BYTES_IN_LEN, str, len); - q_ptr[MICROPY_QSTR_BYTES_IN_HASH + MICROPY_QSTR_BYTES_IN_LEN + len] = '\0'; - q = qstr_add(q_ptr); + memcpy(q_ptr, str, len); + q_ptr[len] = '\0'; + q = qstr_add(hash, len, q_ptr); } QSTR_EXIT(); return q; } mp_uint_t PLACE_IN_ITCM(qstr_hash)(qstr q) { - return Q_GET_HASH(find_qstr(q)); + qstr_attr_t attr; + find_qstr(q, &attr); + return attr.hash; } size_t qstr_len(qstr q) { - const byte *qd = find_qstr(q); - return Q_GET_LENGTH(qd); + qstr_attr_t attr; + find_qstr(q, &attr); + return attr.len; } const char *qstr_str(qstr q) { - const byte *qd = find_qstr(q); - return (const char *)Q_GET_DATA(qd); + qstr_attr_t attr; + return find_qstr(q, &attr); } const byte *qstr_data(qstr q, size_t *len) { - const byte *qd = find_qstr(q); - *len = Q_GET_LENGTH(qd); - return Q_GET_DATA(qd); + qstr_attr_t attr; + const char *qd = find_qstr(q, &attr); + *len = attr.len; + return (byte *)qd; } void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, size_t *n_total_bytes) { @@ -280,13 +277,14 @@ void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, si for (qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL && pool != &CONST_POOL; pool = pool->prev) { *n_pool += 1; *n_qstr += pool->len; - for (const byte **q = pool->qstrs, **q_top = pool->qstrs + pool->len; q < q_top; q++) { - *n_str_data_bytes += Q_GET_ALLOC(*q); + for (const qstr_attr_t *q = pool->attrs, *q_top = pool->attrs + pool->len; q < q_top; q++) { + *n_str_data_bytes += sizeof(*q) + q->len + 1; } #if MICROPY_ENABLE_GC - *n_total_bytes += gc_nbytes(pool); // this counts actual bytes used in heap + // this counts actual bytes used in heap + *n_total_bytes += gc_nbytes(pool) - sizeof(qstr_attr_t) * pool->alloc; #else - *n_total_bytes += sizeof(qstr_pool_t) + sizeof(qstr) * pool->alloc; + *n_total_bytes += sizeof(qstr_pool_t) + sizeof(const char *) * pool->alloc; #endif } *n_total_bytes += *n_str_data_bytes; @@ -297,8 +295,8 @@ void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, si void qstr_dump_data(void) { QSTR_ENTER(); for (qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL && pool != &CONST_POOL; pool = pool->prev) { - for (const byte **q = pool->qstrs, **q_top = pool->qstrs + pool->len; q < q_top; q++) { - mp_printf(&mp_plat_print, "Q(%s)\n", Q_GET_DATA(*q)); + for (const char **q = pool->qstrs, **q_top = pool->qstrs + pool->len; q < q_top; q++) { + mp_printf(&mp_plat_print, "Q(%s)\n", *q); } } QSTR_EXIT(); diff --git a/py/qstr.h b/py/qstr.h index c86e74324c..288bf5dbac 100644 --- a/py/qstr.h +++ b/py/qstr.h @@ -47,12 +47,30 @@ enum { typedef size_t qstr; +typedef struct _qstr_attr_t { + #if MICROPY_QSTR_BYTES_IN_HASH == 1 + uint8_t hash; + #elif MICROPY_QSTR_BYTES_IN_HASH == 2 + uint16_t hash; + #else + #error unimplemented qstr hash decoding + #endif + #if MICROPY_QSTR_BYTES_IN_LEN == 1 + uint8_t len; + #elif MICROPY_QSTR_BYTES_IN_LEN == 2 + uint16_t len; + #else + #error unimplemented qstr length decoding + #endif +} qstr_attr_t; + typedef struct _qstr_pool_t { struct _qstr_pool_t *prev; size_t total_prev_len; size_t alloc; size_t len; - const byte *qstrs[]; + qstr_attr_t *attrs; + const char *qstrs[]; } qstr_pool_t; #define QSTR_FROM_STR_STATIC(s) (qstr_from_strn((s), strlen(s))) diff --git a/py/repl.c b/py/repl.c index ccc8dd5c6b..6cc10bb007 100644 --- a/py/repl.c +++ b/py/repl.c @@ -281,6 +281,12 @@ size_t mp_repl_autocomplete(const char *str, size_t len, const mp_print_t *print ++str; } + // after "import", suggest built-in modules + static const char import_str[] = "import "; + if (len >= 7 && !memcmp(org_str, import_str, 7)) { + obj = MP_OBJ_NULL; + } + // look for matches size_t match_len; qstr q_first, q_last; @@ -291,19 +297,12 @@ size_t mp_repl_autocomplete(const char *str, size_t len, const mp_print_t *print if (q_first == 0) { // If there're no better alternatives, and if it's first word // in the line, try to complete "import". - static const char import_str[] = "import "; if (s_start == org_str && s_len > 0) { if (memcmp(s_start, import_str, s_len) == 0) { *compl_str = import_str + s_len; return sizeof(import_str) - 1 - s_len; } } - // after "import", suggest built-in modules - if (len >= 7 && !memcmp(org_str, import_str, 7)) { - obj = NULL; - match_str = find_completions( - s_start, s_len, obj, &match_len, &q_first, &q_last); - } if (q_first == 0) { *compl_str = " "; return s_len ? 0 : 4; diff --git a/shared-bindings/_bleio/Characteristic.c b/shared-bindings/_bleio/Characteristic.c index 0aa832cf21..b69b71d0c9 100644 --- a/shared-bindings/_bleio/Characteristic.c +++ b/shared-bindings/_bleio/Characteristic.c @@ -219,6 +219,23 @@ const mp_obj_property_t bleio_characteristic_value_obj = { (mp_obj_t)&mp_const_none_obj }, }; +//| max_length: int +//| """The max length of this characteristic.""" +//| +STATIC mp_obj_t bleio_characteristic_get_max_length(mp_obj_t self_in) { + bleio_characteristic_obj_t *self = MP_OBJ_TO_PTR(self_in); + + return MP_OBJ_NEW_SMALL_INT(common_hal_bleio_characteristic_get_max_length(self)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_characteristic_get_max_length_obj, bleio_characteristic_get_max_length); + +const mp_obj_property_t bleio_characteristic_max_length_obj = { + .base.type = &mp_type_property, + .proxy = { (mp_obj_t)&bleio_characteristic_get_max_length_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj }, +}; + //| descriptors: Descriptor //| """A tuple of :py:class:`Descriptor` objects related to this characteristic. (read-only)""" //| diff --git a/shared-bindings/_bleio/Characteristic.h b/shared-bindings/_bleio/Characteristic.h index a8486866f9..878d998a2d 100644 --- a/shared-bindings/_bleio/Characteristic.h +++ b/shared-bindings/_bleio/Characteristic.h @@ -40,6 +40,7 @@ extern bleio_characteristic_properties_t common_hal_bleio_characteristic_get_pro extern mp_obj_tuple_t *common_hal_bleio_characteristic_get_descriptors(bleio_characteristic_obj_t *self); extern bleio_service_obj_t *common_hal_bleio_characteristic_get_service(bleio_characteristic_obj_t *self); extern bleio_uuid_obj_t *common_hal_bleio_characteristic_get_uuid(bleio_characteristic_obj_t *self); +extern size_t common_hal_bleio_characteristic_get_max_length(bleio_characteristic_obj_t *self); extern size_t common_hal_bleio_characteristic_get_value(bleio_characteristic_obj_t *self, uint8_t *buf, size_t len); extern void common_hal_bleio_characteristic_add_descriptor(bleio_characteristic_obj_t *self, bleio_descriptor_obj_t *descriptor); extern void common_hal_bleio_characteristic_construct(bleio_characteristic_obj_t *self, bleio_service_obj_t *service, uint16_t handle, bleio_uuid_obj_t *uuid, bleio_characteristic_properties_t props, bleio_attribute_security_mode_t read_perm, bleio_attribute_security_mode_t write_perm, mp_int_t max_length, bool fixed_length, mp_buffer_info_t *initial_value_bufinfo); diff --git a/shared-bindings/_bleio/PacketBuffer.c b/shared-bindings/_bleio/PacketBuffer.c index 9412dee5d7..b54a48230b 100644 --- a/shared-bindings/_bleio/PacketBuffer.c +++ b/shared-bindings/_bleio/PacketBuffer.c @@ -44,7 +44,7 @@ //| When we're the server, we ignore all connections besides the first to subscribe to //| notifications.""" //| -//| def __init__(self, characteristic: Characteristic, *, buffer_size: int) -> None: +//| def __init__(self, characteristic: Characteristic, *, buffer_size: int, max_packet_size: Optional[int] = None) -> None: //| """Monitor the given Characteristic. Each time a new value is written to the Characteristic //| add the newly-written bytes to a FIFO buffer. //| @@ -55,14 +55,17 @@ //| It may be a local Characteristic provided by a Peripheral Service, or a remote Characteristic //| in a remote Service that a Central has connected to. //| :param int buffer_size: Size of ring buffer (in packets of the Characteristic's maximum -//| length) that stores incoming packets coming from the peer.""" +//| length) that stores incoming packets coming from the peer. +//| :param int max_packet_size: Maximum size of packets. Overrides value from the characteristic. +//| (Remote characteristics may not have the correct length.)""" //| ... //| STATIC mp_obj_t bleio_packet_buffer_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_characteristic, ARG_buffer_size }; + enum { ARG_characteristic, ARG_buffer_size, ARG_max_packet_size }; static const mp_arg_t allowed_args[] = { { MP_QSTR_characteristic, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_buffer_size, MP_ARG_KW_ONLY | MP_ARG_REQUIRED | MP_ARG_INT }, + { MP_QSTR_max_packet_size, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none}}, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; @@ -79,10 +82,15 @@ STATIC mp_obj_t bleio_packet_buffer_make_new(const mp_obj_type_t *type, size_t n mp_raise_TypeError(translate("Expected a Characteristic")); } + size_t max_packet_size = common_hal_bleio_characteristic_get_max_length(characteristic); + if (args[ARG_max_packet_size].u_obj != mp_const_none) { + max_packet_size = mp_obj_get_int(args[ARG_max_packet_size].u_obj); + } + bleio_packet_buffer_obj_t *self = m_new_obj(bleio_packet_buffer_obj_t); self->base.type = &bleio_packet_buffer_type; - common_hal_bleio_packet_buffer_construct(self, MP_OBJ_TO_PTR(characteristic), buffer_size); + common_hal_bleio_packet_buffer_construct(self, MP_OBJ_TO_PTR(characteristic), buffer_size, max_packet_size); return MP_OBJ_FROM_PTR(self); } @@ -133,7 +141,7 @@ STATIC mp_obj_t bleio_packet_buffer_write(mp_uint_t n_args, const mp_obj_t *pos_ enum { ARG_data, ARG_header }; static const mp_arg_t allowed_args[] = { { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_OBJ }, - { MP_QSTR_header, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL}}, + { MP_QSTR_header, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none}}, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; @@ -147,7 +155,7 @@ STATIC mp_obj_t bleio_packet_buffer_write(mp_uint_t n_args, const mp_obj_t *pos_ mp_buffer_info_t header_bufinfo; header_bufinfo.len = 0; - if (args[ARG_header].u_obj != MP_OBJ_NULL) { + if (args[ARG_header].u_obj != mp_const_none) { mp_get_buffer_raise(args[ARG_header].u_obj, &header_bufinfo, MP_BUFFER_READ); } diff --git a/shared-bindings/_bleio/PacketBuffer.h b/shared-bindings/_bleio/PacketBuffer.h index 65ce3ded1f..b300cb0215 100644 --- a/shared-bindings/_bleio/PacketBuffer.h +++ b/shared-bindings/_bleio/PacketBuffer.h @@ -33,7 +33,7 @@ extern const mp_obj_type_t bleio_packet_buffer_type; extern void common_hal_bleio_packet_buffer_construct( bleio_packet_buffer_obj_t *self, bleio_characteristic_obj_t *characteristic, - size_t buffer_size); + size_t buffer_size, size_t max_packet_size); mp_int_t common_hal_bleio_packet_buffer_write(bleio_packet_buffer_obj_t *self, uint8_t *data, size_t len, uint8_t *header, size_t header_len); mp_int_t common_hal_bleio_packet_buffer_readinto(bleio_packet_buffer_obj_t *self, uint8_t *data, size_t len); mp_int_t common_hal_bleio_packet_buffer_get_incoming_packet_length(bleio_packet_buffer_obj_t *self); diff --git a/shared-bindings/_typing/__init__.pyi b/shared-bindings/_typing/__init__.pyi index 9a6e963ea5..d1bf853f71 100644 --- a/shared-bindings/_typing/__init__.pyi +++ b/shared-bindings/_typing/__init__.pyi @@ -38,7 +38,7 @@ WriteableBuffer = Union[ """ AudioSample = Union[ - audiocore.WaveFile, audiocore.RawSample, audiomixer.Mixer, audiomp3.MP3Decoder + audiocore.WaveFile, audiocore.RawSample, audiomixer.Mixer, audiomp3.MP3Decoder, synthio.MidiTrack ] """Classes that implement the audiosample protocol @@ -46,6 +46,7 @@ AudioSample = Union[ - `audiocore.RawSample` - `audiomixer.Mixer` - `audiomp3.MP3Decoder` + - `synthio.MidiTrack` You can play these back with `audioio.AudioOut`, `audiobusio.I2SOut` or `audiopwmio.PWMAudioOut`. """ diff --git a/shared-bindings/audiocore/RawSample.c b/shared-bindings/audiocore/RawSample.c index 23a2d3f0be..13339222c1 100644 --- a/shared-bindings/audiocore/RawSample.c +++ b/shared-bindings/audiocore/RawSample.c @@ -30,7 +30,6 @@ #include "py/binary.h" #include "py/objproperty.h" #include "py/runtime.h" -#include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/util.h" #include "shared-bindings/audiocore/RawSample.h" #include "supervisor/shared/translate.h" @@ -83,26 +82,23 @@ STATIC mp_obj_t audioio_rawsample_make_new(const mp_obj_type_t *type, size_t n_a audioio_rawsample_obj_t *self = m_new_obj(audioio_rawsample_obj_t); self->base.type = &audioio_rawsample_type; mp_buffer_info_t bufinfo; - if (mp_get_buffer(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_READ)) { - uint8_t bytes_per_sample = 1; - bool signed_samples = bufinfo.typecode == 'b' || bufinfo.typecode == 'h'; - if (bufinfo.typecode == 'h' || bufinfo.typecode == 'H') { - bytes_per_sample = 2; - } else if (bufinfo.typecode != 'b' && bufinfo.typecode != 'B' && bufinfo.typecode != BYTEARRAY_TYPECODE) { - mp_raise_ValueError(translate("sample_source buffer must be a bytearray or array of type 'h', 'H', 'b' or 'B'")); - } - common_hal_audioio_rawsample_construct(self, ((uint8_t *)bufinfo.buf), bufinfo.len, - bytes_per_sample, signed_samples, args[ARG_channel_count].u_int, - args[ARG_sample_rate].u_int); - } else { - mp_raise_TypeError(translate("buffer must be a bytes-like object")); + mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_READ); + uint8_t bytes_per_sample = 1; + bool signed_samples = bufinfo.typecode == 'b' || bufinfo.typecode == 'h'; + if (bufinfo.typecode == 'h' || bufinfo.typecode == 'H') { + bytes_per_sample = 2; + } else if (bufinfo.typecode != 'b' && bufinfo.typecode != 'B' && bufinfo.typecode != BYTEARRAY_TYPECODE) { + mp_raise_ValueError(translate("sample_source buffer must be a bytearray or array of type 'h', 'H', 'b' or 'B'")); } + common_hal_audioio_rawsample_construct(self, ((uint8_t *)bufinfo.buf), bufinfo.len, + bytes_per_sample, signed_samples, args[ARG_channel_count].u_int, + args[ARG_sample_rate].u_int); return MP_OBJ_FROM_PTR(self); } //| def deinit(self) -> None: -//| """Deinitialises the AudioOut and releases any hardware resources for reuse.""" +//| """Deinitialises the RawSample and releases any hardware resources for reuse.""" //| ... //| STATIC mp_obj_t audioio_rawsample_deinit(mp_obj_t self_in) { diff --git a/shared-bindings/audiocore/RawSample.h b/shared-bindings/audiocore/RawSample.h index b07add2dd1..71056f30c3 100644 --- a/shared-bindings/audiocore/RawSample.h +++ b/shared-bindings/audiocore/RawSample.h @@ -27,7 +27,6 @@ #ifndef MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_RAWSAMPLE_H #define MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOIO_RAWSAMPLE_H -#include "common-hal/microcontroller/Pin.h" #include "shared-module/audiocore/RawSample.h" extern const mp_obj_type_t audioio_rawsample_type; diff --git a/shared-bindings/audiocore/WaveFile.c b/shared-bindings/audiocore/WaveFile.c index 73943f980f..5cf6deb2ed 100644 --- a/shared-bindings/audiocore/WaveFile.c +++ b/shared-bindings/audiocore/WaveFile.c @@ -44,7 +44,7 @@ //| """Load a .wav file for playback with `audioio.AudioOut` or `audiobusio.I2SOut`. //| //| :param typing.BinaryIO file: Already opened wave file -//| :param ~_typing.WriteableBuffer buffer: Optional pre-allocated buffer, that will be split in half and used for double-buffering of the data. If not provided, two 512 byte buffers are allocated internally. +//| :param ~_typing.WriteableBuffer buffer: Optional pre-allocated buffer, that will be split in half and used for double-buffering of the data. If not provided, two 256 byte buffers are allocated internally. //| //| //| Playing a wave file from flash:: diff --git a/shared-bindings/support_matrix.rst b/shared-bindings/support_matrix.rst index a2fb7987d2..2d2172122a 100644 --- a/shared-bindings/support_matrix.rst +++ b/shared-bindings/support_matrix.rst @@ -6,6 +6,11 @@ Module Support Matrix - Which Modules Are Available on Which Boards The following table lists the available built-in modules for each CircuitPython capable board. +.. raw:: html + +

(all)

+ +.. rst-class:: support-matrix-table .. list-table:: :header-rows: 1 :widths: 7, 50 diff --git a/shared-bindings/synthio/MidiTrack.c b/shared-bindings/synthio/MidiTrack.c new file mode 100644 index 0000000000..65fc7a4ee1 --- /dev/null +++ b/shared-bindings/synthio/MidiTrack.c @@ -0,0 +1,169 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Artyom Skrobov + * + * 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 + +#include "lib/utils/context_manager_helpers.h" +#include "py/binary.h" +#include "py/objproperty.h" +#include "py/runtime.h" +#include "shared-bindings/util.h" +#include "shared-bindings/synthio/MidiTrack.h" +#include "supervisor/shared/translate.h" + +//| class MidiTrack: +//| """Simple square-wave MIDI synth""" +//| +//| def __init__(self, buffer: ReadableBuffer, tempo: int, *, sample_rate: int = 11025) -> None: +//| """Create a MidiTrack from the given stream of MIDI events. Only "Note On" and "Note Off" events +//| are supported; channel numbers and key velocities are ignored. Up to two notes may be on at the +//| same time. +//| +//| :param ~_typing.ReadableBuffer buffer: Stream of MIDI events, as stored in a MIDI file track chunk +//| :param int tempo: Tempo of the streamed events, in MIDI ticks per second +//| :param int sample_rate: The desired playback sample rate; higher sample rate requires more memory +//| +//| Simple melody:: +//| +//| import audioio +//| import board +//| import synthio +//| +//| dac = audioio.AudioOut(board.SPEAKER) +//| melody = synthio.MidiTrack(b"\\0\\x90H\\0*\\x80H\\0\\6\\x90J\\0*\\x80J\\0\\6\\x90L\\0*\\x80L\\0\\6\\x90J\\0" + +//| b"*\\x80J\\0\\6\\x90H\\0*\\x80H\\0\\6\\x90J\\0*\\x80J\\0\\6\\x90L\\0T\\x80L\\0" + +//| b"\\x0c\\x90H\\0T\\x80H\\0\\x0c\\x90H\\0T\\x80H\\0", tempo=640) +//| dac.play(melody) +//| print("playing") +//| while dac.playing: +//| pass +//| print("stopped")""" +//| ... +//| +STATIC mp_obj_t synthio_miditrack_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_buffer, ARG_tempo, ARG_sample_rate }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_tempo, MP_ARG_INT | MP_ARG_REQUIRED }, + { MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 11025} }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_READ); + + synthio_miditrack_obj_t *self = m_new_obj(synthio_miditrack_obj_t); + self->base.type = &synthio_miditrack_type; + + common_hal_synthio_miditrack_construct(self, + (uint8_t *)bufinfo.buf, bufinfo.len, + args[ARG_tempo].u_int, + args[ARG_sample_rate].u_int); + + return MP_OBJ_FROM_PTR(self); +} + +//| def deinit(self) -> None: +//| """Deinitialises the MidiTrack and releases any hardware resources for reuse.""" +//| ... +//| +STATIC mp_obj_t synthio_miditrack_deinit(mp_obj_t self_in) { + synthio_miditrack_obj_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_synthio_miditrack_deinit(self); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(synthio_miditrack_deinit_obj, synthio_miditrack_deinit); + +STATIC void check_for_deinit(synthio_miditrack_obj_t *self) { + if (common_hal_synthio_miditrack_deinited(self)) { + raise_deinited_error(); + } +} + +//| def __enter__(self) -> MidiTrack: +//| """No-op used by Context Managers.""" +//| ... +//| +// Provided by context manager helper. + +//| def __exit__(self) -> None: +//| """Automatically deinitializes the hardware when exiting a context. See +//| :ref:`lifetime-and-contextmanagers` for more info.""" +//| ... +//| +STATIC mp_obj_t synthio_miditrack_obj___exit__(size_t n_args, const mp_obj_t *args) { + (void)n_args; + common_hal_synthio_miditrack_deinit(args[0]); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(synthio_miditrack___exit___obj, 4, 4, synthio_miditrack_obj___exit__); + +//| sample_rate: Optional[int] +//| """32 bit value that tells how quickly samples are played in Hertz (cycles per second).""" +//| +STATIC mp_obj_t synthio_miditrack_obj_get_sample_rate(mp_obj_t self_in) { + synthio_miditrack_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_synthio_miditrack_get_sample_rate(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(synthio_miditrack_get_sample_rate_obj, synthio_miditrack_obj_get_sample_rate); + +const mp_obj_property_t synthio_miditrack_sample_rate_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&synthio_miditrack_get_sample_rate_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + +STATIC const mp_rom_map_elem_t synthio_miditrack_locals_dict_table[] = { + // Methods + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&synthio_miditrack_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&synthio_miditrack___exit___obj) }, + + // Properties + { MP_ROM_QSTR(MP_QSTR_sample_rate), MP_ROM_PTR(&synthio_miditrack_sample_rate_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(synthio_miditrack_locals_dict, synthio_miditrack_locals_dict_table); + +STATIC const audiosample_p_t synthio_miditrack_proto = { + MP_PROTO_IMPLEMENT(MP_QSTR_protocol_audiosample) + .sample_rate = (audiosample_sample_rate_fun)common_hal_synthio_miditrack_get_sample_rate, + .bits_per_sample = (audiosample_bits_per_sample_fun)common_hal_synthio_miditrack_get_bits_per_sample, + .channel_count = (audiosample_channel_count_fun)common_hal_synthio_miditrack_get_channel_count, + .reset_buffer = (audiosample_reset_buffer_fun)synthio_miditrack_reset_buffer, + .get_buffer = (audiosample_get_buffer_fun)synthio_miditrack_get_buffer, + .get_buffer_structure = (audiosample_get_buffer_structure_fun)synthio_miditrack_get_buffer_structure, +}; + +const mp_obj_type_t synthio_miditrack_type = { + { &mp_type_type }, + .name = MP_QSTR_MidiTrack, + .make_new = synthio_miditrack_make_new, + .locals_dict = (mp_obj_dict_t *)&synthio_miditrack_locals_dict, + .protocol = &synthio_miditrack_proto, +}; diff --git a/shared-bindings/synthio/MidiTrack.h b/shared-bindings/synthio/MidiTrack.h new file mode 100644 index 0000000000..d44d4c3bb7 --- /dev/null +++ b/shared-bindings/synthio/MidiTrack.h @@ -0,0 +1,43 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Artyom Skrobov + * + * 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_SHARED_BINDINGS_SYNTHIO_MIDITRACK_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_SYNTHIO_MIDITRACK_H + +#include "shared-module/synthio/MidiTrack.h" + +extern const mp_obj_type_t synthio_miditrack_type; + +void common_hal_synthio_miditrack_construct(synthio_miditrack_obj_t *self, + const uint8_t *buffer, uint32_t len, uint32_t tempo, uint32_t sample_rate); + +void common_hal_synthio_miditrack_deinit(synthio_miditrack_obj_t *self); +bool common_hal_synthio_miditrack_deinited(synthio_miditrack_obj_t *self); +uint32_t common_hal_synthio_miditrack_get_sample_rate(synthio_miditrack_obj_t *self); +uint8_t common_hal_synthio_miditrack_get_bits_per_sample(synthio_miditrack_obj_t *self); +uint8_t common_hal_synthio_miditrack_get_channel_count(synthio_miditrack_obj_t *self); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_SYNTHIO_MIDITRACK_H diff --git a/shared-bindings/synthio/__init__.c b/shared-bindings/synthio/__init__.c new file mode 100644 index 0000000000..d5165001fc --- /dev/null +++ b/shared-bindings/synthio/__init__.c @@ -0,0 +1,136 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Artyom Skrobov + * + * 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 + +#include "py/mperrno.h" +#include "py/obj.h" +#include "py/runtime.h" +#include "extmod/vfs_fat.h" + +#include "shared-bindings/synthio/__init__.h" +#include "shared-bindings/synthio/MidiTrack.h" + +//| """Support for MIDI synthesis""" +//| +//| def from_file(file: typing.BinaryIO, *, sample_rate: int = 11025) -> MidiTrack: +//| """Create an AudioSample from an already opened MIDI file. +//| Currently, only single-track MIDI (type 0) is supported. +//| +//| :param typing.BinaryIO file: Already opened MIDI file +//| :param int sample_rate: The desired playback sample rate; higher sample rate requires more memory +//| +//| +//| Playing a MIDI file from flash:: +//| +//| import audioio +//| import board +//| import synthio +//| +//| data = open("single-track.midi", "rb") +//| midi = synthio.from_file(data) +//| a = audioio.AudioOut(board.A0) +//| +//| print("playing") +//| a.play(midi) +//| while a.playing: +//| pass +//| print("stopped")""" +//| ... +//| +STATIC mp_obj_t synthio_from_file(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_file, ARG_sample_rate }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_file, MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 11025} }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + if (!MP_OBJ_IS_TYPE(args[ARG_file].u_obj, &mp_type_fileio)) { + mp_raise_TypeError(translate("file must be a file opened in byte mode")); + } + pyb_file_obj_t *file = MP_OBJ_TO_PTR(args[ARG_file].u_obj); + + uint8_t chunk_header[14]; + f_rewind(&file->fp); + UINT bytes_read; + if (f_read(&file->fp, chunk_header, sizeof(chunk_header), &bytes_read) != FR_OK) { + mp_raise_OSError(MP_EIO); + } + if (bytes_read != sizeof(chunk_header) || + memcmp(chunk_header, "MThd\0\0\0\6\0\0\0\1", 12)) { + mp_raise_ValueError(translate("Invalid MIDI file")); + // TODO: for a multi-track MIDI (type 1), return an AudioMixer + } + + uint16_t tempo; + if (chunk_header[12] & 0x80) { + tempo = -(int8_t)chunk_header[12] * chunk_header[13]; + } else { + tempo = 2 * ((chunk_header[12] << 8) | chunk_header[13]); + } + + if (f_read(&file->fp, chunk_header, 8, &bytes_read) != FR_OK) { + mp_raise_OSError(MP_EIO); + } + if (bytes_read != 8 || memcmp(chunk_header, "MTrk", 4)) { + mp_raise_ValueError(translate("Invalid MIDI file")); + } + uint32_t track_size = (chunk_header[4] << 24) | + (chunk_header[5] << 16) | (chunk_header[6] << 8) | chunk_header[7]; + uint8_t *buffer = m_malloc(track_size, false); + if (f_read(&file->fp, buffer, track_size, &bytes_read) != FR_OK) { + mp_raise_OSError(MP_EIO); + } + if (bytes_read != track_size) { + mp_raise_ValueError(translate("Invalid MIDI file")); + } + + synthio_miditrack_obj_t *result = m_new_obj(synthio_miditrack_obj_t); + result->base.type = &synthio_miditrack_type; + + common_hal_synthio_miditrack_construct(result, buffer, track_size, + tempo, args[ARG_sample_rate].u_int); + + m_free(buffer); + + return MP_OBJ_FROM_PTR(result); +} +MP_DEFINE_CONST_FUN_OBJ_KW(synthio_from_file_obj, 1, synthio_from_file); + + +STATIC const mp_rom_map_elem_t synthio_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_synthio) }, + { MP_ROM_QSTR(MP_QSTR_MidiTrack), MP_ROM_PTR(&synthio_miditrack_type) }, + { MP_ROM_QSTR(MP_QSTR_from_file), MP_ROM_PTR(&synthio_from_file_obj) }, +}; + +STATIC MP_DEFINE_CONST_DICT(synthio_module_globals, synthio_module_globals_table); + +const mp_obj_module_t synthio_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&synthio_module_globals, +}; diff --git a/shared-bindings/synthio/__init__.h b/shared-bindings/synthio/__init__.h new file mode 100644 index 0000000000..14af1a5805 --- /dev/null +++ b/shared-bindings/synthio/__init__.h @@ -0,0 +1,34 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Artyom Skrobov + * + * 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_SHARED_BINDINGS_SYNTHIO___INIT___H +#define MICROPY_INCLUDED_SHARED_BINDINGS_SYNTHIO___INIT___H + +#include "py/obj.h" + +// Nothing now. + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_SYNTHIO___INIT___H diff --git a/shared-module/audiomixer/Mixer.c b/shared-module/audiomixer/Mixer.c index fdcd2dbfbf..20731933c4 100644 --- a/shared-module/audiomixer/Mixer.c +++ b/shared-module/audiomixer/Mixer.c @@ -103,11 +103,28 @@ void audiomixer_mixer_reset_buffer(audiomixer_mixer_obj_t *self, __attribute__((always_inline)) static inline uint32_t add16signed(uint32_t a, uint32_t b) { + #if (defined(__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) return __QADD16(a, b); + #else + uint32_t result = 0; + for (int8_t i = 0; i < 2; i++) { + int16_t ai = a >> (sizeof(int16_t) * 8 * i); + int16_t bi = b >> (sizeof(int16_t) * 8 * i); + int32_t intermediate = (int32_t)ai + bi; + if (intermediate > SHRT_MAX) { + intermediate = SHRT_MAX; + } else if (intermediate < SHRT_MIN) { + intermediate = SHRT_MIN; + } + result |= (((uint32_t)intermediate) & 0xffff) << (sizeof(int16_t) * 8 * i); + } + return result; + #endif } __attribute__((always_inline)) static inline uint32_t mult16signed(uint32_t val, int32_t mul) { + #if (defined(__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) mul <<= 16; int32_t hi, lo; enum { bits = 16 }; // saturate to 16 bits @@ -118,18 +135,46 @@ static inline uint32_t mult16signed(uint32_t val, int32_t mul) { asm volatile ("ssat %0, %1, %2, asr %3" : "=r" (hi) : "I" (bits), "r" (hi), "I" (shift)); asm volatile ("pkhbt %0, %1, %2, lsl #16" : "=r" (val) : "r" (lo), "r" (hi)); // pack return val; + #else + uint32_t result = 0; + float mod_mul = (float)mul / (float)((1 << 15) - 1); + for (int8_t i = 0; i < 2; i++) { + int16_t ai = (val >> (sizeof(uint16_t) * 8 * i)); + int32_t intermediate = ai * mod_mul; + if (intermediate > SHRT_MAX) { + intermediate = SHRT_MAX; + } else if (intermediate < SHRT_MIN) { + intermediate = SHRT_MIN; + } + intermediate &= 0x0000FFFF; + result |= (((uint32_t)intermediate)) << (sizeof(int16_t) * 8 * i); + } + return result; + #endif } static inline uint32_t tounsigned8(uint32_t val) { + #if (defined(__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) return __UADD8(val, 0x80808080); + #else + return val ^ 0x80808080; + #endif } static inline uint32_t tounsigned16(uint32_t val) { + #if (defined(__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) return __UADD16(val, 0x80008000); + #else + return val ^ 0x80008000; + #endif } static inline uint32_t tosigned16(uint32_t val) { + #if (defined(__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1)) return __UADD16(val, 0x80008000); + #else + return val ^ 0x80008000; + #endif } static inline uint32_t unpack8(uint16_t val) { diff --git a/shared-module/struct/__init__.c b/shared-module/struct/__init__.c index 7a7ea845e7..258036c93b 100644 --- a/shared-module/struct/__init__.c +++ b/shared-module/struct/__init__.c @@ -153,9 +153,11 @@ void shared_modules_struct_pack_into(mp_obj_t fmt_in, byte *p, byte *end_p, size p += sz; } else { while (sz--) { - mp_binary_set_val(fmt_type, *fmt, args[i], &p); // Pad bytes don't have a corresponding argument. - if (*fmt != 'x') { + if (*fmt == 'x') { + mp_binary_set_val(fmt_type, *fmt, MP_OBJ_NEW_SMALL_INT(0), &p); + } else { + mp_binary_set_val(fmt_type, *fmt, args[i], &p); i++; } } diff --git a/shared-module/synthio/MidiTrack.c b/shared-module/synthio/MidiTrack.c new file mode 100644 index 0000000000..0827945ab5 --- /dev/null +++ b/shared-module/synthio/MidiTrack.c @@ -0,0 +1,212 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Artyom Skrobov + * + * 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 "py/runtime.h" +#include "shared-bindings/synthio/MidiTrack.h" + +#define LOUDNESS 0x4000 // 0.5 +#define BITS_PER_SAMPLE 16 +#define BYTES_PER_SAMPLE (BITS_PER_SAMPLE / 8) +#define SILENCE 0x80 + +STATIC uint8_t parse_note(const uint8_t *buffer, uint32_t len, uint32_t *pos) { + if (*pos + 1 >= len) { + mp_raise_ValueError_varg(translate("Error in MIDI stream at position %d"), *pos); + } + uint8_t note = buffer[(*pos)++]; + if (note > 127 || buffer[(*pos)++] > 127) { + mp_raise_ValueError_varg(translate("Error in MIDI stream at position %d"), *pos); + } + return note; +} + +STATIC void terminate_span(synthio_miditrack_obj_t *self, uint16_t *dur, uint16_t *max_dur) { + if (*dur) { + self->track[self->total_spans - 1].dur = *dur; + if (*dur > *max_dur) { + *max_dur = *dur; + } + *dur = 0; + } else { + self->total_spans--; + } +} + +STATIC void add_span(synthio_miditrack_obj_t *self, uint8_t note1, uint8_t note2) { + synthio_midi_span_t span = { 0, {note1, note2} }; + self->track = m_realloc(self->track, + (self->total_spans + 1) * sizeof(synthio_midi_span_t)); + self->track[self->total_spans++] = span; +} + +void common_hal_synthio_miditrack_construct(synthio_miditrack_obj_t *self, + const uint8_t *buffer, uint32_t len, uint32_t tempo, uint32_t sample_rate) { + + synthio_midi_span_t initial = { 0, {SILENCE, SILENCE} }; + self->sample_rate = sample_rate; + self->track = m_malloc(sizeof(synthio_midi_span_t), false); + self->next_span = 0; + self->total_spans = 1; + *self->track = initial; + + uint16_t dur = 0, max_dur = 0; + uint32_t pos = 0; + while (pos < len) { + uint8_t c; + uint32_t delta = 0; + do { + c = buffer[pos++]; + delta <<= 7; + delta |= c & 0x7f; + } while ((c & 0x80) && (pos < len)); + + if (c & 0x80) { + mp_raise_ValueError_varg(translate("Error in MIDI stream at position %d"), pos); + } + + dur += delta * sample_rate / tempo; + + switch (buffer[pos++] >> 4) { + case 8: { // Note Off + uint8_t note = parse_note(buffer, len, &pos); + + // Ignore if not a note which is playing + synthio_midi_span_t last_span = self->track[self->total_spans - 1]; + if (last_span.note[0] == note || last_span.note[1] == note) { + terminate_span(self, &dur, &max_dur); + if (last_span.note[0] == note) { + add_span(self, last_span.note[1], SILENCE); + } else { + add_span(self, last_span.note[0], SILENCE); + } + } + break; + } + case 9: { // Note On + uint8_t note = parse_note(buffer, len, &pos); + + // Ignore if two notes are already playing + synthio_midi_span_t last_span = self->track[self->total_spans - 1]; + if (last_span.note[1] == SILENCE) { + terminate_span(self, &dur, &max_dur); + if (last_span.note[0] == SILENCE) { + add_span(self, note, SILENCE); + } else { + add_span(self, last_span.note[0], note); + } + } + break; + } + case 10: + case 11: + case 14: // two data bytes to ignore + parse_note(buffer, len, &pos); + break; + case 12: + case 13: // one data byte to ignore + if (pos >= len || buffer[pos++] > 127) { + mp_raise_ValueError_varg(translate("Error in MIDI stream at position %d"), pos); + } + break; + case 15: // the full syntax is too complicated, just assume it's "End of Track" event + pos = len; + break; + default: // invalid event + mp_raise_ValueError_varg(translate("Error in MIDI stream at position %d"), pos); + } + } + terminate_span(self, &dur, &max_dur); + + self->buffer_length = max_dur * BYTES_PER_SAMPLE; + self->buffer = m_malloc(self->buffer_length, false); +} + +void common_hal_synthio_miditrack_deinit(synthio_miditrack_obj_t *self) { + m_free(self->buffer); + self->buffer = NULL; + m_free(self->track); + self->track = NULL; +} +bool common_hal_synthio_miditrack_deinited(synthio_miditrack_obj_t *self) { + return self->buffer == NULL; +} + +uint32_t common_hal_synthio_miditrack_get_sample_rate(synthio_miditrack_obj_t *self) { + return self->sample_rate; +} +uint8_t common_hal_synthio_miditrack_get_bits_per_sample(synthio_miditrack_obj_t *self) { + return BITS_PER_SAMPLE; +} +uint8_t common_hal_synthio_miditrack_get_channel_count(synthio_miditrack_obj_t *self) { + return 1; +} + +void synthio_miditrack_reset_buffer(synthio_miditrack_obj_t *self, + bool single_channel, uint8_t channel) { + + self->next_span = 0; +} + +STATIC const uint16_t notes[] = {8372, 8870, 9397, 9956, 10548, 11175, 11840, + 12544, 13290, 14080, 14917, 15804}; // 9th octave + +audioio_get_buffer_result_t synthio_miditrack_get_buffer(synthio_miditrack_obj_t *self, + bool single_channel, uint8_t channel, uint8_t **buffer, uint32_t *buffer_length) { + + if (self->next_span >= self->total_spans) { + *buffer_length = 0; + return GET_BUFFER_DONE; + } + + synthio_midi_span_t span = self->track[self->next_span++]; + *buffer_length = span.dur * BYTES_PER_SAMPLE; + uint8_t octave1 = span.note[0] / 12; // 0..10 + uint8_t octave2 = span.note[1] / 12; // 0..10 + int32_t base_freq1 = notes[span.note[0] % 12]; + int32_t base_freq2 = notes[span.note[1] % 12]; + int32_t sample_rate = self->sample_rate; + + for (uint16_t i = 0; i < span.dur; i++) { + int16_t semiperiod1 = span.note[0] == SILENCE ? 0 : + ((base_freq1 * i * 2) / sample_rate) >> (10 - octave1); + int16_t semiperiod2 = span.note[1] == SILENCE ? semiperiod1 : + ((base_freq2 * i * 2) / sample_rate) >> (10 - octave2); + self->buffer[i] = ((semiperiod1 % 2 + semiperiod2 % 2) - 1) * LOUDNESS; + } + *buffer = (uint8_t *)self->buffer; + + return self->next_span >= self->total_spans ? + GET_BUFFER_DONE : GET_BUFFER_MORE_DATA; +} + +void synthio_miditrack_get_buffer_structure(synthio_miditrack_obj_t *self, bool single_channel, + bool *single_buffer, bool *samples_signed, uint32_t *max_buffer_length, uint8_t *spacing) { + + *single_buffer = true; + *samples_signed = true; + *max_buffer_length = self->buffer_length; + *spacing = 1; +} diff --git a/shared-module/synthio/MidiTrack.h b/shared-module/synthio/MidiTrack.h new file mode 100644 index 0000000000..bd058daaee --- /dev/null +++ b/shared-module/synthio/MidiTrack.h @@ -0,0 +1,65 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Artyom Skrobov + * + * 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_SHARED_MODULE_SYNTHIO_MIDITRACK_H +#define MICROPY_INCLUDED_SHARED_MODULE_SYNTHIO_MIDITRACK_H + +#include "py/obj.h" + +#include "shared-module/synthio/__init__.h" + +typedef struct { + uint16_t dur; + uint8_t note[2]; +} synthio_midi_span_t; + +typedef struct { + mp_obj_base_t base; + uint32_t sample_rate; + uint16_t *buffer; + uint16_t buffer_length; + synthio_midi_span_t *track; + uint16_t next_span; + uint16_t total_spans; +} synthio_miditrack_obj_t; + + +// These are not available from Python because it may be called in an interrupt. +void synthio_miditrack_reset_buffer(synthio_miditrack_obj_t *self, + bool single_channel, + uint8_t channel); + +audioio_get_buffer_result_t synthio_miditrack_get_buffer(synthio_miditrack_obj_t *self, + bool single_channel, + uint8_t channel, + uint8_t **buffer, + uint32_t *buffer_length); // length in bytes + +void synthio_miditrack_get_buffer_structure(synthio_miditrack_obj_t *self, bool single_channel, + bool *single_buffer, bool *samples_signed, + uint32_t *max_buffer_length, uint8_t *spacing); + +#endif // MICROPY_INCLUDED_SHARED_MODULE_SYNTHIO_MIDITRACK_H diff --git a/shared-module/synthio/__init__.c b/shared-module/synthio/__init__.c new file mode 100644 index 0000000000..e69de29bb2 diff --git a/shared-module/synthio/__init__.h b/shared-module/synthio/__init__.h new file mode 100644 index 0000000000..d9d98a5341 --- /dev/null +++ b/shared-module/synthio/__init__.h @@ -0,0 +1,32 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Artyom Skrobov + * + * 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_SHARED_MODULE_SYNTHIO__INIT__H +#define MICROPY_INCLUDED_SHARED_MODULE_SYNTHIO__INIT__H + +#include "shared-module/audiocore/__init__.h" + +#endif // MICROPY_INCLUDED_SHARED_MODULE_SYNTHIO__INIT__H diff --git a/supervisor/shared/cpu.c b/supervisor/shared/cpu.c new file mode 100644 index 0000000000..510225d197 --- /dev/null +++ b/supervisor/shared/cpu.c @@ -0,0 +1,40 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Scott Shawcroft for Adafruit Industries + * + * 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 + +#include "supervisor/shared/cpu.h" + +bool cpu_interrupt_active(void) { + #if defined(__ARM_ARCH) && (__ARM_ARCH >= 6) + // Check VECTACTIVE in ICSR. We don't need to disable interrupts because if + // one occurs after we read, we won't continue until it is resolved. + return (*((volatile uint32_t *)0xE000ED04) & 0x1ff) != 0; + #else + // We don't know. + return false; + #endif +} diff --git a/supervisor/shared/cpu.h b/supervisor/shared/cpu.h new file mode 100644 index 0000000000..9e2bed1e55 --- /dev/null +++ b/supervisor/shared/cpu.h @@ -0,0 +1,36 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Scott Shawcroft for Adafruit Industries + * + * 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_SUPERVISOR_SHARED_CPU_H +#define MICROPY_INCLUDED_SUPERVISOR_SHARED_CPU_H + +#include +#include + +// True when we're in an interrupt handler. +bool cpu_interrupt_active(void); + +#endif // MICROPY_INCLUDED_SUPERVISOR_SHARED_CPU_H diff --git a/supervisor/shared/safe_mode.c b/supervisor/shared/safe_mode.c index f9e787c159..cd73e1b9f9 100644 --- a/supervisor/shared/safe_mode.c +++ b/supervisor/shared/safe_mode.c @@ -170,13 +170,13 @@ void print_safe_mode_message(safe_mode_t reason) { serial_write_compressed(translate("Crash into the HardFault_Handler.")); return; case MICROPY_NLR_JUMP_FAIL: - serial_write_compressed(translate("MicroPython NLR jump failed. Likely memory corruption.")); + serial_write_compressed(translate("NLR jump failed. Likely memory corruption.")); return; case MICROPY_FATAL_ERROR: - serial_write_compressed(translate("MicroPython fatal error.")); + serial_write_compressed(translate("Fatal error.")); break; case GC_ALLOC_OUTSIDE_VM: - serial_write_compressed(translate("Attempted heap allocation when MicroPython VM not running.")); + serial_write_compressed(translate("Attempted heap allocation when VM not running.")); break; #ifdef SOFTDEVICE_PRESENT // defined in ports/nrf/bluetooth/bluetooth_common.mk diff --git a/supervisor/shared/serial.c b/supervisor/shared/serial.c index c73d702c9c..beb2541a15 100644 --- a/supervisor/shared/serial.c +++ b/supervisor/shared/serial.c @@ -28,6 +28,7 @@ #include "py/mpconfig.h" +#include "supervisor/shared/cpu.h" #include "supervisor/shared/display.h" #include "shared-bindings/terminalio/Terminal.h" #include "supervisor/serial.h" @@ -77,9 +78,9 @@ void serial_early_init(void) { void serial_init(void) { usb_init(); -#ifdef NRF_DEBUG_PRINT + #ifdef NRF_DEBUG_PRINT _debug_uart_init(); -#endif + #endif } bool serial_connected(void) { @@ -149,13 +150,17 @@ void serial_write_substring(const char *text, uint32_t length) { uint32_t count = 0; while (count < length && tud_cdc_connected()) { count += tud_cdc_write(text + count, length - count); + // If we're in an interrupt, then don't wait for more room. Queue up what we can. + if (cpu_interrupt_active()) { + break; + } usb_background(); } #if defined(DEBUG_UART_TX) && defined(DEBUG_UART_RX) int uart_errcode; - common_hal_busio_uart_write(&debug_uart, (const uint8_t *) text, length, &uart_errcode); + common_hal_busio_uart_write(&debug_uart, (const uint8_t *)text, length, &uart_errcode); #endif #ifdef NRF_DEBUG_PRINT diff --git a/supervisor/shared/translate.c b/supervisor/shared/translate.c index c99cbf180d..7afbd43e21 100644 --- a/supervisor/shared/translate.c +++ b/supervisor/shared/translate.c @@ -129,7 +129,7 @@ __attribute__((always_inline)) #endif const compressed_string_t *translate(const char *original) { #ifndef NO_QSTR - #define QDEF(id, str) + #define QDEF(id, hash, len, str) #define TRANSLATION(id, firstbyte, ...) if (strcmp(original, id) == 0) { static const compressed_string_t v = { .data = firstbyte, .tail = { __VA_ARGS__ } }; return &v; } else #include "genhdr/qstrdefs.generated.h" #undef TRANSLATION diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index 1744c4f47f..c206ff96be 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -4,6 +4,7 @@ SRC_SUPERVISOR = \ supervisor/shared/autoreload.c \ supervisor/shared/background_callback.c \ supervisor/shared/board.c \ + supervisor/shared/cpu.c \ supervisor/shared/filesystem.c \ supervisor/shared/flash.c \ supervisor/shared/micropython.c \ diff --git a/tests/basics/struct1.py b/tests/basics/struct1.py index 107006cc3f..ec29ea9080 100644 --- a/tests/basics/struct1.py +++ b/tests/basics/struct1.py @@ -121,3 +121,5 @@ except: # check padding bytes print(struct.pack("xb", 3)) +# Make sure pack doesn't reuse a larger value and error +print(struct.pack("xH", 0x100)) diff --git a/tests/circuitpython-manual/audiocore/single-track.midi b/tests/circuitpython-manual/audiocore/single-track.midi new file mode 100755 index 0000000000000000000000000000000000000000..3b3dcea8221ff6e7592c835a25e6ea2789e04324 GIT binary patch literal 5123 zcmZ{oeM=)*7RGBs2q8$2UTH)mh=_zBStn$Ioy6i=9m=inm7xmCuwL*W)_Xqm?Vp?j?>7TXW`@!`JD47&S^C}TeQ+M zGs;e{8aO7|+0{qR>1Jl8Ej&kAf6_?%D9qvu=d_gd@aV~7u?p1&a)7}x2IpBs=!noE zAwzd=a~@>l#br7+N7--^r9;!nqR9jDE$kxfIFour>ci=u4QJ3>oDj&6S{{giAqHl0 zK%g4{8aO0bxY$8{PfY?$H>jaW4KdBwqoxnp*>88MX)80Nq!eFjnm(zffcE8~CMS51 z`>+pWpHOWK283z>Jwoo=8cjmZU20lVQ;nSSnrND{yUOjRyPWT`cUM6+{Pg@lU7P7U z^EK<(^R#1*vlDxqo{&-3w$d&EdbUo@v+UIRn!EN8`JD6bB=$24txv3L50Kw*wj^rN z`^3Apfjr@ymT`C_P(+{(ff@u#2-L(NCQyEh0G?9mn&TS;_iK^rILtVwRYH9N`uPzH z3v?Iga1GkW?vY!M+)fFpk?Pt#5SUGy{$J>~KrgZA;t}HEW8$%m-~*vf2xSP>q>31W zRl6F5Qn_vH2J4Pn2=2(*U&N}s&^{4~8~?=ycs^=lQvHh6FIA7WVpriDXZYO{yW*=Q0-Hfw(@&~dlZ0@ru`YHMe z*E`{Qr%s<9p{%0l0Coq^Zgx)Z>EyH`vBtA4O*^6ORx(gC+V>o=pq85s{Zft-WNq z%Ium9uF2raeoL=R1-k?6Zm@$w?H4c#RJ?(_jeLL|Eg7PW8HX!#k3q$?B(hp@Z?gey z7`Pq=*$9AKkr>}UIv95showk0at#7g! zp=WMjf^1HQ=I9fUuX%je6u+Pua|UZ+>gW>A0lu<@NXA_h-}qf2#V#p^dDtfbk=`acrFfJBZsJ=* z7n7P#aUtSf07jiCT5BopbDlXvrAdl=q_~CQCJG_aH4pOuf(k66)JG9F+2bZxoFuLZ zxk=AS+YrG3!f3zT_==NsIUSp78VeZD;Gl0%PX(Y6oYZop1^H^zmQWmnWI+nxqysqV z#u>0!Dj4jd&}RQeDnjs|1U?nfqd2JsK-1Yp%u2+Kh5&^CDU}|VHRe`(Zb(D-K86Gw z5-{RZBw{&<vq8hFu-K=x~)m3;D>spE30&WScO8%J`c8j7`Fb)sf#J-^DIM z*Krw(sK&e^Dn_<}zJO1Jy~r_*Q9Qrp*GGPAlgR^_Y=Q6@>o;UlBa@{=8r!dUZ=h?U zi;=-dVrp@Mn0f5_Q4%o&(npqVxaN#`c*^^=A5HoZb52Ei6+)QYyNPE^h;M|bU~qu0 zip|IYyf$P9{XHrC%nKS(&<1vgIr#=K@f|j0NO%i73uXb^pZpeMZ=&1f9AhW47MuUM zfpHOK0cG-1&e({N%NSV_Dx-TtQo23e#Oj9n$orgKPu`G;)@hK>NP#vy0#a2^_BqJF z&x4wF4vk-$&-7$NJ$Z{#ZSUtPc((Q7D}>oW*TQC>aK7s?0Eto0ipXrvJ1u%rbeZ^t zq@MU4tR7q$^-i^0d^RY%CjbBK39k*s77oUN&zQa$j-H3B1lz%>LNKwWUj<6S^YLTO zN@dC~tm(P=g^N}~VcZR(u7iW06RvpvNSnp;a6F29o^NuPQm{ww7xd zJ!@1{yZZ0|f`73yp3{uyGU(s-wF~INfsJU*O3uJu(7X5WSOTfP4&?LFMSxR@qD{Bj2L221 zl>`rY@N-w1c9-8to*mBNZk{LNf*3!ZQMYZm8Rxi91r)KSJy9IWBgXI&Y-5tVLn_FvQD zVL12z<4u&B`6B|Z_L7J$B8e(x)mSJr=G)69$A0R$ngj+m!UEX+|HMi zWc0a(KIU`$-%_0df$a9AYM1b}^e(=S%pU&>=Rn$ z^=-#rWB%at`>~em^>>%{s#d)cR;7x!!WVySBkSh=O@0Sp#MnOTkna8aZ^3^606o9) literal 0 HcmV?d00001 diff --git a/tools/build_board_info.py b/tools/build_board_info.py index 94f6e50af1..66ca48a02d 100644 --- a/tools/build_board_info.py +++ b/tools/build_board_info.py @@ -266,7 +266,7 @@ def generate_download_info(): # Delete the release we are replacing for board in current_info: info = current_info[board] - for version in info["versions"]: + for version in list(info["versions"]): previous_releases.add(version["version"]) previous_languages.update(version["languages"]) if version["stable"] == new_stable or ( diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index c989b63007..42d62fdf11 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -607,6 +607,20 @@ def freeze_mpy(base_qstrs, raw_codes): print(" MP_QSTR_%s," % new[i][1]) print("};") + print() + print("const qstr_attr_t mp_qstr_frozen_const_attr[] = {") + qstr_size = {"metadata": 0, "data": 0} + for _, _, qstr in new: + qbytes = qstrutil.bytes_cons(qstr, "utf8") + print(" {%d, %d}," % ( + qstrutil.compute_hash(qbytes, config.MICROPY_QSTR_BYTES_IN_HASH), + len(qbytes) + )) + qstr_size["metadata"] += ( + config.MICROPY_QSTR_BYTES_IN_LEN + config.MICROPY_QSTR_BYTES_IN_HASH + ) + qstr_size["data"] += len(qbytes) + print("};") print() print("extern const qstr_pool_t mp_qstr_const_pool;") print("const qstr_pool_t mp_qstr_frozen_const_pool = {") @@ -614,19 +628,10 @@ def freeze_mpy(base_qstrs, raw_codes): print(" MP_QSTRnumber_of, // previous pool size") print(" %u, // allocated entries" % len(new)) print(" %u, // used entries" % len(new)) + print(" (qstr_attr_t *)mp_qstr_frozen_const_attr,") print(" {") - qstr_size = {"metadata": 0, "data": 0} for _, _, qstr in new: - qstr_size["metadata"] += ( - config.MICROPY_QSTR_BYTES_IN_LEN + config.MICROPY_QSTR_BYTES_IN_HASH - ) - qstr_size["data"] += len(qstr) - print( - " %s," - % qstrutil.make_bytes( - config.MICROPY_QSTR_BYTES_IN_LEN, config.MICROPY_QSTR_BYTES_IN_HASH, qstr - ) - ) + print(" \"%s\"," % qstrutil.escape_bytes(qstr)) print(" },") print("};") From 7daba64cb11fba0ab978cd84f4d58034906ccd93 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 25 Apr 2021 20:12:20 +0900 Subject: [PATCH 054/103] merge. --- lib/protomatter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protomatter b/lib/protomatter index 98017c5734..c2c81ded11 160000 --- a/lib/protomatter +++ b/lib/protomatter @@ -1 +1 @@ -Subproject commit 98017c57349e259fab70c6a7830436b19a55f6f4 +Subproject commit c2c81ded118484f8925bf81e270b416739cd72d9 From 872fff7fbbb8ca1297f7c5ec7760fa6536e9c233 Mon Sep 17 00:00:00 2001 From: jun2sak Date: Sun, 25 Apr 2021 23:59:21 +0900 Subject: [PATCH 055/103] simplify system_on_idle_until_alarm() --- ports/nrf/common-hal/alarm/__init__.c | 121 ++++++++------------------ 1 file changed, 37 insertions(+), 84 deletions(-) diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index 4c00cc4216..fb2938aebb 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -118,18 +118,6 @@ bool common_hal_alarm_woken_from_sleep(void) { || cause == NRF_SLEEP_WAKEUP_TOUCHPAD); } -nrf_sleep_source_t alarm_woken_from_sleep_2(void) { - nrf_sleep_source_t cause = _get_wakeup_cause(); - if (cause == NRF_SLEEP_WAKEUP_GPIO || - cause == NRF_SLEEP_WAKEUP_TIMER || - cause == NRF_SLEEP_WAKEUP_TOUCHPAD) { - return cause; - } - else { - return NRF_SLEEP_WAKEUP_UNDEFINED; - } -} - STATIC mp_obj_t _get_wake_alarm(size_t n_alarms, const mp_obj_t *alarms) { nrf_sleep_source_t cause = _get_wakeup_cause(); switch (cause) { @@ -163,7 +151,7 @@ STATIC void _setup_sleep_alarms(bool deep_sleep, size_t n_alarms, const mp_obj_t // TODO: this handles all possible types of wakeup, which is redundant with main. // revise to extract all parts essential to enabling sleep wakeup, but leave the // alarm/non-alarm sorting to the existing main loop. -nrf_sleep_source_t system_on_idle_until_alarm(int64_t timediff_ms, uint32_t prescaler) { +void system_on_idle_until_alarm(int64_t timediff_ms, uint32_t prescaler) { bool have_timeout = false; uint64_t start_tick = 0, end_tick = 0; int64_t tickdiff; @@ -197,7 +185,6 @@ nrf_sleep_source_t system_on_idle_until_alarm(int64_t timediff_ms, uint32_t pres #endif int64_t remaining; - nrf_sleep_source_t wakeup_cause = NRF_SLEEP_WAKEUP_UNDEFINED; sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_NONE; sleepmem_wakeup_pin = WAKEUP_PIN_UNDEF; @@ -210,30 +197,29 @@ nrf_sleep_source_t system_on_idle_until_alarm(int64_t timediff_ms, uint32_t pres #endif while(1) { - if (mp_hal_is_interrupted()) { - WAKEUP_REASON('I'); - break; - } - if (serial_connected() && serial_bytes_available()) { - WAKEUP_REASON('S'); - break; - } - RUN_BACKGROUND_TASKS; - wakeup_cause = alarm_woken_from_sleep_2(); - if (wakeup_cause != NRF_SLEEP_WAKEUP_UNDEFINED) { - WAKEUP_REASON('0'+wakeup_cause); - break; - } - if (have_timeout) { - remaining = end_tick - port_get_raw_ticks(NULL); - // We break a bit early so we don't risk setting the alarm before the time when we call - // sleep. - if (remaining < 1) { - WAKEUP_REASON('t'); + if (mp_hal_is_interrupted()) { + WAKEUP_REASON('I'); break; } - port_interrupt_after_ticks(remaining); - } + if (serial_connected() && serial_bytes_available()) { + WAKEUP_REASON('S'); + break; + } + RUN_BACKGROUND_TASKS; + if (common_hal_alarm_woken_from_sleep()) { + WAKEUP_REASON('W'); + break; + } + if (have_timeout) { + remaining = end_tick - port_get_raw_ticks(NULL); + // We break a bit early so we don't risk setting the alarm before the time when we call + // sleep. + if (remaining < 1) { + WAKEUP_REASON('t'); + break; + } + port_interrupt_after_ticks(remaining); + } // Idle until an interrupt happens. port_idle_until_interrupt(); #ifdef NRF_DEBUG_PRINT @@ -242,16 +228,15 @@ nrf_sleep_source_t system_on_idle_until_alarm(int64_t timediff_ms, uint32_t pres --ct; } #endif - if (have_timeout) { - remaining = end_tick - port_get_raw_ticks(NULL); - if (remaining <= 0) { - wakeup_cause = NRF_SLEEP_WAKEUP_TIMER; - sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_TIMER; - WAKEUP_REASON('T'); - break; + if (have_timeout) { + remaining = end_tick - port_get_raw_ticks(NULL); + if (remaining <= 0) { + sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_TIMER; + WAKEUP_REASON('T'); + break; + } } } - } #ifdef NRF_DEBUG_PRINT dbg_printf("%c\r\n", reason); #endif @@ -271,12 +256,10 @@ nrf_sleep_source_t system_on_idle_until_alarm(int64_t timediff_ms, uint32_t pres } dbg_printf("lapse %6.1f sec\r\n", sec); #endif - - return wakeup_cause; } mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj_t *alarms) { - mp_obj_t r_obj = mp_const_none; + mp_obj_t wake_alarm; alarm_time_timealarm_clear_wakeup_time(); _setup_sleep_alarms(false, n_alarms, alarms); @@ -285,25 +268,16 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj #endif int64_t timediff_ms = alarm_time_timealarm_get_wakeup_timediff_ms(); - nrf_sleep_source_t cause = system_on_idle_until_alarm(timediff_ms, 0); - (void)cause; - -#ifdef NRF_DEBUG_PRINT - //dbg_printf("wakeup! "); - print_wakeup_cause(cause); -#endif + system_on_idle_until_alarm(timediff_ms, 0); if (mp_hal_is_interrupted()) { -#ifdef NRF_DEBUG_PRINT - dbg_printf("mp_hal_is_interrupted\r\n"); -#endif - r_obj = mp_const_none; + wake_alarm = mp_const_none; } else { - r_obj = _get_wake_alarm(n_alarms, alarms); + wake_alarm = _get_wake_alarm(n_alarms, alarms); } alarm_reset(); - return r_obj; + return wake_alarm; } void common_hal_alarm_set_deep_sleep_alarms(size_t n_alarms, const mp_obj_t *alarms) { @@ -325,14 +299,9 @@ void NORETURN common_hal_alarm_enter_deep_sleep(void) { #ifdef NRF_DEBUG_PRINT dbg_check_RTCprescaler(); //XXX #endif - nrf_sleep_source_t cause; - cause = system_on_idle_until_alarm(timediff_ms, - PRESCALER_VALUE_IN_DEEP_SLEEP); - (void)cause; + system_on_idle_until_alarm(timediff_ms, PRESCALER_VALUE_IN_DEEP_SLEEP); #ifdef NRF_DEBUG_PRINT - dbg_printf("wakeup! "); - print_wakeup_cause(cause); dbg_printf("RESET...\r\n\r\n"); #endif @@ -370,25 +339,9 @@ void common_hal_alarm_pretending_deep_sleep(void) { #endif int64_t timediff_ms = alarm_time_timealarm_get_wakeup_timediff_ms(); - nrf_sleep_source_t cause = system_on_idle_until_alarm(timediff_ms, 0); - (void)cause; + system_on_idle_until_alarm(timediff_ms, 0); -#ifdef NRF_DEBUG_PRINT - dbg_printf("wakeup! "); - print_wakeup_cause(cause); -#endif - - // alarm_reset(); - -#if 0 - // if one of Alarm event occurred, reset myself - if (cause == NRF_SLEEP_WAKEUP_GPIO || - cause == NRF_SLEEP_WAKEUP_TIMER || - cause == NRF_SLEEP_WAKEUP_TOUCHPAD) { - reset_cpu(); - } - // else, just return and go into REPL -#endif + alarm_reset(); } void common_hal_alarm_gc_collect(void) { From 43840363c2ac1709ff0ed456f042a7b31c82db41 Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Mon, 26 Apr 2021 17:59:21 -0400 Subject: [PATCH 056/103] Fix submodule --- lib/protomatter | 2 +- ports/nrf/common-hal/alarm/__init__.c | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/protomatter b/lib/protomatter index c2c81ded11..98017c5734 160000 --- a/lib/protomatter +++ b/lib/protomatter @@ -1 +1 @@ -Subproject commit c2c81ded118484f8925bf81e270b416739cd72d9 +Subproject commit 98017c57349e259fab70c6a7830436b19a55f6f4 diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index fb2938aebb..3ce963f0d6 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -121,16 +121,16 @@ bool common_hal_alarm_woken_from_sleep(void) { STATIC mp_obj_t _get_wake_alarm(size_t n_alarms, const mp_obj_t *alarms) { nrf_sleep_source_t cause = _get_wakeup_cause(); switch (cause) { - case NRF_SLEEP_WAKEUP_TIMER: { - return alarm_time_timealarm_get_wakeup_alarm(n_alarms, alarms); - } - case NRF_SLEEP_WAKEUP_TOUCHPAD: { - return alarm_touch_touchalarm_get_wakeup_alarm(n_alarms, alarms); - } - case NRF_SLEEP_WAKEUP_GPIO: { - return alarm_pin_pinalarm_get_wakeup_alarm(n_alarms, alarms); - } - default: + case NRF_SLEEP_WAKEUP_TIMER: { + return alarm_time_timealarm_get_wakeup_alarm(n_alarms, alarms); + } + case NRF_SLEEP_WAKEUP_TOUCHPAD: { + return alarm_touch_touchalarm_get_wakeup_alarm(n_alarms, alarms); + } + case NRF_SLEEP_WAKEUP_GPIO: { + return alarm_pin_pinalarm_get_wakeup_alarm(n_alarms, alarms); + } + default: break; } return mp_const_none; From 2d80f6b872008a5afc07bffbeaf7a1e0522287aa Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Tue, 27 Apr 2021 17:11:42 -0400 Subject: [PATCH 057/103] Module_description_changes --- docs/design_guide.rst | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index 5bd6bbd387..edd8c0a6f2 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -238,11 +238,34 @@ Module description After the license comment:: """ - `` - + `` ================================================= + + + * Author(s): + + Implementation Notes + -------------------- + + + **Hardware:** + + * Adafruit `Device Description + `_ (Product ID: ) + + **Software and Dependencies:** + + * Adafruit CircuitPython firmware for the supported boards: + https://circuitpython.org/downloads + * Adafruit's Bus Device library: + https://github.com/adafruit/Adafruit_CircuitPython_BusDevice + * Adafruit's Register library: + https://github.com/adafruit/Adafruit_CircuitPython_Register + """ + Class description ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ From 4d0e183ae11e291390f54d3d8ed749976866b7d0 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Tue, 27 Apr 2021 17:18:14 -0400 Subject: [PATCH 058/103] Module_description_changes --- docs/design_guide.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index edd8c0a6f2..5ba5788573 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -241,7 +241,7 @@ After the license comment:: `` ================================================= - + * Author(s): From a512dd230df419c204b7acd49c0cc7f9ebdce290 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Tue, 27 Apr 2021 17:34:45 -0400 Subject: [PATCH 059/103] word_order_better_phrasing --- docs/design_guide.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index 5ba5788573..e9a275dd41 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -409,7 +409,7 @@ Renders as: Documentation References to other Libraries ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ When you need to make references to documentation in other libraries you should refer the class using single -backticks ``:class:`~adafruit_motor.servo.Servo```. You must add also the reference in the ``conf.py`` file in the +backticks ``:class:`~adafruit_motor.servo.Servo```. You must also add the reference in the ``conf.py`` file in the ``intersphinx_mapping section`` adding a new entry:: "adafruit_motor": ("https://circuitpython.readthedocs.io/projects/motor/en/latest/", None,), From cb42acea53d4780a018db3bea253708d5d7dd404 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Tue, 27 Apr 2021 17:43:25 -0400 Subject: [PATCH 060/103] better_phrasing --- docs/design_guide.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index e9a275dd41..8ad0428afa 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -410,7 +410,7 @@ Documentation References to other Libraries ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ When you need to make references to documentation in other libraries you should refer the class using single backticks ``:class:`~adafruit_motor.servo.Servo```. You must also add the reference in the ``conf.py`` file in the -``intersphinx_mapping section`` adding a new entry:: +``intersphinx_mapping section`` by adding a new entry:: "adafruit_motor": ("https://circuitpython.readthedocs.io/projects/motor/en/latest/", None,), From e85091193b4a3ffdcff55984ed1459e7477dd531 Mon Sep 17 00:00:00 2001 From: Seth Kerr Date: Tue, 27 Apr 2021 16:30:44 -0600 Subject: [PATCH 061/103] adding CP Sapling Rev B --- .../boards/cp_sapling_m0_revb/mpconfigboard.h | 1 + .../boards/cp_sapling_m0_revb/pins.c | 34 ++++++++----------- supervisor/shared/external_flash/devices.h | 4 +-- tests/pyboard 2.py | 1 + 4 files changed, 18 insertions(+), 22 deletions(-) create mode 120000 tests/pyboard 2.py diff --git a/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.h b/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.h index 7e216598fe..384c299e3d 100644 --- a/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.h +++ b/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.h @@ -14,6 +14,7 @@ #define IGNORE_PIN_PA13 1 #define IGNORE_PIN_PA20 1 #define IGNORE_PIN_PA21 1 +#define IGNORE_PIN_PA23 // USB is always used internally so skip the pin objects for it. #define IGNORE_PIN_PA24 1 #define IGNORE_PIN_PA25 1 diff --git a/ports/atmel-samd/boards/cp_sapling_m0_revb/pins.c b/ports/atmel-samd/boards/cp_sapling_m0_revb/pins.c index 81ed8722c5..b88b6869ef 100644 --- a/ports/atmel-samd/boards/cp_sapling_m0_revb/pins.c +++ b/ports/atmel-samd/boards/cp_sapling_m0_revb/pins.c @@ -2,21 +2,17 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PA22) }, - { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PA22) }, - { MP_ROM_QSTR(MP_QSTR_SS), MP_ROM_PTR(&pin_PA22) }, - { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_PA19) }, { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA19) }, - { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pon_PA19 }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PA19) }, { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PA18) }, { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PA18) }, - { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA18) }. + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA18) }, { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PA17) }, { MP_ROM_QSTR(MP_QSTR_A6), MP_ROM_PTR(&pin_PA17) }, - { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA17) }. + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA17) }, { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_PA07) }, { MP_ROM_QSTR(MP_QSTR_A7), MP_ROM_PTR(&pin_PA07) }, @@ -35,22 +31,20 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA03) }, { MP_ROM_QSTR(MP_QSTR_A11), MP_ROM_PTR(&pin_PA03) }, - { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA09) }, - { MP_ROM_QSTR(MP_QSTR_A12), MP_ROM_PTR(&pin_PA09) }, - { MP_ROM+QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA09) }, + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA03) }, + { MP_ROM_QSTR(MP_QSTR_A12), MP_ROM_PTR(&pin_PA03) }, - { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA08) }, - { MP_ROM_QSTR(MP_QSTR_A13), MP_ROM_PTR(&pin_PA08),}, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA03) }, + { MP_ROM_QSTR(MP_QSTR_A13), MP_ROM_PTR(&pin_PA03) }, + + { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_PA09) }, + { MP_ROM_QSTR(MP_QSTR_A14), MP_ROM_PTR(&pin_PA09) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA09) }, + + { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_PA08) }, + { MP_ROM_QSTR(MP_QSTR_A15), MP_ROM_PTR(&pin_PA08) }, { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA08) }, - { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PA17) }, - { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA17) }, - { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PA17) }, - - { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PA18) }, - { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PA18) }, - { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PA18) }, - { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA15) }, { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, diff --git a/supervisor/shared/external_flash/devices.h b/supervisor/shared/external_flash/devices.h index c8c941adf8..45473b21bc 100644 --- a/supervisor/shared/external_flash/devices.h +++ b/supervisor/shared/external_flash/devices.h @@ -605,8 +605,8 @@ typedef struct { .single_status_byte = true, \ } -// Settings for the Macronix MX25L51245G 64MiB SPI flash. -// Datasheet: https://www.macronix.com/Lists/Datasheet/Attachments/7437/MX25L51245G,%203V,%20512Mb,%20v1.6.pdf +// Settings for the Macronix MX25L25645G 32MiB SPI flash. +// Datasheet: https://www.macronix.com/Lists/Datasheet/Attachments/7437/MX25L25645G,%203V,%20256Mb,%20v1.6.pdf #define MX25L25645G {\ .total_size = (1 << 25), /* 32 MiB */ \ .start_up_time_us = 5000, \ diff --git a/tests/pyboard 2.py b/tests/pyboard 2.py new file mode 120000 index 0000000000..616773a313 --- /dev/null +++ b/tests/pyboard 2.py @@ -0,0 +1 @@ +../tools/cpboard.py \ No newline at end of file From 2f09535c3a3d7561de27ed5b60be96974733ba99 Mon Sep 17 00:00:00 2001 From: Seth Kerr Date: Tue, 27 Apr 2021 16:41:54 -0600 Subject: [PATCH 062/103] removing duplicate file --- tests/pyboard 2.py | 1 - 1 file changed, 1 deletion(-) delete mode 120000 tests/pyboard 2.py diff --git a/tests/pyboard 2.py b/tests/pyboard 2.py deleted file mode 120000 index 616773a313..0000000000 --- a/tests/pyboard 2.py +++ /dev/null @@ -1 +0,0 @@ -../tools/cpboard.py \ No newline at end of file From 710397fd84f6681bd973905022a798c04d19bbfb Mon Sep 17 00:00:00 2001 From: Seth Kerr Date: Tue, 27 Apr 2021 16:54:13 -0600 Subject: [PATCH 063/103] adding board to build.yml --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 69dcaf46d1..f9c11a8f44 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -202,6 +202,7 @@ jobs: - "clue_nrf52840_express" - "cp32-m4" - "cp_sapling_m0" + - "cp_sapling_m0_revb" - "cp_sapling_m0_spiflash" - "datalore_ip_m4" - "datum_distance" From 444c008731735457cba5f798e3504ccb8315e3b4 Mon Sep 17 00:00:00 2001 From: Seth Kerr Date: Tue, 27 Apr 2021 17:50:22 -0600 Subject: [PATCH 064/103] removing changes from external flash devices --- supervisor/shared/external_flash/devices.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/supervisor/shared/external_flash/devices.h b/supervisor/shared/external_flash/devices.h index 45473b21bc..c8c941adf8 100644 --- a/supervisor/shared/external_flash/devices.h +++ b/supervisor/shared/external_flash/devices.h @@ -605,8 +605,8 @@ typedef struct { .single_status_byte = true, \ } -// Settings for the Macronix MX25L25645G 32MiB SPI flash. -// Datasheet: https://www.macronix.com/Lists/Datasheet/Attachments/7437/MX25L25645G,%203V,%20256Mb,%20v1.6.pdf +// Settings for the Macronix MX25L51245G 64MiB SPI flash. +// Datasheet: https://www.macronix.com/Lists/Datasheet/Attachments/7437/MX25L51245G,%203V,%20512Mb,%20v1.6.pdf #define MX25L25645G {\ .total_size = (1 << 25), /* 32 MiB */ \ .start_up_time_us = 5000, \ From 0c23c735102a4702f18adf6525a44ec563876034 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Wed, 28 Apr 2021 05:34:51 -0400 Subject: [PATCH 065/103] defining_parameters --- docs/design_guide.rst | 83 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 2 deletions(-) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index 1bac4df61b..9ff7dffb55 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -238,11 +238,34 @@ Module description After the license comment:: """ - `` - + `` ================================================= - + + + + * Author(s): + + Implementation Notes + -------------------- + + + **Hardware:** + + * Adafruit `Device Description + `_ (Product ID: ) + + **Software and Dependencies:** + + * Adafruit CircuitPython firmware for the supported boards: + https://circuitpython.org/downloads + * Adafruit's Bus Device library: + https://github.com/adafruit/Adafruit_CircuitPython_BusDevice + * Adafruit's Register library: + https://github.com/adafruit/Adafruit_CircuitPython_Register + """ + Class description ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -269,6 +292,54 @@ Renders as: :param ~busio.I2C i2c_bus: The I2C bus the DS3231 is connected to. :param int address: The I2C address of the device. Defaults to :const:`0x40` + +Parameters Documentation +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Although there are different ways to document class and functions definitions in Python, +the following is the prevalent method of doing paramaters documenations +for CircuitPython libraries. When documenting class parameters you should use the +following structure:: + + :param ~busio.I2C i2c_bus: The I2C bus the DS3231 is connected to + + +param_type +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Type of the parameter. This could be amon other ``int``, ``float``, ``str`` ``bool``, etc. +When referring to different objects in the CircuitPython domain you need to include the reference +by adding a `~` before the definition as shown in the following example:: + + :param ~busio.I2C i2c_bus: The I2C bus the DS3231 is connected to. + + +To include references to CircuitPython modules cookiecutter creates an entry in the +intersphinx_mapping entry in the `conf.py` file located within the `docs` directory. +To add different types outside CircuitPython you need to add more definition to intersphinx_mapping:: + + + intersphinx_mapping = { + "python": ("https://docs.python.org/3.4", None), + "BusDevice":("https://circuitpython.readthedocs.io/projects/busdevice/en/latest/", None,), + "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), + } + +The inthersphinx_mapping above include reference to the Python, BusDevice and CircuitPython +Documentation + + +param_name +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Parameter name used in the class or method definition + + +Parameter_description +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Parameter description. When the parameter defaults to a particular values, it is a good +practice to mention this:: + + :param int pitch: Pitch value for the servo. Defaults to :const:`4500` + + Attributes ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -383,6 +454,14 @@ Renders as: :param float degrees: Degrees to turn right +Documentation References to other Libraries +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +When you need to make references to documentation in other libraries you should refer the class using single +backticks ``:class:`~adafruit_motor.servo.Servo```. You must also add the reference in the ``conf.py`` file in the +``intersphinx_mapping section`` by adding a new entry:: + + "adafruit_motor": ("https://circuitpython.readthedocs.io/projects/motor/en/latest/", None,), + Use BusDevice -------------------------------------------------------------------------------- From 4e931697c6efee6db1188124a72adfa923c9d645 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Wed, 28 Apr 2021 06:07:45 -0400 Subject: [PATCH 066/103] adding_backticks, typos --- docs/design_guide.rst | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index 9ff7dffb55..4c9ca00521 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -296,24 +296,28 @@ Renders as: Parameters Documentation ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Although there are different ways to document class and functions definitions in Python, -the following is the prevalent method of doing paramaters documenations +the following is the prevalent method of doing parameters documentations for CircuitPython libraries. When documenting class parameters you should use the -following structure:: +following structure: - :param ~busio.I2C i2c_bus: The I2C bus the DS3231 is connected to +.. code-block:: sh + + :param param_type param_name: Parameter_description param_type ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Type of the parameter. This could be amon other ``int``, ``float``, ``str`` ``bool``, etc. +Type of the parameter. This could be among other `int`, `float`, `str` `bool`, etc. When referring to different objects in the CircuitPython domain you need to include the reference -by adding a `~` before the definition as shown in the following example:: +by adding a ``~`` before the definition as shown in the following example: + +.. code-block:: sh :param ~busio.I2C i2c_bus: The I2C bus the DS3231 is connected to. To include references to CircuitPython modules cookiecutter creates an entry in the -intersphinx_mapping entry in the `conf.py` file located within the `docs` directory. +intersphinx_mapping entry in the ``conf.py`` file located within the ``docs`` directory. To add different types outside CircuitPython you need to add more definition to intersphinx_mapping:: From 38c6234b84a701a0d1dca0ee7e40d53a82833f1e Mon Sep 17 00:00:00 2001 From: Reza Almanda Date: Wed, 28 Apr 2021 02:21:35 +0000 Subject: [PATCH 067/103] Translated using Weblate (Indonesian) Currently translated at 46.5% (452 of 972 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/id/ --- locale/ID.po | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index 9507fb0b22..8653094ab4 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2021-04-07 12:23+0000\n" +"PO-Revision-Date: 2021-04-28 16:11+0000\n" "Last-Translator: Reza Almanda \n" "Language-Team: LANGUAGE \n" "Language: ID\n" @@ -14,7 +14,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" -"X-Generator: Weblate 4.6-dev\n" +"X-Generator: Weblate 4.7-dev\n" #: main.c msgid "" @@ -1662,11 +1662,11 @@ msgstr "Hanya 8 atau 16 bit mono dengan " #: ports/esp32s2/common-hal/wifi/__init__.c msgid "Only IPv4 addresses supported" -msgstr "" +msgstr "Hanya alamat IPv4 yang didukung" #: ports/esp32s2/common-hal/socketpool/SocketPool.c msgid "Only IPv4 sockets supported" -msgstr "" +msgstr "Hanysa socket IPv4 yang didukung" #: shared-module/displayio/OnDiskBitmap.c #, c-format @@ -1707,15 +1707,15 @@ msgstr "" #: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c msgid "Operation timed out" -msgstr "" +msgstr "Waktu habis" #: ports/esp32s2/bindings/espidf/__init__.c ports/esp32s2/esp_error.c msgid "Out of memory" -msgstr "" +msgstr "Kehabisan memori" #: ports/esp32s2/common-hal/socketpool/SocketPool.c msgid "Out of sockets" -msgstr "" +msgstr "Kehabisan socket" #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "Out-buffer elements must be <= 4 bytes long" @@ -1761,7 +1761,7 @@ msgstr "ParallelBus belum didukung" #: ports/esp32s2/common-hal/audiobusio/__init__.c msgid "Peripheral in use" -msgstr "" +msgstr "Periferal sedang digunakan" #: py/moduerrno.c msgid "Permission denied" @@ -1773,7 +1773,7 @@ msgstr "" #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "Pin count too large" -msgstr "" +msgstr "Jumlah pin terlalu besar" #: ports/atmel-samd/common-hal/analogio/AnalogIn.c #: ports/cxd56/common-hal/analogio/AnalogIn.c @@ -1815,7 +1815,7 @@ msgstr "" #: ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c msgid "Pins must be sequential" -msgstr "" +msgstr "Pin harus berurutan" #: ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c msgid "Pins must share PWM slice" @@ -4239,11 +4239,11 @@ msgstr "" #: ports/esp32s2/common-hal/wifi/Radio.c msgid "wifi is not enabled" -msgstr "" +msgstr "wifi tidak diaktifkan" #: shared-bindings/_bleio/Adapter.c msgid "window must be <= interval" -msgstr "" +msgstr "jendela harus <= interval" #: extmod/ulab/code/numpy/numerical/numerical.c msgid "wrong axis index" From bc8b254d4f0bd64c22d5f6836cb18f78f02a649f Mon Sep 17 00:00:00 2001 From: Alvaro Figueroa Date: Tue, 27 Apr 2021 19:50:57 +0000 Subject: [PATCH 068/103] Translated using Weblate (Spanish) Currently translated at 100.0% (972 of 972 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/es/ --- locale/es.po | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/locale/es.po b/locale/es.po index 3dfe2adc7b..0bb384dd9d 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2021-04-25 18:43+0000\n" +"PO-Revision-Date: 2021-04-28 16:11+0000\n" "Last-Translator: Alvaro Figueroa \n" "Language-Team: \n" "Language: es\n" @@ -3164,11 +3164,11 @@ msgstr "identificador redefinido como nonlocal" #: py/persistentcode.c msgid "incompatible .mpy file" -msgstr "" +msgstr "archivo .mpy incompatible" #: py/persistentcode.c msgid "incompatible native .mpy architecture" -msgstr "" +msgstr "arquitectura nativa de .mpy incompatible" #: py/objstr.c msgid "incomplete format" @@ -3291,7 +3291,7 @@ msgstr "el intervalo debe ser der rango %s-%s" #: py/compile.c msgid "invalid architecture" -msgstr "" +msgstr "arquitectura inválida" #: lib/netutils/netutils.c msgid "invalid arguments" From 602835a62933a58085104d7760decfafe19c4da5 Mon Sep 17 00:00:00 2001 From: Hugo Dahl Date: Wed, 28 Apr 2021 00:56:51 +0000 Subject: [PATCH 069/103] Translated using Weblate (French) Currently translated at 100.0% (972 of 972 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/fr/ --- locale/fr.po | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/locale/fr.po b/locale/fr.po index 4b314c155d..7660ce4169 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2021-04-24 14:29+0000\n" +"PO-Revision-Date: 2021-04-28 16:11+0000\n" "Last-Translator: Hugo Dahl \n" "Language: fr\n" "MIME-Version: 1.0\n" @@ -3187,11 +3187,11 @@ msgstr "identifiant redéfini comme nonlocal" #: py/persistentcode.c msgid "incompatible .mpy file" -msgstr "" +msgstr "Fichier .mpy incompatible" #: py/persistentcode.c msgid "incompatible native .mpy architecture" -msgstr "" +msgstr "architecture native .mpy incompatible" #: py/objstr.c msgid "incomplete format" @@ -3315,7 +3315,7 @@ msgstr "interval doit être dans la portée %s-%s" #: py/compile.c msgid "invalid architecture" -msgstr "" +msgstr "architecture invalide" #: lib/netutils/netutils.c msgid "invalid arguments" From 4834a21b9c136a0faf673f7ea73791c88a66cb17 Mon Sep 17 00:00:00 2001 From: Wellington Terumi Uemura Date: Tue, 27 Apr 2021 20:41:16 +0000 Subject: [PATCH 070/103] Translated using Weblate (Portuguese (Brazil)) Currently translated at 100.0% (972 of 972 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/pt_BR/ --- locale/pt_BR.po | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/locale/pt_BR.po b/locale/pt_BR.po index cfe04562a0..58a706d216 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2021-04-25 18:43+0000\n" +"PO-Revision-Date: 2021-04-28 16:11+0000\n" "Last-Translator: Wellington Terumi Uemura \n" "Language-Team: \n" "Language: pt_BR\n" @@ -3173,11 +3173,11 @@ msgstr "o identificador foi redefinido como não-local" #: py/persistentcode.c msgid "incompatible .mpy file" -msgstr "" +msgstr "arquivo .mpy incompatível" #: py/persistentcode.c msgid "incompatible native .mpy architecture" -msgstr "" +msgstr "arquivo .mpy com arquitetura nativa incompatível" #: py/objstr.c msgid "incomplete format" @@ -3301,7 +3301,7 @@ msgstr "o intervalo deve estar entre %s-%s" #: py/compile.c msgid "invalid architecture" -msgstr "" +msgstr "arquitetura inválida" #: lib/netutils/netutils.c msgid "invalid arguments" From 9b5d131bf69ba962d42adbfdd8188f86c6bbd409 Mon Sep 17 00:00:00 2001 From: Jonny Bergdahl Date: Wed, 28 Apr 2021 07:05:55 +0000 Subject: [PATCH 071/103] Translated using Weblate (Swedish) Currently translated at 100.0% (972 of 972 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/sv/ --- locale/sv.po | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/locale/sv.po b/locale/sv.po index afa32f410a..7cee54cd84 100644 --- a/locale/sv.po +++ b/locale/sv.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2021-04-24 14:29+0000\n" +"PO-Revision-Date: 2021-04-28 16:11+0000\n" "Last-Translator: Jonny Bergdahl \n" "Language-Team: LANGUAGE \n" "Language: sv\n" @@ -3139,11 +3139,11 @@ msgstr "identifieraren omdefinierad som icke-lokal" #: py/persistentcode.c msgid "incompatible .mpy file" -msgstr "" +msgstr "inkompatibel .mpy-fil" #: py/persistentcode.c msgid "incompatible native .mpy architecture" -msgstr "" +msgstr "inkompatibel nativ .mpy-arkitektur" #: py/objstr.c msgid "incomplete format" @@ -3266,7 +3266,7 @@ msgstr "interval måste vara i intervallet %s-%s" #: py/compile.c msgid "invalid architecture" -msgstr "" +msgstr "ogiltig arkitektur" #: lib/netutils/netutils.c msgid "invalid arguments" From 9cd255a55d40121c2322ea75fb85050a91125d6a Mon Sep 17 00:00:00 2001 From: Hosted Weblate Date: Wed, 28 Apr 2021 18:11:43 +0200 Subject: [PATCH 072/103] Update translation files Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/ --- locale/ID.po | 5 ++++- locale/cs.po | 5 ++++- locale/de_DE.po | 5 ++++- locale/el.po | 5 ++++- locale/en_GB.po | 5 ++++- locale/es.po | 5 ++++- locale/fil.po | 5 ++++- locale/fr.po | 5 ++++- locale/hi.po | 5 ++++- locale/it_IT.po | 5 ++++- locale/ja.po | 5 ++++- locale/ko.po | 5 ++++- locale/nl.po | 5 ++++- locale/pl.po | 5 ++++- locale/pt_BR.po | 5 ++++- locale/sv.po | 5 ++++- locale/zh_Latn_pinyin.po | 5 ++++- 17 files changed, 68 insertions(+), 17 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index 8653094ab4..ac07d1544d 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -698,6 +698,7 @@ msgstr "" "digunakan" #: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge. Only level." msgstr "" @@ -1307,7 +1308,8 @@ msgstr "Fase tidak valid" #: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c #: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c -#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c +#: ports/esp32s2/common-hal/touchio/TouchIn.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c #: shared-module/rgbmatrix/RGBMatrix.c msgid "Invalid pin" msgstr "Pin tidak valid" @@ -1690,6 +1692,7 @@ msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" #: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c +#: ports/nrf/common-hal/alarm/time/TimeAlarm.c msgid "Only one alarm.time alarm can be set." msgstr "" diff --git a/locale/cs.po b/locale/cs.po index dab2eb901a..5c1d1d77ba 100644 --- a/locale/cs.po +++ b/locale/cs.po @@ -684,6 +684,7 @@ msgid "Cannot vary frequency on a timer that is already in use" msgstr "" #: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge. Only level." msgstr "" @@ -1288,7 +1289,8 @@ msgstr "" #: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c #: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c -#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c +#: ports/esp32s2/common-hal/touchio/TouchIn.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c #: shared-module/rgbmatrix/RGBMatrix.c msgid "Invalid pin" msgstr "" @@ -1666,6 +1668,7 @@ msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" #: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c +#: ports/nrf/common-hal/alarm/time/TimeAlarm.c msgid "Only one alarm.time alarm can be set." msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index d8d3727bb6..e71d79d94f 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -694,6 +694,7 @@ msgstr "" "Die Frequenz eines bereits verwendeten Timers kann nicht variiert werden" #: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge. Only level." msgstr "Kann nicht auf Flanke wecken, nur auf Level." @@ -1308,7 +1309,8 @@ msgstr "Ungültige Phase" #: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c #: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c -#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c +#: ports/esp32s2/common-hal/touchio/TouchIn.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c #: shared-module/rgbmatrix/RGBMatrix.c msgid "Invalid pin" msgstr "Ungültiger Pin" @@ -1693,6 +1695,7 @@ msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" #: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c +#: ports/nrf/common-hal/alarm/time/TimeAlarm.c msgid "Only one alarm.time alarm can be set." msgstr "" diff --git a/locale/el.po b/locale/el.po index c2a73c577a..de02ad0ca2 100644 --- a/locale/el.po +++ b/locale/el.po @@ -681,6 +681,7 @@ msgid "Cannot vary frequency on a timer that is already in use" msgstr "" #: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge. Only level." msgstr "" @@ -1285,7 +1286,8 @@ msgstr "" #: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c #: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c -#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c +#: ports/esp32s2/common-hal/touchio/TouchIn.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c #: shared-module/rgbmatrix/RGBMatrix.c msgid "Invalid pin" msgstr "" @@ -1663,6 +1665,7 @@ msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" #: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c +#: ports/nrf/common-hal/alarm/time/TimeAlarm.c msgid "Only one alarm.time alarm can be set." msgstr "" diff --git a/locale/en_GB.po b/locale/en_GB.po index 2f1b10a1f3..d8ddf8f91f 100644 --- a/locale/en_GB.po +++ b/locale/en_GB.po @@ -692,6 +692,7 @@ msgid "Cannot vary frequency on a timer that is already in use" msgstr "Cannot vary frequency on a timer that is already in use" #: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge. Only level." msgstr "Cannot wake on pin edge. Only level." @@ -1302,7 +1303,8 @@ msgstr "Invalid phase" #: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c #: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c -#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c +#: ports/esp32s2/common-hal/touchio/TouchIn.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c #: shared-module/rgbmatrix/RGBMatrix.c msgid "Invalid pin" msgstr "Invalid pin" @@ -1684,6 +1686,7 @@ msgid "Only one TouchAlarm can be set in deep sleep." msgstr "Only one TouchAlarm can be set in deep sleep." #: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c +#: ports/nrf/common-hal/alarm/time/TimeAlarm.c msgid "Only one alarm.time alarm can be set." msgstr "Only one alarm.time alarm can be set." diff --git a/locale/es.po b/locale/es.po index 0bb384dd9d..61ec78ce0f 100644 --- a/locale/es.po +++ b/locale/es.po @@ -701,6 +701,7 @@ msgid "Cannot vary frequency on a timer that is already in use" msgstr "No puede variar la frecuencia en un temporizador que ya está en uso" #: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge. Only level." msgstr "No puede despertar en pin edge, solo en nivel." @@ -1319,7 +1320,8 @@ msgstr "Fase inválida" #: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c #: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c -#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c +#: ports/esp32s2/common-hal/touchio/TouchIn.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c #: shared-module/rgbmatrix/RGBMatrix.c msgid "Invalid pin" msgstr "Pin inválido" @@ -1707,6 +1709,7 @@ msgid "Only one TouchAlarm can be set in deep sleep." msgstr "Solamente una TouchAlarm puede ser configurada durante deep sleep." #: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c +#: ports/nrf/common-hal/alarm/time/TimeAlarm.c msgid "Only one alarm.time alarm can be set." msgstr "Solamente una alarm.time puede ser configurada." diff --git a/locale/fil.po b/locale/fil.po index f5727a9da3..511b273934 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -688,6 +688,7 @@ msgid "Cannot vary frequency on a timer that is already in use" msgstr "" #: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge. Only level." msgstr "" @@ -1300,7 +1301,8 @@ msgstr "Mali ang phase" #: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c #: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c -#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c +#: ports/esp32s2/common-hal/touchio/TouchIn.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c #: shared-module/rgbmatrix/RGBMatrix.c msgid "Invalid pin" msgstr "Mali ang pin" @@ -1681,6 +1683,7 @@ msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" #: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c +#: ports/nrf/common-hal/alarm/time/TimeAlarm.c msgid "Only one alarm.time alarm can be set." msgstr "" diff --git a/locale/fr.po b/locale/fr.po index 7660ce4169..fee1a85a25 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -707,6 +707,7 @@ msgid "Cannot vary frequency on a timer that is already in use" msgstr "Impossible de faire varier la fréquence sur un minuteur déjà utilisée" #: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge. Only level." msgstr "Ne peut reveillé sur le board de broche. Seuleument à niveau." @@ -1331,7 +1332,8 @@ msgstr "Phase invalide" #: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c #: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c -#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c +#: ports/esp32s2/common-hal/touchio/TouchIn.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c #: shared-module/rgbmatrix/RGBMatrix.c msgid "Invalid pin" msgstr "Broche invalide" @@ -1717,6 +1719,7 @@ msgid "Only one TouchAlarm can be set in deep sleep." msgstr "Seulement une TouchAlarm peu être réglée en someil profond." #: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c +#: ports/nrf/common-hal/alarm/time/TimeAlarm.c msgid "Only one alarm.time alarm can be set." msgstr "Seulement une alarme alarm.time peut être réglée." diff --git a/locale/hi.po b/locale/hi.po index 4d23454770..4a4539ba2c 100644 --- a/locale/hi.po +++ b/locale/hi.po @@ -681,6 +681,7 @@ msgid "Cannot vary frequency on a timer that is already in use" msgstr "" #: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge. Only level." msgstr "" @@ -1285,7 +1286,8 @@ msgstr "" #: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c #: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c -#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c +#: ports/esp32s2/common-hal/touchio/TouchIn.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c #: shared-module/rgbmatrix/RGBMatrix.c msgid "Invalid pin" msgstr "" @@ -1663,6 +1665,7 @@ msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" #: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c +#: ports/nrf/common-hal/alarm/time/TimeAlarm.c msgid "Only one alarm.time alarm can be set." msgstr "" diff --git a/locale/it_IT.po b/locale/it_IT.po index e39ad7594f..f641552686 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -698,6 +698,7 @@ msgid "Cannot vary frequency on a timer that is already in use" msgstr "" #: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge. Only level." msgstr "" @@ -1311,7 +1312,8 @@ msgstr "Fase non valida" #: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c #: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c -#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c +#: ports/esp32s2/common-hal/touchio/TouchIn.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c #: shared-module/rgbmatrix/RGBMatrix.c msgid "Invalid pin" msgstr "Pin non valido" @@ -1695,6 +1697,7 @@ msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" #: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c +#: ports/nrf/common-hal/alarm/time/TimeAlarm.c msgid "Only one alarm.time alarm can be set." msgstr "" diff --git a/locale/ja.po b/locale/ja.po index 5df538a05d..c057a9d8a7 100644 --- a/locale/ja.po +++ b/locale/ja.po @@ -690,6 +690,7 @@ msgid "Cannot vary frequency on a timer that is already in use" msgstr "使用中のタイマー上では周波数を変えられません" #: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge. Only level." msgstr "" @@ -1298,7 +1299,8 @@ msgstr "不正なphase" #: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c #: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c -#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c +#: ports/esp32s2/common-hal/touchio/TouchIn.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c #: shared-module/rgbmatrix/RGBMatrix.c msgid "Invalid pin" msgstr "不正なピン" @@ -1678,6 +1680,7 @@ msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" #: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c +#: ports/nrf/common-hal/alarm/time/TimeAlarm.c msgid "Only one alarm.time alarm can be set." msgstr "" diff --git a/locale/ko.po b/locale/ko.po index 06edd419c2..5add85aed8 100644 --- a/locale/ko.po +++ b/locale/ko.po @@ -684,6 +684,7 @@ msgid "Cannot vary frequency on a timer that is already in use" msgstr "" #: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge. Only level." msgstr "" @@ -1288,7 +1289,8 @@ msgstr "단계가 잘못되었습니다" #: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c #: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c -#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c +#: ports/esp32s2/common-hal/touchio/TouchIn.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c #: shared-module/rgbmatrix/RGBMatrix.c msgid "Invalid pin" msgstr "핀이 잘못되었습니다" @@ -1666,6 +1668,7 @@ msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" #: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c +#: ports/nrf/common-hal/alarm/time/TimeAlarm.c msgid "Only one alarm.time alarm can be set." msgstr "" diff --git a/locale/nl.po b/locale/nl.po index 57ff2337b8..3a450d2112 100644 --- a/locale/nl.po +++ b/locale/nl.po @@ -688,6 +688,7 @@ msgid "Cannot vary frequency on a timer that is already in use" msgstr "Kan de frequentie van een timer die al in gebruik is niet variëren" #: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge. Only level." msgstr "" @@ -1299,7 +1300,8 @@ msgstr "Ongeldige fase" #: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c #: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c -#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c +#: ports/esp32s2/common-hal/touchio/TouchIn.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c #: shared-module/rgbmatrix/RGBMatrix.c msgid "Invalid pin" msgstr "Ongeldige pin" @@ -1683,6 +1685,7 @@ msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" #: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c +#: ports/nrf/common-hal/alarm/time/TimeAlarm.c msgid "Only one alarm.time alarm can be set." msgstr "Slechts één alarm.time alarm kan worden ingesteld." diff --git a/locale/pl.po b/locale/pl.po index 984ed10275..1062baf66a 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -688,6 +688,7 @@ msgid "Cannot vary frequency on a timer that is already in use" msgstr "Nie można zmieniać częstotliwości timera, który jest już używany" #: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge. Only level." msgstr "" @@ -1298,7 +1299,8 @@ msgstr "Zła faza" #: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c #: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c -#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c +#: ports/esp32s2/common-hal/touchio/TouchIn.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c #: shared-module/rgbmatrix/RGBMatrix.c msgid "Invalid pin" msgstr "Zła nóżka" @@ -1676,6 +1678,7 @@ msgid "Only one TouchAlarm can be set in deep sleep." msgstr "" #: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c +#: ports/nrf/common-hal/alarm/time/TimeAlarm.c msgid "Only one alarm.time alarm can be set." msgstr "" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 58a706d216..afde2984c1 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -705,6 +705,7 @@ msgid "Cannot vary frequency on a timer that is already in use" msgstr "Não é possível variar a frequência em um timer que já esteja em uso" #: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge. Only level." msgstr "Não é possível acordar (wake) no pino edge. Nível apenas." @@ -1322,7 +1323,8 @@ msgstr "Fase Inválida" #: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c #: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c -#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c +#: ports/esp32s2/common-hal/touchio/TouchIn.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c #: shared-module/rgbmatrix/RGBMatrix.c msgid "Invalid pin" msgstr "Pino inválido" @@ -1707,6 +1709,7 @@ msgid "Only one TouchAlarm can be set in deep sleep." msgstr "Apenas um TouchAlarm pode ser colocado em deep sleep." #: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c +#: ports/nrf/common-hal/alarm/time/TimeAlarm.c msgid "Only one alarm.time alarm can be set." msgstr "Apenas um alarme alarm.time pode ser definido." diff --git a/locale/sv.po b/locale/sv.po index 7cee54cd84..0423871517 100644 --- a/locale/sv.po +++ b/locale/sv.po @@ -694,6 +694,7 @@ msgid "Cannot vary frequency on a timer that is already in use" msgstr "Det går inte att ändra frekvensen på en timer som redan används" #: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge. Only level." msgstr "Kan inte vakna på nivåskift, enbart nivå." @@ -1306,7 +1307,8 @@ msgstr "Ogiltig fas" #: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c #: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c -#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c +#: ports/esp32s2/common-hal/touchio/TouchIn.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c #: shared-module/rgbmatrix/RGBMatrix.c msgid "Invalid pin" msgstr "Ogiltig pinne" @@ -1690,6 +1692,7 @@ msgid "Only one TouchAlarm can be set in deep sleep." msgstr "Endast ett TouchAlarm kan ställas in för djupsömn." #: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c +#: ports/nrf/common-hal/alarm/time/TimeAlarm.c msgid "Only one alarm.time alarm can be set." msgstr "Endast ett alarm.time kan ställas in." diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index 49bf62a3a6..7c7db58dcd 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -695,6 +695,7 @@ msgid "Cannot vary frequency on a timer that is already in use" msgstr "Wúfǎ gēnggǎi yǐ zài shǐyòng de jìshí qì shàng de pínlǜ" #: ports/esp32s2/common-hal/alarm/pin/PinAlarm.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge. Only level." msgstr "wú fǎ zài yǐn jiǎo biān yuán huàn xǐng. jǐn jí bié." @@ -1308,7 +1309,8 @@ msgstr "Jiēduàn wúxiào" #: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/touchio/TouchIn.c #: ports/esp32s2/common-hal/alarm/touch/TouchAlarm.c -#: ports/esp32s2/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c +#: ports/esp32s2/common-hal/touchio/TouchIn.c +#: ports/nrf/common-hal/alarm/pin/PinAlarm.c shared-bindings/pwmio/PWMOut.c #: shared-module/rgbmatrix/RGBMatrix.c msgid "Invalid pin" msgstr "Wúxiào de yǐn jiǎo" @@ -1692,6 +1694,7 @@ msgid "Only one TouchAlarm can be set in deep sleep." msgstr "zhǐ yǒu yí gè chù mō bì kě yǐ shè zhì zài shēn dù shuì mián." #: ports/esp32s2/common-hal/alarm/time/TimeAlarm.c +#: ports/nrf/common-hal/alarm/time/TimeAlarm.c msgid "Only one alarm.time alarm can be set." msgstr "zhǐ néng shè zhì yí gè bào jǐng." From cfac07c1ccf31bc4a0395c0b100b23ef4512b32d Mon Sep 17 00:00:00 2001 From: root Date: Wed, 28 Apr 2021 11:20:13 -0500 Subject: [PATCH 073/103] Wrap pulsein when maxlen is exceeded --- ports/raspberrypi/common-hal/pulseio/PulseIn.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index 8d04981b6c..66e5721eec 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -141,9 +141,16 @@ void common_hal_pulseio_pulsein_interrupt() { } // ignore pulses that are too short if (result <= MAX_PULSE && result > MIN_PULSE) { - self->buffer[buf_index] = (uint16_t) result; - buf_index++; - self->len++; + self->buffer[buf_index] = (uint16_t) result; + if (self->len < self->maxlen) { + self->len++; + } + if (buf_index < self->maxlen) { + buf_index++; + } else { + self->start = 0; + buf_index = 0; + } } } } From 3c49bd6bde1525558def647d0cca3d99ec9fb708 Mon Sep 17 00:00:00 2001 From: jposada202020 <34255413+jposada202020@users.noreply.github.com> Date: Wed, 28 Apr 2021 13:15:09 -0400 Subject: [PATCH 074/103] Update docs/design_guide.rst Co-authored-by: Kattni --- docs/design_guide.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index 4c9ca00521..814962c7c7 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -296,7 +296,7 @@ Renders as: Parameters Documentation ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Although there are different ways to document class and functions definitions in Python, -the following is the prevalent method of doing parameters documentations +the following is the prevalent method of documenting parameters for CircuitPython libraries. When documenting class parameters you should use the following structure: From 69a510edc1b24634e7fd24ae330a1d05d9e08019 Mon Sep 17 00:00:00 2001 From: jposada202020 <34255413+jposada202020@users.noreply.github.com> Date: Wed, 28 Apr 2021 13:15:17 -0400 Subject: [PATCH 075/103] Update docs/design_guide.rst Co-authored-by: Kattni --- docs/design_guide.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index 814962c7c7..7eecc4fe87 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -308,8 +308,8 @@ following structure: param_type ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Type of the parameter. This could be among other `int`, `float`, `str` `bool`, etc. -When referring to different objects in the CircuitPython domain you need to include the reference -by adding a ``~`` before the definition as shown in the following example: +To document an object in the CircuitPython domain, you need to include a ``~`` before the +definition as shown in the following example: .. code-block:: sh From 9fe1751f0195dc705e818322e24a841bf5bd7685 Mon Sep 17 00:00:00 2001 From: jposada202020 <34255413+jposada202020@users.noreply.github.com> Date: Wed, 28 Apr 2021 13:15:28 -0400 Subject: [PATCH 076/103] Update docs/design_guide.rst Co-authored-by: Kattni --- docs/design_guide.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index 7eecc4fe87..81975a2117 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -316,7 +316,7 @@ definition as shown in the following example: :param ~busio.I2C i2c_bus: The I2C bus the DS3231 is connected to. -To include references to CircuitPython modules cookiecutter creates an entry in the +To include references to CircuitPython modules, cookiecutter creates an entry in the intersphinx_mapping entry in the ``conf.py`` file located within the ``docs`` directory. To add different types outside CircuitPython you need to add more definition to intersphinx_mapping:: From 129df1b3f78c62b349cd63a24726d78fae955e9c Mon Sep 17 00:00:00 2001 From: jposada202020 <34255413+jposada202020@users.noreply.github.com> Date: Wed, 28 Apr 2021 13:15:37 -0400 Subject: [PATCH 077/103] Update docs/design_guide.rst Co-authored-by: Kattni --- docs/design_guide.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index 81975a2117..2a5a24d56e 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -317,7 +317,7 @@ definition as shown in the following example: To include references to CircuitPython modules, cookiecutter creates an entry in the -intersphinx_mapping entry in the ``conf.py`` file located within the ``docs`` directory. +intersphinx_mapping section in the ``conf.py`` file located within the ``docs`` directory. To add different types outside CircuitPython you need to add more definition to intersphinx_mapping:: From aa9114254aa3cee6a385a6acf72efd4d200b80c3 Mon Sep 17 00:00:00 2001 From: jposada202020 <34255413+jposada202020@users.noreply.github.com> Date: Wed, 28 Apr 2021 13:15:45 -0400 Subject: [PATCH 078/103] Update docs/design_guide.rst Co-authored-by: Kattni --- docs/design_guide.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index 2a5a24d56e..9da43be431 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -327,7 +327,7 @@ To add different types outside CircuitPython you need to add more definition to "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), } -The inthersphinx_mapping above include reference to the Python, BusDevice and CircuitPython +The intersphinx_mapping above includes references to Python, BusDevice and CircuitPython Documentation From 1950cf66664c1ab83fe226d9907b5cad7bf35a0f Mon Sep 17 00:00:00 2001 From: jposada202020 <34255413+jposada202020@users.noreply.github.com> Date: Wed, 28 Apr 2021 13:15:55 -0400 Subject: [PATCH 079/103] Update docs/design_guide.rst Co-authored-by: Kattni --- docs/design_guide.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index 9da43be431..6ced1b4e17 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -338,7 +338,7 @@ Parameter name used in the class or method definition Parameter_description ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Parameter description. When the parameter defaults to a particular values, it is a good +Parameter description. When the parameter defaults to a particular value, it is good practice to mention this:: :param int pitch: Pitch value for the servo. Defaults to :const:`4500` From ed2980b967768018144e784895b923152124ed5e Mon Sep 17 00:00:00 2001 From: jposada202020 <34255413+jposada202020@users.noreply.github.com> Date: Wed, 28 Apr 2021 13:16:02 -0400 Subject: [PATCH 080/103] Update docs/design_guide.rst Co-authored-by: Kattni --- docs/design_guide.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index 6ced1b4e17..7df3c40b95 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -460,7 +460,7 @@ Renders as: Documentation References to other Libraries ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -When you need to make references to documentation in other libraries you should refer the class using single +When you need to reference documentation in other libraries you should include the class by using single backticks ``:class:`~adafruit_motor.servo.Servo```. You must also add the reference in the ``conf.py`` file in the ``intersphinx_mapping section`` by adding a new entry:: From 8ff29f68db41017e1f16d27468f5ba3d202f16fd Mon Sep 17 00:00:00 2001 From: jposada202020 <34255413+jposada202020@users.noreply.github.com> Date: Wed, 28 Apr 2021 13:16:11 -0400 Subject: [PATCH 081/103] Update docs/design_guide.rst Co-authored-by: Kattni --- docs/design_guide.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index 7df3c40b95..c639be902f 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -307,7 +307,7 @@ following structure: param_type ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Type of the parameter. This could be among other `int`, `float`, `str` `bool`, etc. +The type of the parameter. This could be among other `int`, `float`, `str` `bool`, etc. To document an object in the CircuitPython domain, you need to include a ``~`` before the definition as shown in the following example: From e33bc9f57be32317cdc078e220359c243642dddb Mon Sep 17 00:00:00 2001 From: jposada202020 <34255413+jposada202020@users.noreply.github.com> Date: Wed, 28 Apr 2021 13:16:21 -0400 Subject: [PATCH 082/103] Update docs/design_guide.rst Co-authored-by: Kattni --- docs/design_guide.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index c639be902f..e1e5b83635 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -339,7 +339,7 @@ Parameter name used in the class or method definition Parameter_description ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameter description. When the parameter defaults to a particular value, it is good -practice to mention this:: +practice to include the default:: :param int pitch: Pitch value for the servo. Defaults to :const:`4500` From 71d575f0c4e0b57fa4a2e16b991461f9fb5df526 Mon Sep 17 00:00:00 2001 From: jposada202020 <34255413+jposada202020@users.noreply.github.com> Date: Wed, 28 Apr 2021 13:16:33 -0400 Subject: [PATCH 083/103] Update docs/design_guide.rst Co-authored-by: Kattni --- docs/design_guide.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index e1e5b83635..630203ff5f 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -318,7 +318,7 @@ definition as shown in the following example: To include references to CircuitPython modules, cookiecutter creates an entry in the intersphinx_mapping section in the ``conf.py`` file located within the ``docs`` directory. -To add different types outside CircuitPython you need to add more definition to intersphinx_mapping:: +To add different types outside CircuitPython you need to include them in the intersphinx_mapping:: intersphinx_mapping = { From 9c12b180c843d76067bb5b6471c572bea280a379 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Wed, 28 Apr 2021 13:21:18 -0400 Subject: [PATCH 084/103] title change --- docs/design_guide.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/design_guide.rst b/docs/design_guide.rst index 630203ff5f..a0db2df79f 100644 --- a/docs/design_guide.rst +++ b/docs/design_guide.rst @@ -293,7 +293,7 @@ Renders as: :param int address: The I2C address of the device. Defaults to :const:`0x40` -Parameters Documentation +Documenting Parameters ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Although there are different ways to document class and functions definitions in Python, the following is the prevalent method of documenting parameters @@ -308,7 +308,7 @@ following structure: param_type ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The type of the parameter. This could be among other `int`, `float`, `str` `bool`, etc. -To document an object in the CircuitPython domain, you need to include a ``~`` before the +To document an object in the CircuitPython domain, you need to include a ``~`` before the definition as shown in the following example: .. code-block:: sh From 5c4500dbfab8120bb13e5e5e8e12ba2d5de2fa7d Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Wed, 28 Apr 2021 15:35:15 -0400 Subject: [PATCH 085/103] Fix MP type macros --- ports/nrf/common-hal/alarm/pin/PinAlarm.c | 4 ++-- ports/nrf/common-hal/alarm/time/TimeAlarm.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ports/nrf/common-hal/alarm/pin/PinAlarm.c b/ports/nrf/common-hal/alarm/pin/PinAlarm.c index 59bb4a84a1..3c38cad1ac 100644 --- a/ports/nrf/common-hal/alarm/pin/PinAlarm.c +++ b/ports/nrf/common-hal/alarm/pin/PinAlarm.c @@ -93,7 +93,7 @@ bool alarm_pin_pinalarm_woke_us_up(void) { mp_obj_t alarm_pin_pinalarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *alarms) { // First, check to see if we match any given alarms. for (size_t i = 0; i < n_alarms; i++) { - if (!MP_OBJ_IS_TYPE(alarms[i], &alarm_pin_pinalarm_type)) { + if (!mp_obj_is_type(alarms[i], &alarm_pin_pinalarm_type)) { continue; } alarm_pin_pinalarm_obj_t *alarm = MP_OBJ_TO_PTR(alarms[i]); @@ -197,7 +197,7 @@ void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ob int pin_number = -1; for (size_t i = 0; i < n_alarms; i++) { - if (!MP_OBJ_IS_TYPE(alarms[i], &alarm_pin_pinalarm_type)) { + if (!mp_obj_is_type(alarms[i], &alarm_pin_pinalarm_type)) { continue; } alarm_pin_pinalarm_obj_t *alarm = MP_OBJ_TO_PTR(alarms[i]); diff --git a/ports/nrf/common-hal/alarm/time/TimeAlarm.c b/ports/nrf/common-hal/alarm/time/TimeAlarm.c index 09409e7ce4..6fb1aea1ef 100644 --- a/ports/nrf/common-hal/alarm/time/TimeAlarm.c +++ b/ports/nrf/common-hal/alarm/time/TimeAlarm.c @@ -43,7 +43,7 @@ mp_float_t common_hal_alarm_time_timealarm_get_monotonic_time(alarm_time_timeala mp_obj_t alarm_time_timealarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *alarms) { // First, check to see if we match for (size_t i = 0; i < n_alarms; i++) { - if (MP_OBJ_IS_TYPE(alarms[i], &alarm_time_timealarm_type)) { + if (mp_obj_is_type(alarms[i], &alarm_time_timealarm_type)) { return alarms[i]; } } @@ -82,7 +82,7 @@ void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ wakeup_time_saved = 0; for (size_t i = 0; i < n_alarms; i++) { - if (!MP_OBJ_IS_TYPE(alarms[i], &alarm_time_timealarm_type)) { + if (!mp_obj_is_type(alarms[i], &alarm_time_timealarm_type)) { continue; } if (timealarm_set) { From 8090af07dd360626d0fe6391392641a8eecdecdb Mon Sep 17 00:00:00 2001 From: Seth Kerr Date: Wed, 28 Apr 2021 19:14:45 -0600 Subject: [PATCH 086/103] fix ja build issue --- ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk b/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk index b94a5335eb..514fa40009 100644 --- a/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk +++ b/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk @@ -22,3 +22,6 @@ RELEASE_NEEDS_CLEAN_BUILD = 1 CFLAGS_INLINE_LIMIT = 35 SUPEROPT_VM = 0 endif +ifeq ($(TRANSLATION), ja) +CFLAGS_INLINE_LIMIT = 35 +endif From 555ade7ff3b9fb04c067be4bbdf9d27cc10e8ddd Mon Sep 17 00:00:00 2001 From: Seth Kerr Date: Wed, 28 Apr 2021 20:42:13 -0600 Subject: [PATCH 087/103] final change to ja flags i think --- ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk b/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk index 514fa40009..b46ff6069a 100644 --- a/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk +++ b/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk @@ -23,5 +23,6 @@ CFLAGS_INLINE_LIMIT = 35 SUPEROPT_VM = 0 endif ifeq ($(TRANSLATION), ja) +RELEASE_NEEDS_CLEAN_BUILD = 1 CFLAGS_INLINE_LIMIT = 35 endif From 1b972c51c3bcdbaa517a87f91b20a539e0c6eac3 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Thu, 29 Apr 2021 18:42:36 +0530 Subject: [PATCH 088/103] add authmode class --- ports/esp32s2/common-hal/wifi/Network.c | 35 +++++++----- py/circuitpy_defns.mk | 1 + shared-bindings/wifi/AuthMode.c | 76 +++++++++++++++++++++++++ shared-bindings/wifi/AuthMode.h | 42 ++++++++++++++ 4 files changed, 140 insertions(+), 14 deletions(-) create mode 100644 shared-bindings/wifi/AuthMode.c create mode 100644 shared-bindings/wifi/AuthMode.h diff --git a/ports/esp32s2/common-hal/wifi/Network.c b/ports/esp32s2/common-hal/wifi/Network.c index 49507df0d5..db99f264b6 100644 --- a/ports/esp32s2/common-hal/wifi/Network.c +++ b/ports/esp32s2/common-hal/wifi/Network.c @@ -24,11 +24,11 @@ * THE SOFTWARE. */ -#include "shared-bindings/wifi/Network.h" - #include -#include "py/obj.h" +#include "py/enum.h" +#include "shared-bindings/wifi/Network.h" +#include "shared-bindings/wifi/AuthMode.h" mp_obj_t common_hal_wifi_network_get_ssid(wifi_network_obj_t *self) { const char *cstr = (const char *)self->record.ssid; @@ -56,35 +56,42 @@ mp_obj_t common_hal_wifi_network_get_country(wifi_network_obj_t *self) { } mp_obj_t common_hal_wifi_network_get_authmode(wifi_network_obj_t *self) { - const char *authmode = ""; + uint8_t authmode_mask = 0; switch (self->record.authmode) { case WIFI_AUTH_OPEN: - authmode = "OPEN"; + authmode_mask = (1 << AUTHMODE_OPEN); break; case WIFI_AUTH_WEP: - authmode = "WEP"; + authmode_mask = (1 << AUTHMODE_WEP); break; case WIFI_AUTH_WPA_PSK: - authmode = "WPA_PSK"; + authmode_mask = (1 << AUTHMODE_WPA) | (1 << AUTHMODE_PSK); break; case WIFI_AUTH_WPA2_PSK: - authmode = "WPA2_PSK"; + authmode_mask = (1 << AUTHMODE_WPA2) | (1 << AUTHMODE_PSK); break; case WIFI_AUTH_WPA_WPA2_PSK: - authmode = "WPA_WPA2_PSK"; + authmode_mask = (1 << AUTHMODE_WPA) | (1 << AUTHMODE_WPA2) | (1 << AUTHMODE_PSK); break; case WIFI_AUTH_WPA2_ENTERPRISE: - authmode = "WPA2_ENTERPRISE"; + authmode_mask = (1 << AUTHMODE_WPA2) | (1 << AUTHMODE_ENTERPRISE); break; case WIFI_AUTH_WPA3_PSK: - authmode = "WPA3_PSK"; + authmode_mask = (1 << AUTHMODE_WPA3) | (1 << AUTHMODE_PSK); break; case WIFI_AUTH_WPA2_WPA3_PSK: - authmode = "WPA2_WPA3_PSK"; + authmode_mask = (1 << AUTHMODE_WPA2) | (1 << AUTHMODE_WPA3) | (1 << AUTHMODE_PSK); break; default: - authmode = "UNKNOWN"; break; } - return mp_obj_new_str(authmode, strlen(authmode)); + mp_obj_t authmode_list = mp_obj_new_list(0, NULL); + if (authmode_mask != 0) { + for (uint8_t i = 0; i < 8; i++) { + if ((authmode_mask >> i) & 1) { + mp_obj_list_append(authmode_list, cp_enum_find(&wifi_authmode_type, i)); + } + } + } + return authmode_list; } diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index a080f916f4..41f8d71abd 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -451,6 +451,7 @@ $(filter $(SRC_PATTERNS), \ msgpack/__init__.c \ msgpack/ExtType.c \ supervisor/RunReason.c \ + wifi/AuthMode.c \ ) SRC_BINDINGS_ENUMS += \ diff --git a/shared-bindings/wifi/AuthMode.c b/shared-bindings/wifi/AuthMode.c new file mode 100644 index 0000000000..528fcd4143 --- /dev/null +++ b/shared-bindings/wifi/AuthMode.c @@ -0,0 +1,76 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 microDev + * + * 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 "py/enum.h" + +#include "shared-bindings/wifi/AuthMode.h" + +MAKE_ENUM_VALUE(wifi_authmode_type, authmode, OPEN, AUTHMODE_OPEN); +MAKE_ENUM_VALUE(wifi_authmode_type, authmode, WEP, AUTHMODE_WEP); +MAKE_ENUM_VALUE(wifi_authmode_type, authmode, WPA, AUTHMODE_WPA); +MAKE_ENUM_VALUE(wifi_authmode_type, authmode, WPA2, AUTHMODE_WPA2); +MAKE_ENUM_VALUE(wifi_authmode_type, authmode, WPA3, AUTHMODE_WPA3); +MAKE_ENUM_VALUE(wifi_authmode_type, authmode, PSK, AUTHMODE_PSK); +MAKE_ENUM_VALUE(wifi_authmode_type, authmode, ENTERPRISE, AUTHMODE_ENTERPRISE); + +//| class AuthMode: +//| """The authentication protocols used by WiFi.""" +//| +//| OPEN: object +//| """Open network. No authentication required.""" +//| +//| WEP: object +//| """Wired Equivalent Privacy.""" +//| +//| WPA: object +//| """Wireless Protected Access.""" +//| +//| WPA2: object +//| """Wireless Protected Access 2.""" +//| +//| WPA3: object +//| """Wireless Protected Access 3.""" +//| +//| PSK: object +//| """Pre-shared Key. (password)""" +//| +//| ENTERPRISE: object +//| """Each user has a unique credential.""" +//| +MAKE_ENUM_MAP(wifi_authmode) { + MAKE_ENUM_MAP_ENTRY(authmode, OPEN), + MAKE_ENUM_MAP_ENTRY(authmode, WEP), + MAKE_ENUM_MAP_ENTRY(authmode, WPA), + MAKE_ENUM_MAP_ENTRY(authmode, WPA2), + MAKE_ENUM_MAP_ENTRY(authmode, WPA3), + MAKE_ENUM_MAP_ENTRY(authmode, PSK), + MAKE_ENUM_MAP_ENTRY(authmode, ENTERPRISE), +}; +STATIC MP_DEFINE_CONST_DICT(wifi_authmode_locals_dict, wifi_authmode_locals_table); + +MAKE_PRINTER(wifi, wifi_authmode); + +MAKE_ENUM_TYPE(wifi, AuthMode, wifi_authmode); diff --git a/shared-bindings/wifi/AuthMode.h b/shared-bindings/wifi/AuthMode.h new file mode 100644 index 0000000000..f7056ea97c --- /dev/null +++ b/shared-bindings/wifi/AuthMode.h @@ -0,0 +1,42 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 microDev + * + * 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_SHARED_BINDINGS_WIFI_AUTHMODE_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_AUTHMODE_H + +typedef enum { + AUTHMODE_OPEN, + AUTHMODE_WEP, + AUTHMODE_WPA, + AUTHMODE_WPA2, + AUTHMODE_WPA3, + AUTHMODE_PSK, + AUTHMODE_ENTERPRISE +} wifi_authmode_t; + +extern const mp_obj_type_t wifi_authmode_type; + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_WIFI_AUTHMODE_H From 0bf747870aa9ba8c5332de149457f7624cf4c242 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Thu, 29 Apr 2021 12:41:23 -0400 Subject: [PATCH 089/103] Fixing board definition. --- ports/raspberrypi/boards/adafruit_itsybitsy_rp2040/pins.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ports/raspberrypi/boards/adafruit_itsybitsy_rp2040/pins.c b/ports/raspberrypi/boards/adafruit_itsybitsy_rp2040/pins.c index 5c83bf3d74..792f25c496 100644 --- a/ports/raspberrypi/boards/adafruit_itsybitsy_rp2040/pins.c +++ b/ports/raspberrypi/boards/adafruit_itsybitsy_rp2040/pins.c @@ -29,8 +29,9 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO8) }, { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_GPIO9) }, { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO11) }, - { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO11) }, { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO17) }, { MP_ROM_QSTR(MP_QSTR_NEOPIXEL_POWER), MP_ROM_PTR(&pin_GPIO16) }, From d1e17fdcccb51bf9893695c49c7a7fb01ba10757 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 29 Apr 2021 11:59:11 -0500 Subject: [PATCH 090/103] objtype: Restore our customized behavior of instance_subscr For pixelbuf's [] to be able to call _transmit on the Python subclass, we need to do the subscripting operation specially. --- py/objtype.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/py/objtype.c b/py/objtype.c index 42c616b75e..4a30bf3e29 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -854,7 +854,8 @@ STATIC mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value } mp_obj_class_lookup(&lookup, self->base.type); if (member[0] == MP_OBJ_SENTINEL) { - mp_obj_t ret = mp_obj_subscr(self->subobj[0], index, value); + mp_obj_type_t *subobj_type = mp_obj_get_type(self->subobj[0]); + mp_obj_t ret = subobj_type->subscr(self_in, index, value); // May have called port specific C code. Make sure it didn't mess up the heap. assert_heap_ok(); return ret; From 1ec59cd534d13d418f8c8d7a6375ac1535d0c561 Mon Sep 17 00:00:00 2001 From: DavePutz Date: Thu, 29 Apr 2021 12:38:13 -0500 Subject: [PATCH 091/103] Fix up indentation --- ports/raspberrypi/common-hal/pulseio/PulseIn.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index 66e5721eec..6e0c838d34 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -141,16 +141,16 @@ void common_hal_pulseio_pulsein_interrupt() { } // ignore pulses that are too short if (result <= MAX_PULSE && result > MIN_PULSE) { - self->buffer[buf_index] = (uint16_t) result; - if (self->len < self->maxlen) { - self->len++; + self->buffer[buf_index] = (uint16_t) result; + if (self->len < self->maxlen) { + self->len++; } - if (buf_index < self->maxlen) { - buf_index++; - } else { - self->start = 0; - buf_index = 0; - } + if (buf_index < self->maxlen) { + buf_index++; + } else { + self->start = 0; + buf_index = 0; + } } } } From 4d97680caeadfc068eaa75aa42ac25a8f186c7ce Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Thu, 29 Apr 2021 13:45:39 -0400 Subject: [PATCH 092/103] Fix board definition. --- ports/raspberrypi/boards/adafruit_itsybitsy_rp2040/pins.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/raspberrypi/boards/adafruit_itsybitsy_rp2040/pins.c b/ports/raspberrypi/boards/adafruit_itsybitsy_rp2040/pins.c index 792f25c496..bc8ace4654 100644 --- a/ports/raspberrypi/boards/adafruit_itsybitsy_rp2040/pins.c +++ b/ports/raspberrypi/boards/adafruit_itsybitsy_rp2040/pins.c @@ -23,7 +23,7 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO12) }, { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO5) }, { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO4) }, - { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO14) }, { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_GPIO6) }, { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_GPIO7) }, { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO8) }, @@ -35,7 +35,7 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO17) }, { MP_ROM_QSTR(MP_QSTR_NEOPIXEL_POWER), MP_ROM_PTR(&pin_GPIO16) }, - { MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO13) }, { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, From 6498684f5ea20ccf9696f53af4fdb1f81fdbee2f Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 29 Apr 2021 14:30:31 -0500 Subject: [PATCH 093/103] ignore some pins to reclaim flash space --- .../boards/feather_m0_express/mpconfigboard.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h index 27ea6c72ba..a5c81feaae 100644 --- a/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h +++ b/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.h @@ -27,6 +27,17 @@ #define DEFAULT_UART_BUS_RX (&pin_PA11) #define DEFAULT_UART_BUS_TX (&pin_PA10) +// Other some pins that do not appear in the pinout & are not used internally +// this list is not (yet) exhaustive +#define IGNORE_PIN_PA03 1 +#define IGNORE_PIN_PB01 1 +#define IGNORE_PIN_PB03 1 +#define IGNORE_PIN_PB04 1 +#define IGNORE_PIN_PB05 1 +#define IGNORE_PIN_PB06 1 +#define IGNORE_PIN_PB07 1 +#define IGNORE_PIN_PB12 1 + // USB is always used internally so skip the pin objects for it. #define IGNORE_PIN_PA24 1 #define IGNORE_PIN_PA25 1 From 90bdb252190b1176dc48419458243fefc99ab74b Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 29 Apr 2021 14:30:31 -0500 Subject: [PATCH 094/103] ignore some pins to reclaim flash space --- ports/atmel-samd/boards/snekboard/mpconfigboard.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ports/atmel-samd/boards/snekboard/mpconfigboard.h b/ports/atmel-samd/boards/snekboard/mpconfigboard.h index bea90a0fae..0c9f274c06 100644 --- a/ports/atmel-samd/boards/snekboard/mpconfigboard.h +++ b/ports/atmel-samd/boards/snekboard/mpconfigboard.h @@ -23,6 +23,21 @@ #define DEFAULT_UART_BUS_RX (&pin_PB08) /* ANALOG 1 */ #define DEFAULT_UART_BUS_TX (&pin_PB09) /* ANALOG 2 */ +// Other some pins that do not appear in the pinout & are not used internally +// this list is not (yet) exhaustive +#define IGNORE_PIN_PA01 1 +#define IGNORE_PIN_PA03 1 +#define IGNORE_PIN_PB04 1 +#define IGNORE_PIN_PB05 1 +#define IGNORE_PIN_PB00 1 +#define IGNORE_PIN_PB01 1 +#define IGNORE_PIN_PB02 1 +#define IGNORE_PIN_PB04 1 +#define IGNORE_PIN_PB05 1 +#define IGNORE_PIN_PB06 1 +#define IGNORE_PIN_PB07 1 +#define IGNORE_PIN_PB12 1 + // USB is always used internally so skip the pin objects for it. #define IGNORE_PIN_PA24 1 #define IGNORE_PIN_PA25 1 From 8b611d4b6b958480cbb64ff766258f48dd52679f Mon Sep 17 00:00:00 2001 From: Seth Kerr Date: Thu, 29 Apr 2021 16:45:08 -0600 Subject: [PATCH 095/103] changing mpconfigboard makefile --- .../boards/cp_sapling_m0_revb/mpconfigboard.mk | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk b/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk index b46ff6069a..173327a3af 100644 --- a/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk +++ b/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.mk @@ -11,18 +11,4 @@ LONGINT_IMPL = NONE CIRCUITPY_FULL_BUILD = 0 SUPEROPT_GC = 0 - -CFLAGS_BOARD = --param max-inline-insns-auto=15 -ifeq ($(TRANSLATION), zh_Latn_pinyin) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -endif -ifeq ($(TRANSLATION), de_DE) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 SUPEROPT_VM = 0 -endif -ifeq ($(TRANSLATION), ja) -RELEASE_NEEDS_CLEAN_BUILD = 1 -CFLAGS_INLINE_LIMIT = 35 -endif From 9c1466a33088300f66493190638b558b864debb5 Mon Sep 17 00:00:00 2001 From: nm3210 Date: Fri, 30 Apr 2021 09:37:37 -0400 Subject: [PATCH 096/103] Update Sparkfun Thing Plus RP2040 pins to match board This fixes some missing and incorrectly-assigned pins for the SparkFun Thing Plus RP2040 protoboard so that they actually match what the board says. This also changes the default SPI pins from the SD card pins to the breakout pins on the side of the board. --- .../mpconfigboard.h | 20 ++--- .../boards/sparkfun_thing_plus_rp2040/pins.c | 82 ++++++++++++------- 2 files changed, 64 insertions(+), 38 deletions(-) diff --git a/ports/raspberrypi/boards/sparkfun_thing_plus_rp2040/mpconfigboard.h b/ports/raspberrypi/boards/sparkfun_thing_plus_rp2040/mpconfigboard.h index 6c307ec890..a4a162062a 100644 --- a/ports/raspberrypi/boards/sparkfun_thing_plus_rp2040/mpconfigboard.h +++ b/ports/raspberrypi/boards/sparkfun_thing_plus_rp2040/mpconfigboard.h @@ -1,14 +1,14 @@ #define MICROPY_HW_BOARD_NAME "SparkFun Thing Plus - RP2040" #define MICROPY_HW_MCU_NAME "rp2040" -#define MICROPY_HW_NEOPIXEL (&pin_GPIO8) - -#define DEFAULT_I2C_BUS_SCL (&pin_GPIO7) -#define DEFAULT_I2C_BUS_SDA (&pin_GPIO6) - -#define DEFAULT_SPI_BUS_SCK (&pin_GPIO14) -#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO15) -#define DEFAULT_SPI_BUS_MISO (&pin_GPIO12) - -#define DEFAULT_UART_BUS_RX (&pin_GPIO1) #define DEFAULT_UART_BUS_TX (&pin_GPIO0) +#define DEFAULT_UART_BUS_RX (&pin_GPIO1) + +#define DEFAULT_SPI_BUS_SCK (&pin_GPIO2) +#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO3) +#define DEFAULT_SPI_BUS_MISO (&pin_GPIO4) + +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO6) +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO7) + +#define MICROPY_HW_NEOPIXEL (&pin_GPIO8) diff --git a/ports/raspberrypi/boards/sparkfun_thing_plus_rp2040/pins.c b/ports/raspberrypi/boards/sparkfun_thing_plus_rp2040/pins.c index 8f63a9bdf2..72ae577ec2 100644 --- a/ports/raspberrypi/boards/sparkfun_thing_plus_rp2040/pins.c +++ b/ports/raspberrypi/boards/sparkfun_thing_plus_rp2040/pins.c @@ -1,37 +1,63 @@ #include "shared-bindings/board/__init__.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) }, - { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, - { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) }, - { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) }, - { MP_ROM_QSTR(MP_QSTR_D24), MP_ROM_PTR(&pin_GPIO24) }, - { MP_ROM_QSTR(MP_QSTR_D25), MP_ROM_PTR(&pin_GPIO25) }, - { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO14) }, - { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO15) }, - { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO12) }, - { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO1) }, - { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO1) }, - { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO0) }, - { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO0) }, - { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO2) }, - + // Left side breakouts, top-to-bottom, as labeled + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO6) }, { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO6) }, + + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_D23), MP_ROM_PTR(&pin_GPIO7) }, // GPIO7 & GPIO23 are shorted together { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO7) }, - { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO3) }, - { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO8) }, - { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_GPIO9) }, - { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO10) }, - { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_GPIO11) }, - { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO12) }, - { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO13) }, - { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO25) }, - + + { MP_ROM_QSTR(MP_QSTR_D22), MP_ROM_PTR(&pin_GPIO22) }, + { MP_ROM_QSTR(MP_QSTR_D21), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_D20), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_D19), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_GPIO16) }, + + // Right side breakouts, top-to-bottom, as labeled { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO8) }, - { MP_ROM_QSTR(MP_QSTR_SD_CS), MP_ROM_PTR(&pin_GPIO9)}, - - { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, - { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, + + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO0) }, + + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO1) }, + + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO4) }, + + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO3) }, + + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO2) }, + + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) }, + { MP_ROM_QSTR(MP_QSTR_D29), MP_ROM_PTR(&pin_GPIO29) }, + + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_D28), MP_ROM_PTR(&pin_GPIO28) }, + + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_D27), MP_ROM_PTR(&pin_GPIO27) }, + + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_D26), MP_ROM_PTR(&pin_GPIO28) }, + + // SD Card + { MP_ROM_QSTR(MP_QSTR_SD_SCK), MP_ROM_PTR(&pin_GPIO14)}, + { MP_ROM_QSTR(MP_QSTR_SD_MOSI), MP_ROM_PTR(&pin_GPIO15)}, + { MP_ROM_QSTR(MP_QSTR_SD_MISO), MP_ROM_PTR(&pin_GPIO12)}, + { MP_ROM_QSTR(MP_QSTR_SD_CS), MP_ROM_PTR(&pin_GPIO9)}, + + // Others + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO25) }, // on-board LED (separate/additional from neopixel) + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); From 41b273e0c1e379067a2cd4b5e1436f2e39311aae Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 30 Apr 2021 09:17:14 -0500 Subject: [PATCH 097/103] py/vm.c: Restore lost bits of MICROPY_OPT_COMPUTED_GOTO_SAVE_SPACE This fixes a problem where boards that enabled this (most SAM D21s) would crash on the first bytecode instruction. Closes: #4686 --- py/vm.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/py/vm.c b/py/vm.c index 17ac860e6e..14541766ca 100644 --- a/py/vm.c +++ b/py/vm.c @@ -127,11 +127,21 @@ mp_vm_return_kind_t PLACE_IN_ITCM(mp_execute_bytecode)(mp_code_state_t * code_st #endif #if MICROPY_OPT_COMPUTED_GOTO #include "py/vmentrytable.h" + #if MICROPY_OPT_COMPUTED_GOTO_SAVE_SPACE + #define ONE_TRUE_DISPATCH() one_true_dispatch : do { \ + TRACE(ip); \ + MARK_EXC_IP_GLOBAL(); \ + goto *(void *)((char *) && entry_MP_BC_LOAD_CONST_FALSE + entry_table[*ip++]); \ + } while (0) + #define DISPATCH() do { goto one_true_dispatch; } while (0) + #else + #define ONE_TRUE_DISPATCH() DISPATCH() #define DISPATCH() do { \ TRACE(ip); \ MARK_EXC_IP_GLOBAL(); \ goto *entry_table[*ip++]; \ -} while (0) + } while (0) + #endif #define DISPATCH_WITH_PEND_EXC_CHECK() goto pending_exception_check #define ENTRY(op) entry_##op #define ENTRY_DEFAULT entry_default @@ -197,7 +207,7 @@ mp_vm_return_kind_t PLACE_IN_ITCM(mp_execute_bytecode)(mp_code_state_t * code_st for (;;) { dispatch_loop: #if MICROPY_OPT_COMPUTED_GOTO - DISPATCH(); + ONE_TRUE_DISPATCH(); #else TRACE(ip); MARK_EXC_IP_GLOBAL(); From e95e921ca12446a3d0f7ed0e0ebe66582974cb29 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 30 Apr 2021 10:47:37 -0500 Subject: [PATCH 098/103] codeformat: Fix filename matching In #4683, tannewt noticed that uncrustify was not running on some file in common-hal. I investigated and found that it was not being run on a bunch of paths. Rather than make incremental changes, I rewrote list_files to work bsaed on regular expressions; these regular expressions are created from the same git-style glob patterns. I spot-checked some specific filenames after this change, and all looks good: ``` $ python3 tools/codeformat.py -v --dry-run tests/basics/int_small.py ports/raspberrypi/common-hal/pulseio/PulseIn.c extmod/virtpin.c tests/thread/thread_exit1.py ports/raspberrypi/background.h extmod/re1.5/recursiveloop.c tools/codeformat.py -v --dry-run tests/basics/int_small.py ports/raspberrypi/common-hal/pulseio/PulseIn.c extmod/virtpin.c tests/thread/thread_exit1.py ports/raspberrypi/background.h extmod/re1.5/recursiveloop.c uncrustify -c /home/jepler/src/circuitpython/tools/uncrustify.cfg -lC --no-backup extmod/virtpin.c ports/raspberrypi/background.h ports/raspberrypi/common-hal/pulseio/PulseIn.c black --fast --line-length=99 -v tests/thread/thread_exit1.py ``` recursiveloop and int_small are excluded, while PulseIn, virtpin, and background are included. Testing running from a subdirectory (not _specifically_ supported though): ``` (cd ports && python3 ../tools/codeformat.py -v --dry-run raspberrypi/common-hal/pulseio/PulseIn.c ../extmod/virtpin.c) ../tools/codeformat.py -v --dry-run raspberrypi/common-hal/pulseio/PulseIn.c ../extmod/virtpin.c uncrustify -c /home/jepler/src/circuitpython/tools/uncrustify.cfg -lC --no-backup ../extmod/virtpin.c raspberrypi/common-hal/pulseio/PulseIn. ``` As a side-effect, a bunch more files are re-formatted now. :-P --- .../ble_hci/common-hal/_bleio/PacketBuffer.c | 4 +- .../boards/adafruit_slide_trinkey_m0/pins.c | 2 +- .../atmel-samd/common-hal/audioio/AudioOut.c | 110 +- ports/atmel-samd/common-hal/busio/I2C.c | 38 +- ports/atmel-samd/common-hal/busio/SPI.c | 54 +- ports/atmel-samd/common-hal/busio/SPI.h | 2 +- ports/atmel-samd/common-hal/busio/UART.h | 2 +- ports/atmel-samd/common-hal/canio/CAN.c | 42 +- ports/atmel-samd/common-hal/canio/CAN.h | 14 +- ports/atmel-samd/common-hal/canio/Listener.c | 34 +- ports/atmel-samd/common-hal/canio/Listener.h | 6 +- ports/atmel-samd/common-hal/countio/Counter.c | 22 +- ports/atmel-samd/common-hal/countio/Counter.h | 2 +- .../atmel-samd/common-hal/countio/__init__.c | 2 +- .../common-hal/digitalio/DigitalInOut.c | 33 +- .../common-hal/digitalio/DigitalInOut.h | 2 +- .../common-hal/displayio/ParallelBus.h | 4 +- .../imagecapture/ParallelImageCapture.c | 54 +- .../common-hal/neopixel_write/__init__.c | 111 +- ports/atmel-samd/common-hal/nvm/ByteArray.c | 6 +- ports/atmel-samd/common-hal/nvm/ByteArray.h | 2 +- ports/atmel-samd/common-hal/os/__init__.c | 4 +- ports/atmel-samd/common-hal/ps2io/Ps2.c | 55 +- ports/atmel-samd/common-hal/pulseio/PulseIn.h | 2 +- .../atmel-samd/common-hal/pulseio/PulseOut.c | 52 +- ports/atmel-samd/common-hal/pwmio/PWMOut.c | 109 +- ports/atmel-samd/common-hal/pwmio/PWMOut.h | 2 +- .../common-hal/rgbmatrix/RGBMatrix.c | 8 +- .../common-hal/rgbmatrix/RGBMatrix.h | 6 +- .../common-hal/rotaryio/IncrementalEncoder.c | 22 +- ports/atmel-samd/common-hal/rtc/RTC.c | 8 +- ports/atmel-samd/common-hal/sdioio/SDCard.c | 24 +- ports/atmel-samd/common-hal/sdioio/SDCard.h | 2 +- .../common-hal/supervisor/Runtime.c | 4 +- ports/atmel-samd/common-hal/touchio/TouchIn.c | 18 +- ports/atmel-samd/sd_mmc/sd_mmc.c | 2109 ++++++++--------- ports/atmel-samd/sd_mmc/sd_mmc.h | 8 +- ports/atmel-samd/sd_mmc/sd_mmc_protocol.h | 337 ++- ports/atmel-samd/supervisor/internal_flash.c | 18 +- ports/atmel-samd/supervisor/port.c | 183 +- ports/atmel-samd/supervisor/qspi_flash.c | 114 +- ports/atmel-samd/supervisor/usb.c | 8 +- .../esp32s2/boards/adafruit_funhouse/board.c | 10 +- .../boards/adafruit_funhouse/mpconfigboard.h | 2 +- ports/esp32s2/boards/artisense_rd00/board.c | 4 +- .../boards/artisense_rd00/mpconfigboard.h | 4 +- .../esp32s2/boards/atmegazero_esp32s2/board.c | 4 +- .../boards/atmegazero_esp32s2/mpconfigboard.h | 2 +- ports/mimxrt10xx/common-hal/pwmio/PWMOut.c | 12 +- .../peripherals/mimxrt10xx/periph.h | 10 +- ports/nrf/common-hal/alarm/__init__.c | 148 +- ports/nrf/common-hal/alarm/pin/PinAlarm.c | 64 +- ports/nrf/common-hal/alarm/time/TimeAlarm.c | 6 +- ports/nrf/common-hal/alarm/touch/TouchAlarm.c | 2 +- ports/nrf/common-hal/countio/Counter.c | 18 +- ports/nrf/common-hal/countio/__init__.c | 2 +- .../common-hal/microcontroller/Processor.c | 28 +- .../common-hal/rotaryio/IncrementalEncoder.c | 4 +- ports/nrf/supervisor/debug_uart.c | 141 +- ports/nrf/supervisor/port.c | 4 +- ports/nrf/supervisor/qspi_flash.c | 60 +- .../boards/sparkfun_micromod_rp2040/pins.c | 2 +- ports/raspberrypi/common-hal/busio/I2C.c | 2 +- .../imagecapture/ParallelImageCapture.c | 28 +- .../raspberrypi/common-hal/pulseio/PulseIn.c | 10 +- .../common-hal/rp2pio/StateMachine.c | 2 +- ports/stm/common-hal/audiopwmio/PWMAudioOut.c | 28 +- ports/stm/common-hal/pwmio/PWMOut.c | 2 +- ports/unix/coverage-frzmpy/frzmpy1.py | 2 +- .../coverage-frzmpy/frzmpy_pkg1/__init__.py | 2 +- ports/unix/coverage-frzmpy/frzmpy_pkg2/mod.py | 4 +- ports/unix/coverage-frzstr/frzstr1.py | 2 +- .../coverage-frzstr/frzstr_pkg1/__init__.py | 2 +- ports/unix/coverage-frzstr/frzstr_pkg2/mod.py | 4 +- supervisor/shared/external_flash/spi_flash.c | 2 +- tools/codeformat.py | 75 +- 76 files changed, 2179 insertions(+), 2152 deletions(-) mode change 100755 => 100644 ports/atmel-samd/common-hal/supervisor/Runtime.c diff --git a/devices/ble_hci/common-hal/_bleio/PacketBuffer.c b/devices/ble_hci/common-hal/_bleio/PacketBuffer.c index cb14f4044b..a282cdce46 100644 --- a/devices/ble_hci/common-hal/_bleio/PacketBuffer.c +++ b/devices/ble_hci/common-hal/_bleio/PacketBuffer.c @@ -245,8 +245,8 @@ mp_int_t common_hal_bleio_packet_buffer_get_outgoing_packet_length(bleio_packet_ bleio_connection_internal_t *connection = bleio_conn_handle_to_connection(self->conn_handle); if (connection) { return MIN(MIN(common_hal_bleio_connection_get_max_packet_length(connection), - self->max_packet_size), - self->characteristic->max_length); + self->max_packet_size), + self->characteristic->max_length); } } // There's no current connection, so we don't know the MTU, and diff --git a/ports/atmel-samd/boards/adafruit_slide_trinkey_m0/pins.c b/ports/atmel-samd/boards/adafruit_slide_trinkey_m0/pins.c index c48c69206a..238610ddc2 100644 --- a/ports/atmel-samd/boards/adafruit_slide_trinkey_m0/pins.c +++ b/ports/atmel-samd/boards/adafruit_slide_trinkey_m0/pins.c @@ -1,7 +1,7 @@ #include "shared-bindings/board/__init__.h" STATIC const mp_rom_map_elem_t board_global_dict_table[] = { - //{ MP_ROM_QSTR(MP_QSTR_TOUCH), MP_ROM_PTR(&pin_PA07) }, + // { MP_ROM_QSTR(MP_QSTR_TOUCH), MP_ROM_PTR(&pin_PA07) }, { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA06) }, { MP_ROM_QSTR(MP_QSTR_POTENTIOMETER), MP_ROM_PTR(&pin_PA07) }, }; diff --git a/ports/atmel-samd/common-hal/audioio/AudioOut.c b/ports/atmel-samd/common-hal/audioio/AudioOut.c index 34b718dca8..5c1a02634b 100644 --- a/ports/atmel-samd/common-hal/audioio/AudioOut.c +++ b/ports/atmel-samd/common-hal/audioio/AudioOut.c @@ -57,7 +57,7 @@ #ifdef SAMD21 static void ramp_value(uint16_t start, uint16_t end) { start = DAC->DATA.reg; - int32_t diff = (int32_t) end - start; + int32_t diff = (int32_t)end - start; int32_t step = 49; int32_t steps = diff / step; if (diff < 0) { @@ -76,7 +76,7 @@ static void ramp_value(uint16_t start, uint16_t end) { #ifdef SAM_D5X_E5X static void ramp_value(uint16_t start, uint16_t end) { - int32_t diff = (int32_t) end - start; + int32_t diff = (int32_t)end - start; int32_t step = 49; int32_t steps = diff / step; if (diff < 0) { @@ -102,10 +102,12 @@ void audioout_reset(void) { return; #endif #ifdef SAMD21 - while (DAC->STATUS.reg & DAC_STATUS_SYNCBUSY) {} + while (DAC->STATUS.reg & DAC_STATUS_SYNCBUSY) { + } #endif #ifdef SAM_D5X_E5X - while (DAC->SYNCBUSY.reg & DAC_SYNCBUSY_SWRST) {} + while (DAC->SYNCBUSY.reg & DAC_SYNCBUSY_SWRST) { + } #endif if (DAC->CTRLA.bit.ENABLE) { ramp_value(0x8000, 0); @@ -116,8 +118,8 @@ void audioout_reset(void) { } // Caller validates that pins are free. -void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self, - const mcu_pin_obj_t* left_channel, const mcu_pin_obj_t* right_channel, uint16_t quiescent_value) { +void common_hal_audioio_audioout_construct(audioio_audioout_obj_t *self, + const mcu_pin_obj_t *left_channel, const mcu_pin_obj_t *right_channel, uint16_t quiescent_value) { #ifdef SAM_D5X_E5X bool dac_clock_enabled = hri_mclk_get_APBDMASK_DAC_bit(MCLK); #endif @@ -174,7 +176,8 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self, _gclk_enable_channel(DAC_GCLK_ID, CONF_GCLK_DAC_SRC); DAC->CTRLA.bit.SWRST = 1; - while (DAC->CTRLA.bit.SWRST == 1) {} + while (DAC->CTRLA.bit.SWRST == 1) { + } // Make sure there are no outstanding access errors. (Reading DATA can cause this.) #ifdef SAM_D5X_E5X PAC->INTFLAGD.reg = PAC_INTFLAGD_DAC; @@ -191,15 +194,15 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self, DAC->EVCTRL.reg |= DAC_EVCTRL_STARTEI; // We disable the voltage pump because we always run at 3.3v. DAC->CTRLB.reg = DAC_CTRLB_REFSEL_AVCC | - DAC_CTRLB_LEFTADJ | - DAC_CTRLB_EOEN | - DAC_CTRLB_VPD; + DAC_CTRLB_LEFTADJ | + DAC_CTRLB_EOEN | + DAC_CTRLB_VPD; #endif #ifdef SAM_D5X_E5X DAC->EVCTRL.reg |= DAC_EVCTRL_STARTEI0; DAC->DACCTRL[0].reg = DAC_DACCTRL_CCTRL_CC12M | - DAC_DACCTRL_ENABLE | - DAC_DACCTRL_LEFTADJ; + DAC_DACCTRL_ENABLE | + DAC_DACCTRL_LEFTADJ; DAC->CTRLB.reg = DAC_CTRLB_REFSEL_VREFPU; #endif } @@ -207,8 +210,8 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self, if (channel1_enabled) { DAC->EVCTRL.reg |= DAC_EVCTRL_STARTEI1; DAC->DACCTRL[1].reg = DAC_DACCTRL_CCTRL_CC12M | - DAC_DACCTRL_ENABLE | - DAC_DACCTRL_LEFTADJ; + DAC_DACCTRL_ENABLE | + DAC_DACCTRL_LEFTADJ; DAC->CTRLB.reg = DAC_CTRLB_REFSEL_VREFPU; } #endif @@ -216,12 +219,16 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self, // Re-enable the DAC DAC->CTRLA.bit.ENABLE = 1; #ifdef SAMD21 - while (DAC->STATUS.bit.SYNCBUSY == 1) {} + while (DAC->STATUS.bit.SYNCBUSY == 1) { + } #endif #ifdef SAM_D5X_E5X - while (DAC->SYNCBUSY.bit.ENABLE == 1) {} - while (channel0_enabled && DAC->STATUS.bit.READY0 == 0) {} - while (channel1_enabled && DAC->STATUS.bit.READY1 == 0) {} + while (DAC->SYNCBUSY.bit.ENABLE == 1) { + } + while (channel0_enabled && DAC->STATUS.bit.READY0 == 0) { + } + while (channel1_enabled && DAC->STATUS.bit.READY1 == 0) { + } #endif // Use a timer to coordinate when DAC conversions occur. @@ -302,11 +309,11 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self, // Leave the DMA setup to playback. } -bool common_hal_audioio_audioout_deinited(audioio_audioout_obj_t* self) { +bool common_hal_audioio_audioout_deinited(audioio_audioout_obj_t *self) { return self->left_channel == NULL; } -void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t* self) { +void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t *self) { if (common_hal_audioio_audioout_deinited(self)) { return; } @@ -320,10 +327,12 @@ void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t* self) { DAC->CTRLA.bit.ENABLE = 0; #ifdef SAMD21 - while (DAC->STATUS.bit.SYNCBUSY == 1) {} + while (DAC->STATUS.bit.SYNCBUSY == 1) { + } #endif #ifdef SAM_D5X_E5X - while (DAC->SYNCBUSY.bit.ENABLE == 1) {} + while (DAC->SYNCBUSY.bit.ENABLE == 1) { + } #endif disable_event_channel(self->tc_to_dac_event_channel); @@ -338,7 +347,7 @@ void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t* self) { #endif } -static void set_timer_frequency(Tc* timer, uint32_t frequency) { +static void set_timer_frequency(Tc *timer, uint32_t frequency) { uint32_t system_clock = 48000000; uint32_t new_top; uint8_t new_divisor; @@ -359,8 +368,8 @@ static void set_timer_frequency(Tc* timer, uint32_t frequency) { tc_wait_for_sync(timer); } -void common_hal_audioio_audioout_play(audioio_audioout_obj_t* self, - mp_obj_t sample, bool loop) { +void common_hal_audioio_audioout_play(audioio_audioout_obj_t *self, + mp_obj_t sample, bool loop) { if (common_hal_audioio_audioout_get_playing(self)) { common_hal_audioio_audioout_stop(self); } @@ -377,40 +386,40 @@ void common_hal_audioio_audioout_play(audioio_audioout_obj_t* self, } #ifdef SAMD21 result = audio_dma_setup_playback(&self->left_dma, sample, loop, true, 0, - false /* output unsigned */, - (uint32_t) &DAC->DATABUF.reg, - DAC_DMAC_ID_EMPTY); + false /* output unsigned */, + (uint32_t)&DAC->DATABUF.reg, + DAC_DMAC_ID_EMPTY); #endif #ifdef SAM_D5X_E5X - uint32_t left_channel_reg = (uint32_t) &DAC->DATABUF[0].reg; + uint32_t left_channel_reg = (uint32_t)&DAC->DATABUF[0].reg; uint8_t tc_trig_id = TC0_DMAC_ID_OVF + 3 * self->tc_index; uint8_t left_channel_trigger = tc_trig_id; uint32_t right_channel_reg = 0; uint8_t right_channel_trigger = tc_trig_id; if (self->left_channel == &pin_PA05) { - left_channel_reg = (uint32_t) &DAC->DATABUF[1].reg; + left_channel_reg = (uint32_t)&DAC->DATABUF[1].reg; } else if (self->right_channel == &pin_PA05) { - right_channel_reg = (uint32_t) &DAC->DATABUF[1].reg; + right_channel_reg = (uint32_t)&DAC->DATABUF[1].reg; } if (self->right_channel == &pin_PA02) { - right_channel_reg = (uint32_t) &DAC->DATABUF[0].reg; + right_channel_reg = (uint32_t)&DAC->DATABUF[0].reg; } - if(right_channel_reg == left_channel_reg + 2 && audiosample_bits_per_sample(sample) == 16) { + if (right_channel_reg == left_channel_reg + 2 && audiosample_bits_per_sample(sample) == 16) { result = audio_dma_setup_playback(&self->left_dma, sample, loop, false, 0, - false /* output unsigned */, - left_channel_reg, - left_channel_trigger); + false /* output unsigned */, + left_channel_reg, + left_channel_trigger); } else { result = audio_dma_setup_playback(&self->left_dma, sample, loop, true, 0, - false /* output unsigned */, - left_channel_reg, - left_channel_trigger); + false /* output unsigned */, + left_channel_reg, + left_channel_trigger); if (right_channel_reg != 0 && result == AUDIO_DMA_OK) { result = audio_dma_setup_playback(&self->right_dma, sample, loop, true, 1, - false /* output unsigned */, - right_channel_reg, - right_channel_trigger); + false /* output unsigned */, + right_channel_reg, + right_channel_trigger); } } #endif @@ -425,21 +434,22 @@ void common_hal_audioio_audioout_play(audioio_audioout_obj_t* self, mp_raise_RuntimeError(translate("Unable to allocate buffers for signed conversion")); } } - Tc* timer = tc_insts[self->tc_index]; + Tc *timer = tc_insts[self->tc_index]; set_timer_frequency(timer, audiosample_sample_rate(sample)); timer->COUNT16.CTRLBSET.reg = TC_CTRLBSET_CMD_RETRIGGER; - while (timer->COUNT16.STATUS.bit.STOP == 1) {} + while (timer->COUNT16.STATUS.bit.STOP == 1) { + } self->playing = true; } -void common_hal_audioio_audioout_pause(audioio_audioout_obj_t* self) { +void common_hal_audioio_audioout_pause(audioio_audioout_obj_t *self) { audio_dma_pause(&self->left_dma); #ifdef SAM_D5X_E5X audio_dma_pause(&self->right_dma); #endif } -void common_hal_audioio_audioout_resume(audioio_audioout_obj_t* self) { +void common_hal_audioio_audioout_resume(audioio_audioout_obj_t *self) { // Clear any overrun/underrun errors #ifdef SAMD21 DAC->INTFLAG.reg = DAC_INTFLAG_UNDERRUN; @@ -454,12 +464,12 @@ void common_hal_audioio_audioout_resume(audioio_audioout_obj_t* self) { #endif } -bool common_hal_audioio_audioout_get_paused(audioio_audioout_obj_t* self) { +bool common_hal_audioio_audioout_get_paused(audioio_audioout_obj_t *self) { return audio_dma_get_paused(&self->left_dma); } -void common_hal_audioio_audioout_stop(audioio_audioout_obj_t* self) { - Tc* timer = tc_insts[self->tc_index]; +void common_hal_audioio_audioout_stop(audioio_audioout_obj_t *self) { + Tc *timer = tc_insts[self->tc_index]; timer->COUNT16.CTRLBSET.reg = TC_CTRLBSET_CMD_STOP; audio_dma_stop(&self->left_dma); #ifdef SAM_D5X_E5X @@ -470,7 +480,7 @@ void common_hal_audioio_audioout_stop(audioio_audioout_obj_t* self) { ramp_value(self->quiescent_value, self->quiescent_value); } -bool common_hal_audioio_audioout_get_playing(audioio_audioout_obj_t* self) { +bool common_hal_audioio_audioout_get_playing(audioio_audioout_obj_t *self) { bool now_playing = audio_dma_get_playing(&self->left_dma); if (self->playing && !now_playing) { common_hal_audioio_audioout_stop(self); diff --git a/ports/atmel-samd/common-hal/busio/I2C.c b/ports/atmel-samd/common-hal/busio/I2C.c index 2551f7bf17..f7b8807976 100644 --- a/ports/atmel-samd/common-hal/busio/I2C.c +++ b/ports/atmel-samd/common-hal/busio/I2C.c @@ -41,8 +41,8 @@ // Number of times to try to send packet if failed. #define ATTEMPTS 2 -Sercom *samd_i2c_get_sercom(const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, - uint8_t *sercom_index, uint32_t *sda_pinmux, uint32_t *scl_pinmux) { +Sercom *samd_i2c_get_sercom(const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, + uint8_t *sercom_index, uint32_t *sda_pinmux, uint32_t *scl_pinmux) { *sda_pinmux = 0; *scl_pinmux = 0; for (int i = 0; i < NUM_SERCOMS_PER_PIN; i++) { @@ -50,7 +50,7 @@ Sercom *samd_i2c_get_sercom(const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, if (*sercom_index >= SERCOM_INST_NUM) { continue; } - Sercom* potential_sercom = sercom_insts[*sercom_index]; + Sercom *potential_sercom = sercom_insts[*sercom_index]; if (potential_sercom->I2CM.CTRLA.bit.ENABLE != 0 || sda->sercom[i].pad != 0) { continue; @@ -68,15 +68,15 @@ Sercom *samd_i2c_get_sercom(const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, } void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, - const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, uint32_t frequency, uint32_t timeout) { + const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, uint32_t frequency, uint32_t timeout) { uint8_t sercom_index; uint32_t sda_pinmux, scl_pinmux; - Sercom* sercom = samd_i2c_get_sercom(scl, sda, &sercom_index, &sda_pinmux, &scl_pinmux); + Sercom *sercom = samd_i2c_get_sercom(scl, sda, &sercom_index, &sda_pinmux, &scl_pinmux); if (sercom == NULL) { mp_raise_ValueError(translate("Invalid pins")); } -#if CIRCUITPY_REQUIRE_I2C_PULLUPS + #if CIRCUITPY_REQUIRE_I2C_PULLUPS // Test that the pins are in a high state. (Hopefully indicating they are pulled up.) gpio_set_pin_function(sda->number, GPIO_PIN_FUNCTION_OFF); gpio_set_pin_function(scl->number, GPIO_PIN_FUNCTION_OFF); @@ -99,7 +99,7 @@ void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, reset_pin_number(scl->number); mp_raise_RuntimeError(translate("No pull up found on SDA or SCL; check your wiring")); } -#endif + #endif gpio_set_pin_function(sda->number, sda_pinmux); gpio_set_pin_function(scl->number, scl_pinmux); @@ -164,10 +164,10 @@ bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) { bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) { bool grabbed_lock = false; CRITICAL_SECTION_ENTER() - if (!self->has_lock) { - grabbed_lock = true; - self->has_lock = true; - } + if (!self->has_lock) { + grabbed_lock = true; + self->has_lock = true; + } CRITICAL_SECTION_LEAVE(); return grabbed_lock; } @@ -181,7 +181,7 @@ void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) { } uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr, - const uint8_t *data, size_t len, bool transmit_stop_bit) { + const uint8_t *data, size_t len, bool transmit_stop_bit) { uint16_t attempts = ATTEMPTS; int32_t status; @@ -189,8 +189,8 @@ uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr, struct _i2c_m_msg msg; msg.addr = addr; msg.len = len; - msg.flags = transmit_stop_bit ? I2C_M_STOP : 0; - msg.buffer = (uint8_t *) data; + msg.flags = transmit_stop_bit ? I2C_M_STOP : 0; + msg.buffer = (uint8_t *)data; status = _i2c_m_sync_transfer(&self->i2c_desc.device, &msg); // Give up after ATTEMPTS tries. @@ -207,16 +207,16 @@ uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr, } uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, uint16_t addr, - uint8_t *data, size_t len) { + uint8_t *data, size_t len) { uint16_t attempts = ATTEMPTS; int32_t status; do { struct _i2c_m_msg msg; - msg.addr = addr; - msg.len = len; - msg.flags = I2C_M_STOP | I2C_M_RD; - msg.buffer = data; + msg.addr = addr; + msg.len = len; + msg.flags = I2C_M_STOP | I2C_M_RD; + msg.buffer = data; status = _i2c_m_sync_transfer(&self->i2c_desc.device, &msg); // Give up after ATTEMPTS tries. diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c index 9646f9cf1e..7b4034d156 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.c +++ b/ports/atmel-samd/common-hal/busio/SPI.c @@ -43,7 +43,7 @@ bool never_reset_sercoms[SERCOM_INST_NUM]; -void never_reset_sercom(Sercom* sercom) { +void never_reset_sercom(Sercom *sercom) { // Reset all SERCOMs except the ones being used by on-board devices. Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS; for (int i = 0; i < SERCOM_INST_NUM; i++) { @@ -54,7 +54,7 @@ void never_reset_sercom(Sercom* sercom) { } } -void allow_reset_sercom(Sercom* sercom) { +void allow_reset_sercom(Sercom *sercom) { // Reset all SERCOMs except the ones being used by on-board devices. Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS; for (int i = 0; i < SERCOM_INST_NUM; i++) { @@ -72,11 +72,11 @@ void reset_sercoms(void) { if (never_reset_sercoms[i]) { continue; } - #ifdef MICROPY_HW_APA102_SERCOM + #ifdef MICROPY_HW_APA102_SERCOM if (sercom_instances[i] == MICROPY_HW_APA102_SERCOM) { continue; } - #endif + #endif // SWRST is same for all modes of SERCOMs. sercom_instances[i]->SPI.CTRLA.bit.SWRST = 1; } @@ -84,9 +84,9 @@ void reset_sercoms(void) { void common_hal_busio_spi_construct(busio_spi_obj_t *self, - const mcu_pin_obj_t * clock, const mcu_pin_obj_t * mosi, - const mcu_pin_obj_t * miso) { - Sercom* sercom = NULL; + const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, + const mcu_pin_obj_t *miso) { + Sercom *sercom = NULL; uint8_t sercom_index; uint32_t clock_pinmux = 0; bool mosi_none = mosi == NULL; @@ -121,16 +121,16 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, if (sercom_index >= SERCOM_INST_NUM) { continue; } - Sercom* potential_sercom = sercom_insts[sercom_index]; + Sercom *potential_sercom = sercom_insts[sercom_index]; if ( - #if defined(MICROPY_HW_APA102_SCK) && defined(MICROPY_HW_APA102_MOSI) && !CIRCUITPY_BITBANG_APA102 + #if defined(MICROPY_HW_APA102_SCK) && defined(MICROPY_HW_APA102_MOSI) && !CIRCUITPY_BITBANG_APA102 (potential_sercom->SPI.CTRLA.bit.ENABLE != 0 && potential_sercom != status_apa102.spi_desc.dev.prvt && !apa102_sck_in_use) - #else + #else potential_sercom->SPI.CTRLA.bit.ENABLE != 0 - #endif - ) { + #endif + ) { continue; } clock_pinmux = PINMUX(clock->number, (i == 0) ? MUX_C : MUX_D); @@ -172,7 +172,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, if (sercom != NULL) { break; } - } + } } if (sercom == NULL) { mp_raise_ValueError(translate("Invalid pins")); @@ -259,10 +259,10 @@ void common_hal_busio_spi_deinit(busio_spi_obj_t *self) { } bool common_hal_busio_spi_configure(busio_spi_obj_t *self, - uint32_t baudrate, uint8_t polarity, uint8_t phase, uint8_t bits) { + uint32_t baudrate, uint8_t polarity, uint8_t phase, uint8_t bits) { uint8_t baud_reg_value = samd_peripherals_spi_baudrate_to_baud_reg_value(baudrate); - void * hw = self->spi_desc.dev.prvt; + void *hw = self->spi_desc.dev.prvt; // If the settings are already what we want then don't reset them. if (hri_sercomspi_get_CTRLA_CPHA_bit(hw) == phase && hri_sercomspi_get_CTRLA_CPOL_bit(hw) == polarity && @@ -290,10 +290,10 @@ bool common_hal_busio_spi_configure(busio_spi_obj_t *self, bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) { bool grabbed_lock = false; CRITICAL_SECTION_ENTER() - if (!self->has_lock) { - grabbed_lock = true; - self->has_lock = true; - } + if (!self->has_lock) { + grabbed_lock = true; + self->has_lock = true; + } CRITICAL_SECTION_LEAVE(); return grabbed_lock; } @@ -307,7 +307,7 @@ void common_hal_busio_spi_unlock(busio_spi_obj_t *self) { } bool common_hal_busio_spi_write(busio_spi_obj_t *self, - const uint8_t *data, size_t len) { + const uint8_t *data, size_t len) { if (len == 0) { return true; } @@ -323,7 +323,7 @@ bool common_hal_busio_spi_write(busio_spi_obj_t *self, } bool common_hal_busio_spi_read(busio_spi_obj_t *self, - uint8_t *data, size_t len, uint8_t write_value) { + uint8_t *data, size_t len, uint8_t write_value) { if (len == 0) { return true; } @@ -350,7 +350,7 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, const uint8_t *data_ou status = sercom_dma_transfer(self->spi_desc.dev.prvt, data_out, data_in, len); } else { struct spi_xfer xfer; - xfer.txbuf = (uint8_t*) data_out; + xfer.txbuf = (uint8_t *)data_out; xfer.rxbuf = data_in; xfer.size = len; status = spi_m_sync_transfer(&self->spi_desc, &xfer); @@ -358,16 +358,16 @@ bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, const uint8_t *data_ou return status >= 0; // Status is number of chars read or an error code < 0. } -uint32_t common_hal_busio_spi_get_frequency(busio_spi_obj_t* self) { +uint32_t common_hal_busio_spi_get_frequency(busio_spi_obj_t *self) { return samd_peripherals_spi_baud_reg_value_to_baudrate(hri_sercomspi_read_BAUD_reg(self->spi_desc.dev.prvt)); } -uint8_t common_hal_busio_spi_get_phase(busio_spi_obj_t* self) { - void * hw = self->spi_desc.dev.prvt; +uint8_t common_hal_busio_spi_get_phase(busio_spi_obj_t *self) { + void *hw = self->spi_desc.dev.prvt; return hri_sercomspi_get_CTRLA_CPHA_bit(hw); } -uint8_t common_hal_busio_spi_get_polarity(busio_spi_obj_t* self) { - void * hw = self->spi_desc.dev.prvt; +uint8_t common_hal_busio_spi_get_polarity(busio_spi_obj_t *self) { + void *hw = self->spi_desc.dev.prvt; return hri_sercomspi_get_CTRLA_CPOL_bit(hw); } diff --git a/ports/atmel-samd/common-hal/busio/SPI.h b/ports/atmel-samd/common-hal/busio/SPI.h index a1c0e15179..27bbfdeb3a 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.h +++ b/ports/atmel-samd/common-hal/busio/SPI.h @@ -43,7 +43,7 @@ typedef struct { } busio_spi_obj_t; void reset_sercoms(void); -void never_reset_sercom(Sercom* sercom); +void never_reset_sercom(Sercom *sercom); #endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H diff --git a/ports/atmel-samd/common-hal/busio/UART.h b/ports/atmel-samd/common-hal/busio/UART.h index f94df040f8..c95fbf1556 100644 --- a/ports/atmel-samd/common-hal/busio/UART.h +++ b/ports/atmel-samd/common-hal/busio/UART.h @@ -43,7 +43,7 @@ typedef struct { uint32_t baudrate; uint32_t timeout_ms; uint32_t buffer_length; - uint8_t* buffer; + uint8_t *buffer; } busio_uart_obj_t; #endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_UART_H diff --git a/ports/atmel-samd/common-hal/canio/CAN.c b/ports/atmel-samd/common-hal/canio/CAN.c index 76599a9a7b..2ad292195d 100644 --- a/ports/atmel-samd/common-hal/canio/CAN.c +++ b/ports/atmel-samd/common-hal/canio/CAN.c @@ -40,15 +40,14 @@ #include "genhdr/candata.h" -STATIC Can * const can_insts[] = CAN_INSTS; +STATIC Can *const can_insts[] = CAN_INSTS; STATIC canio_can_obj_t *can_objs[MP_ARRAY_SIZE(can_insts)]; // This must be placed in the first 64kB of RAM STATIC COMPILER_SECTION(".canram") canio_can_state_t can_state[MP_ARRAY_SIZE(can_insts)]; -void common_hal_canio_can_construct(canio_can_obj_t *self, mcu_pin_obj_t *tx, mcu_pin_obj_t *rx, int baudrate, bool loopback, bool silent) -{ +void common_hal_canio_can_construct(canio_can_obj_t *self, mcu_pin_obj_t *tx, mcu_pin_obj_t *rx, int baudrate, bool loopback, bool silent) { mcu_pin_function_t *tx_function = mcu_find_pin_function(can_tx, tx, -1, MP_QSTR_tx); int instance = tx_function->instance; @@ -56,7 +55,7 @@ void common_hal_canio_can_construct(canio_can_obj_t *self, mcu_pin_obj_t *tx, mc const uint32_t can_frequency = CONF_CAN0_FREQUENCY; -#define DIV_ROUND(a, b) (((a) + (b)/2) / (b)) +#define DIV_ROUND(a, b) (((a) + (b) / 2) / (b)) #define DIV_ROUND_UP(a, b) (((a) + (b) - 1) / (b)) uint32_t clocks_per_bit = DIV_ROUND(can_frequency, baudrate); @@ -97,7 +96,7 @@ void common_hal_canio_can_construct(canio_can_obj_t *self, mcu_pin_obj_t *tx, mc NVIC_ClearPendingIRQ(CAN0_IRQn); NVIC_EnableIRQ(CAN0_IRQn); hri_can_write_ILE_reg(self->hw, CAN_ILE_EINT0); -#ifdef CAN1_GCLK_ID + #ifdef CAN1_GCLK_ID } else if (instance == 1) { hri_mclk_set_AHBMASK_CAN1_bit(MCLK); hri_gclk_write_PCHCTRL_reg(GCLK, CAN1_GCLK_ID, CONF_GCLK_CAN1_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos)); @@ -106,7 +105,7 @@ void common_hal_canio_can_construct(canio_can_obj_t *self, mcu_pin_obj_t *tx, mc NVIC_ClearPendingIRQ(CAN1_IRQn); NVIC_EnableIRQ(CAN1_IRQn); hri_can_write_ILE_reg(self->hw, CAN_ILE_EINT0); -#endif + #endif } self->hw->CCCR.bit.FDOE = 0; // neither FD nor Bit Rate Switch enabled @@ -237,12 +236,12 @@ void common_hal_canio_can_construct(canio_can_obj_t *self, mcu_pin_obj_t *tx, mc NVIC_DisableIRQ(CAN0_IRQn); NVIC_ClearPendingIRQ(CAN0_IRQn); NVIC_EnableIRQ(CAN0_IRQn); -#ifdef CAN1_GCLK_ID + #ifdef CAN1_GCLK_ID } else if (instance == 1) { NVIC_DisableIRQ(CAN1_IRQn); NVIC_ClearPendingIRQ(CAN1_IRQn); NVIC_EnableIRQ(CAN1_IRQn); -#endif + #endif } hri_can_write_ILE_reg(self->hw, CAN_ILE_EINT0); @@ -255,23 +254,19 @@ void common_hal_canio_can_construct(canio_can_obj_t *self, mcu_pin_obj_t *tx, mc can_objs[instance] = self; } -bool common_hal_canio_can_loopback_get(canio_can_obj_t *self) -{ +bool common_hal_canio_can_loopback_get(canio_can_obj_t *self) { return self->loopback; } -int common_hal_canio_can_baudrate_get(canio_can_obj_t *self) -{ +int common_hal_canio_can_baudrate_get(canio_can_obj_t *self) { return self->baudrate; } -int common_hal_canio_can_transmit_error_count_get(canio_can_obj_t *self) -{ +int common_hal_canio_can_transmit_error_count_get(canio_can_obj_t *self) { return self->hw->ECR.bit.TEC; } -int common_hal_canio_can_receive_error_count_get(canio_can_obj_t *self) -{ +int common_hal_canio_can_receive_error_count_get(canio_can_obj_t *self) { return self->hw->ECR.bit.REC; } @@ -313,11 +308,11 @@ static void maybe_auto_restart(canio_can_obj_t *self) { } } -void common_hal_canio_can_send(canio_can_obj_t *self, mp_obj_t message_in) -{ +void common_hal_canio_can_send(canio_can_obj_t *self, mp_obj_t message_in) { maybe_auto_restart(self); - canio_message_obj_t *message = message_in;; + canio_message_obj_t *message = message_in; + ; // We have just one dedicated TX buffer, use it! canio_can_tx_buffer_t *ent = &self->state->tx_buffer[0]; @@ -365,8 +360,7 @@ void common_hal_canio_can_check_for_deinit(canio_can_obj_t *self) { } } -void common_hal_canio_can_deinit(canio_can_obj_t *self) -{ +void common_hal_canio_can_deinit(canio_can_obj_t *self) { if (self->hw) { hri_can_set_CCCR_INIT_bit(self->hw); self->hw = 0; @@ -384,11 +378,11 @@ void common_hal_canio_can_deinit(canio_can_obj_t *self) void common_hal_canio_reset(void) { memset(can_state, 0, sizeof(can_state)); - for (size_t i=0; iextended) { continue; } @@ -89,13 +89,13 @@ STATIC size_t num_filters_needed(size_t nmatch, canio_match_obj_t **matches, boo STATIC size_t num_filters_available(canio_can_obj_t *can, bool extended) { size_t available = 0; if (extended) { - for(size_t i = 0; i < MP_ARRAY_SIZE(can->state->extended_rx_filter); i++) { + for (size_t i = 0; i < MP_ARRAY_SIZE(can->state->extended_rx_filter); i++) { if (!extended_filter_in_use(&can->state->extended_rx_filter[i])) { available++; } } } else { - for(size_t i = 0; i < MP_ARRAY_SIZE(can->state->standard_rx_filter); i++) { + for (size_t i = 0; i < MP_ARRAY_SIZE(can->state->standard_rx_filter); i++) { if (!standard_filter_in_use(&can->state->standard_rx_filter[i])) { available++; } @@ -119,13 +119,13 @@ STATIC void clear_filters(canio_listener_obj_t *self) { prevent_config_change(can); // For each filter entry, if it pointed at this FIFO set it to DISABLE - for(size_t i = 0; i < MP_ARRAY_SIZE(can->state->extended_rx_filter); i++) { + for (size_t i = 0; i < MP_ARRAY_SIZE(can->state->extended_rx_filter); i++) { int val = CAN_XIDFE_0_EFEC_STF0M_Val + fifo; if (can->state->extended_rx_filter[i].XIDFE_0.bit.EFEC == val) { can->state->extended_rx_filter[i].XIDFE_0.bit.EFEC = CAN_XIDFE_0_EFEC_DISABLE_Val; } } - for(size_t i = 0; i < MP_ARRAY_SIZE(can->state->standard_rx_filter); i++) { + for (size_t i = 0; i < MP_ARRAY_SIZE(can->state->standard_rx_filter); i++) { int val = CAN_SIDFE_0_SFEC_STF1M_Val + fifo; if (can->state->standard_rx_filter[i].SIDFE_0.bit.SFEC == val) { can->state->standard_rx_filter[i].SIDFE_0.bit.SFEC = CAN_SIDFE_0_SFEC_DISABLE_Val; @@ -212,7 +212,7 @@ void set_filters(canio_listener_obj_t *self, size_t nmatch, canio_match_obj_t ** // step 1: single id standard matches // we have to gather up pairs and stuff them in a single filter entry - for(size_t i = 0; iextended) { continue; @@ -230,13 +230,13 @@ void set_filters(canio_listener_obj_t *self, size_t nmatch, canio_match_obj_t ** } // step 1.5. odd single id standard match if (first_id != NO_ID) { - install_standard_filter(standard, first_id, first_id, CAN_SIDFE_0_SFEC_STF0M_Val + fifo, CAN_SIDFE_0_SFT_DUAL_Val); - standard = next_standard_filter(self, standard); - first_id = NO_ID; + install_standard_filter(standard, first_id, first_id, CAN_SIDFE_0_SFEC_STF0M_Val + fifo, CAN_SIDFE_0_SFT_DUAL_Val); + standard = next_standard_filter(self, standard); + first_id = NO_ID; } // step 2: standard mask filter - for(size_t i = 0; iextended) { continue; @@ -250,7 +250,7 @@ void set_filters(canio_listener_obj_t *self, size_t nmatch, canio_match_obj_t ** // step 3: single id extended matches // we have to gather up pairs and stuff them in a single filter entry - for(size_t i = 0; iextended) { continue; @@ -268,13 +268,13 @@ void set_filters(canio_listener_obj_t *self, size_t nmatch, canio_match_obj_t ** } // step 3.5. odd single id standard match if (first_id != NO_ID) { - install_extended_filter(extended, first_id, first_id, CAN_XIDFE_0_EFEC_STF0M_Val + fifo, CAN_XIDFE_1_EFT_DUAL_Val); - extended = next_extended_filter(self, extended); - first_id = NO_ID; + install_extended_filter(extended, first_id, first_id, CAN_XIDFE_0_EFEC_STF0M_Val + fifo, CAN_XIDFE_1_EFT_DUAL_Val); + extended = next_extended_filter(self, extended); + first_id = NO_ID; } // step 4: extended mask filters - for(size_t i = 0; iextended) { continue; @@ -294,13 +294,13 @@ void common_hal_canio_listener_construct(canio_listener_obj_t *self, canio_can_o if (!can->fifo0_in_use) { self->fifo_idx = 0; self->fifo = can->state->rx0_fifo; - self->hw = (canio_rxfifo_reg_t*)&can->hw->RXF0C; + self->hw = (canio_rxfifo_reg_t *)&can->hw->RXF0C; can->hw->IR.reg = CAN_IR_RF0N | CAN_IR_RF0W | CAN_IR_RF0F | CAN_IR_RF0L; can->fifo0_in_use = true; } else if (!can->fifo1_in_use) { self->fifo_idx = 1; self->fifo = can->state->rx1_fifo; - self->hw = (canio_rxfifo_reg_t*)&can->hw->RXF1C; + self->hw = (canio_rxfifo_reg_t *)&can->hw->RXF1C; can->fifo1_in_use = true; can->hw->IR.reg = CAN_IR_RF1N | CAN_IR_RF1W | CAN_IR_RF1F | CAN_IR_RF1L; } else { diff --git a/ports/atmel-samd/common-hal/canio/Listener.h b/ports/atmel-samd/common-hal/canio/Listener.h index 237dca870d..be19bd84fb 100644 --- a/ports/atmel-samd/common-hal/canio/Listener.h +++ b/ports/atmel-samd/common-hal/canio/Listener.h @@ -30,9 +30,9 @@ #include "shared-module/canio/Match.h" typedef struct { - __IO CAN_RXF0C_Type RXFC; /**< \brief (R/W 32) Rx FIFO n Configuration */ - __I CAN_RXF0S_Type RXFS; /**< \brief (R/ 32) Rx FIFO n Status */ - __IO CAN_RXF0A_Type RXFA; /**< \brief (R/W 32) Rx FIFO n Acknowledge */ + __IO CAN_RXF0C_Type RXFC; /**< \brief (R/W 32) Rx FIFO n Configuration */ + __I CAN_RXF0S_Type RXFS; /**< \brief (R/ 32) Rx FIFO n Status */ + __IO CAN_RXF0A_Type RXFA; /**< \brief (R/W 32) Rx FIFO n Acknowledge */ } canio_rxfifo_reg_t; typedef struct canio_listener_obj { diff --git a/ports/atmel-samd/common-hal/countio/Counter.c b/ports/atmel-samd/common-hal/countio/Counter.c index d2e3fae630..4531a4ed8c 100644 --- a/ports/atmel-samd/common-hal/countio/Counter.c +++ b/ports/atmel-samd/common-hal/countio/Counter.c @@ -8,8 +8,8 @@ #include "py/runtime.h" #include "supervisor/shared/translate.h" -void common_hal_countio_counter_construct(countio_counter_obj_t* self, - const mcu_pin_obj_t* pin_a) { +void common_hal_countio_counter_construct(countio_counter_obj_t *self, + const mcu_pin_obj_t *pin_a) { if (!pin_a->has_extint) { mp_raise_RuntimeError(translate("Pin must support hardware interrupts")); } @@ -31,7 +31,7 @@ void common_hal_countio_counter_construct(countio_counter_obj_t* self, gpio_set_pin_function(self->pin_a, GPIO_PIN_FUNCTION_A); gpio_set_pin_pull_mode(self->pin_a, GPIO_PULL_UP); - set_eic_channel_data(self->eic_channel_a, (void*) self); + set_eic_channel_data(self->eic_channel_a, (void *)self); self->count = 0; @@ -44,11 +44,11 @@ void common_hal_countio_counter_construct(countio_counter_obj_t* self, } -bool common_hal_countio_counter_deinited(countio_counter_obj_t* self) { +bool common_hal_countio_counter_deinited(countio_counter_obj_t *self) { return self->pin_a == NO_PIN; } -void common_hal_countio_counter_deinit(countio_counter_obj_t* self) { +void common_hal_countio_counter_deinit(countio_counter_obj_t *self) { if (common_hal_countio_counter_deinited(self)) { return; } @@ -62,21 +62,21 @@ void common_hal_countio_counter_deinit(countio_counter_obj_t* self) { } -mp_int_t common_hal_countio_counter_get_count(countio_counter_obj_t* self) { +mp_int_t common_hal_countio_counter_get_count(countio_counter_obj_t *self) { return self->count; } -void common_hal_countio_counter_set_count(countio_counter_obj_t* self, - mp_int_t new_count) { +void common_hal_countio_counter_set_count(countio_counter_obj_t *self, + mp_int_t new_count) { self->count = new_count; } -void common_hal_countio_counter_reset(countio_counter_obj_t* self){ - self->count = 0; +void common_hal_countio_counter_reset(countio_counter_obj_t *self) { + self->count = 0; } void counter_interrupt_handler(uint8_t channel) { - countio_counter_obj_t* self = get_eic_channel_data(channel); + countio_counter_obj_t *self = get_eic_channel_data(channel); self->count += 1; diff --git a/ports/atmel-samd/common-hal/countio/Counter.h b/ports/atmel-samd/common-hal/countio/Counter.h index 724c734152..8af22253f9 100644 --- a/ports/atmel-samd/common-hal/countio/Counter.h +++ b/ports/atmel-samd/common-hal/countio/Counter.h @@ -9,7 +9,7 @@ typedef struct { mp_obj_base_t base; uint8_t pin_a; - uint8_t eic_channel_a:4; + uint8_t eic_channel_a : 4; mp_int_t count; } countio_counter_obj_t; diff --git a/ports/atmel-samd/common-hal/countio/__init__.c b/ports/atmel-samd/common-hal/countio/__init__.c index b95b20d153..d47de33e53 100644 --- a/ports/atmel-samd/common-hal/countio/__init__.c +++ b/ports/atmel-samd/common-hal/countio/__init__.c @@ -1 +1 @@ -//No countio module functions +// No countio module functions diff --git a/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c b/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c index e37769c157..40637bef4b 100644 --- a/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c +++ b/ports/atmel-samd/common-hal/digitalio/DigitalInOut.c @@ -37,7 +37,7 @@ #include "supervisor/shared/translate.h" digitalinout_result_t common_hal_digitalio_digitalinout_construct( - digitalio_digitalinout_obj_t* self, const mcu_pin_obj_t* pin) { + digitalio_digitalinout_obj_t *self, const mcu_pin_obj_t *pin) { claim_pin(pin); self->pin = pin; self->output = false; @@ -50,15 +50,15 @@ digitalinout_result_t common_hal_digitalio_digitalinout_construct( } void common_hal_digitalio_digitalinout_never_reset( - digitalio_digitalinout_obj_t *self) { + digitalio_digitalinout_obj_t *self) { never_reset_pin_number(self->pin->number); } -bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t* self) { +bool common_hal_digitalio_digitalinout_deinited(digitalio_digitalinout_obj_t *self) { return self->pin == NULL; } -void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t* self) { +void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t *self) { if (common_hal_digitalio_digitalinout_deinited(self)) { return; } @@ -67,15 +67,15 @@ void common_hal_digitalio_digitalinout_deinit(digitalio_digitalinout_obj_t* self } void common_hal_digitalio_digitalinout_switch_to_input( - digitalio_digitalinout_obj_t* self, digitalio_pull_t pull) { + digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { self->output = false; // This also sets direction to input. common_hal_digitalio_digitalinout_set_pull(self, pull); } digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( - digitalio_digitalinout_obj_t* self, bool value, - digitalio_drive_mode_t drive_mode) { + digitalio_digitalinout_obj_t *self, bool value, + digitalio_drive_mode_t drive_mode) { const uint8_t pin = self->pin->number; gpio_set_pin_pull_mode(pin, GPIO_PULL_OFF); // Turn on "strong" pin driving (more current available). See DRVSTR doc in datasheet. @@ -90,12 +90,12 @@ digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( } digitalio_direction_t common_hal_digitalio_digitalinout_get_direction( - digitalio_digitalinout_obj_t* self) { + digitalio_digitalinout_obj_t *self) { return self->output ? DIRECTION_OUTPUT : DIRECTION_INPUT; } void common_hal_digitalio_digitalinout_set_value( - digitalio_digitalinout_obj_t* self, bool value) { + digitalio_digitalinout_obj_t *self, bool value) { const uint8_t pin = self->pin->number; const uint8_t port = GPIO_PORT(pin); const uint32_t pin_mask = 1U << GPIO_PIN(pin); @@ -116,7 +116,7 @@ void common_hal_digitalio_digitalinout_set_value( } bool common_hal_digitalio_digitalinout_get_value( - digitalio_digitalinout_obj_t* self) { + digitalio_digitalinout_obj_t *self) { const uint8_t pin = self->pin->number; if (!self->output) { return gpio_get_pin_level(pin); @@ -130,8 +130,8 @@ bool common_hal_digitalio_digitalinout_get_value( } digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode( - digitalio_digitalinout_obj_t* self, - digitalio_drive_mode_t drive_mode) { + digitalio_digitalinout_obj_t *self, + digitalio_drive_mode_t drive_mode) { bool value = common_hal_digitalio_digitalinout_get_value(self); self->open_drain = drive_mode == DRIVE_MODE_OPEN_DRAIN; // True is implemented differently between modes so reset the value to make @@ -143,7 +143,7 @@ digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode( } digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode( - digitalio_digitalinout_obj_t* self) { + digitalio_digitalinout_obj_t *self) { if (self->open_drain) { return DRIVE_MODE_OPEN_DRAIN; } else { @@ -152,7 +152,7 @@ digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode( } void common_hal_digitalio_digitalinout_set_pull( - digitalio_digitalinout_obj_t* self, digitalio_pull_t pull) { + digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { enum gpio_pull_mode asf_pull = GPIO_PULL_OFF; switch (pull) { case PULL_UP: @@ -171,7 +171,7 @@ void common_hal_digitalio_digitalinout_set_pull( } digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( - digitalio_digitalinout_obj_t* self) { + digitalio_digitalinout_obj_t *self) { uint32_t pin = self->pin->number; if (self->output) { mp_raise_AttributeError(translate("Cannot get pull while in output mode")); @@ -179,7 +179,8 @@ digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( } else { if (hri_port_get_PINCFG_PULLEN_bit(PORT, GPIO_PORT(pin), GPIO_PIN(pin)) == 0) { return PULL_NONE; - } if (hri_port_get_OUT_reg(PORT, GPIO_PORT(pin), 1U << GPIO_PIN(pin)) > 0) { + } + if (hri_port_get_OUT_reg(PORT, GPIO_PORT(pin), 1U << GPIO_PIN(pin)) > 0) { return PULL_UP; } else { return PULL_DOWN; diff --git a/ports/atmel-samd/common-hal/digitalio/DigitalInOut.h b/ports/atmel-samd/common-hal/digitalio/DigitalInOut.h index 4b443d9bce..3e8817e282 100644 --- a/ports/atmel-samd/common-hal/digitalio/DigitalInOut.h +++ b/ports/atmel-samd/common-hal/digitalio/DigitalInOut.h @@ -32,7 +32,7 @@ typedef struct { mp_obj_base_t base; - const mcu_pin_obj_t * pin; + const mcu_pin_obj_t *pin; bool output; bool open_drain; } digitalio_digitalinout_obj_t; diff --git a/ports/atmel-samd/common-hal/displayio/ParallelBus.h b/ports/atmel-samd/common-hal/displayio/ParallelBus.h index 630bec351b..ee19caddf6 100644 --- a/ports/atmel-samd/common-hal/displayio/ParallelBus.h +++ b/ports/atmel-samd/common-hal/displayio/ParallelBus.h @@ -31,14 +31,14 @@ typedef struct { mp_obj_base_t base; - uint8_t* bus; + uint8_t *bus; digitalio_digitalinout_obj_t command; digitalio_digitalinout_obj_t chip_select; digitalio_digitalinout_obj_t reset; digitalio_digitalinout_obj_t write; digitalio_digitalinout_obj_t read; uint8_t data0_pin; - PortGroup* write_group; + PortGroup *write_group; uint32_t write_mask; } displayio_parallelbus_obj_t; diff --git a/ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c b/ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c index 074c2b6d23..2a01057b7f 100644 --- a/ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c +++ b/ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c @@ -54,14 +54,12 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle const mcu_pin_obj_t *data_clock, const mcu_pin_obj_t *vertical_sync, const mcu_pin_obj_t *horizontal_reference, - int data_count) -{ + int data_count) { if (data0->number != PIN_PCC_D0) { mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_data0); } // The peripheral supports 8, 10, 12, or 14 data bits, but the code only supports 8 at present - if (data_count != 8) - { + if (data_count != 8) { mp_raise_ValueError_varg(translate("Invalid data_count %d"), data_count); } if (vertical_sync && vertical_sync->number != PIN_PCC_DEN1) { @@ -74,7 +72,7 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle mp_raise_ValueError_varg(translate("Invalid %q pin"), MP_QSTR_data_clock); } // technically, 0 was validated as free already but check again - for (int i=0; inumber + i)) { mp_raise_ValueError_varg(translate("data pin #%d in use"), i); } @@ -87,8 +85,8 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle // Accumulate 4 bytes into RHR register (two 16-bit pixels) PCC->MR.reg = PCC_MR_CID(0x1) | // Clear on falling DEN1 (VSYNC) - PCC_MR_ISIZE(0x0) | // Input data bus is 8 bits - PCC_MR_DSIZE(0x2); // "4 data" at a time (accumulate in RHR) + PCC_MR_ISIZE(0x0) | // Input data bus is 8 bits + PCC_MR_DSIZE(0x2); // "4 data" at a time (accumulate in RHR) PCC->MR.bit.PCEN = 1; // Enable PCC @@ -100,62 +98,59 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle gpio_set_pin_direction(PIN_PCC_CLK, GPIO_DIRECTION_IN); gpio_set_pin_pull_mode(PIN_PCC_CLK, GPIO_PULL_OFF); gpio_set_pin_function(PIN_PCC_CLK, GPIO_PIN_FUNCTION_PCC); - //claim_pin_number(PIN_PCC_CLK); + // claim_pin_number(PIN_PCC_CLK); if (vertical_sync) { gpio_set_pin_direction(PIN_PCC_DEN1, GPIO_DIRECTION_IN); gpio_set_pin_pull_mode(PIN_PCC_DEN1, GPIO_PULL_OFF); gpio_set_pin_function(PIN_PCC_DEN1, GPIO_PIN_FUNCTION_PCC); // VSYNC - //claim_pin_number(PIN_PCC_DEN1); + // claim_pin_number(PIN_PCC_DEN1); } if (horizontal_reference) { gpio_set_pin_direction(PIN_PCC_DEN2, GPIO_DIRECTION_IN); gpio_set_pin_pull_mode(PIN_PCC_DEN2, GPIO_PULL_OFF); gpio_set_pin_function(PIN_PCC_DEN2, GPIO_PIN_FUNCTION_PCC); // HSYNC - //claim_pin_number(PIN_PCC_DEN2); + // claim_pin_number(PIN_PCC_DEN2); } - for (int i=0; ivertical_sync); reset_pin_number(self->horizontal_reference); reset_pin_number(PIN_PCC_CLK); - for (int i=0; idata_count; i++) { + for (int i = 0; i < self->data_count; i++) { reset_pin_number(PIN_PCC_D0 + i); } self->data_count = 0; } -bool common_hal_imagecapture_parallelimagecapture_deinited(imagecapture_parallelimagecapture_obj_t *self) -{ +bool common_hal_imagecapture_parallelimagecapture_deinited(imagecapture_parallelimagecapture_obj_t *self) { return self->data_count == 0; } -static void setup_dma(DmacDescriptor* descriptor, size_t count, uint32_t *buffer) { +static void setup_dma(DmacDescriptor *descriptor, size_t count, uint32_t *buffer) { descriptor->BTCTRL.reg = DMAC_BTCTRL_VALID | - DMAC_BTCTRL_BLOCKACT_NOACT | - DMAC_BTCTRL_EVOSEL_BLOCK | - DMAC_BTCTRL_DSTINC | - DMAC_BTCTRL_BEATSIZE_WORD; + DMAC_BTCTRL_BLOCKACT_NOACT | + DMAC_BTCTRL_EVOSEL_BLOCK | + DMAC_BTCTRL_DSTINC | + DMAC_BTCTRL_BEATSIZE_WORD; descriptor->BTCNT.reg = count; - descriptor->DSTADDR.reg = (uint32_t)buffer + 4*count; + descriptor->DSTADDR.reg = (uint32_t)buffer + 4 * count; descriptor->SRCADDR.reg = (uint32_t)&PCC->RHR.reg; descriptor->DESCADDR.reg = 0; } #include -void common_hal_imagecapture_parallelimagecapture_capture(imagecapture_parallelimagecapture_obj_t *self, void *buffer, size_t bufsize) -{ +void common_hal_imagecapture_parallelimagecapture_capture(imagecapture_parallelimagecapture_obj_t *self, void *buffer, size_t bufsize) { uint8_t dma_channel = dma_allocate_channel(); @@ -171,8 +166,7 @@ void common_hal_imagecapture_parallelimagecapture_capture(imagecapture_paralleli const volatile uint32_t *vsync_reg = &PORT->Group[(self->vertical_sync / 32)].IN.reg; uint32_t vsync_bit = 1 << (self->vertical_sync % 32); - while (*vsync_reg & vsync_bit) - { + while (*vsync_reg & vsync_bit) { // Wait for VSYNC low (frame end) RUN_BACKGROUND_TASKS; diff --git a/ports/atmel-samd/common-hal/neopixel_write/__init__.c b/ports/atmel-samd/common-hal/neopixel_write/__init__.c index 6f2090b983..4677437f90 100644 --- a/ports/atmel-samd/common-hal/neopixel_write/__init__.c +++ b/ports/atmel-samd/common-hal/neopixel_write/__init__.c @@ -44,71 +44,72 @@ __attribute__((naked,noinline,aligned(16))) static void neopixel_send_buffer_core(volatile uint32_t *clraddr, uint32_t pinMask, - const uint8_t *ptr, int numBytes); + const uint8_t *ptr, int numBytes); static void neopixel_send_buffer_core(volatile uint32_t *clraddr, uint32_t pinMask, - const uint8_t *ptr, int numBytes) { - asm volatile(" push {r4, r5, r6, lr};" - " add r3, r2, r3;" - "loopLoad:" - " ldrb r5, [r2, #0];" // r5 := *ptr - " add r2, #1;" // ptr++ - " movs r4, #128;" // r4-mask, 0x80 - "loopBit:" - " str r1, [r0, #4];" // set - #ifdef SAMD21 - " movs r6, #3; d2: sub r6, #1; bne d2;" // delay 3 - #endif - #ifdef SAM_D5X_E5X - " movs r6, #3; d2: subs r6, #1; bne d2;" // delay 3 - #endif - " tst r4, r5;" // mask&r5 - " bne skipclr;" - " str r1, [r0, #0];" // clr - "skipclr:" - #ifdef SAMD21 - " movs r6, #6; d0: sub r6, #1; bne d0;" // delay 6 - #endif - #ifdef SAM_D5X_E5X - " movs r6, #6; d0: subs r6, #1; bne d0;" // delay 6 - #endif - " str r1, [r0, #0];" // clr (possibly again, doesn't matter) - #ifdef SAMD21 - " asr r4, r4, #1;" // mask >>= 1 - #endif - #ifdef SAM_D5X_E5X - " asrs r4, r4, #1;" // mask >>= 1 - #endif - " beq nextbyte;" - " uxtb r4, r4;" - #ifdef SAMD21 - " movs r6, #2; d1: sub r6, #1; bne d1;" // delay 2 - #endif - #ifdef SAM_D5X_E5X - " movs r6, #2; d1: subs r6, #1; bne d1;" // delay 2 - #endif - " b loopBit;" - "nextbyte:" - " cmp r2, r3;" - " bcs neopixel_stop;" - " b loopLoad;" - "neopixel_stop:" - " pop {r4, r5, r6, pc};" - ""); + const uint8_t *ptr, int numBytes) { + asm volatile (" push {r4, r5, r6, lr};" + " add r3, r2, r3;" + "loopLoad:" + " ldrb r5, [r2, #0];" // r5 := *ptr + " add r2, #1;" // ptr++ + " movs r4, #128;" // r4-mask, 0x80 + "loopBit:" + " str r1, [r0, #4];" // set + #ifdef SAMD21 + " movs r6, #3; d2: sub r6, #1; bne d2;" // delay 3 + #endif + #ifdef SAM_D5X_E5X + " movs r6, #3; d2: subs r6, #1; bne d2;" // delay 3 + #endif + " tst r4, r5;" // mask&r5 + " bne skipclr;" + " str r1, [r0, #0];" // clr + "skipclr:" + #ifdef SAMD21 + " movs r6, #6; d0: sub r6, #1; bne d0;" // delay 6 + #endif + #ifdef SAM_D5X_E5X + " movs r6, #6; d0: subs r6, #1; bne d0;" // delay 6 + #endif + " str r1, [r0, #0];" // clr (possibly again, doesn't matter) + #ifdef SAMD21 + " asr r4, r4, #1;" // mask >>= 1 + #endif + #ifdef SAM_D5X_E5X + " asrs r4, r4, #1;" // mask >>= 1 + #endif + " beq nextbyte;" + " uxtb r4, r4;" + #ifdef SAMD21 + " movs r6, #2; d1: sub r6, #1; bne d1;" // delay 2 + #endif + #ifdef SAM_D5X_E5X + " movs r6, #2; d1: subs r6, #1; bne d1;" // delay 2 + #endif + " b loopBit;" + "nextbyte:" + " cmp r2, r3;" + " bcs neopixel_stop;" + " b loopLoad;" + "neopixel_stop:" + " pop {r4, r5, r6, pc};" + ""); } uint64_t next_start_raw_ticks = 0; -void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout, uint8_t *pixels, uint32_t numBytes) { +void common_hal_neopixel_write(const digitalio_digitalinout_obj_t *digitalinout, uint8_t *pixels, uint32_t numBytes) { // This is adapted directly from the Adafruit NeoPixel library SAMD21G18A code: // https://github.com/adafruit/Adafruit_NeoPixel/blob/master/Adafruit_NeoPixel.cpp // and the asm version from https://github.com/microsoft/uf2-samdx1/blob/master/inc/neopixel.h - uint32_t pinMask; - PortGroup* port; + uint32_t pinMask; + PortGroup *port; // Wait to make sure we don't append onto the last transmission. This should only be a tick or // two. - while (port_get_raw_ticks(NULL) < next_start_raw_ticks) {} + while (port_get_raw_ticks(NULL) < next_start_raw_ticks) { + } // Turn off interrupts of any kind during timing-sensitive code. mp_hal_disable_all_interrupts(); @@ -136,8 +137,8 @@ void common_hal_neopixel_write(const digitalio_digitalinout_obj_t* digitalinout, #endif uint32_t pin = digitalinout->pin->number; - port = &PORT->Group[GPIO_PORT(pin)]; // Convert GPIO # to port register - pinMask = (1UL << (pin % 32)); // From port_pin_set_output_level ASF code. + port = &PORT->Group[GPIO_PORT(pin)]; // Convert GPIO # to port register + pinMask = (1UL << (pin % 32)); // From port_pin_set_output_level ASF code. volatile uint32_t *clr = &(port->OUTCLR.reg); neopixel_send_buffer_core(clr, pinMask, pixels, numBytes); diff --git a/ports/atmel-samd/common-hal/nvm/ByteArray.c b/ports/atmel-samd/common-hal/nvm/ByteArray.c index ac896a9d52..9d711d3413 100644 --- a/ports/atmel-samd/common-hal/nvm/ByteArray.c +++ b/ports/atmel-samd/common-hal/nvm/ByteArray.c @@ -38,18 +38,18 @@ uint32_t common_hal_nvm_bytearray_get_length(nvm_bytearray_obj_t *self) { } bool common_hal_nvm_bytearray_set_bytes(nvm_bytearray_obj_t *self, - uint32_t start_index, uint8_t* values, uint32_t len) { + uint32_t start_index, uint8_t *values, uint32_t len) { // We don't use features that use any advanced NVMCTRL features so we can fake the descriptor // whenever we need it instead of storing it long term. struct flash_descriptor desc; desc.dev.hw = NVMCTRL; - bool status = flash_write(&desc, (uint32_t) self->start_address + start_index, values, len) == ERR_NONE; + bool status = flash_write(&desc, (uint32_t)self->start_address + start_index, values, len) == ERR_NONE; assert_heap_ok(); return status; } // NVM memory is memory mapped so reading it is easy. void common_hal_nvm_bytearray_get_bytes(nvm_bytearray_obj_t *self, - uint32_t start_index, uint32_t len, uint8_t* values) { + uint32_t start_index, uint32_t len, uint8_t *values) { memcpy(values, self->start_address + start_index, len); } diff --git a/ports/atmel-samd/common-hal/nvm/ByteArray.h b/ports/atmel-samd/common-hal/nvm/ByteArray.h index f6a816cb9d..28c6d0e510 100644 --- a/ports/atmel-samd/common-hal/nvm/ByteArray.h +++ b/ports/atmel-samd/common-hal/nvm/ByteArray.h @@ -31,7 +31,7 @@ typedef struct { mp_obj_base_t base; - uint8_t* start_address; + uint8_t *start_address; uint32_t len; } nvm_bytearray_obj_t; diff --git a/ports/atmel-samd/common-hal/os/__init__.c b/ports/atmel-samd/common-hal/os/__init__.c index c151b105a8..6c554bff30 100644 --- a/ports/atmel-samd/common-hal/os/__init__.c +++ b/ports/atmel-samd/common-hal/os/__init__.c @@ -60,13 +60,13 @@ STATIC MP_DEFINE_ATTRTUPLE( (mp_obj_t)&os_uname_info_release_obj, (mp_obj_t)&os_uname_info_version_obj, (mp_obj_t)&os_uname_info_machine_obj -); + ); mp_obj_t common_hal_os_uname(void) { return (mp_obj_t)&os_uname_info_obj; } -bool common_hal_os_urandom(uint8_t* buffer, uint32_t length) { +bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) { #ifdef SAM_D5X_E5X hri_mclk_set_APBCMASK_TRNG_bit(MCLK); struct rand_sync_desc random; diff --git a/ports/atmel-samd/common-hal/ps2io/Ps2.c b/ports/atmel-samd/common-hal/ps2io/Ps2.c index 2579142ad0..f07cadf417 100644 --- a/ports/atmel-samd/common-hal/ps2io/Ps2.c +++ b/ports/atmel-samd/common-hal/ps2io/Ps2.c @@ -63,18 +63,18 @@ #define ERROR_TX_RTS 0x1000 #define ERROR_TX_NORESP 0x2000 -static void ps2_set_config(ps2io_ps2_obj_t* self) { +static void ps2_set_config(ps2io_ps2_obj_t *self) { uint32_t sense_setting = EIC_CONFIG_SENSE0_FALL_Val; set_eic_handler(self->channel, EIC_HANDLER_PS2); turn_on_eic_channel(self->channel, sense_setting); } -static void disable_interrupt(ps2io_ps2_obj_t* self) { +static void disable_interrupt(ps2io_ps2_obj_t *self) { uint32_t mask = 1 << self->channel; EIC->INTENCLR.reg = mask << EIC_INTENSET_EXTINT_Pos; } -static void resume_interrupt(ps2io_ps2_obj_t* self) { +static void resume_interrupt(ps2io_ps2_obj_t *self) { disable_interrupt(self); self->state = STATE_IDLE; @@ -86,14 +86,14 @@ static void resume_interrupt(ps2io_ps2_obj_t* self) { ps2_set_config(self); } -static void clk_hi(ps2io_ps2_obj_t* self) { +static void clk_hi(ps2io_ps2_obj_t *self) { // External pull-up // Must set pull after setting direction. gpio_set_pin_direction(self->clk_pin, GPIO_DIRECTION_IN); gpio_set_pin_pull_mode(self->clk_pin, GPIO_PULL_OFF); } -static bool wait_clk_lo(ps2io_ps2_obj_t* self, uint32_t us) { +static bool wait_clk_lo(ps2io_ps2_obj_t *self, uint32_t us) { clk_hi(self); common_hal_mcu_delay_us(1); while (gpio_get_pin_level(self->clk_pin) && us) { @@ -103,7 +103,7 @@ static bool wait_clk_lo(ps2io_ps2_obj_t* self, uint32_t us) { return us; } -static bool wait_clk_hi(ps2io_ps2_obj_t* self, uint32_t us) { +static bool wait_clk_hi(ps2io_ps2_obj_t *self, uint32_t us) { clk_hi(self); common_hal_mcu_delay_us(1); while (!gpio_get_pin_level(self->clk_pin) && us) { @@ -113,19 +113,19 @@ static bool wait_clk_hi(ps2io_ps2_obj_t* self, uint32_t us) { return us; } -static void clk_lo(ps2io_ps2_obj_t* self) { +static void clk_lo(ps2io_ps2_obj_t *self) { gpio_set_pin_pull_mode(self->clk_pin, GPIO_PULL_OFF); gpio_set_pin_direction(self->clk_pin, GPIO_DIRECTION_OUT); gpio_set_pin_level(self->clk_pin, 0); } -static void data_hi(ps2io_ps2_obj_t* self) { +static void data_hi(ps2io_ps2_obj_t *self) { // External pull-up gpio_set_pin_direction(self->data_pin, GPIO_DIRECTION_IN); gpio_set_pin_pull_mode(self->data_pin, GPIO_PULL_OFF); } -static bool wait_data_lo(ps2io_ps2_obj_t* self, uint32_t us) { +static bool wait_data_lo(ps2io_ps2_obj_t *self, uint32_t us) { data_hi(self); common_hal_mcu_delay_us(1); while (gpio_get_pin_level(self->data_pin) && us) { @@ -135,7 +135,7 @@ static bool wait_data_lo(ps2io_ps2_obj_t* self, uint32_t us) { return us; } -static bool wait_data_hi(ps2io_ps2_obj_t* self, uint32_t us) { +static bool wait_data_hi(ps2io_ps2_obj_t *self, uint32_t us) { data_hi(self); common_hal_mcu_delay_us(1); while (!gpio_get_pin_level(self->data_pin) && us) { @@ -145,18 +145,18 @@ static bool wait_data_hi(ps2io_ps2_obj_t* self, uint32_t us) { return us; } -static void data_lo(ps2io_ps2_obj_t* self) { +static void data_lo(ps2io_ps2_obj_t *self) { gpio_set_pin_pull_mode(self->data_pin, GPIO_PULL_OFF); gpio_set_pin_direction(self->data_pin, GPIO_DIRECTION_OUT); gpio_set_pin_level(self->data_pin, 0); } -static void idle(ps2io_ps2_obj_t* self) { +static void idle(ps2io_ps2_obj_t *self) { clk_hi(self); data_hi(self); } -static void inhibit(ps2io_ps2_obj_t* self) { +static void inhibit(ps2io_ps2_obj_t *self) { clk_lo(self); data_hi(self); } @@ -169,7 +169,7 @@ void ps2_interrupt_handler(uint8_t channel) { // Grab the current time first. uint64_t current_tick = port_get_raw_ticks(NULL); - ps2io_ps2_obj_t* self = get_eic_channel_data(channel); + ps2io_ps2_obj_t *self = get_eic_channel_data(channel); int data_bit = gpio_get_pin_level(self->data_pin) ? 1 : 0; // test for timeout @@ -192,7 +192,7 @@ void ps2_interrupt_handler(uint8_t channel) { // start bit should be 0 self->last_errors |= ERROR_STARTBIT; self->state = STATE_RECV_ERR; - } else { + } else { self->state = STATE_RECV; } @@ -220,7 +220,7 @@ void ps2_interrupt_handler(uint8_t channel) { } else if (self->state == STATE_RECV_STOP) { ++self->bitcount; - if (! data_bit) { + if (!data_bit) { self->last_errors |= ERROR_STOPBIT; } else if (self->waiting_cmd_response) { self->cmd_response = self->bits; @@ -242,8 +242,8 @@ void ps2_interrupt_handler(uint8_t channel) { } } -void common_hal_ps2io_ps2_construct(ps2io_ps2_obj_t* self, - const mcu_pin_obj_t* data_pin, const mcu_pin_obj_t* clk_pin) { +void common_hal_ps2io_ps2_construct(ps2io_ps2_obj_t *self, + const mcu_pin_obj_t *data_pin, const mcu_pin_obj_t *clk_pin) { if (!clk_pin->has_extint) { mp_raise_RuntimeError(translate("No hardware support on clk pin")); } @@ -263,7 +263,7 @@ void common_hal_ps2io_ps2_construct(ps2io_ps2_obj_t* self, self->bufposw = 0; self->waiting_cmd_response = false; - set_eic_channel_data(clk_pin->extint_channel, (void*) self); + set_eic_channel_data(clk_pin->extint_channel, (void *)self); // Check to see if the EIC is enabled and start it up if its not.' if (eic_get_enable() == 0) { @@ -282,11 +282,11 @@ void common_hal_ps2io_ps2_construct(ps2io_ps2_obj_t* self, ps2_set_config(self); } -bool common_hal_ps2io_ps2_deinited(ps2io_ps2_obj_t* self) { +bool common_hal_ps2io_ps2_deinited(ps2io_ps2_obj_t *self) { return self->clk_pin == NO_PIN; } -void common_hal_ps2io_ps2_deinit(ps2io_ps2_obj_t* self) { +void common_hal_ps2io_ps2_deinit(ps2io_ps2_obj_t *self) { if (common_hal_ps2io_ps2_deinited(self)) { return; } @@ -298,17 +298,16 @@ void common_hal_ps2io_ps2_deinit(ps2io_ps2_obj_t* self) { self->data_pin = NO_PIN; } -uint16_t common_hal_ps2io_ps2_get_len(ps2io_ps2_obj_t* self) { +uint16_t common_hal_ps2io_ps2_get_len(ps2io_ps2_obj_t *self) { return self->bufcount; } -bool common_hal_ps2io_ps2_get_paused(ps2io_ps2_obj_t* self) { +bool common_hal_ps2io_ps2_get_paused(ps2io_ps2_obj_t *self) { uint32_t mask = 1 << self->channel; return (EIC->INTENSET.reg & (mask << EIC_INTENSET_EXTINT_Pos)) == 0; } -int16_t common_hal_ps2io_ps2_popleft(ps2io_ps2_obj_t* self) -{ +int16_t common_hal_ps2io_ps2_popleft(ps2io_ps2_obj_t *self) { common_hal_mcu_disable_interrupts(); if (self->bufcount <= 0) { common_hal_mcu_enable_interrupts(); @@ -321,8 +320,7 @@ int16_t common_hal_ps2io_ps2_popleft(ps2io_ps2_obj_t* self) return b; } -uint16_t common_hal_ps2io_ps2_clear_errors(ps2io_ps2_obj_t* self) -{ +uint16_t common_hal_ps2io_ps2_clear_errors(ps2io_ps2_obj_t *self) { common_hal_mcu_disable_interrupts(); uint16_t errors = self->last_errors; self->last_errors = 0; @@ -333,8 +331,7 @@ uint16_t common_hal_ps2io_ps2_clear_errors(ps2io_ps2_obj_t* self) // Based upon TMK implementation of PS/2 protocol // https://github.com/tmk/tmk_keyboard/blob/master/tmk_core/protocol/ps2_interrupt.c -int16_t common_hal_ps2io_ps2_sendcmd(ps2io_ps2_obj_t* self, uint8_t b) -{ +int16_t common_hal_ps2io_ps2_sendcmd(ps2io_ps2_obj_t *self, uint8_t b) { disable_interrupt(self); inhibit(self); delay_us(100); diff --git a/ports/atmel-samd/common-hal/pulseio/PulseIn.h b/ports/atmel-samd/common-hal/pulseio/PulseIn.h index e8fed8e5a0..81780aa130 100644 --- a/ports/atmel-samd/common-hal/pulseio/PulseIn.h +++ b/ports/atmel-samd/common-hal/pulseio/PulseIn.h @@ -35,7 +35,7 @@ typedef struct { mp_obj_base_t base; uint8_t channel; uint8_t pin; - uint16_t* buffer; + uint16_t *buffer; uint16_t maxlen; bool idle_state; volatile uint16_t start; diff --git a/ports/atmel-samd/common-hal/pulseio/PulseOut.c b/ports/atmel-samd/common-hal/pulseio/PulseOut.c index ebfd4e7b1a..56b5f036ed 100644 --- a/ports/atmel-samd/common-hal/pulseio/PulseOut.c +++ b/ports/atmel-samd/common-hal/pulseio/PulseOut.c @@ -51,11 +51,11 @@ static volatile uint16_t pulse_index = 0; static uint16_t pulse_length; static volatile uint32_t current_compare = 0; -static void turn_on(__IO PORT_PINCFG_Type * pincfg) { +static void turn_on(__IO PORT_PINCFG_Type *pincfg) { pincfg->reg = PORT_PINCFG_PMUXEN; } -static void turn_off(__IO PORT_PINCFG_Type * pincfg) { +static void turn_off(__IO PORT_PINCFG_Type *pincfg) { pincfg->reg = PORT_PINCFG_RESETVALUE; } @@ -71,7 +71,7 @@ void pulse_finish(void) { return; } current_compare = (current_compare + pulse_buffer[pulse_index] * 3 / 4) & 0xffff; - Tc* tc = tc_insts[pulseout_tc_index]; + Tc *tc = tc_insts[pulseout_tc_index]; tc->COUNT16.CC[0].reg = current_compare; if (pulse_index % 2 == 0) { turn_on(active_pincfg); @@ -79,9 +79,13 @@ void pulse_finish(void) { } void pulseout_interrupt_handler(uint8_t index) { - if (index != pulseout_tc_index) return; - Tc* tc = tc_insts[index]; - if (!tc->COUNT16.INTFLAG.bit.MC0) return; + if (index != pulseout_tc_index) { + return; + } + Tc *tc = tc_insts[index]; + if (!tc->COUNT16.INTFLAG.bit.MC0) { + return; + } pulse_finish(); @@ -93,16 +97,16 @@ void pulseout_reset() { refcount = 0; pulseout_tc_index = 0xff; active_pincfg = NULL; -#ifdef SAMD21 + #ifdef SAMD21 rtc_end_pulse(); -#endif + #endif } -void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, - const pwmio_pwmout_obj_t* carrier, - const mcu_pin_obj_t* pin, - uint32_t frequency, - uint16_t duty_cycle) { +void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t *self, + const pwmio_pwmout_obj_t *carrier, + const mcu_pin_obj_t *pin, + uint32_t frequency, + uint16_t duty_cycle) { if (!carrier || pin || frequency) { mp_raise_NotImplementedError(translate("Port does not accept pins or frequency. Construct and pass a PWMOut Carrier instead")); } @@ -136,8 +140,8 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, #ifdef SAMD21 tc->COUNT16.CTRLA.reg = TC_CTRLA_MODE_COUNT16 | - TC_CTRLA_PRESCALER_DIV64 | - TC_CTRLA_WAVEGEN_NFRQ; + TC_CTRLA_PRESCALER_DIV64 | + TC_CTRLA_WAVEGEN_NFRQ; #endif #ifdef SAM_D5X_E5X tc_reset(tc); @@ -162,17 +166,17 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, // Turn off the pinmux which should connect the port output. turn_off(self->pincfg); -#ifdef SAMD21 + #ifdef SAMD21 rtc_start_pulse(); -#endif + #endif } -bool common_hal_pulseio_pulseout_deinited(pulseio_pulseout_obj_t* self) { +bool common_hal_pulseio_pulseout_deinited(pulseio_pulseout_obj_t *self) { return self->pin == NO_PIN; } -void common_hal_pulseio_pulseout_deinit(pulseio_pulseout_obj_t* self) { +void common_hal_pulseio_pulseout_deinit(pulseio_pulseout_obj_t *self) { if (common_hal_pulseio_pulseout_deinited(self)) { return; } @@ -187,12 +191,12 @@ void common_hal_pulseio_pulseout_deinit(pulseio_pulseout_obj_t* self) { pulseout_tc_index = 0xff; } self->pin = NO_PIN; -#ifdef SAMD21 + #ifdef SAMD21 rtc_end_pulse(); -#endif + #endif } -void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t* self, uint16_t* pulses, uint16_t length) { +void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t *self, uint16_t *pulses, uint16_t length) { if (active_pincfg != NULL) { mp_raise_RuntimeError(translate("Another send is already active")); } @@ -202,7 +206,7 @@ void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t* self, uint16_t* pu pulse_length = length; current_compare = pulses[0] * 3 / 4; - Tc* tc = tc_insts[pulseout_tc_index]; + Tc *tc = tc_insts[pulseout_tc_index]; tc->COUNT16.CC[0].reg = current_compare; // Clear our interrupt in case it was set earlier @@ -212,7 +216,7 @@ void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t* self, uint16_t* pu turn_on(active_pincfg); tc->COUNT16.CTRLBSET.reg = TC_CTRLBSET_CMD_RETRIGGER; - while(pulse_index < length) { + while (pulse_index < length) { // Do other things while we wait. The interrupts will handle sending the // signal. RUN_BACKGROUND_TASKS; diff --git a/ports/atmel-samd/common-hal/pwmio/PWMOut.c b/ports/atmel-samd/common-hal/pwmio/PWMOut.c index c46145d7d7..815f1a7fe0 100644 --- a/ports/atmel-samd/common-hal/pwmio/PWMOut.c +++ b/ports/atmel-samd/common-hal/pwmio/PWMOut.c @@ -42,8 +42,8 @@ #undef ENABLE -# define _TCC_SIZE(unused, n) TCC ## n ## _SIZE, -# define TCC_SIZES { REPEAT_MACRO(_TCC_SIZE, 0, TCC_INST_NUM) } +#define _TCC_SIZE(unused, n) TCC##n##_SIZE, +#define TCC_SIZES { REPEAT_MACRO(_TCC_SIZE, 0, TCC_INST_NUM) } static const uint8_t tcc_sizes[TCC_INST_NUM] = TCC_SIZES; static uint32_t tcc_periods[TCC_INST_NUM]; @@ -126,38 +126,38 @@ void pwmout_reset(void) { } } -static uint8_t tcc_channel(const pin_timer_t* t) { +static uint8_t tcc_channel(const pin_timer_t *t) { // For the SAMD51 this hardcodes the use of OTMX == 0x0, the output matrix mapping, which uses // SAMD21-style modulo mapping. return t->wave_output % tcc_cc_num[t->index]; } -bool channel_ok(const pin_timer_t* t) { +bool channel_ok(const pin_timer_t *t) { uint8_t channel_bit = 1 << tcc_channel(t); return (!t->is_tc && ((tcc_channels[t->index] & channel_bit) == 0)) || - t->is_tc; + t->is_tc; } -pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t* self, - const mcu_pin_obj_t* pin, - uint16_t duty, - uint32_t frequency, - bool variable_frequency) { +pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self, + const mcu_pin_obj_t *pin, + uint16_t duty, + uint32_t frequency, + bool variable_frequency) { self->pin = pin; self->variable_frequency = variable_frequency; self->duty_cycle = duty; if (pin->timer[0].index >= TC_INST_NUM && pin->timer[1].index >= TCC_INST_NUM -#ifdef SAM_D5X_E5X + #ifdef SAM_D5X_E5X && pin->timer[2].index >= TCC_INST_NUM -#endif + #endif ) { return PWMOUT_INVALID_PIN; } uint32_t system_clock = common_hal_mcu_processor_get_frequency(); - if (frequency == 0 || frequency > system_clock/2) { + if (frequency == 0 || frequency > system_clock / 2) { return PWMOUT_INVALID_FREQUENCY; } @@ -165,7 +165,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t* self, // First see if a tcc is already going with the frequency we want and our // channel is unused. tc's don't have enough channels to share. - const pin_timer_t* timer = NULL; + const pin_timer_t *timer = NULL; uint8_t mux_position = 0; if (!variable_frequency) { for (uint8_t i = 0; i < TCC_INST_NUM && timer == NULL; i++) { @@ -173,11 +173,11 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t* self, continue; } for (uint8_t j = 0; j < NUM_TIMERS_PER_PIN && timer == NULL; j++) { - const pin_timer_t* t = &pin->timer[j]; + const pin_timer_t *t = &pin->timer[j]; if (t->index != i || t->is_tc || t->index >= TCC_INST_NUM) { continue; } - Tcc* tcc = tcc_insts[t->index]; + Tcc *tcc = tcc_insts[t->index]; if (tcc->CTRLA.bit.ENABLE == 1 && channel_ok(t)) { timer = t; mux_position = j; @@ -202,20 +202,20 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t* self, start = 0; } for (int8_t i = start; i >= 0 && i < NUM_TIMERS_PER_PIN && timer == NULL; i += direction) { - const pin_timer_t* t = &pin->timer[i]; + const pin_timer_t *t = &pin->timer[i]; if ((!t->is_tc && t->index >= TCC_INST_NUM) || (t->is_tc && t->index >= TC_INST_NUM)) { continue; } if (t->is_tc) { found = true; - Tc* tc = tc_insts[t->index]; + Tc *tc = tc_insts[t->index]; if (tc->COUNT16.CTRLA.bit.ENABLE == 0 && t->wave_output == 1) { timer = t; mux_position = i; } } else { - Tcc* tcc = tcc_insts[t->index]; + Tcc *tcc = tcc_insts[t->index]; if (tcc->CTRLA.bit.ENABLE == 0 && channel_ok(t)) { timer = t; mux_position = i; @@ -253,11 +253,11 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t* self, if (timer->is_tc) { tc_periods[timer->index] = top; - Tc* tc = tc_insts[timer->index]; + Tc *tc = tc_insts[timer->index]; #ifdef SAMD21 tc->COUNT16.CTRLA.reg = TC_CTRLA_MODE_COUNT16 | - TC_CTRLA_PRESCALER(divisor) | - TC_CTRLA_WAVEGEN_MPWM; + TC_CTRLA_PRESCALER(divisor) | + TC_CTRLA_WAVEGEN_MPWM; tc->COUNT16.CC[0].reg = top; #endif #ifdef SAM_D5X_E5X @@ -275,7 +275,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t* self, tc_set_enable(tc, true); } else { tcc_periods[timer->index] = top; - Tcc* tcc = tcc_insts[timer->index]; + Tcc *tcc = tcc_insts[timer->index]; tcc_set_enable(tcc, false); tcc->CTRLA.bit.PRESCALER = divisor; tcc->PER.bit.PER = top; @@ -300,17 +300,17 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t* self, return PWMOUT_OK; } -bool common_hal_pwmio_pwmout_deinited(pwmio_pwmout_obj_t* self) { +bool common_hal_pwmio_pwmout_deinited(pwmio_pwmout_obj_t *self) { return self->pin == NULL; } -void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t* self) { +void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t *self) { if (common_hal_pwmio_pwmout_deinited(self)) { return; } - const pin_timer_t* t = self->timer; + const pin_timer_t *t = self->timer; if (t->is_tc) { - Tc* tc = tc_insts[t->index]; + Tc *tc = tc_insts[t->index]; tc_set_enable(tc, false); tc->COUNT16.CTRLA.bit.SWRST = true; tc_wait_for_sync(tc); @@ -319,7 +319,7 @@ void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t* self) { tcc_channels[t->index] &= ~(1 << tcc_channel(t)); if (tcc_refcount[t->index] == 0) { target_tcc_frequencies[t->index] = 0; - Tcc* tcc = tcc_insts[t->index]; + Tcc *tcc = tcc_insts[t->index]; tcc_set_enable(tcc, false); tcc->CTRLA.bit.SWRST = true; while (tcc->SYNCBUSY.bit.SWRST != 0) { @@ -331,7 +331,7 @@ void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t* self) { self->pin = NULL; } -extern void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t* self, uint16_t duty) { +extern void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t *self, uint16_t duty) { // Store the unadjusted duty cycle. It turns out the the process of adjusting and calculating // the duty cycle here and reading it back is lossy - the value will decay over time. // Track it here so that if frequency is changed we can use this value to recalculate the @@ -339,27 +339,29 @@ extern void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t* self, uin // See https://github.com/adafruit/circuitpython/issues/2086 for more details self->duty_cycle = duty; - const pin_timer_t* t = self->timer; + const pin_timer_t *t = self->timer; if (t->is_tc) { uint16_t adjusted_duty = tc_periods[t->index] * duty / 0xffff; #ifdef SAMD21 tc_insts[t->index]->COUNT16.CC[t->wave_output].reg = adjusted_duty; #endif #ifdef SAM_D5X_E5X - Tc* tc = tc_insts[t->index]; - while (tc->COUNT16.SYNCBUSY.bit.CC1 != 0) {} + Tc *tc = tc_insts[t->index]; + while (tc->COUNT16.SYNCBUSY.bit.CC1 != 0) { + } tc->COUNT16.CCBUF[1].reg = adjusted_duty; #endif } else { - uint32_t adjusted_duty = ((uint64_t) tcc_periods[t->index]) * duty / 0xffff; + uint32_t adjusted_duty = ((uint64_t)tcc_periods[t->index]) * duty / 0xffff; uint8_t channel = tcc_channel(t); - Tcc* tcc = tcc_insts[t->index]; + Tcc *tcc = tcc_insts[t->index]; // Write into the CC buffer register, which will be transferred to the // CC register on an UPDATE (when period is finished). // Do clock domain syncing as necessary. - while (tcc->SYNCBUSY.reg != 0) {} + while (tcc->SYNCBUSY.reg != 0) { + } // Lock out double-buffering while updating the CCB value. tcc->CTRLBSET.bit.LUPD = 1; @@ -373,19 +375,20 @@ extern void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t* self, uin } } -uint16_t common_hal_pwmio_pwmout_get_duty_cycle(pwmio_pwmout_obj_t* self) { - const pin_timer_t* t = self->timer; +uint16_t common_hal_pwmio_pwmout_get_duty_cycle(pwmio_pwmout_obj_t *self) { + const pin_timer_t *t = self->timer; if (t->is_tc) { - Tc* tc = tc_insts[t->index]; + Tc *tc = tc_insts[t->index]; tc_wait_for_sync(tc); uint16_t cv = tc->COUNT16.CC[t->wave_output].reg; return cv * 0xffff / tc_periods[t->index]; } else { - Tcc* tcc = tcc_insts[t->index]; + Tcc *tcc = tcc_insts[t->index]; uint8_t channel = tcc_channel(t); uint32_t cv = 0; - while (tcc->SYNCBUSY.bit.CTRLB) {} + while (tcc->SYNCBUSY.bit.CTRLB) { + } #ifdef SAMD21 // If CCBV (CCB valid) is set, the CCB value hasn't yet been copied @@ -404,20 +407,20 @@ uint16_t common_hal_pwmio_pwmout_get_duty_cycle(pwmio_pwmout_obj_t* self) { } #endif - uint32_t duty_cycle = ((uint64_t) cv) * 0xffff / tcc_periods[t->index]; + uint32_t duty_cycle = ((uint64_t)cv) * 0xffff / tcc_periods[t->index]; return duty_cycle; } } -void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t* self, - uint32_t frequency) { +void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t *self, + uint32_t frequency) { uint32_t system_clock = common_hal_mcu_processor_get_frequency(); - if (frequency == 0 || frequency > system_clock/2) { + if (frequency == 0 || frequency > system_clock / 2) { mp_raise_ValueError(translate("Invalid PWM frequency")); } - const pin_timer_t* t = self->timer; + const pin_timer_t *t = self->timer; uint8_t resolution; if (t->is_tc) { resolution = 16; @@ -434,7 +437,7 @@ void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t* self, } } if (t->is_tc) { - Tc* tc = tc_insts[t->index]; + Tc *tc = tc_insts[t->index]; uint8_t old_divisor = tc->COUNT16.CTRLA.bit.PRESCALER; if (new_divisor != old_divisor) { tc_set_enable(tc, false); @@ -446,18 +449,20 @@ void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t* self, tc->COUNT16.CC[0].reg = new_top; #endif #ifdef SAM_D5X_E5X - while (tc->COUNT16.SYNCBUSY.reg != 0) {} + while (tc->COUNT16.SYNCBUSY.reg != 0) { + } tc->COUNT16.CCBUF[0].reg = new_top; #endif } else { - Tcc* tcc = tcc_insts[t->index]; + Tcc *tcc = tcc_insts[t->index]; uint8_t old_divisor = tcc->CTRLA.bit.PRESCALER; if (new_divisor != old_divisor) { tcc_set_enable(tcc, false); tcc->CTRLA.bit.PRESCALER = new_divisor; tcc_set_enable(tcc, true); } - while (tcc->SYNCBUSY.reg != 0) {} + while (tcc->SYNCBUSY.reg != 0) { + } tcc_periods[t->index] = new_top; #ifdef SAMD21 tcc->PERB.bit.PERB = new_top; @@ -470,9 +475,9 @@ void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t* self, common_hal_pwmio_pwmout_set_duty_cycle(self, self->duty_cycle); } -uint32_t common_hal_pwmio_pwmout_get_frequency(pwmio_pwmout_obj_t* self) { +uint32_t common_hal_pwmio_pwmout_get_frequency(pwmio_pwmout_obj_t *self) { uint32_t system_clock = common_hal_mcu_processor_get_frequency(); - const pin_timer_t* t = self->timer; + const pin_timer_t *t = self->timer; uint8_t divisor; uint32_t top; if (t->is_tc) { @@ -485,6 +490,6 @@ uint32_t common_hal_pwmio_pwmout_get_frequency(pwmio_pwmout_obj_t* self) { return (system_clock / prescaler[divisor]) / (top + 1); } -bool common_hal_pwmio_pwmout_get_variable_frequency(pwmio_pwmout_obj_t* self) { +bool common_hal_pwmio_pwmout_get_variable_frequency(pwmio_pwmout_obj_t *self) { return self->variable_frequency; } diff --git a/ports/atmel-samd/common-hal/pwmio/PWMOut.h b/ports/atmel-samd/common-hal/pwmio/PWMOut.h index 1f5e62bae0..1915991b54 100644 --- a/ports/atmel-samd/common-hal/pwmio/PWMOut.h +++ b/ports/atmel-samd/common-hal/pwmio/PWMOut.h @@ -34,7 +34,7 @@ typedef struct { mp_obj_base_t base; const mcu_pin_obj_t *pin; - const pin_timer_t* timer; + const pin_timer_t *timer; bool variable_frequency; uint16_t duty_cycle; } pwmio_pwmout_obj_t; diff --git a/ports/atmel-samd/common-hal/rgbmatrix/RGBMatrix.c b/ports/atmel-samd/common-hal/rgbmatrix/RGBMatrix.c index 6daf20aeaa..aa0bd78275 100644 --- a/ports/atmel-samd/common-hal/rgbmatrix/RGBMatrix.c +++ b/ports/atmel-samd/common-hal/rgbmatrix/RGBMatrix.c @@ -40,7 +40,7 @@ void *common_hal_rgbmatrix_timer_allocate(rgbmatrix_rgbmatrix_obj_t *self) { return tc_insts[timer_index]; } -static uint8_t tc_index_from_ptr(void* ptr) { +static uint8_t tc_index_from_ptr(void *ptr) { for (uint8_t i = TC_INST_NUM; i > 0; i--) { if (tc_insts[i] == ptr) { return i; @@ -49,7 +49,7 @@ static uint8_t tc_index_from_ptr(void* ptr) { return 0xff; } -void common_hal_rgbmatrix_timer_enable(void* ptr) { +void common_hal_rgbmatrix_timer_enable(void *ptr) { uint8_t timer_index = tc_index_from_ptr(ptr); if (timer_index == 0xff) { return; @@ -58,7 +58,7 @@ void common_hal_rgbmatrix_timer_enable(void* ptr) { turn_on_clocks(true, timer_index, 1); } -void common_hal_rgbmatrix_timer_disable(void* ptr) { +void common_hal_rgbmatrix_timer_disable(void *ptr) { uint8_t timer_index = tc_index_from_ptr(ptr); if (timer_index == 0xff) { return; @@ -67,7 +67,7 @@ void common_hal_rgbmatrix_timer_disable(void* ptr) { tc_set_enable(ptr, false); } -void common_hal_rgbmatrix_timer_free(void* ptr) { +void common_hal_rgbmatrix_timer_free(void *ptr) { uint8_t timer_index = tc_index_from_ptr(ptr); if (timer_index == 0xff) { return; diff --git a/ports/atmel-samd/common-hal/rgbmatrix/RGBMatrix.h b/ports/atmel-samd/common-hal/rgbmatrix/RGBMatrix.h index 2378cf1735..d14cd9b083 100644 --- a/ports/atmel-samd/common-hal/rgbmatrix/RGBMatrix.h +++ b/ports/atmel-samd/common-hal/rgbmatrix/RGBMatrix.h @@ -30,8 +30,8 @@ #include "shared-module/rgbmatrix/RGBMatrix.h" void *common_hal_rgbmatrix_timer_allocate(rgbmatrix_rgbmatrix_obj_t *self); -void common_hal_rgbmatrix_timer_enable(void*); -void common_hal_rgbmatrix_timer_disable(void*); -void common_hal_rgbmatrix_timer_free(void*); +void common_hal_rgbmatrix_timer_enable(void *); +void common_hal_rgbmatrix_timer_disable(void *); +void common_hal_rgbmatrix_timer_free(void *); #endif diff --git a/ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c b/ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c index 4b74b438ff..2a30142ab3 100644 --- a/ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c +++ b/ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c @@ -34,8 +34,8 @@ #include "py/runtime.h" #include "supervisor/shared/translate.h" -void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencoder_obj_t* self, - const mcu_pin_obj_t* pin_a, const mcu_pin_obj_t* pin_b) { +void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencoder_obj_t *self, + const mcu_pin_obj_t *pin_a, const mcu_pin_obj_t *pin_b) { if (!pin_a->has_extint || !pin_b->has_extint) { mp_raise_RuntimeError(translate("Both pins must support hardware interrupts")); } @@ -63,15 +63,15 @@ void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencode gpio_set_pin_function(self->pin_b, GPIO_PIN_FUNCTION_A); gpio_set_pin_pull_mode(self->pin_b, GPIO_PULL_UP); - set_eic_channel_data(self->eic_channel_a, (void*) self); - set_eic_channel_data(self->eic_channel_b, (void*) self); + set_eic_channel_data(self->eic_channel_a, (void *)self); + set_eic_channel_data(self->eic_channel_b, (void *)self); self->position = 0; self->quarter_count = 0; shared_module_softencoder_state_init(self, - ((uint8_t) gpio_get_pin_level(self->pin_a) << 1) | - (uint8_t) gpio_get_pin_level(self->pin_b)); + ((uint8_t)gpio_get_pin_level(self->pin_a) << 1) | + (uint8_t)gpio_get_pin_level(self->pin_b)); claim_pin(pin_a); claim_pin(pin_b); @@ -83,11 +83,11 @@ void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencode turn_on_eic_channel(self->eic_channel_b, EIC_CONFIG_SENSE0_BOTH_Val); } -bool common_hal_rotaryio_incrementalencoder_deinited(rotaryio_incrementalencoder_obj_t* self) { +bool common_hal_rotaryio_incrementalencoder_deinited(rotaryio_incrementalencoder_obj_t *self) { return self->pin_a == NO_PIN; } -void common_hal_rotaryio_incrementalencoder_deinit(rotaryio_incrementalencoder_obj_t* self) { +void common_hal_rotaryio_incrementalencoder_deinit(rotaryio_incrementalencoder_obj_t *self) { if (common_hal_rotaryio_incrementalencoder_deinited(self)) { return; } @@ -106,11 +106,11 @@ void common_hal_rotaryio_incrementalencoder_deinit(rotaryio_incrementalencoder_o } void incrementalencoder_interrupt_handler(uint8_t channel) { - rotaryio_incrementalencoder_obj_t* self = get_eic_channel_data(channel); + rotaryio_incrementalencoder_obj_t *self = get_eic_channel_data(channel); uint8_t new_state = - ((uint8_t) gpio_get_pin_level(self->pin_a) << 1) | - (uint8_t) gpio_get_pin_level(self->pin_b); + ((uint8_t)gpio_get_pin_level(self->pin_a) << 1) | + (uint8_t)gpio_get_pin_level(self->pin_b); shared_module_softencoder_state_update(self, new_state); } diff --git a/ports/atmel-samd/common-hal/rtc/RTC.c b/ports/atmel-samd/common-hal/rtc/RTC.c index 3473165db2..3517f31aa5 100644 --- a/ports/atmel-samd/common-hal/rtc/RTC.c +++ b/ports/atmel-samd/common-hal/rtc/RTC.c @@ -51,7 +51,7 @@ void common_hal_rtc_set_time(timeutils_struct_time_t *tm) { uint64_t ticks_s = port_get_raw_ticks(NULL) / 1024; uint32_t epoch_s = timeutils_seconds_since_2000( tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec - ); + ); rtc_offset = epoch_s - ticks_s; } @@ -68,11 +68,11 @@ int common_hal_rtc_get_calibration(void) { void common_hal_rtc_set_calibration(int calibration) { if (calibration > 127 || calibration < -127) { -#if CIRCUITPY_FULL_BUILD + #if CIRCUITPY_FULL_BUILD mp_raise_ValueError(translate("calibration value out of range +/-127")); -#else + #else mp_raise_ValueError(translate("calibration is out of range")); -#endif + #endif } hri_rtcmode0_write_FREQCORR_SIGN_bit(RTC, calibration < 0 ? 0 : 1); diff --git a/ports/atmel-samd/common-hal/sdioio/SDCard.c b/ports/atmel-samd/common-hal/sdioio/SDCard.c index 14c6f29de1..9c8c1abf39 100644 --- a/ports/atmel-samd/common-hal/sdioio/SDCard.c +++ b/ports/atmel-samd/common-hal/sdioio/SDCard.c @@ -58,8 +58,8 @@ static Sdhc *sdhc_insts[] = SDHC_INSTS; void common_hal_sdioio_sdcard_construct(sdioio_sdcard_obj_t *self, - const mcu_pin_obj_t * clock, const mcu_pin_obj_t * command, - uint8_t num_data, mcu_pin_obj_t ** data, uint32_t frequency) { + const mcu_pin_obj_t *clock, const mcu_pin_obj_t *command, + uint8_t num_data, mcu_pin_obj_t **data, uint32_t frequency) { /* SD breakout as assembled ("*" = minimum viable set) @@ -84,7 +84,7 @@ CLK PA21 PCC_D? (D32) BROWN int instance = functions[0]->instance; functions[1] = mcu_find_pin_function(sdio_ck, clock, instance, MP_QSTR_clock); functions[2] = mcu_find_pin_function(sdio_dat0, data[0], instance, MP_QSTR_data0); - if(num_data == 4) { + if (num_data == 4) { functions[3] = mcu_find_pin_function(sdio_dat1, data[1], instance, MP_QSTR_data1); functions[4] = mcu_find_pin_function(sdio_dat2, data[2], instance, MP_QSTR_data2); functions[5] = mcu_find_pin_function(sdio_dat3, data[3], instance, MP_QSTR_data3); @@ -94,8 +94,8 @@ CLK PA21 PCC_D? (D32) BROWN self->command_pin = common_hal_mcu_pin_number(functions[0]->obj); self->clock_pin = common_hal_mcu_pin_number(functions[1]->obj); - for(int i=0; idata_pins[i] = common_hal_mcu_pin_number(function->obj); } else { @@ -103,7 +103,7 @@ CLK PA21 PCC_D? (D32) BROWN } } - for(size_t i=0; iobj) { break; } @@ -121,16 +121,16 @@ CLK PA21 PCC_D? (D32) BROWN self->num_data = num_data; self->frequency = frequency; - if(instance == 0) { + if (instance == 0) { hri_mclk_set_AHBMASK_SDHC0_bit(MCLK); hri_gclk_write_PCHCTRL_reg(GCLK, SDHC0_GCLK_ID, CONF_GCLK_SDHC0_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos)); hri_gclk_write_PCHCTRL_reg(GCLK, SDHC0_GCLK_ID_SLOW, CONF_GCLK_SDHC0_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos)); -#ifdef SDHC1_GCLK_ID + #ifdef SDHC1_GCLK_ID } else { hri_mclk_set_AHBMASK_SDHC1_bit(MCLK); hri_gclk_write_PCHCTRL_reg(GCLK, SDHC1_GCLK_ID, CONF_GCLK_SDHC1_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos)); hri_gclk_write_PCHCTRL_reg(GCLK, SDHC1_GCLK_ID_SLOW, CONF_GCLK_SDHC1_SLOW_SRC | (1 << GCLK_PCHCTRL_CHEN_Pos)); -#endif + #endif } DEBUG_PRINT("instance %d @%p\n", instance, sdhc_insts[instance]); @@ -139,7 +139,7 @@ CLK PA21 PCC_D? (D32) BROWN sd_mmc_err_t result = SD_MMC_INIT_ONGOING; - for (int i=0; result == SD_MMC_INIT_ONGOING && i<100; i++) { + for (int i = 0; result == SD_MMC_INIT_ONGOING && i < 100; i++) { result = sd_mmc_check(0); DEBUG_PRINT("sd_mmc_check(0) -> %d\n", result); } @@ -182,9 +182,9 @@ STATIC void wait_write_complete(sdioio_sdcard_obj_t *self) { } STATIC void debug_print_state(sdioio_sdcard_obj_t *self, const char *what, sd_mmc_err_t r) { -#if DEBUG_SDIO + #if DEBUG_SDIO DEBUG_PRINT("%s: %d\n", what, r); -#endif + #endif } int common_hal_sdioio_sdcard_writeblocks(sdioio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *bufinfo) { diff --git a/ports/atmel-samd/common-hal/sdioio/SDCard.h b/ports/atmel-samd/common-hal/sdioio/SDCard.h index 2baba38f0d..1ab89fedda 100644 --- a/ports/atmel-samd/common-hal/sdioio/SDCard.h +++ b/ports/atmel-samd/common-hal/sdioio/SDCard.h @@ -33,7 +33,7 @@ typedef struct { struct mci_sync_desc IO_BUS; uint32_t frequency; uint32_t capacity; - uint8_t num_data:3, state_programming:1, has_lock:1; + uint8_t num_data : 3, state_programming : 1, has_lock : 1; uint8_t command_pin; uint8_t clock_pin; uint8_t data_pins[4]; diff --git a/ports/atmel-samd/common-hal/supervisor/Runtime.c b/ports/atmel-samd/common-hal/supervisor/Runtime.c old mode 100755 new mode 100644 index 974f26cec1..f827651781 --- a/ports/atmel-samd/common-hal/supervisor/Runtime.c +++ b/ports/atmel-samd/common-hal/supervisor/Runtime.c @@ -29,9 +29,9 @@ #include "supervisor/serial.h" bool common_hal_supervisor_runtime_get_serial_connected(void) { - return (bool) serial_connected(); + return (bool)serial_connected(); } bool common_hal_supervisor_runtime_get_serial_bytes_available(void) { - return (bool) serial_bytes_available(); + return (bool)serial_bytes_available(); } diff --git a/ports/atmel-samd/common-hal/touchio/TouchIn.c b/ports/atmel-samd/common-hal/touchio/TouchIn.c index b2fcc6cdef..89979b620f 100644 --- a/ports/atmel-samd/common-hal/touchio/TouchIn.c +++ b/ports/atmel-samd/common-hal/touchio/TouchIn.c @@ -57,15 +57,15 @@ static uint16_t get_raw_reading(touchio_touchin_obj_t *self) { return adafruit_ptc_get_conversion_result(PTC); } -void common_hal_touchio_touchin_construct(touchio_touchin_obj_t* self, - const mcu_pin_obj_t *pin) { +void common_hal_touchio_touchin_construct(touchio_touchin_obj_t *self, + const mcu_pin_obj_t *pin) { if (!pin->has_touch) { mp_raise_ValueError(translate("Invalid pin")); } claim_pin(pin); // Turn on the PTC if its not in use. We won't turn it off until reset. - if ((( Ptc *) PTC)->CTRLA.bit.ENABLE == 0) { + if (((Ptc *)PTC)->CTRLA.bit.ENABLE == 0) { // We run the PTC at 8mhz so divide the 48mhz clock by 6. uint8_t gclk = find_free_gclk(6); if (gclk > GCLK_GEN_NUM) { @@ -95,11 +95,11 @@ void common_hal_touchio_touchin_construct(touchio_touchin_obj_t* self, self->threshold = get_raw_reading(self) + 100; } -bool common_hal_touchio_touchin_deinited(touchio_touchin_obj_t* self) { +bool common_hal_touchio_touchin_deinited(touchio_touchin_obj_t *self) { return self->config.pin == NO_PIN; } -void common_hal_touchio_touchin_deinit(touchio_touchin_obj_t* self) { +void common_hal_touchio_touchin_deinit(touchio_touchin_obj_t *self) { // TODO(tannewt): Reset the PTC. if (common_hal_touchio_touchin_deinited(self)) { return; @@ -111,13 +111,15 @@ void common_hal_touchio_touchin_deinit(touchio_touchin_obj_t* self) { } void touchin_reset() { - Ptc* ptc = ((Ptc *) PTC); + Ptc *ptc = ((Ptc *)PTC); if (ptc->CTRLA.bit.ENABLE == 1) { ptc->CTRLA.bit.ENABLE = 0; - while (ptc->CTRLA.bit.ENABLE == 1) {} + while (ptc->CTRLA.bit.ENABLE == 1) { + } ptc->CTRLA.bit.SWRESET = 1; - while (ptc->CTRLA.bit.SWRESET == 1) {} + while (ptc->CTRLA.bit.SWRESET == 1) { + } } } diff --git a/ports/atmel-samd/sd_mmc/sd_mmc.c b/ports/atmel-samd/sd_mmc/sd_mmc.c index 5ea9d830e9..de5a3cfe17 100644 --- a/ports/atmel-samd/sd_mmc/sd_mmc.c +++ b/ports/atmel-samd/sd_mmc/sd_mmc.c @@ -72,7 +72,7 @@ #define driver mci #else #error No MCI or HSMCI interfaces are defined for SD MMC stack. \ - CONF_SD_MMC_MEM_CNT must be added in board.h file. + CONF_SD_MMC_MEM_CNT must be added in board.h file. #endif #if CONF_MCI_OS_SUPPORT @@ -119,28 +119,28 @@ /** This SD MMC stack supports only the high voltage */ #define SD_MMC_VOLTAGE_SUPPORT \ - (OCR_VDD_27_28 | OCR_VDD_28_29 | OCR_VDD_29_30 | OCR_VDD_30_31 | OCR_VDD_31_32 | OCR_VDD_32_33) + (OCR_VDD_27_28 | OCR_VDD_28_29 | OCR_VDD_29_30 | OCR_VDD_30_31 | OCR_VDD_31_32 | OCR_VDD_32_33) /** SD/MMC card states */ enum card_state { - SD_MMC_CARD_STATE_READY = 0, /**< Ready to use */ - SD_MMC_CARD_STATE_DEBOUNCE = 1, /**< Debounce on going */ - SD_MMC_CARD_STATE_INIT = 2, /**< Initialization on going */ - SD_MMC_CARD_STATE_UNUSABLE = 3, /**< Unusable card */ - SD_MMC_CARD_STATE_NO_CARD = 4 /**< No SD/MMC card inserted */ + SD_MMC_CARD_STATE_READY = 0, /**< Ready to use */ + SD_MMC_CARD_STATE_DEBOUNCE = 1, /**< Debounce on going */ + SD_MMC_CARD_STATE_INIT = 2, /**< Initialization on going */ + SD_MMC_CARD_STATE_UNUSABLE = 3, /**< Unusable card */ + SD_MMC_CARD_STATE_NO_CARD = 4 /**< No SD/MMC card inserted */ }; /** SD/MMC card information structure */ struct sd_mmc_card { - uint32_t clock; /**< Card access clock */ - uint32_t capacity; /**< Card capacity in KBytes */ - uint16_t rca; /**< Relative card address */ - enum card_state state; /**< Card state */ - card_type_t type; /**< Card type */ - card_version_t version; /**< Card version */ - uint8_t bus_width; /**< Number of DATA lin on bus (MCI only) */ - uint8_t csd[CSD_REG_BSIZE]; /**< CSD register */ - uint8_t high_speed; /**< High speed card (1) */ + uint32_t clock; /**< Card access clock */ + uint32_t capacity; /**< Card capacity in KBytes */ + uint16_t rca; /**< Relative card address */ + enum card_state state; /**< Card state */ + card_type_t type; /**< Card type */ + card_version_t version; /**< Card version */ + uint8_t bus_width; /**< Number of DATA lin on bus (MCI only) */ + uint8_t csd[CSD_REG_BSIZE]; /**< CSD register */ + uint8_t high_speed; /**< High speed card (1) */ }; /** Card detect pin */ @@ -192,7 +192,7 @@ static bool sd_mmc_cmd13(void); #if (CONF_SDIO_SUPPORT == 1) static bool sdio_cmd52(uint8_t rw_flag, uint8_t func_nb, uint32_t reg_addr, uint8_t rd_after_wr, uint8_t *io_data); static bool sdio_cmd53(uint8_t rw_flag, uint8_t func_nb, uint32_t reg_addr, uint8_t inc_addr, uint32_t size, - bool access_block); + bool access_block); #endif static bool sd_acmd6(void); static bool sd_acmd51(void); @@ -228,34 +228,33 @@ static bool sd_mmc_mci_install_mmc(void); * * \return true if success, otherwise false */ -static bool mmc_mci_op_cond(void) -{ - uint32_t retry, resp; +static bool mmc_mci_op_cond(void) { + uint32_t retry, resp; - /* - * Timeout 1s = 400KHz / ((6+6)*8) cylces = 4200 retry - * 6 = cmd byte size - * 6 = response byte size - */ - retry = 4200; - do { - if (!driver_send_cmd(sd_mmc_hal, MMC_MCI_CMD1_SEND_OP_COND, SD_MMC_VOLTAGE_SUPPORT | OCR_ACCESS_MODE_SECTOR)) { - return false; - } - /* Check busy flag */ - resp = driver_get_response(sd_mmc_hal); - if (resp & OCR_POWER_UP_BUSY) { - /* Check OCR value */ - if ((resp & OCR_ACCESS_MODE_MASK) == OCR_ACCESS_MODE_SECTOR) { - sd_mmc_card->type |= CARD_TYPE_HC; - } - break; - } - if (retry-- == 0) { - return false; - } - } while (1); - return true; + /* + * Timeout 1s = 400KHz / ((6+6)*8) cylces = 4200 retry + * 6 = cmd byte size + * 6 = response byte size + */ + retry = 4200; + do { + if (!driver_send_cmd(sd_mmc_hal, MMC_MCI_CMD1_SEND_OP_COND, SD_MMC_VOLTAGE_SUPPORT | OCR_ACCESS_MODE_SECTOR)) { + return false; + } + /* Check busy flag */ + resp = driver_get_response(sd_mmc_hal); + if (resp & OCR_POWER_UP_BUSY) { + /* Check OCR value */ + if ((resp & OCR_ACCESS_MODE_MASK) == OCR_ACCESS_MODE_SECTOR) { + sd_mmc_card->type |= CARD_TYPE_HC; + } + break; + } + if (retry-- == 0) { + return false; + } + } while (1); + return true; } #endif @@ -268,47 +267,46 @@ static bool mmc_mci_op_cond(void) * * \return true if success, otherwise false */ -static bool sd_mci_op_cond(uint8_t v2) -{ - uint32_t arg, retry, resp; +static bool sd_mci_op_cond(uint8_t v2) { + uint32_t arg, retry, resp; - /* - * Timeout 1s = 400KHz / ((6+6+6+6)*8) cylces = 2100 retry - * 6 = cmd byte size - * 6 = response byte size - * 6 = cmd byte size - * 6 = response byte size - */ - retry = 2100; - do { - /* CMD55 - Indicate to the card that the next command is an - * application specific command rather than a standard command.*/ - if (!driver_send_cmd(sd_mmc_hal, SDMMC_CMD55_APP_CMD, 0)) { - return false; - } + /* + * Timeout 1s = 400KHz / ((6+6+6+6)*8) cylces = 2100 retry + * 6 = cmd byte size + * 6 = response byte size + * 6 = cmd byte size + * 6 = response byte size + */ + retry = 2100; + do { + /* CMD55 - Indicate to the card that the next command is an + * application specific command rather than a standard command.*/ + if (!driver_send_cmd(sd_mmc_hal, SDMMC_CMD55_APP_CMD, 0)) { + return false; + } - /* (ACMD41) Sends host OCR register */ - arg = SD_MMC_VOLTAGE_SUPPORT; - if (v2) { - arg |= SD_ACMD41_HCS; - } - /* Check response */ - if (!driver_send_cmd(sd_mmc_hal, SD_MCI_ACMD41_SD_SEND_OP_COND, arg)) { - return false; - } - resp = driver_get_response(sd_mmc_hal); - if (resp & OCR_POWER_UP_BUSY) { - /* Card is ready */ - if ((resp & OCR_CCS) != 0) { - sd_mmc_card->type |= CARD_TYPE_HC; - } - break; - } - if (retry-- == 0) { - return false; - } - } while (1); - return true; + /* (ACMD41) Sends host OCR register */ + arg = SD_MMC_VOLTAGE_SUPPORT; + if (v2) { + arg |= SD_ACMD41_HCS; + } + /* Check response */ + if (!driver_send_cmd(sd_mmc_hal, SD_MCI_ACMD41_SD_SEND_OP_COND, arg)) { + return false; + } + resp = driver_get_response(sd_mmc_hal); + if (resp & OCR_POWER_UP_BUSY) { + /* Card is ready */ + if ((resp & OCR_CCS) != 0) { + sd_mmc_card->type |= CARD_TYPE_HC; + } + break; + } + if (retry-- == 0) { + return false; + } + } while (1); + return true; } #if (CONF_SDIO_SUPPORT == 1) @@ -321,46 +319,45 @@ static bool sd_mci_op_cond(uint8_t v2) * * \return true if success, otherwise false */ -static bool sdio_op_cond(void) -{ - uint32_t resp; +static bool sdio_op_cond(void) { + uint32_t resp; - /* CMD5 - SDIO send operation condition (OCR) command. */ - if (!driver_send_cmd(sd_mmc_hal, SDIO_CMD5_SEND_OP_COND, 0)) { - return true; /* No error but card type not updated */ - } - resp = driver_get_response(sd_mmc_hal); - if ((resp & OCR_SDIO_NF) == 0) { - return true; /* No error but card type not updated */ - } + /* CMD5 - SDIO send operation condition (OCR) command. */ + if (!driver_send_cmd(sd_mmc_hal, SDIO_CMD5_SEND_OP_COND, 0)) { + return true; /* No error but card type not updated */ + } + resp = driver_get_response(sd_mmc_hal); + if ((resp & OCR_SDIO_NF) == 0) { + return true; /* No error but card type not updated */ + } - /* - * Wait card ready - * Timeout 1s = 400KHz / ((6+4)*8) cylces = 5000 retry - * 6 = cmd byte size - * 4(SPI) 6(MCI) = response byte size - */ - uint32_t cmd5_retry = 5000; - while (1) { - /* CMD5 - SDIO send operation condition (OCR) command.*/ - if (!driver_send_cmd(sd_mmc_hal, SDIO_CMD5_SEND_OP_COND, resp & SD_MMC_VOLTAGE_SUPPORT)) { - return false; - } - resp = driver_get_response(sd_mmc_hal); - if ((resp & OCR_POWER_UP_BUSY) == OCR_POWER_UP_BUSY) { - break; - } - if (cmd5_retry-- == 0) { - return false; - } - } - /* Update card type at the end of busy */ - if ((resp & OCR_SDIO_MP) > 0) { - sd_mmc_card->type = CARD_TYPE_SD_COMBO; - } else { - sd_mmc_card->type = CARD_TYPE_SDIO; - } - return true; /* No error and card type updated with SDIO type */ + /* + * Wait card ready + * Timeout 1s = 400KHz / ((6+4)*8) cylces = 5000 retry + * 6 = cmd byte size + * 4(SPI) 6(MCI) = response byte size + */ + uint32_t cmd5_retry = 5000; + while (1) { + /* CMD5 - SDIO send operation condition (OCR) command.*/ + if (!driver_send_cmd(sd_mmc_hal, SDIO_CMD5_SEND_OP_COND, resp & SD_MMC_VOLTAGE_SUPPORT)) { + return false; + } + resp = driver_get_response(sd_mmc_hal); + if ((resp & OCR_POWER_UP_BUSY) == OCR_POWER_UP_BUSY) { + break; + } + if (cmd5_retry-- == 0) { + return false; + } + } + /* Update card type at the end of busy */ + if ((resp & OCR_SDIO_MP) > 0) { + sd_mmc_card->type = CARD_TYPE_SD_COMBO; + } else { + sd_mmc_card->type = CARD_TYPE_SDIO; + } + return true; /* No error and card type updated with SDIO type */ } /** @@ -373,75 +370,74 @@ static bool sdio_op_cond(void) * * \return true if success, otherwise false */ -static bool sdio_get_max_speed(void) -{ - uint32_t addr_new, addr_old; - uint8_t buf[6]; - uint32_t unit; - uint32_t mul; - uint8_t tplfe_max_tran_speed, i; - uint8_t addr_cis[4]; +static bool sdio_get_max_speed(void) { + uint32_t addr_new, addr_old; + uint8_t buf[6]; + uint32_t unit; + uint32_t mul; + uint8_t tplfe_max_tran_speed, i; + uint8_t addr_cis[4]; - /* Read CIS area address in CCCR area */ - addr_old = SDIO_CCCR_CIS_PTR; - for (i = 0; i < 4; i++) { - sdio_cmd52(SDIO_CMD52_READ_FLAG, SDIO_CIA, addr_old, 0, &addr_cis[i]); - addr_old++; - } - addr_old = addr_cis[0] + (addr_cis[1] << 8) + (addr_cis[2] << 16) + (addr_cis[3] << 24); - addr_new = addr_old; + /* Read CIS area address in CCCR area */ + addr_old = SDIO_CCCR_CIS_PTR; + for (i = 0; i < 4; i++) { + sdio_cmd52(SDIO_CMD52_READ_FLAG, SDIO_CIA, addr_old, 0, &addr_cis[i]); + addr_old++; + } + addr_old = addr_cis[0] + (addr_cis[1] << 8) + (addr_cis[2] << 16) + (addr_cis[3] << 24); + addr_new = addr_old; - while (1) { - /* Read a sample of CIA area */ - for (i = 0; i < 3; i++) { - sdio_cmd52(SDIO_CMD52_READ_FLAG, SDIO_CIA, addr_new, 0, &buf[i]); - addr_new++; - } - if (buf[0] == SDIO_CISTPL_END) { - return false; /* Tuple error */ - } - if (buf[0] == SDIO_CISTPL_FUNCE && buf[2] == 0x00) { - break; /* Fun0 tuple found */ - } - if (buf[1] == 0) { - return false; /* Tuple error */ - } - /* Next address */ - addr_new += buf[1] - 1; - if (addr_new > (addr_old + 256)) { - return false; /* Outoff CIS area */ - } - } + while (1) { + /* Read a sample of CIA area */ + for (i = 0; i < 3; i++) { + sdio_cmd52(SDIO_CMD52_READ_FLAG, SDIO_CIA, addr_new, 0, &buf[i]); + addr_new++; + } + if (buf[0] == SDIO_CISTPL_END) { + return false; /* Tuple error */ + } + if (buf[0] == SDIO_CISTPL_FUNCE && buf[2] == 0x00) { + break; /* Fun0 tuple found */ + } + if (buf[1] == 0) { + return false; /* Tuple error */ + } + /* Next address */ + addr_new += buf[1] - 1; + if (addr_new > (addr_old + 256)) { + return false; /* Outoff CIS area */ + } + } - /* Read all Fun0 tuple fields: fn0_blk_siz & max_tran_speed */ - addr_new -= 3; - for (i = 0; i < 6; i++) { - sdio_cmd52(SDIO_CMD52_READ_FLAG, SDIO_CIA, addr_new, 0, &buf[i]); - addr_new++; - } + /* Read all Fun0 tuple fields: fn0_blk_siz & max_tran_speed */ + addr_new -= 3; + for (i = 0; i < 6; i++) { + sdio_cmd52(SDIO_CMD52_READ_FLAG, SDIO_CIA, addr_new, 0, &buf[i]); + addr_new++; + } - tplfe_max_tran_speed = buf[5]; - if (tplfe_max_tran_speed > 0x32) { - /* Error on SDIO register, the high speed is not activated - * and the clock can not be more than 25MHz. - * This error is present on specific SDIO card - * (H&D wireless card - HDG104 WiFi SIP). - */ - tplfe_max_tran_speed = 0x32; /* 25Mhz */ - } + tplfe_max_tran_speed = buf[5]; + if (tplfe_max_tran_speed > 0x32) { + /* Error on SDIO register, the high speed is not activated + * and the clock can not be more than 25MHz. + * This error is present on specific SDIO card + * (H&D wireless card - HDG104 WiFi SIP). + */ + tplfe_max_tran_speed = 0x32; /* 25Mhz */ + } - /* Decode transfer speed in Hz.*/ - unit = sd_mmc_trans_units[tplfe_max_tran_speed & 0x7]; - mul = sd_trans_multipliers[(tplfe_max_tran_speed >> 3) & 0xF]; - sd_mmc_card->clock = unit * mul * 1000; - /** - * Note: A combo card shall be a Full-Speed SDIO card - * which supports upto 25MHz. - * A SDIO card alone can be: - * - a Low-Speed SDIO card which supports 400Khz minimum - * - a Full-Speed SDIO card which supports upto 25MHz - */ - return true; + /* Decode transfer speed in Hz.*/ + unit = sd_mmc_trans_units[tplfe_max_tran_speed & 0x7]; + mul = sd_trans_multipliers[(tplfe_max_tran_speed >> 3) & 0xF]; + sd_mmc_card->clock = unit * mul * 1000; + /** + * Note: A combo card shall be a Full-Speed SDIO card + * which supports upto 25MHz. + * A SDIO card alone can be: + * - a Low-Speed SDIO card which supports 400Khz minimum + * - a Full-Speed SDIO card which supports upto 25MHz + */ + return true; } /** @@ -451,31 +447,30 @@ static bool sdio_get_max_speed(void) * * \return true if success, otherwise false */ -static bool sdio_cmd52_set_bus_width(void) -{ - /** - * A SD memory card always supports bus 4bit - * A SD COMBO card always supports bus 4bit - * A SDIO Full-Speed alone always supports 4bit - * A SDIO Low-Speed alone can supports 4bit (Optional) - */ - uint8_t u8_value; +static bool sdio_cmd52_set_bus_width(void) { + /** + * A SD memory card always supports bus 4bit + * A SD COMBO card always supports bus 4bit + * A SDIO Full-Speed alone always supports 4bit + * A SDIO Low-Speed alone can supports 4bit (Optional) + */ + uint8_t u8_value; - /* Check 4bit support in 4BLS of "Card Capability" register */ - if (!sdio_cmd52(SDIO_CMD52_READ_FLAG, SDIO_CIA, SDIO_CCCR_CAP, 0, &u8_value)) { - return false; - } - if ((u8_value & SDIO_CAP_4BLS) != SDIO_CAP_4BLS) { - /* No supported, it is not a protocol error */ - return true; - } - /* HS mode possible, then enable */ - u8_value = SDIO_BUSWIDTH_4B; - if (!sdio_cmd52(SDIO_CMD52_WRITE_FLAG, SDIO_CIA, SDIO_CCCR_BUS_CTRL, 1, &u8_value)) { - return false; - } - sd_mmc_card->bus_width = 4; - return true; + /* Check 4bit support in 4BLS of "Card Capability" register */ + if (!sdio_cmd52(SDIO_CMD52_READ_FLAG, SDIO_CIA, SDIO_CCCR_CAP, 0, &u8_value)) { + return false; + } + if ((u8_value & SDIO_CAP_4BLS) != SDIO_CAP_4BLS) { + /* No supported, it is not a protocol error */ + return true; + } + /* HS mode possible, then enable */ + u8_value = SDIO_BUSWIDTH_4B; + if (!sdio_cmd52(SDIO_CMD52_WRITE_FLAG, SDIO_CIA, SDIO_CCCR_BUS_CTRL, 1, &u8_value)) { + return false; + } + sd_mmc_card->bus_width = 4; + return true; } /** @@ -486,44 +481,39 @@ static bool sdio_cmd52_set_bus_width(void) * * \return true if success, otherwise false */ -static bool sdio_cmd52_set_high_speed(void) -{ - uint8_t u8_value; +static bool sdio_cmd52_set_high_speed(void) { + uint8_t u8_value; - /* Check CIA.HS */ - if (!sdio_cmd52(SDIO_CMD52_READ_FLAG, SDIO_CIA, SDIO_CCCR_HS, 0, &u8_value)) { - return false; - } - if ((u8_value & SDIO_SHS) != SDIO_SHS) { - /* No supported, it is not a protocol error */ - return true; - } - /* HS mode possible, then enable */ - u8_value = SDIO_EHS; - if (!sdio_cmd52(SDIO_CMD52_WRITE_FLAG, SDIO_CIA, SDIO_CCCR_HS, 1, &u8_value)) { - return false; - } - sd_mmc_card->high_speed = 1; - sd_mmc_card->clock *= 2; - return true; + /* Check CIA.HS */ + if (!sdio_cmd52(SDIO_CMD52_READ_FLAG, SDIO_CIA, SDIO_CCCR_HS, 0, &u8_value)) { + return false; + } + if ((u8_value & SDIO_SHS) != SDIO_SHS) { + /* No supported, it is not a protocol error */ + return true; + } + /* HS mode possible, then enable */ + u8_value = SDIO_EHS; + if (!sdio_cmd52(SDIO_CMD52_WRITE_FLAG, SDIO_CIA, SDIO_CCCR_HS, 1, &u8_value)) { + return false; + } + sd_mmc_card->high_speed = 1; + sd_mmc_card->clock *= 2; + return true; } #else -static bool sdio_op_cond(void) -{ - return true; /* No error but card type not updated */ +static bool sdio_op_cond(void) { + return true; /* No error but card type not updated */ } -static bool sdio_get_max_speed(void) -{ - return false; +static bool sdio_get_max_speed(void) { + return false; } -static bool sdio_cmd52_set_bus_width(void) -{ - return false; +static bool sdio_cmd52_set_bus_width(void) { + return false; } -static bool sdio_cmd52_set_high_speed(void) -{ - return false; +static bool sdio_cmd52_set_high_speed(void) { + return false; } #endif @@ -536,43 +526,42 @@ static bool sdio_cmd52_set_high_speed(void) * * \return true if success, otherwise false */ -static bool sd_cm6_set_high_speed(void) -{ - uint8_t switch_status[SD_SW_STATUS_BSIZE] = {0}; +static bool sd_cm6_set_high_speed(void) { + uint8_t switch_status[SD_SW_STATUS_BSIZE] = {0}; - if (!driver_adtc_start(sd_mmc_hal, - SD_CMD6_SWITCH_FUNC, - SD_CMD6_MODE_SWITCH | SD_CMD6_GRP6_NO_INFLUENCE | SD_CMD6_GRP5_NO_INFLUENCE - | SD_CMD6_GRP4_NO_INFLUENCE | SD_CMD6_GRP3_NO_INFLUENCE | SD_CMD6_GRP2_DEFAULT - | SD_CMD6_GRP1_HIGH_SPEED, - SD_SW_STATUS_BSIZE, - 1, - true)) { - return false; - } - if (!driver_start_read_blocks(sd_mmc_hal, switch_status, 1)) { - return false; - } - if (!driver_wait_end_of_read_blocks(sd_mmc_hal)) { - return false; - } + if (!driver_adtc_start(sd_mmc_hal, + SD_CMD6_SWITCH_FUNC, + SD_CMD6_MODE_SWITCH | SD_CMD6_GRP6_NO_INFLUENCE | SD_CMD6_GRP5_NO_INFLUENCE + | SD_CMD6_GRP4_NO_INFLUENCE | SD_CMD6_GRP3_NO_INFLUENCE | SD_CMD6_GRP2_DEFAULT + | SD_CMD6_GRP1_HIGH_SPEED, + SD_SW_STATUS_BSIZE, + 1, + true)) { + return false; + } + if (!driver_start_read_blocks(sd_mmc_hal, switch_status, 1)) { + return false; + } + if (!driver_wait_end_of_read_blocks(sd_mmc_hal)) { + return false; + } - if (driver_get_response(sd_mmc_hal) & CARD_STATUS_SWITCH_ERROR) { - return false; - } - if (SD_SW_STATUS_FUN_GRP1_RC(switch_status) == SD_SW_STATUS_FUN_GRP_RC_ERROR) { - /* No supported, it is not a protocol error */ - return true; - } - if (SD_SW_STATUS_FUN_GRP1_BUSY(switch_status)) { - return false; - } - /* CMD6 function switching period is within 8 clocks - * after the end bit of status data.*/ - driver_send_clock(sd_mmc_hal); - sd_mmc_card->high_speed = 1; - sd_mmc_card->clock *= 2; - return true; + if (driver_get_response(sd_mmc_hal) & CARD_STATUS_SWITCH_ERROR) { + return false; + } + if (SD_SW_STATUS_FUN_GRP1_RC(switch_status) == SD_SW_STATUS_FUN_GRP_RC_ERROR) { + /* No supported, it is not a protocol error */ + return true; + } + if (SD_SW_STATUS_FUN_GRP1_BUSY(switch_status)) { + return false; + } + /* CMD6 function switching period is within 8 clocks + * after the end bit of status data.*/ + driver_send_clock(sd_mmc_hal); + sd_mmc_card->high_speed = 1; + sd_mmc_card->clock *= 2; + return true; } #if CONF_MMC_SUPPORT @@ -587,30 +576,29 @@ static bool sd_cm6_set_high_speed(void) * * \return true if success, otherwise false */ -static bool mmc_cmd6_set_bus_width(uint8_t bus_width) -{ - uint32_t arg; +static bool mmc_cmd6_set_bus_width(uint8_t bus_width) { + uint32_t arg; - switch (bus_width) { - case 8: - arg = MMC_CMD6_ACCESS_SET_BITS | MMC_CMD6_INDEX_BUS_WIDTH | MMC_CMD6_VALUE_BUS_WIDTH_8BIT; - break; - case 4: - arg = MMC_CMD6_ACCESS_SET_BITS | MMC_CMD6_INDEX_BUS_WIDTH | MMC_CMD6_VALUE_BUS_WIDTH_4BIT; - break; - default: - arg = MMC_CMD6_ACCESS_SET_BITS | MMC_CMD6_INDEX_BUS_WIDTH | MMC_CMD6_VALUE_BUS_WIDTH_1BIT; - break; - } - if (!driver_send_cmd(sd_mmc_hal, MMC_CMD6_SWITCH, arg)) { - return false; - } - if (driver_get_response(sd_mmc_hal) & CARD_STATUS_SWITCH_ERROR) { - /* No supported, it is not a protocol error */ - return false; - } - sd_mmc_card->bus_width = bus_width; - return true; + switch (bus_width) { + case 8: + arg = MMC_CMD6_ACCESS_SET_BITS | MMC_CMD6_INDEX_BUS_WIDTH | MMC_CMD6_VALUE_BUS_WIDTH_8BIT; + break; + case 4: + arg = MMC_CMD6_ACCESS_SET_BITS | MMC_CMD6_INDEX_BUS_WIDTH | MMC_CMD6_VALUE_BUS_WIDTH_4BIT; + break; + default: + arg = MMC_CMD6_ACCESS_SET_BITS | MMC_CMD6_INDEX_BUS_WIDTH | MMC_CMD6_VALUE_BUS_WIDTH_1BIT; + break; + } + if (!driver_send_cmd(sd_mmc_hal, MMC_CMD6_SWITCH, arg)) { + return false; + } + if (driver_get_response(sd_mmc_hal) & CARD_STATUS_SWITCH_ERROR) { + /* No supported, it is not a protocol error */ + return false; + } + sd_mmc_card->bus_width = bus_width; + return true; } /** @@ -622,20 +610,19 @@ static bool mmc_cmd6_set_bus_width(uint8_t bus_width) * * \return true if success, otherwise false */ -static bool mmc_cmd6_set_high_speed(void) -{ - if (!driver_send_cmd(sd_mmc_hal, - MMC_CMD6_SWITCH, - MMC_CMD6_ACCESS_WRITE_BYTE | MMC_CMD6_INDEX_HS_TIMING | MMC_CMD6_VALUE_HS_TIMING_ENABLE)) { - return false; - } - if (driver_get_response(sd_mmc_hal) & CARD_STATUS_SWITCH_ERROR) { - /* No supported, it is not a protocol error */ - return false; - } - sd_mmc_card->high_speed = 1; - sd_mmc_card->clock = 52000000lu; - return true; +static bool mmc_cmd6_set_high_speed(void) { + if (!driver_send_cmd(sd_mmc_hal, + MMC_CMD6_SWITCH, + MMC_CMD6_ACCESS_WRITE_BYTE | MMC_CMD6_INDEX_HS_TIMING | MMC_CMD6_VALUE_HS_TIMING_ENABLE)) { + return false; + } + if (driver_get_response(sd_mmc_hal) & CARD_STATUS_SWITCH_ERROR) { + /* No supported, it is not a protocol error */ + return false; + } + sd_mmc_card->high_speed = 1; + sd_mmc_card->clock = 52000000lu; + return true; } #endif @@ -652,26 +639,25 @@ static bool mmc_cmd6_set_high_speed(void) * \return true if success, otherwise false * with a update of \ref sd_mmc_err. */ -static bool sd_cmd8(uint8_t *v2) -{ - uint32_t resp; +static bool sd_cmd8(uint8_t *v2) { + uint32_t resp; - *v2 = 0; - /* Test for SD version 2 */ - if (!driver_send_cmd(sd_mmc_hal, SD_CMD8_SEND_IF_COND, SD_CMD8_PATTERN | SD_CMD8_HIGH_VOLTAGE)) { - return true; /* It is not a V2 */ - } - /* Check R7 response */ - resp = driver_get_response(sd_mmc_hal); - if (resp == 0xFFFFFFFF) { - /* No compliance R7 value */ - return true; /* It is not a V2 */ - } - if ((resp & (SD_CMD8_MASK_PATTERN | SD_CMD8_MASK_VOLTAGE)) != (SD_CMD8_PATTERN | SD_CMD8_HIGH_VOLTAGE)) { - return false; - } - *v2 = 1; - return true; + *v2 = 0; + /* Test for SD version 2 */ + if (!driver_send_cmd(sd_mmc_hal, SD_CMD8_SEND_IF_COND, SD_CMD8_PATTERN | SD_CMD8_HIGH_VOLTAGE)) { + return true; /* It is not a V2 */ + } + /* Check R7 response */ + resp = driver_get_response(sd_mmc_hal); + if (resp == 0xFFFFFFFF) { + /* No compliance R7 value */ + return true; /* It is not a V2 */ + } + if ((resp & (SD_CMD8_MASK_PATTERN | SD_CMD8_MASK_VOLTAGE)) != (SD_CMD8_PATTERN | SD_CMD8_HIGH_VOLTAGE)) { + return false; + } + *v2 = 1; + return true; } #if CONF_MMC_SUPPORT @@ -683,43 +669,42 @@ static bool sd_cmd8(uint8_t *v2) * * \return true if success, otherwise false */ -static bool mmc_cmd8(uint8_t *b_authorize_high_speed) -{ - uint16_t i; - uint32_t ext_csd; - uint32_t sec_count; +static bool mmc_cmd8(uint8_t *b_authorize_high_speed) { + uint16_t i; + uint32_t ext_csd; + uint32_t sec_count; - if (!driver_adtc_start(sd_mmc_hal, MMC_CMD8_SEND_EXT_CSD, 0, EXT_CSD_BSIZE, 1, false)) { - return false; - } - /* Read and decode Extended Extended CSD - * Note: The read access is done in byte to avoid a buffer - * of EXT_CSD_BSIZE Byte in stack.*/ + if (!driver_adtc_start(sd_mmc_hal, MMC_CMD8_SEND_EXT_CSD, 0, EXT_CSD_BSIZE, 1, false)) { + return false; + } + /* Read and decode Extended Extended CSD + * Note: The read access is done in byte to avoid a buffer + * of EXT_CSD_BSIZE Byte in stack.*/ - /* Read card type */ - for (i = 0; i < (EXT_CSD_CARD_TYPE_INDEX + 4) / 4; i++) { - if (!driver_read_word(sd_mmc_hal, &ext_csd)) { - return false; - } - } - *b_authorize_high_speed = (ext_csd >> ((EXT_CSD_CARD_TYPE_INDEX % 4) * 8)) & MMC_CTYPE_52MHZ; + /* Read card type */ + for (i = 0; i < (EXT_CSD_CARD_TYPE_INDEX + 4) / 4; i++) { + if (!driver_read_word(sd_mmc_hal, &ext_csd)) { + return false; + } + } + *b_authorize_high_speed = (ext_csd >> ((EXT_CSD_CARD_TYPE_INDEX % 4) * 8)) & MMC_CTYPE_52MHZ; - if (MMC_CSD_C_SIZE(sd_mmc_card->csd) == 0xFFF) { - /* For high capacity SD/MMC card, - * memory capacity = SEC_COUNT * 512 byte */ - for (; i < (EXT_CSD_SEC_COUNT_INDEX + 4) / 4; i++) { - if (!driver_read_word(sd_mmc_hal, &sec_count)) { - return false; - } - } - sd_mmc_card->capacity = sec_count / 2; - } - for (; i < EXT_CSD_BSIZE / 4; i++) { - if (!driver_read_word(sd_mmc_hal, &sec_count)) { - return false; - } - } - return true; + if (MMC_CSD_C_SIZE(sd_mmc_card->csd) == 0xFFF) { + /* For high capacity SD/MMC card, + * memory capacity = SEC_COUNT * 512 byte */ + for (; i < (EXT_CSD_SEC_COUNT_INDEX + 4) / 4; i++) { + if (!driver_read_word(sd_mmc_hal, &sec_count)) { + return false; + } + } + sd_mmc_card->capacity = sec_count / 2; + } + for (; i < EXT_CSD_BSIZE / 4; i++) { + if (!driver_read_word(sd_mmc_hal, &sec_count)) { + return false; + } + } + return true; } #endif @@ -730,111 +715,108 @@ static bool mmc_cmd8(uint8_t *b_authorize_high_speed) * * \return true if success, otherwise false */ -static bool sd_mmc_cmd9_mci(void) -{ - if (!driver_send_cmd(sd_mmc_hal, SDMMC_MCI_CMD9_SEND_CSD, (uint32_t)sd_mmc_card->rca << 16)) { - return false; - } - driver_get_response_128(sd_mmc_hal, sd_mmc_card->csd); - return true; +static bool sd_mmc_cmd9_mci(void) { + if (!driver_send_cmd(sd_mmc_hal, SDMMC_MCI_CMD9_SEND_CSD, (uint32_t)sd_mmc_card->rca << 16)) { + return false; + } + driver_get_response_128(sd_mmc_hal, sd_mmc_card->csd); + return true; } #if CONF_MMC_SUPPORT /** * \brief Decodes MMC CSD register */ -static void mmc_decode_csd(void) -{ - uint32_t unit; - uint32_t mul; - uint32_t tran_speed; +static void mmc_decode_csd(void) { + uint32_t unit; + uint32_t mul; + uint32_t tran_speed; - /* Get MMC System Specification version supported by the card */ - switch (MMC_CSD_SPEC_VERS(sd_mmc_card->csd)) { - default: - case 0: - sd_mmc_card->version = CARD_VER_MMC_1_2; - break; + /* Get MMC System Specification version supported by the card */ + switch (MMC_CSD_SPEC_VERS(sd_mmc_card->csd)) { + default: + case 0: + sd_mmc_card->version = CARD_VER_MMC_1_2; + break; - case 1: - sd_mmc_card->version = CARD_VER_MMC_1_4; - break; + case 1: + sd_mmc_card->version = CARD_VER_MMC_1_4; + break; - case 2: - sd_mmc_card->version = CARD_VER_MMC_2_2; - break; + case 2: + sd_mmc_card->version = CARD_VER_MMC_2_2; + break; - case 3: - sd_mmc_card->version = CARD_VER_MMC_3; - break; + case 3: + sd_mmc_card->version = CARD_VER_MMC_3; + break; - case 4: - sd_mmc_card->version = CARD_VER_MMC_4; - break; - } + case 4: + sd_mmc_card->version = CARD_VER_MMC_4; + break; + } - /* Get MMC memory max transfer speed in Hz.*/ - tran_speed = CSD_TRAN_SPEED(sd_mmc_card->csd); - unit = sd_mmc_trans_units[tran_speed & 0x7]; - mul = mmc_trans_multipliers[(tran_speed >> 3) & 0xF]; - sd_mmc_card->clock = unit * mul * 1000; + /* Get MMC memory max transfer speed in Hz.*/ + tran_speed = CSD_TRAN_SPEED(sd_mmc_card->csd); + unit = sd_mmc_trans_units[tran_speed & 0x7]; + mul = mmc_trans_multipliers[(tran_speed >> 3) & 0xF]; + sd_mmc_card->clock = unit * mul * 1000; - /* - * Get card capacity. - * ---------------------------------------------------- - * For normal SD/MMC card: - * memory capacity = BLOCKNR * BLOCK_LEN - * Where - * BLOCKNR = (C_SIZE+1) * MULT - * MULT = 2 ^ (C_SIZE_MULT+2) (C_SIZE_MULT < 8) - * BLOCK_LEN = 2 ^ READ_BL_LEN (READ_BL_LEN < 12) - * ---------------------------------------------------- - * For high capacity SD/MMC card: - * memory capacity = SEC_COUNT * 512 byte - */ - if (MMC_CSD_C_SIZE(sd_mmc_card->csd) != 0xFFF) { - uint32_t blocknr - = ((MMC_CSD_C_SIZE(sd_mmc_card->csd) + 1) * (1 << (MMC_CSD_C_SIZE_MULT(sd_mmc_card->csd) + 2))); - sd_mmc_card->capacity = blocknr * (1 << MMC_CSD_READ_BL_LEN(sd_mmc_card->csd)) / 1024; - } + /* + * Get card capacity. + * ---------------------------------------------------- + * For normal SD/MMC card: + * memory capacity = BLOCKNR * BLOCK_LEN + * Where + * BLOCKNR = (C_SIZE+1) * MULT + * MULT = 2 ^ (C_SIZE_MULT+2) (C_SIZE_MULT < 8) + * BLOCK_LEN = 2 ^ READ_BL_LEN (READ_BL_LEN < 12) + * ---------------------------------------------------- + * For high capacity SD/MMC card: + * memory capacity = SEC_COUNT * 512 byte + */ + if (MMC_CSD_C_SIZE(sd_mmc_card->csd) != 0xFFF) { + uint32_t blocknr + = ((MMC_CSD_C_SIZE(sd_mmc_card->csd) + 1) * (1 << (MMC_CSD_C_SIZE_MULT(sd_mmc_card->csd) + 2))); + sd_mmc_card->capacity = blocknr * (1 << MMC_CSD_READ_BL_LEN(sd_mmc_card->csd)) / 1024; + } } #endif /** * \brief Decodes SD CSD register */ -static void sd_decode_csd(void) -{ - uint32_t unit; - uint32_t mul; - uint32_t tran_speed; +static void sd_decode_csd(void) { + uint32_t unit; + uint32_t mul; + uint32_t tran_speed; - /* Get SD memory maximum transfer speed in Hz. */ - tran_speed = CSD_TRAN_SPEED(sd_mmc_card->csd); - unit = sd_mmc_trans_units[tran_speed & 0x7]; - mul = sd_trans_multipliers[(tran_speed >> 3) & 0xF]; - sd_mmc_card->clock = unit * mul * 1000; + /* Get SD memory maximum transfer speed in Hz. */ + tran_speed = CSD_TRAN_SPEED(sd_mmc_card->csd); + unit = sd_mmc_trans_units[tran_speed & 0x7]; + mul = sd_trans_multipliers[(tran_speed >> 3) & 0xF]; + sd_mmc_card->clock = unit * mul * 1000; - /* - * Get card capacity. - * ---------------------------------------------------- - * For normal SD/MMC card: - * memory capacity = BLOCKNR * BLOCK_LEN - * Where - * BLOCKNR = (C_SIZE+1) * MULT - * MULT = 2 ^ (C_SIZE_MULT+2) (C_SIZE_MULT < 8) - * BLOCK_LEN = 2 ^ READ_BL_LEN (READ_BL_LEN < 12) - * ---------------------------------------------------- - * For high capacity SD card: - * memory capacity = (C_SIZE+1) * 512K byte - */ - if (CSD_STRUCTURE_VERSION(sd_mmc_card->csd) >= SD_CSD_VER_2_0) { - sd_mmc_card->capacity = (SD_CSD_2_0_C_SIZE(sd_mmc_card->csd) + 1) * 512; - } else { - uint32_t blocknr - = ((SD_CSD_1_0_C_SIZE(sd_mmc_card->csd) + 1) * (1 << (SD_CSD_1_0_C_SIZE_MULT(sd_mmc_card->csd) + 2))); - sd_mmc_card->capacity = blocknr * (1 << SD_CSD_1_0_READ_BL_LEN(sd_mmc_card->csd)) / 1024; - } + /* + * Get card capacity. + * ---------------------------------------------------- + * For normal SD/MMC card: + * memory capacity = BLOCKNR * BLOCK_LEN + * Where + * BLOCKNR = (C_SIZE+1) * MULT + * MULT = 2 ^ (C_SIZE_MULT+2) (C_SIZE_MULT < 8) + * BLOCK_LEN = 2 ^ READ_BL_LEN (READ_BL_LEN < 12) + * ---------------------------------------------------- + * For high capacity SD card: + * memory capacity = (C_SIZE+1) * 512K byte + */ + if (CSD_STRUCTURE_VERSION(sd_mmc_card->csd) >= SD_CSD_VER_2_0) { + sd_mmc_card->capacity = (SD_CSD_2_0_C_SIZE(sd_mmc_card->csd) + 1) * 512; + } else { + uint32_t blocknr + = ((SD_CSD_1_0_C_SIZE(sd_mmc_card->csd) + 1) * (1 << (SD_CSD_1_0_C_SIZE_MULT(sd_mmc_card->csd) + 2))); + sd_mmc_card->capacity = blocknr * (1 << SD_CSD_1_0_READ_BL_LEN(sd_mmc_card->csd)) / 1024; + } } /** @@ -843,30 +825,29 @@ static void sd_decode_csd(void) * * \return true if success, otherwise false */ -static bool sd_mmc_cmd13(void) -{ - uint32_t nec_timeout; +static bool sd_mmc_cmd13(void) { + uint32_t nec_timeout; - /* Wait for data ready status. - * Nec timing: 0 to unlimited - * However a timeout is used. - * 200 000 * 8 cycles - */ - nec_timeout = 200000; - do { - if (!driver_send_cmd(sd_mmc_hal, SDMMC_MCI_CMD13_SEND_STATUS, (uint32_t)sd_mmc_card->rca << 16)) { - return false; - } - /* Check busy flag */ - if (driver_get_response(sd_mmc_hal) & CARD_STATUS_READY_FOR_DATA) { - break; - } - if (nec_timeout-- == 0) { - return false; - } - } while (1); + /* Wait for data ready status. + * Nec timing: 0 to unlimited + * However a timeout is used. + * 200 000 * 8 cycles + */ + nec_timeout = 200000; + do { + if (!driver_send_cmd(sd_mmc_hal, SDMMC_MCI_CMD13_SEND_STATUS, (uint32_t)sd_mmc_card->rca << 16)) { + return false; + } + /* Check busy flag */ + if (driver_get_response(sd_mmc_hal) & CARD_STATUS_READY_FOR_DATA) { + break; + } + if (nec_timeout-- == 0) { + return false; + } + } while (1); - return true; + return true; } #if (CONF_SDIO_SUPPORT == 1) @@ -881,19 +862,18 @@ static bool sd_mmc_cmd13(void) * * \return true if success, otherwise false */ -static bool sdio_cmd52(uint8_t rw_flag, uint8_t func_nb, uint32_t reg_addr, uint8_t rd_after_wr, uint8_t *io_data) -{ - ASSERT(io_data != NULL); - if (!driver_send_cmd(sd_mmc_hal, - SDIO_CMD52_IO_RW_DIRECT, - ((uint32_t)*io_data << SDIO_CMD52_WR_DATA) | ((uint32_t)rw_flag << SDIO_CMD52_RW_FLAG) - | ((uint32_t)func_nb << SDIO_CMD52_FUNCTION_NUM) - | ((uint32_t)rd_after_wr << SDIO_CMD52_RAW_FLAG) - | ((uint32_t)reg_addr << SDIO_CMD52_REG_ADRR))) { - return false; - } - *io_data = driver_get_response(sd_mmc_hal) & 0xFF; - return true; +static bool sdio_cmd52(uint8_t rw_flag, uint8_t func_nb, uint32_t reg_addr, uint8_t rd_after_wr, uint8_t *io_data) { + ASSERT(io_data != NULL); + if (!driver_send_cmd(sd_mmc_hal, + SDIO_CMD52_IO_RW_DIRECT, + ((uint32_t)*io_data << SDIO_CMD52_WR_DATA) | ((uint32_t)rw_flag << SDIO_CMD52_RW_FLAG) + | ((uint32_t)func_nb << SDIO_CMD52_FUNCTION_NUM) + | ((uint32_t)rd_after_wr << SDIO_CMD52_RAW_FLAG) + | ((uint32_t)reg_addr << SDIO_CMD52_REG_ADRR))) { + return false; + } + *io_data = driver_get_response(sd_mmc_hal) & 0xFF; + return true; } /** @@ -912,20 +892,19 @@ static bool sdio_cmd52(uint8_t rw_flag, uint8_t func_nb, uint32_t reg_addr, uint * \return true if success, otherwise false */ static bool sdio_cmd53(uint8_t rw_flag, uint8_t func_nb, uint32_t reg_addr, uint8_t inc_addr, uint32_t size, - bool access_block) -{ - ASSERT(size != 0); - ASSERT(size <= 512); + bool access_block) { + ASSERT(size != 0); + ASSERT(size <= 512); - return driver_adtc_start( - sd_mmc_hal, - (rw_flag == SDIO_CMD53_READ_FLAG) ? SDIO_CMD53_IO_R_BYTE_EXTENDED : SDIO_CMD53_IO_W_BYTE_EXTENDED, - ((size % 512) << SDIO_CMD53_COUNT) | ((uint32_t)reg_addr << SDIO_CMD53_REG_ADDR) - | ((uint32_t)inc_addr << SDIO_CMD53_OP_CODE) | ((uint32_t)0 << SDIO_CMD53_BLOCK_MODE) - | ((uint32_t)func_nb << SDIO_CMD53_FUNCTION_NUM) | ((uint32_t)rw_flag << SDIO_CMD53_RW_FLAG), - size, - 1, - access_block); + return driver_adtc_start( + sd_mmc_hal, + (rw_flag == SDIO_CMD53_READ_FLAG) ? SDIO_CMD53_IO_R_BYTE_EXTENDED : SDIO_CMD53_IO_W_BYTE_EXTENDED, + ((size % 512) << SDIO_CMD53_COUNT) | ((uint32_t)reg_addr << SDIO_CMD53_REG_ADDR) + | ((uint32_t)inc_addr << SDIO_CMD53_OP_CODE) | ((uint32_t)0 << SDIO_CMD53_BLOCK_MODE) + | ((uint32_t)func_nb << SDIO_CMD53_FUNCTION_NUM) | ((uint32_t)rw_flag << SDIO_CMD53_RW_FLAG), + size, + 1, + access_block); } #endif @@ -934,19 +913,18 @@ static bool sdio_cmd53(uint8_t rw_flag, uint8_t func_nb, uint32_t reg_addr, uint * * \return true if success, otherwise false */ -static bool sd_acmd6(void) -{ - /* CMD55 - Indicate to the card that the next command is an - * application specific command rather than a standard command.*/ - if (!driver_send_cmd(sd_mmc_hal, SDMMC_CMD55_APP_CMD, (uint32_t)sd_mmc_card->rca << 16)) { - return false; - } - /* 10b = 4 bits bus */ - if (!driver_send_cmd(sd_mmc_hal, SD_ACMD6_SET_BUS_WIDTH, 0x2)) { - return false; - } - sd_mmc_card->bus_width = 4; - return true; +static bool sd_acmd6(void) { + /* CMD55 - Indicate to the card that the next command is an + * application specific command rather than a standard command.*/ + if (!driver_send_cmd(sd_mmc_hal, SDMMC_CMD55_APP_CMD, (uint32_t)sd_mmc_card->rca << 16)) { + return false; + } + /* 10b = 4 bits bus */ + if (!driver_send_cmd(sd_mmc_hal, SD_ACMD6_SET_BUS_WIDTH, 0x2)) { + return false; + } + sd_mmc_card->bus_width = 4; + return true; } /** @@ -960,48 +938,47 @@ static bool sd_acmd6(void) * * \return true if success, otherwise false */ -static bool sd_acmd51(void) -{ - uint8_t scr[SD_SCR_REG_BSIZE]; +static bool sd_acmd51(void) { + uint8_t scr[SD_SCR_REG_BSIZE]; - /* CMD55 - Indicate to the card that the next command is an - * application specific command rather than a standard command.*/ - if (!driver_send_cmd(sd_mmc_hal, SDMMC_CMD55_APP_CMD, (uint32_t)sd_mmc_card->rca << 16)) { - return false; - } - if (!driver_adtc_start(sd_mmc_hal, SD_ACMD51_SEND_SCR, 0, SD_SCR_REG_BSIZE, 1, true)) { - return false; - } - if (!driver_start_read_blocks(sd_mmc_hal, scr, 1)) { - return false; - } - if (!driver_wait_end_of_read_blocks(sd_mmc_hal)) { - return false; - } + /* CMD55 - Indicate to the card that the next command is an + * application specific command rather than a standard command.*/ + if (!driver_send_cmd(sd_mmc_hal, SDMMC_CMD55_APP_CMD, (uint32_t)sd_mmc_card->rca << 16)) { + return false; + } + if (!driver_adtc_start(sd_mmc_hal, SD_ACMD51_SEND_SCR, 0, SD_SCR_REG_BSIZE, 1, true)) { + return false; + } + if (!driver_start_read_blocks(sd_mmc_hal, scr, 1)) { + return false; + } + if (!driver_wait_end_of_read_blocks(sd_mmc_hal)) { + return false; + } - /* Get SD Memory Card - Spec. Version */ - switch (SD_SCR_SD_SPEC(scr)) { - case SD_SCR_SD_SPEC_1_0_01: - sd_mmc_card->version = CARD_VER_SD_1_0; - break; + /* Get SD Memory Card - Spec. Version */ + switch (SD_SCR_SD_SPEC(scr)) { + case SD_SCR_SD_SPEC_1_0_01: + sd_mmc_card->version = CARD_VER_SD_1_0; + break; - case SD_SCR_SD_SPEC_1_10: - sd_mmc_card->version = CARD_VER_SD_1_10; - break; + case SD_SCR_SD_SPEC_1_10: + sd_mmc_card->version = CARD_VER_SD_1_10; + break; - case SD_SCR_SD_SPEC_2_00: - if (SD_SCR_SD_SPEC3(scr) == SD_SCR_SD_SPEC_3_00) { - sd_mmc_card->version = CARD_VER_SD_3_0; - } else { - sd_mmc_card->version = CARD_VER_SD_2_0; - } - break; + case SD_SCR_SD_SPEC_2_00: + if (SD_SCR_SD_SPEC3(scr) == SD_SCR_SD_SPEC_3_00) { + sd_mmc_card->version = CARD_VER_SD_3_0; + } else { + sd_mmc_card->version = CARD_VER_SD_2_0; + } + break; - default: - sd_mmc_card->version = CARD_VER_SD_1_0; - break; - } - return true; + default: + sd_mmc_card->version = CARD_VER_SD_1_0; + break; + } + return true; } /** @@ -1015,82 +992,79 @@ static bool sd_acmd51(void) * \retval SD_MMC_INIT_ONGOING Card initialization requested * \retval SD_MMC_OK Card present */ -static sd_mmc_err_t sd_mmc_select_slot(uint8_t slot) -{ - if (slot >= CONF_SD_MMC_MEM_CNT) { - return SD_MMC_ERR_SLOT; - } +static sd_mmc_err_t sd_mmc_select_slot(uint8_t slot) { + if (slot >= CONF_SD_MMC_MEM_CNT) { + return SD_MMC_ERR_SLOT; + } - if (_cd && _cd[slot].pin != -1) { - /** Card Detect pins */ - if (gpio_get_pin_level(_cd[slot].pin) != _cd[slot].val) { - if (sd_mmc_cards[slot].state == SD_MMC_CARD_STATE_DEBOUNCE) { - SD_MMC_STOP_TIMEOUT(); - } - sd_mmc_cards[slot].state = SD_MMC_CARD_STATE_NO_CARD; - return SD_MMC_ERR_NO_CARD; - } - if (sd_mmc_cards[slot].state == SD_MMC_CARD_STATE_NO_CARD) { - /* A card plug on going, but this is not initialized */ - sd_mmc_cards[slot].state = SD_MMC_CARD_STATE_DEBOUNCE; - /* Debounce + Power On Setup */ - SD_MMC_START_TIMEOUT(); - return SD_MMC_ERR_NO_CARD; - } - if (sd_mmc_cards[slot].state == SD_MMC_CARD_STATE_DEBOUNCE) { - if (!SD_MMC_IS_TIMEOUT()) { - /* Debounce on going */ - return SD_MMC_ERR_NO_CARD; - } - /* Card is not initialized */ - sd_mmc_cards[slot].state = SD_MMC_CARD_STATE_INIT; - /* Set 1-bit bus width and low clock for initialization */ - sd_mmc_cards[slot].clock = SDMMC_CLOCK_INIT; - sd_mmc_cards[slot].bus_width = 1; - sd_mmc_cards[slot].high_speed = 0; - } - if (sd_mmc_cards[slot].state == SD_MMC_CARD_STATE_UNUSABLE) { - return SD_MMC_ERR_UNUSABLE; - } - } else { - /* No pin card detection, then always try to install it */ - if ((sd_mmc_cards[slot].state == SD_MMC_CARD_STATE_NO_CARD) - || (sd_mmc_cards[slot].state == SD_MMC_CARD_STATE_UNUSABLE)) { - /* Card is not initialized */ - sd_mmc_cards[slot].state = SD_MMC_CARD_STATE_INIT; - /* Set 1-bit bus width and low clock for initialization */ - sd_mmc_cards[slot].clock = SDMMC_CLOCK_INIT; - sd_mmc_cards[slot].bus_width = 1; - sd_mmc_cards[slot].high_speed = 0; - } - } + if (_cd && _cd[slot].pin != -1) { + /** Card Detect pins */ + if (gpio_get_pin_level(_cd[slot].pin) != _cd[slot].val) { + if (sd_mmc_cards[slot].state == SD_MMC_CARD_STATE_DEBOUNCE) { + SD_MMC_STOP_TIMEOUT(); + } + sd_mmc_cards[slot].state = SD_MMC_CARD_STATE_NO_CARD; + return SD_MMC_ERR_NO_CARD; + } + if (sd_mmc_cards[slot].state == SD_MMC_CARD_STATE_NO_CARD) { + /* A card plug on going, but this is not initialized */ + sd_mmc_cards[slot].state = SD_MMC_CARD_STATE_DEBOUNCE; + /* Debounce + Power On Setup */ + SD_MMC_START_TIMEOUT(); + return SD_MMC_ERR_NO_CARD; + } + if (sd_mmc_cards[slot].state == SD_MMC_CARD_STATE_DEBOUNCE) { + if (!SD_MMC_IS_TIMEOUT()) { + /* Debounce on going */ + return SD_MMC_ERR_NO_CARD; + } + /* Card is not initialized */ + sd_mmc_cards[slot].state = SD_MMC_CARD_STATE_INIT; + /* Set 1-bit bus width and low clock for initialization */ + sd_mmc_cards[slot].clock = SDMMC_CLOCK_INIT; + sd_mmc_cards[slot].bus_width = 1; + sd_mmc_cards[slot].high_speed = 0; + } + if (sd_mmc_cards[slot].state == SD_MMC_CARD_STATE_UNUSABLE) { + return SD_MMC_ERR_UNUSABLE; + } + } else { + /* No pin card detection, then always try to install it */ + if ((sd_mmc_cards[slot].state == SD_MMC_CARD_STATE_NO_CARD) + || (sd_mmc_cards[slot].state == SD_MMC_CARD_STATE_UNUSABLE)) { + /* Card is not initialized */ + sd_mmc_cards[slot].state = SD_MMC_CARD_STATE_INIT; + /* Set 1-bit bus width and low clock for initialization */ + sd_mmc_cards[slot].clock = SDMMC_CLOCK_INIT; + sd_mmc_cards[slot].bus_width = 1; + sd_mmc_cards[slot].high_speed = 0; + } + } - ASSERT(!(sd_mmc_slot_sel != slot && sd_mmc_nb_block_remaining != 0)); + ASSERT(!(sd_mmc_slot_sel != slot && sd_mmc_nb_block_remaining != 0)); - /* Initialize interface */ - sd_mmc_slot_sel = slot; - sd_mmc_card = &sd_mmc_cards[slot]; - sd_mmc_configure_slot(); - return (sd_mmc_cards[slot].state == SD_MMC_CARD_STATE_INIT) ? SD_MMC_INIT_ONGOING : SD_MMC_OK; + /* Initialize interface */ + sd_mmc_slot_sel = slot; + sd_mmc_card = &sd_mmc_cards[slot]; + sd_mmc_configure_slot(); + return (sd_mmc_cards[slot].state == SD_MMC_CARD_STATE_INIT) ? SD_MMC_INIT_ONGOING : SD_MMC_OK; } /** * \brief Configures the driver with the selected card configuration */ -static void sd_mmc_configure_slot(void) -{ - driver_select_device( - sd_mmc_hal, sd_mmc_slot_sel, sd_mmc_card->clock, sd_mmc_card->bus_width, sd_mmc_card->high_speed); +static void sd_mmc_configure_slot(void) { + driver_select_device( + sd_mmc_hal, sd_mmc_slot_sel, sd_mmc_card->clock, sd_mmc_card->bus_width, sd_mmc_card->high_speed); } /** * \brief Deselect the current card slot */ -static void sd_mmc_deselect_slot(void) -{ - if (sd_mmc_slot_sel < CONF_SD_MMC_MEM_CNT) { - driver_deselect_device(sd_mmc_hal, sd_mmc_slot_sel); - } +static void sd_mmc_deselect_slot(void) { + if (sd_mmc_slot_sel < CONF_SD_MMC_MEM_CNT) { + driver_deselect_device(sd_mmc_hal, sd_mmc_slot_sel); + } } /** @@ -1103,126 +1077,125 @@ static void sd_mmc_deselect_slot(void) * * \return true if success, otherwise false */ -static bool sd_mmc_mci_card_init(void) -{ - uint8_t v2 = 0; -#if (CONF_SDIO_SUPPORT == 1) - uint8_t data = 0x08; -#endif +static bool sd_mmc_mci_card_init(void) { + uint8_t v2 = 0; + #if (CONF_SDIO_SUPPORT == 1) + uint8_t data = 0x08; + #endif - /* In first, try to install SD/SDIO card */ - sd_mmc_card->type = CARD_TYPE_SD; - sd_mmc_card->version = CARD_VER_UNKNOWN; - sd_mmc_card->rca = 0; + /* In first, try to install SD/SDIO card */ + sd_mmc_card->type = CARD_TYPE_SD; + sd_mmc_card->version = CARD_VER_UNKNOWN; + sd_mmc_card->rca = 0; - /* Card need of 74 cycles clock minimum to start */ - driver_send_clock(sd_mmc_hal); + /* Card need of 74 cycles clock minimum to start */ + driver_send_clock(sd_mmc_hal); -#if (CONF_SDIO_SUPPORT == 1) - /* CMD52 Reset SDIO */ - sdio_cmd52(SDIO_CMD52_WRITE_FLAG, SDIO_CIA, SDIO_CCCR_IOA, 0, &data); -#endif + #if (CONF_SDIO_SUPPORT == 1) + /* CMD52 Reset SDIO */ + sdio_cmd52(SDIO_CMD52_WRITE_FLAG, SDIO_CIA, SDIO_CCCR_IOA, 0, &data); + #endif - /* CMD0 - Reset all cards to idle state.*/ - if (!driver_send_cmd(sd_mmc_hal, SDMMC_MCI_CMD0_GO_IDLE_STATE, 0)) { - return false; - } - if (!sd_cmd8(&v2)) { - return false; - } - /* Try to get the SDIO card's operating condition */ - if (!sdio_op_cond()) { - return false; - } + /* CMD0 - Reset all cards to idle state.*/ + if (!driver_send_cmd(sd_mmc_hal, SDMMC_MCI_CMD0_GO_IDLE_STATE, 0)) { + return false; + } + if (!sd_cmd8(&v2)) { + return false; + } + /* Try to get the SDIO card's operating condition */ + if (!sdio_op_cond()) { + return false; + } - if (sd_mmc_card->type & CARD_TYPE_SD) { - /* Try to get the SD card's operating condition */ - if (!sd_mci_op_cond(v2)) { - /* It is not a SD card */ -#if CONF_MMC_SUPPORT - sd_mmc_card->type = CARD_TYPE_MMC; - return sd_mmc_mci_install_mmc(); -#else - sd_mmc_card->type = CARD_TYPE_UNKNOWN; - return false; -#endif - } - } + if (sd_mmc_card->type & CARD_TYPE_SD) { + /* Try to get the SD card's operating condition */ + if (!sd_mci_op_cond(v2)) { + /* It is not a SD card */ + #if CONF_MMC_SUPPORT + sd_mmc_card->type = CARD_TYPE_MMC; + return sd_mmc_mci_install_mmc(); + #else + sd_mmc_card->type = CARD_TYPE_UNKNOWN; + return false; + #endif + } + } - if (sd_mmc_card->type & CARD_TYPE_SD) { - /* SD MEMORY, Put the Card in Identify Mode - * Note: The CID is not used in this stack */ - if (!driver_send_cmd(sd_mmc_hal, SDMMC_CMD2_ALL_SEND_CID, 0)) { - return false; - } - } - /* Ask the card to publish a new relative address (RCA).*/ - if (!driver_send_cmd(sd_mmc_hal, SD_CMD3_SEND_RELATIVE_ADDR, 0)) { - return false; - } - sd_mmc_card->rca = (driver_get_response(sd_mmc_hal) >> 16) & 0xFFFF; + if (sd_mmc_card->type & CARD_TYPE_SD) { + /* SD MEMORY, Put the Card in Identify Mode + * Note: The CID is not used in this stack */ + if (!driver_send_cmd(sd_mmc_hal, SDMMC_CMD2_ALL_SEND_CID, 0)) { + return false; + } + } + /* Ask the card to publish a new relative address (RCA).*/ + if (!driver_send_cmd(sd_mmc_hal, SD_CMD3_SEND_RELATIVE_ADDR, 0)) { + return false; + } + sd_mmc_card->rca = (driver_get_response(sd_mmc_hal) >> 16) & 0xFFFF; - /* SD MEMORY, Get the Card-Specific Data */ - if (sd_mmc_card->type & CARD_TYPE_SD) { - if (!sd_mmc_cmd9_mci()) { - return false; - } - sd_decode_csd(); - } - /* Select the and put it into Transfer Mode */ - if (!driver_send_cmd(sd_mmc_hal, SDMMC_CMD7_SELECT_CARD_CMD, (uint32_t)sd_mmc_card->rca << 16)) { - return false; - } - /* SD MEMORY, Read the SCR to get card version */ - if (sd_mmc_card->type & CARD_TYPE_SD) { - if (!sd_acmd51()) { - return false; - } - } - if (IS_SDIO()) { - if (!sdio_get_max_speed()) { - return false; - } - } - if ((4 <= driver_get_bus_width(sd_mmc_hal, sd_mmc_slot_sel))) { - /* TRY to enable 4-bit mode */ - if (IS_SDIO()) { - if (!sdio_cmd52_set_bus_width()) { - return false; - } - } - if (sd_mmc_card->type & CARD_TYPE_SD) { - if (!sd_acmd6()) { - return false; - } - } - /* Switch to selected bus mode */ - sd_mmc_configure_slot(); - } - if (driver_is_high_speed_capable(sd_mmc_hal)) { - /* TRY to enable High-Speed Mode */ - if (IS_SDIO()) { - if (!sdio_cmd52_set_high_speed()) { - return false; - } - } - if (sd_mmc_card->type & CARD_TYPE_SD) { - if (sd_mmc_card->version > CARD_VER_SD_1_0) { - if (!sd_cm6_set_high_speed()) { - return false; - } - } - } - /* Valid new configuration */ - sd_mmc_configure_slot(); - } - /* SD MEMORY, Set default block size */ - if (sd_mmc_card->type & CARD_TYPE_SD) { - if (!driver_send_cmd(sd_mmc_hal, SDMMC_CMD16_SET_BLOCKLEN, SD_MMC_BLOCK_SIZE)) { - return false; - } - } - return true; + /* SD MEMORY, Get the Card-Specific Data */ + if (sd_mmc_card->type & CARD_TYPE_SD) { + if (!sd_mmc_cmd9_mci()) { + return false; + } + sd_decode_csd(); + } + /* Select the and put it into Transfer Mode */ + if (!driver_send_cmd(sd_mmc_hal, SDMMC_CMD7_SELECT_CARD_CMD, (uint32_t)sd_mmc_card->rca << 16)) { + return false; + } + /* SD MEMORY, Read the SCR to get card version */ + if (sd_mmc_card->type & CARD_TYPE_SD) { + if (!sd_acmd51()) { + return false; + } + } + if (IS_SDIO()) { + if (!sdio_get_max_speed()) { + return false; + } + } + if ((4 <= driver_get_bus_width(sd_mmc_hal, sd_mmc_slot_sel))) { + /* TRY to enable 4-bit mode */ + if (IS_SDIO()) { + if (!sdio_cmd52_set_bus_width()) { + return false; + } + } + if (sd_mmc_card->type & CARD_TYPE_SD) { + if (!sd_acmd6()) { + return false; + } + } + /* Switch to selected bus mode */ + sd_mmc_configure_slot(); + } + if (driver_is_high_speed_capable(sd_mmc_hal)) { + /* TRY to enable High-Speed Mode */ + if (IS_SDIO()) { + if (!sdio_cmd52_set_high_speed()) { + return false; + } + } + if (sd_mmc_card->type & CARD_TYPE_SD) { + if (sd_mmc_card->version > CARD_VER_SD_1_0) { + if (!sd_cm6_set_high_speed()) { + return false; + } + } + } + /* Valid new configuration */ + sd_mmc_configure_slot(); + } + /* SD MEMORY, Set default block size */ + if (sd_mmc_card->type & CARD_TYPE_SD) { + if (!driver_send_cmd(sd_mmc_hal, SDMMC_CMD16_SET_BLOCKLEN, SD_MMC_BLOCK_SIZE)) { + return false; + } + } + return true; } #if CONF_MMC_SUPPORT @@ -1236,435 +1209,417 @@ static bool sd_mmc_mci_card_init(void) * * \return true if success, otherwise false */ -static bool sd_mmc_mci_install_mmc(void) -{ - uint8_t b_authorize_high_speed; +static bool sd_mmc_mci_install_mmc(void) { + uint8_t b_authorize_high_speed; - /* CMD0 - Reset all cards to idle state. */ - if (!driver_send_cmd(sd_mmc_hal, SDMMC_MCI_CMD0_GO_IDLE_STATE, 0)) { - return false; - } + /* CMD0 - Reset all cards to idle state. */ + if (!driver_send_cmd(sd_mmc_hal, SDMMC_MCI_CMD0_GO_IDLE_STATE, 0)) { + return false; + } - if (!mmc_mci_op_cond()) { - return false; - } + if (!mmc_mci_op_cond()) { + return false; + } - /* Put the Card in Identify Mode - * Note: The CID is not used in this stack*/ - if (!driver_send_cmd(sd_mmc_hal, SDMMC_CMD2_ALL_SEND_CID, 0)) { - return false; - } - /* Assign relative address to the card.*/ - sd_mmc_card->rca = 1; - if (!driver_send_cmd(sd_mmc_hal, MMC_CMD3_SET_RELATIVE_ADDR, (uint32_t)sd_mmc_card->rca << 16)) { - return false; - } - /* Get the Card-Specific Data */ - if (!sd_mmc_cmd9_mci()) { - return false; - } - mmc_decode_csd(); - /* Select the and put it into Transfer Mode */ - if (!driver_send_cmd(sd_mmc_hal, SDMMC_CMD7_SELECT_CARD_CMD, (uint32_t)sd_mmc_card->rca << 16)) { - return false; - } - if (sd_mmc_card->version >= CARD_VER_MMC_4) { - /* For MMC 4.0 Higher version - * Get EXT_CSD */ - if (!mmc_cmd8(&b_authorize_high_speed)) { - return false; - } - if (4 <= driver_get_bus_width(sd_mmc_hal, sd_mmc_slot_sel)) { - /* Enable more bus width */ - if (!mmc_cmd6_set_bus_width(driver_get_bus_width(sd_mmc_hal, sd_mmc_slot_sel))) { - return false; - } - /* Reinitialize the slot with the bus width */ - sd_mmc_configure_slot(); - } - if (driver_is_high_speed_capable(sd_mmc_hal) && b_authorize_high_speed) { - /* Enable HS */ - if (!mmc_cmd6_set_high_speed()) { - return false; - } - /* Reinitialize the slot with the new speed */ - sd_mmc_configure_slot(); - } - } else { - /* Reinitialize the slot with the new speed */ - sd_mmc_configure_slot(); - } + /* Put the Card in Identify Mode + * Note: The CID is not used in this stack*/ + if (!driver_send_cmd(sd_mmc_hal, SDMMC_CMD2_ALL_SEND_CID, 0)) { + return false; + } + /* Assign relative address to the card.*/ + sd_mmc_card->rca = 1; + if (!driver_send_cmd(sd_mmc_hal, MMC_CMD3_SET_RELATIVE_ADDR, (uint32_t)sd_mmc_card->rca << 16)) { + return false; + } + /* Get the Card-Specific Data */ + if (!sd_mmc_cmd9_mci()) { + return false; + } + mmc_decode_csd(); + /* Select the and put it into Transfer Mode */ + if (!driver_send_cmd(sd_mmc_hal, SDMMC_CMD7_SELECT_CARD_CMD, (uint32_t)sd_mmc_card->rca << 16)) { + return false; + } + if (sd_mmc_card->version >= CARD_VER_MMC_4) { + /* For MMC 4.0 Higher version + * Get EXT_CSD */ + if (!mmc_cmd8(&b_authorize_high_speed)) { + return false; + } + if (4 <= driver_get_bus_width(sd_mmc_hal, sd_mmc_slot_sel)) { + /* Enable more bus width */ + if (!mmc_cmd6_set_bus_width(driver_get_bus_width(sd_mmc_hal, sd_mmc_slot_sel))) { + return false; + } + /* Reinitialize the slot with the bus width */ + sd_mmc_configure_slot(); + } + if (driver_is_high_speed_capable(sd_mmc_hal) && b_authorize_high_speed) { + /* Enable HS */ + if (!mmc_cmd6_set_high_speed()) { + return false; + } + /* Reinitialize the slot with the new speed */ + sd_mmc_configure_slot(); + } + } else { + /* Reinitialize the slot with the new speed */ + sd_mmc_configure_slot(); + } - uint8_t retry = 10; - while (retry--) { - /* Retry is a WORKAROUND for no compliance card (Atmel Internal ref. MMC19): - * These cards seem not ready immediatly - * after the end of busy of mmc_cmd6_set_high_speed()*/ + uint8_t retry = 10; + while (retry--) { + /* Retry is a WORKAROUND for no compliance card (Atmel Internal ref. MMC19): + * These cards seem not ready immediatly + * after the end of busy of mmc_cmd6_set_high_speed()*/ - /* Set default block size */ - if (driver_send_cmd(sd_mmc_hal, SDMMC_CMD16_SET_BLOCKLEN, SD_MMC_BLOCK_SIZE)) { - return true; - } - } - return false; + /* Set default block size */ + if (driver_send_cmd(sd_mmc_hal, SDMMC_CMD16_SET_BLOCKLEN, SD_MMC_BLOCK_SIZE)) { + return true; + } + } + return false; } #endif /*--------------------- PUBLIC FUNCTIONS ----------------------------*/ -void sd_mmc_init(void *hal, sd_mmc_detect_t *card_detects, sd_mmc_detect_t *wp_detects) -{ - /* GPIO will be used to detect card and write protect. - * The related clocks and pinmux must be configurated in good - * condition. */ +void sd_mmc_init(void *hal, sd_mmc_detect_t *card_detects, sd_mmc_detect_t *wp_detects) { + /* GPIO will be used to detect card and write protect. + * The related clocks and pinmux must be configurated in good + * condition. */ - for (uint8_t slot = 0; slot < CONF_SD_MMC_MEM_CNT; slot++) { - sd_mmc_cards[slot].state = SD_MMC_CARD_STATE_NO_CARD; - } - sd_mmc_slot_sel = 0xFF; /* No slot configurated */ - sd_mmc_hal = hal; - _cd = card_detects; - _wp = wp_detects; + for (uint8_t slot = 0; slot < CONF_SD_MMC_MEM_CNT; slot++) { + sd_mmc_cards[slot].state = SD_MMC_CARD_STATE_NO_CARD; + } + sd_mmc_slot_sel = 0xFF; /* No slot configurated */ + sd_mmc_hal = hal; + _cd = card_detects; + _wp = wp_detects; } -uint8_t sd_mmc_nb_slot(void) -{ - return CONF_SD_MMC_MEM_CNT; +uint8_t sd_mmc_nb_slot(void) { + return CONF_SD_MMC_MEM_CNT; } -sd_mmc_err_t sd_mmc_check(uint8_t slot) -{ - sd_mmc_err_t sd_mmc_err; +sd_mmc_err_t sd_mmc_check(uint8_t slot) { + sd_mmc_err_t sd_mmc_err; - sd_mmc_err = sd_mmc_select_slot(slot); - if (sd_mmc_err != SD_MMC_INIT_ONGOING) { - sd_mmc_deselect_slot(); - return sd_mmc_err; - } + sd_mmc_err = sd_mmc_select_slot(slot); + if (sd_mmc_err != SD_MMC_INIT_ONGOING) { + sd_mmc_deselect_slot(); + return sd_mmc_err; + } - /* Initialization of the card requested */ - if (sd_mmc_mci_card_init()) { - sd_mmc_card->state = SD_MMC_CARD_STATE_READY; - sd_mmc_deselect_slot(); - /* To notify that the card has been just initialized - * It is necessary for USB Device MSC */ - return SD_MMC_INIT_ONGOING; - } - sd_mmc_card->state = SD_MMC_CARD_STATE_UNUSABLE; - sd_mmc_deselect_slot(); - return SD_MMC_ERR_UNUSABLE; + /* Initialization of the card requested */ + if (sd_mmc_mci_card_init()) { + sd_mmc_card->state = SD_MMC_CARD_STATE_READY; + sd_mmc_deselect_slot(); + /* To notify that the card has been just initialized + * It is necessary for USB Device MSC */ + return SD_MMC_INIT_ONGOING; + } + sd_mmc_card->state = SD_MMC_CARD_STATE_UNUSABLE; + sd_mmc_deselect_slot(); + return SD_MMC_ERR_UNUSABLE; } -card_type_t sd_mmc_get_type(uint8_t slot) -{ - if (SD_MMC_OK != sd_mmc_select_slot(slot)) { - return CARD_TYPE_UNKNOWN; - } - sd_mmc_deselect_slot(); - return sd_mmc_card->type; +card_type_t sd_mmc_get_type(uint8_t slot) { + if (SD_MMC_OK != sd_mmc_select_slot(slot)) { + return CARD_TYPE_UNKNOWN; + } + sd_mmc_deselect_slot(); + return sd_mmc_card->type; } -card_version_t sd_mmc_get_version(uint8_t slot) -{ - if (SD_MMC_OK != sd_mmc_select_slot(slot)) { - return CARD_VER_UNKNOWN; - } - sd_mmc_deselect_slot(); - return sd_mmc_card->version; +card_version_t sd_mmc_get_version(uint8_t slot) { + if (SD_MMC_OK != sd_mmc_select_slot(slot)) { + return CARD_VER_UNKNOWN; + } + sd_mmc_deselect_slot(); + return sd_mmc_card->version; } -uint32_t sd_mmc_get_capacity(uint8_t slot) -{ - if (SD_MMC_OK != sd_mmc_select_slot(slot)) { - return 0; - } - sd_mmc_deselect_slot(); - return sd_mmc_card->capacity; +uint32_t sd_mmc_get_capacity(uint8_t slot) { + if (SD_MMC_OK != sd_mmc_select_slot(slot)) { + return 0; + } + sd_mmc_deselect_slot(); + return sd_mmc_card->capacity; } -bool sd_mmc_is_write_protected(uint8_t slot) -{ - /* No detection, always writable */ - if (!_wp || _wp[slot].pin == -1) { - return false; - } - /* Write Protect Detect */ - if (gpio_get_pin_level(_wp[slot].pin) == _wp[slot].val) { - return true; - } - return false; +bool sd_mmc_is_write_protected(uint8_t slot) { + /* No detection, always writable */ + if (!_wp || _wp[slot].pin == -1) { + return false; + } + /* Write Protect Detect */ + if (gpio_get_pin_level(_wp[slot].pin) == _wp[slot].val) { + return true; + } + return false; } -sd_mmc_err_t sd_mmc_init_read_blocks(uint8_t slot, uint32_t start, uint16_t nb_block) -{ - sd_mmc_err_t sd_mmc_err; - uint32_t cmd, arg, resp; +sd_mmc_err_t sd_mmc_init_read_blocks(uint8_t slot, uint32_t start, uint16_t nb_block) { + sd_mmc_err_t sd_mmc_err; + uint32_t cmd, arg, resp; - sd_mmc_err = sd_mmc_select_slot(slot); - if (sd_mmc_err != SD_MMC_OK) { - return sd_mmc_err; - } + sd_mmc_err = sd_mmc_select_slot(slot); + if (sd_mmc_err != SD_MMC_OK) { + return sd_mmc_err; + } - /* Wait for data ready status */ - if (!sd_mmc_cmd13()) { - sd_mmc_deselect_slot(); - return SD_MMC_ERR_COMM; - } + /* Wait for data ready status */ + if (!sd_mmc_cmd13()) { + sd_mmc_deselect_slot(); + return SD_MMC_ERR_COMM; + } - if (nb_block > 1) { - cmd = SDMMC_CMD18_READ_MULTIPLE_BLOCK; - } else { - cmd = SDMMC_CMD17_READ_SINGLE_BLOCK; - } - /* - * SDSC Card (CCS=0) uses byte unit address, - * SDHC and SDXC Cards (CCS=1) use block unit address (512 Bytes unit). - */ - if (sd_mmc_card->type & CARD_TYPE_HC) { - arg = start; - } else { - arg = (start * SD_MMC_BLOCK_SIZE); - } + if (nb_block > 1) { + cmd = SDMMC_CMD18_READ_MULTIPLE_BLOCK; + } else { + cmd = SDMMC_CMD17_READ_SINGLE_BLOCK; + } + /* + * SDSC Card (CCS=0) uses byte unit address, + * SDHC and SDXC Cards (CCS=1) use block unit address (512 Bytes unit). + */ + if (sd_mmc_card->type & CARD_TYPE_HC) { + arg = start; + } else { + arg = (start * SD_MMC_BLOCK_SIZE); + } - if (!driver_adtc_start(sd_mmc_hal, cmd, arg, SD_MMC_BLOCK_SIZE, nb_block, true)) { - sd_mmc_deselect_slot(); - return SD_MMC_ERR_COMM; - } - /* Check response */ - resp = driver_get_response(sd_mmc_hal); - if (resp & CARD_STATUS_ERR_RD_WR) { - sd_mmc_deselect_slot(); - return SD_MMC_ERR_COMM; - } + if (!driver_adtc_start(sd_mmc_hal, cmd, arg, SD_MMC_BLOCK_SIZE, nb_block, true)) { + sd_mmc_deselect_slot(); + return SD_MMC_ERR_COMM; + } + /* Check response */ + resp = driver_get_response(sd_mmc_hal); + if (resp & CARD_STATUS_ERR_RD_WR) { + sd_mmc_deselect_slot(); + return SD_MMC_ERR_COMM; + } - sd_mmc_nb_block_remaining = nb_block; - sd_mmc_nb_block_to_tranfer = nb_block; - return SD_MMC_OK; + sd_mmc_nb_block_remaining = nb_block; + sd_mmc_nb_block_to_tranfer = nb_block; + return SD_MMC_OK; } -sd_mmc_err_t sd_mmc_start_read_blocks(void *dest, uint16_t nb_block) -{ - ASSERT(sd_mmc_nb_block_remaining >= nb_block); +sd_mmc_err_t sd_mmc_start_read_blocks(void *dest, uint16_t nb_block) { + ASSERT(sd_mmc_nb_block_remaining >= nb_block); - if (!driver_start_read_blocks(sd_mmc_hal, dest, nb_block)) { - sd_mmc_nb_block_remaining = 0; - return SD_MMC_ERR_COMM; - } - sd_mmc_nb_block_remaining -= nb_block; - return SD_MMC_OK; + if (!driver_start_read_blocks(sd_mmc_hal, dest, nb_block)) { + sd_mmc_nb_block_remaining = 0; + return SD_MMC_ERR_COMM; + } + sd_mmc_nb_block_remaining -= nb_block; + return SD_MMC_OK; } -sd_mmc_err_t sd_mmc_wait_end_of_read_blocks(bool abort) -{ - if (!driver_wait_end_of_read_blocks(sd_mmc_hal)) { - return SD_MMC_ERR_COMM; - } - if (abort) { - sd_mmc_nb_block_remaining = 0; - } else if (sd_mmc_nb_block_remaining) { - return SD_MMC_OK; - } +sd_mmc_err_t sd_mmc_wait_end_of_read_blocks(bool abort) { + if (!driver_wait_end_of_read_blocks(sd_mmc_hal)) { + return SD_MMC_ERR_COMM; + } + if (abort) { + sd_mmc_nb_block_remaining = 0; + } else if (sd_mmc_nb_block_remaining) { + return SD_MMC_OK; + } - /* All blocks are transfered then stop read operation */ - if (sd_mmc_nb_block_to_tranfer == 1) { - /* Single block transfer, then nothing to do */ - sd_mmc_deselect_slot(); - return SD_MMC_OK; - } - /* WORKAROUND for no compliance card (Atmel Internal ref. !MMC7 !SD19): - * The errors on this command must be ignored - * and one retry can be necessary in SPI mode for no compliance card.*/ - if (!driver_adtc_stop(sd_mmc_hal, SDMMC_CMD12_STOP_TRANSMISSION, 0)) { - driver_adtc_stop(sd_mmc_hal, SDMMC_CMD12_STOP_TRANSMISSION, 0); - } - sd_mmc_deselect_slot(); - return SD_MMC_OK; + /* All blocks are transfered then stop read operation */ + if (sd_mmc_nb_block_to_tranfer == 1) { + /* Single block transfer, then nothing to do */ + sd_mmc_deselect_slot(); + return SD_MMC_OK; + } + /* WORKAROUND for no compliance card (Atmel Internal ref. !MMC7 !SD19): + * The errors on this command must be ignored + * and one retry can be necessary in SPI mode for no compliance card.*/ + if (!driver_adtc_stop(sd_mmc_hal, SDMMC_CMD12_STOP_TRANSMISSION, 0)) { + driver_adtc_stop(sd_mmc_hal, SDMMC_CMD12_STOP_TRANSMISSION, 0); + } + sd_mmc_deselect_slot(); + return SD_MMC_OK; } -sd_mmc_err_t sd_mmc_init_write_blocks(uint8_t slot, uint32_t start, uint16_t nb_block) -{ - sd_mmc_err_t sd_mmc_err; - uint32_t cmd, arg, resp; +sd_mmc_err_t sd_mmc_init_write_blocks(uint8_t slot, uint32_t start, uint16_t nb_block) { + sd_mmc_err_t sd_mmc_err; + uint32_t cmd, arg, resp; - sd_mmc_err = sd_mmc_select_slot(slot); - if (sd_mmc_err != SD_MMC_OK) { - return sd_mmc_err; - } - if (sd_mmc_is_write_protected(slot)) { - sd_mmc_deselect_slot(); - return SD_MMC_ERR_WP; - } + sd_mmc_err = sd_mmc_select_slot(slot); + if (sd_mmc_err != SD_MMC_OK) { + return sd_mmc_err; + } + if (sd_mmc_is_write_protected(slot)) { + sd_mmc_deselect_slot(); + return SD_MMC_ERR_WP; + } - if (nb_block > 1) { - cmd = SDMMC_CMD25_WRITE_MULTIPLE_BLOCK; - } else { - cmd = SDMMC_CMD24_WRITE_BLOCK; - } - /* - * SDSC Card (CCS=0) uses byte unit address, - * SDHC and SDXC Cards (CCS=1) use block unit address (512 Bytes unit). - */ - if (sd_mmc_card->type & CARD_TYPE_HC) { - arg = start; - } else { - arg = (start * SD_MMC_BLOCK_SIZE); - } - if (!driver_adtc_start(sd_mmc_hal, cmd, arg, SD_MMC_BLOCK_SIZE, nb_block, true)) { - sd_mmc_deselect_slot(); - return SD_MMC_ERR_COMM; - } - /* Check response */ - resp = driver_get_response(sd_mmc_hal); - if (resp & CARD_STATUS_ERR_RD_WR) { - sd_mmc_deselect_slot(); - return SD_MMC_ERR_COMM; - } + if (nb_block > 1) { + cmd = SDMMC_CMD25_WRITE_MULTIPLE_BLOCK; + } else { + cmd = SDMMC_CMD24_WRITE_BLOCK; + } + /* + * SDSC Card (CCS=0) uses byte unit address, + * SDHC and SDXC Cards (CCS=1) use block unit address (512 Bytes unit). + */ + if (sd_mmc_card->type & CARD_TYPE_HC) { + arg = start; + } else { + arg = (start * SD_MMC_BLOCK_SIZE); + } + if (!driver_adtc_start(sd_mmc_hal, cmd, arg, SD_MMC_BLOCK_SIZE, nb_block, true)) { + sd_mmc_deselect_slot(); + return SD_MMC_ERR_COMM; + } + /* Check response */ + resp = driver_get_response(sd_mmc_hal); + if (resp & CARD_STATUS_ERR_RD_WR) { + sd_mmc_deselect_slot(); + return SD_MMC_ERR_COMM; + } - sd_mmc_nb_block_remaining = nb_block; - sd_mmc_nb_block_to_tranfer = nb_block; - return SD_MMC_OK; + sd_mmc_nb_block_remaining = nb_block; + sd_mmc_nb_block_to_tranfer = nb_block; + return SD_MMC_OK; } -sd_mmc_err_t sd_mmc_start_write_blocks(const void *src, uint16_t nb_block) -{ - ASSERT(sd_mmc_nb_block_remaining >= nb_block); - if (!driver_start_write_blocks(sd_mmc_hal, src, nb_block)) { - sd_mmc_nb_block_remaining = 0; - return SD_MMC_ERR_COMM; - } - sd_mmc_nb_block_remaining -= nb_block; - return SD_MMC_OK; +sd_mmc_err_t sd_mmc_start_write_blocks(const void *src, uint16_t nb_block) { + ASSERT(sd_mmc_nb_block_remaining >= nb_block); + if (!driver_start_write_blocks(sd_mmc_hal, src, nb_block)) { + sd_mmc_nb_block_remaining = 0; + return SD_MMC_ERR_COMM; + } + sd_mmc_nb_block_remaining -= nb_block; + return SD_MMC_OK; } -sd_mmc_err_t sd_mmc_wait_end_of_write_blocks(bool abort) -{ - if (!driver_wait_end_of_write_blocks(sd_mmc_hal)) { - return SD_MMC_ERR_COMM; - } - if (abort) { - sd_mmc_nb_block_remaining = 0; - } else if (sd_mmc_nb_block_remaining) { - return SD_MMC_OK; - } +sd_mmc_err_t sd_mmc_wait_end_of_write_blocks(bool abort) { + if (!driver_wait_end_of_write_blocks(sd_mmc_hal)) { + return SD_MMC_ERR_COMM; + } + if (abort) { + sd_mmc_nb_block_remaining = 0; + } else if (sd_mmc_nb_block_remaining) { + return SD_MMC_OK; + } - /* All blocks are transfered then stop write operation */ - if (sd_mmc_nb_block_to_tranfer == 1) { - /* Single block transfer, then nothing to do */ - sd_mmc_deselect_slot(); - return SD_MMC_OK; - } + /* All blocks are transfered then stop write operation */ + if (sd_mmc_nb_block_to_tranfer == 1) { + /* Single block transfer, then nothing to do */ + sd_mmc_deselect_slot(); + return SD_MMC_OK; + } - /* Note: SPI multiblock writes terminate using a special - * token, not a STOP_TRANSMISSION request.*/ - if (!driver_adtc_stop(sd_mmc_hal, SDMMC_CMD12_STOP_TRANSMISSION, 0)) { - sd_mmc_deselect_slot(); - return SD_MMC_ERR_COMM; - } + /* Note: SPI multiblock writes terminate using a special + * token, not a STOP_TRANSMISSION request.*/ + if (!driver_adtc_stop(sd_mmc_hal, SDMMC_CMD12_STOP_TRANSMISSION, 0)) { + sd_mmc_deselect_slot(); + return SD_MMC_ERR_COMM; + } - sd_mmc_deselect_slot(); - return SD_MMC_OK; + sd_mmc_deselect_slot(); + return SD_MMC_OK; } #if (CONF_SDIO_SUPPORT == 1) -sd_mmc_err_t sdio_read_direct(uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t *dest) -{ - sd_mmc_err_t sd_mmc_err; +sd_mmc_err_t sdio_read_direct(uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t *dest) { + sd_mmc_err_t sd_mmc_err; - if (dest == NULL) { - return SD_MMC_ERR_PARAM; - } + if (dest == NULL) { + return SD_MMC_ERR_PARAM; + } - sd_mmc_err = sd_mmc_select_slot(slot); - if (sd_mmc_err != SD_MMC_OK) { - return sd_mmc_err; - } + sd_mmc_err = sd_mmc_select_slot(slot); + if (sd_mmc_err != SD_MMC_OK) { + return sd_mmc_err; + } - if (!sdio_cmd52(SDIO_CMD52_READ_FLAG, func_num, addr, 0, dest)) { - sd_mmc_deselect_slot(); - return SD_MMC_ERR_COMM; - } - sd_mmc_deselect_slot(); - return SD_MMC_OK; + if (!sdio_cmd52(SDIO_CMD52_READ_FLAG, func_num, addr, 0, dest)) { + sd_mmc_deselect_slot(); + return SD_MMC_ERR_COMM; + } + sd_mmc_deselect_slot(); + return SD_MMC_OK; } -sd_mmc_err_t sdio_write_direct(uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t data) -{ - sd_mmc_err_t sd_mmc_err; +sd_mmc_err_t sdio_write_direct(uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t data) { + sd_mmc_err_t sd_mmc_err; - sd_mmc_err = sd_mmc_select_slot(slot); - if (sd_mmc_err != SD_MMC_OK) { - return sd_mmc_err; - } + sd_mmc_err = sd_mmc_select_slot(slot); + if (sd_mmc_err != SD_MMC_OK) { + return sd_mmc_err; + } - if (!sdio_cmd52(SDIO_CMD52_WRITE_FLAG, func_num, addr, 0, &data)) { - sd_mmc_deselect_slot(); - return SD_MMC_ERR_COMM; - } + if (!sdio_cmd52(SDIO_CMD52_WRITE_FLAG, func_num, addr, 0, &data)) { + sd_mmc_deselect_slot(); + return SD_MMC_ERR_COMM; + } - sd_mmc_deselect_slot(); - return SD_MMC_OK; + sd_mmc_deselect_slot(); + return SD_MMC_OK; } sd_mmc_err_t sdio_read_extended(uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t inc_addr, uint8_t *dest, - uint16_t size) -{ - sd_mmc_err_t sd_mmc_err; + uint16_t size) { + sd_mmc_err_t sd_mmc_err; - if ((size == 0) || (size > 512)) { - return SD_MMC_ERR_PARAM; - } + if ((size == 0) || (size > 512)) { + return SD_MMC_ERR_PARAM; + } - sd_mmc_err = sd_mmc_select_slot(slot); - if (sd_mmc_err != SD_MMC_OK) { - return sd_mmc_err; - } + sd_mmc_err = sd_mmc_select_slot(slot); + if (sd_mmc_err != SD_MMC_OK) { + return sd_mmc_err; + } - if (!sdio_cmd53(SDIO_CMD53_READ_FLAG, func_num, addr, inc_addr, size, true)) { - sd_mmc_deselect_slot(); - return SD_MMC_ERR_COMM; - } - if (!driver_start_read_blocks(sd_mmc_hal, dest, 1)) { - sd_mmc_deselect_slot(); - return SD_MMC_ERR_COMM; - } - if (!driver_wait_end_of_read_blocks(sd_mmc_hal)) { - sd_mmc_deselect_slot(); - return SD_MMC_ERR_COMM; - } + if (!sdio_cmd53(SDIO_CMD53_READ_FLAG, func_num, addr, inc_addr, size, true)) { + sd_mmc_deselect_slot(); + return SD_MMC_ERR_COMM; + } + if (!driver_start_read_blocks(sd_mmc_hal, dest, 1)) { + sd_mmc_deselect_slot(); + return SD_MMC_ERR_COMM; + } + if (!driver_wait_end_of_read_blocks(sd_mmc_hal)) { + sd_mmc_deselect_slot(); + return SD_MMC_ERR_COMM; + } - sd_mmc_deselect_slot(); - return SD_MMC_OK; + sd_mmc_deselect_slot(); + return SD_MMC_OK; } sd_mmc_err_t sdio_write_extended(uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t inc_addr, uint8_t *src, - uint16_t size) -{ - sd_mmc_err_t sd_mmc_err; + uint16_t size) { + sd_mmc_err_t sd_mmc_err; - if ((size == 0) || (size > 512)) { - return SD_MMC_ERR_PARAM; - } + if ((size == 0) || (size > 512)) { + return SD_MMC_ERR_PARAM; + } - sd_mmc_err = sd_mmc_select_slot(slot); - if (sd_mmc_err != SD_MMC_OK) { - return sd_mmc_err; - } + sd_mmc_err = sd_mmc_select_slot(slot); + if (sd_mmc_err != SD_MMC_OK) { + return sd_mmc_err; + } - if (!sdio_cmd53(SDIO_CMD53_WRITE_FLAG, func_num, addr, inc_addr, size, true)) { - sd_mmc_deselect_slot(); - return SD_MMC_ERR_COMM; - } - if (!driver_start_write_blocks(sd_mmc_hal, src, 1)) { - sd_mmc_deselect_slot(); - return SD_MMC_ERR_COMM; - } - if (!driver_wait_end_of_write_blocks(sd_mmc_hal)) { - sd_mmc_deselect_slot(); - return SD_MMC_ERR_COMM; - } + if (!sdio_cmd53(SDIO_CMD53_WRITE_FLAG, func_num, addr, inc_addr, size, true)) { + sd_mmc_deselect_slot(); + return SD_MMC_ERR_COMM; + } + if (!driver_start_write_blocks(sd_mmc_hal, src, 1)) { + sd_mmc_deselect_slot(); + return SD_MMC_ERR_COMM; + } + if (!driver_wait_end_of_write_blocks(sd_mmc_hal)) { + sd_mmc_deselect_slot(); + return SD_MMC_ERR_COMM; + } - sd_mmc_deselect_slot(); - return SD_MMC_OK; + sd_mmc_deselect_slot(); + return SD_MMC_OK; } #endif diff --git a/ports/atmel-samd/sd_mmc/sd_mmc.h b/ports/atmel-samd/sd_mmc/sd_mmc.h index 1437e5efd5..e51bf17e80 100644 --- a/ports/atmel-samd/sd_mmc/sd_mmc.h +++ b/ports/atmel-samd/sd_mmc/sd_mmc.h @@ -104,8 +104,8 @@ typedef uint8_t card_version_t; /**< Type of card version */ /** Card detect setting */ typedef struct sd_mmc_detect { - int16_t pin; /**< Detection pin, -1 if no such pin */ - uint16_t val; /**< Detection value */ + int16_t pin; /**< Detection pin, -1 if no such pin */ + uint16_t val; /**< Detection value */ } sd_mmc_detect_t; /** This SD MMC stack uses the maximum block size autorized (512 bytes) */ @@ -281,7 +281,7 @@ sd_mmc_err_t sdio_write_direct(uint8_t slot, uint8_t func_num, uint32_t addr, ui * otherwise return an error code (\ref sd_mmc_err_t). */ sd_mmc_err_t sdio_read_extended(uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t inc_addr, uint8_t *dest, - uint16_t size); + uint16_t size); /** * \brief Write bytes to SDIO using RW_EXTENDED command. @@ -298,7 +298,7 @@ sd_mmc_err_t sdio_read_extended(uint8_t slot, uint8_t func_num, uint32_t addr, u * otherwise return an error code (\ref sd_mmc_err_t). */ sd_mmc_err_t sdio_write_extended(uint8_t slot, uint8_t func_num, uint32_t addr, uint8_t inc_addr, uint8_t *src, - uint16_t size); + uint16_t size); #endif /* SDIO_SUPPORT_ENABLE */ /** @} */ diff --git a/ports/atmel-samd/sd_mmc/sd_mmc_protocol.h b/ports/atmel-samd/sd_mmc/sd_mmc_protocol.h index 0516e4fd10..9b4d8e8e74 100644 --- a/ports/atmel-samd/sd_mmc/sd_mmc_protocol.h +++ b/ports/atmel-samd/sd_mmc/sd_mmc_protocol.h @@ -97,43 +97,43 @@ extern "C" { * @{ */ -//! Value to define a SD/MMC/SDIO command +// ! Value to define a SD/MMC/SDIO command typedef uint32_t sdmmc_cmd_def_t; -//! \name Flags used to define a SD/MMC/SDIO command -//! @{ +// ! \name Flags used to define a SD/MMC/SDIO command +// ! @{ #define SDMMC_CMD_GET_INDEX(cmd) (cmd & 0x3F) -//! Have response (MCI only) +// ! Have response (MCI only) #define SDMMC_RESP_PRESENT (1lu << 8) -//! 8 bit response (SPI only) +// ! 8 bit response (SPI only) #define SDMMC_RESP_8 (1lu << 9) -//! 32 bit response (SPI only) +// ! 32 bit response (SPI only) #define SDMMC_RESP_32 (1lu << 10) -//! 136 bit response (MCI only) +// ! 136 bit response (MCI only) #define SDMMC_RESP_136 (1lu << 11) -//! Expect valid crc (MCI only) +// ! Expect valid crc (MCI only) #define SDMMC_RESP_CRC (1lu << 12) -//! Card may send busy +// ! Card may send busy #define SDMMC_RESP_BUSY (1lu << 13) // Open drain for a braodcast command (bc) // or to enter in inactive state (MCI only) #define SDMMC_CMD_OPENDRAIN (1lu << 14) -//! To signal a data write operation +// ! To signal a data write operation #define SDMMC_CMD_WRITE (1lu << 15) -//! To signal a SDIO tranfer in multi byte mode +// ! To signal a SDIO tranfer in multi byte mode #define SDMMC_CMD_SDIO_BYTE (1lu << 16) -//! To signal a SDIO tranfer in block mode +// ! To signal a SDIO tranfer in block mode #define SDMMC_CMD_SDIO_BLOCK (1lu << 17) -//! To signal a data transfer in stream mode +// ! To signal a data transfer in stream mode #define SDMMC_CMD_STREAM (1lu << 18) -//! To signal a data transfer in single block mode +// ! To signal a data transfer in single block mode #define SDMMC_CMD_SINGLE_BLOCK (1lu << 19) -//! To signal a data transfer in multi block mode +// ! To signal a data transfer in multi block mode #define SDMMC_CMD_MULTI_BLOCK (1lu << 20) -//! @} +// ! @} -//! \name Set of flags to define a reponse type -//! @{ +// ! \name Set of flags to define a reponse type +// ! @{ #define SDMMC_CMD_NO_RESP (0) #define SDMMC_CMD_R1 (SDMMC_RESP_PRESENT | SDMMC_RESP_CRC) #define SDMMC_CMD_R1B (SDMMC_RESP_PRESENT | SDMMC_RESP_CRC | SDMMC_RESP_BUSY) @@ -143,14 +143,14 @@ typedef uint32_t sdmmc_cmd_def_t; #define SDMMC_CMD_R5 (SDMMC_RESP_PRESENT | SDMMC_RESP_8 | SDMMC_RESP_CRC) #define SDMMC_CMD_R6 (SDMMC_RESP_PRESENT | SDMMC_RESP_CRC) #define SDMMC_CMD_R7 (SDMMC_RESP_PRESENT | SDMMC_RESP_32 | SDMMC_RESP_CRC) -//! @} +// ! @} -//! \name SD/MMC/SDIO command definitions -//! SDMMC_CMDx are include in SD and MMC norms -//! MMC_CMDx are include in MMC norms only -//! SD_CMDx are include in SD norms only -//! SDIO_CMDx are include in SDIO norms only -//! @{ +// ! \name SD/MMC/SDIO command definitions +// ! SDMMC_CMDx are include in SD and MMC norms +// ! MMC_CMDx are include in MMC norms only +// ! SD_CMDx are include in SD norms only +// ! SDIO_CMDx are include in SDIO norms only +// ! @{ /* * --- Basic commands and read-stream command (class 0 and class 1) --- @@ -351,21 +351,21 @@ typedef uint32_t sdmmc_cmd_def_t; #define SDIO_CMD53_IO_W_BYTE_EXTENDED (53 | SDMMC_CMD_R5 | SDMMC_CMD_SDIO_BYTE | SDMMC_CMD_WRITE) #define SDIO_CMD53_IO_R_BLOCK_EXTENDED (53 | SDMMC_CMD_R5 | SDMMC_CMD_SDIO_BLOCK) #define SDIO_CMD53_IO_W_BLOCK_EXTENDED (53 | SDMMC_CMD_R5 | SDMMC_CMD_SDIO_BLOCK | SDMMC_CMD_WRITE) -//! @} -//! @} +// ! @} +// ! @} -//! \name Macros for command argument definition -//! @{ +// ! \name Macros for command argument definition +// ! @{ -//! \name MMC CMD6 argument structure -//! @{ -//! [31:26] Set to 0 -//! [25:24] Access +// ! \name MMC CMD6 argument structure +// ! @{ +// ! [31:26] Set to 0 +// ! [25:24] Access #define MMC_CMD6_ACCESS_COMMAND_SET (0lu << 24) #define MMC_CMD6_ACCESS_SET_BITS (1lu << 24) #define MMC_CMD6_ACCESS_CLEAR_BITS (2lu << 24) #define MMC_CMD6_ACCESS_WRITE_BYTE (3lu << 24) -//! [23:16] Index for Mode Segment +// ! [23:16] Index for Mode Segment #define MMC_CMD6_INDEX_CMD_SET (EXT_CSD_CMD_SET_INDEX << 16) #define MMC_CMD6_INDEX_CMD_SET_REV (EXT_CSD_CMD_SET_REV_INDEX << 16) #define MMC_CMD6_INDEX_POWER_CLASS (EXT_CSD_POWER_CLASS_INDEX << 16) @@ -375,61 +375,61 @@ typedef uint32_t sdmmc_cmd_def_t; #define MMC_CMD6_INDEX_BOOT_CONFIG (EXT_CSD_BOOT_CONFIG_INDEX << 16) #define MMC_CMD6_INDEX_BOOT_BUS_WIDTH (EXT_CSD_BOOT_BUS_WIDTH_INDEX << 16) #define MMC_CMD6_INDEX_ERASE_GROUP_DEF (EXT_CSD_ERASE_GROUP_DEF_INDEX << 16) -//! [15:8] Value +// ! [15:8] Value #define MMC_CMD6_VALUE_BUS_WIDTH_1BIT (0x0lu << 8) #define MMC_CMD6_VALUE_BUS_WIDTH_4BIT (0x1lu << 8) #define MMC_CMD6_VALUE_BUS_WIDTH_8BIT (0x2lu << 8) #define MMC_CMD6_VALUE_HS_TIMING_ENABLE (0x1lu << 8) #define MMC_CMD6_VALUE_HS_TIMING_DISABLE (0x0lu << 8) -//! [7:3] Set to 0 -//! [2:0] Cmd Set -//! @} +// ! [7:3] Set to 0 +// ! [2:0] Cmd Set +// ! @} -//! \name SD CMD6 argument structure -//! @{ -//! CMD6 arg[ 3: 0] function group 1, access mode +// ! \name SD CMD6 argument structure +// ! @{ +// ! CMD6 arg[ 3: 0] function group 1, access mode #define SD_CMD6_GRP1_HIGH_SPEED (0x1lu << 0) #define SD_CMD6_GRP1_DEFAULT (0x0lu << 0) -//! CMD6 arg[ 7: 4] function group 2, command system +// ! CMD6 arg[ 7: 4] function group 2, command system #define SD_CMD6_GRP2_NO_INFLUENCE (0xFlu << 4) #define SD_CMD6_GRP2_DEFAULT (0x0lu << 4) -//! CMD6 arg[11: 8] function group 3, 0xF or 0x0 +// ! CMD6 arg[11: 8] function group 3, 0xF or 0x0 #define SD_CMD6_GRP3_NO_INFLUENCE (0xFlu << 8) #define SD_CMD6_GRP3_DEFAULT (0x0lu << 8) -//! CMD6 arg[15:12] function group 4, 0xF or 0x0 +// ! CMD6 arg[15:12] function group 4, 0xF or 0x0 #define SD_CMD6_GRP4_NO_INFLUENCE (0xFlu << 12) #define SD_CMD6_GRP4_DEFAULT (0x0lu << 12) -//! CMD6 arg[19:16] function group 5, 0xF or 0x0 +// ! CMD6 arg[19:16] function group 5, 0xF or 0x0 #define SD_CMD6_GRP5_NO_INFLUENCE (0xFlu << 16) #define SD_CMD6_GRP5_DEFAULT (0x0lu << 16) -//! CMD6 arg[23:20] function group 6, 0xF or 0x0 +// ! CMD6 arg[23:20] function group 6, 0xF or 0x0 #define SD_CMD6_GRP6_NO_INFLUENCE (0xFlu << 20) #define SD_CMD6_GRP6_DEFAULT (0x0lu << 20) -//! CMD6 arg[30:24] reserved 0 -//! CMD6 arg[31 ] Mode, 0: Check, 1: Switch +// ! CMD6 arg[30:24] reserved 0 +// ! CMD6 arg[31 ] Mode, 0: Check, 1: Switch #define SD_CMD6_MODE_CHECK (0lu << 31) #define SD_CMD6_MODE_SWITCH (1lu << 31) -//! @} +// ! @} -//! \name SD CMD8 argument structure -//! @{ +// ! \name SD CMD8 argument structure +// ! @{ #define SD_CMD8_PATTERN 0xAA #define SD_CMD8_MASK_PATTERN 0xFF #define SD_CMD8_HIGH_VOLTAGE 0x100 #define SD_CMD8_MASK_VOLTAGE 0xF00 -//! @} +// ! @} -//! \name SD ACMD41 arguments -//! @{ -#define SD_ACMD41_HCS (1lu << 30) //!< (SD) Host Capacity Support - //! @} -//! @} +// ! \name SD ACMD41 arguments +// ! @{ +#define SD_ACMD41_HCS (1lu << 30) // !< (SD) Host Capacity Support + // ! @} +// ! @} -//! \name SDIO definitions -//! @{ +// ! \name SDIO definitions +// ! @{ -//! \name SDIO state (in R5) -//! @{ +// ! \name SDIO state (in R5) +// ! @{ #define SDIO_R5_COM_CRC_ERROR (1lu << 15) /**< CRC check error */ #define SDIO_R5_ILLEGAL_COMMAND (1lu << 14) /**< Illegal command */ #define SDIO_R5_STATE (3lu << 12) /**< SDIO R5 state mask */ @@ -440,11 +440,11 @@ typedef uint32_t sdmmc_cmd_def_t; #define SDIO_R5_ERROR (1lu << 11) /**< General error */ #define SDIO_R5_FUNC_NUM (1lu << 9) /**< Invalid function number */ #define SDIO_R5_OUT_OF_RANGE (1lu << 8) /**< Argument out of range */ -#define SDIO_R5_STATUS_ERR (SDIO_R5_ERROR | SDIO_R5_FUNC_NUM | SDIO_R5_OUT_OF_RANGE) //!< Errro status bits mask - //! @} +#define SDIO_R5_STATUS_ERR (SDIO_R5_ERROR | SDIO_R5_FUNC_NUM | SDIO_R5_OUT_OF_RANGE) // !< Errro status bits mask + // ! @} -//! \name SDIO state (in R6) -//! @{ +// ! \name SDIO state (in R6) +// ! @{ /** The CRC check of the previous command failed. */ #define SDIO_R6_COM_CRC_ERROR (1lu << 15) /** Command not legal for the card state. */ @@ -453,30 +453,30 @@ typedef uint32_t sdmmc_cmd_def_t; #define SDIO_R6_ERROR (1lu << 13) /** Status bits mask for SDIO R6 */ #define SDIO_STATUS_R6 (SDIO_R6_COM_CRC_ERROR | SDIO_R6_ILLEGAL_COMMAND | SDIO_R6_ERROR) -//! @} +// ! @} -//! \name SDIO CMD52 argument bit offset -//! @{ -//! CMD52 arg[ 7: 0] Write data or stuff bits +// ! \name SDIO CMD52 argument bit offset +// ! @{ +// ! CMD52 arg[ 7: 0] Write data or stuff bits #define SDIO_CMD52_WR_DATA 0 -//! CMD52 arg[ 8] Reserved +// ! CMD52 arg[ 8] Reserved #define SDIO_CMD52_STUFF0 8 -//! CMD52 arg[25: 9] Register address +// ! CMD52 arg[25: 9] Register address #define SDIO_CMD52_REG_ADRR 9 -//! CMD52 arg[ 26] Reserved +// ! CMD52 arg[ 26] Reserved #define SDIO_CMD52_STUFF1 26 -//! CMD52 arg[ 27] Read after Write flag +// ! CMD52 arg[ 27] Read after Write flag #define SDIO_CMD52_RAW_FLAG 27 -//! CMD52 arg[30:28] Number of the function +// ! CMD52 arg[30:28] Number of the function #define SDIO_CMD52_FUNCTION_NUM 28 -//! CMD52 arg[ 31] Direction, 1:write, 0:read. +// ! CMD52 arg[ 31] Direction, 1:write, 0:read. #define SDIO_CMD52_RW_FLAG 31 #define SDIO_CMD52_READ_FLAG 0 #define SDIO_CMD52_WRITE_FLAG 1 -//! @} +// ! @} -//! \name SDIO CMD53 argument structure -//! @{ +// ! \name SDIO CMD53 argument structure +// ! @{ /** * [ 8: 0] Byte mode: number of bytes to transfer, * 0 cause 512 bytes transfer. @@ -484,22 +484,22 @@ typedef uint32_t sdmmc_cmd_def_t; * 0 set count to infinite. */ #define SDIO_CMD53_COUNT 0 -//! CMD53 arg[25: 9] Start Address I/O register +// ! CMD53 arg[25: 9] Start Address I/O register #define SDIO_CMD53_REG_ADDR 9 -//! CMD53 arg[ 26] 1:Incrementing address, 0: fixed +// ! CMD53 arg[ 26] 1:Incrementing address, 0: fixed #define SDIO_CMD53_OP_CODE 26 -//! CMD53 arg[ 27] (Optional) 1:block mode +// ! CMD53 arg[ 27] (Optional) 1:block mode #define SDIO_CMD53_BLOCK_MODE 27 -//! CMD53 arg[30:28] Number of the function +// ! CMD53 arg[30:28] Number of the function #define SDIO_CMD53_FUNCTION_NUM 28 -//! CMD53 arg[ 31] Direction, 1:WR, 0:RD +// ! CMD53 arg[ 31] Direction, 1:WR, 0:RD #define SDIO_CMD53_RW_FLAG 31 #define SDIO_CMD53_READ_FLAG 0 #define SDIO_CMD53_WRITE_FLAG 1 -//! @} +// ! @} -//! \name SDIO Functions -//! @{ +// ! \name SDIO Functions +// ! @{ #define SDIO_CIA 0 /**< SDIO Function 0 (CIA) */ #define SDIO_FN0 0 /**< SDIO Function 0 */ #define SDIO_FN1 1 /**< SDIO Function 1 */ @@ -509,10 +509,10 @@ typedef uint32_t sdmmc_cmd_def_t; #define SDIO_FN5 5 /**< SDIO Function 5 */ #define SDIO_FN6 6 /**< SDIO Function 6 */ #define SDIO_FN7 7 /**< SDIO Function 7 */ - //! @} +// ! @} -//! \name SDIO Card Common Control Registers (CCCR) -//! @{ +// ! \name SDIO Card Common Control Registers (CCCR) +// ! @{ #define SDIO_CCCR_SDIO_REV 0x00 /**< CCCR/SDIO revision (RO) */ #define SDIO_CCCR_REV (0xFlu << 0) /**< CCCR/FBR Version */ #define SDIO_CCCR_REV_1_00 (0x0lu << 0) /**< CCCR/FBR Version 1.00 */ @@ -652,10 +652,10 @@ typedef uint32_t sdmmc_cmd_def_t; #define SDIO_CCCR_HS 0x13 /**< High-Speed */ #define SDIO_SHS (0x1lu << 0) /**< Support High-Speed (RO) */ #define SDIO_EHS (0x1lu << 1) /**< Enable High-Speed (R/W) */ - //! @} +// ! @} -//! \name SDIO Function Basic Registers (FBR) -//! @{ +// ! \name SDIO Function Basic Registers (FBR) +// ! @{ #define SDIO_FBR_ADDR(fn, x) (0x100 * (fn) + (x)) #define SDIO_FBR_CSA_IF 0x0 /**< CSA and function interface code (RO) */ #define SDIO_IFC (0xFUL << 0) /**< Standard SDIO Fun Interface Code */ @@ -679,10 +679,10 @@ typedef uint32_t sdmmc_cmd_def_t; #define SDIO_FBR_CSA_PTR 0xC /**< Address pointer to CSA (3B, LSB first) (R/W) */ #define SDIO_FBR_CSA_DATA 0xF /**< Read/Write fifo to CSA (R/W) */ #define SDIO_FBR_BLK_SIZ 0x10 /**< Block size (2B, LSB first) (R/W) */ - //! @} +// ! @} -//! \name SDIO Card Metaformat -//! @{ +// ! \name SDIO Card Metaformat +// ! @{ /** Null tuple (PCMCIA 3.1.9) */ #define SDIO_CISTPL_NULL 0x00 /** Device tuple (PCMCIA 3.2.2) */ @@ -705,38 +705,37 @@ typedef uint32_t sdmmc_cmd_def_t; #define SDIO_CISTPL_SDIO_EXT 0x92 /** The End-of-chain Tuple (PCMCIA 3.1.2) */ #define SDIO_CISTPL_END 0xFF -//! @} +// ! @} -//! @} +// ! @} -//! \name CSD, OCR, SCR, Switch status, extend CSD definitions -//! @{ +// ! \name CSD, OCR, SCR, Switch status, extend CSD definitions +// ! @{ /** * \brief Macro function to extract a bits field from a large SD MMC register * Used by : CSD, SCR, Switch status */ -static inline uint32_t SDMMC_UNSTUFF_BITS(uint8_t *reg, uint16_t reg_size, uint16_t pos, uint8_t size) -{ - uint32_t value; - value = reg[((reg_size - pos + 7) / 8) - 1] >> (pos % 8); - if (((pos % 8) + size) > 8) { - value |= (uint32_t)reg[((reg_size - pos + 7) / 8) - 2] << (8 - (pos % 8)); - } - if (((pos % 8) + size) > 16) { - value |= (uint32_t)reg[((reg_size - pos + 7) / 8) - 3] << (16 - (pos % 8)); - } - if (((pos % 8) + size) > 24) { - value |= (uint32_t)reg[((reg_size - pos + 7) / 8) - 3] << (24 - (pos % 8)); - } - value &= ((uint32_t)1 << size) - 1; - return value; +static inline uint32_t SDMMC_UNSTUFF_BITS(uint8_t *reg, uint16_t reg_size, uint16_t pos, uint8_t size) { + uint32_t value; + value = reg[((reg_size - pos + 7) / 8) - 1] >> (pos % 8); + if (((pos % 8) + size) > 8) { + value |= (uint32_t)reg[((reg_size - pos + 7) / 8) - 2] << (8 - (pos % 8)); + } + if (((pos % 8) + size) > 16) { + value |= (uint32_t)reg[((reg_size - pos + 7) / 8) - 3] << (16 - (pos % 8)); + } + if (((pos % 8) + size) > 24) { + value |= (uint32_t)reg[((reg_size - pos + 7) / 8) - 3] << (24 - (pos % 8)); + } + value &= ((uint32_t)1 << size) - 1; + return value; } - //! \name CSD Fields - //! @{ -#define CSD_REG_BIT_SIZE 128 //!< 128 bits -#define CSD_REG_BSIZE (CSD_REG_BIT_SIZE / 8) //!< 16 bytes +// ! \name CSD Fields +// ! @{ +#define CSD_REG_BIT_SIZE 128 // !< 128 bits +#define CSD_REG_BSIZE (CSD_REG_BIT_SIZE / 8) // !< 16 bytes #define CSD_STRUCTURE(csd, pos, size) SDMMC_UNSTUFF_BITS(csd, CSD_REG_BIT_SIZE, pos, size) #define CSD_STRUCTURE_VERSION(csd) CSD_STRUCTURE(csd, 126, 2) #define SD_CSD_VER_1_0 0 @@ -753,10 +752,10 @@ static inline uint32_t SDMMC_UNSTUFF_BITS(uint8_t *reg, uint16_t reg_size, uint1 #define MMC_CSD_C_SIZE_MULT(csd) CSD_STRUCTURE(csd, 47, 3) #define MMC_CSD_READ_BL_LEN(csd) CSD_STRUCTURE(csd, 80, 4) #define MMC_CSD_SPEC_VERS(csd) CSD_STRUCTURE(csd, 122, 4) - //! @} +// ! @} - //! \name OCR Register Fields - //! @{ +// ! \name OCR Register Fields +// ! @{ #define OCR_REG_BSIZE (32 / 8) /**< 32 bits, 4 bytes */ #define OCR_VDD_170_195 (1lu << 7) #define OCR_VDD_20_21 (1lu << 8) @@ -783,12 +782,12 @@ static inline uint32_t SDMMC_UNSTUFF_BITS(uint8_t *reg, uint16_t reg_size, uint1 #define OCR_ACCESS_MODE_SECTOR (2lu << 29) /**< (MMC) Sector access mode */ #define OCR_CCS (1lu << 30) /**< (SD) Card Capacity Status */ #define OCR_POWER_UP_BUSY (1lu << 31) /**< Card power up status bit */ - //! @} +// ! @} - //! \name SD SCR Register Fields - //! @{ -#define SD_SCR_REG_BIT_SIZE 64 //!< 64 bits -#define SD_SCR_REG_BSIZE (SD_SCR_REG_BIT_SIZE / 8) //!< 8 bytes +// ! \name SD SCR Register Fields +// ! @{ +#define SD_SCR_REG_BIT_SIZE 64 // !< 64 bits +#define SD_SCR_REG_BSIZE (SD_SCR_REG_BIT_SIZE / 8) // !< 8 bytes #define SD_SCR_STRUCTURE(scr, pos, size) SDMMC_UNSTUFF_BITS(scr, SD_SCR_REG_BIT_SIZE, pos, size) #define SD_SCR_SCR_STRUCTURE(scr) SD_SCR_STRUCTURE(scr, 60, 4) #define SD_SCR_SCR_STRUCTURE_1_0 0 @@ -810,14 +809,14 @@ static inline uint32_t SDMMC_UNSTUFF_BITS(uint8_t *reg, uint16_t reg_size, uint1 #define SD_SCR_SD_SPEC_3_00 1 #define SD_SCR_SD_EX_SECURITY(scr) SD_SCR_STRUCTURE(scr, 43, 4) #define SD_SCR_SD_CMD_SUPPORT(scr) SD_SCR_STRUCTURE(scr, 32, 2) - //! @} +// ! @} - //! \name SD Switch Status Fields - //! @{ -#define SD_SW_STATUS_BIT_SIZE 512 //!< 512 bits -#define SD_SW_STATUS_BSIZE (SD_SW_STATUS_BIT_SIZE / 8) //!< 64 bytes +// ! \name SD Switch Status Fields +// ! @{ +#define SD_SW_STATUS_BIT_SIZE 512 // !< 512 bits +#define SD_SW_STATUS_BSIZE (SD_SW_STATUS_BIT_SIZE / 8) // !< 64 bytes #define SD_SW_STATUS_STRUCTURE(sd_sw_status, pos, size) \ - SDMMC_UNSTUFF_BITS(sd_sw_status, SD_SW_STATUS_BIT_SIZE, pos, size) + SDMMC_UNSTUFF_BITS(sd_sw_status, SD_SW_STATUS_BIT_SIZE, pos, size) #define SD_SW_STATUS_MAX_CURRENT_CONSUMPTION(status) SD_SW_STATUS_STRUCTURE(status, 496, 16) #define SD_SW_STATUS_FUN_GRP6_INFO(status) SD_SW_STATUS_STRUCTURE(status, 480, 16) #define SD_SW_STATUS_FUN_GRP5_INFO(status) SD_SW_STATUS_STRUCTURE(status, 464, 16) @@ -839,10 +838,10 @@ static inline uint32_t SDMMC_UNSTUFF_BITS(uint8_t *reg, uint16_t reg_size, uint1 #define SD_SW_STATUS_FUN_GRP3_BUSY(status) SD_SW_STATUS_STRUCTURE(status, 304, 16) #define SD_SW_STATUS_FUN_GRP2_BUSY(status) SD_SW_STATUS_STRUCTURE(status, 288, 16) #define SD_SW_STATUS_FUN_GRP1_BUSY(status) SD_SW_STATUS_STRUCTURE(status, 272, 16) - //! @} +// ! @} - //! \name Card Status Fields - //! @{ +// ! \name Card Status Fields +// ! @{ #define CARD_STATUS_APP_CMD (1lu << 5) #define CARD_STATUS_SWITCH_ERROR (1lu << 7) #define CARD_STATUS_READY_FOR_DATA (1lu << 8) @@ -876,17 +875,17 @@ static inline uint32_t SDMMC_UNSTUFF_BITS(uint8_t *reg, uint16_t reg_size, uint1 #define CARD_STATUS_ADDR_OUT_OF_RANGE (1lu << 31) #define CARD_STATUS_ERR_RD_WR \ - (CARD_STATUS_ADDR_OUT_OF_RANGE | CARD_STATUS_ADDRESS_MISALIGN | CARD_STATUS_BLOCK_LEN_ERROR \ - | CARD_STATUS_WP_VIOLATION | CARD_STATUS_ILLEGAL_COMMAND | CARD_STATUS_CC_ERROR | CARD_STATUS_ERROR) - //! @} + (CARD_STATUS_ADDR_OUT_OF_RANGE | CARD_STATUS_ADDRESS_MISALIGN | CARD_STATUS_BLOCK_LEN_ERROR \ + | CARD_STATUS_WP_VIOLATION | CARD_STATUS_ILLEGAL_COMMAND | CARD_STATUS_CC_ERROR | CARD_STATUS_ERROR) +// ! @} - //! \name SD Status Field - //! @{ +// ! \name SD Status Field +// ! @{ #define SD_STATUS_BSIZE (512 / 8) /**< 512 bits, 64bytes */ - //! @} +// ! @} - //! \name MMC Extended CSD Register Field - //! @{ +// ! \name MMC Extended CSD Register Field +// ! @{ #define EXT_CSD_BSIZE 512 /**< 512 bytes. */ /* Below belongs to Properties Segment */ #define EXT_CSD_S_CMD_SET_INDEX 504lu @@ -928,18 +927,18 @@ static inline uint32_t SDMMC_UNSTUFF_BITS(uint8_t *reg, uint16_t reg_size, uint1 #define EXT_CSD_BOOT_CONFIG_INDEX 179lu #define EXT_CSD_BOOT_BUS_WIDTH_INDEX 177lu #define EXT_CSD_ERASE_GROUP_DEF_INDEX 175lu - //! @} -//! @} +// ! @} +// ! @} -//! \name Definition for SPI mode only -//! @{ +// ! \name Definition for SPI mode only +// ! @{ -//! SPI commands start with a start bit "0" and a transmit bit "1" +// ! SPI commands start with a start bit "0" and a transmit bit "1" #define SPI_CMD_ENCODE(x) (0x40 | (x & 0x3F)) -//! \name Register R1 definition for SPI mode -//! The R1 register is always send after a command. -//! @{ +// ! \name Register R1 definition for SPI mode +// ! The R1 register is always send after a command. +// ! @{ #define R1_SPI_IDLE (1lu << 0) #define R1_SPI_ERASE_RESET (1lu << 1) #define R1_SPI_ILLEGAL_COMMAND (1lu << 2) @@ -949,11 +948,11 @@ static inline uint32_t SDMMC_UNSTUFF_BITS(uint8_t *reg, uint16_t reg_size, uint1 #define R1_SPI_PARAMETER (1lu << 6) // R1 bit 7 is always zero, reuse this bit for error #define R1_SPI_ERROR (1lu << 7) -//! @} +// ! @} -//! \name Register R2 definition for SPI mode -//! The R2 register can be send after R1 register. -//! @{ +// ! \name Register R2 definition for SPI mode +// ! The R2 register can be send after R1 register. +// ! @{ #define R2_SPI_CARD_LOCKED (1lu << 0) #define R2_SPI_WP_ERASE_SKIP (1lu << 1) #define R2_SPI_LOCK_UNLOCK_FAIL R2_SPI_WP_ERASE_SKIP @@ -964,35 +963,35 @@ static inline uint32_t SDMMC_UNSTUFF_BITS(uint8_t *reg, uint16_t reg_size, uint1 #define R2_SPI_ERASE_PARAM (1lu << 6) #define R2_SPI_OUT_OF_RANGE (1lu << 7) #define R2_SPI_CSD_OVERWRITE R2_SPI_OUT_OF_RANGE -//! @} +// ! @} -//! \name Control Tokens in SPI Mode -//! @{ -//! \name Tokens used for a read operation -//! @{ +// ! \name Control Tokens in SPI Mode +// ! @{ +// ! \name Tokens used for a read operation +// ! @{ #define SPI_TOKEN_SINGLE_MULTI_READ 0xFE -#define SPI_TOKEN_DATA_ERROR_VALID(token) (((token)&0xF0) == 0) +#define SPI_TOKEN_DATA_ERROR_VALID(token) (((token) & 0xF0) == 0) #define SPI_TOKEN_DATA_ERROR_ERRORS (0x0F) #define SPI_TOKEN_DATA_ERROR_ERROR (1lu << 0) #define SPI_TOKEN_DATA_ERROR_CC_ERROR (1lu << 1) #define SPI_TOKEN_DATA_ERROR_ECC_ERROR (1lu << 2) #define SPI_TOKEN_DATA_ERROR_OUT_RANGE (1lu << 3) - //! @} - //! \name Tokens used for a write operation - //! @{ +// ! @} +// ! \name Tokens used for a write operation +// ! @{ #define SPI_TOKEN_SINGLE_WRITE 0xFE #define SPI_TOKEN_MULTI_WRITE 0xFC #define SPI_TOKEN_STOP_TRAN 0xFD #define SPI_TOKEN_DATA_RESP_VALID(token) ((((token) & (1 << 4)) == 0) && (((token) & (1 << 0)) == 1)) -#define SPI_TOKEN_DATA_RESP_CODE(token) ((token)&0x1E) +#define SPI_TOKEN_DATA_RESP_CODE(token) ((token) & 0x1E) #define SPI_TOKEN_DATA_RESP_ACCEPTED (2lu << 1) #define SPI_TOKEN_DATA_RESP_CRC_ERR (5lu << 1) #define SPI_TOKEN_DATA_RESP_WRITE_ERR (6lu << 1) - //! @} - //! @} - //! @} +// ! @} +// ! @} +// ! @} - //! @} end of sd_mmc_protocol +// ! @} end of sd_mmc_protocol #ifdef __cplusplus } diff --git a/ports/atmel-samd/supervisor/internal_flash.c b/ports/atmel-samd/supervisor/internal_flash.c index 4c7ca0dc76..98d7892c9f 100644 --- a/ports/atmel-samd/supervisor/internal_flash.c +++ b/ports/atmel-samd/supervisor/internal_flash.c @@ -58,12 +58,12 @@ static struct flash_descriptor supervisor_flash_desc; void supervisor_flash_init(void) { // Activity LED for flash writes. #ifdef MICROPY_HW_LED_MSC - struct port_config pin_conf; - port_get_config_defaults(&pin_conf); + struct port_config pin_conf; + port_get_config_defaults(&pin_conf); - pin_conf.direction = PORT_PIN_DIR_OUTPUT; - port_pin_set_config(MICROPY_HW_LED_MSC, &pin_conf); - port_pin_set_output_level(MICROPY_HW_LED_MSC, false); + pin_conf.direction = PORT_PIN_DIR_OUTPUT; + port_pin_set_config(MICROPY_HW_LED_MSC, &pin_conf); + port_pin_set_output_level(MICROPY_HW_LED_MSC, false); #endif #ifdef SAM_D5X_E5X @@ -115,7 +115,7 @@ bool supervisor_flash_read_block(uint8_t *dest, uint32_t block) { bool supervisor_flash_write_block(const uint8_t *src, uint32_t block) { #ifdef MICROPY_HW_LED_MSC - port_pin_set_output_level(MICROPY_HW_LED_MSC, true); + port_pin_set_output_level(MICROPY_HW_LED_MSC, true); #endif temp_status_color(ACTIVE_WRITE); // non-MBR block, copy to cache @@ -126,8 +126,8 @@ bool supervisor_flash_write_block(const uint8_t *src, uint32_t block) { } int32_t error_code; error_code = flash_erase(&supervisor_flash_desc, - dest, - FILESYSTEM_BLOCK_SIZE / flash_get_page_size(&supervisor_flash_desc)); + dest, + FILESYSTEM_BLOCK_SIZE / flash_get_page_size(&supervisor_flash_desc)); if (error_code != ERR_NONE) { return false; } @@ -138,7 +138,7 @@ bool supervisor_flash_write_block(const uint8_t *src, uint32_t block) { } clear_temp_status(); #ifdef MICROPY_HW_LED_MSC - port_pin_set_output_level(MICROPY_HW_LED_MSC, false); + port_pin_set_output_level(MICROPY_HW_LED_MSC, false); #endif return true; } diff --git a/ports/atmel-samd/supervisor/port.c b/ports/atmel-samd/supervisor/port.c index 2137c47559..15112f5ba7 100644 --- a/ports/atmel-samd/supervisor/port.c +++ b/ports/atmel-samd/supervisor/port.c @@ -97,9 +97,13 @@ volatile bool hold_interrupt = false; #ifdef SAMD21 static void rtc_set_continuous(bool continuous) { - while (RTC->MODE0.STATUS.bit.SYNCBUSY); + while (RTC->MODE0.STATUS.bit.SYNCBUSY) { + ; + } RTC->MODE0.READREQ.reg = (continuous ? RTC_READREQ_RCONT : 0) | 0x0010; - while (RTC->MODE0.STATUS.bit.SYNCBUSY); + while (RTC->MODE0.STATUS.bit.SYNCBUSY) { + ; + } } void rtc_start_pulse(void) { @@ -132,8 +136,8 @@ static void save_usb_clock_calibration(void) { // save the new value if its different enough. SYSCTRL->DFLLSYNC.bit.READREQ = 1; uint16_t saved_calibration = 0x1ff; - if (strcmp((char*) CIRCUITPY_INTERNAL_CONFIG_START_ADDR, "CIRCUITPYTHON1") == 0) { - saved_calibration = ((uint16_t *) CIRCUITPY_INTERNAL_CONFIG_START_ADDR)[8]; + if (strcmp((char *)CIRCUITPY_INTERNAL_CONFIG_START_ADDR, "CIRCUITPYTHON1") == 0) { + saved_calibration = ((uint16_t *)CIRCUITPY_INTERNAL_CONFIG_START_ADDR)[8]; } while (SYSCTRL->PCLKSR.bit.DFLLRDY == 0) { // TODO(tannewt): Run the mass storage stuff if this takes a while. @@ -142,7 +146,7 @@ static void save_usb_clock_calibration(void) { if (abs(current_calibration - saved_calibration) > 10) { // Copy the full internal config page to memory. uint8_t page_buffer[NVMCTRL_ROW_SIZE]; - memcpy(page_buffer, (uint8_t*) CIRCUITPY_INTERNAL_CONFIG_START_ADDR, NVMCTRL_ROW_SIZE); + memcpy(page_buffer, (uint8_t *)CIRCUITPY_INTERNAL_CONFIG_START_ADDR, NVMCTRL_ROW_SIZE); // Modify it. memcpy(page_buffer, "CIRCUITPYTHON1", 15); @@ -155,31 +159,33 @@ static void save_usb_clock_calibration(void) { // whenever we need it instead of storing it long term. struct flash_descriptor desc; desc.dev.hw = NVMCTRL; - flash_write(&desc, (uint32_t) CIRCUITPY_INTERNAL_CONFIG_START_ADDR, page_buffer, NVMCTRL_ROW_SIZE); + flash_write(&desc, (uint32_t)CIRCUITPY_INTERNAL_CONFIG_START_ADDR, page_buffer, NVMCTRL_ROW_SIZE); } } #endif static void rtc_init(void) { -#ifdef SAMD21 + #ifdef SAMD21 _gclk_enable_channel(RTC_GCLK_ID, GCLK_CLKCTRL_GEN_GCLK2_Val); RTC->MODE0.CTRL.bit.SWRST = true; - while (RTC->MODE0.CTRL.bit.SWRST != 0) {} + while (RTC->MODE0.CTRL.bit.SWRST != 0) { + } RTC->MODE0.CTRL.reg = RTC_MODE0_CTRL_ENABLE | - RTC_MODE0_CTRL_MODE_COUNT32 | - RTC_MODE0_CTRL_PRESCALER_DIV2; -#endif -#ifdef SAM_D5X_E5X + RTC_MODE0_CTRL_MODE_COUNT32 | + RTC_MODE0_CTRL_PRESCALER_DIV2; + #endif + #ifdef SAM_D5X_E5X hri_mclk_set_APBAMASK_RTC_bit(MCLK); RTC->MODE0.CTRLA.bit.SWRST = true; - while (RTC->MODE0.SYNCBUSY.bit.SWRST != 0) {} + while (RTC->MODE0.SYNCBUSY.bit.SWRST != 0) { + } RTC->MODE0.CTRLA.reg = RTC_MODE0_CTRLA_ENABLE | - RTC_MODE0_CTRLA_MODE_COUNT32 | - RTC_MODE0_CTRLA_PRESCALER_DIV2 | - RTC_MODE0_CTRLA_COUNTSYNC; -#endif + RTC_MODE0_CTRLA_MODE_COUNT32 | + RTC_MODE0_CTRLA_PRESCALER_DIV2 | + RTC_MODE0_CTRLA_COUNTSYNC; + #endif RTC->MODE0.INTENSET.reg = RTC_MODE0_INTENSET_OVF; @@ -201,14 +207,14 @@ static void rtc_init(void) { #endif NVIC_ClearPendingIRQ(RTC_IRQn); NVIC_EnableIRQ(RTC_IRQn); -#if CIRCUITPY_RTC + #if CIRCUITPY_RTC rtc_reset(); -#endif + #endif } safe_mode_t port_init(void) { -#if defined(SAMD21) + #if defined(SAMD21) // Set brownout detection. // Disable while changing level. @@ -217,17 +223,17 @@ safe_mode_t port_init(void) { SYSCTRL->BOD33.bit.ENABLE = 1; #ifdef ENABLE_MICRO_TRACE_BUFFER - REG_MTB_POSITION = ((uint32_t) (mtb - REG_MTB_BASE)) & 0xFFFFFFF8; - REG_MTB_FLOW = (((uint32_t) mtb - REG_MTB_BASE) + TRACE_BUFFER_SIZE_BYTES) & 0xFFFFFFF8; - REG_MTB_MASTER = 0x80000000 + (TRACE_BUFFER_MAGNITUDE_PACKETS - 1); + REG_MTB_POSITION = ((uint32_t)(mtb - REG_MTB_BASE)) & 0xFFFFFFF8; + REG_MTB_FLOW = (((uint32_t)mtb - REG_MTB_BASE) + TRACE_BUFFER_SIZE_BYTES) & 0xFFFFFFF8; + REG_MTB_MASTER = 0x80000000 + (TRACE_BUFFER_MAGNITUDE_PACKETS - 1); #else - // Triple check that the MTB is off. Switching between debug and non-debug - // builds can leave it set over reset and wreak havok as a result. - REG_MTB_MASTER = 0x00000000 + 6; + // Triple check that the MTB is off. Switching between debug and non-debug + // builds can leave it set over reset and wreak havok as a result. + REG_MTB_MASTER = 0x00000000 + 6; + #endif #endif -#endif -#if defined(SAM_D5X_E5X) + #if defined(SAM_D5X_E5X) // Set brownout detection. // Disable while changing level. SUPC->BOD33.bit.ENABLE = 0; @@ -240,7 +246,7 @@ safe_mode_t port_init(void) { // Leaving this code here disabled, // because it was hard enough to figure out, and maybe there's // a mistake that could make it work in the future. -#if 0 + #if 0 // Designate QSPI memory mapped region as not cachable. // Turn off MPU in case it is on. @@ -252,15 +258,15 @@ safe_mode_t port_init(void) { MPU->RBAR = QSPI_AHB; MPU->RASR = 0b011 << MPU_RASR_AP_Pos | // full read/write access for privileged and user mode - 0b000 << MPU_RASR_TEX_Pos | // caching not allowed, strongly ordered - 1 << MPU_RASR_S_Pos | // sharable - 0 << MPU_RASR_C_Pos | // not cachable - 0 << MPU_RASR_B_Pos | // not bufferable - 0b10111 << MPU_RASR_SIZE_Pos | // 16MB region size - 1 << MPU_RASR_ENABLE_Pos // enable this region - ; + 0b000 << MPU_RASR_TEX_Pos | // caching not allowed, strongly ordered + 1 << MPU_RASR_S_Pos | // sharable + 0 << MPU_RASR_C_Pos | // not cachable + 0 << MPU_RASR_B_Pos | // not bufferable + 0b10111 << MPU_RASR_SIZE_Pos | // 16MB region size + 1 << MPU_RASR_ENABLE_Pos // enable this region + ; // Turn off regions 1-7. - for (uint32_t i = 1; i < 8; i ++) { + for (uint32_t i = 1; i < 8; i++) { MPU->RNR = i; MPU->RBAR = 0; MPU->RASR = 0; @@ -270,28 +276,28 @@ safe_mode_t port_init(void) { // map for all privileged access, so we don't have to set up other regions // besides QSPI. MPU->CTRL = MPU_CTRL_PRIVDEFENA_Msk | MPU_CTRL_ENABLE_Msk; -#endif + #endif samd_peripherals_enable_cache(); -#endif + #endif -#ifdef SAMD21 + #ifdef SAMD21 hri_nvmctrl_set_CTRLB_RWS_bf(NVMCTRL, 2); _pm_init(); -#endif + #endif -#if CALIBRATE_CRYSTALLESS + #if CALIBRATE_CRYSTALLESS uint32_t fine = DEFAULT_DFLL48M_FINE_CALIBRATION; // The fine calibration data is stored in an NVM page after the text and data storage but before // the optional file system. The first 16 bytes are the identifier for the section. - if (strcmp((char*) CIRCUITPY_INTERNAL_CONFIG_START_ADDR, "CIRCUITPYTHON1") == 0) { - fine = ((uint16_t *) CIRCUITPY_INTERNAL_CONFIG_START_ADDR)[8]; + if (strcmp((char *)CIRCUITPY_INTERNAL_CONFIG_START_ADDR, "CIRCUITPYTHON1") == 0) { + fine = ((uint16_t *)CIRCUITPY_INTERNAL_CONFIG_START_ADDR)[8]; } clock_init(BOARD_HAS_CRYSTAL, fine); -#else + #else // Use a default fine value clock_init(BOARD_HAS_CRYSTAL, DEFAULT_DFLL48M_FINE_CALIBRATION); -#endif + #endif rtc_init(); @@ -319,48 +325,48 @@ safe_mode_t port_init(void) { } void reset_port(void) { -#if CIRCUITPY_BUSIO + #if CIRCUITPY_BUSIO reset_sercoms(); -#endif -#if CIRCUITPY_AUDIOIO + #endif + #if CIRCUITPY_AUDIOIO audio_dma_reset(); audioout_reset(); -#endif -#if CIRCUITPY_AUDIOBUSIO - //pdmin_reset(); -#endif -#if CIRCUITPY_AUDIOBUSIO_I2SOUT + #endif + #if CIRCUITPY_AUDIOBUSIO + // pdmin_reset(); + #endif + #if CIRCUITPY_AUDIOBUSIO_I2SOUT i2sout_reset(); -#endif + #endif -#if CIRCUITPY_TOUCHIO && CIRCUITPY_TOUCHIO_USE_NATIVE + #if CIRCUITPY_TOUCHIO && CIRCUITPY_TOUCHIO_USE_NATIVE touchin_reset(); -#endif + #endif eic_reset(); -#if CIRCUITPY_PULSEIO + #if CIRCUITPY_PULSEIO pulsein_reset(); pulseout_reset(); -#endif -#if CIRCUITPY_PWMIO + #endif + #if CIRCUITPY_PWMIO pwmout_reset(); -#endif + #endif -#if CIRCUITPY_ANALOGIO + #if CIRCUITPY_ANALOGIO analogin_reset(); analogout_reset(); -#endif + #endif reset_gclks(); -#if CIRCUITPY_GAMEPAD + #if CIRCUITPY_GAMEPAD gamepad_reset(); -#endif -#if CIRCUITPY_GAMEPADSHIFT + #endif + #if CIRCUITPY_GAMEPADSHIFT gamepadshift_reset(); -#endif -#if CIRCUITPY_PEW + #endif + #if CIRCUITPY_PEW pew_reset(); -#endif + #endif reset_event_system(); @@ -375,11 +381,11 @@ void reset_port(void) { // gpio_set_pin_function(PIN_PB15, GPIO_PIN_FUNCTION_M); // GCLK1, D6 // #endif -#if CALIBRATE_CRYSTALLESS + #if CALIBRATE_CRYSTALLESS if (tud_cdc_connected()) { save_usb_clock_calibration(); } -#endif + #endif } void reset_to_bootloader(void) { @@ -413,10 +419,10 @@ uint32_t *port_heap_get_top(void) { // Place the word to save 8k from the end of RAM so we and the bootloader don't clobber it. #ifdef SAMD21 -uint32_t* safe_word = (uint32_t*) (HMCRAMC0_ADDR + HMCRAMC0_SIZE - 0x2000); +uint32_t *safe_word = (uint32_t *)(HMCRAMC0_ADDR + HMCRAMC0_SIZE - 0x2000); #endif #ifdef SAM_D5X_E5X -uint32_t* safe_word = (uint32_t*) (HSRAM_ADDR + HSRAM_SIZE - 0x2000); +uint32_t *safe_word = (uint32_t *)(HSRAM_ADDR + HSRAM_SIZE - 0x2000); #endif void port_set_saved_word(uint32_t value) { @@ -434,14 +440,16 @@ static volatile uint64_t overflowed_ticks = 0; static volatile bool _ticks_enabled = false; #endif -static uint32_t _get_count(uint64_t* overflow_count) { +static uint32_t _get_count(uint64_t *overflow_count) { #ifdef SAM_D5X_E5X - while ((RTC->MODE0.SYNCBUSY.reg & (RTC_MODE0_SYNCBUSY_COUNTSYNC | RTC_MODE0_SYNCBUSY_COUNT)) != 0) {} + while ((RTC->MODE0.SYNCBUSY.reg & (RTC_MODE0_SYNCBUSY_COUNTSYNC | RTC_MODE0_SYNCBUSY_COUNT)) != 0) { + } #endif #ifdef SAMD21 // Request a read so we don't stall the bus later. See section 14.3.1.5 Read Request RTC->MODE0.READREQ.reg = RTC_READREQ_RREQ | 0x0010; - while (RTC->MODE0.STATUS.bit.SYNCBUSY != 0) {} + while (RTC->MODE0.STATUS.bit.SYNCBUSY != 0) { + } #endif // Disable interrupts so we can grab the count and the overflow. common_hal_mcu_disable_interrupts(); @@ -460,11 +468,11 @@ static void _port_interrupt_after_ticks(uint32_t ticks) { // We'll interrupt sooner with an overflow. return; } -#ifdef SAMD21 + #ifdef SAMD21 if (hold_interrupt) { return; } -#endif + #endif RTC->MODE0.COMP[0].reg = current_ticks + (ticks << 4); RTC->MODE0.INTFLAG.reg = RTC_MODE0_INTFLAG_CMP0; RTC->MODE0.INTENSET.reg = RTC_MODE0_INTENSET_CMP0; @@ -476,7 +484,7 @@ void RTC_Handler(void) { RTC->MODE0.INTFLAG.reg = RTC_MODE0_INTFLAG_OVF; // Our RTC is 32 bits and we're clocking it at 16.384khz which is 16 (2 ** 4) subticks per // tick. - overflowed_ticks += (1L<< (32 - 4)); + overflowed_ticks += (1L << (32 - 4)); #ifdef SAM_D5X_E5X } else if (intflag & RTC_MODE0_INTFLAG_PER2) { RTC->MODE0.INTFLAG.reg = RTC_MODE0_INTFLAG_PER2; @@ -502,7 +510,7 @@ void RTC_Handler(void) { } } -uint64_t port_get_raw_ticks(uint8_t* subticks) { +uint64_t port_get_raw_ticks(uint8_t *subticks) { uint64_t overflow_count; uint32_t current_ticks = _get_count(&overflow_count); if (subticks != NULL) { @@ -551,9 +559,9 @@ void port_interrupt_after_ticks(uint32_t ticks) { void port_idle_until_interrupt(void) { #ifdef SAM_D5X_E5X // Clear the FPU interrupt because it can prevent us from sleeping. - if (__get_FPSCR() & ~(0x9f)) { - __set_FPSCR(__get_FPSCR() & ~(0x9f)); - (void) __get_FPSCR(); + if (__get_FPSCR() & ~(0x9f)) { + __set_FPSCR(__get_FPSCR() & ~(0x9f)); + (void)__get_FPSCR(); } #endif common_hal_mcu_disable_interrupts(); @@ -567,16 +575,15 @@ void port_idle_until_interrupt(void) { /** * \brief Default interrupt handler for unused IRQs. */ -__attribute__((used)) void HardFault_Handler(void) -{ -#ifdef ENABLE_MICRO_TRACE_BUFFER +__attribute__((used)) void HardFault_Handler(void) { + #ifdef ENABLE_MICRO_TRACE_BUFFER // Turn off the micro trace buffer so we don't fill it up in the infinite // loop below. REG_MTB_MASTER = 0x00000000 + 6; -#endif + #endif reset_into_safe_mode(HARD_CRASH); while (true) { - asm("nop;"); + asm ("nop;"); } } diff --git a/ports/atmel-samd/supervisor/qspi_flash.c b/ports/atmel-samd/supervisor/qspi_flash.c index aaed2a0eee..e59c2ee4a6 100644 --- a/ports/atmel-samd/supervisor/qspi_flash.c +++ b/ports/atmel-samd/supervisor/qspi_flash.c @@ -43,40 +43,44 @@ bool spi_flash_command(uint8_t command) { QSPI->INSTRCTRL.bit.INSTR = command; QSPI->INSTRFRAME.reg = QSPI_INSTRFRAME_WIDTH_SINGLE_BIT_SPI | - QSPI_INSTRFRAME_ADDRLEN_24BITS | - QSPI_INSTRFRAME_TFRTYPE_READ | - QSPI_INSTRFRAME_INSTREN; + QSPI_INSTRFRAME_ADDRLEN_24BITS | + QSPI_INSTRFRAME_TFRTYPE_READ | + QSPI_INSTRFRAME_INSTREN; QSPI->CTRLA.reg = QSPI_CTRLA_ENABLE | QSPI_CTRLA_LASTXFER; - while( !QSPI->INTFLAG.bit.INSTREND ); + while (!QSPI->INTFLAG.bit.INSTREND) { + ; + } QSPI->INTFLAG.reg = QSPI_INTFLAG_INSTREND; return true; } -bool spi_flash_read_command(uint8_t command, uint8_t* response, uint32_t length) { +bool spi_flash_read_command(uint8_t command, uint8_t *response, uint32_t length) { samd_peripherals_disable_and_clear_cache(); QSPI->INSTRCTRL.bit.INSTR = command; QSPI->INSTRFRAME.reg = QSPI_INSTRFRAME_WIDTH_SINGLE_BIT_SPI | - QSPI_INSTRFRAME_ADDRLEN_24BITS | - QSPI_INSTRFRAME_TFRTYPE_READ | - QSPI_INSTRFRAME_INSTREN | - QSPI_INSTRFRAME_DATAEN; + QSPI_INSTRFRAME_ADDRLEN_24BITS | + QSPI_INSTRFRAME_TFRTYPE_READ | + QSPI_INSTRFRAME_INSTREN | + QSPI_INSTRFRAME_DATAEN; // Dummy read of INSTRFRAME needed to synchronize. // See Instruction Transmission Flow Diagram, figure 37.9, page 995 // and Example 4, page 998, section 37.6.8.5. - (volatile uint32_t) QSPI->INSTRFRAME.reg; + (volatile uint32_t)QSPI->INSTRFRAME.reg; - memcpy(response, (uint8_t *) QSPI_AHB, length); + memcpy(response, (uint8_t *)QSPI_AHB, length); QSPI->CTRLA.reg = QSPI_CTRLA_ENABLE | QSPI_CTRLA_LASTXFER; - while( !QSPI->INTFLAG.bit.INSTREND ); + while (!QSPI->INTFLAG.bit.INSTREND) { + ; + } QSPI->INTFLAG.reg = QSPI_INTFLAG_INSTREND; @@ -85,29 +89,31 @@ bool spi_flash_read_command(uint8_t command, uint8_t* response, uint32_t length) return true; } -bool spi_flash_write_command(uint8_t command, uint8_t* data, uint32_t length) { +bool spi_flash_write_command(uint8_t command, uint8_t *data, uint32_t length) { samd_peripherals_disable_and_clear_cache(); QSPI->INSTRCTRL.bit.INSTR = command; QSPI->INSTRFRAME.reg = QSPI_INSTRFRAME_WIDTH_SINGLE_BIT_SPI | - QSPI_INSTRFRAME_ADDRLEN_24BITS | - QSPI_INSTRFRAME_TFRTYPE_WRITE | - QSPI_INSTRFRAME_INSTREN | - (data != NULL ? QSPI_INSTRFRAME_DATAEN : 0); + QSPI_INSTRFRAME_ADDRLEN_24BITS | + QSPI_INSTRFRAME_TFRTYPE_WRITE | + QSPI_INSTRFRAME_INSTREN | + (data != NULL ? QSPI_INSTRFRAME_DATAEN : 0); // Dummy read of INSTRFRAME needed to synchronize. // See Instruction Transmission Flow Diagram, figure 37.9, page 995 // and Example 4, page 998, section 37.6.8.5. - (volatile uint32_t) QSPI->INSTRFRAME.reg; + (volatile uint32_t)QSPI->INSTRFRAME.reg; if (data != NULL) { - memcpy((uint8_t *) QSPI_AHB, data, length); + memcpy((uint8_t *)QSPI_AHB, data, length); } QSPI->CTRLA.reg = QSPI_CTRLA_ENABLE | QSPI_CTRLA_LASTXFER; - while( !QSPI->INTFLAG.bit.INSTREND ); + while (!QSPI->INTFLAG.bit.INSTREND) { + ; + } QSPI->INTFLAG.reg = QSPI_INTFLAG_INSTREND; @@ -121,40 +127,44 @@ bool spi_flash_sector_command(uint8_t command, uint32_t address) { QSPI->INSTRADDR.bit.ADDR = address; QSPI->INSTRFRAME.reg = QSPI_INSTRFRAME_WIDTH_SINGLE_BIT_SPI | - QSPI_INSTRFRAME_ADDRLEN_24BITS | - QSPI_INSTRFRAME_TFRTYPE_WRITE | - QSPI_INSTRFRAME_INSTREN | - QSPI_INSTRFRAME_ADDREN; + QSPI_INSTRFRAME_ADDRLEN_24BITS | + QSPI_INSTRFRAME_TFRTYPE_WRITE | + QSPI_INSTRFRAME_INSTREN | + QSPI_INSTRFRAME_ADDREN; QSPI->CTRLA.reg = QSPI_CTRLA_ENABLE | QSPI_CTRLA_LASTXFER; - while( !QSPI->INTFLAG.bit.INSTREND ); + while (!QSPI->INTFLAG.bit.INSTREND) { + ; + } QSPI->INTFLAG.reg = QSPI_INTFLAG_INSTREND; return true; } -bool spi_flash_write_data(uint32_t address, uint8_t* data, uint32_t length) { +bool spi_flash_write_data(uint32_t address, uint8_t *data, uint32_t length) { samd_peripherals_disable_and_clear_cache(); QSPI->INSTRCTRL.bit.INSTR = CMD_PAGE_PROGRAM; uint32_t mode = QSPI_INSTRFRAME_WIDTH_SINGLE_BIT_SPI; QSPI->INSTRFRAME.reg = mode | - QSPI_INSTRFRAME_ADDRLEN_24BITS | - QSPI_INSTRFRAME_TFRTYPE_WRITEMEMORY | - QSPI_INSTRFRAME_INSTREN | - QSPI_INSTRFRAME_ADDREN | - QSPI_INSTRFRAME_DATAEN; + QSPI_INSTRFRAME_ADDRLEN_24BITS | + QSPI_INSTRFRAME_TFRTYPE_WRITEMEMORY | + QSPI_INSTRFRAME_INSTREN | + QSPI_INSTRFRAME_ADDREN | + QSPI_INSTRFRAME_DATAEN; - memcpy(((uint8_t *) QSPI_AHB) + address, data, length); + memcpy(((uint8_t *)QSPI_AHB) + address, data, length); // TODO(tannewt): Fix DMA and enable it. // qspi_dma_write(address, data, length); QSPI->CTRLA.reg = QSPI_CTRLA_ENABLE | QSPI_CTRLA_LASTXFER; - while( !QSPI->INTFLAG.bit.INSTREND ); + while (!QSPI->INTFLAG.bit.INSTREND) { + ; + } QSPI->INTFLAG.reg = QSPI_INTFLAG_INSTREND; @@ -163,7 +173,7 @@ bool spi_flash_write_data(uint32_t address, uint8_t* data, uint32_t length) { return true; } -bool spi_flash_read_data(uint32_t address, uint8_t* data, uint32_t length) { +bool spi_flash_read_data(uint32_t address, uint8_t *data, uint32_t length) { samd_peripherals_disable_and_clear_cache(); #ifdef EXTERNAL_FLASH_QSPI_SINGLE @@ -179,29 +189,31 @@ bool spi_flash_read_data(uint32_t address, uint8_t* data, uint32_t length) { #ifdef EXTERNAL_FLASH_QSPI_SINGLE QSPI->INSTRFRAME.reg = mode | - QSPI_INSTRFRAME_ADDRLEN_24BITS | - QSPI_INSTRFRAME_TFRTYPE_READMEMORY | - QSPI_INSTRFRAME_INSTREN | - QSPI_INSTRFRAME_ADDREN | - QSPI_INSTRFRAME_DATAEN | - QSPI_INSTRFRAME_DUMMYLEN(0); + QSPI_INSTRFRAME_ADDRLEN_24BITS | + QSPI_INSTRFRAME_TFRTYPE_READMEMORY | + QSPI_INSTRFRAME_INSTREN | + QSPI_INSTRFRAME_ADDREN | + QSPI_INSTRFRAME_DATAEN | + QSPI_INSTRFRAME_DUMMYLEN(0); #else QSPI->INSTRFRAME.reg = mode | - QSPI_INSTRFRAME_ADDRLEN_24BITS | - QSPI_INSTRFRAME_TFRTYPE_READMEMORY | - QSPI_INSTRFRAME_INSTREN | - QSPI_INSTRFRAME_ADDREN | - QSPI_INSTRFRAME_DATAEN | - QSPI_INSTRFRAME_DUMMYLEN(8); + QSPI_INSTRFRAME_ADDRLEN_24BITS | + QSPI_INSTRFRAME_TFRTYPE_READMEMORY | + QSPI_INSTRFRAME_INSTREN | + QSPI_INSTRFRAME_ADDREN | + QSPI_INSTRFRAME_DATAEN | + QSPI_INSTRFRAME_DUMMYLEN(8); #endif - memcpy(data, ((uint8_t *) QSPI_AHB) + address, length); + memcpy(data, ((uint8_t *)QSPI_AHB) + address, length); // TODO(tannewt): Fix DMA and enable it. // qspi_dma_read(address, data, length); QSPI->CTRLA.reg = QSPI_CTRLA_ENABLE | QSPI_CTRLA_LASTXFER; - while( !QSPI->INTFLAG.bit.INSTREND ); + while (!QSPI->INTFLAG.bit.INSTREND) { + ; + } QSPI->INTFLAG.reg = QSPI_INTFLAG_INSTREND; @@ -224,8 +236,8 @@ void spi_flash_init(void) { // Super fast, may be unreliable when Saleae is connected to high speed lines. QSPI->BAUD.bit.BAUD = 2; QSPI->CTRLB.reg = QSPI_CTRLB_MODE_MEMORY | // Serial memory mode (map to QSPI_AHB) - QSPI_CTRLB_DATALEN_8BITS | - QSPI_CTRLB_CSMODE_LASTXFER; + QSPI_CTRLB_DATALEN_8BITS | + QSPI_CTRLB_CSMODE_LASTXFER; QSPI->CTRLA.reg = QSPI_CTRLA_ENABLE; @@ -238,7 +250,7 @@ void spi_flash_init(void) { } } -void spi_flash_init_device(const external_flash_device* device) { +void spi_flash_init_device(const external_flash_device *device) { check_quad_enable(device); // TODO(tannewt): Adjust the speed for the found device. diff --git a/ports/atmel-samd/supervisor/usb.c b/ports/atmel-samd/supervisor/usb.c index ea940f8988..2a4c2d4f78 100644 --- a/ports/atmel-samd/supervisor/usb.c +++ b/ports/atmel-samd/supervisor/usb.c @@ -68,19 +68,19 @@ void USB_Handler(void) { #endif #ifdef SAM_D5X_E5X -void USB_0_Handler (void) { +void USB_0_Handler(void) { usb_irq_handler(); } -void USB_1_Handler (void) { +void USB_1_Handler(void) { usb_irq_handler(); } -void USB_2_Handler (void) { +void USB_2_Handler(void) { usb_irq_handler(); } -void USB_3_Handler (void) { +void USB_3_Handler(void) { usb_irq_handler(); } #endif diff --git a/ports/esp32s2/boards/adafruit_funhouse/board.c b/ports/esp32s2/boards/adafruit_funhouse/board.c index 3ca5c5d64f..d371c5fa1f 100644 --- a/ports/esp32s2/boards/adafruit_funhouse/board.c +++ b/ports/esp32s2/boards/adafruit_funhouse/board.c @@ -55,16 +55,16 @@ void board_init(void) { common_hal_never_reset_pin(&pin_GPIO20); // Debug UART -#ifdef DEBUG + #ifdef DEBUG common_hal_never_reset_pin(&pin_GPIO37); common_hal_never_reset_pin(&pin_GPIO38); -#endif /* DEBUG */ + #endif /* DEBUG */ - busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus; + busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; common_hal_busio_spi_construct(spi, &pin_GPIO36, &pin_GPIO35, NULL); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus; + displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -78,7 +78,7 @@ void board_init(void) { // workaround as board_init() is called before reset_port() in main.c pwmout_reset(); - displayio_display_obj_t* display = &displays[0].display; + displayio_display_obj_t *display = &displays[0].display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct( display, diff --git a/ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h b/ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h index 99cb0982c9..2e6486c372 100644 --- a/ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h +++ b/ports/esp32s2/boards/adafruit_funhouse/mpconfigboard.h @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -//Micropython setup +// Micropython setup #define MICROPY_HW_BOARD_NAME "Adafruit FunHome" #define MICROPY_HW_MCU_NAME "ESP32S2" diff --git a/ports/esp32s2/boards/artisense_rd00/board.c b/ports/esp32s2/boards/artisense_rd00/board.c index fb3e458cf4..2b18dd7592 100644 --- a/ports/esp32s2/boards/artisense_rd00/board.c +++ b/ports/esp32s2/boards/artisense_rd00/board.c @@ -34,10 +34,10 @@ void board_init(void) { common_hal_never_reset_pin(&pin_GPIO20); // Debug UART -#ifdef DEBUG + #ifdef DEBUG common_hal_never_reset_pin(&pin_GPIO43); common_hal_never_reset_pin(&pin_GPIO44); -#endif /* DEBUG */ + #endif /* DEBUG */ // Crystal common_hal_never_reset_pin(&pin_GPIO15); diff --git a/ports/esp32s2/boards/artisense_rd00/mpconfigboard.h b/ports/esp32s2/boards/artisense_rd00/mpconfigboard.h index e9ff39dbbd..0ee8c48ab8 100644 --- a/ports/esp32s2/boards/artisense_rd00/mpconfigboard.h +++ b/ports/esp32s2/boards/artisense_rd00/mpconfigboard.h @@ -24,9 +24,9 @@ * THE SOFTWARE. */ -//Micropython setup +// Micropython setup -//Same setup as the Saola board but with no Neopixel on board +// Same setup as the Saola board but with no Neopixel on board #define MICROPY_HW_BOARD_NAME "Artisense Reference Design RD00" #define MICROPY_HW_MCU_NAME "ESP32S2" diff --git a/ports/esp32s2/boards/atmegazero_esp32s2/board.c b/ports/esp32s2/boards/atmegazero_esp32s2/board.c index d8fd3a0a2b..a0e399b1ef 100644 --- a/ports/esp32s2/boards/atmegazero_esp32s2/board.c +++ b/ports/esp32s2/boards/atmegazero_esp32s2/board.c @@ -34,10 +34,10 @@ void board_init(void) { common_hal_never_reset_pin(&pin_GPIO20); // Debug UART -#ifdef DEBUG + #ifdef DEBUG common_hal_never_reset_pin(&pin_GPIO43); common_hal_never_reset_pin(&pin_GPIO44); -#endif /* DEBUG */ + #endif /* DEBUG */ // SPI Flash and RAM common_hal_never_reset_pin(&pin_GPIO26); diff --git a/ports/esp32s2/boards/atmegazero_esp32s2/mpconfigboard.h b/ports/esp32s2/boards/atmegazero_esp32s2/mpconfigboard.h index 3ef4e7eede..18fa67d245 100644 --- a/ports/esp32s2/boards/atmegazero_esp32s2/mpconfigboard.h +++ b/ports/esp32s2/boards/atmegazero_esp32s2/mpconfigboard.h @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -//Micropython setup +// Micropython setup #define MICROPY_HW_BOARD_NAME "ATMegaZero ESP32-S2" #define MICROPY_HW_MCU_NAME "ESP32S2" diff --git a/ports/mimxrt10xx/common-hal/pwmio/PWMOut.c b/ports/mimxrt10xx/common-hal/pwmio/PWMOut.c index 458fee6412..d48bda7cd1 100644 --- a/ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +++ b/ports/mimxrt10xx/common-hal/pwmio/PWMOut.c @@ -150,11 +150,11 @@ void pwmout_reset(void) { #define PWM_SRC_CLK_FREQ CLOCK_GetFreq(kCLOCK_IpgClk) static int calculate_pulse_count(uint32_t frequency, uint8_t *prescaler) { - if (frequency > PWM_SRC_CLK_FREQ/2) { + if (frequency > PWM_SRC_CLK_FREQ / 2) { return 0; } - for(int shift = 0; shift<8; shift++) { - int pulse_count = PWM_SRC_CLK_FREQ/(1<= 65535) { continue; } @@ -270,7 +270,7 @@ void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t *self, uint16_t d if (duty == 65535) { self->duty_scaled = self->pulse_count + 1; } else { - self->duty_scaled = ((uint32_t)duty * self->pulse_count + self->pulse_count/2) / 65535; + self->duty_scaled = ((uint32_t)duty * self->pulse_count + self->pulse_count / 2) / 65535; } switch (self->pwm->channel) { case kPWM_PwmX: @@ -292,7 +292,7 @@ uint16_t common_hal_pwmio_pwmout_get_duty_cycle(pwmio_pwmout_obj_t *self) { if (self->duty_cycle == 65535) { return 65535; } - return ((uint32_t)self->duty_scaled * 65535 + 65535/2) / self->pulse_count; + return ((uint32_t)self->duty_scaled * 65535 + 65535 / 2) / self->pulse_count; } void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t *self, @@ -319,7 +319,7 @@ void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t *self, } uint32_t common_hal_pwmio_pwmout_get_frequency(pwmio_pwmout_obj_t *self) { - return PWM_SRC_CLK_FREQ/self->pulse_count/(1 << self->prescaler); + return PWM_SRC_CLK_FREQ / self->pulse_count / (1 << self->prescaler); } bool common_hal_pwmio_pwmout_get_variable_frequency(pwmio_pwmout_obj_t *self) { diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/periph.h index 1b808b0b18..c77497a775 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/periph.h @@ -49,8 +49,8 @@ typedef struct { typedef struct { PWM_Type *pwm; - pwm_submodule_t submodule:4; - pwm_channels_t channel:4; + pwm_submodule_t submodule : 4; + pwm_channels_t channel : 4; uint8_t mux_mode; uint8_t input_idx; uint32_t input_reg; @@ -59,9 +59,9 @@ typedef struct { #define PWM_PIN(p_pwm, p_submodule, p_channel, p_iomuxc, p_pin) \ PWM_PIN_(p_pwm, p_submodule, p_channel, p_iomuxc, p_pin) - //----------------------------------------------------------// - // supplied by the expansion of p_iomuxc into multiple args // -#define PWM_PIN_(p_pwm, p_submodule, p_channel, p_mux_reg, p_mux_mode, p_input_reg, p_input_idx, p_config_reg, p_pin)\ +// ----------------------------------------------------------// +// supplied by the expansion of p_iomuxc into multiple args // +#define PWM_PIN_(p_pwm, p_submodule, p_channel, p_mux_reg, p_mux_mode, p_input_reg, p_input_idx, p_config_reg, p_pin) \ { \ .pwm = p_pwm, \ .submodule = p_submodule, \ diff --git a/ports/nrf/common-hal/alarm/__init__.c b/ports/nrf/common-hal/alarm/__init__.c index 3ce963f0d6..4a0fdeb8a0 100644 --- a/ports/nrf/common-hal/alarm/__init__.c +++ b/ports/nrf/common-hal/alarm/__init__.c @@ -80,42 +80,40 @@ STATIC nrf_sleep_source_t _get_wakeup_cause(void) { } if (reset_reason_saved & NRF_POWER_RESETREAS_RESETPIN_MASK) { return NRF_SLEEP_WAKEUP_RESETPIN; - } - else if (reset_reason_saved & NRF_POWER_RESETREAS_OFF_MASK) { + } else if (reset_reason_saved & NRF_POWER_RESETREAS_OFF_MASK) { return NRF_SLEEP_WAKEUP_GPIO; - } - else if (reset_reason_saved & NRF_POWER_RESETREAS_VBUS_MASK) { + } else if (reset_reason_saved & NRF_POWER_RESETREAS_VBUS_MASK) { return NRF_SLEEP_WAKEUP_VBUS; } return NRF_SLEEP_WAKEUP_UNDEFINED; } #ifdef NRF_DEBUG_PRINT -static const char* cause_str[] = { - "UNDEFINED", - "GPIO", - "TIMER", - "TOUCHPAD", - "VBUS", - "RESETPIN", +static const char *cause_str[] = { + "UNDEFINED", + "GPIO", + "TIMER", + "TOUCHPAD", + "VBUS", + "RESETPIN", }; void print_wakeup_cause(nrf_sleep_source_t cause) { if (cause >= 0 && cause < NRF_SLEEP_WAKEUP_ZZZ) { dbg_printf("wakeup cause = NRF_SLEEP_WAKEUP_%s\r\n", - cause_str[(int)cause]); + cause_str[(int)cause]); } } #endif bool common_hal_alarm_woken_from_sleep(void) { - nrf_sleep_source_t cause = _get_wakeup_cause(); -#ifdef NRF_DEBUG_PRINT - if (cause != NRF_SLEEP_WAKEUP_UNDEFINED) { - //print_wakeup_cause(cause); - } -#endif - return (cause == NRF_SLEEP_WAKEUP_GPIO || cause == NRF_SLEEP_WAKEUP_TIMER - || cause == NRF_SLEEP_WAKEUP_TOUCHPAD); + nrf_sleep_source_t cause = _get_wakeup_cause(); + #ifdef NRF_DEBUG_PRINT + if (cause != NRF_SLEEP_WAKEUP_UNDEFINED) { + // print_wakeup_cause(cause); + } + #endif + return cause == NRF_SLEEP_WAKEUP_GPIO || cause == NRF_SLEEP_WAKEUP_TIMER + || cause == NRF_SLEEP_WAKEUP_TOUCHPAD; } STATIC mp_obj_t _get_wake_alarm(size_t n_alarms, const mp_obj_t *alarms) { @@ -131,7 +129,7 @@ STATIC mp_obj_t _get_wake_alarm(size_t n_alarms, const mp_obj_t *alarms) { return alarm_pin_pinalarm_get_wakeup_alarm(n_alarms, alarms); } default: - break; + break; } return mp_const_none; } @@ -156,47 +154,48 @@ void system_on_idle_until_alarm(int64_t timediff_ms, uint32_t prescaler) { uint64_t start_tick = 0, end_tick = 0; int64_t tickdiff; -#if defined(MICROPY_QSPI_CS) + #if defined(MICROPY_QSPI_CS) qspi_flash_enter_sleep(); -#endif + #endif if (timediff_ms != -1) { have_timeout = true; -#if 0 - int64_t now = common_hal_time_monotonic_ms(); - dbg_printf("now_ms=%ld timediff_ms=%ld\r\n", (long)now, (long)timediff_ms); -#endif - if (timediff_ms < 0) timediff_ms = 0; - if (prescaler == 0) { - // 1 tick = 1/1024 sec = 1000/1024 ms - // -> 1 ms = 1024/1000 ticks - tickdiff = (mp_uint_t)(timediff_ms * 1024 / 1000); // ms -> ticks + #if 0 + int64_t now = common_hal_time_monotonic_ms(); + dbg_printf("now_ms=%ld timediff_ms=%ld\r\n", (long)now, (long)timediff_ms); + #endif + if (timediff_ms < 0) { + timediff_ms = 0; + } + if (prescaler == 0) { + // 1 tick = 1/1024 sec = 1000/1024 ms + // -> 1 ms = 1024/1000 ticks + tickdiff = (mp_uint_t)(timediff_ms * 1024 / 1000); // ms -> ticks + } else { + // 1 tick = prescaler/1024 sec = prescaler*1000/1024 ms + // -> 1ms = 1024/(1000*prescaler) ticks + tickdiff = (mp_uint_t)(timediff_ms * 1024 / (1000 * prescaler)); + } + start_tick = port_get_raw_ticks(NULL); + end_tick = start_tick + tickdiff; } - else { - // 1 tick = prescaler/1024 sec = prescaler*1000/1024 ms - // -> 1ms = 1024/(1000*prescaler) ticks - tickdiff = (mp_uint_t)(timediff_ms * 1024 / (1000 * prescaler)); - } - start_tick = port_get_raw_ticks(NULL); - end_tick = start_tick + tickdiff; - } -#if 0 + #if 0 dbg_printf("start_tick=%ld end_tick=%ld have_timeout=%c\r\n", (long)start_tick, (long)end_tick, have_timeout ? 'T' : 'F'); -#endif + #endif int64_t remaining; sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_NONE; - sleepmem_wakeup_pin = WAKEUP_PIN_UNDEF; + sleepmem_wakeup_pin = WAKEUP_PIN_UNDEF; -#ifdef NRF_DEBUG_PRINT + #ifdef NRF_DEBUG_PRINT int ct = 40; char reason = '?'; #define WAKEUP_REASON(x) reason = (x) -#else + #else #define WAKEUP_REASON(x) -#endif + #endif - while(1) { + while (1) { if (mp_hal_is_interrupted()) { WAKEUP_REASON('I'); break; @@ -222,12 +221,12 @@ void system_on_idle_until_alarm(int64_t timediff_ms, uint32_t prescaler) { } // Idle until an interrupt happens. port_idle_until_interrupt(); -#ifdef NRF_DEBUG_PRINT + #ifdef NRF_DEBUG_PRINT if (ct > 0) { dbg_printf("_"); --ct; } -#endif + #endif if (have_timeout) { remaining = end_tick - port_get_raw_ticks(NULL); if (remaining <= 0) { @@ -237,25 +236,24 @@ void system_on_idle_until_alarm(int64_t timediff_ms, uint32_t prescaler) { } } } -#ifdef NRF_DEBUG_PRINT + #ifdef NRF_DEBUG_PRINT dbg_printf("%c\r\n", reason); -#endif + #endif -#if defined(MICROPY_QSPI_CS) + #if defined(MICROPY_QSPI_CS) qspi_flash_exit_sleep(); -#endif + #endif -#ifdef NRF_DEBUG_PRINT + #ifdef NRF_DEBUG_PRINT tickdiff = port_get_raw_ticks(NULL) - start_tick; double sec; if (prescaler == 0) { sec = (double)tickdiff / 1024; - } - else { + } else { sec = (double)(tickdiff * prescaler) / 1024; } dbg_printf("lapse %6.1f sec\r\n", sec); -#endif + #endif } mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj_t *alarms) { @@ -263,17 +261,16 @@ mp_obj_t common_hal_alarm_light_sleep_until_alarms(size_t n_alarms, const mp_obj alarm_time_timealarm_clear_wakeup_time(); _setup_sleep_alarms(false, n_alarms, alarms); -#ifdef NRF_DEBUG_PRINT + #ifdef NRF_DEBUG_PRINT dbg_printf("\r\nlight sleep..."); -#endif + #endif int64_t timediff_ms = alarm_time_timealarm_get_wakeup_timediff_ms(); system_on_idle_until_alarm(timediff_ms, 0); if (mp_hal_is_interrupted()) { wake_alarm = mp_const_none; - } - else { + } else { wake_alarm = _get_wake_alarm(n_alarms, alarms); } alarm_reset(); @@ -291,24 +288,26 @@ void NORETURN common_hal_alarm_enter_deep_sleep(void) { alarm_pin_pinalarm_prepare_for_deep_sleep(); alarm_time_timealarm_prepare_for_deep_sleep(); -#ifdef NRF_DEBUG_PRINT + #ifdef NRF_DEBUG_PRINT dbg_printf("\r\ndeep sleep..."); -#endif + #endif int64_t timediff_ms = alarm_time_timealarm_get_wakeup_timediff_ms(); - tick_set_prescaler(PRESCALER_VALUE_IN_DEEP_SLEEP -1); -#ifdef NRF_DEBUG_PRINT - dbg_check_RTCprescaler(); //XXX -#endif + tick_set_prescaler(PRESCALER_VALUE_IN_DEEP_SLEEP - 1); + #ifdef NRF_DEBUG_PRINT + dbg_check_RTCprescaler(); // XXX + #endif system_on_idle_until_alarm(timediff_ms, PRESCALER_VALUE_IN_DEEP_SLEEP); -#ifdef NRF_DEBUG_PRINT + #ifdef NRF_DEBUG_PRINT dbg_printf("RESET...\r\n\r\n"); -#endif + #endif reset_cpu(); // should not reach here.. - while(1) ; + while (1) { + ; + } } // old version deep sleep code that was used in common_hal_alarm_enter_deep_sleep() @@ -316,15 +315,14 @@ void NORETURN common_hal_alarm_enter_deep_sleep(void) { #if 0 void OLD_go_system_off(void) { sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_NONE; - sleepmem_wakeup_pin = WAKEUP_PIN_UNDEF; + sleepmem_wakeup_pin = WAKEUP_PIN_UNDEF; uint8_t sd_enabled; sd_softdevice_is_enabled(&sd_enabled); set_memory_retention(); dbg_printf("OLD go system off.. %d\r\n", sd_enabled); if (sd_enabled) { sd_power_system_off(); - } - else { + } else { NRF_POWER->SYSTEMOFF = 1; } } @@ -334,9 +332,9 @@ void common_hal_alarm_pretending_deep_sleep(void) { alarm_pin_pinalarm_prepare_for_deep_sleep(); alarm_time_timealarm_prepare_for_deep_sleep(); -#ifdef NRF_DEBUG_PRINT + #ifdef NRF_DEBUG_PRINT dbg_printf("\r\npretending to deep sleep..."); -#endif + #endif int64_t timediff_ms = alarm_time_timealarm_get_wakeup_timediff_ms(); system_on_idle_until_alarm(timediff_ms, 0); diff --git a/ports/nrf/common-hal/alarm/pin/PinAlarm.c b/ports/nrf/common-hal/alarm/pin/PinAlarm.c index 3c38cad1ac..cf602e8202 100644 --- a/ports/nrf/common-hal/alarm/pin/PinAlarm.c +++ b/ports/nrf/common-hal/alarm/pin/PinAlarm.c @@ -82,12 +82,12 @@ bool common_hal_alarm_pin_pinalarm_get_pull(alarm_pin_pinalarm_obj_t *self) { static void pinalarm_gpiote_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { ++_pinhandler_gpiote_count; sleepmem_wakeup_event = SLEEPMEM_WAKEUP_BY_PIN; - sleepmem_wakeup_pin = pin & 0xFF; + sleepmem_wakeup_pin = pin & 0xFF; } bool alarm_pin_pinalarm_woke_us_up(void) { - return (sleepmem_wakeup_event == SLEEPMEM_WAKEUP_BY_PIN && - sleepmem_wakeup_pin != WAKEUP_PIN_UNDEF); + return sleepmem_wakeup_event == SLEEPMEM_WAKEUP_BY_PIN && + sleepmem_wakeup_pin != WAKEUP_PIN_UNDEF; } mp_obj_t alarm_pin_pinalarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *alarms) { @@ -96,8 +96,8 @@ mp_obj_t alarm_pin_pinalarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *al if (!mp_obj_is_type(alarms[i], &alarm_pin_pinalarm_type)) { continue; } - alarm_pin_pinalarm_obj_t *alarm = MP_OBJ_TO_PTR(alarms[i]); - if (alarm->pin->number == sleepmem_wakeup_pin) { + alarm_pin_pinalarm_obj_t *alarm = MP_OBJ_TO_PTR(alarms[i]); + if (alarm->pin->number == sleepmem_wakeup_pin) { return alarms[i]; } } @@ -106,8 +106,8 @@ mp_obj_t alarm_pin_pinalarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t *al alarm->pin = NULL; // Map the pin number back to a pin object. for (size_t i = 0; i < mcu_pin_globals.map.used; i++) { - const mcu_pin_obj_t* pin_obj = MP_OBJ_TO_PTR(mcu_pin_globals.map.table[i].value); - if ((size_t) pin_obj->number == sleepmem_wakeup_pin) { + const mcu_pin_obj_t *pin_obj = MP_OBJ_TO_PTR(mcu_pin_globals.map.table[i].value); + if ((size_t)pin_obj->number == sleepmem_wakeup_pin) { alarm->pin = mcu_pin_globals.map.table[i].value; break; } @@ -130,8 +130,8 @@ void alarm_pin_pinalarm_reset(void) { continue; } reset_pin_number(i); - nrfx_gpiote_in_event_disable((nrfx_gpiote_pin_t)i); - nrfx_gpiote_in_uninit((nrfx_gpiote_pin_t)i); + nrfx_gpiote_in_event_disable((nrfx_gpiote_pin_t)i); + nrfx_gpiote_in_uninit((nrfx_gpiote_pin_t)i); } high_alarms = 0; @@ -141,7 +141,7 @@ void alarm_pin_pinalarm_reset(void) { static void configure_pins_for_sleep(void) { nrfx_err_t err; - if ( nrfx_gpiote_is_init() ) { + if (nrfx_gpiote_is_init()) { nrfx_gpiote_uninit(); } err = nrfx_gpiote_init(NRFX_GPIOTE_CONFIG_IRQ_PRIORITY); @@ -157,7 +157,7 @@ static void configure_pins_for_sleep(void) { .hi_accuracy = true, .skip_gpio_setup = false }; - for(size_t i = 0; i < 64; ++i) { + for (size_t i = 0; i < 64; ++i) { uint64_t mask = 1ull << i; if (((high_alarms & mask) == 0) && ((low_alarms & mask) == 0)) { continue; @@ -165,28 +165,26 @@ static void configure_pins_for_sleep(void) { if (((high_alarms & mask) != 0) && ((low_alarms & mask) == 0)) { cfg.sense = NRF_GPIOTE_POLARITY_LOTOHI; cfg.pull = ((pull_pins & mask) != 0) ? - NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_NOPULL; - } - else + NRF_GPIO_PIN_PULLDOWN : NRF_GPIO_PIN_NOPULL; + } else if (((high_alarms & mask) == 0) && ((low_alarms & mask) != 0)) { cfg.sense = NRF_GPIOTE_POLARITY_HITOLO; cfg.pull = ((pull_pins & mask) != 0) ? - NRF_GPIO_PIN_PULLUP : NRF_GPIO_PIN_NOPULL; - } - else { + NRF_GPIO_PIN_PULLUP : NRF_GPIO_PIN_NOPULL; + } else { cfg.sense = NRF_GPIOTE_POLARITY_TOGGLE; cfg.pull = NRF_GPIO_PIN_NOPULL; } err = nrfx_gpiote_in_init((nrfx_gpiote_pin_t)i, &cfg, - pinalarm_gpiote_handler); - assert(err == NRFX_SUCCESS); + pinalarm_gpiote_handler); + assert(err == NRFX_SUCCESS); nrfx_gpiote_in_event_enable((nrfx_gpiote_pin_t)i, true); if (((high_alarms & mask) != 0) && ((low_alarms & mask) == 0)) { nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_HIGH); - } + } if (((high_alarms & mask) == 0) && ((low_alarms & mask) != 0)) { nrf_gpio_cfg_sense_set((uint32_t)i, NRF_GPIO_PIN_SENSE_LOW); - } + } } } @@ -200,10 +198,10 @@ void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ob if (!mp_obj_is_type(alarms[i], &alarm_pin_pinalarm_type)) { continue; } - alarm_pin_pinalarm_obj_t *alarm = MP_OBJ_TO_PTR(alarms[i]); + alarm_pin_pinalarm_obj_t *alarm = MP_OBJ_TO_PTR(alarms[i]); pin_number = alarm->pin->number; - //dbg_printf("alarm_pin_pinalarm_set_alarms(pin#=%d, val=%d, pull=%d)\r\n", pin_number, alarm->value, alarm->pull); + // dbg_printf("alarm_pin_pinalarm_set_alarms(pin#=%d, val=%d, pull=%d)\r\n", pin_number, alarm->value, alarm->pull); if (alarm->value) { high_alarms |= 1ull << pin_number; high_count++; @@ -218,25 +216,23 @@ void alarm_pin_pinalarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ob if (pin_number != -1) { if (!deep_sleep) { configure_pins_for_sleep(); - } - else { + } else { // we don't setup gpio HW here but do them in // alarm_pin_pinalarm_prepare_for_deep_sleep() below - reset_reason_saved = 0; - pins_configured = false; + reset_reason_saved = 0; + pins_configured = false; } - } - else { - //dbg_printf("alarm_pin_pinalarm_set_alarms() no valid pins\r\n"); + } else { + // dbg_printf("alarm_pin_pinalarm_set_alarms() no valid pins\r\n"); } } void alarm_pin_pinalarm_prepare_for_deep_sleep(void) { if (!pins_configured) { configure_pins_for_sleep(); - pins_configured = true; -#ifdef NRF_DEBUG_PRINT - //dbg_dump_GPIOregs(); -#endif + pins_configured = true; + #ifdef NRF_DEBUG_PRINT + // dbg_dump_GPIOregs(); + #endif } } diff --git a/ports/nrf/common-hal/alarm/time/TimeAlarm.c b/ports/nrf/common-hal/alarm/time/TimeAlarm.c index 6fb1aea1ef..1d30065529 100644 --- a/ports/nrf/common-hal/alarm/time/TimeAlarm.c +++ b/ports/nrf/common-hal/alarm/time/TimeAlarm.c @@ -55,10 +55,10 @@ mp_obj_t alarm_time_timealarm_get_wakeup_alarm(size_t n_alarms, const mp_obj_t * } bool alarm_time_timealarm_woke_us_up(void) { - return sleepmem_wakeup_event == SLEEPMEM_WAKEUP_BY_TIMER; + return sleepmem_wakeup_event == SLEEPMEM_WAKEUP_BY_TIMER; } -int64_t wakeup_time_saved =0; +int64_t wakeup_time_saved = 0; int64_t alarm_time_timealarm_get_wakeup_timediff_ms(void) { if (wakeup_time_saved == 0) { @@ -88,7 +88,7 @@ void alarm_time_timealarm_set_alarms(bool deep_sleep, size_t n_alarms, const mp_ if (timealarm_set) { mp_raise_ValueError(translate("Only one alarm.time alarm can be set.")); } - timealarm = MP_OBJ_TO_PTR(alarms[i]); + timealarm = MP_OBJ_TO_PTR(alarms[i]); timealarm_set = true; } if (!timealarm_set) { diff --git a/ports/nrf/common-hal/alarm/touch/TouchAlarm.c b/ports/nrf/common-hal/alarm/touch/TouchAlarm.c index e85797e692..2d7ee89bd3 100644 --- a/ports/nrf/common-hal/alarm/touch/TouchAlarm.c +++ b/ports/nrf/common-hal/alarm/touch/TouchAlarm.c @@ -28,7 +28,7 @@ #include "shared-bindings/alarm/touch/TouchAlarm.h" #include "shared-bindings/microcontroller/__init__.h" -//static volatile bool woke_up = false; +// static volatile bool woke_up = false; void common_hal_alarm_touch_touchalarm_construct(alarm_touch_touchalarm_obj_t *self, const mcu_pin_obj_t *pin) { mp_raise_NotImplementedError(NULL); diff --git a/ports/nrf/common-hal/countio/Counter.c b/ports/nrf/common-hal/countio/Counter.c index 94fadae7c3..e863f5475a 100644 --- a/ports/nrf/common-hal/countio/Counter.c +++ b/ports/nrf/common-hal/countio/Counter.c @@ -13,8 +13,8 @@ static void _intr_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { self->count += 1; } -void common_hal_countio_counter_construct(countio_counter_obj_t* self, - const mcu_pin_obj_t* pin_a) { +void common_hal_countio_counter_construct(countio_counter_obj_t *self, + const mcu_pin_obj_t *pin_a) { self->pin_a = pin_a->number; _countio_objs[self->pin_a] = self; @@ -36,11 +36,11 @@ void common_hal_countio_counter_construct(countio_counter_obj_t* self, } -bool common_hal_countio_counter_deinited(countio_counter_obj_t* self) { +bool common_hal_countio_counter_deinited(countio_counter_obj_t *self) { return self->pin_a == NO_PIN; } -void common_hal_countio_counter_deinit(countio_counter_obj_t* self) { +void common_hal_countio_counter_deinit(countio_counter_obj_t *self) { if (common_hal_countio_counter_deinited(self)) { return; } @@ -52,15 +52,15 @@ void common_hal_countio_counter_deinit(countio_counter_obj_t* self) { self->pin_a = NO_PIN; } -mp_int_t common_hal_countio_counter_get_count(countio_counter_obj_t* self) { +mp_int_t common_hal_countio_counter_get_count(countio_counter_obj_t *self) { return self->count; } -void common_hal_countio_counter_set_count(countio_counter_obj_t* self, - mp_int_t new_count) { +void common_hal_countio_counter_set_count(countio_counter_obj_t *self, + mp_int_t new_count) { self->count = new_count; } -void common_hal_countio_counter_reset(countio_counter_obj_t* self){ - self->count = 0; +void common_hal_countio_counter_reset(countio_counter_obj_t *self) { + self->count = 0; } diff --git a/ports/nrf/common-hal/countio/__init__.c b/ports/nrf/common-hal/countio/__init__.c index b95b20d153..d47de33e53 100644 --- a/ports/nrf/common-hal/countio/__init__.c +++ b/ports/nrf/common-hal/countio/__init__.c @@ -1 +1 @@ -//No countio module functions +// No countio module functions diff --git a/ports/nrf/common-hal/microcontroller/Processor.c b/ports/nrf/common-hal/microcontroller/Processor.c index bcad002ffe..f59fc54972 100644 --- a/ports/nrf/common-hal/microcontroller/Processor.c +++ b/ports/nrf/common-hal/microcontroller/Processor.c @@ -129,22 +129,18 @@ void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { mcu_reset_reason_t r = RESET_REASON_UNKNOWN; if (reset_reason_saved == 0) { - r = RESET_REASON_POWER_ON; - } - else if (reset_reason_saved & POWER_RESETREAS_RESETPIN_Msk) { - r = RESET_REASON_RESET_PIN; - } - else if (reset_reason_saved & POWER_RESETREAS_DOG_Msk) { - r = RESET_REASON_WATCHDOG; - } - else if (reset_reason_saved & POWER_RESETREAS_SREQ_Msk) { - r = RESET_REASON_SOFTWARE; - } - else if ((reset_reason_saved & POWER_RESETREAS_OFF_Msk) || - (reset_reason_saved & POWER_RESETREAS_LPCOMP_Msk) || - (reset_reason_saved & POWER_RESETREAS_NFC_Msk) || - (reset_reason_saved & POWER_RESETREAS_VBUS_Msk)) { - r = RESET_REASON_DEEP_SLEEP_ALARM; + r = RESET_REASON_POWER_ON; + } else if (reset_reason_saved & POWER_RESETREAS_RESETPIN_Msk) { + r = RESET_REASON_RESET_PIN; + } else if (reset_reason_saved & POWER_RESETREAS_DOG_Msk) { + r = RESET_REASON_WATCHDOG; + } else if (reset_reason_saved & POWER_RESETREAS_SREQ_Msk) { + r = RESET_REASON_SOFTWARE; + } else if ((reset_reason_saved & POWER_RESETREAS_OFF_Msk) || + (reset_reason_saved & POWER_RESETREAS_LPCOMP_Msk) || + (reset_reason_saved & POWER_RESETREAS_NFC_Msk) || + (reset_reason_saved & POWER_RESETREAS_VBUS_Msk)) { + r = RESET_REASON_DEEP_SLEEP_ALARM; } return r; } diff --git a/ports/nrf/common-hal/rotaryio/IncrementalEncoder.c b/ports/nrf/common-hal/rotaryio/IncrementalEncoder.c index 8b46c3bd79..bc5851ccd4 100644 --- a/ports/nrf/common-hal/rotaryio/IncrementalEncoder.c +++ b/ports/nrf/common-hal/rotaryio/IncrementalEncoder.c @@ -42,8 +42,8 @@ static void _intr_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { } uint8_t new_state = - ((uint8_t) nrf_gpio_pin_read(self->pin_a) << 1) | - (uint8_t) nrf_gpio_pin_read(self->pin_b); + ((uint8_t)nrf_gpio_pin_read(self->pin_a) << 1) | + (uint8_t)nrf_gpio_pin_read(self->pin_b); shared_module_softencoder_state_update(self, new_state); } diff --git a/ports/nrf/supervisor/debug_uart.c b/ports/nrf/supervisor/debug_uart.c index 9cf33279f7..f5a9b1f47d 100644 --- a/ports/nrf/supervisor/debug_uart.c +++ b/ports/nrf/supervisor/debug_uart.c @@ -50,20 +50,20 @@ extern uint32_t reset_reason_saved; const nrfx_uarte_t _dbg_uart_inst = NRFX_UARTE_INSTANCE(1); static int _dbg_uart_initialized = 0; #define DBG_PBUF_LEN 80 -static char _dbg_pbuf[DBG_PBUF_LEN+1]; +static char _dbg_pbuf[DBG_PBUF_LEN + 1]; void _debug_uart_uninit(void) { nrf_gpio_cfg(DEBUG_UART_TXPIN, - NRF_GPIO_PIN_DIR_INPUT, - NRF_GPIO_PIN_INPUT_DISCONNECT, - NRF_GPIO_PIN_NOPULL, - NRF_GPIO_PIN_S0S1, - NRF_GPIO_PIN_NOSENSE); + NRF_GPIO_PIN_DIR_INPUT, + NRF_GPIO_PIN_INPUT_DISCONNECT, + NRF_GPIO_PIN_NOPULL, + NRF_GPIO_PIN_S0S1, + NRF_GPIO_PIN_NOSENSE); nrfx_uarte_uninit(&_dbg_uart_inst); } void _debug_uart_init(void) { - //if (_dbg_uart_initialized) return; + // if (_dbg_uart_initialized) return; nrfx_uarte_config_t config = { .pseltxd = DEBUG_UART_TXPIN, .pselrxd = DEBUG_UART_RXPIN, @@ -80,30 +80,29 @@ void _debug_uart_init(void) { nrfx_uarte_init(&_dbg_uart_inst, &config, NULL); // drive config nrf_gpio_cfg(config.pseltxd, - NRF_GPIO_PIN_DIR_OUTPUT, - NRF_GPIO_PIN_INPUT_DISCONNECT, - NRF_GPIO_PIN_PULLUP, // orig=NOPULL - NRF_GPIO_PIN_H0H1, // orig=S0S1 - NRF_GPIO_PIN_NOSENSE); + NRF_GPIO_PIN_DIR_OUTPUT, + NRF_GPIO_PIN_INPUT_DISCONNECT, + NRF_GPIO_PIN_PULLUP, // orig=NOPULL + NRF_GPIO_PIN_H0H1, // orig=S0S1 + NRF_GPIO_PIN_NOSENSE); _dbg_uart_initialized = 1; return; } -void _debug_print_substr(const char* text, uint32_t length) { - char* data = (char*)text; - int siz; - while(length != 0) { +void _debug_print_substr(const char *text, uint32_t length) { + char *data = (char *)text; + int siz; + while (length != 0) { if (length <= DBG_PBUF_LEN) { - siz = length; - } - else { - siz = DBG_PBUF_LEN; - } - memcpy(_dbg_pbuf, data, siz); - _dbg_pbuf[siz] = 0; - nrfx_uarte_tx(&_dbg_uart_inst, (uint8_t const*)_dbg_pbuf, siz); - data += siz; - length -= siz; + siz = length; + } else { + siz = DBG_PBUF_LEN; + } + memcpy(_dbg_pbuf, data, siz); + _dbg_pbuf[siz] = 0; + nrfx_uarte_tx(&_dbg_uart_inst, (uint8_t const *)_dbg_pbuf, siz); + data += siz; + length -= siz; } } @@ -121,7 +120,7 @@ int dbg_printf(const char *fmt, ...) { void dbg_dump_RTCreg(void) { dbg_printf("\r\nRTC2\r\n"); - NRF_RTC_Type *r = rtc_instance.p_reg; + NRF_RTC_Type *r = rtc_instance.p_reg; dbg_printf("PRESCALER=%08X, ", (int)r->PRESCALER); dbg_printf("COUNTER=%08X ", (int)r->COUNTER); dbg_printf("INTENSET=%08X ", (int)r->INTENSET); @@ -131,19 +130,21 @@ void dbg_dump_RTCreg(void) { } int dbg_check_RTCprescaler(void) { - NRF_RTC_Type *r = rtc_instance.p_reg; + NRF_RTC_Type *r = rtc_instance.p_reg; if ((int)r->PRESCALER == 0) { dbg_printf("****** PRESCALER == 0\r\n"); - return -1; + return -1; } return 0; } void dbg_dump_RAMreg(void) { int i; - for(i = 0; i <= 8; ++i) { + for (i = 0; i <= 8; ++i) { dbg_printf(" RAM%d:%08X", i, (int)(NRF_POWER->RAM[i].POWER)); - if (i==4) dbg_printf("\r\n"); + if (i == 4) { + dbg_printf("\r\n"); + } } dbg_printf("\r\n"); } @@ -154,52 +155,58 @@ void dbg_dump_GPIOregs(void) { NRF_GPIO_Type *gpio[] = { NRF_P0, NRF_P1 }; const char cnf_pull_chr[] = "-D*U"; // pull down, pull up const char cnf_sense_chr[] = "-?HL"; // sense high, sense low - for(port=0, col=0; port<=1; ++port) { - for(i=0; i<32; ++i) { - uint32_t cnf = gpio[port]->PIN_CNF[i]; - if (cnf != 0x0002) { // changed from default value - dbg_printf("[%d_%02d]:%c%c%c%d%c ", port, i, - (cnf & 1) ? 'O' : 'I', // output, input - (cnf & 2) ? 'd' : 'c', // disconnected, connected - cnf_pull_chr[(cnf >> 2) & 3], - (int)((cnf >> 8) & 7), // drive config 0-7 - cnf_sense_chr[(cnf >> 16) & 3]); - if (++col >= 6) { - dbg_printf("\r\n"); - col = 0; - } + for (port = 0, col = 0; port <= 1; ++port) { + for (i = 0; i < 32; ++i) { + uint32_t cnf = gpio[port]->PIN_CNF[i]; + if (cnf != 0x0002) { // changed from default value + dbg_printf("[%d_%02d]:%c%c%c%d%c ", port, i, + (cnf & 1) ? 'O' : 'I', // output, input + (cnf & 2) ? 'd' : 'c', // disconnected, connected + cnf_pull_chr[(cnf >> 2) & 3], + (int)((cnf >> 8) & 7), // drive config 0-7 + cnf_sense_chr[(cnf >> 16) & 3]); + if (++col >= 6) { + dbg_printf("\r\n"); + col = 0; + } + } } } + if (col > 0) { + dbg_printf("\r\n"); } - if (col > 0) dbg_printf("\r\n"); dbg_printf("GPIOTE\r\n"); NRF_GPIOTE_Type const *reg = NRF_GPIOTE; const char config_mode_chr[] = "-E-T"; // event, task const char config_pol_chr[] = "-HLT"; // low-to-Hi, hi-to-Low, Toggle const char config_outinit_chr[] = "01"; // initial value is 0 or 1 - for(i=0, col=0; i<8; ++i) { + for (i = 0, col = 0; i < 8; ++i) { uint32_t conf = reg->CONFIG[i]; - if (conf != 0) { // changed from default value - dbg_printf("CONFIG[%d]:%d_%02d,%c%c%c ", i, - (int)((conf >> 13) & 1), (int)((conf >> 8) & 0x1F), - config_mode_chr[conf & 3], - config_pol_chr[(conf >> 16) & 3], - (conf & 3) == 3 ? - config_outinit_chr[(conf >> 20) & 1] : '-'); - if (++col >= 4) { - dbg_printf("\r\n"); - col = 0; + if (conf != 0) { // changed from default value + dbg_printf("CONFIG[%d]:%d_%02d,%c%c%c ", i, + (int)((conf >> 13) & 1), (int)((conf >> 8) & 0x1F), + config_mode_chr[conf & 3], + config_pol_chr[(conf >> 16) & 3], + (conf & 3) == 3 ? + config_outinit_chr[(conf >> 20) & 1] : '-'); + if (++col >= 4) { + dbg_printf("\r\n"); + col = 0; + } } } + if (col > 0) { + dbg_printf("\r\n"); } - if (col > 0) dbg_printf("\r\n"); - for(i=0; i<8; ++i) { + for (i = 0; i < 8; ++i) { dbg_printf("EVENTS_IN[%d]:%X ", i, (int)(reg->EVENTS_IN[i])); - if ((i & 3) == 3) dbg_printf("\r\n"); + if ((i & 3) == 3) { + dbg_printf("\r\n"); + } } dbg_printf("EVENTS_PORT:%X INTENSET:%08X\r\n", - (int)(reg->EVENTS_PORT), (int)(reg->INTENSET)); + (int)(reg->EVENTS_PORT), (int)(reg->INTENSET)); } void dbg_dumpQSPIreg(void) { @@ -207,22 +214,22 @@ void dbg_dumpQSPIreg(void) { dbg_printf("QSPI\r\n"); r = NRF_QSPI->IFCONFIG0; dbg_printf("IFCONFIG0 READ=%ld write=%ld ADDR=%ld DPM=%ld PPSIZE=%ld\r\n", - r & 7, (r >> 3) & 7, (r >> 6) & 1, (r >> 7) & 1, (r >> 12) & 1); + r & 7, (r >> 3) & 7, (r >> 6) & 1, (r >> 7) & 1, (r >> 12) & 1); r = NRF_QSPI->IFCONFIG1; dbg_printf("IFCONFIG1 SCKDELAY=%ld SPIMODE=%ld SCKFREQ=%ld\r\n", - r & 0xFF, (r >> 25) & 1, (r >> 28) & 0xF); + r & 0xFF, (r >> 25) & 1, (r >> 28) & 0xF); r = NRF_QSPI->STATUS; dbg_printf("STATUS DPM=%ld READY=%ld SREG=0x%02lX\r\n", - (r >> 2) & 1, (r >> 3) & 1, (r >> 24) & 0xFF); + (r >> 2) & 1, (r >> 3) & 1, (r >> 24) & 0xFF); r = NRF_QSPI->DPMDUR; dbg_printf("DPMDUR ENTER=%ld EXIT=%ld\r\n", r & 0xFFFF, (r >> 16) & 0xFFFF); } void dbg_dump_reset_reason(void) { int reset_reason = (int)common_hal_mcu_processor_get_reset_reason(); - const char* rr_str[] = { - "POWER_ON", "BROWNOUT", "SOFTWARE", "DEEPSLEEPALARM", - "RESET_PIN", "WATCHDOG", "UNKNOWN" + const char *rr_str[] = { + "POWER_ON", "BROWNOUT", "SOFTWARE", "DEEPSLEEPALARM", + "RESET_PIN", "WATCHDOG", "UNKNOWN" }; dbg_printf("reset_reason=%s\r\n", rr_str[reset_reason]); } diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c index e162c64837..26ee3b20dc 100644 --- a/ports/nrf/supervisor/port.c +++ b/ports/nrf/supervisor/port.c @@ -259,9 +259,9 @@ void reset_port(void) { reset_all_pins(); -#ifdef NRF_DEBUG_PRINT + #ifdef NRF_DEBUG_PRINT _debug_uart_init(); -#endif + #endif } void reset_to_bootloader(void) { diff --git a/ports/nrf/supervisor/qspi_flash.c b/ports/nrf/supervisor/qspi_flash.c index 6d1bec4422..cb380e6156 100644 --- a/ports/nrf/supervisor/qspi_flash.c +++ b/ports/nrf/supervisor/qspi_flash.c @@ -213,11 +213,11 @@ void spi_flash_init(void) { .readoc = NRF_QSPI_READOC_FASTREAD, .writeoc = NRF_QSPI_WRITEOC_PP, .addrmode = NRF_QSPI_ADDRMODE_24BIT, -#ifdef QSPI_FLASH_POWERDOWN + #ifdef QSPI_FLASH_POWERDOWN .dpmconfig = true -#else + #else .dpmconfig = false -#endif + #endif }, .phy_if = { .sck_freq = NRF_QSPI_FREQ_32MDIV16, // Start at a slow 2MHz and speed up once we know what we're talking to. @@ -243,12 +243,12 @@ void spi_flash_init(void) { // No callback for blocking API nrfx_qspi_init(&qspi_cfg, NULL, NULL); -#ifdef QSPI_FLASH_POWERDOWN + #ifdef QSPI_FLASH_POWERDOWN // If pin-reset while flash is in power-down mode, // the flash cannot accept any commands. Send CMD_WAKE to release it. spi_flash_write_command(CMD_WAKE, NULL, 0); NRFX_DELAY_US(WAIT_AFTER_DPM_EXIT); -#endif + #endif } void spi_flash_init_device(const external_flash_device *device) { @@ -274,59 +274,59 @@ void spi_flash_init_device(const external_flash_device *device) { } void qspi_flash_enter_sleep(void) { -#ifdef QSPI_FLASH_POWERDOWN + #ifdef QSPI_FLASH_POWERDOWN uint32_t r; NRF_QSPI->DPMDUR = ((DUR_DPM_ENTER & 0xFFFF) << 16) | (DUR_DPM_EXIT & 0xFFFF); // set sck_delay tempolarily r = NRF_QSPI->IFCONFIG1; sck_delay_saved = (r & QSPI_IFCONFIG1_SCKDELAY_Msk) - >> QSPI_IFCONFIG1_SCKDELAY_Pos; + >> QSPI_IFCONFIG1_SCKDELAY_Pos; NRF_QSPI->IFCONFIG1 = (NRF_QSPI->IFCONFIG1 & ~QSPI_IFCONFIG1_SCKDELAY_Msk) - | (SCK_DELAY << QSPI_IFCONFIG1_SCKDELAY_Pos); + | (SCK_DELAY << QSPI_IFCONFIG1_SCKDELAY_Pos); // enabling IFCONFIG0.DPMENABLE here won't work. // -> do it in spi_flash_init() - //NRF_QSPI->IFCONFIG0 |= QSPI_IFCONFIG0_DPMENABLE_Msk; - //dbg_dumpQSPIreg(); + // NRF_QSPI->IFCONFIG0 |= QSPI_IFCONFIG0_DPMENABLE_Msk; + // dbg_dumpQSPIreg(); // enter deep power-down mode (DPM) NRF_QSPI->IFCONFIG1 |= QSPI_IFCONFIG1_DPMEN_Msk; NRFX_DELAY_US(WAIT_AFTER_DPM_ENTER); if (!(NRF_QSPI->STATUS & QSPI_STATUS_DPM_Msk)) { -#ifdef NRF_DEBUG_PRINT + #ifdef NRF_DEBUG_PRINT dbg_printf("qspi flash: DPM failed\r\n"); -#endif + #endif } -#endif + #endif qspi_disable(); - //dbg_dumpQSPIreg(); + // dbg_dumpQSPIreg(); } void qspi_flash_exit_sleep(void) { qspi_enable(); -#ifdef QSPI_FLASH_POWERDOWN + #ifdef QSPI_FLASH_POWERDOWN if (NRF_QSPI->STATUS & QSPI_STATUS_DPM_Msk) { // exit deep power-down mode NRF_QSPI->IFCONFIG1 &= ~QSPI_IFCONFIG1_DPMEN_Msk; - NRFX_DELAY_US(WAIT_AFTER_DPM_EXIT); + NRFX_DELAY_US(WAIT_AFTER_DPM_EXIT); - if (NRF_QSPI->STATUS & QSPI_STATUS_DPM_Msk) { -#ifdef NRF_DEBUG_PRINT - dbg_printf("qspi flash: exiting DPM failed\r\n"); -#endif + if (NRF_QSPI->STATUS & QSPI_STATUS_DPM_Msk) { + #ifdef NRF_DEBUG_PRINT + dbg_printf("qspi flash: exiting DPM failed\r\n"); + #endif + } + // restore sck_delay + if (sck_delay_saved == 0) { + sck_delay_saved = 10; // default + } + NRF_QSPI->IFCONFIG1 + = (NRF_QSPI->IFCONFIG1 & ~QSPI_IFCONFIG1_SCKDELAY_Msk) + | (sck_delay_saved << QSPI_IFCONFIG1_SCKDELAY_Pos); } - // restore sck_delay - if (sck_delay_saved == 0) { - sck_delay_saved = 10; // default - } - NRF_QSPI->IFCONFIG1 - = (NRF_QSPI->IFCONFIG1 & ~QSPI_IFCONFIG1_SCKDELAY_Msk) - | (sck_delay_saved << QSPI_IFCONFIG1_SCKDELAY_Pos); - } - //dbg_dumpQSPIreg(); -#endif + // dbg_dumpQSPIreg(); + #endif } diff --git a/ports/raspberrypi/boards/sparkfun_micromod_rp2040/pins.c b/ports/raspberrypi/boards/sparkfun_micromod_rp2040/pins.c index 5414dd3e2b..90069a7e6f 100644 --- a/ports/raspberrypi/boards/sparkfun_micromod_rp2040/pins.c +++ b/ports/raspberrypi/boards/sparkfun_micromod_rp2040/pins.c @@ -37,7 +37,7 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_BUS10), MP_ROM_PTR(&pin_GPIO25) }, // BUS10 alias { MP_ROM_QSTR(MP_QSTR_ADC_DP), MP_ROM_PTR(&pin_GPIO25) }, // ADC_DP alias { MP_ROM_QSTR(MP_QSTR_CAM_VSYNC), MP_ROM_PTR(&pin_GPIO25) }, // CAM_VSYNC alias - // NC - G11 + // NC - G11 // PWM pins (PWM0,PWM1) { MP_ROM_QSTR(MP_QSTR_PWM0), MP_ROM_PTR(&pin_GPIO13) }, // GPIO13 - PWM0 diff --git a/ports/raspberrypi/common-hal/busio/I2C.c b/ports/raspberrypi/common-hal/busio/I2C.c index 0190959f87..a72675d6b6 100644 --- a/ports/raspberrypi/common-hal/busio/I2C.c +++ b/ports/raspberrypi/common-hal/busio/I2C.c @@ -162,7 +162,7 @@ void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) { } uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr, - const uint8_t *data, size_t len, bool transmit_stop_bit) { + const uint8_t *data, size_t len, bool transmit_stop_bit) { if (len == 0) { // The RP2040 I2C peripheral will not perform 0 byte writes. // So use bitbangio.I2C to do the write. diff --git a/ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c b/ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c index 2c91a2fa16..2a175470ee 100644 --- a/ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c +++ b/ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c @@ -44,7 +44,7 @@ // Define this to (1), and you can scope the instruction-pointer of the state machine on D26..28 (note the weird encoding though!) #define DEBUG_STATE_MACHINE (0) #if DEBUG_STATE_MACHINE -#define SIDE(x) ((x)<<8) +#define SIDE(x) ((x) << 8) #else #define SIDE(x) (0) #endif @@ -61,10 +61,10 @@ /* 0 */ pio_encode_wait_gpio(0, vsync) | _0, \ /* 1 */ pio_encode_wait_gpio(1, vsync) | _1, \ /* .wrap_target */ \ -/* 2 */ pio_encode_wait_gpio(1, href) | _2, \ -/* 3 */ pio_encode_wait_gpio(1, pclk) | _3, \ +/* 2 */ pio_encode_wait_gpio(1, href) | _2, \ +/* 3 */ pio_encode_wait_gpio(1, pclk) | _3, \ /* 4 */ pio_encode_in(pio_pins, width) | _4, \ -/* 5 */ pio_encode_wait_gpio(0, pclk) | _5, \ +/* 5 */ pio_encode_wait_gpio(0, pclk) | _5, \ /* .wrap */ \ } @@ -73,8 +73,7 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle const mcu_pin_obj_t *data_clock, const mcu_pin_obj_t *vertical_sync, const mcu_pin_obj_t *horizontal_reference, - int data_count) -{ + int data_count) { uint16_t imagecapture_code[] = IMAGECAPTURE_CODE(data_count, data_clock->number, vertical_sync->number, horizontal_reference->number); @@ -86,12 +85,12 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle data0, data_count, // in pins 0, 0, // in pulls NULL, 0, 0, 0, // set pins -#if DEBUG_STATE_MACHINE + #if DEBUG_STATE_MACHINE &pin_GPIO26, 3, 7, 7, // sideset pins -#else + #else NULL, 0, 0, 0, // sideset pins -#endif - (1<number) | (1<number) | (1<number), // wait gpio pins + #endif + (1 << vertical_sync->number) | (1 << horizontal_reference->number) | (1 << data_clock->number), // wait gpio pins true, // exclusive pin use false, 32, false, // out settings false, // wait for txstall @@ -103,21 +102,18 @@ void common_hal_imagecapture_parallelimagecapture_construct(imagecapture_paralle rp2pio_statemachine_set_wrap(&self->state_machine, 2, 5); } -void common_hal_imagecapture_parallelimagecapture_deinit(imagecapture_parallelimagecapture_obj_t *self) -{ +void common_hal_imagecapture_parallelimagecapture_deinit(imagecapture_parallelimagecapture_obj_t *self) { if (common_hal_imagecapture_parallelimagecapture_deinited(self)) { return; } return common_hal_rp2pio_statemachine_deinit(&self->state_machine); } -bool common_hal_imagecapture_parallelimagecapture_deinited(imagecapture_parallelimagecapture_obj_t *self) -{ +bool common_hal_imagecapture_parallelimagecapture_deinited(imagecapture_parallelimagecapture_obj_t *self) { return common_hal_rp2pio_statemachine_deinited(&self->state_machine); } -void common_hal_imagecapture_parallelimagecapture_capture(imagecapture_parallelimagecapture_obj_t *self, void *buffer, size_t bufsize) -{ +void common_hal_imagecapture_parallelimagecapture_capture(imagecapture_parallelimagecapture_obj_t *self, void *buffer, size_t bufsize) { PIO pio = self->state_machine.pio; uint sm = self->state_machine.state_machine; uint8_t offset = rp2pio_statemachine_program_offset(&self->state_machine); diff --git a/ports/raspberrypi/common-hal/pulseio/PulseIn.c b/ports/raspberrypi/common-hal/pulseio/PulseIn.c index 8d04981b6c..cd78f6807f 100644 --- a/ports/raspberrypi/common-hal/pulseio/PulseIn.c +++ b/ports/raspberrypi/common-hal/pulseio/PulseIn.c @@ -135,13 +135,13 @@ void common_hal_pulseio_pulsein_interrupt() { result = level_count; last_level = level; level_count = 1; - // Pulses that are londger than MAX_PULSE will return MAX_PULSE - if (result > MAX_PULSE ) { - result = MAX_PULSE; - } + // Pulses that are londger than MAX_PULSE will return MAX_PULSE + if (result > MAX_PULSE) { + result = MAX_PULSE; + } // ignore pulses that are too short if (result <= MAX_PULSE && result > MIN_PULSE) { - self->buffer[buf_index] = (uint16_t) result; + self->buffer[buf_index] = (uint16_t)result; buf_index++; self->len++; } diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c index 21ec09c42c..ab70a27fcd 100644 --- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c +++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c @@ -813,5 +813,5 @@ void rp2pio_statemachine_set_wrap(rp2pio_statemachine_obj_t *self, uint wrap_tar uint8_t sm = self->state_machine; uint8_t offset = rp2pio_statemachine_program_offset(self); - pio_sm_set_wrap(self->pio, sm, offset+wrap_target, offset+wrap); + pio_sm_set_wrap(self->pio, sm, offset + wrap_target, offset + wrap); } diff --git a/ports/stm/common-hal/audiopwmio/PWMAudioOut.c b/ports/stm/common-hal/audiopwmio/PWMAudioOut.c index e5c478e632..d7df155932 100644 --- a/ports/stm/common-hal/audiopwmio/PWMAudioOut.c +++ b/ports/stm/common-hal/audiopwmio/PWMAudioOut.c @@ -37,12 +37,12 @@ STATIC audiopwmio_pwmaudioout_obj_t *active_audio = NULL; STATIC void set_pin(uint8_t channel, GPIO_PinState state) { HAL_GPIO_WritePin(pin_port(active_audio->pin[channel]->port), - pin_mask(active_audio->pin[channel]->number), state); + pin_mask(active_audio->pin[channel]->number), state); } STATIC void toggle_pin(uint8_t channel) { HAL_GPIO_TogglePin(pin_port(active_audio->pin[channel]->port), - pin_mask(active_audio->pin[channel]->number)); + pin_mask(active_audio->pin[channel]->number)); } STATIC void set_drive_mode(const mcu_pin_obj_t *pin, uint32_t mode) { @@ -93,10 +93,10 @@ STATIC bool fill_buffers(audiopwmio_pwmaudioout_obj_t *self) { } uint32_t num_samples = buffer_length / self->bytes_per_sample / self->sample_channel_count; - int16_t *buffer16 = (int16_t*)buffer; + int16_t *buffer16 = (int16_t *)buffer; while (num_samples--) { - for (int8_t channel=0; channel < effective_channels; channel++) { + for (int8_t channel = 0; channel < effective_channels; channel++) { int16_t val; if (self->bytes_per_sample == 1) { val = *buffer++ << 8; @@ -121,7 +121,7 @@ STATIC bool fill_buffers(audiopwmio_pwmaudioout_obj_t *self) { if (self->len[channel] > 1) { self->buffer[channel][self->buffer_length[channel]++] = self->len[channel]; if (replicate) { - self->buffer[1-channel][self->buffer_length[1-channel]++] = self->len[channel]; + self->buffer[1 - channel][self->buffer_length[1 - channel]++] = self->len[channel]; } self->len[channel] = 0; } @@ -131,14 +131,14 @@ STATIC bool fill_buffers(audiopwmio_pwmaudioout_obj_t *self) { } } } while (get_buffer_result == GET_BUFFER_MORE_DATA && - (!self->buffer_length[0] || (self->pin[1] && !self->buffer_length[1]))); + (!self->buffer_length[0] || (self->pin[1] && !self->buffer_length[1]))); if (get_buffer_result == GET_BUFFER_DONE) { // It's the final countdown - for (int8_t channel=0; channel < effective_channels; channel++) { + for (int8_t channel = 0; channel < effective_channels; channel++) { self->buffer[channel][self->buffer_length[channel]++] = self->len[channel]; if (replicate) { - self->buffer[1-channel][self->buffer_length[1-channel]++] = self->len[channel]; + self->buffer[1 - channel][self->buffer_length[1 - channel]++] = self->len[channel]; } } @@ -163,10 +163,8 @@ STATIC void move_to_beginning(uint16_t *buffer, uint16_t *buffer_length, uint16_ STATIC void pwmaudioout_event_handler(void) { // Detect TIM Update event - if (__HAL_TIM_GET_FLAG(&tim_handle, TIM_FLAG_UPDATE) != RESET) - { - if (__HAL_TIM_GET_IT_SOURCE(&tim_handle, TIM_IT_UPDATE) != RESET) - { + if (__HAL_TIM_GET_FLAG(&tim_handle, TIM_FLAG_UPDATE) != RESET) { + if (__HAL_TIM_GET_IT_SOURCE(&tim_handle, TIM_IT_UPDATE) != RESET) { __HAL_TIM_CLEAR_IT(&tim_handle, TIM_IT_UPDATE); if (!active_audio || active_audio->paused) { __HAL_TIM_DISABLE_IT(&tim_handle, TIM_IT_UPDATE); @@ -221,7 +219,7 @@ void audiopwmout_reset() { // Caller validates that pins are free. void common_hal_audiopwmio_pwmaudioout_construct(audiopwmio_pwmaudioout_obj_t *self, - const mcu_pin_obj_t *left_channel, const mcu_pin_obj_t *right_channel, uint16_t quiescent_value) { + const mcu_pin_obj_t *left_channel, const mcu_pin_obj_t *right_channel, uint16_t quiescent_value) { // Set up the pin(s) for output self->pin[0] = left_channel; @@ -306,7 +304,7 @@ void common_hal_audiopwmio_pwmaudioout_play(audiopwmio_pwmaudioout_obj_t *self, // Calculate period (TODO: supersample to 1 MHz?) TIM_TypeDef *tim_instance = stm_peripherals_find_timer(); uint32_t source = stm_peripherals_timer_get_source_freq(tim_instance); - uint32_t prescaler = source/sample_rate; + uint32_t prescaler = source / sample_rate; // Activate timer active_audio = self; @@ -314,7 +312,7 @@ void common_hal_audiopwmio_pwmaudioout_play(audiopwmio_pwmaudioout_obj_t *self, stm_peripherals_timer_preinit(tim_instance, 4, pwmaudioout_event_handler); tim_handle.Instance = tim_instance; - tim_handle.Init.Period = 100; //immediately replaced. + tim_handle.Init.Period = 100; // immediately replaced. tim_handle.Init.Prescaler = prescaler - 1; tim_handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; tim_handle.Init.CounterMode = TIM_COUNTERMODE_UP; diff --git a/ports/stm/common-hal/pwmio/PWMOut.c b/ports/stm/common-hal/pwmio/PWMOut.c index beb6e44aa4..17ef82a060 100644 --- a/ports/stm/common-hal/pwmio/PWMOut.c +++ b/ports/stm/common-hal/pwmio/PWMOut.c @@ -183,7 +183,7 @@ pwmout_result_t common_hal_pwmio_pwmout_construct(pwmio_pwmout_obj_t *self, } } - //Channel/PWM init + // Channel/PWM init self->chan_handle.OCMode = TIM_OCMODE_PWM1; self->chan_handle.Pulse = timer_get_internal_duty(duty, period); self->chan_handle.OCPolarity = TIM_OCPOLARITY_HIGH; diff --git a/ports/unix/coverage-frzmpy/frzmpy1.py b/ports/unix/coverage-frzmpy/frzmpy1.py index 8ad0f15730..83231c81a5 100644 --- a/ports/unix/coverage-frzmpy/frzmpy1.py +++ b/ports/unix/coverage-frzmpy/frzmpy1.py @@ -1 +1 @@ -print('frzmpy1') +print("frzmpy1") diff --git a/ports/unix/coverage-frzmpy/frzmpy_pkg1/__init__.py b/ports/unix/coverage-frzmpy/frzmpy_pkg1/__init__.py index 8c023afeba..a0f0a6e540 100644 --- a/ports/unix/coverage-frzmpy/frzmpy_pkg1/__init__.py +++ b/ports/unix/coverage-frzmpy/frzmpy_pkg1/__init__.py @@ -1,3 +1,3 @@ # test frozen package with __init__.py -print('frzmpy_pkg1.__init__') +print("frzmpy_pkg1.__init__") x = 1 diff --git a/ports/unix/coverage-frzmpy/frzmpy_pkg2/mod.py b/ports/unix/coverage-frzmpy/frzmpy_pkg2/mod.py index a66b505bf6..bd5419a0a7 100644 --- a/ports/unix/coverage-frzmpy/frzmpy_pkg2/mod.py +++ b/ports/unix/coverage-frzmpy/frzmpy_pkg2/mod.py @@ -1,4 +1,6 @@ # test frozen package without __init__.py -print('frzmpy_pkg2.mod') +print("frzmpy_pkg2.mod") + + class Foo: x = 1 diff --git a/ports/unix/coverage-frzstr/frzstr1.py b/ports/unix/coverage-frzstr/frzstr1.py index 6e88ac38d2..cf4b98d338 100644 --- a/ports/unix/coverage-frzstr/frzstr1.py +++ b/ports/unix/coverage-frzstr/frzstr1.py @@ -1 +1 @@ -print('frzstr1') +print("frzstr1") diff --git a/ports/unix/coverage-frzstr/frzstr_pkg1/__init__.py b/ports/unix/coverage-frzstr/frzstr_pkg1/__init__.py index 1d1df9417e..748abb6ce9 100644 --- a/ports/unix/coverage-frzstr/frzstr_pkg1/__init__.py +++ b/ports/unix/coverage-frzstr/frzstr_pkg1/__init__.py @@ -1,3 +1,3 @@ # test frozen package with __init__.py -print('frzstr_pkg1.__init__') +print("frzstr_pkg1.__init__") x = 1 diff --git a/ports/unix/coverage-frzstr/frzstr_pkg2/mod.py b/ports/unix/coverage-frzstr/frzstr_pkg2/mod.py index bafb5978b0..9e256d9ea7 100644 --- a/ports/unix/coverage-frzstr/frzstr_pkg2/mod.py +++ b/ports/unix/coverage-frzstr/frzstr_pkg2/mod.py @@ -1,4 +1,6 @@ # test frozen package without __init__.py -print('frzstr_pkg2.mod') +print("frzstr_pkg2.mod") + + class Foo: x = 1 diff --git a/supervisor/shared/external_flash/spi_flash.c b/supervisor/shared/external_flash/spi_flash.c index 4f7d5f6d3a..9444e303a1 100644 --- a/supervisor/shared/external_flash/spi_flash.c +++ b/supervisor/shared/external_flash/spi_flash.c @@ -56,7 +56,7 @@ static void flash_disable(void) { common_hal_busio_spi_unlock(&supervisor_flash_spi_bus); } -static bool transfer(uint8_t* command, uint32_t command_length, uint8_t* data_in, uint8_t* data_out, uint32_t data_length) { +static bool transfer(uint8_t *command, uint32_t command_length, uint8_t *data_in, uint8_t *data_out, uint32_t data_length) { if (!flash_enable()) { return false; } diff --git a/tools/codeformat.py b/tools/codeformat.py index 58c5a8e39f..6a1528c163 100644 --- a/tools/codeformat.py +++ b/tools/codeformat.py @@ -32,6 +32,7 @@ import itertools import os import pathlib import re +import sys import subprocess # Relative to top-level repo dir. @@ -68,6 +69,45 @@ EXCLUSIONS = [ "tests/basics/*.py", ] +# None of the standard Python path matching routines implement the matching +# we want, which is most like git's "pathspec" version of globs. +# In particular, we want "**/" to match all directories. +# This routine is sufficient to work with the patterns we have, but +# subtle cases like character classes that contain meta-characters +# are not covered +def git_glob_to_regex(pat): + def transform(m): + m = m.group(0) + if m == "*": + return "[^/]*" + if m == "**": + return ".*" + if m == "?": + return "[^/]" + if m == ".": + return r"\." + return m + + result = [transform(part) for part in re.finditer(r"(\*\*|[*?.]|[^*?.]+)", pat)] + return "(^" + "".join(result) + "$)" + + +# Create a single, complicated regular expression that matches exactly the +# files we want, accounting for the PATHS as well as the EXCLUSIONS. +path_re = ( + "" + # First a negative lookahead assertion that it doesn't match + # any of the EXCLUSIONS + + "(?!" + + "|".join(git_glob_to_regex(pat) for pat in EXCLUSIONS) + + ")" + # Then a positive match for any of the PATHS + + "(?:" + + "|".join(git_glob_to_regex(pat) for pat in PATHS) + + ")" +) +path_rx = re.compile(path_re) + # Path to repo top-level dir. TOP = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) @@ -76,15 +116,15 @@ UNCRUSTIFY_CFG = os.path.join(TOP, "tools/uncrustify.cfg") C_EXTS = (".c", ".h") PY_EXTS = (".py",) +# Transform a filename argument relative to the current directory into one +# relative to the TOP directory, which is what we need when checking against +# path_rx. +def relative_filename(arg): + return str(pathlib.Path(arg).resolve().relative_to(TOP)) -def list_files(args, paths, exclusions=None, prefix=""): - files = set() - args = [os.path.join(prefix, arg) for arg in args] - for pattern in paths: - files.update(arg for arg in args if pathlib.Path(arg).match(pattern)) - for pattern in exclusions or []: - files.difference_update(fnmatch.filter(files, os.path.join(prefix, pattern))) - return sorted(files) + +def list_files(args): + return sorted(arg for arg in args if path_rx.match(relative_filename(arg))) def fixup_c(filename): @@ -111,7 +151,9 @@ def fixup_c(filename): if directive in ("if ", "ifdef ", "ifndef "): l_next = lines[0] indent_next = len(re.match(r"( *)", l_next).group(1)) - if indent - 4 == indent_next and re.match(r" +(} else |case )", l_next): + if indent - 4 == indent_next and re.match( + r" +(} else |case )", l_next + ): # This #-line (and all associated ones) needs dedenting by 4 spaces. l = l[4:] dedent_stack.append(indent - 4) @@ -135,19 +177,25 @@ def fixup_c(filename): def main(): - cmd_parser = argparse.ArgumentParser(description="Auto-format C and Python files -- to be used via pre-commit only.") + cmd_parser = argparse.ArgumentParser( + description="Auto-format C and Python files -- to be used via pre-commit only." + ) cmd_parser.add_argument("-c", action="store_true", help="Format C code only") cmd_parser.add_argument("-p", action="store_true", help="Format Python code only") cmd_parser.add_argument("-v", action="store_true", help="Enable verbose output") + cmd_parser.add_argument("--dry-run", action="store_true", help="Print, don't act") cmd_parser.add_argument("files", nargs="+", help="Run on specific globs") args = cmd_parser.parse_args() + if args.dry_run: + print(" ".join(sys.argv)) + # Setting only one of -c or -p disables the other. If both or neither are set, then do both. format_c = args.c or not args.p format_py = args.p or not args.c # Expand the arguments passed on the command line, subject to the PATHS and EXCLUSIONS - files = list_files(args.files, PATHS, EXCLUSIONS, TOP) + files = list_files(args.files) # Extract files matching a specific language. def lang_files(exts): @@ -161,7 +209,10 @@ def main(): file_args = list(itertools.islice(files, N)) if not file_args: break - subprocess.call(cmd + file_args) + if args.dry_run: + print(" ".join(cmd + file_args)) + else: + subprocess.call(cmd + file_args) # Format C files with uncrustify. if format_c: From 929ee8d3b4402d7ef06967569ca38157e26333cc Mon Sep 17 00:00:00 2001 From: nm3210 Date: Fri, 30 Apr 2021 14:16:13 -0400 Subject: [PATCH 099/103] Fix pre-commit whitespace error --- .../boards/sparkfun_thing_plus_rp2040/pins.c | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/ports/raspberrypi/boards/sparkfun_thing_plus_rp2040/pins.c b/ports/raspberrypi/boards/sparkfun_thing_plus_rp2040/pins.c index 72ae577ec2..a27a6c6550 100644 --- a/ports/raspberrypi/boards/sparkfun_thing_plus_rp2040/pins.c +++ b/ports/raspberrypi/boards/sparkfun_thing_plus_rp2040/pins.c @@ -4,11 +4,11 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { // Left side breakouts, top-to-bottom, as labeled { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO6) }, { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO6) }, - + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_GPIO7) }, { MP_ROM_QSTR(MP_QSTR_D23), MP_ROM_PTR(&pin_GPIO7) }, // GPIO7 & GPIO23 are shorted together { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO7) }, - + { MP_ROM_QSTR(MP_QSTR_D22), MP_ROM_PTR(&pin_GPIO22) }, { MP_ROM_QSTR(MP_QSTR_D21), MP_ROM_PTR(&pin_GPIO21) }, { MP_ROM_QSTR(MP_QSTR_D20), MP_ROM_PTR(&pin_GPIO20) }, @@ -16,46 +16,46 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_GPIO18) }, { MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_GPIO17) }, { MP_ROM_QSTR(MP_QSTR_D16), MP_ROM_PTR(&pin_GPIO16) }, - + // Right side breakouts, top-to-bottom, as labeled { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO8) }, - + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO0) }, { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO0) }, - + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO1) }, { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO1) }, - + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO4) }, { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO4) }, - + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO3) }, { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO3) }, - + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO2) }, { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO2) }, - + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) }, { MP_ROM_QSTR(MP_QSTR_D29), MP_ROM_PTR(&pin_GPIO29) }, - + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) }, { MP_ROM_QSTR(MP_QSTR_D28), MP_ROM_PTR(&pin_GPIO28) }, - + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, { MP_ROM_QSTR(MP_QSTR_D27), MP_ROM_PTR(&pin_GPIO27) }, - + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO28) }, { MP_ROM_QSTR(MP_QSTR_D26), MP_ROM_PTR(&pin_GPIO28) }, - + // SD Card { MP_ROM_QSTR(MP_QSTR_SD_SCK), MP_ROM_PTR(&pin_GPIO14)}, { MP_ROM_QSTR(MP_QSTR_SD_MOSI), MP_ROM_PTR(&pin_GPIO15)}, { MP_ROM_QSTR(MP_QSTR_SD_MISO), MP_ROM_PTR(&pin_GPIO12)}, { MP_ROM_QSTR(MP_QSTR_SD_CS), MP_ROM_PTR(&pin_GPIO9)}, - + // Others { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO25) }, // on-board LED (separate/additional from neopixel) - + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, From dfa7c3d32de122bc3d07d9f2880cb82ad953385c Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 30 Apr 2021 15:30:13 -0500 Subject: [PATCH 100/103] codeformat: Fix handling of `**` After discussing with danh, I noticed that `a/**/b` would not match `a/b`. After correcting this and re-running "pre-commit run --all", additional files were reindented, including the codeformat script itself. --- mpy-cross/main.c | 32 +- .../boards/cp_sapling_m0_revb/mpconfigboard.h | 6 +- ports/atmel-samd/common-hal/busio/I2C.h | 4 +- ports/atmel-samd/common-hal/busio/UART.c | 88 ++-- .../common-hal/i2cperipheral/I2CPeripheral.c | 14 +- .../common-hal/microcontroller/Pin.h | 2 +- .../common-hal/microcontroller/Processor.c | 104 ++--- .../common-hal/microcontroller/__init__.c | 378 +++++++++--------- ports/atmel-samd/common-hal/pulseio/PulseIn.c | 75 ++-- ports/nrf/common-hal/alarm/SleepMemory.c | 56 +-- py/makemoduledefs.py | 2 +- py/makeqstrdata.py | 3 +- py/makeversionhdr.py | 1 - py/objgenerator.c | 12 +- py/persistentcode.c | 6 +- py/qstr.c | 6 +- supervisor/serial.h | 2 +- tools/build_board_info.py | 38 +- tools/build_release_files.py | 6 +- tools/codeformat.py | 10 +- tools/gen_usb_descriptor.py | 1 - tools/mpy-tool.py | 12 +- 22 files changed, 431 insertions(+), 427 deletions(-) diff --git a/mpy-cross/main.c b/mpy-cross/main.c index 786f0635e3..f2b5c5090c 100644 --- a/mpy-cross/main.c +++ b/mpy-cross/main.c @@ -76,22 +76,22 @@ STATIC int compile_and_save(const char *file, const char *output_file, const cha STATIC int usage(char **argv) { printf( -"usage: %s [] [-X ] \n" -"Options:\n" -"--version : show version information\n" -"-o : output file for compiled bytecode (defaults to input with .mpy extension)\n" -"-s : source filename to embed in the compiled bytecode (defaults to input file)\n" -"-v : verbose (trace various operations); can be multiple\n" -"-O[N] : apply bytecode optimizations of level N\n" -"\n" -"Target specific options:\n" -"-msmall-int-bits=number : set the maximum bits used to encode a small-int\n" -"-mno-unicode : don't support unicode in compiled strings\n" -"-mcache-lookup-bc : cache map lookups in the bytecode\n" -"-march= : set architecture for native emitter; x86, x64, armv6, armv7m, xtensa\n" -"\n" -"Implementation specific options:\n", argv[0] -); + "usage: %s [] [-X ] \n" + "Options:\n" + "--version : show version information\n" + "-o : output file for compiled bytecode (defaults to input with .mpy extension)\n" + "-s : source filename to embed in the compiled bytecode (defaults to input file)\n" + "-v : verbose (trace various operations); can be multiple\n" + "-O[N] : apply bytecode optimizations of level N\n" + "\n" + "Target specific options:\n" + "-msmall-int-bits=number : set the maximum bits used to encode a small-int\n" + "-mno-unicode : don't support unicode in compiled strings\n" + "-mcache-lookup-bc : cache map lookups in the bytecode\n" + "-march= : set architecture for native emitter; x86, x64, armv6, armv7m, xtensa\n" + "\n" + "Implementation specific options:\n", argv[0] + ); int impl_opts_cnt = 0; printf( " emit={bytecode,native,viper} -- set the default code emitter\n" diff --git a/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.h b/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.h index 384c299e3d..2299f69998 100644 --- a/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.h +++ b/ports/atmel-samd/boards/cp_sapling_m0_revb/mpconfigboard.h @@ -7,9 +7,9 @@ #define MICROPY_PORT_B (0) #define MICROPY_PORT_C (0) -#define IGNORE_PIN_PA04 1 -#define IGNORE_PIN_PA05 1 -#define IGNORE_PIN_PA06 1 +#define IGNORE_PIN_PA04 1 +#define IGNORE_PIN_PA05 1 +#define IGNORE_PIN_PA06 1 #define IGNORE_PIN_PA12 1 #define IGNORE_PIN_PA13 1 #define IGNORE_PIN_PA20 1 diff --git a/ports/atmel-samd/common-hal/busio/I2C.h b/ports/atmel-samd/common-hal/busio/I2C.h index 6bec6e8047..74a1147fc7 100644 --- a/ports/atmel-samd/common-hal/busio/I2C.h +++ b/ports/atmel-samd/common-hal/busio/I2C.h @@ -41,7 +41,7 @@ typedef struct { uint8_t sda_pin; } busio_i2c_obj_t; -extern Sercom *samd_i2c_get_sercom(const mcu_pin_obj_t* scl, const mcu_pin_obj_t* sda, - uint8_t *sercom_index, uint32_t *sda_pinmux, uint32_t *scl_pinmux); +extern Sercom *samd_i2c_get_sercom(const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, + uint8_t *sercom_index, uint32_t *sda_pinmux, uint32_t *scl_pinmux); #endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_I2C_H diff --git a/ports/atmel-samd/common-hal/busio/UART.c b/ports/atmel-samd/common-hal/busio/UART.c index 9557c3b5f1..cd8263bc56 100644 --- a/ports/atmel-samd/common-hal/busio/UART.c +++ b/ports/atmel-samd/common-hal/busio/UART.c @@ -55,14 +55,14 @@ static void usart_async_rxc_callback(const struct usart_async_descriptor *const } void common_hal_busio_uart_construct(busio_uart_obj_t *self, - const mcu_pin_obj_t * tx, const mcu_pin_obj_t * rx, - const mcu_pin_obj_t * rts, const mcu_pin_obj_t * cts, - const mcu_pin_obj_t * rs485_dir, bool rs485_invert, + const mcu_pin_obj_t *tx, const mcu_pin_obj_t *rx, + const mcu_pin_obj_t *rts, const mcu_pin_obj_t *cts, + const mcu_pin_obj_t *rs485_dir, bool rs485_invert, uint32_t baudrate, uint8_t bits, busio_uart_parity_t parity, uint8_t stop, - mp_float_t timeout, uint16_t receiver_buffer_size, byte* receiver_buffer, + mp_float_t timeout, uint16_t receiver_buffer_size, byte *receiver_buffer, bool sigint_enabled) { - Sercom* sercom = NULL; + Sercom *sercom = NULL; uint8_t sercom_index = 255; // Unset index uint32_t rx_pinmux = 0; uint8_t rx_pad = 255; // Unset pad @@ -88,29 +88,29 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, self->timeout_ms = timeout * 1000; // This assignment is only here because the usart_async routines take a *const argument. - struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; + struct usart_async_descriptor *const usart_desc_p = (struct usart_async_descriptor *const)&self->usart_desc; for (int i = 0; i < NUM_SERCOMS_PER_PIN; i++) { - Sercom* potential_sercom = NULL; + Sercom *potential_sercom = NULL; if (have_tx) { sercom_index = tx->sercom[i].index; if (sercom_index >= SERCOM_INST_NUM) { continue; } potential_sercom = sercom_insts[sercom_index]; -#ifdef SAMD21 - if (potential_sercom->USART.CTRLA.bit.ENABLE != 0 || + #ifdef SAMD21 + if (potential_sercom->USART.CTRLA.bit.ENABLE != 0 || !(tx->sercom[i].pad == 0 || tx->sercom[i].pad == 2)) { continue; } -#endif -#ifdef SAM_D5X_E5X - if (potential_sercom->USART.CTRLA.bit.ENABLE != 0 || + #endif + #ifdef SAM_D5X_E5X + if (potential_sercom->USART.CTRLA.bit.ENABLE != 0 || !(tx->sercom[i].pad == 0)) { continue; } -#endif + #endif tx_pinmux = PINMUX(tx->number, (i == 0) ? MUX_C : MUX_D); tx_pad = tx->sercom[i].pad; if (rx == NULL) { @@ -158,7 +158,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, // self->buffer, so do it manually. (However, as long as internal // pointers like this are NOT moved, allocating the buffer // in the long-lived pool is not strictly necessary) - self->buffer = (uint8_t *) gc_alloc(self->buffer_length * sizeof(uint8_t), false, true); + self->buffer = (uint8_t *)gc_alloc(self->buffer_length * sizeof(uint8_t), false, true); if (self->buffer == NULL) { common_hal_busio_uart_deinit(self); mp_raise_msg_varg(&mp_type_MemoryError, translate("Failed to allocate RX buffer of %d bytes"), self->buffer_length * sizeof(uint8_t)); @@ -191,24 +191,24 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, // Doing a group mask and set of the registers saves 60 bytes over setting the bitfields individually. sercom->USART.CTRLA.reg &= ~(SERCOM_USART_CTRLA_TXPO_Msk | - SERCOM_USART_CTRLA_RXPO_Msk | - SERCOM_USART_CTRLA_FORM_Msk); + SERCOM_USART_CTRLA_RXPO_Msk | + SERCOM_USART_CTRLA_FORM_Msk); sercom->USART.CTRLA.reg |= SERCOM_USART_CTRLA_TXPO(tx_pad / 2) | - SERCOM_USART_CTRLA_RXPO(rx_pad) | - (parity == BUSIO_UART_PARITY_NONE ? 0 : SERCOM_USART_CTRLA_FORM(1)); + SERCOM_USART_CTRLA_RXPO(rx_pad) | + (parity == BUSIO_UART_PARITY_NONE ? 0 : SERCOM_USART_CTRLA_FORM(1)); // Enable tx and/or rx based on whether the pins were specified. // CHSIZE is 0 for 8 bits, 5, 6, 7 for 5, 6, 7 bits. 1 for 9 bits, but we don't support that. sercom->USART.CTRLB.reg &= ~(SERCOM_USART_CTRLB_TXEN | - SERCOM_USART_CTRLB_RXEN | - SERCOM_USART_CTRLB_PMODE | - SERCOM_USART_CTRLB_SBMODE | - SERCOM_USART_CTRLB_CHSIZE_Msk); + SERCOM_USART_CTRLB_RXEN | + SERCOM_USART_CTRLB_PMODE | + SERCOM_USART_CTRLB_SBMODE | + SERCOM_USART_CTRLB_CHSIZE_Msk); sercom->USART.CTRLB.reg |= (have_tx ? SERCOM_USART_CTRLB_TXEN : 0) | - (have_rx ? SERCOM_USART_CTRLB_RXEN : 0) | - (parity == BUSIO_UART_PARITY_ODD ? SERCOM_USART_CTRLB_PMODE : 0) | - (stop > 1 ? SERCOM_USART_CTRLB_SBMODE : 0) | - SERCOM_USART_CTRLB_CHSIZE(bits % 8); + (have_rx ? SERCOM_USART_CTRLB_RXEN : 0) | + (parity == BUSIO_UART_PARITY_ODD ? SERCOM_USART_CTRLB_PMODE : 0) | + (stop > 1 ? SERCOM_USART_CTRLB_SBMODE : 0) | + SERCOM_USART_CTRLB_CHSIZE(bits % 8); // Set baud rate common_hal_busio_uart_set_baudrate(self, baudrate); @@ -227,7 +227,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, gpio_set_pin_direction(tx->number, GPIO_DIRECTION_OUT); gpio_set_pin_pull_mode(tx->number, GPIO_PULL_OFF); gpio_set_pin_function(tx->number, tx_pinmux); - self->tx_pin = tx->number; + self->tx_pin = tx->number; claim_pin(tx); } else { self->tx_pin = NO_PIN; @@ -237,7 +237,7 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, gpio_set_pin_direction(rx->number, GPIO_DIRECTION_IN); gpio_set_pin_pull_mode(rx->number, GPIO_PULL_OFF); gpio_set_pin_function(rx->number, rx_pinmux); - self->rx_pin = rx->number; + self->rx_pin = rx->number; claim_pin(rx); } else { self->rx_pin = NO_PIN; @@ -255,7 +255,7 @@ void common_hal_busio_uart_deinit(busio_uart_obj_t *self) { return; } // This assignment is only here because the usart_async routines take a *const argument. - struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; + struct usart_async_descriptor *const usart_desc_p = (struct usart_async_descriptor *const)&self->usart_desc; usart_async_disable(usart_desc_p); usart_async_deinit(usart_desc_p); reset_pin_number(self->rx_pin); @@ -271,7 +271,7 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t } // This assignment is only here because the usart_async routines take a *const argument. - struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; + struct usart_async_descriptor *const usart_desc_p = (struct usart_async_descriptor *const)&self->usart_desc; if (len == 0) { // Nothing to read. @@ -328,7 +328,7 @@ size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data, } // This assignment is only here because the usart_async routines take a *const argument. - struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; + struct usart_async_descriptor *const usart_desc_p = (struct usart_async_descriptor *const)&self->usart_desc; struct io_descriptor *io; usart_async_get_io_descriptor(usart_desc_p, &io); @@ -359,21 +359,21 @@ uint32_t common_hal_busio_uart_get_baudrate(busio_uart_obj_t *self) { void common_hal_busio_uart_set_baudrate(busio_uart_obj_t *self, uint32_t baudrate) { // This assignment is only here because the usart_async routines take a *const argument. - struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; + struct usart_async_descriptor *const usart_desc_p = (struct usart_async_descriptor *const)&self->usart_desc; usart_async_set_baud_rate(usart_desc_p, - // Samples and ARITHMETIC vs FRACTIONAL must correspond to USART_SAMPR in - // hpl_sercom_config.h. - _usart_async_calculate_baud_rate(baudrate, // e.g. 9600 baud - PROTOTYPE_SERCOM_USART_ASYNC_CLOCK_FREQUENCY, - 16, // samples - USART_BAUDRATE_ASYNCH_ARITHMETIC, - 0 // fraction - not used for ARITHMETIC - )); + // Samples and ARITHMETIC vs FRACTIONAL must correspond to USART_SAMPR in + // hpl_sercom_config.h. + _usart_async_calculate_baud_rate(baudrate, // e.g. 9600 baud + PROTOTYPE_SERCOM_USART_ASYNC_CLOCK_FREQUENCY, + 16, // samples + USART_BAUDRATE_ASYNCH_ARITHMETIC, + 0 // fraction - not used for ARITHMETIC + )); self->baudrate = baudrate; } mp_float_t common_hal_busio_uart_get_timeout(busio_uart_obj_t *self) { - return (mp_float_t) (self->timeout_ms / 1000.0f); + return (mp_float_t)(self->timeout_ms / 1000.0f); } void common_hal_busio_uart_set_timeout(busio_uart_obj_t *self, mp_float_t timeout) { @@ -382,7 +382,7 @@ void common_hal_busio_uart_set_timeout(busio_uart_obj_t *self, mp_float_t timeou uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self) { // This assignment is only here because the usart_async routines take a *const argument. - struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; + struct usart_async_descriptor *const usart_desc_p = (struct usart_async_descriptor *const)&self->usart_desc; struct usart_async_status async_status; usart_async_get_status(usart_desc_p, &async_status); return async_status.rxcnt; @@ -390,7 +390,7 @@ uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self) { void common_hal_busio_uart_clear_rx_buffer(busio_uart_obj_t *self) { // This assignment is only here because the usart_async routines take a *const argument. - struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; + struct usart_async_descriptor *const usart_desc_p = (struct usart_async_descriptor *const)&self->usart_desc; usart_async_flush_rx_buffer(usart_desc_p); } @@ -401,7 +401,7 @@ bool common_hal_busio_uart_ready_to_tx(busio_uart_obj_t *self) { return false; } // This assignment is only here because the usart_async routines take a *const argument. - struct usart_async_descriptor * const usart_desc_p = (struct usart_async_descriptor * const) &self->usart_desc; + struct usart_async_descriptor *const usart_desc_p = (struct usart_async_descriptor *const)&self->usart_desc; struct usart_async_status async_status; usart_async_get_status(usart_desc_p, &async_status); return !(async_status.flags & USART_ASYNC_STATUS_BUSY); diff --git a/ports/atmel-samd/common-hal/i2cperipheral/I2CPeripheral.c b/ports/atmel-samd/common-hal/i2cperipheral/I2CPeripheral.c index 53cbe854fd..961fde8439 100644 --- a/ports/atmel-samd/common-hal/i2cperipheral/I2CPeripheral.c +++ b/ports/atmel-samd/common-hal/i2cperipheral/I2CPeripheral.c @@ -36,8 +36,8 @@ #include "peripherals/samd/sercom.h" void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_peripheral_obj_t *self, - const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, - uint8_t *addresses, unsigned int num_addresses, bool smbus) { + const mcu_pin_obj_t *scl, const mcu_pin_obj_t *sda, + uint8_t *addresses, unsigned int num_addresses, bool smbus) { uint8_t sercom_index; uint32_t sda_pinmux, scl_pinmux; Sercom *sercom = samd_i2c_get_sercom(scl, sda, &sercom_index, &sda_pinmux, &scl_pinmux); @@ -58,12 +58,13 @@ void common_hal_i2cperipheral_i2c_peripheral_construct(i2cperipheral_i2c_periphe samd_peripherals_sercom_clock_init(sercom, sercom_index); -#ifdef SAM_D5X_E5X + #ifdef SAM_D5X_E5X sercom->I2CS.CTRLC.bit.SDASETUP = 0x08; -#endif + #endif sercom->I2CS.CTRLA.bit.SWRST = 1; - while (sercom->I2CS.CTRLA.bit.SWRST || sercom->I2CS.SYNCBUSY.bit.SWRST) {} + while (sercom->I2CS.CTRLA.bit.SWRST || sercom->I2CS.SYNCBUSY.bit.SWRST) { + } sercom->I2CS.CTRLB.bit.AACKEN = 0; // Automatic acknowledge is disabled. @@ -134,8 +135,7 @@ static int i2c_peripheral_check_error(i2cperipheral_i2c_peripheral_obj_t *self, return -err; } -int common_hal_i2cperipheral_i2c_peripheral_is_addressed(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t *address, bool *is_read, bool *is_restart) -{ +int common_hal_i2cperipheral_i2c_peripheral_is_addressed(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t *address, bool *is_read, bool *is_restart) { int err = i2c_peripheral_check_error(self, false); if (err) { return err; diff --git a/ports/atmel-samd/common-hal/microcontroller/Pin.h b/ports/atmel-samd/common-hal/microcontroller/Pin.h index 59302713af..6e313acfd3 100644 --- a/ports/atmel-samd/common-hal/microcontroller/Pin.h +++ b/ports/atmel-samd/common-hal/microcontroller/Pin.h @@ -44,7 +44,7 @@ void reset_all_pins(void); // need to store a full pointer. void reset_pin_number(uint8_t pin_number); void never_reset_pin_number(uint8_t pin_number); -void claim_pin(const mcu_pin_obj_t* pin); +void claim_pin(const mcu_pin_obj_t *pin); bool pin_number_is_free(uint8_t pin_number); typedef struct { diff --git a/ports/atmel-samd/common-hal/microcontroller/Processor.c b/ports/atmel-samd/common-hal/microcontroller/Processor.c index 8c288a352e..2985cf5a67 100644 --- a/ports/atmel-samd/common-hal/microcontroller/Processor.c +++ b/ports/atmel-samd/common-hal/microcontroller/Processor.c @@ -83,11 +83,11 @@ STATIC float convert_dec_to_frac(uint8_t val) { float float_val = (float)val; if (val < 10) { - return (float_val/10.0); + return float_val / 10.0; } else if (val < 100) { - return (float_val/100.0); + return float_val / 100.0; } else { - return (float_val/1000.0); + return float_val / 1000.0; } } @@ -134,17 +134,17 @@ STATIC float calculate_temperature(uint16_t raw_value) { tempR = room_temp_val_int + convert_dec_to_frac(room_temp_val_dec); tempH = hot_temp_val_int + convert_dec_to_frac(hot_temp_val_dec); - INT1VR = 1 - ((float)room_int1v_val/INT1V_DIVIDER_1000); - INT1VH = 1 - ((float)hot_int1v_val/INT1V_DIVIDER_1000); + INT1VR = 1 - ((float)room_int1v_val / INT1V_DIVIDER_1000); + INT1VH = 1 - ((float)hot_int1v_val / INT1V_DIVIDER_1000); - VADCR = ((float)ADCR * INT1VR)/ADC_12BIT_FULL_SCALE_VALUE_FLOAT; - VADCH = ((float)ADCH * INT1VH)/ADC_12BIT_FULL_SCALE_VALUE_FLOAT; + VADCR = ((float)ADCR * INT1VR) / ADC_12BIT_FULL_SCALE_VALUE_FLOAT; + VADCH = ((float)ADCH * INT1VH) / ADC_12BIT_FULL_SCALE_VALUE_FLOAT; float VADC; /* Voltage calculation using ADC result for Coarse Temp calculation */ float VADCM; /* Voltage calculation using ADC result for Fine Temp calculation. */ float INT1VM; /* Voltage calculation for reality INT1V value during the ADC conversion */ - VADC = ((float)raw_value * INT1V_VALUE_FLOAT)/ADC_12BIT_FULL_SCALE_VALUE_FLOAT; + VADC = ((float)raw_value * INT1V_VALUE_FLOAT) / ADC_12BIT_FULL_SCALE_VALUE_FLOAT; // Hopefully compiler will remove common subepxressions here. @@ -152,15 +152,15 @@ STATIC float calculate_temperature(uint16_t raw_value) { // 1b as mentioned in data sheet section "Temperature Sensor Characteristics" // of Electrical Characteristics. (adapted from ASF sample code). // Coarse Temp Calculation by assume INT1V=1V for this ADC conversion - float coarse_temp = tempR + (((tempH - tempR)/(VADCH - VADCR)) * (VADC - VADCR)); + float coarse_temp = tempR + (((tempH - tempR) / (VADCH - VADCR)) * (VADC - VADCR)); // Calculation to find the real INT1V value during the ADC conversion - INT1VM = INT1VR + (((INT1VH - INT1VR) * (coarse_temp - tempR))/(tempH - tempR)); + INT1VM = INT1VR + (((INT1VH - INT1VR) * (coarse_temp - tempR)) / (tempH - tempR)); - VADCM = ((float)raw_value * INT1VM)/ADC_12BIT_FULL_SCALE_VALUE_FLOAT; + VADCM = ((float)raw_value * INT1VM) / ADC_12BIT_FULL_SCALE_VALUE_FLOAT; // Fine Temp Calculation by replace INT1V=1V by INT1V = INT1Vm for ADC conversion - float fine_temp = tempR + (((tempH - tempR)/(VADCH - VADCR)) * (VADCM - VADCR)); + float fine_temp = tempR + (((tempH - tempR) / (VADCH - VADCR)) * (VADCM - VADCR)); return fine_temp; } @@ -183,17 +183,17 @@ STATIC float calculate_temperature(uint16_t TP, uint16_t TC) { uint16_t VCH = (*(uint32_t *)FUSES_HOT_ADC_VAL_CTAT_ADDR & FUSES_HOT_ADC_VAL_CTAT_Msk) >> FUSES_HOT_ADC_VAL_CTAT_Pos; // From SAMD51 datasheet: section 45.6.3.1 (page 1327). - return (TL*VPH*TC - VPL*TH*TC - TL*VCH*TP + TH*VCL*TP) / (VCL*TP - VCH*TP - VPL*TC + VPH*TC); + return (TL * VPH * TC - VPL * TH * TC - TL * VCH * TP + TH * VCL * TP) / (VCL * TP - VCH * TP - VPL * TC + VPH * TC); } #endif // SAMD51 float common_hal_mcu_processor_get_temperature(void) { struct adc_sync_descriptor adc; - static Adc* adc_insts[] = ADC_INSTS; + static Adc *adc_insts[] = ADC_INSTS; samd_peripherals_adc_setup(&adc, adc_insts[0]); -#ifdef SAMD21 + #ifdef SAMD21 // The parameters chosen here are from the temperature example in: // http://www.atmel.com/images/Atmel-42645-ADC-Configurations-with-Examples_ApplicationNote_AT11481.pdf // That note also recommends in general: @@ -205,9 +205,9 @@ float common_hal_mcu_processor_get_temperature(void) { // Channel arg is ignored. adc_sync_enable_channel(&adc, IGNORED_CHANNEL); adc_sync_set_inputs(&adc, - ADC_INPUTCTRL_MUXPOS_TEMP_Val, // pos_input - ADC_INPUTCTRL_MUXNEG_GND_Val, // neg_input - IGNORED_CHANNEL); // channel (ignored) + ADC_INPUTCTRL_MUXPOS_TEMP_Val, // pos_input + ADC_INPUTCTRL_MUXNEG_GND_Val, // neg_input + IGNORED_CHANNEL); // channel (ignored) hri_adc_write_CTRLB_PRESCALER_bf(adc.device.hw, ADC_CTRLB_PRESCALER_DIV32_Val); hri_adc_write_SAMPCTRL_SAMPLEN_bf(adc.device.hw, ADC_TEMP_SAMPLE_LENGTH); @@ -227,14 +227,14 @@ float common_hal_mcu_processor_get_temperature(void) { // Empirical observation shows the first reading is quite different than subsequent ones. // Channel arg is ignored. - adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t*) &value), 2); - adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t*) &value), 2); + adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t *)&value), 2); + adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t *)&value), 2); adc_sync_deinit(&adc); return calculate_temperature(value); -#endif // SAMD21 + #endif // SAMD21 -#ifdef SAM_D5X_E5X + #ifdef SAM_D5X_E5X adc_sync_set_resolution(&adc, ADC_CTRLB_RESSEL_12BIT_Val); // Using INTVCC0 as the reference voltage. // INTVCC1 seems to read a little high. @@ -250,48 +250,48 @@ float common_hal_mcu_processor_get_temperature(void) { // Channel arg is ignored. adc_sync_enable_channel(&adc, IGNORED_CHANNEL); adc_sync_set_inputs(&adc, - ADC_INPUTCTRL_MUXPOS_PTAT_Val, // pos_input - ADC_INPUTCTRL_MUXNEG_GND_Val, // neg_input - IGNORED_CHANNEL); // channel (ignored) + ADC_INPUTCTRL_MUXPOS_PTAT_Val, // pos_input + ADC_INPUTCTRL_MUXNEG_GND_Val, // neg_input + IGNORED_CHANNEL); // channel (ignored) // Read both temperature sensors. volatile uint16_t ptat; volatile uint16_t ctat; // Read twice for stability (necessary?). - adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t*) &ptat), 2); - adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t*) &ptat), 2); + adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t *)&ptat), 2); + adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t *)&ptat), 2); adc_sync_set_inputs(&adc, - ADC_INPUTCTRL_MUXPOS_CTAT_Val, // pos_input - ADC_INPUTCTRL_MUXNEG_GND_Val, // neg_input - IGNORED_CHANNEL); // channel (ignored) + ADC_INPUTCTRL_MUXPOS_CTAT_Val, // pos_input + ADC_INPUTCTRL_MUXNEG_GND_Val, // neg_input + IGNORED_CHANNEL); // channel (ignored) - adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t*) &ctat), 2); - adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t*) &ctat), 2); + adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t *)&ctat), 2); + adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t *)&ctat), 2); // Turn off temp sensor. hri_supc_clear_VREF_TSEN_bit(SUPC); adc_sync_deinit(&adc); return calculate_temperature(ptat, ctat); -#endif // SAMD51 + #endif // SAMD51 } float common_hal_mcu_processor_get_voltage(void) { -#if MICROCONTROLLER_VOLTAGE_DISABLE + #if MICROCONTROLLER_VOLTAGE_DISABLE return NAN; -#else + #else struct adc_sync_descriptor adc; - static Adc* adc_insts[] = ADC_INSTS; + static Adc *adc_insts[] = ADC_INSTS; samd_peripherals_adc_setup(&adc, adc_insts[0]); -#ifdef SAMD21 + #ifdef SAMD21 adc_sync_set_reference(&adc, ADC_REFCTRL_REFSEL_INT1V_Val); -#endif + #endif -#ifdef SAM_D5X_E5X + #ifdef SAM_D5X_E5X hri_supc_set_VREF_SEL_bf(SUPC, SUPC_VREF_SEL_1V0_Val); hri_supc_set_VREF_VREFOE_bit(SUPC); @@ -302,14 +302,14 @@ float common_hal_mcu_processor_get_voltage(void) { // startup time. There is no synchronization bit to check. // See https://community.atmel.com/forum/samd51-using-intref-adc-voltage-reference mp_hal_delay_ms(1); -#endif + #endif adc_sync_set_resolution(&adc, ADC_CTRLB_RESSEL_12BIT_Val); // Channel arg is ignored. adc_sync_set_inputs(&adc, - ADC_INPUTCTRL_MUXPOS_SCALEDIOVCC_Val, // IOVCC/4 (nominal 3.3V/4) - ADC_INPUTCTRL_MUXNEG_GND_Val, // neg_input - IGNORED_CHANNEL); // channel (ignored). + ADC_INPUTCTRL_MUXPOS_SCALEDIOVCC_Val, // IOVCC/4 (nominal 3.3V/4) + ADC_INPUTCTRL_MUXNEG_GND_Val, // neg_input + IGNORED_CHANNEL); // channel (ignored). adc_sync_enable_channel(&adc, IGNORED_CHANNEL); volatile uint16_t reading; @@ -320,13 +320,13 @@ float common_hal_mcu_processor_get_voltage(void) { // "Discard the first conversion result whenever there is a change in ADC configuration // like voltage reference / ADC channel change" // Empirical observation shows the first reading is quite different than subsequent ones. - adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t*) &reading), 2); - adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t*) &reading), 2); + adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t *)&reading), 2); + adc_sync_read_channel(&adc, IGNORED_CHANNEL, ((uint8_t *)&reading), 2); adc_sync_deinit(&adc); // Multiply by 4 to compensate for SCALEDIOVCC division by 4. return (reading / 4095.0f) * 4.0f; -#endif + #endif } uint32_t common_hal_mcu_processor_get_frequency(void) { @@ -336,16 +336,16 @@ uint32_t common_hal_mcu_processor_get_frequency(void) { void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { #ifdef SAMD21 - uint32_t* id_addresses[4] = {(uint32_t *) 0x0080A00C, (uint32_t *) 0x0080A040, - (uint32_t *) 0x0080A044, (uint32_t *) 0x0080A048}; + uint32_t *id_addresses[4] = {(uint32_t *)0x0080A00C, (uint32_t *)0x0080A040, + (uint32_t *)0x0080A044, (uint32_t *)0x0080A048}; #endif #ifdef SAM_D5X_E5X - uint32_t* id_addresses[4] = {(uint32_t *) 0x008061FC, (uint32_t *) 0x00806010, - (uint32_t *) 0x00806014, (uint32_t *) 0x00806018}; + uint32_t *id_addresses[4] = {(uint32_t *)0x008061FC, (uint32_t *)0x00806010, + (uint32_t *)0x00806014, (uint32_t *)0x00806018}; #endif - for (int i=0; i<4; i++) { - for (int k=0; k<4; k++) { + for (int i = 0; i < 4; i++) { + for (int k = 0; k < 4; k++) { raw_id[4 * i + k] = (*(id_addresses[i]) >> k * 8) & 0xff; } } diff --git a/ports/atmel-samd/common-hal/microcontroller/__init__.c b/ports/atmel-samd/common-hal/microcontroller/__init__.c index 50a1ec038e..df1324c1fb 100644 --- a/ports/atmel-samd/common-hal/microcontroller/__init__.c +++ b/ports/atmel-samd/common-hal/microcontroller/__init__.c @@ -99,296 +99,296 @@ const nvm_bytearray_obj_t common_hal_mcu_nvm_obj = { .type = &nvm_bytearray_type, }, .len = CIRCUITPY_INTERNAL_NVM_SIZE, - .start_address = (uint8_t*) (CIRCUITPY_INTERNAL_NVM_START_ADDR) + .start_address = (uint8_t *)(CIRCUITPY_INTERNAL_NVM_START_ADDR) }; #endif // This maps MCU pin names to pin objects. STATIC const mp_rom_map_elem_t mcu_pin_global_dict_table[] = { -#if defined(PIN_PA00) && !defined(IGNORE_PIN_PA00) + #if defined(PIN_PA00) && !defined(IGNORE_PIN_PA00) { MP_ROM_QSTR(MP_QSTR_PA00), MP_ROM_PTR(&pin_PA00) }, -#endif -#if defined(PIN_PA01) && !defined(IGNORE_PIN_PA01) + #endif + #if defined(PIN_PA01) && !defined(IGNORE_PIN_PA01) { MP_ROM_QSTR(MP_QSTR_PA01), MP_ROM_PTR(&pin_PA01) }, -#endif -#if defined(PIN_PA02) && !defined(IGNORE_PIN_PA02) + #endif + #if defined(PIN_PA02) && !defined(IGNORE_PIN_PA02) { MP_ROM_QSTR(MP_QSTR_PA02), MP_ROM_PTR(&pin_PA02) }, -#endif -#if defined(PIN_PA03) && !defined(IGNORE_PIN_PA03) + #endif + #if defined(PIN_PA03) && !defined(IGNORE_PIN_PA03) { MP_ROM_QSTR(MP_QSTR_PA03), MP_ROM_PTR(&pin_PA03) }, -#endif -#if defined(PIN_PA04) && !defined(IGNORE_PIN_PA04) + #endif + #if defined(PIN_PA04) && !defined(IGNORE_PIN_PA04) { MP_ROM_QSTR(MP_QSTR_PA04), MP_ROM_PTR(&pin_PA04) }, -#endif -#if defined(PIN_PA05) && !defined(IGNORE_PIN_PA05) + #endif + #if defined(PIN_PA05) && !defined(IGNORE_PIN_PA05) { MP_ROM_QSTR(MP_QSTR_PA05), MP_ROM_PTR(&pin_PA05) }, -#endif -#if defined(PIN_PA06) && !defined(IGNORE_PIN_PA06) + #endif + #if defined(PIN_PA06) && !defined(IGNORE_PIN_PA06) { MP_ROM_QSTR(MP_QSTR_PA06), MP_ROM_PTR(&pin_PA06) }, -#endif -#if defined(PIN_PA07) && !defined(IGNORE_PIN_PA07) + #endif + #if defined(PIN_PA07) && !defined(IGNORE_PIN_PA07) { MP_ROM_QSTR(MP_QSTR_PA07), MP_ROM_PTR(&pin_PA07) }, -#endif -#if defined(PIN_PA08) && !defined(IGNORE_PIN_PA08) + #endif + #if defined(PIN_PA08) && !defined(IGNORE_PIN_PA08) { MP_ROM_QSTR(MP_QSTR_PA08), MP_ROM_PTR(&pin_PA08) }, -#endif -#if defined(PIN_PA09) && !defined(IGNORE_PIN_PA09) + #endif + #if defined(PIN_PA09) && !defined(IGNORE_PIN_PA09) { MP_ROM_QSTR(MP_QSTR_PA09), MP_ROM_PTR(&pin_PA09) }, -#endif -#if defined(PIN_PA10) && !defined(IGNORE_PIN_PA10) + #endif + #if defined(PIN_PA10) && !defined(IGNORE_PIN_PA10) { MP_ROM_QSTR(MP_QSTR_PA10), MP_ROM_PTR(&pin_PA10) }, -#endif -#if defined(PIN_PA11) && !defined(IGNORE_PIN_PA11) + #endif + #if defined(PIN_PA11) && !defined(IGNORE_PIN_PA11) { MP_ROM_QSTR(MP_QSTR_PA11), MP_ROM_PTR(&pin_PA11) }, -#endif -#if defined(PIN_PA12) && !defined(IGNORE_PIN_PA12) + #endif + #if defined(PIN_PA12) && !defined(IGNORE_PIN_PA12) { MP_ROM_QSTR(MP_QSTR_PA12), MP_ROM_PTR(&pin_PA12) }, -#endif -#if defined(PIN_PA13) && !defined(IGNORE_PIN_PA13) + #endif + #if defined(PIN_PA13) && !defined(IGNORE_PIN_PA13) { MP_ROM_QSTR(MP_QSTR_PA13), MP_ROM_PTR(&pin_PA13) }, -#endif -#if defined(PIN_PA14) && !defined(IGNORE_PIN_PA14) + #endif + #if defined(PIN_PA14) && !defined(IGNORE_PIN_PA14) { MP_ROM_QSTR(MP_QSTR_PA14), MP_ROM_PTR(&pin_PA14) }, -#endif -#if defined(PIN_PA15) && !defined(IGNORE_PIN_PA15) + #endif + #if defined(PIN_PA15) && !defined(IGNORE_PIN_PA15) { MP_ROM_QSTR(MP_QSTR_PA15), MP_ROM_PTR(&pin_PA15) }, -#endif -#if defined(PIN_PA16) && !defined(IGNORE_PIN_PA16) + #endif + #if defined(PIN_PA16) && !defined(IGNORE_PIN_PA16) { MP_ROM_QSTR(MP_QSTR_PA16), MP_ROM_PTR(&pin_PA16) }, -#endif -#if defined(PIN_PA17) && !defined(IGNORE_PIN_PA17) + #endif + #if defined(PIN_PA17) && !defined(IGNORE_PIN_PA17) { MP_ROM_QSTR(MP_QSTR_PA17), MP_ROM_PTR(&pin_PA17) }, -#endif -#if defined(PIN_PA18) && !defined(IGNORE_PIN_PA18) + #endif + #if defined(PIN_PA18) && !defined(IGNORE_PIN_PA18) { MP_ROM_QSTR(MP_QSTR_PA18), MP_ROM_PTR(&pin_PA18) }, -#endif -#if defined(PIN_PA19) && !defined(IGNORE_PIN_PA19) + #endif + #if defined(PIN_PA19) && !defined(IGNORE_PIN_PA19) { MP_ROM_QSTR(MP_QSTR_PA19), MP_ROM_PTR(&pin_PA19) }, -#endif -#if defined(PIN_PA20) && !defined(IGNORE_PIN_PA20) + #endif + #if defined(PIN_PA20) && !defined(IGNORE_PIN_PA20) { MP_ROM_QSTR(MP_QSTR_PA20), MP_ROM_PTR(&pin_PA20) }, -#endif -#if defined(PIN_PA21) && !defined(IGNORE_PIN_PA21) + #endif + #if defined(PIN_PA21) && !defined(IGNORE_PIN_PA21) { MP_ROM_QSTR(MP_QSTR_PA21), MP_ROM_PTR(&pin_PA21) }, -#endif -#if defined(PIN_PA22) && !defined(IGNORE_PIN_PA22) + #endif + #if defined(PIN_PA22) && !defined(IGNORE_PIN_PA22) { MP_ROM_QSTR(MP_QSTR_PA22), MP_ROM_PTR(&pin_PA22) }, -#endif -#if defined(PIN_PA23) && !defined(IGNORE_PIN_PA23) + #endif + #if defined(PIN_PA23) && !defined(IGNORE_PIN_PA23) { MP_ROM_QSTR(MP_QSTR_PA23), MP_ROM_PTR(&pin_PA23) }, -#endif -#if defined(PIN_PA24) && !defined(IGNORE_PIN_PA24) + #endif + #if defined(PIN_PA24) && !defined(IGNORE_PIN_PA24) { MP_ROM_QSTR(MP_QSTR_PA24), MP_ROM_PTR(&pin_PA24) }, -#endif -#if defined(PIN_PA25) && !defined(IGNORE_PIN_PA25) + #endif + #if defined(PIN_PA25) && !defined(IGNORE_PIN_PA25) { MP_ROM_QSTR(MP_QSTR_PA25), MP_ROM_PTR(&pin_PA25) }, -#endif -#if defined(PIN_PA27) && !defined(IGNORE_PIN_PA27) + #endif + #if defined(PIN_PA27) && !defined(IGNORE_PIN_PA27) { MP_ROM_QSTR(MP_QSTR_PA27), MP_ROM_PTR(&pin_PA27) }, -#endif -#if defined(PIN_PA28) && !defined(IGNORE_PIN_PA28) + #endif + #if defined(PIN_PA28) && !defined(IGNORE_PIN_PA28) { MP_ROM_QSTR(MP_QSTR_PA28), MP_ROM_PTR(&pin_PA28) }, -#endif -#if defined(PIN_PA30) && !defined(IGNORE_PIN_PA30) + #endif + #if defined(PIN_PA30) && !defined(IGNORE_PIN_PA30) { MP_ROM_QSTR(MP_QSTR_PA30), MP_ROM_PTR(&pin_PA30) }, -#endif -#if defined(PIN_PA31) && !defined(IGNORE_PIN_PA31) + #endif + #if defined(PIN_PA31) && !defined(IGNORE_PIN_PA31) { MP_ROM_QSTR(MP_QSTR_PA31), MP_ROM_PTR(&pin_PA31) }, -#endif + #endif -#if defined(PIN_PB00) && !defined(IGNORE_PIN_PB00) + #if defined(PIN_PB00) && !defined(IGNORE_PIN_PB00) { MP_ROM_QSTR(MP_QSTR_PB00), MP_ROM_PTR(&pin_PB00) }, -#endif -#if defined(PIN_PB01) && !defined(IGNORE_PIN_PB01) + #endif + #if defined(PIN_PB01) && !defined(IGNORE_PIN_PB01) { MP_ROM_QSTR(MP_QSTR_PB01), MP_ROM_PTR(&pin_PB01) }, -#endif -#if defined(PIN_PB02) && !defined(IGNORE_PIN_PB02) + #endif + #if defined(PIN_PB02) && !defined(IGNORE_PIN_PB02) { MP_ROM_QSTR(MP_QSTR_PB02), MP_ROM_PTR(&pin_PB02) }, -#endif -#if defined(PIN_PB03) && !defined(IGNORE_PIN_PB03) + #endif + #if defined(PIN_PB03) && !defined(IGNORE_PIN_PB03) { MP_ROM_QSTR(MP_QSTR_PB03), MP_ROM_PTR(&pin_PB03) }, -#endif -#if defined(PIN_PB04) && !defined(IGNORE_PIN_PB04) + #endif + #if defined(PIN_PB04) && !defined(IGNORE_PIN_PB04) { MP_ROM_QSTR(MP_QSTR_PB04), MP_ROM_PTR(&pin_PB04) }, -#endif -#if defined(PIN_PB05) && !defined(IGNORE_PIN_PB05) + #endif + #if defined(PIN_PB05) && !defined(IGNORE_PIN_PB05) { MP_ROM_QSTR(MP_QSTR_PB05), MP_ROM_PTR(&pin_PB05) }, -#endif -#if defined(PIN_PB06) && !defined(IGNORE_PIN_PB06) + #endif + #if defined(PIN_PB06) && !defined(IGNORE_PIN_PB06) { MP_ROM_QSTR(MP_QSTR_PB06), MP_ROM_PTR(&pin_PB06) }, -#endif -#if defined(PIN_PB07) && !defined(IGNORE_PIN_PB07) + #endif + #if defined(PIN_PB07) && !defined(IGNORE_PIN_PB07) { MP_ROM_QSTR(MP_QSTR_PB07), MP_ROM_PTR(&pin_PB07) }, -#endif -#if defined(PIN_PB08) && !defined(IGNORE_PIN_PB08) + #endif + #if defined(PIN_PB08) && !defined(IGNORE_PIN_PB08) { MP_ROM_QSTR(MP_QSTR_PB08), MP_ROM_PTR(&pin_PB08) }, -#endif -#if defined(PIN_PB09) && !defined(IGNORE_PIN_PB09) + #endif + #if defined(PIN_PB09) && !defined(IGNORE_PIN_PB09) { MP_ROM_QSTR(MP_QSTR_PB09), MP_ROM_PTR(&pin_PB09) }, -#endif -#if defined(PIN_PB10) && !defined(IGNORE_PIN_PB10) + #endif + #if defined(PIN_PB10) && !defined(IGNORE_PIN_PB10) { MP_ROM_QSTR(MP_QSTR_PB10), MP_ROM_PTR(&pin_PB10) }, -#endif -#if defined(PIN_PB11) && !defined(IGNORE_PIN_PB11) + #endif + #if defined(PIN_PB11) && !defined(IGNORE_PIN_PB11) { MP_ROM_QSTR(MP_QSTR_PB11), MP_ROM_PTR(&pin_PB11) }, -#endif -#if defined(PIN_PB12) && !defined(IGNORE_PIN_PB12) + #endif + #if defined(PIN_PB12) && !defined(IGNORE_PIN_PB12) { MP_ROM_QSTR(MP_QSTR_PB12), MP_ROM_PTR(&pin_PB12) }, -#endif -#if defined(PIN_PB13) && !defined(IGNORE_PIN_PB13) + #endif + #if defined(PIN_PB13) && !defined(IGNORE_PIN_PB13) { MP_ROM_QSTR(MP_QSTR_PB13), MP_ROM_PTR(&pin_PB13) }, -#endif -#if defined(PIN_PB14) && !defined(IGNORE_PIN_PB14) + #endif + #if defined(PIN_PB14) && !defined(IGNORE_PIN_PB14) { MP_ROM_QSTR(MP_QSTR_PB14), MP_ROM_PTR(&pin_PB14) }, -#endif -#if defined(PIN_PB15) && !defined(IGNORE_PIN_PB15) + #endif + #if defined(PIN_PB15) && !defined(IGNORE_PIN_PB15) { MP_ROM_QSTR(MP_QSTR_PB15), MP_ROM_PTR(&pin_PB15) }, -#endif -#if defined(PIN_PB16) && !defined(IGNORE_PIN_PB16) + #endif + #if defined(PIN_PB16) && !defined(IGNORE_PIN_PB16) { MP_ROM_QSTR(MP_QSTR_PB16), MP_ROM_PTR(&pin_PB16) }, -#endif -#if defined(PIN_PB17) && !defined(IGNORE_PIN_PB17) + #endif + #if defined(PIN_PB17) && !defined(IGNORE_PIN_PB17) { MP_ROM_QSTR(MP_QSTR_PB17), MP_ROM_PTR(&pin_PB17) }, -#endif -#if defined(PIN_PB18) && !defined(IGNORE_PIN_PB18) + #endif + #if defined(PIN_PB18) && !defined(IGNORE_PIN_PB18) { MP_ROM_QSTR(MP_QSTR_PB18), MP_ROM_PTR(&pin_PB18) }, -#endif -#if defined(PIN_PB19) && !defined(IGNORE_PIN_PB19) + #endif + #if defined(PIN_PB19) && !defined(IGNORE_PIN_PB19) { MP_ROM_QSTR(MP_QSTR_PB19), MP_ROM_PTR(&pin_PB19) }, -#endif -#if defined(PIN_PB20) && !defined(IGNORE_PIN_PB20) + #endif + #if defined(PIN_PB20) && !defined(IGNORE_PIN_PB20) { MP_ROM_QSTR(MP_QSTR_PB20), MP_ROM_PTR(&pin_PB20) }, -#endif -#if defined(PIN_PB21) && !defined(IGNORE_PIN_PB21) + #endif + #if defined(PIN_PB21) && !defined(IGNORE_PIN_PB21) { MP_ROM_QSTR(MP_QSTR_PB21), MP_ROM_PTR(&pin_PB21) }, -#endif -#if defined(PIN_PB22) && !defined(IGNORE_PIN_PB22) + #endif + #if defined(PIN_PB22) && !defined(IGNORE_PIN_PB22) { MP_ROM_QSTR(MP_QSTR_PB22), MP_ROM_PTR(&pin_PB22) }, -#endif -#if defined(PIN_PB23) && !defined(IGNORE_PIN_PB23) + #endif + #if defined(PIN_PB23) && !defined(IGNORE_PIN_PB23) { MP_ROM_QSTR(MP_QSTR_PB23), MP_ROM_PTR(&pin_PB23) }, -#endif -#if defined(PIN_PB30) && !defined(IGNORE_PIN_PB30) + #endif + #if defined(PIN_PB30) && !defined(IGNORE_PIN_PB30) { MP_ROM_QSTR(MP_QSTR_PB30), MP_ROM_PTR(&pin_PB30) }, -#endif -#if defined(PIN_PB31) && !defined(IGNORE_PIN_PB31) + #endif + #if defined(PIN_PB31) && !defined(IGNORE_PIN_PB31) { MP_ROM_QSTR(MP_QSTR_PB31), MP_ROM_PTR(&pin_PB31) }, -#endif + #endif -#if defined(PIN_PC00) && !defined(IGNORE_PIN_PC00) + #if defined(PIN_PC00) && !defined(IGNORE_PIN_PC00) { MP_ROM_QSTR(MP_QSTR_PC00), MP_ROM_PTR(&pin_PC00) }, -#endif -#if defined(PIN_PC01) && !defined(IGNORE_PIN_PC01) + #endif + #if defined(PIN_PC01) && !defined(IGNORE_PIN_PC01) { MP_ROM_QSTR(MP_QSTR_PC01), MP_ROM_PTR(&pin_PC01) }, -#endif -#if defined(PIN_PC02) && !defined(IGNORE_PIN_PC02) + #endif + #if defined(PIN_PC02) && !defined(IGNORE_PIN_PC02) { MP_ROM_QSTR(MP_QSTR_PC02), MP_ROM_PTR(&pin_PC02) }, -#endif -#if defined(PIN_PC03) && !defined(IGNORE_PIN_PC03) + #endif + #if defined(PIN_PC03) && !defined(IGNORE_PIN_PC03) { MP_ROM_QSTR(MP_QSTR_PC03), MP_ROM_PTR(&pin_PC03) }, -#endif -#if defined(PIN_PC04) && !defined(IGNORE_PIN_PC04) + #endif + #if defined(PIN_PC04) && !defined(IGNORE_PIN_PC04) { MP_ROM_QSTR(MP_QSTR_PC04), MP_ROM_PTR(&pin_PC04) }, -#endif -#if defined(PIN_PC05) && !defined(IGNORE_PIN_PC05) + #endif + #if defined(PIN_PC05) && !defined(IGNORE_PIN_PC05) { MP_ROM_QSTR(MP_QSTR_PC05), MP_ROM_PTR(&pin_PC05) }, -#endif -#if defined(PIN_PC06) && !defined(IGNORE_PIN_PC06) + #endif + #if defined(PIN_PC06) && !defined(IGNORE_PIN_PC06) { MP_ROM_QSTR(MP_QSTR_PC06), MP_ROM_PTR(&pin_PC06) }, -#endif -#if defined(PIN_PC07) && !defined(IGNORE_PIN_PC07) + #endif + #if defined(PIN_PC07) && !defined(IGNORE_PIN_PC07) { MP_ROM_QSTR(MP_QSTR_PC07), MP_ROM_PTR(&pin_PC07) }, -#endif -#if defined(PIN_PC10) && !defined(IGNORE_PIN_PC10) + #endif + #if defined(PIN_PC10) && !defined(IGNORE_PIN_PC10) { MP_ROM_QSTR(MP_QSTR_PC10), MP_ROM_PTR(&pin_PC10) }, -#endif -#if defined(PIN_PC11) && !defined(IGNORE_PIN_PC11) + #endif + #if defined(PIN_PC11) && !defined(IGNORE_PIN_PC11) { MP_ROM_QSTR(MP_QSTR_PC11), MP_ROM_PTR(&pin_PC11) }, -#endif -#if defined(PIN_PC12) && !defined(IGNORE_PIN_PC12) + #endif + #if defined(PIN_PC12) && !defined(IGNORE_PIN_PC12) { MP_ROM_QSTR(MP_QSTR_PC12), MP_ROM_PTR(&pin_PC12) }, -#endif -#if defined(PIN_PC13) && !defined(IGNORE_PIN_PC13) + #endif + #if defined(PIN_PC13) && !defined(IGNORE_PIN_PC13) { MP_ROM_QSTR(MP_QSTR_PC13), MP_ROM_PTR(&pin_PC13) }, -#endif -#if defined(PIN_PC14) && !defined(IGNORE_PIN_PC14) + #endif + #if defined(PIN_PC14) && !defined(IGNORE_PIN_PC14) { MP_ROM_QSTR(MP_QSTR_PC14), MP_ROM_PTR(&pin_PC14) }, -#endif -#if defined(PIN_PC15) && !defined(IGNORE_PIN_PC15) + #endif + #if defined(PIN_PC15) && !defined(IGNORE_PIN_PC15) { MP_ROM_QSTR(MP_QSTR_PC15), MP_ROM_PTR(&pin_PC15) }, -#endif -#if defined(PIN_PC16) && !defined(IGNORE_PIN_PC16) + #endif + #if defined(PIN_PC16) && !defined(IGNORE_PIN_PC16) { MP_ROM_QSTR(MP_QSTR_PC16), MP_ROM_PTR(&pin_PC16) }, -#endif -#if defined(PIN_PC17) && !defined(IGNORE_PIN_PC17) + #endif + #if defined(PIN_PC17) && !defined(IGNORE_PIN_PC17) { MP_ROM_QSTR(MP_QSTR_PC17), MP_ROM_PTR(&pin_PC17) }, -#endif -#if defined(PIN_PC18) && !defined(IGNORE_PIN_PC18) + #endif + #if defined(PIN_PC18) && !defined(IGNORE_PIN_PC18) { MP_ROM_QSTR(MP_QSTR_PC18), MP_ROM_PTR(&pin_PC18) }, -#endif -#if defined(PIN_PC19) && !defined(IGNORE_PIN_PC19) + #endif + #if defined(PIN_PC19) && !defined(IGNORE_PIN_PC19) { MP_ROM_QSTR(MP_QSTR_PC19), MP_ROM_PTR(&pin_PC19) }, -#endif -#if defined(PIN_PC20) && !defined(IGNORE_PIN_PC20) + #endif + #if defined(PIN_PC20) && !defined(IGNORE_PIN_PC20) { MP_ROM_QSTR(MP_QSTR_PC20), MP_ROM_PTR(&pin_PC20) }, -#endif -#if defined(PIN_PC21) && !defined(IGNORE_PIN_PC21) + #endif + #if defined(PIN_PC21) && !defined(IGNORE_PIN_PC21) { MP_ROM_QSTR(MP_QSTR_PC21), MP_ROM_PTR(&pin_PC21) }, -#endif -#if defined(PIN_PC22) && !defined(IGNORE_PIN_PC22) + #endif + #if defined(PIN_PC22) && !defined(IGNORE_PIN_PC22) { MP_ROM_QSTR(MP_QSTR_PC22), MP_ROM_PTR(&pin_PC22) }, -#endif -#if defined(PIN_PC23) && !defined(IGNORE_PIN_PC23) + #endif + #if defined(PIN_PC23) && !defined(IGNORE_PIN_PC23) { MP_ROM_QSTR(MP_QSTR_PC23), MP_ROM_PTR(&pin_PC23) }, -#endif -#if defined(PIN_PC24) && !defined(IGNORE_PIN_PC24) + #endif + #if defined(PIN_PC24) && !defined(IGNORE_PIN_PC24) { MP_ROM_QSTR(MP_QSTR_PC24), MP_ROM_PTR(&pin_PC24) }, -#endif -#if defined(PIN_PC25) && !defined(IGNORE_PIN_PC25) + #endif + #if defined(PIN_PC25) && !defined(IGNORE_PIN_PC25) { MP_ROM_QSTR(MP_QSTR_PC25), MP_ROM_PTR(&pin_PC25) }, -#endif -#if defined(PIN_PC26) && !defined(IGNORE_PIN_PC26) + #endif + #if defined(PIN_PC26) && !defined(IGNORE_PIN_PC26) { MP_ROM_QSTR(MP_QSTR_PC26), MP_ROM_PTR(&pin_PC26) }, -#endif -#if defined(PIN_PC27) && !defined(IGNORE_PIN_PC27) + #endif + #if defined(PIN_PC27) && !defined(IGNORE_PIN_PC27) { MP_ROM_QSTR(MP_QSTR_PC27), MP_ROM_PTR(&pin_PC27) }, -#endif -#if defined(PIN_PC28) && !defined(IGNORE_PIN_PC28) + #endif + #if defined(PIN_PC28) && !defined(IGNORE_PIN_PC28) { MP_ROM_QSTR(MP_QSTR_PC28), MP_ROM_PTR(&pin_PC28) }, -#endif -#if defined(PIN_PC30) && !defined(IGNORE_PIN_PC30) + #endif + #if defined(PIN_PC30) && !defined(IGNORE_PIN_PC30) { MP_ROM_QSTR(MP_QSTR_PC30), MP_ROM_PTR(&pin_PC30) }, -#endif -#if defined(PIN_PC31) && !defined(IGNORE_PIN_PC31) + #endif + #if defined(PIN_PC31) && !defined(IGNORE_PIN_PC31) { MP_ROM_QSTR(MP_QSTR_PC31), MP_ROM_PTR(&pin_PC31) }, -#endif + #endif -#if defined(PIN_PD00) && !defined(IGNORE_PIN_PD00) + #if defined(PIN_PD00) && !defined(IGNORE_PIN_PD00) { MP_ROM_QSTR(MP_QSTR_PD00), MP_ROM_PTR(&pin_PD00) }, -#endif -#if defined(PIN_PD01) && !defined(IGNORE_PIN_PD01) + #endif + #if defined(PIN_PD01) && !defined(IGNORE_PIN_PD01) { MP_ROM_QSTR(MP_QSTR_PD01), MP_ROM_PTR(&pin_PD01) }, -#endif -#if defined(PIN_PD08) && !defined(IGNORE_PIN_PD08) + #endif + #if defined(PIN_PD08) && !defined(IGNORE_PIN_PD08) { MP_ROM_QSTR(MP_QSTR_PD08), MP_ROM_PTR(&pin_PD08) }, -#endif -#if defined(PIN_PD09) && !defined(IGNORE_PIN_PD09) + #endif + #if defined(PIN_PD09) && !defined(IGNORE_PIN_PD09) { MP_ROM_QSTR(MP_QSTR_PD09), MP_ROM_PTR(&pin_PD09) }, -#endif -#if defined(PIN_PD10) && !defined(IGNORE_PIN_PD10) + #endif + #if defined(PIN_PD10) && !defined(IGNORE_PIN_PD10) { MP_ROM_QSTR(MP_QSTR_PD10), MP_ROM_PTR(&pin_PD10) }, -#endif -#if defined(PIN_PD11) && !defined(IGNORE_PIN_PD11) + #endif + #if defined(PIN_PD11) && !defined(IGNORE_PIN_PD11) { MP_ROM_QSTR(MP_QSTR_PD11), MP_ROM_PTR(&pin_PD11) }, -#endif -#if defined(PIN_PD12) && !defined(IGNORE_PIN_PD12) + #endif + #if defined(PIN_PD12) && !defined(IGNORE_PIN_PD12) { MP_ROM_QSTR(MP_QSTR_PD12), MP_ROM_PTR(&pin_PD12) }, -#endif -#if defined(PIN_PD20) && !defined(IGNORE_PIN_PD20) + #endif + #if defined(PIN_PD20) && !defined(IGNORE_PIN_PD20) { MP_ROM_QSTR(MP_QSTR_PD20), MP_ROM_PTR(&pin_PD20) }, -#endif -#if defined(PIN_PD21) && !defined(IGNORE_PIN_PD21) + #endif + #if defined(PIN_PD21) && !defined(IGNORE_PIN_PD21) { MP_ROM_QSTR(MP_QSTR_PD21), MP_ROM_PTR(&pin_PD21) }, -#endif + #endif }; MP_DEFINE_CONST_DICT(mcu_pin_globals, mcu_pin_global_dict_table); diff --git a/ports/atmel-samd/common-hal/pulseio/PulseIn.c b/ports/atmel-samd/common-hal/pulseio/PulseIn.c index 20c79642a3..49cef92478 100644 --- a/ports/atmel-samd/common-hal/pulseio/PulseIn.c +++ b/ports/atmel-samd/common-hal/pulseio/PulseIn.c @@ -54,16 +54,20 @@ volatile static uint32_t overflow_count = 0; volatile static uint32_t start_overflow = 0; void pulsein_timer_interrupt_handler(uint8_t index) { - if (index != pulsein_tc_index) return; + if (index != pulsein_tc_index) { + return; + } overflow_count++; - Tc* tc = tc_insts[index]; - if (!tc->COUNT16.INTFLAG.bit.OVF) return; + Tc *tc = tc_insts[index]; + if (!tc->COUNT16.INTFLAG.bit.OVF) { + return; + } // Clear the interrupt bit. tc->COUNT16.INTFLAG.reg = TC_INTFLAG_OVF; } -static void pulsein_set_config(pulseio_pulsein_obj_t* self, bool first_edge) { +static void pulsein_set_config(pulseio_pulsein_obj_t *self, bool first_edge) { uint32_t sense_setting; if (!first_edge) { sense_setting = EIC_CONFIG_SENSE0_BOTH_Val; @@ -83,16 +87,17 @@ void pulsein_interrupt_handler(uint8_t channel) { common_hal_mcu_disable_interrupts(); // Grab the current time first. uint32_t current_overflow = overflow_count; - Tc* tc = tc_insts[pulsein_tc_index]; + Tc *tc = tc_insts[pulsein_tc_index]; #ifdef SAM_D5X_E5X tc->COUNT16.CTRLBSET.reg = TC_CTRLBSET_CMD_READSYNC; while (tc->COUNT16.SYNCBUSY.bit.COUNT == 1 || - tc->COUNT16.CTRLBSET.bit.CMD == TC_CTRLBSET_CMD_READSYNC_Val) {} + tc->COUNT16.CTRLBSET.bit.CMD == TC_CTRLBSET_CMD_READSYNC_Val) { + } #endif uint32_t current_count = tc->COUNT16.COUNT.reg; - pulseio_pulsein_obj_t* self = get_eic_channel_data(channel); - if (self->len == 0 ) { + pulseio_pulsein_obj_t *self = get_eic_channel_data(channel); + if (self->len == 0) { start_overflow = overflow_count; } if (self->first_edge) { @@ -114,7 +119,7 @@ void pulsein_interrupt_handler(uint8_t channel) { if (total_diff < duration) { duration = total_diff; } - //check if the input is taking too long, 15 timer overflows is approx 1 second + // check if the input is taking too long, 15 timer overflows is approx 1 second if (current_overflow - start_overflow > 15) { self->errored_too_fast = true; common_hal_pulseio_pulsein_pause(self); @@ -136,16 +141,16 @@ void pulsein_interrupt_handler(uint8_t channel) { } void pulsein_reset() { -#ifdef SAMD21 + #ifdef SAMD21 rtc_end_pulse(); -#endif + #endif refcount = 0; pulsein_tc_index = 0xff; overflow_count = 0; } -void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, - const mcu_pin_obj_t* pin, uint16_t maxlen, bool idle_state) { +void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self, + const mcu_pin_obj_t *pin, uint16_t maxlen, bool idle_state) { if (!pin->has_extint) { mp_raise_RuntimeError(translate("No hardware support on pin")); } @@ -153,7 +158,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, mp_raise_RuntimeError(translate("EXTINT channel already in use")); } - self->buffer = (uint16_t *) m_malloc(maxlen * sizeof(uint16_t), false); + self->buffer = (uint16_t *)m_malloc(maxlen * sizeof(uint16_t), false); if (self->buffer == NULL) { mp_raise_msg_varg(&mp_type_MemoryError, translate("Failed to allocate RX buffer of %d bytes"), maxlen * sizeof(uint16_t)); } @@ -196,8 +201,8 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, #ifdef SAMD21 tc->COUNT16.CTRLA.reg = TC_CTRLA_MODE_COUNT16 | - TC_CTRLA_PRESCALER_DIV16 | - TC_CTRLA_WAVEGEN_NFRQ; + TC_CTRLA_PRESCALER_DIV16 | + TC_CTRLA_WAVEGEN_NFRQ; #endif #ifdef SAM_D5X_E5X tc_reset(tc); @@ -220,7 +225,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, self->last_overflow = overflow_count; self->last_count = 0; - set_eic_channel_data(pin->extint_channel, (void*) self); + set_eic_channel_data(pin->extint_channel, (void *)self); // Check to see if the EIC is enabled and start it up if its not.' if (eic_get_enable() == 0) { @@ -235,23 +240,23 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t* self, // Set config will enable the EIC. pulsein_set_config(self, true); -#ifdef SAMD21 + #ifdef SAMD21 rtc_start_pulse(); -#endif + #endif } -bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t* self) { +bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t *self) { return self->pin == NO_PIN; } -void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t* self) { +void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t *self) { if (common_hal_pulseio_pulsein_deinited(self)) { return; } -#ifdef SAMD21 + #ifdef SAMD21 rtc_end_pulse(); -#endif + #endif set_eic_handler(self->channel, EIC_HANDLER_NO_INTERRUPT); turn_off_eic_channel(self->channel); reset_pin_number(self->pin); @@ -264,13 +269,13 @@ void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t* self) { self->pin = NO_PIN; } -void common_hal_pulseio_pulsein_pause(pulseio_pulsein_obj_t* self) { +void common_hal_pulseio_pulsein_pause(pulseio_pulsein_obj_t *self) { uint32_t mask = 1 << self->channel; EIC->INTENCLR.reg = mask << EIC_INTENSET_EXTINT_Pos; } -void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self, - uint16_t trigger_duration) { +void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t *self, + uint16_t trigger_duration) { // Make sure we're paused. common_hal_pulseio_pulsein_pause(self); @@ -297,20 +302,20 @@ void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t* self, pulsein_set_config(self, true); } -void common_hal_pulseio_pulsein_clear(pulseio_pulsein_obj_t* self) { +void common_hal_pulseio_pulsein_clear(pulseio_pulsein_obj_t *self) { common_hal_mcu_disable_interrupts(); self->start = 0; self->len = 0; common_hal_mcu_enable_interrupts(); } -uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t* self) { +uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t *self) { if (self->len == 0) { mp_raise_IndexError_varg(translate("pop from empty %q"), MP_QSTR_PulseIn); } if (self->errored_too_fast) { - self->errored_too_fast = 0; - mp_raise_RuntimeError(translate("Input taking too long")); + self->errored_too_fast = 0; + mp_raise_RuntimeError(translate("Input taking too long")); } common_hal_mcu_disable_interrupts(); uint16_t value = self->buffer[self->start]; @@ -320,21 +325,21 @@ uint16_t common_hal_pulseio_pulsein_popleft(pulseio_pulsein_obj_t* self) { return value; } -uint16_t common_hal_pulseio_pulsein_get_maxlen(pulseio_pulsein_obj_t* self) { +uint16_t common_hal_pulseio_pulsein_get_maxlen(pulseio_pulsein_obj_t *self) { return self->maxlen; } -uint16_t common_hal_pulseio_pulsein_get_len(pulseio_pulsein_obj_t* self) { +uint16_t common_hal_pulseio_pulsein_get_len(pulseio_pulsein_obj_t *self) { return self->len; } -bool common_hal_pulseio_pulsein_get_paused(pulseio_pulsein_obj_t* self) { +bool common_hal_pulseio_pulsein_get_paused(pulseio_pulsein_obj_t *self) { uint32_t mask = 1 << self->channel; return (EIC->INTENSET.reg & (mask << EIC_INTENSET_EXTINT_Pos)) == 0; } -uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t* self, - int16_t index) { +uint16_t common_hal_pulseio_pulsein_get_item(pulseio_pulsein_obj_t *self, + int16_t index) { common_hal_mcu_disable_interrupts(); if (index < 0) { index += self->len; diff --git a/ports/nrf/common-hal/alarm/SleepMemory.c b/ports/nrf/common-hal/alarm/SleepMemory.c index e20f893567..4c7e5af847 100644 --- a/ports/nrf/common-hal/alarm/SleepMemory.c +++ b/ports/nrf/common-hal/alarm/SleepMemory.c @@ -44,8 +44,8 @@ __attribute__((section(".uninitialized"))) static uint32_t _sleepmem_magicnum; static int is_sleep_memory_valid(void) { if ((_sleepmem_magicnum & SLEEP_MEMORY_DATA_GUARD_MASK) - == SLEEP_MEMORY_DATA_GUARD) { - return 1; + == SLEEP_MEMORY_DATA_GUARD) { + return 1; } return 0; } @@ -54,36 +54,36 @@ void set_memory_retention(void) { // set RAM[n].POWER register for RAM retention // nRF52840 has RAM[0..7].Section[0..1] and RAM[8].Section[0..5] // nRF52833 has RAM[0..7].Section[0..1] and RAM[8].Section[0,1] - for(int block = 0; block <= 7; ++block) { + for (int block = 0; block <= 7; ++block) { nrf_power_rampower_mask_on(NRF_POWER, block, - NRF_POWER_RAMPOWER_S0RETENTION_MASK | - NRF_POWER_RAMPOWER_S1RETENTION_MASK); + NRF_POWER_RAMPOWER_S0RETENTION_MASK | + NRF_POWER_RAMPOWER_S1RETENTION_MASK); }; -#ifdef NRF52840 + #ifdef NRF52840 nrf_power_rampower_mask_on(NRF_POWER, 8, - NRF_POWER_RAMPOWER_S0RETENTION_MASK | - NRF_POWER_RAMPOWER_S1RETENTION_MASK | - NRF_POWER_RAMPOWER_S2RETENTION_MASK | - NRF_POWER_RAMPOWER_S3RETENTION_MASK | - NRF_POWER_RAMPOWER_S4RETENTION_MASK | - NRF_POWER_RAMPOWER_S5RETENTION_MASK); -#endif -#ifdef NRF52833 + NRF_POWER_RAMPOWER_S0RETENTION_MASK | + NRF_POWER_RAMPOWER_S1RETENTION_MASK | + NRF_POWER_RAMPOWER_S2RETENTION_MASK | + NRF_POWER_RAMPOWER_S3RETENTION_MASK | + NRF_POWER_RAMPOWER_S4RETENTION_MASK | + NRF_POWER_RAMPOWER_S5RETENTION_MASK); + #endif + #ifdef NRF52833 nrf_power_rampower_mask_on(NRF_POWER, 8, - NRF_POWER_RAMPOWER_S0RETENTION_MASK | - NRF_POWER_RAMPOWER_S1RETENTION_MASK); -#endif + NRF_POWER_RAMPOWER_S0RETENTION_MASK | + NRF_POWER_RAMPOWER_S1RETENTION_MASK); + #endif } static void initialize_sleep_memory(void) { memset((uint8_t *)_sleepmem, 0, SLEEP_MEMORY_LENGTH); sleepmem_wakeup_event = 0; - sleepmem_wakeup_pin = 0; + sleepmem_wakeup_pin = 0; set_memory_retention(); -#ifdef NRF_DEBUG_PRINT - //dbg_dump_RAMreg(); -#endif + #ifdef NRF_DEBUG_PRINT + // dbg_dump_RAMreg(); + #endif _sleepmem_magicnum = SLEEP_MEMORY_DATA_GUARD; } @@ -91,9 +91,9 @@ static void initialize_sleep_memory(void) { void alarm_sleep_memory_reset(void) { if (!is_sleep_memory_valid()) { initialize_sleep_memory(); -#ifdef NRF_DEBUG_PRINT - dbg_printf("sleep memory initialized\r\n"); -#endif + #ifdef NRF_DEBUG_PRINT + dbg_printf("sleep memory initialized\r\n"); + #endif } } @@ -101,18 +101,18 @@ uint32_t common_hal_alarm_sleep_memory_get_length(alarm_sleep_memory_obj_t *self return sizeof(_sleepmem); } -bool common_hal_alarm_sleep_memory_set_bytes(alarm_sleep_memory_obj_t *self, uint32_t start_index, const uint8_t* values, uint32_t len) { +bool common_hal_alarm_sleep_memory_set_bytes(alarm_sleep_memory_obj_t *self, uint32_t start_index, const uint8_t *values, uint32_t len) { if (start_index + len > sizeof(_sleepmem)) { return false; } - memcpy((uint8_t *) (_sleepmem + start_index), values, len); + memcpy((uint8_t *)(_sleepmem + start_index), values, len); return true; } -void common_hal_alarm_sleep_memory_get_bytes(alarm_sleep_memory_obj_t *self, uint32_t start_index, uint8_t* values, uint32_t len) { +void common_hal_alarm_sleep_memory_get_bytes(alarm_sleep_memory_obj_t *self, uint32_t start_index, uint8_t *values, uint32_t len) { if (start_index + len > sizeof(_sleepmem)) { return; } - memcpy(values, (uint8_t *) (_sleepmem + start_index), len); + memcpy(values, (uint8_t *)(_sleepmem + start_index), len); } diff --git a/py/makemoduledefs.py b/py/makemoduledefs.py index e20bff1eb0..aa2e5077ca 100644 --- a/py/makemoduledefs.py +++ b/py/makemoduledefs.py @@ -61,7 +61,7 @@ def generate_module_table_header(modules): # Print header file for all external modules. mod_defs = [] print("// Automatically generated by makemoduledefs.py.\n") - print("#include \"py/mpconfig.h\"") + print('#include "py/mpconfig.h"') for module_name, obj_module, enabled_define in modules: mod_def = "MODULE_DEF_{}".format(module_name.upper()) mod_defs.append(mod_def) diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py index 40942ed106..0f4717f0b6 100644 --- a/py/makeqstrdata.py +++ b/py/makeqstrdata.py @@ -631,6 +631,7 @@ def parse_input_headers(infiles): return qcfgs, qstrs, i18ns + def escape_bytes(qstr): if all(32 <= ord(c) <= 126 and c != "\\" and c != '"' for c in qstr): # qstr is all printable ASCII so render it as-is (for easier debugging) @@ -640,6 +641,7 @@ def escape_bytes(qstr): qbytes = bytes_cons(qstr, "utf8") return "".join(("\\x%02x" % b) for b in qbytes) + def make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr): qbytes = bytes_cons(qstr, "utf8") qlen = len(qbytes) @@ -715,7 +717,6 @@ def print_qstr_enums(qstrs): print("QENUM(MP_QSTR_%s)" % (ident,)) - if __name__ == "__main__": import argparse diff --git a/py/makeversionhdr.py b/py/makeversionhdr.py index 1ab15ecd95..41e5956542 100644 --- a/py/makeversionhdr.py +++ b/py/makeversionhdr.py @@ -65,7 +65,6 @@ def get_version_info_from_git(): return git_tag, git_hash, ver - def get_version_info_from_docs_conf(): with open(os.path.join(os.path.dirname(sys.argv[0]), "..", "conf.py")) as f: for line in f: diff --git a/py/objgenerator.c b/py/objgenerator.c index 518944e26b..33300b36b5 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -62,10 +62,10 @@ STATIC mp_obj_t native_gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_k mp_obj_fun_bc_t *self_fun = (mp_obj_fun_bc_t *)self->fun; // Determine start of prelude, and extract n_state from it -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-align" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wcast-align" uintptr_t prelude_offset = ((uintptr_t *)self_fun->bytecode)[0]; -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop size_t n_state = mp_decode_uint_value(self_fun->bytecode + prelude_offset); size_t n_exc_stack = 0; @@ -85,10 +85,10 @@ STATIC mp_obj_t native_gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_k o->code_state.exc_sp = NULL; // Prepare the generator instance for execution -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-align" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wcast-align" uintptr_t start_offset = ((uintptr_t *)self_fun->bytecode)[1]; -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop o->code_state.ip = MICROPY_MAKE_POINTER_CALLABLE((void *)(self_fun->bytecode + start_offset)); return MP_OBJ_FROM_PTR(o); diff --git a/py/persistentcode.c b/py/persistentcode.c index 13447e931f..175ad0a930 100644 --- a/py/persistentcode.c +++ b/py/persistentcode.c @@ -189,13 +189,13 @@ STATIC void extract_prelude(const byte **ip, const byte **ip2, bytecode_prelude_ #if MICROPY_EMIT_THUMB STATIC void asm_thumb_rewrite_mov(uint8_t *pc, uint16_t val) { -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wcast-align" + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wcast-align" // high part *(uint16_t *)pc = (*(uint16_t *)pc & 0xfbf0) | (val >> 1 & 0x0400) | (val >> 12); // low part *(uint16_t *)(pc + 2) = (*(uint16_t *)(pc + 2) & 0x0f00) | (val << 4 & 0x7000) | (val & 0x00ff); -#pragma GCC diagnostic pop + #pragma GCC diagnostic pop } #endif diff --git a/py/qstr.c b/py/qstr.c index a10adc578a..e56498984b 100644 --- a/py/qstr.c +++ b/py/qstr.c @@ -77,13 +77,13 @@ mp_uint_t qstr_compute_hash(const byte *data, size_t len) { } const qstr_attr_t mp_qstr_const_attr[] = { - #ifndef NO_QSTR + #ifndef NO_QSTR #define QDEF(id, hash, len, str) { hash, len }, #define TRANSLATION(id, length, compressed ...) - #include "genhdr/qstrdefs.generated.h" + #include "genhdr/qstrdefs.generated.h" #undef TRANSLATION #undef QDEF - #endif + #endif }; const qstr_pool_t mp_qstr_const_pool = { diff --git a/supervisor/serial.h b/supervisor/serial.h index 4b49abb9fb..391a874e48 100644 --- a/supervisor/serial.h +++ b/supervisor/serial.h @@ -49,6 +49,6 @@ bool serial_bytes_available(void); bool serial_connected(void); // XXX used in nrf52-sleep debug -int dbg_printf(const char *fmt, ...)__attribute__((format (printf, 1, 2))); +int dbg_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); #endif // MICROPY_INCLUDED_SUPERVISOR_SERIAL_H diff --git a/tools/build_board_info.py b/tools/build_board_info.py index 66ca48a02d..f44cf54821 100644 --- a/tools/build_board_info.py +++ b/tools/build_board_info.py @@ -65,26 +65,28 @@ extension_by_board = { "meowbit_v121": UF2, } -language_allow_list = set([ - "ID", - "de_DE", - "en_GB", - "en_US", - "en_x_pirate", - "es", - "fil", - "fr", - "it_IT", - "ja", - "nl", - "pl", - "pt_BR", - "sv", - "zh_Latn_pinyin", -]) +language_allow_list = set( + [ + "ID", + "de_DE", + "en_GB", + "en_US", + "en_x_pirate", + "es", + "fil", + "fr", + "it_IT", + "ja", + "nl", + "pl", + "pt_BR", + "sv", + "zh_Latn_pinyin", + ] +) -def get_languages(list_all = False): +def get_languages(list_all=False): languages = set() for f in os.scandir("../locale"): if f.name.endswith(".po"): diff --git a/tools/build_release_files.py b/tools/build_release_files.py index 68aa45f0a0..3fe714e393 100755 --- a/tools/build_release_files.py +++ b/tools/build_release_files.py @@ -90,8 +90,10 @@ for board in build_boards: for alias in board_info["aliases"] + [board]: bin_directory = "../bin/{alias}/{language}".format(alias=alias, language=language) os.makedirs(bin_directory, exist_ok=True) - final_filename = "adafruit-circuitpython-{alias}-{language}-{version}.{extension}".format( - alias=alias, language=language, version=version, extension=extension + final_filename = ( + "adafruit-circuitpython-{alias}-{language}-{version}.{extension}".format( + alias=alias, language=language, version=version, extension=extension + ) ) final_filename = os.path.join(bin_directory, final_filename) try: diff --git a/tools/codeformat.py b/tools/codeformat.py index 6a1528c163..58e2113459 100644 --- a/tools/codeformat.py +++ b/tools/codeformat.py @@ -80,15 +80,15 @@ def git_glob_to_regex(pat): m = m.group(0) if m == "*": return "[^/]*" - if m == "**": - return ".*" + if m == "**/": + return "(.*/)?" if m == "?": return "[^/]" if m == ".": return r"\." return m - result = [transform(part) for part in re.finditer(r"(\*\*|[*?.]|[^*?.]+)", pat)] + result = [transform(part) for part in re.finditer(r"(\*\*/|[*?.]|[^*?.]+)", pat)] return "(^" + "".join(result) + "$)" @@ -151,9 +151,7 @@ def fixup_c(filename): if directive in ("if ", "ifdef ", "ifndef "): l_next = lines[0] indent_next = len(re.match(r"( *)", l_next).group(1)) - if indent - 4 == indent_next and re.match( - r" +(} else |case )", l_next - ): + if indent - 4 == indent_next and re.match(r" +(} else |case )", l_next): # This #-line (and all associated ones) needs dedenting by 4 spaces. l = l[4:] dedent_stack.append(indent - 4) diff --git a/tools/gen_usb_descriptor.py b/tools/gen_usb_descriptor.py index 1fad2fbeb3..121bce6a0e 100644 --- a/tools/gen_usb_descriptor.py +++ b/tools/gen_usb_descriptor.py @@ -619,7 +619,6 @@ configuration = standard.ConfigurationDescriptor( # bit 7 is always 1 and 0-4 are always 0 # Turn off remote wakeup until we handle it in CircuitPython. bmAttributes=0x80, - ) descriptor_list.insert(0, configuration) diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index 5c3a6af32d..622a96014d 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -805,7 +805,6 @@ def read_raw_code(f, qstr_win): ) - def read_mpy(filename): with open(filename, "rb") as f: header = bytes_cons(f.read(4)) @@ -823,7 +822,6 @@ def read_mpy(filename): return read_raw_code(f, qstr_win) - def dump_mpy(raw_codes): for rc in raw_codes: rc.dump() @@ -896,10 +894,10 @@ def freeze_mpy(base_qstrs, raw_codes): qstr_size = {"metadata": 0, "data": 0} for _, _, qstr in new: qbytes = qstrutil.bytes_cons(qstr, "utf8") - print(" {%d, %d}," % ( - qstrutil.compute_hash(qbytes, config.MICROPY_QSTR_BYTES_IN_HASH), - len(qbytes) - )) + print( + " {%d, %d}," + % (qstrutil.compute_hash(qbytes, config.MICROPY_QSTR_BYTES_IN_HASH), len(qbytes)) + ) qstr_size["metadata"] += ( config.MICROPY_QSTR_BYTES_IN_LEN + config.MICROPY_QSTR_BYTES_IN_HASH ) @@ -919,7 +917,7 @@ def freeze_mpy(base_qstrs, raw_codes): print(" (qstr_attr_t *)mp_qstr_frozen_const_attr,") print(" {") for _, _, qstr in new: - print(" \"%s\"," % qstrutil.escape_bytes(qstr)) + print(' "%s",' % qstrutil.escape_bytes(qstr)) print(" },") print("};") From 1a52cbcf5dd90188f09231f41ab1c2dc4359f2b8 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 30 Apr 2021 16:42:25 -0500 Subject: [PATCH 101/103] Format a straggler file --- ports/nrf/common-hal/_bleio/PacketBuffer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/nrf/common-hal/_bleio/PacketBuffer.c b/ports/nrf/common-hal/_bleio/PacketBuffer.c index 260e20514b..c3e8e43b3f 100644 --- a/ports/nrf/common-hal/_bleio/PacketBuffer.c +++ b/ports/nrf/common-hal/_bleio/PacketBuffer.c @@ -401,8 +401,8 @@ mp_int_t common_hal_bleio_packet_buffer_get_outgoing_packet_length(bleio_packet_ bleio_connection_internal_t *connection = bleio_conn_handle_to_connection(self->conn_handle); if (connection) { return MIN(MIN(common_hal_bleio_connection_get_max_packet_length(connection), - self->max_packet_size), - self->characteristic->max_length); + self->max_packet_size), + self->characteristic->max_length); } } // There's no current connection, so we don't know the MTU, and @@ -418,7 +418,7 @@ mp_int_t common_hal_bleio_packet_buffer_get_outgoing_packet_length(bleio_packet_ bleio_connection_internal_t *connection = bleio_conn_handle_to_connection(self->conn_handle); if (connection) { return MIN(common_hal_bleio_connection_get_max_packet_length(connection), - self->max_packet_size); + self->max_packet_size); } } } From 670c49ed946e53bab7444fab85cffcf7122d5f7f Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 30 Apr 2021 22:58:51 -0400 Subject: [PATCH 102/103] MagTag: Remove board.SPI(); rename display-only pins --- .../boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h | 4 ---- .../esp32s2/boards/adafruit_magtag_2.9_grayscale/pins.c | 9 +++------ 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h b/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h index ecfa1d78b3..4d3e8c0972 100644 --- a/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h +++ b/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h @@ -39,7 +39,3 @@ #define DEFAULT_I2C_BUS_SCL (&pin_GPIO34) #define DEFAULT_I2C_BUS_SDA (&pin_GPIO33) - -#define DEFAULT_SPI_BUS_SCK (&pin_GPIO36) -#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO35) -#define DEFAULT_SPI_BUS_MISO (&pin_GPIO37) diff --git a/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/pins.c b/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/pins.c index ff44d9edb6..f0bc69be09 100644 --- a/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/pins.c +++ b/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/pins.c @@ -18,6 +18,9 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_EPD_RESET), MP_ROM_PTR(&pin_GPIO6) }, { MP_ROM_QSTR(MP_QSTR_EPD_DC), MP_ROM_PTR(&pin_GPIO7) }, { MP_ROM_QSTR(MP_QSTR_EPD_CS), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_EPD_MOSI), MP_ROM_PTR(&pin_GPIO35) }, + { MP_ROM_QSTR(MP_QSTR_EPD_SCK), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_EPD_MISO), MP_ROM_PTR(&pin_GPIO37) }, { MP_ROM_QSTR(MP_QSTR_BUTTON_A), MP_ROM_PTR(&pin_GPIO15) }, { MP_ROM_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_GPIO15) }, @@ -40,18 +43,12 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO33) }, { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO34) }, - { MP_ROM_QSTR(MP_QSTR_CS), MP_ROM_PTR(&pin_GPIO8) }, - { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO35) }, - { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO36) }, - { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO37) }, - { MP_ROM_QSTR(MP_QSTR_NEOPIXEL_POWER), MP_ROM_PTR(&pin_GPIO21) }, { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO1) }, { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO1) }, { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, - { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, { MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].epaper_display)}, From 9a5fb44c76f56d86dffc7f60a88df68eb8994159 Mon Sep 17 00:00:00 2001 From: Artyom Skrobov Date: Sat, 1 May 2021 13:25:35 -0400 Subject: [PATCH 103/103] `workflow_active` was never defined or used `supervisor_workflow_active` needs to be stubbed for when there's no USB --- supervisor/shared/workflow.h | 1 - supervisor/stub/serial.c | 4 ++++ supervisor/workflow.h | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/supervisor/shared/workflow.h b/supervisor/shared/workflow.h index 2596dd2c45..b3c817fb8b 100644 --- a/supervisor/shared/workflow.h +++ b/supervisor/shared/workflow.h @@ -27,4 +27,3 @@ #pragma once extern bool supervisor_workflow_connecting(void); -extern bool supervisor_workflow_active(void); diff --git a/supervisor/stub/serial.c b/supervisor/stub/serial.c index 6ca14fcfde..7d00ae1dc3 100644 --- a/supervisor/stub/serial.c +++ b/supervisor/stub/serial.c @@ -53,3 +53,7 @@ void serial_write(const char *text) { void supervisor_workflow_reset(void) { } + +bool supervisor_workflow_active(void) { + return false; +} diff --git a/supervisor/workflow.h b/supervisor/workflow.h index 27d063503a..31900392cd 100755 --- a/supervisor/workflow.h +++ b/supervisor/workflow.h @@ -29,4 +29,4 @@ void supervisor_workflow_reset(void); // True when the user could be actively iterating on their code. -bool workflow_active(void); +bool supervisor_workflow_active(void);