From d37326326dba329392964d283eb13507643bfbec Mon Sep 17 00:00:00 2001 From: sabas1080 Date: Tue, 28 Jul 2020 00:56:37 -0500 Subject: [PATCH 01/79] init bastwifi --- .../boards/electroniccats_bastwifi/board.c | 47 +++++++++++++++++++ .../electroniccats_bastwifi/mpconfigboard.h | 32 +++++++++++++ .../electroniccats_bastwifi/mpconfigboard.mk | 19 ++++++++ .../boards/electroniccats_bastwifi/pins.c | 46 ++++++++++++++++++ .../boards/electroniccats_bastwifi/sdkconfig | 0 5 files changed, 144 insertions(+) create mode 100644 ports/esp32s2/boards/electroniccats_bastwifi/board.c create mode 100644 ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h create mode 100644 ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.mk create mode 100644 ports/esp32s2/boards/electroniccats_bastwifi/pins.c create mode 100644 ports/esp32s2/boards/electroniccats_bastwifi/sdkconfig diff --git a/ports/esp32s2/boards/electroniccats_bastwifi/board.c b/ports/esp32s2/boards/electroniccats_bastwifi/board.c new file mode 100644 index 0000000000..9f708874bf --- /dev/null +++ b/ports/esp32s2/boards/electroniccats_bastwifi/board.c @@ -0,0 +1,47 @@ +/* + * 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 "boards/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 + common_hal_never_reset_pin(&pin_GPIO43); + common_hal_never_reset_pin(&pin_GPIO44); +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { + +} diff --git a/ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h b/ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h new file mode 100644 index 0000000000..ed3f23a3c4 --- /dev/null +++ b/ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h @@ -0,0 +1,32 @@ +/* + * 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 "BastWiFi" +#define MICROPY_HW_MCU_NAME "ESP32S2" + +#define AUTORESET_DELAY_MS 500 diff --git a/ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.mk b/ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.mk new file mode 100644 index 0000000000..4a2e8ecd8a --- /dev/null +++ b/ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.mk @@ -0,0 +1,19 @@ +USB_VID = 0x239A +USB_PID = 0x80A6 +USB_PRODUCT = "Bast WiFi" +USB_MANUFACTURER = "ElectronicCats" + +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_NEOPIXEL_WRITE = 0 + +CIRCUITPY_ESP_FLASH_MODE=dio +CIRCUITPY_ESP_FLASH_FREQ=40m +CIRCUITPY_ESP_FLASH_SIZE=4MB + +CIRCUITPY_MODULE=wrover diff --git a/ports/esp32s2/boards/electroniccats_bastwifi/pins.c b/ports/esp32s2/boards/electroniccats_bastwifi/pins.c new file mode 100644 index 0000000000..1d4e2c4eba --- /dev/null +++ b/ports/esp32s2/boards/electroniccats_bastwifi/pins.c @@ -0,0 +1,46 @@ +#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_IO15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) }, + { 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_IO19), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_IO20), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_IO26), MP_ROM_PTR(&pin_GPIO26) }, + { 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_IO39), MP_ROM_PTR(&pin_GPIO39) }, + { MP_ROM_QSTR(MP_QSTR_IO40), MP_ROM_PTR(&pin_GPIO40) }, + { MP_ROM_QSTR(MP_QSTR_IO41), MP_ROM_PTR(&pin_GPIO41) }, + { MP_ROM_QSTR(MP_QSTR_IO42), MP_ROM_PTR(&pin_GPIO42) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_IO43), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) }, + { MP_ROM_QSTR(MP_QSTR_IO44), MP_ROM_PTR(&pin_GPIO44) }, + { MP_ROM_QSTR(MP_QSTR_IO45), MP_ROM_PTR(&pin_GPIO45) }, + { MP_ROM_QSTR(MP_QSTR_IO46), MP_ROM_PTR(&pin_GPIO46) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/esp32s2/boards/electroniccats_bastwifi/sdkconfig b/ports/esp32s2/boards/electroniccats_bastwifi/sdkconfig new file mode 100644 index 0000000000..e69de29bb2 From fea1cad02cba369f3b9c0da8da5829a5066fc318 Mon Sep 17 00:00:00 2001 From: sabas1080 Date: Sat, 1 Aug 2020 17:51:45 -0500 Subject: [PATCH 02/79] add support for Bast Wifi Electronic Cats --- .github/workflows/build.yml | 1 + .../boards/electroniccats_bastwifi/pins.c | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 406f6c43ba..aa743f87b6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -384,6 +384,7 @@ jobs: - "espressif_saola_1_wroom" - "espressif_saola_1_wrover" - "unexpectedmaker_feathers2" + - "electroniccats_bastwifi" steps: - name: Set up Python 3.8 diff --git a/ports/esp32s2/boards/electroniccats_bastwifi/pins.c b/ports/esp32s2/boards/electroniccats_bastwifi/pins.c index 1d4e2c4eba..0b19346455 100644 --- a/ports/esp32s2/boards/electroniccats_bastwifi/pins.c +++ b/ports/esp32s2/boards/electroniccats_bastwifi/pins.c @@ -2,12 +2,19 @@ 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_A0), MP_ROM_PTR(&pin_GPIO0) }, { MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO1) }, { MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO2) }, { MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO3) }, { MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_GPIO4) }, { MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_GPIO5) }, { MP_ROM_QSTR(MP_QSTR_IO6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_A6), 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) }, @@ -18,6 +25,8 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_IO14), MP_ROM_PTR(&pin_GPIO14) }, { MP_ROM_QSTR(MP_QSTR_IO15), MP_ROM_PTR(&pin_GPIO15) }, { MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO16) }, { MP_ROM_QSTR(MP_QSTR_IO17), MP_ROM_PTR(&pin_GPIO17) }, @@ -31,6 +40,14 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { 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_MOSI), MP_ROM_PTR(&pin_GPIO37) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO35) }, + { MP_ROM_QSTR(MP_QSTR_CS), MP_ROM_PTR(&pin_GPIO11) }, + + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_IO38), MP_ROM_PTR(&pin_GPIO38) }, { MP_ROM_QSTR(MP_QSTR_IO39), MP_ROM_PTR(&pin_GPIO39) }, { MP_ROM_QSTR(MP_QSTR_IO40), MP_ROM_PTR(&pin_GPIO40) }, @@ -42,5 +59,9 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_IO44), MP_ROM_PTR(&pin_GPIO44) }, { MP_ROM_QSTR(MP_QSTR_IO45), MP_ROM_PTR(&pin_GPIO45) }, { MP_ROM_QSTR(MP_QSTR_IO46), MP_ROM_PTR(&pin_GPIO46) }, + + { 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 b074f8a1618e765307f01ac99bd7a37f0663cf68 Mon Sep 17 00:00:00 2001 From: sabas1080 Date: Sun, 2 Aug 2020 00:42:36 -0500 Subject: [PATCH 03/79] update for build test --- .github/workflows/build.yml | 2 +- ports/esp32s2/boards/electroniccats_bastwifi/pins.c | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index aa743f87b6..435dae2bb2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -381,10 +381,10 @@ jobs: fail-fast: false matrix: board: + - "electroniccats_bastwifi" - "espressif_saola_1_wroom" - "espressif_saola_1_wrover" - "unexpectedmaker_feathers2" - - "electroniccats_bastwifi" steps: - name: Set up Python 3.8 diff --git a/ports/esp32s2/boards/electroniccats_bastwifi/pins.c b/ports/esp32s2/boards/electroniccats_bastwifi/pins.c index 0b19346455..2f9987b0ed 100644 --- a/ports/esp32s2/boards/electroniccats_bastwifi/pins.c +++ b/ports/esp32s2/boards/electroniccats_bastwifi/pins.c @@ -40,14 +40,11 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { 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_MOSI), MP_ROM_PTR(&pin_GPIO37) }, { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO36) }, { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO35) }, { MP_ROM_QSTR(MP_QSTR_CS), MP_ROM_PTR(&pin_GPIO11) }, - { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO14) }, - { MP_ROM_QSTR(MP_QSTR_IO38), MP_ROM_PTR(&pin_GPIO38) }, { MP_ROM_QSTR(MP_QSTR_IO39), MP_ROM_PTR(&pin_GPIO39) }, { MP_ROM_QSTR(MP_QSTR_IO40), MP_ROM_PTR(&pin_GPIO40) }, From 0e30fe1cc56ae48b1e1ea4b4ef07ffdfdf928fc4 Mon Sep 17 00:00:00 2001 From: sabas1080 Date: Sun, 2 Aug 2020 19:54:11 -0500 Subject: [PATCH 04/79] Update VID & PID codes --- ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.mk b/ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.mk index 4a2e8ecd8a..6a6ae7937e 100644 --- a/ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.mk +++ b/ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.mk @@ -1,5 +1,5 @@ -USB_VID = 0x239A -USB_PID = 0x80A6 +USB_VID = 0x1209 +USB_PID = 0xBAB0 USB_PRODUCT = "Bast WiFi" USB_MANUFACTURER = "ElectronicCats" From 64c9baa6aa6203e21ff0420ce5a9889f44422334 Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 7 Aug 2020 15:46:00 -0500 Subject: [PATCH 05/79] Added bitmap.insert function for slice copy into a bitmap from another bitmap --- shared-bindings/displayio/Bitmap.c | 72 ++++++++++++++++++++++++++++++ shared-bindings/displayio/Bitmap.h | 4 ++ shared-module/displayio/Bitmap.c | 71 +++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+) diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index a52840f2e0..d62502b17f 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -172,6 +172,77 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val return mp_const_none; } +//| def insert(self, x: int, y: int, source_bitmap: bitmap, x1: int, y1: int, x2: int, y2:int) -> Any: +//| """Inserts the source_bitmap region defined by rectangular boundaries +//| (x1,y1) and (x2,y2) into the bitmap at the specified (x,y) location. +//| :param int x: Horizontal pixel location in bitmap where source_bitmap upper-left +//| corner will be placed +//| :param int y: Vertical pixel location in bitmap where source_bitmap upper-left +//| corner will be placed +//| :param bitmap source_bitmap: Source bitmap that contains the graphical region to be copied +//| : param x1: Minimum x-value for rectangular bounding box to be copied from the source bitmap +//| : param y1: Minimum y-value for rectangular bounding box to be copied from the source bitmap +//| : param x2: Maximum x-value for rectangular bounding box to be copied from the source bitmap +//| : param y2: Maximum y-value for rectangular bounding box to be copied from the source bitmap +//| +//| ... +//| + +//STATIC mp_obj_t displayio_bitmap_obj_insert(mp_obj_t self_in, mp_obj_t x_obj, mp_obj_t y_obj, mp_obj_t source_in, mp_obj_t x1_obj, mp_obj_t y1_obj, mp_obj_t x2_obj, mp_obj_t y2_obj){ +STATIC mp_obj_t displayio_bitmap_obj_insert(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args){ + + // // convert the inputs into the correct type + // displayio_bitmap_t *self = MP_OBJ_TO_PTR(self_in); + // int16_t x = mp_obj_get_int(x_obj); + // int16_t y = mp_obj_get_int(y_obj); + // displayio_bitmap_t *source = MP_OBJ_TO_PTR(source_in); + // int16_t x1 = mp_obj_get_int(x1_obj); + // int16_t y1 = mp_obj_get_int(y1_obj); + // int16_t x2 = mp_obj_get_int(x2_obj); + // int16_t y2 = mp_obj_get_int(y2_obj); + displayio_bitmap_t *self = MP_OBJ_TO_PTR(pos_args[0]); + int16_t x = mp_obj_get_int(pos_args[1]); + int16_t y = mp_obj_get_int(pos_args[2]); + displayio_bitmap_t *source = MP_OBJ_TO_PTR(pos_args[3]); + int16_t x1 = mp_obj_get_int(pos_args[4]); + int16_t y1 = mp_obj_get_int(pos_args[5]); + int16_t x2 = mp_obj_get_int(pos_args[6]); + int16_t y2 = mp_obj_get_int(pos_args[7]); + + + + + if ( (x<0) || (y<0) || (x > self-> width) || (y > self->height) ) { + mp_raise_ValueError(translate("(x,y): out of range of target bitmap")); + } + if ( (x1 < 0) || (x1 > source->width) || + (y1 < 0) || (y1 > source->height) || + (x2 < 0) || (x2 > source->width) || + (y2 < 0) || (y2 > source->height) ) { + mp_raise_ValueError(translate("(x1,y1) or (x2,y2): out of range of source bitmap")); + } + + // Ensure x1 < x2 and y1 < y2 + if (x1 > x2) { + int16_t temp=x2; + x2=x1; + x1=temp; + } + if (y1 > y2) { + int16_t temp=y2; + y2=y1; + y1=temp; + } + + common_hal_displayio_bitmap_insert(self, x, y, source, x1, y1, x2, y2); + + return mp_const_none; +} + +MP_DEFINE_CONST_FUN_OBJ_KW(displayio_bitmap_insert_obj, 8, displayio_bitmap_obj_insert); +/// What should this number value be? **** + + //| def fill(self, value: Any) -> Any: //| """Fills the bitmap with the supplied palette index value.""" //| ... @@ -192,6 +263,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(displayio_bitmap_fill_obj, displayio_bitmap_obj_fill); STATIC const mp_rom_map_elem_t displayio_bitmap_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_bitmap_height_obj) }, { MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&displayio_bitmap_width_obj) }, + { MP_ROM_QSTR(MP_QSTR_insert), MP_ROM_PTR(&displayio_bitmap_insert_obj) }, // Added insert function 8/7/2020 { MP_ROM_QSTR(MP_QSTR_fill), MP_ROM_PTR(&displayio_bitmap_fill_obj) }, }; diff --git a/shared-bindings/displayio/Bitmap.h b/shared-bindings/displayio/Bitmap.h index 46c3373292..d6183f7d00 100644 --- a/shared-bindings/displayio/Bitmap.h +++ b/shared-bindings/displayio/Bitmap.h @@ -40,6 +40,10 @@ uint16_t common_hal_displayio_bitmap_get_height(displayio_bitmap_t *self); uint16_t common_hal_displayio_bitmap_get_width(displayio_bitmap_t *self); uint32_t common_hal_displayio_bitmap_get_bits_per_value(displayio_bitmap_t *self); void common_hal_displayio_bitmap_set_pixel(displayio_bitmap_t *bitmap, int16_t x, int16_t y, uint32_t value); +void common_hal_displayio_bitmap_insert(displayio_bitmap_t *self, int16_t x, int16_t y, displayio_bitmap_t *source, + int16_t x1, int16_t y1, int16_t x2, int16_t y2); +// New selective bitmap copy function "insert": KMatocha 8/7/2020 + uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *bitmap, int16_t x, int16_t y); void common_hal_displayio_bitmap_fill(displayio_bitmap_t *bitmap, uint32_t value); diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c index 8bcda6086f..ab6e4f5dd5 100644 --- a/shared-module/displayio/Bitmap.c +++ b/shared-module/displayio/Bitmap.c @@ -105,6 +105,77 @@ uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *self, int16_t return 0; } +void common_hal_displayio_bitmap_insert(displayio_bitmap_t *self, int16_t x, int16_t y, displayio_bitmap_t *source, + int16_t x1, int16_t y1, int16_t x2, int16_t y2) { + // Copy complete "source" bitmap into "self" bitmap at location x,y in the "self" + // Add a boolean to determine if all values are copied, or only if non-zero + // Default is copy all values, but for text glyphs this should copy only non-zero values + + if (self->read_only) { + mp_raise_RuntimeError(translate("Read-only object")); + } + + //// check for zero width, this would be a single pixel + // if (x1_source == x2_source) || (y1_source == y2_source) { + // return 0 + // } + + // Dirty area update is unnecessary with simplest version. + // int16_t x_max=x+(x2_source-x1_source); + // int16_t y_max=y+(y2_source-y1_source); + // + // + // // Update the dirty area. + // if (x < self->dirty_area.x1) { + // self->dirty_area.x1 = x; + // } else if (x_max >= self->dirty_area.x2) { + // self->dirty_area.x2 = x_max); + // } + // if (y < self->dirty_area.y1) { + // self->dirty_area.y1 = y; + // } else if (y_max >= self->dirty_area.y2) { + // self->dirty_area.y2 = y_max; + // } + + // simplest version - use internal functions for get/set pixels + for (uint16_t i=0; i<= (x2-x1) ; i++) { + for (uint16_t j=0; j<= (y2-y1) ; j++){ + uint16_t value = common_hal_displayio_bitmap_get_pixel(source, x1+i, y1+j); + if ( (x+i >= 0) && (y+j >= 0) && (x+i <= self->width-1) && (y+j <= self->height-1) ){ + common_hal_displayio_bitmap_set_pixel(self, x+i, y+j, value); + } + } + } + + // Would be faster if copying a full word at a time. + /// Hard work here!!!! + // index into the original row + // figure out how to shift the bits into the right location + // check the boolean and don't update any zero's + + // // Update our data + // int32_t row_start = y * self->stride; + // uint32_t bytes_per_value = self->bits_per_value / 8; + // if (bytes_per_value < 1) { + // uint32_t bit_position = (sizeof(size_t) * 8 - ((x & self->x_mask) + 1) * self->bits_per_value); + // uint32_t index = row_start + (x >> self->x_shift); + // uint32_t word = self->data[index]; + // word &= ~(self->bitmask << bit_position); + // word |= (value & self->bitmask) << bit_position; + // self->data[index] = word; + // } else { + // size_t* row = self->data + row_start; + // if (bytes_per_value == 1) { + // ((uint8_t*) row)[x] = value; + // } else if (bytes_per_value == 2) { + // ((uint16_t*) row)[x] = value; + // } else if (bytes_per_value == 4) { + // ((uint32_t*) row)[x] = value; + // } + // } +} + + void common_hal_displayio_bitmap_set_pixel(displayio_bitmap_t *self, int16_t x, int16_t y, uint32_t value) { if (self->read_only) { mp_raise_RuntimeError(translate("Read-only object")); From b6008d0032a49e6b5c332576fa2f141d353b9fd3 Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Fri, 7 Aug 2020 15:59:42 -0500 Subject: [PATCH 06/79] Adding bitmap.insert to copy a slice of a source bitmap into another bitmap --- shared-module/displayio/Bitmap.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c index ab6e4f5dd5..75f352b30c 100644 --- a/shared-module/displayio/Bitmap.c +++ b/shared-module/displayio/Bitmap.c @@ -115,6 +115,10 @@ void common_hal_displayio_bitmap_insert(displayio_bitmap_t *self, int16_t x, int mp_raise_RuntimeError(translate("Read-only object")); } + // If this value is encountered in the source bitmap, it will not be copied (for text glyphs) + // This should be added as an optional parameter, and if it is `None`, then all pixels are copied + uint32_t skip_value=0; + //// check for zero width, this would be a single pixel // if (x1_source == x2_source) || (y1_source == y2_source) { // return 0 @@ -140,9 +144,11 @@ void common_hal_displayio_bitmap_insert(displayio_bitmap_t *self, int16_t x, int // simplest version - use internal functions for get/set pixels for (uint16_t i=0; i<= (x2-x1) ; i++) { for (uint16_t j=0; j<= (y2-y1) ; j++){ - uint16_t value = common_hal_displayio_bitmap_get_pixel(source, x1+i, y1+j); - if ( (x+i >= 0) && (y+j >= 0) && (x+i <= self->width-1) && (y+j <= self->height-1) ){ - common_hal_displayio_bitmap_set_pixel(self, x+i, y+j, value); + uint32_t value = common_hal_displayio_bitmap_get_pixel(source, x1+i, y1+j); + if (value != skip_value) { + if ( (x+i >= 0) && (y+j >= 0) && (x+i <= self->width-1) && (y+j <= self->height-1) ){ + common_hal_displayio_bitmap_set_pixel(self, x+i, y+j, value); + } } } } From 14f5d03b6dd947bd82d2daf88ca398d7d3b44930 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Thu, 13 Aug 2020 18:59:00 -0500 Subject: [PATCH 07/79] bringing up to date --- extmod/ulab | 2 +- frozen/Adafruit_CircuitPython_BLE | 2 +- ...ircuitPython_BLE_Apple_Notification_Center | 2 +- frozen/Adafruit_CircuitPython_BusDevice | 2 +- .../Adafruit_CircuitPython_CircuitPlayground | 2 +- frozen/Adafruit_CircuitPython_Crickit | 2 +- frozen/Adafruit_CircuitPython_DRV2605 | 2 +- frozen/Adafruit_CircuitPython_DS3231 | 2 +- frozen/Adafruit_CircuitPython_ESP32SPI | 2 +- frozen/Adafruit_CircuitPython_FocalTouch | 2 +- frozen/Adafruit_CircuitPython_HID | 2 +- frozen/Adafruit_CircuitPython_IRRemote | 2 +- frozen/Adafruit_CircuitPython_LIS3DH | 2 +- frozen/Adafruit_CircuitPython_LSM6DS | 2 +- frozen/Adafruit_CircuitPython_Motor | 2 +- frozen/Adafruit_CircuitPython_Register | 2 +- frozen/Adafruit_CircuitPython_Requests | 2 +- frozen/Adafruit_CircuitPython_Thermistor | 2 +- frozen/Adafruit_CircuitPython_seesaw | 2 +- frozen/circuitpython-stage | 2 +- lib/mp3 | 2 +- lib/protomatter | 2 +- lib/tinyusb | 2 +- ports/atmel-samd/asf4 | 2 +- ports/atmel-samd/peripherals | 2 +- ports/cxd56/spresense-exported-sdk | 2 +- ports/esp32s2/esp-idf | 2 +- ports/stm/st_driver | 2 +- shared-bindings/_typing/__init__ 2.pyi | 54 ++ shared-bindings/gnss/GNSS 2.c | 205 ++++++++ shared-bindings/gnss/GNSS 2.h | 27 + shared-bindings/gnss/PositionFix 2.c | 80 +++ shared-bindings/gnss/PositionFix 2.h | 28 ++ shared-bindings/gnss/SatelliteSystem 2.c | 113 +++++ shared-bindings/gnss/SatelliteSystem 2.h | 33 ++ shared-bindings/gnss/__init__ 2.c | 31 ++ .../i2cperipheral/I2CPeripheral 2.c | 436 ++++++++++++++++ .../i2cperipheral/I2CPeripheral 2.h | 60 +++ shared-bindings/i2cperipheral/__init__ 2.c | 106 ++++ .../memorymonitor/AllocationAlarm 2.c | 137 +++++ .../memorymonitor/AllocationAlarm 2.h | 39 ++ .../memorymonitor/AllocationSize 2.c | 183 +++++++ .../memorymonitor/AllocationSize 2.h | 42 ++ shared-bindings/memorymonitor/__init__ 2.c | 76 +++ shared-bindings/memorymonitor/__init__ 2.h | 49 ++ shared-bindings/sdcardio/SDCard 2.c | 183 +++++++ shared-bindings/sdcardio/SDCard 2.h | 30 ++ shared-bindings/sdcardio/__init__ 2.c | 47 ++ shared-bindings/sdcardio/__init__ 2.h | 0 shared-bindings/sdioio/SDCard 2.c | 296 +++++++++++ shared-bindings/sdioio/SDCard 2.h | 66 +++ shared-bindings/sdioio/__init__ 2.c | 47 ++ shared-bindings/sdioio/__init__ 2.h | 0 .../memorymonitor/AllocationAlarm 2.c | 94 ++++ .../memorymonitor/AllocationAlarm 2.h | 51 ++ .../memorymonitor/AllocationSize 2.c | 91 ++++ .../memorymonitor/AllocationSize 2.h | 51 ++ shared-module/memorymonitor/__init__ 2.c | 39 ++ shared-module/memorymonitor/__init__ 2.h | 35 ++ shared-module/sdcardio/SDCard 2.c | 466 ++++++++++++++++++ shared-module/sdcardio/SDCard 2.h | 51 ++ shared-module/sdcardio/__init__ 2.c | 0 shared-module/sdcardio/__init__ 2.h | 0 supervisor/background_callback 2.h | 87 ++++ supervisor/shared/background_callback 2.c | 138 ++++++ 65 files changed, 3499 insertions(+), 28 deletions(-) create mode 100644 shared-bindings/_typing/__init__ 2.pyi create mode 100644 shared-bindings/gnss/GNSS 2.c create mode 100644 shared-bindings/gnss/GNSS 2.h create mode 100644 shared-bindings/gnss/PositionFix 2.c create mode 100644 shared-bindings/gnss/PositionFix 2.h create mode 100644 shared-bindings/gnss/SatelliteSystem 2.c create mode 100644 shared-bindings/gnss/SatelliteSystem 2.h create mode 100644 shared-bindings/gnss/__init__ 2.c create mode 100644 shared-bindings/i2cperipheral/I2CPeripheral 2.c create mode 100644 shared-bindings/i2cperipheral/I2CPeripheral 2.h create mode 100644 shared-bindings/i2cperipheral/__init__ 2.c create mode 100644 shared-bindings/memorymonitor/AllocationAlarm 2.c create mode 100644 shared-bindings/memorymonitor/AllocationAlarm 2.h create mode 100644 shared-bindings/memorymonitor/AllocationSize 2.c create mode 100644 shared-bindings/memorymonitor/AllocationSize 2.h create mode 100644 shared-bindings/memorymonitor/__init__ 2.c create mode 100644 shared-bindings/memorymonitor/__init__ 2.h create mode 100644 shared-bindings/sdcardio/SDCard 2.c create mode 100644 shared-bindings/sdcardio/SDCard 2.h create mode 100644 shared-bindings/sdcardio/__init__ 2.c create mode 100644 shared-bindings/sdcardio/__init__ 2.h create mode 100644 shared-bindings/sdioio/SDCard 2.c create mode 100644 shared-bindings/sdioio/SDCard 2.h create mode 100644 shared-bindings/sdioio/__init__ 2.c create mode 100644 shared-bindings/sdioio/__init__ 2.h create mode 100644 shared-module/memorymonitor/AllocationAlarm 2.c create mode 100644 shared-module/memorymonitor/AllocationAlarm 2.h create mode 100644 shared-module/memorymonitor/AllocationSize 2.c create mode 100644 shared-module/memorymonitor/AllocationSize 2.h create mode 100644 shared-module/memorymonitor/__init__ 2.c create mode 100644 shared-module/memorymonitor/__init__ 2.h create mode 100644 shared-module/sdcardio/SDCard 2.c create mode 100644 shared-module/sdcardio/SDCard 2.h create mode 100644 shared-module/sdcardio/__init__ 2.c create mode 100644 shared-module/sdcardio/__init__ 2.h create mode 100644 supervisor/background_callback 2.h create mode 100644 supervisor/shared/background_callback 2.c diff --git a/extmod/ulab b/extmod/ulab index 11a7ecff6d..cf61d728e7 160000 --- a/extmod/ulab +++ b/extmod/ulab @@ -1 +1 @@ -Subproject commit 11a7ecff6d76a02644ff23a734b792afaa615e44 +Subproject commit cf61d728e70b9ec57e5711b40540793a89296f5d diff --git a/frozen/Adafruit_CircuitPython_BLE b/frozen/Adafruit_CircuitPython_BLE index 41f7a3530d..5d584576ef 160000 --- a/frozen/Adafruit_CircuitPython_BLE +++ b/frozen/Adafruit_CircuitPython_BLE @@ -1 +1 @@ -Subproject commit 41f7a3530d4cacdbf668399d3a015ea29c7e169b +Subproject commit 5d584576ef79ca36506e6c7470e7ac5204cf0a8d diff --git a/frozen/Adafruit_CircuitPython_BLE_Apple_Notification_Center b/frozen/Adafruit_CircuitPython_BLE_Apple_Notification_Center index 6a034887e3..3ffb3f02d2 160000 --- a/frozen/Adafruit_CircuitPython_BLE_Apple_Notification_Center +++ b/frozen/Adafruit_CircuitPython_BLE_Apple_Notification_Center @@ -1 +1 @@ -Subproject commit 6a034887e370caa61fee5f51db8dd393d3e72542 +Subproject commit 3ffb3f02d2046910e09d1f5a74721bd1a4cdf8cf diff --git a/frozen/Adafruit_CircuitPython_BusDevice b/frozen/Adafruit_CircuitPython_BusDevice index eb4b21e216..e9411c4244 160000 --- a/frozen/Adafruit_CircuitPython_BusDevice +++ b/frozen/Adafruit_CircuitPython_BusDevice @@ -1 +1 @@ -Subproject commit eb4b21e216efd8ec0c4862a938e81b56be961724 +Subproject commit e9411c4244984b69ec6928370ede40cec014c10b diff --git a/frozen/Adafruit_CircuitPython_CircuitPlayground b/frozen/Adafruit_CircuitPython_CircuitPlayground index 3c540329b6..e9f15d6150 160000 --- a/frozen/Adafruit_CircuitPython_CircuitPlayground +++ b/frozen/Adafruit_CircuitPython_CircuitPlayground @@ -1 +1 @@ -Subproject commit 3c540329b63163e45f108df4bfebc387d5352c4f +Subproject commit e9f15d61502f34173912ba271aaaf9446dae8da1 diff --git a/frozen/Adafruit_CircuitPython_Crickit b/frozen/Adafruit_CircuitPython_Crickit index 809646ba11..0e1230676a 160000 --- a/frozen/Adafruit_CircuitPython_Crickit +++ b/frozen/Adafruit_CircuitPython_Crickit @@ -1 +1 @@ -Subproject commit 809646ba11366b5aedbc8a90be1da1829304bf62 +Subproject commit 0e1230676a54da17a309d1dfffdd7fa90240191c diff --git a/frozen/Adafruit_CircuitPython_DRV2605 b/frozen/Adafruit_CircuitPython_DRV2605 index 209edd164e..7914a63903 160000 --- a/frozen/Adafruit_CircuitPython_DRV2605 +++ b/frozen/Adafruit_CircuitPython_DRV2605 @@ -1 +1 @@ -Subproject commit 209edd164eb640a8ced561a54505792fc99a67b9 +Subproject commit 7914a6390318687bb8e2e9c4119aa932fea01531 diff --git a/frozen/Adafruit_CircuitPython_DS3231 b/frozen/Adafruit_CircuitPython_DS3231 index 5d81a9ea82..0d49a1fcd9 160000 --- a/frozen/Adafruit_CircuitPython_DS3231 +++ b/frozen/Adafruit_CircuitPython_DS3231 @@ -1 +1 @@ -Subproject commit 5d81a9ea822a85e46be4a512ac44abf21e77d816 +Subproject commit 0d49a1fcd96c13a94e8bdf26f92abe79b8517906 diff --git a/frozen/Adafruit_CircuitPython_ESP32SPI b/frozen/Adafruit_CircuitPython_ESP32SPI index 01f3f6674b..94b03517c1 160000 --- a/frozen/Adafruit_CircuitPython_ESP32SPI +++ b/frozen/Adafruit_CircuitPython_ESP32SPI @@ -1 +1 @@ -Subproject commit 01f3f6674b4493ba29b857e0f43deb69975736ec +Subproject commit 94b03517c1f4ff68cc2bb09b0963f7e7e3ce3d04 diff --git a/frozen/Adafruit_CircuitPython_FocalTouch b/frozen/Adafruit_CircuitPython_FocalTouch index 1e3312ab1c..72968d3546 160000 --- a/frozen/Adafruit_CircuitPython_FocalTouch +++ b/frozen/Adafruit_CircuitPython_FocalTouch @@ -1 +1 @@ -Subproject commit 1e3312ab1cba0b1d3bb1f559c52acfdc1a6d57b8 +Subproject commit 72968d3546f9d6c5af138d4c179343007cb9662c diff --git a/frozen/Adafruit_CircuitPython_HID b/frozen/Adafruit_CircuitPython_HID index 829ba0f0a2..65fb213b8c 160000 --- a/frozen/Adafruit_CircuitPython_HID +++ b/frozen/Adafruit_CircuitPython_HID @@ -1 +1 @@ -Subproject commit 829ba0f0a2d8a63f7d0215c6c9fc821e14e52a93 +Subproject commit 65fb213b8c554181d54b77f75335e16e2f4c0987 diff --git a/frozen/Adafruit_CircuitPython_IRRemote b/frozen/Adafruit_CircuitPython_IRRemote index fc3a7b4798..d435fc9a9d 160000 --- a/frozen/Adafruit_CircuitPython_IRRemote +++ b/frozen/Adafruit_CircuitPython_IRRemote @@ -1 +1 @@ -Subproject commit fc3a7b479874a1ea315ddb3bf6c5e281e16ef097 +Subproject commit d435fc9a9d90cb063608ae037bf5284b33bc5e84 diff --git a/frozen/Adafruit_CircuitPython_LIS3DH b/frozen/Adafruit_CircuitPython_LIS3DH index 9fe8f314c0..457aba6dd5 160000 --- a/frozen/Adafruit_CircuitPython_LIS3DH +++ b/frozen/Adafruit_CircuitPython_LIS3DH @@ -1 +1 @@ -Subproject commit 9fe8f314c032cee89b9ad7697d61e9cba76431ff +Subproject commit 457aba6dd59ad00502b80c9031655d3d26ecc82b diff --git a/frozen/Adafruit_CircuitPython_LSM6DS b/frozen/Adafruit_CircuitPython_LSM6DS index f1cc47f024..ee8f2187d4 160000 --- a/frozen/Adafruit_CircuitPython_LSM6DS +++ b/frozen/Adafruit_CircuitPython_LSM6DS @@ -1 +1 @@ -Subproject commit f1cc47f024b27e670b9bf2a51c89e32f93c1b957 +Subproject commit ee8f2187d4795b08ae4aa60558f564d26c997be9 diff --git a/frozen/Adafruit_CircuitPython_Motor b/frozen/Adafruit_CircuitPython_Motor index 434e5b5346..5fd72fb963 160000 --- a/frozen/Adafruit_CircuitPython_Motor +++ b/frozen/Adafruit_CircuitPython_Motor @@ -1 +1 @@ -Subproject commit 434e5b5346cb0a1a9eb15989b00278be87cb2ff1 +Subproject commit 5fd72fb963c4a0318d29282ca2cc988f19787fda diff --git a/frozen/Adafruit_CircuitPython_Register b/frozen/Adafruit_CircuitPython_Register index 6143ec2a96..56358b4494 160000 --- a/frozen/Adafruit_CircuitPython_Register +++ b/frozen/Adafruit_CircuitPython_Register @@ -1 +1 @@ -Subproject commit 6143ec2a96a6d218041e9cab5968de26702d7bbf +Subproject commit 56358b4494da825cd99a56a854119f926abca670 diff --git a/frozen/Adafruit_CircuitPython_Requests b/frozen/Adafruit_CircuitPython_Requests index 43017e30a1..41de8b3c05 160000 --- a/frozen/Adafruit_CircuitPython_Requests +++ b/frozen/Adafruit_CircuitPython_Requests @@ -1 +1 @@ -Subproject commit 43017e30a1e772b67ac68293a944e863c031e389 +Subproject commit 41de8b3c05dd78d7be8893a0f6cb47a7e9b421a2 diff --git a/frozen/Adafruit_CircuitPython_Thermistor b/frozen/Adafruit_CircuitPython_Thermistor index fb773e0ed1..b5bbdbd56c 160000 --- a/frozen/Adafruit_CircuitPython_Thermistor +++ b/frozen/Adafruit_CircuitPython_Thermistor @@ -1 +1 @@ -Subproject commit fb773e0ed1891cda2ace6271fafc5312e167d275 +Subproject commit b5bbdbd56ca205c581ba2c84d927ef99befce88e diff --git a/frozen/Adafruit_CircuitPython_seesaw b/frozen/Adafruit_CircuitPython_seesaw index 88738da275..76c0dd1329 160000 --- a/frozen/Adafruit_CircuitPython_seesaw +++ b/frozen/Adafruit_CircuitPython_seesaw @@ -1 +1 @@ -Subproject commit 88738da275a83acabb14b7140d1c79b33cdc7b02 +Subproject commit 76c0dd13294ce8ae0518cb9882dcad5d3668977e diff --git a/frozen/circuitpython-stage b/frozen/circuitpython-stage index 9596a5904e..0d2c083a2f 160000 --- a/frozen/circuitpython-stage +++ b/frozen/circuitpython-stage @@ -1 +1 @@ -Subproject commit 9596a5904ed757e6fbffcf03e7aa77ae9ecf5223 +Subproject commit 0d2c083a2fb57a1562d4806775f45273abbfbfae diff --git a/lib/mp3 b/lib/mp3 index bc58a65496..c3c664bf4d 160000 --- a/lib/mp3 +++ b/lib/mp3 @@ -1 +1 @@ -Subproject commit bc58a654964c799e972719a63ff12694998f3549 +Subproject commit c3c664bf4db6a36d11808dfcbb5dbf7cff1715b8 diff --git a/lib/protomatter b/lib/protomatter index 761d6437e8..9f71088d2c 160000 --- a/lib/protomatter +++ b/lib/protomatter @@ -1 +1 @@ -Subproject commit 761d6437e8cd6a131d51de96974337121a9c7164 +Subproject commit 9f71088d2c32206c6f0495704ae0c040426d5764 diff --git a/lib/tinyusb b/lib/tinyusb index 22100b252f..dc5445e2f4 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit 22100b252fc2eb8f51ed407949645653c4880fd9 +Subproject commit dc5445e2f45cb348a44fe24fc1be4bc8b5ba5bab diff --git a/ports/atmel-samd/asf4 b/ports/atmel-samd/asf4 index 35a1525796..039b5f3bbc 160000 --- a/ports/atmel-samd/asf4 +++ b/ports/atmel-samd/asf4 @@ -1 +1 @@ -Subproject commit 35a1525796c7ef8a3893d90befdad2f267fca20e +Subproject commit 039b5f3bbc3f4ba4421e581db290560d59fef625 diff --git a/ports/atmel-samd/peripherals b/ports/atmel-samd/peripherals index 0f5f1522d0..6b531fc923 160000 --- a/ports/atmel-samd/peripherals +++ b/ports/atmel-samd/peripherals @@ -1 +1 @@ -Subproject commit 0f5f1522d09c8fa7d858edec484a994c21c59668 +Subproject commit 6b531fc923d9f02b14bd731a5f584ddf716e8773 diff --git a/ports/cxd56/spresense-exported-sdk b/ports/cxd56/spresense-exported-sdk index c991d439fa..7f6568c7f4 160000 --- a/ports/cxd56/spresense-exported-sdk +++ b/ports/cxd56/spresense-exported-sdk @@ -1 +1 @@ -Subproject commit c991d439fac9c23cfcac0da16fe8055f818d40a4 +Subproject commit 7f6568c7f4898cdb24a2f06040784a836050686e diff --git a/ports/esp32s2/esp-idf b/ports/esp32s2/esp-idf index 160ba4924d..0daf6e0e41 160000 --- a/ports/esp32s2/esp-idf +++ b/ports/esp32s2/esp-idf @@ -1 +1 @@ -Subproject commit 160ba4924d8b588e718f76e3a0d0e92c11052fa3 +Subproject commit 0daf6e0e41f95d22d193d08941a00df9525bc405 diff --git a/ports/stm/st_driver b/ports/stm/st_driver index 1900834751..3fc2e0f3db 160000 --- a/ports/stm/st_driver +++ b/ports/stm/st_driver @@ -1 +1 @@ -Subproject commit 1900834751fd6754457874b8c971690bab33e0a7 +Subproject commit 3fc2e0f3db155b33177bb0705e0dd65cadb58412 diff --git a/shared-bindings/_typing/__init__ 2.pyi b/shared-bindings/_typing/__init__ 2.pyi new file mode 100644 index 0000000000..48e68a8d57 --- /dev/null +++ b/shared-bindings/_typing/__init__ 2.pyi @@ -0,0 +1,54 @@ +"""Types for the C-level protocols""" + +from typing import Union + +import array +import audiocore +import audiomixer +import audiomp3 +import rgbmatrix +import ulab + +ReadableBuffer = Union[ + bytes, bytearray, memoryview, array.array, ulab.array, rgbmatrix.RGBMatrix +] +"""Classes that implement the readable buffer protocol + + - `bytes` + - `bytearray` + - `memoryview` + - `array.array` + - `ulab.array` + - `rgbmatrix.RGBMatrix` +""" + +WriteableBuffer = Union[ + bytearray, memoryview, array.array, ulab.array, rgbmatrix.RGBMatrix +] +"""Classes that implement the writeable buffer protocol + + - `bytearray` + - `memoryview` + - `array.array` + - `ulab.array` + - `rgbmatrix.RGBMatrix` +""" + +AudioSample = Union[ + audiocore.WaveFile, audiocore.RawSample, audiomixer.Mixer, audiomp3.MP3Decoder +] +"""Classes that implement the audiosample protocol + + - `audiocore.WaveFile` + - `audiocore.RawSample` + - `audiomixer.Mixer` + - `audiomp3.MP3Decoder` + + You can play these back with `audioio.AudioOut`, `audiobusio.I2SOut` or `audiopwmio.PWMAudioOut`. +""" + +FrameBuffer = Union[rgbmatrix.RGBMatrix] +"""Classes that implement the framebuffer protocol + + - `rgbmatrix.RGBMatrix` +""" diff --git a/shared-bindings/gnss/GNSS 2.c b/shared-bindings/gnss/GNSS 2.c new file mode 100644 index 0000000000..087c353953 --- /dev/null +++ b/shared-bindings/gnss/GNSS 2.c @@ -0,0 +1,205 @@ +// SPDX-FileCopyrightText: Sony Semiconductor Solutions Corporation +// +// SPDX-License-Identifier: MIT + +#include "shared-bindings/gnss/GNSS.h" +#include "shared-bindings/time/__init__.h" +#include "shared-bindings/util.h" + +#include "py/objproperty.h" +#include "py/runtime.h" + +//| class GNSS: +//| """Get updated positioning information from Global Navigation Satellite System (GNSS) +//| +//| Usage:: +//| +//| import gnss +//| import time +//| +//| nav = gnss.GNSS([gnss.SatelliteSystem.GPS, gnss.SatelliteSystem.GLONASS]) +//| last_print = time.monotonic() +//| while True: +//| nav.update() +//| current = time.monotonic() +//| if current - last_print >= 1.0: +//| last_print = current +//| if nav.fix is gnss.PositionFix.INVALID: +//| print("Waiting for fix...") +//| continue +//| print("Latitude: {0:.6f} degrees".format(nav.latitude)) +//| print("Longitude: {0:.6f} degrees".format(nav.longitude))""" +//| + +//| def __init__(self, system: Union[SatelliteSystem, List[SatelliteSystem]]) -> None: +//| """Turn on the GNSS. +//| +//| :param system: satellite system to use""" +//| ... +//| +STATIC mp_obj_t gnss_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + gnss_obj_t *self = m_new_obj(gnss_obj_t); + self->base.type = &gnss_type; + enum { ARG_system }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_system, MP_ARG_REQUIRED | MP_ARG_OBJ }, + }; + 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); + + unsigned long selection = 0; + if (MP_OBJ_IS_TYPE(args[ARG_system].u_obj, &gnss_satellitesystem_type)) { + selection |= gnss_satellitesystem_obj_to_type(args[ARG_system].u_obj); + } else if (MP_OBJ_IS_TYPE(args[ARG_system].u_obj, &mp_type_list)) { + size_t systems_size = 0; + mp_obj_t *systems; + mp_obj_list_get(args[ARG_system].u_obj, &systems_size, &systems); + for (size_t i = 0; i < systems_size; ++i) { + if (!MP_OBJ_IS_TYPE(systems[i], &gnss_satellitesystem_type)) { + mp_raise_TypeError(translate("System entry must be gnss.SatelliteSystem")); + } + selection |= gnss_satellitesystem_obj_to_type(systems[i]); + } + } else { + mp_raise_TypeError(translate("System entry must be gnss.SatelliteSystem")); + } + + common_hal_gnss_construct(self, selection); + return MP_OBJ_FROM_PTR(self); +} + +//| def deinit(self) -> None: +//| """Turn off the GNSS.""" +//| ... +//| +STATIC mp_obj_t gnss_obj_deinit(mp_obj_t self_in) { + gnss_obj_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_gnss_deinit(self); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(gnss_deinit_obj, gnss_obj_deinit); + +STATIC void check_for_deinit(gnss_obj_t *self) { + if (common_hal_gnss_deinited(self)) { + raise_deinited_error(); + } +} + +//| def update(self) -> None: +//| """Update GNSS positioning information.""" +//| ... +//| +STATIC mp_obj_t gnss_obj_update(mp_obj_t self_in) { + gnss_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + + common_hal_gnss_update(self); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(gnss_update_obj, gnss_obj_update); + +//| latitude: float +//| """Latitude of current position in degrees (float).""" +//| +STATIC mp_obj_t gnss_obj_get_latitude(mp_obj_t self_in) { + gnss_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return mp_obj_new_float(common_hal_gnss_get_latitude(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_latitude_obj, gnss_obj_get_latitude); + +const mp_obj_property_t gnss_latitude_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&gnss_get_latitude_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + +//| longitude: float +//| """Longitude of current position in degrees (float).""" +//| +STATIC mp_obj_t gnss_obj_get_longitude(mp_obj_t self_in) { + gnss_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return mp_obj_new_float(common_hal_gnss_get_longitude(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_longitude_obj, gnss_obj_get_longitude); + +const mp_obj_property_t gnss_longitude_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&gnss_get_longitude_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + +//| altitude: float +//| """Altitude of current position in meters (float).""" +//| +STATIC mp_obj_t gnss_obj_get_altitude(mp_obj_t self_in) { + gnss_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return mp_obj_new_float(common_hal_gnss_get_altitude(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_altitude_obj, gnss_obj_get_altitude); + +const mp_obj_property_t gnss_altitude_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&gnss_get_altitude_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + +//| timestamp: time.struct_time +//| """Time when the position data was updated.""" +//| +STATIC mp_obj_t gnss_obj_get_timestamp(mp_obj_t self_in) { + gnss_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + timeutils_struct_time_t tm; + common_hal_gnss_get_timestamp(self, &tm); + return struct_time_from_tm(&tm); +} +MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_timestamp_obj, gnss_obj_get_timestamp); + +const mp_obj_property_t gnss_timestamp_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&gnss_get_timestamp_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + +//| fix: PositionFix +//| """Fix mode.""" +//| +STATIC mp_obj_t gnss_obj_get_fix(mp_obj_t self_in) { + gnss_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return gnss_positionfix_type_to_obj(common_hal_gnss_get_fix(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_fix_obj, gnss_obj_get_fix); + +const mp_obj_property_t gnss_fix_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&gnss_get_fix_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + +STATIC const mp_rom_map_elem_t gnss_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&gnss_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&gnss_update_obj) }, + + { MP_ROM_QSTR(MP_QSTR_latitude), MP_ROM_PTR(&gnss_latitude_obj) }, + { MP_ROM_QSTR(MP_QSTR_longitude), MP_ROM_PTR(&gnss_longitude_obj) }, + { MP_ROM_QSTR(MP_QSTR_altitude), MP_ROM_PTR(&gnss_altitude_obj) }, + { MP_ROM_QSTR(MP_QSTR_timestamp), MP_ROM_PTR(&gnss_timestamp_obj) }, + { MP_ROM_QSTR(MP_QSTR_fix), MP_ROM_PTR(&gnss_fix_obj) } +}; +STATIC MP_DEFINE_CONST_DICT(gnss_locals_dict, gnss_locals_dict_table); + +const mp_obj_type_t gnss_type = { + { &mp_type_type }, + .name = MP_QSTR_GNSS, + .make_new = gnss_make_new, + .locals_dict = (mp_obj_dict_t*)&gnss_locals_dict, +}; diff --git a/shared-bindings/gnss/GNSS 2.h b/shared-bindings/gnss/GNSS 2.h new file mode 100644 index 0000000000..60069a90a9 --- /dev/null +++ b/shared-bindings/gnss/GNSS 2.h @@ -0,0 +1,27 @@ +// SPDX-FileCopyrightText: Sony Semiconductor Solutions Corporation +// +// SPDX-License-Identifier: MIT + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_GNSS_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_GNSS_H + +#include "common-hal/gnss/GNSS.h" +#include "shared-bindings/gnss/SatelliteSystem.h" +#include "shared-bindings/gnss/PositionFix.h" + +#include "lib/timeutils/timeutils.h" + +extern const mp_obj_type_t gnss_type; + +void common_hal_gnss_construct(gnss_obj_t *self, unsigned long selection); +void common_hal_gnss_deinit(gnss_obj_t *self); +bool common_hal_gnss_deinited(gnss_obj_t *self); +void common_hal_gnss_update(gnss_obj_t *self); + +mp_float_t common_hal_gnss_get_latitude(gnss_obj_t *self); +mp_float_t common_hal_gnss_get_longitude(gnss_obj_t *self); +mp_float_t common_hal_gnss_get_altitude(gnss_obj_t *self); +void common_hal_gnss_get_timestamp(gnss_obj_t *self, timeutils_struct_time_t *tm); +gnss_positionfix_t common_hal_gnss_get_fix(gnss_obj_t *self); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_GNSS_H diff --git a/shared-bindings/gnss/PositionFix 2.c b/shared-bindings/gnss/PositionFix 2.c new file mode 100644 index 0000000000..e60611d705 --- /dev/null +++ b/shared-bindings/gnss/PositionFix 2.c @@ -0,0 +1,80 @@ +// SPDX-FileCopyrightText: Sony Semiconductor Solutions Corporation +// +// SPDX-License-Identifier: MIT + +#include "shared-bindings/gnss/PositionFix.h" + +//| class PositionFix: +//| """Position fix mode""" +//| +//| def __init__(self) -> None: +//| """Enum-like class to define the position fix mode.""" +//| +//| INVALID: PositionFix +//| """No measurement.""" +//| +//| FIX_2D: PositionFix +//| """2D fix.""" +//| +//| FIX_3D: PositionFix +//| """3D fix.""" +//| +const mp_obj_type_t gnss_positionfix_type; + +const gnss_positionfix_obj_t gnss_positionfix_invalid_obj = { + { &gnss_positionfix_type }, +}; + +const gnss_positionfix_obj_t gnss_positionfix_fix2d_obj = { + { &gnss_positionfix_type }, +}; + +const gnss_positionfix_obj_t gnss_positionfix_fix3d_obj = { + { &gnss_positionfix_type }, +}; + +gnss_positionfix_t gnss_positionfix_obj_to_type(mp_obj_t obj) { + gnss_positionfix_t posfix = POSITIONFIX_INVALID; + if (obj == MP_ROM_PTR(&gnss_positionfix_fix2d_obj)) { + posfix = POSITIONFIX_2D; + } else if (obj == MP_ROM_PTR(&gnss_positionfix_fix3d_obj)) { + posfix = POSITIONFIX_3D; + } + return posfix; +} + +mp_obj_t gnss_positionfix_type_to_obj(gnss_positionfix_t posfix) { + switch (posfix) { + case POSITIONFIX_2D: + return (mp_obj_t)MP_ROM_PTR(&gnss_positionfix_fix2d_obj); + case POSITIONFIX_3D: + return (mp_obj_t)MP_ROM_PTR(&gnss_positionfix_fix3d_obj); + case POSITIONFIX_INVALID: + default: + return (mp_obj_t)MP_ROM_PTR(&gnss_positionfix_invalid_obj); + } +} + +STATIC const mp_rom_map_elem_t gnss_positionfix_locals_dict_table[] = { + {MP_ROM_QSTR(MP_QSTR_INVALID), MP_ROM_PTR(&gnss_positionfix_invalid_obj)}, + {MP_ROM_QSTR(MP_QSTR_FIX_2D), MP_ROM_PTR(&gnss_positionfix_fix2d_obj)}, + {MP_ROM_QSTR(MP_QSTR_FIX_3D), MP_ROM_PTR(&gnss_positionfix_fix3d_obj)}, +}; +STATIC MP_DEFINE_CONST_DICT(gnss_positionfix_locals_dict, gnss_positionfix_locals_dict_table); + +STATIC void gnss_positionfix_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { + qstr posfix = MP_QSTR_INVALID; + if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_positionfix_fix2d_obj)) { + posfix = MP_QSTR_FIX_2D; + } else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_positionfix_fix3d_obj)) { + posfix = MP_QSTR_FIX_3D; + } + mp_printf(print, "%q.%q.%q", MP_QSTR_gnss, MP_QSTR_PositionFix, posfix); +} + +const mp_obj_type_t gnss_positionfix_type = { + { &mp_type_type }, + .name = MP_QSTR_PositionFix, + .print = gnss_positionfix_print, + .locals_dict = (mp_obj_t)&gnss_positionfix_locals_dict, +}; diff --git a/shared-bindings/gnss/PositionFix 2.h b/shared-bindings/gnss/PositionFix 2.h new file mode 100644 index 0000000000..34090872cc --- /dev/null +++ b/shared-bindings/gnss/PositionFix 2.h @@ -0,0 +1,28 @@ +// SPDX-FileCopyrightText: Sony Semiconductor Solutions Corporation +// +// SPDX-License-Identifier: MIT + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_POSITIONFIX_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_POSITIONFIX_H + +#include "py/obj.h" + +typedef enum { + POSITIONFIX_INVALID, + POSITIONFIX_2D, + POSITIONFIX_3D, +} gnss_positionfix_t; + +const mp_obj_type_t gnss_positionfix_type; + +gnss_positionfix_t gnss_positionfix_obj_to_type(mp_obj_t obj); +mp_obj_t gnss_positionfix_type_to_obj(gnss_positionfix_t mode); + +typedef struct { + mp_obj_base_t base; +} gnss_positionfix_obj_t; +extern const gnss_positionfix_obj_t gnss_positionfix_invalid_obj; +extern const gnss_positionfix_obj_t gnss_positionfix_fix2d_obj; +extern const gnss_positionfix_obj_t gnss_positionfix_fix3d_obj; + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_POSITIONFIX_H diff --git a/shared-bindings/gnss/SatelliteSystem 2.c b/shared-bindings/gnss/SatelliteSystem 2.c new file mode 100644 index 0000000000..7d66727b8d --- /dev/null +++ b/shared-bindings/gnss/SatelliteSystem 2.c @@ -0,0 +1,113 @@ +// SPDX-FileCopyrightText: Sony Semiconductor Solutions Corporation +// +// SPDX-License-Identifier: MIT + +#include "shared-bindings/gnss/SatelliteSystem.h" + +//| class SatelliteSystem: +//| """Satellite system type""" +//| +//| def __init__(self) -> None: +//| """Enum-like class to define the satellite system type.""" +//| +//| GPS: SatelliteSystem +//| """Global Positioning System.""" +//| +//| GLONASS: SatelliteSystem +//| """GLObal NAvigation Satellite System.""" +//| +//| SBAS: SatelliteSystem +//| """Satellite Based Augmentation System.""" +//| +//| QZSS_L1CA: SatelliteSystem +//| """Quasi-Zenith Satellite System L1C/A.""" +//| +//| QZSS_L1S: SatelliteSystem +//| """Quasi-Zenith Satellite System L1S.""" +//| +const mp_obj_type_t gnss_satellitesystem_type; + +const gnss_satellitesystem_obj_t gnss_satellitesystem_gps_obj = { + { &gnss_satellitesystem_type }, +}; + +const gnss_satellitesystem_obj_t gnss_satellitesystem_glonass_obj = { + { &gnss_satellitesystem_type }, +}; + +const gnss_satellitesystem_obj_t gnss_satellitesystem_sbas_obj = { + { &gnss_satellitesystem_type }, +}; + +const gnss_satellitesystem_obj_t gnss_satellitesystem_qzss_l1ca_obj = { + { &gnss_satellitesystem_type }, +}; + +const gnss_satellitesystem_obj_t gnss_satellitesystem_qzss_l1s_obj = { + { &gnss_satellitesystem_type }, +}; + +gnss_satellitesystem_t gnss_satellitesystem_obj_to_type(mp_obj_t obj) { + if (obj == MP_ROM_PTR(&gnss_satellitesystem_gps_obj)) { + return SATELLITESYSTEM_GPS; + } else if (obj == MP_ROM_PTR(&gnss_satellitesystem_glonass_obj)) { + return SATELLITESYSTEM_GLONASS; + } else if (obj == MP_ROM_PTR(&gnss_satellitesystem_sbas_obj)) { + return SATELLITESYSTEM_SBAS; + } else if (obj == MP_ROM_PTR(&gnss_satellitesystem_qzss_l1ca_obj)) { + return SATELLITESYSTEM_QZSS_L1CA; + } else if (obj == MP_ROM_PTR(&gnss_satellitesystem_qzss_l1s_obj)) { + return SATELLITESYSTEM_QZSS_L1S; + } + return SATELLITESYSTEM_NONE; +} + +mp_obj_t gnss_satellitesystem_type_to_obj(gnss_satellitesystem_t system) { + switch (system) { + case SATELLITESYSTEM_GPS: + return (mp_obj_t)MP_ROM_PTR(&gnss_satellitesystem_gps_obj); + case SATELLITESYSTEM_GLONASS: + return (mp_obj_t)MP_ROM_PTR(&gnss_satellitesystem_glonass_obj); + case SATELLITESYSTEM_SBAS: + return (mp_obj_t)MP_ROM_PTR(&gnss_satellitesystem_sbas_obj); + case SATELLITESYSTEM_QZSS_L1CA: + return (mp_obj_t)MP_ROM_PTR(&gnss_satellitesystem_qzss_l1ca_obj); + case SATELLITESYSTEM_QZSS_L1S: + return (mp_obj_t)MP_ROM_PTR(&gnss_satellitesystem_qzss_l1s_obj); + case SATELLITESYSTEM_NONE: + default: + return (mp_obj_t)MP_ROM_PTR(&mp_const_none_obj); + } +} + +STATIC const mp_rom_map_elem_t gnss_satellitesystem_locals_dict_table[] = { + {MP_ROM_QSTR(MP_QSTR_GPS), MP_ROM_PTR(&gnss_satellitesystem_gps_obj)}, + {MP_ROM_QSTR(MP_QSTR_GLONASS), MP_ROM_PTR(&gnss_satellitesystem_glonass_obj)}, + {MP_ROM_QSTR(MP_QSTR_SBAS), MP_ROM_PTR(&gnss_satellitesystem_sbas_obj)}, + {MP_ROM_QSTR(MP_QSTR_QZSS_L1CA), MP_ROM_PTR(&gnss_satellitesystem_qzss_l1ca_obj)}, + {MP_ROM_QSTR(MP_QSTR_QZSS_L1S), MP_ROM_PTR(&gnss_satellitesystem_qzss_l1s_obj)}, +}; +STATIC MP_DEFINE_CONST_DICT(gnss_satellitesystem_locals_dict, gnss_satellitesystem_locals_dict_table); + +STATIC void gnss_satellitesystem_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { + qstr system = MP_QSTR_None; + if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_satellitesystem_gps_obj)) { + system = MP_QSTR_GPS; + } else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_satellitesystem_glonass_obj)) { + system = MP_QSTR_GLONASS; + } else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_satellitesystem_sbas_obj)) { + system = MP_QSTR_SBAS; + } else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_satellitesystem_qzss_l1ca_obj)) { + system = MP_QSTR_QZSS_L1CA; + } else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_satellitesystem_qzss_l1s_obj)) { + system = MP_QSTR_QZSS_L1S; + } + mp_printf(print, "%q.%q.%q", MP_QSTR_gnss, MP_QSTR_SatelliteSystem, system); +} + +const mp_obj_type_t gnss_satellitesystem_type = { + { &mp_type_type }, + .name = MP_QSTR_SatelliteSystem, + .print = gnss_satellitesystem_print, + .locals_dict = (mp_obj_t)&gnss_satellitesystem_locals_dict, +}; diff --git a/shared-bindings/gnss/SatelliteSystem 2.h b/shared-bindings/gnss/SatelliteSystem 2.h new file mode 100644 index 0000000000..17f1550028 --- /dev/null +++ b/shared-bindings/gnss/SatelliteSystem 2.h @@ -0,0 +1,33 @@ +// SPDX-FileCopyrightText: Sony Semiconductor Solutions Corporation +// +// SPDX-License-Identifier: MIT + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_SATELLITESYSTEM_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_SATELLITESYSTEM_H + +#include "py/obj.h" + +typedef enum { + SATELLITESYSTEM_NONE = 0, + SATELLITESYSTEM_GPS = (1U << 0), + SATELLITESYSTEM_GLONASS = (1U << 1), + SATELLITESYSTEM_SBAS = (1U << 2), + SATELLITESYSTEM_QZSS_L1CA = (1U << 3), + SATELLITESYSTEM_QZSS_L1S = (1U << 4), +} gnss_satellitesystem_t; + +const mp_obj_type_t gnss_satellitesystem_type; + +gnss_satellitesystem_t gnss_satellitesystem_obj_to_type(mp_obj_t obj); +mp_obj_t gnss_satellitesystem_type_to_obj(gnss_satellitesystem_t mode); + +typedef struct { + mp_obj_base_t base; +} gnss_satellitesystem_obj_t; +extern const gnss_satellitesystem_obj_t gnss_satellitesystem_gps_obj; +extern const gnss_satellitesystem_obj_t gnss_satellitesystem_glonass_obj; +extern const gnss_satellitesystem_obj_t gnss_satellitesystem_sbas_obj; +extern const gnss_satellitesystem_obj_t gnss_satellitesystem_qzss_l1ca_obj; +extern const gnss_satellitesystem_obj_t gnss_satellitesystem_qzss_l1s_obj; + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_SATELLITESYSTEM_H diff --git a/shared-bindings/gnss/__init__ 2.c b/shared-bindings/gnss/__init__ 2.c new file mode 100644 index 0000000000..4b0d312ae6 --- /dev/null +++ b/shared-bindings/gnss/__init__ 2.c @@ -0,0 +1,31 @@ +// SPDX-FileCopyrightText: Sony Semiconductor Solutions Corporation +// +// SPDX-License-Identifier: MIT + +#include "py/obj.h" +#include "py/runtime.h" +#include "py/mphal.h" +#include "shared-bindings/gnss/GNSS.h" +#include "shared-bindings/gnss/SatelliteSystem.h" +#include "shared-bindings/gnss/PositionFix.h" +#include "shared-bindings/util.h" + +//| """Global Navigation Satellite System +//| +//| The `gnss` module contains classes to control the GNSS and acquire positioning information.""" +//| +STATIC const mp_rom_map_elem_t gnss_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gnss) }, + { MP_ROM_QSTR(MP_QSTR_GNSS), MP_ROM_PTR(&gnss_type) }, + + // Enum-like Classes. + { MP_ROM_QSTR(MP_QSTR_SatelliteSystem), MP_ROM_PTR(&gnss_satellitesystem_type) }, + { MP_ROM_QSTR(MP_QSTR_PositionFix), MP_ROM_PTR(&gnss_positionfix_type) }, +}; + +STATIC MP_DEFINE_CONST_DICT(gnss_module_globals, gnss_module_globals_table); + +const mp_obj_module_t gnss_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t*)&gnss_module_globals, +}; diff --git a/shared-bindings/i2cperipheral/I2CPeripheral 2.c b/shared-bindings/i2cperipheral/I2CPeripheral 2.c new file mode 100644 index 0000000000..b5ac861b4e --- /dev/null +++ b/shared-bindings/i2cperipheral/I2CPeripheral 2.c @@ -0,0 +1,436 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Noralf Trønnes + * + * 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/microcontroller/Pin.h" +#include "shared-bindings/i2cperipheral/I2CPeripheral.h" +#include "shared-bindings/time/__init__.h" +#include "shared-bindings/util.h" + +#include "lib/utils/buffer_helper.h" +#include "lib/utils/context_manager_helpers.h" +#include "lib/utils/interrupt_char.h" + +#include "py/mperrno.h" +#include "py/mphal.h" +#include "py/obj.h" +#include "py/objproperty.h" +#include "py/runtime.h" + +STATIC mp_obj_t mp_obj_new_i2cperipheral_i2c_peripheral_request(i2cperipheral_i2c_peripheral_obj_t *peripheral, uint8_t address, bool is_read, bool is_restart) { + i2cperipheral_i2c_peripheral_request_obj_t *self = m_new_obj(i2cperipheral_i2c_peripheral_request_obj_t); + self->base.type = &i2cperipheral_i2c_peripheral_request_type; + self->peripheral = peripheral; + self->address = address; + self->is_read = is_read; + self->is_restart = is_restart; + return (mp_obj_t)self; +} + +//| class I2CPeripheral: +//| """Two wire serial protocol peripheral""" +//| +//| def __init__(self, scl: microcontroller.Pin, sda: microcontroller.Pin, addresses: Sequence[int], smbus: bool = False) -> None: +//| """I2C is a two-wire protocol for communicating between devices. +//| This implements the peripheral (sensor, secondary) side. +//| +//| :param ~microcontroller.Pin scl: The clock pin +//| :param ~microcontroller.Pin sda: The data pin +//| :param addresses: The I2C addresses to respond to (how many is hw dependent). +//| :type addresses: list[int] +//| :param bool smbus: Use SMBUS timings if the hardware supports it""" +//| ... +//| +STATIC mp_obj_t i2cperipheral_i2c_peripheral_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + i2cperipheral_i2c_peripheral_obj_t *self = m_new_obj(i2cperipheral_i2c_peripheral_obj_t); + self->base.type = &i2cperipheral_i2c_peripheral_type; + enum { ARG_scl, ARG_sda, ARG_addresses, ARG_smbus }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_scl, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_sda, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_addresses, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_smbus, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, + }; + 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); + + const mcu_pin_obj_t* scl = validate_obj_is_free_pin(args[ARG_scl].u_obj); + const mcu_pin_obj_t* sda = validate_obj_is_free_pin(args[ARG_sda].u_obj); + + mp_obj_iter_buf_t iter_buf; + mp_obj_t iterable = mp_getiter(args[ARG_addresses].u_obj, &iter_buf); + mp_obj_t item; + uint8_t *addresses = NULL; + unsigned int i = 0; + while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { + mp_int_t value; + if (!mp_obj_get_int_maybe(item, &value)) { + mp_raise_TypeError_varg(translate("can't convert %q to %q"), MP_QSTR_address, MP_QSTR_int); + } + if (value < 0x00 || value > 0x7f) { + mp_raise_ValueError(translate("address out of bounds")); + } + addresses = m_renew(uint8_t, addresses, i, i + 1); + addresses[i++] = value; + } + if (i == 0) { + mp_raise_ValueError(translate("addresses is empty")); + } + + common_hal_i2cperipheral_i2c_peripheral_construct(self, scl, sda, addresses, i, args[ARG_smbus].u_bool); + return (mp_obj_t)self; +} + +//| def deinit(self) -> None: +//| """Releases control of the underlying hardware so other classes can use it.""" +//| ... +//| +STATIC mp_obj_t i2cperipheral_i2c_peripheral_obj_deinit(mp_obj_t self_in) { + mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cperipheral_i2c_peripheral_type)); + i2cperipheral_i2c_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_i2cperipheral_i2c_peripheral_deinit(self); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(i2cperipheral_i2c_peripheral_deinit_obj, i2cperipheral_i2c_peripheral_obj_deinit); + +//| def __enter__(self) -> I2CPeripheral: +//| """No-op used in Context Managers.""" +//| ... +//| +// Provided by context manager helper. + +//| def __exit__(self) -> None: +//| """Automatically deinitializes the hardware on context exit. See +//| :ref:`lifetime-and-contextmanagers` for more info.""" +//| ... +//| +STATIC mp_obj_t i2cperipheral_i2c_peripheral_obj___exit__(size_t n_args, const mp_obj_t *args) { + mp_check_self(MP_OBJ_IS_TYPE(args[0], &i2cperipheral_i2c_peripheral_type)); + i2cperipheral_i2c_peripheral_obj_t *self = MP_OBJ_TO_PTR(args[0]); + common_hal_i2cperipheral_i2c_peripheral_deinit(self); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cperipheral_i2c_peripheral___exit___obj, 4, 4, i2cperipheral_i2c_peripheral_obj___exit__); + +//| def request(self, timeout: float = -1) -> I2CPeripheralRequest: +//| """Wait for an I2C request. +//| +//| :param float timeout: Timeout in seconds. Zero means wait forever, a negative value means check once +//| :return: I2C Slave Request or None if timeout=-1 and there's no request +//| :rtype: ~i2cperipheral.I2CPeripheralRequest""" +//| +STATIC mp_obj_t i2cperipheral_i2c_peripheral_request(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + mp_check_self(MP_OBJ_IS_TYPE(pos_args[0], &i2cperipheral_i2c_peripheral_type)); + i2cperipheral_i2c_peripheral_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + if(common_hal_i2cperipheral_i2c_peripheral_deinited(self)) { + raise_deinited_error(); + } + enum { ARG_timeout }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(-1)} }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + #if MICROPY_PY_BUILTINS_FLOAT + float f = mp_obj_get_float(args[ARG_timeout].u_obj) * 1000; + int timeout_ms = (int)f; + #else + int timeout_ms = mp_obj_get_int(args[ARG_timeout].u_obj) * 1000; + #endif + + bool forever = false; + uint64_t timeout_end = 0; + if (timeout_ms == 0) { + forever = true; + } else if (timeout_ms > 0) { + timeout_end = common_hal_time_monotonic() + timeout_ms; + } + + int last_error = 0; + + do { + uint8_t address; + bool is_read; + bool is_restart; + + RUN_BACKGROUND_TASKS; + if (mp_hal_is_interrupted()) { + return mp_const_none; + } + + int status = common_hal_i2cperipheral_i2c_peripheral_is_addressed(self, &address, &is_read, &is_restart); + if (status < 0) { + // On error try one more time before bailing out + if (last_error) { + mp_raise_OSError(last_error); + } + last_error = -status; + mp_hal_delay_ms(10); + continue; + } + + last_error = 0; + + if (status == 0) { + mp_hal_delay_us(10); + continue; + } + + return mp_obj_new_i2cperipheral_i2c_peripheral_request(self, address, is_read, is_restart); + } while (forever || common_hal_time_monotonic() < timeout_end); + + if (timeout_ms > 0) { + mp_raise_OSError(MP_ETIMEDOUT); + } + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(i2cperipheral_i2c_peripheral_request_obj, 1, i2cperipheral_i2c_peripheral_request); + +STATIC const mp_rom_map_elem_t i2cperipheral_i2c_peripheral_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&i2cperipheral_i2c_peripheral___exit___obj) }, + { MP_ROM_QSTR(MP_QSTR_request), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_obj) }, + +}; + +STATIC MP_DEFINE_CONST_DICT(i2cperipheral_i2c_peripheral_locals_dict, i2cperipheral_i2c_peripheral_locals_dict_table); + +const mp_obj_type_t i2cperipheral_i2c_peripheral_type = { + { &mp_type_type }, + .name = MP_QSTR_I2CPeripheral, + .make_new = i2cperipheral_i2c_peripheral_make_new, + .locals_dict = (mp_obj_dict_t*)&i2cperipheral_i2c_peripheral_locals_dict, +}; + +//| class I2CPeripheralRequest: +//| +//| def __init__(self, peripheral: i2cperipheral.I2CPeripheral, address: int, is_read: bool, is_restart: bool) -> None: +//| """Information about an I2C transfer request +//| This cannot be instantiated directly, but is returned by :py:meth:`I2CPeripheral.request`. +//| +//| :param peripheral: The I2CPeripheral object receiving this request +//| :param address: I2C address +//| :param is_read: True if the main peripheral is requesting data +//| :param is_restart: Repeated Start Condition""" +//| +STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { + mp_arg_check_num(n_args, kw_args, 4, 4, false); + return mp_obj_new_i2cperipheral_i2c_peripheral_request(args[0], mp_obj_get_int(args[1]), mp_obj_is_true(args[2]), mp_obj_is_true(args[3])); +} + +//| def __enter__(self) -> I2CPeripheralRequest: +//| """No-op used in Context Managers.""" +//| ... +//| +// Provided by context manager helper. + +//| def __exit__(self) -> None: +//| """Close the request.""" +//| ... +//| +STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_obj___exit__(size_t n_args, const mp_obj_t *args) { + mp_check_self(MP_OBJ_IS_TYPE(args[0], &i2cperipheral_i2c_peripheral_request_type)); + i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(args[0]); + common_hal_i2cperipheral_i2c_peripheral_close(self->peripheral); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cperipheral_i2c_peripheral_request___exit___obj, 4, 4, i2cperipheral_i2c_peripheral_request_obj___exit__); + +//| address: int +//| """The I2C address of the request.""" +//| +STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_get_address(mp_obj_t self_in) { + mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cperipheral_i2c_peripheral_request_type)); + i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(self_in); + return mp_obj_new_int(self->address); +} +MP_DEFINE_CONST_PROP_GET(i2cperipheral_i2c_peripheral_request_address_obj, i2cperipheral_i2c_peripheral_request_get_address); + +//| is_read: bool +//| """The I2C main controller is reading from this peripheral.""" +//| +STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_get_is_read(mp_obj_t self_in) { + mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cperipheral_i2c_peripheral_request_type)); + i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(self_in); + return mp_obj_new_bool(self->is_read); +} +MP_DEFINE_CONST_PROP_GET(i2cperipheral_i2c_peripheral_request_is_read_obj, i2cperipheral_i2c_peripheral_request_get_is_read); + +//| is_restart: bool +//| """Is Repeated Start Condition.""" +//| +STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_get_is_restart(mp_obj_t self_in) { + mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cperipheral_i2c_peripheral_request_type)); + i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(self_in); + return mp_obj_new_bool(self->is_restart); +} +MP_DEFINE_CONST_PROP_GET(i2cperipheral_i2c_peripheral_request_is_restart_obj, i2cperipheral_i2c_peripheral_request_get_is_restart); + +//| def read(self, n: int = -1, ack: bool = True) -> bytearray: +//| """Read data. +//| If ack=False, the caller is responsible for calling :py:meth:`I2CPeripheralRequest.ack`. +//| +//| :param n: Number of bytes to read (negative means all) +//| :param ack: Whether or not to send an ACK after the n'th byte +//| :return: Bytes read""" +//| ... +//| +STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + mp_check_self(MP_OBJ_IS_TYPE(pos_args[0], &i2cperipheral_i2c_peripheral_request_type)); + i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + enum { ARG_n, ARG_ack }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_n, MP_ARG_INT, {.u_int = -1} }, + { MP_QSTR_ack, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + if (self->is_read) { + mp_raise_OSError(MP_EACCES); + } + + int n = args[ARG_n].u_int; + if (n == 0) { + return mp_obj_new_bytearray(0, NULL); + } + bool ack = args[ARG_ack].u_bool; + + int i = 0; + uint8_t *buffer = NULL; + uint64_t timeout_end = common_hal_time_monotonic() + 10 * 1000; + while (common_hal_time_monotonic() < timeout_end) { + RUN_BACKGROUND_TASKS; + if (mp_hal_is_interrupted()) { + break; + } + + uint8_t data; + int num = common_hal_i2cperipheral_i2c_peripheral_read_byte(self->peripheral, &data); + if (num == 0) { + break; + } + + buffer = m_renew(uint8_t, buffer, i, i + 1); + buffer[i++] = data; + if (i == n) { + if (ack) { + common_hal_i2cperipheral_i2c_peripheral_ack(self->peripheral, true); + } + break; + } + common_hal_i2cperipheral_i2c_peripheral_ack(self->peripheral, true); + } + + return mp_obj_new_bytearray(i, buffer); +} +MP_DEFINE_CONST_FUN_OBJ_KW(i2cperipheral_i2c_peripheral_request_read_obj, 1, i2cperipheral_i2c_peripheral_request_read); + +//| def write(self, buffer: ReadableBuffer) -> int: +//| """Write the data contained in buffer. +//| +//| :param ~_typing.ReadableBuffer buffer: Write out the data in this buffer +//| :return: Number of bytes written""" +//| ... +//| +STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_write(mp_obj_t self_in, mp_obj_t buf_in) { + mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cperipheral_i2c_peripheral_request_type)); + i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(self_in); + + if (!self->is_read) { + mp_raise_OSError(MP_EACCES); + } + + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ); + + for (size_t i = 0; i < bufinfo.len; i++) { + RUN_BACKGROUND_TASKS; + if (mp_hal_is_interrupted()) { + break; + } + + int num = common_hal_i2cperipheral_i2c_peripheral_write_byte(self->peripheral, ((uint8_t *)(bufinfo.buf))[i]); + if (num == 0) { + return mp_obj_new_int(i); + } + } + + return mp_obj_new_int(bufinfo.len); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(i2cperipheral_i2c_peripheral_request_write_obj, i2cperipheral_i2c_peripheral_request_write); + +//| def ack(self, ack: bool = True) -> None: +//| """Acknowledge or Not Acknowledge last byte received. +//| Use together with :py:meth:`I2CPeripheralRequest.read` ack=False. +//| +//| :param ack: Whether to send an ACK or NACK""" +//| ... +//| +STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_ack(uint n_args, const mp_obj_t *args) { + mp_check_self(MP_OBJ_IS_TYPE(args[0], &i2cperipheral_i2c_peripheral_request_type)); + i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(args[0]); + bool ack = (n_args == 1) ? true : mp_obj_is_true(args[1]); + + if (self->is_read) { + mp_raise_OSError(MP_EACCES); + } + + common_hal_i2cperipheral_i2c_peripheral_ack(self->peripheral, ack); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cperipheral_i2c_peripheral_request_ack_obj, 1, 2, i2cperipheral_i2c_peripheral_request_ack); + +STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_close(mp_obj_t self_in) { + mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cperipheral_i2c_peripheral_request_type)); + i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(self_in); + + common_hal_i2cperipheral_i2c_peripheral_close(self->peripheral); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(i2cperipheral_i2c_peripheral_request_close_obj, i2cperipheral_i2c_peripheral_request_close); + +STATIC const mp_rom_map_elem_t i2cperipheral_i2c_peripheral_request_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request___exit___obj) }, + { MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_address_obj) }, + { MP_ROM_QSTR(MP_QSTR_is_read), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_is_read_obj) }, + { MP_ROM_QSTR(MP_QSTR_is_restart), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_is_restart_obj) }, + { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_read_obj) }, + { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_write_obj) }, + { MP_ROM_QSTR(MP_QSTR_ack), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_ack_obj) }, + { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_close_obj) }, +}; + +STATIC MP_DEFINE_CONST_DICT(i2cperipheral_i2c_peripheral_request_locals_dict, i2cperipheral_i2c_peripheral_request_locals_dict_table); + +const mp_obj_type_t i2cperipheral_i2c_peripheral_request_type = { + { &mp_type_type }, + .name = MP_QSTR_I2CPeripheralRequest, + .make_new = i2cperipheral_i2c_peripheral_request_make_new, + .locals_dict = (mp_obj_dict_t*)&i2cperipheral_i2c_peripheral_request_locals_dict, +}; diff --git a/shared-bindings/i2cperipheral/I2CPeripheral 2.h b/shared-bindings/i2cperipheral/I2CPeripheral 2.h new file mode 100644 index 0000000000..3035cfbfe7 --- /dev/null +++ b/shared-bindings/i2cperipheral/I2CPeripheral 2.h @@ -0,0 +1,60 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Noralf Trønnes + * + * 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_BUSIO_I2C_SLAVE_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_I2C_SLAVE_H + +#include "py/obj.h" + +#include "common-hal/microcontroller/Pin.h" +#include "common-hal/i2cperipheral/I2CPeripheral.h" + +typedef struct { + mp_obj_base_t base; + i2cperipheral_i2c_peripheral_obj_t *peripheral; + uint16_t address; + bool is_read; + bool is_restart; +} i2cperipheral_i2c_peripheral_request_obj_t; + +extern const mp_obj_type_t i2cperipheral_i2c_peripheral_request_type; + +extern const mp_obj_type_t i2cperipheral_i2c_peripheral_type; + +extern 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); +extern void common_hal_i2cperipheral_i2c_peripheral_deinit(i2cperipheral_i2c_peripheral_obj_t *self); +extern bool common_hal_i2cperipheral_i2c_peripheral_deinited(i2cperipheral_i2c_peripheral_obj_t *self); + +extern int common_hal_i2cperipheral_i2c_peripheral_is_addressed(i2cperipheral_i2c_peripheral_obj_t *self, + uint8_t *address, bool *is_read, bool *is_restart); +extern int common_hal_i2cperipheral_i2c_peripheral_read_byte(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t *data); +extern int common_hal_i2cperipheral_i2c_peripheral_write_byte(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t data); +extern void common_hal_i2cperipheral_i2c_peripheral_ack(i2cperipheral_i2c_peripheral_obj_t *self, bool ack); +extern void common_hal_i2cperipheral_i2c_peripheral_close(i2cperipheral_i2c_peripheral_obj_t *self); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_I2C_SLAVE_H diff --git a/shared-bindings/i2cperipheral/__init__ 2.c b/shared-bindings/i2cperipheral/__init__ 2.c new file mode 100644 index 0000000000..e2cb8509d6 --- /dev/null +++ b/shared-bindings/i2cperipheral/__init__ 2.c @@ -0,0 +1,106 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Noralf Trønnes + * + * 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/obj.h" +#include "py/runtime.h" + +#include "shared-bindings/microcontroller/Pin.h" +//#include "shared-bindings/i2cperipheral/__init__.h" +#include "shared-bindings/i2cperipheral/I2CPeripheral.h" + +#include "py/runtime.h" + +//| """Two wire serial protocol peripheral +//| +//| The `i2cperipheral` module contains classes to support an I2C peripheral. +//| +//| Example emulating a peripheral with 2 addresses (read and write):: +//| +//| import board +//| from i2cperipheral import I2CPeripheral +//| +//| regs = [0] * 16 +//| index = 0 +//| +//| with I2CPeripheral(board.SCL, board.SDA, (0x40, 0x41)) as device: +//| while True: +//| r = device.request() +//| if not r: +//| # Maybe do some housekeeping +//| continue +//| with r: # Closes the transfer if necessary by sending a NACK or feeding dummy bytes +//| if r.address == 0x40: +//| if not r.is_read: # Main write which is Selected read +//| b = r.read(1) +//| if not b or b[0] > 15: +//| break +//| index = b[0] +//| b = r.read(1) +//| if b: +//| regs[index] = b[0] +//| elif r.is_restart: # Combined transfer: This is the Main read message +//| n = r.write(bytes([regs[index]])) +//| #else: +//| # A read transfer is not supported in this example +//| # If the microcontroller tries, it will get 0xff byte(s) by the ctx manager (r.close()) +//| elif r.address == 0x41: +//| if not r.is_read: +//| b = r.read(1) +//| if b and b[0] == 0xde: +//| # do something +//| pass +//| +//| This example sets up an I2C device that can be accessed from Linux like this:: +//| +//| $ i2cget -y 1 0x40 0x01 +//| 0x00 +//| $ i2cset -y 1 0x40 0x01 0xaa +//| $ i2cget -y 1 0x40 0x01 +//| 0xaa +//| +//| .. warning:: +//| I2CPeripheral makes use of clock stretching in order to slow down +//| the host. +//| Make sure the I2C host supports this. +//| +//| Raspberry Pi in particular does not support this with its I2C hw block. +//| This can be worked around by using the ``i2c-gpio`` bit banging driver. +//| Since the RPi firmware uses the hw i2c, it's not possible to emulate a HAT eeprom.""" +//| + +STATIC const mp_rom_map_elem_t i2cperipheral_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_i2cperipheral) }, + { MP_ROM_QSTR(MP_QSTR_I2CPeripheral), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_type) }, +}; + +STATIC MP_DEFINE_CONST_DICT(i2cperipheral_module_globals, i2cperipheral_module_globals_table); + +const mp_obj_module_t i2cperipheral_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t*)&i2cperipheral_module_globals, +}; diff --git a/shared-bindings/memorymonitor/AllocationAlarm 2.c b/shared-bindings/memorymonitor/AllocationAlarm 2.c new file mode 100644 index 0000000000..7de8c12874 --- /dev/null +++ b/shared-bindings/memorymonitor/AllocationAlarm 2.c @@ -0,0 +1,137 @@ +/* + * This file is part of the Micro Python 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 + +#include "py/objproperty.h" +#include "py/runtime.h" +#include "py/runtime0.h" +#include "shared-bindings/memorymonitor/AllocationAlarm.h" +#include "shared-bindings/util.h" +#include "supervisor/shared/translate.h" + +//| class AllocationAlarm: +//| +//| def __init__(self, *, minimum_block_count: int = 1) -> None: +//| """Throw an exception when an allocation of ``minimum_block_count`` or more blocks +//| occurs while active. +//| +//| Track allocations:: +//| +//| import memorymonitor +//| +//| aa = memorymonitor.AllocationAlarm(minimum_block_count=2) +//| x = 2 +//| # Should not allocate any blocks. +//| with aa: +//| x = 5 +//| +//| # Should throw an exception when allocating storage for the 20 bytes. +//| with aa: +//| x = bytearray(20) +//| +//| """ +//| ... +//| +STATIC mp_obj_t memorymonitor_allocationalarm_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_minimum_block_count }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_minimum_block_count, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} }, + }; + 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_int_t minimum_block_count = args[ARG_minimum_block_count].u_int; + if (minimum_block_count < 1) { + mp_raise_ValueError_varg(translate("%q must be >= 1"), MP_QSTR_minimum_block_count); + } + + memorymonitor_allocationalarm_obj_t *self = m_new_obj(memorymonitor_allocationalarm_obj_t); + self->base.type = &memorymonitor_allocationalarm_type; + + common_hal_memorymonitor_allocationalarm_construct(self, minimum_block_count); + + return MP_OBJ_FROM_PTR(self); +} + +//| def ignore(self, count: int) -> AllocationAlarm: +//| """Sets the number of applicable allocations to ignore before raising the exception. +//| Automatically set back to zero at context exit. +//| +//| Use it within a ``with`` block:: +//| +//| # Will not alarm because the bytearray allocation will be ignored. +//| with aa.ignore(2): +//| x = bytearray(20) +//| """ +//| ... +//| +STATIC mp_obj_t memorymonitor_allocationalarm_obj_ignore(mp_obj_t self_in, mp_obj_t count_obj) { + mp_int_t count = mp_obj_get_int(count_obj); + if (count < 0) { + mp_raise_ValueError_varg(translate("%q must be >= 0"), MP_QSTR_count); + } + common_hal_memorymonitor_allocationalarm_set_ignore(self_in, count); + return self_in; +} +MP_DEFINE_CONST_FUN_OBJ_2(memorymonitor_allocationalarm_ignore_obj, memorymonitor_allocationalarm_obj_ignore); + +//| def __enter__(self) -> AllocationAlarm: +//| """Enables the alarm.""" +//| ... +//| +STATIC mp_obj_t memorymonitor_allocationalarm_obj___enter__(mp_obj_t self_in) { + common_hal_memorymonitor_allocationalarm_resume(self_in); + return self_in; +} +MP_DEFINE_CONST_FUN_OBJ_1(memorymonitor_allocationalarm___enter___obj, memorymonitor_allocationalarm_obj___enter__); + +//| def __exit__(self) -> None: +//| """Automatically disables the allocation alarm when exiting a context. See +//| :ref:`lifetime-and-contextmanagers` for more info.""" +//| ... +//| +STATIC mp_obj_t memorymonitor_allocationalarm_obj___exit__(size_t n_args, const mp_obj_t *args) { + (void)n_args; + common_hal_memorymonitor_allocationalarm_set_ignore(args[0], 0); + common_hal_memorymonitor_allocationalarm_pause(args[0]); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(memorymonitor_allocationalarm___exit___obj, 4, 4, memorymonitor_allocationalarm_obj___exit__); + +STATIC const mp_rom_map_elem_t memorymonitor_allocationalarm_locals_dict_table[] = { + // Methods + { MP_ROM_QSTR(MP_QSTR_ignore), MP_ROM_PTR(&memorymonitor_allocationalarm_ignore_obj) }, + { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&memorymonitor_allocationalarm___enter___obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&memorymonitor_allocationalarm___exit___obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(memorymonitor_allocationalarm_locals_dict, memorymonitor_allocationalarm_locals_dict_table); + +const mp_obj_type_t memorymonitor_allocationalarm_type = { + { &mp_type_type }, + .name = MP_QSTR_AllocationAlarm, + .make_new = memorymonitor_allocationalarm_make_new, + .locals_dict = (mp_obj_dict_t*)&memorymonitor_allocationalarm_locals_dict, +}; diff --git a/shared-bindings/memorymonitor/AllocationAlarm 2.h b/shared-bindings/memorymonitor/AllocationAlarm 2.h new file mode 100644 index 0000000000..304b9c5a72 --- /dev/null +++ b/shared-bindings/memorymonitor/AllocationAlarm 2.h @@ -0,0 +1,39 @@ +/* + * This file is part of the Micro Python 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. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_MEMORYMONITOR_ALLOCATIONALARM_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_MEMORYMONITOR_ALLOCATIONALARM_H + +#include "shared-module/memorymonitor/AllocationAlarm.h" + +extern const mp_obj_type_t memorymonitor_allocationalarm_type; + +void common_hal_memorymonitor_allocationalarm_construct(memorymonitor_allocationalarm_obj_t* self, size_t minimum_block_count); +void common_hal_memorymonitor_allocationalarm_pause(memorymonitor_allocationalarm_obj_t* self); +void common_hal_memorymonitor_allocationalarm_resume(memorymonitor_allocationalarm_obj_t* self); +void common_hal_memorymonitor_allocationalarm_set_ignore(memorymonitor_allocationalarm_obj_t* self, mp_int_t count); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_MEMORYMONITOR_ALLOCATIONALARM_H diff --git a/shared-bindings/memorymonitor/AllocationSize 2.c b/shared-bindings/memorymonitor/AllocationSize 2.c new file mode 100644 index 0000000000..b35bae3602 --- /dev/null +++ b/shared-bindings/memorymonitor/AllocationSize 2.c @@ -0,0 +1,183 @@ +/* + * This file is part of the Micro Python 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 + +#include "py/objproperty.h" +#include "py/runtime.h" +#include "py/runtime0.h" +#include "shared-bindings/memorymonitor/AllocationSize.h" +#include "shared-bindings/util.h" +#include "supervisor/shared/translate.h" + +//| class AllocationSize: +//| +//| def __init__(self) -> None: +//| """Tracks the number of allocations in power of two buckets. +//| +//| It will have 16 16-bit buckets to track allocation counts. It is total allocations +//| meaning frees are ignored. Reallocated memory is counted twice, at allocation and when +//| reallocated with the larger size. +//| +//| The buckets are measured in terms of blocks which is the finest granularity of the heap. +//| This means bucket 0 will count all allocations less than or equal to the number of bytes +//| per block, typically 16. Bucket 2 will be less than or equal to 4 blocks. See +//| `bytes_per_block` to convert blocks to bytes. +//| +//| Multiple AllocationSizes can be used to track different code boundaries. +//| +//| Track allocations:: +//| +//| import memorymonitor +//| +//| mm = memorymonitor.AllocationSize() +//| with mm: +//| print("hello world" * 3) +//| +//| for bucket, count in enumerate(mm): +//| print("<", 2 ** bucket, count) +//| +//| """ +//| ... +//| +STATIC mp_obj_t memorymonitor_allocationsize_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + memorymonitor_allocationsize_obj_t *self = m_new_obj(memorymonitor_allocationsize_obj_t); + self->base.type = &memorymonitor_allocationsize_type; + + common_hal_memorymonitor_allocationsize_construct(self); + + return MP_OBJ_FROM_PTR(self); +} + +//| def __enter__(self) -> AllocationSize: +//| """Clears counts and resumes tracking.""" +//| ... +//| +STATIC mp_obj_t memorymonitor_allocationsize_obj___enter__(mp_obj_t self_in) { + common_hal_memorymonitor_allocationsize_clear(self_in); + common_hal_memorymonitor_allocationsize_resume(self_in); + return self_in; +} +MP_DEFINE_CONST_FUN_OBJ_1(memorymonitor_allocationsize___enter___obj, memorymonitor_allocationsize_obj___enter__); + +//| def __exit__(self) -> None: +//| """Automatically pauses allocation tracking when exiting a context. See +//| :ref:`lifetime-and-contextmanagers` for more info.""" +//| ... +//| +STATIC mp_obj_t memorymonitor_allocationsize_obj___exit__(size_t n_args, const mp_obj_t *args) { + (void)n_args; + common_hal_memorymonitor_allocationsize_pause(args[0]); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(memorymonitor_allocationsize___exit___obj, 4, 4, memorymonitor_allocationsize_obj___exit__); + +//| bytes_per_block: int +//| """Number of bytes per block""" +//| +STATIC mp_obj_t memorymonitor_allocationsize_obj_get_bytes_per_block(mp_obj_t self_in) { + memorymonitor_allocationsize_obj_t *self = MP_OBJ_TO_PTR(self_in); + + return MP_OBJ_NEW_SMALL_INT(common_hal_memorymonitor_allocationsize_get_bytes_per_block(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(memorymonitor_allocationsize_get_bytes_per_block_obj, memorymonitor_allocationsize_obj_get_bytes_per_block); + +const mp_obj_property_t memorymonitor_allocationsize_bytes_per_block_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&memorymonitor_allocationsize_get_bytes_per_block_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + +//| def __len__(self) -> int: +//| """Returns the number of allocation buckets. +//| +//| This allows you to:: +//| +//| mm = memorymonitor.AllocationSize() +//| print(len(mm))""" +//| ... +//| +STATIC mp_obj_t memorymonitor_allocationsize_unary_op(mp_unary_op_t op, mp_obj_t self_in) { + memorymonitor_allocationsize_obj_t *self = MP_OBJ_TO_PTR(self_in); + uint16_t len = common_hal_memorymonitor_allocationsize_get_len(self); + switch (op) { + case MP_UNARY_OP_BOOL: return mp_obj_new_bool(len != 0); + case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(len); + default: return MP_OBJ_NULL; // op not supported + } +} + +//| def __getitem__(self, index: int) -> Optional[int]: +//| """Returns the allocation count for the given bucket. +//| +//| This allows you to:: +//| +//| mm = memorymonitor.AllocationSize() +//| print(mm[0])""" +//| ... +//| +STATIC mp_obj_t memorymonitor_allocationsize_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t value) { + if (value == mp_const_none) { + // delete item + mp_raise_AttributeError(translate("Cannot delete values")); + } else { + memorymonitor_allocationsize_obj_t *self = MP_OBJ_TO_PTR(self_in); + + if (MP_OBJ_IS_TYPE(index_obj, &mp_type_slice)) { + mp_raise_NotImplementedError(translate("Slices not supported")); + } else { + size_t index = mp_get_index(&memorymonitor_allocationsize_type, common_hal_memorymonitor_allocationsize_get_len(self), index_obj, false); + if (value == MP_OBJ_SENTINEL) { + // load + return MP_OBJ_NEW_SMALL_INT(common_hal_memorymonitor_allocationsize_get_item(self, index)); + } else { + mp_raise_AttributeError(translate("Read-only")); + } + } + } + return mp_const_none; +} + +STATIC const mp_rom_map_elem_t memorymonitor_allocationsize_locals_dict_table[] = { + // Methods + { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&memorymonitor_allocationsize___enter___obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&memorymonitor_allocationsize___exit___obj) }, + + // Properties + { MP_ROM_QSTR(MP_QSTR_bytes_per_block), MP_ROM_PTR(&memorymonitor_allocationsize_bytes_per_block_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(memorymonitor_allocationsize_locals_dict, memorymonitor_allocationsize_locals_dict_table); + +const mp_obj_type_t memorymonitor_allocationsize_type = { + { &mp_type_type }, + .name = MP_QSTR_AllocationSize, + .make_new = memorymonitor_allocationsize_make_new, + .subscr = memorymonitor_allocationsize_subscr, + .unary_op = memorymonitor_allocationsize_unary_op, + .getiter = mp_obj_new_generic_iterator, + .locals_dict = (mp_obj_dict_t*)&memorymonitor_allocationsize_locals_dict, +}; diff --git a/shared-bindings/memorymonitor/AllocationSize 2.h b/shared-bindings/memorymonitor/AllocationSize 2.h new file mode 100644 index 0000000000..bcd9514bf2 --- /dev/null +++ b/shared-bindings/memorymonitor/AllocationSize 2.h @@ -0,0 +1,42 @@ +/* + * This file is part of the Micro Python 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. + */ + +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_MEMORYMONITOR_ALLOCATIONSIZE_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_MEMORYMONITOR_ALLOCATIONSIZE_H + +#include "shared-module/memorymonitor/AllocationSize.h" + +extern const mp_obj_type_t memorymonitor_allocationsize_type; + +extern void common_hal_memorymonitor_allocationsize_construct(memorymonitor_allocationsize_obj_t* self); +extern void common_hal_memorymonitor_allocationsize_pause(memorymonitor_allocationsize_obj_t* self); +extern void common_hal_memorymonitor_allocationsize_resume(memorymonitor_allocationsize_obj_t* self); +extern void common_hal_memorymonitor_allocationsize_clear(memorymonitor_allocationsize_obj_t* self); +extern size_t common_hal_memorymonitor_allocationsize_get_bytes_per_block(memorymonitor_allocationsize_obj_t* self); +extern uint16_t common_hal_memorymonitor_allocationsize_get_len(memorymonitor_allocationsize_obj_t* self); +extern uint16_t common_hal_memorymonitor_allocationsize_get_item(memorymonitor_allocationsize_obj_t* self, int16_t index); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_MEMORYMONITOR_ALLOCATIONSIZE_H diff --git a/shared-bindings/memorymonitor/__init__ 2.c b/shared-bindings/memorymonitor/__init__ 2.c new file mode 100644 index 0000000000..c101ba5e0d --- /dev/null +++ b/shared-bindings/memorymonitor/__init__ 2.c @@ -0,0 +1,76 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Scott Shawcroft + * + * 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/obj.h" +#include "py/runtime.h" + +#include "shared-bindings/memorymonitor/__init__.h" +#include "shared-bindings/memorymonitor/AllocationAlarm.h" +#include "shared-bindings/memorymonitor/AllocationSize.h" + +//| """Memory monitoring helpers""" +//| + +//| class AllocationError(Exception): +//| """Catchall exception for allocation related errors.""" +//| ... +MP_DEFINE_MEMORYMONITOR_EXCEPTION(AllocationError, Exception) + +NORETURN void mp_raise_memorymonitor_AllocationError(const compressed_string_t* fmt, ...) { + va_list argptr; + va_start(argptr,fmt); + mp_obj_t exception = mp_obj_new_exception_msg_vlist(&mp_type_memorymonitor_AllocationError, fmt, argptr); + va_end(argptr); + nlr_raise(exception); +} + +STATIC const mp_rom_map_elem_t memorymonitor_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_memorymonitor) }, + { MP_ROM_QSTR(MP_QSTR_AllocationAlarm), MP_ROM_PTR(&memorymonitor_allocationalarm_type) }, + { MP_ROM_QSTR(MP_QSTR_AllocationSize), MP_ROM_PTR(&memorymonitor_allocationsize_type) }, + + // Errors + { MP_ROM_QSTR(MP_QSTR_AllocationError), MP_ROM_PTR(&mp_type_memorymonitor_AllocationError) }, +}; + +STATIC MP_DEFINE_CONST_DICT(memorymonitor_module_globals, memorymonitor_module_globals_table); + +void memorymonitor_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { + mp_print_kind_t k = kind & ~PRINT_EXC_SUBCLASS; + bool is_subclass = kind & PRINT_EXC_SUBCLASS; + if (!is_subclass && (k == PRINT_EXC)) { + mp_print_str(print, qstr_str(MP_OBJ_QSTR_VALUE(memorymonitor_module_globals_table[0].value))); + mp_print_str(print, "."); + } + mp_obj_exception_print(print, o_in, kind); +} + +const mp_obj_module_t memorymonitor_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t*)&memorymonitor_module_globals, +}; diff --git a/shared-bindings/memorymonitor/__init__ 2.h b/shared-bindings/memorymonitor/__init__ 2.h new file mode 100644 index 0000000000..60fcdc3f62 --- /dev/null +++ b/shared-bindings/memorymonitor/__init__ 2.h @@ -0,0 +1,49 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Scott Shawcroft + * + * 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_MEMORYMONITOR___INIT___H +#define MICROPY_INCLUDED_SHARED_BINDINGS_MEMORYMONITOR___INIT___H + +#include "py/obj.h" + + +void memorymonitor_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind); + +#define MP_DEFINE_MEMORYMONITOR_EXCEPTION(exc_name, base_name) \ +const mp_obj_type_t mp_type_memorymonitor_ ## exc_name = { \ + { &mp_type_type }, \ + .name = MP_QSTR_ ## exc_name, \ + .print = memorymonitor_exception_print, \ + .make_new = mp_obj_exception_make_new, \ + .attr = mp_obj_exception_attr, \ + .parent = &mp_type_ ## base_name, \ +}; + +extern const mp_obj_type_t mp_type_memorymonitor_AllocationError; + +NORETURN void mp_raise_memorymonitor_AllocationError(const compressed_string_t* msg, ...); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_MEMORYMONITOR___INIT___H diff --git a/shared-bindings/sdcardio/SDCard 2.c b/shared-bindings/sdcardio/SDCard 2.c new file mode 100644 index 0000000000..975f8b0953 --- /dev/null +++ b/shared-bindings/sdcardio/SDCard 2.c @@ -0,0 +1,183 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Jeff Epler 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/objproperty.h" +#include "py/runtime.h" +#include "py/objarray.h" + +#include "shared-bindings/sdcardio/SDCard.h" +#include "shared-module/sdcardio/SDCard.h" +#include "common-hal/busio/SPI.h" +#include "shared-bindings/busio/SPI.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "supervisor/flash.h" + +//| class SDCard: +//| """SD Card Block Interface +//| +//| Controls an SD card over SPI. This built-in module has higher read +//| performance than the library adafruit_sdcard, but it is only compatible with +//| `busio.SPI`, not `bitbangio.SPI`. Usually an SDCard object is used +//| with ``storage.VfsFat`` to allow file I/O to an SD card.""" +//| +//| def __init__(self, bus: busio.SPI, cs: microcontroller.Pin, baudrate: int = 8000000) -> None: +//| """Construct an SPI SD Card object with the given properties +//| +//| :param busio.SPI spi: The SPI bus +//| :param microcontroller.Pin cs: The chip select connected to the card +//| :param int baudrate: The SPI data rate to use after card setup +//| +//| Note that during detection and configuration, a hard-coded low baudrate is used. +//| Data transfers use the specified baurate (rounded down to one that is supported by +//| the microcontroller) +//| +//| Example usage: +//| +//| .. code-block:: python +//| +//| import os +//| +//| import board +//| import sdcardio +//| import storage +//| +//| sd = sdcardio.SDCard(board.SPI(), board.SD_CS) +//| vfs = storage.VfsFat(sd) +//| storage.mount(vfs, '/sd') +//| os.listdir('/sd')""" + +STATIC mp_obj_t sdcardio_sdcard_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_spi, ARG_cs, ARG_baudrate, ARG_sdio, NUM_ARGS }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_spi, MP_ARG_OBJ, {.u_obj = mp_const_none } }, + { MP_QSTR_cs, MP_ARG_OBJ, {.u_obj = mp_const_none } }, + { MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 8000000} }, + { MP_QSTR_sdio, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_int = 8000000} }, + }; + MP_STATIC_ASSERT( MP_ARRAY_SIZE(allowed_args) == NUM_ARGS ); + 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); + + busio_spi_obj_t *spi = validate_obj_is_spi_bus(args[ARG_spi].u_obj); + mcu_pin_obj_t *cs = validate_obj_is_free_pin(args[ARG_cs].u_obj); + + sdcardio_sdcard_obj_t *self = m_new_obj(sdcardio_sdcard_obj_t); + self->base.type = &sdcardio_SDCard_type; + + common_hal_sdcardio_sdcard_construct(self, spi, cs, args[ARG_baudrate].u_int); + + return self; +} + + +//| def count(self) -> int: +//| """Returns the total number of sectors +//| +//| Due to technical limitations, this is a function and not a property. +//| +//| :return: The number of 512-byte blocks, as a number""" +//| +mp_obj_t sdcardio_sdcard_count(mp_obj_t self_in) { + sdcardio_sdcard_obj_t *self = (sdcardio_sdcard_obj_t*)self_in; + return mp_obj_new_int_from_ull(common_hal_sdcardio_sdcard_get_blockcount(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(sdcardio_sdcard_count_obj, sdcardio_sdcard_count); + +//| def deinit(self) -> None: +//| """Disable permanently. +//| +//| :return: None""" +//| +mp_obj_t sdcardio_sdcard_deinit(mp_obj_t self_in) { + sdcardio_sdcard_obj_t *self = (sdcardio_sdcard_obj_t*)self_in; + common_hal_sdcardio_sdcard_deinit(self); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(sdcardio_sdcard_deinit_obj, sdcardio_sdcard_deinit); + + +//| def readblocks(self, start_block: int, buf: WriteableBuffer) -> None: +//| +//| """Read one or more blocks from the card +//| +//| :param int start_block: The block to start reading from +//| :param ~_typing.WriteableBuffer buf: The buffer to write into. Length must be multiple of 512. +//| +//| :return: None""" +//| + +mp_obj_t sdcardio_sdcard_readblocks(mp_obj_t self_in, mp_obj_t start_block_in, mp_obj_t buf_in) { + uint32_t start_block = mp_obj_get_int(start_block_in); + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_WRITE); + sdcardio_sdcard_obj_t *self = (sdcardio_sdcard_obj_t*)self_in; + int result = common_hal_sdcardio_sdcard_readblocks(self, start_block, &bufinfo); + if (result < 0) { + mp_raise_OSError(-result); + } + return mp_const_none; +} + +MP_DEFINE_CONST_FUN_OBJ_3(sdcardio_sdcard_readblocks_obj, sdcardio_sdcard_readblocks); + +//| def writeblocks(self, start_block: int, buf: ReadableBuffer) -> None: +//| +//| """Write one or more blocks to the card +//| +//| :param int start_block: The block to start writing from +//| :param ~_typing.ReadableBuffer buf: The buffer to read from. Length must be multiple of 512. +//| +//| :return: None""" +//| + +mp_obj_t sdcardio_sdcard_writeblocks(mp_obj_t self_in, mp_obj_t start_block_in, mp_obj_t buf_in) { + uint32_t start_block = mp_obj_get_int(start_block_in); + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ); + sdcardio_sdcard_obj_t *self = (sdcardio_sdcard_obj_t*)self_in; + int result = common_hal_sdcardio_sdcard_writeblocks(self, start_block, &bufinfo); + if (result < 0) { + mp_raise_OSError(-result); + } + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_3(sdcardio_sdcard_writeblocks_obj, sdcardio_sdcard_writeblocks); + +STATIC const mp_rom_map_elem_t sdcardio_sdcard_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_count), MP_ROM_PTR(&sdcardio_sdcard_count_obj) }, + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&sdcardio_sdcard_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&sdcardio_sdcard_readblocks_obj) }, + { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&sdcardio_sdcard_writeblocks_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(sdcardio_sdcard_locals_dict, sdcardio_sdcard_locals_dict_table); + +const mp_obj_type_t sdcardio_SDCard_type = { + { &mp_type_type }, + .name = MP_QSTR_SDCard, + .make_new = sdcardio_sdcard_make_new, + .locals_dict = (mp_obj_dict_t*)&sdcardio_sdcard_locals_dict, +}; diff --git a/shared-bindings/sdcardio/SDCard 2.h b/shared-bindings/sdcardio/SDCard 2.h new file mode 100644 index 0000000000..5986d5b814 --- /dev/null +++ b/shared-bindings/sdcardio/SDCard 2.h @@ -0,0 +1,30 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017, 2018 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2020 Jeff Epler 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. + */ + +#pragma once + +extern const mp_obj_type_t sdcardio_SDCard_type; diff --git a/shared-bindings/sdcardio/__init__ 2.c b/shared-bindings/sdcardio/__init__ 2.c new file mode 100644 index 0000000000..746aa5588e --- /dev/null +++ b/shared-bindings/sdcardio/__init__ 2.c @@ -0,0 +1,47 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Jeff Epler 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/obj.h" +#include "py/runtime.h" + +#include "shared-bindings/sdcardio/SDCard.h" + +//| """Interface to an SD card via the SPI bus""" + +STATIC const mp_rom_map_elem_t sdcardio_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sdcardio) }, + { MP_ROM_QSTR(MP_QSTR_SDCard), MP_ROM_PTR(&sdcardio_SDCard_type) }, +}; + +STATIC MP_DEFINE_CONST_DICT(sdcardio_module_globals, sdcardio_module_globals_table); + +const mp_obj_module_t sdcardio_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t*)&sdcardio_module_globals, +}; diff --git a/shared-bindings/sdcardio/__init__ 2.h b/shared-bindings/sdcardio/__init__ 2.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/shared-bindings/sdioio/SDCard 2.c b/shared-bindings/sdioio/SDCard 2.c new file mode 100644 index 0000000000..aba414cd63 --- /dev/null +++ b/shared-bindings/sdioio/SDCard 2.c @@ -0,0 +1,296 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Scott Shawcroft + * + * 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. + */ + +// This file contains all of the Python API definitions for the +// sdioio.SDCard class. + +#include + +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/sdioio/SDCard.h" +#include "shared-bindings/util.h" + +#include "lib/utils/buffer_helper.h" +#include "lib/utils/context_manager_helpers.h" +#include "py/mperrno.h" +#include "py/objproperty.h" +#include "py/runtime.h" +#include "supervisor/shared/translate.h" + +//| class SDCard: +//| """SD Card Block Interface with SDIO +//| +//| Controls an SD card over SDIO. SDIO is a parallel protocol designed +//| for SD cards. It uses a clock pin, a command pin, and 1 or 4 +//| data pins. It can be operated at a high frequency such as +//| 25MHz. Usually an SDCard object is used with ``storage.VfsFat`` +//| to allow file I/O to an SD card.""" +//| +//| def __init__(self, clock: microcontroller.Pin, command: microcontroller.Pin, data: Sequence[microcontroller.Pin], frequency: int) -> None: +//| """Construct an SDIO SD Card object with the given properties +//| +//| :param ~microcontroller.Pin clock: the pin to use for the clock. +//| :param ~microcontroller.Pin command: the pin to use for the command. +//| :param data: A sequence of pins to use for data. +//| :param frequency: The frequency of the bus in Hz +//| +//| Example usage: +//| +//| .. code-block:: python +//| +//| import os +//| +//| import board +//| import sdioio +//| import storage +//| +//| sd = sdioio.SDCard( +//| clock=board.SDIO_CLOCK, +//| command=board.SDIO_COMMAND, +//| data=board.SDIO_DATA, +//| frequency=25000000) +//| vfs = storage.VfsFat(sd) +//| storage.mount(vfs, '/sd') +//| os.listdir('/sd')""" +//| ... +//| + +STATIC mp_obj_t sdioio_sdcard_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + sdioio_sdcard_obj_t *self = m_new_obj(sdioio_sdcard_obj_t); + self->base.type = &sdioio_SDCard_type; + enum { ARG_clock, ARG_command, ARG_data, ARG_frequency, NUM_ARGS }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_clock, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_OBJ }, + { MP_QSTR_command, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_OBJ }, + { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_OBJ }, + { MP_QSTR_frequency, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_INT }, + }; + MP_STATIC_ASSERT( MP_ARRAY_SIZE(allowed_args) == NUM_ARGS ); + 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); + + const mcu_pin_obj_t* clock = validate_obj_is_free_pin(args[ARG_clock].u_obj); + const mcu_pin_obj_t* command = validate_obj_is_free_pin(args[ARG_command].u_obj); + mcu_pin_obj_t *data_pins[4]; + uint8_t num_data; + validate_list_is_free_pins(MP_QSTR_data, data_pins, MP_ARRAY_SIZE(data_pins), args[ARG_data].u_obj, &num_data); + + common_hal_sdioio_sdcard_construct(self, clock, command, num_data, data_pins, args[ARG_frequency].u_int); + return MP_OBJ_FROM_PTR(self); +} + +STATIC void check_for_deinit(sdioio_sdcard_obj_t *self) { + if (common_hal_sdioio_sdcard_deinited(self)) { + raise_deinited_error(); + } +} + +//| def configure(self, frequency: int = 0, width: int = 0) -> None: +//| """Configures the SDIO bus. +//| +//| :param int frequency: the desired clock rate in Hertz. The actual clock rate may be higher or lower due to the granularity of available clock settings. Check the `frequency` attribute for the actual clock rate. +//| :param int width: the number of data lines to use. Must be 1 or 4 and must also not exceed the number of data lines at construction +//| +//| .. note:: Leaving a value unspecified or 0 means the current setting is kept""" +//| +STATIC mp_obj_t sdioio_sdcard_configure(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_frequency, ARG_width, NUM_ARGS }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_frequency, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, + { MP_QSTR_width, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, + }; + sdioio_sdcard_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + check_for_deinit(self); + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + MP_STATIC_ASSERT( MP_ARRAY_SIZE(allowed_args) == NUM_ARGS ); + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + mp_int_t frequency = args[ARG_frequency].u_int; + if (frequency < 0) { + mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_baudrate); + } + + uint8_t width = args[ARG_width].u_int; + if (width != 0 && width != 1 && width != 4) { + mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_width); + } + + if (!common_hal_sdioio_sdcard_configure(self, frequency, width)) { + mp_raise_OSError(MP_EIO); + } + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_KW(sdioio_sdcard_configure_obj, 1, sdioio_sdcard_configure); + +//| def count(self) -> int: +//| """Returns the total number of sectors +//| +//| Due to technical limitations, this is a function and not a property. +//| +//| :return: The number of 512-byte blocks, as a number""" +//| +STATIC mp_obj_t sdioio_sdcard_count(mp_obj_t self_in) { + sdioio_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_sdioio_sdcard_get_count(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(sdioio_sdcard_count_obj, sdioio_sdcard_count); + +//| def readblocks(self, start_block: int, buf: WriteableBuffer) -> None: +//| +//| """Read one or more blocks from the card +//| +//| :param int start_block: The block to start reading from +//| :param ~_typing.WriteableBuffer buf: The buffer to write into. Length must be multiple of 512. +//| +//| :return: None""" +mp_obj_t sdioio_sdcard_readblocks(mp_obj_t self_in, mp_obj_t start_block_in, mp_obj_t buf_in) { + uint32_t start_block = mp_obj_get_int(start_block_in); + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_WRITE); + sdioio_sdcard_obj_t *self = (sdioio_sdcard_obj_t*)self_in; + int result = common_hal_sdioio_sdcard_readblocks(self, start_block, &bufinfo); + if (result < 0) { + mp_raise_OSError(-result); + } + return mp_const_none; +} + +MP_DEFINE_CONST_FUN_OBJ_3(sdioio_sdcard_readblocks_obj, sdioio_sdcard_readblocks); + +//| def writeblocks(self, start_block: int, buf: ReadableBuffer) -> None: +//| +//| """Write one or more blocks to the card +//| +//| :param int start_block: The block to start writing from +//| :param ~_typing.ReadableBuffer buf: The buffer to read from. Length must be multiple of 512. +//| +//| :return: None""" +//| +mp_obj_t sdioio_sdcard_writeblocks(mp_obj_t self_in, mp_obj_t start_block_in, mp_obj_t buf_in) { + uint32_t start_block = mp_obj_get_int(start_block_in); + mp_buffer_info_t bufinfo; + mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ); + sdioio_sdcard_obj_t *self = (sdioio_sdcard_obj_t*)self_in; + int result = common_hal_sdioio_sdcard_writeblocks(self, start_block, &bufinfo); + if (result < 0) { + mp_raise_OSError(-result); + } + return mp_const_none; +} + +MP_DEFINE_CONST_FUN_OBJ_3(sdioio_sdcard_writeblocks_obj, sdioio_sdcard_writeblocks); + +//| @property +//| def frequency(self) -> int: +//| """The actual SDIO bus frequency. This may not match the frequency +//| requested due to internal limitations.""" +//| ... +//| +STATIC mp_obj_t sdioio_sdcard_obj_get_frequency(mp_obj_t self_in) { + sdioio_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_sdioio_sdcard_get_frequency(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(sdioio_sdcard_get_frequency_obj, sdioio_sdcard_obj_get_frequency); + +const mp_obj_property_t sdioio_sdcard_frequency_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&sdioio_sdcard_get_frequency_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + +//| @property +//| def width(self) -> int: +//| """The actual SDIO bus width, in bits""" +//| ... +//| +STATIC mp_obj_t sdioio_sdcard_obj_get_width(mp_obj_t self_in) { + sdioio_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_sdioio_sdcard_get_width(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(sdioio_sdcard_get_width_obj, sdioio_sdcard_obj_get_width); + +const mp_obj_property_t sdioio_sdcard_width_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&sdioio_sdcard_get_width_obj, + (mp_obj_t)&mp_const_none_obj, + (mp_obj_t)&mp_const_none_obj}, +}; + +//| def deinit(self) -> None: +//| """Disable permanently. +//| +//| :return: None""" +STATIC mp_obj_t sdioio_sdcard_obj_deinit(mp_obj_t self_in) { + sdioio_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_sdioio_sdcard_deinit(self); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(sdioio_sdcard_deinit_obj, sdioio_sdcard_obj_deinit); + +//| def __enter__(self) -> SDCard: +//| """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 sdioio_sdcard_obj___exit__(size_t n_args, const mp_obj_t *args) { + (void)n_args; + common_hal_sdioio_sdcard_deinit(args[0]); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(sdioio_sdcard_obj___exit___obj, 4, 4, sdioio_sdcard_obj___exit__); + +STATIC const mp_rom_map_elem_t sdioio_sdcard_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&sdioio_sdcard_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&sdioio_sdcard_obj___exit___obj) }, + + { MP_ROM_QSTR(MP_QSTR_configure), MP_ROM_PTR(&sdioio_sdcard_configure_obj) }, + { MP_ROM_QSTR(MP_QSTR_frequency), MP_ROM_PTR(&sdioio_sdcard_frequency_obj) }, + { MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&sdioio_sdcard_width_obj) }, + + { MP_ROM_QSTR(MP_QSTR_count), MP_ROM_PTR(&sdioio_sdcard_count_obj) }, + { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&sdioio_sdcard_readblocks_obj) }, + { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&sdioio_sdcard_writeblocks_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(sdioio_sdcard_locals_dict, sdioio_sdcard_locals_dict_table); + +const mp_obj_type_t sdioio_SDCard_type = { + { &mp_type_type }, + .name = MP_QSTR_SDCard, + .make_new = sdioio_sdcard_make_new, + .locals_dict = (mp_obj_dict_t*)&sdioio_sdcard_locals_dict, +}; diff --git a/shared-bindings/sdioio/SDCard 2.h b/shared-bindings/sdioio/SDCard 2.h new file mode 100644 index 0000000000..7f62ee7a65 --- /dev/null +++ b/shared-bindings/sdioio/SDCard 2.h @@ -0,0 +1,66 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Scott Shawcroft + * + * 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_BUSIO_SDIO_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_SDIO_H + +#include "py/obj.h" + +#include "common-hal/microcontroller/Pin.h" +#include "common-hal/sdioio/SDCard.h" + +// Type object used in Python. Should be shared between ports. +extern const mp_obj_type_t sdioio_SDCard_type; + +// Construct an underlying SDIO object. +extern 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); + +extern void common_hal_sdioio_sdcard_deinit(sdioio_sdcard_obj_t *self); +extern bool common_hal_sdioio_sdcard_deinited(sdioio_sdcard_obj_t *self); + +extern bool common_hal_sdioio_sdcard_configure(sdioio_sdcard_obj_t *self, uint32_t baudrate, uint8_t width); + +extern void common_hal_sdioio_sdcard_unlock(sdioio_sdcard_obj_t *self); + +// Return actual SDIO bus frequency. +uint32_t common_hal_sdioio_sdcard_get_frequency(sdioio_sdcard_obj_t* self); + +// Return SDIO bus width. +uint8_t common_hal_sdioio_sdcard_get_width(sdioio_sdcard_obj_t* self); + +// Return number of device blocks +uint32_t common_hal_sdioio_sdcard_get_count(sdioio_sdcard_obj_t* self); + +// Read or write blocks +int common_hal_sdioio_sdcard_readblocks(sdioio_sdcard_obj_t* self, uint32_t start_block, mp_buffer_info_t *bufinfo); +int common_hal_sdioio_sdcard_writeblocks(sdioio_sdcard_obj_t* self, uint32_t start_block, mp_buffer_info_t *bufinfo); + +// This is used by the supervisor to claim SDIO devices indefinitely. +extern void common_hal_sdioio_sdcard_never_reset(sdioio_sdcard_obj_t *self); + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_SDIO_H diff --git a/shared-bindings/sdioio/__init__ 2.c b/shared-bindings/sdioio/__init__ 2.c new file mode 100644 index 0000000000..b88e5c3a96 --- /dev/null +++ b/shared-bindings/sdioio/__init__ 2.c @@ -0,0 +1,47 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Jeff Epler 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/obj.h" +#include "py/runtime.h" + +#include "shared-bindings/sdioio/SDCard.h" + +//| """Interface to an SD card via the SDIO bus""" + +STATIC const mp_rom_map_elem_t sdioio_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sdio) }, + { MP_ROM_QSTR(MP_QSTR_SDCard), MP_ROM_PTR(&sdioio_SDCard_type) }, +}; + +STATIC MP_DEFINE_CONST_DICT(sdioio_module_globals, sdioio_module_globals_table); + +const mp_obj_module_t sdioio_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t*)&sdioio_module_globals, +}; diff --git a/shared-bindings/sdioio/__init__ 2.h b/shared-bindings/sdioio/__init__ 2.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/shared-module/memorymonitor/AllocationAlarm 2.c b/shared-module/memorymonitor/AllocationAlarm 2.c new file mode 100644 index 0000000000..35f4e4c636 --- /dev/null +++ b/shared-module/memorymonitor/AllocationAlarm 2.c @@ -0,0 +1,94 @@ +/* + * This file is part of the Micro Python 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 "shared-bindings/memorymonitor/__init__.h" +#include "shared-bindings/memorymonitor/AllocationAlarm.h" + +#include "py/gc.h" +#include "py/mpstate.h" +#include "py/runtime.h" + +void common_hal_memorymonitor_allocationalarm_construct(memorymonitor_allocationalarm_obj_t* self, size_t minimum_block_count) { + self->minimum_block_count = minimum_block_count; + self->next = NULL; + self->previous = NULL; +} + +void common_hal_memorymonitor_allocationalarm_set_ignore(memorymonitor_allocationalarm_obj_t* self, mp_int_t count) { + self->count = count; +} + +void common_hal_memorymonitor_allocationalarm_pause(memorymonitor_allocationalarm_obj_t* self) { + // Check to make sure we aren't already paused. We can be if we're exiting from an exception we + // caused. + if (self->previous == NULL) { + return; + } + *self->previous = self->next; + self->next = NULL; + self->previous = NULL; +} + +void common_hal_memorymonitor_allocationalarm_resume(memorymonitor_allocationalarm_obj_t* self) { + if (self->previous != NULL) { + mp_raise_RuntimeError(translate("Already running")); + } + self->next = MP_STATE_VM(active_allocationalarms); + self->previous = (memorymonitor_allocationalarm_obj_t**) &MP_STATE_VM(active_allocationalarms); + if (self->next != NULL) { + self->next->previous = &self->next; + } + MP_STATE_VM(active_allocationalarms) = self; +} + +void memorymonitor_allocationalarms_allocation(size_t block_count) { + memorymonitor_allocationalarm_obj_t* alarm = MP_OBJ_TO_PTR(MP_STATE_VM(active_allocationalarms)); + size_t alert_count = 0; + while (alarm != NULL) { + // Hold onto next in case we remove the alarm from the list. + memorymonitor_allocationalarm_obj_t* next = alarm->next; + if (block_count >= alarm->minimum_block_count) { + if (alarm->count > 0) { + alarm->count--; + } else { + // Uncomment the breakpoint below if you want to use a C debugger to figure out the C + // call stack for an allocation. + // asm("bkpt"); + // Pause now because we may alert when throwing the exception too. + common_hal_memorymonitor_allocationalarm_pause(alarm); + alert_count++; + } + } + alarm = next; + } + if (alert_count > 0) { + mp_raise_memorymonitor_AllocationError(translate("Attempt to allocate %d blocks"), block_count); + } +} + +void memorymonitor_allocationalarms_reset(void) { + MP_STATE_VM(active_allocationalarms) = NULL; +} diff --git a/shared-module/memorymonitor/AllocationAlarm 2.h b/shared-module/memorymonitor/AllocationAlarm 2.h new file mode 100644 index 0000000000..172c24f6c8 --- /dev/null +++ b/shared-module/memorymonitor/AllocationAlarm 2.h @@ -0,0 +1,51 @@ +/* + * This file is part of the Micro Python 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. + */ + +#ifndef MICROPY_INCLUDED_SHARED_MODULE_MEMORYMONITOR_ALLOCATIONALARM_H +#define MICROPY_INCLUDED_SHARED_MODULE_MEMORYMONITOR_ALLOCATIONALARM_H + +#include +#include + +#include "py/obj.h" + +typedef struct _memorymonitor_allocationalarm_obj_t memorymonitor_allocationalarm_obj_t; + +#define ALLOCATION_SIZE_BUCKETS 16 + +typedef struct _memorymonitor_allocationalarm_obj_t { + mp_obj_base_t base; + size_t minimum_block_count; + mp_int_t count; + // Store the location that points to us so we can remove ourselves. + memorymonitor_allocationalarm_obj_t** previous; + memorymonitor_allocationalarm_obj_t* next; +} memorymonitor_allocationalarm_obj_t; + +void memorymonitor_allocationalarms_allocation(size_t block_count); +void memorymonitor_allocationalarms_reset(void); + +#endif // MICROPY_INCLUDED_SHARED_MODULE_MEMORYMONITOR_ALLOCATIONALARM_H diff --git a/shared-module/memorymonitor/AllocationSize 2.c b/shared-module/memorymonitor/AllocationSize 2.c new file mode 100644 index 0000000000..c28e65592c --- /dev/null +++ b/shared-module/memorymonitor/AllocationSize 2.c @@ -0,0 +1,91 @@ +/* + * This file is part of the Micro Python 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 "shared-bindings/memorymonitor/AllocationSize.h" + +#include "py/gc.h" +#include "py/mpstate.h" +#include "py/runtime.h" + +void common_hal_memorymonitor_allocationsize_construct(memorymonitor_allocationsize_obj_t* self) { + common_hal_memorymonitor_allocationsize_clear(self); + self->next = NULL; + self->previous = NULL; +} + +void common_hal_memorymonitor_allocationsize_pause(memorymonitor_allocationsize_obj_t* self) { + *self->previous = self->next; + self->next = NULL; + self->previous = NULL; +} + +void common_hal_memorymonitor_allocationsize_resume(memorymonitor_allocationsize_obj_t* self) { + if (self->previous != NULL) { + mp_raise_RuntimeError(translate("Already running")); + } + self->next = MP_STATE_VM(active_allocationsizes); + self->previous = (memorymonitor_allocationsize_obj_t**) &MP_STATE_VM(active_allocationsizes); + if (self->next != NULL) { + self->next->previous = &self->next; + } + MP_STATE_VM(active_allocationsizes) = self; +} + +void common_hal_memorymonitor_allocationsize_clear(memorymonitor_allocationsize_obj_t* self) { + for (size_t i = 0; i < ALLOCATION_SIZE_BUCKETS; i++) { + self->buckets[i] = 0; + } +} + +uint16_t common_hal_memorymonitor_allocationsize_get_len(memorymonitor_allocationsize_obj_t* self) { + return ALLOCATION_SIZE_BUCKETS; +} + +size_t common_hal_memorymonitor_allocationsize_get_bytes_per_block(memorymonitor_allocationsize_obj_t* self) { + return BYTES_PER_BLOCK; +} + +uint16_t common_hal_memorymonitor_allocationsize_get_item(memorymonitor_allocationsize_obj_t* self, int16_t index) { + return self->buckets[index]; +} + +void memorymonitor_allocationsizes_track_allocation(size_t block_count) { + memorymonitor_allocationsize_obj_t* as = MP_OBJ_TO_PTR(MP_STATE_VM(active_allocationsizes)); + size_t power_of_two = 0; + block_count >>= 1; + while (block_count != 0) { + power_of_two++; + block_count >>= 1; + } + while (as != NULL) { + as->buckets[power_of_two]++; + as = as->next; + } +} + +void memorymonitor_allocationsizes_reset(void) { + MP_STATE_VM(active_allocationsizes) = NULL; +} diff --git a/shared-module/memorymonitor/AllocationSize 2.h b/shared-module/memorymonitor/AllocationSize 2.h new file mode 100644 index 0000000000..3baab2213e --- /dev/null +++ b/shared-module/memorymonitor/AllocationSize 2.h @@ -0,0 +1,51 @@ +/* + * This file is part of the Micro Python 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. + */ + +#ifndef MICROPY_INCLUDED_SHARED_MODULE_MEMORYMONITOR_ALLOCATIONSIZE_H +#define MICROPY_INCLUDED_SHARED_MODULE_MEMORYMONITOR_ALLOCATIONSIZE_H + +#include +#include + +#include "py/obj.h" + +typedef struct _memorymonitor_allocationsize_obj_t memorymonitor_allocationsize_obj_t; + +#define ALLOCATION_SIZE_BUCKETS 16 + +typedef struct _memorymonitor_allocationsize_obj_t { + mp_obj_base_t base; + uint16_t buckets[ALLOCATION_SIZE_BUCKETS]; + // Store the location that points to us so we can remove ourselves. + memorymonitor_allocationsize_obj_t** previous; + memorymonitor_allocationsize_obj_t* next; + bool paused; +} memorymonitor_allocationsize_obj_t; + +void memorymonitor_allocationsizes_track_allocation(size_t block_count); +void memorymonitor_allocationsizes_reset(void); + +#endif // MICROPY_INCLUDED_SHARED_MODULE_MEMORYMONITOR_ALLOCATIONSIZE_H diff --git a/shared-module/memorymonitor/__init__ 2.c b/shared-module/memorymonitor/__init__ 2.c new file mode 100644 index 0000000000..6cb424153d --- /dev/null +++ b/shared-module/memorymonitor/__init__ 2.c @@ -0,0 +1,39 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Scott Shawcroft + * + * 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-module/memorymonitor/__init__.h" +#include "shared-module/memorymonitor/AllocationAlarm.h" +#include "shared-module/memorymonitor/AllocationSize.h" + +void memorymonitor_track_allocation(size_t block_count) { + memorymonitor_allocationalarms_allocation(block_count); + memorymonitor_allocationsizes_track_allocation(block_count); +} + +void memorymonitor_reset(void) { + memorymonitor_allocationalarms_reset(); + memorymonitor_allocationsizes_reset(); +} diff --git a/shared-module/memorymonitor/__init__ 2.h b/shared-module/memorymonitor/__init__ 2.h new file mode 100644 index 0000000000..f47f6434bf --- /dev/null +++ b/shared-module/memorymonitor/__init__ 2.h @@ -0,0 +1,35 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 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_MEMORYMONITOR___INIT___H +#define MICROPY_INCLUDED_MEMORYMONITOR___INIT___H + +#include + +void memorymonitor_track_allocation(size_t block_count); +void memorymonitor_reset(void); + +#endif // MICROPY_INCLUDED_MEMORYMONITOR___INIT___H diff --git a/shared-module/sdcardio/SDCard 2.c b/shared-module/sdcardio/SDCard 2.c new file mode 100644 index 0000000000..9e861279d3 --- /dev/null +++ b/shared-module/sdcardio/SDCard 2.c @@ -0,0 +1,466 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Jeff Epler 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. + */ + +// This implementation largely follows the structure of adafruit_sdcard.py + +#include "shared-bindings/busio/SPI.h" +#include "shared-bindings/digitalio/DigitalInOut.h" +#include "shared-bindings/time/__init__.h" +#include "shared-bindings/util.h" +#include "shared-module/sdcardio/SDCard.h" + +#include "py/mperrno.h" + +#if 0 +#define DEBUG_PRINT(...) ((void)mp_printf(&mp_plat_print, ## __VA_ARGS__)) +#else +#define DEBUG_PRINT(...) ((void)0) +#endif + +#define CMD_TIMEOUT (200) + +#define R1_IDLE_STATE (1<<0) +#define R1_ILLEGAL_COMMAND (1<<2) + +#define TOKEN_CMD25 (0xFC) +#define TOKEN_STOP_TRAN (0xFD) +#define TOKEN_DATA (0xFE) + +STATIC bool lock_and_configure_bus(sdcardio_sdcard_obj_t *self) { + if (!common_hal_busio_spi_try_lock(self->bus)) { + return false; + } + common_hal_busio_spi_configure(self->bus, self->baudrate, 0, 0, 8); + common_hal_digitalio_digitalinout_set_value(&self->cs, false); + return true; +} + +STATIC void lock_bus_or_throw(sdcardio_sdcard_obj_t *self) { + if (!lock_and_configure_bus(self)) { + mp_raise_OSError(EAGAIN); + } +} + +STATIC void clock_card(sdcardio_sdcard_obj_t *self, int bytes) { + uint8_t buf[] = {0xff}; + common_hal_digitalio_digitalinout_set_value(&self->cs, true); + for (int i=0; ibus, buf, 1); + } +} + +STATIC void extraclock_and_unlock_bus(sdcardio_sdcard_obj_t *self) { + clock_card(self, 1); + common_hal_busio_spi_unlock(self->bus); +} + +static uint8_t CRC7(const uint8_t* data, uint8_t n) { + uint8_t crc = 0; + for (uint8_t i = 0; i < n; i++) { + uint8_t d = data[i]; + for (uint8_t j = 0; j < 8; j++) { + crc <<= 1; + if ((d & 0x80) ^ (crc & 0x80)) { + crc ^= 0x09; + } + d <<= 1; + } + } + return (crc << 1) | 1; +} + +#define READY_TIMEOUT_NS (300 * 1000 * 1000) // 300ms +STATIC void wait_for_ready(sdcardio_sdcard_obj_t *self) { + uint64_t deadline = common_hal_time_monotonic_ns() + READY_TIMEOUT_NS; + while (common_hal_time_monotonic_ns() < deadline) { + uint8_t b; + common_hal_busio_spi_read(self->bus, &b, 1, 0xff); + if (b == 0xff) { + break; + } + } +} + +// In Python API, defaults are response=None, data_block=True, wait=True +STATIC int cmd(sdcardio_sdcard_obj_t *self, int cmd, int arg, void *response_buf, size_t response_len, bool data_block, bool wait) { + DEBUG_PRINT("cmd % 3d [%02x] arg=% 11d [%08x] len=%d%s%s\n", cmd, cmd, arg, arg, response_len, data_block ? " data" : "", wait ? " wait" : ""); + uint8_t cmdbuf[6]; + cmdbuf[0] = cmd | 0x40; + cmdbuf[1] = (arg >> 24) & 0xff; + cmdbuf[2] = (arg >> 16) & 0xff; + cmdbuf[3] = (arg >> 8) & 0xff; + cmdbuf[4] = arg & 0xff; + cmdbuf[5] = CRC7(cmdbuf, 5); + + if (wait) { + wait_for_ready(self); + } + + common_hal_busio_spi_write(self->bus, cmdbuf, sizeof(cmdbuf)); + + // Wait for the response (response[7] == 0) + bool response_received = false; + for (int i=0; ibus, cmdbuf, 1, 0xff); + if ((cmdbuf[0] & 0x80) == 0) { + response_received = true; + break; + } + } + + if (!response_received) { + return -EIO; + } + + if (response_buf) { + + if (data_block) { + cmdbuf[1] = 0xff; + do { + // Wait for the start block byte + common_hal_busio_spi_read(self->bus, cmdbuf+1, 1, 0xff); + } while (cmdbuf[1] != 0xfe); + } + + common_hal_busio_spi_read(self->bus, response_buf, response_len, 0xff); + + if (data_block) { + // Read and discard the CRC-CCITT checksum + common_hal_busio_spi_read(self->bus, cmdbuf+1, 2, 0xff); + } + + } + + return cmdbuf[0]; +} + +STATIC int block_cmd(sdcardio_sdcard_obj_t *self, int cmd_, int block, void *response_buf, size_t response_len, bool data_block, bool wait) { + return cmd(self, cmd_, block * self->cdv, response_buf, response_len, true, true); +} + +STATIC bool cmd_nodata(sdcardio_sdcard_obj_t* self, int cmd, int response) { + uint8_t cmdbuf[2] = {cmd, 0xff}; + + common_hal_busio_spi_write(self->bus, cmdbuf, sizeof(cmdbuf)); + + // Wait for the response (response[7] == response) + for (int i=0; ibus, cmdbuf, 1, 0xff); + if (cmdbuf[0] == response) { + return 0; + } + } + return -EIO; +} + +STATIC const compressed_string_t *init_card_v1(sdcardio_sdcard_obj_t *self) { + for (int i=0; icdv = 1; + } + return NULL; + } + } + return translate("timeout waiting for v2 card"); +} + +STATIC const compressed_string_t *init_card(sdcardio_sdcard_obj_t *self) { + clock_card(self, 10); + + common_hal_digitalio_digitalinout_set_value(&self->cs, false); + + // CMD0: init card: should return _R1_IDLE_STATE (allow 5 attempts) + { + bool reached_idle_state = false; + for (int i=0; i<5; i++) { + if (cmd(self, 0, 0, NULL, 0, true, true) == R1_IDLE_STATE) { + reached_idle_state = true; + break; + } + } + if (!reached_idle_state) { + return translate("no SD card"); + } + } + + // CMD8: determine card version + { + uint8_t rb7[4]; + int response = cmd(self, 8, 0x1AA, rb7, sizeof(rb7), false, true); + if (response == R1_IDLE_STATE) { + const compressed_string_t *result =init_card_v2(self); + if (result != NULL) { + return result; + } + } else if (response == (R1_IDLE_STATE | R1_ILLEGAL_COMMAND)) { + const compressed_string_t *result =init_card_v1(self); + if (result != NULL) { + return result; + } + } else { + return translate("couldn't determine SD card version"); + } + } + + // CMD9: get number of sectors + { + uint8_t csd[16]; + int response = cmd(self, 9, 0, csd, sizeof(csd), true, true); + if (response != 0) { + return translate("no response from SD card"); + } + int csd_version = (csd[0] & 0xC0) >> 6; + if (csd_version >= 2) { + return translate("SD card CSD format not supported"); + } + + if (csd_version == 1) { + self->sectors = ((csd[8] << 8 | csd[9]) + 1) * 1024; + } else { + uint32_t block_length = 1 << (csd[5] & 0xF); + uint32_t c_size = ((csd[6] & 0x3) << 10) | (csd[7] << 2) | ((csd[8] & 0xC) >> 6); + uint32_t mult = 1 << (((csd[9] & 0x3) << 1 | (csd[10] & 0x80) >> 7) + 2); + self->sectors = block_length / 512 * mult * (c_size + 1); + } + } + + // CMD16: set block length to 512 bytes + { + int response = cmd(self, 16, 512, NULL, 0, true, true); + if (response != 0) { + return translate("can't set 512 block size"); + } + } + + return NULL; +} + +void common_hal_sdcardio_sdcard_construct(sdcardio_sdcard_obj_t *self, busio_spi_obj_t *bus, mcu_pin_obj_t *cs, int baudrate) { + self->bus = bus; + common_hal_digitalio_digitalinout_construct(&self->cs, cs); + common_hal_digitalio_digitalinout_switch_to_output(&self->cs, true, DRIVE_MODE_PUSH_PULL); + + self->cdv = 512; + self->sectors = 0; + self->baudrate = 250000; + + lock_bus_or_throw(self); + const compressed_string_t *result = init_card(self); + extraclock_and_unlock_bus(self); + + if (result != NULL) { + common_hal_digitalio_digitalinout_deinit(&self->cs); + mp_raise_OSError_msg(result); + } + + self->baudrate = baudrate; +} + +void common_hal_sdcardio_sdcard_deinit(sdcardio_sdcard_obj_t *self) { + if (!self->bus) { + return; + } + self->bus = 0; + common_hal_digitalio_digitalinout_deinit(&self->cs); +} + +void common_hal_sdcardio_check_for_deinit(sdcardio_sdcard_obj_t *self) { + if (!self->bus) { + raise_deinited_error(); + } +} + +int common_hal_sdcardio_sdcard_get_blockcount(sdcardio_sdcard_obj_t *self) { + common_hal_sdcardio_check_for_deinit(self); + return self->sectors; +} + +int readinto(sdcardio_sdcard_obj_t *self, void *buf, size_t size) { + uint8_t aux[2] = {0, 0}; + while (aux[0] != 0xfe) { + common_hal_busio_spi_read(self->bus, aux, 1, 0xff); + } + + common_hal_busio_spi_read(self->bus, buf, size, 0xff); + + // Read checksum and throw it away + common_hal_busio_spi_read(self->bus, aux, sizeof(aux), 0xff); + return 0; +} + +int readblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf) { + uint32_t nblocks = buf->len / 512; + if (nblocks == 1) { + // Use CMD17 to read a single block + return block_cmd(self, 17, start_block, buf->buf, buf->len, true, true); + } else { + // Use CMD18 to read multiple blocks + int r = block_cmd(self, 18, start_block, NULL, 0, true, true); + if (r < 0) { + return r; + } + + uint8_t *ptr = buf->buf; + while (nblocks--) { + r = readinto(self, ptr, 512); + if (r < 0) { + return r; + } + ptr += 512; + } + + // End the multi-block read + r = cmd(self, 12, 0, NULL, 0, true, false); + + // Return first status 0 or last before card ready (0xff) + while (r != 0) { + uint8_t single_byte; + common_hal_busio_spi_read(self->bus, &single_byte, 1, 0xff); + if (single_byte & 0x80) { + return r; + } + r = single_byte; + } + } + return 0; +} + +int common_hal_sdcardio_sdcard_readblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf) { + common_hal_sdcardio_check_for_deinit(self); + if (buf->len % 512 != 0) { + mp_raise_ValueError(translate("Buffer length must be a multiple of 512")); + } + + lock_and_configure_bus(self); + int r = readblocks(self, start_block, buf); + extraclock_and_unlock_bus(self); + return r; +} + +int _write(sdcardio_sdcard_obj_t *self, uint8_t token, void *buf, size_t size) { + wait_for_ready(self); + + uint8_t cmd[2]; + cmd[0] = token; + + common_hal_busio_spi_write(self->bus, cmd, 1); + common_hal_busio_spi_write(self->bus, buf, size); + + cmd[0] = cmd[1] = 0xff; + common_hal_busio_spi_write(self->bus, cmd, 2); + + // Check the response + // This differs from the traditional adafruit_sdcard handling, + // but adafruit_sdcard also ignored the return value of SDCard._write(!) + // so nobody noticed + // + // + // Response is as follows: + // x x x 0 STAT 1 + // 7 6 5 4 3..1 0 + // with STATUS 010 indicating "data accepted", and other status bit + // combinations indicating failure. + // In practice, I was seeing cmd[0] as 0xe5, indicating success + for (int i=0; ibus, cmd, 1, 0xff); + DEBUG_PRINT("i=%02d cmd[0] = 0x%02x\n", i, cmd[0]); + if ((cmd[0] & 0b00010001) == 0b00000001) { + if ((cmd[0] & 0x1f) != 0x5) { + return -EIO; + } else { + break; + } + } + } + + // Wait for the write to finish + do { + common_hal_busio_spi_read(self->bus, cmd, 1, 0xff); + } while (cmd[0] == 0); + + // Success + return 0; +} + +int writeblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf) { + common_hal_sdcardio_check_for_deinit(self); + uint32_t nblocks = buf->len / 512; + if (nblocks == 1) { + // Use CMD24 to write a single block + int r = block_cmd(self, 24, start_block, NULL, 0, true, true); + if (r < 0) { + return r; + } + r = _write(self, TOKEN_DATA, buf->buf, buf->len); + if (r < 0) { + return r; + } + } else { + // Use CMD25 to write multiple block + int r = block_cmd(self, 25, start_block, NULL, 0, true, true); + if (r < 0) { + return r; + } + + uint8_t *ptr = buf->buf; + while (nblocks--) { + r = _write(self, TOKEN_CMD25, ptr, 512); + if (r < 0) { + return r; + } + ptr += 512; + } + + cmd_nodata(self, TOKEN_STOP_TRAN, 0); + } + return 0; +} + +int common_hal_sdcardio_sdcard_writeblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf) { + common_hal_sdcardio_check_for_deinit(self); + if (buf->len % 512 != 0) { + mp_raise_ValueError(translate("Buffer length must be a multiple of 512")); + } + lock_and_configure_bus(self); + int r = writeblocks(self, start_block, buf); + extraclock_and_unlock_bus(self); + return r; +} diff --git a/shared-module/sdcardio/SDCard 2.h b/shared-module/sdcardio/SDCard 2.h new file mode 100644 index 0000000000..76c906029f --- /dev/null +++ b/shared-module/sdcardio/SDCard 2.h @@ -0,0 +1,51 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Jeff Epler 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. + */ + +#pragma once + +#include "py/obj.h" +#include "py/objproperty.h" +#include "py/runtime.h" +#include "py/objarray.h" + +#include "common-hal/busio/SPI.h" +#include "common-hal/digitalio/DigitalInOut.h" + +typedef struct { + mp_obj_base_t base; + busio_spi_obj_t *bus; + digitalio_digitalinout_obj_t cs; + int cdv; + int baudrate; + uint32_t sectors; +} sdcardio_sdcard_obj_t; + +void common_hal_sdcardio_sdcard_construct(sdcardio_sdcard_obj_t *self, busio_spi_obj_t *spi, mcu_pin_obj_t *cs, int baudrate); +void common_hal_sdcardio_sdcard_deinit(sdcardio_sdcard_obj_t *self); +void common_hal_sdcardio_sdcard_check_for_deinit(sdcardio_sdcard_obj_t *self); +int common_hal_sdcardio_sdcard_get_blockcount(sdcardio_sdcard_obj_t *self); +int common_hal_sdcardio_sdcard_readblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf); +int common_hal_sdcardio_sdcard_writeblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf); diff --git a/shared-module/sdcardio/__init__ 2.c b/shared-module/sdcardio/__init__ 2.c new file mode 100644 index 0000000000..e69de29bb2 diff --git a/shared-module/sdcardio/__init__ 2.h b/shared-module/sdcardio/__init__ 2.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/supervisor/background_callback 2.h b/supervisor/background_callback 2.h new file mode 100644 index 0000000000..535dd656be --- /dev/null +++ b/supervisor/background_callback 2.h @@ -0,0 +1,87 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Jeff Epler 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 CIRCUITPY_INCLUDED_SUPERVISOR_BACKGROUND_CALLBACK_H +#define CIRCUITPY_INCLUDED_SUPERVISOR_BACKGROUND_CALLBACK_H + +/** Background callbacks are a linked list of tasks to call in the background. + * + * Include a member of type `background_callback_t` inside an object + * which needs to queue up background work, and zero-initialize it. + * + * To schedule the work, use background_callback_add, with fun as the + * function to call and data pointing to the object itself. + * + * Next time run_background_tasks_if_tick is called, the callback will + * be run and removed from the linked list. + * + * Queueing a task that is already queued does nothing. Unconditionally + * re-queueing it from its own background task will cause it to run during the + * very next background-tasks invocation, leading to a CircuitPython freeze, so + * don't do that. + * + * background_callback_add can be called from interrupt context. + */ +typedef void (*background_callback_fun)(void *data); +typedef struct background_callback { + background_callback_fun fun; + void *data; + struct background_callback *next; + struct background_callback *prev; +} background_callback_t; + +/* Add a background callback for which 'fun' and 'data' were previously set */ +void background_callback_add_core(background_callback_t *cb); + +/* Add a background callback to the given function with the given data. When + * the callback involves an object on the GC heap, the 'data' must be a pointer + * to that object itself, not an internal pointer. Otherwise, it can be the + * case that no other references to the object itself survive, and the object + * becomes garbage collected while an outstanding background callback still + * exists. + */ +void background_callback_add(background_callback_t *cb, background_callback_fun fun, void *data); + +/* Run all background callbacks. Normally, this is done by the supervisor + * whenever the list is non-empty */ +void background_callback_run_all(void); + +/* During soft reset, remove all pending callbacks and clear the critical section flag */ +void background_callback_reset(void); + +/* Sometimes background callbacks must be blocked. Use these functions to + * bracket the section of code where this is the case. These calls nest, and + * begins must be balanced with ends. + */ +void background_callback_begin_critical_section(void); +void background_callback_end_critical_section(void); + +/* + * Background callbacks may stop objects from being collected + */ +void background_callback_gc_collect(void); + +#endif diff --git a/supervisor/shared/background_callback 2.c b/supervisor/shared/background_callback 2.c new file mode 100644 index 0000000000..8e12dd3625 --- /dev/null +++ b/supervisor/shared/background_callback 2.c @@ -0,0 +1,138 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Jeff Epler 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/gc.h" +#include "py/mpconfig.h" +#include "supervisor/background_callback.h" +#include "supervisor/shared/tick.h" +#include "shared-bindings/microcontroller/__init__.h" + +STATIC volatile background_callback_t *callback_head, *callback_tail; + +#define CALLBACK_CRITICAL_BEGIN (common_hal_mcu_disable_interrupts()) +#define CALLBACK_CRITICAL_END (common_hal_mcu_enable_interrupts()) + +void background_callback_add_core(background_callback_t *cb) { + CALLBACK_CRITICAL_BEGIN; + if (cb->prev || callback_head == cb) { + CALLBACK_CRITICAL_END; + return; + } + cb->next = 0; + cb->prev = (background_callback_t*)callback_tail; + if (callback_tail) { + callback_tail->next = cb; + cb->prev = (background_callback_t*)callback_tail; + } + if (!callback_head) { + callback_head = cb; + } + callback_tail = cb; + CALLBACK_CRITICAL_END; +} + +void background_callback_add(background_callback_t *cb, background_callback_fun fun, void *data) { + cb->fun = fun; + cb->data = data; + background_callback_add_core(cb); +} + +static bool in_background_callback; +void background_callback_run_all() { + if (!callback_head) { + return; + } + CALLBACK_CRITICAL_BEGIN; + if (in_background_callback) { + CALLBACK_CRITICAL_END; + return; + } + in_background_callback = true; + background_callback_t *cb = (background_callback_t*)callback_head; + callback_head = NULL; + callback_tail = NULL; + while (cb) { + background_callback_t *next = cb->next; + cb->next = cb->prev = NULL; + background_callback_fun fun = cb->fun; + void *data = cb->data; + CALLBACK_CRITICAL_END; + // Leave the critical section in order to run the callback function + if (fun) { + fun(data); + } + CALLBACK_CRITICAL_BEGIN; + cb = next; + } + in_background_callback = false; + CALLBACK_CRITICAL_END; +} + +void background_callback_begin_critical_section() { + CALLBACK_CRITICAL_BEGIN; +} + +void background_callback_end_critical_section() { + CALLBACK_CRITICAL_END; +} + +void background_callback_reset() { + CALLBACK_CRITICAL_BEGIN; + background_callback_t *cb = (background_callback_t*)callback_head; + while(cb) { + background_callback_t *next = cb->next; + memset(cb, 0, sizeof(*cb)); + cb = next; + } + callback_head = NULL; + callback_tail = NULL; + in_background_callback = false; + CALLBACK_CRITICAL_END; +} + +void background_callback_gc_collect(void) { + // We don't enter the callback critical section here. We rely on + // gc_collect_ptr _NOT_ entering background callbacks, so it is not + // possible for the list to be cleared. + // + // However, it is possible for the list to be extended. We make the + // minor assumption that no newly added callback is for a + // collectable object. That is, we only plug the hole where an + // object becomes collectable AFTER it is added but before the + // callback is run, not the hole where an object was ALREADY + // collectable but adds a background task for itself. + // + // It's necessary to traverse the whole list here, as the callbacks + // themselves can be in non-gc memory, and some of the cb->data + // objects themselves might be in non-gc memory. + background_callback_t *cb = (background_callback_t*)callback_head; + while(cb) { + gc_collect_ptr(cb->data); + cb = cb->next; + } +} From 4ba9ff892c2176d4aeefe1a8287cdb899acf5da1 Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Mon, 10 Aug 2020 11:04:56 -0500 Subject: [PATCH 08/79] Added bitmap.blit function for copying slices of bitmaps --- shared-bindings/displayio/Bitmap.c | 62 +++++++++++++++++++++++++++++- shared-bindings/displayio/Bitmap.h | 2 + shared-module/displayio/Bitmap.c | 31 +++++++++++++++ 3 files changed, 94 insertions(+), 1 deletion(-) diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index 0a45bbdfdb..56c6007f05 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -172,7 +172,66 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val return mp_const_none; } -//| def fill(self, value: int) -> None: +//| def blit(self, x: int, y: int, source_bitmap: bitmap, x1: int, y1: int, x2: int, y2:int) -> Any: +//| """Inserts the source_bitmap region defined by rectangular boundaries +//| (x1,y1) and (x2,y2) into the bitmap at the specified (x,y) location. +//| :param int x: Horizontal pixel location in bitmap where source_bitmap upper-left +//| corner will be placed +//| :param int y: Vertical pixel location in bitmap where source_bitmap upper-left +//| corner will be placed +//| :param bitmap source_bitmap: Source bitmap that contains the graphical region to be copied +//| : param x1: Minimum x-value for rectangular bounding box to be copied from the source bitmap +//| : param y1: Minimum y-value for rectangular bounding box to be copied from the source bitmap +//| : param x2: Maximum x-value for rectangular bounding box to be copied from the source bitmap +//| : param y2: Maximum y-value for rectangular bounding box to be copied from the source bitmap +//| +//| ... +//| + +STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args){ + + // Consider improving the input checking. + + displayio_bitmap_t *self = MP_OBJ_TO_PTR(pos_args[0]); + int16_t x = mp_obj_get_int(pos_args[1]); + int16_t y = mp_obj_get_int(pos_args[2]); + displayio_bitmap_t *source = MP_OBJ_TO_PTR(pos_args[3]); + int16_t x1 = mp_obj_get_int(pos_args[4]); + int16_t y1 = mp_obj_get_int(pos_args[5]); + int16_t x2 = mp_obj_get_int(pos_args[6]); + int16_t y2 = mp_obj_get_int(pos_args[7]); + + if ( (x<0) || (y<0) || (x > self-> width) || (y > self->height) ) { + mp_raise_ValueError(translate("(x,y): out of range of target bitmap")); + } + if ( (x1 < 0) || (x1 > source->width) || + (y1 < 0) || (y1 > source->height) || + (x2 < 0) || (x2 > source->width) || + (y2 < 0) || (y2 > source->height) ) { + mp_raise_ValueError(translate("(x1,y1) or (x2,y2): out of range of source bitmap")); + } + + // Ensure x1 < x2 and y1 < y2 + if (x1 > x2) { + int16_t temp=x2; + x2=x1; + x1=temp; + } + if (y1 > y2) { + int16_t temp=y2; + y2=y1; + y1=temp; + } + + common_hal_displayio_bitmap_blit(self, x, y, source, x1, y1, x2, y2); + + return mp_const_none; +} + +MP_DEFINE_CONST_FUN_OBJ_KW(displayio_bitmap_blit_obj, 8, displayio_bitmap_obj_blit); +// requires 8 parameters + +//| def fill(self, value: Any) -> Any: //| """Fills the bitmap with the supplied palette index value.""" //| ... //| @@ -192,6 +251,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(displayio_bitmap_fill_obj, displayio_bitmap_obj_fill); STATIC const mp_rom_map_elem_t displayio_bitmap_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&displayio_bitmap_height_obj) }, { MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&displayio_bitmap_width_obj) }, + { MP_ROM_QSTR(MP_QSTR_blit), MP_ROM_PTR(&displayio_bitmap_blit_obj) }, { MP_ROM_QSTR(MP_QSTR_fill), MP_ROM_PTR(&displayio_bitmap_fill_obj) }, }; diff --git a/shared-bindings/displayio/Bitmap.h b/shared-bindings/displayio/Bitmap.h index 46c3373292..8225af6c6a 100644 --- a/shared-bindings/displayio/Bitmap.h +++ b/shared-bindings/displayio/Bitmap.h @@ -40,6 +40,8 @@ uint16_t common_hal_displayio_bitmap_get_height(displayio_bitmap_t *self); uint16_t common_hal_displayio_bitmap_get_width(displayio_bitmap_t *self); uint32_t common_hal_displayio_bitmap_get_bits_per_value(displayio_bitmap_t *self); void common_hal_displayio_bitmap_set_pixel(displayio_bitmap_t *bitmap, int16_t x, int16_t y, uint32_t value); +void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16_t y, displayio_bitmap_t *source, + int16_t x1, int16_t y1, int16_t x2, int16_t y2); uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *bitmap, int16_t x, int16_t y); void common_hal_displayio_bitmap_fill(displayio_bitmap_t *bitmap, uint32_t value); diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c index 8bcda6086f..dde346ad31 100644 --- a/shared-module/displayio/Bitmap.c +++ b/shared-module/displayio/Bitmap.c @@ -105,6 +105,37 @@ uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *self, int16_t return 0; } +void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16_t y, displayio_bitmap_t *source, + int16_t x1, int16_t y1, int16_t x2, int16_t y2) { + // Copy complete "source" bitmap into "self" bitmap at location x,y in the "self" + // Add a boolean to determine if all values are copied, or only if non-zero + // Default is copy all values, but for text glyphs this should copy only non-zero values + + if (self->read_only) { + mp_raise_RuntimeError(translate("Read-only object")); + } + + // If this value is encountered in the source bitmap, it will not be copied (for text glyphs) + // This should be added as an optional parameter, and if it is `None`, then all pixels are copied + uint32_t skip_value=0; + + // simplest version - use internal functions for get/set pixels + for (uint16_t i=0; i<= (x2-x1) ; i++) { + if ( (x+i >= 0) && (x+i < self->width) ) { + for (uint16_t j=0; j<= (y2-y1) ; j++){ + if ((y+j >= 0) && (y+j < self->height) ) { + uint32_t value = common_hal_displayio_bitmap_get_pixel(source, x1+i, y1+j); + if ( (value != skip_value) ) { + common_hal_displayio_bitmap_set_pixel(self, x+i, y+j, value); + } + } + } + } + } + +} + + void common_hal_displayio_bitmap_set_pixel(displayio_bitmap_t *self, int16_t x, int16_t y, uint32_t value) { if (self->read_only) { mp_raise_RuntimeError(translate("Read-only object")); From 824f47d6e99d85b2b604db524c9e9178e0a99ceb Mon Sep 17 00:00:00 2001 From: Margaret Matocha Date: Wed, 12 Aug 2020 21:50:17 -0500 Subject: [PATCH 09/79] Added bitmap.blit function for bitmap slice copy --- shared-bindings/displayio/Bitmap.c | 98 ++++++++++++++++++++++-------- shared-bindings/displayio/Bitmap.h | 3 +- shared-module/displayio/Bitmap.c | 16 +++-- 3 files changed, 83 insertions(+), 34 deletions(-) diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index 56c6007f05..af9f6c3c8b 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -172,7 +172,7 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val return mp_const_none; } -//| def blit(self, x: int, y: int, source_bitmap: bitmap, x1: int, y1: int, x2: int, y2:int) -> Any: +//| def blit(self, x: int, y: int, source_bitmap: bitmap, x1: int, y1: int, x2: int, y2: int, skip_index: int) -> Any: //| """Inserts the source_bitmap region defined by rectangular boundaries //| (x1,y1) and (x2,y2) into the bitmap at the specified (x,y) location. //| :param int x: Horizontal pixel location in bitmap where source_bitmap upper-left @@ -180,34 +180,74 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val //| :param int y: Vertical pixel location in bitmap where source_bitmap upper-left //| corner will be placed //| :param bitmap source_bitmap: Source bitmap that contains the graphical region to be copied -//| : param x1: Minimum x-value for rectangular bounding box to be copied from the source bitmap -//| : param y1: Minimum y-value for rectangular bounding box to be copied from the source bitmap -//| : param x2: Maximum x-value for rectangular bounding box to be copied from the source bitmap -//| : param y2: Maximum y-value for rectangular bounding box to be copied from the source bitmap -//| +//| : param int x1: Minimum x-value for rectangular bounding box to be copied from the source bitmap +//| : param int y1: Minimum y-value for rectangular bounding box to be copied from the source bitmap +//| : param int x2: Maximum x-value for rectangular bounding box to be copied from the source bitmap +//| : param int y2: Maximum y-value for rectangular bounding box to be copied from the source bitmap +//| : param int skip_index: bitmap palette index in the source that will not be copied, set `None` to copy all pixels //| ... //| STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args){ + enum {ARG_x, ARG_y, ARG_source, ARG_x1, ARG_y1, ARG_x2, ARG_y2, ARG_skip_index}; + static const mp_arg_t allowed_args[] = { + {MP_QSTR_x, MP_ARG_REQUIRED | MP_ARG_INT}, + {MP_QSTR_y, MP_ARG_REQUIRED | MP_ARG_INT}, + {MP_QSTR_source, MP_ARG_REQUIRED | MP_ARG_OBJ}, + {MP_QSTR_x1, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, + {MP_QSTR_y1, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, + {MP_QSTR_x2, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, // None convert to source->width + {MP_QSTR_y2, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, // None convert to source->height + {MP_QSTR_skip_index, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj=mp_const_none} }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - // Consider improving the input checking. + displayio_bitmap_t *self = MP_OBJ_TO_PTR(pos_args[0]); //******* - displayio_bitmap_t *self = MP_OBJ_TO_PTR(pos_args[0]); - int16_t x = mp_obj_get_int(pos_args[1]); - int16_t y = mp_obj_get_int(pos_args[2]); - displayio_bitmap_t *source = MP_OBJ_TO_PTR(pos_args[3]); - int16_t x1 = mp_obj_get_int(pos_args[4]); - int16_t y1 = mp_obj_get_int(pos_args[5]); - int16_t x2 = mp_obj_get_int(pos_args[6]); - int16_t y2 = mp_obj_get_int(pos_args[7]); + int16_t x = args[ARG_x].u_int; + int16_t y = args[ARG_y].u_int; - if ( (x<0) || (y<0) || (x > self-> width) || (y > self->height) ) { + displayio_bitmap_t *source = MP_OBJ_TO_PTR(args[ARG_source].u_obj); + + int16_t x1, y1; + // if x1 or y1 is None, then set as the zero-point of the bitmap + if ( args[ARG_x1].u_obj == mp_const_none ) { + x1 = 0; + } else { + x1 = mp_obj_get_int(args[ARG_x1].u_obj); + } + //int16_t y1; + if ( args[ARG_y1].u_obj == mp_const_none ) { + y1 = 0; + } else { + y1 = mp_obj_get_int(args[ARG_y1].u_obj); + } + + int16_t x2, y2; + // if x2 or y2 is None, then set as the maximum size of the source bitmap + if ( args[ARG_x2].u_obj == mp_const_none ) { + x2 = source->width-1; + } else { + x2 = mp_obj_get_int(args[ARG_x2].u_obj); + } + //int16_t y2; + if ( args[ARG_y2].u_obj == mp_const_none ) { + y2 = source->height-1; + } else { + y2 = mp_obj_get_int(args[ARG_y2].u_obj); + } + + + // Check x,y are within self (target) bitmap boundary + if ( (x < 0) || (y < 0) || (x >= self->width) || (y >= self->height) ) { mp_raise_ValueError(translate("(x,y): out of range of target bitmap")); } - if ( (x1 < 0) || (x1 > source->width) || - (y1 < 0) || (y1 > source->height) || - (x2 < 0) || (x2 > source->width) || - (y2 < 0) || (y2 > source->height) ) { + // Check x1,y1,x2,y2 are within source bitmap boundary + if ( (x1 < 0) || (x1 >= source->width) || + (y1 < 0) || (y1 >= source->height) || + (x2 < 0) || (x2 >= source->width) || + (y2 < 0) || (y2 >= source->height) ) { mp_raise_ValueError(translate("(x1,y1) or (x2,y2): out of range of source bitmap")); } @@ -223,13 +263,23 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg y1=temp; } - common_hal_displayio_bitmap_blit(self, x, y, source, x1, y1, x2, y2); + uint32_t skip_index; + bool skip_index_none; // flag whether skip_value was None + + if (args[ARG_skip_index].u_obj == mp_const_none ) { + skip_index = 0; + skip_index_none = true; + } else { + skip_index = mp_obj_get_int(args[ARG_skip_index].u_obj); + skip_index_none = false; + } + + common_hal_displayio_bitmap_blit(self, x, y, source, x1, y1, x2, y2, skip_index, skip_index_none); return mp_const_none; } - -MP_DEFINE_CONST_FUN_OBJ_KW(displayio_bitmap_blit_obj, 8, displayio_bitmap_obj_blit); -// requires 8 parameters +MP_DEFINE_CONST_FUN_OBJ_KW(displayio_bitmap_blit_obj, 4, displayio_bitmap_obj_blit); +// `displayio_bitmap_obj_blit` requires at least 4 arguments //| def fill(self, value: Any) -> Any: //| """Fills the bitmap with the supplied palette index value.""" diff --git a/shared-bindings/displayio/Bitmap.h b/shared-bindings/displayio/Bitmap.h index 8225af6c6a..cf75f3d764 100644 --- a/shared-bindings/displayio/Bitmap.h +++ b/shared-bindings/displayio/Bitmap.h @@ -41,7 +41,8 @@ uint16_t common_hal_displayio_bitmap_get_width(displayio_bitmap_t *self); uint32_t common_hal_displayio_bitmap_get_bits_per_value(displayio_bitmap_t *self); void common_hal_displayio_bitmap_set_pixel(displayio_bitmap_t *bitmap, int16_t x, int16_t y, uint32_t value); void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16_t y, displayio_bitmap_t *source, - int16_t x1, int16_t y1, int16_t x2, int16_t y2); + int16_t x1, int16_t y1, int16_t x2, int16_t y2, + uint32_t skip_index, bool skip_index_none); uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *bitmap, int16_t x, int16_t y); void common_hal_displayio_bitmap_fill(displayio_bitmap_t *bitmap, uint32_t value); diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c index dde346ad31..dbcba6b583 100644 --- a/shared-module/displayio/Bitmap.c +++ b/shared-module/displayio/Bitmap.c @@ -106,26 +106,24 @@ uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *self, int16_t } void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16_t y, displayio_bitmap_t *source, - int16_t x1, int16_t y1, int16_t x2, int16_t y2) { + int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint32_t skip_index, bool skip_index_none) { // Copy complete "source" bitmap into "self" bitmap at location x,y in the "self" // Add a boolean to determine if all values are copied, or only if non-zero - // Default is copy all values, but for text glyphs this should copy only non-zero values + // + // If skip_value is encountered in the source bitmap, it will not be copied. + // If skip_value is `None`, then all pixels are copied. if (self->read_only) { mp_raise_RuntimeError(translate("Read-only object")); } - // If this value is encountered in the source bitmap, it will not be copied (for text glyphs) - // This should be added as an optional parameter, and if it is `None`, then all pixels are copied - uint32_t skip_value=0; - // simplest version - use internal functions for get/set pixels - for (uint16_t i=0; i<= (x2-x1) ; i++) { + for (int16_t i=0; i<= (x2-x1) ; i++) { if ( (x+i >= 0) && (x+i < self->width) ) { - for (uint16_t j=0; j<= (y2-y1) ; j++){ + for (int16_t j=0; j<= (y2-y1) ; j++){ if ((y+j >= 0) && (y+j < self->height) ) { uint32_t value = common_hal_displayio_bitmap_get_pixel(source, x1+i, y1+j); - if ( (value != skip_value) ) { + if ( (skip_index_none) || (value != skip_index) ) { // write if skip_value_none is True common_hal_displayio_bitmap_set_pixel(self, x+i, y+j, value); } } From a66ef32da2fee0077f7917071294fa54b689e2e9 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Thu, 13 Aug 2020 17:03:06 -0500 Subject: [PATCH 10/79] Added inclusive indexing for x2,y2, fixed default value handling for x1,y1, added bitmap palette comparison --- locale/circuitpython.pot | 40 ++++++++++++++++++++++++-- shared-bindings/displayio/Bitmap.c | 45 ++++++++++++------------------ shared-module/displayio/Bitmap.c | 4 +-- 3 files changed, 58 insertions(+), 31 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index a1b286e2ed..3eb5b1ced2 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-14 09:36-0400\n" +"POT-Creation-Date: 2020-08-14 13:10-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -82,6 +82,8 @@ msgstr "" msgid "%q list must be a list" msgstr "" +#: shared-bindings/memorymonitor/AllocationAlarm 3.c +#: shared-bindings/memorymonitor/AllocationAlarm 4.c #: shared-bindings/memorymonitor/AllocationAlarm.c msgid "%q must be >= 0" msgstr "" @@ -89,6 +91,8 @@ msgstr "" #: shared-bindings/_bleio/CharacteristicBuffer.c #: shared-bindings/_bleio/PacketBuffer.c shared-bindings/displayio/Group.c #: shared-bindings/displayio/Shape.c +#: shared-bindings/memorymonitor/AllocationAlarm 3.c +#: shared-bindings/memorymonitor/AllocationAlarm 4.c #: shared-bindings/memorymonitor/AllocationAlarm.c #: shared-bindings/vectorio/Circle.c shared-bindings/vectorio/Rectangle.c msgid "%q must be >= 1" @@ -252,6 +256,14 @@ msgstr "" msgid "'yield' outside function" msgstr "" +#: shared-bindings/displayio/Bitmap.c +msgid "(x,y): out of range of target bitmap" +msgstr "" + +#: shared-bindings/displayio/Bitmap.c +msgid "(x1,y1) or (x2,y2): out of range of source bitmap" +msgstr "" + #: py/compile.c msgid "*x must be assignment target" msgstr "" @@ -306,6 +318,7 @@ msgstr "" msgid "All timers for this pin are in use" msgstr "" +#: ports/atmel-samd/common-hal/_pew/PewPew 2.c #: ports/atmel-samd/common-hal/_pew/PewPew.c #: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c @@ -322,7 +335,11 @@ msgstr "" msgid "Already advertising." msgstr "" +#: shared-module/memorymonitor/AllocationAlarm 3.c +#: shared-module/memorymonitor/AllocationAlarm 4.c #: shared-module/memorymonitor/AllocationAlarm.c +#: shared-module/memorymonitor/AllocationSize 3.c +#: shared-module/memorymonitor/AllocationSize 4.c #: shared-module/memorymonitor/AllocationSize.c msgid "Already running" msgstr "" @@ -362,6 +379,8 @@ msgstr "" msgid "At most %d %q may be specified (not %d)" msgstr "" +#: shared-module/memorymonitor/AllocationAlarm 3.c +#: shared-module/memorymonitor/AllocationAlarm 4.c #: shared-module/memorymonitor/AllocationAlarm.c #, c-format msgid "Attempt to allocate %d blocks" @@ -491,6 +510,12 @@ msgid "Can't set CCCD on local Characteristic" msgstr "" #: shared-bindings/displayio/Bitmap.c +msgid "Cannot blit: source palette too large." +msgstr "" + +#: shared-bindings/displayio/Bitmap.c +#: shared-bindings/memorymonitor/AllocationSize 3.c +#: shared-bindings/memorymonitor/AllocationSize 4.c #: shared-bindings/memorymonitor/AllocationSize.c #: shared-bindings/pulseio/PulseIn.c msgid "Cannot delete values" @@ -1014,6 +1039,7 @@ msgstr "" #: ports/atmel-samd/common-hal/busio/I2C.c #: ports/atmel-samd/common-hal/busio/SPI.c #: ports/atmel-samd/common-hal/busio/UART.c +#: ports/atmel-samd/common-hal/i2cperipheral/I2CPeripheral 2.c #: ports/atmel-samd/common-hal/i2cperipheral/I2CPeripheral.c #: ports/cxd56/common-hal/busio/I2C.c ports/cxd56/common-hal/busio/SPI.c #: ports/cxd56/common-hal/busio/UART.c ports/cxd56/common-hal/sdioio/SDCard.c @@ -1370,6 +1396,8 @@ msgstr "" msgid "Random number generation error" msgstr "" +#: shared-bindings/memorymonitor/AllocationSize 3.c +#: shared-bindings/memorymonitor/AllocationSize 4.c #: shared-bindings/memorymonitor/AllocationSize.c #: shared-bindings/pulseio/PulseIn.c msgid "Read-only" @@ -1462,6 +1490,8 @@ msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c #: shared-bindings/displayio/TileGrid.c +#: shared-bindings/memorymonitor/AllocationSize 3.c +#: shared-bindings/memorymonitor/AllocationSize 4.c #: shared-bindings/memorymonitor/AllocationSize.c #: shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" @@ -1791,10 +1821,14 @@ msgstr "" msgid "address %08x is not aligned to %d bytes" msgstr "" +#: shared-bindings/i2cperipheral/I2CPeripheral 3.c +#: shared-bindings/i2cperipheral/I2CPeripheral 4.c #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "address out of bounds" msgstr "" +#: shared-bindings/i2cperipheral/I2CPeripheral 3.c +#: shared-bindings/i2cperipheral/I2CPeripheral 4.c #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "addresses is empty" msgstr "" @@ -1957,7 +1991,9 @@ msgstr "" msgid "can't assign to expression" msgstr "" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral 3.c +#: shared-bindings/i2cperipheral/I2CPeripheral 4.c +#: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "can't convert %q to %q" msgstr "" diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index af9f6c3c8b..5852f1a703 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -172,7 +172,7 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val return mp_const_none; } -//| def blit(self, x: int, y: int, source_bitmap: bitmap, x1: int, y1: int, x2: int, y2: int, skip_index: int) -> Any: +//| def blit(self, x: int, y: int, source_bitmap: bitmap, *, x1: int, y1: int, x2: int, y2: int, skip_index: int) -> Any: //| """Inserts the source_bitmap region defined by rectangular boundaries //| (x1,y1) and (x2,y2) into the bitmap at the specified (x,y) location. //| :param int x: Horizontal pixel location in bitmap where source_bitmap upper-left @@ -193,9 +193,9 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg static const mp_arg_t allowed_args[] = { {MP_QSTR_x, MP_ARG_REQUIRED | MP_ARG_INT}, {MP_QSTR_y, MP_ARG_REQUIRED | MP_ARG_INT}, - {MP_QSTR_source, MP_ARG_REQUIRED | MP_ARG_OBJ}, - {MP_QSTR_x1, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, - {MP_QSTR_y1, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, + {MP_QSTR_source_bitmap, MP_ARG_REQUIRED | MP_ARG_OBJ}, + {MP_QSTR_x1, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = 0} }, + {MP_QSTR_y1, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = 0} }, {MP_QSTR_x2, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, // None convert to source->width {MP_QSTR_y2, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, // None convert to source->height {MP_QSTR_skip_index, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj=mp_const_none} }, @@ -203,51 +203,42 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - displayio_bitmap_t *self = MP_OBJ_TO_PTR(pos_args[0]); //******* + displayio_bitmap_t *self = MP_OBJ_TO_PTR(pos_args[0]); int16_t x = args[ARG_x].u_int; int16_t y = args[ARG_y].u_int; displayio_bitmap_t *source = MP_OBJ_TO_PTR(args[ARG_source].u_obj); - int16_t x1, y1; - // if x1 or y1 is None, then set as the zero-point of the bitmap - if ( args[ARG_x1].u_obj == mp_const_none ) { - x1 = 0; - } else { - x1 = mp_obj_get_int(args[ARG_x1].u_obj); + // ensure that the target bitmap (self) has at least as many `bits_per_value` as the source + if (self->bits_per_value < source->bits_per_value) { + mp_raise_ValueError(translate("Cannot blit: source palette too large.")); } - //int16_t y1; - if ( args[ARG_y1].u_obj == mp_const_none ) { - y1 = 0; - } else { - y1 = mp_obj_get_int(args[ARG_y1].u_obj); - } - - int16_t x2, y2; + + int16_t x1, y1, x2, y2; // if x2 or y2 is None, then set as the maximum size of the source bitmap if ( args[ARG_x2].u_obj == mp_const_none ) { - x2 = source->width-1; + x2 = source->width; } else { x2 = mp_obj_get_int(args[ARG_x2].u_obj); } //int16_t y2; if ( args[ARG_y2].u_obj == mp_const_none ) { - y2 = source->height-1; + y2 = source->height; } else { y2 = mp_obj_get_int(args[ARG_y2].u_obj); } // Check x,y are within self (target) bitmap boundary - if ( (x < 0) || (y < 0) || (x >= self->width) || (y >= self->height) ) { + if ( (x < 0) || (y < 0) || (x > self->width) || (y > self->height) ) { mp_raise_ValueError(translate("(x,y): out of range of target bitmap")); } // Check x1,y1,x2,y2 are within source bitmap boundary - if ( (x1 < 0) || (x1 >= source->width) || - (y1 < 0) || (y1 >= source->height) || - (x2 < 0) || (x2 >= source->width) || - (y2 < 0) || (y2 >= source->height) ) { + if ( (x1 < 0) || (x1 > source->width) || + (y1 < 0) || (y1 > source->height) || + (x2 < 0) || (x2 > source->width) || + (y2 < 0) || (y2 > source->height) ) { mp_raise_ValueError(translate("(x1,y1) or (x2,y2): out of range of source bitmap")); } @@ -272,7 +263,7 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg } else { skip_index = mp_obj_get_int(args[ARG_skip_index].u_obj); skip_index_none = false; - } + } common_hal_displayio_bitmap_blit(self, x, y, source, x1, y1, x2, y2, skip_index, skip_index_none); diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c index dbcba6b583..7de9e9755e 100644 --- a/shared-module/displayio/Bitmap.c +++ b/shared-module/displayio/Bitmap.c @@ -118,9 +118,9 @@ void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16 } // simplest version - use internal functions for get/set pixels - for (int16_t i=0; i<= (x2-x1) ; i++) { + for (int16_t i=0; i < (x2-x1) ; i++) { if ( (x+i >= 0) && (x+i < self->width) ) { - for (int16_t j=0; j<= (y2-y1) ; j++){ + for (int16_t j=0; j < (y2-y1) ; j++){ if ((y+j >= 0) && (y+j < self->height) ) { uint32_t value = common_hal_displayio_bitmap_get_pixel(source, x1+i, y1+j); if ( (skip_index_none) || (value != skip_index) ) { // write if skip_value_none is True From b1fce9e933275cd9d945ec46c3ea8eaa350e6a67 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Thu, 13 Aug 2020 19:56:45 -0500 Subject: [PATCH 11/79] Deleted trailing whitespace --- shared-bindings/displayio/Bitmap.c | 13 ++++++------- shared-bindings/displayio/Bitmap.h | 4 ++-- shared-module/displayio/Bitmap.c | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index 5852f1a703..9479dc1a51 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -184,7 +184,8 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val //| : param int y1: Minimum y-value for rectangular bounding box to be copied from the source bitmap //| : param int x2: Maximum x-value for rectangular bounding box to be copied from the source bitmap //| : param int y2: Maximum y-value for rectangular bounding box to be copied from the source bitmap -//| : param int skip_index: bitmap palette index in the source that will not be copied, set `None` to copy all pixels +//| : param int skip_index: bitmap palette index in the source that will not be copied, +//| set `None` to copy all pixels""" //| ... //| @@ -229,19 +230,17 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg y2 = mp_obj_get_int(args[ARG_y2].u_obj); } - // Check x,y are within self (target) bitmap boundary if ( (x < 0) || (y < 0) || (x > self->width) || (y > self->height) ) { mp_raise_ValueError(translate("(x,y): out of range of target bitmap")); } // Check x1,y1,x2,y2 are within source bitmap boundary - if ( (x1 < 0) || (x1 > source->width) || - (y1 < 0) || (y1 > source->height) || + if ( (x1 < 0) || (x1 > source->width) || + (y1 < 0) || (y1 > source->height) || (x2 < 0) || (x2 > source->width) || (y2 < 0) || (y2 > source->height) ) { mp_raise_ValueError(translate("(x1,y1) or (x2,y2): out of range of source bitmap")); } - // Ensure x1 < x2 and y1 < y2 if (x1 > x2) { int16_t temp=x2; @@ -254,7 +253,7 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg y1=temp; } - uint32_t skip_index; + uint32_t skip_index; bool skip_index_none; // flag whether skip_value was None if (args[ARG_skip_index].u_obj == mp_const_none ) { @@ -263,7 +262,7 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg } else { skip_index = mp_obj_get_int(args[ARG_skip_index].u_obj); skip_index_none = false; - } + } common_hal_displayio_bitmap_blit(self, x, y, source, x1, y1, x2, y2, skip_index, skip_index_none); diff --git a/shared-bindings/displayio/Bitmap.h b/shared-bindings/displayio/Bitmap.h index cf75f3d764..00cd98b0a9 100644 --- a/shared-bindings/displayio/Bitmap.h +++ b/shared-bindings/displayio/Bitmap.h @@ -40,8 +40,8 @@ uint16_t common_hal_displayio_bitmap_get_height(displayio_bitmap_t *self); uint16_t common_hal_displayio_bitmap_get_width(displayio_bitmap_t *self); uint32_t common_hal_displayio_bitmap_get_bits_per_value(displayio_bitmap_t *self); void common_hal_displayio_bitmap_set_pixel(displayio_bitmap_t *bitmap, int16_t x, int16_t y, uint32_t value); -void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16_t y, displayio_bitmap_t *source, - int16_t x1, int16_t y1, int16_t x2, int16_t y2, +void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16_t y, displayio_bitmap_t *source, + int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint32_t skip_index, bool skip_index_none); uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *bitmap, int16_t x, int16_t y); void common_hal_displayio_bitmap_fill(displayio_bitmap_t *bitmap, uint32_t value); diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c index 7de9e9755e..e581d849d9 100644 --- a/shared-module/displayio/Bitmap.c +++ b/shared-module/displayio/Bitmap.c @@ -110,7 +110,7 @@ void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16 // Copy complete "source" bitmap into "self" bitmap at location x,y in the "self" // Add a boolean to determine if all values are copied, or only if non-zero // - // If skip_value is encountered in the source bitmap, it will not be copied. + // If skip_value is encountered in the source bitmap, it will not be copied. // If skip_value is `None`, then all pixels are copied. if (self->read_only) { From ba5dedc1df768bfac05db844f6220c4756c24223 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Thu, 13 Aug 2020 20:57:17 -0500 Subject: [PATCH 12/79] deleted whitespace --- shared-module/displayio/Bitmap.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c index e581d849d9..b470cecc35 100644 --- a/shared-module/displayio/Bitmap.c +++ b/shared-module/displayio/Bitmap.c @@ -105,11 +105,10 @@ uint32_t common_hal_displayio_bitmap_get_pixel(displayio_bitmap_t *self, int16_t return 0; } -void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16_t y, displayio_bitmap_t *source, - int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint32_t skip_index, bool skip_index_none) { +void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16_t y, displayio_bitmap_t *source, + int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint32_t skip_index, bool skip_index_none) { // Copy complete "source" bitmap into "self" bitmap at location x,y in the "self" // Add a boolean to determine if all values are copied, or only if non-zero - // // If skip_value is encountered in the source bitmap, it will not be copied. // If skip_value is `None`, then all pixels are copied. From fc1347ac2a0b467c1cbd9ac4a8ecf117bcdbb96a Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Thu, 13 Aug 2020 20:58:29 -0500 Subject: [PATCH 13/79] deleted whitespace --- shared-module/displayio/Bitmap.c | 1 - 1 file changed, 1 deletion(-) diff --git a/shared-module/displayio/Bitmap.c b/shared-module/displayio/Bitmap.c index b470cecc35..2f87a89448 100644 --- a/shared-module/displayio/Bitmap.c +++ b/shared-module/displayio/Bitmap.c @@ -129,7 +129,6 @@ void common_hal_displayio_bitmap_blit(displayio_bitmap_t *self, int16_t x, int16 } } } - } From 0c1768010bbe8cda69ebddf00c5112c3729e37bb Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Fri, 14 Aug 2020 13:43:32 -0500 Subject: [PATCH 14/79] Cleaning up with tannewt's help and adding the translation file --- locale/circuitpython.pot | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 3eb5b1ced2..5ee0a04859 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-14 13:10-0500\n" +"POT-Creation-Date: 2020-08-14 13:42-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -82,8 +82,6 @@ msgstr "" msgid "%q list must be a list" msgstr "" -#: shared-bindings/memorymonitor/AllocationAlarm 3.c -#: shared-bindings/memorymonitor/AllocationAlarm 4.c #: shared-bindings/memorymonitor/AllocationAlarm.c msgid "%q must be >= 0" msgstr "" @@ -91,8 +89,6 @@ msgstr "" #: shared-bindings/_bleio/CharacteristicBuffer.c #: shared-bindings/_bleio/PacketBuffer.c shared-bindings/displayio/Group.c #: shared-bindings/displayio/Shape.c -#: shared-bindings/memorymonitor/AllocationAlarm 3.c -#: shared-bindings/memorymonitor/AllocationAlarm 4.c #: shared-bindings/memorymonitor/AllocationAlarm.c #: shared-bindings/vectorio/Circle.c shared-bindings/vectorio/Rectangle.c msgid "%q must be >= 1" @@ -318,7 +314,6 @@ msgstr "" msgid "All timers for this pin are in use" msgstr "" -#: ports/atmel-samd/common-hal/_pew/PewPew 2.c #: ports/atmel-samd/common-hal/_pew/PewPew.c #: ports/atmel-samd/common-hal/audioio/AudioOut.c #: ports/atmel-samd/common-hal/frequencyio/FrequencyIn.c @@ -335,11 +330,7 @@ msgstr "" msgid "Already advertising." msgstr "" -#: shared-module/memorymonitor/AllocationAlarm 3.c -#: shared-module/memorymonitor/AllocationAlarm 4.c #: shared-module/memorymonitor/AllocationAlarm.c -#: shared-module/memorymonitor/AllocationSize 3.c -#: shared-module/memorymonitor/AllocationSize 4.c #: shared-module/memorymonitor/AllocationSize.c msgid "Already running" msgstr "" @@ -379,8 +370,6 @@ msgstr "" msgid "At most %d %q may be specified (not %d)" msgstr "" -#: shared-module/memorymonitor/AllocationAlarm 3.c -#: shared-module/memorymonitor/AllocationAlarm 4.c #: shared-module/memorymonitor/AllocationAlarm.c #, c-format msgid "Attempt to allocate %d blocks" @@ -514,8 +503,6 @@ msgid "Cannot blit: source palette too large." msgstr "" #: shared-bindings/displayio/Bitmap.c -#: shared-bindings/memorymonitor/AllocationSize 3.c -#: shared-bindings/memorymonitor/AllocationSize 4.c #: shared-bindings/memorymonitor/AllocationSize.c #: shared-bindings/pulseio/PulseIn.c msgid "Cannot delete values" @@ -1039,7 +1026,6 @@ msgstr "" #: ports/atmel-samd/common-hal/busio/I2C.c #: ports/atmel-samd/common-hal/busio/SPI.c #: ports/atmel-samd/common-hal/busio/UART.c -#: ports/atmel-samd/common-hal/i2cperipheral/I2CPeripheral 2.c #: ports/atmel-samd/common-hal/i2cperipheral/I2CPeripheral.c #: ports/cxd56/common-hal/busio/I2C.c ports/cxd56/common-hal/busio/SPI.c #: ports/cxd56/common-hal/busio/UART.c ports/cxd56/common-hal/sdioio/SDCard.c @@ -1396,8 +1382,6 @@ msgstr "" msgid "Random number generation error" msgstr "" -#: shared-bindings/memorymonitor/AllocationSize 3.c -#: shared-bindings/memorymonitor/AllocationSize 4.c #: shared-bindings/memorymonitor/AllocationSize.c #: shared-bindings/pulseio/PulseIn.c msgid "Read-only" @@ -1490,8 +1474,6 @@ msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c #: shared-bindings/displayio/TileGrid.c -#: shared-bindings/memorymonitor/AllocationSize 3.c -#: shared-bindings/memorymonitor/AllocationSize 4.c #: shared-bindings/memorymonitor/AllocationSize.c #: shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" @@ -1821,14 +1803,10 @@ msgstr "" msgid "address %08x is not aligned to %d bytes" msgstr "" -#: shared-bindings/i2cperipheral/I2CPeripheral 3.c -#: shared-bindings/i2cperipheral/I2CPeripheral 4.c #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "address out of bounds" msgstr "" -#: shared-bindings/i2cperipheral/I2CPeripheral 3.c -#: shared-bindings/i2cperipheral/I2CPeripheral 4.c #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "addresses is empty" msgstr "" @@ -1991,9 +1969,7 @@ msgstr "" msgid "can't assign to expression" msgstr "" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral 3.c -#: shared-bindings/i2cperipheral/I2CPeripheral 4.c -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c msgid "can't convert %q to %q" msgstr "" From e84723abba89f346cd9772e217f6f2c7dcf2b703 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Fri, 14 Aug 2020 14:22:34 -0500 Subject: [PATCH 15/79] Bug fixes related to input parameter handling x1,y1. Update comments --- locale/circuitpython.pot | 2 +- shared-bindings/displayio/Bitmap.c | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 5ee0a04859..d697f15c81 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-14 13:42-0500\n" +"POT-Creation-Date: 2020-08-14 14:20-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index 9479dc1a51..f2123135f6 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -182,8 +182,8 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val //| :param bitmap source_bitmap: Source bitmap that contains the graphical region to be copied //| : param int x1: Minimum x-value for rectangular bounding box to be copied from the source bitmap //| : param int y1: Minimum y-value for rectangular bounding box to be copied from the source bitmap -//| : param int x2: Maximum x-value for rectangular bounding box to be copied from the source bitmap -//| : param int y2: Maximum y-value for rectangular bounding box to be copied from the source bitmap +//| : param int x2: Maximum x-value (exclusive) for rectangular bounding box to be copied from the source bitmap +//| : param int y2: Maximum y-value (exclusive) for rectangular bounding box to be copied from the source bitmap //| : param int skip_index: bitmap palette index in the source that will not be copied, //| set `None` to copy all pixels""" //| ... @@ -195,8 +195,8 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg {MP_QSTR_x, MP_ARG_REQUIRED | MP_ARG_INT}, {MP_QSTR_y, MP_ARG_REQUIRED | MP_ARG_INT}, {MP_QSTR_source_bitmap, MP_ARG_REQUIRED | MP_ARG_OBJ}, - {MP_QSTR_x1, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = 0} }, - {MP_QSTR_y1, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = 0} }, + {MP_QSTR_x1, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, + {MP_QSTR_y1, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, {MP_QSTR_x2, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, // None convert to source->width {MP_QSTR_y2, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = mp_const_none} }, // None convert to source->height {MP_QSTR_skip_index, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj=mp_const_none} }, @@ -216,7 +216,9 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg mp_raise_ValueError(translate("Cannot blit: source palette too large.")); } - int16_t x1, y1, x2, y2; + int16_t x1 = args[ARG_x1].u_int; + int16_t y1 = args[ARG_y1].u_int; + int16_t x2, y2; // if x2 or y2 is None, then set as the maximum size of the source bitmap if ( args[ARG_x2].u_obj == mp_const_none ) { x2 = source->width; From bfa9904f3e036d5c72cc2bd10ec4333d1f4fd58b Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Fri, 14 Aug 2020 14:28:06 -0500 Subject: [PATCH 16/79] Corrected erroneous edit to fill description to -> None --- shared-bindings/displayio/Bitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index f2123135f6..b9a4fe47df 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -273,7 +273,7 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg MP_DEFINE_CONST_FUN_OBJ_KW(displayio_bitmap_blit_obj, 4, displayio_bitmap_obj_blit); // `displayio_bitmap_obj_blit` requires at least 4 arguments -//| def fill(self, value: Any) -> Any: +//| def fill(self, value: Any) -> None: //| """Fills the bitmap with the supplied palette index value.""" //| ... //| From 6c199c5d6918b00752bd03696e17607b1489512c Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Sat, 15 Aug 2020 15:58:04 -0500 Subject: [PATCH 17/79] Update documentation to remove whitespaces --- shared-bindings/displayio/Bitmap.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index b9a4fe47df..d732bc5f40 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -176,16 +176,16 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val //| """Inserts the source_bitmap region defined by rectangular boundaries //| (x1,y1) and (x2,y2) into the bitmap at the specified (x,y) location. //| :param int x: Horizontal pixel location in bitmap where source_bitmap upper-left -//| corner will be placed +//| corner will be placed //| :param int y: Vertical pixel location in bitmap where source_bitmap upper-left -//| corner will be placed +//| corner will be placed //| :param bitmap source_bitmap: Source bitmap that contains the graphical region to be copied -//| : param int x1: Minimum x-value for rectangular bounding box to be copied from the source bitmap -//| : param int y1: Minimum y-value for rectangular bounding box to be copied from the source bitmap -//| : param int x2: Maximum x-value (exclusive) for rectangular bounding box to be copied from the source bitmap -//| : param int y2: Maximum y-value (exclusive) for rectangular bounding box to be copied from the source bitmap -//| : param int skip_index: bitmap palette index in the source that will not be copied, -//| set `None` to copy all pixels""" +//| :param int x1: Minimum x-value for rectangular bounding box to be copied from the source bitmap +//| :param int y1: Minimum y-value for rectangular bounding box to be copied from the source bitmap +//| :param int x2: Maximum x-value (exclusive) for rectangular bounding box to be copied from the source bitmap +//| :param int y2: Maximum y-value (exclusive) for rectangular bounding box to be copied from the source bitmap +//| :param int skip_index: bitmap palette index in the source that will not be copied, +//| set `None` to copy all pixels""" //| ... //| From 1ccd2e234f336872b646ba978ac139dcdc7dc84f Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 17 Aug 2020 10:48:23 -0500 Subject: [PATCH 18/79] allocate_display_bus: fix bug where in-use bus would be returned --- shared-module/displayio/__init__.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index 5afcba35ec..8049be5b47 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -398,7 +398,7 @@ primary_display_t *allocate_display_or_raise(void) { } primary_display_t *allocate_display_bus(void) { for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { - mp_const_obj_t display_type = displays[i].display.base.type; + mp_const_obj_t display_type = displays[i].bus_base.type; if (display_type == NULL || display_type == &mp_type_NoneType) { return &displays[i]; } From 6425a411ca7e53b8cdc6c8399c6cd717f39e25fe Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 17 Aug 2020 21:07:24 -0500 Subject: [PATCH 19/79] Update shared-module/displayio/__init__.c Co-authored-by: Scott Shawcroft --- shared-module/displayio/__init__.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index 8049be5b47..73626ce154 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -398,7 +398,7 @@ primary_display_t *allocate_display_or_raise(void) { } primary_display_t *allocate_display_bus(void) { for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { - mp_const_obj_t display_type = displays[i].bus_base.type; + mp_const_obj_t display_bus_type = displays[i].bus_base.type; if (display_type == NULL || display_type == &mp_type_NoneType) { return &displays[i]; } From 6d2d36db3d161fefadd52cc1f2d5a9da99bb2dc9 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 17 Aug 2020 21:09:21 -0500 Subject: [PATCH 20/79] Finish implementing scott's suggestion --- shared-module/displayio/__init__.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index 73626ce154..295af3e7c4 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -399,7 +399,7 @@ primary_display_t *allocate_display_or_raise(void) { primary_display_t *allocate_display_bus(void) { for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { mp_const_obj_t display_bus_type = displays[i].bus_base.type; - if (display_type == NULL || display_type == &mp_type_NoneType) { + if (display_bus_type == NULL || display_bus_type == &mp_type_NoneType) { return &displays[i]; } } From 6857f984269149b46d1cd4283506420f341b2601 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 18 Aug 2020 13:08:33 -0700 Subject: [PATCH 21/79] Split pulseio.PWMOut into pwmio This gives us better granularity when implementing new ports because PWMOut is commonly implemented before PulseIn and PulseOut. Fixes #3211 --- .../atmel-samd/common-hal/pulseio/PulseOut.c | 2 +- .../common-hal/{pulseio => pwmio}/PWMOut.c | 30 ++--- .../common-hal/{pulseio => pwmio}/PWMOut.h | 8 +- ports/atmel-samd/common-hal/pwmio/__init__.c | 1 + ports/atmel-samd/supervisor/port.c | 4 +- ports/cxd56/common-hal/pulseio/PulseOut.c | 2 +- .../common-hal/{pulseio => pwmio}/PWMOut.c | 24 ++-- .../common-hal/{pulseio => pwmio}/PWMOut.h | 8 +- ports/cxd56/common-hal/pwmio/__init__.c | 1 + ports/cxd56/supervisor/port.c | 4 +- ports/esp32s2/common-hal/pulseio/PulseOut.c | 4 +- ports/esp32s2/common-hal/pulseio/PulseOut.h | 4 +- .../common-hal/{pulseio => pwmio}/PWMOut.c | 28 ++--- .../common-hal/{pulseio => pwmio}/PWMOut.h | 8 +- ports/esp32s2/common-hal/pwmio/__init__.c | 1 + ports/esp32s2/supervisor/port.c | 4 +- .../mimxrt10xx/common-hal/pulseio/PulseOut.c | 2 +- .../common-hal/{pulseio => pwmio}/PWMOut.c | 32 +++--- .../common-hal/{pulseio => pwmio}/PWMOut.h | 8 +- ports/mimxrt10xx/common-hal/pwmio/__init__.c | 1 + ports/mimxrt10xx/supervisor/port.c | 4 +- ports/nrf/common-hal/audiopwmio/PWMAudioOut.c | 2 +- ports/nrf/common-hal/pulseio/PulseOut.c | 4 +- ports/nrf/common-hal/pulseio/PulseOut.h | 4 +- .../common-hal/{pulseio => pwmio}/PWMOut.c | 30 ++--- .../common-hal/{pulseio => pwmio}/PWMOut.h | 8 +- ports/nrf/common-hal/pwmio/__init__.c | 1 + ports/nrf/supervisor/port.c | 7 +- ports/stm/common-hal/pulseio/PulseOut.c | 6 +- ports/stm/common-hal/pulseio/PulseOut.h | 4 +- .../common-hal/{pulseio => pwmio}/PWMOut.c | 26 ++--- .../common-hal/{pulseio => pwmio}/PWMOut.h | 8 +- ports/stm/common-hal/pwmio/__init__.c | 1 + ports/stm/supervisor/port.c | 14 ++- py/circuitpy_defns.mk | 10 +- py/circuitpy_mpconfig.h | 16 ++- py/circuitpy_mpconfig.mk | 17 ++- shared-bindings/pulseio/PulseOut.c | 15 +-- shared-bindings/pulseio/PulseOut.h | 4 +- shared-bindings/pulseio/__init__.c | 27 ++--- shared-bindings/{pulseio => pwmio}/PWMOut.c | 104 +++++++++--------- shared-bindings/{pulseio => pwmio}/PWMOut.h | 30 ++--- shared-bindings/pwmio/__init__.c | 73 ++++++++++++ shared-bindings/pwmio/__init__.h | 34 ++++++ shared-module/displayio/Display.c | 16 +-- shared-module/displayio/Display.h | 8 +- .../framebufferio/FramebufferDisplay.h | 1 - 47 files changed, 393 insertions(+), 257 deletions(-) rename ports/atmel-samd/common-hal/{pulseio => pwmio}/PWMOut.c (94%) rename ports/atmel-samd/common-hal/{pulseio => pwmio}/PWMOut.h (87%) create mode 100644 ports/atmel-samd/common-hal/pwmio/__init__.c rename ports/cxd56/common-hal/{pulseio => pwmio}/PWMOut.c (82%) rename ports/cxd56/common-hal/{pulseio => pwmio}/PWMOut.h (88%) create mode 100644 ports/cxd56/common-hal/pwmio/__init__.c rename ports/esp32s2/common-hal/{pulseio => pwmio}/PWMOut.c (87%) rename ports/esp32s2/common-hal/{pulseio => pwmio}/PWMOut.h (88%) create mode 100644 ports/esp32s2/common-hal/pwmio/__init__.c rename ports/mimxrt10xx/common-hal/{pulseio => pwmio}/PWMOut.c (94%) rename ports/mimxrt10xx/common-hal/{pulseio => pwmio}/PWMOut.h (87%) create mode 100644 ports/mimxrt10xx/common-hal/pwmio/__init__.c rename ports/nrf/common-hal/{pulseio => pwmio}/PWMOut.c (89%) rename ports/nrf/common-hal/{pulseio => pwmio}/PWMOut.h (89%) create mode 100644 ports/nrf/common-hal/pwmio/__init__.c rename ports/stm/common-hal/{pulseio => pwmio}/PWMOut.c (92%) rename ports/stm/common-hal/{pulseio => pwmio}/PWMOut.h (88%) create mode 100644 ports/stm/common-hal/pwmio/__init__.c rename shared-bindings/{pulseio => pwmio}/PWMOut.c (67%) rename shared-bindings/{pulseio => pwmio}/PWMOut.h (60%) create mode 100644 shared-bindings/pwmio/__init__.c create mode 100644 shared-bindings/pwmio/__init__.h diff --git a/ports/atmel-samd/common-hal/pulseio/PulseOut.c b/ports/atmel-samd/common-hal/pulseio/PulseOut.c index e9b2137cb0..59714f9b50 100644 --- a/ports/atmel-samd/common-hal/pulseio/PulseOut.c +++ b/ports/atmel-samd/common-hal/pulseio/PulseOut.c @@ -96,7 +96,7 @@ void pulseout_reset() { } void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, - const pulseio_pwmout_obj_t* carrier) { + const pwmio_pwmout_obj_t* carrier) { if (refcount == 0) { // Find a spare timer. Tc *tc = NULL; diff --git a/ports/atmel-samd/common-hal/pulseio/PWMOut.c b/ports/atmel-samd/common-hal/pwmio/PWMOut.c similarity index 94% rename from ports/atmel-samd/common-hal/pulseio/PWMOut.c rename to ports/atmel-samd/common-hal/pwmio/PWMOut.c index e33437dada..2e538ccdc3 100644 --- a/ports/atmel-samd/common-hal/pulseio/PWMOut.c +++ b/ports/atmel-samd/common-hal/pwmio/PWMOut.c @@ -28,8 +28,8 @@ #include #include "py/runtime.h" -#include "common-hal/pulseio/PWMOut.h" -#include "shared-bindings/pulseio/PWMOut.h" +#include "common-hal/pwmio/PWMOut.h" +#include "shared-bindings/pwmio/PWMOut.h" #include "shared-bindings/microcontroller/Processor.h" #include "timer_handler.h" @@ -78,13 +78,13 @@ void timer_reset_ok(int index, bool is_tc) { } -void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self) { +void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self) { timer_never_reset(self->timer->index, self->timer->is_tc); never_reset_pin_number(self->pin->number); } -void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) { +void common_hal_pwmio_pwmout_reset_ok(pwmio_pwmout_obj_t *self) { timer_reset_ok(self->timer->index, self->timer->is_tc); } @@ -137,7 +137,7 @@ bool channel_ok(const pin_timer_t* t) { t->is_tc; } -pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self, +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, @@ -296,16 +296,16 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self, gpio_set_pin_function(pin->number, GPIO_PIN_FUNCTION_E + mux_position); - common_hal_pulseio_pwmout_set_duty_cycle(self, duty); + common_hal_pwmio_pwmout_set_duty_cycle(self, duty); return PWMOUT_OK; } -bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t* self) { +bool common_hal_pwmio_pwmout_deinited(pwmio_pwmout_obj_t* self) { return self->pin == NULL; } -void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) { - if (common_hal_pulseio_pwmout_deinited(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; @@ -331,7 +331,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) { self->pin = NULL; } -extern void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_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 @@ -373,7 +373,7 @@ extern void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self, } } -uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t* self) { +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]; @@ -411,7 +411,7 @@ uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t* self) { } -void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self, +void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t* self, uint32_t frequency) { if (frequency == 0 || frequency > 6000000) { mp_raise_ValueError(translate("Invalid PWM frequency")); @@ -466,10 +466,10 @@ void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self, #endif } - common_hal_pulseio_pwmout_set_duty_cycle(self, self->duty_cycle); + common_hal_pwmio_pwmout_set_duty_cycle(self, self->duty_cycle); } -uint32_t common_hal_pulseio_pwmout_get_frequency(pulseio_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; uint8_t divisor; @@ -484,6 +484,6 @@ uint32_t common_hal_pulseio_pwmout_get_frequency(pulseio_pwmout_obj_t* self) { return (system_clock / prescaler[divisor]) / (top + 1); } -bool common_hal_pulseio_pwmout_get_variable_frequency(pulseio_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/pulseio/PWMOut.h b/ports/atmel-samd/common-hal/pwmio/PWMOut.h similarity index 87% rename from ports/atmel-samd/common-hal/pulseio/PWMOut.h rename to ports/atmel-samd/common-hal/pwmio/PWMOut.h index 09abda8196..1f5e62bae0 100644 --- a/ports/atmel-samd/common-hal/pulseio/PWMOut.h +++ b/ports/atmel-samd/common-hal/pwmio/PWMOut.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PWMOUT_H -#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PWMOUT_H +#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PWMIO_PWMOUT_H +#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PWMIO_PWMOUT_H #include "common-hal/microcontroller/Pin.h" @@ -37,8 +37,8 @@ typedef struct { const pin_timer_t* timer; bool variable_frequency; uint16_t duty_cycle; -} pulseio_pwmout_obj_t; +} pwmio_pwmout_obj_t; void pwmout_reset(void); -#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PULSEIO_PWMOUT_H +#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_PWMIO_PWMOUT_H diff --git a/ports/atmel-samd/common-hal/pwmio/__init__.c b/ports/atmel-samd/common-hal/pwmio/__init__.c new file mode 100644 index 0000000000..9e551a1072 --- /dev/null +++ b/ports/atmel-samd/common-hal/pwmio/__init__.c @@ -0,0 +1 @@ +// No pwmio module functions. diff --git a/ports/atmel-samd/supervisor/port.c b/ports/atmel-samd/supervisor/port.c index 591a858536..6352afb1d4 100644 --- a/ports/atmel-samd/supervisor/port.c +++ b/ports/atmel-samd/supervisor/port.c @@ -59,7 +59,7 @@ #include "common-hal/microcontroller/Pin.h" #include "common-hal/pulseio/PulseIn.h" #include "common-hal/pulseio/PulseOut.h" -#include "common-hal/pulseio/PWMOut.h" +#include "common-hal/pwmio/PWMOut.h" #include "common-hal/ps2io/Ps2.h" #include "common-hal/rtc/RTC.h" @@ -335,6 +335,8 @@ void reset_port(void) { #if CIRCUITPY_PULSEIO pulsein_reset(); pulseout_reset(); +#endif +#if CIRCUITPY_PWMIO pwmout_reset(); #endif diff --git a/ports/cxd56/common-hal/pulseio/PulseOut.c b/ports/cxd56/common-hal/pulseio/PulseOut.c index 21b4c77e55..a0c77b0a3d 100644 --- a/ports/cxd56/common-hal/pulseio/PulseOut.c +++ b/ports/cxd56/common-hal/pulseio/PulseOut.c @@ -59,7 +59,7 @@ static bool pulseout_timer_handler(unsigned int *next_interval_us, void *arg) } void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t *self, - const pulseio_pwmout_obj_t *carrier) { + const pwmio_pwmout_obj_t *carrier) { if (pulse_fd < 0) { pulse_fd = open("/dev/timer0", O_RDONLY); } diff --git a/ports/cxd56/common-hal/pulseio/PWMOut.c b/ports/cxd56/common-hal/pwmio/PWMOut.c similarity index 82% rename from ports/cxd56/common-hal/pulseio/PWMOut.c rename to ports/cxd56/common-hal/pwmio/PWMOut.c index 7e0be566b4..e0eb7abde8 100644 --- a/ports/cxd56/common-hal/pulseio/PWMOut.c +++ b/ports/cxd56/common-hal/pwmio/PWMOut.c @@ -30,7 +30,7 @@ #include "py/runtime.h" -#include "shared-bindings/pulseio/PWMOut.h" +#include "shared-bindings/pwmio/PWMOut.h" typedef struct { const char* devpath; @@ -46,7 +46,7 @@ STATIC pwmout_dev_t pwmout_dev[] = { {"/dev/pwm3", &pin_PWM3, -1, true} }; -pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t *self, +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->number = -1; @@ -85,8 +85,8 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t *self, return PWMOUT_OK; } -void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t *self) { - if (common_hal_pulseio_pwmout_deinited(self)) { +void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t *self) { + if (common_hal_pwmio_pwmout_deinited(self)) { return; } @@ -98,21 +98,21 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t *self) { self->pin = NULL; } -bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t *self) { +bool common_hal_pwmio_pwmout_deinited(pwmio_pwmout_obj_t *self) { return pwmout_dev[self->number].fd < 0; } -void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t *self, uint16_t duty) { +void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t *self, uint16_t duty) { self->info.duty = duty; ioctl(pwmout_dev[self->number].fd, PWMIOC_SETCHARACTERISTICS, (unsigned long)((uintptr_t)&self->info)); } -uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t *self) { +uint16_t common_hal_pwmio_pwmout_get_duty_cycle(pwmio_pwmout_obj_t *self) { return self->info.duty; } -void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t *self, uint32_t frequency) { +void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t *self, uint32_t frequency) { self->info.frequency = frequency; if (ioctl(pwmout_dev[self->number].fd, PWMIOC_SETCHARACTERISTICS, (unsigned long)((uintptr_t)&self->info)) < 0) { @@ -120,21 +120,21 @@ void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t *self, uint32_ } } -uint32_t common_hal_pulseio_pwmout_get_frequency(pulseio_pwmout_obj_t *self) { +uint32_t common_hal_pwmio_pwmout_get_frequency(pwmio_pwmout_obj_t *self) { return self->info.frequency; } -bool common_hal_pulseio_pwmout_get_variable_frequency(pulseio_pwmout_obj_t *self) { +bool common_hal_pwmio_pwmout_get_variable_frequency(pwmio_pwmout_obj_t *self) { return self->variable_frequency; } -void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self) { +void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self) { never_reset_pin_number(self->pin->number); pwmout_dev[self->number].reset = false; } -void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) { +void common_hal_pwmio_pwmout_reset_ok(pwmio_pwmout_obj_t *self) { pwmout_dev[self->number].reset = true; } diff --git a/ports/cxd56/common-hal/pulseio/PWMOut.h b/ports/cxd56/common-hal/pwmio/PWMOut.h similarity index 88% rename from ports/cxd56/common-hal/pulseio/PWMOut.h rename to ports/cxd56/common-hal/pwmio/PWMOut.h index 694acc4e0c..d9f3ea389d 100644 --- a/ports/cxd56/common-hal/pulseio/PWMOut.h +++ b/ports/cxd56/common-hal/pwmio/PWMOut.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_PULSEIO_PWMOUT_H -#define MICROPY_INCLUDED_CXD56_COMMON_HAL_PULSEIO_PWMOUT_H +#ifndef MICROPY_INCLUDED_CXD56_COMMON_HAL_PWMIO_PWMOUT_H +#define MICROPY_INCLUDED_CXD56_COMMON_HAL_PWMIO_PWMOUT_H #include @@ -39,10 +39,10 @@ typedef struct { struct pwm_info_s info; bool variable_frequency; int8_t number; -} pulseio_pwmout_obj_t; +} pwmio_pwmout_obj_t; void pwmout_reset(void); void pwmout_start(uint8_t pwm_num); void pwmout_stop(uint8_t pwm_num); -#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_PULSEIO_PWMOUT_H +#endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_PWMIO_PWMOUT_H diff --git a/ports/cxd56/common-hal/pwmio/__init__.c b/ports/cxd56/common-hal/pwmio/__init__.c new file mode 100644 index 0000000000..2bee925bc7 --- /dev/null +++ b/ports/cxd56/common-hal/pwmio/__init__.c @@ -0,0 +1 @@ +// No pulseio module functions. diff --git a/ports/cxd56/supervisor/port.c b/ports/cxd56/supervisor/port.c index a40d31fafb..94eda66dc1 100644 --- a/ports/cxd56/supervisor/port.c +++ b/ports/cxd56/supervisor/port.c @@ -41,7 +41,7 @@ #include "common-hal/microcontroller/Pin.h" #include "common-hal/analogio/AnalogIn.h" #include "common-hal/pulseio/PulseOut.h" -#include "common-hal/pulseio/PWMOut.h" +#include "common-hal/pwmio/PWMOut.h" #include "common-hal/busio/UART.h" safe_mode_t port_init(void) { @@ -67,6 +67,8 @@ void reset_port(void) { #endif #if CIRCUITPY_PULSEIO pulseout_reset(); +#endif +#if CIRCUITPY_PWMIO pwmout_reset(); #endif #if CIRCUITPY_BUSIO diff --git a/ports/esp32s2/common-hal/pulseio/PulseOut.c b/ports/esp32s2/common-hal/pulseio/PulseOut.c index c448c578df..15eab83ddf 100644 --- a/ports/esp32s2/common-hal/pulseio/PulseOut.c +++ b/ports/esp32s2/common-hal/pulseio/PulseOut.c @@ -26,7 +26,7 @@ #include "common-hal/pulseio/PulseOut.h" -#include "shared-bindings/pulseio/PWMOut.h" +#include "shared-bindings/pwmio/PWMOut.h" #include "py/runtime.h" // STATIC void turn_on(pulseio_pulseout_obj_t *pulseout) { @@ -45,7 +45,7 @@ void pulseout_reset() { } void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, - const pulseio_pwmout_obj_t* carrier) { + const pwmio_pwmout_obj_t* carrier) { mp_raise_NotImplementedError(translate("PulseOut not supported on this chip")); } diff --git a/ports/esp32s2/common-hal/pulseio/PulseOut.h b/ports/esp32s2/common-hal/pulseio/PulseOut.h index f465d00792..e58bb0457c 100644 --- a/ports/esp32s2/common-hal/pulseio/PulseOut.h +++ b/ports/esp32s2/common-hal/pulseio/PulseOut.h @@ -28,13 +28,13 @@ #define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_PULSEIO_PULSEOUT_H #include "common-hal/microcontroller/Pin.h" -#include "common-hal/pulseio/PWMOut.h" +#include "common-hal/pwmio/PWMOut.h" #include "py/obj.h" typedef struct { mp_obj_base_t base; - pulseio_pwmout_obj_t *pwmout; + pwmio_pwmout_obj_t *pwmout; } pulseio_pulseout_obj_t; void pulseout_reset(void); diff --git a/ports/esp32s2/common-hal/pulseio/PWMOut.c b/ports/esp32s2/common-hal/pwmio/PWMOut.c similarity index 87% rename from ports/esp32s2/common-hal/pulseio/PWMOut.c rename to ports/esp32s2/common-hal/pwmio/PWMOut.c index 0ac42852ae..d745b7789e 100644 --- a/ports/esp32s2/common-hal/pulseio/PWMOut.c +++ b/ports/esp32s2/common-hal/pwmio/PWMOut.c @@ -25,8 +25,8 @@ */ #include -#include "common-hal/pulseio/PWMOut.h" -#include "shared-bindings/pulseio/PWMOut.h" +#include "common-hal/pwmio/PWMOut.h" +#include "shared-bindings/pwmio/PWMOut.h" #include "py/runtime.h" #include "driver/ledc.h" @@ -58,7 +58,7 @@ void pwmout_reset(void) { not_first_reset = true; } -pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self, +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, @@ -140,27 +140,27 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self, claim_pin(pin); // Set initial duty - common_hal_pulseio_pwmout_set_duty_cycle(self, duty); + common_hal_pwmio_pwmout_set_duty_cycle(self, duty); return PWMOUT_OK; } -void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self) { +void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self) { never_reset_tim[self->tim_handle.timer_num] = true; never_reset_chan[self->chan_handle.channel] = true; } -void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) { +void common_hal_pwmio_pwmout_reset_ok(pwmio_pwmout_obj_t *self) { never_reset_tim[self->tim_handle.timer_num] = false; never_reset_chan[self->chan_handle.channel] = false; } -bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t* self) { +bool common_hal_pwmio_pwmout_deinited(pwmio_pwmout_obj_t* self) { return self->deinited == true; } -void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) { - if (common_hal_pulseio_pwmout_deinited(self)) { +void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t* self) { + if (common_hal_pwmio_pwmout_deinited(self)) { return; } @@ -186,23 +186,23 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) { self->deinited = true; } -void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self, uint16_t duty) { +void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t* self, uint16_t duty) { ledc_set_duty(LEDC_LOW_SPEED_MODE, self->chan_handle.channel, duty >> (16 - self->duty_resolution)); ledc_update_duty(LEDC_LOW_SPEED_MODE, self->chan_handle.channel); } -uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t* self) { +uint16_t common_hal_pwmio_pwmout_get_duty_cycle(pwmio_pwmout_obj_t* self) { return ledc_get_duty(LEDC_LOW_SPEED_MODE, self->chan_handle.channel) << (16 - self->duty_resolution); } -void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self, uint32_t frequency) { +void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t* self, uint32_t frequency) { ledc_set_freq(LEDC_LOW_SPEED_MODE, self->tim_handle.timer_num, frequency); } -uint32_t common_hal_pulseio_pwmout_get_frequency(pulseio_pwmout_obj_t* self) { +uint32_t common_hal_pwmio_pwmout_get_frequency(pwmio_pwmout_obj_t* self) { return ledc_get_freq(LEDC_LOW_SPEED_MODE, self->tim_handle.timer_num); } -bool common_hal_pulseio_pwmout_get_variable_frequency(pulseio_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/esp32s2/common-hal/pulseio/PWMOut.h b/ports/esp32s2/common-hal/pwmio/PWMOut.h similarity index 88% rename from ports/esp32s2/common-hal/pulseio/PWMOut.h rename to ports/esp32s2/common-hal/pwmio/PWMOut.h index 90a0c3ed96..c489e5a278 100644 --- a/ports/esp32s2/common-hal/pulseio/PWMOut.h +++ b/ports/esp32s2/common-hal/pwmio/PWMOut.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_ESP32S2_COMMON_HAL_PULSEIO_PWMOUT_H -#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_PULSEIO_PWMOUT_H +#ifndef MICROPY_INCLUDED_ESP32S2_COMMON_HAL_PWMIO_PWMOUT_H +#define MICROPY_INCLUDED_ESP32S2_COMMON_HAL_PWMIO_PWMOUT_H #include "common-hal/microcontroller/Pin.h" #include "driver/ledc.h" @@ -38,8 +38,8 @@ typedef struct { uint8_t duty_resolution; bool variable_frequency: 1; bool deinited: 1; -} pulseio_pwmout_obj_t; +} pwmio_pwmout_obj_t; void pwmout_reset(void); -#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_PULSEIO_PWMOUT_H +#endif // MICROPY_INCLUDED_ESP32S2_COMMON_HAL_PWMIO_PWMOUT_H diff --git a/ports/esp32s2/common-hal/pwmio/__init__.c b/ports/esp32s2/common-hal/pwmio/__init__.c new file mode 100644 index 0000000000..2bee925bc7 --- /dev/null +++ b/ports/esp32s2/common-hal/pwmio/__init__.c @@ -0,0 +1 @@ +// No pulseio module functions. diff --git a/ports/esp32s2/supervisor/port.c b/ports/esp32s2/supervisor/port.c index e4767e5146..2f430c7e35 100644 --- a/ports/esp32s2/supervisor/port.c +++ b/ports/esp32s2/supervisor/port.c @@ -38,7 +38,7 @@ #include "common-hal/busio/I2C.h" #include "common-hal/busio/SPI.h" #include "common-hal/busio/UART.h" -#include "common-hal/pulseio/PWMOut.h" +#include "common-hal/pwmio/PWMOut.h" #include "supervisor/memory.h" #include "supervisor/shared/tick.h" @@ -65,7 +65,7 @@ void reset_port(void) { // A larger delay so the idle task can run and do any IDF cleanup needed. vTaskDelay(4); -#if CIRCUITPY_PULSEIO +#if CIRCUITPY_PWMIO pwmout_reset(); #endif #if CIRCUITPY_BUSIO diff --git a/ports/mimxrt10xx/common-hal/pulseio/PulseOut.c b/ports/mimxrt10xx/common-hal/pulseio/PulseOut.c index ffa885688a..2c27847eda 100644 --- a/ports/mimxrt10xx/common-hal/pulseio/PulseOut.c +++ b/ports/mimxrt10xx/common-hal/pulseio/PulseOut.c @@ -94,7 +94,7 @@ void pulseout_reset() { } void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, - const pulseio_pwmout_obj_t* carrier) { + const pwmio_pwmout_obj_t* carrier) { // if (refcount == 0) { // // Find a spare timer. // Tc *tc = NULL; diff --git a/ports/mimxrt10xx/common-hal/pulseio/PWMOut.c b/ports/mimxrt10xx/common-hal/pwmio/PWMOut.c similarity index 94% rename from ports/mimxrt10xx/common-hal/pulseio/PWMOut.c rename to ports/mimxrt10xx/common-hal/pwmio/PWMOut.c index 50dd477ea6..dd464ef846 100644 --- a/ports/mimxrt10xx/common-hal/pulseio/PWMOut.c +++ b/ports/mimxrt10xx/common-hal/pwmio/PWMOut.c @@ -29,8 +29,8 @@ #include #include "py/runtime.h" -#include "common-hal/pulseio/PWMOut.h" -#include "shared-bindings/pulseio/PWMOut.h" +#include "common-hal/pwmio/PWMOut.h" +#include "shared-bindings/pwmio/PWMOut.h" #include "shared-bindings/microcontroller/Processor.h" #include "fsl_pwm.h" @@ -64,7 +64,7 @@ // //static uint8_t never_reset_tc_or_tcc[TC_INST_NUM + TCC_INST_NUM]; -void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self) { +void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self) { // if (self->timer->is_tc) { // never_reset_tc_or_tcc[self->timer->index] += 1; // } else { @@ -74,7 +74,7 @@ void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self) { // never_reset_pin_number(self->pin->number); } -void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) { +void common_hal_pwmio_pwmout_reset_ok(pwmio_pwmout_obj_t *self) { // if (self->timer->is_tc) { // never_reset_tc_or_tcc[self->timer->index] -= 1; // } else { @@ -133,7 +133,7 @@ void pwmout_reset(void) { #define PWM_SRC_CLK_FREQ CLOCK_GetFreq(kCLOCK_IpgClk) -pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t *self, +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, @@ -359,17 +359,17 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t *self, // // gpio_set_pin_function(pin->number, GPIO_PIN_FUNCTION_E + mux_position); - common_hal_pulseio_pwmout_set_duty_cycle(self, duty); + common_hal_pwmio_pwmout_set_duty_cycle(self, duty); return PWMOUT_OK; } -bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t* self) { +bool common_hal_pwmio_pwmout_deinited(pwmio_pwmout_obj_t* self) { return self->pin == NULL; } -void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) { - if (common_hal_pulseio_pwmout_deinited(self)) { +void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t* self) { + if (common_hal_pwmio_pwmout_deinited(self)) { return; } @@ -396,7 +396,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) { self->pin = NULL; } -void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t *self, uint16_t duty) { +void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t *self, uint16_t duty) { PWM_UpdatePwmDutycycle(PWM1, self->pwm->submodule, self->pwm->channel, kPWM_SignedCenterAligned, duty); // const pin_timer_t* t = self->timer; @@ -433,7 +433,7 @@ void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t *self, uint16 // } } -uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t* self) { +uint16_t common_hal_pwmio_pwmout_get_duty_cycle(pwmio_pwmout_obj_t* self) { return 0; // const pin_timer_t* t = self->timer; // if (t->is_tc) { @@ -471,7 +471,7 @@ uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t* self) { // } } -void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self, +void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t* self, uint32_t frequency) { // if (frequency == 0 || frequency > 6000000) { // mp_raise_ValueError(translate("Invalid PWM frequency")); @@ -492,7 +492,7 @@ void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self, // break; // } // } -// uint16_t old_duty = common_hal_pulseio_pwmout_get_duty_cycle(self); +// uint16_t old_duty = common_hal_pwmio_pwmout_get_duty_cycle(self); // if (t->is_tc) { // Tc* tc = tc_insts[t->index]; // uint8_t old_divisor = tc->COUNT16.CTRLA.bit.PRESCALER; @@ -527,10 +527,10 @@ void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self, // #endif // } -// common_hal_pulseio_pwmout_set_duty_cycle(self, old_duty); +// common_hal_pwmio_pwmout_set_duty_cycle(self, old_duty); } -uint32_t common_hal_pulseio_pwmout_get_frequency(pulseio_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; // uint8_t divisor; @@ -546,6 +546,6 @@ uint32_t common_hal_pulseio_pwmout_get_frequency(pulseio_pwmout_obj_t* self) { return 0; } -bool common_hal_pulseio_pwmout_get_variable_frequency(pulseio_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/mimxrt10xx/common-hal/pulseio/PWMOut.h b/ports/mimxrt10xx/common-hal/pwmio/PWMOut.h similarity index 87% rename from ports/mimxrt10xx/common-hal/pulseio/PWMOut.h rename to ports/mimxrt10xx/common-hal/pwmio/PWMOut.h index 2f0fe94c44..d3954de401 100644 --- a/ports/mimxrt10xx/common-hal/pulseio/PWMOut.h +++ b/ports/mimxrt10xx/common-hal/pwmio/PWMOut.h @@ -25,8 +25,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_MIMXRT10XX_COMMON_HAL_PULSEIO_PWMOUT_H -#define MICROPY_INCLUDED_MIMXRT10XX_COMMON_HAL_PULSEIO_PWMOUT_H +#ifndef MICROPY_INCLUDED_MIMXRT10XX_COMMON_HAL_PWMIO_PWMOUT_H +#define MICROPY_INCLUDED_MIMXRT10XX_COMMON_HAL_PWMIO_PWMOUT_H #include "common-hal/microcontroller/Pin.h" #include "periph.h" @@ -37,8 +37,8 @@ typedef struct { const mcu_pin_obj_t *pin; const mcu_pwm_obj_t *pwm; bool variable_frequency; -} pulseio_pwmout_obj_t; +} pwmio_pwmout_obj_t; void pwmout_reset(void); -#endif // MICROPY_INCLUDED_MIMXRT10XX_COMMON_HAL_PULSEIO_PWMOUT_H +#endif // MICROPY_INCLUDED_MIMXRT10XX_COMMON_HAL_PWMIO_PWMOUT_H diff --git a/ports/mimxrt10xx/common-hal/pwmio/__init__.c b/ports/mimxrt10xx/common-hal/pwmio/__init__.c new file mode 100644 index 0000000000..2bee925bc7 --- /dev/null +++ b/ports/mimxrt10xx/common-hal/pwmio/__init__.c @@ -0,0 +1 @@ +// No pulseio module functions. diff --git a/ports/mimxrt10xx/supervisor/port.c b/ports/mimxrt10xx/supervisor/port.c index 0b53a79f07..38cf16a494 100644 --- a/ports/mimxrt10xx/supervisor/port.c +++ b/ports/mimxrt10xx/supervisor/port.c @@ -39,7 +39,7 @@ #include "common-hal/microcontroller/Pin.h" #include "common-hal/pulseio/PulseIn.h" #include "common-hal/pulseio/PulseOut.h" -#include "common-hal/pulseio/PWMOut.h" +#include "common-hal/pwmio/PWMOut.h" #include "common-hal/rtc/RTC.h" #include "common-hal/busio/SPI.h" @@ -289,6 +289,8 @@ void reset_port(void) { #if CIRCUITPY_PULSEIO pulseout_reset(); +#endif +#if CIRCUITPY_PWMIO pwmout_reset(); #endif diff --git a/ports/nrf/common-hal/audiopwmio/PWMAudioOut.c b/ports/nrf/common-hal/audiopwmio/PWMAudioOut.c index 7fec766fb8..ed1bf81e48 100644 --- a/ports/nrf/common-hal/audiopwmio/PWMAudioOut.c +++ b/ports/nrf/common-hal/audiopwmio/PWMAudioOut.c @@ -32,7 +32,7 @@ #include "py/mperrno.h" #include "py/runtime.h" #include "common-hal/audiopwmio/PWMAudioOut.h" -#include "common-hal/pulseio/PWMOut.h" +#include "common-hal/pwmio/PWMOut.h" #include "shared-bindings/audiopwmio/PWMAudioOut.h" #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" diff --git a/ports/nrf/common-hal/pulseio/PulseOut.c b/ports/nrf/common-hal/pulseio/PulseOut.c index 270cb45d6d..16e383caf2 100644 --- a/ports/nrf/common-hal/pulseio/PulseOut.c +++ b/ports/nrf/common-hal/pulseio/PulseOut.c @@ -34,7 +34,7 @@ #include "py/gc.h" #include "py/runtime.h" #include "shared-bindings/pulseio/PulseOut.h" -#include "shared-bindings/pulseio/PWMOut.h" +#include "shared-bindings/pwmio/PWMOut.h" #include "supervisor/shared/translate.h" // A single timer is shared amongst all PulseOut objects under the assumption that @@ -100,7 +100,7 @@ void pulseout_reset() { } void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, - const pulseio_pwmout_obj_t* carrier) { + const pwmio_pwmout_obj_t* carrier) { if (refcount == 0) { timer = nrf_peripherals_allocate_timer_or_throw(); } diff --git a/ports/nrf/common-hal/pulseio/PulseOut.h b/ports/nrf/common-hal/pulseio/PulseOut.h index 42ec52e30e..714f740b20 100644 --- a/ports/nrf/common-hal/pulseio/PulseOut.h +++ b/ports/nrf/common-hal/pulseio/PulseOut.h @@ -28,13 +28,13 @@ #define MICROPY_INCLUDED_NRF_COMMON_HAL_PULSEIO_PULSEOUT_H #include "common-hal/microcontroller/Pin.h" -#include "common-hal/pulseio/PWMOut.h" +#include "common-hal/pwmio/PWMOut.h" #include "py/obj.h" typedef struct { mp_obj_base_t base; - const pulseio_pwmout_obj_t *pwmout; + const pwmio_pwmout_obj_t *pwmout; } pulseio_pulseout_obj_t; void pulseout_reset(void); diff --git a/ports/nrf/common-hal/pulseio/PWMOut.c b/ports/nrf/common-hal/pwmio/PWMOut.c similarity index 89% rename from ports/nrf/common-hal/pulseio/PWMOut.c rename to ports/nrf/common-hal/pwmio/PWMOut.c index 9d42ccca0f..a9d8964883 100644 --- a/ports/nrf/common-hal/pulseio/PWMOut.c +++ b/ports/nrf/common-hal/pwmio/PWMOut.c @@ -28,8 +28,8 @@ #include "nrf.h" #include "py/runtime.h" -#include "common-hal/pulseio/PWMOut.h" -#include "shared-bindings/pulseio/PWMOut.h" +#include "common-hal/pwmio/PWMOut.h" +#include "shared-bindings/pwmio/PWMOut.h" #include "supervisor/shared/translate.h" #include "nrf_gpio.h" @@ -63,7 +63,7 @@ STATIC int pwm_idx(NRF_PWM_Type *pwm) { return -1; } -void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self) { +void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self) { for(size_t i=0; i < MP_ARRAY_SIZE(pwms); i++) { NRF_PWM_Type* pwm = pwms[i]; if (pwm == self->pwm) { @@ -74,7 +74,7 @@ void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self) { never_reset_pin_number(self->pin_number); } -void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) { +void common_hal_pwmio_pwmout_reset_ok(pwmio_pwmout_obj_t *self) { for(size_t i=0; i < MP_ARRAY_SIZE(pwms); i++) { NRF_PWM_Type* pwm = pwms[i]; if (pwm == self->pwm) { @@ -204,7 +204,7 @@ void pwmout_free_channel(NRF_PWM_Type *pwm, int8_t channel) { nrf_pwm_disable(pwm); } -pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self, +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, @@ -251,16 +251,16 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self, nrf_pwm_enable(self->pwm); - common_hal_pulseio_pwmout_set_duty_cycle(self, duty); + common_hal_pwmio_pwmout_set_duty_cycle(self, duty); return PWMOUT_OK; } -bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t* self) { +bool common_hal_pwmio_pwmout_deinited(pwmio_pwmout_obj_t* self) { return self->pwm == NULL; } -void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) { - if (common_hal_pulseio_pwmout_deinited(self)) { +void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t* self) { + if (common_hal_pwmio_pwmout_deinited(self)) { return; } @@ -275,7 +275,7 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) { self->pin_number = NO_PIN; } -void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self, uint16_t duty_cycle) { +void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t* self, uint16_t duty_cycle) { self->duty_cycle = duty_cycle; uint16_t* p_value = ((uint16_t*)self->pwm->SEQ[0].PTR) + self->channel; @@ -284,11 +284,11 @@ void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self, uint16 self->pwm->TASKS_SEQSTART[0] = 1; } -uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t* self) { +uint16_t common_hal_pwmio_pwmout_get_duty_cycle(pwmio_pwmout_obj_t* self) { return self->duty_cycle; } -void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self, uint32_t frequency) { +void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t* self, uint32_t frequency) { // COUNTERTOP is 3..32767, so highest available frequency is PWM_MAX_FREQ / 3. uint16_t countertop; nrf_pwm_clk_t base_clock; @@ -300,13 +300,13 @@ void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self, uint32_ nrf_pwm_configure(self->pwm, base_clock, NRF_PWM_MODE_UP, countertop); // Set the duty cycle again, because it depends on COUNTERTOP, which probably changed. // Setting the duty cycle will also do a SEQSTART. - common_hal_pulseio_pwmout_set_duty_cycle(self, self->duty_cycle); + common_hal_pwmio_pwmout_set_duty_cycle(self, self->duty_cycle); } -uint32_t common_hal_pulseio_pwmout_get_frequency(pulseio_pwmout_obj_t* self) { +uint32_t common_hal_pwmio_pwmout_get_frequency(pwmio_pwmout_obj_t* self) { return self->frequency; } -bool common_hal_pulseio_pwmout_get_variable_frequency(pulseio_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/nrf/common-hal/pulseio/PWMOut.h b/ports/nrf/common-hal/pwmio/PWMOut.h similarity index 89% rename from ports/nrf/common-hal/pulseio/PWMOut.h rename to ports/nrf/common-hal/pwmio/PWMOut.h index a0c2d87471..e910baa765 100644 --- a/ports/nrf/common-hal/pulseio/PWMOut.h +++ b/ports/nrf/common-hal/pwmio/PWMOut.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_PULSEIO_PWMOUT_H -#define MICROPY_INCLUDED_NRF_COMMON_HAL_PULSEIO_PWMOUT_H +#ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_PWMIO_PWMOUT_H +#define MICROPY_INCLUDED_NRF_COMMON_HAL_PWMIO_PWMOUT_H #include "nrfx_pwm.h" #include "py/obj.h" @@ -38,7 +38,7 @@ typedef struct { bool variable_frequency: 1; uint16_t duty_cycle; uint32_t frequency; -} pulseio_pwmout_obj_t; +} pwmio_pwmout_obj_t; void pwmout_reset(void); NRF_PWM_Type *pwmout_allocate(uint16_t countertop, nrf_pwm_clk_t base_clock, @@ -46,4 +46,4 @@ NRF_PWM_Type *pwmout_allocate(uint16_t countertop, nrf_pwm_clk_t base_clock, IRQn_Type *irq); void pwmout_free_channel(NRF_PWM_Type *pwm, int8_t channel); -#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_PULSEIO_PWMOUT_H +#endif // MICROPY_INCLUDED_NRF_COMMON_HAL_PWMIO_PWMOUT_H diff --git a/ports/nrf/common-hal/pwmio/__init__.c b/ports/nrf/common-hal/pwmio/__init__.c new file mode 100644 index 0000000000..9e551a1072 --- /dev/null +++ b/ports/nrf/common-hal/pwmio/__init__.c @@ -0,0 +1 @@ +// No pwmio module functions. diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c index 87a4d7396f..2945f244db 100644 --- a/ports/nrf/supervisor/port.c +++ b/ports/nrf/supervisor/port.c @@ -45,9 +45,9 @@ #include "common-hal/busio/I2C.h" #include "common-hal/busio/SPI.h" #include "common-hal/busio/UART.h" -#include "common-hal/pulseio/PWMOut.h" #include "common-hal/pulseio/PulseOut.h" #include "common-hal/pulseio/PulseIn.h" +#include "common-hal/pwmio/PWMOut.h" #include "common-hal/rtc/RTC.h" #include "common-hal/neopixel_write/__init__.h" #include "common-hal/watchdog/WatchDogTimer.h" @@ -196,11 +196,14 @@ void reset_port(void) { #if CIRCUITPY_PULSEIO - pwmout_reset(); pulseout_reset(); pulsein_reset(); #endif +#if CIRCUITPY_PWMIO + pwmout_reset(); +#endif + #if CIRCUITPY_RTC rtc_reset(); #endif diff --git a/ports/stm/common-hal/pulseio/PulseOut.c b/ports/stm/common-hal/pulseio/PulseOut.c index bcc25d8177..fb48561d89 100644 --- a/ports/stm/common-hal/pulseio/PulseOut.c +++ b/ports/stm/common-hal/pulseio/PulseOut.c @@ -32,7 +32,7 @@ #include "py/gc.h" #include "py/runtime.h" #include "shared-bindings/pulseio/PulseOut.h" -#include "shared-bindings/pulseio/PWMOut.h" +#include "shared-bindings/pwmio/PWMOut.h" #include "supervisor/shared/translate.h" #include STM32_HAL_H @@ -113,7 +113,7 @@ void pulseout_reset() { } void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, - const pulseio_pwmout_obj_t* carrier) { + const pwmio_pwmout_obj_t* carrier) { // Add to active PulseOuts refcount++; TIM_TypeDef * tim_instance = stm_peripherals_find_timer(); @@ -135,7 +135,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, tim_handle.Instance->SR = 0; // The HAL can't work with const, recast required. - self->pwmout = (pulseio_pwmout_obj_t*)carrier; + self->pwmout = (pwmio_pwmout_obj_t*)carrier; turn_off(self); } diff --git a/ports/stm/common-hal/pulseio/PulseOut.h b/ports/stm/common-hal/pulseio/PulseOut.h index aa97396d00..29894f27d2 100644 --- a/ports/stm/common-hal/pulseio/PulseOut.h +++ b/ports/stm/common-hal/pulseio/PulseOut.h @@ -28,13 +28,13 @@ #define MICROPY_INCLUDED_STM32F4_COMMON_HAL_PULSEIO_PULSEOUT_H #include "common-hal/microcontroller/Pin.h" -#include "common-hal/pulseio/PWMOut.h" +#include "common-hal/pwmio/PWMOut.h" #include "py/obj.h" typedef struct { mp_obj_base_t base; - pulseio_pwmout_obj_t *pwmout; + pwmio_pwmout_obj_t *pwmout; } pulseio_pulseout_obj_t; void pulseout_reset(void); diff --git a/ports/stm/common-hal/pulseio/PWMOut.c b/ports/stm/common-hal/pwmio/PWMOut.c similarity index 92% rename from ports/stm/common-hal/pulseio/PWMOut.c rename to ports/stm/common-hal/pwmio/PWMOut.c index ddbadaf4ce..065eb2a757 100644 --- a/ports/stm/common-hal/pulseio/PWMOut.c +++ b/ports/stm/common-hal/pwmio/PWMOut.c @@ -27,8 +27,8 @@ #include #include "py/runtime.h" -#include "common-hal/pulseio/PWMOut.h" -#include "shared-bindings/pulseio/PWMOut.h" +#include "common-hal/pwmio/PWMOut.h" +#include "shared-bindings/pwmio/PWMOut.h" #include "supervisor/shared/translate.h" #include "shared-bindings/microcontroller/__init__.h" @@ -75,7 +75,7 @@ void pwmout_reset(void) { } } -pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self, +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, @@ -204,7 +204,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self, return PWMOUT_OK; } -void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self) { +void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self) { for (size_t i = 0; i < TIM_BANK_ARRAY_LEN; i++) { if (mcu_tim_banks[i] == self->handle.Instance) { never_reset_tim[i] = true; @@ -214,7 +214,7 @@ void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self) { } } -void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) { +void common_hal_pwmio_pwmout_reset_ok(pwmio_pwmout_obj_t *self) { for(size_t i = 0; i < TIM_BANK_ARRAY_LEN; i++) { if (mcu_tim_banks[i] == self->handle.Instance) { never_reset_tim[i] = false; @@ -223,12 +223,12 @@ void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self) { } } -bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t* self) { +bool common_hal_pwmio_pwmout_deinited(pwmio_pwmout_obj_t* self) { return self->tim == NULL; } -void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) { - if (common_hal_pulseio_pwmout_deinited(self)) { +void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t* self) { + if (common_hal_pwmio_pwmout_deinited(self)) { return; } //var freq shuts down entire timer, others just their channel @@ -248,17 +248,17 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) { } } -void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self, uint16_t duty) { +void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t* self, uint16_t duty) { uint32_t internal_duty_cycle = timer_get_internal_duty(duty, self->period); __HAL_TIM_SET_COMPARE(&self->handle, self->channel, internal_duty_cycle); self->duty_cycle = duty; } -uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t* self) { +uint16_t common_hal_pwmio_pwmout_get_duty_cycle(pwmio_pwmout_obj_t* self) { return self->duty_cycle; } -void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self, uint32_t frequency) { +void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t* self, uint32_t frequency) { //don't halt setup for the same frequency if (frequency == self->frequency) { return; @@ -295,10 +295,10 @@ void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self, uint32_ self->period = period; } -uint32_t common_hal_pulseio_pwmout_get_frequency(pulseio_pwmout_obj_t* self) { +uint32_t common_hal_pwmio_pwmout_get_frequency(pwmio_pwmout_obj_t* self) { return self->frequency; } -bool common_hal_pulseio_pwmout_get_variable_frequency(pulseio_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/stm/common-hal/pulseio/PWMOut.h b/ports/stm/common-hal/pwmio/PWMOut.h similarity index 88% rename from ports/stm/common-hal/pulseio/PWMOut.h rename to ports/stm/common-hal/pwmio/PWMOut.h index 57ab143b9a..5d8001202c 100644 --- a/ports/stm/common-hal/pulseio/PWMOut.h +++ b/ports/stm/common-hal/pwmio/PWMOut.h @@ -24,8 +24,8 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_STM32F4_COMMON_HAL_PULSEIO_PWMOUT_H -#define MICROPY_INCLUDED_STM32F4_COMMON_HAL_PULSEIO_PWMOUT_H +#ifndef MICROPY_INCLUDED_STM32F4_COMMON_HAL_PWMIO_PWMOUT_H +#define MICROPY_INCLUDED_STM32F4_COMMON_HAL_PWMIO_PWMOUT_H #include "common-hal/microcontroller/Pin.h" @@ -44,8 +44,8 @@ typedef struct { uint16_t duty_cycle; uint32_t frequency; uint32_t period; -} pulseio_pwmout_obj_t; +} pwmio_pwmout_obj_t; void pwmout_reset(void); -#endif // MICROPY_INCLUDED_STM32F4_COMMON_HAL_PULSEIO_PWMOUT_H +#endif // MICROPY_INCLUDED_STM32F4_COMMON_HAL_PWMIO_PWMOUT_H diff --git a/ports/stm/common-hal/pwmio/__init__.c b/ports/stm/common-hal/pwmio/__init__.c new file mode 100644 index 0000000000..9e551a1072 --- /dev/null +++ b/ports/stm/common-hal/pwmio/__init__.c @@ -0,0 +1 @@ +// No pwmio module functions. diff --git a/ports/stm/supervisor/port.c b/ports/stm/supervisor/port.c index 5ce92f70a4..e21105001c 100644 --- a/ports/stm/supervisor/port.c +++ b/ports/stm/supervisor/port.c @@ -38,9 +38,13 @@ #include "common-hal/busio/UART.h" #endif #if CIRCUITPY_PULSEIO -#include "common-hal/pulseio/PWMOut.h" #include "common-hal/pulseio/PulseOut.h" #include "common-hal/pulseio/PulseIn.h" +#endif +#if CIRCUITPY_PWMIO +#include "common-hal/pwmio/PWMOut.h" +#endif +#if CIRCUITPY_PULSEIO || CIRCUITPY_PWMIO #include "timers.h" #endif #if CIRCUITPY_SDIOIO @@ -230,12 +234,16 @@ void reset_port(void) { #if CIRCUITPY_SDIOIO sdioio_reset(); #endif -#if CIRCUITPY_PULSEIO +#if CIRCUITPY_PULSEIO || CIRCUITPY_PWMIO timers_reset(); - pwmout_reset(); +#endif +#if CIRCUITPY_PULSEIO pulseout_reset(); pulsein_reset(); #endif +#if CIRCUITPY_PWMIO + pwmout_reset(); +#endif } void reset_to_bootloader(void) { diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index b70ae64a80..ab7a3af60b 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -198,11 +198,14 @@ endif ifeq ($(CIRCUITPY_RGBMATRIX),1) SRC_PATTERNS += rgbmatrix/% endif +ifeq ($(CIRCUITPY_PS2IO),1) +SRC_PATTERNS += ps2io/% +endif ifeq ($(CIRCUITPY_PULSEIO),1) SRC_PATTERNS += pulseio/% endif -ifeq ($(CIRCUITPY_PS2IO),1) -SRC_PATTERNS += ps2io/% +ifeq ($(CIRCUITPY_PWMIO),1) +SRC_PATTERNS += pwmio/% endif ifeq ($(CIRCUITPY_RANDOM),1) SRC_PATTERNS += random/% @@ -316,10 +319,11 @@ SRC_COMMON_HAL_ALL = \ os/__init__.c \ ps2io/Ps2.c \ ps2io/__init__.c \ - pulseio/PWMOut.c \ pulseio/PulseIn.c \ pulseio/PulseOut.c \ pulseio/__init__.c \ + pwmio/PWMOut.c \ + pwmio/__init__.c \ rgbmatrix/RGBMatrix.c \ rgbmatrix/__init__.c \ rotaryio/IncrementalEncoder.c \ diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 12d667d8f8..76b91defae 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -503,6 +503,13 @@ extern const struct _mp_obj_module_t pixelbuf_module; #define PIXELBUF_MODULE #endif +#if CIRCUITPY_PS2IO +extern const struct _mp_obj_module_t ps2io_module; +#define PS2IO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_ps2io), (mp_obj_t)&ps2io_module }, +#else +#define PS2IO_MODULE +#endif + #if CIRCUITPY_PULSEIO extern const struct _mp_obj_module_t pulseio_module; #define PULSEIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_pulseio), (mp_obj_t)&pulseio_module }, @@ -510,11 +517,11 @@ extern const struct _mp_obj_module_t pulseio_module; #define PULSEIO_MODULE #endif -#if CIRCUITPY_PS2IO -extern const struct _mp_obj_module_t ps2io_module; -#define PS2IO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_ps2io), (mp_obj_t)&ps2io_module }, +#if CIRCUITPY_PWMIO +extern const struct _mp_obj_module_t pwmio_module; +#define PWMIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_pwmio), (mp_obj_t)&pwmio_module }, #else -#define PS2IO_MODULE +#define PWMIO_MODULE #endif #if CIRCUITPY_RGBMATRIX @@ -740,6 +747,7 @@ extern const struct _mp_obj_module_t watchdog_module; PIXELBUF_MODULE \ PS2IO_MODULE \ PULSEIO_MODULE \ + PWMIO_MODULE \ RANDOM_MODULE \ RE_MODULE \ RGBMATRIX_MODULE \ diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index bdc1e77d54..379c3850e3 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -148,19 +148,24 @@ CFLAGS += -DCIRCUITPY_OS=$(CIRCUITPY_OS) CIRCUITPY_PIXELBUF ?= $(CIRCUITPY_FULL_BUILD) CFLAGS += -DCIRCUITPY_PIXELBUF=$(CIRCUITPY_PIXELBUF) -CIRCUITPY_RGBMATRIX ?= 0 -CFLAGS += -DCIRCUITPY_RGBMATRIX=$(CIRCUITPY_RGBMATRIX) - -CIRCUITPY_PULSEIO ?= 1 -CFLAGS += -DCIRCUITPY_PULSEIO=$(CIRCUITPY_PULSEIO) - # Only for SAMD boards for the moment CIRCUITPY_PS2IO ?= 0 CFLAGS += -DCIRCUITPY_PS2IO=$(CIRCUITPY_PS2IO) +CIRCUITPY_PULSEIO ?= 1 +CFLAGS += -DCIRCUITPY_PULSEIO=$(CIRCUITPY_PULSEIO) + +# For now we tie PWMIO to PULSEIO so they always both exist. In CircuitPython 7 +# we can enable and disable them separately once PWMOut is removed from `pulseio`. +CIRCUITPY_PWMIO = $(CIRCUITPY_PULSEIO) +CFLAGS += -DCIRCUITPY_PWMIO=$(CIRCUITPY_PWMIO) + CIRCUITPY_RANDOM ?= 1 CFLAGS += -DCIRCUITPY_RANDOM=$(CIRCUITPY_RANDOM) +CIRCUITPY_RGBMATRIX ?= 0 +CFLAGS += -DCIRCUITPY_RGBMATRIX=$(CIRCUITPY_RGBMATRIX) + CIRCUITPY_ROTARYIO ?= 1 CFLAGS += -DCIRCUITPY_ROTARYIO=$(CIRCUITPY_ROTARYIO) diff --git a/shared-bindings/pulseio/PulseOut.c b/shared-bindings/pulseio/PulseOut.c index 3d35f05445..024ee613ce 100644 --- a/shared-bindings/pulseio/PulseOut.c +++ b/shared-bindings/pulseio/PulseOut.c @@ -32,7 +32,7 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/pulseio/PulseOut.h" -#include "shared-bindings/pulseio/PWMOut.h" +#include "shared-bindings/pwmio/PWMOut.h" #include "shared-bindings/util.h" #include "supervisor/shared/translate.h" @@ -41,19 +41,20 @@ //| pulsed signal consists of timed on and off periods. Unlike PWM, there is no set duration //| for on and off pairs.""" //| -//| def __init__(self, carrier: PWMOut) -> None: +//| def __init__(self, carrier: pwmio.PWMOut) -> None: //| """Create a PulseOut object associated with the given PWMout object. //| -//| :param ~pulseio.PWMOut carrier: PWMOut that is set to output on the desired pin. +//| :param ~pwmio.PWMOut carrier: PWMOut that is set to output on the desired pin. //| //| Send a short series of pulses:: //| //| import array //| import pulseio +//| import pwmio //| import board //| //| # 50% duty cycle at 38kHz. -//| pwm = pulseio.PWMOut(board.D13, frequency=38000, duty_cycle=32768) +//| pwm = pwmio.PWMOut(board.D13, frequency=38000, duty_cycle=32768) //| pulse = pulseio.PulseOut(pwm) //| # on off on off on //| pulses = array.array('H', [65000, 1000, 65000, 65000, 1000]) @@ -68,15 +69,15 @@ STATIC mp_obj_t pulseio_pulseout_make_new(const mp_obj_type_t *type, size_t n_ar mp_arg_check_num(n_args, kw_args, 1, 1, false); mp_obj_t carrier_obj = args[0]; - if (!MP_OBJ_IS_TYPE(carrier_obj, &pulseio_pwmout_type)) { - mp_raise_TypeError_varg(translate("Expected a %q"), pulseio_pwmout_type.name); + if (!MP_OBJ_IS_TYPE(carrier_obj, &pwmio_pwmout_type)) { + mp_raise_TypeError_varg(translate("Expected a %q"), pwmio_pwmout_type.name); } // create Pulse object from the given pin pulseio_pulseout_obj_t *self = m_new_obj(pulseio_pulseout_obj_t); self->base.type = &pulseio_pulseout_type; - common_hal_pulseio_pulseout_construct(self, (pulseio_pwmout_obj_t *)MP_OBJ_TO_PTR(carrier_obj)); + common_hal_pulseio_pulseout_construct(self, (pwmio_pwmout_obj_t *)MP_OBJ_TO_PTR(carrier_obj)); return MP_OBJ_FROM_PTR(self); } diff --git a/shared-bindings/pulseio/PulseOut.h b/shared-bindings/pulseio/PulseOut.h index 390910ff62..80dd0e92f0 100644 --- a/shared-bindings/pulseio/PulseOut.h +++ b/shared-bindings/pulseio/PulseOut.h @@ -29,12 +29,12 @@ #include "common-hal/microcontroller/Pin.h" #include "common-hal/pulseio/PulseOut.h" -#include "common-hal/pulseio/PWMOut.h" +#include "common-hal/pwmio/PWMOut.h" extern const mp_obj_type_t pulseio_pulseout_type; extern void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, - const pulseio_pwmout_obj_t* carrier); + const pwmio_pwmout_obj_t* carrier); extern void common_hal_pulseio_pulseout_deinit(pulseio_pulseout_obj_t* self); extern bool common_hal_pulseio_pulseout_deinited(pulseio_pulseout_obj_t* self); extern void common_hal_pulseio_pulseout_send(pulseio_pulseout_obj_t* self, diff --git a/shared-bindings/pulseio/__init__.c b/shared-bindings/pulseio/__init__.c index 87946e5f0b..efef640433 100644 --- a/shared-bindings/pulseio/__init__.c +++ b/shared-bindings/pulseio/__init__.c @@ -33,40 +33,29 @@ #include "shared-bindings/pulseio/__init__.h" #include "shared-bindings/pulseio/PulseIn.h" #include "shared-bindings/pulseio/PulseOut.h" -#include "shared-bindings/pulseio/PWMOut.h" +#include "shared-bindings/pwmio/PWMOut.h" -//| """Support for pulse based protocols +//| """Support for individual pulse based protocols //| //| The `pulseio` module contains classes to provide access to basic pulse IO. +//| Individual pulses are commonly used in infrared remotes and in DHT +//| temperature sensors. //| +//| .. warning:: PWMOut is moving to `pwmio` and will be removed from `pulseio` +//| in CircuitPython 7. + //| All classes change hardware state and should be deinitialized when they //| are no longer needed if the program continues after use. To do so, either //| call :py:meth:`!deinit` or use a context manager. See //| :ref:`lifetime-and-contextmanagers` for more info. //| -//| For example:: -//| -//| import pulseio -//| import time -//| from board import * -//| -//| pwm = pulseio.PWMOut(D13) -//| pwm.duty_cycle = 2 ** 15 -//| time.sleep(0.1) -//| -//| This example will initialize the the device, set -//| :py:data:`~pulseio.PWMOut.duty_cycle`, and then sleep 0.1 seconds. -//| CircuitPython will automatically turn off the PWM when it resets all -//| hardware after program completion. Use ``deinit()`` or a ``with`` statement -//| to do it yourself.""" -//| STATIC const mp_rom_map_elem_t pulseio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pulseio) }, { MP_ROM_QSTR(MP_QSTR_PulseIn), MP_ROM_PTR(&pulseio_pulsein_type) }, { MP_ROM_QSTR(MP_QSTR_PulseOut), MP_ROM_PTR(&pulseio_pulseout_type) }, - { MP_ROM_QSTR(MP_QSTR_PWMOut), MP_ROM_PTR(&pulseio_pwmout_type) }, + { MP_ROM_QSTR(MP_QSTR_PWMOut), MP_ROM_PTR(&pwmio_pwmout_type) }, }; STATIC MP_DEFINE_CONST_DICT(pulseio_module_globals, pulseio_module_globals_table); diff --git a/shared-bindings/pulseio/PWMOut.c b/shared-bindings/pwmio/PWMOut.c similarity index 67% rename from shared-bindings/pulseio/PWMOut.c rename to shared-bindings/pwmio/PWMOut.c index e9b6c45d20..da07555928 100644 --- a/shared-bindings/pulseio/PWMOut.c +++ b/shared-bindings/pwmio/PWMOut.c @@ -31,7 +31,7 @@ #include "py/runtime.h" #include "shared-bindings/microcontroller/Pin.h" -#include "shared-bindings/pulseio/PWMOut.h" +#include "shared-bindings/pwmio/PWMOut.h" #include "shared-bindings/util.h" #include "supervisor/shared/translate.h" @@ -55,33 +55,33 @@ //| //| Simple LED fade:: //| -//| import pulseio +//| import pwmio //| import board //| -//| pwm = pulseio.PWMOut(board.D13) # output on D13 +//| pwm = pwmio.PWMOut(board.D13) # output on D13 //| pwm.duty_cycle = 2 ** 15 # Cycles the pin with 50% duty cycle (half of 2 ** 16) at the default 500hz //| //| PWM at specific frequency (servos and motors):: //| -//| import pulseio +//| import pwmio //| import board //| -//| pwm = pulseio.PWMOut(board.D13, frequency=50) +//| pwm = pwmio.PWMOut(board.D13, frequency=50) //| pwm.duty_cycle = 2 ** 15 # Cycles the pin with 50% duty cycle (half of 2 ** 16) at 50hz //| //| Variable frequency (usually tones):: //| -//| import pulseio +//| import pwmio //| import board //| import time //| -//| pwm = pulseio.PWMOut(board.D13, duty_cycle=2 ** 15, frequency=440, variable_frequency=True) +//| pwm = pwmio.PWMOut(board.D13, duty_cycle=2 ** 15, frequency=440, variable_frequency=True) //| time.sleep(0.2) //| pwm.frequency = 880 //| time.sleep(0.1)""" //| ... //| -STATIC mp_obj_t pulseio_pwmout_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t pwmio_pwmout_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { enum { ARG_pin, ARG_duty_cycle, ARG_frequency, ARG_variable_frequency }; static const mp_arg_t allowed_args[] = { { MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ, }, @@ -99,9 +99,9 @@ STATIC mp_obj_t pulseio_pwmout_make_new(const mp_obj_type_t *type, size_t n_args bool variable_frequency = parsed_args[ARG_variable_frequency].u_bool; // create PWM object from the given pin - pulseio_pwmout_obj_t *self = m_new_obj(pulseio_pwmout_obj_t); - self->base.type = &pulseio_pwmout_type; - pwmout_result_t result = common_hal_pulseio_pwmout_construct(self, pin, duty_cycle, frequency, variable_frequency); + pwmio_pwmout_obj_t *self = m_new_obj(pwmio_pwmout_obj_t); + self->base.type = &pwmio_pwmout_type; + pwmout_result_t result = common_hal_pwmio_pwmout_construct(self, pin, duty_cycle, frequency, variable_frequency); if (result == PWMOUT_INVALID_PIN) { mp_raise_ValueError(translate("Invalid pin")); } else if (result == PWMOUT_INVALID_FREQUENCY) { @@ -119,15 +119,15 @@ STATIC mp_obj_t pulseio_pwmout_make_new(const mp_obj_type_t *type, size_t n_args //| """Deinitialises the PWMOut and releases any hardware resources for reuse.""" //| ... //| -STATIC mp_obj_t pulseio_pwmout_deinit(mp_obj_t self_in) { - pulseio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_pulseio_pwmout_deinit(self); +STATIC mp_obj_t pwmio_pwmout_deinit(mp_obj_t self_in) { + pwmio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in); + common_hal_pwmio_pwmout_deinit(self); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(pulseio_pwmout_deinit_obj, pulseio_pwmout_deinit); +STATIC MP_DEFINE_CONST_FUN_OBJ_1(pwmio_pwmout_deinit_obj, pwmio_pwmout_deinit); -STATIC void check_for_deinit(pulseio_pwmout_obj_t *self) { - if (common_hal_pulseio_pwmout_deinited(self)) { +STATIC void check_for_deinit(pwmio_pwmout_obj_t *self) { + if (common_hal_pwmio_pwmout_deinited(self)) { raise_deinited_error(); } } @@ -143,12 +143,12 @@ STATIC void check_for_deinit(pulseio_pwmout_obj_t *self) { //| :ref:`lifetime-and-contextmanagers` for more info.""" //| ... //| -STATIC mp_obj_t pulseio_pwmout_obj___exit__(size_t n_args, const mp_obj_t *args) { +STATIC mp_obj_t pwmio_pwmout_obj___exit__(size_t n_args, const mp_obj_t *args) { (void)n_args; - common_hal_pulseio_pwmout_deinit(args[0]); + common_hal_pwmio_pwmout_deinit(args[0]); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pulseio_pwmout___exit___obj, 4, 4, pulseio_pwmout_obj___exit__); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pwmio_pwmout___exit___obj, 4, 4, pwmio_pwmout_obj___exit__); //| duty_cycle: int //| """16 bit value that dictates how much of one cycle is high (1) versus low @@ -160,29 +160,29 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pulseio_pwmout___exit___obj, 4, 4, pu //| Reading this property will return the value from the internal representation, //| so it may differ from the value set.""" //| -STATIC mp_obj_t pulseio_pwmout_obj_get_duty_cycle(mp_obj_t self_in) { - pulseio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in); +STATIC mp_obj_t pwmio_pwmout_obj_get_duty_cycle(mp_obj_t self_in) { + pwmio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in); check_for_deinit(self); - return MP_OBJ_NEW_SMALL_INT(common_hal_pulseio_pwmout_get_duty_cycle(self)); + return MP_OBJ_NEW_SMALL_INT(common_hal_pwmio_pwmout_get_duty_cycle(self)); } -MP_DEFINE_CONST_FUN_OBJ_1(pulseio_pwmout_get_duty_cycle_obj, pulseio_pwmout_obj_get_duty_cycle); +MP_DEFINE_CONST_FUN_OBJ_1(pwmio_pwmout_get_duty_cycle_obj, pwmio_pwmout_obj_get_duty_cycle); -STATIC mp_obj_t pulseio_pwmout_obj_set_duty_cycle(mp_obj_t self_in, mp_obj_t duty_cycle) { - pulseio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in); +STATIC mp_obj_t pwmio_pwmout_obj_set_duty_cycle(mp_obj_t self_in, mp_obj_t duty_cycle) { + pwmio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in); check_for_deinit(self); mp_int_t duty = mp_obj_get_int(duty_cycle); if (duty < 0 || duty > 0xffff) { mp_raise_ValueError(translate("PWM duty_cycle must be between 0 and 65535 inclusive (16 bit resolution)")); } - common_hal_pulseio_pwmout_set_duty_cycle(self, duty); + common_hal_pwmio_pwmout_set_duty_cycle(self, duty); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_2(pulseio_pwmout_set_duty_cycle_obj, pulseio_pwmout_obj_set_duty_cycle); +MP_DEFINE_CONST_FUN_OBJ_2(pwmio_pwmout_set_duty_cycle_obj, pwmio_pwmout_obj_set_duty_cycle); -const mp_obj_property_t pulseio_pwmout_duty_cycle_obj = { +const mp_obj_property_t pwmio_pwmout_duty_cycle_obj = { .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&pulseio_pwmout_get_duty_cycle_obj, - (mp_obj_t)&pulseio_pwmout_set_duty_cycle_obj, + .proxy = {(mp_obj_t)&pwmio_pwmout_get_duty_cycle_obj, + (mp_obj_t)&pwmio_pwmout_set_duty_cycle_obj, (mp_obj_t)&mp_const_none_obj}, }; @@ -196,50 +196,50 @@ const mp_obj_property_t pulseio_pwmout_duty_cycle_obj = { //| from the original duty cycle value. This should happen without any need //| to manually re-set the duty cycle.""" //| -STATIC mp_obj_t pulseio_pwmout_obj_get_frequency(mp_obj_t self_in) { - pulseio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in); +STATIC mp_obj_t pwmio_pwmout_obj_get_frequency(mp_obj_t self_in) { + pwmio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in); check_for_deinit(self); - return MP_OBJ_NEW_SMALL_INT(common_hal_pulseio_pwmout_get_frequency(self)); + return MP_OBJ_NEW_SMALL_INT(common_hal_pwmio_pwmout_get_frequency(self)); } -MP_DEFINE_CONST_FUN_OBJ_1(pulseio_pwmout_get_frequency_obj, pulseio_pwmout_obj_get_frequency); +MP_DEFINE_CONST_FUN_OBJ_1(pwmio_pwmout_get_frequency_obj, pwmio_pwmout_obj_get_frequency); -STATIC mp_obj_t pulseio_pwmout_obj_set_frequency(mp_obj_t self_in, mp_obj_t frequency) { - pulseio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in); +STATIC mp_obj_t pwmio_pwmout_obj_set_frequency(mp_obj_t self_in, mp_obj_t frequency) { + pwmio_pwmout_obj_t *self = MP_OBJ_TO_PTR(self_in); check_for_deinit(self); - if (!common_hal_pulseio_pwmout_get_variable_frequency(self)) { + if (!common_hal_pwmio_pwmout_get_variable_frequency(self)) { mp_raise_AttributeError(translate( "PWM frequency not writable when variable_frequency is False on " "construction.")); } - common_hal_pulseio_pwmout_set_frequency(self, mp_obj_get_int(frequency)); + common_hal_pwmio_pwmout_set_frequency(self, mp_obj_get_int(frequency)); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_2(pulseio_pwmout_set_frequency_obj, pulseio_pwmout_obj_set_frequency); +MP_DEFINE_CONST_FUN_OBJ_2(pwmio_pwmout_set_frequency_obj, pwmio_pwmout_obj_set_frequency); -const mp_obj_property_t pulseio_pwmout_frequency_obj = { +const mp_obj_property_t pwmio_pwmout_frequency_obj = { .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&pulseio_pwmout_get_frequency_obj, - (mp_obj_t)&pulseio_pwmout_set_frequency_obj, + .proxy = {(mp_obj_t)&pwmio_pwmout_get_frequency_obj, + (mp_obj_t)&pwmio_pwmout_set_frequency_obj, (mp_obj_t)&mp_const_none_obj}, }; -STATIC const mp_rom_map_elem_t pulseio_pwmout_locals_dict_table[] = { +STATIC const mp_rom_map_elem_t pwmio_pwmout_locals_dict_table[] = { // Methods - { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pulseio_pwmout_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&pwmio_pwmout_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, - { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&pulseio_pwmout___exit___obj) }, + { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&pwmio_pwmout___exit___obj) }, // Properties - { MP_ROM_QSTR(MP_QSTR_duty_cycle), MP_ROM_PTR(&pulseio_pwmout_duty_cycle_obj) }, - { MP_ROM_QSTR(MP_QSTR_frequency), MP_ROM_PTR(&pulseio_pwmout_frequency_obj) }, + { MP_ROM_QSTR(MP_QSTR_duty_cycle), MP_ROM_PTR(&pwmio_pwmout_duty_cycle_obj) }, + { MP_ROM_QSTR(MP_QSTR_frequency), MP_ROM_PTR(&pwmio_pwmout_frequency_obj) }, // TODO(tannewt): Add enabled to determine whether the signal is output // without giving up the resources. Useful for IR output. }; -STATIC MP_DEFINE_CONST_DICT(pulseio_pwmout_locals_dict, pulseio_pwmout_locals_dict_table); +STATIC MP_DEFINE_CONST_DICT(pwmio_pwmout_locals_dict, pwmio_pwmout_locals_dict_table); -const mp_obj_type_t pulseio_pwmout_type = { +const mp_obj_type_t pwmio_pwmout_type = { { &mp_type_type }, .name = MP_QSTR_PWMOut, - .make_new = pulseio_pwmout_make_new, - .locals_dict = (mp_obj_dict_t*)&pulseio_pwmout_locals_dict, + .make_new = pwmio_pwmout_make_new, + .locals_dict = (mp_obj_dict_t*)&pwmio_pwmout_locals_dict, }; diff --git a/shared-bindings/pulseio/PWMOut.h b/shared-bindings/pwmio/PWMOut.h similarity index 60% rename from shared-bindings/pulseio/PWMOut.h rename to shared-bindings/pwmio/PWMOut.h index c72278e0e0..1a99914ea5 100644 --- a/shared-bindings/pulseio/PWMOut.h +++ b/shared-bindings/pwmio/PWMOut.h @@ -24,13 +24,13 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_PULSEIO_PWMOUT_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_PULSEIO_PWMOUT_H +#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_PWMIO_PWMOUT_H +#define MICROPY_INCLUDED_SHARED_BINDINGS_PWMIO_PWMOUT_H #include "common-hal/microcontroller/Pin.h" -#include "common-hal/pulseio/PWMOut.h" +#include "common-hal/pwmio/PWMOut.h" -extern const mp_obj_type_t pulseio_pwmout_type; +extern const mp_obj_type_t pwmio_pwmout_type; typedef enum { PWMOUT_OK, @@ -40,19 +40,19 @@ typedef enum { PWMOUT_ALL_TIMERS_IN_USE } pwmout_result_t; -extern pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self, +extern 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); -extern void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self); -extern bool common_hal_pulseio_pwmout_deinited(pulseio_pwmout_obj_t* self); -extern void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self, uint16_t duty); -extern uint16_t common_hal_pulseio_pwmout_get_duty_cycle(pulseio_pwmout_obj_t* self); -extern void common_hal_pulseio_pwmout_set_frequency(pulseio_pwmout_obj_t* self, uint32_t frequency); -extern uint32_t common_hal_pulseio_pwmout_get_frequency(pulseio_pwmout_obj_t* self); -extern bool common_hal_pulseio_pwmout_get_variable_frequency(pulseio_pwmout_obj_t* self); +extern void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t* self); +extern bool common_hal_pwmio_pwmout_deinited(pwmio_pwmout_obj_t* self); +extern void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t* self, uint16_t duty); +extern uint16_t common_hal_pwmio_pwmout_get_duty_cycle(pwmio_pwmout_obj_t* self); +extern void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t* self, uint32_t frequency); +extern uint32_t common_hal_pwmio_pwmout_get_frequency(pwmio_pwmout_obj_t* self); +extern bool common_hal_pwmio_pwmout_get_variable_frequency(pwmio_pwmout_obj_t* self); // This is used by the supervisor to claim PWMOut devices indefinitely. -extern void common_hal_pulseio_pwmout_never_reset(pulseio_pwmout_obj_t *self); -extern void common_hal_pulseio_pwmout_reset_ok(pulseio_pwmout_obj_t *self); +extern void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self); +extern void common_hal_pwmio_pwmout_reset_ok(pwmio_pwmout_obj_t *self); -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_PULSEIO_PWMOUT_H +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_PWMIO_PWMOUT_H diff --git a/shared-bindings/pwmio/__init__.c b/shared-bindings/pwmio/__init__.c new file mode 100644 index 0000000000..a513837034 --- /dev/null +++ b/shared-bindings/pwmio/__init__.c @@ -0,0 +1,73 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 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 "py/obj.h" +#include "py/runtime.h" + +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/pwmio/__init__.h" +#include "shared-bindings/pwmio/PWMOut.h" + +//| """Support for PWM based protocols +//| +//| The `pwmio` module contains classes to provide access to basic pulse IO. +//| + +//| All classes change hardware state and should be deinitialized when they +//| are no longer needed if the program continues after use. To do so, either +//| call :py:meth:`!deinit` or use a context manager. See +//| :ref:`lifetime-and-contextmanagers` for more info. +//| +//| For example:: +//| +//| import pwmio +//| import time +//| from board import * +//| +//| pwm = pwmio.PWMOut(D13) +//| pwm.duty_cycle = 2 ** 15 +//| time.sleep(0.1) +//| +//| This example will initialize the the device, set +//| :py:data:`~pwmio.PWMOut.duty_cycle`, and then sleep 0.1 seconds. +//| CircuitPython will automatically turn off the PWM when it resets all +//| hardware after program completion. Use ``deinit()`` or a ``with`` statement +//| to do it yourself.""" +//| + +STATIC const mp_rom_map_elem_t pwmio_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pwmio) }, + { MP_ROM_QSTR(MP_QSTR_PWMOut), MP_ROM_PTR(&pwmio_pwmout_type) }, +}; + +STATIC MP_DEFINE_CONST_DICT(pwmio_module_globals, pwmio_module_globals_table); + +const mp_obj_module_t pwmio_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t*)&pwmio_module_globals, +}; diff --git a/shared-bindings/pwmio/__init__.h b/shared-bindings/pwmio/__init__.h new file mode 100644 index 0000000000..93c70377d7 --- /dev/null +++ b/shared-bindings/pwmio/__init__.h @@ -0,0 +1,34 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Scott Shawcroft + * + * 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_PWMIO___INIT___H +#define MICROPY_INCLUDED_SHARED_BINDINGS_PWMIO___INIT___H + +#include "py/obj.h" + +// Nothing now. + +#endif // MICROPY_INCLUDED_SHARED_BINDINGS_PWMIO___INIT___H diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index 46bb6fdb57..4f92f249fd 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -111,14 +111,14 @@ void common_hal_displayio_display_construct(displayio_display_obj_t* self, if (backlight_pin != NULL && common_hal_mcu_pin_is_free(backlight_pin)) { // Avoid PWM types and functions when the module isn't enabled #if (CIRCUITPY_PULSEIO) - pwmout_result_t result = common_hal_pulseio_pwmout_construct(&self->backlight_pwm, backlight_pin, 0, 50000, false); + pwmout_result_t result = common_hal_pwmio_pwmout_construct(&self->backlight_pwm, backlight_pin, 0, 50000, false); if (result != PWMOUT_OK) { self->backlight_inout.base.type = &digitalio_digitalinout_type; common_hal_digitalio_digitalinout_construct(&self->backlight_inout, backlight_pin); common_hal_never_reset_pin(backlight_pin); } else { - self->backlight_pwm.base.type = &pulseio_pwmout_type; - common_hal_pulseio_pwmout_never_reset(&self->backlight_pwm); + self->backlight_pwm.base.type = &pwmio_pwmout_type; + common_hal_pwmio_pwmout_never_reset(&self->backlight_pwm); } #else // Otherwise default to digital @@ -173,14 +173,14 @@ bool common_hal_displayio_display_set_brightness(displayio_display_obj_t* self, // Avoid PWM types and functions when the module isn't enabled #if (CIRCUITPY_PULSEIO) - bool ispwm = (self->backlight_pwm.base.type == &pulseio_pwmout_type) ? true : false; + bool ispwm = (self->backlight_pwm.base.type == &pwmio_pwmout_type) ? true : false; #else bool ispwm = false; #endif if (ispwm) { #if (CIRCUITPY_PULSEIO) - common_hal_pulseio_pwmout_set_duty_cycle(&self->backlight_pwm, (uint16_t) (0xffff * brightness)); + common_hal_pwmio_pwmout_set_duty_cycle(&self->backlight_pwm, (uint16_t) (0xffff * brightness)); ok = true; #else ok = false; @@ -419,9 +419,9 @@ void release_display(displayio_display_obj_t* self) { common_hal_displayio_display_set_auto_refresh(self, false); release_display_core(&self->core); #if (CIRCUITPY_PULSEIO) - if (self->backlight_pwm.base.type == &pulseio_pwmout_type) { - common_hal_pulseio_pwmout_reset_ok(&self->backlight_pwm); - common_hal_pulseio_pwmout_deinit(&self->backlight_pwm); + if (self->backlight_pwm.base.type == &pwmio_pwmout_type) { + common_hal_pwmio_pwmout_reset_ok(&self->backlight_pwm); + common_hal_pwmio_pwmout_deinit(&self->backlight_pwm); } else if (self->backlight_inout.base.type == &digitalio_digitalinout_type) { common_hal_digitalio_digitalinout_deinit(&self->backlight_inout); } diff --git a/shared-module/displayio/Display.h b/shared-module/displayio/Display.h index 861a38fd7c..bdb861aa09 100644 --- a/shared-module/displayio/Display.h +++ b/shared-module/displayio/Display.h @@ -29,8 +29,8 @@ #include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/displayio/Group.h" -#if CIRCUITPY_PULSEIO -#include "shared-bindings/pulseio/PWMOut.h" +#if CIRCUITPY_PWMIO +#include "shared-bindings/pwmio/PWMOut.h" #endif #include "shared-module/displayio/area.h" @@ -41,8 +41,8 @@ typedef struct { displayio_display_core_t core; union { digitalio_digitalinout_obj_t backlight_inout; - #if CIRCUITPY_PULSEIO - pulseio_pwmout_obj_t backlight_pwm; + #if CIRCUITPY_PWMIO + pwmio_pwmout_obj_t backlight_pwm; #endif }; uint64_t last_backlight_refresh; diff --git a/shared-module/framebufferio/FramebufferDisplay.h b/shared-module/framebufferio/FramebufferDisplay.h index 89df0d27c1..d73d4b9a95 100644 --- a/shared-module/framebufferio/FramebufferDisplay.h +++ b/shared-module/framebufferio/FramebufferDisplay.h @@ -33,7 +33,6 @@ #include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/displayio/Group.h" -#include "shared-bindings/pulseio/PWMOut.h" #include "shared-module/displayio/area.h" #include "shared-module/displayio/display_core.h" From 135626a03822f0aa098f41800cf3a961dfa2b819 Mon Sep 17 00:00:00 2001 From: Benjamin Shockley Date: Thu, 20 Aug 2020 13:50:52 -0500 Subject: [PATCH 22/79] Update mpconfigboard.mk Added support for second type of memory chip. --- ports/atmel-samd/boards/mini_sam_m4/mpconfigboard.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/atmel-samd/boards/mini_sam_m4/mpconfigboard.mk b/ports/atmel-samd/boards/mini_sam_m4/mpconfigboard.mk index ae2a1e9733..393adf8397 100644 --- a/ports/atmel-samd/boards/mini_sam_m4/mpconfigboard.mk +++ b/ports/atmel-samd/boards/mini_sam_m4/mpconfigboard.mk @@ -7,8 +7,8 @@ CHIP_VARIANT = SAMD51G19A CHIP_FAMILY = samd51 QSPI_FLASH_FILESYSTEM = 1 -EXTERNAL_FLASH_DEVICE_COUNT = 1 -EXTERNAL_FLASH_DEVICES = "W25Q16JV_IM" +EXTERNAL_FLASH_DEVICE_COUNT = 2 +EXTERNAL_FLASH_DEVICES = "W25Q16JV_IM, W25Q16JV_IQ" LONGINT_IMPL = MPZ # No I2S on SAMD51G From f62b07cc8c98c6abba4a26e0ed5aa5c23eba9bc0 Mon Sep 17 00:00:00 2001 From: Hosted Weblate Date: Thu, 20 Aug 2020 20:24:16 +0200 Subject: [PATCH 23/79] 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 | 17 +++++++++++++++-- locale/cs.po | 17 +++++++++++++++-- locale/de_DE.po | 20 +++++++++++++++----- locale/es.po | 20 +++++++++++++++----- locale/fil.po | 17 +++++++++++++++-- locale/fr.po | 20 +++++++++++++++----- locale/hi.po | 17 +++++++++++++++-- locale/it_IT.po | 17 +++++++++++++++-- locale/ja.po | 17 +++++++++++++++-- locale/ko.po | 17 +++++++++++++++-- locale/nl.po | 20 +++++++++++++++----- locale/pl.po | 17 +++++++++++++++-- locale/pt_BR.po | 20 +++++++++++++++----- locale/sv.po | 20 +++++++++++++++----- locale/zh_Latn_pinyin.po | 17 +++++++++++++++-- 15 files changed, 225 insertions(+), 48 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index b553c67495..ec5b6f6e86 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-14 09:36-0400\n" +"POT-Creation-Date: 2020-08-18 11:19-0400\n" "PO-Revision-Date: 2020-07-06 18:10+0000\n" "Last-Translator: oon arfiandwi \n" "Language-Team: LANGUAGE \n" @@ -764,7 +764,7 @@ msgstr "Error pada regex" #: shared-bindings/aesio/aes.c shared-bindings/busio/SPI.c #: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "Diharapkan %q" @@ -1352,6 +1352,15 @@ msgstr "Tambahkan module apapun pada filesystem\n" msgid "Polygon needs at least 3 points" msgstr "" +#: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/cxd56/common-hal/pulseio/PulseOut.c +#: ports/nrf/common-hal/pulseio/PulseOut.c +#: ports/stm/common-hal/pulseio/PulseOut.c +msgid "" +"Port does not accept pins or frequency. " +"Construct and pass a PWMOut Carrier instead" +msgstr "" + #: shared-bindings/_bleio/Adapter.c msgid "Prefix buffer must be on the heap" msgstr "" @@ -1366,6 +1375,10 @@ msgstr "" msgid "Pull not used when direction is output." msgstr "" +#: ports/stm/ref/pulseout-pre-timeralloc.c +msgid "PulseOut not supported on this chip" +msgstr "" + #: ports/stm/common-hal/os/__init__.c msgid "RNG DeInit Error" msgstr "" diff --git a/locale/cs.po b/locale/cs.po index c1a8ded4e9..b353f46306 100644 --- a/locale/cs.po +++ b/locale/cs.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-14 09:36-0400\n" +"POT-Creation-Date: 2020-08-18 11:19-0400\n" "PO-Revision-Date: 2020-05-24 03:22+0000\n" "Last-Translator: dronecz \n" "Language-Team: LANGUAGE \n" @@ -750,7 +750,7 @@ msgstr "" #: shared-bindings/aesio/aes.c shared-bindings/busio/SPI.c #: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "" @@ -1334,6 +1334,15 @@ msgstr "" msgid "Polygon needs at least 3 points" msgstr "" +#: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/cxd56/common-hal/pulseio/PulseOut.c +#: ports/nrf/common-hal/pulseio/PulseOut.c +#: ports/stm/common-hal/pulseio/PulseOut.c +msgid "" +"Port does not accept pins or frequency. " +"Construct and pass a PWMOut Carrier instead" +msgstr "" + #: shared-bindings/_bleio/Adapter.c msgid "Prefix buffer must be on the heap" msgstr "" @@ -1346,6 +1355,10 @@ msgstr "" msgid "Pull not used when direction is output." msgstr "" +#: ports/stm/ref/pulseout-pre-timeralloc.c +msgid "PulseOut not supported on this chip" +msgstr "" + #: ports/stm/common-hal/os/__init__.c msgid "RNG DeInit Error" msgstr "" diff --git a/locale/de_DE.po b/locale/de_DE.po index 10c07f667c..87cca4a77f 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-14 09:36-0400\n" +"POT-Creation-Date: 2020-08-18 11:19-0400\n" "PO-Revision-Date: 2020-06-16 18:24+0000\n" "Last-Translator: Andreas Buchen \n" "Language: de_DE\n" @@ -760,7 +760,7 @@ msgstr "Fehler in regex" #: shared-bindings/aesio/aes.c shared-bindings/busio/SPI.c #: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "Erwartet ein(e) %q" @@ -1362,6 +1362,15 @@ msgstr "und alle Module im Dateisystem \n" msgid "Polygon needs at least 3 points" msgstr "Polygone brauchen mindestens 3 Punkte" +#: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/cxd56/common-hal/pulseio/PulseOut.c +#: ports/nrf/common-hal/pulseio/PulseOut.c +#: ports/stm/common-hal/pulseio/PulseOut.c +msgid "" +"Port does not accept pins or frequency. " +"Construct and pass a PWMOut Carrier instead" +msgstr "" + #: shared-bindings/_bleio/Adapter.c msgid "Prefix buffer must be on the heap" msgstr "Der Präfixbuffer muss sich auf dem Heap befinden" @@ -1376,6 +1385,10 @@ msgstr "" msgid "Pull not used when direction is output." msgstr "Pull wird nicht verwendet, wenn die Richtung output ist." +#: ports/stm/ref/pulseout-pre-timeralloc.c +msgid "PulseOut not supported on this chip" +msgstr "PulseOut wird auf diesem Chip nicht unterstützt" + #: ports/stm/common-hal/os/__init__.c msgid "RNG DeInit Error" msgstr "RNG DeInit-Fehler" @@ -3553,9 +3566,6 @@ msgstr "" #~ msgid "'async for' or 'async with' outside async function" #~ msgstr "'async for' oder 'async with' außerhalb der asynchronen Funktion" -#~ msgid "PulseOut not supported on this chip" -#~ msgstr "PulseOut wird auf diesem Chip nicht unterstützt" - #~ msgid "PulseIn not supported on this chip" #~ msgstr "PulseIn wird auf diesem Chip nicht unterstützt" diff --git a/locale/es.po b/locale/es.po index 5012b749be..882904f640 100644 --- a/locale/es.po +++ b/locale/es.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-14 09:36-0400\n" +"POT-Creation-Date: 2020-08-18 11:19-0400\n" "PO-Revision-Date: 2020-08-17 21:11+0000\n" "Last-Translator: Alvaro Figueroa \n" "Language-Team: \n" @@ -765,7 +765,7 @@ msgstr "Error en regex" #: shared-bindings/aesio/aes.c shared-bindings/busio/SPI.c #: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "Se espera un %q" @@ -1362,6 +1362,15 @@ msgstr "Además de cualquier módulo en el sistema de archivos\n" msgid "Polygon needs at least 3 points" msgstr "El polígono necesita al menos 3 puntos" +#: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/cxd56/common-hal/pulseio/PulseOut.c +#: ports/nrf/common-hal/pulseio/PulseOut.c +#: ports/stm/common-hal/pulseio/PulseOut.c +msgid "" +"Port does not accept pins or frequency. " +"Construct and pass a PWMOut Carrier instead" +msgstr "" + #: shared-bindings/_bleio/Adapter.c msgid "Prefix buffer must be on the heap" msgstr "El búfer de prefijo debe estar en el montículo" @@ -1375,6 +1384,10 @@ msgstr "" msgid "Pull not used when direction is output." msgstr "Pull no se usa cuando la dirección es output." +#: ports/stm/ref/pulseout-pre-timeralloc.c +msgid "PulseOut not supported on this chip" +msgstr "PulseOut no es compatible con este chip" + #: ports/stm/common-hal/os/__init__.c msgid "RNG DeInit Error" msgstr "Error de desinicializado del RNG" @@ -3539,9 +3552,6 @@ msgstr "zi debe ser una forma (n_section,2)" #~ msgid "'async for' or 'async with' outside async function" #~ msgstr "'async for' o 'async with' fuera de la función async" -#~ msgid "PulseOut not supported on this chip" -#~ msgstr "PulseOut no es compatible con este chip" - #~ msgid "PulseIn not supported on this chip" #~ msgstr "PulseIn no es compatible con este chip" diff --git a/locale/fil.po b/locale/fil.po index 37a21dc6a7..ec4f9f6856 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-14 09:36-0400\n" +"POT-Creation-Date: 2020-08-18 11:19-0400\n" "PO-Revision-Date: 2018-12-20 22:15-0800\n" "Last-Translator: Timothy \n" "Language-Team: fil\n" @@ -754,7 +754,7 @@ msgstr "May pagkakamali sa REGEX" #: shared-bindings/aesio/aes.c shared-bindings/busio/SPI.c #: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "Umasa ng %q" @@ -1346,6 +1346,15 @@ msgstr "Kasama ang kung ano pang modules na sa filesystem\n" msgid "Polygon needs at least 3 points" msgstr "" +#: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/cxd56/common-hal/pulseio/PulseOut.c +#: ports/nrf/common-hal/pulseio/PulseOut.c +#: ports/stm/common-hal/pulseio/PulseOut.c +msgid "" +"Port does not accept pins or frequency. " +"Construct and pass a PWMOut Carrier instead" +msgstr "" + #: shared-bindings/_bleio/Adapter.c msgid "Prefix buffer must be on the heap" msgstr "" @@ -1360,6 +1369,10 @@ msgstr "" msgid "Pull not used when direction is output." msgstr "Pull hindi ginagamit kapag ang direksyon ay output." +#: ports/stm/ref/pulseout-pre-timeralloc.c +msgid "PulseOut not supported on this chip" +msgstr "" + #: ports/stm/common-hal/os/__init__.c msgid "RNG DeInit Error" msgstr "" diff --git a/locale/fr.po b/locale/fr.po index 419cef785e..0562053f15 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-14 09:36-0400\n" +"POT-Creation-Date: 2020-08-18 11:19-0400\n" "PO-Revision-Date: 2020-07-27 21:27+0000\n" "Last-Translator: Nathan \n" "Language: fr\n" @@ -768,7 +768,7 @@ msgstr "Erreur dans l'expression régulière" #: shared-bindings/aesio/aes.c shared-bindings/busio/SPI.c #: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "Attendu un %q" @@ -1369,6 +1369,15 @@ msgstr "Ainsi que tout autre module présent sur le système de fichiers\n" msgid "Polygon needs at least 3 points" msgstr "Polygone a besoin d’au moins 3 points" +#: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/cxd56/common-hal/pulseio/PulseOut.c +#: ports/nrf/common-hal/pulseio/PulseOut.c +#: ports/stm/common-hal/pulseio/PulseOut.c +msgid "" +"Port does not accept pins or frequency. " +"Construct and pass a PWMOut Carrier instead" +msgstr "" + #: shared-bindings/_bleio/Adapter.c msgid "Prefix buffer must be on the heap" msgstr "Le tampon de préfixe doit être sur le tas" @@ -1381,6 +1390,10 @@ msgstr "Appuyez sur une touche pour entrer sur REPL ou CTRL-D pour recharger." msgid "Pull not used when direction is output." msgstr "Le tirage 'pull' n'est pas utilisé quand la direction est 'output'." +#: ports/stm/ref/pulseout-pre-timeralloc.c +msgid "PulseOut not supported on this chip" +msgstr "PulseOut non pris en charge sur cette puce" + #: ports/stm/common-hal/os/__init__.c msgid "RNG DeInit Error" msgstr "Erreur RNG DeInit" @@ -3557,9 +3570,6 @@ msgstr "" #~ msgid "'async for' or 'async with' outside async function" #~ msgstr "'async for' ou 'async with' sans fonction asynchrone extérieure" -#~ msgid "PulseOut not supported on this chip" -#~ msgstr "PulseOut non pris en charge sur cette puce" - #~ msgid "PulseIn not supported on this chip" #~ msgstr "PulseIn non pris en charge sur cette puce" diff --git a/locale/hi.po b/locale/hi.po index 9d0dd74e90..50a1887f67 100644 --- a/locale/hi.po +++ b/locale/hi.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-14 09:36-0400\n" +"POT-Creation-Date: 2020-08-18 11:19-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Automatically generated\n" "Language-Team: none\n" @@ -743,7 +743,7 @@ msgstr "" #: shared-bindings/aesio/aes.c shared-bindings/busio/SPI.c #: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "" @@ -1327,6 +1327,15 @@ msgstr "" msgid "Polygon needs at least 3 points" msgstr "" +#: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/cxd56/common-hal/pulseio/PulseOut.c +#: ports/nrf/common-hal/pulseio/PulseOut.c +#: ports/stm/common-hal/pulseio/PulseOut.c +msgid "" +"Port does not accept pins or frequency. " +"Construct and pass a PWMOut Carrier instead" +msgstr "" + #: shared-bindings/_bleio/Adapter.c msgid "Prefix buffer must be on the heap" msgstr "" @@ -1339,6 +1348,10 @@ msgstr "" msgid "Pull not used when direction is output." msgstr "" +#: ports/stm/ref/pulseout-pre-timeralloc.c +msgid "PulseOut not supported on this chip" +msgstr "" + #: ports/stm/common-hal/os/__init__.c msgid "RNG DeInit Error" msgstr "" diff --git a/locale/it_IT.po b/locale/it_IT.po index e128b7ef91..9635220af3 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-14 09:36-0400\n" +"POT-Creation-Date: 2020-08-18 11:19-0400\n" "PO-Revision-Date: 2018-10-02 16:27+0200\n" "Last-Translator: Enrico Paganin \n" "Language-Team: \n" @@ -754,7 +754,7 @@ msgstr "Errore nella regex" #: shared-bindings/aesio/aes.c shared-bindings/busio/SPI.c #: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "Atteso un %q" @@ -1356,6 +1356,15 @@ msgstr "Imposssibile rimontare il filesystem" msgid "Polygon needs at least 3 points" msgstr "" +#: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/cxd56/common-hal/pulseio/PulseOut.c +#: ports/nrf/common-hal/pulseio/PulseOut.c +#: ports/stm/common-hal/pulseio/PulseOut.c +msgid "" +"Port does not accept pins or frequency. " +"Construct and pass a PWMOut Carrier instead" +msgstr "" + #: shared-bindings/_bleio/Adapter.c msgid "Prefix buffer must be on the heap" msgstr "" @@ -1369,6 +1378,10 @@ msgstr "" msgid "Pull not used when direction is output." msgstr "" +#: ports/stm/ref/pulseout-pre-timeralloc.c +msgid "PulseOut not supported on this chip" +msgstr "" + #: ports/stm/common-hal/os/__init__.c msgid "RNG DeInit Error" msgstr "" diff --git a/locale/ja.po b/locale/ja.po index 8385cce1b9..7c3b42580a 100644 --- a/locale/ja.po +++ b/locale/ja.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-14 09:36-0400\n" +"POT-Creation-Date: 2020-08-18 11:19-0400\n" "PO-Revision-Date: 2020-08-16 13:25+0000\n" "Last-Translator: Taku Fukada \n" "Language-Team: none\n" @@ -759,7 +759,7 @@ msgstr "正規表現にエラーがあります" #: shared-bindings/aesio/aes.c shared-bindings/busio/SPI.c #: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "" @@ -1348,6 +1348,15 @@ msgstr "" msgid "Polygon needs at least 3 points" msgstr "ポリゴンには少なくとも3つの点が必要" +#: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/cxd56/common-hal/pulseio/PulseOut.c +#: ports/nrf/common-hal/pulseio/PulseOut.c +#: ports/stm/common-hal/pulseio/PulseOut.c +msgid "" +"Port does not accept pins or frequency. " +"Construct and pass a PWMOut Carrier instead" +msgstr "" + #: shared-bindings/_bleio/Adapter.c msgid "Prefix buffer must be on the heap" msgstr "Prefixバッファはヒープ上になければなりません" @@ -1361,6 +1370,10 @@ msgstr "何らかのキーを押すとREPLに入ります。CTRL-Dでリロー msgid "Pull not used when direction is output." msgstr "方向がoutputのときpullは使われません" +#: ports/stm/ref/pulseout-pre-timeralloc.c +msgid "PulseOut not supported on this chip" +msgstr "" + #: ports/stm/common-hal/os/__init__.c msgid "RNG DeInit Error" msgstr "乱数生成器の解体エラー" diff --git a/locale/ko.po b/locale/ko.po index e86372bcb1..ecf539946f 100644 --- a/locale/ko.po +++ b/locale/ko.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-14 09:36-0400\n" +"POT-Creation-Date: 2020-08-18 11:19-0400\n" "PO-Revision-Date: 2019-05-06 14:22-0700\n" "Last-Translator: \n" "Language-Team: LANGUAGE \n" @@ -746,7 +746,7 @@ msgstr "Regex에 오류가 있습니다." #: shared-bindings/aesio/aes.c shared-bindings/busio/SPI.c #: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "%q 이 예상되었습니다." @@ -1330,6 +1330,15 @@ msgstr "" msgid "Polygon needs at least 3 points" msgstr "" +#: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/cxd56/common-hal/pulseio/PulseOut.c +#: ports/nrf/common-hal/pulseio/PulseOut.c +#: ports/stm/common-hal/pulseio/PulseOut.c +msgid "" +"Port does not accept pins or frequency. " +"Construct and pass a PWMOut Carrier instead" +msgstr "" + #: shared-bindings/_bleio/Adapter.c msgid "Prefix buffer must be on the heap" msgstr "" @@ -1342,6 +1351,10 @@ msgstr "" msgid "Pull not used when direction is output." msgstr "" +#: ports/stm/ref/pulseout-pre-timeralloc.c +msgid "PulseOut not supported on this chip" +msgstr "" + #: ports/stm/common-hal/os/__init__.c msgid "RNG DeInit Error" msgstr "" diff --git a/locale/nl.po b/locale/nl.po index b26592f1e0..3133596686 100644 --- a/locale/nl.po +++ b/locale/nl.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-14 09:36-0400\n" +"POT-Creation-Date: 2020-08-18 11:19-0400\n" "PO-Revision-Date: 2020-08-10 19:59+0000\n" "Last-Translator: _fonzlate \n" "Language-Team: none\n" @@ -762,7 +762,7 @@ msgstr "Fout in regex" #: shared-bindings/aesio/aes.c shared-bindings/busio/SPI.c #: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "Verwacht een %q" @@ -1364,6 +1364,15 @@ msgstr "En iedere module in het bestandssysteem\n" msgid "Polygon needs at least 3 points" msgstr "Polygon heeft op zijn minst 3 punten nodig" +#: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/cxd56/common-hal/pulseio/PulseOut.c +#: ports/nrf/common-hal/pulseio/PulseOut.c +#: ports/stm/common-hal/pulseio/PulseOut.c +msgid "" +"Port does not accept pins or frequency. " +"Construct and pass a PWMOut Carrier instead" +msgstr "" + #: shared-bindings/_bleio/Adapter.c msgid "Prefix buffer must be on the heap" msgstr "Prefix buffer moet op de heap zijn" @@ -1378,6 +1387,10 @@ msgstr "" msgid "Pull not used when direction is output." msgstr "Pull niet gebruikt wanneer de richting output is." +#: ports/stm/ref/pulseout-pre-timeralloc.c +msgid "PulseOut not supported on this chip" +msgstr "PulseOut niet ondersteund door deze chip" + #: ports/stm/common-hal/os/__init__.c msgid "RNG DeInit Error" msgstr "RNG DeInit Fout" @@ -3531,9 +3544,6 @@ msgstr "zi moet vorm (n_section, 2) hebben" #~ msgid "PulseIn not supported on this chip" #~ msgstr "PusleIn niet ondersteund door deze chip" -#~ msgid "PulseOut not supported on this chip" -#~ msgstr "PulseOut niet ondersteund door deze chip" - #~ msgid "I2C operation not supported" #~ msgstr "I2C actie niet ondersteund" diff --git a/locale/pl.po b/locale/pl.po index 8250f840d2..6c52062d9a 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-14 09:36-0400\n" +"POT-Creation-Date: 2020-08-18 11:19-0400\n" "PO-Revision-Date: 2019-03-19 18:37-0700\n" "Last-Translator: Radomir Dopieralski \n" "Language-Team: pl\n" @@ -746,7 +746,7 @@ msgstr "Błąd w regex" #: shared-bindings/aesio/aes.c shared-bindings/busio/SPI.c #: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "Oczekiwano %q" @@ -1332,6 +1332,15 @@ msgstr "Oraz moduły w systemie plików\n" msgid "Polygon needs at least 3 points" msgstr "" +#: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/cxd56/common-hal/pulseio/PulseOut.c +#: ports/nrf/common-hal/pulseio/PulseOut.c +#: ports/stm/common-hal/pulseio/PulseOut.c +msgid "" +"Port does not accept pins or frequency. " +"Construct and pass a PWMOut Carrier instead" +msgstr "" + #: shared-bindings/_bleio/Adapter.c msgid "Prefix buffer must be on the heap" msgstr "" @@ -1344,6 +1353,10 @@ msgstr "Dowolny klawisz aby uruchomić konsolę. CTRL-D aby przeładować." msgid "Pull not used when direction is output." msgstr "Podciągnięcie nieużywane w trybie wyjścia." +#: ports/stm/ref/pulseout-pre-timeralloc.c +msgid "PulseOut not supported on this chip" +msgstr "" + #: ports/stm/common-hal/os/__init__.c msgid "RNG DeInit Error" msgstr "" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 459b198df3..b2967cf992 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-14 09:36-0400\n" +"POT-Creation-Date: 2020-08-18 11:19-0400\n" "PO-Revision-Date: 2020-08-16 02:25+0000\n" "Last-Translator: Wellington Terumi Uemura \n" "Language-Team: \n" @@ -767,7 +767,7 @@ msgstr "Erro no regex" #: shared-bindings/aesio/aes.c shared-bindings/busio/SPI.c #: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "Esperado um" @@ -1367,6 +1367,15 @@ msgstr "Além de quaisquer módulos no sistema de arquivos\n" msgid "Polygon needs at least 3 points" msgstr "O Polígono precisa de pelo menos 3 pontos" +#: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/cxd56/common-hal/pulseio/PulseOut.c +#: ports/nrf/common-hal/pulseio/PulseOut.c +#: ports/stm/common-hal/pulseio/PulseOut.c +msgid "" +"Port does not accept pins or frequency. " +"Construct and pass a PWMOut Carrier instead" +msgstr "" + #: shared-bindings/_bleio/Adapter.c msgid "Prefix buffer must be on the heap" msgstr "" @@ -1382,6 +1391,10 @@ msgstr "" msgid "Pull not used when direction is output." msgstr "O Pull não foi usado quando a direção for gerada." +#: ports/stm/ref/pulseout-pre-timeralloc.c +msgid "PulseOut not supported on this chip" +msgstr "O PulseOut não é compatível neste CI" + #: ports/stm/common-hal/os/__init__.c msgid "RNG DeInit Error" msgstr "Erro DeInit RNG" @@ -3552,9 +3565,6 @@ msgstr "zi deve estar na forma (n_section, 2)" #~ msgid "'async for' or 'async with' outside async function" #~ msgstr "'assíncrono para' ou 'assíncrono com' função assíncrona externa" -#~ msgid "PulseOut not supported on this chip" -#~ msgstr "O PulseOut não é compatível neste CI" - #~ msgid "PulseIn not supported on this chip" #~ msgstr "O PulseIn não é compatível neste CI" diff --git a/locale/sv.po b/locale/sv.po index d747de177a..df205b1095 100644 --- a/locale/sv.po +++ b/locale/sv.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-14 09:36-0400\n" +"POT-Creation-Date: 2020-08-18 11:19-0400\n" "PO-Revision-Date: 2020-07-25 20:58+0000\n" "Last-Translator: Jonny Bergdahl \n" "Language-Team: LANGUAGE \n" @@ -758,7 +758,7 @@ msgstr "Fel i regex" #: shared-bindings/aesio/aes.c shared-bindings/busio/SPI.c #: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "Förväntade %q" @@ -1355,6 +1355,15 @@ msgstr "Plus eventuella moduler i filsystemet\n" msgid "Polygon needs at least 3 points" msgstr "Polygonen behöver minst 3 punkter" +#: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/cxd56/common-hal/pulseio/PulseOut.c +#: ports/nrf/common-hal/pulseio/PulseOut.c +#: ports/stm/common-hal/pulseio/PulseOut.c +msgid "" +"Port does not accept pins or frequency. " +"Construct and pass a PWMOut Carrier instead" +msgstr "" + #: shared-bindings/_bleio/Adapter.c msgid "Prefix buffer must be on the heap" msgstr "Prefixbufferten måste finnas på heap" @@ -1368,6 +1377,10 @@ msgstr "" msgid "Pull not used when direction is output." msgstr "Pull används inte när riktningen är output." +#: ports/stm/ref/pulseout-pre-timeralloc.c +msgid "PulseOut not supported on this chip" +msgstr "PulseIn stöds inte av detta chip" + #: ports/stm/common-hal/os/__init__.c msgid "RNG DeInit Error" msgstr "RNG DeInit-fel" @@ -3519,9 +3532,6 @@ msgstr "zi måste vara i formen (n_section, 2)" #~ msgid "'async for' or 'async with' outside async function" #~ msgstr "'async for' eller 'async with' utanför async-funktion" -#~ msgid "PulseOut not supported on this chip" -#~ msgstr "PulseIn stöds inte av detta chip" - #~ msgid "PulseIn not supported on this chip" #~ msgstr "PulseIn stöds inte av detta chip" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index 3e5d21d458..725491f5b2 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: circuitpython-cn\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-14 09:36-0400\n" +"POT-Creation-Date: 2020-08-18 11:19-0400\n" "PO-Revision-Date: 2019-04-13 10:10-0700\n" "Last-Translator: hexthat\n" "Language-Team: Chinese Hanyu Pinyin\n" @@ -755,7 +755,7 @@ msgstr "Zhèngzé biǎodá shì cuòwù" #: shared-bindings/aesio/aes.c shared-bindings/busio/SPI.c #: shared-bindings/microcontroller/Pin.c -#: shared-bindings/neopixel_write/__init__.c shared-bindings/pulseio/PulseOut.c +#: shared-bindings/neopixel_write/__init__.c #: shared-bindings/terminalio/Terminal.c msgid "Expected a %q" msgstr "Yùqí %q" @@ -1350,6 +1350,15 @@ msgstr "Zài wénjiàn xìtǒng shàng tiānjiā rènhé mókuài\n" msgid "Polygon needs at least 3 points" msgstr "Duōbiānxíng zhìshǎo xūyào 3 diǎn" +#: ports/atmel-samd/common-hal/pulseio/PulseOut.c +#: ports/cxd56/common-hal/pulseio/PulseOut.c +#: ports/nrf/common-hal/pulseio/PulseOut.c +#: ports/stm/common-hal/pulseio/PulseOut.c +msgid "" +"Port does not accept pins or frequency. " +"Construct and pass a PWMOut Carrier instead" +msgstr "" + #: shared-bindings/_bleio/Adapter.c msgid "Prefix buffer must be on the heap" msgstr "Qiánzhuì huǎnchōng qū bìxū zài duī shàng" @@ -1362,6 +1371,10 @@ msgstr "Àn xià rènhé jiàn jìnrù REPL. Shǐyòng CTRL-D chóngxīn jiāzà msgid "Pull not used when direction is output." msgstr "Fāngxiàng shūchū shí Pull méiyǒu shǐyòng." +#: ports/stm/ref/pulseout-pre-timeralloc.c +msgid "PulseOut not supported on this chip" +msgstr "" + #: ports/stm/common-hal/os/__init__.c msgid "RNG DeInit Error" msgstr "RNG qǔxiāo chūshǐhuà cuòwù" From 83deea0e0364cfce83d6cf1c5c5f150a1a986d93 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 21 Aug 2020 11:17:42 -0700 Subject: [PATCH 24/79] Fix copy pasta and stub build --- ports/cxd56/common-hal/pwmio/__init__.c | 2 +- ports/esp32s2/common-hal/pwmio/__init__.c | 2 +- ports/mimxrt10xx/common-hal/pwmio/__init__.c | 2 +- shared-bindings/pulseio/__init__.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ports/cxd56/common-hal/pwmio/__init__.c b/ports/cxd56/common-hal/pwmio/__init__.c index 2bee925bc7..9e551a1072 100644 --- a/ports/cxd56/common-hal/pwmio/__init__.c +++ b/ports/cxd56/common-hal/pwmio/__init__.c @@ -1 +1 @@ -// No pulseio module functions. +// No pwmio module functions. diff --git a/ports/esp32s2/common-hal/pwmio/__init__.c b/ports/esp32s2/common-hal/pwmio/__init__.c index 2bee925bc7..9e551a1072 100644 --- a/ports/esp32s2/common-hal/pwmio/__init__.c +++ b/ports/esp32s2/common-hal/pwmio/__init__.c @@ -1 +1 @@ -// No pulseio module functions. +// No pwmio module functions. diff --git a/ports/mimxrt10xx/common-hal/pwmio/__init__.c b/ports/mimxrt10xx/common-hal/pwmio/__init__.c index 2bee925bc7..9e551a1072 100644 --- a/ports/mimxrt10xx/common-hal/pwmio/__init__.c +++ b/ports/mimxrt10xx/common-hal/pwmio/__init__.c @@ -1 +1 @@ -// No pulseio module functions. +// No pwmio module functions. diff --git a/shared-bindings/pulseio/__init__.c b/shared-bindings/pulseio/__init__.c index efef640433..624cd2dfe8 100644 --- a/shared-bindings/pulseio/__init__.c +++ b/shared-bindings/pulseio/__init__.c @@ -48,7 +48,7 @@ //| All classes change hardware state and should be deinitialized when they //| are no longer needed if the program continues after use. To do so, either //| call :py:meth:`!deinit` or use a context manager. See -//| :ref:`lifetime-and-contextmanagers` for more info. +//| :ref:`lifetime-and-contextmanagers` for more info.""" //| STATIC const mp_rom_map_elem_t pulseio_module_globals_table[] = { From 1fc551054a08c90c793a9dafc7d5e3551b6a3ab2 Mon Sep 17 00:00:00 2001 From: Wellington Terumi Uemura Date: Fri, 21 Aug 2020 16:07:43 +0000 Subject: [PATCH 25/79] Translated using Weblate (Portuguese (Brazil)) Currently translated at 100.0% (777 of 777 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/pt_BR/ --- locale/pt_BR.po | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/locale/pt_BR.po b/locale/pt_BR.po index b2967cf992..9fb4142c47 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: 2020-08-18 11:19-0400\n" -"PO-Revision-Date: 2020-08-16 02:25+0000\n" +"PO-Revision-Date: 2020-08-21 18:19+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.2-dev\n" +"X-Generator: Weblate 4.2.1-dev\n" #: main.c msgid "" @@ -1375,6 +1375,8 @@ msgid "" "Port does not accept pins or frequency. " "Construct and pass a PWMOut Carrier instead" msgstr "" +"A porta não aceita pinos ou frequência. " +"Em vez disso, Construa e encaminhe um PWMOut Carrier" #: shared-bindings/_bleio/Adapter.c msgid "Prefix buffer must be on the heap" From 9a8b4e98bf0880a5ca703077faa0028c28f17ebb Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 21 Aug 2020 11:36:50 -0700 Subject: [PATCH 26/79] Add empty lines --- shared-bindings/pulseio/__init__.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared-bindings/pulseio/__init__.c b/shared-bindings/pulseio/__init__.c index 624cd2dfe8..bfe9635f01 100644 --- a/shared-bindings/pulseio/__init__.c +++ b/shared-bindings/pulseio/__init__.c @@ -41,10 +41,10 @@ //| Individual pulses are commonly used in infrared remotes and in DHT //| temperature sensors. //| - +//| //| .. warning:: PWMOut is moving to `pwmio` and will be removed from `pulseio` //| in CircuitPython 7. - +//| //| All classes change hardware state and should be deinitialized when they //| are no longer needed if the program continues after use. To do so, either //| call :py:meth:`!deinit` or use a context manager. See From 1e7e42b2217582fcd596dcb737dbf5cd1f7521cb Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Fri, 21 Aug 2020 14:17:17 -0500 Subject: [PATCH 27/79] Updating to adafruit/main --- extmod/ulab | 2 +- frozen/Adafruit_CircuitPython_BLE | 2 +- frozen/Adafruit_CircuitPython_BLE_Apple_Notification_Center | 2 +- frozen/Adafruit_CircuitPython_BusDevice | 2 +- frozen/Adafruit_CircuitPython_CircuitPlayground | 2 +- frozen/Adafruit_CircuitPython_Crickit | 2 +- frozen/Adafruit_CircuitPython_DRV2605 | 2 +- frozen/Adafruit_CircuitPython_DS3231 | 2 +- frozen/Adafruit_CircuitPython_ESP32SPI | 2 +- frozen/Adafruit_CircuitPython_FocalTouch | 2 +- frozen/Adafruit_CircuitPython_HID | 2 +- frozen/Adafruit_CircuitPython_IRRemote | 2 +- frozen/Adafruit_CircuitPython_LIS3DH | 2 +- frozen/Adafruit_CircuitPython_LSM6DS | 2 +- frozen/Adafruit_CircuitPython_Motor | 2 +- frozen/Adafruit_CircuitPython_Register | 2 +- frozen/Adafruit_CircuitPython_Requests | 2 +- frozen/Adafruit_CircuitPython_Thermistor | 2 +- frozen/Adafruit_CircuitPython_seesaw | 2 +- frozen/circuitpython-stage | 2 +- lib/mp3 | 2 +- lib/protomatter | 2 +- lib/tinyusb | 2 +- ports/atmel-samd/asf4 | 2 +- ports/atmel-samd/peripherals | 2 +- ports/cxd56/spresense-exported-sdk | 2 +- ports/esp32s2/esp-idf | 2 +- ports/stm/st_driver | 2 +- 28 files changed, 28 insertions(+), 28 deletions(-) diff --git a/extmod/ulab b/extmod/ulab index cf61d728e7..11a7ecff6d 160000 --- a/extmod/ulab +++ b/extmod/ulab @@ -1 +1 @@ -Subproject commit cf61d728e70b9ec57e5711b40540793a89296f5d +Subproject commit 11a7ecff6d76a02644ff23a734b792afaa615e44 diff --git a/frozen/Adafruit_CircuitPython_BLE b/frozen/Adafruit_CircuitPython_BLE index 5d584576ef..41f7a3530d 160000 --- a/frozen/Adafruit_CircuitPython_BLE +++ b/frozen/Adafruit_CircuitPython_BLE @@ -1 +1 @@ -Subproject commit 5d584576ef79ca36506e6c7470e7ac5204cf0a8d +Subproject commit 41f7a3530d4cacdbf668399d3a015ea29c7e169b diff --git a/frozen/Adafruit_CircuitPython_BLE_Apple_Notification_Center b/frozen/Adafruit_CircuitPython_BLE_Apple_Notification_Center index 3ffb3f02d2..6a034887e3 160000 --- a/frozen/Adafruit_CircuitPython_BLE_Apple_Notification_Center +++ b/frozen/Adafruit_CircuitPython_BLE_Apple_Notification_Center @@ -1 +1 @@ -Subproject commit 3ffb3f02d2046910e09d1f5a74721bd1a4cdf8cf +Subproject commit 6a034887e370caa61fee5f51db8dd393d3e72542 diff --git a/frozen/Adafruit_CircuitPython_BusDevice b/frozen/Adafruit_CircuitPython_BusDevice index e9411c4244..eb4b21e216 160000 --- a/frozen/Adafruit_CircuitPython_BusDevice +++ b/frozen/Adafruit_CircuitPython_BusDevice @@ -1 +1 @@ -Subproject commit e9411c4244984b69ec6928370ede40cec014c10b +Subproject commit eb4b21e216efd8ec0c4862a938e81b56be961724 diff --git a/frozen/Adafruit_CircuitPython_CircuitPlayground b/frozen/Adafruit_CircuitPython_CircuitPlayground index e9f15d6150..3c540329b6 160000 --- a/frozen/Adafruit_CircuitPython_CircuitPlayground +++ b/frozen/Adafruit_CircuitPython_CircuitPlayground @@ -1 +1 @@ -Subproject commit e9f15d61502f34173912ba271aaaf9446dae8da1 +Subproject commit 3c540329b63163e45f108df4bfebc387d5352c4f diff --git a/frozen/Adafruit_CircuitPython_Crickit b/frozen/Adafruit_CircuitPython_Crickit index 0e1230676a..809646ba11 160000 --- a/frozen/Adafruit_CircuitPython_Crickit +++ b/frozen/Adafruit_CircuitPython_Crickit @@ -1 +1 @@ -Subproject commit 0e1230676a54da17a309d1dfffdd7fa90240191c +Subproject commit 809646ba11366b5aedbc8a90be1da1829304bf62 diff --git a/frozen/Adafruit_CircuitPython_DRV2605 b/frozen/Adafruit_CircuitPython_DRV2605 index 7914a63903..209edd164e 160000 --- a/frozen/Adafruit_CircuitPython_DRV2605 +++ b/frozen/Adafruit_CircuitPython_DRV2605 @@ -1 +1 @@ -Subproject commit 7914a6390318687bb8e2e9c4119aa932fea01531 +Subproject commit 209edd164eb640a8ced561a54505792fc99a67b9 diff --git a/frozen/Adafruit_CircuitPython_DS3231 b/frozen/Adafruit_CircuitPython_DS3231 index 0d49a1fcd9..5d81a9ea82 160000 --- a/frozen/Adafruit_CircuitPython_DS3231 +++ b/frozen/Adafruit_CircuitPython_DS3231 @@ -1 +1 @@ -Subproject commit 0d49a1fcd96c13a94e8bdf26f92abe79b8517906 +Subproject commit 5d81a9ea822a85e46be4a512ac44abf21e77d816 diff --git a/frozen/Adafruit_CircuitPython_ESP32SPI b/frozen/Adafruit_CircuitPython_ESP32SPI index 94b03517c1..01f3f6674b 160000 --- a/frozen/Adafruit_CircuitPython_ESP32SPI +++ b/frozen/Adafruit_CircuitPython_ESP32SPI @@ -1 +1 @@ -Subproject commit 94b03517c1f4ff68cc2bb09b0963f7e7e3ce3d04 +Subproject commit 01f3f6674b4493ba29b857e0f43deb69975736ec diff --git a/frozen/Adafruit_CircuitPython_FocalTouch b/frozen/Adafruit_CircuitPython_FocalTouch index 72968d3546..1e3312ab1c 160000 --- a/frozen/Adafruit_CircuitPython_FocalTouch +++ b/frozen/Adafruit_CircuitPython_FocalTouch @@ -1 +1 @@ -Subproject commit 72968d3546f9d6c5af138d4c179343007cb9662c +Subproject commit 1e3312ab1cba0b1d3bb1f559c52acfdc1a6d57b8 diff --git a/frozen/Adafruit_CircuitPython_HID b/frozen/Adafruit_CircuitPython_HID index 65fb213b8c..829ba0f0a2 160000 --- a/frozen/Adafruit_CircuitPython_HID +++ b/frozen/Adafruit_CircuitPython_HID @@ -1 +1 @@ -Subproject commit 65fb213b8c554181d54b77f75335e16e2f4c0987 +Subproject commit 829ba0f0a2d8a63f7d0215c6c9fc821e14e52a93 diff --git a/frozen/Adafruit_CircuitPython_IRRemote b/frozen/Adafruit_CircuitPython_IRRemote index d435fc9a9d..fc3a7b4798 160000 --- a/frozen/Adafruit_CircuitPython_IRRemote +++ b/frozen/Adafruit_CircuitPython_IRRemote @@ -1 +1 @@ -Subproject commit d435fc9a9d90cb063608ae037bf5284b33bc5e84 +Subproject commit fc3a7b479874a1ea315ddb3bf6c5e281e16ef097 diff --git a/frozen/Adafruit_CircuitPython_LIS3DH b/frozen/Adafruit_CircuitPython_LIS3DH index 457aba6dd5..9fe8f314c0 160000 --- a/frozen/Adafruit_CircuitPython_LIS3DH +++ b/frozen/Adafruit_CircuitPython_LIS3DH @@ -1 +1 @@ -Subproject commit 457aba6dd59ad00502b80c9031655d3d26ecc82b +Subproject commit 9fe8f314c032cee89b9ad7697d61e9cba76431ff diff --git a/frozen/Adafruit_CircuitPython_LSM6DS b/frozen/Adafruit_CircuitPython_LSM6DS index ee8f2187d4..f1cc47f024 160000 --- a/frozen/Adafruit_CircuitPython_LSM6DS +++ b/frozen/Adafruit_CircuitPython_LSM6DS @@ -1 +1 @@ -Subproject commit ee8f2187d4795b08ae4aa60558f564d26c997be9 +Subproject commit f1cc47f024b27e670b9bf2a51c89e32f93c1b957 diff --git a/frozen/Adafruit_CircuitPython_Motor b/frozen/Adafruit_CircuitPython_Motor index 5fd72fb963..434e5b5346 160000 --- a/frozen/Adafruit_CircuitPython_Motor +++ b/frozen/Adafruit_CircuitPython_Motor @@ -1 +1 @@ -Subproject commit 5fd72fb963c4a0318d29282ca2cc988f19787fda +Subproject commit 434e5b5346cb0a1a9eb15989b00278be87cb2ff1 diff --git a/frozen/Adafruit_CircuitPython_Register b/frozen/Adafruit_CircuitPython_Register index 56358b4494..6143ec2a96 160000 --- a/frozen/Adafruit_CircuitPython_Register +++ b/frozen/Adafruit_CircuitPython_Register @@ -1 +1 @@ -Subproject commit 56358b4494da825cd99a56a854119f926abca670 +Subproject commit 6143ec2a96a6d218041e9cab5968de26702d7bbf diff --git a/frozen/Adafruit_CircuitPython_Requests b/frozen/Adafruit_CircuitPython_Requests index 41de8b3c05..43017e30a1 160000 --- a/frozen/Adafruit_CircuitPython_Requests +++ b/frozen/Adafruit_CircuitPython_Requests @@ -1 +1 @@ -Subproject commit 41de8b3c05dd78d7be8893a0f6cb47a7e9b421a2 +Subproject commit 43017e30a1e772b67ac68293a944e863c031e389 diff --git a/frozen/Adafruit_CircuitPython_Thermistor b/frozen/Adafruit_CircuitPython_Thermistor index b5bbdbd56c..fb773e0ed1 160000 --- a/frozen/Adafruit_CircuitPython_Thermistor +++ b/frozen/Adafruit_CircuitPython_Thermistor @@ -1 +1 @@ -Subproject commit b5bbdbd56ca205c581ba2c84d927ef99befce88e +Subproject commit fb773e0ed1891cda2ace6271fafc5312e167d275 diff --git a/frozen/Adafruit_CircuitPython_seesaw b/frozen/Adafruit_CircuitPython_seesaw index 76c0dd1329..88738da275 160000 --- a/frozen/Adafruit_CircuitPython_seesaw +++ b/frozen/Adafruit_CircuitPython_seesaw @@ -1 +1 @@ -Subproject commit 76c0dd13294ce8ae0518cb9882dcad5d3668977e +Subproject commit 88738da275a83acabb14b7140d1c79b33cdc7b02 diff --git a/frozen/circuitpython-stage b/frozen/circuitpython-stage index 0d2c083a2f..9596a5904e 160000 --- a/frozen/circuitpython-stage +++ b/frozen/circuitpython-stage @@ -1 +1 @@ -Subproject commit 0d2c083a2fb57a1562d4806775f45273abbfbfae +Subproject commit 9596a5904ed757e6fbffcf03e7aa77ae9ecf5223 diff --git a/lib/mp3 b/lib/mp3 index c3c664bf4d..bc58a65496 160000 --- a/lib/mp3 +++ b/lib/mp3 @@ -1 +1 @@ -Subproject commit c3c664bf4db6a36d11808dfcbb5dbf7cff1715b8 +Subproject commit bc58a654964c799e972719a63ff12694998f3549 diff --git a/lib/protomatter b/lib/protomatter index 9f71088d2c..761d6437e8 160000 --- a/lib/protomatter +++ b/lib/protomatter @@ -1 +1 @@ -Subproject commit 9f71088d2c32206c6f0495704ae0c040426d5764 +Subproject commit 761d6437e8cd6a131d51de96974337121a9c7164 diff --git a/lib/tinyusb b/lib/tinyusb index dc5445e2f4..22100b252f 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit dc5445e2f45cb348a44fe24fc1be4bc8b5ba5bab +Subproject commit 22100b252fc2eb8f51ed407949645653c4880fd9 diff --git a/ports/atmel-samd/asf4 b/ports/atmel-samd/asf4 index 039b5f3bbc..35a1525796 160000 --- a/ports/atmel-samd/asf4 +++ b/ports/atmel-samd/asf4 @@ -1 +1 @@ -Subproject commit 039b5f3bbc3f4ba4421e581db290560d59fef625 +Subproject commit 35a1525796c7ef8a3893d90befdad2f267fca20e diff --git a/ports/atmel-samd/peripherals b/ports/atmel-samd/peripherals index 6b531fc923..0f5f1522d0 160000 --- a/ports/atmel-samd/peripherals +++ b/ports/atmel-samd/peripherals @@ -1 +1 @@ -Subproject commit 6b531fc923d9f02b14bd731a5f584ddf716e8773 +Subproject commit 0f5f1522d09c8fa7d858edec484a994c21c59668 diff --git a/ports/cxd56/spresense-exported-sdk b/ports/cxd56/spresense-exported-sdk index 7f6568c7f4..c991d439fa 160000 --- a/ports/cxd56/spresense-exported-sdk +++ b/ports/cxd56/spresense-exported-sdk @@ -1 +1 @@ -Subproject commit 7f6568c7f4898cdb24a2f06040784a836050686e +Subproject commit c991d439fac9c23cfcac0da16fe8055f818d40a4 diff --git a/ports/esp32s2/esp-idf b/ports/esp32s2/esp-idf index 0daf6e0e41..160ba4924d 160000 --- a/ports/esp32s2/esp-idf +++ b/ports/esp32s2/esp-idf @@ -1 +1 @@ -Subproject commit 0daf6e0e41f95d22d193d08941a00df9525bc405 +Subproject commit 160ba4924d8b588e718f76e3a0d0e92c11052fa3 diff --git a/ports/stm/st_driver b/ports/stm/st_driver index 3fc2e0f3db..1900834751 160000 --- a/ports/stm/st_driver +++ b/ports/stm/st_driver @@ -1 +1 @@ -Subproject commit 3fc2e0f3db155b33177bb0705e0dd65cadb58412 +Subproject commit 1900834751fd6754457874b8c971690bab33e0a7 From 644d2ba7a2075c44306583fada847047a7a44d5d Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 3 Aug 2020 16:40:45 -0700 Subject: [PATCH 28/79] Add more "extern" declarations for gcc10 compat gcc has tightened the restrictions on forward declarations that lack "extern". Fix them up. --- .../common-hal/microcontroller/Processor.h | 2 +- ports/mimxrt10xx/mphalport.h | 4 ++-- .../peripherals/mimxrt10xx/MIMXRT1011/periph.h | 6 +++--- .../peripherals/mimxrt10xx/MIMXRT1021/periph.h | 6 +++--- .../peripherals/mimxrt10xx/MIMXRT1062/periph.h | 6 +++--- ports/nrf/common-hal/_bleio/__init__.c | 2 ++ ports/nrf/common-hal/_bleio/__init__.h | 2 +- ports/stm/common-hal/pulseio/PWMOut.c | 2 +- ports/stm/mphalport.h | 4 ++-- .../peripherals/stm32f4/stm32f401xe/periph.h | 4 ++-- .../peripherals/stm32f4/stm32f405xx/periph.h | 4 ++-- .../peripherals/stm32f4/stm32f407xx/periph.h | 4 ++-- .../peripherals/stm32f4/stm32f411xe/periph.h | 4 ++-- .../peripherals/stm32f4/stm32f412zx/periph.h | 4 ++-- .../peripherals/stm32f7/stm32f746xx/periph.h | 16 ++++++++-------- .../peripherals/stm32f7/stm32f767xx/periph.h | 18 +++++++++--------- .../peripherals/stm32h7/stm32h743xx/periph.h | 16 ++++++++-------- ports/stm/supervisor/internal_flash.c | 4 ++-- shared-bindings/_bleio/Adapter.h | 2 +- shared-bindings/_bleio/Service.h | 2 +- shared-bindings/gnss/PositionFix.h | 2 +- shared-bindings/gnss/SatelliteSystem.h | 2 +- shared-bindings/watchdog/WatchDogMode.h | 2 +- 23 files changed, 60 insertions(+), 58 deletions(-) diff --git a/ports/cxd56/common-hal/microcontroller/Processor.h b/ports/cxd56/common-hal/microcontroller/Processor.h index 12555e82c1..5d7ad56977 100644 --- a/ports/cxd56/common-hal/microcontroller/Processor.h +++ b/ports/cxd56/common-hal/microcontroller/Processor.h @@ -35,6 +35,6 @@ typedef struct { mp_obj_base_t base; } mcu_processor_obj_t; -const mp_obj_type_t mcu_processor_type; +extern const mp_obj_type_t mcu_processor_type; #endif // MICROPY_INCLUDED_CXD56_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H diff --git a/ports/mimxrt10xx/mphalport.h b/ports/mimxrt10xx/mphalport.h index 1acc461b7e..4ba3a24764 100644 --- a/ports/mimxrt10xx/mphalport.h +++ b/ports/mimxrt10xx/mphalport.h @@ -39,8 +39,8 @@ static inline mp_uint_t mp_hal_ticks_ms(void) { return supervisor_ticks_ms32(); } // Number of bytes in receive buffer -volatile uint8_t usb_rx_count; -volatile bool mp_cdc_enabled; +extern volatile uint8_t usb_rx_count; +extern volatile bool mp_cdc_enabled; int receive_usb(void); diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.h index 3bc86f33a5..c3f04a0490 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.h @@ -27,18 +27,18 @@ #ifndef MICROPY_INCLUDED_MIMXRT10XX_PERIPHERALS_MIMXRT1011_PERIPH_H #define MICROPY_INCLUDED_MIMXRT10XX_PERIPHERALS_MIMXRT1011_PERIPH_H -LPI2C_Type *mcu_i2c_banks[2]; +extern LPI2C_Type *mcu_i2c_banks[2]; extern const mcu_periph_obj_t mcu_i2c_sda_list[8]; extern const mcu_periph_obj_t mcu_i2c_scl_list[8]; -LPSPI_Type *mcu_spi_banks[2]; +extern LPSPI_Type *mcu_spi_banks[2]; extern const mcu_periph_obj_t mcu_spi_sck_list[4]; extern const mcu_periph_obj_t mcu_spi_mosi_list[4]; extern const mcu_periph_obj_t mcu_spi_miso_list[4]; -LPUART_Type *mcu_uart_banks[4]; +extern LPUART_Type *mcu_uart_banks[4]; extern const mcu_periph_obj_t mcu_uart_rx_list[9]; extern const mcu_periph_obj_t mcu_uart_tx_list[9]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.h index 814bc5f6c3..6c778ad525 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.h @@ -28,18 +28,18 @@ #ifndef MICROPY_INCLUDED_MIMXRT10XX_PERIPHERALS_MIMXRT1021_PERIPH_H #define MICROPY_INCLUDED_MIMXRT10XX_PERIPHERALS_MIMXRT1021_PERIPH_H -LPI2C_Type *mcu_i2c_banks[4]; +extern LPI2C_Type *mcu_i2c_banks[4]; extern const mcu_periph_obj_t mcu_i2c_sda_list[8]; extern const mcu_periph_obj_t mcu_i2c_scl_list[8]; -LPSPI_Type *mcu_spi_banks[4]; +extern LPSPI_Type *mcu_spi_banks[4]; extern const mcu_periph_obj_t mcu_spi_sck_list[8]; extern const mcu_periph_obj_t mcu_spi_mosi_list[8]; extern const mcu_periph_obj_t mcu_spi_miso_list[8]; -LPUART_Type *mcu_uart_banks[8]; +extern LPUART_Type *mcu_uart_banks[8]; extern const mcu_periph_obj_t mcu_uart_rx_list[16]; extern const mcu_periph_obj_t mcu_uart_tx_list[16]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.h index 35ac4fc9b7..4f6ab6261e 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.h @@ -27,18 +27,18 @@ #ifndef MICROPY_INCLUDED_MIMXRT10XX_PERIPHERALS_MIMXRT1011_PERIPH_H #define MICROPY_INCLUDED_MIMXRT10XX_PERIPHERALS_MIMXRT1011_PERIPH_H -LPI2C_Type *mcu_i2c_banks[4]; +extern LPI2C_Type *mcu_i2c_banks[4]; extern const mcu_periph_obj_t mcu_i2c_sda_list[9]; extern const mcu_periph_obj_t mcu_i2c_scl_list[9]; -LPSPI_Type *mcu_spi_banks[4]; +extern LPSPI_Type *mcu_spi_banks[4]; extern const mcu_periph_obj_t mcu_spi_sck_list[8]; extern const mcu_periph_obj_t mcu_spi_mosi_list[8]; extern const mcu_periph_obj_t mcu_spi_miso_list[8]; -LPUART_Type *mcu_uart_banks[8]; +extern LPUART_Type *mcu_uart_banks[8]; extern const mcu_periph_obj_t mcu_uart_rx_list[18]; extern const mcu_periph_obj_t mcu_uart_tx_list[18]; diff --git a/ports/nrf/common-hal/_bleio/__init__.c b/ports/nrf/common-hal/_bleio/__init__.c index e84bba6626..23d7397c79 100644 --- a/ports/nrf/common-hal/_bleio/__init__.c +++ b/ports/nrf/common-hal/_bleio/__init__.c @@ -87,6 +87,8 @@ void check_sec_status(uint8_t sec_status) { } } +bool vm_used_ble; + // Turn off BLE on a reset or reload. void bleio_reset() { if (!common_hal_bleio_adapter_get_enabled(&common_hal_bleio_adapter_obj)) { diff --git a/ports/nrf/common-hal/_bleio/__init__.h b/ports/nrf/common-hal/_bleio/__init__.h index e216795fcd..6881c90e6c 100644 --- a/ports/nrf/common-hal/_bleio/__init__.h +++ b/ports/nrf/common-hal/_bleio/__init__.h @@ -45,6 +45,6 @@ void check_gatt_status(uint16_t gatt_status); void check_sec_status(uint8_t sec_status); // Track if the user code modified the BLE state to know if we need to undo it on reload. -bool vm_used_ble; +extern bool vm_used_ble; #endif // MICROPY_INCLUDED_NRF_COMMON_HAL_BLEIO_INIT_H diff --git a/ports/stm/common-hal/pulseio/PWMOut.c b/ports/stm/common-hal/pulseio/PWMOut.c index ddbadaf4ce..c9768f4f61 100644 --- a/ports/stm/common-hal/pulseio/PWMOut.c +++ b/ports/stm/common-hal/pulseio/PWMOut.c @@ -96,7 +96,7 @@ pwmout_result_t common_hal_pulseio_pwmout_construct(pulseio_pwmout_obj_t* self, //if pin is same if (l_tim->pin == pin) { //check if the timer has a channel active, or is reserved by main timer system - if (reserved_tim[l_tim_index] != 0) { + if (l_tim_index < TIM_BANK_ARRAY_LEN && reserved_tim[l_tim_index] != 0) { // Timer has already been reserved by an internal module if (stm_peripherals_timer_is_reserved(mcu_tim_banks[l_tim_index])) { tim_taken_internal = true; diff --git a/ports/stm/mphalport.h b/ports/stm/mphalport.h index 69f2c489c5..2c4caf3b22 100644 --- a/ports/stm/mphalport.h +++ b/ports/stm/mphalport.h @@ -38,8 +38,8 @@ static inline mp_uint_t mp_hal_ticks_ms(void) { return supervisor_ticks_ms32(); } // Number of bytes in receive buffer -volatile uint8_t usb_rx_count; -volatile bool mp_cdc_enabled; +extern volatile uint8_t usb_rx_count; +extern volatile bool mp_cdc_enabled; int receive_usb(void); diff --git a/ports/stm/peripherals/stm32f4/stm32f401xe/periph.h b/ports/stm/peripherals/stm32f4/stm32f401xe/periph.h index ae416bda1d..c38e9ea98b 100644 --- a/ports/stm/peripherals/stm32f4/stm32f401xe/periph.h +++ b/ports/stm/peripherals/stm32f4/stm32f401xe/periph.h @@ -51,7 +51,7 @@ extern const mcu_periph_obj_t mcu_uart_rx_list[6]; //Timers #define TIM_BANK_ARRAY_LEN 14 #define TIM_PIN_ARRAY_LEN 44 -TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN]; -const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN]; +extern TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN]; +extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN]; #endif // MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F401XE_PERIPH_H diff --git a/ports/stm/peripherals/stm32f4/stm32f405xx/periph.h b/ports/stm/peripherals/stm32f4/stm32f405xx/periph.h index 020bff3709..5b64fe10c4 100644 --- a/ports/stm/peripherals/stm32f4/stm32f405xx/periph.h +++ b/ports/stm/peripherals/stm32f4/stm32f405xx/periph.h @@ -58,8 +58,8 @@ extern const mcu_periph_obj_t mcu_uart_rx_list[UART_RX_ARRAY_LEN]; //Timers #define TIM_BANK_ARRAY_LEN 14 #define TIM_PIN_ARRAY_LEN 67 -TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN]; -const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN]; +extern TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN]; +extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN]; //SDIO extern SDIO_TypeDef * mcu_sdio_banks[1]; diff --git a/ports/stm/peripherals/stm32f4/stm32f407xx/periph.h b/ports/stm/peripherals/stm32f4/stm32f407xx/periph.h index 55c00ee936..fb6348abaa 100644 --- a/ports/stm/peripherals/stm32f4/stm32f407xx/periph.h +++ b/ports/stm/peripherals/stm32f4/stm32f407xx/periph.h @@ -51,7 +51,7 @@ extern const mcu_periph_obj_t mcu_uart_rx_list[12]; //Timers #define TIM_BANK_ARRAY_LEN 14 #define TIM_PIN_ARRAY_LEN 56 -TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN]; -const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN]; +extern TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN]; +extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN]; #endif // MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F407XX_PERIPH_H diff --git a/ports/stm/peripherals/stm32f4/stm32f411xe/periph.h b/ports/stm/peripherals/stm32f4/stm32f411xe/periph.h index 14a73d12f1..f78cb57a7b 100644 --- a/ports/stm/peripherals/stm32f4/stm32f411xe/periph.h +++ b/ports/stm/peripherals/stm32f4/stm32f411xe/periph.h @@ -51,7 +51,7 @@ extern const mcu_periph_obj_t mcu_uart_rx_list[7]; //Timers #define TIM_BANK_ARRAY_LEN 14 #define TIM_PIN_ARRAY_LEN 44 -TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN]; -const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN]; +extern TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN]; +extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN]; #endif // MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F411XE_PERIPH_H diff --git a/ports/stm/peripherals/stm32f4/stm32f412zx/periph.h b/ports/stm/peripherals/stm32f4/stm32f412zx/periph.h index f6b001a4e9..40afd27f46 100644 --- a/ports/stm/peripherals/stm32f4/stm32f412zx/periph.h +++ b/ports/stm/peripherals/stm32f4/stm32f412zx/periph.h @@ -52,7 +52,7 @@ extern const mcu_periph_obj_t mcu_uart_rx_list[12]; //Timers #define TIM_BANK_ARRAY_LEN 14 #define TIM_PIN_ARRAY_LEN 60 -TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN]; -const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN]; +extern TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN]; +extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN]; #endif // MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F412ZX_PERIPH_H diff --git a/ports/stm/peripherals/stm32f7/stm32f746xx/periph.h b/ports/stm/peripherals/stm32f7/stm32f746xx/periph.h index 26f4ad2b54..f20896e22e 100644 --- a/ports/stm/peripherals/stm32f7/stm32f746xx/periph.h +++ b/ports/stm/peripherals/stm32f7/stm32f746xx/periph.h @@ -31,28 +31,28 @@ //I2C extern I2C_TypeDef * mcu_i2c_banks[4]; -const mcu_periph_obj_t mcu_i2c_sda_list[10]; -const mcu_periph_obj_t mcu_i2c_scl_list[10]; +extern const mcu_periph_obj_t mcu_i2c_sda_list[10]; +extern const mcu_periph_obj_t mcu_i2c_scl_list[10]; //SPI extern SPI_TypeDef * mcu_spi_banks[6]; -const mcu_periph_obj_t mcu_spi_sck_list[14]; -const mcu_periph_obj_t mcu_spi_mosi_list[15]; -const mcu_periph_obj_t mcu_spi_miso_list[12]; +extern const mcu_periph_obj_t mcu_spi_sck_list[14]; +extern const mcu_periph_obj_t mcu_spi_mosi_list[15]; +extern const mcu_periph_obj_t mcu_spi_miso_list[12]; //UART extern USART_TypeDef * mcu_uart_banks[MAX_UART]; extern bool mcu_uart_has_usart[MAX_UART]; -const mcu_periph_obj_t mcu_uart_tx_list[15]; -const mcu_periph_obj_t mcu_uart_rx_list[15]; +extern const mcu_periph_obj_t mcu_uart_tx_list[15]; +extern const mcu_periph_obj_t mcu_uart_rx_list[15]; //Timers #define TIM_BANK_ARRAY_LEN 14 #define TIM_PIN_ARRAY_LEN 55 extern TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN]; -const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN]; +extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN]; #endif // MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F746XX_PERIPH_H diff --git a/ports/stm/peripherals/stm32f7/stm32f767xx/periph.h b/ports/stm/peripherals/stm32f7/stm32f767xx/periph.h index 438964c3e1..70f03f2580 100644 --- a/ports/stm/peripherals/stm32f7/stm32f767xx/periph.h +++ b/ports/stm/peripherals/stm32f7/stm32f767xx/periph.h @@ -30,28 +30,28 @@ //I2C extern I2C_TypeDef * mcu_i2c_banks[4]; -const mcu_periph_obj_t mcu_i2c_sda_list[12]; -const mcu_periph_obj_t mcu_i2c_scl_list[12]; +extern const mcu_periph_obj_t mcu_i2c_sda_list[12]; +extern const mcu_periph_obj_t mcu_i2c_scl_list[12]; //SPI extern SPI_TypeDef * mcu_spi_banks[6]; -const mcu_periph_obj_t mcu_spi_sck_list[18]; -const mcu_periph_obj_t mcu_spi_mosi_list[18]; -const mcu_periph_obj_t mcu_spi_miso_list[15]; +extern const mcu_periph_obj_t mcu_spi_sck_list[18]; +extern const mcu_periph_obj_t mcu_spi_mosi_list[18]; +extern const mcu_periph_obj_t mcu_spi_miso_list[15]; //UART extern USART_TypeDef * mcu_uart_banks[MAX_UART]; extern bool mcu_uart_has_usart[MAX_UART]; -const mcu_periph_obj_t mcu_uart_tx_list[24]; -const mcu_periph_obj_t mcu_uart_rx_list[25]; +extern const mcu_periph_obj_t mcu_uart_tx_list[24]; +extern const mcu_periph_obj_t mcu_uart_rx_list[25]; //Timers #define TIM_BANK_ARRAY_LEN 14 #define TIM_PIN_ARRAY_LEN 55 -TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN]; +extern TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN]; -const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN]; +extern const mcu_tim_pin_obj_t mcu_tim_pin_list[TIM_PIN_ARRAY_LEN]; #endif // MICROPY_INCLUDED_STM32_PERIPHERALS_STM32F767XX_PERIPH_H diff --git a/ports/stm/peripherals/stm32h7/stm32h743xx/periph.h b/ports/stm/peripherals/stm32h7/stm32h743xx/periph.h index 9aa2f7366b..e3902e7c74 100644 --- a/ports/stm/peripherals/stm32h7/stm32h743xx/periph.h +++ b/ports/stm/peripherals/stm32h7/stm32h743xx/periph.h @@ -30,26 +30,26 @@ //I2C extern I2C_TypeDef * mcu_i2c_banks[4]; -const mcu_periph_obj_t mcu_i2c_sda_list[12]; -const mcu_periph_obj_t mcu_i2c_scl_list[12]; +extern const mcu_periph_obj_t mcu_i2c_sda_list[12]; +extern const mcu_periph_obj_t mcu_i2c_scl_list[12]; //SPI extern SPI_TypeDef * mcu_spi_banks[6]; -const mcu_periph_obj_t mcu_spi_sck_list[19]; -const mcu_periph_obj_t mcu_spi_mosi_list[19]; -const mcu_periph_obj_t mcu_spi_miso_list[16]; +extern const mcu_periph_obj_t mcu_spi_sck_list[19]; +extern const mcu_periph_obj_t mcu_spi_mosi_list[19]; +extern const mcu_periph_obj_t mcu_spi_miso_list[16]; //UART extern USART_TypeDef * mcu_uart_banks[MAX_UART]; extern bool mcu_uart_has_usart[MAX_UART]; -const mcu_periph_obj_t mcu_uart_tx_list[25]; -const mcu_periph_obj_t mcu_uart_rx_list[26]; +extern const mcu_periph_obj_t mcu_uart_tx_list[25]; +extern const mcu_periph_obj_t mcu_uart_rx_list[26]; //Timers #define TIM_BANK_ARRAY_LEN 14 #define TIM_PIN_ARRAY_LEN 58 -TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN]; +extern TIM_TypeDef * mcu_tim_banks[TIM_BANK_ARRAY_LEN]; #endif // MICROPY_INCLUDED_STM32_PERIPHERALS_STM32H743XX_PERIPH_H diff --git a/ports/stm/supervisor/internal_flash.c b/ports/stm/supervisor/internal_flash.c index 864403c366..78ee4f3e60 100644 --- a/ports/stm/supervisor/internal_flash.c +++ b/ports/stm/supervisor/internal_flash.c @@ -177,13 +177,13 @@ void port_internal_flash_flush(void) { EraseInitStruct.VoltageRange = VOLTAGE_RANGE_3; // voltage range needs to be 2.7V to 3.6V // get the sector information uint32_t sector_size; - uint32_t sector_start_addr; + uint32_t sector_start_addr = 0xffffffff; #if defined(STM32H7) EraseInitStruct.Banks = get_bank(_cache_flash_addr); #endif EraseInitStruct.Sector = flash_get_sector_info(_cache_flash_addr, §or_start_addr, §or_size); EraseInitStruct.NbSectors = 1; - if (sector_size > sizeof(_flash_cache)) { + if (sector_size > sizeof(_flash_cache) || sector_start_addr == 0xffffffff) { reset_into_safe_mode(FLASH_WRITE_FAIL); } diff --git a/shared-bindings/_bleio/Adapter.h b/shared-bindings/_bleio/Adapter.h index 3523733577..c56dbb01cf 100644 --- a/shared-bindings/_bleio/Adapter.h +++ b/shared-bindings/_bleio/Adapter.h @@ -35,7 +35,7 @@ #include "py/objstr.h" #include "shared-module/_bleio/Address.h" -const mp_obj_type_t bleio_adapter_type; +extern const mp_obj_type_t bleio_adapter_type; extern bool common_hal_bleio_adapter_get_advertising(bleio_adapter_obj_t *self); extern bool common_hal_bleio_adapter_get_enabled(bleio_adapter_obj_t *self); diff --git a/shared-bindings/_bleio/Service.h b/shared-bindings/_bleio/Service.h index 273c6bd989..3af427f950 100644 --- a/shared-bindings/_bleio/Service.h +++ b/shared-bindings/_bleio/Service.h @@ -34,7 +34,7 @@ #include "py/objtuple.h" -const mp_obj_type_t bleio_service_type; +extern const mp_obj_type_t bleio_service_type; // Private version that doesn't allocate on the heap extern uint32_t _common_hal_bleio_service_construct(bleio_service_obj_t *self, bleio_uuid_obj_t *uuid, bool is_secondary, mp_obj_list_t * characteristic_list); diff --git a/shared-bindings/gnss/PositionFix.h b/shared-bindings/gnss/PositionFix.h index 34090872cc..0fd595fc6c 100644 --- a/shared-bindings/gnss/PositionFix.h +++ b/shared-bindings/gnss/PositionFix.h @@ -13,7 +13,7 @@ typedef enum { POSITIONFIX_3D, } gnss_positionfix_t; -const mp_obj_type_t gnss_positionfix_type; +extern const mp_obj_type_t gnss_positionfix_type; gnss_positionfix_t gnss_positionfix_obj_to_type(mp_obj_t obj); mp_obj_t gnss_positionfix_type_to_obj(gnss_positionfix_t mode); diff --git a/shared-bindings/gnss/SatelliteSystem.h b/shared-bindings/gnss/SatelliteSystem.h index 17f1550028..02cd17db2f 100644 --- a/shared-bindings/gnss/SatelliteSystem.h +++ b/shared-bindings/gnss/SatelliteSystem.h @@ -16,7 +16,7 @@ typedef enum { SATELLITESYSTEM_QZSS_L1S = (1U << 4), } gnss_satellitesystem_t; -const mp_obj_type_t gnss_satellitesystem_type; +extern const mp_obj_type_t gnss_satellitesystem_type; gnss_satellitesystem_t gnss_satellitesystem_obj_to_type(mp_obj_t obj); mp_obj_t gnss_satellitesystem_type_to_obj(gnss_satellitesystem_t mode); diff --git a/shared-bindings/watchdog/WatchDogMode.h b/shared-bindings/watchdog/WatchDogMode.h index 68022671fb..fb09445a9f 100644 --- a/shared-bindings/watchdog/WatchDogMode.h +++ b/shared-bindings/watchdog/WatchDogMode.h @@ -35,7 +35,7 @@ typedef enum { WATCHDOGMODE_RESET, } watchdog_watchdogmode_t; -const mp_obj_type_t watchdog_watchdogmode_type; +extern const mp_obj_type_t watchdog_watchdogmode_type; watchdog_watchdogmode_t watchdog_watchdogmode_obj_to_type(mp_obj_t obj); mp_obj_t watchdog_watchdogmode_type_to_obj(watchdog_watchdogmode_t mode); From 9a6a156512afefaf8413482be63e1ec73d626ee8 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Fri, 21 Aug 2020 15:26:50 -0500 Subject: [PATCH 29/79] Update documentation string with blank line --- shared-bindings/displayio/Bitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index 2fb1cd11eb..c669e5312b 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -172,10 +172,10 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val return mp_const_none; } - //| def blit(self, x: int, y: int, source_bitmap: bitmap, *, x1: int, y1: int, x2: int, y2: int, skip_index: int) -> None: //| """Inserts the source_bitmap region defined by rectangular boundaries //| (x1,y1) and (x2,y2) into the bitmap at the specified (x,y) location. +//| //| :param int x: Horizontal pixel location in bitmap where source_bitmap upper-left //| corner will be placed //| :param int y: Vertical pixel location in bitmap where source_bitmap upper-left From f1fb2cde175c72d9b4fc6c88b07bf45e21376cf7 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Fri, 21 Aug 2020 16:12:40 -0500 Subject: [PATCH 30/79] Minor tweaks to try to fix documentation failing --- shared-bindings/displayio/Bitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index c669e5312b..dad8beeaf4 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -186,7 +186,7 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val //| :param int x2: Maximum x-value (exclusive) for rectangular bounding box to be copied from the source bitmap //| :param int y2: Maximum y-value (exclusive) for rectangular bounding box to be copied from the source bitmap //| :param int skip_index: bitmap palette index in the source that will not be copied, -//| set `None` to copy all pixels""" +//| set to None to copy all pixels""" //| ... //| From 5b6313e642f90be13351a58e9a8d0ef325bdeb35 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Fri, 21 Aug 2020 16:13:18 -0500 Subject: [PATCH 31/79] More tweaks to try to fix documentation failing --- shared-bindings/displayio/Bitmap.c | 1 - 1 file changed, 1 deletion(-) diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index dad8beeaf4..c13ed0407e 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -189,7 +189,6 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val //| set to None to copy all pixels""" //| ... //| - STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args){ enum {ARG_x, ARG_y, ARG_source, ARG_x1, ARG_y1, ARG_x2, ARG_y2, ARG_skip_index}; static const mp_arg_t allowed_args[] = { From f39708abb23b7c7794c04de184213433de481a33 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 21 Aug 2020 16:20:58 -0700 Subject: [PATCH 32/79] Add PSRAM support to ESP32S2 When configured the CircuitPython heap will be on the external RAM. When not available, the heap will be 48k inside the IDF heap. --- main.c | 5 +-- .../boards/espressif_saola_1_wrover/sdkconfig | 33 +++++++++++++++++ .../unexpectedmaker_feathers2/sdkconfig | 35 +++++++++++++++++++ ports/esp32s2/supervisor/port.c | 23 +++++++++--- 4 files changed, 90 insertions(+), 6 deletions(-) diff --git a/main.c b/main.c index fb73b09b1f..3a14df0fa6 100755 --- a/main.c +++ b/main.c @@ -436,11 +436,12 @@ int run_repl(void) { } int __attribute__((used)) main(void) { - memory_init(); - // initialise the cpu and peripherals safe_mode_t safe_mode = port_init(); + // Init memory after the port in case the port needs to set aside memory. + memory_init(); + // Turn on LEDs init_status_leds(); rgb_led_status_init(); diff --git a/ports/esp32s2/boards/espressif_saola_1_wrover/sdkconfig b/ports/esp32s2/boards/espressif_saola_1_wrover/sdkconfig index e69de29bb2..9d8bbde967 100644 --- a/ports/esp32s2/boards/espressif_saola_1_wrover/sdkconfig +++ b/ports/esp32s2/boards/espressif_saola_1_wrover/sdkconfig @@ -0,0 +1,33 @@ +CONFIG_ESP32S2_SPIRAM_SUPPORT=y + +# +# SPI RAM config +# +# CONFIG_SPIRAM_TYPE_AUTO is not set +CONFIG_SPIRAM_TYPE_ESPPSRAM16=y +# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set +# CONFIG_SPIRAM_TYPE_ESPPSRAM64 is not set +CONFIG_SPIRAM_SIZE=2097152 + +# +# 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 diff --git a/ports/esp32s2/boards/unexpectedmaker_feathers2/sdkconfig b/ports/esp32s2/boards/unexpectedmaker_feathers2/sdkconfig index e69de29bb2..b73c4a8c20 100644 --- a/ports/esp32s2/boards/unexpectedmaker_feathers2/sdkconfig +++ b/ports/esp32s2/boards/unexpectedmaker_feathers2/sdkconfig @@ -0,0 +1,35 @@ +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_SPIWP_SD3_PIN=28 +# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set +# CONFIG_SPIRAM_RODATA is not set +# CONFIG_SPIRAM_USE_AHB_DBUS3 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 diff --git a/ports/esp32s2/supervisor/port.c b/ports/esp32s2/supervisor/port.c index 46590b5513..08710fe910 100644 --- a/ports/esp32s2/supervisor/port.c +++ b/ports/esp32s2/supervisor/port.c @@ -43,7 +43,14 @@ #include "supervisor/memory.h" #include "supervisor/shared/tick.h" -#include "rmt.h" +#include "peripherals/rmt.h" +#include "esp-idf/components/heap/include/esp_heap_caps.h" +#include "esp-idf/components/soc/soc/esp32s2/include/soc/cache_memory.h" + +#define HEAP_SIZE (48 * 1024) + +uint32_t* heap; +uint32_t heap_size; STATIC esp_timer_handle_t _tick_timer; @@ -59,6 +66,16 @@ safe_mode_t port_init(void) { args.name = "CircuitPython Tick"; esp_timer_create(&args, &_tick_timer); never_reset_module_internal_pins(); + + #ifdef CONFIG_SPIRAM + heap = (uint32_t*) (DRAM0_CACHE_ADDRESS_HIGH - CONFIG_SPIRAM_SIZE); + heap_size = CONFIG_SPIRAM_SIZE / sizeof(uint32_t); + #endif + + if (heap == NULL) { + heap = malloc(HEAP_SIZE); + heap_size = HEAP_SIZE / sizeof(uint32_t); + } return NO_SAFE_MODE; } @@ -86,14 +103,12 @@ void reset_to_bootloader(void) { void reset_cpu(void) { } -uint32_t heap[64 / sizeof(uint32_t) * 1024]; - uint32_t *port_heap_get_bottom(void) { return heap; } uint32_t *port_heap_get_top(void) { - return heap + sizeof(heap) / sizeof(heap[0]); + return heap + heap_size; } uint32_t *port_stack_get_limit(void) { From dc502a5f26fdf5514eb835fae5f523c1b15c23b5 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Fri, 21 Aug 2020 19:08:25 -0500 Subject: [PATCH 33/79] remove extraneous files --- shared-bindings/_typing/__init__ 2.pyi | 54 -- shared-bindings/gnss/GNSS 2.c | 205 -------- shared-bindings/gnss/GNSS 2.h | 27 - shared-bindings/gnss/PositionFix 2.c | 80 --- shared-bindings/gnss/PositionFix 2.h | 28 -- shared-bindings/gnss/SatelliteSystem 2.c | 113 ----- shared-bindings/gnss/SatelliteSystem 2.h | 33 -- shared-bindings/gnss/__init__ 2.c | 31 -- .../i2cperipheral/I2CPeripheral 2.c | 436 ---------------- .../i2cperipheral/I2CPeripheral 2.h | 60 --- shared-bindings/i2cperipheral/__init__ 2.c | 106 ---- .../memorymonitor/AllocationAlarm 2.c | 137 ----- .../memorymonitor/AllocationAlarm 2.h | 39 -- .../memorymonitor/AllocationSize 2.c | 183 ------- .../memorymonitor/AllocationSize 2.h | 42 -- shared-bindings/memorymonitor/__init__ 2.c | 76 --- shared-bindings/memorymonitor/__init__ 2.h | 49 -- shared-bindings/sdcardio/SDCard 2.c | 183 ------- shared-bindings/sdcardio/SDCard 2.h | 30 -- shared-bindings/sdcardio/__init__ 2.c | 47 -- shared-bindings/sdcardio/__init__ 2.h | 0 shared-module/sdcardio/SDCard 2.c | 466 ------------------ shared-module/sdcardio/SDCard 2.h | 51 -- shared-module/sdcardio/__init__ 2.c | 0 shared-module/sdcardio/__init__ 2.h | 0 supervisor/background_callback 2.h | 87 ---- supervisor/shared/background_callback 2.c | 138 ------ 27 files changed, 2701 deletions(-) delete mode 100644 shared-bindings/_typing/__init__ 2.pyi delete mode 100644 shared-bindings/gnss/GNSS 2.c delete mode 100644 shared-bindings/gnss/GNSS 2.h delete mode 100644 shared-bindings/gnss/PositionFix 2.c delete mode 100644 shared-bindings/gnss/PositionFix 2.h delete mode 100644 shared-bindings/gnss/SatelliteSystem 2.c delete mode 100644 shared-bindings/gnss/SatelliteSystem 2.h delete mode 100644 shared-bindings/gnss/__init__ 2.c delete mode 100644 shared-bindings/i2cperipheral/I2CPeripheral 2.c delete mode 100644 shared-bindings/i2cperipheral/I2CPeripheral 2.h delete mode 100644 shared-bindings/i2cperipheral/__init__ 2.c delete mode 100644 shared-bindings/memorymonitor/AllocationAlarm 2.c delete mode 100644 shared-bindings/memorymonitor/AllocationAlarm 2.h delete mode 100644 shared-bindings/memorymonitor/AllocationSize 2.c delete mode 100644 shared-bindings/memorymonitor/AllocationSize 2.h delete mode 100644 shared-bindings/memorymonitor/__init__ 2.c delete mode 100644 shared-bindings/memorymonitor/__init__ 2.h delete mode 100644 shared-bindings/sdcardio/SDCard 2.c delete mode 100644 shared-bindings/sdcardio/SDCard 2.h delete mode 100644 shared-bindings/sdcardio/__init__ 2.c delete mode 100644 shared-bindings/sdcardio/__init__ 2.h delete mode 100644 shared-module/sdcardio/SDCard 2.c delete mode 100644 shared-module/sdcardio/SDCard 2.h delete mode 100644 shared-module/sdcardio/__init__ 2.c delete mode 100644 shared-module/sdcardio/__init__ 2.h delete mode 100644 supervisor/background_callback 2.h delete mode 100644 supervisor/shared/background_callback 2.c diff --git a/shared-bindings/_typing/__init__ 2.pyi b/shared-bindings/_typing/__init__ 2.pyi deleted file mode 100644 index 48e68a8d57..0000000000 --- a/shared-bindings/_typing/__init__ 2.pyi +++ /dev/null @@ -1,54 +0,0 @@ -"""Types for the C-level protocols""" - -from typing import Union - -import array -import audiocore -import audiomixer -import audiomp3 -import rgbmatrix -import ulab - -ReadableBuffer = Union[ - bytes, bytearray, memoryview, array.array, ulab.array, rgbmatrix.RGBMatrix -] -"""Classes that implement the readable buffer protocol - - - `bytes` - - `bytearray` - - `memoryview` - - `array.array` - - `ulab.array` - - `rgbmatrix.RGBMatrix` -""" - -WriteableBuffer = Union[ - bytearray, memoryview, array.array, ulab.array, rgbmatrix.RGBMatrix -] -"""Classes that implement the writeable buffer protocol - - - `bytearray` - - `memoryview` - - `array.array` - - `ulab.array` - - `rgbmatrix.RGBMatrix` -""" - -AudioSample = Union[ - audiocore.WaveFile, audiocore.RawSample, audiomixer.Mixer, audiomp3.MP3Decoder -] -"""Classes that implement the audiosample protocol - - - `audiocore.WaveFile` - - `audiocore.RawSample` - - `audiomixer.Mixer` - - `audiomp3.MP3Decoder` - - You can play these back with `audioio.AudioOut`, `audiobusio.I2SOut` or `audiopwmio.PWMAudioOut`. -""" - -FrameBuffer = Union[rgbmatrix.RGBMatrix] -"""Classes that implement the framebuffer protocol - - - `rgbmatrix.RGBMatrix` -""" diff --git a/shared-bindings/gnss/GNSS 2.c b/shared-bindings/gnss/GNSS 2.c deleted file mode 100644 index 087c353953..0000000000 --- a/shared-bindings/gnss/GNSS 2.c +++ /dev/null @@ -1,205 +0,0 @@ -// SPDX-FileCopyrightText: Sony Semiconductor Solutions Corporation -// -// SPDX-License-Identifier: MIT - -#include "shared-bindings/gnss/GNSS.h" -#include "shared-bindings/time/__init__.h" -#include "shared-bindings/util.h" - -#include "py/objproperty.h" -#include "py/runtime.h" - -//| class GNSS: -//| """Get updated positioning information from Global Navigation Satellite System (GNSS) -//| -//| Usage:: -//| -//| import gnss -//| import time -//| -//| nav = gnss.GNSS([gnss.SatelliteSystem.GPS, gnss.SatelliteSystem.GLONASS]) -//| last_print = time.monotonic() -//| while True: -//| nav.update() -//| current = time.monotonic() -//| if current - last_print >= 1.0: -//| last_print = current -//| if nav.fix is gnss.PositionFix.INVALID: -//| print("Waiting for fix...") -//| continue -//| print("Latitude: {0:.6f} degrees".format(nav.latitude)) -//| print("Longitude: {0:.6f} degrees".format(nav.longitude))""" -//| - -//| def __init__(self, system: Union[SatelliteSystem, List[SatelliteSystem]]) -> None: -//| """Turn on the GNSS. -//| -//| :param system: satellite system to use""" -//| ... -//| -STATIC mp_obj_t gnss_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - gnss_obj_t *self = m_new_obj(gnss_obj_t); - self->base.type = &gnss_type; - enum { ARG_system }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_system, MP_ARG_REQUIRED | MP_ARG_OBJ }, - }; - 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); - - unsigned long selection = 0; - if (MP_OBJ_IS_TYPE(args[ARG_system].u_obj, &gnss_satellitesystem_type)) { - selection |= gnss_satellitesystem_obj_to_type(args[ARG_system].u_obj); - } else if (MP_OBJ_IS_TYPE(args[ARG_system].u_obj, &mp_type_list)) { - size_t systems_size = 0; - mp_obj_t *systems; - mp_obj_list_get(args[ARG_system].u_obj, &systems_size, &systems); - for (size_t i = 0; i < systems_size; ++i) { - if (!MP_OBJ_IS_TYPE(systems[i], &gnss_satellitesystem_type)) { - mp_raise_TypeError(translate("System entry must be gnss.SatelliteSystem")); - } - selection |= gnss_satellitesystem_obj_to_type(systems[i]); - } - } else { - mp_raise_TypeError(translate("System entry must be gnss.SatelliteSystem")); - } - - common_hal_gnss_construct(self, selection); - return MP_OBJ_FROM_PTR(self); -} - -//| def deinit(self) -> None: -//| """Turn off the GNSS.""" -//| ... -//| -STATIC mp_obj_t gnss_obj_deinit(mp_obj_t self_in) { - gnss_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_gnss_deinit(self); - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_1(gnss_deinit_obj, gnss_obj_deinit); - -STATIC void check_for_deinit(gnss_obj_t *self) { - if (common_hal_gnss_deinited(self)) { - raise_deinited_error(); - } -} - -//| def update(self) -> None: -//| """Update GNSS positioning information.""" -//| ... -//| -STATIC mp_obj_t gnss_obj_update(mp_obj_t self_in) { - gnss_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - - common_hal_gnss_update(self); - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_1(gnss_update_obj, gnss_obj_update); - -//| latitude: float -//| """Latitude of current position in degrees (float).""" -//| -STATIC mp_obj_t gnss_obj_get_latitude(mp_obj_t self_in) { - gnss_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - return mp_obj_new_float(common_hal_gnss_get_latitude(self)); -} -MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_latitude_obj, gnss_obj_get_latitude); - -const mp_obj_property_t gnss_latitude_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&gnss_get_latitude_obj, - (mp_obj_t)&mp_const_none_obj, - (mp_obj_t)&mp_const_none_obj}, -}; - -//| longitude: float -//| """Longitude of current position in degrees (float).""" -//| -STATIC mp_obj_t gnss_obj_get_longitude(mp_obj_t self_in) { - gnss_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - return mp_obj_new_float(common_hal_gnss_get_longitude(self)); -} -MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_longitude_obj, gnss_obj_get_longitude); - -const mp_obj_property_t gnss_longitude_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&gnss_get_longitude_obj, - (mp_obj_t)&mp_const_none_obj, - (mp_obj_t)&mp_const_none_obj}, -}; - -//| altitude: float -//| """Altitude of current position in meters (float).""" -//| -STATIC mp_obj_t gnss_obj_get_altitude(mp_obj_t self_in) { - gnss_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - return mp_obj_new_float(common_hal_gnss_get_altitude(self)); -} -MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_altitude_obj, gnss_obj_get_altitude); - -const mp_obj_property_t gnss_altitude_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&gnss_get_altitude_obj, - (mp_obj_t)&mp_const_none_obj, - (mp_obj_t)&mp_const_none_obj}, -}; - -//| timestamp: time.struct_time -//| """Time when the position data was updated.""" -//| -STATIC mp_obj_t gnss_obj_get_timestamp(mp_obj_t self_in) { - gnss_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - timeutils_struct_time_t tm; - common_hal_gnss_get_timestamp(self, &tm); - return struct_time_from_tm(&tm); -} -MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_timestamp_obj, gnss_obj_get_timestamp); - -const mp_obj_property_t gnss_timestamp_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&gnss_get_timestamp_obj, - (mp_obj_t)&mp_const_none_obj, - (mp_obj_t)&mp_const_none_obj}, -}; - -//| fix: PositionFix -//| """Fix mode.""" -//| -STATIC mp_obj_t gnss_obj_get_fix(mp_obj_t self_in) { - gnss_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - return gnss_positionfix_type_to_obj(common_hal_gnss_get_fix(self)); -} -MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_fix_obj, gnss_obj_get_fix); - -const mp_obj_property_t gnss_fix_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&gnss_get_fix_obj, - (mp_obj_t)&mp_const_none_obj, - (mp_obj_t)&mp_const_none_obj}, -}; - -STATIC const mp_rom_map_elem_t gnss_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&gnss_deinit_obj) }, - { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&gnss_update_obj) }, - - { MP_ROM_QSTR(MP_QSTR_latitude), MP_ROM_PTR(&gnss_latitude_obj) }, - { MP_ROM_QSTR(MP_QSTR_longitude), MP_ROM_PTR(&gnss_longitude_obj) }, - { MP_ROM_QSTR(MP_QSTR_altitude), MP_ROM_PTR(&gnss_altitude_obj) }, - { MP_ROM_QSTR(MP_QSTR_timestamp), MP_ROM_PTR(&gnss_timestamp_obj) }, - { MP_ROM_QSTR(MP_QSTR_fix), MP_ROM_PTR(&gnss_fix_obj) } -}; -STATIC MP_DEFINE_CONST_DICT(gnss_locals_dict, gnss_locals_dict_table); - -const mp_obj_type_t gnss_type = { - { &mp_type_type }, - .name = MP_QSTR_GNSS, - .make_new = gnss_make_new, - .locals_dict = (mp_obj_dict_t*)&gnss_locals_dict, -}; diff --git a/shared-bindings/gnss/GNSS 2.h b/shared-bindings/gnss/GNSS 2.h deleted file mode 100644 index 60069a90a9..0000000000 --- a/shared-bindings/gnss/GNSS 2.h +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-FileCopyrightText: Sony Semiconductor Solutions Corporation -// -// SPDX-License-Identifier: MIT - -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_GNSS_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_GNSS_H - -#include "common-hal/gnss/GNSS.h" -#include "shared-bindings/gnss/SatelliteSystem.h" -#include "shared-bindings/gnss/PositionFix.h" - -#include "lib/timeutils/timeutils.h" - -extern const mp_obj_type_t gnss_type; - -void common_hal_gnss_construct(gnss_obj_t *self, unsigned long selection); -void common_hal_gnss_deinit(gnss_obj_t *self); -bool common_hal_gnss_deinited(gnss_obj_t *self); -void common_hal_gnss_update(gnss_obj_t *self); - -mp_float_t common_hal_gnss_get_latitude(gnss_obj_t *self); -mp_float_t common_hal_gnss_get_longitude(gnss_obj_t *self); -mp_float_t common_hal_gnss_get_altitude(gnss_obj_t *self); -void common_hal_gnss_get_timestamp(gnss_obj_t *self, timeutils_struct_time_t *tm); -gnss_positionfix_t common_hal_gnss_get_fix(gnss_obj_t *self); - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_GNSS_H diff --git a/shared-bindings/gnss/PositionFix 2.c b/shared-bindings/gnss/PositionFix 2.c deleted file mode 100644 index e60611d705..0000000000 --- a/shared-bindings/gnss/PositionFix 2.c +++ /dev/null @@ -1,80 +0,0 @@ -// SPDX-FileCopyrightText: Sony Semiconductor Solutions Corporation -// -// SPDX-License-Identifier: MIT - -#include "shared-bindings/gnss/PositionFix.h" - -//| class PositionFix: -//| """Position fix mode""" -//| -//| def __init__(self) -> None: -//| """Enum-like class to define the position fix mode.""" -//| -//| INVALID: PositionFix -//| """No measurement.""" -//| -//| FIX_2D: PositionFix -//| """2D fix.""" -//| -//| FIX_3D: PositionFix -//| """3D fix.""" -//| -const mp_obj_type_t gnss_positionfix_type; - -const gnss_positionfix_obj_t gnss_positionfix_invalid_obj = { - { &gnss_positionfix_type }, -}; - -const gnss_positionfix_obj_t gnss_positionfix_fix2d_obj = { - { &gnss_positionfix_type }, -}; - -const gnss_positionfix_obj_t gnss_positionfix_fix3d_obj = { - { &gnss_positionfix_type }, -}; - -gnss_positionfix_t gnss_positionfix_obj_to_type(mp_obj_t obj) { - gnss_positionfix_t posfix = POSITIONFIX_INVALID; - if (obj == MP_ROM_PTR(&gnss_positionfix_fix2d_obj)) { - posfix = POSITIONFIX_2D; - } else if (obj == MP_ROM_PTR(&gnss_positionfix_fix3d_obj)) { - posfix = POSITIONFIX_3D; - } - return posfix; -} - -mp_obj_t gnss_positionfix_type_to_obj(gnss_positionfix_t posfix) { - switch (posfix) { - case POSITIONFIX_2D: - return (mp_obj_t)MP_ROM_PTR(&gnss_positionfix_fix2d_obj); - case POSITIONFIX_3D: - return (mp_obj_t)MP_ROM_PTR(&gnss_positionfix_fix3d_obj); - case POSITIONFIX_INVALID: - default: - return (mp_obj_t)MP_ROM_PTR(&gnss_positionfix_invalid_obj); - } -} - -STATIC const mp_rom_map_elem_t gnss_positionfix_locals_dict_table[] = { - {MP_ROM_QSTR(MP_QSTR_INVALID), MP_ROM_PTR(&gnss_positionfix_invalid_obj)}, - {MP_ROM_QSTR(MP_QSTR_FIX_2D), MP_ROM_PTR(&gnss_positionfix_fix2d_obj)}, - {MP_ROM_QSTR(MP_QSTR_FIX_3D), MP_ROM_PTR(&gnss_positionfix_fix3d_obj)}, -}; -STATIC MP_DEFINE_CONST_DICT(gnss_positionfix_locals_dict, gnss_positionfix_locals_dict_table); - -STATIC void gnss_positionfix_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { - qstr posfix = MP_QSTR_INVALID; - if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_positionfix_fix2d_obj)) { - posfix = MP_QSTR_FIX_2D; - } else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_positionfix_fix3d_obj)) { - posfix = MP_QSTR_FIX_3D; - } - mp_printf(print, "%q.%q.%q", MP_QSTR_gnss, MP_QSTR_PositionFix, posfix); -} - -const mp_obj_type_t gnss_positionfix_type = { - { &mp_type_type }, - .name = MP_QSTR_PositionFix, - .print = gnss_positionfix_print, - .locals_dict = (mp_obj_t)&gnss_positionfix_locals_dict, -}; diff --git a/shared-bindings/gnss/PositionFix 2.h b/shared-bindings/gnss/PositionFix 2.h deleted file mode 100644 index 34090872cc..0000000000 --- a/shared-bindings/gnss/PositionFix 2.h +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-FileCopyrightText: Sony Semiconductor Solutions Corporation -// -// SPDX-License-Identifier: MIT - -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_POSITIONFIX_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_POSITIONFIX_H - -#include "py/obj.h" - -typedef enum { - POSITIONFIX_INVALID, - POSITIONFIX_2D, - POSITIONFIX_3D, -} gnss_positionfix_t; - -const mp_obj_type_t gnss_positionfix_type; - -gnss_positionfix_t gnss_positionfix_obj_to_type(mp_obj_t obj); -mp_obj_t gnss_positionfix_type_to_obj(gnss_positionfix_t mode); - -typedef struct { - mp_obj_base_t base; -} gnss_positionfix_obj_t; -extern const gnss_positionfix_obj_t gnss_positionfix_invalid_obj; -extern const gnss_positionfix_obj_t gnss_positionfix_fix2d_obj; -extern const gnss_positionfix_obj_t gnss_positionfix_fix3d_obj; - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_POSITIONFIX_H diff --git a/shared-bindings/gnss/SatelliteSystem 2.c b/shared-bindings/gnss/SatelliteSystem 2.c deleted file mode 100644 index 7d66727b8d..0000000000 --- a/shared-bindings/gnss/SatelliteSystem 2.c +++ /dev/null @@ -1,113 +0,0 @@ -// SPDX-FileCopyrightText: Sony Semiconductor Solutions Corporation -// -// SPDX-License-Identifier: MIT - -#include "shared-bindings/gnss/SatelliteSystem.h" - -//| class SatelliteSystem: -//| """Satellite system type""" -//| -//| def __init__(self) -> None: -//| """Enum-like class to define the satellite system type.""" -//| -//| GPS: SatelliteSystem -//| """Global Positioning System.""" -//| -//| GLONASS: SatelliteSystem -//| """GLObal NAvigation Satellite System.""" -//| -//| SBAS: SatelliteSystem -//| """Satellite Based Augmentation System.""" -//| -//| QZSS_L1CA: SatelliteSystem -//| """Quasi-Zenith Satellite System L1C/A.""" -//| -//| QZSS_L1S: SatelliteSystem -//| """Quasi-Zenith Satellite System L1S.""" -//| -const mp_obj_type_t gnss_satellitesystem_type; - -const gnss_satellitesystem_obj_t gnss_satellitesystem_gps_obj = { - { &gnss_satellitesystem_type }, -}; - -const gnss_satellitesystem_obj_t gnss_satellitesystem_glonass_obj = { - { &gnss_satellitesystem_type }, -}; - -const gnss_satellitesystem_obj_t gnss_satellitesystem_sbas_obj = { - { &gnss_satellitesystem_type }, -}; - -const gnss_satellitesystem_obj_t gnss_satellitesystem_qzss_l1ca_obj = { - { &gnss_satellitesystem_type }, -}; - -const gnss_satellitesystem_obj_t gnss_satellitesystem_qzss_l1s_obj = { - { &gnss_satellitesystem_type }, -}; - -gnss_satellitesystem_t gnss_satellitesystem_obj_to_type(mp_obj_t obj) { - if (obj == MP_ROM_PTR(&gnss_satellitesystem_gps_obj)) { - return SATELLITESYSTEM_GPS; - } else if (obj == MP_ROM_PTR(&gnss_satellitesystem_glonass_obj)) { - return SATELLITESYSTEM_GLONASS; - } else if (obj == MP_ROM_PTR(&gnss_satellitesystem_sbas_obj)) { - return SATELLITESYSTEM_SBAS; - } else if (obj == MP_ROM_PTR(&gnss_satellitesystem_qzss_l1ca_obj)) { - return SATELLITESYSTEM_QZSS_L1CA; - } else if (obj == MP_ROM_PTR(&gnss_satellitesystem_qzss_l1s_obj)) { - return SATELLITESYSTEM_QZSS_L1S; - } - return SATELLITESYSTEM_NONE; -} - -mp_obj_t gnss_satellitesystem_type_to_obj(gnss_satellitesystem_t system) { - switch (system) { - case SATELLITESYSTEM_GPS: - return (mp_obj_t)MP_ROM_PTR(&gnss_satellitesystem_gps_obj); - case SATELLITESYSTEM_GLONASS: - return (mp_obj_t)MP_ROM_PTR(&gnss_satellitesystem_glonass_obj); - case SATELLITESYSTEM_SBAS: - return (mp_obj_t)MP_ROM_PTR(&gnss_satellitesystem_sbas_obj); - case SATELLITESYSTEM_QZSS_L1CA: - return (mp_obj_t)MP_ROM_PTR(&gnss_satellitesystem_qzss_l1ca_obj); - case SATELLITESYSTEM_QZSS_L1S: - return (mp_obj_t)MP_ROM_PTR(&gnss_satellitesystem_qzss_l1s_obj); - case SATELLITESYSTEM_NONE: - default: - return (mp_obj_t)MP_ROM_PTR(&mp_const_none_obj); - } -} - -STATIC const mp_rom_map_elem_t gnss_satellitesystem_locals_dict_table[] = { - {MP_ROM_QSTR(MP_QSTR_GPS), MP_ROM_PTR(&gnss_satellitesystem_gps_obj)}, - {MP_ROM_QSTR(MP_QSTR_GLONASS), MP_ROM_PTR(&gnss_satellitesystem_glonass_obj)}, - {MP_ROM_QSTR(MP_QSTR_SBAS), MP_ROM_PTR(&gnss_satellitesystem_sbas_obj)}, - {MP_ROM_QSTR(MP_QSTR_QZSS_L1CA), MP_ROM_PTR(&gnss_satellitesystem_qzss_l1ca_obj)}, - {MP_ROM_QSTR(MP_QSTR_QZSS_L1S), MP_ROM_PTR(&gnss_satellitesystem_qzss_l1s_obj)}, -}; -STATIC MP_DEFINE_CONST_DICT(gnss_satellitesystem_locals_dict, gnss_satellitesystem_locals_dict_table); - -STATIC void gnss_satellitesystem_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { - qstr system = MP_QSTR_None; - if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_satellitesystem_gps_obj)) { - system = MP_QSTR_GPS; - } else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_satellitesystem_glonass_obj)) { - system = MP_QSTR_GLONASS; - } else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_satellitesystem_sbas_obj)) { - system = MP_QSTR_SBAS; - } else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_satellitesystem_qzss_l1ca_obj)) { - system = MP_QSTR_QZSS_L1CA; - } else if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_satellitesystem_qzss_l1s_obj)) { - system = MP_QSTR_QZSS_L1S; - } - mp_printf(print, "%q.%q.%q", MP_QSTR_gnss, MP_QSTR_SatelliteSystem, system); -} - -const mp_obj_type_t gnss_satellitesystem_type = { - { &mp_type_type }, - .name = MP_QSTR_SatelliteSystem, - .print = gnss_satellitesystem_print, - .locals_dict = (mp_obj_t)&gnss_satellitesystem_locals_dict, -}; diff --git a/shared-bindings/gnss/SatelliteSystem 2.h b/shared-bindings/gnss/SatelliteSystem 2.h deleted file mode 100644 index 17f1550028..0000000000 --- a/shared-bindings/gnss/SatelliteSystem 2.h +++ /dev/null @@ -1,33 +0,0 @@ -// SPDX-FileCopyrightText: Sony Semiconductor Solutions Corporation -// -// SPDX-License-Identifier: MIT - -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_SATELLITESYSTEM_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_SATELLITESYSTEM_H - -#include "py/obj.h" - -typedef enum { - SATELLITESYSTEM_NONE = 0, - SATELLITESYSTEM_GPS = (1U << 0), - SATELLITESYSTEM_GLONASS = (1U << 1), - SATELLITESYSTEM_SBAS = (1U << 2), - SATELLITESYSTEM_QZSS_L1CA = (1U << 3), - SATELLITESYSTEM_QZSS_L1S = (1U << 4), -} gnss_satellitesystem_t; - -const mp_obj_type_t gnss_satellitesystem_type; - -gnss_satellitesystem_t gnss_satellitesystem_obj_to_type(mp_obj_t obj); -mp_obj_t gnss_satellitesystem_type_to_obj(gnss_satellitesystem_t mode); - -typedef struct { - mp_obj_base_t base; -} gnss_satellitesystem_obj_t; -extern const gnss_satellitesystem_obj_t gnss_satellitesystem_gps_obj; -extern const gnss_satellitesystem_obj_t gnss_satellitesystem_glonass_obj; -extern const gnss_satellitesystem_obj_t gnss_satellitesystem_sbas_obj; -extern const gnss_satellitesystem_obj_t gnss_satellitesystem_qzss_l1ca_obj; -extern const gnss_satellitesystem_obj_t gnss_satellitesystem_qzss_l1s_obj; - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_GNSS_SATELLITESYSTEM_H diff --git a/shared-bindings/gnss/__init__ 2.c b/shared-bindings/gnss/__init__ 2.c deleted file mode 100644 index 4b0d312ae6..0000000000 --- a/shared-bindings/gnss/__init__ 2.c +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-FileCopyrightText: Sony Semiconductor Solutions Corporation -// -// SPDX-License-Identifier: MIT - -#include "py/obj.h" -#include "py/runtime.h" -#include "py/mphal.h" -#include "shared-bindings/gnss/GNSS.h" -#include "shared-bindings/gnss/SatelliteSystem.h" -#include "shared-bindings/gnss/PositionFix.h" -#include "shared-bindings/util.h" - -//| """Global Navigation Satellite System -//| -//| The `gnss` module contains classes to control the GNSS and acquire positioning information.""" -//| -STATIC const mp_rom_map_elem_t gnss_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gnss) }, - { MP_ROM_QSTR(MP_QSTR_GNSS), MP_ROM_PTR(&gnss_type) }, - - // Enum-like Classes. - { MP_ROM_QSTR(MP_QSTR_SatelliteSystem), MP_ROM_PTR(&gnss_satellitesystem_type) }, - { MP_ROM_QSTR(MP_QSTR_PositionFix), MP_ROM_PTR(&gnss_positionfix_type) }, -}; - -STATIC MP_DEFINE_CONST_DICT(gnss_module_globals, gnss_module_globals_table); - -const mp_obj_module_t gnss_module = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t*)&gnss_module_globals, -}; diff --git a/shared-bindings/i2cperipheral/I2CPeripheral 2.c b/shared-bindings/i2cperipheral/I2CPeripheral 2.c deleted file mode 100644 index b5ac861b4e..0000000000 --- a/shared-bindings/i2cperipheral/I2CPeripheral 2.c +++ /dev/null @@ -1,436 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Noralf Trønnes - * - * 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/microcontroller/Pin.h" -#include "shared-bindings/i2cperipheral/I2CPeripheral.h" -#include "shared-bindings/time/__init__.h" -#include "shared-bindings/util.h" - -#include "lib/utils/buffer_helper.h" -#include "lib/utils/context_manager_helpers.h" -#include "lib/utils/interrupt_char.h" - -#include "py/mperrno.h" -#include "py/mphal.h" -#include "py/obj.h" -#include "py/objproperty.h" -#include "py/runtime.h" - -STATIC mp_obj_t mp_obj_new_i2cperipheral_i2c_peripheral_request(i2cperipheral_i2c_peripheral_obj_t *peripheral, uint8_t address, bool is_read, bool is_restart) { - i2cperipheral_i2c_peripheral_request_obj_t *self = m_new_obj(i2cperipheral_i2c_peripheral_request_obj_t); - self->base.type = &i2cperipheral_i2c_peripheral_request_type; - self->peripheral = peripheral; - self->address = address; - self->is_read = is_read; - self->is_restart = is_restart; - return (mp_obj_t)self; -} - -//| class I2CPeripheral: -//| """Two wire serial protocol peripheral""" -//| -//| def __init__(self, scl: microcontroller.Pin, sda: microcontroller.Pin, addresses: Sequence[int], smbus: bool = False) -> None: -//| """I2C is a two-wire protocol for communicating between devices. -//| This implements the peripheral (sensor, secondary) side. -//| -//| :param ~microcontroller.Pin scl: The clock pin -//| :param ~microcontroller.Pin sda: The data pin -//| :param addresses: The I2C addresses to respond to (how many is hw dependent). -//| :type addresses: list[int] -//| :param bool smbus: Use SMBUS timings if the hardware supports it""" -//| ... -//| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - i2cperipheral_i2c_peripheral_obj_t *self = m_new_obj(i2cperipheral_i2c_peripheral_obj_t); - self->base.type = &i2cperipheral_i2c_peripheral_type; - enum { ARG_scl, ARG_sda, ARG_addresses, ARG_smbus }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_scl, MP_ARG_REQUIRED | MP_ARG_OBJ }, - { MP_QSTR_sda, MP_ARG_REQUIRED | MP_ARG_OBJ }, - { MP_QSTR_addresses, MP_ARG_REQUIRED | MP_ARG_OBJ }, - { MP_QSTR_smbus, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, - }; - 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); - - const mcu_pin_obj_t* scl = validate_obj_is_free_pin(args[ARG_scl].u_obj); - const mcu_pin_obj_t* sda = validate_obj_is_free_pin(args[ARG_sda].u_obj); - - mp_obj_iter_buf_t iter_buf; - mp_obj_t iterable = mp_getiter(args[ARG_addresses].u_obj, &iter_buf); - mp_obj_t item; - uint8_t *addresses = NULL; - unsigned int i = 0; - while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { - mp_int_t value; - if (!mp_obj_get_int_maybe(item, &value)) { - mp_raise_TypeError_varg(translate("can't convert %q to %q"), MP_QSTR_address, MP_QSTR_int); - } - if (value < 0x00 || value > 0x7f) { - mp_raise_ValueError(translate("address out of bounds")); - } - addresses = m_renew(uint8_t, addresses, i, i + 1); - addresses[i++] = value; - } - if (i == 0) { - mp_raise_ValueError(translate("addresses is empty")); - } - - common_hal_i2cperipheral_i2c_peripheral_construct(self, scl, sda, addresses, i, args[ARG_smbus].u_bool); - return (mp_obj_t)self; -} - -//| def deinit(self) -> None: -//| """Releases control of the underlying hardware so other classes can use it.""" -//| ... -//| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_obj_deinit(mp_obj_t self_in) { - mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cperipheral_i2c_peripheral_type)); - i2cperipheral_i2c_peripheral_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_i2cperipheral_i2c_peripheral_deinit(self); - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_1(i2cperipheral_i2c_peripheral_deinit_obj, i2cperipheral_i2c_peripheral_obj_deinit); - -//| def __enter__(self) -> I2CPeripheral: -//| """No-op used in Context Managers.""" -//| ... -//| -// Provided by context manager helper. - -//| def __exit__(self) -> None: -//| """Automatically deinitializes the hardware on context exit. See -//| :ref:`lifetime-and-contextmanagers` for more info.""" -//| ... -//| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_obj___exit__(size_t n_args, const mp_obj_t *args) { - mp_check_self(MP_OBJ_IS_TYPE(args[0], &i2cperipheral_i2c_peripheral_type)); - i2cperipheral_i2c_peripheral_obj_t *self = MP_OBJ_TO_PTR(args[0]); - common_hal_i2cperipheral_i2c_peripheral_deinit(self); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cperipheral_i2c_peripheral___exit___obj, 4, 4, i2cperipheral_i2c_peripheral_obj___exit__); - -//| def request(self, timeout: float = -1) -> I2CPeripheralRequest: -//| """Wait for an I2C request. -//| -//| :param float timeout: Timeout in seconds. Zero means wait forever, a negative value means check once -//| :return: I2C Slave Request or None if timeout=-1 and there's no request -//| :rtype: ~i2cperipheral.I2CPeripheralRequest""" -//| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_request(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - mp_check_self(MP_OBJ_IS_TYPE(pos_args[0], &i2cperipheral_i2c_peripheral_type)); - i2cperipheral_i2c_peripheral_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - if(common_hal_i2cperipheral_i2c_peripheral_deinited(self)) { - raise_deinited_error(); - } - enum { ARG_timeout }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NEW_SMALL_INT(-1)} }, - }; - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - #if MICROPY_PY_BUILTINS_FLOAT - float f = mp_obj_get_float(args[ARG_timeout].u_obj) * 1000; - int timeout_ms = (int)f; - #else - int timeout_ms = mp_obj_get_int(args[ARG_timeout].u_obj) * 1000; - #endif - - bool forever = false; - uint64_t timeout_end = 0; - if (timeout_ms == 0) { - forever = true; - } else if (timeout_ms > 0) { - timeout_end = common_hal_time_monotonic() + timeout_ms; - } - - int last_error = 0; - - do { - uint8_t address; - bool is_read; - bool is_restart; - - RUN_BACKGROUND_TASKS; - if (mp_hal_is_interrupted()) { - return mp_const_none; - } - - int status = common_hal_i2cperipheral_i2c_peripheral_is_addressed(self, &address, &is_read, &is_restart); - if (status < 0) { - // On error try one more time before bailing out - if (last_error) { - mp_raise_OSError(last_error); - } - last_error = -status; - mp_hal_delay_ms(10); - continue; - } - - last_error = 0; - - if (status == 0) { - mp_hal_delay_us(10); - continue; - } - - return mp_obj_new_i2cperipheral_i2c_peripheral_request(self, address, is_read, is_restart); - } while (forever || common_hal_time_monotonic() < timeout_end); - - if (timeout_ms > 0) { - mp_raise_OSError(MP_ETIMEDOUT); - } - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(i2cperipheral_i2c_peripheral_request_obj, 1, i2cperipheral_i2c_peripheral_request); - -STATIC const mp_rom_map_elem_t i2cperipheral_i2c_peripheral_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_deinit_obj) }, - { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, - { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&i2cperipheral_i2c_peripheral___exit___obj) }, - { MP_ROM_QSTR(MP_QSTR_request), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_obj) }, - -}; - -STATIC MP_DEFINE_CONST_DICT(i2cperipheral_i2c_peripheral_locals_dict, i2cperipheral_i2c_peripheral_locals_dict_table); - -const mp_obj_type_t i2cperipheral_i2c_peripheral_type = { - { &mp_type_type }, - .name = MP_QSTR_I2CPeripheral, - .make_new = i2cperipheral_i2c_peripheral_make_new, - .locals_dict = (mp_obj_dict_t*)&i2cperipheral_i2c_peripheral_locals_dict, -}; - -//| class I2CPeripheralRequest: -//| -//| def __init__(self, peripheral: i2cperipheral.I2CPeripheral, address: int, is_read: bool, is_restart: bool) -> None: -//| """Information about an I2C transfer request -//| This cannot be instantiated directly, but is returned by :py:meth:`I2CPeripheral.request`. -//| -//| :param peripheral: The I2CPeripheral object receiving this request -//| :param address: I2C address -//| :param is_read: True if the main peripheral is requesting data -//| :param is_restart: Repeated Start Condition""" -//| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 4, 4, false); - return mp_obj_new_i2cperipheral_i2c_peripheral_request(args[0], mp_obj_get_int(args[1]), mp_obj_is_true(args[2]), mp_obj_is_true(args[3])); -} - -//| def __enter__(self) -> I2CPeripheralRequest: -//| """No-op used in Context Managers.""" -//| ... -//| -// Provided by context manager helper. - -//| def __exit__(self) -> None: -//| """Close the request.""" -//| ... -//| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_obj___exit__(size_t n_args, const mp_obj_t *args) { - mp_check_self(MP_OBJ_IS_TYPE(args[0], &i2cperipheral_i2c_peripheral_request_type)); - i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(args[0]); - common_hal_i2cperipheral_i2c_peripheral_close(self->peripheral); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cperipheral_i2c_peripheral_request___exit___obj, 4, 4, i2cperipheral_i2c_peripheral_request_obj___exit__); - -//| address: int -//| """The I2C address of the request.""" -//| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_get_address(mp_obj_t self_in) { - mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cperipheral_i2c_peripheral_request_type)); - i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_int(self->address); -} -MP_DEFINE_CONST_PROP_GET(i2cperipheral_i2c_peripheral_request_address_obj, i2cperipheral_i2c_peripheral_request_get_address); - -//| is_read: bool -//| """The I2C main controller is reading from this peripheral.""" -//| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_get_is_read(mp_obj_t self_in) { - mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cperipheral_i2c_peripheral_request_type)); - i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_bool(self->is_read); -} -MP_DEFINE_CONST_PROP_GET(i2cperipheral_i2c_peripheral_request_is_read_obj, i2cperipheral_i2c_peripheral_request_get_is_read); - -//| is_restart: bool -//| """Is Repeated Start Condition.""" -//| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_get_is_restart(mp_obj_t self_in) { - mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cperipheral_i2c_peripheral_request_type)); - i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(self_in); - return mp_obj_new_bool(self->is_restart); -} -MP_DEFINE_CONST_PROP_GET(i2cperipheral_i2c_peripheral_request_is_restart_obj, i2cperipheral_i2c_peripheral_request_get_is_restart); - -//| def read(self, n: int = -1, ack: bool = True) -> bytearray: -//| """Read data. -//| If ack=False, the caller is responsible for calling :py:meth:`I2CPeripheralRequest.ack`. -//| -//| :param n: Number of bytes to read (negative means all) -//| :param ack: Whether or not to send an ACK after the n'th byte -//| :return: Bytes read""" -//| ... -//| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_read(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - mp_check_self(MP_OBJ_IS_TYPE(pos_args[0], &i2cperipheral_i2c_peripheral_request_type)); - i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - enum { ARG_n, ARG_ack }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_n, MP_ARG_INT, {.u_int = -1} }, - { MP_QSTR_ack, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} }, - }; - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - if (self->is_read) { - mp_raise_OSError(MP_EACCES); - } - - int n = args[ARG_n].u_int; - if (n == 0) { - return mp_obj_new_bytearray(0, NULL); - } - bool ack = args[ARG_ack].u_bool; - - int i = 0; - uint8_t *buffer = NULL; - uint64_t timeout_end = common_hal_time_monotonic() + 10 * 1000; - while (common_hal_time_monotonic() < timeout_end) { - RUN_BACKGROUND_TASKS; - if (mp_hal_is_interrupted()) { - break; - } - - uint8_t data; - int num = common_hal_i2cperipheral_i2c_peripheral_read_byte(self->peripheral, &data); - if (num == 0) { - break; - } - - buffer = m_renew(uint8_t, buffer, i, i + 1); - buffer[i++] = data; - if (i == n) { - if (ack) { - common_hal_i2cperipheral_i2c_peripheral_ack(self->peripheral, true); - } - break; - } - common_hal_i2cperipheral_i2c_peripheral_ack(self->peripheral, true); - } - - return mp_obj_new_bytearray(i, buffer); -} -MP_DEFINE_CONST_FUN_OBJ_KW(i2cperipheral_i2c_peripheral_request_read_obj, 1, i2cperipheral_i2c_peripheral_request_read); - -//| def write(self, buffer: ReadableBuffer) -> int: -//| """Write the data contained in buffer. -//| -//| :param ~_typing.ReadableBuffer buffer: Write out the data in this buffer -//| :return: Number of bytes written""" -//| ... -//| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_write(mp_obj_t self_in, mp_obj_t buf_in) { - mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cperipheral_i2c_peripheral_request_type)); - i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(self_in); - - if (!self->is_read) { - mp_raise_OSError(MP_EACCES); - } - - mp_buffer_info_t bufinfo; - mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ); - - for (size_t i = 0; i < bufinfo.len; i++) { - RUN_BACKGROUND_TASKS; - if (mp_hal_is_interrupted()) { - break; - } - - int num = common_hal_i2cperipheral_i2c_peripheral_write_byte(self->peripheral, ((uint8_t *)(bufinfo.buf))[i]); - if (num == 0) { - return mp_obj_new_int(i); - } - } - - return mp_obj_new_int(bufinfo.len); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(i2cperipheral_i2c_peripheral_request_write_obj, i2cperipheral_i2c_peripheral_request_write); - -//| def ack(self, ack: bool = True) -> None: -//| """Acknowledge or Not Acknowledge last byte received. -//| Use together with :py:meth:`I2CPeripheralRequest.read` ack=False. -//| -//| :param ack: Whether to send an ACK or NACK""" -//| ... -//| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_ack(uint n_args, const mp_obj_t *args) { - mp_check_self(MP_OBJ_IS_TYPE(args[0], &i2cperipheral_i2c_peripheral_request_type)); - i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(args[0]); - bool ack = (n_args == 1) ? true : mp_obj_is_true(args[1]); - - if (self->is_read) { - mp_raise_OSError(MP_EACCES); - } - - common_hal_i2cperipheral_i2c_peripheral_ack(self->peripheral, ack); - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(i2cperipheral_i2c_peripheral_request_ack_obj, 1, 2, i2cperipheral_i2c_peripheral_request_ack); - -STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_close(mp_obj_t self_in) { - mp_check_self(MP_OBJ_IS_TYPE(self_in, &i2cperipheral_i2c_peripheral_request_type)); - i2cperipheral_i2c_peripheral_request_obj_t *self = MP_OBJ_TO_PTR(self_in); - - common_hal_i2cperipheral_i2c_peripheral_close(self->peripheral); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(i2cperipheral_i2c_peripheral_request_close_obj, i2cperipheral_i2c_peripheral_request_close); - -STATIC const mp_rom_map_elem_t i2cperipheral_i2c_peripheral_request_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, - { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request___exit___obj) }, - { MP_ROM_QSTR(MP_QSTR_address), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_address_obj) }, - { MP_ROM_QSTR(MP_QSTR_is_read), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_is_read_obj) }, - { MP_ROM_QSTR(MP_QSTR_is_restart), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_is_restart_obj) }, - { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_read_obj) }, - { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_write_obj) }, - { MP_ROM_QSTR(MP_QSTR_ack), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_ack_obj) }, - { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_request_close_obj) }, -}; - -STATIC MP_DEFINE_CONST_DICT(i2cperipheral_i2c_peripheral_request_locals_dict, i2cperipheral_i2c_peripheral_request_locals_dict_table); - -const mp_obj_type_t i2cperipheral_i2c_peripheral_request_type = { - { &mp_type_type }, - .name = MP_QSTR_I2CPeripheralRequest, - .make_new = i2cperipheral_i2c_peripheral_request_make_new, - .locals_dict = (mp_obj_dict_t*)&i2cperipheral_i2c_peripheral_request_locals_dict, -}; diff --git a/shared-bindings/i2cperipheral/I2CPeripheral 2.h b/shared-bindings/i2cperipheral/I2CPeripheral 2.h deleted file mode 100644 index 3035cfbfe7..0000000000 --- a/shared-bindings/i2cperipheral/I2CPeripheral 2.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Noralf Trønnes - * - * 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_BUSIO_I2C_SLAVE_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_I2C_SLAVE_H - -#include "py/obj.h" - -#include "common-hal/microcontroller/Pin.h" -#include "common-hal/i2cperipheral/I2CPeripheral.h" - -typedef struct { - mp_obj_base_t base; - i2cperipheral_i2c_peripheral_obj_t *peripheral; - uint16_t address; - bool is_read; - bool is_restart; -} i2cperipheral_i2c_peripheral_request_obj_t; - -extern const mp_obj_type_t i2cperipheral_i2c_peripheral_request_type; - -extern const mp_obj_type_t i2cperipheral_i2c_peripheral_type; - -extern 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); -extern void common_hal_i2cperipheral_i2c_peripheral_deinit(i2cperipheral_i2c_peripheral_obj_t *self); -extern bool common_hal_i2cperipheral_i2c_peripheral_deinited(i2cperipheral_i2c_peripheral_obj_t *self); - -extern int common_hal_i2cperipheral_i2c_peripheral_is_addressed(i2cperipheral_i2c_peripheral_obj_t *self, - uint8_t *address, bool *is_read, bool *is_restart); -extern int common_hal_i2cperipheral_i2c_peripheral_read_byte(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t *data); -extern int common_hal_i2cperipheral_i2c_peripheral_write_byte(i2cperipheral_i2c_peripheral_obj_t *self, uint8_t data); -extern void common_hal_i2cperipheral_i2c_peripheral_ack(i2cperipheral_i2c_peripheral_obj_t *self, bool ack); -extern void common_hal_i2cperipheral_i2c_peripheral_close(i2cperipheral_i2c_peripheral_obj_t *self); - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_I2C_SLAVE_H diff --git a/shared-bindings/i2cperipheral/__init__ 2.c b/shared-bindings/i2cperipheral/__init__ 2.c deleted file mode 100644 index e2cb8509d6..0000000000 --- a/shared-bindings/i2cperipheral/__init__ 2.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2018 Noralf Trønnes - * - * 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/obj.h" -#include "py/runtime.h" - -#include "shared-bindings/microcontroller/Pin.h" -//#include "shared-bindings/i2cperipheral/__init__.h" -#include "shared-bindings/i2cperipheral/I2CPeripheral.h" - -#include "py/runtime.h" - -//| """Two wire serial protocol peripheral -//| -//| The `i2cperipheral` module contains classes to support an I2C peripheral. -//| -//| Example emulating a peripheral with 2 addresses (read and write):: -//| -//| import board -//| from i2cperipheral import I2CPeripheral -//| -//| regs = [0] * 16 -//| index = 0 -//| -//| with I2CPeripheral(board.SCL, board.SDA, (0x40, 0x41)) as device: -//| while True: -//| r = device.request() -//| if not r: -//| # Maybe do some housekeeping -//| continue -//| with r: # Closes the transfer if necessary by sending a NACK or feeding dummy bytes -//| if r.address == 0x40: -//| if not r.is_read: # Main write which is Selected read -//| b = r.read(1) -//| if not b or b[0] > 15: -//| break -//| index = b[0] -//| b = r.read(1) -//| if b: -//| regs[index] = b[0] -//| elif r.is_restart: # Combined transfer: This is the Main read message -//| n = r.write(bytes([regs[index]])) -//| #else: -//| # A read transfer is not supported in this example -//| # If the microcontroller tries, it will get 0xff byte(s) by the ctx manager (r.close()) -//| elif r.address == 0x41: -//| if not r.is_read: -//| b = r.read(1) -//| if b and b[0] == 0xde: -//| # do something -//| pass -//| -//| This example sets up an I2C device that can be accessed from Linux like this:: -//| -//| $ i2cget -y 1 0x40 0x01 -//| 0x00 -//| $ i2cset -y 1 0x40 0x01 0xaa -//| $ i2cget -y 1 0x40 0x01 -//| 0xaa -//| -//| .. warning:: -//| I2CPeripheral makes use of clock stretching in order to slow down -//| the host. -//| Make sure the I2C host supports this. -//| -//| Raspberry Pi in particular does not support this with its I2C hw block. -//| This can be worked around by using the ``i2c-gpio`` bit banging driver. -//| Since the RPi firmware uses the hw i2c, it's not possible to emulate a HAT eeprom.""" -//| - -STATIC const mp_rom_map_elem_t i2cperipheral_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_i2cperipheral) }, - { MP_ROM_QSTR(MP_QSTR_I2CPeripheral), MP_ROM_PTR(&i2cperipheral_i2c_peripheral_type) }, -}; - -STATIC MP_DEFINE_CONST_DICT(i2cperipheral_module_globals, i2cperipheral_module_globals_table); - -const mp_obj_module_t i2cperipheral_module = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t*)&i2cperipheral_module_globals, -}; diff --git a/shared-bindings/memorymonitor/AllocationAlarm 2.c b/shared-bindings/memorymonitor/AllocationAlarm 2.c deleted file mode 100644 index 7de8c12874..0000000000 --- a/shared-bindings/memorymonitor/AllocationAlarm 2.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * This file is part of the Micro Python 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 - -#include "py/objproperty.h" -#include "py/runtime.h" -#include "py/runtime0.h" -#include "shared-bindings/memorymonitor/AllocationAlarm.h" -#include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" - -//| class AllocationAlarm: -//| -//| def __init__(self, *, minimum_block_count: int = 1) -> None: -//| """Throw an exception when an allocation of ``minimum_block_count`` or more blocks -//| occurs while active. -//| -//| Track allocations:: -//| -//| import memorymonitor -//| -//| aa = memorymonitor.AllocationAlarm(minimum_block_count=2) -//| x = 2 -//| # Should not allocate any blocks. -//| with aa: -//| x = 5 -//| -//| # Should throw an exception when allocating storage for the 20 bytes. -//| with aa: -//| x = bytearray(20) -//| -//| """ -//| ... -//| -STATIC mp_obj_t memorymonitor_allocationalarm_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_minimum_block_count }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_minimum_block_count, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} }, - }; - 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_int_t minimum_block_count = args[ARG_minimum_block_count].u_int; - if (minimum_block_count < 1) { - mp_raise_ValueError_varg(translate("%q must be >= 1"), MP_QSTR_minimum_block_count); - } - - memorymonitor_allocationalarm_obj_t *self = m_new_obj(memorymonitor_allocationalarm_obj_t); - self->base.type = &memorymonitor_allocationalarm_type; - - common_hal_memorymonitor_allocationalarm_construct(self, minimum_block_count); - - return MP_OBJ_FROM_PTR(self); -} - -//| def ignore(self, count: int) -> AllocationAlarm: -//| """Sets the number of applicable allocations to ignore before raising the exception. -//| Automatically set back to zero at context exit. -//| -//| Use it within a ``with`` block:: -//| -//| # Will not alarm because the bytearray allocation will be ignored. -//| with aa.ignore(2): -//| x = bytearray(20) -//| """ -//| ... -//| -STATIC mp_obj_t memorymonitor_allocationalarm_obj_ignore(mp_obj_t self_in, mp_obj_t count_obj) { - mp_int_t count = mp_obj_get_int(count_obj); - if (count < 0) { - mp_raise_ValueError_varg(translate("%q must be >= 0"), MP_QSTR_count); - } - common_hal_memorymonitor_allocationalarm_set_ignore(self_in, count); - return self_in; -} -MP_DEFINE_CONST_FUN_OBJ_2(memorymonitor_allocationalarm_ignore_obj, memorymonitor_allocationalarm_obj_ignore); - -//| def __enter__(self) -> AllocationAlarm: -//| """Enables the alarm.""" -//| ... -//| -STATIC mp_obj_t memorymonitor_allocationalarm_obj___enter__(mp_obj_t self_in) { - common_hal_memorymonitor_allocationalarm_resume(self_in); - return self_in; -} -MP_DEFINE_CONST_FUN_OBJ_1(memorymonitor_allocationalarm___enter___obj, memorymonitor_allocationalarm_obj___enter__); - -//| def __exit__(self) -> None: -//| """Automatically disables the allocation alarm when exiting a context. See -//| :ref:`lifetime-and-contextmanagers` for more info.""" -//| ... -//| -STATIC mp_obj_t memorymonitor_allocationalarm_obj___exit__(size_t n_args, const mp_obj_t *args) { - (void)n_args; - common_hal_memorymonitor_allocationalarm_set_ignore(args[0], 0); - common_hal_memorymonitor_allocationalarm_pause(args[0]); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(memorymonitor_allocationalarm___exit___obj, 4, 4, memorymonitor_allocationalarm_obj___exit__); - -STATIC const mp_rom_map_elem_t memorymonitor_allocationalarm_locals_dict_table[] = { - // Methods - { MP_ROM_QSTR(MP_QSTR_ignore), MP_ROM_PTR(&memorymonitor_allocationalarm_ignore_obj) }, - { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&memorymonitor_allocationalarm___enter___obj) }, - { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&memorymonitor_allocationalarm___exit___obj) }, -}; -STATIC MP_DEFINE_CONST_DICT(memorymonitor_allocationalarm_locals_dict, memorymonitor_allocationalarm_locals_dict_table); - -const mp_obj_type_t memorymonitor_allocationalarm_type = { - { &mp_type_type }, - .name = MP_QSTR_AllocationAlarm, - .make_new = memorymonitor_allocationalarm_make_new, - .locals_dict = (mp_obj_dict_t*)&memorymonitor_allocationalarm_locals_dict, -}; diff --git a/shared-bindings/memorymonitor/AllocationAlarm 2.h b/shared-bindings/memorymonitor/AllocationAlarm 2.h deleted file mode 100644 index 304b9c5a72..0000000000 --- a/shared-bindings/memorymonitor/AllocationAlarm 2.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This file is part of the Micro Python 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. - */ - -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_MEMORYMONITOR_ALLOCATIONALARM_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_MEMORYMONITOR_ALLOCATIONALARM_H - -#include "shared-module/memorymonitor/AllocationAlarm.h" - -extern const mp_obj_type_t memorymonitor_allocationalarm_type; - -void common_hal_memorymonitor_allocationalarm_construct(memorymonitor_allocationalarm_obj_t* self, size_t minimum_block_count); -void common_hal_memorymonitor_allocationalarm_pause(memorymonitor_allocationalarm_obj_t* self); -void common_hal_memorymonitor_allocationalarm_resume(memorymonitor_allocationalarm_obj_t* self); -void common_hal_memorymonitor_allocationalarm_set_ignore(memorymonitor_allocationalarm_obj_t* self, mp_int_t count); - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_MEMORYMONITOR_ALLOCATIONALARM_H diff --git a/shared-bindings/memorymonitor/AllocationSize 2.c b/shared-bindings/memorymonitor/AllocationSize 2.c deleted file mode 100644 index b35bae3602..0000000000 --- a/shared-bindings/memorymonitor/AllocationSize 2.c +++ /dev/null @@ -1,183 +0,0 @@ -/* - * This file is part of the Micro Python 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 - -#include "py/objproperty.h" -#include "py/runtime.h" -#include "py/runtime0.h" -#include "shared-bindings/memorymonitor/AllocationSize.h" -#include "shared-bindings/util.h" -#include "supervisor/shared/translate.h" - -//| class AllocationSize: -//| -//| def __init__(self) -> None: -//| """Tracks the number of allocations in power of two buckets. -//| -//| It will have 16 16-bit buckets to track allocation counts. It is total allocations -//| meaning frees are ignored. Reallocated memory is counted twice, at allocation and when -//| reallocated with the larger size. -//| -//| The buckets are measured in terms of blocks which is the finest granularity of the heap. -//| This means bucket 0 will count all allocations less than or equal to the number of bytes -//| per block, typically 16. Bucket 2 will be less than or equal to 4 blocks. See -//| `bytes_per_block` to convert blocks to bytes. -//| -//| Multiple AllocationSizes can be used to track different code boundaries. -//| -//| Track allocations:: -//| -//| import memorymonitor -//| -//| mm = memorymonitor.AllocationSize() -//| with mm: -//| print("hello world" * 3) -//| -//| for bucket, count in enumerate(mm): -//| print("<", 2 ** bucket, count) -//| -//| """ -//| ... -//| -STATIC mp_obj_t memorymonitor_allocationsize_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - memorymonitor_allocationsize_obj_t *self = m_new_obj(memorymonitor_allocationsize_obj_t); - self->base.type = &memorymonitor_allocationsize_type; - - common_hal_memorymonitor_allocationsize_construct(self); - - return MP_OBJ_FROM_PTR(self); -} - -//| def __enter__(self) -> AllocationSize: -//| """Clears counts and resumes tracking.""" -//| ... -//| -STATIC mp_obj_t memorymonitor_allocationsize_obj___enter__(mp_obj_t self_in) { - common_hal_memorymonitor_allocationsize_clear(self_in); - common_hal_memorymonitor_allocationsize_resume(self_in); - return self_in; -} -MP_DEFINE_CONST_FUN_OBJ_1(memorymonitor_allocationsize___enter___obj, memorymonitor_allocationsize_obj___enter__); - -//| def __exit__(self) -> None: -//| """Automatically pauses allocation tracking when exiting a context. See -//| :ref:`lifetime-and-contextmanagers` for more info.""" -//| ... -//| -STATIC mp_obj_t memorymonitor_allocationsize_obj___exit__(size_t n_args, const mp_obj_t *args) { - (void)n_args; - common_hal_memorymonitor_allocationsize_pause(args[0]); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(memorymonitor_allocationsize___exit___obj, 4, 4, memorymonitor_allocationsize_obj___exit__); - -//| bytes_per_block: int -//| """Number of bytes per block""" -//| -STATIC mp_obj_t memorymonitor_allocationsize_obj_get_bytes_per_block(mp_obj_t self_in) { - memorymonitor_allocationsize_obj_t *self = MP_OBJ_TO_PTR(self_in); - - return MP_OBJ_NEW_SMALL_INT(common_hal_memorymonitor_allocationsize_get_bytes_per_block(self)); -} -MP_DEFINE_CONST_FUN_OBJ_1(memorymonitor_allocationsize_get_bytes_per_block_obj, memorymonitor_allocationsize_obj_get_bytes_per_block); - -const mp_obj_property_t memorymonitor_allocationsize_bytes_per_block_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&memorymonitor_allocationsize_get_bytes_per_block_obj, - (mp_obj_t)&mp_const_none_obj, - (mp_obj_t)&mp_const_none_obj}, -}; - -//| def __len__(self) -> int: -//| """Returns the number of allocation buckets. -//| -//| This allows you to:: -//| -//| mm = memorymonitor.AllocationSize() -//| print(len(mm))""" -//| ... -//| -STATIC mp_obj_t memorymonitor_allocationsize_unary_op(mp_unary_op_t op, mp_obj_t self_in) { - memorymonitor_allocationsize_obj_t *self = MP_OBJ_TO_PTR(self_in); - uint16_t len = common_hal_memorymonitor_allocationsize_get_len(self); - switch (op) { - case MP_UNARY_OP_BOOL: return mp_obj_new_bool(len != 0); - case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(len); - default: return MP_OBJ_NULL; // op not supported - } -} - -//| def __getitem__(self, index: int) -> Optional[int]: -//| """Returns the allocation count for the given bucket. -//| -//| This allows you to:: -//| -//| mm = memorymonitor.AllocationSize() -//| print(mm[0])""" -//| ... -//| -STATIC mp_obj_t memorymonitor_allocationsize_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t value) { - if (value == mp_const_none) { - // delete item - mp_raise_AttributeError(translate("Cannot delete values")); - } else { - memorymonitor_allocationsize_obj_t *self = MP_OBJ_TO_PTR(self_in); - - if (MP_OBJ_IS_TYPE(index_obj, &mp_type_slice)) { - mp_raise_NotImplementedError(translate("Slices not supported")); - } else { - size_t index = mp_get_index(&memorymonitor_allocationsize_type, common_hal_memorymonitor_allocationsize_get_len(self), index_obj, false); - if (value == MP_OBJ_SENTINEL) { - // load - return MP_OBJ_NEW_SMALL_INT(common_hal_memorymonitor_allocationsize_get_item(self, index)); - } else { - mp_raise_AttributeError(translate("Read-only")); - } - } - } - return mp_const_none; -} - -STATIC const mp_rom_map_elem_t memorymonitor_allocationsize_locals_dict_table[] = { - // Methods - { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&memorymonitor_allocationsize___enter___obj) }, - { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&memorymonitor_allocationsize___exit___obj) }, - - // Properties - { MP_ROM_QSTR(MP_QSTR_bytes_per_block), MP_ROM_PTR(&memorymonitor_allocationsize_bytes_per_block_obj) }, -}; -STATIC MP_DEFINE_CONST_DICT(memorymonitor_allocationsize_locals_dict, memorymonitor_allocationsize_locals_dict_table); - -const mp_obj_type_t memorymonitor_allocationsize_type = { - { &mp_type_type }, - .name = MP_QSTR_AllocationSize, - .make_new = memorymonitor_allocationsize_make_new, - .subscr = memorymonitor_allocationsize_subscr, - .unary_op = memorymonitor_allocationsize_unary_op, - .getiter = mp_obj_new_generic_iterator, - .locals_dict = (mp_obj_dict_t*)&memorymonitor_allocationsize_locals_dict, -}; diff --git a/shared-bindings/memorymonitor/AllocationSize 2.h b/shared-bindings/memorymonitor/AllocationSize 2.h deleted file mode 100644 index bcd9514bf2..0000000000 --- a/shared-bindings/memorymonitor/AllocationSize 2.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * This file is part of the Micro Python 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. - */ - -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_MEMORYMONITOR_ALLOCATIONSIZE_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_MEMORYMONITOR_ALLOCATIONSIZE_H - -#include "shared-module/memorymonitor/AllocationSize.h" - -extern const mp_obj_type_t memorymonitor_allocationsize_type; - -extern void common_hal_memorymonitor_allocationsize_construct(memorymonitor_allocationsize_obj_t* self); -extern void common_hal_memorymonitor_allocationsize_pause(memorymonitor_allocationsize_obj_t* self); -extern void common_hal_memorymonitor_allocationsize_resume(memorymonitor_allocationsize_obj_t* self); -extern void common_hal_memorymonitor_allocationsize_clear(memorymonitor_allocationsize_obj_t* self); -extern size_t common_hal_memorymonitor_allocationsize_get_bytes_per_block(memorymonitor_allocationsize_obj_t* self); -extern uint16_t common_hal_memorymonitor_allocationsize_get_len(memorymonitor_allocationsize_obj_t* self); -extern uint16_t common_hal_memorymonitor_allocationsize_get_item(memorymonitor_allocationsize_obj_t* self, int16_t index); - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_MEMORYMONITOR_ALLOCATIONSIZE_H diff --git a/shared-bindings/memorymonitor/__init__ 2.c b/shared-bindings/memorymonitor/__init__ 2.c deleted file mode 100644 index c101ba5e0d..0000000000 --- a/shared-bindings/memorymonitor/__init__ 2.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2020 Scott Shawcroft - * - * 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/obj.h" -#include "py/runtime.h" - -#include "shared-bindings/memorymonitor/__init__.h" -#include "shared-bindings/memorymonitor/AllocationAlarm.h" -#include "shared-bindings/memorymonitor/AllocationSize.h" - -//| """Memory monitoring helpers""" -//| - -//| class AllocationError(Exception): -//| """Catchall exception for allocation related errors.""" -//| ... -MP_DEFINE_MEMORYMONITOR_EXCEPTION(AllocationError, Exception) - -NORETURN void mp_raise_memorymonitor_AllocationError(const compressed_string_t* fmt, ...) { - va_list argptr; - va_start(argptr,fmt); - mp_obj_t exception = mp_obj_new_exception_msg_vlist(&mp_type_memorymonitor_AllocationError, fmt, argptr); - va_end(argptr); - nlr_raise(exception); -} - -STATIC const mp_rom_map_elem_t memorymonitor_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_memorymonitor) }, - { MP_ROM_QSTR(MP_QSTR_AllocationAlarm), MP_ROM_PTR(&memorymonitor_allocationalarm_type) }, - { MP_ROM_QSTR(MP_QSTR_AllocationSize), MP_ROM_PTR(&memorymonitor_allocationsize_type) }, - - // Errors - { MP_ROM_QSTR(MP_QSTR_AllocationError), MP_ROM_PTR(&mp_type_memorymonitor_AllocationError) }, -}; - -STATIC MP_DEFINE_CONST_DICT(memorymonitor_module_globals, memorymonitor_module_globals_table); - -void memorymonitor_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { - mp_print_kind_t k = kind & ~PRINT_EXC_SUBCLASS; - bool is_subclass = kind & PRINT_EXC_SUBCLASS; - if (!is_subclass && (k == PRINT_EXC)) { - mp_print_str(print, qstr_str(MP_OBJ_QSTR_VALUE(memorymonitor_module_globals_table[0].value))); - mp_print_str(print, "."); - } - mp_obj_exception_print(print, o_in, kind); -} - -const mp_obj_module_t memorymonitor_module = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t*)&memorymonitor_module_globals, -}; diff --git a/shared-bindings/memorymonitor/__init__ 2.h b/shared-bindings/memorymonitor/__init__ 2.h deleted file mode 100644 index 60fcdc3f62..0000000000 --- a/shared-bindings/memorymonitor/__init__ 2.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2016 Scott Shawcroft - * - * 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_MEMORYMONITOR___INIT___H -#define MICROPY_INCLUDED_SHARED_BINDINGS_MEMORYMONITOR___INIT___H - -#include "py/obj.h" - - -void memorymonitor_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind); - -#define MP_DEFINE_MEMORYMONITOR_EXCEPTION(exc_name, base_name) \ -const mp_obj_type_t mp_type_memorymonitor_ ## exc_name = { \ - { &mp_type_type }, \ - .name = MP_QSTR_ ## exc_name, \ - .print = memorymonitor_exception_print, \ - .make_new = mp_obj_exception_make_new, \ - .attr = mp_obj_exception_attr, \ - .parent = &mp_type_ ## base_name, \ -}; - -extern const mp_obj_type_t mp_type_memorymonitor_AllocationError; - -NORETURN void mp_raise_memorymonitor_AllocationError(const compressed_string_t* msg, ...); - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_MEMORYMONITOR___INIT___H diff --git a/shared-bindings/sdcardio/SDCard 2.c b/shared-bindings/sdcardio/SDCard 2.c deleted file mode 100644 index 975f8b0953..0000000000 --- a/shared-bindings/sdcardio/SDCard 2.c +++ /dev/null @@ -1,183 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2020 Jeff Epler 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/objproperty.h" -#include "py/runtime.h" -#include "py/objarray.h" - -#include "shared-bindings/sdcardio/SDCard.h" -#include "shared-module/sdcardio/SDCard.h" -#include "common-hal/busio/SPI.h" -#include "shared-bindings/busio/SPI.h" -#include "shared-bindings/microcontroller/Pin.h" -#include "supervisor/flash.h" - -//| class SDCard: -//| """SD Card Block Interface -//| -//| Controls an SD card over SPI. This built-in module has higher read -//| performance than the library adafruit_sdcard, but it is only compatible with -//| `busio.SPI`, not `bitbangio.SPI`. Usually an SDCard object is used -//| with ``storage.VfsFat`` to allow file I/O to an SD card.""" -//| -//| def __init__(self, bus: busio.SPI, cs: microcontroller.Pin, baudrate: int = 8000000) -> None: -//| """Construct an SPI SD Card object with the given properties -//| -//| :param busio.SPI spi: The SPI bus -//| :param microcontroller.Pin cs: The chip select connected to the card -//| :param int baudrate: The SPI data rate to use after card setup -//| -//| Note that during detection and configuration, a hard-coded low baudrate is used. -//| Data transfers use the specified baurate (rounded down to one that is supported by -//| the microcontroller) -//| -//| Example usage: -//| -//| .. code-block:: python -//| -//| import os -//| -//| import board -//| import sdcardio -//| import storage -//| -//| sd = sdcardio.SDCard(board.SPI(), board.SD_CS) -//| vfs = storage.VfsFat(sd) -//| storage.mount(vfs, '/sd') -//| os.listdir('/sd')""" - -STATIC mp_obj_t sdcardio_sdcard_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_spi, ARG_cs, ARG_baudrate, ARG_sdio, NUM_ARGS }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_spi, MP_ARG_OBJ, {.u_obj = mp_const_none } }, - { MP_QSTR_cs, MP_ARG_OBJ, {.u_obj = mp_const_none } }, - { MP_QSTR_baudrate, MP_ARG_INT, {.u_int = 8000000} }, - { MP_QSTR_sdio, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_int = 8000000} }, - }; - MP_STATIC_ASSERT( MP_ARRAY_SIZE(allowed_args) == NUM_ARGS ); - 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); - - busio_spi_obj_t *spi = validate_obj_is_spi_bus(args[ARG_spi].u_obj); - mcu_pin_obj_t *cs = validate_obj_is_free_pin(args[ARG_cs].u_obj); - - sdcardio_sdcard_obj_t *self = m_new_obj(sdcardio_sdcard_obj_t); - self->base.type = &sdcardio_SDCard_type; - - common_hal_sdcardio_sdcard_construct(self, spi, cs, args[ARG_baudrate].u_int); - - return self; -} - - -//| def count(self) -> int: -//| """Returns the total number of sectors -//| -//| Due to technical limitations, this is a function and not a property. -//| -//| :return: The number of 512-byte blocks, as a number""" -//| -mp_obj_t sdcardio_sdcard_count(mp_obj_t self_in) { - sdcardio_sdcard_obj_t *self = (sdcardio_sdcard_obj_t*)self_in; - return mp_obj_new_int_from_ull(common_hal_sdcardio_sdcard_get_blockcount(self)); -} -MP_DEFINE_CONST_FUN_OBJ_1(sdcardio_sdcard_count_obj, sdcardio_sdcard_count); - -//| def deinit(self) -> None: -//| """Disable permanently. -//| -//| :return: None""" -//| -mp_obj_t sdcardio_sdcard_deinit(mp_obj_t self_in) { - sdcardio_sdcard_obj_t *self = (sdcardio_sdcard_obj_t*)self_in; - common_hal_sdcardio_sdcard_deinit(self); - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_1(sdcardio_sdcard_deinit_obj, sdcardio_sdcard_deinit); - - -//| def readblocks(self, start_block: int, buf: WriteableBuffer) -> None: -//| -//| """Read one or more blocks from the card -//| -//| :param int start_block: The block to start reading from -//| :param ~_typing.WriteableBuffer buf: The buffer to write into. Length must be multiple of 512. -//| -//| :return: None""" -//| - -mp_obj_t sdcardio_sdcard_readblocks(mp_obj_t self_in, mp_obj_t start_block_in, mp_obj_t buf_in) { - uint32_t start_block = mp_obj_get_int(start_block_in); - mp_buffer_info_t bufinfo; - mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_WRITE); - sdcardio_sdcard_obj_t *self = (sdcardio_sdcard_obj_t*)self_in; - int result = common_hal_sdcardio_sdcard_readblocks(self, start_block, &bufinfo); - if (result < 0) { - mp_raise_OSError(-result); - } - return mp_const_none; -} - -MP_DEFINE_CONST_FUN_OBJ_3(sdcardio_sdcard_readblocks_obj, sdcardio_sdcard_readblocks); - -//| def writeblocks(self, start_block: int, buf: ReadableBuffer) -> None: -//| -//| """Write one or more blocks to the card -//| -//| :param int start_block: The block to start writing from -//| :param ~_typing.ReadableBuffer buf: The buffer to read from. Length must be multiple of 512. -//| -//| :return: None""" -//| - -mp_obj_t sdcardio_sdcard_writeblocks(mp_obj_t self_in, mp_obj_t start_block_in, mp_obj_t buf_in) { - uint32_t start_block = mp_obj_get_int(start_block_in); - mp_buffer_info_t bufinfo; - mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ); - sdcardio_sdcard_obj_t *self = (sdcardio_sdcard_obj_t*)self_in; - int result = common_hal_sdcardio_sdcard_writeblocks(self, start_block, &bufinfo); - if (result < 0) { - mp_raise_OSError(-result); - } - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_3(sdcardio_sdcard_writeblocks_obj, sdcardio_sdcard_writeblocks); - -STATIC const mp_rom_map_elem_t sdcardio_sdcard_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_count), MP_ROM_PTR(&sdcardio_sdcard_count_obj) }, - { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&sdcardio_sdcard_deinit_obj) }, - { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&sdcardio_sdcard_readblocks_obj) }, - { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&sdcardio_sdcard_writeblocks_obj) }, -}; -STATIC MP_DEFINE_CONST_DICT(sdcardio_sdcard_locals_dict, sdcardio_sdcard_locals_dict_table); - -const mp_obj_type_t sdcardio_SDCard_type = { - { &mp_type_type }, - .name = MP_QSTR_SDCard, - .make_new = sdcardio_sdcard_make_new, - .locals_dict = (mp_obj_dict_t*)&sdcardio_sdcard_locals_dict, -}; diff --git a/shared-bindings/sdcardio/SDCard 2.h b/shared-bindings/sdcardio/SDCard 2.h deleted file mode 100644 index 5986d5b814..0000000000 --- a/shared-bindings/sdcardio/SDCard 2.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017, 2018 Scott Shawcroft for Adafruit Industries - * Copyright (c) 2020 Jeff Epler 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. - */ - -#pragma once - -extern const mp_obj_type_t sdcardio_SDCard_type; diff --git a/shared-bindings/sdcardio/__init__ 2.c b/shared-bindings/sdcardio/__init__ 2.c deleted file mode 100644 index 746aa5588e..0000000000 --- a/shared-bindings/sdcardio/__init__ 2.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2020 Jeff Epler 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/obj.h" -#include "py/runtime.h" - -#include "shared-bindings/sdcardio/SDCard.h" - -//| """Interface to an SD card via the SPI bus""" - -STATIC const mp_rom_map_elem_t sdcardio_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sdcardio) }, - { MP_ROM_QSTR(MP_QSTR_SDCard), MP_ROM_PTR(&sdcardio_SDCard_type) }, -}; - -STATIC MP_DEFINE_CONST_DICT(sdcardio_module_globals, sdcardio_module_globals_table); - -const mp_obj_module_t sdcardio_module = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t*)&sdcardio_module_globals, -}; diff --git a/shared-bindings/sdcardio/__init__ 2.h b/shared-bindings/sdcardio/__init__ 2.h deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/shared-module/sdcardio/SDCard 2.c b/shared-module/sdcardio/SDCard 2.c deleted file mode 100644 index 9e861279d3..0000000000 --- a/shared-module/sdcardio/SDCard 2.c +++ /dev/null @@ -1,466 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2020 Jeff Epler 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. - */ - -// This implementation largely follows the structure of adafruit_sdcard.py - -#include "shared-bindings/busio/SPI.h" -#include "shared-bindings/digitalio/DigitalInOut.h" -#include "shared-bindings/time/__init__.h" -#include "shared-bindings/util.h" -#include "shared-module/sdcardio/SDCard.h" - -#include "py/mperrno.h" - -#if 0 -#define DEBUG_PRINT(...) ((void)mp_printf(&mp_plat_print, ## __VA_ARGS__)) -#else -#define DEBUG_PRINT(...) ((void)0) -#endif - -#define CMD_TIMEOUT (200) - -#define R1_IDLE_STATE (1<<0) -#define R1_ILLEGAL_COMMAND (1<<2) - -#define TOKEN_CMD25 (0xFC) -#define TOKEN_STOP_TRAN (0xFD) -#define TOKEN_DATA (0xFE) - -STATIC bool lock_and_configure_bus(sdcardio_sdcard_obj_t *self) { - if (!common_hal_busio_spi_try_lock(self->bus)) { - return false; - } - common_hal_busio_spi_configure(self->bus, self->baudrate, 0, 0, 8); - common_hal_digitalio_digitalinout_set_value(&self->cs, false); - return true; -} - -STATIC void lock_bus_or_throw(sdcardio_sdcard_obj_t *self) { - if (!lock_and_configure_bus(self)) { - mp_raise_OSError(EAGAIN); - } -} - -STATIC void clock_card(sdcardio_sdcard_obj_t *self, int bytes) { - uint8_t buf[] = {0xff}; - common_hal_digitalio_digitalinout_set_value(&self->cs, true); - for (int i=0; ibus, buf, 1); - } -} - -STATIC void extraclock_and_unlock_bus(sdcardio_sdcard_obj_t *self) { - clock_card(self, 1); - common_hal_busio_spi_unlock(self->bus); -} - -static uint8_t CRC7(const uint8_t* data, uint8_t n) { - uint8_t crc = 0; - for (uint8_t i = 0; i < n; i++) { - uint8_t d = data[i]; - for (uint8_t j = 0; j < 8; j++) { - crc <<= 1; - if ((d & 0x80) ^ (crc & 0x80)) { - crc ^= 0x09; - } - d <<= 1; - } - } - return (crc << 1) | 1; -} - -#define READY_TIMEOUT_NS (300 * 1000 * 1000) // 300ms -STATIC void wait_for_ready(sdcardio_sdcard_obj_t *self) { - uint64_t deadline = common_hal_time_monotonic_ns() + READY_TIMEOUT_NS; - while (common_hal_time_monotonic_ns() < deadline) { - uint8_t b; - common_hal_busio_spi_read(self->bus, &b, 1, 0xff); - if (b == 0xff) { - break; - } - } -} - -// In Python API, defaults are response=None, data_block=True, wait=True -STATIC int cmd(sdcardio_sdcard_obj_t *self, int cmd, int arg, void *response_buf, size_t response_len, bool data_block, bool wait) { - DEBUG_PRINT("cmd % 3d [%02x] arg=% 11d [%08x] len=%d%s%s\n", cmd, cmd, arg, arg, response_len, data_block ? " data" : "", wait ? " wait" : ""); - uint8_t cmdbuf[6]; - cmdbuf[0] = cmd | 0x40; - cmdbuf[1] = (arg >> 24) & 0xff; - cmdbuf[2] = (arg >> 16) & 0xff; - cmdbuf[3] = (arg >> 8) & 0xff; - cmdbuf[4] = arg & 0xff; - cmdbuf[5] = CRC7(cmdbuf, 5); - - if (wait) { - wait_for_ready(self); - } - - common_hal_busio_spi_write(self->bus, cmdbuf, sizeof(cmdbuf)); - - // Wait for the response (response[7] == 0) - bool response_received = false; - for (int i=0; ibus, cmdbuf, 1, 0xff); - if ((cmdbuf[0] & 0x80) == 0) { - response_received = true; - break; - } - } - - if (!response_received) { - return -EIO; - } - - if (response_buf) { - - if (data_block) { - cmdbuf[1] = 0xff; - do { - // Wait for the start block byte - common_hal_busio_spi_read(self->bus, cmdbuf+1, 1, 0xff); - } while (cmdbuf[1] != 0xfe); - } - - common_hal_busio_spi_read(self->bus, response_buf, response_len, 0xff); - - if (data_block) { - // Read and discard the CRC-CCITT checksum - common_hal_busio_spi_read(self->bus, cmdbuf+1, 2, 0xff); - } - - } - - return cmdbuf[0]; -} - -STATIC int block_cmd(sdcardio_sdcard_obj_t *self, int cmd_, int block, void *response_buf, size_t response_len, bool data_block, bool wait) { - return cmd(self, cmd_, block * self->cdv, response_buf, response_len, true, true); -} - -STATIC bool cmd_nodata(sdcardio_sdcard_obj_t* self, int cmd, int response) { - uint8_t cmdbuf[2] = {cmd, 0xff}; - - common_hal_busio_spi_write(self->bus, cmdbuf, sizeof(cmdbuf)); - - // Wait for the response (response[7] == response) - for (int i=0; ibus, cmdbuf, 1, 0xff); - if (cmdbuf[0] == response) { - return 0; - } - } - return -EIO; -} - -STATIC const compressed_string_t *init_card_v1(sdcardio_sdcard_obj_t *self) { - for (int i=0; icdv = 1; - } - return NULL; - } - } - return translate("timeout waiting for v2 card"); -} - -STATIC const compressed_string_t *init_card(sdcardio_sdcard_obj_t *self) { - clock_card(self, 10); - - common_hal_digitalio_digitalinout_set_value(&self->cs, false); - - // CMD0: init card: should return _R1_IDLE_STATE (allow 5 attempts) - { - bool reached_idle_state = false; - for (int i=0; i<5; i++) { - if (cmd(self, 0, 0, NULL, 0, true, true) == R1_IDLE_STATE) { - reached_idle_state = true; - break; - } - } - if (!reached_idle_state) { - return translate("no SD card"); - } - } - - // CMD8: determine card version - { - uint8_t rb7[4]; - int response = cmd(self, 8, 0x1AA, rb7, sizeof(rb7), false, true); - if (response == R1_IDLE_STATE) { - const compressed_string_t *result =init_card_v2(self); - if (result != NULL) { - return result; - } - } else if (response == (R1_IDLE_STATE | R1_ILLEGAL_COMMAND)) { - const compressed_string_t *result =init_card_v1(self); - if (result != NULL) { - return result; - } - } else { - return translate("couldn't determine SD card version"); - } - } - - // CMD9: get number of sectors - { - uint8_t csd[16]; - int response = cmd(self, 9, 0, csd, sizeof(csd), true, true); - if (response != 0) { - return translate("no response from SD card"); - } - int csd_version = (csd[0] & 0xC0) >> 6; - if (csd_version >= 2) { - return translate("SD card CSD format not supported"); - } - - if (csd_version == 1) { - self->sectors = ((csd[8] << 8 | csd[9]) + 1) * 1024; - } else { - uint32_t block_length = 1 << (csd[5] & 0xF); - uint32_t c_size = ((csd[6] & 0x3) << 10) | (csd[7] << 2) | ((csd[8] & 0xC) >> 6); - uint32_t mult = 1 << (((csd[9] & 0x3) << 1 | (csd[10] & 0x80) >> 7) + 2); - self->sectors = block_length / 512 * mult * (c_size + 1); - } - } - - // CMD16: set block length to 512 bytes - { - int response = cmd(self, 16, 512, NULL, 0, true, true); - if (response != 0) { - return translate("can't set 512 block size"); - } - } - - return NULL; -} - -void common_hal_sdcardio_sdcard_construct(sdcardio_sdcard_obj_t *self, busio_spi_obj_t *bus, mcu_pin_obj_t *cs, int baudrate) { - self->bus = bus; - common_hal_digitalio_digitalinout_construct(&self->cs, cs); - common_hal_digitalio_digitalinout_switch_to_output(&self->cs, true, DRIVE_MODE_PUSH_PULL); - - self->cdv = 512; - self->sectors = 0; - self->baudrate = 250000; - - lock_bus_or_throw(self); - const compressed_string_t *result = init_card(self); - extraclock_and_unlock_bus(self); - - if (result != NULL) { - common_hal_digitalio_digitalinout_deinit(&self->cs); - mp_raise_OSError_msg(result); - } - - self->baudrate = baudrate; -} - -void common_hal_sdcardio_sdcard_deinit(sdcardio_sdcard_obj_t *self) { - if (!self->bus) { - return; - } - self->bus = 0; - common_hal_digitalio_digitalinout_deinit(&self->cs); -} - -void common_hal_sdcardio_check_for_deinit(sdcardio_sdcard_obj_t *self) { - if (!self->bus) { - raise_deinited_error(); - } -} - -int common_hal_sdcardio_sdcard_get_blockcount(sdcardio_sdcard_obj_t *self) { - common_hal_sdcardio_check_for_deinit(self); - return self->sectors; -} - -int readinto(sdcardio_sdcard_obj_t *self, void *buf, size_t size) { - uint8_t aux[2] = {0, 0}; - while (aux[0] != 0xfe) { - common_hal_busio_spi_read(self->bus, aux, 1, 0xff); - } - - common_hal_busio_spi_read(self->bus, buf, size, 0xff); - - // Read checksum and throw it away - common_hal_busio_spi_read(self->bus, aux, sizeof(aux), 0xff); - return 0; -} - -int readblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf) { - uint32_t nblocks = buf->len / 512; - if (nblocks == 1) { - // Use CMD17 to read a single block - return block_cmd(self, 17, start_block, buf->buf, buf->len, true, true); - } else { - // Use CMD18 to read multiple blocks - int r = block_cmd(self, 18, start_block, NULL, 0, true, true); - if (r < 0) { - return r; - } - - uint8_t *ptr = buf->buf; - while (nblocks--) { - r = readinto(self, ptr, 512); - if (r < 0) { - return r; - } - ptr += 512; - } - - // End the multi-block read - r = cmd(self, 12, 0, NULL, 0, true, false); - - // Return first status 0 or last before card ready (0xff) - while (r != 0) { - uint8_t single_byte; - common_hal_busio_spi_read(self->bus, &single_byte, 1, 0xff); - if (single_byte & 0x80) { - return r; - } - r = single_byte; - } - } - return 0; -} - -int common_hal_sdcardio_sdcard_readblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf) { - common_hal_sdcardio_check_for_deinit(self); - if (buf->len % 512 != 0) { - mp_raise_ValueError(translate("Buffer length must be a multiple of 512")); - } - - lock_and_configure_bus(self); - int r = readblocks(self, start_block, buf); - extraclock_and_unlock_bus(self); - return r; -} - -int _write(sdcardio_sdcard_obj_t *self, uint8_t token, void *buf, size_t size) { - wait_for_ready(self); - - uint8_t cmd[2]; - cmd[0] = token; - - common_hal_busio_spi_write(self->bus, cmd, 1); - common_hal_busio_spi_write(self->bus, buf, size); - - cmd[0] = cmd[1] = 0xff; - common_hal_busio_spi_write(self->bus, cmd, 2); - - // Check the response - // This differs from the traditional adafruit_sdcard handling, - // but adafruit_sdcard also ignored the return value of SDCard._write(!) - // so nobody noticed - // - // - // Response is as follows: - // x x x 0 STAT 1 - // 7 6 5 4 3..1 0 - // with STATUS 010 indicating "data accepted", and other status bit - // combinations indicating failure. - // In practice, I was seeing cmd[0] as 0xe5, indicating success - for (int i=0; ibus, cmd, 1, 0xff); - DEBUG_PRINT("i=%02d cmd[0] = 0x%02x\n", i, cmd[0]); - if ((cmd[0] & 0b00010001) == 0b00000001) { - if ((cmd[0] & 0x1f) != 0x5) { - return -EIO; - } else { - break; - } - } - } - - // Wait for the write to finish - do { - common_hal_busio_spi_read(self->bus, cmd, 1, 0xff); - } while (cmd[0] == 0); - - // Success - return 0; -} - -int writeblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf) { - common_hal_sdcardio_check_for_deinit(self); - uint32_t nblocks = buf->len / 512; - if (nblocks == 1) { - // Use CMD24 to write a single block - int r = block_cmd(self, 24, start_block, NULL, 0, true, true); - if (r < 0) { - return r; - } - r = _write(self, TOKEN_DATA, buf->buf, buf->len); - if (r < 0) { - return r; - } - } else { - // Use CMD25 to write multiple block - int r = block_cmd(self, 25, start_block, NULL, 0, true, true); - if (r < 0) { - return r; - } - - uint8_t *ptr = buf->buf; - while (nblocks--) { - r = _write(self, TOKEN_CMD25, ptr, 512); - if (r < 0) { - return r; - } - ptr += 512; - } - - cmd_nodata(self, TOKEN_STOP_TRAN, 0); - } - return 0; -} - -int common_hal_sdcardio_sdcard_writeblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf) { - common_hal_sdcardio_check_for_deinit(self); - if (buf->len % 512 != 0) { - mp_raise_ValueError(translate("Buffer length must be a multiple of 512")); - } - lock_and_configure_bus(self); - int r = writeblocks(self, start_block, buf); - extraclock_and_unlock_bus(self); - return r; -} diff --git a/shared-module/sdcardio/SDCard 2.h b/shared-module/sdcardio/SDCard 2.h deleted file mode 100644 index 76c906029f..0000000000 --- a/shared-module/sdcardio/SDCard 2.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2020 Jeff Epler 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. - */ - -#pragma once - -#include "py/obj.h" -#include "py/objproperty.h" -#include "py/runtime.h" -#include "py/objarray.h" - -#include "common-hal/busio/SPI.h" -#include "common-hal/digitalio/DigitalInOut.h" - -typedef struct { - mp_obj_base_t base; - busio_spi_obj_t *bus; - digitalio_digitalinout_obj_t cs; - int cdv; - int baudrate; - uint32_t sectors; -} sdcardio_sdcard_obj_t; - -void common_hal_sdcardio_sdcard_construct(sdcardio_sdcard_obj_t *self, busio_spi_obj_t *spi, mcu_pin_obj_t *cs, int baudrate); -void common_hal_sdcardio_sdcard_deinit(sdcardio_sdcard_obj_t *self); -void common_hal_sdcardio_sdcard_check_for_deinit(sdcardio_sdcard_obj_t *self); -int common_hal_sdcardio_sdcard_get_blockcount(sdcardio_sdcard_obj_t *self); -int common_hal_sdcardio_sdcard_readblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf); -int common_hal_sdcardio_sdcard_writeblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf); diff --git a/shared-module/sdcardio/__init__ 2.c b/shared-module/sdcardio/__init__ 2.c deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/shared-module/sdcardio/__init__ 2.h b/shared-module/sdcardio/__init__ 2.h deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/supervisor/background_callback 2.h b/supervisor/background_callback 2.h deleted file mode 100644 index 535dd656be..0000000000 --- a/supervisor/background_callback 2.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2020 Jeff Epler 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 CIRCUITPY_INCLUDED_SUPERVISOR_BACKGROUND_CALLBACK_H -#define CIRCUITPY_INCLUDED_SUPERVISOR_BACKGROUND_CALLBACK_H - -/** Background callbacks are a linked list of tasks to call in the background. - * - * Include a member of type `background_callback_t` inside an object - * which needs to queue up background work, and zero-initialize it. - * - * To schedule the work, use background_callback_add, with fun as the - * function to call and data pointing to the object itself. - * - * Next time run_background_tasks_if_tick is called, the callback will - * be run and removed from the linked list. - * - * Queueing a task that is already queued does nothing. Unconditionally - * re-queueing it from its own background task will cause it to run during the - * very next background-tasks invocation, leading to a CircuitPython freeze, so - * don't do that. - * - * background_callback_add can be called from interrupt context. - */ -typedef void (*background_callback_fun)(void *data); -typedef struct background_callback { - background_callback_fun fun; - void *data; - struct background_callback *next; - struct background_callback *prev; -} background_callback_t; - -/* Add a background callback for which 'fun' and 'data' were previously set */ -void background_callback_add_core(background_callback_t *cb); - -/* Add a background callback to the given function with the given data. When - * the callback involves an object on the GC heap, the 'data' must be a pointer - * to that object itself, not an internal pointer. Otherwise, it can be the - * case that no other references to the object itself survive, and the object - * becomes garbage collected while an outstanding background callback still - * exists. - */ -void background_callback_add(background_callback_t *cb, background_callback_fun fun, void *data); - -/* Run all background callbacks. Normally, this is done by the supervisor - * whenever the list is non-empty */ -void background_callback_run_all(void); - -/* During soft reset, remove all pending callbacks and clear the critical section flag */ -void background_callback_reset(void); - -/* Sometimes background callbacks must be blocked. Use these functions to - * bracket the section of code where this is the case. These calls nest, and - * begins must be balanced with ends. - */ -void background_callback_begin_critical_section(void); -void background_callback_end_critical_section(void); - -/* - * Background callbacks may stop objects from being collected - */ -void background_callback_gc_collect(void); - -#endif diff --git a/supervisor/shared/background_callback 2.c b/supervisor/shared/background_callback 2.c deleted file mode 100644 index 8e12dd3625..0000000000 --- a/supervisor/shared/background_callback 2.c +++ /dev/null @@ -1,138 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2020 Jeff Epler 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/gc.h" -#include "py/mpconfig.h" -#include "supervisor/background_callback.h" -#include "supervisor/shared/tick.h" -#include "shared-bindings/microcontroller/__init__.h" - -STATIC volatile background_callback_t *callback_head, *callback_tail; - -#define CALLBACK_CRITICAL_BEGIN (common_hal_mcu_disable_interrupts()) -#define CALLBACK_CRITICAL_END (common_hal_mcu_enable_interrupts()) - -void background_callback_add_core(background_callback_t *cb) { - CALLBACK_CRITICAL_BEGIN; - if (cb->prev || callback_head == cb) { - CALLBACK_CRITICAL_END; - return; - } - cb->next = 0; - cb->prev = (background_callback_t*)callback_tail; - if (callback_tail) { - callback_tail->next = cb; - cb->prev = (background_callback_t*)callback_tail; - } - if (!callback_head) { - callback_head = cb; - } - callback_tail = cb; - CALLBACK_CRITICAL_END; -} - -void background_callback_add(background_callback_t *cb, background_callback_fun fun, void *data) { - cb->fun = fun; - cb->data = data; - background_callback_add_core(cb); -} - -static bool in_background_callback; -void background_callback_run_all() { - if (!callback_head) { - return; - } - CALLBACK_CRITICAL_BEGIN; - if (in_background_callback) { - CALLBACK_CRITICAL_END; - return; - } - in_background_callback = true; - background_callback_t *cb = (background_callback_t*)callback_head; - callback_head = NULL; - callback_tail = NULL; - while (cb) { - background_callback_t *next = cb->next; - cb->next = cb->prev = NULL; - background_callback_fun fun = cb->fun; - void *data = cb->data; - CALLBACK_CRITICAL_END; - // Leave the critical section in order to run the callback function - if (fun) { - fun(data); - } - CALLBACK_CRITICAL_BEGIN; - cb = next; - } - in_background_callback = false; - CALLBACK_CRITICAL_END; -} - -void background_callback_begin_critical_section() { - CALLBACK_CRITICAL_BEGIN; -} - -void background_callback_end_critical_section() { - CALLBACK_CRITICAL_END; -} - -void background_callback_reset() { - CALLBACK_CRITICAL_BEGIN; - background_callback_t *cb = (background_callback_t*)callback_head; - while(cb) { - background_callback_t *next = cb->next; - memset(cb, 0, sizeof(*cb)); - cb = next; - } - callback_head = NULL; - callback_tail = NULL; - in_background_callback = false; - CALLBACK_CRITICAL_END; -} - -void background_callback_gc_collect(void) { - // We don't enter the callback critical section here. We rely on - // gc_collect_ptr _NOT_ entering background callbacks, so it is not - // possible for the list to be cleared. - // - // However, it is possible for the list to be extended. We make the - // minor assumption that no newly added callback is for a - // collectable object. That is, we only plug the hole where an - // object becomes collectable AFTER it is added but before the - // callback is run, not the hole where an object was ALREADY - // collectable but adds a background task for itself. - // - // It's necessary to traverse the whole list here, as the callbacks - // themselves can be in non-gc memory, and some of the cb->data - // objects themselves might be in non-gc memory. - background_callback_t *cb = (background_callback_t*)callback_head; - while(cb) { - gc_collect_ptr(cb->data); - cb = cb->next; - } -} From 983e1af33d0440329aa4f34109994f8597f0737a Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Fri, 21 Aug 2020 19:10:13 -0500 Subject: [PATCH 34/79] remove other extraneous files --- shared-bindings/sdioio/SDCard 2.c | 296 ------------------ shared-bindings/sdioio/SDCard 2.h | 66 ---- shared-bindings/sdioio/__init__ 2.c | 47 --- shared-bindings/sdioio/__init__ 2.h | 0 .../memorymonitor/AllocationAlarm 2.c | 94 ------ .../memorymonitor/AllocationAlarm 2.h | 51 --- .../memorymonitor/AllocationSize 2.c | 91 ------ .../memorymonitor/AllocationSize 2.h | 51 --- shared-module/memorymonitor/__init__ 2.c | 39 --- shared-module/memorymonitor/__init__ 2.h | 35 --- 10 files changed, 770 deletions(-) delete mode 100644 shared-bindings/sdioio/SDCard 2.c delete mode 100644 shared-bindings/sdioio/SDCard 2.h delete mode 100644 shared-bindings/sdioio/__init__ 2.c delete mode 100644 shared-bindings/sdioio/__init__ 2.h delete mode 100644 shared-module/memorymonitor/AllocationAlarm 2.c delete mode 100644 shared-module/memorymonitor/AllocationAlarm 2.h delete mode 100644 shared-module/memorymonitor/AllocationSize 2.c delete mode 100644 shared-module/memorymonitor/AllocationSize 2.h delete mode 100644 shared-module/memorymonitor/__init__ 2.c delete mode 100644 shared-module/memorymonitor/__init__ 2.h diff --git a/shared-bindings/sdioio/SDCard 2.c b/shared-bindings/sdioio/SDCard 2.c deleted file mode 100644 index aba414cd63..0000000000 --- a/shared-bindings/sdioio/SDCard 2.c +++ /dev/null @@ -1,296 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2016 Scott Shawcroft - * - * 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. - */ - -// This file contains all of the Python API definitions for the -// sdioio.SDCard class. - -#include - -#include "shared-bindings/microcontroller/Pin.h" -#include "shared-bindings/sdioio/SDCard.h" -#include "shared-bindings/util.h" - -#include "lib/utils/buffer_helper.h" -#include "lib/utils/context_manager_helpers.h" -#include "py/mperrno.h" -#include "py/objproperty.h" -#include "py/runtime.h" -#include "supervisor/shared/translate.h" - -//| class SDCard: -//| """SD Card Block Interface with SDIO -//| -//| Controls an SD card over SDIO. SDIO is a parallel protocol designed -//| for SD cards. It uses a clock pin, a command pin, and 1 or 4 -//| data pins. It can be operated at a high frequency such as -//| 25MHz. Usually an SDCard object is used with ``storage.VfsFat`` -//| to allow file I/O to an SD card.""" -//| -//| def __init__(self, clock: microcontroller.Pin, command: microcontroller.Pin, data: Sequence[microcontroller.Pin], frequency: int) -> None: -//| """Construct an SDIO SD Card object with the given properties -//| -//| :param ~microcontroller.Pin clock: the pin to use for the clock. -//| :param ~microcontroller.Pin command: the pin to use for the command. -//| :param data: A sequence of pins to use for data. -//| :param frequency: The frequency of the bus in Hz -//| -//| Example usage: -//| -//| .. code-block:: python -//| -//| import os -//| -//| import board -//| import sdioio -//| import storage -//| -//| sd = sdioio.SDCard( -//| clock=board.SDIO_CLOCK, -//| command=board.SDIO_COMMAND, -//| data=board.SDIO_DATA, -//| frequency=25000000) -//| vfs = storage.VfsFat(sd) -//| storage.mount(vfs, '/sd') -//| os.listdir('/sd')""" -//| ... -//| - -STATIC mp_obj_t sdioio_sdcard_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - sdioio_sdcard_obj_t *self = m_new_obj(sdioio_sdcard_obj_t); - self->base.type = &sdioio_SDCard_type; - enum { ARG_clock, ARG_command, ARG_data, ARG_frequency, NUM_ARGS }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_clock, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_OBJ }, - { MP_QSTR_command, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_OBJ }, - { MP_QSTR_data, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_OBJ }, - { MP_QSTR_frequency, MP_ARG_REQUIRED | MP_ARG_KW_ONLY | MP_ARG_INT }, - }; - MP_STATIC_ASSERT( MP_ARRAY_SIZE(allowed_args) == NUM_ARGS ); - 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); - - const mcu_pin_obj_t* clock = validate_obj_is_free_pin(args[ARG_clock].u_obj); - const mcu_pin_obj_t* command = validate_obj_is_free_pin(args[ARG_command].u_obj); - mcu_pin_obj_t *data_pins[4]; - uint8_t num_data; - validate_list_is_free_pins(MP_QSTR_data, data_pins, MP_ARRAY_SIZE(data_pins), args[ARG_data].u_obj, &num_data); - - common_hal_sdioio_sdcard_construct(self, clock, command, num_data, data_pins, args[ARG_frequency].u_int); - return MP_OBJ_FROM_PTR(self); -} - -STATIC void check_for_deinit(sdioio_sdcard_obj_t *self) { - if (common_hal_sdioio_sdcard_deinited(self)) { - raise_deinited_error(); - } -} - -//| def configure(self, frequency: int = 0, width: int = 0) -> None: -//| """Configures the SDIO bus. -//| -//| :param int frequency: the desired clock rate in Hertz. The actual clock rate may be higher or lower due to the granularity of available clock settings. Check the `frequency` attribute for the actual clock rate. -//| :param int width: the number of data lines to use. Must be 1 or 4 and must also not exceed the number of data lines at construction -//| -//| .. note:: Leaving a value unspecified or 0 means the current setting is kept""" -//| -STATIC mp_obj_t sdioio_sdcard_configure(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_frequency, ARG_width, NUM_ARGS }; - static const mp_arg_t allowed_args[] = { - { MP_QSTR_frequency, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, - { MP_QSTR_width, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, - }; - sdioio_sdcard_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); - check_for_deinit(self); - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - MP_STATIC_ASSERT( MP_ARRAY_SIZE(allowed_args) == NUM_ARGS ); - mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - mp_int_t frequency = args[ARG_frequency].u_int; - if (frequency < 0) { - mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_baudrate); - } - - uint8_t width = args[ARG_width].u_int; - if (width != 0 && width != 1 && width != 4) { - mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_width); - } - - if (!common_hal_sdioio_sdcard_configure(self, frequency, width)) { - mp_raise_OSError(MP_EIO); - } - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_KW(sdioio_sdcard_configure_obj, 1, sdioio_sdcard_configure); - -//| def count(self) -> int: -//| """Returns the total number of sectors -//| -//| Due to technical limitations, this is a function and not a property. -//| -//| :return: The number of 512-byte blocks, as a number""" -//| -STATIC mp_obj_t sdioio_sdcard_count(mp_obj_t self_in) { - sdioio_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - return MP_OBJ_NEW_SMALL_INT(common_hal_sdioio_sdcard_get_count(self)); -} -MP_DEFINE_CONST_FUN_OBJ_1(sdioio_sdcard_count_obj, sdioio_sdcard_count); - -//| def readblocks(self, start_block: int, buf: WriteableBuffer) -> None: -//| -//| """Read one or more blocks from the card -//| -//| :param int start_block: The block to start reading from -//| :param ~_typing.WriteableBuffer buf: The buffer to write into. Length must be multiple of 512. -//| -//| :return: None""" -mp_obj_t sdioio_sdcard_readblocks(mp_obj_t self_in, mp_obj_t start_block_in, mp_obj_t buf_in) { - uint32_t start_block = mp_obj_get_int(start_block_in); - mp_buffer_info_t bufinfo; - mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_WRITE); - sdioio_sdcard_obj_t *self = (sdioio_sdcard_obj_t*)self_in; - int result = common_hal_sdioio_sdcard_readblocks(self, start_block, &bufinfo); - if (result < 0) { - mp_raise_OSError(-result); - } - return mp_const_none; -} - -MP_DEFINE_CONST_FUN_OBJ_3(sdioio_sdcard_readblocks_obj, sdioio_sdcard_readblocks); - -//| def writeblocks(self, start_block: int, buf: ReadableBuffer) -> None: -//| -//| """Write one or more blocks to the card -//| -//| :param int start_block: The block to start writing from -//| :param ~_typing.ReadableBuffer buf: The buffer to read from. Length must be multiple of 512. -//| -//| :return: None""" -//| -mp_obj_t sdioio_sdcard_writeblocks(mp_obj_t self_in, mp_obj_t start_block_in, mp_obj_t buf_in) { - uint32_t start_block = mp_obj_get_int(start_block_in); - mp_buffer_info_t bufinfo; - mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ); - sdioio_sdcard_obj_t *self = (sdioio_sdcard_obj_t*)self_in; - int result = common_hal_sdioio_sdcard_writeblocks(self, start_block, &bufinfo); - if (result < 0) { - mp_raise_OSError(-result); - } - return mp_const_none; -} - -MP_DEFINE_CONST_FUN_OBJ_3(sdioio_sdcard_writeblocks_obj, sdioio_sdcard_writeblocks); - -//| @property -//| def frequency(self) -> int: -//| """The actual SDIO bus frequency. This may not match the frequency -//| requested due to internal limitations.""" -//| ... -//| -STATIC mp_obj_t sdioio_sdcard_obj_get_frequency(mp_obj_t self_in) { - sdioio_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - return MP_OBJ_NEW_SMALL_INT(common_hal_sdioio_sdcard_get_frequency(self)); -} -MP_DEFINE_CONST_FUN_OBJ_1(sdioio_sdcard_get_frequency_obj, sdioio_sdcard_obj_get_frequency); - -const mp_obj_property_t sdioio_sdcard_frequency_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&sdioio_sdcard_get_frequency_obj, - (mp_obj_t)&mp_const_none_obj, - (mp_obj_t)&mp_const_none_obj}, -}; - -//| @property -//| def width(self) -> int: -//| """The actual SDIO bus width, in bits""" -//| ... -//| -STATIC mp_obj_t sdioio_sdcard_obj_get_width(mp_obj_t self_in) { - sdioio_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); - check_for_deinit(self); - return MP_OBJ_NEW_SMALL_INT(common_hal_sdioio_sdcard_get_width(self)); -} -MP_DEFINE_CONST_FUN_OBJ_1(sdioio_sdcard_get_width_obj, sdioio_sdcard_obj_get_width); - -const mp_obj_property_t sdioio_sdcard_width_obj = { - .base.type = &mp_type_property, - .proxy = {(mp_obj_t)&sdioio_sdcard_get_width_obj, - (mp_obj_t)&mp_const_none_obj, - (mp_obj_t)&mp_const_none_obj}, -}; - -//| def deinit(self) -> None: -//| """Disable permanently. -//| -//| :return: None""" -STATIC mp_obj_t sdioio_sdcard_obj_deinit(mp_obj_t self_in) { - sdioio_sdcard_obj_t *self = MP_OBJ_TO_PTR(self_in); - common_hal_sdioio_sdcard_deinit(self); - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_1(sdioio_sdcard_deinit_obj, sdioio_sdcard_obj_deinit); - -//| def __enter__(self) -> SDCard: -//| """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 sdioio_sdcard_obj___exit__(size_t n_args, const mp_obj_t *args) { - (void)n_args; - common_hal_sdioio_sdcard_deinit(args[0]); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(sdioio_sdcard_obj___exit___obj, 4, 4, sdioio_sdcard_obj___exit__); - -STATIC const mp_rom_map_elem_t sdioio_sdcard_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&sdioio_sdcard_deinit_obj) }, - { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, - { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&sdioio_sdcard_obj___exit___obj) }, - - { MP_ROM_QSTR(MP_QSTR_configure), MP_ROM_PTR(&sdioio_sdcard_configure_obj) }, - { MP_ROM_QSTR(MP_QSTR_frequency), MP_ROM_PTR(&sdioio_sdcard_frequency_obj) }, - { MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&sdioio_sdcard_width_obj) }, - - { MP_ROM_QSTR(MP_QSTR_count), MP_ROM_PTR(&sdioio_sdcard_count_obj) }, - { MP_ROM_QSTR(MP_QSTR_readblocks), MP_ROM_PTR(&sdioio_sdcard_readblocks_obj) }, - { MP_ROM_QSTR(MP_QSTR_writeblocks), MP_ROM_PTR(&sdioio_sdcard_writeblocks_obj) }, -}; -STATIC MP_DEFINE_CONST_DICT(sdioio_sdcard_locals_dict, sdioio_sdcard_locals_dict_table); - -const mp_obj_type_t sdioio_SDCard_type = { - { &mp_type_type }, - .name = MP_QSTR_SDCard, - .make_new = sdioio_sdcard_make_new, - .locals_dict = (mp_obj_dict_t*)&sdioio_sdcard_locals_dict, -}; diff --git a/shared-bindings/sdioio/SDCard 2.h b/shared-bindings/sdioio/SDCard 2.h deleted file mode 100644 index 7f62ee7a65..0000000000 --- a/shared-bindings/sdioio/SDCard 2.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2016 Scott Shawcroft - * - * 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_BUSIO_SDIO_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_SDIO_H - -#include "py/obj.h" - -#include "common-hal/microcontroller/Pin.h" -#include "common-hal/sdioio/SDCard.h" - -// Type object used in Python. Should be shared between ports. -extern const mp_obj_type_t sdioio_SDCard_type; - -// Construct an underlying SDIO object. -extern 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); - -extern void common_hal_sdioio_sdcard_deinit(sdioio_sdcard_obj_t *self); -extern bool common_hal_sdioio_sdcard_deinited(sdioio_sdcard_obj_t *self); - -extern bool common_hal_sdioio_sdcard_configure(sdioio_sdcard_obj_t *self, uint32_t baudrate, uint8_t width); - -extern void common_hal_sdioio_sdcard_unlock(sdioio_sdcard_obj_t *self); - -// Return actual SDIO bus frequency. -uint32_t common_hal_sdioio_sdcard_get_frequency(sdioio_sdcard_obj_t* self); - -// Return SDIO bus width. -uint8_t common_hal_sdioio_sdcard_get_width(sdioio_sdcard_obj_t* self); - -// Return number of device blocks -uint32_t common_hal_sdioio_sdcard_get_count(sdioio_sdcard_obj_t* self); - -// Read or write blocks -int common_hal_sdioio_sdcard_readblocks(sdioio_sdcard_obj_t* self, uint32_t start_block, mp_buffer_info_t *bufinfo); -int common_hal_sdioio_sdcard_writeblocks(sdioio_sdcard_obj_t* self, uint32_t start_block, mp_buffer_info_t *bufinfo); - -// This is used by the supervisor to claim SDIO devices indefinitely. -extern void common_hal_sdioio_sdcard_never_reset(sdioio_sdcard_obj_t *self); - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BUSIO_SDIO_H diff --git a/shared-bindings/sdioio/__init__ 2.c b/shared-bindings/sdioio/__init__ 2.c deleted file mode 100644 index b88e5c3a96..0000000000 --- a/shared-bindings/sdioio/__init__ 2.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2020 Jeff Epler 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/obj.h" -#include "py/runtime.h" - -#include "shared-bindings/sdioio/SDCard.h" - -//| """Interface to an SD card via the SDIO bus""" - -STATIC const mp_rom_map_elem_t sdioio_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sdio) }, - { MP_ROM_QSTR(MP_QSTR_SDCard), MP_ROM_PTR(&sdioio_SDCard_type) }, -}; - -STATIC MP_DEFINE_CONST_DICT(sdioio_module_globals, sdioio_module_globals_table); - -const mp_obj_module_t sdioio_module = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t*)&sdioio_module_globals, -}; diff --git a/shared-bindings/sdioio/__init__ 2.h b/shared-bindings/sdioio/__init__ 2.h deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/shared-module/memorymonitor/AllocationAlarm 2.c b/shared-module/memorymonitor/AllocationAlarm 2.c deleted file mode 100644 index 35f4e4c636..0000000000 --- a/shared-module/memorymonitor/AllocationAlarm 2.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * This file is part of the Micro Python 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 "shared-bindings/memorymonitor/__init__.h" -#include "shared-bindings/memorymonitor/AllocationAlarm.h" - -#include "py/gc.h" -#include "py/mpstate.h" -#include "py/runtime.h" - -void common_hal_memorymonitor_allocationalarm_construct(memorymonitor_allocationalarm_obj_t* self, size_t minimum_block_count) { - self->minimum_block_count = minimum_block_count; - self->next = NULL; - self->previous = NULL; -} - -void common_hal_memorymonitor_allocationalarm_set_ignore(memorymonitor_allocationalarm_obj_t* self, mp_int_t count) { - self->count = count; -} - -void common_hal_memorymonitor_allocationalarm_pause(memorymonitor_allocationalarm_obj_t* self) { - // Check to make sure we aren't already paused. We can be if we're exiting from an exception we - // caused. - if (self->previous == NULL) { - return; - } - *self->previous = self->next; - self->next = NULL; - self->previous = NULL; -} - -void common_hal_memorymonitor_allocationalarm_resume(memorymonitor_allocationalarm_obj_t* self) { - if (self->previous != NULL) { - mp_raise_RuntimeError(translate("Already running")); - } - self->next = MP_STATE_VM(active_allocationalarms); - self->previous = (memorymonitor_allocationalarm_obj_t**) &MP_STATE_VM(active_allocationalarms); - if (self->next != NULL) { - self->next->previous = &self->next; - } - MP_STATE_VM(active_allocationalarms) = self; -} - -void memorymonitor_allocationalarms_allocation(size_t block_count) { - memorymonitor_allocationalarm_obj_t* alarm = MP_OBJ_TO_PTR(MP_STATE_VM(active_allocationalarms)); - size_t alert_count = 0; - while (alarm != NULL) { - // Hold onto next in case we remove the alarm from the list. - memorymonitor_allocationalarm_obj_t* next = alarm->next; - if (block_count >= alarm->minimum_block_count) { - if (alarm->count > 0) { - alarm->count--; - } else { - // Uncomment the breakpoint below if you want to use a C debugger to figure out the C - // call stack for an allocation. - // asm("bkpt"); - // Pause now because we may alert when throwing the exception too. - common_hal_memorymonitor_allocationalarm_pause(alarm); - alert_count++; - } - } - alarm = next; - } - if (alert_count > 0) { - mp_raise_memorymonitor_AllocationError(translate("Attempt to allocate %d blocks"), block_count); - } -} - -void memorymonitor_allocationalarms_reset(void) { - MP_STATE_VM(active_allocationalarms) = NULL; -} diff --git a/shared-module/memorymonitor/AllocationAlarm 2.h b/shared-module/memorymonitor/AllocationAlarm 2.h deleted file mode 100644 index 172c24f6c8..0000000000 --- a/shared-module/memorymonitor/AllocationAlarm 2.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of the Micro Python 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. - */ - -#ifndef MICROPY_INCLUDED_SHARED_MODULE_MEMORYMONITOR_ALLOCATIONALARM_H -#define MICROPY_INCLUDED_SHARED_MODULE_MEMORYMONITOR_ALLOCATIONALARM_H - -#include -#include - -#include "py/obj.h" - -typedef struct _memorymonitor_allocationalarm_obj_t memorymonitor_allocationalarm_obj_t; - -#define ALLOCATION_SIZE_BUCKETS 16 - -typedef struct _memorymonitor_allocationalarm_obj_t { - mp_obj_base_t base; - size_t minimum_block_count; - mp_int_t count; - // Store the location that points to us so we can remove ourselves. - memorymonitor_allocationalarm_obj_t** previous; - memorymonitor_allocationalarm_obj_t* next; -} memorymonitor_allocationalarm_obj_t; - -void memorymonitor_allocationalarms_allocation(size_t block_count); -void memorymonitor_allocationalarms_reset(void); - -#endif // MICROPY_INCLUDED_SHARED_MODULE_MEMORYMONITOR_ALLOCATIONALARM_H diff --git a/shared-module/memorymonitor/AllocationSize 2.c b/shared-module/memorymonitor/AllocationSize 2.c deleted file mode 100644 index c28e65592c..0000000000 --- a/shared-module/memorymonitor/AllocationSize 2.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * This file is part of the Micro Python 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 "shared-bindings/memorymonitor/AllocationSize.h" - -#include "py/gc.h" -#include "py/mpstate.h" -#include "py/runtime.h" - -void common_hal_memorymonitor_allocationsize_construct(memorymonitor_allocationsize_obj_t* self) { - common_hal_memorymonitor_allocationsize_clear(self); - self->next = NULL; - self->previous = NULL; -} - -void common_hal_memorymonitor_allocationsize_pause(memorymonitor_allocationsize_obj_t* self) { - *self->previous = self->next; - self->next = NULL; - self->previous = NULL; -} - -void common_hal_memorymonitor_allocationsize_resume(memorymonitor_allocationsize_obj_t* self) { - if (self->previous != NULL) { - mp_raise_RuntimeError(translate("Already running")); - } - self->next = MP_STATE_VM(active_allocationsizes); - self->previous = (memorymonitor_allocationsize_obj_t**) &MP_STATE_VM(active_allocationsizes); - if (self->next != NULL) { - self->next->previous = &self->next; - } - MP_STATE_VM(active_allocationsizes) = self; -} - -void common_hal_memorymonitor_allocationsize_clear(memorymonitor_allocationsize_obj_t* self) { - for (size_t i = 0; i < ALLOCATION_SIZE_BUCKETS; i++) { - self->buckets[i] = 0; - } -} - -uint16_t common_hal_memorymonitor_allocationsize_get_len(memorymonitor_allocationsize_obj_t* self) { - return ALLOCATION_SIZE_BUCKETS; -} - -size_t common_hal_memorymonitor_allocationsize_get_bytes_per_block(memorymonitor_allocationsize_obj_t* self) { - return BYTES_PER_BLOCK; -} - -uint16_t common_hal_memorymonitor_allocationsize_get_item(memorymonitor_allocationsize_obj_t* self, int16_t index) { - return self->buckets[index]; -} - -void memorymonitor_allocationsizes_track_allocation(size_t block_count) { - memorymonitor_allocationsize_obj_t* as = MP_OBJ_TO_PTR(MP_STATE_VM(active_allocationsizes)); - size_t power_of_two = 0; - block_count >>= 1; - while (block_count != 0) { - power_of_two++; - block_count >>= 1; - } - while (as != NULL) { - as->buckets[power_of_two]++; - as = as->next; - } -} - -void memorymonitor_allocationsizes_reset(void) { - MP_STATE_VM(active_allocationsizes) = NULL; -} diff --git a/shared-module/memorymonitor/AllocationSize 2.h b/shared-module/memorymonitor/AllocationSize 2.h deleted file mode 100644 index 3baab2213e..0000000000 --- a/shared-module/memorymonitor/AllocationSize 2.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of the Micro Python 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. - */ - -#ifndef MICROPY_INCLUDED_SHARED_MODULE_MEMORYMONITOR_ALLOCATIONSIZE_H -#define MICROPY_INCLUDED_SHARED_MODULE_MEMORYMONITOR_ALLOCATIONSIZE_H - -#include -#include - -#include "py/obj.h" - -typedef struct _memorymonitor_allocationsize_obj_t memorymonitor_allocationsize_obj_t; - -#define ALLOCATION_SIZE_BUCKETS 16 - -typedef struct _memorymonitor_allocationsize_obj_t { - mp_obj_base_t base; - uint16_t buckets[ALLOCATION_SIZE_BUCKETS]; - // Store the location that points to us so we can remove ourselves. - memorymonitor_allocationsize_obj_t** previous; - memorymonitor_allocationsize_obj_t* next; - bool paused; -} memorymonitor_allocationsize_obj_t; - -void memorymonitor_allocationsizes_track_allocation(size_t block_count); -void memorymonitor_allocationsizes_reset(void); - -#endif // MICROPY_INCLUDED_SHARED_MODULE_MEMORYMONITOR_ALLOCATIONSIZE_H diff --git a/shared-module/memorymonitor/__init__ 2.c b/shared-module/memorymonitor/__init__ 2.c deleted file mode 100644 index 6cb424153d..0000000000 --- a/shared-module/memorymonitor/__init__ 2.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2020 Scott Shawcroft - * - * 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-module/memorymonitor/__init__.h" -#include "shared-module/memorymonitor/AllocationAlarm.h" -#include "shared-module/memorymonitor/AllocationSize.h" - -void memorymonitor_track_allocation(size_t block_count) { - memorymonitor_allocationalarms_allocation(block_count); - memorymonitor_allocationsizes_track_allocation(block_count); -} - -void memorymonitor_reset(void) { - memorymonitor_allocationalarms_reset(); - memorymonitor_allocationsizes_reset(); -} diff --git a/shared-module/memorymonitor/__init__ 2.h b/shared-module/memorymonitor/__init__ 2.h deleted file mode 100644 index f47f6434bf..0000000000 --- a/shared-module/memorymonitor/__init__ 2.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2016 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_MEMORYMONITOR___INIT___H -#define MICROPY_INCLUDED_MEMORYMONITOR___INIT___H - -#include - -void memorymonitor_track_allocation(size_t block_count); -void memorymonitor_reset(void); - -#endif // MICROPY_INCLUDED_MEMORYMONITOR___INIT___H From 7f629624dbd1d67576af495026305b75200f8872 Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Fri, 21 Aug 2020 20:50:15 -0500 Subject: [PATCH 35/79] Added hanging indents to docs per @sommersoft's suggestion --- 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 c13ed0407e..b1d73115de 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -174,19 +174,19 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val //| def blit(self, x: int, y: int, source_bitmap: bitmap, *, x1: int, y1: int, x2: int, y2: int, skip_index: int) -> None: //| """Inserts the source_bitmap region defined by rectangular boundaries -//| (x1,y1) and (x2,y2) into the bitmap at the specified (x,y) location. +//| (x1,y1) and (x2,y2) into the bitmap at the specified (x,y) location. //| //| :param int x: Horizontal pixel location in bitmap where source_bitmap upper-left -//| corner will be placed +//| corner will be placed //| :param int y: Vertical pixel location in bitmap where source_bitmap upper-left -//| corner will be placed +//| corner will be placed //| :param bitmap source_bitmap: Source bitmap that contains the graphical region to be copied //| :param int x1: Minimum x-value for rectangular bounding box to be copied from the source bitmap //| :param int y1: Minimum y-value for rectangular bounding box to be copied from the source bitmap //| :param int x2: Maximum x-value (exclusive) for rectangular bounding box to be copied from the source bitmap //| :param int y2: Maximum y-value (exclusive) for rectangular bounding box to be copied from the source bitmap //| :param int skip_index: bitmap palette index in the source that will not be copied, -//| set to None to copy all pixels""" +//| set to None to copy all pixels""" //| ... //| STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args){ From f55f2bfee1bcce39a617628a5b1aa7728a24295b Mon Sep 17 00:00:00 2001 From: Kevin Matocha Date: Fri, 21 Aug 2020 21:40:46 -0500 Subject: [PATCH 36/79] shorten error strings --- locale/circuitpython.pot | 60 ++++++++++++------------------ shared-bindings/displayio/Bitmap.c | 12 +++--- 2 files changed, 30 insertions(+), 42 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index c8a24ef674..fe726acf27 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-21 14:36-0500\n" +"POT-Creation-Date: 2020-08-21 21:39-0500\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -82,7 +82,6 @@ msgstr "" msgid "%q list must be a list" msgstr "" -#: shared-bindings/memorymonitor/AllocationAlarm 2.c #: shared-bindings/memorymonitor/AllocationAlarm.c msgid "%q must be >= 0" msgstr "" @@ -90,7 +89,6 @@ msgstr "" #: shared-bindings/_bleio/CharacteristicBuffer.c #: shared-bindings/_bleio/PacketBuffer.c shared-bindings/displayio/Group.c #: shared-bindings/displayio/Shape.c -#: shared-bindings/memorymonitor/AllocationAlarm 2.c #: shared-bindings/memorymonitor/AllocationAlarm.c #: shared-bindings/vectorio/Circle.c shared-bindings/vectorio/Rectangle.c msgid "%q must be >= 1" @@ -254,14 +252,6 @@ msgstr "" msgid "'yield' outside function" msgstr "" -#: shared-bindings/displayio/Bitmap.c -msgid "(x,y): out of range of target bitmap" -msgstr "" - -#: shared-bindings/displayio/Bitmap.c -msgid "(x1,y1) or (x2,y2): out of range of source bitmap" -msgstr "" - #: py/compile.c msgid "*x must be assignment target" msgstr "" @@ -332,9 +322,7 @@ msgstr "" msgid "Already advertising." msgstr "" -#: shared-module/memorymonitor/AllocationAlarm 2.c #: shared-module/memorymonitor/AllocationAlarm.c -#: shared-module/memorymonitor/AllocationSize 2.c #: shared-module/memorymonitor/AllocationSize.c msgid "Already running" msgstr "" @@ -374,7 +362,6 @@ msgstr "" msgid "At most %d %q may be specified (not %d)" msgstr "" -#: shared-module/memorymonitor/AllocationAlarm 2.c #: shared-module/memorymonitor/AllocationAlarm.c #, c-format msgid "Attempt to allocate %d blocks" @@ -456,8 +443,7 @@ msgid "Buffer length %d too big. It must be less than %d" msgstr "" #: ports/atmel-samd/common-hal/sdioio/SDCard.c -#: ports/cxd56/common-hal/sdioio/SDCard.c shared-module/sdcardio/SDCard 2.c -#: shared-module/sdcardio/SDCard.c +#: ports/cxd56/common-hal/sdioio/SDCard.c shared-module/sdcardio/SDCard.c msgid "Buffer length must be a multiple of 512" msgstr "" @@ -505,11 +491,6 @@ msgid "Can't set CCCD on local Characteristic" msgstr "" #: shared-bindings/displayio/Bitmap.c -msgid "Cannot blit: source palette too large." -msgstr "" - -#: shared-bindings/displayio/Bitmap.c -#: shared-bindings/memorymonitor/AllocationSize 2.c #: shared-bindings/memorymonitor/AllocationSize.c #: shared-bindings/pulseio/PulseIn.c msgid "Cannot delete values" @@ -931,7 +912,7 @@ msgstr "" msgid "Internal error #%d" msgstr "" -#: shared-bindings/sdioio/SDCard 2.c shared-bindings/sdioio/SDCard.c +#: shared-bindings/sdioio/SDCard.c msgid "Invalid %q" msgstr "" @@ -1398,7 +1379,6 @@ msgstr "" msgid "Random number generation error" msgstr "" -#: shared-bindings/memorymonitor/AllocationSize 2.c #: shared-bindings/memorymonitor/AllocationSize.c #: shared-bindings/pulseio/PulseIn.c msgid "Read-only" @@ -1432,7 +1412,7 @@ msgstr "" msgid "Running in safe mode! " msgstr "" -#: shared-module/sdcardio/SDCard 2.c shared-module/sdcardio/SDCard.c +#: shared-module/sdcardio/SDCard.c msgid "SD card CSD format not supported" msgstr "" @@ -1491,7 +1471,6 @@ msgstr "" #: shared-bindings/displayio/Bitmap.c shared-bindings/displayio/Group.c #: shared-bindings/displayio/TileGrid.c -#: shared-bindings/memorymonitor/AllocationSize 2.c #: shared-bindings/memorymonitor/AllocationSize.c #: shared-bindings/pulseio/PulseIn.c msgid "Slices not supported" @@ -1517,7 +1496,7 @@ msgstr "" msgid "Supply at least one UART pin" msgstr "" -#: shared-bindings/gnss/GNSS 2.c shared-bindings/gnss/GNSS.c +#: shared-bindings/gnss/GNSS.c msgid "System entry must be gnss.SatelliteSystem" msgstr "" @@ -1821,12 +1800,10 @@ msgstr "" msgid "address %08x is not aligned to %d bytes" msgstr "" -#: shared-bindings/i2cperipheral/I2CPeripheral 2.c #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "address out of bounds" msgstr "" -#: shared-bindings/i2cperipheral/I2CPeripheral 2.c #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "addresses is empty" msgstr "" @@ -1989,8 +1966,7 @@ msgstr "" msgid "can't assign to expression" msgstr "" -#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral 2.c -#: shared-bindings/i2cperipheral/I2CPeripheral.c +#: py/obj.c py/objint.c shared-bindings/i2cperipheral/I2CPeripheral.c #: shared-module/_pixelbuf/PixelBuf.c msgid "can't convert %q to %q" msgstr "" @@ -2051,7 +2027,7 @@ msgstr "" msgid "can't send non-None value to a just-started generator" msgstr "" -#: shared-module/sdcardio/SDCard 2.c shared-module/sdcardio/SDCard.c +#: shared-module/sdcardio/SDCard.c msgid "can't set 512 block size" msgstr "" @@ -2181,7 +2157,7 @@ msgstr "" msgid "could not invert Vandermonde matrix" msgstr "" -#: shared-module/sdcardio/SDCard 2.c shared-module/sdcardio/SDCard.c +#: shared-module/sdcardio/SDCard.c msgid "couldn't determine SD card version" msgstr "" @@ -2739,7 +2715,7 @@ msgstr "" msgid "negative shift count" msgstr "" -#: shared-module/sdcardio/SDCard 2.c shared-module/sdcardio/SDCard.c +#: shared-module/sdcardio/SDCard.c msgid "no SD card" msgstr "" @@ -2764,7 +2740,7 @@ msgstr "" msgid "no reset pin available" msgstr "" -#: shared-module/sdcardio/SDCard 2.c shared-module/sdcardio/SDCard.c +#: shared-module/sdcardio/SDCard.c msgid "no response from SD card" msgstr "" @@ -2899,6 +2875,14 @@ msgstr "" msgid "ord() expected a character, but string of length %d found" msgstr "" +#: shared-bindings/displayio/Bitmap.c +msgid "out of range of source" +msgstr "" + +#: shared-bindings/displayio/Bitmap.c +msgid "out of range of target" +msgstr "" + #: py/objint_mpz.c msgid "overflow converting long int to machine word" msgstr "" @@ -3076,6 +3060,10 @@ msgstr "" msgid "sosfilt requires iterable arguments" msgstr "" +#: shared-bindings/displayio/Bitmap.c +msgid "source palette too large" +msgstr "" + #: py/objstr.c msgid "start/end indices" msgstr "" @@ -3152,11 +3140,11 @@ msgstr "" msgid "timeout must be >= 0.0" msgstr "" -#: shared-module/sdcardio/SDCard 2.c shared-module/sdcardio/SDCard.c +#: shared-module/sdcardio/SDCard.c msgid "timeout waiting for v1 card" msgstr "" -#: shared-module/sdcardio/SDCard 2.c shared-module/sdcardio/SDCard.c +#: shared-module/sdcardio/SDCard.c msgid "timeout waiting for v2 card" msgstr "" diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index b1d73115de..5a2fc785f8 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -177,16 +177,16 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val //| (x1,y1) and (x2,y2) into the bitmap at the specified (x,y) location. //| //| :param int x: Horizontal pixel location in bitmap where source_bitmap upper-left -//| corner will be placed +//| corner will be placed //| :param int y: Vertical pixel location in bitmap where source_bitmap upper-left -//| corner will be placed +//| corner will be placed //| :param bitmap source_bitmap: Source bitmap that contains the graphical region to be copied //| :param int x1: Minimum x-value for rectangular bounding box to be copied from the source bitmap //| :param int y1: Minimum y-value for rectangular bounding box to be copied from the source bitmap //| :param int x2: Maximum x-value (exclusive) for rectangular bounding box to be copied from the source bitmap //| :param int y2: Maximum y-value (exclusive) for rectangular bounding box to be copied from the source bitmap //| :param int skip_index: bitmap palette index in the source that will not be copied, -//| set to None to copy all pixels""" +//| set to None to copy all pixels""" //| ... //| STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args){ @@ -213,7 +213,7 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg // ensure that the target bitmap (self) has at least as many `bits_per_value` as the source if (self->bits_per_value < source->bits_per_value) { - mp_raise_ValueError(translate("Cannot blit: source palette too large.")); + mp_raise_ValueError(translate("source palette too large")); } int16_t x1 = args[ARG_x1].u_int; @@ -234,14 +234,14 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg // Check x,y are within self (target) bitmap boundary if ( (x < 0) || (y < 0) || (x > self->width) || (y > self->height) ) { - mp_raise_ValueError(translate("(x,y): out of range of target bitmap")); + mp_raise_ValueError(translate("out of range of target")); } // Check x1,y1,x2,y2 are within source bitmap boundary if ( (x1 < 0) || (x1 > source->width) || (y1 < 0) || (y1 > source->height) || (x2 < 0) || (x2 > source->width) || (y2 < 0) || (y2 > source->height) ) { - mp_raise_ValueError(translate("(x1,y1) or (x2,y2): out of range of source bitmap")); + mp_raise_ValueError(translate("out of range of source")); } // Ensure x1 < x2 and y1 < y2 From f8a9e11ff4f42620bbe6e678f009bdadcb4ac542 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sun, 23 Aug 2020 08:46:42 -0500 Subject: [PATCH 37/79] WIP supervisor: check for interrupt during rx_chr --- supervisor/shared/micropython.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/supervisor/shared/micropython.c b/supervisor/shared/micropython.c index 245db11d42..cd9485f8c0 100644 --- a/supervisor/shared/micropython.c +++ b/supervisor/shared/micropython.c @@ -29,14 +29,32 @@ #include "supervisor/serial.h" #include "lib/oofatfs/ff.h" #include "py/mpconfig.h" +#include "py/mpstate.h" #include "supervisor/shared/status_leds.h" +#if CIRCUITPY_WATCHDOG +#include "shared-bindings/watchdog/__init__.h" +#define WATCHDOG_EXCEPTION_CHECK() (MP_STATE_VM(mp_pending_exception) == &mp_watchdog_timeout_exception) +#else +#define WATCHDOG_EXCEPTION_CHECK() 0 +#endif + int mp_hal_stdin_rx_chr(void) { for (;;) { #ifdef MICROPY_VM_HOOK_LOOP MICROPY_VM_HOOK_LOOP #endif + // Check to see if we've been CTRL-Ced by autoreload or the user. + if (MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception))) { + // clear exception and generate stacktrace + MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL; + nlr_raise(&MP_STATE_VM(mp_kbd_exception)); + } + if (MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception)) || WATCHDOG_EXCEPTION_CHECK()) { + // stop reading immediately + return EOF; + } if (serial_bytes_available()) { toggle_rx_led(); return serial_read(); From 1033e89561d6535f32aa4cfd3541ffd9683a1123 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sun, 23 Aug 2020 09:03:34 -0500 Subject: [PATCH 38/79] supervisor: use mp_handle_pending to check for exceptions --- supervisor/shared/micropython.c | 12 ++---------- supervisor/shared/tick.c | 13 ++----------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/supervisor/shared/micropython.c b/supervisor/shared/micropython.c index cd9485f8c0..bbc4807f97 100644 --- a/supervisor/shared/micropython.c +++ b/supervisor/shared/micropython.c @@ -30,6 +30,7 @@ #include "lib/oofatfs/ff.h" #include "py/mpconfig.h" #include "py/mpstate.h" +#include "py/runtime.h" #include "supervisor/shared/status_leds.h" @@ -45,16 +46,7 @@ int mp_hal_stdin_rx_chr(void) { #ifdef MICROPY_VM_HOOK_LOOP MICROPY_VM_HOOK_LOOP #endif - // Check to see if we've been CTRL-Ced by autoreload or the user. - if (MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception))) { - // clear exception and generate stacktrace - MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL; - nlr_raise(&MP_STATE_VM(mp_kbd_exception)); - } - if (MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception)) || WATCHDOG_EXCEPTION_CHECK()) { - // stop reading immediately - return EOF; - } + mp_handle_pending(); if (serial_bytes_available()) { toggle_rx_led(); return serial_read(); diff --git a/supervisor/shared/tick.c b/supervisor/shared/tick.c index 4af59f78e3..f26e1e79d1 100644 --- a/supervisor/shared/tick.c +++ b/supervisor/shared/tick.c @@ -27,6 +27,7 @@ #include "supervisor/shared/tick.h" #include "py/mpstate.h" +#include "py/runtime.h" #include "supervisor/linker.h" #include "supervisor/filesystem.h" #include "supervisor/background_callback.h" @@ -149,17 +150,7 @@ void mp_hal_delay_ms(mp_uint_t delay) { while (remaining > 0) { RUN_BACKGROUND_TASKS; // Check to see if we've been CTRL-Ced by autoreload or the user. - if(MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception))) - { - // clear exception and generate stacktrace - MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL; - nlr_raise(&MP_STATE_VM(mp_kbd_exception)); - } - if( MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception)) || - WATCHDOG_EXCEPTION_CHECK()) { - // stop sleeping immediately - break; - } + mp_handle_pending(); 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. From c79389c4d4af881a1df3e366855c731f09a1e128 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Mon, 24 Aug 2020 11:10:34 +0530 Subject: [PATCH 39/79] Added microS2 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 ceb691a15b..28bc7664c7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -410,6 +410,7 @@ jobs: board: - "espressif_saola_1_wroom" - "espressif_saola_1_wrover" + - "micro_s2" - "unexpectedmaker_feathers2" steps: From 3eea3b5311c9e096a790b37f339ae02e2b206934 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Mon, 24 Aug 2020 11:12:35 +0530 Subject: [PATCH 40/79] Added microS2 specific config files --- ports/esp32s2/boards/micro_s2/board.c | 56 +++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 ports/esp32s2/boards/micro_s2/board.c diff --git a/ports/esp32s2/boards/micro_s2/board.c b/ports/esp32s2/boards/micro_s2/board.c new file mode 100644 index 0000000000..1dc30b5af8 --- /dev/null +++ b/ports/esp32s2/boards/micro_s2/board.c @@ -0,0 +1,56 @@ +/* + * 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 "boards/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 + common_hal_never_reset_pin(&pin_GPIO43); + common_hal_never_reset_pin(&pin_GPIO44); + + // 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) { + +} From c137a1612133e06d2b7bec06b325695c9a60c4b9 Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Mon, 24 Aug 2020 14:49:06 -0400 Subject: [PATCH 41/79] Remove Meowbit LSE flag, harsher failure for LSE issues --- ports/stm/boards/meowbit_v121/mpconfigboard.h | 3 +-- ports/stm/peripherals/stm32f4/clocks.c | 17 +++-------------- ports/stm/peripherals/stm32f7/clocks.c | 17 +++-------------- ports/stm/peripherals/stm32h7/clocks.c | 17 +++-------------- 4 files changed, 10 insertions(+), 44 deletions(-) diff --git a/ports/stm/boards/meowbit_v121/mpconfigboard.h b/ports/stm/boards/meowbit_v121/mpconfigboard.h index 106f25b15c..be9f2a75fb 100644 --- a/ports/stm/boards/meowbit_v121/mpconfigboard.h +++ b/ports/stm/boards/meowbit_v121/mpconfigboard.h @@ -36,8 +36,7 @@ #define BOARD_FLASH_SIZE (FLASH_SIZE - 0x4000) #define HSE_VALUE ((uint32_t)12000000U) -#define LSE_VALUE ((uint32_t)32000U) -#define BOARD_HAS_LOW_SPEED_CRYSTAL (1) +#define BOARD_HAS_LOW_SPEED_CRYSTAL (0) #define BOARD_NO_VBUS_SENSE (1) #define BOARD_VTOR_DEFER (1) //Leave VTOR relocation to bootloader diff --git a/ports/stm/peripherals/stm32f4/clocks.c b/ports/stm/peripherals/stm32f4/clocks.c index 7a16812b36..c2d0a452a0 100644 --- a/ports/stm/peripherals/stm32f4/clocks.c +++ b/ports/stm/peripherals/stm32f4/clocks.c @@ -49,7 +49,6 @@ void stm32_peripherals_clocks_init(void) { RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_OscInitTypeDef RCC_OscInitStruct; RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; - bool lse_failure = false; // Set voltage scaling in accordance with system clock speed __HAL_RCC_PWR_CLK_ENABLE(); @@ -76,15 +75,9 @@ void stm32_peripherals_clocks_init(void) { #endif if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { - // Failure likely means a LSE issue - attempt to swap to LSI, and set to crash - RCC_OscInitStruct.LSEState = RCC_LSE_OFF; - RCC_OscInitStruct.OscillatorType |= RCC_OSCILLATORTYPE_LSI; - RCC_OscInitStruct.LSIState = RCC_LSI_ON; - if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { - // No HSE means no USB, so just fail forever - while(1); - } - lse_failure = true; + // Clock issues are too problematic to even attempt recovery. + // If you end up here, check whether your LSE settings match your board. + while(1); } // Configure bus clock sources and divisors @@ -113,8 +106,4 @@ void stm32_peripherals_clocks_init(void) { #endif HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); - - if (lse_failure) { - reset_into_safe_mode(HARD_CRASH); //TODO: make safe mode category CLOCK_FAULT? - } } diff --git a/ports/stm/peripherals/stm32f7/clocks.c b/ports/stm/peripherals/stm32f7/clocks.c index 93016f6828..f130887822 100644 --- a/ports/stm/peripherals/stm32f7/clocks.c +++ b/ports/stm/peripherals/stm32f7/clocks.c @@ -40,7 +40,6 @@ void stm32_peripherals_clocks_init(void) { RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_OscInitTypeDef RCC_OscInitStruct; RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; - bool lse_failure = false; // Configure LSE Drive HAL_PWR_EnableBkUpAccess(); @@ -68,15 +67,9 @@ void stm32_peripherals_clocks_init(void) { RCC_OscInitStruct.PLL.PLLQ = CPY_CLK_PLLQ; if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { - // Failure likely means a LSE issue - attempt to swap to LSI, and set to crash - RCC_OscInitStruct.LSEState = RCC_LSE_OFF; - RCC_OscInitStruct.OscillatorType |= RCC_OSCILLATORTYPE_LSI; - RCC_OscInitStruct.LSIState = RCC_LSI_ON; - if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { - // No HSE means no USB, so just fail forever - while(1); - } - lse_failure = true; + // Clock issues are too problematic to even attempt recovery. + // If you end up here, check whether your LSE settings match your board. + while(1); } /* Activate the OverDrive to reach the 216 MHz Frequency */ @@ -111,8 +104,4 @@ void stm32_peripherals_clocks_init(void) { #endif HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); - - if (lse_failure) { - reset_into_safe_mode(HARD_CRASH); //TODO: make safe mode category CLOCK_FAULT? - } } diff --git a/ports/stm/peripherals/stm32h7/clocks.c b/ports/stm/peripherals/stm32h7/clocks.c index 0e4e79f9f7..a088f78bf2 100644 --- a/ports/stm/peripherals/stm32h7/clocks.c +++ b/ports/stm/peripherals/stm32h7/clocks.c @@ -37,7 +37,6 @@ void stm32_peripherals_clocks_init(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0}; - bool lse_failure = false; // Set voltage scaling in accordance with system clock speed HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY); @@ -73,15 +72,9 @@ void stm32_peripherals_clocks_init(void) { RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE; RCC_OscInitStruct.PLL.PLLFRACN = 0; if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { - // Failure likely means a LSE issue - attempt to swap to LSI, and set to crash - RCC_OscInitStruct.LSEState = RCC_LSE_OFF; - RCC_OscInitStruct.OscillatorType |= RCC_OSCILLATORTYPE_LSI; - RCC_OscInitStruct.LSIState = RCC_LSI_ON; - if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { - // No HSE means no USB, so just fail forever - while(1); - } - lse_failure = true; + // Clock issues are too problematic to even attempt recovery. + // If you end up here, check whether your LSE settings match your board. + while(1); } // Configure bus clock sources and divisors @@ -116,8 +109,4 @@ void stm32_peripherals_clocks_init(void) { // Enable USB Voltage detector HAL_PWREx_EnableUSBVoltageDetector(); - - if (lse_failure) { - reset_into_safe_mode(HARD_CRASH); //TODO: make safe mode category CLOCK_FAULT? - } } From 0cc438e6b99f29a097bc256f2320be7060ebfa17 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 24 Aug 2020 18:29:34 -0700 Subject: [PATCH 42/79] Fix pycubed pwm use --- ports/atmel-samd/boards/pycubed/board.c | 8 ++++---- ports/atmel-samd/boards/pycubed_mram/board.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ports/atmel-samd/boards/pycubed/board.c b/ports/atmel-samd/boards/pycubed/board.c index 9d29d2a66a..0bf586ad8e 100644 --- a/ports/atmel-samd/boards/pycubed/board.c +++ b/ports/atmel-samd/boards/pycubed/board.c @@ -32,7 +32,7 @@ #include "shared-bindings/nvm/ByteArray.h" #include "common-hal/microcontroller/Pin.h" #include "hal/include/hal_gpio.h" -#include "shared-bindings/pulseio/PWMOut.h" +#include "shared-bindings/pwmio/PWMOut.h" nvm_bytearray_obj_t bootcnt = { .base = { @@ -44,9 +44,9 @@ nvm_bytearray_obj_t bootcnt = { void board_init(void) { - pulseio_pwmout_obj_t pwm; - common_hal_pulseio_pwmout_construct(&pwm, &pin_PA23, 4096, 2, false); - common_hal_pulseio_pwmout_never_reset(&pwm); + pwmio_pwmout_obj_t pwm; + common_hal_pwmio_pwmout_construct(&pwm, &pin_PA23, 4096, 2, false); + common_hal_pwmio_pwmout_never_reset(&pwm); } bool board_requests_safe_mode(void) { diff --git a/ports/atmel-samd/boards/pycubed_mram/board.c b/ports/atmel-samd/boards/pycubed_mram/board.c index 9d29d2a66a..0bf586ad8e 100644 --- a/ports/atmel-samd/boards/pycubed_mram/board.c +++ b/ports/atmel-samd/boards/pycubed_mram/board.c @@ -32,7 +32,7 @@ #include "shared-bindings/nvm/ByteArray.h" #include "common-hal/microcontroller/Pin.h" #include "hal/include/hal_gpio.h" -#include "shared-bindings/pulseio/PWMOut.h" +#include "shared-bindings/pwmio/PWMOut.h" nvm_bytearray_obj_t bootcnt = { .base = { @@ -44,9 +44,9 @@ nvm_bytearray_obj_t bootcnt = { void board_init(void) { - pulseio_pwmout_obj_t pwm; - common_hal_pulseio_pwmout_construct(&pwm, &pin_PA23, 4096, 2, false); - common_hal_pulseio_pwmout_never_reset(&pwm); + pwmio_pwmout_obj_t pwm; + common_hal_pwmio_pwmout_construct(&pwm, &pin_PA23, 4096, 2, false); + common_hal_pwmio_pwmout_never_reset(&pwm); } bool board_requests_safe_mode(void) { From 2b470b148620031adbd0afe6732a5b1965cbb19f Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 24 Aug 2020 18:29:50 -0700 Subject: [PATCH 43/79] Fix RGB LED use --- supervisor/shared/rgb_led_status.c | 44 +++++++++++++++--------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/supervisor/shared/rgb_led_status.c b/supervisor/shared/rgb_led_status.c index 2f23e31258..283b9da123 100644 --- a/supervisor/shared/rgb_led_status.c +++ b/supervisor/shared/rgb_led_status.c @@ -66,22 +66,22 @@ busio_spi_obj_t status_apa102 = { #if defined(CP_RGB_STATUS_R) || defined(CP_RGB_STATUS_G) || defined(CP_RGB_STATUS_B) #define CP_RGB_STATUS_LED -#include "shared-bindings/pulseio/PWMOut.h" +#include "shared-bindings/pwmio/PWMOut.h" #include "shared-bindings/microcontroller/Pin.h" -pulseio_pwmout_obj_t rgb_status_r = { +pwmio_pwmout_obj_t rgb_status_r = { .base = { - .type = &pulseio_pwmout_type, + .type = &pwmio_pwmout_type, }, }; -pulseio_pwmout_obj_t rgb_status_g = { +pwmio_pwmout_obj_t rgb_status_g = { .base = { - .type = &pulseio_pwmout_type, + .type = &pwmio_pwmout_type, }, }; -pulseio_pwmout_obj_t rgb_status_b = { +pwmio_pwmout_obj_t rgb_status_b = { .base = { - .type = &pulseio_pwmout_type, + .type = &pwmio_pwmout_type, }, }; @@ -147,26 +147,26 @@ void rgb_led_status_init() { #if defined(CP_RGB_STATUS_LED) if (common_hal_mcu_pin_is_free(CP_RGB_STATUS_R)) { - pwmout_result_t red_result = common_hal_pulseio_pwmout_construct(&rgb_status_r, CP_RGB_STATUS_R, 0, 50000, false); + pwmout_result_t red_result = common_hal_pwmio_pwmout_construct(&rgb_status_r, CP_RGB_STATUS_R, 0, 50000, false); if (PWMOUT_OK == red_result) { - common_hal_pulseio_pwmout_never_reset(&rgb_status_r); + common_hal_pwmio_pwmout_never_reset(&rgb_status_r); } } if (common_hal_mcu_pin_is_free(CP_RGB_STATUS_G)) { - pwmout_result_t green_result = common_hal_pulseio_pwmout_construct(&rgb_status_g, CP_RGB_STATUS_G, 0, 50000, false); + pwmout_result_t green_result = common_hal_pwmio_pwmout_construct(&rgb_status_g, CP_RGB_STATUS_G, 0, 50000, false); if (PWMOUT_OK == green_result) { - common_hal_pulseio_pwmout_never_reset(&rgb_status_g); + common_hal_pwmio_pwmout_never_reset(&rgb_status_g); } } if (common_hal_mcu_pin_is_free(CP_RGB_STATUS_B)) { - pwmout_result_t blue_result = common_hal_pulseio_pwmout_construct(&rgb_status_b, CP_RGB_STATUS_B, 0, 50000, false); + pwmout_result_t blue_result = common_hal_pwmio_pwmout_construct(&rgb_status_b, CP_RGB_STATUS_B, 0, 50000, false); if (PWMOUT_OK == blue_result) { - common_hal_pulseio_pwmout_never_reset(&rgb_status_b); + common_hal_pwmio_pwmout_never_reset(&rgb_status_b); } } #endif @@ -242,9 +242,9 @@ void new_status_color(uint32_t rgb) { status_rgb_color[2] = (uint16_t) (blue_u8 << 8) + blue_u8; #endif - common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_r, status_rgb_color[0]); - common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_g, status_rgb_color[1]); - common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_b, status_rgb_color[2]); + common_hal_pwmio_pwmout_set_duty_cycle(&rgb_status_r, status_rgb_color[0]); + common_hal_pwmio_pwmout_set_duty_cycle(&rgb_status_g, status_rgb_color[1]); + common_hal_pwmio_pwmout_set_duty_cycle(&rgb_status_b, status_rgb_color[2]); #endif } @@ -288,9 +288,9 @@ void temp_status_color(uint32_t rgb) { temp_status_color_rgb[2] = (uint16_t) (blue_u8 << 8) + blue_u8; #endif - common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_r, temp_status_color_rgb[0]); - common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_g, temp_status_color_rgb[1]); - common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_b, temp_status_color_rgb[2]); + common_hal_pwmio_pwmout_set_duty_cycle(&rgb_status_r, temp_status_color_rgb[0]); + common_hal_pwmio_pwmout_set_duty_cycle(&rgb_status_g, temp_status_color_rgb[1]); + common_hal_pwmio_pwmout_set_duty_cycle(&rgb_status_b, temp_status_color_rgb[2]); #endif } @@ -327,9 +327,9 @@ void clear_temp_status() { blue = status_rgb_color[2]; #endif - common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_r, red); - common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_g, green); - common_hal_pulseio_pwmout_set_duty_cycle(&rgb_status_b, blue); + common_hal_pwmio_pwmout_set_duty_cycle(&rgb_status_r, red); + common_hal_pwmio_pwmout_set_duty_cycle(&rgb_status_g, green); + common_hal_pwmio_pwmout_set_duty_cycle(&rgb_status_b, blue); #endif } From de9fd4a0fb26c1a62b97d6175c75568b68e50abd Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Mon, 24 Aug 2020 17:59:13 -0400 Subject: [PATCH 44/79] Fix null dereference, invert auto_brightness to reenable screen --- ports/stm/boards/meowbit_v121/board.c | 2 +- ports/stm/boards/meowbit_v121/mpconfigboard.mk | 4 +++- ports/stm/common-hal/pulseio/PWMOut.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ports/stm/boards/meowbit_v121/board.c b/ports/stm/boards/meowbit_v121/board.c index 812a8c208c..b74f135165 100644 --- a/ports/stm/boards/meowbit_v121/board.c +++ b/ports/stm/boards/meowbit_v121/board.c @@ -106,7 +106,7 @@ void board_init(void) { &pin_PB03, NO_BRIGHTNESS_COMMAND, 1.0f, // brightness (ignored) - true, // auto_brightness + false, // auto_brightness false, // single_byte_bounds false, // data_as_commands true, // auto_refresh diff --git a/ports/stm/boards/meowbit_v121/mpconfigboard.mk b/ports/stm/boards/meowbit_v121/mpconfigboard.mk index 852836ef8f..9eaa1bd8fb 100644 --- a/ports/stm/boards/meowbit_v121/mpconfigboard.mk +++ b/ports/stm/boards/meowbit_v121/mpconfigboard.mk @@ -18,4 +18,6 @@ OPTIMIZATION_FLAGS = -Os LD_COMMON = boards/common_default.ld LD_FILE = boards/STM32F401xe_boot.ld -# LD_FILE = boards/STM32F401xe_fs.ld # use for internal flash + +# For debugging - also comment BOOTLOADER_OFFSET and BOARD_VTOR_DEFER +# LD_FILE = boards/STM32F401xe_fs.ld diff --git a/ports/stm/common-hal/pulseio/PWMOut.c b/ports/stm/common-hal/pulseio/PWMOut.c index ddbadaf4ce..4bcb072122 100644 --- a/ports/stm/common-hal/pulseio/PWMOut.c +++ b/ports/stm/common-hal/pulseio/PWMOut.c @@ -239,13 +239,14 @@ void common_hal_pulseio_pwmout_deinit(pulseio_pwmout_obj_t* self) { HAL_TIM_PWM_Stop(&self->handle, self->channel); } reset_pin_number(self->tim->pin->port,self->tim->pin->number); - self->tim = NULL; //if reserved timer has no active channels, we can disable it if (!reserved_tim[self->tim->tim_index - 1]) { tim_frequencies[self->tim->tim_index - 1] = 0x00; stm_peripherals_timer_free(self->handle.Instance); } + + self->tim = NULL; } void common_hal_pulseio_pwmout_set_duty_cycle(pulseio_pwmout_obj_t* self, uint16_t duty) { From 645adaadb0ec97b7e0250b8987ff5be9cd59c4c5 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Tue, 25 Aug 2020 20:32:44 +0530 Subject: [PATCH 45/79] Added microS2 specific config files --- ports/esp32s2/boards/micro_s2/mpconfigboard.h | 35 +++++++++++++ .../esp32s2/boards/micro_s2/mpconfigboard.mk | 15 ++++++ ports/esp32s2/boards/micro_s2/pins.c | 49 +++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 ports/esp32s2/boards/micro_s2/mpconfigboard.h create mode 100644 ports/esp32s2/boards/micro_s2/mpconfigboard.mk create mode 100644 ports/esp32s2/boards/micro_s2/pins.c diff --git a/ports/esp32s2/boards/micro_s2/mpconfigboard.h b/ports/esp32s2/boards/micro_s2/mpconfigboard.h new file mode 100644 index 0000000000..05d860394b --- /dev/null +++ b/ports/esp32s2/boards/micro_s2/mpconfigboard.h @@ -0,0 +1,35 @@ +/* + * 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 "microS2" +#define MICROPY_HW_MCU_NAME "ESP32S2" + +#define MICROPY_HW_LED (&pin_GPIO21) +#define MICROPY_HW_NEOPIXEL (&pin_GPIO33) + +#define AUTORESET_DELAY_MS 500 diff --git a/ports/esp32s2/boards/micro_s2/mpconfigboard.mk b/ports/esp32s2/boards/micro_s2/mpconfigboard.mk new file mode 100644 index 0000000000..783e7ad4c7 --- /dev/null +++ b/ports/esp32s2/boards/micro_s2/mpconfigboard.mk @@ -0,0 +1,15 @@ +USB_VID = 0x239A +USB_PID = 0x80C6 +USB_PRODUCT = "microS2" +USB_MANUFACTURER = "microDev" + +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/micro_s2/pins.c b/ports/esp32s2/boards/micro_s2/pins.c new file mode 100644 index 0000000000..570b6a4ccb --- /dev/null +++ b/ports/esp32s2/boards/micro_s2/pins.c @@ -0,0 +1,49 @@ +#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_IO15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) }, + { 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_IO19), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_IO20), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_IO26), MP_ROM_PTR(&pin_GPIO26) }, + { 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_IO39), MP_ROM_PTR(&pin_GPIO39) }, + { MP_ROM_QSTR(MP_QSTR_IO40), MP_ROM_PTR(&pin_GPIO40) }, + { MP_ROM_QSTR(MP_QSTR_IO41), MP_ROM_PTR(&pin_GPIO41) }, + { MP_ROM_QSTR(MP_QSTR_IO42), MP_ROM_PTR(&pin_GPIO42) }, + { 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_IO45), MP_ROM_PTR(&pin_GPIO45) }, + { MP_ROM_QSTR(MP_QSTR_IO46), MP_ROM_PTR(&pin_GPIO46) }, + + { 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_LED), MP_ROM_PTR(&pin_GPIO21) }, + + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO33) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); \ No newline at end of file From 89c6a44e4e1340d87931f20b58503d09a0f2aa74 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Tue, 25 Aug 2020 20:35:08 +0530 Subject: [PATCH 46/79] Added microS2 specific config files --- ports/esp32s2/boards/micro_s2/sdkconfig | 1 + 1 file changed, 1 insertion(+) create mode 100644 ports/esp32s2/boards/micro_s2/sdkconfig diff --git a/ports/esp32s2/boards/micro_s2/sdkconfig b/ports/esp32s2/boards/micro_s2/sdkconfig new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/ports/esp32s2/boards/micro_s2/sdkconfig @@ -0,0 +1 @@ + From e9bc8e892b5ccc88782d8aaf08868b0094eae414 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 25 Aug 2020 11:45:00 -0500 Subject: [PATCH 47/79] pyexec: Handle a ctrl-c that comes in "very late" In relatively unusual circumstances, such as entering `l = 17 ** 17777` at the REPL, you could hit ctrl-c, but not get KeyboardInterrupt. This can lead to a condition where the display would stop updating (#2689). --- lib/utils/pyexec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/utils/pyexec.c b/lib/utils/pyexec.c index 8e99bc2099..378fb6267d 100755 --- a/lib/utils/pyexec.c +++ b/lib/utils/pyexec.c @@ -113,6 +113,8 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input start = mp_hal_ticks_ms(); mp_call_function_0(module_fun); mp_hal_set_interrupt_char(-1); // disable interrupt + // Handle any ctrl-c interrupt that arrived just in time + mp_handle_pending(); nlr_pop(); ret = 0; if (exec_flags & EXEC_FLAG_PRINT_EOF) { From c0753c1afb09dab873da02e6f98a492cb913f0e9 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 25 Aug 2020 11:46:49 -0500 Subject: [PATCH 48/79] mp_obj_print_helper: Handle a ctrl-c that comes in during printing In #2689, hitting ctrl-c during the printing of an object with a lot of sub-objects could cause the screen to stop updating (without showing a KeyboardInterrupt). This makes the printing of such objects acutally interruptable, and also correctly handles the KeyboardInterrupt: ``` >>> l = ["a" * 100] * 200 >>> l ['aaaaaaaaaaaaaaaaaaaaaa...aaaaaaaaaaa', Traceback (most recent call last): File "", line 1, in KeyboardInterrupt: >>> ``` --- py/obj.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/py/obj.c b/py/obj.c index 0cff2f1a4b..9dc0cf4749 100644 --- a/py/obj.c +++ b/py/obj.c @@ -67,6 +67,8 @@ void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t #ifdef RUN_BACKGROUND_TASKS RUN_BACKGROUND_TASKS; #endif + mp_handle_pending(); + #ifndef NDEBUG if (o_in == MP_OBJ_NULL) { mp_print_str(print, "(nil)"); From 05bde255f7a00dd9b41d2e4200eda652aeec28f2 Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Tue, 25 Aug 2020 14:00:29 -0400 Subject: [PATCH 49/79] Add random to ESP32-S2, fix it on STM32 --- ports/esp32s2/common-hal/os/__init__.c | 14 +++++++++++++- ports/esp32s2/mpconfigport.mk | 1 - ports/stm/common-hal/os/__init__.c | 3 +-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/ports/esp32s2/common-hal/os/__init__.c b/ports/esp32s2/common-hal/os/__init__.c index 17bda75ad3..4d6a6a2bfc 100644 --- a/ports/esp32s2/common-hal/os/__init__.c +++ b/ports/esp32s2/common-hal/os/__init__.c @@ -30,6 +30,8 @@ #include "py/objtuple.h" #include "py/qstr.h" +#include "esp_system.h" + STATIC const qstr os_uname_info_fields[] = { MP_QSTR_sysname, MP_QSTR_nodename, MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine @@ -57,5 +59,15 @@ mp_obj_t common_hal_os_uname(void) { } bool common_hal_os_urandom(uint8_t* buffer, uint32_t length) { - return false; + uint32_t i = 0; + while (i < length) { + uint32_t new_random = esp_random(); + for (int j = 0; j < 4 && i < length; j++) { + buffer[i] = new_random & 0xff; + i++; + new_random >>= 8; + } + } + + return true; } diff --git a/ports/esp32s2/mpconfigport.mk b/ports/esp32s2/mpconfigport.mk index a7873aa468..13c0d66fb1 100644 --- a/ports/esp32s2/mpconfigport.mk +++ b/ports/esp32s2/mpconfigport.mk @@ -25,7 +25,6 @@ CIRCUITPY_COUNTIO = 0 # These modules are implemented in shared-module/ - they can be included in # any port once their prerequisites in common-hal are complete. -CIRCUITPY_RANDOM = 0 # Requires OS CIRCUITPY_USB_MIDI = 0 # Requires USB CIRCUITPY_ULAB = 0 # No requirements, but takes extra flash diff --git a/ports/stm/common-hal/os/__init__.c b/ports/stm/common-hal/os/__init__.c index 84deb81759..13871a46ea 100644 --- a/ports/stm/common-hal/os/__init__.c +++ b/ports/stm/common-hal/os/__init__.c @@ -77,11 +77,10 @@ bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) { uint32_t start = HAL_GetTick(); //the HAL function has a timeout, but it isn't long enough, and isn't adjustable while(!(__HAL_RNG_GET_FLAG(&handle,RNG_FLAG_DRDY)) && ((HAL_GetTick() - start) < RNG_TIMEOUT)); - // if (HAL_RNG_GenerateRandomNumber(&handle, &temp) != HAL_OK) { mp_raise_ValueError(translate("Random number generation error")); } - *buffer = (uint8_t)temp; + buffer[i] = (uint8_t)temp; } //shut down the peripheral From f71f6631ccae6b595c419d9e161b1d566f3cc6ed Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Tue, 25 Aug 2020 14:24:35 -0400 Subject: [PATCH 50/79] Enable ulab --- ports/esp32s2/mpconfigport.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/esp32s2/mpconfigport.mk b/ports/esp32s2/mpconfigport.mk index a7873aa468..152e5c8030 100644 --- a/ports/esp32s2/mpconfigport.mk +++ b/ports/esp32s2/mpconfigport.mk @@ -27,6 +27,6 @@ CIRCUITPY_COUNTIO = 0 # any port once their prerequisites in common-hal are complete. CIRCUITPY_RANDOM = 0 # Requires OS CIRCUITPY_USB_MIDI = 0 # Requires USB -CIRCUITPY_ULAB = 0 # No requirements, but takes extra flash +CIRCUITPY_ULAB = 1 # No requirements, but takes extra flash CIRCUITPY_MODULE ?= none From 964a39164e9630144944c59c5be1f1fb47c760a0 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Wed, 26 Aug 2020 08:23:54 +0530 Subject: [PATCH 51/79] Changed microS2 board name --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 28bc7664c7..4782012102 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -410,7 +410,7 @@ jobs: board: - "espressif_saola_1_wroom" - "espressif_saola_1_wrover" - - "micro_s2" + - "microdev_micro_s2" - "unexpectedmaker_feathers2" steps: From bf2b594066191f7dee335550c0f14e70cfef639b Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Wed, 26 Aug 2020 08:33:21 +0530 Subject: [PATCH 52/79] Change microS2 board name --- ports/esp32s2/boards/{micro_s2 => microdev_micro_s2}/board.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ports/esp32s2/boards/{micro_s2 => microdev_micro_s2}/board.c (100%) diff --git a/ports/esp32s2/boards/micro_s2/board.c b/ports/esp32s2/boards/microdev_micro_s2/board.c similarity index 100% rename from ports/esp32s2/boards/micro_s2/board.c rename to ports/esp32s2/boards/microdev_micro_s2/board.c From 1dce6bd7ca24b4135980953ede3a653ebcdeaeb5 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Wed, 26 Aug 2020 08:35:09 +0530 Subject: [PATCH 53/79] Change microS2 board name --- .../boards/{micro_s2 => microdev_micro_s2}/mpconfigboard.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ports/esp32s2/boards/{micro_s2 => microdev_micro_s2}/mpconfigboard.h (100%) diff --git a/ports/esp32s2/boards/micro_s2/mpconfigboard.h b/ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.h similarity index 100% rename from ports/esp32s2/boards/micro_s2/mpconfigboard.h rename to ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.h From 3f699024d943982acd55073c5db19ee9733843e2 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Wed, 26 Aug 2020 08:36:38 +0530 Subject: [PATCH 54/79] Change microS2 board name --- ports/esp32s2/boards/{micro_s2 => microdev_micro_s2}/sdkconfig | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ports/esp32s2/boards/{micro_s2 => microdev_micro_s2}/sdkconfig (100%) diff --git a/ports/esp32s2/boards/micro_s2/sdkconfig b/ports/esp32s2/boards/microdev_micro_s2/sdkconfig similarity index 100% rename from ports/esp32s2/boards/micro_s2/sdkconfig rename to ports/esp32s2/boards/microdev_micro_s2/sdkconfig From f1f316c50236f11c91b64ec06d361380a8a485f5 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Wed, 26 Aug 2020 08:37:36 +0530 Subject: [PATCH 55/79] Change microS2 board name --- ports/esp32s2/boards/{micro_s2 => microdev_micro_s2}/pins.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename ports/esp32s2/boards/{micro_s2 => microdev_micro_s2}/pins.c (99%) diff --git a/ports/esp32s2/boards/micro_s2/pins.c b/ports/esp32s2/boards/microdev_micro_s2/pins.c similarity index 99% rename from ports/esp32s2/boards/micro_s2/pins.c rename to ports/esp32s2/boards/microdev_micro_s2/pins.c index 570b6a4ccb..c5d14fd9e3 100644 --- a/ports/esp32s2/boards/micro_s2/pins.c +++ b/ports/esp32s2/boards/microdev_micro_s2/pins.c @@ -46,4 +46,4 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO33) }, }; -MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); \ No newline at end of file +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); From b019ef2e4330dcf1e341a912be3fe5bcbbeeecb8 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Wed, 26 Aug 2020 08:38:42 +0530 Subject: [PATCH 56/79] Change microS2 board name --- .../boards/{micro_s2 => microdev_micro_s2}/mpconfigboard.mk | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ports/esp32s2/boards/{micro_s2 => microdev_micro_s2}/mpconfigboard.mk (100%) diff --git a/ports/esp32s2/boards/micro_s2/mpconfigboard.mk b/ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.mk similarity index 100% rename from ports/esp32s2/boards/micro_s2/mpconfigboard.mk rename to ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.mk From 0425305a737b2f79f2f1d383a1b91cf8426980a3 Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Wed, 26 Aug 2020 08:40:46 +0530 Subject: [PATCH 57/79] Change microS2 board name --- ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.h b/ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.h index 05d860394b..bb28fe16ad 100644 --- a/ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.h +++ b/ports/esp32s2/boards/microdev_micro_s2/mpconfigboard.h @@ -26,7 +26,7 @@ //Micropython setup -#define MICROPY_HW_BOARD_NAME "microS2" +#define MICROPY_HW_BOARD_NAME "microDev microS2" #define MICROPY_HW_MCU_NAME "ESP32S2" #define MICROPY_HW_LED (&pin_GPIO21) From 0c9513a2e73870670e79a8fbcc58fdbd7a74a892 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 26 Aug 2020 09:00:16 -0400 Subject: [PATCH 58/79] Remove trailing whitespace --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4782012102..e54bbb84b1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -410,7 +410,7 @@ jobs: board: - "espressif_saola_1_wroom" - "espressif_saola_1_wrover" - - "microdev_micro_s2" + - "microdev_micro_s2" - "unexpectedmaker_feathers2" steps: From f7d224705f55e32a59a23cee7dc9cb6ad5fcd403 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 26 Aug 2020 09:01:27 -0400 Subject: [PATCH 59/79] Trim trailing whitespace in pins.c --- ports/esp32s2/boards/microdev_micro_s2/pins.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/esp32s2/boards/microdev_micro_s2/pins.c b/ports/esp32s2/boards/microdev_micro_s2/pins.c index c5d14fd9e3..25300b5c3c 100644 --- a/ports/esp32s2/boards/microdev_micro_s2/pins.c +++ b/ports/esp32s2/boards/microdev_micro_s2/pins.c @@ -33,8 +33,8 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_IO39), MP_ROM_PTR(&pin_GPIO39) }, { MP_ROM_QSTR(MP_QSTR_IO40), MP_ROM_PTR(&pin_GPIO40) }, { MP_ROM_QSTR(MP_QSTR_IO41), MP_ROM_PTR(&pin_GPIO41) }, - { MP_ROM_QSTR(MP_QSTR_IO42), MP_ROM_PTR(&pin_GPIO42) }, - { MP_ROM_QSTR(MP_QSTR_IO43), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_IO42), MP_ROM_PTR(&pin_GPIO42) }, + { 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_IO45), MP_ROM_PTR(&pin_GPIO45) }, { MP_ROM_QSTR(MP_QSTR_IO46), MP_ROM_PTR(&pin_GPIO46) }, From 01ddb177fc7f5d7bd5008e3a657ae398af404bf4 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 26 Aug 2020 09:07:54 -0400 Subject: [PATCH 62/79] Remove whitespace in sdkconfig --- ports/esp32s2/boards/microdev_micro_s2/sdkconfig | 1 - 1 file changed, 1 deletion(-) diff --git a/ports/esp32s2/boards/microdev_micro_s2/sdkconfig b/ports/esp32s2/boards/microdev_micro_s2/sdkconfig index 8b13789179..e69de29bb2 100644 --- a/ports/esp32s2/boards/microdev_micro_s2/sdkconfig +++ b/ports/esp32s2/boards/microdev_micro_s2/sdkconfig @@ -1 +0,0 @@ - From f26d15c5c9988f95317211d66e583f6982f8228a Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Wed, 26 Aug 2020 18:39:30 +0530 Subject: [PATCH 63/79] Added PSRAM support --- .../boards/microdev_micro_s2/sdkconfig | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/ports/esp32s2/boards/microdev_micro_s2/sdkconfig b/ports/esp32s2/boards/microdev_micro_s2/sdkconfig index e69de29bb2..8ee2c08fd1 100644 --- a/ports/esp32s2/boards/microdev_micro_s2/sdkconfig +++ b/ports/esp32s2/boards/microdev_micro_s2/sdkconfig @@ -0,0 +1,35 @@ +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_SPIWP_SD3_PIN=28 +# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set +# CONFIG_SPIRAM_RODATA is not set +# CONFIG_SPIRAM_USE_AHB_DBUS3 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 From 44342732a4e774a63d03c9902d1dfd6a07f77ed2 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 26 Aug 2020 10:56:00 -0500 Subject: [PATCH 64/79] Fix DOS line endings, they give my git fits --- .../boards/microdev_micro_s2/sdkconfig | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/ports/esp32s2/boards/microdev_micro_s2/sdkconfig b/ports/esp32s2/boards/microdev_micro_s2/sdkconfig index 8ee2c08fd1..b73c4a8c20 100644 --- a/ports/esp32s2/boards/microdev_micro_s2/sdkconfig +++ b/ports/esp32s2/boards/microdev_micro_s2/sdkconfig @@ -1,35 +1,35 @@ -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_SPIWP_SD3_PIN=28 -# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set -# CONFIG_SPIRAM_RODATA is not set -# CONFIG_SPIRAM_USE_AHB_DBUS3 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 +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_SPIWP_SD3_PIN=28 +# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set +# CONFIG_SPIRAM_RODATA is not set +# CONFIG_SPIRAM_USE_AHB_DBUS3 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 From 5422dd682ca107ae27c57c7d3fa240baa354bc87 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 26 Aug 2020 11:13:18 -0500 Subject: [PATCH 65/79] shared_bindings_matrix: Run in parallel .. this makes it take a fraction of the time, at least on systems with a lot of CPU threads. Even on my old laptop with a 2-core CPU it reduces the time from 55s to 27s. --- docs/shared_bindings_matrix.py | 51 +++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/docs/shared_bindings_matrix.py b/docs/shared_bindings_matrix.py index 7b96c14f29..3523b8ec60 100644 --- a/docs/shared_bindings_matrix.py +++ b/docs/shared_bindings_matrix.py @@ -28,6 +28,7 @@ import re import subprocess import sys +from concurrent.futures import ThreadPoolExecutor SUPPORTED_PORTS = ['atmel-samd', 'esp32s2', 'litex', 'mimxrt10xx', 'nrf', 'stm'] @@ -131,38 +132,44 @@ def lookup_setting(settings, key, default=''): key = value[2:-1] return value +def all_ports_all_boards(ports=SUPPORTED_PORTS): + for port in ports: + + port_dir = get_circuitpython_root_dir() / "ports" / port + for entry in (port_dir / "boards").iterdir(): + if not entry.is_dir(): + continue + yield (port, entry) + def support_matrix_by_board(use_branded_name=True): """ Compiles a list of the available core modules available for each board. """ base = build_module_map() - boards = dict() - for port in SUPPORTED_PORTS: - + def support_matrix(arg): + port, entry = arg port_dir = get_circuitpython_root_dir() / "ports" / port - for entry in (port_dir / "boards").iterdir(): - if not entry.is_dir(): - continue - board_modules = [] - board_name = entry.name + settings = get_settings_from_makefile(str(port_dir), entry.name) - settings = get_settings_from_makefile(str(port_dir), entry.name) + if use_branded_name: + with open(entry / "mpconfigboard.h") as get_name: + board_contents = get_name.read() + board_name_re = re.search(r"(?<=MICROPY_HW_BOARD_NAME)\s+(.+)", + board_contents) + if board_name_re: + board_name = board_name_re.group(1).strip('"') - if use_branded_name: - with open(entry / "mpconfigboard.h") as get_name: - board_contents = get_name.read() - board_name_re = re.search(r"(?<=MICROPY_HW_BOARD_NAME)\s+(.+)", - board_contents) - if board_name_re: - board_name = board_name_re.group(1).strip('"') + board_modules = [] + for module in base: + key = f'CIRCUITPY_{module.upper()}' + if int(lookup_setting(settings, key, '0')): + board_modules.append(base[module]['name']) - board_modules = [] - for module in base: - key = f'CIRCUITPY_{module.upper()}' - if int(lookup_setting(settings, key, '0')): - board_modules.append(base[module]['name']) - boards[board_name] = sorted(board_modules) + return (board_name, sorted(board_modules)) + + executor = ThreadPoolExecutor(max_workers=os.cpu_count()) + boards = dict(sorted(executor.map(support_matrix, all_ports_all_boards()))) #print(json.dumps(boards, indent=2)) return boards From e121e267adacf69809b78fdafc0209ad9a824266 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 26 Aug 2020 11:28:39 -0500 Subject: [PATCH 66/79] shared_bindings_matrix: Use stubs, not shared-bindings This fixes a problem where things that were in extmod/ could not be listed. --- docs/shared_bindings_matrix.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/shared_bindings_matrix.py b/docs/shared_bindings_matrix.py index 3523b8ec60..e81ae188c2 100644 --- a/docs/shared_bindings_matrix.py +++ b/docs/shared_bindings_matrix.py @@ -43,7 +43,7 @@ def get_circuitpython_root_dir(): def get_shared_bindings(): """ Get a list of modules in shared-bindings based on folder names """ - shared_bindings_dir = get_circuitpython_root_dir() / "shared-bindings" + shared_bindings_dir = get_circuitpython_root_dir() / "circuitpython-stubs" return [item.name for item in shared_bindings_dir.iterdir()] From c77523503bfebbcb3ea74465928145b7ccf5b625 Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Wed, 26 Aug 2020 14:48:46 -0400 Subject: [PATCH 67/79] Fix trailing whitespace errors across ports and docs --- docs/porting.rst | 43 +++++++++++++------ ports/esp32s2/mpconfigport.mk | 7 +-- .../stm/boards/espruino_pico/mpconfigboard.mk | 3 +- .../mpconfigboard.mk | 3 +- .../stm/boards/meowbit_v121/mpconfigboard.mk | 3 +- 5 files changed, 40 insertions(+), 19 deletions(-) diff --git a/docs/porting.rst b/docs/porting.rst index db4ae76262..6cd59fefb1 100644 --- a/docs/porting.rst +++ b/docs/porting.rst @@ -51,10 +51,15 @@ as a natural "TODO" list. An example minimal build list is shown below: .. code-block:: makefile # These modules are implemented in ports//common-hal: - CIRCUITPY_MICROCONTROLLER = 0 # Typically the first module to create - CIRCUITPY_DIGITALIO = 0 # Typically the second module to create + + # Typically the first module to create + CIRCUITPY_MICROCONTROLLER = 0 + # Typically the second module to create + CIRCUITPY_DIGITALIO = 0 + # Other modules: CIRCUITPY_ANALOGIO = 0 CIRCUITPY_BUSIO = 0 + CIRCUITPY_COUNTIO = 0 CIRCUITPY_NEOPIXEL_WRITE = 0 CIRCUITPY_PULSEIO = 0 CIRCUITPY_OS = 0 @@ -63,22 +68,34 @@ as a natural "TODO" list. An example minimal build list is shown below: CIRCUITPY_AUDIOIO = 0 CIRCUITPY_ROTARYIO = 0 CIRCUITPY_RTC = 0 + CIRCUITPY_SDCARDIO = 0 + CIRCUITPY_FRAMEBUFFERIO = 0 CIRCUITPY_FREQUENCYIO = 0 CIRCUITPY_I2CPERIPHERAL = 0 - CIRCUITPY_DISPLAYIO = 0 # Requires SPI, PulseIO (stub ok) + # Requires SPI, PulseIO (stub ok): + CIRCUITPY_DISPLAYIO = 0 # These modules are implemented in shared-module/ - they can be included in # any port once their prerequisites in common-hal are complete. - CIRCUITPY_BITBANGIO = 0 # Requires DigitalIO - CIRCUITPY_GAMEPAD = 0 # Requires DigitalIO - CIRCUITPY_PIXELBUF = 0 # Requires neopixel_write or SPI (dotstar) - CIRCUITPY_RANDOM = 0 # Requires OS - CIRCUITPY_STORAGE = 0 # Requires OS, filesystem - CIRCUITPY_TOUCHIO = 0 # Requires Microcontroller - CIRCUITPY_USB_HID = 0 # Requires USB - CIRCUITPY_USB_MIDI = 0 # Requires USB - CIRCUITPY_REQUIRE_I2C_PULLUPS = 0 # Does nothing without I2C - CIRCUITPY_ULAB = 0 # No requirements, but takes extra flash + # Requires DigitalIO: + CIRCUITPY_BITBANGIO = 0 + # Requires DigitalIO + CIRCUITPY_GAMEPAD = 0 + # Requires neopixel_write or SPI (dotstar) + CIRCUITPY_PIXELBUF = 0 + # Requires OS + CIRCUITPY_RANDOM = 0 + # Requires OS, filesystem + CIRCUITPY_STORAGE = 0 + # Requires Microcontroller + CIRCUITPY_TOUCHIO = 0 + # Requires USB + CIRCUITPY_USB_HID = 0 + CIRCUITPY_USB_MIDI = 0 + # Does nothing without I2C + CIRCUITPY_REQUIRE_I2C_PULLUPS = 0 + # No requirements, but takes extra flash + CIRCUITPY_ULAB = 0 Step 2: Init -------------- diff --git a/ports/esp32s2/mpconfigport.mk b/ports/esp32s2/mpconfigport.mk index 152e5c8030..3ddcf5d613 100644 --- a/ports/esp32s2/mpconfigport.mk +++ b/ports/esp32s2/mpconfigport.mk @@ -25,8 +25,9 @@ CIRCUITPY_COUNTIO = 0 # These modules are implemented in shared-module/ - they can be included in # any port once their prerequisites in common-hal are complete. -CIRCUITPY_RANDOM = 0 # Requires OS -CIRCUITPY_USB_MIDI = 0 # Requires USB -CIRCUITPY_ULAB = 1 # No requirements, but takes extra flash +# Requires OS +CIRCUITPY_RANDOM = 0 +# Requires USB +CIRCUITPY_USB_MIDI = 0 CIRCUITPY_MODULE ?= none diff --git a/ports/stm/boards/espruino_pico/mpconfigboard.mk b/ports/stm/boards/espruino_pico/mpconfigboard.mk index 201237c9d6..b1b023dd58 100644 --- a/ports/stm/boards/espruino_pico/mpconfigboard.mk +++ b/ports/stm/boards/espruino_pico/mpconfigboard.mk @@ -10,7 +10,8 @@ MCU_VARIANT = STM32F401xE MCU_PACKAGE = UFQFPN48 LD_COMMON = boards/common_default.ld -LD_FILE = boards/STM32F401xd_fs.ld # use for internal flash +# use for internal flash +LD_FILE = boards/STM32F401xd_fs.ld # Disable ulab as we're nearly out of space on this board due to # INTERNAL_FLASH_FILESYSTEM. It can probably be reenabled if we enable diff --git a/ports/stm/boards/feather_stm32f405_express/mpconfigboard.mk b/ports/stm/boards/feather_stm32f405_express/mpconfigboard.mk index 2b2c0d6db5..4d0bd4598d 100644 --- a/ports/stm/boards/feather_stm32f405_express/mpconfigboard.mk +++ b/ports/stm/boards/feather_stm32f405_express/mpconfigboard.mk @@ -13,5 +13,6 @@ MCU_PACKAGE = LQFP64 LD_COMMON = boards/common_default.ld LD_DEFAULT = boards/STM32F405_default.ld -LD_BOOT = boards/STM32F405_boot.ld # UF2 boot option +# UF2 boot option +LD_BOOT = boards/STM32F405_boot.ld UF2_OFFSET = 0x8010000 diff --git a/ports/stm/boards/meowbit_v121/mpconfigboard.mk b/ports/stm/boards/meowbit_v121/mpconfigboard.mk index 852836ef8f..a638183019 100644 --- a/ports/stm/boards/meowbit_v121/mpconfigboard.mk +++ b/ports/stm/boards/meowbit_v121/mpconfigboard.mk @@ -18,4 +18,5 @@ OPTIMIZATION_FLAGS = -Os LD_COMMON = boards/common_default.ld LD_FILE = boards/STM32F401xe_boot.ld -# LD_FILE = boards/STM32F401xe_fs.ld # use for internal flash +# use for internal flash +# LD_FILE = boards/STM32F401xe_fs.ld From ad733e6c4a33b830fe430599c372d1fa51ed1b2e Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Wed, 26 Aug 2020 17:37:05 -0400 Subject: [PATCH 68/79] rename reader tool --- tools/mpconfig_category_reader.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tools/mpconfig_category_reader.py diff --git a/tools/mpconfig_category_reader.py b/tools/mpconfig_category_reader.py new file mode 100644 index 0000000000..2f813931e8 --- /dev/null +++ b/tools/mpconfig_category_reader.py @@ -0,0 +1,31 @@ +filepath = '../py/circuitpy_mpconfig.mk' +with open(filepath) as fp: + line = fp.readline() + cnt = 1 + fullbuild = [] + defon = [] + defoff = [] + while line: + wordlist = line.split() + if wordlist: + if wordlist[-1] == "$(CIRCUITPY_FULL_BUILD)": + fullbuild.append(wordlist[0]) + elif wordlist[-1] == "0": + defoff.append(wordlist[0]) + elif wordlist[-1] == "1": + defon.append(wordlist[0]) + line = fp.readline() + cnt += 1 + + print(str(cnt) + " Lines Read\n") + print("\nFULL BUILDS ------------------------") + for string in fullbuild: + print(string) + + print("\nON BUILDS ------------------------") + for string in defon: + print(string) + + print("\nOFF BUILDS ------------------------") + for string in defoff: + print(string) From 553ac576ebd59941965ef7615fdb15bd2bdc347e Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Wed, 26 Aug 2020 17:48:29 -0400 Subject: [PATCH 69/79] Disable ulab --- ports/esp32s2/mpconfigport.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ports/esp32s2/mpconfigport.mk b/ports/esp32s2/mpconfigport.mk index 3ddcf5d613..b7cd635044 100644 --- a/ports/esp32s2/mpconfigport.mk +++ b/ports/esp32s2/mpconfigport.mk @@ -29,5 +29,7 @@ CIRCUITPY_COUNTIO = 0 CIRCUITPY_RANDOM = 0 # Requires USB CIRCUITPY_USB_MIDI = 0 +# Too large for the partition table! +CIRCUITPY_ULAB = 0 CIRCUITPY_MODULE ?= none From c22934574146c4468374a10916d2746f0400a8a8 Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Wed, 26 Aug 2020 18:47:19 -0400 Subject: [PATCH 70/79] improve efficiency of stm32 random gen --- ports/stm/common-hal/os/__init__.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ports/stm/common-hal/os/__init__.c b/ports/stm/common-hal/os/__init__.c index 13871a46ea..8da7243a30 100644 --- a/ports/stm/common-hal/os/__init__.c +++ b/ports/stm/common-hal/os/__init__.c @@ -72,15 +72,20 @@ bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) { if (HAL_RNG_Init(&handle) != HAL_OK) mp_raise_ValueError(translate("RNG Init Error")); //Assign bytes - for (uint i = 0; i < length; i++) { - uint32_t temp; + uint32_t i = 0; + while (i < length) { + uint32_t new_random; uint32_t start = HAL_GetTick(); //the HAL function has a timeout, but it isn't long enough, and isn't adjustable while(!(__HAL_RNG_GET_FLAG(&handle,RNG_FLAG_DRDY)) && ((HAL_GetTick() - start) < RNG_TIMEOUT)); - if (HAL_RNG_GenerateRandomNumber(&handle, &temp) != HAL_OK) { + if (HAL_RNG_GenerateRandomNumber(&handle, &new_random) != HAL_OK) { mp_raise_ValueError(translate("Random number generation error")); } - buffer[i] = (uint8_t)temp; + for (int j = 0; j < 4 && i < length; j++) { + buffer[i] = new_random & 0xff; + i++; + new_random >>= 8; + } } //shut down the peripheral From 200a296b5cf6851b72460d49fdb3be43980f2d9b Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 26 Aug 2020 20:41:25 -0500 Subject: [PATCH 71/79] conf.py (docs): Reorder the steps of the doc build Since e121e267adacf6, the shared bindings matrix uses the stubs. Therefore, we must build them! This should fix the failure to build the docs on readthedocs.org. Neither @sommersoft nor I saw this locally since we had previously built the stubs. github CI didn't see it, because it manually builds the stubs in an earlier step of the build process, and does not clean the tree in between. --- conf.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/conf.py b/conf.py index 4a8b72584e..256ca922c7 100644 --- a/conf.py +++ b/conf.py @@ -42,6 +42,9 @@ master_doc = 'docs/index' # Grab the JSON values to use while building the module support matrix # in 'shared-bindings/index.rst' +# The stubs must be built before we calculate the shared bindings matrix +subprocess.check_output(["make", "stubs"]) + #modules_support_matrix = shared_bindings_matrix.support_matrix_excluded_boards() modules_support_matrix = shared_bindings_matrix.support_matrix_by_board() @@ -77,7 +80,6 @@ source_suffix = { '.md': 'markdown', } -subprocess.check_output(["make", "stubs"]) extensions.append('autoapi.extension') autoapi_type = 'python' From 8021da08d3fb0a3a55ffc00f00ce9c2959ce80c8 Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Thu, 27 Aug 2020 11:07:47 -0400 Subject: [PATCH 72/79] Fix problematic whitespace on pulseout parameter errors --- ports/atmel-samd/common-hal/pulseio/PulseOut.c | 3 +-- ports/cxd56/common-hal/pulseio/PulseOut.c | 3 +-- ports/esp32s2/common-hal/pulseio/PulseOut.c | 3 +-- ports/nrf/common-hal/pulseio/PulseOut.c | 3 +-- ports/stm/common-hal/pulseio/PulseOut.c | 3 +-- 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/ports/atmel-samd/common-hal/pulseio/PulseOut.c b/ports/atmel-samd/common-hal/pulseio/PulseOut.c index 3463bb5e20..086052a973 100644 --- a/ports/atmel-samd/common-hal/pulseio/PulseOut.c +++ b/ports/atmel-samd/common-hal/pulseio/PulseOut.c @@ -101,8 +101,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, 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")); + mp_raise_NotImplementedError(translate("Port does not accept pins or frequency. Construct and pass a PWMOut Carrier instead")); } if (refcount == 0) { diff --git a/ports/cxd56/common-hal/pulseio/PulseOut.c b/ports/cxd56/common-hal/pulseio/PulseOut.c index 764a5860a9..f08e7cd7a0 100644 --- a/ports/cxd56/common-hal/pulseio/PulseOut.c +++ b/ports/cxd56/common-hal/pulseio/PulseOut.c @@ -64,8 +64,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, 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")); + mp_raise_NotImplementedError(translate("Port does not accept pins or frequency. Construct and pass a PWMOut Carrier instead")); } if (pulse_fd < 0) { diff --git a/ports/esp32s2/common-hal/pulseio/PulseOut.c b/ports/esp32s2/common-hal/pulseio/PulseOut.c index cfe750732b..e45492a893 100644 --- a/ports/esp32s2/common-hal/pulseio/PulseOut.c +++ b/ports/esp32s2/common-hal/pulseio/PulseOut.c @@ -37,8 +37,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, uint32_t frequency, uint16_t duty_cycle) { if (carrier || !pin || !frequency) { - mp_raise_NotImplementedError(translate("Port does not accept PWM carrier. \ - Pass a pin, frequency and duty cycle instead")); + mp_raise_NotImplementedError(translate("Port does not accept PWM carrier. Pass a pin, frequency and duty cycle instead")); } rmt_channel_t channel = esp32s2_peripherals_find_and_reserve_rmt(); diff --git a/ports/nrf/common-hal/pulseio/PulseOut.c b/ports/nrf/common-hal/pulseio/PulseOut.c index 9f301a7306..f40dbea5c8 100644 --- a/ports/nrf/common-hal/pulseio/PulseOut.c +++ b/ports/nrf/common-hal/pulseio/PulseOut.c @@ -105,8 +105,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, 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")); + mp_raise_NotImplementedError(translate("Port does not accept pins or frequency. Construct and pass a PWMOut Carrier instead")); } if (refcount == 0) { diff --git a/ports/stm/common-hal/pulseio/PulseOut.c b/ports/stm/common-hal/pulseio/PulseOut.c index 3bf23ad14b..963aee721a 100644 --- a/ports/stm/common-hal/pulseio/PulseOut.c +++ b/ports/stm/common-hal/pulseio/PulseOut.c @@ -118,8 +118,7 @@ void common_hal_pulseio_pulseout_construct(pulseio_pulseout_obj_t* self, 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")); + mp_raise_NotImplementedError(translate("Port does not accept pins or frequency. Construct and pass a PWMOut Carrier instead")); } // Add to active PulseOuts From e2559efb9374af54ac10d30c2178a10d99352c16 Mon Sep 17 00:00:00 2001 From: Lucian Copeland Date: Thu, 27 Aug 2020 11:21:39 -0400 Subject: [PATCH 73/79] translations --- locale/circuitpython.pot | 52 +++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index fe726acf27..108bcb381c 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-08-21 21:39-0500\n" +"POT-Creation-Date: 2020-08-27 11:21-0400\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -302,7 +302,7 @@ msgstr "" msgid "All sync event channels in use" msgstr "" -#: shared-bindings/pulseio/PWMOut.c +#: shared-bindings/pwmio/PWMOut.c msgid "All timers for this pin are in use" msgstr "" @@ -314,7 +314,7 @@ msgstr "" #: ports/cxd56/common-hal/pulseio/PulseOut.c #: ports/nrf/common-hal/audiopwmio/PWMAudioOut.c #: ports/nrf/common-hal/pulseio/PulseIn.c ports/nrf/peripherals/nrf/timers.c -#: ports/stm/peripherals/timers.c shared-bindings/pulseio/PWMOut.c +#: ports/stm/peripherals/timers.c shared-bindings/pwmio/PWMOut.c msgid "All timers in use" msgstr "" @@ -552,7 +552,7 @@ msgstr "" msgid "Cannot unambiguously get sizeof scalar" msgstr "" -#: ports/stm/common-hal/pulseio/PWMOut.c +#: ports/stm/common-hal/pwmio/PWMOut.c msgid "Cannot vary frequency on a timer that is already in use" msgstr "" @@ -621,23 +621,23 @@ msgstr "" msgid "Could not initialize UART" msgstr "" -#: ports/stm/common-hal/pulseio/PWMOut.c +#: ports/stm/common-hal/pwmio/PWMOut.c msgid "Could not initialize channel" msgstr "" -#: ports/stm/common-hal/pulseio/PWMOut.c +#: ports/stm/common-hal/pwmio/PWMOut.c msgid "Could not initialize timer" msgstr "" -#: ports/stm/common-hal/pulseio/PWMOut.c +#: ports/stm/common-hal/pwmio/PWMOut.c msgid "Could not re-init channel" msgstr "" -#: ports/stm/common-hal/pulseio/PWMOut.c +#: ports/stm/common-hal/pwmio/PWMOut.c msgid "Could not re-init timer" msgstr "" -#: ports/stm/common-hal/pulseio/PWMOut.c +#: ports/stm/common-hal/pwmio/PWMOut.c msgid "Could not restart PWM" msgstr "" @@ -645,7 +645,7 @@ msgstr "" msgid "Could not set address" msgstr "" -#: ports/stm/common-hal/pulseio/PWMOut.c +#: ports/stm/common-hal/pwmio/PWMOut.c msgid "Could not start PWM" msgstr "" @@ -836,7 +836,7 @@ msgstr "" msgid "Frequency captured is above capability. Capture Paused." msgstr "" -#: ports/stm/common-hal/pulseio/PWMOut.c +#: ports/stm/common-hal/pwmio/PWMOut.c msgid "Frequency must match existing PWMOut using this timer" msgstr "" @@ -938,9 +938,9 @@ msgstr "" msgid "Invalid DAC pin supplied" msgstr "" -#: ports/atmel-samd/common-hal/pulseio/PWMOut.c -#: ports/cxd56/common-hal/pulseio/PWMOut.c -#: ports/nrf/common-hal/pulseio/PWMOut.c shared-bindings/pulseio/PWMOut.c +#: ports/atmel-samd/common-hal/pwmio/PWMOut.c +#: ports/cxd56/common-hal/pwmio/PWMOut.c ports/nrf/common-hal/pwmio/PWMOut.c +#: shared-bindings/pwmio/PWMOut.c msgid "Invalid PWM frequency" msgstr "" @@ -980,7 +980,7 @@ msgstr "" msgid "Invalid format chunk size" msgstr "" -#: ports/stm/common-hal/pulseio/PWMOut.c +#: ports/stm/common-hal/pwmio/PWMOut.c msgid "Invalid frequency supplied" msgstr "" @@ -998,8 +998,8 @@ msgid "Invalid phase" msgstr "" #: ports/atmel-samd/common-hal/audioio/AudioOut.c -#: ports/atmel-samd/common-hal/touchio/TouchIn.c -#: shared-bindings/pulseio/PWMOut.c shared-module/rgbmatrix/RGBMatrix.c +#: ports/atmel-samd/common-hal/touchio/TouchIn.c shared-bindings/pwmio/PWMOut.c +#: shared-module/rgbmatrix/RGBMatrix.c msgid "Invalid pin" msgstr "" @@ -1023,7 +1023,7 @@ msgstr "" msgid "Invalid pins" msgstr "" -#: ports/stm/common-hal/pulseio/PWMOut.c +#: ports/stm/common-hal/pwmio/PWMOut.c msgid "Invalid pins for PWMOut" msgstr "" @@ -1205,7 +1205,7 @@ msgstr "" msgid "No long integer support" msgstr "" -#: ports/stm/common-hal/pulseio/PWMOut.c +#: ports/stm/common-hal/pwmio/PWMOut.c msgid "No more timers available on this pin." msgstr "" @@ -1273,12 +1273,12 @@ msgstr "" msgid "Oversample must be multiple of 8." msgstr "" -#: shared-bindings/pulseio/PWMOut.c +#: shared-bindings/pwmio/PWMOut.c msgid "" "PWM duty_cycle must be between 0 and 65535 inclusive (16 bit resolution)" msgstr "" -#: shared-bindings/pulseio/PWMOut.c +#: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." msgstr "" @@ -1333,8 +1333,8 @@ msgstr "" #: ports/nrf/common-hal/pulseio/PulseOut.c #: ports/stm/common-hal/pulseio/PulseOut.c msgid "" -"Port does not accept pins or frequency. " -"Construct and pass a PWMOut Carrier instead" +"Port does not accept pins or frequency. Construct and pass a PWMOut Carrier " +"instead" msgstr "" #: shared-bindings/_bleio/Adapter.c @@ -1349,6 +1349,10 @@ msgstr "" msgid "Pull not used when direction is output." msgstr "" +#: ports/stm/ref/pulseout-pre-timeralloc.c +msgid "PulseOut not supported on this chip" +msgstr "" + #: ports/stm/common-hal/os/__init__.c msgid "RNG DeInit Error" msgstr "" @@ -1560,7 +1564,7 @@ msgstr "" msgid "Timeout is too long: Maximum timeout length is %d seconds" msgstr "" -#: ports/stm/common-hal/pulseio/PWMOut.c +#: ports/stm/common-hal/pwmio/PWMOut.c msgid "" "Timer was reserved for internal use - declare PWM pins earlier in the program" msgstr "" From a03b6a99e60c8c428d95bc78b1ee6948607f69c6 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 27 Aug 2020 15:10:52 -0500 Subject: [PATCH 74/79] gen_usb_descriptor: Fix off-by-1 error in endpoint counting --- tools/gen_usb_descriptor.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/gen_usb_descriptor.py b/tools/gen_usb_descriptor.py index baee8cad7b..adf0d8270d 100644 --- a/tools/gen_usb_descriptor.py +++ b/tools/gen_usb_descriptor.py @@ -382,8 +382,9 @@ if args.max_ep != 0: for interface in interfaces: for subdescriptor in interface.subdescriptors: endpoint_address = getattr(subdescriptor, 'bEndpointAddress', 0) & 0x7f - if endpoint_address > args.max_ep: - raise ValueError("Endpoint address %d of %s may not exceed %d" % (endpoint_address & 0x7f, interface.description, args.max_ep)) + print("Endpoint %d - vs max_ep %d" % (endpoint_address, args.max_ep)) + if endpoint_address >= args.max_ep: + raise ValueError("Endpoint address %d of %s must be less than %d" % (endpoint_address & 0x7f, interface.description, args.max_ep)) else: print("Unable to check whether maximum number of endpoints is respected", file=sys.stderr) From 563e038c0d210dd0d17f6dc65f2c9eb5bbff1892 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Thu, 27 Aug 2020 15:11:17 -0500 Subject: [PATCH 75/79] stm: Specify max endpoints for stm32f405xx .. which is why we can't have HID or MIDI on the stm32f405 feather --- ports/stm/mpconfigport.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/stm/mpconfigport.mk b/ports/stm/mpconfigport.mk index 19f9ffa44c..b827aa48b9 100644 --- a/ports/stm/mpconfigport.mk +++ b/ports/stm/mpconfigport.mk @@ -7,6 +7,7 @@ ifeq ($(MCU_VARIANT),STM32F405xx) CIRCUITPY_FRAMEBUFFERIO ?= 1 CIRCUITPY_RGBMATRIX ?= 1 CIRCUITPY_SDIOIO ?= 1 + USB_NUM_EP = 4 endif ifeq ($(MCU_SERIES),F4) From a09243472cf4e57d9c157ecd4c55416a42fb7081 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 28 Aug 2020 16:08:24 -0700 Subject: [PATCH 76/79] Add Kaluga board definition --- .github/workflows/build.yml | 1 + .../esp32s2/boards/espressif_kaluga_1/board.c | 47 +++++++++++++ .../boards/espressif_kaluga_1/mpconfigboard.h | 34 ++++++++++ .../espressif_kaluga_1/mpconfigboard.mk | 17 +++++ .../esp32s2/boards/espressif_kaluga_1/pins.c | 66 +++++++++++++++++++ .../boards/espressif_kaluga_1/sdkconfig | 33 ++++++++++ 6 files changed, 198 insertions(+) create mode 100644 ports/esp32s2/boards/espressif_kaluga_1/board.c create mode 100644 ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h create mode 100644 ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.mk create mode 100644 ports/esp32s2/boards/espressif_kaluga_1/pins.c create mode 100644 ports/esp32s2/boards/espressif_kaluga_1/sdkconfig diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a8528168ac..e780f652ab 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -409,6 +409,7 @@ jobs: matrix: board: - "electroniccats_bastwifi" + - "espressif_kaluga_1" - "espressif_saola_1_wroom" - "espressif_saola_1_wrover" - "microdev_micro_s2" diff --git a/ports/esp32s2/boards/espressif_kaluga_1/board.c b/ports/esp32s2/boards/espressif_kaluga_1/board.c new file mode 100644 index 0000000000..9f708874bf --- /dev/null +++ b/ports/esp32s2/boards/espressif_kaluga_1/board.c @@ -0,0 +1,47 @@ +/* + * 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 "boards/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 + common_hal_never_reset_pin(&pin_GPIO43); + common_hal_never_reset_pin(&pin_GPIO44); +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { + +} diff --git a/ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h b/ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h new file mode 100644 index 0000000000..84d15ffc2b --- /dev/null +++ b/ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h @@ -0,0 +1,34 @@ +/* + * 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 "Kaluga 1" +#define MICROPY_HW_MCU_NAME "ESP32S2" + +#define MICROPY_HW_NEOPIXEL (&pin_GPIO45) + +#define AUTORESET_DELAY_MS 500 diff --git a/ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.mk b/ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.mk new file mode 100644 index 0000000000..43b1a9a688 --- /dev/null +++ b/ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.mk @@ -0,0 +1,17 @@ +USB_VID = 0x239A +USB_PID = 0x80A6 +USB_PRODUCT = "Kaluga 1" +USB_MANUFACTURER = "Espressif" + +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=dio +CIRCUITPY_ESP_FLASH_FREQ=40m +CIRCUITPY_ESP_FLASH_SIZE=4MB + +CIRCUITPY_MODULE=wrover diff --git a/ports/esp32s2/boards/espressif_kaluga_1/pins.c b/ports/esp32s2/boards/espressif_kaluga_1/pins.c new file mode 100644 index 0000000000..b0e9957a1d --- /dev/null +++ b/ports/esp32s2/boards/espressif_kaluga_1/pins.c @@ -0,0 +1,66 @@ +#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_IO15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) }, + { 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_IO19), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_IO20), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_IO26), MP_ROM_PTR(&pin_GPIO26) }, + { 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_IO39), MP_ROM_PTR(&pin_GPIO39) }, + { MP_ROM_QSTR(MP_QSTR_IO40), MP_ROM_PTR(&pin_GPIO40) }, + { MP_ROM_QSTR(MP_QSTR_IO41), MP_ROM_PTR(&pin_GPIO41) }, + { MP_ROM_QSTR(MP_QSTR_IO42), MP_ROM_PTR(&pin_GPIO42) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_IO43), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) }, + { MP_ROM_QSTR(MP_QSTR_IO44), MP_ROM_PTR(&pin_GPIO44) }, + { MP_ROM_QSTR(MP_QSTR_IO45), MP_ROM_PTR(&pin_GPIO45) }, + { MP_ROM_QSTR(MP_QSTR_IO46), MP_ROM_PTR(&pin_GPIO46) }, + + + { MP_ROM_QSTR(MP_QSTR_CAMERA_XCLK), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_PCLK), MP_ROM_PTR(&pin_GPIO33) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_HREF), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_VSYNC), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_SIOD), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_SIOC), MP_ROM_PTR(&pin_GPIO7) }, + + + { MP_ROM_QSTR(MP_QSTR_CAMERA_D2), MP_ROM_PTR(&pin_GPIO46) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_D3), MP_ROM_PTR(&pin_GPIO45) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_D4), MP_ROM_PTR(&pin_GPIO41) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_D5), MP_ROM_PTR(&pin_GPIO42) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_D6), MP_ROM_PTR(&pin_GPIO39) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_D7), MP_ROM_PTR(&pin_GPIO40) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_D8), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_D9), MP_ROM_PTR(&pin_GPIO38) }, + + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO45) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); diff --git a/ports/esp32s2/boards/espressif_kaluga_1/sdkconfig b/ports/esp32s2/boards/espressif_kaluga_1/sdkconfig new file mode 100644 index 0000000000..9d8bbde967 --- /dev/null +++ b/ports/esp32s2/boards/espressif_kaluga_1/sdkconfig @@ -0,0 +1,33 @@ +CONFIG_ESP32S2_SPIRAM_SUPPORT=y + +# +# SPI RAM config +# +# CONFIG_SPIRAM_TYPE_AUTO is not set +CONFIG_SPIRAM_TYPE_ESPPSRAM16=y +# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set +# CONFIG_SPIRAM_TYPE_ESPPSRAM64 is not set +CONFIG_SPIRAM_SIZE=2097152 + +# +# 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 From 81870413af5efc35beb31449a099fb69ba05e15c Mon Sep 17 00:00:00 2001 From: lady ada Date: Fri, 28 Aug 2020 19:08:36 -0400 Subject: [PATCH 77/79] add default I2C --- ports/atmel-samd/boards/blm_badge/pins.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ports/atmel-samd/boards/blm_badge/pins.c b/ports/atmel-samd/boards/blm_badge/pins.c index af1b693584..6e7d8da754 100644 --- a/ports/atmel-samd/boards/blm_badge/pins.c +++ b/ports/atmel-samd/boards/blm_badge/pins.c @@ -39,5 +39,7 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_L), MP_ROM_PTR(&pin_PA03) }, { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA03) }, + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table); From 0bb5c6c07fdb0ce4100cd4b8a9465ad9f4d090ff Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 28 Aug 2020 16:37:25 -0700 Subject: [PATCH 78/79] Add unique USB PID --- ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.mk b/ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.mk index 43b1a9a688..ba85e46efc 100644 --- a/ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.mk +++ b/ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.mk @@ -1,5 +1,5 @@ USB_VID = 0x239A -USB_PID = 0x80A6 +USB_PID = 0x80C8 USB_PRODUCT = "Kaluga 1" USB_MANUFACTURER = "Espressif" From 7b59ede25e4bba09e2b104c2404399bbf0af7fb6 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 28 Aug 2020 18:22:22 -0700 Subject: [PATCH 79/79] Add remaining pins --- .../esp32s2/boards/espressif_kaluga_1/pins.c | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/ports/esp32s2/boards/espressif_kaluga_1/pins.c b/ports/esp32s2/boards/espressif_kaluga_1/pins.c index b0e9957a1d..c1657d6c0e 100644 --- a/ports/esp32s2/boards/espressif_kaluga_1/pins.c +++ b/ports/esp32s2/boards/espressif_kaluga_1/pins.c @@ -44,6 +44,8 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_IO46), MP_ROM_PTR(&pin_GPIO46) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO45) }, + { MP_ROM_QSTR(MP_QSTR_CAMERA_XCLK), MP_ROM_PTR(&pin_GPIO1) }, { MP_ROM_QSTR(MP_QSTR_CAMERA_PCLK), MP_ROM_PTR(&pin_GPIO33) }, { MP_ROM_QSTR(MP_QSTR_CAMERA_HREF), MP_ROM_PTR(&pin_GPIO3) }, @@ -61,6 +63,63 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_CAMERA_D8), MP_ROM_PTR(&pin_GPIO21) }, { MP_ROM_QSTR(MP_QSTR_CAMERA_D9), MP_ROM_PTR(&pin_GPIO38) }, - { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO45) }, + + { MP_ROM_QSTR(MP_QSTR_TOUCH1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_TOUCH2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_TOUCH3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_TOUCH4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_TOUCH5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_TOUCH6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_TOUCH7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_TOUCH8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_TOUCH9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_TOUCH10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_TOUCH11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_TOUCH12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_TOUCH13), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_TOUCH14), MP_ROM_PTR(&pin_GPIO14) }, + + // LED FPC + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_BT_ARRAY_ADC), MP_ROM_PTR(&pin_GPIO6) }, + + // 3.2 inch LCD FPC + { MP_ROM_QSTR(MP_QSTR_LCD_TP_MISO), MP_ROM_PTR(&pin_GPIO42) }, + { MP_ROM_QSTR(MP_QSTR_LCD_TP_MOSI), MP_ROM_PTR(&pin_GPIO40) }, + { MP_ROM_QSTR(MP_QSTR_LCD_TP_SCK), MP_ROM_PTR(&pin_GPIO38) }, + { MP_ROM_QSTR(MP_QSTR_LCD_TP_CS), MP_ROM_PTR(&pin_GPIO33) }, + { MP_ROM_QSTR(MP_QSTR_LCD_TP_IRQ), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_LCD_TP_BUSY), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_LCD_BL_CTR), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_LCD_MISO), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_LCD_MOSI), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_LCD_CS), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D_C), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_LCD_CLK), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_LCD_RST), MP_ROM_PTR(&pin_GPIO16) }, + + // Audio + { MP_ROM_QSTR(MP_QSTR_AUDIO_SPI_MISO), MP_ROM_PTR(&pin_GPIO42) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_SPI_MOSI), MP_ROM_PTR(&pin_GPIO40) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_SPI_SCK), MP_ROM_PTR(&pin_GPIO38) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_SPI_CS), MP_ROM_PTR(&pin_GPIO33) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_BT_ADC), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_SCL), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_SDA), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_I2S0_MCLK), MP_ROM_PTR(&pin_GPIO41) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_I2S0_BCLK), MP_ROM_PTR(&pin_GPIO39) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_I2S0_LRCK), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_I2S0_SDI), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_I2S0_SDO), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_RST), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_WAKE_INT), MP_ROM_PTR(&pin_GPIO34) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_I2S1_MCLK), MP_ROM_PTR(&pin_GPIO35) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_PA_CTRL), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_I2S1_SDI), MP_ROM_PTR(&pin_GPIO46) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_I2S1_SDO), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_I2S1_LRCK_DAC1), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_I2S1_BCLK_DAC2), MP_ROM_PTR(&pin_GPIO18) }, + }; MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);