From 1fe7d2956c73dba39333d2b3248e9cf7f89d5eb2 Mon Sep 17 00:00:00 2001 From: flom84 Date: Tue, 22 Nov 2022 21:17:04 +0100 Subject: [PATCH 001/117] Enable uart over FTDI by default. --- ports/stm/boards/nucleo_f446re/mpconfigboard.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/stm/boards/nucleo_f446re/mpconfigboard.h b/ports/stm/boards/nucleo_f446re/mpconfigboard.h index f0155f4624..c1d61492e4 100644 --- a/ports/stm/boards/nucleo_f446re/mpconfigboard.h +++ b/ports/stm/boards/nucleo_f446re/mpconfigboard.h @@ -44,8 +44,8 @@ // #define CIRCUITPY_CONSOLE_UART_RX (&pin_PC11) // USART2 + ST link -// #define CIRCUITPY_CONSOLE_UART_TX (&pin_PA02) -// #define CIRCUITPY_CONSOLE_UART_RX (&pin_PA03) +#define CIRCUITPY_CONSOLE_UART_TX (&pin_PA02) +#define CIRCUITPY_CONSOLE_UART_RX (&pin_PA03) // Status LEDs #define MICROPY_HW_LED_STATUS (&pin_PA05) From a84a8855ed2deff2b20ef5cfd11bbdef862fc239 Mon Sep 17 00:00:00 2001 From: Colin B Date: Sat, 7 Jan 2023 16:17:51 -0800 Subject: [PATCH 002/117] Add frequency setting for RP2040 boards. --- ports/raspberrypi/Makefile | 1 + .../common-hal/microcontroller/Processor.c | 12 ++++++++++++ ports/raspberrypi/mpconfigport.mk | 1 + shared-bindings/microcontroller/Processor.c | 2 +- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ports/raspberrypi/Makefile b/ports/raspberrypi/Makefile index d72d59bcf6..395a5553e2 100644 --- a/ports/raspberrypi/Makefile +++ b/ports/raspberrypi/Makefile @@ -229,6 +229,7 @@ SRC_SDK := \ src/rp2_common/pico_printf/printf.c \ src/rp2_common/pico_runtime/runtime.c \ src/rp2_common/pico_stdio/stdio.c \ + src/rp2_common/pico_stdlib/stdlib.c \ src/rp2_common/pico_unique_id/unique_id.c \ $(SRC_SDK_CYW43) \ diff --git a/ports/raspberrypi/common-hal/microcontroller/Processor.c b/ports/raspberrypi/common-hal/microcontroller/Processor.c index 8c5bc7ba75..08e6495d26 100644 --- a/ports/raspberrypi/common-hal/microcontroller/Processor.c +++ b/ports/raspberrypi/common-hal/microcontroller/Processor.c @@ -28,10 +28,12 @@ #include #include "py/mphal.h" +#include "py/runtime.h" #include "common-hal/microcontroller/Processor.h" #include "shared-bindings/microcontroller/Processor.h" #include "shared-bindings/microcontroller/ResetReason.h" +#include "pico/stdlib.h" #include "src/rp2_common/hardware_adc/include/hardware/adc.h" #include "src/rp2_common/hardware_clocks/include/hardware/clocks.h" @@ -59,6 +61,16 @@ uint32_t common_hal_mcu_processor_get_frequency(void) { return clock_get_hz(clk_sys); } +uint32_t common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, + uint32_t frequency) { + uint32_t freq = frequency / 1000; + + if (!set_sys_clock_khz(freq, false)) { + mp_raise_ValueError(translate("Invalid frequency supplied")); + } + return clock_get_hz(clk_sys); +} + void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { pico_unique_board_id_t retrieved_id; pico_get_unique_board_id(&retrieved_id); diff --git a/ports/raspberrypi/mpconfigport.mk b/ports/raspberrypi/mpconfigport.mk index c5de2a439d..7a6b9f2167 100644 --- a/ports/raspberrypi/mpconfigport.mk +++ b/ports/raspberrypi/mpconfigport.mk @@ -48,3 +48,4 @@ CIRCUITPY_BUILD_EXTENSIONS ?= uf2 USB_NUM_ENDPOINT_PAIRS = 8 INTERNAL_FLASH_FILESYSTEM = 1 +CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY = 1 diff --git a/shared-bindings/microcontroller/Processor.c b/shared-bindings/microcontroller/Processor.c index 986f81ea53..f5190d36ef 100644 --- a/shared-bindings/microcontroller/Processor.c +++ b/shared-bindings/microcontroller/Processor.c @@ -67,7 +67,7 @@ //| frequency: int //| """The CPU operating frequency in Hertz. //| -//| **Limitations:** Setting the ``frequency`` is possible only on some i.MX boards. +//| **Limitations:** Setting the ``frequency`` is possible on RP2040 boards and some i.MX boards. //| On most boards, ``frequency`` is read-only. //| """ From bfba1e4100d88999d5c6a211413fc8215c319164 Mon Sep 17 00:00:00 2001 From: Colin B Date: Mon, 16 Jan 2023 20:39:20 -0800 Subject: [PATCH 003/117] Change common_hal_mcu_processor_set_frequency to void * Add warning about setting RP2040 frequency --- .../mimxrt10xx/common-hal/microcontroller/Processor.c | 4 +--- .../raspberrypi/common-hal/microcontroller/Processor.c | 10 +++------- shared-bindings/microcontroller/Processor.c | 7 +++++-- shared-bindings/microcontroller/Processor.h | 2 +- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/ports/mimxrt10xx/common-hal/microcontroller/Processor.c b/ports/mimxrt10xx/common-hal/microcontroller/Processor.c index 17ced78910..34400e3f41 100644 --- a/ports/mimxrt10xx/common-hal/microcontroller/Processor.c +++ b/ports/mimxrt10xx/common-hal/microcontroller/Processor.c @@ -52,15 +52,13 @@ float common_hal_mcu_processor_get_temperature(void) { return temp; } -uint32_t common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, +void common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, uint32_t frequency) { uint32_t freq = frequency / 1000000; if (freq != 24 && freq != 150 && freq != 396 && freq != 450 && freq != 528 && freq != 600 && freq != 720 && freq != 816 && freq != 912 && freq != 960 && freq != 1008) { mp_raise_ValueError(translate("Frequency must be 24, 150, 396, 450, 528, 600, 720, 816, 912, 960 or 1008 Mhz")); } - SystemCoreClock = setarmclock(frequency); - return SystemCoreClock; } diff --git a/ports/raspberrypi/common-hal/microcontroller/Processor.c b/ports/raspberrypi/common-hal/microcontroller/Processor.c index 08e6495d26..66083a357d 100644 --- a/ports/raspberrypi/common-hal/microcontroller/Processor.c +++ b/ports/raspberrypi/common-hal/microcontroller/Processor.c @@ -61,14 +61,10 @@ uint32_t common_hal_mcu_processor_get_frequency(void) { return clock_get_hz(clk_sys); } -uint32_t common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, - uint32_t frequency) { - uint32_t freq = frequency / 1000; - - if (!set_sys_clock_khz(freq, false)) { - mp_raise_ValueError(translate("Invalid frequency supplied")); +void common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, uint32_t frequency) { + if (!set_sys_clock_khz(frequency / 1000, false)) { + mp_arg_error_invalid(MP_QSTR_frequency); } - return clock_get_hz(clk_sys); } void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { diff --git a/shared-bindings/microcontroller/Processor.c b/shared-bindings/microcontroller/Processor.c index f5190d36ef..6ae0212a6a 100644 --- a/shared-bindings/microcontroller/Processor.c +++ b/shared-bindings/microcontroller/Processor.c @@ -67,8 +67,11 @@ //| frequency: int //| """The CPU operating frequency in Hertz. //| -//| **Limitations:** Setting the ``frequency`` is possible on RP2040 boards and some i.MX boards. -//| On most boards, ``frequency`` is read-only. +//| **Limitations:** On most boards, ``frequency`` is read-only. Setting +//| the ``frequency`` is possible on RP2040 boards and some i.MX boards. +//| +//| .. warning:: On RP2040 boards changing the frequency may cause issues +//| with other subsystems, such as USB, PWM, and PIO. //| """ #if CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY diff --git a/shared-bindings/microcontroller/Processor.h b/shared-bindings/microcontroller/Processor.h index 9a2f22b245..473f25cbc6 100644 --- a/shared-bindings/microcontroller/Processor.h +++ b/shared-bindings/microcontroller/Processor.h @@ -39,6 +39,6 @@ mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void); float common_hal_mcu_processor_get_temperature(void); void common_hal_mcu_processor_get_uid(uint8_t raw_id[]); float common_hal_mcu_processor_get_voltage(void); -uint32_t common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, uint32_t frequency); +void common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, uint32_t frequency); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_MICROCONTROLLER_PROCESSOR_H From 659e5b4bedc11f90a9792ee7310657bbd1d28e05 Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Fri, 24 Mar 2023 12:29:51 +0100 Subject: [PATCH 004/117] support for Pimoroni Badger2040W --- .gitmodules | 3 + frozen/circuitpython-pcf85063a | 1 + .../pimoroni_badger2040w/badger-shared.h | 8 + .../boards/pimoroni_badger2040w/board.c | 341 ++++++++++++++++++ .../boards/pimoroni_badger2040w/link.ld | 294 +++++++++++++++ .../pimoroni_badger2040w/mpconfigboard.h | 18 + .../pimoroni_badger2040w/mpconfigboard.mk | 27 ++ .../pico-sdk-configboard.h | 1 + .../boards/pimoroni_badger2040w/pins.c | 68 ++++ 9 files changed, 761 insertions(+) create mode 160000 frozen/circuitpython-pcf85063a create mode 100644 ports/raspberrypi/boards/pimoroni_badger2040w/badger-shared.h create mode 100644 ports/raspberrypi/boards/pimoroni_badger2040w/board.c create mode 100644 ports/raspberrypi/boards/pimoroni_badger2040w/link.ld create mode 100644 ports/raspberrypi/boards/pimoroni_badger2040w/mpconfigboard.h create mode 100644 ports/raspberrypi/boards/pimoroni_badger2040w/mpconfigboard.mk create mode 100644 ports/raspberrypi/boards/pimoroni_badger2040w/pico-sdk-configboard.h create mode 100644 ports/raspberrypi/boards/pimoroni_badger2040w/pins.c diff --git a/.gitmodules b/.gitmodules index 9c8d3b4b68..e2e90243a4 100644 --- a/.gitmodules +++ b/.gitmodules @@ -324,3 +324,6 @@ path = ports/broadcom/peripherals url = https://github.com/adafruit/broadcom-peripherals.git branch = main-build +[submodule "frozen/circuitpython-pcf85063a"] + path = frozen/circuitpython-pcf85063a + url = https://github.com/bablokb/circuitpython-pcf85063a diff --git a/frozen/circuitpython-pcf85063a b/frozen/circuitpython-pcf85063a new file mode 160000 index 0000000000..21baeb6479 --- /dev/null +++ b/frozen/circuitpython-pcf85063a @@ -0,0 +1 @@ +Subproject commit 21baeb6479434b950e9356a320a5a4d050a4bf47 diff --git a/ports/raspberrypi/boards/pimoroni_badger2040w/badger-shared.h b/ports/raspberrypi/boards/pimoroni_badger2040w/badger-shared.h new file mode 100644 index 0000000000..5a64e9e00b --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_badger2040w/badger-shared.h @@ -0,0 +1,8 @@ +#ifndef PIMORONI_BADGER2040W_SHARED +#define PIMORONI_BADGER2040W_SHARED + +#include "shared-bindings/digitalio/DigitalInOut.h" + +extern digitalio_digitalinout_obj_t enable_pin_obj; + +#endif // PIMORONI_BADGER2040W_SHARED diff --git a/ports/raspberrypi/boards/pimoroni_badger2040w/board.c b/ports/raspberrypi/boards/pimoroni_badger2040w/board.c new file mode 100644 index 0000000000..9eea472925 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_badger2040w/board.c @@ -0,0 +1,341 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" + +#include "mpconfigboard.h" +#include "shared-bindings/busio/SPI.h" +#include "shared-bindings/displayio/FourWire.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-module/displayio/__init__.h" +#include "supervisor/shared/board.h" +#include "badger-shared.h" + +digitalio_digitalinout_obj_t enable_pin_obj; + +#define DELAY 0x80 + +enum reg { + PSR = 0x00, + PWR = 0x01, + POF = 0x02, + PFS = 0x03, + PON = 0x04, + PMES = 0x05, + BTST = 0x06, + DSLP = 0x07, + DTM1 = 0x10, + DSP = 0x11, + DRF = 0x12, + DTM2 = 0x13, + LUT_VCOM = 0x20, + LUT_WW = 0x21, + LUT_BW = 0x22, + LUT_WB = 0x23, + LUT_BB = 0x24, + PLL = 0x30, + TSC = 0x40, + TSE = 0x41, + TSR = 0x43, + TSW = 0x42, + CDI = 0x50, + LPD = 0x51, + TCON = 0x60, + TRES = 0x61, + REV = 0x70, + FLG = 0x71, + AMV = 0x80, + VV = 0x81, + VDCS = 0x82, + PTL = 0x90, + PTIN = 0x91, + PTOU = 0x92, + PGM = 0xa0, + APG = 0xa1, + ROTP = 0xa2, + CCSET = 0xe0, + PWS = 0xe3, + TSSET = 0xe5 +}; + +enum PSR_FLAGS { + RES_96x230 = 0b00000000, + RES_96x252 = 0b01000000, + RES_128x296 = 0b10000000, + RES_160x296 = 0b11000000, + + LUT_OTP = 0b00000000, + LUT_REG = 0b00100000, + + FORMAT_BWR = 0b00000000, + FORMAT_BW = 0b00010000, + + SCAN_DOWN = 0b00000000, + SCAN_UP = 0b00001000, + + SHIFT_LEFT = 0b00000000, + SHIFT_RIGHT = 0b00000100, + + BOOSTER_OFF = 0b00000000, + BOOSTER_ON = 0b00000010, + + RESET_SOFT = 0b00000000, + RESET_NONE = 0b00000001 +}; + +enum PWR_FLAGS_1 { + VDS_EXTERNAL = 0b00000000, + VDS_INTERNAL = 0b00000010, + + VDG_EXTERNAL = 0b00000000, + VDG_INTERNAL = 0b00000001 +}; + +enum PWR_FLAGS_2 { + VCOM_VD = 0b00000000, + VCOM_VG = 0b00000100, + + VGHL_16V = 0b00000000, + VGHL_15V = 0b00000001, + VGHL_14V = 0b00000010, + VGHL_13V = 0b00000011 +}; + +enum BOOSTER_FLAGS { + START_10MS = 0b00000000, + START_20MS = 0b01000000, + START_30MS = 0b10000000, + START_40MS = 0b11000000, + + STRENGTH_1 = 0b00000000, + STRENGTH_2 = 0b00001000, + STRENGTH_3 = 0b00010000, + STRENGTH_4 = 0b00011000, + STRENGTH_5 = 0b00100000, + STRENGTH_6 = 0b00101000, + STRENGTH_7 = 0b00110000, + STRENGTH_8 = 0b00111000, + + OFF_0_27US = 0b00000000, + OFF_0_34US = 0b00000001, + OFF_0_40US = 0b00000010, + OFF_0_54US = 0b00000011, + OFF_0_80US = 0b00000100, + OFF_1_54US = 0b00000101, + OFF_3_34US = 0b00000110, + OFF_6_58US = 0b00000111 +}; + +enum PFS_FLAGS { + FRAMES_1 = 0b00000000, + FRAMES_2 = 0b00010000, + FRAMES_3 = 0b00100000, + FRAMES_4 = 0b00110000 +}; + +enum TSE_FLAGS { + TEMP_INTERNAL = 0b00000000, + TEMP_EXTERNAL = 0b10000000, + + OFFSET_0 = 0b00000000, + OFFSET_1 = 0b00000001, + OFFSET_2 = 0b00000010, + OFFSET_3 = 0b00000011, + OFFSET_4 = 0b00000100, + OFFSET_5 = 0b00000101, + OFFSET_6 = 0b00000110, + OFFSET_7 = 0b00000111, + + OFFSET_MIN_8 = 0b00001000, + OFFSET_MIN_7 = 0b00001001, + OFFSET_MIN_6 = 0b00001010, + OFFSET_MIN_5 = 0b00001011, + OFFSET_MIN_4 = 0b00001100, + OFFSET_MIN_3 = 0b00001101, + OFFSET_MIN_2 = 0b00001110, + OFFSET_MIN_1 = 0b00001111 +}; + +enum PLL_FLAGS { + // other frequency options exist but there doesn't seem to be much + // point in including them - this is a fair range of options... + HZ_29 = 0b00111111, + HZ_33 = 0b00111110, + HZ_40 = 0b00111101, + HZ_50 = 0b00111100, + HZ_67 = 0b00111011, + HZ_100 = 0b00111010, + HZ_200 = 0b00111001 +}; + +// This is an UC8151 control chip. The display is a 2.9" grayscale EInk. +const uint8_t display_start_sequence[] = { + PWR, 5, VDS_INTERNAL | VDG_INTERNAL, VCOM_VD | VGHL_16V, 0b101011, 0b101011, 0b101011, // power setting + PON, DELAY, 200, // power on and wait 200 ms + BTST, 3, (START_10MS | STRENGTH_3 | OFF_6_58US), (START_10MS | STRENGTH_3 | OFF_6_58US), (START_10MS | STRENGTH_3 | OFF_6_58US), + PSR, 1, (RES_128x296 | LUT_REG | FORMAT_BW | SCAN_UP | SHIFT_RIGHT | BOOSTER_ON | RESET_NONE), + PFS, 1, FRAMES_1, + TSE, 1, TEMP_INTERNAL | OFFSET_0, + TCON, 1, 0x22, // tcon setting + CDI, 1, 0b01001100, // vcom and data interval + PLL, 1, HZ_100, // PLL set to 100 Hz + + // Look up tables for voltage sequence for pixel transition + // Common voltage + LUT_VCOM, 44, + 0x00, 0x16, 0x16, 0x0d, 0x00, 0x01, + 0x00, 0x23, 0x23, 0x00, 0x00, 0x02, + 0x00, 0x16, 0x16, 0x0d, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, + + // White to white + LUT_WW, 42, + 0x54, 0x16, 0x16, 0x0d, 0x00, 0x01, + 0x60, 0x23, 0x23, 0x00, 0x00, 0x02, + 0xa8, 0x16, 0x16, 0x0d, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + // Black to white + LUT_BW, 42, + 0x54, 0x16, 0x16, 0x0d, 0x00, 0x01, + 0x60, 0x23, 0x23, 0x00, 0x00, 0x02, + 0xa8, 0x16, 0x16, 0x0d, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + // White to black + LUT_WB, 42, + 0xa8, 0x16, 0x16, 0x0d, 0x00, 0x01, + 0x60, 0x23, 0x23, 0x00, 0x00, 0x02, + 0x54, 0x16, 0x16, 0x0d, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + + // Black to black + LUT_BB, 42, + 0xa8, 0x16, 0x16, 0x0d, 0x00, 0x01, + 0x60, 0x23, 0x23, 0x00, 0x00, 0x02, + 0x54, 0x16, 0x16, 0x0d, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +const uint8_t display_stop_sequence[] = { + POF, 0x00 // Power off +}; + +const uint8_t refresh_sequence[] = { + DRF, 0x00 +}; + +void board_init(void) { + // Drive the EN_3V3 pin high so the board stays awake on battery power + enable_pin_obj.base.type = &digitalio_digitalinout_type; + common_hal_digitalio_digitalinout_construct(&enable_pin_obj, &pin_GPIO10); + common_hal_digitalio_digitalinout_switch_to_output(&enable_pin_obj, true, DRIVE_MODE_PUSH_PULL); + + // Never reset + common_hal_digitalio_digitalinout_never_reset(&enable_pin_obj); + + // Set up the SPI object used to control the display + busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, &pin_GPIO16, false); + common_hal_busio_spi_never_reset(spi); + + // Set up the DisplayIO pin object + displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; + bus->base.type = &displayio_fourwire_type; + common_hal_displayio_fourwire_construct(bus, + spi, + &pin_GPIO20, // EPD_DC Command or data + &pin_GPIO17, // EPD_CS Chip select + &pin_GPIO21, // EPD_RST Reset + 1200000, // Baudrate + 0, // Polarity + 0); // Phase + + // Set up the DisplayIO epaper object + displayio_epaperdisplay_obj_t *display = &displays[0].epaper_display; + display->base.type = &displayio_epaperdisplay_type; + common_hal_displayio_epaperdisplay_construct( + display, + bus, + display_start_sequence, sizeof(display_start_sequence), + 0, // start up time + display_stop_sequence, sizeof(display_stop_sequence), + 296, // width + 128, // height + 160, // ram_width + 296, // ram_height + 0, // colstart + 0, // rowstart + 270, // rotation + NO_COMMAND, // set_column_window_command + NO_COMMAND, // set_row_window_command + NO_COMMAND, // set_current_column_command + NO_COMMAND, // set_current_row_command + DTM2, // write_black_ram_command + true, // black_bits_inverted + DTM1, // write_color_ram_command + false, // color_bits_inverted + 0x000000, // highlight_color + refresh_sequence, sizeof(refresh_sequence), // refresh_display_command + 1.0, // refresh_time + &pin_GPIO26, // busy_pin + false, // busy_state + 2.0, // seconds_per_frame + false, // always_toggle_chip_select + false, // grayscale + false, // acep + false); // two_byte_sequence_length +} + +void board_deinit(void) { + displayio_epaperdisplay_obj_t *display = &displays[0].epaper_display; + if (display->base.type == &displayio_epaperdisplay_type) { + size_t i = 0; + while (common_hal_displayio_epaperdisplay_get_busy(display)) { + RUN_BACKGROUND_TASKS; + i++; + } + } + common_hal_displayio_release_displays(); +} + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/raspberrypi/boards/pimoroni_badger2040w/link.ld b/ports/raspberrypi/boards/pimoroni_badger2040w/link.ld new file mode 100644 index 0000000000..2777b41720 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_badger2040w/link.ld @@ -0,0 +1,294 @@ +/* Based on GCC ARM embedded samples. + Defines the following symbols for use by code: + __exidx_start + __exidx_end + __etext + __data_start__ + __preinit_array_start + __preinit_array_end + __init_array_start + __init_array_end + __fini_array_start + __fini_array_end + __data_end__ + __bss_start__ + __bss_end__ + __end__ + end + __HeapLimit + __StackLimit + __StackTop + __stack (== StackTop) +*/ + +MEMORY +{ + FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 1532k + /* Followed by: 4kB of NVRAM and at least 512kB of CIRCUITPY */ + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k + SCRATCH_X (rwx) : ORIGIN = 0x20040000, LENGTH = 4k + SCRATCH_Y (rwx) : ORIGIN = 0x20041000, LENGTH = 4k +} + +ENTRY(_entry_point) + +SECTIONS +{ + /* Second stage bootloader is prepended to the image. It must be 256 bytes big + and checksummed. It is usually built by the boot_stage2 target + in the Pico SDK + */ + + .flash_begin : { + __flash_binary_start = .; + } > FLASH_FIRMWARE + + .boot2 : { + __boot2_start__ = .; + KEEP (*(.boot2)) + __boot2_end__ = .; + } > FLASH_FIRMWARE + + ASSERT(__boot2_end__ - __boot2_start__ == 256, + "ERROR: Pico second stage bootloader must be 256 bytes in size") + + /* The second stage will always enter the image at the start of .text. + The debugger will use the ELF entry point, which is the _entry_point + symbol if present, otherwise defaults to start of .text. + This can be used to transfer control back to the bootrom on debugger + launches only, to perform proper flash setup. + */ + + .text : { + __logical_binary_start = .; + KEEP (*(.vectors)) + KEEP (*(.binary_info_header)) + __binary_info_header_end = .; + KEEP (*(.reset)) + /* TODO revisit this now memset/memcpy/float in ROM */ + /* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from + * FLASH ... we will include any thing excluded here in .data below by default */ + *(.init) + + __property_getter_start = .; + *(.property_getter) + __property_getter_end = .; + __property_getset_start = .; + *(.property_getset) + __property_getset_end = .; + + *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*) + *(.fini) + /* Pull all c'tors into .text */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + /* Followed by destructors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + *(.eh_frame*) + . = ALIGN(4); + } > FLASH_FIRMWARE + + .rodata : { + *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*) + . = ALIGN(4); + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) + . = ALIGN(4); + } > FLASH_FIRMWARE + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH_FIRMWARE + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > FLASH_FIRMWARE + __exidx_end = .; + + /* Machine inspectable binary information */ + . = ALIGN(4); + __binary_info_start = .; + .binary_info : + { + KEEP(*(.binary_info.keep.*)) + *(.binary_info.*) + } > FLASH_FIRMWARE + __binary_info_end = .; + . = ALIGN(4); + + /* End of .text-like segments */ + __etext = .; + + .ram_vector_table (COPY): { + *(.ram_vector_table) + } > RAM + + .data : { + __data_start__ = .; + *(vtable) + + *(.time_critical*) + + /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */ + *(.text*) + . = ALIGN(4); + *(.rodata*) + . = ALIGN(4); + + *(.data*) + + . = ALIGN(4); + *(.after_data.*) + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__mutex_array_start = .); + KEEP(*(SORT(.mutex_array.*))) + KEEP(*(.mutex_array)) + PROVIDE_HIDDEN (__mutex_array_end = .); + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(SORT(.preinit_array.*))) + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + *(SORT(.fini_array.*)) + *(.fini_array) + PROVIDE_HIDDEN (__fini_array_end = .); + + *(.jcr) + . = ALIGN(4); + /* All data end */ + __data_end__ = .; + } > RAM AT> FLASH_FIRMWARE + + .itcm : + { + . = ALIGN(4); + *(.itcm.*) + + . = ALIGN(4); + } > RAM AT> FLASH_FIRMWARE + _ld_itcm_destination = ADDR(.itcm); + _ld_itcm_flash_copy = LOADADDR(.itcm); + _ld_itcm_size = SIZEOF(.itcm); + + .dtcm_data : + { + . = ALIGN(4); + + *(.dtcm_data.*) + + . = ALIGN(4); + } > RAM AT> FLASH_FIRMWARE + _ld_dtcm_data_destination = ADDR(.dtcm_data); + _ld_dtcm_data_flash_copy = LOADADDR(.dtcm_data); + _ld_dtcm_data_size = SIZEOF(.dtcm_data); + + .dtcm_bss : + { + . = ALIGN(4); + + *(.dtcm_bss.*) + + . = ALIGN(4); + } > RAM AT> RAM + _ld_dtcm_bss_start = ADDR(.dtcm_bss); + _ld_dtcm_bss_size = SIZEOF(.dtcm_bss); + + .uninitialized_data (COPY): { + . = ALIGN(4); + *(.uninitialized_data*) + } > RAM + + /* Start and end symbols must be word-aligned */ + .scratch_x : { + __scratch_x_start__ = .; + *(.scratch_x.*) + . = ALIGN(4); + __scratch_x_end__ = .; + } > SCRATCH_X AT > FLASH_FIRMWARE + __scratch_x_source__ = LOADADDR(.scratch_x); + + .scratch_y : { + __scratch_y_start__ = .; + *(.scratch_y.*) + . = ALIGN(4); + __scratch_y_end__ = .; + } > SCRATCH_Y AT > FLASH_FIRMWARE + __scratch_y_source__ = LOADADDR(.scratch_y); + + .bss : { + . = ALIGN(4); + __bss_start__ = .; + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + } > RAM + + .heap (COPY): + { + __end__ = .; + end = __end__; + *(.heap*) + __HeapLimit = .; + } > RAM + + /* .stack*_dummy section doesn't contains any symbols. It is only + * used for linker to calculate size of stack sections, and assign + * values to stack symbols later + * + * stack1 section may be empty/missing if platform_launch_core1 is not used */ + + /* by default we put core 0 stack at the end of scratch Y, so that if core 1 + * stack is not used then all of SCRATCH_X is free. + */ + .stack1_dummy (COPY): + { + *(.stack1*) + } > SCRATCH_X + .stack_dummy (COPY): + { + *(.stack*) + } > SCRATCH_Y + + .flash_end : { + __flash_binary_end = .; + } > FLASH_FIRMWARE + + /* stack limit is poorly named, but historically is maximum heap ptr */ + __StackLimit = ORIGIN(RAM) + LENGTH(RAM); + __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); + __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); + __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); + __StackBottom = __StackTop - SIZEOF(.stack_dummy); + PROVIDE(__stack = __StackTop); + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") + + ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary") + /* todo assert on extra code */ +} diff --git a/ports/raspberrypi/boards/pimoroni_badger2040w/mpconfigboard.h b/ports/raspberrypi/boards/pimoroni_badger2040w/mpconfigboard.h new file mode 100644 index 0000000000..674f07b538 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_badger2040w/mpconfigboard.h @@ -0,0 +1,18 @@ +#define MICROPY_HW_BOARD_NAME "Pimoroni Badger 2040 W" +#define MICROPY_HW_MCU_NAME "rp2040" + +#define CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL (1) +#define CIRCUITPY_DIGITALIO_HAVE_INVALID_DRIVE_MODE (1) + +// Status LED +#define MICROPY_HW_LED_STATUS (&pin_CYW0) + +#define DEFAULT_UART_BUS_TX (&pin_GPIO0) +#define DEFAULT_UART_BUS_RX (&pin_GPIO1) + +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO4) +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO5) + +#define DEFAULT_SPI_BUS_SCK (&pin_GPIO18) +#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO19) +#define DEFAULT_SPI_BUS_MISO (&pin_GPIO16) diff --git a/ports/raspberrypi/boards/pimoroni_badger2040w/mpconfigboard.mk b/ports/raspberrypi/boards/pimoroni_badger2040w/mpconfigboard.mk new file mode 100644 index 0000000000..4ddb0e7d87 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_badger2040w/mpconfigboard.mk @@ -0,0 +1,27 @@ +USB_VID = 0x2E8A +USB_PID = 0x104F + +USB_PRODUCT = "Badger 2040 W" +USB_MANUFACTURER = "Pimoroni" + +CHIP_VARIANT = RP2040 +CHIP_FAMILY = rp2 + +EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ" + +CIRCUITPY__EVE = 1 + +CIRCUITPY_CYW43 = 1 +CIRCUITPY_SSL = 1 +CIRCUITPY_SSL_MBEDTLS = 1 +CIRCUITPY_HASHLIB = 1 +CIRCUITPY_WEB_WORKFLOW = 1 +CIRCUITPY_MDNS = 1 +CIRCUITPY_SOCKETPOOL = 1 +CIRCUITPY_WIFI = 1 + +CFLAGS += -DCYW43_PIN_WL_HOST_WAKE=24 -DCYW43_PIN_WL_REG_ON=23 -DCYW43_WL_GPIO_COUNT=3 -DCYW43_WL_GPIO_LED_PIN=0 +# Must be accompanied by a linker script change +CFLAGS += -DCIRCUITPY_FIRMWARE_SIZE='(1536 * 1024)' + +FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-pcf85063a diff --git a/ports/raspberrypi/boards/pimoroni_badger2040w/pico-sdk-configboard.h b/ports/raspberrypi/boards/pimoroni_badger2040w/pico-sdk-configboard.h new file mode 100644 index 0000000000..36da55d457 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_badger2040w/pico-sdk-configboard.h @@ -0,0 +1 @@ +// Put board-specific pico-sdk definitions here. This file must exist. diff --git a/ports/raspberrypi/boards/pimoroni_badger2040w/pins.c b/ports/raspberrypi/boards/pimoroni_badger2040w/pins.c new file mode 100644 index 0000000000..49a821000c --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_badger2040w/pins.c @@ -0,0 +1,68 @@ +#include "shared-bindings/board/__init__.h" + +#include "shared-module/displayio/__init__.h" +#include "badger-shared.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) }, + + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_GP1), MP_ROM_PTR(&pin_GPIO1) }, + + { MP_ROM_QSTR(MP_QSTR_GP2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_GP3), MP_ROM_PTR(&pin_GPIO3) }, + + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO5) }, + + { MP_ROM_QSTR(MP_QSTR_GP6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_GP7), MP_ROM_PTR(&pin_GPIO7) }, + + { MP_ROM_QSTR(MP_QSTR_RTC_ALARM), MP_ROM_PTR(&pin_GPIO8) }, + + { MP_ROM_QSTR(MP_QSTR_GP9), MP_ROM_PTR(&pin_GPIO9) }, + + // { MP_ROM_QSTR(MP_QSTR_EN_3V3), MP_ROM_PTR(&pin_GPIO10) }, + + { MP_ROM_QSTR(MP_QSTR_SW_DOWN), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_SW_A), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_SW_B), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_SW_C), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_SW_UP), MP_ROM_PTR(&pin_GPIO15) }, + + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_INKY_CS), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_INKY_DC), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_INKY_RST), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_USER_LED), MP_ROM_PTR(&pin_GPIO22) }, + + { MP_ROM_QSTR(MP_QSTR_SMPS_MODE), MP_ROM_PTR(&pin_CYW1) }, + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_CYW0) }, + { MP_ROM_QSTR(MP_QSTR_VBUS_SENSE), MP_ROM_PTR(&pin_CYW2) }, + + { MP_ROM_QSTR(MP_QSTR_INKY_BUSY), MP_ROM_PTR(&pin_GPIO26) }, + + { MP_ROM_QSTR(MP_QSTR_GP27_A1), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_GP27), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, + + { MP_ROM_QSTR(MP_QSTR_GP28_A2), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_GP28), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) }, + + { MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_GPIO29) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) }, + + { 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_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].epaper_display)}, + { MP_ROM_QSTR(MP_QSTR_ENABLE_DIO), MP_ROM_PTR(&enable_pin_obj)}, // GP10 +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); From 690168b1ab6bbae0f235dfc5a1eb4f47008bd431 Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Wed, 5 Apr 2023 19:53:26 +0200 Subject: [PATCH 005/117] add support for Plasma2040W --- .../boards/pimoroni_plasma2040w/board.c | 29 ++ .../boards/pimoroni_plasma2040w/link.ld | 294 ++++++++++++++++++ .../pimoroni_plasma2040w/mpconfigboard.h | 10 + .../pimoroni_plasma2040w/mpconfigboard.mk | 26 ++ .../pico-sdk-configboard.h | 1 + .../boards/pimoroni_plasma2040w/pins.c | 62 ++++ 6 files changed, 422 insertions(+) create mode 100644 ports/raspberrypi/boards/pimoroni_plasma2040w/board.c create mode 100644 ports/raspberrypi/boards/pimoroni_plasma2040w/link.ld create mode 100644 ports/raspberrypi/boards/pimoroni_plasma2040w/mpconfigboard.h create mode 100644 ports/raspberrypi/boards/pimoroni_plasma2040w/mpconfigboard.mk create mode 100644 ports/raspberrypi/boards/pimoroni_plasma2040w/pico-sdk-configboard.h create mode 100644 ports/raspberrypi/boards/pimoroni_plasma2040w/pins.c diff --git a/ports/raspberrypi/boards/pimoroni_plasma2040w/board.c b/ports/raspberrypi/boards/pimoroni_plasma2040w/board.c new file mode 100644 index 0000000000..331653173e --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_plasma2040w/board.c @@ -0,0 +1,29 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/raspberrypi/boards/pimoroni_plasma2040w/link.ld b/ports/raspberrypi/boards/pimoroni_plasma2040w/link.ld new file mode 100644 index 0000000000..2777b41720 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_plasma2040w/link.ld @@ -0,0 +1,294 @@ +/* Based on GCC ARM embedded samples. + Defines the following symbols for use by code: + __exidx_start + __exidx_end + __etext + __data_start__ + __preinit_array_start + __preinit_array_end + __init_array_start + __init_array_end + __fini_array_start + __fini_array_end + __data_end__ + __bss_start__ + __bss_end__ + __end__ + end + __HeapLimit + __StackLimit + __StackTop + __stack (== StackTop) +*/ + +MEMORY +{ + FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 1532k + /* Followed by: 4kB of NVRAM and at least 512kB of CIRCUITPY */ + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k + SCRATCH_X (rwx) : ORIGIN = 0x20040000, LENGTH = 4k + SCRATCH_Y (rwx) : ORIGIN = 0x20041000, LENGTH = 4k +} + +ENTRY(_entry_point) + +SECTIONS +{ + /* Second stage bootloader is prepended to the image. It must be 256 bytes big + and checksummed. It is usually built by the boot_stage2 target + in the Pico SDK + */ + + .flash_begin : { + __flash_binary_start = .; + } > FLASH_FIRMWARE + + .boot2 : { + __boot2_start__ = .; + KEEP (*(.boot2)) + __boot2_end__ = .; + } > FLASH_FIRMWARE + + ASSERT(__boot2_end__ - __boot2_start__ == 256, + "ERROR: Pico second stage bootloader must be 256 bytes in size") + + /* The second stage will always enter the image at the start of .text. + The debugger will use the ELF entry point, which is the _entry_point + symbol if present, otherwise defaults to start of .text. + This can be used to transfer control back to the bootrom on debugger + launches only, to perform proper flash setup. + */ + + .text : { + __logical_binary_start = .; + KEEP (*(.vectors)) + KEEP (*(.binary_info_header)) + __binary_info_header_end = .; + KEEP (*(.reset)) + /* TODO revisit this now memset/memcpy/float in ROM */ + /* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from + * FLASH ... we will include any thing excluded here in .data below by default */ + *(.init) + + __property_getter_start = .; + *(.property_getter) + __property_getter_end = .; + __property_getset_start = .; + *(.property_getset) + __property_getset_end = .; + + *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*) + *(.fini) + /* Pull all c'tors into .text */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + /* Followed by destructors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + *(.eh_frame*) + . = ALIGN(4); + } > FLASH_FIRMWARE + + .rodata : { + *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*) + . = ALIGN(4); + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) + . = ALIGN(4); + } > FLASH_FIRMWARE + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH_FIRMWARE + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > FLASH_FIRMWARE + __exidx_end = .; + + /* Machine inspectable binary information */ + . = ALIGN(4); + __binary_info_start = .; + .binary_info : + { + KEEP(*(.binary_info.keep.*)) + *(.binary_info.*) + } > FLASH_FIRMWARE + __binary_info_end = .; + . = ALIGN(4); + + /* End of .text-like segments */ + __etext = .; + + .ram_vector_table (COPY): { + *(.ram_vector_table) + } > RAM + + .data : { + __data_start__ = .; + *(vtable) + + *(.time_critical*) + + /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */ + *(.text*) + . = ALIGN(4); + *(.rodata*) + . = ALIGN(4); + + *(.data*) + + . = ALIGN(4); + *(.after_data.*) + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__mutex_array_start = .); + KEEP(*(SORT(.mutex_array.*))) + KEEP(*(.mutex_array)) + PROVIDE_HIDDEN (__mutex_array_end = .); + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP(*(SORT(.preinit_array.*))) + KEEP(*(.preinit_array)) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + KEEP(*(SORT(.init_array.*))) + KEEP(*(.init_array)) + PROVIDE_HIDDEN (__init_array_end = .); + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + *(SORT(.fini_array.*)) + *(.fini_array) + PROVIDE_HIDDEN (__fini_array_end = .); + + *(.jcr) + . = ALIGN(4); + /* All data end */ + __data_end__ = .; + } > RAM AT> FLASH_FIRMWARE + + .itcm : + { + . = ALIGN(4); + *(.itcm.*) + + . = ALIGN(4); + } > RAM AT> FLASH_FIRMWARE + _ld_itcm_destination = ADDR(.itcm); + _ld_itcm_flash_copy = LOADADDR(.itcm); + _ld_itcm_size = SIZEOF(.itcm); + + .dtcm_data : + { + . = ALIGN(4); + + *(.dtcm_data.*) + + . = ALIGN(4); + } > RAM AT> FLASH_FIRMWARE + _ld_dtcm_data_destination = ADDR(.dtcm_data); + _ld_dtcm_data_flash_copy = LOADADDR(.dtcm_data); + _ld_dtcm_data_size = SIZEOF(.dtcm_data); + + .dtcm_bss : + { + . = ALIGN(4); + + *(.dtcm_bss.*) + + . = ALIGN(4); + } > RAM AT> RAM + _ld_dtcm_bss_start = ADDR(.dtcm_bss); + _ld_dtcm_bss_size = SIZEOF(.dtcm_bss); + + .uninitialized_data (COPY): { + . = ALIGN(4); + *(.uninitialized_data*) + } > RAM + + /* Start and end symbols must be word-aligned */ + .scratch_x : { + __scratch_x_start__ = .; + *(.scratch_x.*) + . = ALIGN(4); + __scratch_x_end__ = .; + } > SCRATCH_X AT > FLASH_FIRMWARE + __scratch_x_source__ = LOADADDR(.scratch_x); + + .scratch_y : { + __scratch_y_start__ = .; + *(.scratch_y.*) + . = ALIGN(4); + __scratch_y_end__ = .; + } > SCRATCH_Y AT > FLASH_FIRMWARE + __scratch_y_source__ = LOADADDR(.scratch_y); + + .bss : { + . = ALIGN(4); + __bss_start__ = .; + *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + } > RAM + + .heap (COPY): + { + __end__ = .; + end = __end__; + *(.heap*) + __HeapLimit = .; + } > RAM + + /* .stack*_dummy section doesn't contains any symbols. It is only + * used for linker to calculate size of stack sections, and assign + * values to stack symbols later + * + * stack1 section may be empty/missing if platform_launch_core1 is not used */ + + /* by default we put core 0 stack at the end of scratch Y, so that if core 1 + * stack is not used then all of SCRATCH_X is free. + */ + .stack1_dummy (COPY): + { + *(.stack1*) + } > SCRATCH_X + .stack_dummy (COPY): + { + *(.stack*) + } > SCRATCH_Y + + .flash_end : { + __flash_binary_end = .; + } > FLASH_FIRMWARE + + /* stack limit is poorly named, but historically is maximum heap ptr */ + __StackLimit = ORIGIN(RAM) + LENGTH(RAM); + __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); + __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); + __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); + __StackBottom = __StackTop - SIZEOF(.stack_dummy); + PROVIDE(__stack = __StackTop); + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") + + ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary") + /* todo assert on extra code */ +} diff --git a/ports/raspberrypi/boards/pimoroni_plasma2040w/mpconfigboard.h b/ports/raspberrypi/boards/pimoroni_plasma2040w/mpconfigboard.h new file mode 100644 index 0000000000..d36f7a8baf --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_plasma2040w/mpconfigboard.h @@ -0,0 +1,10 @@ +#define MICROPY_HW_BOARD_NAME "Pimoroni Plasma 2040W" +#define MICROPY_HW_MCU_NAME "rp2040" + +#define CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL (1) +#define CIRCUITPY_DIGITALIO_HAVE_INVALID_DRIVE_MODE (1) + +#define MICROPY_HW_LED_STATUS (&pin_CYW0) + +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO4) +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO5) diff --git a/ports/raspberrypi/boards/pimoroni_plasma2040w/mpconfigboard.mk b/ports/raspberrypi/boards/pimoroni_plasma2040w/mpconfigboard.mk new file mode 100644 index 0000000000..68fec260ed --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_plasma2040w/mpconfigboard.mk @@ -0,0 +1,26 @@ +USB_VID = 0x2E8A +USB_PID = 0x100a +USB_PRODUCT = "Plasma 2040 W" +USB_MANUFACTURER = "Pimoroni" + +CHIP_VARIANT = RP2040 +CHIP_FAMILY = rp2 + +EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ" + +CIRCUITPY__EVE = 1 + +CIRCUITPY_CYW43 = 1 +CIRCUITPY_SSL = 1 +CIRCUITPY_SSL_MBEDTLS = 1 +CIRCUITPY_HASHLIB = 1 +CIRCUITPY_WEB_WORKFLOW = 1 +CIRCUITPY_MDNS = 1 +CIRCUITPY_SOCKETPOOL = 1 +CIRCUITPY_WIFI = 1 + +CFLAGS += -DCYW43_PIN_WL_HOST_WAKE=24 -DCYW43_PIN_WL_REG_ON=23 -DCYW43_WL_GPIO_COUNT=3 -DCYW43_WL_GPIO_LED_PIN=0 +# Must be accompanied by a linker script change +CFLAGS += -DCIRCUITPY_FIRMWARE_SIZE='(1536 * 1024)' + +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel diff --git a/ports/raspberrypi/boards/pimoroni_plasma2040w/pico-sdk-configboard.h b/ports/raspberrypi/boards/pimoroni_plasma2040w/pico-sdk-configboard.h new file mode 100644 index 0000000000..36da55d457 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_plasma2040w/pico-sdk-configboard.h @@ -0,0 +1 @@ +// Put board-specific pico-sdk definitions here. This file must exist. diff --git a/ports/raspberrypi/boards/pimoroni_plasma2040w/pins.c b/ports/raspberrypi/boards/pimoroni_plasma2040w/pins.c new file mode 100644 index 0000000000..691e2c9355 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_plasma2040w/pins.c @@ -0,0 +1,62 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_GP1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_GP2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_GP3), MP_ROM_PTR(&pin_GPIO3) }, + + { MP_ROM_QSTR(MP_QSTR_GP4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_GP5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO5) }, + + { MP_ROM_QSTR(MP_QSTR_GP6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_GP7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_GP8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_GP9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_GP10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_GP11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_GP12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_GP13), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_GP14), MP_ROM_PTR(&pin_GPIO14) }, + + { MP_ROM_QSTR(MP_QSTR_DATA), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_GP15), MP_ROM_PTR(&pin_GPIO15) }, + + { MP_ROM_QSTR(MP_QSTR_GP16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_GP17), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_GP18), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_GP19), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_GP20), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_GP21), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_GP22), MP_ROM_PTR(&pin_GPIO22) }, + + { MP_ROM_QSTR(MP_QSTR_SMPS_MODE), MP_ROM_PTR(&pin_CYW1) }, + + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_CYW0) }, + + { MP_ROM_QSTR(MP_QSTR_VBUS_SENSE), MP_ROM_PTR(&pin_CYW2) }, + + { MP_ROM_QSTR(MP_QSTR_GP26_A0), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_GP26), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) }, + + { MP_ROM_QSTR(MP_QSTR_GP27_A1), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_GP27), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, + + { MP_ROM_QSTR(MP_QSTR_GP28_A2), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_GP28), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) }, + + { MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_GPIO29) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) }, + + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_STEMMA_I2C), MP_ROM_PTR(&board_i2c_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); From 5ab3b7d7f389bc009dcbf9f86a5b26b155a59bcf Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Thu, 6 Apr 2023 14:24:09 +0200 Subject: [PATCH 006/117] upgraded to version 1.1.0 --- frozen/circuitpython-pcf85063a | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frozen/circuitpython-pcf85063a b/frozen/circuitpython-pcf85063a index 21baeb6479..85aa931a14 160000 --- a/frozen/circuitpython-pcf85063a +++ b/frozen/circuitpython-pcf85063a @@ -1 +1 @@ -Subproject commit 21baeb6479434b950e9356a320a5a4d050a4bf47 +Subproject commit 85aa931a14f46558233ef9bf1122ea68e2192958 From 42ab93fa4cc083e0647d05674be1b7efd7985021 Mon Sep 17 00:00:00 2001 From: Bill Sideris Date: Fri, 7 Apr 2023 18:34:10 +0300 Subject: [PATCH 007/117] YD_ESP32_S3 --- .../boards/yd_esp32_s3_n16r8/board.c | 39 ++++++++++++ .../boards/yd_esp32_s3_n16r8/mpconfigboard.h | 33 ++++++++++ .../boards/yd_esp32_s3_n16r8/mpconfigboard.mk | 13 ++++ .../espressif/boards/yd_esp32_s3_n16r8/pins.c | 60 +++++++++++++++++++ .../boards/yd_esp32_s3_n16r8/sdkconfig | 16 +++++ .../espressif/boards/yd_esp32_s3_n8r8/board.c | 39 ++++++++++++ .../boards/yd_esp32_s3_n8r8/mpconfigboard.h | 33 ++++++++++ .../boards/yd_esp32_s3_n8r8/mpconfigboard.mk | 13 ++++ .../espressif/boards/yd_esp32_s3_n8r8/pins.c | 60 +++++++++++++++++++ .../boards/yd_esp32_s3_n8r8/sdkconfig | 16 +++++ tools/ci_check_duplicate_usb_vid_pid.py | 1 + 11 files changed, 323 insertions(+) create mode 100644 ports/espressif/boards/yd_esp32_s3_n16r8/board.c create mode 100644 ports/espressif/boards/yd_esp32_s3_n16r8/mpconfigboard.h create mode 100644 ports/espressif/boards/yd_esp32_s3_n16r8/mpconfigboard.mk create mode 100644 ports/espressif/boards/yd_esp32_s3_n16r8/pins.c create mode 100644 ports/espressif/boards/yd_esp32_s3_n16r8/sdkconfig create mode 100644 ports/espressif/boards/yd_esp32_s3_n8r8/board.c create mode 100644 ports/espressif/boards/yd_esp32_s3_n8r8/mpconfigboard.h create mode 100644 ports/espressif/boards/yd_esp32_s3_n8r8/mpconfigboard.mk create mode 100644 ports/espressif/boards/yd_esp32_s3_n8r8/pins.c create mode 100644 ports/espressif/boards/yd_esp32_s3_n8r8/sdkconfig diff --git a/ports/espressif/boards/yd_esp32_s3_n16r8/board.c b/ports/espressif/boards/yd_esp32_s3_n16r8/board.c new file mode 100644 index 0000000000..e218345f59 --- /dev/null +++ b/ports/espressif/boards/yd_esp32_s3_n16r8/board.c @@ -0,0 +1,39 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023 Bill Sideris, independently providing these changes. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" +#include "mpconfigboard.h" +#include "shared-bindings/microcontroller/Pin.h" + +void board_init(void) { + // Debug UART + #ifdef DEBUG + common_hal_never_reset_pin(&pin_GPIO43); + common_hal_never_reset_pin(&pin_GPIO44); + #endif +} + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/espressif/boards/yd_esp32_s3_n16r8/mpconfigboard.h b/ports/espressif/boards/yd_esp32_s3_n16r8/mpconfigboard.h new file mode 100644 index 0000000000..4a0ea02809 --- /dev/null +++ b/ports/espressif/boards/yd_esp32_s3_n16r8/mpconfigboard.h @@ -0,0 +1,33 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023 Bill Sideris, independently providing these changes. + * + * 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. + */ + +#define MICROPY_HW_BOARD_NAME "VCC-GND YD-ESP32-S3 (N16R8)" +#define MICROPY_HW_MCU_NAME "ESP32S3" + +#define MICROPY_HW_NEOPIXEL (&pin_GPIO48) + +#define DEFAULT_UART_BUS_RX (&pin_GPIO44) +#define DEFAULT_UART_BUS_TX (&pin_GPIO43) diff --git a/ports/espressif/boards/yd_esp32_s3_n16r8/mpconfigboard.mk b/ports/espressif/boards/yd_esp32_s3_n16r8/mpconfigboard.mk new file mode 100644 index 0000000000..2120ba97cb --- /dev/null +++ b/ports/espressif/boards/yd_esp32_s3_n16r8/mpconfigboard.mk @@ -0,0 +1,13 @@ +USB_VID = 0x303A +USB_PID = 0x8166 +USB_PRODUCT = "YD-ESP32-S3" +USB_MANUFACTURER = "VCC-GND" + +IDF_TARGET = esp32s3 + +CIRCUITPY_ESP_FLASH_MODE = dio +CIRCUITPY_ESP_FLASH_FREQ = 80m +CIRCUITPY_ESP_FLASH_SIZE = 16MB + +# Include these Python libraries in firmware. +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel diff --git a/ports/espressif/boards/yd_esp32_s3_n16r8/pins.c b/ports/espressif/boards/yd_esp32_s3_n16r8/pins.c new file mode 100644 index 0000000000..46a579fc20 --- /dev/null +++ b/ports/espressif/boards/yd_esp32_s3_n16r8/pins.c @@ -0,0 +1,60 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + // Left header, module facing up. + { MP_ROM_QSTR(MP_QSTR_GPIO4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_GPIO5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_GPIO6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_GPIO7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_GPIO15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_GPIO16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_GPIO17), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_GPIO18), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_GPIO8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_GPIO3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_GPIO46), MP_ROM_PTR(&pin_GPIO46) }, + { MP_ROM_QSTR(MP_QSTR_GPIO9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_GPIO10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_GPIO11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_GPIO12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_GPIO13), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_GPIO14), MP_ROM_PTR(&pin_GPIO14) }, + + + // Right header, module facing up. + { MP_ROM_QSTR(MP_QSTR_GPIO43), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) }, + + { MP_ROM_QSTR(MP_QSTR_GPIO44), MP_ROM_PTR(&pin_GPIO44) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) }, + + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, + + { MP_ROM_QSTR(MP_QSTR_GPIO1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_GPIO2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_GPIO14), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_GPIO42), MP_ROM_PTR(&pin_GPIO42) }, + { MP_ROM_QSTR(MP_QSTR_GPIO41), MP_ROM_PTR(&pin_GPIO41) }, + { MP_ROM_QSTR(MP_QSTR_GPIO40), MP_ROM_PTR(&pin_GPIO40) }, + { MP_ROM_QSTR(MP_QSTR_GPIO39), MP_ROM_PTR(&pin_GPIO39) }, + { MP_ROM_QSTR(MP_QSTR_GPIO38), MP_ROM_PTR(&pin_GPIO38) }, + { MP_ROM_QSTR(MP_QSTR_GPIO37), MP_ROM_PTR(&pin_GPIO37) }, + { MP_ROM_QSTR(MP_QSTR_GPIO36), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_GPIO35), MP_ROM_PTR(&pin_GPIO35) }, + + { MP_ROM_QSTR(MP_QSTR_GPIO0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_GPIO0) }, + + { MP_ROM_QSTR(MP_QSTR_GPIO45), MP_ROM_PTR(&pin_GPIO45) }, + + { MP_ROM_QSTR(MP_QSTR_GPIO48), MP_ROM_PTR(&pin_GPIO48) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO48) }, + // For the neopixel to work, please bridge the "RGB" pad + // or use external neopixels. + + { MP_ROM_QSTR(MP_QSTR_GPIO47), MP_ROM_PTR(&pin_GPIO47) }, + { MP_ROM_QSTR(MP_QSTR_GPIO21), MP_ROM_PTR(&pin_GPIO21) } +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/espressif/boards/yd_esp32_s3_n16r8/sdkconfig b/ports/espressif/boards/yd_esp32_s3_n16r8/sdkconfig new file mode 100644 index 0000000000..5aff7f49b1 --- /dev/null +++ b/ports/espressif/boards/yd_esp32_s3_n16r8/sdkconfig @@ -0,0 +1,16 @@ +CONFIG_ESP32S3_SPIRAM_SUPPORT=y + +CONFIG_SPIRAM_TYPE_ESPPSRAM64=y +CONFIG_SPIRAM_SIZE=8388608 +CONFIG_SPIRAM_MODE_OCT=y +CONFIG_SPIRAM_SPEED_80M=y + +CONFIG_DEFAULT_PSRAM_CLK_IO=30 +CONFIG_DEFAULT_PSRAM_CS_IO=26 + +CONFIG_SPIRAM=y +CONFIG_SPIRAM_BOOT_INIT=y +CONFIG_SPIRAM_USE_MEMMAP=y +CONFIG_SPIRAM_MEMTEST=y + +CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" diff --git a/ports/espressif/boards/yd_esp32_s3_n8r8/board.c b/ports/espressif/boards/yd_esp32_s3_n8r8/board.c new file mode 100644 index 0000000000..e218345f59 --- /dev/null +++ b/ports/espressif/boards/yd_esp32_s3_n8r8/board.c @@ -0,0 +1,39 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023 Bill Sideris, independently providing these changes. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" +#include "mpconfigboard.h" +#include "shared-bindings/microcontroller/Pin.h" + +void board_init(void) { + // Debug UART + #ifdef DEBUG + common_hal_never_reset_pin(&pin_GPIO43); + common_hal_never_reset_pin(&pin_GPIO44); + #endif +} + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/espressif/boards/yd_esp32_s3_n8r8/mpconfigboard.h b/ports/espressif/boards/yd_esp32_s3_n8r8/mpconfigboard.h new file mode 100644 index 0000000000..349931740d --- /dev/null +++ b/ports/espressif/boards/yd_esp32_s3_n8r8/mpconfigboard.h @@ -0,0 +1,33 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023 Bill Sideris, independently providing these changes. + * + * 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. + */ + +#define MICROPY_HW_BOARD_NAME "VCC-GND YD-ESP32-S3 (N8R8)" +#define MICROPY_HW_MCU_NAME "ESP32S3" + +#define MICROPY_HW_NEOPIXEL (&pin_GPIO48) + +#define DEFAULT_UART_BUS_RX (&pin_GPIO44) +#define DEFAULT_UART_BUS_TX (&pin_GPIO43) diff --git a/ports/espressif/boards/yd_esp32_s3_n8r8/mpconfigboard.mk b/ports/espressif/boards/yd_esp32_s3_n8r8/mpconfigboard.mk new file mode 100644 index 0000000000..766e71dc2d --- /dev/null +++ b/ports/espressif/boards/yd_esp32_s3_n8r8/mpconfigboard.mk @@ -0,0 +1,13 @@ +USB_VID = 0x303A +USB_PID = 0x8166 +USB_PRODUCT = "YD-ESP32-S3" +USB_MANUFACTURER = "VCC-GND" + +IDF_TARGET = esp32s3 + +CIRCUITPY_ESP_FLASH_MODE = dio +CIRCUITPY_ESP_FLASH_FREQ = 80m +CIRCUITPY_ESP_FLASH_SIZE = 8MB + +# Include these Python libraries in firmware. +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel diff --git a/ports/espressif/boards/yd_esp32_s3_n8r8/pins.c b/ports/espressif/boards/yd_esp32_s3_n8r8/pins.c new file mode 100644 index 0000000000..46a579fc20 --- /dev/null +++ b/ports/espressif/boards/yd_esp32_s3_n8r8/pins.c @@ -0,0 +1,60 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + // Left header, module facing up. + { MP_ROM_QSTR(MP_QSTR_GPIO4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_GPIO5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_GPIO6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_GPIO7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_GPIO15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_GPIO16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_GPIO17), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_GPIO18), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_GPIO8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_GPIO3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_GPIO46), MP_ROM_PTR(&pin_GPIO46) }, + { MP_ROM_QSTR(MP_QSTR_GPIO9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_GPIO10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_GPIO11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_GPIO12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_GPIO13), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_GPIO14), MP_ROM_PTR(&pin_GPIO14) }, + + + // Right header, module facing up. + { MP_ROM_QSTR(MP_QSTR_GPIO43), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) }, + + { MP_ROM_QSTR(MP_QSTR_GPIO44), MP_ROM_PTR(&pin_GPIO44) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) }, + + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, + + { MP_ROM_QSTR(MP_QSTR_GPIO1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_GPIO2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_GPIO14), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_GPIO42), MP_ROM_PTR(&pin_GPIO42) }, + { MP_ROM_QSTR(MP_QSTR_GPIO41), MP_ROM_PTR(&pin_GPIO41) }, + { MP_ROM_QSTR(MP_QSTR_GPIO40), MP_ROM_PTR(&pin_GPIO40) }, + { MP_ROM_QSTR(MP_QSTR_GPIO39), MP_ROM_PTR(&pin_GPIO39) }, + { MP_ROM_QSTR(MP_QSTR_GPIO38), MP_ROM_PTR(&pin_GPIO38) }, + { MP_ROM_QSTR(MP_QSTR_GPIO37), MP_ROM_PTR(&pin_GPIO37) }, + { MP_ROM_QSTR(MP_QSTR_GPIO36), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_GPIO35), MP_ROM_PTR(&pin_GPIO35) }, + + { MP_ROM_QSTR(MP_QSTR_GPIO0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_GPIO0) }, + + { MP_ROM_QSTR(MP_QSTR_GPIO45), MP_ROM_PTR(&pin_GPIO45) }, + + { MP_ROM_QSTR(MP_QSTR_GPIO48), MP_ROM_PTR(&pin_GPIO48) }, + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO48) }, + // For the neopixel to work, please bridge the "RGB" pad + // or use external neopixels. + + { MP_ROM_QSTR(MP_QSTR_GPIO47), MP_ROM_PTR(&pin_GPIO47) }, + { MP_ROM_QSTR(MP_QSTR_GPIO21), MP_ROM_PTR(&pin_GPIO21) } +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/espressif/boards/yd_esp32_s3_n8r8/sdkconfig b/ports/espressif/boards/yd_esp32_s3_n8r8/sdkconfig new file mode 100644 index 0000000000..5aff7f49b1 --- /dev/null +++ b/ports/espressif/boards/yd_esp32_s3_n8r8/sdkconfig @@ -0,0 +1,16 @@ +CONFIG_ESP32S3_SPIRAM_SUPPORT=y + +CONFIG_SPIRAM_TYPE_ESPPSRAM64=y +CONFIG_SPIRAM_SIZE=8388608 +CONFIG_SPIRAM_MODE_OCT=y +CONFIG_SPIRAM_SPEED_80M=y + +CONFIG_DEFAULT_PSRAM_CLK_IO=30 +CONFIG_DEFAULT_PSRAM_CS_IO=26 + +CONFIG_SPIRAM=y +CONFIG_SPIRAM_BOOT_INIT=y +CONFIG_SPIRAM_USE_MEMMAP=y +CONFIG_SPIRAM_MEMTEST=y + +CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3" diff --git a/tools/ci_check_duplicate_usb_vid_pid.py b/tools/ci_check_duplicate_usb_vid_pid.py index 4d9a0b162e..f20630e886 100644 --- a/tools/ci_check_duplicate_usb_vid_pid.py +++ b/tools/ci_check_duplicate_usb_vid_pid.py @@ -62,6 +62,7 @@ DEFAULT_CLUSTERLIST = { "espressif_esp32s2_devkitc_1_n8r2", ], "0x239A:0x102E": ["weact_studio_pico", "weact_studio_pico_16mb"], + "0x303A:0x8166": ["yd_esp32_s3_n8r8", "yd_esp32_s3_n16r8"], } cli_parser = argparse.ArgumentParser( From e38b5491f452df2ff5e09209ea0859f3444d4158 Mon Sep 17 00:00:00 2001 From: Isaac Benitez Date: Fri, 7 Apr 2023 11:45:13 -0700 Subject: [PATCH 008/117] Add device name env variable for web workflow --- docs/environment.rst | 4 ++++ docs/workflows.md | 4 +++- supervisor/shared/web_workflow/web_workflow.c | 15 ++++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/docs/environment.rst b/docs/environment.rst index 58ada402c6..f569d5e6a4 100644 --- a/docs/environment.rst +++ b/docs/environment.rst @@ -74,6 +74,10 @@ CIRCUITPY_WEB_API_PORT ~~~~~~~~~~~~~~~~~~~~~~ TCP port number used for the web HTTP API. Defaults to 80 when omitted. +CIRCUITPY_WEB_INSTANCE_NAME +~~~~~~~~~~~~~~~~~~~ +Name the board advertises as for the WEB workflow. Defaults to human readable board name if omitted. + CIRCUITPY_WIFI_PASSWORD ~~~~~~~~~~~~~~~~~~~~~~~ Wi-Fi password used to auto connect to CIRCUITPY_WIFI_SSID. diff --git a/docs/workflows.md b/docs/workflows.md index 29229bd00e..453b425491 100644 --- a/docs/workflows.md +++ b/docs/workflows.md @@ -72,7 +72,8 @@ Read-only characteristic that returns the UTF-8 encoded version string. The web workflow is depends on adding Wi-Fi credentials into the `settings.toml` file. The keys are `CIRCUITPY_WIFI_SSID` and `CIRCUITPY_WIFI_PASSWORD`. Once these are defined, CircuitPython will automatically connect to the network and start the webserver used for the workflow. The webserver -is on port 80 unless overridden by `CIRCUITPY_WEB_API_PORT`. It also enables MDNS. +is on port 80 unless overridden by `CIRCUITPY_WEB_API_PORT`. It also enables MDNS. The name +of the board as advertised to the network can be overridden by `CIRCUITPY_WEB_INSTANCE_NAME`. Here is an example `/settings.toml`: @@ -86,6 +87,7 @@ CIRCUITPY_WIFI_PASSWORD="secretpassword" CIRCUITPY_WEB_API_PASSWORD="passw0rd" CIRCUITPY_WEB_API_PORT=80 +CIRCUITPY_WEB_INSTANCE_NAME="" ``` MDNS is used to resolve [`circuitpython.local`](http://circuitpython.local) to a device specific diff --git a/supervisor/shared/web_workflow/web_workflow.c b/supervisor/shared/web_workflow/web_workflow.c index 468787269a..b640578e20 100644 --- a/supervisor/shared/web_workflow/web_workflow.c +++ b/supervisor/shared/web_workflow/web_workflow.c @@ -269,6 +269,7 @@ void supervisor_start_web_workflow(void) { char ssid[33]; char password[64]; + char web_instance_name[50]; os_getenv_err_t result = common_hal_os_getenv_str("CIRCUITPY_WIFI_SSID", ssid, sizeof(ssid)); if (result != GETENV_OK) { @@ -283,6 +284,11 @@ void supervisor_start_web_workflow(void) { return; } + result = common_hal_os_getenv_str("CIRCUITPY_WEB_INSTANCE_NAME", web_instance_name, sizeof(web_instance_name)); + if (result != GETENV_OK || web_instance_name[0] == '\0') { + strcpy(web_instance_name, MICROPY_HW_BOARD_NAME); + } + if (!common_hal_wifi_radio_get_enabled(&common_hal_wifi_radio_obj)) { common_hal_wifi_init(false); common_hal_wifi_radio_set_enabled(&common_hal_wifi_radio_obj, true); @@ -329,7 +335,8 @@ void supervisor_start_web_workflow(void) { mdns_server_construct(&mdns, true); mdns.base.type = &mdns_server_type; if (!common_hal_mdns_server_deinited(&mdns)) { - common_hal_mdns_server_set_instance_name(&mdns, MICROPY_HW_BOARD_NAME); + char *instance_name = strndup(web_instance_name, strlen(web_instance_name)); + common_hal_mdns_server_set_instance_name(&mdns, instance_name); } } if (!common_hal_mdns_server_deinited(&mdns)) { @@ -796,9 +803,11 @@ static void _reply_with_version_json(socketpool_socket_obj_t *socket, _request * mp_print_t _socket_print = {socket, _print_chunk}; const char *hostname = ""; + const char *instance_name = ""; #if CIRCUITPY_MDNS if (!common_hal_mdns_server_deinited(&mdns)) { hostname = common_hal_mdns_server_get_hostname(&mdns); + instance_name = common_hal_mdns_server_get_instance_name(&mdns); } #endif _update_encoded_ip(); @@ -807,13 +816,13 @@ static void _reply_with_version_json(socketpool_socket_obj_t *socket, _request * "{\"web_api_version\": 2, " "\"version\": \"" MICROPY_GIT_TAG "\", " "\"build_date\": \"" MICROPY_BUILD_DATE "\", " - "\"board_name\": \"" MICROPY_HW_BOARD_NAME "\", " + "\"board_name\": \"%s\", " "\"mcu_name\": \"" MICROPY_HW_MCU_NAME "\", " "\"board_id\": \"" CIRCUITPY_BOARD_ID "\", " "\"creator_id\": %u, " "\"creation_id\": %u, " "\"hostname\": \"%s\", " - "\"port\": %d, ", CIRCUITPY_CREATOR_ID, CIRCUITPY_CREATION_ID, hostname, web_api_port, _our_ip_encoded); + "\"port\": %d, ", instance_name, CIRCUITPY_CREATOR_ID, CIRCUITPY_CREATION_ID, hostname, web_api_port, _our_ip_encoded); #if CIRCUITPY_MICROCONTROLLER && COMMON_HAL_MCU_PROCESSOR_UID_LENGTH > 0 uint8_t raw_id[COMMON_HAL_MCU_PROCESSOR_UID_LENGTH]; common_hal_mcu_processor_get_uid(raw_id); From 37116e6583cd60cfe66500abb273ec2552b5dc34 Mon Sep 17 00:00:00 2001 From: Isaac Benitez Date: Fri, 7 Apr 2023 12:09:51 -0700 Subject: [PATCH 009/117] Fix documentation format error --- docs/environment.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/environment.rst b/docs/environment.rst index f569d5e6a4..f8144407ef 100644 --- a/docs/environment.rst +++ b/docs/environment.rst @@ -75,7 +75,7 @@ CIRCUITPY_WEB_API_PORT TCP port number used for the web HTTP API. Defaults to 80 when omitted. CIRCUITPY_WEB_INSTANCE_NAME -~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~ Name the board advertises as for the WEB workflow. Defaults to human readable board name if omitted. CIRCUITPY_WIFI_PASSWORD From c37af65ee16c130a6867e91864e66a6b530c0919 Mon Sep 17 00:00:00 2001 From: George White Date: Sat, 8 Apr 2023 16:29:50 -0400 Subject: [PATCH 010/117] Update pins to include UART1 RTS and CTS Previous pins definition stated that the UART1 RTS and CTS were not connected. They are connected and can currently be used via A1 and PWM0 respectively. To make things a little clearer, enabling the RTS1/CTS1. --- ports/atmel-samd/boards/sparkfun_samd51_micromod/pins.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/atmel-samd/boards/sparkfun_samd51_micromod/pins.c b/ports/atmel-samd/boards/sparkfun_samd51_micromod/pins.c index 5a35a60e82..e39272b41e 100644 --- a/ports/atmel-samd/boards/sparkfun_samd51_micromod/pins.c +++ b/ports/atmel-samd/boards/sparkfun_samd51_micromod/pins.c @@ -77,8 +77,8 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { // MicroMod UART1 pins { MP_ROM_QSTR(MP_QSTR_UART_TX1), MP_ROM_PTR(&pin_PB31) }, // MicroMod UART_TX1 | CircuitPython TX (PB31) { MP_ROM_QSTR(MP_QSTR_UART_RX1), MP_ROM_PTR(&pin_PB30) }, // MicroMod UART_RX1 | CircuitPython RX (PB30) - // { MP_ROM_QSTR(MP_QSTR_UART_RTS1), MP_ROM_PTR() }, // MicroMod RTS1 (not connected) - // { MP_ROM_QSTR(MP_QSTR_UART_CTS1), MP_ROM_PTR() }, // MicroMod CTS1 (not connected) + { MP_ROM_QSTR(MP_QSTR_UART_RTS1), MP_ROM_PTR(&pin_PB00) }, // MicroMod RTS1 + { MP_ROM_QSTR(MP_QSTR_UART_CTS1), MP_ROM_PTR(&pin_PB01) }, // MicroMod CTS1 // CircuitPython default UART pins { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PB31) }, // CircuitPython TX | MicroMod UART_TX1 (PB31) From 60502679d928abebd23a9f8d31af73f4c4108817 Mon Sep 17 00:00:00 2001 From: hexthat Date: Sat, 8 Apr 2023 17:17:42 +0000 Subject: [PATCH 011/117] Translated using Weblate (Chinese (Pinyin)) Currently translated at 100.0% (1000 of 1000 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/zh_Latn/ --- locale/zh_Latn_pinyin.po | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index 37d8016fc7..dffbea185d 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -7,7 +7,7 @@ msgstr "" "Project-Id-Version: circuitpython-cn\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2023-03-01 17:39+0000\n" +"PO-Revision-Date: 2023-04-09 17:51+0000\n" "Last-Translator: hexthat \n" "Language-Team: Chinese Hanyu Pinyin\n" "Language: zh_Latn_pinyin\n" @@ -15,7 +15,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" -"X-Generator: Weblate 4.16\n" +"X-Generator: Weblate 4.17-dev\n" #: main.c msgid "" @@ -211,7 +211,7 @@ msgstr "%q bì xū shì lèi xíng wéi 'H' de shù zǔ" #: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c msgid "%q must be array of type 'h'" -msgstr "" +msgstr "%q bìxū shì lèixíng wéi 'h' de shùzǔ" #: ports/raspberrypi/bindings/cyw43/__init__.c py/argcheck.c py/objexcept.c #: shared-bindings/canio/CAN.c shared-bindings/digitalio/Pull.c @@ -830,11 +830,11 @@ msgstr "Liánjiē yǐ duàn kāi, wúfǎ zài shǐyòng. Chuàngjiàn yīgè xī #: shared-bindings/bitmaptools/__init__.c msgid "Coordinate arrays have different lengths" -msgstr "" +msgstr "zuòbiāo shùzǔ jùyǒu bùtóng de chángdù" #: shared-bindings/bitmaptools/__init__.c msgid "Coordinate arrays types have different sizes" -msgstr "" +msgstr "zuòbiāo shùzǔ lèixíng jùyǒu bùtóng de dàxiǎo" #: py/persistentcode.c msgid "Corrupt .mpy file" @@ -1284,7 +1284,7 @@ msgstr "Wúxiào de BSSID" #: main.c msgid "Invalid CIRCUITPY_PYSTACK_SIZE\n" -msgstr "" +msgstr "wú xiào CIRCUITPY_PYSTACK_SIZE\n" #: shared-bindings/wifi/Radio.c msgid "Invalid MAC address" @@ -1310,7 +1310,7 @@ msgstr "wú xiào data_pins[%d]" #: shared-module/msgpack/__init__.c msgid "Invalid format" -msgstr "" +msgstr "géshì wúxiào" #: shared-module/audiocore/WaveFile.c msgid "Invalid format chunk size" @@ -1985,7 +1985,7 @@ msgstr "bǐ lì chǐ cùn bì xū chú yǐ 3" #: ports/espressif/common-hal/_bleio/Adapter.c #: ports/nrf/common-hal/_bleio/Adapter.c msgid "Scan already in progress. Stop with stop_scan." -msgstr "" +msgstr "Sǎomiáo yǐ zài jìnxíng zhōng. Shǐyòng stop_scan tíngzhǐ." #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/atmel-samd/common-hal/audiobusio/PDMIn.c @@ -2302,7 +2302,7 @@ msgstr "wèi zhī de BLE cuò wù: %d" #: ports/raspberrypi/common-hal/wifi/__init__.c #, c-format msgid "Unknown error code %d" -msgstr "" +msgstr "Wèizhī cuòwù dàimǎ %d" #: shared-bindings/wifi/Radio.c #, c-format From add8f06b758bca93f513d32df66c72fbde2cf7ee Mon Sep 17 00:00:00 2001 From: applecuckoo <113647417+applecuckoo@users.noreply.github.com> Date: Mon, 10 Apr 2023 15:27:15 +1200 Subject: [PATCH 012/117] urandom is supported on nRF boards --- shared-bindings/os/__init__.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/os/__init__.c b/shared-bindings/os/__init__.c index b2fb8ff095..e9e5f0885f 100644 --- a/shared-bindings/os/__init__.c +++ b/shared-bindings/os/__init__.c @@ -241,7 +241,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(os_sync_obj, os_sync); //| """Returns a string of *size* random bytes based on a hardware True Random //| Number Generator. When not available, it will raise a NotImplementedError. //| -//| **Limitations:** Not yet available on nRF. Not available on SAMD21 due to lack of hardware. +//| **Limitations:** Not available on SAMD21 due to lack of hardware. //| """ //| ... //| From ef78dee4a5980ce8af6ff32724dce632ea14ada1 Mon Sep 17 00:00:00 2001 From: applecuckoo <113647417+applecuckoo@users.noreply.github.com> Date: Mon, 10 Apr 2023 15:33:38 +1200 Subject: [PATCH 013/117] Fix up Contributor Covenant homepage link There was a reference to a Markdown variable that has been deleted from this version, used the original Contributor Covenant as a reference. --- CODE_OF_CONDUCT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index be1966ce1e..2c17dcfe16 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -123,7 +123,7 @@ accordingly. ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], +This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 1.4, available at , and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html). From 532283d1a56953bd22cde26d56a017003d69c6ab Mon Sep 17 00:00:00 2001 From: Isaac Benitez Date: Mon, 10 Apr 2023 20:58:21 -0700 Subject: [PATCH 014/117] Replace malloc() with static varible --- supervisor/shared/web_workflow/web_workflow.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/supervisor/shared/web_workflow/web_workflow.c b/supervisor/shared/web_workflow/web_workflow.c index b640578e20..d24547dd09 100644 --- a/supervisor/shared/web_workflow/web_workflow.c +++ b/supervisor/shared/web_workflow/web_workflow.c @@ -125,6 +125,7 @@ static socketpool_socket_obj_t active; static _request active_request; static char _api_password[64]; +static char web_instance_name[50]; // Store the encoded IP so we don't duplicate work. static uint32_t _encoded_ip = 0; @@ -269,7 +270,6 @@ void supervisor_start_web_workflow(void) { char ssid[33]; char password[64]; - char web_instance_name[50]; os_getenv_err_t result = common_hal_os_getenv_str("CIRCUITPY_WIFI_SSID", ssid, sizeof(ssid)); if (result != GETENV_OK) { @@ -335,8 +335,7 @@ void supervisor_start_web_workflow(void) { mdns_server_construct(&mdns, true); mdns.base.type = &mdns_server_type; if (!common_hal_mdns_server_deinited(&mdns)) { - char *instance_name = strndup(web_instance_name, strlen(web_instance_name)); - common_hal_mdns_server_set_instance_name(&mdns, instance_name); + common_hal_mdns_server_set_instance_name(&mdns, web_instance_name); } } if (!common_hal_mdns_server_deinited(&mdns)) { From 88644613b5d161274fb4c6f77f282bd27ef05cd1 Mon Sep 17 00:00:00 2001 From: CDario Date: Tue, 11 Apr 2023 12:29:43 +0000 Subject: [PATCH 015/117] Add M5Stack Core2 --- ports/espressif/boards/m5stack_core2/axp192.h | 286 ++++++++ ports/espressif/boards/m5stack_core2/board.c | 632 ++++++++++++++++++ .../boards/m5stack_core2/mpconfigboard.h | 44 ++ .../boards/m5stack_core2/mpconfigboard.mk | 18 + ports/espressif/boards/m5stack_core2/pins.c | 93 +++ .../espressif/boards/m5stack_core2/sdkconfig | 34 + 6 files changed, 1107 insertions(+) create mode 100755 ports/espressif/boards/m5stack_core2/axp192.h create mode 100644 ports/espressif/boards/m5stack_core2/board.c create mode 100755 ports/espressif/boards/m5stack_core2/mpconfigboard.h create mode 100644 ports/espressif/boards/m5stack_core2/mpconfigboard.mk create mode 100644 ports/espressif/boards/m5stack_core2/pins.c create mode 100644 ports/espressif/boards/m5stack_core2/sdkconfig diff --git a/ports/espressif/boards/m5stack_core2/axp192.h b/ports/espressif/boards/m5stack_core2/axp192.h new file mode 100755 index 0000000000..45279ce56f --- /dev/null +++ b/ports/espressif/boards/m5stack_core2/axp192.h @@ -0,0 +1,286 @@ +/* + * + * The MIT License (MIT) + * + * Copyright (c) 2022 Stephen Oliver + * Copyright (c) 2023 CDarius + * + * 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_AXP192_H +#define MICROPY_AXP192_H + +#define AXP192_I2C_ADDRESS 0x34 + +#define AXP192_INPUT_POWER_STATE 0x00 +#define AXP192_INPUT_POWER_STATE_ACIN_IS_PRESENT 0b10000000 +#define AXP192_INPUT_POWER_STATE_ACIN_AVAILABLE 0b01000000 +#define AXP192_INPUT_POWER_STATE_VBUS_IS_PRESENT 0b00100000 +#define AXP192_INPUT_POWER_STATE_VBUS_AVAILABLE 0b00010000 +#define AXP192_INPUT_POWER_STATE_VBUS_GREATER_VHOLD_BEFORE_USE 0b00001000 +#define AXP192_INPUT_POWER_STATE_BATT_CURRENT_DIR_IS_CHARGING 0b00000100 +#define AXP192_INPUT_POWER_STATE_ACIN_VBUS_PCB_SHORTED 0b00000010 +#define AXP192_INPUT_POWER_STATE_BOOT_SOURCE_ACIN_OR_VBUS 0b00000001 + +#define AXP192_EXTEN_DCDC2_CTRL 0x10 +#define AXP192_EXTEN_DCDC2_CTRL_EXTEN 0b00000100 +#define AXP192_EXTEN_DCDC2_CTRL_DCDC2 0b00000001 + +#define AXP192_DCDC13_LDO23_CTRL 0x12 +#define AXP192_DCDC13_LDO23_CTRL_EXTEN 0b01000000 +#define AXP192_DCDC13_LDO23_CTRL_LDO3 0b00001000 +#define AXP192_DCDC13_LDO23_CTRL_LDO2 0b00000100 +#define AXP192_DCDC13_LDO23_CTRL_DCDC3 0b00000010 +#define AXP192_DCDC13_LDO23_CTRL_DCDC1 0b00000001 + +#define AXP192_DCDC2_OUT_VOLTAGE 0x25 + +#define AXP192_DCDC1_OUT_VOLTAGE 0x26 +#define AXP192_DCDC1_OUT_VOLTAGE_3_350V 0b01101010 + +#define AXP192_DCDC3_OUT_VOLTAGE 0x27 +#define AXP192_DCDC3_OUT_VOLTAGE_3_0V 0b01011100 + +#define AXP192_LDO23_OUT_VOLTAGE 0x28 +#define AXP192_LDO23_OUT_VOLTAGE_LDO2_3_3V 0b11110000 +#define AXP192_LDO23_OUT_VOLTAGE_LDO2_3_0V 0b11000000 +#define AXP192_LDO23_OUT_VOLTAGE_LDO2_2_8V 0b10100000 +#define AXP192_LDO23_OUT_VOLTAGE_LDO2_MASK 0b11110000 +#define AXP192_LDO23_OUT_VOLTAGE_LDO3_3_0V 0b00001100 +#define AXP192_LDO23_OUT_VOLTAGE_LDO3_2_8V 0b00001010 +#define AXP192_LDO23_OUT_VOLTAGE_LDO3_1_8V 0b00000000 +#define AXP192_LDO23_OUT_VOLTAGE_LDO3_MASK 0b00001111 + +#define AXP192_VBUS_IPSOUT 0x30 +#define AXP192_VBUS_IPSOUT_IGNORE_VBUSEN 0b10000000 +#define AXP192_VBUS_IPSOUT_VHOLD_LIMIT 0b01000000 +#define AXP192_VBUS_IPSOUT_VHOLD_VOLTAGE_4_4V 0b00100000 +#define AXP192_VBUS_IPSOUT_VHOLD_VOLTAGE_MASK 0b00111000 +#define AXP192_VBUS_IPSOUT_VBUS_LIMIT_CURRENT 0b00000010 +#define AXP192_VBUS_IPSOUT_VBUS_LIMIT_CURRENT_100mA 0b00000001 +#define AXP192_VBUS_IPSOUT_VBUS_LIMIT_CURRENT_500mA 0b00000000 + +#define AXP192_POWER_OFF_VOLTAGE 0x31 +#define AXP192_POWER_OFF_VOLTAGE_2_6V 0b0000 +#define AXP192_POWER_OFF_VOLTAGE_2_7V 0b0001 +#define AXP192_POWER_OFF_VOLTAGE_2_8V 0b0010 +#define AXP192_POWER_OFF_VOLTAGE_2_9V 0b0011 +#define AXP192_POWER_OFF_VOLTAGE_3_0V 0b0100 +#define AXP192_POWER_OFF_VOLTAGE_3_1V 0b0101 +#define AXP192_POWER_OFF_VOLTAGE_3_2V 0b0110 +#define AXP192_POWER_OFF_VOLTAGE_3_3V 0b0111 +#define AXP192_POWER_OFF_VOLTAGE_MASK 0b0111 + +#define AXP192_POWER_OFF_BATT_CHGLED_CTRL 0x32 +#define AXP192_POWER_OFF_BATT_CHGLED_CTRL_OFF 0b10000000 +#define AXP192_POWER_OFF_BATT_CHGLED_CTRL_BATT_MONITOR_ON 0b01000000 +#define AXP192_POWER_OFF_BATT_CHGLED_CTRL_N_OE_SHUTDOWN_DELAY_3_0S 0b00000011 +#define AXP192_POWER_OFF_BATT_CHGLED_CTRL_N_OE_SHUTDOWN_DELAY_2_0S 0b00000010 +#define AXP192_POWER_OFF_BATT_CHGLED_CTRL_N_OE_SHUTDOWN_DELAY_1_0S 0b00000001 +#define AXP192_POWER_OFF_BATT_CHGLED_CTRL_N_OE_SHUTDOWN_DELAY_0_5S 0b00000000 + +#define AXP192_CHARGING_CTRL1 0x33 +#define AXP192_CHARGING_CTRL1_ENABLE 0b10000000 +#define AXP192_CHARGING_CTRL1_VOLTAGE_4_36V 0b01100000 +#define AXP192_CHARGING_CTRL1_VOLTAGE_4_20V 0b01000000 +#define AXP192_CHARGING_CTRL1_VOLTAGE_4_15V 0b00100000 +#define AXP192_CHARGING_CTRL1_VOLTAGE_4_10V 0b00000000 +#define AXP192_CHARGING_CTRL1_VOLTAGE_MASK 0b01100000 +#define AXP192_CHARGING_CTRL1_CHARGING_THRESH_15PERC 0b00010000 +#define AXP192_CHARGING_CTRL1_CHARGING_THRESH_10PERC 0b00000000 +#define AXP192_CHARGING_CTRL1_CHARGING_THRESH_MASK 0b00010000 +#define AXP192_CHARGING_CTRL1_CURRENT_100mA 0b00000000 +#define AXP192_CHARGING_CTRL1_CURRENT_190mA 0b00000001 +#define AXP192_CHARGING_CTRL1_CURRENT_280mA 0b00000010 +#define AXP192_CHARGING_CTRL1_CURRENT_360mA 0b00000011 +#define AXP192_CHARGING_CTRL1_CURRENT_450mA 0b00000100 +#define AXP192_CHARGING_CTRL1_CURRENT_550mA 0b00000101 +#define AXP192_CHARGING_CTRL1_CURRENT_630mA 0b00000110 +#define AXP192_CHARGING_CTRL1_CURRENT_700mA 0b00000111 +#define AXP192_CHARGING_CTRL1_CURRENT_780mA 0b00001000 +#define AXP192_CHARGING_CTRL1_CURRENT_880mA 0b00001001 +#define AXP192_CHARGING_CTRL1_CURRENT_960mA 0b00001010 +#define AXP192_CHARGING_CTRL1_CURRENT_1000mA 0b00001011 + +#define AXP192_CHARGING_CTRL1_CURRENT_MASK 0b00001111 + +#define AXP192_CHARGING_CTRL2 0x34 + +#define AXP192_BACKUP_BATT 0x35 +#define AXP192_BACKUP_BATT_CHARGING_ENABLE 0b10000000 +#define AXP192_BACKUP_BATT_CHARGING_VOLTAGE_2_5V 0b01100000 +#define AXP192_BACKUP_BATT_CHARGING_VOLTAGE_3_0V 0b00100000 +#define AXP192_BACKUP_BATT_CHARGING_VOLTAGE_3_1V 0b00000000 +#define AXP192_BACKUP_BATT_CHARGING_VOLTAGE_MASK 0b01100000 +#define AXP192_BACKUP_BATT_CHARGING_CURRENT_400uA 0b00000011 +#define AXP192_BACKUP_BATT_CHARGING_CURRENT_200uA 0b00000010 +#define AXP192_BACKUP_BATT_CHARGING_CURRENT_100uA 0b00000001 +#define AXP192_BACKUP_BATT_CHARGING_CURRENT_50uA 0b00000000 +#define AXP192_BACKUP_BATT_CHARGING_CURRENT_MASK 0b00000011 + +#define AXP192_PEK 0x36 +#define AXP192_PEK_SHORT_PRESS_1S 0b11000000 +#define AXP192_PEK_SHORT_PRESS_512mS 0b10000000 +#define AXP192_PEK_SHORT_PRESS_256mS 0b01000000 +#define AXP192_PEK_SHORT_PRESS_128mS 0b00000000 +#define AXP192_PEK_SHORT_PRESS_MASK 0b11000000 +#define AXP192_PEK_LONG_PRESS_2_5S 0b00110000 +#define AXP192_PEK_LONG_PRESS_2_0S 0b00100000 +#define AXP192_PEK_LONG_PRESS_1_5S 0b00010000 +#define AXP192_PEK_LONG_PRESS_1_0S 0b00000000 +#define AXP192_PEK_LONG_PRESS_MASK 0b00110000 +#define AXP192_PEK_LONG_PRESS_POWER_OFF 0b00001000 +#define AXP192_PEK_PWROK_DELAY_64mS 0b00000100 +#define AXP192_PEK_PWROK_DELAY_32mS 0b00000000 +#define AXP192_PEK_PWROK_DELAY_MASK 0b00000100 +#define AXP192_PEK_POWER_OFF_TIME_12S 0b00000011 +#define AXP192_PEK_POWER_OFF_TIME_8S 0b00000010 +#define AXP192_PEK_POWER_OFF_TIME_6S 0b00000001 +#define AXP192_PEK_POWER_OFF_TIME_4S 0b00000000 +#define AXP192_PEK_POWER_OFF_TIME_MASK 0b00000011 + +#define AXP192_BATT_TEMP_LOW_THRESH 0x38 +#define AXP192_BATT_TEMP_HIGH_THRESH 0x39 +#define AXP192_BATT_TEMP_HIGH_THRESH_DEFAULT 0b11111100 + +#define AXP192_APS_LOW_BATT_LEVEL_1 0x3A +#define AXP192_APS_LOW_BATT_LEVEL_2 0x3B +#define AXP192_APS_LOW_BATT_VOLTAGE_3_695V 0b10010100 +#define AXP192_APS_LOW_BATT_VOLTAGE_3_600V 0b10000011 + +#define AXP192_IRQ_1_ENABLE 0x40 +#define AXP192_IRQ_2_ENABLE 0x41 +#define AXP192_IRQ_3_ENABLE 0x42 +#define AXP192_IRQ_3_PEK_SHORT_PRESS 0b00000010 +#define AXP192_IRQ_3_PEK_LONG_PRESS 0b00000001 +#define AXP192_IRQ_4_ENABLE 0x43 +#define AXP192_IRQ_4_LOW_VOLTAGE_WARNING 0b00000001 +#define AXP192_IRQ_5_ENABLE 0x4a + +#define AXP192_IRQ_X_DISABLE_ALL 0b00000000 + +#define AXP192_IRQ_1_STATUS 0x44 +#define AXP192_IRQ_2_STATUS 0x45 +#define AXP192_IRQ_3_STATUS 0x46 +#define AXP192_IRQ_4_STATUS 0x47 +#define AXP192_IRQ_5_STATUS 0x4d + +#define AXP192_IRQ_X_CLEAR_STATUS 0b11111111 + +#define AXP192_ADC_ACIN_VOLTAGE_H 0x56 +#define AXP192_ADC_ACIN_VOLTAGE_L 0x57 +#define AXP192_ADC_ACIN_CURRENT_H 0x58 +#define AXP192_ADC_ACIN_CURRENT_L 0x59 +#define AXP192_ADC_VBUS_VOLTAGE_H 0x5a +#define AXP192_ADC_VBUS_VOLTAGE_L 0x5b +#define AXP192_ADC_VBUS_CURRENT_H 0x5c +#define AXP192_ADC_VBUS_CURRENT_L 0x5d +#define AXP192_ADC_INTERNAL_TEMP_H 0x5e +#define AXP192_ADC_INTERNAL_TEMP_L 0x5f + +#define AXP192_ADC_BATT_VOLTAGE_H 0x78 +#define AXP192_ADC_BATT_VOLTAGE_L 0x79 + +#define AXP192_ADC_BATT_POWER_H 0x70 +#define AXP192_ADC_BATT_POWER_M 0x71 +#define AXP192_ADC_BATT_POWER_L 0x72 + +#define AXP192_ADC_BATT_CHARGE_CURRENT_H 0x7a +#define AXP192_ADC_BATT_CHARGE_CURRENT_L 0x7b +#define AXP192_ADC_BATT_DISCHARGE_CURRENT_H 0x7c +#define AXP192_ADC_BATT_DISCHARGE_CURRENT_L 0x7d +#define AXP192_ADC_APS_VOLTAGE_H 0x7e +#define AXP192_ADC_APS_VOLTAGE_L 0x7f + +#define AXP192_ADC_ENABLE_1 0x82 +#define AXP192_ADC_ENABLE_1_BATT_VOL 0b10000000 +#define AXP192_ADC_ENABLE_1_BATT_CUR 0b01000000 +#define AXP192_ADC_ENABLE_1_ACIN_VOL 0b00100000 +#define AXP192_ADC_ENABLE_1_ACIN_CUR 0b00010000 +#define AXP192_ADC_ENABLE_1_VBUS_VOL 0b00001000 +#define AXP192_ADC_ENABLE_1_VBUS_CUR 0b00000100 +#define AXP192_ADC_ENABLE_1_APS_VOL 0b00000010 +#define AXP192_ADC_ENABLE_1_TS_PIN 0b00000001 + +#define AXP192_ADC_ENABLE_2 0x83 +#define AXP192_ADC_ENABLE_2_TEMP_MON 0b10000000 +#define AXP192_ADC_ENABLE_2_GPIO0 0b00001000 +#define AXP192_ADC_ENABLE_2_GPIO1 0b00000100 +#define AXP192_ADC_ENABLE_2_GPIO2 0b00000010 +#define AXP192_ADC_ENABLE_2_GPIO3 0b00000001 + +#define AXP192_ADC_TS 0x84 +#define AXP192_ADC_TS_SAMPLE_200HZ 0b11000000 +#define AXP192_ADC_TS_SAMPLE_100HZ 0b10000000 +#define AXP192_ADC_TS_SAMPLE_50HZ 0b01000000 +#define AXP192_ADC_TS_SAMPLE_25HZ 0b00000000 +#define AXP192_ADC_TS_SAMPLE_MASK 0b11000000 +#define AXP192_ADC_TS_OUT_CUR_80uA 0b00110000 +#define AXP192_ADC_TS_OUT_CUR_60uA 0b00100000 +#define AXP192_ADC_TS_OUT_CUR_40uA 0b00010000 +#define AXP192_ADC_TS_OUT_CUR_20uA 0b00000000 +#define AXP192_ADC_TS_OUT_CUR_MASK 0b00110000 +#define AXP192_ADC_TS_PIN_TEMP_MON 0b00000000 +#define AXP192_ADC_TS_PIN_EXTERN_ADC 0b00000100 +#define AXP192_ADC_TS_PIN_OUT_ALWAYS 0b00000011 +#define AXP192_ADC_TS_PIN_OUT_SAVE_ENG 0b00000010 +#define AXP192_ADC_TS_PIN_OUT_CHG 0b00000001 +#define AXP192_ADC_TS_PIN_OUT_DIS 0b00000000 +#define AXP192_ADC_TS_PIN_OUT_MASK 0b00000011 + +#define AXP192_GPIO0_FUNCTION 0x90 +#define AXP192_GPIO0_FUNCTION_MASK 0b00000111 +#define AXP192_GPIO0_FUNCTION_FLOATING 0b00000111 +#define AXP192_GPIO0_FUNCTION_LOW_OUTPUT 0b00000101 +#define AXP192_GPIO0_FUNCTION_ADC_INPUT 0b00000100 +#define AXP192_GPIO0_FUNCTION_LDO_OUTPUT 0b00000010 +#define AXP192_GPIO0_FUNCTION_GENERAL_INPUT 0b00000001 +#define AXP192_GPIO0_FUNCTION_OPEN_DRAIN_OUTPUT 0b00000000 + +#define AXP192_GPIO0_LDO_VOLTAGE 0x91 +#define AXP192_GPIO0_LDO_VOLTAGE_MASK 0b11110000 +#define AXP192_GPIO0_LDO_VOLTAGE_3_3V 0b11110000 +#define AXP192_GPIO0_LDO_VOLTAGE_2_8V 0b10100000 +#define AXP192_GPIO0_LDO_VOLTAGE_1_8V 0b00000000 + + +#define AXP192_GPIO1_FUNCTION 0x92 +#define AXP192_GPIO1_FUNCTION_FLOATING 0b00000111 +#define AXP192_GPIO1_FUNCTION_LOW_OUTPUT 0b00000101 +#define AXP192_GPIO1_FUNCTION_ADC_INPUT 0b00000100 +#define AXP192_GPIO1_FUNCTION_PWM1_OUTPUT 0b00000010 +#define AXP192_GPIO1_FUNCTION_GENERAL_INPUT 0b00000001 +#define AXP192_GPIO1_FUNCTION_OPEN_DRAIN_OUTPUT 0b00000000 + + +#define AXP192_GPIO2_FUNCTION 0x93 +#define AXP192_GPIO2_FUNCTION_FLOATING 0b00000111 +#define AXP192_GPIO2_FUNCTION_LOW_OUTPUT 0b00000101 +#define AXP192_GPIO2_FUNCTION_ADC_INPUT 0b00000100 +#define AXP192_GPIO2_FUNCTION_PWM2_OUTPUT 0b00000010 +#define AXP192_GPIO2_FUNCTION_GENERAL_INPUT 0b00000001 +#define AXP192_GPIO2_FUNCTION_OPEN_DRAIN_OUTPUT 0b00000000 + +#define AXP192_PWM1_OUTPUT_FREQUECY 0x98 +#define AXP192_PWM1_DUTY_RATIO_Y1 0x99 +#define AXP192_PWM1_DUTY_RATIO_Y2 0x9A + +#endif diff --git a/ports/espressif/boards/m5stack_core2/board.c b/ports/espressif/boards/m5stack_core2/board.c new file mode 100644 index 0000000000..f0f0d701b3 --- /dev/null +++ b/ports/espressif/boards/m5stack_core2/board.c @@ -0,0 +1,632 @@ +/* + * + * The MIT License (MIT) + * + * Copyright (c) 2023 CDarius + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" +#include "mpconfigboard.h" +#include "shared-bindings/busio/SPI.h" +#include "shared-bindings/busio/I2C.h" +#include "shared-bindings/displayio/FourWire.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-module/displayio/__init__.h" +#include "shared-module/displayio/mipi_constants.h" +#include "shared-bindings/board/__init__.h" + +#include "shared-bindings/microcontroller/Pin.h" +#include "components/driver/include/driver/gpio.h" +#include "components/hal/include/hal/gpio_hal.h" +#include "common-hal/microcontroller/Pin.h" + +#include "axp192.h" + +displayio_fourwire_obj_t board_display_obj; + +#define DELAY 0x80 +#define PMIC_POWER_SOURCE_USB 0 +#define PMIC_POWER_SOURCE_M_BUS 1 + +// display init sequence according to M5Gfx +uint8_t display_init_sequence[] = { + 0x01,DELAY,0x80, // Software reset then delay 0x80 (128ms) + 0xC8,0x03,0xFF,0x93,0x42, // Turn on the external command + 0xC0,0x02,0x12, 0x12, // Power Control 1 + 0xC1,0x01,0x03, // Power Control 2 + 0xC5,0x01,0xF2, // VCOM Control 1 + 0xB0,0x01,0xE0, // RGB Interface SYNC Mode + 0xF6,0x03,0x01, 0x00, 0x00, // Interface control + 0XE0,0x0F,0x00,0x0C,0x11,0x04,0x11,0x08,0x37,0x89,0x4C,0x06,0x0C,0x0A,0x2E,0x34,0x0F, // Positive Gamma Correction + 0xE1,0x0F,0x00,0x0B,0x11,0x05,0x13,0x09,0x33,0x67,0x48,0x07,0x0E,0x0B,0x2E,0x33,0x0F, // Negative Gamma Correction + 0xB6,0x04,0x08,0x82,0x1D,0x04, // Display Function Control + 0x3A,0x01,0x55, // COLMOD: Pixel Format Set 16 bit + 0x21,0x00, // Display inversion ON + 0x36,0x01,0x08, // Memory Access Control: RGB order + 0x11,DELAY,0x78, // Exit Sleep then delay 0x78 (120ms) + 0x29,DELAY,0x78, // Display on then delay 0x78 (120ms) +}; + +static bool pmic_set_power_source(uint8_t source, busio_i2c_obj_t *internal_i2c) { + int rc; + uint8_t read_buf[1]; + uint8_t write_buf[2]; + + switch (source) + { + case PMIC_POWER_SOURCE_USB: + // Set GPIO to 3.3V (when LDO OUTPUT mode is active) + write_buf[0] = AXP192_GPIO0_LDO_VOLTAGE; + rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); + if (rc != 0) { + return false; + } + write_buf[1] = (read_buf[0] & ~AXP192_GPIO0_LDO_VOLTAGE_MASK) | AXP192_GPIO0_LDO_VOLTAGE_3_3V; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + // Set GPIO0 to LDO_OUTPUT to set N_VBUSEN high + // When N_VBUSEN is high IPSOUT do not select VBUS as source (BUS_5V) + write_buf[0] = AXP192_GPIO0_FUNCTION; + rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); + if (rc != 0) { + return false; + } + write_buf[1] = (read_buf[0] & ~AXP192_GPIO0_FUNCTION_MASK) | AXP192_GPIO0_FUNCTION_LDO_OUTPUT; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + #if M5STACK_CORE2_5V_OUTPUT_ENABLE_DEFAULT + // Set EXTENT output high to enable 5V power boost + write_buf[0] = AXP192_EXTEN_DCDC2_CTRL; + rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); + if (rc != 0) { + return false; + } + write_buf[1] = read_buf[0] | AXP192_EXTEN_DCDC2_CTRL_EXTEN; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + #endif + + // Enable VBUS-IPSOUT when N_VBUSEN is high + write_buf[0] = AXP192_VBUS_IPSOUT; + rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); + if (rc != 0) { + return false; + } + write_buf[1] = read_buf[0] & ~AXP192_VBUS_IPSOUT_IGNORE_VBUSEN; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + return true; + + case PMIC_POWER_SOURCE_M_BUS: + // Enable VBUS-IPSOUT regardless of f N_VBUSEN + write_buf[0] = AXP192_VBUS_IPSOUT; + rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); + if (rc != 0) { + return false; + } + write_buf[1] = read_buf[0] | AXP192_VBUS_IPSOUT_IGNORE_VBUSEN; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Set EXTENT output low to disable 5V power boost + write_buf[0] = AXP192_EXTEN_DCDC2_CTRL; + rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); + if (rc != 0) { + return false; + } + write_buf[1] = read_buf[0] & ~AXP192_EXTEN_DCDC2_CTRL_EXTEN; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Set GPIO0 to float and the pull down resistor set N_VBUSEN low + // When N_VBUSEN is low IPSOUT select VBUS as source (BUS_5V) + write_buf[0] = AXP192_GPIO0_FUNCTION; + rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); + if (rc != 0) { + return false; + } + write_buf[1] = (read_buf[0] & ~AXP192_GPIO0_FUNCTION_MASK) | AXP192_GPIO0_FUNCTION_FLOATING; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + return true; + + default: + return false; + } +} + +static bool pmic_disable_all_irq(busio_i2c_obj_t *i2c) { + int rc; + // uint8_t read_buf[1]; + uint8_t write_buf[2]; + + // Reg: 40h + // IRQ enable control register 1 + write_buf[0] = AXP192_IRQ_1_ENABLE; + write_buf[1] = AXP192_IRQ_X_DISABLE_ALL; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 41h + // IRQ enable control register 2 + write_buf[0] = AXP192_IRQ_2_ENABLE; + write_buf[1] = AXP192_IRQ_X_DISABLE_ALL; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 42h + // IRQ enable control register 3 + // Enable power on key short and long press interrupt + write_buf[0] = AXP192_IRQ_3_ENABLE; + write_buf[1] = AXP192_IRQ_X_DISABLE_ALL; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 43h + // IRQ enable control register 4 + // Enable power on key short and long press interrupt + write_buf[0] = AXP192_IRQ_4_ENABLE; + write_buf[1] = AXP192_IRQ_X_DISABLE_ALL; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 4Ah + // IRQ enable control register 5 + write_buf[0] = AXP192_IRQ_5_ENABLE; + write_buf[1] = AXP192_IRQ_X_DISABLE_ALL; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + return true; +} + +static bool pmic_clear_all_irq(busio_i2c_obj_t *i2c) { + int rc; + // uint8_t read_buf[1]; + uint8_t write_buf[2]; + + // Reg: 44h + // IRQ enable control register 1 + write_buf[0] = AXP192_IRQ_1_STATUS; + write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 45h + // IRQ enable control register 2 + write_buf[0] = AXP192_IRQ_2_STATUS; + write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 46h + // IRQ enable control register 3 + write_buf[0] = AXP192_IRQ_3_STATUS; + write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 47h + // IRQ enable control register 4 + write_buf[0] = AXP192_IRQ_4_STATUS; + write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 4Ah + // IRQ enable control register 5 + write_buf[0] = AXP192_IRQ_5_STATUS; + write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + return true; +} + +static bool pmic_enable_default_irq(busio_i2c_obj_t *i2c) { + int rc; + // uint8_t read_buf[1]; + uint8_t write_buf[2]; + + // Reg: 42h + // IRQ enable control register 3 + // Enable power on key short and long press interrupt + write_buf[0] = AXP192_IRQ_2_ENABLE; + write_buf[1] = AXP192_IRQ_3_PEK_SHORT_PRESS | + AXP192_IRQ_3_PEK_LONG_PRESS; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 43h + // IRQ enable control register 4 + // Enable power on key short and long press interrupt + write_buf[0] = AXP192_IRQ_2_ENABLE; + write_buf[1] = AXP192_IRQ_4_LOW_VOLTAGE_WARNING; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + return true; +} + +static bool pmic_init(busio_i2c_obj_t *internal_i2c) { + int rc; + uint8_t read_buf[1]; + uint8_t write_buf[2]; + + // Reg: 30h + // The VBUS-IPSOUT path can be selected to be opened regardless of the status of N_VBUSEN + // VBUS VHOLD pressure limit control disabled + // VBUS current limit control enabled + write_buf[0] = AXP192_VBUS_IPSOUT; + write_buf[1] = AXP192_VBUS_IPSOUT_VBUS_LIMIT_CURRENT | + AXP192_VBUS_IPSOUT_VBUS_LIMIT_CURRENT_500mA; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 31h + // VOFF Shutdown voltage setting ( 3.0V ) + write_buf[0] = AXP192_POWER_OFF_VOLTAGE; + write_buf[1] = AXP192_POWER_OFF_VOLTAGE_3_0V; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 32h + // Charge function enable control bit, including internal and external channels + // Charging target voltage: 4.2V + // Charging end current: End charging when charging current is less than 10% setting + // Internal path charging current: 100mA + write_buf[0] = AXP192_POWER_OFF_BATT_CHGLED_CTRL; + write_buf[1] = AXP192_POWER_OFF_BATT_CHGLED_CTRL_BATT_MONITOR_ON | + AXP192_POWER_OFF_BATT_CHGLED_CTRL_N_OE_SHUTDOWN_DELAY_2_0S; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 33h + // Charge function enable control bit, including internal and external channels + // Charging target voltage: 4.2V + // Charging end current: End charging when charging current is less than 10% setting + // Internal path charging current: 100mA + write_buf[0] = AXP192_CHARGING_CTRL1; + write_buf[1] = AXP192_CHARGING_CTRL1_ENABLE | + AXP192_CHARGING_CTRL1_VOLTAGE_4_20V | + AXP192_CHARGING_CTRL1_CHARGING_THRESH_10PERC | + AXP192_CHARGING_CTRL1_CURRENT_360mA; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 35h + // Enable RTC battery charge: 3.0V, 200uA + write_buf[0] = AXP192_BACKUP_BATT; + write_buf[1] = AXP192_BACKUP_BATT_CHARGING_ENABLE | + AXP192_BACKUP_BATT_CHARGING_VOLTAGE_3_0V | + AXP192_BACKUP_BATT_CHARGING_CURRENT_200uA; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 36h + // Power on: Short press 128ms + // Power off: Long press 1s + // Power OK delay 64ms + // Power off delay 4s + write_buf[0] = AXP192_PEK; + write_buf[1] = AXP192_PEK_SHORT_PRESS_128mS | + AXP192_PEK_LONG_PRESS_1_0S | + AXP192_PEK_LONG_PRESS_POWER_OFF | + AXP192_PEK_PWROK_DELAY_64mS | + AXP192_PEK_POWER_OFF_TIME_4S; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 3Ah + // APS Low battery warning level 1: 3.695V + write_buf[0] = AXP192_APS_LOW_BATT_LEVEL_1; + write_buf[1] = AXP192_APS_LOW_BATT_VOLTAGE_3_695V; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 3Bh + // APS Low battery warning level 2: 3.600V + write_buf[0] = AXP192_APS_LOW_BATT_LEVEL_2; + write_buf[1] = AXP192_APS_LOW_BATT_VOLTAGE_3_600V; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 82h + // ADC all on + write_buf[0] = AXP192_ADC_ENABLE_1; + write_buf[1] = AXP192_ADC_ENABLE_1_BATT_VOL | + AXP192_ADC_ENABLE_1_BATT_CUR | + AXP192_ADC_ENABLE_1_ACIN_VOL | + AXP192_ADC_ENABLE_1_ACIN_CUR | + AXP192_ADC_ENABLE_1_VBUS_VOL | + AXP192_ADC_ENABLE_1_VBUS_CUR | + AXP192_ADC_ENABLE_1_APS_VOL | + AXP192_ADC_ENABLE_1_TS_PIN; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 83h + // ADC temperature on + write_buf[0] = AXP192_ADC_ENABLE_2; + write_buf[1] = AXP192_ADC_ENABLE_2_TEMP_MON; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 84h + // ADC 25Hz + write_buf[0] = AXP192_ADC_TS; + write_buf[1] = AXP192_ADC_TS_SAMPLE_25HZ | + AXP192_ADC_TS_OUT_CUR_80uA | + AXP192_ADC_TS_PIN_TEMP_MON | + AXP192_ADC_TS_PIN_OUT_SAVE_ENG; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 98h + // PWM1 frequency + write_buf[0] = AXP192_PWM1_OUTPUT_FREQUECY; + write_buf[1] = 0x00; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 99h + // PWM1 duty cycle Y1 + write_buf[0] = AXP192_PWM1_DUTY_RATIO_Y1; + write_buf[1] = 0xFF; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 9Ah + // PWM1 duty cycle Y2 + write_buf[0] = AXP192_PWM1_DUTY_RATIO_Y2; + write_buf[1] = 0xFF; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 93h + // Speaker off (GPIO2 output low) + write_buf[0] = AXP192_GPIO2_FUNCTION; + write_buf[1] = AXP192_GPIO2_FUNCTION_LOW_OUTPUT; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 28h + // LDO2 (SD + TFT Logic): 3.3V + // LDO3 (Vibration motore): Set to minimum voltage 1.8V + write_buf[0] = AXP192_LDO23_OUT_VOLTAGE; + write_buf[1] = AXP192_LDO23_OUT_VOLTAGE_LDO2_3_3V | + AXP192_LDO23_OUT_VOLTAGE_LDO3_1_8V; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 26h + // DCDC1 (ESP32 VDD): 3.350V + write_buf[0] = AXP192_DCDC1_OUT_VOLTAGE; + write_buf[1] = AXP192_DCDC1_OUT_VOLTAGE_3_350V; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 27h + // DCDC3 (TFT backlight): 3.0V + write_buf[0] = AXP192_DCDC3_OUT_VOLTAGE; + write_buf[1] = AXP192_DCDC3_OUT_VOLTAGE_3_0V; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 12h + // Enable: + // DCDC1 ESP32 VDD, touch screen and 3.3V on M-Bus + // DCDC3 LCD backlight + // LDO2 LCD logic and SD card + write_buf[0] = AXP192_DCDC13_LDO23_CTRL; + write_buf[1] = AXP192_DCDC13_LDO23_CTRL_LDO2 | + AXP192_DCDC13_LDO23_CTRL_DCDC3 | + AXP192_DCDC13_LDO23_CTRL_DCDC1; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 92h + // Set GPIO1 Sys green LED output as PWM + // PWM duty cycle is set to 100% therefore sys led is off + write_buf[0] = AXP192_GPIO1_FUNCTION; + write_buf[1] = AXP192_GPIO1_FUNCTION_PWM1_OUTPUT; + rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + /* + * Select power source: + * If there is voltage on VBUS means that BUS_5V is powered from M-BUS + * and it can use VBUS as power source. If no voltage is present on VBUS + * disable VBUS and rely on ACIN (USB_5V) as power source. + */ + write_buf[0] = AXP192_INPUT_POWER_STATE; + rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); + if (rc != 0) { + return false; + } + uint8_t powersource = (read_buf[0] & AXP192_INPUT_POWER_STATE_VBUS_AVAILABLE) ? + PMIC_POWER_SOURCE_M_BUS : PMIC_POWER_SOURCE_USB; + if (!pmic_set_power_source(powersource, internal_i2c)) { + return false; + } + + if (!pmic_disable_all_irq(internal_i2c)) { + return false; + } + + if (!pmic_clear_all_irq(internal_i2c)) { + return false; + } + + if (!pmic_enable_default_irq(internal_i2c)) { + return false; + } + + return true; +} + +static bool display_init(void) { + busio_spi_obj_t *spi = common_hal_board_create_spi(0); + displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; + bus->base.type = &displayio_fourwire_type; + + common_hal_displayio_fourwire_construct( + bus, + spi, + &pin_GPIO15, // DC + &pin_GPIO5, // CS + NULL, // RST + 32000000, // baudrate + 0, // polarity + 0 // phase + ); + + displayio_display_obj_t *display = &displays[0].display; + display->base.type = &displayio_display_type; + + common_hal_displayio_display_construct( + display, + bus, + 320, // width (after rotation) + 240, // height (after rotation) + 0, // column start + 0, // row start + 0, // rotation + 16, // color depth + false, // grayscale + false, // pixels in a byte share a row. Only valid for depths < 8 + 1, // bytes per cell. Only valid for depths < 8 + false, // reverse_pixels_in_byte. Only valid for depths < 8 + true, // reverse_pixels_in_word + MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command + MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command + MIPI_COMMAND_WRITE_MEMORY_START, // write memory command + display_init_sequence, + sizeof(display_init_sequence), + NULL, // backlight pin + NO_BRIGHTNESS_COMMAND, + 1.0f, // brightness + false, // single_byte_bounds + false, // data_as_commands + true, // auto_refresh + 61, // native_frames_per_second + true, // backlight_on_high + false, // SH1107_addressing + 50000 // backlight pwm frequency + ); + + return true; +} + +void board_init(void) { + busio_i2c_obj_t *internal_i2c = common_hal_board_create_i2c(0); + + if (!pmic_init(internal_i2c)) { + mp_printf(&mp_plat_print, "could not initialize axp192 pmic\n"); + return; + } + + if (!display_init()) { + mp_printf(&mp_plat_print, "could not initialize the display"); + return; + } +} diff --git a/ports/espressif/boards/m5stack_core2/mpconfigboard.h b/ports/espressif/boards/m5stack_core2/mpconfigboard.h new file mode 100755 index 0000000000..f55f754fa7 --- /dev/null +++ b/ports/espressif/boards/m5stack_core2/mpconfigboard.h @@ -0,0 +1,44 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023 CDarius + * + * 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 "M5Stack Core2" +#define MICROPY_HW_MCU_NAME "ESP32" + +#define CIRCUITPY_BOARD_I2C (2) +#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO22, .sda = &pin_GPIO21}, \ + {.scl = &pin_GPIO33, .sda = &pin_GPIO32}} + +#define CIRCUITPY_BOARD_SPI (1) +#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO18, .mosi = &pin_GPIO23, .miso = &pin_GPIO38}} + +#define CIRCUITPY_BOARD_UART (1) +#define CIRCUITPY_BOARD_UART_PIN {{.tx = &pin_GPIO14, .rx = &pin_GPIO13}} + +// UART pins attached to the USB-serial converter chip +#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO1) +#define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO3) diff --git a/ports/espressif/boards/m5stack_core2/mpconfigboard.mk b/ports/espressif/boards/m5stack_core2/mpconfigboard.mk new file mode 100644 index 0000000000..28a098a195 --- /dev/null +++ b/ports/espressif/boards/m5stack_core2/mpconfigboard.mk @@ -0,0 +1,18 @@ +CIRCUITPY_CREATOR_ID = 0x10151015 +CIRCUITPY_CREATION_ID = 0x00320008 + +IDF_TARGET = esp32 + +CIRCUITPY_ESP_FLASH_MODE = qio +CIRCUITPY_ESP_FLASH_FREQ = 80m +CIRCUITPY_ESP_FLASH_SIZE = 16MB + +M5STACK_CORE2_5V_OUTPUT_ENABLE_DEFAULT = 1 + +CFLAGS += -DM5STACK_CORE2_5V_OUTPUT_ENABLE_DEFAULT=$(M5STACK_CORE2_5V_OUTPUT_ENABLE_DEFAULT) + +# Include these Python libraries in firmware. +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Display_Text +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_FakeRequests +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Requests diff --git a/ports/espressif/boards/m5stack_core2/pins.c b/ports/espressif/boards/m5stack_core2/pins.c new file mode 100644 index 0000000000..465006a6b6 --- /dev/null +++ b/ports/espressif/boards/m5stack_core2/pins.c @@ -0,0 +1,93 @@ +#include "shared-bindings/board/__init__.h" +#include "shared-module/displayio/__init__.h" + +CIRCUITPY_BOARD_BUS_SINGLETON(porta_i2c, i2c, 1) + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + // External pins are in silkscreen order, from top to bottom, left side, then right side + + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO23) }, + { MP_ROM_QSTR(MP_QSTR_D23), MP_ROM_PTR(&pin_GPIO23) }, + + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO38) }, + { MP_ROM_QSTR(MP_QSTR_D38), MP_ROM_PTR(&pin_GPIO38) }, + + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_D18), MP_ROM_PTR(&pin_GPIO18) }, + + { MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO3) }, + + { MP_ROM_QSTR(MP_QSTR_PORTC_RX), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_RX2), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO13) }, + + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_D21), MP_ROM_PTR(&pin_GPIO21) }, + + { MP_ROM_QSTR(MP_QSTR_PORTA_SDA), MP_ROM_PTR(&pin_GPIO32) }, + { MP_ROM_QSTR(MP_QSTR_D32), MP_ROM_PTR(&pin_GPIO32) }, + + { MP_ROM_QSTR(MP_QSTR_D27), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_A27), MP_ROM_PTR(&pin_GPIO27) }, + + { MP_ROM_QSTR(MP_QSTR_I2S_DATA_SPK), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO2) }, + + { MP_ROM_QSTR(MP_QSTR_A35), MP_ROM_PTR(&pin_GPIO35) }, + { MP_ROM_QSTR(MP_QSTR_D35), MP_ROM_PTR(&pin_GPIO35) }, + + { MP_ROM_QSTR(MP_QSTR_PORTB_IN), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_A36), MP_ROM_PTR(&pin_GPIO36) }, + { MP_ROM_QSTR(MP_QSTR_D36), MP_ROM_PTR(&pin_GPIO36) }, + + { MP_ROM_QSTR(MP_QSTR_A25), MP_ROM_PTR(&pin_GPIO25) }, + { MP_ROM_QSTR(MP_QSTR_D25), MP_ROM_PTR(&pin_GPIO25) }, + + { MP_ROM_QSTR(MP_QSTR_PORTB_OUT), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_A26), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_D26), MP_ROM_PTR(&pin_GPIO26) }, + + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO1) }, + + { MP_ROM_QSTR(MP_QSTR_PORTC_TX), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_TX2), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_GPIO14) }, + + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO22) }, + { MP_ROM_QSTR(MP_QSTR_D22), MP_ROM_PTR(&pin_GPIO22) }, + + { MP_ROM_QSTR(MP_QSTR_PORTA_SCL), MP_ROM_PTR(&pin_GPIO33) }, + { MP_ROM_QSTR(MP_QSTR_D33), MP_ROM_PTR(&pin_GPIO33) }, + + { MP_ROM_QSTR(MP_QSTR_D19), MP_ROM_PTR(&pin_GPIO19) }, + + { MP_ROM_QSTR(MP_QSTR_I2S_WS_SPK), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_I2S_PDM_CLOCK_MIC), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO0) }, + + { MP_ROM_QSTR(MP_QSTR_I2S_PDM_DATA_MIC), MP_ROM_PTR(&pin_GPIO34) }, + { MP_ROM_QSTR(MP_QSTR_D34), MP_ROM_PTR(&pin_GPIO34) }, + { MP_ROM_QSTR(MP_QSTR_A34), MP_ROM_PTR(&pin_GPIO34) }, + + // tft + { MP_ROM_QSTR(MP_QSTR_TFT_CS), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_TFT_DC), MP_ROM_PTR(&pin_GPIO15) }, + // { MP_ROM_QSTR(MP_QSTR_TFT_RESET), MP_ROM_PTR(&pin_GPIO33) }, AXP_IO4 + // { MP_ROM_QSTR(MP_QSTR_TFT_BACKLIGHT), MP_ROM_PTR(&pin_GPIO32) }, AXP_DC3 + + // sd card + { MP_ROM_QSTR(MP_QSTR_SD_CS),MP_ROM_PTR(&pin_GPIO4) }, + + // touch screen + { MP_ROM_QSTR(MP_QSTR_TOUCH_SCR_IRQ),MP_ROM_PTR(&pin_GPIO4) }, + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_PORTA_I2C), MP_ROM_PTR(&board_porta_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_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)} +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/espressif/boards/m5stack_core2/sdkconfig b/ports/espressif/boards/m5stack_core2/sdkconfig new file mode 100644 index 0000000000..47a0a18a5e --- /dev/null +++ b/ports/espressif/boards/m5stack_core2/sdkconfig @@ -0,0 +1,34 @@ +CONFIG_ESP32_ECO3_CACHE_LOCK_FIX=y +CONFIG_ESP32_SPIRAM_SUPPORT=y +CONFIG_ESP32_REV_MIN_3=y + +# +# LWIP +# +CONFIG_LWIP_LOCAL_HOSTNAME="M5StaskCore2" +# end of LWIP + +# +# SPI RAM config +# +# CONFIG_SPIRAM_TYPE_AUTO=y +# CONFIG_SPIRAM_TYPE_ESPPSRAM16 is not set +# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set +CONFIG_SPIRAM_TYPE_ESPPSRAM64=y +CONFIG_SPIRAM_SIZE=8388608 +# end of SPI RAM config + +# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set +# CONFIG_SPIRAM_RODATA is not set +CONFIG_SPIRAM_SPEED_80M=y +# CONFIG_SPIRAM_SPEED_40M is not set +# 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 From 33ddf50d388740c32c9b82f7d8ad39c4d1417083 Mon Sep 17 00:00:00 2001 From: flom84 Date: Tue, 11 Apr 2023 19:11:01 +0200 Subject: [PATCH 016/117] Revert "Enable uart over FTDI by default." This reverts commit 1fe7d2956c73dba39333d2b3248e9cf7f89d5eb2. --- ports/stm/boards/nucleo_f446re/mpconfigboard.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/stm/boards/nucleo_f446re/mpconfigboard.h b/ports/stm/boards/nucleo_f446re/mpconfigboard.h index c1d61492e4..f0155f4624 100644 --- a/ports/stm/boards/nucleo_f446re/mpconfigboard.h +++ b/ports/stm/boards/nucleo_f446re/mpconfigboard.h @@ -44,8 +44,8 @@ // #define CIRCUITPY_CONSOLE_UART_RX (&pin_PC11) // USART2 + ST link -#define CIRCUITPY_CONSOLE_UART_TX (&pin_PA02) -#define CIRCUITPY_CONSOLE_UART_RX (&pin_PA03) +// #define CIRCUITPY_CONSOLE_UART_TX (&pin_PA02) +// #define CIRCUITPY_CONSOLE_UART_RX (&pin_PA03) // Status LEDs #define MICROPY_HW_LED_STATUS (&pin_PA05) From 3ca0131ddd3026a0edb2e517ed524e51c7c93be6 Mon Sep 17 00:00:00 2001 From: flom84 Date: Tue, 11 Apr 2023 19:37:01 +0200 Subject: [PATCH 017/117] Fix mpy-cross compile error with GCC13. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - GCC13 reports the following error when compiling mpy-cross: main.c:313:6: error: conflicting types for ‘mp_import_stat’ due to enum/integer mismatch; have ‘uint(const char *)’ {aka ‘unsigned int(const char *)’} [-Werror=enum-int-mismatch] 313 | uint mp_import_stat(const char *path) { | ^~~~~~~~~~~~~~ In file included from ../py/compile.h:29, from main.c:11: ../py/lexer.h:205:18: note: previous declaration of ‘mp_import_stat’ with type ‘mp_import_stat_t(const char *)’ 205 | mp_import_stat_t mp_import_stat(const char *path); | ^~~~~~~~~~~~~~ cc1: all warnings being treated as errors make: *** [../py/mkrules.mk:62: build/main.o] Error 1 --- mpy-cross/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpy-cross/main.c b/mpy-cross/main.c index c00829be10..077e84f473 100644 --- a/mpy-cross/main.c +++ b/mpy-cross/main.c @@ -310,7 +310,7 @@ int main(int argc, char **argv) { return main_(argc, argv); } -uint mp_import_stat(const char *path) { +mp_import_stat_t mp_import_stat(const char *path) { (void)path; return MP_IMPORT_STAT_NO_EXIST; } From ed86f710c2630bc5905f4326ffbc338ed0ba9b73 Mon Sep 17 00:00:00 2001 From: CDarius Date: Thu, 13 Apr 2023 13:39:39 +0000 Subject: [PATCH 018/117] Refactored AXP192 code and moved under ports/espressif --- locale/circuitpython.pot | 13 +- ports/espressif/boards/m5stack_core2/board.c | 315 +++--------------- .../boards/m5stack_core2/mpconfigboard.mk | 2 + .../espressif/boards/m5stack_stick_c/axp192.h | 263 --------------- .../espressif/boards/m5stack_stick_c/board.c | 162 ++------- .../boards/m5stack_stick_c/mpconfigboard.mk | 2 + ports/espressif/pmic/axp192/axp192.c | 255 ++++++++++++++ .../m5stack_core2 => pmic/axp192}/axp192.h | 8 + 8 files changed, 335 insertions(+), 685 deletions(-) delete mode 100755 ports/espressif/boards/m5stack_stick_c/axp192.h create mode 100644 ports/espressif/pmic/axp192/axp192.c rename ports/espressif/{boards/m5stack_core2 => pmic/axp192}/axp192.h (97%) diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index f87fc02975..9df2093107 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -98,6 +98,9 @@ msgstr "" #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c msgid "%q" msgstr "" @@ -193,7 +196,7 @@ msgstr "" msgid "%q must be array of type 'H'" msgstr "" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "" @@ -1117,10 +1120,6 @@ msgstr "" msgid "I2C peripheral in use" msgstr "" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "" @@ -1708,10 +1707,6 @@ msgstr "" msgid "Oversample must be multiple of 8." msgstr "" -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "" - #: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." diff --git a/ports/espressif/boards/m5stack_core2/board.c b/ports/espressif/boards/m5stack_core2/board.c index f0f0d701b3..ea0d0a1a7d 100644 --- a/ports/espressif/boards/m5stack_core2/board.c +++ b/ports/espressif/boards/m5stack_core2/board.c @@ -38,7 +38,7 @@ #include "components/hal/include/hal/gpio_hal.h" #include "common-hal/microcontroller/Pin.h" -#include "axp192.h" +#include "../../pmic/axp192/axp192.h" displayio_fourwire_obj_t board_display_obj; @@ -65,7 +65,7 @@ uint8_t display_init_sequence[] = { 0x29,DELAY,0x78, // Display on then delay 0x78 (120ms) }; -static bool pmic_set_power_source(uint8_t source, busio_i2c_obj_t *internal_i2c) { +static bool pmic_set_power_source(uint8_t source, busio_i2c_obj_t *i2c) { int rc; uint8_t read_buf[1]; uint8_t write_buf[2]; @@ -75,24 +75,24 @@ static bool pmic_set_power_source(uint8_t source, busio_i2c_obj_t *internal_i2c) case PMIC_POWER_SOURCE_USB: // Set GPIO to 3.3V (when LDO OUTPUT mode is active) write_buf[0] = AXP192_GPIO0_LDO_VOLTAGE; - rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); + rc = common_hal_busio_i2c_write_read(i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); if (rc != 0) { return false; } write_buf[1] = (read_buf[0] & ~AXP192_GPIO0_LDO_VOLTAGE_MASK) | AXP192_GPIO0_LDO_VOLTAGE_3_3V; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } // Set GPIO0 to LDO_OUTPUT to set N_VBUSEN high // When N_VBUSEN is high IPSOUT do not select VBUS as source (BUS_5V) write_buf[0] = AXP192_GPIO0_FUNCTION; - rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); + rc = common_hal_busio_i2c_write_read(i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); if (rc != 0) { return false; } write_buf[1] = (read_buf[0] & ~AXP192_GPIO0_FUNCTION_MASK) | AXP192_GPIO0_FUNCTION_LDO_OUTPUT; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -100,12 +100,12 @@ static bool pmic_set_power_source(uint8_t source, busio_i2c_obj_t *internal_i2c) #if M5STACK_CORE2_5V_OUTPUT_ENABLE_DEFAULT // Set EXTENT output high to enable 5V power boost write_buf[0] = AXP192_EXTEN_DCDC2_CTRL; - rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); + rc = common_hal_busio_i2c_write_read(i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); if (rc != 0) { return false; } write_buf[1] = read_buf[0] | AXP192_EXTEN_DCDC2_CTRL_EXTEN; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -113,12 +113,12 @@ static bool pmic_set_power_source(uint8_t source, busio_i2c_obj_t *internal_i2c) // Enable VBUS-IPSOUT when N_VBUSEN is high write_buf[0] = AXP192_VBUS_IPSOUT; - rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); + rc = common_hal_busio_i2c_write_read(i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); if (rc != 0) { return false; } write_buf[1] = read_buf[0] & ~AXP192_VBUS_IPSOUT_IGNORE_VBUSEN; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -128,24 +128,24 @@ static bool pmic_set_power_source(uint8_t source, busio_i2c_obj_t *internal_i2c) case PMIC_POWER_SOURCE_M_BUS: // Enable VBUS-IPSOUT regardless of f N_VBUSEN write_buf[0] = AXP192_VBUS_IPSOUT; - rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); + rc = common_hal_busio_i2c_write_read(i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); if (rc != 0) { return false; } write_buf[1] = read_buf[0] | AXP192_VBUS_IPSOUT_IGNORE_VBUSEN; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } // Set EXTENT output low to disable 5V power boost write_buf[0] = AXP192_EXTEN_DCDC2_CTRL; - rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); + rc = common_hal_busio_i2c_write_read(i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); if (rc != 0) { return false; } write_buf[1] = read_buf[0] & ~AXP192_EXTEN_DCDC2_CTRL_EXTEN; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -153,12 +153,12 @@ static bool pmic_set_power_source(uint8_t source, busio_i2c_obj_t *internal_i2c) // Set GPIO0 to float and the pull down resistor set N_VBUSEN low // When N_VBUSEN is low IPSOUT select VBUS as source (BUS_5V) write_buf[0] = AXP192_GPIO0_FUNCTION; - rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); + rc = common_hal_busio_i2c_write_read(i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); if (rc != 0) { return false; } write_buf[1] = (read_buf[0] & ~AXP192_GPIO0_FUNCTION_MASK) | AXP192_GPIO0_FUNCTION_FLOATING; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -170,148 +170,15 @@ static bool pmic_set_power_source(uint8_t source, busio_i2c_obj_t *internal_i2c) } } -static bool pmic_disable_all_irq(busio_i2c_obj_t *i2c) { - int rc; - // uint8_t read_buf[1]; - uint8_t write_buf[2]; - - // Reg: 40h - // IRQ enable control register 1 - write_buf[0] = AXP192_IRQ_1_ENABLE; - write_buf[1] = AXP192_IRQ_X_DISABLE_ALL; - rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 41h - // IRQ enable control register 2 - write_buf[0] = AXP192_IRQ_2_ENABLE; - write_buf[1] = AXP192_IRQ_X_DISABLE_ALL; - rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 42h - // IRQ enable control register 3 - // Enable power on key short and long press interrupt - write_buf[0] = AXP192_IRQ_3_ENABLE; - write_buf[1] = AXP192_IRQ_X_DISABLE_ALL; - rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 43h - // IRQ enable control register 4 - // Enable power on key short and long press interrupt - write_buf[0] = AXP192_IRQ_4_ENABLE; - write_buf[1] = AXP192_IRQ_X_DISABLE_ALL; - rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 4Ah - // IRQ enable control register 5 - write_buf[0] = AXP192_IRQ_5_ENABLE; - write_buf[1] = AXP192_IRQ_X_DISABLE_ALL; - rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - return true; -} - -static bool pmic_clear_all_irq(busio_i2c_obj_t *i2c) { - int rc; - // uint8_t read_buf[1]; - uint8_t write_buf[2]; - - // Reg: 44h - // IRQ enable control register 1 - write_buf[0] = AXP192_IRQ_1_STATUS; - write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS; - rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 45h - // IRQ enable control register 2 - write_buf[0] = AXP192_IRQ_2_STATUS; - write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS; - rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 46h - // IRQ enable control register 3 - write_buf[0] = AXP192_IRQ_3_STATUS; - write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS; - rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 47h - // IRQ enable control register 4 - write_buf[0] = AXP192_IRQ_4_STATUS; - write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS; - rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 4Ah - // IRQ enable control register 5 - write_buf[0] = AXP192_IRQ_5_STATUS; - write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS; - rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - return true; -} - -static bool pmic_enable_default_irq(busio_i2c_obj_t *i2c) { - int rc; - // uint8_t read_buf[1]; - uint8_t write_buf[2]; - - // Reg: 42h - // IRQ enable control register 3 - // Enable power on key short and long press interrupt - write_buf[0] = AXP192_IRQ_2_ENABLE; - write_buf[1] = AXP192_IRQ_3_PEK_SHORT_PRESS | - AXP192_IRQ_3_PEK_LONG_PRESS; - rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 43h - // IRQ enable control register 4 - // Enable power on key short and long press interrupt - write_buf[0] = AXP192_IRQ_2_ENABLE; - write_buf[1] = AXP192_IRQ_4_LOW_VOLTAGE_WARNING; - rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - return true; -} - -static bool pmic_init(busio_i2c_obj_t *internal_i2c) { +static bool pmic_init(busio_i2c_obj_t *i2c) { int rc; uint8_t read_buf[1]; uint8_t write_buf[2]; + if (!pmic_common_init(i2c)) { + return false; + } + // Reg: 30h // The VBUS-IPSOUT path can be selected to be opened regardless of the status of N_VBUSEN // VBUS VHOLD pressure limit control disabled @@ -319,29 +186,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) { write_buf[0] = AXP192_VBUS_IPSOUT; write_buf[1] = AXP192_VBUS_IPSOUT_VBUS_LIMIT_CURRENT | AXP192_VBUS_IPSOUT_VBUS_LIMIT_CURRENT_500mA; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 31h - // VOFF Shutdown voltage setting ( 3.0V ) - write_buf[0] = AXP192_POWER_OFF_VOLTAGE; - write_buf[1] = AXP192_POWER_OFF_VOLTAGE_3_0V; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 32h - // Charge function enable control bit, including internal and external channels - // Charging target voltage: 4.2V - // Charging end current: End charging when charging current is less than 10% setting - // Internal path charging current: 100mA - write_buf[0] = AXP192_POWER_OFF_BATT_CHGLED_CTRL; - write_buf[1] = AXP192_POWER_OFF_BATT_CHGLED_CTRL_BATT_MONITOR_ON | - AXP192_POWER_OFF_BATT_CHGLED_CTRL_N_OE_SHUTDOWN_DELAY_2_0S; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -356,89 +201,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) { AXP192_CHARGING_CTRL1_VOLTAGE_4_20V | AXP192_CHARGING_CTRL1_CHARGING_THRESH_10PERC | AXP192_CHARGING_CTRL1_CURRENT_360mA; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 35h - // Enable RTC battery charge: 3.0V, 200uA - write_buf[0] = AXP192_BACKUP_BATT; - write_buf[1] = AXP192_BACKUP_BATT_CHARGING_ENABLE | - AXP192_BACKUP_BATT_CHARGING_VOLTAGE_3_0V | - AXP192_BACKUP_BATT_CHARGING_CURRENT_200uA; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 36h - // Power on: Short press 128ms - // Power off: Long press 1s - // Power OK delay 64ms - // Power off delay 4s - write_buf[0] = AXP192_PEK; - write_buf[1] = AXP192_PEK_SHORT_PRESS_128mS | - AXP192_PEK_LONG_PRESS_1_0S | - AXP192_PEK_LONG_PRESS_POWER_OFF | - AXP192_PEK_PWROK_DELAY_64mS | - AXP192_PEK_POWER_OFF_TIME_4S; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 3Ah - // APS Low battery warning level 1: 3.695V - write_buf[0] = AXP192_APS_LOW_BATT_LEVEL_1; - write_buf[1] = AXP192_APS_LOW_BATT_VOLTAGE_3_695V; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 3Bh - // APS Low battery warning level 2: 3.600V - write_buf[0] = AXP192_APS_LOW_BATT_LEVEL_2; - write_buf[1] = AXP192_APS_LOW_BATT_VOLTAGE_3_600V; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 82h - // ADC all on - write_buf[0] = AXP192_ADC_ENABLE_1; - write_buf[1] = AXP192_ADC_ENABLE_1_BATT_VOL | - AXP192_ADC_ENABLE_1_BATT_CUR | - AXP192_ADC_ENABLE_1_ACIN_VOL | - AXP192_ADC_ENABLE_1_ACIN_CUR | - AXP192_ADC_ENABLE_1_VBUS_VOL | - AXP192_ADC_ENABLE_1_VBUS_CUR | - AXP192_ADC_ENABLE_1_APS_VOL | - AXP192_ADC_ENABLE_1_TS_PIN; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 83h - // ADC temperature on - write_buf[0] = AXP192_ADC_ENABLE_2; - write_buf[1] = AXP192_ADC_ENABLE_2_TEMP_MON; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 84h - // ADC 25Hz - write_buf[0] = AXP192_ADC_TS; - write_buf[1] = AXP192_ADC_TS_SAMPLE_25HZ | - AXP192_ADC_TS_OUT_CUR_80uA | - AXP192_ADC_TS_PIN_TEMP_MON | - AXP192_ADC_TS_PIN_OUT_SAVE_ENG; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -447,7 +210,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) { // PWM1 frequency write_buf[0] = AXP192_PWM1_OUTPUT_FREQUECY; write_buf[1] = 0x00; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -456,7 +219,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) { // PWM1 duty cycle Y1 write_buf[0] = AXP192_PWM1_DUTY_RATIO_Y1; write_buf[1] = 0xFF; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -465,7 +228,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) { // PWM1 duty cycle Y2 write_buf[0] = AXP192_PWM1_DUTY_RATIO_Y2; write_buf[1] = 0xFF; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -474,7 +237,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) { // Speaker off (GPIO2 output low) write_buf[0] = AXP192_GPIO2_FUNCTION; write_buf[1] = AXP192_GPIO2_FUNCTION_LOW_OUTPUT; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -485,7 +248,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) { write_buf[0] = AXP192_LDO23_OUT_VOLTAGE; write_buf[1] = AXP192_LDO23_OUT_VOLTAGE_LDO2_3_3V | AXP192_LDO23_OUT_VOLTAGE_LDO3_1_8V; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -494,7 +257,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) { // DCDC1 (ESP32 VDD): 3.350V write_buf[0] = AXP192_DCDC1_OUT_VOLTAGE; write_buf[1] = AXP192_DCDC1_OUT_VOLTAGE_3_350V; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -503,7 +266,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) { // DCDC3 (TFT backlight): 3.0V write_buf[0] = AXP192_DCDC3_OUT_VOLTAGE; write_buf[1] = AXP192_DCDC3_OUT_VOLTAGE_3_0V; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -517,7 +280,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) { write_buf[1] = AXP192_DCDC13_LDO23_CTRL_LDO2 | AXP192_DCDC13_LDO23_CTRL_DCDC3 | AXP192_DCDC13_LDO23_CTRL_DCDC1; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -527,7 +290,7 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) { // PWM duty cycle is set to 100% therefore sys led is off write_buf[0] = AXP192_GPIO1_FUNCTION; write_buf[1] = AXP192_GPIO1_FUNCTION_PWM1_OUTPUT; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -539,25 +302,29 @@ static bool pmic_init(busio_i2c_obj_t *internal_i2c) { * disable VBUS and rely on ACIN (USB_5V) as power source. */ write_buf[0] = AXP192_INPUT_POWER_STATE; - rc = common_hal_busio_i2c_write_read(internal_i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); + rc = common_hal_busio_i2c_write_read(i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); if (rc != 0) { return false; } uint8_t powersource = (read_buf[0] & AXP192_INPUT_POWER_STATE_VBUS_AVAILABLE) ? PMIC_POWER_SOURCE_M_BUS : PMIC_POWER_SOURCE_USB; - if (!pmic_set_power_source(powersource, internal_i2c)) { + if (!pmic_set_power_source(powersource, i2c)) { return false; } - if (!pmic_disable_all_irq(internal_i2c)) { + if (!pmic_disable_all_irq(i2c)) { return false; } - if (!pmic_clear_all_irq(internal_i2c)) { + if (!pmic_clear_all_irq(i2c)) { return false; } - if (!pmic_enable_default_irq(internal_i2c)) { + if (!pmic_enable_power_key_press_irq(i2c)) { + return false; + } + + if (!pmic_enable_low_battery_irq(i2c)) { return false; } diff --git a/ports/espressif/boards/m5stack_core2/mpconfigboard.mk b/ports/espressif/boards/m5stack_core2/mpconfigboard.mk index 28a098a195..74ed5bcb83 100644 --- a/ports/espressif/boards/m5stack_core2/mpconfigboard.mk +++ b/ports/espressif/boards/m5stack_core2/mpconfigboard.mk @@ -11,6 +11,8 @@ M5STACK_CORE2_5V_OUTPUT_ENABLE_DEFAULT = 1 CFLAGS += -DM5STACK_CORE2_5V_OUTPUT_ENABLE_DEFAULT=$(M5STACK_CORE2_5V_OUTPUT_ENABLE_DEFAULT) +SRC_C += pmic/axp192/axp192.c + # Include these Python libraries in firmware. FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Display_Text diff --git a/ports/espressif/boards/m5stack_stick_c/axp192.h b/ports/espressif/boards/m5stack_stick_c/axp192.h deleted file mode 100755 index aa8f6367a7..0000000000 --- a/ports/espressif/boards/m5stack_stick_c/axp192.h +++ /dev/null @@ -1,263 +0,0 @@ -/* - * - * The MIT License (MIT) - * - * Copyright (c) 2022 Stephen Oliver - * Copyright (c) 2023 CDarius - * - * 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_AXP192_H -#define MICROPY_AXP192_H - -#define AXP192_I2C_ADDRESS 0x34 - -#define AXP192_EXTEN_DCDC2_CTRL 0x10 -#define AXP192_EXTEN_DCDC2_CTRL_EXTEN 0b00000100 -#define AXP192_EXTEN_DCDC2_CTRL_DCDC2 0b00000001 - -#define AXP192_DCDC13_LDO23_CTRL 0x12 -#define AXP192_DCDC13_LDO23_CTRL_EXTEN 0b01000000 -#define AXP192_DCDC13_LDO23_CTRL_LDO3 0b00001000 -#define AXP192_DCDC13_LDO23_CTRL_LDO2 0b00000100 -#define AXP192_DCDC13_LDO23_CTRL_DCDC3 0b00000010 -#define AXP192_DCDC13_LDO23_CTRL_DCDC1 0b00000001 - -#define AXP192_DCDC2_OUT_VOLTAGE 0x25 - -#define AXP192_DCDC1_OUT_VOLTAGE 0x26 -#define AXP192_DCDC1_OUT_VOLTAGE_3_350V 0b01101010 - -#define AXP192_DCDC3_OUT_VOLTAGE 0x27 - - -#define AXP192_LDO23_OUT_VOLTAGE 0x28 -#define AXP192_LDO23_OUT_VOLTAGE_LDO2_3_0V 0b11000000 -#define AXP192_LDO23_OUT_VOLTAGE_LDO2_2_8V 0b10100000 -#define AXP192_LDO23_OUT_VOLTAGE_LDO2_MASK 0b11110000 -#define AXP192_LDO23_OUT_VOLTAGE_LDO3_3_0V 0b00001100 -#define AXP192_LDO23_OUT_VOLTAGE_LDO3_2_8V 0b00001010 -#define AXP192_LDO23_OUT_VOLTAGE_LDO3_MASK 0b00001111 - -#define AXP192_VBUS_IPSOUT 0x30 -#define AXP192_VBUS_IPSOUT_IGNORE_VBUSEN 0b10000000 -#define AXP192_VBUS_IPSOUT_VHOLD_LIMIT 0b01000000 -#define AXP192_VBUS_IPSOUT_VHOLD_VOLTAGE_4_4V 0b00100000 -#define AXP192_VBUS_IPSOUT_VHOLD_VOLTAGE_MASK 0b00111000 -#define AXP192_VBUS_IPSOUT_VBUS_LIMIT_CURRENT 0b00000010 -#define AXP192_VBUS_IPSOUT_VBUS_LIMIT_CURRENT_500mA 0b00000001 -#define AXP192_VBUS_IPSOUT_VBUS_LIMIT_CURRENT_100mA 0b00000000 - -#define AXP192_POWER_OFF_VOLTAGE 0x31 -#define AXP192_POWER_OFF_VOLTAGE_2_6V 0b0000 -#define AXP192_POWER_OFF_VOLTAGE_2_7V 0b0001 -#define AXP192_POWER_OFF_VOLTAGE_2_8V 0b0010 -#define AXP192_POWER_OFF_VOLTAGE_2_9V 0b0011 -#define AXP192_POWER_OFF_VOLTAGE_3_0V 0b0100 -#define AXP192_POWER_OFF_VOLTAGE_3_1V 0b0101 -#define AXP192_POWER_OFF_VOLTAGE_3_2V 0b0110 -#define AXP192_POWER_OFF_VOLTAGE_3_3V 0b0111 -#define AXP192_POWER_OFF_VOLTAGE_MASK 0b0111 - -#define AXP192_POWER_OFF_BATT_CHGLED_CTRL 0x32 -#define AXP192_POWER_OFF_BATT_CHGLED_CTRL_OFF 0b10000000 - -#define AXP192_CHARGING_CTRL1 0x33 -#define AXP192_CHARGING_CTRL1_ENABLE 0b10000000 -#define AXP192_CHARGING_CTRL1_VOLTAGE_4_36V 0b01100000 -#define AXP192_CHARGING_CTRL1_VOLTAGE_4_20V 0b01000000 -#define AXP192_CHARGING_CTRL1_VOLTAGE_4_15V 0b00100000 -#define AXP192_CHARGING_CTRL1_VOLTAGE_4_10V 0b00000000 -#define AXP192_CHARGING_CTRL1_VOLTAGE_MASK 0b01100000 -#define AXP192_CHARGING_CTRL1_CHARGING_THRESH_15PERC 0b00010000 -#define AXP192_CHARGING_CTRL1_CHARGING_THRESH_10PERC 0b00000000 -#define AXP192_CHARGING_CTRL1_CHARGING_THRESH_MASK 0b00010000 -#define AXP192_CHARGING_CTRL1_CURRENT_100mA 0b00000000 -#define AXP192_CHARGING_CTRL1_CURRENT_190mA 0b00000001 -#define AXP192_CHARGING_CTRL1_CURRENT_280mA 0b00000010 -#define AXP192_CHARGING_CTRL1_CURRENT_360mA 0b00000011 -#define AXP192_CHARGING_CTRL1_CURRENT_450mA 0b00000100 -#define AXP192_CHARGING_CTRL1_CURRENT_550mA 0b00000101 -#define AXP192_CHARGING_CTRL1_CURRENT_630mA 0b00000110 -#define AXP192_CHARGING_CTRL1_CURRENT_700mA 0b00000111 -#define AXP192_CHARGING_CTRL1_CURRENT_780mA 0b00001000 -#define AXP192_CHARGING_CTRL1_CURRENT_880mA 0b00001001 -#define AXP192_CHARGING_CTRL1_CURRENT_960mA 0b00001010 -#define AXP192_CHARGING_CTRL1_CURRENT_1000mA 0b00001011 - -#define AXP192_CHARGING_CTRL1_CURRENT_MASK 0b00001111 - -#define AXP192_CHARGING_CTRL2 0x34 - -#define AXP192_BACKUP_BATT 0x35 -#define AXP192_BACKUP_BATT_CHARGING_ENABLE 0b10000000 -#define AXP192_BACKUP_BATT_CHARGING_VOLTAGE_2_5V 0b01100000 -#define AXP192_BACKUP_BATT_CHARGING_VOLTAGE_3_0V 0b00100000 -#define AXP192_BACKUP_BATT_CHARGING_VOLTAGE_3_1V 0b00000000 -#define AXP192_BACKUP_BATT_CHARGING_VOLTAGE_MASK 0b01100000 -#define AXP192_BACKUP_BATT_CHARGING_CURRENT_400uA 0b00000011 -#define AXP192_BACKUP_BATT_CHARGING_CURRENT_200uA 0b00000010 -#define AXP192_BACKUP_BATT_CHARGING_CURRENT_100uA 0b00000001 -#define AXP192_BACKUP_BATT_CHARGING_CURRENT_50uA 0b00000000 -#define AXP192_BACKUP_BATT_CHARGING_CURRENT_MASK 0b00000011 - -#define AXP192_PEK 0x36 -#define AXP192_PEK_SHORT_PRESS_1S 0b11000000 -#define AXP192_PEK_SHORT_PRESS_512mS 0b10000000 -#define AXP192_PEK_SHORT_PRESS_256mS 0b01000000 -#define AXP192_PEK_SHORT_PRESS_128mS 0b00000000 -#define AXP192_PEK_SHORT_PRESS_MASK 0b11000000 -#define AXP192_PEK_LONG_PRESS_2_5S 0b00110000 -#define AXP192_PEK_LONG_PRESS_2_0S 0b00100000 -#define AXP192_PEK_LONG_PRESS_1_5S 0b00010000 -#define AXP192_PEK_LONG_PRESS_1_0S 0b00000000 -#define AXP192_PEK_LONG_PRESS_MASK 0b00110000 -#define AXP192_PEK_LONG_PRESS_POWER_OFF 0b00001000 -#define AXP192_PEK_PWROK_DELAY_64mS 0b00000100 -#define AXP192_PEK_PWROK_DELAY_32mS 0b00000000 -#define AXP192_PEK_PWROK_DELAY_MASK 0b00000100 -#define AXP192_PEK_POWER_OFF_TIME_12S 0b00000011 -#define AXP192_PEK_POWER_OFF_TIME_8S 0b00000010 -#define AXP192_PEK_POWER_OFF_TIME_6S 0b00000001 -#define AXP192_PEK_POWER_OFF_TIME_4S 0b00000000 -#define AXP192_PEK_POWER_OFF_TIME_MASK 0b00000011 - -#define AXP192_BATT_TEMP_LOW_THRESH 0x38 -#define AXP192_BATT_TEMP_HIGH_THRESH 0x39 -#define AXP192_BATT_TEMP_HIGH_THRESH_DEFAULT 0b11111100 - -#define AXP192_APS_LOW_BATT_LEVEL_1 0x3A -#define AXP192_APS_LOW_BATT_LEVEL_2 0x3B -#define AXP192_APS_LOW_BATT_VOLTAGE_3_695V 0b10010100 -#define AXP192_APS_LOW_BATT_VOLTAGE_3_600V 0b10000011 - -#define AXP192_IRQ_1_ENABLE 0x40 -#define AXP192_IRQ_2_ENABLE 0x41 -#define AXP192_IRQ_3_ENABLE 0x42 -#define AXP192_IRQ_3_PEK_SHORT_PRESS 0b00000010 -#define AXP192_IRQ_3_PEK_LONG_PRESS 0b00000001 -#define AXP192_IRQ_4_ENABLE 0x43 -#define AXP192_IRQ_4_LOW_VOLTAGE_WARNING 0b00000001 -#define AXP192_IRQ_5_ENABLE 0x4a - -#define AXP192_IRQ_X_DISABLE_ALL 0b00000000 - -#define AXP192_IRQ_1_STATUS 0x44 -#define AXP192_IRQ_2_STATUS 0x45 -#define AXP192_IRQ_3_STATUS 0x46 -#define AXP192_IRQ_4_STATUS 0x47 -#define AXP192_IRQ_5_STATUS 0x4d - -#define AXP192_ADC_ACIN_VOLTAGE_H 0x56 -#define AXP192_ADC_ACIN_VOLTAGE_L 0x57 -#define AXP192_ADC_ACIN_CURRENT_H 0x58 -#define AXP192_ADC_ACIN_CURRENT_L 0x59 -#define AXP192_ADC_VBUS_VOLTAGE_H 0x5a -#define AXP192_ADC_VBUS_VOLTAGE_L 0x5b -#define AXP192_ADC_VBUS_CURRENT_H 0x5c -#define AXP192_ADC_VBUS_CURRENT_L 0x5d -#define AXP192_ADC_INTERNAL_TEMP_H 0x5e -#define AXP192_ADC_INTERNAL_TEMP_L 0x5f - -#define AXP192_ADC_BATT_VOLTAGE_H 0x78 -#define AXP192_ADC_BATT_VOLTAGE_L 0x79 - -#define AXP192_ADC_BATT_POWER_H 0x70 -#define AXP192_ADC_BATT_POWER_M 0x71 -#define AXP192_ADC_BATT_POWER_L 0x72 - -#define AXP192_ADC_BATT_CHARGE_CURRENT_H 0x7a -#define AXP192_ADC_BATT_CHARGE_CURRENT_L 0x7b -#define AXP192_ADC_BATT_DISCHARGE_CURRENT_H 0x7c -#define AXP192_ADC_BATT_DISCHARGE_CURRENT_L 0x7d -#define AXP192_ADC_APS_VOLTAGE_H 0x7e -#define AXP192_ADC_APS_VOLTAGE_L 0x7f - -#define AXP192_ADC_ENABLE_1 0x82 -#define AXP192_ADC_ENABLE_1_BATT_VOL 0b10000000 -#define AXP192_ADC_ENABLE_1_BATT_CUR 0b01000000 -#define AXP192_ADC_ENABLE_1_ACIN_VOL 0b00100000 -#define AXP192_ADC_ENABLE_1_ACIN_CUR 0b00010000 -#define AXP192_ADC_ENABLE_1_VBUS_VOL 0b00001000 -#define AXP192_ADC_ENABLE_1_VBUS_CUR 0b00000100 -#define AXP192_ADC_ENABLE_1_APS_VOL 0b00000010 -#define AXP192_ADC_ENABLE_1_TS_PIN 0b00000001 - -#define AXP192_ADC_ENABLE_2 0x83 -#define AXP192_ADC_ENABLE_2_TEMP_MON 0b10000000 -#define AXP192_ADC_ENABLE_2_GPIO0 0b00001000 -#define AXP192_ADC_ENABLE_2_GPIO1 0b00000100 -#define AXP192_ADC_ENABLE_2_GPIO2 0b00000010 -#define AXP192_ADC_ENABLE_2_GPIO3 0b00000001 - -#define AXP192_ADC_TS 0x84 -#define AXP192_ADC_TS_SAMPLE_200HZ 0b11000000 -#define AXP192_ADC_TS_SAMPLE_100HZ 0b10000000 -#define AXP192_ADC_TS_SAMPLE_50HZ 0b01000000 -#define AXP192_ADC_TS_SAMPLE_25HZ 0b00000000 -#define AXP192_ADC_TS_SAMPLE_MASK 0b11000000 -#define AXP192_ADC_TS_OUT_CUR_80uA 0b00110000 -#define AXP192_ADC_TS_OUT_CUR_60uA 0b00100000 -#define AXP192_ADC_TS_OUT_CUR_40uA 0b00010000 -#define AXP192_ADC_TS_OUT_CUR_20uA 0b00000000 -#define AXP192_ADC_TS_OUT_CUR_MASK 0b00110000 -#define AXP192_ADC_TS_PIN_TEMP_MON 0b00000000 -#define AXP192_ADC_TS_PIN_EXTERN_ADC 0b00000100 -#define AXP192_ADC_TS_PIN_OUT_ALWAYS 0b00000011 -#define AXP192_ADC_TS_PIN_OUT_SAVE_ENG 0b00000010 -#define AXP192_ADC_TS_PIN_OUT_CHG 0b00000001 -#define AXP192_ADC_TS_PIN_OUT_DIS 0b00000000 -#define AXP192_ADC_TS_PIN_OUT_MASK 0b00000011 - -#define AXP192_GPIO0_FUNCTION 0x90 -#define AXP192_GPIO0_FUNCTION_FLOATING 0b00000111 -#define AXP192_GPIO0_FUNCTION_LOW_OUTPUT 0b00000101 -#define AXP192_GPIO0_FUNCTION_ADC_INPUT 0b00000100 -#define AXP192_GPIO0_FUNCTION_LDO_OUTPUT 0b00000010 -#define AXP192_GPIO0_FUNCTION_GENERAL_INPUT 0b00000001 -#define AXP192_GPIO0_FUNCTION_OPEN_DRAIN_OUTPUT 0b00000000 - -#define AXP192_GPIO0_LDO_VOLTAGE 0x91 -#define AXP192_GPIO0_LDO_VOLTAGE_3_3V 0b11110000 -#define AXP192_GPIO0_LDO_VOLTAGE_2_8V 0b10100000 -#define AXP192_GPIO0_LDO_VOLTAGE_1_8V 0b00000000 - - -#define AXP192_GPIO1_FUNCTION 0x92 -#define AXP192_GPIO1_FUNCTION_FLOATING 0b00000111 -#define AXP192_GPIO1_FUNCTION_LOW_OUTPUT 0b00000101 -#define AXP192_GPIO1_FUNCTION_ADC_INPUT 0b00000100 -#define AXP192_GPIO1_FUNCTION_PWM1_OUTPUT 0b00000010 -#define AXP192_GPIO1_FUNCTION_GENERAL_INPUT 0b00000001 -#define AXP192_GPIO1_FUNCTION_OPEN_DRAIN_OUTPUT 0b00000000 - - -#define AXP192_GPIO2_FUNCTION 0x93 -#define AXP192_GPIO2_FUNCTION_FLOATING 0b00000111 -#define AXP192_GPIO2_FUNCTION_LOW_OUTPUT 0b00000101 -#define AXP192_GPIO2_FUNCTION_ADC_INPUT 0b00000100 -#define AXP192_GPIO1_FUNCTION_PWM2_OUTPUT 0b00000010 -#define AXP192_GPIO2_FUNCTION_GENERAL_INPUT 0b00000001 -#define AXP192_GPIO2_FUNCTION_OPEN_DRAIN_OUTPUT 0b00000000 - -#define AXP192_PWM1_DUTY_RATIO 0x9A - -#endif diff --git a/ports/espressif/boards/m5stack_stick_c/board.c b/ports/espressif/boards/m5stack_stick_c/board.c index 2f993d4a05..d25663895c 100755 --- a/ports/espressif/boards/m5stack_stick_c/board.c +++ b/ports/espressif/boards/m5stack_stick_c/board.c @@ -29,12 +29,15 @@ #include "shared-bindings/busio/SPI.h" #include "shared-bindings/busio/I2C.h" #include "shared-bindings/displayio/FourWire.h" -#include "shared-bindings/microcontroller/Pin.h" #include "shared-module/displayio/__init__.h" #include "shared-module/displayio/mipi_constants.h" #include "shared-bindings/board/__init__.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "components/driver/include/driver/gpio.h" +#include "components/hal/include/hal/gpio_hal.h" +#include "common-hal/microcontroller/Pin.h" -#include "axp192.h" +#include "../../pmic/axp192/axp192.h" // display init sequence according to adafruit_st7735r.py library uint8_t display_init_sequence[] = { @@ -59,12 +62,13 @@ uint8_t display_init_sequence[] = { 0x29,0x80,0x64 // _DISPON }; -static bool pmic_init(void) { +static bool pmic_init(busio_i2c_obj_t *i2c) { int rc; - // uint8_t read_buf[1]; uint8_t write_buf[2]; - busio_i2c_obj_t *internal_i2c = common_hal_board_create_i2c(0); + if (!pmic_common_init(i2c)) { + return false; + } // Reg: 30h // The VBUS-IPSOUT path can be selected to be opened regardless of the status of N_VBUSEN @@ -72,16 +76,7 @@ static bool pmic_init(void) { // VBUS current limit control disabled write_buf[0] = AXP192_VBUS_IPSOUT; write_buf[1] = AXP192_VBUS_IPSOUT_IGNORE_VBUSEN; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 31h - // VOFF Shutdown voltage setting ( 3.0V ) - write_buf[0] = AXP192_POWER_OFF_VOLTAGE; - write_buf[1] = AXP192_POWER_OFF_VOLTAGE_3_0V; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -95,88 +90,7 @@ static bool pmic_init(void) { write_buf[1] = AXP192_CHARGING_CTRL1_ENABLE | AXP192_CHARGING_CTRL1_VOLTAGE_4_20V | AXP192_CHARGING_CTRL1_CURRENT_100mA; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 35h - // Enable RTC battery charge: 3.0V, 200uA - write_buf[0] = AXP192_BACKUP_BATT; - write_buf[1] = AXP192_BACKUP_BATT_CHARGING_ENABLE | - AXP192_BACKUP_BATT_CHARGING_VOLTAGE_3_0V | - AXP192_BACKUP_BATT_CHARGING_CURRENT_200uA; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 36h - // Power on: Short press 128ms - // Power off: Long press 1s - // Power OK delay 64ms - // Power off delay 4s - write_buf[0] = AXP192_PEK; - write_buf[1] = AXP192_PEK_SHORT_PRESS_128mS | - AXP192_PEK_LONG_PRESS_1_0S | - AXP192_PEK_LONG_PRESS_POWER_OFF | - AXP192_PEK_PWROK_DELAY_64mS | - AXP192_PEK_POWER_OFF_TIME_4S; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 3Ah - // APS Low battery warning level 1: 3.695V - write_buf[0] = AXP192_APS_LOW_BATT_LEVEL_1; - write_buf[1] = AXP192_APS_LOW_BATT_VOLTAGE_3_695V; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 3Bh - // APS Low battery warning level 2: 3.600V - write_buf[0] = AXP192_APS_LOW_BATT_LEVEL_2; - write_buf[1] = AXP192_APS_LOW_BATT_VOLTAGE_3_600V; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 82h - // ADC all on - write_buf[0] = AXP192_ADC_ENABLE_1; - write_buf[1] = AXP192_ADC_ENABLE_1_BATT_VOL | - AXP192_ADC_ENABLE_1_BATT_CUR | - AXP192_ADC_ENABLE_1_ACIN_VOL | - AXP192_ADC_ENABLE_1_ACIN_CUR | - AXP192_ADC_ENABLE_1_VBUS_VOL | - AXP192_ADC_ENABLE_1_VBUS_CUR | - AXP192_ADC_ENABLE_1_APS_VOL | - AXP192_ADC_ENABLE_1_TS_PIN; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 83h - // ADC temperature on - write_buf[0] = AXP192_ADC_ENABLE_2; - write_buf[1] = AXP192_ADC_ENABLE_2_TEMP_MON; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 84h - // ADC 25Hz - write_buf[0] = AXP192_ADC_TS; - write_buf[1] = AXP192_ADC_TS_SAMPLE_25HZ | - AXP192_ADC_TS_OUT_CUR_80uA | - AXP192_ADC_TS_PIN_OUT_SAVE_ENG; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -185,7 +99,7 @@ static bool pmic_init(void) { // GPIO0(LDOio0) floating write_buf[0] = AXP192_GPIO0_FUNCTION; write_buf[1] = AXP192_GPIO0_FUNCTION_FLOATING; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -194,7 +108,7 @@ static bool pmic_init(void) { // GPIO0(LDOio0) 2.8V write_buf[0] = AXP192_GPIO0_LDO_VOLTAGE; write_buf[1] = AXP192_GPIO0_LDO_VOLTAGE_2_8V; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -205,7 +119,7 @@ static bool pmic_init(void) { write_buf[0] = AXP192_LDO23_OUT_VOLTAGE; write_buf[1] = AXP192_LDO23_OUT_VOLTAGE_LDO2_2_8V | AXP192_LDO23_OUT_VOLTAGE_LDO3_3_0V; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -217,7 +131,7 @@ static bool pmic_init(void) { AXP192_DCDC13_LDO23_CTRL_LDO3 | AXP192_DCDC13_LDO23_CTRL_LDO2 | AXP192_DCDC13_LDO23_CTRL_DCDC1; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } @@ -226,56 +140,24 @@ static bool pmic_init(void) { // DCDC1 (ESP32 VDD): 3.350V write_buf[0] = AXP192_DCDC1_OUT_VOLTAGE; write_buf[1] = AXP192_DCDC1_OUT_VOLTAGE_3_350V; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; } - // Reg: 40h - // IRQ enable control register 1 - write_buf[0] = AXP192_IRQ_1_ENABLE; - write_buf[1] = AXP192_IRQ_X_DISABLE_ALL; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { + if (!pmic_disable_all_irq(i2c)) { return false; } - // Reg: 41h - // IRQ enable control register 2 - write_buf[0] = AXP192_IRQ_2_ENABLE; - write_buf[1] = AXP192_IRQ_X_DISABLE_ALL; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { + if (!pmic_clear_all_irq(i2c)) { return false; } - // Reg: 42h - // IRQ enable control register 3 - // Enable power on key short and long press interrupt - write_buf[0] = AXP192_IRQ_2_ENABLE; - write_buf[1] = AXP192_IRQ_3_PEK_SHORT_PRESS | - AXP192_IRQ_3_PEK_LONG_PRESS; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { + if (!pmic_enable_power_key_press_irq(i2c)) { return false; } - // Reg: 43h - // IRQ enable control register 4 - // Enable power on key short and long press interrupt - write_buf[0] = AXP192_IRQ_2_ENABLE; - write_buf[1] = AXP192_IRQ_4_LOW_VOLTAGE_WARNING; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { - return false; - } - - // Reg: 44h - // IRQ enable control register 5 - write_buf[0] = AXP192_IRQ_2_ENABLE; - write_buf[1] = AXP192_IRQ_X_DISABLE_ALL; - rc = common_hal_busio_i2c_write(internal_i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); - if (rc != 0) { + if (!pmic_enable_low_battery_irq(i2c)) { return false; } @@ -339,7 +221,9 @@ static bool display_init(void) { } void board_init(void) { - if (!pmic_init()) { + busio_i2c_obj_t *internal_i2c = common_hal_board_create_i2c(0); + + if (!pmic_init(internal_i2c)) { mp_printf(&mp_plat_print, "could not initialize axp192 pmic\n"); return; } diff --git a/ports/espressif/boards/m5stack_stick_c/mpconfigboard.mk b/ports/espressif/boards/m5stack_stick_c/mpconfigboard.mk index 5910605915..ce4d23a303 100644 --- a/ports/espressif/boards/m5stack_stick_c/mpconfigboard.mk +++ b/ports/espressif/boards/m5stack_stick_c/mpconfigboard.mk @@ -7,3 +7,5 @@ CIRCUITPY_ESP_FLASH_MODE = qio CIRCUITPY_ESP_FLASH_FREQ = 80m CIRCUITPY_ESP_FLASH_SIZE = 4MB CIRCUITPY_ESPCAMERA = 0 + +SRC_C += pmic/axp192/axp192.c diff --git a/ports/espressif/pmic/axp192/axp192.c b/ports/espressif/pmic/axp192/axp192.c new file mode 100644 index 0000000000..fe698a0416 --- /dev/null +++ b/ports/espressif/pmic/axp192/axp192.c @@ -0,0 +1,255 @@ +#include "axp192.h" + +bool pmic_common_init(busio_i2c_obj_t *i2c) { + int rc; + uint8_t write_buf[2]; + + // Reg: 31h + // VOFF Shutdown voltage setting ( 3.0V ) + write_buf[0] = AXP192_POWER_OFF_VOLTAGE; + write_buf[1] = AXP192_POWER_OFF_VOLTAGE_3_0V; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 32h + // Enable battery monitoring + // N_OE shout down delay 2 seconds + write_buf[0] = AXP192_POWER_OFF_BATT_CHGLED_CTRL; + write_buf[1] = AXP192_POWER_OFF_BATT_CHGLED_CTRL_BATT_MONITOR_ON | + AXP192_POWER_OFF_BATT_CHGLED_CTRL_N_OE_SHUTDOWN_DELAY_2_0S; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 35h + // Enable RTC battery charge: 3.0V, 200uA + write_buf[0] = AXP192_BACKUP_BATT; + write_buf[1] = AXP192_BACKUP_BATT_CHARGING_ENABLE | + AXP192_BACKUP_BATT_CHARGING_VOLTAGE_3_0V | + AXP192_BACKUP_BATT_CHARGING_CURRENT_200uA; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 36h + // Power on: Short press 128ms + // Power off: Long press 1s + // Power OK delay 64ms + // Power off delay 4s + write_buf[0] = AXP192_PEK; + write_buf[1] = AXP192_PEK_SHORT_PRESS_128mS | + AXP192_PEK_LONG_PRESS_1_0S | + AXP192_PEK_LONG_PRESS_POWER_OFF | + AXP192_PEK_PWROK_DELAY_64mS | + AXP192_PEK_POWER_OFF_TIME_4S; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 3Ah + // APS Low battery warning level 1: 3.695V + write_buf[0] = AXP192_APS_LOW_BATT_LEVEL_1; + write_buf[1] = AXP192_APS_LOW_BATT_VOLTAGE_3_695V; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 3Bh + // APS Low battery warning level 2: 3.600V + write_buf[0] = AXP192_APS_LOW_BATT_LEVEL_2; + write_buf[1] = AXP192_APS_LOW_BATT_VOLTAGE_3_600V; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 82h + // ADC all on + write_buf[0] = AXP192_ADC_ENABLE_1; + write_buf[1] = AXP192_ADC_ENABLE_1_BATT_VOL | + AXP192_ADC_ENABLE_1_BATT_CUR | + AXP192_ADC_ENABLE_1_ACIN_VOL | + AXP192_ADC_ENABLE_1_ACIN_CUR | + AXP192_ADC_ENABLE_1_VBUS_VOL | + AXP192_ADC_ENABLE_1_VBUS_CUR | + AXP192_ADC_ENABLE_1_APS_VOL | + AXP192_ADC_ENABLE_1_TS_PIN; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 83h + // ADC temperature on + write_buf[0] = AXP192_ADC_ENABLE_2; + write_buf[1] = AXP192_ADC_ENABLE_2_TEMP_MON; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 84h + // ADC 25Hz + write_buf[0] = AXP192_ADC_TS; + write_buf[1] = AXP192_ADC_TS_SAMPLE_25HZ | + AXP192_ADC_TS_OUT_CUR_80uA | + AXP192_ADC_TS_PIN_TEMP_MON | + AXP192_ADC_TS_PIN_OUT_SAVE_ENG; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + return true; +} + +bool pmic_disable_all_irq(busio_i2c_obj_t *i2c) { + int rc; + uint8_t write_buf[2]; + + // Reg: 40h + // IRQ enable control register 1 + write_buf[0] = AXP192_IRQ_1_ENABLE; + write_buf[1] = AXP192_IRQ_X_DISABLE_ALL; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 41h + // IRQ enable control register 2 + write_buf[0] = AXP192_IRQ_2_ENABLE; + write_buf[1] = AXP192_IRQ_X_DISABLE_ALL; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 42h + // IRQ enable control register 3 + // Enable power on key short and long press interrupt + write_buf[0] = AXP192_IRQ_3_ENABLE; + write_buf[1] = AXP192_IRQ_X_DISABLE_ALL; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 43h + // IRQ enable control register 4 + // Enable power on key short and long press interrupt + write_buf[0] = AXP192_IRQ_4_ENABLE; + write_buf[1] = AXP192_IRQ_X_DISABLE_ALL; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 4Ah + // IRQ enable control register 5 + write_buf[0] = AXP192_IRQ_5_ENABLE; + write_buf[1] = AXP192_IRQ_X_DISABLE_ALL; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + return true; +} + +bool pmic_clear_all_irq(busio_i2c_obj_t *i2c) { + int rc; + uint8_t write_buf[2]; + + // Reg: 44h + // IRQ enable control register 1 + write_buf[0] = AXP192_IRQ_1_STATUS; + write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 45h + // IRQ enable control register 2 + write_buf[0] = AXP192_IRQ_2_STATUS; + write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 46h + // IRQ enable control register 3 + write_buf[0] = AXP192_IRQ_3_STATUS; + write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 47h + // IRQ enable control register 4 + write_buf[0] = AXP192_IRQ_4_STATUS; + write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + // Reg: 4Ah + // IRQ enable control register 5 + write_buf[0] = AXP192_IRQ_5_STATUS; + write_buf[1] = AXP192_IRQ_X_CLEAR_STATUS; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + return true; +} + +bool pmic_enable_power_key_press_irq(busio_i2c_obj_t *i2c) { + int rc; + uint8_t read_buf[1]; + uint8_t write_buf[2]; + + // Reg: 42h + // IRQ enable control register 3 + // Enable power on key short and long press interrupt + write_buf[0] = AXP192_IRQ_2_ENABLE; + rc = common_hal_busio_i2c_write_read(i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); + if (rc != 0) { + return false; + } + write_buf[1] = read_buf[0] | AXP192_IRQ_3_PEK_SHORT_PRESS | AXP192_IRQ_3_PEK_LONG_PRESS; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + return true; +} + +bool pmic_enable_low_battery_irq(busio_i2c_obj_t *i2c) { + int rc; + uint8_t write_buf[2]; + + // Reg: 43h + // IRQ enable control register 4 + // Enable power on key short and long press interrupt + write_buf[0] = AXP192_IRQ_2_ENABLE; + write_buf[1] = AXP192_IRQ_4_LOW_VOLTAGE_WARNING; + rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); + if (rc != 0) { + return false; + } + + return true; +} diff --git a/ports/espressif/boards/m5stack_core2/axp192.h b/ports/espressif/pmic/axp192/axp192.h similarity index 97% rename from ports/espressif/boards/m5stack_core2/axp192.h rename to ports/espressif/pmic/axp192/axp192.h index 45279ce56f..e05592ce70 100755 --- a/ports/espressif/boards/m5stack_core2/axp192.h +++ b/ports/espressif/pmic/axp192/axp192.h @@ -28,6 +28,8 @@ #ifndef MICROPY_AXP192_H #define MICROPY_AXP192_H +#include "shared-bindings/busio/I2C.h" + #define AXP192_I2C_ADDRESS 0x34 #define AXP192_INPUT_POWER_STATE 0x00 @@ -283,4 +285,10 @@ #define AXP192_PWM1_DUTY_RATIO_Y1 0x99 #define AXP192_PWM1_DUTY_RATIO_Y2 0x9A +bool pmic_common_init(busio_i2c_obj_t *i2c); +bool pmic_disable_all_irq(busio_i2c_obj_t *i2c); +bool pmic_clear_all_irq(busio_i2c_obj_t *i2c); +bool pmic_enable_power_key_press_irq(busio_i2c_obj_t *i2c); +bool pmic_enable_low_battery_irq(busio_i2c_obj_t *i2c); + #endif From 32ffdcdc7c52f4698b79c71544698e2ba5212d89 Mon Sep 17 00:00:00 2001 From: CDarius Date: Fri, 14 Apr 2023 08:02:56 +0000 Subject: [PATCH 019/117] Fix I2S pins --- ports/espressif/boards/m5stack_core2/pins.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ports/espressif/boards/m5stack_core2/pins.c b/ports/espressif/boards/m5stack_core2/pins.c index 465006a6b6..865ce61eaf 100644 --- a/ports/espressif/boards/m5stack_core2/pins.c +++ b/ports/espressif/boards/m5stack_core2/pins.c @@ -32,7 +32,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_D27), MP_ROM_PTR(&pin_GPIO27) }, { MP_ROM_QSTR(MP_QSTR_A27), MP_ROM_PTR(&pin_GPIO27) }, - { MP_ROM_QSTR(MP_QSTR_I2S_DATA_SPK), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_I2S_SDO), MP_ROM_PTR(&pin_GPIO2) }, { MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO2) }, { MP_ROM_QSTR(MP_QSTR_A35), MP_ROM_PTR(&pin_GPIO35) }, @@ -63,14 +63,16 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_D19), MP_ROM_PTR(&pin_GPIO19) }, - { MP_ROM_QSTR(MP_QSTR_I2S_WS_SPK), MP_ROM_PTR(&pin_GPIO0) }, - { MP_ROM_QSTR(MP_QSTR_I2S_PDM_CLOCK_MIC), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_I2S_LRC), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_I2S_PDM_MIC_CLOCK), MP_ROM_PTR(&pin_GPIO0) }, { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO0) }, - { MP_ROM_QSTR(MP_QSTR_I2S_PDM_DATA_MIC), MP_ROM_PTR(&pin_GPIO34) }, + { MP_ROM_QSTR(MP_QSTR_I2S_PDM_MIC_DATA), MP_ROM_PTR(&pin_GPIO34) }, { MP_ROM_QSTR(MP_QSTR_D34), MP_ROM_PTR(&pin_GPIO34) }, { MP_ROM_QSTR(MP_QSTR_A34), MP_ROM_PTR(&pin_GPIO34) }, + { MP_ROM_QSTR(MP_QSTR_I2S_SCK), MP_ROM_PTR(&pin_GPIO12) }, + // tft { MP_ROM_QSTR(MP_QSTR_TFT_CS), MP_ROM_PTR(&pin_GPIO5) }, { MP_ROM_QSTR(MP_QSTR_TFT_DC), MP_ROM_PTR(&pin_GPIO15) }, From 681eb66824ce7224f0abf804ad361abe0e240794 Mon Sep 17 00:00:00 2001 From: CDarius Date: Fri, 14 Apr 2023 13:02:51 +0000 Subject: [PATCH 020/117] Fixed DCDC2 output voltage register --- ports/espressif/pmic/axp192/axp192.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/espressif/pmic/axp192/axp192.h b/ports/espressif/pmic/axp192/axp192.h index e05592ce70..65eb712b1a 100755 --- a/ports/espressif/pmic/axp192/axp192.h +++ b/ports/espressif/pmic/axp192/axp192.h @@ -53,7 +53,7 @@ #define AXP192_DCDC13_LDO23_CTRL_DCDC3 0b00000010 #define AXP192_DCDC13_LDO23_CTRL_DCDC1 0b00000001 -#define AXP192_DCDC2_OUT_VOLTAGE 0x25 +#define AXP192_DCDC2_OUT_VOLTAGE 0x23 #define AXP192_DCDC1_OUT_VOLTAGE 0x26 #define AXP192_DCDC1_OUT_VOLTAGE_3_350V 0b01101010 From d765efd71ca554fd3976217a99a2d6016e950359 Mon Sep 17 00:00:00 2001 From: CDarius Date: Fri, 14 Apr 2023 13:08:52 +0000 Subject: [PATCH 021/117] Moved EXTEN and DCDC2 on register 0x12 --- ports/espressif/boards/m5stack_core2/board.c | 8 ++++---- ports/espressif/pmic/axp192/axp192.h | 9 +++------ 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/ports/espressif/boards/m5stack_core2/board.c b/ports/espressif/boards/m5stack_core2/board.c index ea0d0a1a7d..a2565229ce 100644 --- a/ports/espressif/boards/m5stack_core2/board.c +++ b/ports/espressif/boards/m5stack_core2/board.c @@ -99,12 +99,12 @@ static bool pmic_set_power_source(uint8_t source, busio_i2c_obj_t *i2c) { #if M5STACK_CORE2_5V_OUTPUT_ENABLE_DEFAULT // Set EXTENT output high to enable 5V power boost - write_buf[0] = AXP192_EXTEN_DCDC2_CTRL; + write_buf[0] = AXP192_DCDC13_LDO23_CTRL; rc = common_hal_busio_i2c_write_read(i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); if (rc != 0) { return false; } - write_buf[1] = read_buf[0] | AXP192_EXTEN_DCDC2_CTRL_EXTEN; + write_buf[1] = read_buf[0] | AXP192_DCDC13_LDO23_CTRL_EXTEN; rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; @@ -139,12 +139,12 @@ static bool pmic_set_power_source(uint8_t source, busio_i2c_obj_t *i2c) { } // Set EXTENT output low to disable 5V power boost - write_buf[0] = AXP192_EXTEN_DCDC2_CTRL; + write_buf[0] = AXP192_DCDC13_LDO23_CTRL; rc = common_hal_busio_i2c_write_read(i2c, AXP192_I2C_ADDRESS, write_buf, 1, read_buf, sizeof(read_buf)); if (rc != 0) { return false; } - write_buf[1] = read_buf[0] & ~AXP192_EXTEN_DCDC2_CTRL_EXTEN; + write_buf[1] = read_buf[0] & ~AXP192_DCDC13_LDO23_CTRL_EXTEN; rc = common_hal_busio_i2c_write(i2c, AXP192_I2C_ADDRESS, write_buf, sizeof(write_buf)); if (rc != 0) { return false; diff --git a/ports/espressif/pmic/axp192/axp192.h b/ports/espressif/pmic/axp192/axp192.h index 65eb712b1a..587ce04b0c 100755 --- a/ports/espressif/pmic/axp192/axp192.h +++ b/ports/espressif/pmic/axp192/axp192.h @@ -42,14 +42,11 @@ #define AXP192_INPUT_POWER_STATE_ACIN_VBUS_PCB_SHORTED 0b00000010 #define AXP192_INPUT_POWER_STATE_BOOT_SOURCE_ACIN_OR_VBUS 0b00000001 -#define AXP192_EXTEN_DCDC2_CTRL 0x10 -#define AXP192_EXTEN_DCDC2_CTRL_EXTEN 0b00000100 -#define AXP192_EXTEN_DCDC2_CTRL_DCDC2 0b00000001 - #define AXP192_DCDC13_LDO23_CTRL 0x12 #define AXP192_DCDC13_LDO23_CTRL_EXTEN 0b01000000 -#define AXP192_DCDC13_LDO23_CTRL_LDO3 0b00001000 -#define AXP192_DCDC13_LDO23_CTRL_LDO2 0b00000100 +#define AXP192_DCDC13_LDO23_CTRL_DCDC2 0b00010000 +#define AXP192_DCDC13_LDO23_CTRL_LDO3 0b00001000 +#define AXP192_DCDC13_LDO23_CTRL_LDO2 0b00000100 #define AXP192_DCDC13_LDO23_CTRL_DCDC3 0b00000010 #define AXP192_DCDC13_LDO23_CTRL_DCDC1 0b00000001 From 5828a9852f22d94cb95460254caa437016ccb060 Mon Sep 17 00:00:00 2001 From: Andi Chandler Date: Fri, 14 Apr 2023 10:51:56 +0000 Subject: [PATCH 022/117] Translated using Weblate (English (United Kingdom)) Currently translated at 86.4% (864 of 1000 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/en_GB/ --- locale/en_GB.po | 124 ++++++++++++++++++++++++++---------------------- 1 file changed, 66 insertions(+), 58 deletions(-) diff --git a/locale/en_GB.po b/locale/en_GB.po index 8f45f3617a..8b0c8a4b0b 100644 --- a/locale/en_GB.po +++ b/locale/en_GB.po @@ -7,15 +7,15 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"PO-Revision-Date: 2022-05-22 00:18+0000\n" -"Last-Translator: Dan Halbert \n" +"PO-Revision-Date: 2023-04-15 11:47+0000\n" +"Last-Translator: Andi Chandler \n" "Language-Team: none\n" "Language: en_GB\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 4.13-dev\n" +"X-Generator: Weblate 4.17-dev\n" #: main.c msgid "" @@ -26,7 +26,6 @@ msgstr "" "Code done running.\n" #: main.c -#, fuzzy msgid "" "\n" "Code stopped by auto-reload. Reloading soon.\n" @@ -40,18 +39,25 @@ msgid "" "Please file an issue with your program at https://github.com/adafruit/" "circuitpython/issues." msgstr "" +"\n" +"Please file an issue with your program at https://github.com/adafruit/" +"circuitpython/issues." #: supervisor/shared/safe_mode.c msgid "" "\n" "Press reset to exit safe mode.\n" msgstr "" +"\n" +"Press reset to exit safe mode.\n" #: supervisor/shared/safe_mode.c msgid "" "\n" "You are in safe mode because:\n" msgstr "" +"\n" +"You are in safe mode because:\n" #: py/obj.c msgid " File \"%q\"" @@ -81,7 +87,7 @@ msgstr "%%c requires int or char" #: main.c #, c-format msgid "%02X" -msgstr "" +msgstr "%02X" #: shared-module/os/getenv.c #, c-format @@ -106,7 +112,7 @@ msgstr "" #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c msgid "%q" -msgstr "" +msgstr "%q" #: shared-bindings/microcontroller/Pin.c msgid "%q and %q contain duplicate pins" @@ -114,7 +120,7 @@ msgstr "%q and %q contain duplicate pins" #: ports/atmel-samd/common-hal/audioio/AudioOut.c msgid "%q and %q must be different" -msgstr "" +msgstr "%q and %q must be different" #: shared-bindings/microcontroller/Pin.c msgid "%q contains duplicate pins" @@ -126,7 +132,7 @@ msgstr "%q failure: %d" #: py/argcheck.c msgid "%q in %q must be of type %q, not %q" -msgstr "" +msgstr "%q in %q must be of type %q, not %q" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c @@ -142,19 +148,19 @@ msgstr "%q index out of range" #: shared-module/bitbangio/SPI.c msgid "%q init failed" -msgstr "" +msgstr "%q init failed" #: ports/espressif/bindings/espnow/Peer.c shared-bindings/dualbank/__init__.c msgid "%q is %q" -msgstr "" +msgstr "%q is %q" #: ports/raspberrypi/common-hal/wifi/Radio.c msgid "%q is read-only for this board" -msgstr "" +msgstr "%q is read-only for this board" #: py/argcheck.c shared-bindings/usb_hid/Device.c msgid "%q length must be %d" -msgstr "" +msgstr "%q length must be %d" #: py/argcheck.c msgid "%q length must be %d-%d" @@ -162,15 +168,15 @@ msgstr "%q length must be %d-%d" #: py/argcheck.c msgid "%q length must be <= %d" -msgstr "" +msgstr "%q length must be <= %d" #: py/argcheck.c msgid "%q length must be >= %d" -msgstr "" +msgstr "%q length must be >= %d" #: py/argcheck.c msgid "%q must be %d" -msgstr "" +msgstr "%q must be %d" #: py/argcheck.c msgid "%q must be %d-%d" @@ -178,11 +184,11 @@ msgstr "%q must be %d-%d" #: shared-bindings/displayio/Display.c msgid "%q must be 1 when %q is True" -msgstr "" +msgstr "%q must be 1 when %q is True" #: py/argcheck.c shared-bindings/gifio/GifWriter.c msgid "%q must be <= %d" -msgstr "" +msgstr "%q must be <= %d" #: py/argcheck.c msgid "%q must be >= %d" @@ -190,28 +196,28 @@ msgstr "%q must be >= %d" #: shared-bindings/analogbufio/BufferedIn.c msgid "%q must be a bytearray or array of type 'H' or 'B'" -msgstr "" +msgstr "%q must be a bytearray or array of type 'H' or 'B'" #: shared-bindings/audiocore/RawSample.c msgid "%q must be a bytearray or array of type 'h', 'H', 'b', or 'B'" -msgstr "" +msgstr "%q must be a bytearray or array of type 'h', 'H', 'b', or 'B'" #: ports/espressif/common-hal/analogbufio/BufferedIn.c msgid "%q must be array of type 'H'" -msgstr "" +msgstr "%q must be array of type 'H'" #: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c msgid "%q must be array of type 'h'" -msgstr "" +msgstr "%q must be array of type 'h'" #: ports/raspberrypi/bindings/cyw43/__init__.c py/argcheck.c py/objexcept.c #: shared-bindings/canio/CAN.c shared-bindings/digitalio/Pull.c msgid "%q must be of type %q or %q, not %q" -msgstr "" +msgstr "%q must be of type %q or %q, not %q" #: py/argcheck.c py/obj.c py/objstrunicode.c msgid "%q must be of type %q, not %q" -msgstr "" +msgstr "%q must be of type %q, not %q" #: ports/atmel-samd/common-hal/busio/UART.c msgid "%q must be power of 2" @@ -219,7 +225,7 @@ msgstr "%q must be power of 2" #: shared-bindings/wifi/Monitor.c msgid "%q out of bounds" -msgstr "" +msgstr "%q out of bounds" #: ports/atmel-samd/common-hal/pulseio/PulseIn.c #: ports/cxd56/common-hal/pulseio/PulseIn.c @@ -232,7 +238,7 @@ msgstr "%q out of range" #: py/objrange.c py/objslice.c shared-bindings/random/__init__.c msgid "%q step cannot be zero" -msgstr "" +msgstr "%q step cannot be zero" #: py/bc.c py/objnamedtuple.c msgid "%q() takes %d positional arguments but %d were given" @@ -244,7 +250,7 @@ msgstr "%q, %q, and %q must all be the same length" #: py/objint.c shared-bindings/storage/__init__.c msgid "%q=%q" -msgstr "" +msgstr "%q=%q" #: ports/espressif/common-hal/espidf/__init__.c #, c-format @@ -429,7 +435,7 @@ msgstr "Address must be %d bytes long" #: ports/espressif/common-hal/memorymap/AddressRange.c msgid "Address range not allowed" -msgstr "" +msgstr "Address range not allowed" #: ports/espressif/common-hal/canio/CAN.c msgid "All CAN peripherals are in use" @@ -525,7 +531,7 @@ msgstr "Already scanning for WiFi networks" #: shared-module/os/getenv.c #, c-format msgid "An error occurred while retrieving '%s':\n" -msgstr "" +msgstr "An error occurred while retrieving '%s':\n" #: ports/stm/common-hal/audiopwmio/PWMAudioOut.c msgid "Another PWMAudioOut is already active" @@ -597,11 +603,11 @@ msgstr "Bit depth must be multiple of 8." #: shared-bindings/bitmaptools/__init__.c msgid "Bitmap size and bits per value must match" -msgstr "" +msgstr "Bitmap size and bits per value must match" #: supervisor/shared/safe_mode.c msgid "Boot device must be first (interface #0)." -msgstr "" +msgstr "Boot device must be first (interface #0)." #: ports/mimxrt10xx/common-hal/busio/UART.c msgid "Both RX and TX required for flow control" @@ -662,7 +668,7 @@ msgstr "Buffer too short by %d bytes" #: ports/espressif/common-hal/imagecapture/ParallelImageCapture.c msgid "Buffers must be same size" -msgstr "" +msgstr "Buffers must be same size" #: ports/atmel-samd/common-hal/paralleldisplay/ParallelBus.c #: ports/espressif/common-hal/paralleldisplay/ParallelBus.c @@ -682,7 +688,7 @@ msgstr "CBC blocks must be multiples of 16 bytes" #: supervisor/shared/safe_mode.c msgid "CIRCUITPY drive could not be found or created." -msgstr "" +msgstr "CIRCUITPY drive could not be found or created." #: ports/espressif/common-hal/espidf/__init__.c msgid "CRC or checksum was invalid" @@ -694,7 +700,7 @@ msgstr "Call super().__init__() before accessing native object." #: ports/cxd56/common-hal/camera/Camera.c msgid "Camera init" -msgstr "" +msgstr "Camera init" #: ports/espressif/common-hal/alarm/pin/PinAlarm.c msgid "Can only alarm on RTC IO from deep sleep." @@ -759,7 +765,7 @@ msgstr "Cannot remount '/' when visible via USB." #: ports/cxd56/common-hal/microcontroller/__init__.c #: ports/mimxrt10xx/common-hal/microcontroller/__init__.c msgid "Cannot reset into bootloader because no bootloader is present" -msgstr "" +msgstr "Cannot reset into bootloader because no bootloader is present" #: ports/espressif/common-hal/socketpool/Socket.c msgid "Cannot set socket options" @@ -780,7 +786,7 @@ msgstr "Cannot subclass slice" #: shared-module/bitbangio/SPI.c msgid "Cannot transfer without MOSI and MISO pins" -msgstr "" +msgstr "Cannot transfer without MOSI and MISO pins" #: shared-bindings/pwmio/PWMOut.c msgid "Cannot vary frequency on a timer that is already in use" @@ -788,7 +794,7 @@ msgstr "Cannot vary frequency on a timer that is already in use" #: ports/nrf/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge, only level" -msgstr "" +msgstr "Cannot wake on pin edge, only level" #: ports/espressif/common-hal/alarm/pin/PinAlarm.c msgid "Cannot wake on pin edge. Only level." @@ -820,11 +826,11 @@ msgstr "" #: shared-bindings/bitmaptools/__init__.c msgid "Coordinate arrays have different lengths" -msgstr "" +msgstr "Coordinate arrays have different lengths" #: shared-bindings/bitmaptools/__init__.c msgid "Coordinate arrays types have different sizes" -msgstr "" +msgstr "Coordinate arrays types have different sizes" #: py/persistentcode.c msgid "Corrupt .mpy file" @@ -906,7 +912,7 @@ msgstr "Display rotation must be in 90 degree increments" #: main.c msgid "Done" -msgstr "" +msgstr "Done" #: shared-bindings/digitalio/DigitalInOut.c msgid "Drive mode not used when direction is input." @@ -914,7 +920,7 @@ msgstr "Drive mode not used when direction is input." #: py/obj.c msgid "During handling of the above exception, another exception occurred:" -msgstr "" +msgstr "During handling of the above exception, another exception occurred:" #: shared-bindings/aesio/aes.c msgid "ECB only operates on 16 bytes at a time" @@ -943,7 +949,7 @@ msgstr "Error in regex" #: supervisor/shared/safe_mode.c msgid "Error in safemode.py." -msgstr "" +msgstr "Error in safemode.py." #: shared-bindings/socketpool/Socket.c shared-bindings/ssl/SSLSocket.c msgid "Error: Failure to bind" @@ -951,7 +957,7 @@ msgstr "Error: Failure to bind" #: shared-bindings/alarm/__init__.c msgid "Expected a kind of %q" -msgstr "" +msgstr "Expected a kind of %q" #: ports/espressif/common-hal/_bleio/Adapter.c #: ports/nrf/common-hal/_bleio/Adapter.c @@ -981,7 +987,7 @@ msgstr "Failed to acquire mutex, err 0x%04x" #: shared-module/rgbmatrix/RGBMatrix.c msgid "Failed to allocate %q buffer" -msgstr "" +msgstr "Failed to allocate %q buffer" #: ports/espressif/common-hal/wifi/__init__.c msgid "Failed to allocate Wifi memory" @@ -1019,7 +1025,7 @@ msgstr "Failed to write internal flash." #: supervisor/shared/safe_mode.c msgid "Fault detected by hardware." -msgstr "" +msgstr "Fault detected by hardware." #: py/moduerrno.c msgid "File exists" @@ -1027,7 +1033,7 @@ msgstr "File exists" #: shared-module/os/getenv.c msgid "File not found" -msgstr "" +msgstr "File not found" #: ports/atmel-samd/common-hal/canio/Listener.c #: ports/espressif/common-hal/canio/Listener.c @@ -1037,23 +1043,23 @@ msgstr "Filters too complex" #: ports/espressif/common-hal/dualbank/__init__.c msgid "Firmware is duplicate" -msgstr "" +msgstr "Firmware is duplicate" #: ports/espressif/common-hal/dualbank/__init__.c msgid "Firmware is invalid" -msgstr "" +msgstr "Firmware is invalid" #: ports/espressif/common-hal/dualbank/__init__.c msgid "Firmware is too big" -msgstr "" +msgstr "Firmware is too big" #: shared-bindings/bitmaptools/__init__.c msgid "For L8 colorspace, input bitmap must have 8 bits per pixel" -msgstr "" +msgstr "For L8 colourspace, input bitmap must have 8 bits per pixel" #: shared-bindings/bitmaptools/__init__.c msgid "For RGB colorspaces, input bitmap must have 16 bits per pixel" -msgstr "" +msgstr "For RGB colourspaces, input bitmap must have 16 bits per pixel" #: ports/cxd56/common-hal/camera/Camera.c msgid "Format not supported" @@ -1063,6 +1069,7 @@ msgstr "Format not supported" msgid "" "Frequency must be 24, 150, 396, 450, 528, 600, 720, 816, 912, 960 or 1008 Mhz" msgstr "" +"Frequency must be 24, 150, 396, 450, 528, 600, 720, 816, 912, 960 or 1008 Mhz" #: shared-bindings/pwmio/PWMOut.c msgid "Frequency must match existing PWMOut using this timer" @@ -1075,7 +1082,7 @@ msgstr "Function requires lock" #: ports/cxd56/common-hal/gnss/GNSS.c msgid "GNSS init" -msgstr "" +msgstr "GNSS init" #: ports/espressif/common-hal/espidf/__init__.c msgid "Generic Failure" @@ -1094,7 +1101,7 @@ msgstr "Group already used" #: ports/mimxrt10xx/common-hal/busio/SPI.c ports/nrf/common-hal/busio/SPI.c #: ports/raspberrypi/common-hal/busio/SPI.c msgid "Half duplex SPI is not implemented" -msgstr "" +msgstr "Half duplex SPI is not implemented" #: ports/mimxrt10xx/common-hal/busio/SPI.c ports/stm/common-hal/busio/I2C.c #: ports/stm/common-hal/busio/SPI.c ports/stm/common-hal/canio/CAN.c @@ -1108,12 +1115,13 @@ msgstr "Hardware in use, try alternative pins" #: supervisor/shared/safe_mode.c msgid "Heap allocation when VM not running." -msgstr "" +msgstr "Heap allocation when VM not running." #: supervisor/shared/safe_mode.c msgid "" "Heap was corrupted because the stack was too small. Increase stack size." msgstr "" +"Heap was corrupted because the stack was too small. Increase stack size." #: extmod/vfs_posix_file.c py/objstringio.c msgid "I/O operation on closed file" @@ -1121,7 +1129,7 @@ msgstr "I/O operation on closed file" #: ports/stm/common-hal/busio/I2C.c msgid "I2C init error" -msgstr "" +msgstr "I2C init error" #: ports/raspberrypi/common-hal/busio/I2C.c #: ports/raspberrypi/common-hal/i2ctarget/I2CTarget.c @@ -1207,7 +1215,7 @@ msgstr "Insufficient encryption" #: ports/espressif/common-hal/wifi/Radio.c msgid "Interface must be started" -msgstr "" +msgstr "Interface must be started" #: ports/atmel-samd/audio_dma.c ports/raspberrypi/audio_dma.c msgid "Internal audio buffer too small" @@ -1220,7 +1228,7 @@ msgstr "Internal define error" #: ports/espressif/common-hal/paralleldisplay/ParallelBus.c #: shared-module/os/getenv.c msgid "Internal error" -msgstr "" +msgstr "Internal error" #: shared-module/rgbmatrix/RGBMatrix.c #, c-format @@ -1229,11 +1237,11 @@ msgstr "Internal error #%d" #: supervisor/shared/safe_mode.c msgid "Internal watchdog timer expired." -msgstr "" +msgstr "Internal watchdog timer expired." #: supervisor/shared/safe_mode.c msgid "Interrupt error." -msgstr "" +msgstr "Interrupt error." #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c #: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c From 8927e4118090c3c7f03ed43a7f6167955a84afff Mon Sep 17 00:00:00 2001 From: Debian Date: Sat, 15 Apr 2023 17:05:12 -0600 Subject: [PATCH 023/117] Reset stuck low detection --- shared-module/onewireio/OneWire.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/shared-module/onewireio/OneWire.c b/shared-module/onewireio/OneWire.c index aeb4dcb00d..ff5caa2bac 100644 --- a/shared-module/onewireio/OneWire.c +++ b/shared-module/onewireio/OneWire.c @@ -59,8 +59,10 @@ bool common_hal_onewireio_onewire_reset(onewireio_onewire_obj_t *self) { common_hal_mcu_delay_us(70); bool value = common_hal_digitalio_digitalinout_get_value(&self->pin); common_hal_mcu_delay_us(410); + // test if bus returned high (idle) and not stck at low + bool idle = common_hal_digitalio_digitalinout_get_value(&self->pin); common_hal_mcu_enable_interrupts(); - return value; + return value || !idle; } bool common_hal_onewireio_onewire_read_bit(onewireio_onewire_obj_t *self) { From ec78a23a566c2942a4e555c414c3f1fdff961c33 Mon Sep 17 00:00:00 2001 From: Richard Ellis Date: Sat, 15 Apr 2023 22:54:57 -0400 Subject: [PATCH 024/117] Code changes to allow 64 character hex WiFi passwords to be used with wifi.radio.connect. Fixes adafruit/circuitpython#7677. --- py/argcheck.c | 13 +++++++++++++ py/runtime.h | 1 + shared-bindings/wifi/Radio.c | 10 ++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/py/argcheck.c b/py/argcheck.c index 465a82c97e..73f3ead269 100644 --- a/py/argcheck.c +++ b/py/argcheck.c @@ -268,6 +268,19 @@ mp_int_t mp_arg_validate_type_int(mp_obj_t obj, qstr arg_name) { return an_int; } +mp_int_t mp_arg_validate_valid_hex_password(mp_uint_t length, uint8_t *buf) { + unsigned int i=0; + while (i Date: Sat, 15 Apr 2023 23:44:30 -0400 Subject: [PATCH 025/117] displayio arg validation tweaking --- shared-bindings/displayio/Bitmap.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index 12aee30b19..724c29eb0b 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -62,8 +62,8 @@ //| ... STATIC mp_obj_t displayio_bitmap_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { mp_arg_check_num(n_args, n_kw, 3, 3, false); - uint32_t width = mp_arg_validate_int_range(mp_obj_get_int(all_args[0]), 1, 32767, MP_QSTR_width); - uint32_t height = mp_arg_validate_int_range(mp_obj_get_int(all_args[1]), 1, 32767, MP_QSTR_height); + uint32_t width = mp_arg_validate_int_range(mp_obj_get_int(all_args[0]), 0, 32767, MP_QSTR_width); + uint32_t height = mp_arg_validate_int_range(mp_obj_get_int(all_args[1]), 0, 32767, MP_QSTR_height); uint32_t value_count = mp_arg_validate_int_range(mp_obj_get_int(all_args[2]), 1, 65535, MP_QSTR_value_count); uint32_t bits = 1; @@ -220,8 +220,8 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg check_for_deinit(self); // Check x,y are within self (target) bitmap boundary - int16_t x = mp_arg_validate_int_range(args[ARG_x].u_int, 0, self->width - 1, MP_QSTR_x); - int16_t y = mp_arg_validate_int_range(args[ARG_y].u_int, 0, self->height - 1, MP_QSTR_y); + int16_t x = mp_arg_validate_int_range(args[ARG_x].u_int, 0, self->width, MP_QSTR_x); + int16_t y = mp_arg_validate_int_range(args[ARG_y].u_int, 0, self->height, MP_QSTR_y); displayio_bitmap_t *source = mp_arg_validate_type(args[ARG_source].u_obj, &displayio_bitmap_type, MP_QSTR_source_bitmap); @@ -232,8 +232,8 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg } // Check x1,y1,x2,y2 are within source bitmap boundary - int16_t x1 = mp_arg_validate_int_range(args[ARG_x1].u_int, 0, source->width - 1, MP_QSTR_x1); - int16_t y1 = mp_arg_validate_int_range(args[ARG_y1].u_int, 0, source->height - 1, MP_QSTR_y1); + int16_t x1 = mp_arg_validate_int_range(args[ARG_x1].u_int, 0, source->width, MP_QSTR_x1); + int16_t y1 = mp_arg_validate_int_range(args[ARG_y1].u_int, 0, source->height, MP_QSTR_y1); 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) { From bf548efd85821a329409fda1f0af36fc3d218be4 Mon Sep 17 00:00:00 2001 From: Andi Chandler Date: Sat, 15 Apr 2023 13:17:55 +0000 Subject: [PATCH 026/117] Translated using Weblate (English (United Kingdom)) Currently translated at 100.0% (1000 of 1000 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/en_GB/ --- locale/en_GB.po | 277 +++++++++++++++++++++++++----------------------- 1 file changed, 143 insertions(+), 134 deletions(-) diff --git a/locale/en_GB.po b/locale/en_GB.po index 8b0c8a4b0b..8b7a1da9fc 100644 --- a/locale/en_GB.po +++ b/locale/en_GB.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"PO-Revision-Date: 2023-04-15 11:47+0000\n" +"PO-Revision-Date: 2023-04-16 13:51+0000\n" "Last-Translator: Andi Chandler \n" "Language-Team: none\n" "Language: en_GB\n" @@ -1271,11 +1271,11 @@ msgstr "Invalid BSSID" #: main.c msgid "Invalid CIRCUITPY_PYSTACK_SIZE\n" -msgstr "" +msgstr "Invalid CIRCUITPY_PYSTACK_SIZE\n" #: shared-bindings/wifi/Radio.c msgid "Invalid MAC address" -msgstr "" +msgstr "Invalid MAC address" #: ports/espressif/common-hal/espidf/__init__.c py/moduerrno.c msgid "Invalid argument" @@ -1288,7 +1288,7 @@ msgstr "Invalid bits per value" #: shared-module/os/getenv.c #, c-format msgid "Invalid byte %.*s" -msgstr "" +msgstr "Invalid byte %.*s" #: ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c #, c-format @@ -1297,7 +1297,7 @@ msgstr "Invalid data_pins[%d]" #: shared-module/msgpack/__init__.c msgid "Invalid format" -msgstr "" +msgstr "Invalid format" #: shared-module/audiocore/WaveFile.c msgid "Invalid format chunk size" @@ -1305,7 +1305,7 @@ msgstr "Invalid format chunk size" #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" -msgstr "" +msgstr "Invalid multicast MAC address" #: ports/espressif/common-hal/espidf/__init__.c msgid "Invalid size" @@ -1322,7 +1322,7 @@ msgstr "Invalid state" #: shared-module/os/getenv.c msgid "Invalid unicode escape" -msgstr "" +msgstr "Invalid unicode escape" #: shared-bindings/aesio/aes.c msgid "Key must be 16, 24, or 32 bytes long" @@ -1330,11 +1330,11 @@ msgstr "Key must be 16, 24, or 32 bytes long" #: shared-module/os/getenv.c msgid "Key not found" -msgstr "" +msgstr "Key not found" #: shared-module/is31fl3741/FrameBuffer.c msgid "LED mappings must match display size" -msgstr "" +msgstr "LED mappings must match display size" #: py/compile.c msgid "LHS of keyword arg must be an id" @@ -1342,11 +1342,11 @@ msgstr "LHS of keyword arg must be an id" #: shared-module/displayio/Group.c msgid "Layer already in a group" -msgstr "" +msgstr "Layer already in a group" #: shared-module/displayio/Group.c msgid "Layer must be a Group or TileGrid subclass" -msgstr "" +msgstr "Layer must be a Group or TileGrid subclass" #: ports/espressif/common-hal/espidf/__init__.c msgid "MAC address was invalid" @@ -1354,7 +1354,7 @@ msgstr "MAC address was invalid" #: shared-bindings/is31fl3741/IS31FL3741.c msgid "Mapping must be a tuple" -msgstr "" +msgstr "Mapping must be a tuple" #: shared-module/displayio/Shape.c #, c-format @@ -1368,11 +1368,11 @@ msgstr "Microphone startup delay must be in range 0.0 to 1.0" #: ports/raspberrypi/bindings/rp2pio/StateMachine.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "Mismatched data size" -msgstr "" +msgstr "Mismatched data size" #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "Mismatched swap flag" -msgstr "" +msgstr "Mismatched swap flag" #: ports/mimxrt10xx/common-hal/busio/SPI.c msgid "Missing MISO or MOSI Pin" @@ -1380,7 +1380,7 @@ msgstr "Missing MISO or MOSI pin" #: ports/stm/common-hal/busio/SPI.c msgid "Missing MISO or MOSI pin" -msgstr "" +msgstr "Missing MISO or MOSI pin" #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #, c-format @@ -1440,7 +1440,7 @@ msgstr "NVS Error" #: shared-bindings/socketpool/SocketPool.c msgid "Name or service not known" -msgstr "" +msgstr "Name or service not known" #: py/qstr.c msgid "Name too long" @@ -1448,11 +1448,11 @@ msgstr "Name too long" #: shared-bindings/displayio/TileGrid.c msgid "New bitmap must be same size as old bitmap" -msgstr "" +msgstr "New bitmap must be same size as old bitmap" #: ports/espressif/common-hal/_bleio/__init__.c msgid "Nimble out of memory" -msgstr "" +msgstr "Nimble out of memory" #: ports/espressif/common-hal/_bleio/Characteristic.c #: ports/nrf/common-hal/_bleio/Characteristic.c @@ -1478,11 +1478,11 @@ msgstr "No DMA pacing timer found" #: shared-module/adafruit_bus_device/i2c_device/I2CDevice.c #, c-format msgid "No I2C device at address: 0x%x" -msgstr "" +msgstr "No I2C device at address: 0x%x" #: supervisor/shared/web_workflow/web_workflow.c msgid "No IP" -msgstr "" +msgstr "No IP" #: ports/espressif/common-hal/busio/SPI.c #: ports/mimxrt10xx/common-hal/busio/SPI.c @@ -1491,7 +1491,7 @@ msgstr "No MISO pin" #: ports/stm/common-hal/busio/SPI.c shared-module/bitbangio/SPI.c msgid "No MISO pin" -msgstr "" +msgstr "No MISO pin" #: ports/espressif/common-hal/busio/SPI.c #: ports/mimxrt10xx/common-hal/busio/SPI.c @@ -1500,7 +1500,7 @@ msgstr "No MOSI pin" #: ports/stm/common-hal/busio/SPI.c shared-module/bitbangio/SPI.c msgid "No MOSI pin" -msgstr "" +msgstr "No MOSI pin" #: ports/atmel-samd/common-hal/busio/UART.c #: ports/espressif/common-hal/busio/UART.c @@ -1522,7 +1522,7 @@ msgstr "No available clocks" #: ports/espressif/common-hal/imagecapture/ParallelImageCapture.c msgid "No capture in progress" -msgstr "" +msgstr "No capture in progress" #: shared-bindings/_bleio/PacketBuffer.c msgid "No connection: length cannot be determined" @@ -1577,7 +1577,7 @@ msgstr "No space left on device" #: py/moduerrno.c msgid "No such device" -msgstr "" +msgstr "No such device" #: py/moduerrno.c msgid "No such file/directory" @@ -1609,7 +1609,7 @@ msgstr "Not playing" #: ports/espressif/common-hal/paralleldisplay/ParallelBus.c #, c-format msgid "Number of data_pins must be 8 or 16, not %d" -msgstr "" +msgstr "Number of data_pins must be 8 or 16, not %d" #: shared-bindings/util.c msgid "" @@ -1623,11 +1623,11 @@ msgstr "Odd parity is not supported" #: supervisor/shared/bluetooth/bluetooth.c msgid "Off" -msgstr "" +msgstr "Off" #: supervisor/shared/bluetooth/bluetooth.c msgid "Ok" -msgstr "" +msgstr "Ok" #: ports/atmel-samd/common-hal/audiobusio/PDMIn.c #: ports/raspberrypi/common-hal/audiobusio/PDMIn.c @@ -1674,22 +1674,22 @@ msgstr "" #: ports/espressif/common-hal/alarm/touch/TouchAlarm.c msgid "Only one %q can be set in deep sleep." -msgstr "" +msgstr "Only one %q can be set in deep sleep." #: ports/espressif/common-hal/espulp/ULPAlarm.c msgid "Only one %q can be set." -msgstr "" +msgstr "Only one %q can be set." #: ports/espressif/common-hal/i2ctarget/I2CTarget.c #: ports/raspberrypi/common-hal/i2ctarget/I2CTarget.c msgid "Only one address is allowed" -msgstr "" +msgstr "Only one address is allowed" #: ports/atmel-samd/common-hal/alarm/time/TimeAlarm.c #: ports/nrf/common-hal/alarm/time/TimeAlarm.c #: ports/stm/common-hal/alarm/time/TimeAlarm.c msgid "Only one alarm.time alarm can be set" -msgstr "" +msgstr "Only one alarm.time alarm can be set" #: ports/espressif/common-hal/alarm/time/TimeAlarm.c #: ports/raspberrypi/common-hal/alarm/time/TimeAlarm.c @@ -1702,7 +1702,7 @@ msgstr "Only one colour can be transparent at a time" #: py/moduerrno.c msgid "Operation not permitted" -msgstr "" +msgstr "Operation not permitted" #: ports/espressif/common-hal/espidf/__init__.c msgid "Operation or feature not supported" @@ -1714,7 +1714,7 @@ msgstr "Operation timed out" #: ports/raspberrypi/common-hal/mdns/Server.c msgid "Out of MDNS service slots" -msgstr "" +msgstr "Out of MDNS service slots" #: ports/espressif/common-hal/espidf/__init__.c msgid "Out of memory" @@ -1745,7 +1745,7 @@ msgstr "" #: ports/stm/common-hal/pwmio/PWMOut.c msgid "PWM restart" -msgstr "" +msgstr "PWM restart" #: ports/raspberrypi/common-hal/countio/Counter.c msgid "PWM slice already in use" @@ -1805,7 +1805,7 @@ msgstr "Pins must be sequential" #: ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c msgid "Pins must be sequential GPIO pins" -msgstr "" +msgstr "Pins must be sequential GPIO pins" #: ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c msgid "Pins must share PWM slice" @@ -1845,7 +1845,7 @@ msgstr "Program size invalid" #: ports/espressif/common-hal/espulp/ULP.c msgid "Program too long" -msgstr "" +msgstr "Program too long" #: shared-bindings/digitalio/DigitalInOut.c msgid "Pull not used when direction is output." @@ -1858,7 +1858,7 @@ msgstr "RAISE mode is not implemented" #: ports/raspberrypi/common-hal/countio/Counter.c msgid "RISE_AND_FALL not available on this chip" -msgstr "" +msgstr "RISE_AND_FALL not available on this chip" #: ports/stm/common-hal/os/__init__.c msgid "RNG DeInit Error" @@ -1871,7 +1871,7 @@ msgstr "RNG init Error" #: ports/atmel-samd/common-hal/busio/UART.c ports/cxd56/common-hal/busio/UART.c #: ports/nrf/common-hal/busio/UART.c ports/stm/common-hal/busio/UART.c msgid "RS485" -msgstr "" +msgstr "RS485" #: ports/espressif/common-hal/busio/UART.c #: ports/mimxrt10xx/common-hal/busio/UART.c @@ -1902,7 +1902,7 @@ msgstr "Received response was invalid" #: supervisor/shared/bluetooth/bluetooth.c msgid "Reconnecting" -msgstr "" +msgstr "Reconnecting" #: shared-bindings/displayio/EPaperDisplay.c msgid "Refresh too soon" @@ -1934,7 +1934,7 @@ msgstr "SD card CSD format not supported" #: ports/cxd56/common-hal/sdioio/SDCard.c msgid "SDCard init" -msgstr "" +msgstr "SDCard init" #: ports/stm/common-hal/sdioio/SDCard.c #, c-format @@ -1952,7 +1952,7 @@ msgstr "SPI configuration failed" #: ports/stm/common-hal/busio/SPI.c msgid "SPI init error" -msgstr "" +msgstr "SPI init error" #: ports/raspberrypi/common-hal/busio/SPI.c msgid "SPI peripheral in use" @@ -1960,16 +1960,16 @@ msgstr "SPI peripheral in use" #: ports/stm/common-hal/busio/SPI.c msgid "SPI re-init" -msgstr "" +msgstr "SPI re-init" #: shared-bindings/is31fl3741/FrameBuffer.c msgid "Scale dimensions must divide by 3" -msgstr "" +msgstr "Scale dimensions must divide by 3" #: ports/espressif/common-hal/_bleio/Adapter.c #: ports/nrf/common-hal/_bleio/Adapter.c msgid "Scan already in progress. Stop with stop_scan." -msgstr "" +msgstr "Scan already in progress. Stop with stop_scan." #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c #: ports/atmel-samd/common-hal/audiobusio/PDMIn.c @@ -2011,7 +2011,7 @@ msgstr "Source and destination buffers must be the same length" #: shared-bindings/paralleldisplay/ParallelBus.c msgid "Specify exactly one of data0 or data_pins" -msgstr "" +msgstr "Specify exactly one of data0 or data_pins" #: extmod/modure.c msgid "Splitting with sub-captures" @@ -2027,7 +2027,7 @@ msgstr "Stereo right must be on PWM channel B" #: ports/raspberrypi/common-hal/wifi/Radio.c msgid "Stopping AP is not supported." -msgstr "" +msgstr "Stopping AP is not supported." #: shared-bindings/alarm/time/TimeAlarm.c msgid "Supply one of monotonic_time or epoch_time" @@ -2043,11 +2043,11 @@ msgstr "Temperature read timed out" #: supervisor/shared/safe_mode.c msgid "The `microcontroller` module was used to boot into safe mode." -msgstr "" +msgstr "The `microcontroller` module was used to boot into safe mode." #: py/obj.c msgid "The above exception was the direct cause of the following exception:" -msgstr "" +msgstr "The above exception was the direct cause of the following exception:" #: shared-bindings/rgbmatrix/RGBMatrix.c msgid "The length of rgb_pins must be 6, 12, 18, 24, or 30" @@ -2055,7 +2055,7 @@ msgstr "The length of rgb_pins must be 6, 12, 18, 24, or 30" #: supervisor/shared/safe_mode.c msgid "The power dipped. Make sure you are providing enough power." -msgstr "" +msgstr "The power dipped. Make sure you are providing enough power." #: shared-module/audiomixer/MixerVoice.c msgid "The sample's bits_per_sample does not match the mixer's" @@ -2075,17 +2075,19 @@ msgstr "The sample's signedness does not match the mixer's" #: supervisor/shared/safe_mode.c msgid "Third-party firmware fatal error." -msgstr "" +msgstr "Third-party firmware fatal error." #: shared-module/imagecapture/ParallelImageCapture.c msgid "This microcontroller does not support continuous capture." -msgstr "" +msgstr "This microcontroller does not support continuous capture." #: shared-module/paralleldisplay/ParallelBus.c msgid "" "This microcontroller only supports data0=, not data_pins=, because it " "requires contiguous pins." msgstr "" +"This microcontroller only supports data0=, not data_pins=, because it " +"requires contiguous pins." #: shared-bindings/displayio/TileGrid.c msgid "Tile height must exactly divide bitmap height" @@ -2111,7 +2113,7 @@ msgstr "Timeout is too long: Maximum timeout length is %d seconds" #: ports/atmel-samd/common-hal/audiobusio/I2SOut.c msgid "Too many channels in sample" -msgstr "" +msgstr "Too many channels in sample" #: ports/raspberrypi/common-hal/audiobusio/I2SOut.c msgid "Too many channels in sample." @@ -2146,28 +2148,28 @@ msgstr "Tuple or struct_time argument required" #: ports/stm/common-hal/busio/UART.c msgid "UART de-init" -msgstr "" +msgstr "UART de-init" #: ports/atmel-samd/common-hal/busio/UART.c ports/cxd56/common-hal/busio/UART.c #: ports/espressif/common-hal/busio/UART.c ports/stm/common-hal/busio/UART.c msgid "UART init" -msgstr "" +msgstr "UART init" #: ports/raspberrypi/common-hal/busio/UART.c msgid "UART peripheral in use" -msgstr "" +msgstr "UART peripheral in use" #: ports/stm/common-hal/busio/UART.c msgid "UART re-init" -msgstr "" +msgstr "UART re-init" #: ports/stm/common-hal/busio/UART.c msgid "UART write" -msgstr "" +msgstr "UART write" #: main.c msgid "UID:" -msgstr "" +msgstr "UID:" #: shared-module/usb_hid/Device.c msgid "USB busy" @@ -2206,12 +2208,12 @@ msgstr "Unable to allocate buffers for signed conversion" #: supervisor/shared/safe_mode.c msgid "Unable to allocate the heap." -msgstr "" +msgstr "Unable to allocate the heap." #: ports/espressif/common-hal/analogbufio/BufferedIn.c #, c-format msgid "Unable to configure ADC DMA controller, ErrorCode:%d" -msgstr "" +msgstr "Unable to configure ADC DMA controller, ErrorCode:%d" #: ports/espressif/common-hal/busio/I2C.c msgid "Unable to create lock" @@ -2234,7 +2236,7 @@ msgstr "Unable to init parser" #: ports/espressif/common-hal/analogbufio/BufferedIn.c #, c-format msgid "Unable to initialize ADC DMA controller, ErrorCode:%d" -msgstr "" +msgstr "Unable to initialise ADC DMA controller, ErrorCode:%d" #: shared-module/displayio/OnDiskBitmap.c msgid "Unable to read color palette data" @@ -2243,16 +2245,16 @@ msgstr "Unable to read colour palette data" #: ports/espressif/common-hal/analogbufio/BufferedIn.c #, c-format msgid "Unable to start ADC DMA controller, ErrorCode:%d" -msgstr "" +msgstr "Unable to start ADC DMA controller, ErrorCode:%d" #: ports/espressif/common-hal/mdns/Server.c #: ports/raspberrypi/common-hal/mdns/Server.c msgid "Unable to start mDNS query" -msgstr "" +msgstr "Unable to start mDNS query" #: shared-bindings/memorymap/AddressRange.c msgid "Unable to write to address." -msgstr "" +msgstr "Unable to write to address." #: shared-bindings/nvm/ByteArray.c msgid "Unable to write to nvm." @@ -2274,17 +2276,17 @@ msgstr "Unhandled ESP TLS error %d %d %x %d" #: ports/espressif/common-hal/_bleio/__init__.c #, c-format msgid "Unknown BLE error at %s:%d: %d" -msgstr "" +msgstr "Unknown BLE error at %s:%d: %d" #: ports/espressif/common-hal/_bleio/__init__.c #, c-format msgid "Unknown BLE error: %d" -msgstr "" +msgstr "Unknown BLE error: %d" #: ports/raspberrypi/common-hal/wifi/__init__.c #, c-format msgid "Unknown error code %d" -msgstr "" +msgstr "Unknown error code %d" #: shared-bindings/wifi/Radio.c #, c-format @@ -2309,7 +2311,7 @@ msgstr "Unknown security error: 0x%04x" #: ports/espressif/common-hal/_bleio/__init__.c #, c-format msgid "Unknown system firmware error at %s:%d: %d" -msgstr "" +msgstr "Unknown system firmware error at %s:%d: %d" #: ports/nrf/common-hal/_bleio/__init__.c #, c-format @@ -2319,7 +2321,7 @@ msgstr "Unknown system firmware error: %04x" #: ports/espressif/common-hal/_bleio/__init__.c #, c-format msgid "Unknown system firmware error: %d" -msgstr "" +msgstr "Unknown system firmware error: %d" #: shared-bindings/adafruit_pixelbuf/PixelBuf.c #: shared-module/_pixelmap/PixelMap.c @@ -2337,7 +2339,7 @@ msgstr "" #: shared-bindings/bitmaptools/__init__.c msgid "Unsupported colorspace" -msgstr "" +msgstr "Unsupported colourspace" #: shared-module/displayio/display_core.c msgid "Unsupported display bus type" @@ -2349,7 +2351,7 @@ msgstr "Unsupported format" #: shared-bindings/hashlib/__init__.c msgid "Unsupported hash algorithm" -msgstr "" +msgstr "Unsupported hash algorithm" #: ports/espressif/common-hal/dualbank/__init__.c msgid "Update Failed" @@ -2404,22 +2406,27 @@ msgid "" "\n" "To list built-in modules type `help(\"modules\")`.\n" msgstr "" +"Welcome to Adafruit CircuitPython %s!\n" +"\n" +"Visit circuitpython.org for more information.\n" +"\n" +"To list built-in modules type `help(\"modules\")`.\n" #: supervisor/shared/web_workflow/web_workflow.c msgid "Wi-Fi: " -msgstr "" +msgstr "Wi-Fi: " #: ports/raspberrypi/common-hal/wifi/Radio.c msgid "Wifi is in access point mode." -msgstr "" +msgstr "Wifi is in access point mode." #: ports/raspberrypi/common-hal/wifi/Radio.c msgid "Wifi is in station mode." -msgstr "" +msgstr "Wifi is in station mode." #: ports/raspberrypi/common-hal/wifi/Radio.c msgid "Wifi is not enabled" -msgstr "" +msgstr "Wifi is not enabled" #: main.c msgid "Woken up by alarm.\n" @@ -2435,52 +2442,52 @@ msgstr "Writes not supported on Characteristic" #: ports/atmel-samd/boards/circuitplayground_express_displayio/mpconfigboard.h #: ports/atmel-samd/boards/meowmeow/mpconfigboard.h msgid "You pressed both buttons at start up." -msgstr "" +msgstr "You pressed both buttons at start up." #: ports/espressif/boards/m5stack_core_basic/mpconfigboard.h #: ports/espressif/boards/m5stack_core_fire/mpconfigboard.h #: ports/espressif/boards/m5stack_stick_c/mpconfigboard.h msgid "You pressed button A at start up." -msgstr "" +msgstr "You pressed button A at start up." #: supervisor/shared/safe_mode.c msgid "You pressed the BOOT button at start up" -msgstr "" +msgstr "You pressed the BOOT button at start up" #: ports/espressif/boards/adafruit_huzzah32_breakout/mpconfigboard.h msgid "You pressed the GPIO0 button at start up." -msgstr "" +msgstr "You pressed the GPIO0 button at start up." #: ports/espressif/boards/espressif_esp32_lyrat/mpconfigboard.h msgid "You pressed the Rec button at start up." -msgstr "" +msgstr "You pressed the Rec button at start up." #: ports/espressif/boards/adafruit_feather_esp32_v2/mpconfigboard.h msgid "You pressed the SW38 button at start up." -msgstr "" +msgstr "You pressed the SW38 button at start up." #: ports/espressif/boards/hardkernel_odroid_go/mpconfigboard.h msgid "You pressed the VOLUME button at start up." -msgstr "" +msgstr "You pressed the VOLUME button at start up." #: ports/espressif/boards/m5stack_atom_echo/mpconfigboard.h #: ports/espressif/boards/m5stack_atom_lite/mpconfigboard.h #: ports/espressif/boards/m5stack_atom_matrix/mpconfigboard.h #: ports/espressif/boards/m5stack_atom_u/mpconfigboard.h msgid "You pressed the central button at start up." -msgstr "" +msgstr "You pressed the central button at start up." #: ports/nrf/boards/aramcon2_badge/mpconfigboard.h msgid "You pressed the left button at start up." -msgstr "" +msgstr "You pressed the left button at start up." #: supervisor/shared/safe_mode.c msgid "You pressed the reset button during boot." -msgstr "" +msgstr "You pressed the reset button during boot." #: supervisor/shared/micropython.c msgid "[truncated due to length]" -msgstr "" +msgstr "[truncated due to length]" #: py/objtype.c msgid "__init__() should return None" @@ -2549,11 +2556,11 @@ msgstr "array and index length must be equal" #: extmod/ulab/code/numpy/io/io.c msgid "array has too many dimensions" -msgstr "" +msgstr "array has too many dimensions" #: extmod/ulab/code/ndarray.c msgid "array is too big" -msgstr "" +msgstr "array is too big" #: py/objarray.c shared-bindings/alarm/SleepMemory.c #: shared-bindings/memorymap/AddressRange.c shared-bindings/nvm/ByteArray.c @@ -2610,7 +2617,7 @@ msgstr "binary op %q not implemented" #: shared-bindings/bitmaptools/__init__.c msgid "bitmap sizes must match" -msgstr "" +msgstr "bitmap sizes must match" #: extmod/modurandom.c msgid "bits must be 32 or less" @@ -2668,7 +2675,7 @@ msgstr "Calibration is read only" #: shared-module/vectorio/Circle.c shared-module/vectorio/Polygon.c #: shared-module/vectorio/Rectangle.c msgid "can only have one parent" -msgstr "" +msgstr "can only have one parent" #: py/emitinlinethumb.c msgid "can only have up to 4 parameters to Thumb assembly" @@ -2705,7 +2712,7 @@ msgstr "Can't convert '%q' object to %q implicitly" #: extmod/ulab/code/numpy/vector.c msgid "can't convert complex to float" -msgstr "" +msgstr "can't convert complex to float" #: py/obj.c msgid "can't convert to %q" @@ -2761,7 +2768,7 @@ msgstr "can't load with '%q' index" #: py/builtinimport.c msgid "can't perform relative import" -msgstr "" +msgstr "can't perform relative import" #: py/objgenerator.c msgid "can't send non-None value to a just-started generator" @@ -2777,7 +2784,7 @@ msgstr "can't set attribute" #: py/runtime.c shared-bindings/supervisor/Runtime.c msgid "can't set attribute '%q'" -msgstr "" +msgstr "can't set attribute '%q'" #: py/emitnative.c msgid "can't store '%q'" @@ -2813,11 +2820,11 @@ msgstr "can't cast output with casting rule" #: extmod/ulab/code/ndarray.c msgid "cannot convert complex to dtype" -msgstr "" +msgstr "cannot convert complex to dtype" #: extmod/ulab/code/ndarray.c msgid "cannot convert complex type" -msgstr "" +msgstr "cannot convert complex type" #: py/objtype.c msgid "cannot create '%q' instances" @@ -2841,7 +2848,7 @@ msgstr "casting" #: ports/stm/common-hal/pwmio/PWMOut.c msgid "channel re-init" -msgstr "" +msgstr "channel re-init" #: shared-bindings/_stage/Text.c msgid "chars buffer too small" @@ -2913,7 +2920,7 @@ msgstr "convolve arguments must not be empty" #: extmod/ulab/code/numpy/io/io.c msgid "corrupted file" -msgstr "" +msgstr "corrupted file" #: extmod/ulab/code/numpy/poly.c msgid "could not invert Vandermonde matrix" @@ -2996,7 +3003,7 @@ msgstr "division by zero" #: extmod/ulab/code/numpy/vector.c msgid "dtype must be float, or complex" -msgstr "" +msgstr "dtype must be float, or complex" #: py/objdeque.c msgid "empty" @@ -3004,7 +3011,7 @@ msgstr "empty" #: extmod/ulab/code/numpy/io/io.c msgid "empty file" -msgstr "" +msgstr "empty file" #: extmod/moduasyncio.c extmod/moduheapq.c extmod/modutimeq.c msgid "empty heap" @@ -3036,6 +3043,8 @@ msgid "" "espcamera.Camera requires reserved PSRAM to be configured. See the " "documentation for instructions." msgstr "" +"espcamera.Camera requires reserved PSRAM to be configured. See the " +"documentation for instructions." #: py/runtime.c msgid "exceptions must derive from BaseException" @@ -3166,7 +3175,7 @@ msgstr "function is defined for ndarrays only" #: extmod/ulab/code/numpy/carray/carray.c msgid "function is implemented for ndarrays only" -msgstr "" +msgstr "function is implemented for ndarrays only" #: py/argcheck.c #, c-format @@ -3253,7 +3262,7 @@ msgstr "index is out of bounds" #: shared-bindings/_pixelmap/PixelMap.c msgid "index must be tuple or int" -msgstr "" +msgstr "index must be tuple or int" #: extmod/ulab/code/numpy/numerical.c extmod/ulab/code/ulab_tools.c #: ports/espressif/common-hal/pulseio/PulseIn.c @@ -3267,7 +3276,7 @@ msgstr "indices must be integers, slices, or Boolean lists" #: ports/espressif/common-hal/busio/I2C.c msgid "init I2C" -msgstr "" +msgstr "init I2C" #: extmod/ulab/code/scipy/optimize/optimize.c msgid "initial values must be iterable" @@ -3303,7 +3312,7 @@ msgstr "input data must be an iterable" #: extmod/ulab/code/numpy/vector.c msgid "input dtype must be float or complex" -msgstr "" +msgstr "input dtype must be float or complex" #: extmod/ulab/code/numpy/linalg/linalg.c msgid "input matrix is asymmetric" @@ -3316,11 +3325,11 @@ msgstr "input matrix is singular" #: extmod/ulab/code/numpy/create.c msgid "input must be 1- or 2-d" -msgstr "" +msgstr "input must be 1- or 2-d" #: extmod/ulab/code/numpy/carray/carray.c msgid "input must be a 1D ndarray" -msgstr "" +msgstr "input must be a 1D ndarray" #: extmod/ulab/code/scipy/linalg/linalg.c extmod/ulab/code/user/user.c msgid "input must be a dense ndarray" @@ -3332,7 +3341,7 @@ msgstr "input must be an ndarray" #: extmod/ulab/code/numpy/carray/carray.c msgid "input must be an ndarray, or a scalar" -msgstr "" +msgstr "input must be an ndarray, or a scalar" #: extmod/ulab/code/scipy/signal/signal.c msgid "input must be one-dimensional" @@ -3412,7 +3421,7 @@ msgstr "invalid micropython decorator" #: ports/espressif/common-hal/espcamera/Camera.c msgid "invalid setting" -msgstr "" +msgstr "invalid setting" #: shared-bindings/random/__init__.c msgid "invalid step" @@ -3498,12 +3507,12 @@ msgstr "loopback + silent mode not supported by peripheral" #: ports/espressif/common-hal/mdns/Server.c #: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS already initialized" -msgstr "" +msgstr "mDNS already initialszed" #: ports/espressif/common-hal/mdns/Server.c #: ports/raspberrypi/common-hal/mdns/Server.c msgid "mDNS only works with built-in WiFi" -msgstr "" +msgstr "mDNS only works with built-in WiFi" #: py/parse.c msgid "malformed f-string" @@ -3530,7 +3539,7 @@ msgstr "max_length must be 0-%d when fixed_length is %s" #: extmod/ulab/code/ndarray.c msgid "maximum number of dimensions is " -msgstr "" +msgstr "maximum number of dimensions is " #: py/runtime.c msgid "maximum recursion depth exceeded" @@ -3571,7 +3580,7 @@ msgstr "module not found" #: ports/espressif/common-hal/wifi/Monitor.c msgid "monitor init failed" -msgstr "" +msgstr "monitor init failed" #: extmod/ulab/code/numpy/poly.c msgid "more degrees of freedom than data points" @@ -3632,7 +3641,7 @@ msgstr "negative shift count" #: shared-bindings/_pixelmap/PixelMap.c msgid "nested index must be int" -msgstr "" +msgstr "nested index must be int" #: shared-module/sdcardio/SDCard.c msgid "no SD card" @@ -3714,7 +3723,7 @@ msgstr "not enough arguments for format string" #: extmod/ulab/code/numpy/carray/carray_tools.c msgid "not implemented for complex dtype" -msgstr "" +msgstr "not implemented for complex dtype" #: extmod/ulab/code/numpy/create.c msgid "number of points must be at least 2" @@ -3776,7 +3785,7 @@ msgstr "odd-length string" #: supervisor/shared/web_workflow/web_workflow.c msgid "off" -msgstr "" +msgstr "off" #: extmod/ulab/code/utils/utils.c msgid "offset is too large" @@ -3801,15 +3810,15 @@ msgstr "only bit_depth=16 is supported" #: ports/stm/common-hal/audiobusio/PDMIn.c msgid "only mono is supported" -msgstr "" +msgstr "only mono is supported" #: extmod/ulab/code/numpy/create.c msgid "only ndarrays can be concatenated" -msgstr "" +msgstr "only ndarrays can be concatenated" #: ports/stm/common-hal/audiobusio/PDMIn.c msgid "only oversample=64 is supported" -msgstr "" +msgstr "only oversample=64 is supported" #: ports/nrf/common-hal/audiobusio/PDMIn.c #: ports/stm/common-hal/audiobusio/PDMIn.c @@ -3903,7 +3912,7 @@ msgstr "pixel_shader must be displayio.Palette or displayio.ColorConverter" #: extmod/vfs_posix_file.c msgid "poll on file not available on win32" -msgstr "" +msgstr "poll on file not available on win32" #: ports/espressif/common-hal/pulseio/PulseIn.c msgid "pop from an empty PulseIn" @@ -3940,7 +3949,7 @@ msgstr "queue overflow" #: py/parse.c msgid "raw f-strings are not supported" -msgstr "" +msgstr "raw f-strings are not supported" #: extmod/ulab/code/numpy/fft/fft_tools.c msgid "real and imaginary parts must be of equal length" @@ -4059,15 +4068,15 @@ msgstr "source palette too large" #: shared-bindings/bitmaptools/__init__.c msgid "source_bitmap must have value_count of 2 or 65536" -msgstr "" +msgstr "source_bitmap must have value_count of 2 or 65536" #: shared-bindings/bitmaptools/__init__.c msgid "source_bitmap must have value_count of 65536" -msgstr "" +msgstr "source_bitmap must have value_count of 65536" #: shared-bindings/bitmaptools/__init__.c msgid "source_bitmap must have value_count of 8" -msgstr "" +msgstr "source_bitmap must have value_count of 8" #: py/objstr.c msgid "start/end indices" @@ -4134,7 +4143,7 @@ msgstr "timeout waiting for v2 card" #: ports/stm/common-hal/pwmio/PWMOut.c msgid "timer re-init" -msgstr "" +msgstr "timer re-init" #: shared-bindings/time/__init__.c msgid "timestamp out of range for platform time_t" @@ -4225,7 +4234,7 @@ msgstr "unicode name escapes" #: py/parse.c msgid "unindent doesn't match any outer indent level" -msgstr "" +msgstr "unindent doesn't match any outer indent level" #: py/objstr.c #, c-format @@ -4247,7 +4256,7 @@ msgstr "unknown type '%q'" #: py/objstr.c #, c-format msgid "unmatched '%c' in format" -msgstr "" +msgstr "unmatched '%c' in format" #: py/objtype.c py/runtime.c msgid "unreadable attribute" @@ -4269,11 +4278,11 @@ msgstr "unsupported Xtensa instruction '%s' with %d arguments" #: shared-module/gifio/GifWriter.c msgid "unsupported colorspace for GifWriter" -msgstr "" +msgstr "unsupported colourspace for GifWriter" #: shared-bindings/bitmaptools/__init__.c msgid "unsupported colorspace for dither" -msgstr "" +msgstr "unsupported colourspace for dither" #: py/objstr.c #, c-format @@ -4294,11 +4303,11 @@ msgstr "unsupported types for %q: '%q', '%q'" #: extmod/ulab/code/numpy/io/io.c msgid "usecols is too high" -msgstr "" +msgstr "usecols is too high" #: extmod/ulab/code/numpy/io/io.c msgid "usecols keyword must be specified" -msgstr "" +msgstr "usecols keyword must be specified" #: py/objint.c #, c-format @@ -4324,7 +4333,7 @@ msgstr "WiFi is not enabled" #: ports/raspberrypi/common-hal/wifi/Monitor.c msgid "wifi.Monitor not available" -msgstr "" +msgstr "wifi.Monitor not available" #: shared-bindings/_bleio/Adapter.c msgid "window must be <= interval" @@ -4340,11 +4349,11 @@ msgstr "wrong axis specified" #: extmod/ulab/code/numpy/io/io.c msgid "wrong dtype" -msgstr "" +msgstr "wrong dtype" #: extmod/ulab/code/numpy/transform.c msgid "wrong index type" -msgstr "" +msgstr "wrong index type" #: extmod/ulab/code/numpy/compare.c extmod/ulab/code/numpy/create.c #: extmod/ulab/code/numpy/io/io.c extmod/ulab/code/numpy/transform.c @@ -4354,11 +4363,11 @@ msgstr "wrong input type" #: extmod/ulab/code/numpy/transform.c msgid "wrong length of condition array" -msgstr "" +msgstr "wrong length of condition array" #: extmod/ulab/code/numpy/transform.c msgid "wrong length of index array" -msgstr "" +msgstr "wrong length of index array" #: extmod/ulab/code/numpy/create.c py/objarray.c py/objstr.c msgid "wrong number of arguments" From 27a97dec16cd3b62db66ae54fe45849ae4dc86c2 Mon Sep 17 00:00:00 2001 From: Ted Hess Date: Sun, 16 Apr 2023 15:51:11 -0400 Subject: [PATCH 027/117] Static web pages: - Move loading .js scripts from to for faster rendering - Enable back-button support for file system/editor navigation - Close WebSocket when navigating away from /cp/serial - Use better looking Blinka icon. --- .../shared/web_workflow/static/blinka_16x16.ico | Bin 318 -> 0 bytes .../shared/web_workflow/static/blinka_32x32.ico | Bin 0 -> 4414 bytes .../shared/web_workflow/static/directory.html | 2 +- .../shared/web_workflow/static/directory.js | 10 ++++++++++ .../shared/web_workflow/static/serial.html | 3 ++- supervisor/shared/web_workflow/static/serial.js | 11 +++++++++++ .../shared/web_workflow/static/welcome.html | 2 +- supervisor/shared/web_workflow/web_workflow.c | 4 ++-- 8 files changed, 27 insertions(+), 5 deletions(-) delete mode 100644 supervisor/shared/web_workflow/static/blinka_16x16.ico create mode 100644 supervisor/shared/web_workflow/static/blinka_32x32.ico diff --git a/supervisor/shared/web_workflow/static/blinka_16x16.ico b/supervisor/shared/web_workflow/static/blinka_16x16.ico deleted file mode 100644 index ff2937dfee32c98d6a34162b96e5d8b4ee8aafe6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 318 zcmZ{fu}T9$6h-gGfMo^?+sIUlrL$d-4Ve+GC01)2wlI}NB3RjM`m7&dXJ?ZEi)q5* zhxiG`N<HYMX~zRyXl#7ft3uVT~Gu!kQNqyfCl5U>@S)=YSSD0G17(^w%NaXQTuC Pb%9L^{7eaRP19`w1vX@( diff --git a/supervisor/shared/web_workflow/static/blinka_32x32.ico b/supervisor/shared/web_workflow/static/blinka_32x32.ico new file mode 100644 index 0000000000000000000000000000000000000000..5aca98376a1f7e593ebd9cf41a808512c2135635 GIT binary patch literal 4414 zcmd^BX;4#F6n=SG-XmlONeGrD5E6J{RVh+e928U#MG!$jWvO+UsvWh`x&VqGNx*en zx=qox7Dqv{kPwo%fZC$dDwVpRtz{HzTkSs8QhG0)%Y=-3@Kt!4ag|JcIo?$-F|?bXVS9UDUyev>MVZQ(H8K4#;BQW-t2CPorj8^KJrMX}QK zp+e<;4ldpXz~=)2GxNy811&)gt-}Q*yVQpsxr@VMoA##{)$1~=bZ1MmjeFw?uT(`8 z^g=09<=zW%r%buwN%iHtuKSg|+r7HkT0PYN*_u9k1;^Ss-Z!RBfJ?Un4w(awqp2b3 z%+myoFis_lTlCrGx2z$0BQdh+7?!JK#9K9@Z!VrG zNj6gK5r(b4?YDOLw|DPRoN7bdP{(>GEG41YcN~4r_SUHU2hgVtUwZG@s%edC;k7Sn zC)RvEnlq~raE2mY2ko64^m1KQL}3riixh?#J{o)IT+K-RdHae2eRX91-+g!y`8^># z-zI0ir>P%Xon)!@xp-BK2bDYUB9k613NRrY6%lVjbFcQc*pRqiK~8xtkNPLxt}e?&QsTB}^!39t_%Qb)~Ukn0O%iC;zt z<&A-y;3h++)>c1br`5VFM~5(83!HKx$L+my8sW_c#@x*|*vB1yU)_dt3vH;2hqPWx zAl^6@?ipx&U7pf`a*>Yq6C85nb+B=Fnn+(id$W#WB^uHAcZVG`qg;rWB}ubvi(Y>D z$ei>REw$#xp0SHAd^|1hq&9HJ=jKK8^zTH~nk)G?yUcmTh9vUM6Y0LMw4(gYVY$D$ zGl&WY&H<)BbJ&3sYbKjx1j^=3-0Q#f^}(aP1?8^`&FUWMp|rmtpK)bLQ1Zo?^s4jqK=Lfg*9&geMGVQ z#^-*!V`fG@;H&{M9S8%+;|h&Qrxym0Ar>WT4BCVLR8cGXF=JmEYN(sNT(9vl+S|%g z8r7nXQ(95i^`=+XHo|){$vf2$?=`F$^&wFlYXyXg$B{a>$-Fp+V}+D;9k=~Xl~?C4 zAB-;RKXdUzBJE{V&d&%R>aEfFe;vxqI$0@hwVM}gFeQR@j}a>DDxR+n+-*6|_)k%% z*mSpDV|=5I9!&VC&9tD%fcVygWZV!iIo2qFtm#!*(s|@ZT33*Ad;+<|3^+yrp*;oH zBSYLV(H1zTU?2WjrCQoQW)Z>J2a=dTriuvezBmu16`tM2fm7Q@d4^iqII-xFpwHGI zn9CL}QE*1vdj2PX{PIuqOe5dracsciH6OlAZATvE8rj6ykqdIjal2 z0S0S~PwHb-5?OQ-tU-^KTG@XNrEVSvo|HIP?H;7ZhYeZkhSqh-{reE!5di;1zk$#Y zCe7rOnlzFYJ6Z#Hm$GoidKB=2HBCwm`BbZVeZY4ukmG%1uz7p2URs6c9j-Gjj^oQV zsdDb3@k2e`C$1I5ML5U0Qs0C1GAp^?!*`=|Nm(vWz3j*j*8ucum2;r0^-6Aca=Gv) zc%}&;!+_*S2tlnnJnz0EKeRmw-Y!@9ob!XQBwiv}^u9MkaXHvM=!<3YX;+2#5Cj5pp?FEK750S3BgeSDtaE^ zXUM@xoV6yBFKfzvY20V&Lr0yC - @@ -21,4 +20,5 @@
+📁  + diff --git a/supervisor/shared/web_workflow/static/directory.js b/supervisor/shared/web_workflow/static/directory.js index a89d5e5602..2068ca38ea 100644 --- a/supervisor/shared/web_workflow/static/directory.js +++ b/supervisor/shared/web_workflow/static/directory.js @@ -267,3 +267,13 @@ new_directory_name.oninput = () => { } window.onhashchange = refresh_list; + +window.addEventListener("pageshow", function (event) { + var historyTraversal = event.persisted || + (typeof window.performance != "undefined" && + window.performance.navigation.type === 2); + if (historyTraversal) { + // Handle page restore. + window.location.reload(); + } +}); diff --git a/supervisor/shared/web_workflow/static/serial.html b/supervisor/shared/web_workflow/static/serial.html index 9193953443..24fb3a3d32 100644 --- a/supervisor/shared/web_workflow/static/serial.html +++ b/supervisor/shared/web_workflow/static/serial.html @@ -4,7 +4,6 @@ Simple client - @@ -16,11 +15,13 @@
Ctrl +
+ diff --git a/supervisor/shared/web_workflow/static/serial.js b/supervisor/shared/web_workflow/static/serial.js index 5c644795a0..52cde95396 100644 --- a/supervisor/shared/web_workflow/static/serial.js +++ b/supervisor/shared/web_workflow/static/serial.js @@ -72,6 +72,17 @@ input.addEventListener("beforeinput", function(e) { } }); +window.addEventListener("unload", function() { + if (ws.readyState == WebSocket.OPEN) { + ws.close(); + } +}); + +let ctrl_b = document.querySelector("#b"); +ctrl_b.onclick = function() { + ws.send("\x02"); +} + let ctrl_c = document.querySelector("#c"); ctrl_c.onclick = function() { ws.send("\x03"); diff --git a/supervisor/shared/web_workflow/static/welcome.html b/supervisor/shared/web_workflow/static/welcome.html index efbb30e312..ffd23b72e9 100644 --- a/supervisor/shared/web_workflow/static/welcome.html +++ b/supervisor/shared/web_workflow/static/welcome.html @@ -4,7 +4,6 @@ CircuitPython - @@ -30,5 +29,6 @@

Here are other CircuitPython devices on your network:

+ diff --git a/supervisor/shared/web_workflow/web_workflow.c b/supervisor/shared/web_workflow/web_workflow.c index d24547dd09..30ff2004a7 100644 --- a/supervisor/shared/web_workflow/web_workflow.c +++ b/supervisor/shared/web_workflow/web_workflow.c @@ -1002,7 +1002,7 @@ STATIC_FILE(edit_js); STATIC_FILE(style_css); STATIC_FILE(serial_html); STATIC_FILE(serial_js); -STATIC_FILE(blinka_16x16_ico); +STATIC_FILE(blinka_32x32_ico); static void _reply_static(socketpool_socket_obj_t *socket, _request *request, const uint8_t *response, size_t response_len, const char *content_type) { uint32_t total_length = response_len; @@ -1303,7 +1303,7 @@ static bool _reply(socketpool_socket_obj_t *socket, _request *request) { } else if (strcmp(request->path, "/favicon.ico") == 0) { // TODO: Autogenerate this based on the blinka bitmap and change the // palette based on MAC address. - _REPLY_STATIC(socket, request, blinka_16x16_ico); + _REPLY_STATIC(socket, request, blinka_32x32_ico); } else { _reply_missing(socket, request); } From a4cb73a567e39d9cc97def164b4a3fa70e92ce9f Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Sun, 16 Apr 2023 18:42:00 -0400 Subject: [PATCH 028/117] Add MAX(0,xxx-1) to prevent potential display wrap --- 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 724c29eb0b..3513f03554 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -220,8 +220,8 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg check_for_deinit(self); // Check x,y are within self (target) bitmap boundary - int16_t x = mp_arg_validate_int_range(args[ARG_x].u_int, 0, self->width, MP_QSTR_x); - int16_t y = mp_arg_validate_int_range(args[ARG_y].u_int, 0, self->height, MP_QSTR_y); + int16_t x = mp_arg_validate_int_range(args[ARG_x].u_int, 0, MAX(0, self->width - 1), MP_QSTR_x); + int16_t y = mp_arg_validate_int_range(args[ARG_y].u_int, 0, MAX(0, self->height - 1), MP_QSTR_y); displayio_bitmap_t *source = mp_arg_validate_type(args[ARG_source].u_obj, &displayio_bitmap_type, MP_QSTR_source_bitmap); @@ -232,8 +232,8 @@ STATIC mp_obj_t displayio_bitmap_obj_blit(size_t n_args, const mp_obj_t *pos_arg } // Check x1,y1,x2,y2 are within source bitmap boundary - int16_t x1 = mp_arg_validate_int_range(args[ARG_x1].u_int, 0, source->width, MP_QSTR_x1); - int16_t y1 = mp_arg_validate_int_range(args[ARG_y1].u_int, 0, source->height, MP_QSTR_y1); + int16_t x1 = mp_arg_validate_int_range(args[ARG_x1].u_int, 0, MAX(0, source->width - 1), MP_QSTR_x1); + int16_t y1 = mp_arg_validate_int_range(args[ARG_y1].u_int, 0, MAX(0, source->height - 1), MP_QSTR_y1); 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) { From 2a49567ec6e17eb3246140726c09027d204658b8 Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Mon, 17 Apr 2023 19:03:42 +0200 Subject: [PATCH 029/117] added Adafruit_CircuitPython_Register to frozen libs --- ports/raspberrypi/boards/pimoroni_badger2040w/mpconfigboard.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/raspberrypi/boards/pimoroni_badger2040w/mpconfigboard.mk b/ports/raspberrypi/boards/pimoroni_badger2040w/mpconfigboard.mk index 4ddb0e7d87..f5d0a3a05a 100644 --- a/ports/raspberrypi/boards/pimoroni_badger2040w/mpconfigboard.mk +++ b/ports/raspberrypi/boards/pimoroni_badger2040w/mpconfigboard.mk @@ -25,3 +25,4 @@ CFLAGS += -DCYW43_PIN_WL_HOST_WAKE=24 -DCYW43_PIN_WL_REG_ON=23 -DCYW43_WL_GPIO_C CFLAGS += -DCIRCUITPY_FIRMWARE_SIZE='(1536 * 1024)' FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-pcf85063a +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Register From 61f868a14e253c02c95bbbc925042004ac8f131f Mon Sep 17 00:00:00 2001 From: CanyonCasa Date: Mon, 17 Apr 2023 12:02:45 -0600 Subject: [PATCH 030/117] Update shared-module/onewireio/OneWire.c Co-authored-by: Scott Shawcroft --- shared-module/onewireio/OneWire.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-module/onewireio/OneWire.c b/shared-module/onewireio/OneWire.c index ff5caa2bac..f00cf572dd 100644 --- a/shared-module/onewireio/OneWire.c +++ b/shared-module/onewireio/OneWire.c @@ -59,7 +59,7 @@ bool common_hal_onewireio_onewire_reset(onewireio_onewire_obj_t *self) { common_hal_mcu_delay_us(70); bool value = common_hal_digitalio_digitalinout_get_value(&self->pin); common_hal_mcu_delay_us(410); - // test if bus returned high (idle) and not stck at low + // test if bus returned high (idle) and not stuck at low bool idle = common_hal_digitalio_digitalinout_get_value(&self->pin); common_hal_mcu_enable_interrupts(); return value || !idle; From 304134c6a48c10c57a7845f0c7fe3b7de71827af Mon Sep 17 00:00:00 2001 From: Debian Date: Mon, 17 Apr 2023 12:54:59 -0600 Subject: [PATCH 031/117] Fixed outdated reference link --- shared-bindings/onewireio/__init__.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/onewireio/__init__.c b/shared-bindings/onewireio/__init__.c index 81b2d605d7..282192179b 100644 --- a/shared-bindings/onewireio/__init__.c +++ b/shared-bindings/onewireio/__init__.c @@ -37,7 +37,7 @@ //| """Low-level bit primitives for Maxim (formerly Dallas Semi) one-wire protocol. //| -//| Protocol definition is here: https://www.maximintegrated.com/en/app-notes/index.mvp/id/126""" +//| Protocol definition is here: https://www.analog.com/en/technical-articles/1wire-communication-through-software.html""" STATIC const mp_rom_map_elem_t onewireio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_onewireio) }, From d1df7e9cffce17eaadd36b9c9f75ca0322f9a91c Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 17 Apr 2023 19:51:02 -0400 Subject: [PATCH 032/117] Add 'sudo apt-get update' before any 'sudo apt-get install' --- .github/actions/deps/external/action.yml | 4 +++- .github/actions/deps/ports/broadcom/action.yml | 1 + .github/workflows/build.yml | 1 + .github/workflows/pre-commit.yml | 4 +++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/actions/deps/external/action.yml b/.github/actions/deps/external/action.yml index 9e32e733a2..a26579b53d 100644 --- a/.github/actions/deps/external/action.yml +++ b/.github/actions/deps/external/action.yml @@ -30,7 +30,9 @@ runs: # espressif - name: Get espressif toolchain if: inputs.port == 'espressif' - run: sudo apt-get install -y ninja-build + run: | + sudo apt-get update + sudo apt-get install -y ninja-build shell: bash - name: Install IDF tools if: inputs.port == 'espressif' diff --git a/.github/actions/deps/ports/broadcom/action.yml b/.github/actions/deps/ports/broadcom/action.yml index bd76c78262..7ea747999b 100644 --- a/.github/actions/deps/ports/broadcom/action.yml +++ b/.github/actions/deps/ports/broadcom/action.yml @@ -7,6 +7,7 @@ runs: run: | wget --no-verbose https://adafruit-circuit-python.s3.amazonaws.com/gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf.tar.xz sudo tar -C /usr --strip-components=1 -xaf gcc-arm-10.3-2021.07-x86_64-aarch64-none-elf.tar.xz + sudo apt-get update sudo apt-get install -y mtools shell: bash - name: Install mkfs.fat diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e322004515..1b504d34c7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -174,6 +174,7 @@ jobs: uses: ./.github/actions/deps/submodules - name: Install dependencies run: | + sudo apt-get update sudo apt-get install -y latexmk librsvg2-bin texlive-fonts-recommended texlive-latex-recommended texlive-latex-extra pip install -r requirements-doc.txt - name: Build and Validate Stubs diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 2a3fcf9439..b3e51a2148 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -30,7 +30,9 @@ jobs: - name: Set up external uses: ./.github/actions/deps/external - name: Install dependencies - run: sudo apt-get install -y gettext uncrustify + run: | + sudo apt-get update + sudo apt-get install -y gettext uncrustify - name: Run pre-commit uses: pre-commit/action@v3.0.0 - name: Make patch From 7186235fa233ce3df8ce9e4f9d9fc0a7802c5d4a Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 18 Apr 2023 13:21:39 +0000 Subject: [PATCH 033/117] Translated using Weblate (French) Currently translated at 97.9% (979 of 1000 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/fr/ --- locale/fr.po | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/locale/fr.po b/locale/fr.po index a281712f96..22391687cb 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -8,14 +8,14 @@ msgstr "" "Project-Id-Version: 0.1\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2023-02-26 06:37+0000\n" -"Last-Translator: Neradoc \n" +"PO-Revision-Date: 2023-04-18 13:22+0000\n" +"Last-Translator: Jeff Epler \n" "Language: fr\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n > 1;\n" -"X-Generator: Weblate 4.16-dev\n" +"X-Generator: Weblate 4.17\n" #: main.c msgid "" @@ -40,6 +40,9 @@ msgid "" "Please file an issue with your program at https://github.com/adafruit/" "circuitpython/issues." msgstr "" +"\n" +"Veuillez signaler un problème avec votre programme sur https://github.com/" +"adafruit/circuitpython/issues." #: supervisor/shared/safe_mode.c msgid "" From 4e25a4f6b3efd64f02d81348b373d534dde9f34e Mon Sep 17 00:00:00 2001 From: silabs-BelaV <104006455+silabs-BelaV@users.noreply.github.com> Date: Tue, 18 Apr 2023 18:42:16 +0200 Subject: [PATCH 034/117] Silabs' new Pull Request for submoduling the ports/silabs/tools/slc_cli_linux/ (#7874) Doing a squash merge to avoid having the `slc_cli_linux` .zip files in the history. They were added in one commit and removed and replaced with a submodule in another. * Initial commit for xg24 * Fix SLC issue * Fix SLC extract fail * Change board's name * Correct spelling of code Build immediately after slc generate * Remove VID and PID * Change creator and creation id * Apply new creator_id and creation_id * Update makefile, error message, mcu_processor function * Update mpconfigboard.mk * Update Board extensions, PORT_DEPS * Update makefile * Add exclude_patterns * Show java, jinja2 version * Show path for debugging CI * Add requirements-dev for slc * Add PATH slc_cli * Update background function * Add jinja2 PATH * Show PATH * Update jinja2 path * Update jinja2 path * Update jinja2 path * Update jinja2 path * Change slc folder * Change markupsafe folder * Add symbolic link for slc * Update makefile * Update makefile * Update MX25R3235F.toml from submodule nvm.toml * alphabetize the list * Remove slc_cli_linux folder * Update slc_cli submodule --------- Co-authored-by: Chat Nguyen Co-authored-by: silabs-ChatNguyen Co-authored-by: silabs-ChatNguyen <126220343+silabs-ChatNguyen@users.noreply.github.com> --- .gitmodules | 7 + conf.py | 1 + data/nvm.toml | 2 +- docs/shared_bindings_matrix.py | 1 + ports/silabs/Makefile | 214 ++++++ ports/silabs/README.md | 132 ++++ ports/silabs/background.c | 50 ++ ports/silabs/background.h | 30 + .../boards/devkit_xg24_brd2601b/README.md | 28 + .../boards/devkit_xg24_brd2601b/board.c | 29 + .../custom_brd2601b_cp_support.slcc | 27 + .../devkit_xg24_brd2601b/mpconfigboard.h | 55 ++ .../devkit_xg24_brd2601b/mpconfigboard.mk | 17 + .../devkit_xg24_brd2601b/pin_functions.csv | 35 + .../boards/devkit_xg24_brd2601b/pins.csv | 21 + .../boards/devkit_xg24_brd2601b/sensor.c | 214 ++++++ .../explorerkit_xg24_brd2703a/README.md | 28 + .../boards/explorerkit_xg24_brd2703a/board.c | 33 + .../custom_brd2703a_cp_support.slcc | 20 + .../explorerkit_xg24_brd2703a/mpconfigboard.h | 52 ++ .../mpconfigboard.mk | 16 + .../pin_functions.csv | 35 + .../boards/explorerkit_xg24_brd2703a/pins.csv | 24 + ports/silabs/boards/mp_efr32xg24_gchelper.s | 28 + .../README.md | 28 + .../board.c | 29 + .../custom_brd2704a_cp_support.slcc | 18 + .../mpconfigboard.h | 49 ++ .../mpconfigboard.mk | 17 + .../pin_functions.csv | 35 + .../pins.csv | 24 + ports/silabs/circuitpython_efr32.slcp | 74 ++ ports/silabs/common-hal/_bleio/Adapter.c | 650 ++++++++++++++++++ ports/silabs/common-hal/_bleio/Adapter.h | 87 +++ ports/silabs/common-hal/_bleio/Attribute.c | 27 + ports/silabs/common-hal/_bleio/Attribute.h | 32 + .../silabs/common-hal/_bleio/Characteristic.c | 407 +++++++++++ .../silabs/common-hal/_bleio/Characteristic.h | 68 ++ .../common-hal/_bleio/CharacteristicBuffer.c | 164 +++++ .../common-hal/_bleio/CharacteristicBuffer.h | 55 ++ ports/silabs/common-hal/_bleio/Connection.c | 274 ++++++++ ports/silabs/common-hal/_bleio/Connection.h | 96 +++ ports/silabs/common-hal/_bleio/Descriptor.c | 114 +++ ports/silabs/common-hal/_bleio/Descriptor.h | 53 ++ ports/silabs/common-hal/_bleio/PacketBuffer.c | 399 +++++++++++ ports/silabs/common-hal/_bleio/PacketBuffer.h | 64 ++ ports/silabs/common-hal/_bleio/Service.c | 242 +++++++ ports/silabs/common-hal/_bleio/Service.h | 63 ++ ports/silabs/common-hal/_bleio/UUID.c | 83 +++ ports/silabs/common-hal/_bleio/UUID.h | 90 +++ ports/silabs/common-hal/_bleio/__init__.c | 402 +++++++++++ ports/silabs/common-hal/_bleio/__init__.h | 80 +++ ports/silabs/common-hal/analogio/AnalogIn.c | 216 ++++++ ports/silabs/common-hal/analogio/AnalogIn.h | 39 ++ ports/silabs/common-hal/analogio/AnalogOut.c | 167 +++++ ports/silabs/common-hal/analogio/AnalogOut.h | 42 ++ ports/silabs/common-hal/analogio/__init__.c | 1 + ports/silabs/common-hal/board/__init__.c | 0 ports/silabs/common-hal/busio/I2C.c | 212 ++++++ ports/silabs/common-hal/busio/I2C.h | 46 ++ ports/silabs/common-hal/busio/SPI.c | 252 +++++++ ports/silabs/common-hal/busio/SPI.h | 52 ++ ports/silabs/common-hal/busio/UART.c | 299 ++++++++ ports/silabs/common-hal/busio/UART.h | 52 ++ ports/silabs/common-hal/busio/__init__.c | 1 + .../common-hal/digitalio/DigitalInOut.c | 159 +++++ .../common-hal/digitalio/DigitalInOut.h | 39 ++ ports/silabs/common-hal/digitalio/__init__.c | 1 + ports/silabs/common-hal/microcontroller/Pin.c | 115 ++++ ports/silabs/common-hal/microcontroller/Pin.h | 36 + .../common-hal/microcontroller/Processor.c | 67 ++ .../common-hal/microcontroller/Processor.h | 39 ++ .../common-hal/microcontroller/__init__.c | 223 ++++++ ports/silabs/common-hal/nvm/ByteArray.c | 98 +++ ports/silabs/common-hal/nvm/ByteArray.h | 37 + ports/silabs/common-hal/nvm/__init__.c | 1 + ports/silabs/common-hal/os/__init__.c | 66 ++ ports/silabs/common-hal/pwmio/PWMOut.c | 181 +++++ ports/silabs/common-hal/pwmio/PWMOut.h | 47 ++ ports/silabs/common-hal/pwmio/__init__.c | 1 + ports/silabs/common-hal/rtc/RTC.c | 78 +++ ports/silabs/common-hal/rtc/RTC.h | 33 + ports/silabs/common-hal/rtc/__init__.c | 0 ports/silabs/common-hal/rtc/__init__.h | 0 ports/silabs/common-hal/supervisor/Runtime.c | 37 + ports/silabs/common-hal/supervisor/Runtime.h | 37 + ports/silabs/common-hal/supervisor/__init__.c | 38 + .../silabs/common-hal/watchdog/WatchDogMode.c | 25 + .../common-hal/watchdog/WatchDogTimer.c | 133 ++++ .../common-hal/watchdog/WatchDogTimer.h | 43 ++ ports/silabs/common-hal/watchdog/__init__.c | 0 ports/silabs/cp_efr32_extension/cp_efr32.slce | 10 + ports/silabs/gecko_sdk | 1 + ports/silabs/license.md | 21 + ports/silabs/mpconfigport.h | 73 ++ ports/silabs/mpconfigport.mk | 37 + ports/silabs/mphalport.c | 46 ++ ports/silabs/mphalport.h | 51 ++ ports/silabs/peripherals/periph.h | 81 +++ ports/silabs/peripherals/pins.h | 171 +++++ ports/silabs/peripherals/rtc.h | 33 + ports/silabs/peripherals/timers.h | 29 + ports/silabs/qstrdefsport.h | 1 + ports/silabs/res/Thony.png | Bin 0 -> 49362 bytes ports/silabs/silabs.pintool | 28 + ports/silabs/supervisor/internal_flash.c | 138 ++++ ports/silabs/supervisor/internal_flash.h | 38 + .../supervisor/internal_flash_root_pointers.h | 32 + ports/silabs/supervisor/port.c | 336 +++++++++ ports/silabs/supervisor/serial.c | 156 +++++ ports/silabs/tools/make_pins.py | 216 ++++++ ports/silabs/tools/slc_cli_linux | 1 + requirements-dev.txt | 4 + tools/ci_fetch_deps.py | 1 + 114 files changed, 9239 insertions(+), 1 deletion(-) create mode 100644 ports/silabs/Makefile create mode 100644 ports/silabs/README.md create mode 100644 ports/silabs/background.c create mode 100644 ports/silabs/background.h create mode 100644 ports/silabs/boards/devkit_xg24_brd2601b/README.md create mode 100644 ports/silabs/boards/devkit_xg24_brd2601b/board.c create mode 100644 ports/silabs/boards/devkit_xg24_brd2601b/custom_brd2601b_cp_support.slcc create mode 100644 ports/silabs/boards/devkit_xg24_brd2601b/mpconfigboard.h create mode 100644 ports/silabs/boards/devkit_xg24_brd2601b/mpconfigboard.mk create mode 100644 ports/silabs/boards/devkit_xg24_brd2601b/pin_functions.csv create mode 100644 ports/silabs/boards/devkit_xg24_brd2601b/pins.csv create mode 100644 ports/silabs/boards/devkit_xg24_brd2601b/sensor.c create mode 100644 ports/silabs/boards/explorerkit_xg24_brd2703a/README.md create mode 100644 ports/silabs/boards/explorerkit_xg24_brd2703a/board.c create mode 100644 ports/silabs/boards/explorerkit_xg24_brd2703a/custom_brd2703a_cp_support.slcc create mode 100644 ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.h create mode 100644 ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.mk create mode 100644 ports/silabs/boards/explorerkit_xg24_brd2703a/pin_functions.csv create mode 100644 ports/silabs/boards/explorerkit_xg24_brd2703a/pins.csv create mode 100644 ports/silabs/boards/mp_efr32xg24_gchelper.s create mode 100644 ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/README.md create mode 100644 ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/board.c create mode 100644 ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/custom_brd2704a_cp_support.slcc create mode 100644 ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/mpconfigboard.h create mode 100644 ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/mpconfigboard.mk create mode 100644 ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/pin_functions.csv create mode 100644 ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/pins.csv create mode 100644 ports/silabs/circuitpython_efr32.slcp create mode 100644 ports/silabs/common-hal/_bleio/Adapter.c create mode 100644 ports/silabs/common-hal/_bleio/Adapter.h create mode 100644 ports/silabs/common-hal/_bleio/Attribute.c create mode 100644 ports/silabs/common-hal/_bleio/Attribute.h create mode 100644 ports/silabs/common-hal/_bleio/Characteristic.c create mode 100644 ports/silabs/common-hal/_bleio/Characteristic.h create mode 100644 ports/silabs/common-hal/_bleio/CharacteristicBuffer.c create mode 100644 ports/silabs/common-hal/_bleio/CharacteristicBuffer.h create mode 100644 ports/silabs/common-hal/_bleio/Connection.c create mode 100644 ports/silabs/common-hal/_bleio/Connection.h create mode 100644 ports/silabs/common-hal/_bleio/Descriptor.c create mode 100644 ports/silabs/common-hal/_bleio/Descriptor.h create mode 100644 ports/silabs/common-hal/_bleio/PacketBuffer.c create mode 100644 ports/silabs/common-hal/_bleio/PacketBuffer.h create mode 100644 ports/silabs/common-hal/_bleio/Service.c create mode 100644 ports/silabs/common-hal/_bleio/Service.h create mode 100644 ports/silabs/common-hal/_bleio/UUID.c create mode 100644 ports/silabs/common-hal/_bleio/UUID.h create mode 100644 ports/silabs/common-hal/_bleio/__init__.c create mode 100644 ports/silabs/common-hal/_bleio/__init__.h create mode 100644 ports/silabs/common-hal/analogio/AnalogIn.c create mode 100644 ports/silabs/common-hal/analogio/AnalogIn.h create mode 100644 ports/silabs/common-hal/analogio/AnalogOut.c create mode 100644 ports/silabs/common-hal/analogio/AnalogOut.h create mode 100644 ports/silabs/common-hal/analogio/__init__.c create mode 100644 ports/silabs/common-hal/board/__init__.c create mode 100644 ports/silabs/common-hal/busio/I2C.c create mode 100644 ports/silabs/common-hal/busio/I2C.h create mode 100644 ports/silabs/common-hal/busio/SPI.c create mode 100644 ports/silabs/common-hal/busio/SPI.h create mode 100644 ports/silabs/common-hal/busio/UART.c create mode 100644 ports/silabs/common-hal/busio/UART.h create mode 100644 ports/silabs/common-hal/busio/__init__.c create mode 100644 ports/silabs/common-hal/digitalio/DigitalInOut.c create mode 100644 ports/silabs/common-hal/digitalio/DigitalInOut.h create mode 100644 ports/silabs/common-hal/digitalio/__init__.c create mode 100644 ports/silabs/common-hal/microcontroller/Pin.c create mode 100644 ports/silabs/common-hal/microcontroller/Pin.h create mode 100644 ports/silabs/common-hal/microcontroller/Processor.c create mode 100644 ports/silabs/common-hal/microcontroller/Processor.h create mode 100644 ports/silabs/common-hal/microcontroller/__init__.c create mode 100644 ports/silabs/common-hal/nvm/ByteArray.c create mode 100644 ports/silabs/common-hal/nvm/ByteArray.h create mode 100644 ports/silabs/common-hal/nvm/__init__.c create mode 100644 ports/silabs/common-hal/os/__init__.c create mode 100644 ports/silabs/common-hal/pwmio/PWMOut.c create mode 100644 ports/silabs/common-hal/pwmio/PWMOut.h create mode 100644 ports/silabs/common-hal/pwmio/__init__.c create mode 100644 ports/silabs/common-hal/rtc/RTC.c create mode 100644 ports/silabs/common-hal/rtc/RTC.h create mode 100644 ports/silabs/common-hal/rtc/__init__.c create mode 100644 ports/silabs/common-hal/rtc/__init__.h create mode 100644 ports/silabs/common-hal/supervisor/Runtime.c create mode 100644 ports/silabs/common-hal/supervisor/Runtime.h create mode 100644 ports/silabs/common-hal/supervisor/__init__.c create mode 100644 ports/silabs/common-hal/watchdog/WatchDogMode.c create mode 100644 ports/silabs/common-hal/watchdog/WatchDogTimer.c create mode 100644 ports/silabs/common-hal/watchdog/WatchDogTimer.h create mode 100644 ports/silabs/common-hal/watchdog/__init__.c create mode 100644 ports/silabs/cp_efr32_extension/cp_efr32.slce create mode 160000 ports/silabs/gecko_sdk create mode 100644 ports/silabs/license.md create mode 100644 ports/silabs/mpconfigport.h create mode 100644 ports/silabs/mpconfigport.mk create mode 100644 ports/silabs/mphalport.c create mode 100644 ports/silabs/mphalport.h create mode 100644 ports/silabs/peripherals/periph.h create mode 100644 ports/silabs/peripherals/pins.h create mode 100644 ports/silabs/peripherals/rtc.h create mode 100644 ports/silabs/peripherals/timers.h create mode 100644 ports/silabs/qstrdefsport.h create mode 100755 ports/silabs/res/Thony.png create mode 100644 ports/silabs/silabs.pintool create mode 100644 ports/silabs/supervisor/internal_flash.c create mode 100644 ports/silabs/supervisor/internal_flash.h create mode 100644 ports/silabs/supervisor/internal_flash_root_pointers.h create mode 100644 ports/silabs/supervisor/port.c create mode 100644 ports/silabs/supervisor/serial.c create mode 100644 ports/silabs/tools/make_pins.py create mode 160000 ports/silabs/tools/slc_cli_linux diff --git a/.gitmodules b/.gitmodules index 9c8d3b4b68..a33354bbff 100644 --- a/.gitmodules +++ b/.gitmodules @@ -324,3 +324,10 @@ path = ports/broadcom/peripherals url = https://github.com/adafruit/broadcom-peripherals.git branch = main-build +[submodule "ports/silabs/gecko_sdk"] + path = ports/silabs/gecko_sdk + url = https://github.com/SiliconLabs/gecko_sdk.git + branch = v4.2.1 +[submodule "ports/silabs/tools/slc_cli_linux"] + path = ports/silabs/tools/slc_cli_linux + url = https://github.com/SiliconLabs/circuitpython_slc_cli_linux diff --git a/conf.py b/conf.py index ea5072ae4c..e14c6ace83 100644 --- a/conf.py +++ b/conf.py @@ -216,6 +216,7 @@ exclude_patterns = ["**/build*", "ports/nrf/usb", "ports/raspberrypi/sdk", "ports/raspberrypi/lib", + "ports/silabs", "ports/stm/st_driver", "ports/stm/packages", "ports/stm/peripherals", diff --git a/data/nvm.toml b/data/nvm.toml index 73fafcbe4c..427cc92397 160000 --- a/data/nvm.toml +++ b/data/nvm.toml @@ -1 +1 @@ -Subproject commit 73fafcbe4c66b23df63be31e9227353b695abb08 +Subproject commit 427cc923976229bcb981ca6f218ebe8efd636df6 diff --git a/docs/shared_bindings_matrix.py b/docs/shared_bindings_matrix.py index 9705e33585..f7efb47385 100644 --- a/docs/shared_bindings_matrix.py +++ b/docs/shared_bindings_matrix.py @@ -40,6 +40,7 @@ SUPPORTED_PORTS = [ "mimxrt10xx", "nrf", "raspberrypi", + "silabs", "stm", ] diff --git a/ports/silabs/Makefile b/ports/silabs/Makefile new file mode 100644 index 0000000000..06ddf3a57d --- /dev/null +++ b/ports/silabs/Makefile @@ -0,0 +1,214 @@ +# This file is part of Adafruit for EFR32 project +# +# The MIT License (MIT) +# +# Copyright 2023 Silicon Laboratories Inc. www.silabs.com +# +# 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. +# + +.SUFFIXES: # ignore builtin rules +.PHONY: all clean slc-clean slc-generate dependents +# Values set by the initial generation +PROJECTNAME = circuitpython_efr32 +# If the build directory is not given, make it reflect the board name. +SILABS_BUILD = build-$(BOARD) +# Build dir for CircuitPython +BUILD ?= $(SILABS_BUILD) +# Override Build Directories +OUTPUT_DIR = $(SILABS_BUILD) +# Python script to generate pins and pins functionalities code +PY_GEN_PINS_SRC ?= tools/make_pins.py +# SLC tool path +SLC_PATH = $(realpath $(CURDIR))/tools/slc_cli_linux + +BUILD_VERBOSE ?= 1 + +CFLAGS = $(INCLUDES) $(C_DEFS) $(C_FLAGS) \ + -Wno-expansion-to-defined \ + -Wno-unused-parameter \ + -Wno-missing-field-initializers \ + -Wno-type-limits + +ASMFLAGS = $(INCLUDES) $(ASM_DEFS) $(ASM_FLAGS) $(DEPFLAGS) + +include ../../py/circuitpy_mkenv.mk + +CROSS_COMPILE = arm-none-eabi- + +MCU_SERIES_LOWER = $(shell echo $(MCU_SERIES) | tr '[:upper:]' '[:lower:]') +MCU_VARIANT_LOWER = $(shell echo $(MCU_VARIANT) | tr '[:upper:]' '[:lower:]') + +# Header files folders include +INC += -I. +INC += -I../.. +INC += -I$(BUILD) +INC += -I$(BUILD)/genhdr +INC += -I$(SILABS_BUILD)/autogen +INC += -I$(SILABS_BUILD)/config +INC += -I./boards +INC += -I./peripherals +INC += -I../../lib/mp-readline + +#Debugging/Optimization +ifeq ($(DEBUG), 1) + CFLAGS += -g3 + # You may want to enable these flags to make setting breakpoints easier. + CFLAGS += -fno-inline -fno-ipa-sra -Og +else + CFLAGS += -DNDEBUG + OPTIMIZATION_FLAGS ?= -Os -fno-inline-functions + CFLAGS += -g +endif + +# to override compiler optimization level, set in boards/$(BOARD)/mpconfigboard.mk +CFLAGS += $(OPTIMIZATION_FLAGS) +CFLAGS += $(INC) $(BASE_CFLAGS) $(C_DEFS) $(CFLAGS_MOD) $(COPT) +CFLAGS += -DEFR32_SERIES_LOWER='"$(MCU_VARIANT)"' +CFLAGS += -Wno-undef -Wno-shadow -Wno-cast-align -Wno-nested-externs -Wno-strict-prototypes + +SRC_C += \ + background.c \ + mphalport.c \ + $(SILABS_BUILD)/pins.c\ + +ifeq ('$(BOARD)','brd2601b') +SRC_C += boards/$(BOARD)/sensor.c +endif + +SRC_S = boards/mp_efr32xg24_gchelper.s + +SRC_COMMON_HAL_EXPANDED = $(addprefix shared-bindings/, $(SRC_COMMON_HAL)) \ + $(addprefix shared-bindings/, $(SRC_BINDINGS_ENUMS)) \ + $(addprefix common-hal/, $(SRC_COMMON_HAL)) + +SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \ + $(addprefix shared-module/, $(SRC_SHARED_MODULE)) \ + $(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL)) + +# There may be duplicates between SRC_COMMON_HAL_EXPANDED and SRC_SHARED_MODULE_EXPANDED, +# because a few modules have files both in common-hal/ and shared-module/. +# Doing a $(sort ...) removes duplicates as part of sorting. +SRC_COMMON_HAL_SHARED_MODULE_EXPANDED = $(sort $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED)) + +ifneq ($(FROZEN_MPY_DIR),) +FROZEN_MPY_PY_FILES := $(shell find -L $(FROZEN_MPY_DIR) -type f -name '*.py') +FROZEN_MPY_MPY_FILES := $(addprefix $(BUILD)/,$(FROZEN_MPY_PY_FILES:.py=.mpy)) +endif + +OBJ += $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) +OBJ += $(addprefix $(BUILD)/, $(SRC_COMMON_HAL_SHARED_MODULE_EXPANDED:.c=.o)) +ifeq ($(INTERNAL_LIBM),1) +OBJ += $(addprefix $(BUILD)/, $(SRC_LIBM:.c=.o)) +endif +OBJ += $(addprefix $(BUILD)/, $(SRC_CIRCUITPY_COMMON:.c=.o)) +OBJ += $(addprefix $(BUILD)/, $(SRC_S:.s=.o)) +OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o)) + +$(BUILD)/$(FATFS_DIR)/ff.o: COPT += -Os +$(filter $(PY_BUILD)/../extmod/vfs_fat_%.o, $(PY_O)): COPT += -Os + +# List of sources for qstr extraction +SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_MOD) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED) +# Sources that only hold QSTRs after pre-processing. +SRC_QSTR_PREPROCESSOR += + +MCU_SECTIONS = $^ $@ + +# Include sub-makefiles +-include $(SILABS_BUILD)/$(PROJECTNAME).project.mak + +# Default goal +all: $(OUTPUT_DIR)/firmware.bin + +$(OUTPUT_DIR)/firmware.bin: $(SILABS_BUILD)/$(PROJECTNAME).Makefile $(OUTPUT_DIR)/firmware.hex + +@$(MAKE) --no-print-directory $(OUTPUT_DIR)/firmware.out + @echo 'Done.' + +$(SILABS_BUILD)/$(PROJECTNAME).Makefile: + +@$(MAKE) --no-print-directory slc-generate + +$(OUTPUT_DIR)/firmware.out: $(SILABS_BUILD)/pin_functions.h $(SILABS_BUILD)/pins.c $(OBJ) $(OBJS) $(LIB_FILES) + @echo 'Linking $(OUTPUT_DIR)/firmware.out' + @echo "$(OBJS) $(OBJ)" > $(OUTPUT_DIR)/linker_objs + $(CC) $(LD_FLAGS) @$(OUTPUT_DIR)/linker_objs $(LIBS) -o $(OUTPUT_DIR)/firmware.out + $(OBJCOPY) $(OUTPUT_DIR)/firmware.out -O binary $(OUTPUT_DIR)/firmware.bin + +$(OUTPUT_DIR)/firmware.hex: + +$(SILABS_BUILD)/pin_functions.h: + $(STEPECHO) "GEN $@" + $(Q)$(PYTHON) $(PY_GEN_PINS_SRC) -e $@ boards/$(BOARD)/pins.csv boards/$(BOARD)/pin_functions.csv + @-$(RM) pins.c + +$(SILABS_BUILD)/pins.c: + $(STEPECHO) "GEN $@" + $(Q)$(PYTHON) $(PY_GEN_PINS_SRC) -s $@ boards/$(BOARD)/pins.csv boards/$(BOARD)/pin_functions.csv + @-$(RM) pin_functions.h + +slc-generate: +ifeq (,$(wildcard $(SLC_PATH)/bin/slc-cli/developer/adapter_packs/python/lib/python3.6/jinja2)) + -@ln -s $(SLC_PATH)/bin/slc-cli/developer/adapter_packs/python/lib/python3.6/site-packages/jinja2 \ + $(SLC_PATH)/bin/slc-cli/developer/adapter_packs/python/lib/python3.6/jinja2 + -@ln -s $(SLC_PATH)/bin/slc-cli/developer/adapter_packs/python/lib/python3.6/site-packages/markupsafe \ + $(SLC_PATH)/bin/slc-cli/developer/adapter_packs/python/lib/python3.6/markupsafe +endif + @echo 'SLC generates project' + @$(SLC_PATH)/slc configuration --sdk gecko_sdk + @$(SLC_PATH)/slc signature trust -extpath cp_efr32_extension + @$(SLC_PATH)/slc signature trust --sdk gecko_sdk + @$(SLC_PATH)/slc generate -name=$(PROJECTNAME) $(PROJECTNAME).slcp --sdk gecko_sdk --with $(BOARD_BRD) -tlcn gcc -d=$(SILABS_BUILD) + @sed -i 's/ autogen\// $(SILABS_BUILD)\/autogen\//g' $(SILABS_BUILD)/circuitpython_efr32.project.mak + @sed -i 's/-T"autogen\//-T"$(SILABS_BUILD)\/autogen\//g' $(SILABS_BUILD)/circuitpython_efr32.project.mak + +#Override ECHO +$(OBJS): ECHO = +$(OBJS): + +$(OUTPUT_DIR)/%.o: %.c + @echo 'Building $<' + @$(MKDIR_P) $(@D) + $(ECHO)$(CC) $(CFLAGS) -c -o $@ $< + +$(OUTPUT_DIR)/%.o: %.cpp + @echo 'Building $<' + @$(MKDIR_P) $(@D) + $(ECHO)$(CXX) $(CXXFLAGS) -c -o $@ $< + +$(OUTPUT_DIR)/%.o: %.cc + @echo 'Building $<' + @$(MKDIR_P) $(@D) + $(ECHO)$(CXX) $(CXXFLAGS) -c -o $@ $< + +$(OUTPUT_DIR)/%.o: %.s + @echo 'Building $<' + @$(MKDIR_P) $(@D) + $(ECHO)$(CC) $(ASMFLAGS) -c -o $@ $< + +$(OUTPUT_DIR)/%.o: %.S + @echo 'Building $<' + @$(MKDIR_P) $(@D) + $(ECHO)$(CC) $(ASMFLAGS) -c -o $@ $< + +include $(TOP)/py/mkrules.mk + +# Print out the value of a make variable. +# https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile +print-%: + @echo $* = $($*) diff --git a/ports/silabs/README.md b/ports/silabs/README.md new file mode 100644 index 0000000000..626b8e7788 --- /dev/null +++ b/ports/silabs/README.md @@ -0,0 +1,132 @@ +# Circuitpython on EFR32 # +![GitHub](https://img.shields.io/badge/Technology-Bluetooth_BLE-green) +![GitHub](https://img.shields.io/badge/CircuitPython-8.1.0--beta.0-green) +![GitHub](https://img.shields.io/badge/GSDK-v4.2.1-green) +![GitHub](https://img.shields.io/badge/SLC-5.6.3.0-green) +![GitHub](https://img.shields.io/badge/License-MIT-green) +![GitHub](https://img.shields.io/badge/GCC_build-passing-green) + +This port brings the Silicon Labs EFR32 series of MCUs to Circuitpython. + +Refer to **mpconfigport.mk** for a full list of enabled modules sorted by family. + +## How this port is organized: ## + +- **boards/** contains the configuration files for each development board and breakout available on the port, as well as system files and both shared and SoC-specific linker files. Board configuration includes a pin mapping of the board, oscillator information, board-specific build flags, and setup for some other peripheral where applicable. +- **common-hal/** contains the port-specific module implementations, used by shared-module and shared-bindings. +- **peripherals/** contains peripheral setup files and peripheral mapping information, sorted by family and sub-variant. Most files in this directory can be generated with the python scripts in **tools/**. +- **supervisor/** contains port-specific implementations of internal flash and serial, as well as the **port.c** file, which initializes the port at startup. +- **tools/** contains Silicon Labs configurator (SLC) tool, python scripts for generating peripheral and pin mapping files in **peripherals/** and **board/**. + +At the root level, refer to **mpconfigboard.h** and **mpconfigport.mk** for port specific settings and a list of enabled modules. + +## Prerequisites ## +Please ensure you set up your build environment appropriately, as per the guide. You will need: + +- Linux: https://learn.adafruit.com/building-circuitpython/linux +- Windows Subsystem for Linux (WSL): https://learn.adafruit.com/building-circuitpython/windows-subsystem-for-linux +- MacOS: Not supported yet + +Install necessary packages + + $ sudo apt install default-jre gcc-arm-none-eabi wget python3 python3-pip git git-lfs gettext uncrustify + $ sudo python -m pip install --upgrade pip + +## Board supported ## + +| Board | Code | Build CMD | +| --------------------------- | ------------ | ------------------------------------------ | +| xG24 Dev Kit | brd2601b | devkit_xg24_brd2601b | +| xG24 Explorer Kit | brd2703a | explorerkit_xg24_brd2703a | +| Sparkfun Thing Plus MGM240P | brd2704a | sparkfun_thingplus_matter_mgm240p_brd2704a | + +## Build instructions ## + +Ensure your clone of Circuitpython is ready to build by following the [guide on the Adafruit Website](https://learn.adafruit.com/building-circuitpython/build-circuitpython). This includes installing the toolchain, synchronizing submodules, and running `mpy-cross`. + +Clone the source code of CircuitPython from Github: + + $ git clone https://github.com/SiliconLabs/circuitpython.git + $ cd circuitpython + $ make fetch-submodules + +Checkout the branch or tag you want to build. For example: + + $ git checkout main + +Following the guideline below to install required packages for SLC tool: + https://www.silabs.com/documents/public/user-guides/ug520-software-project-generation-configuration-with-slc-cli.pdf + +Once the one-time build tasks are complete, you can build at any time by navigating to the port directory: + + $ make BOARD=explorerkit_xg24_brd2703a + +You may also build with certain flags available in the makefile, depending on your board and development goals: + + $ make BOARD=explorerkit_xg24_brd2703a DEBUG=1 + +Clean project by using: + + $ make BOARD=explorerkit_xg24_brd2703a clean + +## Bring-up on the board ## + +### Getting a REPL prompt ### + +Connect the devkit to the PC via the USB cable. The board uses serial for REPL access and debugging because the EFR32 chips has no USB support. + +#### Windows #### + +On Windows, we need to install a serial console e.g., PuTTY, MobaXterm. The JLink CDC UART Port can be found in the Device Manager. + +#### Linux #### + +Open a terminal and issue the following command:  + + $ ls /dev/ttyACM* + +Then note down the correct name and substitute com-port-name in the following command with it:  + + $ screen /dev/'com-port-name' + +### Using the REPL prompt ### + +After flashing the firmware to the board, at your first connecting to the board, you might see a blank screen. Press enter and you should be presented with a Circuitpython prompt, >>>. If not, try to reset the board (see instructions below). + +You can now type in simple commands such as:  + +```sh +>>> print("Hello world!")  + +Hello world +``` + +If something goes wrong with the board, you can reset it. Pressing CTRL+D when the prompt is open performs a soft reset. + +### Recommended editors ### + +**Thonny** is a simple code editor that works with the Adafruit CircuitPython boards.  + +Config serial: Tools > Options > Interpreter > Select MicroPython > Select Port Jlink CDC UART Port + +### Running CircuitPython scripts ### + +At the boot stage, two scripts will be run (if not booting in safe mode). First, the file  boot.py  will be executed. The file **boot.py** can be used to perform the initial setup. Then, after boot.py has been completed, the file **code.py** will be executed.   + +After code.py has finished executing, a REPL prompt will be presented on the serial port. Other files can also be executed by using the **Thonny** editors or using **Ampy** tool. + +![Thony](./res/Thony.png) + +With the boards which support USB mass storage, we can drag the files to the board file system. However, because the EFR32 boards don’t support USB mass storage, we need to use a tool like **Ampy** to copy the file to the board. You can use the latest version of **Ampy** and its  command to copy the module directories to the board. + +Refer to the guideline below for installing the **Ampy** tool:  + +https://learn.adafruit.com/micropython-basics-load-files-and-run-code/install-ampy   + +## Modules supported ## + +| Board | Modules Available| +| --------------------------- | ---------------- | +| xG24 Dev Kit | _asyncio, _bleio, _pixelmap, adafruit_ble, adafruit_bus_device, adafruit_pixelbuf, adafruit_register, aesio,analogio, array, atexit, binascii, bitmaptools, board, builtins, busio, collections, digitalio, displayio,errno, fontio, framebufferio, gc, getpass, gifio, json, math, microcontroller, micropython, msgpack, nvm, onewireio, os, pwmio, rainbowio, random, re, rtc, select, sharpdisplay, storage, struct, supervisor, sys, terminalio, time, traceback, ulab, uselect, vectorio, watchdog, zlib | +| xG24 Explorer Kit | _asyncio, _bleio, _pixelmap, adafruit_ble, adafruit_bus_device, adafruit_pixelbuf, adafruit_register, aesio,analogio, array, atexit, binascii, bitmaptools, board, builtins, busio, collections, digitalio, displayio,errno, fontio, framebufferio, gc, getpass, gifio, json, math, microcontroller, micropython, msgpack, nvm, onewireio, os, pwmio, rainbowio, random, re, rtc, sdcardio, select, sharpdisplay, storage, struct, supervisor, sys, terminalio, time, traceback, ulab, uselect, vectorio, watchdog, zlib | +| Sparkfun Thing Plus MGM240P | _asyncio, _bleio, _pixelmap, adafruit_ble, adafruit_bus_device, adafruit_pixelbuf, adafruit_register, aesio,analogio, array, atexit, binascii, bitmaptools, board, builtins, busio, collections, digitalio, displayio,errno, fontio, framebufferio, gc, getpass, gifio, json, math, microcontroller, micropython, msgpack, nvm, onewireio, os, pwmio, rainbowio, random, re, rtc, sdcardio, select, sharpdisplay, storage, struct, supervisor, sys, terminalio, time, traceback, ulab, uselect, vectorio, watchdog, zlib | diff --git a/ports/silabs/background.c b/ports/silabs/background.c new file mode 100644 index 0000000000..176918adda --- /dev/null +++ b/ports/silabs/background.c @@ -0,0 +1,50 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "py/runtime.h" +#include "supervisor/filesystem.h" +#include "supervisor/usb.h" +#include "supervisor/shared/stack.h" +#include "FreeRTOS.h" +#include "task.h" + +#if CIRCUITPY_DISPLAYIO +#include "shared-module/displayio/__init__.h" +#endif + +void port_background_tick(void) { + // Zero delay in case FreeRTOS wants to switch to something else + vTaskDelay(0); +} + +void port_background_task(void) { +} + +void port_start_background_tick(void) { +} + +void port_finish_background_tick(void) { +} diff --git a/ports/silabs/background.h b/ports/silabs/background.h new file mode 100644 index 0000000000..c68865fa5b --- /dev/null +++ b/ports/silabs/background.h @@ -0,0 +1,30 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR32_BACKGROUND_H +#define MICROPY_INCLUDED_EFR32_BACKGROUND_H + +#endif // MICROPY_INCLUDED_EFR32_BACKGROUND_H diff --git a/ports/silabs/boards/devkit_xg24_brd2601b/README.md b/ports/silabs/boards/devkit_xg24_brd2601b/README.md new file mode 100644 index 0000000000..438ec42bfc --- /dev/null +++ b/ports/silabs/boards/devkit_xg24_brd2601b/README.md @@ -0,0 +1,28 @@ +## Gen Pin instructions ## + +# Input File +pins.csv : contain pin name, port number ,pin number +pin_functions.csv : contain list of pin support for peripheral +make_pins.py : python script to gen pin + + +# Run make_pins.py +Copy above input file to folder boards/brd2601b/ +Run CMD: + $ cd boards/brd2601b/ + $ python make_pins.py -s pins.c -e pin_functions.h pins.csv pin_functions.csv + + -s: name/directory of output source file + -e: name/directory of output header file + +# Output +pins.c : register pin to board_module_globals_table + generate array contains supported function of pin +pin_functions.h : define index of functions + Example: pin_pa0_functions[FN_EUSART0_RX] == 1 // Can assign pin pa0 for EUSART0_RX + pin_pa0_functions[FN_EUSART0_RX] == 255 // Can't assign pin pa0 for EUSART0_RX + + +# Read pin define on REPL +import board +dir(board) diff --git a/ports/silabs/boards/devkit_xg24_brd2601b/board.c b/ports/silabs/boards/devkit_xg24_brd2601b/board.c new file mode 100644 index 0000000000..100ef47b15 --- /dev/null +++ b/ports/silabs/boards/devkit_xg24_brd2601b/board.c @@ -0,0 +1,29 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/silabs/boards/devkit_xg24_brd2601b/custom_brd2601b_cp_support.slcc b/ports/silabs/boards/devkit_xg24_brd2601b/custom_brd2601b_cp_support.slcc new file mode 100644 index 0000000000..b1731a306f --- /dev/null +++ b/ports/silabs/boards/devkit_xg24_brd2601b/custom_brd2601b_cp_support.slcc @@ -0,0 +1,27 @@ +id: custom_brd2601b_cp_support +label: CircuitPython BRD2601B support +description: > + CircuitPython Board support for BRD2601B. +package: custom +category: Custom +quality: production +root_path: ../boards/devkit_xg24_brd2601b +include: + - path: '' + file_list: + - path: mpconfigboard.h +source: + - path: board.c +provides: + - name: custom_brd2601b_cp_support +requires: + - name: efr32mg24b310f1536im48 + - name: sensor_pressure + - name: sensor_hall + - name: sensor_imu + - name: sensor_rht + - name: sensor_lux +recommends: + - id: sensor_rht + - id: sensor_lux + - id: bt_rail_compatibility_fix diff --git a/ports/silabs/boards/devkit_xg24_brd2601b/mpconfigboard.h b/ports/silabs/boards/devkit_xg24_brd2601b/mpconfigboard.h new file mode 100644 index 0000000000..5456e1ecd5 --- /dev/null +++ b/ports/silabs/boards/devkit_xg24_brd2601b/mpconfigboard.h @@ -0,0 +1,55 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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 "build-devkit_xg24_brd2601b/pin_functions.h" + +// Micropython setup +#define MICROPY_HW_BOARD_NAME "SiLabs xG24 Dev Kit" +#define MICROPY_HW_MCU_NAME EFR32_SERIES_LOWER + +#define HSE_VALUE ((uint32_t)8000000) +#define BOARD_HSE_SOURCE (RCC_HSE_BYPASS) +#define BOARD_HAS_LOW_SPEED_CRYSTAL (0) + +// On-board flash +#define SPI_FLASH_MOSI_PIN (&pin_PC3) +#define SPI_FLASH_MISO_PIN (&pin_PC2) +#define SPI_FLASH_SCK_PIN (&pin_PC1) +#define SPI_FLASH_CS_PIN (&pin_PC0) + +#define DEFAULT_I2C_BUS_SDA (&pin_PC5) +#define DEFAULT_I2C_BUS_SCL (&pin_PC4) +#define DEFAULT_I2C_PERIPHERAL I2C1 + +#define DEFAULT_SPI_BUS_SCK (&pin_PC1) +#define DEFAULT_SPI_BUS_MOSI (&pin_PC3) +#define DEFAULT_SPI_BUS_MISO (&pin_PC2) +#define DEFAULT_SPI_BUS_SS (&pin_PA7) + +#define NVM_BYTEARRAY_BUFFER_SIZE 512 +#define CIRCUITPY_INTERNAL_NVM_SIZE (512) +#undef MICROPY_USE_INTERNAL_PRINTF +#define MICROPY_USE_INTERNAL_PRINTF (0) diff --git a/ports/silabs/boards/devkit_xg24_brd2601b/mpconfigboard.mk b/ports/silabs/boards/devkit_xg24_brd2601b/mpconfigboard.mk new file mode 100644 index 0000000000..9c40c6fe7c --- /dev/null +++ b/ports/silabs/boards/devkit_xg24_brd2601b/mpconfigboard.mk @@ -0,0 +1,17 @@ + +BOARD_BRD = brd2601b +INTERNAL_FLASH_FILESYSTEM = 0 +QSPI_FLASH_FILESYSTEM = 0 +SPI_FLASH_FILESYSTEM = 1 +EXTERNAL_FLASH_DEVICES = MX25R3235F + +MCU_SERIES = MG24 +MCU_VARIANT = EFR32MG24B310F1536IM48 + +CIRCUITPY_USB = 0 + +CIRCUITPY_CREATOR_ID = 0x19960000 +CIRCUITPY_CREATION_ID = 0x00242601 + +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_BLE +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Register diff --git a/ports/silabs/boards/devkit_xg24_brd2601b/pin_functions.csv b/ports/silabs/boards/devkit_xg24_brd2601b/pin_functions.csv new file mode 100644 index 0000000000..aad9f34198 --- /dev/null +++ b/ports/silabs/boards/devkit_xg24_brd2601b/pin_functions.csv @@ -0,0 +1,35 @@ +EUSART0_CS,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,,,,,,,,,,,,,, +EUSART0_RX,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,,,,,,,,,,,,,, +EUSART0_SCLK,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,,,,,,,,,,,,,, +EUSART0_TX,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,,,,,,,,,,,,,, +EUSART1_CS,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PC0,PC1,PC2,PC3,PC4,PC5,PC9,PD2,PD3,PD4,PD5,,, +EUSART1_RX,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PC0,PC1,PC2,PC3,PC4,PC5,PC9,PD2,PD3,PD4,PD5,,, +EUSART1_SCLK,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PC0,PC1,PC2,PC3,PC4,PC5,PC9,PD2,PD3,PD4,PD5,,, +EUSART1_TX,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PC0,PC1,PC2,PC3,PC4,PC5,PC9,PD2,PD3,PD4,PD5,,, +I2C0_SCL,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PC0,PC1,PC2,PC3,PC4,PC5,PC9,PD2,PD3,PD4,PD5,,, +I2C0_SDA,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PC0,PC1,PC2,PC3,PC4,PC5,PC9,PD2,PD3,PD4,PD5,,, +I2C1_SCL,,,,,,,,,,PC0,PC1,PC2,PC3,PC4,PC5,PC9,PD2,PD3,PD4,PD5,,, +I2C1_SDA,,,,,,,,,,PC0,PC1,PC2,PC3,PC4,PC5,PC9,PD2,PD3,PD4,PD5,,, +TIMER0_CC0,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PC0,PC1,PC2,PC3,PC4,PC5,PC9,PD2,PD3,PD4,PD5,,, +TIMER0_CC1,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PC0,PC1,PC2,PC3,PC4,PC5,PC9,PD2,PD3,PD4,PD5,,, +TIMER0_CC2,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PC0,PC1,PC2,PC3,PC4,PC5,PC9,PD2,PD3,PD4,PD5,,, +TIMER1_CC0,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PC0,PC1,PC2,PC3,PC4,PC5,PC9,PD2,PD3,PD4,PD5,,, +TIMER1_CC1,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PC0,PC1,PC2,PC3,PC4,PC5,PC9,PD2,PD3,PD4,PD5,,, +TIMER1_CC2,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PC0,PC1,PC2,PC3,PC4,PC5,PC9,PD2,PD3,PD4,PD5,,, +TIMER2_CC0,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,,,,,,,,,,,,,, +TIMER2_CC1,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,,,,,,,,,,,,,, +TIMER2_CC2,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,,,,,,,,,,,,,, +TIMER3_CC0,,,,,,,,,,PC0,PC1,PC2,PC3,PC4,PC5,PC9,PD2,PD3,PD4,PD5,,, +TIMER3_CC1,,,,,,,,,,PC0,PC1,PC2,PC3,PC4,PC5,PC9,PD2,PD3,PD4,PD5,,, +TIMER3_CC2,,,,,,,,,,PC0,PC1,PC2,PC3,PC4,PC5,PC9,PD2,PD3,PD4,PD5,,, +TIMER4_CC0,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,,,,,,,,,,,,,, +TIMER4_CC1,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,,,,,,,,,,,,,, +TIMER4_CC2,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,,,,,,,,,,,,,, +USART0_CLK,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PC0,PC1,PC2,PC3,PC4,PC5,PC9,PD2,PD3,PD4,PD5,,, +USART0_CS,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PC0,PC1,PC2,PC3,PC4,PC5,PC9,PD2,PD3,PD4,PD5,,, +USART0_RX,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PC0,PC1,PC2,PC3,PC4,PC5,PC9,PD2,PD3,PD4,PD5,,, +USART0_TX,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PC0,PC1,PC2,PC3,PC4,PC5,PC9,PD2,PD3,PD4,PD5,,, +VDAC0_CH0,,,,,,PB0,,,,,,,,,,,,,,,,, +VDAC0_CH1,,,,,,,PB1,,,,,,,,,,,,,,,, +VDAC1_CH0,,,,,,,,PB2,,,,,,,,,,,,,,, +VDAC1_CH1,,,,,,,,,PB3,,,,,,,,,,,,,, diff --git a/ports/silabs/boards/devkit_xg24_brd2601b/pins.csv b/ports/silabs/boards/devkit_xg24_brd2601b/pins.csv new file mode 100644 index 0000000000..c1d9a5a252 --- /dev/null +++ b/ports/silabs/boards/devkit_xg24_brd2601b/pins.csv @@ -0,0 +1,21 @@ +mcu_name, board_name,port ,pin +PA0,,0,0 +PA4,LEDG,0,4 +PA5,TX,0,5 +PA6,RX,0,6 +PA7,CS,0,7 +PB0,LEDB,1,0 +PB1,,1,1 +PB2,BTN0,1,2 +PB3,BTN1,1,3 +PC0,FLASH_CS,2,0 +PC1,SCLK,2,1 +PC2,CIPO,2,2 +PC3,COPI,2,3 +PC4,SCL,2,4 +PC5,SDA,2,5 +PC9,SENSOR_CS,2,9 +PD2,LEDR,3,2 +PD3,,3,3 +PD4,,3,4 +PD5,,3,5 diff --git a/ports/silabs/boards/devkit_xg24_brd2601b/sensor.c b/ports/silabs/boards/devkit_xg24_brd2601b/sensor.c new file mode 100644 index 0000000000..cdffa9f1e5 --- /dev/null +++ b/ports/silabs/boards/devkit_xg24_brd2601b/sensor.c @@ -0,0 +1,214 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "py/runtime.h" +#include "common-hal/busio/I2C.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "supervisor/shared/translate/translate.h" +#include "em_i2c.h" +#include "sl_i2cspm.h" +#include "sl_i2cspm_sensor_config.h" +#include "sl_sensor_lux.h" +#include "sl_sensor_rht.h" +#include "sl_sensor_imu.h" +#include "sl_sensor_hall.h" +#include "sl_sensor_pressure.h" + +STATIC mp_obj_t sensor_init(busio_i2c_obj_t *i2c) { + sl_status_t sc; + + if (!common_hal_mcu_pin_is_free(&pin_PC9)) { + mp_raise_ValueError(translate("Pin PC9 is busy ")); + return mp_const_false; + } + + sc = sl_sensor_rht_init(); + if (sc != SL_STATUS_OK) { + return mp_const_false; + } + + sc = sl_sensor_lux_init(); + if (sc != SL_STATUS_OK) { + return mp_const_false; + } + + sc = sl_sensor_hall_init(); + if (sc != SL_STATUS_OK) { + return mp_const_false; + } + + sc = sl_sensor_pressure_init(); + if (sc != SL_STATUS_OK) { + return mp_const_false; + } + + sl_sensor_imu_init(); + sc = sl_sensor_imu_enable(true); + if (sc != SL_STATUS_OK) { + return mp_const_false; + } + + common_hal_mcu_pin_claim(&pin_PC9); + return mp_const_true; +} + +STATIC mp_obj_t sensor_deinit() { + + sl_sensor_hall_deinit(); + sl_sensor_lux_deinit(); + sl_sensor_rht_deinit(); + sl_sensor_pressure_deinit(); + sl_sensor_imu_enable(false); + sl_sensor_imu_deinit(); + common_hal_reset_pin(&pin_PC9); + return mp_const_true; +} + +STATIC mp_obj_t sensor_get_temperature(void) { + sl_status_t sc; + uint32_t rh; + int32_t t; + sc = sl_sensor_rht_get(&rh, &t); + + if (sc != SL_STATUS_OK) { + return mp_const_false; + } + + return mp_obj_new_float((float)t / 1000.0f); +} + +STATIC mp_obj_t sensor_get_humidity(void) { + sl_status_t sc; + uint32_t rh; + int32_t t; + sc = sl_sensor_rht_get(&rh, &t); + + if (sc != SL_STATUS_OK) { + return mp_const_false; + } + return mp_obj_new_float((float)rh / 1000.0f); +} + +STATIC mp_obj_t sensor_get_lux(void) { + sl_status_t sc; + float lux; + sc = sl_sensor_lux_get(&lux); + + if (sc != SL_STATUS_OK) { + return mp_const_false; + } + return mp_obj_new_float(lux); +} + +STATIC mp_obj_t sensor_get_hall(void) { + sl_status_t sc; + float field_strength; + bool alert; + bool tamper; + sc = sl_sensor_hall_get(&field_strength, &alert, &tamper); + + if (sc != SL_STATUS_OK) { + return mp_const_false; + } + return mp_obj_new_float(field_strength); +} + +STATIC mp_obj_t sensor_get_pressure(void) { + sl_status_t sc; + float pressure; + sc = sl_sensor_pressure_get(&pressure); + + if (sc != SL_STATUS_OK) { + return mp_const_false; + } + return mp_obj_new_float(pressure); +} + +STATIC mp_obj_t sensor_imu_get(void) { + sl_status_t sc; + int16_t ovec[3]; + int16_t avec[3]; + mp_obj_t ovec_obj[3]; + mp_obj_t avec_obj[3]; + mp_obj_t ret[2]; + + sc = sl_sensor_imu_get(ovec, avec); + if (sc != SL_STATUS_OK) { + return mp_const_false; + } + + ovec_obj[0] = mp_obj_new_int(ovec[0]); + ovec_obj[1] = mp_obj_new_int(ovec[1]); + ovec_obj[2] = mp_obj_new_int(ovec[2]); + + avec_obj[0] = mp_obj_new_int(avec[0]); + avec_obj[1] = mp_obj_new_int(avec[1]); + avec_obj[2] = mp_obj_new_int(avec[2]); + ret[0] = mp_obj_new_list(3,ovec_obj); + ret[1] = mp_obj_new_list(3,avec_obj); + return mp_obj_new_tuple(2,ret); +} + +STATIC mp_obj_t sensor_imu_calibrate(void) { + sl_status_t sc; + sc = sl_sensor_imu_calibrate(); + if (sc != SL_STATUS_OK) { + return mp_const_false; + } + return mp_const_true; +} + +STATIC MP_DEFINE_CONST_FUN_OBJ_1(sensor_init_obj,sensor_init); +STATIC MP_DEFINE_CONST_FUN_OBJ_0(sensor_deinit_obj,sensor_deinit); +STATIC MP_DEFINE_CONST_FUN_OBJ_0(sensor_get_temperature_obj,sensor_get_temperature); +STATIC MP_DEFINE_CONST_FUN_OBJ_0(sensor_get_humidity_obj,sensor_get_humidity); +STATIC MP_DEFINE_CONST_FUN_OBJ_0(sensor_get_lux_obj,sensor_get_lux); +STATIC MP_DEFINE_CONST_FUN_OBJ_0(sensor_get_hall_obj,sensor_get_hall); +STATIC MP_DEFINE_CONST_FUN_OBJ_0(sensor_get_pressure_obj,sensor_get_pressure); +STATIC MP_DEFINE_CONST_FUN_OBJ_0(sensor_imu_get_obj,sensor_imu_get); +STATIC MP_DEFINE_CONST_FUN_OBJ_0(sensor_imu_calibrate_obj,sensor_imu_calibrate); + + +STATIC const mp_rom_map_elem_t sensor_globals_table[] = { + { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_sensor) }, + { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&sensor_init_obj) }, + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&sensor_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR_temperature), MP_ROM_PTR(&sensor_get_temperature_obj) }, + { MP_ROM_QSTR(MP_QSTR_humidity), MP_ROM_PTR(&sensor_get_humidity_obj) }, + { MP_ROM_QSTR(MP_QSTR_lux), MP_ROM_PTR(&sensor_get_lux_obj) }, + { MP_ROM_QSTR(MP_QSTR_hall), MP_ROM_PTR(&sensor_get_hall_obj) }, + { MP_ROM_QSTR(MP_QSTR_pressure), MP_ROM_PTR(&sensor_get_pressure_obj) }, + { MP_ROM_QSTR(MP_QSTR_imu), MP_ROM_PTR(&sensor_imu_get_obj) }, + { MP_ROM_QSTR(MP_QSTR_imu_calibrate), MP_ROM_PTR(&sensor_imu_calibrate_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(sensor_module_globals, sensor_globals_table); + +const mp_obj_module_t sensor_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&sensor_module_globals, +}; + +MP_REGISTER_MODULE(MP_QSTR_sensor, sensor_module,1); diff --git a/ports/silabs/boards/explorerkit_xg24_brd2703a/README.md b/ports/silabs/boards/explorerkit_xg24_brd2703a/README.md new file mode 100644 index 0000000000..438ec42bfc --- /dev/null +++ b/ports/silabs/boards/explorerkit_xg24_brd2703a/README.md @@ -0,0 +1,28 @@ +## Gen Pin instructions ## + +# Input File +pins.csv : contain pin name, port number ,pin number +pin_functions.csv : contain list of pin support for peripheral +make_pins.py : python script to gen pin + + +# Run make_pins.py +Copy above input file to folder boards/brd2601b/ +Run CMD: + $ cd boards/brd2601b/ + $ python make_pins.py -s pins.c -e pin_functions.h pins.csv pin_functions.csv + + -s: name/directory of output source file + -e: name/directory of output header file + +# Output +pins.c : register pin to board_module_globals_table + generate array contains supported function of pin +pin_functions.h : define index of functions + Example: pin_pa0_functions[FN_EUSART0_RX] == 1 // Can assign pin pa0 for EUSART0_RX + pin_pa0_functions[FN_EUSART0_RX] == 255 // Can't assign pin pa0 for EUSART0_RX + + +# Read pin define on REPL +import board +dir(board) diff --git a/ports/silabs/boards/explorerkit_xg24_brd2703a/board.c b/ports/silabs/boards/explorerkit_xg24_brd2703a/board.c new file mode 100644 index 0000000000..f0fcc3d41f --- /dev/null +++ b/ports/silabs/boards/explorerkit_xg24_brd2703a/board.c @@ -0,0 +1,33 @@ +/***************************************************************************//** + * @file board.c + * @brief + ******************************************************************************* + * # License + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + ******************************************************************************* + * + * SPDX-License-Identifier: Zlib + * + * The licensor of this software is Silicon Laboratories Inc. + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + * + ******************************************************************************/ + +#include "supervisor/board.h" + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/silabs/boards/explorerkit_xg24_brd2703a/custom_brd2703a_cp_support.slcc b/ports/silabs/boards/explorerkit_xg24_brd2703a/custom_brd2703a_cp_support.slcc new file mode 100644 index 0000000000..b78d83ce51 --- /dev/null +++ b/ports/silabs/boards/explorerkit_xg24_brd2703a/custom_brd2703a_cp_support.slcc @@ -0,0 +1,20 @@ +id: custom_brd2703a_cp_support +label: CircuitPython BRD2703A support +description: > + CircuitPython Board support for BRD2703A. +package: custom +category: Custom +quality: production +root_path: ../boards/explorerkit_xg24_brd2703a +include: + - path: '' + file_list: + - path: mpconfigboard.h +source: + - path: board.c +provides: + - name: custom_brd2703a_cp_support +requires: + - name: efr32mg24b210f1536im48 +recommends: + - id: bt_rail_compatibility_fix diff --git a/ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.h b/ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.h new file mode 100644 index 0000000000..87da017fb7 --- /dev/null +++ b/ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.h @@ -0,0 +1,52 @@ +/***************************************************************************//** + * @file mpconfigboard.h + * @brief + ******************************************************************************* + * # License + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + ******************************************************************************* + * + * SPDX-License-Identifier: Zlib + * + * The licensor of this software is Silicon Laboratories Inc. + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + * + ******************************************************************************/ +#include "build-explorerkit_xg24_brd2703a/pin_functions.h" + +// Micropython setup +#define MICROPY_HW_BOARD_NAME "SiLabs xG24 Explorer Kit" +#define MICROPY_HW_MCU_NAME EFR32_SERIES_LOWER + +#define HSE_VALUE ((uint32_t)8000000) +#define BOARD_HSE_SOURCE (RCC_HSE_BYPASS) +#define BOARD_HAS_LOW_SPEED_CRYSTAL (0) + +#define DEFAULT_I2C_BUS_SDA (&pin_PB5) +#define DEFAULT_I2C_BUS_SCL (&pin_PB4) +#define DEFAULT_I2C_PERIPHERAL I2C0 + +#define DEFAULT_SPI_BUS_SCK (&pin_PC1) +#define DEFAULT_SPI_BUS_MOSI (&pin_PC3) +#define DEFAULT_SPI_BUS_MISO (&pin_PC2) +#define DEFAULT_SPI_BUS_SS (&pin_PC0) + +#define NVM_BYTEARRAY_BUFFER_SIZE (512) +#define CIRCUITPY_INTERNAL_NVM_SIZE (512) +#undef MICROPY_USE_INTERNAL_PRINTF +#define MICROPY_USE_INTERNAL_PRINTF (0) diff --git a/ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.mk b/ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.mk new file mode 100644 index 0000000000..dd63b4da17 --- /dev/null +++ b/ports/silabs/boards/explorerkit_xg24_brd2703a/mpconfigboard.mk @@ -0,0 +1,16 @@ +BOARD_BRD = brd2703a +INTERNAL_FLASH_FILESYSTEM = 1 +QSPI_FLASH_FILESYSTEM = 0 +SPI_FLASH_FILESYSTEM = 0 + +MCU_SERIES = MG24 +MCU_VARIANT = EFR32MG24B210F1536IM48 + +CIRCUITPY_USB = 0 + +CIRCUITPY_CREATOR_ID = 0x19960000 +CIRCUITPY_CREATION_ID = 0x00242703 + + +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_BLE +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Register diff --git a/ports/silabs/boards/explorerkit_xg24_brd2703a/pin_functions.csv b/ports/silabs/boards/explorerkit_xg24_brd2703a/pin_functions.csv new file mode 100644 index 0000000000..8d623ce708 --- /dev/null +++ b/ports/silabs/boards/explorerkit_xg24_brd2703a/pin_functions.csv @@ -0,0 +1,35 @@ +EUSART0_CS,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,,,,,,,,,,,, +EUSART0_RX,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,,,,,,,,,,,, +EUSART0_SCLK,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,,,,,,,,,,,, +EUSART0_TX,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,,,,,,,,,,,, +EUSART1_CS,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,PC0,PC1,PC2,PC3,PC4,PC5,PC8,PC9,PD2,PD3,PD4,PD5 +EUSART1_RX,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,PC0,PC1,PC2,PC3,PC4,PC5,PC8,PC9,PD2,PD3,PD4,PD5 +EUSART1_SCLK,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,PC0,PC1,PC2,PC3,PC4,PC5,PC8,PC9,PD2,PD3,PD4,PD5 +EUSART1_TX,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,PC0,PC1,PC2,PC3,PC4,PC5,PC8,PC9,PD2,PD3,PD4,PD5 +I2C0_SCL,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,PB4,PC0,PC1,PC2,PC3,PC4,PC8,PC9,PD2,PD3,PD4,PD5 +I2C0_SDA,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,PB4,PC0,PC1,PC2,PC3,PC4,PC8,PC9,PD2,PD3,PD4,PD5 +I2C1_SCL,,,,,,,,,,,,PC0,PC1,PC2,PC3,PC4,PC5,PC8,PC9,PD2,PD3,PD4,PD5 +I2C1_SDA,,,,,,,,,,,,PC0,PC1,PC2,PC3,PC4,PC5,PC8,PC9,PD2,PD3,PD4,PD5 +TIMER0_CC0,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,PC0,PC1,PC2,PC3,PC4,PC5,PC8,PC9,PD2,PD3,PD4,PD5 +TIMER0_CC1,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,PC0,PC1,PC2,PC3,PC4,PC5,PC8,PC9,PD2,PD3,PD4,PD5 +TIMER0_CC2,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,PC0,PC1,PC2,PC3,PC4,PC5,PC8,PC9,PD2,PD3,PD4,PD5 +TIMER1_CC0,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,PC0,PC1,PC2,PC3,PC4,PC5,PC8,PC9,PD2,PD3,PD4,PD5 +TIMER1_CC1,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,PC0,PC1,PC2,PC3,PC4,PC5,PC8,PC9,PD2,PD3,PD4,PD5 +TIMER1_CC2,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,PC0,PC1,PC2,PC3,PC4,PC5,PC8,PC9,PD2,PD3,PD4,PD5 +TIMER2_CC0,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,,,,,,,,,,,, +TIMER2_CC1,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,,,,,,,,,,,, +TIMER2_CC2,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,,,,,,,,,,,, +TIMER3_CC0,,,,,,,,,,,,PC0,PC1,PC2,PC3,PC4,PC5,PC8,PC9,PD2,PD3,PD4,PD5 +TIMER3_CC1,,,,,,,,,,,,PC0,PC1,PC2,PC3,PC4,PC5,PC8,PC9,PD2,PD3,PD4,PD5 +TIMER3_CC2,,,,,,,,,,,,PC0,PC1,PC2,PC3,PC4,PC5,PC8,PC9,PD2,PD3,PD4,PD5 +TIMER4_CC0,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,,,,,,,,,,,, +TIMER4_CC1,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,,,,,,,,,,,, +TIMER4_CC2,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,,,,,,,,,,,, +USART0_CLK,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,PC0,PC1,PC2,PC3,PC4,PC5,PC8,PC9,PD2,PD3,PD4,PD5 +USART0_CS,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,PC0,PC1,PC2,PC3,PC4,PC5,PC8,PC9,PD2,PD3,PD4,PD5 +USART0_RX,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,PC0,PC1,PC2,PC3,PC4,PC5,PC8,PC9,PD2,PD3,PD4,PD5 +USART0_TX,PA0,PA4,PA5,PA6,PA7,PB0,PB1,PB2,PB3,PB4,PB5,PC0,PC1,PC2,PC3,PC4,PC5,PC8,PC9,PD2,PD3,PD4,PD5 +VDAC0_CH0,,,,,,PB0,,,,,,,,,,,,,,,,, +VDAC0_CH1,,,,,,,PB1,,,,,,,,,,,,,,,, +VDAC1_CH0,,,,,,,,PB2,,,,,,,,,,,,,,, +VDAC1_CH1,,,,,,,,,PB3,,,,,,,,,,,,,, diff --git a/ports/silabs/boards/explorerkit_xg24_brd2703a/pins.csv b/ports/silabs/boards/explorerkit_xg24_brd2703a/pins.csv new file mode 100644 index 0000000000..c321057906 --- /dev/null +++ b/ports/silabs/boards/explorerkit_xg24_brd2703a/pins.csv @@ -0,0 +1,24 @@ +mcu_name, board_name,port ,pin +PA0,MIKROE_PWM,0,0 +PA4,LED0,0,4 +PA5,TX,0,5 +PA6,RX,0,6 +PA7,LED1,0,7 +PB0,MIKROE_AN,1,0 +PB1,MIKROE_INT,1,1 +PB2,BTN0,1,2 +PB3,BNT1,1,3 +PB4,MIKROE_SCL,1,4 +PB5,MIKROE_SDA,1,5 +PC0,MIKROE_CS,2,0 +PC1,MIKROE_SCK,2,1 +PC2,MIKROE_MISO,2,2 +PC3,MIKROE_MOSI,2,3 +PC4,QWIIC_SCL,2,4 +PC5,QWIIC_SDA,2,5 +PC8,MIKROE_RST,2,8 +PC9,,2,9 +PD2,,3,2 +PD3,,3,3 +PD4,MIKROE_TX,3,4 +PD5,MIKROE_RX,3,5 diff --git a/ports/silabs/boards/mp_efr32xg24_gchelper.s b/ports/silabs/boards/mp_efr32xg24_gchelper.s new file mode 100644 index 0000000000..18fe4a4a3a --- /dev/null +++ b/ports/silabs/boards/mp_efr32xg24_gchelper.s @@ -0,0 +1,28 @@ + .syntax unified + .cpu cortex-m33 + .thumb + .text + .align 2 + +@ uint cpu_get_regs_and_sp(r0=uint regs[10]) + .global cpu_get_regs_and_sp + .thumb + .thumb_func + .type cpu_get_regs_and_sp, %function +cpu_get_regs_and_sp: +@ store registers into given array + str r4, [r0], #4 + str r5, [r0], #4 + str r6, [r0], #4 + str r7, [r0], #4 + str r8, [r0], #4 + str r9, [r0], #4 + str r10, [r0], #4 + str r11, [r0], #4 + str r12, [r0], #4 + str r13, [r0], #4 +@ return the sp + @Move stack pointer to return register + mov r0, sp + @Branch to link register (return address) and change instruction set if needed + bx lr diff --git a/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/README.md b/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/README.md new file mode 100644 index 0000000000..438ec42bfc --- /dev/null +++ b/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/README.md @@ -0,0 +1,28 @@ +## Gen Pin instructions ## + +# Input File +pins.csv : contain pin name, port number ,pin number +pin_functions.csv : contain list of pin support for peripheral +make_pins.py : python script to gen pin + + +# Run make_pins.py +Copy above input file to folder boards/brd2601b/ +Run CMD: + $ cd boards/brd2601b/ + $ python make_pins.py -s pins.c -e pin_functions.h pins.csv pin_functions.csv + + -s: name/directory of output source file + -e: name/directory of output header file + +# Output +pins.c : register pin to board_module_globals_table + generate array contains supported function of pin +pin_functions.h : define index of functions + Example: pin_pa0_functions[FN_EUSART0_RX] == 1 // Can assign pin pa0 for EUSART0_RX + pin_pa0_functions[FN_EUSART0_RX] == 255 // Can't assign pin pa0 for EUSART0_RX + + +# Read pin define on REPL +import board +dir(board) diff --git a/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/board.c b/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/board.c new file mode 100644 index 0000000000..100ef47b15 --- /dev/null +++ b/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/board.c @@ -0,0 +1,29 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/custom_brd2704a_cp_support.slcc b/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/custom_brd2704a_cp_support.slcc new file mode 100644 index 0000000000..669e19908f --- /dev/null +++ b/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/custom_brd2704a_cp_support.slcc @@ -0,0 +1,18 @@ +id: custom_brd2704a_cp_support +label: CircuitPython BRD2704A support +description: > + CircuitPython Board support for BRD2704A. +package: custom +category: Custom +quality: production +root_path: ../boards/sparkfun_thingplus_matter_mgm240p_brd2704a +include: + - path: '' + file_list: + - path: mpconfigboard.h +source: + - path: board.c +provides: + - name: custom_brd2704a_cp_support +requires: + - name: mgm240pb32vna diff --git a/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/mpconfigboard.h b/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/mpconfigboard.h new file mode 100644 index 0000000000..ea43ef27cd --- /dev/null +++ b/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/mpconfigboard.h @@ -0,0 +1,49 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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 "build-sparkfun_thingplus_matter_mgm240p_brd2704a/pin_functions.h" + +// Micropython setup +#define MICROPY_HW_BOARD_NAME "Sparkfun Thing Plus MGM240P" +#define MICROPY_HW_MCU_NAME EFR32_SERIES_LOWER + +#define HSE_VALUE ((uint32_t)8000000) +#define BOARD_HSE_SOURCE (RCC_HSE_BYPASS) +#define BOARD_HAS_LOW_SPEED_CRYSTAL (0) + +#define DEFAULT_I2C_BUS_SDA (&pin_PB4) +#define DEFAULT_I2C_BUS_SCL (&pin_PB3) +#define DEFAULT_I2C_PERIPHERAL I2C0 + +#define DEFAULT_SPI_BUS_SCK (&pin_PC2) +#define DEFAULT_SPI_BUS_MOSI (&pin_PC3) +#define DEFAULT_SPI_BUS_MISO (&pin_PC6) +#define DEFAULT_SPI_BUS_SS (&pin_PA7) + +#define NVM_BYTEARRAY_BUFFER_SIZE (512) +#define CIRCUITPY_INTERNAL_NVM_SIZE (512) +#undef MICROPY_USE_INTERNAL_PRINTF +#define MICROPY_USE_INTERNAL_PRINTF (0) diff --git a/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/mpconfigboard.mk b/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/mpconfigboard.mk new file mode 100644 index 0000000000..dcfc337031 --- /dev/null +++ b/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/mpconfigboard.mk @@ -0,0 +1,17 @@ + +BOARD_BRD = brd2704a +INTERNAL_FLASH_FILESYSTEM = 1 +QSPI_FLASH_FILESYSTEM = 0 +SPI_FLASH_FILESYSTEM = 0 + +MCU_SERIES = MG24 +MCU_VARIANT = MGM240PB32VNA + +CIRCUITPY_USB = 0 +CIRCUITPY_SDCARDIO = 1 + +CIRCUITPY_CREATOR_ID = 0x19960000 +CIRCUITPY_CREATION_ID = 0x00242704 + +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_BLE +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Register diff --git a/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/pin_functions.csv b/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/pin_functions.csv new file mode 100644 index 0000000000..a1ff1c3820 --- /dev/null +++ b/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/pin_functions.csv @@ -0,0 +1,35 @@ +EUSART0_CS,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,,,,,,,,,,,,,, +EUSART0_RX,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,,,,,,,,,,,,,, +EUSART0_SCLK,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,,,,,,,,,,,,,, +EUSART0_TX,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,,,,,,,,,,,,,, +EUSART1_CS,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7,PD0,PD1,PD2,PD3,, +EUSART1_RX,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7,PD0,PD1,PD2,PD3,, +EUSART1_SCLK,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7,PD0,PD1,PD2,PD3,, +EUSART1_TX,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7,PD0,PD1,PD2,PD3,, +I2C0_SCL,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,PB4,PC0,PC1,PC2,PC3,PC4,PC5,PC6,PD0,PD1,PD2,PD3,, +I2C0_SDA,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,PB4,PC0,PC1,PC2,PC3,PC4,PC5,PC6,PD0,PD1,PD2,PD3,, +I2C1_SCL,,,,,,,,,,,,PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7,PD0,PD1,PD2,PD3,, +I2C1_SDA,,,,,,,,,,,,PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7,PD0,PD1,PD2,PD3,, +TIMER0_CC0,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7,PD0,PD1,PD2,PD3,, +TIMER0_CC1,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7,PD0,PD1,PD2,PD3,, +TIMER0_CC2,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7,PD0,PD1,PD2,PD3,, +TIMER1_CC0,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7,PD0,PD1,PD2,PD3,, +TIMER1_CC1,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7,PD0,PD1,PD2,PD3,, +TIMER1_CC2,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7,PD0,PD1,PD2,PD3,, +TIMER2_CC0,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,,,,,,,,,,,,,, +TIMER2_CC1,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,,,,,,,,,,,,,, +TIMER2_CC2,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,,,,,,,,,,,,,, +TIMER3_CC0,,,,,,,,,,,,PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7,PD0,PD1,PD2,PD3,, +TIMER3_CC1,,,,,,,,,,,,PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7,PD0,PD1,PD2,PD3,, +TIMER3_CC2,,,,,,,,,,,,PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7,PD0,PD1,PD2,PD3,, +TIMER4_CC0,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,,,,,,,,,,,,,, +TIMER4_CC1,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,,,,,,,,,,,,,, +TIMER4_CC2,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,,,,,,,,,,,,,, +USART0_CLK,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7,PD0,PD1,PD2,PD3,, +USART0_CS,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7,PD0,PD1,PD2,PD3,, +USART0_RX,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7,PD0,PD1,PD2,PD3,, +USART0_TX,PA0,PA4,PA5,PA6,PA7,PA8,PB0,PB1,PB2,PB3,PB4,PC0,PC1,PC2,PC3,PC4,PC5,PC6,PC7,PD0,PD1,PD2,PD3,, +VDAC0_CH0,,,,,,,PB0,,,,,,,,,,,,,,,,,, +VDAC0_CH1,,,,,,,,PB1,,,,,,,,,,,,,,,,, +VDAC1_CH0,,,,,,,,,PB2,,,,,,,,,,,,,,,, +VDAC1_CH1,,,,,,,,,,PB3,,,,,,,,,,,,,,, diff --git a/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/pins.csv b/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/pins.csv new file mode 100644 index 0000000000..7c60920065 --- /dev/null +++ b/ports/silabs/boards/sparkfun_thingplus_matter_mgm240p_brd2704a/pins.csv @@ -0,0 +1,24 @@ +mcu_name, board_name,port ,pin +PA0,,0,0 +PA4,,0,4 +PA5,TX,0,5 +PA6,RX,0,6 +PA7,SD_CS,0,7 +PA8,LED,0,8 +PB0,,1,0 +PB1,,1,1 +PB2,,1,2 +PB3,SCL,1,3 +PB4,SDA,1,4 +PC0,,2,0 +PC1,,2,1 +PC2,SCK,2,2 +PC3,MOSI,2,3 +PC4,,2,4 +PC5,,2,5 +PC6,MISO,2,6 +PC7,,2,7 +PD0,,3,0 +PD1,,3,1 +PD2,,3,2 +PD3,,3,3 diff --git a/ports/silabs/circuitpython_efr32.slcp b/ports/silabs/circuitpython_efr32.slcp new file mode 100644 index 0000000000..e7010b08cd --- /dev/null +++ b/ports/silabs/circuitpython_efr32.slcp @@ -0,0 +1,74 @@ +# Silicon Labs Project Configuration Tools: slcp, v0, Component selection file. +description: | + A project structure used as a configuration for CircuitPython + Custom Bluetooth + Standard DMP (Dynamic Multiprotocol) applications. It runs on top of FreeRTOS and multiprotocol RAIL utilizing IEEE 802.15.4 standard protocol. +filter: +- name: Capability + value: [Multiprotocol] +- name: Device Type + value: [SoC] +- name: Project Difficulty + value: [Advanced] +- name: Wireless Technology + value: [Bluetooth] +package: Bluetooth +quality: production +tag: ['hardware:rf:band:2400', 'hardware:device:ram:64'] +sdk: {id: gecko_sdk, version: 4.2.1} +toolchain_settings: [] +sdk_extension: +- id: cp_efr32 + version: 1.0.0 +component: +- {id: bluetooth_feature_nvm} +- {id: bluetooth_feature_gatt_server} +- {id: bluetooth_feature_sm} +- {id: mpu} +- {id: bluetooth_feature_legacy_advertiser} +- {id: bluetooth_feature_legacy_scanner} +- {id: gatt_configuration} +- {id: freertos} +- {id: bluetooth_stack} +- {id: bluetooth_feature_gatt} +- {id: uartdrv_core} +- {id: i2cspm_core} +- {id: spidrv_core} +- {id: pwm_core} +- {id: emlib_usart} +- {id: emlib_vdac} +- {id: emlib_iadc} +- {id: nvm3_lib} +- {id: nvm3_default} +- {id: tempdrv} +- {id: sleeptimer} +- {id: emlib_wdog} +- {id: bluetooth_feature_connection} +- {id: rail_lib_multiprotocol} +- {id: bluetooth_feature_dynamic_gattdb} +- {id: bluetooth_feature_system} +- {id: bluetooth_feature_scanner} +- {id: component_catalog} +- {id: app_assert} +requires: +- condition: [brd2601b] + name: custom_brd2601b_cp_support +- condition: [brd2704a] + name: custom_brd2704a_cp_support +- condition: [brd2703a] + name: custom_brd2703a_cp_support +configuration: +- {name: SL_SLEEPTIMER_WALLCLOCK_CONFIG, value: '1'} +- {name: NVM3_DEFAULT_MAX_OBJECT_SIZE, value: '512'} +- {name: SL_STACK_SIZE, value: '2752'} +- {name: SL_HEAP_SIZE, value: '11000'} +- name: SL_POWER_MANAGER_LOWEST_EM_ALLOWED + value: '1' +- {name: configTOTAL_HEAP_SIZE, value: '8192'} +- {name: configTIMER_TASK_PRIORITY, value: '55'} +- {name: configTIMER_TASK_STACK_DEPTH, value: '160'} +- condition: [psa_crypto] + name: SL_PSA_KEY_USER_SLOT_COUNT + value: '0' +- {name: APP_LOG_PREFIX_ENABLE, value: '0'} +ui_hints: + highlight: + - {path: config/btconf/gatt_configuration.btconf} diff --git a/ports/silabs/common-hal/_bleio/Adapter.c b/ports/silabs/common-hal/_bleio/Adapter.c new file mode 100644 index 0000000000..cbfdcbce55 --- /dev/null +++ b/ports/silabs/common-hal/_bleio/Adapter.c @@ -0,0 +1,650 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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 +#include +#include +#include "py/gc.h" +#include "py/objstr.h" +#include "py/runtime.h" +#include "shared/runtime/interrupt_char.h" +#include "shared-bindings/_bleio/Address.h" +#include "shared-bindings/_bleio/Connection.h" +#include "shared-bindings/_bleio/ScanEntry.h" +#include "shared-bindings/_bleio/__init__.h" +#include "shared-bindings/time/__init__.h" +#include "common-hal/_bleio/Connection.h" +#include "supervisor/shared/tick.h" + +#define PUBLIC_ADDRESS 0 +#define STATIC_ADDRESS 1 +#define BLE_EXT_ADV_MAX_SIZE 32 + +#define UNIT_0_625_MS (625) +#define UNIT_1_25_MS (1250) +#define UNIT_10_MS (10000) + +#define SCAN_TIMEOUT_MS_DEFAUT 3000 +#define BLE_GAP_SCAN_BUFFER_EXTENDED_MAX_SUPPORTED 256 +#define BLE_GAP_SCAN_BUFFER_MAX 32 +#define DEVICE_NAME_LEN 15 + +EventGroupHandle_t xscan_event; +device_scan_info_t scan_info; +bleio_connection_internal_t bleio_connections[BLEIO_TOTAL_CONNECTION_COUNT]; + +// Set scan data form sl_bt_on_event +void set_scan_device_info_on_ble_evt(bd_addr address, + uint8_t address_type, + int8_t rssi, + uint8array *data) { + scan_info.address = address; + scan_info.address_type = address_type; + scan_info.rssi = rssi; + memcpy(scan_info.data, data->data, data->len); +} + +// Get state of the BLE adapter. +bool common_hal_bleio_adapter_get_enabled(bleio_adapter_obj_t *self) { + return self->is_enable; +} + +// Set state of the BLE adapter +void common_hal_bleio_adapter_set_enabled(bleio_adapter_obj_t *self, + bool enabled) { + + const bool is_enabled = common_hal_bleio_adapter_get_enabled(self); + bd_addr get_address; + uint8_t address_type; + uint8_t conn_index; + bleio_connection_internal_t *connection; + sl_status_t sc = SL_STATUS_FAIL; + uint8_t device_name[DEVICE_NAME_LEN + 1]; + memset(device_name, 0, DEVICE_NAME_LEN); + + // Don't enable or disable twice + if (is_enabled == enabled) { + return; + } + + sc = sl_bt_system_get_identity_address(&get_address, &address_type); + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError(translate("Get address fail.")); + } + snprintf((char *)device_name, DEVICE_NAME_LEN + 1, + "CIRCUITPY-%X%X", get_address.addr[1], get_address.addr[0]); + + if (enabled) { + sl_bt_gatt_server_write_attribute_value(gattdb_device_name, + 0, + DEVICE_NAME_LEN, + device_name); + + // Clear all of the internal connection objects. + for (conn_index = 0; conn_index < BLEIO_TOTAL_CONNECTION_COUNT; conn_index++) { + connection = &bleio_connections[conn_index]; + // Reset connection. + connection->conn_handle = BLEIO_HANDLE_INVALID; + } + } else { + self->is_enable = false; + } +} + +// Get mac address of the BLE adapter +bleio_address_obj_t *common_hal_bleio_adapter_get_address(bleio_adapter_obj_t *self) { + bd_addr get_address; + uint8_t address_type; + sl_status_t sc = SL_STATUS_FAIL; + bleio_address_obj_t *address; + + sc = sl_bt_system_get_identity_address(&get_address, &address_type); + if (SL_STATUS_OK != sc) { + return NULL; + } + + address = m_new_obj(bleio_address_obj_t); + address->base.type = &bleio_address_type; + common_hal_bleio_address_construct(address, get_address.addr, + BLEIO_ADDRESS_TYPE_RANDOM_STATIC); + return address; +} + +// Set identity address +bool common_hal_bleio_adapter_set_address(bleio_adapter_obj_t *self, + bleio_address_obj_t *address) { + + sl_status_t sc = SL_STATUS_FAIL; + mp_buffer_info_t bufinfo; + bd_addr ble_addr; + + if (NULL == address) { + return false; + } + if (!mp_get_buffer(address->bytes, &bufinfo, MP_BUFFER_READ)) { + return false; + } + memcpy(ble_addr.addr, bufinfo.buf, 6); + sl_bt_system_set_identity_address(ble_addr, PUBLIC_ADDRESS); + return sc == SL_STATUS_OK; +} + +// Get name of the BLE adapter +mp_obj_str_t *common_hal_bleio_adapter_get_name(bleio_adapter_obj_t *self) { + char name[DEVICE_NAME_LEN]; + size_t value_len = 0; + uint8_t sc; + memset(name, 0, DEVICE_NAME_LEN); + sc = sl_bt_gatt_server_read_attribute_value(gattdb_device_name, + 0, + DEVICE_NAME_LEN, + &value_len, + (uint8_t *)name); + if (SL_STATUS_OK != sc) { + return NULL; + } + return mp_obj_new_str(name, strlen(name)); +} + +// Set name of the BLE adapter +void common_hal_bleio_adapter_set_name(bleio_adapter_obj_t *self, + const char *name) { + sl_bt_gatt_server_write_attribute_value(gattdb_device_name, + 0, + DEVICE_NAME_LEN, + (const uint8_t *)name); +} + +// starts a BLE scan +mp_obj_t common_hal_bleio_adapter_start_scan(bleio_adapter_obj_t *self, + uint8_t *prefixes, + size_t prefix_length, + bool extended, + mp_int_t buffer_size, + mp_float_t timeout, + mp_float_t interval, + mp_float_t window, + mp_int_t minimum_rssi, + bool active) { + + sl_status_t sc; + uint64_t start_ticks = supervisor_ticks_ms64(); + uint64_t current_ticks = start_ticks; + uint32_t timeout_ms = timeout * 1000; + + if (timeout_ms == 0) { + timeout_ms = SCAN_TIMEOUT_MS_DEFAUT; + } + + if (self->scan_results != NULL) { + if (!shared_module_bleio_scanresults_get_done(self->scan_results)) { + mp_raise_bleio_BluetoothError( + translate("Scan already in progress. Stop with stop_scan.")); + } + self->scan_results = NULL; + } + + sl_bt_scanner_stop(); + self->scan_results = shared_module_bleio_new_scanresults(buffer_size, + prefixes, + prefix_length, + minimum_rssi); + xscan_event = xEventGroupCreate(); + if (xscan_event != NULL) { + xEventGroupClearBits(xscan_event, 1 << 0); + } + + sc = sl_bt_scanner_start(sl_bt_scanner_scan_phy_1m, + sl_bt_scanner_discover_generic); + + if (SL_STATUS_OK != sc) { + self->scan_results = NULL; + } + + // Busy-wait until timeout or until we've read enough chars. + while (current_ticks - start_ticks <= timeout_ms) { + if (xscan_event != NULL) { + xEventGroupWaitBits(xscan_event, 1 << 0, pdTRUE, pdFALSE, + timeout_ms / portTICK_PERIOD_MS); + } + self->scan_results->prefix_length = 0; + scan_info.data_len = 28; + shared_module_bleio_scanresults_append( + self->scan_results, + supervisor_ticks_ms64(), + true, + true, + scan_info.rssi, + scan_info.address.addr, + scan_info.address_type, + scan_info.data, + scan_info.data_len); + current_ticks = supervisor_ticks_ms64(); + // Allow user to break out of a timeout with a KeyboardInterrupt. + if (mp_hal_is_interrupted()) { + break; + } + } + + shared_module_bleio_scanresults_set_done(self->scan_results, true); + vEventGroupDelete(xscan_event); + return MP_OBJ_FROM_PTR(self->scan_results); +} + +void common_hal_bleio_adapter_stop_scan(bleio_adapter_obj_t *self) { + if (self->scan_results == NULL) { + return; + } + sl_bt_scanner_stop(); + shared_module_bleio_scanresults_set_done(self->scan_results, true); + self->scan_results = NULL; +} + +// Start the advertising on an advertising set with specified +// discovery and connection modes +uint32_t _common_hal_bleio_adapter_start_advertising( + bleio_adapter_obj_t *self, + bool connectable, + bool anonymous, + uint32_t timeout, + float interval, + const uint8_t *advertising_data, + uint16_t advertising_data_len, + const uint8_t *scan_response_data, + uint16_t scan_response_data_len, + mp_int_t tx_power, + const bleio_address_obj_t *directed_to) { + + sl_status_t sc = SL_STATUS_FAIL; + int16_t set_power; + uint32_t interval_min = 160; + uint32_t interval_max = 160; + bd_addr address; + uint8_t address_type; + uint8_t system_id[8]; + uint8_t enable_connect; + + if (self->user_advertising) { + return SL_STATUS_BUSY; + } + + sc = sl_bt_advertiser_create_set(&self->advertising_handle); + + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError(translate("Create_set fail.")); + return sc; + } + sc = sl_bt_advertiser_set_channel_map(self->advertising_handle, 7); + if (SL_STATUS_OK != sc) { + return sc; + } + + sc = sl_bt_system_get_identity_address(&address, &address_type); + + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError(translate("Get address fail.")); + return sc; + } + // Pad and reverse unique ID to get System ID. + system_id[0] = address.addr[5]; + system_id[1] = address.addr[4]; + system_id[2] = address.addr[3]; + system_id[3] = 0xFF; + system_id[4] = 0xFE; + system_id[5] = address.addr[2]; + system_id[6] = address.addr[1]; + system_id[7] = address.addr[0]; + + sc = sl_bt_gatt_server_write_attribute_value(gattdb_system_id, + 0, + sizeof(system_id), + system_id); + if (SL_STATUS_OK != sc) { + return sc; + } + + sc = sl_bt_advertiser_set_tx_power(self->advertising_handle, + tx_power, + &set_power); + if (SL_STATUS_OK != sc) { + return sc; + } + + // Set advertising interval. + sc = sl_bt_advertiser_set_timing( + self->advertising_handle, + interval_min, // min. adv. interval (milliseconds * 1.6) + interval_max, // max. adv. interval (milliseconds * 1.6) + 0, // adv. duration + 0); // max. num. adv. events + + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError(translate("Set_timing fail.")); + return sc; + } + + sc = sl_bt_legacy_advertiser_set_data( + self->advertising_handle, + sl_bt_advertiser_advertising_data_packet, + advertising_data_len, + advertising_data); + + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError(translate("Set data fail.")); + return sc; + } + + // Start advertising and enable connections. + enable_connect = sl_bt_legacy_advertiser_scannable; + if (true == connectable) { + enable_connect = sl_bt_advertiser_connectable_scannable; + } + sc = sl_bt_legacy_advertiser_start(self->advertising_handle, + enable_connect); + + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError(translate("Start advertise fail.")); + } else { + self->user_advertising = true; + } + + return sc; +} + +// Check size of packet advertising to send +STATIC void check_data_fit(size_t data_len, bool connectable) { + if (data_len > BLE_EXT_ADV_MAX_SIZE || + (connectable && data_len > BLE_EXT_ADV_MAX_SIZE)) { + mp_raise_ValueError( + translate("Data too large for advertisement packet")); + } +} + +// Start advertising +void common_hal_bleio_adapter_start_advertising( + bleio_adapter_obj_t *self, + bool connectable, + bool anonymous, + uint32_t timeout, + mp_float_t interval, + mp_buffer_info_t *advertising_data_bufinfo, + mp_buffer_info_t *scan_response_data_bufinfo, + mp_int_t tx_power, + const bleio_address_obj_t *directed_to) { + + if (self->user_advertising) { + common_hal_bleio_adapter_stop_advertising(self); + } + // Interval value has already been validated. + + check_data_fit(advertising_data_bufinfo->len, connectable); + check_data_fit(scan_response_data_bufinfo->len, connectable); + + if (advertising_data_bufinfo->len > 31 && scan_response_data_bufinfo->len > 0) { + mp_raise_bleio_BluetoothError( + translate("Extended advertisements not supported")); + } + + if (advertising_data_bufinfo->len > 0 && directed_to != NULL) { + mp_raise_bleio_BluetoothError( + translate("Data not supported with directed advertising")); + } + + if (anonymous) { + mp_raise_NotImplementedError(NULL); + } + + if (!timeout) { + timeout = INT32_MAX; + } else if (timeout > INT32_MAX) { + mp_raise_bleio_BluetoothError( + translate("Maximum timeout length is %d seconds"), INT32_MAX / 1000); + } + + _common_hal_bleio_adapter_start_advertising(self, connectable, anonymous, + timeout, interval, + advertising_data_bufinfo->buf, + advertising_data_bufinfo->len, + scan_response_data_bufinfo->buf, + scan_response_data_bufinfo->len, + tx_power, + directed_to); +} + +// Stop advertising +void common_hal_bleio_adapter_stop_advertising(bleio_adapter_obj_t *self) { + if (!common_hal_bleio_adapter_get_advertising(self)) { + return; + } + sl_bt_advertiser_delete_set(self->advertising_handle); + sl_bt_advertiser_stop(0); + self->user_advertising = false; +} + +// Get status of advertising +bool common_hal_bleio_adapter_get_advertising(bleio_adapter_obj_t *self) { + return self->user_advertising; +} + +// Convert mac address of remote device to connect +STATIC void _convert_address(const bleio_address_obj_t *address, + bd_addr *sd_address, uint8_t *addr_type) { + mp_buffer_info_t address_buf_info; + *addr_type = address->type; + mp_get_buffer_raise(address->bytes, &address_buf_info, MP_BUFFER_READ); + memcpy(sd_address->addr, (uint8_t *)address_buf_info.buf, 6); +} + +// Add new connection into connection list +void _new_connection(uint16_t conn_handle) { + // Find an empty connection. One must always be available because the SD has the same + // total connection limit. + bleio_connection_internal_t *connection; + uint8_t conn_index; + for (conn_index = 0; conn_index < BLEIO_TOTAL_CONNECTION_COUNT; conn_index++) { + connection = &bleio_connections[conn_index]; + if (connection->conn_handle == BLEIO_HANDLE_INVALID) { + break; + } + } + connection->conn_handle = conn_handle; + connection->connection_obj = mp_const_none; + connection->pair_status = PAIR_NOT_PAIRED; + connection->mtu = 0; +} + +// Attempts a connection to the device with the given address. +mp_obj_t common_hal_bleio_adapter_connect(bleio_adapter_obj_t *self, + bleio_address_obj_t *address, + mp_float_t timeout) { + + bd_addr addr; + uint8_t address_type; + sl_status_t error_code; + uint8_t conn_handle; + uint8_t conn_index; + bleio_connection_internal_t *connection; + + if (self->scan_results != NULL) { + common_hal_bleio_adapter_stop_scan(self); + } + conn_handle = common_hal_bleio_adapter_get_connected(self); + timeout = MSEC_TO_UNITS(timeout, UNIT_10_MS); + + _convert_address(address, &addr, &address_type); + + error_code = sl_bt_connection_open(addr, + address_type, + sl_bt_gap_phy_1m, + &conn_handle); + + // Negative values are error codes, connection handle otherwise. + if (SL_STATUS_OK != error_code) { + return mp_const_none; + } + + _new_connection(conn_handle); + + // TODO: If we have keys, then try and encrypt the connection. + + // TODO: Negotiate for better PHY and data lengths since we are the central. These are + // nice-to-haves so ignore any errors. + + // Make the connection object and return it. + for (conn_index = 0; conn_index < BLEIO_TOTAL_CONNECTION_COUNT; conn_index++) { + connection = &bleio_connections[conn_index]; + if (connection->conn_handle == conn_handle) { + connection->is_central = true; + connection->pair_status = PAIR_PAIRED; + return bleio_connection_new_from_internal(connection); + } + } + + mp_raise_bleio_BluetoothError( + translate("Failed to connect: internal error")); + return mp_const_none; +} + +// Get connected status +bool common_hal_bleio_adapter_get_connected(bleio_adapter_obj_t *self) { + uint8_t conn_index; + bleio_connection_internal_t *connection; + for (conn_index = 0; conn_index < BLEIO_TOTAL_CONNECTION_COUNT; conn_index++) { + connection = &bleio_connections[conn_index]; + if (connection->conn_handle != BLEIO_HANDLE_INVALID) { + return true; + } + } + return false; +} + +// Get connection object +mp_obj_t common_hal_bleio_adapter_get_connections(bleio_adapter_obj_t *self) { + + size_t total_connected = 0; + mp_obj_t items[BLEIO_TOTAL_CONNECTION_COUNT]; + uint8_t conn_index; + bleio_connection_internal_t *connection; + + if (self->connection_objs != NULL) { + return self->connection_objs; + } + for (conn_index = 0; conn_index < BLEIO_TOTAL_CONNECTION_COUNT; conn_index++) { + connection = &bleio_connections[conn_index]; + if (connection->conn_handle != BLEIO_HANDLE_INVALID) { + if (connection->connection_obj == mp_const_none) { + connection->connection_obj = + bleio_connection_new_from_internal(connection); + } + items[total_connected] = connection->connection_obj; + total_connected++; + } + } + self->connection_objs = mp_obj_new_tuple(total_connected, items); + return self->connection_objs; +} + +void common_hal_bleio_adapter_remove_connection(uint8_t conn_handle) { + uint8_t conn_index; + bleio_connection_internal_t *connection; + osMutexAcquire(bluetooth_connection_mutex_id, osWaitForever); + for (conn_index = 0; conn_index < BLEIO_TOTAL_CONNECTION_COUNT; conn_index++) { + connection = &bleio_connections[conn_index]; + if (conn_handle == connection->conn_handle) { + connection->connection_obj = NULL; + connection->conn_handle = BLEIO_HANDLE_INVALID; + } + } + osMutexRelease(bluetooth_connection_mutex_id); +} + +// Delete all bonding +void common_hal_bleio_adapter_erase_bonding(bleio_adapter_obj_t *self) { + sl_status_t sc; + sc = sl_bt_sm_delete_bondings(); + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError(translate("All bonding deleted fail.")); + } +} + +// Get status bonding to central +bool common_hal_bleio_adapter_is_bonded_to_central(bleio_adapter_obj_t *self) { + bleio_connection_internal_t *connection; + uint8_t conn_index; + for (conn_index = 0; conn_index < BLEIO_TOTAL_CONNECTION_COUNT; conn_index++) { + connection = &bleio_connections[conn_index]; + if (connection->conn_handle != BLEIO_HANDLE_INVALID) { + return true; + } + } + return false; +} + +void bleio_adapter_gc_collect(bleio_adapter_obj_t *adapter) { + // We divide by size_t so that we can scan each 32-bit aligned value to see + // if it is a pointer. This allows us to change the structs without worrying + // about collecting new pointers. + gc_collect_root((void **)adapter, + sizeof(bleio_adapter_obj_t) / (sizeof(size_t))); + gc_collect_root((void **)bleio_connections, + sizeof(bleio_connections) / (sizeof(size_t))); +} + +// Reset the BLE adapter +void bleio_adapter_reset(bleio_adapter_obj_t *adapter) { + + bool any_connected = false; + uint64_t start_ticks; + uint8_t conn_index; + bleio_connection_internal_t *connection; + + common_hal_bleio_adapter_stop_scan(adapter); + if (common_hal_bleio_adapter_get_advertising(adapter)) { + common_hal_bleio_adapter_stop_advertising(adapter); + } + + adapter->connection_objs = NULL; + for (conn_index = 0; conn_index < BLEIO_TOTAL_CONNECTION_COUNT; conn_index++) { + connection = &bleio_connections[conn_index]; + // Disconnect all connections cleanly. + if (connection->conn_handle != BLEIO_HANDLE_INVALID) { + common_hal_bleio_connection_disconnect(connection); + } + connection->connection_obj = mp_const_none; + } + + // Wait up to 125 ms (128 ticks) for disconnect to complete. This should be + // greater than most connection intervals. + start_ticks = supervisor_ticks_ms64(); + while (any_connected && supervisor_ticks_ms64() - start_ticks < 128) { + any_connected = false; + for (conn_index = 0; conn_index < BLEIO_TOTAL_CONNECTION_COUNT; conn_index++) { + connection = &bleio_connections[conn_index]; + any_connected |= connection->conn_handle != BLEIO_HANDLE_INVALID; + } + } +} diff --git a/ports/silabs/common-hal/_bleio/Adapter.h b/ports/silabs/common-hal/_bleio/Adapter.h new file mode 100644 index 0000000000..d7f252df33 --- /dev/null +++ b/ports/silabs/common-hal/_bleio/Adapter.h @@ -0,0 +1,87 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR_COMMON_HAL_BLEIO_ADAPTER_H +#define MICROPY_INCLUDED_EFR_COMMON_HAL_BLEIO_ADAPTER_H + +#include "py/obj.h" +#include "py/objtuple.h" +#include "shared-bindings/_bleio/Connection.h" +#include "shared-bindings/_bleio/ScanResults.h" +#include "supervisor/background_callback.h" + +#ifndef BLEIO_TOTAL_CONNECTION_COUNT +#define BLEIO_TOTAL_CONNECTION_COUNT 5 +#endif + +#define BLEIO_HANDLE_INVALID 0xffff +#define BLE_GAP_ADDR_LEN 6 + +extern bleio_connection_internal_t + bleio_connections[BLEIO_TOTAL_CONNECTION_COUNT]; + +extern EventGroupHandle_t xscan_event; + +typedef struct { + mp_obj_base_t base; + bleio_scanresults_obj_t *scan_results; + mp_obj_t name; + mp_obj_tuple_t *connection_objs; + background_callback_t background_callback; + bool user_advertising; + bool is_enable; + uint8_t advertising_handle; +} bleio_adapter_obj_t; + +typedef struct { + uint8_t addr_id_peer : 1; + uint8_t addr_type : 7; + uint8_t addr[BLE_GAP_ADDR_LEN]; +} ble_gap_addr_t; + +typedef struct { + // Pointer to the data buffer provided to/from the application. + uint8_t *p_data; + // Length of the data buffer, in bytes. + uint16_t len; +} ble_data_t; + +typedef struct { + uint8_t address_type; + uint8_t conn_handle; + uint8_t data_len; + int8_t rssi; + bd_addr address; + uint8_t data[255]; +} device_scan_info_t; + +void set_scan_device_info_on_ble_evt(bd_addr address, uint8_t address_type, + int8_t rssi, uint8array *data); +void bleio_adapter_gc_collect(bleio_adapter_obj_t *adapter); +void bleio_adapter_reset(bleio_adapter_obj_t *adapter); +void common_hal_bleio_adapter_remove_connection(uint8_t conn_handle); + +#endif // MICROPY_INCLUDED_EFR_COMMON_HAL_BLEIO_ADAPTER_H diff --git a/ports/silabs/common-hal/_bleio/Attribute.c b/ports/silabs/common-hal/_bleio/Attribute.c new file mode 100644 index 0000000000..2e477a72ba --- /dev/null +++ b/ports/silabs/common-hal/_bleio/Attribute.c @@ -0,0 +1,27 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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/_bleio/Attribute.h" diff --git a/ports/silabs/common-hal/_bleio/Attribute.h b/ports/silabs/common-hal/_bleio/Attribute.h new file mode 100644 index 0000000000..b2a635005b --- /dev/null +++ b/ports/silabs/common-hal/_bleio/Attribute.h @@ -0,0 +1,32 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR_COMMON_HAL_BLEIO_ATTRIBUTE_H +#define MICROPY_INCLUDED_EFR_COMMON_HAL_BLEIO_ATTRIBUTE_H + +#include "shared-module/_bleio/Attribute.h" + +#endif // MICROPY_INCLUDED_EFR_COMMON_HAL_BLEIO_ATTRIBUTE_H diff --git a/ports/silabs/common-hal/_bleio/Characteristic.c b/ports/silabs/common-hal/_bleio/Characteristic.c new file mode 100644 index 0000000000..a39180b19b --- /dev/null +++ b/ports/silabs/common-hal/_bleio/Characteristic.c @@ -0,0 +1,407 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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 +#include "py/runtime.h" +#include "common-hal/_bleio/Adapter.h" +#include "shared-bindings/_bleio/Characteristic.h" +#include "shared-bindings/_bleio/Descriptor.h" +#include "shared-bindings/_bleio/Service.h" +#include "shared-bindings/_bleio/__init__.h" +#include "shared/runtime/interrupt_char.h" +#include "supervisor/shared/tick.h" +#include "supervisor/serial.h" + +EventGroupHandle_t xcharacteristic_event; + +// Set the characteristic data from sl_bt_on_event +bool set_characteristic_value_on_ble_evt(uint8_t conn_handle, + uint16_t char_handle, + uint8_t *data, + size_t data_len) { + + uint8_t serv_index; + uint8_t charc_index; + bleio_service_obj_t *service; + bleio_characteristic_obj_t *characteristic; + bleio_connection_internal_t *connection = + bleio_conn_handle_to_connection(conn_handle); + if (NULL == connection) { + mp_raise_bleio_BluetoothError(translate("Get connection fail.")); + return false; + } + for (serv_index = 0; serv_index < connection->remote_service_list->len; serv_index++) { + service = connection->remote_service_list->items[serv_index]; + + for (charc_index = 0; charc_index < service->characteristic_list->len; charc_index++) { + characteristic = service->characteristic_list->items[charc_index]; + + if (char_handle == characteristic->handle) { + characteristic->current_value = pvPortMalloc(data_len); + characteristic->current_value_len = data_len; + memcpy(characteristic->current_value, data, data_len); + + if (xcharacteristic_event != NULL) { + xEventGroupSetBits(xcharacteristic_event, 1 << 0); + } + return true; + } + } + } + return false; +} + +// Get the characteristic data object +STATIC bool get_characteristic_value(uint8_t conn_handle, + uint16_t char_handle, + uint8_t *data, + size_t *data_len) { + + uint8_t serv_index; + uint8_t charc_index; + bleio_service_obj_t *service; + bleio_characteristic_obj_t *characteristic; + bleio_connection_internal_t *connection = bleio_conn_handle_to_connection(conn_handle); + + if (NULL == connection) { + mp_raise_bleio_BluetoothError(translate("Get connection fail.")); + return false; + } + for (serv_index = 0; serv_index < connection->remote_service_list->len; serv_index++) { + service = connection->remote_service_list->items[serv_index]; + + for (charc_index = 0; charc_index < service->characteristic_list->len; charc_index++) { + characteristic = service->characteristic_list->items[charc_index]; + + if (char_handle == characteristic->handle) { + *data_len = characteristic->current_value_len; + memcpy(data, characteristic->current_value, *data_len); + vPortFree(characteristic->current_value); + return true; + } + } + } + return false; +} + +// Create new bleio characteristic +void common_hal_bleio_characteristic_construct( + bleio_characteristic_obj_t *self, + bleio_service_obj_t *service, + uint16_t handle, bleio_uuid_obj_t *uuid, + bleio_characteristic_properties_t props, + bleio_attribute_security_mode_t read_perm, + bleio_attribute_security_mode_t write_perm, + mp_int_t max_length, + bool fixed_length, + mp_buffer_info_t *initial_value_bufinfo, + const char *user_description) { + + self->service = service; + self->uuid = uuid; + self->handle = BLEIO_HANDLE_INVALID; + self->cccd_handle = BLEIO_HANDLE_INVALID; + self->sccd_handle = BLEIO_HANDLE_INVALID; + self->props = props; + self->read_perm = read_perm; + self->write_perm = write_perm; + self->max_length = max_length > MAX_LENGTH_DATA ? MAX_LENGTH_DATA : max_length; + self->max_length = self->max_length ? self->max_length : MAX_LENGTH_DATA; + self->fixed_length = fixed_length; + + if (gc_alloc_possible()) { + self->descriptor_list = mp_obj_new_list(0, NULL); + } else { + self->descriptor_list = NULL; + } + + if (service->is_remote) { + self->handle = handle; + } else { + common_hal_bleio_service_add_characteristic(self->service, + self, + initial_value_bufinfo, + user_description); + + sl_bt_gatt_server_write_attribute_value( + self->handle, + 0, + initial_value_bufinfo->len, + (uint8_t *)initial_value_bufinfo->buf); + } +} + +// A tuple of Descriptor that describe this characteristic +mp_obj_tuple_t *common_hal_bleio_characteristic_get_descriptors( + bleio_characteristic_obj_t *self) { + + if (self->descriptor_list == NULL) { + return mp_const_empty_tuple; + } + return mp_obj_new_tuple(self->descriptor_list->len, + self->descriptor_list->items); +} + +// The Service this Characteristic is a part of +bleio_service_obj_t *common_hal_bleio_characteristic_get_service( + bleio_characteristic_obj_t *self) { + + return self->service; +} + +// Get value of characteristic +size_t common_hal_bleio_characteristic_get_value( + bleio_characteristic_obj_t *self, + uint8_t *buf, + size_t len) { + + sl_status_t sc = SL_STATUS_FAIL; + EventBits_t ux_bits; + uint8_t retry = 10; + uint64_t start_ticks = supervisor_ticks_ms64(); + uint64_t current_ticks = start_ticks; + + if (self->handle == BLEIO_HANDLE_INVALID) { + return 0; + } + uint16_t conn_handle = bleio_connection_get_conn_handle(self->service->connection); + + if (common_hal_bleio_service_get_is_remote(self->service)) { + // ble client gets characteristic value + if (BT_GATT_CHRC_READ & self->props) { + sc = sl_bt_gatt_read_characteristic_value(conn_handle,self->handle); + while (SL_STATUS_OK != sc && retry > 0) { + sc = sl_bt_gatt_read_characteristic_value(conn_handle,self->handle); + vTaskDelay(100 / portTICK_PERIOD_MS); + retry--; + } + } + + xcharacteristic_event = xEventGroupCreate(); + if (xcharacteristic_event != NULL) { + xEventGroupClearBits(xcharacteristic_event, 1 << 0); + } + + while (current_ticks - start_ticks <= GET_CHARACTERISTIC_TIMEOUT_MS) { + if (xcharacteristic_event != NULL) { + ux_bits = xEventGroupWaitBits( + xcharacteristic_event, 1 << 0, pdTRUE, pdFALSE, + GET_CHARACTERISTIC_TIMEOUT_MS / portTICK_PERIOD_MS); + + if ((ux_bits & (1 << 0)) == (1 << 0)) { + break; + } + } + current_ticks = supervisor_ticks_ms64(); + // Allow user to break out of a timeout with a KeyboardInterrupt. + if (mp_hal_is_interrupted()) { + break; + } + } + get_characteristic_value(conn_handle, self->handle, buf, &len); + vEventGroupDelete(xcharacteristic_event); + return len; + + } else { + sc = sl_bt_gatt_server_read_attribute_value(self->handle, + 0, + self->max_length, + &len, + (uint8_t *)buf); + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError( + translate("Read_attribute_value fail!")); + } + return len; + } + + return 0; +} + +// Get max length of charateristic +size_t common_hal_bleio_characteristic_get_max_length( + bleio_characteristic_obj_t *self) { + return self->max_length; +} + +// Set value of this characteristic +void common_hal_bleio_characteristic_set_value(bleio_characteristic_obj_t *self, + mp_buffer_info_t *bufinfo) { + + sl_status_t sc = SL_STATUS_FAIL; + uint16_t conn_handle; + uint16_t sent_len; + + if (common_hal_bleio_service_get_is_remote(self->service)) { + + conn_handle = bleio_connection_get_conn_handle(self->service->connection); + if ((self->props & CHAR_PROP_WRITE_NO_RESPONSE) != 0) { + sc = sl_bt_gatt_write_characteristic_value_without_response( + conn_handle, + self->handle, + bufinfo->len, + bufinfo->buf, + &sent_len); + } else { + sc = sl_bt_gatt_write_characteristic_value(conn_handle, + self->handle, + bufinfo->len, + bufinfo->buf); + } + } else { + if (self->props & BT_GATT_CHRC_READ) { + sc = sl_bt_gatt_server_write_attribute_value(self->handle, + 0, + bufinfo->len, + (uint8_t *)bufinfo->buf); + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError( + translate("Write_attribute_value fail!")); + } + } + + if (self->props & BT_GATT_CHRC_NOTIFY) { + sc = sl_bt_gatt_server_send_notification( + 1, + self->handle, + bufinfo->len, + (uint8_t *)bufinfo->buf); + } + + if (self->props & BT_GATT_CHRC_INDICATE) { + sc = sl_bt_gatt_server_send_indication( + 1, + self->handle, + bufinfo->len, + (uint8_t *)bufinfo->buf); + } + } +} + +// Get UUID of this characteristic +bleio_uuid_obj_t *common_hal_bleio_characteristic_get_uuid( + bleio_characteristic_obj_t *self) { + return self->uuid; +} + +// Get properties of this characteristic +bleio_characteristic_properties_t common_hal_bleio_characteristic_get_properties( + bleio_characteristic_obj_t *self) { + return self->props; +} + +// Add new descriptor to characteristic +void common_hal_bleio_characteristic_add_descriptor( + bleio_characteristic_obj_t *self, + bleio_descriptor_obj_t *descriptor) { + + sl_status_t sc = SL_STATUS_FAIL; + const uint8_t value; + uuid_128 bt_uuid_128; + sl_bt_uuid_16_t bt_uuid_16; + uint16_t gattdb_session; + + sc = sl_bt_gattdb_new_session(&gattdb_session); + + if (SL_STATUS_OK != sc && SL_STATUS_ALREADY_EXISTS != sc) { + mp_raise_bleio_BluetoothError(translate("Create new session fail.")); + return; + } + + if (BLE_UUID_TYPE_16 == descriptor->uuid->efr_ble_uuid.uuid.type) { + bt_uuid_16.data[0] = descriptor->uuid->efr_ble_uuid.uuid16.value & 0xff; + bt_uuid_16.data[1] = descriptor->uuid->efr_ble_uuid.uuid16.value >> 8; + + sl_bt_gattdb_add_uuid16_descriptor(self->session, + self->handle, + descriptor->handle, + 0, + bt_uuid_16, + sl_bt_gattdb_user_managed_value, + descriptor->max_length, + 2, + &value, + &descriptor->handle); + } else { + memcpy(bt_uuid_128.data, descriptor->uuid->efr_ble_uuid.uuid128.value, 16); + sl_bt_gattdb_add_uuid128_descriptor(self->session, + self->handle, + descriptor->handle, + 0, + bt_uuid_128, + sl_bt_gattdb_user_managed_value, + descriptor->max_length, + 2, + &value, + &descriptor->handle); + } + + sc = sl_bt_gattdb_commit(gattdb_session); + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError(translate("Commit descriptor fail.")); + return; + } + + mp_obj_list_append(MP_OBJ_FROM_PTR(self->descriptor_list), + MP_OBJ_FROM_PTR(descriptor)); +} + +// Set the remote characteristic’s CCCD to enable or disable notification and indication. +void common_hal_bleio_characteristic_set_cccd(bleio_characteristic_obj_t *self, + bool notify,bool indicate) { + + sl_status_t sc = SL_STATUS_FAIL; + + const uint16_t conn_handle = bleio_connection_get_conn_handle( + self->service->connection); + common_hal_bleio_check_connected(conn_handle); + notify = 1; + indicate = 0; + if (notify) { + sc = sl_bt_gatt_set_characteristic_notification(conn_handle, + self->handle,sl_bt_gatt_notification); + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError(translate("Notify fail")); + } + } + + if (indicate) { + sc = sl_bt_gatt_set_characteristic_notification(conn_handle, + self->handle,sl_bt_gatt_indication); + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError(translate("Indicate fail")); + } + } + + if (0 == notify && 0 == indicate) { + sc = sl_bt_gatt_set_characteristic_notification(conn_handle, + self->handle,sl_bt_gatt_disable); + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError(translate("Indicate fail")); + } + } +} diff --git a/ports/silabs/common-hal/_bleio/Characteristic.h b/ports/silabs/common-hal/_bleio/Characteristic.h new file mode 100644 index 0000000000..9605988b68 --- /dev/null +++ b/ports/silabs/common-hal/_bleio/Characteristic.h @@ -0,0 +1,68 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR_COMMON_HAL_BLEIO_CHARACTERISTIC_H +#define MICROPY_INCLUDED_EFR_COMMON_HAL_BLEIO_CHARACTERISTIC_H + +#include "shared-bindings/_bleio/Attribute.h" +#include "common-hal/_bleio/Descriptor.h" +#include "shared-module/_bleio/Characteristic.h" +#include "common-hal/_bleio/Service.h" +#include "common-hal/_bleio/UUID.h" + +#define MAX_LENGTH_DATA 512 +#define GET_CHARACTERISTIC_TIMEOUT_MS 1000 + +typedef struct _bleio_characteristic_obj { + mp_obj_base_t base; + // Will be MP_OBJ_NULL before being assigned to a Service. + bleio_service_obj_t *service; + bleio_uuid_obj_t *uuid; + uint8_t *current_value; + uint16_t current_value_len; + // Our internal allocation length. If > 0, then current_value is managed by + // this characteristic. + uint16_t current_value_alloc; + uint16_t max_length; + uint16_t def_handle; + uint16_t handle; + uint16_t session; + bleio_characteristic_properties_t props; + bleio_attribute_security_mode_t read_perm; + bleio_attribute_security_mode_t write_perm; + mp_obj_list_t *descriptor_list; + uint16_t user_desc_handle; + uint16_t cccd_handle; + uint16_t sccd_handle; + bool fixed_length; +} bleio_characteristic_obj_t; + +bool set_characteristic_value_on_ble_evt(uint8_t conn_handle, + uint16_t char_handle, + uint8_t *data, + size_t data_len); + +#endif // MICROPY_INCLUDED_EFR_COMMON_HAL_BLEIO_CHARACTERISTIC_H diff --git a/ports/silabs/common-hal/_bleio/CharacteristicBuffer.c b/ports/silabs/common-hal/_bleio/CharacteristicBuffer.c new file mode 100644 index 0000000000..653de697cd --- /dev/null +++ b/ports/silabs/common-hal/_bleio/CharacteristicBuffer.c @@ -0,0 +1,164 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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 +#include "py/ringbuf.h" +#include "py/runtime.h" +#include "py/stream.h" +#include "shared-bindings/_bleio/__init__.h" +#include "shared-bindings/_bleio/Connection.h" +#include "shared-bindings/_bleio/CharacteristicBuffer.h" +#include "common-hal/_bleio/CharacteristicBuffer.h" +#include "shared/runtime/interrupt_char.h" +#include "supervisor/shared/tick.h" + +// Characteristic buffer list of peripheral device +bleio_characteristic_buffer_obj_list_t bleio_characteristic_buffer_list; + +bool characteristic_buffer_on_ble_evt(uint16_t attribute, + uint8_t *data, + uint16_t len) { + + uint16_t cindex = 0; + for (cindex = 0; cindex < bleio_characteristic_buffer_list.len; cindex++) { + if (bleio_characteristic_buffer_list.data[cindex] != NULL && + bleio_characteristic_buffer_list.data[cindex]->characteristic->handle == attribute) { + taskENTER_CRITICAL(); + if (bleio_characteristic_buffer_list.data[cindex]->watch_for_interrupt_char) { + for (uint16_t i = 0; i < len; i++) { + if (data[i] == mp_interrupt_char) { + mp_sched_keyboard_interrupt(); + } else { + ringbuf_put(&bleio_characteristic_buffer_list.data[cindex]->ringbuf, data[i]); + } + } + } else { + ringbuf_put_n(&bleio_characteristic_buffer_list.data[cindex]->ringbuf,data, len); + } + taskEXIT_CRITICAL(); + + return true; + } + } + return false; +} + +void _common_hal_bleio_characteristic_buffer_construct( + bleio_characteristic_buffer_obj_t *self, + bleio_characteristic_obj_t *characteristic, + mp_float_t timeout, + uint8_t *buffer, size_t buffer_size, + void *static_handler_entry, + bool watch_for_interrupt_char) { + + self->characteristic = characteristic; + self->timeout_ms = timeout * 1000; + self->watch_for_interrupt_char = watch_for_interrupt_char; + ringbuf_init(&self->ringbuf, buffer, buffer_size); +} + +void common_hal_bleio_characteristic_buffer_construct( + bleio_characteristic_buffer_obj_t *self, + bleio_characteristic_obj_t *characteristic, + mp_float_t timeout, + size_t buffer_size) { + + uint8_t *buffer = m_malloc(buffer_size, true); + _common_hal_bleio_characteristic_buffer_construct(self, + characteristic, + timeout, + buffer, + buffer_size, + NULL, + false); + + bleio_characteristic_buffer_list.data[bleio_characteristic_buffer_list.len] = self; + bleio_characteristic_buffer_list.len++; +} + +uint32_t common_hal_bleio_characteristic_buffer_read( + bleio_characteristic_buffer_obj_t *self, + uint8_t *data, + size_t len, + int *errcode) { + + uint64_t start_ticks = supervisor_ticks_ms64(); + // Wait for all bytes received or timeout + while ((ringbuf_num_filled(&self->ringbuf) < len) && + (supervisor_ticks_ms64() - start_ticks < self->timeout_ms)) { + RUN_BACKGROUND_TASKS; + // Allow user to break out of a timeout with a KeyboardInterrupt. + if (mp_hal_is_interrupted()) { + return 0; + } + } + taskENTER_CRITICAL(); + uint32_t num_bytes_read = ringbuf_get_n(&self->ringbuf, data, len); + taskEXIT_CRITICAL(); + + return num_bytes_read; +} + +uint32_t common_hal_bleio_characteristic_buffer_rx_characters_available( + bleio_characteristic_buffer_obj_t *self) { + return ringbuf_num_filled(&self->ringbuf); +} + +void common_hal_bleio_characteristic_buffer_clear_rx_buffer( + bleio_characteristic_buffer_obj_t *self) { + taskENTER_CRITICAL(); + ringbuf_clear(&self->ringbuf); + taskEXIT_CRITICAL(); +} + +bool common_hal_bleio_characteristic_buffer_deinited( + bleio_characteristic_buffer_obj_t *self) { + return self->characteristic == NULL; +} + +void common_hal_bleio_characteristic_buffer_deinit(bleio_characteristic_buffer_obj_t *self) { + if (!common_hal_bleio_characteristic_buffer_deinited(self)) { + self->characteristic = NULL; + ringbuf_deinit(&self->ringbuf); + } +} + +bool common_hal_bleio_characteristic_buffer_connected( + bleio_characteristic_buffer_obj_t *self) { + return self->characteristic != NULL && + self->characteristic->service != NULL && + (!self->characteristic->service->is_remote || + (self->characteristic->service->connection != MP_OBJ_NULL && + common_hal_bleio_connection_get_connected(self->characteristic->service->connection))); +} + +void reset_characteristic_buffer_list() { + // Remove characteristic_buffer list + memset(bleio_characteristic_buffer_list.data, 0, + sizeof(bleio_characteristic_buffer_list.data)); + bleio_characteristic_buffer_list.len = 0; +} diff --git a/ports/silabs/common-hal/_bleio/CharacteristicBuffer.h b/ports/silabs/common-hal/_bleio/CharacteristicBuffer.h new file mode 100644 index 0000000000..6acb52e790 --- /dev/null +++ b/ports/silabs/common-hal/_bleio/CharacteristicBuffer.h @@ -0,0 +1,55 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR_COMMON_HAL_BLEIO_CHARACTERISTICBUFFER_H +#define MICROPY_INCLUDED_EFR_COMMON_HAL_BLEIO_CHARACTERISTICBUFFER_H + +#include "py/ringbuf.h" +#include "shared-bindings/_bleio/Characteristic.h" + +#define MAX_NUMBER_CHARACTERISTIC_BUFFER 64 +#define GET_CHARACTERISTIC_TIMEOUT_MS 1000 +typedef struct { + mp_obj_base_t base; + bleio_characteristic_obj_t *characteristic; + uint32_t timeout_ms; + // Ring buffer storing consecutive incoming values + ringbuf_t ringbuf; + bool watch_for_interrupt_char; +} bleio_characteristic_buffer_obj_t; + +typedef struct +{ + bleio_characteristic_buffer_obj_t *data[MAX_NUMBER_CHARACTERISTIC_BUFFER]; + uint8_t len; +} bleio_characteristic_buffer_obj_list_t; + +extern bleio_characteristic_buffer_obj_list_t bleio_characteristic_buffer_list; +extern bool characteristic_buffer_on_ble_evt(uint16_t attribute, + uint8_t *data, + uint16_t len); +extern void reset_characteristic_buffer_list(); +#endif // MICROPY_INCLUDED_EFR_COMMON_HAL_BLEIO_CHARACTERISTICBUFFER_H diff --git a/ports/silabs/common-hal/_bleio/Connection.c b/ports/silabs/common-hal/_bleio/Connection.c new file mode 100644 index 0000000000..ad3f6db198 --- /dev/null +++ b/ports/silabs/common-hal/_bleio/Connection.c @@ -0,0 +1,274 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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 +#include "py/gc.h" +#include "py/objlist.h" +#include "py/objstr.h" +#include "py/qstr.h" +#include "py/runtime.h" + +#include "shared-bindings/_bleio/Connection.h" +#include "shared-bindings/_bleio/Adapter.h" +#include "shared-bindings/_bleio/Attribute.h" +#include "shared-bindings/_bleio/Characteristic.h" +#include "shared-bindings/_bleio/Service.h" +#include "shared-bindings/_bleio/UUID.h" +#include "shared-bindings/_bleio/__init__.h" +#include "shared-module/_bleio/Characteristic.h" +#include "shared/runtime/interrupt_char.h" +#include "supervisor/shared/tick.h" +#include "supervisor/serial.h" + +// Give 10 seconds for discovery +#define DISCOVERY_TIMEOUT_MS 10000 +EventGroupHandle_t xdiscovery_event; + +// Get the remote peer status +bool common_hal_bleio_connection_get_paired(bleio_connection_obj_t *self) { + if (self->connection == NULL) { + return false; + } + + return self->connection->pair_status == PAIR_PAIRED; +} + +// Get connected status +bool common_hal_bleio_connection_get_connected(bleio_connection_obj_t *self) { + if (self->connection == NULL) { + return false; + } + return self->connection->conn_handle != BLEIO_HANDLE_INVALID; +} + +// Disconnects from the remote peripheral +void common_hal_bleio_connection_disconnect(bleio_connection_internal_t *self) { + sl_bt_connection_close(self->conn_handle); +} + +// Pair to the peer to improve security +void common_hal_bleio_connection_pair(bleio_connection_internal_t *self, + bool bond) { + + while (self->pair_status == PAIR_WAITING && !mp_hal_is_interrupted()) { + RUN_BACKGROUND_TASKS; + } + if (self->pair_status == PAIR_PAIRED) { + return; + } + self->pair_status = PAIR_WAITING; + + while (self->pair_status == PAIR_WAITING && !mp_hal_is_interrupted()) { + RUN_BACKGROUND_TASKS; + } + if (mp_hal_is_interrupted()) { + return; + } +} + +// Get time between transmissions in milliseconds +mp_float_t common_hal_bleio_connection_get_connection_interval( + bleio_connection_internal_t *self) { + // TODO: Implement this. + return 0; +} + +// The maximum number of data bytes that can be sent in a single transmission +mp_int_t common_hal_bleio_connection_get_max_packet_length( + bleio_connection_internal_t *self) { + + sl_status_t sc = sl_bt_gatt_server_get_mtu(self->conn_handle,&self->mtu); + if (sc != SL_STATUS_OK) { + mp_raise_bleio_BluetoothError(translate("gatt_server_get_mtu fail.")); + } + + return self->mtu; +} + +// Set time between transmissions in milliseconds +void common_hal_bleio_connection_set_connection_interval( + bleio_connection_internal_t *self, + mp_float_t new_interval) { + self->conn_params_updating = true; + // TODO: Implement this. +} + +// Do BLE discovery for all services +mp_obj_tuple_t *common_hal_bleio_connection_discover_remote_services( + bleio_connection_obj_t *self, + mp_obj_t service_uuids_whitelist) { + + EventBits_t ux_bits; + mp_obj_iter_buf_t iter_buf; + mp_obj_t iterable; + mp_obj_t uuid_obj; + mp_obj_tuple_t *services_tuple; + sl_status_t sc = SL_STATUS_FAIL; + bleio_uuid_obj_t *uuid; + uint8_t uuid16_value[2]; + + uint64_t start_ticks = supervisor_ticks_ms64(); + uint64_t current_ticks = start_ticks; + + xdiscovery_event = xEventGroupCreate(); + if (xdiscovery_event != NULL) { + xEventGroupClearBits(xdiscovery_event,1 << 0); + } + self->connection->remote_service_list = mp_obj_new_list(0, NULL); + bleio_connection_ensure_connected(self); + if (NULL == self->connection->remote_service_list) { + mp_raise_bleio_BluetoothError( + translate("Create new remote service list fail.")); + return mp_const_none; + } + vTaskDelay(500 / portTICK_PERIOD_MS); + + if (service_uuids_whitelist == mp_const_none) { + + sc = sl_bt_gatt_discover_primary_services(self->connection->conn_handle); + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError(translate("Discover uuid fail.")); + return mp_const_none; + } + + while (current_ticks - start_ticks <= DISCOVERY_TIMEOUT_MS) { + + if (xdiscovery_event != NULL) { + ux_bits = xEventGroupWaitBits( + xdiscovery_event, + 1 << 0, + pdTRUE,pdFALSE, + DISCOVERY_TIMEOUT_MS / portTICK_PERIOD_MS); + + if ((ux_bits & (1 << 0)) == (1 << 0)) { + break; + } + } + current_ticks = supervisor_ticks_ms64(); + // Allow user to break out of a timeout with a KeyboardInterrupt. + if (mp_hal_is_interrupted()) { + break; + } + } + + } else { + + iterable = mp_getiter(service_uuids_whitelist, &iter_buf); + while ((uuid_obj = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { + if (!mp_obj_is_type(uuid_obj, &bleio_uuid_type)) { + mp_raise_TypeError( + translate("non-UUID found in service_uuids_whitelist")); + } + uuid = MP_OBJ_TO_PTR(uuid_obj); + + if (BLE_UUID_TYPE_16 == uuid->efr_ble_uuid.uuid.type) { + uuid16_value[0] = uuid->efr_ble_uuid.uuid16.value & 0xff; + uuid16_value[1] = uuid->efr_ble_uuid.uuid16.value >> 8; + sc = sl_bt_gatt_discover_primary_services_by_uuid( + self->connection->conn_handle,2,uuid16_value); + + } else if (BLE_UUID_TYPE_128 == uuid->efr_ble_uuid.uuid.type) { + sc = sl_bt_gatt_discover_primary_services_by_uuid( + self->connection->conn_handle, + 16, + uuid->efr_ble_uuid.uuid128.value); + } + + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError(translate("Discover fail.")); + return mp_const_none; + } + + while (current_ticks - start_ticks <= DISCOVERY_TIMEOUT_MS) { + + if (xdiscovery_event != NULL) { + ux_bits = xEventGroupWaitBits( + xdiscovery_event, + 1 << 0, + pdTRUE, + pdFALSE, + DISCOVERY_TIMEOUT_MS / portTICK_PERIOD_MS); + + if ((ux_bits & (1 << 0)) == (1 << 0)) { + break; + } + } + current_ticks = supervisor_ticks_ms64(); + if (mp_hal_is_interrupted()) { + break; + } + } + } + } + + vEventGroupDelete(xdiscovery_event); + services_tuple = mp_obj_new_tuple(self->connection->remote_service_list->len, + self->connection->remote_service_list->items); + + if (NULL == services_tuple) { + mp_raise_ValueError(translate("Create new service tuple fail.")); + return mp_const_none; + } + return services_tuple; +} + +// Get connection handle +uint16_t bleio_connection_get_conn_handle(bleio_connection_obj_t *self) { + if (self == NULL || self->connection == NULL) { + return BLEIO_HANDLE_INVALID; + } + return self->connection->conn_handle; +} + +mp_obj_t bleio_connection_new_from_internal( + bleio_connection_internal_t *internal) { + + bleio_connection_obj_t *connection; + if (internal->connection_obj != mp_const_none) { + return internal->connection_obj; + } + connection = m_new_obj(bleio_connection_obj_t); + connection->base.type = &bleio_connection_type; + connection->connection = internal; + internal->connection_obj = connection; + + return MP_OBJ_FROM_PTR(connection); +} + +// Get internal connection object by handle connection +bleio_connection_internal_t *bleio_conn_handle_to_connection( + uint16_t conn_handle) { + bleio_connection_internal_t *connection; + uint8_t conn_index; + for (conn_index = 0; conn_index < BLEIO_TOTAL_CONNECTION_COUNT; conn_index++) { + connection = &bleio_connections[conn_index]; + if (connection->conn_handle == conn_handle) { + return connection; + } + } + return NULL; +} diff --git a/ports/silabs/common-hal/_bleio/Connection.h b/ports/silabs/common-hal/_bleio/Connection.h new file mode 100644 index 0000000000..56872024c9 --- /dev/null +++ b/ports/silabs/common-hal/_bleio/Connection.h @@ -0,0 +1,96 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR_COMMON_HAL_BLEIO_CONNECTION_H +#define MICROPY_INCLUDED_EFR_COMMON_HAL_BLEIO_CONNECTION_H + +#include + +#include "common-hal/_bleio/__init__.h" +#include "py/obj.h" +#include "py/objlist.h" +#include "common-hal/_bleio/Service.h" +#include "shared-module/_bleio/Address.h" +#include "FreeRTOS.h" +#include "event_groups.h" + +typedef enum { + PAIR_NOT_PAIRED, + PAIR_WAITING, + PAIR_PAIRED, +} pair_status_t; + +// We split the Connection object into two so that +// the internal mechanics can live outside of theVM. +// If it were one object, then we'd risk user code seeing +// a connection object of theirs be reused. +typedef struct +{ + uint16_t conn_handle; + bool is_central; + // Remote services discovered when this peripheral is acting as a client. + mp_obj_list_t *remote_service_list; + // The advertising data and scan response buffers are held by us, + // not by the SD, so we must maintain them and not change it. + // If we need to change the contents during advertising, + // there are tricks to get the SD to notice (see DevZone - TBS). + // bonding_keys_t bonding_keys; + // EDIV: Encrypted Diversifier: Identifies LTK during legacy pairing. + uint16_t ediv; + volatile pair_status_t pair_status; + uint8_t sec_status; // Internal security status. + mp_obj_t connection_obj; + volatile bool conn_params_updating; + uint16_t mtu; + // Request that CCCD values for this connection be saved, + // using sys_attr values. + volatile bool do_bond_cccds; + // Request that security key info for this connection be saved. + volatile bool do_bond_keys; + // Time of setting do_bond_ccds: we delay a bit to consolidate + // multiple CCCD changes into one write. Time is currently in ticks_ms. + uint64_t do_bond_cccds_request_time; +} bleio_connection_internal_t; + +typedef struct +{ + mp_obj_base_t base; + bleio_connection_internal_t *connection; + // The HCI disconnect reason. + uint8_t disconnect_reason; +} bleio_connection_obj_t; + +void bleio_connection_clear(bleio_connection_internal_t *self); + +uint16_t bleio_connection_get_conn_handle(bleio_connection_obj_t *self); + +mp_obj_t bleio_connection_new_from_internal( + bleio_connection_internal_t *connection); + +bleio_connection_internal_t *bleio_conn_handle_to_connection( + uint16_t conn_handle); +extern EventGroupHandle_t xdiscovery_event; +#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_BLEIO_CONNECTION_H diff --git a/ports/silabs/common-hal/_bleio/Descriptor.c b/ports/silabs/common-hal/_bleio/Descriptor.c new file mode 100644 index 0000000000..6a40f1f859 --- /dev/null +++ b/ports/silabs/common-hal/_bleio/Descriptor.c @@ -0,0 +1,114 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "py/runtime.h" +#include "shared-bindings/_bleio/__init__.h" +#include "shared-bindings/_bleio/Descriptor.h" +#include "shared-bindings/_bleio/Service.h" +#include "shared-bindings/_bleio/UUID.h" + +void common_hal_bleio_descriptor_construct( + bleio_descriptor_obj_t *self, + bleio_characteristic_obj_t *characteristic, + bleio_uuid_obj_t *uuid, + bleio_attribute_security_mode_t read_perm, + bleio_attribute_security_mode_t write_perm, + mp_int_t max_length, bool fixed_length, + mp_buffer_info_t *initial_value_bufinfo) { + + const mp_int_t max_length_max = BLE_ATT_ATTR_MAX_LEN; + self->uuid = uuid; + self->handle = BLEIO_HANDLE_INVALID; + self->read_perm = read_perm; + self->write_perm = write_perm; + self->initial_value = mp_obj_new_bytes(initial_value_bufinfo->buf, + initial_value_bufinfo->len); + + if (max_length < 0 || max_length > max_length_max) { + mp_raise_ValueError_varg( + translate("max_length must be 0-%d when fixed_length is %s"), + max_length_max, fixed_length ? "True" : "False"); + } + self->max_length = max_length; + self->fixed_length = fixed_length; +} + +// Get descriptor uuid +bleio_uuid_obj_t *common_hal_bleio_descriptor_get_uuid( + bleio_descriptor_obj_t *self) { + return self->uuid; +} + +bleio_characteristic_obj_t *common_hal_bleio_descriptor_get_characteristic( + bleio_descriptor_obj_t *self) { + return self->characteristic; +} + +size_t common_hal_bleio_descriptor_get_value(bleio_descriptor_obj_t *self, + uint8_t *buf, size_t len) { + + uint16_t conn_handle; + if (self->handle != BLE_GATT_HANDLE_INVALID) { + conn_handle = bleio_connection_get_conn_handle( + self->characteristic->service->connection); + if (common_hal_bleio_service_get_is_remote( + self->characteristic->service)) { + + sl_bt_gatt_read_descriptor_value(conn_handle, self->handle); + } + } + + return 0; +} + +// Set value to descriptor +void common_hal_bleio_descriptor_set_value(bleio_descriptor_obj_t *self, + mp_buffer_info_t *bufinfo) { + + uint16_t conn_handle; + if (self->handle != BLE_GATT_HANDLE_INVALID) { + conn_handle = bleio_connection_get_conn_handle( + self->characteristic->service->connection); + if (common_hal_bleio_service_get_is_remote( + self->characteristic->service)) { + + // false means WRITE_REQ, not write-no-response + sl_bt_gatt_write_descriptor_value(conn_handle, + self->handle, + bufinfo->len, + bufinfo->buf); + } else { + // Validate data length for local descriptors only. + if (self->fixed_length && bufinfo->len != self->max_length) { + mp_raise_ValueError( + translate("Value length != required fixed length")); + } + if (bufinfo->len > self->max_length) { + mp_raise_ValueError(translate("Value length > max_length")); + } + } + } +} diff --git a/ports/silabs/common-hal/_bleio/Descriptor.h b/ports/silabs/common-hal/_bleio/Descriptor.h new file mode 100644 index 0000000000..b71cac2b68 --- /dev/null +++ b/ports/silabs/common-hal/_bleio/Descriptor.h @@ -0,0 +1,53 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR_COMMON_HAL_BLEIO_DESCRIPTOR_H +#define MICROPY_INCLUDED_EFR_COMMON_HAL_BLEIO_DESCRIPTOR_H + +#include "py/obj.h" +#include "common-hal/_bleio/UUID.h" +#include "shared-module/_bleio/Attribute.h" + +#define BLE_ATT_ATTR_MAX_LEN 50 + +// Forward declare characteristic because it includes a Descriptor. +struct _bleio_characteristic_obj; + +typedef struct _bleio_descriptor_obj { + mp_obj_base_t base; + // Will be MP_OBJ_NULL before being assigned to a Characteristic. + struct _bleio_characteristic_obj *characteristic; + bleio_uuid_obj_t *uuid; + mp_obj_t initial_value; + uint16_t max_length; + bool fixed_length; + uint16_t handle; + // struct ble_gatt_dsc_def def; + bleio_attribute_security_mode_t read_perm; + bleio_attribute_security_mode_t write_perm; +} bleio_descriptor_obj_t; + +#endif // MICROPY_INCLUDED_EFR_COMMON_HAL_BLEIO_DESCRIPTOR_H diff --git a/ports/silabs/common-hal/_bleio/PacketBuffer.c b/ports/silabs/common-hal/_bleio/PacketBuffer.c new file mode 100644 index 0000000000..dd74e17099 --- /dev/null +++ b/ports/silabs/common-hal/_bleio/PacketBuffer.c @@ -0,0 +1,399 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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 +#include "py/runtime.h" +#include "py/stream.h" +#include "shared-bindings/_bleio/__init__.h" +#include "shared-bindings/_bleio/Service.h" +#include "shared-bindings/_bleio/Connection.h" +#include "shared-bindings/_bleio/PacketBuffer.h" +#include "shared/runtime/interrupt_char.h" +#include "common-hal/_bleio/Connection.h" +#include "supervisor/shared/tick.h" +#include "supervisor/serial.h" + +// List packet buffer of peripheral device +bleio_packet_buffer_obj_list_t bleio_packet_buffer_list; + +// Write data to ringbuf of packet buffer +STATIC void write_to_ringbuf(bleio_packet_buffer_obj_t *self, + uint8_t *data, + uint16_t len) { + + uint16_t packet_length; + uint16_t packet_index; + if (len + sizeof(uint16_t) > ringbuf_size(&self->ringbuf)) { + // This shouldn't happen but can if our buffer size was much smaller than + // the writes the client actually makes. + return; + } + + taskENTER_CRITICAL(); + // Push all the data onto the ring buffer. + // Make room for the new value by dropping the oldest packets first. + while (ringbuf_size(&self->ringbuf) - ringbuf_num_filled(&self->ringbuf) < len + sizeof(uint16_t)) { + ringbuf_get_n(&self->ringbuf, + (uint8_t *)&packet_length, sizeof(uint16_t)); + + for (packet_index = 0; packet_index < packet_length; packet_index++) { + ringbuf_get(&self->ringbuf); + } + } + ringbuf_put_n(&self->ringbuf, (uint8_t *)&len, sizeof(uint16_t)); + ringbuf_put_n(&self->ringbuf, data, len); + taskEXIT_CRITICAL(); +} + +// Write characteristic or attribute value +STATIC int queue_next_write(bleio_packet_buffer_obj_t *self) { + self->packet_queued = false; + + uint32_t sc = SL_STATUS_OK; + if (self->pending_size > 0) { + if (self->client) { + if (self->write_type & BT_GATT_CHRC_WRITE_WITHOUT_RESP) { + uint16_t sent_len; + sc = sl_bt_gatt_write_characteristic_value_without_response( + self->conn_handle, self->characteristic->handle, + self->pending_size, + (uint8_t *)self->outgoing[self->pending_index], + &sent_len); + } else { + sc = sl_bt_gatt_write_characteristic_value( + self->conn_handle, self->characteristic->handle, + self->pending_size, + (uint8_t *)self->outgoing[self->pending_index]); + } + + } else { + if (self->write_type & BT_GATT_CHRC_READ) { + sc = sl_bt_gatt_server_write_attribute_value(self->characteristic->handle, + 0, + self->pending_size, + (uint8_t *)self->outgoing[self->pending_index]); + } + + if (self->write_type & BT_GATT_CHRC_NOTIFY) { + sc = sl_bt_gatt_server_send_notification( + self->conn_handle, + self->characteristic->handle, + self->pending_size, + (uint8_t *)self->outgoing[self->pending_index]); + } + + if (self->write_type & BT_GATT_CHRC_INDICATE) { + sl_bt_gatt_server_send_indication( + self->conn_handle, + self->characteristic->handle, + self->pending_size, + (uint8_t *)self->outgoing[self->pending_index]); + } + } + self->pending_size = 0; + self->pending_index = (self->pending_index + 1) % 2; + self->packet_queued = true; + } + return sc; +} + + +// This funttion is called in sl_bt_on_event to receive +bool packet_buffer_on_ble_evt(uint16_t attribute, uint8_t *data, uint16_t len) { + uint16_t cindex = 0; + for (cindex = 0; cindex < bleio_packet_buffer_list.len; cindex++) { + if (bleio_packet_buffer_list.data[cindex]->characteristic->handle == attribute) { + taskENTER_CRITICAL(); + write_to_ringbuf(bleio_packet_buffer_list.data[cindex], data, len); + taskEXIT_CRITICAL(); + + return true; + } + } + return false; +} + +void _common_hal_bleio_packet_buffer_construct( + bleio_packet_buffer_obj_t *self, + bleio_characteristic_obj_t *characteristic, + uint32_t *incoming_buffer, + size_t incoming_buffer_size, + uint32_t *outgoing_buffer1, + uint32_t *outgoing_buffer2, + size_t max_packet_size, + void *static_handler_entry) { + + bleio_characteristic_properties_t temp_prop; + self->characteristic = characteristic; + self->client = self->characteristic->service->is_remote; + self->max_packet_size = max_packet_size; + bleio_characteristic_properties_t incoming = self->characteristic->props & (BT_GATT_CHRC_WRITE_WITHOUT_RESP | BT_GATT_CHRC_WRITE); + bleio_characteristic_properties_t outgoing = self->characteristic->props & (BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_INDICATE); + + if (self->client) { + // Swap if we're the client. + temp_prop = incoming; + incoming = outgoing; + outgoing = temp_prop; + self->conn_handle = bleio_connection_get_conn_handle( + MP_OBJ_TO_PTR(self->characteristic->service->connection)); + } else { + self->conn_handle = BLE_CONN_HANDLE_INVALID; + } + + if (incoming) { + ringbuf_init(&self->ringbuf, + (uint8_t *)incoming_buffer, + incoming_buffer_size); + } + + self->packet_queued = false; + self->pending_index = 0; + self->pending_size = 0; + self->outgoing[0] = outgoing_buffer1; + self->outgoing[1] = outgoing_buffer2; + + if (self->client) { + if (incoming) { + if (incoming & BT_GATT_CHRC_NOTIFY) { + common_hal_bleio_characteristic_set_cccd(self->characteristic, + true, false); + } else { + common_hal_bleio_characteristic_set_cccd(self->characteristic, + false, true); + } + } + if (outgoing) { + self->write_type = BT_GATT_CHRC_WRITE; + if (outgoing & BT_GATT_CHRC_WRITE_WITHOUT_RESP) { + self->write_type = BT_GATT_CHRC_WRITE_WITHOUT_RESP; + } + } + } else { + self->write_type = outgoing; + } +} + +// Init packet buffer +void common_hal_bleio_packet_buffer_construct( + bleio_packet_buffer_obj_t *self, bleio_characteristic_obj_t *characteristic, + size_t buffer_size, size_t max_packet_size) { + + size_t incoming_buffer_size = 0; + uint32_t *incoming_buffer = NULL; + uint32_t *outgoing1 = NULL; + uint32_t *outgoing2 = NULL; + + bleio_characteristic_properties_t temp_properties; + // Cap the packet size to our implementation limits. + max_packet_size = MIN(max_packet_size, BLE_GATTS_VAR_ATTR_LEN_MAX - 3); + + bleio_characteristic_properties_t incoming = characteristic->props & (BT_GATT_CHRC_WRITE_WITHOUT_RESP | BT_GATT_CHRC_WRITE); + bleio_characteristic_properties_t outgoing = characteristic->props & (BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_INDICATE); + if (characteristic->service->is_remote) { + // Swap if we're the client. + temp_properties = incoming; + incoming = outgoing; + outgoing = temp_properties; + } + + if (incoming) { + incoming_buffer_size = buffer_size * (sizeof(uint16_t) + max_packet_size); + incoming_buffer = m_malloc(incoming_buffer_size, false); + } + + if (outgoing) { + outgoing1 = m_malloc(max_packet_size, false); + outgoing2 = m_malloc(max_packet_size, false); + } + _common_hal_bleio_packet_buffer_construct(self, characteristic, + incoming_buffer, incoming_buffer_size, + outgoing1, outgoing2, max_packet_size, + NULL); + + bleio_packet_buffer_list.data[bleio_packet_buffer_list.len] = self; + bleio_packet_buffer_list.len++; +} + +// Reads a single BLE packet into the buffer +mp_int_t common_hal_bleio_packet_buffer_readinto( + bleio_packet_buffer_obj_t *self, + uint8_t *data, + size_t len) { + + mp_int_t ret; + uint16_t packet_length; + + if (ringbuf_num_filled(&self->ringbuf) < 1) { + return 0; + } + taskENTER_CRITICAL(); + // Get packet length, which is in first two bytes of packet. + packet_length = 5; + ringbuf_get_n(&self->ringbuf, (uint8_t *)&packet_length, sizeof(uint16_t)); + + if (packet_length > len) { + // Packet is longer than requested. Return negative of overrun value. + ret = len - packet_length; + // Discard the packet if it's too large. Don't fill data. + while (packet_length--) { + (void)ringbuf_get(&self->ringbuf); + } + } else { + // Read as much as possible, but might be shorter than len. + ringbuf_get_n(&self->ringbuf, data, packet_length); + ret = packet_length; + } + taskEXIT_CRITICAL(); + return ret; +} + +// Writes all bytes from data into the same outgoing packet +mp_int_t common_hal_bleio_packet_buffer_write(bleio_packet_buffer_obj_t *self, + const uint8_t *data, + size_t len, + uint8_t *header, + size_t header_len) { + + mp_int_t outgoing_packet_length; + mp_int_t total_len; + size_t num_bytes_written; + uint32_t *pending; + + if (!self->client) { + self->conn_handle = bleio_connections[0].conn_handle; + } + if (self->outgoing[0] == NULL) { + mp_raise_bleio_BluetoothError( + translate("Writes not supported on Characteristic")); + } + if (self->conn_handle == BLE_CONN_HANDLE_INVALID) { + return -1; + } + outgoing_packet_length = + common_hal_bleio_packet_buffer_get_outgoing_packet_length(self); + + if (outgoing_packet_length < 0) { + return -1; + } + + total_len = len + header_len; + if (total_len > outgoing_packet_length) { + // Supplied data will not fit in a single BLE packet. + mp_raise_ValueError_varg( + translate("Total data to write is larger than %q"), + MP_QSTR_outgoing_packet_length); + } + if (total_len > self->max_packet_size) { + // Supplied data will not fit in a single BLE packet. + mp_raise_ValueError_varg( + translate("Total data to write is larger than %q"), + MP_QSTR_max_packet_size); + } + outgoing_packet_length = MIN(outgoing_packet_length, self->max_packet_size); + + if (len + self->pending_size > (size_t)outgoing_packet_length) { + // No room to append len bytes to packet. Wait until we get a free buffer + // and keep checking that we haven't been disconnected. + while (self->pending_size != 0 && + self->conn_handle != BLE_CONN_HANDLE_INVALID && + !mp_hal_is_interrupted()) { + RUN_BACKGROUND_TASKS; + } + if (mp_hal_is_interrupted()) { + return -1; + } + } + if (self->conn_handle == BLE_CONN_HANDLE_INVALID) { + return -1; + } + + num_bytes_written = 0; + pending = self->outgoing[self->pending_index]; + + if (self->pending_size == 0) { + memcpy(pending, header, header_len); + self->pending_size += header_len; + num_bytes_written += header_len; + } + memcpy(((uint8_t *)pending) + self->pending_size, data, len); + self->pending_size += len; + num_bytes_written += len; + + queue_next_write(self); + return num_bytes_written; +} + +// Get length of receiving packet +mp_int_t common_hal_bleio_packet_buffer_get_incoming_packet_length( + bleio_packet_buffer_obj_t *self) { + + if (self->characteristic == NULL) { + return -1; + } + return self->characteristic->max_length; +} + +// Get length of outgoing packet +mp_int_t common_hal_bleio_packet_buffer_get_outgoing_packet_length( + bleio_packet_buffer_obj_t *self) { + + if (self->characteristic == NULL) { + return -1; + } + return MIN(self->max_packet_size, self->characteristic->max_length); +} + +// Flush ring buffer og packer buffer +void common_hal_bleio_packet_buffer_flush(bleio_packet_buffer_obj_t *self) { + while ((self->pending_size != 0 || + self->packet_queued) && + self->conn_handle != BLEIO_HANDLE_INVALID && + !mp_hal_is_interrupted()) { + RUN_BACKGROUND_TASKS; + } +} + +// Check status of packet buffer obj +bool common_hal_bleio_packet_buffer_deinited(bleio_packet_buffer_obj_t *self) { + return self->characteristic == NULL; +} + +// Deinit packet buffer +void common_hal_bleio_packet_buffer_deinit(bleio_packet_buffer_obj_t *self) { + if (!common_hal_bleio_packet_buffer_deinited(self)) { + ringbuf_deinit(&self->ringbuf); + } +} + +// Remove packet_buffer list when reload +void reset_packet_buffer_list() { + // Remove packet_buffer list + memset(bleio_packet_buffer_list.data, 0, + sizeof(bleio_packet_buffer_list.data)); + bleio_packet_buffer_list.len = 0; +} diff --git a/ports/silabs/common-hal/_bleio/PacketBuffer.h b/ports/silabs/common-hal/_bleio/PacketBuffer.h new file mode 100644 index 0000000000..f79eda6cf3 --- /dev/null +++ b/ports/silabs/common-hal/_bleio/PacketBuffer.h @@ -0,0 +1,64 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR_COMMON_HAL_BLEIO_PACKETBUFFER_H +#define MICROPY_INCLUDED_EFR_COMMON_HAL_BLEIO_PACKETBUFFER_H + +#include "py/ringbuf.h" +#include "shared-bindings/_bleio/Characteristic.h" + +#define MAX_NUMBER_PACKET_BUFFER 64 +typedef struct { + mp_obj_base_t base; + bleio_characteristic_obj_t *characteristic; + // Ring buffer storing consecutive incoming values. + ringbuf_t ringbuf; + // Two outgoing buffers to alternate between. + // One will be queued for transmission by the SD and + // the other is waiting to be queued and can be extended. + uint32_t *outgoing[2]; + volatile uint16_t pending_size; + // We remember the conn_handle so we can do a NOTIFY/INDICATE to a client. + // We can find out the conn_handle on a Characteristic write + // or a CCCD write (but not a read). + volatile uint16_t conn_handle; + uint16_t max_packet_size; + uint8_t pending_index; + uint8_t write_type; + bool client; + bool packet_queued; +} bleio_packet_buffer_obj_t; + +typedef struct { + bleio_packet_buffer_obj_t *data[MAX_NUMBER_PACKET_BUFFER]; + uint8_t len; +} bleio_packet_buffer_obj_list_t; + +extern bool packet_buffer_on_ble_evt(uint16_t attribute, + uint8_t *data, + uint16_t len); +extern void reset_packet_buffer_list(); +#endif // MICROPY_INCLUDED_EFR_COMMON_HAL_BLEIO_PACKETBUFFER_H diff --git a/ports/silabs/common-hal/_bleio/Service.c b/ports/silabs/common-hal/_bleio/Service.c new file mode 100644 index 0000000000..5fd06a2111 --- /dev/null +++ b/ports/silabs/common-hal/_bleio/Service.c @@ -0,0 +1,242 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include "py/runtime.h" +#include "common-hal/_bleio/__init__.h" +#include "shared-bindings/_bleio/__init__.h" +#include "shared-bindings/_bleio/Adapter.h" +#include "shared-bindings/_bleio/Characteristic.h" +#include "shared-bindings/_bleio/Descriptor.h" +#include "shared-bindings/_bleio/Service.h" + +// List ble service of central device +bleio_service_obj_list bleio_service_list; + +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) { + + uint8_t service_type; + sl_status_t sc = SL_STATUS_FAIL; + uint16_t gattdb_session; + sl_bt_uuid_16_t bt_uuid; + + self->handle = 0xFFFF; + self->uuid = uuid; + self->characteristic_list = characteristic_list; + self->is_remote = false; + self->connection = NULL; + self->is_secondary = is_secondary; + + if (self->is_secondary) { + service_type = sl_bt_gattdb_secondary_service; + } else { + service_type = sl_bt_gattdb_primary_service; + } + + sc = sl_bt_gattdb_new_session(&gattdb_session); + if (SL_STATUS_OK != sc && SL_STATUS_ALREADY_EXISTS != sc) { + mp_raise_bleio_BluetoothError(translate("Create new session fail.")); + return sc; + } + if (BLE_UUID_TYPE_16 == self->uuid->efr_ble_uuid.uuid.type) { + + bt_uuid.data[0] = self->uuid->efr_ble_uuid.uuid16.value & 0xff; + bt_uuid.data[1] = self->uuid->efr_ble_uuid.uuid16.value >> 8; + sc = sl_bt_gattdb_add_service(gattdb_session, + service_type, + 0, 2, bt_uuid.data, + (uint16_t *)&self->handle); + } else if (BLE_UUID_TYPE_128 == self->uuid->efr_ble_uuid.uuid.type) { + sc = sl_bt_gattdb_add_service(gattdb_session, + service_type, 0, 16, + self->uuid->efr_ble_uuid.uuid128.value, + (uint16_t *)&self->handle); + } + + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError(translate("Create new session fail.")); + return sc; + } + + sc = sl_bt_gattdb_start_service(gattdb_session, self->handle); + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError(translate("Start service fail.")); + } + + sc = sl_bt_gattdb_commit(gattdb_session); + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError(translate("Commit service fail.")); + } + + bleio_service_list.data[bleio_service_list.len] = self; + bleio_service_list.len++; + return sc; +} + +// Create a new Service identified by the specified UUID +void common_hal_bleio_service_construct(bleio_service_obj_t *self, + bleio_uuid_obj_t *uuid, + bool is_secondary) { + _common_hal_bleio_service_construct(self, uuid, + is_secondary, + mp_obj_new_list(0, NULL)); +} + +// Get service from connection +void bleio_service_from_connection(bleio_service_obj_t *self, + mp_obj_t connection) { + self->handle = BLEIO_HANDLE_INVALID; + self->uuid = NULL; + self->characteristic_list = mp_obj_new_list(0, NULL); + self->is_remote = true; + self->is_secondary = false; + self->connection = connection; +} + +// Get service uuid +bleio_uuid_obj_t *common_hal_bleio_service_get_uuid(bleio_service_obj_t *self) { + return self->uuid; +} + +// Get tuple charateristic of service +mp_obj_tuple_t *common_hal_bleio_service_get_characteristics( + bleio_service_obj_t *self) { + return mp_obj_new_tuple(self->characteristic_list->len, + self->characteristic_list->items); +} + +// This is a service provided by a remote device or not +bool common_hal_bleio_service_get_is_remote(bleio_service_obj_t *self) { + return self->is_remote; +} + +// If the service is a secondary one +bool common_hal_bleio_service_get_is_secondary(bleio_service_obj_t *self) { + return self->is_secondary; +} + +// Add new dynamic characteristic to service +void common_hal_bleio_service_add_characteristic(bleio_service_obj_t *self, + bleio_characteristic_obj_t *characteristic, + mp_buffer_info_t *initial_value_bufinfo, + const char *user_description) { + + bool broadcast = (characteristic->props & CHAR_PROP_BROADCAST) ? 1 : 0; + bool read = (characteristic->props & CHAR_PROP_READ) ? 1 : 0; + bool write_wo_resp = + (characteristic->props & CHAR_PROP_WRITE_NO_RESPONSE) ? 1 : 0; + bool write = + write_wo_resp ? 1 : (characteristic->props & CHAR_PROP_WRITE) ? 1 + : 0; + bool notify = (characteristic->props & CHAR_PROP_NOTIFY) ? 1 : 0; + bool indicate = (characteristic->props & CHAR_PROP_INDICATE) ? 1 : 0; + + sl_status_t sc = SL_STATUS_FAIL; + sl_bt_uuid_16_t bt_uuid; + uint16_t gattdb_session; + + sc = sl_bt_gattdb_new_session(&gattdb_session); + + if (SL_STATUS_OK != sc && SL_STATUS_ALREADY_EXISTS != sc) { + mp_raise_bleio_BluetoothError(translate("Create new session fail.")); + return; + } + characteristic->props = (broadcast << 0) | (read << 1) | + (write_wo_resp << 2) | (write << 3) | (notify << 4) | (indicate << 5); + + if (BLE_UUID_TYPE_16 == characteristic->uuid->efr_ble_uuid.uuid.type) { + bt_uuid.data[0] = characteristic->uuid->efr_ble_uuid.uuid16.value & 0xff; + bt_uuid.data[1] = characteristic->uuid->efr_ble_uuid.uuid16.value >> 8; + + sc = sl_bt_gattdb_add_uuid16_characteristic( + gattdb_session, + self->handle, + characteristic->props, + 0, + 0, + bt_uuid, + sl_bt_gattdb_variable_length_value, + characteristic->max_length, + 0, + initial_value_bufinfo->buf, + &characteristic->handle); + + } else if (BLE_UUID_TYPE_128 == + characteristic->uuid->efr_ble_uuid.uuid.type) { + uuid_128 uuid; + memcpy(uuid.data, characteristic->uuid->efr_ble_uuid.uuid128.value, 16); + + sc = sl_bt_gattdb_add_uuid128_characteristic(gattdb_session, + self->handle, + characteristic->props, + 0, + 0, + uuid, + sl_bt_gattdb_variable_length_value, + characteristic->max_length, + 0, + initial_value_bufinfo->buf, + &characteristic->handle); + } + + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError(translate("Add charateristic fail.")); + } + + sc = sl_bt_gattdb_start_characteristic(gattdb_session, + characteristic->handle); + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError(translate("Start charateristic fail.")); + return; + } + + sc = sl_bt_gattdb_commit(gattdb_session); + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError(translate("Commit charateristic fail.")); + return; + } + mp_obj_list_append(self->characteristic_list, + MP_OBJ_FROM_PTR(characteristic)); +} + +// Remove dynamic service when reload +void reset_dynamic_service() { + + uint16_t gattdb_session; + uint8_t svc_index; + // Remove dynamic service + for (svc_index = 0; svc_index < bleio_service_list.len; svc_index++) { + sl_bt_gattdb_new_session(&gattdb_session); + sl_bt_gattdb_remove_service(gattdb_session, + bleio_service_list.data[svc_index]->handle); + sl_bt_gattdb_commit(gattdb_session); + } + bleio_service_list.len = 0; +} diff --git a/ports/silabs/common-hal/_bleio/Service.h b/ports/silabs/common-hal/_bleio/Service.h new file mode 100644 index 0000000000..a389da21b7 --- /dev/null +++ b/ports/silabs/common-hal/_bleio/Service.h @@ -0,0 +1,63 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR_COMMON_HAL_BLEIO_SERVICE_H +#define MICROPY_INCLUDED_EFR_COMMON_HAL_BLEIO_SERVICE_H + +#include "py/objlist.h" +#include "common-hal/_bleio/UUID.h" + +#define MAX_NUMBER_SERVICE 64 + +typedef struct bleio_service_obj +{ + mp_obj_base_t base; + // Handle for the local service. + uint32_t handle; + // True if created during discovery. + bool is_remote; + bool is_secondary; + bleio_uuid_obj_t *uuid; + // The connection object is set only when this is a remote service. + // A local service doesn't know the connection. + mp_obj_t connection; + mp_obj_list_t *characteristic_list; + // Range of attribute handles of this remote service. + uint16_t start_handle; + uint16_t end_handle; +} bleio_service_obj_t; + +typedef struct +{ + bleio_service_obj_t *data[MAX_NUMBER_SERVICE]; + uint8_t len; +} bleio_service_obj_list; + +void bleio_service_from_connection(bleio_service_obj_t *self, + mp_obj_t connection); +uint16_t get_characteristic_handle(bleio_uuid_obj_t *uuid); +extern void reset_dynamic_service(); +#endif // MICROPY_INCLUDED_EFR_COMMON_HAL_BLEIO_SERVICE_H diff --git a/ports/silabs/common-hal/_bleio/UUID.c b/ports/silabs/common-hal/_bleio/UUID.c new file mode 100644 index 0000000000..482a23d8f8 --- /dev/null +++ b/ports/silabs/common-hal/_bleio/UUID.c @@ -0,0 +1,83 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include "py/runtime.h" +#include "shared-bindings/_bleio/Adapter.h" +#include "shared-bindings/_bleio/UUID.h" +#include "shared-bindings/_bleio/__init__.h" +#include "common-hal/_bleio/UUID.h" + +void common_hal_bleio_uuid_construct(bleio_uuid_obj_t *self, + mp_int_t uuid16, + const uint8_t uuid128[16]) { + + if (uuid128 == NULL) { + self->efr_ble_uuid.uuid16.value = uuid16; + self->efr_ble_uuid.uuid.type = BLE_UUID_TYPE_16; + } else { + memcpy(self->efr_ble_uuid.uuid128.value, uuid128, 16); + self->efr_ble_uuid.uuid128.value[12] = uuid16 & 0xff; + self->efr_ble_uuid.uuid128.value[13] = (uuid16 >> 8) & 0xff; + self->efr_ble_uuid.uuid.type = BLE_UUID_TYPE_128; + } +} + +uint32_t common_hal_bleio_uuid_get_size(bleio_uuid_obj_t *self) { + return self->efr_ble_uuid.uuid.type == BLE_UUID_TYPE_16 ? 16 : 128; +} + +uint32_t common_hal_bleio_uuid_get_uuid16(bleio_uuid_obj_t *self) { + return self->efr_ble_uuid.uuid16.value; +} + +void common_hal_bleio_uuid_get_uuid128(bleio_uuid_obj_t *self, + uint8_t uuid128[16]) { + memcpy(uuid128, self->efr_ble_uuid.uuid128.value, 16); +} + +void common_hal_bleio_uuid_pack_into(bleio_uuid_obj_t *self, uint8_t *buf) { + if (self->efr_ble_uuid.uuid.type == BLE_UUID_TYPE_16) { + buf[0] = self->efr_ble_uuid.uuid16.value & 0xff; + buf[1] = self->efr_ble_uuid.uuid16.value >> 8; + } else { + common_hal_bleio_uuid_get_uuid128(self, buf); + } +} + +void bleio_uuid_construct_from_efr_ble_uuid(bleio_uuid_obj_t *self, + ble_uuid_any_t *efr_ble_uuid) { + + if (self->efr_ble_uuid.uuid.type == BLE_UUID_TYPE_16) { + mp_raise_bleio_BluetoothError(translate("Unexpected efr uuid type")); + } + self->efr_ble_uuid.uuid16.value = efr_ble_uuid->uuid16.value; +} + +void bleio_uuid_convert_to_efr_ble_uuid(bleio_uuid_obj_t *self, + ble_uuid_any_t *efr_ble_uuid) { + efr_ble_uuid->uuid16.value = self->efr_ble_uuid.uuid16.value; +} diff --git a/ports/silabs/common-hal/_bleio/UUID.h b/ports/silabs/common-hal/_bleio/UUID.h new file mode 100644 index 0000000000..c1b99eb1ff --- /dev/null +++ b/ports/silabs/common-hal/_bleio/UUID.h @@ -0,0 +1,90 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR_COMMON_HAL_BLEIO_UUID_H +#define MICROPY_INCLUDED_EFR_COMMON_HAL_BLEIO_UUID_H + +#include "py/obj.h" + +#define UUID16_LEN 2 +#define UUID128_LEN 16 + +// Type of UUID +typedef enum { + // 16-bit UUID (BT SIG assigned) + BLE_UUID_TYPE_16 = 16, + // 32-bit UUID (BT SIG assigned) + BLE_UUID_TYPE_32 = 32, + // 128-bit UUID + BLE_UUID_TYPE_128 = 128, +} uuid_type_e; + +typedef struct { + // Type of the UUID + uint8_t type; +} ble_uuid_t; + +// 16-bit UUID +typedef struct { + uint8_t type; + uint16_t value; +} ble_uuid16_t; + +// 32-bit UUID +typedef struct { + uint8_t type; + uint32_t value; +} ble_uuid32_t; + +// 128-bit UUID +typedef struct { + uint8_t type; + uint8_t value[16]; +} ble_uuid128_t; + +typedef union { + ble_uuid_t uuid; + ble_uuid16_t uuid16; + ble_uuid32_t uuid32; + ble_uuid128_t uuid128; +} ble_uuid_any_t; + +typedef struct { + mp_obj_base_t base; + // Use the native way of storing UUID's: + // - ble_uuid_t.uuid is a 16-bit uuid. + // - ble_uuid_t.type is BLE_UUID_TYPE_BLE if it's a 16-bit Bluetooth SIG UUID. + // or is BLE_UUID_TYPE_VENDOR_BEGIN and higher, which indexes into a table of registered + // 128-bit UUIDs. + ble_uuid_any_t efr_ble_uuid; +} bleio_uuid_obj_t; + +void bleio_uuid_construct_from_efr_ble_uuid(bleio_uuid_obj_t *self, + ble_uuid_any_t *efr_ble_uuid); +void bleio_uuid_convert_to_efr_ble_uuid(bleio_uuid_obj_t *self, + ble_uuid_any_t *efr_ble_uuid); + +#endif // MICROPY_INCLUDED_EFR_COMMON_HAL_BLEIO_UUID_H diff --git a/ports/silabs/common-hal/_bleio/__init__.c b/ports/silabs/common-hal/_bleio/__init__.c new file mode 100644 index 0000000000..e7323c7793 --- /dev/null +++ b/ports/silabs/common-hal/_bleio/__init__.c @@ -0,0 +1,402 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include +#include "py/runtime.h" +#include "shared-bindings/_bleio/__init__.h" +#include "shared-bindings/_bleio/Adapter.h" +#include "shared-bindings/_bleio/Characteristic.h" +#include "shared-bindings/_bleio/CharacteristicBuffer.h" +#include "shared-bindings/_bleio/PacketBuffer.h" +#include "shared-bindings/_bleio/Connection.h" +#include "shared-bindings/_bleio/Descriptor.h" +#include "shared-bindings/_bleio/Service.h" +#include "shared-bindings/_bleio/UUID.h" +#include "supervisor/shared/bluetooth/bluetooth.h" +#include "common-hal/_bleio/__init__.h" + +STATIC conn_state_t conn_state; +osMutexId_t bluetooth_connection_mutex_id; +bleio_adapter_obj_t common_hal_bleio_adapter_obj; + +__ALIGNED(4) static uint8_t bluetooth_connection_mutex_cb[osMutexCbSize]; +const osMutexAttr_t bluetooth_connection_mutex_attr = { + .name = "Bluetooth Mutex", + .attr_bits = osMutexRecursive | osMutexPrioInherit, + .cb_mem = bluetooth_connection_mutex_cb, + .cb_size = osMutexCbSize +}; + +void bleio_user_reset() { + // Stop any user scanning or advertising. + common_hal_bleio_adapter_stop_scan(&common_hal_bleio_adapter_obj); + common_hal_bleio_adapter_stop_advertising(&common_hal_bleio_adapter_obj); + + // Maybe start advertising the BLE workflow. + supervisor_bluetooth_background(); +} + +void bleio_reset() { + reset_dynamic_service(); + reset_packet_buffer_list(); + reset_characteristic_buffer_list(); + bleio_adapter_reset(&common_hal_bleio_adapter_obj); + // Set this explicitly to save data. + common_hal_bleio_adapter_obj.base.type = &bleio_adapter_type; + if (!common_hal_bleio_adapter_get_enabled(&common_hal_bleio_adapter_obj)) { + return; + } + + supervisor_stop_bluetooth(); + common_hal_bleio_adapter_set_enabled(&common_hal_bleio_adapter_obj, false); + supervisor_start_bluetooth(); +} + +void bleio_background(void) { + +} + +void common_hal_bleio_gc_collect(void) { + bleio_adapter_gc_collect(&common_hal_bleio_adapter_obj); +} + +void check_ble_error(int error_code) { + if (error_code == SL_STATUS_OK) { + return; + } + switch (error_code) { + case SL_STATUS_TIMEOUT: + mp_raise_msg(&mp_type_TimeoutError, NULL); + return; + default: + mp_raise_bleio_BluetoothError( + translate("Unknown BLE error: %d"), error_code); + break; + } +} + +void common_hal_bleio_check_connected(uint16_t conn_handle) { + if (conn_handle == BLEIO_HANDLE_INVALID) { + mp_raise_ConnectionError(translate("Not connected")); + } +} + +// Bluetooth stack event handler. +void sl_bt_on_event(sl_bt_msg_t *evt) { + sl_status_t sc = SL_STATUS_OK; + bd_addr address; + uint8_t address_type = 0; + STATIC uint8_t serv_idx = 0; + STATIC uint8_t device_name[16]; + + bleio_connection_internal_t *connection; + bleio_service_obj_t *service; + bleio_characteristic_obj_t *characteristic; + bleio_uuid_obj_t *uuid; + bleio_characteristic_properties_t props; + + switch (SL_BT_MSG_ID(evt->header)) { + + case sl_bt_evt_system_boot_id: + + sc = sl_bt_system_get_identity_address(&address, &address_type); + + snprintf((char *)device_name, 14 + 1, + "CIRCUITPY-%X%X",address.addr[1], address.addr[0]); + sl_bt_gatt_server_write_attribute_value(gattdb_device_name, + 0,14,device_name); + + sc = sl_bt_sm_configure(0x00,sl_bt_sm_io_capability_noinputnooutput); + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError(translate("Sm configure fail")); + } + + sc = sl_bt_sm_set_bondable_mode(1); + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError(translate("Set bondable mode fail")); + } + sl_bt_sm_delete_bondings(); + break; + + // This event indicates that a new connection was opened. + case sl_bt_evt_connection_opened_id: + serv_idx = 0; + osMutexAcquire(bluetooth_connection_mutex_id, osWaitForever); + // Device role is Peripheral + if (evt->data.evt_connection_opened.master == 0) { + bleio_connections[0].conn_handle = + evt->data.evt_connection_opened.connection; + bleio_connections[0].connection_obj = mp_const_none; + bleio_connections[0].pair_status = PAIR_PAIRED; + bleio_connections[0].is_central = false; + bleio_connections[0].mtu = 0; + } + + sc = sl_bt_sm_increase_security( + evt->data.evt_connection_opened.connection); + + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError( + translate("Increase security fail.")); + } + osMutexRelease(bluetooth_connection_mutex_id); + break; + + case sl_bt_evt_scanner_legacy_advertisement_report_id: + + set_scan_device_info_on_ble_evt( + evt->data.evt_scanner_legacy_advertisement_report.address, + evt->data.evt_scanner_legacy_advertisement_report.address_type, + evt->data.evt_scanner_legacy_advertisement_report.rssi, + &evt->data.evt_scanner_legacy_advertisement_report.data); + + if (xscan_event != NULL) { + xEventGroupSetBits(xscan_event,1 << 0); + } + break; + + case sl_bt_evt_connection_closed_id: + common_hal_bleio_adapter_remove_connection( + evt->data.evt_connection_closed.connection); + break; + + case sl_bt_evt_system_external_signal_id: + if (evt->data.evt_system_external_signal.extsignals & 1) { + sl_bt_external_signal(0); + } + break; + + case sl_bt_evt_gatt_service_id: + osMutexAcquire(bluetooth_connection_mutex_id, osWaitForever); + connection = bleio_conn_handle_to_connection( + evt->data.evt_gatt_service.connection); + service = m_new_obj(bleio_service_obj_t); + if (NULL == service) { + mp_raise_bleio_BluetoothError( + translate("Create new service obj fail")); + } + service->base.type = &bleio_service_type; + bleio_service_from_connection(service, + bleio_connection_new_from_internal(connection)); + service->is_remote = true; + service->handle = evt->data.evt_gatt_service.service; + uuid = m_new_obj(bleio_uuid_obj_t); + if (NULL == uuid) { + osMutexRelease(bluetooth_connection_mutex_id); + mp_raise_bleio_BluetoothError( + translate("Create new service uuid obj fail")); + break; + } + uuid->base.type = &bleio_uuid_type; + + if (UUID16_LEN == evt->data.evt_gatt_service.uuid.len) { + uuid->efr_ble_uuid.uuid16.value &= 0x0000; + uuid->efr_ble_uuid.uuid16.value + |= evt->data.evt_gatt_service.uuid.data[1]; + + uuid->efr_ble_uuid.uuid16.value = + (uuid->efr_ble_uuid.uuid16.value << 8) + | evt->data.evt_gatt_service.uuid.data[0]; + uuid->efr_ble_uuid.uuid.type = BLE_UUID_TYPE_16; + + } else if (UUID128_LEN == evt->data.evt_gatt_service.uuid.len) { + memcpy(uuid->efr_ble_uuid.uuid128.value, + evt->data.evt_gatt_service.uuid.data, UUID128_LEN); + uuid->efr_ble_uuid.uuid.type = BLE_UUID_TYPE_128; + } + service->uuid = uuid; + mp_obj_list_append(MP_OBJ_FROM_PTR(connection->remote_service_list), + MP_OBJ_FROM_PTR(service)); + conn_state = DISCOVER_SERVICES; + osMutexRelease(bluetooth_connection_mutex_id); + break; + + case sl_bt_evt_gatt_characteristic_id: + osMutexAcquire(bluetooth_connection_mutex_id, osWaitForever); + connection = bleio_conn_handle_to_connection( + evt->data.evt_gatt_characteristic.connection); + service = + MP_OBJ_TO_PTR(connection->remote_service_list->items[serv_idx - 1]); + + characteristic = m_new_obj(bleio_characteristic_obj_t); + if (characteristic == NULL) { + mp_raise_bleio_BluetoothError( + translate("Create new characteristic obj fail.")); + } + + characteristic->base.type = &bleio_characteristic_type; + uuid = m_new_obj(bleio_uuid_obj_t); + if (uuid == NULL) { + mp_raise_bleio_BluetoothError( + translate("Create new characteristic uuid obj fail.")); + break; + } + + uuid->base.type = &bleio_uuid_type; + if (UUID16_LEN == evt->data.evt_gatt_characteristic.uuid.len) { + uuid->efr_ble_uuid.uuid16.value &= 0x0000; + uuid->efr_ble_uuid.uuid16.value + |= evt->data.evt_gatt_characteristic.uuid.data[1]; + + uuid->efr_ble_uuid.uuid16.value = + (uuid->efr_ble_uuid.uuid16.value << 8) + | evt->data.evt_gatt_characteristic.uuid.data[0]; + + uuid->efr_ble_uuid.uuid.type = BLE_UUID_TYPE_16; + } else if ( + UUID128_LEN == evt->data.evt_gatt_characteristic.uuid.len) { + + memcpy(uuid->efr_ble_uuid.uuid128.value, + evt->data.evt_gatt_characteristic.uuid.data, + UUID128_LEN); + uuid->efr_ble_uuid.uuid.type = BLE_UUID_TYPE_128; + } + + props = evt->data.evt_gatt_characteristic.properties; + characteristic->handle = + evt->data.evt_gatt_characteristic.characteristic; + characteristic->props = props; + + common_hal_bleio_characteristic_construct( + characteristic, service, + evt->data.evt_gatt_characteristic.characteristic, uuid, + props, SECURITY_MODE_OPEN, SECURITY_MODE_OPEN, + 0, false, + mp_const_empty_bytes, + NULL); + + mp_obj_list_append(MP_OBJ_FROM_PTR(service->characteristic_list), + MP_OBJ_FROM_PTR(characteristic)); + osMutexRelease(bluetooth_connection_mutex_id); + break; + + case sl_bt_evt_gatt_procedure_completed_id: + + if (conn_state == DISCOVER_SERVICES + || conn_state == DISCOVER_CHARACTERISTICS) { + + connection = MP_OBJ_TO_PTR( + bleio_conn_handle_to_connection( + evt->data.evt_gatt_procedure_completed.connection)); + + if (connection != NULL + && serv_idx < connection->remote_service_list->len) { + + service = connection->remote_service_list->items[serv_idx]; + sc = sl_bt_gatt_discover_characteristics( + evt->data.evt_gatt_procedure_completed.connection, + service->handle); + + conn_state = DISCOVER_CHARACTERISTICS; + serv_idx++; + + } else { + conn_state = RUNNING; + serv_idx = 0; + if (xdiscovery_event != NULL) { + xEventGroupSetBits(xdiscovery_event,1 << 0); + } + } + } + break; + + case sl_bt_evt_gatt_characteristic_value_id: + + if (characteristic_buffer_on_ble_evt( + evt->data.evt_gatt_characteristic_value.characteristic, + evt->data.evt_gatt_characteristic_value.value.data, + evt->data.evt_gatt_characteristic_value.value.len)) { + } else if (packet_buffer_on_ble_evt( + evt->data.evt_gatt_characteristic_value.characteristic, + evt->data.evt_gatt_characteristic_value.value.data, + evt->data.evt_gatt_characteristic_value.value.len)) { + } else { + + set_characteristic_value_on_ble_evt( + evt->data.evt_gatt_characteristic_value.connection, + evt->data.evt_gatt_characteristic_value.characteristic, + evt->data.evt_gatt_characteristic_value.value.data, + evt->data.evt_gatt_characteristic_value.value.len); + } + + sl_bt_gatt_send_characteristic_confirmation( + evt->data.evt_gatt_characteristic_value.connection); + break; + + case sl_bt_evt_gatt_server_attribute_value_id: + if (characteristic_buffer_on_ble_evt( + evt->data.evt_gatt_server_attribute_value.attribute, + evt->data.evt_gatt_server_attribute_value.value.data, + evt->data.evt_gatt_server_attribute_value.value.len)) { + } else { + packet_buffer_on_ble_evt( + evt->data.evt_gatt_server_attribute_value.attribute, + evt->data.evt_gatt_server_attribute_value.value.data, + evt->data.evt_gatt_server_attribute_value.value.len); + } + break; + + case sl_bt_evt_gatt_server_characteristic_status_id: + break; + + case sl_bt_evt_sm_passkey_display_id: + break; + + case sl_bt_evt_sm_confirm_bonding_id: + sc = sl_bt_sm_bonding_confirm( + evt->data.evt_sm_confirm_bonding.connection,1); + if (SL_STATUS_OK != sc) { + mp_raise_bleio_BluetoothError( + translate("Bonding confirm fail")); + } + break; + + case sl_bt_evt_sm_bonded_id: + break; + + case sl_bt_evt_sm_bonding_failed_id: + break; + + case sl_bt_evt_connection_parameters_id: + switch (evt->data.evt_connection_parameters.security_mode) + { + case connection_mode1_level1: + break; + case connection_mode1_level2: + break; + case connection_mode1_level3: + break; + case connection_mode1_level4: + break; + default: + break; + } + break; + + default: + break; + } +} diff --git a/ports/silabs/common-hal/_bleio/__init__.h b/ports/silabs/common-hal/_bleio/__init__.h new file mode 100644 index 0000000000..63eda59d84 --- /dev/null +++ b/ports/silabs/common-hal/_bleio/__init__.h @@ -0,0 +1,80 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_BLE_HCI_COMMON_HAL_INIT_H +#define MICROPY_INCLUDED_BLE_HCI_COMMON_HAL_INIT_H + +#include +#include +#include "shared-bindings/_bleio/UUID.h" + +#include "gatt_db.h" +#include "sl_status.h" +#include "sl_bt_api.h" +#include "sl_bgapi.h" +#include "sl_bluetooth.h" +#include "sl_bt_rtos_adaptation.h" +#include "sl_cmsis_os2_common.h" +#include + +#include "FreeRTOS.h" +#include "task.h" +#include "queue.h" +#include "semphr.h" + +#define MSEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000) / (RESOLUTION)) +#define SEC_TO_UNITS(TIME, RESOLUTION) (((TIME) * 1000000) / (RESOLUTION)) +#define UNITS_TO_SEC(TIME, RESOLUTION) (((TIME)*(RESOLUTION)) / 1000000) + +// We assume variable length data. 20 bytes max (23 - 3). +#define GATT_MAX_DATA_LENGTH (BT_ATT_DEFAULT_LE_MTU - 3) + +#define BLE_GATT_HANDLE_INVALID 0x0000 +#define BLE_CONN_HANDLE_INVALID 0xFFFF + +// Maximum length for fixed length Attribute Values. +#define BLE_GATTS_FIX_ATTR_LEN_MAX (510) + +// Maximum length for variable length Attribute Values. +#define BLE_GATTS_VAR_ATTR_LEN_MAX (512) + +// Track if the user code modified the BLE state +// to know if we need to undo it on reload. +extern bool vm_used_ble; + +// UUID shared by all CCCD's. +extern bleio_uuid_obj_t cccd_uuid; +extern void bleio_reset(); + +extern osMutexId_t bluetooth_connection_mutex_id; +extern const osMutexAttr_t bluetooth_connection_mutex_attr; +typedef enum { + DISCOVER_SERVICES, + DISCOVER_CHARACTERISTICS, + RUNNING +} conn_state_t; + +#endif // MICROPY_INCLUDED_BLE_HCI_COMMON_HAL_INIT_H diff --git a/ports/silabs/common-hal/analogio/AnalogIn.c b/ports/silabs/common-hal/analogio/AnalogIn.c new file mode 100644 index 0000000000..ecf61ca268 --- /dev/null +++ b/ports/silabs/common-hal/analogio/AnalogIn.c @@ -0,0 +1,216 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "py/runtime.h" +#include "common-hal/analogio/AnalogIn.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "shared/runtime/interrupt_char.h" +#include "supervisor/shared/translate/translate.h" +#include "em_cmu.h" +#include "em_iadc.h" + +// Set CLK_ADC to 10MHz +#define CLK_SRC_ADC_FREQ 20000000 // CLK_SRC_ADC +#define CLK_ADC_FREQ 10000000 // CLK_ADC - 10 MHz max in normal mode + +// Number of scan channels +#define NUM_INPUTS 8 + +STATIC uint8_t num_current_input = 0; +STATIC volatile uint16_t scan_result[NUM_INPUTS]; +STATIC volatile uint8_t scan_flag = 0; +STATIC IADC_ScanTable_t init_scan_table = IADC_SCANTABLE_DEFAULT; // Scan Table + +// Construct analogin pin. This function is called when init AnalogIn +void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, + const mcu_pin_obj_t *pin) { + + uint8_t adc_index; + if (self->pin == NULL) { + self->id = NUM_INPUTS + 1; + for (adc_index = 0; adc_index < NUM_INPUTS; adc_index++) { + if (init_scan_table.entries[adc_index].includeInScan == false) { + self->id = adc_index; + self->pin = pin; + init_scan_table.entries[adc_index].includeInScan = true; + init_scan_table.entries[adc_index].negInput = iadcNegInputGnd; + init_scan_table.entries[adc_index].posInput + = IADC_portPinToPosInput(self->pin->port, self->pin->number); + num_current_input++; + break; + } + } + } + + if (self->id == NUM_INPUTS + 1) { + mp_raise_ValueError(translate("ADC busy pin")); + } + + // Declare init structs + IADC_Init_t init = IADC_INIT_DEFAULT; + IADC_AllConfigs_t initAllConfigs = IADC_ALLCONFIGS_DEFAULT; + IADC_InitScan_t initScan = IADC_INITSCAN_DEFAULT; + + CMU_ClockEnable(cmuClock_IADC0, true); + + // Select clock for IADC + CMU_ClockSelectSet(cmuClock_IADCCLK, cmuSelect_FSRCO); + + // Modify init structures and initialize + init.warmup = iadcWarmupKeepWarm; + + // Set the HFSCLK prescale value here + init.srcClkPrescale = IADC_calcSrcClkPrescale(IADC0, CLK_SRC_ADC_FREQ, 0); + + // Configuration 0 is used by both scan and single conversions by + // default. Use internal bandgap as the reference and specify the + // reference voltage in mV. + // Resolution is not configurable directly but is based on the + // selected oversampling ratio (osrHighSpeed), which defaults to + // 2x and generates 12-bit results. + initAllConfigs.configs[0].reference = iadcCfgReferenceInt1V2; + initAllConfigs.configs[0].vRef = 1210; + initAllConfigs.configs[0].osrHighSpeed = iadcCfgOsrHighSpeed2x; + initAllConfigs.configs[0].analogGain = iadcCfgAnalogGain0P5x; + + // Divide CLK_SRC_ADC to set the CLK_ADC frequency + initAllConfigs.configs[0].adcClkPrescale + = IADC_calcAdcClkPrescale(IADC0, + CLK_ADC_FREQ, + 0, + iadcCfgModeNormal, + init.srcClkPrescale); + + + // Set the SCANFIFODVL flag when there are 8 entries in the scan + // FIFO. Note that in this example, the interrupt associated with + // the SCANFIFODVL flag in the IADC_IF register is not used. + // Similarly, the fifoDmaWakeup member of the initScan structure + // is left at its default setting of false, so LDMA service is not + // requested when the FIFO holds the specified number of samples. + initScan.dataValidLevel = _IADC_SCANFIFOCFG_DVL_VALID8; + + // Tag FIFO entry with scan table entry id + initScan.showId = true; + + // Initialize IADC + IADC_init(IADC0, &init, &initAllConfigs); + + // Initialize scan + IADC_initScan(IADC0, &initScan, &init_scan_table); + + if (self->pin->port == gpioPortA) { + GPIO->ABUSALLOC |= GPIO_ABUSALLOC_AEVEN0_ADC0; + GPIO->ABUSALLOC |= GPIO_ABUSALLOC_AODD0_ADC0; + } else if (self->pin->port == gpioPortB) { + GPIO->BBUSALLOC |= GPIO_BBUSALLOC_BEVEN0_ADC0; + GPIO->BBUSALLOC |= GPIO_BBUSALLOC_BODD0_ADC0; + } else { + GPIO->CDBUSALLOC |= GPIO_CDBUSALLOC_CDEVEN0_ADC0; + GPIO->CDBUSALLOC |= GPIO_CDBUSALLOC_CDODD0_ADC0; + } + + // Clear any previous interrupt flags + IADC_clearInt(IADC0, _IADC_IF_MASK); + + // Enable Scan interrupts + IADC_enableInt(IADC0, IADC_IEN_SCANTABLEDONE); + + // Enable ADC interrupts + NVIC_ClearPendingIRQ(IADC_IRQn); + NVIC_EnableIRQ(IADC_IRQn); + + common_hal_mcu_pin_claim(pin); +} + +// Check obj is deinited or not +bool common_hal_analogio_analogin_deinited(analogio_analogin_obj_t *self) { + return self->pin == NULL; +} + +// Deinit a analogin obj +void common_hal_analogio_analogin_deinit(analogio_analogin_obj_t *self) { + if (num_current_input > 0) { + num_current_input--; + if (num_current_input == 0) { + IADC_reset(IADC0); + } + } + init_scan_table.entries[self->id].includeInScan = false; + init_scan_table.entries[self->id].posInput = iadcPosInputGnd; + scan_result[self->id] = 0; + common_hal_reset_pin(self->pin); + self->pin = NULL; +} + +// IADC Handler to read adc value +void IADC_IRQHandler(void) { + IADC_Result_t result = {0, 0}; + + // While the FIFO count is non-zero + while (IADC_getScanFifoCnt(IADC0)) { + // Pull a scan result from the FIFO + result = IADC_pullScanFifoResult(IADC0); + scan_result[result.id] = result.data; + scan_result[result.id] *= 16; + } + scan_flag = 1; + IADC_clearInt(IADC0, IADC_IF_SCANTABLEDONE); +} + +// Get adc value, use IADC_IRQHandler +// adc value 0 - 65535 +uint16_t common_hal_analogio_analogin_get_value(analogio_analogin_obj_t *self) { + // Start scan + IADC_command(IADC0, iadcCmdStartScan); + + uint64_t start_ticks = supervisor_ticks_ms64(); + uint64_t current_ticks = start_ticks; + + // Busy-wait until timeout or until we've read enough chars. + while (current_ticks - start_ticks <= 1000) { + current_ticks = supervisor_ticks_ms64(); + if (scan_flag == 1) { + scan_flag = 0; + break; + } + RUN_BACKGROUND_TASKS; + // Allow user to break out of a timeout with a KeyboardInterrupt. + if (mp_hal_is_interrupted()) { + break; + } + } + + uint16_t ret = scan_result[self->id]; + scan_result[self->id] = 0; + return ret; +} + +// Get adc ref value +float common_hal_analogio_analogin_get_reference_voltage + (analogio_analogin_obj_t *self) { + return 2.42f; +} diff --git a/ports/silabs/common-hal/analogio/AnalogIn.h b/ports/silabs/common-hal/analogio/AnalogIn.h new file mode 100644 index 0000000000..ae67036132 --- /dev/null +++ b/ports/silabs/common-hal/analogio/AnalogIn.h @@ -0,0 +1,39 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR32_COMMON_HAL_ANALOGIO_ANALOGIN_H +#define MICROPY_INCLUDED_EFR32_COMMON_HAL_ANALOGIO_ANALOGIN_H + +#include "common-hal/microcontroller/Pin.h" +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; + const mcu_pin_obj_t *pin; + uint8_t id; +} analogio_analogin_obj_t; + +#endif // MICROPY_INCLUDED_EFR32_COMMON_HAL_ANALOGIO_ANALOGIN_H diff --git a/ports/silabs/common-hal/analogio/AnalogOut.c b/ports/silabs/common-hal/analogio/AnalogOut.c new file mode 100644 index 0000000000..88b2f53f9e --- /dev/null +++ b/ports/silabs/common-hal/analogio/AnalogOut.c @@ -0,0 +1,167 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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/mperrno.h" +#include "py/runtime.h" +#include "shared-bindings/analogio/AnalogOut.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "supervisor/shared/translate/translate.h" +#include "common-hal/microcontroller/Pin.h" +#include "em_vdac.h" + +// Set the VDAC to max frequency of 1 MHz +#define CLK_VDAC_FREQ 1000000 + +// List DAC pin and channel supported +mcu_dac_pin_obj_t mcu_dac_list[DAC_BANK_ARRAY_LEN] = { + DAC(VDAC0, 0, FN_VDAC0_CH0, false, 0, &pin_PB0), + DAC(VDAC0, 1, FN_VDAC0_CH1, false, 0, &pin_PB1), + DAC(VDAC1, 0, FN_VDAC1_CH0, false, 0, &pin_PB2), + DAC(VDAC1, 1, FN_VDAC1_CH1, false, 0, &pin_PB3), +}; + +// Construct analogout pin. This function is called when init analogout +void common_hal_analogio_analogout_construct(analogio_analogout_obj_t *self, + const mcu_pin_obj_t *pin) { + uint8_t dac_num = DAC_BANK_ARRAY_LEN; + mcu_dac_pin_obj_t *p_dac; + uint8_t dac_index; + + if (self->dac == NULL) { + for (dac_index = 0; dac_index < dac_num; dac_index++) { + p_dac = &mcu_dac_list[dac_index]; + + if (p_dac->pin == pin) { + self->dac = p_dac; + self->dac->is_used = true; + self->dac->value = 0; + break; + } + } + } + + if (self->dac == NULL) { + mp_raise_ValueError(translate("DAC Device Init Error")); + } + + // Use default settings + VDAC_Init_TypeDef init = VDAC_INIT_DEFAULT; + VDAC_InitChannel_TypeDef initChannel = VDAC_INITCHANNEL_DEFAULT; + + // Use the HFRCOEM23 to clock the VDAC in order to operate in EM3 mode + CMU_ClockSelectSet(self->dac->vdac == VDAC0 ? + cmuClock_VDAC0:cmuClock_VDAC1, cmuSelect_HFRCOEM23); + + // Enable the HFRCOEM23 and VDAC clocks + CMU_ClockEnable(cmuClock_HFRCOEM23, true); + CMU_ClockEnable(self->dac->vdac == VDAC0 ? + cmuClock_VDAC0 : cmuClock_VDAC1, true); + + // Calculate the VDAC clock prescaler value resulting in a 1 MHz VDAC clock + init.prescaler = VDAC_PrescaleCalc(VDAC0, CLK_VDAC_FREQ); + + init.reference = vdacRef2V5; + // Clocking is requested on demand + init.onDemandClk = false; + + // Disable High Capacitance Load mode + initChannel.highCapLoadEnable = false; + + // Use Low Power mode + initChannel.powerMode = vdacPowerModeLowPower; + + // Initialize the VDAC and VDAC channel + VDAC_Init(self->dac->vdac, &init); + + VDAC_InitChannel(self->dac->vdac, &initChannel, self->dac->channel); + + // Enable the VDAC + VDAC_Enable(self->dac->vdac, self->dac->channel, true); + + for (dac_index = 0; dac_index < dac_num; dac_index++) { + p_dac = &mcu_dac_list[dac_index]; + + if (p_dac->vdac == self->dac->vdac && p_dac->pin != self->dac->pin + && p_dac->is_used == true) { + VDAC_InitChannel(p_dac->vdac, &initChannel, p_dac->channel); + VDAC_Enable(p_dac->vdac, p_dac->channel, true); + VDAC_ChannelOutputSet(p_dac->vdac, p_dac->channel, + p_dac->value >> 4); + break; + } + } + + VDAC_ChannelOutputSet(self->dac->vdac, self->dac->channel, 0); + + common_hal_mcu_pin_claim(pin); +} + +// Check obj is deinited or not +bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) { + return self->dac == NULL; +} + +// Deinit analogout obj +void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) { + uint8_t dac_num = DAC_BANK_ARRAY_LEN; + mcu_dac_pin_obj_t *p_dac; + uint8_t dac_index; + VDAC_Enable(self->dac->vdac, self->dac->channel, false); + + for (dac_index = 0; dac_index < dac_num; dac_index++) { + p_dac = &mcu_dac_list[dac_index]; + if (p_dac->vdac == self->dac->vdac && p_dac->pin != self->dac->pin + && p_dac->is_used == false) { + VDAC_Reset(self->dac->vdac); + } + } + common_hal_reset_pin(self->dac->pin); + + self->dac->value = 0; + self->dac->is_used = false; + self->dac = NULL; +} + +// Set value for dac pin +// dac value 0 - 65535 (0 - 2.5V) +void common_hal_analogio_analogout_set_value(analogio_analogout_obj_t *self, + uint16_t value) { + self->dac->value = value; + // Write the output value to VDAC DATA register + VDAC_ChannelOutputSet(self->dac->vdac, self->dac->channel, value >> 4); +} + +// Function reset dac peripheral +void analogout_reset(void) { + uint8_t dac_index; + mcu_dac_pin_obj_t *p_dac; + for (dac_index = 0; dac_index < DAC_BANK_ARRAY_LEN; dac_index++) { + p_dac = &mcu_dac_list[dac_index]; + if (p_dac->is_used == true) { + VDAC_Reset(p_dac->vdac); + } + } +} diff --git a/ports/silabs/common-hal/analogio/AnalogOut.h b/ports/silabs/common-hal/analogio/AnalogOut.h new file mode 100644 index 0000000000..a8a8e8f9ae --- /dev/null +++ b/ports/silabs/common-hal/analogio/AnalogOut.h @@ -0,0 +1,42 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR32_COMMON_HAL_ANALOGIO_ANALOGOUT_H +#define MICROPY_INCLUDED_EFR32_COMMON_HAL_ANALOGIO_ANALOGOUT_H + +#include "common-hal/microcontroller/Pin.h" +#include "py/obj.h" +#include "peripherals/periph.h" + +typedef struct +{ + mp_obj_base_t base; + mcu_dac_pin_obj_t *dac; +} analogio_analogout_obj_t; + +void analogout_reset(void); + +#endif // MICROPY_INCLUDED_EFR32_COMMON_HAL_ANALOGIO_ANALOGOUT_H diff --git a/ports/silabs/common-hal/analogio/__init__.c b/ports/silabs/common-hal/analogio/__init__.c new file mode 100644 index 0000000000..eea58c77d6 --- /dev/null +++ b/ports/silabs/common-hal/analogio/__init__.c @@ -0,0 +1 @@ +// No analogio module functions. diff --git a/ports/silabs/common-hal/board/__init__.c b/ports/silabs/common-hal/board/__init__.c new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ports/silabs/common-hal/busio/I2C.c b/ports/silabs/common-hal/busio/I2C.c new file mode 100644 index 0000000000..6d858be85e --- /dev/null +++ b/ports/silabs/common-hal/busio/I2C.c @@ -0,0 +1,212 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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/busio/I2C.h" +#include "py/mperrno.h" +#include "py/runtime.h" +#include "shared-bindings/microcontroller/__init__.h" +#include "supervisor/shared/translate/translate.h" +#include "shared-bindings/microcontroller/Pin.h" + +STATIC I2CSPM_Init_TypeDef i2cspm_init; +STATIC bool in_used = false; +STATIC bool never_reset = false; + +// Reser I2C peripheral +void i2c_reset(void) { + if ((!never_reset) && in_used) { + I2C_Reset(DEFAULT_I2C_PERIPHERAL); + in_used = false; + } +} + +// Construct I2C protocol, this function init i2c peripheral +void common_hal_busio_i2c_construct(busio_i2c_obj_t *self, + const mcu_pin_obj_t *scl, + const mcu_pin_obj_t *sda, + uint32_t frequency, uint32_t timeout) { + + if ((scl != NULL) && (sda != NULL)) { + if (scl->function_list[ DEFAULT_I2C_PERIPHERAL == I2C1? + FN_I2C1_SCL : FN_I2C0_SCL] == 1 && + scl->function_list[DEFAULT_I2C_PERIPHERAL == I2C1? + FN_I2C1_SDA : FN_I2C0_SDA] == 1) { + self->scl = scl; + self->sda = sda; + self->has_lock = false; + i2cspm_init.sclPort = self->scl->port; + i2cspm_init.sclPin = self->scl->number; + i2cspm_init.sdaPort = self->sda->port; + i2cspm_init.sdaPin = self->sda->number; + i2cspm_init.port = DEFAULT_I2C_PERIPHERAL; + i2cspm_init.i2cRefFreq = 0; + i2cspm_init.i2cMaxFreq = I2C_FREQ_STANDARD_MAX; + i2cspm_init.i2cClhr = i2cClockHLRStandard; + + self->i2cspm = i2cspm_init.port; + I2CSPM_Init(&i2cspm_init); + common_hal_mcu_pin_claim(scl); + common_hal_mcu_pin_claim(sda); + in_used = true; + } else { + mp_raise_ValueError(translate("Hardware busy, try alternative pins")); + } + } else { + raise_ValueError_invalid_pins(); + } +} + +// Never reset I2C obj when reload +void common_hal_busio_i2c_never_reset(busio_i2c_obj_t *self) { + never_reset = true; + common_hal_never_reset_pin(self->sda); + common_hal_never_reset_pin(self->scl); +} + +// Check I2C status, deinited or not +bool common_hal_busio_i2c_deinited(busio_i2c_obj_t *self) { + return self->sda == NULL; +} + +// Deinit i2c obj, reset I2C pin +void common_hal_busio_i2c_deinit(busio_i2c_obj_t *self) { + if (common_hal_busio_i2c_deinited(self)) { + return; + } + I2C_Reset(self->i2cspm); + common_hal_reset_pin(self->sda); + common_hal_reset_pin(self->scl); + self->sda = NULL; + self->scl = NULL; + self->i2cspm = NULL; + in_used = false; +} + +// Probe device in I2C bus +bool common_hal_busio_i2c_probe(busio_i2c_obj_t *self, uint8_t addr) { + I2C_TransferSeq_TypeDef seq; + I2C_TransferReturn_TypeDef ret; + uint8_t data = 0; + + seq.addr = addr << 1; + seq.flags = I2C_FLAG_READ; + + seq.buf[0].data = &data; + seq.buf[0].len = 1; + + ret = I2CSPM_Transfer(self->i2cspm, &seq); + if (ret != i2cTransferDone) { + return false; + } + return true; +} + +// Lock I2C bus +bool common_hal_busio_i2c_try_lock(busio_i2c_obj_t *self) { + bool grabbed_lock = false; + + if (!self->has_lock) { + grabbed_lock = true; + self->has_lock = true; + } + + return grabbed_lock; +} + +// Check I2C lock status +bool common_hal_busio_i2c_has_lock(busio_i2c_obj_t *self) { + return self->has_lock; +} + +// Unlock I2C bus +void common_hal_busio_i2c_unlock(busio_i2c_obj_t *self) { + self->has_lock = false; +} + +// Write data to the device selected by address +uint8_t common_hal_busio_i2c_write(busio_i2c_obj_t *self, uint16_t addr, + const uint8_t *data, size_t len) { + + I2C_TransferSeq_TypeDef seq; + I2C_TransferReturn_TypeDef ret; + + seq.addr = addr << 1; + seq.flags = I2C_FLAG_WRITE; + + seq.buf[0].data = (uint8_t *)data; + seq.buf[0].len = len; + + ret = I2CSPM_Transfer(self->i2cspm, &seq); + if (ret != i2cTransferDone) { + return MP_EIO; + } + return 0; +} + +// Read into buffer from the device selected by address +uint8_t common_hal_busio_i2c_read(busio_i2c_obj_t *self, + uint16_t addr, + uint8_t *data, size_t len) { + + I2C_TransferSeq_TypeDef seq; + I2C_TransferReturn_TypeDef ret; + + seq.addr = addr << 1; + seq.flags = I2C_FLAG_READ; + + seq.buf[0].data = data; + seq.buf[0].len = len; + + ret = I2CSPM_Transfer(self->i2cspm, &seq); + if (ret != i2cTransferDone) { + return MP_EIO; + } + return 0; +} + +// Write the bytes from out_data to the device selected by address, +uint8_t common_hal_busio_i2c_write_read(busio_i2c_obj_t *self, uint16_t addr, + uint8_t *out_data, size_t out_len, + uint8_t *in_data, size_t in_len) { + + I2C_TransferSeq_TypeDef seq; + I2C_TransferReturn_TypeDef ret; + + seq.addr = addr << 1; + seq.flags = I2C_FLAG_WRITE_READ; + // Select command to issue + seq.buf[0].data = out_data; + seq.buf[0].len = out_len; + // Select location/length of data to be read + seq.buf[1].data = in_data; + seq.buf[1].len = in_len; + + ret = I2CSPM_Transfer(self->i2cspm, &seq); + if (ret != i2cTransferDone) { + return MP_EIO; + } + return 0; +} diff --git a/ports/silabs/common-hal/busio/I2C.h b/ports/silabs/common-hal/busio/I2C.h new file mode 100644 index 0000000000..14f879ee44 --- /dev/null +++ b/ports/silabs/common-hal/busio/I2C.h @@ -0,0 +1,46 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR32_COMMON_HAL_BUSIO_I2C_H +#define MICROPY_INCLUDED_EFR32_COMMON_HAL_BUSIO_I2C_H + +#include "common-hal/microcontroller/Pin.h" +#include "peripherals/periph.h" +#include "py/obj.h" +#include "em_i2c.h" +#include "sl_i2cspm.h" + +typedef struct { + mp_obj_base_t base; + I2C_TypeDef *i2cspm; + bool has_lock; + const mcu_pin_obj_t *scl; + const mcu_pin_obj_t *sda; +} busio_i2c_obj_t; + +void i2c_reset(void); + +#endif // MICROPY_INCLUDED_EFR32_COMMON_HAL_BUSIO_I2C_H diff --git a/ports/silabs/common-hal/busio/SPI.c b/ports/silabs/common-hal/busio/SPI.c new file mode 100644 index 0000000000..a6f3109a32 --- /dev/null +++ b/ports/silabs/common-hal/busio/SPI.c @@ -0,0 +1,252 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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/busio/SPI.h" +#include "py/mperrno.h" +#include "py/runtime.h" +#include "shared-bindings/microcontroller/__init__.h" +#include "supervisor/board.h" +#include "supervisor/shared/translate/translate.h" +#include "shared-bindings/microcontroller/Pin.h" + +// Note that any bugs introduced in this file can cause crashes +// at startupfor chips using external SPI flash. + +STATIC SPIDRV_HandleData_t spidrv_eusart_handle; +STATIC SPIDRV_Init_t spidrv_eusart_init = SPIDRV_MASTER_EUSART1; +STATIC bool in_used = false; +STATIC bool never_reset = false; + +// Reset SPI when reload +void spi_reset(void) { + if (!never_reset && in_used) { + SPIDRV_DeInit(&spidrv_eusart_handle); + in_used = false; + } + return; +} + +// Construct SPI protocol, this function init SPI peripheral +void common_hal_busio_spi_construct(busio_spi_obj_t *self, + const mcu_pin_obj_t *sck, + const mcu_pin_obj_t *mosi, + const mcu_pin_obj_t *miso, + bool half_duplex) { + Ecode_t sc = ECODE_OK; + + if (half_duplex) { + mp_raise_NotImplementedError( + translate("Half duplex SPI is not implemented")); + } + + if ((sck != NULL) && (mosi != NULL) && (miso != NULL)) { + if (sck->function_list[FN_EUSART1_SCLK] == 1 + && miso->function_list[FN_EUSART1_RX] == 1 + && mosi->function_list[FN_EUSART1_TX] == 1) { + + self->sck = sck; + self->mosi = mosi; + self->miso = miso; + self->handle = &spidrv_eusart_handle; + self->polarity = 0; + self->phase = 0; + self->bits = 8; + + spidrv_eusart_init.portTx = mosi->port; + spidrv_eusart_init.portRx = miso->port; + spidrv_eusart_init.portClk = sck->port; + spidrv_eusart_init.pinTx = mosi->number; + spidrv_eusart_init.pinRx = miso->number; + spidrv_eusart_init.pinClk = sck->number; + spidrv_eusart_init.bitRate = 1000000; + spidrv_eusart_init.frameLength = 8; + spidrv_eusart_init.dummyTxValue = 0; + spidrv_eusart_init.type = spidrvMaster; + spidrv_eusart_init.bitOrder = spidrvBitOrderMsbFirst; + spidrv_eusart_init.clockMode = spidrvClockMode0; + spidrv_eusart_init.csControl = spidrvCsControlApplication; + spidrv_eusart_init.slaveStartMode = spidrvSlaveStartImmediate; + + sc = SPIDRV_Init(self->handle, &spidrv_eusart_init); + if (sc != ECODE_EMDRV_SPIDRV_OK) { + mp_raise_ValueError(translate("SPI init error")); + } + } else { + mp_raise_ValueError(translate("Hardware busy, try alternative pins")); + } + } else { + raise_ValueError_invalid_pins(); + } + + in_used = true; + common_hal_mcu_pin_claim(sck); + common_hal_mcu_pin_claim(mosi); + common_hal_mcu_pin_claim(miso); +} + +// Never reset SPI when reload +void common_hal_busio_spi_never_reset(busio_spi_obj_t *self) { + never_reset = true; + common_hal_never_reset_pin(self->mosi); + common_hal_never_reset_pin(self->miso); + common_hal_never_reset_pin(self->sck); +} + +// Check SPI status, deinited or not +bool common_hal_busio_spi_deinited(busio_spi_obj_t *self) { + return self->sck == NULL; +} + +// Deinit SPI obj +void common_hal_busio_spi_deinit(busio_spi_obj_t *self) { + + if (common_hal_busio_spi_deinited(self)) { + return; + } + + Ecode_t sc = SPIDRV_DeInit(self->handle); + if (sc != ECODE_EMDRV_SPIDRV_OK) { + mp_raise_RuntimeError(translate("SPI re-init")); + } + + in_used = false; + self->sck = NULL; + self->mosi = NULL; + self->miso = NULL; + self->handle = NULL; + common_hal_reset_pin(self->mosi); + common_hal_reset_pin(self->miso); + common_hal_reset_pin(self->sck); +} + +// Configures the SPI bus. The SPI object must be locked. +bool common_hal_busio_spi_configure(busio_spi_obj_t *self, + uint32_t baudrate, + uint8_t polarity, + uint8_t phase, + uint8_t bits) { + Ecode_t sc; + // This resets the SPI, so check before updating it redundantly + if (baudrate == self->baudrate && polarity == self->polarity + && phase == self->phase && bits == self->bits) { + return true; + } + + sc = SPIDRV_DeInit(self->handle); + if (sc != ECODE_EMDRV_SPIDRV_OK) { + mp_raise_RuntimeError(translate("SPI re-init")); + } + in_used = false; + self->baudrate = baudrate; + self->phase = phase; + self->bits = bits; + self->polarity = polarity; + + spidrv_eusart_init.bitRate = baudrate; + spidrv_eusart_init.frameLength = 8; + if (polarity == 0 && phase == 0) { + spidrv_eusart_init.clockMode = spidrvClockMode0; + } else if (polarity == 0 && phase == 1) { + spidrv_eusart_init.clockMode = spidrvClockMode1; + } else if (polarity == 1 && phase == 0) { + spidrv_eusart_init.clockMode = spidrvClockMode2; + } else if (polarity == 1 && phase == 1) { + spidrv_eusart_init.clockMode = spidrvClockMode3; + } + + sc = SPIDRV_Init(self->handle, &spidrv_eusart_init); + if (sc != ECODE_EMDRV_SPIDRV_OK) { + mp_raise_RuntimeError(translate("SPI re-init")); + } + in_used = true; + return true; +} + +// Lock SPI bus +bool common_hal_busio_spi_try_lock(busio_spi_obj_t *self) { + bool grabbed_lock = false; + if (!self->has_lock) { + grabbed_lock = true; + self->has_lock = true; + } + + return grabbed_lock; +} + +// Check SPI lock status +bool common_hal_busio_spi_has_lock(busio_spi_obj_t *self) { + return self->has_lock; +} + +// Unlock SPI bus +void common_hal_busio_spi_unlock(busio_spi_obj_t *self) { + self->has_lock = false; +} + +// Write the data contained in buffer +bool common_hal_busio_spi_write(busio_spi_obj_t *self, + const uint8_t *data, + size_t len) { + + Ecode_t result = SPIDRV_MTransmitB(self->handle, data, len); + return result == ECODE_EMDRV_SPIDRV_OK; +} + +// Read data into buffer +bool common_hal_busio_spi_read(busio_spi_obj_t *self, + uint8_t *data, size_t len, + uint8_t write_value) { + + self->handle->initData.dummyTxValue = write_value; + Ecode_t result = SPIDRV_MReceiveB(self->handle, data, len); + return result == ECODE_EMDRV_SPIDRV_OK; +} + +// Write out the data in data_out +// while simultaneously reading data into data_in +bool common_hal_busio_spi_transfer(busio_spi_obj_t *self, + const uint8_t *data_out, + uint8_t *data_in, + size_t len) { + + Ecode_t result = SPIDRV_MTransferB(self->handle, data_out, data_in, len); + return result == ECODE_EMDRV_SPIDRV_OK; +} + +// Get SPI baudrate +uint32_t common_hal_busio_spi_get_frequency(busio_spi_obj_t *self) { + return self->baudrate; +} + +// Get SPI phase +uint8_t common_hal_busio_spi_get_phase(busio_spi_obj_t *self) { + return self->phase; +} + +// Get SPI polarity +uint8_t common_hal_busio_spi_get_polarity(busio_spi_obj_t *self) { + return self->polarity; +} diff --git a/ports/silabs/common-hal/busio/SPI.h b/ports/silabs/common-hal/busio/SPI.h new file mode 100644 index 0000000000..f81316cda1 --- /dev/null +++ b/ports/silabs/common-hal/busio/SPI.h @@ -0,0 +1,52 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR32_COMMON_HAL_BUSIO_SPI_H +#define MICROPY_INCLUDED_EFR32_COMMON_HAL_BUSIO_SPI_H + +#include "common-hal/microcontroller/Pin.h" +#include "peripherals/periph.h" +#include "py/obj.h" +#include "spidrv.h" + +typedef struct { + mp_obj_base_t base; + SPIDRV_Handle_t handle; + bool has_lock; + const mcu_pin_obj_t *sck; + const mcu_pin_obj_t *mosi; + const mcu_pin_obj_t *miso; + const mcu_pin_obj_t *nss; + uint32_t baudrate; + uint16_t prescaler; + uint8_t polarity; + uint8_t phase; + uint8_t bits; +} busio_spi_obj_t; + +void spi_reset(void); + +#endif // MICROPY_INCLUDED_EFR32_COMMON_HAL_BUSIO_SPI_H diff --git a/ports/silabs/common-hal/busio/UART.c b/ports/silabs/common-hal/busio/UART.c new file mode 100644 index 0000000000..8b1883d906 --- /dev/null +++ b/ports/silabs/common-hal/busio/UART.c @@ -0,0 +1,299 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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/__init__.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/busio/UART.h" + +#include "mpconfigport.h" +#include "shared/readline/readline.h" +#include "shared/runtime/interrupt_char.h" +#include "py/gc.h" +#include "py/mperrno.h" +#include "py/runtime.h" +#include "py/stream.h" +#include "supervisor/shared/translate/translate.h" + +#define UARTDRV_USART_BUFFER_SIZE 6 + +// Define RX and TX buffer queues +DEFINE_BUF_QUEUE(UARTDRV_USART_BUFFER_SIZE, uartdrv_usart_rx_buffer); +DEFINE_BUF_QUEUE(UARTDRV_USART_BUFFER_SIZE, uartdrv_usart_tx_buffer); + +STATIC UARTDRV_HandleData_t uartdrv_usart_handle; +STATIC UARTDRV_InitUart_t uartdrv_usart_init; +STATIC bool in_used = false; +STATIC bool never_reset = false; +busio_uart_obj_t *context; +volatile Ecode_t errflag; // Used to restart read halts + +// Reset uart peripheral +void uart_reset(void) { + if ((!never_reset) && in_used) { + if (UARTDRV_DeInit(&uartdrv_usart_handle) != ECODE_EMDRV_UARTDRV_OK) { + mp_raise_ValueError(translate("UART Deinit fail")); + } + in_used = false; + } +} + +// Construct uart obj +void common_hal_busio_uart_construct(busio_uart_obj_t *self, + const mcu_pin_obj_t *tx, + const mcu_pin_obj_t *rx, + const mcu_pin_obj_t *rts, + const mcu_pin_obj_t *cts, + const mcu_pin_obj_t *rs485_dir, + bool rs485_invert, + uint32_t baudrate, + uint8_t bits, + busio_uart_parity_t parity, + uint8_t stop, + mp_float_t timeout, + uint16_t receiver_buffer_size, + byte *receiver_buffer, + bool sigint_enabled) { + + if ((rts != NULL) || (cts != NULL) || (rs485_dir != NULL) + || (rs485_invert == true)) { + mp_raise_NotImplementedError(translate("RS485")); + } + + if ((tx != NULL) && (rx != NULL)) { + if (tx->function_list[FN_USART0_TX] == 1 + && tx->function_list[FN_USART0_RX] == 1) { + + self->handle = &uartdrv_usart_handle; + self->baudrate = baudrate; + self->tx = tx; + self->rx = rx; + self->sigint_enabled = sigint_enabled; + self->timeout_ms = timeout * 1000; + uartdrv_usart_init.port = USART0; + uartdrv_usart_init.baudRate = baudrate; + uartdrv_usart_init.txPort = tx->port; + uartdrv_usart_init.rxPort = rx->port; + uartdrv_usart_init.txPin = tx->number; + uartdrv_usart_init.rxPin = rx->number; + uartdrv_usart_init.uartNum = 0; + uartdrv_usart_init.stopBits = (stop >= 2) ? usartStopbits2 + :usartStopbits1; + uartdrv_usart_init.parity = (USART_Parity_TypeDef)parity; + uartdrv_usart_init.oversampling = usartOVS4; + uartdrv_usart_init.mvdis = false; + uartdrv_usart_init.fcType = uartdrvFlowControlNone; + + uartdrv_usart_init.rxQueue = (UARTDRV_Buffer_FifoQueue_t *) + &uartdrv_usart_rx_buffer; + uartdrv_usart_init.txQueue = (UARTDRV_Buffer_FifoQueue_t *) + &uartdrv_usart_tx_buffer; + + if (UARTDRV_InitUart(self->handle,&uartdrv_usart_init) + != ECODE_EMDRV_UARTDRV_OK) { + mp_raise_RuntimeError(translate("UART init")); + } + common_hal_mcu_pin_claim(tx); + common_hal_mcu_pin_claim(rx); + in_used = true; + + // Use the provided buffer when given. + if (receiver_buffer != NULL) { + ringbuf_init(&self->ringbuf, receiver_buffer, receiver_buffer_size); + } else { + if (!ringbuf_alloc(&self->ringbuf, receiver_buffer_size, true)) { + m_malloc_fail(receiver_buffer_size); + } + } + errflag = ECODE_EMDRV_UARTDRV_OK; + context = self; + + } else { + mp_raise_ValueError(translate("Hardware busy, try alternative pins")); + } + + } else { + raise_ValueError_invalid_pins(); + } +} + +// Never reset UART obj when reload +void common_hal_busio_uart_never_reset(busio_uart_obj_t *self) { + never_reset = true; + common_hal_never_reset_pin(self->tx); + common_hal_never_reset_pin(self->rx); + return; +} + +// Check Uart status, deinited or not +bool common_hal_busio_uart_deinited(busio_uart_obj_t *self) { + return self->handle == NULL; +} + +// Deinit uart obj +void common_hal_busio_uart_deinit(busio_uart_obj_t *self) { + if (common_hal_busio_uart_deinited(self)) { + return; + } + + if (UARTDRV_DeInit(self->handle) != ECODE_EMDRV_UARTDRV_OK) { + mp_raise_RuntimeError(translate("UART de-init")); + } + + common_hal_reset_pin(self->rx); + common_hal_reset_pin(self->tx); + self->tx = NULL; + self->rx = NULL; + self->handle = NULL; + in_used = false; +} + +// Callback function for UARTDRV_Receive +void UARTDRV_Receive_Callback(UARTDRV_Handle_t *handle, + Ecode_t transferStatus, + uint8_t *data, + UARTDRV_Count_t transferCount) { + (void)handle; + (void)transferStatus; + (void)data; + (void)transferCount; + + taskENTER_CRITICAL(); + ringbuf_put_n(&context->ringbuf, &context->rx_char, 1); + taskEXIT_CRITICAL(); + errflag = UARTDRV_Receive(context->handle,&context->rx_char,1, + (UARTDRV_Callback_t)UARTDRV_Receive_Callback); + if (context->sigint_enabled) { + if (context->rx_char == CHAR_CTRL_C) { + common_hal_busio_uart_clear_rx_buffer(context); + mp_sched_keyboard_interrupt(); + } + } +} + +// Read bytes. If nbytes is specified then read at most that many bytes. +// Otherwise, read everything that arrives until the connection times out. +// Providing the number of bytes expected is highly recommended because it will be faster. +// If no bytes are read, return None. +size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, + size_t len, int *errcode) { + + uint64_t start_ticks = supervisor_ticks_ms64(); + if (len == 0) { + // Nothing to read. + return 0; + } + errflag = ECODE_EMDRV_UARTDRV_WAITING; + // Wait for all bytes received or timeout, same as nrf + while ((ringbuf_num_filled(&self->ringbuf) < len) && + (supervisor_ticks_ms64() - start_ticks < self->timeout_ms)) { + + RUN_BACKGROUND_TASKS; + // restart if it failed in the callback + if (errflag != ECODE_EMDRV_UARTDRV_OK) { + errflag = UARTDRV_Receive(self->handle,&self->rx_char,1, + (UARTDRV_Callback_t)UARTDRV_Receive_Callback); + } + // Allow user to break out of a timeout with a KeyboardInterrupt. + if (mp_hal_is_interrupted()) { + return 0; + } + } + + taskENTER_CRITICAL(); + // Copy as much received data as available, up to len bytes. + size_t rx_bytes = ringbuf_get_n(&self->ringbuf, data, len); + taskEXIT_CRITICAL(); + + if (rx_bytes == 0) { + *errcode = EAGAIN; + return MP_STREAM_ERROR; + } + return rx_bytes; +} + +// Write the buffer of bytes to the bus. +size_t common_hal_busio_uart_write(busio_uart_obj_t *self, + const uint8_t *data, + size_t len, + int *errcode) { + + Ecode_t ret = UARTDRV_TransmitB(self->handle, (uint8_t *)data, len); + if (ret != ECODE_EMDRV_UARTDRV_OK) { + mp_raise_RuntimeError(translate("UART write")); + } + return len; +} + +// Get uart baudrate value +uint32_t common_hal_busio_uart_get_baudrate(busio_uart_obj_t *self) { + return self->baudrate; +} + +// Set uart baudrate value +void common_hal_busio_uart_set_baudrate(busio_uart_obj_t *self, + uint32_t baudrate) { + + // Don't reset if it's the same value + if (baudrate == self->baudrate) { + return; + } + uartdrv_usart_init.baudRate = baudrate; + if (UARTDRV_InitUart(self->handle, &uartdrv_usart_init) + != ECODE_EMDRV_UARTDRV_OK) { + mp_raise_RuntimeError(translate("UART re-init")); + } +} + +// Get timeout for receive +mp_float_t common_hal_busio_uart_get_timeout(busio_uart_obj_t *self) { + return (mp_float_t)(self->timeout_ms / 1000.0f); +} + +// Set timeout for receive +void common_hal_busio_uart_set_timeout(busio_uart_obj_t *self, + mp_float_t timeout) { + self->timeout_ms = timeout * 1000; +} + +// Query characters available to read +uint32_t common_hal_busio_uart_rx_characters_available(busio_uart_obj_t *self) { + return ringbuf_num_filled(&self->ringbuf); +} + +// Clear rx buffer +void common_hal_busio_uart_clear_rx_buffer(busio_uart_obj_t *self) { + taskENTER_CRITICAL(); + ringbuf_clear(&self->ringbuf); + taskEXIT_CRITICAL(); + self->handle->rxQueue->head = 0; + self->handle->rxQueue->tail = 0; + self->handle->rxQueue->used = 0; +} + +// Check uart bus ready to transmit or not +bool common_hal_busio_uart_ready_to_tx(busio_uart_obj_t *self) { + return UARTDRV_GetTransmitDepth(self->handle) == 0; +} diff --git a/ports/silabs/common-hal/busio/UART.h b/ports/silabs/common-hal/busio/UART.h new file mode 100644 index 0000000000..50d43d5cd6 --- /dev/null +++ b/ports/silabs/common-hal/busio/UART.h @@ -0,0 +1,52 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR32_COMMON_HAL_BUSIO_UART_H +#define MICROPY_INCLUDED_EFR32_COMMON_HAL_BUSIO_UART_H + +#include "common-hal/microcontroller/Pin.h" +#include "peripherals/periph.h" +#include "py/obj.h" +#include "py/ringbuf.h" +#include "uartdrv.h" +#include "FreeRTOS.h" +#include "task.h" + +typedef struct { + mp_obj_base_t base; + UARTDRV_Handle_t handle; + const mcu_pin_obj_t *rx; + const mcu_pin_obj_t *tx; + ringbuf_t ringbuf; + uint8_t rx_char; + uint32_t baudrate; + uint32_t timeout_ms; + bool sigint_enabled; +} busio_uart_obj_t; + +void uart_reset(void); + +#endif // MICROPY_INCLUDED_EFR32_COMMON_HAL_BUSIO_UART_H diff --git a/ports/silabs/common-hal/busio/__init__.c b/ports/silabs/common-hal/busio/__init__.c new file mode 100644 index 0000000000..41761b6743 --- /dev/null +++ b/ports/silabs/common-hal/busio/__init__.c @@ -0,0 +1 @@ +// No busio module functions. diff --git a/ports/silabs/common-hal/digitalio/DigitalInOut.c b/ports/silabs/common-hal/digitalio/DigitalInOut.c new file mode 100644 index 0000000000..0f266bb41e --- /dev/null +++ b/ports/silabs/common-hal/digitalio/DigitalInOut.c @@ -0,0 +1,159 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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/digitalio/DigitalInOut.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "py/runtime.h" +#include "supervisor/shared/translate/translate.h" + +// Never reset pin when reload +void common_hal_digitalio_digitalinout_never_reset( + digitalio_digitalinout_obj_t *self) { + common_hal_never_reset_pin(self->pin); +} + +// Construct Digitalio obj +digitalinout_result_t common_hal_digitalio_digitalinout_construct( + digitalio_digitalinout_obj_t *self, const mcu_pin_obj_t *pin) { + common_hal_mcu_pin_claim(pin); + self->pin = pin; + GPIO_PinModeSet(pin->port, pin->number, gpioModeInput, 1); + return DIGITALINOUT_OK; +} + +// Check Digitalio status, deinited or not +bool common_hal_digitalio_digitalinout_deinited( + digitalio_digitalinout_obj_t *self) { + return self->pin == NULL; +} + +// Deinit Digitalio obj +void common_hal_digitalio_digitalinout_deinit( + digitalio_digitalinout_obj_t *self) { + if (common_hal_digitalio_digitalinout_deinited(self)) { + return; + } + common_hal_reset_pin(self->pin); + self->pin = NULL; +} + +// Switch pin to input +digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_input( + digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { + if (pull == PULL_NONE) { + GPIO_PinModeSet(self->pin->port,self->pin->number,gpioModeInput,1); + } else if (pull == PULL_UP) { + GPIO_PinModeSet(self->pin->port,self->pin->number,gpioModeInputPull,1); + } else { + GPIO_PinModeSet(self->pin->port,self->pin->number,gpioModeInputPull,0); + } + return DIGITALINOUT_OK; +} + +// Switch pin to output +digitalinout_result_t common_hal_digitalio_digitalinout_switch_to_output( + digitalio_digitalinout_obj_t *self, bool value, + digitalio_drive_mode_t drive_mode) { + if (drive_mode == DRIVE_MODE_OPEN_DRAIN) { + GPIO_PinModeSet(self->pin->port,self->pin->number, + gpioModeWiredAnd,value); + } else { + GPIO_PinModeSet(self->pin->port,self->pin->number, + gpioModePushPull,value); + } + + if (value) { + GPIO_PinOutSet(self->pin->port, self->pin->number); + } else { + GPIO_PinOutClear(self->pin->port, self->pin->number); + } + + return DIGITALINOUT_OK; +} + +// Get direction of the pin +digitalio_direction_t common_hal_digitalio_digitalinout_get_direction( + digitalio_digitalinout_obj_t *self) { + GPIO_Mode_TypeDef mode = GPIO_PinModeGet(self->pin->port,self->pin->number); + if (mode >= gpioModePushPull) { + return DIRECTION_OUTPUT; + } + return DIRECTION_INPUT; +} + +// Set digital logic level of the pin +void common_hal_digitalio_digitalinout_set_value( + digitalio_digitalinout_obj_t *self, bool value) { + if (value) { + GPIO_PinOutSet(self->pin->port, self->pin->number); + } else { + GPIO_PinOutClear(self->pin->port, self->pin->number); + } +} + +// The digital logic level of the pin +bool common_hal_digitalio_digitalinout_get_value( + digitalio_digitalinout_obj_t *self) { + if (common_hal_digitalio_digitalinout_get_direction(self) + == DIRECTION_OUTPUT) { + return GPIO_PinOutGet(self->pin->port, self->pin->number); + } + return GPIO_PinInGet(self->pin->port, self->pin->number); +} + +// Set drive mode +digitalinout_result_t common_hal_digitalio_digitalinout_set_drive_mode( + digitalio_digitalinout_obj_t *self, + digitalio_drive_mode_t drive_mode) { + if (drive_mode == DRIVE_MODE_OPEN_DRAIN) { + GPIO_PinModeSet(self->pin->port,self->pin->number,gpioModeWiredAnd,1); + } else { + GPIO_PinModeSet(self->pin->port,self->pin->number,gpioModePushPull,1); + } + return DIGITALINOUT_OK; +} + +// Get drive mode +digitalio_drive_mode_t common_hal_digitalio_digitalinout_get_drive_mode( + digitalio_digitalinout_obj_t *self) { + GPIO_Mode_TypeDef mode = GPIO_PinModeGet(self->pin->port,self->pin->number); + if (mode >= gpioModeWiredAnd) { + return DRIVE_MODE_OPEN_DRAIN; + } + return DRIVE_MODE_PUSH_PULL; +} + +// Set pull direction +digitalinout_result_t common_hal_digitalio_digitalinout_set_pull( + digitalio_digitalinout_obj_t *self, digitalio_pull_t pull) { + return DIGITALINOUT_OK; +} + +// Get pull direction +digitalio_pull_t common_hal_digitalio_digitalinout_get_pull( + digitalio_digitalinout_obj_t *self) { + return PULL_NONE; +} diff --git a/ports/silabs/common-hal/digitalio/DigitalInOut.h b/ports/silabs/common-hal/digitalio/DigitalInOut.h new file mode 100644 index 0000000000..23a5a23537 --- /dev/null +++ b/ports/silabs/common-hal/digitalio/DigitalInOut.h @@ -0,0 +1,39 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR32_COMMON_HAL_DIGITALIO_DIGITALINOUT_H +#define MICROPY_INCLUDED_EFR32_COMMON_HAL_DIGITALIO_DIGITALINOUT_H + +#include "common-hal/microcontroller/Pin.h" +#include "em_gpio.h" + +typedef struct +{ + mp_obj_base_t base; + const mcu_pin_obj_t *pin; +} digitalio_digitalinout_obj_t; + +#endif // MICROPY_INCLUDED_STM32_COMMON_HAL_DIGITALIO_DIGITALINOUT_H diff --git a/ports/silabs/common-hal/digitalio/__init__.c b/ports/silabs/common-hal/digitalio/__init__.c new file mode 100644 index 0000000000..20fad45959 --- /dev/null +++ b/ports/silabs/common-hal/digitalio/__init__.c @@ -0,0 +1 @@ +// No digitalio module functions. diff --git a/ports/silabs/common-hal/microcontroller/Pin.c b/ports/silabs/common-hal/microcontroller/Pin.c new file mode 100644 index 0000000000..24141522df --- /dev/null +++ b/ports/silabs/common-hal/microcontroller/Pin.c @@ -0,0 +1,115 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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/digitalio/DigitalInOut.h" +#include "py/mphal.h" +#include "em_gpio.h" + +#define GPIO_PORT_COUNT (MP_ARRAY_SIZE(ports)) + +GPIO_Port_TypeDef ports[] = {gpioPortA, gpioPortB, gpioPortC, gpioPortD}; +STATIC uint16_t claimed_pins[GPIO_PORT_COUNT]; +STATIC uint16_t __ALIGNED(4) never_reset_pins[GPIO_PORT_COUNT]; + +// Reset all pin except pin in never_reset_pins list +void reset_all_pins(void) { + + uint8_t pin_num; + uint8_t port_num; + // Reset claimed pins + for (pin_num = 0; pin_num < GPIO_PORT_COUNT; pin_num++) { + claimed_pins[pin_num] = never_reset_pins[pin_num]; + } + + for (port_num = 0; port_num < GPIO_PORT_COUNT; port_num++) { + for (pin_num = 0; pin_num < 16; pin_num++) { + if (GPIO_PORT_PIN_VALID(ports[port_num],pin_num) + && !(never_reset_pins[port_num] >> pin_num & 0x01)) { + GPIO_PinModeSet(ports[port_num], pin_num,gpioModeInput,1); + } + } + } +} + +// Mark pin as free and return it to a quiescent state. +void reset_pin_number(uint8_t pin_port, uint8_t pin_number) { + // Clear claimed bit & reset + claimed_pins[pin_port] &= ~(1 << pin_number); + never_reset_pins[pin_port] &= ~(1 << pin_number); + GPIO_PinModeSet(pin_port, pin_number, gpioModeInput, 1); +} + +// Mark pin as never reset +void never_reset_pin_number(uint8_t pin_port, uint8_t pin_number) { + never_reset_pins[pin_port] |= 1 << pin_number; + // Make sure never reset pins are also always claimed + claimed_pins[pin_port] |= 1 << pin_number; +} + +// Mark pin as never reset +void common_hal_never_reset_pin(const mcu_pin_obj_t *pin) { + never_reset_pin_number(pin->port, pin->number); +} + +// Reset pin +void common_hal_reset_pin(const mcu_pin_obj_t *pin) { + if (pin == NULL) { + return; + } + reset_pin_number(pin->port, pin->number); +} + +// Mark pin as in used +void claim_pin(uint8_t pin_port, uint8_t pin_number) { + // Set bit in claimed_pins bitmask. + claimed_pins[pin_port] |= 1 << pin_number; +} + +// Check pin status free or in used +bool pin_number_is_free(uint8_t pin_port, uint8_t pin_number) { + return !(claimed_pins[pin_port] & (1 << pin_number)); +} + +// Check pin status free or in used +bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t *pin) { + return pin_number_is_free(pin->port, pin->number); +} + +// Calculate pin number for a pin obj +uint8_t common_hal_mcu_pin_number(const mcu_pin_obj_t *pin) { + return pin->port * 16 + pin->number; +} + +// Mark pin is in used +void common_hal_mcu_pin_claim(const mcu_pin_obj_t *pin) { + claim_pin(pin->port, pin->number); +} + +// Reset pin by pin number +void common_hal_mcu_pin_reset_number(uint8_t pin_no) { + reset_pin_number(pin_no / 16, pin_no % 16); +} diff --git a/ports/silabs/common-hal/microcontroller/Pin.h b/ports/silabs/common-hal/microcontroller/Pin.h new file mode 100644 index 0000000000..20bf8a82f2 --- /dev/null +++ b/ports/silabs/common-hal/microcontroller/Pin.h @@ -0,0 +1,36 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR32_COMMON_HAL_MICROCONTROLLER_PIN_H +#define MICROPY_INCLUDED_EFR32_COMMON_HAL_MICROCONTROLLER_PIN_H + +#include "py/mphal.h" + +#include "peripherals/pins.h" + +void reset_all_pins(void); + +#endif // MICROPY_INCLUDED_EFR32_COMMON_HAL_MICROCONTROLLER_PIN_H diff --git a/ports/silabs/common-hal/microcontroller/Processor.c b/ports/silabs/common-hal/microcontroller/Processor.c new file mode 100644 index 0000000000..1414a28df6 --- /dev/null +++ b/ports/silabs/common-hal/microcontroller/Processor.c @@ -0,0 +1,67 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "py/runtime.h" + +#if CIRCUITPY_ALARM +#include "common-hal/alarm/__init__.h" +#endif +#include "common-hal/microcontroller/Processor.h" +#include "shared-bindings/microcontroller/ResetReason.h" +#include "supervisor/shared/translate/translate.h" +#include "tempdrv.h" +#include "em_system.h" +#include "em_cmu.h" + +float common_hal_mcu_processor_get_temperature(void) { + TEMPDRV_Init(); + return (float)TEMPDRV_GetTemp(); +} + +float common_hal_mcu_processor_get_voltage(void) { + // xG24 does not have built-in direct reading of processor voltage + // Have Only 1 of IADC, already used for analogio module + return 3.3f; +} + +uint32_t common_hal_mcu_processor_get_frequency(void) { + return CMU_ClockFreqGet(cmuClock_HCLK); +} + +void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { + + size_t byte_index; + uint64_t serial = SYSTEM_GetUnique(); + for (byte_index = 0; byte_index < sizeof(uint64_t); byte_index++) { + raw_id[byte_index] = (serial >> (64 - ((byte_index + 1) * 8))) & 0xff; + } +} + +mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void) { + return RESET_REASON_UNKNOWN; +} diff --git a/ports/silabs/common-hal/microcontroller/Processor.h b/ports/silabs/common-hal/microcontroller/Processor.h new file mode 100644 index 0000000000..7faea68da3 --- /dev/null +++ b/ports/silabs/common-hal/microcontroller/Processor.h @@ -0,0 +1,39 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR32_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H +#define MICROPY_INCLUDED_EFR32_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H + +#define COMMON_HAL_MCU_PROCESSOR_UID_LENGTH 12 + +#include "py/obj.h" + +typedef struct +{ + mp_obj_base_t base; +} mcu_processor_obj_t; + +#endif // MICROPY_INCLUDED_EFR32_COMMON_HAL_MICROCONTROLLER_PROCESSOR_H diff --git a/ports/silabs/common-hal/microcontroller/__init__.c b/ports/silabs/common-hal/microcontroller/__init__.c new file mode 100644 index 0000000000..b1472fcf43 --- /dev/null +++ b/ports/silabs/common-hal/microcontroller/__init__.c @@ -0,0 +1,223 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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/mphal.h" +#include "py/obj.h" +#include "py/runtime.h" + +#include "common-hal/microcontroller/Pin.h" +#include "common-hal/microcontroller/Processor.h" + +#include "shared-bindings/nvm/ByteArray.h" +#include "shared-bindings/microcontroller/__init__.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-bindings/microcontroller/Processor.h" + +#include "supervisor/filesystem.h" +#include "supervisor/shared/safe_mode.h" +#include "em_chip.h" +#include "em_core.h" +#include "sl_udelay.h" + +void common_hal_mcu_delay_us(uint32_t delay) { + sl_udelay_wait(delay); +} + +void common_hal_mcu_disable_interrupts(void) { + CORE_CriticalDisableIrq(); +} + +void common_hal_mcu_enable_interrupts(void) { + CORE_CriticalEnableIrq(); +} + +void common_hal_mcu_on_next_reset(mcu_runmode_t runmode) { + if (runmode == RUNMODE_SAFE_MODE) { + safe_mode_on_next_reset(SAFE_MODE_PROGRAMMATIC); + } +} + +void common_hal_mcu_reset(void) { + filesystem_flush(); // TODO: implement as part of flash improvements + CHIP_Reset(); +} + +// The singleton microcontroller.Processor object, bound to microcontroller.cpu +// It currently only has properties, and no state. +const mcu_processor_obj_t common_hal_mcu_processor_obj = { + .base = { + .type = &mcu_processor_type, + }, +}; + +#if CIRCUITPY_INTERNAL_NVM_SIZE > 0 +// The singleton nvm.ByteArray object. +const nvm_bytearray_obj_t common_hal_mcu_nvm_obj = { + .base = { + .type = &nvm_bytearray_type, + }, + .len = NVM_BYTEARRAY_BUFFER_SIZE +}; + +#endif + +#if CIRCUITPY_WATCHDOG +// The singleton watchdog.WatchDogTimer object. +watchdog_watchdogtimer_obj_t common_hal_mcu_watchdogtimer_obj = { + .base = { + .type = &watchdog_watchdogtimer_type, + }, + .timeout = 0.0f, + .mode = WATCHDOGMODE_NONE, +}; +#endif + +// This maps MCU pin names to pin objects. +const mp_rom_map_elem_t mcu_pin_global_dict_table[] = { + + #ifdef GPIO_PA0_EXISTS + { MP_ROM_QSTR(MP_QSTR_PA0), MP_ROM_PTR(&pin_PA0) }, + #endif + + #ifdef GPIO_PA1_EXISTS + { MP_ROM_QSTR(MP_QSTR_PA1), MP_ROM_PTR(&pin_PA1) }, + #endif + + #ifdef GPIO_PA2_EXISTS + { MP_ROM_QSTR(MP_QSTR_PA2), MP_ROM_PTR(&pin_PA2) }, + #endif + + #ifdef GPIO_PA3_EXISTS + { MP_ROM_QSTR(MP_QSTR_PA3), MP_ROM_PTR(&pin_PA3) }, + #endif + + #ifdef GPIO_PA4_EXISTS + { MP_ROM_QSTR(MP_QSTR_PA4), MP_ROM_PTR(&pin_PA4) }, + #endif + + #ifdef GPIO_PA5_EXISTS + { MP_ROM_QSTR(MP_QSTR_PA5), MP_ROM_PTR(&pin_PA5) }, + #endif + #ifdef GPIO_PA6_EXISTS + { MP_ROM_QSTR(MP_QSTR_PA6), MP_ROM_PTR(&pin_PA6) }, + #endif + + #ifdef GPIO_PA7_EXISTS + { MP_ROM_QSTR(MP_QSTR_PA7), MP_ROM_PTR(&pin_PA7) }, + #endif + + #ifdef GPIO_PA8_EXISTS + { MP_ROM_QSTR(MP_QSTR_PA8), MP_ROM_PTR(&pin_PA8) }, + #endif + + #ifdef GPIO_PB0_EXISTS + { MP_ROM_QSTR(MP_QSTR_PB0), MP_ROM_PTR(&pin_PB0) }, + #endif + + #ifdef GPIO_PB1_EXISTS + { MP_ROM_QSTR(MP_QSTR_PB1), MP_ROM_PTR(&pin_PB1) }, + #endif + + #ifdef GPIO_PB2_EXISTS + { MP_ROM_QSTR(MP_QSTR_PB2), MP_ROM_PTR(&pin_PB2) }, + #endif + + #ifdef GPIO_PB3_EXISTS + { MP_ROM_QSTR(MP_QSTR_PB3), MP_ROM_PTR(&pin_PB3) }, + #endif + + #ifdef GPIO_PB4_EXISTS + { MP_ROM_QSTR(MP_QSTR_PB4), MP_ROM_PTR(&pin_PB4) }, + #endif + + #ifdef GPIO_PB5_EXISTS + { MP_ROM_QSTR(MP_QSTR_PB5), MP_ROM_PTR(&pin_PB5) }, + #endif + + #ifdef GPIO_PC0_EXISTS + { MP_ROM_QSTR(MP_QSTR_PC0), MP_ROM_PTR(&pin_PC0) }, + #endif + + #ifdef GPIO_PC1_EXISTS + { MP_ROM_QSTR(MP_QSTR_PC1), MP_ROM_PTR(&pin_PC1) }, + #endif + + #ifdef GPIO_PC2_EXISTS + { MP_ROM_QSTR(MP_QSTR_PC2), MP_ROM_PTR(&pin_PC2) }, + #endif + + #ifdef GPIO_PC3_EXISTS + { MP_ROM_QSTR(MP_QSTR_PC3), MP_ROM_PTR(&pin_PC3) }, + #endif + + #ifdef GPIO_PC4_EXISTS + { MP_ROM_QSTR(MP_QSTR_PC4), MP_ROM_PTR(&pin_PC4) }, + #endif + + #ifdef GPIO_PC5_EXISTS + { MP_ROM_QSTR(MP_QSTR_PC5), MP_ROM_PTR(&pin_PC5) }, + #endif + + #ifdef GPIO_PC6_EXISTS + { MP_ROM_QSTR(MP_QSTR_PC6), MP_ROM_PTR(&pin_PC6) }, + #endif + + #ifdef GPIO_PC7_EXISTS + { MP_ROM_QSTR(MP_QSTR_PC7), MP_ROM_PTR(&pin_PC7) }, + #endif + #ifdef GPIO_PC8_EXISTS + { MP_ROM_QSTR(MP_QSTR_PC8), MP_ROM_PTR(&pin_PC8) }, + #endif + + #ifdef GPIO_PC9_EXISTS + { MP_ROM_QSTR(MP_QSTR_PC9), MP_ROM_PTR(&pin_PC9) }, + #endif + + #ifdef GPIO_PD0_EXISTS + { MP_ROM_QSTR(MP_QSTR_PD0), MP_ROM_PTR(&pin_PD0) }, + #endif + + #ifdef GPIO_PD1_EXISTS + { MP_ROM_QSTR(MP_QSTR_PD1), MP_ROM_PTR(&pin_PD1) }, + #endif + + #ifdef GPIO_PD2_EXISTS + { MP_ROM_QSTR(MP_QSTR_PD2), MP_ROM_PTR(&pin_PD2) }, + #endif + + #ifdef GPIO_PD3_EXISTS + { MP_ROM_QSTR(MP_QSTR_PD3), MP_ROM_PTR(&pin_PD3) }, + #endif + + #ifdef GPIO_PD4_EXISTS + { MP_ROM_QSTR(MP_QSTR_PD4), MP_ROM_PTR(&pin_PD4) }, + #endif + + #ifdef GPIO_PD5_EXISTS + { MP_ROM_QSTR(MP_QSTR_PD5), MP_ROM_PTR(&pin_PD5) } + #endif +}; +MP_DEFINE_CONST_DICT(mcu_pin_globals, mcu_pin_global_dict_table); diff --git a/ports/silabs/common-hal/nvm/ByteArray.c b/ports/silabs/common-hal/nvm/ByteArray.c new file mode 100644 index 0000000000..e94ed9198d --- /dev/null +++ b/ports/silabs/common-hal/nvm/ByteArray.c @@ -0,0 +1,98 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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 "common-hal/nvm/ByteArray.h" +#include "supervisor/shared/stack.h" + +#include "py/runtime.h" +#include "supervisor/shared/translate/translate.h" + +#include "nvm3_default.h" +#include "nvm3_default_config.h" + +uint8_t nvm_array[NVM_BYTEARRAY_BUFFER_SIZE]; +STATIC bool isInitialized = false; +#define NVM_KEY 98 + +// Get length of nvm bytearray +uint32_t common_hal_nvm_bytearray_get_length(nvm_bytearray_obj_t *self) { + return self->len; +} + +uint32_t nvm3_read(nvm_bytearray_obj_t *self) { + uint32_t type; + Ecode_t err; + size_t len; + + if (isInitialized == false) { + nvm3_initDefault(); + isInitialized = true; + } + err = nvm3_getObjectInfo(nvm3_defaultHandle, NVM_KEY, &type, &len); + if (err != ECODE_NVM3_OK || type != NVM3_OBJECTTYPE_DATA + || len != NVM_BYTEARRAY_BUFFER_SIZE) { + + nvm3_deleteObject(nvm3_defaultHandle, NVM_KEY); + nvm3_writeData(nvm3_defaultHandle, NVM_KEY, nvm_array, + NVM_BYTEARRAY_BUFFER_SIZE); + } + + err = nvm3_readData(nvm3_defaultHandle, NVM_KEY, nvm_array, + NVM_BYTEARRAY_BUFFER_SIZE); + + return err; +} + +// Write n bytes to nvm bytearray +bool common_hal_nvm_bytearray_set_bytes(nvm_bytearray_obj_t *self, + uint32_t start_index, uint8_t *values, + uint32_t len) { + Ecode_t err; + err = nvm3_read(self); + + if (err != ECODE_NVM3_OK) { + mp_raise_RuntimeError(translate("NVM3 read false")); + } + // Set bytes in buffer + memmove(nvm_array + start_index, values, len); + + err = nvm3_writeData(nvm3_defaultHandle, NVM_KEY, nvm_array, + NVM_BYTEARRAY_BUFFER_SIZE); + + if (err != ECODE_NVM3_OK) { + mp_raise_RuntimeError(translate("NVM3 write false")); + } + + return true; +} + +// Read n bytes from nvm bytearray +void common_hal_nvm_bytearray_get_bytes(nvm_bytearray_obj_t *self, + uint32_t start_index, + uint32_t len, uint8_t *values) { + nvm3_read(self); + memcpy(values, nvm_array + start_index, len); +} diff --git a/ports/silabs/common-hal/nvm/ByteArray.h b/ports/silabs/common-hal/nvm/ByteArray.h new file mode 100644 index 0000000000..ac609e47eb --- /dev/null +++ b/ports/silabs/common-hal/nvm/ByteArray.h @@ -0,0 +1,37 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR32_COMMON_HAL_NVM_BYTEARRAY_H +#define MICROPY_INCLUDED_EFR32_COMMON_HAL_NVM_BYTEARRAY_H + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; + uint32_t len; +} nvm_bytearray_obj_t; + +#endif // MICROPY_INCLUDED_EFR32_COMMON_HAL_NVM_BYTEARRAY_H diff --git a/ports/silabs/common-hal/nvm/__init__.c b/ports/silabs/common-hal/nvm/__init__.c new file mode 100644 index 0000000000..1b702a1584 --- /dev/null +++ b/ports/silabs/common-hal/nvm/__init__.c @@ -0,0 +1 @@ +// No nvm module functions. diff --git a/ports/silabs/common-hal/os/__init__.c b/ports/silabs/common-hal/os/__init__.c new file mode 100644 index 0000000000..d4841556de --- /dev/null +++ b/ports/silabs/common-hal/os/__init__.c @@ -0,0 +1,66 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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 "genhdr/mpversion.h" +#include "py/mpconfig.h" +#include "py/objstr.h" +#include "py/objtuple.h" + +#include "py/mperrno.h" +#include "py/runtime.h" + +#include "peripherals/periph.h" +#define RNG_TIMEOUT 5 + +STATIC const qstr os_uname_info_fields[] = { + MP_QSTR_sysname, MP_QSTR_nodename, + MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine +}; +STATIC const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, EFR32_SERIES_LOWER); +STATIC const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, EFR32_SERIES_LOWER); + +STATIC const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); +STATIC const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); +STATIC const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); + +STATIC MP_DEFINE_ATTRTUPLE( + os_uname_info_obj, + os_uname_info_fields, + 5, + (mp_obj_t)&os_uname_info_sysname_obj, + (mp_obj_t)&os_uname_info_nodename_obj, + (mp_obj_t)&os_uname_info_release_obj, + (mp_obj_t)&os_uname_info_version_obj, + (mp_obj_t)&os_uname_info_machine_obj); + +mp_obj_t common_hal_os_uname(void) { + return (mp_obj_t)&os_uname_info_obj; +} + +bool common_hal_os_urandom(uint8_t *buffer, uint32_t length) { + + return false; +} diff --git a/ports/silabs/common-hal/pwmio/PWMOut.c b/ports/silabs/common-hal/pwmio/PWMOut.c new file mode 100644 index 0000000000..b55c821462 --- /dev/null +++ b/ports/silabs/common-hal/pwmio/PWMOut.c @@ -0,0 +1,181 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include "py/runtime.h" +#include "common-hal/pwmio/PWMOut.h" +#include "shared-bindings/pwmio/PWMOut.h" +#include "supervisor/shared/translate/translate.h" +#include "shared-bindings/microcontroller/Pin.h" + +STATIC sl_pwm_instance_t pwm_handle[TIM_BANK_ARRAY_LEN]; +STATIC bool never_reset_tim[TIM_BANK_ARRAY_LEN]; + +mcu_tim_pin_obj_t mcu_tim_list[TIM_BANK_ARRAY_LEN] = { + TIM(TIMER0, 0, FN_TIMER0_CC0, NULL), + TIM(TIMER1, 0, FN_TIMER1_CC0, NULL), + TIM(TIMER2, 0, FN_TIMER2_CC0, NULL), + TIM(TIMER3, 0, FN_TIMER3_CC0, NULL), + TIM(TIMER4, 0, FN_TIMER4_CC0, NULL), +}; + +// Reset all pwm channel +void pwmout_reset(void) { + uint8_t tim_index; + for (tim_index = 0; tim_index < TIM_BANK_ARRAY_LEN; tim_index++) { + mcu_tim_pin_obj_t *l_tim = &mcu_tim_list[tim_index]; + if (l_tim->pin != NULL) { + sl_pwm_deinit(&pwm_handle[tim_index]); + } + } + +} + +// Create a PWM object associated with the given pin +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) { + uint8_t tim_num = TIM_BANK_ARRAY_LEN; + uint8_t percent = (duty * 100) / 65535; + sl_pwm_config_t pwm_config; + pwm_config.frequency = frequency; + pwm_config.polarity = PWM_ACTIVE_LOW; + + mcu_tim_pin_obj_t *l_tim; + uint8_t tim_index; + + if (self->tim == NULL) { + for (tim_index = 0; tim_index < tim_num; tim_index++) { + l_tim = &mcu_tim_list[tim_index]; + + if ((l_tim->pin == NULL && pin->function_list[l_tim->fn_index] == 1) + || l_tim->pin == pin) { + l_tim->pin = pin; + self->tim = l_tim; + self->handle = &pwm_handle[tim_index]; + break; + } + } + } + + if (self->tim == NULL) { + return PWMOUT_ALL_TIMERS_ON_PIN_IN_USE; + } + + self->duty_cycle = duty; + self->variable_frequency = variable_frequency; + self->frequency = frequency; + self->handle->port = pin->port; + self->handle->pin = pin->number; + self->handle->timer = self->tim->timer; + self->handle->channel = self->tim->channel; + self->tim->pin = pin; + + if (SL_STATUS_OK != sl_pwm_init(self->handle, &pwm_config)) { + return PWMOUT_INITIALIZATION_ERROR; + } + + sl_pwm_start(self->handle); + sl_pwm_set_duty_cycle(self->handle, percent); + + common_hal_mcu_pin_claim(pin); + return PWMOUT_OK; +} + +// Mark pwm obj to never reset after reload +void common_hal_pwmio_pwmout_never_reset(pwmio_pwmout_obj_t *self) { + + uint8_t tim_index; + for (tim_index = 0; tim_index < TIM_BANK_ARRAY_LEN; tim_index++) { + if (&mcu_tim_list[tim_index] == self->tim) { + never_reset_tim[tim_index] = true; + common_hal_never_reset_pin(self->tim->pin); + break; + } + } +} + +// Pwm will be reset after reloading. +void common_hal_pwmio_pwmout_reset_ok(pwmio_pwmout_obj_t *self) { + + uint8_t tim_index; + for (tim_index = 0; tim_index < TIM_BANK_ARRAY_LEN; tim_index++) { + if (&mcu_tim_list[tim_index] == self->tim) { + never_reset_tim[tim_index] = false; + break; + } + } +} + +// Check pwm obj status, deinited or not +bool common_hal_pwmio_pwmout_deinited(pwmio_pwmout_obj_t *self) { + return self->tim == NULL; +} + +// Deint pwm obj +void common_hal_pwmio_pwmout_deinit(pwmio_pwmout_obj_t *self) { + sl_pwm_deinit(self->handle); + common_hal_reset_pin(self->tim->pin); + mcu_tim_pin_obj_t *l_tim = self->tim; + l_tim->pin = NULL; +} + +// Set pwm duty cycle +void common_hal_pwmio_pwmout_set_duty_cycle(pwmio_pwmout_obj_t *self, + uint16_t duty) { + uint8_t percent = (duty * 100) / 65535; + sl_pwm_set_duty_cycle(self->handle, percent); + self->duty_cycle = duty; +} + +// Get pwm duty cycle +uint16_t common_hal_pwmio_pwmout_get_duty_cycle(pwmio_pwmout_obj_t *self) { + return self->duty_cycle; +} + +// Set pwm frequency +void common_hal_pwmio_pwmout_set_frequency(pwmio_pwmout_obj_t *self, + uint32_t frequency) { + sl_pwm_config_t pwm_config; + pwm_config.frequency = frequency; + pwm_config.polarity = PWM_ACTIVE_LOW; + sl_pwm_init(self->handle, &pwm_config); +} + +// Get pwm frequency +uint32_t common_hal_pwmio_pwmout_get_frequency(pwmio_pwmout_obj_t *self) { + return self->frequency; +} + +// Check variable frequency +bool common_hal_pwmio_pwmout_get_variable_frequency(pwmio_pwmout_obj_t *self) { + return self->variable_frequency; +} + +// Get pin value in pwmio obj +const mcu_pin_obj_t *common_hal_pwmio_pwmout_get_pin(pwmio_pwmout_obj_t *self) { + return self->tim->pin; +} diff --git a/ports/silabs/common-hal/pwmio/PWMOut.h b/ports/silabs/common-hal/pwmio/PWMOut.h new file mode 100644 index 0000000000..484b1d87b9 --- /dev/null +++ b/ports/silabs/common-hal/pwmio/PWMOut.h @@ -0,0 +1,47 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_STM32F4_COMMON_HAL_PWMIO_PWMOUT_H +#define MICROPY_INCLUDED_STM32F4_COMMON_HAL_PWMIO_PWMOUT_H + +#include "common-hal/microcontroller/Pin.h" +#include "common-hal/microcontroller/Pin.h" +#include "py/obj.h" +#include "peripherals/periph.h" +#include "sl_pwm.h" + +typedef struct { + mp_obj_base_t base; + sl_pwm_instance_t *handle; + mcu_tim_pin_obj_t *tim; + bool variable_frequency : 1; + uint16_t duty_cycle; + uint32_t frequency; +} pwmio_pwmout_obj_t; + +void pwmout_reset(void); + +#endif // MICROPY_INCLUDED_STM32F4_COMMON_HAL_PWMIO_PWMOUT_H diff --git a/ports/silabs/common-hal/pwmio/__init__.c b/ports/silabs/common-hal/pwmio/__init__.c new file mode 100644 index 0000000000..9e551a1072 --- /dev/null +++ b/ports/silabs/common-hal/pwmio/__init__.c @@ -0,0 +1 @@ +// No pwmio module functions. diff --git a/ports/silabs/common-hal/rtc/RTC.c b/ports/silabs/common-hal/rtc/RTC.c new file mode 100644 index 0000000000..f3de48894c --- /dev/null +++ b/ports/silabs/common-hal/rtc/RTC.c @@ -0,0 +1,78 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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/timeutils/timeutils.h" +#include "shared-bindings/rtc/__init__.h" +#include "common-hal/rtc/RTC.h" +#include "shared-bindings/rtc/RTC.h" +#include "supervisor/port.h" +#include "supervisor/shared/translate/translate.h" +#include "peripherals/rtc.h" +#include "sl_sleeptimer.h" + +// Set rtc time +void common_hal_rtc_set_time(timeutils_struct_time_t *tm) { + + sl_sleeptimer_date_t date = { 0 }; + date.year = tm->tm_year - 1900; + // Month enum begins at + date.month = tm->tm_mon - 1; + date.month_day = tm->tm_mday; + date.day_of_week = tm->tm_wday == 6?0:tm->tm_wday + 1; + date.hour = tm->tm_hour; + date.min = tm->tm_min; + date.sec = tm->tm_sec; + date.day_of_year = tm->tm_yday; + sl_sleeptimer_set_datetime(&date); +} + +// Get rtc time +void common_hal_rtc_get_time(timeutils_struct_time_t *tm) { + sl_sleeptimer_date_t date; + sl_sleeptimer_get_datetime(&date); + + tm->tm_year = date.year + 1900; + tm->tm_mon = date.month + 1; + tm->tm_mday = date.month_day; + tm->tm_wday = date.day_of_week == 0?6:date.day_of_week - 1; + tm->tm_hour = date.hour; + tm->tm_min = date.min; + tm->tm_sec = date.sec; + tm->tm_yday = date.day_of_year; + +} + +int common_hal_rtc_get_calibration(void) { + return 0; +} + +void common_hal_rtc_set_calibration(int calibration) { + mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_calibration); +} diff --git a/ports/silabs/common-hal/rtc/RTC.h b/ports/silabs/common-hal/rtc/RTC.h new file mode 100644 index 0000000000..12683a310a --- /dev/null +++ b/ports/silabs/common-hal/rtc/RTC.h @@ -0,0 +1,33 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_STM_COMMON_HAL_RTC_RTC_H +#define MICROPY_INCLUDED_STM_COMMON_HAL_RTC_RTC_H + +extern void rtc_init(void); +extern void rtc_reset(void); + +#endif // MICROPY_INCLUDED_STM_COMMON_HAL_RTC_RTC_H diff --git a/ports/silabs/common-hal/rtc/__init__.c b/ports/silabs/common-hal/rtc/__init__.c new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ports/silabs/common-hal/rtc/__init__.h b/ports/silabs/common-hal/rtc/__init__.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ports/silabs/common-hal/supervisor/Runtime.c b/ports/silabs/common-hal/supervisor/Runtime.c new file mode 100644 index 0000000000..f2ac082604 --- /dev/null +++ b/ports/silabs/common-hal/supervisor/Runtime.c @@ -0,0 +1,37 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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 "shared-bindings/supervisor/Runtime.h" +#include "supervisor/serial.h" + +bool common_hal_supervisor_runtime_get_serial_connected(void) { + return (bool)serial_connected(); +} + +bool common_hal_supervisor_runtime_get_serial_bytes_available(void) { + return (bool)serial_bytes_available(); +} diff --git a/ports/silabs/common-hal/supervisor/Runtime.h b/ports/silabs/common-hal/supervisor/Runtime.h new file mode 100644 index 0000000000..b71bd9b545 --- /dev/null +++ b/ports/silabs/common-hal/supervisor/Runtime.h @@ -0,0 +1,37 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_STM32_COMMON_HAL_SUPERVISOR_RUNTIME_H +#define MICROPY_INCLUDED_STM32_COMMON_HAL_SUPERVISOR_RUNTIME_H + +#include "py/obj.h" + +typedef struct { + mp_obj_base_t base; + // Stores no state currently. +} super_runtime_obj_t; + +#endif // MICROPY_INCLUDED_STM32_COMMON_HAL_SUPERVISOR_RUNTIME_H diff --git a/ports/silabs/common-hal/supervisor/__init__.c b/ports/silabs/common-hal/supervisor/__init__.c new file mode 100644 index 0000000000..16dc414b06 --- /dev/null +++ b/ports/silabs/common-hal/supervisor/__init__.c @@ -0,0 +1,38 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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 "shared-bindings/supervisor/__init__.h" +#include "shared-bindings/supervisor/Runtime.h" + +// The singleton supervisor.Runtime object, bound to supervisor.runtime +// It currently only has properties, and no state. +const super_runtime_obj_t common_hal_supervisor_runtime_obj = { + .base = { + .type = &supervisor_runtime_type, + }, +}; diff --git a/ports/silabs/common-hal/watchdog/WatchDogMode.c b/ports/silabs/common-hal/watchdog/WatchDogMode.c new file mode 100644 index 0000000000..200db64eec --- /dev/null +++ b/ports/silabs/common-hal/watchdog/WatchDogMode.c @@ -0,0 +1,25 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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. + */ diff --git a/ports/silabs/common-hal/watchdog/WatchDogTimer.c b/ports/silabs/common-hal/watchdog/WatchDogTimer.c new file mode 100644 index 0000000000..b6158e1cc6 --- /dev/null +++ b/ports/silabs/common-hal/watchdog/WatchDogTimer.c @@ -0,0 +1,133 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "py/runtime.h" +#include "common-hal/watchdog/WatchDogTimer.h" + +#include "shared-bindings/watchdog/__init__.h" +#include "shared-bindings/microcontroller/__init__.h" + +#include "em_wdog.h" +#include "em_cmu.h" + +void common_hal_watchdog_feed(watchdog_watchdogtimer_obj_t *self) { + WDOGn_Feed(DEFAULT_WDOG); +} + +void common_hal_watchdog_deinit(watchdog_watchdogtimer_obj_t *self) { + WDOG_Enable(false); +} + +void watchdog_reset(void) { + common_hal_watchdog_deinit(&common_hal_mcu_watchdogtimer_obj); +} + +mp_float_t common_hal_watchdog_get_timeout(watchdog_watchdogtimer_obj_t *self) { + return self->timeout; +} + +void common_hal_watchdog_set_timeout(watchdog_watchdogtimer_obj_t *self, + mp_float_t new_timeout) { + + // Max timeout is 256000 ms + uint64_t timeout = new_timeout * 1000; + mp_arg_validate_int_max(timeout, 256000, MP_QSTR_WatchDogTimeout); + + if ((uint32_t)self->timeout != (uint32_t)new_timeout) { + + // Watchdog Initialize settings + WDOG_Init_TypeDef wdogInit = WDOG_INIT_DEFAULT; + + switch ((uint32_t)new_timeout) + { + case 1: + wdogInit.perSel = wdogPeriod_1k; + break; + case 2: + wdogInit.perSel = wdogPeriod_2k; + break; + case 4: + wdogInit.perSel = wdogPeriod_4k; + break; + case 8: + wdogInit.perSel = wdogPeriod_8k; + break; + case 16: + wdogInit.perSel = wdogPeriod_16k; + break; + case 32: + wdogInit.perSel = wdogPeriod_32k; + break; + case 64: + wdogInit.perSel = wdogPeriod_64k; + break; + case 128: + wdogInit.perSel = wdogPeriod_128k; + break; + case 256: + wdogInit.perSel = wdogPeriod_256k; + break; + default: + mp_raise_ValueError( + translate("Timeout value supported: 1,2,4,8,16,32,64,128,256")); + + } + + self->timeout = new_timeout; + // Enable clock for the WDOG module; has no effect on xG21 + CMU_ClockEnable(cmuClock_WDOG0, true); + + // ULFRCO as clock source + CMU_ClockSelectSet(cmuClock_WDOG0, cmuSelect_ULFRCO); + + wdogInit.em1Run = true; + wdogInit.em2Run = true; + wdogInit.em3Run = true; + + // Initializing watchdog with chosen settings + WDOGn_Init(DEFAULT_WDOG, &wdogInit); + } +} + +watchdog_watchdogmode_t common_hal_watchdog_get_mode + (watchdog_watchdogtimer_obj_t *self) { + return self->mode; +} + +void common_hal_watchdog_set_mode(watchdog_watchdogtimer_obj_t *self, + watchdog_watchdogmode_t new_mode) { + if (self->mode != new_mode) { + if (new_mode == WATCHDOGMODE_RAISE) { + mp_raise_NotImplementedError( + translate("RAISE mode is not implemented")); + } else if (new_mode == WATCHDOGMODE_NONE) { + self->mode = WATCHDOGMODE_NONE; + common_hal_watchdog_deinit(self); + } + self->mode = new_mode; + common_hal_watchdog_set_timeout(self, self->timeout); + } +} diff --git a/ports/silabs/common-hal/watchdog/WatchDogTimer.h b/ports/silabs/common-hal/watchdog/WatchDogTimer.h new file mode 100644 index 0000000000..d1538bd491 --- /dev/null +++ b/ports/silabs/common-hal/watchdog/WatchDogTimer.h @@ -0,0 +1,43 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_ESPRESSIF_COMMON_HAL_WATCHDOG_WATCHDOGTIMER_H +#define MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_WATCHDOG_WATCHDOGTIMER_H + +#include "py/obj.h" +#include "shared-bindings/watchdog/WatchDogMode.h" +#include "shared-bindings/watchdog/WatchDogTimer.h" + +struct _watchdog_watchdogtimer_obj_t { + mp_obj_base_t base; + mp_float_t timeout; + watchdog_watchdogmode_t mode; +}; + +// This needs to be called in order to disable the watchdog +void watchdog_reset(void); + +#endif // MICROPY_INCLUDED_ESPRESSIF_COMMON_HAL_WATCHDOG_WATCHDOGTIMER_H diff --git a/ports/silabs/common-hal/watchdog/__init__.c b/ports/silabs/common-hal/watchdog/__init__.c new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ports/silabs/cp_efr32_extension/cp_efr32.slce b/ports/silabs/cp_efr32_extension/cp_efr32.slce new file mode 100644 index 0000000000..90052a887d --- /dev/null +++ b/ports/silabs/cp_efr32_extension/cp_efr32.slce @@ -0,0 +1,10 @@ +id: cp_efr32 +label: CircuitPython support +version: 1.0.0 +sdk: + id: "gecko_sdk" + version: 4.2.1 +component_path: + - path: ../boards/devkit_xg24_brd2601b/ + - path: ../boards/explorerkit_xg24_brd2703a/ + - path: ../boards/sparkfun_thingplus_matter_mgm240p_brd2704a/ diff --git a/ports/silabs/gecko_sdk b/ports/silabs/gecko_sdk new file mode 160000 index 0000000000..3fbadf9fb4 --- /dev/null +++ b/ports/silabs/gecko_sdk @@ -0,0 +1 @@ +Subproject commit 3fbadf9fb4e904fd8ed087642a41762b833ae0fe diff --git a/ports/silabs/license.md b/ports/silabs/license.md new file mode 100644 index 0000000000..5b8797814f --- /dev/null +++ b/ports/silabs/license.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2013-2022 Damien P. George and others + +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. diff --git a/ports/silabs/mpconfigport.h b/ports/silabs/mpconfigport.h new file mode 100644 index 0000000000..ba498dd763 --- /dev/null +++ b/ports/silabs/mpconfigport.h @@ -0,0 +1,73 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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 EFR32_MPCONFIGPORT_H__ +#define EFR32_MPCONFIGPORT_H__ + +#include + +#define MICROPY_PY_FUNCTION_ATTRS (1) +#define MICROPY_PY_REVERSE_SPECIAL_METHODS (1) + +// 24kiB stack +#define CIRCUITPY_DEFAULT_STACK_SIZE 0x6000 + +// Board flags: +#ifndef BOARD_OVERWRITE_SWD +#define BOARD_OVERWRITE_SWD (0) +#endif +#ifndef BOARD_VTOR_DEFER +#define BOARD_VTOR_DEFER (0) +#endif +#ifndef BOARD_NO_VBUS_SENSE +#define BOARD_NO_VBUS_SENSE (0) +#endif +#ifndef BOARD_NO_USB_OTG_ID_SENSE +#define BOARD_NO_USB_OTG_ID_SENSE (0) +#endif + +#if INTERNAL_FLASH_FILESYSTEM +#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR (0x080E0000UL) +#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (512 * 1024) +#else +#define CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE (0) +#endif + +// Peripheral implementation counts +#define MAX_UART 1 +#define MAX_I2C 1 +#define MAX_SPI 1 + +#define asm(str) __asm(str) + +#include "py/circuitpy_mpconfig.h" + +#define MICROPY_PORT_ROOT_POINTERS \ + void *cpy_uart_obj_all[MAX_UART]; \ + void *cpy_i2c_obj_all[MAX_I2C]; \ + CIRCUITPY_COMMON_ROOT_POINTERS + +#endif // EFR32_MPCONFIGPORT_H__ diff --git a/ports/silabs/mpconfigport.mk b/ports/silabs/mpconfigport.mk new file mode 100644 index 0000000000..b3a2d63724 --- /dev/null +++ b/ports/silabs/mpconfigport.mk @@ -0,0 +1,37 @@ +LONGINT_IMPL ?= MPZ +INTERNAL_LIBM ?= 1 +USB_NUM_ENDPOINT_PAIRS ?= 0 + +CIRCUITPY_ANALOGIO ?= 1 +CIRCUITPY_BLEIO ?= 1 +CIRCUITPY_BUSDEVICE ?= 1 +CIRCUITPY_BUSIO ?= 1 +CIRCUITPY_DIGITALIO ?= 1 +CIRCUITPY_DISPLAYIO ?= 1 +CIRCUITPY_FRAMEBUFFERIO ?= 1 +CIRCUITPY_NVM ?= 1 +CIRCUITPY_PWMIO ?= 1 +CIRCUITPY_RTC ?= 1 +CIRCUITPY_WATCHDOG ?=1 + +ifeq ($(MCU_SERIES),MG24) + # Not yet implemented common-hal modules: + CIRCUITPY_AUDIOIO ?= 0 + CIRCUITPY_AUDIOCORE ?= 0 + CIRCUITPY_AUDIOPWMIO ?= 0 + CIRCUITPY_AUDIOBUSIO ?= 0 + CIRCUITPY_BITBANGIO ?= 0 + CIRCUITPY_BLEIO_HCI ?= 0 + CIRCUITPY_COUNTIO ?= 0 + CIRCUITPY_FREQUENCYIO ?= 0 + CIRCUITPY_I2CTARGET ?= 0 + CIRCUITPY_KEYPAD ?= 0 + CIRCUITPY_NEOPIXEL_WRITE ?= 0 + CIRCUITPY_PARALLELDISPLAY ?= 0 + CIRCUITPY_PULSEIO ?= 0 + CIRCUITPY_ROTARYIO ?= 0 + CIRCUITPY_TOUCHIO ?= 0 + CIRCUITPY_USB ?= 0 +endif + +CIRCUITPY_BUILD_EXTENSIONS ?= bin diff --git a/ports/silabs/mphalport.c b/ports/silabs/mphalport.c new file mode 100644 index 0000000000..715541b968 --- /dev/null +++ b/ports/silabs/mphalport.c @@ -0,0 +1,46 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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/mphal.h" +#include "py/mpstate.h" +#include "py/gc.h" + +#include "shared-bindings/microcontroller/__init__.h" +#include "supervisor/shared/tick.h" + +void mp_hal_delay_us(mp_uint_t delay) { + common_hal_mcu_delay_us(delay); +} + +void mp_hal_disable_all_interrupts(void) { + common_hal_mcu_disable_interrupts(); +} + +void mp_hal_enable_all_interrupts(void) { + common_hal_mcu_enable_interrupts(); +} diff --git a/ports/silabs/mphalport.h b/ports/silabs/mphalport.h new file mode 100644 index 0000000000..39c817868a --- /dev/null +++ b/ports/silabs/mphalport.h @@ -0,0 +1,51 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR32_MPHALPORT_H +#define MICROPY_INCLUDED_EFR32_MPHALPORT_H + +#include "py/obj.h" + +#include "lib/oofatfs/ff.h" + +#include "supervisor/shared/tick.h" + +// Global millisecond tick count (driven by SysTick interrupt). +static inline mp_uint_t mp_hal_ticks_ms(void) { + return supervisor_ticks_ms32(); +} +// Number of bytes in receive buffer +extern volatile uint8_t usb_rx_count; +extern volatile bool mp_cdc_enabled; + +int receive_usb(void); + +void mp_hal_set_interrupt_char(int c); + +void mp_hal_disable_all_interrupts(void); +void mp_hal_enable_all_interrupts(void); + +#endif // MICROPY_INCLUDED_EFR32_MPHALPORT_H diff --git a/ports/silabs/peripherals/periph.h b/ports/silabs/peripherals/periph.h new file mode 100644 index 0000000000..e70119a6b5 --- /dev/null +++ b/ports/silabs/peripherals/periph.h @@ -0,0 +1,81 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR32_PERIPHERALS_PERIPH_H__ +#define __MICROPY_INCLUDED_EFR32_PERIPHERALS_PERIPH_H__ + +#include +#include + +#include "pins.h" +#include "uartdrv.h" +#include "sl_pwm.h" +#include "em_vdac.h" +#define TIM_BANK_ARRAY_LEN 5 + + +// Timer Peripheral +typedef struct { + TIMER_TypeDef *timer; + uint8_t channel; + uint8_t fn_index; + const mcu_pin_obj_t *pin; +} mcu_tim_pin_obj_t; + +#define TIM(timer_index, channel_index, pin_fun, pin_num) \ + { \ + .timer = timer_index, \ + .channel = channel_index, \ + .fn_index = pin_fun, \ + .pin = pin_num \ + } + +extern mcu_tim_pin_obj_t mcu_tim_list[TIM_BANK_ARRAY_LEN]; + +#define DAC_BANK_ARRAY_LEN 4 + +typedef struct { + VDAC_TypeDef *vdac; + uint8_t channel; + uint8_t fn_index; + bool is_used; + uint16_t value; + const mcu_pin_obj_t *pin; +} mcu_dac_pin_obj_t; + +#define DAC(vdac_index, channel_index, pin_fun, used, dac_value, pin_num) \ + { \ + .vdac = vdac_index, \ + .channel = channel_index, \ + .fn_index = pin_fun, \ + .is_used = used, \ + .value = dac_value, \ + .pin = pin_num \ + } + +extern mcu_dac_pin_obj_t mcu_dac_list[DAC_BANK_ARRAY_LEN]; + +#endif // __MICROPY_INCLUDED_EFR32_PERIPHERALS_PERIPH_H__ diff --git a/ports/silabs/peripherals/pins.h b/ports/silabs/peripherals/pins.h new file mode 100644 index 0000000000..ca02bf4af6 --- /dev/null +++ b/ports/silabs/peripherals/pins.h @@ -0,0 +1,171 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR32_PERIPHERALS_PINS_H__ +#define __MICROPY_INCLUDED_EFR32_PERIPHERALS_PINS_H__ + +typedef struct { + mp_obj_base_t base; + const uint8_t port : 4; + const uint8_t number : 4; + const uint8_t *const function_list; +} mcu_pin_obj_t; + +extern const mp_obj_type_t mcu_pin_type; + +#define PIN(p_port, p_number, p_funtion_list) \ + { \ + {&mcu_pin_type}, \ + .port = p_port, \ + .number = p_number, \ + .function_list = p_funtion_list \ + } + +#ifdef GPIO_PA0_EXISTS +extern const mcu_pin_obj_t pin_PA0; +#endif + +#ifdef GPIO_PA1_EXISTS +extern const mcu_pin_obj_t pin_PA1; +#endif + +#ifdef GPIO_PA2_EXISTS +extern const mcu_pin_obj_t pin_PA2; +#endif + +#ifdef GPIO_PA3_EXISTS +extern const mcu_pin_obj_t pin_PA3; +#endif + +#ifdef GPIO_PA4_EXISTS +extern const mcu_pin_obj_t pin_PA4; +#endif + +#ifdef GPIO_PA5_EXISTS +extern const mcu_pin_obj_t pin_PA5; +#endif + +#ifdef GPIO_PA6_EXISTS +extern const mcu_pin_obj_t pin_PA6; +#endif + +#ifdef GPIO_PA7_EXISTS +extern const mcu_pin_obj_t pin_PA7; +#endif + +#ifdef GPIO_PA8_EXISTS +extern const mcu_pin_obj_t pin_PA8; +#endif + +#ifdef GPIO_PB0_EXISTS +extern const mcu_pin_obj_t pin_PB0; +#endif + +#ifdef GPIO_PB1_EXISTS +extern const mcu_pin_obj_t pin_PB1; +#endif + +#ifdef GPIO_PB2_EXISTS +extern const mcu_pin_obj_t pin_PB2; +#endif + +#ifdef GPIO_PB3_EXISTS +extern const mcu_pin_obj_t pin_PB3; +#endif + +#ifdef GPIO_PB4_EXISTS +extern const mcu_pin_obj_t pin_PB4; +#endif + +#ifdef GPIO_PB5_EXISTS +extern const mcu_pin_obj_t pin_PB5; +#endif + +#ifdef GPIO_PC0_EXISTS +extern const mcu_pin_obj_t pin_PC0; +#endif + +#ifdef GPIO_PC1_EXISTS +extern const mcu_pin_obj_t pin_PC1; +#endif + +#ifdef GPIO_PC2_EXISTS +extern const mcu_pin_obj_t pin_PC2; +#endif + +#ifdef GPIO_PC3_EXISTS +extern const mcu_pin_obj_t pin_PC3; +#endif + +#ifdef GPIO_PC4_EXISTS +extern const mcu_pin_obj_t pin_PC4; +#endif + +#ifdef GPIO_PC5_EXISTS +extern const mcu_pin_obj_t pin_PC5; +#endif + +#ifdef GPIO_PC6_EXISTS +extern const mcu_pin_obj_t pin_PC6; +#endif + +#ifdef GPIO_PC7_EXISTS +extern const mcu_pin_obj_t pin_PC7; +#endif + +#ifdef GPIO_PC8_EXISTS +extern const mcu_pin_obj_t pin_PC8; +#endif + +#ifdef GPIO_PC9_EXISTS +extern const mcu_pin_obj_t pin_PC9; +#endif + +#ifdef GPIO_PD0_EXISTS +extern const mcu_pin_obj_t pin_PD0; +#endif + +#ifdef GPIO_PD1_EXISTS +extern const mcu_pin_obj_t pin_PD1; +#endif + +#ifdef GPIO_PD2_EXISTS +extern const mcu_pin_obj_t pin_PD2; +#endif + +#ifdef GPIO_PD3_EXISTS +extern const mcu_pin_obj_t pin_PD3; +#endif + +#ifdef GPIO_PD4_EXISTS +extern const mcu_pin_obj_t pin_PD4; +#endif + +#ifdef GPIO_PD5_EXISTS +extern const mcu_pin_obj_t pin_PD5; +#endif + +#endif // __MICROPY_INCLUDED_EFR32_PERIPHERALS_PINS_H__ diff --git a/ports/silabs/peripherals/rtc.h b/ports/silabs/peripherals/rtc.h new file mode 100644 index 0000000000..74e3201767 --- /dev/null +++ b/ports/silabs/peripherals/rtc.h @@ -0,0 +1,33 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR32_PERIPHERALS_RTC_H__ +#define __MICROPY_INCLUDED_EFR32_PERIPHERALS_RTC_H__ + +#include +#include + +#endif // __MICROPY_INCLUDED_EFR32_PERIPHERALS_RTC_H__ diff --git a/ports/silabs/peripherals/timers.h b/ports/silabs/peripherals/timers.h new file mode 100644 index 0000000000..6fb7bb2a03 --- /dev/null +++ b/ports/silabs/peripherals/timers.h @@ -0,0 +1,29 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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/mphal.h" +#include "peripherals/periph.h" diff --git a/ports/silabs/qstrdefsport.h b/ports/silabs/qstrdefsport.h new file mode 100644 index 0000000000..3ba897069b --- /dev/null +++ b/ports/silabs/qstrdefsport.h @@ -0,0 +1 @@ +// qstrs specific to this port diff --git a/ports/silabs/res/Thony.png b/ports/silabs/res/Thony.png new file mode 100755 index 0000000000000000000000000000000000000000..93b3f5dd4b258dd2e1d50860e0c9bebd54735497 GIT binary patch literal 49362 zcmce-2UJt-*Dr_-UQ|F)M5L)S=?VhUL6qJhbO<641p(DxBL*AQj;4-V=W@bg~rqIBX@VO>S^`rvu=$lJcOIraC?-$Er zgPcK|5K?c-r=trGze#d)miyCQvUXlOlk_90$oy5-%c~FjYOl4ShNhUYAD%!DfjqfWr3ncE7-_$DhhC>?9?G-^l|n@zg0!PPWs6!5dA>?ja!)kB%HX95wO% zyKDN=a>K`08@s!0yXvGxG0le!?iAW?yDW@621iWbSp>tY_mTkZqyazonFb$16>Ypd zIfAm&GhCooL9`xzics*LcsG4YH5?j)>}>MDrI__n*&H!FH>~{aFQ$k!s_X>fQoLS| z-a`)UmO+kmvHp;gm+E(M_Nxg>>Q~aCk-2_>D@Q$o$%TznqD8U=)123 z`%0d_z3kV94{f#G-UK2RN?JZD;6iWi`pq3>M^|ZN&@VMk%OKUIf!PxchEN=1Q(CJ* zTA;Syx+>xi>j*Eac(#O|aip^;I~3CXl^7lj?rYP5t=!DqA`atH*NIzk#K2$O>@2TjRK zWWPRHofSp9VnL^0hIQ7`-xqi`**%}Oo}8N#TH39I;#w--d!J!!rKg_M@rc@gGZ+poNOC31GIG0 zZ&@zB&=_;@r+jqIQwD2oJlQcnt2Ff*=Wt7}Zz@0?df#j#xg%H1V<&T9)uPa`(KoFk zPS1TuB&mh_^nQcEP?9~7#P6v-^CN|FhrI+{XfJE}RI!UwE}+Yl)lOTJUrSA*K&&G4 zuNs|Cp4Z(!hbiuQrmhkLBxj!^Q_8hfU+ACxblKlU7~=IN zZWzAxs!r&j?&2P*KpgXiF0ASJ&XMA0!k4xEx23~+;UuSKFRzHFfj5WRmezG@y6h)g zI&Yj5#qXZKMSIvRh(%HGwpF2hbph4_)8&&UU!PZEItT9~&FNdjuVCYKOh0Mz0{M+% z<6E(=ZSM`*yWOSjrthQ~1Qw$#>HvUJPPjYAvepg1!)FDo!Dx}o^^G6MDrlnZgZ5F& zE_6-nPYoOdOD#W_KQJdq**dj9Pq>uQ?Haqb`p~MyC)%d2t`@#f67*yy=$R?|8|yQB zfUbba6#=lQ>qMaRk9IyXUw8hUet)&?H8p6#U-K+fK4ybFZT-;WL>XbK*5kE3f;sqD zi`im+o-Sb|B4GPHbxBum&ef+uPr}~H*i;}fsl`gkFN-|8!cIYz4?QH!d#B{7@AlNi zC$YzJs7vmyuUg=(d-&IDr=$kWc8heF*Hue?^Uce01h=~5QzUj)q$A!idw{$QXN;~= zMp#x#-qZ_P&%lz_!J64s9OR|oKr-`KWy^Pe$smE+A+&aI=UzE7LSrjpa-Wjb&f&qg zd>fszd$D+BA*Au;{3IwZ2{aZvGU{CM>aJ5?DLM*bHe!|bN?mWMLMna>xD6sq<$<8} z;Sn-HwD|6%=hG$AewvfvlfRBmrWW`O&CgwK8G|oJE{8`*2T{3H&|CHoV7Zg7Z7JD! z)ny8bE5K6sD@`>tz}g+I?rxyi2>+&yjBC7qhx62inTD5ONa@z5{xCP_?3jkYtayxy z{&apq0!^JE*!=lITEY756U5TruHy-j+d`x+=)N9_oBkWv4cDZu1~qLBs+znFDB=AP zv$XVp!XB*S?Hjbc&4x^;RsHl)uNCt?8B2D;7Jnlt8$I3K4uCXI-c!CAptXdO?N!CP z3FzsKS2!JENN!3fK3i)%BfjHhv%2KSQb^OnR7;?4(8~Qn-`f?uHvk)vHo;fMV^l|! zlEIo~n4OL{?4t#uwf$kUC;7a+$tJ}vjza=Om$N4$CXZ4a{y22cbwzI^hD5Nqtc0E9 z*YS9q!T*oMMJ9ce~Eb(DpA7_v0yE~h_myrWIL1*a*)k5AnGs$8Z)+e|Q$ zx{v}T$}7Jsp3%Z zo4d@!KULcrKIkO%g`4}e^RxAiANUY*{^piZb8EBF-*q-M1Q()v)?-4uwrS!LSV z@qY3WzC^8F(rWonWN>E)aOW-1apl^YXd%?NfVeuy=_A*IBo%<(un|`BzM0b@P-*S%Sa#|s&o<-WbI>f-t6+M2TneCfhs%uwV88T!dTuU`Zr5`CvjsaxI0u_w{S9xD?K=(R5 zD=w_T>+O}aCZG=|n>-MSes|2Cu0FBJTmNB2?fQ%pml)K*)fx$#myD{syq;|Esg;_U z5}+lJJg`(3noyFB9D56EGmxKA(o8*hajHw-vfyk`k5ZQi9`v?cquyZXEcMB*aoFlo zkb1Bc?a^?7s5RQSQgCiihPZ01FMsYwU7Ogh{}y=2B8ie^Ht0X0w6R(WWTO;P3*}?2 zp5im{7bVEE>wMO*8s9=98;ZnUmT=0sFI2y)MBU9O;hF)p89SW@n zlbwF<5BL-$K99E*XIP@-$KsJ!E4Un--_tGU;x+HmBIyjzx&(nhJURHx zl|Xl=Kl&F0GtEp-FQ(bL)J!P(ObbKzyP%Iu=zY#r+_8ASL>*N_1371%SbU=ZsjX1S z{Pl2bjhIK7K(NK)z@zb@B;NQy7s&B9?CN|K5Gf_W#4`?bT>NEQa=i`QhVKRrWV=Z}<~cFKwJbJ(x6*ww;;9x6`Y^ zlCKLm>?6wJJ9o3GAu8eRH&+J7eo_pr)@~rwBXV-6`f18tmDiBXl_!yo{k!7`vxALj zNd~y5nUPHgd)LaH<2A-aM|KkVa@8duH9NKK^vre7z$*-*rjPGY;wi$k(G<^tkiGA9 z0ciH|%)9Crp5KZeHew_Mq3Eie@J%16XmFlOGKDXqwvy+7den*QY}IzzP_ytMfq>&t z?0xS+_;dVa0lDj{iyEYw{Wrs!2hZgXTAwM;0)0tVkd{$6QT{?GoDUt?^%R!*)&b#1 zCi;SHevh=+kC(aoI?XJ*!}0dYsb0VTTmkR2@w;^)0^;xHQ71#IkubKmaght^^bj*FevMHIKJp@&r{V42rCcp;C;oweRdFbd~NTbdU^cz znw*_SwEEJEaGKWB=BH@2YpSDGBX`;?H`!XZC|26XsOl)fX2u$x6vmSZs#rIj!SE~x z)t^}A7=)W>G>(dCDt4xgSTQYkx6>h)e$|!gPyW&&+=q4lY+P&j)~0Zc5SCqmAt=WW zzvq_=+rBcs;8rq3wH|LILttORcC!~8O{SK;cHCk6d%k*~%72Ej$L<>8yMVR063gMz zdUxPx$nevFRJW@8D0BZw*Aeb+mtH!S=t^5o1$Vvygx;< z&1?uN_kydRMjTzbn7h`OS^4n{v1v@Ze0*CQ_wH7)af7-rG#Kbq-sje~n^XSqU8t@9 zqUDZ)4>$jho3Gm90jf~HqcP9P><7pD%BCO(u-juacv%b6={l=zb|O`qH1W%?6k1$7 zg-HR?tzi7BQn8Wc8ZFLMbZgUi=`owQX@TT+JjI_&x31|;+839Ee2SIillp6;Oh#?- z!DmLLj{YSbRcozjH@;&*`l#keagC$pJ*iq#(tcfY4A>*jRz1CKt(7$25=JyH*&kgy zxzSFY>d>UV+W$c=ccIttP18p|`=l8p$Wfj^RHi*i>ahFu34BMdWM z#df$abJxP7OYz`U4e*X{*bJ<9u>X9e)Qm@0#L^bvVtfJoD0z&2(riYul|FIv^Apcr zmRM#pn8BA{Jiw%XAH-L1n6Jfz+B~j_GVgB4Sn);#z&6-C6%95o&x}qdTsk9{$4UM zRo|q|wNpYvs=e^@D9>~Mxfz0=AGoP?c=eH`T`ecN}q(bishwdUByjP8E%JSU{rMsv12L95F{4RB1883Di`R(h;Nifftk(0*Kf*;SY#xBgC*s z(x};bB8NgddQ57rdni(ZUy!O^_riOezPGQLqDlior2;$*D_we6Z4?xH)3&%5$5(b2 zE8kziRd_KF9&V`bgkk+sD67o@_fjf$0K!cz{t_&qaWPeTgsA6O9yRpz=`lhDKK|YG z_$C?0U0%D~Hq`Tcay|b?8>n4`zN1NvDYf{)CTWWps!XjMsz?o^e@TVTU4758PRIyz zSbX39sHT14i$6HRDMFiVAKfF^?QF(^q0qMz2(gV-sp`<38>Bwy)Rh@3K4Y=yK0(in z?hU5x^%aM#dV&U`14whB7?7r*y!W;7{{9x5QYHEx2`bu%rsxG=KJzrGX~@_{Zt*q+ zxTFOxkK@3|^_=ctTL!qao(P?7mnlY zM1AiL%CC|1N}(1p9h8q9?nZZO(hE5H;?2-kVS9hzi=P)&2@^%3m={YpjFliYYQLw! zgs@!(m8Ey>y2!yK1~7g2cOod&jK$s-PivF611=~DZu+W;GNtb<50tu>6R?q?nbd=( z8G7ap*Pm!rAn_`1Z7qQNnv~4CRWpi>2c~aPz9lTK;WU#Q;gR5l6*ZK=8psaRIWn$7W(CtIW3&+bmQXtM zD9LXgIY5>=uqa>4fNBYah{{A+I`IgOhy&7_iOu;&+>7aszUiu=vsXhy=A@iet(&%( zo3v&0*JjKz4X0kQT0U%^XPdbBX z-->yB#j@49ne^qz1$yYp?2}VV?Rg>Xm439u{iQY8SL}8b&A)^Yk7`}4D5M=s=;Hnt zFi*rn;r{4Xtc$H_(kHq^X!tMr0MfuSg=j3Ixwy*Ix&DWx}N^>RH(0LCa%|+JW5&4`Lp8Qt?ERfnoZhuc zS@}%?!zcAS|PzQ4ELS zK_acn%Z1Gm=LEvPaZ!)yehfOMyBlT_-{Z5fa^O#E5XJ#X|ND1>G2g2Z1V|Q;da!f4*$|A!V%>%Xxw9c3hy{9EQuby+^(W2 zQ&0sATF14e=%cmy^(hWuT=FY zRY+4%QQ_oPoQtF{K- zsLONjr+85Lw4poNZ2bM+j~=D&R@da7vPJa_Wh<-;^0iNE@nO}D><8EKSlz5 zrfJKi?h!YN_LNSILY4!E_yy(h5uK0-+z0l@2l3#iz<8g1T10}&P4(K|lUl2nfAsP$ zj@!!WZ||`oW|PIM=B3b2h!+697t~MV94G#f1d!oMham zwo4?Gs}N`ENEDrs%X}YzF{TM*ve+U^m zNrd#AysqH9E3g&6t}Zz*IeKmuE+Uj z($=%FL|d;ia$aU10zVqi*=*C|b|j?Tb4<^AxGMg^bc=0O@oO5gqP5MS(g`IMXVsp# zn5kr3(d*Q7OQcGWoQ_nRr!Et)`0~bd`f_e#U(+#)`v5suj=YLSx>$Xq5pLjuvElxs zdnMpHvs?lB7v7q6Ei6P=S2|&GJhz;|kOXuBKbW zO29lM%-0%U%YPzP@D76i zV{_YZ)+M`BrI+7Ej(1#xhspwzfqDCRt;#z(O^6*mmds0+vKQaNsAkA@mg0%eL8^YD z34P+@@w8U>s^iU1i0%3W7dVVCSxcr0+7x}YmeLYr zVrWJ*Ak#G~5>-BU-^L=?)0!W7DquChGu2t7IFe+fO!uQBTO)ryY@%i?7jA|^CtDX1 zUyWSyfl@ybA*%yGhpIFc;*gpgr5z2h8HWAs!!cbhdh;+U@R*A7Zih$>XTGEgbIATP zhsnA>LEl%BGYJ_G)MF>O>s}Y*%%mNClT?G{LY>D5 z@zP3V9~#E5nvj#yH;- zPyqo5Zzqe0-?H7m67flm^G%OVlwRV!gWODaYEluJY=>*lw{6FV)AhPAdYV)NK%i{} zrCLvvzWRokWyF$n>Cz<+B8!GpS$Ra07fP|cT_jhw^kOrA?w@_sfKoRCi7R*gj@Yfr zNGqG@P76iXLS05qV!4o; zUImXF+ATCfwmhwBGo<_U+&nXG}0P zL4u`XV>Z0Z*roZZi3yv{!?7gc1tmYKjR37Zq%Sn3W}D*It||oE&y_CzwjVTzNB}o> zXN{M6P}#gOpT|@K>=RB}(np_Gts0F61c&H)Ru1-xLFpGBqWlZqP=9kTjixywmttyH z3mP4&nrvDd?dKcG#|RT&(cR^P1fLUL^J$HugMHJ%Uo}h38w+OIZ>rxzzK?NfMj2V1 z3+Rk>ST$}l zkYnE@Fcjs~zz*7cs&gRr3p!srB-9ax3GuZtrij#(e5VN01Vpoa7qg7r6(Q9JL95YR zCAHH49QQY1#-v#ZfqX*Q7ctOx{C&`MX^f^OO3y`5QwB)GRrO`G?|U@8$1o#(%`{uJ zeJ11P%2tQ`X0D`+LZ&m=byt%BAzBMW^uDD4A;It%iakgB^SyxQMi)p4b=5Iyd|lGkI%*Z2`G=vY`FO!Srd~#R4Cn34+_+&llMk zRM|wYBe!gKe@h0V1L&>sq@bLtm85;S(|4H}?Co_MxfS24u54kW`h2yZ=oPD+bNg>p zts6$dyXnDON#mZjsLB#_Y~FgK?*I#CL6B5Z4yChHY&n_K$S-5arQ%H+1V?O3rJZ(3 zANh5aO9K$lR0um?Qu$h(7=zkRAN(2&s6=4!_GV`eD$7sm5+`j|;n-EJ#59%OOJBE} zB}C$lo884!CmZT-9R>7?j2F91XiLmh3Pc325P26rO3+ej4Ul9jM0me`~W}Z(t7g>ed{g0r!$sjIcNqO z$`aTsLp!BcCXg{Z*-&(N^Ama7s@`uL6)6MlqY}2Bl_}8XKb6L9?8Q?)kyuicIsKc5Dp5xnk($c59^m@-HG z_s!&1yMl&Ga+yK8eMmxq)S5NU|8_ zISiI!Bsp0k7*ybd3ctJU+R$gaT`MqL6uI&?#Jp~^7tj=dw4gRrcAr|7)gR&=Hy|9q zEn3J_uJVzBQfAr}383coE5284SF2h-^pZ}v`N z#us84DFjDpNJ5`v7tj_DOtdw9$xz}H#7sx|bGuO{*|&~;z)7kVj7k7T+K0@7;jNLs zKPnjFq9Le!y%)~ade5A{E7u~VRwy9CSF_`baJcB=mnkL8rXO9bDV!JpxsxWa9)O+1 z_fBMMO4EM@&MjFLk-G7Zl3_52P8NFCW%W<^9UH~|?uvE6v1Hg1F| zN!!Kk%s|hw?&kDtOz5<45>imgSJ?V}NYEz)pmE`!CtQeZvtJ=fJ!8+&-Lby?!lJT8 zb8iJn5mS#x(}S8;g?6mCHEWujeSMn@=I`sak6RAOn)WJLYsxCQ__4rcfXHK32qyrh zmaCPsX#*kfAQ-?rMAwCk6Aw|QnVWwnAU5V&Cd*~k1Zj@OZM3&Ko<5OuDt(W)&iaSu zHr)}Ykk*0?&TTQQD&zLPnWn(@hZ*ebcl}$W%WMe(N-0vhYcnlWYwd0G2m2yT$*$^Q zdlN(^~FE2DNX#xp`9e;%tPBrh1mh)Soi+nYM0 zt_}fPuhBPbGtat?Unik>7mGQv(>PHi$)s^uz`p1~`ZHNR*Aki`P<|UT-xOdUsZMgt z%*?IHyYSKLYuJD)X4C+MMg`ohgeIsD;Acs|K6^mW(VbbbGj3o?*@O)#23IL>=G>n{ z(M6I`eHj?doC@E3!_f|e;hFLSAwKv!zw`I=^OB0)*F@gKi~lWL=)W+f|3Zko8tOnp zSt6-!oiErtSr5PD>oh8C_j89t)ui`?`I|dewW|-|hy2qFPW}g0^;KATd{%dfyQ~W)0geX zIm+-qvQ+2HA|in;IXUX$>y!;!?=8xrX5%p%hLO7bov&hGnm&Mw!>*thjsY=#~ zalBNkFMF9|g_SQ*b+>^o6;T#fbSQz*x+;Hy8oQ0KR8T{nLlJr&+l9n$ zYGWXQ8}~l^?Go@LJrnw*@X@>O^oE)^c)>dTD7th8vXjUf&Y!L$#3D>oz!;iPTktTn zUfUto7&!Vht| zkH8&{S8J!OIT5unR!!ZG2Z=6|xg(d^v9*hH9%4r5eZ~}xwYxyciAT_-!Zp6x95L-? z#i3B_!>9a1y>SWybA<62S=?2wai~~o&Pq6n6 zj-?zuyl)q@#=e>%yp@-$V)$?I}luwHt&!aI1)L22(&WgCw}{;oB8hDb#KhDf3aIM!1&lf zh-ZrO{?`rsw^v$sBlkK5vx<7p9{LX^ttrc=2(J_6|Jd9!5TQ^<#>Rwc=41a3o)NDq zX#w6wadjY0e{B>fSS@>rufIu}O z#dW;?4ToTokdBUAkZ|e5g+6b&Y03*^kW9F>sc^+tk6+>2cflR>5;XzHz@t)jb<1A# zc?r2ci%FkMVaUZ(8;LUBhkj-(#X7&2ryB9BB?d4WlIZo|nrP>Om7Is7Y@TBg$}a_3 zukj@I(Wc$&zE3>LHF#y7xS6LPy;PJhafg*#`>V~}$jr=4`oZ-6UoK62qY#&lNZPWL zed}7goTgt_AKYN@8U?oSS*0P=6t~z|*}`2WGXHfMlg+oEmKq+jsbsf7K6;R{ly17| zHzSdk4)DZXeW~GrDeaXp>tWpr$tvBwz5V9PesLcCt}-m##N|5fSp35fvD==GbROj@ z4OLfUSziGmdRj5oOY8z<%)%^UqKcfP%70@VNS%X>rIL-C+k_@3z$sANX0dEfsAVVY zGtg)fiCxBZ-TrVz(x6%9Y4!Y>^eB5XE@*q*s0Ayg6`d;E0jUM!L#UT4e1bI0Wma zok7JnRobnhIkJ61ScB0I=C5f_Mx})sX1qiWX~(@ITE_*eo{J3b(ITT>BGlWTsL8ao zJ?po7+a!u^jU+#8M6|NQpl#u6ioIL%fTL;p1T4R z_S&w&Rs)WMqk(7W;XOYhBByvLtp-0L3-)&RDh95?7h45rDdE!Ua^4YW^~^6Dd5)O8 zm!-Tz^q|kg2(xbWVp&{k#e{eB90Y?)i5YawaDWyX@v~R)HygzX)LsQ}@~k8q`y>Rh zt<@ZL`=xW|FyKE{jRuT=_rGsLAQIPk2Q05tO!Z7FHTFWhf3YdU^;mP&Jahp*$?;l) z`taFi`v5Fl?`1?V?Pq2mDTJA?1KxydC=}M+#?6M?o0uFy0(cCrbN!uXWMaw?vO9FV zOp}-GFh`e#^hSkBC;V(=x8CGsSxu(t3fHXYyi;=;Z8^&M(&1rc}-pl#T5|26iFs zqBai2<;|F>TA{SDx#2d6V^naSlU=m+$kr1-t=9Nf3tFV!_O(k{*=7=a-N44p(DzAcv4#iGZF_jaiQNBB{X?lz_jX`bR@N86S6R~I z7G)vcMf2oSe@SXpoGEws6i3s;Y!-)kT;BeWqcme4{h<5g=f#8$VG+5Djp@IC=~$w! zn^a6o>ssITf)X|0ebGlsiq>QgSlakaa~)#6{r!8QxSsnhWuN(S37J15IauVB6d zswJ8m>^3H182v|f-@d{7nSBhub-BsiRP&wiUbT6MpK+J2;F!PSs5bFi?y;`vT9~Qs z?~u#B;^5}{a`N&*HBYfG9=!6|U3}oQcEepKj_%k^YTtOz0E$R#JP;`FpsuC1Vd|pzATW+b8hUkPGB{Y4NrLHbmxVMNV zq|1cte&&1}smlc|ws4e_pdvUTLHtnt4_qc}()e4}jR(DXrjMssC(2xffBr-J0!x9T zfGKC|B4zd!z*od*k1KbL2tk)cm;0N$dF4Jdc$|2ZEZZC9wXFI}iH|r2TDZZpt)T)p zG1^ZJSK1cgv4$BabK6kuQ(LW75`U*@`PuyjENk8Xtw9Kjo+*GavH>vpaassFFpo1J99W#(SyLB7Rw#<^%hz6 z=1d4vUzFV826jO*Nuc^<{Oek)aqy!hR#JJcqvIg4%~jVgH|a;^vTpuhVmDo8cd*atU#1NfvgE18pLjQh^UCLrSCt!oqS{}FWfEq3X^OPTWrb1|H^ z##Qo_DCu0suM1iFX(RuOcok}i%K2Z!D|_VLv`3wN`Gtf@0iz2VW3sCst>q*r758-c ze>=Znt^q4-ry#x1sUxSRAtId{ znc~X7aW7gN`JMQZM|n(g-a4_H_l%@*s?rmyV?B|ZIDEOUoXmkUNz~&%UREpu7WUM& z_DLDc5j0LpyBvU97+rhNP~|yE66EV>m!;M4=UQ2!U9-D2nQ9U;LOl7SqcVR@ z`H4B_>X+X)c)CrZT#5%mQcakJhWl@J9#v`09?zRj9*$(S2RC2P$@sBa^O^G>WlAaR z(*w>b*@aD3>kNd{tbo@2q{Jnqx>|acS{s#AbZQ8#hY{B zz&xT1&z48O&V-*fw1c2B!!4ShphDusfN1Sf%gW#bsy~k&FZ<~xuo^ES%(*?#BaYcR zQDnCK<*MaD67i|__TXV{#nk^g=im9wkD~vnFaK91>i;=)xNcjEmNhXk;e3_FMwGbZ zAaIxhYUKt*RC__x#5?s~xIgGl75bYd$c!#gry(Y~Vd(1g!RHCRafQf_QaK52*JSqu z)4Fu3GNljrW-=PWbRhhBcm+~6#p@6zCOvyUs=vJG8hGK*449@U+8g0wLc1>{AU~eY zNjgW#OG*03|MEa4Opi}ZCX{>mK1?yCD^4{GoQG!L#3_9n>UDco)(`{*2xOC9JY&|7 z#q}#5e$&{Cz8HY?@6~PnK8ZR+1>q(9tJI|7wz#AjAOvh^`mS-*7{&boB)p_V+?VYo zEqW88?FAnj*QuVBn;{Q%gNai|%AB1A(zwSOl&w{3z8Czhv?9k7W>;U9(y;i6g5ojI z2$8?3VK95&F+nN9pzWLzZ|A=SqTX=$NSpmK1E^>(?dheCEpiw@=T}n<;$G}$LJ)g^ zxd&~{Jtf=R040el)I8#I1DyOS`F$i(Bm*0>QKmWSYjye2{NcWh-fwW0nWcaZg%Akq6^NDAX(vs$>;TFu+ zs%X~sUnOu2-h`g~-C<=Phu`qUmiMwf`DEkXrfTfa)up0KvlwnaKRe4<9Y*a&BnKX~ zF<9LV6FCzP!ixI?loG2pDx!^3eGHj)`CI6T((2a z6#=kxARZd1aF*ko00TaeQ&@lYMnr8TOGPQPS{`;s$8Q* zo{B}vhc)Y9fo$+?4P2d4E-s?u&Af_Gjq_0EDW=Z*VS^B$V> zNZGMFZ5naHLF!gY4<^^=VCSN-{}=*=?_rCuSf$Sa*Uah-S&BdZ?h6+^d$xuA-uSU( zGq7CS+CJi4(zChi2Wn+^HCUQw-!hnm{T0_t0CU>d&c@RttAp0o)^q$@C(^8Ef%&NP@zO4N3+KP zztySO%XUaZHAi{Y32JUgG_kbiomB6!Bd>@5Kg4~m;3t9Y59;dSy8ia2y(L^_(^s5# zm{}5@RJ^}0l>C@^GTDNaBu|20=$B4|uU8&X5AeDi)>7q6Je-dGXfXG-++qB8QpHkS zl+~!rCFkeU`a7@Dyorwi=ZrF=4o9gU=Qigsf1J%p;4?`mbf}6Y_sc`POr0BzbiZT~ zCw~p(xn(Gf%ZiA{ouy7+DLvvaOhwta1p|Q+9O>d*m~^=U)bE01)mze#m;YjU3=uH$ zG<9{E&aN(Z!>ppBq8A1e+&zDbnD8nv1cql<)l6HqS-ozxtb5eVBfv@on1WxLknVe1 zJ2*JzD+a9c(vZ}<&oEbfZH!3=e<|ye(tV42tj|8gPm@=}MK>XN55xKA2UcBe<)&q? zNG@A9S&p)GGD81~_M9y=B{%4BL{*9>l!0)?j+z}Y)?~Y`D79d9b-<@lze3=jCvA*k zs&&<+OfB~$yMZzDKtmUml=sCpdM}U=grI6+OQG3|bu5~G0rpb{lk39(Y#3@O38o0GRfare-E1rG4w?z+xJK+4zt6)noB1R+C!T)$k*m#arfJkux@F z5!!LLB>WUvt8&&M$50>2Y(C(UG-{Y_iCG~gz=)1~oMERh0rtFdX`2&6b z-(6uP>=bg!g)xQ*EAm#ug5WN1~f9^-l3YN=_(z9mvM+^!NiMZMaf~$Lt>E6C6 zj%sE933^ht3|MrE@nq5Zg@iMRf3XSLEN{7?8NKE1Me9S5;jzzSA4UidcPbvkjoBH$ zc=2LHq*%T}a-nmFoU~YvJhay+@-po>?vUk=o*xzMkiB()2F5E|@V%L=id{#Qbz(*T z*+badPVu7sA??2q)qhqcEv^7Bh%4yz)FG89kC^`fi2QH9PGYq9FWMw`hJjYw8!|kP z4i>hNuC|s@Ov(O25B0^1dzEQa+W!4!EieNFi<1v<`*Q$eyvwOhPdBtAQ;)EAReV+c z0G)I{@iNOe>RKpD&4P7RF~_50Cz+F!w^69S|Kok{F)k40YgOAM^wyARK~%t?qrYME z;I{bdSds5{J{_D!x=;qgv^}0Y(0@Tl6EetDL}G{D)_N?9dOwW#qd4Uz4KPiZxby&m zDEw)Ab1`lHqZyg=*a+qZFTW!62PnOkq|rJhHDy_lSNj^c51o`9t}C{@tH!yPI>(Ln zQ7!Cq_#9xd7VNnh)T8ymESxi4>*eEv0YoXKH{}jjasLC|Xv~sMQ`IED$dT{68}~x^ z%!N%Nf9i(XQwg~B_k45nEA1b@BoGaM*36#0?kxAG|4qN0$W`sS;469SH*oSbnqt<- zo4u-jMc2qGTS0vt8UQiAGrteg$LiLxyVZ!M0a?a-?0qthjCs7)gaF|pD2%H#Ip)+| zM(=a~we@wKjAz?(#f>j8-~Dku`Ce*sVdYWwPk_)ip7Ot^5T)|98=Y$r_A^Gb;B3VO2jt6NnyL8?O$(l z-c@l7!$*ABUJzfrJ6(*;a@&>G3u@o~b~jx0m>jUAck35>ox4#*X!yr>Oc{F3^!$-c zrLW5dweYLtBKjlC53xEnrV?c|+uL5*rS(jp%0j}i%gSg!lh}SAS#c_`2F-zCCKzi} z6jv=Czc;8`M8{h@u7+fPsoIhD&MG36`^qD*4#e`1vE9sIP&B#!#%LdgzwYxZW%dR_ zWt|N8PD16Y-QGxD+rP&DsaCt%OF*b)BMlyQKeIG=^IdqCH%raZ#qp;ljE2JJkl#V; zPJ7DW<_~Zx>OJ|72v5#v>HuY9|we=O)hJ{vOMOz^S7w`)X#uAGsWCNFwFW4123~ z5Ay*cwOMU30L)aZwDy-49&iDx1jg_k<~PfI5iD(?c3WUTf$$_)-559cQ_|NoSfor5+B&D z!5m*JhE}xzQ}MAQM`S4!tB5~wty7YeI&%Kbx@`I5wB!8`;ETT)*&@&sj;<7L=dBs+`qXy~wn7?m;a;QO`_)X0=}O-CAAGQjPtlo~rGboU>Yur+*xQ z-#^02zmegL5NxIg>YWD{QifOxDHoP``qpOnl!!eYW7kAXDl|V#_viX%d^qN4-}R_v z4!yT~)g!khIYDPi?e}=gc|m}!!e6^~RelVvM%+~iRRQee)L(vRm=-mS$jMVZT7nxI_ir|cz$WI=KrBxPD!ggmZH)yG z)+EQWapiEv>qmFfTk^bpeM<&LD#_M)g!sc;!r^c3iR=~1&9(V>(zj7Nff@1Wndv}; z7bDe9zE4>aRRP`<^Vl}2vwLZpL$lNR?1#PL|95vxQo!I$*9ZutS4z5e(Ob^V1lBTa z+!t726%g4`^4;^H*ib^vlxa|;mD6Xaqy24vZ^LO_Vt^G)$jr)=BncV`a@@vmKM;a# zQ}4paAiJYr&O|*S$XHrl<#PX#qE~4t2cPdIXz%1lJS3`3e@*Nb2;QUO?X!vA?5QDt3k(!k4m zGvQ1QBBC|F{4+XD@jIuQaK8j9hpR44bSXARF52%;GJ&a=1pO20C>$9V4yE4}(Pr5C- z7O$&Z(D&O?J*H4J_J5G}7En>H|GqdX1}d@zK|w;KTR=b>m2Mbj=#cJFQW_PNlI~P` zg6>8I>1JkVRC0!rmZ9!Du>GBV&i$S9zxRLla<9c&%KJWVJ$feHfb-0=R1=bLAcu>`e9D&&=tu=)t{$`hXx_=2*gSSB4!WHp zrN?YjkLQSh)Ypbgt30~RLiheEGt(OnO(%ui{copF-C4_q36YXpo2w>vWN0-w4A~b} zQkVheu)r{i3{OdRGTFnou`S~6lK1`KCJmkeW3Q4gPR+%B%&6Mcy`X*jQxNGCd3hcR z3wt?#2}ziCNkS$UV)r$k>O6_W4ys6D>-$An)cua7=pGKA%TZ;Jn6QW$z3El~8*f&l zGjzb2#pm`J%8@LFN#2N8RF)+}Yy!r{Rybj7W@ENXSZp$&Vk*|}_1Im}*Dp1Ht8eIU zV7MBsSlhQJ&8e~1#7Gwnjgt4p27*6xaAE{@Rf-&2RcB zYu;yMO1Q4T`PYBIs-)YZXPhe0bG7^bDkuM=u)L@D7Ot{;kPCw;9eyep)26GmuZAoY z7fwfftz_h63{X6x=)Sy2XbHLjJfdNwc^i@H;P)n-x3Xa{;vI6mAk}Bz>mc=yU;@1H z4F*}I%1&E;#&KYHqi>>;iR0)vFlfh4Y1~j-`&C<=wCc{TNF~j7ZTP>czMW#{*Wlq< zC2A=bS)hVerA~OUML*ff^eSD-q4V}6qcK`r=+;b8(~n)geNw~1h_6pJiEVW@4xSD% z^oFQf)_&_xC2_vR8GlhS2JY1eP2N5HRV_wN-{$}QW<-n;7v^atD1vh|E#YhM+m;T_V z&P)-Quva@$Ir&rTQMPTkwIeNV-z{(s&Kvd6i1^k<-wooKHzunTyD=Z!{&nc?FXh-~ z>5~sdU%U_(B||&8UOnG!YWvzq{tH5%#I>I!_Y}@|zp3fXklM#C%Ful$>w+!18^P6@ z#v0YMD_bE2Vy%QHr`d1B08kAPouhGzt}3Z+_#;BL14t~lZRA|kR}5Q-+ecQ$5JgSo zh8n=$qndy5YzXB$w9s;aM@olYM~`fzM!U>nN;qFxa@a1pc|e)anZ(yco4x&leKE;y@Cfp~ zr&{o%_XCE^3Ml$089Jk_T;m@m1>LQ*SbsVM=u!OHO^Lpxy|3F(#XX#Xy7FoyQj4+> zBoWY5gbMwjJ0M;TXgZz0Zo9glHF!Dt}tSYts-H)Kz zH%WxN3j1@Gu(8ufTa(5kHJ*<@XRL)a%tm@w@^n6|A+3i3}?0-(fU@Gd?|P0T)vp+Bb}=KoG0|fzh^aH zh9))jhO0nP@8w>$PJA*=&lY$Dogeyq(-iM%T0=%RefXI%(oaBHw~rqbaE_b_*H#Up ziU7Bvn%c_udczl}-FhUs_VGL$4cHbPJ>TU1oFbt`5R1dMNG10VnT+PM;2IYA|aY0 zVHb=eU_#z0k)3yAny#sg@0+_#Avqq`Roz7uH7hL_=~p)7iw`HXs~W?GI$po^%JDIi zsVk>{pVv1L(N@=~rffOTgiRBdTlt>GVU8-RH5M_V?=y@rYgML!?lBL)zv+5UyWN2i zhOczjmfx92|L9Gt_xg<|A3Lz#yw`S_iS@S@ZpX0C3*@v+WQ!BT8FUw!Km$OFx=Yp6 zH!NS9P6yJjE`SoJ1A8*%dx@KWX5)GYMb}RI4hg!FAkaDhg`kdx#?X#V4AS)@gPei} zkH5IOe0wN#aRkD$*X($3$|oiiz3K^m-5@vB5%0GJd2^g69~VR>D(}kz+V>O7X_1M; zfo7;T7w1gN-q~?qqL8?<*5NvwOk<^WL=@%k4S1oTW3RVvICat%zr97{RT;OiYgcaB zuH9ARuObQc8m~G*&lB6*{}O?7dr=_yZs~NfuT@jWHOV4Zf=+}F4|@l?UHfO>jTBs}nBmlq}W@yN3C z+Ot0swsl;SZxZ*>O4YJR!aKuNI|O;YW+>}5jn5(B#sQ$(NMET%P0~!_19AaSCF6yy zNafJAbxOa?(pF2F0t-K;ihe_TOZ7PlWP967gz6shr3%EXfaJdZZ8SRF?>6#nu; zV~hx|rZR(a!GuthcU^LMriu8YAJ+_&4i*PQKIO%3?30%)6NQwk9oYs{>a+Fr*(YpS zyP}0&U9d4g79pL@Hlal&)Pg6Vqo%(uGeoSb=uL@G*Si+~>X0UOCV03a2`l=s~DlLJrz)N%K6U zrtTr(B|wThZS$fCNQe!>RLpQC2v=n-{sWIzADk^p$WW-W*qt4}Hlt0G;T(c(V1k9( zGu}~BT#5E5|7>MHGBdJ7#Iq+QL67+yb=9@ZjZ`nPsNZR#bC@nxHgoG8BwhNbz@Lk+ z$6QM!BP4iRKN7FOe-uoq*n?zHg5nNB`zUfJDi~H75N5Y-Ef!wKi^MI`Ufyx55q)gw zC%LVZXAd`7sOi^gboK>|qhF)X9av{^_TI)C_qb6G@(%j!^g zxOR4z@{X}p#>mogtU`jvB5-wqWv4NarzQw%ai3izQm^z2l1I9*u+W+$jE&>Szj*uG z8{8$esR8S$Oe|Iu*H}W|%Kw$3*y!z675CCj%U2~rq4_Z_ER$Sg>j1BoHgg|1EWD_+ zR0{}F>@o0iOS2gq|4WU&OR78lpASqhFq0d zAJa&_W%J6=*1b1lAYtH>4D^0lay6_+;R_nN-P4?Yf-(;Xh7E<5b3FmeY9pd8O4*A`L4vvL^QdzIfJ)t}MYDNd@M0;sN8w6=t=;_8M=S=wIV zc@-B)?)h5wMNcCr=0>vxa1V*PBg23~j!@k`eYzFLqy)Y;zoBTB@9)v*KfZqhTb3}X z5?S&~p}Wp-e&xZvE}Mkz{AH;2o;z}d}AW0Jy-G^*yzbrpe=^?YRqOm z8%Ers+W(`b=C%3--f72OIL880x|ntg}P8r7{sm{*)07UbcNs(M>< zCM=xPyS=499ega#sM%iQq+Q`I=#e7aOqAw(CO}G)OsiYW^K+wyMJJx1Q0BLKqR|{o zRU`Vqea9_K=SXI>K{v#Ff`=tC(ij7sVrI*gj!U-B%1`W>YSxZ;6BBM-30r=jCNjs` z9>cp^RB*T1&A5KlPldy3ra}VbdH5;KP7t0T)FvOP-Z3UEDTnyp$5UxwM3&;$L#VJ_ zi4~$(6MQ2mU8lI+rjbzx6Yk}CVLf^vKTd7!`rO5hL6M4Q8%h9W9l-lcYLS*-v+G64 z`5TSs-YmXqf7AEIa?3OiCTx1*Qa;KKxv!FUr@YZVY@*Dl%ZBpK4y8^#3%hY>iAOBs z3g>5n<)0=;-}CC0@Csc3BbFamrixi(T@&i4kgl_7 zYJlg>lrxea{%Y}?&cPY@pKdzMVdU2+o3kA=YM;vG4D)@#ir;geE$JWWP2tUQ(9MFZieXc`lic!Y_S`xn(!@J{Mgp%>@Q$pv z`_}>rHXGDByFQeYP$>B%OEN~YlGc}y`3V6Rj-xgYb@u^EoAX(VBj3iOG}=me z3t~@h6zPZ(b)|TeO~qsTTiui2RVoi07`}Ri)&bD6fAb~GQ~Nl@-%%E=x&ra#`A@H2 z=Y>h_q%#JnPjfpw8Zc*HABV;HhnlqgrZa?(&6q2wQ_^^WK~g}ecRwaLw~wI8)s)7u z=>fuVrS40Za5(3O+ERF(L8YO1TZFufsQpVxH%W7O#CE6%W$Q2A&4<}J=}a6(v2%{j z@mKHf=QLX1#13tU_pv{8u`i9(LdW9G`KgyYB3=^ebDTmtF+w{Vo|0SGtM-X=%XB?m z)YnDD+pWjC)OvHyi!)YoC(j5#R&M3ezVERO8p{8sjWvL^$gC<{MX}m|NsBMX zmUk@OXZUsjXJn1_rH{|%V}R0<_sDk73)-SR ztW6Nq1#=#Ccn08Jti4@guHB7eJNo^*w#%uyE>!x4GUf)?iCP1O3kaEI+E`WSTJ#A` zN-t;QeG~0P|H-sMrzoR@*e#&YDaAiDLus@@kLfME$OH3~Gjs5)M71tdfaK$*Godf*k1*#Kdxv>^R^FINg88Q|FN@ejiuC|j zv@y|xh1RY0$$aQ9y^AMY6E_k7WmF!(Icd7Wot5V8NiGjf97fbX(5O!Dz<5{Gi|iz; zzL=hIlN_=+(S7OeYSUQEuwUd{;0w_4l6>i{qY_k7Cih;rDy=4z0QB7aqovfIbAsfo z(+FJtG8VYZOyO9XwrFGN{AQLFLxAvCvK5^vj@-G=!dwLIgBuu=d3S^lm*)_9P>uA4EgkwI!->csalP4ORSVRxOjB_yWE z!wT-c)sagl5;>#xpVDUpu2j%}Em~)~8cxohKLzLd@yOQrLX4*0jlN`Uj|V59RwVv& zj}%08%9ic^kWECP+K#dGP}4L8IcCZGm)nF!(6CGYQ;DKCdY`^LPBOpsB0_SCUuj$P zjq^ep_DIOkzBt?=KWS!zwyqaY`&ctq*`6czZ`Th!I!MhY^KjWp3oM7F`ZQ4OtVjI) zcs~C3dVivY{CpDZ;B7$RH$v)!rmM-|w322uWqWB7^w^H@Yy;)cqoeE;6cpBl5@LN7 z1lL%?3{X5SFWChWC1|qlyL^ep%B!%Ve9%Tbo|1*9+`48aP(ZQ2_6ki3%EhF1-p&of zI4n|bQl{VuKnRfx$?0D+B}NOPKK%So+P;GGfRP|{4p{n z8JW|A1kQh*B0(F9S*13E3|ulUjRKB_^kXM;?NdgXfE+yc1j0g5_tOoly8to9kkv9; zy;I5J?|W+1a`eYPVkG$Qi}X|S=Kn&~as>ij0z5BX4N80OxH0yib<41Z}858m+G3^4NcJ8p?TwNX1jIcbl37r<_iY zL`2~4e?J{dN8c`_14uwhm>Zy!%1t5x4zx)PJ%s;GSJr01W4+~T@m@G+KOh4RIFGN7-;esw%CorUht{4M4OO3xrj2F(w zD9)w}XXvv4v-j(I`z#5Sv*d33g}pl*8ktM{YxvgbBPrlo>(@s$a8eW~>sKmoe}@C) zhEL$~6P(#EpVuSv7L znU+)UqL*fwA%!&st)>~JthEojp4V*Sw3*3rVMl7n8htsyw|(IFeEPU#{0VPtg0(~4 zOv!a|1x>X`6_-bLYGiRRES$~26!VPg>Z8m@R*gl_8QVr{K=$mxy1iZVo(0v@!Ke`R zjlZ%e#j5~doH&3u7)wB-7R|P@u9$=WEB15Q1-bd)PDQ<(uiH$GnLjM7F7|d!RP&DA z9ND7sBcG&*^8I@Vf#Lx62`CgZs2uEkA0>Fvm^nUT`{C_g=urKJYf)aquz2xc73+Ax zT6tz)%cpg~d;J62;oYgsGA4J1bM>*q?EObfY?stB@!qX7R`~f^uvF~TTOZOoGs^TV zmJc$bd{m_gM5Asr$faqHQGI?LSRqxdt<41nBGii%2QJD4Nm?y6Zl zeJO<~=i;{FCrQr&z#XI5nnA-p#JOxFSnrsP#9)(eNgnmlx5XLK$MJYj-u6+G|7y+e zRJ(HKe`1HwoifYbM(-l8cb4=OP5->9L23?8ChFwylG8Z1J;i8P=Nx~da&_|i7FrRJ zo4T1u5H;m@mZJ`G8vZi=&hd^ns_UBdMPhe)#GC{9R)8Avv4eisOtozXARG55;prN_ zbNXh>RMv+rIkgkcX=az~6YM;E!0@(v`(JNj00R5(Q&43XECqU}@08H#b)dk$!d z6C^f46nMu9Xs<38m=j*}+_{Fe(}!TzIWpJ*x3+V3j#h6rt#aDYku3H8_MxokE4Nt8 zTXBlwV&MHwnEVN;W!nu}x$Z3R_+BC~(=`3HA&!SfxXw_JkI$+)XKME~xpziO1T9+LIf^B2uuo{m1z;1Dp5)8)|6gm(V=9jBVy`!<{m z;cYRizmxavJ&Q0jaM@s(<$|D~fJJ;TaWC3|?2jd{dg(KKgI`>c1@K3uI}Mpb`=Gvh zC~$Ev4?$8oQ3d13}O!A7EcPQQ*muHCxnSr^5oe&*O3AnS~pJ|?Zr?{++u zZnjuaN$R1>KB=V`inTR6Aqb|u!u=1KmG{9z9xC}c2w>gsGt{|j|H3{E8#u3|Tp`VT z?B>kY{QId^r4R!Mv)*xm@=EGnSJX;%GiD}p?;wk@Uizp{BvuPc29wG=n8?9X#MmC+ zxXm)QUOk>1JJdBdyJ_Pt!!@6TiXN$W3@m;oeH|eK*;v@?3yh6Cv$7qkOcglmoa*-` zf`-~UK1Ujzfp&bTg^)UFTf(giG%z>>rWN|J@v-|`?_m`$N-e-V$ujZ6lDwTG6)iB1 ze03_l#5XkCVfApOJAW$r1uxU048$6ye|eg7wwBh z0Pi1_TD9nsAK-jAd+A(wp1t0=sH!n>4z>VhEwOSjZhL3dlOkWBhP7vxd&rD#DKL{I z#~!Magb@4P2T0oW@M8iX;pa!Ll!NP2ysxb!%pU2sKA0KVZRT9T>8*$?TE#*tX~kX- z-B!wJo>?pQXX1WO#bf~P;^%rL8S0o(R`9AMDZIdMC0OE_8insiXl$dXFA~`@w13Pt zFAlMU#`>Zw_Voz<@#znpW@C>}HTNwpi_>QDpYjjJG%oba)!ExE$Mp#x-B6~ie8+o{ zMPOk5$`!912eZidD2cR)V}d9Vc6T{}7qAR-Md?HUni5Zd!qWeoq%-4TIS=~VE+_u+ zpgub$P~R?8+Iq*yZ-&A}1M>mBDF#LCaJne>CDQVX18d6aO@rkF?^fvet^UHzWSzep z=Ty-;PfkAzZGhh%(l}O;Bz+LS3?CjgS34&Qi;1~2Sp1Bnhq{xZL|&*<@xIT)$YNvR z)HWQJoC_T%L^+^(?)sYM`huc7%UrdqYOV^4SGltGH-0W{jEsF8Q7uB) zC08w8!Pyst#0nS`N`Sq9u98h^QAft%>PHPceJ2SR8?-VV7=%c8cxoCZs!0w5s_O)6 zE`!|sBd-N!{c0OxVT1vDhC+jwT~u*@v=2vqj>48>f(O@4d_h_TT5!eg1*Jd;8U#95 zC|pjCn8-TtDa=`DlCo)H2Xl6%g7vnegu=T%#aTdTJm-;|7zY8dMVC=P2v(WB1be%C zrEqfdqhslrz$2=y4Y-1#p{#5$Kri{~eFKGz{+%SmQ_?oe@e}s?`8bkE6L0SP8vI>yos={g=uW&RMv_{!CnA_xC=(6l0iI9-2bvY26iF&9NHAHR0f zd%sCaO=7uNIArxPljyW{xhI{-rf15MQRt7Ykk`u{1$rO~7-uX%<`6#qw-?ko05(Ss zFR*d9@~?1a=3T}5v8eYM)A{3Q-~E_en^KCx_g{Y;hM*|VRQ=zRaGnqDlT7iI=Slz` zyCsTYu-s~DhW(xL%wLIxK^9eMUQ&Ff!N1j7lqZ^5GYhu2S{M*)hO6t${1sHOmTR#2o|KIinn38{Z?e)CRMCS2ui1_I- zxp`lMF~~o>g>5piP!_qpecAcvSZ&=`H96Y{7s%21EOt?pLhmPy5+Gd|43S zk)j5CxC-yySuQDR7xw1I)nRynz!g)s=U@IIARu=v;xCdPrY_E76W;hq zML(AbKI=kpZCR&bEiJKs!dgU&wQ=WnxB&MNQZb&k=PrzVALZ&1r3{XVJU)=B9h`2s zr?E%RWqW%XW4h6EHic4s1&(4MT%qKulK;EfiBbbF>IpS#<4nr4KDqg`N(v}!SMb^N zv4Rhe`X0zdd!@%5{nTB@R%bDa-}H$!y(|$k1Vt~hT5AAHy`^8D^8^$HlTeJAC^}yA z4}nZR=Q!diDoU@I=EFy^rSBXuIvAP^9u3{Sy|H>-@zYoU!?7vea>s^g^Zk2^pN&%v zRaDu4h9(;Uh-fkgPv4qAv6A0FuP#wmSuPiPRWe@twh(_=Ki@g7*=j&$bo9x1$N@e3 z!%zR*ope`@fx8~6a^VQEa~lSai#B_mbOSt#i8;fY;)Z6l_ne;V#=cD7nFZW+ zgHOe}mSWRiy$*rPIdwJa|oJ^{l)9~o8*m}?-jFG$|cl85&wK8ZwYEdyJN*^8xEM6O(wXO4E3 z{)E@T7GxCYm8O|xW*hGuMN5%XO$c>qD+j1dSJ#L+-*0mB17m25KPv)DIN+(;`8mO{ z)duJMNfI2d62PpbHE>qsw#k%S-Rkbm&OtL^$v0k#_gqSq6k}(Pe#P6aBMbzgB&8|E zN8m`vlw0}N`-f3H7pCUf-tpx&&#$E3_=RoV@c_;;7Xf(MT+Yk0S?Q29<9>;a7YRq| z<#S2Fo6fKUPbR&$Uh@lDU75O_;WxTs`4BLUk5!yjkvKr)rl{#l4k%1?D;E#OjWBB|5`rhDM~UOrmGx)sDO3`UtdUHvynGKJ^ZkEraT`@6DL}WLFAf!yncH4J^g>X z&{&Pb3*xkIV{;ZarUPHn)y5z8{ZJUx^!5>3)P5Az>`VeIFTJ*GJ5$p=p83ktdT}?h zg4}P(1*}EgN*NI$M-LynHNjPVrcJoEne_`0f(Xmz8JZo+@SZt3 zIdBv`CDj$e2T{6)Q$usrOP>z#(L-V3uGZEdeXhs|L8sA@&&c^|pFL-J$ho2cp?lFE z>5VH9Jvkd*%m-G98NB*tc*fITbCxZ+`aGoQRWLCNZ{u{7EElOBHfL?xBxE`N4ms@f zT^qUi8XV~0*4d&ei+pGj-$y)>xku3V71eN@9)gPEGv~+9)2u5Pv$Rg)^;S+L+Dz?2 zkJG=^Gy1=8^HlC2QxZ0QFu7O)Hlqk;l)<^-*%+OjcW#mh+UOsapT|#+OjKYI#(+$z zdZY97DL*xRW(-HUXfZa2HiWc037*IgxDWWLY3N0k&;GF?~dox=7J6QdW!`z%#d*Ic|e&`5Y zHSA-9zYi`?74RqA>dCXS0}vVc0JEBR?YDVk#tCNf{T&F{~aauzr<E=Hfa%TGmhtXi(FCBm1ySM!RDodFE-^!A+0T4=>?k74=)YOLNxIYzm6<^9? zTo$+Ar<~WHn|)rW)Wm*4ZLe!qf1X41+4O1J;YXT;2Y}9S_HVSGP6=LlnAaXF;46z7 z+(Fh6jQl1gQqOz4@9K2L-3~t6aL34TMe3y*e;F^F{NZ%SI+(M%;Xgv&YCkR{2m>H~tkZ<*Mm0=>bJphVbIJ$J z5y5muE(tz$J*lU^STpdymkO0pR2y#I%!qN$NPL>Ud~yu=Dp`nh`a~z+v8IkwZ~MrO z_@)eys?#XIe6YH{v$uHEWZSW((Y)0Q1adruM`DkKVaGwtDa~Kyly(maJr;5*1omqV z_2~wbMXh({&%*F*(K?^coq)&@FBeaH|1l6bxSlP>rsqH%?tB8$cfb6E4_>$6L>Og@ zki|y+xvH0z4mM%jxAHhG0oO*%EMW4z7TNX0|9|N7hx1Kl-;gI$1P6C9(p}zKjSFm_ z&N>)q=DOGT45d&m7uNoj{MWk?HY$aUc4Qy3Y24z4{!Yb1((=z9y!5f_FBuB&neC)B z3;@wR*8#Ux4^^1G=fJ@eb?se2@-0MNV=1x@zyn})%+Co(N}xk8IjbHYx`LSw*e|RI zz98J}xD$7Gt?rxLQ*+XALfrsF>O?6Hu#vCFAN4J1xHTJNFl^DX@U?K}`|*}dQ5QA+wy0Db7{-TN3%N?IKpmSF=RLd;yWaw zlR1-qXCbSny`IY7-^;rk9@1954y>qNU#$_meb?5jx@SFk?h}rgn-uVrmOrtVf;hfE^VJpv&n33;;lTnrx@ckGwvj5MsH z9n40`Xp7c)=*>_vgj-&;(Ds{%jt6xzO{4-g|^C?S$U8Vb0=2eN14T(k36-%7ehObx7>BF7>W!4HdFdyZ8`9^hSK7UXx2aNdL*GrYf2wYcy}jAyaOGky6eX5YVFV#*

uQqBc3xdgunz8_-esG6F6@8636{qN_Ur;pDVqh)Q~4=p?E3e1 z>Bq+#!p%iOrFVlQ{@OS927tW9PXG_{eBF$oZzXCWM|9f-vL^x{&mdqJ+!I-a^_jI#Y2plA)#&dqAje=A2emYg5}e2TgH_%yH$a}}R8 zAKq;mt|PM?(o;|nI?29VC&jndx+2W5w3WIFghPGOp@)AcoA$-vr4*)-$jy%y7 z#T`dUTJ;wJdpO1PqF)CgI;Y;tc$n48b`PYz!)HcE| zRs1#Lw*{nq0QgV_pq7xJdamILEoag2dKLVdcllhWpgqi}sYf z7!9nSobCnOQugm~WC+XbSAmD7Wv~U|4d_lV<-3%8XQ7NMqvI(@I%Rc~q`j$MJ28n- zdY)ney+K2wl{v z{OHUJodWvXhPPq}%bn_+S+jt>v~elAq|n5Gp2>RvxA!u$JZ}dJc(Hnhs|nFJ&zovY zfdl}@?+}L#zvNcOc9e|hm$AQXUm$fga-{VxeABbj8Q zMrGmtCW}hHIhz65vLg6ZUB+4xGyZi%6WsqYQ_R4TfMFK^M~6u98-quhu&{Uh2P6Sw z%8#twt-D(&aK6d;Yx-wSE{`F9uQddZK1Wa=4Q6--X6 zgd(9Z>9Q`lgx){PIE}gGX@5pURHXEOU&a0NH;SHh`Zqrm5(<&NC1hAK7eh+EDWWLU zr`X)Ag^#s9Er0^W9+%)!;{Rn-VtG`y{ZEkL5{cJcW?E>JOu=VIE{(EgEpHTdb%(s< ztVT`Dy#^srdcT7K+zRF*8#8R}^LSRk5hY~xa?(*Dl%8WAdX^IoF=&6`k z8I(H$Y;sv*@~cOH|IaDXOi@3nF04ii{ZOtrPV)O)TEbwtxVSTtqRaO<5 z$D1SnB&0`~S(uC70r54}BMO%~(YV>T-fA`En4y7b0b|R5M#o2voL-GtDYrMk(Q{Me z*gHE{ncRMu9ye=&7wp9e?y{PVDGGNKnfUPEN$wTzTGj0zd(3$=(|3Djuk*w1!bSIW zex`~qq)+Tmu{;?`JzzVD?srsnf2RrII9N9y@^sEx?7HPsMc&$pc2Ig4*VlimWFhJ; z%lDqKoKR^lJFWi;Ks1}i-~x`U{hZBr2_b&y#g(cfNO~8Db-oJGTyL61DPp7?5QcDI z1ELbVvSRx1$C{rfwK^5wNZ#)g;flOmpI+6 zXwBXJ#sCNkyjII_R7Fl-6Y=1DQ%O=7#xv==Jg9rgX2olibN^9#5$umibnD zK_H&fe^iAqe-hQ8hgkIZx@xYc%Hnv^)1Lt1tfF(V*>>NUM{X!Hr&o9KmO9&9$*E{i zCxq|#ktCPWM5;WZO*FHVCr3X|uL;knfMabVB+Iz&M9bD41>s`hx7Xu0XO*=?Eh{G$ zZFT(uax`AAdVDAYz>=6fo}!3Ub)!spF)n3R=uT${gyn9lM4Xn#r4!>B3#Y{jcmhJ&4#aUb{ zWd!zr1S+a0itYmSLS(BL?5Unmo>;V)A@=+I(>uXCKTSY^N8iAcj;rH<%z+4^-br^u zZE_~OyK@sVFE22|k5wRs-IdcU@w)8mpRqODml}X9+aNqwuP#_QpnIbF26RnpoO^Zm zSKfJRt3HLZ8+@r&SWn0w4Op7hF4EG(FoJrJGF(Zym`LXQ-b>tufVnJHX%uwg`+{U| zSGgsX@3W7jMd(>rX-c;% zFZoP3jtYmGSeQJV;WwZjQ*Kf)8udX?dj}0|UIk*EAP6LC={35Gw8u^Y zIvNkrD2=2vIuTx4qUrMvHtF-p>Y|!<1JK}l!XkH0RwqMBMeo+C4s%E)0G<=-) z!JD~ccpBq!K_Yj%deTotMV_Ssf$37CoQ#gO>5lDW6N-6o4VBOr)~556aMHj79^ktc z^J13Fg|bWLLzTao!(jfbFfru>WpDa*(qK%qVdpxn|1Hwo>U>w;w-@%86IzD-2EskG zXI6WCJ>hd7BigjPdL2wXXe@keQAmxnsM3Xah%5p zxHrK0Af8MD57^iakt+kqnE2mjPk-E-MKJC!?6QK+yU0TiyowJaN2&sbi~Z&H<;a9a zui<>UG?Y$rHd}t0(R_Cq61qo{9zJPnVWw>#w)ZZ3p zFa%9DKs{9Sfa^j?kDCm%V=kE!R3J2*5QxPeCBN7ktiou=}{ig-B)DS z*aLHM_?rHNyKNE65RM{4did+T^h1@gt4@4W{{lofcuc`m{mARBa6!PN{pW;+wS-)6 zFmO!5ZxRv3@lbw*%YRh;wA4EFQBg1a}p0r{!U9Y{aJpYlgUEiPL6uifopGnm9oQRk>@C#Xy6p5CBc(OT#9CQb-f zeA1rtjocm!>=!>4j;uS-7Zvl?#&GJ}<7WI$4y88#AV(CGmk{Aq^rA1n-|*Vihynkb@aJf#jjYNCKmyV@4Np3 zQoU?6DTkbphXgqi@XRwLt3?e+t2WO4W1p9y{PVW_`>aPJ&}aC39QWA*VkTrI0)(qiNcPdP3E|>ahYiu zTZkf9=Ucm<3TThq>aH9bALLy%6z;MwKf7z+4P*g*aTfbo&6keVHLirv&v~d zR6|VXZ5Y!FYVTt!(a(xpr{fEhd*O5u!K)q|an2;|R;|+I?2%<03ZYiZo(*hj;H||6 zjpM1FV)4X&M2(YBQ{Oj>pWo*9I^JKLAGIq#3$-e;lRo@G)~h{V^vMjBlXgdvrL5|y z^GuDF@bp5g5XJ3YpKs%pWoT{#w*efl42U$>Sv49QFB+P%j-O7C;OMJ5 zU@kM1+resez&_c@FS1_yDlFD+zvZ%&8QL*6U!!9qlXZR@JM58cA62=G?zp<#OR>2r zVj9g55z%D}S1pR)O-1Wv8XIs~w$B#<-g(ye!?;jd- zlj8T+jdTL)$D!KI&pkPQi=YqvB>RO3lZzS2!-o$$#DNe57;Wu2_{PSIePEJyM3-S7 zfm~h7^}E-_XZF>xpW)p${_LIc^c%jmACPu6?9dGRs8osN6*JWQ*5=lnXeSOojz0ex zt|aRBvxe4Z9_99Yd3(-4zZhrWglY+Or?+zg&y+TS8>_lVNi76+DR!pv*{n7jYWY%MzuvlGvH4XuAc@2c?mATCQi$xHs*M@J(IEWm z6Z=n$Viu=i`b3(hPiOq*8<0j>-@_>bMR!9R@LxyvC3#}ki+YIb5O&kc!^DM!7DxQG zxyqO8Q`)P)&x}%X%^4qgE@3_lrQlOfdz~<5(~>Ug0(>i*)U%85iYMm~=5N4OY8Q;k zy|W!hKv-dGwG;~dM!7Zom)mpKAf>TMw_Wg~QLPH<`l317tm#@}_v zINj|{=mH=7UO2g1Z%|c%XolmeU(^)^Y!SYzgu8SFE=>@7I~Pd06zc{E=kA2~U6uSD zEu6XZGD*hN=;Lw_$QfB5rz6au3sGAgQHv}wPSd)~w2K~EiE z;(9ZNQ^B|=`0fq%c{GWG96u4PK5o=$AO>;)I9|#p@l4m z>I|gQY6mUfa#He48%*SFj~2`5%h>d%(70>@ZrwuXazO`mMUO|R1h<`vo@#QN^iOp( za)J(b_CV{WnqIkI3Q1FE7!HXxHHpg~DAaeDQr1gJl9~cxw+MEsML}fu&?(j+SQvgD?0;k zycG09AG}kcv(-dt77HTRz*Kj4*M3;$NXB_4*y*CQ{0bbIBk9{}SX>(_P=>N(V-s6SY5xf^qqDI|UEd=f8B1ddYq!zARPjvBhZ{lbyY*`YQbl1)N`qm=- zZm#i(Bx45wqHVc&^)Zm{Zbp zOjmorR$W8A$#r?i=~4TOUg~Y82^MTCX5Be;R1uA|y4A-Hx!H|rFoSs$i)%1&J$1f` zpZ>cv(Dfa+4hfLtqPpD3@Dr}|&_^6>Ch6iVu1|ItrQDG4&(WR3?XCWgZ0h5rsi6X{ zv}trj2_$qCG-VMAp&8zW=#e(m-QJ~oUncHechoqqVHyT}ZWp=`XOVK+WOMW7vgt{m zxbE*<-6EDu*E~||1R~tBoSAnh_C`MVL9{nJ1vf$IL4J)2QqP<)B55=6&=WJ&K4VoD zoPE??1IaR8#Gug71DG?8wEN>1>_xRENl^~Ai01ni zVgf^W{@SS*;cOa_@YxE;)B*bO>mADF*5PsX*hP&_7znDYy&50@i|FoxY)tJ_?@!%# zo?c`>pfQvw90#wsN<3ph7*60~#ZP{F?92KfkWLbOP~7S|pk;t-xvTjdu;E$}-V;dg z)uEzgbzEJ(fJUK_YwUQ@i~}HKaCkyD%y(Ei>0E`4aUOQj@5^lFUY1^n?Vmg*0V!0c z>SQ*ulTu2)RW~l?3jmq$lb~a9c>S4DH7Ss)TVB*~`|4~-6|h;X^GQ&nMj?PR?3Nez z3%P*2n=xIMP0ea{yU?x4HrFhJ=o>TXyBoIP%wdc*j^i~8-3(=!^L!3|s$jX@i??!E zI$jqXU?}ZTkD9r7@(n)IqrBs1(d^F`f+nou+$p{!Xch1<@iOY;W$Mx4q<75DAB^<4 z3hAUa^g#=o6E9QM!+jGc6NHetI=i+c4&xE=3O0tUk?PL14l3x8hmyTEmhAl_Fxvc| z$#ybNabc|6P5aIWGvbimv9&E=;Wn4w{|!%K_f|qqvpZns()L2a1iVViqM7E6EZW#} zjgR7Lwnbgzo?r&XBb*>Vp$Bz_Ja?-{L6Ygi*H&S{yI%c9naOsatQPmRog8adg~wtf zO*Mq4b>jEEUDIf&yL@Ov#jRt}w!+Jg3T9yC-DAyT%1hsejgx0T6%B{pc$++)A`TuA z%XARWiF+J`7EQi$^UQ9c7m>iNmz&R>o5v4K8WV1R*@x8`B07CD!iU?pw*?MZw|TiD z)i0D<0+mJaxH2X!t02ucI625KX>-eSs!oZ^`fKUz&DRUwRnc4 z)AnT#Q1HgrQEN;Y_JByKy`-c4f*Qp*e2XJlugdn>oFA?4}qf?MlNUIBqWzKTB7Sj2O*sL*8_b*j4>LVBAyN;p#U! z%$)e;upMJgUN`|dw=+ZO-nte3om2jQwfCJ-O?BP6c2q!AR1^fPAiYYjDk2@}9hD{} z1PDb+5)~1VCPIKv1!>Y-=p+In5SmCQK#&e0l!PRN5OR4x-`DevJI*-c8~5)$JAd|0 zvgcZRtu^ObbFXJUvjQ4^pcaQdO$)1+qoYn5%39tmQ{agx%ja!&!wTcn)R3uo6VcS- zj*g^n$d+Ma7s*U>Sq7IZ`g_{!Rc@)kS<@?zW!u?T8fQ&@JbOxJ&7HsmK73}|s5{f% z@T;$HPAYI$FId}pdgdUFlU!oMB|@~N5QVeIv@zG~>haFvw9D>&&G{hP0Yfdjsj`3k88CK2db4 z7V(%8JwYVh1UbwP-3tb_u{Si^?``t?=nn@j&DQs@_iI<)8z})M465$D+MD0bDYk{i z_s|U0!NlOb#gDFE;%Mq|LOJGQ1bUUsCK|e8B8=-7iKA3D@O4I#r6C24VC_zYt9MSL!oDg85=iZ;Edsl5 ze=b8IK!4h@(NbkAcpR!4$>2&=IN?y3j)q45HJZeEM-Nz`=_U==gNHO%d@C1BZr~FT z{;iv@;hnwj-n`e%(=1%R)v0)mkqdww@QA zsx?{K-ZDZBH%=^#cUcL{?l?PU2wL2!2pWJo^j5c4`ZWGEeZ189zx>x~1OkpQN>6my zU2$A>4p{H?58O`3F`pw3U8lck{<#j~|ChU%ojo`|KvCI^sc@Us7XGSG%g=bH@{GyKW7P+)hY~!D^m&8F(M5=w&&>oin6q-!lY0*z zcKs`2@kwBT=K&OD*UrGULVHsGgRKU6s2t#=$DLBmqnOXGX;8RuqkCo0XZPDFdFS(w z*j5yEl||65o#)ZPLVUpD(NwiF__C-7J68X8;z zaXw)^NQ@ZGBjR)^vO1;nFV?$*L%zt(0dX-zF!%T66K~u5|GZhNVWaT*wfTgyQ1jGe3bj5Ve_jT`9Z*mo5#g&_>Pc zn%aAVE>5#&)Fa1Vdwo5{CFfQCmi^T90}h>+NA7<$I_AvUc1Y{^$D<8;yt;a7Y>xrGI_Qr!-Usuxx79dS>RRAO_C7tPnW4LrYf-SnJM760=9crCipE zr1dPVZ9bR|#+v0hK|Hm;x2kTt=$j*mvY8wl%d(0^~YzfD0 zWjQx4410gEt-p3(&#LOWJE_5A`O~F^2e}F&h=~NkGhb<+FJ1Rj zx=dJSYTLMZ@wQWLOCU;q&^l#o34=AMwlC`)@)g!K(8{P8w+OtW!(|F@mTamq^JiFd zTJxVLR$Ys|3!JsIDc65UeRiQg^=+||%|}+6;Ip5W+%KZUG|j-z7s5ySg#_Sn`TLyC zioD+=pXSLF~~^9I!DH`gpId-q*>H-W~&@gWvZ++bAB(!P&BYLt#U^m=V#&*QB0R zQ{E#2q{qw-pNO?LHDfyUadnXr-g)f&`eWuRo>-*v3|dh6g>iu?;811N_2@i09r^P# z*N||@k1C?i0va}AVEz>L+`~SwC_FqUmN~Ci zCWh{}2WNJbg=tuFmGdMSeP_~Fq$emiPtaF?wyK%0a0)S3Uf}A9N{_y6X<;)sVryeb z6B%q7Nq;+(^z0}iYh~PGSV{3^ce&H{q&Hlyz8}j z@TL^gqbZAhkV0cuSFbLn@a@F!x{HmfP)!;sH>_d*?i5Z2D)(sd)@)V@yKP|8Rd-Dd zTn-XgkNf8PLRX>pGULabx72ks8%Q$cu_~J{((WrRahkB=o!7T;by2(?gDD-?c;X;c zAN$=o=xl4h43N;1HdpMsjS~%AlyQbhGKm2uebX5!Ge7TJo}8A7GN~J_N<@;fnuxV@ zLh3=rPX>LTwt-2~LhTVE_tpbYRb>r#8QV5UY|4jPv5bVcT>}DRx&Xa0_nBMO}HoGX5xeUp3IEu5& z{MvZRklWoaW-*;bagXH#L*z2I6*}WlWi|GlyCZgI!ALpwMbi>17`g}m-iSFMq>Ec! znfqA97vQbcHba6!rAN)?;aVHjBNYLN7`PJis)g|gf_o#zB*$!CjZ=s)Pn){ds!E&I zfJ^w*TE#8a)U2e7jH}H4$o~eb##VL%cIcszd3*JNy88V{u0``7qA`ygz&d1q%^b-! zX;uJB=f)G_=+V!?l~b4Fph~hr8+~bd)lUK6x+MKw?~Bs>#z)lW8q0hM4fza7j#7x& z=Tz&;VBdRvIi!W#xh+m8{S^@{hlPkY8pZV8c7K#7n%Y@(?uv3?lZ8rw1(WKqVo>GDEdYr@2%$Pol8&%%HF- z%~K;oOf_lAS&{B4o#NwrkGUYY18wF5I6Dppl=7&=@xK1Pr9EPXj4ShFv>;P89dE44 zB}BY~l1Ly|KF+G2Zz-EymD1-~g(o*E^;|Xwbp?EBc0|f%d4QADJ`Y`MT^3bv-VL9` zCaQ~m?!obSu0!#Nsr(>UXQqot&002omGo9RR`-Cn*?RW_>PslXd2*-g^G|6%SD*=> zZupbZpb!#537ErF)&n?WkjUlpjU^G&K4?hozertl2XHwnmf$q2O9RZ0mn>PG5CTtV zB%{Qn_1G&Z`~VP`l4_7J9Wf~7BbZ44Ja_YH2FU|D&Z#QQ6koJLnT8n;Xb%l|%gdiT zb6zpn608k$!pruAeGvkyOG_d34`Q1B7dw#COFaq@nrb1vYKA%LdVB;F@GP!+c?wtH3MbTQB1SrZA zvnZ>Qy}~IkvSGUysvENrMtt3)Ngy}I|;O`dmWl>JQdY}27z9&?*$n_nx zAQAL~V=U=gNw|nDa1{;@mzG>@)~WvdlX>aM+YdGgLaQh9974U8bNv;S&YCP5zP& zs(%4#8ip|~^zai;#~K?bNMSj;aF*PDlx$oI;zfm&Fb`6KyI4M_Ci!{{8nzH^Jeg6iu!0p_ob<4N5OFwT{Fmg33*tSH<{=sACSDFj!2I~3r+>V*>%w{r#X4&{ z#YdvP%Y(lc<(%GtpJ6H_&4^()4 zS7B=Ji$f3-tXf=NZ|8tSK{!pPAmpB=-2-}d&5pBhEGQZnxI5Gb$veqi^m<7FuL-#z zZYKf%(1SWg4_z^60~J;-qz5DSPh_->`3#(~)^}@*^&F6_bv7-Gw*u+~j{A`6dodN( z{Ng^9{lQX1VM?;;?A}w}4r+18bD16q7HShFH$%f`B;2PDOE&)nGyNsQp5LoTT<@X1eGVV&=nsshxp3~cLd zVNO-A#jK%)l=qi6LprfT($Cq-$y1|*_!W`DUvBCp!#;Zj_2;wvN{Z|l*Sb@tS20q* zR8HqU<$tGLOBBv6ExO~A;c?&DIv6usL>{hL9@8yv#6r@ec-TryWol&|9UP2DaDJAu zq?rQCS*}K(*=%YiA=I^lJ%7RD!yWdaorf7pG%cL%Py=(Z&mDJ^VAW*IbIW9G2QK1_ zuR1m#)7yc0BT!qy8h8;F24Z}u$`t-~%%l}|bn$)h%4dGxYaz8S9*lUi+{uddLEDGR zY;;EYr=f+VWT{uVG~fPwYeY`%a>6LJHpIE)8ez%@&vsQ|n^w4!&T$LL2E=NUZ1nVR ziym#{QvCwR&B|@ zO~z`1AC686*4p`bnUHJr0@o4dmGj)#?Pf4-2&52x=ffgd!aS#98|=k3z*KT%*`zN- zvTUFke~oRHdN2jC;V(MXAa&DJ+=(SUR3NfGpUWERFN+~Hk_PLui#ux40j(Ka-*AXi zH-uARB1W)U7X@09`l7f1zBdCHv$}-3>$$r1E)Qrhl9Vd>v=2(r-6cEDMkUUb@&Z(L z>FarPUE*g@wg`A*EttFL`B4o*u_pAF64a}J?UeG*vnLry1cC>X83SU#?)EKohvP|0 z6J~sl&$6%gnf3WO#+AC2Pb7Hn=h=nAOsx*IgIzC z@taxio`T(E4;y>_s!3;i+#}|qDt~M7X{IangIK>!$IBZ&+mA)HU5Px1xiirhgZ)IT z&YhQfgjqvi^_y$_0I3=<*omZ&P6xv4z%fFa&7*2YHs3<)WK&{(M)7-aaRP65}I)R^iSC8?XC9f#8wCn}5A zS<3Vm&XuybfjF^2q%XTk5FzE=af?doJn{75bVc~psNHpEkU66WAUg2FH+6Qny;mhl zr0qgxnV4{xkac0zI5y~V(%tZtq1rMT(pd3X8%#p<4i(4*#O(FC5e{!C&-Yf@oq($* zICsQ=%T=bX5REVX z*+fvf-%}&EJcsB}+@e*TwDjWxI+08lGS>|wbk^{qLeks9Ur8D?Ga=#!BvmNrwL|ux z6(Q8WZ?Wdpve^+(E^s>S9Xvkb+nt%xVmjxXt^JCMXQ82Pu$uLIic?E0Jn9bjt8=mve(-3OXVMj)+A5VaR#C69;Q-qx%uHsyl^+;bUm8e@+_bL3z@U2 z5z(=9-TXDSE7g+0+;aRYm1-G0;4O!ZN=((@*8Gk?|N4K0U3vST^BP^ z{X?L`@Z>(n3BYayav1+UCX?PbDv8s_jl{yiCB}=XixV~-vcZS1dqbW8FKXl2r%YUW zHQYs(()eeY?%_OwSy;sEl7U9CM_xSLber_35!2?f_Dy>(!ug!;7}f5I$rF`cHi4}K zvX|G2vA^$qN+1pA@wh7wN=V3a`~ZFWr0lEMDFfu0pF)oY()T`r>|qO~G0ka#nZ&&; zFK}nJgIdS_;!=L-SE@MSx?CRhc`#^zUwCGgBl{+J6%GR5+1LZ1E}S+Cqqx64ewjC? zwO(USTb)*P88mQ2ykD8KZ&YocbL^Cr)k`nlu+TLe|3F-SSo(9TMz#$KU=&xrZ=PF| zDb;@Tk{y1aZ`@|!457^IDNN!ZWCb@Wd-1-4X|J4)B^F^#(^a_bS{Sd}m<~ zka_W>nd|4DCx&$zuRmx>SZDeY)(ws4^aF*V9Sb7%+WErdh0Nfbsp*>H@79Hu+aH+E z&mC^1%UItn)Y4M<1r$)Wir6 zErR5J_+ORicM|U=w6VY3#&o@}&QhX9*LhecR{or6t6+8RnKmnrpWgd<29IfE**GaF1J>d7y=U`VZQH*XlwxnKSZFD*c7@;yuW+;2+ z`p5)cXQ}iQW|cRToj-70jrj~+cKfdxJR?$uc5!ZRdt+f5#nIXl>bn_Po zZAx9kSsRh44XMsX1h@`;K{@toP77pE?Ge!va9ctkWQrgw&1Za9xi#Iiq$6*ig5;E& zlzz~U9q97P4$(uxgA+-aZE_Lo0&X2s9T#*PdQ^>=c(~snJVH-GSBLv5Hmx7{p^CbN z@G?uoKU3(;g1kqMxOE7*{&$H>9hb4wT3lDl3PO+r8tZDZnrL@_+qFB4vFs%m_>wjW zcQa_P(q?GOl3BKb7hlXNL@KxEMR$QzO6it54;k)e9wo>6r{DA1HrlyN)x?Jj936xn zuYLM}zu&eNHin7NoqVbF6X?JG;`<)z zr|n^tTB<*4x@?NoVcLBEYST&fJ9eisC6edHDhbzZNRBZgDko}}eA?DW73zn>vzLI7 zEA`%U-?1B$^$zxY%^_5yzBG9Ud&@;GVc!|Fn}ze)Sfq+fXTg(*01Np!K~s^nXx1yS zc>W+@;&%TK+HpNjwxz0Pny+8xTw@7%_!$#?#QTbjSmmvnXvZdgKTKNCqV-;K`cK?P z7eNp<=%Xxe>>1vW{fE?HcdzA3I<@sFV>p#n^`B3$saBWBrmq99g{;Y2d(!-V@S zB?rj8_sa(}tk1HJkezJIri9#4^7EeVuXtPyzXUEC22@@UjpT8%shhrh#z74glsF-3 zgO<|VuaU2&+MGdhQ;HP3=6bMiZOFL96HMUMK1fcBE9%S&Kqpbl&APut6U_2FJ#AFs z%I&XT04cq}$8sD<`Suy@u@y@->2$S+D0Vcbtj{}g>YYsg`di&Ol*{5h3Rjv@FVdH7 zc^hbHN9I!LECWdU#{F5RC%L>J->ckCYZlO>S2nIRF`|1T9Wvv_fLbfP#r))Ejaa>a zA65G~iH|cXFnK~k&AZ`bm7sacCGQ0Q(5lN%aYZgRqJsX)^9cpI2|zAE6c;%~14rC3 zYB!pd30XyxQ@HziFE}M@@3yqWxMbAN-!F3jb=uz)Y%K3N@S$sqcR$Fomd0F_&(6my zuL95T_4&?zJ4F+m!eeTu%*{wNa?GYBFW>qTG4^EOx>R>g+sn*LIbUw2j3bsg0DM+* zydgq*IoS&;n4r$_{p1AZ#ls#YY(v{A3o9Uh%e_xMMhlk8->>r+egL*eU71z98z?JM zMI+(ww0QgFXHAd})s2cl?+>6)>UpCIs6Pgu5Ikf;+2lRs0X?Y8h#h}>FIVk>RrhJ#LUH#*89|>@>0V6%9K=kUp`AEUizEthJfaj zz>vWrx=O!>O`@Nx^YT@Y_vNG7OG7f;6Ct8J)eig%)z?{COLw^5`-63*nE+RRg*qVg z&)BWdd{+9?cJ1*2&J7a>V7p(}A~H-4=&IKFsUo^oqEb(TWD{rme@Xy4m0b8mxF>4+ z5`vFIykye9IHLq{S;xjUx&^9U=O~JMZj-+9CV6L5@`sKbOabqIbffBhwTIA8I ztl;$(i9wEItfiwO&CRPoOCH1xnPsgq&MQs*DQ_HaA1#!Pq&WDlaGEEFCFa0-?A$!J^}&vGDA)Pb-Fpj({oTdTue`w@|Nw3oK@U?pns&t76d-bSPs#S7|qZhBI*j z{0qW(=w(~plk(NNCL-Q15IV9)%PqFs<)9KG@iSsm=!t{I{ObtsJ=9-(`lyaMgZf}| zb%D_&WDlw4Tgl3;toaSy{rXgL=IBUl_fRw2!tR`_L{@GRgRHiWBm$hz7N-4E7Ymll z#izL$`Q3zHb1R$eKcU+!!Z3u$?=tM5_fMGt7_^&I!cVuIXJl~wK3>sBDP;K1vuy5i ziCZ8<+_)^iXq??0~T6PaIcS@5zuB)-sw~{iwdmj z?_$oxziufM|Fq4kvxwz)+}&b)WK-=s&HrCAQV)KgBlI!q1qZ7JeMk(*og_xrzJjSG z<~JCBrd$BRHM1g6zlV2%D*)^%Mk6)9pFqy!M95c#-{;~=e}en|B)9#yUY#>!D%vO4 zqK^Njra1IMx%?kKfd964|7+0vk7EDR!ScW2{@)etf7|Z=$F}n#?@>XtvYcYO4J|Hw;(YiC{l`4Jxb$Zr7}_TaXHjCW{|U}Hy~3i)%2^=!&p7&2 zen;(Ylp5@hc|Ur^?B8Vkn~DGDj;~z*lsFR|$0h4|K#7&ENOt0r}qxZe-RKVn_ zy**+-Va+(sn%D1`dc&H5m*B5zHNHDmg%dJ;>{TU*FxOk2 z_Bu282J_={8ygS)xT;CQYFq)zAvCr{pH3xI-1JV9&LkHhnx!a?_k@*phHk-rbd+QKi z9XB>e;)CM#A-{T_rV$j>-@a7&9n()~Zi?>wR^)?E0`}ag@%76f{q%F-NcO*D)vlfg zLPCt)B4%Enx;L~i7%MhD`f#Z*uiCn%6`(@>HaX#B-hNC7WaEiHO-UW=E1s@@@t6WK zUGFxo_tU3b#6D@JUx~P=49^6_E_l+&h;8d-yGNIc-iH-Fqcy#tcuE?a&*UgMy-KuH zo*wM$Pzo&5M+q$9R9Ec7=i6T^1qJDeI*AB&@6x^m)`uWPRol;hEQ@JB_NrLtBWb|( z@1f`Qyr(PIowDG4K}%fyWWDg#WxbE564T-}lQI#WtnOt^fr2F2jg<|R(PmLJ|57VV z9&g<^tDaQD5uh4RTk3U5xp;4M9wH>c=jm-jCqFo4Dto7ma4wAvbTu)tlAa&br4ZIuC@;(EZS+Wu7&k3~`bIx4CxSsN~ zWns9gmVuQzN~e?ZOW3-1id8nWikIJS_s|9j&K>XbJX11dS`&Fb;eLqiz^D`=!CCWy zkO8-%A6@J6o5pPm;w|NJc-TMnj;Qz3;pu9fwWSujcs);^V6!kNy_OOmt6IWT6xH*- zXxDwK=gwS;Qh8DO>r5M=(DzOJI!oH+(#~PVJ7vU7$Yh0E(S0vPdyl&&`Nb%v!-xdm zx}l2t{sr|Lbz{8$XyZlN%k`q#T~))$69N;p#ZD)AK60Z-xY7`RREN}uXZpSNmjbuL zLI$Wk1x+V*)@ov4+ARS8+FL?3*F=RK&0tD~8mb%zecr6%X zv&;0IWpi94|JFM=0@#KQ|h18 zd%&KV6sJKKh{}0*tmMx<`m4_2Wnf3?d!^-bCvm17`ixtdx5?~`#FqVso|AQ36vcq` zv83O&w#|v>*#3^u-Y-1UOuKFUPF!d6a-fy>B5( + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ports/silabs/supervisor/internal_flash.c b/ports/silabs/supervisor/internal_flash.c new file mode 100644 index 0000000000..c260649c63 --- /dev/null +++ b/ports/silabs/supervisor/internal_flash.c @@ -0,0 +1,138 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/internal_flash.h" + +#include +#include + +#include "extmod/vfs.h" +#include "extmod/vfs_fat.h" +#include "py/mphal.h" +#include "py/obj.h" +#include "py/runtime.h" +#include "lib/oofatfs/ff.h" +#include "supervisor/flash.h" +#include "supervisor/shared/safe_mode.h" + +#include "FreeRTOS.h" +#include "task.h" + +#include "em_core.h" +#include "em_device.h" +#include "em_cmu.h" +#include "em_msc.h" +#include "sl_status.h" + +#define NO_CACHE 0xffffffff +uint8_t _flash_cache[FLASH_PAGE_SIZE] __attribute__((aligned(4))); +uint32_t _flash_page_addr = NO_CACHE; + +STATIC inline uint32_t lba2addr(uint32_t block) { + return CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR + block * FILESYSTEM_BLOCK_SIZE; +} + +void supervisor_flash_init(void) { + // Enable MSC clock if supported + CMU_ClockEnable(cmuClock_MSC, true); +} + +uint32_t supervisor_flash_get_block_size(void) { + return FILESYSTEM_BLOCK_SIZE; +} + +uint32_t supervisor_flash_get_block_count(void) { + return CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_SIZE / FILESYSTEM_BLOCK_SIZE; +} + +void port_internal_flash_flush(void) { + if (_flash_page_addr == NO_CACHE) { + return; + } + + msc_Return_TypeDef ret = mscReturnOk; + + // Skip if data is the same + if (memcmp(_flash_cache, (void *)_flash_page_addr, FLASH_PAGE_SIZE) != 0) { + + MSC_Init(); + taskENTER_CRITICAL(); + ret = MSC_ErasePage((uint32_t *)_flash_page_addr); + taskEXIT_CRITICAL(); + if (mscReturnOk != ret) { + reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); + } + taskENTER_CRITICAL(); + ret = MSC_WriteWord((uint32_t *)_flash_page_addr,_flash_cache,FLASH_PAGE_SIZE); + taskEXIT_CRITICAL(); + if (mscReturnOk != ret) { + reset_into_safe_mode(SAFE_MODE_FLASH_WRITE_FAIL); + } + MSC_Deinit(); + } +} + +mp_uint_t supervisor_flash_read_blocks(uint8_t *dest, uint32_t block, uint32_t num_blocks) { + // Must write out anything in cache before trying to read. + supervisor_flash_flush(); + + uint32_t src = lba2addr(block); + memcpy(dest, (uint8_t *)src, FILESYSTEM_BLOCK_SIZE * num_blocks); + return 0; // success +} + +mp_uint_t supervisor_flash_write_blocks(const uint8_t *src, uint32_t lba, uint32_t num_blocks) { + while (num_blocks) { + uint32_t const addr = lba2addr(lba); + uint32_t const page_addr = addr & ~(FLASH_PAGE_SIZE - 1); + + // Up to page boundary + uint32_t count = 8 - (lba % 8); + count = MIN(num_blocks, count); + + if (page_addr != _flash_page_addr) { + // Write out anything in cache before overwriting it.*/ + supervisor_flash_flush(); + + _flash_page_addr = page_addr; + + // Copy the current contents of the entire page into the cache. + memcpy(_flash_cache, (void *)page_addr, FLASH_PAGE_SIZE); + } + + // Overwrite part or all of the page cache with the src data. + memcpy(_flash_cache + (addr & (FLASH_PAGE_SIZE - 1)), src, count * FILESYSTEM_BLOCK_SIZE); + + // adjust for next run + lba += count; + src += count * FILESYSTEM_BLOCK_SIZE; + num_blocks -= count; + } + return 0; // success +} + +void supervisor_flash_release_cache(void) { +} diff --git a/ports/silabs/supervisor/internal_flash.h b/ports/silabs/supervisor/internal_flash.h new file mode 100644 index 0000000000..898376e9d6 --- /dev/null +++ b/ports/silabs/supervisor/internal_flash.h @@ -0,0 +1,38 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR32_INTERNAL_FLASH_H +#define MICROPY_INCLUDED_EFR32_INTERNAL_FLASH_H + +#include +#include + +#include "py/mpconfig.h" + +#define INTERNAL_FLASH_SYSTICK_MASK (0x1ff) // 512ms +#define INTERNAL_FLASH_IDLE_TICK(tick) (((tick) & INTERNAL_FLASH_SYSTICK_MASK) == 2) + +#endif // MICROPY_INCLUDED_EFR32_INTERNAL_FLASH_H diff --git a/ports/silabs/supervisor/internal_flash_root_pointers.h b/ports/silabs/supervisor/internal_flash_root_pointers.h new file mode 100644 index 0000000000..16694d5dac --- /dev/null +++ b/ports/silabs/supervisor/internal_flash_root_pointers.h @@ -0,0 +1,32 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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_EFR32_INTERNAL_FLASH_ROOT_POINTERS_H +#define MICROPY_INCLUDED_EFR32_INTERNAL_FLASH_ROOT_POINTERS_H + +#define FLASH_ROOT_POINTERS + +#endif // MICROPY_INCLUDED_EFR32_INTERNAL_FLASH_ROOT_POINTERS_H diff --git a/ports/silabs/supervisor/port.c b/ports/silabs/supervisor/port.c new file mode 100644 index 0000000000..b5deebf979 --- /dev/null +++ b/ports/silabs/supervisor/port.c @@ -0,0 +1,336 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/background_callback.h" +#include "supervisor/board.h" +#include "supervisor/port.h" +#include "shared/timeutils/timeutils.h" + +#include "common-hal/microcontroller/Pin.h" +#include "shared-bindings/microcontroller/__init__.h" + +#if CIRCUITPY_AUDIOPWMIO +#include "common-hal/audiopwmio/PWMAudioOut.h" +#endif +#if CIRCUITPY_BUSIO +#include "common-hal/busio/I2C.h" +#include "common-hal/busio/SPI.h" +#include "common-hal/busio/UART.h" +#endif +#if CIRCUITPY_PULSEIO +#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 "peripherals/timers.h" +#endif +#if CIRCUITPY_SDIOIO +#include "common-hal/sdioio/SDCard.h" +#endif +#if CIRCUITPY_PULSEIO || CIRCUITPY_ALARM +#include "peripherals/exti.h" +#endif +#if CIRCUITPY_ALARM +#include "common-hal/alarm/__init__.h" +#endif +#if CIRCUITPY_RTC +#include "shared-bindings/rtc/__init__.h" +#endif +#if CIRCUITPY_ANALOGIO +#include "common-hal/analogio/AnalogOut.h" +#endif + +#if CIRCUITPY_BLEIO +#include "common-hal/_bleio/__init__.h" +#endif + +// Include headers of EFR32 +#include +#include "em_chip.h" +#include "sl_cmsis_os2_common.h" +#include "sl_component_catalog.h" +#include "sl_sleeptimer.h" +#include "sl_system_init.h" +#include "sl_system_kernel.h" + +#if defined(SL_CATALOG_POWER_MANAGER_PRESENT) +#include "sl_power_manager.h" +#endif // SL_CATALOG_POWER_MANAGER_PRESENT + +#if !defined(SL_CATALOG_KERNEL_PRESENT) +#error "Error: Requires SL_CATALOG_KERNEL_PRESENT definition" +#endif + +#define SL_CIRCUITPYTHON_TASK_STACK_EXTRA_SIZE (32) +#define SL_CIRCUITPYTHON_TASK_PRIORITY (40) +#define HEAP_SIZE (88 * 1024) + +extern uint32_t __bss_start__; +extern uint32_t __bss_end__; + +uint32_t _sbss; +uint32_t _ebss; + +uint32_t *heap; +uint32_t heap_size; + +STATIC sl_sleeptimer_timer_handle_t _tick_timer; +STATIC sl_sleeptimer_timer_handle_t _sleep_timer; + +// CircuitPython stack thread +STATIC void circuitpython_thread(void *p_arg); +STATIC osThreadId_t tid_thread_circuitpython; +__ALIGNED(8) +STATIC uint8_t thread_circuitpython_stk[(CIRCUITPY_DEFAULT_STACK_SIZE + + SL_CIRCUITPYTHON_TASK_STACK_EXTRA_SIZE) & + 0xFFFFFFF8u]; +__ALIGNED(4) +STATIC uint8_t thread_circuitpython_cb[osThreadCbSize]; + +STATIC const osThreadAttr_t thread_circuitpython_attr = { + .name = "CircuitPython stack", + .stack_mem = thread_circuitpython_stk, + .stack_size = sizeof(thread_circuitpython_stk), + .cb_mem = thread_circuitpython_cb, + .cb_size = osThreadCbSize, + .priority = (osPriority_t)SL_CIRCUITPYTHON_TASK_PRIORITY +}; + +STATIC bool isSchedulerStarted = false; + +safe_mode_t port_init(void) { + #if defined(SL_CATALOG_KERNEL_PRESENT) + + if (!isSchedulerStarted) { + _sbss = __bss_start__; + _ebss = __bss_end__; + + isSchedulerStarted = true; + // Initialize Silicon Labs device, system, service(s) and protocol stack(s). + // Note that if the kernel is present, processing task(s) will be created by + // this call. + sl_system_init(); + // Create thread for Bluetooth stack + if (tid_thread_circuitpython == NULL) { + tid_thread_circuitpython = osThreadNew(circuitpython_thread, + NULL, + &thread_circuitpython_attr); + } + + // Create mutex for Bluetooth handle + if (bluetooth_connection_mutex_id == NULL) { + bluetooth_connection_mutex_id = osMutexNew(&bluetooth_connection_mutex_attr); + } + + if (tid_thread_circuitpython == NULL) { + for (;;) { + } + } + // Start the kernel. Task(s) created in app_init() will start running. + sl_system_kernel_start(); + } + + #endif // SL_CATALOG_KERNEL_PRESENT + + if (heap == NULL) { + heap = malloc(HEAP_SIZE); + heap_size = HEAP_SIZE / sizeof(uint32_t); + } + if (heap == NULL) { + return SAFE_MODE_NO_HEAP; + } + return SAFE_MODE_NONE; +} + +void reset_port(void) { + reset_all_pins(); + + #if CIRCUITPY_BUSIO + i2c_reset(); + spi_reset(); + uart_reset(); + #endif + + #if CIRCUITPY_PWMIO + pwmout_reset(); + #endif + + #if CIRCUITPY_ANALOGIO + analogout_reset(); + #endif + + #if CIRCUITPY_BLEIO + bleio_reset(); + #endif +} + +void reset_to_bootloader(void) { + CHIP_Reset(); + for (;;) { + } +} + +void reset_cpu(void) { + CHIP_Reset(); + for (;;) { + } +} + +uint32_t *port_heap_get_bottom(void) { + return heap; +} + +uint32_t *port_heap_get_top(void) { + return heap + heap_size; +} + +bool port_has_fixed_stack(void) { + return true; +} + +uint32_t *port_stack_get_limit(void) { + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wcast-align" + return (uint32_t *)thread_circuitpython_stk; + #pragma GCC diagnostic pop +} + +uint32_t *port_stack_get_top(void) { + return port_stack_get_limit() + CIRCUITPY_DEFAULT_STACK_SIZE / sizeof(uint32_t); +} + +uint64_t port_get_raw_ticks(uint8_t *subticks) { + uint32_t timer_freq = sl_sleeptimer_get_timer_frequency(); + uint64_t all_subticks = (uint64_t)(sl_sleeptimer_get_tick_count()) * 1024; + if (subticks != NULL) { + *subticks = all_subticks % timer_freq; + } + return all_subticks / timer_freq; +} + +// Periodic tick timer callback +STATIC void on_tick_timer_timeout(sl_sleeptimer_timer_handle_t *handle, + void *data) { + (void)&handle; + (void)&data; + supervisor_tick(); + + // CircuitPython's VM is run in a separate FreeRTOS task from timer callbacks. + // So, we have to notify the main task every time in case it's waiting for us. + osThreadFlagsSet(tid_thread_circuitpython, 0x0001); +} + +// Enable 1/1024 second tick. +void port_enable_tick(void) { + uint32_t timer_freq = sl_sleeptimer_get_timer_frequency(); + + // Create timer for waking up the system periodically. + sl_sleeptimer_start_periodic_timer(&_tick_timer, + timer_freq / 1024, + on_tick_timer_timeout, NULL, + 0, + SL_SLEEPTIMER_NO_HIGH_PRECISION_HF_CLOCKS_REQUIRED_FLAG); +} + +// Disable 1/1024 second tick. +void port_disable_tick(void) { + sl_sleeptimer_stop_timer(&_tick_timer); +} + +void port_wake_main_task(void) { + osThreadFlagsSet(tid_thread_circuitpython, 0x0001); +} + +STATIC void on_sleep_timer_timeout(sl_sleeptimer_timer_handle_t *handle, + void *data) { + port_wake_main_task(); +} + +void port_interrupt_after_ticks(uint32_t ticks) { + uint32_t timer_freq = sl_sleeptimer_get_timer_frequency(); + + uint32_t timer_tick = (uint32_t)((((uint64_t)ticks * timer_freq) + 1023) / 1024u); + + // Create one-shot timer for waking up the system. + sl_sleeptimer_start_timer(&_sleep_timer, + timer_tick, + on_sleep_timer_timeout, NULL, + 0, + SL_SLEEPTIMER_NO_HIGH_PRECISION_HF_CLOCKS_REQUIRED_FLAG); +} + +void port_idle_until_interrupt(void) { + if (!background_callback_pending()) { + osThreadFlagsWait(0x0001, osFlagsWaitAny, osWaitForever); + } + +} + +// Place the word to save just after our BSS section that gets blanked. +void port_set_saved_word(uint32_t value) { + __bss_end__ = value; +} + +uint32_t port_get_saved_word(void) { + return __bss_end__; +} + +#if CIRCUITPY_ALARM +// Board deinit in case boards/xxx/board.c does not provide board_deinit() +MP_WEAK void board_deinit(void) { +} +#endif + +extern void main(void); + +void circuitpython_thread(void *p_arg) { + (void)p_arg; + main(); +} + +__attribute__((used)) void BusFault_Handler(void) { + reset_into_safe_mode(SAFE_MODE_HARD_FAULT); + while (true) { + asm ("nop;"); + } +} + +__attribute__((used)) void UsageFault_Handler(void) { + reset_into_safe_mode(SAFE_MODE_HARD_FAULT); + while (true) { + asm ("nop;"); + } +} + +__attribute__((used)) void HardFault_Handler(void) { + reset_into_safe_mode(SAFE_MODE_HARD_FAULT); + while (true) { + asm ("nop;"); + } +} diff --git a/ports/silabs/supervisor/serial.c b/ports/silabs/supervisor/serial.c new file mode 100644 index 0000000000..01aaa49835 --- /dev/null +++ b/ports/silabs/supervisor/serial.c @@ -0,0 +1,156 @@ +/* + * This file is part of Adafruit for EFR32 project + * + * The MIT License (MIT) + * + * Copyright 2023 Silicon Laboratories Inc. www.silabs.com + * + * 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/mphal.h" +#include "py/ringbuf.h" +#include "supervisor/port.h" +#include "supervisor/serial.h" +#include "shared/readline/readline.h" +#include "shared/runtime/interrupt_char.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "py/runtime.h" + +#include "em_cmu.h" +#include "em_core.h" +#include "em_gpio.h" +#include "em_eusart.h" +#include "em_gpio.h" +#include "em_cmu.h" + +#define CONSOLE_RCV_BUFFER_SIZE 4096 + +#define EUSART_VCOM_TX_PORT gpioPortA +#define EUSART_VCOM_TX_PIN 5 + +#define EUSART_VCOM_RX_PORT gpioPortA +#define EUSART_VCOM_RX_PIN 6 + +STATIC ringbuf_t con_uart_rx_ringbuf; +STATIC byte con_uart_rx_buf[CONSOLE_RCV_BUFFER_SIZE]; +STATIC volatile uint8_t received_data; + +// USART0 RX interrupt handler , put characters to ring buffer one by one +void EUSART0_RX_IRQHandler(void) { + CORE_DECLARE_IRQ_STATE; + CORE_ENTER_ATOMIC(); + + received_data = EUSART0->RXDATA; + if (1 != ringbuf_put_n(&con_uart_rx_ringbuf, (uint8_t *)&received_data, 1)) { + mp_raise_OverflowError_varg(translate("Console UART RX buffer overflow")); + } + + CORE_EXIT_ATOMIC(); + port_wake_main_task(); + + if (received_data == CHAR_CTRL_C && + mp_interrupt_char == CHAR_CTRL_C) { + ringbuf_clear(&con_uart_rx_ringbuf); + mp_sched_keyboard_interrupt(); + } + EUSART_IntClear(EUSART0, EUSART_IF_RXFL); +} + +// Configure EUSART0 for REPL +void port_serial_early_init(void) { + + // Enable clock to GPIO and EUSART1 + CMU_ClockEnable(cmuClock_GPIO, true); + CMU_ClockEnable(cmuClock_EUSART0, true); + + // Configure the EUSART TX pin to the board controller as an output + GPIO_PinModeSet(EUSART_VCOM_TX_PORT, EUSART_VCOM_TX_PIN, gpioModePushPull, 0); + + // Configure the EUSART RX pin to the board controller as an input + GPIO_PinModeSet(EUSART_VCOM_RX_PORT, EUSART_VCOM_RX_PIN, gpioModeInput, 0); + + // Route EUSART0 TX and RX to the board controller TX and RX pins + GPIO->EUSARTROUTE[0].TXROUTE = (EUSART_VCOM_TX_PORT << _GPIO_EUSART_TXROUTE_PORT_SHIFT) + | (EUSART_VCOM_TX_PIN << _GPIO_EUSART_TXROUTE_PIN_SHIFT); + GPIO->EUSARTROUTE[0].RXROUTE = (EUSART_VCOM_RX_PORT << _GPIO_EUSART_RXROUTE_PORT_SHIFT) + | (EUSART_VCOM_RX_PIN << _GPIO_EUSART_RXROUTE_PIN_SHIFT); + + // Enable RX and TX signals now that they have been routed + GPIO->EUSARTROUTE[0].ROUTEEN = GPIO_EUSART_ROUTEEN_RXPEN | GPIO_EUSART_ROUTEEN_TXPEN; + + // Default asynchronous initializer (115.2 Kbps, 8N1, no flow control) + EUSART_UartInit_TypeDef init = EUSART_UART_INIT_DEFAULT_HF; + + // Configure and enable EUSART0 for high-frequency (EM0/1) operation + EUSART_UartInitHf(EUSART0, &init); + + + // Claim and never reset UART console pin + common_hal_mcu_pin_claim(&pin_PA5); + common_hal_mcu_pin_claim(&pin_PA6); + common_hal_never_reset_pin(&pin_PA5); + common_hal_never_reset_pin(&pin_PA6); +} + +// Enable EUSART0 interrupt, init ring buffer +void port_serial_init(void) { + ringbuf_init(&con_uart_rx_ringbuf, + con_uart_rx_buf, + CONSOLE_RCV_BUFFER_SIZE); + + received_data = 0; + // Enable NVIC USART sources + NVIC_ClearPendingIRQ(EUSART0_RX_IRQn); + NVIC_EnableIRQ(EUSART0_RX_IRQn); + NVIC_SetPriority(EUSART0_RX_IRQn, 3); + EUSART_IntEnable(EUSART0, EUSART_IEN_RXFL); +} + +bool port_serial_connected(void) { + return true; +} + +// Get a characters from ring buffer +char port_serial_read(void) { + int data; + + CORE_DECLARE_IRQ_STATE; + CORE_ENTER_ATOMIC(); + + data = ringbuf_get(&con_uart_rx_ringbuf); + + CORE_EXIT_ATOMIC(); + + return (char)data; +} + +// Checking ring buffer haves bytes available or not +bool port_serial_bytes_available(void) { + return ringbuf_num_filled(&con_uart_rx_ringbuf) > 0 ? true : false; +} + +// Send n bytes data to serial by EUSART0 +void port_serial_write_substring(const char *text, uint32_t len) { + char *p_text = (char *)text; + while (len--) { + EUSART_Tx(EUSART0, *p_text); + p_text++; + } +} diff --git a/ports/silabs/tools/make_pins.py b/ports/silabs/tools/make_pins.py new file mode 100644 index 0000000000..bd4973d3e0 --- /dev/null +++ b/ports/silabs/tools/make_pins.py @@ -0,0 +1,216 @@ +import csv +import argparse +import string + + +def parse_pins(filename): + """Parse CSV file given in filename. + The CSV file should have the following columns: + mcu_name, board_name, port (integer), pin (integer) + The CSV file should also have a header row""" + pins = {} + with open(filename, newline="") as csv_file: + reader = csv.reader(csv_file) + reader.__next__() + for row in reader: + entry = (row[0].strip(), row[1].strip(), int(row[2].strip()), int(row[3].strip())) + pins[row[0].lower()] = entry + return pins + + +def parse_pin_functions(filename): + """Parse a CSV file with peripheral pin mappings. + The CSV file should have the following columns + func_name, LOC0,LOC1,...,LOC31 + There should not be any header row""" + functions = {} + with open(filename, newline="") as csv_file: + reader = csv.reader(csv_file) + for row in reader: + entry = row[1:] + functions[row[0].strip()] = entry + return functions + + +def make_pin_name(pin): + """Create pin name""" + return "pin_" + pin[0] + + +def make_mcu_dict_entry(pin): + """Create a pin mcu dictionary entry""" + entry = "{ MP_ROM_QSTR(MP_QSTR_" + pin[0] + "), MP_ROM_PTR(&" + make_pin_name(pin) + ") }," + return entry + + +def make_mcu_dict_entry2(pin): + """Create a pin mcu dictionary entry""" + entry = ( + "{ MP_ROM_QSTR(MP_QSTR_" + pin[1] + "), \t\t\tMP_ROM_PTR(&" + make_pin_name(pin) + ") }," + ) + return entry + + +def make_mcu_dict(pins): + """Create the mcu dictionary""" + decl = "\n\nSTATIC const mp_rom_map_elem_t board_module_globals_table[] = {\n" + decl += "\tCIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS\n" + for pin in pins.values(): + decl += "\t" + make_mcu_dict_entry(pin) + "\n" + + decl += "\n" + for pin in pins.values(): + if pin[1] != "": + decl += "\t" + make_mcu_dict_entry2(pin) + "\n" + + decl += "\t{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },\n" + decl += "\t{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },\n" + decl += "};\n" + decl += "MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);\n" + return decl + + +def make_board_dict_entry(pin): + """Create a pin board dictionary entry""" + entry = "{ MP_OBJ_NEW_QSTR(MP_QSTR_" + pin[1] + "), (mp_obj_t)&" + make_pin_name(pin) + " }," + return entry + + +def make_pin_function_list_decl(pin, fcns): + """Create a pin function list declaration""" + decl = "\nconst uint8_t pin_" + pin + "_functions[] = { \n" + if len(fcns) > 0: + decl += str(fcns[0]) + for i in fcns[1:]: + decl += ", " + str(i) + decl += "\n};\n" + return decl + + +def make_pin_declaration(pin): + """Create a pin declaration""" + decl = ( + "\nconst mcu_pin_obj_t " + + make_pin_name(pin) + + " = PIN(" + + str(pin[2]) + + "," + + str(pin[3]) + + "," + + make_pin_name(pin).lower() + + "_functions" + ");" + ) + return decl + + +def define_pin_exists(pin): + ret = "\n#define GPIO_" + pin[0] + "_EXISTS\t1" + return ret + + +def make_pin_function_lists(functions, pins): + """Create lists of pin functions from the parsed CSV data""" + fcn_list = {} + decl = "" + i = 0 + for fcn, fcn_pins in sorted(functions.items()): + for j in range(0, len(fcn_pins)): + pin = fcn_pins[j].lower() + if pin == "": + continue + if pin not in fcn_list: + fcn_list[pin] = [255] * len(functions) + fcn_list[pin][i] = 1 + i += 1 + for pin in pins.keys(): + if not pin in fcn_list: + fcn_list[pin] = [] + + decl += make_pin_function_list_decl(pin, fcn_list[pin]) + + return decl + + +def make_source_file(src_file, pins, fcn): + """Make pins.c""" + with open(src_file, "w") as f: + f.write('#include "shared-bindings/board/__init__.h"\n') + f.write('#include "pin_functions.h"\n') + + f.write(make_pin_function_lists(fcn, pins)) + + for pin in pins.values(): + f.write(make_pin_declaration(pin)) + f.write(make_mcu_dict(pins)) + f.close() + return + + +def make_header_file(hdr_file, pins, fcns): + """Make pins.h""" + hdr_file_name = hdr_file.split("/")[-1] + guard_name = "__" + hdr_file_name.replace(".", "_").upper() + "__" + with open(hdr_file, "w") as f: + f.write("#ifndef " + guard_name + "\n") + f.write("#define " + guard_name + "\n\n") + + fcn_names = sorted(fcns.keys()) + for i in range(len(fcn_names)): + f.write("#define " + "FN_" + fcn_names[i] + "\t\t\t(" + str(i) + ")\n") + + for pin in pins.values(): + f.write(define_pin_exists(pin)) + + f.write("\n\n") + f.write("\n\n#endif /*" + guard_name + "*/\n") + f.close() + + return + + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + prog="make_pins", + usage="%(prog)s [options]", + description="Parse a CSV file with pin data and store as corresponding C source and header files.", + ) + parser.add_argument( + "-s", + "--source_file", + dest="source_file", + action="store", + help="Name of the output source file", + default="pins.c", + ) + parser.add_argument( + "-e", + "--header_file", + dest="header_file", + action="store", + help="Name of the output header file", + default="pin_functions.h", + ) + + parser.add_argument( + "csv_file", + action="store", + help="Name of the input csv file", + ) + parser.add_argument( + "fcn_csv", + action="store", + help="Name of the csv file with pin functions", + ) + args = parser.parse_args() + + src_file = args.source_file + hdr_file = args.header_file + + csv_file = args.csv_file + fcn_csv = args.fcn_csv + + pins = parse_pins(csv_file) + fcns = parse_pin_functions(fcn_csv) + make_source_file(src_file, pins, fcns) + make_header_file(hdr_file, pins, fcns) diff --git a/ports/silabs/tools/slc_cli_linux b/ports/silabs/tools/slc_cli_linux new file mode 160000 index 0000000000..a2cef44346 --- /dev/null +++ b/ports/silabs/tools/slc_cli_linux @@ -0,0 +1 @@ +Subproject commit a2cef4434600379695bef23bfbdcc8e604f7f305 diff --git a/requirements-dev.txt b/requirements-dev.txt index 5e8fe3d3f6..5efa084652 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -30,3 +30,7 @@ cryptography # for web workflow minify minify_html jsmin + +# for Silicon Labs Configurator (SLC) +websockets +colorama diff --git a/tools/ci_fetch_deps.py b/tools/ci_fetch_deps.py index 1b292b9d73..b77bea72f9 100644 --- a/tools/ci_fetch_deps.py +++ b/tools/ci_fetch_deps.py @@ -43,6 +43,7 @@ PORT_DEPS = { "lib/tinyusb/", "data/nvm.toml/", ], + "silabs": ["extmod/ulab/", "data/nvm.toml/"], "stm": ["extmod/ulab/", "lib/mp3/", "lib/protomatter/", "lib/tinyusb/", "data/nvm.toml/"] # omit unix which is part of the "test" target below } From 75670829652aaf1794c27f6b0bbad5937fecd9f0 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 18 Apr 2023 15:52:06 -0400 Subject: [PATCH 035/117] Add Adafruit Feather RP2040 Prop-Maker --- .../board.c | 29 ++++++++++ .../mpconfigboard.h | 14 +++++ .../mpconfigboard.mk | 9 +++ .../pico-sdk-configboard.h | 4 ++ .../adafruit_feather_rp2040_prop_maker/pins.c | 57 +++++++++++++++++++ 5 files changed, 113 insertions(+) create mode 100644 ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/board.c create mode 100644 ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/mpconfigboard.h create mode 100644 ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/mpconfigboard.mk create mode 100644 ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/pico-sdk-configboard.h create mode 100644 ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/pins.c diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/board.c b/ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/board.c new file mode 100644 index 0000000000..331653173e --- /dev/null +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/board.c @@ -0,0 +1,29 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/mpconfigboard.h b/ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/mpconfigboard.h new file mode 100644 index 0000000000..c9e83756e3 --- /dev/null +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/mpconfigboard.h @@ -0,0 +1,14 @@ +#define MICROPY_HW_BOARD_NAME "Adafruit Feather RP2040 Prop-Maker" +#define MICROPY_HW_MCU_NAME "rp2040" + +#define MICROPY_HW_NEOPIXEL (&pin_GPIO4) + +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO3) +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO2) + +#define DEFAULT_SPI_BUS_SCK (&pin_GPIO14) +#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO15) +#define DEFAULT_SPI_BUS_MISO (&pin_GPIO8) + +#define DEFAULT_UART_BUS_RX (&pin_GPIO1) +#define DEFAULT_UART_BUS_TX (&pin_GPIO0) diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/mpconfigboard.mk b/ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/mpconfigboard.mk new file mode 100644 index 0000000000..06d0c5e2b8 --- /dev/null +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/mpconfigboard.mk @@ -0,0 +1,9 @@ +USB_VID = 0x239A +USB_PID = 0x8132 +USB_PRODUCT = "Feather RP2040 Prop-Maker" +USB_MANUFACTURER = "Adafruit" + +CHIP_VARIANT = RP2040 +CHIP_FAMILY = rp2 + +EXTERNAL_FLASH_DEVICES = "GD25Q64C,W25Q64JVxQ" diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/pico-sdk-configboard.h b/ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/pico-sdk-configboard.h new file mode 100644 index 0000000000..a41131dd22 --- /dev/null +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/pico-sdk-configboard.h @@ -0,0 +1,4 @@ +// Put board-specific pico-sdk definitions here. This file must exist. + +// Allow extra time for xosc to start. +#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64 diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/pins.c b/ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/pins.c new file mode 100644 index 0000000000..96e0bc71df --- /dev/null +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/pins.c @@ -0,0 +1,57 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) }, + { MP_ROM_QSTR(MP_QSTR_D24), MP_ROM_PTR(&pin_GPIO24) }, + { MP_ROM_QSTR(MP_QSTR_D25), MP_ROM_PTR(&pin_GPIO25) }, + + { MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO12) }, + + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO1) }, + + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO0) }, + + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO8) }, + + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO3) }, + + { MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_GPIO7) }, + + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO13) }, + + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO4) }, + + { MP_ROM_QSTR(MP_QSTR_I2S_DATA), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_I2S_BIT_CLOCK), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_WORD_SELECT), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_EXTERNAL_BUTTON), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_SERVO), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_EXTERNAL_NEOPIXELS), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_ACCELEROMETER_INTERRUPT), MP_ROM_PTR(&pin_GPIO22) }, + { MP_ROM_QSTR(MP_QSTR_EXTERNAL_NEOPIXELS_POWER), MP_ROM_PTR(&pin_GPIO23) }, + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_STEMMA_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_module_globals_table); From 403ea89d5799a37d4cda08071d5bf2e5bc86a383 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Tue, 18 Apr 2023 19:44:03 -0500 Subject: [PATCH 036/117] Initial paletts for OnDiskGif --- shared-bindings/gifio/OnDiskGif.c | 28 ++++++- shared-bindings/gifio/OnDiskGif.h | 3 +- shared-module/gifio/OnDiskGif.c | 121 +++++++++++++++++++++--------- shared-module/gifio/OnDiskGif.h | 8 +- 4 files changed, 118 insertions(+), 42 deletions(-) diff --git a/shared-bindings/gifio/OnDiskGif.c b/shared-bindings/gifio/OnDiskGif.c index f6acccfabf..cfed55d0c8 100644 --- a/shared-bindings/gifio/OnDiskGif.c +++ b/shared-bindings/gifio/OnDiskGif.c @@ -117,9 +117,16 @@ //| """ //| ... STATIC mp_obj_t gifio_ondiskgif_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - mp_arg_check_num(n_args, n_kw, 1, 1, false); - mp_obj_t arg = all_args[0]; + enum { ARG_filename, ARG_use_palette, NUM_ARGS }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_filename, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_use_palette, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, + }; + MP_STATIC_ASSERT(MP_ARRAY_SIZE(allowed_args) == NUM_ARGS); + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_obj_t arg = all_args[0]; if (mp_obj_is_str(arg)) { arg = mp_call_function_2(MP_OBJ_FROM_PTR(&mp_builtin_open_obj), arg, MP_ROM_QSTR(MP_QSTR_rb)); } @@ -130,7 +137,7 @@ STATIC mp_obj_t gifio_ondiskgif_make_new(const mp_obj_type_t *type, size_t n_arg gifio_ondiskgif_t *self = m_new_obj(gifio_ondiskgif_t); self->base.type = &gifio_ondiskgif_type; - common_hal_gifio_ondiskgif_construct(self, MP_OBJ_TO_PTR(arg)); + common_hal_gifio_ondiskgif_construct(self, MP_OBJ_TO_PTR(arg), args[ARG_use_palette].u_bool); return MP_OBJ_FROM_PTR(self); } @@ -199,6 +206,20 @@ MP_DEFINE_CONST_FUN_OBJ_1(gifio_ondiskgif_get_bitmap_obj, gifio_ondiskgif_obj_ge MP_PROPERTY_GETTER(gifio_ondiskgif_bitmap_obj, (mp_obj_t)&gifio_ondiskgif_get_bitmap_obj); +//| palette: displayio.Palette +//| """The palette for the current frame.""" +STATIC mp_obj_t gifio_ondiskgif_obj_get_palette(mp_obj_t self_in) { + gifio_ondiskgif_t *self = MP_OBJ_TO_PTR(self_in); + + check_for_deinit(self); + return common_hal_gifio_ondiskgif_get_palette(self); +} + +MP_DEFINE_CONST_FUN_OBJ_1(gifio_ondiskgif_get_palette_obj, gifio_ondiskgif_obj_get_palette); + +MP_PROPERTY_GETTER(gifio_ondiskgif_palette_obj, + (mp_obj_t)&gifio_ondiskgif_get_palette_obj); + //| def next_frame(self) -> float: //| """Loads the next frame. Returns expected delay before the next frame in seconds.""" STATIC mp_obj_t gifio_ondiskgif_obj_next_frame(mp_obj_t self_in) { @@ -285,6 +306,7 @@ STATIC const mp_rom_map_elem_t gifio_ondiskgif_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&gifio_ondiskgif___exit___obj) }, { MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&gifio_ondiskgif_height_obj) }, { MP_ROM_QSTR(MP_QSTR_bitmap), MP_ROM_PTR(&gifio_ondiskgif_bitmap_obj) }, + { MP_ROM_QSTR(MP_QSTR_palette), MP_ROM_PTR(&gifio_ondiskgif_palette_obj) }, { MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&gifio_ondiskgif_width_obj) }, { MP_ROM_QSTR(MP_QSTR_next_frame), MP_ROM_PTR(&gifio_ondiskgif_next_frame_obj) }, { MP_ROM_QSTR(MP_QSTR_duration), MP_ROM_PTR(&gifio_ondiskgif_duration_obj) }, diff --git a/shared-bindings/gifio/OnDiskGif.h b/shared-bindings/gifio/OnDiskGif.h index 6776466e8d..deaa639685 100644 --- a/shared-bindings/gifio/OnDiskGif.h +++ b/shared-bindings/gifio/OnDiskGif.h @@ -32,13 +32,14 @@ extern const mp_obj_type_t gifio_ondiskgif_type; -void common_hal_gifio_ondiskgif_construct(gifio_ondiskgif_t *self, pyb_file_obj_t *file); +void common_hal_gifio_ondiskgif_construct(gifio_ondiskgif_t *self, pyb_file_obj_t *file, bool use_palette); uint32_t common_hal_gifio_ondiskgif_get_pixel(gifio_ondiskgif_t *bitmap, int16_t x, int16_t y); uint16_t common_hal_gifio_ondiskgif_get_height(gifio_ondiskgif_t *self); mp_obj_t common_hal_gifio_ondiskgif_get_bitmap(gifio_ondiskgif_t *self); +mp_obj_t common_hal_gifio_ondiskgif_get_palette(gifio_ondiskgif_t *self); uint16_t common_hal_gifio_ondiskgif_get_width(gifio_ondiskgif_t *self); uint32_t common_hal_gifio_ondiskgif_next_frame(gifio_ondiskgif_t *self, bool setDirty); int32_t common_hal_gifio_ondiskgif_get_duration(gifio_ondiskgif_t *self); diff --git a/shared-module/gifio/OnDiskGif.c b/shared-module/gifio/OnDiskGif.c index aeb4f7bb74..f6adfa0775 100644 --- a/shared-module/gifio/OnDiskGif.c +++ b/shared-module/gifio/OnDiskGif.c @@ -26,6 +26,7 @@ #include "shared-bindings/gifio/OnDiskGif.h" #include "shared-bindings/displayio/Bitmap.h" +#include "shared-bindings/displayio/Palette.h" #include @@ -34,7 +35,6 @@ static int32_t GIFReadFile(GIFFILE *pFile, uint8_t *pBuf, int32_t iLen) { - // mp_printf(&mp_plat_print, "GifReadFile len %d ", iLen); uint32_t iBytesRead; iBytesRead = iLen; pyb_file_obj_t *f = pFile->fHandle; @@ -50,18 +50,15 @@ static int32_t GIFReadFile(GIFFILE *pFile, uint8_t *pBuf, int32_t iLen) { mp_raise_OSError(MP_EIO); } pFile->iPos = f->fp.fptr; - // mp_printf(&mp_plat_print, " now at %d\n", pFile->iPos); return bytes_read; } /* GIFReadFile() */ static int32_t GIFSeekFile(GIFFILE *pFile, int32_t iPosition) { - // mp_printf(&mp_plat_print, "GifSeekFile %d ", iPosition); pyb_file_obj_t *f = pFile->fHandle; f_lseek(&f->fp, iPosition); pFile->iPos = f->fp.fptr; - // mp_printf(&mp_plat_print, " now at %d\n", pFile->iPos); return pFile->iPos; } /* GIFSeekFile() */ @@ -71,10 +68,25 @@ static void GIFDraw(GIFDRAW *pDraw) { // The palette is either RGB565 or the original 24-bit RGB values // depending on the pixel type selected with gif.begin() - displayio_bitmap_t *bitmap = (displayio_bitmap_t *)pDraw->pUser; + gifio_ondiskgif_displayio_objs_t *displayio_objs = (gifio_ondiskgif_displayio_objs_t *)pDraw->pUser; + displayio_bitmap_t *bitmap = displayio_objs->bitmap; + displayio_palette_t *palette = displayio_objs->palette; - uint8_t *s; - uint16_t *d; + // Update the palette if we have one in RGB888 + if (palette != NULL) { + uint8_t *pPal = pDraw->pPalette24; + for (int p = 0; p < 256; p++) { + uint8_t r = *pPal++; + uint8_t g = *pPal++; + uint8_t b = *pPal++; + uint32_t color = (r << 16) + (g << 8) + b; + common_hal_displayio_palette_set_color(palette, p, color); + common_hal_displayio_palette_make_opaque(palette, p); // Transparency can change frame to frame + } + if (pDraw->ucHasTransparency) { + common_hal_displayio_palette_make_transparent(palette, pDraw->ucTransparent); + } + } int iWidth = pDraw->iWidth; if (iWidth + pDraw->iX > bitmap->width) { @@ -87,11 +99,6 @@ static void GIFDraw(GIFDRAW *pDraw) { int32_t row_start = (pDraw->y + pDraw->iY) * bitmap->stride; uint32_t *row = bitmap->data + row_start; - s = pDraw->pPixels; - d = (uint16_t *)row; - - uint16_t *pPal; - pPal = (uint16_t *)pDraw->pPalette; if (pDraw->ucDisposalMethod == 2) { // restore to background color // Not supported currently. Need to reset the area the previous frame occupied @@ -101,31 +108,53 @@ static void GIFDraw(GIFDRAW *pDraw) { // To workaround clear the gif.bitmap object yourself as required. } - uint8_t c, ucTransparent = pDraw->ucTransparent; - d += pDraw->iX; - if (pDraw->ucHasTransparency == 1) { + if (palette != NULL) { + uint8_t *s = pDraw->pPixels; + uint8_t *d = (uint8_t *)row; + + d += pDraw->iX; for (int x = 0; x < iWidth; x++) { - c = *s++; - if (c != ucTransparent) { - *d = pPal[c]; - } - d++; + *d++ = *s++; } } else { - for (int x = 0; x < iWidth; x++) - { - c = *s++; - *d++ = pPal[c]; + // No palette writing RGB565_SWAPPED right to bitmap buffer + uint8_t *s = pDraw->pPixels; + ; + uint16_t *d = (uint16_t *)row; + + uint16_t *pPal; + pPal = (uint16_t *)pDraw->pPalette; + + uint8_t c, ucTransparent = pDraw->ucTransparent; + d += pDraw->iX; + if (pDraw->ucHasTransparency == 1) { + for (int x = 0; x < iWidth; x++) + { + c = *s++; + if (c != ucTransparent) { + *d = pPal[c]; + } + d++; + } + } else { + for (int x = 0; x < iWidth; x++) + { + c = *s++; + *d++ = pPal[c]; + } } } } -void common_hal_gifio_ondiskgif_construct(gifio_ondiskgif_t *self, pyb_file_obj_t *file) { - // mp_printf(&mp_plat_print, "Begin OnDiskGif\n"); +void common_hal_gifio_ondiskgif_construct(gifio_ondiskgif_t *self, pyb_file_obj_t *file, bool use_palette) { self->file = file; - GIF_begin(&self->gif, GIF_PALETTE_RGB565_BE); + if (use_palette == true) { + GIF_begin(&self->gif, GIF_PALETTE_RGB888); + } else { + GIF_begin(&self->gif, GIF_PALETTE_RGB565_BE); + } self->gif.iError = GIF_SUCCESS; self->gif.pfnRead = GIFReadFile; @@ -143,10 +172,22 @@ void common_hal_gifio_ondiskgif_construct(gifio_ondiskgif_t *self, pyb_file_obj_ mp_arg_error_invalid(MP_QSTR_file); } + int bpp = 16; + if (use_palette == true) { + mp_printf(&mp_plat_print, "Using palette\n"); + displayio_palette_t *palette = m_new_obj(displayio_palette_t); + palette->base.type = &displayio_palette_type; + common_hal_displayio_palette_construct(palette, 256, false); + self->displayio_objs.palette = palette; + bpp = 8; + } else { + self->displayio_objs.palette = NULL; + } + displayio_bitmap_t *bitmap = m_new_obj(displayio_bitmap_t); bitmap->base.type = &displayio_bitmap_type; - common_hal_displayio_bitmap_construct(bitmap, self->gif.iCanvasWidth, self->gif.iCanvasHeight, 16); - self->bitmap = bitmap; + common_hal_displayio_bitmap_construct(bitmap, self->gif.iCanvasWidth, self->gif.iCanvasHeight, bpp); + self->displayio_objs.bitmap = bitmap; GIFINFO info; GIF_getInfo(&self->gif, &info); @@ -158,12 +199,13 @@ void common_hal_gifio_ondiskgif_construct(gifio_ondiskgif_t *self, pyb_file_obj_ void common_hal_gifio_ondiskgif_deinit(gifio_ondiskgif_t *self) { self->file = NULL; - common_hal_displayio_bitmap_deinit(self->bitmap); - self->bitmap = NULL; + common_hal_displayio_bitmap_deinit(self->displayio_objs.bitmap); + self->displayio_objs.bitmap = NULL; + self->displayio_objs.palette = NULL; } bool common_hal_gifio_ondiskgif_deinited(gifio_ondiskgif_t *self) { - return self->bitmap == NULL; + return self->displayio_objs.bitmap == NULL; } uint16_t common_hal_gifio_ondiskgif_get_height(gifio_ondiskgif_t *self) { @@ -175,7 +217,11 @@ uint16_t common_hal_gifio_ondiskgif_get_width(gifio_ondiskgif_t *self) { } mp_obj_t common_hal_gifio_ondiskgif_get_bitmap(gifio_ondiskgif_t *self) { - return MP_OBJ_FROM_PTR(self->bitmap); + return MP_OBJ_FROM_PTR(self->displayio_objs.bitmap); +} + +mp_obj_t common_hal_gifio_ondiskgif_get_palette(gifio_ondiskgif_t *self) { + return MP_OBJ_FROM_PTR(self->displayio_objs.palette); } int32_t common_hal_gifio_ondiskgif_get_duration(gifio_ondiskgif_t *self) { @@ -196,17 +242,18 @@ int32_t common_hal_gifio_ondiskgif_get_max_delay(gifio_ondiskgif_t *self) { uint32_t common_hal_gifio_ondiskgif_next_frame(gifio_ondiskgif_t *self, bool setDirty) { int nextDelay = 0; - int result = GIF_playFrame(&self->gif, &nextDelay, self->bitmap); + int result = 0; + result = GIF_playFrame(&self->gif, &nextDelay, &self->displayio_objs); if ((result >= 0) && (setDirty)) { displayio_area_t dirty_area = { .x1 = 0, .y1 = 0, - .x2 = self->bitmap->width, - .y2 = self->bitmap->height, + .x2 = self->displayio_objs.bitmap->width, + .y2 = self->displayio_objs.bitmap->height, }; - displayio_bitmap_set_dirty_area(self->bitmap, &dirty_area); + displayio_bitmap_set_dirty_area(self->displayio_objs.bitmap, &dirty_area); } return nextDelay; diff --git a/shared-module/gifio/OnDiskGif.h b/shared-module/gifio/OnDiskGif.h index c40781ef1f..70479ac8d9 100644 --- a/shared-module/gifio/OnDiskGif.h +++ b/shared-module/gifio/OnDiskGif.h @@ -34,14 +34,20 @@ #include "lib/AnimatedGIF/AnimatedGIF_circuitpy.h" #include "shared-module/displayio/Bitmap.h" +#include "shared-module/displayio/Palette.h" #include "extmod/vfs_fat.h" +typedef struct { + displayio_bitmap_t *bitmap; + displayio_palette_t *palette; +} gifio_ondiskgif_displayio_objs_t; + typedef struct { mp_obj_base_t base; GIFIMAGE gif; pyb_file_obj_t *file; - displayio_bitmap_t *bitmap; + gifio_ondiskgif_displayio_objs_t displayio_objs; int32_t duration; int32_t frame_count; int32_t min_delay; From 8980ebfa169059ca993e27f164e92aed51185b1f Mon Sep 17 00:00:00 2001 From: Ted Hess Date: Sun, 16 Apr 2023 12:06:15 -0400 Subject: [PATCH 037/117] Simplify CORS checks and don't restrict host names. Minor socket cleanup. --- .../espressif/common-hal/socketpool/Socket.c | 1 - supervisor/shared/web_workflow/web_workflow.c | 82 ++++++++----------- 2 files changed, 35 insertions(+), 48 deletions(-) diff --git a/ports/espressif/common-hal/socketpool/Socket.c b/ports/espressif/common-hal/socketpool/Socket.c index 5af3cdbbc3..ef56480672 100644 --- a/ports/espressif/common-hal/socketpool/Socket.c +++ b/ports/espressif/common-hal/socketpool/Socket.c @@ -88,7 +88,6 @@ STATIC void socket_select_task(void *arg) { } assert(num_triggered > 0); - assert(!FD_ISSET(socket_change_fd, &excptfds)); // Notice event trigger if (FD_ISSET(socket_change_fd, &readfds)) { diff --git a/supervisor/shared/web_workflow/web_workflow.c b/supervisor/shared/web_workflow/web_workflow.c index d24547dd09..faadd52bda 100644 --- a/supervisor/shared/web_workflow/web_workflow.c +++ b/supervisor/shared/web_workflow/web_workflow.c @@ -24,6 +24,9 @@ * THE SOFTWARE. */ +// Include strchrnul() +#define _GNU_SOURCE + #include #include @@ -85,8 +88,8 @@ typedef struct { char destination[256]; char header_key[64]; char header_value[256]; - // We store the origin so we can reply back with it. - char origin[64]; + char origin[64]; // We store the origin so we can reply back with it. + char host[64]; // We store the host to check against origin. size_t content_length; size_t offset; uint64_t timestamp_ms; @@ -454,49 +457,33 @@ static bool _endswith(const char *str, const char *suffix) { return strcmp(str + (strlen(str) - strlen(suffix)), suffix) == 0; } -const char *ok_hosts[] = { - "127.0.0.1", - "localhost", -}; +const char http_scheme[] = "http://"; +#define PREFIX_HTTP_LEN (sizeof(http_scheme) - 1) -static bool _origin_ok(const char *origin) { - const char *http = "http://"; - - // note: redirected requests send an Origin of "null" and will be caught by this - if (strncmp(origin, http, strlen(http)) != 0) { - return false; - } - // These are prefix checks up to : so that any port works. - // TODO: Support DHCP hostname in addition to MDNS. - const char *end; - #if CIRCUITPY_MDNS - if (!common_hal_mdns_server_deinited(&mdns)) { - const char *local = ".local"; - const char *hostname = common_hal_mdns_server_get_hostname(&mdns); - end = origin + strlen(http) + strlen(hostname) + strlen(local); - if (strncmp(origin + strlen(http), hostname, strlen(hostname)) == 0 && - strncmp(origin + strlen(http) + strlen(hostname), local, strlen(local)) == 0 && - (end[0] == '\0' || end[0] == ':')) { - return true; - } - } - #endif - - _update_encoded_ip(); - end = origin + strlen(http) + strlen(_our_ip_encoded); - if (strncmp(origin + strlen(http), _our_ip_encoded, strlen(_our_ip_encoded)) == 0 && - (end[0] == '\0' || end[0] == ':')) { +static bool _origin_ok(_request *request) { + // Origin may be 'null' + if (request->origin[0] == '\0') { return true; } - - for (size_t i = 0; i < MP_ARRAY_SIZE(ok_hosts); i++) { - // Allows any port - end = origin + strlen(http) + strlen(ok_hosts[i]); - if (strncmp(origin + strlen(http), ok_hosts[i], strlen(ok_hosts[i])) == 0 - && (end[0] == '\0' || end[0] == ':')) { + // Origin has http prefix? + if (strncmp(request->origin, http_scheme, PREFIX_HTTP_LEN) != 0) { + // Not HTTP scheme request - ok + request->origin[0] = '\0'; + return true; + } + // Host given? + if (request->host[0] != '\0') { + // OK if host and origin match (fqdn + port #) + if (strcmp(request->host, &request->origin[PREFIX_HTTP_LEN]) == 0) { + return true; + } + // DEBUG: OK if origin is 'localhost' (ignoring port #) + *strchrnul(&request->origin[PREFIX_HTTP_LEN], ':') = '\0'; + if (strcmp(&request->origin[PREFIX_HTTP_LEN], "localhost") == 0) { return true; } } + // Otherwise deny request return false; } @@ -517,8 +504,8 @@ static void _cors_header(socketpool_socket_obj_t *socket, _request *request) { _send_strs(socket, "Access-Control-Allow-Credentials: true\r\n", "Vary: Origin, Accept, Upgrade\r\n", - "Access-Control-Allow-Origin: *\r\n", - NULL); + "Access-Control-Allow-Origin: ", + (request->origin[0] == '\0') ? "*" : request->origin, "\r\n", NULL); } static void _reply_continue(socketpool_socket_obj_t *socket, _request *request) { @@ -1086,11 +1073,7 @@ static bool _reply(socketpool_socket_obj_t *socket, _request *request) { #else _reply_missing(socket, request); #endif - -// For now until CORS is sorted, allow always the origin requester. -// Note: caller knows who we are better than us. CORS is not security -// unless browser cooperates. Do not rely on mDNS or IP. - } else if (strlen(request->origin) > 0 && !_origin_ok(request->origin)) { + } else if (!_origin_ok(request)) { _reply_forbidden(socket, request); } else if (strncmp(request->path, "/fs/", 4) == 0) { if (strcasecmp(request->method, "OPTIONS") == 0) { @@ -1314,6 +1297,7 @@ static bool _reply(socketpool_socket_obj_t *socket, _request *request) { static void _reset_request(_request *request) { request->state = STATE_METHOD; request->origin[0] = '\0'; + request->host[0] = '\0'; request->content_length = 0; request->offset = 0; request->timestamp_ms = 0; @@ -1340,6 +1324,7 @@ static void _process_request(socketpool_socket_obj_t *socket, _request *request) if (len == 0 || len == -MP_ENOTCONN) { // Disconnect - clear 'in-progress' _reset_request(request); + common_hal_socketpool_socket_close(socket); } break; } @@ -1421,6 +1406,8 @@ static void _process_request(socketpool_socket_obj_t *socket, _request *request) request->redirect = strncmp(request->header_value, cp_local, strlen(cp_local)) == 0 && (strlen(request->header_value) == strlen(cp_local) || request->header_value[strlen(cp_local)] == ':'); + strncpy(request->host, request->header_value, sizeof(request->host) - 1); + request->host[sizeof(request->host) - 1] = '\0'; } else if (strcasecmp(request->header_key, "Content-Length") == 0) { request->content_length = strtoul(request->header_value, NULL, 10); } else if (strcasecmp(request->header_key, "Expect") == 0) { @@ -1428,7 +1415,8 @@ static void _process_request(socketpool_socket_obj_t *socket, _request *request) } else if (strcasecmp(request->header_key, "Accept") == 0) { request->json = strcasecmp(request->header_value, "application/json") == 0; } else if (strcasecmp(request->header_key, "Origin") == 0) { - strcpy(request->origin, request->header_value); + strncpy(request->origin, request->header_value, sizeof(request->origin) - 1); + request->origin[sizeof(request->origin) - 1] = '\0'; } else if (strcasecmp(request->header_key, "X-Timestamp") == 0) { request->timestamp_ms = strtoull(request->header_value, NULL, 10); } else if (strcasecmp(request->header_key, "Upgrade") == 0) { From e5a5a348fd9c9e927c1e7e5d82a3957ea5044f81 Mon Sep 17 00:00:00 2001 From: CDarius Date: Wed, 19 Apr 2023 08:17:10 +0000 Subject: [PATCH 038/117] Fixed wrong GPIO number for touch screen interrupt --- ports/espressif/boards/m5stack_core2/pins.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/espressif/boards/m5stack_core2/pins.c b/ports/espressif/boards/m5stack_core2/pins.c index 865ce61eaf..ee8fe21ad9 100644 --- a/ports/espressif/boards/m5stack_core2/pins.c +++ b/ports/espressif/boards/m5stack_core2/pins.c @@ -83,7 +83,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_SD_CS),MP_ROM_PTR(&pin_GPIO4) }, // touch screen - { MP_ROM_QSTR(MP_QSTR_TOUCH_SCR_IRQ),MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_TOUCH_INT),MP_ROM_PTR(&pin_GPIO39) }, { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, { MP_ROM_QSTR(MP_QSTR_PORTA_I2C), MP_ROM_PTR(&board_porta_i2c_obj) }, From fd1e9cf8f18d96cb46ee878700040b4b462a8931 Mon Sep 17 00:00:00 2001 From: Milind Date: Wed, 19 Apr 2023 21:46:08 +0530 Subject: [PATCH 039/117] 1. Changed attenuation from ADC_ATTEN_DB_0 to ADC_ATTEN_DB_11 2. Scaling the 12-bit values received from DMA engine to 16-bit value --- ports/espressif/common-hal/analogbufio/BufferedIn.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ports/espressif/common-hal/analogbufio/BufferedIn.c b/ports/espressif/common-hal/analogbufio/BufferedIn.c index f2ee8c19af..3a8d8d0def 100644 --- a/ports/espressif/common-hal/analogbufio/BufferedIn.c +++ b/ports/espressif/common-hal/analogbufio/BufferedIn.c @@ -46,8 +46,9 @@ #define NUM_SAMPLES_PER_INTERRUPT 256 #define NUM_ADC_CHANNELS 1 #define DMA_BUFFER_SIZE 1024 -#define ATTENUATION ADC_ATTEN_DB_0 +#define ATTENUATION ADC_ATTEN_DB_11 #define ADC_READ_TIMEOUT_MS 2000 +#define ADC_PIN_MAX_VALUE 0xfff #if defined(CONFIG_IDF_TARGET_ESP32) #define ADC_RESULT_BYTE 2 @@ -239,6 +240,7 @@ uint32_t common_hal_analogbufio_bufferedin_readinto(analogbufio_bufferedin_obj_t uint32_t captured_bytes = 0; esp_err_t ret; uint32_t ret_num = 0; + uint32_t adc_reading = 0; adc_digi_convert_mode_t convert_mode = ADC_CONV_SINGLE_UNIT_2; adc_digi_output_format_t output_format = ADC_DIGI_OUTPUT_FORMAT_TYPE1; @@ -264,11 +266,13 @@ uint32_t common_hal_analogbufio_bufferedin_readinto(analogbufio_bufferedin_obj_t uint16_t *pBuffer = (uint16_t *)(void *)&buffer[captured_bytes]; if (output_format == ADC_DIGI_OUTPUT_FORMAT_TYPE1) { #if defined(CONFIG_IDF_TARGET_ESP32) || defined(CONFIG_IDF_TARGET_ESP32S2) - *pBuffer = pResult->type1.data; + adc_reading = pResult->type1.data; #endif } else { - *pBuffer = pResult->type2.data; + adc_reading = pResult->type2.data; } + adc_reading = adc_reading * ((1 << 16) - 1) / ADC_PIN_MAX_VALUE; + *pBuffer = (uint16_t)adc_reading; captured_bytes += sizeof(uint16_t); captured_samples++; } else { From 66edcf5d034432519aac18690806adad2cacf2ac Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 7 Apr 2023 11:59:55 -0700 Subject: [PATCH 040/117] Add PicoDVI support PicoDVI in CP support 640x480 and 800x480 on Feather DVI, Pico and Pico W. 1 and 2 bit grayscale are full resolution. 8 and 16 bit color are half resolution. Memory layout is modified to give the top most 4k of ram to the second core. Its MPU is used to prevent flash access after startup. The port saved word is moved to a watchdog scratch register so that it doesn't get overwritten by other things in RAM. Right align status bar and scroll area. This normally gives a few pixels of padding on the left hand side and improves the odds it is readable in a case. Fixes #7562 Fixes c stack checking. The length was correct but the top was being set to the current stack pointer instead of the correct top. Fixes #7643 This makes Bitmap subscr raise IndexError instead of ValueError when the index arguments are wrong. --- .gitmodules | 4 + locale/circuitpython.pot | 24 +- main.c | 10 +- .../common-hal/videocore/Framebuffer.c | 1 + ports/raspberrypi/Makefile | 47 +- ports/raspberrypi/audio_dma.c | 2 +- .../bindings/picodvi/Framebuffer.c | 265 +++++++++++ .../bindings/picodvi/Framebuffer.h | 49 ++ ports/raspberrypi/bindings/picodvi/__init__.c | 48 ++ .../adafruit_feather_rp2040_dvi/board.c | 23 + .../mpconfigboard.mk | 2 + .../boards/adafruit_feather_rp2040_dvi/pins.c | 4 + .../boards/raspberry_pi_pico/mpconfigboard.mk | 1 + .../boards/raspberry_pi_pico_w/link.ld | 295 +----------- .../raspberry_pi_pico_w/mpconfigboard.mk | 2 + .../common-hal/picodvi/Framebuffer.c | 419 ++++++++++++++++++ .../common-hal/picodvi/Framebuffer.h | 51 +++ .../common-hal/rp2pio/StateMachine.c | 18 +- .../common-hal/rp2pio/StateMachine.h | 3 + ports/raspberrypi/lib/PicoDVI | 1 + ports/raspberrypi/link.ld | 52 ++- ports/raspberrypi/mpconfigport.mk | 2 +- .../sdk_config/pico/config_autogen.h | 6 + ports/raspberrypi/supervisor/port.c | 29 +- py/circuitpy_defns.mk | 19 +- py/circuitpy_mpconfig.mk | 5 + shared-bindings/displayio/Bitmap.c | 24 +- shared-module/displayio/ColorConverter.c | 12 + shared-module/displayio/ColorConverter.h | 1 + shared-module/displayio/__init__.c | 11 + shared-module/displayio/__init__.h | 7 + supervisor/shared/display.c | 40 +- supervisor/shared/memory.c | 2 + supervisor/shared/usb/usb.c | 2 +- tools/cortex-m-fault-gdb.py | 62 ++- 35 files changed, 1134 insertions(+), 409 deletions(-) create mode 100644 ports/raspberrypi/bindings/picodvi/Framebuffer.c create mode 100644 ports/raspberrypi/bindings/picodvi/Framebuffer.h create mode 100644 ports/raspberrypi/bindings/picodvi/__init__.c create mode 100644 ports/raspberrypi/common-hal/picodvi/Framebuffer.c create mode 100644 ports/raspberrypi/common-hal/picodvi/Framebuffer.h create mode 160000 ports/raspberrypi/lib/PicoDVI diff --git a/.gitmodules b/.gitmodules index a33354bbff..2fcfc07fcc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -331,3 +331,7 @@ [submodule "ports/silabs/tools/slc_cli_linux"] path = ports/silabs/tools/slc_cli_linux url = https://github.com/SiliconLabs/circuitpython_slc_cli_linux +[submodule "ports/raspberrypi/lib/PicoDVI"] + path = ports/raspberrypi/lib/PicoDVI + url = https://github.com/circuitpython/PicoDVI.git + branch = circuitpython diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index f87fc02975..87c28a21e9 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -98,6 +98,9 @@ msgstr "" #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c msgid "%q" msgstr "" @@ -123,6 +126,7 @@ msgstr "" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/microcontroller/Pin.c @@ -161,11 +165,11 @@ msgstr "" msgid "%q length must be >= %d" msgstr "" -#: py/argcheck.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c msgid "%q must be %d" msgstr "" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/displayio/Bitmap.c msgid "%q must be %d-%d" msgstr "" @@ -193,7 +197,7 @@ msgstr "" msgid "%q must be array of type 'H'" msgstr "" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "" @@ -465,6 +469,7 @@ msgstr "" msgid "All event channels in use" msgstr "" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "All state machines in use" msgstr "" @@ -473,6 +478,7 @@ msgstr "" msgid "All sync event channels in use" msgstr "" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: shared-bindings/pwmio/PWMOut.c msgid "All timers for this pin are in use" msgstr "" @@ -1117,10 +1123,6 @@ msgstr "" msgid "I2C peripheral in use" msgstr "" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "" @@ -1223,7 +1225,9 @@ msgid "Interrupt error." msgstr "" #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c -#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c +#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +#: ports/raspberrypi/bindings/picodvi/Framebuffer.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/displayio/EPaperDisplay.c msgid "Invalid %q" @@ -1708,10 +1712,6 @@ msgstr "" msgid "Oversample must be multiple of 8." msgstr "" -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "" - #: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." diff --git a/main.c b/main.c index 6ff6202d6d..9351d90529 100644 --- a/main.c +++ b/main.c @@ -153,11 +153,15 @@ STATIC void start_mp(supervisor_allocation *heap, supervisor_allocation *pystack supervisor_workflow_reset(); // Stack limit should be less than real stack size, so we have a chance - // to recover from limit hit. (Limit is measured in bytes.) + // to recover from limit hit. (Limit is measured in bytes.) The top of the + // stack is set to our current state. Not the actual top. mp_stack_ctrl_init(); - if (stack_get_bottom() != NULL) { - mp_stack_set_limit(stack_get_length() - 1024); + uint32_t *stack_bottom = stack_get_bottom(); + if (stack_bottom != NULL) { + size_t stack_length = stack_get_length(); + mp_stack_set_top(stack_bottom + (stack_length / sizeof(uint32_t))); + mp_stack_set_limit(stack_length - 1024); } diff --git a/ports/broadcom/common-hal/videocore/Framebuffer.c b/ports/broadcom/common-hal/videocore/Framebuffer.c index 18b703b8b6..63c55324af 100644 --- a/ports/broadcom/common-hal/videocore/Framebuffer.c +++ b/ports/broadcom/common-hal/videocore/Framebuffer.c @@ -42,6 +42,7 @@ void common_hal_videocore_framebuffer_deinit(videocore_framebuffer_obj_t *self) if (vcmailbox_release_framebuffer()) { self->framebuffer = NULL; } + self->base.type = &mp_type_NoneType; } bool common_hal_videocore_framebuffer_deinited(videocore_framebuffer_obj_t *self) { diff --git a/ports/raspberrypi/Makefile b/ports/raspberrypi/Makefile index fafc817ca2..f23da5a51d 100644 --- a/ports/raspberrypi/Makefile +++ b/ports/raspberrypi/Makefile @@ -33,11 +33,11 @@ INC_CYW43 := \ -isystem lib/cyw43-driver/firmware \ -isystem lib/cyw43-driver/src \ -isystem lib/lwip/src/include \ - -isystem sdk/src/rp2_common/pico_async_context/include/ \ + -isystem sdk/src/rp2_common/pico_async_context/include/ \ -isystem sdk/src/rp2_common/pico_cyw43_arch/include/ \ -isystem sdk/src/rp2_common/pico_cyw43_driver/include/ \ -isystem sdk/src/rp2_common/pico_lwip/include/ \ - -isystem sdk/src/rp2_common/pico_rand/include/ \ + -isystem sdk/src/rp2_common/pico_rand/include/ \ CFLAGS_CYW43 := -DCYW43_LWIP=1 -DPICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1 -DCYW43_USE_SPI -DIGNORE_GPIO25 -DIGNORE_GPIO23 -DIGNORE_GPIO24 -DCYW43_LOGIC_DEBUG=0 -DCYW43_NETUTILS=1 SRC_SDK_CYW43 := \ @@ -105,6 +105,7 @@ INC += \ -isystem sdk/src/common/pico_util/include/ \ -isystem sdk/src/rp2040/hardware_regs/include/ \ -isystem sdk/src/rp2040/hardware_structs/include/ \ + -isystem sdk/src/rp2_common/cmsis/ \ -isystem sdk/src/rp2_common/hardware_adc/include/ \ -isystem sdk/src/rp2_common/hardware_base/include/ \ -isystem sdk/src/rp2_common/hardware_claim/include/ \ @@ -113,16 +114,19 @@ INC += \ -isystem sdk/src/rp2_common/hardware_dma/include/ \ -isystem sdk/src/rp2_common/hardware_flash/include/ \ -isystem sdk/src/rp2_common/hardware_gpio/include/ \ + -isystem sdk/src/rp2_common/hardware_interp/include/ \ -isystem sdk/src/rp2_common/hardware_irq/include/ \ -isystem sdk/src/rp2_common/hardware_i2c/include/ \ -isystem sdk/src/rp2_common/hardware_pio/include/ \ -isystem sdk/src/rp2_common/hardware_pll/include/ \ + -isystem sdk/src/rp2_common/hardware_pwm/include/ \ -isystem sdk/src/rp2_common/hardware_resets/include/ \ -isystem sdk/src/rp2_common/hardware_rtc/include/ \ -isystem sdk/src/rp2_common/hardware_spi/include/ \ -isystem sdk/src/rp2_common/hardware_sync/include/ \ -isystem sdk/src/rp2_common/hardware_timer/include/ \ -isystem sdk/src/rp2_common/hardware_uart/include/ \ + -isystem sdk/src/rp2_common/hardware_vreg/include/ \ -isystem sdk/src/rp2_common/hardware_watchdog/include/ \ -isystem sdk/src/rp2_common/hardware_xosc/include/ \ -isystem sdk/src/rp2_common/pico_multicore/include/ \ @@ -131,7 +135,7 @@ INC += \ -isystem sdk/src/rp2_common/pico_printf/include/ \ -isystem sdk/src/rp2_common/pico_float/include/ \ -isystem sdk/src/rp2_common/pico_platform/include/ \ - -isystem sdk/src/rp2_common/pico_runtime/printf/include/ \ + -isystem sdk/src/rp2_common/pico_runtime/include/ \ -isystem sdk/src/rp2_common/pico_bootrom/include/ \ -isystem sdk/src/rp2_common/pico_unique_id/include/ \ $(INC_CYW43) \ @@ -141,7 +145,7 @@ INC += \ -I$(BUILD) # Pico specific configuration -CFLAGS += -DRASPBERRYPI -DPICO_ON_DEVICE=1 -DPICO_NO_BINARY_INFO=0 -DPICO_TIME_DEFAULT_ALARM_POOL_DISABLED=0 -DPICO_DIVIDER_CALL_IDIV0=0 -DPICO_DIVIDER_CALL_LDIV0=0 -DPICO_DIVIDER_HARDWARE=1 -DPICO_DOUBLE_ROM=1 -DPICO_FLOAT_ROM=1 -DPICO_MULTICORE=1 -DPICO_BITS_IN_RAM=0 -DPICO_DIVIDER_IN_RAM=0 -DPICO_DOUBLE_PROPAGATE_NANS=0 -DPICO_DOUBLE_IN_RAM=0 -DPICO_MEM_IN_RAM=0 -DPICO_FLOAT_IN_RAM=0 -DPICO_FLOAT_PROPAGATE_NANS=1 -DPICO_NO_FLASH=0 -DPICO_COPY_TO_RAM=0 -DPICO_DISABLE_SHARED_IRQ_HANDLERS=0 -DPICO_NO_BI_BOOTSEL_VIA_DOUBLE_RESET=0 +CFLAGS += -DRASPBERRYPI -DPICO_ON_DEVICE=1 -DPICO_NO_BINARY_INFO=0 -DPICO_TIME_DEFAULT_ALARM_POOL_DISABLED=0 -DPICO_DIVIDER_CALL_IDIV0=0 -DPICO_DIVIDER_CALL_LDIV0=0 -DPICO_DIVIDER_HARDWARE=1 -DPICO_DOUBLE_ROM=1 -DPICO_FLOAT_ROM=1 -DPICO_MULTICORE=1 -DPICO_BITS_IN_RAM=0 -DPICO_DIVIDER_IN_RAM=0 -DPICO_DOUBLE_PROPAGATE_NANS=0 -DPICO_DOUBLE_IN_RAM=0 -DPICO_MEM_IN_RAM=0 -DPICO_FLOAT_IN_RAM=0 -DPICO_FLOAT_PROPAGATE_NANS=1 -DPICO_NO_FLASH=0 -DPICO_COPY_TO_RAM=0 -DPICO_DISABLE_SHARED_IRQ_HANDLERS=0 -DPICO_NO_BI_BOOTSEL_VIA_DOUBLE_RESET=0 -DDVI_1BPP_BIT_REVERSE=0 OPTIMIZATION_FLAGS ?= -O3 # TinyUSB defines CFLAGS += -DTUD_OPT_RP2040_USB_DEVICE_ENUMERATION_FIX=1 -DCFG_TUSB_MCU=OPT_MCU_RP2040 -DCFG_TUD_MIDI_RX_BUFSIZE=128 -DCFG_TUD_CDC_RX_BUFSIZE=256 -DCFG_TUD_MIDI_TX_BUFSIZE=128 -DCFG_TUD_CDC_TX_BUFSIZE=256 -DCFG_TUD_MSC_BUFSIZE=1024 @@ -172,8 +176,8 @@ DISABLE_WARNINGS = -Wno-stringop-overflow -Wno-cast-align CFLAGS += $(INC) -Wall -Werror -std=gnu11 -nostdlib -fshort-enums $(BASE_CFLAGS) $(CFLAGS_MOD) $(COPT) $(DISABLE_WARNINGS) -Werror=missing-prototypes CFLAGS += \ - -march=armv6-m \ - -mthumb \ + -march=armv6-m \ + -mthumb \ -mabi=aapcs-linux \ -mcpu=cortex-m0plus \ -msoft-float \ @@ -195,6 +199,7 @@ SRC_SDK := \ src/common/pico_time/time.c \ src/common/pico_time/timeout_helper.c \ src/common/pico_util/pheap.c \ + src/common/pico_util/queue.c \ src/rp2_common/hardware_adc/adc.c \ src/rp2_common/hardware_claim/claim.c \ src/rp2_common/hardware_clocks/clocks.c \ @@ -202,6 +207,7 @@ SRC_SDK := \ src/rp2_common/hardware_flash/flash.c \ src/rp2_common/hardware_gpio/gpio.c \ src/rp2_common/hardware_i2c/i2c.c \ + src/rp2_common/hardware_interp/interp.c \ src/rp2_common/hardware_irq/irq.c \ src/rp2_common/hardware_pio/pio.c \ src/rp2_common/hardware_pll/pll.c \ @@ -210,6 +216,7 @@ SRC_SDK := \ src/rp2_common/hardware_sync/sync.c \ src/rp2_common/hardware_timer/timer.c \ src/rp2_common/hardware_uart/uart.c \ + src/rp2_common/hardware_vreg/vreg.c \ src/rp2_common/hardware_watchdog/watchdog.c \ src/rp2_common/hardware_xosc/xosc.c \ src/rp2_common/pico_bootrom/bootrom.c \ @@ -223,6 +230,7 @@ SRC_SDK := \ src/rp2_common/pico_printf/printf.c \ src/rp2_common/pico_runtime/runtime.c \ src/rp2_common/pico_stdio/stdio.c \ + src/rp2_common/pico_stdlib/stdlib.c \ src/rp2_common/pico_unique_id/unique_id.c \ $(SRC_SDK_CYW43) \ @@ -240,12 +248,24 @@ SRC_C += \ background.c \ peripherals/pins.c \ lib/crypto-algorithms/sha256.c \ + lib/PicoDVI/software/libdvi/dvi.c \ + lib/PicoDVI/software/libdvi/dvi_serialiser.c \ + lib/PicoDVI/software/libdvi/dvi_timing.c \ + lib/PicoDVI/software/libdvi/tmds_encode.c \ lib/tinyusb/src/portable/raspberrypi/rp2040/dcd_rp2040.c \ lib/tinyusb/src/portable/raspberrypi/rp2040/rp2040_usb.c \ mphalport.c \ $(SRC_CYW43) \ $(SRC_LWIP) \ +ifeq ($(CIRCUITPY_PICODVI),1) +SRC_C += \ + bindings/picodvi/__init__.c \ + bindings/picodvi/Framebuffer.c \ + common-hal/picodvi/Framebuffer.c \ + +endif + ifeq ($(CIRCUITPY_SSL),1) CFLAGS += -isystem $(TOP)/mbedtls/include SRC_MBEDTLS := $(addprefix lib/mbedtls/library/, \ @@ -359,6 +379,7 @@ SRC_S_UPPER = sdk/src/rp2_common/hardware_divider/divider.S \ sdk/src/rp2_common/pico_int64_ops/pico_int64_ops_aeabi.S \ sdk/src/rp2_common/pico_mem_ops/mem_ops_aeabi.S \ sdk/src/rp2_common/pico_standard_link/crt0.S \ + lib/PicoDVI/software/libdvi/tmds_encode_asm.S \ OBJ = $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_SDK:.c=.o)) @@ -405,13 +426,19 @@ SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_M all: $(BUILD)/firmware.uf2 -LINK_LD := $(firstword $(wildcard boards/$(BOARD)/link.ld link.ld)) -$(BUILD)/firmware.elf: $(OBJ) $(LINK_LD) +BOARD_LD := $(wildcard boards/$(BOARD)/link.ld) + +ifneq ($(BOARD_LD),) + LINKER_SCRIPTS = -Wl,-T,$(BOARD_LD) +endif + +LINKER_SCRIPTS += -Wl,-T,link.ld + +$(BUILD)/firmware.elf: $(OBJ) $(BOARD_LD) link.ld $(STEPECHO) "LINK $@" $(Q)echo $(OBJ) > $(BUILD)/firmware.objs $(Q)echo $(PICO_LDFLAGS) > $(BUILD)/firmware.ldflags - $(Q)$(CC) -o $@ $(CFLAGS) @$(BUILD)/firmware.ldflags -Wl,-T,$(LINK_LD) -Wl,-Map=$@.map -Wl,-cref -Wl,--gc-sections @$(BUILD)/firmware.objs -Wl,-lc - $(Q)$(SIZE) $@ | $(PYTHON) $(TOP)/tools/build_memory_info.py $(LINK_LD) $(BUILD) + $(Q)$(CC) -o $@ $(CFLAGS) @$(BUILD)/firmware.ldflags $(LINKER_SCRIPTS) -Wl,--print-memory-usage -Wl,-Map=$@.map -Wl,-cref -Wl,--gc-sections @$(BUILD)/firmware.objs -Wl,-lc $(BUILD)/firmware.bin: $(BUILD)/firmware.elf $(STEPECHO) "Create $@" diff --git a/ports/raspberrypi/audio_dma.c b/ports/raspberrypi/audio_dma.c index 7fef1a52e0..612fbbde4c 100644 --- a/ports/raspberrypi/audio_dma.c +++ b/ports/raspberrypi/audio_dma.c @@ -37,7 +37,7 @@ #include "src/rp2_common/hardware_irq/include/hardware/irq.h" -#if CIRCUITPY_AUDIOPWMIO || CIRCUITPY_AUDIOBUSIO +#if CIRCUITPY_AUDIOCORE void audio_dma_reset(void) { for (size_t channel = 0; channel < NUM_DMA_CHANNELS; channel++) { diff --git a/ports/raspberrypi/bindings/picodvi/Framebuffer.c b/ports/raspberrypi/bindings/picodvi/Framebuffer.c new file mode 100644 index 0000000000..51afd0eda7 --- /dev/null +++ b/ports/raspberrypi/bindings/picodvi/Framebuffer.c @@ -0,0 +1,265 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "py/obj.h" +#include "py/objproperty.h" +#include "py/runtime.h" +#include "py/objarray.h" + +#include "bindings/picodvi/Framebuffer.h" +#include "shared-bindings/util.h" +#include "shared-module/displayio/__init__.h" +#include "shared-module/framebufferio/__init__.h" +#include "shared-module/framebufferio/FramebufferDisplay.h" + +//| class Framebuffer: +//| """A PicoDVI managed frame buffer.""" +//| +//| def __init__( +//| self, +//| width: int, +//| height: int, +//| *, +//| clk_dp: microcontroller.Pin, +//| clk_dn: microcontroller.Pin, +//| red_dp: microcontroller.Pin, +//| red_dn: microcontroller.Pin, +//| green_dp: microcontroller.Pin, +//| green_dn: microcontroller.Pin, +//| blue_dp: microcontroller.Pin, +//| blue_dn: microcontroller.Pin, +//| color_depth: int = 8, +//| ) -> None: +//| """Create a Framebuffer object with the given dimensions (640x480 or 800x480). Memory is +//| allocated outside of onto the heap and then moved outside on VM +//| end. +//| +//| This will change the system clock speed to match the DVI signal. +//| Make sure to initialize other objects after this one so they account +//| for the changed clock. This also allocates a very large framebuffer +//| and is most likely to succeed the earlier it is attempted. +//| +//| Each *_dp and *_dn pair of pins must be neighboring, such as 19 and +//| 20. They must also be ordered the same way. In other words, dp must +//| be less than dn for all pairs or dp must be greater than dn for all +//| pairs. +//| +//| The framebuffer pixel format varies depending on color_depth: +//| * 1 - Each bit is a pixel. Either white (1) or black (0). +//| * 2 - Each 2 bits is a pixels. Grayscale between white (0x3) and black (0x0). +//| * 8 - Each byte is a pixels in RGB332 format. +//| * 16 - Each two bytes are a pixel in RGB565 format. +//| +//| Monochrome framebuffers (color_depth=1 or 2) will be full resolution. +//| Color framebuffers will be half resolution and pixels will be +//| duplicated to create a signal with the target dimensions. +//| +//| A Framebuffer is often used in conjunction with a +//| `framebufferio.FramebufferDisplay`. +//| +//| :param int width: the width of the target display signal. It will be halved when +//| color_depth >= 8 when creating the framebuffer. Only 640 or 800 is currently supported. +//| :param int height: the height of the target display signal. It will be halved when +//| color_depth >= 8 when creating the framebuffer. Only 480 is currently supported. +//| :param ~microcontroller.Pin clk_dp: the positive clock signal pin +//| :param ~microcontroller.Pin clk_dn: the negative clock signal pin +//| :param ~microcontroller.Pin red_dp: the positive red signal pin +//| :param ~microcontroller.Pin red_dn: the negative red signal pin +//| :param ~microcontroller.Pin green_dp: the positive green signal pin +//| :param ~microcontroller.Pin green_dn: the negative green signal pin +//| :param ~microcontroller.Pin blue_dp: the positive blue signal pin +//| :param ~microcontroller.Pin blue_dn: the negative blue signal pin +//| :param int color_depth: the color depth of the framebuffer in bits. 1, 2 for grayscale +//| and 8 or 16 for color +//| """ + +STATIC mp_obj_t picodvi_framebuffer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + enum { ARG_width, ARG_height, ARG_clk_dp, ARG_clk_dn, ARG_red_dp, ARG_red_dn, ARG_green_dp, + ARG_green_dn, ARG_blue_dp, ARG_blue_dn, ARG_color_depth }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_width, MP_ARG_INT | MP_ARG_REQUIRED }, + { MP_QSTR_height, MP_ARG_INT | MP_ARG_REQUIRED }, + + { MP_QSTR_clk_dp, MP_ARG_KW_ONLY | MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_clk_dn, MP_ARG_KW_ONLY | MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_red_dp, MP_ARG_KW_ONLY | MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_red_dn, MP_ARG_KW_ONLY | MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_green_dp, MP_ARG_KW_ONLY | MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_green_dn, MP_ARG_KW_ONLY | MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_blue_dp, MP_ARG_KW_ONLY | MP_ARG_OBJ | MP_ARG_REQUIRED }, + { MP_QSTR_blue_dn, MP_ARG_KW_ONLY | MP_ARG_OBJ | MP_ARG_REQUIRED }, + + { MP_QSTR_color_depth, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 8} }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + picodvi_framebuffer_obj_t *self = &allocate_display_bus_or_raise()->picodvi; + self->base.type = &picodvi_framebuffer_type; + + mp_uint_t width = (mp_uint_t)mp_arg_validate_int_min(args[ARG_width].u_int, 0, MP_QSTR_width); + mp_uint_t height = (mp_uint_t)mp_arg_validate_int_min(args[ARG_height].u_int, 0, MP_QSTR_height); + mp_uint_t color_depth = args[ARG_color_depth].u_int; + if (color_depth != 1 && color_depth != 2 && color_depth != 8 && color_depth != 16) { + mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_color_depth); + } + common_hal_picodvi_framebuffer_construct(self, + width, height, + validate_obj_is_free_pin(args[ARG_clk_dp].u_obj, MP_QSTR_clk_dp), + validate_obj_is_free_pin(args[ARG_clk_dn].u_obj, MP_QSTR_clk_dn), + validate_obj_is_free_pin(args[ARG_red_dp].u_obj, MP_QSTR_red_dp), + validate_obj_is_free_pin(args[ARG_red_dn].u_obj, MP_QSTR_red_dn), + validate_obj_is_free_pin(args[ARG_green_dp].u_obj, MP_QSTR_green_dp), + validate_obj_is_free_pin(args[ARG_green_dn].u_obj, MP_QSTR_green_dn), + validate_obj_is_free_pin(args[ARG_blue_dp].u_obj, MP_QSTR_blue_dp), + validate_obj_is_free_pin(args[ARG_blue_dn].u_obj, MP_QSTR_blue_dn), + color_depth); + + return MP_OBJ_FROM_PTR(self); +} + +//| def deinit(self) -> None: +//| """Free the resources (pins, timers, etc.) associated with this +//| rgbmatrix instance. After deinitialization, no further operations +//| may be performed.""" +//| ... +STATIC mp_obj_t picodvi_framebuffer_deinit(mp_obj_t self_in) { + picodvi_framebuffer_obj_t *self = (picodvi_framebuffer_obj_t *)self_in; + common_hal_picodvi_framebuffer_deinit(self); + return mp_const_none; +} + +STATIC MP_DEFINE_CONST_FUN_OBJ_1(picodvi_framebuffer_deinit_obj, picodvi_framebuffer_deinit); + +static void check_for_deinit(picodvi_framebuffer_obj_t *self) { + if (common_hal_picodvi_framebuffer_deinited(self)) { + raise_deinited_error(); + } +} + +//| width: int +//| """The width of the framebuffer, in pixels. It may be doubled for output (and half of what +//| width was given to __init__.)""" +STATIC mp_obj_t picodvi_framebuffer_get_width(mp_obj_t self_in) { + picodvi_framebuffer_obj_t *self = (picodvi_framebuffer_obj_t *)self_in; + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_picodvi_framebuffer_get_width(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(picodvi_framebuffer_get_width_obj, picodvi_framebuffer_get_width); +MP_PROPERTY_GETTER(picodvi_framebuffer_width_obj, + (mp_obj_t)&picodvi_framebuffer_get_width_obj); + +//| height: int +//| """The width of the framebuffer, in pixels. It may be doubled for output (and half of what +//| width was given to __init__.)""" +//| +STATIC mp_obj_t picodvi_framebuffer_get_height(mp_obj_t self_in) { + picodvi_framebuffer_obj_t *self = (picodvi_framebuffer_obj_t *)self_in; + check_for_deinit(self); + return MP_OBJ_NEW_SMALL_INT(common_hal_picodvi_framebuffer_get_height(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(picodvi_framebuffer_get_height_obj, picodvi_framebuffer_get_height); + +MP_PROPERTY_GETTER(picodvi_framebuffer_height_obj, + (mp_obj_t)&picodvi_framebuffer_get_height_obj); + +STATIC const mp_rom_map_elem_t picodvi_framebuffer_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&picodvi_framebuffer_deinit_obj) }, + + { MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&picodvi_framebuffer_width_obj) }, + { MP_ROM_QSTR(MP_QSTR_height), MP_ROM_PTR(&picodvi_framebuffer_height_obj) }, +}; +STATIC MP_DEFINE_CONST_DICT(picodvi_framebuffer_locals_dict, picodvi_framebuffer_locals_dict_table); + +STATIC void picodvi_framebuffer_get_bufinfo(mp_obj_t self_in, mp_buffer_info_t *bufinfo) { + common_hal_picodvi_framebuffer_get_buffer(self_in, bufinfo, 0); +} + +// These versions exist so that the prototype matches the protocol, +// avoiding a type cast that can hide errors +STATIC void picodvi_framebuffer_swapbuffers(mp_obj_t self_in, uint8_t *dirty_row_bitmap) { + (void)dirty_row_bitmap; + common_hal_picodvi_framebuffer_refresh(self_in); +} + +STATIC void picodvi_framebuffer_deinit_proto(mp_obj_t self_in) { + common_hal_picodvi_framebuffer_deinit(self_in); +} + +STATIC int picodvi_framebuffer_get_width_proto(mp_obj_t self_in) { + return common_hal_picodvi_framebuffer_get_width(self_in); +} + +STATIC int picodvi_framebuffer_get_height_proto(mp_obj_t self_in) { + return common_hal_picodvi_framebuffer_get_height(self_in); +} + +STATIC int picodvi_framebuffer_get_color_depth_proto(mp_obj_t self_in) { + return common_hal_picodvi_framebuffer_get_color_depth(self_in); + ; +} + +STATIC int picodvi_framebuffer_get_bytes_per_cell_proto(mp_obj_t self_in) { + return 1; +} + +STATIC int picodvi_framebuffer_get_native_frames_per_second_proto(mp_obj_t self_in) { + return 60; +} + +STATIC bool picodvi_framebuffer_get_pixels_in_byte_share_row_proto(mp_obj_t self_in) { + return true; +} + +STATIC int picodvi_framebuffer_get_row_stride_proto(mp_obj_t self_in) { + return common_hal_picodvi_framebuffer_get_row_stride(self_in); +} + +STATIC const framebuffer_p_t picodvi_framebuffer_proto = { + MP_PROTO_IMPLEMENT(MP_QSTR_protocol_framebuffer) + .get_bufinfo = picodvi_framebuffer_get_bufinfo, + .get_width = picodvi_framebuffer_get_width_proto, + .get_height = picodvi_framebuffer_get_height_proto, + .get_color_depth = picodvi_framebuffer_get_color_depth_proto, + .get_row_stride = picodvi_framebuffer_get_row_stride_proto, + .get_bytes_per_cell = picodvi_framebuffer_get_bytes_per_cell_proto, + .get_native_frames_per_second = picodvi_framebuffer_get_native_frames_per_second_proto, + .get_pixels_in_byte_share_row = picodvi_framebuffer_get_pixels_in_byte_share_row_proto, + .swapbuffers = picodvi_framebuffer_swapbuffers, + .deinit = picodvi_framebuffer_deinit_proto, +}; + +const mp_obj_type_t picodvi_framebuffer_type = { + { &mp_type_type }, + .flags = MP_TYPE_FLAG_EXTENDED, + .name = MP_QSTR_Framebuffer, + .locals_dict = (mp_obj_dict_t *)&picodvi_framebuffer_locals_dict, + .make_new = picodvi_framebuffer_make_new, + MP_TYPE_EXTENDED_FIELDS( + .buffer_p = { .get_buffer = common_hal_picodvi_framebuffer_get_buffer, }, + .protocol = &picodvi_framebuffer_proto, + ), +}; diff --git a/ports/raspberrypi/bindings/picodvi/Framebuffer.h b/ports/raspberrypi/bindings/picodvi/Framebuffer.h new file mode 100644 index 0000000000..cfcab4af50 --- /dev/null +++ b/ports/raspberrypi/bindings/picodvi/Framebuffer.h @@ -0,0 +1,49 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023 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. + */ + +#pragma once + +#include "common-hal/picodvi/Framebuffer.h" + +#include "shared-bindings/microcontroller/Pin.h" + +extern const mp_obj_type_t picodvi_framebuffer_type; + +void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self, + mp_uint_t width, mp_uint_t height, + const mcu_pin_obj_t *clk_dp, const mcu_pin_obj_t *clk_dn, + const mcu_pin_obj_t *red_dp, const mcu_pin_obj_t *red_dn, + const mcu_pin_obj_t *green_dp, const mcu_pin_obj_t *green_dn, + const mcu_pin_obj_t *blue_dp, const mcu_pin_obj_t *blue_dn, + mp_uint_t color_depth); +void common_hal_picodvi_framebuffer_deinit(picodvi_framebuffer_obj_t *self); +bool common_hal_picodvi_framebuffer_deinited(picodvi_framebuffer_obj_t *self); +void common_hal_picodvi_framebuffer_refresh(picodvi_framebuffer_obj_t *self); +int common_hal_picodvi_framebuffer_get_width(picodvi_framebuffer_obj_t *self); +int common_hal_picodvi_framebuffer_get_height(picodvi_framebuffer_obj_t *self); +int common_hal_picodvi_framebuffer_get_row_stride(picodvi_framebuffer_obj_t *self); +int common_hal_picodvi_framebuffer_get_color_depth(picodvi_framebuffer_obj_t *self); +mp_int_t common_hal_picodvi_framebuffer_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags); diff --git a/ports/raspberrypi/bindings/picodvi/__init__.c b/ports/raspberrypi/bindings/picodvi/__init__.c new file mode 100644 index 0000000000..edfe7759c8 --- /dev/null +++ b/ports/raspberrypi/bindings/picodvi/__init__.c @@ -0,0 +1,48 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "py/obj.h" +#include "py/runtime.h" + +#include "bindings/picodvi/Framebuffer.h" + +//| """Low-level routines for interacting with PicoDVI Output""" + +STATIC const mp_rom_map_elem_t picodvi_module_globals_table[] = { + { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_picodvi) }, + { MP_ROM_QSTR(MP_QSTR_Framebuffer), MP_ROM_PTR(&picodvi_framebuffer_type) }, +}; + +STATIC MP_DEFINE_CONST_DICT(picodvi_module_globals, picodvi_module_globals_table); + +const mp_obj_module_t picodvi_module = { + .base = { &mp_type_module }, + .globals = (mp_obj_dict_t *)&picodvi_module_globals, +}; + +MP_REGISTER_MODULE(MP_QSTR_picodvi, picodvi_module, CIRCUITPY_PICODVI); diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/board.c b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/board.c index 331653173e..bcbab5e4cd 100644 --- a/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/board.c +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/board.c @@ -26,4 +26,27 @@ #include "supervisor/board.h" +#include "bindings/picodvi/Framebuffer.h" +#include "shared-module/displayio/__init__.h" +#include "shared-bindings/framebufferio/FramebufferDisplay.h" + +void board_init(void) { + picodvi_framebuffer_obj_t *fb = &allocate_display_bus()->picodvi; + fb->base.type = &picodvi_framebuffer_type; + common_hal_picodvi_framebuffer_construct(fb, 640, 480, + &pin_GPIO17, &pin_GPIO16, + &pin_GPIO19, &pin_GPIO18, + &pin_GPIO21, &pin_GPIO20, + &pin_GPIO23, &pin_GPIO22, + 8); + + framebufferio_framebufferdisplay_obj_t *display = &displays[0].framebuffer_display; + display->base.type = &framebufferio_framebufferdisplay_type; + common_hal_framebufferio_framebufferdisplay_construct( + display, + MP_OBJ_FROM_PTR(fb), + 0, + true); +} + // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/mpconfigboard.mk b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/mpconfigboard.mk index a60ff7b9a7..ca8a6fa396 100644 --- a/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/mpconfigboard.mk +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/mpconfigboard.mk @@ -7,3 +7,5 @@ CHIP_VARIANT = RP2040 CHIP_FAMILY = rp2 EXTERNAL_FLASH_DEVICES = "GD25Q64C,W25Q64JVxQ" + +CIRCUITPY_PICODVI = 1 diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/pins.c b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/pins.c index c8b4e3474f..3dd0fe86bb 100644 --- a/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/pins.c +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/pins.c @@ -1,5 +1,7 @@ #include "shared-bindings/board/__init__.h" +#include "shared-module/displayio/__init__.h" + STATIC const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS @@ -49,6 +51,8 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_D2N), MP_ROM_PTR(&pin_GPIO22) }, { MP_ROM_QSTR(MP_QSTR_D2P), MP_ROM_PTR(&pin_GPIO23) }, + { MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].framebuffer_display)}, + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, { MP_ROM_QSTR(MP_QSTR_STEMMA_I2C), MP_ROM_PTR(&board_i2c_obj) }, { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) }, diff --git a/ports/raspberrypi/boards/raspberry_pi_pico/mpconfigboard.mk b/ports/raspberrypi/boards/raspberry_pi_pico/mpconfigboard.mk index 608ca280df..20607d50e4 100644 --- a/ports/raspberrypi/boards/raspberry_pi_pico/mpconfigboard.mk +++ b/ports/raspberrypi/boards/raspberry_pi_pico/mpconfigboard.mk @@ -9,3 +9,4 @@ CHIP_FAMILY = rp2 EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ" CIRCUITPY__EVE = 1 +CIRCUITPY_PICODVI = 1 diff --git a/ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld b/ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld index 2777b41720..e814bead4c 100644 --- a/ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld +++ b/ports/raspberrypi/boards/raspberry_pi_pico_w/link.ld @@ -1,294 +1 @@ -/* Based on GCC ARM embedded samples. - Defines the following symbols for use by code: - __exidx_start - __exidx_end - __etext - __data_start__ - __preinit_array_start - __preinit_array_end - __init_array_start - __init_array_end - __fini_array_start - __fini_array_end - __data_end__ - __bss_start__ - __bss_end__ - __end__ - end - __HeapLimit - __StackLimit - __StackTop - __stack (== StackTop) -*/ - -MEMORY -{ - FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 1532k - /* Followed by: 4kB of NVRAM and at least 512kB of CIRCUITPY */ - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k - SCRATCH_X (rwx) : ORIGIN = 0x20040000, LENGTH = 4k - SCRATCH_Y (rwx) : ORIGIN = 0x20041000, LENGTH = 4k -} - -ENTRY(_entry_point) - -SECTIONS -{ - /* Second stage bootloader is prepended to the image. It must be 256 bytes big - and checksummed. It is usually built by the boot_stage2 target - in the Pico SDK - */ - - .flash_begin : { - __flash_binary_start = .; - } > FLASH_FIRMWARE - - .boot2 : { - __boot2_start__ = .; - KEEP (*(.boot2)) - __boot2_end__ = .; - } > FLASH_FIRMWARE - - ASSERT(__boot2_end__ - __boot2_start__ == 256, - "ERROR: Pico second stage bootloader must be 256 bytes in size") - - /* The second stage will always enter the image at the start of .text. - The debugger will use the ELF entry point, which is the _entry_point - symbol if present, otherwise defaults to start of .text. - This can be used to transfer control back to the bootrom on debugger - launches only, to perform proper flash setup. - */ - - .text : { - __logical_binary_start = .; - KEEP (*(.vectors)) - KEEP (*(.binary_info_header)) - __binary_info_header_end = .; - KEEP (*(.reset)) - /* TODO revisit this now memset/memcpy/float in ROM */ - /* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from - * FLASH ... we will include any thing excluded here in .data below by default */ - *(.init) - - __property_getter_start = .; - *(.property_getter) - __property_getter_end = .; - __property_getset_start = .; - *(.property_getset) - __property_getset_end = .; - - *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*) - *(.fini) - /* Pull all c'tors into .text */ - *crtbegin.o(.ctors) - *crtbegin?.o(.ctors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) - *(SORT(.ctors.*)) - *(.ctors) - /* Followed by destructors */ - *crtbegin.o(.dtors) - *crtbegin?.o(.dtors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) - *(SORT(.dtors.*)) - *(.dtors) - - *(.eh_frame*) - . = ALIGN(4); - } > FLASH_FIRMWARE - - .rodata : { - *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*) - . = ALIGN(4); - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) - . = ALIGN(4); - } > FLASH_FIRMWARE - - .ARM.extab : - { - *(.ARM.extab* .gnu.linkonce.armextab.*) - } > FLASH_FIRMWARE - - __exidx_start = .; - .ARM.exidx : - { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > FLASH_FIRMWARE - __exidx_end = .; - - /* Machine inspectable binary information */ - . = ALIGN(4); - __binary_info_start = .; - .binary_info : - { - KEEP(*(.binary_info.keep.*)) - *(.binary_info.*) - } > FLASH_FIRMWARE - __binary_info_end = .; - . = ALIGN(4); - - /* End of .text-like segments */ - __etext = .; - - .ram_vector_table (COPY): { - *(.ram_vector_table) - } > RAM - - .data : { - __data_start__ = .; - *(vtable) - - *(.time_critical*) - - /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */ - *(.text*) - . = ALIGN(4); - *(.rodata*) - . = ALIGN(4); - - *(.data*) - - . = ALIGN(4); - *(.after_data.*) - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__mutex_array_start = .); - KEEP(*(SORT(.mutex_array.*))) - KEEP(*(.mutex_array)) - PROVIDE_HIDDEN (__mutex_array_end = .); - - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - - . = ALIGN(4); - /* init data */ - PROVIDE_HIDDEN (__init_array_start = .); - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - - . = ALIGN(4); - /* finit data */ - PROVIDE_HIDDEN (__fini_array_start = .); - *(SORT(.fini_array.*)) - *(.fini_array) - PROVIDE_HIDDEN (__fini_array_end = .); - - *(.jcr) - . = ALIGN(4); - /* All data end */ - __data_end__ = .; - } > RAM AT> FLASH_FIRMWARE - - .itcm : - { - . = ALIGN(4); - *(.itcm.*) - - . = ALIGN(4); - } > RAM AT> FLASH_FIRMWARE - _ld_itcm_destination = ADDR(.itcm); - _ld_itcm_flash_copy = LOADADDR(.itcm); - _ld_itcm_size = SIZEOF(.itcm); - - .dtcm_data : - { - . = ALIGN(4); - - *(.dtcm_data.*) - - . = ALIGN(4); - } > RAM AT> FLASH_FIRMWARE - _ld_dtcm_data_destination = ADDR(.dtcm_data); - _ld_dtcm_data_flash_copy = LOADADDR(.dtcm_data); - _ld_dtcm_data_size = SIZEOF(.dtcm_data); - - .dtcm_bss : - { - . = ALIGN(4); - - *(.dtcm_bss.*) - - . = ALIGN(4); - } > RAM AT> RAM - _ld_dtcm_bss_start = ADDR(.dtcm_bss); - _ld_dtcm_bss_size = SIZEOF(.dtcm_bss); - - .uninitialized_data (COPY): { - . = ALIGN(4); - *(.uninitialized_data*) - } > RAM - - /* Start and end symbols must be word-aligned */ - .scratch_x : { - __scratch_x_start__ = .; - *(.scratch_x.*) - . = ALIGN(4); - __scratch_x_end__ = .; - } > SCRATCH_X AT > FLASH_FIRMWARE - __scratch_x_source__ = LOADADDR(.scratch_x); - - .scratch_y : { - __scratch_y_start__ = .; - *(.scratch_y.*) - . = ALIGN(4); - __scratch_y_end__ = .; - } > SCRATCH_Y AT > FLASH_FIRMWARE - __scratch_y_source__ = LOADADDR(.scratch_y); - - .bss : { - . = ALIGN(4); - __bss_start__ = .; - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) - *(COMMON) - . = ALIGN(4); - __bss_end__ = .; - } > RAM - - .heap (COPY): - { - __end__ = .; - end = __end__; - *(.heap*) - __HeapLimit = .; - } > RAM - - /* .stack*_dummy section doesn't contains any symbols. It is only - * used for linker to calculate size of stack sections, and assign - * values to stack symbols later - * - * stack1 section may be empty/missing if platform_launch_core1 is not used */ - - /* by default we put core 0 stack at the end of scratch Y, so that if core 1 - * stack is not used then all of SCRATCH_X is free. - */ - .stack1_dummy (COPY): - { - *(.stack1*) - } > SCRATCH_X - .stack_dummy (COPY): - { - *(.stack*) - } > SCRATCH_Y - - .flash_end : { - __flash_binary_end = .; - } > FLASH_FIRMWARE - - /* stack limit is poorly named, but historically is maximum heap ptr */ - __StackLimit = ORIGIN(RAM) + LENGTH(RAM); - __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); - __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); - __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); - __StackBottom = __StackTop - SIZEOF(.stack_dummy); - PROVIDE(__stack = __StackTop); - - /* Check if data + heap + stack exceeds RAM limit */ - ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") - - ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary") - /* todo assert on extra code */ -} +firmware_size = 1532k; diff --git a/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk b/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk index a050391505..f36f98b7c5 100644 --- a/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk +++ b/ports/raspberrypi/boards/raspberry_pi_pico_w/mpconfigboard.mk @@ -19,6 +19,8 @@ CIRCUITPY_MDNS = 1 CIRCUITPY_SOCKETPOOL = 1 CIRCUITPY_WIFI = 1 +CIRCUITPY_PICODVI = 1 + CFLAGS += -DCYW43_PIN_WL_HOST_WAKE=24 -DCYW43_PIN_WL_REG_ON=23 -DCYW43_WL_GPIO_COUNT=3 -DCYW43_WL_GPIO_LED_PIN=0 # Must be accompanied by a linker script change CFLAGS += -DCIRCUITPY_FIRMWARE_SIZE='(1536 * 1024)' diff --git a/ports/raspberrypi/common-hal/picodvi/Framebuffer.c b/ports/raspberrypi/common-hal/picodvi/Framebuffer.c new file mode 100644 index 0000000000..20f447a824 --- /dev/null +++ b/ports/raspberrypi/common-hal/picodvi/Framebuffer.c @@ -0,0 +1,419 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023 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 "bindings/picodvi/Framebuffer.h" + +#include "py/gc.h" +#include "py/runtime.h" +#include "shared-bindings/time/__init__.h" +#include "common-hal/pwmio/PWMOut.h" +#include "common-hal/rp2pio/StateMachine.h" + +#include "src/common/pico_stdlib/include/pico/stdlib.h" +#include "src/rp2040/hardware_structs/include/hardware/structs/mpu.h" +#include "src/rp2_common/cmsis/stub/CMSIS/Device/RaspberryPi/RP2040/Include/RP2040.h" +#include "src/rp2_common/hardware_pwm/include/hardware/pwm.h" +#include "src/rp2_common/hardware_vreg/include/hardware/vreg.h" +#include "src/rp2_common/pico_multicore/include/pico/multicore.h" + +#include "lib/PicoDVI/software/libdvi/tmds_encode.h" + +picodvi_framebuffer_obj_t *active_picodvi = NULL; + +STATIC PIO pio_instances[2] = {pio0, pio1}; + +static void __not_in_flash_func(core1_main)(void) { + // The MPU is reset before this starts. + + picodvi_framebuffer_obj_t *self = active_picodvi; + dvi_register_irqs_this_core(&self->dvi, DMA_IRQ_1); + + while (queue_is_empty(&self->dvi.q_colour_valid)) { + __wfe(); + } + dvi_start(&self->dvi); + + // Turn off flash access. After this, it will hard fault. Better than messing + // up CIRCUITPY. + MPU->CTRL = MPU_CTRL_PRIVDEFENA_Msk | MPU_CTRL_ENABLE_Msk; + MPU->RNR = 6; // 7 is used by pico-sdk stack protection. + MPU->RBAR = XIP_MAIN_BASE | MPU_RBAR_VALID_Msk; + MPU->RASR = MPU_RASR_XN_Msk | // Set execute never and everything else is restricted. + MPU_RASR_ENABLE_Msk | + (0x1b << MPU_RASR_SIZE_Pos); // Size is 0x10000000 which masks up to SRAM region. + MPU->RNR = 7; + + uint y = 0; + while (1) { + uint32_t *scanbuf; + queue_remove_blocking_u32(&self->dvi.q_colour_valid, &scanbuf); + + uint32_t *tmdsbuf; + queue_remove_blocking_u32(&self->dvi.q_tmds_free, &tmdsbuf); + // Check to see if the tmds memory has moved and replace this tmdsbuf + // the corresponding on at a new location. + size_t old_fb = tmdsbuf[self->tmdsbuf_size - 1]; + if (old_fb != (uint32_t)self->framebuffer) { + size_t index = ((uint32_t)(tmdsbuf - old_fb)) / self->tmdsbuf_size; + // Check our index and hang if it is out of range. Hang is ok since this is core 1. + // Better than writing the wrong memory that is shared with CP. + while (index >= DVI_N_TMDS_BUFFERS) { + } + tmdsbuf = self->framebuffer + self->framebuffer_len + (self->tmdsbuf_size * index); + tmdsbuf[self->tmdsbuf_size - 1] = (uint32_t)self->framebuffer; + } + uint pixwidth = self->dvi.timing->h_active_pixels; + uint words_per_channel = pixwidth / DVI_SYMBOLS_PER_WORD; + if (self->color_depth == 8) { + tmds_encode_data_channel_8bpp(scanbuf, tmdsbuf + 0 * words_per_channel, pixwidth / 2, DVI_8BPP_BLUE_MSB, DVI_8BPP_BLUE_LSB); + tmds_encode_data_channel_8bpp(scanbuf, tmdsbuf + 1 * words_per_channel, pixwidth / 2, DVI_8BPP_GREEN_MSB, DVI_8BPP_GREEN_LSB); + tmds_encode_data_channel_8bpp(scanbuf, tmdsbuf + 2 * words_per_channel, pixwidth / 2, DVI_8BPP_RED_MSB, DVI_8BPP_RED_LSB); + } else if (self->color_depth == 16) { + tmds_encode_data_channel_16bpp(scanbuf, tmdsbuf + 0 * words_per_channel, pixwidth / 2, DVI_16BPP_BLUE_MSB, DVI_16BPP_BLUE_LSB); + tmds_encode_data_channel_16bpp(scanbuf, tmdsbuf + 1 * words_per_channel, pixwidth / 2, DVI_16BPP_GREEN_MSB, DVI_16BPP_GREEN_LSB); + tmds_encode_data_channel_16bpp(scanbuf, tmdsbuf + 2 * words_per_channel, pixwidth / 2, DVI_16BPP_RED_MSB, DVI_16BPP_RED_LSB); + } else if (self->color_depth == 1) { + tmds_encode_1bpp(scanbuf, tmdsbuf, pixwidth); + } else if (self->color_depth == 2) { + tmds_encode_2bpp(scanbuf, tmdsbuf, pixwidth); + } + queue_add_blocking_u32(&self->dvi.q_tmds_valid, &tmdsbuf); + + queue_add_blocking_u32(&self->dvi.q_colour_free, &scanbuf); + ++y; + if (y == self->dvi.timing->v_active_lines) { + y = 0; + } + } + __builtin_unreachable(); +} + +static void __not_in_flash_func(core1_scanline_callback)(void) { + picodvi_framebuffer_obj_t *self = active_picodvi; + uint32_t *next_scanline_buf; + next_scanline_buf = self->framebuffer + (self->pitch * self->next_scanline); + queue_add_blocking_u32(&self->dvi.q_colour_valid, &next_scanline_buf); + + // Remove any buffers that were sent back to us. + while (queue_try_remove_u32(&self->dvi.q_colour_free, &next_scanline_buf)) { + } + self->next_scanline += 1; + if (self->next_scanline >= self->height) { + self->next_scanline = 0; + // Update the framebuffer pointer in case it moved. + self->framebuffer = self->allocation->ptr; + } +} + +extern uint8_t dvi_vertical_repeat; +extern bool dvi_monochrome_tmds; + +void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self, + mp_uint_t width, mp_uint_t height, + const mcu_pin_obj_t *clk_dp, const mcu_pin_obj_t *clk_dn, + const mcu_pin_obj_t *red_dp, const mcu_pin_obj_t *red_dn, + const mcu_pin_obj_t *green_dp, const mcu_pin_obj_t *green_dn, + const mcu_pin_obj_t *blue_dp, const mcu_pin_obj_t *blue_dn, + mp_uint_t color_depth) { + + const struct dvi_timing *timing = NULL; + if (width == 640 && height == 480) { + timing = &dvi_timing_640x480p_60hz; + } else if (width == 800 && height == 480) { + timing = &dvi_timing_800x480p_60hz; + } else { + if (height == 480) { + mp_raise_ValueError_varg(translate("%q must be %d"), MP_QSTR_width, 480); + } + mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_height); + } + + if (active_picodvi != NULL) { + mp_raise_msg_varg(&mp_type_RuntimeError, translate("%q in use"), MP_QSTR_picodvi); + } + + bool invert_diffpairs = clk_dn->number < clk_dp->number; + int8_t other_pins[4]; + int8_t *a; + int8_t *b; + if (invert_diffpairs) { + a = other_pins; + b = self->pin_pair; + } else { + a = self->pin_pair; + b = other_pins; + } + a[0] = clk_dp->number; + a[1] = red_dp->number; + a[2] = green_dp->number; + a[3] = blue_dp->number; + b[0] = clk_dn->number; + b[1] = red_dn->number; + b[2] = green_dn->number; + b[3] = blue_dn->number; + qstr pin_names[4] = {MP_QSTR_clk_dp, MP_QSTR_red_dp, MP_QSTR_green_dp, MP_QSTR_blue_dp}; + for (size_t i = 0; i < 4; i++) { + if (other_pins[i] - self->pin_pair[i] != 1) { + raise_ValueError_invalid_pin_name(pin_names[i]); + } + } + + uint8_t slice = pwm_gpio_to_slice_num(self->pin_pair[0]); + + + pio_program_t program_struct = { + .instructions = NULL, + .length = 2, + .origin = -1 + }; + size_t pio_index = NUM_PIOS; + int free_state_machines[4]; // We may find all four free. We only use the first three. + for (size_t i = 0; i < NUM_PIOS; i++) { + PIO pio = pio_instances[i]; + uint8_t free_count = 0; + for (size_t sm = 0; sm < NUM_PIO_STATE_MACHINES; sm++) { + if (!pio_sm_is_claimed(pio, sm)) { + free_state_machines[free_count] = sm; + free_count++; + } + } + if (free_count >= 3 && pio_can_add_program(pio, &program_struct)) { + pio_index = i; + break; + } + } + + if (pio_index == NUM_PIOS) { + mp_raise_RuntimeError(translate("All state machines in use")); + } + + self->width = width; + self->height = height; + + size_t tmds_bufs_per_scanline; + if (color_depth >= 8) { + dvi_vertical_repeat = 2; + dvi_monochrome_tmds = false; + self->width /= 2; + self->height /= 2; + tmds_bufs_per_scanline = 3; + } else { + dvi_vertical_repeat = 1; + dvi_monochrome_tmds = true; + // One tmds buffer is used for all three color outputs. + tmds_bufs_per_scanline = 1; + } + self->pitch = (self->width * color_depth) / 8; + // Align each row to words. + if (self->pitch % sizeof(uint32_t) != 0) { + self->pitch += sizeof(uint32_t) - (self->pitch % sizeof(uint32_t)); + } + self->pitch /= sizeof(uint32_t); + size_t framebuffer_size = self->pitch * self->height; + // use width here because it hasn't been downsized for the frame buffer + self->tmdsbuf_size = tmds_bufs_per_scanline * width / DVI_SYMBOLS_PER_WORD + 1; + size_t total_allocation_size = sizeof(uint32_t) * (framebuffer_size + DVI_N_TMDS_BUFFERS * self->tmdsbuf_size); + self->allocation = allocate_memory(total_allocation_size, false, true); + if (self->allocation == NULL) { + m_malloc_fail(total_allocation_size); + return; + } + + // Do the pwmio check last because it claims the pwm slice. + if (!pwmio_claim_slice_ab_channels(slice)) { + mp_raise_ValueError(translate("All timers for this pin are in use")); + } + self->pwm_slice = slice; + + pwmout_never_reset(self->pwm_slice, 0); + pwmout_never_reset(self->pwm_slice, 1); + + for (size_t i = 0; i < 4; i++) { + never_reset_pin_number(self->pin_pair[i]); + never_reset_pin_number(self->pin_pair[i] + 1); + } + + for (size_t i = 0; i < 3; i++) { + rp2pio_statemachine_never_reset(pio_instances[pio_index], free_state_machines[i]); + } + + // For the output. + user_irq_claim(DMA_IRQ_1); + self->framebuffer_len = framebuffer_size; + self->framebuffer = self->allocation->ptr; + self->color_depth = color_depth; + + self->dvi.timing = timing; + self->dvi.ser_cfg.pio = pio_instances[pio_index]; + self->dvi.ser_cfg.sm_tmds[0] = free_state_machines[0]; + self->dvi.ser_cfg.sm_tmds[1] = free_state_machines[1]; + self->dvi.ser_cfg.sm_tmds[2] = free_state_machines[2]; + self->dvi.ser_cfg.pins_clk = self->pin_pair[0]; + self->dvi.ser_cfg.pins_tmds[0] = self->pin_pair[1]; + self->dvi.ser_cfg.pins_tmds[1] = self->pin_pair[2]; + self->dvi.ser_cfg.pins_tmds[2] = self->pin_pair[3]; + self->dvi.ser_cfg.invert_diffpairs = invert_diffpairs; + self->dvi.scanline_callback = core1_scanline_callback; + + vreg_set_voltage(VREG_VOLTAGE_1_20); + common_hal_time_delay_ms(10); + set_sys_clock_khz(timing->bit_clk_khz, true); // Run at TMDS bit clock + self->tmds_lock = next_striped_spin_lock_num(); + self->colour_lock = next_striped_spin_lock_num(); + dvi_init(&self->dvi, self->tmds_lock, self->colour_lock); + + // Load up the TMDS buffers. + for (int i = 0; i < DVI_N_TMDS_BUFFERS; ++i) { + uint32_t *tmdsbuf = self->framebuffer + (self->framebuffer_len + self->tmdsbuf_size * i); + // Use the last word in the buffer to track its original root. That way + // we can detect when framebuffer is moved. + tmdsbuf[self->tmdsbuf_size - 1] = (uint32_t)self->framebuffer; + queue_add_blocking_u32(&self->dvi.q_tmds_free, &tmdsbuf); + } + + active_picodvi = self; + + // Core 1 will wait until it sees the first colour buffer, then start up the + // DVI signalling. + multicore_launch_core1(core1_main); + + self->next_scanline = 0; + uint32_t *next_scanline_buf = self->framebuffer + (self->pitch * self->next_scanline); + queue_add_blocking_u32(&self->dvi.q_colour_valid, &next_scanline_buf); + self->next_scanline += 1; + next_scanline_buf = self->framebuffer + (self->pitch * self->next_scanline); + queue_add_blocking_u32(&self->dvi.q_colour_valid, &next_scanline_buf); + self->next_scanline += 1; + + // Wait for the second core to run dvi_start because it is in flash. Once it is done, + // it'll pull from this queue. Not waiting may lead to us reading flash when this core + // doesn't want us to. + while (queue_get_level(&self->dvi.q_colour_valid) == 2) { + } +} + +STATIC void _turn_off_dma(uint8_t channel) { + dma_channel_config c = dma_channel_get_default_config(channel); + channel_config_set_enable(&c, false); + dma_channel_set_config(channel, &c, false /* trigger */); + + if (dma_channel_is_busy(channel)) { + dma_channel_abort(channel); + } + dma_channel_set_irq1_enabled(channel, false); + dma_channel_unclaim(channel); +} + +void common_hal_picodvi_framebuffer_deinit(picodvi_framebuffer_obj_t *self) { + if (common_hal_picodvi_framebuffer_deinited(self)) { + return; + } + // Stop the other core and free resources. + + // Grab the locks before shutting down the other core so we don't leave the + // locks locked. + spin_lock_t *tmds_lock = spin_lock_instance(self->tmds_lock); + spin_lock_t *colour_lock = spin_lock_instance(self->colour_lock); + uint32_t tmds_save = spin_lock_blocking(tmds_lock); + uint32_t colour_save = spin_lock_blocking(colour_lock); + multicore_reset_core1(); + spin_unlock(colour_lock, colour_save); + spin_unlock(tmds_lock, tmds_save); + + for (size_t i = 0; i < 4; i++) { + reset_pin_number(self->pin_pair[i]); + reset_pin_number(self->pin_pair[i] + 1); + } + + for (int i = 0; i < N_TMDS_LANES; ++i) { + // Turn off data first because it chains to the ctrl DMA. + _turn_off_dma(self->dvi.dma_cfg[i].chan_data); + _turn_off_dma(self->dvi.dma_cfg[i].chan_ctrl); + } + + pwm_set_enabled(self->pwm_slice, false); + pwmout_free(self->pwm_slice, 0); + pwmout_free(self->pwm_slice, 1); + + pio_program_t program_struct = { + .length = 2 + }; + PIO pio = self->dvi.ser_cfg.pio; + for (size_t i = 0; i < 3; i++) { + int sm = self->dvi.ser_cfg.sm_tmds[i]; + pio_sm_set_enabled(pio, sm, false); + pio_sm_unclaim(pio, sm); + rp2pio_statemachine_reset_ok(pio, sm); + } + pio_remove_program(pio, &program_struct, self->dvi.ser_cfg.prog_offs); + + if (user_irq_is_claimed(DMA_IRQ_1)) { + user_irq_unclaim(DMA_IRQ_1); + } + + active_picodvi = NULL; + + free_memory(self->allocation); + self->framebuffer = NULL; + + self->base.type = &mp_type_NoneType; +} + +bool common_hal_picodvi_framebuffer_deinited(picodvi_framebuffer_obj_t *self) { + return self->framebuffer == NULL; +} + +void common_hal_picodvi_framebuffer_refresh(picodvi_framebuffer_obj_t *self) { +} + +int common_hal_picodvi_framebuffer_get_width(picodvi_framebuffer_obj_t *self) { + return self->width; +} + +int common_hal_picodvi_framebuffer_get_height(picodvi_framebuffer_obj_t *self) { + return self->height; +} + +int common_hal_picodvi_framebuffer_get_color_depth(picodvi_framebuffer_obj_t *self) { + return self->color_depth; +} + +mp_int_t common_hal_picodvi_framebuffer_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { + picodvi_framebuffer_obj_t *self = (picodvi_framebuffer_obj_t *)self_in; + bufinfo->buf = self->framebuffer; + char typecode = 'B'; + if (self->color_depth == 16) { + typecode = 'H'; + } + bufinfo->typecode = typecode; + bufinfo->len = self->framebuffer_len * sizeof(uint32_t); + return 0; +} + +int common_hal_picodvi_framebuffer_get_row_stride(picodvi_framebuffer_obj_t *self) { + // Pitch is in words but row stride is expected as bytes. + return self->pitch * sizeof(uint32_t); +} diff --git a/ports/raspberrypi/common-hal/picodvi/Framebuffer.h b/ports/raspberrypi/common-hal/picodvi/Framebuffer.h new file mode 100644 index 0000000000..f5d7df8f9a --- /dev/null +++ b/ports/raspberrypi/common-hal/picodvi/Framebuffer.h @@ -0,0 +1,51 @@ +#pragma once + +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2023 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "py/obj.h" + +#include "supervisor/memory.h" + +#include "lib/PicoDVI/software/libdvi/dvi.h" + +typedef struct { + mp_obj_base_t base; + supervisor_allocation *allocation; + uint32_t *framebuffer; + size_t framebuffer_len; // in words + size_t tmdsbuf_size; // in words + struct dvi_inst dvi; + mp_uint_t width; + mp_uint_t height; + uint tmds_lock; + uint colour_lock; + uint16_t next_scanline; + uint16_t pitch; // Number of words between rows. (May be more than a width's worth.) + uint8_t color_depth; + uint8_t pwm_slice; + int8_t pin_pair[4]; +} picodvi_framebuffer_obj_t; diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c index e9cb3d34bb..9034b64242 100644 --- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c +++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c @@ -218,9 +218,7 @@ bool rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self, _current_program_len[i][j] == program_len) { program_offset = _current_program_offset[i][j]; } - int temp_claim = pio_claim_unused_sm(pio, false); - if (temp_claim >= 0) { - pio_sm_unclaim(pio, temp_claim); + if (!pio_sm_is_claimed(pio, j)) { free_count++; } } @@ -634,6 +632,16 @@ void common_hal_rp2pio_statemachine_set_frequency(rp2pio_statemachine_obj_t *sel pio_sm_clkdiv_restart(self->pio, self->state_machine); } +void rp2pio_statemachine_reset_ok(PIO pio, int sm) { + uint8_t pio_index = pio_get_index(pio); + _never_reset[pio_index][sm] = false; +} + +void rp2pio_statemachine_never_reset(PIO pio, int sm) { + uint8_t pio_index = pio_get_index(pio); + _never_reset[pio_index][sm] = true; +} + void rp2pio_statemachine_deinit(rp2pio_statemachine_obj_t *self, bool leave_pins) { common_hal_rp2pio_statemachine_stop(self); (void)common_hal_rp2pio_statemachine_stop_background_write(self); @@ -654,9 +662,7 @@ void common_hal_rp2pio_statemachine_deinit(rp2pio_statemachine_obj_t *self) { } void common_hal_rp2pio_statemachine_never_reset(rp2pio_statemachine_obj_t *self) { - uint8_t sm = self->state_machine; - uint8_t pio_index = pio_get_index(self->pio); - _never_reset[pio_index][sm] = true; + rp2pio_statemachine_never_reset(self->pio, self->state_machine); // TODO: never reset all the pins } diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.h b/ports/raspberrypi/common-hal/rp2pio/StateMachine.h index 03dadc53b3..71f85b1f11 100644 --- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.h +++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.h @@ -95,6 +95,9 @@ uint8_t rp2pio_statemachine_program_offset(rp2pio_statemachine_obj_t *self); void rp2pio_statemachine_deinit(rp2pio_statemachine_obj_t *self, bool leave_pins); void rp2pio_statemachine_dma_complete(rp2pio_statemachine_obj_t *self, int channel); +void rp2pio_statemachine_reset_ok(PIO pio, int sm); +void rp2pio_statemachine_never_reset(PIO pio, int sm); + extern const mp_obj_type_t rp2pio_statemachine_type; #endif // MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_RP2PIO_STATEMACHINE_H diff --git a/ports/raspberrypi/lib/PicoDVI b/ports/raspberrypi/lib/PicoDVI new file mode 160000 index 0000000000..23a3a3bf18 --- /dev/null +++ b/ports/raspberrypi/lib/PicoDVI @@ -0,0 +1 @@ +Subproject commit 23a3a3bf18820f2abd78e8a9c05b45c01b5a3810 diff --git a/ports/raspberrypi/link.ld b/ports/raspberrypi/link.ld index 982c5e3a0c..1e758f61bf 100644 --- a/ports/raspberrypi/link.ld +++ b/ports/raspberrypi/link.ld @@ -21,13 +21,16 @@ __stack (== StackTop) */ +firmware_size = DEFINED(firmware_size) ? firmware_size : 1020K ; + MEMORY { - FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 1020k + FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = firmware_size /* Followed by: 4kB of NVRAM and at least 1024kB of CIRCUITPY */ RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k - SCRATCH_X (rwx) : ORIGIN = 0x20040000, LENGTH = 4k - SCRATCH_Y (rwx) : ORIGIN = 0x20041000, LENGTH = 4k + SCRATCH_Y (rwx) : ORIGIN = 0x20040000, LENGTH = 4k + /* X is used by core 1 so we put it last. */ + SCRATCH_X (rwx) : ORIGIN = 0x20041000, LENGTH = 4k } ENTRY(_entry_point) @@ -77,7 +80,7 @@ SECTIONS *(.property_getset) __property_getset_end = .; - *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*) + *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a: *interp.o *divider.o) .text*) *(.fini) /* Pull all c'tors into .text */ *crtbegin.o(.ctors) @@ -137,7 +140,7 @@ SECTIONS __data_start__ = .; *(vtable) - *(.time_critical*) + *(EXCLUDE_FILE(*tmds_encode.o) .time_critical*) /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */ *(.text*) @@ -222,23 +225,6 @@ SECTIONS *(.uninitialized_data*) } > RAM - /* Start and end symbols must be word-aligned */ - .scratch_x : { - __scratch_x_start__ = .; - *(.scratch_x.*) - . = ALIGN(4); - __scratch_x_end__ = .; - } > SCRATCH_X AT > FLASH_FIRMWARE - __scratch_x_source__ = LOADADDR(.scratch_x); - - .scratch_y : { - __scratch_y_start__ = .; - *(.scratch_y.*) - . = ALIGN(4); - __scratch_y_end__ = .; - } > SCRATCH_Y AT > FLASH_FIRMWARE - __scratch_y_source__ = LOADADDR(.scratch_y); - .bss : { . = ALIGN(4); __bss_start__ = .; @@ -252,10 +238,30 @@ SECTIONS { __end__ = .; end = __end__; + _ld_cp_dynamic_mem_start = .; *(.heap*) __HeapLimit = .; } > RAM + /* Start and end symbols must be word-aligned */ + .scratch_x : { + __scratch_x_start__ = .; + *(.scratch_x.*) + *tmds_encode.o (.time_critical*) + . = ALIGN(4); + __scratch_x_end__ = .; + } > SCRATCH_X AT > FLASH_FIRMWARE + __scratch_x_source__ = LOADADDR(.scratch_x); + + .scratch_y : { + __scratch_y_start__ = .; + /* Don't put anything into scratch y because CircuitPython manages it and uses it for core 0 stack. + /* *(.scratch_y.*) */ + . = ALIGN(4); + __scratch_y_end__ = .; + } > SCRATCH_Y AT > FLASH_FIRMWARE + __scratch_y_source__ = LOADADDR(.scratch_y); + /* .stack*_dummy section doesn't contains any symbols. It is only * used for linker to calculate size of stack sections, and assign * values to stack symbols later @@ -269,6 +275,7 @@ SECTIONS { *(.stack1*) } > SCRATCH_X + .stack_dummy (COPY): { *(.stack*) @@ -282,6 +289,7 @@ SECTIONS __StackLimit = ORIGIN(RAM) + LENGTH(RAM); __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); + _ld_cp_dynamic_mem_end = __StackTop; __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); __StackBottom = __StackTop - SIZEOF(.stack_dummy); PROVIDE(__stack = __StackTop); diff --git a/ports/raspberrypi/mpconfigport.mk b/ports/raspberrypi/mpconfigport.mk index 671d4669bf..ab60207b0d 100644 --- a/ports/raspberrypi/mpconfigport.mk +++ b/ports/raspberrypi/mpconfigport.mk @@ -39,7 +39,7 @@ CIRCUITPY_AUDIOBUSIO ?= 1 CIRCUITPY_AUDIOCORE ?= 1 CIRCUITPY_AUDIOPWMIO ?= 1 -CIRCUITPY_AUDIOMIXER = 1 +CIRCUITPY_AUDIOMIXER ?= 1 INTERNAL_LIBM = 1 diff --git a/ports/raspberrypi/sdk_config/pico/config_autogen.h b/ports/raspberrypi/sdk_config/pico/config_autogen.h index ee99b1c609..85a8cccb6f 100644 --- a/ports/raspberrypi/sdk_config/pico/config_autogen.h +++ b/ports/raspberrypi/sdk_config/pico/config_autogen.h @@ -3,6 +3,7 @@ #include "pico-sdk-configboard.h" // alphabetized +#define LIB_CMSIS_CORE (1) #define LIB_PICO_BINARY_INFO (0) #define LIB_PICO_PRINTF_NONE (0) #define LIB_PICO_PRINTF_PICO (0) @@ -23,4 +24,9 @@ #define PICO_STDIO_IGNORE_NESTED_STDOUT (0) #define PICO_USE_CRT_PRINTF (0) #define PICO_USE_OPTIMISTIC_SBRK (0) +// Stack guards cause a hard fault when 32 bytes around the stack bottom are +// accessed. These backtraces aren't always helpful and this conflicts with our +// own stack checking. #define PICO_USE_STACK_GUARDS (0) + +#include "include/cmsis/rename_exceptions.h" diff --git a/ports/raspberrypi/supervisor/port.c b/ports/raspberrypi/supervisor/port.c index f3da71cbd7..2ee3a1ee98 100644 --- a/ports/raspberrypi/supervisor/port.c +++ b/ports/raspberrypi/supervisor/port.c @@ -228,14 +228,14 @@ bool port_has_fixed_stack(void) { } // From the linker script -extern uint32_t __HeapLimit; -extern uint32_t __StackTop; +extern uint32_t _ld_cp_dynamic_mem_start; +extern uint32_t _ld_cp_dynamic_mem_end; uint32_t *port_stack_get_limit(void) { - return &__HeapLimit; + return &_ld_cp_dynamic_mem_start; } uint32_t *port_stack_get_top(void) { - return &__StackTop; + return &_ld_cp_dynamic_mem_end; } uint32_t *port_heap_get_bottom(void) { @@ -246,13 +246,14 @@ uint32_t *port_heap_get_top(void) { return port_stack_get_top(); } -extern uint32_t __scratch_x_start__; void port_set_saved_word(uint32_t value) { - __scratch_x_start__ = value; + // Store in a watchdog scratch register instead of RAM. 4-7 are used by the + // sdk. 0 is used by alarm. 1-3 are free. + watchdog_hw->scratch[1] = value; } uint32_t port_get_saved_word(void) { - return __scratch_x_start__; + return watchdog_hw->scratch[1]; } static volatile bool ticks_enabled; @@ -305,14 +306,12 @@ void port_idle_until_interrupt(void) { * \brief Default interrupt handler for unused IRQs. */ extern void HardFault_Handler(void); // provide a prototype to avoid a missing-prototypes diagnostic -__attribute__((used)) void HardFault_Handler(void) { - #ifdef ENABLE_MICRO_TRACE_BUFFER - // Turn off the micro trace buffer so we don't fill it up in the infinite - // loop below. - REG_MTB_MASTER = 0x00000000 + 6; - #endif - - reset_into_safe_mode(SAFE_MODE_HARD_FAULT); +__attribute__((used)) void __not_in_flash_func(HardFault_Handler)(void) { + // Only safe mode from core 0 which is running CircuitPython. Core 1 faulting + // should not be fatal to CP. (Fingers crossed.) + if (get_core_num() == 0) { + reset_into_safe_mode(SAFE_MODE_HARD_FAULT); + } while (true) { asm ("nop;"); } diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index fb5d745ebb..d9af56356a 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -278,14 +278,8 @@ endif ifeq ($(CIRCUITPY_PIXELMAP),1) SRC_PATTERNS += _pixelmap/% endif -ifeq ($(CIRCUITPY_QRIO),1) -SRC_PATTERNS += qrio/% -endif -ifeq ($(CIRCUITPY_RAINBOWIO),1) -SRC_PATTERNS += rainbowio/% -endif -ifeq ($(CIRCUITPY_RGBMATRIX),1) -SRC_PATTERNS += rgbmatrix/% +ifeq ($(CIRCUITPY_PICODVI),1) +SRC_PATTERNS += picodvi/% endif ifeq ($(CIRCUITPY_PS2IO),1) SRC_PATTERNS += ps2io/% @@ -296,9 +290,18 @@ endif ifeq ($(CIRCUITPY_PWMIO),1) SRC_PATTERNS += pwmio/% endif +ifeq ($(CIRCUITPY_QRIO),1) +SRC_PATTERNS += qrio/% +endif +ifeq ($(CIRCUITPY_RAINBOWIO),1) +SRC_PATTERNS += rainbowio/% +endif ifeq ($(CIRCUITPY_RANDOM),1) SRC_PATTERNS += random/% endif +ifeq ($(CIRCUITPY_RGBMATRIX),1) +SRC_PATTERNS += rgbmatrix/% +endif ifeq ($(CIRCUITPY_RP2PIO),1) SRC_PATTERNS += rp2pio/% endif diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 0aec2ebe74..639fae9bbc 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -339,6 +339,11 @@ CFLAGS += -DCIRCUITPY_OS=$(CIRCUITPY_OS) CIRCUITPY_PEW ?= 0 CFLAGS += -DCIRCUITPY_PEW=$(CIRCUITPY_PEW) +# CIRCUITPY_PICODVI is handled in the raspberrypi tree. +# Only for RP2 chips. Assume not a raspberrypi build. +CIRCUITPY_PICODVI ?= 0 +CFLAGS += -DCIRCUITPY_PICODVI=$(CIRCUITPY_PICODVI) + CIRCUITPY_PIXELBUF ?= $(CIRCUITPY_FULL_BUILD) CFLAGS += -DCIRCUITPY_PIXELBUF=$(CIRCUITPY_PIXELBUF) diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index 12aee30b19..c4dc345cb8 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -151,15 +151,27 @@ STATIC mp_obj_t bitmap_subscr(mp_obj_t self_in, mp_obj_t index_obj, mp_obj_t val uint16_t x = 0; uint16_t y = 0; if (mp_obj_is_small_int(index_obj)) { - mp_int_t i = mp_arg_validate_int_min(MP_OBJ_SMALL_INT_VALUE(index_obj), 0, MP_QSTR_index); - uint16_t width = common_hal_displayio_bitmap_get_width(self); - x = i % width; - y = i / width; + mp_int_t i = MP_OBJ_SMALL_INT_VALUE(index_obj); + int total_length = self->width * self->height; + if (i < 0 || i >= total_length) { + mp_raise_IndexError_varg(translate("%q must be %d-%d"), MP_QSTR_index, 0, total_length - 1); + } + + x = i % self->width; + y = i / self->width; } else { mp_obj_t *items; mp_obj_get_array_fixed_n(index_obj, 2, &items); - x = mp_arg_validate_int_range(mp_obj_get_int(items[0]), 0, self->width - 1, MP_QSTR_x); - y = mp_arg_validate_int_range(mp_obj_get_int(items[1]), 0, self->height - 1, MP_QSTR_y); + mp_int_t x_in = mp_obj_get_int(items[0]); + if (x_in < 0 || x_in >= self->width) { + mp_raise_IndexError_varg(translate("%q must be %d-%d"), MP_QSTR_x, 0, self->width - 1); + } + mp_int_t y_in = mp_obj_get_int(items[1]); + if (y_in < 0 || y_in >= self->height) { + mp_raise_IndexError_varg(translate("%q must be %d-%d"), MP_QSTR_y, 0, self->height - 1); + } + x = x_in; + y = y_in; } if (value_obj == MP_OBJ_SENTINEL) { diff --git a/shared-module/displayio/ColorConverter.c b/shared-module/displayio/ColorConverter.c index 7064569e2d..112f7f9ad1 100644 --- a/shared-module/displayio/ColorConverter.c +++ b/shared-module/displayio/ColorConverter.c @@ -55,6 +55,13 @@ uint16_t displayio_colorconverter_compute_rgb565(uint32_t color_rgb888) { return r5 << 11 | g6 << 5 | b5; } +uint8_t displayio_colorconverter_compute_rgb332(uint32_t color_rgb888) { + uint32_t r3 = (color_rgb888 >> 21); + uint32_t g3 = (color_rgb888 >> 13) & 0x7; + uint32_t b2 = (color_rgb888 >> 6) & 0x3; + return r3 << 5 | g3 << 2 | b2; +} + uint8_t displayio_colorconverter_compute_rgbd(uint32_t color_rgb888) { uint32_t r1 = (color_rgb888 >> 23) & 0x1; uint32_t g1 = (color_rgb888 >> 15) & 0x1; @@ -309,6 +316,11 @@ void displayio_convert_color(const _displayio_colorspace_t *colorspace, bool dit output_color->pixel = pixel; output_color->opaque = true; return; + } else if (colorspace->depth == 8 && !colorspace->grayscale) { + uint8_t packed = displayio_colorconverter_compute_rgb332(pixel); + output_color->pixel = packed; + output_color->opaque = true; + return; } else if (colorspace->depth == 4) { uint8_t packed; if (colorspace->sevencolor) { diff --git a/shared-module/displayio/ColorConverter.h b/shared-module/displayio/ColorConverter.h index c1e46035ca..7ac5062ff3 100644 --- a/shared-module/displayio/ColorConverter.h +++ b/shared-module/displayio/ColorConverter.h @@ -57,6 +57,7 @@ uint32_t displayio_colorconverter_dither_noise_2(uint32_t x, uint32_t y); void displayio_convert_color(const _displayio_colorspace_t *colorspace, bool dither, const displayio_input_pixel_t *input_pixel, displayio_output_pixel_t *output_color); uint16_t displayio_colorconverter_compute_rgb565(uint32_t color_rgb888); +uint8_t displayio_colorconverter_compute_rgb332(uint32_t color_rgb888); uint8_t displayio_colorconverter_compute_rgbd(uint32_t color_rgb888); uint8_t displayio_colorconverter_compute_luma(uint32_t color_rgb888); uint8_t displayio_colorconverter_compute_chroma(uint32_t color_rgb888); diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index 87962dfc60..2dd0cff8b8 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -152,6 +152,10 @@ void common_hal_displayio_release_displays(void) { } else if (displays[i].bus_base.type == &videocore_framebuffer_type) { common_hal_videocore_framebuffer_deinit(&displays[i].videocore); #endif + #if CIRCUITPY_PICODVI + } else if (displays[i].bus_base.type == &picodvi_framebuffer_type) { + common_hal_picodvi_framebuffer_deinit(&displays[i].picodvi); + #endif } displays[i].fourwire_bus.base.type = &mp_type_NoneType; } @@ -266,6 +270,13 @@ void reset_displays(void) { // The framebuffer is allocated outside of the heap so it doesn't // need to be moved. #endif + #if CIRCUITPY_PICODVI + } else if (displays[i].bus_base.type == &picodvi_framebuffer_type) { + picodvi_framebuffer_obj_t *vc = &displays[i].picodvi; + if (!any_display_uses_this_framebuffer(&vc->base)) { + common_hal_picodvi_framebuffer_deinit(vc); + } + #endif } else { // Not an active display bus. continue; diff --git a/shared-module/displayio/__init__.h b/shared-module/displayio/__init__.h index c1954b146c..b450cb711d 100644 --- a/shared-module/displayio/__init__.h +++ b/shared-module/displayio/__init__.h @@ -47,9 +47,13 @@ #if CIRCUITPY_SHARPDISPLAY #include "shared-module/sharpdisplay/SharpMemoryFramebuffer.h" #endif +// Port unique frame buffers. #if CIRCUITPY_VIDEOCORE #include "bindings/videocore/Framebuffer.h" #endif +#if CIRCUITPY_PICODVI +#include "bindings/picodvi/Framebuffer.h" +#endif typedef struct { union { @@ -71,6 +75,9 @@ typedef struct { #if CIRCUITPY_VIDEOCORE videocore_framebuffer_obj_t videocore; #endif + #if CIRCUITPY_PICODVI + picodvi_framebuffer_obj_t picodvi; + #endif }; union { mp_obj_base_t display_base; diff --git a/supervisor/shared/display.c b/supervisor/shared/display.c index 26585c54d5..5ab00d4f8a 100644 --- a/supervisor/shared/display.c +++ b/supervisor/shared/display.c @@ -103,37 +103,43 @@ void supervisor_start_terminal(uint16_t width_px, uint16_t height_px) { if (reset_tiles) { uint8_t *tiles = (uint8_t *)tilegrid_tiles->ptr; + // Adjust the display dimensions to account for scale of the outer group. + width_px /= scale; + height_px /= scale; + + // Number of tiles from the left edge to inset the status bar. + size_t min_left_padding = 0; #if CIRCUITPY_REPL_LOGO - status_bar->x = supervisor_blinka_sprite.pixel_width + 1; + // Blinka + 1 px padding minimum + min_left_padding = supervisor_blinka_sprite.pixel_width + 1; // Align the status bar to the bottom of the logo. status_bar->y = supervisor_blinka_sprite.pixel_height - status_bar->tile_height; #else - status_bar->x = 0; status_bar->y = 0; #endif - status_bar->top_left_y = 0; - status_bar->width_in_tiles = width_in_tiles; + status_bar->width_in_tiles = (width_px - min_left_padding) / status_bar->tile_width; status_bar->height_in_tiles = 1; - status_bar->pixel_width = width_in_tiles * status_bar->tile_width; + status_bar->pixel_width = status_bar->width_in_tiles * status_bar->tile_width; status_bar->pixel_height = status_bar->tile_height; + // Right align the status bar. + status_bar->x = width_px - status_bar->pixel_width; + status_bar->top_left_y = 0; status_bar->tiles = tiles; status_bar->full_change = true; - scroll_area->x = 0; - scroll_area->top_left_y = 0; scroll_area->width_in_tiles = width_in_tiles; - scroll_area->height_in_tiles = height_in_tiles - 1; - scroll_area->pixel_width = width_in_tiles * scroll_area->tile_width; - scroll_area->pixel_height = (height_in_tiles - 1) * scroll_area->tile_height; + scroll_area->height_in_tiles = height_in_tiles; #if CIRCUITPY_REPL_LOGO - scroll_area->y = blinka_bitmap.height; - #else - scroll_area->y = status_bar->tile_height; + scroll_area->height_in_tiles -= 1; #endif - int16_t extra_height = (scroll_area->pixel_height + scroll_area->y) - (height_px / scale); - // Subtract extra height so that the bottom line fully shows. The top line will be under the - // title bar and Blinka logo. - scroll_area->y -= extra_height; + scroll_area->pixel_width = scroll_area->width_in_tiles * scroll_area->tile_width; + scroll_area->pixel_height = scroll_area->height_in_tiles * scroll_area->tile_height; + // Right align the scroll area to give margin to the start of each line. + scroll_area->x = width_px - scroll_area->pixel_width; + scroll_area->top_left_y = 0; + // Align the scroll area to the bottom so that the newest line isn't cutoff. The top line + // may be clipped by the status bar and that's ok. + scroll_area->y = height_px - scroll_area->pixel_height; scroll_area->tiles = tiles + width_in_tiles; scroll_area->full_change = true; diff --git a/supervisor/shared/memory.c b/supervisor/shared/memory.c index a5f3296a28..ec0b27a9a6 100644 --- a/supervisor/shared/memory.c +++ b/supervisor/shared/memory.c @@ -77,6 +77,8 @@ enum { // Maximum needs of one display: max(4 if RGBMATRIX, 1 if SHARPDISPLAY, 0) #if CIRCUITPY_RGBMATRIX 4 + #elif CIRCUITPY_PICODVI + 2 #elif CIRCUITPY_SHARPDISPLAY 1 #else diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index 1d600e1158..133a97a99d 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -123,7 +123,7 @@ void usb_set_defaults(void) { }; #if CIRCUITPY_USB_IDENTIFICATION -supervisor_allocation *usb_identification_allocation; +supervisor_allocation *usb_identification_allocation = NULL; #endif // Some dynamic USB data must be saved after boot.py. How much is needed? diff --git a/tools/cortex-m-fault-gdb.py b/tools/cortex-m-fault-gdb.py index 31b76aa1d4..2ed2d13909 100644 --- a/tools/cortex-m-fault-gdb.py +++ b/tools/cortex-m-fault-gdb.py @@ -17,7 +17,7 @@ MMFAR = SCB + 0x034 # (R/W) MemManage Fault Address Register */ BFAR = SCB + 0x038 # (R/W) BusFault Address Register */ AFSR = SCB + 0x03C # (R/W) Auxiliary Fault Status Register */ -PARTS = {0xC27: "Cortex M7"} +PARTS = {0xC27: "Cortex M7", 0xC60: "Cortex M0+"} EXCEPTIONS = { 0: "Thread mode", @@ -40,18 +40,35 @@ class CortexMFault(gdb.Command): i = gdb.selected_inferior() return i.read_memory(address, 4).cast("I")[0] - def invoke(self, arg, from_tty): - cpuid = self._read(CPUID) - implementer = cpuid >> 24 - if implementer != 0x41: - raise RuntimeError() - variant = (cpuid >> 20) & 0xF - constant = (cpuid >> 16) & 0xF - if constant != 0xF: - raise RuntimeError() - revision = cpuid & 0xF - part_no = (cpuid >> 4) & 0xFFF - print(PARTS[part_no]) + def _armv6m_fault(self): + vtor = self._read(VTOR) + print("vtor", hex(vtor)) + + icsr = self._read(ICSR) + if (icsr & (1 << 23)) != 0: + print("No preempted exceptions") + else: + print("Another exception was preempted") + vectactive = icsr & 0x1FF + print(hex(icsr), vectactive) + if vectactive != 0: + if vectactive in EXCEPTIONS: + vectactive = EXCEPTIONS[vectactive] + else: + vectactive -= 16 + + print("Active interrupt:", vectactive) + + vectpending = (icsr >> 12) & 0x1FF + if vectpending != 0: + if vectpending in EXCEPTIONS: + vectpending = EXCEPTIONS[vectpending] + else: + vectpending -= 16 + + print("Pending interrupt:", vectpending) + + def _armv7m_fault(self): icsr = self._read(ICSR) if (icsr & (1 << 11)) != 0: print("No preempted exceptions") @@ -65,6 +82,7 @@ class CortexMFault(gdb.Command): print(vectactive - 16) vtor = self._read(VTOR) + print("vtor", hex(vtor)) # print(hex(self._read(SHCSR))) cfsr = self._read(CFSR) ufsr = cfsr >> 16 @@ -102,5 +120,23 @@ class CortexMFault(gdb.Command): print("Bus fault when reading vector table") print("VTOR", hex(vtor)) + def invoke(self, arg, from_tty): + cpuid = self._read(CPUID) + implementer = cpuid >> 24 + if implementer != 0x41: + raise RuntimeError() + variant = (cpuid >> 20) & 0xF + architecture = (cpuid >> 16) & 0xF + revision = cpuid & 0xF + part_no = (cpuid >> 4) & 0xFFF + print(PARTS[part_no]) + + if architecture == 0xF: + self._armv7m_fault() + elif architecture == 0xC: + self._armv6m_fault() + else: + raise RuntimeError(f"Unknown architecture {architecture:x}") + CortexMFault() From 13bb8012117dd297ee558410c32150729630de2d Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 19 Apr 2023 15:42:02 -0700 Subject: [PATCH 041/117] Fix docs and windows --- ports/raspberrypi/bindings/picodvi/Framebuffer.c | 7 +++---- tools/ci_fetch_deps.py | 5 ++++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ports/raspberrypi/bindings/picodvi/Framebuffer.c b/ports/raspberrypi/bindings/picodvi/Framebuffer.c index 51afd0eda7..12482c3baa 100644 --- a/ports/raspberrypi/bindings/picodvi/Framebuffer.c +++ b/ports/raspberrypi/bindings/picodvi/Framebuffer.c @@ -62,10 +62,9 @@ //| for the changed clock. This also allocates a very large framebuffer //| and is most likely to succeed the earlier it is attempted. //| -//| Each *_dp and *_dn pair of pins must be neighboring, such as 19 and -//| 20. They must also be ordered the same way. In other words, dp must -//| be less than dn for all pairs or dp must be greater than dn for all -//| pairs. +//| Each dp and dn pair of pins must be neighboring, such as 19 and 20. +//| They must also be ordered the same way. In other words, dp must be +//| less than dn for all pairs or dp must be greater than dn for all pairs. //| //| The framebuffer pixel format varies depending on color_depth: //| * 1 - Each bit is a pixel. Either white (1) or black (0). diff --git a/tools/ci_fetch_deps.py b/tools/ci_fetch_deps.py index b77bea72f9..2069c035c7 100644 --- a/tools/ci_fetch_deps.py +++ b/tools/ci_fetch_deps.py @@ -87,7 +87,10 @@ def main(): submodules = ["tools/"] # for huffman elif TARGET == "windows": # This builds one board from a number of ports so fill out a bunch of submodules - submodules = ["extmod/ulab", "lib/", "tools/", "ports/", "data/nvm.toml"] + for port in ("atmel-samd", "nrf", "raspberrypi", "stm"): + submodules.extend(PORT_DEPS[port]) + unique_submodules = set(submodules) + submodules = list(unique_submodules) elif TARGET == "website": submodules = ["tools/adabot/"] submodules_tags = ["frozen/"] From f38d59be2cb2af43a0fb2a07d4cbd833d5797082 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 19 Apr 2023 16:02:01 -0700 Subject: [PATCH 042/117] Fix windows CI --- tools/ci_fetch_deps.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/ci_fetch_deps.py b/tools/ci_fetch_deps.py index 2069c035c7..15ef6a51cd 100644 --- a/tools/ci_fetch_deps.py +++ b/tools/ci_fetch_deps.py @@ -88,6 +88,7 @@ def main(): elif TARGET == "windows": # This builds one board from a number of ports so fill out a bunch of submodules for port in ("atmel-samd", "nrf", "raspberrypi", "stm"): + submodules.append(f"ports/{port}") submodules.extend(PORT_DEPS[port]) unique_submodules = set(submodules) submodules = list(unique_submodules) From e2ab7a4751e867e7981425f60bf2ef54c6bae355 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Wed, 19 Apr 2023 17:04:54 -0700 Subject: [PATCH 043/117] Change voltage. Refine docs --- .../common-hal/microcontroller/Processor.c | 1 + ports/raspberrypi/Makefile | 2 ++ .../common-hal/microcontroller/Processor.c | 19 ++++++++++++++++++- shared-bindings/microcontroller/Processor.c | 8 ++++++-- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/ports/mimxrt10xx/common-hal/microcontroller/Processor.c b/ports/mimxrt10xx/common-hal/microcontroller/Processor.c index 34400e3f41..8df21268ec 100644 --- a/ports/mimxrt10xx/common-hal/microcontroller/Processor.c +++ b/ports/mimxrt10xx/common-hal/microcontroller/Processor.c @@ -59,6 +59,7 @@ void common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, freq != 720 && freq != 816 && freq != 912 && freq != 960 && freq != 1008) { mp_raise_ValueError(translate("Frequency must be 24, 150, 396, 450, 528, 600, 720, 816, 912, 960 or 1008 Mhz")); } + SystemCoreClock = setarmclock(frequency); } diff --git a/ports/raspberrypi/Makefile b/ports/raspberrypi/Makefile index 395a5553e2..98a5d7d77a 100644 --- a/ports/raspberrypi/Makefile +++ b/ports/raspberrypi/Makefile @@ -129,6 +129,7 @@ INC += \ -isystem sdk/src/rp2_common/hardware_sync/include/ \ -isystem sdk/src/rp2_common/hardware_timer/include/ \ -isystem sdk/src/rp2_common/hardware_uart/include/ \ + -isystem sdk/src/rp2_common/hardware_vreg/include/ \ -isystem sdk/src/rp2_common/hardware_watchdog/include/ \ -isystem sdk/src/rp2_common/hardware_xosc/include/ \ -isystem sdk/src/rp2_common/pico_multicore/include/ \ @@ -216,6 +217,7 @@ SRC_SDK := \ src/rp2_common/hardware_sync/sync.c \ src/rp2_common/hardware_timer/timer.c \ src/rp2_common/hardware_uart/uart.c \ + src/rp2_common/hardware_vreg/vreg.c \ src/rp2_common/hardware_watchdog/watchdog.c \ src/rp2_common/hardware_xosc/xosc.c \ src/rp2_common/pico_bootrom/bootrom.c \ diff --git a/ports/raspberrypi/common-hal/microcontroller/Processor.c b/ports/raspberrypi/common-hal/microcontroller/Processor.c index 66083a357d..56f2fd7fb1 100644 --- a/ports/raspberrypi/common-hal/microcontroller/Processor.c +++ b/ports/raspberrypi/common-hal/microcontroller/Processor.c @@ -32,10 +32,12 @@ #include "common-hal/microcontroller/Processor.h" #include "shared-bindings/microcontroller/Processor.h" #include "shared-bindings/microcontroller/ResetReason.h" +#include "shared-bindings/time/__init__.h" #include "pico/stdlib.h" #include "src/rp2_common/hardware_adc/include/hardware/adc.h" #include "src/rp2_common/hardware_clocks/include/hardware/clocks.h" +#include "src/rp2_common/hardware_vreg/include/hardware/vreg.h" #include "src/rp2040/hardware_regs/include/hardware/regs/vreg_and_chip_reset.h" #include "src/rp2040/hardware_regs/include/hardware/regs/watchdog.h" @@ -62,9 +64,24 @@ uint32_t common_hal_mcu_processor_get_frequency(void) { } void common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, uint32_t frequency) { - if (!set_sys_clock_khz(frequency / 1000, false)) { + uint vco, postdiv1, postdiv2; + uint32_t freq_khz = frequency / 1000; + if (!check_sys_clock_khz(freq_khz, &vco, &postdiv1, &postdiv2)) { mp_arg_error_invalid(MP_QSTR_frequency); } + // These voltages are approximate based on the PicoDVI examples. + enum vreg_voltage voltage = VREG_VOLTAGE_1_10; + if (freq_khz >= 400000) { + voltage = VREG_VOLTAGE_1_30; + } else if (freq_khz >= 300000) { + voltage = VREG_VOLTAGE_1_20; + } else if (freq_khz > 133000) { + voltage = VREG_VOLTAGE_1_20; + } + vreg_set_voltage(voltage); + // Wait for a stable voltage + common_hal_time_delay_ms(10); + set_sys_clock_khz(freq_khz, false); } void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { diff --git a/shared-bindings/microcontroller/Processor.c b/shared-bindings/microcontroller/Processor.c index 6ae0212a6a..e4819047da 100644 --- a/shared-bindings/microcontroller/Processor.c +++ b/shared-bindings/microcontroller/Processor.c @@ -70,8 +70,12 @@ //| **Limitations:** On most boards, ``frequency`` is read-only. Setting //| the ``frequency`` is possible on RP2040 boards and some i.MX boards. //| -//| .. warning:: On RP2040 boards changing the frequency may cause issues -//| with other subsystems, such as USB, PWM, and PIO. +//| .. warning:: Overclocking likely voids your warranties and may reduce +//| the lifetime of the chip. +//| +//| .. warning:: Changing the frequency may cause issues with other +//| subsystems, such as USB, PWM, and PIO. To minimize issues, set the CPU +//| frequency before initializing other systems. //| """ #if CIRCUITPY_SETTABLE_PROCESSOR_FREQUENCY From df41bd9eadc33e35568fbc7031f395324c83e2f6 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Thu, 20 Apr 2023 09:47:25 -0400 Subject: [PATCH 044/117] change hex radio password validation; add password length doc --- data/nvm.toml | 2 +- locale/circuitpython.pot | 17 ++++++++--------- py/argcheck.c | 13 ------------- py/runtime.h | 1 - shared-bindings/wifi/Radio.c | 23 +++++++++++++++++++---- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/data/nvm.toml b/data/nvm.toml index 73fafcbe4c..427cc92397 160000 --- a/data/nvm.toml +++ b/data/nvm.toml @@ -1 +1 @@ -Subproject commit 73fafcbe4c66b23df63be31e9227353b695abb08 +Subproject commit 427cc923976229bcb981ca6f218ebe8efd636df6 diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index f87fc02975..16ff1b38cc 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -98,6 +98,9 @@ msgstr "" #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c msgid "%q" msgstr "" @@ -193,7 +196,7 @@ msgstr "" msgid "%q must be array of type 'H'" msgstr "" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "" @@ -1117,10 +1120,6 @@ msgstr "" msgid "I2C peripheral in use" msgstr "" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "" @@ -1282,6 +1281,10 @@ msgstr "" msgid "Invalid format chunk size" msgstr "" +#: shared-bindings/wifi/Radio.c +msgid "Invalid hex password" +msgstr "" + #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" msgstr "" @@ -1708,10 +1711,6 @@ msgstr "" msgid "Oversample must be multiple of 8." msgstr "" -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "" - #: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." diff --git a/py/argcheck.c b/py/argcheck.c index 73f3ead269..465a82c97e 100644 --- a/py/argcheck.c +++ b/py/argcheck.c @@ -268,19 +268,6 @@ mp_int_t mp_arg_validate_type_int(mp_obj_t obj, qstr arg_name) { return an_int; } -mp_int_t mp_arg_validate_valid_hex_password(mp_uint_t length, uint8_t *buf) { - unsigned int i=0; - while (i +#include "py/unicode.h" #include "py/runtime.h" #include "py/objproperty.h" @@ -70,6 +71,14 @@ STATIC bool hostname_valid(const char *ptr, size_t len) { return !(partlen > 63); } +STATIC void validate_hex_password(const uint8_t *buf, size_t len) { + for (size_t i = 0; i < len; i++) { + if (!unichar_isxdigit(buf[i])) { + mp_raise_ValueError_varg(translate("Invalid hex password")); + } + } +} + //| class Radio: //| """Native wifi radio. @@ -321,6 +330,9 @@ MP_DEFINE_CONST_FUN_OBJ_1(wifi_radio_stop_station_obj, wifi_radio_stop_station); //| ``OPEN`` will be used when the password is the empty string, //| otherwise ``authmode`` will be ``WPA_WPA2_PSK``. //| +//| The length of ``password`` must be 8-63 characters if it is ASCII, +//| or exactly 64 hexadecimal characters if it is the hex form of the 256-bit key. +//| //| If ``max_connections`` is given, the access point will allow up to //| that number of stations to connect.""" //| ... @@ -368,8 +380,8 @@ STATIC mp_obj_t wifi_radio_start_ap(size_t n_args, const mp_obj_t *pos_args, mp_ if (authmodes != AUTHMODE_OPEN) { mp_arg_validate_length_range(password.len, 8, 64, MP_QSTR_password); - if (password.len==64) { - mp_arg_validate_valid_hex_password(password.len, password.buf); + if (password.len == 64) { + validate_hex_password(password.buf, password.len); } } @@ -409,6 +421,9 @@ MP_PROPERTY_GETTER(wifi_radio_ap_active_obj, //| """Connects to the given ssid and waits for an ip address. Reconnections are handled //| automatically once one connection succeeds. //| +//| The length of ``password`` must be 0 if there is no password, 8-63 characters if it is ASCII, +//| or exactly 64 hexadecimal characters if it is the hex form of the 256-bit key. +//| //| By default, this will scan all channels and connect to the access point (AP) with the //| given ``ssid`` and greatest signal strength (rssi). //| @@ -449,8 +464,8 @@ STATIC mp_obj_t wifi_radio_connect(size_t n_args, const mp_obj_t *pos_args, mp_m mp_get_buffer_raise(args[ARG_password].u_obj, &password, MP_BUFFER_READ); if (password.len != 0) { mp_arg_validate_length_range(password.len, 8, 64, MP_QSTR_password); - if (password.len==64) { - mp_arg_validate_valid_hex_password(password.len, password.buf); + if (password.len == 64) { + validate_hex_password(password.buf, password.len); } } } From 6f71e81c862d42eae77c61a05276a5bf6faf318a Mon Sep 17 00:00:00 2001 From: Hosted Weblate Date: Thu, 20 Apr 2023 16:23:03 +0200 Subject: [PATCH 045/117] 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 | 23 ++++++++++++++--------- locale/el.po | 17 ++++++++--------- locale/en_GB.po | 23 ++++++++++++++--------- locale/es.po | 23 ++++++++++++++--------- locale/fil.po | 17 ++++++++--------- locale/fr.po | 23 ++++++++++++++--------- locale/hi.po | 17 ++++++++--------- locale/it_IT.po | 17 ++++++++--------- locale/ja.po | 20 +++++++++++--------- locale/ko.po | 17 ++++++++--------- locale/nl.po | 20 +++++++++++--------- locale/pl.po | 20 +++++++++++--------- locale/pt_BR.po | 23 ++++++++++++++--------- locale/ru.po | 20 +++++++++++--------- locale/sv.po | 23 ++++++++++++++--------- locale/tr.po | 20 +++++++++++--------- locale/zh_Latn_pinyin.po | 23 ++++++++++++++--------- 19 files changed, 209 insertions(+), 171 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index 7163efb5df..c37a4f64db 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -101,6 +101,9 @@ msgstr "" #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c msgid "%q" msgstr "" @@ -196,7 +199,7 @@ msgstr "" msgid "%q must be array of type 'H'" msgstr "" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "" @@ -1127,10 +1130,6 @@ msgstr "" msgid "I2C peripheral in use" msgstr "" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "" @@ -1294,6 +1293,10 @@ msgstr "" msgid "Invalid format chunk size" msgstr "Ukuran potongan format tidak valid" +#: shared-bindings/wifi/Radio.c +msgid "Invalid hex password" +msgstr "" + #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" msgstr "" @@ -1725,10 +1728,6 @@ msgstr "" msgid "Oversample must be multiple of 8." msgstr "Sampel berlebihan harus kelipatan 8." -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "" - #: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." diff --git a/locale/cs.po b/locale/cs.po index 0e6b8714af..277287a4af 100644 --- a/locale/cs.po +++ b/locale/cs.po @@ -102,6 +102,9 @@ msgstr "%d adresní pin, %d rgb pin a %d dlaždice indikuje výšku %d, ne %d" #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c msgid "%q" msgstr "%q" @@ -197,7 +200,7 @@ msgstr "" msgid "%q must be array of type 'H'" msgstr "" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "" @@ -1127,10 +1130,6 @@ msgstr "Chyba inicializace I2C" msgid "I2C peripheral in use" msgstr "Periférie I2C je používána" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "" @@ -1294,6 +1293,10 @@ msgstr "" msgid "Invalid format chunk size" msgstr "Neplatná velikost bloku" +#: shared-bindings/wifi/Radio.c +msgid "Invalid hex password" +msgstr "" + #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" msgstr "Chybná multicastová MAC adresa" @@ -1721,10 +1724,6 @@ msgstr "" msgid "Oversample must be multiple of 8." msgstr "" -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "" - #: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." diff --git a/locale/de_DE.po b/locale/de_DE.po index 6b68831288..9c39023401 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -110,6 +110,9 @@ msgstr "" #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c msgid "%q" msgstr "%q" @@ -206,7 +209,7 @@ msgstr "" msgid "%q must be array of type 'H'" msgstr "%q muss ein Array vom Typ 'H' sein" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "" @@ -1147,10 +1150,6 @@ msgstr "I2C-Initialisierungsfehler" msgid "I2C peripheral in use" msgstr "I2C Peripherie in Verwendung" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "I2SOut nicht verfügbar" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "In-Puffer-Elemente müssen <= 4 Bytes lang sein" @@ -1318,6 +1317,10 @@ msgstr "Ungültiges Format" msgid "Invalid format chunk size" msgstr "Ungültige format chunk size" +#: shared-bindings/wifi/Radio.c +msgid "Invalid hex password" +msgstr "" + #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" msgstr "Ungültige Multicast-MAC-Adresse" @@ -1751,10 +1754,6 @@ msgstr "Out-Buffer-Elemente müssen <= 4 bytes lang sein" msgid "Oversample must be multiple of 8." msgstr "Oversample muss ein Vielfaches von 8 sein." -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "PDMIn nicht verfügbar" - #: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." @@ -4464,6 +4463,12 @@ msgstr "zi muss eine Gleitkommazahl sein" msgid "zi must be of shape (n_section, 2)" msgstr "zi muss die Form (n_section, 2) haben" +#~ msgid "I2SOut not available" +#~ msgstr "I2SOut nicht verfügbar" + +#~ msgid "PDMIn not available" +#~ msgstr "PDMIn nicht verfügbar" + #~ msgid "out of range of source" #~ msgstr "Außerhalb des Bereichs der Quelle" diff --git a/locale/el.po b/locale/el.po index c1d8350462..ca698c532f 100644 --- a/locale/el.po +++ b/locale/el.po @@ -106,6 +106,9 @@ msgstr "" #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c msgid "%q" msgstr "%q" @@ -201,7 +204,7 @@ msgstr "%q πρέπει να είναι bytearray ή array τύπου 'h', 'H', msgid "%q must be array of type 'H'" msgstr "" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "" @@ -1137,10 +1140,6 @@ msgstr "" msgid "I2C peripheral in use" msgstr "" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "" @@ -1302,6 +1301,10 @@ msgstr "" msgid "Invalid format chunk size" msgstr "" +#: shared-bindings/wifi/Radio.c +msgid "Invalid hex password" +msgstr "" + #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" msgstr "" @@ -1728,10 +1731,6 @@ msgstr "" msgid "Oversample must be multiple of 8." msgstr "" -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "" - #: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." diff --git a/locale/en_GB.po b/locale/en_GB.po index 8b7a1da9fc..8568718c68 100644 --- a/locale/en_GB.po +++ b/locale/en_GB.po @@ -111,6 +111,9 @@ msgstr "" #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c msgid "%q" msgstr "%q" @@ -206,7 +209,7 @@ msgstr "%q must be a bytearray or array of type 'h', 'H', 'b', or 'B'" msgid "%q must be array of type 'H'" msgstr "%q must be array of type 'H'" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "%q must be array of type 'h'" @@ -1136,10 +1139,6 @@ msgstr "I2C init error" msgid "I2C peripheral in use" msgstr "I2C peripheral in use" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "I2SOut not available" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "In-buffer elements must be <= 4 bytes long" @@ -1303,6 +1302,10 @@ msgstr "Invalid format" msgid "Invalid format chunk size" msgstr "Invalid format chunk size" +#: shared-bindings/wifi/Radio.c +msgid "Invalid hex password" +msgstr "" + #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" msgstr "Invalid multicast MAC address" @@ -1733,10 +1736,6 @@ msgstr "Out-buffer elements must be <= 4 bytes long" msgid "Oversample must be multiple of 8." msgstr "Oversample must be multiple of 8." -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "PDMIn not available" - #: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." @@ -4405,6 +4404,12 @@ msgstr "zi must be of float type" msgid "zi must be of shape (n_section, 2)" msgstr "zi must be of shape (n_section, 2)" +#~ msgid "I2SOut not available" +#~ msgstr "I2SOut not available" + +#~ msgid "PDMIn not available" +#~ msgstr "PDMIn not available" + #~ msgid "out of range of source" #~ msgstr "out of range of source" diff --git a/locale/es.po b/locale/es.po index 3ebfdc7833..ef8ca30c40 100644 --- a/locale/es.po +++ b/locale/es.po @@ -113,6 +113,9 @@ msgstr "" #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c msgid "%q" msgstr "%q" @@ -208,7 +211,7 @@ msgstr "%q debe ser un byte-matriz o matriz de tipo 'h', 'H', 'b', o 'B'" msgid "%q must be array of type 'H'" msgstr "%q debe ser un arreglo de tipo 'H'" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "%q debe ser una matriz de tipo 'h'" @@ -1154,10 +1157,6 @@ msgstr "Error en la inicialización I2C" msgid "I2C peripheral in use" msgstr "Dispositivo I2C en uso" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "I2SOut no disponible" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "" @@ -1328,6 +1327,10 @@ msgstr "Formato inválido" msgid "Invalid format chunk size" msgstr "Formato de fragmento de formato no válido" +#: shared-bindings/wifi/Radio.c +msgid "Invalid hex password" +msgstr "" + #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" msgstr "Dirección MAC de multidifusión inválida" @@ -1764,10 +1767,6 @@ msgstr "Los elementos del búfer de salida deben ser de una longitud <= 4 bytes" msgid "Oversample must be multiple of 8." msgstr "El sobremuestreo debe ser un múltiplo de 8." -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "PDMIn no esta disponible" - #: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." @@ -4461,6 +4460,12 @@ msgstr "zi debe ser de tipo flotante" msgid "zi must be of shape (n_section, 2)" msgstr "zi debe ser una forma (n_section,2)" +#~ msgid "I2SOut not available" +#~ msgstr "I2SOut no disponible" + +#~ msgid "PDMIn not available" +#~ msgstr "PDMIn no esta disponible" + #~ msgid "out of range of source" #~ msgstr "fuera de rango de fuente" diff --git a/locale/fil.po b/locale/fil.po index 2a9127c34c..e7630e6068 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -99,6 +99,9 @@ msgstr "" #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c msgid "%q" msgstr "" @@ -194,7 +197,7 @@ msgstr "" msgid "%q must be array of type 'H'" msgstr "" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "" @@ -1127,10 +1130,6 @@ msgstr "" msgid "I2C peripheral in use" msgstr "" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "" @@ -1294,6 +1293,10 @@ msgstr "" msgid "Invalid format chunk size" msgstr "Mali ang format ng chunk size" +#: shared-bindings/wifi/Radio.c +msgid "Invalid hex password" +msgstr "" + #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" msgstr "" @@ -1723,10 +1726,6 @@ msgstr "" msgid "Oversample must be multiple of 8." msgstr "Oversample ay dapat multiple ng 8." -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "" - #: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." diff --git a/locale/fr.po b/locale/fr.po index 22391687cb..81f8c8dcd2 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -113,6 +113,9 @@ msgstr "" #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c msgid "%q" msgstr "%q" @@ -208,7 +211,7 @@ msgstr "%q doit être a bytearray ou array de type 'h', 'H', 'b', ou 'B'" msgid "%q must be array of type 'H'" msgstr "" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "" @@ -1160,10 +1163,6 @@ msgstr "Erreur d'initialisation I2C" msgid "I2C peripheral in use" msgstr "Périphérique I2C utilisé" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "I2SOut n'est pas disponible" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "Éléments dans le tampon doivent être <= à 4 octets" @@ -1337,6 +1336,10 @@ msgstr "" msgid "Invalid format chunk size" msgstr "Taille de bloc de formatage invalide" +#: shared-bindings/wifi/Radio.c +msgid "Invalid hex password" +msgstr "" + #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" msgstr "Adresse MAC multicast invalide" @@ -1773,10 +1776,6 @@ msgstr "Éléments du tampon de sortie doivent être <= à 4 octets" msgid "Oversample must be multiple of 8." msgstr "Le sur-échantillonage doit être un multiple de 8." -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "PDMIn non disponible" - #: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." @@ -4483,6 +4482,12 @@ msgstr "zi doit être de type float" msgid "zi must be of shape (n_section, 2)" msgstr "zi doit être de forme (n_section, 2)" +#~ msgid "I2SOut not available" +#~ msgstr "I2SOut n'est pas disponible" + +#~ msgid "PDMIn not available" +#~ msgstr "PDMIn non disponible" + #~ msgid "out of range of source" #~ msgstr "dépassement des bornes de source" diff --git a/locale/hi.po b/locale/hi.po index 1f60a526cd..56095ed2f7 100644 --- a/locale/hi.po +++ b/locale/hi.po @@ -98,6 +98,9 @@ msgstr "" #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c msgid "%q" msgstr "" @@ -193,7 +196,7 @@ msgstr "" msgid "%q must be array of type 'H'" msgstr "" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "" @@ -1117,10 +1120,6 @@ msgstr "" msgid "I2C peripheral in use" msgstr "" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "" @@ -1282,6 +1281,10 @@ msgstr "" msgid "Invalid format chunk size" msgstr "" +#: shared-bindings/wifi/Radio.c +msgid "Invalid hex password" +msgstr "" + #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" msgstr "" @@ -1708,10 +1711,6 @@ msgstr "" msgid "Oversample must be multiple of 8." msgstr "" -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "" - #: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." diff --git a/locale/it_IT.po b/locale/it_IT.po index 57a9a3b91f..4bedc7d428 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -102,6 +102,9 @@ msgstr "" #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c msgid "%q" msgstr "" @@ -197,7 +200,7 @@ msgstr "" msgid "%q must be array of type 'H'" msgstr "" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "" @@ -1129,10 +1132,6 @@ msgstr "" msgid "I2C peripheral in use" msgstr "" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "" @@ -1296,6 +1295,10 @@ msgstr "" msgid "Invalid format chunk size" msgstr "" +#: shared-bindings/wifi/Radio.c +msgid "Invalid hex password" +msgstr "" + #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" msgstr "" @@ -1727,10 +1730,6 @@ msgstr "" msgid "Oversample must be multiple of 8." msgstr "L'oversampling deve essere multiplo di 8." -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "" - #: shared-bindings/pwmio/PWMOut.c #, fuzzy msgid "" diff --git a/locale/ja.po b/locale/ja.po index fbe0d8c902..1045e43dbc 100644 --- a/locale/ja.po +++ b/locale/ja.po @@ -104,6 +104,9 @@ msgstr "%dアドレスピン、%dRGBピン、%dタイルは%dの高さを指示 #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c #, fuzzy msgid "%q" msgstr "%q" @@ -200,7 +203,7 @@ msgstr "" msgid "%q must be array of type 'H'" msgstr "" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "" @@ -1128,10 +1131,6 @@ msgstr "" msgid "I2C peripheral in use" msgstr "" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "I2SOutが利用できません" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "" @@ -1295,6 +1294,10 @@ msgstr "" msgid "Invalid format chunk size" msgstr "フォーマットチャンクのサイズが不正" +#: shared-bindings/wifi/Radio.c +msgid "Invalid hex password" +msgstr "" + #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" msgstr "" @@ -1723,10 +1726,6 @@ msgstr "" msgid "Oversample must be multiple of 8." msgstr "オーバーサンプルは8の倍数でなければなりません" -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "" - #: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." @@ -4386,6 +4385,9 @@ msgstr "ziはfloat値でなければなりません" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "I2SOut not available" +#~ msgstr "I2SOutが利用できません" + #~ msgid "out of range of source" #~ msgstr "ソースが範囲外" diff --git a/locale/ko.po b/locale/ko.po index 339cb42c86..6dccfd143b 100644 --- a/locale/ko.po +++ b/locale/ko.po @@ -99,6 +99,9 @@ msgstr "" #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c msgid "%q" msgstr "" @@ -194,7 +197,7 @@ msgstr "" msgid "%q must be array of type 'H'" msgstr "" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "" @@ -1120,10 +1123,6 @@ msgstr "" msgid "I2C peripheral in use" msgstr "" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "" @@ -1285,6 +1284,10 @@ msgstr "" msgid "Invalid format chunk size" msgstr "형식 청크 크기가 잘못되었습니다" +#: shared-bindings/wifi/Radio.c +msgid "Invalid hex password" +msgstr "" + #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" msgstr "" @@ -1711,10 +1714,6 @@ msgstr "" msgid "Oversample must be multiple of 8." msgstr "" -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "" - #: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." diff --git a/locale/nl.po b/locale/nl.po index a91063c256..003953f289 100644 --- a/locale/nl.po +++ b/locale/nl.po @@ -98,6 +98,9 @@ msgstr "" #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c msgid "%q" msgstr "" @@ -193,7 +196,7 @@ msgstr "" msgid "%q must be array of type 'H'" msgstr "" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "" @@ -1123,10 +1126,6 @@ msgstr "" msgid "I2C peripheral in use" msgstr "" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "I2SOut is niet beschikbaar" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "" @@ -1290,6 +1289,10 @@ msgstr "" msgid "Invalid format chunk size" msgstr "Ongeldig formaat stuk grootte" +#: shared-bindings/wifi/Radio.c +msgid "Invalid hex password" +msgstr "" + #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" msgstr "" @@ -1722,10 +1725,6 @@ msgstr "" msgid "Oversample must be multiple of 8." msgstr "Oversample moet een meervoud van 8 zijn." -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "" - #: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." @@ -4396,6 +4395,9 @@ msgstr "zi moet van type float zijn" msgid "zi must be of shape (n_section, 2)" msgstr "zi moet vorm (n_section, 2) hebben" +#~ msgid "I2SOut not available" +#~ msgstr "I2SOut is niet beschikbaar" + #~ msgid "out of range of source" #~ msgstr "buiten bereik van bron" diff --git a/locale/pl.po b/locale/pl.po index fbd76182cc..b0f60e0806 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -100,6 +100,9 @@ msgstr "" #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c msgid "%q" msgstr "" @@ -195,7 +198,7 @@ msgstr "" msgid "%q must be array of type 'H'" msgstr "" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "" @@ -1123,10 +1126,6 @@ msgstr "" msgid "I2C peripheral in use" msgstr "" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "I2SOut niedostępne" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "" @@ -1290,6 +1289,10 @@ msgstr "" msgid "Invalid format chunk size" msgstr "Zła wielkość fragmentu formatu" +#: shared-bindings/wifi/Radio.c +msgid "Invalid hex password" +msgstr "" + #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" msgstr "" @@ -1716,10 +1719,6 @@ msgstr "" msgid "Oversample must be multiple of 8." msgstr "Nadpróbkowanie musi być wielokrotnością 8." -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "" - #: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." @@ -4372,6 +4371,9 @@ msgstr "" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "I2SOut not available" +#~ msgstr "I2SOut niedostępne" + #~ msgid "pixel value requires too many bits" #~ msgstr "wartość piksela wymaga zbyt wielu bitów" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index d130fcc464..b428121645 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -111,6 +111,9 @@ msgstr "" #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c msgid "%q" msgstr "%q" @@ -206,7 +209,7 @@ msgstr "%q deve ser um bytearray ou uma matriz do tipo 'h', 'H', 'b', ou 'B'" msgid "%q must be array of type 'H'" msgstr "%q deve ser uma matriz do tipo 'H'" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "%q deve ser uma matriz do tipo 'h'" @@ -1151,10 +1154,6 @@ msgstr "Erro de inicialização do I2C" msgid "I2C peripheral in use" msgstr "Periférico I2C em uso" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "O I2SOut não está disponível" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "Os elementos In-buffer devem ter um comprimento de <= 4 bytes" @@ -1324,6 +1323,10 @@ msgstr "Formato inválido" msgid "Invalid format chunk size" msgstr "Tamanho do pedaço de formato inválido" +#: shared-bindings/wifi/Radio.c +msgid "Invalid hex password" +msgstr "" + #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" msgstr "Endereço MAC multicast inválido" @@ -1757,10 +1760,6 @@ msgstr "Os elementos Out-buffer devem ter um comprimento de <= 4 bytes" msgid "Oversample must be multiple of 8." msgstr "A superamostragem deve ser um múltiplo de 8." -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "O PDMIn não está disponível" - #: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." @@ -4461,6 +4460,12 @@ msgstr "zi deve ser de um tipo float" msgid "zi must be of shape (n_section, 2)" msgstr "zi deve estar na forma (n_section, 2)" +#~ msgid "I2SOut not available" +#~ msgstr "O I2SOut não está disponível" + +#~ msgid "PDMIn not available" +#~ msgstr "O PDMIn não está disponível" + #~ msgid "out of range of source" #~ msgstr "fora do alcance da fonte" diff --git a/locale/ru.po b/locale/ru.po index 8fe6419b11..75447bec23 100644 --- a/locale/ru.po +++ b/locale/ru.po @@ -105,6 +105,9 @@ msgstr "" #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c msgid "%q" msgstr "%q" @@ -200,7 +203,7 @@ msgstr "%q должно быть bytearray или array типа 'h', 'H', 'b', msgid "%q must be array of type 'H'" msgstr "" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "" @@ -1154,10 +1157,6 @@ msgstr "Ошибка инициализации I2C" msgid "I2C peripheral in use" msgstr "Периферийное устройство I2C уже используется" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "I2SOut недоступен" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "Элементы буфера должны быть длиной <= 4 байта" @@ -1327,6 +1326,10 @@ msgstr "" msgid "Invalid format chunk size" msgstr "Неверный размер блока формата" +#: shared-bindings/wifi/Radio.c +msgid "Invalid hex password" +msgstr "" + #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" msgstr "Неверный MAC-адрес multicast" @@ -1764,10 +1767,6 @@ msgstr "" msgid "Oversample must be multiple of 8." msgstr "" -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "" - #: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." @@ -4425,6 +4424,9 @@ msgstr "zi должно быть типа float" msgid "zi must be of shape (n_section, 2)" msgstr "zi должен иметь форму (n_section, 2)" +#~ msgid "I2SOut not available" +#~ msgstr "I2SOut недоступен" + #~ msgid "64 bit types" #~ msgstr "64-битные типы" diff --git a/locale/sv.po b/locale/sv.po index 8cb79da28e..5cc3ecdf9c 100644 --- a/locale/sv.po +++ b/locale/sv.po @@ -110,6 +110,9 @@ msgstr "" #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c msgid "%q" msgstr "%q" @@ -207,7 +210,7 @@ msgstr "" msgid "%q must be array of type 'H'" msgstr "%q måste vara en array av typen 'H'" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "%q måste vara en matris av typen 'h'" @@ -1140,10 +1143,6 @@ msgstr "I2C-initieringsfel" msgid "I2C peripheral in use" msgstr "I2C-enhet används redan" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "I2SOut är inte tillgängligt" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "Antal element i buffert måste vara <= 4 byte" @@ -1309,6 +1308,10 @@ msgstr "Ogiltigt format" msgid "Invalid format chunk size" msgstr "Ogiltig formatsegmentstorlek" +#: shared-bindings/wifi/Radio.c +msgid "Invalid hex password" +msgstr "" + #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" msgstr "Ogiltig MAC-adress för multicast" @@ -1741,10 +1744,6 @@ msgstr "Element i utbuffer måste vara <= 4 byte långa" msgid "Oversample must be multiple of 8." msgstr "Översampling måste vara multipel av 8." -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "PDMIn inte tillgänglig" - #: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." @@ -4423,6 +4422,12 @@ msgstr "zi måste vara av typ float" msgid "zi must be of shape (n_section, 2)" msgstr "zi måste vara i formen (n_section, 2)" +#~ msgid "I2SOut not available" +#~ msgstr "I2SOut är inte tillgängligt" + +#~ msgid "PDMIn not available" +#~ msgstr "PDMIn inte tillgänglig" + #~ msgid "out of range of source" #~ msgstr "utanför räckvidd för source" diff --git a/locale/tr.po b/locale/tr.po index 1f8874167b..3a4b19ea1b 100644 --- a/locale/tr.po +++ b/locale/tr.po @@ -106,6 +106,9 @@ msgstr "" #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c msgid "%q" msgstr "%q" @@ -201,7 +204,7 @@ msgstr "%q 'h', 'H', 'b' ya da 'B' tipi bir bytearray ya da array olmalı" msgid "%q must be array of type 'H'" msgstr "" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "" @@ -1133,10 +1136,6 @@ msgstr "I2C init hatası" msgid "I2C peripheral in use" msgstr "I2C çevre cihazı kullanımda" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "I2SOut uygundeğil" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "Buffer öğeleri <=4 bayt uzunluğunda olmalı" @@ -1301,6 +1300,10 @@ msgstr "" msgid "Invalid format chunk size" msgstr "Geçersiz biçim yığın boyutu" +#: shared-bindings/wifi/Radio.c +msgid "Invalid hex password" +msgstr "" + #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" msgstr "Geçersiz multicast MAC adresi" @@ -1727,10 +1730,6 @@ msgstr "" msgid "Oversample must be multiple of 8." msgstr "" -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "" - #: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." @@ -4384,6 +4383,9 @@ msgstr "" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "I2SOut not available" +#~ msgstr "I2SOut uygundeğil" + #~ msgid "64 bit types" #~ msgstr "64 bit tipler" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index dffbea185d..1ecf35326f 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -113,6 +113,9 @@ msgstr "" #: ports/raspberrypi/common-hal/analogio/AnalogOut.c #: ports/raspberrypi/common-hal/rtc/RTC.c ports/stm/common-hal/alarm/__init__.c #: ports/stm/common-hal/canio/Listener.c ports/stm/common-hal/rtc/RTC.c +#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audiobusio/PDMIn.c +#: shared-bindings/keypad/KeyMatrix.c shared-bindings/keypad/Keys.c +#: shared-bindings/keypad/ShiftRegisterKeys.c msgid "%q" msgstr "%q" @@ -209,7 +212,7 @@ msgstr "" msgid "%q must be array of type 'H'" msgstr "%q bì xū shì lèi xíng wéi 'H' de shù zǔ" -#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c +#: shared-module/synthio/__init__.c msgid "%q must be array of type 'h'" msgstr "%q bìxū shì lèixíng wéi 'h' de shùzǔ" @@ -1144,10 +1147,6 @@ msgstr "I2C qǐdòng cuòwù" msgid "I2C peripheral in use" msgstr "I2C wài shè zhèng zài shǐ yòng zhōng" -#: shared-bindings/audiobusio/I2SOut.c -msgid "I2SOut not available" -msgstr "I2SOut bù kě yòng" - #: ports/raspberrypi/bindings/rp2pio/StateMachine.c msgid "In-buffer elements must be <= 4 bytes long" msgstr "huǎn chōng nèi yuán sù bì xū <= 4 zì jié cháng" @@ -1316,6 +1315,10 @@ msgstr "géshì wúxiào" msgid "Invalid format chunk size" msgstr "Géshì kuài dàxiǎo wúxiào" +#: shared-bindings/wifi/Radio.c +msgid "Invalid hex password" +msgstr "" + #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" msgstr "wú xiào de duō bō MAC dì zhǐ" @@ -1748,10 +1751,6 @@ msgstr "huǎn chōng wài yuán sù bì xū <= 4 zì jié cháng" msgid "Oversample must be multiple of 8." msgstr "Guò cǎiyàng bìxū shì 8 de bèishù." -#: shared-bindings/audiobusio/PDMIn.c -msgid "PDMIn not available" -msgstr "PDMIn bù kě yòng" - #: shared-bindings/pwmio/PWMOut.c msgid "" "PWM frequency not writable when variable_frequency is False on construction." @@ -4429,6 +4428,12 @@ msgstr "zi bìxū wèi fú diǎn xíng" msgid "zi must be of shape (n_section, 2)" msgstr "zi bìxū jùyǒu xíngzhuàng (n_section,2)" +#~ msgid "I2SOut not available" +#~ msgstr "I2SOut bù kě yòng" + +#~ msgid "PDMIn not available" +#~ msgstr "PDMIn bù kě yòng" + #~ msgid "out of range of source" #~ msgstr "yuán fàn wéi wài" From 8cc44f2b9033df4713ee9a277e66529983a4f013 Mon Sep 17 00:00:00 2001 From: Hosted Weblate Date: Thu, 20 Apr 2023 20:50:34 +0200 Subject: [PATCH 046/117] 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 | 11 ++++++++--- locale/cs.po | 11 ++++++++--- locale/de_DE.po | 11 ++++++++--- locale/el.po | 11 ++++++++--- locale/en_GB.po | 11 ++++++++--- locale/es.po | 11 ++++++++--- locale/fil.po | 11 ++++++++--- locale/fr.po | 11 ++++++++--- locale/hi.po | 11 ++++++++--- locale/it_IT.po | 11 ++++++++--- locale/ja.po | 11 ++++++++--- locale/ko.po | 11 ++++++++--- locale/nl.po | 11 ++++++++--- locale/pl.po | 11 ++++++++--- locale/pt_BR.po | 11 ++++++++--- locale/ru.po | 11 ++++++++--- locale/sv.po | 11 ++++++++--- locale/tr.po | 11 ++++++++--- locale/zh_Latn_pinyin.po | 11 ++++++++--- 19 files changed, 152 insertions(+), 57 deletions(-) diff --git a/locale/ID.po b/locale/ID.po index c37a4f64db..b629eeb48e 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -129,6 +129,7 @@ msgstr "" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/microcontroller/Pin.c @@ -167,11 +168,11 @@ msgstr "" msgid "%q length must be >= %d" msgstr "" -#: py/argcheck.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c msgid "%q must be %d" msgstr "" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/displayio/Bitmap.c msgid "%q must be %d-%d" msgstr "%q harus %d-%d" @@ -471,6 +472,7 @@ msgstr "" msgid "All event channels in use" msgstr "Semua channel event sedang digunakan" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "All state machines in use" msgstr "" @@ -479,6 +481,7 @@ msgstr "" msgid "All sync event channels in use" msgstr "Semua channel event yang disinkronisasi sedang digunakan" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: shared-bindings/pwmio/PWMOut.c msgid "All timers for this pin are in use" msgstr "Semua timer untuk pin ini sedang digunakan" @@ -1234,7 +1237,9 @@ msgid "Interrupt error." msgstr "" #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c -#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c +#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +#: ports/raspberrypi/bindings/picodvi/Framebuffer.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/displayio/EPaperDisplay.c msgid "Invalid %q" diff --git a/locale/cs.po b/locale/cs.po index 277287a4af..2b7854a27f 100644 --- a/locale/cs.po +++ b/locale/cs.po @@ -130,6 +130,7 @@ msgstr "" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/microcontroller/Pin.c @@ -168,11 +169,11 @@ msgstr "Délka %q musí být <= %d" msgid "%q length must be >= %d" msgstr "Délka %q musí být >= %d" -#: py/argcheck.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c msgid "%q must be %d" msgstr "%q musí být %d" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/displayio/Bitmap.c msgid "%q must be %d-%d" msgstr "%q musí být %d-%d" @@ -472,6 +473,7 @@ msgstr "Všechny kanály jsou používány" msgid "All event channels in use" msgstr "Všechny kanály událostí jsou již používány" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "All state machines in use" msgstr "" @@ -480,6 +482,7 @@ msgstr "" msgid "All sync event channels in use" msgstr "" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: shared-bindings/pwmio/PWMOut.c msgid "All timers for this pin are in use" msgstr "Všechny časovače pro tento pin jsou používány" @@ -1234,7 +1237,9 @@ msgid "Interrupt error." msgstr "" #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c -#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c +#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +#: ports/raspberrypi/bindings/picodvi/Framebuffer.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/displayio/EPaperDisplay.c msgid "Invalid %q" diff --git a/locale/de_DE.po b/locale/de_DE.po index 9c39023401..21fea5273f 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -138,6 +138,7 @@ msgstr "%q in %q muss von Typ %q sein, nicht %q" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/microcontroller/Pin.c @@ -176,11 +177,11 @@ msgstr "%q länge muss kleiner oder gleich %d sein" msgid "%q length must be >= %d" msgstr "%q länge muss größer oder gleich %d sein" -#: py/argcheck.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c msgid "%q must be %d" msgstr "%q muss %d entsprechen" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/displayio/Bitmap.c msgid "%q must be %d-%d" msgstr "%q muss %d-%d sein" @@ -482,6 +483,7 @@ msgstr "Alle Kanäle werden verwendet" msgid "All event channels in use" msgstr "Alle Event-Kanäle werden benutzt" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "All state machines in use" msgstr "Alle State-Maschinen in Verwendung" @@ -490,6 +492,7 @@ msgstr "Alle State-Maschinen in Verwendung" msgid "All sync event channels in use" msgstr "Alle Sync Event-Kanäle werden benutzt" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: shared-bindings/pwmio/PWMOut.c msgid "All timers for this pin are in use" msgstr "Alle Timer für diesen Pin werden bereits benutzt" @@ -1258,7 +1261,9 @@ msgid "Interrupt error." msgstr "Interrupt Fehler." #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c -#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c +#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +#: ports/raspberrypi/bindings/picodvi/Framebuffer.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/displayio/EPaperDisplay.c msgid "Invalid %q" diff --git a/locale/el.po b/locale/el.po index ca698c532f..f7bc0aa360 100644 --- a/locale/el.po +++ b/locale/el.po @@ -134,6 +134,7 @@ msgstr "" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/microcontroller/Pin.c @@ -172,11 +173,11 @@ msgstr "%q μήκος πρέπει να είναι <= %d" msgid "%q length must be >= %d" msgstr "%q μήκος πρέπει να είναι >= %d" -#: py/argcheck.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c msgid "%q must be %d" msgstr "%q πρέπει να είναι %d" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/displayio/Bitmap.c msgid "%q must be %d-%d" msgstr "%q πρέπει να είναι %d-%d" @@ -476,6 +477,7 @@ msgstr "Όλα τα κανάλια είναι σε χρήση" msgid "All event channels in use" msgstr "Όλα τα κανάλια συμβάντων είναι σε χρήση" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "All state machines in use" msgstr "Όλες οι μηχανές κατάστασης είναι σε χρήση" @@ -484,6 +486,7 @@ msgstr "Όλες οι μηχανές κατάστασης είναι σε χρή msgid "All sync event channels in use" msgstr "Όλα τα κανάλια συμβάντων συγχρονισμού είναι σε χρήση" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: shared-bindings/pwmio/PWMOut.c msgid "All timers for this pin are in use" msgstr "Όλοι οι χρονιστές για αυτό το pin χρησιμοποιούνται ήδη" @@ -1242,7 +1245,9 @@ msgid "Interrupt error." msgstr "" #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c -#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c +#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +#: ports/raspberrypi/bindings/picodvi/Framebuffer.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/displayio/EPaperDisplay.c msgid "Invalid %q" diff --git a/locale/en_GB.po b/locale/en_GB.po index 8568718c68..06ad558ee1 100644 --- a/locale/en_GB.po +++ b/locale/en_GB.po @@ -139,6 +139,7 @@ msgstr "%q in %q must be of type %q, not %q" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/microcontroller/Pin.c @@ -177,11 +178,11 @@ msgstr "%q length must be <= %d" msgid "%q length must be >= %d" msgstr "%q length must be >= %d" -#: py/argcheck.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c msgid "%q must be %d" msgstr "%q must be %d" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/displayio/Bitmap.c msgid "%q must be %d-%d" msgstr "%q must be %d-%d" @@ -481,6 +482,7 @@ msgstr "All channels in use" msgid "All event channels in use" msgstr "All event channels in use" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "All state machines in use" msgstr "All state machines in use" @@ -489,6 +491,7 @@ msgstr "All state machines in use" msgid "All sync event channels in use" msgstr "All sync event channels in use" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: shared-bindings/pwmio/PWMOut.c msgid "All timers for this pin are in use" msgstr "All timers for this pin are in use" @@ -1243,7 +1246,9 @@ msgid "Interrupt error." msgstr "Interrupt error." #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c -#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c +#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +#: ports/raspberrypi/bindings/picodvi/Framebuffer.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/displayio/EPaperDisplay.c msgid "Invalid %q" diff --git a/locale/es.po b/locale/es.po index ef8ca30c40..f0604b74f4 100644 --- a/locale/es.po +++ b/locale/es.po @@ -141,6 +141,7 @@ msgstr "%q en %q debe ser del tipo %q, no %q" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/microcontroller/Pin.c @@ -179,11 +180,11 @@ msgstr "%q longitud debe ser <= %d" msgid "%q length must be >= %d" msgstr "%q longitud debe ser >= %d" -#: py/argcheck.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c msgid "%q must be %d" msgstr "%q debe ser %d" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/displayio/Bitmap.c msgid "%q must be %d-%d" msgstr "%q debe ser %d-%d" @@ -483,6 +484,7 @@ msgstr "Todos los canales están en uso" msgid "All event channels in use" msgstr "Todos los canales de eventos están en uso" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "All state machines in use" msgstr "Todas las máquinas de estado están en uso" @@ -493,6 +495,7 @@ msgstr "" "Todos los canales de eventos de sincronización (sync event channels) están " "en uso" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: shared-bindings/pwmio/PWMOut.c msgid "All timers for this pin are in use" msgstr "Todos los timers para este pin están en uso" @@ -1268,7 +1271,9 @@ msgid "Interrupt error." msgstr "Error de interrupción." #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c -#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c +#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +#: ports/raspberrypi/bindings/picodvi/Framebuffer.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/displayio/EPaperDisplay.c msgid "Invalid %q" diff --git a/locale/fil.po b/locale/fil.po index e7630e6068..c7c0aeb635 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -127,6 +127,7 @@ msgstr "" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/microcontroller/Pin.c @@ -165,11 +166,11 @@ msgstr "" msgid "%q length must be >= %d" msgstr "" -#: py/argcheck.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c msgid "%q must be %d" msgstr "" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/displayio/Bitmap.c msgid "%q must be %d-%d" msgstr "" @@ -471,6 +472,7 @@ msgstr "" msgid "All event channels in use" msgstr "Lahat ng event channels ginagamit" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "All state machines in use" msgstr "" @@ -479,6 +481,7 @@ msgstr "" msgid "All sync event channels in use" msgstr "Lahat ng sync event channels ay ginagamit" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: shared-bindings/pwmio/PWMOut.c msgid "All timers for this pin are in use" msgstr "Lahat ng timers para sa pin na ito ay ginagamit" @@ -1234,7 +1237,9 @@ msgid "Interrupt error." msgstr "" #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c -#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c +#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +#: ports/raspberrypi/bindings/picodvi/Framebuffer.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/displayio/EPaperDisplay.c msgid "Invalid %q" diff --git a/locale/fr.po b/locale/fr.po index 81f8c8dcd2..ac83978de1 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -141,6 +141,7 @@ msgstr "%q dans %q doit être de type %q, pas %q" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/microcontroller/Pin.c @@ -179,11 +180,11 @@ msgstr "La longeur de %q doit être <= %d" msgid "%q length must be >= %d" msgstr "La longeur de %q doit être >= %d" -#: py/argcheck.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c msgid "%q must be %d" msgstr "%q doit être %d" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/displayio/Bitmap.c msgid "%q must be %d-%d" msgstr "%q doit être %d-%d" @@ -483,6 +484,7 @@ msgstr "Tout les canaux sont utilisés" msgid "All event channels in use" msgstr "Tous les canaux d'événements sont utilisés" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "All state machines in use" msgstr "Tous les automates finis sont utilisés" @@ -491,6 +493,7 @@ msgstr "Tous les automates finis sont utilisés" msgid "All sync event channels in use" msgstr "Tout les canaux d'événements sync sont utilisés" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: shared-bindings/pwmio/PWMOut.c msgid "All timers for this pin are in use" msgstr "Tous les minuteurs pour cette broche sont utilisés" @@ -1277,7 +1280,9 @@ msgid "Interrupt error." msgstr "Erreur d'interruption." #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c -#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c +#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +#: ports/raspberrypi/bindings/picodvi/Framebuffer.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/displayio/EPaperDisplay.c msgid "Invalid %q" diff --git a/locale/hi.po b/locale/hi.po index 56095ed2f7..e264d5e692 100644 --- a/locale/hi.po +++ b/locale/hi.po @@ -126,6 +126,7 @@ msgstr "" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/microcontroller/Pin.c @@ -164,11 +165,11 @@ msgstr "" msgid "%q length must be >= %d" msgstr "" -#: py/argcheck.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c msgid "%q must be %d" msgstr "" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/displayio/Bitmap.c msgid "%q must be %d-%d" msgstr "" @@ -468,6 +469,7 @@ msgstr "" msgid "All event channels in use" msgstr "" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "All state machines in use" msgstr "" @@ -476,6 +478,7 @@ msgstr "" msgid "All sync event channels in use" msgstr "" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: shared-bindings/pwmio/PWMOut.c msgid "All timers for this pin are in use" msgstr "" @@ -1222,7 +1225,9 @@ msgid "Interrupt error." msgstr "" #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c -#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c +#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +#: ports/raspberrypi/bindings/picodvi/Framebuffer.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/displayio/EPaperDisplay.c msgid "Invalid %q" diff --git a/locale/it_IT.po b/locale/it_IT.po index 4bedc7d428..52fb4b00a3 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -130,6 +130,7 @@ msgstr "" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/microcontroller/Pin.c @@ -168,11 +169,11 @@ msgstr "" msgid "%q length must be >= %d" msgstr "" -#: py/argcheck.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c msgid "%q must be %d" msgstr "" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/displayio/Bitmap.c msgid "%q must be %d-%d" msgstr "" @@ -474,6 +475,7 @@ msgstr "" msgid "All event channels in use" msgstr "Tutti i canali eventi utilizati" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "All state machines in use" msgstr "Tutte le state machines sono in uso" @@ -482,6 +484,7 @@ msgstr "Tutte le state machines sono in uso" msgid "All sync event channels in use" msgstr "Tutti i canali di eventi sincronizzati in uso" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: shared-bindings/pwmio/PWMOut.c msgid "All timers for this pin are in use" msgstr "Tutti i timer per questo pin sono in uso" @@ -1236,7 +1239,9 @@ msgid "Interrupt error." msgstr "" #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c -#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c +#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +#: ports/raspberrypi/bindings/picodvi/Framebuffer.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/displayio/EPaperDisplay.c msgid "Invalid %q" diff --git a/locale/ja.po b/locale/ja.po index 1045e43dbc..805dc10e8e 100644 --- a/locale/ja.po +++ b/locale/ja.po @@ -133,6 +133,7 @@ msgstr "" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/microcontroller/Pin.c @@ -171,11 +172,11 @@ msgstr "" msgid "%q length must be >= %d" msgstr "" -#: py/argcheck.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c msgid "%q must be %d" msgstr "" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/displayio/Bitmap.c msgid "%q must be %d-%d" msgstr "" @@ -475,6 +476,7 @@ msgstr "" msgid "All event channels in use" msgstr "全てのイベントチャネルが使用中" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "All state machines in use" msgstr "" @@ -483,6 +485,7 @@ msgstr "" msgid "All sync event channels in use" msgstr "全ての同期イベントチャネルが使用中" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: shared-bindings/pwmio/PWMOut.c msgid "All timers for this pin are in use" msgstr "このピン用の全てのタイマが使用中" @@ -1235,7 +1238,9 @@ msgid "Interrupt error." msgstr "" #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c -#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c +#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +#: ports/raspberrypi/bindings/picodvi/Framebuffer.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/displayio/EPaperDisplay.c msgid "Invalid %q" diff --git a/locale/ko.po b/locale/ko.po index 6dccfd143b..061c70bdfa 100644 --- a/locale/ko.po +++ b/locale/ko.po @@ -127,6 +127,7 @@ msgstr "" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/microcontroller/Pin.c @@ -165,11 +166,11 @@ msgstr "" msgid "%q length must be >= %d" msgstr "" -#: py/argcheck.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c msgid "%q must be %d" msgstr "" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/displayio/Bitmap.c msgid "%q must be %d-%d" msgstr "" @@ -469,6 +470,7 @@ msgstr "" msgid "All event channels in use" msgstr "" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "All state machines in use" msgstr "" @@ -477,6 +479,7 @@ msgstr "" msgid "All sync event channels in use" msgstr "" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: shared-bindings/pwmio/PWMOut.c msgid "All timers for this pin are in use" msgstr "핀의 모든 타이머가 사용 중입니다" @@ -1225,7 +1228,9 @@ msgid "Interrupt error." msgstr "" #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c -#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c +#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +#: ports/raspberrypi/bindings/picodvi/Framebuffer.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/displayio/EPaperDisplay.c msgid "Invalid %q" diff --git a/locale/nl.po b/locale/nl.po index 003953f289..3f14b144c6 100644 --- a/locale/nl.po +++ b/locale/nl.po @@ -126,6 +126,7 @@ msgstr "" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/microcontroller/Pin.c @@ -164,11 +165,11 @@ msgstr "" msgid "%q length must be >= %d" msgstr "" -#: py/argcheck.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c msgid "%q must be %d" msgstr "" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/displayio/Bitmap.c msgid "%q must be %d-%d" msgstr "" @@ -468,6 +469,7 @@ msgstr "" msgid "All event channels in use" msgstr "Alle event kanalen zijn in gebruik" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "All state machines in use" msgstr "" @@ -476,6 +478,7 @@ msgstr "" msgid "All sync event channels in use" msgstr "Alle sync event kanalen zijn in gebruik" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: shared-bindings/pwmio/PWMOut.c msgid "All timers for this pin are in use" msgstr "Alle timers voor deze pin zijn in gebruik" @@ -1230,7 +1233,9 @@ msgid "Interrupt error." msgstr "" #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c -#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c +#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +#: ports/raspberrypi/bindings/picodvi/Framebuffer.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/displayio/EPaperDisplay.c msgid "Invalid %q" diff --git a/locale/pl.po b/locale/pl.po index b0f60e0806..f6c35b87b2 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -128,6 +128,7 @@ msgstr "" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/microcontroller/Pin.c @@ -166,11 +167,11 @@ msgstr "" msgid "%q length must be >= %d" msgstr "" -#: py/argcheck.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c msgid "%q must be %d" msgstr "" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/displayio/Bitmap.c msgid "%q must be %d-%d" msgstr "" @@ -470,6 +471,7 @@ msgstr "" msgid "All event channels in use" msgstr "Wszystkie kanały zdarzeń w użyciu" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "All state machines in use" msgstr "" @@ -478,6 +480,7 @@ msgstr "" msgid "All sync event channels in use" msgstr "Wszystkie kanały zdarzeń synchronizacji w użyciu" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: shared-bindings/pwmio/PWMOut.c msgid "All timers for this pin are in use" msgstr "Wszystkie timery tej nóżki w użyciu" @@ -1230,7 +1233,9 @@ msgid "Interrupt error." msgstr "" #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c -#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c +#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +#: ports/raspberrypi/bindings/picodvi/Framebuffer.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/displayio/EPaperDisplay.c msgid "Invalid %q" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index b428121645..5d02126604 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -139,6 +139,7 @@ msgstr "%q em %q deve ser do tipo %q e não %q" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/microcontroller/Pin.c @@ -177,11 +178,11 @@ msgstr "o comprimento de %q deve ser <= %d" msgid "%q length must be >= %d" msgstr "o comprimento de %q deve ser >= %d" -#: py/argcheck.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c msgid "%q must be %d" msgstr "%q deve ser %d" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/displayio/Bitmap.c msgid "%q must be %d-%d" msgstr "o %q deve ser %d-%d" @@ -485,6 +486,7 @@ msgstr "Todos os canais estão em uso" msgid "All event channels in use" msgstr "Todos os canais de eventos em uso" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "All state machines in use" msgstr "O estado de todas as máquinas em uso" @@ -493,6 +495,7 @@ msgstr "O estado de todas as máquinas em uso" msgid "All sync event channels in use" msgstr "Todos os canais dos eventos de sincronização em uso" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: shared-bindings/pwmio/PWMOut.c msgid "All timers for this pin are in use" msgstr "Todos os temporizadores para este pino estão em uso" @@ -1264,7 +1267,9 @@ msgid "Interrupt error." msgstr "Erro de interrupção." #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c -#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c +#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +#: ports/raspberrypi/bindings/picodvi/Framebuffer.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/displayio/EPaperDisplay.c msgid "Invalid %q" diff --git a/locale/ru.po b/locale/ru.po index 75447bec23..82bf8504f9 100644 --- a/locale/ru.po +++ b/locale/ru.po @@ -133,6 +133,7 @@ msgstr "" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/microcontroller/Pin.c @@ -171,11 +172,11 @@ msgstr "Длинна %q должна быть <= %d" msgid "%q length must be >= %d" msgstr "Длинна %q должна быть >= %d" -#: py/argcheck.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c msgid "%q must be %d" msgstr "%q должно быть %d" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/displayio/Bitmap.c msgid "%q must be %d-%d" msgstr "%q должно быть %d-%d" @@ -475,6 +476,7 @@ msgstr "Все каналы уже используются" msgid "All event channels in use" msgstr "Все каналы событий уже используются" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "All state machines in use" msgstr "Все машины состояний уже используются" @@ -483,6 +485,7 @@ msgstr "Все машины состояний уже используются" msgid "All sync event channels in use" msgstr "Все каналы событий синхронизации уже используются" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: shared-bindings/pwmio/PWMOut.c msgid "All timers for this pin are in use" msgstr "Все таймеры для этого пина уже используются" @@ -1267,7 +1270,9 @@ msgid "Interrupt error." msgstr "" #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c -#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c +#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +#: ports/raspberrypi/bindings/picodvi/Framebuffer.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/displayio/EPaperDisplay.c msgid "Invalid %q" diff --git a/locale/sv.po b/locale/sv.po index 5cc3ecdf9c..909c8a624f 100644 --- a/locale/sv.po +++ b/locale/sv.po @@ -138,6 +138,7 @@ msgstr "%q i %q måste vara av typen %q, inte %q" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/microcontroller/Pin.c @@ -176,11 +177,11 @@ msgstr "längden på %q måste vara <= %d" msgid "%q length must be >= %d" msgstr "längden på %q måste vara >= %d" -#: py/argcheck.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c msgid "%q must be %d" msgstr "%q måste vara %d" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/displayio/Bitmap.c msgid "%q must be %d-%d" msgstr "%q måste vara %d-%d" @@ -482,6 +483,7 @@ msgstr "Alla kanaler används" msgid "All event channels in use" msgstr "Alla händelsekanaler används" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "All state machines in use" msgstr "Alla tillståndsmaskiner används" @@ -490,6 +492,7 @@ msgstr "Alla tillståndsmaskiner används" msgid "All sync event channels in use" msgstr "Alla händelsekanaler används" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: shared-bindings/pwmio/PWMOut.c msgid "All timers for this pin are in use" msgstr "Alla timers för denna pinne är i bruk" @@ -1249,7 +1252,9 @@ msgid "Interrupt error." msgstr "Interrupt-fel." #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c -#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c +#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +#: ports/raspberrypi/bindings/picodvi/Framebuffer.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/displayio/EPaperDisplay.c msgid "Invalid %q" diff --git a/locale/tr.po b/locale/tr.po index 3a4b19ea1b..1bcf4b9cfb 100644 --- a/locale/tr.po +++ b/locale/tr.po @@ -134,6 +134,7 @@ msgstr "" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/microcontroller/Pin.c @@ -172,11 +173,11 @@ msgstr "%q boyutu <= %d olmalıdır" msgid "%q length must be >= %d" msgstr "%q boyutu >= %d olmalıdır" -#: py/argcheck.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c msgid "%q must be %d" msgstr "%q, %d olmalıdır" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/displayio/Bitmap.c msgid "%q must be %d-%d" msgstr "%q, %d-%d olmalıdır" @@ -477,6 +478,7 @@ msgstr "Tüm kanallar kullanımda" msgid "All event channels in use" msgstr "Tüm olay kanalları kullanımda" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "All state machines in use" msgstr "Tüm durum makineleri kullanımda" @@ -485,6 +487,7 @@ msgstr "Tüm durum makineleri kullanımda" msgid "All sync event channels in use" msgstr "Tüm asenkron olay kanalları kullanımda" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: shared-bindings/pwmio/PWMOut.c msgid "All timers for this pin are in use" msgstr "Bu pin için tüm zamanlayıcılar kullanımda" @@ -1240,7 +1243,9 @@ msgid "Interrupt error." msgstr "" #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c -#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c +#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +#: ports/raspberrypi/bindings/picodvi/Framebuffer.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/displayio/EPaperDisplay.c msgid "Invalid %q" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index 1ecf35326f..ec33771682 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -141,6 +141,7 @@ msgstr "%q zhōng de %q bì xū shì %q lèi xíng, ér bù shì %q" #: ports/espressif/common-hal/espulp/ULP.c #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/microcontroller/Pin.c @@ -179,11 +180,11 @@ msgstr "%q chángdù bìxū <= %d" msgid "%q length must be >= %d" msgstr "%q chángdù bìxū >= %d" -#: py/argcheck.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c msgid "%q must be %d" msgstr "%q bìxū %d" -#: py/argcheck.c +#: py/argcheck.c shared-bindings/displayio/Bitmap.c msgid "%q must be %d-%d" msgstr "%q bì xū wéi %d-%d" @@ -484,6 +485,7 @@ msgstr "suǒyǒu píndào dōu zài shǐyòng zhōng" msgid "All event channels in use" msgstr "suǒyǒu shìjiàn píndào dōu zài shǐyòng zhōng" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: ports/raspberrypi/common-hal/rp2pio/StateMachine.c msgid "All state machines in use" msgstr "suǒyǒu zhuàngtàijī dōu zài shǐyòng zhōng" @@ -492,6 +494,7 @@ msgstr "suǒyǒu zhuàngtàijī dōu zài shǐyòng zhōng" msgid "All sync event channels in use" msgstr "suǒyǒu tóngbù shìjiàn píndào dōu zài shǐyòng zhōng" +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c #: shared-bindings/pwmio/PWMOut.c msgid "All timers for this pin are in use" msgstr "cǐ yǐnjiǎo de suǒyǒu jìshíqì dōu zài shǐyòng zhōng" @@ -1256,7 +1259,9 @@ msgid "Interrupt error." msgstr "zhōng duàn cuò wù." #: ports/mimxrt10xx/common-hal/audiobusio/__init__.c -#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c +#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c +#: ports/raspberrypi/bindings/picodvi/Framebuffer.c +#: ports/raspberrypi/common-hal/picodvi/Framebuffer.c py/argcheck.c #: shared-bindings/digitalio/DigitalInOut.c #: shared-bindings/displayio/EPaperDisplay.c msgid "Invalid %q" From afae39765f958953e6e3f595578d609cc16718c8 Mon Sep 17 00:00:00 2001 From: gamblor21 Date: Thu, 20 Apr 2023 18:26:04 -0500 Subject: [PATCH 047/117] PR review fixups --- shared-bindings/gifio/OnDiskGif.c | 12 +++++------ shared-module/gifio/OnDiskGif.c | 36 ++++++++++++++++--------------- shared-module/gifio/OnDiskGif.h | 8 ++----- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/shared-bindings/gifio/OnDiskGif.c b/shared-bindings/gifio/OnDiskGif.c index cfed55d0c8..be8794f24c 100644 --- a/shared-bindings/gifio/OnDiskGif.c +++ b/shared-bindings/gifio/OnDiskGif.c @@ -126,18 +126,18 @@ STATIC mp_obj_t gifio_ondiskgif_make_new(const mp_obj_type_t *type, size_t n_arg mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - mp_obj_t arg = all_args[0]; - if (mp_obj_is_str(arg)) { - arg = mp_call_function_2(MP_OBJ_FROM_PTR(&mp_builtin_open_obj), arg, MP_ROM_QSTR(MP_QSTR_rb)); + mp_obj_t filename = all_args[0]; + if (mp_obj_is_str(filename)) { + filename = mp_call_function_2(MP_OBJ_FROM_PTR(&mp_builtin_open_obj), filename, MP_ROM_QSTR(MP_QSTR_rb)); } - if (!mp_obj_is_type(arg, &mp_type_fileio)) { + if (!mp_obj_is_type(filename, &mp_type_fileio)) { mp_raise_TypeError(translate("file must be a file opened in byte mode")); } gifio_ondiskgif_t *self = m_new_obj(gifio_ondiskgif_t); self->base.type = &gifio_ondiskgif_type; - common_hal_gifio_ondiskgif_construct(self, MP_OBJ_TO_PTR(arg), args[ARG_use_palette].u_bool); + common_hal_gifio_ondiskgif_construct(self, MP_OBJ_TO_PTR(filename), args[ARG_use_palette].u_bool); return MP_OBJ_FROM_PTR(self); } @@ -207,7 +207,7 @@ MP_PROPERTY_GETTER(gifio_ondiskgif_bitmap_obj, (mp_obj_t)&gifio_ondiskgif_get_bitmap_obj); //| palette: displayio.Palette -//| """The palette for the current frame.""" +//| """The palette for the current frame if it exists.""" STATIC mp_obj_t gifio_ondiskgif_obj_get_palette(mp_obj_t self_in) { gifio_ondiskgif_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/shared-module/gifio/OnDiskGif.c b/shared-module/gifio/OnDiskGif.c index f6adfa0775..c1e6d1f2c2 100644 --- a/shared-module/gifio/OnDiskGif.c +++ b/shared-module/gifio/OnDiskGif.c @@ -68,9 +68,9 @@ static void GIFDraw(GIFDRAW *pDraw) { // The palette is either RGB565 or the original 24-bit RGB values // depending on the pixel type selected with gif.begin() - gifio_ondiskgif_displayio_objs_t *displayio_objs = (gifio_ondiskgif_displayio_objs_t *)pDraw->pUser; - displayio_bitmap_t *bitmap = displayio_objs->bitmap; - displayio_palette_t *palette = displayio_objs->palette; + gifio_ondiskgif_t *ondiskgif = (gifio_ondiskgif_t *)pDraw->pUser; + displayio_bitmap_t *bitmap = ondiskgif->bitmap; + displayio_palette_t *palette = ondiskgif->palette; // Update the palette if we have one in RGB888 if (palette != NULL) { @@ -174,20 +174,19 @@ void common_hal_gifio_ondiskgif_construct(gifio_ondiskgif_t *self, pyb_file_obj_ int bpp = 16; if (use_palette == true) { - mp_printf(&mp_plat_print, "Using palette\n"); displayio_palette_t *palette = m_new_obj(displayio_palette_t); palette->base.type = &displayio_palette_type; common_hal_displayio_palette_construct(palette, 256, false); - self->displayio_objs.palette = palette; + self->palette = palette; bpp = 8; } else { - self->displayio_objs.palette = NULL; + self->palette = NULL; } displayio_bitmap_t *bitmap = m_new_obj(displayio_bitmap_t); bitmap->base.type = &displayio_bitmap_type; common_hal_displayio_bitmap_construct(bitmap, self->gif.iCanvasWidth, self->gif.iCanvasHeight, bpp); - self->displayio_objs.bitmap = bitmap; + self->bitmap = bitmap; GIFINFO info; GIF_getInfo(&self->gif, &info); @@ -199,13 +198,13 @@ void common_hal_gifio_ondiskgif_construct(gifio_ondiskgif_t *self, pyb_file_obj_ void common_hal_gifio_ondiskgif_deinit(gifio_ondiskgif_t *self) { self->file = NULL; - common_hal_displayio_bitmap_deinit(self->displayio_objs.bitmap); - self->displayio_objs.bitmap = NULL; - self->displayio_objs.palette = NULL; + common_hal_displayio_bitmap_deinit(self->bitmap); + self->bitmap = NULL; + self->palette = NULL; } bool common_hal_gifio_ondiskgif_deinited(gifio_ondiskgif_t *self) { - return self->displayio_objs.bitmap == NULL; + return self->bitmap == NULL; } uint16_t common_hal_gifio_ondiskgif_get_height(gifio_ondiskgif_t *self) { @@ -217,11 +216,14 @@ uint16_t common_hal_gifio_ondiskgif_get_width(gifio_ondiskgif_t *self) { } mp_obj_t common_hal_gifio_ondiskgif_get_bitmap(gifio_ondiskgif_t *self) { - return MP_OBJ_FROM_PTR(self->displayio_objs.bitmap); + return MP_OBJ_FROM_PTR(self->bitmap); } mp_obj_t common_hal_gifio_ondiskgif_get_palette(gifio_ondiskgif_t *self) { - return MP_OBJ_FROM_PTR(self->displayio_objs.palette); + if (self->palette == NULL) { + return mp_const_none; + } + return MP_OBJ_FROM_PTR(self->palette); } int32_t common_hal_gifio_ondiskgif_get_duration(gifio_ondiskgif_t *self) { @@ -243,17 +245,17 @@ int32_t common_hal_gifio_ondiskgif_get_max_delay(gifio_ondiskgif_t *self) { uint32_t common_hal_gifio_ondiskgif_next_frame(gifio_ondiskgif_t *self, bool setDirty) { int nextDelay = 0; int result = 0; - result = GIF_playFrame(&self->gif, &nextDelay, &self->displayio_objs); + result = GIF_playFrame(&self->gif, &nextDelay, self); if ((result >= 0) && (setDirty)) { displayio_area_t dirty_area = { .x1 = 0, .y1 = 0, - .x2 = self->displayio_objs.bitmap->width, - .y2 = self->displayio_objs.bitmap->height, + .x2 = self->bitmap->width, + .y2 = self->bitmap->height, }; - displayio_bitmap_set_dirty_area(self->displayio_objs.bitmap, &dirty_area); + displayio_bitmap_set_dirty_area(self->bitmap, &dirty_area); } return nextDelay; diff --git a/shared-module/gifio/OnDiskGif.h b/shared-module/gifio/OnDiskGif.h index 70479ac8d9..6138337391 100644 --- a/shared-module/gifio/OnDiskGif.h +++ b/shared-module/gifio/OnDiskGif.h @@ -38,16 +38,12 @@ #include "extmod/vfs_fat.h" -typedef struct { - displayio_bitmap_t *bitmap; - displayio_palette_t *palette; -} gifio_ondiskgif_displayio_objs_t; - typedef struct { mp_obj_base_t base; GIFIMAGE gif; pyb_file_obj_t *file; - gifio_ondiskgif_displayio_objs_t displayio_objs; + displayio_bitmap_t *bitmap; + displayio_palette_t *palette; int32_t duration; int32_t frame_count; int32_t min_delay; From b3c8575b81ef78c5df9af265d7270056b00d9459 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Thu, 20 Apr 2023 21:22:39 -0400 Subject: [PATCH 048/117] Update for Pimoroni Pico dv pins/connectors --- .../boards/pimoroni_pico_dv/board.c | 52 +++++++++++ .../boards/pimoroni_pico_dv/mpconfigboard.h | 7 ++ .../boards/pimoroni_pico_dv/mpconfigboard.mk | 12 +++ .../pimoroni_pico_dv/pico-sdk-configboard.h | 4 + .../boards/pimoroni_pico_dv/pins.c | 92 +++++++++++++++++++ 5 files changed, 167 insertions(+) create mode 100644 ports/raspberrypi/boards/pimoroni_pico_dv/board.c create mode 100644 ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.h create mode 100644 ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.mk create mode 100644 ports/raspberrypi/boards/pimoroni_pico_dv/pico-sdk-configboard.h create mode 100644 ports/raspberrypi/boards/pimoroni_pico_dv/pins.c diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv/board.c b/ports/raspberrypi/boards/pimoroni_pico_dv/board.c new file mode 100644 index 0000000000..bc5878bf24 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_pico_dv/board.c @@ -0,0 +1,52 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" + +#include "bindings/picodvi/Framebuffer.h" +#include "shared-module/displayio/__init__.h" +#include "shared-bindings/framebufferio/FramebufferDisplay.h" + +void board_init(void) { + picodvi_framebuffer_obj_t *fb = &allocate_display_bus()->picodvi; + fb->base.type = &picodvi_framebuffer_type; + common_hal_picodvi_framebuffer_construct(fb, 640, 480, + &pin_GPIO7, &pin_GPIO6, + &pin_GPIO9, &pin_GPIO8, + &pin_GPIO11, &pin_GPIO10, + &pin_GPIO13, &pin_GPIO12, + 8); + + framebufferio_framebufferdisplay_obj_t *display = &displays[0].framebuffer_display; + display->base.type = &framebufferio_framebufferdisplay_type; + common_hal_framebufferio_framebufferdisplay_construct( + display, + MP_OBJ_FROM_PTR(fb), + 0, + true); +} + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.h b/ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.h new file mode 100644 index 0000000000..bf18491e47 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.h @@ -0,0 +1,7 @@ +#define MICROPY_HW_BOARD_NAME "Pimoroni Pico DV" +#define MICROPY_HW_MCU_NAME "rp2040" + +#define MICROPY_HW_LED_STATUS (&pin_GPIO25) + +#define DEFAULT_UART_BUS_RX (&pin_GPIO1) +#define DEFAULT_UART_BUS_TX (&pin_GPIO0) diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.mk b/ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.mk new file mode 100644 index 0000000000..20607d50e4 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.mk @@ -0,0 +1,12 @@ +USB_VID = 0x239A +USB_PID = 0x80F4 +USB_PRODUCT = "Pico" +USB_MANUFACTURER = "Raspberry Pi" + +CHIP_VARIANT = RP2040 +CHIP_FAMILY = rp2 + +EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ" + +CIRCUITPY__EVE = 1 +CIRCUITPY_PICODVI = 1 diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv/pico-sdk-configboard.h b/ports/raspberrypi/boards/pimoroni_pico_dv/pico-sdk-configboard.h new file mode 100644 index 0000000000..a41131dd22 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_pico_dv/pico-sdk-configboard.h @@ -0,0 +1,4 @@ +// Put board-specific pico-sdk definitions here. This file must exist. + +// Allow extra time for xosc to start. +#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64 diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv/pins.c b/ports/raspberrypi/boards/pimoroni_pico_dv/pins.c new file mode 100644 index 0000000000..c331d5cbf9 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_pico_dv/pins.c @@ -0,0 +1,92 @@ +#include "shared-bindings/board/__init__.h" + +#include "shared-module/displayio/__init__.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_GP1), MP_ROM_PTR(&pin_GPIO1) }, + + { MP_ROM_QSTR(MP_QSTR_GP2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_GP3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_GP4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_GP5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_GP6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_GP7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_GP8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_GP9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_GP10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_GP11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_GP12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_GP13), MP_ROM_PTR(&pin_GPIO13) }, + + { MP_ROM_QSTR(MP_QSTR_BUTTON_A), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_GP14), MP_ROM_PTR(&pin_GPIO14) }, + + { MP_ROM_QSTR(MP_QSTR_BUTTON_B), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_GP15), MP_ROM_PTR(&pin_GPIO15) }, + + { MP_ROM_QSTR(MP_QSTR_BUTTON_C), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_GP16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_GP17), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_GP18), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_GP19), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_GP20), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_GP21), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_GP22), MP_ROM_PTR(&pin_GPIO22) }, + + // SD Card + { MP_ROM_QSTR(MP_QSTR_SD_SCK), MP_ROM_PTR(&pin_GPIO5)}, + { MP_ROM_QSTR(MP_QSTR_SD_MOSI), MP_ROM_PTR(&pin_GPIO18)}, + { MP_ROM_QSTR(MP_QSTR_SD_MISO), MP_ROM_PTR(&pin_GPIO19)}, + { MP_ROM_QSTR(MP_QSTR_SD_CS), MP_ROM_PTR(&pin_GPIO22)}, + + { MP_ROM_QSTR(MP_QSTR_SMPS_MODE), MP_ROM_PTR(&pin_GPIO23) }, + { MP_ROM_QSTR(MP_QSTR_GP23), MP_ROM_PTR(&pin_GPIO23) }, + + { MP_ROM_QSTR(MP_QSTR_VBUS_SENSE), MP_ROM_PTR(&pin_GPIO24) }, + { MP_ROM_QSTR(MP_QSTR_GP24), MP_ROM_PTR(&pin_GPIO24) }, + + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO25) }, + { MP_ROM_QSTR(MP_QSTR_GP25), MP_ROM_PTR(&pin_GPIO25) }, + + { MP_ROM_QSTR(MP_QSTR_I2S_WS), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_GP26_A0), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_GP26), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) }, + + { MP_ROM_QSTR(MP_QSTR_I2S_BCLK), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_GP27_A1), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_GP27), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, + + { MP_ROM_QSTR(MP_QSTR_I2S_OUT), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_GP28_A2), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_GP28), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) }, + + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) }, + { MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_GPIO29) }, + + // DVI VIDEO + { MP_ROM_QSTR(MP_QSTR_DV_CEC), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_DV_SCL), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_DV_SDA), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_CKN), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_CKP), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_D0N), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_D0P), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_D1N), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_D1P), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_D2N), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_D2P), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_DV_HPD), MP_ROM_PTR(&pin_GPIO17) }, + + { MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].framebuffer_display)}, + +}; + +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); From ae7303221d687150c506c4c39f0b8f787064d7a3 Mon Sep 17 00:00:00 2001 From: Mark <56205165+gamblor21@users.noreply.github.com> Date: Fri, 21 Apr 2023 11:21:29 -0500 Subject: [PATCH 049/117] Update doc that Palette may not always be there Co-authored-by: Scott Shawcroft --- shared-bindings/gifio/OnDiskGif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/gifio/OnDiskGif.c b/shared-bindings/gifio/OnDiskGif.c index be8794f24c..e4335f9e44 100644 --- a/shared-bindings/gifio/OnDiskGif.c +++ b/shared-bindings/gifio/OnDiskGif.c @@ -206,7 +206,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(gifio_ondiskgif_get_bitmap_obj, gifio_ondiskgif_obj_ge MP_PROPERTY_GETTER(gifio_ondiskgif_bitmap_obj, (mp_obj_t)&gifio_ondiskgif_get_bitmap_obj); -//| palette: displayio.Palette +//| palette: Optional[displayio.Palette] //| """The palette for the current frame if it exists.""" STATIC mp_obj_t gifio_ondiskgif_obj_get_palette(mp_obj_t self_in) { gifio_ondiskgif_t *self = MP_OBJ_TO_PTR(self_in); From 7089ea4d6586821f03c062e21ccdc8c4dfab9422 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 20 Apr 2023 16:15:06 -0700 Subject: [PATCH 050/117] Add address_little_endian for displayio Add address_little_endian for epaper displays with little endian (low byte first) addresses. Also clears allocated display and display bus memory so it has a known state. The acep member wasn't always set so it varied accidentally. Fixes #7560. May fix #7778. Fixes #5119. --- shared-bindings/displayio/EPaperDisplay.c | 10 +- shared-bindings/displayio/EPaperDisplay.h | 14 +- shared-module/_stage/__init__.c | 5 +- shared-module/board/__init__.c | 8 +- shared-module/displayio/Display.c | 12 +- shared-module/displayio/EPaperDisplay.c | 26 ++-- shared-module/displayio/EPaperDisplay.h | 4 - shared-module/displayio/TileGrid.c | 1 - shared-module/displayio/__init__.c | 139 ++++++++++-------- shared-module/displayio/__init__.h | 8 +- shared-module/displayio/display_core.c | 50 +++++-- shared-module/displayio/display_core.h | 20 ++- .../framebufferio/FramebufferDisplay.c | 5 +- supervisor/shared/display.c | 8 +- 14 files changed, 181 insertions(+), 129 deletions(-) diff --git a/shared-bindings/displayio/EPaperDisplay.c b/shared-bindings/displayio/EPaperDisplay.c index 93d91110a2..42f58ac0c5 100644 --- a/shared-bindings/displayio/EPaperDisplay.c +++ b/shared-bindings/displayio/EPaperDisplay.c @@ -80,7 +80,8 @@ //| grayscale: bool = False, //| advanced_color_epaper: bool = False, //| two_byte_sequence_length: bool = False, -//| start_up_time: float = 0 +//| start_up_time: float = 0, +//| address_little_endian: bool = False //| ) -> None: //| """Create a EPaperDisplay object on the given display bus (`displayio.FourWire` or `paralleldisplay.ParallelBus`). //| @@ -122,6 +123,7 @@ //| :param bool advanced_color_epaper: When true, the display is a 7-color advanced color epaper (ACeP) //| :param bool two_byte_sequence_length: When true, use two bytes to define sequence length //| :param float start_up_time: Time to wait after reset before sending commands +//| :param bool address_little_endian: Send the least significant byte (not bit) of multi-byte addresses first. Ignored when ram is addressed with one byte //| """ //| ... STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { @@ -132,7 +134,7 @@ STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size ARG_write_color_ram_command, ARG_color_bits_inverted, ARG_highlight_color, ARG_refresh_display_command, ARG_refresh_time, ARG_busy_pin, ARG_busy_state, ARG_seconds_per_frame, ARG_always_toggle_chip_select, ARG_grayscale, ARG_advanced_color_epaper, - ARG_two_byte_sequence_length, ARG_start_up_time }; + ARG_two_byte_sequence_length, ARG_start_up_time, ARG_address_little_endian }; static const mp_arg_t allowed_args[] = { { MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_start_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -163,6 +165,7 @@ STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size { MP_QSTR_advanced_color_epaper, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, { MP_QSTR_two_byte_sequence_length, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, { MP_QSTR_start_up_time, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NEW_SMALL_INT(0)} }, + { MP_QSTR_address_little_endian, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -228,7 +231,8 @@ STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size args[ARG_write_black_ram_command].u_int, args[ARG_black_bits_inverted].u_bool, write_color_ram_command, args[ARG_color_bits_inverted].u_bool, highlight_color, refresh_buf, refresh_buf_len, refresh_time, busy_pin, args[ARG_busy_state].u_bool, seconds_per_frame, - args[ARG_always_toggle_chip_select].u_bool, args[ARG_grayscale].u_bool, args[ARG_advanced_color_epaper].u_bool, two_byte_sequence_length + args[ARG_always_toggle_chip_select].u_bool, args[ARG_grayscale].u_bool, args[ARG_advanced_color_epaper].u_bool, + two_byte_sequence_length, args[ARG_address_little_endian].u_bool ); return self; diff --git a/shared-bindings/displayio/EPaperDisplay.h b/shared-bindings/displayio/EPaperDisplay.h index 1ef2ed4b4b..bdaad61300 100644 --- a/shared-bindings/displayio/EPaperDisplay.h +++ b/shared-bindings/displayio/EPaperDisplay.h @@ -37,12 +37,18 @@ extern const mp_obj_type_t displayio_epaperdisplay_type; #define NO_COMMAND 0x100 void common_hal_displayio_epaperdisplay_construct(displayio_epaperdisplay_obj_t *self, - mp_obj_t bus, const uint8_t *start_sequence, uint16_t start_sequence_len, mp_float_t start_up_time, const uint8_t *stop_sequence, uint16_t stop_sequence_len, - uint16_t width, uint16_t height, uint16_t ram_width, uint16_t ram_height, int16_t colstart, int16_t rowstart, uint16_t rotation, + mp_obj_t bus, const uint8_t *start_sequence, uint16_t start_sequence_len, mp_float_t start_up_time, + const uint8_t *stop_sequence, uint16_t stop_sequence_len, + uint16_t width, uint16_t height, uint16_t ram_width, uint16_t ram_height, + int16_t colstart, int16_t rowstart, uint16_t rotation, uint16_t set_column_window_command, uint16_t set_row_window_command, uint16_t set_current_column_command, uint16_t set_current_row_command, - uint16_t write_black_ram_command, bool black_bits_inverted, uint16_t write_color_ram_command, bool color_bits_inverted, uint32_t highlight_color, const uint8_t *refresh_sequence, uint16_t refresh_sequence_len, mp_float_t refresh_time, - const mcu_pin_obj_t *busy_pin, bool busy_state, mp_float_t seconds_per_frame, bool always_toggle_chip_select, bool grayscale, bool acep, bool two_byte_sequence_length); + uint16_t write_black_ram_command, bool black_bits_inverted, + uint16_t write_color_ram_command, bool color_bits_inverted, uint32_t highlight_color, + const uint8_t *refresh_sequence, uint16_t refresh_sequence_len, mp_float_t refresh_time, + const mcu_pin_obj_t *busy_pin, bool busy_state, mp_float_t seconds_per_frame, + bool always_toggle_chip_select, bool grayscale, bool acep, bool two_byte_sequence_length, + bool address_little_endian); bool common_hal_displayio_epaperdisplay_refresh(displayio_epaperdisplay_obj_t *self); diff --git a/shared-module/_stage/__init__.c b/shared-module/_stage/__init__.c index 7ec640bc6e..0a18635562 100644 --- a/shared-module/_stage/__init__.c +++ b/shared-module/_stage/__init__.c @@ -46,10 +46,7 @@ void render_stage( area.y1 = y0 * scale; area.x2 = x1 * scale; area.y2 = y1 * scale; - displayio_display_core_set_region_to_update( - &display->core, display->set_column_command, display->set_row_command, - NO_COMMAND, NO_COMMAND, display->data_as_commands, false, &area, - display->SH1107_addressing); + displayio_display_core_set_region_to_update(&display->core, &area); while (!displayio_display_core_begin_transaction(&display->core)) { RUN_BACKGROUND_TASKS; diff --git a/shared-module/board/__init__.c b/shared-module/board/__init__.c index 5d08c368b5..2d5a8a07e4 100644 --- a/shared-module/board/__init__.c +++ b/shared-module/board/__init__.c @@ -190,7 +190,7 @@ void reset_board_buses(void) { bool display_using_i2c = false; #if CIRCUITPY_DISPLAYIO for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { - if (displays[i].bus_base.type == &displayio_i2cdisplay_type && displays[i].i2cdisplay_bus.bus == &i2c_obj[instance]) { + if (display_buses[i].bus_base.type == &displayio_i2cdisplay_type && display_buses[i].i2cdisplay_bus.bus == &i2c_obj[instance]) { display_using_i2c = true; break; } @@ -211,13 +211,13 @@ void reset_board_buses(void) { bool display_using_spi = false; #if CIRCUITPY_DISPLAYIO for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { - mp_const_obj_t bus_type = displays[i].bus_base.type; - if (bus_type == &displayio_fourwire_type && displays[i].fourwire_bus.bus == &spi_obj[instance]) { + mp_const_obj_t bus_type = display_buses[i].bus_base.type; + if (bus_type == &displayio_fourwire_type && display_buses[i].fourwire_bus.bus == &spi_obj[instance]) { display_using_spi = true; break; } #if CIRCUITPY_SHARPDISPLAY - if (displays[i].bus_base.type == &sharpdisplay_framebuffer_type && displays[i].sharpdisplay.bus == &spi_obj[instance]) { + if (bus_type == &sharpdisplay_framebuffer_type && display_buses[i].sharpdisplay.bus == &spi_obj[instance]) { display_using_spi = true; break; } diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index 01d8c544ad..6d4acbe8c0 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -64,16 +64,14 @@ void common_hal_displayio_display_construct(displayio_display_obj_t *self, ram_height = 0xff; } displayio_display_core_construct(&self->core, bus, width, height, ram_width, ram_height, colstart, rowstart, rotation, - color_depth, grayscale, pixels_in_byte_share_row, bytes_per_cell, reverse_pixels_in_byte, reverse_bytes_in_word); + color_depth, grayscale, pixels_in_byte_share_row, bytes_per_cell, reverse_pixels_in_byte, reverse_bytes_in_word, + set_column_command, set_row_command, NO_COMMAND, NO_COMMAND, self->data_as_commands, false /* always_toggle_chip_select */, + SH1107_addressing && color_depth == 1, false /*address_little_endian */); - self->set_column_command = set_column_command; - self->set_row_command = set_row_command; self->write_ram_command = write_ram_command; self->brightness_command = brightness_command; self->first_manual_refresh = !auto_refresh; - self->data_as_commands = data_as_commands; self->backlight_on_high = backlight_on_high; - self->SH1107_addressing = SH1107_addressing && color_depth == 1; self->native_frames_per_second = native_frames_per_second; self->native_ms_per_frame = 1000 / native_frames_per_second; @@ -294,9 +292,7 @@ STATIC bool _refresh_area(displayio_display_obj_t *self, const displayio_area_t } remaining_rows -= rows_per_buffer; - displayio_display_core_set_region_to_update(&self->core, self->set_column_command, - self->set_row_command, NO_COMMAND, NO_COMMAND, self->data_as_commands, false, - &subrectangle, self->SH1107_addressing); + displayio_display_core_set_region_to_update(&self->core, &subrectangle); uint16_t subrectangle_size_bytes; if (self->core.colorspace.depth >= 8) { diff --git a/shared-module/displayio/EPaperDisplay.c b/shared-module/displayio/EPaperDisplay.c index 74f828aea8..2f6c8fa5c9 100644 --- a/shared-module/displayio/EPaperDisplay.c +++ b/shared-module/displayio/EPaperDisplay.c @@ -58,28 +58,30 @@ void common_hal_displayio_epaperdisplay_construct(displayio_epaperdisplay_obj_t uint16_t write_color_ram_command, bool color_bits_inverted, uint32_t highlight_color, const uint8_t *refresh_sequence, uint16_t refresh_sequence_len, mp_float_t refresh_time, const mcu_pin_obj_t *busy_pin, bool busy_state, mp_float_t seconds_per_frame, - bool chip_select, bool grayscale, bool acep, bool two_byte_sequence_length) { + bool chip_select, bool grayscale, bool acep, bool two_byte_sequence_length, bool address_little_endian) { uint16_t color_depth = 1; bool core_grayscale = true; if (highlight_color != 0x000000) { self->core.colorspace.tricolor = true; self->core.colorspace.tricolor_hue = displayio_colorconverter_compute_hue(highlight_color); self->core.colorspace.tricolor_luma = displayio_colorconverter_compute_luma(highlight_color); + } else { + self->core.colorspace.tricolor = false; } + self->acep = acep; + self->core.colorspace.sevencolor = acep; if (acep) { - self->core.colorspace.sevencolor = true; color_depth = 4; // bits. 7 colors + clean - self->acep = acep; grayscale = false; core_grayscale = false; } - displayio_display_core_construct(&self->core, bus, width, height, ram_width, ram_height, colstart, rowstart, rotation, color_depth, core_grayscale, true, 1, true, true); + displayio_display_core_construct(&self->core, bus, width, height, ram_width, ram_height, + colstart, rowstart, rotation, color_depth, core_grayscale, true, 1, true, true, + set_column_window_command, set_row_window_command, set_current_column_command, set_current_row_command, + false /* data_as_commands */, chip_select, + false /* SH1107_addressing */, address_little_endian); - self->set_column_window_command = set_column_window_command; - self->set_row_window_command = set_row_window_command; - self->set_current_column_command = set_current_column_command; - self->set_current_row_command = set_current_row_command; self->write_black_ram_command = write_black_ram_command; self->black_bits_inverted = black_bits_inverted; self->write_color_ram_command = write_color_ram_command; @@ -137,7 +139,7 @@ STATIC const displayio_area_t *displayio_epaperdisplay_get_refresh_areas(display if (self->core.current_group != NULL) { first_area = displayio_group_get_refresh_areas(self->core.current_group, NULL); } - if (first_area != NULL && self->set_row_window_command == NO_COMMAND) { + if (first_area != NULL) { self->core.area.next = NULL; return &self->core.area; } @@ -310,10 +312,8 @@ STATIC bool displayio_epaperdisplay_refresh_area(displayio_epaperdisplay_obj_t * for (uint8_t pass = 0; pass < passes; pass++) { uint16_t remaining_rows = displayio_area_height(&clipped); - if (self->set_row_window_command != NO_COMMAND) { - displayio_display_core_set_region_to_update(&self->core, self->set_column_window_command, - self->set_row_window_command, self->set_current_column_command, self->set_current_row_command, - false, self->chip_select, &clipped, false /* SH1107_addressing */); + if (self->core.row_command != NO_COMMAND) { + displayio_display_core_set_region_to_update(&self->core, &clipped); } uint8_t write_command = self->write_black_ram_command; diff --git a/shared-module/displayio/EPaperDisplay.h b/shared-module/displayio/EPaperDisplay.h index f2398398ea..13cf84dbd3 100644 --- a/shared-module/displayio/EPaperDisplay.h +++ b/shared-module/displayio/EPaperDisplay.h @@ -46,10 +46,6 @@ typedef struct { uint16_t refresh_sequence_len; uint16_t start_up_time_ms; uint16_t refresh_time; - uint16_t set_column_window_command; - uint16_t set_row_window_command; - uint16_t set_current_column_command; - uint16_t set_current_row_command; uint16_t write_black_ram_command; uint16_t write_color_ram_command; uint8_t hue; diff --git a/shared-module/displayio/TileGrid.c b/shared-module/displayio/TileGrid.c index e5573ac34c..723aa41682 100644 --- a/shared-module/displayio/TileGrid.c +++ b/shared-module/displayio/TileGrid.c @@ -543,7 +543,6 @@ bool displayio_tilegrid_fill_area(displayio_tilegrid_t *self, ((uint8_t *)buffer)[offset / pixels_per_byte] |= output_pixel.pixel << shift; } } - (void)input_pixel; } } return full_coverage; diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index 2dd0cff8b8..c47b19caea 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -48,6 +48,7 @@ #include "shared-module/sharpdisplay/SharpMemoryFramebuffer.h" #endif +primary_display_bus_t display_buses[CIRCUITPY_DISPLAY_LIMIT]; primary_display_t displays[CIRCUITPY_DISPLAY_LIMIT]; displayio_buffer_transform_t null_transform = { @@ -87,19 +88,19 @@ void displayio_background(void) { return; } - for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { - if (displays[i].display.base.type == NULL || displays[i].display.base.type == &mp_type_NoneType) { + mp_const_obj_t display_type = displays[i].display.base.type; + if (display_type == NULL || display_type == &mp_type_NoneType) { // Skip null display. continue; } - if (displays[i].display.base.type == &displayio_display_type) { + if (display_type == &displayio_display_type) { displayio_display_background(&displays[i].display); #if CIRCUITPY_FRAMEBUFFERIO - } else if (displays[i].framebuffer_display.base.type == &framebufferio_framebufferdisplay_type) { + } else if (display_type == &framebufferio_framebufferdisplay_type) { framebufferio_framebufferdisplay_background(&displays[i].framebuffer_display); #endif - } else if (displays[i].epaper_display.base.type == &displayio_epaperdisplay_type) { + } else if (display_type == &displayio_epaperdisplay_type) { displayio_epaperdisplay_background(&displays[i].epaper_display); } } @@ -110,7 +111,7 @@ void common_hal_displayio_release_displays(void) { // Release displays before busses so that they can send any final commands to turn the display // off properly. 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].display_base.type; if (display_type == NULL || display_type == &mp_type_NoneType) { continue; } else if (display_type == &displayio_display_type) { @@ -125,39 +126,39 @@ void common_hal_displayio_release_displays(void) { displays[i].display.base.type = &mp_type_NoneType; } for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { - mp_const_obj_t bus_type = displays[i].fourwire_bus.base.type; + mp_const_obj_t bus_type = display_buses[i].bus_base.type; if (bus_type == NULL || bus_type == &mp_type_NoneType) { continue; } else if (bus_type == &displayio_fourwire_type) { - common_hal_displayio_fourwire_deinit(&displays[i].fourwire_bus); + common_hal_displayio_fourwire_deinit(&display_buses[i].fourwire_bus); } else if (bus_type == &displayio_i2cdisplay_type) { - common_hal_displayio_i2cdisplay_deinit(&displays[i].i2cdisplay_bus); + common_hal_displayio_i2cdisplay_deinit(&display_buses[i].i2cdisplay_bus); #if CIRCUITPY_PARALLELDISPLAY } else if (bus_type == ¶lleldisplay_parallelbus_type) { - common_hal_paralleldisplay_parallelbus_deinit(&displays[i].parallel_bus); + common_hal_paralleldisplay_parallelbus_deinit(&display_buses[i].parallel_bus); #endif #if CIRCUITPY_RGBMATRIX } else if (bus_type == &rgbmatrix_RGBMatrix_type) { - common_hal_rgbmatrix_rgbmatrix_deinit(&displays[i].rgbmatrix); + common_hal_rgbmatrix_rgbmatrix_deinit(&display_buses[i].rgbmatrix); #endif #if CIRCUITPY_IS31FL3741 } else if (bus_type == &is31fl3741_FrameBuffer_type) { - common_hal_is31fl3741_FrameBuffer_deinit(&displays[i].is31fl3741); + common_hal_is31fl3741_FrameBuffer_deinit(&display_buses[i].is31fl3741); #endif #if CIRCUITPY_SHARPDISPLAY - } else if (displays[i].bus_base.type == &sharpdisplay_framebuffer_type) { - common_hal_sharpdisplay_framebuffer_deinit(&displays[i].sharpdisplay); + } else if (bus_type == &sharpdisplay_framebuffer_type) { + common_hal_sharpdisplay_framebuffer_deinit(&display_buses[i].sharpdisplay); #endif #if CIRCUITPY_VIDEOCORE - } else if (displays[i].bus_base.type == &videocore_framebuffer_type) { - common_hal_videocore_framebuffer_deinit(&displays[i].videocore); + } else if (bus_type == &videocore_framebuffer_type) { + common_hal_videocore_framebuffer_deinit(&display_buses[i].videocore); #endif #if CIRCUITPY_PICODVI } else if (displays[i].bus_base.type == &picodvi_framebuffer_type) { common_hal_picodvi_framebuffer_deinit(&displays[i].picodvi); #endif } - displays[i].fourwire_bus.base.type = &mp_type_NoneType; + display_buses[i].bus_base.type = &mp_type_NoneType; } supervisor_stop_terminal(); @@ -166,10 +167,11 @@ void common_hal_displayio_release_displays(void) { void reset_displays(void) { // The SPI buses used by FourWires may be allocated on the heap so we need to move them inline. for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { - if (displays[i].fourwire_bus.base.type == &displayio_fourwire_type) { - displayio_fourwire_obj_t *fourwire = &displays[i].fourwire_bus; - if (((size_t)fourwire->bus) < ((size_t)&displays) || - ((size_t)fourwire->bus) > ((size_t)&displays + CIRCUITPY_DISPLAY_LIMIT)) { + mp_const_obj_t display_bus_type = display_buses[i].bus_base.type; + if (display_bus_type == &displayio_fourwire_type) { + displayio_fourwire_obj_t *fourwire = &display_buses[i].fourwire_bus; + if (((size_t)fourwire->bus) < ((size_t)&display_buses) || + ((size_t)fourwire->bus) > ((size_t)&display_buses + CIRCUITPY_DISPLAY_LIMIT * sizeof(primary_display_bus_t))) { busio_spi_obj_t *original_spi = fourwire->bus; #if CIRCUITPY_BOARD_SPI // We don't need to move original_spi if it is a board.SPI object because it is @@ -186,18 +188,19 @@ void reset_displays(void) { #endif memcpy(&fourwire->inline_bus, original_spi, sizeof(busio_spi_obj_t)); fourwire->bus = &fourwire->inline_bus; - // Check for other displays that use the same spi bus and swap them too. + // Check for other display buses that use the same spi bus and swap them too. for (uint8_t j = i + 1; j < CIRCUITPY_DISPLAY_LIMIT; j++) { - if (displays[i].fourwire_bus.base.type == &displayio_fourwire_type && - displays[i].fourwire_bus.bus == original_spi) { - displays[i].fourwire_bus.bus = &fourwire->inline_bus; + if (display_buses[j].fourwire_bus.base.type == &displayio_fourwire_type && + display_buses[j].fourwire_bus.bus == original_spi) { + display_buses[j].fourwire_bus.bus = &fourwire->inline_bus; } } } - } else if (displays[i].i2cdisplay_bus.base.type == &displayio_i2cdisplay_type) { - displayio_i2cdisplay_obj_t *i2c = &displays[i].i2cdisplay_bus; - if (((size_t)i2c->bus) < ((size_t)&displays) || - ((size_t)i2c->bus) > ((size_t)&displays + CIRCUITPY_DISPLAY_LIMIT)) { + } else if (display_bus_type == &displayio_i2cdisplay_type) { + displayio_i2cdisplay_obj_t *i2c = &display_buses[i].i2cdisplay_bus; + // Check to see if we need to inline the I2C bus. + if (((size_t)i2c->bus) < ((size_t)&display_buses) || + ((size_t)i2c->bus) > ((size_t)&display_buses + CIRCUITPY_DISPLAY_LIMIT * sizeof(primary_display_bus_t))) { busio_i2c_obj_t *original_i2c = i2c->bus; #if CIRCUITPY_BOARD_I2C // We don't need to move original_i2c if it is a board.I2C object because it is @@ -211,15 +214,15 @@ void reset_displays(void) { i2c->bus = &i2c->inline_bus; // Check for other displays that use the same i2c bus and swap them too. for (uint8_t j = i + 1; j < CIRCUITPY_DISPLAY_LIMIT; j++) { - if (displays[i].i2cdisplay_bus.base.type == &displayio_i2cdisplay_type && - displays[i].i2cdisplay_bus.bus == original_i2c) { - displays[i].i2cdisplay_bus.bus = &i2c->inline_bus; + if (display_buses[j].i2cdisplay_bus.base.type == &displayio_i2cdisplay_type && + display_buses[j].i2cdisplay_bus.bus == original_i2c) { + display_buses[j].i2cdisplay_bus.bus = &i2c->inline_bus; } } } #if CIRCUITPY_RGBMATRIX - } else if (displays[i].rgbmatrix.base.type == &rgbmatrix_RGBMatrix_type) { - rgbmatrix_rgbmatrix_obj_t *pm = &displays[i].rgbmatrix; + } else if (display_bus_type == &rgbmatrix_RGBMatrix_type) { + rgbmatrix_rgbmatrix_obj_t *pm = &display_buses[i].rgbmatrix; if (!any_display_uses_this_framebuffer(&pm->base)) { common_hal_rgbmatrix_rgbmatrix_deinit(pm); } else { @@ -227,11 +230,11 @@ void reset_displays(void) { } #endif #if CIRCUITPY_IS31FL3741 - } else if (displays[i].is31fl3741.base.type == &is31fl3741_FrameBuffer_type) { - is31fl3741_FrameBuffer_obj_t *is31fb = &displays[i].is31fl3741; + } else if (display_bus_type == &is31fl3741_FrameBuffer_type) { + is31fl3741_FrameBuffer_obj_t *is31fb = &display_buses[i].is31fl3741; - if (((uint32_t)is31fb->is31fl3741->i2c) < ((uint32_t)&displays) || - ((uint32_t)is31fb->is31fl3741->i2c) > ((uint32_t)&displays + CIRCUITPY_DISPLAY_LIMIT)) { + if (((uint32_t)is31fb->is31fl3741->i2c) < ((uint32_t)&display_buses) || + ((uint32_t)is31fb->is31fl3741->i2c) > ((uint32_t)&display_buses + CIRCUITPY_DISPLAY_LIMIT)) { #if CIRCUITPY_BOARD_I2C // We don't need to move original_i2c if it is the board.I2C object because it is // statically allocated already. (Doing so would also make it impossible to reference in @@ -257,13 +260,13 @@ void reset_displays(void) { } #endif #if CIRCUITPY_SHARPDISPLAY - } else if (displays[i].bus_base.type == &sharpdisplay_framebuffer_type) { - sharpdisplay_framebuffer_obj_t *sharp = &displays[i].sharpdisplay; + } else if (display_bus_type == &sharpdisplay_framebuffer_type) { + sharpdisplay_framebuffer_obj_t *sharp = &display_buses[i].sharpdisplay; common_hal_sharpdisplay_framebuffer_reset(sharp); #endif #if CIRCUITPY_VIDEOCORE - } else if (displays[i].bus_base.type == &videocore_framebuffer_type) { - videocore_framebuffer_obj_t *vc = &displays[i].videocore; + } else if (display_bus_type == &videocore_framebuffer_type) { + videocore_framebuffer_obj_t *vc = &display_buses[i].videocore; if (!any_display_uses_this_framebuffer(&vc->base)) { common_hal_videocore_framebuffer_deinit(vc); } @@ -286,13 +289,14 @@ void reset_displays(void) { for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { // Reset the displayed group. Only the first will get the terminal but // that's ok. - if (displays[i].display.base.type == &displayio_display_type) { + mp_const_obj_t display_type = displays[i].display_base.type; + if (display_type == &displayio_display_type) { reset_display(&displays[i].display); - } else if (displays[i].epaper_display.base.type == &displayio_epaperdisplay_type) { + } else if (display_type == &displayio_epaperdisplay_type) { displayio_epaperdisplay_obj_t *display = &displays[i].epaper_display; common_hal_displayio_epaperdisplay_show(display, NULL); #if CIRCUITPY_FRAMEBUFFERIO - } else if (displays[i].framebuffer_display.base.type == &framebufferio_framebufferdisplay_type) { + } else if (display_type == &framebufferio_framebufferdisplay_type) { framebufferio_framebufferdisplay_reset(&displays[i].framebuffer_display); #endif } @@ -301,35 +305,42 @@ void reset_displays(void) { void displayio_gc_collect(void) { for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { + mp_const_obj_t display_bus_type = display_buses[i].bus_base.type; + if (display_bus_type == NULL || display_bus_type == &mp_type_NoneType) { + continue; + } #if CIRCUITPY_RGBMATRIX - if (displays[i].rgbmatrix.base.type == &rgbmatrix_RGBMatrix_type) { - rgbmatrix_rgbmatrix_collect_ptrs(&displays[i].rgbmatrix); + if (display_bus_type == &rgbmatrix_RGBMatrix_type) { + rgbmatrix_rgbmatrix_collect_ptrs(&display_buses[i].rgbmatrix); } #endif #if CIRCUITPY_IS31FL3741 - if (displays[i].is31fl3741.base.type == &is31fl3741_FrameBuffer_type) { - is31fl3741_FrameBuffer_collect_ptrs(&displays[i].is31fl3741); + if (display_bus_type == &is31fl3741_FrameBuffer_type) { + is31fl3741_FrameBuffer_collect_ptrs(&display_buses[i].is31fl3741); } #endif #if CIRCUITPY_SHARPDISPLAY - if (displays[i].bus_base.type == &sharpdisplay_framebuffer_type) { - common_hal_sharpdisplay_framebuffer_collect_ptrs(&displays[i].sharpdisplay); + if (display_bus_type == &sharpdisplay_framebuffer_type) { + common_hal_sharpdisplay_framebuffer_collect_ptrs(&display_buses[i].sharpdisplay); } #endif + } - if (displays[i].display.base.type == NULL) { + for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { + mp_const_obj_t display_type = displays[i].display_base.type; + if (display_type == NULL || display_type == &mp_type_NoneType) { continue; } // Alternatively, we could use gc_collect_root over the whole object, // but this is more precise, and is the only field that needs marking. - if (displays[i].display.base.type == &displayio_display_type) { + if (display_type == &displayio_display_type) { displayio_display_collect_ptrs(&displays[i].display); #if CIRCUITPY_FRAMEBUFFERIO - } else if (displays[i].framebuffer_display.base.type == &framebufferio_framebufferdisplay_type) { + } else if (display_type == &framebufferio_framebufferdisplay_type) { framebufferio_framebufferdisplay_collect_ptrs(&displays[i].framebuffer_display); #endif - } else if (displays[i].epaper_display.base.type == &displayio_epaperdisplay_type) { + } else if (display_type == &displayio_epaperdisplay_type) { displayio_epaperdisplay_collect_ptrs(&displays[i].epaper_display); } } @@ -339,6 +350,10 @@ primary_display_t *allocate_display(void) { for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { mp_const_obj_t display_type = displays[i].display.base.type; if (display_type == NULL || display_type == &mp_type_NoneType) { + // Clear this memory so it is in a known state before init. + memset(&displays[i], 0, sizeof(displays[i])); + // Default to None so that it works as board.DISPLAY. + displays[i].display_base.type = &mp_type_NoneType; return &displays[i]; } } @@ -352,18 +367,22 @@ primary_display_t *allocate_display_or_raise(void) { } mp_raise_RuntimeError(translate("Too many displays")); } -primary_display_t *allocate_display_bus(void) { + +primary_display_bus_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; + mp_const_obj_t display_bus_type = display_buses[i].bus_base.type; if (display_bus_type == NULL || display_bus_type == &mp_type_NoneType) { - return &displays[i]; + // Clear this memory so it is in a known state before init. + memset(&display_buses[i], 0, sizeof(display_buses[i])); + display_buses[i].bus_base.type = &mp_type_NoneType; + return &display_buses[i]; } } return NULL; } -primary_display_t *allocate_display_bus_or_raise(void) { - primary_display_t *result = allocate_display_bus(); +primary_display_bus_t *allocate_display_bus_or_raise(void) { + primary_display_bus_t *result = allocate_display_bus(); if (result) { return result; } diff --git a/shared-module/displayio/__init__.h b/shared-module/displayio/__init__.h index b450cb711d..1add0133b6 100644 --- a/shared-module/displayio/__init__.h +++ b/shared-module/displayio/__init__.h @@ -79,6 +79,9 @@ typedef struct { picodvi_framebuffer_obj_t picodvi; #endif }; +} primary_display_bus_t; + +typedef struct { union { mp_obj_base_t display_base; displayio_display_obj_t display; @@ -89,6 +92,7 @@ typedef struct { }; } primary_display_t; +extern primary_display_bus_t display_buses[CIRCUITPY_DISPLAY_LIMIT]; extern primary_display_t displays[CIRCUITPY_DISPLAY_LIMIT]; extern displayio_group_t circuitpython_splash; @@ -99,7 +103,7 @@ void displayio_gc_collect(void); primary_display_t *allocate_display(void); primary_display_t *allocate_display_or_raise(void); -primary_display_t *allocate_display_bus(void); -primary_display_t *allocate_display_bus_or_raise(void); +primary_display_bus_t *allocate_display_bus(void); +primary_display_bus_t *allocate_display_bus_or_raise(void); #endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO___INIT___H diff --git a/shared-module/displayio/display_core.c b/shared-module/displayio/display_core.c index c21d87316d..8e6d51084e 100644 --- a/shared-module/displayio/display_core.c +++ b/shared-module/displayio/display_core.c @@ -47,7 +47,9 @@ void displayio_display_core_construct(displayio_display_core_t *self, mp_obj_t bus, uint16_t width, uint16_t height, uint16_t ram_width, uint16_t ram_height, int16_t colstart, int16_t rowstart, uint16_t rotation, - uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row, uint8_t bytes_per_cell, bool reverse_pixels_in_byte, bool reverse_bytes_in_word) { + uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row, uint8_t bytes_per_cell, bool reverse_pixels_in_byte, bool reverse_bytes_in_word, + uint16_t column_command, uint16_t row_command, uint16_t set_current_column_command, uint16_t set_current_row_command, + bool data_as_commands, bool always_toggle_chip_select, bool SH1107_addressing, bool address_little_endian) { self->colorspace.depth = color_depth; self->colorspace.grayscale = grayscale; self->colorspace.grayscale_bit = 8 - color_depth; @@ -61,6 +63,15 @@ void displayio_display_core_construct(displayio_display_core_t *self, self->rowstart = rowstart; self->last_refresh = 0; + self->column_command = column_command; + self->row_command = row_command; + self->set_current_column_command = set_current_column_command; + self->set_current_row_command = set_current_row_command; + self->data_as_commands = data_as_commands; + self->always_toggle_chip_select = always_toggle_chip_select; + self->SH1107_addressing = SH1107_addressing; + self->address_little_endian = address_little_endian; + // (framebufferdisplay already validated its 'bus' is a buffer-protocol object) if (bus) { #if CIRCUITPY_PARALLELDISPLAY @@ -214,10 +225,7 @@ void displayio_display_core_end_transaction(displayio_display_core_t *self) { self->end_transaction(self->bus); } -void displayio_display_core_set_region_to_update(displayio_display_core_t *self, uint8_t column_command, - uint8_t row_command, uint16_t set_current_column_command, uint16_t set_current_row_command, - bool data_as_commands, bool always_toggle_chip_select, - displayio_area_t *area, bool SH1107_addressing) { +void displayio_display_core_set_region_to_update(displayio_display_core_t *self, displayio_area_t *area) { uint16_t x1 = area->x1 + self->colstart; uint16_t x2 = area->x2 + self->colstart; uint16_t y1 = area->y1 + self->rowstart; @@ -239,17 +247,17 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self, y2 -= 1; display_chip_select_behavior_t chip_select = CHIP_SELECT_UNTOUCHED; - if (always_toggle_chip_select || data_as_commands) { + if (self->always_toggle_chip_select || self->data_as_commands) { chip_select = CHIP_SELECT_TOGGLE_EVERY_BYTE; } // Set column. displayio_display_core_begin_transaction(self); uint8_t data[5]; - data[0] = column_command; + data[0] = self->column_command; uint8_t data_length = 1; display_byte_type_t data_type = DISPLAY_DATA; - if (!data_as_commands) { + if (!self->data_as_commands) { self->send(self->bus, DISPLAY_COMMAND, CHIP_SELECT_UNTOUCHED, data, 1); data_length = 0; } else { @@ -260,6 +268,10 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self, data[data_length++] = x1; data[data_length++] = x2; } else { + if (self->address_little_endian) { + x1 = __builtin_bswap16(x1); + x2 = __builtin_bswap16(x2); + } data[data_length++] = x1 >> 8; data[data_length++] = x1 & 0xff; data[data_length++] = x2 >> 8; @@ -268,7 +280,7 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self, // Quirk for SH1107 "SH1107_addressing" // Column lower command = 0x00, Column upper command = 0x10 - if (SH1107_addressing) { + if (self->SH1107_addressing) { data[0] = ((x1 >> 4) & 0x0F) | 0x10; // 0x10 to 0x17 data[1] = x1 & 0x0F; // 0x00 to 0x0F data_length = 2; @@ -277,10 +289,11 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self, self->send(self->bus, data_type, chip_select, data, data_length); displayio_display_core_end_transaction(self); - if (set_current_column_command != NO_COMMAND) { - uint8_t command = set_current_column_command; + if (self->set_current_column_command != NO_COMMAND) { + uint8_t command = self->set_current_column_command; displayio_display_core_begin_transaction(self); self->send(self->bus, DISPLAY_COMMAND, chip_select, &command, 1); + // Only send the first half of data because it is the first coordinate. self->send(self->bus, DISPLAY_DATA, chip_select, data, data_length / 2); displayio_display_core_end_transaction(self); } @@ -288,9 +301,9 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self, // Set row. displayio_display_core_begin_transaction(self); - data[0] = row_command; + data[0] = self->row_command; data_length = 1; - if (!data_as_commands) { + if (!self->data_as_commands) { self->send(self->bus, DISPLAY_COMMAND, CHIP_SELECT_UNTOUCHED, data, 1); data_length = 0; } @@ -299,6 +312,10 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self, data[data_length++] = y1; data[data_length++] = y2; } else { + if (self->address_little_endian) { + y1 = __builtin_bswap16(y1); + y2 = __builtin_bswap16(y2); + } data[data_length++] = y1 >> 8; data[data_length++] = y1 & 0xff; data[data_length++] = y2 >> 8; @@ -307,7 +324,7 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self, // Quirk for SH1107 "SH1107_addressing" // Page address command = 0xB0 - if (SH1107_addressing) { + if (self->SH1107_addressing) { // set the page to our y value data[0] = 0xB0 | y1; data_length = 1; @@ -316,10 +333,11 @@ void displayio_display_core_set_region_to_update(displayio_display_core_t *self, self->send(self->bus, data_type, chip_select, data, data_length); displayio_display_core_end_transaction(self); - if (set_current_row_command != NO_COMMAND) { - uint8_t command = set_current_row_command; + if (self->set_current_row_command != NO_COMMAND) { + uint8_t command = self->set_current_row_command; displayio_display_core_begin_transaction(self); self->send(self->bus, DISPLAY_COMMAND, chip_select, &command, 1); + // Only send the first half of data because it is the first coordinate. self->send(self->bus, DISPLAY_DATA, chip_select, data, data_length / 2); displayio_display_core_end_transaction(self); } diff --git a/shared-module/displayio/display_core.h b/shared-module/displayio/display_core.h index 2167683a0d..07e57fbc6a 100644 --- a/shared-module/displayio/display_core.h +++ b/shared-module/displayio/display_core.h @@ -53,13 +53,26 @@ typedef struct { _displayio_colorspace_t colorspace; int16_t colstart; int16_t rowstart; + + // Refresh area related. + uint16_t column_command; + uint16_t row_command; + uint16_t set_current_column_command; + uint16_t set_current_row_command; + bool data_as_commands; + bool always_toggle_chip_select; + bool SH1107_addressing; + bool address_little_endian; + bool full_refresh; // New group means we need to refresh the whole display. bool refresh_in_progress; } displayio_display_core_t; void displayio_display_core_construct(displayio_display_core_t *self, mp_obj_t bus, uint16_t width, uint16_t height, uint16_t ram_width, uint16_t ram_height, int16_t colstart, int16_t rowstart, uint16_t rotation, - uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row, uint8_t bytes_per_cell, bool reverse_pixels_in_byte, bool reverse_bytes_in_word); + uint16_t color_depth, bool grayscale, bool pixels_in_byte_share_row, uint8_t bytes_per_cell, bool reverse_pixels_in_byte, bool reverse_bytes_in_word, + uint16_t column_command, uint16_t row_command, uint16_t set_current_column_command, uint16_t set_current_row_command, + bool data_as_commands, bool always_toggle_chip_select, bool SH1107_addressing, bool address_little_endian); bool displayio_display_core_set_root_group(displayio_display_core_t *self, displayio_group_t *root_group); @@ -75,10 +88,7 @@ bool displayio_display_core_bus_free(displayio_display_core_t *self); bool displayio_display_core_begin_transaction(displayio_display_core_t *self); void displayio_display_core_end_transaction(displayio_display_core_t *self); -void displayio_display_core_set_region_to_update(displayio_display_core_t *self, uint8_t column_command, - uint8_t row_command, uint16_t set_current_column_command, uint16_t set_current_row_command, - bool data_as_commands, bool always_toggle_chip_select, - displayio_area_t *area, bool SH1107_addressing); +void displayio_display_core_set_region_to_update(displayio_display_core_t *self, displayio_area_t *area); void release_display_core(displayio_display_core_t *self); diff --git a/shared-module/framebufferio/FramebufferDisplay.c b/shared-module/framebufferio/FramebufferDisplay.c index 3d66370c04..6db2c3fec1 100644 --- a/shared-module/framebufferio/FramebufferDisplay.c +++ b/shared-module/framebufferio/FramebufferDisplay.c @@ -72,7 +72,10 @@ void common_hal_framebufferio_framebufferdisplay_construct(framebufferio_framebu fb_getter_default(get_pixels_in_byte_share_row, false), fb_getter_default(get_bytes_per_cell, 2), fb_getter_default(get_reverse_pixels_in_byte, false), - fb_getter_default(get_reverse_pixels_in_word, false) + fb_getter_default(get_reverse_pixels_in_word, false), + // Region update related settings that aren't used by framebuffer display. + NO_COMMAND, NO_COMMAND, NO_COMMAND, NO_COMMAND, + false, false, false, false ); self->first_pixel_offset = fb_getter_default(get_first_pixel_offset, 0); diff --git a/supervisor/shared/display.c b/supervisor/shared/display.c index 5ab00d4f8a..939a13340d 100644 --- a/supervisor/shared/display.c +++ b/supervisor/shared/display.c @@ -189,14 +189,14 @@ void supervisor_display_move_memory(void) { #if CIRCUITPY_DISPLAYIO for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) { #if CIRCUITPY_RGBMATRIX - if (displays[i].rgbmatrix.base.type == &rgbmatrix_RGBMatrix_type) { - rgbmatrix_rgbmatrix_obj_t *pm = &displays[i].rgbmatrix; + if (display_buses[i].rgbmatrix.base.type == &rgbmatrix_RGBMatrix_type) { + rgbmatrix_rgbmatrix_obj_t *pm = &display_buses[i].rgbmatrix; common_hal_rgbmatrix_rgbmatrix_reconstruct(pm, NULL); } #endif #if CIRCUITPY_SHARPDISPLAY - if (displays[i].bus_base.type == &sharpdisplay_framebuffer_type) { - sharpdisplay_framebuffer_obj_t *sharp = &displays[i].sharpdisplay; + if (display_buses[i].bus_base.type == &sharpdisplay_framebuffer_type) { + sharpdisplay_framebuffer_obj_t *sharp = &display_buses[i].sharpdisplay; common_hal_sharpdisplay_framebuffer_reconstruct(sharp); } #endif From d5b747b305597c89430bfd8d7585340d93cfe012 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 21 Apr 2023 13:23:01 -0700 Subject: [PATCH 051/117] Fix board inits --- ports/atmel-samd/boards/hallowing_m0_express/board.c | 4 ++-- ports/atmel-samd/boards/hallowing_m4_express/board.c | 6 +++--- ports/atmel-samd/boards/monster_m4sk/board.c | 6 +++--- ports/atmel-samd/boards/openbook_m4/board.c | 6 +++--- ports/atmel-samd/boards/pewpew_lcd/board.c | 6 +++--- ports/atmel-samd/boards/pewpew_m4/board.c | 6 +++--- ports/atmel-samd/boards/pybadge/board.c | 6 +++--- ports/atmel-samd/boards/pygamer/board.c | 6 +++--- ports/atmel-samd/boards/pyportal/board.c | 4 ++-- ports/atmel-samd/boards/pyportal_titano/board.c | 4 ++-- ports/atmel-samd/boards/seeeduino_wio_terminal/board.c | 6 +++--- ports/atmel-samd/boards/ugame10/board.c | 4 ++-- ports/broadcom/boards/diodes_delight_piunora/board.c | 2 +- ports/broadcom/boards/raspberrypi_cm4/board.c | 2 +- ports/broadcom/boards/raspberrypi_cm4io/board.c | 2 +- ports/broadcom/boards/raspberrypi_pi4b/board.c | 2 +- ports/broadcom/boards/raspberrypi_zero/board.c | 2 +- ports/broadcom/boards/raspberrypi_zero2w/board.c | 2 +- ports/broadcom/boards/raspberrypi_zero_w/board.c | 2 +- ports/espressif/boards/01space_lcd042_esp32c3/board.c | 6 +++--- ports/espressif/boards/adafruit_esp32s2_camera/board.c | 4 ++-- .../boards/adafruit_feather_esp32s2_reverse_tft/board.c | 4 ++-- .../espressif/boards/adafruit_feather_esp32s2_tft/board.c | 4 ++-- .../boards/adafruit_feather_esp32s3_reverse_tft/board.c | 4 ++-- .../espressif/boards/adafruit_feather_esp32s3_tft/board.c | 4 ++-- ports/espressif/boards/adafruit_funhouse/board.c | 6 +++--- .../boards/adafruit_magtag_2.9_grayscale/board.c | 6 +++--- ports/espressif/boards/espressif_esp32s3_box/board.c | 6 +++--- ports/espressif/boards/espressif_esp32s3_box_lite/board.c | 6 +++--- ports/espressif/boards/espressif_esp32s3_eye/board.c | 4 ++-- .../espressif/boards/espressif_esp32s3_usb_otg_n8/board.c | 6 +++--- ports/espressif/boards/hardkernel_odroid_go/board.c | 6 +++--- ports/espressif/boards/hexky_s2/board.c | 4 ++-- ports/espressif/boards/hiibot_iots2/board.c | 6 +++--- ports/espressif/boards/lilygo_tembed_esp32s3/board.c | 6 +++--- ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c | 6 +++--- .../boards/lilygo_ttgo_tdisplay_esp32_16m/board.c | 6 +++--- ports/espressif/boards/lilygo_twatch_2020_v3/board.c | 6 +++--- ports/espressif/boards/lolin_s2_pico/board.c | 4 ++-- ports/espressif/boards/m5stack_core2/board.c | 4 ++-- ports/espressif/boards/m5stack_core_basic/board.c | 4 ++-- ports/espressif/boards/m5stack_core_fire/board.c | 4 ++-- ports/espressif/boards/m5stack_stick_c/board.c | 6 +++--- ports/espressif/boards/morpheans_morphesp-240/board.c | 6 +++--- .../espressif/boards/waveshare_esp32_s2_pico_lcd/board.c | 6 +++--- ports/nrf/boards/clue_nrf52840_express/board.c | 6 +++--- ports/nrf/boards/hiibot_bluefi/board.c | 6 +++--- ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c | 6 +++--- ports/nrf/boards/ohs2020_badge/board.c | 6 +++--- .../boards/adafruit_feather_rp2040_dvi/board.c | 2 +- ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c | 6 +++--- ports/raspberrypi/boards/hack_club_sprig/board.c | 6 +++--- ports/raspberrypi/boards/pimoroni_badger2040/board.c | 8 +++----- ports/raspberrypi/boards/pimoroni_picosystem/board.c | 6 +++--- .../raspberrypi/boards/waveshare_rp2040_lcd_0_96/board.c | 6 +++--- ports/stm/boards/meowbit_v121/board.c | 4 ++-- 56 files changed, 136 insertions(+), 138 deletions(-) diff --git a/ports/atmel-samd/boards/hallowing_m0_express/board.c b/ports/atmel-samd/boards/hallowing_m0_express/board.c index aeea62d2a2..357cda495c 100644 --- a/ports/atmel-samd/boards/hallowing_m0_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m0_express/board.c @@ -69,7 +69,7 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; bus->base.type = &displayio_fourwire_type; busio_spi_obj_t *spi = common_hal_board_create_spi(0); common_hal_busio_spi_never_reset(spi); @@ -82,7 +82,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/atmel-samd/boards/hallowing_m4_express/board.c b/ports/atmel-samd/boards/hallowing_m4_express/board.c index 5003c904bc..c070db6e52 100644 --- a/ports/atmel-samd/boards/hallowing_m4_express/board.c +++ b/ports/atmel-samd/boards/hallowing_m4_express/board.c @@ -47,11 +47,11 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_PA01, &pin_PA00, NULL, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -62,7 +62,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/atmel-samd/boards/monster_m4sk/board.c b/ports/atmel-samd/boards/monster_m4sk/board.c index 76c96bba82..c67bc7dab9 100644 --- a/ports/atmel-samd/boards/monster_m4sk/board.c +++ b/ports/atmel-samd/boards/monster_m4sk/board.c @@ -48,11 +48,11 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA12, NULL, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -63,7 +63,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/atmel-samd/boards/openbook_m4/board.c b/ports/atmel-samd/boards/openbook_m4/board.c index ec1ba9f956..59c3bb4978 100644 --- a/ports/atmel-samd/boards/openbook_m4/board.c +++ b/ports/atmel-samd/boards/openbook_m4/board.c @@ -57,11 +57,11 @@ uint8_t refresh_sequence[] = { }; void board_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -72,7 +72,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_epaperdisplay_obj_t *display = &displays[0].epaper_display; + displayio_epaperdisplay_obj_t *display = &allocate_display()->epaper_display; display->base.type = &displayio_epaperdisplay_type; common_hal_displayio_epaperdisplay_construct(display, bus, diff --git a/ports/atmel-samd/boards/pewpew_lcd/board.c b/ports/atmel-samd/boards/pewpew_lcd/board.c index f4060571bf..8c058fb6d9 100644 --- a/ports/atmel-samd/boards/pewpew_lcd/board.c +++ b/ports/atmel-samd/boards/pewpew_lcd/board.c @@ -46,11 +46,11 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_PA23, &pin_PA22, NULL, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -61,7 +61,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/atmel-samd/boards/pewpew_m4/board.c b/ports/atmel-samd/boards/pewpew_m4/board.c index c36388f933..381af5ec16 100644 --- a/ports/atmel-samd/boards/pewpew_m4/board.c +++ b/ports/atmel-samd/boards/pewpew_m4/board.c @@ -97,11 +97,11 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA15, NULL, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -115,7 +115,7 @@ void board_init(void) { uint32_t cfg0 = lookupCfg(CFG_DISPLAY_CFG0, 0x000000); uint32_t offX = (cfg0 >> 8) & 0xff; uint32_t offY = (cfg0 >> 16) & 0xff; - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/atmel-samd/boards/pybadge/board.c b/ports/atmel-samd/boards/pybadge/board.c index 11db1ba0a8..4b5ac1dc19 100644 --- a/ports/atmel-samd/boards/pybadge/board.c +++ b/ports/atmel-samd/boards/pybadge/board.c @@ -68,11 +68,11 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -83,7 +83,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/atmel-samd/boards/pygamer/board.c b/ports/atmel-samd/boards/pygamer/board.c index 141365a4a1..84b81a4b4e 100644 --- a/ports/atmel-samd/boards/pygamer/board.c +++ b/ports/atmel-samd/boards/pygamer/board.c @@ -70,11 +70,11 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -85,7 +85,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/atmel-samd/boards/pyportal/board.c b/ports/atmel-samd/boards/pyportal/board.c index e304f6f24b..49dd831c4d 100644 --- a/ports/atmel-samd/boards/pyportal/board.c +++ b/ports/atmel-samd/boards/pyportal/board.c @@ -61,7 +61,7 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - paralleldisplay_parallelbus_obj_t *bus = &displays[0].parallel_bus; + paralleldisplay_parallelbus_obj_t *bus = &allocate_display_bus()->parallel_bus; bus->base.type = ¶lleldisplay_parallelbus_type; common_hal_paralleldisplay_parallelbus_construct(bus, &pin_PA16, // Data0 @@ -72,7 +72,7 @@ void board_init(void) { &pin_PA00, // Reset 0); // Frequency - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/atmel-samd/boards/pyportal_titano/board.c b/ports/atmel-samd/boards/pyportal_titano/board.c index 939a2dcc70..f938456599 100644 --- a/ports/atmel-samd/boards/pyportal_titano/board.c +++ b/ports/atmel-samd/boards/pyportal_titano/board.c @@ -78,7 +78,7 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - paralleldisplay_parallelbus_obj_t *bus = &displays[0].parallel_bus; + paralleldisplay_parallelbus_obj_t *bus = &allocate_display_bus()->parallel_bus; bus->base.type = ¶lleldisplay_parallelbus_type; common_hal_paralleldisplay_parallelbus_construct(bus, &pin_PA16, // Data0 @@ -89,7 +89,7 @@ void board_init(void) { &pin_PA00, // Reset 0); // Frequency - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/atmel-samd/boards/seeeduino_wio_terminal/board.c b/ports/atmel-samd/boards/seeeduino_wio_terminal/board.c index 2eddb41fd6..6a18d4ea84 100644 --- a/ports/atmel-samd/boards/seeeduino_wio_terminal/board.c +++ b/ports/atmel-samd/boards/seeeduino_wio_terminal/board.c @@ -65,11 +65,11 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_PB20, &pin_PB19, NULL, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -80,7 +80,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/atmel-samd/boards/ugame10/board.c b/ports/atmel-samd/boards/ugame10/board.c index 9953f27d02..6db511d775 100644 --- a/ports/atmel-samd/boards/ugame10/board.c +++ b/ports/atmel-samd/boards/ugame10/board.c @@ -70,7 +70,7 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; bus->base.type = &displayio_fourwire_type; busio_spi_obj_t *spi = common_hal_board_create_spi(0); common_hal_displayio_fourwire_construct(bus, @@ -82,7 +82,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/broadcom/boards/diodes_delight_piunora/board.c b/ports/broadcom/boards/diodes_delight_piunora/board.c index e272a8cc3d..ab9454298c 100644 --- a/ports/broadcom/boards/diodes_delight_piunora/board.c +++ b/ports/broadcom/boards/diodes_delight_piunora/board.c @@ -36,7 +36,7 @@ void board_init(void) { fb->base.type = &videocore_framebuffer_type; common_hal_videocore_framebuffer_construct(fb, 640, 480); - framebufferio_framebufferdisplay_obj_t *display = &displays[0].framebuffer_display; + framebufferio_framebufferdisplay_obj_t *display = &allocate_display()->framebuffer_display; display->base.type = &framebufferio_framebufferdisplay_type; common_hal_framebufferio_framebufferdisplay_construct( display, diff --git a/ports/broadcom/boards/raspberrypi_cm4/board.c b/ports/broadcom/boards/raspberrypi_cm4/board.c index e272a8cc3d..ab9454298c 100644 --- a/ports/broadcom/boards/raspberrypi_cm4/board.c +++ b/ports/broadcom/boards/raspberrypi_cm4/board.c @@ -36,7 +36,7 @@ void board_init(void) { fb->base.type = &videocore_framebuffer_type; common_hal_videocore_framebuffer_construct(fb, 640, 480); - framebufferio_framebufferdisplay_obj_t *display = &displays[0].framebuffer_display; + framebufferio_framebufferdisplay_obj_t *display = &allocate_display()->framebuffer_display; display->base.type = &framebufferio_framebufferdisplay_type; common_hal_framebufferio_framebufferdisplay_construct( display, diff --git a/ports/broadcom/boards/raspberrypi_cm4io/board.c b/ports/broadcom/boards/raspberrypi_cm4io/board.c index e272a8cc3d..ab9454298c 100644 --- a/ports/broadcom/boards/raspberrypi_cm4io/board.c +++ b/ports/broadcom/boards/raspberrypi_cm4io/board.c @@ -36,7 +36,7 @@ void board_init(void) { fb->base.type = &videocore_framebuffer_type; common_hal_videocore_framebuffer_construct(fb, 640, 480); - framebufferio_framebufferdisplay_obj_t *display = &displays[0].framebuffer_display; + framebufferio_framebufferdisplay_obj_t *display = &allocate_display()->framebuffer_display; display->base.type = &framebufferio_framebufferdisplay_type; common_hal_framebufferio_framebufferdisplay_construct( display, diff --git a/ports/broadcom/boards/raspberrypi_pi4b/board.c b/ports/broadcom/boards/raspberrypi_pi4b/board.c index e272a8cc3d..ab9454298c 100644 --- a/ports/broadcom/boards/raspberrypi_pi4b/board.c +++ b/ports/broadcom/boards/raspberrypi_pi4b/board.c @@ -36,7 +36,7 @@ void board_init(void) { fb->base.type = &videocore_framebuffer_type; common_hal_videocore_framebuffer_construct(fb, 640, 480); - framebufferio_framebufferdisplay_obj_t *display = &displays[0].framebuffer_display; + framebufferio_framebufferdisplay_obj_t *display = &allocate_display()->framebuffer_display; display->base.type = &framebufferio_framebufferdisplay_type; common_hal_framebufferio_framebufferdisplay_construct( display, diff --git a/ports/broadcom/boards/raspberrypi_zero/board.c b/ports/broadcom/boards/raspberrypi_zero/board.c index e272a8cc3d..ab9454298c 100644 --- a/ports/broadcom/boards/raspberrypi_zero/board.c +++ b/ports/broadcom/boards/raspberrypi_zero/board.c @@ -36,7 +36,7 @@ void board_init(void) { fb->base.type = &videocore_framebuffer_type; common_hal_videocore_framebuffer_construct(fb, 640, 480); - framebufferio_framebufferdisplay_obj_t *display = &displays[0].framebuffer_display; + framebufferio_framebufferdisplay_obj_t *display = &allocate_display()->framebuffer_display; display->base.type = &framebufferio_framebufferdisplay_type; common_hal_framebufferio_framebufferdisplay_construct( display, diff --git a/ports/broadcom/boards/raspberrypi_zero2w/board.c b/ports/broadcom/boards/raspberrypi_zero2w/board.c index e272a8cc3d..ab9454298c 100644 --- a/ports/broadcom/boards/raspberrypi_zero2w/board.c +++ b/ports/broadcom/boards/raspberrypi_zero2w/board.c @@ -36,7 +36,7 @@ void board_init(void) { fb->base.type = &videocore_framebuffer_type; common_hal_videocore_framebuffer_construct(fb, 640, 480); - framebufferio_framebufferdisplay_obj_t *display = &displays[0].framebuffer_display; + framebufferio_framebufferdisplay_obj_t *display = &allocate_display()->framebuffer_display; display->base.type = &framebufferio_framebufferdisplay_type; common_hal_framebufferio_framebufferdisplay_construct( display, diff --git a/ports/broadcom/boards/raspberrypi_zero_w/board.c b/ports/broadcom/boards/raspberrypi_zero_w/board.c index e272a8cc3d..ab9454298c 100644 --- a/ports/broadcom/boards/raspberrypi_zero_w/board.c +++ b/ports/broadcom/boards/raspberrypi_zero_w/board.c @@ -36,7 +36,7 @@ void board_init(void) { fb->base.type = &videocore_framebuffer_type; common_hal_videocore_framebuffer_construct(fb, 640, 480); - framebufferio_framebufferdisplay_obj_t *display = &displays[0].framebuffer_display; + framebufferio_framebufferdisplay_obj_t *display = &allocate_display()->framebuffer_display; display->base.type = &framebufferio_framebufferdisplay_type; common_hal_framebufferio_framebufferdisplay_construct( display, diff --git a/ports/espressif/boards/01space_lcd042_esp32c3/board.c b/ports/espressif/boards/01space_lcd042_esp32c3/board.c index 56df21ab57..53f6e4a48e 100644 --- a/ports/espressif/boards/01space_lcd042_esp32c3/board.c +++ b/ports/espressif/boards/01space_lcd042_esp32c3/board.c @@ -55,11 +55,11 @@ void board_init(void) { busio_i2c_obj_t *i2c = common_hal_board_create_i2c(0); // What we would do if it wasn't the shared board I2C: (for reference) - // busio_i2c_obj_t *i2c = &displays[0].i2cdisplay_bus.inline_bus; + // busio_i2c_obj_t *i2c = &allocate_display_bus()->i2cdisplay_bus.inline_bus; // common_hal_busio_i2c_construct(i2c, &pin_GPIO23, &pin_GPIO22, 100000, 0); // common_hal_busio_i2c_never_reset(i2c); - displayio_i2cdisplay_obj_t *bus = &displays[0].i2cdisplay_bus; + displayio_i2cdisplay_obj_t *bus = &allocate_display_bus()->i2cdisplay_bus; bus->base.type = &displayio_i2cdisplay_type; common_hal_displayio_i2cdisplay_construct(bus, i2c, @@ -67,7 +67,7 @@ void board_init(void) { NULL ); - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/espressif/boards/adafruit_esp32s2_camera/board.c b/ports/espressif/boards/adafruit_esp32s2_camera/board.c index 280f2b14b8..4799a07b79 100644 --- a/ports/espressif/boards/adafruit_esp32s2_camera/board.c +++ b/ports/espressif/boards/adafruit_esp32s2_camera/board.c @@ -52,7 +52,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { busio_spi_obj_t *spi = common_hal_board_create_spi(0); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -63,7 +63,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct( display, diff --git a/ports/espressif/boards/adafruit_feather_esp32s2_reverse_tft/board.c b/ports/espressif/boards/adafruit_feather_esp32s2_reverse_tft/board.c index 360c71804c..ef6908d50a 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s2_reverse_tft/board.c +++ b/ports/espressif/boards/adafruit_feather_esp32s2_reverse_tft/board.c @@ -72,7 +72,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { busio_spi_obj_t *spi = common_hal_board_create_spi(0); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct( @@ -85,7 +85,7 @@ void board_init(void) { 0, // polarity 0 // phase ); - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct( diff --git a/ports/espressif/boards/adafruit_feather_esp32s2_tft/board.c b/ports/espressif/boards/adafruit_feather_esp32s2_tft/board.c index c5b47a2f95..ce0aa8d2b9 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s2_tft/board.c +++ b/ports/espressif/boards/adafruit_feather_esp32s2_tft/board.c @@ -72,7 +72,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { busio_spi_obj_t *spi = common_hal_board_create_spi(0); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct( @@ -85,7 +85,7 @@ void board_init(void) { 0, // polarity 0 // phase ); - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct( diff --git a/ports/espressif/boards/adafruit_feather_esp32s3_reverse_tft/board.c b/ports/espressif/boards/adafruit_feather_esp32s3_reverse_tft/board.c index 360c71804c..ef6908d50a 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s3_reverse_tft/board.c +++ b/ports/espressif/boards/adafruit_feather_esp32s3_reverse_tft/board.c @@ -72,7 +72,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { busio_spi_obj_t *spi = common_hal_board_create_spi(0); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct( @@ -85,7 +85,7 @@ void board_init(void) { 0, // polarity 0 // phase ); - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct( diff --git a/ports/espressif/boards/adafruit_feather_esp32s3_tft/board.c b/ports/espressif/boards/adafruit_feather_esp32s3_tft/board.c index 7e28aafb8e..18f361cc06 100644 --- a/ports/espressif/boards/adafruit_feather_esp32s3_tft/board.c +++ b/ports/espressif/boards/adafruit_feather_esp32s3_tft/board.c @@ -72,7 +72,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { busio_spi_obj_t *spi = common_hal_board_create_spi(0); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct( @@ -85,7 +85,7 @@ void board_init(void) { 0, // polarity 0 // phase ); - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct( diff --git a/ports/espressif/boards/adafruit_funhouse/board.c b/ports/espressif/boards/adafruit_funhouse/board.c index d89a4db268..b1a01b2dcb 100644 --- a/ports/espressif/boards/adafruit_funhouse/board.c +++ b/ports/espressif/boards/adafruit_funhouse/board.c @@ -56,11 +56,11 @@ void board_init(void) { common_hal_never_reset_pin(&pin_GPIO38); #endif /* DEBUG */ - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_GPIO36, &pin_GPIO35, NULL, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -71,7 +71,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct( display, diff --git a/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c b/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c index 681efc1cea..55c61a0912 100644 --- a/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c +++ b/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c @@ -120,11 +120,11 @@ void board_init(void) { common_hal_never_reset_pin(&pin_GPIO44); #endif /* DEBUG */ - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_GPIO36, &pin_GPIO35, NULL, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -135,7 +135,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_epaperdisplay_obj_t *display = &displays[0].epaper_display; + displayio_epaperdisplay_obj_t *display = &allocate_display()->epaper_display; display->base.type = &displayio_epaperdisplay_type; common_hal_displayio_epaperdisplay_construct( display, diff --git a/ports/espressif/boards/espressif_esp32s3_box/board.c b/ports/espressif/boards/espressif_esp32s3_box/board.c index 75c0ede92d..a91a924d04 100644 --- a/ports/espressif/boards/espressif_esp32s3_box/board.c +++ b/ports/espressif/boards/espressif_esp32s3_box/board.c @@ -43,11 +43,11 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_GPIO7, &pin_GPIO6, NULL, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -58,7 +58,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/espressif/boards/espressif_esp32s3_box_lite/board.c b/ports/espressif/boards/espressif_esp32s3_box_lite/board.c index 23c67d06b6..ddfab49797 100644 --- a/ports/espressif/boards/espressif_esp32s3_box_lite/board.c +++ b/ports/espressif/boards/espressif_esp32s3_box_lite/board.c @@ -44,11 +44,11 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_GPIO7, &pin_GPIO6, NULL, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -59,7 +59,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/espressif/boards/espressif_esp32s3_eye/board.c b/ports/espressif/boards/espressif_esp32s3_eye/board.c index be129c6a30..49535de902 100644 --- a/ports/espressif/boards/espressif_esp32s3_eye/board.c +++ b/ports/espressif/boards/espressif_esp32s3_eye/board.c @@ -71,7 +71,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { busio_spi_obj_t *spi = common_hal_board_create_spi(0); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct( @@ -84,7 +84,7 @@ void board_init(void) { 0, // polarity 0 // phase ); - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct( diff --git a/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c b/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c index 685e7cf156..afbb5ae8fb 100644 --- a/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c +++ b/ports/espressif/boards/espressif_esp32s3_usb_otg_n8/board.c @@ -71,11 +71,11 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_GPIO6, &pin_GPIO7, NULL, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -86,7 +86,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/espressif/boards/hardkernel_odroid_go/board.c b/ports/espressif/boards/hardkernel_odroid_go/board.c index 609572977e..54ecd27ff3 100644 --- a/ports/espressif/boards/hardkernel_odroid_go/board.c +++ b/ports/espressif/boards/hardkernel_odroid_go/board.c @@ -63,11 +63,11 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO23, NULL, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -78,7 +78,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/espressif/boards/hexky_s2/board.c b/ports/espressif/boards/hexky_s2/board.c index e4f8f48855..ef99a96e1d 100644 --- a/ports/espressif/boards/hexky_s2/board.c +++ b/ports/espressif/boards/hexky_s2/board.c @@ -72,7 +72,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { busio_spi_obj_t *spi = common_hal_board_create_spi(0); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct( @@ -85,7 +85,7 @@ void board_init(void) { 0, // polarity 0 // phase ); - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct( diff --git a/ports/espressif/boards/hiibot_iots2/board.c b/ports/espressif/boards/hiibot_iots2/board.c index c9cf7afb92..87ee7d0b14 100644 --- a/ports/espressif/boards/hiibot_iots2/board.c +++ b/ports/espressif/boards/hiibot_iots2/board.c @@ -65,7 +65,8 @@ uint8_t display_init_sequence[] = { }; static void display_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct( spi, @@ -76,7 +77,6 @@ static void display_init(void) { common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct( @@ -90,7 +90,7 @@ static void display_init(void) { 0 // phase ); - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct( diff --git a/ports/espressif/boards/lilygo_tembed_esp32s3/board.c b/ports/espressif/boards/lilygo_tembed_esp32s3/board.c index ed49eb504c..03a86a48d4 100644 --- a/ports/espressif/boards/lilygo_tembed_esp32s3/board.c +++ b/ports/espressif/boards/lilygo_tembed_esp32s3/board.c @@ -43,11 +43,11 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_GPIO12, &pin_GPIO11, NULL, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -58,7 +58,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c b/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c index 6c0a54c99c..7ba109dfce 100644 --- a/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c +++ b/ports/espressif/boards/lilygo_ttgo_t8_s2_st7789/board.c @@ -65,7 +65,8 @@ uint8_t display_init_sequence[] = { }; static void display_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct( spi, @@ -76,7 +77,6 @@ static void display_init(void) { common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct( @@ -90,7 +90,7 @@ static void display_init(void) { 0 // phase ); - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct( diff --git a/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/board.c b/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/board.c index 630de0b63f..916f1d0a78 100644 --- a/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/board.c +++ b/ports/espressif/boards/lilygo_ttgo_tdisplay_esp32_16m/board.c @@ -45,7 +45,8 @@ uint8_t display_init_sequence[] = { }; static void display_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct( spi, @@ -56,7 +57,6 @@ static void display_init(void) { common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct( @@ -71,7 +71,7 @@ static void display_init(void) { 0 // phase ); - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct( diff --git a/ports/espressif/boards/lilygo_twatch_2020_v3/board.c b/ports/espressif/boards/lilygo_twatch_2020_v3/board.c index 6a60ada6b0..de2b79b895 100644 --- a/ports/espressif/boards/lilygo_twatch_2020_v3/board.c +++ b/ports/espressif/boards/lilygo_twatch_2020_v3/board.c @@ -48,7 +48,8 @@ uint8_t display_init_sequence[] = { }; static void display_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct( spi, @@ -60,7 +61,6 @@ static void display_init(void) { common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct( @@ -74,7 +74,7 @@ static void display_init(void) { 0 // phase ); - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct( diff --git a/ports/espressif/boards/lolin_s2_pico/board.c b/ports/espressif/boards/lolin_s2_pico/board.c index e2c24bb22a..2f987799ad 100644 --- a/ports/espressif/boards/lolin_s2_pico/board.c +++ b/ports/espressif/boards/lolin_s2_pico/board.c @@ -54,7 +54,7 @@ uint8_t display_init_sequence[] = { // SSD1306 static void display_init(void) { busio_i2c_obj_t *i2c = common_hal_board_create_i2c(0); - displayio_i2cdisplay_obj_t *bus = &displays[0].i2cdisplay_bus; + displayio_i2cdisplay_obj_t *bus = &allocate_display_bus()->i2cdisplay_bus; bus->base.type = &displayio_i2cdisplay_type; common_hal_displayio_i2cdisplay_construct(bus, i2c, @@ -62,7 +62,7 @@ static void display_init(void) { &pin_GPIO18 // reset ); - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/espressif/boards/m5stack_core2/board.c b/ports/espressif/boards/m5stack_core2/board.c index a2565229ce..5080617df4 100644 --- a/ports/espressif/boards/m5stack_core2/board.c +++ b/ports/espressif/boards/m5stack_core2/board.c @@ -333,7 +333,7 @@ static bool pmic_init(busio_i2c_obj_t *i2c) { static bool display_init(void) { busio_spi_obj_t *spi = common_hal_board_create_spi(0); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct( @@ -347,7 +347,7 @@ static bool display_init(void) { 0 // phase ); - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct( diff --git a/ports/espressif/boards/m5stack_core_basic/board.c b/ports/espressif/boards/m5stack_core_basic/board.c index 2736bc758b..68eff30782 100644 --- a/ports/espressif/boards/m5stack_core_basic/board.c +++ b/ports/espressif/boards/m5stack_core_basic/board.c @@ -57,7 +57,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { busio_spi_obj_t *spi = common_hal_board_create_spi(0); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct( @@ -71,7 +71,7 @@ void board_init(void) { 0 // phase ); - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct( diff --git a/ports/espressif/boards/m5stack_core_fire/board.c b/ports/espressif/boards/m5stack_core_fire/board.c index 2736bc758b..68eff30782 100755 --- a/ports/espressif/boards/m5stack_core_fire/board.c +++ b/ports/espressif/boards/m5stack_core_fire/board.c @@ -57,7 +57,7 @@ uint8_t display_init_sequence[] = { void board_init(void) { busio_spi_obj_t *spi = common_hal_board_create_spi(0); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct( @@ -71,7 +71,7 @@ void board_init(void) { 0 // phase ); - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct( diff --git a/ports/espressif/boards/m5stack_stick_c/board.c b/ports/espressif/boards/m5stack_stick_c/board.c index d25663895c..e6a0125fb4 100755 --- a/ports/espressif/boards/m5stack_stick_c/board.c +++ b/ports/espressif/boards/m5stack_stick_c/board.c @@ -165,11 +165,11 @@ static bool pmic_init(busio_i2c_obj_t *i2c) { } static bool display_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_GPIO13, &pin_GPIO15, NULL, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct( @@ -183,7 +183,7 @@ static bool display_init(void) { 0 // phase ); - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct( diff --git a/ports/espressif/boards/morpheans_morphesp-240/board.c b/ports/espressif/boards/morpheans_morphesp-240/board.c index 30e0a04aad..9491902161 100644 --- a/ports/espressif/boards/morpheans_morphesp-240/board.c +++ b/ports/espressif/boards/morpheans_morphesp-240/board.c @@ -147,7 +147,8 @@ void board_init(void) { // Display - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct( spi, @@ -158,7 +159,6 @@ void board_init(void) { common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct( @@ -172,7 +172,7 @@ void board_init(void) { 0 // phase ); - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct( display, diff --git a/ports/espressif/boards/waveshare_esp32_s2_pico_lcd/board.c b/ports/espressif/boards/waveshare_esp32_s2_pico_lcd/board.c index 359263df81..2898f675c8 100644 --- a/ports/espressif/boards/waveshare_esp32_s2_pico_lcd/board.c +++ b/ports/espressif/boards/waveshare_esp32_s2_pico_lcd/board.c @@ -64,7 +64,8 @@ uint8_t display_init_sequence[] = { }; static void display_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct( spi, @@ -75,7 +76,6 @@ static void display_init(void) { common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct( @@ -89,7 +89,7 @@ static void display_init(void) { 0 // phase ); - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct( diff --git a/ports/nrf/boards/clue_nrf52840_express/board.c b/ports/nrf/boards/clue_nrf52840_express/board.c index 92ea3fefeb..98ec033dc6 100644 --- a/ports/nrf/boards/clue_nrf52840_express/board.c +++ b/ports/nrf/boards/clue_nrf52840_express/board.c @@ -47,11 +47,11 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_P0_14, &pin_P0_15, NULL, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -62,7 +62,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/nrf/boards/hiibot_bluefi/board.c b/ports/nrf/boards/hiibot_bluefi/board.c index e5fc4279f8..d2c9e732b2 100644 --- a/ports/nrf/boards/hiibot_bluefi/board.c +++ b/ports/nrf/boards/hiibot_bluefi/board.c @@ -47,11 +47,11 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_P0_07, &pin_P1_08, NULL, false); // SCK, MOSI, MISO, not half-duplex common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -63,7 +63,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c b/ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c index ce4241c9da..1fea4b2b9f 100644 --- a/ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c +++ b/ports/nrf/boards/makerdiary_nrf52840_m2_devkit/board.c @@ -48,11 +48,11 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_P0_11, &pin_P0_12, NULL, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -63,7 +63,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/nrf/boards/ohs2020_badge/board.c b/ports/nrf/boards/ohs2020_badge/board.c index 30c066d91e..568357eacb 100644 --- a/ports/nrf/boards/ohs2020_badge/board.c +++ b/ports/nrf/boards/ohs2020_badge/board.c @@ -47,11 +47,11 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_P0_11, &pin_P0_12, NULL, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -62,7 +62,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/board.c b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/board.c index bcbab5e4cd..140a15cc04 100644 --- a/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/board.c +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/board.c @@ -40,7 +40,7 @@ void board_init(void) { &pin_GPIO23, &pin_GPIO22, 8); - framebufferio_framebufferdisplay_obj_t *display = &displays[0].framebuffer_display; + framebufferio_framebufferdisplay_obj_t *display = &allocate_display()->framebuffer_display; display->base.type = &framebufferio_framebufferdisplay_type; common_hal_framebufferio_framebufferdisplay_construct( display, diff --git a/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c b/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c index b5cef1639d..25d8dbe831 100644 --- a/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c +++ b/ports/raspberrypi/boards/adafruit_macropad_rp2040/board.c @@ -59,11 +59,11 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_GPIO26, &pin_GPIO27, NULL, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -74,7 +74,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/raspberrypi/boards/hack_club_sprig/board.c b/ports/raspberrypi/boards/hack_club_sprig/board.c index 775e6ca5df..819d7943dc 100644 --- a/ports/raspberrypi/boards/hack_club_sprig/board.c +++ b/ports/raspberrypi/boards/hack_club_sprig/board.c @@ -78,11 +78,11 @@ uint8_t display_init_sequence[] = { void board_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, &pin_GPIO16, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -93,7 +93,7 @@ void board_init(void) { 0, 0); - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/raspberrypi/boards/pimoroni_badger2040/board.c b/ports/raspberrypi/boards/pimoroni_badger2040/board.c index 9eea472925..3331ee1e98 100644 --- a/ports/raspberrypi/boards/pimoroni_badger2040/board.c +++ b/ports/raspberrypi/boards/pimoroni_badger2040/board.c @@ -274,12 +274,12 @@ void board_init(void) { common_hal_digitalio_digitalinout_never_reset(&enable_pin_obj); // Set up the SPI object used to control the display - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, &pin_GPIO16, false); common_hal_busio_spi_never_reset(spi); // Set up the DisplayIO pin object - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -291,7 +291,7 @@ void board_init(void) { 0); // Phase // Set up the DisplayIO epaper object - displayio_epaperdisplay_obj_t *display = &displays[0].epaper_display; + displayio_epaperdisplay_obj_t *display = &allocate_display()->epaper_display; display->base.type = &displayio_epaperdisplay_type; common_hal_displayio_epaperdisplay_construct( display, @@ -329,10 +329,8 @@ void board_init(void) { void board_deinit(void) { displayio_epaperdisplay_obj_t *display = &displays[0].epaper_display; if (display->base.type == &displayio_epaperdisplay_type) { - size_t i = 0; while (common_hal_displayio_epaperdisplay_get_busy(display)) { RUN_BACKGROUND_TASKS; - i++; } } common_hal_displayio_release_displays(); diff --git a/ports/raspberrypi/boards/pimoroni_picosystem/board.c b/ports/raspberrypi/boards/pimoroni_picosystem/board.c index 600089f129..388c3f2417 100644 --- a/ports/raspberrypi/boards/pimoroni_picosystem/board.c +++ b/ports/raspberrypi/boards/pimoroni_picosystem/board.c @@ -64,11 +64,11 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct(spi, &pin_GPIO6, &pin_GPIO7, NULL, false); common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -79,7 +79,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, diff --git a/ports/raspberrypi/boards/waveshare_rp2040_lcd_0_96/board.c b/ports/raspberrypi/boards/waveshare_rp2040_lcd_0_96/board.c index afe3f87787..2c3ef18805 100644 --- a/ports/raspberrypi/boards/waveshare_rp2040_lcd_0_96/board.c +++ b/ports/raspberrypi/boards/waveshare_rp2040_lcd_0_96/board.c @@ -63,7 +63,8 @@ uint8_t display_init_sequence[] = { }; static void display_init(void) { - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; + busio_spi_obj_t *spi = &bus->inline_bus; common_hal_busio_spi_construct( spi, &pin_GPIO10, // CLK @@ -74,7 +75,6 @@ static void display_init(void) { common_hal_busio_spi_never_reset(spi); - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct( @@ -88,7 +88,7 @@ static void display_init(void) { 0 // phase ); - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct( display, diff --git a/ports/stm/boards/meowbit_v121/board.c b/ports/stm/boards/meowbit_v121/board.c index 0edf3d40e4..2d67daf806 100644 --- a/ports/stm/boards/meowbit_v121/board.c +++ b/ports/stm/boards/meowbit_v121/board.c @@ -70,7 +70,7 @@ uint8_t display_init_sequence[] = { }; void board_init(void) { - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; bus->base.type = &displayio_fourwire_type; busio_spi_obj_t *internal_spi = &supervisor_flash_spi_bus; common_hal_displayio_fourwire_construct(bus, @@ -82,7 +82,7 @@ void board_init(void) { 0, // Polarity 0); // Phase - displayio_display_obj_t *display = &displays[0].display; + displayio_display_obj_t *display = &allocate_display()->display; display->base.type = &displayio_display_type; common_hal_displayio_display_construct(display, bus, From b16037859cfb22ef5c9b308938ac7512696d488a Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 21 Apr 2023 14:36:35 -0700 Subject: [PATCH 052/117] Fix native epd boards --- ports/atmel-samd/boards/openbook_m4/board.c | 3 ++- .../boards/adafruit_magtag_2.9_grayscale/board.c | 3 ++- ports/raspberrypi/boards/pimoroni_badger2040/board.c | 3 ++- shared-module/displayio/__init__.c | 8 ++++---- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ports/atmel-samd/boards/openbook_m4/board.c b/ports/atmel-samd/boards/openbook_m4/board.c index 59c3bb4978..5867a279f4 100644 --- a/ports/atmel-samd/boards/openbook_m4/board.c +++ b/ports/atmel-samd/boards/openbook_m4/board.c @@ -106,7 +106,8 @@ void board_init(void) { false, // chip_select (don't always toggle chip select) false, // grayscale false, // acep - false); // two_byte_sequence_length + false, // two_byte_sequence_length + false); // address_little_endian } // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c b/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c index 55c61a0912..da070688ed 100644 --- a/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c +++ b/ports/espressif/boards/adafruit_magtag_2.9_grayscale/board.c @@ -167,7 +167,8 @@ void board_init(void) { false, // always_toggle_chip_select true, // grayscale false, // acep - false); // two_byte_sequence_length + false, // two_byte_sequence_length + false); // address_little_endian } bool espressif_board_reset_pin_number(gpio_num_t pin_number) { diff --git a/ports/raspberrypi/boards/pimoroni_badger2040/board.c b/ports/raspberrypi/boards/pimoroni_badger2040/board.c index 3331ee1e98..cd7cd3a194 100644 --- a/ports/raspberrypi/boards/pimoroni_badger2040/board.c +++ b/ports/raspberrypi/boards/pimoroni_badger2040/board.c @@ -323,7 +323,8 @@ void board_init(void) { false, // always_toggle_chip_select false, // grayscale false, // acep - false); // two_byte_sequence_length + false, // two_byte_sequence_length + false); // address_little_endian } void board_deinit(void) { diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index c47b19caea..e9431dee14 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -154,8 +154,8 @@ void common_hal_displayio_release_displays(void) { common_hal_videocore_framebuffer_deinit(&display_buses[i].videocore); #endif #if CIRCUITPY_PICODVI - } else if (displays[i].bus_base.type == &picodvi_framebuffer_type) { - common_hal_picodvi_framebuffer_deinit(&displays[i].picodvi); + } else if (bus_type == &picodvi_framebuffer_type) { + common_hal_picodvi_framebuffer_deinit(&display_buses[i].picodvi); #endif } display_buses[i].bus_base.type = &mp_type_NoneType; @@ -274,8 +274,8 @@ void reset_displays(void) { // need to be moved. #endif #if CIRCUITPY_PICODVI - } else if (displays[i].bus_base.type == &picodvi_framebuffer_type) { - picodvi_framebuffer_obj_t *vc = &displays[i].picodvi; + } else if (display_bus_type == &picodvi_framebuffer_type) { + picodvi_framebuffer_obj_t *vc = &display_buses[i].picodvi; if (!any_display_uses_this_framebuffer(&vc->base)) { common_hal_picodvi_framebuffer_deinit(vc); } From 031667ebd0bb3deb944962ea280aa2246b7103a6 Mon Sep 17 00:00:00 2001 From: George White Date: Fri, 21 Apr 2023 17:41:52 -0400 Subject: [PATCH 053/117] Added notes re the RTL8720D pins The Wio Terminal includes a RealTek RTL8720D as a companion to the main chip to provide WiFi and Bluetooth capabilities via eRPC over a UART connection. The WIO Terminal schematic labels some pins as the RXD/TXD for the UART, and that was captured in the board definition for CircuitPython. However, these pins may be used for logging in another mode, but they are not the main pins used to communicate with the RTL chip. The correct configuration is RX on PC24/pad 2 and TX on PB24/pad 0 of SERCOM 0. The comments on the pin definitions now reflect this situation, for anyone trying to get the WiFi/BLE to work on the Wio Terminal. --- ports/atmel-samd/boards/seeeduino_wio_terminal/pins.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ports/atmel-samd/boards/seeeduino_wio_terminal/pins.c b/ports/atmel-samd/boards/seeeduino_wio_terminal/pins.c index 0ff0f7b1ba..90daa8df00 100644 --- a/ports/atmel-samd/boards/seeeduino_wio_terminal/pins.c +++ b/ports/atmel-samd/boards/seeeduino_wio_terminal/pins.c @@ -95,13 +95,13 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_I2S_SDIN), MP_ROM_PTR(&pin_PA22) }, { MP_OBJ_NEW_QSTR(MP_QSTR_I2S_BCLK), MP_ROM_PTR(&pin_PB16) }, - // RTL8720D + // RTL8720D - follows the schematic, but see comments { MP_OBJ_NEW_QSTR(MP_QSTR_RTL_PWR), MP_ROM_PTR(&pin_PA18) }, // CHIP_PU - { MP_OBJ_NEW_QSTR(MP_QSTR_RTL_RXD), MP_ROM_PTR(&pin_PC22) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_RTL_TXD), MP_ROM_PTR(&pin_PC23) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_RTL_MOSI), MP_ROM_PTR(&pin_PB24) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_RTL_RXD), MP_ROM_PTR(&pin_PC22) }, // *NOT* THE MAIN RX FOR THE RTL CHIP (may be a log UART?) + { MP_OBJ_NEW_QSTR(MP_QSTR_RTL_TXD), MP_ROM_PTR(&pin_PC23) }, // *NOT* THE MAIN TX FOR THE RTL CHIP (may be a log UART?) + { MP_OBJ_NEW_QSTR(MP_QSTR_RTL_MOSI), MP_ROM_PTR(&pin_PB24) }, // used as the UART TX for the RTL chip { MP_OBJ_NEW_QSTR(MP_QSTR_RTL_CLK), MP_ROM_PTR(&pin_PB25) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_RTL_MISO), MP_ROM_PTR(&pin_PC24) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_RTL_MISO), MP_ROM_PTR(&pin_PC24) }, // used as the UART RX for the RTL chip { MP_OBJ_NEW_QSTR(MP_QSTR_RTL_CS), MP_ROM_PTR(&pin_PC25) }, { MP_OBJ_NEW_QSTR(MP_QSTR_RTL_READY), MP_ROM_PTR(&pin_PC20) }, // IRQ0 { MP_OBJ_NEW_QSTR(MP_QSTR_RTL_DIR), MP_ROM_PTR(&pin_PA19) }, // SYNC From 01197a96d15141b35093daf1f844f685a60b2a4a Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 21 Apr 2023 16:54:46 -0500 Subject: [PATCH 054/117] remove abs() from radius --- shared-module/vectorio/Circle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-module/vectorio/Circle.c b/shared-module/vectorio/Circle.c index ee83ad18b9..4f89e46163 100644 --- a/shared-module/vectorio/Circle.c +++ b/shared-module/vectorio/Circle.c @@ -23,7 +23,7 @@ void common_hal_vectorio_circle_set_on_dirty(vectorio_circle_t *self, vectorio_e uint32_t common_hal_vectorio_circle_get_pixel(void *obj, int16_t x, int16_t y) { vectorio_circle_t *self = obj; - int16_t radius = abs(self->radius); + int16_t radius = self->radius; x = abs(x); y = abs(y); if (x + y <= radius) { From 56fd7dcf0adf76eb838d2d76d3ba312f1d12e3d3 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 21 Apr 2023 18:00:16 -0500 Subject: [PATCH 055/117] add minimum validation for tilegrid size in terminalio.Terminal --- shared-bindings/terminalio/Terminal.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shared-bindings/terminalio/Terminal.c b/shared-bindings/terminalio/Terminal.c index 46e171ff7e..164999093a 100644 --- a/shared-bindings/terminalio/Terminal.c +++ b/shared-bindings/terminalio/Terminal.c @@ -85,6 +85,9 @@ STATIC mp_obj_t terminalio_terminal_make_new(const mp_obj_type_t *type, size_t n fontio_builtinfont_t *font = mp_arg_validate_type(args[ARG_font].u_obj, &fontio_builtinfont_type, MP_QSTR_font); + mp_arg_validate_int_min(scroll_area->width_in_tiles, 2, MP_QSTR_scroll_area_width); + mp_arg_validate_int_min(scroll_area->height_in_tiles, 2, MP_QSTR_scroll_area_height); + terminalio_terminal_obj_t *self = m_new_obj(terminalio_terminal_obj_t); self->base.type = &terminalio_terminal_type; From b59f0e17be471c5828287d3f136b8d9b92bdc85c Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 21 Apr 2023 15:59:11 -0700 Subject: [PATCH 056/117] Fix RP2040 idle Don't idle from main if we scheduled an interrupt for 0 ticks in the future. Have RP2040 detect wakes that happen between setting the timer and the idle call. Fixes #7361 --- main.c | 10 ++++++++-- ports/raspberrypi/supervisor/port.c | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index 9351d90529..ae8c339172 100644 --- a/main.c +++ b/main.c @@ -716,9 +716,15 @@ STATIC bool run_code_py(safe_mode_t safe_mode, bool *simulate_reset) { // time_to_next_change is in ms and ticks are slightly shorter so // we'll undersleep just a little. It shouldn't matter. - port_interrupt_after_ticks(time_to_next_change); - #endif + if (time_to_next_change > 0) { + port_interrupt_after_ticks(time_to_next_change); + port_idle_until_interrupt(); + } + #else + // No status LED can we sleep until we are interrupted by some + // interaction. port_idle_until_interrupt(); + #endif } } diff --git a/ports/raspberrypi/supervisor/port.c b/ports/raspberrypi/supervisor/port.c index 2ee3a1ee98..e45fa8837a 100644 --- a/ports/raspberrypi/supervisor/port.c +++ b/ports/raspberrypi/supervisor/port.c @@ -257,6 +257,7 @@ uint32_t port_get_saved_word(void) { } static volatile bool ticks_enabled; +static volatile bool _woken_up; uint64_t port_get_raw_ticks(uint8_t *subticks) { uint64_t microseconds = time_us_64(); @@ -268,6 +269,7 @@ STATIC void _tick_callback(uint alarm_num) { supervisor_tick(); hardware_alarm_set_target(0, delayed_by_us(get_absolute_time(), 977)); } + _woken_up = true; } // Enable 1/1024 second tick. @@ -291,11 +293,12 @@ void port_interrupt_after_ticks(uint32_t ticks) { if (!ticks_enabled) { hardware_alarm_set_target(0, delayed_by_us(get_absolute_time(), ticks * 977)); } + _woken_up = false; } void port_idle_until_interrupt(void) { common_hal_mcu_disable_interrupts(); - if (!background_callback_pending() && !tud_task_event_ready()) { + if (!background_callback_pending() && !tud_task_event_ready() && !_woken_up) { __DSB(); __WFI(); } From 73fde93218ddfcb7238c7ea538f05d68a5ddb27a Mon Sep 17 00:00:00 2001 From: Wellington Terumi Uemura Date: Fri, 21 Apr 2023 06:45:05 +0000 Subject: [PATCH 057/117] Translated using Weblate (Portuguese (Brazil)) Currently translated at 100.0% (999 of 999 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/pt_BR/ --- locale/pt_BR.po | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/locale/pt_BR.po b/locale/pt_BR.po index 5d02126604..c31b7e0134 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2023-04-07 00:49+0000\n" +"PO-Revision-Date: 2023-04-22 06:48+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.17-dev\n" +"X-Generator: Weblate 4.18-dev\n" #: main.c msgid "" @@ -1330,7 +1330,7 @@ msgstr "Tamanho do pedaço de formato inválido" #: shared-bindings/wifi/Radio.c msgid "Invalid hex password" -msgstr "" +msgstr "Senha hexadecimal inválida" #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" From 964a94929a1bec1f25253787bf904406b5936e40 Mon Sep 17 00:00:00 2001 From: Jonny Bergdahl Date: Thu, 20 Apr 2023 22:11:28 +0000 Subject: [PATCH 058/117] Translated using Weblate (Swedish) Currently translated at 100.0% (999 of 999 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/sv/ --- locale/sv.po | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/locale/sv.po b/locale/sv.po index 909c8a624f..c5dece498d 100644 --- a/locale/sv.po +++ b/locale/sv.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2023-04-07 00:49+0000\n" +"PO-Revision-Date: 2023-04-22 06:48+0000\n" "Last-Translator: Jonny Bergdahl \n" "Language-Team: LANGUAGE \n" "Language: sv\n" @@ -14,7 +14,7 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=n != 1;\n" -"X-Generator: Weblate 4.17-dev\n" +"X-Generator: Weblate 4.18-dev\n" #: main.c msgid "" @@ -1315,7 +1315,7 @@ msgstr "Ogiltig formatsegmentstorlek" #: shared-bindings/wifi/Radio.c msgid "Invalid hex password" -msgstr "" +msgstr "Ogiltigt hex-lösenord" #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" From 14b69d750f7ec60984069a42d92dfe504eac5d48 Mon Sep 17 00:00:00 2001 From: Andi Chandler Date: Thu, 20 Apr 2023 20:20:28 +0000 Subject: [PATCH 059/117] Translated using Weblate (English (United Kingdom)) Currently translated at 100.0% (999 of 999 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/en_GB/ --- locale/en_GB.po | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/locale/en_GB.po b/locale/en_GB.po index 06ad558ee1..4452427b1a 100644 --- a/locale/en_GB.po +++ b/locale/en_GB.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"PO-Revision-Date: 2023-04-16 13:51+0000\n" +"PO-Revision-Date: 2023-04-22 06:48+0000\n" "Last-Translator: Andi Chandler \n" "Language-Team: none\n" "Language: en_GB\n" @@ -15,7 +15,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.17-dev\n" +"X-Generator: Weblate 4.18-dev\n" #: main.c msgid "" @@ -1309,7 +1309,7 @@ msgstr "Invalid format chunk size" #: shared-bindings/wifi/Radio.c msgid "Invalid hex password" -msgstr "" +msgstr "Invalid hex password" #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" From a6545d6341c92201376a973f2e8e74815b76127e Mon Sep 17 00:00:00 2001 From: Jose David M Date: Sat, 22 Apr 2023 15:48:28 +0000 Subject: [PATCH 060/117] Translated using Weblate (Spanish) Currently translated at 100.0% (999 of 999 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/es/ --- locale/es.po | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/locale/es.po b/locale/es.po index f0604b74f4..c9ba32682f 100644 --- a/locale/es.po +++ b/locale/es.po @@ -8,7 +8,7 @@ msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2023-04-07 00:49+0000\n" +"PO-Revision-Date: 2023-04-22 15:51+0000\n" "Last-Translator: Jose David M \n" "Language-Team: \n" "Language: es\n" @@ -16,7 +16,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.17-dev\n" +"X-Generator: Weblate 4.18-dev\n" #: main.c msgid "" @@ -1334,7 +1334,7 @@ msgstr "Formato de fragmento de formato no válido" #: shared-bindings/wifi/Radio.c msgid "Invalid hex password" -msgstr "" +msgstr "Contraseña hexadecimal no válida" #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" From ccbb6a58fbefbb552098c11b81fd4886290c9975 Mon Sep 17 00:00:00 2001 From: Ted Hess Date: Sat, 22 Apr 2023 13:09:18 -0400 Subject: [PATCH 061/117] Fix web-editor debug on non-standard port using localhost (CORS) --- supervisor/shared/web_workflow/web_workflow.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/supervisor/shared/web_workflow/web_workflow.c b/supervisor/shared/web_workflow/web_workflow.c index 94732cf52c..648af72ccb 100644 --- a/supervisor/shared/web_workflow/web_workflow.c +++ b/supervisor/shared/web_workflow/web_workflow.c @@ -478,8 +478,12 @@ static bool _origin_ok(_request *request) { return true; } // DEBUG: OK if origin is 'localhost' (ignoring port #) - *strchrnul(&request->origin[PREFIX_HTTP_LEN], ':') = '\0'; + char *cptr = strchrnul(&request->origin[PREFIX_HTTP_LEN], ':'); + char csave = *cptr; // NULL or colon + *cptr = '\0'; if (strcmp(&request->origin[PREFIX_HTTP_LEN], "localhost") == 0) { + // Restore removed colon if non-null host terminator + *cptr = csave; return true; } } From b0ea28a031e85d1497793da3bd777933d036a282 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Sun, 23 Apr 2023 00:33:14 -0400 Subject: [PATCH 062/117] Doc fix for root_group=None behaviour --- shared-bindings/displayio/Display.c | 2 +- shared-bindings/displayio/EPaperDisplay.c | 2 +- shared-bindings/framebufferio/FramebufferDisplay.c | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 49194ebd1e..29bca28c3f 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -426,7 +426,7 @@ MP_PROPERTY_GETTER(displayio_display_bus_obj, //| root_group: Group //| """The root group on the display. -//| If the root group is set to ``None``, the default CircuitPython terminal will be shown. +//| If the root group is set to ``None``, no output will be shown. //| """ STATIC mp_obj_t displayio_display_obj_get_root_group(mp_obj_t self_in) { displayio_display_obj_t *self = native_display(self_in); diff --git a/shared-bindings/displayio/EPaperDisplay.c b/shared-bindings/displayio/EPaperDisplay.c index 93d91110a2..8c753de19b 100644 --- a/shared-bindings/displayio/EPaperDisplay.c +++ b/shared-bindings/displayio/EPaperDisplay.c @@ -384,7 +384,7 @@ MP_PROPERTY_GETTER(displayio_epaperdisplay_bus_obj, //| root_group: Group //| """The root group on the epaper display. -//| If the root group is set to ``None``, the default CircuitPython terminal will be shown. +//| If the root group is set to ``None``, no output will be shown. //| """ //| STATIC mp_obj_t displayio_epaperdisplay_obj_get_root_group(mp_obj_t self_in) { diff --git a/shared-bindings/framebufferio/FramebufferDisplay.c b/shared-bindings/framebufferio/FramebufferDisplay.c index 030b924c1e..7f27d3851c 100644 --- a/shared-bindings/framebufferio/FramebufferDisplay.c +++ b/shared-bindings/framebufferio/FramebufferDisplay.c @@ -323,8 +323,9 @@ STATIC mp_obj_t framebufferio_framebufferdisplay_obj_fill_row(size_t n_args, con MP_DEFINE_CONST_FUN_OBJ_KW(framebufferio_framebufferdisplay_fill_row_obj, 1, framebufferio_framebufferdisplay_obj_fill_row); //| root_group: displayio.Group -//| """The root group on the display.""" -//| +//| """The root group on the display. +//| If the root group is set to ``None``, no output will be shown. +//| """ STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_root_group(mp_obj_t self_in) { framebufferio_framebufferdisplay_obj_t *self = native_display(self_in); return common_hal_framebufferio_framebufferdisplay_get_root_group(self); From b2b24231bc68d199e36676c3ff77df36604fa296 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Sun, 23 Apr 2023 00:45:38 -0400 Subject: [PATCH 063/117] local pre-commit changes --- shared-bindings/framebufferio/FramebufferDisplay.c | 1 + shared-bindings/socketpool/SocketPool.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/framebufferio/FramebufferDisplay.c b/shared-bindings/framebufferio/FramebufferDisplay.c index 7f27d3851c..eb49f311b7 100644 --- a/shared-bindings/framebufferio/FramebufferDisplay.c +++ b/shared-bindings/framebufferio/FramebufferDisplay.c @@ -326,6 +326,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(framebufferio_framebufferdisplay_fill_row_obj, 1, fra //| """The root group on the display. //| If the root group is set to ``None``, no output will be shown. //| """ +//| STATIC mp_obj_t framebufferio_framebufferdisplay_obj_get_root_group(mp_obj_t self_in) { framebufferio_framebufferdisplay_obj_t *self = native_display(self_in); return common_hal_framebufferio_framebufferdisplay_get_root_group(self); diff --git a/shared-bindings/socketpool/SocketPool.c b/shared-bindings/socketpool/SocketPool.c index 3023721378..f056c741f3 100644 --- a/shared-bindings/socketpool/SocketPool.c +++ b/shared-bindings/socketpool/SocketPool.c @@ -52,7 +52,6 @@ //| returned by :py:attr:`wifi.radio` //| """ //| ... -//| STATIC mp_obj_t socketpool_socketpool_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, false); From 0c00220aa633dbc8e38ebedd6b06140c45e10589 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Sun, 23 Apr 2023 00:52:48 -0400 Subject: [PATCH 064/117] Removing unrelated change by local pre-commit --- shared-bindings/socketpool/SocketPool.c | 1 + 1 file changed, 1 insertion(+) diff --git a/shared-bindings/socketpool/SocketPool.c b/shared-bindings/socketpool/SocketPool.c index f056c741f3..3023721378 100644 --- a/shared-bindings/socketpool/SocketPool.c +++ b/shared-bindings/socketpool/SocketPool.c @@ -52,6 +52,7 @@ //| returned by :py:attr:`wifi.radio` //| """ //| ... +//| STATIC mp_obj_t socketpool_socketpool_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 1, 1, false); From 3cf712556b363fc2ce0f316152eaf4ba4400f04f Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Sun, 23 Apr 2023 01:03:13 -0400 Subject: [PATCH 065/117] Add CIRCUITPYTHON_TERMINAL usage description --- shared-bindings/displayio/Display.c | 1 + shared-bindings/displayio/EPaperDisplay.c | 1 + shared-bindings/framebufferio/FramebufferDisplay.c | 1 + 3 files changed, 3 insertions(+) diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 29bca28c3f..381924e0ab 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -426,6 +426,7 @@ MP_PROPERTY_GETTER(displayio_display_bus_obj, //| root_group: Group //| """The root group on the display. +//| If the root group is set to displayio.CIRCUITPYTHON_TERMINAL, the default CircuitPython terminal will be shown. //| If the root group is set to ``None``, no output will be shown. //| """ STATIC mp_obj_t displayio_display_obj_get_root_group(mp_obj_t self_in) { diff --git a/shared-bindings/displayio/EPaperDisplay.c b/shared-bindings/displayio/EPaperDisplay.c index 8c753de19b..8df3b31de9 100644 --- a/shared-bindings/displayio/EPaperDisplay.c +++ b/shared-bindings/displayio/EPaperDisplay.c @@ -384,6 +384,7 @@ MP_PROPERTY_GETTER(displayio_epaperdisplay_bus_obj, //| root_group: Group //| """The root group on the epaper display. +//| If the root group is set to displayio.CIRCUITPYTHON_TERMINAL, the default CircuitPython terminal will be shown. //| If the root group is set to ``None``, no output will be shown. //| """ //| diff --git a/shared-bindings/framebufferio/FramebufferDisplay.c b/shared-bindings/framebufferio/FramebufferDisplay.c index eb49f311b7..806d9957b4 100644 --- a/shared-bindings/framebufferio/FramebufferDisplay.c +++ b/shared-bindings/framebufferio/FramebufferDisplay.c @@ -324,6 +324,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(framebufferio_framebufferdisplay_fill_row_obj, 1, fra //| root_group: displayio.Group //| """The root group on the display. +//| If the root group is set to displayio.CIRCUITPYTHON_TERMINAL, the default CircuitPython terminal will be shown. //| If the root group is set to ``None``, no output will be shown. //| """ //| From 6aa3e7d8a6881df241240983f19cb06d05b52929 Mon Sep 17 00:00:00 2001 From: David Glaude Date: Sun, 23 Apr 2023 10:58:02 +0200 Subject: [PATCH 066/117] This is about picodvi not rgbmatrix There might be another way or other place where the documentation does not match the code. But this is the most obvious, that's why I found it. --- ports/raspberrypi/bindings/picodvi/Framebuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/raspberrypi/bindings/picodvi/Framebuffer.c b/ports/raspberrypi/bindings/picodvi/Framebuffer.c index 12482c3baa..67d6a286dd 100644 --- a/ports/raspberrypi/bindings/picodvi/Framebuffer.c +++ b/ports/raspberrypi/bindings/picodvi/Framebuffer.c @@ -142,7 +142,7 @@ STATIC mp_obj_t picodvi_framebuffer_make_new(const mp_obj_type_t *type, size_t n //| def deinit(self) -> None: //| """Free the resources (pins, timers, etc.) associated with this -//| rgbmatrix instance. After deinitialization, no further operations +//| picodvi instance. After deinitialization, no further operations //| may be performed.""" //| ... STATIC mp_obj_t picodvi_framebuffer_deinit(mp_obj_t self_in) { From 8e3c28e97dcca5795d9b7834f812841ec9e9a300 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 14 Apr 2023 13:43:24 -0500 Subject: [PATCH 067/117] Fix `memoryview.cast` in micropython-coverage `locals_dict` and `attr` are incompatible, so just use circuitpython-style properties so that a property and a method are both available. this makes no difference in circuitpython, where `MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE` is never enabled --- py/objarray.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/py/objarray.c b/py/objarray.c index 763ec15cdb..518c3aba52 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -31,6 +31,7 @@ #include "py/runtime.h" #include "py/binary.h" +#include "py/objproperty.h" #include "py/objstr.h" #include "py/objarray.h" @@ -270,15 +271,13 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(memoryview_cast_obj, memoryview_cast); #endif #if MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE -STATIC void memoryview_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { - if (dest[0] != MP_OBJ_NULL) { - return; - } - if (attr == MP_QSTR_itemsize) { - mp_obj_array_t *self = MP_OBJ_TO_PTR(self_in); - dest[0] = MP_OBJ_NEW_SMALL_INT(mp_binary_get_size('@', self->typecode & TYPECODE_MASK, NULL)); - } +STATIC mp_obj_t memoryview_itemsize_get(mp_obj_t self_in) { + mp_obj_array_t *self = MP_OBJ_TO_PTR(self_in); + return MP_OBJ_NEW_SMALL_INT(mp_binary_get_size('@', self->typecode & TYPECODE_MASK, NULL)); } +MP_DEFINE_CONST_FUN_OBJ_1(memoryview_itemsize_get_obj, memoryview_itemsize_get); + +MP_PROPERTY_GETTER(memoryview_itemsize_obj, (mp_obj_t)&memoryview_itemsize_get_obj); #endif #endif @@ -785,9 +784,14 @@ const mp_obj_type_t mp_type_bytearray = { #if MICROPY_PY_BUILTINS_MEMORYVIEW -#if MICROPY_CPYTHON_COMPAT +#if MICROPY_CPYTHON_COMPAT || MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE STATIC const mp_rom_map_elem_t memoryview_locals_dict_table[] = { + #if MICROPY_CPYTHON_COMPAT { MP_ROM_QSTR(MP_QSTR_cast), MP_ROM_PTR(&memoryview_cast_obj) }, + #endif + #if MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE + { MP_ROM_QSTR(MP_QSTR_itemsize), MP_ROM_PTR(&memoryview_itemsize_obj) }, + #endif }; STATIC MP_DEFINE_CONST_DICT(memoryview_locals_dict, memoryview_locals_dict_table); @@ -798,12 +802,9 @@ const mp_obj_type_t mp_type_memoryview = { .flags = MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE | MP_TYPE_FLAG_EXTENDED, .name = MP_QSTR_memoryview, .make_new = memoryview_make_new, - #if MICROPY_CPYTHON_COMPAT + #if MICROPY_CPYTHON_COMPAT || MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE .locals_dict = (mp_obj_dict_t *)&memoryview_locals_dict, #endif - #if MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE - .attr = memoryview_attr, - #endif MP_TYPE_EXTENDED_FIELDS( .getiter = array_iterator_new, .unary_op = array_unary_op, From 738f626663745fa55c812159ab76f4ffb13d430a Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 24 Apr 2023 12:54:37 -0400 Subject: [PATCH 068/117] Code formatting in doc --- shared-bindings/displayio/Display.c | 2 +- shared-bindings/displayio/EPaperDisplay.c | 2 +- shared-bindings/framebufferio/FramebufferDisplay.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 381924e0ab..451f2c770e 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -426,7 +426,7 @@ MP_PROPERTY_GETTER(displayio_display_bus_obj, //| root_group: Group //| """The root group on the display. -//| If the root group is set to displayio.CIRCUITPYTHON_TERMINAL, the default CircuitPython terminal will be shown. +//| If the root group is set to `displayio.CIRCUITPYTHON_TERMINAL`, the default CircuitPython terminal will be shown. //| If the root group is set to ``None``, no output will be shown. //| """ STATIC mp_obj_t displayio_display_obj_get_root_group(mp_obj_t self_in) { diff --git a/shared-bindings/displayio/EPaperDisplay.c b/shared-bindings/displayio/EPaperDisplay.c index 8df3b31de9..0df2311b36 100644 --- a/shared-bindings/displayio/EPaperDisplay.c +++ b/shared-bindings/displayio/EPaperDisplay.c @@ -384,7 +384,7 @@ MP_PROPERTY_GETTER(displayio_epaperdisplay_bus_obj, //| root_group: Group //| """The root group on the epaper display. -//| If the root group is set to displayio.CIRCUITPYTHON_TERMINAL, the default CircuitPython terminal will be shown. +//| If the root group is set to `displayio.CIRCUITPYTHON_TERMINAL`, the default CircuitPython terminal will be shown. //| If the root group is set to ``None``, no output will be shown. //| """ //| diff --git a/shared-bindings/framebufferio/FramebufferDisplay.c b/shared-bindings/framebufferio/FramebufferDisplay.c index 806d9957b4..b80b57b435 100644 --- a/shared-bindings/framebufferio/FramebufferDisplay.c +++ b/shared-bindings/framebufferio/FramebufferDisplay.c @@ -324,7 +324,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(framebufferio_framebufferdisplay_fill_row_obj, 1, fra //| root_group: displayio.Group //| """The root group on the display. -//| If the root group is set to displayio.CIRCUITPYTHON_TERMINAL, the default CircuitPython terminal will be shown. +//| If the root group is set to `displayio.CIRCUITPYTHON_TERMINAL`, the default CircuitPython terminal will be shown. //| If the root group is set to ``None``, no output will be shown. //| """ //| From b9c7cd40281caaf830af3c7ae981a5b37b047f9a Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 24 Apr 2023 12:58:40 -0400 Subject: [PATCH 069/117] describe instance more precisely --- ports/raspberrypi/bindings/picodvi/Framebuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/raspberrypi/bindings/picodvi/Framebuffer.c b/ports/raspberrypi/bindings/picodvi/Framebuffer.c index 67d6a286dd..e4584370af 100644 --- a/ports/raspberrypi/bindings/picodvi/Framebuffer.c +++ b/ports/raspberrypi/bindings/picodvi/Framebuffer.c @@ -142,7 +142,7 @@ STATIC mp_obj_t picodvi_framebuffer_make_new(const mp_obj_type_t *type, size_t n //| def deinit(self) -> None: //| """Free the resources (pins, timers, etc.) associated with this -//| picodvi instance. After deinitialization, no further operations +//| `picodvi.Framebuffer` instance. After deinitialization, no further operations //| may be performed.""" //| ... STATIC mp_obj_t picodvi_framebuffer_deinit(mp_obj_t self_in) { From ac82f8f90b27838b610fe57a4a1295729499e8cd Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Mon, 24 Apr 2023 13:43:09 -0400 Subject: [PATCH 070/117] document displayio.CIRCUITPYTHON_TERMINAL --- shared-bindings/displayio/__init__.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/shared-bindings/displayio/__init__.c b/shared-bindings/displayio/__init__.c index 77dc8aecee..6b4dc6d895 100644 --- a/shared-bindings/displayio/__init__.c +++ b/shared-bindings/displayio/__init__.c @@ -57,6 +57,10 @@ //| `_. //| """ +//| CIRCUITPYTHON_TERMINAL: Group +//| """The `displayio.Group` that is the displayed serial terminal (REPL).""" +//| + //| import paralleldisplay //| From 87fc5eff267e1e29b8b8cafee6cf4dc7076415ea Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 24 Apr 2023 16:24:33 -0700 Subject: [PATCH 071/117] Re-enable partial updates when available --- shared-module/displayio/EPaperDisplay.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shared-module/displayio/EPaperDisplay.c b/shared-module/displayio/EPaperDisplay.c index 2f6c8fa5c9..e79c692766 100644 --- a/shared-module/displayio/EPaperDisplay.c +++ b/shared-module/displayio/EPaperDisplay.c @@ -139,7 +139,8 @@ STATIC const displayio_area_t *displayio_epaperdisplay_get_refresh_areas(display if (self->core.current_group != NULL) { first_area = displayio_group_get_refresh_areas(self->core.current_group, NULL); } - if (first_area != NULL) { + if (first_area != NULL && self->core.row_command == NO_COMMAND) { + // Do a full refresh if the display doesn't support partial updates. self->core.area.next = NULL; return &self->core.area; } From c4104898cec82bee66ac513322f44b67663e4980 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sun, 23 Apr 2023 09:43:25 -0500 Subject: [PATCH 072/117] add additional float validators --- py/argcheck.c | 15 +++++++++++++++ py/runtime.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/py/argcheck.c b/py/argcheck.c index 465a82c97e..b530d44caa 100644 --- a/py/argcheck.c +++ b/py/argcheck.c @@ -186,6 +186,21 @@ mp_int_t mp_arg_validate_int_range(mp_int_t i, mp_int_t min, mp_int_t max, qstr return i; } +mp_float_t mp_arg_validate_type_float(mp_obj_t obj, qstr arg_name) { + mp_float_t a_float; + if (!mp_obj_get_float_maybe(obj, &a_float)) { + mp_raise_TypeError_varg(translate("%q must be of type %q, not %q"), arg_name, MP_QSTR_float, mp_obj_get_type(obj)->name); + } + return a_float; +} + +void mp_arg_validate_obj_float_range(mp_obj_t float_in, mp_int_t min, mp_int_t max, qstr arg_name) { + const mp_float_t f = mp_arg_validate_type_float(float_in, arg_name); + if (f < (mp_float_t)min || f > (mp_float_t)max) { + mp_raise_ValueError_varg(translate("%q must be %d-%d"), arg_name, min, max); + } +} + mp_float_t mp_arg_validate_obj_float_non_negative(mp_obj_t float_in, mp_float_t default_for_null, qstr arg_name) { const mp_float_t f = (float_in == MP_OBJ_NULL) ? default_for_null diff --git a/py/runtime.h b/py/runtime.h index d154772508..f7b96a27ae 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -103,6 +103,8 @@ mp_int_t mp_arg_validate_int_max(mp_int_t i, mp_int_t j, qstr arg_name); mp_int_t mp_arg_validate_int_range(mp_int_t i, mp_int_t min, mp_int_t max, qstr arg_name); #if MICROPY_PY_BUILTINS_FLOAT mp_float_t mp_arg_validate_obj_float_non_negative(mp_obj_t float_in, mp_float_t default_for_null, qstr arg_name); +void mp_arg_validate_obj_float_range(mp_obj_t float_in, mp_int_t min, mp_int_t max, qstr arg_name); +mp_float_t mp_arg_validate_type_float(mp_obj_t obj, qstr arg_name); #endif mp_uint_t mp_arg_validate_length_min(mp_uint_t length, mp_uint_t min, qstr arg_name); mp_uint_t mp_arg_validate_length_max(mp_uint_t length, mp_uint_t max, qstr arg_name); From ca6ea83ff5a25422028ebe11c2527af4b7f328d2 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sun, 23 Apr 2023 09:28:34 -0500 Subject: [PATCH 073/117] Fix `non_negative` validator to allow 0.0 --- py/argcheck.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/py/argcheck.c b/py/argcheck.c index b530d44caa..265b303901 100644 --- a/py/argcheck.c +++ b/py/argcheck.c @@ -204,8 +204,8 @@ void mp_arg_validate_obj_float_range(mp_obj_t float_in, mp_int_t min, mp_int_t m mp_float_t mp_arg_validate_obj_float_non_negative(mp_obj_t float_in, mp_float_t default_for_null, qstr arg_name) { const mp_float_t f = (float_in == MP_OBJ_NULL) ? default_for_null - : mp_obj_get_float(float_in); - if (f <= (mp_float_t)0.0) { + : mp_arg_validate_type_float(float_in, arg_name); + if (f < (mp_float_t)0.0) { mp_raise_ValueError_varg(translate("%q must be >= %d"), arg_name, 0); } return f; From 361608119c1ee47e7a055a22096bb0011f3299ac Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Tue, 25 Apr 2023 10:33:13 -0400 Subject: [PATCH 074/117] Change VID/PID to be Raspberry Pi values Spotted the Cosmo_pico port on circuitpython.org which is the same class of device as the Pimoroni PICO dv so I'm switching the VID/PID to use the Raspberry Pi owned values rather than the Adafruit values just as the Como device uses. --- ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.mk b/ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.mk index 20607d50e4..e4eb325fc1 100644 --- a/ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.mk +++ b/ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.mk @@ -1,6 +1,6 @@ -USB_VID = 0x239A -USB_PID = 0x80F4 -USB_PRODUCT = "Pico" +USB_VID = 0x2E8A +USB_PID = 0x104C +USB_PRODUCT = "Pimoroni PICO dv" USB_MANUFACTURER = "Raspberry Pi" CHIP_VARIANT = RP2040 From 076cd1fab4279b444f555887718937a902e036da Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Tue, 25 Apr 2023 11:14:48 -0400 Subject: [PATCH 075/117] Nope, can't use the COSMO-pico vid/pid pair Setting back, at least temporarily to the Adafruit pair. --- ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.mk b/ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.mk index e4eb325fc1..f78d88add3 100644 --- a/ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.mk +++ b/ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.mk @@ -1,5 +1,5 @@ -USB_VID = 0x2E8A -USB_PID = 0x104C +USB_VID = 0x239A +USB_PID = 0x80F4 USB_PRODUCT = "Pimoroni PICO dv" USB_MANUFACTURER = "Raspberry Pi" From 2bee4926f9957f00c33ff8de3447346565ef5669 Mon Sep 17 00:00:00 2001 From: Neradoc Date: Tue, 25 Apr 2023 17:22:04 +0200 Subject: [PATCH 076/117] Fix Scorpio on-board neopixel pin --- .../boards/adafruit_feather_rp2040_scorpio/mpconfigboard.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_scorpio/mpconfigboard.h b/ports/raspberrypi/boards/adafruit_feather_rp2040_scorpio/mpconfigboard.h index 94b6fcee7b..d9cec8d50a 100644 --- a/ports/raspberrypi/boards/adafruit_feather_rp2040_scorpio/mpconfigboard.h +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_scorpio/mpconfigboard.h @@ -1,7 +1,7 @@ #define MICROPY_HW_BOARD_NAME "Adafruit Feather RP2040 Scorpio" #define MICROPY_HW_MCU_NAME "rp2040" -#define MICROPY_HW_NEOPIXEL (&pin_GPIO16) +#define MICROPY_HW_NEOPIXEL (&pin_GPIO4) #define DEFAULT_I2C_BUS_SCL (&pin_GPIO3) #define DEFAULT_I2C_BUS_SDA (&pin_GPIO2) From 375a9cd4c500ff7bf04ca426e51a53148477bfea Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Mon, 17 Apr 2023 10:59:54 -0500 Subject: [PATCH 077/117] add Synthesizer.release --- shared-bindings/synthio/Synthesizer.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/shared-bindings/synthio/Synthesizer.c b/shared-bindings/synthio/Synthesizer.c index 56ad0d76cd..4a4256b5ac 100644 --- a/shared-bindings/synthio/Synthesizer.c +++ b/shared-bindings/synthio/Synthesizer.c @@ -92,7 +92,20 @@ STATIC mp_obj_t synthio_synthesizer_press(mp_obj_t self_in, mp_obj_t press) { return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_2(synthio_synthesizer_press_obj, synthio_synthesizer_press); -// +//| def release(self, /, release: Sequence[int] = ()) -> None: +//| """Turn some notes off. Notes use MIDI numbering, with 60 being middle C, approximately 262Hz. +//| +//| Releasing a note that was already released has no effect. +//| +//| :param Sequence[int] release: Any sequence of integer notes.""" +STATIC mp_obj_t synthio_synthesizer_release(mp_obj_t self_in, mp_obj_t release) { + synthio_synthesizer_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + common_hal_synthio_synthesizer_release(self, release); + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_2(synthio_synthesizer_release_obj, synthio_synthesizer_release); + //| def release_then_press( //| self, release: Sequence[int] = (), press: Sequence[int] = () //| ) -> None: @@ -210,6 +223,7 @@ MP_PROPERTY_GETTER(synthio_synthesizer_pressed_obj, STATIC const mp_rom_map_elem_t synthio_synthesizer_locals_dict_table[] = { // Methods { MP_ROM_QSTR(MP_QSTR_press), MP_ROM_PTR(&synthio_synthesizer_press_obj) }, + { MP_ROM_QSTR(MP_QSTR_release), MP_ROM_PTR(&synthio_synthesizer_release_obj) }, { MP_ROM_QSTR(MP_QSTR_release_all), MP_ROM_PTR(&synthio_synthesizer_release_all_obj) }, { MP_ROM_QSTR(MP_QSTR_release_then_press), MP_ROM_PTR(&synthio_synthesizer_release_then_press_obj) }, { MP_ROM_QSTR(MP_QSTR_release_all_then_press), MP_ROM_PTR(&synthio_synthesizer_release_all_then_press_obj) }, From 12c1a72f03209837e894d081eabaab3e975413eb Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 12 Apr 2023 20:26:46 -0500 Subject: [PATCH 078/117] synthio: implement envelope This works for me (tested playing midi to raw files on host computer, as well as a variant of the nunchuk instrument on pygamer) it has to re-factor how/when MIDI reading occurs, because reasons. endorse new test results .. and allow `-1` to specify a note with no sustain (plucked) --- shared-bindings/audiocore/__init__.c | 18 ++- shared-bindings/synthio/MidiTrack.c | 11 +- shared-bindings/synthio/MidiTrack.h | 8 +- shared-bindings/synthio/Synthesizer.c | 44 +++++- shared-bindings/synthio/Synthesizer.h | 4 +- shared-bindings/synthio/__init__.c | 111 ++++++++++++- shared-bindings/synthio/__init__.h | 6 + shared-module/synthio/MidiTrack.c | 167 +++++++++---------- shared-module/synthio/MidiTrack.h | 7 +- shared-module/synthio/Synthesizer.c | 33 ++-- shared-module/synthio/__init__.c | 211 +++++++++++++++++++++---- shared-module/synthio/__init__.h | 33 +++- tests/circuitpython/miditrack.py | 6 +- tests/circuitpython/miditrack.py.exp | 4 +- tests/circuitpython/synthesizer.py | 16 +- tests/circuitpython/synthesizer.py.exp | 32 +++- 16 files changed, 535 insertions(+), 176 deletions(-) diff --git a/shared-bindings/audiocore/__init__.c b/shared-bindings/audiocore/__init__.c index 6f32979099..3ecd7391b6 100644 --- a/shared-bindings/audiocore/__init__.c +++ b/shared-bindings/audiocore/__init__.c @@ -27,6 +27,7 @@ #include #include "py/obj.h" +#include "py/gc.h" #include "py/runtime.h" #include "shared-bindings/audiocore/__init__.h" @@ -46,8 +47,23 @@ STATIC mp_obj_t audiocore_get_buffer(mp_obj_t sample_in) { mp_obj_t result[2] = {mp_obj_new_int_from_uint(gbr), mp_const_none}; if (gbr != GET_BUFFER_ERROR) { + bool single_buffer, samples_signed; + uint32_t max_buffer_length; + uint8_t spacing; + + uint8_t bits_per_sample = audiosample_bits_per_sample(sample_in); + audiosample_get_buffer_structure(sample_in, false, &single_buffer, &samples_signed, &max_buffer_length, &spacing); // copies the data because the gc semantics of get_buffer are unclear - result[1] = mp_obj_new_bytes(buffer, buffer_length); + void *result_buf = gc_alloc(buffer_length, 0, false); + memcpy(result_buf, buffer, buffer_length); + char typecode = + (bits_per_sample == 8 && samples_signed) ? 'b' : + (bits_per_sample == 8 && !samples_signed) ? 'B' : + (bits_per_sample == 16 && samples_signed) ? 'h' : + (bits_per_sample == 16 && !samples_signed) ? 'H' : + 'b'; + size_t nitems = buffer_length / (bits_per_sample / 8); + result[1] = mp_obj_new_memoryview(typecode, nitems, result_buf); } return mp_obj_new_tuple(2, result); diff --git a/shared-bindings/synthio/MidiTrack.c b/shared-bindings/synthio/MidiTrack.c index 20a203ce9c..6916a21689 100644 --- a/shared-bindings/synthio/MidiTrack.c +++ b/shared-bindings/synthio/MidiTrack.c @@ -44,7 +44,8 @@ //| tempo: int, //| *, //| sample_rate: int = 11025, -//| waveform: ReadableBuffer = None +//| waveform: Optional[ReadableBuffer] = None, +//| envelope: Optional[Envelope] = None, //| ) -> None: //| """Create a MidiTrack from the given stream of MIDI events. Only "Note On" and "Note Off" events //| are supported; channel numbers and key velocities are ignored. Up to two notes may be on at the @@ -54,6 +55,7 @@ //| :param int tempo: Tempo of the streamed events, in MIDI ticks per second //| :param int sample_rate: The desired playback sample rate; higher sample rate requires more memory //| :param ReadableBuffer waveform: A single-cycle waveform. Default is a 50% duty cycle square wave. If specified, must be a ReadableBuffer of type 'h' (signed 16 bit) +//| :param Envelope envelope: An object that defines the loudness of a note over time. The default envelope provides no ramping, voices turn instantly on and off. //| //| Simple melody:: //| @@ -72,12 +74,13 @@ //| print("stopped")""" //| ... STATIC mp_obj_t synthio_miditrack_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - enum { ARG_buffer, ARG_tempo, ARG_sample_rate, ARG_waveform }; + enum { ARG_buffer, ARG_tempo, ARG_sample_rate, ARG_waveform, ARG_envelope }; static const mp_arg_t allowed_args[] = { { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED }, { MP_QSTR_tempo, MP_ARG_INT | MP_ARG_REQUIRED }, { MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 11025} }, { MP_QSTR_waveform, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none } }, + { MP_QSTR_envelope, 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_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -96,7 +99,9 @@ STATIC mp_obj_t synthio_miditrack_make_new(const mp_obj_type_t *type, size_t n_a args[ARG_tempo].u_int, args[ARG_sample_rate].u_int, bufinfo_waveform.buf, - bufinfo_waveform.len / 2); + bufinfo_waveform.len / 2, + args[ARG_envelope].u_obj + ); return MP_OBJ_FROM_PTR(self); } diff --git a/shared-bindings/synthio/MidiTrack.h b/shared-bindings/synthio/MidiTrack.h index 90ddab8728..046163c2de 100644 --- a/shared-bindings/synthio/MidiTrack.h +++ b/shared-bindings/synthio/MidiTrack.h @@ -24,20 +24,18 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_SYNTHIO_MIDITRACK_H -#define MICROPY_INCLUDED_SHARED_BINDINGS_SYNTHIO_MIDITRACK_H +#pragma once #include "shared-module/synthio/MidiTrack.h" extern const mp_obj_type_t synthio_miditrack_type; void common_hal_synthio_miditrack_construct(synthio_miditrack_obj_t *self, - const uint8_t *buffer, uint32_t len, uint32_t tempo, uint32_t sample_rate, const int16_t *waveform, uint16_t waveform_len); + const uint8_t *buffer, uint32_t len, uint32_t tempo, uint32_t sample_rate, const int16_t *waveform, uint16_t waveform_len, + mp_obj_t envelope); void common_hal_synthio_miditrack_deinit(synthio_miditrack_obj_t *self); bool common_hal_synthio_miditrack_deinited(synthio_miditrack_obj_t *self); uint32_t common_hal_synthio_miditrack_get_sample_rate(synthio_miditrack_obj_t *self); uint8_t common_hal_synthio_miditrack_get_bits_per_sample(synthio_miditrack_obj_t *self); uint8_t common_hal_synthio_miditrack_get_channel_count(synthio_miditrack_obj_t *self); - -#endif // MICROPY_INCLUDED_SHARED_BINDINGS_SYNTHIO_MIDITRACK_H diff --git a/shared-bindings/synthio/Synthesizer.c b/shared-bindings/synthio/Synthesizer.c index 4a4256b5ac..97941b860b 100644 --- a/shared-bindings/synthio/Synthesizer.c +++ b/shared-bindings/synthio/Synthesizer.c @@ -37,24 +37,29 @@ #include "supervisor/shared/translate/translate.h" //| class Synthesizer: -//| def __init__(self, *, sample_rate: int = 11025, waveform: ReadableBuffer = None) -> None: +//| def __init__( +//| self, +//| *, +//| sample_rate: int = 11025, +//| waveform: Optional[ReadableBuffer] = None, +//| envelope: Optional[Envelope] = None, +//| ) -> None: //| """Create a synthesizer object. //| //| This API is experimental. //| -//| At least 2 simultaneous notes are supported. mimxrt10xx and rp2040 platforms support up to -//| 12 notes. -//| //| Notes use MIDI note numbering, with 60 being C4 or Middle C, approximately 262Hz. //| //| :param int sample_rate: The desired playback sample rate; higher sample rate requires more memory -//| :param ReadableBuffer waveform: A single-cycle waveform. Default is a 50% duty cycle square wave. If specified, must be a ReadableBuffer of type 'h' (signed 16 bit). It is permitted to modify this buffer during synthesis. This can be used, for instance, to control the overall volume or timbre of the notes. +//| :param ReadableBuffer waveform: A single-cycle waveform. Default is a 50% duty cycle square wave. If specified, must be a ReadableBuffer of type 'h' (signed 16 bit) +//| :param Optional[Envelope] envelope: An object that defines the loudness of a note over time. The default envelope, `None` provides no ramping, voices turn instantly on and off. //| """ STATIC mp_obj_t synthio_synthesizer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - enum { ARG_sample_rate, ARG_waveform }; + enum { ARG_sample_rate, ARG_waveform, ARG_envelope }; static const mp_arg_t allowed_args[] = { { MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 11025} }, { MP_QSTR_waveform, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none } }, + { MP_QSTR_envelope, 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_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -68,7 +73,9 @@ STATIC mp_obj_t synthio_synthesizer_make_new(const mp_obj_type_t *type, size_t n common_hal_synthio_synthesizer_construct(self, args[ARG_sample_rate].u_int, bufinfo_waveform.buf, - bufinfo_waveform.len / 2); + bufinfo_waveform.len / 2, + args[ARG_envelope].u_obj); + return MP_OBJ_FROM_PTR(self); } @@ -191,6 +198,28 @@ STATIC mp_obj_t synthio_synthesizer_obj___exit__(size_t n_args, const mp_obj_t * return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(synthio_synthesizer___exit___obj, 4, 4, synthio_synthesizer_obj___exit__); + +//| envelope: Optional[Envelope] +//| """The envelope to apply to all notes. `None`, the default envelope, instantly turns notes on and off. The envelope may be changed dynamically, but it affects all notes (even currently playing notes)""" +STATIC mp_obj_t synthio_synthesizer_obj_get_envelope(mp_obj_t self_in) { + synthio_synthesizer_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + return synthio_synth_envelope_get(&self->synth); +} +MP_DEFINE_CONST_FUN_OBJ_1(synthio_synthesizer_get_envelope_obj, synthio_synthesizer_obj_get_envelope); + +STATIC mp_obj_t synthio_synthesizer_obj_set_envelope(mp_obj_t self_in, mp_obj_t envelope) { + synthio_synthesizer_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + synthio_synth_envelope_set(&self->synth, envelope); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(synthio_synthesizer_set_envelope_obj, synthio_synthesizer_obj_set_envelope); + +MP_PROPERTY_GETSET(synthio_synthesizer_envelope_obj, + (mp_obj_t)&synthio_synthesizer_get_envelope_obj, + (mp_obj_t)&synthio_synthesizer_set_envelope_obj); + //| sample_rate: int //| """32 bit value that tells how quickly samples are played in Hertz (cycles per second).""" STATIC mp_obj_t synthio_synthesizer_obj_get_sample_rate(mp_obj_t self_in) { @@ -232,6 +261,7 @@ STATIC const mp_rom_map_elem_t synthio_synthesizer_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&synthio_synthesizer___exit___obj) }, // Properties + { MP_ROM_QSTR(MP_QSTR_envelope), MP_ROM_PTR(&synthio_synthesizer_envelope_obj) }, { MP_ROM_QSTR(MP_QSTR_sample_rate), MP_ROM_PTR(&synthio_synthesizer_sample_rate_obj) }, { MP_ROM_QSTR(MP_QSTR_max_polyphony), MP_ROM_INT(CIRCUITPY_SYNTHIO_MAX_CHANNELS) }, { MP_ROM_QSTR(MP_QSTR_pressed), MP_ROM_PTR(&synthio_synthesizer_pressed_obj) }, diff --git a/shared-bindings/synthio/Synthesizer.h b/shared-bindings/synthio/Synthesizer.h index 92e75a1c23..ba6c3b99e3 100644 --- a/shared-bindings/synthio/Synthesizer.h +++ b/shared-bindings/synthio/Synthesizer.h @@ -32,8 +32,8 @@ extern const mp_obj_type_t synthio_synthesizer_type; void common_hal_synthio_synthesizer_construct(synthio_synthesizer_obj_t *self, - uint32_t sample_rate, const int16_t *waveform, uint16_t waveform_len); - + uint32_t sample_rate, const int16_t *waveform, uint16_t waveform_length, + mp_obj_t envelope); void common_hal_synthio_synthesizer_deinit(synthio_synthesizer_obj_t *self); bool common_hal_synthio_synthesizer_deinited(synthio_synthesizer_obj_t *self); uint32_t common_hal_synthio_synthesizer_get_sample_rate(synthio_synthesizer_obj_t *self); diff --git a/shared-bindings/synthio/__init__.c b/shared-bindings/synthio/__init__.c index 3c50377ff8..703966defc 100644 --- a/shared-bindings/synthio/__init__.c +++ b/shared-bindings/synthio/__init__.c @@ -28,6 +28,7 @@ #include "py/mperrno.h" #include "py/obj.h" +#include "py/objnamedtuple.h" #include "py/runtime.h" #include "extmod/vfs_fat.h" #include "extmod/vfs_posix.h" @@ -36,16 +37,111 @@ #include "shared-bindings/synthio/MidiTrack.h" #include "shared-bindings/synthio/Synthesizer.h" -//| """Support for MIDI synthesis""" +//| """Support for multi-channel audio synthesis //| -//| def from_file(file: typing.BinaryIO, *, sample_rate: int = 11025) -> MidiTrack: +//| At least 2 simultaneous notes are supported. samd5x, mimxrt10xx and rp2040 platforms support up to 12 notes. +//| +//| I'm a little teapot. I'm not on line 11, but I don't know what is. +//| """ +//| +//| class Envelope: +//| def __init__( +//| self, +//| attack_time: float, +//| decay_time: float, +//| release_time: float, +//| attack_level: float, +//| sustain_level: float, +//| ) -> None: +//| """Construct an Envelope object +//| +//| The Envelope defines an ADSR (Attack, Decay, Sustain, Release) envelope with linear amplitude ramping. A note starts at 0 volume, then increases to ``attack_level`` over ``attack_time`` seconds; then it decays to ``sustain_level`` over ``decay_time`` seconds. Finally, when the note is released, it decreases to ``0`` volume over ``release_time``. +//| +//| If the ``sustain_level`` of an envelope is 0, then the decay and sustain phases of the note are always omitted. The note is considered to be released as soon as the envelope reaches the end of the attack phase. The ``decay_time`` is ignored. This is similar to how a plucked or struck instrument behaves. +//| +//| If a note is released before it reaches its sustain phase, it decays with the same slope indicated by ``sustain_level/release_time`` (or ``attack_level/release_time`` for plucked envelopes) +//| +//| :param float attack_time: The time in seconds it takes to ramp from 0 volume to attack_volume +//| :param float decay_time: The time in seconds it takes to ramp from attack_volume to sustain_volume +//| :param float release_time: The time in seconds it takes to ramp from sustain_volume to release_volume. When a note is released before it has reached the sustain phase, the release is done with the same slope indicated by ``release_time`` and ``sustain_level`` +//| :param float attack_level: The relative level, in the range ``0.0`` to ``1.0`` of the peak volume of the attack phase +//| :param float sustain_level: The relative level, in the range ``0.0`` to ``1.0`` of the volume of the sustain phase +//| """ +//| attack_time: float +//| """The time in seconds it takes to ramp from 0 volume to attack_volume""" +//| +//| decay_time: float +//| """The time in seconds it takes to ramp from attack_volume to sustain_volume""" +//| +//| release_time: float +//| """The time in seconds it takes to ramp from sustain_volume to release_volume. When a note is released before it has reached the sustain phase, the release is done with the same slope indicated by ``release_time`` and ``sustain_level``""" +//| +//| attack_level: float +//| """The relative level, in the range ``0.0`` to ``1.0`` of the peak volume of the attack phase""" +//| +//| sustain_level: float +//| """The relative level, in the range ``0.0`` to ``1.0`` of the volume of the sustain phase""" +//| + +STATIC mp_obj_t synthio_envelope_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_obj_t new_obj = namedtuple_make_new(type_in, n_args, n_kw, args); + mp_obj_t *fields; + size_t len; + mp_obj_tuple_get(new_obj, &len, &fields); + + mp_arg_validate_obj_float_non_negative(fields[0], 0., MP_QSTR_attack_time); + mp_arg_validate_obj_float_non_negative(fields[1], 0., MP_QSTR_decay_time); + mp_arg_validate_obj_float_non_negative(fields[2], 0., MP_QSTR_release_time); + + mp_arg_validate_obj_float_range(fields[3], 0, 1, MP_QSTR_attack_level); + mp_arg_validate_obj_float_range(fields[4], 0, 1, MP_QSTR_sustain_level); + + return new_obj; +}; + +const mp_obj_namedtuple_type_t synthio_envelope_type_obj = { + .base = { + .base = { + .type = &mp_type_type + }, + .flags = MP_TYPE_FLAG_EXTENDED, + .name = MP_QSTR_Envelope, + .print = namedtuple_print, + .parent = &mp_type_tuple, + .make_new = synthio_envelope_make_new, + .attr = namedtuple_attr, + MP_TYPE_EXTENDED_FIELDS( + .unary_op = mp_obj_tuple_unary_op, + .binary_op = mp_obj_tuple_binary_op, + .subscr = mp_obj_tuple_subscr, + .getiter = mp_obj_tuple_getiter, + ), + }, + .n_fields = 5, + .fields = { + MP_QSTR_attack_time, + MP_QSTR_decay_time, + MP_QSTR_release_time, + MP_QSTR_attack_level, + MP_QSTR_sustain_level, + }, +}; + + +//| def from_file( +//| file: typing.BinaryIO, +//| *, +//| sample_rate: int = 11025, +//| waveform: Optional[ReadableBuffer] = None, +//| envelope: Optional[ReadableBuffer] = None, +//| ) -> MidiTrack: //| """Create an AudioSample from an already opened MIDI file. //| Currently, only single-track MIDI (type 0) is supported. //| //| :param typing.BinaryIO file: Already opened MIDI file //| :param int sample_rate: The desired playback sample rate; higher sample rate requires more memory //| :param ReadableBuffer waveform: A single-cycle waveform. Default is a 50% duty cycle square wave. If specified, must be a ReadableBuffer of type 'h' (signed 16 bit) -//| +//| :param Envelope envelope: An object that defines the loudness of a note over time. The default envelope provides no ramping, voices turn instantly on and off. //| //| Playing a MIDI file from flash:: //| @@ -65,11 +161,12 @@ //| ... //| STATIC mp_obj_t synthio_from_file(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_file, ARG_sample_rate, ARG_waveform }; + enum { ARG_file, ARG_sample_rate, ARG_waveform, ARG_envelope }; static const mp_arg_t allowed_args[] = { { MP_QSTR_file, MP_ARG_OBJ | MP_ARG_REQUIRED }, { MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 11025} }, { MP_QSTR_waveform, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none } }, + { MP_QSTR_envelope, 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, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -121,7 +218,9 @@ STATIC mp_obj_t synthio_from_file(size_t n_args, const mp_obj_t *pos_args, mp_ma result->base.type = &synthio_miditrack_type; common_hal_synthio_miditrack_construct(result, buffer, track_size, - tempo, args[ARG_sample_rate].u_int, bufinfo_waveform.buf, bufinfo_waveform.len / 2); + tempo, args[ARG_sample_rate].u_int, bufinfo_waveform.buf, bufinfo_waveform.len / 2, + args[ARG_envelope].u_obj + ); #if MICROPY_MALLOC_USES_ALLOCATED_SIZE m_free(buffer, track_size); @@ -133,12 +232,12 @@ STATIC mp_obj_t synthio_from_file(size_t n_args, const mp_obj_t *pos_args, mp_ma } MP_DEFINE_CONST_FUN_OBJ_KW(synthio_from_file_obj, 1, synthio_from_file); - STATIC const mp_rom_map_elem_t synthio_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_synthio) }, { MP_ROM_QSTR(MP_QSTR_MidiTrack), MP_ROM_PTR(&synthio_miditrack_type) }, { MP_ROM_QSTR(MP_QSTR_Synthesizer), MP_ROM_PTR(&synthio_synthesizer_type) }, { MP_ROM_QSTR(MP_QSTR_from_file), MP_ROM_PTR(&synthio_from_file_obj) }, + { MP_ROM_QSTR(MP_QSTR_Envelope), MP_ROM_PTR(&synthio_envelope_type_obj) }, }; STATIC MP_DEFINE_CONST_DICT(synthio_module_globals, synthio_module_globals_table); diff --git a/shared-bindings/synthio/__init__.h b/shared-bindings/synthio/__init__.h index 3b7d47db28..6ea323905a 100644 --- a/shared-bindings/synthio/__init__.h +++ b/shared-bindings/synthio/__init__.h @@ -26,4 +26,10 @@ #pragma once +#include "py/objnamedtuple.h" + +typedef struct synthio_synth synthio_synth_t; extern int16_t shared_bindings_synthio_square_wave[]; +extern const mp_obj_namedtuple_type_t synthio_envelope_type_obj; +void synthio_synth_envelope_set(synthio_synth_t *synth, mp_obj_t envelope_obj); +mp_obj_t synthio_synth_envelope_get(synthio_synth_t *synth); diff --git a/shared-module/synthio/MidiTrack.c b/shared-module/synthio/MidiTrack.c index f8b39c29e3..6a021af85c 100644 --- a/shared-module/synthio/MidiTrack.c +++ b/shared-module/synthio/MidiTrack.c @@ -28,118 +28,109 @@ #include "shared-bindings/synthio/MidiTrack.h" -STATIC NORETURN void raise_midi_stream_error(uint32_t pos) { - mp_raise_ValueError_varg(translate("Error in MIDI stream at position %d"), pos); +STATIC void print_midi_stream_error(synthio_miditrack_obj_t *self) { + mp_cprintf(&mp_plat_print, translate("Error in MIDI stream at position %d"), self->pos); + self->pos = self->track.len; } -STATIC uint8_t parse_note(const uint8_t *buffer, uint32_t len, uint32_t *pos) { - if (*pos + 1 >= len) { - raise_midi_stream_error(*pos); +STATIC uint8_t parse_note(synthio_miditrack_obj_t *self) { + uint8_t *buffer = self->track.buf; + size_t len = self->track.len; + if (self->pos + 1 >= len) { + print_midi_stream_error(self); } - uint8_t note = buffer[(*pos)++]; - if (note > 127 || buffer[(*pos)++] > 127) { - raise_midi_stream_error(*pos); + uint8_t note = buffer[(self->pos)++]; + if (note > 127 || buffer[(self->pos)++] > 127) { + print_midi_stream_error(self); } return note; } -STATIC void terminate_span(synthio_miditrack_obj_t *self, uint16_t *dur) { - if (*dur) { - self->track[self->total_spans - 1].dur = *dur; - *dur = 0; - } else { - self->total_spans--; +static int decode_duration(synthio_miditrack_obj_t *self) { + uint8_t *buffer = self->track.buf; + size_t len = self->track.len; + uint8_t c; + uint32_t delta = 0; + do { + c = buffer[self->pos++]; + delta <<= 7; + delta |= c & 0x7f; + } while ((c & 0x80) && (self->pos < len)); + + // errors cannot be raised from the background task, so simply end the track. + if (c & 0x80) { + self->pos = self->track.len; + print_midi_stream_error(self); } + return delta * self->synth.sample_rate / self->tempo; } -STATIC void add_span(synthio_miditrack_obj_t *self, const synthio_midi_span_t *span) { - self->track = m_renew(synthio_midi_span_t, self->track, self->total_spans, self->total_spans + 1); - self->track[self->total_spans++] = *span; -} - -STATIC void change_span_note(synthio_miditrack_obj_t *self, uint8_t old_note, uint8_t new_note, uint16_t *dur) { - synthio_midi_span_t span = self->track[self->total_spans - 1]; - if (synthio_span_change_note(&span, old_note, new_note)) { - terminate_span(self, dur); - add_span(self, &span); - *dur = 0; - } -} - -void common_hal_synthio_miditrack_construct(synthio_miditrack_obj_t *self, - const uint8_t *buffer, uint32_t len, uint32_t tempo, uint32_t sample_rate, - const int16_t *waveform, uint16_t waveform_length) { - - self->synth.sample_rate = sample_rate; - self->track = m_malloc(sizeof(synthio_midi_span_t), false); - synthio_span_init(self->track); - self->next_span = 0; - self->total_spans = 1; - self->synth.waveform = waveform; - self->synth.waveform_length = waveform_length; - - uint16_t dur = 0; - uint32_t pos = 0; - while (pos < len) { - uint8_t c; - uint32_t delta = 0; - do { - c = buffer[pos++]; - delta <<= 7; - delta |= c & 0x7f; - } while ((c & 0x80) && (pos < len)); - - if (c & 0x80) { - raise_midi_stream_error(pos); - } - - // dur is carried over here so that if a note on/off message doesn't actually produce a change, the - // underlying "span" is extended. Otherwise, it is zeroed out in the call to `terminate_span`. - dur += delta * sample_rate / tempo; - - switch (buffer[pos++] >> 4) { +// invariant: pointing at a MIDI message +static void decode_until_pause(synthio_miditrack_obj_t *self) { + uint8_t *buffer = self->track.buf; + size_t len = self->track.len; + do { + switch (buffer[self->pos++] >> 4) { case 8: { // Note Off - uint8_t note = parse_note(buffer, len, &pos); - change_span_note(self, note, SYNTHIO_SILENCE, &dur); + uint8_t note = parse_note(self); + synthio_span_change_note(&self->synth, note, SYNTHIO_SILENCE); break; } case 9: { // Note On - uint8_t note = parse_note(buffer, len, &pos); - change_span_note(self, SYNTHIO_SILENCE, note, &dur); + uint8_t note = parse_note(self); + synthio_span_change_note(&self->synth, SYNTHIO_SILENCE, note); break; } case 10: case 11: case 14: // two data bytes to ignore - parse_note(buffer, len, &pos); + parse_note(self); break; case 12: case 13: // one data byte to ignore - if (pos >= len || buffer[pos++] > 127) { - raise_midi_stream_error(pos); + if (self->pos >= len || buffer[self->pos++] > 127) { + print_midi_stream_error(self); } break; case 15: // the full syntax is too complicated, just assume it's "End of Track" event - pos = len; + self->pos = len; break; default: // invalid event - raise_midi_stream_error(pos); + print_midi_stream_error(self); } - } - terminate_span(self, &dur); + if (self->pos < len) { + self->synth.span.dur = decode_duration(self); + } + } while (self->pos < len && self->synth.span.dur == 0); +} - uint16_t max_dur = 0; - for (int i = 0; i < self->total_spans; i++) { - max_dur = MAX(self->track[i].dur, max_dur); +STATIC void start_parse(synthio_miditrack_obj_t *self) { + self->pos = 0; + self->synth.span.dur = decode_duration(self); + if (self->synth.span.dur == 0) { + // the usual case: the file starts with some MIDI event, not a delay + decode_until_pause(self); } - synthio_synth_init(&self->synth, max_dur); +} + +void common_hal_synthio_miditrack_construct(synthio_miditrack_obj_t *self, + const uint8_t *buffer, uint32_t len, uint32_t tempo, uint32_t sample_rate, + const int16_t *waveform, uint16_t waveform_length, + mp_obj_t envelope) { + + self->tempo = tempo; + self->track.buf = (void *)buffer; + self->track.len = len; + + synthio_synth_init(&self->synth, sample_rate, waveform, waveform_length, envelope); + + start_parse(self); } void common_hal_synthio_miditrack_deinit(synthio_miditrack_obj_t *self) { synthio_synth_deinit(&self->synth); - m_del(synthio_midi_span_t, self->track, self->total_spans + 1); - self->track = NULL; } + bool common_hal_synthio_miditrack_deinited(synthio_miditrack_obj_t *self) { return synthio_synth_deinited(&self->synth); } @@ -157,25 +148,21 @@ uint8_t common_hal_synthio_miditrack_get_channel_count(synthio_miditrack_obj_t * void synthio_miditrack_reset_buffer(synthio_miditrack_obj_t *self, bool single_channel_output, uint8_t channel) { synthio_synth_reset_buffer(&self->synth, single_channel_output, channel); - self->synth.span.dur = 0; - self->next_span = 0; + start_parse(self); } audioio_get_buffer_result_t synthio_miditrack_get_buffer(synthio_miditrack_obj_t *self, bool single_channel_output, uint8_t channel, uint8_t **buffer, uint32_t *buffer_length) { - if (self->synth.span.dur == 0) { - if (self->next_span >= self->total_spans) { - *buffer_length = 0; - return GET_BUFFER_DONE; - } - self->synth.span = self->track[self->next_span++]; - } - synthio_synth_synthesize(&self->synth, buffer, buffer_length, single_channel_output ? 0 : channel); - - return (self->synth.span.dur == 0 && self->next_span >= self->total_spans) ? - GET_BUFFER_DONE : GET_BUFFER_MORE_DATA; + if (self->synth.span.dur == 0) { + if (self->pos == self->track.len) { + return GET_BUFFER_DONE; + } else { + decode_until_pause(self); + } + } + return GET_BUFFER_MORE_DATA; } void synthio_miditrack_get_buffer_structure(synthio_miditrack_obj_t *self, bool single_channel_output, diff --git a/shared-module/synthio/MidiTrack.h b/shared-module/synthio/MidiTrack.h index e301ef355f..549e72fb25 100644 --- a/shared-module/synthio/MidiTrack.h +++ b/shared-module/synthio/MidiTrack.h @@ -34,9 +34,10 @@ typedef struct { mp_obj_base_t base; synthio_synth_t synth; - uint16_t next_span; - uint16_t total_spans; - synthio_midi_span_t *track; + mp_buffer_info_t track; + // invariant: after initial startup, pos always points just after an encoded duration, i.e., at a midi message (or at EOF) + size_t pos; + uint32_t tempo; } synthio_miditrack_obj_t; diff --git a/shared-module/synthio/Synthesizer.c b/shared-module/synthio/Synthesizer.c index 25c91ecbe0..42d0468845 100644 --- a/shared-module/synthio/Synthesizer.c +++ b/shared-module/synthio/Synthesizer.c @@ -30,13 +30,10 @@ void common_hal_synthio_synthesizer_construct(synthio_synthesizer_obj_t *self, - uint32_t sample_rate, const int16_t *waveform, uint16_t waveform_length) { + uint32_t sample_rate, const int16_t *waveform, uint16_t waveform_length, + mp_obj_t envelope) { - self->synth.sample_rate = sample_rate; - self->synth.waveform = waveform; - self->synth.waveform_length = waveform_length; - synthio_synth_init(&self->synth, SYNTHIO_MAX_DUR); - common_hal_synthio_synthesizer_release_all(self); + synthio_synth_init(&self->synth, sample_rate, waveform, waveform_length, envelope); } void common_hal_synthio_synthesizer_deinit(synthio_synthesizer_obj_t *self) { @@ -74,14 +71,18 @@ void synthio_synthesizer_get_buffer_structure(synthio_synthesizer_obj_t *self, b } void common_hal_synthio_synthesizer_release_all(synthio_synthesizer_obj_t *self) { - synthio_span_init(&self->synth.span); + for (size_t i = 0; i < CIRCUITPY_SYNTHIO_MAX_CHANNELS; i++) { + if (self->synth.span.note[i] != SYNTHIO_SILENCE) { + synthio_span_change_note(&self->synth, self->synth.span.note[i], SYNTHIO_SILENCE); + } + } } void common_hal_synthio_synthesizer_release(synthio_synthesizer_obj_t *self, mp_obj_t to_release) { mp_obj_iter_buf_t iter_buf; mp_obj_t iterable = mp_getiter(to_release, &iter_buf); mp_obj_t item; while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { - synthio_span_change_note(&self->synth.span, mp_arg_validate_int_range(mp_obj_get_int(item), 0, 127, MP_QSTR_note), SYNTHIO_SILENCE); + synthio_span_change_note(&self->synth, mp_arg_validate_int_range(mp_obj_get_int(item), 0, 127, MP_QSTR_note), SYNTHIO_SILENCE); } } @@ -90,15 +91,21 @@ void common_hal_synthio_synthesizer_press(synthio_synthesizer_obj_t *self, mp_ob mp_obj_t iterable = mp_getiter(to_press, &iter_buf); mp_obj_t item; while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) { - synthio_span_change_note(&self->synth.span, SYNTHIO_SILENCE, mp_arg_validate_int_range(mp_obj_get_int(item), 0, 127, MP_QSTR_note)); + synthio_span_change_note(&self->synth, SYNTHIO_SILENCE, mp_arg_validate_int_range(mp_obj_get_int(item), 0, 127, MP_QSTR_note)); } } mp_obj_t common_hal_synthio_synthesizer_get_pressed_notes(synthio_synthesizer_obj_t *self) { - mp_obj_tuple_t *result = MP_OBJ_TO_PTR(mp_obj_new_tuple(synthio_span_count_active_channels(&self->synth.span), NULL)); - for (size_t i = 0, j = 0; i < CIRCUITPY_SYNTHIO_MAX_CHANNELS; i++) { - if (self->synth.span.note[i] != SYNTHIO_SILENCE) { - result->items[j++] = MP_OBJ_NEW_SMALL_INT(self->synth.span.note[i]); + int count = 0; + for (int chan = 0; chan < CIRCUITPY_SYNTHIO_MAX_CHANNELS; chan++) { + if (self->synth.span.note[chan] != SYNTHIO_SILENCE && self->synth.envelope_state[chan].state != SYNTHIO_ENVELOPE_STATE_RELEASE) { + count += 1; + } + } + mp_obj_tuple_t *result = MP_OBJ_TO_PTR(mp_obj_new_tuple(count, NULL)); + for (size_t chan = 0, j = 0; chan < CIRCUITPY_SYNTHIO_MAX_CHANNELS; chan++) { + if (self->synth.span.note[chan] != SYNTHIO_SILENCE && self->synth.envelope_state[chan].state != SYNTHIO_ENVELOPE_STATE_RELEASE) { + result->items[j++] = MP_OBJ_NEW_SMALL_INT(self->synth.span.note[chan]); } } return MP_OBJ_FROM_PTR(result); diff --git a/shared-module/synthio/__init__.c b/shared-module/synthio/__init__.c index 11e4c1dcc9..1385059b99 100644 --- a/shared-module/synthio/__init__.c +++ b/shared-module/synthio/__init__.c @@ -26,18 +26,117 @@ */ #include "shared-module/synthio/__init__.h" +#include "shared-bindings/synthio/__init__.h" #include "py/runtime.h" +#include +#include -STATIC const int16_t square_wave[] = {-32768, 32767}; +STATIC const int16_t square_wave[] = {-32768, 0}; STATIC const uint16_t notes[] = {8372, 8870, 9397, 9956, 10548, 11175, 11840, 12544, 13290, 14080, 14917, 15804}; // 9th octave -int synthio_span_count_active_channels(synthio_midi_span_t *span) { - int result = 0; - for (int i = 0; i < CIRCUITPY_SYNTHIO_MAX_CHANNELS; i++) { - if (span->note[i] != SYNTHIO_SILENCE) { - result += 1; +STATIC int16_t convert_time_to_rate(uint32_t sample_rate, mp_obj_t time_in, int16_t difference) { + mp_float_t time = mp_obj_get_float(time_in); + int num_samples = (int)MICROPY_FLOAT_C_FUN(round)(time * sample_rate); + if (num_samples == 0) { + return 0; + } + int16_t result = MIN(32767, MAX(1, abs(difference * SYNTHIO_MAX_DUR) / num_samples)); + return (difference < 0) ? -result : result; +} + +STATIC void synthio_envelope_definition_set(synthio_envelope_definition_t *envelope, mp_obj_t obj, uint32_t sample_rate) { + if (obj == mp_const_none) { + envelope->attack_level = 32767; + envelope->sustain_level = 32767; + envelope->attack_step = 32767; + envelope->decay_step = -32767; + envelope->release_step = -32767; + return; + } + mp_arg_validate_type(obj, (mp_obj_type_t *)&synthio_envelope_type_obj, MP_QSTR_envelope); + + size_t len; + mp_obj_t *fields; + mp_obj_tuple_get(obj, &len, &fields); + + envelope->attack_level = (int)(32767 * mp_obj_get_float(fields[3])); + envelope->sustain_level = (int)(32767 * mp_obj_get_float(fields[4])); + + envelope->attack_step = convert_time_to_rate( + sample_rate, fields[0], envelope->attack_level); + + envelope->decay_step = -convert_time_to_rate( + sample_rate, fields[1], envelope->attack_level - envelope->sustain_level); + + envelope->release_step = -convert_time_to_rate( + sample_rate, fields[2], + envelope->decay_step + ? envelope->sustain_level + : envelope->attack_level); +} + +STATIC void synthio_envelope_state_step(synthio_envelope_state_t *state, synthio_envelope_definition_t *def, size_t n_steps) { + state->substep += n_steps; + while (state->substep >= SYNTHIO_MAX_DUR) { + // max n_steps should be SYNTHIO_MAX_DUR so this loop executes at most + // once + state->substep -= SYNTHIO_MAX_DUR; + switch (state->state) { + case SYNTHIO_ENVELOPE_STATE_SUSTAIN: + break; + case SYNTHIO_ENVELOPE_STATE_ATTACK: + if (def->attack_step != 0) { + state->level = MIN(state->level + def->attack_step, def->attack_level); + if (state->level == def->attack_level) { + state->state = SYNTHIO_ENVELOPE_STATE_DECAY; + } + break; + } + state->state = SYNTHIO_ENVELOPE_STATE_DECAY; + MP_FALLTHROUGH; + case SYNTHIO_ENVELOPE_STATE_DECAY: + if (def->decay_step != 0) { + state->level = MAX(state->level + def->decay_step, def->sustain_level); + assert(state->level >= 0); + if (state->level == def->sustain_level) { + state->state = SYNTHIO_ENVELOPE_STATE_SUSTAIN; + } + break; + } + state->state = SYNTHIO_ENVELOPE_STATE_RELEASE; + MP_FALLTHROUGH; + case SYNTHIO_ENVELOPE_STATE_RELEASE: + if (def->release_step != 0) { + int delta = def->release_step; + state->level = MAX(state->level + delta, 0); + } else { + state->level = 0; + } + break; + } + } +} + +STATIC void synthio_envelope_state_init(synthio_envelope_state_t *state, synthio_envelope_definition_t *def) { + state->level = 0; + state->substep = 0; + state->state = SYNTHIO_ENVELOPE_STATE_ATTACK; + + synthio_envelope_state_step(state, def, SYNTHIO_MAX_DUR); +} + +STATIC void synthio_envelope_state_release(synthio_envelope_state_t *state, synthio_envelope_definition_t *def) { + state->state = SYNTHIO_ENVELOPE_STATE_RELEASE; +} + + +STATIC uint32_t synthio_synth_sum_envelope(synthio_synth_t *synth) { + uint32_t result = 0; + for (int chan = 0; chan < CIRCUITPY_SYNTHIO_MAX_CHANNELS; chan++) { + if (synth->span.note[chan] != SYNTHIO_SILENCE) { + result += synth->envelope_state[chan].level; } } return result; @@ -62,16 +161,23 @@ void synthio_synth_synthesize(synthio_synth_t *synth, uint8_t **bufptr, uint32_t memset(out_buffer, 0, synth->buffer_length); int32_t sample_rate = synth->sample_rate; - int active_channels = synthio_span_count_active_channels(&synth->span); + uint32_t total_envelope = synthio_synth_sum_envelope(synth); const int16_t *waveform = synth->waveform; uint32_t waveform_length = synth->waveform_length; - if (active_channels) { - int16_t loudness = 0xffff / (1 + 2 * active_channels); + if (total_envelope > 0) { + uint16_t ovl_loudness = 0x7fffffff / MAX(0x8000, total_envelope); for (int chan = 0; chan < CIRCUITPY_SYNTHIO_MAX_CHANNELS; chan++) { if (synth->span.note[chan] == SYNTHIO_SILENCE) { synth->accum[chan] = 0; continue; } + // adjust loudness by envelope + uint16_t loudness = (ovl_loudness * synth->envelope_state[chan].level) >> 16; + + if (synth->envelope_state[chan].level == 0) { + // note is truly finished + synth->span.note[chan] = SYNTHIO_SILENCE; + } uint8_t octave = synth->span.note[chan] / 12; uint16_t base_freq = notes[synth->span.note[chan] % 12]; uint32_t accum = synth->accum[chan]; @@ -95,6 +201,11 @@ void synthio_synth_synthesize(synthio_synth_t *synth, uint8_t **bufptr, uint32_t } } + // advance envelope states + for (int chan = 0; chan < CIRCUITPY_SYNTHIO_MAX_CHANNELS; chan++) { + synthio_envelope_state_step(&synth->envelope_state[chan], &synth->envelope_definition, dur); + } + *buffer_length = synth->last_buffer_length = dur * SYNTHIO_BYTES_PER_SAMPLE; *bufptr = (uint8_t *)out_buffer; } @@ -117,11 +228,28 @@ void synthio_synth_deinit(synthio_synth_t *synth) { synth->buffers[1] = NULL; } -void synthio_synth_init(synthio_synth_t *synth, uint16_t max_dur) { - synth->buffer_length = MIN(SYNTHIO_MAX_DUR, max_dur) * SYNTHIO_BYTES_PER_SAMPLE; +void synthio_synth_envelope_set(synthio_synth_t *synth, mp_obj_t envelope_obj) { + synthio_envelope_definition_set(&synth->envelope_definition, envelope_obj, synth->sample_rate); + synth->envelope_obj = envelope_obj; +} + +mp_obj_t synthio_synth_envelope_get(synthio_synth_t *synth) { + return synth->envelope_obj; +} + +void synthio_synth_init(synthio_synth_t *synth, uint32_t sample_rate, const int16_t *waveform, uint16_t waveform_length, mp_obj_t envelope_obj) { + synth->buffer_length = SYNTHIO_MAX_DUR * SYNTHIO_BYTES_PER_SAMPLE; synth->buffers[0] = m_malloc(synth->buffer_length, false); synth->buffers[1] = m_malloc(synth->buffer_length, false); synth->other_channel = -1; + synth->waveform = waveform; + synth->waveform_length = waveform_length; + synth->sample_rate = sample_rate; + synthio_synth_envelope_set(synth, envelope_obj); + + for (size_t i = 0; i < CIRCUITPY_SYNTHIO_MAX_CHANNELS; i++) { + synth->span.note[i] = SYNTHIO_SILENCE; + } } void synthio_synth_get_buffer_structure(synthio_synth_t *synth, bool single_channel_output, @@ -132,40 +260,57 @@ void synthio_synth_get_buffer_structure(synthio_synth_t *synth, bool single_chan *spacing = 1; } +static bool parse_common(mp_buffer_info_t *bufinfo, mp_obj_t o, int16_t what) { + if (o != mp_const_none) { + mp_get_buffer_raise(o, bufinfo, MP_BUFFER_READ); + if (bufinfo->typecode != 'h') { + mp_raise_ValueError_varg(translate("%q must be array of type 'h'"), what); + } + mp_arg_validate_length_range(bufinfo->len / 2, 2, 1024, what); + return true; + } + return false; +} + void synthio_synth_parse_waveform(mp_buffer_info_t *bufinfo_waveform, mp_obj_t waveform_obj) { *bufinfo_waveform = ((mp_buffer_info_t) { .buf = (void *)square_wave, .len = 4 }); + parse_common(bufinfo_waveform, waveform_obj, MP_QSTR_waveform); +} - if (waveform_obj != mp_const_none) { - mp_get_buffer_raise(waveform_obj, bufinfo_waveform, MP_BUFFER_READ); - if (bufinfo_waveform->typecode != 'h') { - mp_raise_ValueError_varg(translate("%q must be array of type 'h'"), MP_QSTR_waveform); +STATIC int find_channel_with_note(synthio_synth_t *synth, uint8_t note) { + for (int i = 0; i < CIRCUITPY_SYNTHIO_MAX_CHANNELS; i++) { + if (synth->span.note[i] == note) { + return i; } } - mp_arg_validate_length_range(bufinfo_waveform->len / 2, 2, 1024, MP_QSTR_waveform); -} - -void synthio_span_init(synthio_midi_span_t *span) { - span->dur = 0; - for (size_t i = 0; i < CIRCUITPY_SYNTHIO_MAX_CHANNELS; i++) { span->note[i] = SYNTHIO_SILENCE; - } -} - -STATIC int find_channel_with_note(const synthio_midi_span_t *span, uint8_t note) { - for (int i = 0; i < CIRCUITPY_SYNTHIO_MAX_CHANNELS; i++) { - if (span->note[i] == note) { - return i; + if (note == SYNTHIO_SILENCE) { + // we need a victim note that is releasing. simple algorithm: lowest numbered slot + for (int i = 0; i < CIRCUITPY_SYNTHIO_MAX_CHANNELS; i++) { + if (SYNTHIO_VOICE_IS_RELEASING(synth, i)) { + return i; + } } } return -1; } -bool synthio_span_change_note(synthio_midi_span_t *span, uint8_t old_note, uint8_t new_note) { - if (new_note != SYNTHIO_SILENCE && find_channel_with_note(span, new_note) != -1) { - return false; // note already pressed, do nothing +bool synthio_span_change_note(synthio_synth_t *synth, uint8_t old_note, uint8_t new_note) { + int channel; + if (new_note != SYNTHIO_SILENCE && (channel = find_channel_with_note(synth, new_note)) != -1) { + // note already playing, re-strike + synthio_envelope_state_init(&synth->envelope_state[channel], &synth->envelope_definition); + synth->accum[channel] = 0; + return true; } - int channel = find_channel_with_note(span, old_note); + channel = find_channel_with_note(synth, old_note); if (channel != -1) { - span->note[channel] = new_note; + if (new_note == SYNTHIO_SILENCE) { + synthio_envelope_state_release(&synth->envelope_state[channel], &synth->envelope_definition); + } else { + synth->span.note[channel] = new_note; + synthio_envelope_state_init(&synth->envelope_state[channel], &synth->envelope_definition); + synth->accum[channel] = 0; + } return true; } return false; diff --git a/shared-module/synthio/__init__.h b/shared-module/synthio/__init__.h index e14e5ead10..56521d3208 100644 --- a/shared-module/synthio/__init__.h +++ b/shared-module/synthio/__init__.h @@ -30,6 +30,7 @@ #define SYNTHIO_BYTES_PER_SAMPLE (SYNTHIO_BITS_PER_SAMPLE / 8) #define SYNTHIO_MAX_DUR (256) #define SYNTHIO_SILENCE (0x80) +#define SYNTHIO_VOICE_IS_RELEASING(synth, i) (synth->envelope_state[i].state == SYNTHIO_ENVELOPE_STATE_RELEASE) #include "shared-module/audiocore/__init__.h" @@ -39,6 +40,25 @@ typedef struct { } synthio_midi_span_t; typedef struct { + // the number of attack or decay steps (signed) per sample + // therefore the maximum time is 32767 samples or 0.68s at 48kHz + // provided the level is maximum (this should be increased!) + int16_t attack_step, decay_step, release_step; + uint16_t attack_level, sustain_level; +} synthio_envelope_definition_t; + +typedef enum { + SYNTHIO_ENVELOPE_STATE_ATTACK, SYNTHIO_ENVELOPE_STATE_DECAY, + SYNTHIO_ENVELOPE_STATE_SUSTAIN, SYNTHIO_ENVELOPE_STATE_RELEASE +} envelope_state_e; + +typedef struct { + int16_t level; + uint16_t substep; + envelope_state_e state; +} synthio_envelope_state_t; + +typedef struct synthio_synth { uint32_t sample_rate; int16_t *buffers[2]; const int16_t *waveform; @@ -46,19 +66,24 @@ typedef struct { uint16_t last_buffer_length; uint8_t other_channel, buffer_index, other_buffer_index; uint16_t waveform_length; + synthio_envelope_definition_t envelope_definition; + mp_obj_t envelope_obj; synthio_midi_span_t span; uint32_t accum[CIRCUITPY_SYNTHIO_MAX_CHANNELS]; + synthio_envelope_state_t envelope_state[CIRCUITPY_SYNTHIO_MAX_CHANNELS]; } synthio_synth_t; -void synthio_span_init(synthio_midi_span_t *span); void synthio_synth_synthesize(synthio_synth_t *synth, uint8_t **buffer, uint32_t *buffer_length, uint8_t channel); void synthio_synth_deinit(synthio_synth_t *synth); bool synthio_synth_deinited(synthio_synth_t *synth); -void synthio_synth_init(synthio_synth_t *synth, uint16_t max_dur); +void synthio_synth_init(synthio_synth_t *synth, uint32_t sample_rate, const int16_t *waveform, uint16_t waveform_length, + mp_obj_t envelope); void synthio_synth_get_buffer_structure(synthio_synth_t *synth, bool single_channel_output, bool *single_buffer, bool *samples_signed, uint32_t *max_buffer_length, uint8_t *spacing); void synthio_synth_reset_buffer(synthio_synth_t *synth, bool single_channel_output, uint8_t channel); void synthio_synth_parse_waveform(mp_buffer_info_t *bufinfo_waveform, mp_obj_t waveform_obj); +void synthio_synth_parse_envelope(uint16_t *envelope_sustain_index, mp_buffer_info_t *bufinfo_envelope, mp_obj_t envelope_obj, mp_obj_t envelope_hold_obj); -bool synthio_span_change_note(synthio_midi_span_t *span, uint8_t old_note, uint8_t new_note); -int synthio_span_count_active_channels(synthio_midi_span_t *span); +bool synthio_span_change_note(synthio_synth_t *synth, uint8_t old_note, uint8_t new_note); + +void synthio_envelope_step(synthio_envelope_definition_t *definition, synthio_envelope_state_t *state, int n_samples); diff --git a/tests/circuitpython/miditrack.py b/tests/circuitpython/miditrack.py index 53a8ca631d..2eac69b152 100644 --- a/tests/circuitpython/miditrack.py +++ b/tests/circuitpython/miditrack.py @@ -11,10 +11,12 @@ SCORE = b"\0\x90@\0\x20\x90b\0\x20\x80@\0\0\x80\b\0" with MidiTrack(SCORE, sample_rate=8000, tempo=640) as m: print(get_structure(m)) - print(get_buffer(m)) + p, q = get_buffer(m) + print(p, list(q)) with MidiTrack( SCORE, sample_rate=8000, tempo=640, waveform=array.array("h", [0, 32767, 0, -32768]) ) as m: print(get_structure(m)) - print(get_buffer(m)) + p, q = get_buffer(m) + print(p, list(q)) diff --git a/tests/circuitpython/miditrack.py.exp b/tests/circuitpython/miditrack.py.exp index bfb082bfe7..2d9e2548a0 100644 --- a/tests/circuitpython/miditrack.py.exp +++ b/tests/circuitpython/miditrack.py.exp @@ -1,4 +1,4 @@ (0, 1, 512, 1) -(1, b'V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5\xaa*\xaa*') +1 [-16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0] (0, 1, 512, 1) -(1, b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00V\xd5V\xd5V\xd5V\xd5V\xd5V\xd5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xaa*\xaa*\xaa*\xaa*\xaa*\xaa*\x00\x00\x00\x00') +1 [0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0] diff --git a/tests/circuitpython/synthesizer.py b/tests/circuitpython/synthesizer.py index bdb273f861..326fef0994 100644 --- a/tests/circuitpython/synthesizer.py +++ b/tests/circuitpython/synthesizer.py @@ -1,10 +1,11 @@ import struct import synthio import audiocore +import ulab.numpy as np def dump_samples(): - print(struct.unpack("12h", audiocore.get_buffer(s)[1][:24])) + print([i for i in audiocore.get_buffer(s)[1][:24]]) s = synthio.Synthesizer(sample_rate=8000) @@ -22,3 +23,16 @@ dump_samples() s.release_then_press((80,)) print(s.pressed) dump_samples() + +envelope = synthio.Envelope( + attack_time=0.1, decay_time=0.05, release_time=0.2, attack_level=1, sustain_level=0.8 +) +s = synthio.Synthesizer(sample_rate=8000, envelope=envelope) +s.press((60,)) +for _ in range(12): + buf = audiocore.get_buffer(s)[1] + print((min(buf), max(buf))) +s.release_all() +for _ in range(12): + buf = audiocore.get_buffer(s)[1] + print((min(buf), max(buf))) diff --git a/tests/circuitpython/synthesizer.py.exp b/tests/circuitpython/synthesizer.py.exp index 79c88b3248..70eb647bab 100644 --- a/tests/circuitpython/synthesizer.py.exp +++ b/tests/circuitpython/synthesizer.py.exp @@ -1,8 +1,32 @@ () -(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) +[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] (80,) -(-10922, -10922, -10922, -10922, 10922, 10922, 10922, 10922, 10922, -10922, -10922, -10922) +[-16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383] (80, 91) -(0, 0, 13106, 13106, 0, -13106, -13106, 0, 13106, 13106, 0, 0) +[-8191, -8191, 0, 0, -8191, -16382, -16382, -8191, 0, 0, -8191, -8191, 0, -8191, -8191, -16382, -16382, -8191, 0, 0, -8191, -8191, 0, -8191] (91,) -(-10922, 10922, 10922, 10922, -10922, -10922, 10922, 10922, 10922, -10922, -10922, 10922) +[-16382, -8191, -8191, 0, -8191, -8191, 0, 0, -8191, -16382, -16382, -8191, 0, 0, -8191, -8191, 0, -8191, -8191, -16382, -16382, -16382, 0, 0] +(-5242, 0) +(-10484, 0) +(-15727, 0) +(-16383, 0) +(-14286, 0) +(-13106, 0) +(-13106, 0) +(-13106, 0) +(-13106, 0) +(-13106, 0) +(-13106, 0) +(-13106, 0) +(-13106, 0) +(-11009, 0) +(-8912, 0) +(-6815, 0) +(-4718, 0) +(-2621, 0) +(-524, 0) +(0, 0) +(0, 0) +(0, 0) +(0, 0) +(0, 0) From b5c33a4c03a7a31cc1bf46a6fa22d79bc82747a4 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sun, 23 Apr 2023 09:24:17 -0500 Subject: [PATCH 079/117] Add a manual test of synthio this allows to test how the midi synthesizer is working, without access to hardware. Run `micropython-coverage midi2wav.py` and it will create `tune.wav` as an output. --- .../synthio/wave/.gitignore | 1 + .../synthio/wave/README.md | 5 + .../synthio/wave/audioop.py | 7 + .../synthio/wave/chunk.py | 169 ++++++ .../synthio/wave/midi2wav.py | 59 ++ .../circuitpython-manual/synthio/wave/wave.py | 546 ++++++++++++++++++ 6 files changed, 787 insertions(+) create mode 100644 tests/circuitpython-manual/synthio/wave/.gitignore create mode 100644 tests/circuitpython-manual/synthio/wave/README.md create mode 100644 tests/circuitpython-manual/synthio/wave/audioop.py create mode 100644 tests/circuitpython-manual/synthio/wave/chunk.py create mode 100644 tests/circuitpython-manual/synthio/wave/midi2wav.py create mode 100644 tests/circuitpython-manual/synthio/wave/wave.py diff --git a/tests/circuitpython-manual/synthio/wave/.gitignore b/tests/circuitpython-manual/synthio/wave/.gitignore new file mode 100644 index 0000000000..c212df9c3d --- /dev/null +++ b/tests/circuitpython-manual/synthio/wave/.gitignore @@ -0,0 +1 @@ +tune.wav diff --git a/tests/circuitpython-manual/synthio/wave/README.md b/tests/circuitpython-manual/synthio/wave/README.md new file mode 100644 index 0000000000..27868bf9f3 --- /dev/null +++ b/tests/circuitpython-manual/synthio/wave/README.md @@ -0,0 +1,5 @@ +# Test synthio without hardware + +Build the uninx port then run `....../ports/unix/micropython-coverage midi2wav.py`. + +This will create `tune.wav` as output, which you can listen to using any old audio player. diff --git a/tests/circuitpython-manual/synthio/wave/audioop.py b/tests/circuitpython-manual/synthio/wave/audioop.py new file mode 100644 index 0000000000..6ec637a3a1 --- /dev/null +++ b/tests/circuitpython-manual/synthio/wave/audioop.py @@ -0,0 +1,7 @@ +import struct + + +def byteswap(data, sampwidth): + print(data) + raise + ch = "I" if sampwidth == 16 else "H" diff --git a/tests/circuitpython-manual/synthio/wave/chunk.py b/tests/circuitpython-manual/synthio/wave/chunk.py new file mode 100644 index 0000000000..eea83c42d6 --- /dev/null +++ b/tests/circuitpython-manual/synthio/wave/chunk.py @@ -0,0 +1,169 @@ +"""Simple class to read IFF chunks. + +An IFF chunk (used in formats such as AIFF, TIFF, RMFF (RealMedia File +Format)) has the following structure: + ++----------------+ +| ID (4 bytes) | ++----------------+ +| size (4 bytes) | ++----------------+ +| data | +| ... | ++----------------+ + +The ID is a 4-byte string which identifies the type of chunk. + +The size field (a 32-bit value, encoded using big-endian byte order) +gives the size of the whole chunk, including the 8-byte header. + +Usually an IFF-type file consists of one or more chunks. The proposed +usage of the Chunk class defined here is to instantiate an instance at +the start of each chunk and read from the instance until it reaches +the end, after which a new instance can be instantiated. At the end +of the file, creating a new instance will fail with an EOFError +exception. + +Usage: +while True: + try: + chunk = Chunk(file) + except EOFError: + break + chunktype = chunk.getname() + while True: + data = chunk.read(nbytes) + if not data: + pass + # do something with data + +The interface is file-like. The implemented methods are: +read, close, seek, tell, isatty. +Extra methods are: skip() (called by close, skips to the end of the chunk), +getname() (returns the name (ID) of the chunk) + +The __init__ method has one required argument, a file-like object +(including a chunk instance), and one optional argument, a flag which +specifies whether or not chunks are aligned on 2-byte boundaries. The +default is 1, i.e. aligned. +""" + + +class Chunk: + def __init__(self, file, align=True, bigendian=True, inclheader=False): + import struct + + self.closed = False + self.align = align # whether to align to word (2-byte) boundaries + if bigendian: + strflag = ">" + else: + strflag = "<" + self.file = file + self.chunkname = file.read(4) + if len(self.chunkname) < 4: + raise EOFError + try: + self.chunksize = struct.unpack_from(strflag + "L", file.read(4))[0] + except struct.error: + raise EOFError from None + if inclheader: + self.chunksize = self.chunksize - 8 # subtract header + self.size_read = 0 + try: + self.offset = self.file.tell() + except (AttributeError, OSError): + self.seekable = False + else: + self.seekable = True + + def getname(self): + """Return the name (ID) of the current chunk.""" + return self.chunkname + + def getsize(self): + """Return the size of the current chunk.""" + return self.chunksize + + def close(self): + if not self.closed: + try: + self.skip() + finally: + self.closed = True + + def isatty(self): + if self.closed: + raise ValueError("I/O operation on closed file") + return False + + def seek(self, pos, whence=0): + """Seek to specified position into the chunk. + Default position is 0 (start of chunk). + If the file is not seekable, this will result in an error. + """ + + if self.closed: + raise ValueError("I/O operation on closed file") + if not self.seekable: + raise OSError("cannot seek") + if whence == 1: + pos = pos + self.size_read + elif whence == 2: + pos = pos + self.chunksize + if pos < 0 or pos > self.chunksize: + raise RuntimeError + self.file.seek(self.offset + pos, 0) + self.size_read = pos + + def tell(self): + if self.closed: + raise ValueError("I/O operation on closed file") + return self.size_read + + def read(self, size=-1): + """Read at most size bytes from the chunk. + If size is omitted or negative, read until the end + of the chunk. + """ + + if self.closed: + raise ValueError("I/O operation on closed file") + if self.size_read >= self.chunksize: + return b"" + if size < 0: + size = self.chunksize - self.size_read + if size > self.chunksize - self.size_read: + size = self.chunksize - self.size_read + data = self.file.read(size) + self.size_read = self.size_read + len(data) + if self.size_read == self.chunksize and self.align and (self.chunksize & 1): + dummy = self.file.read(1) + self.size_read = self.size_read + len(dummy) + return data + + def skip(self): + """Skip the rest of the chunk. + If you are not interested in the contents of the chunk, + this method should be called so that the file points to + the start of the next chunk. + """ + + if self.closed: + raise ValueError("I/O operation on closed file") + if self.seekable: + try: + n = self.chunksize - self.size_read + # maybe fix alignment + if self.align and (self.chunksize & 1): + n = n + 1 + self.file.seek(n, 1) + self.size_read = self.size_read + n + return + except OSError: + pass + while self.size_read < self.chunksize: + n = min(8192, self.chunksize - self.size_read) + dummy = self.read(n) + if not dummy: + raise EOFError diff --git a/tests/circuitpython-manual/synthio/wave/midi2wav.py b/tests/circuitpython-manual/synthio/wave/midi2wav.py new file mode 100644 index 0000000000..daa46a28c0 --- /dev/null +++ b/tests/circuitpython-manual/synthio/wave/midi2wav.py @@ -0,0 +1,59 @@ +import audiocore +import synthio +from ulab import numpy as np +import wave + +SAMPLE_SIZE = 1024 +VOLUME = 32700 +sine = np.array( + np.sin(np.linspace(0, 2 * np.pi, SAMPLE_SIZE, endpoint=False)) * VOLUME, + dtype=np.int16, +) + +envelope = synthio.Envelope( + attack_time=0.1, decay_time=0.05, release_time=0.2, attack_level=1, sustain_level=0.8 +) +melody = synthio.MidiTrack( + b"\0\x90H\0*\x80H\0\6\x90J\0*\x80J\0\6\x90L\0*\x80L\0\6\x90J\0" + + b"*\x80J\0\6\x90H\0*\x80H\0\6\x90J\0*\x80J\0\6\x90L\0T\x80L\0" + + b"\x0c\x90H\0T\x80H\0\x0c\x90H\0T\x80H\0", + tempo=240, + sample_rate=48000, + waveform=sine, + envelope=envelope, +) + +# sox -r 48000 -e signed -b 16 -c 1 tune.raw tune.wav +with wave.open("tune.wav", "w") as f: + f.setnchannels(1) + f.setsampwidth(2) + f.setframerate(48000) + while True: + result, data = audiocore.get_buffer(melody) + if data is None: + break + f.writeframes(data) + if result != 1: + break + +melody = synthio.MidiTrack( + b"\0\x90H\0*\x80H\0\6\x90J\0*\x80J\0\6\x90L\0*\x80L\0\6\x90J\0" + + b"*\x80J\0\6\x90H\0*\x80H\0\6\x90J\0*\x80J\0\6\x90L\0T\x80L\0" + + b"\x0c\x90H\0T\x80H\0\x0c\x90H\0T\x80H\0", + tempo=240, + sample_rate=48000, + waveform=sine, +) + +# sox -r 48000 -e signed -b 16 -c 1 tune.raw tune.wav +with wave.open("tune-noenv.wav", "w") as f: + f.setnchannels(1) + f.setsampwidth(2) + f.setframerate(48000) + while True: + result, data = audiocore.get_buffer(melody) + if data is None: + break + f.writeframes(data) + if result != 1: + break diff --git a/tests/circuitpython-manual/synthio/wave/wave.py b/tests/circuitpython-manual/synthio/wave/wave.py new file mode 100644 index 0000000000..903295a4ba --- /dev/null +++ b/tests/circuitpython-manual/synthio/wave/wave.py @@ -0,0 +1,546 @@ +"""Stuff to parse WAVE files. + +Usage. + +Reading WAVE files: + f = wave.open(file, 'r') +where file is either the name of a file or an open file pointer. +The open file pointer must have methods read(), seek(), and close(). +When the setpos() and rewind() methods are not used, the seek() +method is not necessary. + +This returns an instance of a class with the following public methods: + getnchannels() -- returns number of audio channels (1 for + mono, 2 for stereo) + getsampwidth() -- returns sample width in bytes + getframerate() -- returns sampling frequency + getnframes() -- returns number of audio frames + getcomptype() -- returns compression type ('NONE' for linear samples) + getcompname() -- returns human-readable version of + compression type ('not compressed' linear samples) + getparams() -- returns a namedtuple consisting of all of the + above in the above order + getmarkers() -- returns None (for compatibility with the + aifc module) + getmark(id) -- raises an error since the mark does not + exist (for compatibility with the aifc module) + readframes(n) -- returns at most n frames of audio + rewind() -- rewind to the beginning of the audio stream + setpos(pos) -- seek to the specified position + tell() -- return the current position + close() -- close the instance (make it unusable) +The position returned by tell() and the position given to setpos() +are compatible and have nothing to do with the actual position in the +file. +The close() method is called automatically when the class instance +is destroyed. + +Writing WAVE files: + f = wave.open(file, 'w') +where file is either the name of a file or an open file pointer. +The open file pointer must have methods write(), tell(), seek(), and +close(). + +This returns an instance of a class with the following public methods: + setnchannels(n) -- set the number of channels + setsampwidth(n) -- set the sample width + setframerate(n) -- set the frame rate + setnframes(n) -- set the number of frames + setcomptype(type, name) + -- set the compression type and the + human-readable compression type + setparams(tuple) + -- set all parameters at once + tell() -- return current position in output file + writeframesraw(data) + -- write audio frames without patching up the + file header + writeframes(data) + -- write audio frames and patch up the file header + close() -- patch up the file header and close the + output file +You should set the parameters before the first writeframesraw or +writeframes. The total number of frames does not need to be set, +but when it is set to the correct value, the header does not have to +be patched up. +It is best to first set all parameters, perhaps possibly the +compression type, and then write audio frames using writeframesraw. +When all frames have been written, either call writeframes(b'') or +close() to patch up the sizes in the header. +The close() method is called automatically when the class instance +is destroyed. +""" + +from chunk import Chunk +from collections import namedtuple +import audioop +import builtins +import struct +import sys + + +__all__ = ["open", "Error", "Wave_read", "Wave_write"] + + +class Error(Exception): + pass + + +WAVE_FORMAT_PCM = 0x0001 + +_array_fmts = None, "b", "h", None, "i" + +_wave_params = namedtuple( + "_wave_params", "nchannels sampwidth framerate nframes comptype compname" +) + + +class Wave_read: + """Variables used in this class: + + These variables are available to the user though appropriate + methods of this class: + _file -- the open file with methods read(), close(), and seek() + set through the __init__() method + _nchannels -- the number of audio channels + available through the getnchannels() method + _nframes -- the number of audio frames + available through the getnframes() method + _sampwidth -- the number of bytes per audio sample + available through the getsampwidth() method + _framerate -- the sampling frequency + available through the getframerate() method + _comptype -- the AIFF-C compression type ('NONE' if AIFF) + available through the getcomptype() method + _compname -- the human-readable AIFF-C compression type + available through the getcomptype() method + _soundpos -- the position in the audio stream + available through the tell() method, set through the + setpos() method + + These variables are used internally only: + _fmt_chunk_read -- 1 iff the FMT chunk has been read + _data_seek_needed -- 1 iff positioned correctly in audio + file for readframes() + _data_chunk -- instantiation of a chunk class for the DATA chunk + _framesize -- size of one frame in the file + """ + + def initfp(self, file): + self._convert = None + self._soundpos = 0 + self._file = Chunk(file, bigendian=0) + if self._file.getname() != b"RIFF": + raise Error("file does not start with RIFF id") + if self._file.read(4) != b"WAVE": + raise Error("not a WAVE file") + self._fmt_chunk_read = 0 + self._data_chunk = None + while 1: + self._data_seek_needed = 1 + try: + chunk = Chunk(self._file, bigendian=0) + except EOFError: + break + chunkname = chunk.getname() + if chunkname == b"fmt ": + self._read_fmt_chunk(chunk) + self._fmt_chunk_read = 1 + elif chunkname == b"data": + if not self._fmt_chunk_read: + raise Error("data chunk before fmt chunk") + self._data_chunk = chunk + self._nframes = chunk.chunksize // self._framesize + self._data_seek_needed = 0 + break + chunk.skip() + if not self._fmt_chunk_read or not self._data_chunk: + raise Error("fmt chunk and/or data chunk missing") + + def __init__(self, f): + self._i_opened_the_file = None + if isinstance(f, str): + f = builtins.open(f, "rb") + self._i_opened_the_file = f + # else, assume it is an open file object already + try: + self.initfp(f) + except: + if self._i_opened_the_file: + f.close() + raise + + def __del__(self): + self.close() + + def __enter__(self): + return self + + def __exit__(self, *args): + self.close() + + # + # User visible methods. + # + def getfp(self): + return self._file + + def rewind(self): + self._data_seek_needed = 1 + self._soundpos = 0 + + def close(self): + self._file = None + file = self._i_opened_the_file + if file: + self._i_opened_the_file = None + file.close() + + def tell(self): + return self._soundpos + + def getnchannels(self): + return self._nchannels + + def getnframes(self): + return self._nframes + + def getsampwidth(self): + return self._sampwidth + + def getframerate(self): + return self._framerate + + def getcomptype(self): + return self._comptype + + def getcompname(self): + return self._compname + + def getparams(self): + return _wave_params( + self.getnchannels(), + self.getsampwidth(), + self.getframerate(), + self.getnframes(), + self.getcomptype(), + self.getcompname(), + ) + + def getmarkers(self): + return None + + def getmark(self, id): + raise Error("no marks") + + def setpos(self, pos): + if pos < 0 or pos > self._nframes: + raise Error("position not in range") + self._soundpos = pos + self._data_seek_needed = 1 + + def readframes(self, nframes): + if self._data_seek_needed: + self._data_chunk.seek(0, 0) + pos = self._soundpos * self._framesize + if pos: + self._data_chunk.seek(pos, 0) + self._data_seek_needed = 0 + if nframes == 0: + return b"" + data = self._data_chunk.read(nframes * self._framesize) + if self._sampwidth != 1 and sys.byteorder == "big": + data = audioop.byteswap(data, self._sampwidth) + if self._convert and data: + data = self._convert(data) + self._soundpos = self._soundpos + len(data) // (self._nchannels * self._sampwidth) + return data + + # + # Internal methods. + # + + def _read_fmt_chunk(self, chunk): + try: + ( + wFormatTag, + self._nchannels, + self._framerate, + dwAvgBytesPerSec, + wBlockAlign, + ) = struct.unpack_from(" 4: + raise Error("bad sample width") + self._sampwidth = sampwidth + + def getsampwidth(self): + if not self._sampwidth: + raise Error("sample width not set") + return self._sampwidth + + def setframerate(self, framerate): + if self._datawritten: + raise Error("cannot change parameters after starting to write") + if framerate <= 0: + raise Error("bad frame rate") + self._framerate = int(round(framerate)) + + def getframerate(self): + if not self._framerate: + raise Error("frame rate not set") + return self._framerate + + def setnframes(self, nframes): + if self._datawritten: + raise Error("cannot change parameters after starting to write") + self._nframes = nframes + + def getnframes(self): + return self._nframeswritten + + def setcomptype(self, comptype, compname): + if self._datawritten: + raise Error("cannot change parameters after starting to write") + if comptype not in ("NONE",): + raise Error("unsupported compression type") + self._comptype = comptype + self._compname = compname + + def getcomptype(self): + return self._comptype + + def getcompname(self): + return self._compname + + def setparams(self, params): + nchannels, sampwidth, framerate, nframes, comptype, compname = params + if self._datawritten: + raise Error("cannot change parameters after starting to write") + self.setnchannels(nchannels) + self.setsampwidth(sampwidth) + self.setframerate(framerate) + self.setnframes(nframes) + self.setcomptype(comptype, compname) + + def getparams(self): + if not self._nchannels or not self._sampwidth or not self._framerate: + raise Error("not all parameters set") + return _wave_params( + self._nchannels, + self._sampwidth, + self._framerate, + self._nframes, + self._comptype, + self._compname, + ) + + def setmark(self, id, pos, name): + raise Error("setmark() not supported") + + def getmark(self, id): + raise Error("no marks") + + def getmarkers(self): + return None + + def tell(self): + return self._nframeswritten + + def writeframesraw(self, data): + if not isinstance(data, (bytes, bytearray)): + data = memoryview(data).cast("B") + self._ensure_header_written(len(data)) + nframes = len(data) // (self._sampwidth * self._nchannels) + if self._convert: + data = self._convert(data) + if self._sampwidth != 1 and sys.byteorder == "big": + data = audioop.byteswap(data, self._sampwidth) + self._file.write(data) + self._datawritten += len(data) + self._nframeswritten = self._nframeswritten + nframes + + def writeframes(self, data): + self.writeframesraw(data) + if self._datalength != self._datawritten: + self._patchheader() + + def close(self): + try: + if self._file: + self._ensure_header_written(0) + if self._datalength != self._datawritten: + self._patchheader() + self._file.flush() + finally: + self._file = None + file = self._i_opened_the_file + if file: + self._i_opened_the_file = None + file.close() + + # + # Internal methods. + # + + def _ensure_header_written(self, datasize): + if not self._headerwritten: + if not self._nchannels: + raise Error("# channels not specified") + if not self._sampwidth: + raise Error("sample width not specified") + if not self._framerate: + raise Error("sampling rate not specified") + self._write_header(datasize) + + def _write_header(self, initlength): + assert not self._headerwritten + self._file.write(b"RIFF") + if not self._nframes: + self._nframes = initlength // (self._nchannels * self._sampwidth) + self._datalength = self._nframes * self._nchannels * self._sampwidth + try: + self._form_length_pos = self._file.tell() + except (AttributeError, OSError): + self._form_length_pos = None + self._file.write( + struct.pack( + " Date: Tue, 25 Apr 2023 08:21:31 -0500 Subject: [PATCH 080/117] Disable synthio on two boards where it doesn't fit --- ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk | 2 +- ports/stm/boards/thunderpack_v11/mpconfigboard.mk | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk b/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk index 49be084ddf..e297e96d95 100644 --- a/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk +++ b/ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk @@ -48,7 +48,7 @@ CIRCUITPY_KEYPAD_SHIFTREGISTERKEYS = 0 CIRCUITPY_KEYPAD_KEYMATRIX = 0 CIRCUITPY_MATH = 1 CIRCUITPY_STAGE = 1 -CIRCUITPY_SYNTHIO = 1 +CIRCUITPY_SYNTHIO = 0 CIRCUITPY_ZLIB = 1 FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-stage/pewpew_m4 diff --git a/ports/stm/boards/thunderpack_v11/mpconfigboard.mk b/ports/stm/boards/thunderpack_v11/mpconfigboard.mk index 0aa8ce6746..376f54ac6d 100644 --- a/ports/stm/boards/thunderpack_v11/mpconfigboard.mk +++ b/ports/stm/boards/thunderpack_v11/mpconfigboard.mk @@ -19,6 +19,7 @@ LD_FILE = boards/STM32F411_nvm.ld CIRCUITPY_AESIO = 0 CIRCUITPY_BITMAPTOOLS = 0 CIRCUITPY_BLEIO_HCI = 0 +CIRCUITPY_SYNTHIO = 0 CIRCUITPY_VECTORIO = 0 CIRCUITPY_ULAB = 0 CIRCUITPY_ZLIB = 0 From 95acec0f55d53213a2475f7c03af95c1fd3e757b Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Tue, 25 Apr 2023 13:22:42 -0400 Subject: [PATCH 081/117] Improve pin names --- .../boards/adafruit_feather_rp2040_prop_maker/pins.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/pins.c b/ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/pins.c index 96e0bc71df..20368dd6fd 100644 --- a/ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/pins.c +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_prop_maker/pins.c @@ -42,12 +42,12 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_I2S_DATA), MP_ROM_PTR(&pin_GPIO16) }, { MP_ROM_QSTR(MP_QSTR_I2S_BIT_CLOCK), MP_ROM_PTR(&pin_GPIO17) }, - { MP_ROM_QSTR(MP_QSTR_WORD_SELECT), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_I2S_WORD_SELECT), MP_ROM_PTR(&pin_GPIO18) }, { MP_ROM_QSTR(MP_QSTR_EXTERNAL_BUTTON), MP_ROM_PTR(&pin_GPIO19) }, - { MP_ROM_QSTR(MP_QSTR_SERVO), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_EXTERNAL_SERVO), MP_ROM_PTR(&pin_GPIO20) }, { MP_ROM_QSTR(MP_QSTR_EXTERNAL_NEOPIXELS), MP_ROM_PTR(&pin_GPIO21) }, { MP_ROM_QSTR(MP_QSTR_ACCELEROMETER_INTERRUPT), MP_ROM_PTR(&pin_GPIO22) }, - { MP_ROM_QSTR(MP_QSTR_EXTERNAL_NEOPIXELS_POWER), MP_ROM_PTR(&pin_GPIO23) }, + { MP_ROM_QSTR(MP_QSTR_EXTERNAL_POWER), MP_ROM_PTR(&pin_GPIO23) }, { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, { MP_ROM_QSTR(MP_QSTR_STEMMA_I2C), MP_ROM_PTR(&board_i2c_obj) }, From eab202aa530b17993be4a440cc99b28577fceaa6 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 25 Apr 2023 10:36:34 -0700 Subject: [PATCH 082/117] Fix SH110x --- shared-module/displayio/Display.c | 10 +++++----- shared-module/displayio/Display.h | 5 ----- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/shared-module/displayio/Display.c b/shared-module/displayio/Display.c index 6d4acbe8c0..093604214d 100644 --- a/shared-module/displayio/Display.c +++ b/shared-module/displayio/Display.c @@ -65,7 +65,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t *self, } displayio_display_core_construct(&self->core, bus, width, height, ram_width, ram_height, colstart, rowstart, rotation, color_depth, grayscale, pixels_in_byte_share_row, bytes_per_cell, reverse_pixels_in_byte, reverse_bytes_in_word, - set_column_command, set_row_command, NO_COMMAND, NO_COMMAND, self->data_as_commands, false /* always_toggle_chip_select */, + set_column_command, set_row_command, NO_COMMAND, NO_COMMAND, data_as_commands, false /* always_toggle_chip_select */, SH1107_addressing && color_depth == 1, false /*address_little_endian */); self->write_ram_command = write_ram_command; @@ -86,7 +86,7 @@ void common_hal_displayio_display_construct(displayio_display_obj_t *self, while (!displayio_display_core_begin_transaction(&self->core)) { RUN_BACKGROUND_TASKS; } - if (self->data_as_commands) { + if (self->core.data_as_commands) { uint8_t full_command[data_size + 1]; full_command[0] = cmd[0]; memcpy(full_command + 1, data, data_size); @@ -185,7 +185,7 @@ bool common_hal_displayio_display_set_brightness(displayio_display_obj_t *self, } else if (self->brightness_command != NO_BRIGHTNESS_COMMAND) { ok = displayio_display_core_begin_transaction(&self->core); if (ok) { - if (self->data_as_commands) { + if (self->core.data_as_commands) { uint8_t set_brightness[2] = {self->brightness_command, (uint8_t)(0xff * brightness)}; self->core.send(self->core.bus, DISPLAY_COMMAND, CHIP_SELECT_TOGGLE_EVERY_BYTE, set_brightness, 2); } else { @@ -226,7 +226,7 @@ STATIC const displayio_area_t *_get_refresh_areas(displayio_display_obj_t *self) } STATIC void _send_pixels(displayio_display_obj_t *self, uint8_t *pixels, uint32_t length) { - if (!self->data_as_commands) { + if (!self->core.data_as_commands) { self->core.send(self->core.bus, DISPLAY_COMMAND, CHIP_SELECT_TOGGLE_EVERY_BYTE, &self->write_ram_command, 1); } self->core.send(self->core.bus, DISPLAY_DATA, CHIP_SELECT_UNTOUCHED, pixels, length); @@ -247,7 +247,7 @@ STATIC bool _refresh_area(displayio_display_obj_t *self, const displayio_area_t uint16_t subrectangles = 1; // for SH1107 and other boundary constrained controllers // write one single row at a time - if (self->SH1107_addressing) { + if (self->core.SH1107_addressing) { subrectangles = rows_per_buffer / 8; // page addressing mode writes 8 rows at a time rows_per_buffer = 8; } else if (displayio_area_size(&clipped) > buffer_size * pixels_per_word) { diff --git a/shared-module/displayio/Display.h b/shared-module/displayio/Display.h index c60adc482f..e56aa87a5f 100644 --- a/shared-module/displayio/Display.h +++ b/shared-module/displayio/Display.h @@ -50,15 +50,10 @@ typedef struct { uint16_t brightness_command; uint16_t native_frames_per_second; uint16_t native_ms_per_frame; - uint8_t set_column_command; - uint8_t set_row_command; uint8_t write_ram_command; bool auto_refresh; bool first_manual_refresh; - bool data_as_commands; bool backlight_on_high; - // new quirk for sh1107 - bool SH1107_addressing; } displayio_display_obj_t; void displayio_display_background(displayio_display_obj_t *self); From 75046b3a58b698e61036fed12ae10f22d23a07a2 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 25 Apr 2023 13:26:48 -0700 Subject: [PATCH 083/117] Save space with consolidated errors --- shared-bindings/displayio/Display.c | 2 +- .../framebufferio/FramebufferDisplay.c | 2 +- shared-bindings/is31fl3741/FrameBuffer.c | 2 +- shared-bindings/rgbmatrix/RGBMatrix.c | 2 +- shared-module/displayio/Shape.c | 16 +++++++++------- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 49194ebd1e..d6326d6d3b 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -358,7 +358,7 @@ STATIC mp_obj_t displayio_display_obj_set_brightness(mp_obj_t self_in, mp_obj_t displayio_display_obj_t *self = native_display(self_in); mp_float_t brightness = mp_obj_get_float(brightness_obj); if (brightness < 0 || brightness > 1.0) { - mp_raise_ValueError(translate("Brightness must be 0-1.0")); + mp_raise_ValueError_varg(translate("%q must be %d-%d"), MP_QSTR_brightness, 0, 1); } bool ok = common_hal_displayio_display_set_brightness(self, brightness); if (!ok) { diff --git a/shared-bindings/framebufferio/FramebufferDisplay.c b/shared-bindings/framebufferio/FramebufferDisplay.c index 030b924c1e..826f69fd83 100644 --- a/shared-bindings/framebufferio/FramebufferDisplay.c +++ b/shared-bindings/framebufferio/FramebufferDisplay.c @@ -194,7 +194,7 @@ STATIC mp_obj_t framebufferio_framebufferdisplay_obj_set_brightness(mp_obj_t sel framebufferio_framebufferdisplay_obj_t *self = native_display(self_in); mp_float_t brightness = mp_obj_get_float(brightness_obj); if (brightness < 0.0f || brightness > 1.0f) { - mp_raise_ValueError(translate("Brightness must be 0-1.0")); + mp_raise_ValueError_varg(translate("%q must be %d-%d"), MP_QSTR_brightness, 0, 1); } bool ok = common_hal_framebufferio_framebufferdisplay_set_brightness(self, brightness); if (!ok) { diff --git a/shared-bindings/is31fl3741/FrameBuffer.c b/shared-bindings/is31fl3741/FrameBuffer.c index f907a1dcd3..02a783fd15 100644 --- a/shared-bindings/is31fl3741/FrameBuffer.c +++ b/shared-bindings/is31fl3741/FrameBuffer.c @@ -162,7 +162,7 @@ STATIC mp_obj_t is31fl3741_FrameBuffer_set_brightness(mp_obj_t self_in, mp_obj_t check_for_deinit(self); mp_float_t brightness = mp_obj_get_float(value_in); if (brightness < 0.0f || brightness > 1.0f) { - mp_raise_ValueError(translate("Brightness must be 0-1.0")); + mp_raise_ValueError_varg(translate("%q must be %d-%d"), MP_QSTR_brightness, 0, 1); } uint8_t current = (uint8_t)(brightness * 0xFF); diff --git a/shared-bindings/rgbmatrix/RGBMatrix.c b/shared-bindings/rgbmatrix/RGBMatrix.c index f2877531bb..129d77e321 100644 --- a/shared-bindings/rgbmatrix/RGBMatrix.c +++ b/shared-bindings/rgbmatrix/RGBMatrix.c @@ -294,7 +294,7 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_set_brightness(mp_obj_t self_in, mp_obj_t va check_for_deinit(self); mp_float_t brightness = mp_obj_get_float(value_in); if (brightness < 0.0f || brightness > 1.0f) { - mp_raise_ValueError(translate("Brightness must be 0-1.0")); + mp_raise_ValueError_varg(translate("%q must be %d-%d"), MP_QSTR_brightness, 0, 1); } common_hal_rgbmatrix_rgbmatrix_set_paused(self, brightness <= 0); diff --git a/shared-module/displayio/Shape.c b/shared-module/displayio/Shape.c index 4a32c7a606..1d6db5bd69 100644 --- a/shared-module/displayio/Shape.c +++ b/shared-module/displayio/Shape.c @@ -63,15 +63,17 @@ void common_hal_displayio_shape_construct(displayio_shape_t *self, uint32_t widt } void common_hal_displayio_shape_set_boundary(displayio_shape_t *self, uint16_t y, uint16_t start_x, uint16_t end_x) { - if (y < 0 || y >= self->height || (self->mirror_y && y >= self->half_height)) { - mp_raise_ValueError(translate("y value out of bounds")); + uint16_t max_y = self->height - 1; + if (self->mirror_y) { + max_y = self->half_height - 1; } - if (start_x < 0 || start_x >= self->width || end_x < 0 || end_x >= self->width) { - mp_raise_ValueError(translate("x value out of bounds")); - } - if (self->mirror_x && (start_x >= self->half_width || end_x >= self->half_width)) { - mp_raise_ValueError_varg(translate("Maximum x value when mirrored is %d"), self->half_width); + mp_arg_validate_int_range(y, 0, max_y, MP_QSTR_y); + uint16_t max_x = self->width - 1; + if (self->mirror_x) { + max_x = self->half_width - 1; } + mp_arg_validate_int_range(start_x, 0, max_x, MP_QSTR_start_x); + mp_arg_validate_int_range(end_x, 0, max_x, MP_QSTR_end_x); uint16_t lower_x, upper_x, lower_y, upper_y; From 6c850349528c4da31141ff0d6a6b90b01e4cb901 Mon Sep 17 00:00:00 2001 From: Marco Sirabella Date: Tue, 25 Apr 2023 15:16:42 -0600 Subject: [PATCH 084/117] Bump recommended shallow-since 1.5 years forward --- py/makeversionhdr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py/makeversionhdr.py b/py/makeversionhdr.py index 6576c3abbb..21ad92f1d8 100644 --- a/py/makeversionhdr.py +++ b/py/makeversionhdr.py @@ -66,7 +66,7 @@ def cannot_determine_version(): CircuitPython must be built from a git clone with tags. If you cloned from a fork, fetch the tags from adafruit/circuitpython as follows: - git fetch --tags --recurse-submodules=no --shallow-since="2021-07-01" https://github.com/adafruit/circuitpython HEAD""" + git fetch --tags --recurse-submodules=no --shallow-since="2023-02-01" https://github.com/adafruit/circuitpython HEAD""" ) From 863042dfd0abebba04be242b33b6f1a4f5d6bab5 Mon Sep 17 00:00:00 2001 From: Marco Sirabella Date: Tue, 25 Apr 2023 16:05:20 -0600 Subject: [PATCH 085/117] Move git command to update necessary tags to submodule I ran into this one since I did an initial shallow clone due to slow pycon 2023 wifi. --- Makefile | 4 ++++ py/makeversionhdr.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d0f1fcb3d0..d611dff49d 100644 --- a/Makefile +++ b/Makefile @@ -345,3 +345,7 @@ fetch-submodules: remove-submodules: git submodule deinit -f --all rm -rf .git/modules/* + +.PHONY: fetch-tags +fetch-tags: + git fetch --tags --recurse-submodules=no --shallow-since="2023-02-01" https://github.com/adafruit/circuitpython HEAD diff --git a/py/makeversionhdr.py b/py/makeversionhdr.py index 21ad92f1d8..b0d00a694e 100644 --- a/py/makeversionhdr.py +++ b/py/makeversionhdr.py @@ -66,7 +66,7 @@ def cannot_determine_version(): CircuitPython must be built from a git clone with tags. If you cloned from a fork, fetch the tags from adafruit/circuitpython as follows: - git fetch --tags --recurse-submodules=no --shallow-since="2023-02-01" https://github.com/adafruit/circuitpython HEAD""" + make fetch-tags""" ) From 4214f2bb77bd38844223ce4a36bd8ec84c740b28 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Wed, 26 Apr 2023 11:01:56 -0400 Subject: [PATCH 086/117] Rename ports/raspberrypi/boards/pimoroni_pico_dv to ports/raspberrypi/boards/pimoroni_pico_dv_base --- .../boards/{pimoroni_pico_dv => pimoroni_pico_dv_base}/board.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ports/raspberrypi/boards/{pimoroni_pico_dv => pimoroni_pico_dv_base}/board.c (100%) diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv/board.c b/ports/raspberrypi/boards/pimoroni_pico_dv_base/board.c similarity index 100% rename from ports/raspberrypi/boards/pimoroni_pico_dv/board.c rename to ports/raspberrypi/boards/pimoroni_pico_dv_base/board.c From 9f38304c2054df58a00fe5fb28eac99e46bc57c8 Mon Sep 17 00:00:00 2001 From: Chenxi Xiao <347396430@qq.com> Date: Wed, 26 Apr 2023 11:45:57 -0600 Subject: [PATCH 087/117] Update zh_Latn_pinyin.po --- locale/zh_Latn_pinyin.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index ec33771682..133958f5a6 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -1322,7 +1322,7 @@ msgstr "Géshì kuài dàxiǎo wúxiào" #: shared-bindings/wifi/Radio.c msgid "Invalid hex password" -msgstr "" +msgstr "Shíliù jìn zhì mìmǎ wúxiào" #: ports/espressif/common-hal/wifi/Radio.c msgid "Invalid multicast MAC address" From 6e8031faf846f2f4e5c3b9ca5305c7c1f66a3bb8 Mon Sep 17 00:00:00 2001 From: anecdata <16617689+anecdata@users.noreply.github.com> Date: Wed, 26 Apr 2023 13:53:33 -0500 Subject: [PATCH 088/117] Note limitation of next_stack_limit on espressif boards Open to better wording. --- shared-bindings/supervisor/Runtime.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/shared-bindings/supervisor/Runtime.c b/shared-bindings/supervisor/Runtime.c index ecdd914a8f..1cc2f0abb1 100644 --- a/shared-bindings/supervisor/Runtime.c +++ b/shared-bindings/supervisor/Runtime.c @@ -187,8 +187,10 @@ MP_PROPERTY_GETSET(supervisor_runtime_ble_workflow_obj, (mp_obj_t)&supervisor_runtime_set_ble_workflow_obj); //| next_stack_limit: int -//| """The size of the stack for the next vm run. If its too large, the default will be used.""" +//| """The size of the stack for the next vm run. If its too large, the default will be used. //| +//| **Limitations**: Stack size is fixed at startup on ``espressif`` port and this will have no effect. +//| """ STATIC mp_obj_t supervisor_runtime_get_next_stack_limit(mp_obj_t self) { return mp_obj_new_int(get_next_stack_size()); } From c333e6168179ca3c012f5d2578066825c64c61d7 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Wed, 26 Apr 2023 14:58:45 -0400 Subject: [PATCH 089/117] small wording change --- shared-bindings/supervisor/Runtime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/supervisor/Runtime.c b/shared-bindings/supervisor/Runtime.c index 1cc2f0abb1..792f18637a 100644 --- a/shared-bindings/supervisor/Runtime.c +++ b/shared-bindings/supervisor/Runtime.c @@ -189,7 +189,7 @@ MP_PROPERTY_GETSET(supervisor_runtime_ble_workflow_obj, //| next_stack_limit: int //| """The size of the stack for the next vm run. If its too large, the default will be used. //| -//| **Limitations**: Stack size is fixed at startup on ``espressif`` port and this will have no effect. +//| **Limitations**: Stack size is fixed at startup on the ``espressif`` port; setting this will have no effect. //| """ STATIC mp_obj_t supervisor_runtime_get_next_stack_limit(mp_obj_t self) { return mp_obj_new_int(get_next_stack_size()); From 5d0c37f19807daf37817795fe5bfb44845c86130 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Wed, 26 Apr 2023 17:45:59 -0400 Subject: [PATCH 090/117] Rename folders and add VID/PID from Pimoroni --- .../mpconfigboard.h | 2 +- .../mpconfigboard.mk | 8 +- .../pico-sdk-configboard.h | 0 .../pins.c | 0 .../boards/pimoroni_pico_dv_base_w/board.c | 52 +++++++++++ .../boards/pimoroni_pico_dv_base_w/link.ld | 1 + .../pimoroni_pico_dv_base_w/mpconfigboard.h | 10 +++ .../pimoroni_pico_dv_base_w/mpconfigboard.mk | 26 ++++++ .../pico-sdk-configboard.h | 4 + .../boards/pimoroni_pico_dv_base_w/pins.c | 89 +++++++++++++++++++ 10 files changed, 187 insertions(+), 5 deletions(-) rename ports/raspberrypi/boards/{pimoroni_pico_dv => pimoroni_pico_dv_base}/mpconfigboard.h (75%) rename ports/raspberrypi/boards/{pimoroni_pico_dv => pimoroni_pico_dv_base}/mpconfigboard.mk (51%) rename ports/raspberrypi/boards/{pimoroni_pico_dv => pimoroni_pico_dv_base}/pico-sdk-configboard.h (100%) rename ports/raspberrypi/boards/{pimoroni_pico_dv => pimoroni_pico_dv_base}/pins.c (100%) create mode 100644 ports/raspberrypi/boards/pimoroni_pico_dv_base_w/board.c create mode 100644 ports/raspberrypi/boards/pimoroni_pico_dv_base_w/link.ld create mode 100644 ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.h create mode 100644 ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.mk create mode 100644 ports/raspberrypi/boards/pimoroni_pico_dv_base_w/pico-sdk-configboard.h create mode 100644 ports/raspberrypi/boards/pimoroni_pico_dv_base_w/pins.c diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.h b/ports/raspberrypi/boards/pimoroni_pico_dv_base/mpconfigboard.h similarity index 75% rename from ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.h rename to ports/raspberrypi/boards/pimoroni_pico_dv_base/mpconfigboard.h index bf18491e47..969ccf74d8 100644 --- a/ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.h +++ b/ports/raspberrypi/boards/pimoroni_pico_dv_base/mpconfigboard.h @@ -1,4 +1,4 @@ -#define MICROPY_HW_BOARD_NAME "Pimoroni Pico DV" +#define MICROPY_HW_BOARD_NAME "Pimoroni Pico dv Base" #define MICROPY_HW_MCU_NAME "rp2040" #define MICROPY_HW_LED_STATUS (&pin_GPIO25) diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.mk b/ports/raspberrypi/boards/pimoroni_pico_dv_base/mpconfigboard.mk similarity index 51% rename from ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.mk rename to ports/raspberrypi/boards/pimoroni_pico_dv_base/mpconfigboard.mk index f78d88add3..8546a32c93 100644 --- a/ports/raspberrypi/boards/pimoroni_pico_dv/mpconfigboard.mk +++ b/ports/raspberrypi/boards/pimoroni_pico_dv_base/mpconfigboard.mk @@ -1,7 +1,7 @@ -USB_VID = 0x239A -USB_PID = 0x80F4 -USB_PRODUCT = "Pimoroni PICO dv" -USB_MANUFACTURER = "Raspberry Pi" +USB_VID = 0x2E8A +USB_PID = 0x1059 +USB_PRODUCT = "Pimoroni Pico DV Demo Base for Pico" +USB_MANUFACTURER = "Pimoroni" CHIP_VARIANT = RP2040 CHIP_FAMILY = rp2 diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv/pico-sdk-configboard.h b/ports/raspberrypi/boards/pimoroni_pico_dv_base/pico-sdk-configboard.h similarity index 100% rename from ports/raspberrypi/boards/pimoroni_pico_dv/pico-sdk-configboard.h rename to ports/raspberrypi/boards/pimoroni_pico_dv_base/pico-sdk-configboard.h diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv/pins.c b/ports/raspberrypi/boards/pimoroni_pico_dv_base/pins.c similarity index 100% rename from ports/raspberrypi/boards/pimoroni_pico_dv/pins.c rename to ports/raspberrypi/boards/pimoroni_pico_dv_base/pins.c diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/board.c b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/board.c new file mode 100644 index 0000000000..bc5878bf24 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/board.c @@ -0,0 +1,52 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" + +#include "bindings/picodvi/Framebuffer.h" +#include "shared-module/displayio/__init__.h" +#include "shared-bindings/framebufferio/FramebufferDisplay.h" + +void board_init(void) { + picodvi_framebuffer_obj_t *fb = &allocate_display_bus()->picodvi; + fb->base.type = &picodvi_framebuffer_type; + common_hal_picodvi_framebuffer_construct(fb, 640, 480, + &pin_GPIO7, &pin_GPIO6, + &pin_GPIO9, &pin_GPIO8, + &pin_GPIO11, &pin_GPIO10, + &pin_GPIO13, &pin_GPIO12, + 8); + + framebufferio_framebufferdisplay_obj_t *display = &displays[0].framebuffer_display; + display->base.type = &framebufferio_framebufferdisplay_type; + common_hal_framebufferio_framebufferdisplay_construct( + display, + MP_OBJ_FROM_PTR(fb), + 0, + true); +} + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/link.ld b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/link.ld new file mode 100644 index 0000000000..e814bead4c --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/link.ld @@ -0,0 +1 @@ +firmware_size = 1532k; diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.h b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.h new file mode 100644 index 0000000000..df6539734e --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.h @@ -0,0 +1,10 @@ +#define MICROPY_HW_BOARD_NAME "Pimoroni Pico DV Base W" +#define MICROPY_HW_MCU_NAME "rp2040" + +#define CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL (1) +#define CIRCUITPY_DIGITALIO_HAVE_INVALID_DRIVE_MODE (1) + +#define MICROPY_HW_LED_STATUS (&pin_CYW0) + +#define DEFAULT_UART_BUS_RX (&pin_GPIO1) +#define DEFAULT_UART_BUS_TX (&pin_GPIO0) diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.mk b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.mk new file mode 100644 index 0000000000..cf37a7e401 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.mk @@ -0,0 +1,26 @@ +USB_VID = 0x2E8A +USB_PID = 0x105A +USB_PRODUCT = "Pimoroni Pico DV Demo Base for Pico W" +USB_MANUFACTURER = "Pimoroni" + +CHIP_VARIANT = RP2040 +CHIP_FAMILY = rp2 + +EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ" + +CIRCUITPY__EVE = 1 + +CIRCUITPY_CYW43 = 1 +CIRCUITPY_SSL = 1 +CIRCUITPY_SSL_MBEDTLS = 1 +CIRCUITPY_HASHLIB = 1 +CIRCUITPY_WEB_WORKFLOW = 1 +CIRCUITPY_MDNS = 1 +CIRCUITPY_SOCKETPOOL = 1 +CIRCUITPY_WIFI = 1 + +CIRCUITPY_PICODVI = 1 + +CFLAGS += -DCYW43_PIN_WL_HOST_WAKE=24 -DCYW43_PIN_WL_REG_ON=23 -DCYW43_WL_GPIO_COUNT=3 -DCYW43_WL_GPIO_LED_PIN=0 +# Must be accompanied by a linker script change +CFLAGS += -DCIRCUITPY_FIRMWARE_SIZE='(1536 * 1024)' diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/pico-sdk-configboard.h b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/pico-sdk-configboard.h new file mode 100644 index 0000000000..a41131dd22 --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/pico-sdk-configboard.h @@ -0,0 +1,4 @@ +// Put board-specific pico-sdk definitions here. This file must exist. + +// Allow extra time for xosc to start. +#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64 diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/pins.c b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/pins.c new file mode 100644 index 0000000000..346a2ae44c --- /dev/null +++ b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/pins.c @@ -0,0 +1,89 @@ +#include "shared-bindings/board/__init__.h" + +#include "shared-module/displayio/__init__.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_GP1), MP_ROM_PTR(&pin_GPIO1) }, + + { MP_ROM_QSTR(MP_QSTR_GP2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_GP3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_GP4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_GP5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_GP6), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_GP7), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_GP8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_GP9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_GP10), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_GP11), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_GP12), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_GP13), MP_ROM_PTR(&pin_GPIO13) }, + + { MP_ROM_QSTR(MP_QSTR_BUTTON_A), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_GP14), MP_ROM_PTR(&pin_GPIO14) }, + + { MP_ROM_QSTR(MP_QSTR_BUTTON_B), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_GP15), MP_ROM_PTR(&pin_GPIO15) }, + + { MP_ROM_QSTR(MP_QSTR_BUTTON_C), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_GP16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_GP17), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_GP18), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_GP19), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_GP20), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_GP21), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_GP22), MP_ROM_PTR(&pin_GPIO22) }, + + // SD Card + { MP_ROM_QSTR(MP_QSTR_SD_SCK), MP_ROM_PTR(&pin_GPIO5)}, + { MP_ROM_QSTR(MP_QSTR_SD_MOSI), MP_ROM_PTR(&pin_GPIO18)}, + { MP_ROM_QSTR(MP_QSTR_SD_MISO), MP_ROM_PTR(&pin_GPIO19)}, + { MP_ROM_QSTR(MP_QSTR_SD_CS), MP_ROM_PTR(&pin_GPIO22)}, + + { MP_ROM_QSTR(MP_QSTR_SMPS_MODE), MP_ROM_PTR(&pin_CYW1) }, + + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_CYW0) }, + + { MP_ROM_QSTR(MP_QSTR_VBUS_SENSE), MP_ROM_PTR(&pin_CYW2) }, + + { MP_ROM_QSTR(MP_QSTR_I2S_WS), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_GP26_A0), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_GP26), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) }, + + { MP_ROM_QSTR(MP_QSTR_I2S_BCLK), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_GP27_A1), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_GP27), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, + + { MP_ROM_QSTR(MP_QSTR_I2S_OUT), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_GP28_A2), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_GP28), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) }, + + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) }, + { MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_GPIO29) }, + + // DVI VIDEO + { MP_ROM_QSTR(MP_QSTR_DV_CEC), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_DV_SCL), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_DV_SDA), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_CKN), MP_ROM_PTR(&pin_GPIO6) }, + { MP_ROM_QSTR(MP_QSTR_CKP), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_D0N), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_D0P), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_D1N), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_D1P), MP_ROM_PTR(&pin_GPIO11) }, + { MP_ROM_QSTR(MP_QSTR_D2N), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_D2P), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_DV_HPD), MP_ROM_PTR(&pin_GPIO17) }, + + { MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].framebuffer_display)}, + +}; + +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); From aba4c50e74af1301e2b5fe1ee5198ddea92879fd Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Wed, 26 Apr 2023 21:08:28 -0400 Subject: [PATCH 091/117] Add adafruit_sdcard as frozen library --- .../raspberrypi/boards/pimoroni_pico_dv_base/mpconfigboard.mk | 3 +++ .../boards/pimoroni_pico_dv_base_w/mpconfigboard.mk | 3 +++ 2 files changed, 6 insertions(+) diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv_base/mpconfigboard.mk b/ports/raspberrypi/boards/pimoroni_pico_dv_base/mpconfigboard.mk index 8546a32c93..d5d90c6b4b 100644 --- a/ports/raspberrypi/boards/pimoroni_pico_dv_base/mpconfigboard.mk +++ b/ports/raspberrypi/boards/pimoroni_pico_dv_base/mpconfigboard.mk @@ -10,3 +10,6 @@ EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ" CIRCUITPY__EVE = 1 CIRCUITPY_PICODVI = 1 + +# Include these Python libraries in firmware. +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_SD \ No newline at end of file diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.mk b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.mk index cf37a7e401..83e0764ab4 100644 --- a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.mk +++ b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.mk @@ -24,3 +24,6 @@ CIRCUITPY_PICODVI = 1 CFLAGS += -DCYW43_PIN_WL_HOST_WAKE=24 -DCYW43_PIN_WL_REG_ON=23 -DCYW43_WL_GPIO_COUNT=3 -DCYW43_WL_GPIO_LED_PIN=0 # Must be accompanied by a linker script change CFLAGS += -DCIRCUITPY_FIRMWARE_SIZE='(1536 * 1024)' + +# Include these Python libraries in firmware. +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_SD \ No newline at end of file From 12f59b494834838db405e1cf8eeb82d2833e509c Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Wed, 26 Apr 2023 21:14:57 -0400 Subject: [PATCH 092/117] pre-commit formatting --- ports/raspberrypi/boards/pimoroni_pico_dv_base/mpconfigboard.mk | 2 +- .../raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.mk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv_base/mpconfigboard.mk b/ports/raspberrypi/boards/pimoroni_pico_dv_base/mpconfigboard.mk index d5d90c6b4b..b383ead573 100644 --- a/ports/raspberrypi/boards/pimoroni_pico_dv_base/mpconfigboard.mk +++ b/ports/raspberrypi/boards/pimoroni_pico_dv_base/mpconfigboard.mk @@ -12,4 +12,4 @@ CIRCUITPY__EVE = 1 CIRCUITPY_PICODVI = 1 # Include these Python libraries in firmware. -FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_SD \ No newline at end of file +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_SD diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.mk b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.mk index 83e0764ab4..b7919a1847 100644 --- a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.mk +++ b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.mk @@ -26,4 +26,4 @@ CFLAGS += -DCYW43_PIN_WL_HOST_WAKE=24 -DCYW43_PIN_WL_REG_ON=23 -DCYW43_WL_GPIO_C CFLAGS += -DCIRCUITPY_FIRMWARE_SIZE='(1536 * 1024)' # Include these Python libraries in firmware. -FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_SD \ No newline at end of file +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_SD From ec6fde91adae9a648863686374bccc1badf0587a Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Thu, 27 Apr 2023 18:14:46 +0200 Subject: [PATCH 093/117] integrate latest changes from upstream --- .../boards/pimoroni_badger2040w/board.c | 13 +- .../boards/pimoroni_badger2040w/link.ld | 295 +----------------- 2 files changed, 7 insertions(+), 301 deletions(-) diff --git a/ports/raspberrypi/boards/pimoroni_badger2040w/board.c b/ports/raspberrypi/boards/pimoroni_badger2040w/board.c index 9eea472925..e54e7edd43 100644 --- a/ports/raspberrypi/boards/pimoroni_badger2040w/board.c +++ b/ports/raspberrypi/boards/pimoroni_badger2040w/board.c @@ -31,6 +31,7 @@ #include "shared-bindings/displayio/FourWire.h" #include "shared-bindings/microcontroller/Pin.h" #include "shared-module/displayio/__init__.h" +#include "shared-bindings/board/__init__.h" #include "supervisor/shared/board.h" #include "badger-shared.h" @@ -274,12 +275,11 @@ void board_init(void) { common_hal_digitalio_digitalinout_never_reset(&enable_pin_obj); // Set up the SPI object used to control the display - busio_spi_obj_t *spi = &displays[0].fourwire_bus.inline_bus; - common_hal_busio_spi_construct(spi, &pin_GPIO18, &pin_GPIO19, &pin_GPIO16, false); + busio_spi_obj_t *spi = common_hal_board_create_spi(0); common_hal_busio_spi_never_reset(spi); // Set up the DisplayIO pin object - displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus; + displayio_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus; bus->base.type = &displayio_fourwire_type; common_hal_displayio_fourwire_construct(bus, spi, @@ -291,7 +291,7 @@ void board_init(void) { 0); // Phase // Set up the DisplayIO epaper object - displayio_epaperdisplay_obj_t *display = &displays[0].epaper_display; + displayio_epaperdisplay_obj_t *display = &allocate_display()->epaper_display; display->base.type = &displayio_epaperdisplay_type; common_hal_displayio_epaperdisplay_construct( display, @@ -323,16 +323,15 @@ void board_init(void) { false, // always_toggle_chip_select false, // grayscale false, // acep - false); // two_byte_sequence_length + false, // two_byte_sequence_length + false); // address_little_endian } void board_deinit(void) { displayio_epaperdisplay_obj_t *display = &displays[0].epaper_display; if (display->base.type == &displayio_epaperdisplay_type) { - size_t i = 0; while (common_hal_displayio_epaperdisplay_get_busy(display)) { RUN_BACKGROUND_TASKS; - i++; } } common_hal_displayio_release_displays(); diff --git a/ports/raspberrypi/boards/pimoroni_badger2040w/link.ld b/ports/raspberrypi/boards/pimoroni_badger2040w/link.ld index 2777b41720..e814bead4c 100644 --- a/ports/raspberrypi/boards/pimoroni_badger2040w/link.ld +++ b/ports/raspberrypi/boards/pimoroni_badger2040w/link.ld @@ -1,294 +1 @@ -/* Based on GCC ARM embedded samples. - Defines the following symbols for use by code: - __exidx_start - __exidx_end - __etext - __data_start__ - __preinit_array_start - __preinit_array_end - __init_array_start - __init_array_end - __fini_array_start - __fini_array_end - __data_end__ - __bss_start__ - __bss_end__ - __end__ - end - __HeapLimit - __StackLimit - __StackTop - __stack (== StackTop) -*/ - -MEMORY -{ - FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 1532k - /* Followed by: 4kB of NVRAM and at least 512kB of CIRCUITPY */ - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k - SCRATCH_X (rwx) : ORIGIN = 0x20040000, LENGTH = 4k - SCRATCH_Y (rwx) : ORIGIN = 0x20041000, LENGTH = 4k -} - -ENTRY(_entry_point) - -SECTIONS -{ - /* Second stage bootloader is prepended to the image. It must be 256 bytes big - and checksummed. It is usually built by the boot_stage2 target - in the Pico SDK - */ - - .flash_begin : { - __flash_binary_start = .; - } > FLASH_FIRMWARE - - .boot2 : { - __boot2_start__ = .; - KEEP (*(.boot2)) - __boot2_end__ = .; - } > FLASH_FIRMWARE - - ASSERT(__boot2_end__ - __boot2_start__ == 256, - "ERROR: Pico second stage bootloader must be 256 bytes in size") - - /* The second stage will always enter the image at the start of .text. - The debugger will use the ELF entry point, which is the _entry_point - symbol if present, otherwise defaults to start of .text. - This can be used to transfer control back to the bootrom on debugger - launches only, to perform proper flash setup. - */ - - .text : { - __logical_binary_start = .; - KEEP (*(.vectors)) - KEEP (*(.binary_info_header)) - __binary_info_header_end = .; - KEEP (*(.reset)) - /* TODO revisit this now memset/memcpy/float in ROM */ - /* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from - * FLASH ... we will include any thing excluded here in .data below by default */ - *(.init) - - __property_getter_start = .; - *(.property_getter) - __property_getter_end = .; - __property_getset_start = .; - *(.property_getset) - __property_getset_end = .; - - *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*) - *(.fini) - /* Pull all c'tors into .text */ - *crtbegin.o(.ctors) - *crtbegin?.o(.ctors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) - *(SORT(.ctors.*)) - *(.ctors) - /* Followed by destructors */ - *crtbegin.o(.dtors) - *crtbegin?.o(.dtors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) - *(SORT(.dtors.*)) - *(.dtors) - - *(.eh_frame*) - . = ALIGN(4); - } > FLASH_FIRMWARE - - .rodata : { - *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*) - . = ALIGN(4); - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) - . = ALIGN(4); - } > FLASH_FIRMWARE - - .ARM.extab : - { - *(.ARM.extab* .gnu.linkonce.armextab.*) - } > FLASH_FIRMWARE - - __exidx_start = .; - .ARM.exidx : - { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > FLASH_FIRMWARE - __exidx_end = .; - - /* Machine inspectable binary information */ - . = ALIGN(4); - __binary_info_start = .; - .binary_info : - { - KEEP(*(.binary_info.keep.*)) - *(.binary_info.*) - } > FLASH_FIRMWARE - __binary_info_end = .; - . = ALIGN(4); - - /* End of .text-like segments */ - __etext = .; - - .ram_vector_table (COPY): { - *(.ram_vector_table) - } > RAM - - .data : { - __data_start__ = .; - *(vtable) - - *(.time_critical*) - - /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */ - *(.text*) - . = ALIGN(4); - *(.rodata*) - . = ALIGN(4); - - *(.data*) - - . = ALIGN(4); - *(.after_data.*) - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__mutex_array_start = .); - KEEP(*(SORT(.mutex_array.*))) - KEEP(*(.mutex_array)) - PROVIDE_HIDDEN (__mutex_array_end = .); - - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - - . = ALIGN(4); - /* init data */ - PROVIDE_HIDDEN (__init_array_start = .); - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - - . = ALIGN(4); - /* finit data */ - PROVIDE_HIDDEN (__fini_array_start = .); - *(SORT(.fini_array.*)) - *(.fini_array) - PROVIDE_HIDDEN (__fini_array_end = .); - - *(.jcr) - . = ALIGN(4); - /* All data end */ - __data_end__ = .; - } > RAM AT> FLASH_FIRMWARE - - .itcm : - { - . = ALIGN(4); - *(.itcm.*) - - . = ALIGN(4); - } > RAM AT> FLASH_FIRMWARE - _ld_itcm_destination = ADDR(.itcm); - _ld_itcm_flash_copy = LOADADDR(.itcm); - _ld_itcm_size = SIZEOF(.itcm); - - .dtcm_data : - { - . = ALIGN(4); - - *(.dtcm_data.*) - - . = ALIGN(4); - } > RAM AT> FLASH_FIRMWARE - _ld_dtcm_data_destination = ADDR(.dtcm_data); - _ld_dtcm_data_flash_copy = LOADADDR(.dtcm_data); - _ld_dtcm_data_size = SIZEOF(.dtcm_data); - - .dtcm_bss : - { - . = ALIGN(4); - - *(.dtcm_bss.*) - - . = ALIGN(4); - } > RAM AT> RAM - _ld_dtcm_bss_start = ADDR(.dtcm_bss); - _ld_dtcm_bss_size = SIZEOF(.dtcm_bss); - - .uninitialized_data (COPY): { - . = ALIGN(4); - *(.uninitialized_data*) - } > RAM - - /* Start and end symbols must be word-aligned */ - .scratch_x : { - __scratch_x_start__ = .; - *(.scratch_x.*) - . = ALIGN(4); - __scratch_x_end__ = .; - } > SCRATCH_X AT > FLASH_FIRMWARE - __scratch_x_source__ = LOADADDR(.scratch_x); - - .scratch_y : { - __scratch_y_start__ = .; - *(.scratch_y.*) - . = ALIGN(4); - __scratch_y_end__ = .; - } > SCRATCH_Y AT > FLASH_FIRMWARE - __scratch_y_source__ = LOADADDR(.scratch_y); - - .bss : { - . = ALIGN(4); - __bss_start__ = .; - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) - *(COMMON) - . = ALIGN(4); - __bss_end__ = .; - } > RAM - - .heap (COPY): - { - __end__ = .; - end = __end__; - *(.heap*) - __HeapLimit = .; - } > RAM - - /* .stack*_dummy section doesn't contains any symbols. It is only - * used for linker to calculate size of stack sections, and assign - * values to stack symbols later - * - * stack1 section may be empty/missing if platform_launch_core1 is not used */ - - /* by default we put core 0 stack at the end of scratch Y, so that if core 1 - * stack is not used then all of SCRATCH_X is free. - */ - .stack1_dummy (COPY): - { - *(.stack1*) - } > SCRATCH_X - .stack_dummy (COPY): - { - *(.stack*) - } > SCRATCH_Y - - .flash_end : { - __flash_binary_end = .; - } > FLASH_FIRMWARE - - /* stack limit is poorly named, but historically is maximum heap ptr */ - __StackLimit = ORIGIN(RAM) + LENGTH(RAM); - __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); - __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); - __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); - __StackBottom = __StackTop - SIZEOF(.stack_dummy); - PROVIDE(__stack = __StackTop); - - /* Check if data + heap + stack exceeds RAM limit */ - ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") - - ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary") - /* todo assert on extra code */ -} +firmware_size = 1532k; From 4f8ae14c18e15ffc6bc0a33fd3151fff193c9829 Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Fri, 28 Apr 2023 08:56:52 +0200 Subject: [PATCH 094/117] update to upstream version --- .../boards/pimoroni_plasma2040w/link.ld | 295 +----------------- 1 file changed, 1 insertion(+), 294 deletions(-) diff --git a/ports/raspberrypi/boards/pimoroni_plasma2040w/link.ld b/ports/raspberrypi/boards/pimoroni_plasma2040w/link.ld index 2777b41720..e814bead4c 100644 --- a/ports/raspberrypi/boards/pimoroni_plasma2040w/link.ld +++ b/ports/raspberrypi/boards/pimoroni_plasma2040w/link.ld @@ -1,294 +1 @@ -/* Based on GCC ARM embedded samples. - Defines the following symbols for use by code: - __exidx_start - __exidx_end - __etext - __data_start__ - __preinit_array_start - __preinit_array_end - __init_array_start - __init_array_end - __fini_array_start - __fini_array_end - __data_end__ - __bss_start__ - __bss_end__ - __end__ - end - __HeapLimit - __StackLimit - __StackTop - __stack (== StackTop) -*/ - -MEMORY -{ - FLASH_FIRMWARE (rx) : ORIGIN = 0x10000000, LENGTH = 1532k - /* Followed by: 4kB of NVRAM and at least 512kB of CIRCUITPY */ - RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256k - SCRATCH_X (rwx) : ORIGIN = 0x20040000, LENGTH = 4k - SCRATCH_Y (rwx) : ORIGIN = 0x20041000, LENGTH = 4k -} - -ENTRY(_entry_point) - -SECTIONS -{ - /* Second stage bootloader is prepended to the image. It must be 256 bytes big - and checksummed. It is usually built by the boot_stage2 target - in the Pico SDK - */ - - .flash_begin : { - __flash_binary_start = .; - } > FLASH_FIRMWARE - - .boot2 : { - __boot2_start__ = .; - KEEP (*(.boot2)) - __boot2_end__ = .; - } > FLASH_FIRMWARE - - ASSERT(__boot2_end__ - __boot2_start__ == 256, - "ERROR: Pico second stage bootloader must be 256 bytes in size") - - /* The second stage will always enter the image at the start of .text. - The debugger will use the ELF entry point, which is the _entry_point - symbol if present, otherwise defaults to start of .text. - This can be used to transfer control back to the bootrom on debugger - launches only, to perform proper flash setup. - */ - - .text : { - __logical_binary_start = .; - KEEP (*(.vectors)) - KEEP (*(.binary_info_header)) - __binary_info_header_end = .; - KEEP (*(.reset)) - /* TODO revisit this now memset/memcpy/float in ROM */ - /* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from - * FLASH ... we will include any thing excluded here in .data below by default */ - *(.init) - - __property_getter_start = .; - *(.property_getter) - __property_getter_end = .; - __property_getset_start = .; - *(.property_getset) - __property_getset_end = .; - - *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*) - *(.fini) - /* Pull all c'tors into .text */ - *crtbegin.o(.ctors) - *crtbegin?.o(.ctors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) - *(SORT(.ctors.*)) - *(.ctors) - /* Followed by destructors */ - *crtbegin.o(.dtors) - *crtbegin?.o(.dtors) - *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) - *(SORT(.dtors.*)) - *(.dtors) - - *(.eh_frame*) - . = ALIGN(4); - } > FLASH_FIRMWARE - - .rodata : { - *(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .rodata*) - . = ALIGN(4); - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.flashdata*))) - . = ALIGN(4); - } > FLASH_FIRMWARE - - .ARM.extab : - { - *(.ARM.extab* .gnu.linkonce.armextab.*) - } > FLASH_FIRMWARE - - __exidx_start = .; - .ARM.exidx : - { - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - } > FLASH_FIRMWARE - __exidx_end = .; - - /* Machine inspectable binary information */ - . = ALIGN(4); - __binary_info_start = .; - .binary_info : - { - KEEP(*(.binary_info.keep.*)) - *(.binary_info.*) - } > FLASH_FIRMWARE - __binary_info_end = .; - . = ALIGN(4); - - /* End of .text-like segments */ - __etext = .; - - .ram_vector_table (COPY): { - *(.ram_vector_table) - } > RAM - - .data : { - __data_start__ = .; - *(vtable) - - *(.time_critical*) - - /* remaining .text and .rodata; i.e. stuff we exclude above because we want it in RAM */ - *(.text*) - . = ALIGN(4); - *(.rodata*) - . = ALIGN(4); - - *(.data*) - - . = ALIGN(4); - *(.after_data.*) - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__mutex_array_start = .); - KEEP(*(SORT(.mutex_array.*))) - KEEP(*(.mutex_array)) - PROVIDE_HIDDEN (__mutex_array_end = .); - - . = ALIGN(4); - /* preinit data */ - PROVIDE_HIDDEN (__preinit_array_start = .); - KEEP(*(SORT(.preinit_array.*))) - KEEP(*(.preinit_array)) - PROVIDE_HIDDEN (__preinit_array_end = .); - - . = ALIGN(4); - /* init data */ - PROVIDE_HIDDEN (__init_array_start = .); - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - PROVIDE_HIDDEN (__init_array_end = .); - - . = ALIGN(4); - /* finit data */ - PROVIDE_HIDDEN (__fini_array_start = .); - *(SORT(.fini_array.*)) - *(.fini_array) - PROVIDE_HIDDEN (__fini_array_end = .); - - *(.jcr) - . = ALIGN(4); - /* All data end */ - __data_end__ = .; - } > RAM AT> FLASH_FIRMWARE - - .itcm : - { - . = ALIGN(4); - *(.itcm.*) - - . = ALIGN(4); - } > RAM AT> FLASH_FIRMWARE - _ld_itcm_destination = ADDR(.itcm); - _ld_itcm_flash_copy = LOADADDR(.itcm); - _ld_itcm_size = SIZEOF(.itcm); - - .dtcm_data : - { - . = ALIGN(4); - - *(.dtcm_data.*) - - . = ALIGN(4); - } > RAM AT> FLASH_FIRMWARE - _ld_dtcm_data_destination = ADDR(.dtcm_data); - _ld_dtcm_data_flash_copy = LOADADDR(.dtcm_data); - _ld_dtcm_data_size = SIZEOF(.dtcm_data); - - .dtcm_bss : - { - . = ALIGN(4); - - *(.dtcm_bss.*) - - . = ALIGN(4); - } > RAM AT> RAM - _ld_dtcm_bss_start = ADDR(.dtcm_bss); - _ld_dtcm_bss_size = SIZEOF(.dtcm_bss); - - .uninitialized_data (COPY): { - . = ALIGN(4); - *(.uninitialized_data*) - } > RAM - - /* Start and end symbols must be word-aligned */ - .scratch_x : { - __scratch_x_start__ = .; - *(.scratch_x.*) - . = ALIGN(4); - __scratch_x_end__ = .; - } > SCRATCH_X AT > FLASH_FIRMWARE - __scratch_x_source__ = LOADADDR(.scratch_x); - - .scratch_y : { - __scratch_y_start__ = .; - *(.scratch_y.*) - . = ALIGN(4); - __scratch_y_end__ = .; - } > SCRATCH_Y AT > FLASH_FIRMWARE - __scratch_y_source__ = LOADADDR(.scratch_y); - - .bss : { - . = ALIGN(4); - __bss_start__ = .; - *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.bss*))) - *(COMMON) - . = ALIGN(4); - __bss_end__ = .; - } > RAM - - .heap (COPY): - { - __end__ = .; - end = __end__; - *(.heap*) - __HeapLimit = .; - } > RAM - - /* .stack*_dummy section doesn't contains any symbols. It is only - * used for linker to calculate size of stack sections, and assign - * values to stack symbols later - * - * stack1 section may be empty/missing if platform_launch_core1 is not used */ - - /* by default we put core 0 stack at the end of scratch Y, so that if core 1 - * stack is not used then all of SCRATCH_X is free. - */ - .stack1_dummy (COPY): - { - *(.stack1*) - } > SCRATCH_X - .stack_dummy (COPY): - { - *(.stack*) - } > SCRATCH_Y - - .flash_end : { - __flash_binary_end = .; - } > FLASH_FIRMWARE - - /* stack limit is poorly named, but historically is maximum heap ptr */ - __StackLimit = ORIGIN(RAM) + LENGTH(RAM); - __StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X); - __StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y); - __StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy); - __StackBottom = __StackTop - SIZEOF(.stack_dummy); - PROVIDE(__stack = __StackTop); - - /* Check if data + heap + stack exceeds RAM limit */ - ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed") - - ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary") - /* todo assert on extra code */ -} +firmware_size = 1532k; From 14c17224a1a0d4dc82262b8a72cba6b8e1f9999a Mon Sep 17 00:00:00 2001 From: Bernhard Bablok Date: Fri, 28 Apr 2023 08:57:22 +0200 Subject: [PATCH 095/117] update product-id --- ports/raspberrypi/boards/pimoroni_plasma2040w/mpconfigboard.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/raspberrypi/boards/pimoroni_plasma2040w/mpconfigboard.mk b/ports/raspberrypi/boards/pimoroni_plasma2040w/mpconfigboard.mk index 68fec260ed..4b5faf6efb 100644 --- a/ports/raspberrypi/boards/pimoroni_plasma2040w/mpconfigboard.mk +++ b/ports/raspberrypi/boards/pimoroni_plasma2040w/mpconfigboard.mk @@ -1,5 +1,5 @@ USB_VID = 0x2E8A -USB_PID = 0x100a +USB_PID = 0x1058 USB_PRODUCT = "Plasma 2040 W" USB_MANUFACTURER = "Pimoroni" From a9dc31a88198e5f09d46799870a921b92470b120 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 23 Mar 2023 16:11:00 -0700 Subject: [PATCH 096/117] Add additional iMX RT support This adds a script to generate the peripherals files (except clock). It adds support for the 1015, 1020, 1040, and 1050 EVKs. Some work was started on 1176 but it isn't working. So, the board def is in a separate branch. Fixes #3521. Fixes #2477. --- lib/tinyusb | 2 +- ports/mimxrt10xx/Makefile | 42 +- ports/mimxrt10xx/boards/board.h | 1 + ports/mimxrt10xx/boards/imxrt1010_evk/board.c | 4 +- .../boards/imxrt1010_evk/flash_config.c | 2 +- .../boards/imxrt1010_evk/mpconfigboard.h | 4 +- ports/mimxrt10xx/boards/imxrt1015_evk/board.c | 49 ++ .../boards/imxrt1015_evk/flash_config.c | 143 ++++ .../boards/imxrt1015_evk/mpconfigboard.h | 24 + .../boards/imxrt1015_evk/mpconfigboard.mk | 8 + ports/mimxrt10xx/boards/imxrt1015_evk/pins.c | 76 ++ ports/mimxrt10xx/boards/imxrt1020_evk/board.c | 4 +- .../boards/imxrt1020_evk/flash_config.c | 2 +- ports/mimxrt10xx/boards/imxrt1040_evk/board.c | 53 ++ .../boards/imxrt1040_evk/flash_config.c | 144 ++++ .../boards/imxrt1040_evk/mpconfigboard.h | 22 + .../boards/imxrt1040_evk/mpconfigboard.mk | 8 + ports/mimxrt10xx/boards/imxrt1040_evk/pins.c | 123 ++++ .../mimxrt10xx/boards/imxrt1050_evkb/board.c | 53 ++ .../boards/imxrt1050_evkb/flash_config.c | 144 ++++ .../boards/imxrt1050_evkb/mpconfigboard.h | 27 + .../boards/imxrt1050_evkb/mpconfigboard.mk | 10 + ports/mimxrt10xx/boards/imxrt1050_evkb/pins.c | 142 ++++ .../boards/metro_m7_1011/flash_config.c | 6 +- .../mimxrt10xx/common-hal/audiobusio/I2SOut.c | 6 +- ports/mimxrt10xx/common-hal/busio/I2C.c | 30 +- ports/mimxrt10xx/common-hal/busio/SPI.c | 58 +- ports/mimxrt10xx/common-hal/busio/UART.c | 30 +- .../common-hal/digitalio/DigitalInOut.c | 10 +- .../common-hal/microcontroller/Processor.c | 10 + .../common-hal/microcontroller/__init__.c | 190 +---- ports/mimxrt10xx/common-hal/os/__init__.c | 6 + .../linking/chip_family/MIMXRT1011.ld | 4 +- .../linking/chip_family/MIMXRT1015.ld | 4 + .../linking/chip_family/MIMXRT1021.ld | 4 +- .../linking/chip_family/MIMXRT1042.ld | 4 + .../linking/chip_family/MIMXRT1052.ld | 4 + .../linking/chip_family/MIMXRT1062.ld | 4 +- .../linking/chip_family/MIMXRT1176.ld | 4 + ports/mimxrt10xx/linking/common.ld | 14 +- ports/mimxrt10xx/linking/flash/IS25WP128.ld | 1 + ports/mimxrt10xx/mpconfigport.mk | 6 +- .../mimxrt10xx/MIMXRT1011/clocks.c | 2 + .../mimxrt10xx/MIMXRT1011/periph.c | 98 +-- .../mimxrt10xx/MIMXRT1011/periph.h | 29 +- .../mimxrt10xx/MIMXRT1011/pin_names.h | 78 ++ .../peripherals/mimxrt10xx/MIMXRT1011/pins.c | 88 +-- .../peripherals/mimxrt10xx/MIMXRT1011/pins.h | 59 +- .../mimxrt10xx/MIMXRT1015/clocks.c | 315 ++++++++ .../mimxrt10xx/MIMXRT1015/periph.c | 184 +++++ .../mimxrt10xx/MIMXRT1015/periph.h | 55 ++ .../mimxrt10xx/MIMXRT1015/pin_names.h | 92 +++ .../peripherals/mimxrt10xx/MIMXRT1015/pins.c | 91 +++ .../peripherals/mimxrt10xx/MIMXRT1015/pins.h | 36 + .../mimxrt10xx/MIMXRT1021/clocks.c | 2 + .../mimxrt10xx/MIMXRT1021/periph.c | 232 +++--- .../mimxrt10xx/MIMXRT1021/periph.h | 27 +- .../mimxrt10xx/MIMXRT1021/pin_names.h | 130 ++++ .../peripherals/mimxrt10xx/MIMXRT1021/pins.c | 68 +- .../peripherals/mimxrt10xx/MIMXRT1021/pins.h | 111 +-- .../mimxrt10xx/MIMXRT1042/clocks.c | 382 ++++++++++ .../mimxrt10xx/MIMXRT1042/periph.c | 356 ++++++++++ .../mimxrt10xx/MIMXRT1042/periph.h | 55 ++ .../mimxrt10xx/MIMXRT1042/pin_names.h | 151 ++++ .../peripherals/mimxrt10xx/MIMXRT1042/pins.c | 147 ++++ .../peripherals/mimxrt10xx/MIMXRT1042/pins.h | 36 + .../mimxrt10xx/MIMXRT1052/clocks.c | 402 +++++++++++ .../mimxrt10xx/MIMXRT1052/periph.c | 377 ++++++++++ .../mimxrt10xx/MIMXRT1052/periph.h | 55 ++ .../mimxrt10xx/MIMXRT1052/pin_names.h | 165 +++++ .../peripherals/mimxrt10xx/MIMXRT1052/pins.c | 161 +++++ .../peripherals/mimxrt10xx/MIMXRT1052/pins.h | 36 + .../mimxrt10xx/MIMXRT1062/periph.c | 178 ++--- .../mimxrt10xx/MIMXRT1062/periph.h | 29 +- .../mimxrt10xx/MIMXRT1062/pin_names.h | 165 +++++ .../peripherals/mimxrt10xx/MIMXRT1062/pins.c | 27 +- .../peripherals/mimxrt10xx/MIMXRT1062/pins.h | 148 +--- .../mimxrt10xx/MIMXRT1176/clocks.c | 672 ++++++++++++++++++ .../mimxrt10xx/MIMXRT1176/periph.c | 358 ++++++++++ .../mimxrt10xx/MIMXRT1176/periph.h | 55 ++ .../mimxrt10xx/MIMXRT1176/pin_names.h | 182 +++++ .../peripherals/mimxrt10xx/MIMXRT1176/pins.c | 177 +++++ .../peripherals/mimxrt10xx/MIMXRT1176/pins.h | 36 + .../peripherals/mimxrt10xx/periph.h | 8 + .../peripherals/mimxrt10xx/pin_names.h | 42 ++ .../mimxrt10xx/peripherals/mimxrt10xx/pins.h | 8 + ports/mimxrt10xx/sdk | 2 +- .../supervisor/flexspi_nor_flash_ops.c | 2 +- ports/mimxrt10xx/supervisor/internal_flash.c | 40 ++ ports/mimxrt10xx/supervisor/port.c | 113 ++- ports/mimxrt10xx/supervisor/usb.c | 5 + .../mimxrt10xx/tools/gen_peripherals_data.py | 356 ++++++++++ py/stackctrl.c | 3 + supervisor/linker.h | 2 +- tools/cortex-m-fault-gdb.py | 7 + 95 files changed, 7148 insertions(+), 969 deletions(-) create mode 100644 ports/mimxrt10xx/boards/imxrt1015_evk/board.c create mode 100644 ports/mimxrt10xx/boards/imxrt1015_evk/flash_config.c create mode 100644 ports/mimxrt10xx/boards/imxrt1015_evk/mpconfigboard.h create mode 100644 ports/mimxrt10xx/boards/imxrt1015_evk/mpconfigboard.mk create mode 100644 ports/mimxrt10xx/boards/imxrt1015_evk/pins.c create mode 100644 ports/mimxrt10xx/boards/imxrt1040_evk/board.c create mode 100644 ports/mimxrt10xx/boards/imxrt1040_evk/flash_config.c create mode 100644 ports/mimxrt10xx/boards/imxrt1040_evk/mpconfigboard.h create mode 100644 ports/mimxrt10xx/boards/imxrt1040_evk/mpconfigboard.mk create mode 100644 ports/mimxrt10xx/boards/imxrt1040_evk/pins.c create mode 100644 ports/mimxrt10xx/boards/imxrt1050_evkb/board.c create mode 100644 ports/mimxrt10xx/boards/imxrt1050_evkb/flash_config.c create mode 100644 ports/mimxrt10xx/boards/imxrt1050_evkb/mpconfigboard.h create mode 100644 ports/mimxrt10xx/boards/imxrt1050_evkb/mpconfigboard.mk create mode 100644 ports/mimxrt10xx/boards/imxrt1050_evkb/pins.c create mode 100644 ports/mimxrt10xx/linking/chip_family/MIMXRT1015.ld create mode 100644 ports/mimxrt10xx/linking/chip_family/MIMXRT1042.ld create mode 100644 ports/mimxrt10xx/linking/chip_family/MIMXRT1052.ld create mode 100644 ports/mimxrt10xx/linking/chip_family/MIMXRT1176.ld create mode 100644 ports/mimxrt10xx/linking/flash/IS25WP128.ld create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pin_names.h create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/clocks.c create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.c create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.h create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pin_names.h create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pins.c create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pins.h create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pin_names.h create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/clocks.c create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.c create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.h create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pin_names.h create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pins.c create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pins.h create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/clocks.c create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.c create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.h create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pin_names.h create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pins.c create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pins.h create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pin_names.h create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/clocks.c create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.c create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.h create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pin_names.h create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pins.c create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pins.h create mode 100644 ports/mimxrt10xx/peripherals/mimxrt10xx/pin_names.h create mode 100644 ports/mimxrt10xx/tools/gen_peripherals_data.py diff --git a/lib/tinyusb b/lib/tinyusb index ec9c666107..e3b3229d61 160000 --- a/lib/tinyusb +++ b/lib/tinyusb @@ -1 +1 @@ -Subproject commit ec9c666107c0be0f8dc7c2a15e3bdea8c44a50b4 +Subproject commit e3b3229d61676585879c81d5f2e3393a2a1f1b16 diff --git a/ports/mimxrt10xx/Makefile b/ports/mimxrt10xx/Makefile index 72f4d191ef..b10466bb2d 100644 --- a/ports/mimxrt10xx/Makefile +++ b/ports/mimxrt10xx/Makefile @@ -34,10 +34,11 @@ INC += \ -I../../lib/tinyusb/src \ -I../../supervisor/shared/usb \ -I$(BUILD) \ - -Iboards/ \ + -Iboards \ -Iboards/$(BOARD) \ -Iperipherals/ \ -Iperipherals/mimxrt10xx/ \ + -Isdk/CMSIS/Include/ \ -Isdk/devices/$(CHIP_FAMILY) \ -Isdk/devices/$(CHIP_FAMILY)/drivers \ -Isdk/drivers/common @@ -48,7 +49,7 @@ CFLAGS += -ftree-vrp -DNDEBUG # TinyUSB defines CFLAGS += -DCFG_TUSB_MCU=OPT_MCU_MIMXRT10XX -DCFG_TUD_CDC_RX_BUFSIZE=512 -DCFG_TUD_CDC_TX_BUFSIZE=512 -ifeq ($(CHIP_FAMILY), MIMXRT1011) +ifeq ($(CHIP_FAMILY),$(filter $(CHIP_FAMILY),MIMXRT1011 MIMXRT1015)) CFLAGS += -DCFG_TUD_MIDI_RX_BUFSIZE=64 -DCFG_TUD_MIDI_TX_BUFSIZE=64 -DCFG_TUD_MSC_BUFSIZE=512 else CFLAGS += -DCFG_TUD_MIDI_RX_BUFSIZE=512 -DCFG_TUD_MIDI_TX_BUFSIZE=512 -DCFG_TUD_MSC_BUFSIZE=1024 @@ -75,7 +76,7 @@ CFLAGS += \ -mfloat-abi=hard \ -mfpu=fpv5-sp-d16 \ -DCPU_$(CHIP_VARIANT) \ - -DIMXRT10XX \ + -DIMXRT1XXX \ -g3 -Wno-unused-parameter \ -ffunction-sections -fdata-sections -fstack-usage @@ -100,14 +101,27 @@ ifndef INTERNAL_LIBM LIBS += -lm endif -LDFLAGS += -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -mthumb -mapcs +ifndef CHIP_CORE +CHIP_CORE = $(CHIP_FAMILY) +endif + +# If not empty, then it is 10xx. +ifneq ($(findstring MIMXRT10, $(CHIP_FAMILY)),) +CFLAGS += -DIMXRT10XX=1 -DIMXRT11XX=0 +MIMXRT10xx = $(CHIP_FAMILY) BOOTLOADER_SIZE := 0x6000C000 +else +CFLAGS += -DIMXRT11XX=1 -DIMXRT10XX=0 +MIMXRT11xx = $(CHIP_FAMILY) +BOOTLOADER_SIZE := 0x3000C000 +endif + +LDFLAGS += -mcpu=cortex-m7 -mfloat-abi=hard -mfpu=fpv5-sp-d16 -mthumb -mapcs SRC_SDK := \ devices/$(CHIP_FAMILY)/drivers/fsl_clock.c \ - devices/$(CHIP_FAMILY)/system_$(CHIP_FAMILY).c \ + devices/$(CHIP_FAMILY)/system_$(CHIP_CORE).c \ devices/$(CHIP_FAMILY)/xip/fsl_flexspi_nor_boot.c \ - drivers/adc_12b1msps_sar/fsl_adc.c \ drivers/cache/armv7-m7/fsl_cache.c \ drivers/common/fsl_common_arm.c \ drivers/common/fsl_common.c \ @@ -121,11 +135,23 @@ SRC_SDK := \ drivers/sai/fsl_sai.c \ drivers/snvs_hp/fsl_snvs_hp.c \ drivers/snvs_lp/fsl_snvs_lp.c \ - drivers/tempmon/fsl_tempmon.c \ drivers/trng/fsl_trng.c \ +ifeq ($(CIRCUITPY_ANALOGIO), 1) +SRC_SDK += drivers/adc_12b1msps_sar/fsl_adc.c \ + drivers/tempmon/fsl_tempmon.c +endif + +ifeq ($(CHIP_FAMILY), MIMXRT1176) +SRC_SDK += devices/$(CHIP_FAMILY)/drivers/fsl_anatop_ai.c \ + devices/$(CHIP_FAMILY)/drivers/fsl_dcdc.c \ + devices/$(CHIP_FAMILY)/drivers/fsl_pmu.c +endif + SRC_SDK := $(addprefix sdk/, $(SRC_SDK)) +$(addprefix $(BUILD)/, $(SRC_SDK:.c=.o)): CFLAGS += -Wno-array-bounds + SRC_C += \ background.c \ boards/$(BOARD)/board.c \ @@ -156,7 +182,7 @@ SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) $(addprefix shared-module/, $(SRC_SHARED_MODULE_INTERNAL)) SRC_S = \ - sdk/devices/$(CHIP_FAMILY)/gcc/startup_$(CHIP_FAMILY).S \ + sdk/devices/$(CHIP_FAMILY)/gcc/startup_$(CHIP_CORE).S \ supervisor/cpu.S OBJ = $(PY_O) $(SUPERVISOR_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) diff --git a/ports/mimxrt10xx/boards/board.h b/ports/mimxrt10xx/boards/board.h index e6736806ed..f00fea6be9 100644 --- a/ports/mimxrt10xx/boards/board.h +++ b/ports/mimxrt10xx/boards/board.h @@ -27,3 +27,4 @@ #include "mpconfigboard.h" #define XIP_BOOT_HEADER_ENABLE (1) +#define XIP_EXTERNAL_FLASH (1) diff --git a/ports/mimxrt10xx/boards/imxrt1010_evk/board.c b/ports/mimxrt10xx/boards/imxrt1010_evk/board.c index b839ffa666..c5237c8a8e 100644 --- a/ports/mimxrt10xx/boards/imxrt1010_evk/board.c +++ b/ports/mimxrt10xx/boards/imxrt1010_evk/board.c @@ -42,8 +42,8 @@ const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { &pin_GPIO_SD_07, &pin_GPIO_SD_06, // USB Pins - &pin_GPIO_12, - &pin_GPIO_13, + &pin_USB_OTG1_DN, + &pin_USB_OTG1_DP, NULL, // Must end in NULL. }; diff --git a/ports/mimxrt10xx/boards/imxrt1010_evk/flash_config.c b/ports/mimxrt10xx/boards/imxrt1010_evk/flash_config.c index f15a3f3459..383a8ba1d1 100644 --- a/ports/mimxrt10xx/boards/imxrt1010_evk/flash_config.c +++ b/ports/mimxrt10xx/boards/imxrt1010_evk/flash_config.c @@ -37,7 +37,7 @@ const flexspi_nor_config_t qspiflash_config = { .deviceModeArg = 0x02, .deviceType = kFLEXSPIDeviceType_SerialNOR, .sflashPadType = kSerialFlash_4Pads, - .serialClkFreq = kFLEXSPISerialClk_60MHz, + .serialClkFreq = kFLEXSPISerialClk_133MHz, .sflashA1Size = FLASH_SIZE, .lookupTable = { diff --git a/ports/mimxrt10xx/boards/imxrt1010_evk/mpconfigboard.h b/ports/mimxrt10xx/boards/imxrt1010_evk/mpconfigboard.h index 192c265f88..2ae3a8b6f1 100644 --- a/ports/mimxrt10xx/boards/imxrt1010_evk/mpconfigboard.h +++ b/ports/mimxrt10xx/boards/imxrt1010_evk/mpconfigboard.h @@ -17,7 +17,7 @@ #define DEFAULT_UART_BUS_RX (&pin_GPIO_09) #define DEFAULT_UART_BUS_TX (&pin_GPIO_10) -#define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO_09) -#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO_10) +// #define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO_09) +// #define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO_10) #define MICROPY_HW_LED_STATUS (&pin_GPIO_11) diff --git a/ports/mimxrt10xx/boards/imxrt1015_evk/board.c b/ports/mimxrt10xx/boards/imxrt1015_evk/board.c new file mode 100644 index 0000000000..568945a3eb --- /dev/null +++ b/ports/mimxrt10xx/boards/imxrt1015_evk/board.c @@ -0,0 +1,49 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" +#include "shared-bindings/microcontroller/Pin.h" + +// These pins should never ever be reset; doing so could interfere with basic operation. +// Used in common-hal/microcontroller/Pin.c +const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { + &pin_GPIO_AD_B0_00, // SWDIO + &pin_GPIO_AD_B0_01, // SWCLK + // FLEX flash + &pin_GPIO_SD_B1_06, + &pin_GPIO_SD_B1_07, + &pin_GPIO_SD_B1_08, + &pin_GPIO_SD_B1_09, + &pin_GPIO_SD_B1_10, + &pin_GPIO_SD_B1_11, + // USB Pins + &pin_USB_OTG1_DN, + &pin_USB_OTG1_DP, + NULL, // Must end in NULL. +}; + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/mimxrt10xx/boards/imxrt1015_evk/flash_config.c b/ports/mimxrt10xx/boards/imxrt1015_evk/flash_config.c new file mode 100644 index 0000000000..f15a3f3459 --- /dev/null +++ b/ports/mimxrt10xx/boards/imxrt1015_evk/flash_config.c @@ -0,0 +1,143 @@ +/* + * Copyright 2017 NXP + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "boards/flash_config.h" + +#include "xip/fsl_flexspi_nor_boot.h" + +// Config for AT25SF128A with QSPI routed. +__attribute__((section(".boot_hdr.conf"))) +const flexspi_nor_config_t qspiflash_config = { + .pageSize = 256u, + .sectorSize = 4u * 1024u, + .ipcmdSerialClkFreq = kFLEXSPISerialClk_30MHz, + .blockSize = 0x00010000, + .isUniformBlockSize = false, + .memConfig = + { + .tag = FLEXSPI_CFG_BLK_TAG, + .version = FLEXSPI_CFG_BLK_VERSION, + .readSampleClkSrc = kFLEXSPIReadSampleClk_LoopbackFromDqsPad, + .csHoldTime = 3u, + .csSetupTime = 3u, + + .busyOffset = 0u, // Status bit 0 indicates busy. + .busyBitPolarity = 0u, // Busy when the bit is 1. + + .deviceModeCfgEnable = 1u, + .deviceModeType = kDeviceConfigCmdType_QuadEnable, + .deviceModeSeq = { + .seqId = 4u, + .seqNum = 1u, + }, + .deviceModeArg = 0x02, + .deviceType = kFLEXSPIDeviceType_SerialNOR, + .sflashPadType = kSerialFlash_4Pads, + .serialClkFreq = kFLEXSPISerialClk_60MHz, + .sflashA1Size = FLASH_SIZE, + .lookupTable = + { + // FSL_ROM_FLEXSPI_LUT_SEQ(cmd0, pad0, op0, cmd1, pad1, op1) + // The high 16 bits is command 1 and the low are command 0. + // Within a command, the top 6 bits are the opcode, the next two are the number + // of pads and then last byte is the operand. The operand's meaning changes + // per opcode. + + // Indices with ROM should always have the same function because the ROM + // bootloader uses it. + + // 0: ROM: Read LUTs + // Quad version + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0xEB /* the command to send */, + RADDR_SDR, FLEXSPI_4PAD, 24 /* bits to transmit */), + FSL_ROM_FLEXSPI_LUT_SEQ(DUMMY_SDR, FLEXSPI_4PAD, 6 /* 6 dummy cycles, 2 for M7-0 and 4 dummy */, + READ_SDR, FLEXSPI_4PAD, 0x04), + // Single fast read version, good for debugging. + // FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x0B /* the command to send */, + // RADDR_SDR, FLEXSPI_1PAD, 24 /* bits to transmit */), + // FSL_ROM_FLEXSPI_LUT_SEQ(DUMMY_SDR, FLEXSPI_1PAD, 8 /* 8 dummy clocks */, + // READ_SDR, FLEXSPI_1PAD, 0x04), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 1: ROM: Read status + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x05 /* the command to send */, + READ_SDR, FLEXSPI_1PAD, 0x02), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 2: Empty + EMPTY_SEQUENCE, + + // 3: ROM: Write Enable + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x06 /* the command to send */, + STOP, FLEXSPI_1PAD, 0x00), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 4: Config: Write Status + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x31 /* the command to send */, + WRITE_SDR, FLEXSPI_1PAD, 0x01), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 5: ROM: Erase Sector + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x20 /* the command to send */, + RADDR_SDR, FLEXSPI_1PAD, 24 /* bits to transmit */), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 6: Empty + EMPTY_SEQUENCE, + + // 7: Empty + EMPTY_SEQUENCE, + + // 8: Block Erase + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0xD8 /* the command to send */, + RADDR_SDR, FLEXSPI_1PAD, 24 /* bits to transmit */), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 9: ROM: Page program + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x02 /* the command to send */, + RADDR_SDR, FLEXSPI_1PAD, 24 /* bits to transmit */), + + FSL_ROM_FLEXSPI_LUT_SEQ(WRITE_SDR, FLEXSPI_1PAD, 0x04 /* data out */, + STOP, FLEXSPI_1PAD, 0), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 10: Empty + EMPTY_SEQUENCE, + + // 11: ROM: Chip erase + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x60 /* the command to send */, + STOP, FLEXSPI_1PAD, 0), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 12: Empty + EMPTY_SEQUENCE, + + // 13: ROM: Read SFDP + EMPTY_SEQUENCE, + + // 14: ROM: Restore no cmd + EMPTY_SEQUENCE, + + // 15: ROM: Dummy + EMPTY_SEQUENCE + }, + }, +}; diff --git a/ports/mimxrt10xx/boards/imxrt1015_evk/mpconfigboard.h b/ports/mimxrt10xx/boards/imxrt1015_evk/mpconfigboard.h new file mode 100644 index 0000000000..ff2fe55319 --- /dev/null +++ b/ports/mimxrt10xx/boards/imxrt1015_evk/mpconfigboard.h @@ -0,0 +1,24 @@ +#define MICROPY_HW_BOARD_NAME "IMXRT1015-EVK" +#define MICROPY_HW_MCU_NAME "IMXRT1015DAF5A" + +// If you change this, then make sure to update the linker scripts as well to +// make sure you don't overwrite code +#define CIRCUITPY_INTERNAL_NVM_SIZE 0 + +#define BOARD_FLASH_SIZE (16 * 1024 * 1024) + +#define DEFAULT_SPI_BUS_SCK (&pin_GPIO_AD_B0_10) +#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO_AD_B0_12) +#define DEFAULT_SPI_BUS_MISO (&pin_GPIO_AD_B0_13) + +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO_AD_B1_15) +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO_AD_B1_14) + +#define DEFAULT_UART_BUS_RX (&pin_GPIO_EMC_33) +#define DEFAULT_UART_BUS_TX (&pin_GPIO_EMC_32) + +// #define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO_AD_B0_07) +// #define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO_AD_B0_06) + +#define MICROPY_HW_LED_STATUS (&pin_GPIO_SD_B1_00) +#define MICROPY_HW_LED_STATUS_INVERTED (1) diff --git a/ports/mimxrt10xx/boards/imxrt1015_evk/mpconfigboard.mk b/ports/mimxrt10xx/boards/imxrt1015_evk/mpconfigboard.mk new file mode 100644 index 0000000000..0f446e13bf --- /dev/null +++ b/ports/mimxrt10xx/boards/imxrt1015_evk/mpconfigboard.mk @@ -0,0 +1,8 @@ +USB_VID = 0x239A +USB_PID = 0x8078 +USB_PRODUCT = "IMXRT1015-EVK" +USB_MANUFACTURER = "NXP" + +CHIP_VARIANT = MIMXRT1015DAF5A +CHIP_FAMILY = MIMXRT1015 +FLASH = AT25SF128A diff --git a/ports/mimxrt10xx/boards/imxrt1015_evk/pins.c b/ports/mimxrt10xx/boards/imxrt1015_evk/pins.c new file mode 100644 index 0000000000..abe2e8e746 --- /dev/null +++ b/ports/mimxrt10xx/boards/imxrt1015_evk/pins.c @@ -0,0 +1,76 @@ +#include "shared-bindings/board/__init__.h" + +#include "supervisor/board.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_OBJ_NEW_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO_EMC_33) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO_EMC_33) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO_EMC_32) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO_EMC_32) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO_EMC_20) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO_EMC_26) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO_EMC_34) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO_EMC_27) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO_AD_B1_11) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_GPIO_AD_B0_15) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_GPIO_EMC_21) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_GPIO_EMC_22) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO_AD_B0_11) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_GPIO_AD_B0_12) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO_AD_B0_12) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO_AD_B0_13) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO_AD_B0_13) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO_AD_B0_10) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO_AD_B0_10) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_GPIO_AD_B1_15) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_GPIO_AD_B1_14) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO_AD_B1_13) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO_AD_B0_14) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO_AD_B1_12) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO_AD_B1_10) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_GPIO_AD_B1_15) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO_AD_B1_15) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_GPIO_AD_B1_14) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO_AD_B1_14) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_USER_LED), MP_ROM_PTR(&pin_GPIO_SD_B1_00) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO_SD_B1_00) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_LED1), MP_ROM_PTR(&pin_GPIO_SD_B1_00) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_LED2), MP_ROM_PTR(&pin_GPIO_SD_B1_01) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_LED3), MP_ROM_PTR(&pin_GPIO_SD_B1_02) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_USER_SW), MP_ROM_PTR(&pin_GPIO_EMC_09) }, + + // Audio Interface + { MP_ROM_QSTR(MP_QSTR_AUDIO_INT), MP_ROM_PTR(&pin_GPIO_EMC_08) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_SYNC), MP_ROM_PTR(&pin_GPIO_EMC_27) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_BCLK), MP_ROM_PTR(&pin_GPIO_EMC_26) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_RXD), MP_ROM_PTR(&pin_GPIO_EMC_21) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_TXD), MP_ROM_PTR(&pin_GPIO_EMC_25) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_MCLK), MP_ROM_PTR(&pin_GPIO_EMC_20) }, + + // SPDIF + { MP_ROM_QSTR(MP_QSTR_SPDIF_IN), MP_ROM_PTR(&pin_GPIO_EMC_05) }, + { MP_ROM_QSTR(MP_QSTR_SPDIF_OUT), MP_ROM_PTR(&pin_GPIO_EMC_04) }, + + // J29 UART LPUART4 + { MP_ROM_QSTR(MP_QSTR_J29_TX), MP_ROM_PTR(&pin_GPIO_EMC_32) }, + { MP_ROM_QSTR(MP_QSTR_J29_RX), MP_ROM_PTR(&pin_GPIO_EMC_33) }, + + // J30 UART LPUART3 + { MP_ROM_QSTR(MP_QSTR_J30_TX), MP_ROM_PTR(&pin_GPIO_EMC_06) }, + { MP_ROM_QSTR(MP_QSTR_J30_RX), MP_ROM_PTR(&pin_GPIO_EMC_07) }, + + // Freelink UART + { MP_ROM_QSTR(MP_QSTR_FREELINK_TX), MP_ROM_PTR(&pin_GPIO_AD_B0_06) }, + { MP_ROM_QSTR(MP_QSTR_FREELINK_RX), MP_ROM_PTR(&pin_GPIO_AD_B0_07) }, + + { 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_module_globals_table); diff --git a/ports/mimxrt10xx/boards/imxrt1020_evk/board.c b/ports/mimxrt10xx/boards/imxrt1020_evk/board.c index afbc0c58b5..f814afd956 100644 --- a/ports/mimxrt10xx/boards/imxrt1020_evk/board.c +++ b/ports/mimxrt10xx/boards/imxrt1020_evk/board.c @@ -44,8 +44,8 @@ const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { &pin_GPIO_SD_B1_11, // USB Pins - &pin_GPIO_AD_B1_11, - &pin_GPIO_AD_B1_12, + &pin_USB_OTG1_DN, + &pin_USB_OTG1_DP, NULL, // Must end in NULL. }; diff --git a/ports/mimxrt10xx/boards/imxrt1020_evk/flash_config.c b/ports/mimxrt10xx/boards/imxrt1020_evk/flash_config.c index 2ae8ae9b76..47293c22b9 100644 --- a/ports/mimxrt10xx/boards/imxrt1020_evk/flash_config.c +++ b/ports/mimxrt10xx/boards/imxrt1020_evk/flash_config.c @@ -21,7 +21,7 @@ const flexspi_nor_config_t qspiflash_config = { { .tag = FLEXSPI_CFG_BLK_TAG, .version = FLEXSPI_CFG_BLK_VERSION, - .readSampleClkSrc = kFLEXSPIReadSampleClk_LoopbackFromDqsPad, + .readSampleClkSrc = kFLEXSPIReadSampleClk_LoopbackFromSckPad, .csHoldTime = 3u, .csSetupTime = 3u, diff --git a/ports/mimxrt10xx/boards/imxrt1040_evk/board.c b/ports/mimxrt10xx/boards/imxrt1040_evk/board.c new file mode 100644 index 0000000000..0e97d87b60 --- /dev/null +++ b/ports/mimxrt10xx/boards/imxrt1040_evk/board.c @@ -0,0 +1,53 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" +#include "shared-bindings/microcontroller/Pin.h" + +// These pins should never ever be reset; doing so could interfere with basic operation. +// Used in common-hal/microcontroller/Pin.c +const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { + // SWD Pins + &pin_GPIO_AD_B0_06, // SWDIO + &pin_GPIO_AD_B0_07, // SWCLK + + // FLEXSPI QSPI + &pin_GPIO_SD_B1_05, + &pin_GPIO_SD_B1_06, + &pin_GPIO_SD_B1_07, + &pin_GPIO_SD_B1_08, + &pin_GPIO_SD_B1_09, + &pin_GPIO_SD_B1_10, + &pin_GPIO_SD_B1_11, + + &pin_USB_OTG1_DN, + &pin_USB_OTG1_DP, + + NULL, // Must end in NULL. +}; + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/mimxrt10xx/boards/imxrt1040_evk/flash_config.c b/ports/mimxrt10xx/boards/imxrt1040_evk/flash_config.c new file mode 100644 index 0000000000..e68d9f9312 --- /dev/null +++ b/ports/mimxrt10xx/boards/imxrt1040_evk/flash_config.c @@ -0,0 +1,144 @@ +/* + * Copyright 2017 NXP + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "boards/flash_config.h" + +#include "xip/fsl_flexspi_nor_boot.h" + +// Config for W25Q64JVSSIQ with QSPI routed. +__attribute__((section(".boot_hdr.conf"))) +const flexspi_nor_config_t qspiflash_config = { + .pageSize = 256u, + .sectorSize = 4u * 1024u, + .ipcmdSerialClkFreq = kFLEXSPISerialClk_30MHz, + .blockSize = 0x00010000, + .isUniformBlockSize = false, + .memConfig = + { + .tag = FLEXSPI_CFG_BLK_TAG, + .version = FLEXSPI_CFG_BLK_VERSION, + .readSampleClkSrc = kFLEXSPIReadSampleClk_LoopbackFromSckPad, + .csHoldTime = 3u, + .csSetupTime = 3u, + + .busyOffset = 0u, // Status bit 0 indicates busy. + .busyBitPolarity = 0u, // Busy when the bit is 1. + + .deviceModeCfgEnable = 1u, + .deviceModeType = kDeviceConfigCmdType_QuadEnable, + .deviceModeSeq = { + .seqId = 4u, + .seqNum = 1u, + }, + .deviceModeArg = 0x40, + .deviceType = kFLEXSPIDeviceType_SerialNOR, + .sflashPadType = kSerialFlash_4Pads, + .serialClkFreq = kFLEXSPISerialClk_60MHz, + .sflashA1Size = FLASH_SIZE, + .lookupTable = + { + // FSL_ROM_FLEXSPI_LUT_SEQ(cmd0, pad0, op0, cmd1, pad1, op1) + // The high 16 bits is command 1 and the low are command 0. + // Within a command, the top 6 bits are the opcode, the next two are the number + // of pads and then last byte is the operand. The operand's meaning changes + // per opcode. + + // Indices with ROM should always have the same function because the ROM + // bootloader uses it. + + // 0: ROM: Read LUTs + // Quad version + SEQUENCE( + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0xEB /* the command to send */, + RADDR_SDR, FLEXSPI_4PAD, 24 /* bits to transmit */), + FSL_ROM_FLEXSPI_LUT_SEQ(DUMMY_SDR, FLEXSPI_4PAD, 6 /* 6 dummy cycles, 2 for M7-0 and 4 dummy */, + READ_SDR, FLEXSPI_4PAD, 0x04), + // Single fast read version, good for debugging. + // FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x0B /* the command to send */, + // RADDR_SDR, FLEXSPI_1PAD, 24 /* bits to transmit */), + // FSL_ROM_FLEXSPI_LUT_SEQ(DUMMY_SDR, FLEXSPI_1PAD, 8 /* 8 dummy clocks */, + // READ_SDR, FLEXSPI_1PAD, 0x04), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 1: ROM: Read status + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x05 /* the command to send */, + READ_SDR, FLEXSPI_1PAD, 0x02), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 2: Empty + EMPTY_SEQUENCE, + + // 3: ROM: Write Enable + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x06 /* the command to send */, + STOP, FLEXSPI_1PAD, 0x00), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 4: Config: Write Status + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x01 /* the command to send */, + WRITE_SDR, FLEXSPI_1PAD, 0x01), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 5: ROM: Erase Sector + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x20 /* the command to send */, + RADDR_SDR, FLEXSPI_1PAD, 24 /* bits to transmit */), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 6: Empty + EMPTY_SEQUENCE, + + // 7: Empty + EMPTY_SEQUENCE, + + // 8: Block Erase + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0xD8 /* the command to send */, + RADDR_SDR, FLEXSPI_1PAD, 24 /* bits to transmit */), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 9: ROM: Page program + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x02 /* the command to send */, + RADDR_SDR, FLEXSPI_1PAD, 24 /* bits to transmit */), + + FSL_ROM_FLEXSPI_LUT_SEQ(WRITE_SDR, FLEXSPI_1PAD, 0x04 /* data out */, + STOP, FLEXSPI_1PAD, 0), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 10: Empty + EMPTY_SEQUENCE, + + // 11: ROM: Chip erase + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x60 /* the command to send */, + STOP, FLEXSPI_1PAD, 0), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 12: Empty + EMPTY_SEQUENCE, + + // 13: ROM: Read SFDP + EMPTY_SEQUENCE, + + // 14: ROM: Restore no cmd + EMPTY_SEQUENCE, + + // 15: ROM: Dummy + EMPTY_SEQUENCE + }, + }, +}; diff --git a/ports/mimxrt10xx/boards/imxrt1040_evk/mpconfigboard.h b/ports/mimxrt10xx/boards/imxrt1040_evk/mpconfigboard.h new file mode 100644 index 0000000000..dd1cf9f759 --- /dev/null +++ b/ports/mimxrt10xx/boards/imxrt1040_evk/mpconfigboard.h @@ -0,0 +1,22 @@ +#define MICROPY_HW_BOARD_NAME "iMX RT 1040 EVK" +#define MICROPY_HW_MCU_NAME "IMXRT1042XJM5B" + +// If you change this, then make sure to update the linker scripts as well to +// make sure you don't overwrite code +#define CIRCUITPY_INTERNAL_NVM_SIZE 0 + +#define BOARD_FLASH_SIZE (8 * 1024 * 1024) + +#define MICROPY_HW_LED_STATUS (&pin_GPIO_AD_B0_08) +#define MICROPY_HW_LED_STATUS_INVERTED (1) + +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO_AD_B1_00) +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO_AD_B1_01) + +#define DEFAULT_UART_BUS_RX (&pin_GPIO_AD_B1_07) +#define DEFAULT_UART_BUS_TX (&pin_GPIO_AD_B1_06) + +#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO_AD_B0_12) +#define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO_AD_B0_13) + +// If you want to connect over SWD, then make sure J80 is open. diff --git a/ports/mimxrt10xx/boards/imxrt1040_evk/mpconfigboard.mk b/ports/mimxrt10xx/boards/imxrt1040_evk/mpconfigboard.mk new file mode 100644 index 0000000000..cf351d906e --- /dev/null +++ b/ports/mimxrt10xx/boards/imxrt1040_evk/mpconfigboard.mk @@ -0,0 +1,8 @@ +USB_VID = 0x239A +USB_PID = 0x8084 +USB_PRODUCT = "iMX RT 1040 EVK" +USB_MANUFACTURER = "NXP" + +CHIP_VARIANT = MIMXRT1042XJM5B +CHIP_FAMILY = MIMXRT1042 +FLASH = W25Q64JV diff --git a/ports/mimxrt10xx/boards/imxrt1040_evk/pins.c b/ports/mimxrt10xx/boards/imxrt1040_evk/pins.c new file mode 100644 index 0000000000..4cabdddc55 --- /dev/null +++ b/ports/mimxrt10xx/boards/imxrt1040_evk/pins.c @@ -0,0 +1,123 @@ +#include "shared-bindings/board/__init__.h" + +#include "supervisor/board.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_OBJ_NEW_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO_SD_B1_01) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO_SD_B1_01) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO_SD_B1_00) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO_SD_B1_00) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO_AD_B0_11) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO_SD_B1_02) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO_AD_B0_09) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO_AD_B0_10) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO_AD_B1_02) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_GPIO_AD_B1_03) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_GPIO_B1_14) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_GPIO_B1_15) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO_SD_B0_01) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_GPIO_SD_B0_02) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO_SD_B0_03) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO_SD_B0_00) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_GPIO_AD_B1_01) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO_AD_B1_01) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_GPIO_AD_B1_00) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO_AD_B1_00) }, + + // i2c sensor is on I2C1_SCL/SDA + + { MP_OBJ_NEW_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO_AD_B0_14) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO_AD_B0_15) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO_AD_B1_04) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO_AD_B1_05) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_GPIO_AD_B1_06) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_GPIO_AD_B1_07) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_USER_LED), MP_ROM_PTR(&pin_GPIO_AD_B0_08) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO_AD_B0_08) }, + + // SD Card / Wifi + { MP_OBJ_NEW_QSTR(MP_QSTR_SDIO_CLK), MP_ROM_PTR(&pin_GPIO_SD_B0_01) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SD_SW), MP_ROM_PTR(&pin_GPIO_B1_12) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SDIO_CMD), MP_ROM_PTR(&pin_GPIO_SD_B0_00) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SDIO_D0), MP_ROM_PTR(&pin_GPIO_SD_B0_02) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SDIO_D1), MP_ROM_PTR(&pin_GPIO_SD_B0_03) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SDIO_D2), MP_ROM_PTR(&pin_GPIO_SD_B0_04) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SDIO_D3), MP_ROM_PTR(&pin_GPIO_SD_B0_05) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SD_PWREN), MP_ROM_PTR(&pin_GPIO_AD_B1_04) }, + + // LCD Interface + { MP_ROM_QSTR(MP_QSTR_LCD_BACKLIGHT), MP_ROM_PTR(&pin_GPIO_B1_15) }, + { MP_ROM_QSTR(MP_QSTR_LCD_RST), MP_ROM_PTR(&pin_GPIO_AD_B1_03) }, + { MP_ROM_QSTR(MP_QSTR_LCD_ENABLE), MP_ROM_PTR(&pin_GPIO_B0_01) }, + { MP_ROM_QSTR(MP_QSTR_LCD_VSYNC), MP_ROM_PTR(&pin_GPIO_B0_03) }, + { MP_ROM_QSTR(MP_QSTR_LCD_HSYNC), MP_ROM_PTR(&pin_GPIO_B0_02) }, + { MP_ROM_QSTR(MP_QSTR_LCD_CLK), MP_ROM_PTR(&pin_GPIO_B0_00) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D0), MP_ROM_PTR(&pin_GPIO_B0_04) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D1), MP_ROM_PTR(&pin_GPIO_B0_05) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D2), MP_ROM_PTR(&pin_GPIO_B0_06) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D3), MP_ROM_PTR(&pin_GPIO_B0_07) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D4), MP_ROM_PTR(&pin_GPIO_B0_08) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D5), MP_ROM_PTR(&pin_GPIO_B0_09) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D6), MP_ROM_PTR(&pin_GPIO_B0_10) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D7), MP_ROM_PTR(&pin_GPIO_B0_11) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D8), MP_ROM_PTR(&pin_GPIO_B0_12) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D9), MP_ROM_PTR(&pin_GPIO_B0_13) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D10), MP_ROM_PTR(&pin_GPIO_B0_14) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D11), MP_ROM_PTR(&pin_GPIO_B0_15) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D12), MP_ROM_PTR(&pin_GPIO_B1_00) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D13), MP_ROM_PTR(&pin_GPIO_B1_01) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D14), MP_ROM_PTR(&pin_GPIO_B1_02) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D15), MP_ROM_PTR(&pin_GPIO_B1_03) }, + + // Touch Interface + { MP_ROM_QSTR(MP_QSTR_LCD_TOUCH_INT), MP_ROM_PTR(&pin_GPIO_AD_B0_11) }, + + // Audio Interface + { MP_ROM_QSTR(MP_QSTR_AUDIO_INT), MP_ROM_PTR(&pin_GPIO_SD_B1_03) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_MCLK), MP_ROM_PTR(&pin_GPIO_B0_13) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_RX_SYNC), MP_ROM_PTR(&pin_GPIO_B0_14) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_RX_BCLK), MP_ROM_PTR(&pin_GPIO_B0_15) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_RXD), MP_ROM_PTR(&pin_GPIO_AD_B1_00) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_TXD), MP_ROM_PTR(&pin_GPIO_AD_B1_01) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_TX_BCLK), MP_ROM_PTR(&pin_GPIO_AD_B1_02) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_TX_SYNC), MP_ROM_PTR(&pin_GPIO_AD_B1_03) }, + + // SPDIF + { MP_ROM_QSTR(MP_QSTR_SPDIF_IN), MP_ROM_PTR(&pin_GPIO_AD_B1_03) }, + { MP_ROM_QSTR(MP_QSTR_SPDIF_OUT), MP_ROM_PTR(&pin_GPIO_AD_B1_02) }, + + // Ethernet + { MP_ROM_QSTR(MP_QSTR_ETHERNET_MDIO), MP_ROM_PTR(&pin_GPIO_EMC_41) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_MDC), MP_ROM_PTR(&pin_GPIO_EMC_40) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_RXD0), MP_ROM_PTR(&pin_GPIO_B1_04) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_RXD1), MP_ROM_PTR(&pin_GPIO_B1_05) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_CRS_DV), MP_ROM_PTR(&pin_GPIO_B1_06) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_TXD0), MP_ROM_PTR(&pin_GPIO_B1_07) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_TXD1), MP_ROM_PTR(&pin_GPIO_B1_08) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_TXEN), MP_ROM_PTR(&pin_GPIO_B1_09) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_INT), MP_ROM_PTR(&pin_GPIO_SD_B1_04) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_RST), MP_ROM_PTR(&pin_GPIO_AD_B0_09) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_CLK), MP_ROM_PTR(&pin_GPIO_B1_10) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_RXER), MP_ROM_PTR(&pin_GPIO_B1_11) }, + + // Freelink UART + { MP_ROM_QSTR(MP_QSTR_FREELINK_TX), MP_ROM_PTR(&pin_GPIO_AD_B0_12) }, + { MP_ROM_QSTR(MP_QSTR_FREELINK_RX), MP_ROM_PTR(&pin_GPIO_AD_B0_13) }, + + // CAN + { MP_ROM_QSTR(MP_QSTR_CAN_TX), MP_ROM_PTR(&pin_GPIO_AD_B0_14) }, + { MP_ROM_QSTR(MP_QSTR_CAN_RX), MP_ROM_PTR(&pin_GPIO_AD_B0_15) }, + { MP_ROM_QSTR(MP_QSTR_CAN_STBY), MP_ROM_PTR(&pin_GPIO_AD_B0_05) }, + + // USB + { MP_ROM_QSTR(MP_QSTR_USB_HOST_DP), MP_ROM_PTR(&pin_USB_OTG1_DP) }, + { MP_ROM_QSTR(MP_QSTR_USB_HOST_DM), MP_ROM_PTR(&pin_USB_OTG1_DN) }, + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/mimxrt10xx/boards/imxrt1050_evkb/board.c b/ports/mimxrt10xx/boards/imxrt1050_evkb/board.c new file mode 100644 index 0000000000..8a34fc4210 --- /dev/null +++ b/ports/mimxrt10xx/boards/imxrt1050_evkb/board.c @@ -0,0 +1,53 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" +#include "shared-bindings/microcontroller/Pin.h" + +// These pins should never ever be reset; doing so could interfere with basic operation. +// Used in common-hal/microcontroller/Pin.c +const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = { + // SWD Pins + &pin_GPIO_AD_B0_06, // SWDIO + &pin_GPIO_AD_B0_07, // SWCLK + + // FLEXSPI QSPI + &pin_GPIO_SD_B1_05, + &pin_GPIO_SD_B1_06, + &pin_GPIO_SD_B1_07, + &pin_GPIO_SD_B1_08, + &pin_GPIO_SD_B1_09, + &pin_GPIO_SD_B1_10, + &pin_GPIO_SD_B1_11, + + // USB Pins + &pin_GPIO_AD_B0_01, + &pin_GPIO_AD_B0_03, + NULL, // Must end in NULL. +}; + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/mimxrt10xx/boards/imxrt1050_evkb/flash_config.c b/ports/mimxrt10xx/boards/imxrt1050_evkb/flash_config.c new file mode 100644 index 0000000000..110ef465bf --- /dev/null +++ b/ports/mimxrt10xx/boards/imxrt1050_evkb/flash_config.c @@ -0,0 +1,144 @@ +/* + * Copyright 2017 NXP + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "boards/flash_config.h" + +#include "xip/fsl_flexspi_nor_boot.h" + +// Config for IS25WP064A with QSPI routed. +__attribute__((section(".boot_hdr.conf"))) +const flexspi_nor_config_t qspiflash_config = { + .pageSize = 256u, + .sectorSize = 4u * 1024u, + .ipcmdSerialClkFreq = kFLEXSPISerialClk_30MHz, + .blockSize = 0x00010000, + .isUniformBlockSize = false, + .memConfig = + { + .tag = FLEXSPI_CFG_BLK_TAG, + .version = FLEXSPI_CFG_BLK_VERSION, + .readSampleClkSrc = kFLEXSPIReadSampleClk_LoopbackFromSckPad, + .csHoldTime = 3u, + .csSetupTime = 3u, + + .busyOffset = 0u, // Status bit 0 indicates busy. + .busyBitPolarity = 0u, // Busy when the bit is 1. + + .deviceModeCfgEnable = 1u, + .deviceModeType = kDeviceConfigCmdType_QuadEnable, + .deviceModeSeq = { + .seqId = 4u, + .seqNum = 1u, + }, + .deviceModeArg = 0x40, + .deviceType = kFLEXSPIDeviceType_SerialNOR, + .sflashPadType = kSerialFlash_4Pads, + .serialClkFreq = kFLEXSPISerialClk_60MHz, + .sflashA1Size = FLASH_SIZE, + .lookupTable = + { + // FSL_ROM_FLEXSPI_LUT_SEQ(cmd0, pad0, op0, cmd1, pad1, op1) + // The high 16 bits is command 1 and the low are command 0. + // Within a command, the top 6 bits are the opcode, the next two are the number + // of pads and then last byte is the operand. The operand's meaning changes + // per opcode. + + // Indices with ROM should always have the same function because the ROM + // bootloader uses it. + + // 0: ROM: Read LUTs + // Quad version + SEQUENCE( + FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0xEB /* the command to send */, + RADDR_SDR, FLEXSPI_4PAD, 24 /* bits to transmit */), + FSL_ROM_FLEXSPI_LUT_SEQ(DUMMY_SDR, FLEXSPI_4PAD, 6 /* 6 dummy cycles, 2 for M7-0 and 4 dummy */, + READ_SDR, FLEXSPI_4PAD, 0x04), + // Single fast read version, good for debugging. + // FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x0B /* the command to send */, + // RADDR_SDR, FLEXSPI_1PAD, 24 /* bits to transmit */), + // FSL_ROM_FLEXSPI_LUT_SEQ(DUMMY_SDR, FLEXSPI_1PAD, 8 /* 8 dummy clocks */, + // READ_SDR, FLEXSPI_1PAD, 0x04), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 1: ROM: Read status + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x05 /* the command to send */, + READ_SDR, FLEXSPI_1PAD, 0x02), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 2: Empty + EMPTY_SEQUENCE, + + // 3: ROM: Write Enable + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x06 /* the command to send */, + STOP, FLEXSPI_1PAD, 0x00), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 4: Config: Write Status + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x01 /* the command to send */, + WRITE_SDR, FLEXSPI_1PAD, 0x01), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 5: ROM: Erase Sector + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x20 /* the command to send */, + RADDR_SDR, FLEXSPI_1PAD, 24 /* bits to transmit */), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 6: Empty + EMPTY_SEQUENCE, + + // 7: Empty + EMPTY_SEQUENCE, + + // 8: Block Erase + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0xD8 /* the command to send */, + RADDR_SDR, FLEXSPI_1PAD, 24 /* bits to transmit */), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 9: ROM: Page program + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x02 /* the command to send */, + RADDR_SDR, FLEXSPI_1PAD, 24 /* bits to transmit */), + + FSL_ROM_FLEXSPI_LUT_SEQ(WRITE_SDR, FLEXSPI_1PAD, 0x04 /* data out */, + STOP, FLEXSPI_1PAD, 0), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 10: Empty + EMPTY_SEQUENCE, + + // 11: ROM: Chip erase + SEQUENCE(FSL_ROM_FLEXSPI_LUT_SEQ(CMD_SDR, FLEXSPI_1PAD, 0x60 /* the command to send */, + STOP, FLEXSPI_1PAD, 0), + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS, + TWO_EMPTY_STEPS), + + // 12: Empty + EMPTY_SEQUENCE, + + // 13: ROM: Read SFDP + EMPTY_SEQUENCE, + + // 14: ROM: Restore no cmd + EMPTY_SEQUENCE, + + // 15: ROM: Dummy + EMPTY_SEQUENCE + }, + }, +}; diff --git a/ports/mimxrt10xx/boards/imxrt1050_evkb/mpconfigboard.h b/ports/mimxrt10xx/boards/imxrt1050_evkb/mpconfigboard.h new file mode 100644 index 0000000000..44e1dfaf12 --- /dev/null +++ b/ports/mimxrt10xx/boards/imxrt1050_evkb/mpconfigboard.h @@ -0,0 +1,27 @@ +#define MICROPY_HW_BOARD_NAME "iMX RT 1050 EVKB" +#define MICROPY_HW_MCU_NAME "IMXRT1052DVL6B" + +// If you change this, then make sure to update the linker scripts as well to +// make sure you don't overwrite code +#define CIRCUITPY_INTERNAL_NVM_SIZE 0 + +// This uses the QSPI Flash. You'll need to modify the board to access it. See +// AN12108 for instructions. https://www.nxp.com/docs/en/application-note/AN12108.pdf +// JLinkGDBServer -if SWD -device "MIMXRT1052xxx6B?BankAddr=0x60000000&Loader=QSPI" +#define BOARD_FLASH_SIZE (8 * 1024 * 1024) + +#define MICROPY_HW_LED_STATUS (&pin_GPIO_AD_B0_09) +#define MICROPY_HW_LED_STATUS_INVERTED (1) + +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO_AD_B1_00) +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO_AD_B1_01) + +#define DEFAULT_UART_BUS_RX (&pin_GPIO_AD_B1_07) +#define DEFAULT_UART_BUS_TX (&pin_GPIO_AD_B1_06) + +#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO_AD_B0_12) +#define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO_AD_B0_13) + +// Put host on the second USB so that the device connection powers the board. +#define CIRCUITPY_USB_DEVICE_INSTANCE 0 +#define CIRCUITPY_USB_HOST_INSTANCE 1 diff --git a/ports/mimxrt10xx/boards/imxrt1050_evkb/mpconfigboard.mk b/ports/mimxrt10xx/boards/imxrt1050_evkb/mpconfigboard.mk new file mode 100644 index 0000000000..6627d46681 --- /dev/null +++ b/ports/mimxrt10xx/boards/imxrt1050_evkb/mpconfigboard.mk @@ -0,0 +1,10 @@ +USB_VID = 0x239A +USB_PID = 0x8084 +USB_PRODUCT = "iMX RT 1050 EVKB" +USB_MANUFACTURER = "NXP" + +CHIP_VARIANT = MIMXRT1052DVL6B +CHIP_FAMILY = MIMXRT1052 +FLASH = IS25WP064A + +CIRCUITPY_USB_HOST = 1 diff --git a/ports/mimxrt10xx/boards/imxrt1050_evkb/pins.c b/ports/mimxrt10xx/boards/imxrt1050_evkb/pins.c new file mode 100644 index 0000000000..a162463b28 --- /dev/null +++ b/ports/mimxrt10xx/boards/imxrt1050_evkb/pins.c @@ -0,0 +1,142 @@ +#include "shared-bindings/board/__init__.h" + +#include "supervisor/board.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + { MP_OBJ_NEW_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO_AD_B1_07) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO_AD_B1_07) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_GPIO_AD_B1_06) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO_AD_B1_06) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO_AD_B0_11) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO_AD_B1_08) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO_AD_B0_09) }, // Connected to audio codec + { MP_OBJ_NEW_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO_AD_B0_10) }, // Connected to audio codec + { MP_OBJ_NEW_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO_AD_B1_02) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_GPIO_AD_B1_03) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_GPIO_AD_B0_03) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_GPIO_AD_B0_02) }, // Connected to audio codec + { MP_OBJ_NEW_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO_SD_B0_01) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_GPIO_SD_B0_02) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO_SD_B0_03) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO_SD_B0_00) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D14), MP_ROM_PTR(&pin_GPIO_AD_B1_01) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO_AD_B1_01) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_D15), MP_ROM_PTR(&pin_GPIO_AD_B1_00) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO_AD_B1_00) }, + + // i2c sensor is on I2C1_SCL/SDA + + { MP_OBJ_NEW_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO_AD_B1_10) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO_AD_B1_11) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO_AD_B1_04) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO_AD_B1_05) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_GPIO_AD_B1_01) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_GPIO_AD_B1_00) }, + + { MP_OBJ_NEW_QSTR(MP_QSTR_USER_LED), MP_ROM_PTR(&pin_GPIO_AD_B0_09) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO_AD_B0_09) }, + + // Camera Sensor Interface + { MP_OBJ_NEW_QSTR(MP_QSTR_CSI_VSYNC), MP_ROM_PTR(&pin_GPIO_AD_B1_06) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CSI_PWDN), MP_ROM_PTR(&pin_GPIO_AD_B1_02) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CSI_HSYNC), MP_ROM_PTR(&pin_GPIO_AD_B1_07) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CSI_D9), MP_ROM_PTR(&pin_GPIO_AD_B1_08) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CSI_MCLK), MP_ROM_PTR(&pin_GPIO_AD_B1_05) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CSI_D8), MP_ROM_PTR(&pin_GPIO_AD_B1_09) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CSI_D7), MP_ROM_PTR(&pin_GPIO_AD_B1_10) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CSI_PIXCLK), MP_ROM_PTR(&pin_GPIO_AD_B1_04) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CSI_D6), MP_ROM_PTR(&pin_GPIO_AD_B1_11) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CSI_D2), MP_ROM_PTR(&pin_GPIO_AD_B1_15) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CSI_D5), MP_ROM_PTR(&pin_GPIO_AD_B1_12) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CSI_D3), MP_ROM_PTR(&pin_GPIO_AD_B1_14) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_CSI_D4), MP_ROM_PTR(&pin_GPIO_AD_B1_13) }, + + // SD Card + { MP_OBJ_NEW_QSTR(MP_QSTR_SD_CLK), MP_ROM_PTR(&pin_GPIO_SD_B0_01) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SD_SW), MP_ROM_PTR(&pin_GPIO_B1_12) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SD_CMD), MP_ROM_PTR(&pin_GPIO_SD_B0_00) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SD_D0), MP_ROM_PTR(&pin_GPIO_SD_B0_02) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SD_D1), MP_ROM_PTR(&pin_GPIO_SD_B0_03) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SD_D2), MP_ROM_PTR(&pin_GPIO_SD_B0_04) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SD_D3), MP_ROM_PTR(&pin_GPIO_SD_B0_05) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_SD_PWREN), MP_ROM_PTR(&pin_GPIO_AD_B1_03) }, + + // LCD Interface + { MP_ROM_QSTR(MP_QSTR_LCD_BACKLIGHT), MP_ROM_PTR(&pin_GPIO_B1_15) }, + { MP_ROM_QSTR(MP_QSTR_LCD_RST), MP_ROM_PTR(&pin_GPIO_AD_B0_02) }, + { MP_ROM_QSTR(MP_QSTR_LCD_ENABLE), MP_ROM_PTR(&pin_GPIO_B0_01) }, + { MP_ROM_QSTR(MP_QSTR_LCD_VSYNC), MP_ROM_PTR(&pin_GPIO_B0_03) }, + { MP_ROM_QSTR(MP_QSTR_LCD_HSYNC), MP_ROM_PTR(&pin_GPIO_B0_02) }, + { MP_ROM_QSTR(MP_QSTR_LCD_CLK), MP_ROM_PTR(&pin_GPIO_B0_00) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D0), MP_ROM_PTR(&pin_GPIO_B0_04) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D1), MP_ROM_PTR(&pin_GPIO_B0_05) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D2), MP_ROM_PTR(&pin_GPIO_B0_06) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D3), MP_ROM_PTR(&pin_GPIO_B0_07) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D4), MP_ROM_PTR(&pin_GPIO_B0_08) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D5), MP_ROM_PTR(&pin_GPIO_B0_09) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D6), MP_ROM_PTR(&pin_GPIO_B0_10) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D7), MP_ROM_PTR(&pin_GPIO_B0_11) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D8), MP_ROM_PTR(&pin_GPIO_B0_12) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D9), MP_ROM_PTR(&pin_GPIO_B0_13) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D10), MP_ROM_PTR(&pin_GPIO_B0_14) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D11), MP_ROM_PTR(&pin_GPIO_B0_15) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D12), MP_ROM_PTR(&pin_GPIO_B1_00) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D13), MP_ROM_PTR(&pin_GPIO_B1_01) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D14), MP_ROM_PTR(&pin_GPIO_B1_02) }, + { MP_ROM_QSTR(MP_QSTR_LCD_D15), MP_ROM_PTR(&pin_GPIO_B1_03) }, + + // Touch Interface + { MP_ROM_QSTR(MP_QSTR_LCD_TOUCH_INT), MP_ROM_PTR(&pin_GPIO_AD_B0_11) }, + + // Audio Interface + { MP_ROM_QSTR(MP_QSTR_AUDIO_INT), MP_ROM_PTR(&pin_GPIO_AD_B1_08) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_MCLK), MP_ROM_PTR(&pin_GPIO_AD_B1_09) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_RX_SYNC), MP_ROM_PTR(&pin_GPIO_AD_B1_10) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_RX_BCLK), MP_ROM_PTR(&pin_GPIO_AD_B1_11) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_RXD), MP_ROM_PTR(&pin_GPIO_AD_B1_12) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_TXD), MP_ROM_PTR(&pin_GPIO_AD_B1_13) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_TX_BCLK), MP_ROM_PTR(&pin_GPIO_AD_B1_14) }, + { MP_ROM_QSTR(MP_QSTR_AUDIO_TX_SYNC), MP_ROM_PTR(&pin_GPIO_AD_B1_15) }, + + // SPDIF + { MP_ROM_QSTR(MP_QSTR_SPDIF_IN), MP_ROM_PTR(&pin_GPIO_AD_B1_03) }, + { MP_ROM_QSTR(MP_QSTR_SPDIF_OUT), MP_ROM_PTR(&pin_GPIO_AD_B1_02) }, + + // Ethernet + { MP_ROM_QSTR(MP_QSTR_ETHERNET_MDIO), MP_ROM_PTR(&pin_GPIO_EMC_41) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_MDC), MP_ROM_PTR(&pin_GPIO_EMC_40) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_RXD0), MP_ROM_PTR(&pin_GPIO_B1_04) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_RXD1), MP_ROM_PTR(&pin_GPIO_B1_05) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_CRS_DV), MP_ROM_PTR(&pin_GPIO_B1_06) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_TXD0), MP_ROM_PTR(&pin_GPIO_B1_07) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_TXD1), MP_ROM_PTR(&pin_GPIO_B1_08) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_TXEN), MP_ROM_PTR(&pin_GPIO_B1_09) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_INT), MP_ROM_PTR(&pin_GPIO_AD_B0_10) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_RST), MP_ROM_PTR(&pin_GPIO_AD_B0_09) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_CLK), MP_ROM_PTR(&pin_GPIO_B1_10) }, + { MP_ROM_QSTR(MP_QSTR_ETHERNET_RXER), MP_ROM_PTR(&pin_GPIO_B1_11) }, + + // Freelink UART + { MP_ROM_QSTR(MP_QSTR_FREELINK_TX), MP_ROM_PTR(&pin_GPIO_AD_B0_12) }, + { MP_ROM_QSTR(MP_QSTR_FREELINK_RX), MP_ROM_PTR(&pin_GPIO_AD_B0_13) }, + + // CAN + { MP_ROM_QSTR(MP_QSTR_CAN_TX), MP_ROM_PTR(&pin_GPIO_AD_B0_14) }, + { MP_ROM_QSTR(MP_QSTR_CAN_RX), MP_ROM_PTR(&pin_GPIO_AD_B0_15) }, + { MP_ROM_QSTR(MP_QSTR_CAN_STBY), MP_ROM_PTR(&pin_GPIO_AD_B0_05) }, + + // USB + #if CIRCUITPY_USB_HOST_INSTANCE == 0 + { MP_ROM_QSTR(MP_QSTR_USB_HOST_DP), MP_ROM_PTR(&pin_USB_OTG1_DP) }, + { MP_ROM_QSTR(MP_QSTR_USB_HOST_DM), MP_ROM_PTR(&pin_USB_OTG1_DN) }, + #elif CIRCUITPY_USB_HOST_INSTANCE == 1 + { MP_ROM_QSTR(MP_QSTR_USB_HOST_DP), MP_ROM_PTR(&pin_USB_OTG2_DP) }, + { MP_ROM_QSTR(MP_QSTR_USB_HOST_DM), MP_ROM_PTR(&pin_USB_OTG2_DN) }, + #endif + + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, + { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/mimxrt10xx/boards/metro_m7_1011/flash_config.c b/ports/mimxrt10xx/boards/metro_m7_1011/flash_config.c index e4562c1965..3b47af1d6c 100644 --- a/ports/mimxrt10xx/boards/metro_m7_1011/flash_config.c +++ b/ports/mimxrt10xx/boards/metro_m7_1011/flash_config.c @@ -14,14 +14,14 @@ __attribute__((section(".boot_hdr.conf"))) const flexspi_nor_config_t qspiflash_config = { .pageSize = 256u, .sectorSize = 4u * 1024u, - .ipcmdSerialClkFreq = kFLEXSPISerialClk_30MHz, + .ipcmdSerialClkFreq = kFLEXSPISerialClk_133MHz, .blockSize = 0x00010000, .isUniformBlockSize = false, .memConfig = { .tag = FLEXSPI_CFG_BLK_TAG, .version = FLEXSPI_CFG_BLK_VERSION, - .readSampleClkSrc = kFLEXSPIReadSampleClk_LoopbackFromDqsPad, + .readSampleClkSrc = kFLEXSPIReadSampleClk_LoopbackFromSckPad, .csHoldTime = 3u, .csSetupTime = 3u, @@ -43,7 +43,7 @@ const flexspi_nor_config_t qspiflash_config = { }, .deviceType = kFLEXSPIDeviceType_SerialNOR, .sflashPadType = kSerialFlash_4Pads, - .serialClkFreq = kFLEXSPISerialClk_60MHz, + .serialClkFreq = kFLEXSPISerialClk_133MHz, .sflashA1Size = FLASH_SIZE, .lookupTable = { diff --git a/ports/mimxrt10xx/common-hal/audiobusio/I2SOut.c b/ports/mimxrt10xx/common-hal/audiobusio/I2SOut.c index 06765afe02..9ba2762f1c 100644 --- a/ports/mimxrt10xx/common-hal/audiobusio/I2SOut.c +++ b/ports/mimxrt10xx/common-hal/audiobusio/I2SOut.c @@ -77,9 +77,9 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t *self, const mcu_pin_obj_t *data, bool left_justified) { int instance = -1; - const mcu_periph_obj_t *bclk_periph = find_pin_function(mcu_sai_tx_bclk_list, bit_clock, &instance, MP_QSTR_bit_clock); - const mcu_periph_obj_t *sync_periph = find_pin_function(mcu_sai_tx_sync_list, word_select, &instance, MP_QSTR_word_select); - const mcu_periph_obj_t *data_periph = find_pin_function(mcu_sai_tx_data0_list, data, &instance, MP_QSTR_data); + const mcu_periph_obj_t *bclk_periph = find_pin_function(mcu_i2s_tx_bclk_list, bit_clock, &instance, MP_QSTR_bit_clock); + const mcu_periph_obj_t *sync_periph = find_pin_function(mcu_i2s_tx_sync_list, word_select, &instance, MP_QSTR_word_select); + const mcu_periph_obj_t *data_periph = find_pin_function(mcu_i2s_tx_data0_list, data, &instance, MP_QSTR_data); sai_transceiver_t config; SAI_GetClassicI2SConfig(&config, 16, kSAI_Stereo, 1); diff --git a/ports/mimxrt10xx/common-hal/busio/I2C.c b/ports/mimxrt10xx/common-hal/busio/I2C.c index 6c5bbea416..de1b94e80e 100644 --- a/ports/mimxrt10xx/common-hal/busio/I2C.c +++ b/ports/mimxrt10xx/common-hal/busio/I2C.c @@ -37,13 +37,17 @@ #include "sdk/drivers/lpi2c/fsl_lpi2c.h" #include "sdk/drivers/igpio/fsl_gpio.h" +#if IMXRT11XX +#define I2C_CLOCK_FREQ (24000000) +#else #define I2C_CLOCK_FREQ (CLOCK_GetFreq(kCLOCK_Usb1PllClk) / 8 / (1 + CLOCK_GetDiv(kCLOCK_Lpi2cDiv))) +#endif + #define IOMUXC_SW_MUX_CTL_PAD_MUX_MODE_ALT5 5U // arrays use 0 based numbering: I2C1 is stored at index 0 -#define MAX_I2C 4 -STATIC bool reserved_i2c[MAX_I2C]; -STATIC bool never_reset_i2c[MAX_I2C]; +STATIC bool reserved_i2c[MP_ARRAY_SIZE(mcu_i2c_banks)]; +STATIC bool never_reset_i2c[MP_ARRAY_SIZE(mcu_i2c_banks)]; void i2c_reset(void) { for (uint i = 0; i < MP_ARRAY_SIZE(mcu_i2c_banks); i++) { @@ -63,24 +67,28 @@ static void config_periph_pin(const mcu_periph_obj_t *periph) { IOMUXC_SetPinConfig(0, 0, 0, 0, periph->pin->cfg_reg, - IOMUXC_SW_PAD_CTL_PAD_HYS(0) - | IOMUXC_SW_PAD_CTL_PAD_PUS(3) - | IOMUXC_SW_PAD_CTL_PAD_PUE(0) + IOMUXC_SW_PAD_CTL_PAD_PUS(3) + #if IMXRT10XX + | IOMUXC_SW_PAD_CTL_PAD_HYS(0) | IOMUXC_SW_PAD_CTL_PAD_PKE(1) - | IOMUXC_SW_PAD_CTL_PAD_ODE(1) | IOMUXC_SW_PAD_CTL_PAD_SPEED(2) + #endif + | IOMUXC_SW_PAD_CTL_PAD_PUE(0) + | IOMUXC_SW_PAD_CTL_PAD_ODE(1) | IOMUXC_SW_PAD_CTL_PAD_DSE(4) | IOMUXC_SW_PAD_CTL_PAD_SRE(0)); } static void i2c_check_pin_config(const mcu_pin_obj_t *pin, uint32_t pull) { IOMUXC_SetPinConfig(0, 0, 0, 0, pin->cfg_reg, - IOMUXC_SW_PAD_CTL_PAD_HYS(1) - | IOMUXC_SW_PAD_CTL_PAD_PUS(0) // Pulldown - | IOMUXC_SW_PAD_CTL_PAD_PUE(pull) // 0=nopull (keeper), 1=pull + IOMUXC_SW_PAD_CTL_PAD_PUS(0) // Pulldown + #if IMXRT10XX + | IOMUXC_SW_PAD_CTL_PAD_HYS(1) | IOMUXC_SW_PAD_CTL_PAD_PKE(1) - | IOMUXC_SW_PAD_CTL_PAD_ODE(0) | IOMUXC_SW_PAD_CTL_PAD_SPEED(2) + #endif + | IOMUXC_SW_PAD_CTL_PAD_PUE(pull) // 0=nopull (keeper), 1=pull + | IOMUXC_SW_PAD_CTL_PAD_ODE(0) | IOMUXC_SW_PAD_CTL_PAD_DSE(1) | IOMUXC_SW_PAD_CTL_PAD_SRE(0)); } diff --git a/ports/mimxrt10xx/common-hal/busio/SPI.c b/ports/mimxrt10xx/common-hal/busio/SPI.c index d88b71a403..641714bcca 100644 --- a/ports/mimxrt10xx/common-hal/busio/SPI.c +++ b/ports/mimxrt10xx/common-hal/busio/SPI.c @@ -36,14 +36,21 @@ #include +#if IMXRT11XX +#define LPSPI_MASTER_CLK_FREQ (24000000) +#else #define LPSPI_MASTER_CLK_FREQ (CLOCK_GetFreq(kCLOCK_Usb1PllPfd0Clk) / (CLOCK_GetDiv(kCLOCK_LpspiDiv) + 1)) +#endif #define MAX_SPI_BUSY_RETRIES 100 // arrays use 0 based numbering: SPI1 is stored at index 0 -#define MAX_SPI 4 -STATIC bool reserved_spi[MAX_SPI]; -STATIC bool never_reset_spi[MAX_SPI]; +STATIC bool reserved_spi[MP_ARRAY_SIZE(mcu_spi_banks)]; +STATIC bool never_reset_spi[MP_ARRAY_SIZE(mcu_spi_banks)]; + +#if IMXRT11XX +STATIC const clock_ip_name_t s_lpspiClocks[] = LPSPI_CLOCKS; +#endif STATIC void config_periph_pin(const mcu_periph_obj_t *periph) { IOMUXC_SetPinMux( @@ -54,12 +61,14 @@ STATIC void config_periph_pin(const mcu_periph_obj_t *periph) { IOMUXC_SetPinConfig(0, 0, 0, 0, periph->pin->cfg_reg, - IOMUXC_SW_PAD_CTL_PAD_HYS(0) - | IOMUXC_SW_PAD_CTL_PAD_PUS(0) - | IOMUXC_SW_PAD_CTL_PAD_PUE(0) + IOMUXC_SW_PAD_CTL_PAD_PUS(0) + #if IMXRT10XX + | IOMUXC_SW_PAD_CTL_PAD_HYS(0) | IOMUXC_SW_PAD_CTL_PAD_PKE(1) - | IOMUXC_SW_PAD_CTL_PAD_ODE(0) | IOMUXC_SW_PAD_CTL_PAD_SPEED(2) + #endif + | IOMUXC_SW_PAD_CTL_PAD_PUE(0) + | IOMUXC_SW_PAD_CTL_PAD_ODE(0) | IOMUXC_SW_PAD_CTL_PAD_DSE(4) | IOMUXC_SW_PAD_CTL_PAD_SRE(0)); } @@ -68,6 +77,13 @@ void spi_reset(void) { for (uint i = 0; i < MP_ARRAY_SIZE(mcu_spi_banks); i++) { if (!never_reset_spi[i]) { reserved_spi[i] = false; + #if IMXRT11XX + // Skip resetting SPIs that aren't clocked. Doing so generates a bus fault. + if ((CCM->LPCG[s_lpspiClocks[i + 1]].STATUS0 & CCM_LPCG_STATUS0_ON_MASK) == ((uint32_t)kCLOCK_Off & CCM_LPCG_STATUS0_ON_MASK)) { + continue; + } + #endif + LPSPI_Deinit(mcu_spi_banks[i]); } } @@ -78,8 +94,8 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *miso, bool half_duplex) { const uint32_t sck_count = MP_ARRAY_SIZE(mcu_spi_sck_list); - const uint32_t miso_count = MP_ARRAY_SIZE(mcu_spi_miso_list); - const uint32_t mosi_count = MP_ARRAY_SIZE(mcu_spi_mosi_list); + const uint32_t miso_count = MP_ARRAY_SIZE(mcu_spi_sdi_list); + const uint32_t mosi_count = MP_ARRAY_SIZE(mcu_spi_sdo_list); bool spi_taken = false; if (half_duplex) { @@ -93,13 +109,13 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, // if both MOSI and MISO exist, loop search normally if ((mosi != NULL) && (miso != NULL)) { for (uint j = 0; j < mosi_count; j++) { - if ((mcu_spi_mosi_list[i].pin != mosi) - || (mcu_spi_sck_list[i].bank_idx != mcu_spi_mosi_list[j].bank_idx)) { + if ((mcu_spi_sdo_list[i].pin != mosi) + || (mcu_spi_sck_list[i].bank_idx != mcu_spi_sdo_list[j].bank_idx)) { continue; } for (uint k = 0; k < miso_count; k++) { - if ((mcu_spi_miso_list[k].pin != miso) // everything needs the same index - || (mcu_spi_sck_list[i].bank_idx != mcu_spi_miso_list[k].bank_idx)) { + if ((mcu_spi_sdi_list[k].pin != miso) // everything needs the same index + || (mcu_spi_sck_list[i].bank_idx != mcu_spi_sdi_list[k].bank_idx)) { continue; } // if SPI is taken, break (pins never have >1 periph) @@ -109,8 +125,8 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, } // store pins if not self->clock = &mcu_spi_sck_list[i]; - self->mosi = &mcu_spi_mosi_list[j]; - self->miso = &mcu_spi_miso_list[k]; + self->mosi = &mcu_spi_sdo_list[j]; + self->miso = &mcu_spi_sdi_list[k]; break; } if (self->clock != NULL || spi_taken) { @@ -123,8 +139,8 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, // if just MISO, reduce search } else if (miso != NULL) { for (uint j = 0; j < miso_count; j++) { - if ((mcu_spi_miso_list[j].pin != miso) // only SCK and MISO need the same index - || (mcu_spi_sck_list[i].bank_idx != mcu_spi_miso_list[j].bank_idx)) { + if ((mcu_spi_sdi_list[j].pin != miso) // only SCK and MISO need the same index + || (mcu_spi_sck_list[i].bank_idx != mcu_spi_sdi_list[j].bank_idx)) { continue; } if (reserved_spi[mcu_spi_sck_list[i].bank_idx - 1]) { @@ -132,7 +148,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, break; } self->clock = &mcu_spi_sck_list[i]; - self->miso = &mcu_spi_miso_list[j]; + self->miso = &mcu_spi_sdi_list[j]; break; } if (self->clock != NULL || spi_taken) { @@ -141,8 +157,8 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, // if just MOSI, reduce search } else if (mosi != NULL) { for (uint j = 0; j < mosi_count; j++) { - if ((mcu_spi_mosi_list[j].pin != mosi) // only SCK and MOSI need the same index - || (mcu_spi_sck_list[i].bank_idx != mcu_spi_mosi_list[j].bank_idx)) { + if ((mcu_spi_sdo_list[j].pin != mosi) // only SCK and MOSI need the same index + || (mcu_spi_sck_list[i].bank_idx != mcu_spi_sdo_list[j].bank_idx)) { continue; } if (reserved_spi[mcu_spi_sck_list[i].bank_idx - 1]) { @@ -150,7 +166,7 @@ void common_hal_busio_spi_construct(busio_spi_obj_t *self, break; } self->clock = &mcu_spi_sck_list[i]; - self->mosi = &mcu_spi_mosi_list[j]; + self->mosi = &mcu_spi_sdo_list[j]; break; } if (self->clock != NULL || spi_taken) { diff --git a/ports/mimxrt10xx/common-hal/busio/UART.c b/ports/mimxrt10xx/common-hal/busio/UART.c index 088b2aefc6..e4d5fda6ae 100644 --- a/ports/mimxrt10xx/common-hal/busio/UART.c +++ b/ports/mimxrt10xx/common-hal/busio/UART.c @@ -52,11 +52,15 @@ // arrays use 0 based numbering: UART1 is stored at index 0 -#define MAX_UART 8 -STATIC bool reserved_uart[MAX_UART]; -STATIC bool never_reset_uart[MAX_UART]; +STATIC bool reserved_uart[MP_ARRAY_SIZE(mcu_uart_banks)]; +STATIC bool never_reset_uart[MP_ARRAY_SIZE(mcu_uart_banks)]; +#if IMXRT11XX +#define UART_CLOCK_FREQ (24000000) +#else #define UART_CLOCK_FREQ (CLOCK_GetPllFreq(kCLOCK_PllUsb1) / 6U) / (CLOCK_GetDiv(kCLOCK_UartDiv) + 1U) +#endif + static void config_periph_pin(const mcu_periph_obj_t *periph) { IOMUXC_SetPinMux( @@ -67,12 +71,14 @@ static void config_periph_pin(const mcu_periph_obj_t *periph) { IOMUXC_SetPinConfig(0, 0, 0, 0, periph->pin->cfg_reg, - IOMUXC_SW_PAD_CTL_PAD_HYS(0) - | IOMUXC_SW_PAD_CTL_PAD_PUS(1) - | IOMUXC_SW_PAD_CTL_PAD_PUE(1) + IOMUXC_SW_PAD_CTL_PAD_PUS(1) + #if IMXRT10XX + | IOMUXC_SW_PAD_CTL_PAD_HYS(0) | IOMUXC_SW_PAD_CTL_PAD_PKE(1) - | IOMUXC_SW_PAD_CTL_PAD_ODE(0) | IOMUXC_SW_PAD_CTL_PAD_SPEED(1) + #endif + | IOMUXC_SW_PAD_CTL_PAD_PUE(1) + | IOMUXC_SW_PAD_CTL_PAD_ODE(0) | IOMUXC_SW_PAD_CTL_PAD_DSE(6) | IOMUXC_SW_PAD_CTL_PAD_SRE(0)); } @@ -288,12 +294,14 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self, IOMUXC_SetPinMux(rs485_dir->mux_reg, IOMUXC_SW_MUX_CTL_PAD_MUX_MODE_ALT5, 0, 0, 0, 0); DBGPrintf(&mp_plat_print, "\tAfter IOMUXC_SetPinMux\n"); IOMUXC_SetPinConfig(0, 0, 0, 0, rs485_dir->cfg_reg, - IOMUXC_SW_PAD_CTL_PAD_HYS(1) - | IOMUXC_SW_PAD_CTL_PAD_PUS(0) - | IOMUXC_SW_PAD_CTL_PAD_PUE(0) + IOMUXC_SW_PAD_CTL_PAD_PUS(0) + #if IMXRT10XX + | IOMUXC_SW_PAD_CTL_PAD_HYS(1) | IOMUXC_SW_PAD_CTL_PAD_PKE(1) - | IOMUXC_SW_PAD_CTL_PAD_ODE(0) | IOMUXC_SW_PAD_CTL_PAD_SPEED(2) + #endif + | IOMUXC_SW_PAD_CTL_PAD_PUE(0) + | IOMUXC_SW_PAD_CTL_PAD_ODE(0) | IOMUXC_SW_PAD_CTL_PAD_DSE(1) | IOMUXC_SW_PAD_CTL_PAD_SRE(0)); DBGPrintf(&mp_plat_print, "\tAfter IOMUXC_SetPinConfig\n"); diff --git a/ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c b/ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c index 2b4a78948e..31dac38bdc 100644 --- a/ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c +++ b/ports/mimxrt10xx/common-hal/digitalio/DigitalInOut.c @@ -42,12 +42,14 @@ void pin_config(const mcu_pin_obj_t *pin, bool open_drain, digitalio_pull_t pull) { IOMUXC_SetPinConfig(0, 0, 0, 0, pin->cfg_reg, - IOMUXC_SW_PAD_CTL_PAD_HYS(1) - | IOMUXC_SW_PAD_CTL_PAD_PUS((pull == PULL_UP) ? 2 : 0) - | IOMUXC_SW_PAD_CTL_PAD_PUE(pull != PULL_NONE) + IOMUXC_SW_PAD_CTL_PAD_PUS((pull == PULL_UP) ? 2 : 0) + #if IMXRT10XX + | IOMUXC_SW_PAD_CTL_PAD_HYS(1) | IOMUXC_SW_PAD_CTL_PAD_PKE(1) - | IOMUXC_SW_PAD_CTL_PAD_ODE(open_drain) | IOMUXC_SW_PAD_CTL_PAD_SPEED(2) + #endif + | IOMUXC_SW_PAD_CTL_PAD_PUE(pull != PULL_NONE) + | IOMUXC_SW_PAD_CTL_PAD_ODE(open_drain) | IOMUXC_SW_PAD_CTL_PAD_DSE(1) | IOMUXC_SW_PAD_CTL_PAD_SRE(0)); } diff --git a/ports/mimxrt10xx/common-hal/microcontroller/Processor.c b/ports/mimxrt10xx/common-hal/microcontroller/Processor.c index 9277f81d47..bd7d77f4fa 100644 --- a/ports/mimxrt10xx/common-hal/microcontroller/Processor.c +++ b/ports/mimxrt10xx/common-hal/microcontroller/Processor.c @@ -33,11 +33,14 @@ #include "shared-bindings/microcontroller/Processor.h" #include "shared-bindings/microcontroller/ResetReason.h" +#if CIRCUITPY_ANALOGIO #include "sdk/drivers/tempmon/fsl_tempmon.h" +#endif #include "sdk/drivers/ocotp/fsl_ocotp.h" #include "clocks.h" float common_hal_mcu_processor_get_temperature(void) { + #if CIRCUITPY_ANALOGIO tempmon_config_t config; TEMPMON_GetDefaultConfig(&config); @@ -50,6 +53,9 @@ float common_hal_mcu_processor_get_temperature(void) { OCOTP_Deinit(OCOTP); return temp; + #else + return 0; + #endif } uint32_t common_hal_mcu_processor_set_frequency(mcu_processor_obj_t *self, @@ -73,7 +79,11 @@ uint32_t common_hal_mcu_processor_get_frequency(void) { } void common_hal_mcu_processor_get_uid(uint8_t raw_id[]) { + #if IMXRT11XX + OCOTP_Init(OCOTP, CLOCK_GetFreq(kCLOCK_Ocotp)); + #else OCOTP_Init(OCOTP, CLOCK_GetFreq(kCLOCK_IpgClk)); + #endif // Reads shadow registers 0x01 - 0x04 (Configuration and Manufacturing Info) // into 8 bit wide destination, avoiding punning. diff --git a/ports/mimxrt10xx/common-hal/microcontroller/__init__.c b/ports/mimxrt10xx/common-hal/microcontroller/__init__.c index 1b10b4d4ee..de970fa26a 100644 --- a/ports/mimxrt10xx/common-hal/microcontroller/__init__.c +++ b/ports/mimxrt10xx/common-hal/microcontroller/__init__.c @@ -40,6 +40,8 @@ #include "supervisor/shared/safe_mode.h" #include "supervisor/shared/translate/translate.h" +#include "pins.h" + void common_hal_mcu_delay_us(uint32_t delay) { mp_hal_delay_us(delay); } @@ -107,188 +109,10 @@ const nvm_bytearray_obj_t common_hal_mcu_nvm_obj = { // This maps MCU pin names to pin objects. // NOTE: for all i.MX chips, order MUST match _iomuxc_sw_mux_ctl_pad enum -STATIC const mp_rom_map_elem_t mcu_pin_global_dict_table[] = { - #ifdef MIMXRT1011_SERIES - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_14), MP_ROM_PTR(&pin_GPIO_AD_14) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_13), MP_ROM_PTR(&pin_GPIO_AD_13) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_12), MP_ROM_PTR(&pin_GPIO_AD_12) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_11), MP_ROM_PTR(&pin_GPIO_AD_11) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_10), MP_ROM_PTR(&pin_GPIO_AD_10) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_09), MP_ROM_PTR(&pin_GPIO_AD_09) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_08), MP_ROM_PTR(&pin_GPIO_AD_08) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_07), MP_ROM_PTR(&pin_GPIO_AD_07) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_06), MP_ROM_PTR(&pin_GPIO_AD_06) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_05), MP_ROM_PTR(&pin_GPIO_AD_05) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_04), MP_ROM_PTR(&pin_GPIO_AD_04) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_03), MP_ROM_PTR(&pin_GPIO_AD_03) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_02), MP_ROM_PTR(&pin_GPIO_AD_02) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_01), MP_ROM_PTR(&pin_GPIO_AD_01) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_00), MP_ROM_PTR(&pin_GPIO_AD_00) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_14), MP_ROM_PTR(&pin_GPIO_SD_14) }, // spooky ghost pin - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_13), MP_ROM_PTR(&pin_GPIO_SD_13) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_12), MP_ROM_PTR(&pin_GPIO_SD_12) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_11), MP_ROM_PTR(&pin_GPIO_SD_11) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_10), MP_ROM_PTR(&pin_GPIO_SD_10) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_09), MP_ROM_PTR(&pin_GPIO_SD_09) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_08), MP_ROM_PTR(&pin_GPIO_SD_08) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_07), MP_ROM_PTR(&pin_GPIO_SD_07) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_06), MP_ROM_PTR(&pin_GPIO_SD_06) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_05), MP_ROM_PTR(&pin_GPIO_SD_05) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_04), MP_ROM_PTR(&pin_GPIO_SD_04) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_03), MP_ROM_PTR(&pin_GPIO_SD_03) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_02), MP_ROM_PTR(&pin_GPIO_SD_02) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_01), MP_ROM_PTR(&pin_GPIO_SD_01) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_00), MP_ROM_PTR(&pin_GPIO_SD_00) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_13), MP_ROM_PTR(&pin_GPIO_13) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_12), MP_ROM_PTR(&pin_GPIO_12) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_11), MP_ROM_PTR(&pin_GPIO_11) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_10), MP_ROM_PTR(&pin_GPIO_10) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_09), MP_ROM_PTR(&pin_GPIO_09) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_08), MP_ROM_PTR(&pin_GPIO_08) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_07), MP_ROM_PTR(&pin_GPIO_07) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_06), MP_ROM_PTR(&pin_GPIO_06) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_05), MP_ROM_PTR(&pin_GPIO_05) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_04), MP_ROM_PTR(&pin_GPIO_04) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_03), MP_ROM_PTR(&pin_GPIO_03) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_02), MP_ROM_PTR(&pin_GPIO_02) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_01), MP_ROM_PTR(&pin_GPIO_01) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_00), MP_ROM_PTR(&pin_GPIO_00) }, - #else - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_00), MP_ROM_PTR(&pin_GPIO_EMC_00) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_01), MP_ROM_PTR(&pin_GPIO_EMC_01) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_02), MP_ROM_PTR(&pin_GPIO_EMC_02) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_03), MP_ROM_PTR(&pin_GPIO_EMC_03) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_04), MP_ROM_PTR(&pin_GPIO_EMC_04) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_05), MP_ROM_PTR(&pin_GPIO_EMC_05) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_06), MP_ROM_PTR(&pin_GPIO_EMC_06) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_07), MP_ROM_PTR(&pin_GPIO_EMC_07) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_08), MP_ROM_PTR(&pin_GPIO_EMC_08) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_09), MP_ROM_PTR(&pin_GPIO_EMC_09) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_10), MP_ROM_PTR(&pin_GPIO_EMC_10) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_11), MP_ROM_PTR(&pin_GPIO_EMC_11) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_12), MP_ROM_PTR(&pin_GPIO_EMC_12) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_13), MP_ROM_PTR(&pin_GPIO_EMC_13) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_14), MP_ROM_PTR(&pin_GPIO_EMC_14) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_15), MP_ROM_PTR(&pin_GPIO_EMC_15) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_16), MP_ROM_PTR(&pin_GPIO_EMC_16) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_17), MP_ROM_PTR(&pin_GPIO_EMC_17) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_18), MP_ROM_PTR(&pin_GPIO_EMC_18) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_19), MP_ROM_PTR(&pin_GPIO_EMC_19) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_20), MP_ROM_PTR(&pin_GPIO_EMC_20) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_21), MP_ROM_PTR(&pin_GPIO_EMC_21) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_22), MP_ROM_PTR(&pin_GPIO_EMC_22) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_23), MP_ROM_PTR(&pin_GPIO_EMC_23) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_24), MP_ROM_PTR(&pin_GPIO_EMC_24) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_25), MP_ROM_PTR(&pin_GPIO_EMC_25) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_26), MP_ROM_PTR(&pin_GPIO_EMC_26) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_27), MP_ROM_PTR(&pin_GPIO_EMC_27) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_28), MP_ROM_PTR(&pin_GPIO_EMC_28) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_29), MP_ROM_PTR(&pin_GPIO_EMC_29) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_30), MP_ROM_PTR(&pin_GPIO_EMC_30) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_31), MP_ROM_PTR(&pin_GPIO_EMC_31) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_32), MP_ROM_PTR(&pin_GPIO_EMC_32) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_33), MP_ROM_PTR(&pin_GPIO_EMC_33) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_34), MP_ROM_PTR(&pin_GPIO_EMC_34) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_35), MP_ROM_PTR(&pin_GPIO_EMC_35) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_36), MP_ROM_PTR(&pin_GPIO_EMC_36) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_37), MP_ROM_PTR(&pin_GPIO_EMC_37) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_38), MP_ROM_PTR(&pin_GPIO_EMC_38) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_39), MP_ROM_PTR(&pin_GPIO_EMC_39) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_40), MP_ROM_PTR(&pin_GPIO_EMC_40) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_EMC_41), MP_ROM_PTR(&pin_GPIO_EMC_41) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B0_00), MP_ROM_PTR(&pin_GPIO_AD_B0_00) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B0_01), MP_ROM_PTR(&pin_GPIO_AD_B0_01) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B0_02), MP_ROM_PTR(&pin_GPIO_AD_B0_02) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B0_03), MP_ROM_PTR(&pin_GPIO_AD_B0_03) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B0_04), MP_ROM_PTR(&pin_GPIO_AD_B0_04) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B0_05), MP_ROM_PTR(&pin_GPIO_AD_B0_05) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B0_06), MP_ROM_PTR(&pin_GPIO_AD_B0_06) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B0_07), MP_ROM_PTR(&pin_GPIO_AD_B0_07) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B0_08), MP_ROM_PTR(&pin_GPIO_AD_B0_08) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B0_09), MP_ROM_PTR(&pin_GPIO_AD_B0_09) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B0_10), MP_ROM_PTR(&pin_GPIO_AD_B0_10) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B0_11), MP_ROM_PTR(&pin_GPIO_AD_B0_11) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B0_12), MP_ROM_PTR(&pin_GPIO_AD_B0_12) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B0_13), MP_ROM_PTR(&pin_GPIO_AD_B0_13) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B0_14), MP_ROM_PTR(&pin_GPIO_AD_B0_14) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B0_15), MP_ROM_PTR(&pin_GPIO_AD_B0_15) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B1_00), MP_ROM_PTR(&pin_GPIO_AD_B1_00) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B1_01), MP_ROM_PTR(&pin_GPIO_AD_B1_01) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B1_02), MP_ROM_PTR(&pin_GPIO_AD_B1_02) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B1_03), MP_ROM_PTR(&pin_GPIO_AD_B1_03) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B1_04), MP_ROM_PTR(&pin_GPIO_AD_B1_04) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B1_05), MP_ROM_PTR(&pin_GPIO_AD_B1_05) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B1_06), MP_ROM_PTR(&pin_GPIO_AD_B1_06) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B1_07), MP_ROM_PTR(&pin_GPIO_AD_B1_07) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B1_08), MP_ROM_PTR(&pin_GPIO_AD_B1_08) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B1_09), MP_ROM_PTR(&pin_GPIO_AD_B1_09) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B1_10), MP_ROM_PTR(&pin_GPIO_AD_B1_10) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B1_11), MP_ROM_PTR(&pin_GPIO_AD_B1_11) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B1_12), MP_ROM_PTR(&pin_GPIO_AD_B1_12) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B1_13), MP_ROM_PTR(&pin_GPIO_AD_B1_13) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B1_14), MP_ROM_PTR(&pin_GPIO_AD_B1_14) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_AD_B1_15), MP_ROM_PTR(&pin_GPIO_AD_B1_15) }, - #ifdef MIMXRT1062_SERIES - { MP_ROM_QSTR(MP_QSTR_GPIO_B0_00), MP_ROM_PTR(&pin_GPIO_B0_00) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B0_01), MP_ROM_PTR(&pin_GPIO_B0_01) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B0_02), MP_ROM_PTR(&pin_GPIO_B0_02) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B0_03), MP_ROM_PTR(&pin_GPIO_B0_03) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B0_04), MP_ROM_PTR(&pin_GPIO_B0_04) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B0_05), MP_ROM_PTR(&pin_GPIO_B0_05) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B0_06), MP_ROM_PTR(&pin_GPIO_B0_06) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B0_07), MP_ROM_PTR(&pin_GPIO_B0_07) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B0_08), MP_ROM_PTR(&pin_GPIO_B0_08) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B0_09), MP_ROM_PTR(&pin_GPIO_B0_09) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B0_10), MP_ROM_PTR(&pin_GPIO_B0_10) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B0_11), MP_ROM_PTR(&pin_GPIO_B0_11) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B0_12), MP_ROM_PTR(&pin_GPIO_B0_12) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B0_13), MP_ROM_PTR(&pin_GPIO_B0_13) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B0_14), MP_ROM_PTR(&pin_GPIO_B0_14) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B0_15), MP_ROM_PTR(&pin_GPIO_B0_15) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B1_00), MP_ROM_PTR(&pin_GPIO_B1_00) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B1_01), MP_ROM_PTR(&pin_GPIO_B1_01) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B1_02), MP_ROM_PTR(&pin_GPIO_B1_02) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B1_03), MP_ROM_PTR(&pin_GPIO_B1_03) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B1_04), MP_ROM_PTR(&pin_GPIO_B1_04) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B1_05), MP_ROM_PTR(&pin_GPIO_B1_05) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B1_06), MP_ROM_PTR(&pin_GPIO_B1_06) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B1_07), MP_ROM_PTR(&pin_GPIO_B1_07) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B1_08), MP_ROM_PTR(&pin_GPIO_B1_08) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B1_09), MP_ROM_PTR(&pin_GPIO_B1_09) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B1_10), MP_ROM_PTR(&pin_GPIO_B1_10) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B1_11), MP_ROM_PTR(&pin_GPIO_B1_11) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B1_12), MP_ROM_PTR(&pin_GPIO_B1_12) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B1_13), MP_ROM_PTR(&pin_GPIO_B1_13) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B1_14), MP_ROM_PTR(&pin_GPIO_B1_14) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_B1_15), MP_ROM_PTR(&pin_GPIO_B1_15) }, - #endif - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_B0_00), MP_ROM_PTR(&pin_GPIO_SD_B0_00) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_B0_01), MP_ROM_PTR(&pin_GPIO_SD_B0_01) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_B0_02), MP_ROM_PTR(&pin_GPIO_SD_B0_02) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_B0_03), MP_ROM_PTR(&pin_GPIO_SD_B0_03) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_B0_04), MP_ROM_PTR(&pin_GPIO_SD_B0_04) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_B0_05), MP_ROM_PTR(&pin_GPIO_SD_B0_05) }, - #ifdef MIMXRT1021_SERIES - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_B0_06), MP_ROM_PTR(&pin_GPIO_SD_B0_06) }, - #endif - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_B1_00), MP_ROM_PTR(&pin_GPIO_SD_B1_00) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_B1_01), MP_ROM_PTR(&pin_GPIO_SD_B1_01) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_B1_02), MP_ROM_PTR(&pin_GPIO_SD_B1_02) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_B1_03), MP_ROM_PTR(&pin_GPIO_SD_B1_03) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_B1_04), MP_ROM_PTR(&pin_GPIO_SD_B1_04) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_B1_05), MP_ROM_PTR(&pin_GPIO_SD_B1_05) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_B1_06), MP_ROM_PTR(&pin_GPIO_SD_B1_06) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_B1_07), MP_ROM_PTR(&pin_GPIO_SD_B1_07) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_B1_08), MP_ROM_PTR(&pin_GPIO_SD_B1_08) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_B1_09), MP_ROM_PTR(&pin_GPIO_SD_B1_09) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_B1_10), MP_ROM_PTR(&pin_GPIO_SD_B1_10) }, - { MP_ROM_QSTR(MP_QSTR_GPIO_SD_B1_11), MP_ROM_PTR(&pin_GPIO_SD_B1_11) }, - #ifdef MIMXRT1062_SERIES - { MP_ROM_QSTR(MP_QSTR_USB_OTG1_DN), MP_ROM_PTR(&pin_USB_OTG1_DN) }, - { MP_ROM_QSTR(MP_QSTR_USB_OTG1_DP), MP_ROM_PTR(&pin_USB_OTG1_DP) }, - { MP_ROM_QSTR(MP_QSTR_USB_OTG2_DN), MP_ROM_PTR(&pin_USB_OTG2_DN) }, - { MP_ROM_QSTR(MP_QSTR_USB_OTG2_DP), MP_ROM_PTR(&pin_USB_OTG2_DP) }, - #endif - #endif +STATIC const mp_rom_map_elem_t mcu_pin_global_dict_table[PIN_COUNT] = { + +#define FORMAT_PIN(pin_name) { MP_ROM_QSTR(MP_QSTR_##pin_name), MP_ROM_PTR(&pin_##pin_name) }, + #include "pin_names.h" +#undef FORMAT_PIN }; MP_DEFINE_CONST_DICT(mcu_pin_globals, mcu_pin_global_dict_table); diff --git a/ports/mimxrt10xx/common-hal/os/__init__.c b/ports/mimxrt10xx/common-hal/os/__init__.c index 9219242685..899541bb21 100644 --- a/ports/mimxrt10xx/common-hal/os/__init__.c +++ b/ports/mimxrt10xx/common-hal/os/__init__.c @@ -33,7 +33,9 @@ #include "shared-bindings/os/__init__.h" +#if CIRCUITPY_RANDOM #include "sdk/drivers/trng/fsl_trng.h" +#endif STATIC const qstr os_uname_info_fields[] = { MP_QSTR_sysname, MP_QSTR_nodename, @@ -61,6 +63,7 @@ mp_obj_t common_hal_os_uname(void) { } bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length) { + #if CIRCUITPY_RANDOM trng_config_t trngConfig; TRNG_GetDefaultConfig(&trngConfig); @@ -71,4 +74,7 @@ bool common_hal_os_urandom(uint8_t *buffer, mp_uint_t length) { TRNG_Deinit(TRNG); return true; + #else + return false; + #endif } diff --git a/ports/mimxrt10xx/linking/chip_family/MIMXRT1011.ld b/ports/mimxrt10xx/linking/chip_family/MIMXRT1011.ld index 0d0beebaae..55f03cb9c1 100644 --- a/ports/mimxrt10xx/linking/chip_family/MIMXRT1011.ld +++ b/ports/mimxrt10xx/linking/chip_family/MIMXRT1011.ld @@ -1,2 +1,4 @@ ram_size = 128K; -flash_config_location = 0x60000400; +flash_base = 0x60000000; +ocram_base = 0x20200000; +flash_config_location = flash_base + 0x400; diff --git a/ports/mimxrt10xx/linking/chip_family/MIMXRT1015.ld b/ports/mimxrt10xx/linking/chip_family/MIMXRT1015.ld new file mode 100644 index 0000000000..72b2b705b5 --- /dev/null +++ b/ports/mimxrt10xx/linking/chip_family/MIMXRT1015.ld @@ -0,0 +1,4 @@ +ram_size = 128K; +flash_base = 0x60000000; +ocram_base = 0x20200000; +flash_config_location = flash_base; diff --git a/ports/mimxrt10xx/linking/chip_family/MIMXRT1021.ld b/ports/mimxrt10xx/linking/chip_family/MIMXRT1021.ld index 21f2ea872c..215e58f9b3 100644 --- a/ports/mimxrt10xx/linking/chip_family/MIMXRT1021.ld +++ b/ports/mimxrt10xx/linking/chip_family/MIMXRT1021.ld @@ -1,2 +1,4 @@ ram_size = 256K; -flash_config_location = 0x60000000; +flash_base = 0x60000000; +ocram_base = 0x20200000; +flash_config_location = flash_base; diff --git a/ports/mimxrt10xx/linking/chip_family/MIMXRT1042.ld b/ports/mimxrt10xx/linking/chip_family/MIMXRT1042.ld new file mode 100644 index 0000000000..9af9660087 --- /dev/null +++ b/ports/mimxrt10xx/linking/chip_family/MIMXRT1042.ld @@ -0,0 +1,4 @@ +ram_size = 512K; +flash_base = 0x60000000; +ocram_base = 0x20200000; +flash_config_location = flash_base; diff --git a/ports/mimxrt10xx/linking/chip_family/MIMXRT1052.ld b/ports/mimxrt10xx/linking/chip_family/MIMXRT1052.ld new file mode 100644 index 0000000000..9af9660087 --- /dev/null +++ b/ports/mimxrt10xx/linking/chip_family/MIMXRT1052.ld @@ -0,0 +1,4 @@ +ram_size = 512K; +flash_base = 0x60000000; +ocram_base = 0x20200000; +flash_config_location = flash_base; diff --git a/ports/mimxrt10xx/linking/chip_family/MIMXRT1062.ld b/ports/mimxrt10xx/linking/chip_family/MIMXRT1062.ld index e07c5c2c37..1ae8172200 100644 --- a/ports/mimxrt10xx/linking/chip_family/MIMXRT1062.ld +++ b/ports/mimxrt10xx/linking/chip_family/MIMXRT1062.ld @@ -1,2 +1,4 @@ ram_size = 1M; -flash_config_location = 0x60000000; +flash_base = 0x60000000; +ocram_base = 0x20200000; +flash_config_location = flash_base; diff --git a/ports/mimxrt10xx/linking/chip_family/MIMXRT1176.ld b/ports/mimxrt10xx/linking/chip_family/MIMXRT1176.ld new file mode 100644 index 0000000000..a5d18addb7 --- /dev/null +++ b/ports/mimxrt10xx/linking/chip_family/MIMXRT1176.ld @@ -0,0 +1,4 @@ +ram_size = 1M; +flash_base = 0x30000000; +ocram_base = 0x20240000; +flash_config_location = flash_base + 0x400; diff --git a/ports/mimxrt10xx/linking/common.ld b/ports/mimxrt10xx/linking/common.ld index 76c11c8d6f..a3ed2dbdbf 100644 --- a/ports/mimxrt10xx/linking/common.ld +++ b/ports/mimxrt10xx/linking/common.ld @@ -19,13 +19,13 @@ MEMORY /* This is the first block and is read so that the bootrom knows the optimal way to interface with the flash chip. */ FLASH_CONFIG (rx) : ORIGIN = flash_config_location, LENGTH = 512 /* This can't move because the bootrom looks at this address. */ - FLASH_IVT (rx) : ORIGIN = 0x60001000, LENGTH = 4K + FLASH_IVT (rx) : ORIGIN = flash_base + 0x1000, LENGTH = 4K /* Place the ISRs 48k in to leave room for the bootloader when it is available. */ - FLASH_FIRMWARE (rx) : ORIGIN = 0x6000C000, LENGTH = code_size - 48K - FLASH_FATFS (r) : ORIGIN = 0x60000000 + code_size, LENGTH = _ld_flash_size - code_size - _ld_reserved_flash_size + FLASH_FIRMWARE (rx) : ORIGIN = flash_base + 0xC000, LENGTH = code_size - 48K + FLASH_FATFS (r) : ORIGIN = flash_base + code_size, LENGTH = _ld_flash_size - code_size - _ld_reserved_flash_size /* Teensy uses the last bit of flash for recovery. */ - RESERVED_FLASH : ORIGIN = 0x60000000 + code_size + _ld_flash_size - _ld_reserved_flash_size, LENGTH = _ld_reserved_flash_size - OCRAM (rwx) : ORIGIN = 0x20200000, LENGTH = ram_size - 64K + RESERVED_FLASH : ORIGIN = flash_base + code_size + _ld_flash_size - _ld_reserved_flash_size, LENGTH = _ld_reserved_flash_size + OCRAM (rwx) : ORIGIN = ocram_base, LENGTH = ram_size - 64K DTCM (x) : ORIGIN = 0x20000000, LENGTH = 32K ITCM (x) : ORIGIN = 0x00000000, LENGTH = 32K } @@ -135,7 +135,9 @@ SECTIONS _ld_ocram_bss_start = ADDR(.bss); _ld_ocram_bss_size = SIZEOF(.bss); _ld_heap_start = _ld_ocram_bss_start + _ld_ocram_bss_size; - _ld_heap_end = ORIGIN(OCRAM) + LENGTH(OCRAM); + _ld_ocram_start = ORIGIN(OCRAM); + _ld_ocram_end = ORIGIN(OCRAM) + LENGTH(OCRAM); + _ld_heap_end = _ld_ocram_end; .itcm : ALIGN(4) diff --git a/ports/mimxrt10xx/linking/flash/IS25WP128.ld b/ports/mimxrt10xx/linking/flash/IS25WP128.ld new file mode 100644 index 0000000000..205d9dd839 --- /dev/null +++ b/ports/mimxrt10xx/linking/flash/IS25WP128.ld @@ -0,0 +1 @@ +_ld_flash_size = 16M; diff --git a/ports/mimxrt10xx/mpconfigport.mk b/ports/mimxrt10xx/mpconfigport.mk index ae22cb69f4..b421b583be 100644 --- a/ports/mimxrt10xx/mpconfigport.mk +++ b/ports/mimxrt10xx/mpconfigport.mk @@ -11,13 +11,13 @@ CIRCUITPY_TUSB_MEM_ALIGN = 32 INTERNAL_FLASH_FILESYSTEM = 1 -CIRCUITPY_AUDIOBUSIO = 1 +CIRCUITPY_AUDIOBUSIO ?= 1 CIRCUITPY_AUDIOBUSIO_PDMIN = 0 -CIRCUITPY_AUDIOCORE = 1 +CIRCUITPY_AUDIOCORE ?= 1 CIRCUITPY_AUDIOIO = 0 CIRCUITPY_AUDIOMIXER = 1 CIRCUITPY_AUDIOMP3 = 1 -CIRCUITPY_AUDIOPWMIO = 1 +CIRCUITPY_AUDIOPWMIO ?= 1 CIRCUITPY_SYNTHIO_MAX_CHANNELS = 12 CIRCUITPY_BUSDEVICE = 1 CIRCUITPY_COUNTIO = 0 diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/clocks.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/clocks.c index e96b55f3e9..69ce673a0e 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/clocks.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/clocks.c @@ -35,6 +35,8 @@ #include "fsl_clock.h" #include "fsl_iomuxc.h" +#include "board.h" + #include "clocks.h" #define BOARD_XTAL0_CLK_HZ 24000000U /*!< Board xtal0 frequency in Hz */ diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.c index b67f7b1179..fd8ef69f7e 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.c @@ -5,6 +5,7 @@ * * Copyright (c) 2019 Lucian Copeland for Adafruit Industries * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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 @@ -65,7 +66,7 @@ const mcu_periph_obj_t mcu_spi_sck_list[4] = { PERIPH_PIN(2, 1, kIOMUXC_LPSPI2_SCK_SELECT_INPUT, 1, &pin_GPIO_SD_11), }; -const mcu_periph_obj_t mcu_spi_mosi_list[4] = { +const mcu_periph_obj_t mcu_spi_sdo_list[4] = { PERIPH_PIN(1, 0, kIOMUXC_LPSPI1_SDO_SELECT_INPUT, 0, &pin_GPIO_AD_04), PERIPH_PIN(1, 2, kIOMUXC_LPSPI1_SDO_SELECT_INPUT, 1, &pin_GPIO_SD_06), @@ -73,7 +74,7 @@ const mcu_periph_obj_t mcu_spi_mosi_list[4] = { PERIPH_PIN(2, 1, kIOMUXC_LPSPI2_SDO_SELECT_INPUT, 1, &pin_GPIO_SD_10), }; -const mcu_periph_obj_t mcu_spi_miso_list[4] = { +const mcu_periph_obj_t mcu_spi_sdi_list[4] = { PERIPH_PIN(1, 0, kIOMUXC_LPSPI1_SDI_SELECT_INPUT, 0, &pin_GPIO_AD_03), PERIPH_PIN(1, 2, kIOMUXC_LPSPI1_SDI_SELECT_INPUT, 1, &pin_GPIO_SD_05), @@ -120,7 +121,7 @@ const mcu_periph_obj_t mcu_uart_rts_list[4] = { PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_AD_13), - PERIPH_PIN(4, 3, 0, 0, &pin_GPIO_AD_13) + PERIPH_PIN(4, 3, 0, 0, &pin_GPIO_AD_13), }; const mcu_periph_obj_t mcu_uart_cts_list[4] = { @@ -133,67 +134,76 @@ const mcu_periph_obj_t mcu_uart_cts_list[4] = { PERIPH_PIN(4, 3, 0, 0, &pin_GPIO_AD_14), }; -const mcu_pwm_obj_t mcu_pwm_list[20] = { - PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_02_FLEXPWM1_PWM0_A, &pin_GPIO_02), - PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_SD_02_FLEXPWM1_PWM0_A, &pin_GPIO_SD_02), +I2S_Type *const mcu_i2s_banks[2] = { SAI1, SAI3 }; + +const mcu_periph_obj_t mcu_i2s_rx_data0_list[2] = { + PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_03), + + PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_SD_03), +}; + +const mcu_periph_obj_t mcu_i2s_rx_sync_list[2] = { + PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_02), + + PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_SD_04), +}; + +const mcu_periph_obj_t mcu_i2s_tx_bclk_list[2] = { + PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_06), + + PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_SD_01), +}; + +const mcu_periph_obj_t mcu_i2s_tx_data0_list[2] = { + PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_04), + + PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_SD_02), +}; + +const mcu_periph_obj_t mcu_i2s_tx_sync_list[2] = { + PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_07), + + PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_SD_00), +}; + +const mcu_periph_obj_t mcu_mqs_left_list[1] = { + PERIPH_PIN(3, 4, 0, 0, &pin_GPIO_AD_01), +}; + +const mcu_periph_obj_t mcu_mqs_right_list[1] = { + PERIPH_PIN(3, 4, 0, 0, &pin_GPIO_AD_02), +}; + +const mcu_pwm_obj_t mcu_pwm_list[20] = { + PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_SD_02_FLEXPWM1_PWM0_A, &pin_GPIO_SD_02), + PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_02_FLEXPWM1_PWM0_A, &pin_GPIO_02), - PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_01_FLEXPWM1_PWM0_B, &pin_GPIO_01), PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_SD_01_FLEXPWM1_PWM0_B, &pin_GPIO_SD_01), + PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_01_FLEXPWM1_PWM0_B, &pin_GPIO_01), PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmX, IOMUXC_GPIO_AD_12_FLEXPWM1_PWM0_X, &pin_GPIO_AD_12), - PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_04_FLEXPWM1_PWM1_A, &pin_GPIO_04), PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_SD_04_FLEXPWM1_PWM1_A, &pin_GPIO_SD_04), + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_04_FLEXPWM1_PWM1_A, &pin_GPIO_04), - PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_03_FLEXPWM1_PWM1_B, &pin_GPIO_03), PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_SD_03_FLEXPWM1_PWM1_B, &pin_GPIO_SD_03), + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_03_FLEXPWM1_PWM1_B, &pin_GPIO_03), PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmX, IOMUXC_GPIO_AD_11_FLEXPWM1_PWM1_X, &pin_GPIO_AD_11), - PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_06_FLEXPWM1_PWM2_A, &pin_GPIO_06), PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_AD_04_FLEXPWM1_PWM2_A, &pin_GPIO_AD_04), + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_06_FLEXPWM1_PWM2_A, &pin_GPIO_06), - PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_05_FLEXPWM1_PWM2_B, &pin_GPIO_05), PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_AD_03_FLEXPWM1_PWM2_B, &pin_GPIO_AD_03), + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_05_FLEXPWM1_PWM2_B, &pin_GPIO_05), PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmX, IOMUXC_GPIO_AD_10_FLEXPWM1_PWM2_X, &pin_GPIO_AD_10), - PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_08_FLEXPWM1_PWM3_A, &pin_GPIO_08), PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_AD_06_FLEXPWM1_PWM3_A, &pin_GPIO_AD_06), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_08_FLEXPWM1_PWM3_A, &pin_GPIO_08), - PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_07_FLEXPWM1_PWM3_B, &pin_GPIO_07), PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_AD_05_FLEXPWM1_PWM3_B, &pin_GPIO_AD_05), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_07_FLEXPWM1_PWM3_B, &pin_GPIO_07), PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmX, IOMUXC_GPIO_AD_09_FLEXPWM1_PWM3_X, &pin_GPIO_AD_09), }; - -const mcu_periph_obj_t mcu_sai_rx_bclk_list[] = { - PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_08), - PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_00), -}; -const mcu_periph_obj_t mcu_sai_rx_data0_list[] = { - PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_03), - PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_SD_03), -}; -const mcu_periph_obj_t mcu_sai_rx_sync_list[] = { - PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_02), - PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_SD_04), -}; -const mcu_periph_obj_t mcu_sai_tx_bclk_list[] = { - PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_06), - PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_SD_01), -}; -const mcu_periph_obj_t mcu_sai_tx_data0_list[] = { - PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_04), - PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_SD_02), -}; -const mcu_periph_obj_t mcu_sai_tx_sync_list[] = { - PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_07), - PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_SD_00), -}; -const mcu_periph_obj_t mcu_mqs_left_list[] = { - PERIPH_PIN(3, 4, 0, 0, &pin_GPIO_AD_01), -}; -const mcu_periph_obj_t mcu_mqs_right_list[] = { - PERIPH_PIN(3, 4, 0, 0, &pin_GPIO_AD_02), -}; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.h index 045e33ca0e..e03e2c7967 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.h @@ -3,7 +3,9 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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 @@ -24,37 +26,30 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_MIMXRT10XX_MIMXRT1011_PERIPHERALS_MIMXRT1011_PERIPH_H -#define MICROPY_INCLUDED_MIMXRT10XX_MIMXRT1011_PERIPHERALS_MIMXRT1011_PERIPH_H - +#pragma once extern LPI2C_Type *const 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]; extern LPSPI_Type *const 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]; +extern const mcu_periph_obj_t mcu_spi_sdo_list[4]; +extern const mcu_periph_obj_t mcu_spi_sdi_list[4]; extern LPUART_Type *const 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]; extern const mcu_periph_obj_t mcu_uart_rts_list[4]; extern const mcu_periph_obj_t mcu_uart_cts_list[4]; -extern const mcu_pwm_obj_t mcu_pwm_list[20]; - -extern const mcu_periph_obj_t mcu_sai_rx_bclk_list[2]; -extern const mcu_periph_obj_t mcu_sai_rx_data0_list[2]; -extern const mcu_periph_obj_t mcu_sai_rx_sync_list[2]; -extern const mcu_periph_obj_t mcu_sai_tx_bclk_list[2]; -extern const mcu_periph_obj_t mcu_sai_tx_data0_list[2]; -extern const mcu_periph_obj_t mcu_sai_tx_sync_list[2]; +extern I2S_Type *const mcu_i2s_banks[2]; +extern const mcu_periph_obj_t mcu_i2s_rx_data0_list[2]; +extern const mcu_periph_obj_t mcu_i2s_rx_sync_list[2]; +extern const mcu_periph_obj_t mcu_i2s_tx_bclk_list[2]; +extern const mcu_periph_obj_t mcu_i2s_tx_data0_list[2]; +extern const mcu_periph_obj_t mcu_i2s_tx_sync_list[2]; extern const mcu_periph_obj_t mcu_mqs_left_list[1]; extern const mcu_periph_obj_t mcu_mqs_right_list[1]; -#endif // MICROPY_INCLUDED_MIMXRT10XX_MIMXRT1011_PERIPHERALS_MIMXRT1011_PERIPH_H +extern const mcu_pwm_obj_t mcu_pwm_list[20]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pin_names.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pin_names.h new file mode 100644 index 0000000000..b197256a36 --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pin_names.h @@ -0,0 +1,78 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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. + */ + + +// define FORMAT_PIN(pin_name) and then include this file. + +FORMAT_PIN(GPIO_AD_14) +FORMAT_PIN(GPIO_AD_13) +FORMAT_PIN(GPIO_AD_12) +FORMAT_PIN(GPIO_AD_11) +FORMAT_PIN(GPIO_AD_10) +FORMAT_PIN(GPIO_AD_09) +FORMAT_PIN(GPIO_AD_08) +FORMAT_PIN(GPIO_AD_07) +FORMAT_PIN(GPIO_AD_06) +FORMAT_PIN(GPIO_AD_05) +FORMAT_PIN(GPIO_AD_04) +FORMAT_PIN(GPIO_AD_03) +FORMAT_PIN(GPIO_AD_02) +FORMAT_PIN(GPIO_AD_01) +FORMAT_PIN(GPIO_AD_00) + +FORMAT_PIN(GPIO_SD_13) +FORMAT_PIN(GPIO_SD_12) +FORMAT_PIN(GPIO_SD_11) +FORMAT_PIN(GPIO_SD_10) +FORMAT_PIN(GPIO_SD_09) +FORMAT_PIN(GPIO_SD_08) +FORMAT_PIN(GPIO_SD_07) +FORMAT_PIN(GPIO_SD_06) +FORMAT_PIN(GPIO_SD_05) +FORMAT_PIN(GPIO_SD_04) +FORMAT_PIN(GPIO_SD_03) +FORMAT_PIN(GPIO_SD_02) +FORMAT_PIN(GPIO_SD_01) +FORMAT_PIN(GPIO_SD_00) + +FORMAT_PIN(GPIO_13) +FORMAT_PIN(GPIO_12) +FORMAT_PIN(GPIO_11) +FORMAT_PIN(GPIO_10) +FORMAT_PIN(GPIO_09) +FORMAT_PIN(GPIO_08) +FORMAT_PIN(GPIO_07) +FORMAT_PIN(GPIO_06) +FORMAT_PIN(GPIO_05) +FORMAT_PIN(GPIO_04) +FORMAT_PIN(GPIO_03) +FORMAT_PIN(GPIO_02) +FORMAT_PIN(GPIO_01) +FORMAT_PIN(GPIO_00) +FORMAT_PIN(USB_OTG1_DN) +FORMAT_PIN(USB_OTG1_DP) diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pins.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pins.c index 492d1c6f08..a2b38a8a67 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pins.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pins.c @@ -5,6 +5,7 @@ * * Copyright (c) 2019 Lucian Copeland for Adafruit Industries * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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 @@ -29,48 +30,49 @@ #include "py/mphal.h" #include "mimxrt10xx/pins.h" -const mcu_pin_obj_t pin_GPIO_00 = PIN(GPIO1, 0, GPIO_00, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_01 = PIN(GPIO1, 1, GPIO_01, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_02 = PIN(GPIO1, 2, GPIO_02, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_03 = PIN(GPIO1, 3, GPIO_03, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_04 = PIN(GPIO1, 4, GPIO_04, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_05 = PIN(GPIO1, 5, GPIO_05, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_06 = PIN(GPIO1, 6, GPIO_06, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_07 = PIN(GPIO1, 7, GPIO_07, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_08 = PIN(GPIO1, 8, GPIO_08, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_09 = PIN(GPIO1, 9, GPIO_09, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_10 = PIN(GPIO1, 10, GPIO_10, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_11 = PIN(GPIO1, 11, GPIO_11, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_12 = PIN(GPIO1, 12, GPIO_12, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_13 = PIN(GPIO1, 13, GPIO_13, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_AD_00 = PIN(GPIO1, 14, GPIO_AD_00, ADC1, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_AD_01 = PIN(GPIO1, 15, GPIO_AD_01, ADC1, 1, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_AD_02 = PIN(GPIO1, 16, GPIO_AD_02, ADC1, 2, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_AD_03 = PIN(GPIO1, 17, GPIO_AD_03, ADC1, 3, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_AD_04 = PIN(GPIO1, 18, GPIO_AD_04, ADC1, 4, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_AD_05 = PIN(GPIO1, 19, GPIO_AD_05, ADC1, 5, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_AD_06 = PIN(GPIO1, 20, GPIO_AD_06, ADC1, 6, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_AD_07 = PIN(GPIO1, 21, GPIO_AD_07, ADC1, 7, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_AD_08 = PIN(GPIO1, 22, GPIO_AD_08, ADC1, 8, 0x00000007, 0x000070A0); -const mcu_pin_obj_t pin_GPIO_AD_09 = PIN(GPIO1, 23, GPIO_AD_09, ADC1, 9, 0x00000007, 0x000090B1); -const mcu_pin_obj_t pin_GPIO_AD_10 = PIN(GPIO1, 24, GPIO_AD_10, ADC1, 10, 0x00000007, 0x000070A0); -const mcu_pin_obj_t pin_GPIO_AD_11 = PIN(GPIO1, 25, GPIO_AD_11, ADC1, 11, 0x00000007, 0x000030A0); -const mcu_pin_obj_t pin_GPIO_AD_12 = PIN(GPIO1, 26, GPIO_AD_12, ADC1, 12, 0x00000007, 0x000030A0); -const mcu_pin_obj_t pin_GPIO_AD_13 = PIN(GPIO1, 27, GPIO_AD_13, ADC1, 13, 0x00000007, 0x000070A0); const mcu_pin_obj_t pin_GPIO_AD_14 = PIN(GPIO1, 28, GPIO_AD_14, ADC1, 14, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_SD_00 = PIN(GPIO2, 0, GPIO_SD_00, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_SD_01 = PIN(GPIO2, 1, GPIO_SD_01, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_SD_02 = PIN(GPIO2, 2, GPIO_SD_02, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_SD_03 = PIN(GPIO2, 3, GPIO_SD_03, NO_ADC, 0, 0x00000006, 0x000030A0); -const mcu_pin_obj_t pin_GPIO_SD_04 = PIN(GPIO2, 4, GPIO_SD_04, NO_ADC, 0, 0x00000006, 0x000030A0); -const mcu_pin_obj_t pin_GPIO_SD_05 = PIN(GPIO2, 5, GPIO_SD_05, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_SD_06 = PIN(GPIO2, 6, GPIO_SD_06, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_SD_07 = PIN(GPIO2, 7, GPIO_SD_07, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_SD_08 = PIN(GPIO2, 8, GPIO_SD_08, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_SD_09 = PIN(GPIO2, 9, GPIO_SD_09, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_SD_10 = PIN(GPIO2, 10, GPIO_SD_10, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_SD_11 = PIN(GPIO2, 11, GPIO_SD_11, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_SD_12 = PIN(GPIO2, 12, GPIO_SD_12, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_AD_13 = PIN(GPIO1, 27, GPIO_AD_13, ADC1, 13, 0x00000007, 0x000070A0); +const mcu_pin_obj_t pin_GPIO_AD_12 = PIN(GPIO1, 26, GPIO_AD_12, ADC1, 12, 0x00000007, 0x000030A0); +const mcu_pin_obj_t pin_GPIO_AD_11 = PIN(GPIO1, 25, GPIO_AD_11, ADC1, 11, 0x00000007, 0x000030A0); +const mcu_pin_obj_t pin_GPIO_AD_10 = PIN(GPIO1, 24, GPIO_AD_10, ADC1, 10, 0x00000007, 0x000070A0); +const mcu_pin_obj_t pin_GPIO_AD_09 = PIN(GPIO1, 23, GPIO_AD_09, ADC1, 9, 0x00000007, 0x000090B1); +const mcu_pin_obj_t pin_GPIO_AD_08 = PIN(GPIO1, 22, GPIO_AD_08, ADC1, 8, 0x00000007, 0x000070A0); +const mcu_pin_obj_t pin_GPIO_AD_07 = PIN(GPIO1, 21, GPIO_AD_07, ADC1, 7, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_AD_06 = PIN(GPIO1, 20, GPIO_AD_06, ADC1, 6, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_AD_05 = PIN(GPIO1, 19, GPIO_AD_05, ADC1, 5, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_AD_04 = PIN(GPIO1, 18, GPIO_AD_04, ADC1, 4, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_AD_03 = PIN(GPIO1, 17, GPIO_AD_03, ADC1, 3, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_AD_02 = PIN(GPIO1, 16, GPIO_AD_02, ADC1, 2, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_AD_01 = PIN(GPIO1, 15, GPIO_AD_01, ADC1, 1, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_AD_00 = PIN(GPIO1, 14, GPIO_AD_00, ADC1, 0, 0x00000005, 0x000010A0); const mcu_pin_obj_t pin_GPIO_SD_13 = PIN(GPIO2, 13, GPIO_SD_13, NO_ADC, 0, 0x00000005, 0x000010A0); -const mcu_pin_obj_t pin_GPIO_SD_14 = PIN(GPIO2, 14, GPIO_SD_14, NO_ADC, 0, 0x00000000, 0x000010A0); -// pin_GPIO_SD_14 isn't actually used as a pad but we include it anyway to make resetting easier +const mcu_pin_obj_t pin_GPIO_SD_12 = PIN(GPIO2, 12, GPIO_SD_12, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_SD_11 = PIN(GPIO2, 11, GPIO_SD_11, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_SD_10 = PIN(GPIO2, 10, GPIO_SD_10, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_SD_09 = PIN(GPIO2, 9, GPIO_SD_09, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_SD_08 = PIN(GPIO2, 8, GPIO_SD_08, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_SD_07 = PIN(GPIO2, 7, GPIO_SD_07, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_SD_06 = PIN(GPIO2, 6, GPIO_SD_06, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_SD_05 = PIN(GPIO2, 5, GPIO_SD_05, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_SD_04 = PIN(GPIO2, 4, GPIO_SD_04, NO_ADC, 0, 0x00000006, 0x000030A0); +const mcu_pin_obj_t pin_GPIO_SD_03 = PIN(GPIO2, 3, GPIO_SD_03, NO_ADC, 0, 0x00000006, 0x000030A0); +const mcu_pin_obj_t pin_GPIO_SD_02 = PIN(GPIO2, 2, GPIO_SD_02, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_SD_01 = PIN(GPIO2, 1, GPIO_SD_01, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_SD_00 = PIN(GPIO2, 0, GPIO_SD_00, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_13 = PIN(GPIO1, 13, GPIO_13, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_12 = PIN(GPIO1, 12, GPIO_12, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_11 = PIN(GPIO1, 11, GPIO_11, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_10 = PIN(GPIO1, 10, GPIO_10, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_09 = PIN(GPIO1, 9, GPIO_09, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_08 = PIN(GPIO1, 8, GPIO_08, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_07 = PIN(GPIO1, 7, GPIO_07, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_06 = PIN(GPIO1, 6, GPIO_06, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_05 = PIN(GPIO1, 5, GPIO_05, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_04 = PIN(GPIO1, 4, GPIO_04, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_03 = PIN(GPIO1, 3, GPIO_03, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_02 = PIN(GPIO1, 2, GPIO_02, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_01 = PIN(GPIO1, 1, GPIO_01, NO_ADC, 0, 0x00000005, 0x000010A0); +const mcu_pin_obj_t pin_GPIO_00 = PIN(GPIO1, 0, GPIO_00, NO_ADC, 0, 0x00000005, 0x000010A0); + +const mcu_pin_obj_t pin_USB_OTG1_DN = { { &mcu_pin_type }, }; +const mcu_pin_obj_t pin_USB_OTG1_DP = { { &mcu_pin_type }, }; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pins.h index 58ef7329e7..118eff9335 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pins.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pins.h @@ -3,7 +3,9 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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 @@ -24,56 +26,11 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_MIMXRT10XX_PERIPHERALS_MIMXRT1011_PINS_H -#define MICROPY_INCLUDED_MIMXRT10XX_PERIPHERALS_MIMXRT1011_PINS_H +#pragma once -extern const mcu_pin_obj_t pin_GPIO_00; -extern const mcu_pin_obj_t pin_GPIO_01; -extern const mcu_pin_obj_t pin_GPIO_02; -extern const mcu_pin_obj_t pin_GPIO_03; -extern const mcu_pin_obj_t pin_GPIO_04; -extern const mcu_pin_obj_t pin_GPIO_05; -extern const mcu_pin_obj_t pin_GPIO_06; -extern const mcu_pin_obj_t pin_GPIO_07; -extern const mcu_pin_obj_t pin_GPIO_08; -extern const mcu_pin_obj_t pin_GPIO_09; -extern const mcu_pin_obj_t pin_GPIO_10; -extern const mcu_pin_obj_t pin_GPIO_11; -extern const mcu_pin_obj_t pin_GPIO_12; -extern const mcu_pin_obj_t pin_GPIO_13; +#define FORMAT_PIN(pin_name) extern const mcu_pin_obj_t pin_##pin_name; +#include "pin_names.h" +#undef FORMAT_PIN -extern const mcu_pin_obj_t pin_GPIO_SD_00; -extern const mcu_pin_obj_t pin_GPIO_SD_01; -extern const mcu_pin_obj_t pin_GPIO_SD_02; -extern const mcu_pin_obj_t pin_GPIO_SD_03; -extern const mcu_pin_obj_t pin_GPIO_SD_04; -extern const mcu_pin_obj_t pin_GPIO_SD_05; -extern const mcu_pin_obj_t pin_GPIO_SD_06; -extern const mcu_pin_obj_t pin_GPIO_SD_07; -extern const mcu_pin_obj_t pin_GPIO_SD_08; -extern const mcu_pin_obj_t pin_GPIO_SD_09; -extern const mcu_pin_obj_t pin_GPIO_SD_10; -extern const mcu_pin_obj_t pin_GPIO_SD_11; -extern const mcu_pin_obj_t pin_GPIO_SD_12; -extern const mcu_pin_obj_t pin_GPIO_SD_13; -extern const mcu_pin_obj_t pin_GPIO_SD_14; - -extern const mcu_pin_obj_t pin_GPIO_AD_00; -extern const mcu_pin_obj_t pin_GPIO_AD_01; -extern const mcu_pin_obj_t pin_GPIO_AD_02; -extern const mcu_pin_obj_t pin_GPIO_AD_03; -extern const mcu_pin_obj_t pin_GPIO_AD_04; -extern const mcu_pin_obj_t pin_GPIO_AD_05; -extern const mcu_pin_obj_t pin_GPIO_AD_06; -extern const mcu_pin_obj_t pin_GPIO_AD_07; -extern const mcu_pin_obj_t pin_GPIO_AD_08; -extern const mcu_pin_obj_t pin_GPIO_AD_09; -extern const mcu_pin_obj_t pin_GPIO_AD_10; -extern const mcu_pin_obj_t pin_GPIO_AD_11; -extern const mcu_pin_obj_t pin_GPIO_AD_12; -extern const mcu_pin_obj_t pin_GPIO_AD_13; -extern const mcu_pin_obj_t pin_GPIO_AD_14; - -extern const mcu_pin_obj_t mcu_pin_list[IOMUXC_SW_PAD_CTL_PAD_COUNT]; - -#endif // MICROPY_INCLUDED_MIMXRT10XX_PERIPHERALS_MIMXRT1011_PINS_H +#define PIN_COUNT (IOMUXC_SW_PAD_CTL_PAD_COUNT + 2) +extern const mcu_pin_obj_t mcu_pin_list[PIN_COUNT]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/clocks.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/clocks.c new file mode 100644 index 0000000000..bef213a7c7 --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/clocks.c @@ -0,0 +1,315 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Artur Pacholec + * + * 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. + */ +/* + * Copyright 2019 NXP + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "mpconfigport.h" + +#include "fsl_clock.h" +#include "fsl_iomuxc.h" + +#include "supervisor/linker.h" + +#include "board.h" + +#include "clocks.h" + +#define BOARD_XTAL0_CLK_HZ 24000000U /*!< Board xtal0 frequency in Hz */ +#define BOARD_XTAL32K_CLK_HZ 32768U /*!< Board xtal32k frequency in Hz */ + +#define BOARD_BOOTCLOCKRUN_CORE_CLOCK 500000000U /*!< Core clock frequency: 500000000Hz */ + +/* Clock outputs (values are in Hz): */ +#define BOARD_BOOTCLOCKRUN_AHB_CLK_ROOT 500000000UL +#define BOARD_BOOTCLOCKRUN_CKIL_SYNC_CLK_ROOT 32768UL +#define BOARD_BOOTCLOCKRUN_CLKO1_CLK 0UL +#define BOARD_BOOTCLOCKRUN_CLKO2_CLK 0UL +#define BOARD_BOOTCLOCKRUN_CLK_1M 1000000UL +#define BOARD_BOOTCLOCKRUN_CLK_24M 24000000UL +#define BOARD_BOOTCLOCKRUN_ENET_500M_REF_CLK 500000000UL +#define BOARD_BOOTCLOCKRUN_FLEXIO1_CLK_ROOT 30000000UL +#define BOARD_BOOTCLOCKRUN_FLEXSPI_CLK_ROOT 196363636UL +#define BOARD_BOOTCLOCKRUN_GPT1_IPG_CLK_HIGHFREQ 62500000UL +#define BOARD_BOOTCLOCKRUN_GPT2_IPG_CLK_HIGHFREQ 62500000UL +#define BOARD_BOOTCLOCKRUN_IPG_CLK_ROOT 125000000UL +#define BOARD_BOOTCLOCKRUN_LPI2C_CLK_ROOT 60000000UL +#define BOARD_BOOTCLOCKRUN_LPSPI_CLK_ROOT 105600000UL +#define BOARD_BOOTCLOCKRUN_MQS_MCLK 63529411UL +#define BOARD_BOOTCLOCKRUN_PERCLK_CLK_ROOT 62500000UL +#define BOARD_BOOTCLOCKRUN_SAI1_CLK_ROOT 63529411UL +#define BOARD_BOOTCLOCKRUN_SAI1_MCLK1 63529411UL +#define BOARD_BOOTCLOCKRUN_SAI1_MCLK2 63529411UL +#define BOARD_BOOTCLOCKRUN_SAI1_MCLK3 30000000UL +#define BOARD_BOOTCLOCKRUN_SAI2_CLK_ROOT 63529411UL +#define BOARD_BOOTCLOCKRUN_SAI2_MCLK1 63529411UL +#define BOARD_BOOTCLOCKRUN_SAI2_MCLK2 0UL +#define BOARD_BOOTCLOCKRUN_SAI2_MCLK3 30000000UL +#define BOARD_BOOTCLOCKRUN_SAI3_CLK_ROOT 63529411UL +#define BOARD_BOOTCLOCKRUN_SAI3_MCLK1 63529411UL +#define BOARD_BOOTCLOCKRUN_SAI3_MCLK2 0UL +#define BOARD_BOOTCLOCKRUN_SAI3_MCLK3 30000000UL +#define BOARD_BOOTCLOCKRUN_SPDIF0_CLK_ROOT 30000000UL +#define BOARD_BOOTCLOCKRUN_SPDIF0_EXTCLK_OUT 0UL +#define BOARD_BOOTCLOCKRUN_TRACE_CLK_ROOT 117333333UL +#define BOARD_BOOTCLOCKRUN_UART_CLK_ROOT 80000000UL +#define BOARD_BOOTCLOCKRUN_USBPHY1_CLK 0UL + + +const clock_sys_pll_config_t sysPllConfig_BOARD_BootClockRUN = +{ + .loopDivider = 1, /* PLL loop divider, Fout = Fin * ( 20 + loopDivider*2 + numerator / denominator ) */ + .numerator = 0, /* 30 bit numerator of fractional loop divider */ + .denominator = 1, /* 30 bit denominator of fractional loop divider */ + .src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */ +}; +const clock_usb_pll_config_t usb1PllConfig_BOARD_BootClockRUN = +{ + .loopDivider = 0, /* PLL loop divider, Fout = Fin * 20 */ + .src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */ +}; +const clock_enet_pll_config_t enetPllConfig_BOARD_BootClockRUN = +{ + .enableClkOutput500M = true, /* Enable the PLL providing the ENET 500MHz reference clock */ + .src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */ +}; + +// Based on the hello_world example in the SDK +void clocks_init(void) { + /* Init RTC OSC clock frequency. */ + CLOCK_SetRtcXtalFreq(32768U); + /* Enable 1MHz clock output. */ + XTALOSC24M->OSC_CONFIG2 |= XTALOSC24M_OSC_CONFIG2_ENABLE_1M_MASK; + /* Use free 1MHz clock output. */ + XTALOSC24M->OSC_CONFIG2 &= ~XTALOSC24M_OSC_CONFIG2_MUX_1M_MASK; + /* Set XTAL 24MHz clock frequency. */ + CLOCK_SetXtalFreq(24000000U); + /* Enable XTAL 24MHz clock source. */ + CLOCK_InitExternalClk(0); + /* Enable internal RC. */ + CLOCK_InitRcOsc24M(); + /* Switch clock source to external OSC. */ + CLOCK_SwitchOsc(kCLOCK_XtalOsc); + /* Set Oscillator ready counter value. */ + CCM->CCR = (CCM->CCR & (~CCM_CCR_OSCNT_MASK)) | CCM_CCR_OSCNT(127); + /* Setting PeriphClk2Mux and PeriphMux to provide stable clock before PLLs are initialed */ + CLOCK_SetMux(kCLOCK_PeriphClk2Mux, 1); /* Set PERIPH_CLK2 MUX to OSC */ + CLOCK_SetMux(kCLOCK_PeriphMux, 1); /* Set PERIPH_CLK MUX to PERIPH_CLK2 */ + /* Setting the VDD_SOC to 1.25V. It is necessary to config AHB to 500Mhz. */ + DCDC->REG3 = (DCDC->REG3 & (~DCDC_REG3_TRG_MASK)) | DCDC_REG3_TRG(0x12); + /* Waiting for DCDC_STS_DC_OK bit is asserted */ + while (DCDC_REG0_STS_DC_OK_MASK != (DCDC_REG0_STS_DC_OK_MASK & DCDC->REG0)) { + } + /* Set AHB_PODF. */ + CLOCK_SetDiv(kCLOCK_AhbDiv, 0); + /* Disable IPG clock gate. */ + CLOCK_DisableClock(kCLOCK_Adc1); + CLOCK_DisableClock(kCLOCK_Xbar1); + CLOCK_DisableClock(kCLOCK_Xbar2); + /* Set IPG_PODF. */ + CLOCK_SetDiv(kCLOCK_IpgDiv, 3); + /* Set ARM_PODF. */ + CLOCK_SetDiv(kCLOCK_ArmDiv, 0); + /* Set PERIPH_CLK2_PODF. */ + CLOCK_SetDiv(kCLOCK_PeriphClk2Div, 0); + /* Disable PERCLK clock gate. */ + CLOCK_DisableClock(kCLOCK_Gpt1); + CLOCK_DisableClock(kCLOCK_Gpt1S); + CLOCK_DisableClock(kCLOCK_Gpt2); + CLOCK_DisableClock(kCLOCK_Gpt2S); + CLOCK_DisableClock(kCLOCK_Pit); + /* Set PERCLK_PODF. */ + CLOCK_SetDiv(kCLOCK_PerclkDiv, 1); + /* Set SEMC_PODF. */ + CLOCK_SetDiv(kCLOCK_SemcDiv, 1); + /* Set Semc alt clock source. */ + CLOCK_SetMux(kCLOCK_SemcAltMux, 0); + /* Set Semc clock source. */ + CLOCK_SetMux(kCLOCK_SemcMux, 0); + /* In SDK projects, external flash (configured by FLEXSPI) will be initialized by dcd. + * With this macro XIP_EXTERNAL_FLASH, usb1 pll (selected to be FLEXSPI clock source in SDK projects) will be left unchanged. + * Note: If another clock source is selected for FLEXSPI, user may want to avoid changing that clock as well.*/ + #if !(defined(XIP_EXTERNAL_FLASH) && (XIP_EXTERNAL_FLASH == 1)) + /* Disable Flexspi clock gate. */ + CLOCK_DisableClock(kCLOCK_FlexSpi); + /* Set FLEXSPI_PODF. */ + CLOCK_SetDiv(kCLOCK_FlexspiDiv, 1); + /* Set Flexspi clock source. */ + CLOCK_SetMux(kCLOCK_FlexspiMux, 3); + #endif + /* Disable LPSPI clock gate. */ + CLOCK_DisableClock(kCLOCK_Lpspi1); + CLOCK_DisableClock(kCLOCK_Lpspi2); + /* Set LPSPI_PODF. */ + CLOCK_SetDiv(kCLOCK_LpspiDiv, 4); + /* Set Lpspi clock source. */ + CLOCK_SetMux(kCLOCK_LpspiMux, 2); + /* Disable TRACE clock gate. */ + CLOCK_DisableClock(kCLOCK_Trace); + /* Set TRACE_PODF. */ + CLOCK_SetDiv(kCLOCK_TraceDiv, 2); + /* Set Trace clock source. */ + CLOCK_SetMux(kCLOCK_TraceMux, 2); + /* Disable SAI1 clock gate. */ + CLOCK_DisableClock(kCLOCK_Sai1); + /* Set SAI1_CLK_PRED. */ + CLOCK_SetDiv(kCLOCK_Sai1PreDiv, 3); + /* Set SAI1_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_Sai1Div, 1); + /* Set Sai1 clock source. */ + CLOCK_SetMux(kCLOCK_Sai1Mux, 0); + /* Disable SAI2 clock gate. */ + CLOCK_DisableClock(kCLOCK_Sai2); + /* Set SAI2_CLK_PRED. */ + CLOCK_SetDiv(kCLOCK_Sai2PreDiv, 3); + /* Set SAI2_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_Sai2Div, 1); + /* Set Sai2 clock source. */ + CLOCK_SetMux(kCLOCK_Sai2Mux, 0); + /* Disable SAI3 clock gate. */ + CLOCK_DisableClock(kCLOCK_Sai3); + /* Set SAI3_CLK_PRED. */ + CLOCK_SetDiv(kCLOCK_Sai3PreDiv, 3); + /* Set SAI3_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_Sai3Div, 1); + /* Set Sai3 clock source. */ + CLOCK_SetMux(kCLOCK_Sai3Mux, 0); + /* Disable Lpi2c clock gate. */ + CLOCK_DisableClock(kCLOCK_Lpi2c1); + CLOCK_DisableClock(kCLOCK_Lpi2c2); + /* Set LPI2C_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_Lpi2cDiv, 0); + /* Set Lpi2c clock source. */ + CLOCK_SetMux(kCLOCK_Lpi2cMux, 0); + /* Disable UART clock gate. */ + CLOCK_DisableClock(kCLOCK_Lpuart1); + CLOCK_DisableClock(kCLOCK_Lpuart2); + CLOCK_DisableClock(kCLOCK_Lpuart3); + CLOCK_DisableClock(kCLOCK_Lpuart4); + /* Set UART_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_UartDiv, 0); + /* Set Uart clock source. */ + CLOCK_SetMux(kCLOCK_UartMux, 0); + /* Disable SPDIF clock gate. */ + CLOCK_DisableClock(kCLOCK_Spdif); + /* Set SPDIF0_CLK_PRED. */ + CLOCK_SetDiv(kCLOCK_Spdif0PreDiv, 1); + /* Set SPDIF0_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_Spdif0Div, 7); + /* Set Spdif clock source. */ + CLOCK_SetMux(kCLOCK_SpdifMux, 3); + /* Disable Flexio1 clock gate. */ + CLOCK_DisableClock(kCLOCK_Flexio1); + /* Set FLEXIO1_CLK_PRED. */ + CLOCK_SetDiv(kCLOCK_Flexio1PreDiv, 1); + /* Set FLEXIO1_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_Flexio1Div, 7); + /* Set Flexio1 clock source. */ + CLOCK_SetMux(kCLOCK_Flexio1Mux, 3); + /* Set Pll3 sw clock source. */ + CLOCK_SetMux(kCLOCK_Pll3SwMux, 0); + /* Init System PLL. */ + CLOCK_InitSysPll(&sysPllConfig_BOARD_BootClockRUN); + /* Init System pfd0. */ + CLOCK_InitSysPfd(kCLOCK_Pfd0, 27); + /* Init System pfd1. */ + CLOCK_InitSysPfd(kCLOCK_Pfd1, 16); + /* Init System pfd2. */ + CLOCK_InitSysPfd(kCLOCK_Pfd2, 18); + /* Init System pfd3. */ + CLOCK_InitSysPfd(kCLOCK_Pfd3, 18); + /* In SDK projects, external flash (configured by FLEXSPI) will be initialized by dcd. + * With this macro XIP_EXTERNAL_FLASH, usb1 pll (selected to be FLEXSPI clock source in SDK projects) will be left unchanged. + * Note: If another clock source is selected for FLEXSPI, user may want to avoid changing that clock as well.*/ + #if !(defined(XIP_EXTERNAL_FLASH) && (XIP_EXTERNAL_FLASH == 1)) + /* Init Usb1 PLL. */ + CLOCK_InitUsb1Pll(&usb1PllConfig_BOARD_BootClockRUN); + /* Init Usb1 pfd0. */ + CLOCK_InitUsb1Pfd(kCLOCK_Pfd0, 22); + /* Init Usb1 pfd1. */ + CLOCK_InitUsb1Pfd(kCLOCK_Pfd1, 16); + /* Init Usb1 pfd2. */ + CLOCK_InitUsb1Pfd(kCLOCK_Pfd2, 17); + /* Init Usb1 pfd3. */ + CLOCK_InitUsb1Pfd(kCLOCK_Pfd3, 18); + /* Disable Usb1 PLL output for USBPHY1. */ + CCM_ANALOG->PLL_USB1 &= ~CCM_ANALOG_PLL_USB1_EN_USB_CLKS_MASK; + #endif + /* DeInit Audio PLL. */ + CLOCK_DeinitAudioPll(); + /* Bypass Audio PLL. */ + CLOCK_SetPllBypass(CCM_ANALOG, kCLOCK_PllAudio, 1); + /* Set divider for Audio PLL. */ + CCM_ANALOG->MISC2 &= ~CCM_ANALOG_MISC2_AUDIO_DIV_LSB_MASK; + CCM_ANALOG->MISC2 &= ~CCM_ANALOG_MISC2_AUDIO_DIV_MSB_MASK; + /* Enable Audio PLL output. */ + CCM_ANALOG->PLL_AUDIO |= CCM_ANALOG_PLL_AUDIO_ENABLE_MASK; + /* Init Enet PLL. */ + CLOCK_InitEnetPll(&enetPllConfig_BOARD_BootClockRUN); + /* Set preperiph clock source. */ + CLOCK_SetMux(kCLOCK_PrePeriphMux, 3); + /* Set periph clock source. */ + CLOCK_SetMux(kCLOCK_PeriphMux, 0); + /* Set periph clock2 clock source. */ + CLOCK_SetMux(kCLOCK_PeriphClk2Mux, 0); + /* Set per clock source. */ + CLOCK_SetMux(kCLOCK_PerclkMux, 0); + /* Set clock out1 divider. */ + CCM->CCOSR = (CCM->CCOSR & (~CCM_CCOSR_CLKO1_DIV_MASK)) | CCM_CCOSR_CLKO1_DIV(0); + /* Set clock out1 source. */ + CCM->CCOSR = (CCM->CCOSR & (~CCM_CCOSR_CLKO1_SEL_MASK)) | CCM_CCOSR_CLKO1_SEL(1); + /* Set clock out2 divider. */ + CCM->CCOSR = (CCM->CCOSR & (~CCM_CCOSR_CLKO2_DIV_MASK)) | CCM_CCOSR_CLKO2_DIV(0); + /* Set clock out2 source. */ + CCM->CCOSR = (CCM->CCOSR & (~CCM_CCOSR_CLKO2_SEL_MASK)) | CCM_CCOSR_CLKO2_SEL(6); + /* Set clock out1 drives clock out1. */ + CCM->CCOSR &= ~CCM_CCOSR_CLK_OUT_SEL_MASK; + /* Disable clock out1. */ + CCM->CCOSR &= ~CCM_CCOSR_CLKO1_EN_MASK; + /* Disable clock out2. */ + CCM->CCOSR &= ~CCM_CCOSR_CLKO2_EN_MASK; + /* Set SAI1 MCLK1 clock source. */ + IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI1MClk1Sel, 0); + /* Set SAI1 MCLK2 clock source. */ + IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI1MClk2Sel, 0); + /* Set SAI1 MCLK3 clock source. */ + IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI1MClk3Sel, 0); + /* Set SAI2 MCLK3 clock source. */ + IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI2MClk3Sel, 0); + /* Set SAI3 MCLK3 clock source. */ + IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI3MClk3Sel, 0); + /* Set MQS configuration. */ + IOMUXC_MQSConfig(IOMUXC_GPR,kIOMUXC_MqsPwmOverSampleRate32, 0); + /* Set GPT1 High frequency reference clock source. */ + IOMUXC_GPR->GPR5 &= ~IOMUXC_GPR_GPR5_VREF_1M_CLK_GPT1_MASK; + /* Set GPT2 High frequency reference clock source. */ + IOMUXC_GPR->GPR5 &= ~IOMUXC_GPR_GPR5_VREF_1M_CLK_GPT2_MASK; + /* Set SystemCoreClock variable. */ + SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK; +} diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.c new file mode 100644 index 0000000000..9c56c47dc0 --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.c @@ -0,0 +1,184 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "py/obj.h" +#include "py/mphal.h" +#include "mimxrt10xx/periph.h" + +LPI2C_Type *const mcu_i2c_banks[2] = { LPI2C1, LPI2C2 }; + +const mcu_periph_obj_t mcu_i2c_sda_list[2] = { + PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_AD_B1_15), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_18), +}; + +const mcu_periph_obj_t mcu_i2c_scl_list[2] = { + PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_AD_B1_14), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_19), +}; + +LPSPI_Type *const mcu_spi_banks[2] = { LPSPI1, LPSPI2 }; + +const mcu_periph_obj_t mcu_spi_sck_list[2] = { + PERIPH_PIN(1, 1, 0, 0, &pin_GPIO_AD_B0_10), + + PERIPH_PIN(2, 4, 0, 0, &pin_GPIO_SD_B1_07), +}; + +const mcu_periph_obj_t mcu_spi_sdo_list[2] = { + PERIPH_PIN(1, 1, 0, 0, &pin_GPIO_AD_B0_12), + + PERIPH_PIN(2, 4, 0, 0, &pin_GPIO_SD_B1_08), +}; + +const mcu_periph_obj_t mcu_spi_sdi_list[2] = { + PERIPH_PIN(1, 1, 0, 0, &pin_GPIO_AD_B0_13), + + PERIPH_PIN(2, 4, 0, 0, &pin_GPIO_SD_B1_09), +}; + +LPUART_Type *const mcu_uart_banks[4] = { LPUART1, LPUART2, LPUART3, LPUART4 }; + +const mcu_periph_obj_t mcu_uart_rx_list[6] = { + PERIPH_PIN(1, 2, 0, 0, &pin_GPIO_AD_B0_07), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_23), + + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_EMC_07), + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_AD_B0_15), + + PERIPH_PIN(4, 2, 0, 0, &pin_GPIO_EMC_33), + PERIPH_PIN(4, 2, 0, 0, &pin_GPIO_AD_B1_11), +}; + +const mcu_periph_obj_t mcu_uart_tx_list[6] = { + PERIPH_PIN(1, 2, 0, 0, &pin_GPIO_AD_B0_06), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_22), + + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_EMC_06), + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_AD_B0_14), + + PERIPH_PIN(4, 2, 0, 0, &pin_GPIO_EMC_32), + PERIPH_PIN(4, 2, 0, 0, &pin_GPIO_AD_B1_10), +}; + +const mcu_periph_obj_t mcu_uart_rts_list[3] = { + PERIPH_PIN(1, 2, 0, 0, &pin_GPIO_AD_B0_09), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_21), + + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_AD_B0_13), +}; + +const mcu_periph_obj_t mcu_uart_cts_list[3] = { + PERIPH_PIN(1, 2, 0, 0, &pin_GPIO_AD_B0_08), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_20), + + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_AD_B0_12), +}; + +I2S_Type *const mcu_i2s_banks[3] = { SAI1, SAI2, SAI3 }; + +const mcu_periph_obj_t mcu_i2s_rx_data0_list[3] = { + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_EMC_21), + + PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_EMC_08), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_SD_B1_11), +}; + +const mcu_periph_obj_t mcu_i2s_rx_sync_list[3] = { + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_EMC_18), + + PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_EMC_07), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_SD_B1_10), +}; + +const mcu_periph_obj_t mcu_i2s_tx_bclk_list[4] = { + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_EMC_26), + + PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_EMC_04), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_33), + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_SD_B1_06), +}; + +const mcu_periph_obj_t mcu_i2s_tx_data0_list[4] = { + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_EMC_25), + + PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_EMC_06), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_32), + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_SD_B1_08), +}; + +const mcu_periph_obj_t mcu_i2s_tx_sync_list[4] = { + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_EMC_27), + + PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_EMC_05), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_34), + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_SD_B1_07), +}; + +const mcu_periph_obj_t mcu_mqs_left_list[2] = { + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_EMC_17), + PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_AD_B0_07), +}; + +const mcu_periph_obj_t mcu_mqs_right_list[2] = { + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_EMC_16), + PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_AD_B0_06), +}; + +const mcu_pwm_obj_t mcu_pwm_list[12] = { + PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_EMC_26_FLEXPWM1_PWMA00, &pin_GPIO_EMC_26), + + PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_EMC_27_FLEXPWM1_PWMB00, &pin_GPIO_EMC_27), + + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_EMC_24_FLEXPWM1_PWMA01, &pin_GPIO_EMC_24), + + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_EMC_25_FLEXPWM1_PWMB01, &pin_GPIO_EMC_25), + + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_EMC_22_FLEXPWM1_PWMA02, &pin_GPIO_EMC_22), + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_AD_B1_10_FLEXPWM1_PWMA02, &pin_GPIO_AD_B1_10), + + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_EMC_23_FLEXPWM1_PWMB02, &pin_GPIO_EMC_23), + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_AD_B1_11_FLEXPWM1_PWMB02, &pin_GPIO_AD_B1_11), + + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_20_FLEXPWM1_PWMA03, &pin_GPIO_EMC_20), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_AD_B1_12_FLEXPWM1_PWMA03, &pin_GPIO_AD_B1_12), + + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_21_FLEXPWM1_PWMB03, &pin_GPIO_EMC_21), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_AD_B1_13_FLEXPWM1_PWMB03, &pin_GPIO_AD_B1_13), +}; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.h new file mode 100644 index 0000000000..af53706d6f --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.h @@ -0,0 +1,55 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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. + */ + +#pragma once +extern LPI2C_Type *const mcu_i2c_banks[2]; +extern const mcu_periph_obj_t mcu_i2c_sda_list[2]; +extern const mcu_periph_obj_t mcu_i2c_scl_list[2]; + +extern LPSPI_Type *const mcu_spi_banks[2]; +extern const mcu_periph_obj_t mcu_spi_sck_list[2]; +extern const mcu_periph_obj_t mcu_spi_sdo_list[2]; +extern const mcu_periph_obj_t mcu_spi_sdi_list[2]; + +extern LPUART_Type *const mcu_uart_banks[4]; +extern const mcu_periph_obj_t mcu_uart_rx_list[6]; +extern const mcu_periph_obj_t mcu_uart_tx_list[6]; +extern const mcu_periph_obj_t mcu_uart_rts_list[3]; +extern const mcu_periph_obj_t mcu_uart_cts_list[3]; + +extern I2S_Type *const mcu_i2s_banks[3]; +extern const mcu_periph_obj_t mcu_i2s_rx_data0_list[3]; +extern const mcu_periph_obj_t mcu_i2s_rx_sync_list[3]; +extern const mcu_periph_obj_t mcu_i2s_tx_bclk_list[4]; +extern const mcu_periph_obj_t mcu_i2s_tx_data0_list[4]; +extern const mcu_periph_obj_t mcu_i2s_tx_sync_list[4]; + +extern const mcu_periph_obj_t mcu_mqs_left_list[2]; +extern const mcu_periph_obj_t mcu_mqs_right_list[2]; + +extern const mcu_pwm_obj_t mcu_pwm_list[12]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pin_names.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pin_names.h new file mode 100644 index 0000000000..0416e2ee65 --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pin_names.h @@ -0,0 +1,92 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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. + */ + + +// define FORMAT_PIN(pin_name) and then include this file. + +FORMAT_PIN(GPIO_EMC_04) +FORMAT_PIN(GPIO_EMC_05) +FORMAT_PIN(GPIO_EMC_06) +FORMAT_PIN(GPIO_EMC_07) +FORMAT_PIN(GPIO_EMC_08) +FORMAT_PIN(GPIO_EMC_09) +FORMAT_PIN(GPIO_EMC_16) +FORMAT_PIN(GPIO_EMC_17) +FORMAT_PIN(GPIO_EMC_18) +FORMAT_PIN(GPIO_EMC_19) +FORMAT_PIN(GPIO_EMC_20) +FORMAT_PIN(GPIO_EMC_21) +FORMAT_PIN(GPIO_EMC_22) +FORMAT_PIN(GPIO_EMC_23) +FORMAT_PIN(GPIO_EMC_24) +FORMAT_PIN(GPIO_EMC_25) +FORMAT_PIN(GPIO_EMC_26) +FORMAT_PIN(GPIO_EMC_27) +FORMAT_PIN(GPIO_EMC_32) +FORMAT_PIN(GPIO_EMC_33) +FORMAT_PIN(GPIO_EMC_34) +FORMAT_PIN(GPIO_EMC_35) + +FORMAT_PIN(GPIO_AD_B0_00) +FORMAT_PIN(GPIO_AD_B0_01) +FORMAT_PIN(GPIO_AD_B0_02) +FORMAT_PIN(GPIO_AD_B0_03) +FORMAT_PIN(GPIO_AD_B0_04) +FORMAT_PIN(GPIO_AD_B0_05) +FORMAT_PIN(GPIO_AD_B0_06) +FORMAT_PIN(GPIO_AD_B0_07) +FORMAT_PIN(GPIO_AD_B0_08) +FORMAT_PIN(GPIO_AD_B0_09) +FORMAT_PIN(GPIO_AD_B0_10) +FORMAT_PIN(GPIO_AD_B0_11) +FORMAT_PIN(GPIO_AD_B0_12) +FORMAT_PIN(GPIO_AD_B0_13) +FORMAT_PIN(GPIO_AD_B0_14) +FORMAT_PIN(GPIO_AD_B0_15) + +FORMAT_PIN(GPIO_AD_B1_10) +FORMAT_PIN(GPIO_AD_B1_11) +FORMAT_PIN(GPIO_AD_B1_12) +FORMAT_PIN(GPIO_AD_B1_13) +FORMAT_PIN(GPIO_AD_B1_14) +FORMAT_PIN(GPIO_AD_B1_15) + +FORMAT_PIN(GPIO_SD_B1_00) +FORMAT_PIN(GPIO_SD_B1_01) +FORMAT_PIN(GPIO_SD_B1_02) +FORMAT_PIN(GPIO_SD_B1_03) +FORMAT_PIN(GPIO_SD_B1_04) +FORMAT_PIN(GPIO_SD_B1_05) +FORMAT_PIN(GPIO_SD_B1_06) +FORMAT_PIN(GPIO_SD_B1_07) +FORMAT_PIN(GPIO_SD_B1_08) +FORMAT_PIN(GPIO_SD_B1_09) +FORMAT_PIN(GPIO_SD_B1_10) +FORMAT_PIN(GPIO_SD_B1_11) +FORMAT_PIN(USB_OTG1_DN) +FORMAT_PIN(USB_OTG1_DP) diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pins.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pins.c new file mode 100644 index 0000000000..efa7abcedf --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pins.c @@ -0,0 +1,91 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "py/obj.h" +#include "py/mphal.h" +#include "mimxrt10xx/pins.h" + +const mcu_pin_obj_t pin_GPIO_EMC_04 = PIN(GPIO2, 4, GPIO_EMC_04, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_05 = PIN(GPIO2, 5, GPIO_EMC_05, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_06 = PIN(GPIO2, 6, GPIO_EMC_06, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_07 = PIN(GPIO2, 7, GPIO_EMC_07, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_08 = PIN(GPIO2, 8, GPIO_EMC_08, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_09 = PIN(GPIO2, 9, GPIO_EMC_09, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_16 = PIN(GPIO2, 16, GPIO_EMC_16, NO_ADC, 0, 0x00000006, 0x000030B0); +const mcu_pin_obj_t pin_GPIO_EMC_17 = PIN(GPIO2, 17, GPIO_EMC_17, NO_ADC, 0, 0x00000006, 0x000030B0); +const mcu_pin_obj_t pin_GPIO_EMC_18 = PIN(GPIO2, 18, GPIO_EMC_18, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_19 = PIN(GPIO2, 19, GPIO_EMC_19, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_20 = PIN(GPIO2, 20, GPIO_EMC_20, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_21 = PIN(GPIO2, 21, GPIO_EMC_21, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_22 = PIN(GPIO2, 22, GPIO_EMC_22, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_23 = PIN(GPIO2, 23, GPIO_EMC_23, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_24 = PIN(GPIO2, 24, GPIO_EMC_24, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_25 = PIN(GPIO2, 25, GPIO_EMC_25, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_26 = PIN(GPIO2, 26, GPIO_EMC_26, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_27 = PIN(GPIO2, 27, GPIO_EMC_27, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_32 = PIN(GPIO3, 0, GPIO_EMC_32, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_33 = PIN(GPIO3, 1, GPIO_EMC_33, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_34 = PIN(GPIO3, 2, GPIO_EMC_34, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_35 = PIN(GPIO3, 3, GPIO_EMC_35, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_00 = PIN(GPIO1, 0, GPIO_AD_B0_00, NO_ADC, 0, 0x00000000, 0x000070A0); +const mcu_pin_obj_t pin_GPIO_AD_B0_01 = PIN(GPIO1, 1, GPIO_AD_B0_01, NO_ADC, 0, 0x00000000, 0x000030A0); +const mcu_pin_obj_t pin_GPIO_AD_B0_02 = PIN(GPIO1, 2, GPIO_AD_B0_02, NO_ADC, 0, 0x00000000, 0x000030A0); +const mcu_pin_obj_t pin_GPIO_AD_B0_03 = PIN(GPIO1, 3, GPIO_AD_B0_03, NO_ADC, 0, 0x00000000, 0x000070A0); +const mcu_pin_obj_t pin_GPIO_AD_B0_04 = PIN(GPIO1, 4, GPIO_AD_B0_04, NO_ADC, 0, 0x00000000, 0x000090B1); +const mcu_pin_obj_t pin_GPIO_AD_B0_05 = PIN(GPIO1, 5, GPIO_AD_B0_05, NO_ADC, 0, 0x00000000, 0x000070A0); +const mcu_pin_obj_t pin_GPIO_AD_B0_06 = PIN(GPIO1, 6, GPIO_AD_B0_06, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_07 = PIN(GPIO1, 7, GPIO_AD_B0_07, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_08 = PIN(GPIO1, 8, GPIO_AD_B0_08, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_09 = PIN(GPIO1, 9, GPIO_AD_B0_09, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_10 = PIN(GPIO1, 10, GPIO_AD_B0_10, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_11 = PIN(GPIO1, 11, GPIO_AD_B0_11, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_12 = PIN(GPIO1, 12, GPIO_AD_B0_12, ADC1, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_13 = PIN(GPIO1, 13, GPIO_AD_B0_13, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_14 = PIN(GPIO1, 14, GPIO_AD_B0_14, ADC1, 1, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_15 = PIN(GPIO1, 15, GPIO_AD_B0_15, ADC1, 2, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_10 = PIN(GPIO1, 26, GPIO_AD_B1_10, ADC1, 10, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_11 = PIN(GPIO1, 27, GPIO_AD_B1_11, ADC1, 11, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_12 = PIN(GPIO1, 28, GPIO_AD_B1_12, ADC1, 12, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_13 = PIN(GPIO1, 29, GPIO_AD_B1_13, ADC1, 13, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_14 = PIN(GPIO1, 30, GPIO_AD_B1_14, ADC1, 14, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_15 = PIN(GPIO1, 31, GPIO_AD_B1_15, ADC1, 15, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_00 = PIN(GPIO3, 20, GPIO_SD_B1_00, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_01 = PIN(GPIO3, 21, GPIO_SD_B1_01, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_02 = PIN(GPIO3, 22, GPIO_SD_B1_02, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_03 = PIN(GPIO3, 23, GPIO_SD_B1_03, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_04 = PIN(GPIO3, 24, GPIO_SD_B1_04, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_05 = PIN(GPIO3, 25, GPIO_SD_B1_05, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_06 = PIN(GPIO3, 26, GPIO_SD_B1_06, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_07 = PIN(GPIO3, 27, GPIO_SD_B1_07, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_08 = PIN(GPIO3, 28, GPIO_SD_B1_08, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_09 = PIN(GPIO3, 29, GPIO_SD_B1_09, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_10 = PIN(GPIO3, 30, GPIO_SD_B1_10, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_11 = PIN(GPIO3, 31, GPIO_SD_B1_11, NO_ADC, 0, 0x00000005, 0x000010B0); + +const mcu_pin_obj_t pin_USB_OTG1_DN = { { &mcu_pin_type }, }; +const mcu_pin_obj_t pin_USB_OTG1_DP = { { &mcu_pin_type }, }; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pins.h new file mode 100644 index 0000000000..118eff9335 --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pins.h @@ -0,0 +1,36 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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. + */ + +#pragma once + +#define FORMAT_PIN(pin_name) extern const mcu_pin_obj_t pin_##pin_name; +#include "pin_names.h" +#undef FORMAT_PIN + +#define PIN_COUNT (IOMUXC_SW_PAD_CTL_PAD_COUNT + 2) +extern const mcu_pin_obj_t mcu_pin_list[PIN_COUNT]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/clocks.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/clocks.c index 198f85110e..eab7f4eacc 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/clocks.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/clocks.c @@ -36,6 +36,8 @@ #include "fsl_clock.h" #include "fsl_iomuxc.h" +#include "board.h" + #include "clocks.h" // These values are pulled from the SDK's devices/MIMXRT1021/project_template/clock_config.* files. diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.c index 59bd3cc105..8615e6cfc5 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.c @@ -5,7 +5,7 @@ * * Copyright (c) 2019 Lucian Copeland for Adafruit Industries * Copyright (c) 2019 Artur Pacholec - * Copyright (c) 2020 Scott Shawcroft + * Copyright (c) 2023 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 @@ -70,13 +70,13 @@ const mcu_periph_obj_t mcu_spi_sck_list[8] = { PERIPH_PIN(2, 4, kIOMUXC_LPSPI2_SCK_SELECT_INPUT, 1, &pin_GPIO_EMC_10), PERIPH_PIN(2, 4, kIOMUXC_LPSPI2_SCK_SELECT_INPUT, 2, &pin_GPIO_SD_B1_07), - PERIPH_PIN(3, 2, kIOMUXC_LPSPI2_SCK_SELECT_INPUT, 0, &pin_GPIO_AD_B1_12), + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_AD_B1_12), - PERIPH_PIN(4, 2, kIOMUXC_LPSPI2_SCK_SELECT_INPUT, 0, &pin_GPIO_AD_B1_02), - PERIPH_PIN(4, 4, kIOMUXC_LPSPI2_SCK_SELECT_INPUT, 1, &pin_GPIO_EMC_32), + PERIPH_PIN(4, 2, kIOMUXC_LPSPI4_SCK_SELECT_INPUT, 0, &pin_GPIO_AD_B1_02), + PERIPH_PIN(4, 4, kIOMUXC_LPSPI4_SCK_SELECT_INPUT, 1, &pin_GPIO_EMC_32), }; -const mcu_periph_obj_t mcu_spi_mosi_list[8] = { +const mcu_periph_obj_t mcu_spi_sdo_list[8] = { PERIPH_PIN(1, 4, kIOMUXC_LPSPI1_SDO_SELECT_INPUT, 0, &pin_GPIO_SD_B0_04), PERIPH_PIN(1, 1, kIOMUXC_LPSPI1_SDO_SELECT_INPUT, 1, &pin_GPIO_AD_B0_12), @@ -84,13 +84,13 @@ const mcu_periph_obj_t mcu_spi_mosi_list[8] = { PERIPH_PIN(2, 4, kIOMUXC_LPSPI2_SDO_SELECT_INPUT, 1, &pin_GPIO_EMC_12), PERIPH_PIN(2, 4, kIOMUXC_LPSPI2_SDO_SELECT_INPUT, 2, &pin_GPIO_SD_B1_08), - PERIPH_PIN(3, 2, kIOMUXC_LPSPI2_SDO_SELECT_INPUT, 0, &pin_GPIO_AD_B1_14), + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_AD_B1_14), - PERIPH_PIN(4, 2, kIOMUXC_LPSPI2_SDO_SELECT_INPUT, 0, &pin_GPIO_AD_B1_04), - PERIPH_PIN(4, 4, kIOMUXC_LPSPI2_SDO_SELECT_INPUT, 1, &pin_GPIO_EMC_34), + PERIPH_PIN(4, 2, kIOMUXC_LPSPI4_SDO_SELECT_INPUT, 0, &pin_GPIO_AD_B1_04), + PERIPH_PIN(4, 4, kIOMUXC_LPSPI4_SDO_SELECT_INPUT, 1, &pin_GPIO_EMC_34), }; -const mcu_periph_obj_t mcu_spi_miso_list[8] = { +const mcu_periph_obj_t mcu_spi_sdi_list[8] = { PERIPH_PIN(1, 4, kIOMUXC_LPSPI1_SDI_SELECT_INPUT, 0, &pin_GPIO_SD_B0_05), PERIPH_PIN(1, 1, kIOMUXC_LPSPI1_SDI_SELECT_INPUT, 1, &pin_GPIO_AD_B0_13), @@ -98,10 +98,10 @@ const mcu_periph_obj_t mcu_spi_miso_list[8] = { PERIPH_PIN(2, 4, kIOMUXC_LPSPI2_SDI_SELECT_INPUT, 1, &pin_GPIO_EMC_13), PERIPH_PIN(2, 4, kIOMUXC_LPSPI2_SDI_SELECT_INPUT, 2, &pin_GPIO_SD_B1_09), - PERIPH_PIN(3, 2, kIOMUXC_LPSPI2_SDI_SELECT_INPUT, 0, &pin_GPIO_AD_B1_15), + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_AD_B1_15), - PERIPH_PIN(4, 2, kIOMUXC_LPSPI2_SDI_SELECT_INPUT, 0, &pin_GPIO_AD_B1_05), - PERIPH_PIN(4, 4, kIOMUXC_LPSPI2_SDI_SELECT_INPUT, 1, &pin_GPIO_EMC_35), + PERIPH_PIN(4, 2, kIOMUXC_LPSPI4_SDI_SELECT_INPUT, 0, &pin_GPIO_AD_B1_05), + PERIPH_PIN(4, 4, kIOMUXC_LPSPI4_SDI_SELECT_INPUT, 1, &pin_GPIO_EMC_35), }; LPUART_Type *const mcu_uart_banks[8] = { LPUART1, LPUART2, LPUART3, LPUART4, LPUART5, LPUART6, LPUART7, LPUART8 }; @@ -162,18 +162,18 @@ const mcu_periph_obj_t mcu_uart_rts_list[10] = { PERIPH_PIN(1, 2, 0, 0, &pin_GPIO_AD_B0_09), PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_21), - PERIPH_PIN(2, 2, 0, 1, &pin_GPIO_AD_B1_07), + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_AD_B1_07), - PERIPH_PIN(3, 2, 0, 1, &pin_GPIO_AD_B0_13), + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_AD_B0_13), PERIPH_PIN(4, 2, 0, 0, &pin_GPIO_EMC_01), - PERIPH_PIN(4, 2, 0, 1, &pin_GPIO_EMC_31), + PERIPH_PIN(4, 2, 0, 0, &pin_GPIO_EMC_31), PERIPH_PIN(5, 2, 0, 0, &pin_GPIO_EMC_37), PERIPH_PIN(6, 2, 0, 0, &pin_GPIO_EMC_15), - PERIPH_PIN(7, 2, 0, 1, &pin_GPIO_SD_B0_03), + PERIPH_PIN(7, 2, 0, 0, &pin_GPIO_SD_B0_03), PERIPH_PIN(8, 2, 0, 0, &pin_GPIO_EMC_25), }; @@ -184,10 +184,10 @@ const mcu_periph_obj_t mcu_uart_cts_list[10] = { PERIPH_PIN(2, 2, kIOMUXC_LPUART2_CTS_B_SELECT_INPUT, 0, &pin_GPIO_AD_B1_06), PERIPH_PIN(2, 2, kIOMUXC_LPUART2_CTS_B_SELECT_INPUT, 1, &pin_GPIO_EMC_20), - PERIPH_PIN(3, 2, 0, 1, &pin_GPIO_AD_B0_12), + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_AD_B0_12), PERIPH_PIN(4, 2, kIOMUXC_LPUART4_CTS_B_SELECT_INPUT, 0, &pin_GPIO_EMC_00), - PERIPH_PIN(4, 2, kIOMUXC_LPUART4_CTS_B_SELECT_INPUT, 0, &pin_GPIO_EMC_30), + PERIPH_PIN(4, 2, kIOMUXC_LPUART4_CTS_B_SELECT_INPUT, 1, &pin_GPIO_EMC_30), PERIPH_PIN(5, 2, 0, 0, &pin_GPIO_EMC_36), @@ -198,126 +198,142 @@ const mcu_periph_obj_t mcu_uart_cts_list[10] = { PERIPH_PIN(8, 2, 0, 0, &pin_GPIO_EMC_24), }; -const mcu_pwm_obj_t mcu_pwm_list[39] = { +I2S_Type *const mcu_i2s_banks[3] = { SAI1, SAI2, SAI3 }; + +const mcu_periph_obj_t mcu_i2s_rx_data0_list[7] = { + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_DATA0_SELECT_INPUT, 0, &pin_GPIO_EMC_13), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_DATA0_SELECT_INPUT, 1, &pin_GPIO_AD_B1_05), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_DATA0_SELECT_INPUT, 2, &pin_GPIO_EMC_21), + + PERIPH_PIN(2, 3, kIOMUXC_SAI2_RX_DATA0_SELECT_INPUT, 0, &pin_GPIO_SD_B0_03), + PERIPH_PIN(2, 3, kIOMUXC_SAI2_RX_DATA0_SELECT_INPUT, 1, &pin_GPIO_EMC_08), + + PERIPH_PIN(3, 3, kIOMUXC_SAI3_RX_DATA0_SELECT_INPUT, 0, &pin_GPIO_SD_B1_11), + PERIPH_PIN(3, 3, kIOMUXC_SAI3_RX_DATA0_SELECT_INPUT, 1, &pin_GPIO_EMC_31), +}; + +const mcu_periph_obj_t mcu_i2s_rx_sync_list[7] = { + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_SYNC_SELECT_INPUT, 0, &pin_GPIO_AD_B1_04), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_SYNC_SELECT_INPUT, 1, &pin_GPIO_EMC_15), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_SYNC_SELECT_INPUT, 2, &pin_GPIO_EMC_18), + + PERIPH_PIN(2, 3, kIOMUXC_SAI2_RX_SYNC_SELECT_INPUT, 0, &pin_GPIO_SD_B0_01), + PERIPH_PIN(2, 3, kIOMUXC_SAI2_RX_SYNC_SELECT_INPUT, 1, &pin_GPIO_EMC_07), + + PERIPH_PIN(3, 3, kIOMUXC_SAI3_RX_SYNC_SELECT_INPUT, 0, &pin_GPIO_SD_B1_10), + PERIPH_PIN(3, 3, kIOMUXC_SAI3_RX_SYNC_SELECT_INPUT, 1, &pin_GPIO_EMC_30), +}; + +const mcu_periph_obj_t mcu_i2s_tx_bclk_list[7] = { + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_BCLK_SELECT_INPUT, 0, &pin_GPIO_EMC_11), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_BCLK_SELECT_INPUT, 1, &pin_GPIO_AD_B1_01), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_BCLK_SELECT_INPUT, 2, &pin_GPIO_EMC_26), + + PERIPH_PIN(2, 3, kIOMUXC_SAI2_TX_BCLK_SELECT_INPUT, 0, &pin_GPIO_SD_B0_05), + PERIPH_PIN(2, 3, kIOMUXC_SAI2_TX_BCLK_SELECT_INPUT, 1, &pin_GPIO_EMC_04), + + PERIPH_PIN(3, 3, kIOMUXC_SAI3_TX_BCLK_SELECT_INPUT, 0, &pin_GPIO_SD_B1_06), + PERIPH_PIN(3, 3, kIOMUXC_SAI3_TX_BCLK_SELECT_INPUT, 1, &pin_GPIO_EMC_33), +}; + +const mcu_periph_obj_t mcu_i2s_tx_data0_list[7] = { + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_EMC_12), + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_EMC_25), + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_AD_B1_03), + + PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_EMC_06), + PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_SD_B0_04), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_32), + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_SD_B1_08), +}; + +const mcu_periph_obj_t mcu_i2s_tx_sync_list[7] = { + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_SYNC_SELECT_INPUT, 0, &pin_GPIO_EMC_10), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_SYNC_SELECT_INPUT, 1, &pin_GPIO_AD_B1_02), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_SYNC_SELECT_INPUT, 2, &pin_GPIO_EMC_27), + + PERIPH_PIN(2, 3, kIOMUXC_SAI2_TX_SYNC_SELECT_INPUT, 0, &pin_GPIO_SD_B0_06), + PERIPH_PIN(2, 3, kIOMUXC_SAI2_TX_SYNC_SELECT_INPUT, 1, &pin_GPIO_EMC_05), + + PERIPH_PIN(3, 3, kIOMUXC_SAI3_TX_SYNC_SELECT_INPUT, 0, &pin_GPIO_SD_B1_07), + PERIPH_PIN(3, 3, kIOMUXC_SAI3_TX_SYNC_SELECT_INPUT, 1, &pin_GPIO_EMC_34), +}; + +const mcu_periph_obj_t mcu_mqs_left_list[3] = { + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_EMC_17), + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_38), + PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_AD_B0_07), +}; + +const mcu_periph_obj_t mcu_mqs_right_list[3] = { + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_EMC_16), + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_37), + PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_AD_B0_06), +}; + +const mcu_pwm_obj_t mcu_pwm_list[40] = { PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_EMC_26_FLEXPWM1_PWMA00, &pin_GPIO_EMC_26), PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_AD_B1_06_FLEXPWM1_PWMA00, &pin_GPIO_AD_B1_06), - PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_EMC_24_FLEXPWM1_PWMA01, &pin_GPIO_EMC_24), - PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_AD_B1_08_FLEXPWM1_PWMA01, &pin_GPIO_AD_B1_08), - - PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_EMC_22_FLEXPWM1_PWMA02, &pin_GPIO_EMC_22), - PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_AD_B1_10_FLEXPWM1_PWMA02, &pin_GPIO_AD_B1_10), - - PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_20_FLEXPWM1_PWMA03, &pin_GPIO_EMC_20), - PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_AD_B1_12_FLEXPWM1_PWMA03, &pin_GPIO_AD_B1_12), - PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_EMC_27_FLEXPWM1_PWMB00, &pin_GPIO_EMC_27), PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_AD_B1_07_FLEXPWM1_PWMB00, &pin_GPIO_AD_B1_07), + PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmX, IOMUXC_GPIO_EMC_28_FLEXPWM1_PWMX00, &pin_GPIO_EMC_28), + + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_EMC_24_FLEXPWM1_PWMA01, &pin_GPIO_EMC_24), + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_AD_B1_08_FLEXPWM1_PWMA01, &pin_GPIO_AD_B1_08), + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_EMC_25_FLEXPWM1_PWMB01, &pin_GPIO_EMC_25), PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_AD_B1_09_FLEXPWM1_PWMB01, &pin_GPIO_AD_B1_09), + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmX, IOMUXC_GPIO_EMC_29_FLEXPWM1_PWMX01, &pin_GPIO_EMC_29), + + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_EMC_22_FLEXPWM1_PWMA02, &pin_GPIO_EMC_22), + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_AD_B1_10_FLEXPWM1_PWMA02, &pin_GPIO_AD_B1_10), + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_EMC_23_FLEXPWM1_PWMB02, &pin_GPIO_EMC_23), PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_AD_B1_11_FLEXPWM1_PWMB02, &pin_GPIO_AD_B1_11), + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmX, IOMUXC_GPIO_EMC_30_FLEXPWM1_PWMX02, &pin_GPIO_EMC_30), + + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_20_FLEXPWM1_PWMA03, &pin_GPIO_EMC_20), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_AD_B1_12_FLEXPWM1_PWMA03, &pin_GPIO_AD_B1_12), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_21_FLEXPWM1_PWMB03, &pin_GPIO_EMC_21), PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_AD_B1_13_FLEXPWM1_PWMB03, &pin_GPIO_AD_B1_13), - PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmX, IOMUXC_GPIO_EMC_28_FLEXPWM1_PWMX00, &pin_GPIO_EMC_28), - PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmX, IOMUXC_GPIO_EMC_29_FLEXPWM1_PWMX01, &pin_GPIO_EMC_29), - PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmX, IOMUXC_GPIO_EMC_30_FLEXPWM1_PWMX02, &pin_GPIO_EMC_30), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmX, IOMUXC_GPIO_EMC_31_FLEXPWM1_PWMX03, &pin_GPIO_EMC_31), PWM_PIN(PWM2, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_EMC_38_FLEXPWM2_PWMA00, &pin_GPIO_EMC_38), PWM_PIN(PWM2, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_AD_B0_14_FLEXPWM2_PWMA00, &pin_GPIO_AD_B0_14), - PWM_PIN(PWM2, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_EMC_36_FLEXPWM2_PWMA01, &pin_GPIO_EMC_36), - PWM_PIN(PWM2, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_AD_B0_12_FLEXPWM2_PWMA01, &pin_GPIO_AD_B0_12), - - PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_EMC_30_FLEXPWM2_PWMA02, &pin_GPIO_EMC_30), - PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_AD_B0_10_FLEXPWM2_PWMA02, &pin_GPIO_AD_B0_10), - - PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_28_FLEXPWM2_PWMA03, &pin_GPIO_EMC_28), - PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_AD_B0_06_FLEXPWM2_PWMA03, &pin_GPIO_AD_B0_06), - PWM_PIN(PWM2, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_EMC_39_FLEXPWM2_PWMB00, &pin_GPIO_EMC_39), PWM_PIN(PWM2, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_AD_B0_15_FLEXPWM2_PWMB00, &pin_GPIO_AD_B0_15), + PWM_PIN(PWM2, kPWM_Module_0, kPWM_PwmX, IOMUXC_GPIO_EMC_10_FLEXPWM2_PWMX00, &pin_GPIO_EMC_10), + + PWM_PIN(PWM2, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_EMC_36_FLEXPWM2_PWMA01, &pin_GPIO_EMC_36), + PWM_PIN(PWM2, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_AD_B0_12_FLEXPWM2_PWMA01, &pin_GPIO_AD_B0_12), + PWM_PIN(PWM2, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_EMC_37_FLEXPWM2_PWMB01, &pin_GPIO_EMC_37), PWM_PIN(PWM2, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_AD_B0_13_FLEXPWM2_PWMB01, &pin_GPIO_AD_B0_13), + PWM_PIN(PWM2, kPWM_Module_1, kPWM_PwmX, IOMUXC_GPIO_EMC_11_FLEXPWM2_PWMX01, &pin_GPIO_EMC_11), + + PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_EMC_30_FLEXPWM2_PWMA02, &pin_GPIO_EMC_30), + PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_AD_B0_10_FLEXPWM2_PWMA02, &pin_GPIO_AD_B0_10), + PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_EMC_31_FLEXPWM2_PWMB02, &pin_GPIO_EMC_31), PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_AD_B0_11_FLEXPWM2_PWMB02, &pin_GPIO_AD_B0_11), + PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmX, IOMUXC_GPIO_EMC_12_FLEXPWM2_PWMX02, &pin_GPIO_EMC_12), + + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_28_FLEXPWM2_PWMA03, &pin_GPIO_EMC_28), + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_AD_B0_06_FLEXPWM2_PWMA03, &pin_GPIO_AD_B0_06), + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_29_FLEXPWM2_PWMB03, &pin_GPIO_EMC_29), PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_AD_B0_07_FLEXPWM2_PWMB03, &pin_GPIO_AD_B0_07), - PWM_PIN(PWM2, kPWM_Module_0, kPWM_PwmX, IOMUXC_GPIO_EMC_10_FLEXPWM2_PWMX00, &pin_GPIO_EMC_10), - PWM_PIN(PWM2, kPWM_Module_1, kPWM_PwmX, IOMUXC_GPIO_EMC_11_FLEXPWM2_PWMX01, &pin_GPIO_EMC_11), - PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmX, IOMUXC_GPIO_EMC_12_FLEXPWM2_PWMX02, &pin_GPIO_EMC_12), PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmX, IOMUXC_GPIO_EMC_13_FLEXPWM2_PWMX03, &pin_GPIO_EMC_13), }; - -const mcu_periph_obj_t mcu_sai_rx_bclk_list[] = { - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_EMC_14), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_EMC_19), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_AD_B1_06), - PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_EMC_09), - PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_SD_B0_02), - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_29), - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_SD_B1_09), -}; -const mcu_periph_obj_t mcu_sai_rx_data0_list[] = { - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_EMC_13), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_EMC_21), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_AD_B1_05), - PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_EMC_08), - PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_SD_B0_03), - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_30), - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_SD_B1_11), -}; -const mcu_periph_obj_t mcu_sai_rx_sync_list[] = { - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_EMC_15), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_EMC_28), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_AD_B1_04), - PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_EMC_07), - PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_SD_B0_01), - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_30), - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_SD_B1_10), -}; -const mcu_periph_obj_t mcu_sai_tx_bclk_list[] = { - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_EMC_11), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_EMC_26), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_AD_B1_01), - PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_EMC_04), - PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_SD_B0_04), - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_33), - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_SD_B0_06), -}; -const mcu_periph_obj_t mcu_sai_tx_data0_list[] = { - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_EMC_12), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_EMC_25), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_AD_B1_03), - PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_EMC_06), - PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_SD_B0_04), - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_32), - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_SD_B1_08), -}; -const mcu_periph_obj_t mcu_sai_tx_sync_list[] = { - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_EMC_10), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_EMC_27), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_AD_B1_02), - PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_EMC_05), - PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_SD_B0_06), - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_34), - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_SD_B1_07), -}; -const mcu_periph_obj_t mcu_mqs_left_list[] = { - PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_AD_B0_07), - PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_EMC_17), - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_38), -}; -const mcu_periph_obj_t mcu_mqs_right_list[] = { - PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_AD_B0_06), - PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_EMC_16), - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_37), -}; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.h index 51c97b3eef..496e0ab153 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.h @@ -3,8 +3,9 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries * Copyright (c) 2019 Artur Pacholec - * Copyright (c) 2020 Scott Shawcroft + * Copyright (c) 2023 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 @@ -26,33 +27,29 @@ */ #pragma once - extern LPI2C_Type *const 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]; extern LPSPI_Type *const 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]; +extern const mcu_periph_obj_t mcu_spi_sdo_list[8]; +extern const mcu_periph_obj_t mcu_spi_sdi_list[8]; extern LPUART_Type *const 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]; extern const mcu_periph_obj_t mcu_uart_rts_list[10]; extern const mcu_periph_obj_t mcu_uart_cts_list[10]; -extern const mcu_pwm_obj_t mcu_pwm_list[39]; - -extern const mcu_periph_obj_t mcu_sai_rx_bclk_list[7]; -extern const mcu_periph_obj_t mcu_sai_rx_data0_list[7]; -extern const mcu_periph_obj_t mcu_sai_rx_sync_list[7]; -extern const mcu_periph_obj_t mcu_sai_tx_bclk_list[7]; -extern const mcu_periph_obj_t mcu_sai_tx_data0_list[7]; -extern const mcu_periph_obj_t mcu_sai_tx_sync_list[7]; +extern I2S_Type *const mcu_i2s_banks[3]; +extern const mcu_periph_obj_t mcu_i2s_rx_data0_list[7]; +extern const mcu_periph_obj_t mcu_i2s_rx_sync_list[7]; +extern const mcu_periph_obj_t mcu_i2s_tx_bclk_list[7]; +extern const mcu_periph_obj_t mcu_i2s_tx_data0_list[7]; +extern const mcu_periph_obj_t mcu_i2s_tx_sync_list[7]; extern const mcu_periph_obj_t mcu_mqs_left_list[3]; extern const mcu_periph_obj_t mcu_mqs_right_list[3]; + +extern const mcu_pwm_obj_t mcu_pwm_list[40]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pin_names.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pin_names.h new file mode 100644 index 0000000000..1f159afe53 --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pin_names.h @@ -0,0 +1,130 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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. + */ + + +// define FORMAT_PIN(pin_name) and then include this file. + +FORMAT_PIN(GPIO_EMC_00) +FORMAT_PIN(GPIO_EMC_01) +FORMAT_PIN(GPIO_EMC_02) +FORMAT_PIN(GPIO_EMC_03) +FORMAT_PIN(GPIO_EMC_04) +FORMAT_PIN(GPIO_EMC_05) +FORMAT_PIN(GPIO_EMC_06) +FORMAT_PIN(GPIO_EMC_07) +FORMAT_PIN(GPIO_EMC_08) +FORMAT_PIN(GPIO_EMC_09) +FORMAT_PIN(GPIO_EMC_10) +FORMAT_PIN(GPIO_EMC_11) +FORMAT_PIN(GPIO_EMC_12) +FORMAT_PIN(GPIO_EMC_13) +FORMAT_PIN(GPIO_EMC_14) +FORMAT_PIN(GPIO_EMC_15) +FORMAT_PIN(GPIO_EMC_16) +FORMAT_PIN(GPIO_EMC_17) +FORMAT_PIN(GPIO_EMC_18) +FORMAT_PIN(GPIO_EMC_19) +FORMAT_PIN(GPIO_EMC_20) +FORMAT_PIN(GPIO_EMC_21) +FORMAT_PIN(GPIO_EMC_22) +FORMAT_PIN(GPIO_EMC_23) +FORMAT_PIN(GPIO_EMC_24) +FORMAT_PIN(GPIO_EMC_25) +FORMAT_PIN(GPIO_EMC_26) +FORMAT_PIN(GPIO_EMC_27) +FORMAT_PIN(GPIO_EMC_28) +FORMAT_PIN(GPIO_EMC_29) +FORMAT_PIN(GPIO_EMC_30) +FORMAT_PIN(GPIO_EMC_31) +FORMAT_PIN(GPIO_EMC_32) +FORMAT_PIN(GPIO_EMC_33) +FORMAT_PIN(GPIO_EMC_34) +FORMAT_PIN(GPIO_EMC_35) +FORMAT_PIN(GPIO_EMC_36) +FORMAT_PIN(GPIO_EMC_37) +FORMAT_PIN(GPIO_EMC_38) +FORMAT_PIN(GPIO_EMC_39) +FORMAT_PIN(GPIO_EMC_40) +FORMAT_PIN(GPIO_EMC_41) + +FORMAT_PIN(GPIO_AD_B0_00) +FORMAT_PIN(GPIO_AD_B0_01) +FORMAT_PIN(GPIO_AD_B0_02) +FORMAT_PIN(GPIO_AD_B0_03) +FORMAT_PIN(GPIO_AD_B0_04) +FORMAT_PIN(GPIO_AD_B0_05) +FORMAT_PIN(GPIO_AD_B0_06) +FORMAT_PIN(GPIO_AD_B0_07) +FORMAT_PIN(GPIO_AD_B0_08) +FORMAT_PIN(GPIO_AD_B0_09) +FORMAT_PIN(GPIO_AD_B0_10) +FORMAT_PIN(GPIO_AD_B0_11) +FORMAT_PIN(GPIO_AD_B0_12) +FORMAT_PIN(GPIO_AD_B0_13) +FORMAT_PIN(GPIO_AD_B0_14) +FORMAT_PIN(GPIO_AD_B0_15) + +FORMAT_PIN(GPIO_AD_B1_00) +FORMAT_PIN(GPIO_AD_B1_01) +FORMAT_PIN(GPIO_AD_B1_02) +FORMAT_PIN(GPIO_AD_B1_03) +FORMAT_PIN(GPIO_AD_B1_04) +FORMAT_PIN(GPIO_AD_B1_05) +FORMAT_PIN(GPIO_AD_B1_06) +FORMAT_PIN(GPIO_AD_B1_07) +FORMAT_PIN(GPIO_AD_B1_08) +FORMAT_PIN(GPIO_AD_B1_09) +FORMAT_PIN(GPIO_AD_B1_10) +FORMAT_PIN(GPIO_AD_B1_11) +FORMAT_PIN(GPIO_AD_B1_12) +FORMAT_PIN(GPIO_AD_B1_13) +FORMAT_PIN(GPIO_AD_B1_14) +FORMAT_PIN(GPIO_AD_B1_15) + +FORMAT_PIN(GPIO_SD_B0_00) +FORMAT_PIN(GPIO_SD_B0_01) +FORMAT_PIN(GPIO_SD_B0_02) +FORMAT_PIN(GPIO_SD_B0_03) +FORMAT_PIN(GPIO_SD_B0_04) +FORMAT_PIN(GPIO_SD_B0_05) +FORMAT_PIN(GPIO_SD_B0_06) + +FORMAT_PIN(GPIO_SD_B1_00) +FORMAT_PIN(GPIO_SD_B1_01) +FORMAT_PIN(GPIO_SD_B1_02) +FORMAT_PIN(GPIO_SD_B1_03) +FORMAT_PIN(GPIO_SD_B1_04) +FORMAT_PIN(GPIO_SD_B1_05) +FORMAT_PIN(GPIO_SD_B1_06) +FORMAT_PIN(GPIO_SD_B1_07) +FORMAT_PIN(GPIO_SD_B1_08) +FORMAT_PIN(GPIO_SD_B1_09) +FORMAT_PIN(GPIO_SD_B1_10) +FORMAT_PIN(GPIO_SD_B1_11) +FORMAT_PIN(USB_OTG1_DN) +FORMAT_PIN(USB_OTG1_DP) diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pins.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pins.c index fe39f7e19d..e349f43542 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pins.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pins.c @@ -5,6 +5,7 @@ * * Copyright (c) 2019 Lucian Copeland for Adafruit Industries * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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 @@ -29,38 +30,6 @@ #include "py/mphal.h" #include "mimxrt10xx/pins.h" -const mcu_pin_obj_t pin_GPIO_AD_B0_00 = PIN(GPIO1, 0, GPIO_AD_B0_00, NO_ADC, 0, 0x00000000, 0x000070A0); -const mcu_pin_obj_t pin_GPIO_AD_B0_01 = PIN(GPIO1, 1, GPIO_AD_B0_01, NO_ADC, 0, 0x00000000, 0x000030A0); -const mcu_pin_obj_t pin_GPIO_AD_B0_02 = PIN(GPIO1, 2, GPIO_AD_B0_02, NO_ADC, 0, 0x00000000, 0x000030A0); -const mcu_pin_obj_t pin_GPIO_AD_B0_03 = PIN(GPIO1, 3, GPIO_AD_B0_03, NO_ADC, 0, 0x00000000, 0x000070A0); -const mcu_pin_obj_t pin_GPIO_AD_B0_04 = PIN(GPIO1, 4, GPIO_AD_B0_04, NO_ADC, 0, 0x00000000, 0x000090B1); -const mcu_pin_obj_t pin_GPIO_AD_B0_05 = PIN(GPIO1, 5, GPIO_AD_B0_05, NO_ADC, 0, 0x00000000, 0x000070A0); -const mcu_pin_obj_t pin_GPIO_AD_B0_06 = PIN(GPIO1, 6, GPIO_AD_B0_06, NO_ADC, 0, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B0_07 = PIN(GPIO1, 7, GPIO_AD_B0_07, NO_ADC, 0, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B0_08 = PIN(GPIO1, 8, GPIO_AD_B0_08, NO_ADC, 0, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B0_09 = PIN(GPIO1, 9, GPIO_AD_B0_09, NO_ADC, 0, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B0_10 = PIN(GPIO1, 10, GPIO_AD_B0_10, NO_ADC, 0, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B0_11 = PIN(GPIO1, 11, GPIO_AD_B0_11, NO_ADC, 0, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B0_12 = PIN(GPIO1, 12, GPIO_AD_B0_12, ADC1, 0, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B0_13 = PIN(GPIO1, 13, GPIO_AD_B0_13, ADC2, 0, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B0_14 = PIN(GPIO1, 14, GPIO_AD_B0_14, ADC2, 1, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B0_15 = PIN(GPIO1, 15, GPIO_AD_B0_15, ADC1, 2, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_00 = PIN(GPIO1, 16, GPIO_AD_B1_00, NO_ADC, 0, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_01 = PIN(GPIO1, 17, GPIO_AD_B1_01, ADC1, 3, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_02 = PIN(GPIO1, 18, GPIO_AD_B1_02, ADC2, 3, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_03 = PIN(GPIO1, 19, GPIO_AD_B1_03, ADC1, 4, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_04 = PIN(GPIO1, 20, GPIO_AD_B1_04, ADC2, 4, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_05 = PIN(GPIO1, 21, GPIO_AD_B1_05, ADC2, 5, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_06 = PIN(GPIO1, 22, GPIO_AD_B1_06, ADC2, 6, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_07 = PIN(GPIO1, 23, GPIO_AD_B1_07, ADC2, 7, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_08 = PIN(GPIO1, 24, GPIO_AD_B1_08, ADC2, 8, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_09 = PIN(GPIO1, 25, GPIO_AD_B1_09, ADC2, 9, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_10 = PIN(GPIO1, 26, GPIO_AD_B1_10, ADC2, 10, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_11 = PIN(GPIO1, 27, GPIO_AD_B1_11, ADC2, 11, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_12 = PIN(GPIO1, 28, GPIO_AD_B1_12, ADC2, 12, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_13 = PIN(GPIO1, 29, GPIO_AD_B1_13, ADC2, 13, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_14 = PIN(GPIO1, 30, GPIO_AD_B1_14, ADC2, 14, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_15 = PIN(GPIO1, 31, GPIO_AD_B1_15, ADC2, 15, 0x00000005, 0x000010B0); const mcu_pin_obj_t pin_GPIO_EMC_00 = PIN(GPIO2, 0, GPIO_EMC_00, NO_ADC, 0, 0x00000005, 0x000010B0); const mcu_pin_obj_t pin_GPIO_EMC_01 = PIN(GPIO2, 1, GPIO_EMC_01, NO_ADC, 0, 0x00000005, 0x000010B0); const mcu_pin_obj_t pin_GPIO_EMC_02 = PIN(GPIO2, 2, GPIO_EMC_02, NO_ADC, 0, 0x00000005, 0x000010B0); @@ -103,6 +72,38 @@ const mcu_pin_obj_t pin_GPIO_EMC_38 = PIN(GPIO3, 6, GPIO_EMC_38, NO_ADC, 0, 0x00 const mcu_pin_obj_t pin_GPIO_EMC_39 = PIN(GPIO3, 7, GPIO_EMC_39, NO_ADC, 0, 0x00000005, 0x000010B0); const mcu_pin_obj_t pin_GPIO_EMC_40 = PIN(GPIO3, 8, GPIO_EMC_40, NO_ADC, 0, 0x00000005, 0x000010B0); const mcu_pin_obj_t pin_GPIO_EMC_41 = PIN(GPIO3, 9, GPIO_EMC_41, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_00 = PIN(GPIO1, 0, GPIO_AD_B0_00, NO_ADC, 0, 0x00000000, 0x000070A0); +const mcu_pin_obj_t pin_GPIO_AD_B0_01 = PIN(GPIO1, 1, GPIO_AD_B0_01, NO_ADC, 0, 0x00000000, 0x000030A0); +const mcu_pin_obj_t pin_GPIO_AD_B0_02 = PIN(GPIO1, 2, GPIO_AD_B0_02, NO_ADC, 0, 0x00000000, 0x000030A0); +const mcu_pin_obj_t pin_GPIO_AD_B0_03 = PIN(GPIO1, 3, GPIO_AD_B0_03, NO_ADC, 0, 0x00000000, 0x000070A0); +const mcu_pin_obj_t pin_GPIO_AD_B0_04 = PIN(GPIO1, 4, GPIO_AD_B0_04, NO_ADC, 0, 0x00000000, 0x000090B1); +const mcu_pin_obj_t pin_GPIO_AD_B0_05 = PIN(GPIO1, 5, GPIO_AD_B0_05, NO_ADC, 0, 0x00000000, 0x000070A0); +const mcu_pin_obj_t pin_GPIO_AD_B0_06 = PIN(GPIO1, 6, GPIO_AD_B0_06, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_07 = PIN(GPIO1, 7, GPIO_AD_B0_07, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_08 = PIN(GPIO1, 8, GPIO_AD_B0_08, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_09 = PIN(GPIO1, 9, GPIO_AD_B0_09, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_10 = PIN(GPIO1, 10, GPIO_AD_B0_10, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_11 = PIN(GPIO1, 11, GPIO_AD_B0_11, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_12 = PIN(GPIO1, 12, GPIO_AD_B0_12, ADC1, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_13 = PIN(GPIO1, 13, GPIO_AD_B0_13, ADC2, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_14 = PIN(GPIO1, 14, GPIO_AD_B0_14, ADC2, 1, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_15 = PIN(GPIO1, 15, GPIO_AD_B0_15, ADC2, 2, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_00 = PIN(GPIO1, 16, GPIO_AD_B1_00, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_01 = PIN(GPIO1, 17, GPIO_AD_B1_01, ADC1, 3, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_02 = PIN(GPIO1, 18, GPIO_AD_B1_02, ADC2, 3, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_03 = PIN(GPIO1, 19, GPIO_AD_B1_03, ADC1, 4, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_04 = PIN(GPIO1, 20, GPIO_AD_B1_04, ADC2, 4, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_05 = PIN(GPIO1, 21, GPIO_AD_B1_05, ADC2, 5, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_06 = PIN(GPIO1, 22, GPIO_AD_B1_06, ADC2, 6, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_07 = PIN(GPIO1, 23, GPIO_AD_B1_07, ADC2, 7, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_08 = PIN(GPIO1, 24, GPIO_AD_B1_08, ADC2, 8, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_09 = PIN(GPIO1, 25, GPIO_AD_B1_09, ADC2, 9, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_10 = PIN(GPIO1, 26, GPIO_AD_B1_10, ADC2, 10, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_11 = PIN(GPIO1, 27, GPIO_AD_B1_11, ADC2, 11, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_12 = PIN(GPIO1, 28, GPIO_AD_B1_12, ADC2, 12, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_13 = PIN(GPIO1, 29, GPIO_AD_B1_13, ADC2, 13, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_14 = PIN(GPIO1, 30, GPIO_AD_B1_14, ADC2, 14, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_15 = PIN(GPIO1, 31, GPIO_AD_B1_15, ADC2, 15, 0x00000005, 0x000010B0); const mcu_pin_obj_t pin_GPIO_SD_B0_00 = PIN(GPIO3, 13, GPIO_SD_B0_00, NO_ADC, 0, 0x00000005, 0x000010B0); const mcu_pin_obj_t pin_GPIO_SD_B0_01 = PIN(GPIO3, 14, GPIO_SD_B0_01, NO_ADC, 0, 0x00000005, 0x000010B0); const mcu_pin_obj_t pin_GPIO_SD_B0_02 = PIN(GPIO3, 15, GPIO_SD_B0_02, NO_ADC, 0, 0x00000005, 0x000010B0); @@ -122,3 +123,6 @@ const mcu_pin_obj_t pin_GPIO_SD_B1_08 = PIN(GPIO3, 28, GPIO_SD_B1_08, NO_ADC, 0, const mcu_pin_obj_t pin_GPIO_SD_B1_09 = PIN(GPIO3, 29, GPIO_SD_B1_09, NO_ADC, 0, 0x00000005, 0x000010B0); const mcu_pin_obj_t pin_GPIO_SD_B1_10 = PIN(GPIO3, 30, GPIO_SD_B1_10, NO_ADC, 0, 0x00000005, 0x000010B0); const mcu_pin_obj_t pin_GPIO_SD_B1_11 = PIN(GPIO3, 31, GPIO_SD_B1_11, NO_ADC, 0, 0x00000005, 0x000010B0); + +const mcu_pin_obj_t pin_USB_OTG1_DN = { { &mcu_pin_type }, }; +const mcu_pin_obj_t pin_USB_OTG1_DP = { { &mcu_pin_type }, }; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pins.h index 4485b6e152..118eff9335 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pins.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pins.h @@ -3,8 +3,9 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries * Copyright (c) 2019 Artur Pacholec - * Copyright (c) 2020 Scott Shawcroft + * Copyright (c) 2023 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 @@ -25,107 +26,11 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_MIMXRT10XX_PERIPHERALS_MIMXRT1021_PINS_H -#define MICROPY_INCLUDED_MIMXRT10XX_PERIPHERALS_MIMXRT1021_PINS_H +#pragma once -extern const mcu_pin_obj_t pin_GPIO_AD_B0_00; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_01; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_02; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_03; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_04; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_05; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_06; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_07; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_08; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_09; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_10; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_11; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_12; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_13; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_14; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_15; +#define FORMAT_PIN(pin_name) extern const mcu_pin_obj_t pin_##pin_name; +#include "pin_names.h" +#undef FORMAT_PIN -extern const mcu_pin_obj_t pin_GPIO_AD_B1_00; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_01; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_02; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_03; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_04; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_05; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_06; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_07; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_08; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_09; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_10; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_11; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_12; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_13; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_14; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_15; - -extern const mcu_pin_obj_t pin_GPIO_EMC_00; -extern const mcu_pin_obj_t pin_GPIO_EMC_01; -extern const mcu_pin_obj_t pin_GPIO_EMC_02; -extern const mcu_pin_obj_t pin_GPIO_EMC_03; -extern const mcu_pin_obj_t pin_GPIO_EMC_04; -extern const mcu_pin_obj_t pin_GPIO_EMC_05; -extern const mcu_pin_obj_t pin_GPIO_EMC_06; -extern const mcu_pin_obj_t pin_GPIO_EMC_07; -extern const mcu_pin_obj_t pin_GPIO_EMC_08; -extern const mcu_pin_obj_t pin_GPIO_EMC_09; -extern const mcu_pin_obj_t pin_GPIO_EMC_10; -extern const mcu_pin_obj_t pin_GPIO_EMC_11; -extern const mcu_pin_obj_t pin_GPIO_EMC_12; -extern const mcu_pin_obj_t pin_GPIO_EMC_13; -extern const mcu_pin_obj_t pin_GPIO_EMC_14; -extern const mcu_pin_obj_t pin_GPIO_EMC_15; -extern const mcu_pin_obj_t pin_GPIO_EMC_16; -extern const mcu_pin_obj_t pin_GPIO_EMC_17; -extern const mcu_pin_obj_t pin_GPIO_EMC_18; -extern const mcu_pin_obj_t pin_GPIO_EMC_19; -extern const mcu_pin_obj_t pin_GPIO_EMC_20; -extern const mcu_pin_obj_t pin_GPIO_EMC_21; -extern const mcu_pin_obj_t pin_GPIO_EMC_22; -extern const mcu_pin_obj_t pin_GPIO_EMC_23; -extern const mcu_pin_obj_t pin_GPIO_EMC_24; -extern const mcu_pin_obj_t pin_GPIO_EMC_25; -extern const mcu_pin_obj_t pin_GPIO_EMC_26; -extern const mcu_pin_obj_t pin_GPIO_EMC_27; -extern const mcu_pin_obj_t pin_GPIO_EMC_28; -extern const mcu_pin_obj_t pin_GPIO_EMC_29; -extern const mcu_pin_obj_t pin_GPIO_EMC_30; -extern const mcu_pin_obj_t pin_GPIO_EMC_31; -extern const mcu_pin_obj_t pin_GPIO_EMC_32; -extern const mcu_pin_obj_t pin_GPIO_EMC_33; -extern const mcu_pin_obj_t pin_GPIO_EMC_34; -extern const mcu_pin_obj_t pin_GPIO_EMC_35; -extern const mcu_pin_obj_t pin_GPIO_EMC_36; -extern const mcu_pin_obj_t pin_GPIO_EMC_37; -extern const mcu_pin_obj_t pin_GPIO_EMC_38; -extern const mcu_pin_obj_t pin_GPIO_EMC_39; -extern const mcu_pin_obj_t pin_GPIO_EMC_40; -extern const mcu_pin_obj_t pin_GPIO_EMC_41; - -extern const mcu_pin_obj_t pin_GPIO_SD_B0_00; -extern const mcu_pin_obj_t pin_GPIO_SD_B0_01; -extern const mcu_pin_obj_t pin_GPIO_SD_B0_02; -extern const mcu_pin_obj_t pin_GPIO_SD_B0_03; -extern const mcu_pin_obj_t pin_GPIO_SD_B0_04; -extern const mcu_pin_obj_t pin_GPIO_SD_B0_05; -extern const mcu_pin_obj_t pin_GPIO_SD_B0_06; - -extern const mcu_pin_obj_t pin_GPIO_SD_B1_00; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_01; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_02; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_03; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_04; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_05; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_06; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_07; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_08; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_09; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_10; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_11; - -extern const mcu_pin_obj_t mcu_pin_list[IOMUXC_SW_PAD_CTL_PAD_COUNT]; - -#endif // MICROPY_INCLUDED_MIMXRT10XX_PERIPHERALS_MIMXRT1021_PINS_H +#define PIN_COUNT (IOMUXC_SW_PAD_CTL_PAD_COUNT + 2) +extern const mcu_pin_obj_t mcu_pin_list[PIN_COUNT]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/clocks.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/clocks.c new file mode 100644 index 0000000000..f62f974bdd --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/clocks.c @@ -0,0 +1,382 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Artur Pacholec + * + * 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. + */ +/* + * Copyright 2019 NXP + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "mpconfigport.h" + +#include "fsl_clock.h" +#include "fsl_iomuxc.h" +#include "fsl_device_registers.h" + +#include "board.h" + +#include "clocks.h" + +#define BOARD_XTAL0_CLK_HZ 24000000U /*!< Board xtal0 frequency in Hz */ +#define BOARD_XTAL32K_CLK_HZ 32768U /*!< Board xtal32k frequency in Hz */ +#define BOARD_BOOTCLOCKRUN_CORE_CLOCK 528000000U /*!< Core clock frequency: 528000000Hz */ + +/******************************************************************************* + * Variables for BOARD_BootClockRUN configuration + ******************************************************************************/ +const clock_arm_pll_config_t armPllConfig_BOARD_BootClockRUN = +{ + .loopDivider = 100, /* PLL loop divider, Fout = Fin * 50 */ + .src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */ +}; +const clock_sys_pll_config_t sysPllConfig_BOARD_BootClockRUN = +{ + .loopDivider = 1, /* PLL loop divider, Fout = Fin * ( 20 + loopDivider*2 + numerator / denominator ) */ + .numerator = 0, /* 30 bit numerator of fractional loop divider */ + .denominator = 1, /* 30 bit denominator of fractional loop divider */ + .src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */ +}; +const clock_usb_pll_config_t usb1PllConfig_BOARD_BootClockRUN = +{ + .loopDivider = 0, /* PLL loop divider, Fout = Fin * 20 */ + .src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */ +}; +const clock_video_pll_config_t videoPllConfig_BOARD_BootClockRUN = +{ + .loopDivider = 31, /* PLL loop divider, Fout = Fin * ( loopDivider + numerator / denominator ) */ + .postDivider = 8, /* Divider after PLL */ + .numerator = 0, /* 30 bit numerator of fractional loop divider, Fout = Fin * ( loopDivider + numerator / denominator ) */ + .denominator = 1, /* 30 bit denominator of fractional loop divider, Fout = Fin * ( loopDivider + numerator / denominator ) */ + .src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */ +}; +/******************************************************************************* + * Code for BOARD_BootClockRUN configuration + ******************************************************************************/ +void clocks_init(void) { + /* Init RTC OSC clock frequency. */ + CLOCK_SetRtcXtalFreq(32768U); + /* Enable 1MHz clock output. */ + XTALOSC24M->OSC_CONFIG2 |= XTALOSC24M_OSC_CONFIG2_ENABLE_1M_MASK; + /* Use free 1MHz clock output. */ + XTALOSC24M->OSC_CONFIG2 &= ~XTALOSC24M_OSC_CONFIG2_MUX_1M_MASK; + /* Set XTAL 24MHz clock frequency. */ + CLOCK_SetXtalFreq(24000000U); + /* Enable XTAL 24MHz clock source. */ + CLOCK_InitExternalClk(0); + /* Enable internal RC. */ + CLOCK_InitRcOsc24M(); + /* Switch clock source to external OSC. */ + CLOCK_SwitchOsc(kCLOCK_XtalOsc); + /* Set Oscillator ready counter value. */ + CCM->CCR = (CCM->CCR & (~CCM_CCR_OSCNT_MASK)) | CCM_CCR_OSCNT(127); + /* Setting PeriphClk2Mux and PeriphMux to provide stable clock before PLLs are initialed */ + CLOCK_SetMux(kCLOCK_PeriphClk2Mux, 1); /* Set PERIPH_CLK2 MUX to OSC */ + CLOCK_SetMux(kCLOCK_PeriphMux, 1); /* Set PERIPH_CLK MUX to PERIPH_CLK2 */ + /* Set AHB_PODF. */ + CLOCK_SetDiv(kCLOCK_AhbDiv, 0); + /* Disable IPG clock gate. */ + CLOCK_DisableClock(kCLOCK_Adc1); + CLOCK_DisableClock(kCLOCK_Adc2); + CLOCK_DisableClock(kCLOCK_Xbar1); + CLOCK_DisableClock(kCLOCK_Xbar2); + CLOCK_DisableClock(kCLOCK_Xbar3); + /* Set IPG_PODF. */ + CLOCK_SetDiv(kCLOCK_IpgDiv, 3); + /* Set ARM_PODF. */ + CLOCK_SetDiv(kCLOCK_ArmDiv, 1); + /* Set PERIPH_CLK2_PODF. */ + CLOCK_SetDiv(kCLOCK_PeriphClk2Div, 0); + /* Disable PERCLK clock gate. */ + CLOCK_DisableClock(kCLOCK_Gpt1); + CLOCK_DisableClock(kCLOCK_Gpt1S); + CLOCK_DisableClock(kCLOCK_Gpt2); + CLOCK_DisableClock(kCLOCK_Gpt2S); + CLOCK_DisableClock(kCLOCK_Pit); + /* Set PERCLK_PODF. */ + CLOCK_SetDiv(kCLOCK_PerclkDiv, 1); + /* Disable USDHC1 clock gate. */ + CLOCK_DisableClock(kCLOCK_Usdhc1); + /* Set USDHC1_PODF. */ + CLOCK_SetDiv(kCLOCK_Usdhc1Div, 1); + /* Set Usdhc1 clock source. */ + CLOCK_SetMux(kCLOCK_Usdhc1Mux, 0); + /* Disable USDHC2 clock gate. */ + CLOCK_DisableClock(kCLOCK_Usdhc2); + /* Set USDHC2_PODF. */ + CLOCK_SetDiv(kCLOCK_Usdhc2Div, 1); + /* Set Usdhc2 clock source. */ + CLOCK_SetMux(kCLOCK_Usdhc2Mux, 0); + /* In SDK projects, SDRAM (configured by SEMC) will be initialized in either debug script or dcd. + * With this macro SKIP_SYSCLK_INIT, system pll (selected to be SEMC source clock in SDK projects) will be left unchanged. + * Note: If another clock source is selected for SEMC, user may want to avoid changing that clock as well.*/ + #ifndef SKIP_SYSCLK_INIT + /* Disable Semc clock gate. */ + CLOCK_DisableClock(kCLOCK_Semc); + /* Set SEMC_PODF. */ + CLOCK_SetDiv(kCLOCK_SemcDiv, 7); + /* Set Semc alt clock source. */ + CLOCK_SetMux(kCLOCK_SemcAltMux, 0); + /* Set Semc clock source. */ + CLOCK_SetMux(kCLOCK_SemcMux, 0); + #endif + /* In SDK projects, external flash (configured by FLEXSPI) will be initialized by dcd. + * With this macro XIP_EXTERNAL_FLASH, usb1 pll (selected to be FLEXSPI clock source in SDK projects) will be left unchanged. + * Note: If another clock source is selected for FLEXSPI, user may want to avoid changing that clock as well.*/ + #if !(defined(XIP_EXTERNAL_FLASH) && (XIP_EXTERNAL_FLASH == 1)) + /* Disable Flexspi clock gate. */ + CLOCK_DisableClock(kCLOCK_FlexSpi); + /* Set FLEXSPI_PODF. */ + CLOCK_SetDiv(kCLOCK_FlexspiDiv, 1); + /* Set Flexspi clock source. */ + CLOCK_SetMux(kCLOCK_FlexspiMux, 3); + #endif + /* Disable Flexspi2 clock gate. */ + CLOCK_DisableClock(kCLOCK_FlexSpi2); + /* Set FLEXSPI2_PODF. */ + CLOCK_SetDiv(kCLOCK_Flexspi2Div, 1); + /* Set Flexspi2 clock source. */ + CLOCK_SetMux(kCLOCK_Flexspi2Mux, 1); + /* Disable LPSPI clock gate. */ + CLOCK_DisableClock(kCLOCK_Lpspi1); + CLOCK_DisableClock(kCLOCK_Lpspi2); + CLOCK_DisableClock(kCLOCK_Lpspi3); + /* Set LPSPI_PODF. */ + CLOCK_SetDiv(kCLOCK_LpspiDiv, 4); + /* Set Lpspi clock source. */ + CLOCK_SetMux(kCLOCK_LpspiMux, 2); + /* Disable TRACE clock gate. */ + CLOCK_DisableClock(kCLOCK_Trace); + /* Set TRACE_PODF. */ + CLOCK_SetDiv(kCLOCK_TraceDiv, 3); + /* Set Trace clock source. */ + CLOCK_SetMux(kCLOCK_TraceMux, 0); + /* Disable SAI1 clock gate. */ + CLOCK_DisableClock(kCLOCK_Sai1); + /* Set SAI1_CLK_PRED. */ + CLOCK_SetDiv(kCLOCK_Sai1PreDiv, 3); + /* Set SAI1_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_Sai1Div, 1); + /* Set Sai1 clock source. */ + CLOCK_SetMux(kCLOCK_Sai1Mux, 0); + /* Disable SAI2 clock gate. */ + CLOCK_DisableClock(kCLOCK_Sai2); + /* Set SAI2_CLK_PRED. */ + CLOCK_SetDiv(kCLOCK_Sai2PreDiv, 3); + /* Set SAI2_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_Sai2Div, 1); + /* Set Sai2 clock source. */ + CLOCK_SetMux(kCLOCK_Sai2Mux, 0); + /* Disable SAI3 clock gate. */ + CLOCK_DisableClock(kCLOCK_Sai3); + /* Set SAI3_CLK_PRED. */ + CLOCK_SetDiv(kCLOCK_Sai3PreDiv, 3); + /* Set SAI3_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_Sai3Div, 1); + /* Set Sai3 clock source. */ + CLOCK_SetMux(kCLOCK_Sai3Mux, 0); + /* Disable Lpi2c clock gate. */ + CLOCK_DisableClock(kCLOCK_Lpi2c1); + CLOCK_DisableClock(kCLOCK_Lpi2c2); + CLOCK_DisableClock(kCLOCK_Lpi2c3); + /* Set LPI2C_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_Lpi2cDiv, 0); + /* Set Lpi2c clock source. */ + CLOCK_SetMux(kCLOCK_Lpi2cMux, 0); + /* Disable CAN clock gate. */ + CLOCK_DisableClock(kCLOCK_Can1); + CLOCK_DisableClock(kCLOCK_Can2); + CLOCK_DisableClock(kCLOCK_Can1S); + CLOCK_DisableClock(kCLOCK_Can2S); + /* Set CAN_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_CanDiv, 1); + /* Set Can clock source. */ + CLOCK_SetMux(kCLOCK_CanMux, 2); + /* Disable UART clock gate. */ + CLOCK_DisableClock(kCLOCK_Lpuart1); + CLOCK_DisableClock(kCLOCK_Lpuart2); + CLOCK_DisableClock(kCLOCK_Lpuart3); + CLOCK_DisableClock(kCLOCK_Lpuart4); + CLOCK_DisableClock(kCLOCK_Lpuart5); + CLOCK_DisableClock(kCLOCK_Lpuart6); + CLOCK_DisableClock(kCLOCK_Lpuart7); + CLOCK_DisableClock(kCLOCK_Lpuart8); + /* Set UART_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_UartDiv, 0); + /* Set Uart clock source. */ + CLOCK_SetMux(kCLOCK_UartMux, 0); + /* Disable LCDIF clock gate. */ + CLOCK_DisableClock(kCLOCK_LcdPixel); + /* Set LCDIF_PRED. */ + CLOCK_SetDiv(kCLOCK_LcdifPreDiv, 1); + /* Set LCDIF_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_LcdifDiv, 3); + /* Set Lcdif pre clock source. */ + CLOCK_SetMux(kCLOCK_LcdifPreMux, 5); + /* Disable SPDIF clock gate. */ + CLOCK_DisableClock(kCLOCK_Spdif); + /* Set SPDIF0_CLK_PRED. */ + CLOCK_SetDiv(kCLOCK_Spdif0PreDiv, 1); + /* Set SPDIF0_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_Spdif0Div, 7); + /* Set Spdif clock source. */ + CLOCK_SetMux(kCLOCK_SpdifMux, 3); + /* Disable Flexio1 clock gate. */ + CLOCK_DisableClock(kCLOCK_Flexio1); + /* Set FLEXIO1_CLK_PRED. */ + CLOCK_SetDiv(kCLOCK_Flexio1PreDiv, 1); + /* Set FLEXIO1_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_Flexio1Div, 7); + /* Set Flexio1 clock source. */ + CLOCK_SetMux(kCLOCK_Flexio1Mux, 3); + /* Disable Flexio2 clock gate. */ + CLOCK_DisableClock(kCLOCK_Flexio2); + /* Set FLEXIO2_CLK_PRED. */ + CLOCK_SetDiv(kCLOCK_Flexio2PreDiv, 1); + /* Set FLEXIO2_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_Flexio2Div, 7); + /* Set Flexio2 clock source. */ + CLOCK_SetMux(kCLOCK_Flexio2Mux, 3); + /* Set Pll3 sw clock source. */ + CLOCK_SetMux(kCLOCK_Pll3SwMux, 0); + /* Init ARM PLL. */ + CLOCK_InitArmPll(&armPllConfig_BOARD_BootClockRUN); + /* In SDK projects, SDRAM (configured by SEMC) will be initialized in either debug script or dcd. + * With this macro SKIP_SYSCLK_INIT, system pll (selected to be SEMC source clock in SDK projects) will be left unchanged. + * Note: If another clock source is selected for SEMC, user may want to avoid changing that clock as well.*/ + #ifndef SKIP_SYSCLK_INIT + #if defined(XIP_BOOT_HEADER_DCD_ENABLE) && (XIP_BOOT_HEADER_DCD_ENABLE == 1) + #warning "SKIP_SYSCLK_INIT should be defined to keep system pll (selected to be SEMC source clock in SDK projects) unchanged." + #endif + /* Init System PLL. */ + CLOCK_InitSysPll(&sysPllConfig_BOARD_BootClockRUN); + /* Init System pfd0. */ + CLOCK_InitSysPfd(kCLOCK_Pfd0, 27); + /* Init System pfd1. */ + CLOCK_InitSysPfd(kCLOCK_Pfd1, 16); + /* Init System pfd2. */ + CLOCK_InitSysPfd(kCLOCK_Pfd2, 24); + /* Init System pfd3. */ + CLOCK_InitSysPfd(kCLOCK_Pfd3, 16); + #endif + /* In SDK projects, external flash (configured by FLEXSPI) will be initialized by dcd. + * With this macro XIP_EXTERNAL_FLASH, usb1 pll (selected to be FLEXSPI clock source in SDK projects) will be left unchanged. + * Note: If another clock source is selected for FLEXSPI, user may want to avoid changing that clock as well.*/ + #if !(defined(XIP_EXTERNAL_FLASH) && (XIP_EXTERNAL_FLASH == 1)) + /* Init Usb1 PLL. */ + CLOCK_InitUsb1Pll(&usb1PllConfig_BOARD_BootClockRUN); + /* Init Usb1 pfd0. */ + CLOCK_InitUsb1Pfd(kCLOCK_Pfd0, 33); + /* Init Usb1 pfd1. */ + CLOCK_InitUsb1Pfd(kCLOCK_Pfd1, 16); + /* Init Usb1 pfd2. */ + CLOCK_InitUsb1Pfd(kCLOCK_Pfd2, 17); + /* Init Usb1 pfd3. */ + CLOCK_InitUsb1Pfd(kCLOCK_Pfd3, 19); + /* Disable Usb1 PLL output for USBPHY1. */ + CCM_ANALOG->PLL_USB1 &= ~CCM_ANALOG_PLL_USB1_EN_USB_CLKS_MASK; + #endif + /* DeInit Audio PLL. */ + CLOCK_DeinitAudioPll(); + /* Bypass Audio PLL. */ + CLOCK_SetPllBypass(CCM_ANALOG, kCLOCK_PllAudio, 1); + /* Set divider for Audio PLL. */ + CCM_ANALOG->MISC2 &= ~CCM_ANALOG_MISC2_AUDIO_DIV_LSB_MASK; + CCM_ANALOG->MISC2 &= ~CCM_ANALOG_MISC2_AUDIO_DIV_MSB_MASK; + /* Enable Audio PLL output. */ + CCM_ANALOG->PLL_AUDIO |= CCM_ANALOG_PLL_AUDIO_ENABLE_MASK; + /* Init Video PLL. */ + uint32_t pllVideo; + /* Disable Video PLL output before initial Video PLL. */ + CCM_ANALOG->PLL_VIDEO &= ~CCM_ANALOG_PLL_VIDEO_ENABLE_MASK; + /* Bypass PLL first */ + CCM_ANALOG->PLL_VIDEO = (CCM_ANALOG->PLL_VIDEO & (~CCM_ANALOG_PLL_VIDEO_BYPASS_CLK_SRC_MASK)) | + CCM_ANALOG_PLL_VIDEO_BYPASS_MASK | CCM_ANALOG_PLL_VIDEO_BYPASS_CLK_SRC(0); + CCM_ANALOG->PLL_VIDEO_NUM = CCM_ANALOG_PLL_VIDEO_NUM_A(0); + CCM_ANALOG->PLL_VIDEO_DENOM = CCM_ANALOG_PLL_VIDEO_DENOM_B(1); + pllVideo = (CCM_ANALOG->PLL_VIDEO & (~(CCM_ANALOG_PLL_VIDEO_DIV_SELECT_MASK | CCM_ANALOG_PLL_VIDEO_POWERDOWN_MASK))) | + CCM_ANALOG_PLL_VIDEO_ENABLE_MASK | CCM_ANALOG_PLL_VIDEO_DIV_SELECT(31); + pllVideo |= CCM_ANALOG_PLL_VIDEO_POST_DIV_SELECT(1); + CCM_ANALOG->MISC2 = (CCM_ANALOG->MISC2 & (~CCM_ANALOG_MISC2_VIDEO_DIV_MASK)) | CCM_ANALOG_MISC2_VIDEO_DIV(3); + CCM_ANALOG->PLL_VIDEO = pllVideo; + while ((CCM_ANALOG->PLL_VIDEO & CCM_ANALOG_PLL_VIDEO_LOCK_MASK) == 0) { + } + /* Disable bypass for Video PLL. */ + CLOCK_SetPllBypass(CCM_ANALOG, kCLOCK_PllVideo, 0); + /* DeInit Enet PLL. */ + CLOCK_DeinitEnetPll(); + /* Bypass Enet PLL. */ + CLOCK_SetPllBypass(CCM_ANALOG, kCLOCK_PllEnet, 1); + /* Set Enet output divider. */ + CCM_ANALOG->PLL_ENET = (CCM_ANALOG->PLL_ENET & (~CCM_ANALOG_PLL_ENET_DIV_SELECT_MASK)) | CCM_ANALOG_PLL_ENET_DIV_SELECT(1); + /* Enable Enet output. */ + CCM_ANALOG->PLL_ENET |= CCM_ANALOG_PLL_ENET_ENABLE_MASK; + /* Enable Enet25M output. */ + CCM_ANALOG->PLL_ENET |= CCM_ANALOG_PLL_ENET_ENET_25M_REF_EN_MASK; + /* Set preperiph clock source. */ + CLOCK_SetMux(kCLOCK_PrePeriphMux, 0); + /* Set periph clock source. */ + CLOCK_SetMux(kCLOCK_PeriphMux, 0); + /* Set periph clock2 clock source. */ + CLOCK_SetMux(kCLOCK_PeriphClk2Mux, 0); + /* Set per clock source. */ + CLOCK_SetMux(kCLOCK_PerclkMux, 0); + /* Set lvds1 clock source. */ + CCM_ANALOG->MISC1 = (CCM_ANALOG->MISC1 & (~CCM_ANALOG_MISC1_LVDS1_CLK_SEL_MASK)) | CCM_ANALOG_MISC1_LVDS1_CLK_SEL(0); + /* Set clock out1 divider. */ + CCM->CCOSR = (CCM->CCOSR & (~CCM_CCOSR_CLKO1_DIV_MASK)) | CCM_CCOSR_CLKO1_DIV(0); + /* Set clock out1 source. */ + CCM->CCOSR = (CCM->CCOSR & (~CCM_CCOSR_CLKO1_SEL_MASK)) | CCM_CCOSR_CLKO1_SEL(1); + /* Set clock out2 divider. */ + CCM->CCOSR = (CCM->CCOSR & (~CCM_CCOSR_CLKO2_DIV_MASK)) | CCM_CCOSR_CLKO2_DIV(0); + /* Set clock out2 source. */ + CCM->CCOSR = (CCM->CCOSR & (~CCM_CCOSR_CLKO2_SEL_MASK)) | CCM_CCOSR_CLKO2_SEL(18); + /* Set clock out1 drives clock out1. */ + CCM->CCOSR &= ~CCM_CCOSR_CLK_OUT_SEL_MASK; + /* Disable clock out1. */ + CCM->CCOSR &= ~CCM_CCOSR_CLKO1_EN_MASK; + /* Disable clock out2. */ + CCM->CCOSR &= ~CCM_CCOSR_CLKO2_EN_MASK; + /* Set SAI1 MCLK1 clock source. */ + IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI1MClk1Sel, 0); + /* Set SAI1 MCLK2 clock source. */ + IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI1MClk2Sel, 0); + /* Set SAI1 MCLK3 clock source. */ + IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI1MClk3Sel, 0); + /* Set SAI2 MCLK3 clock source. */ + IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI2MClk3Sel, 0); + /* Set SAI3 MCLK3 clock source. */ + IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI3MClk3Sel, 0); + /* Set MQS configuration. */ + IOMUXC_MQSConfig(IOMUXC_GPR,kIOMUXC_MqsPwmOverSampleRate32, 0); + /* Set ENET Ref clock source. */ + IOMUXC_GPR->GPR1 &= ~IOMUXC_GPR_GPR1_ENET1_TX_CLK_DIR_MASK; + /* Set GPT1 High frequency reference clock source. */ + IOMUXC_GPR->GPR5 &= ~IOMUXC_GPR_GPR5_VREF_1M_CLK_GPT1_MASK; + /* Set GPT2 High frequency reference clock source. */ + IOMUXC_GPR->GPR5 &= ~IOMUXC_GPR_GPR5_VREF_1M_CLK_GPT2_MASK; + /* Set SystemCoreClock variable. */ + SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK; +} diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.c new file mode 100644 index 0000000000..bbd41e7007 --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.c @@ -0,0 +1,356 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "py/obj.h" +#include "py/mphal.h" +#include "mimxrt10xx/periph.h" + +LPI2C_Type *const mcu_i2c_banks[4] = { LPI2C1, LPI2C2, LPI2C3, LPI2C4 }; + +const mcu_periph_obj_t mcu_i2c_sda_list[9] = { + PERIPH_PIN(1, 2, kIOMUXC_LPI2C1_SDA_SELECT_INPUT, 0, &pin_GPIO_SD_B1_05), + PERIPH_PIN(1, 3, kIOMUXC_LPI2C1_SDA_SELECT_INPUT, 1, &pin_GPIO_AD_B1_01), + + PERIPH_PIN(2, 3, kIOMUXC_LPI2C2_SDA_SELECT_INPUT, 0, &pin_GPIO_SD_B1_10), + PERIPH_PIN(2, 2, kIOMUXC_LPI2C2_SDA_SELECT_INPUT, 1, &pin_GPIO_B0_05), + + PERIPH_PIN(3, 2, kIOMUXC_LPI2C3_SDA_SELECT_INPUT, 0, &pin_GPIO_EMC_21), + PERIPH_PIN(3, 2, kIOMUXC_LPI2C3_SDA_SELECT_INPUT, 1, &pin_GPIO_SD_B0_01), + PERIPH_PIN(3, 1, kIOMUXC_LPI2C3_SDA_SELECT_INPUT, 2, &pin_GPIO_AD_B1_06), + + PERIPH_PIN(4, 2, kIOMUXC_LPI2C4_SDA_SELECT_INPUT, 0, &pin_GPIO_EMC_11), + PERIPH_PIN(4, 0, kIOMUXC_LPI2C4_SDA_SELECT_INPUT, 1, &pin_GPIO_AD_B0_13), +}; + +const mcu_periph_obj_t mcu_i2c_scl_list[9] = { + PERIPH_PIN(1, 2, kIOMUXC_LPI2C1_SCL_SELECT_INPUT, 0, &pin_GPIO_SD_B1_04), + PERIPH_PIN(1, 3, kIOMUXC_LPI2C1_SCL_SELECT_INPUT, 1, &pin_GPIO_AD_B1_00), + + PERIPH_PIN(2, 3, kIOMUXC_LPI2C2_SCL_SELECT_INPUT, 0, &pin_GPIO_SD_B1_11), + PERIPH_PIN(2, 2, kIOMUXC_LPI2C2_SCL_SELECT_INPUT, 1, &pin_GPIO_B0_04), + + PERIPH_PIN(3, 2, kIOMUXC_LPI2C3_SCL_SELECT_INPUT, 0, &pin_GPIO_EMC_22), + PERIPH_PIN(3, 2, kIOMUXC_LPI2C3_SCL_SELECT_INPUT, 1, &pin_GPIO_SD_B0_00), + PERIPH_PIN(3, 1, kIOMUXC_LPI2C3_SCL_SELECT_INPUT, 2, &pin_GPIO_AD_B1_07), + + PERIPH_PIN(4, 2, kIOMUXC_LPI2C4_SCL_SELECT_INPUT, 0, &pin_GPIO_EMC_12), + PERIPH_PIN(4, 0, kIOMUXC_LPI2C4_SCL_SELECT_INPUT, 1, &pin_GPIO_AD_B0_12), +}; + +LPSPI_Type *const mcu_spi_banks[3] = { LPSPI1, LPSPI2, LPSPI3 }; + +const mcu_periph_obj_t mcu_spi_sck_list[6] = { + PERIPH_PIN(1, 3, kIOMUXC_LPSPI1_SCK_SELECT_INPUT, 0, &pin_GPIO_EMC_27), + PERIPH_PIN(1, 4, kIOMUXC_LPSPI1_SCK_SELECT_INPUT, 1, &pin_GPIO_SD_B0_00), + + PERIPH_PIN(2, 4, kIOMUXC_LPSPI2_SCK_SELECT_INPUT, 0, &pin_GPIO_SD_B1_07), + PERIPH_PIN(2, 2, kIOMUXC_LPSPI2_SCK_SELECT_INPUT, 1, &pin_GPIO_EMC_00), + + PERIPH_PIN(3, 3, kIOMUXC_LPSPI3_SCK_SELECT_INPUT, 0, &pin_GPIO_B0_03), + PERIPH_PIN(3, 1, kIOMUXC_LPSPI3_SCK_SELECT_INPUT, 1, &pin_GPIO_B1_07), +}; + +const mcu_periph_obj_t mcu_spi_sdo_list[6] = { + PERIPH_PIN(1, 3, kIOMUXC_LPSPI1_SDO_SELECT_INPUT, 0, &pin_GPIO_EMC_28), + PERIPH_PIN(1, 4, kIOMUXC_LPSPI1_SDO_SELECT_INPUT, 1, &pin_GPIO_SD_B0_02), + + PERIPH_PIN(2, 4, kIOMUXC_LPSPI2_SDO_SELECT_INPUT, 0, &pin_GPIO_SD_B1_08), + PERIPH_PIN(2, 2, kIOMUXC_LPSPI2_SDO_SELECT_INPUT, 1, &pin_GPIO_EMC_02), + + PERIPH_PIN(3, 3, kIOMUXC_LPSPI3_SDO_SELECT_INPUT, 0, &pin_GPIO_B0_02), + PERIPH_PIN(3, 1, kIOMUXC_LPSPI3_SDO_SELECT_INPUT, 1, &pin_GPIO_B1_06), +}; + +const mcu_periph_obj_t mcu_spi_sdi_list[6] = { + PERIPH_PIN(1, 3, kIOMUXC_LPSPI1_SDI_SELECT_INPUT, 0, &pin_GPIO_EMC_29), + PERIPH_PIN(1, 4, kIOMUXC_LPSPI1_SDI_SELECT_INPUT, 1, &pin_GPIO_SD_B0_03), + + PERIPH_PIN(2, 4, kIOMUXC_LPSPI2_SDI_SELECT_INPUT, 0, &pin_GPIO_SD_B1_09), + PERIPH_PIN(2, 2, kIOMUXC_LPSPI2_SDI_SELECT_INPUT, 1, &pin_GPIO_EMC_03), + + PERIPH_PIN(3, 3, kIOMUXC_LPSPI3_SDI_SELECT_INPUT, 0, &pin_GPIO_B0_01), + PERIPH_PIN(3, 1, kIOMUXC_LPSPI3_SDI_SELECT_INPUT, 1, &pin_GPIO_B1_05), +}; + +LPUART_Type *const mcu_uart_banks[8] = { LPUART1, LPUART2, LPUART3, LPUART4, LPUART5, LPUART6, LPUART7, LPUART8 }; + +const mcu_periph_obj_t mcu_uart_rx_list[16] = { + PERIPH_PIN(1, 2, 0, 0, &pin_GPIO_AD_B0_13), + + PERIPH_PIN(2, 2, kIOMUXC_LPUART2_RX_SELECT_INPUT, 0, &pin_GPIO_SD_B1_10), + PERIPH_PIN(2, 2, kIOMUXC_LPUART2_RX_SELECT_INPUT, 1, &pin_GPIO_AD_B1_03), + + PERIPH_PIN(3, 2, kIOMUXC_LPUART3_RX_SELECT_INPUT, 0, &pin_GPIO_AD_B1_07), + PERIPH_PIN(3, 2, kIOMUXC_LPUART3_RX_SELECT_INPUT, 1, &pin_GPIO_EMC_14), + PERIPH_PIN(3, 3, kIOMUXC_LPUART3_RX_SELECT_INPUT, 2, &pin_GPIO_B0_09), + + PERIPH_PIN(4, 4, kIOMUXC_LPUART4_RX_SELECT_INPUT, 0, &pin_GPIO_SD_B1_01), + PERIPH_PIN(4, 2, kIOMUXC_LPUART4_RX_SELECT_INPUT, 1, &pin_GPIO_EMC_20), + PERIPH_PIN(4, 2, kIOMUXC_LPUART4_RX_SELECT_INPUT, 2, &pin_GPIO_B1_01), + + PERIPH_PIN(5, 2, kIOMUXC_LPUART5_RX_SELECT_INPUT, 0, &pin_GPIO_EMC_24), + PERIPH_PIN(5, 1, kIOMUXC_LPUART5_RX_SELECT_INPUT, 1, &pin_GPIO_B1_13), + + PERIPH_PIN(6, 2, kIOMUXC_LPUART6_RX_SELECT_INPUT, 0, &pin_GPIO_EMC_26), + + PERIPH_PIN(7, 2, kIOMUXC_LPUART7_RX_SELECT_INPUT, 0, &pin_GPIO_SD_B1_09), + PERIPH_PIN(7, 2, kIOMUXC_LPUART7_RX_SELECT_INPUT, 1, &pin_GPIO_EMC_32), + + PERIPH_PIN(8, 2, kIOMUXC_LPUART8_RX_SELECT_INPUT, 0, &pin_GPIO_SD_B0_05), + PERIPH_PIN(8, 2, kIOMUXC_LPUART8_RX_SELECT_INPUT, 2, &pin_GPIO_EMC_39), +}; + +const mcu_periph_obj_t mcu_uart_tx_list[16] = { + PERIPH_PIN(1, 2, 0, 0, &pin_GPIO_AD_B0_12), + + PERIPH_PIN(2, 2, kIOMUXC_LPUART2_TX_SELECT_INPUT, 0, &pin_GPIO_SD_B1_11), + PERIPH_PIN(2, 2, kIOMUXC_LPUART2_TX_SELECT_INPUT, 1, &pin_GPIO_AD_B1_02), + + PERIPH_PIN(3, 2, kIOMUXC_LPUART3_TX_SELECT_INPUT, 0, &pin_GPIO_AD_B1_06), + PERIPH_PIN(3, 2, kIOMUXC_LPUART3_TX_SELECT_INPUT, 1, &pin_GPIO_EMC_13), + PERIPH_PIN(3, 3, kIOMUXC_LPUART3_TX_SELECT_INPUT, 2, &pin_GPIO_B0_08), + + PERIPH_PIN(4, 4, kIOMUXC_LPUART4_TX_SELECT_INPUT, 0, &pin_GPIO_SD_B1_00), + PERIPH_PIN(4, 2, kIOMUXC_LPUART4_TX_SELECT_INPUT, 1, &pin_GPIO_EMC_19), + PERIPH_PIN(4, 2, kIOMUXC_LPUART4_TX_SELECT_INPUT, 2, &pin_GPIO_B1_00), + + PERIPH_PIN(5, 2, kIOMUXC_LPUART5_TX_SELECT_INPUT, 0, &pin_GPIO_EMC_23), + PERIPH_PIN(5, 1, kIOMUXC_LPUART5_TX_SELECT_INPUT, 1, &pin_GPIO_B1_12), + + PERIPH_PIN(6, 2, kIOMUXC_LPUART6_TX_SELECT_INPUT, 0, &pin_GPIO_EMC_25), + + PERIPH_PIN(7, 2, kIOMUXC_LPUART7_TX_SELECT_INPUT, 0, &pin_GPIO_SD_B1_08), + PERIPH_PIN(7, 2, kIOMUXC_LPUART7_TX_SELECT_INPUT, 1, &pin_GPIO_EMC_31), + + PERIPH_PIN(8, 2, kIOMUXC_LPUART8_TX_SELECT_INPUT, 0, &pin_GPIO_SD_B0_04), + PERIPH_PIN(8, 2, kIOMUXC_LPUART8_TX_SELECT_INPUT, 2, &pin_GPIO_EMC_38), +}; + +const mcu_periph_obj_t mcu_uart_rts_list[9] = { + PERIPH_PIN(1, 2, 0, 0, &pin_GPIO_AD_B0_15), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_AD_B1_01), + + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_EMC_16), + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_AD_B1_05), + + PERIPH_PIN(4, 2, 0, 0, &pin_GPIO_EMC_18), + + PERIPH_PIN(5, 2, 0, 0, &pin_GPIO_EMC_27), + + PERIPH_PIN(6, 2, 0, 0, &pin_GPIO_EMC_29), + + PERIPH_PIN(7, 2, 0, 0, &pin_GPIO_SD_B1_07), + + PERIPH_PIN(8, 2, 0, 0, &pin_GPIO_SD_B0_03), +}; + +const mcu_periph_obj_t mcu_uart_cts_list[9] = { + PERIPH_PIN(1, 2, 0, 0, &pin_GPIO_AD_B0_14), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_AD_B1_00), + + PERIPH_PIN(3, 2, kIOMUXC_LPUART3_CTS_B_SELECT_INPUT, 0, &pin_GPIO_EMC_15), + PERIPH_PIN(3, 2, kIOMUXC_LPUART3_CTS_B_SELECT_INPUT, 1, &pin_GPIO_AD_B1_04), + + PERIPH_PIN(4, 2, 0, 0, &pin_GPIO_EMC_17), + + PERIPH_PIN(5, 2, 0, 0, &pin_GPIO_EMC_28), + + PERIPH_PIN(6, 2, 0, 0, &pin_GPIO_EMC_30), + + PERIPH_PIN(7, 2, 0, 0, &pin_GPIO_SD_B1_06), + + PERIPH_PIN(8, 2, 0, 0, &pin_GPIO_SD_B0_02), +}; + +I2S_Type *const mcu_i2s_banks[3] = { SAI1, SAI2, SAI3 }; + +const mcu_periph_obj_t mcu_i2s_rx_data0_list[6] = { + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_DATA0_SELECT_INPUT, 0, &pin_GPIO_SD_B1_06), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_DATA0_SELECT_INPUT, 2, &pin_GPIO_B1_00), + + PERIPH_PIN(2, 2, kIOMUXC_SAI2_RX_DATA0_SELECT_INPUT, 0, &pin_GPIO_EMC_08), + PERIPH_PIN(2, 3, kIOMUXC_SAI2_RX_DATA0_SELECT_INPUT, 1, &pin_GPIO_AD_B0_08), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_33), + PERIPH_PIN(3, 8, 0, 0, &pin_GPIO_SD_B1_00), +}; + +const mcu_periph_obj_t mcu_i2s_rx_sync_list[6] = { + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_SYNC_SELECT_INPUT, 0, &pin_GPIO_SD_B1_04), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_SYNC_SELECT_INPUT, 2, &pin_GPIO_B0_14), + + PERIPH_PIN(2, 2, kIOMUXC_SAI2_RX_SYNC_SELECT_INPUT, 0, &pin_GPIO_EMC_09), + PERIPH_PIN(2, 3, kIOMUXC_SAI2_RX_SYNC_SELECT_INPUT, 1, &pin_GPIO_AD_B0_07), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_34), + PERIPH_PIN(3, 8, 0, 0, &pin_GPIO_SD_B1_05), +}; + +const mcu_periph_obj_t mcu_i2s_tx_bclk_list[6] = { + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_BCLK_SELECT_INPUT, 0, &pin_GPIO_SD_B1_08), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_BCLK_SELECT_INPUT, 2, &pin_GPIO_B1_02), + + PERIPH_PIN(2, 2, kIOMUXC_SAI2_TX_BCLK_SELECT_INPUT, 0, &pin_GPIO_EMC_06), + PERIPH_PIN(2, 3, kIOMUXC_SAI2_TX_BCLK_SELECT_INPUT, 1, &pin_GPIO_AD_B0_05), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_38), + PERIPH_PIN(3, 8, 0, 0, &pin_GPIO_SD_B1_03), +}; + +const mcu_periph_obj_t mcu_i2s_tx_data0_list[6] = { + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_B1_01), + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_SD_B1_07), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_04), + PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_AD_B0_09), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_36), + PERIPH_PIN(3, 8, 0, 0, &pin_GPIO_SD_B1_01), +}; + +const mcu_periph_obj_t mcu_i2s_tx_sync_list[6] = { + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_SYNC_SELECT_INPUT, 0, &pin_GPIO_SD_B1_09), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_SYNC_SELECT_INPUT, 2, &pin_GPIO_B1_03), + + PERIPH_PIN(2, 2, kIOMUXC_SAI2_TX_SYNC_SELECT_INPUT, 0, &pin_GPIO_EMC_05), + PERIPH_PIN(2, 3, kIOMUXC_SAI2_TX_SYNC_SELECT_INPUT, 1, &pin_GPIO_AD_B0_04), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_39), + PERIPH_PIN(3, 8, 0, 0, &pin_GPIO_SD_B1_02), +}; + +const mcu_periph_obj_t mcu_mqs_left_list[3] = { + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_14), + PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_AD_B0_05), + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_B0_01), +}; + +const mcu_periph_obj_t mcu_mqs_right_list[3] = { + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_13), + PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_AD_B0_04), + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_B0_00), +}; + +const mcu_pwm_obj_t mcu_pwm_list[61] = { + PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_EMC_23_FLEXPWM1_PWMA00, &pin_GPIO_EMC_23), + PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_SD_B0_00_FLEXPWM1_PWMA00, &pin_GPIO_SD_B0_00), + + PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_EMC_24_FLEXPWM1_PWMB00, &pin_GPIO_EMC_24), + PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_SD_B0_01_FLEXPWM1_PWMB00, &pin_GPIO_SD_B0_01), + + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_EMC_25_FLEXPWM1_PWMA01, &pin_GPIO_EMC_25), + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_SD_B0_02_FLEXPWM1_PWMA01, &pin_GPIO_SD_B0_02), + + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_EMC_26_FLEXPWM1_PWMB01, &pin_GPIO_EMC_26), + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_SD_B0_03_FLEXPWM1_PWMB01, &pin_GPIO_SD_B0_03), + + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_EMC_27_FLEXPWM1_PWMA02, &pin_GPIO_EMC_27), + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_SD_B0_04_FLEXPWM1_PWMA02, &pin_GPIO_SD_B0_04), + + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_EMC_28_FLEXPWM1_PWMB02, &pin_GPIO_EMC_28), + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_SD_B0_05_FLEXPWM1_PWMB02, &pin_GPIO_SD_B0_05), + + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmX, IOMUXC_GPIO_AD_B0_12_FLEXPWM1_PWMX02, &pin_GPIO_AD_B0_12), + + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_12_FLEXPWM1_PWMA03, &pin_GPIO_EMC_12), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_38_FLEXPWM1_PWMA03, &pin_GPIO_EMC_38), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_AD_B0_10_FLEXPWM1_PWMA03, &pin_GPIO_AD_B0_10), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_B1_00_FLEXPWM1_PWMA03, &pin_GPIO_B1_00), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_SD_B1_00_FLEXPWM1_PWMA03, &pin_GPIO_SD_B1_00), + + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_13_FLEXPWM1_PWMB03, &pin_GPIO_EMC_13), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_39_FLEXPWM1_PWMB03, &pin_GPIO_EMC_39), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_AD_B0_11_FLEXPWM1_PWMB03, &pin_GPIO_AD_B0_11), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_B1_01_FLEXPWM1_PWMB03, &pin_GPIO_B1_01), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_SD_B1_01_FLEXPWM1_PWMB03, &pin_GPIO_SD_B1_01), + + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmX, IOMUXC_GPIO_AD_B0_13_FLEXPWM1_PWMX03, &pin_GPIO_AD_B0_13), + + PWM_PIN(PWM2, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_EMC_06_FLEXPWM2_PWMA00, &pin_GPIO_EMC_06), + PWM_PIN(PWM2, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_B0_06_FLEXPWM2_PWMA00, &pin_GPIO_B0_06), + + PWM_PIN(PWM2, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_EMC_07_FLEXPWM2_PWMB00, &pin_GPIO_EMC_07), + PWM_PIN(PWM2, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_B0_07_FLEXPWM2_PWMB00, &pin_GPIO_B0_07), + + PWM_PIN(PWM2, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_EMC_08_FLEXPWM2_PWMA01, &pin_GPIO_EMC_08), + PWM_PIN(PWM2, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_B0_08_FLEXPWM2_PWMA01, &pin_GPIO_B0_08), + + PWM_PIN(PWM2, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_EMC_09_FLEXPWM2_PWMB01, &pin_GPIO_EMC_09), + PWM_PIN(PWM2, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_B0_09_FLEXPWM2_PWMB01, &pin_GPIO_B0_09), + + PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_EMC_10_FLEXPWM2_PWMA02, &pin_GPIO_EMC_10), + PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_B0_10_FLEXPWM2_PWMA02, &pin_GPIO_B0_10), + + PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_EMC_11_FLEXPWM2_PWMB02, &pin_GPIO_EMC_11), + PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_B0_11_FLEXPWM2_PWMB02, &pin_GPIO_B0_11), + + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_19_FLEXPWM2_PWMA03, &pin_GPIO_EMC_19), + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_AD_B0_09_FLEXPWM2_PWMA03, &pin_GPIO_AD_B0_09), + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_B1_02_FLEXPWM2_PWMA03, &pin_GPIO_B1_02), + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_SD_B1_02_FLEXPWM2_PWMA03, &pin_GPIO_SD_B1_02), + + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_20_FLEXPWM2_PWMB03, &pin_GPIO_EMC_20), + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_B1_03_FLEXPWM2_PWMB03, &pin_GPIO_B1_03), + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_SD_B1_03_FLEXPWM2_PWMB03, &pin_GPIO_SD_B1_03), + + PWM_PIN(PWM3, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_EMC_29_FLEXPWM3_PWMA00, &pin_GPIO_EMC_29), + + PWM_PIN(PWM3, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_EMC_30_FLEXPWM3_PWMB00, &pin_GPIO_EMC_30), + + PWM_PIN(PWM3, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_EMC_31_FLEXPWM3_PWMA01, &pin_GPIO_EMC_31), + + PWM_PIN(PWM3, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_EMC_32_FLEXPWM3_PWMB01, &pin_GPIO_EMC_32), + + PWM_PIN(PWM3, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_EMC_33_FLEXPWM3_PWMA02, &pin_GPIO_EMC_33), + + PWM_PIN(PWM3, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_EMC_34_FLEXPWM3_PWMB02, &pin_GPIO_EMC_34), + + PWM_PIN(PWM3, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_21_FLEXPWM3_PWMA03, &pin_GPIO_EMC_21), + + PWM_PIN(PWM3, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_22_FLEXPWM3_PWMB03, &pin_GPIO_EMC_22), + + PWM_PIN(PWM4, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_EMC_00_FLEXPWM4_PWMA00, &pin_GPIO_EMC_00), + + PWM_PIN(PWM4, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_EMC_01_FLEXPWM4_PWMB00, &pin_GPIO_EMC_01), + + PWM_PIN(PWM4, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_EMC_02_FLEXPWM4_PWMA01, &pin_GPIO_EMC_02), + + PWM_PIN(PWM4, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_EMC_03_FLEXPWM4_PWMB01, &pin_GPIO_EMC_03), + + PWM_PIN(PWM4, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_EMC_04_FLEXPWM4_PWMA02, &pin_GPIO_EMC_04), + PWM_PIN(PWM4, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_B1_14_FLEXPWM4_PWMA02, &pin_GPIO_B1_14), + + PWM_PIN(PWM4, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_EMC_05_FLEXPWM4_PWMB02, &pin_GPIO_EMC_05), + + PWM_PIN(PWM4, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_17_FLEXPWM4_PWMA03, &pin_GPIO_EMC_17), + PWM_PIN(PWM4, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_B1_15_FLEXPWM4_PWMA03, &pin_GPIO_B1_15), + + PWM_PIN(PWM4, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_18_FLEXPWM4_PWMB03, &pin_GPIO_EMC_18), +}; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.h new file mode 100644 index 0000000000..69a15dc50c --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.h @@ -0,0 +1,55 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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. + */ + +#pragma once +extern LPI2C_Type *const 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]; + +extern LPSPI_Type *const mcu_spi_banks[3]; +extern const mcu_periph_obj_t mcu_spi_sck_list[6]; +extern const mcu_periph_obj_t mcu_spi_sdo_list[6]; +extern const mcu_periph_obj_t mcu_spi_sdi_list[6]; + +extern LPUART_Type *const 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]; +extern const mcu_periph_obj_t mcu_uart_rts_list[9]; +extern const mcu_periph_obj_t mcu_uart_cts_list[9]; + +extern I2S_Type *const mcu_i2s_banks[3]; +extern const mcu_periph_obj_t mcu_i2s_rx_data0_list[6]; +extern const mcu_periph_obj_t mcu_i2s_rx_sync_list[6]; +extern const mcu_periph_obj_t mcu_i2s_tx_bclk_list[6]; +extern const mcu_periph_obj_t mcu_i2s_tx_data0_list[6]; +extern const mcu_periph_obj_t mcu_i2s_tx_sync_list[6]; + +extern const mcu_periph_obj_t mcu_mqs_left_list[3]; +extern const mcu_periph_obj_t mcu_mqs_right_list[3]; + +extern const mcu_pwm_obj_t mcu_pwm_list[61]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pin_names.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pin_names.h new file mode 100644 index 0000000000..05b3110bf3 --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pin_names.h @@ -0,0 +1,151 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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. + */ + + +// define FORMAT_PIN(pin_name) and then include this file. + +FORMAT_PIN(GPIO_EMC_00) +FORMAT_PIN(GPIO_EMC_01) +FORMAT_PIN(GPIO_EMC_02) +FORMAT_PIN(GPIO_EMC_03) +FORMAT_PIN(GPIO_EMC_04) +FORMAT_PIN(GPIO_EMC_05) +FORMAT_PIN(GPIO_EMC_06) +FORMAT_PIN(GPIO_EMC_07) +FORMAT_PIN(GPIO_EMC_08) +FORMAT_PIN(GPIO_EMC_09) +FORMAT_PIN(GPIO_EMC_10) +FORMAT_PIN(GPIO_EMC_11) +FORMAT_PIN(GPIO_EMC_12) +FORMAT_PIN(GPIO_EMC_13) +FORMAT_PIN(GPIO_EMC_14) +FORMAT_PIN(GPIO_EMC_15) +FORMAT_PIN(GPIO_EMC_16) +FORMAT_PIN(GPIO_EMC_17) +FORMAT_PIN(GPIO_EMC_18) +FORMAT_PIN(GPIO_EMC_19) +FORMAT_PIN(GPIO_EMC_20) +FORMAT_PIN(GPIO_EMC_21) +FORMAT_PIN(GPIO_EMC_22) +FORMAT_PIN(GPIO_EMC_23) +FORMAT_PIN(GPIO_EMC_24) +FORMAT_PIN(GPIO_EMC_25) +FORMAT_PIN(GPIO_EMC_26) +FORMAT_PIN(GPIO_EMC_27) +FORMAT_PIN(GPIO_EMC_28) +FORMAT_PIN(GPIO_EMC_29) +FORMAT_PIN(GPIO_EMC_30) +FORMAT_PIN(GPIO_EMC_31) +FORMAT_PIN(GPIO_EMC_32) +FORMAT_PIN(GPIO_EMC_33) +FORMAT_PIN(GPIO_EMC_34) +FORMAT_PIN(GPIO_EMC_35) +FORMAT_PIN(GPIO_EMC_36) +FORMAT_PIN(GPIO_EMC_37) +FORMAT_PIN(GPIO_EMC_38) +FORMAT_PIN(GPIO_EMC_39) +FORMAT_PIN(GPIO_EMC_40) +FORMAT_PIN(GPIO_EMC_41) + +FORMAT_PIN(GPIO_AD_B0_04) +FORMAT_PIN(GPIO_AD_B0_05) +FORMAT_PIN(GPIO_AD_B0_06) +FORMAT_PIN(GPIO_AD_B0_07) +FORMAT_PIN(GPIO_AD_B0_08) +FORMAT_PIN(GPIO_AD_B0_09) +FORMAT_PIN(GPIO_AD_B0_10) +FORMAT_PIN(GPIO_AD_B0_11) +FORMAT_PIN(GPIO_AD_B0_12) +FORMAT_PIN(GPIO_AD_B0_13) +FORMAT_PIN(GPIO_AD_B0_14) +FORMAT_PIN(GPIO_AD_B0_15) + +FORMAT_PIN(GPIO_AD_B1_00) +FORMAT_PIN(GPIO_AD_B1_01) +FORMAT_PIN(GPIO_AD_B1_02) +FORMAT_PIN(GPIO_AD_B1_03) +FORMAT_PIN(GPIO_AD_B1_04) +FORMAT_PIN(GPIO_AD_B1_05) +FORMAT_PIN(GPIO_AD_B1_06) +FORMAT_PIN(GPIO_AD_B1_07) + +FORMAT_PIN(GPIO_B0_00) +FORMAT_PIN(GPIO_B0_01) +FORMAT_PIN(GPIO_B0_02) +FORMAT_PIN(GPIO_B0_03) +FORMAT_PIN(GPIO_B0_04) +FORMAT_PIN(GPIO_B0_05) +FORMAT_PIN(GPIO_B0_06) +FORMAT_PIN(GPIO_B0_07) +FORMAT_PIN(GPIO_B0_08) +FORMAT_PIN(GPIO_B0_09) +FORMAT_PIN(GPIO_B0_10) +FORMAT_PIN(GPIO_B0_11) +FORMAT_PIN(GPIO_B0_12) +FORMAT_PIN(GPIO_B0_13) +FORMAT_PIN(GPIO_B0_14) +FORMAT_PIN(GPIO_B0_15) + +FORMAT_PIN(GPIO_B1_00) +FORMAT_PIN(GPIO_B1_01) +FORMAT_PIN(GPIO_B1_02) +FORMAT_PIN(GPIO_B1_03) +FORMAT_PIN(GPIO_B1_04) +FORMAT_PIN(GPIO_B1_05) +FORMAT_PIN(GPIO_B1_06) +FORMAT_PIN(GPIO_B1_07) +FORMAT_PIN(GPIO_B1_08) +FORMAT_PIN(GPIO_B1_09) +FORMAT_PIN(GPIO_B1_10) +FORMAT_PIN(GPIO_B1_11) +FORMAT_PIN(GPIO_B1_12) +FORMAT_PIN(GPIO_B1_13) +FORMAT_PIN(GPIO_B1_14) +FORMAT_PIN(GPIO_B1_15) + +FORMAT_PIN(GPIO_SD_B0_00) +FORMAT_PIN(GPIO_SD_B0_01) +FORMAT_PIN(GPIO_SD_B0_02) +FORMAT_PIN(GPIO_SD_B0_03) +FORMAT_PIN(GPIO_SD_B0_04) +FORMAT_PIN(GPIO_SD_B0_05) + +FORMAT_PIN(GPIO_SD_B1_00) +FORMAT_PIN(GPIO_SD_B1_01) +FORMAT_PIN(GPIO_SD_B1_02) +FORMAT_PIN(GPIO_SD_B1_03) +FORMAT_PIN(GPIO_SD_B1_04) +FORMAT_PIN(GPIO_SD_B1_05) +FORMAT_PIN(GPIO_SD_B1_06) +FORMAT_PIN(GPIO_SD_B1_07) +FORMAT_PIN(GPIO_SD_B1_08) +FORMAT_PIN(GPIO_SD_B1_09) +FORMAT_PIN(GPIO_SD_B1_10) +FORMAT_PIN(GPIO_SD_B1_11) +FORMAT_PIN(USB_OTG1_DN) +FORMAT_PIN(USB_OTG1_DP) diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pins.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pins.c new file mode 100644 index 0000000000..64d35c2d67 --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pins.c @@ -0,0 +1,147 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "py/obj.h" +#include "py/mphal.h" +#include "mimxrt10xx/pins.h" + +const mcu_pin_obj_t pin_GPIO_EMC_00 = PIN(GPIO4, 0, GPIO_EMC_00, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_01 = PIN(GPIO4, 1, GPIO_EMC_01, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_02 = PIN(GPIO4, 2, GPIO_EMC_02, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_03 = PIN(GPIO4, 3, GPIO_EMC_03, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_04 = PIN(GPIO4, 4, GPIO_EMC_04, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_05 = PIN(GPIO4, 5, GPIO_EMC_05, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_06 = PIN(GPIO4, 6, GPIO_EMC_06, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_07 = PIN(GPIO4, 7, GPIO_EMC_07, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_08 = PIN(GPIO4, 8, GPIO_EMC_08, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_09 = PIN(GPIO4, 9, GPIO_EMC_09, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_10 = PIN(GPIO4, 10, GPIO_EMC_10, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_11 = PIN(GPIO4, 11, GPIO_EMC_11, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_12 = PIN(GPIO4, 12, GPIO_EMC_12, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_13 = PIN(GPIO4, 13, GPIO_EMC_13, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_14 = PIN(GPIO4, 14, GPIO_EMC_14, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_15 = PIN(GPIO4, 15, GPIO_EMC_15, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_16 = PIN(GPIO4, 16, GPIO_EMC_16, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_17 = PIN(GPIO4, 17, GPIO_EMC_17, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_18 = PIN(GPIO4, 18, GPIO_EMC_18, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_19 = PIN(GPIO4, 19, GPIO_EMC_19, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_20 = PIN(GPIO4, 20, GPIO_EMC_20, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_21 = PIN(GPIO4, 21, GPIO_EMC_21, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_22 = PIN(GPIO4, 22, GPIO_EMC_22, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_23 = PIN(GPIO4, 23, GPIO_EMC_23, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_24 = PIN(GPIO4, 24, GPIO_EMC_24, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_25 = PIN(GPIO4, 25, GPIO_EMC_25, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_26 = PIN(GPIO4, 26, GPIO_EMC_26, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_27 = PIN(GPIO4, 27, GPIO_EMC_27, NO_ADC, 0, 0x00000005, 0x000030B0); +const mcu_pin_obj_t pin_GPIO_EMC_28 = PIN(GPIO4, 28, GPIO_EMC_28, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_29 = PIN(GPIO4, 29, GPIO_EMC_29, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_30 = PIN(GPIO4, 30, GPIO_EMC_30, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_31 = PIN(GPIO4, 31, GPIO_EMC_31, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_32 = PIN(GPIO3, 18, GPIO_EMC_32, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_33 = PIN(GPIO3, 19, GPIO_EMC_33, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_34 = PIN(GPIO3, 20, GPIO_EMC_34, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_35 = PIN(GPIO3, 21, GPIO_EMC_35, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_36 = PIN(GPIO3, 22, GPIO_EMC_36, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_37 = PIN(GPIO3, 23, GPIO_EMC_37, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_38 = PIN(GPIO3, 24, GPIO_EMC_38, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_39 = PIN(GPIO3, 25, GPIO_EMC_39, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_40 = PIN(GPIO3, 26, GPIO_EMC_40, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_41 = PIN(GPIO3, 27, GPIO_EMC_41, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_04 = PIN(GPIO1, 4, GPIO_AD_B0_04, NO_ADC, 0, 0x00000000, 0x000030B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_05 = PIN(GPIO1, 5, GPIO_AD_B0_05, NO_ADC, 0, 0x00000000, 0x000030B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_06 = PIN(GPIO1, 6, GPIO_AD_B0_06, NO_ADC, 0, 0x00000000, 0x000070A0); +const mcu_pin_obj_t pin_GPIO_AD_B0_07 = PIN(GPIO1, 7, GPIO_AD_B0_07, NO_ADC, 0, 0x00000000, 0x000030A0); +const mcu_pin_obj_t pin_GPIO_AD_B0_08 = PIN(GPIO1, 8, GPIO_AD_B0_08, NO_ADC, 0, 0x00000000, 0x000030A0); +const mcu_pin_obj_t pin_GPIO_AD_B0_09 = PIN(GPIO1, 9, GPIO_AD_B0_09, NO_ADC, 0, 0x00000000, 0x000070A0); +const mcu_pin_obj_t pin_GPIO_AD_B0_10 = PIN(GPIO1, 10, GPIO_AD_B0_10, NO_ADC, 0, 0x00000000, 0x000090B1); +const mcu_pin_obj_t pin_GPIO_AD_B0_11 = PIN(GPIO1, 11, GPIO_AD_B0_11, NO_ADC, 0, 0x00000000, 0x000070A0); +const mcu_pin_obj_t pin_GPIO_AD_B0_12 = PIN(GPIO1, 12, GPIO_AD_B0_12, ADC1, 1, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_13 = PIN(GPIO1, 13, GPIO_AD_B0_13, ADC1, 2, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_14 = PIN(GPIO1, 14, GPIO_AD_B0_14, ADC1, 3, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_15 = PIN(GPIO1, 15, GPIO_AD_B0_15, ADC1, 4, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_00 = PIN(GPIO1, 16, GPIO_AD_B1_00, ADC2, 5, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_01 = PIN(GPIO1, 17, GPIO_AD_B1_01, ADC2, 6, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_02 = PIN(GPIO1, 18, GPIO_AD_B1_02, ADC2, 7, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_03 = PIN(GPIO1, 19, GPIO_AD_B1_03, ADC2, 8, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_04 = PIN(GPIO1, 20, GPIO_AD_B1_04, ADC2, 9, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_05 = PIN(GPIO1, 21, GPIO_AD_B1_05, ADC2, 10, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_06 = PIN(GPIO1, 22, GPIO_AD_B1_06, ADC2, 11, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_07 = PIN(GPIO1, 23, GPIO_AD_B1_07, ADC2, 12, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_00 = PIN(GPIO2, 0, GPIO_B0_00, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_01 = PIN(GPIO2, 1, GPIO_B0_01, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_02 = PIN(GPIO2, 2, GPIO_B0_02, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_03 = PIN(GPIO2, 3, GPIO_B0_03, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_04 = PIN(GPIO2, 4, GPIO_B0_04, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_05 = PIN(GPIO2, 5, GPIO_B0_05, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_06 = PIN(GPIO2, 6, GPIO_B0_06, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_07 = PIN(GPIO2, 7, GPIO_B0_07, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_08 = PIN(GPIO2, 8, GPIO_B0_08, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_09 = PIN(GPIO2, 9, GPIO_B0_09, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_10 = PIN(GPIO2, 10, GPIO_B0_10, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_11 = PIN(GPIO2, 11, GPIO_B0_11, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_12 = PIN(GPIO2, 12, GPIO_B0_12, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_13 = PIN(GPIO2, 13, GPIO_B0_13, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_14 = PIN(GPIO2, 14, GPIO_B0_14, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_15 = PIN(GPIO2, 15, GPIO_B0_15, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_00 = PIN(GPIO2, 16, GPIO_B1_00, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_01 = PIN(GPIO2, 17, GPIO_B1_01, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_02 = PIN(GPIO2, 18, GPIO_B1_02, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_03 = PIN(GPIO2, 19, GPIO_B1_03, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_04 = PIN(GPIO2, 20, GPIO_B1_04, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_05 = PIN(GPIO2, 21, GPIO_B1_05, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_06 = PIN(GPIO2, 22, GPIO_B1_06, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_07 = PIN(GPIO2, 23, GPIO_B1_07, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_08 = PIN(GPIO2, 24, GPIO_B1_08, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_09 = PIN(GPIO2, 25, GPIO_B1_09, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_10 = PIN(GPIO2, 26, GPIO_B1_10, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_11 = PIN(GPIO2, 27, GPIO_B1_11, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_12 = PIN(GPIO2, 28, GPIO_B1_12, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_13 = PIN(GPIO2, 29, GPIO_B1_13, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_14 = PIN(GPIO2, 30, GPIO_B1_14, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_15 = PIN(GPIO2, 31, GPIO_B1_15, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B0_00 = PIN(GPIO3, 12, GPIO_SD_B0_00, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B0_01 = PIN(GPIO3, 13, GPIO_SD_B0_01, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B0_02 = PIN(GPIO3, 14, GPIO_SD_B0_02, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B0_03 = PIN(GPIO3, 15, GPIO_SD_B0_03, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B0_04 = PIN(GPIO3, 16, GPIO_SD_B0_04, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B0_05 = PIN(GPIO3, 17, GPIO_SD_B0_05, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_00 = PIN(GPIO3, 0, GPIO_SD_B1_00, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_01 = PIN(GPIO3, 1, GPIO_SD_B1_01, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_02 = PIN(GPIO3, 2, GPIO_SD_B1_02, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_03 = PIN(GPIO3, 3, GPIO_SD_B1_03, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_04 = PIN(GPIO3, 4, GPIO_SD_B1_04, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_05 = PIN(GPIO3, 5, GPIO_SD_B1_05, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_06 = PIN(GPIO3, 6, GPIO_SD_B1_06, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_07 = PIN(GPIO3, 7, GPIO_SD_B1_07, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_08 = PIN(GPIO3, 8, GPIO_SD_B1_08, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_09 = PIN(GPIO3, 9, GPIO_SD_B1_09, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_10 = PIN(GPIO3, 10, GPIO_SD_B1_10, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_11 = PIN(GPIO3, 11, GPIO_SD_B1_11, NO_ADC, 0, 0x00000005, 0x000010B0); + +const mcu_pin_obj_t pin_USB_OTG1_DN = { { &mcu_pin_type }, }; +const mcu_pin_obj_t pin_USB_OTG1_DP = { { &mcu_pin_type }, }; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pins.h new file mode 100644 index 0000000000..118eff9335 --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pins.h @@ -0,0 +1,36 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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. + */ + +#pragma once + +#define FORMAT_PIN(pin_name) extern const mcu_pin_obj_t pin_##pin_name; +#include "pin_names.h" +#undef FORMAT_PIN + +#define PIN_COUNT (IOMUXC_SW_PAD_CTL_PAD_COUNT + 2) +extern const mcu_pin_obj_t mcu_pin_list[PIN_COUNT]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/clocks.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/clocks.c new file mode 100644 index 0000000000..832ad9afac --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/clocks.c @@ -0,0 +1,402 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Artur Pacholec + * + * 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. + */ +/* + * Copyright 2019 NXP + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "mpconfigport.h" + +#include "fsl_clock.h" +#include "fsl_iomuxc.h" +#include "fsl_device_registers.h" + +#include "board.h" + +#include "clocks.h" + +#define BOARD_XTAL0_CLK_HZ 24000000U /*!< Board xtal0 frequency in Hz */ +#define BOARD_XTAL32K_CLK_HZ 32768U /*!< Board xtal32k frequency in Hz */ +#define BOARD_BOOTCLOCKRUN_CORE_CLOCK 600000000U /*!< Core clock frequency: 600000000Hz */ + +/******************************************************************************* + * Variables for BOARD_BootClockRUN configuration + ******************************************************************************/ +const clock_arm_pll_config_t armPllConfig_BOARD_BootClockRUN = +{ + .loopDivider = 100, /* PLL loop divider, Fout = Fin * 50 */ + .src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */ +}; +const clock_sys_pll_config_t sysPllConfig_BOARD_BootClockRUN = +{ + .loopDivider = 1, /* PLL loop divider, Fout = Fin * ( 20 + loopDivider*2 + numerator / denominator ) */ + .numerator = 0, /* 30 bit numerator of fractional loop divider */ + .denominator = 1, /* 30 bit denominator of fractional loop divider */ + .src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */ +}; +const clock_usb_pll_config_t usb1PllConfig_BOARD_BootClockRUN = +{ + .loopDivider = 0, /* PLL loop divider, Fout = Fin * 20 */ + .src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */ +}; +const clock_video_pll_config_t videoPllConfig_BOARD_BootClockRUN = +{ + .loopDivider = 31, /* PLL loop divider, Fout = Fin * ( loopDivider + numerator / denominator ) */ + .postDivider = 8, /* Divider after PLL */ + .numerator = 0, /* 30 bit numerator of fractional loop divider, Fout = Fin * ( loopDivider + numerator / denominator ) */ + .denominator = 1, /* 30 bit denominator of fractional loop divider, Fout = Fin * ( loopDivider + numerator / denominator ) */ + .src = 0, /* Bypass clock source, 0 - OSC 24M, 1 - CLK1_P and CLK1_N */ +}; +/******************************************************************************* + * Code for BOARD_BootClockRUN configuration + ******************************************************************************/ +void clocks_init(void) { + /* Init RTC OSC clock frequency. */ + CLOCK_SetRtcXtalFreq(32768U); + /* Enable 1MHz clock output. */ + XTALOSC24M->OSC_CONFIG2 |= XTALOSC24M_OSC_CONFIG2_ENABLE_1M_MASK; + /* Use free 1MHz clock output. */ + XTALOSC24M->OSC_CONFIG2 &= ~XTALOSC24M_OSC_CONFIG2_MUX_1M_MASK; + /* Set XTAL 24MHz clock frequency. */ + CLOCK_SetXtalFreq(24000000U); + /* Enable XTAL 24MHz clock source. */ + CLOCK_InitExternalClk(0); + /* Enable internal RC. */ + CLOCK_InitRcOsc24M(); + /* Switch clock source to external OSC. */ + CLOCK_SwitchOsc(kCLOCK_XtalOsc); + /* Set Oscillator ready counter value. */ + CCM->CCR = (CCM->CCR & (~CCM_CCR_OSCNT_MASK)) | CCM_CCR_OSCNT(127); + /* Setting PeriphClk2Mux and PeriphMux to provide stable clock before PLLs are initialed */ + CLOCK_SetMux(kCLOCK_PeriphClk2Mux, 1); /* Set PERIPH_CLK2 MUX to OSC */ + CLOCK_SetMux(kCLOCK_PeriphMux, 1); /* Set PERIPH_CLK MUX to PERIPH_CLK2 */ + /* Setting the VDD_SOC to 1.275V. It is necessary to config AHB to 600Mhz. */ + DCDC->REG3 = (DCDC->REG3 & (~DCDC_REG3_TRG_MASK)) | DCDC_REG3_TRG(0x13); + /* Waiting for DCDC_STS_DC_OK bit is asserted */ + while (DCDC_REG0_STS_DC_OK_MASK != (DCDC_REG0_STS_DC_OK_MASK & DCDC->REG0)) { + } + /* Set AHB_PODF. */ + CLOCK_SetDiv(kCLOCK_AhbDiv, 0); + /* Disable IPG clock gate. */ + CLOCK_DisableClock(kCLOCK_Adc1); + CLOCK_DisableClock(kCLOCK_Adc2); + CLOCK_DisableClock(kCLOCK_Xbar1); + CLOCK_DisableClock(kCLOCK_Xbar2); + CLOCK_DisableClock(kCLOCK_Xbar3); + /* Set IPG_PODF. */ + CLOCK_SetDiv(kCLOCK_IpgDiv, 3); + /* Set ARM_PODF. */ + CLOCK_SetDiv(kCLOCK_ArmDiv, 1); + /* Set PERIPH_CLK2_PODF. */ + CLOCK_SetDiv(kCLOCK_PeriphClk2Div, 0); + /* Disable PERCLK clock gate. */ + CLOCK_DisableClock(kCLOCK_Gpt1); + CLOCK_DisableClock(kCLOCK_Gpt1S); + CLOCK_DisableClock(kCLOCK_Gpt2); + CLOCK_DisableClock(kCLOCK_Gpt2S); + CLOCK_DisableClock(kCLOCK_Pit); + /* Set PERCLK_PODF. */ + CLOCK_SetDiv(kCLOCK_PerclkDiv, 1); + /* Disable USDHC1 clock gate. */ + CLOCK_DisableClock(kCLOCK_Usdhc1); + /* Set USDHC1_PODF. */ + CLOCK_SetDiv(kCLOCK_Usdhc1Div, 1); + /* Set Usdhc1 clock source. */ + CLOCK_SetMux(kCLOCK_Usdhc1Mux, 0); + /* Disable USDHC2 clock gate. */ + CLOCK_DisableClock(kCLOCK_Usdhc2); + /* Set USDHC2_PODF. */ + CLOCK_SetDiv(kCLOCK_Usdhc2Div, 1); + /* Set Usdhc2 clock source. */ + CLOCK_SetMux(kCLOCK_Usdhc2Mux, 0); + /* In SDK projects, SDRAM (configured by SEMC) will be initialized in either debug script or dcd. + * With this macro SKIP_SYSCLK_INIT, system pll (selected to be SEMC source clock in SDK projects) will be left unchanged. + * Note: If another clock source is selected for SEMC, user may want to avoid changing that clock as well.*/ + #ifndef SKIP_SYSCLK_INIT + /* Disable Semc clock gate. */ + CLOCK_DisableClock(kCLOCK_Semc); + /* Set SEMC_PODF. */ + CLOCK_SetDiv(kCLOCK_SemcDiv, 7); + /* Set Semc alt clock source. */ + CLOCK_SetMux(kCLOCK_SemcAltMux, 0); + /* Set Semc clock source. */ + CLOCK_SetMux(kCLOCK_SemcMux, 0); + #endif + /* In SDK projects, external flash (configured by FLEXSPI) will be initialized by dcd. + * With this macro XIP_EXTERNAL_FLASH, usb1 pll (selected to be FLEXSPI clock source in SDK projects) will be left unchanged. + * Note: If another clock source is selected for FLEXSPI, user may want to avoid changing that clock as well.*/ + #if !(defined(XIP_EXTERNAL_FLASH) && (XIP_EXTERNAL_FLASH == 1)) + #error "whoops" + /* Disable Flexspi clock gate. */ + CLOCK_DisableClock(kCLOCK_FlexSpi); + /* Set FLEXSPI_PODF. */ + CLOCK_SetDiv(kCLOCK_FlexspiDiv, 2); + /* Set Flexspi clock source. */ + CLOCK_SetMux(kCLOCK_FlexspiMux, 1); + #endif + /* Disable CSI clock gate. */ + CLOCK_DisableClock(kCLOCK_Csi); + /* Set CSI_PODF. */ + CLOCK_SetDiv(kCLOCK_CsiDiv, 1); + /* Set Csi clock source. */ + CLOCK_SetMux(kCLOCK_CsiMux, 0); + /* Disable LPSPI clock gate. */ + CLOCK_DisableClock(kCLOCK_Lpspi1); + CLOCK_DisableClock(kCLOCK_Lpspi2); + CLOCK_DisableClock(kCLOCK_Lpspi3); + CLOCK_DisableClock(kCLOCK_Lpspi4); + /* Set LPSPI_PODF. */ + CLOCK_SetDiv(kCLOCK_LpspiDiv, 4); + /* Set Lpspi clock source. */ + CLOCK_SetMux(kCLOCK_LpspiMux, 2); + /* Disable TRACE clock gate. */ + CLOCK_DisableClock(kCLOCK_Trace); + /* Set TRACE_PODF. */ + CLOCK_SetDiv(kCLOCK_TraceDiv, 3); + /* Set Trace clock source. */ + CLOCK_SetMux(kCLOCK_TraceMux, 0); + /* Disable SAI1 clock gate. */ + CLOCK_DisableClock(kCLOCK_Sai1); + /* Set SAI1_CLK_PRED. */ + CLOCK_SetDiv(kCLOCK_Sai1PreDiv, 3); + /* Set SAI1_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_Sai1Div, 1); + /* Set Sai1 clock source. */ + CLOCK_SetMux(kCLOCK_Sai1Mux, 0); + /* Disable SAI2 clock gate. */ + CLOCK_DisableClock(kCLOCK_Sai2); + /* Set SAI2_CLK_PRED. */ + CLOCK_SetDiv(kCLOCK_Sai2PreDiv, 3); + /* Set SAI2_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_Sai2Div, 1); + /* Set Sai2 clock source. */ + CLOCK_SetMux(kCLOCK_Sai2Mux, 0); + /* Disable SAI3 clock gate. */ + CLOCK_DisableClock(kCLOCK_Sai3); + /* Set SAI3_CLK_PRED. */ + CLOCK_SetDiv(kCLOCK_Sai3PreDiv, 3); + /* Set SAI3_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_Sai3Div, 1); + /* Set Sai3 clock source. */ + CLOCK_SetMux(kCLOCK_Sai3Mux, 0); + /* Disable Lpi2c clock gate. */ + CLOCK_DisableClock(kCLOCK_Lpi2c1); + CLOCK_DisableClock(kCLOCK_Lpi2c2); + CLOCK_DisableClock(kCLOCK_Lpi2c3); + /* Set LPI2C_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_Lpi2cDiv, 0); + /* Set Lpi2c clock source. */ + CLOCK_SetMux(kCLOCK_Lpi2cMux, 0); + /* Disable CAN clock gate. */ + CLOCK_DisableClock(kCLOCK_Can1); + CLOCK_DisableClock(kCLOCK_Can2); + CLOCK_DisableClock(kCLOCK_Can1S); + CLOCK_DisableClock(kCLOCK_Can2S); + /* Set CAN_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_CanDiv, 1); + /* Set Can clock source. */ + CLOCK_SetMux(kCLOCK_CanMux, 2); + /* Disable UART clock gate. */ + CLOCK_DisableClock(kCLOCK_Lpuart1); + CLOCK_DisableClock(kCLOCK_Lpuart2); + CLOCK_DisableClock(kCLOCK_Lpuart3); + CLOCK_DisableClock(kCLOCK_Lpuart4); + CLOCK_DisableClock(kCLOCK_Lpuart5); + CLOCK_DisableClock(kCLOCK_Lpuart6); + CLOCK_DisableClock(kCLOCK_Lpuart7); + CLOCK_DisableClock(kCLOCK_Lpuart8); + /* Set UART_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_UartDiv, 0); + /* Set Uart clock source. */ + CLOCK_SetMux(kCLOCK_UartMux, 0); + /* Disable LCDIF clock gate. */ + CLOCK_DisableClock(kCLOCK_LcdPixel); + /* Set LCDIF_PRED. */ + CLOCK_SetDiv(kCLOCK_LcdifPreDiv, 1); + /* Set LCDIF_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_LcdifDiv, 3); + /* Set Lcdif pre clock source. */ + CLOCK_SetMux(kCLOCK_LcdifPreMux, 5); + /* Disable SPDIF clock gate. */ + CLOCK_DisableClock(kCLOCK_Spdif); + /* Set SPDIF0_CLK_PRED. */ + CLOCK_SetDiv(kCLOCK_Spdif0PreDiv, 1); + /* Set SPDIF0_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_Spdif0Div, 7); + /* Set Spdif clock source. */ + CLOCK_SetMux(kCLOCK_SpdifMux, 3); + /* Disable Flexio1 clock gate. */ + CLOCK_DisableClock(kCLOCK_Flexio1); + /* Set FLEXIO1_CLK_PRED. */ + CLOCK_SetDiv(kCLOCK_Flexio1PreDiv, 1); + /* Set FLEXIO1_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_Flexio1Div, 7); + /* Set Flexio1 clock source. */ + CLOCK_SetMux(kCLOCK_Flexio1Mux, 3); + /* Disable Flexio2 clock gate. */ + CLOCK_DisableClock(kCLOCK_Flexio2); + /* Set FLEXIO2_CLK_PRED. */ + CLOCK_SetDiv(kCLOCK_Flexio2PreDiv, 1); + /* Set FLEXIO2_CLK_PODF. */ + CLOCK_SetDiv(kCLOCK_Flexio2Div, 7); + /* Set Flexio2 clock source. */ + CLOCK_SetMux(kCLOCK_Flexio2Mux, 3); + /* Set Pll3 sw clock source. */ + CLOCK_SetMux(kCLOCK_Pll3SwMux, 0); + /* Init ARM PLL. */ + CLOCK_InitArmPll(&armPllConfig_BOARD_BootClockRUN); + /* In SDK projects, SDRAM (configured by SEMC) will be initialized in either debug script or dcd. + * With this macro SKIP_SYSCLK_INIT, system pll (selected to be SEMC source clock in SDK projects) will be left unchanged. + * Note: If another clock source is selected for SEMC, user may want to avoid changing that clock as well.*/ + #ifndef SKIP_SYSCLK_INIT + #if defined(XIP_BOOT_HEADER_DCD_ENABLE) && (XIP_BOOT_HEADER_DCD_ENABLE == 1) + #warning "SKIP_SYSCLK_INIT should be defined to keep system pll (selected to be SEMC source clock in SDK projects) unchanged." + #endif + /* Init System PLL. */ + CLOCK_InitSysPll(&sysPllConfig_BOARD_BootClockRUN); + /* Init System pfd0. */ + CLOCK_InitSysPfd(kCLOCK_Pfd0, 27); + /* Init System pfd1. */ + CLOCK_InitSysPfd(kCLOCK_Pfd1, 16); + /* Init System pfd2. */ + CLOCK_InitSysPfd(kCLOCK_Pfd2, 24); + /* Init System pfd3. */ + CLOCK_InitSysPfd(kCLOCK_Pfd3, 16); + #endif + /* In SDK projects, external flash (configured by FLEXSPI) will be initialized by dcd. + * With this macro XIP_EXTERNAL_FLASH, usb1 pll (selected to be FLEXSPI clock source in SDK projects) will be left unchanged. + * Note: If another clock source is selected for FLEXSPI, user may want to avoid changing that clock as well.*/ + #if !(defined(XIP_EXTERNAL_FLASH) && (XIP_EXTERNAL_FLASH == 1)) + /* Init Usb1 PLL. */ + CLOCK_InitUsb1Pll(&usb1PllConfig_BOARD_BootClockRUN); + /* Init Usb1 pfd0. */ + CLOCK_InitUsb1Pfd(kCLOCK_Pfd0, 33); + /* Init Usb1 pfd1. */ + CLOCK_InitUsb1Pfd(kCLOCK_Pfd1, 16); + /* Init Usb1 pfd2. */ + CLOCK_InitUsb1Pfd(kCLOCK_Pfd2, 17); + /* Init Usb1 pfd3. */ + CLOCK_InitUsb1Pfd(kCLOCK_Pfd3, 19); + /* Disable Usb1 PLL output for USBPHY1. */ + CCM_ANALOG->PLL_USB1 &= ~CCM_ANALOG_PLL_USB1_EN_USB_CLKS_MASK; + #endif + /* DeInit Audio PLL. */ + CLOCK_DeinitAudioPll(); + /* Bypass Audio PLL. */ + CLOCK_SetPllBypass(CCM_ANALOG, kCLOCK_PllAudio, 1); + /* Set divider for Audio PLL. */ + CCM_ANALOG->MISC2 &= ~CCM_ANALOG_MISC2_AUDIO_DIV_LSB_MASK; + CCM_ANALOG->MISC2 &= ~CCM_ANALOG_MISC2_AUDIO_DIV_MSB_MASK; + /* Enable Audio PLL output. */ + CCM_ANALOG->PLL_AUDIO |= CCM_ANALOG_PLL_AUDIO_ENABLE_MASK; + /* Init Video PLL. */ + uint32_t pllVideo; + /* Disable Video PLL output before initial Video PLL. */ + CCM_ANALOG->PLL_VIDEO &= ~CCM_ANALOG_PLL_VIDEO_ENABLE_MASK; + /* Bypass PLL first */ + CCM_ANALOG->PLL_VIDEO = (CCM_ANALOG->PLL_VIDEO & (~CCM_ANALOG_PLL_VIDEO_BYPASS_CLK_SRC_MASK)) | + CCM_ANALOG_PLL_VIDEO_BYPASS_MASK | CCM_ANALOG_PLL_VIDEO_BYPASS_CLK_SRC(0); + CCM_ANALOG->PLL_VIDEO_NUM = CCM_ANALOG_PLL_VIDEO_NUM_A(0); + CCM_ANALOG->PLL_VIDEO_DENOM = CCM_ANALOG_PLL_VIDEO_DENOM_B(1); + pllVideo = (CCM_ANALOG->PLL_VIDEO & (~(CCM_ANALOG_PLL_VIDEO_DIV_SELECT_MASK | CCM_ANALOG_PLL_VIDEO_POWERDOWN_MASK))) | + CCM_ANALOG_PLL_VIDEO_ENABLE_MASK | CCM_ANALOG_PLL_VIDEO_DIV_SELECT(31); + pllVideo |= CCM_ANALOG_PLL_VIDEO_POST_DIV_SELECT(1); + CCM_ANALOG->MISC2 = (CCM_ANALOG->MISC2 & (~CCM_ANALOG_MISC2_VIDEO_DIV_MASK)) | CCM_ANALOG_MISC2_VIDEO_DIV(3); + CCM_ANALOG->PLL_VIDEO = pllVideo; + while ((CCM_ANALOG->PLL_VIDEO & CCM_ANALOG_PLL_VIDEO_LOCK_MASK) == 0) { + } + /* Disable bypass for Video PLL. */ + CLOCK_SetPllBypass(CCM_ANALOG, kCLOCK_PllVideo, 0); + /* DeInit Enet PLL. */ + CLOCK_DeinitEnetPll(); + /* Bypass Enet PLL. */ + CLOCK_SetPllBypass(CCM_ANALOG, kCLOCK_PllEnet, 1); + /* Set Enet output divider. */ + CCM_ANALOG->PLL_ENET = (CCM_ANALOG->PLL_ENET & (~CCM_ANALOG_PLL_ENET_DIV_SELECT_MASK)) | CCM_ANALOG_PLL_ENET_DIV_SELECT(1); + /* Enable Enet output. */ + CCM_ANALOG->PLL_ENET |= CCM_ANALOG_PLL_ENET_ENABLE_MASK; + /* Enable Enet25M output. */ + CCM_ANALOG->PLL_ENET |= CCM_ANALOG_PLL_ENET_ENET_25M_REF_EN_MASK; + /* DeInit Usb2 PLL. */ + CLOCK_DeinitUsb2Pll(); + /* Bypass Usb2 PLL. */ + CLOCK_SetPllBypass(CCM_ANALOG, kCLOCK_PllUsb2, 1); + /* Enable Usb2 PLL output. */ + CCM_ANALOG->PLL_USB2 |= CCM_ANALOG_PLL_USB2_ENABLE_MASK; + /* Set preperiph clock source. */ + CLOCK_SetMux(kCLOCK_PrePeriphMux, 3); + /* Set periph clock source. */ + CLOCK_SetMux(kCLOCK_PeriphMux, 0); + /* Set periph clock2 clock source. */ + CLOCK_SetMux(kCLOCK_PeriphClk2Mux, 0); + /* Set per clock source. */ + CLOCK_SetMux(kCLOCK_PerclkMux, 0); + /* Set lvds1 clock source. */ + CCM_ANALOG->MISC1 = (CCM_ANALOG->MISC1 & (~CCM_ANALOG_MISC1_LVDS1_CLK_SEL_MASK)) | CCM_ANALOG_MISC1_LVDS1_CLK_SEL(0); + /* Set clock out1 divider. */ + CCM->CCOSR = (CCM->CCOSR & (~CCM_CCOSR_CLKO1_DIV_MASK)) | CCM_CCOSR_CLKO1_DIV(0); + /* Set clock out1 source. */ + CCM->CCOSR = (CCM->CCOSR & (~CCM_CCOSR_CLKO1_SEL_MASK)) | CCM_CCOSR_CLKO1_SEL(1); + /* Set clock out2 divider. */ + CCM->CCOSR = (CCM->CCOSR & (~CCM_CCOSR_CLKO2_DIV_MASK)) | CCM_CCOSR_CLKO2_DIV(0); + /* Set clock out2 source. */ + CCM->CCOSR = (CCM->CCOSR & (~CCM_CCOSR_CLKO2_SEL_MASK)) | CCM_CCOSR_CLKO2_SEL(18); + /* Set clock out1 drives clock out1. */ + CCM->CCOSR &= ~CCM_CCOSR_CLK_OUT_SEL_MASK; + /* Disable clock out1. */ + CCM->CCOSR &= ~CCM_CCOSR_CLKO1_EN_MASK; + /* Disable clock out2. */ + CCM->CCOSR &= ~CCM_CCOSR_CLKO2_EN_MASK; + /* Set SAI1 MCLK1 clock source. */ + IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI1MClk1Sel, 0); + /* Set SAI1 MCLK2 clock source. */ + IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI1MClk2Sel, 0); + /* Set SAI1 MCLK3 clock source. */ + IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI1MClk3Sel, 0); + /* Set SAI2 MCLK3 clock source. */ + IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI2MClk3Sel, 0); + /* Set SAI3 MCLK3 clock source. */ + IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI3MClk3Sel, 0); + /* Set MQS configuration. */ + IOMUXC_MQSConfig(IOMUXC_GPR,kIOMUXC_MqsPwmOverSampleRate32, 0); + /* Set ENET Ref clock source. */ + #if defined(IOMUXC_GPR_GPR1_ENET_REF_CLK_DIR_MASK) + IOMUXC_GPR->GPR1 &= ~IOMUXC_GPR_GPR1_ENET_REF_CLK_DIR_MASK; + #elif defined(IOMUXC_GPR_GPR1_ENET1_TX_CLK_DIR_MASK) + /* Backward compatibility for original bitfield name */ + IOMUXC_GPR->GPR1 &= ~IOMUXC_GPR_GPR1_ENET1_TX_CLK_DIR_MASK; + #else + #error "Neither IOMUXC_GPR_GPR1_ENET_REF_CLK_DIR_MASK nor IOMUXC_GPR_GPR1_ENET1_TX_CLK_DIR_MASK is defined." + #endif /* defined(IOMUXC_GPR_GPR1_ENET_REF_CLK_DIR_MASK) */ + /* Set GPT1 High frequency reference clock source. */ + IOMUXC_GPR->GPR5 &= ~IOMUXC_GPR_GPR5_VREF_1M_CLK_GPT1_MASK; + /* Set GPT2 High frequency reference clock source. */ + IOMUXC_GPR->GPR5 &= ~IOMUXC_GPR_GPR5_VREF_1M_CLK_GPT2_MASK; + /* Set SystemCoreClock variable. */ + SystemCoreClock = BOARD_BOOTCLOCKRUN_CORE_CLOCK; +} diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.c new file mode 100644 index 0000000000..35b097f675 --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.c @@ -0,0 +1,377 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "py/obj.h" +#include "py/mphal.h" +#include "mimxrt10xx/periph.h" + +LPI2C_Type *const mcu_i2c_banks[4] = { LPI2C1, LPI2C2, LPI2C3, LPI2C4 }; + +const mcu_periph_obj_t mcu_i2c_sda_list[9] = { + PERIPH_PIN(1, 2, kIOMUXC_LPI2C1_SDA_SELECT_INPUT, 0, &pin_GPIO_SD_B1_05), + PERIPH_PIN(1, 3, kIOMUXC_LPI2C1_SDA_SELECT_INPUT, 1, &pin_GPIO_AD_B1_01), + + PERIPH_PIN(2, 3, kIOMUXC_LPI2C2_SDA_SELECT_INPUT, 0, &pin_GPIO_SD_B1_10), + PERIPH_PIN(2, 2, kIOMUXC_LPI2C2_SDA_SELECT_INPUT, 1, &pin_GPIO_B0_05), + + PERIPH_PIN(3, 2, kIOMUXC_LPI2C3_SDA_SELECT_INPUT, 0, &pin_GPIO_EMC_21), + PERIPH_PIN(3, 2, kIOMUXC_LPI2C3_SDA_SELECT_INPUT, 1, &pin_GPIO_SD_B0_01), + PERIPH_PIN(3, 1, kIOMUXC_LPI2C3_SDA_SELECT_INPUT, 2, &pin_GPIO_AD_B1_06), + + PERIPH_PIN(4, 2, kIOMUXC_LPI2C4_SDA_SELECT_INPUT, 0, &pin_GPIO_EMC_11), + PERIPH_PIN(4, 0, kIOMUXC_LPI2C4_SDA_SELECT_INPUT, 1, &pin_GPIO_AD_B0_13), +}; + +const mcu_periph_obj_t mcu_i2c_scl_list[9] = { + PERIPH_PIN(1, 2, kIOMUXC_LPI2C1_SCL_SELECT_INPUT, 0, &pin_GPIO_SD_B1_04), + PERIPH_PIN(1, 3, kIOMUXC_LPI2C1_SCL_SELECT_INPUT, 1, &pin_GPIO_AD_B1_00), + + PERIPH_PIN(2, 3, kIOMUXC_LPI2C2_SCL_SELECT_INPUT, 0, &pin_GPIO_SD_B1_11), + PERIPH_PIN(2, 2, kIOMUXC_LPI2C2_SCL_SELECT_INPUT, 1, &pin_GPIO_B0_04), + + PERIPH_PIN(3, 2, kIOMUXC_LPI2C3_SCL_SELECT_INPUT, 0, &pin_GPIO_EMC_22), + PERIPH_PIN(3, 2, kIOMUXC_LPI2C3_SCL_SELECT_INPUT, 1, &pin_GPIO_SD_B0_00), + PERIPH_PIN(3, 1, kIOMUXC_LPI2C3_SCL_SELECT_INPUT, 2, &pin_GPIO_AD_B1_07), + + PERIPH_PIN(4, 2, kIOMUXC_LPI2C4_SCL_SELECT_INPUT, 0, &pin_GPIO_EMC_12), + PERIPH_PIN(4, 0, kIOMUXC_LPI2C4_SCL_SELECT_INPUT, 1, &pin_GPIO_AD_B0_12), +}; + +LPSPI_Type *const mcu_spi_banks[4] = { LPSPI1, LPSPI2, LPSPI3, LPSPI4 }; + +const mcu_periph_obj_t mcu_spi_sck_list[8] = { + PERIPH_PIN(1, 3, kIOMUXC_LPSPI1_SCK_SELECT_INPUT, 0, &pin_GPIO_EMC_27), + PERIPH_PIN(1, 4, kIOMUXC_LPSPI1_SCK_SELECT_INPUT, 1, &pin_GPIO_SD_B0_00), + + PERIPH_PIN(2, 4, kIOMUXC_LPSPI2_SCK_SELECT_INPUT, 0, &pin_GPIO_SD_B1_07), + PERIPH_PIN(2, 2, kIOMUXC_LPSPI2_SCK_SELECT_INPUT, 1, &pin_GPIO_EMC_00), + + PERIPH_PIN(3, 7, kIOMUXC_LPSPI3_SCK_SELECT_INPUT, 0, &pin_GPIO_AD_B0_00), + PERIPH_PIN(3, 2, kIOMUXC_LPSPI3_SCK_SELECT_INPUT, 1, &pin_GPIO_AD_B1_15), + + PERIPH_PIN(4, 3, kIOMUXC_LPSPI4_SCK_SELECT_INPUT, 0, &pin_GPIO_B0_03), + PERIPH_PIN(4, 1, kIOMUXC_LPSPI4_SCK_SELECT_INPUT, 1, &pin_GPIO_B1_07), +}; + +const mcu_periph_obj_t mcu_spi_sdo_list[8] = { + PERIPH_PIN(1, 3, kIOMUXC_LPSPI1_SDO_SELECT_INPUT, 0, &pin_GPIO_EMC_28), + PERIPH_PIN(1, 4, kIOMUXC_LPSPI1_SDO_SELECT_INPUT, 1, &pin_GPIO_SD_B0_02), + + PERIPH_PIN(2, 4, kIOMUXC_LPSPI2_SDO_SELECT_INPUT, 0, &pin_GPIO_SD_B1_08), + PERIPH_PIN(2, 2, kIOMUXC_LPSPI2_SDO_SELECT_INPUT, 1, &pin_GPIO_EMC_02), + + PERIPH_PIN(3, 7, kIOMUXC_LPSPI3_SDO_SELECT_INPUT, 0, &pin_GPIO_AD_B0_01), + PERIPH_PIN(3, 2, kIOMUXC_LPSPI3_SDO_SELECT_INPUT, 1, &pin_GPIO_AD_B1_14), + + PERIPH_PIN(4, 3, kIOMUXC_LPSPI4_SDO_SELECT_INPUT, 0, &pin_GPIO_B0_02), + PERIPH_PIN(4, 1, kIOMUXC_LPSPI4_SDO_SELECT_INPUT, 1, &pin_GPIO_B1_06), +}; + +const mcu_periph_obj_t mcu_spi_sdi_list[8] = { + PERIPH_PIN(1, 3, kIOMUXC_LPSPI1_SDI_SELECT_INPUT, 0, &pin_GPIO_EMC_29), + PERIPH_PIN(1, 4, kIOMUXC_LPSPI1_SDI_SELECT_INPUT, 1, &pin_GPIO_SD_B0_03), + + PERIPH_PIN(2, 4, kIOMUXC_LPSPI2_SDI_SELECT_INPUT, 0, &pin_GPIO_SD_B1_09), + PERIPH_PIN(2, 2, kIOMUXC_LPSPI2_SDI_SELECT_INPUT, 1, &pin_GPIO_EMC_03), + + PERIPH_PIN(3, 7, kIOMUXC_LPSPI3_SDI_SELECT_INPUT, 0, &pin_GPIO_AD_B0_02), + PERIPH_PIN(3, 2, kIOMUXC_LPSPI3_SDI_SELECT_INPUT, 1, &pin_GPIO_AD_B1_13), + + PERIPH_PIN(4, 3, kIOMUXC_LPSPI4_SDI_SELECT_INPUT, 0, &pin_GPIO_B0_01), + PERIPH_PIN(4, 1, kIOMUXC_LPSPI4_SDI_SELECT_INPUT, 1, &pin_GPIO_B1_05), +}; + +LPUART_Type *const mcu_uart_banks[8] = { LPUART1, LPUART2, LPUART3, LPUART4, LPUART5, LPUART6, LPUART7, LPUART8 }; + +const mcu_periph_obj_t mcu_uart_rx_list[18] = { + PERIPH_PIN(1, 2, 0, 0, &pin_GPIO_AD_B0_13), + + PERIPH_PIN(2, 2, kIOMUXC_LPUART2_RX_SELECT_INPUT, 0, &pin_GPIO_SD_B1_10), + PERIPH_PIN(2, 2, kIOMUXC_LPUART2_RX_SELECT_INPUT, 1, &pin_GPIO_AD_B1_03), + + PERIPH_PIN(3, 2, kIOMUXC_LPUART3_RX_SELECT_INPUT, 0, &pin_GPIO_AD_B1_07), + PERIPH_PIN(3, 2, kIOMUXC_LPUART3_RX_SELECT_INPUT, 1, &pin_GPIO_EMC_14), + PERIPH_PIN(3, 3, kIOMUXC_LPUART3_RX_SELECT_INPUT, 2, &pin_GPIO_B0_09), + + PERIPH_PIN(4, 4, kIOMUXC_LPUART4_RX_SELECT_INPUT, 0, &pin_GPIO_SD_B1_01), + PERIPH_PIN(4, 2, kIOMUXC_LPUART4_RX_SELECT_INPUT, 1, &pin_GPIO_EMC_20), + PERIPH_PIN(4, 2, kIOMUXC_LPUART4_RX_SELECT_INPUT, 2, &pin_GPIO_B1_01), + + PERIPH_PIN(5, 2, kIOMUXC_LPUART5_RX_SELECT_INPUT, 0, &pin_GPIO_EMC_24), + PERIPH_PIN(5, 1, kIOMUXC_LPUART5_RX_SELECT_INPUT, 1, &pin_GPIO_B1_13), + + PERIPH_PIN(6, 2, kIOMUXC_LPUART6_RX_SELECT_INPUT, 0, &pin_GPIO_EMC_26), + PERIPH_PIN(6, 2, kIOMUXC_LPUART6_RX_SELECT_INPUT, 1, &pin_GPIO_AD_B0_03), + + PERIPH_PIN(7, 2, kIOMUXC_LPUART7_RX_SELECT_INPUT, 0, &pin_GPIO_SD_B1_09), + PERIPH_PIN(7, 2, kIOMUXC_LPUART7_RX_SELECT_INPUT, 1, &pin_GPIO_EMC_32), + + PERIPH_PIN(8, 2, kIOMUXC_LPUART8_RX_SELECT_INPUT, 0, &pin_GPIO_SD_B0_05), + PERIPH_PIN(8, 2, kIOMUXC_LPUART8_RX_SELECT_INPUT, 1, &pin_GPIO_AD_B1_11), + PERIPH_PIN(8, 2, kIOMUXC_LPUART8_RX_SELECT_INPUT, 2, &pin_GPIO_EMC_39), +}; + +const mcu_periph_obj_t mcu_uart_tx_list[18] = { + PERIPH_PIN(1, 2, 0, 0, &pin_GPIO_AD_B0_12), + + PERIPH_PIN(2, 2, kIOMUXC_LPUART2_TX_SELECT_INPUT, 0, &pin_GPIO_SD_B1_11), + PERIPH_PIN(2, 2, kIOMUXC_LPUART2_TX_SELECT_INPUT, 1, &pin_GPIO_AD_B1_02), + + PERIPH_PIN(3, 2, kIOMUXC_LPUART3_TX_SELECT_INPUT, 0, &pin_GPIO_AD_B1_06), + PERIPH_PIN(3, 2, kIOMUXC_LPUART3_TX_SELECT_INPUT, 1, &pin_GPIO_EMC_13), + PERIPH_PIN(3, 3, kIOMUXC_LPUART3_TX_SELECT_INPUT, 2, &pin_GPIO_B0_08), + + PERIPH_PIN(4, 4, kIOMUXC_LPUART4_TX_SELECT_INPUT, 0, &pin_GPIO_SD_B1_00), + PERIPH_PIN(4, 2, kIOMUXC_LPUART4_TX_SELECT_INPUT, 1, &pin_GPIO_EMC_19), + PERIPH_PIN(4, 2, kIOMUXC_LPUART4_TX_SELECT_INPUT, 2, &pin_GPIO_B1_00), + + PERIPH_PIN(5, 2, kIOMUXC_LPUART5_TX_SELECT_INPUT, 0, &pin_GPIO_EMC_23), + PERIPH_PIN(5, 1, kIOMUXC_LPUART5_TX_SELECT_INPUT, 1, &pin_GPIO_B1_12), + + PERIPH_PIN(6, 2, kIOMUXC_LPUART6_TX_SELECT_INPUT, 0, &pin_GPIO_EMC_25), + PERIPH_PIN(6, 2, kIOMUXC_LPUART6_TX_SELECT_INPUT, 1, &pin_GPIO_AD_B0_02), + + PERIPH_PIN(7, 2, kIOMUXC_LPUART7_TX_SELECT_INPUT, 0, &pin_GPIO_SD_B1_08), + PERIPH_PIN(7, 2, kIOMUXC_LPUART7_TX_SELECT_INPUT, 1, &pin_GPIO_EMC_31), + + PERIPH_PIN(8, 2, kIOMUXC_LPUART8_TX_SELECT_INPUT, 0, &pin_GPIO_SD_B0_04), + PERIPH_PIN(8, 2, kIOMUXC_LPUART8_TX_SELECT_INPUT, 1, &pin_GPIO_AD_B1_10), + PERIPH_PIN(8, 2, kIOMUXC_LPUART8_TX_SELECT_INPUT, 2, &pin_GPIO_EMC_38), +}; + +const mcu_periph_obj_t mcu_uart_rts_list[9] = { + PERIPH_PIN(1, 2, 0, 0, &pin_GPIO_AD_B0_15), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_AD_B1_01), + + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_EMC_16), + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_AD_B1_05), + + PERIPH_PIN(4, 2, 0, 0, &pin_GPIO_EMC_18), + + PERIPH_PIN(5, 2, 0, 0, &pin_GPIO_EMC_27), + + PERIPH_PIN(6, 2, 0, 0, &pin_GPIO_EMC_29), + + PERIPH_PIN(7, 2, 0, 0, &pin_GPIO_SD_B1_07), + + PERIPH_PIN(8, 2, 0, 0, &pin_GPIO_SD_B0_03), +}; + +const mcu_periph_obj_t mcu_uart_cts_list[9] = { + PERIPH_PIN(1, 2, 0, 0, &pin_GPIO_AD_B0_14), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_AD_B1_00), + + PERIPH_PIN(3, 2, kIOMUXC_LPUART3_CTS_B_SELECT_INPUT, 0, &pin_GPIO_EMC_15), + PERIPH_PIN(3, 2, kIOMUXC_LPUART3_CTS_B_SELECT_INPUT, 1, &pin_GPIO_AD_B1_04), + + PERIPH_PIN(4, 2, 0, 0, &pin_GPIO_EMC_17), + + PERIPH_PIN(5, 2, 0, 0, &pin_GPIO_EMC_28), + + PERIPH_PIN(6, 2, 0, 0, &pin_GPIO_EMC_30), + + PERIPH_PIN(7, 2, 0, 0, &pin_GPIO_SD_B1_06), + + PERIPH_PIN(8, 2, 0, 0, &pin_GPIO_SD_B0_02), +}; + +I2S_Type *const mcu_i2s_banks[3] = { SAI1, SAI2, SAI3 }; + +const mcu_periph_obj_t mcu_i2s_rx_data0_list[6] = { + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_DATA0_SELECT_INPUT, 0, &pin_GPIO_SD_B1_06), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_DATA0_SELECT_INPUT, 1, &pin_GPIO_AD_B1_12), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_DATA0_SELECT_INPUT, 2, &pin_GPIO_B1_00), + + PERIPH_PIN(2, 2, kIOMUXC_SAI2_RX_DATA0_SELECT_INPUT, 0, &pin_GPIO_EMC_08), + PERIPH_PIN(2, 3, kIOMUXC_SAI2_RX_DATA0_SELECT_INPUT, 1, &pin_GPIO_AD_B0_08), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_33), +}; + +const mcu_periph_obj_t mcu_i2s_rx_sync_list[6] = { + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_SYNC_SELECT_INPUT, 0, &pin_GPIO_SD_B1_04), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_SYNC_SELECT_INPUT, 1, &pin_GPIO_AD_B1_10), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_SYNC_SELECT_INPUT, 2, &pin_GPIO_B0_14), + + PERIPH_PIN(2, 2, kIOMUXC_SAI2_RX_SYNC_SELECT_INPUT, 0, &pin_GPIO_EMC_09), + PERIPH_PIN(2, 3, kIOMUXC_SAI2_RX_SYNC_SELECT_INPUT, 1, &pin_GPIO_AD_B0_07), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_34), +}; + +const mcu_periph_obj_t mcu_i2s_tx_bclk_list[6] = { + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_BCLK_SELECT_INPUT, 0, &pin_GPIO_SD_B1_08), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_BCLK_SELECT_INPUT, 1, &pin_GPIO_AD_B1_14), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_BCLK_SELECT_INPUT, 2, &pin_GPIO_B1_02), + + PERIPH_PIN(2, 2, kIOMUXC_SAI2_TX_BCLK_SELECT_INPUT, 0, &pin_GPIO_EMC_06), + PERIPH_PIN(2, 3, kIOMUXC_SAI2_TX_BCLK_SELECT_INPUT, 1, &pin_GPIO_AD_B0_05), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_38), +}; + +const mcu_periph_obj_t mcu_i2s_tx_data0_list[6] = { + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_AD_B1_13), + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_B1_01), + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_SD_B1_07), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_04), + PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_AD_B0_09), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_36), +}; + +const mcu_periph_obj_t mcu_i2s_tx_sync_list[6] = { + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_SYNC_SELECT_INPUT, 0, &pin_GPIO_SD_B1_09), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_SYNC_SELECT_INPUT, 1, &pin_GPIO_AD_B1_15), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_SYNC_SELECT_INPUT, 2, &pin_GPIO_B1_03), + + PERIPH_PIN(2, 2, kIOMUXC_SAI2_TX_SYNC_SELECT_INPUT, 0, &pin_GPIO_EMC_05), + PERIPH_PIN(2, 3, kIOMUXC_SAI2_TX_SYNC_SELECT_INPUT, 1, &pin_GPIO_AD_B0_04), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_39), +}; + +const mcu_periph_obj_t mcu_mqs_left_list[3] = { + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_14), + PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_AD_B0_05), + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_B0_01), +}; + +const mcu_periph_obj_t mcu_mqs_right_list[3] = { + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_13), + PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_AD_B0_04), + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_B0_00), +}; + +const mcu_pwm_obj_t mcu_pwm_list[67] = { + PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_EMC_23_FLEXPWM1_PWM0_A, &pin_GPIO_EMC_23), + PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_SD_B0_00_FLEXPWM1_PWM0_A, &pin_GPIO_SD_B0_00), + + PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_EMC_24_FLEXPWM1_PWM0_B, &pin_GPIO_EMC_24), + PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_SD_B0_01_FLEXPWM1_PWM0_B, &pin_GPIO_SD_B0_01), + + PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmX, IOMUXC_GPIO_AD_B0_02_FLEXPWM1_PWM0_X, &pin_GPIO_AD_B0_02), + + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_EMC_25_FLEXPWM1_PWM1_A, &pin_GPIO_EMC_25), + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_SD_B0_02_FLEXPWM1_PWM1_A, &pin_GPIO_SD_B0_02), + + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_EMC_26_FLEXPWM1_PWM1_B, &pin_GPIO_EMC_26), + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_SD_B0_03_FLEXPWM1_PWM1_B, &pin_GPIO_SD_B0_03), + + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmX, IOMUXC_GPIO_AD_B0_03_FLEXPWM1_PWM1_X, &pin_GPIO_AD_B0_03), + + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_EMC_27_FLEXPWM1_PWM2_A, &pin_GPIO_EMC_27), + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_SD_B0_04_FLEXPWM1_PWM2_A, &pin_GPIO_SD_B0_04), + + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_EMC_28_FLEXPWM1_PWM2_B, &pin_GPIO_EMC_28), + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_SD_B0_05_FLEXPWM1_PWM2_B, &pin_GPIO_SD_B0_05), + + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmX, IOMUXC_GPIO_AD_B0_12_FLEXPWM1_PWM2_X, &pin_GPIO_AD_B0_12), + + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_12_FLEXPWM1_PWM3_A, &pin_GPIO_EMC_12), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_38_FLEXPWM1_PWM3_A, &pin_GPIO_EMC_38), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_AD_B0_10_FLEXPWM1_PWM3_A, &pin_GPIO_AD_B0_10), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_B1_00_FLEXPWM1_PWM3_A, &pin_GPIO_B1_00), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_SD_B1_00_FLEXPWM1_PWM3_A, &pin_GPIO_SD_B1_00), + + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_13_FLEXPWM1_PWM3_B, &pin_GPIO_EMC_13), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_39_FLEXPWM1_PWM3_B, &pin_GPIO_EMC_39), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_AD_B0_11_FLEXPWM1_PWM3_B, &pin_GPIO_AD_B0_11), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_B1_01_FLEXPWM1_PWM3_B, &pin_GPIO_B1_01), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_SD_B1_01_FLEXPWM1_PWM3_B, &pin_GPIO_SD_B1_01), + + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmX, IOMUXC_GPIO_AD_B0_13_FLEXPWM1_PWM3_X, &pin_GPIO_AD_B0_13), + + PWM_PIN(PWM2, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_EMC_06_FLEXPWM2_PWM0_A, &pin_GPIO_EMC_06), + PWM_PIN(PWM2, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_B0_06_FLEXPWM2_PWM0_A, &pin_GPIO_B0_06), + + PWM_PIN(PWM2, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_EMC_07_FLEXPWM2_PWM0_B, &pin_GPIO_EMC_07), + PWM_PIN(PWM2, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_B0_07_FLEXPWM2_PWM0_B, &pin_GPIO_B0_07), + + PWM_PIN(PWM2, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_EMC_08_FLEXPWM2_PWM1_A, &pin_GPIO_EMC_08), + PWM_PIN(PWM2, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_B0_08_FLEXPWM2_PWM1_A, &pin_GPIO_B0_08), + + PWM_PIN(PWM2, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_EMC_09_FLEXPWM2_PWM1_B, &pin_GPIO_EMC_09), + PWM_PIN(PWM2, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_B0_09_FLEXPWM2_PWM1_B, &pin_GPIO_B0_09), + + PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_EMC_10_FLEXPWM2_PWM2_A, &pin_GPIO_EMC_10), + PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_B0_10_FLEXPWM2_PWM2_A, &pin_GPIO_B0_10), + + PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_EMC_11_FLEXPWM2_PWM2_B, &pin_GPIO_EMC_11), + PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_B0_11_FLEXPWM2_PWM2_B, &pin_GPIO_B0_11), + + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_19_FLEXPWM2_PWM3_A, &pin_GPIO_EMC_19), + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_AD_B0_00_FLEXPWM2_PWM3_A, &pin_GPIO_AD_B0_00), + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_AD_B0_09_FLEXPWM2_PWM3_A, &pin_GPIO_AD_B0_09), + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_B1_02_FLEXPWM2_PWM3_A, &pin_GPIO_B1_02), + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_SD_B1_02_FLEXPWM2_PWM3_A, &pin_GPIO_SD_B1_02), + + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_20_FLEXPWM2_PWM3_B, &pin_GPIO_EMC_20), + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_AD_B0_01_FLEXPWM2_PWM3_B, &pin_GPIO_AD_B0_01), + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_B1_03_FLEXPWM2_PWM3_B, &pin_GPIO_B1_03), + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_SD_B1_03_FLEXPWM2_PWM3_B, &pin_GPIO_SD_B1_03), + + PWM_PIN(PWM3, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_EMC_29_FLEXPWM3_PWM0_A, &pin_GPIO_EMC_29), + + PWM_PIN(PWM3, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_EMC_30_FLEXPWM3_PWM0_B, &pin_GPIO_EMC_30), + + PWM_PIN(PWM3, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_EMC_31_FLEXPWM3_PWM1_A, &pin_GPIO_EMC_31), + + PWM_PIN(PWM3, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_EMC_32_FLEXPWM3_PWM1_B, &pin_GPIO_EMC_32), + + PWM_PIN(PWM3, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_EMC_33_FLEXPWM3_PWM2_A, &pin_GPIO_EMC_33), + + PWM_PIN(PWM3, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_EMC_34_FLEXPWM3_PWM2_B, &pin_GPIO_EMC_34), + + PWM_PIN(PWM3, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_21_FLEXPWM3_PWM3_A, &pin_GPIO_EMC_21), + + PWM_PIN(PWM3, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_22_FLEXPWM3_PWM3_B, &pin_GPIO_EMC_22), + + PWM_PIN(PWM4, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_EMC_00_FLEXPWM4_PWM0_A, &pin_GPIO_EMC_00), + PWM_PIN(PWM4, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_AD_B1_08_FLEXPWM4_PWM0_A, &pin_GPIO_AD_B1_08), + + PWM_PIN(PWM4, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_EMC_01_FLEXPWM4_PWM0_B, &pin_GPIO_EMC_01), + + PWM_PIN(PWM4, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_EMC_02_FLEXPWM4_PWM1_A, &pin_GPIO_EMC_02), + PWM_PIN(PWM4, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_AD_B1_09_FLEXPWM4_PWM1_A, &pin_GPIO_AD_B1_09), + + PWM_PIN(PWM4, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_EMC_03_FLEXPWM4_PWM1_B, &pin_GPIO_EMC_03), + + PWM_PIN(PWM4, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_EMC_04_FLEXPWM4_PWM2_A, &pin_GPIO_EMC_04), + PWM_PIN(PWM4, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_B1_14_FLEXPWM4_PWM2_A, &pin_GPIO_B1_14), + + PWM_PIN(PWM4, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_EMC_05_FLEXPWM4_PWM2_B, &pin_GPIO_EMC_05), + + PWM_PIN(PWM4, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_17_FLEXPWM4_PWM3_A, &pin_GPIO_EMC_17), + PWM_PIN(PWM4, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_B1_15_FLEXPWM4_PWM3_A, &pin_GPIO_B1_15), + + PWM_PIN(PWM4, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_18_FLEXPWM4_PWM3_B, &pin_GPIO_EMC_18), +}; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.h new file mode 100644 index 0000000000..ae6566f974 --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.h @@ -0,0 +1,55 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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. + */ + +#pragma once +extern LPI2C_Type *const 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]; + +extern LPSPI_Type *const mcu_spi_banks[4]; +extern const mcu_periph_obj_t mcu_spi_sck_list[8]; +extern const mcu_periph_obj_t mcu_spi_sdo_list[8]; +extern const mcu_periph_obj_t mcu_spi_sdi_list[8]; + +extern LPUART_Type *const 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]; +extern const mcu_periph_obj_t mcu_uart_rts_list[9]; +extern const mcu_periph_obj_t mcu_uart_cts_list[9]; + +extern I2S_Type *const mcu_i2s_banks[3]; +extern const mcu_periph_obj_t mcu_i2s_rx_data0_list[6]; +extern const mcu_periph_obj_t mcu_i2s_rx_sync_list[6]; +extern const mcu_periph_obj_t mcu_i2s_tx_bclk_list[6]; +extern const mcu_periph_obj_t mcu_i2s_tx_data0_list[6]; +extern const mcu_periph_obj_t mcu_i2s_tx_sync_list[6]; + +extern const mcu_periph_obj_t mcu_mqs_left_list[3]; +extern const mcu_periph_obj_t mcu_mqs_right_list[3]; + +extern const mcu_pwm_obj_t mcu_pwm_list[67]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pin_names.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pin_names.h new file mode 100644 index 0000000000..4b9df709cf --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pin_names.h @@ -0,0 +1,165 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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. + */ + + +// define FORMAT_PIN(pin_name) and then include this file. + +FORMAT_PIN(GPIO_EMC_00) +FORMAT_PIN(GPIO_EMC_01) +FORMAT_PIN(GPIO_EMC_02) +FORMAT_PIN(GPIO_EMC_03) +FORMAT_PIN(GPIO_EMC_04) +FORMAT_PIN(GPIO_EMC_05) +FORMAT_PIN(GPIO_EMC_06) +FORMAT_PIN(GPIO_EMC_07) +FORMAT_PIN(GPIO_EMC_08) +FORMAT_PIN(GPIO_EMC_09) +FORMAT_PIN(GPIO_EMC_10) +FORMAT_PIN(GPIO_EMC_11) +FORMAT_PIN(GPIO_EMC_12) +FORMAT_PIN(GPIO_EMC_13) +FORMAT_PIN(GPIO_EMC_14) +FORMAT_PIN(GPIO_EMC_15) +FORMAT_PIN(GPIO_EMC_16) +FORMAT_PIN(GPIO_EMC_17) +FORMAT_PIN(GPIO_EMC_18) +FORMAT_PIN(GPIO_EMC_19) +FORMAT_PIN(GPIO_EMC_20) +FORMAT_PIN(GPIO_EMC_21) +FORMAT_PIN(GPIO_EMC_22) +FORMAT_PIN(GPIO_EMC_23) +FORMAT_PIN(GPIO_EMC_24) +FORMAT_PIN(GPIO_EMC_25) +FORMAT_PIN(GPIO_EMC_26) +FORMAT_PIN(GPIO_EMC_27) +FORMAT_PIN(GPIO_EMC_28) +FORMAT_PIN(GPIO_EMC_29) +FORMAT_PIN(GPIO_EMC_30) +FORMAT_PIN(GPIO_EMC_31) +FORMAT_PIN(GPIO_EMC_32) +FORMAT_PIN(GPIO_EMC_33) +FORMAT_PIN(GPIO_EMC_34) +FORMAT_PIN(GPIO_EMC_35) +FORMAT_PIN(GPIO_EMC_36) +FORMAT_PIN(GPIO_EMC_37) +FORMAT_PIN(GPIO_EMC_38) +FORMAT_PIN(GPIO_EMC_39) +FORMAT_PIN(GPIO_EMC_40) +FORMAT_PIN(GPIO_EMC_41) + +FORMAT_PIN(GPIO_AD_B0_00) +FORMAT_PIN(GPIO_AD_B0_01) +FORMAT_PIN(GPIO_AD_B0_02) +FORMAT_PIN(GPIO_AD_B0_03) +FORMAT_PIN(GPIO_AD_B0_04) +FORMAT_PIN(GPIO_AD_B0_05) +FORMAT_PIN(GPIO_AD_B0_06) +FORMAT_PIN(GPIO_AD_B0_07) +FORMAT_PIN(GPIO_AD_B0_08) +FORMAT_PIN(GPIO_AD_B0_09) +FORMAT_PIN(GPIO_AD_B0_10) +FORMAT_PIN(GPIO_AD_B0_11) +FORMAT_PIN(GPIO_AD_B0_12) +FORMAT_PIN(GPIO_AD_B0_13) +FORMAT_PIN(GPIO_AD_B0_14) +FORMAT_PIN(GPIO_AD_B0_15) + +FORMAT_PIN(GPIO_AD_B1_00) +FORMAT_PIN(GPIO_AD_B1_01) +FORMAT_PIN(GPIO_AD_B1_02) +FORMAT_PIN(GPIO_AD_B1_03) +FORMAT_PIN(GPIO_AD_B1_04) +FORMAT_PIN(GPIO_AD_B1_05) +FORMAT_PIN(GPIO_AD_B1_06) +FORMAT_PIN(GPIO_AD_B1_07) +FORMAT_PIN(GPIO_AD_B1_08) +FORMAT_PIN(GPIO_AD_B1_09) +FORMAT_PIN(GPIO_AD_B1_10) +FORMAT_PIN(GPIO_AD_B1_11) +FORMAT_PIN(GPIO_AD_B1_12) +FORMAT_PIN(GPIO_AD_B1_13) +FORMAT_PIN(GPIO_AD_B1_14) +FORMAT_PIN(GPIO_AD_B1_15) + +FORMAT_PIN(GPIO_B0_00) +FORMAT_PIN(GPIO_B0_01) +FORMAT_PIN(GPIO_B0_02) +FORMAT_PIN(GPIO_B0_03) +FORMAT_PIN(GPIO_B0_04) +FORMAT_PIN(GPIO_B0_05) +FORMAT_PIN(GPIO_B0_06) +FORMAT_PIN(GPIO_B0_07) +FORMAT_PIN(GPIO_B0_08) +FORMAT_PIN(GPIO_B0_09) +FORMAT_PIN(GPIO_B0_10) +FORMAT_PIN(GPIO_B0_11) +FORMAT_PIN(GPIO_B0_12) +FORMAT_PIN(GPIO_B0_13) +FORMAT_PIN(GPIO_B0_14) +FORMAT_PIN(GPIO_B0_15) + +FORMAT_PIN(GPIO_B1_00) +FORMAT_PIN(GPIO_B1_01) +FORMAT_PIN(GPIO_B1_02) +FORMAT_PIN(GPIO_B1_03) +FORMAT_PIN(GPIO_B1_04) +FORMAT_PIN(GPIO_B1_05) +FORMAT_PIN(GPIO_B1_06) +FORMAT_PIN(GPIO_B1_07) +FORMAT_PIN(GPIO_B1_08) +FORMAT_PIN(GPIO_B1_09) +FORMAT_PIN(GPIO_B1_10) +FORMAT_PIN(GPIO_B1_11) +FORMAT_PIN(GPIO_B1_12) +FORMAT_PIN(GPIO_B1_13) +FORMAT_PIN(GPIO_B1_14) +FORMAT_PIN(GPIO_B1_15) + +FORMAT_PIN(GPIO_SD_B0_00) +FORMAT_PIN(GPIO_SD_B0_01) +FORMAT_PIN(GPIO_SD_B0_02) +FORMAT_PIN(GPIO_SD_B0_03) +FORMAT_PIN(GPIO_SD_B0_04) +FORMAT_PIN(GPIO_SD_B0_05) + +FORMAT_PIN(GPIO_SD_B1_00) +FORMAT_PIN(GPIO_SD_B1_01) +FORMAT_PIN(GPIO_SD_B1_02) +FORMAT_PIN(GPIO_SD_B1_03) +FORMAT_PIN(GPIO_SD_B1_04) +FORMAT_PIN(GPIO_SD_B1_05) +FORMAT_PIN(GPIO_SD_B1_06) +FORMAT_PIN(GPIO_SD_B1_07) +FORMAT_PIN(GPIO_SD_B1_08) +FORMAT_PIN(GPIO_SD_B1_09) +FORMAT_PIN(GPIO_SD_B1_10) +FORMAT_PIN(GPIO_SD_B1_11) +FORMAT_PIN(USB_OTG1_DN) +FORMAT_PIN(USB_OTG1_DP) +FORMAT_PIN(USB_OTG2_DN) +FORMAT_PIN(USB_OTG2_DP) diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pins.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pins.c new file mode 100644 index 0000000000..83bbe18e42 --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pins.c @@ -0,0 +1,161 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "py/obj.h" +#include "py/mphal.h" +#include "mimxrt10xx/pins.h" + +const mcu_pin_obj_t pin_GPIO_EMC_00 = PIN(GPIO4, 0, GPIO_EMC_00, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_01 = PIN(GPIO4, 1, GPIO_EMC_01, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_02 = PIN(GPIO4, 2, GPIO_EMC_02, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_03 = PIN(GPIO4, 3, GPIO_EMC_03, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_04 = PIN(GPIO4, 4, GPIO_EMC_04, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_05 = PIN(GPIO4, 5, GPIO_EMC_05, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_06 = PIN(GPIO4, 6, GPIO_EMC_06, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_07 = PIN(GPIO4, 7, GPIO_EMC_07, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_08 = PIN(GPIO4, 8, GPIO_EMC_08, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_09 = PIN(GPIO4, 9, GPIO_EMC_09, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_10 = PIN(GPIO4, 10, GPIO_EMC_10, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_11 = PIN(GPIO4, 11, GPIO_EMC_11, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_12 = PIN(GPIO4, 12, GPIO_EMC_12, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_13 = PIN(GPIO4, 13, GPIO_EMC_13, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_14 = PIN(GPIO4, 14, GPIO_EMC_14, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_15 = PIN(GPIO4, 15, GPIO_EMC_15, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_16 = PIN(GPIO4, 16, GPIO_EMC_16, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_17 = PIN(GPIO4, 17, GPIO_EMC_17, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_18 = PIN(GPIO4, 18, GPIO_EMC_18, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_19 = PIN(GPIO4, 19, GPIO_EMC_19, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_20 = PIN(GPIO4, 20, GPIO_EMC_20, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_21 = PIN(GPIO4, 21, GPIO_EMC_21, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_22 = PIN(GPIO4, 22, GPIO_EMC_22, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_23 = PIN(GPIO4, 23, GPIO_EMC_23, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_24 = PIN(GPIO4, 24, GPIO_EMC_24, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_25 = PIN(GPIO4, 25, GPIO_EMC_25, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_26 = PIN(GPIO4, 26, GPIO_EMC_26, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_27 = PIN(GPIO4, 27, GPIO_EMC_27, NO_ADC, 0, 0x00000005, 0x000030B0); +const mcu_pin_obj_t pin_GPIO_EMC_28 = PIN(GPIO4, 28, GPIO_EMC_28, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_29 = PIN(GPIO4, 29, GPIO_EMC_29, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_30 = PIN(GPIO4, 30, GPIO_EMC_30, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_31 = PIN(GPIO4, 31, GPIO_EMC_31, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_32 = PIN(GPIO3, 18, GPIO_EMC_32, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_33 = PIN(GPIO3, 19, GPIO_EMC_33, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_34 = PIN(GPIO3, 20, GPIO_EMC_34, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_35 = PIN(GPIO3, 21, GPIO_EMC_35, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_36 = PIN(GPIO3, 22, GPIO_EMC_36, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_37 = PIN(GPIO3, 23, GPIO_EMC_37, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_38 = PIN(GPIO3, 24, GPIO_EMC_38, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_39 = PIN(GPIO3, 25, GPIO_EMC_39, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_40 = PIN(GPIO3, 26, GPIO_EMC_40, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_41 = PIN(GPIO3, 27, GPIO_EMC_41, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_00 = PIN(GPIO1, 0, GPIO_AD_B0_00, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_01 = PIN(GPIO1, 1, GPIO_AD_B0_01, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_02 = PIN(GPIO1, 2, GPIO_AD_B0_02, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_03 = PIN(GPIO1, 3, GPIO_AD_B0_03, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_04 = PIN(GPIO1, 4, GPIO_AD_B0_04, NO_ADC, 0, 0x00000000, 0x000030B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_05 = PIN(GPIO1, 5, GPIO_AD_B0_05, NO_ADC, 0, 0x00000000, 0x000030B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_06 = PIN(GPIO1, 6, GPIO_AD_B0_06, NO_ADC, 0, 0x00000000, 0x000070A0); +const mcu_pin_obj_t pin_GPIO_AD_B0_07 = PIN(GPIO1, 7, GPIO_AD_B0_07, NO_ADC, 0, 0x00000000, 0x000070A0); +const mcu_pin_obj_t pin_GPIO_AD_B0_08 = PIN(GPIO1, 8, GPIO_AD_B0_08, NO_ADC, 0, 0x00000000, 0x0000B0A0); +const mcu_pin_obj_t pin_GPIO_AD_B0_09 = PIN(GPIO1, 9, GPIO_AD_B0_09, NO_ADC, 0, 0x00000000, 0x000070A0); +const mcu_pin_obj_t pin_GPIO_AD_B0_10 = PIN(GPIO1, 10, GPIO_AD_B0_10, NO_ADC, 0, 0x00000000, 0x000090B1); +const mcu_pin_obj_t pin_GPIO_AD_B0_11 = PIN(GPIO1, 11, GPIO_AD_B0_11, NO_ADC, 0, 0x00000000, 0x000070A0); +const mcu_pin_obj_t pin_GPIO_AD_B0_12 = PIN(GPIO1, 12, GPIO_AD_B0_12, ADC1, 1, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_13 = PIN(GPIO1, 13, GPIO_AD_B0_13, ADC1, 2, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_14 = PIN(GPIO1, 14, GPIO_AD_B0_14, ADC1, 3, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B0_15 = PIN(GPIO1, 15, GPIO_AD_B0_15, ADC1, 4, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_00 = PIN(GPIO1, 16, GPIO_AD_B1_00, ADC2, 5, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_01 = PIN(GPIO1, 17, GPIO_AD_B1_01, ADC2, 6, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_02 = PIN(GPIO1, 18, GPIO_AD_B1_02, ADC2, 7, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_03 = PIN(GPIO1, 19, GPIO_AD_B1_03, ADC2, 8, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_04 = PIN(GPIO1, 20, GPIO_AD_B1_04, ADC2, 9, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_05 = PIN(GPIO1, 21, GPIO_AD_B1_05, ADC2, 10, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_06 = PIN(GPIO1, 22, GPIO_AD_B1_06, ADC2, 11, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_07 = PIN(GPIO1, 23, GPIO_AD_B1_07, ADC2, 12, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_08 = PIN(GPIO1, 24, GPIO_AD_B1_08, ADC2, 13, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_09 = PIN(GPIO1, 25, GPIO_AD_B1_09, ADC2, 14, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_10 = PIN(GPIO1, 26, GPIO_AD_B1_10, ADC2, 15, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_11 = PIN(GPIO1, 27, GPIO_AD_B1_11, ADC2, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_12 = PIN(GPIO1, 28, GPIO_AD_B1_12, ADC2, 1, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_13 = PIN(GPIO1, 29, GPIO_AD_B1_13, ADC2, 2, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_14 = PIN(GPIO1, 30, GPIO_AD_B1_14, ADC2, 3, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_15 = PIN(GPIO1, 31, GPIO_AD_B1_15, ADC2, 4, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_00 = PIN(GPIO2, 0, GPIO_B0_00, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_01 = PIN(GPIO2, 1, GPIO_B0_01, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_02 = PIN(GPIO2, 2, GPIO_B0_02, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_03 = PIN(GPIO2, 3, GPIO_B0_03, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_04 = PIN(GPIO2, 4, GPIO_B0_04, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_05 = PIN(GPIO2, 5, GPIO_B0_05, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_06 = PIN(GPIO2, 6, GPIO_B0_06, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_07 = PIN(GPIO2, 7, GPIO_B0_07, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_08 = PIN(GPIO2, 8, GPIO_B0_08, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_09 = PIN(GPIO2, 9, GPIO_B0_09, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_10 = PIN(GPIO2, 10, GPIO_B0_10, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_11 = PIN(GPIO2, 11, GPIO_B0_11, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_12 = PIN(GPIO2, 12, GPIO_B0_12, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_13 = PIN(GPIO2, 13, GPIO_B0_13, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_14 = PIN(GPIO2, 14, GPIO_B0_14, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B0_15 = PIN(GPIO2, 15, GPIO_B0_15, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_00 = PIN(GPIO2, 16, GPIO_B1_00, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_01 = PIN(GPIO2, 17, GPIO_B1_01, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_02 = PIN(GPIO2, 18, GPIO_B1_02, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_03 = PIN(GPIO2, 19, GPIO_B1_03, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_04 = PIN(GPIO2, 20, GPIO_B1_04, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_05 = PIN(GPIO2, 21, GPIO_B1_05, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_06 = PIN(GPIO2, 22, GPIO_B1_06, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_07 = PIN(GPIO2, 23, GPIO_B1_07, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_08 = PIN(GPIO2, 24, GPIO_B1_08, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_09 = PIN(GPIO2, 25, GPIO_B1_09, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_10 = PIN(GPIO2, 26, GPIO_B1_10, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_11 = PIN(GPIO2, 27, GPIO_B1_11, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_12 = PIN(GPIO2, 28, GPIO_B1_12, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_13 = PIN(GPIO2, 29, GPIO_B1_13, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_14 = PIN(GPIO2, 30, GPIO_B1_14, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_B1_15 = PIN(GPIO2, 31, GPIO_B1_15, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B0_00 = PIN(GPIO3, 12, GPIO_SD_B0_00, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B0_01 = PIN(GPIO3, 13, GPIO_SD_B0_01, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B0_02 = PIN(GPIO3, 14, GPIO_SD_B0_02, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B0_03 = PIN(GPIO3, 15, GPIO_SD_B0_03, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B0_04 = PIN(GPIO3, 16, GPIO_SD_B0_04, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B0_05 = PIN(GPIO3, 17, GPIO_SD_B0_05, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_00 = PIN(GPIO3, 0, GPIO_SD_B1_00, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_01 = PIN(GPIO3, 1, GPIO_SD_B1_01, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_02 = PIN(GPIO3, 2, GPIO_SD_B1_02, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_03 = PIN(GPIO3, 3, GPIO_SD_B1_03, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_04 = PIN(GPIO3, 4, GPIO_SD_B1_04, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_05 = PIN(GPIO3, 5, GPIO_SD_B1_05, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_06 = PIN(GPIO3, 6, GPIO_SD_B1_06, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_07 = PIN(GPIO3, 7, GPIO_SD_B1_07, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_08 = PIN(GPIO3, 8, GPIO_SD_B1_08, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_09 = PIN(GPIO3, 9, GPIO_SD_B1_09, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_10 = PIN(GPIO3, 10, GPIO_SD_B1_10, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_SD_B1_11 = PIN(GPIO3, 11, GPIO_SD_B1_11, NO_ADC, 0, 0x00000005, 0x000010B0); + +const mcu_pin_obj_t pin_USB_OTG1_DN = { { &mcu_pin_type }, }; +const mcu_pin_obj_t pin_USB_OTG1_DP = { { &mcu_pin_type }, }; +const mcu_pin_obj_t pin_USB_OTG2_DN = { { &mcu_pin_type }, }; +const mcu_pin_obj_t pin_USB_OTG2_DP = { { &mcu_pin_type }, }; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pins.h new file mode 100644 index 0000000000..6e40d30c2b --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pins.h @@ -0,0 +1,36 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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. + */ + +#pragma once + +#define FORMAT_PIN(pin_name) extern const mcu_pin_obj_t pin_##pin_name; +#include "pin_names.h" +#undef FORMAT_PIN + +#define PIN_COUNT (IOMUXC_SW_PAD_CTL_PAD_COUNT + 4) +extern const mcu_pin_obj_t mcu_pin_list[PIN_COUNT]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.c index c43f4eb96b..12c9a09621 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.c @@ -5,6 +5,7 @@ * * Copyright (c) 2019 Lucian Copeland for Adafruit Industries * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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 @@ -19,7 +20,7 @@ * 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 R COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * 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. @@ -77,7 +78,7 @@ const mcu_periph_obj_t mcu_spi_sck_list[8] = { PERIPH_PIN(4, 1, kIOMUXC_LPSPI4_SCK_SELECT_INPUT, 1, &pin_GPIO_B1_07), }; -const mcu_periph_obj_t mcu_spi_mosi_list[8] = { +const mcu_periph_obj_t mcu_spi_sdo_list[8] = { PERIPH_PIN(1, 3, kIOMUXC_LPSPI1_SDO_SELECT_INPUT, 0, &pin_GPIO_EMC_28), PERIPH_PIN(1, 4, kIOMUXC_LPSPI1_SDO_SELECT_INPUT, 1, &pin_GPIO_SD_B0_02), @@ -91,7 +92,7 @@ const mcu_periph_obj_t mcu_spi_mosi_list[8] = { PERIPH_PIN(4, 1, kIOMUXC_LPSPI4_SDO_SELECT_INPUT, 1, &pin_GPIO_B1_06), }; -const mcu_periph_obj_t mcu_spi_miso_list[8] = { +const mcu_periph_obj_t mcu_spi_sdi_list[8] = { PERIPH_PIN(1, 3, kIOMUXC_LPSPI1_SDI_SELECT_INPUT, 0, &pin_GPIO_EMC_29), PERIPH_PIN(1, 4, kIOMUXC_LPSPI1_SDI_SELECT_INPUT, 1, &pin_GPIO_SD_B0_03), @@ -168,8 +169,8 @@ const mcu_periph_obj_t mcu_uart_rts_list[9] = { PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_AD_B1_01), - PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_AD_B1_05), PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_EMC_16), + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_AD_B1_05), PERIPH_PIN(4, 2, 0, 0, &pin_GPIO_EMC_18), @@ -201,6 +202,80 @@ const mcu_periph_obj_t mcu_uart_cts_list[9] = { PERIPH_PIN(8, 2, 0, 0, &pin_GPIO_SD_B0_02), }; +I2S_Type *const mcu_i2s_banks[3] = { SAI1, SAI2, SAI3 }; + +const mcu_periph_obj_t mcu_i2s_rx_data0_list[7] = { + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_DATA0_SELECT_INPUT, 0, &pin_GPIO_SD_B1_06), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_DATA0_SELECT_INPUT, 1, &pin_GPIO_AD_B1_12), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_DATA0_SELECT_INPUT, 2, &pin_GPIO_B1_00), + + PERIPH_PIN(2, 2, kIOMUXC_SAI2_RX_DATA0_SELECT_INPUT, 0, &pin_GPIO_EMC_08), + PERIPH_PIN(2, 3, kIOMUXC_SAI2_RX_DATA0_SELECT_INPUT, 1, &pin_GPIO_AD_B0_08), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_33), + PERIPH_PIN(3, 8, 0, 0, &pin_GPIO_SD_B1_00), +}; + +const mcu_periph_obj_t mcu_i2s_rx_sync_list[7] = { + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_SYNC_SELECT_INPUT, 0, &pin_GPIO_SD_B1_04), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_SYNC_SELECT_INPUT, 1, &pin_GPIO_AD_B1_10), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_RX_SYNC_SELECT_INPUT, 2, &pin_GPIO_B0_14), + + PERIPH_PIN(2, 2, kIOMUXC_SAI2_RX_SYNC_SELECT_INPUT, 0, &pin_GPIO_EMC_09), + PERIPH_PIN(2, 3, kIOMUXC_SAI2_RX_SYNC_SELECT_INPUT, 1, &pin_GPIO_AD_B0_07), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_34), + PERIPH_PIN(3, 8, 0, 0, &pin_GPIO_SD_B1_05), +}; + +const mcu_periph_obj_t mcu_i2s_tx_bclk_list[7] = { + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_BCLK_SELECT_INPUT, 0, &pin_GPIO_SD_B1_08), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_BCLK_SELECT_INPUT, 1, &pin_GPIO_AD_B1_14), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_BCLK_SELECT_INPUT, 2, &pin_GPIO_B1_02), + + PERIPH_PIN(2, 2, kIOMUXC_SAI2_TX_BCLK_SELECT_INPUT, 0, &pin_GPIO_EMC_06), + PERIPH_PIN(2, 3, kIOMUXC_SAI2_TX_BCLK_SELECT_INPUT, 1, &pin_GPIO_AD_B0_05), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_38), + PERIPH_PIN(3, 8, 0, 0, &pin_GPIO_SD_B1_03), +}; + +const mcu_periph_obj_t mcu_i2s_tx_data0_list[7] = { + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_AD_B1_13), + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_B1_01), + PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_SD_B1_07), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_04), + PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_AD_B0_09), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_36), + PERIPH_PIN(3, 8, 0, 0, &pin_GPIO_SD_B1_01), +}; + +const mcu_periph_obj_t mcu_i2s_tx_sync_list[7] = { + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_SYNC_SELECT_INPUT, 0, &pin_GPIO_SD_B1_09), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_SYNC_SELECT_INPUT, 1, &pin_GPIO_AD_B1_15), + PERIPH_PIN(1, 3, kIOMUXC_SAI1_TX_SYNC_SELECT_INPUT, 2, &pin_GPIO_B1_03), + + PERIPH_PIN(2, 2, kIOMUXC_SAI2_TX_SYNC_SELECT_INPUT, 0, &pin_GPIO_EMC_05), + PERIPH_PIN(2, 3, kIOMUXC_SAI2_TX_SYNC_SELECT_INPUT, 1, &pin_GPIO_AD_B0_04), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_39), + PERIPH_PIN(3, 8, 0, 0, &pin_GPIO_SD_B1_02), +}; + +const mcu_periph_obj_t mcu_mqs_left_list[3] = { + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_14), + PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_AD_B0_05), + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_B0_01), +}; + +const mcu_periph_obj_t mcu_mqs_right_list[3] = { + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_13), + PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_AD_B0_04), + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_B0_00), +}; + const mcu_pwm_obj_t mcu_pwm_list[67] = { PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_EMC_23_FLEXPWM1_PWMA00, &pin_GPIO_EMC_23), PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_SD_B0_00_FLEXPWM1_PWMA00, &pin_GPIO_SD_B0_00), @@ -226,17 +301,17 @@ const mcu_pwm_obj_t mcu_pwm_list[67] = { PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmX, IOMUXC_GPIO_AD_B0_12_FLEXPWM1_PWMX02, &pin_GPIO_AD_B0_12), - PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_AD_B0_10_FLEXPWM1_PWMA03, &pin_GPIO_AD_B0_10), - PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_38_FLEXPWM1_PWMA03, &pin_GPIO_EMC_38), - PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_SD_B1_00_FLEXPWM1_PWMA03, &pin_GPIO_SD_B1_00), PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_12_FLEXPWM1_PWMA03, &pin_GPIO_EMC_12), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_38_FLEXPWM1_PWMA03, &pin_GPIO_EMC_38), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_AD_B0_10_FLEXPWM1_PWMA03, &pin_GPIO_AD_B0_10), PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_B1_00_FLEXPWM1_PWMA03, &pin_GPIO_B1_00), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_SD_B1_00_FLEXPWM1_PWMA03, &pin_GPIO_SD_B1_00), - PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_AD_B0_11_FLEXPWM1_PWMB03, &pin_GPIO_AD_B0_11), - PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_39_FLEXPWM1_PWMB03, &pin_GPIO_EMC_39), - PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_SD_B1_01_FLEXPWM1_PWMB03, &pin_GPIO_SD_B1_01), PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_13_FLEXPWM1_PWMB03, &pin_GPIO_EMC_13), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_39_FLEXPWM1_PWMB03, &pin_GPIO_EMC_39), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_AD_B0_11_FLEXPWM1_PWMB03, &pin_GPIO_AD_B0_11), PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_B1_01_FLEXPWM1_PWMB03, &pin_GPIO_B1_01), + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_SD_B1_01_FLEXPWM1_PWMB03, &pin_GPIO_SD_B1_01), PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmX, IOMUXC_GPIO_AD_B0_13_FLEXPWM1_PWMX03, &pin_GPIO_AD_B0_13), @@ -258,16 +333,16 @@ const mcu_pwm_obj_t mcu_pwm_list[67] = { PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_EMC_11_FLEXPWM2_PWMB02, &pin_GPIO_EMC_11), PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_B0_11_FLEXPWM2_PWMB02, &pin_GPIO_B0_11), + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_19_FLEXPWM2_PWMA03, &pin_GPIO_EMC_19), PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_AD_B0_00_FLEXPWM2_PWMA03, &pin_GPIO_AD_B0_00), PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_AD_B0_09_FLEXPWM2_PWMA03, &pin_GPIO_AD_B0_09), - PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_19_FLEXPWM2_PWMA03, &pin_GPIO_EMC_19), - PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_SD_B1_02_FLEXPWM2_PWMA03, &pin_GPIO_SD_B1_02), PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_B1_02_FLEXPWM2_PWMA03, &pin_GPIO_B1_02), + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_SD_B1_02_FLEXPWM2_PWMA03, &pin_GPIO_SD_B1_02), - PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_AD_B0_01_FLEXPWM2_PWMB03, &pin_GPIO_AD_B0_01), PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_20_FLEXPWM2_PWMB03, &pin_GPIO_EMC_20), - PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_SD_B1_03_FLEXPWM2_PWMB03, &pin_GPIO_SD_B1_03), + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_AD_B0_01_FLEXPWM2_PWMB03, &pin_GPIO_AD_B0_01), PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_B1_03_FLEXPWM2_PWMB03, &pin_GPIO_B1_03), + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_SD_B1_03_FLEXPWM2_PWMB03, &pin_GPIO_SD_B1_03), PWM_PIN(PWM3, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_EMC_29_FLEXPWM3_PWMA00, &pin_GPIO_EMC_29), @@ -285,90 +360,23 @@ const mcu_pwm_obj_t mcu_pwm_list[67] = { PWM_PIN(PWM3, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_22_FLEXPWM3_PWMB03, &pin_GPIO_EMC_22), - PWM_PIN(PWM4, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_AD_B1_08_FLEXPWM4_PWMA00, &pin_GPIO_AD_B1_08), PWM_PIN(PWM4, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_EMC_00_FLEXPWM4_PWMA00, &pin_GPIO_EMC_00), + PWM_PIN(PWM4, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_AD_B1_08_FLEXPWM4_PWMA00, &pin_GPIO_AD_B1_08), PWM_PIN(PWM4, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_EMC_01_FLEXPWM4_PWMB00, &pin_GPIO_EMC_01), - PWM_PIN(PWM4, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_AD_B1_09_FLEXPWM4_PWMA01, &pin_GPIO_AD_B1_09), PWM_PIN(PWM4, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_EMC_02_FLEXPWM4_PWMA01, &pin_GPIO_EMC_02), + PWM_PIN(PWM4, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_AD_B1_09_FLEXPWM4_PWMA01, &pin_GPIO_AD_B1_09), PWM_PIN(PWM4, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_EMC_03_FLEXPWM4_PWMB01, &pin_GPIO_EMC_03), - PWM_PIN(PWM4, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_B1_14_FLEXPWM4_PWMA02, &pin_GPIO_B1_14), PWM_PIN(PWM4, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_EMC_04_FLEXPWM4_PWMA02, &pin_GPIO_EMC_04), + PWM_PIN(PWM4, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_B1_14_FLEXPWM4_PWMA02, &pin_GPIO_B1_14), PWM_PIN(PWM4, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_EMC_05_FLEXPWM4_PWMB02, &pin_GPIO_EMC_05), - PWM_PIN(PWM4, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_B1_15_FLEXPWM4_PWMA03, &pin_GPIO_B1_15), PWM_PIN(PWM4, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_17_FLEXPWM4_PWMA03, &pin_GPIO_EMC_17), + PWM_PIN(PWM4, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_B1_15_FLEXPWM4_PWMA03, &pin_GPIO_B1_15), PWM_PIN(PWM4, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_18_FLEXPWM4_PWMB03, &pin_GPIO_EMC_18), - -}; - -const mcu_periph_obj_t mcu_sai_rx_bclk_list[] = { - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_AD_B1_11), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_B0_15), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_SD_B1_05), - PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_10), - PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_AD_B0_06), - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_35), - PERIPH_PIN(3, 8, 0, 0, &pin_GPIO_SD_B1_00), -}; - -const mcu_periph_obj_t mcu_sai_rx_data0_list[] = { - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_B1_00), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_AD_B1_12), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_AD_B1_06), - PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_AD_B0_08), - PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_08), - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_33), - PERIPH_PIN(3, 8, 0, 0, &pin_GPIO_SD_B1_00), -}; -const mcu_periph_obj_t mcu_sai_rx_sync_list[] = { - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_AD_B1_11), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_B0_15), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_SD_B1_05), - PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_09), - PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_AD_B0_06), - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_34), - PERIPH_PIN(3, 8, 0, 0, &pin_GPIO_SD_B1_05), -}; -const mcu_periph_obj_t mcu_sai_tx_bclk_list[] = { - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_SD_B1_08), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_B1_02), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_AD_B1_14), - PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_AD_B0_05), - PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_EMC_06), - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_38), - PERIPH_PIN(3, 8, 0, 0, &pin_GPIO_SD_B1_03), -}; -const mcu_periph_obj_t mcu_sai_tx_data0_list[] = { - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_AD_B1_13), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_B1_01), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_SD_B1_07), - PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_04), - PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_AD_B0_09), - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_36), - PERIPH_PIN(3, 8, 0, 0, &pin_GPIO_SD_B1_01), -}; -const mcu_periph_obj_t mcu_sai_tx_sync_list[] = { - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_AD_B1_15), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_B1_03), - PERIPH_PIN(1, 3, 0, 0, &pin_GPIO_SD_B1_09), - PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_AD_B0_04), - PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_EMC_05), - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_39), - PERIPH_PIN(3, 8, 0, 0, &pin_GPIO_SD_B1_02), -}; -const mcu_periph_obj_t mcu_mqs_left_list[] = { - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_14), - PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_B0_01), - PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_AD_B0_05), -}; -const mcu_periph_obj_t mcu_mqs_right_list[] = { - PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_13), - PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_B0_00), - PERIPH_PIN(3, 1, 0, 0, &pin_GPIO_AD_B0_04), }; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.h index 28ea8e3742..7917a2ebdb 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.h @@ -3,7 +3,9 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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 @@ -24,37 +26,30 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_MIMXRT10XX_MIMXRT1062_PERIPHERALS_MIMXRT1011_PERIPH_H -#define MICROPY_INCLUDED_MIMXRT10XX_MIMXRT1062_PERIPHERALS_MIMXRT1011_PERIPH_H - +#pragma once extern LPI2C_Type *const 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]; extern LPSPI_Type *const 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]; +extern const mcu_periph_obj_t mcu_spi_sdo_list[8]; +extern const mcu_periph_obj_t mcu_spi_sdi_list[8]; extern LPUART_Type *const 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]; extern const mcu_periph_obj_t mcu_uart_rts_list[9]; extern const mcu_periph_obj_t mcu_uart_cts_list[9]; -extern const mcu_pwm_obj_t mcu_pwm_list[67]; - -extern const mcu_periph_obj_t mcu_sai_rx_bclk_list[7]; -extern const mcu_periph_obj_t mcu_sai_rx_data0_list[7]; -extern const mcu_periph_obj_t mcu_sai_rx_sync_list[7]; -extern const mcu_periph_obj_t mcu_sai_tx_bclk_list[7]; -extern const mcu_periph_obj_t mcu_sai_tx_data0_list[7]; -extern const mcu_periph_obj_t mcu_sai_tx_sync_list[7]; +extern I2S_Type *const mcu_i2s_banks[3]; +extern const mcu_periph_obj_t mcu_i2s_rx_data0_list[7]; +extern const mcu_periph_obj_t mcu_i2s_rx_sync_list[7]; +extern const mcu_periph_obj_t mcu_i2s_tx_bclk_list[7]; +extern const mcu_periph_obj_t mcu_i2s_tx_data0_list[7]; +extern const mcu_periph_obj_t mcu_i2s_tx_sync_list[7]; extern const mcu_periph_obj_t mcu_mqs_left_list[3]; extern const mcu_periph_obj_t mcu_mqs_right_list[3]; -#endif // MICROPY_INCLUDED_MIMXRT10XX_MIMXRT1062_PERIPHERALS_MIMXRT1011_PERIPH_H +extern const mcu_pwm_obj_t mcu_pwm_list[67]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pin_names.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pin_names.h new file mode 100644 index 0000000000..4b9df709cf --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pin_names.h @@ -0,0 +1,165 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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. + */ + + +// define FORMAT_PIN(pin_name) and then include this file. + +FORMAT_PIN(GPIO_EMC_00) +FORMAT_PIN(GPIO_EMC_01) +FORMAT_PIN(GPIO_EMC_02) +FORMAT_PIN(GPIO_EMC_03) +FORMAT_PIN(GPIO_EMC_04) +FORMAT_PIN(GPIO_EMC_05) +FORMAT_PIN(GPIO_EMC_06) +FORMAT_PIN(GPIO_EMC_07) +FORMAT_PIN(GPIO_EMC_08) +FORMAT_PIN(GPIO_EMC_09) +FORMAT_PIN(GPIO_EMC_10) +FORMAT_PIN(GPIO_EMC_11) +FORMAT_PIN(GPIO_EMC_12) +FORMAT_PIN(GPIO_EMC_13) +FORMAT_PIN(GPIO_EMC_14) +FORMAT_PIN(GPIO_EMC_15) +FORMAT_PIN(GPIO_EMC_16) +FORMAT_PIN(GPIO_EMC_17) +FORMAT_PIN(GPIO_EMC_18) +FORMAT_PIN(GPIO_EMC_19) +FORMAT_PIN(GPIO_EMC_20) +FORMAT_PIN(GPIO_EMC_21) +FORMAT_PIN(GPIO_EMC_22) +FORMAT_PIN(GPIO_EMC_23) +FORMAT_PIN(GPIO_EMC_24) +FORMAT_PIN(GPIO_EMC_25) +FORMAT_PIN(GPIO_EMC_26) +FORMAT_PIN(GPIO_EMC_27) +FORMAT_PIN(GPIO_EMC_28) +FORMAT_PIN(GPIO_EMC_29) +FORMAT_PIN(GPIO_EMC_30) +FORMAT_PIN(GPIO_EMC_31) +FORMAT_PIN(GPIO_EMC_32) +FORMAT_PIN(GPIO_EMC_33) +FORMAT_PIN(GPIO_EMC_34) +FORMAT_PIN(GPIO_EMC_35) +FORMAT_PIN(GPIO_EMC_36) +FORMAT_PIN(GPIO_EMC_37) +FORMAT_PIN(GPIO_EMC_38) +FORMAT_PIN(GPIO_EMC_39) +FORMAT_PIN(GPIO_EMC_40) +FORMAT_PIN(GPIO_EMC_41) + +FORMAT_PIN(GPIO_AD_B0_00) +FORMAT_PIN(GPIO_AD_B0_01) +FORMAT_PIN(GPIO_AD_B0_02) +FORMAT_PIN(GPIO_AD_B0_03) +FORMAT_PIN(GPIO_AD_B0_04) +FORMAT_PIN(GPIO_AD_B0_05) +FORMAT_PIN(GPIO_AD_B0_06) +FORMAT_PIN(GPIO_AD_B0_07) +FORMAT_PIN(GPIO_AD_B0_08) +FORMAT_PIN(GPIO_AD_B0_09) +FORMAT_PIN(GPIO_AD_B0_10) +FORMAT_PIN(GPIO_AD_B0_11) +FORMAT_PIN(GPIO_AD_B0_12) +FORMAT_PIN(GPIO_AD_B0_13) +FORMAT_PIN(GPIO_AD_B0_14) +FORMAT_PIN(GPIO_AD_B0_15) + +FORMAT_PIN(GPIO_AD_B1_00) +FORMAT_PIN(GPIO_AD_B1_01) +FORMAT_PIN(GPIO_AD_B1_02) +FORMAT_PIN(GPIO_AD_B1_03) +FORMAT_PIN(GPIO_AD_B1_04) +FORMAT_PIN(GPIO_AD_B1_05) +FORMAT_PIN(GPIO_AD_B1_06) +FORMAT_PIN(GPIO_AD_B1_07) +FORMAT_PIN(GPIO_AD_B1_08) +FORMAT_PIN(GPIO_AD_B1_09) +FORMAT_PIN(GPIO_AD_B1_10) +FORMAT_PIN(GPIO_AD_B1_11) +FORMAT_PIN(GPIO_AD_B1_12) +FORMAT_PIN(GPIO_AD_B1_13) +FORMAT_PIN(GPIO_AD_B1_14) +FORMAT_PIN(GPIO_AD_B1_15) + +FORMAT_PIN(GPIO_B0_00) +FORMAT_PIN(GPIO_B0_01) +FORMAT_PIN(GPIO_B0_02) +FORMAT_PIN(GPIO_B0_03) +FORMAT_PIN(GPIO_B0_04) +FORMAT_PIN(GPIO_B0_05) +FORMAT_PIN(GPIO_B0_06) +FORMAT_PIN(GPIO_B0_07) +FORMAT_PIN(GPIO_B0_08) +FORMAT_PIN(GPIO_B0_09) +FORMAT_PIN(GPIO_B0_10) +FORMAT_PIN(GPIO_B0_11) +FORMAT_PIN(GPIO_B0_12) +FORMAT_PIN(GPIO_B0_13) +FORMAT_PIN(GPIO_B0_14) +FORMAT_PIN(GPIO_B0_15) + +FORMAT_PIN(GPIO_B1_00) +FORMAT_PIN(GPIO_B1_01) +FORMAT_PIN(GPIO_B1_02) +FORMAT_PIN(GPIO_B1_03) +FORMAT_PIN(GPIO_B1_04) +FORMAT_PIN(GPIO_B1_05) +FORMAT_PIN(GPIO_B1_06) +FORMAT_PIN(GPIO_B1_07) +FORMAT_PIN(GPIO_B1_08) +FORMAT_PIN(GPIO_B1_09) +FORMAT_PIN(GPIO_B1_10) +FORMAT_PIN(GPIO_B1_11) +FORMAT_PIN(GPIO_B1_12) +FORMAT_PIN(GPIO_B1_13) +FORMAT_PIN(GPIO_B1_14) +FORMAT_PIN(GPIO_B1_15) + +FORMAT_PIN(GPIO_SD_B0_00) +FORMAT_PIN(GPIO_SD_B0_01) +FORMAT_PIN(GPIO_SD_B0_02) +FORMAT_PIN(GPIO_SD_B0_03) +FORMAT_PIN(GPIO_SD_B0_04) +FORMAT_PIN(GPIO_SD_B0_05) + +FORMAT_PIN(GPIO_SD_B1_00) +FORMAT_PIN(GPIO_SD_B1_01) +FORMAT_PIN(GPIO_SD_B1_02) +FORMAT_PIN(GPIO_SD_B1_03) +FORMAT_PIN(GPIO_SD_B1_04) +FORMAT_PIN(GPIO_SD_B1_05) +FORMAT_PIN(GPIO_SD_B1_06) +FORMAT_PIN(GPIO_SD_B1_07) +FORMAT_PIN(GPIO_SD_B1_08) +FORMAT_PIN(GPIO_SD_B1_09) +FORMAT_PIN(GPIO_SD_B1_10) +FORMAT_PIN(GPIO_SD_B1_11) +FORMAT_PIN(USB_OTG1_DN) +FORMAT_PIN(USB_OTG1_DP) +FORMAT_PIN(USB_OTG2_DN) +FORMAT_PIN(USB_OTG2_DP) diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pins.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pins.c index 7fb5e7a9be..472677ff24 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pins.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pins.c @@ -5,6 +5,7 @@ * * Copyright (c) 2019 Lucian Copeland for Adafruit Industries * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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 @@ -56,7 +57,7 @@ const mcu_pin_obj_t pin_GPIO_EMC_23 = PIN(GPIO4, 23, GPIO_EMC_23, NO_ADC, 0, 0x0 const mcu_pin_obj_t pin_GPIO_EMC_24 = PIN(GPIO4, 24, GPIO_EMC_24, NO_ADC, 0, 0x00000005, 0x000010B0); const mcu_pin_obj_t pin_GPIO_EMC_25 = PIN(GPIO4, 25, GPIO_EMC_25, NO_ADC, 0, 0x00000005, 0x000010B0); const mcu_pin_obj_t pin_GPIO_EMC_26 = PIN(GPIO4, 26, GPIO_EMC_26, NO_ADC, 0, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_EMC_27 = PIN(GPIO4, 27, GPIO_EMC_27, NO_ADC, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_EMC_27 = PIN(GPIO4, 27, GPIO_EMC_27, NO_ADC, 0, 0x00000005, 0x000030B0); const mcu_pin_obj_t pin_GPIO_EMC_28 = PIN(GPIO4, 28, GPIO_EMC_28, NO_ADC, 0, 0x00000005, 0x000010B0); const mcu_pin_obj_t pin_GPIO_EMC_29 = PIN(GPIO4, 29, GPIO_EMC_29, NO_ADC, 0, 0x00000005, 0x000010B0); const mcu_pin_obj_t pin_GPIO_EMC_30 = PIN(GPIO4, 30, GPIO_EMC_30, NO_ADC, 0, 0x00000005, 0x000010B0); @@ -87,18 +88,18 @@ const mcu_pin_obj_t pin_GPIO_AD_B0_12 = PIN(GPIO1, 12, GPIO_AD_B0_12, ADC1, 1, 0 const mcu_pin_obj_t pin_GPIO_AD_B0_13 = PIN(GPIO1, 13, GPIO_AD_B0_13, ADC1, 2, 0x00000005, 0x000010B0); const mcu_pin_obj_t pin_GPIO_AD_B0_14 = PIN(GPIO1, 14, GPIO_AD_B0_14, ADC1, 3, 0x00000005, 0x000010B0); const mcu_pin_obj_t pin_GPIO_AD_B0_15 = PIN(GPIO1, 15, GPIO_AD_B0_15, ADC1, 4, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_00 = PIN(GPIO1, 16, GPIO_AD_B1_00, ADC1, 5, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_01 = PIN(GPIO1, 17, GPIO_AD_B1_01, ADC1, 6, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_02 = PIN(GPIO1, 18, GPIO_AD_B1_02, ADC1, 7, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_03 = PIN(GPIO1, 19, GPIO_AD_B1_03, ADC1, 8, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_04 = PIN(GPIO1, 20, GPIO_AD_B1_04, ADC1, 9, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_05 = PIN(GPIO1, 21, GPIO_AD_B1_05, ADC1, 10, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_06 = PIN(GPIO1, 22, GPIO_AD_B1_06, ADC1, 11, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_07 = PIN(GPIO1, 23, GPIO_AD_B1_07, ADC1, 12, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_08 = PIN(GPIO1, 24, GPIO_AD_B1_08, ADC1, 13, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_09 = PIN(GPIO1, 25, GPIO_AD_B1_09, ADC1, 14, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_10 = PIN(GPIO1, 26, GPIO_AD_B1_10, ADC1, 15, 0x00000005, 0x000010B0); -const mcu_pin_obj_t pin_GPIO_AD_B1_11 = PIN(GPIO1, 27, GPIO_AD_B1_11, ADC1, 0, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_00 = PIN(GPIO1, 16, GPIO_AD_B1_00, ADC2, 5, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_01 = PIN(GPIO1, 17, GPIO_AD_B1_01, ADC2, 6, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_02 = PIN(GPIO1, 18, GPIO_AD_B1_02, ADC2, 7, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_03 = PIN(GPIO1, 19, GPIO_AD_B1_03, ADC2, 8, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_04 = PIN(GPIO1, 20, GPIO_AD_B1_04, ADC2, 9, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_05 = PIN(GPIO1, 21, GPIO_AD_B1_05, ADC2, 10, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_06 = PIN(GPIO1, 22, GPIO_AD_B1_06, ADC2, 11, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_07 = PIN(GPIO1, 23, GPIO_AD_B1_07, ADC2, 12, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_08 = PIN(GPIO1, 24, GPIO_AD_B1_08, ADC2, 13, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_09 = PIN(GPIO1, 25, GPIO_AD_B1_09, ADC2, 14, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_10 = PIN(GPIO1, 26, GPIO_AD_B1_10, ADC2, 15, 0x00000005, 0x000010B0); +const mcu_pin_obj_t pin_GPIO_AD_B1_11 = PIN(GPIO1, 27, GPIO_AD_B1_11, ADC2, 0, 0x00000005, 0x000010B0); const mcu_pin_obj_t pin_GPIO_AD_B1_12 = PIN(GPIO1, 28, GPIO_AD_B1_12, ADC2, 1, 0x00000005, 0x000010B0); const mcu_pin_obj_t pin_GPIO_AD_B1_13 = PIN(GPIO1, 29, GPIO_AD_B1_13, ADC2, 2, 0x00000005, 0x000010B0); const mcu_pin_obj_t pin_GPIO_AD_B1_14 = PIN(GPIO1, 30, GPIO_AD_B1_14, ADC2, 3, 0x00000005, 0x000010B0); diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pins.h index 109882df93..6e40d30c2b 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pins.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pins.h @@ -3,7 +3,9 @@ * * The MIT License (MIT) * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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 @@ -24,145 +26,11 @@ * THE SOFTWARE. */ -#ifndef MICROPY_INCLUDED_MIMXRT10XX_PERIPHERALS_MIMXRT1062_PINS_H -#define MICROPY_INCLUDED_MIMXRT10XX_PERIPHERALS_MIMXRT1062_PINS_H +#pragma once -extern const mcu_pin_obj_t pin_GPIO_EMC_00; -extern const mcu_pin_obj_t pin_GPIO_EMC_01; -extern const mcu_pin_obj_t pin_GPIO_EMC_02; -extern const mcu_pin_obj_t pin_GPIO_EMC_03; -extern const mcu_pin_obj_t pin_GPIO_EMC_04; -extern const mcu_pin_obj_t pin_GPIO_EMC_05; -extern const mcu_pin_obj_t pin_GPIO_EMC_06; -extern const mcu_pin_obj_t pin_GPIO_EMC_07; -extern const mcu_pin_obj_t pin_GPIO_EMC_08; -extern const mcu_pin_obj_t pin_GPIO_EMC_09; -extern const mcu_pin_obj_t pin_GPIO_EMC_10; -extern const mcu_pin_obj_t pin_GPIO_EMC_11; -extern const mcu_pin_obj_t pin_GPIO_EMC_12; -extern const mcu_pin_obj_t pin_GPIO_EMC_13; -extern const mcu_pin_obj_t pin_GPIO_EMC_14; -extern const mcu_pin_obj_t pin_GPIO_EMC_15; -extern const mcu_pin_obj_t pin_GPIO_EMC_16; -extern const mcu_pin_obj_t pin_GPIO_EMC_17; -extern const mcu_pin_obj_t pin_GPIO_EMC_18; -extern const mcu_pin_obj_t pin_GPIO_EMC_19; -extern const mcu_pin_obj_t pin_GPIO_EMC_20; -extern const mcu_pin_obj_t pin_GPIO_EMC_21; -extern const mcu_pin_obj_t pin_GPIO_EMC_22; -extern const mcu_pin_obj_t pin_GPIO_EMC_23; -extern const mcu_pin_obj_t pin_GPIO_EMC_24; -extern const mcu_pin_obj_t pin_GPIO_EMC_25; -extern const mcu_pin_obj_t pin_GPIO_EMC_26; -extern const mcu_pin_obj_t pin_GPIO_EMC_27; -extern const mcu_pin_obj_t pin_GPIO_EMC_28; -extern const mcu_pin_obj_t pin_GPIO_EMC_29; -extern const mcu_pin_obj_t pin_GPIO_EMC_30; -extern const mcu_pin_obj_t pin_GPIO_EMC_31; -extern const mcu_pin_obj_t pin_GPIO_EMC_32; -extern const mcu_pin_obj_t pin_GPIO_EMC_33; -extern const mcu_pin_obj_t pin_GPIO_EMC_34; -extern const mcu_pin_obj_t pin_GPIO_EMC_35; -extern const mcu_pin_obj_t pin_GPIO_EMC_36; -extern const mcu_pin_obj_t pin_GPIO_EMC_37; -extern const mcu_pin_obj_t pin_GPIO_EMC_38; -extern const mcu_pin_obj_t pin_GPIO_EMC_39; -extern const mcu_pin_obj_t pin_GPIO_EMC_40; -extern const mcu_pin_obj_t pin_GPIO_EMC_41; +#define FORMAT_PIN(pin_name) extern const mcu_pin_obj_t pin_##pin_name; +#include "pin_names.h" +#undef FORMAT_PIN -extern const mcu_pin_obj_t pin_GPIO_AD_B0_00; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_01; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_02; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_03; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_04; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_05; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_06; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_07; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_08; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_09; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_10; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_11; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_12; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_13; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_14; -extern const mcu_pin_obj_t pin_GPIO_AD_B0_15; - -extern const mcu_pin_obj_t pin_GPIO_AD_B1_00; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_01; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_02; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_03; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_04; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_05; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_06; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_07; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_08; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_09; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_10; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_11; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_12; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_13; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_14; -extern const mcu_pin_obj_t pin_GPIO_AD_B1_15; - -extern const mcu_pin_obj_t pin_GPIO_B0_00; -extern const mcu_pin_obj_t pin_GPIO_B0_01; -extern const mcu_pin_obj_t pin_GPIO_B0_02; -extern const mcu_pin_obj_t pin_GPIO_B0_03; -extern const mcu_pin_obj_t pin_GPIO_B0_04; -extern const mcu_pin_obj_t pin_GPIO_B0_05; -extern const mcu_pin_obj_t pin_GPIO_B0_06; -extern const mcu_pin_obj_t pin_GPIO_B0_07; -extern const mcu_pin_obj_t pin_GPIO_B0_08; -extern const mcu_pin_obj_t pin_GPIO_B0_09; -extern const mcu_pin_obj_t pin_GPIO_B0_10; -extern const mcu_pin_obj_t pin_GPIO_B0_11; -extern const mcu_pin_obj_t pin_GPIO_B0_12; -extern const mcu_pin_obj_t pin_GPIO_B0_13; -extern const mcu_pin_obj_t pin_GPIO_B0_14; -extern const mcu_pin_obj_t pin_GPIO_B0_15; - -extern const mcu_pin_obj_t pin_GPIO_B1_00; -extern const mcu_pin_obj_t pin_GPIO_B1_01; -extern const mcu_pin_obj_t pin_GPIO_B1_02; -extern const mcu_pin_obj_t pin_GPIO_B1_03; -extern const mcu_pin_obj_t pin_GPIO_B1_04; -extern const mcu_pin_obj_t pin_GPIO_B1_05; -extern const mcu_pin_obj_t pin_GPIO_B1_06; -extern const mcu_pin_obj_t pin_GPIO_B1_07; -extern const mcu_pin_obj_t pin_GPIO_B1_08; -extern const mcu_pin_obj_t pin_GPIO_B1_09; -extern const mcu_pin_obj_t pin_GPIO_B1_10; -extern const mcu_pin_obj_t pin_GPIO_B1_11; -extern const mcu_pin_obj_t pin_GPIO_B1_12; -extern const mcu_pin_obj_t pin_GPIO_B1_13; -extern const mcu_pin_obj_t pin_GPIO_B1_14; -extern const mcu_pin_obj_t pin_GPIO_B1_15; - -extern const mcu_pin_obj_t pin_GPIO_SD_B0_00; -extern const mcu_pin_obj_t pin_GPIO_SD_B0_01; -extern const mcu_pin_obj_t pin_GPIO_SD_B0_02; -extern const mcu_pin_obj_t pin_GPIO_SD_B0_03; -extern const mcu_pin_obj_t pin_GPIO_SD_B0_04; -extern const mcu_pin_obj_t pin_GPIO_SD_B0_05; - -extern const mcu_pin_obj_t pin_GPIO_SD_B1_00; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_01; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_02; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_03; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_04; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_05; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_06; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_07; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_08; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_09; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_10; -extern const mcu_pin_obj_t pin_GPIO_SD_B1_11; - -extern const mcu_pin_obj_t pin_USB_OTG1_DN; -extern const mcu_pin_obj_t pin_USB_OTG1_DP; -extern const mcu_pin_obj_t pin_USB_OTG2_DN; -extern const mcu_pin_obj_t pin_USB_OTG2_DP; - -extern const mcu_pin_obj_t mcu_pin_list[IOMUXC_SW_PAD_CTL_PAD_COUNT]; - -#endif // MICROPY_INCLUDED_MIMXRT10XX_PERIPHERALS_MIMXRT1062_PINS_H +#define PIN_COUNT (IOMUXC_SW_PAD_CTL_PAD_COUNT + 4) +extern const mcu_pin_obj_t mcu_pin_list[PIN_COUNT]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/clocks.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/clocks.c new file mode 100644 index 0000000000..1252d48135 --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/clocks.c @@ -0,0 +1,672 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Artur Pacholec + * + * 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. + */ +/* + * Copyright 2019 NXP + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "mpconfigport.h" + +#include "fsl_clock.h" +#include "fsl_iomuxc.h" +#include "fsl_dcdc.h" +#include "fsl_device_registers.h" +#include "fsl_pmu.h" + +#include "clocks.h" + +#ifndef SKIP_POWER_ADJUSTMENT +#if __CORTEX_M == 7 +#define BYPASS_LDO_LPSR 1 +#define SKIP_LDO_ADJUSTMENT 1 +#elif __CORTEX_M == 4 +#define SKIP_DCDC_ADJUSTMENT 1 +#define SKIP_FBB_ENABLE 1 +#endif +#endif + +const clock_arm_pll_config_t armPllConfig_BOARD_BootClockRUN = +{ + .postDivider = kCLOCK_PllPostDiv2, /* Post divider, 0 - DIV by 2, 1 - DIV by 4, 2 - DIV by 8, 3 - DIV by 1 */ + .loopDivider = 166, /* PLL Loop divider, Fout = Fin * ( loopDivider / ( 2 * postDivider ) ) */ +}; + +const clock_sys_pll2_config_t sysPll2Config_BOARD_BootClockRUN = +{ + .mfd = 268435455, /* Denominator of spread spectrum */ + .ss = NULL, /* Spread spectrum parameter */ + .ssEnable = false, /* Enable spread spectrum or not */ +}; + +const clock_video_pll_config_t videoPllConfig_BOARD_BootClockRUN = +{ + .loopDivider = 41, /* PLL Loop divider, valid range for DIV_SELECT divider value: 27 ~ 54. */ + .postDivider = 0, /* Divider after PLL, should only be 1, 2, 4, 8, 16, 32 */ + .numerator = 1, /* 30 bit numerator of fractional loop divider, Fout = Fin * ( loopDivider + numerator / denominator ) */ + .denominator = 960000, /* 30 bit denominator of fractional loop divider, Fout = Fin * ( loopDivider + numerator / denominator ) */ + .ss = NULL, /* Spread spectrum parameter */ + .ssEnable = false, /* Enable spread spectrum or not */ +}; + +/******************************************************************************* + * Code for BOARD_BootClockRUN configuration + ******************************************************************************/ +void clocks_init(void) { + clock_root_config_t rootCfg = {0}; + + /* Set DCDC to DCM mode to improve the efficiency for light loading in run mode and transient performance with a big loading step. */ + DCDC_BootIntoDCM(DCDC); + + #if !defined(SKIP_DCDC_ADJUSTMENT) || (!SKIP_DCDC_ADJUSTMENT) + if ((OCOTP->FUSEN[16].FUSE == 0x57AC5969U) && ((OCOTP->FUSEN[17].FUSE & 0xFFU) == 0x0BU)) { + DCDC_SetVDD1P0BuckModeTargetVoltage(DCDC, kDCDC_1P0BuckTarget1P15V); + } else { + /* Set 1.125V for production samples to align with data sheet requirement */ + DCDC_SetVDD1P0BuckModeTargetVoltage(DCDC, kDCDC_1P0BuckTarget1P125V); + } + #endif + + #if !defined(SKIP_FBB_ENABLE) || (!SKIP_FBB_ENABLE) + /* Check if FBB need to be enabled in OverDrive(OD) mode */ + if (((OCOTP->FUSEN[7].FUSE & 0x10U) >> 4U) != 1) { + PMU_EnableBodyBias(ANADIG_PMU, kPMU_FBB_CM7, true); + } else { + PMU_EnableBodyBias(ANADIG_PMU, kPMU_FBB_CM7, false); + } + #endif + + #if defined(BYPASS_LDO_LPSR) && BYPASS_LDO_LPSR + PMU_StaticEnableLpsrAnaLdoBypassMode(ANADIG_LDO_SNVS, true); + PMU_StaticEnableLpsrDigLdoBypassMode(ANADIG_LDO_SNVS, true); + #endif + + #if !defined(SKIP_LDO_ADJUSTMENT) || (!SKIP_LDO_ADJUSTMENT) + pmu_static_lpsr_ana_ldo_config_t lpsrAnaConfig; + pmu_static_lpsr_dig_config_t lpsrDigConfig; + + if ((ANADIG_LDO_SNVS->PMU_LDO_LPSR_ANA & ANADIG_LDO_SNVS_PMU_LDO_LPSR_ANA_BYPASS_MODE_EN_MASK) == 0UL) { + PMU_StaticGetLpsrAnaLdoDefaultConfig(&lpsrAnaConfig); + PMU_StaticLpsrAnaLdoInit(ANADIG_LDO_SNVS, &lpsrAnaConfig); + } + + if ((ANADIG_LDO_SNVS->PMU_LDO_LPSR_DIG & ANADIG_LDO_SNVS_PMU_LDO_LPSR_DIG_BYPASS_MODE_MASK) == 0UL) { + PMU_StaticGetLpsrDigLdoDefaultConfig(&lpsrDigConfig); + lpsrDigConfig.targetVoltage = kPMU_LpsrDigTargetStableVoltage1P117V; + PMU_StaticLpsrDigLdoInit(ANADIG_LDO_SNVS, &lpsrDigConfig); + } + #endif + + /* Config CLK_1M */ + CLOCK_OSC_Set1MHzOutputBehavior(kCLOCK_1MHzOutEnableFreeRunning1Mhz); + + /* Init OSC RC 16M */ + ANADIG_OSC->OSC_16M_CTRL |= ANADIG_OSC_OSC_16M_CTRL_EN_IRC4M16M_MASK; + + /* Init OSC RC 400M */ + CLOCK_OSC_EnableOscRc400M(); + CLOCK_OSC_GateOscRc400M(true); + + /* Init OSC RC 48M */ + CLOCK_OSC_EnableOsc48M(true); + CLOCK_OSC_EnableOsc48MDiv2(true); + + /* Config OSC 24M */ + ANADIG_OSC->OSC_24M_CTRL |= ANADIG_OSC_OSC_24M_CTRL_OSC_EN(1) | ANADIG_OSC_OSC_24M_CTRL_BYPASS_EN(0) | ANADIG_OSC_OSC_24M_CTRL_BYPASS_CLK(0) | ANADIG_OSC_OSC_24M_CTRL_LP_EN(1) | ANADIG_OSC_OSC_24M_CTRL_OSC_24M_GATE(0); + /* Wait for 24M OSC to be stable. */ + while (ANADIG_OSC_OSC_24M_CTRL_OSC_24M_STABLE_MASK != + (ANADIG_OSC->OSC_24M_CTRL & ANADIG_OSC_OSC_24M_CTRL_OSC_24M_STABLE_MASK)) { + } + + /* Switch both core, M7 Systick and Bus_Lpsr to OscRC48MDiv2 first */ + #if __CORTEX_M == 7 + rootCfg.mux = kCLOCK_M7_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_M7, &rootCfg); + + rootCfg.mux = kCLOCK_M7_SYSTICK_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_M7_Systick, &rootCfg); + #endif + + #if __CORTEX_M == 4 + rootCfg.mux = kCLOCK_M4_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_M4, &rootCfg); + + rootCfg.mux = kCLOCK_BUS_LPSR_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Bus_Lpsr, &rootCfg); + #endif + + /* + * if DCD is used, please make sure the clock source of SEMC is not changed in the following PLL/PFD configuration code. + */ + /* Init Arm Pll. */ + CLOCK_InitArmPll(&armPllConfig_BOARD_BootClockRUN); + + /* Bypass Sys Pll1. */ + CLOCK_SetPllBypass(kCLOCK_PllSys1, true); + + /* DeInit Sys Pll1. */ + CLOCK_DeinitSysPll1(); + + /* Init Sys Pll2. */ + CLOCK_InitSysPll2(&sysPll2Config_BOARD_BootClockRUN); + + /* Init System Pll2 pfd0. */ + CLOCK_InitPfd(kCLOCK_PllSys2, kCLOCK_Pfd0, 27); + + /* Init System Pll2 pfd1. */ + CLOCK_InitPfd(kCLOCK_PllSys2, kCLOCK_Pfd1, 16); + + /* Init System Pll2 pfd2. */ + CLOCK_InitPfd(kCLOCK_PllSys2, kCLOCK_Pfd2, 24); + + /* Init System Pll2 pfd3. */ + CLOCK_InitPfd(kCLOCK_PllSys2, kCLOCK_Pfd3, 32); + + /* Init Sys Pll3. */ + CLOCK_InitSysPll3(); + + /* Init System Pll3 pfd0. */ + CLOCK_InitPfd(kCLOCK_PllSys3, kCLOCK_Pfd0, 13); + + /* Init System Pll3 pfd1. */ + CLOCK_InitPfd(kCLOCK_PllSys3, kCLOCK_Pfd1, 17); + + /* Init System Pll3 pfd2. */ + CLOCK_InitPfd(kCLOCK_PllSys3, kCLOCK_Pfd2, 32); + + /* Init System Pll3 pfd3. */ + CLOCK_InitPfd(kCLOCK_PllSys3, kCLOCK_Pfd3, 22); + + /* Bypass Audio Pll. */ + CLOCK_SetPllBypass(kCLOCK_PllAudio, true); + + /* DeInit Audio Pll. */ + CLOCK_DeinitAudioPll(); + + /* Init Video Pll. */ + CLOCK_InitVideoPll(&videoPllConfig_BOARD_BootClockRUN); + + /* Module clock root configurations. */ + /* Configure M7 using ARM_PLL_CLK */ + #if __CORTEX_M == 7 + rootCfg.mux = kCLOCK_M7_ClockRoot_MuxArmPllOut; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_M7, &rootCfg); + #endif + + /* Configure M4 using SYS_PLL3_PFD3_CLK */ + #if __CORTEX_M == 4 + rootCfg.mux = kCLOCK_M4_ClockRoot_MuxSysPll3Pfd3; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_M4, &rootCfg); + #endif + + /* Configure BUS using SYS_PLL3_CLK */ + rootCfg.mux = kCLOCK_BUS_ClockRoot_MuxSysPll3Out; + rootCfg.div = 2; + CLOCK_SetRootClock(kCLOCK_Root_Bus, &rootCfg); + + /* Configure BUS_LPSR using SYS_PLL3_CLK */ + rootCfg.mux = kCLOCK_BUS_LPSR_ClockRoot_MuxSysPll3Out; + rootCfg.div = 3; + CLOCK_SetRootClock(kCLOCK_Root_Bus_Lpsr, &rootCfg); + + /* Configure SEMC using SYS_PLL2_PFD1_CLK */ + #ifndef SKIP_SEMC_INIT + rootCfg.mux = kCLOCK_SEMC_ClockRoot_MuxSysPll2Pfd1; + rootCfg.div = 3; + CLOCK_SetRootClock(kCLOCK_Root_Semc, &rootCfg); + #endif + + #if defined(XIP_BOOT_HEADER_ENABLE) && (XIP_BOOT_HEADER_ENABLE == 1) + #if defined(XIP_BOOT_HEADER_DCD_ENABLE) && (XIP_BOOT_HEADER_DCD_ENABLE == 1) + UpdateSemcClock(); + #endif + #endif + + /* Configure CSSYS using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_CSSYS_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Cssys, &rootCfg); + + /* Configure CSTRACE using SYS_PLL2_CLK */ + rootCfg.mux = kCLOCK_CSTRACE_ClockRoot_MuxSysPll2Out; + rootCfg.div = 4; + CLOCK_SetRootClock(kCLOCK_Root_Cstrace, &rootCfg); + + /* Configure M4_SYSTICK using OSC_RC_48M_DIV2 */ + #if __CORTEX_M == 4 + rootCfg.mux = kCLOCK_M4_SYSTICK_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_M4_Systick, &rootCfg); + #endif + + /* Configure M7_SYSTICK using OSC_RC_48M_DIV2 */ + #if __CORTEX_M == 7 + rootCfg.mux = kCLOCK_M7_SYSTICK_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 240; + CLOCK_SetRootClock(kCLOCK_Root_M7_Systick, &rootCfg); + #endif + + /* Configure ADC1 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_ADC1_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Adc1, &rootCfg); + + /* Configure ADC2 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_ADC2_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Adc2, &rootCfg); + + /* Configure ACMP using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_ACMP_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Acmp, &rootCfg); + + /* Configure FLEXIO1 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_FLEXIO1_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Flexio1, &rootCfg); + + /* Configure FLEXIO2 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_FLEXIO2_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Flexio2, &rootCfg); + + /* Configure GPT1 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_GPT1_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Gpt1, &rootCfg); + + /* Configure GPT2 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_GPT2_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Gpt2, &rootCfg); + + /* Configure GPT3 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_GPT3_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Gpt3, &rootCfg); + + /* Configure GPT4 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_GPT4_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Gpt4, &rootCfg); + + /* Configure GPT5 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_GPT5_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Gpt5, &rootCfg); + + /* Configure GPT6 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_GPT6_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Gpt6, &rootCfg); + + /* Configure FLEXSPI1 using OSC_RC_48M_DIV2 */ + #if !(defined(XIP_EXTERNAL_FLASH) && (XIP_EXTERNAL_FLASH == 1) || defined(FLEXSPI_IN_USE)) + rootCfg.mux = kCLOCK_FLEXSPI1_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Flexspi1, &rootCfg); + #endif + + /* Configure FLEXSPI2 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_FLEXSPI2_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Flexspi2, &rootCfg); + + /* Configure CAN1 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_CAN1_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Can1, &rootCfg); + + /* Configure CAN2 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_CAN2_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Can2, &rootCfg); + + /* Configure CAN3 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_CAN3_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Can3, &rootCfg); + + /* Configure LPUART1 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPUART1_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpuart1, &rootCfg); + + /* Configure LPUART2 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPUART2_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpuart2, &rootCfg); + + /* Configure LPUART3 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPUART3_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpuart3, &rootCfg); + + /* Configure LPUART4 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPUART4_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpuart4, &rootCfg); + + /* Configure LPUART5 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPUART5_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpuart5, &rootCfg); + + /* Configure LPUART6 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPUART6_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpuart6, &rootCfg); + + /* Configure LPUART7 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPUART7_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpuart7, &rootCfg); + + /* Configure LPUART8 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPUART8_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpuart8, &rootCfg); + + /* Configure LPUART9 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPUART9_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpuart9, &rootCfg); + + /* Configure LPUART10 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPUART10_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpuart10, &rootCfg); + + /* Configure LPUART11 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPUART11_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpuart11, &rootCfg); + + /* Configure LPUART12 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPUART12_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpuart12, &rootCfg); + + /* Configure LPI2C1 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPI2C1_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpi2c1, &rootCfg); + + /* Configure LPI2C2 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPI2C2_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpi2c2, &rootCfg); + + /* Configure LPI2C3 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPI2C3_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpi2c3, &rootCfg); + + /* Configure LPI2C4 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPI2C4_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpi2c4, &rootCfg); + + /* Configure LPI2C5 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPI2C5_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpi2c5, &rootCfg); + + /* Configure LPI2C6 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPI2C6_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpi2c6, &rootCfg); + + /* Configure LPSPI1 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPSPI1_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpspi1, &rootCfg); + + /* Configure LPSPI2 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPSPI2_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpspi2, &rootCfg); + + /* Configure LPSPI3 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPSPI3_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpspi3, &rootCfg); + + /* Configure LPSPI4 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPSPI4_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpspi4, &rootCfg); + + /* Configure LPSPI5 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPSPI5_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpspi5, &rootCfg); + + /* Configure LPSPI6 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LPSPI6_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lpspi6, &rootCfg); + + /* Configure EMV1 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_EMV1_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Emv1, &rootCfg); + + /* Configure EMV2 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_EMV2_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Emv2, &rootCfg); + + /* Configure ENET1 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_ENET1_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Enet1, &rootCfg); + + /* Configure ENET2 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_ENET2_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Enet2, &rootCfg); + + /* Configure ENET_QOS using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_ENET_QOS_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Enet_Qos, &rootCfg); + + /* Configure ENET_25M using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_ENET_25M_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Enet_25m, &rootCfg); + + /* Configure ENET_TIMER1 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_ENET_TIMER1_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Enet_Timer1, &rootCfg); + + /* Configure ENET_TIMER2 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_ENET_TIMER2_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Enet_Timer2, &rootCfg); + + /* Configure ENET_TIMER3 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_ENET_TIMER3_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Enet_Timer3, &rootCfg); + + /* Configure USDHC1 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_USDHC1_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Usdhc1, &rootCfg); + + /* Configure USDHC2 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_USDHC2_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Usdhc2, &rootCfg); + + /* Configure ASRC using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_ASRC_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Asrc, &rootCfg); + + /* Configure MQS using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_MQS_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Mqs, &rootCfg); + + /* Configure MIC using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_MIC_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Mic, &rootCfg); + + /* Configure SPDIF using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_SPDIF_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Spdif, &rootCfg); + + /* Configure SAI1 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_SAI1_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Sai1, &rootCfg); + + /* Configure SAI2 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_SAI2_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Sai2, &rootCfg); + + /* Configure SAI3 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_SAI3_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Sai3, &rootCfg); + + /* Configure SAI4 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_SAI4_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Sai4, &rootCfg); + + /* Configure GC355 using PLL_VIDEO_CLK */ + rootCfg.mux = kCLOCK_GC355_ClockRoot_MuxVideoPllOut; + rootCfg.div = 2; + CLOCK_SetRootClock(kCLOCK_Root_Gc355, &rootCfg); + + /* Configure LCDIF using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LCDIF_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lcdif, &rootCfg); + + /* Configure LCDIFV2 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_LCDIFV2_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Lcdifv2, &rootCfg); + + /* Configure MIPI_REF using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_MIPI_REF_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Mipi_Ref, &rootCfg); + + /* Configure MIPI_ESC using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_MIPI_ESC_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Mipi_Esc, &rootCfg); + + /* Configure CSI2 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_CSI2_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Csi2, &rootCfg); + + /* Configure CSI2_ESC using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_CSI2_ESC_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Csi2_Esc, &rootCfg); + + /* Configure CSI2_UI using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_CSI2_UI_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Csi2_Ui, &rootCfg); + + /* Configure CSI using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_CSI_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Csi, &rootCfg); + + /* Configure CKO1 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_CKO1_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Cko1, &rootCfg); + + /* Configure CKO2 using OSC_RC_48M_DIV2 */ + rootCfg.mux = kCLOCK_CKO2_ClockRoot_MuxOscRc48MDiv2; + rootCfg.div = 1; + CLOCK_SetRootClock(kCLOCK_Root_Cko2, &rootCfg); + + /* Set SAI1 MCLK1 clock source. */ + IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI1MClk1Sel, 0); + /* Set SAI1 MCLK2 clock source. */ + IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI1MClk2Sel, 3); + /* Set SAI1 MCLK3 clock source. */ + IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI1MClk3Sel, 0); + /* Set SAI2 MCLK3 clock source. */ + IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI2MClk3Sel, 0); + /* Set SAI3 MCLK3 clock source. */ + IOMUXC_SetSaiMClkClockSource(IOMUXC_GPR, kIOMUXC_GPR_SAI3MClk3Sel, 0); + + /* Set MQS configuration. */ + IOMUXC_MQSConfig(IOMUXC_GPR,kIOMUXC_MqsPwmOverSampleRate32, 0); + /* Set ENET Ref clock source. */ + IOMUXC_GPR->GPR4 &= ~IOMUXC_GPR_GPR4_ENET_REF_CLK_DIR_MASK; + /* Set ENET_1G Tx clock source. */ + IOMUXC_GPR->GPR5 = ((IOMUXC_GPR->GPR5 & ~IOMUXC_GPR_GPR5_ENET1G_TX_CLK_SEL_MASK) | IOMUXC_GPR_GPR5_ENET1G_RGMII_EN_MASK); + /* Set ENET_1G Ref clock source. */ + IOMUXC_GPR->GPR5 &= ~IOMUXC_GPR_GPR5_ENET1G_REF_CLK_DIR_MASK; + /* Set ENET_QOS Tx clock source. */ + IOMUXC_GPR->GPR6 &= ~IOMUXC_GPR_GPR6_ENET_QOS_RGMII_EN_MASK; + /* Set ENET_QOS Ref clock source. */ + IOMUXC_GPR->GPR6 &= ~IOMUXC_GPR_GPR6_ENET_QOS_REF_CLK_DIR_MASK; + /* Set GPT1 High frequency reference clock source. */ + IOMUXC_GPR->GPR22 &= ~IOMUXC_GPR_GPR22_REF_1M_CLK_GPT1_MASK; + /* Set GPT2 High frequency reference clock source. */ + IOMUXC_GPR->GPR23 &= ~IOMUXC_GPR_GPR23_REF_1M_CLK_GPT2_MASK; + /* Set GPT3 High frequency reference clock source. */ + IOMUXC_GPR->GPR24 &= ~IOMUXC_GPR_GPR24_REF_1M_CLK_GPT3_MASK; + /* Set GPT4 High frequency reference clock source. */ + IOMUXC_GPR->GPR25 &= ~IOMUXC_GPR_GPR25_REF_1M_CLK_GPT4_MASK; + /* Set GPT5 High frequency reference clock source. */ + IOMUXC_GPR->GPR26 &= ~IOMUXC_GPR_GPR26_REF_1M_CLK_GPT5_MASK; + /* Set GPT6 High frequency reference clock source. */ + IOMUXC_GPR->GPR27 &= ~IOMUXC_GPR_GPR27_REF_1M_CLK_GPT6_MASK; + + #if __CORTEX_M == 7 + SystemCoreClock = CLOCK_GetRootClockFreq(kCLOCK_Root_M7); + #else + SystemCoreClock = CLOCK_GetRootClockFreq(kCLOCK_Root_M4); + #endif +} diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.c new file mode 100644 index 0000000000..3263bdea09 --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.c @@ -0,0 +1,358 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "py/obj.h" +#include "py/mphal.h" +#include "mimxrt10xx/periph.h" + +LPI2C_Type *const mcu_i2c_banks[6] = { LPI2C1, LPI2C2, LPI2C3, LPI2C4, LPI2C5, LPI2C6 }; + +const mcu_periph_obj_t mcu_i2c_sda_list[8] = { + PERIPH_PIN(1, 1, 0, 0, &pin_GPIO_AD_09), + PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_AD_33), + + PERIPH_PIN(2, 9, 0, 0, &pin_GPIO_EMC_B2_01), + PERIPH_PIN(2, 9, 0, 0, &pin_GPIO_AD_19), + + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_DISP_B1_03), + PERIPH_PIN(3, 6, 0, 0, &pin_GPIO_DISP_B2_11), + + PERIPH_PIN(4, 9, 0, 0, &pin_GPIO_AD_25), + PERIPH_PIN(4, 6, 0, 0, &pin_GPIO_DISP_B2_13), +}; + +const mcu_periph_obj_t mcu_i2c_scl_list[8] = { + PERIPH_PIN(1, 1, 0, 0, &pin_GPIO_AD_08), + PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_AD_32), + + PERIPH_PIN(2, 9, 0, 0, &pin_GPIO_EMC_B2_00), + PERIPH_PIN(2, 9, 0, 0, &pin_GPIO_AD_18), + + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_DISP_B1_02), + PERIPH_PIN(3, 6, 0, 0, &pin_GPIO_DISP_B2_10), + + PERIPH_PIN(4, 9, 0, 0, &pin_GPIO_AD_24), + PERIPH_PIN(4, 6, 0, 0, &pin_GPIO_DISP_B2_12), +}; + +LPSPI_Type *const mcu_spi_banks[6] = { LPSPI1, LPSPI2, LPSPI3, LPSPI4, LPSPI5, LPSPI6 }; + +const mcu_periph_obj_t mcu_spi_sck_list[8] = { + PERIPH_PIN(1, 8, 0, 0, &pin_GPIO_EMC_B2_00), + PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_AD_28), + + PERIPH_PIN(2, 1, 0, 0, &pin_GPIO_AD_24), + PERIPH_PIN(2, 6, 0, 0, &pin_GPIO_SD_B2_07), + + PERIPH_PIN(3, 8, 0, 0, &pin_GPIO_EMC_B2_04), + PERIPH_PIN(3, 9, 0, 0, &pin_GPIO_DISP_B1_04), + + PERIPH_PIN(4, 4, 0, 0, &pin_GPIO_SD_B2_00), + PERIPH_PIN(4, 9, 0, 0, &pin_GPIO_DISP_B2_12), +}; + +const mcu_periph_obj_t mcu_spi_sdo_list[0] = { +}; + +const mcu_periph_obj_t mcu_spi_sdi_list[0] = { +}; + +LPUART_Type *const mcu_uart_banks[12] = { LPUART1, LPUART2, LPUART3, LPUART4, LPUART5, LPUART6, LPUART7, LPUART8, LPUART9, LPUART10, LPUART11, LPUART12 }; + +const mcu_periph_obj_t mcu_uart_rx_list[15] = { + PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_AD_25), + PERIPH_PIN(1, 9, 0, 0, &pin_GPIO_DISP_B1_03), + PERIPH_PIN(1, 9, 0, 0, &pin_GPIO_DISP_B2_09), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_DISP_B2_11), + + PERIPH_PIN(3, 4, 0, 0, &pin_GPIO_AD_31), + + PERIPH_PIN(4, 2, 0, 0, &pin_GPIO_DISP_B1_04), + + PERIPH_PIN(5, 1, 0, 0, &pin_GPIO_AD_29), + + PERIPH_PIN(6, 3, 0, 0, &pin_GPIO_EMC_B1_41), + + PERIPH_PIN(7, 6, 0, 0, &pin_GPIO_AD_01), + PERIPH_PIN(7, 2, 0, 0, &pin_GPIO_DISP_B2_07), + + PERIPH_PIN(8, 6, 0, 0, &pin_GPIO_AD_03), + PERIPH_PIN(8, 2, 0, 0, &pin_GPIO_DISP_B2_09), + + PERIPH_PIN(9, 3, 0, 0, &pin_GPIO_SD_B2_01), + + PERIPH_PIN(10, 1, 0, 0, &pin_GPIO_AD_16), + PERIPH_PIN(10, 8, 0, 0, &pin_GPIO_AD_33), +}; + +const mcu_periph_obj_t mcu_uart_tx_list[15] = { + PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_AD_24), + PERIPH_PIN(1, 9, 0, 0, &pin_GPIO_DISP_B1_02), + PERIPH_PIN(1, 9, 0, 0, &pin_GPIO_DISP_B2_08), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_DISP_B2_10), + + PERIPH_PIN(3, 4, 0, 0, &pin_GPIO_AD_30), + + PERIPH_PIN(4, 2, 0, 0, &pin_GPIO_DISP_B1_06), + + PERIPH_PIN(5, 1, 0, 0, &pin_GPIO_AD_28), + + PERIPH_PIN(6, 3, 0, 0, &pin_GPIO_EMC_B1_40), + + PERIPH_PIN(7, 6, 0, 0, &pin_GPIO_AD_00), + PERIPH_PIN(7, 2, 0, 0, &pin_GPIO_DISP_B2_06), + + PERIPH_PIN(8, 6, 0, 0, &pin_GPIO_AD_02), + PERIPH_PIN(8, 2, 0, 0, &pin_GPIO_DISP_B2_08), + + PERIPH_PIN(9, 3, 0, 0, &pin_GPIO_SD_B2_00), + + PERIPH_PIN(10, 1, 0, 0, &pin_GPIO_AD_15), + PERIPH_PIN(10, 8, 0, 0, &pin_GPIO_AD_32), +}; + +const mcu_periph_obj_t mcu_uart_rts_list[10] = { + PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_AD_27), + + PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_DISP_B2_13), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_SD_B2_08), + + PERIPH_PIN(4, 2, 0, 0, &pin_GPIO_DISP_B1_07), + + PERIPH_PIN(5, 3, 0, 0, &pin_GPIO_SD_B2_10), + + PERIPH_PIN(6, 3, 0, 0, &pin_GPIO_EMC_B2_01), + + PERIPH_PIN(7, 1, 0, 0, &pin_GPIO_AD_03), + + PERIPH_PIN(8, 1, 0, 0, &pin_GPIO_AD_05), + + PERIPH_PIN(9, 3, 0, 0, &pin_GPIO_SD_B2_03), + + PERIPH_PIN(10, 8, 0, 0, &pin_GPIO_AD_35), +}; + +const mcu_periph_obj_t mcu_uart_cts_list[10] = { + PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_AD_26), + + PERIPH_PIN(2, 3, 0, 0, &pin_GPIO_DISP_B2_12), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_SD_B2_07), + + PERIPH_PIN(4, 2, 0, 0, &pin_GPIO_DISP_B1_05), + + PERIPH_PIN(5, 3, 0, 0, &pin_GPIO_SD_B2_09), + + PERIPH_PIN(6, 3, 0, 0, &pin_GPIO_EMC_B2_00), + + PERIPH_PIN(7, 1, 0, 0, &pin_GPIO_AD_02), + + PERIPH_PIN(8, 1, 0, 0, &pin_GPIO_AD_04), + + PERIPH_PIN(9, 3, 0, 0, &pin_GPIO_SD_B2_02), + + PERIPH_PIN(10, 8, 0, 0, &pin_GPIO_AD_34), +}; + +I2S_Type *const mcu_i2s_banks[4] = { SAI1, SAI2, SAI3, SAI4 }; + +const mcu_periph_obj_t mcu_i2s_rx_data0_list[4] = { + PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_AD_20), + PERIPH_PIN(1, 4, 0, 0, &pin_GPIO_DISP_B2_06), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_B2_07), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_B2_13), +}; + +const mcu_periph_obj_t mcu_i2s_rx_sync_list[4] = { + PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_AD_18), + PERIPH_PIN(1, 4, 0, 0, &pin_GPIO_DISP_B2_04), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_B2_05), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_B2_11), +}; + +const mcu_periph_obj_t mcu_i2s_tx_bclk_list[4] = { + PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_AD_22), + PERIPH_PIN(1, 4, 0, 0, &pin_GPIO_DISP_B2_08), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_B2_09), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_B2_15), +}; + +const mcu_periph_obj_t mcu_i2s_tx_data0_list[4] = { + PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_AD_21), + PERIPH_PIN(1, 4, 0, 0, &pin_GPIO_DISP_B2_07), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_B2_08), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_B2_14), +}; + +const mcu_periph_obj_t mcu_i2s_tx_sync_list[4] = { + PERIPH_PIN(1, 0, 0, 0, &pin_GPIO_AD_23), + PERIPH_PIN(1, 4, 0, 0, &pin_GPIO_DISP_B2_09), + + PERIPH_PIN(2, 2, 0, 0, &pin_GPIO_EMC_B2_10), + + PERIPH_PIN(3, 3, 0, 0, &pin_GPIO_EMC_B2_16), +}; + +const mcu_periph_obj_t mcu_mqs_left_list[2] = { + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_EMC_B1_41), + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_DISP_B2_01), +}; + +const mcu_periph_obj_t mcu_mqs_right_list[2] = { + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_EMC_B1_40), + PERIPH_PIN(3, 2, 0, 0, &pin_GPIO_DISP_B2_00), +}; + +const mcu_pwm_obj_t mcu_pwm_list[68] = { + PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_EMC_B1_23_FLEXPWM1_PWM0_A, &pin_GPIO_EMC_B1_23), + PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_AD_00_FLEXPWM1_PWM0_A, &pin_GPIO_AD_00), + + PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_EMC_B1_24_FLEXPWM1_PWM0_B, &pin_GPIO_EMC_B1_24), + PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_AD_01_FLEXPWM1_PWM0_B, &pin_GPIO_AD_01), + + PWM_PIN(PWM1, kPWM_Module_0, kPWM_PwmX, IOMUXC_GPIO_AD_06_FLEXPWM1_PWM0_X, &pin_GPIO_AD_06), + + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_EMC_B1_25_FLEXPWM1_PWM1_A, &pin_GPIO_EMC_B1_25), + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_AD_02_FLEXPWM1_PWM1_A, &pin_GPIO_AD_02), + + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_EMC_B1_26_FLEXPWM1_PWM1_B, &pin_GPIO_EMC_B1_26), + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_AD_03_FLEXPWM1_PWM1_B, &pin_GPIO_AD_03), + + PWM_PIN(PWM1, kPWM_Module_1, kPWM_PwmX, IOMUXC_GPIO_AD_07_FLEXPWM1_PWM1_X, &pin_GPIO_AD_07), + + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_EMC_B1_27_FLEXPWM1_PWM2_A, &pin_GPIO_EMC_B1_27), + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_AD_04_FLEXPWM1_PWM2_A, &pin_GPIO_AD_04), + + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_EMC_B1_28_FLEXPWM1_PWM2_B, &pin_GPIO_EMC_B1_28), + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_AD_05_FLEXPWM1_PWM2_B, &pin_GPIO_AD_05), + + PWM_PIN(PWM1, kPWM_Module_2, kPWM_PwmX, IOMUXC_GPIO_AD_08_FLEXPWM1_PWM2_X, &pin_GPIO_AD_08), + + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_B1_38_FLEXPWM1_PWM3_A, &pin_GPIO_EMC_B1_38), + + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_B1_39_FLEXPWM1_PWM3_B, &pin_GPIO_EMC_B1_39), + + PWM_PIN(PWM1, kPWM_Module_3, kPWM_PwmX, IOMUXC_GPIO_AD_09_FLEXPWM1_PWM3_X, &pin_GPIO_AD_09), + + PWM_PIN(PWM2, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_EMC_B1_06_FLEXPWM2_PWM0_A, &pin_GPIO_EMC_B1_06), + PWM_PIN(PWM2, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_AD_24_FLEXPWM2_PWM0_A, &pin_GPIO_AD_24), + + PWM_PIN(PWM2, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_EMC_B1_07_FLEXPWM2_PWM0_B, &pin_GPIO_EMC_B1_07), + PWM_PIN(PWM2, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_AD_25_FLEXPWM2_PWM0_B, &pin_GPIO_AD_25), + + PWM_PIN(PWM2, kPWM_Module_0, kPWM_PwmX, IOMUXC_GPIO_AD_10_FLEXPWM2_PWM0_X, &pin_GPIO_AD_10), + + PWM_PIN(PWM2, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_EMC_B1_08_FLEXPWM2_PWM1_A, &pin_GPIO_EMC_B1_08), + PWM_PIN(PWM2, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_AD_26_FLEXPWM2_PWM1_A, &pin_GPIO_AD_26), + + PWM_PIN(PWM2, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_EMC_B1_09_FLEXPWM2_PWM1_B, &pin_GPIO_EMC_B1_09), + PWM_PIN(PWM2, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_AD_27_FLEXPWM2_PWM1_B, &pin_GPIO_AD_27), + + PWM_PIN(PWM2, kPWM_Module_1, kPWM_PwmX, IOMUXC_GPIO_AD_11_FLEXPWM2_PWM1_X, &pin_GPIO_AD_11), + + PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_EMC_B1_10_FLEXPWM2_PWM2_A, &pin_GPIO_EMC_B1_10), + PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_AD_28_FLEXPWM2_PWM2_A, &pin_GPIO_AD_28), + + PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_EMC_B1_11_FLEXPWM2_PWM2_B, &pin_GPIO_EMC_B1_11), + PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_AD_29_FLEXPWM2_PWM2_B, &pin_GPIO_AD_29), + + PWM_PIN(PWM2, kPWM_Module_2, kPWM_PwmX, IOMUXC_GPIO_AD_12_FLEXPWM2_PWM2_X, &pin_GPIO_AD_12), + + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_B1_19_FLEXPWM2_PWM3_A, &pin_GPIO_EMC_B1_19), + + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_B1_20_FLEXPWM2_PWM3_B, &pin_GPIO_EMC_B1_20), + + PWM_PIN(PWM2, kPWM_Module_3, kPWM_PwmX, IOMUXC_GPIO_AD_13_FLEXPWM2_PWM3_X, &pin_GPIO_AD_13), + + PWM_PIN(PWM3, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_EMC_B1_29_FLEXPWM3_PWM0_A, &pin_GPIO_EMC_B1_29), + PWM_PIN(PWM3, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_EMC_B2_00_FLEXPWM3_PWM0_A, &pin_GPIO_EMC_B2_00), + + PWM_PIN(PWM3, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_EMC_B1_30_FLEXPWM3_PWM0_B, &pin_GPIO_EMC_B1_30), + PWM_PIN(PWM3, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_EMC_B2_01_FLEXPWM3_PWM0_B, &pin_GPIO_EMC_B2_01), + + PWM_PIN(PWM3, kPWM_Module_0, kPWM_PwmX, IOMUXC_GPIO_AD_14_FLEXPWM3_PWM0_X, &pin_GPIO_AD_14), + + PWM_PIN(PWM3, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_EMC_B1_31_FLEXPWM3_PWM1_A, &pin_GPIO_EMC_B1_31), + PWM_PIN(PWM3, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_EMC_B2_02_FLEXPWM3_PWM1_A, &pin_GPIO_EMC_B2_02), + + PWM_PIN(PWM3, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_EMC_B1_32_FLEXPWM3_PWM1_B, &pin_GPIO_EMC_B1_32), + PWM_PIN(PWM3, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_EMC_B2_03_FLEXPWM3_PWM1_B, &pin_GPIO_EMC_B2_03), + + PWM_PIN(PWM3, kPWM_Module_1, kPWM_PwmX, IOMUXC_GPIO_AD_15_FLEXPWM3_PWM1_X, &pin_GPIO_AD_15), + + PWM_PIN(PWM3, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_EMC_B1_33_FLEXPWM3_PWM2_A, &pin_GPIO_EMC_B1_33), + PWM_PIN(PWM3, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_EMC_B2_04_FLEXPWM3_PWM2_A, &pin_GPIO_EMC_B2_04), + + PWM_PIN(PWM3, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_EMC_B1_34_FLEXPWM3_PWM2_B, &pin_GPIO_EMC_B1_34), + PWM_PIN(PWM3, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_EMC_B2_05_FLEXPWM3_PWM2_B, &pin_GPIO_EMC_B2_05), + + PWM_PIN(PWM3, kPWM_Module_2, kPWM_PwmX, IOMUXC_GPIO_AD_16_FLEXPWM3_PWM2_X, &pin_GPIO_AD_16), + + PWM_PIN(PWM3, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_B1_21_FLEXPWM3_PWM3_A, &pin_GPIO_EMC_B1_21), + PWM_PIN(PWM3, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_B2_06_FLEXPWM3_PWM3_A, &pin_GPIO_EMC_B2_06), + + PWM_PIN(PWM3, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_B1_22_FLEXPWM3_PWM3_B, &pin_GPIO_EMC_B1_22), + PWM_PIN(PWM3, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_B2_07_FLEXPWM3_PWM3_B, &pin_GPIO_EMC_B2_07), + + PWM_PIN(PWM3, kPWM_Module_3, kPWM_PwmX, IOMUXC_GPIO_AD_17_FLEXPWM3_PWM3_X, &pin_GPIO_AD_17), + + PWM_PIN(PWM4, kPWM_Module_0, kPWM_PwmA, IOMUXC_GPIO_EMC_B1_00_FLEXPWM4_PWM0_A, &pin_GPIO_EMC_B1_00), + + PWM_PIN(PWM4, kPWM_Module_0, kPWM_PwmB, IOMUXC_GPIO_EMC_B1_01_FLEXPWM4_PWM0_B, &pin_GPIO_EMC_B1_01), + + PWM_PIN(PWM4, kPWM_Module_0, kPWM_PwmX, IOMUXC_GPIO_AD_18_FLEXPWM4_PWM0_X, &pin_GPIO_AD_18), + + PWM_PIN(PWM4, kPWM_Module_1, kPWM_PwmA, IOMUXC_GPIO_EMC_B1_02_FLEXPWM4_PWM1_A, &pin_GPIO_EMC_B1_02), + + PWM_PIN(PWM4, kPWM_Module_1, kPWM_PwmB, IOMUXC_GPIO_EMC_B1_03_FLEXPWM4_PWM1_B, &pin_GPIO_EMC_B1_03), + + PWM_PIN(PWM4, kPWM_Module_1, kPWM_PwmX, IOMUXC_GPIO_AD_19_FLEXPWM4_PWM1_X, &pin_GPIO_AD_19), + + PWM_PIN(PWM4, kPWM_Module_2, kPWM_PwmA, IOMUXC_GPIO_EMC_B1_04_FLEXPWM4_PWM2_A, &pin_GPIO_EMC_B1_04), + + PWM_PIN(PWM4, kPWM_Module_2, kPWM_PwmB, IOMUXC_GPIO_EMC_B1_05_FLEXPWM4_PWM2_B, &pin_GPIO_EMC_B1_05), + + PWM_PIN(PWM4, kPWM_Module_2, kPWM_PwmX, IOMUXC_GPIO_AD_20_FLEXPWM4_PWM2_X, &pin_GPIO_AD_20), + + PWM_PIN(PWM4, kPWM_Module_3, kPWM_PwmA, IOMUXC_GPIO_EMC_B1_17_FLEXPWM4_PWM3_A, &pin_GPIO_EMC_B1_17), + + PWM_PIN(PWM4, kPWM_Module_3, kPWM_PwmB, IOMUXC_GPIO_EMC_B1_18_FLEXPWM4_PWM3_B, &pin_GPIO_EMC_B1_18), + + PWM_PIN(PWM4, kPWM_Module_3, kPWM_PwmX, IOMUXC_GPIO_AD_21_FLEXPWM4_PWM3_X, &pin_GPIO_AD_21), +}; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.h new file mode 100644 index 0000000000..41695d655b --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.h @@ -0,0 +1,55 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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. + */ + +#pragma once +extern LPI2C_Type *const mcu_i2c_banks[6]; +extern const mcu_periph_obj_t mcu_i2c_sda_list[8]; +extern const mcu_periph_obj_t mcu_i2c_scl_list[8]; + +extern LPSPI_Type *const mcu_spi_banks[6]; +extern const mcu_periph_obj_t mcu_spi_sck_list[8]; +extern const mcu_periph_obj_t mcu_spi_sdo_list[0]; +extern const mcu_periph_obj_t mcu_spi_sdi_list[0]; + +extern LPUART_Type *const mcu_uart_banks[12]; +extern 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_rts_list[10]; +extern const mcu_periph_obj_t mcu_uart_cts_list[10]; + +extern I2S_Type *const mcu_i2s_banks[4]; +extern const mcu_periph_obj_t mcu_i2s_rx_data0_list[4]; +extern const mcu_periph_obj_t mcu_i2s_rx_sync_list[4]; +extern const mcu_periph_obj_t mcu_i2s_tx_bclk_list[4]; +extern const mcu_periph_obj_t mcu_i2s_tx_data0_list[4]; +extern const mcu_periph_obj_t mcu_i2s_tx_sync_list[4]; + +extern const mcu_periph_obj_t mcu_mqs_left_list[2]; +extern const mcu_periph_obj_t mcu_mqs_right_list[2]; + +extern const mcu_pwm_obj_t mcu_pwm_list[68]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pin_names.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pin_names.h new file mode 100644 index 0000000000..6dcd77a6a2 --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pin_names.h @@ -0,0 +1,182 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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. + */ + + +// define FORMAT_PIN(pin_name) and then include this file. + +FORMAT_PIN(GPIO_EMC_B1_00) +FORMAT_PIN(GPIO_EMC_B1_01) +FORMAT_PIN(GPIO_EMC_B1_02) +FORMAT_PIN(GPIO_EMC_B1_03) +FORMAT_PIN(GPIO_EMC_B1_04) +FORMAT_PIN(GPIO_EMC_B1_05) +FORMAT_PIN(GPIO_EMC_B1_06) +FORMAT_PIN(GPIO_EMC_B1_07) +FORMAT_PIN(GPIO_EMC_B1_08) +FORMAT_PIN(GPIO_EMC_B1_09) +FORMAT_PIN(GPIO_EMC_B1_10) +FORMAT_PIN(GPIO_EMC_B1_11) +FORMAT_PIN(GPIO_EMC_B1_12) +FORMAT_PIN(GPIO_EMC_B1_13) +FORMAT_PIN(GPIO_EMC_B1_14) +FORMAT_PIN(GPIO_EMC_B1_15) +FORMAT_PIN(GPIO_EMC_B1_16) +FORMAT_PIN(GPIO_EMC_B1_17) +FORMAT_PIN(GPIO_EMC_B1_18) +FORMAT_PIN(GPIO_EMC_B1_19) +FORMAT_PIN(GPIO_EMC_B1_20) +FORMAT_PIN(GPIO_EMC_B1_21) +FORMAT_PIN(GPIO_EMC_B1_22) +FORMAT_PIN(GPIO_EMC_B1_23) +FORMAT_PIN(GPIO_EMC_B1_24) +FORMAT_PIN(GPIO_EMC_B1_25) +FORMAT_PIN(GPIO_EMC_B1_26) +FORMAT_PIN(GPIO_EMC_B1_27) +FORMAT_PIN(GPIO_EMC_B1_28) +FORMAT_PIN(GPIO_EMC_B1_29) +FORMAT_PIN(GPIO_EMC_B1_30) +FORMAT_PIN(GPIO_EMC_B1_31) +FORMAT_PIN(GPIO_EMC_B1_32) +FORMAT_PIN(GPIO_EMC_B1_33) +FORMAT_PIN(GPIO_EMC_B1_34) +FORMAT_PIN(GPIO_EMC_B1_35) +FORMAT_PIN(GPIO_EMC_B1_36) +FORMAT_PIN(GPIO_EMC_B1_37) +FORMAT_PIN(GPIO_EMC_B1_38) +FORMAT_PIN(GPIO_EMC_B1_39) +FORMAT_PIN(GPIO_EMC_B1_40) +FORMAT_PIN(GPIO_EMC_B1_41) + +FORMAT_PIN(GPIO_EMC_B2_00) +FORMAT_PIN(GPIO_EMC_B2_01) +FORMAT_PIN(GPIO_EMC_B2_02) +FORMAT_PIN(GPIO_EMC_B2_03) +FORMAT_PIN(GPIO_EMC_B2_04) +FORMAT_PIN(GPIO_EMC_B2_05) +FORMAT_PIN(GPIO_EMC_B2_06) +FORMAT_PIN(GPIO_EMC_B2_07) +FORMAT_PIN(GPIO_EMC_B2_08) +FORMAT_PIN(GPIO_EMC_B2_09) +FORMAT_PIN(GPIO_EMC_B2_10) +FORMAT_PIN(GPIO_EMC_B2_11) +FORMAT_PIN(GPIO_EMC_B2_12) +FORMAT_PIN(GPIO_EMC_B2_13) +FORMAT_PIN(GPIO_EMC_B2_14) +FORMAT_PIN(GPIO_EMC_B2_15) +FORMAT_PIN(GPIO_EMC_B2_16) +FORMAT_PIN(GPIO_EMC_B2_17) +FORMAT_PIN(GPIO_EMC_B2_18) +FORMAT_PIN(GPIO_EMC_B2_19) +FORMAT_PIN(GPIO_EMC_B2_20) + +FORMAT_PIN(GPIO_AD_00) +FORMAT_PIN(GPIO_AD_01) +FORMAT_PIN(GPIO_AD_02) +FORMAT_PIN(GPIO_AD_03) +FORMAT_PIN(GPIO_AD_04) +FORMAT_PIN(GPIO_AD_05) +FORMAT_PIN(GPIO_AD_06) +FORMAT_PIN(GPIO_AD_07) +FORMAT_PIN(GPIO_AD_08) +FORMAT_PIN(GPIO_AD_09) +FORMAT_PIN(GPIO_AD_10) +FORMAT_PIN(GPIO_AD_11) +FORMAT_PIN(GPIO_AD_12) +FORMAT_PIN(GPIO_AD_13) +FORMAT_PIN(GPIO_AD_14) +FORMAT_PIN(GPIO_AD_15) +FORMAT_PIN(GPIO_AD_16) +FORMAT_PIN(GPIO_AD_17) +FORMAT_PIN(GPIO_AD_18) +FORMAT_PIN(GPIO_AD_19) +FORMAT_PIN(GPIO_AD_20) +FORMAT_PIN(GPIO_AD_21) +FORMAT_PIN(GPIO_AD_22) +FORMAT_PIN(GPIO_AD_23) +FORMAT_PIN(GPIO_AD_24) +FORMAT_PIN(GPIO_AD_25) +FORMAT_PIN(GPIO_AD_26) +FORMAT_PIN(GPIO_AD_27) +FORMAT_PIN(GPIO_AD_28) +FORMAT_PIN(GPIO_AD_29) +FORMAT_PIN(GPIO_AD_30) +FORMAT_PIN(GPIO_AD_31) +FORMAT_PIN(GPIO_AD_32) +FORMAT_PIN(GPIO_AD_33) +FORMAT_PIN(GPIO_AD_34) +FORMAT_PIN(GPIO_AD_35) + +FORMAT_PIN(GPIO_SD_B1_00) +FORMAT_PIN(GPIO_SD_B1_01) +FORMAT_PIN(GPIO_SD_B1_02) +FORMAT_PIN(GPIO_SD_B1_03) +FORMAT_PIN(GPIO_SD_B1_04) +FORMAT_PIN(GPIO_SD_B1_05) + +FORMAT_PIN(GPIO_SD_B2_00) +FORMAT_PIN(GPIO_SD_B2_01) +FORMAT_PIN(GPIO_SD_B2_02) +FORMAT_PIN(GPIO_SD_B2_03) +FORMAT_PIN(GPIO_SD_B2_04) +FORMAT_PIN(GPIO_SD_B2_05) +FORMAT_PIN(GPIO_SD_B2_06) +FORMAT_PIN(GPIO_SD_B2_07) +FORMAT_PIN(GPIO_SD_B2_08) +FORMAT_PIN(GPIO_SD_B2_09) +FORMAT_PIN(GPIO_SD_B2_10) +FORMAT_PIN(GPIO_SD_B2_11) + +FORMAT_PIN(GPIO_DISP_B1_00) +FORMAT_PIN(GPIO_DISP_B1_01) +FORMAT_PIN(GPIO_DISP_B1_02) +FORMAT_PIN(GPIO_DISP_B1_03) +FORMAT_PIN(GPIO_DISP_B1_04) +FORMAT_PIN(GPIO_DISP_B1_05) +FORMAT_PIN(GPIO_DISP_B1_06) +FORMAT_PIN(GPIO_DISP_B1_07) +FORMAT_PIN(GPIO_DISP_B1_08) +FORMAT_PIN(GPIO_DISP_B1_09) +FORMAT_PIN(GPIO_DISP_B1_10) +FORMAT_PIN(GPIO_DISP_B1_11) + +FORMAT_PIN(GPIO_DISP_B2_00) +FORMAT_PIN(GPIO_DISP_B2_01) +FORMAT_PIN(GPIO_DISP_B2_02) +FORMAT_PIN(GPIO_DISP_B2_03) +FORMAT_PIN(GPIO_DISP_B2_04) +FORMAT_PIN(GPIO_DISP_B2_05) +FORMAT_PIN(GPIO_DISP_B2_06) +FORMAT_PIN(GPIO_DISP_B2_07) +FORMAT_PIN(GPIO_DISP_B2_08) +FORMAT_PIN(GPIO_DISP_B2_09) +FORMAT_PIN(GPIO_DISP_B2_10) +FORMAT_PIN(GPIO_DISP_B2_11) +FORMAT_PIN(GPIO_DISP_B2_12) +FORMAT_PIN(GPIO_DISP_B2_13) +FORMAT_PIN(GPIO_DISP_B2_14) +FORMAT_PIN(GPIO_DISP_B2_15) diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pins.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pins.c new file mode 100644 index 0000000000..71562462e6 --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pins.c @@ -0,0 +1,177 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "py/obj.h" +#include "py/mphal.h" +#include "mimxrt10xx/pins.h" + +const mcu_pin_obj_t pin_GPIO_EMC_B1_00 = PIN(GPIO7, 0, GPIO_EMC_B1_00, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_01 = PIN(GPIO7, 1, GPIO_EMC_B1_01, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_02 = PIN(GPIO7, 2, GPIO_EMC_B1_02, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_03 = PIN(GPIO7, 3, GPIO_EMC_B1_03, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_04 = PIN(GPIO7, 4, GPIO_EMC_B1_04, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_05 = PIN(GPIO7, 5, GPIO_EMC_B1_05, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_06 = PIN(GPIO7, 6, GPIO_EMC_B1_06, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_07 = PIN(GPIO7, 7, GPIO_EMC_B1_07, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_08 = PIN(GPIO7, 8, GPIO_EMC_B1_08, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_09 = PIN(GPIO7, 9, GPIO_EMC_B1_09, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_10 = PIN(GPIO7, 10, GPIO_EMC_B1_10, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_11 = PIN(GPIO7, 11, GPIO_EMC_B1_11, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_12 = PIN(GPIO7, 12, GPIO_EMC_B1_12, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_13 = PIN(GPIO7, 13, GPIO_EMC_B1_13, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_14 = PIN(GPIO7, 14, GPIO_EMC_B1_14, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_15 = PIN(GPIO7, 15, GPIO_EMC_B1_15, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_16 = PIN(GPIO7, 16, GPIO_EMC_B1_16, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_17 = PIN(GPIO7, 17, GPIO_EMC_B1_17, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_18 = PIN(GPIO7, 18, GPIO_EMC_B1_18, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_19 = PIN(GPIO7, 19, GPIO_EMC_B1_19, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_20 = PIN(GPIO7, 20, GPIO_EMC_B1_20, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_21 = PIN(GPIO7, 21, GPIO_EMC_B1_21, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_22 = PIN(GPIO7, 22, GPIO_EMC_B1_22, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_23 = PIN(GPIO7, 23, GPIO_EMC_B1_23, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_24 = PIN(GPIO7, 24, GPIO_EMC_B1_24, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_25 = PIN(GPIO7, 25, GPIO_EMC_B1_25, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_26 = PIN(GPIO7, 26, GPIO_EMC_B1_26, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_27 = PIN(GPIO7, 27, GPIO_EMC_B1_27, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_28 = PIN(GPIO7, 28, GPIO_EMC_B1_28, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_29 = PIN(GPIO7, 29, GPIO_EMC_B1_29, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_30 = PIN(GPIO7, 30, GPIO_EMC_B1_30, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_31 = PIN(GPIO7, 31, GPIO_EMC_B1_31, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_32 = PIN(GPIO8, 0, GPIO_EMC_B1_32, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_33 = PIN(GPIO8, 1, GPIO_EMC_B1_33, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_34 = PIN(GPIO8, 2, GPIO_EMC_B1_34, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_35 = PIN(GPIO8, 3, GPIO_EMC_B1_35, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_36 = PIN(GPIO8, 4, GPIO_EMC_B1_36, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_37 = PIN(GPIO8, 5, GPIO_EMC_B1_37, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_38 = PIN(GPIO8, 6, GPIO_EMC_B1_38, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_39 = PIN(GPIO8, 7, GPIO_EMC_B1_39, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_40 = PIN(GPIO8, 8, GPIO_EMC_B1_40, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B1_41 = PIN(GPIO8, 9, GPIO_EMC_B1_41, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B2_00 = PIN(GPIO8, 10, GPIO_EMC_B2_00, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B2_01 = PIN(GPIO8, 11, GPIO_EMC_B2_01, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B2_02 = PIN(GPIO8, 12, GPIO_EMC_B2_02, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B2_03 = PIN(GPIO8, 13, GPIO_EMC_B2_03, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B2_04 = PIN(GPIO8, 14, GPIO_EMC_B2_04, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B2_05 = PIN(GPIO8, 15, GPIO_EMC_B2_05, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B2_06 = PIN(GPIO8, 16, GPIO_EMC_B2_06, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B2_07 = PIN(GPIO8, 17, GPIO_EMC_B2_07, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B2_08 = PIN(GPIO8, 18, GPIO_EMC_B2_08, NO_ADC, 0, 0x00000005, 0x00000004); +const mcu_pin_obj_t pin_GPIO_EMC_B2_09 = PIN(GPIO8, 19, GPIO_EMC_B2_09, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B2_10 = PIN(GPIO8, 20, GPIO_EMC_B2_10, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B2_11 = PIN(GPIO8, 21, GPIO_EMC_B2_11, NO_ADC, 0, 0x00000005, 0x00000004); +const mcu_pin_obj_t pin_GPIO_EMC_B2_12 = PIN(GPIO8, 22, GPIO_EMC_B2_12, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B2_13 = PIN(GPIO8, 23, GPIO_EMC_B2_13, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B2_14 = PIN(GPIO8, 24, GPIO_EMC_B2_14, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B2_15 = PIN(GPIO8, 25, GPIO_EMC_B2_15, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B2_16 = PIN(GPIO8, 26, GPIO_EMC_B2_16, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B2_17 = PIN(GPIO8, 27, GPIO_EMC_B2_17, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B2_18 = PIN(GPIO8, 28, GPIO_EMC_B2_18, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B2_19 = PIN(GPIO8, 29, GPIO_EMC_B2_19, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_EMC_B2_20 = PIN(GPIO8, 30, GPIO_EMC_B2_20, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_AD_00 = PIN(GPIO8, 31, GPIO_AD_00, NO_ADC, 0, 0x00000005, 0x0000000E); +const mcu_pin_obj_t pin_GPIO_AD_01 = PIN(GPIO9, 0, GPIO_AD_01, NO_ADC, 0, 0x00000005, 0x0000000E); +const mcu_pin_obj_t pin_GPIO_AD_02 = PIN(GPIO9, 1, GPIO_AD_02, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_03 = PIN(GPIO9, 2, GPIO_AD_03, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_04 = PIN(GPIO9, 3, GPIO_AD_04, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_05 = PIN(GPIO9, 4, GPIO_AD_05, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_06 = PIN(GPIO9, 5, GPIO_AD_06, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_07 = PIN(GPIO9, 6, GPIO_AD_07, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_08 = PIN(GPIO9, 7, GPIO_AD_08, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_09 = PIN(GPIO9, 8, GPIO_AD_09, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_10 = PIN(GPIO9, 9, GPIO_AD_10, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_11 = PIN(GPIO9, 10, GPIO_AD_11, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_12 = PIN(GPIO9, 11, GPIO_AD_12, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_13 = PIN(GPIO9, 12, GPIO_AD_13, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_14 = PIN(GPIO9, 13, GPIO_AD_14, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_15 = PIN(GPIO9, 14, GPIO_AD_15, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_16 = PIN(GPIO9, 15, GPIO_AD_16, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_17 = PIN(GPIO9, 16, GPIO_AD_17, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_18 = PIN(GPIO9, 17, GPIO_AD_18, NO_ADC, 0, 0x00000005, 0x0000000E); +const mcu_pin_obj_t pin_GPIO_AD_19 = PIN(GPIO9, 18, GPIO_AD_19, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_20 = PIN(GPIO9, 19, GPIO_AD_20, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_21 = PIN(GPIO9, 20, GPIO_AD_21, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_22 = PIN(GPIO9, 21, GPIO_AD_22, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_23 = PIN(GPIO9, 22, GPIO_AD_23, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_24 = PIN(GPIO9, 23, GPIO_AD_24, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_25 = PIN(GPIO9, 24, GPIO_AD_25, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_26 = PIN(GPIO9, 25, GPIO_AD_26, NO_ADC, 0, 0x00000005, 0x0000000E); +const mcu_pin_obj_t pin_GPIO_AD_27 = PIN(GPIO9, 26, GPIO_AD_27, NO_ADC, 0, 0x00000005, 0x0000000E); +const mcu_pin_obj_t pin_GPIO_AD_28 = PIN(GPIO9, 27, GPIO_AD_28, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_29 = PIN(GPIO9, 28, GPIO_AD_29, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_30 = PIN(GPIO9, 29, GPIO_AD_30, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_31 = PIN(GPIO9, 30, GPIO_AD_31, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_32 = PIN(GPIO9, 31, GPIO_AD_32, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_33 = PIN(GPIO10, 0, GPIO_AD_33, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_34 = PIN(GPIO10, 1, GPIO_AD_34, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_AD_35 = PIN(GPIO10, 2, GPIO_AD_35, NO_ADC, 0, 0x00000005, 0x0000000E); +const mcu_pin_obj_t pin_GPIO_SD_B1_00 = PIN(GPIO10, 3, GPIO_SD_B1_00, NO_ADC, 0, 0x00000005, 0x00000004); +const mcu_pin_obj_t pin_GPIO_SD_B1_01 = PIN(GPIO10, 4, GPIO_SD_B1_01, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_SD_B1_02 = PIN(GPIO10, 5, GPIO_SD_B1_02, NO_ADC, 0, 0x00000005, 0x00000004); +const mcu_pin_obj_t pin_GPIO_SD_B1_03 = PIN(GPIO10, 6, GPIO_SD_B1_03, NO_ADC, 0, 0x00000005, 0x00000004); +const mcu_pin_obj_t pin_GPIO_SD_B1_04 = PIN(GPIO10, 7, GPIO_SD_B1_04, NO_ADC, 0, 0x00000005, 0x00000004); +const mcu_pin_obj_t pin_GPIO_SD_B1_05 = PIN(GPIO10, 8, GPIO_SD_B1_05, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_SD_B2_00 = PIN(GPIO10, 9, GPIO_SD_B2_00, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_SD_B2_01 = PIN(GPIO10, 10, GPIO_SD_B2_01, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_SD_B2_02 = PIN(GPIO10, 11, GPIO_SD_B2_02, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_SD_B2_03 = PIN(GPIO10, 12, GPIO_SD_B2_03, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_SD_B2_04 = PIN(GPIO10, 13, GPIO_SD_B2_04, NO_ADC, 0, 0x00000005, 0x00000004); +const mcu_pin_obj_t pin_GPIO_SD_B2_05 = PIN(GPIO10, 14, GPIO_SD_B2_05, NO_ADC, 0, 0x00000005, 0x00000004); +const mcu_pin_obj_t pin_GPIO_SD_B2_06 = PIN(GPIO10, 15, GPIO_SD_B2_06, NO_ADC, 0, 0x00000005, 0x00000004); +const mcu_pin_obj_t pin_GPIO_SD_B2_07 = PIN(GPIO10, 16, GPIO_SD_B2_07, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_SD_B2_08 = PIN(GPIO10, 17, GPIO_SD_B2_08, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_SD_B2_09 = PIN(GPIO10, 18, GPIO_SD_B2_09, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_SD_B2_10 = PIN(GPIO10, 19, GPIO_SD_B2_10, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_SD_B2_11 = PIN(GPIO10, 20, GPIO_SD_B2_11, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_DISP_B1_00 = PIN(GPIO10, 21, GPIO_DISP_B1_00, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_DISP_B1_01 = PIN(GPIO10, 22, GPIO_DISP_B1_01, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_DISP_B1_02 = PIN(GPIO10, 23, GPIO_DISP_B1_02, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_DISP_B1_03 = PIN(GPIO10, 24, GPIO_DISP_B1_03, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_DISP_B1_04 = PIN(GPIO10, 25, GPIO_DISP_B1_04, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_DISP_B1_05 = PIN(GPIO10, 26, GPIO_DISP_B1_05, NO_ADC, 0, 0x00000005, 0x00000008); +const mcu_pin_obj_t pin_GPIO_DISP_B1_06 = PIN(GPIO10, 27, GPIO_DISP_B1_06, NO_ADC, 0, 0x00000005, 0x0000000C); +const mcu_pin_obj_t pin_GPIO_DISP_B1_07 = PIN(GPIO10, 28, GPIO_DISP_B1_07, NO_ADC, 0, 0x00000005, 0x0000000C); +const mcu_pin_obj_t pin_GPIO_DISP_B1_08 = PIN(GPIO10, 29, GPIO_DISP_B1_08, NO_ADC, 0, 0x00000005, 0x0000000C); +const mcu_pin_obj_t pin_GPIO_DISP_B1_09 = PIN(GPIO10, 30, GPIO_DISP_B1_09, NO_ADC, 0, 0x00000005, 0x0000000C); +const mcu_pin_obj_t pin_GPIO_DISP_B1_10 = PIN(GPIO10, 31, GPIO_DISP_B1_10, NO_ADC, 0, 0x00000005, 0x0000000C); +const mcu_pin_obj_t pin_GPIO_DISP_B1_11 = PIN(GPIO11, 0, GPIO_DISP_B1_11, NO_ADC, 0, 0x00000005, 0x0000000C); +const mcu_pin_obj_t pin_GPIO_DISP_B2_00 = PIN(GPIO11, 1, GPIO_DISP_B2_00, NO_ADC, 0, 0x00000005, 0x00000002); +const mcu_pin_obj_t pin_GPIO_DISP_B2_01 = PIN(GPIO11, 2, GPIO_DISP_B2_01, NO_ADC, 0, 0x00000005, 0x00000002); +const mcu_pin_obj_t pin_GPIO_DISP_B2_02 = PIN(GPIO11, 3, GPIO_DISP_B2_02, NO_ADC, 0, 0x00000005, 0x00000002); +const mcu_pin_obj_t pin_GPIO_DISP_B2_03 = PIN(GPIO11, 4, GPIO_DISP_B2_03, NO_ADC, 0, 0x00000005, 0x00000002); +const mcu_pin_obj_t pin_GPIO_DISP_B2_04 = PIN(GPIO11, 5, GPIO_DISP_B2_04, NO_ADC, 0, 0x00000005, 0x00000002); +const mcu_pin_obj_t pin_GPIO_DISP_B2_05 = PIN(GPIO11, 6, GPIO_DISP_B2_05, NO_ADC, 0, 0x00000005, 0x00000002); +const mcu_pin_obj_t pin_GPIO_DISP_B2_06 = PIN(GPIO11, 7, GPIO_DISP_B2_06, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_DISP_B2_07 = PIN(GPIO11, 8, GPIO_DISP_B2_07, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_DISP_B2_08 = PIN(GPIO11, 9, GPIO_DISP_B2_08, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_DISP_B2_09 = PIN(GPIO11, 10, GPIO_DISP_B2_09, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_DISP_B2_10 = PIN(GPIO11, 11, GPIO_DISP_B2_10, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_DISP_B2_11 = PIN(GPIO11, 12, GPIO_DISP_B2_11, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_DISP_B2_12 = PIN(GPIO11, 13, GPIO_DISP_B2_12, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_DISP_B2_13 = PIN(GPIO11, 14, GPIO_DISP_B2_13, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_DISP_B2_14 = PIN(GPIO11, 15, GPIO_DISP_B2_14, NO_ADC, 0, 0x00000005, 0x00000006); +const mcu_pin_obj_t pin_GPIO_DISP_B2_15 = PIN(GPIO11, 16, GPIO_DISP_B2_15, NO_ADC, 0, 0x00000005, 0x0000000E); diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pins.h new file mode 100644 index 0000000000..0d99219c8a --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pins.h @@ -0,0 +1,36 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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. + */ + +#pragma once + +#define FORMAT_PIN(pin_name) extern const mcu_pin_obj_t pin_##pin_name; +#include "pin_names.h" +#undef FORMAT_PIN + +#define PIN_COUNT (IOMUXC_SW_PAD_CTL_PAD_COUNT + 0) +extern const mcu_pin_obj_t mcu_pin_list[PIN_COUNT]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/periph.h index 8184d5b135..ffbd72339e 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/periph.h @@ -78,10 +78,18 @@ extern LPUART_Type *const mcu_uart_banks[]; #ifdef MIMXRT1011_SERIES #include "MIMXRT1011/periph.h" +#elif defined(MIMXRT1015_SERIES) +#include "MIMXRT1015/periph.h" #elif defined(MIMXRT1021_SERIES) #include "MIMXRT1021/periph.h" +#elif defined(MIMXRT1042_SERIES) +#include "MIMXRT1042/periph.h" +#elif defined(MIMXRT1052_SERIES) +#include "MIMXRT1052/periph.h" #elif defined(MIMXRT1062_SERIES) #include "MIMXRT1062/periph.h" +#elif defined(MIMXRT1176_cm7_SERIES) +#include "MIMXRT1176/periph.h" #endif #endif // MICROPY_INCLUDED_MIMXRT10XX_PERIPHERALS_PERIPH_H diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/pin_names.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/pin_names.h new file mode 100644 index 0000000000..37db5c2261 --- /dev/null +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/pin_names.h @@ -0,0 +1,42 @@ +/* + * This file is part of the Micro Python project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2017 Scott Shawcroft for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * + * 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. + */ + +// OK to include more than once because FORMAT_PIN may be different. + +#ifdef MIMXRT1011_SERIES +#include "MIMXRT1011/pin_names.h" +#elif defined(MIMXRT1021_SERIES) +#include "MIMXRT1021/pin_names.h" +#elif defined(MIMXRT1042_SERIES) +#include "MIMXRT1042/pin_names.h" +#elif defined(MIMXRT1052_SERIES) +#include "MIMXRT1052/pin_names.h" +#elif defined(MIMXRT1062_SERIES) +#include "MIMXRT1062/pin_names.h" +#elif defined(MIMXRT1176_cm7_SERIES) +#include "MIMXRT1176/pin_names.h" +#endif diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/pins.h index 0457a09a1a..8ffc17ba07 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/pins.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/pins.h @@ -78,10 +78,18 @@ void enable_pin_change_interrupt(const mcu_pin_obj_t *pin, gpio_change_interrupt #ifdef MIMXRT1011_SERIES #include "MIMXRT1011/pins.h" +#elif defined(MIMXRT1015_SERIES) +#include "MIMXRT1015/pins.h" #elif defined(MIMXRT1021_SERIES) #include "MIMXRT1021/pins.h" +#elif defined(MIMXRT1042_SERIES) +#include "MIMXRT1042/pins.h" +#elif defined(MIMXRT1052_SERIES) +#include "MIMXRT1052/pins.h" #elif defined(MIMXRT1062_SERIES) #include "MIMXRT1062/pins.h" +#elif defined(MIMXRT1176_cm7_SERIES) +#include "MIMXRT1176/pins.h" #endif #endif // MICROPY_INCLUDED_MIMXRT10XX_PERIPHERALS_PINS_H diff --git a/ports/mimxrt10xx/sdk b/ports/mimxrt10xx/sdk index 2b9354539e..9990f264f9 160000 --- a/ports/mimxrt10xx/sdk +++ b/ports/mimxrt10xx/sdk @@ -1 +1 @@ -Subproject commit 2b9354539e6e4f722749e87b0bdc22966dc080d9 +Subproject commit 9990f264f98430f6d885041ab0f24224d68f4958 diff --git a/ports/mimxrt10xx/supervisor/flexspi_nor_flash_ops.c b/ports/mimxrt10xx/supervisor/flexspi_nor_flash_ops.c index e32eaf8832..3ccd67096a 100644 --- a/ports/mimxrt10xx/supervisor/flexspi_nor_flash_ops.c +++ b/ports/mimxrt10xx/supervisor/flexspi_nor_flash_ops.c @@ -137,7 +137,7 @@ status_t PLACE_IN_ITCM(flexspi_nor_flash_page_program)(FLEXSPI_Type * base, uint status = flexspi_nor_wait_bus_busy(base); /* Do software reset. */ - #if defined(FSL_FEATURE_SOC_OTFAD_COUNT) + #if defined(FSL_FEATURE_SOC_OTFAD_COUNT) && FSL_FEATURE_SOC_OTFAD_COUNT == 1 base->AHBCR |= FLEXSPI_AHBCR_CLRAHBRXBUF_MASK | FLEXSPI_AHBCR_CLRAHBTXBUF_MASK; base->AHBCR &= ~(FLEXSPI_AHBCR_CLRAHBRXBUF_MASK | FLEXSPI_AHBCR_CLRAHBTXBUF_MASK); #else diff --git a/ports/mimxrt10xx/supervisor/internal_flash.c b/ports/mimxrt10xx/supervisor/internal_flash.c index bacb62854a..cd4dd33ba0 100644 --- a/ports/mimxrt10xx/supervisor/internal_flash.c +++ b/ports/mimxrt10xx/supervisor/internal_flash.c @@ -52,6 +52,11 @@ extern uint32_t __fatfs_flash_length[]; uint8_t _flash_cache[SECTOR_SIZE] __attribute__((aligned(4))); uint32_t _flash_page_addr = NO_CACHE; +#ifndef FLEXSPI +#define FLEXSPI FLEXSPI1 +#define FlexSPI_AMBA_BASE FlexSPI1_AMBA_BASE +#endif + void PLACE_IN_ITCM(supervisor_flash_init)(void) { // Update the LUT to make sure all entries are available. Copy the values to // memory first so that we don't read from the flash as we update the LUT. @@ -62,6 +67,41 @@ void PLACE_IN_ITCM(supervisor_flash_init)(void) { __DSB(); __ISB(); flexspi_nor_init(); + + #if IMXRT10XX + // Disable interrupts of priority 8+. They likely use code in flash + // itself. Higher priority interrupts (<8) should ensure all of their + // code is in RAM. + __set_BASEPRI(8 << (8 - __NVIC_PRIO_BITS)); + + // Increase clock speed to 120 MHz + // Wait for bus idle before change flash configuration. + while (!FLEXSPI_GetBusIdleStatus(FLEXSPI)) { + } + FLEXSPI_Enable(FLEXSPI, false); + + // Disable FlexSPI clock + CCM->CCGR6 &= ~CCM_CCGR6_CG5_MASK; + + // Changing the clock is OK now. + + // The PFD is 480 * 18 / PFD0_FRAC. We do / 18 which outputs 480 MHz. + CCM_ANALOG->PFD_480 = (CCM_ANALOG->PFD_480 & ~CCM_ANALOG_PFD_480_TOG_PFD0_FRAC_MASK) | CCM_ANALOG_PFD_480_TOG_PFD0_FRAC(18); + + // This divides down the 480 Mhz by PODF + 1. So 480 / (3 + 1) = 120 MHz. + CCM->CSCMR1 = (CCM->CSCMR1 & ~CCM_CSCMR1_FLEXSPI_PODF_MASK) | CCM_CSCMR1_FLEXSPI_PODF(3); + + // Re-enable FlexSPI + CCM->CCGR6 |= CCM_CCGR6_CG5_MASK; + + FLEXSPI_Enable(FLEXSPI, true); + + FLEXSPI_SoftwareReset(FLEXSPI); + + while (!FLEXSPI_GetBusIdleStatus(FLEXSPI)) { + } + __set_BASEPRI(0U); + #endif } static inline uint32_t lba2addr(uint32_t block) { diff --git a/ports/mimxrt10xx/supervisor/port.c b/ports/mimxrt10xx/supervisor/port.c index feb8566aad..997a97ba49 100644 --- a/ports/mimxrt10xx/supervisor/port.c +++ b/ports/mimxrt10xx/supervisor/port.c @@ -89,11 +89,13 @@ extern uint32_t _ld_stack_top; extern uint32_t __isr_vector[]; +extern uint32_t _ld_ocram_start; extern uint32_t _ld_ocram_bss_start; extern uint32_t _ld_ocram_bss_size; extern uint32_t _ld_ocram_data_destination; extern uint32_t _ld_ocram_data_size; extern uint32_t _ld_ocram_data_flash_copy; +extern uint32_t _ld_ocram_end; extern uint32_t _ld_dtcm_bss_start; extern uint32_t _ld_dtcm_bss_size; extern uint32_t _ld_dtcm_data_destination; @@ -106,36 +108,6 @@ extern uint32_t _ld_isr_destination; extern uint32_t _ld_isr_size; extern uint32_t _ld_isr_flash_copy; -// Remove these once the SDK re-includes them. -// https://github.com/nxp-mcuxpresso/mcux-sdk/issues/110 -/*! @name GPR14 - GPR14 General Purpose Register */ -/*! @{ */ -#define IOMUXC_GPR_GPR14_CM7_CFGITCMSZ_MASK (0xF0000U) -#define IOMUXC_GPR_GPR14_CM7_CFGITCMSZ_SHIFT (16U) -/*! CM7_CFGITCMSZ - * 0b0000..0 KB (No ITCM) - * 0b0011..4 KB - * 0b0100..8 KB - * 0b0101..16 KB - * 0b0110..32 KB - * 0b0111..64 KB - * 0b1000..128 KB - */ -#define IOMUXC_GPR_GPR14_CM7_CFGITCMSZ(x) (((uint32_t)(((uint32_t)(x)) << IOMUXC_GPR_GPR14_CM7_CFGITCMSZ_SHIFT)) & IOMUXC_GPR_GPR14_CM7_CFGITCMSZ_MASK) -#define IOMUXC_GPR_GPR14_CM7_CFGDTCMSZ_MASK (0xF00000U) -#define IOMUXC_GPR_GPR14_CM7_CFGDTCMSZ_SHIFT (20U) -/*! CM7_CFGDTCMSZ - * 0b0000..0 KB (No DTCM) - * 0b0011..4 KB - * 0b0100..8 KB - * 0b0101..16 KB - * 0b0110..32 KB - * 0b0111..64 KB - * 0b1000..128 KB - */ -#define IOMUXC_GPR_GPR14_CM7_CFGDTCMSZ(x) (((uint32_t)(((uint32_t)(x)) << IOMUXC_GPR_GPR14_CM7_CFGDTCMSZ_SHIFT)) & IOMUXC_GPR_GPR14_CM7_CFGDTCMSZ_MASK) -/*! @} */ - extern void main(void); // This replaces the Reset_Handler in startup_*.S and SystemInit in system_*.c. @@ -159,18 +131,27 @@ __attribute__((used, naked, no_instrument_function, optimize("no-tree-loop-distr // then the return will jump to an invalid address. // Configure FlexRAM. The e is one block of ITCM (0b11) and DTCM (0b10). The rest is two OCRAM // (0b01). We shift in zeroes for all unimplemented banks. - IOMUXC_GPR->GPR17 = (0xe5555555) >> (32 - 2 * FSL_FEATURE_FLEXRAM_INTERNAL_RAM_TOTAL_BANK_NUMBERS); + uint32_t flexram_config = (0xe5555555) >> (32 - 2 * FSL_FEATURE_FLEXRAM_INTERNAL_RAM_TOTAL_BANK_NUMBERS); + // imxrt1176 splits the config across two registers. + #ifdef IOMUXC_GPR_GPR17_FLEXRAM_BANK_CFG_LOW_MASK + IOMUXC_GPR->GPR17 = flexram_config & IOMUXC_GPR_GPR17_FLEXRAM_BANK_CFG_LOW_MASK; + IOMUXC_GPR->GPR18 = (flexram_config >> 16) & IOMUXC_GPR_GPR18_FLEXRAM_BANK_CFG_HIGH_MASK; + #else + IOMUXC_GPR->GPR17 = flexram_config; + #endif // Switch from FlexRAM fuse config to the IOMUXC values. IOMUXC_GPR->GPR16 |= IOMUXC_GPR_GPR16_FLEXRAM_BANK_CFG_SEL(1); // Let the core know the TCM sizes changed. + #ifdef IOMUXC_GPR_GPR14_CM7_CFGDTCMSZ_MASK uint32_t current_gpr14 = IOMUXC_GPR->GPR14; current_gpr14 &= ~IOMUXC_GPR_GPR14_CM7_CFGDTCMSZ_MASK; current_gpr14 |= IOMUXC_GPR_GPR14_CM7_CFGDTCMSZ(0x6); current_gpr14 &= ~IOMUXC_GPR_GPR14_CM7_CFGITCMSZ_MASK; current_gpr14 |= IOMUXC_GPR_GPR14_CM7_CFGITCMSZ(0x6); IOMUXC_GPR->GPR14 = current_gpr14; + #endif // Enable FlexRAM interrupts on invalid access. FLEXRAM->INT_STAT_EN = FLEXRAM_INT_STAT_EN_ITCM_ERR_STAT_EN(1) | @@ -182,6 +163,7 @@ __attribute__((used, naked, no_instrument_function, optimize("no-tree-loop-distr #endif /* ((__FPU_PRESENT == 1) && (__FPU_USED == 1)) */ /* Disable Watchdog Power Down Counter */ + #if defined(RTWDOG) WDOG1->WMCR &= ~WDOG_WMCR_PDE_MASK; WDOG2->WMCR &= ~WDOG_WMCR_PDE_MASK; @@ -191,6 +173,32 @@ __attribute__((used, naked, no_instrument_function, optimize("no-tree-loop-distr RTWDOG->CNT = 0xD928C520U; /* 0xD928C520U is the update key */ RTWDOG->TOVAL = 0xFFFF; RTWDOG->CS = (uint32_t)((RTWDOG->CS) & ~RTWDOG_CS_EN_MASK) | RTWDOG_CS_UPDATE_MASK; + #endif + + #if defined(RTWDOG3) + if ((WDOG1->WCR & WDOG_WCR_WDE_MASK) != 0U) { + WDOG1->WCR &= ~(uint16_t)WDOG_WCR_WDE_MASK; + } + if ((WDOG2->WCR & WDOG_WCR_WDE_MASK) != 0U) { + WDOG2->WCR &= ~(uint16_t)WDOG_WCR_WDE_MASK; + } + if ((RTWDOG3->CS & RTWDOG_CS_CMD32EN_MASK) != 0U) { + RTWDOG3->CNT = 0xD928C520U; /* 0xD928C520U is the update key */ + } else { + RTWDOG3->CNT = 0xC520U; + RTWDOG3->CNT = 0xD928U; + } + RTWDOG3->TOVAL = 0xFFFF; + RTWDOG3->CS = (uint32_t)((RTWDOG3->CS) & ~RTWDOG_CS_EN_MASK) | RTWDOG_CS_UPDATE_MASK; + if ((RTWDOG4->CS & RTWDOG_CS_CMD32EN_MASK) != 0U) { + RTWDOG4->CNT = 0xD928C520U; /* 0xD928C520U is the update key */ + } else { + RTWDOG4->CNT = 0xC520U; + RTWDOG4->CNT = 0xD928U; + } + RTWDOG4->TOVAL = 0xFFFF; + RTWDOG4->CS = (uint32_t)((RTWDOG4->CS) & ~RTWDOG_CS_EN_MASK) | RTWDOG_CS_UPDATE_MASK; + #endif /* Disable Systick which might be enabled by bootrom */ if (SysTick->CTRL & SysTick_CTRL_ENABLE_Msk) { @@ -227,6 +235,9 @@ __attribute__((used, naked, no_instrument_function, optimize("no-tree-loop-distr // FlexSPI2 is 0x70000000 // This the first portion (1MB, 2MB or 4MB) of flash is the bootloader and CircuitPython read-only data. + #if !defined(FlexSPI_AMBA_BASE) + #define FlexSPI_AMBA_BASE FlexSPI1_AMBA_BASE + #endif MPU->RBAR = ARM_MPU_RBAR(10, FlexSPI_AMBA_BASE); uint32_t region_size = ARM_MPU_REGION_SIZE_32B; uint32_t code_size = ((uint32_t)&_ld_filesystem_start) - FlexSPI_AMBA_BASE; @@ -265,13 +276,18 @@ __attribute__((used, naked, no_instrument_function, optimize("no-tree-loop-distr // This is OCRAM. We mark it as shareable so that it isn't cached. This makes USB work at the // cost of 1/4 speed OCRAM accesses. It will leave more room for caching data from the flash // too which might be a net win. - MPU->RBAR = ARM_MPU_RBAR(14, 0x20200000U); + MPU->RBAR = ARM_MPU_RBAR(14, ((uint32_t)&_ld_ocram_start)); MPU->RASR = ARM_MPU_RASR(NO_EXECUTION, ARM_MPU_AP_FULL, NORMAL, NOT_SHAREABLE, CACHEABLE, BUFFERABLE, NO_SUBREGIONS, ARM_MPU_REGION_SIZE_512KB); + #if IMXRT10XX // We steal 64k from FlexRAM for ITCM and DTCM so disable those memory regions here. // We use 64k from FlexRAM for ITCM and DTCM so disable those memory regions here. - MPU->RBAR = ARM_MPU_RBAR(15, 0x20280000U); + MPU->RBAR = ARM_MPU_RBAR(15, ((uint32_t)&_ld_ocram_end)); MPU->RASR = ARM_MPU_RASR(EXECUTION, ARM_MPU_AP_FULL, NORMAL, NOT_SHAREABLE, CACHEABLE, BUFFERABLE, 0x80, ARM_MPU_REGION_SIZE_512KB); + #else + // On the iMX RT 11xx OCRAM is not flexram (for now). So no need to mask it off. + #endif + /* Enable MPU */ ARM_MPU_Enable(MPU_CTRL_PRIVDEFENA_Msk); @@ -330,7 +346,9 @@ void __attribute__((no_instrument_function,section(".itcm.profile_exit"),long_ca } safe_mode_t port_init(void) { + #if IMXRT10XX CLOCK_SetMode(kCLOCK_ModeRun); + #endif clocks_init(); @@ -380,6 +398,9 @@ safe_mode_t port_init(void) { for (uint16_t i = 0; i < NUMBER_OF_INT_VECTORS; i++) { NVIC_SetPriority(i, (1UL << __NVIC_PRIO_BITS) - 1UL); } + #ifdef MIMXRT1042_SERIES + #define USB_OTG1_IRQn USB_OTG_IRQn + #endif NVIC_SetPriority(USB_OTG1_IRQn, 1); #ifdef USBPHY2 NVIC_SetPriority(USB_OTG2_IRQn, 1); @@ -398,7 +419,21 @@ safe_mode_t port_init(void) { // Always enable the SNVS interrupt. The GPC won't wake us up unless at least one interrupt is // enabled. It won't occur very often so it'll be low overhead. + #if IMXRT11XX + NVIC_EnableIRQ(SNVS_HP_NON_TZ_IRQn); + #else NVIC_EnableIRQ(SNVS_HP_WRAPPER_IRQn); + #endif + + #if IMXRT11XX + /* Save SRSR to another register so we can read it later. */ + SRC->GPR[11] = SRC->SRSR; + SRC->SRSR = 0xFFFFFFFFU; + + if ((SRC->GPR[11] & SRC_SRSR_M7_LOCKUP_M7_MASK) != 0) { + return SAFE_MODE_HARD_FAULT; + } + #endif // Note that `reset_port` CANNOT GO HERE, unlike other ports, because `board_init` hasn't been // run yet, which uses `never_reset` to protect critical pins from being reset by `reset_port`. @@ -411,7 +446,9 @@ safe_mode_t port_init(void) { } void reset_port(void) { + #if CIRCUITPY_BUSIO spi_reset(); + #endif #if CIRCUITPY_AUDIOIO audio_dma_reset(); @@ -497,9 +534,15 @@ uint64_t port_get_raw_ticks(uint8_t *subticks) { return ticks / 32; } +#if IMXRT10XX void SNVS_HP_WRAPPER_IRQHandler(void); __attribute__((used)) void PLACE_IN_ITCM(SNVS_HP_WRAPPER_IRQHandler)(void) { +#else +void SNVS_HP_NON_TZ_IRQHandler(void); +__attribute__((used)) +void PLACE_IN_ITCM(SNVS_HP_NON_TZ_IRQHandler)(void) { + #endif if ((SNVS->HPSR & SNVS_HPSR_PI_MASK) != 0) { supervisor_tick(); SNVS->HPSR = SNVS_HPSR_PI_MASK; @@ -552,7 +595,11 @@ void port_idle_until_interrupt(void) { common_hal_mcu_disable_interrupts(); if (!background_callback_pending()) { + #if IMXRT11XX + NVIC_ClearPendingIRQ(SNVS_HP_NON_TZ_IRQn); + #else NVIC_ClearPendingIRQ(SNVS_HP_WRAPPER_IRQn); + #endif __WFI(); } common_hal_mcu_enable_interrupts(); diff --git a/ports/mimxrt10xx/supervisor/usb.c b/ports/mimxrt10xx/supervisor/usb.c index bc6bc5f0cd..64a2639c16 100644 --- a/ports/mimxrt10xx/supervisor/usb.c +++ b/ports/mimxrt10xx/supervisor/usb.c @@ -79,8 +79,13 @@ STATIC void init_usb_instance(mp_int_t instance) { // Provide the prototypes for the interrupt handlers. The iMX RT SDK doesn't. // The SDK only links to them from assembly. + #ifdef MIMXRT1042_SERIES + void USB_OTG_IRQHandler(void); + void PLACE_IN_ITCM(USB_OTG_IRQHandler)(void) { + #else void USB_OTG1_IRQHandler(void); void PLACE_IN_ITCM(USB_OTG1_IRQHandler)(void) { + #endif usb_irq_handler(0); } diff --git a/ports/mimxrt10xx/tools/gen_peripherals_data.py b/ports/mimxrt10xx/tools/gen_peripherals_data.py new file mode 100644 index 0000000000..0b4f215279 --- /dev/null +++ b/ports/mimxrt10xx/tools/gen_peripherals_data.py @@ -0,0 +1,356 @@ +import sys +import pathlib +import xml.etree.ElementTree as ET + +SIGNALS = { + "LPI2C": ["SDA", "SCL"], + "LPSPI": ["SCK", "SDO", "SDI"], + "LPUART": ["RX", "TX", "RTS", "CTS"], + "I2S": ["RX_DATA0", "RX_SYNC", "TX_BCLK", "TX_DATA0", "TX_SYNC"], + "MQS": ["LEFT", "RIGHT"], +} + +SIGNAL_RENAME = { + "CTS_B": "CTS", + "RTS_B": "RTS", + "RXD": "RX", + "TXD": "TX", + "TX_DATA00": "TX_DATA0", + "RX_DATA00": "RX_DATA0", + "TX_DATA": "TX_DATA0", + "RX_DATA": "RX_DATA0", +} + +SKIP_LPSR = True + +svd_folder = pathlib.Path(sys.argv[1]) + +# Download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data +config_data_folder = pathlib.Path(sys.argv[2]) +devices = sys.argv[3:] + +peripherals_dir = pathlib.Path("peripherals/mimxrt10xx") + +copyright = """/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Lucian Copeland for Adafruit Industries + * Copyright (c) 2019 Artur Pacholec + * Copyright (c) 2023 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. + */ +""" + +for device in devices: + print(device) + svd_fn = svd_folder / device / (device + ".xml") + if not svd_fn.exists(): + svd_fn = svd_folder / device / (device + "_cm7.xml") + + pin_to_analog = {} + out_dir = peripherals_dir / device + largest_signals = None + for signal_file in config_data_folder.glob( + f"{device}*ConfigTools_data*/**/signal_configuration.xml" + ): + if largest_signals is None or signal_file.stat().st_size > largest_signals.stat().st_size: + largest_signals = signal_file + + # Use the signal file to find analog connections + signal_tree = ET.parse(largest_signals) + signal_root = signal_tree.getroot() + for connection in signal_root.iter("connections"): + if "name_part" not in connection.attrib or not connection.attrib["name_part"].startswith( + "ADC" + ): + continue + name_part = connection.attrib["name_part"] + try: + assign = next(connection.iter("assign")) + except StopIteration: + continue + split_pin = assign.attrib["register"].split("_") + pin_name = "_".join(split_pin[split_pin.index("GPIO") :]) + adc_instance, adc_channel = name_part.split("_") + + try: + adc_channel = int(adc_channel[2:]) + except ValueError: + continue + pin_to_analog[pin_name] = (adc_instance, adc_channel) + + # Find USB pins + usb_pins = [] + all_pins = set() + for pin in signal_root.iter("pin"): + pin_name = pin.get("name") + if SKIP_LPSR and "LPSR" in pin_name: + continue + all_pins.add(pin_name) + if not pin_name.startswith("USB_OTG"): + continue + if not pin_name.endswith(("DN", "DP")): + continue + usb_pins.append(pin_name) + + # Find peripherals + all_peripherals = {} + for peripheral in signal_root.iter("peripheral"): + ptype = peripheral.get("peripheral_type") + if ptype not in all_peripherals: + all_peripherals[ptype] = [] + all_peripherals[ptype].append(peripheral.get("id")) + + print(svd_fn) + tree = ET.parse(svd_fn) + root = tree.getroot() + pin_number = 0 + last_gpio_base = None + mux_register_base = None + + pins_h = [ + copyright, + "#pragma once", + "", + "#define FORMAT_PIN(pin_name) extern const mcu_pin_obj_t pin_##pin_name;", + '#include "pin_names.h"', + "#undef FORMAT_PIN", + ] + pins_c = [ + copyright, + '#include "py/obj.h"', + '#include "py/mphal.h"', + '#include "mimxrt10xx/pins.h"', + "", + ] + pin_names_h = [copyright, "", "// define FORMAT_PIN(pin_name) and then include this file."] + mux_registers_by_pin = {} + peripheral_inputs = {} + pwm_outputs = [] + for register in root.iter("register"): + name = register.find("name").text + if name.endswith("SELECT_INPUT"): + name_split = name.split("_") + instance = name_split[0] + signal = "_".join(name_split[1:-2]) + signal = SIGNAL_RENAME.get(signal, signal) + if instance not in peripheral_inputs: + peripheral_inputs[instance] = {} + if signal not in peripheral_inputs[instance]: + peripheral_inputs[instance][signal] = {} + for evalue in register.iter("enumeratedValue"): + ename = evalue.find("name").text.strip("_") + if "_ALT" in ename: + pin_name, alt = ename.rsplit("_", maxsplit=1) + else: + pin_name = ename + alt = evalue.find("description").text.rsplit(maxsplit=1)[1] + if SKIP_LPSR and "LPSR" in pin_name: + continue + alt = int(alt[3:]) + value = int(evalue.find("value").text, 0) + peripheral_inputs[instance][signal][pin_name] = [alt, name, value] + # Mux registers come before PAD registers. + elif name.startswith("SW_MUX_CTL_PAD_GPIO"): + address_offset = int(register.find("addressOffset").text, 16) + if mux_register_base is None: + mux_register_base = address_offset + + split_pin = name.split("_") + pin_name = "_".join(split_pin[4:]) + if pin_name not in all_pins: + continue + gpio_base = "_".join(split_pin[4:-1]) + + mux_registers_by_pin[pin_name] = register + + if last_gpio_base != gpio_base: + pin_names_h.append("") + last_gpio_base = gpio_base + + pin_number += 1 + + pin_names_h.append(f"FORMAT_PIN({pin_name})") + elif name.startswith("SW_PAD_CTL_PAD_GPIO"): + split_pin = name.split("_") + pin_name = "_".join(split_pin[4:]) + if pin_name not in all_pins: + continue + mux_register = mux_registers_by_pin[pin_name] + mux_reset = int(mux_register.find("resetValue").text, 16) + + pad_reset = int(register.find("resetValue").text, 16) + + # Look through alt modes to find GPIO. + mux_field = mux_register.find("fields").find("field") + assert mux_field.find("name").text == "MUX_MODE" + for alt in mux_field.iter("enumeratedValue"): + desc = alt.find("description").text + if "FLEXPWM" in desc: + desc_split = desc.split() + alt = desc_split[3] + connection = desc_split[6] + pwm_instance = int(connection[7:8]) + if connection.count("_") == 1: + # Form: FLEXPWM#_PWMC## + channel = connection[-3:-2] + module = int(connection[-2:]) + else: # two _ + # Form: FLEXPWM#_PWM#_C + channel = connection[-1:] + module = int(connection[-3:-2]) + pwm_outputs.append((pwm_instance, module, channel, connection, pin_name)) + elif "GPIO" in desc: + alt_name = desc.split()[-4] + # The 117x has a GPIO mux between GPIOn and CM7_GPIOn. For now, + # we use the the slow, default GPIOn. + if alt_name.startswith("GPIO_MUX"): + alt_name = alt_name.replace("GPIO_MUX", "GPIO") + gpio_instance, gpio_number = alt_name.split("_") + if gpio_instance == "GPIOMUX": + gpio_instance = "GPIO1" + gpio_number = int(gpio_number[2:]) + else: + desc_split = desc.split() + alt = desc_split[3] + connection = desc_split[6] + alt = int(alt[3:]) + if "_" not in connection: + print("skipping", pin_name, connection) + continue + instance, signal = connection.split("_", maxsplit=1) + signal = SIGNAL_RENAME.get(signal, signal) + if instance not in peripheral_inputs: + peripheral_inputs[instance] = {} + if signal not in peripheral_inputs[instance]: + peripheral_inputs[instance][signal] = {} + peripheral_inputs[instance][signal][pin_name] = [alt, None, 0] + + if pin_name in pin_to_analog: + adc_instance, adc_channel = pin_to_analog[pin_name] + else: + adc_instance = "NO_ADC" + adc_channel = 0 + + pins_c.append( + f"const mcu_pin_obj_t pin_{pin_name} = PIN({gpio_instance}, {gpio_number}, {pin_name}, {adc_instance}, {adc_channel}, 0x{mux_reset:08X}, 0x{pad_reset:08X});" + ) + + pins_c.append("") + + for pin_name in sorted(usb_pins): + pin_names_h.append(f"FORMAT_PIN({pin_name})") + pins_c.append(f"const mcu_pin_obj_t pin_{pin_name} = {{ {{ &mcu_pin_type }}, }};") + + pin_names_h.append("") + pins_c.append("") + + pins_h.append("") + pins_h.append(f"#define PIN_COUNT (IOMUXC_SW_PAD_CTL_PAD_COUNT + {len(usb_pins)})") + pins_h.append(f"extern const mcu_pin_obj_t mcu_pin_list[PIN_COUNT];") + pins_h.append("") + + out_dir.mkdir(exist_ok=True) + + (out_dir / "pin_names.h").write_text("\n".join(pin_names_h)) + (out_dir / "pins.h").write_text("\n".join(pins_h)) + (out_dir / "pins.c").write_text("\n".join(pins_c)) + + periph_h = [copyright, "#pragma once"] + periph_c = [ + copyright, + '#include "py/obj.h"', + '#include "py/mphal.h"', + '#include "mimxrt10xx/periph.h"', + "", + ] + + for ptype in SIGNALS: + instances = all_peripherals[ptype] + short_name = ptype.lower() + if short_name.startswith("lp"): + short_name = short_name[2:] + # Only one MQS exists and it is related to SAI3 + if ptype != "MQS": + periph_h.append( + f"extern {ptype}_Type *const mcu_{short_name}_banks[{len(instances)}];" + ) + joined_instances = ", ".join(instances) + periph_c.append( + f"{ptype}_Type *const mcu_{short_name}_banks[{len(instances)}] = {{ {joined_instances} }};" + ) + periph_c.append("") + for signal in SIGNALS[ptype]: + pin_count = 0 + for instance in instances: + if instance not in peripheral_inputs or signal not in peripheral_inputs[instance]: + continue + pin_count += len(peripheral_inputs[instance][signal]) + periph_h.append( + f"extern const mcu_periph_obj_t mcu_{short_name}_{signal.lower()}_list[{pin_count}];" + ) + periph_c.append( + f"const mcu_periph_obj_t mcu_{short_name}_{signal.lower()}_list[{pin_count}] = {{" + ) + for instance in instances: + if instance not in peripheral_inputs or signal not in peripheral_inputs[instance]: + continue + # MQS is tied to SAI3 + if instance == "MQS": + instance_number = 3 + else: + instance_number = int(instance[len(ptype) :]) + if instance_number > 1: + periph_c.append("") + pins = peripheral_inputs[instance][signal] + pin_names = list(pins.keys()) + pin_names.sort(key=lambda x: pins[x][-1]) + for pin_name in pin_names: + alt, select_input, input_value = pins[pin_name] + if select_input: + select_input = f"kIOMUXC_{select_input}" + else: + select_input = "0" + periph_c.append( + f" PERIPH_PIN({instance_number}, {alt}, {select_input}, {input_value}, &pin_{pin_name})," + ) + periph_c.append(f"}};") + periph_c.append(f"") + periph_h.append("") + + pwm_outputs.sort(key=lambda x: x[:3]) + periph_c.append(f"const mcu_pwm_obj_t mcu_pwm_list[{len(pwm_outputs)}] = {{") + periph_h.append(f"extern const mcu_pwm_obj_t mcu_pwm_list[{len(pwm_outputs)}];") + last_channel = None + for pwm_instance, module, channel, connection, pin_name in pwm_outputs: + this_channel = (pwm_instance, module, channel) + if last_channel is not None and last_channel != this_channel: + periph_c.append("") + last_channel = this_channel + periph_c.append( + f" PWM_PIN(PWM{pwm_instance}, kPWM_Module_{module}, kPWM_Pwm{channel}, IOMUXC_{pin_name}_{connection}, &pin_{pin_name})," + ) + periph_c.append(f"}};") + periph_c.append("") + + (out_dir / "periph.h").write_text("\n".join(periph_h)) + (out_dir / "periph.c").write_text("\n".join(periph_c)) diff --git a/py/stackctrl.c b/py/stackctrl.c index 546987f04d..e534a2f5f9 100644 --- a/py/stackctrl.c +++ b/py/stackctrl.c @@ -30,8 +30,11 @@ void mp_stack_ctrl_init(void) { // Force routine to not be inlined. Better guarantee than MP_NOINLINE for -flto. __asm volatile (""); + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wdangling-pointer" volatile int stack_dummy; MP_STATE_THREAD(stack_top) = (char *)&stack_dummy; + #pragma GCC diagnostic pop } void mp_stack_set_top(void *top) { diff --git a/supervisor/linker.h b/supervisor/linker.h index 9666c4ca12..2d88812da4 100644 --- a/supervisor/linker.h +++ b/supervisor/linker.h @@ -29,7 +29,7 @@ #ifndef MICROPY_INCLUDED_SUPERVISOR_LINKER_H #define MICROPY_INCLUDED_SUPERVISOR_LINKER_H -#if defined(IMXRT10XX) || defined(FOMU) || defined(STM32H7) || defined(RASPBERRYPI) +#if defined(IMXRT1XXX) || defined(FOMU) || defined(STM32H7) || defined(RASPBERRYPI) #define PLACE_IN_DTCM_DATA(name) name __attribute__((section(".dtcm_data." #name))) #define PLACE_IN_DTCM_BSS(name) name __attribute__((section(".dtcm_bss." #name))) // Don't inline ITCM functions because that may pull them out of ITCM into other sections. diff --git a/tools/cortex-m-fault-gdb.py b/tools/cortex-m-fault-gdb.py index 2ed2d13909..54a921e91f 100644 --- a/tools/cortex-m-fault-gdb.py +++ b/tools/cortex-m-fault-gdb.py @@ -74,12 +74,19 @@ class CortexMFault(gdb.Command): print("No preempted exceptions") else: print("Another exception was preempted") + print("icsr", hex(icsr)) vectactive = icsr & 0x1FF if vectactive != 0: if vectactive in EXCEPTIONS: print(EXCEPTIONS[vectactive]) else: print(vectactive - 16) + vectpending = (icsr >> 12) & 0x1FF + if vectpending != 0: + if vectpending in EXCEPTIONS: + print(EXCEPTIONS[vectpending]) + else: + print(vectpending - 16) vtor = self._read(VTOR) print("vtor", hex(vtor)) From f837f2438a93303fb6c814a222cc990347b8f308 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 28 Apr 2023 11:16:45 -0700 Subject: [PATCH 097/117] Update USB PIDs --- ports/mimxrt10xx/boards/imxrt1015_evk/mpconfigboard.mk | 2 +- ports/mimxrt10xx/boards/imxrt1040_evk/mpconfigboard.mk | 2 +- ports/mimxrt10xx/boards/imxrt1050_evkb/mpconfigboard.mk | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/mimxrt10xx/boards/imxrt1015_evk/mpconfigboard.mk b/ports/mimxrt10xx/boards/imxrt1015_evk/mpconfigboard.mk index 0f446e13bf..8d73671c8a 100644 --- a/ports/mimxrt10xx/boards/imxrt1015_evk/mpconfigboard.mk +++ b/ports/mimxrt10xx/boards/imxrt1015_evk/mpconfigboard.mk @@ -1,5 +1,5 @@ USB_VID = 0x239A -USB_PID = 0x8078 +USB_PID = 0x8138 USB_PRODUCT = "IMXRT1015-EVK" USB_MANUFACTURER = "NXP" diff --git a/ports/mimxrt10xx/boards/imxrt1040_evk/mpconfigboard.mk b/ports/mimxrt10xx/boards/imxrt1040_evk/mpconfigboard.mk index cf351d906e..9667647c83 100644 --- a/ports/mimxrt10xx/boards/imxrt1040_evk/mpconfigboard.mk +++ b/ports/mimxrt10xx/boards/imxrt1040_evk/mpconfigboard.mk @@ -1,5 +1,5 @@ USB_VID = 0x239A -USB_PID = 0x8084 +USB_PID = 0x8136 USB_PRODUCT = "iMX RT 1040 EVK" USB_MANUFACTURER = "NXP" diff --git a/ports/mimxrt10xx/boards/imxrt1050_evkb/mpconfigboard.mk b/ports/mimxrt10xx/boards/imxrt1050_evkb/mpconfigboard.mk index 6627d46681..22b26b41a5 100644 --- a/ports/mimxrt10xx/boards/imxrt1050_evkb/mpconfigboard.mk +++ b/ports/mimxrt10xx/boards/imxrt1050_evkb/mpconfigboard.mk @@ -1,5 +1,5 @@ USB_VID = 0x239A -USB_PID = 0x8084 +USB_PID = 0x8134 USB_PRODUCT = "iMX RT 1050 EVKB" USB_MANUFACTURER = "NXP" From 18207cd547e1ffbfbf1ead9f5a32eea69d079ec6 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 28 Apr 2023 11:28:48 -0700 Subject: [PATCH 098/117] Guard GCC13 pragma --- py/stackctrl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/py/stackctrl.c b/py/stackctrl.c index e534a2f5f9..fa5f16d662 100644 --- a/py/stackctrl.c +++ b/py/stackctrl.c @@ -31,7 +31,10 @@ void mp_stack_ctrl_init(void) { // Force routine to not be inlined. Better guarantee than MP_NOINLINE for -flto. __asm volatile (""); #pragma GCC diagnostic push + #if __GNUC__ > 12 + // Introduced in GCC 13 #pragma GCC diagnostic ignored "-Wdangling-pointer" + #endif volatile int stack_dummy; MP_STATE_THREAD(stack_top) = (char *)&stack_dummy; #pragma GCC diagnostic pop From 1fb6d4d77ed006a95722c203e79158da06b39802 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Fri, 28 Apr 2023 16:58:39 -0400 Subject: [PATCH 099/117] I2S pin names per Dan's suggestions on iMX PR --- ports/raspberrypi/boards/pimoroni_pico_dv_base/pins.c | 6 +++--- ports/raspberrypi/boards/pimoroni_pico_dv_base_w/pins.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv_base/pins.c b/ports/raspberrypi/boards/pimoroni_pico_dv_base/pins.c index c331d5cbf9..d5fe927474 100644 --- a/ports/raspberrypi/boards/pimoroni_pico_dv_base/pins.c +++ b/ports/raspberrypi/boards/pimoroni_pico_dv_base/pins.c @@ -53,17 +53,17 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO25) }, { MP_ROM_QSTR(MP_QSTR_GP25), MP_ROM_PTR(&pin_GPIO25) }, - { MP_ROM_QSTR(MP_QSTR_I2S_WS), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_I2S_WORD_SELECT), MP_ROM_PTR(&pin_GPIO26) }, { MP_ROM_QSTR(MP_QSTR_GP26_A0), MP_ROM_PTR(&pin_GPIO26) }, { MP_ROM_QSTR(MP_QSTR_GP26), MP_ROM_PTR(&pin_GPIO26) }, { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) }, - { MP_ROM_QSTR(MP_QSTR_I2S_BCLK), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_I2S_BIT_CLOCK), MP_ROM_PTR(&pin_GPIO27) }, { MP_ROM_QSTR(MP_QSTR_GP27_A1), MP_ROM_PTR(&pin_GPIO27) }, { MP_ROM_QSTR(MP_QSTR_GP27), MP_ROM_PTR(&pin_GPIO27) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, - { MP_ROM_QSTR(MP_QSTR_I2S_OUT), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_I2S_DATA), MP_ROM_PTR(&pin_GPIO28) }, { MP_ROM_QSTR(MP_QSTR_GP28_A2), MP_ROM_PTR(&pin_GPIO28) }, { MP_ROM_QSTR(MP_QSTR_GP28), MP_ROM_PTR(&pin_GPIO28) }, { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) }, diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/pins.c b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/pins.c index 346a2ae44c..6ab85f3c34 100644 --- a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/pins.c +++ b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/pins.c @@ -50,17 +50,17 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_VBUS_SENSE), MP_ROM_PTR(&pin_CYW2) }, - { MP_ROM_QSTR(MP_QSTR_I2S_WS), MP_ROM_PTR(&pin_GPIO26) }, + { MP_ROM_QSTR(MP_QSTR_I2S_WORD_SELECT), MP_ROM_PTR(&pin_GPIO26) }, { MP_ROM_QSTR(MP_QSTR_GP26_A0), MP_ROM_PTR(&pin_GPIO26) }, { MP_ROM_QSTR(MP_QSTR_GP26), MP_ROM_PTR(&pin_GPIO26) }, { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) }, - { MP_ROM_QSTR(MP_QSTR_I2S_BCLK), MP_ROM_PTR(&pin_GPIO27) }, + { MP_ROM_QSTR(MP_QSTR_I2S_BIT_CLOCK), MP_ROM_PTR(&pin_GPIO27) }, { MP_ROM_QSTR(MP_QSTR_GP27_A1), MP_ROM_PTR(&pin_GPIO27) }, { MP_ROM_QSTR(MP_QSTR_GP27), MP_ROM_PTR(&pin_GPIO27) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, - { MP_ROM_QSTR(MP_QSTR_I2S_OUT), MP_ROM_PTR(&pin_GPIO28) }, + { MP_ROM_QSTR(MP_QSTR_I2S_DATA), MP_ROM_PTR(&pin_GPIO28) }, { MP_ROM_QSTR(MP_QSTR_GP28_A2), MP_ROM_PTR(&pin_GPIO28) }, { MP_ROM_QSTR(MP_QSTR_GP28), MP_ROM_PTR(&pin_GPIO28) }, { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) }, From 8104b824e0b304a6edfaf6a9a1d1fd9b925ff22b Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 28 Apr 2023 16:19:43 -0700 Subject: [PATCH 100/117] Standardize CPU temp and voltage. Add autogen warning --- .../common-hal/microcontroller/Processor.c | 2 +- .../common-hal/microcontroller/Processor.c | 2 +- .../common-hal/microcontroller/Processor.c | 2 +- .../mimxrt10xx/MIMXRT1011/periph.c | 8 ++++++++ .../mimxrt10xx/MIMXRT1011/periph.h | 8 ++++++++ .../peripherals/mimxrt10xx/MIMXRT1011/pins.c | 8 ++++++++ .../peripherals/mimxrt10xx/MIMXRT1011/pins.h | 8 ++++++++ .../mimxrt10xx/MIMXRT1015/periph.c | 8 ++++++++ .../mimxrt10xx/MIMXRT1015/periph.h | 8 ++++++++ .../peripherals/mimxrt10xx/MIMXRT1015/pins.c | 8 ++++++++ .../peripherals/mimxrt10xx/MIMXRT1015/pins.h | 8 ++++++++ .../mimxrt10xx/MIMXRT1021/periph.c | 8 ++++++++ .../mimxrt10xx/MIMXRT1021/periph.h | 8 ++++++++ .../peripherals/mimxrt10xx/MIMXRT1021/pins.c | 8 ++++++++ .../peripherals/mimxrt10xx/MIMXRT1021/pins.h | 8 ++++++++ .../mimxrt10xx/MIMXRT1042/periph.c | 8 ++++++++ .../mimxrt10xx/MIMXRT1042/periph.h | 8 ++++++++ .../peripherals/mimxrt10xx/MIMXRT1042/pins.c | 8 ++++++++ .../peripherals/mimxrt10xx/MIMXRT1042/pins.h | 8 ++++++++ .../mimxrt10xx/MIMXRT1052/periph.c | 8 ++++++++ .../mimxrt10xx/MIMXRT1052/periph.h | 8 ++++++++ .../peripherals/mimxrt10xx/MIMXRT1052/pins.c | 8 ++++++++ .../peripherals/mimxrt10xx/MIMXRT1052/pins.h | 8 ++++++++ .../mimxrt10xx/MIMXRT1062/periph.c | 8 ++++++++ .../mimxrt10xx/MIMXRT1062/periph.h | 8 ++++++++ .../peripherals/mimxrt10xx/MIMXRT1062/pins.c | 8 ++++++++ .../peripherals/mimxrt10xx/MIMXRT1062/pins.h | 8 ++++++++ .../mimxrt10xx/MIMXRT1176/periph.c | 8 ++++++++ .../mimxrt10xx/MIMXRT1176/periph.h | 8 ++++++++ .../peripherals/mimxrt10xx/MIMXRT1176/pins.c | 8 ++++++++ .../peripherals/mimxrt10xx/MIMXRT1176/pins.h | 8 ++++++++ .../mimxrt10xx/tools/gen_peripherals_data.py | 20 +++++++++++++++++-- .../common-hal/microcontroller/Processor.c | 2 +- .../common-hal/microcontroller/Processor.c | 2 +- .../common-hal/microcontroller/Processor.c | 4 ++-- 35 files changed, 249 insertions(+), 9 deletions(-) diff --git a/ports/broadcom/common-hal/microcontroller/Processor.c b/ports/broadcom/common-hal/microcontroller/Processor.c index 70984dd0e4..d49baaee35 100644 --- a/ports/broadcom/common-hal/microcontroller/Processor.c +++ b/ports/broadcom/common-hal/microcontroller/Processor.c @@ -34,7 +34,7 @@ float common_hal_mcu_processor_get_temperature(void) { } float common_hal_mcu_processor_get_voltage(void) { - return 1.2f; + return NAN; } uint32_t common_hal_mcu_processor_get_frequency(void) { diff --git a/ports/espressif/common-hal/microcontroller/Processor.c b/ports/espressif/common-hal/microcontroller/Processor.c index c0e72c85b9..5b7463c9ff 100644 --- a/ports/espressif/common-hal/microcontroller/Processor.c +++ b/ports/espressif/common-hal/microcontroller/Processor.c @@ -47,7 +47,7 @@ float common_hal_mcu_processor_get_temperature(void) { float tsens_out; #if defined(CONFIG_IDF_TARGET_ESP32) - mp_raise_NotImplementedError(NULL); + return NAN; #else temp_sensor_config_t temp_sensor = TSENS_CONFIG_DEFAULT(); // DEFAULT: range:-10℃ ~ 80℃, error < 1℃. temp_sensor_set_config(temp_sensor); diff --git a/ports/mimxrt10xx/common-hal/microcontroller/Processor.c b/ports/mimxrt10xx/common-hal/microcontroller/Processor.c index bd7d77f4fa..8d20e10c48 100644 --- a/ports/mimxrt10xx/common-hal/microcontroller/Processor.c +++ b/ports/mimxrt10xx/common-hal/microcontroller/Processor.c @@ -54,7 +54,7 @@ float common_hal_mcu_processor_get_temperature(void) { return temp; #else - return 0; + return NAN; #endif } diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.c index fd8ef69f7e..a1468971dc 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.c @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1011` to update this file. + */ + #include "py/obj.h" #include "py/mphal.h" #include "mimxrt10xx/periph.h" diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.h index e03e2c7967..f3bee9e464 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/periph.h @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1011` to update this file. + */ + #pragma once extern LPI2C_Type *const mcu_i2c_banks[2]; extern const mcu_periph_obj_t mcu_i2c_sda_list[8]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pins.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pins.c index a2b38a8a67..ac45fbb833 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pins.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pins.c @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1011` to update this file. + */ + #include "py/obj.h" #include "py/mphal.h" #include "mimxrt10xx/pins.h" diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pins.h index 118eff9335..8e901f0980 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pins.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1011/pins.h @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1011` to update this file. + */ + #pragma once #define FORMAT_PIN(pin_name) extern const mcu_pin_obj_t pin_##pin_name; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.c index 9c56c47dc0..c6b2c6b872 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.c @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1015` to update this file. + */ + #include "py/obj.h" #include "py/mphal.h" #include "mimxrt10xx/periph.h" diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.h index af53706d6f..cef33f1ffa 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/periph.h @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1015` to update this file. + */ + #pragma once extern LPI2C_Type *const mcu_i2c_banks[2]; extern const mcu_periph_obj_t mcu_i2c_sda_list[2]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pins.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pins.c index efa7abcedf..ab9d9765b1 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pins.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pins.c @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1015` to update this file. + */ + #include "py/obj.h" #include "py/mphal.h" #include "mimxrt10xx/pins.h" diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pins.h index 118eff9335..8655bf872f 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pins.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1015/pins.h @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1015` to update this file. + */ + #pragma once #define FORMAT_PIN(pin_name) extern const mcu_pin_obj_t pin_##pin_name; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.c index 8615e6cfc5..9129c64272 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.c @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1021` to update this file. + */ + #include "py/obj.h" #include "py/mphal.h" #include "mimxrt10xx/periph.h" diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.h index 496e0ab153..3dea33fa00 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/periph.h @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1021` to update this file. + */ + #pragma once extern LPI2C_Type *const mcu_i2c_banks[4]; extern const mcu_periph_obj_t mcu_i2c_sda_list[8]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pins.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pins.c index e349f43542..f76da7a29e 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pins.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pins.c @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1021` to update this file. + */ + #include "py/obj.h" #include "py/mphal.h" #include "mimxrt10xx/pins.h" diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pins.h index 118eff9335..b4f991a879 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pins.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1021/pins.h @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1021` to update this file. + */ + #pragma once #define FORMAT_PIN(pin_name) extern const mcu_pin_obj_t pin_##pin_name; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.c index bbd41e7007..104960b417 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.c @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1042` to update this file. + */ + #include "py/obj.h" #include "py/mphal.h" #include "mimxrt10xx/periph.h" diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.h index 69a15dc50c..3df1a06d98 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/periph.h @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1042` to update this file. + */ + #pragma once extern LPI2C_Type *const mcu_i2c_banks[4]; extern const mcu_periph_obj_t mcu_i2c_sda_list[9]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pins.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pins.c index 64d35c2d67..6033d199e4 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pins.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pins.c @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1042` to update this file. + */ + #include "py/obj.h" #include "py/mphal.h" #include "mimxrt10xx/pins.h" diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pins.h index 118eff9335..f666962907 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pins.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1042/pins.h @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1042` to update this file. + */ + #pragma once #define FORMAT_PIN(pin_name) extern const mcu_pin_obj_t pin_##pin_name; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.c index 35b097f675..3ff474d7f4 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.c @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1052` to update this file. + */ + #include "py/obj.h" #include "py/mphal.h" #include "mimxrt10xx/periph.h" diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.h index ae6566f974..7d428eae1c 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/periph.h @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1052` to update this file. + */ + #pragma once extern LPI2C_Type *const mcu_i2c_banks[4]; extern const mcu_periph_obj_t mcu_i2c_sda_list[9]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pins.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pins.c index 83bbe18e42..48d8a2a3d6 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pins.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pins.c @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1052` to update this file. + */ + #include "py/obj.h" #include "py/mphal.h" #include "mimxrt10xx/pins.h" diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pins.h index 6e40d30c2b..4ee8d2ae28 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pins.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1052/pins.h @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1052` to update this file. + */ + #pragma once #define FORMAT_PIN(pin_name) extern const mcu_pin_obj_t pin_##pin_name; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.c index 12c9a09621..ab8fb2b4d8 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.c @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1062` to update this file. + */ + #include "py/obj.h" #include "py/mphal.h" #include "mimxrt10xx/periph.h" diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.h index 7917a2ebdb..36a42eba64 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/periph.h @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1062` to update this file. + */ + #pragma once extern LPI2C_Type *const mcu_i2c_banks[4]; extern const mcu_periph_obj_t mcu_i2c_sda_list[9]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pins.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pins.c index 472677ff24..7208ac418e 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pins.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pins.c @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1062` to update this file. + */ + #include "py/obj.h" #include "py/mphal.h" #include "mimxrt10xx/pins.h" diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pins.h index 6e40d30c2b..6f746f3b4c 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pins.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1062/pins.h @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1062` to update this file. + */ + #pragma once #define FORMAT_PIN(pin_name) extern const mcu_pin_obj_t pin_##pin_name; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.c index 3263bdea09..f53136c94f 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.c @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1176` to update this file. + */ + #include "py/obj.h" #include "py/mphal.h" #include "mimxrt10xx/periph.h" diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.h index 41695d655b..266300df18 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/periph.h @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1176` to update this file. + */ + #pragma once extern LPI2C_Type *const mcu_i2c_banks[6]; extern const mcu_periph_obj_t mcu_i2c_sda_list[8]; diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pins.c b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pins.c index 71562462e6..e9241c07c7 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pins.c +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pins.c @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1176` to update this file. + */ + #include "py/obj.h" #include "py/mphal.h" #include "mimxrt10xx/pins.h" diff --git a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pins.h b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pins.h index 0d99219c8a..35be6dd36e 100644 --- a/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pins.h +++ b/ports/mimxrt10xx/peripherals/mimxrt10xx/MIMXRT1176/pins.h @@ -26,6 +26,14 @@ * THE SOFTWARE. */ +/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py MIMXRT1176` to update this file. + */ + #pragma once #define FORMAT_PIN(pin_name) extern const mcu_pin_obj_t pin_##pin_name; diff --git a/ports/mimxrt10xx/tools/gen_peripherals_data.py b/ports/mimxrt10xx/tools/gen_peripherals_data.py index 0b4f215279..4193ae7228 100644 --- a/ports/mimxrt10xx/tools/gen_peripherals_data.py +++ b/ports/mimxrt10xx/tools/gen_peripherals_data.py @@ -60,8 +60,18 @@ copyright = """/* */ """ +autogen_warning_template = """/* + * This file is autogenerated! Do NOT hand edit it. Instead, edit tools/gen_peripherals_data.py and + * then rerun the script. You'll need to 1) clone https://github.com/nxp-mcuxpresso/mcux-soc-svd/ + * and 2) download and extract config tools data from https://mcuxpresso.nxp.com/en/select_config_tools_data. + * + * Run `python tools/gen_peripherals_data.py {}` to update this file. + */ +""" + for device in devices: print(device) + autogen_warning = autogen_warning_template.format(device) svd_fn = svd_folder / device / (device + ".xml") if not svd_fn.exists(): svd_fn = svd_folder / device / (device + "_cm7.xml") @@ -129,6 +139,7 @@ for device in devices: pins_h = [ copyright, + autogen_warning, "#pragma once", "", "#define FORMAT_PIN(pin_name) extern const mcu_pin_obj_t pin_##pin_name;", @@ -137,6 +148,7 @@ for device in devices: ] pins_c = [ copyright, + autogen_warning, '#include "py/obj.h"', '#include "py/mphal.h"', '#include "mimxrt10xx/pins.h"', @@ -255,7 +267,8 @@ for device in devices: f"const mcu_pin_obj_t pin_{pin_name} = PIN({gpio_instance}, {gpio_number}, {pin_name}, {adc_instance}, {adc_channel}, 0x{mux_reset:08X}, 0x{pad_reset:08X});" ) - pins_c.append("") + if usb_pins: + pins_c.append("") for pin_name in sorted(usb_pins): pin_names_h.append(f"FORMAT_PIN({pin_name})") @@ -275,9 +288,10 @@ for device in devices: (out_dir / "pins.h").write_text("\n".join(pins_h)) (out_dir / "pins.c").write_text("\n".join(pins_c)) - periph_h = [copyright, "#pragma once"] + periph_h = [copyright, autogen_warning, "#pragma once"] periph_c = [ copyright, + autogen_warning, '#include "py/obj.h"', '#include "py/mphal.h"', '#include "mimxrt10xx/periph.h"', @@ -352,5 +366,7 @@ for device in devices: periph_c.append(f"}};") periph_c.append("") + periph_h.append("") + (out_dir / "periph.h").write_text("\n".join(periph_h)) (out_dir / "periph.c").write_text("\n".join(periph_c)) diff --git a/ports/raspberrypi/common-hal/microcontroller/Processor.c b/ports/raspberrypi/common-hal/microcontroller/Processor.c index b22d385eec..ace9060c91 100644 --- a/ports/raspberrypi/common-hal/microcontroller/Processor.c +++ b/ports/raspberrypi/common-hal/microcontroller/Processor.c @@ -53,7 +53,7 @@ float common_hal_mcu_processor_get_temperature(void) { } float common_hal_mcu_processor_get_voltage(void) { - return 3.3f; + return NAN; } uint32_t common_hal_mcu_processor_get_frequency(void) { diff --git a/ports/silabs/common-hal/microcontroller/Processor.c b/ports/silabs/common-hal/microcontroller/Processor.c index 1414a28df6..841f3ba35f 100644 --- a/ports/silabs/common-hal/microcontroller/Processor.c +++ b/ports/silabs/common-hal/microcontroller/Processor.c @@ -46,7 +46,7 @@ float common_hal_mcu_processor_get_temperature(void) { float common_hal_mcu_processor_get_voltage(void) { // xG24 does not have built-in direct reading of processor voltage // Have Only 1 of IADC, already used for analogio module - return 3.3f; + return NAN; } uint32_t common_hal_mcu_processor_get_frequency(void) { diff --git a/ports/stm/common-hal/microcontroller/Processor.c b/ports/stm/common-hal/microcontroller/Processor.c index 67cf9a73e4..8e21ca8d82 100644 --- a/ports/stm/common-hal/microcontroller/Processor.c +++ b/ports/stm/common-hal/microcontroller/Processor.c @@ -96,7 +96,7 @@ float common_hal_mcu_processor_get_temperature(void) { float core_temp_avg_slope = (*ADC_CAL2 - *ADC_CAL1) / 80.0; return (((float)value * adc_refcor - *ADC_CAL1) / core_temp_avg_slope) + 30.0f; #else - return false; + return NAN; #endif } @@ -129,7 +129,7 @@ float common_hal_mcu_processor_get_voltage(void) { return adc_refcor * 3.3f; #else - return false; + return NAN; #endif } From b08714bb8fcca13b6765fd2a1c8beaa848b5d758 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Fri, 28 Apr 2023 17:13:17 -0700 Subject: [PATCH 101/117] Take in framebuffer resolution, not output res Fixes #7911 --- .../bindings/picodvi/Framebuffer.c | 16 ++++---- .../adafruit_feather_rp2040_dvi/board.c | 2 +- .../common-hal/picodvi/Framebuffer.c | 37 ++++++++++--------- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/ports/raspberrypi/bindings/picodvi/Framebuffer.c b/ports/raspberrypi/bindings/picodvi/Framebuffer.c index e4584370af..4e522d0f5f 100644 --- a/ports/raspberrypi/bindings/picodvi/Framebuffer.c +++ b/ports/raspberrypi/bindings/picodvi/Framebuffer.c @@ -53,7 +53,7 @@ //| blue_dn: microcontroller.Pin, //| color_depth: int = 8, //| ) -> None: -//| """Create a Framebuffer object with the given dimensions (640x480 or 800x480). Memory is +//| """Create a Framebuffer object with the given dimensions. Memory is //| allocated outside of onto the heap and then moved outside on VM //| end. //| @@ -67,22 +67,22 @@ //| less than dn for all pairs or dp must be greater than dn for all pairs. //| //| The framebuffer pixel format varies depending on color_depth: +//| //| * 1 - Each bit is a pixel. Either white (1) or black (0). //| * 2 - Each 2 bits is a pixels. Grayscale between white (0x3) and black (0x0). //| * 8 - Each byte is a pixels in RGB332 format. //| * 16 - Each two bytes are a pixel in RGB565 format. //| -//| Monochrome framebuffers (color_depth=1 or 2) will be full resolution. -//| Color framebuffers will be half resolution and pixels will be -//| duplicated to create a signal with the target dimensions. +//| Two output resolutions are currently supported, 640x480 and 800x480. +//| Monochrome framebuffers (color_depth=1 or 2) must be full resolution. +//| Color framebuffers must be half resolution (320x240 or 400x240) and +//| pixels will be duplicated to create the signal. //| //| A Framebuffer is often used in conjunction with a //| `framebufferio.FramebufferDisplay`. //| -//| :param int width: the width of the target display signal. It will be halved when -//| color_depth >= 8 when creating the framebuffer. Only 640 or 800 is currently supported. -//| :param int height: the height of the target display signal. It will be halved when -//| color_depth >= 8 when creating the framebuffer. Only 480 is currently supported. +//| :param int width: the width of the target display signal. Only 320, 400, 640 or 800 is currently supported depending on color_depth. +//| :param int height: the height of the target display signal. Only 240 or 480 is currently supported depenting on color_depth. //| :param ~microcontroller.Pin clk_dp: the positive clock signal pin //| :param ~microcontroller.Pin clk_dn: the negative clock signal pin //| :param ~microcontroller.Pin red_dp: the positive red signal pin diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/board.c b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/board.c index 140a15cc04..c6112a5555 100644 --- a/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/board.c +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_dvi/board.c @@ -33,7 +33,7 @@ void board_init(void) { picodvi_framebuffer_obj_t *fb = &allocate_display_bus()->picodvi; fb->base.type = &picodvi_framebuffer_type; - common_hal_picodvi_framebuffer_construct(fb, 640, 480, + common_hal_picodvi_framebuffer_construct(fb, 320, 240, &pin_GPIO17, &pin_GPIO16, &pin_GPIO19, &pin_GPIO18, &pin_GPIO21, &pin_GPIO20, diff --git a/ports/raspberrypi/common-hal/picodvi/Framebuffer.c b/ports/raspberrypi/common-hal/picodvi/Framebuffer.c index 20f447a824..5629d67d1c 100644 --- a/ports/raspberrypi/common-hal/picodvi/Framebuffer.c +++ b/ports/raspberrypi/common-hal/picodvi/Framebuffer.c @@ -138,23 +138,25 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self, const mcu_pin_obj_t *green_dp, const mcu_pin_obj_t *green_dn, const mcu_pin_obj_t *blue_dp, const mcu_pin_obj_t *blue_dn, mp_uint_t color_depth) { - - const struct dvi_timing *timing = NULL; - if (width == 640 && height == 480) { - timing = &dvi_timing_640x480p_60hz; - } else if (width == 800 && height == 480) { - timing = &dvi_timing_800x480p_60hz; - } else { - if (height == 480) { - mp_raise_ValueError_varg(translate("%q must be %d"), MP_QSTR_width, 480); - } - mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_height); - } - if (active_picodvi != NULL) { mp_raise_msg_varg(&mp_type_RuntimeError, translate("%q in use"), MP_QSTR_picodvi); } + bool color_framebuffer = color_depth >= 8; + const struct dvi_timing *timing = NULL; + if ((!color_framebuffer && width == 640 && height == 480) || + (color_framebuffer && width == 320 && height == 240)) { + timing = &dvi_timing_640x480p_60hz; + } else if ((!color_framebuffer && width == 800 && height == 480) || + (color_framebuffer && width == 400 && height == 240)) { + timing = &dvi_timing_800x480p_60hz; + } else { + if (height != 480 && height != 240) { + mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_height); + } + mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_width); + } + bool invert_diffpairs = clk_dn->number < clk_dp->number; int8_t other_pins[4]; int8_t *a; @@ -214,12 +216,12 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self, self->height = height; size_t tmds_bufs_per_scanline; - if (color_depth >= 8) { + size_t scanline_width = width; + if (color_framebuffer) { dvi_vertical_repeat = 2; dvi_monochrome_tmds = false; - self->width /= 2; - self->height /= 2; tmds_bufs_per_scanline = 3; + scanline_width *= 2; } else { dvi_vertical_repeat = 1; dvi_monochrome_tmds = true; @@ -233,8 +235,7 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self, } self->pitch /= sizeof(uint32_t); size_t framebuffer_size = self->pitch * self->height; - // use width here because it hasn't been downsized for the frame buffer - self->tmdsbuf_size = tmds_bufs_per_scanline * width / DVI_SYMBOLS_PER_WORD + 1; + self->tmdsbuf_size = tmds_bufs_per_scanline * scanline_width / DVI_SYMBOLS_PER_WORD + 1; size_t total_allocation_size = sizeof(uint32_t) * (framebuffer_size + DVI_N_TMDS_BUFFERS * self->tmdsbuf_size); self->allocation = allocate_memory(total_allocation_size, false, true); if (self->allocation == NULL) { From a7c3955c4163220925d3a28fc90987e6aaba6c40 Mon Sep 17 00:00:00 2001 From: Yutaro Urata Date: Fri, 28 Apr 2023 17:01:51 +0000 Subject: [PATCH 102/117] Translated using Weblate (Japanese) Currently translated at 40.8% (408 of 999 strings) Translation: CircuitPython/main Translate-URL: https://hosted.weblate.org/projects/circuitpython/main/ja/ --- locale/ja.po | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/locale/ja.po b/locale/ja.po index 805dc10e8e..effefafb1c 100644 --- a/locale/ja.po +++ b/locale/ja.po @@ -8,15 +8,15 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2023-01-05 02:52+0000\n" -"Last-Translator: Matt Watson \n" +"PO-Revision-Date: 2023-04-29 17:47+0000\n" +"Last-Translator: Yutaro Urata \n" "Language-Team: none\n" "Language: ja\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=1; plural=0;\n" -"X-Generator: Weblate 4.15.1-dev\n" +"X-Generator: Weblate 4.18-dev\n" #: main.c msgid "" @@ -350,11 +350,11 @@ msgstr "" #: shared-module/struct/__init__.c msgid "'S' and 'O' are not supported format types" -msgstr "" +msgstr "'S'と'O'はフォーマットタイプではありません" #: py/compile.c msgid "'align' requires 1 argument" -msgstr "" +msgstr "'align'は引数が一つ必要です" #: py/compile.c msgid "'await' outside function" From 0aa71ed6e657c0ba4c118bce1b564688f68b9d91 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 1 May 2023 11:30:04 -0700 Subject: [PATCH 103/117] Tweak the picodvi docs and arg checking --- .../bindings/picodvi/Framebuffer.c | 23 ++++++++----------- .../common-hal/picodvi/Framebuffer.c | 14 +++++++---- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/ports/raspberrypi/bindings/picodvi/Framebuffer.c b/ports/raspberrypi/bindings/picodvi/Framebuffer.c index 4e522d0f5f..f6fa7f986a 100644 --- a/ports/raspberrypi/bindings/picodvi/Framebuffer.c +++ b/ports/raspberrypi/bindings/picodvi/Framebuffer.c @@ -36,8 +36,6 @@ #include "shared-module/framebufferio/FramebufferDisplay.h" //| class Framebuffer: -//| """A PicoDVI managed frame buffer.""" -//| //| def __init__( //| self, //| width: int, @@ -54,13 +52,14 @@ //| color_depth: int = 8, //| ) -> None: //| """Create a Framebuffer object with the given dimensions. Memory is -//| allocated outside of onto the heap and then moved outside on VM -//| end. +//| allocated outside of onto the heap and then moved outside on VM end. //| -//| This will change the system clock speed to match the DVI signal. -//| Make sure to initialize other objects after this one so they account -//| for the changed clock. This also allocates a very large framebuffer -//| and is most likely to succeed the earlier it is attempted. +//| .. warning:: This will change the system clock speed to match the DVI signal. +//| Make sure to initialize other objects after this one so they account +//| for the changed clock. +//| +//| This allocates a very large framebuffer and is most likely to succeed +//| the earlier it is attempted. //| //| Each dp and dn pair of pins must be neighboring, such as 19 and 20. //| They must also be ordered the same way. In other words, dp must be @@ -82,7 +81,7 @@ //| `framebufferio.FramebufferDisplay`. //| //| :param int width: the width of the target display signal. Only 320, 400, 640 or 800 is currently supported depending on color_depth. -//| :param int height: the height of the target display signal. Only 240 or 480 is currently supported depenting on color_depth. +//| :param int height: the height of the target display signal. Only 240 or 480 is currently supported depending on color_depth. //| :param ~microcontroller.Pin clk_dp: the positive clock signal pin //| :param ~microcontroller.Pin clk_dn: the negative clock signal pin //| :param ~microcontroller.Pin red_dp: the positive red signal pin @@ -160,8 +159,7 @@ static void check_for_deinit(picodvi_framebuffer_obj_t *self) { } //| width: int -//| """The width of the framebuffer, in pixels. It may be doubled for output (and half of what -//| width was given to __init__.)""" +//| """The width of the framebuffer, in pixels. It may be doubled for output.""" STATIC mp_obj_t picodvi_framebuffer_get_width(mp_obj_t self_in) { picodvi_framebuffer_obj_t *self = (picodvi_framebuffer_obj_t *)self_in; check_for_deinit(self); @@ -172,8 +170,7 @@ MP_PROPERTY_GETTER(picodvi_framebuffer_width_obj, (mp_obj_t)&picodvi_framebuffer_get_width_obj); //| height: int -//| """The width of the framebuffer, in pixels. It may be doubled for output (and half of what -//| width was given to __init__.)""" +//| """The width of the framebuffer, in pixels. It may be doubled for output.""" //| STATIC mp_obj_t picodvi_framebuffer_get_height(mp_obj_t self_in) { picodvi_framebuffer_obj_t *self = (picodvi_framebuffer_obj_t *)self_in; diff --git a/ports/raspberrypi/common-hal/picodvi/Framebuffer.c b/ports/raspberrypi/common-hal/picodvi/Framebuffer.c index 5629d67d1c..6ad824d080 100644 --- a/ports/raspberrypi/common-hal/picodvi/Framebuffer.c +++ b/ports/raspberrypi/common-hal/picodvi/Framebuffer.c @@ -144,11 +144,11 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self, bool color_framebuffer = color_depth >= 8; const struct dvi_timing *timing = NULL; - if ((!color_framebuffer && width == 640 && height == 480) || - (color_framebuffer && width == 320 && height == 240)) { + if ((width == 640 && height == 480) || + (width == 320 && height == 240)) { timing = &dvi_timing_640x480p_60hz; - } else if ((!color_framebuffer && width == 800 && height == 480) || - (color_framebuffer && width == 400 && height == 240)) { + } else if ((width == 800 && height == 480) || + (width == 400 && height == 240)) { timing = &dvi_timing_800x480p_60hz; } else { if (height != 480 && height != 240) { @@ -157,6 +157,12 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self, mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_width); } + // If the width is > 400, then it must not be color frame buffer and vice + // versa. + if ((width > 400) == color_framebuffer) { + mp_raise_ValueError_varg(translate("Invalid %q"), MP_QSTR_color_depth); + } + bool invert_diffpairs = clk_dn->number < clk_dp->number; int8_t other_pins[4]; int8_t *a; From 051540f8da54d1dd5ca2344afac93dd296700662 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Mon, 1 May 2023 11:38:13 -0700 Subject: [PATCH 104/117] Fix broadcom NAN --- ports/broadcom/common-hal/microcontroller/Processor.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ports/broadcom/common-hal/microcontroller/Processor.c b/ports/broadcom/common-hal/microcontroller/Processor.c index d49baaee35..259ecb6c5f 100644 --- a/ports/broadcom/common-hal/microcontroller/Processor.c +++ b/ports/broadcom/common-hal/microcontroller/Processor.c @@ -26,6 +26,8 @@ #include "shared-bindings/microcontroller/Processor.h" +#include + #include "peripherals/broadcom/vcmailbox.h" float common_hal_mcu_processor_get_temperature(void) { From cba7a812fc8cd5ec9adf2673e834427c84d0011c Mon Sep 17 00:00:00 2001 From: Liz Date: Tue, 2 May 2023 17:02:59 -0400 Subject: [PATCH 105/117] Minor update for Feather RP2040 ThinkInk hihi - updating board name from EPD to ThinkInk and adding pin def for board.BUTTON --- .../boards/adafruit_feather_rp2040_epd/mpconfigboard.h | 2 +- .../boards/adafruit_feather_rp2040_epd/mpconfigboard.mk | 2 +- ports/raspberrypi/boards/adafruit_feather_rp2040_epd/pins.c | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_epd/mpconfigboard.h b/ports/raspberrypi/boards/adafruit_feather_rp2040_epd/mpconfigboard.h index 356f0f5b54..e76281e893 100644 --- a/ports/raspberrypi/boards/adafruit_feather_rp2040_epd/mpconfigboard.h +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_epd/mpconfigboard.h @@ -1,4 +1,4 @@ -#define MICROPY_HW_BOARD_NAME "Adafruit Feather RP2040 EPD" +#define MICROPY_HW_BOARD_NAME "Adafruit Feather RP2040 ThinkInk" #define MICROPY_HW_MCU_NAME "rp2040" #define CIRCUITPY_STATUS_LED_POWER (&pin_GPIO20) diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_epd/mpconfigboard.mk b/ports/raspberrypi/boards/adafruit_feather_rp2040_epd/mpconfigboard.mk index 3b457b93cb..1f71dcb76b 100644 --- a/ports/raspberrypi/boards/adafruit_feather_rp2040_epd/mpconfigboard.mk +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_epd/mpconfigboard.mk @@ -1,6 +1,6 @@ USB_VID = 0x239A USB_PID = 0x812C -USB_PRODUCT = "Feather RP2040 EPD" +USB_PRODUCT = "Feather RP2040 ThinkInk" USB_MANUFACTURER = "Adafruit" CHIP_VARIANT = RP2040 diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_epd/pins.c b/ports/raspberrypi/boards/adafruit_feather_rp2040_epd/pins.c index 22ae43adad..72793fbd56 100644 --- a/ports/raspberrypi/boards/adafruit_feather_rp2040_epd/pins.c +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_epd/pins.c @@ -21,6 +21,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO4) }, { MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO7) }, { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO2) }, { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO3) }, From facd3a4e784a8decd5b9eeed16824963c105d1d5 Mon Sep 17 00:00:00 2001 From: Liz Date: Tue, 2 May 2023 17:07:49 -0400 Subject: [PATCH 106/117] Updating directory name --- .../board.c | 0 .../mpconfigboard.h | 0 .../mpconfigboard.mk | 0 .../pico-sdk-configboard.h | 0 .../pins.c | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename ports/raspberrypi/boards/{adafruit_feather_rp2040_epd => adafruit_feather_rp2040_thinkink}/board.c (100%) rename ports/raspberrypi/boards/{adafruit_feather_rp2040_epd => adafruit_feather_rp2040_thinkink}/mpconfigboard.h (100%) rename ports/raspberrypi/boards/{adafruit_feather_rp2040_epd => adafruit_feather_rp2040_thinkink}/mpconfigboard.mk (100%) rename ports/raspberrypi/boards/{adafruit_feather_rp2040_epd => adafruit_feather_rp2040_thinkink}/pico-sdk-configboard.h (100%) rename ports/raspberrypi/boards/{adafruit_feather_rp2040_epd => adafruit_feather_rp2040_thinkink}/pins.c (100%) diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_epd/board.c b/ports/raspberrypi/boards/adafruit_feather_rp2040_thinkink/board.c similarity index 100% rename from ports/raspberrypi/boards/adafruit_feather_rp2040_epd/board.c rename to ports/raspberrypi/boards/adafruit_feather_rp2040_thinkink/board.c diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_epd/mpconfigboard.h b/ports/raspberrypi/boards/adafruit_feather_rp2040_thinkink/mpconfigboard.h similarity index 100% rename from ports/raspberrypi/boards/adafruit_feather_rp2040_epd/mpconfigboard.h rename to ports/raspberrypi/boards/adafruit_feather_rp2040_thinkink/mpconfigboard.h diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_epd/mpconfigboard.mk b/ports/raspberrypi/boards/adafruit_feather_rp2040_thinkink/mpconfigboard.mk similarity index 100% rename from ports/raspberrypi/boards/adafruit_feather_rp2040_epd/mpconfigboard.mk rename to ports/raspberrypi/boards/adafruit_feather_rp2040_thinkink/mpconfigboard.mk diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_epd/pico-sdk-configboard.h b/ports/raspberrypi/boards/adafruit_feather_rp2040_thinkink/pico-sdk-configboard.h similarity index 100% rename from ports/raspberrypi/boards/adafruit_feather_rp2040_epd/pico-sdk-configboard.h rename to ports/raspberrypi/boards/adafruit_feather_rp2040_thinkink/pico-sdk-configboard.h diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_epd/pins.c b/ports/raspberrypi/boards/adafruit_feather_rp2040_thinkink/pins.c similarity index 100% rename from ports/raspberrypi/boards/adafruit_feather_rp2040_epd/pins.c rename to ports/raspberrypi/boards/adafruit_feather_rp2040_thinkink/pins.c From 480c4f10816325ac685150c2f3a261a99113fa14 Mon Sep 17 00:00:00 2001 From: Liz Date: Tue, 2 May 2023 17:27:53 -0400 Subject: [PATCH 107/117] Update pins.c --- .../raspberrypi/boards/adafruit_feather_rp2040_thinkink/pins.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2040_thinkink/pins.c b/ports/raspberrypi/boards/adafruit_feather_rp2040_thinkink/pins.c index 72793fbd56..919b495abc 100644 --- a/ports/raspberrypi/boards/adafruit_feather_rp2040_thinkink/pins.c +++ b/ports/raspberrypi/boards/adafruit_feather_rp2040_thinkink/pins.c @@ -21,7 +21,7 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO4) }, { MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_GPIO7) }, - { MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO7) }, { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO2) }, { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO3) }, From c369527ace24363bc2739c473a8a8d6275b38e46 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 2 May 2023 19:17:51 -0500 Subject: [PATCH 108/117] remove line added while debugging failed doc builds Co-authored-by: Scott Shawcroft --- shared-bindings/synthio/__init__.c | 1 - 1 file changed, 1 deletion(-) diff --git a/shared-bindings/synthio/__init__.c b/shared-bindings/synthio/__init__.c index 703966defc..15d4e3f3c7 100644 --- a/shared-bindings/synthio/__init__.c +++ b/shared-bindings/synthio/__init__.c @@ -41,7 +41,6 @@ //| //| At least 2 simultaneous notes are supported. samd5x, mimxrt10xx and rp2040 platforms support up to 12 notes. //| -//| I'm a little teapot. I'm not on line 11, but I don't know what is. //| """ //| //| class Envelope: From b2f32a5397c14576fe1107ef852e22b2b36cf96b Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 2 May 2023 19:22:10 -0500 Subject: [PATCH 109/117] Apply suggestions from code review Co-authored-by: Scott Shawcroft --- shared-bindings/synthio/__init__.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/synthio/__init__.c b/shared-bindings/synthio/__init__.c index 15d4e3f3c7..95dc097313 100644 --- a/shared-bindings/synthio/__init__.c +++ b/shared-bindings/synthio/__init__.c @@ -132,7 +132,7 @@ const mp_obj_namedtuple_type_t synthio_envelope_type_obj = { //| *, //| sample_rate: int = 11025, //| waveform: Optional[ReadableBuffer] = None, -//| envelope: Optional[ReadableBuffer] = None, +//| envelope: Optional[Envelope] = None, //| ) -> MidiTrack: //| """Create an AudioSample from an already opened MIDI file. //| Currently, only single-track MIDI (type 0) is supported. From d8550f4e7c08509be184bda7f9e0b2aafac5aaf5 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Tue, 2 May 2023 15:59:34 -0500 Subject: [PATCH 110/117] synthio: fix offset in default square waveform --- shared-module/synthio/__init__.c | 2 +- tests/circuitpython-manual/synthio/.gitignore | 1 + .../synthio/wave/.gitignore | 1 - tests/circuitpython/miditrack.py.exp | 2 +- tests/circuitpython/synthesizer.py.exp | 44 +++++++++---------- 5 files changed, 25 insertions(+), 25 deletions(-) create mode 100644 tests/circuitpython-manual/synthio/.gitignore delete mode 100644 tests/circuitpython-manual/synthio/wave/.gitignore diff --git a/shared-module/synthio/__init__.c b/shared-module/synthio/__init__.c index 1385059b99..c7e1096632 100644 --- a/shared-module/synthio/__init__.c +++ b/shared-module/synthio/__init__.c @@ -31,7 +31,7 @@ #include #include -STATIC const int16_t square_wave[] = {-32768, 0}; +STATIC const int16_t square_wave[] = {-32768, 32767}; STATIC const uint16_t notes[] = {8372, 8870, 9397, 9956, 10548, 11175, 11840, 12544, 13290, 14080, 14917, 15804}; // 9th octave diff --git a/tests/circuitpython-manual/synthio/.gitignore b/tests/circuitpython-manual/synthio/.gitignore new file mode 100644 index 0000000000..d8dd7532ab --- /dev/null +++ b/tests/circuitpython-manual/synthio/.gitignore @@ -0,0 +1 @@ +*.wav diff --git a/tests/circuitpython-manual/synthio/wave/.gitignore b/tests/circuitpython-manual/synthio/wave/.gitignore deleted file mode 100644 index c212df9c3d..0000000000 --- a/tests/circuitpython-manual/synthio/wave/.gitignore +++ /dev/null @@ -1 +0,0 @@ -tune.wav diff --git a/tests/circuitpython/miditrack.py.exp b/tests/circuitpython/miditrack.py.exp index 2d9e2548a0..6de9f947c6 100644 --- a/tests/circuitpython/miditrack.py.exp +++ b/tests/circuitpython/miditrack.py.exp @@ -1,4 +1,4 @@ (0, 1, 512, 1) -1 [-16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0] +1 [-16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 16382, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, -16383, 16382, 16382] (0, 1, 512, 1) 1 [0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, 0, 16382, 16382, 16382, 16382, 16382, 16382, 0, 0] diff --git a/tests/circuitpython/synthesizer.py.exp b/tests/circuitpython/synthesizer.py.exp index 70eb647bab..826290fe27 100644 --- a/tests/circuitpython/synthesizer.py.exp +++ b/tests/circuitpython/synthesizer.py.exp @@ -1,30 +1,30 @@ () [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] (80,) -[-16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383, 0, 0, 0, 0, 0, -16383, -16383, -16383, -16383, -16383] +[-16383, -16383, -16383, -16383, 16382, 16382, 16382, 16382, 16382, -16383, -16383, -16383, -16383, -16383, 16382, 16382, 16382, 16382, 16382, -16383, -16383, -16383, -16383, -16383] (80, 91) -[-8191, -8191, 0, 0, -8191, -16382, -16382, -8191, 0, 0, -8191, -8191, 0, -8191, -8191, -16382, -16382, -8191, 0, 0, -8191, -8191, 0, -8191] +[0, 0, 16382, 16382, 0, -16382, -16382, 0, 16382, 16382, 0, 0, 16382, 0, 0, -16382, -16382, 0, 16382, 16382, 0, 0, 16382, 0] (91,) -[-16382, -8191, -8191, 0, -8191, -8191, 0, 0, -8191, -16382, -16382, -8191, 0, 0, -8191, -8191, 0, -8191, -8191, -16382, -16382, -16382, 0, 0] -(-5242, 0) -(-10484, 0) -(-15727, 0) -(-16383, 0) -(-14286, 0) -(-13106, 0) -(-13106, 0) -(-13106, 0) -(-13106, 0) -(-13106, 0) -(-13106, 0) -(-13106, 0) -(-13106, 0) -(-11009, 0) -(-8912, 0) -(-6815, 0) -(-4718, 0) -(-2621, 0) -(-524, 0) +[-16382, 0, 0, 16382, 0, 0, 16382, 16382, 0, -16382, -16382, 0, 16382, 16382, 0, 0, 16382, 0, 0, -16382, -16382, -16382, 16382, 16382] +(-5242, 5241) +(-10484, 10484) +(-15727, 15726) +(-16383, 16382) +(-14286, 14285) +(-13106, 13105) +(-13106, 13105) +(-13106, 13105) +(-13106, 13105) +(-13106, 13105) +(-13106, 13105) +(-13106, 13105) +(-13106, 13105) +(-11009, 11008) +(-8912, 8911) +(-6815, 6814) +(-4718, 4717) +(-2621, 2620) +(-524, 523) (0, 0) (0, 0) (0, 0) From dd262258e0889cb1e18de0fa4ef4e631feb53b9e Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 3 May 2023 08:45:37 -0500 Subject: [PATCH 111/117] synthio: Add `MidiTrack.error_location` to record errors .. instead of just printing the unraiseable error on the repl --- shared-bindings/synthio/MidiTrack.c | 18 ++++++++++++++++++ shared-bindings/synthio/MidiTrack.h | 1 + shared-module/synthio/MidiTrack.c | 7 ++++++- shared-module/synthio/MidiTrack.h | 1 + 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/shared-bindings/synthio/MidiTrack.c b/shared-bindings/synthio/MidiTrack.c index 6916a21689..084bad204c 100644 --- a/shared-bindings/synthio/MidiTrack.c +++ b/shared-bindings/synthio/MidiTrack.c @@ -151,6 +151,23 @@ MP_DEFINE_CONST_FUN_OBJ_1(synthio_miditrack_get_sample_rate_obj, synthio_miditra MP_PROPERTY_GETTER(synthio_miditrack_sample_rate_obj, (mp_obj_t)&synthio_miditrack_get_sample_rate_obj); +//| error_location: Optional[int] +//| """Offset, in bytes within the midi data, of a decoding error""" +//| +STATIC mp_obj_t synthio_miditrack_obj_get_error_location(mp_obj_t self_in) { + synthio_miditrack_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + mp_int_t location = common_hal_synthio_miditrack_get_error_location(self); + if (location >= 0) { + return MP_OBJ_NEW_SMALL_INT(location); + } + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(synthio_miditrack_get_error_location_obj, synthio_miditrack_obj_get_error_location); + +MP_PROPERTY_GETTER(synthio_miditrack_error_location_obj, + (mp_obj_t)&synthio_miditrack_get_error_location_obj); + STATIC const mp_rom_map_elem_t synthio_miditrack_locals_dict_table[] = { // Methods { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&synthio_miditrack_deinit_obj) }, @@ -159,6 +176,7 @@ STATIC const mp_rom_map_elem_t synthio_miditrack_locals_dict_table[] = { // Properties { MP_ROM_QSTR(MP_QSTR_sample_rate), MP_ROM_PTR(&synthio_miditrack_sample_rate_obj) }, + { MP_ROM_QSTR(MP_QSTR_error_location), MP_ROM_PTR(&synthio_miditrack_error_location_obj) }, }; STATIC MP_DEFINE_CONST_DICT(synthio_miditrack_locals_dict, synthio_miditrack_locals_dict_table); diff --git a/shared-bindings/synthio/MidiTrack.h b/shared-bindings/synthio/MidiTrack.h index 046163c2de..1a76ed36f4 100644 --- a/shared-bindings/synthio/MidiTrack.h +++ b/shared-bindings/synthio/MidiTrack.h @@ -39,3 +39,4 @@ bool common_hal_synthio_miditrack_deinited(synthio_miditrack_obj_t *self); uint32_t common_hal_synthio_miditrack_get_sample_rate(synthio_miditrack_obj_t *self); uint8_t common_hal_synthio_miditrack_get_bits_per_sample(synthio_miditrack_obj_t *self); uint8_t common_hal_synthio_miditrack_get_channel_count(synthio_miditrack_obj_t *self); +mp_int_t common_hal_synthio_miditrack_get_error_location(synthio_miditrack_obj_t *self); diff --git a/shared-module/synthio/MidiTrack.c b/shared-module/synthio/MidiTrack.c index 6a021af85c..c59fa23bef 100644 --- a/shared-module/synthio/MidiTrack.c +++ b/shared-module/synthio/MidiTrack.c @@ -29,7 +29,7 @@ STATIC void print_midi_stream_error(synthio_miditrack_obj_t *self) { - mp_cprintf(&mp_plat_print, translate("Error in MIDI stream at position %d"), self->pos); + self->error_location = self->pos; self->pos = self->track.len; } @@ -106,6 +106,7 @@ static void decode_until_pause(synthio_miditrack_obj_t *self) { STATIC void start_parse(synthio_miditrack_obj_t *self) { self->pos = 0; + self->error_location = -1; self->synth.span.dur = decode_duration(self); if (self->synth.span.dur == 0) { // the usual case: the file starts with some MIDI event, not a delay @@ -135,6 +136,10 @@ bool common_hal_synthio_miditrack_deinited(synthio_miditrack_obj_t *self) { return synthio_synth_deinited(&self->synth); } +mp_int_t common_hal_synthio_miditrack_get_error_location(synthio_miditrack_obj_t *self) { + return self->error_location; +} + uint32_t common_hal_synthio_miditrack_get_sample_rate(synthio_miditrack_obj_t *self) { return self->synth.sample_rate; } diff --git a/shared-module/synthio/MidiTrack.h b/shared-module/synthio/MidiTrack.h index 549e72fb25..2f843dcc3d 100644 --- a/shared-module/synthio/MidiTrack.h +++ b/shared-module/synthio/MidiTrack.h @@ -37,6 +37,7 @@ typedef struct { mp_buffer_info_t track; // invariant: after initial startup, pos always points just after an encoded duration, i.e., at a midi message (or at EOF) size_t pos; + mp_int_t error_location; uint32_t tempo; } synthio_miditrack_obj_t; From eea9b629784f2ac3a31162b30a41d287d90cce8f Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 3 May 2023 08:45:57 -0500 Subject: [PATCH 112/117] synthio: MidiTrack: sample_rate is always available --- shared-bindings/synthio/MidiTrack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-bindings/synthio/MidiTrack.c b/shared-bindings/synthio/MidiTrack.c index 084bad204c..31d8cbc7f0 100644 --- a/shared-bindings/synthio/MidiTrack.c +++ b/shared-bindings/synthio/MidiTrack.c @@ -138,7 +138,7 @@ STATIC mp_obj_t synthio_miditrack_obj___exit__(size_t n_args, const mp_obj_t *ar } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(synthio_miditrack___exit___obj, 4, 4, synthio_miditrack_obj___exit__); -//| sample_rate: Optional[int] +//| sample_rate: int //| """32 bit value that tells how quickly samples are played in Hertz (cycles per second).""" //| STATIC mp_obj_t synthio_miditrack_obj_get_sample_rate(mp_obj_t self_in) { From 1fafa4dc2496671a4aedbd393d76a0b19cb45d8d Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 3 May 2023 09:06:41 -0500 Subject: [PATCH 113/117] synthio: improve Envelope constructor --- shared-bindings/synthio/__init__.c | 63 ++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/shared-bindings/synthio/__init__.c b/shared-bindings/synthio/__init__.c index 95dc097313..eaf67cc0e7 100644 --- a/shared-bindings/synthio/__init__.c +++ b/shared-bindings/synthio/__init__.c @@ -37,6 +37,20 @@ #include "shared-bindings/synthio/MidiTrack.h" #include "shared-bindings/synthio/Synthesizer.h" +#define default_attack_time (MICROPY_FLOAT_CONST(0.1)) +#define default_decay_time (MICROPY_FLOAT_CONST(0.05)) +#define default_release_time (MICROPY_FLOAT_CONST(0.2)) +#define default_attack_level (MICROPY_FLOAT_CONST(1.)) +#define default_sustain_level (MICROPY_FLOAT_CONST(0.8)) + +static const mp_arg_t envelope_properties[] = { + { MP_QSTR_attack_time, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL } }, + { MP_QSTR_decay_time, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL } }, + { MP_QSTR_release_time, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL } }, + { MP_QSTR_attack_level, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL } }, + { MP_QSTR_sustain_level, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = MP_OBJ_NULL } }, +}; + //| """Support for multi-channel audio synthesis //| //| At least 2 simultaneous notes are supported. samd5x, mimxrt10xx and rp2040 platforms support up to 12 notes. @@ -46,11 +60,12 @@ //| class Envelope: //| def __init__( //| self, -//| attack_time: float, -//| decay_time: float, -//| release_time: float, -//| attack_level: float, -//| sustain_level: float, +//| *, +//| attack_time: Optional[float] = 0.1, +//| decay_time: Optional[float] = 0.05, +//| release_time: Optional[float] = 0.2, +//| attack_level: Optional[float] = 1.0, +//| sustain_level: Optional[float] = 0.8, //| ) -> None: //| """Construct an Envelope object //| @@ -82,20 +97,36 @@ //| """The relative level, in the range ``0.0`` to ``1.0`` of the volume of the sustain phase""" //| -STATIC mp_obj_t synthio_envelope_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { - mp_obj_t new_obj = namedtuple_make_new(type_in, n_args, n_kw, args); - mp_obj_t *fields; - size_t len; - mp_obj_tuple_get(new_obj, &len, &fields); +STATIC mp_obj_t synthio_envelope_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + mp_arg_val_t args[MP_ARRAY_SIZE(envelope_properties)]; + enum { ARG_attack_time, ARG_decay_time, ARG_release_time, ARG_attack_level, ARG_sustain_level }; + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(envelope_properties), envelope_properties, args); - mp_arg_validate_obj_float_non_negative(fields[0], 0., MP_QSTR_attack_time); - mp_arg_validate_obj_float_non_negative(fields[1], 0., MP_QSTR_decay_time); - mp_arg_validate_obj_float_non_negative(fields[2], 0., MP_QSTR_release_time); + if (args[ARG_attack_time].u_obj == MP_OBJ_NULL) { + args[ARG_attack_time].u_obj = mp_obj_new_float(default_attack_time); + } + if (args[ARG_decay_time].u_obj == MP_OBJ_NULL) { + args[ARG_decay_time].u_obj = mp_obj_new_float(default_decay_time); + } + if (args[ARG_release_time].u_obj == MP_OBJ_NULL) { + args[ARG_release_time].u_obj = mp_obj_new_float(default_release_time); + } + if (args[ARG_attack_level].u_obj == MP_OBJ_NULL) { + args[ARG_attack_level].u_obj = mp_obj_new_float(default_attack_level); + } + if (args[ARG_sustain_level].u_obj == MP_OBJ_NULL) { + args[ARG_sustain_level].u_obj = mp_obj_new_float(default_sustain_level); + } - mp_arg_validate_obj_float_range(fields[3], 0, 1, MP_QSTR_attack_level); - mp_arg_validate_obj_float_range(fields[4], 0, 1, MP_QSTR_sustain_level); + mp_arg_validate_obj_float_non_negative(args[ARG_attack_time].u_obj, 0., MP_QSTR_attack_time); + mp_arg_validate_obj_float_non_negative(args[ARG_decay_time].u_obj, 0., MP_QSTR_decay_time); + mp_arg_validate_obj_float_non_negative(args[ARG_release_time].u_obj, 0., MP_QSTR_release_time); - return new_obj; + mp_arg_validate_obj_float_range(args[ARG_attack_level].u_obj, 0, 1, MP_QSTR_attack_level); + mp_arg_validate_obj_float_range(args[ARG_sustain_level].u_obj, 0, 1, MP_QSTR_sustain_level); + + MP_STATIC_ASSERT(sizeof(mp_arg_val_t) == sizeof(mp_obj_t)); + return namedtuple_make_new(type_in, MP_ARRAY_SIZE(args), 0, &args[0].u_obj); }; const mp_obj_namedtuple_type_t synthio_envelope_type_obj = { From b33c9f6b4b0ae428682560496c8c89015542496e Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 3 May 2023 09:32:51 -0500 Subject: [PATCH 114/117] synthio: put license notice on copied files --- tests/circuitpython-manual/synthio/wave/audioop.py | 4 ++++ tests/circuitpython-manual/synthio/wave/chunk.py | 4 ++++ tests/circuitpython-manual/synthio/wave/wave.py | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/tests/circuitpython-manual/synthio/wave/audioop.py b/tests/circuitpython-manual/synthio/wave/audioop.py index 6ec637a3a1..cab2fb4a7a 100644 --- a/tests/circuitpython-manual/synthio/wave/audioop.py +++ b/tests/circuitpython-manual/synthio/wave/audioop.py @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2023 Guido van Rossum and others. +# +# SPDX-License-Identifier: PSF-2.0 + import struct diff --git a/tests/circuitpython-manual/synthio/wave/chunk.py b/tests/circuitpython-manual/synthio/wave/chunk.py index eea83c42d6..c1e6364b0f 100644 --- a/tests/circuitpython-manual/synthio/wave/chunk.py +++ b/tests/circuitpython-manual/synthio/wave/chunk.py @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2023 Guido van Rossum and others. +# +# SPDX-License-Identifier: PSF-2.0 + """Simple class to read IFF chunks. An IFF chunk (used in formats such as AIFF, TIFF, RMFF (RealMedia File diff --git a/tests/circuitpython-manual/synthio/wave/wave.py b/tests/circuitpython-manual/synthio/wave/wave.py index 903295a4ba..dc6d5407a7 100644 --- a/tests/circuitpython-manual/synthio/wave/wave.py +++ b/tests/circuitpython-manual/synthio/wave/wave.py @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2023 Guido van Rossum and others. +# +# SPDX-License-Identifier: PSF-2.0 + """Stuff to parse WAVE files. Usage. From 4f7d88676b49f22e7656ec0a4fac89a5c3c9fd4d Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Wed, 3 May 2023 17:30:01 -0400 Subject: [PATCH 115/117] Remove pico-w version --- .../boards/pimoroni_pico_dv_base_w/board.c | 52 ----------- .../boards/pimoroni_pico_dv_base_w/link.ld | 1 - .../pimoroni_pico_dv_base_w/mpconfigboard.h | 10 --- .../pimoroni_pico_dv_base_w/mpconfigboard.mk | 29 ------ .../pico-sdk-configboard.h | 4 - .../boards/pimoroni_pico_dv_base_w/pins.c | 89 ------------------- 6 files changed, 185 deletions(-) delete mode 100644 ports/raspberrypi/boards/pimoroni_pico_dv_base_w/board.c delete mode 100644 ports/raspberrypi/boards/pimoroni_pico_dv_base_w/link.ld delete mode 100644 ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.h delete mode 100644 ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.mk delete mode 100644 ports/raspberrypi/boards/pimoroni_pico_dv_base_w/pico-sdk-configboard.h delete mode 100644 ports/raspberrypi/boards/pimoroni_pico_dv_base_w/pins.c diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/board.c b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/board.c deleted file mode 100644 index bc5878bf24..0000000000 --- a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/board.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2021 Scott Shawcroft for Adafruit Industries - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "supervisor/board.h" - -#include "bindings/picodvi/Framebuffer.h" -#include "shared-module/displayio/__init__.h" -#include "shared-bindings/framebufferio/FramebufferDisplay.h" - -void board_init(void) { - picodvi_framebuffer_obj_t *fb = &allocate_display_bus()->picodvi; - fb->base.type = &picodvi_framebuffer_type; - common_hal_picodvi_framebuffer_construct(fb, 640, 480, - &pin_GPIO7, &pin_GPIO6, - &pin_GPIO9, &pin_GPIO8, - &pin_GPIO11, &pin_GPIO10, - &pin_GPIO13, &pin_GPIO12, - 8); - - framebufferio_framebufferdisplay_obj_t *display = &displays[0].framebuffer_display; - display->base.type = &framebufferio_framebufferdisplay_type; - common_hal_framebufferio_framebufferdisplay_construct( - display, - MP_OBJ_FROM_PTR(fb), - 0, - true); -} - -// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/link.ld b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/link.ld deleted file mode 100644 index e814bead4c..0000000000 --- a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/link.ld +++ /dev/null @@ -1 +0,0 @@ -firmware_size = 1532k; diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.h b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.h deleted file mode 100644 index df6539734e..0000000000 --- a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.h +++ /dev/null @@ -1,10 +0,0 @@ -#define MICROPY_HW_BOARD_NAME "Pimoroni Pico DV Base W" -#define MICROPY_HW_MCU_NAME "rp2040" - -#define CIRCUITPY_DIGITALIO_HAVE_INVALID_PULL (1) -#define CIRCUITPY_DIGITALIO_HAVE_INVALID_DRIVE_MODE (1) - -#define MICROPY_HW_LED_STATUS (&pin_CYW0) - -#define DEFAULT_UART_BUS_RX (&pin_GPIO1) -#define DEFAULT_UART_BUS_TX (&pin_GPIO0) diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.mk b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.mk deleted file mode 100644 index b7919a1847..0000000000 --- a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/mpconfigboard.mk +++ /dev/null @@ -1,29 +0,0 @@ -USB_VID = 0x2E8A -USB_PID = 0x105A -USB_PRODUCT = "Pimoroni Pico DV Demo Base for Pico W" -USB_MANUFACTURER = "Pimoroni" - -CHIP_VARIANT = RP2040 -CHIP_FAMILY = rp2 - -EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ" - -CIRCUITPY__EVE = 1 - -CIRCUITPY_CYW43 = 1 -CIRCUITPY_SSL = 1 -CIRCUITPY_SSL_MBEDTLS = 1 -CIRCUITPY_HASHLIB = 1 -CIRCUITPY_WEB_WORKFLOW = 1 -CIRCUITPY_MDNS = 1 -CIRCUITPY_SOCKETPOOL = 1 -CIRCUITPY_WIFI = 1 - -CIRCUITPY_PICODVI = 1 - -CFLAGS += -DCYW43_PIN_WL_HOST_WAKE=24 -DCYW43_PIN_WL_REG_ON=23 -DCYW43_WL_GPIO_COUNT=3 -DCYW43_WL_GPIO_LED_PIN=0 -# Must be accompanied by a linker script change -CFLAGS += -DCIRCUITPY_FIRMWARE_SIZE='(1536 * 1024)' - -# Include these Python libraries in firmware. -FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_SD diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/pico-sdk-configboard.h b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/pico-sdk-configboard.h deleted file mode 100644 index a41131dd22..0000000000 --- a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/pico-sdk-configboard.h +++ /dev/null @@ -1,4 +0,0 @@ -// Put board-specific pico-sdk definitions here. This file must exist. - -// Allow extra time for xosc to start. -#define PICO_XOSC_STARTUP_DELAY_MULTIPLIER 64 diff --git a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/pins.c b/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/pins.c deleted file mode 100644 index 6ab85f3c34..0000000000 --- a/ports/raspberrypi/boards/pimoroni_pico_dv_base_w/pins.c +++ /dev/null @@ -1,89 +0,0 @@ -#include "shared-bindings/board/__init__.h" - -#include "shared-module/displayio/__init__.h" - -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { - CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS - - { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO0) }, - { MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) }, - { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO1) }, - { MP_ROM_QSTR(MP_QSTR_GP1), MP_ROM_PTR(&pin_GPIO1) }, - - { MP_ROM_QSTR(MP_QSTR_GP2), MP_ROM_PTR(&pin_GPIO2) }, - { MP_ROM_QSTR(MP_QSTR_GP3), MP_ROM_PTR(&pin_GPIO3) }, - { MP_ROM_QSTR(MP_QSTR_GP4), MP_ROM_PTR(&pin_GPIO4) }, - { MP_ROM_QSTR(MP_QSTR_GP5), MP_ROM_PTR(&pin_GPIO5) }, - { MP_ROM_QSTR(MP_QSTR_GP6), MP_ROM_PTR(&pin_GPIO6) }, - { MP_ROM_QSTR(MP_QSTR_GP7), MP_ROM_PTR(&pin_GPIO7) }, - { MP_ROM_QSTR(MP_QSTR_GP8), MP_ROM_PTR(&pin_GPIO8) }, - { MP_ROM_QSTR(MP_QSTR_GP9), MP_ROM_PTR(&pin_GPIO9) }, - { MP_ROM_QSTR(MP_QSTR_GP10), MP_ROM_PTR(&pin_GPIO10) }, - { MP_ROM_QSTR(MP_QSTR_GP11), MP_ROM_PTR(&pin_GPIO11) }, - { MP_ROM_QSTR(MP_QSTR_GP12), MP_ROM_PTR(&pin_GPIO12) }, - { MP_ROM_QSTR(MP_QSTR_GP13), MP_ROM_PTR(&pin_GPIO13) }, - - { MP_ROM_QSTR(MP_QSTR_BUTTON_A), MP_ROM_PTR(&pin_GPIO14) }, - { MP_ROM_QSTR(MP_QSTR_GP14), MP_ROM_PTR(&pin_GPIO14) }, - - { MP_ROM_QSTR(MP_QSTR_BUTTON_B), MP_ROM_PTR(&pin_GPIO15) }, - { MP_ROM_QSTR(MP_QSTR_GP15), MP_ROM_PTR(&pin_GPIO15) }, - - { MP_ROM_QSTR(MP_QSTR_BUTTON_C), MP_ROM_PTR(&pin_GPIO16) }, - { MP_ROM_QSTR(MP_QSTR_GP16), MP_ROM_PTR(&pin_GPIO16) }, - { MP_ROM_QSTR(MP_QSTR_GP17), MP_ROM_PTR(&pin_GPIO17) }, - { MP_ROM_QSTR(MP_QSTR_GP18), MP_ROM_PTR(&pin_GPIO18) }, - { MP_ROM_QSTR(MP_QSTR_GP19), MP_ROM_PTR(&pin_GPIO19) }, - { MP_ROM_QSTR(MP_QSTR_GP20), MP_ROM_PTR(&pin_GPIO20) }, - { MP_ROM_QSTR(MP_QSTR_GP21), MP_ROM_PTR(&pin_GPIO21) }, - { MP_ROM_QSTR(MP_QSTR_GP22), MP_ROM_PTR(&pin_GPIO22) }, - - // SD Card - { MP_ROM_QSTR(MP_QSTR_SD_SCK), MP_ROM_PTR(&pin_GPIO5)}, - { MP_ROM_QSTR(MP_QSTR_SD_MOSI), MP_ROM_PTR(&pin_GPIO18)}, - { MP_ROM_QSTR(MP_QSTR_SD_MISO), MP_ROM_PTR(&pin_GPIO19)}, - { MP_ROM_QSTR(MP_QSTR_SD_CS), MP_ROM_PTR(&pin_GPIO22)}, - - { MP_ROM_QSTR(MP_QSTR_SMPS_MODE), MP_ROM_PTR(&pin_CYW1) }, - - { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_CYW0) }, - - { MP_ROM_QSTR(MP_QSTR_VBUS_SENSE), MP_ROM_PTR(&pin_CYW2) }, - - { MP_ROM_QSTR(MP_QSTR_I2S_WORD_SELECT), MP_ROM_PTR(&pin_GPIO26) }, - { MP_ROM_QSTR(MP_QSTR_GP26_A0), MP_ROM_PTR(&pin_GPIO26) }, - { MP_ROM_QSTR(MP_QSTR_GP26), MP_ROM_PTR(&pin_GPIO26) }, - { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) }, - - { MP_ROM_QSTR(MP_QSTR_I2S_BIT_CLOCK), MP_ROM_PTR(&pin_GPIO27) }, - { MP_ROM_QSTR(MP_QSTR_GP27_A1), MP_ROM_PTR(&pin_GPIO27) }, - { MP_ROM_QSTR(MP_QSTR_GP27), MP_ROM_PTR(&pin_GPIO27) }, - { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO27) }, - - { MP_ROM_QSTR(MP_QSTR_I2S_DATA), MP_ROM_PTR(&pin_GPIO28) }, - { MP_ROM_QSTR(MP_QSTR_GP28_A2), MP_ROM_PTR(&pin_GPIO28) }, - { MP_ROM_QSTR(MP_QSTR_GP28), MP_ROM_PTR(&pin_GPIO28) }, - { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO28) }, - - { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) }, - { MP_ROM_QSTR(MP_QSTR_VOLTAGE_MONITOR), MP_ROM_PTR(&pin_GPIO29) }, - - // DVI VIDEO - { MP_ROM_QSTR(MP_QSTR_DV_CEC), MP_ROM_PTR(&pin_GPIO2) }, - { MP_ROM_QSTR(MP_QSTR_DV_SCL), MP_ROM_PTR(&pin_GPIO3) }, - { MP_ROM_QSTR(MP_QSTR_DV_SDA), MP_ROM_PTR(&pin_GPIO4) }, - { MP_ROM_QSTR(MP_QSTR_CKN), MP_ROM_PTR(&pin_GPIO6) }, - { MP_ROM_QSTR(MP_QSTR_CKP), MP_ROM_PTR(&pin_GPIO7) }, - { MP_ROM_QSTR(MP_QSTR_D0N), MP_ROM_PTR(&pin_GPIO8) }, - { MP_ROM_QSTR(MP_QSTR_D0P), MP_ROM_PTR(&pin_GPIO9) }, - { MP_ROM_QSTR(MP_QSTR_D1N), MP_ROM_PTR(&pin_GPIO10) }, - { MP_ROM_QSTR(MP_QSTR_D1P), MP_ROM_PTR(&pin_GPIO11) }, - { MP_ROM_QSTR(MP_QSTR_D2N), MP_ROM_PTR(&pin_GPIO12) }, - { MP_ROM_QSTR(MP_QSTR_D2P), MP_ROM_PTR(&pin_GPIO13) }, - { MP_ROM_QSTR(MP_QSTR_DV_HPD), MP_ROM_PTR(&pin_GPIO17) }, - - { MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].framebuffer_display)}, - -}; - -MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); From 298bd16529235a7b478818e4feb45c667071c8ad Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Thu, 4 May 2023 15:55:33 -0400 Subject: [PATCH 116/117] Fix creating virtual environment for stub creation --- tools/test-stubs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/test-stubs.sh b/tools/test-stubs.sh index c977ad26d9..6c6c991015 100755 --- a/tools/test-stubs.sh +++ b/tools/test-stubs.sh @@ -1,6 +1,6 @@ #!/bin/sh -e rm -rf test-stubs -python3 -mvenv test-stubs +python3 -m venv test-stubs . test-stubs/bin/activate pip install mypy isort black adafruit-circuitpython-typing wheel rm -rf circuitpython-stubs .mypy_cache From 66411fdd38b95e3b0d3ae6fad7dbe35c873569a4 Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 5 May 2023 17:09:20 -0500 Subject: [PATCH 117/117] espressif: check return value from esp_ping_new_session MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit esp_ping_new_session can fail, particularly if ping is called quickly many times in succession. This is because `esp_ping_new_session` has to do a bunch of stuff including creating a task and a socket. Calling `esp_ping_delete_session` doesn't clean up these resources immediately. Instead, it signals the task to clean up resources and exit 'soon', but 'soon' is defined as 1 second. When the calls are frequent, the in-use sockets and tasks fill up available slots—I didn't actually check which resource gets used up first. With this change, the ping call will raise an exception instead of continuing with a call to esp_ping_start that crashes. Closes #5980 based on my testing on an ESP32S3-N8R2. --- ports/espressif/common-hal/wifi/Radio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ports/espressif/common-hal/wifi/Radio.c b/ports/espressif/common-hal/wifi/Radio.c index 0ce535899a..851e1bea25 100644 --- a/ports/espressif/common-hal/wifi/Radio.c +++ b/ports/espressif/common-hal/wifi/Radio.c @@ -29,6 +29,7 @@ #include +#include "bindings/espidf/__init__.h" #include "common-hal/wifi/__init__.h" #include "shared/runtime/interrupt_char.h" #include "py/gc.h" @@ -497,7 +498,7 @@ mp_int_t common_hal_wifi_radio_ping(wifi_radio_obj_t *self, mp_obj_t ip_address, size_t timeout_ms = timeout * 1000; esp_ping_handle_t ping; - esp_ping_new_session(&ping_config, NULL, &ping); + CHECK_ESP_RESULT(esp_ping_new_session(&ping_config, NULL, &ping)); esp_ping_start(ping); uint32_t received = 0;