From dc0ff3c86f121dff8beae5b2a2cc939267f4694d Mon Sep 17 00:00:00 2001 From: Sean Murphy Date: Thu, 13 Feb 2025 21:25:43 -0400 Subject: [PATCH 01/11] adding support for elecrow crowpanel 4.2 epaper device --- .../elecrow_crowpanel_4_2_epaper/board.c | 11 +++ .../mpconfigboard.h | 27 +++++++ .../mpconfigboard.mk | 17 +++++ .../elecrow_crowpanel_4_2_epaper/pins.c | 73 +++++++++++++++++++ .../elecrow_crowpanel_4_2_epaper/sdkconfig | 14 ++++ 5 files changed, 142 insertions(+) create mode 100644 ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c create mode 100644 ports/espressif/boards/elecrow_crowpanel_4_2_epaper/mpconfigboard.h create mode 100644 ports/espressif/boards/elecrow_crowpanel_4_2_epaper/mpconfigboard.mk create mode 100644 ports/espressif/boards/elecrow_crowpanel_4_2_epaper/pins.c create mode 100644 ports/espressif/boards/elecrow_crowpanel_4_2_epaper/sdkconfig diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c new file mode 100644 index 0000000000000..495b5e3465c6a --- /dev/null +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c @@ -0,0 +1,11 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "supervisor/board.h" + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. + +// TODO: diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/mpconfigboard.h b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/mpconfigboard.h new file mode 100644 index 0000000000000..8d66269523237 --- /dev/null +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/mpconfigboard.h @@ -0,0 +1,27 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2019 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once + +// Micropython setup + +#define MICROPY_HW_BOARD_NAME "CrowPanel 4.2 EPaper" +#define MICROPY_HW_MCU_NAME "ESP32S3" +#define MICROPY_HW_LED_STATUS (&pin_GPIO17) +#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0) + +#define CIRCUITPY_BOARD_SPI (2) +#define CIRCUITPY_BOARD_SPI_PIN { \ + {.clock = &pin_GPIO39, .mosi = &pin_GPIO40, .miso = &pin_GPIO13}, /*SD*/ \ + {.clock = &pin_GPIO12, .mosi = &pin_GPIO11}, /*EPD*/ \ +} + +// UART pins attached to the USB-serial converter chip +#define DEFAULT_UART_BUS_RX (&pin_GPIO43) +#define DEFAULT_UART_BUS_TX (&pin_GPIO44) + +#define CIRCUITPY_CONSOLE_UART_TX DEFAULT_UART_BUS_TX +#define CIRCUITPY_CONSOLE_UART_RX DEFAULT_UART_BUS_RX diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/mpconfigboard.mk b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/mpconfigboard.mk new file mode 100644 index 0000000000000..3f14971607b97 --- /dev/null +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/mpconfigboard.mk @@ -0,0 +1,17 @@ +CIRCUITPY_CREATOR_ID = 0x1C350000 +CIRCUITPY_CREATION_ID = 0x00000001 + +# This board doesn't have USB by default, it +# instead uses a CH340C USB-to-Serial chip +CIRCUITPY_USB_DEVICE = 0 +CIRCUITPY_ESP_USB_SERIAL_JTAG = 0 + +IDF_TARGET = esp32s3 + +CIRCUITPY_ESP_FLASH_SIZE = 8MB +CIRCUITPY_ESP_FLASH_MODE = qio +CIRCUITPY_ESP_FLASH_FREQ = 80m + +CIRCUITPY_ESP_PSRAM_SIZE = 8MB +CIRCUITPY_ESP_PSRAM_MODE = opi +CIRCUITPY_ESP_PSRAM_FREQ = 80m diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/pins.c b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/pins.c new file mode 100644 index 0000000000000..c9712f0c18c9e --- /dev/null +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/pins.c @@ -0,0 +1,73 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#include "shared-bindings/board/__init__.h" +#include "shared-module/displayio/__init__.h" + +CIRCUITPY_BOARD_BUS_SINGLETON(tf_spi, spi, 0) +CIRCUITPY_BOARD_BUS_SINGLETON(epd_spi, spi, 1) + + +static const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + // Buttons + { MP_ROM_QSTR(MP_QSTR_BUTTON_BOOT), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_BUTTON_EXIT), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_BUTTON_MENU), MP_ROM_PTR(&pin_GPIO2) }, + + // Rocker Switch + { MP_ROM_QSTR(MP_QSTR_ROCKER_DOWN), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_ROCKER_CLICK), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_ROCKER_UP), MP_ROM_PTR(&pin_GPIO6) }, + + // LED + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO41) }, + + // Device Control (Pins that, when activated, enable devices) + { MP_ROM_QSTR(MP_QSTR_EPD_ENABLE), MP_ROM_PTR(&pin_GPIO7) }, + { MP_ROM_QSTR(MP_QSTR_TF_ENABLE), MP_ROM_PTR(&pin_GPIO42) }, + + // EPD + { MP_ROM_QSTR(MP_QSTR_EPD_BUSY), MP_ROM_PTR(&pin_GPIO48) }, + { MP_ROM_QSTR(MP_QSTR_EPD_RES), MP_ROM_PTR(&pin_GPIO47) }, + { MP_ROM_QSTR(MP_QSTR_EPD_DC), MP_ROM_PTR(&pin_GPIO46) }, + { MP_ROM_QSTR(MP_QSTR_EPD_CS), MP_ROM_PTR(&pin_GPIO45) }, + { MP_ROM_QSTR(MP_QSTR_EPD_CLK), MP_ROM_PTR(&pin_GPIO12) }, + { MP_ROM_QSTR(MP_QSTR_EPD_MOSI), MP_ROM_PTR(&pin_GPIO10) }, + + // TF Slot + { MP_ROM_QSTR(MP_QSTR_TF_CS), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_TF_MOSI), MP_ROM_PTR(&pin_GPIO40) }, + { MP_ROM_QSTR(MP_QSTR_TF_CLK), MP_ROM_PTR(&pin_GPIO39) }, + { MP_ROM_QSTR(MP_QSTR_TF_MISO), MP_ROM_PTR(&pin_GPIO13) }, + + // User accessible GPIO + { MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_IO14), MP_ROM_PTR(&pin_GPIO14) }, + { MP_ROM_QSTR(MP_QSTR_IO15), MP_ROM_PTR(&pin_GPIO15) }, + { MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_IO17), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_IO18), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_IO19), MP_ROM_PTR(&pin_GPIO19) }, + { MP_ROM_QSTR(MP_QSTR_IO20), MP_ROM_PTR(&pin_GPIO20) }, + { MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) }, + { MP_ROM_QSTR(MP_QSTR_IO38), MP_ROM_PTR(&pin_GPIO38) }, + + // TODO: Are the UART pins really this, or are they reversed? + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO44) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO43) }, + + // Objects + { MP_ROM_QSTR(MP_QSTR_TF_SPI), MP_ROM_PTR(&board_tf_spi_obj) }, + { MP_ROM_QSTR(MP_QSTR_EPD_SPI), MP_ROM_PTR(&board_epd_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/elecrow_crowpanel_4_2_epaper/sdkconfig b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/sdkconfig new file mode 100644 index 0000000000000..e962866216039 --- /dev/null +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/sdkconfig @@ -0,0 +1,14 @@ +# +# Espressif IoT Development Framework Configuration +# +# +# Component config +# +# +# LWIP +# +# end of LWIP + +# end of Component config + +# end of Espressif IoT Development Framework Configuration From a68c40cbf134e34d1898667a47bd029fe9894410 Mon Sep 17 00:00:00 2001 From: Sean Murphy Date: Thu, 13 Feb 2025 21:38:36 -0400 Subject: [PATCH 02/11] added board.c --- .../elecrow_crowpanel_4_2_epaper/board.c | 87 ++++++++++++++++++- 1 file changed, 84 insertions(+), 3 deletions(-) diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c index 495b5e3465c6a..c9b9c9c41fd48 100644 --- a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c @@ -1,11 +1,92 @@ // This file is part of the CircuitPython project: https://circuitpython.org // -// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries +// SPDX-FileCopyrightText: Copyright (c) 2020 Joey Castillo // // SPDX-License-Identifier: MIT #include "supervisor/board.h" +#include "mpconfigboard.h" +#include "hal/include/hal_gpio.h" +#include "shared-bindings/busio/SPI.h" +#include "shared-bindings/fourwire/FourWire.h" +#include "shared-bindings/time/__init__.h" +#include "shared-module/displayio/__init__.h" +#include "shared-module/displayio/mipi_constants.h" -// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. -// TODO: +#define DELAY 0x80 +#define HEIGHT 300 +#define WIDTH 400 + +uint8_t start_sequence[] = { + 0x01, 0x04, 0x03, 0x00, 0x2b, 0x2b, // power setting + 0x06, 0x03, 0x17, 0x17, 0x17, // booster soft start + 0x04, 0x80, 0xc8, // power on and wait 200 ms + 0x00, 0x01, 0x0f, // panel setting + 0x61, 0x04, (HEIGHT >> 8) & 0xFF, HEIGHT & 0xFF, (WIDTH >> 8) & 0xFF, WIDTH & 0xFF // Resolution +}; + +uint8_t stop_sequence[] = { + 0x50, 0x01, 0xf7, // CDI setting + 0x02, 0x80, 0xf0 // Power off +}; + +uint8_t refresh_sequence[] = { + 0x12, 0x00 +}; + +void board_init(void) { + fourwire_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); + + bus->base.type = &fourwire_fourwire_type; + common_hal_fourwire_fourwire_construct(bus, + spi, + &pin_GPIO46, // EPD_DC Command or data + &pin_GPIO45, // EPD_CS Chip select + &pin_GPIO47, // EPD_RST Reset + 1000000, // Baudrate + 0, // Polarity + 0); // Phase + + epaperdisplay_epaperdisplay_obj_t *display = &allocate_display()->epaper_display; + display->base.type = &epaperdisplay_epaperdisplay_type; + common_hal_epaperdisplay_epaperdisplay_construct(display, + bus, + start_sequence, + sizeof(start_sequence), + 0, // start up time + stop_sequence, + sizeof(stop_sequence), + 400, // width + 300, // height + 400, // RAM width + 300, // RAM height + 0, // colstart + 0, // rowstart + 0, // 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 + 0x13, // write_black_ram_command + false, // black_bits_inverted + NO_COMMAND, // write_color_ram_command (can add this for grayscale eventually) + false, // color_bits_inverted + 0x000000, // highlight_color + refresh_sequence, // refresh_display_sequence + sizeof(refresh_sequence), + 40, // refresh_time + &pin_GPIO48, // busy_pin + false, // busy_state + 5, // seconds_per_frame + false, // chip_select (don't always toggle chip select) + false, // grayscale + false, // acep + false, // two_byte_sequence_length + false); // address_little_endian +} + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. From bb49868bceb9b78e9ae30b355682a98151f02d9a Mon Sep 17 00:00:00 2001 From: Sean Murphy Date: Thu, 13 Feb 2025 21:39:46 -0400 Subject: [PATCH 03/11] fixed board.c includes --- ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c index c9b9c9c41fd48..e087f58fdccd6 100644 --- a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c @@ -6,13 +6,13 @@ #include "supervisor/board.h" #include "mpconfigboard.h" -#include "hal/include/hal_gpio.h" #include "shared-bindings/busio/SPI.h" #include "shared-bindings/fourwire/FourWire.h" -#include "shared-bindings/time/__init__.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/digitalio/DigitalInOut.h" #define DELAY 0x80 #define HEIGHT 300 From 976f3af762647d35976ef3fe937f7de202615dcf Mon Sep 17 00:00:00 2001 From: Sean Murphy Date: Fri, 14 Feb 2025 08:48:55 -0400 Subject: [PATCH 04/11] board.c updates --- .../elecrow_crowpanel_4_2_epaper/board.c | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c index e087f58fdccd6..f29dc89c80308 100644 --- a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c @@ -36,6 +36,15 @@ uint8_t refresh_sequence[] = { }; void board_init(void) { + + // Pull EPD Enable pin high + digitalio_digitalinout_obj_t vext_pin_obj; + vext_pin_obj.base.type = &digitalio_digitalinout_type; + common_hal_digitalio_digitalinout_construct(&vext_pin_obj, &pin_GPIO7); + common_hal_digitalio_digitalinout_switch_to_output(&vext_pin_obj, true, DRIVE_MODE_PUSH_PULL); + common_hal_digitalio_digitalinout_never_reset(&vext_pin_obj); + + // Set up SPI bus fourwire_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); @@ -51,6 +60,7 @@ void board_init(void) { 0, // Polarity 0); // Phase + // Set up EPD object epaperdisplay_epaperdisplay_obj_t *display = &allocate_display()->epaper_display; display->base.type = &epaperdisplay_epaperdisplay_type; common_hal_epaperdisplay_epaperdisplay_construct(display, @@ -62,11 +72,11 @@ void board_init(void) { sizeof(stop_sequence), 400, // width 300, // height - 400, // RAM width - 300, // RAM height + 300, // RAM width + 400, // RAM height 0, // colstart 0, // rowstart - 0, // rotation + 90, // rotation NO_COMMAND, // set_column_window_command NO_COMMAND, // set_row_window_command NO_COMMAND, // set_current_column_command @@ -89,4 +99,14 @@ void board_init(void) { false); // address_little_endian } +void board_deinit(void) { + epaperdisplay_epaperdisplay_obj_t *display = &displays[0].epaper_display; + if (display->base.type == &epaperdisplay_epaperdisplay_type) { + while (common_hal_epaperdisplay_epaperdisplay_get_busy(display)) { + RUN_BACKGROUND_TASKS; + } + } + common_hal_displayio_release_displays(); +} + // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. From 36989e9e528cba5d2b8ecc87542f5f9552edcad1 Mon Sep 17 00:00:00 2001 From: Sean Murphy Date: Fri, 14 Feb 2025 08:58:20 -0400 Subject: [PATCH 05/11] update board.c --- ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c index f29dc89c80308..9257a88357eb1 100644 --- a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c @@ -70,8 +70,8 @@ void board_init(void) { 0, // start up time stop_sequence, sizeof(stop_sequence), - 400, // width - 300, // height + WIDTH, // width + HEIGHT, // height 300, // RAM width 400, // RAM height 0, // colstart From 72754e491e8f31f2020d8a5fa7fe305dc8b2c4e6 Mon Sep 17 00:00:00 2001 From: Sean Murphy Date: Thu, 20 Feb 2025 15:38:53 -0400 Subject: [PATCH 06/11] updated epd sequences --- .../elecrow_crowpanel_4_2_epaper/board.c | 52 ++++++++++++++----- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c index 9257a88357eb1..d973a8c029574 100644 --- a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c @@ -14,25 +14,51 @@ #include "shared-bindings/board/__init__.h" #include "shared-bindings/digitalio/DigitalInOut.h" -#define DELAY 0x80 #define HEIGHT 300 #define WIDTH 400 +// Sequences pulled from InkyWhat driver (https://github.com/alanta/CircuitPython_InkyWhat) uint8_t start_sequence[] = { - 0x01, 0x04, 0x03, 0x00, 0x2b, 0x2b, // power setting - 0x06, 0x03, 0x17, 0x17, 0x17, // booster soft start - 0x04, 0x80, 0xc8, // power on and wait 200 ms - 0x00, 0x01, 0x0f, // panel setting - 0x61, 0x04, (HEIGHT >> 8) & 0xFF, HEIGHT & 0xFF, (WIDTH >> 8) & 0xFF, WIDTH & 0xFF // Resolution + 0x12, 0x80, 0x80, // Software reset ✅ TODO wait for busy instead of fixed delay + 0x12, 0x80, 0x80, // Software reset ✅ TODO wait for busy instead of fixed delay + 0x74, 0x01, 0x54, // set analog block control ✅ + 0x7e, 0x01, 0x3b, // set digital block control ✅ + 0x01, 0x03, 0x2b, 0x01, 0x00, // driver output control + 0x03, 0x01, 0x17, // Gate driving voltage ✅ + 0x04, 0x03, 0x07, 0xac, 0x32, // Source Driving voltage ✅ + 0x3a, 0x01, 0x07, // Dummy line period ✅ + 0x3b, 0x01, 0x04, // Gate line width ✅ + 0x3c, 0x01, 0x00, // Border color + 0x2c, 0x01, 0x3c, // VCOM Register, 0x3c = -1.5v? ✅ + 0x22, 0x01, 0xc7, // Display update sequence ✅ + 0x04, 0x03, 0x07, 0xac, 0x32, // Set voltage of VSH and VSL (yellow) + // LUT (yellow) + 0x32, 0x46, + 0xfa, 0x94, 0x8c, 0xc0, 0xd0, 0x00, 0x00, + 0xfa, 0x94, 0x2c, 0x80, 0xe0, 0x00, 0x00, + 0xfa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xfa, 0x94, 0xf8, 0x80, 0x50, 0x00, 0xcc, + 0xbf, 0x58, 0xfc, 0x80, 0xd0, 0x00, 0x11, + 0x40, 0x10, 0x40, 0x10, 0x08, + 0x08, 0x10, 0x04, 0x04, 0x10, + 0x08, 0x08, 0x03, 0x08, 0x20, + 0x08, 0x04, 0x00, 0x00, 0x10, + 0x10, 0x08, 0x08, 0x00, 0x20, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x11, 0x01, 0x03, // Data entry mode setting 0x03 = X/Y increment ✅ + // self._send_command(0x44, [0x00, (self.cols // 8) - 1]) # Set RAM X Start/End + 0x44, 0x02, 0x00, 0x31, // Set RAM X Start/End + // self._send_command(0x45, [0x00, 0x00] + packed_height) # Set RAM Y Start/End + 0x45, 0x04, 0x00, 0x00, 0x2b, 0x01, // Set RAM Y Start/End }; uint8_t stop_sequence[] = { - 0x50, 0x01, 0xf7, // CDI setting - 0x02, 0x80, 0xf0 // Power off + 0x10, 0x01, 0x01 // Enter Deep Sleep }; uint8_t refresh_sequence[] = { - 0x12, 0x00 + 0x20, 0x00 }; void board_init(void) { @@ -79,11 +105,11 @@ void board_init(void) { 90, // 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 - 0x13, // write_black_ram_command + 0x4E, // set_current_column_command + 0x4F, // set_current_row_command + 0x24, // write_black_ram_command false, // black_bits_inverted - NO_COMMAND, // write_color_ram_command (can add this for grayscale eventually) + 0x26, // write_color_ram_command (can add this for grayscale eventually) false, // color_bits_inverted 0x000000, // highlight_color refresh_sequence, // refresh_display_sequence From 7c2f85bfaa2d6a9b183adde66829fb20d473a53a Mon Sep 17 00:00:00 2001 From: Sean Murphy Date: Thu, 20 Feb 2025 20:07:01 -0400 Subject: [PATCH 07/11] updated sequences --- .../elecrow_crowpanel_4_2_epaper/board.c | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c index d973a8c029574..e95a7feb4d925 100644 --- a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c @@ -31,21 +31,21 @@ uint8_t start_sequence[] = { 0x3c, 0x01, 0x00, // Border color 0x2c, 0x01, 0x3c, // VCOM Register, 0x3c = -1.5v? ✅ 0x22, 0x01, 0xc7, // Display update sequence ✅ - 0x04, 0x03, 0x07, 0xac, 0x32, // Set voltage of VSH and VSL (yellow) + // 0x04, 0x03, 0x07, 0xac, 0x32, // Set voltage of VSH and VSL (yellow) // LUT (yellow) - 0x32, 0x46, - 0xfa, 0x94, 0x8c, 0xc0, 0xd0, 0x00, 0x00, - 0xfa, 0x94, 0x2c, 0x80, 0xe0, 0x00, 0x00, - 0xfa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xfa, 0x94, 0xf8, 0x80, 0x50, 0x00, 0xcc, - 0xbf, 0x58, 0xfc, 0x80, 0xd0, 0x00, 0x11, - 0x40, 0x10, 0x40, 0x10, 0x08, - 0x08, 0x10, 0x04, 0x04, 0x10, - 0x08, 0x08, 0x03, 0x08, 0x20, - 0x08, 0x04, 0x00, 0x00, 0x10, - 0x10, 0x08, 0x08, 0x00, 0x20, - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, + // 0x32, 0x46, + // 0xfa, 0x94, 0x8c, 0xc0, 0xd0, 0x00, 0x00, + // 0xfa, 0x94, 0x2c, 0x80, 0xe0, 0x00, 0x00, + // 0xfa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // 0xfa, 0x94, 0xf8, 0x80, 0x50, 0x00, 0xcc, + // 0xbf, 0x58, 0xfc, 0x80, 0xd0, 0x00, 0x11, + // 0x40, 0x10, 0x40, 0x10, 0x08, + // 0x08, 0x10, 0x04, 0x04, 0x10, + // 0x08, 0x08, 0x03, 0x08, 0x20, + // 0x08, 0x04, 0x00, 0x00, 0x10, + // 0x10, 0x08, 0x08, 0x00, 0x20, + // 0x00, 0x00, 0x00, 0x00, 0x00, + // 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x01, 0x03, // Data entry mode setting 0x03 = X/Y increment ✅ // self._send_command(0x44, [0x00, (self.cols // 8) - 1]) # Set RAM X Start/End 0x44, 0x02, 0x00, 0x31, // Set RAM X Start/End From ec4cb222f64df3c660086e7f6df6f5ebdd65186e Mon Sep 17 00:00:00 2001 From: Sean Murphy Date: Mon, 24 Feb 2025 21:33:50 -0400 Subject: [PATCH 08/11] further work --- .../elecrow_crowpanel_4_2_epaper/board.c | 28 ++-- .../elecrow_crowpanel_4_2_epaper/board.c.epd | 138 ++++++++++++++++++ .../mpconfigboard.h | 6 +- .../mpconfigboard.mk | 4 +- .../elecrow_crowpanel_4_2_epaper/pins.c | 8 +- .../elecrow_crowpanel_4_2_epaper/sdkconfig | 1 + 6 files changed, 163 insertions(+), 22 deletions(-) create mode 100644 ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c.epd diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c index e95a7feb4d925..d973a8c029574 100644 --- a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c @@ -31,21 +31,21 @@ uint8_t start_sequence[] = { 0x3c, 0x01, 0x00, // Border color 0x2c, 0x01, 0x3c, // VCOM Register, 0x3c = -1.5v? ✅ 0x22, 0x01, 0xc7, // Display update sequence ✅ - // 0x04, 0x03, 0x07, 0xac, 0x32, // Set voltage of VSH and VSL (yellow) + 0x04, 0x03, 0x07, 0xac, 0x32, // Set voltage of VSH and VSL (yellow) // LUT (yellow) - // 0x32, 0x46, - // 0xfa, 0x94, 0x8c, 0xc0, 0xd0, 0x00, 0x00, - // 0xfa, 0x94, 0x2c, 0x80, 0xe0, 0x00, 0x00, - // 0xfa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - // 0xfa, 0x94, 0xf8, 0x80, 0x50, 0x00, 0xcc, - // 0xbf, 0x58, 0xfc, 0x80, 0xd0, 0x00, 0x11, - // 0x40, 0x10, 0x40, 0x10, 0x08, - // 0x08, 0x10, 0x04, 0x04, 0x10, - // 0x08, 0x08, 0x03, 0x08, 0x20, - // 0x08, 0x04, 0x00, 0x00, 0x10, - // 0x10, 0x08, 0x08, 0x00, 0x20, - // 0x00, 0x00, 0x00, 0x00, 0x00, - // 0x00, 0x00, 0x00, 0x00, 0x00, + 0x32, 0x46, + 0xfa, 0x94, 0x8c, 0xc0, 0xd0, 0x00, 0x00, + 0xfa, 0x94, 0x2c, 0x80, 0xe0, 0x00, 0x00, + 0xfa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xfa, 0x94, 0xf8, 0x80, 0x50, 0x00, 0xcc, + 0xbf, 0x58, 0xfc, 0x80, 0xd0, 0x00, 0x11, + 0x40, 0x10, 0x40, 0x10, 0x08, + 0x08, 0x10, 0x04, 0x04, 0x10, + 0x08, 0x08, 0x03, 0x08, 0x20, + 0x08, 0x04, 0x00, 0x00, 0x10, + 0x10, 0x08, 0x08, 0x00, 0x20, + 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x01, 0x03, // Data entry mode setting 0x03 = X/Y increment ✅ // self._send_command(0x44, [0x00, (self.cols // 8) - 1]) # Set RAM X Start/End 0x44, 0x02, 0x00, 0x31, // Set RAM X Start/End diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c.epd b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c.epd new file mode 100644 index 0000000000000..e95a7feb4d925 --- /dev/null +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c.epd @@ -0,0 +1,138 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2020 Joey Castillo +// +// SPDX-License-Identifier: MIT + +#include "supervisor/board.h" +#include "mpconfigboard.h" +#include "shared-bindings/busio/SPI.h" +#include "shared-bindings/fourwire/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/digitalio/DigitalInOut.h" + +#define HEIGHT 300 +#define WIDTH 400 + +// Sequences pulled from InkyWhat driver (https://github.com/alanta/CircuitPython_InkyWhat) +uint8_t start_sequence[] = { + 0x12, 0x80, 0x80, // Software reset ✅ TODO wait for busy instead of fixed delay + 0x12, 0x80, 0x80, // Software reset ✅ TODO wait for busy instead of fixed delay + 0x74, 0x01, 0x54, // set analog block control ✅ + 0x7e, 0x01, 0x3b, // set digital block control ✅ + 0x01, 0x03, 0x2b, 0x01, 0x00, // driver output control + 0x03, 0x01, 0x17, // Gate driving voltage ✅ + 0x04, 0x03, 0x07, 0xac, 0x32, // Source Driving voltage ✅ + 0x3a, 0x01, 0x07, // Dummy line period ✅ + 0x3b, 0x01, 0x04, // Gate line width ✅ + 0x3c, 0x01, 0x00, // Border color + 0x2c, 0x01, 0x3c, // VCOM Register, 0x3c = -1.5v? ✅ + 0x22, 0x01, 0xc7, // Display update sequence ✅ + // 0x04, 0x03, 0x07, 0xac, 0x32, // Set voltage of VSH and VSL (yellow) + // LUT (yellow) + // 0x32, 0x46, + // 0xfa, 0x94, 0x8c, 0xc0, 0xd0, 0x00, 0x00, + // 0xfa, 0x94, 0x2c, 0x80, 0xe0, 0x00, 0x00, + // 0xfa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + // 0xfa, 0x94, 0xf8, 0x80, 0x50, 0x00, 0xcc, + // 0xbf, 0x58, 0xfc, 0x80, 0xd0, 0x00, 0x11, + // 0x40, 0x10, 0x40, 0x10, 0x08, + // 0x08, 0x10, 0x04, 0x04, 0x10, + // 0x08, 0x08, 0x03, 0x08, 0x20, + // 0x08, 0x04, 0x00, 0x00, 0x10, + // 0x10, 0x08, 0x08, 0x00, 0x20, + // 0x00, 0x00, 0x00, 0x00, 0x00, + // 0x00, 0x00, 0x00, 0x00, 0x00, + 0x11, 0x01, 0x03, // Data entry mode setting 0x03 = X/Y increment ✅ + // self._send_command(0x44, [0x00, (self.cols // 8) - 1]) # Set RAM X Start/End + 0x44, 0x02, 0x00, 0x31, // Set RAM X Start/End + // self._send_command(0x45, [0x00, 0x00] + packed_height) # Set RAM Y Start/End + 0x45, 0x04, 0x00, 0x00, 0x2b, 0x01, // Set RAM Y Start/End +}; + +uint8_t stop_sequence[] = { + 0x10, 0x01, 0x01 // Enter Deep Sleep +}; + +uint8_t refresh_sequence[] = { + 0x20, 0x00 +}; + +void board_init(void) { + + // Pull EPD Enable pin high + digitalio_digitalinout_obj_t vext_pin_obj; + vext_pin_obj.base.type = &digitalio_digitalinout_type; + common_hal_digitalio_digitalinout_construct(&vext_pin_obj, &pin_GPIO7); + common_hal_digitalio_digitalinout_switch_to_output(&vext_pin_obj, true, DRIVE_MODE_PUSH_PULL); + common_hal_digitalio_digitalinout_never_reset(&vext_pin_obj); + + // Set up SPI bus + fourwire_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); + + bus->base.type = &fourwire_fourwire_type; + common_hal_fourwire_fourwire_construct(bus, + spi, + &pin_GPIO46, // EPD_DC Command or data + &pin_GPIO45, // EPD_CS Chip select + &pin_GPIO47, // EPD_RST Reset + 1000000, // Baudrate + 0, // Polarity + 0); // Phase + + // Set up EPD object + epaperdisplay_epaperdisplay_obj_t *display = &allocate_display()->epaper_display; + display->base.type = &epaperdisplay_epaperdisplay_type; + common_hal_epaperdisplay_epaperdisplay_construct(display, + bus, + start_sequence, + sizeof(start_sequence), + 0, // start up time + stop_sequence, + sizeof(stop_sequence), + WIDTH, // width + HEIGHT, // height + 300, // RAM width + 400, // RAM height + 0, // colstart + 0, // rowstart + 90, // rotation + NO_COMMAND, // set_column_window_command + NO_COMMAND, // set_row_window_command + 0x4E, // set_current_column_command + 0x4F, // set_current_row_command + 0x24, // write_black_ram_command + false, // black_bits_inverted + 0x26, // write_color_ram_command (can add this for grayscale eventually) + false, // color_bits_inverted + 0x000000, // highlight_color + refresh_sequence, // refresh_display_sequence + sizeof(refresh_sequence), + 40, // refresh_time + &pin_GPIO48, // busy_pin + false, // busy_state + 5, // seconds_per_frame + false, // chip_select (don't always toggle chip select) + false, // grayscale + false, // acep + false, // two_byte_sequence_length + false); // address_little_endian +} + +void board_deinit(void) { + epaperdisplay_epaperdisplay_obj_t *display = &displays[0].epaper_display; + if (display->base.type == &epaperdisplay_epaperdisplay_type) { + while (common_hal_epaperdisplay_epaperdisplay_get_busy(display)) { + RUN_BACKGROUND_TASKS; + } + } + common_hal_displayio_release_displays(); +} + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/mpconfigboard.h b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/mpconfigboard.h index 8d66269523237..f3c494ed48379 100644 --- a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/mpconfigboard.h +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/mpconfigboard.h @@ -10,7 +10,7 @@ #define MICROPY_HW_BOARD_NAME "CrowPanel 4.2 EPaper" #define MICROPY_HW_MCU_NAME "ESP32S3" -#define MICROPY_HW_LED_STATUS (&pin_GPIO17) +#define MICROPY_HW_LED_STATUS (&pin_GPIO41) #define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0) #define CIRCUITPY_BOARD_SPI (2) @@ -20,8 +20,8 @@ } // UART pins attached to the USB-serial converter chip -#define DEFAULT_UART_BUS_RX (&pin_GPIO43) -#define DEFAULT_UART_BUS_TX (&pin_GPIO44) +#define DEFAULT_UART_BUS_RX (&pin_GPIO44) +#define DEFAULT_UART_BUS_TX (&pin_GPIO43) #define CIRCUITPY_CONSOLE_UART_TX DEFAULT_UART_BUS_TX #define CIRCUITPY_CONSOLE_UART_RX DEFAULT_UART_BUS_RX diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/mpconfigboard.mk b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/mpconfigboard.mk index 3f14971607b97..c82057038b73b 100644 --- a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/mpconfigboard.mk +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/mpconfigboard.mk @@ -9,9 +9,11 @@ CIRCUITPY_ESP_USB_SERIAL_JTAG = 0 IDF_TARGET = esp32s3 CIRCUITPY_ESP_FLASH_SIZE = 8MB -CIRCUITPY_ESP_FLASH_MODE = qio +CIRCUITPY_ESP_FLASH_MODE = dio CIRCUITPY_ESP_FLASH_FREQ = 80m CIRCUITPY_ESP_PSRAM_SIZE = 8MB CIRCUITPY_ESP_PSRAM_MODE = opi CIRCUITPY_ESP_PSRAM_FREQ = 80m + +CIRCUITPY_ESPCAMERA = 0 diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/pins.c b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/pins.c index c9712f0c18c9e..21a15d0732b65 100644 --- a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/pins.c +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/pins.c @@ -37,7 +37,7 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_EPD_DC), MP_ROM_PTR(&pin_GPIO46) }, { MP_ROM_QSTR(MP_QSTR_EPD_CS), MP_ROM_PTR(&pin_GPIO45) }, { MP_ROM_QSTR(MP_QSTR_EPD_CLK), MP_ROM_PTR(&pin_GPIO12) }, - { MP_ROM_QSTR(MP_QSTR_EPD_MOSI), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_EPD_MOSI), MP_ROM_PTR(&pin_GPIO11) }, // TF Slot { MP_ROM_QSTR(MP_QSTR_TF_CS), MP_ROM_PTR(&pin_GPIO10) }, @@ -59,9 +59,9 @@ static const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) }, { MP_ROM_QSTR(MP_QSTR_IO38), MP_ROM_PTR(&pin_GPIO38) }, - // TODO: Are the UART pins really this, or are they reversed? - { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO44) }, - { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO43) }, + // UART + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) }, + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) }, // Objects { MP_ROM_QSTR(MP_QSTR_TF_SPI), MP_ROM_PTR(&board_tf_spi_obj) }, diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/sdkconfig b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/sdkconfig index e962866216039..a71099850d5ff 100644 --- a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/sdkconfig +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/sdkconfig @@ -7,6 +7,7 @@ # # LWIP # +CONFIG_ESP_PHY_ENABLE_USB=n # end of LWIP # end of Component config From 2098c62de0299f8c0a42d9d91207449710aae356 Mon Sep 17 00:00:00 2001 From: Sean Murphy Date: Tue, 25 Feb 2025 14:41:09 -0400 Subject: [PATCH 09/11] still fighting --- .../elecrow_crowpanel_4_2_epaper/board.c | 131 +---------------- .../elecrow_crowpanel_4_2_epaper/board.c.epd | 138 ------------------ .../mpconfigboard.mk | 2 +- .../elecrow_crowpanel_4_2_epaper/sdkconfig | 1 - 4 files changed, 2 insertions(+), 270 deletions(-) delete mode 100644 ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c.epd diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c index d973a8c029574..a3a9eec047145 100644 --- a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c @@ -1,138 +1,9 @@ // This file is part of the CircuitPython project: https://circuitpython.org // -// SPDX-FileCopyrightText: Copyright (c) 2020 Joey Castillo +// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries // // SPDX-License-Identifier: MIT #include "supervisor/board.h" -#include "mpconfigboard.h" -#include "shared-bindings/busio/SPI.h" -#include "shared-bindings/fourwire/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/digitalio/DigitalInOut.h" - -#define HEIGHT 300 -#define WIDTH 400 - -// Sequences pulled from InkyWhat driver (https://github.com/alanta/CircuitPython_InkyWhat) -uint8_t start_sequence[] = { - 0x12, 0x80, 0x80, // Software reset ✅ TODO wait for busy instead of fixed delay - 0x12, 0x80, 0x80, // Software reset ✅ TODO wait for busy instead of fixed delay - 0x74, 0x01, 0x54, // set analog block control ✅ - 0x7e, 0x01, 0x3b, // set digital block control ✅ - 0x01, 0x03, 0x2b, 0x01, 0x00, // driver output control - 0x03, 0x01, 0x17, // Gate driving voltage ✅ - 0x04, 0x03, 0x07, 0xac, 0x32, // Source Driving voltage ✅ - 0x3a, 0x01, 0x07, // Dummy line period ✅ - 0x3b, 0x01, 0x04, // Gate line width ✅ - 0x3c, 0x01, 0x00, // Border color - 0x2c, 0x01, 0x3c, // VCOM Register, 0x3c = -1.5v? ✅ - 0x22, 0x01, 0xc7, // Display update sequence ✅ - 0x04, 0x03, 0x07, 0xac, 0x32, // Set voltage of VSH and VSL (yellow) - // LUT (yellow) - 0x32, 0x46, - 0xfa, 0x94, 0x8c, 0xc0, 0xd0, 0x00, 0x00, - 0xfa, 0x94, 0x2c, 0x80, 0xe0, 0x00, 0x00, - 0xfa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0xfa, 0x94, 0xf8, 0x80, 0x50, 0x00, 0xcc, - 0xbf, 0x58, 0xfc, 0x80, 0xd0, 0x00, 0x11, - 0x40, 0x10, 0x40, 0x10, 0x08, - 0x08, 0x10, 0x04, 0x04, 0x10, - 0x08, 0x08, 0x03, 0x08, 0x20, - 0x08, 0x04, 0x00, 0x00, 0x10, - 0x10, 0x08, 0x08, 0x00, 0x20, - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, - 0x11, 0x01, 0x03, // Data entry mode setting 0x03 = X/Y increment ✅ - // self._send_command(0x44, [0x00, (self.cols // 8) - 1]) # Set RAM X Start/End - 0x44, 0x02, 0x00, 0x31, // Set RAM X Start/End - // self._send_command(0x45, [0x00, 0x00] + packed_height) # Set RAM Y Start/End - 0x45, 0x04, 0x00, 0x00, 0x2b, 0x01, // Set RAM Y Start/End -}; - -uint8_t stop_sequence[] = { - 0x10, 0x01, 0x01 // Enter Deep Sleep -}; - -uint8_t refresh_sequence[] = { - 0x20, 0x00 -}; - -void board_init(void) { - - // Pull EPD Enable pin high - digitalio_digitalinout_obj_t vext_pin_obj; - vext_pin_obj.base.type = &digitalio_digitalinout_type; - common_hal_digitalio_digitalinout_construct(&vext_pin_obj, &pin_GPIO7); - common_hal_digitalio_digitalinout_switch_to_output(&vext_pin_obj, true, DRIVE_MODE_PUSH_PULL); - common_hal_digitalio_digitalinout_never_reset(&vext_pin_obj); - - // Set up SPI bus - fourwire_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); - - bus->base.type = &fourwire_fourwire_type; - common_hal_fourwire_fourwire_construct(bus, - spi, - &pin_GPIO46, // EPD_DC Command or data - &pin_GPIO45, // EPD_CS Chip select - &pin_GPIO47, // EPD_RST Reset - 1000000, // Baudrate - 0, // Polarity - 0); // Phase - - // Set up EPD object - epaperdisplay_epaperdisplay_obj_t *display = &allocate_display()->epaper_display; - display->base.type = &epaperdisplay_epaperdisplay_type; - common_hal_epaperdisplay_epaperdisplay_construct(display, - bus, - start_sequence, - sizeof(start_sequence), - 0, // start up time - stop_sequence, - sizeof(stop_sequence), - WIDTH, // width - HEIGHT, // height - 300, // RAM width - 400, // RAM height - 0, // colstart - 0, // rowstart - 90, // rotation - NO_COMMAND, // set_column_window_command - NO_COMMAND, // set_row_window_command - 0x4E, // set_current_column_command - 0x4F, // set_current_row_command - 0x24, // write_black_ram_command - false, // black_bits_inverted - 0x26, // write_color_ram_command (can add this for grayscale eventually) - false, // color_bits_inverted - 0x000000, // highlight_color - refresh_sequence, // refresh_display_sequence - sizeof(refresh_sequence), - 40, // refresh_time - &pin_GPIO48, // busy_pin - false, // busy_state - 5, // seconds_per_frame - false, // chip_select (don't always toggle chip select) - false, // grayscale - false, // acep - false, // two_byte_sequence_length - false); // address_little_endian -} - -void board_deinit(void) { - epaperdisplay_epaperdisplay_obj_t *display = &displays[0].epaper_display; - if (display->base.type == &epaperdisplay_epaperdisplay_type) { - while (common_hal_epaperdisplay_epaperdisplay_get_busy(display)) { - RUN_BACKGROUND_TASKS; - } - } - common_hal_displayio_release_displays(); -} // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c.epd b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c.epd deleted file mode 100644 index e95a7feb4d925..0000000000000 --- a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c.epd +++ /dev/null @@ -1,138 +0,0 @@ -// This file is part of the CircuitPython project: https://circuitpython.org -// -// SPDX-FileCopyrightText: Copyright (c) 2020 Joey Castillo -// -// SPDX-License-Identifier: MIT - -#include "supervisor/board.h" -#include "mpconfigboard.h" -#include "shared-bindings/busio/SPI.h" -#include "shared-bindings/fourwire/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/digitalio/DigitalInOut.h" - -#define HEIGHT 300 -#define WIDTH 400 - -// Sequences pulled from InkyWhat driver (https://github.com/alanta/CircuitPython_InkyWhat) -uint8_t start_sequence[] = { - 0x12, 0x80, 0x80, // Software reset ✅ TODO wait for busy instead of fixed delay - 0x12, 0x80, 0x80, // Software reset ✅ TODO wait for busy instead of fixed delay - 0x74, 0x01, 0x54, // set analog block control ✅ - 0x7e, 0x01, 0x3b, // set digital block control ✅ - 0x01, 0x03, 0x2b, 0x01, 0x00, // driver output control - 0x03, 0x01, 0x17, // Gate driving voltage ✅ - 0x04, 0x03, 0x07, 0xac, 0x32, // Source Driving voltage ✅ - 0x3a, 0x01, 0x07, // Dummy line period ✅ - 0x3b, 0x01, 0x04, // Gate line width ✅ - 0x3c, 0x01, 0x00, // Border color - 0x2c, 0x01, 0x3c, // VCOM Register, 0x3c = -1.5v? ✅ - 0x22, 0x01, 0xc7, // Display update sequence ✅ - // 0x04, 0x03, 0x07, 0xac, 0x32, // Set voltage of VSH and VSL (yellow) - // LUT (yellow) - // 0x32, 0x46, - // 0xfa, 0x94, 0x8c, 0xc0, 0xd0, 0x00, 0x00, - // 0xfa, 0x94, 0x2c, 0x80, 0xe0, 0x00, 0x00, - // 0xfa, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - // 0xfa, 0x94, 0xf8, 0x80, 0x50, 0x00, 0xcc, - // 0xbf, 0x58, 0xfc, 0x80, 0xd0, 0x00, 0x11, - // 0x40, 0x10, 0x40, 0x10, 0x08, - // 0x08, 0x10, 0x04, 0x04, 0x10, - // 0x08, 0x08, 0x03, 0x08, 0x20, - // 0x08, 0x04, 0x00, 0x00, 0x10, - // 0x10, 0x08, 0x08, 0x00, 0x20, - // 0x00, 0x00, 0x00, 0x00, 0x00, - // 0x00, 0x00, 0x00, 0x00, 0x00, - 0x11, 0x01, 0x03, // Data entry mode setting 0x03 = X/Y increment ✅ - // self._send_command(0x44, [0x00, (self.cols // 8) - 1]) # Set RAM X Start/End - 0x44, 0x02, 0x00, 0x31, // Set RAM X Start/End - // self._send_command(0x45, [0x00, 0x00] + packed_height) # Set RAM Y Start/End - 0x45, 0x04, 0x00, 0x00, 0x2b, 0x01, // Set RAM Y Start/End -}; - -uint8_t stop_sequence[] = { - 0x10, 0x01, 0x01 // Enter Deep Sleep -}; - -uint8_t refresh_sequence[] = { - 0x20, 0x00 -}; - -void board_init(void) { - - // Pull EPD Enable pin high - digitalio_digitalinout_obj_t vext_pin_obj; - vext_pin_obj.base.type = &digitalio_digitalinout_type; - common_hal_digitalio_digitalinout_construct(&vext_pin_obj, &pin_GPIO7); - common_hal_digitalio_digitalinout_switch_to_output(&vext_pin_obj, true, DRIVE_MODE_PUSH_PULL); - common_hal_digitalio_digitalinout_never_reset(&vext_pin_obj); - - // Set up SPI bus - fourwire_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); - - bus->base.type = &fourwire_fourwire_type; - common_hal_fourwire_fourwire_construct(bus, - spi, - &pin_GPIO46, // EPD_DC Command or data - &pin_GPIO45, // EPD_CS Chip select - &pin_GPIO47, // EPD_RST Reset - 1000000, // Baudrate - 0, // Polarity - 0); // Phase - - // Set up EPD object - epaperdisplay_epaperdisplay_obj_t *display = &allocate_display()->epaper_display; - display->base.type = &epaperdisplay_epaperdisplay_type; - common_hal_epaperdisplay_epaperdisplay_construct(display, - bus, - start_sequence, - sizeof(start_sequence), - 0, // start up time - stop_sequence, - sizeof(stop_sequence), - WIDTH, // width - HEIGHT, // height - 300, // RAM width - 400, // RAM height - 0, // colstart - 0, // rowstart - 90, // rotation - NO_COMMAND, // set_column_window_command - NO_COMMAND, // set_row_window_command - 0x4E, // set_current_column_command - 0x4F, // set_current_row_command - 0x24, // write_black_ram_command - false, // black_bits_inverted - 0x26, // write_color_ram_command (can add this for grayscale eventually) - false, // color_bits_inverted - 0x000000, // highlight_color - refresh_sequence, // refresh_display_sequence - sizeof(refresh_sequence), - 40, // refresh_time - &pin_GPIO48, // busy_pin - false, // busy_state - 5, // seconds_per_frame - false, // chip_select (don't always toggle chip select) - false, // grayscale - false, // acep - false, // two_byte_sequence_length - false); // address_little_endian -} - -void board_deinit(void) { - epaperdisplay_epaperdisplay_obj_t *display = &displays[0].epaper_display; - if (display->base.type == &epaperdisplay_epaperdisplay_type) { - while (common_hal_epaperdisplay_epaperdisplay_get_busy(display)) { - RUN_BACKGROUND_TASKS; - } - } - common_hal_displayio_release_displays(); -} - -// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/mpconfigboard.mk b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/mpconfigboard.mk index c82057038b73b..5b6e293439c64 100644 --- a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/mpconfigboard.mk +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/mpconfigboard.mk @@ -9,7 +9,7 @@ CIRCUITPY_ESP_USB_SERIAL_JTAG = 0 IDF_TARGET = esp32s3 CIRCUITPY_ESP_FLASH_SIZE = 8MB -CIRCUITPY_ESP_FLASH_MODE = dio +CIRCUITPY_ESP_FLASH_MODE = qio CIRCUITPY_ESP_FLASH_FREQ = 80m CIRCUITPY_ESP_PSRAM_SIZE = 8MB diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/sdkconfig b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/sdkconfig index a71099850d5ff..e962866216039 100644 --- a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/sdkconfig +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/sdkconfig @@ -7,7 +7,6 @@ # # LWIP # -CONFIG_ESP_PHY_ENABLE_USB=n # end of LWIP # end of Component config From 8eee1fdcbf85f350c9b988fca1fa3293705d81ec Mon Sep 17 00:00:00 2001 From: Sean Murphy Date: Thu, 27 Feb 2025 13:17:21 -0400 Subject: [PATCH 10/11] functional epd --- .../elecrow_crowpanel_4_2_epaper/board.c | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c index a3a9eec047145..8a52f9c0cf375 100644 --- a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c @@ -5,5 +5,108 @@ // SPDX-License-Identifier: MIT #include "supervisor/board.h" +#include "mpconfigboard.h" +#include "shared-bindings/busio/SPI.h" +#include "shared-bindings/fourwire/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/digitalio/DigitalInOut.h" + +const uint8_t display_start_sequence[] = { + // Init + 0x12, 0x80, 0x0a, // Soft reset + 0x01, 0x03, 0x2b, 0x01, 0x00, // Set MUX as 300 + 0x21, 0x02, 0x40, 0x00, // Display update control + 0x3c, 0x01, 0x01, // Border waveform + 0x11, 0x01, 0x03, // X- mode + 0x44, 0x02, 0x00, 0x31, // Set RAM X Address Start/End Pos + 0x45, 0x04, 0x00, 0x00, 0x2b, 0x01, // Set RAM Y Address Start/End Pos + 0x4e, 0x01, 0x00, // Set RAM X Address counter + 0x4f, 0x02, 0x00, 0x00, // Set RAM Y Address counter +}; + +const uint8_t display_stop_sequence[] = { + 0x10, 0x01, 0x32, +}; + +const uint8_t refresh_sequence[] = { + 0x22, 0x01, 0xf7, // Display update sequence option + 0x20, 0x80, 0x0a, // Master activation +}; + +void board_init(void) { + + // Enable EPD with driver pin + digitalio_digitalinout_obj_t epd_enable_pin_obj; + epd_enable_pin_obj.base.type = &digitalio_digitalinout_type; + common_hal_digitalio_digitalinout_construct(&epd_enable_pin_obj, &pin_GPIO7); + common_hal_digitalio_digitalinout_switch_to_output(&epd_enable_pin_obj, true, DRIVE_MODE_PUSH_PULL); + common_hal_digitalio_digitalinout_never_reset(&epd_enable_pin_obj); + + // Set up the SPI object used to control the display + fourwire_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); + + // Set up the DisplayIO pin object + bus->base.type = &fourwire_fourwire_type; + common_hal_fourwire_fourwire_construct(bus, + spi, + &pin_GPIO46, // EPD_DC Command or data + &pin_GPIO45, // EPD_CS Chip select + &pin_GPIO47, // EPD_RST Reset + 1000000, // Baudrate + 0, // Polarity + 0); // Phase + +// Set up the DisplayIO epaper object + epaperdisplay_epaperdisplay_obj_t *display = &allocate_display()->epaper_display; + display->base.type = &epaperdisplay_epaperdisplay_type; + common_hal_epaperdisplay_epaperdisplay_construct( + display, + bus, + display_start_sequence, sizeof(display_start_sequence), + 1, // start up time + display_stop_sequence, sizeof(display_stop_sequence), + 400, // width + 300, // height + 400, // ram_width + 300, // ram_height + 0, // colstart + 0, // rowstart + 0, // 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 + 0x24, // write_black_ram_command + false, // black_bits_inverted + 0x26, // write_color_ram_command + false, // color_bits_inverted + 0x000000, // highlight_color + refresh_sequence, sizeof(refresh_sequence), // refresh_display_command + 1.0, // refresh_time + &pin_GPIO48, // busy_pin + true, // busy_state + 2.0, // seconds_per_frame + false, // always_toggle_chip_select + false, // grayscale + false, // acep + false, // two_byte_sequence_length + false); // address_little_endian +} + +void board_deinit(void) { + epaperdisplay_epaperdisplay_obj_t *display = &displays[0].epaper_display; + if (display->base.type == &epaperdisplay_epaperdisplay_type) { + while (common_hal_epaperdisplay_epaperdisplay_get_busy(display)) { + RUN_BACKGROUND_TASKS; + } + } + common_hal_displayio_release_displays(); +} // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. From 5ae46897fec0dc70ee229686eb6c80bf8d02e350 Mon Sep 17 00:00:00 2001 From: Sean Murphy Date: Thu, 27 Feb 2025 13:30:35 -0400 Subject: [PATCH 11/11] update comments --- ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c index 8a52f9c0cf375..4567e2c595627 100644 --- a/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c +++ b/ports/espressif/boards/elecrow_crowpanel_4_2_epaper/board.c @@ -14,6 +14,7 @@ #include "shared-bindings/board/__init__.h" #include "shared-bindings/digitalio/DigitalInOut.h" +// SSD1683 EPD Driver chip const uint8_t display_start_sequence[] = { // Init 0x12, 0x80, 0x0a, // Soft reset