From 20bec60fe01c3f93c4e61cdb236f9a7d97f89d7b Mon Sep 17 00:00:00 2001 From: Benjamin Shockley Date: Sat, 18 Jan 2025 19:51:53 -0600 Subject: [PATCH 1/5] Create board.c --- .../waveshare_esp32_c6_lcd_1_47/board.c | 149 ++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/board.c diff --git a/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/board.c b/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/board.c new file mode 100644 index 0000000000000..e0bbb0175e381 --- /dev/null +++ b/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/board.c @@ -0,0 +1,149 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2025 Benjamin Shockley +// +// SPDX-License-Identifier: MIT + +#include "supervisor/board.h" +#include "mpconfigboard.h" +#include "shared-bindings/microcontroller/Pin.h" +#include "shared-module/displayio/__init__.h" +#include "shared-module/displayio/mipi_constants.h" + +#define DELAY 0x80 + +// Driver is ST7789V3 +// Display Panel is LBS147TC-IF15 +// 172 X 320 Pixels RGB 18-bit + +uint8_t display_init_sequence[] = { + // (0x01) SW Reset + // The display module performs a software reset, registers are written with their SW reset default values. No parameters. + // ST7789V3 requirement is to wait 120msec before sending sleep out command. + 0x01, 0 | DELAY, 120, + // (0x11) Sleep Out + // This command turns off sleep mode. + // ST7789V3 requirement is to wait 120msec before sending sleep in command and wait 5msec before sending any new commands. No parameters. + 0x11, 0 | DELAY, 120, + // (0x13) Normal Display Mode On + // This command turns the display to normal mode. No parameters. + 0x13, 0, + // Display and Color Format Settings + // + // (0x36) Memory Data Access Control + // LBS147TC-IF15 as Mounted on the board is in Horizontal Mode + // This command defines read/ write scanning direction of frame memory. 1 parameter. + 0x36, 1, 0x00, + // (0x3A) Interface Pixel Format + // This command is used to define the format of RGB picture data. 1 parameter. Value of 0x05 is setting the display to 16-bit (5,6,5). Could do 18-bit + // but may not really see the benefit and costs much more memory. + 0x3A, 1 | DELAY, 0x05, 10, + // (0xB2) Porch Setting + // These 5 parameters front and backporch buffer sizes as well as enabling separate front and back control. Default value provided. + 0xB2, 5, 0x0C, 0x0C, 0x00, 0x33, 0x33, + // (0xB7) Gate Voltage Control + // VGHS and VGLS settings. 1 paramter contains both. Per LBS147TC-IF15 spec; 12.2 < VGH < 14.97 (13.58) and12.5 < VGL <7.16 9.83 + 0xB7, 1, 0x35, + // (0xBB) VCOMS Setting + // VCOMS is used for feed through voltage compensation. Default value provided. + 0xBB, 1, 0x20, + // (0xC0) LCM Control + // Various bits to control modes. 1 paramter. Value taken from Waveshare's own Arduino example LCD init code. + 0xC0, 1, 0x2C, + // (0xC2) VDV and VRH Command Enable + // VDV and VRH command write enable. 2 paramters. Default values provided. + 0xC2, 2, 0x01, 0xFF, + // (0xC3) VRH Set + // 1 parameter. Value taken from Waveshare's own Arduino example LCD init code. + 0xC3, 1, 0x13, + // (0xC4) VDV Set + // 1 parameter. Value taken from Waveshare's own Arduino example LCD init code. + 0xC4, 1, 0x20, + // (0xC6) Frame Rate Control in Normal Mode + // Frame rate value betwee 119 and 39 Hz. Default value is 60 Hz - uses values from 0xB2 as well. See manual. Default value provided. + 0xC6, 1, 0x0F, + // (0xD0) Power Control 1 + // Sets AVDD, AVCL, and VDS voltages. 2 parameters. Values taken from Waveshare's own Arduino example LCD init code. + 0xD0, 2, 0xA4, 0xA1, + // ST7789V gamma setting + // (0xE0) Positive Voltage Gamma Control + // 14 parameters. Values taken from Waveshare's own Arduino example LCD init code. + 0xE0, 14, 0xF0, 0x00, 0x04, 0x04, 0x04, 0x05, 0x29, 0x33, 0x3E, 0x38, 0x12, 0x12, 0x28, 0x30, + // (0xE1) Negative Voltage Gamma Control + // 14 parameters. Values taken from Waveshare's own Arduino example LCD init code. + 0xE1, 14, 0xF0, 0x07, 0x0A, 0x0D, 0x0B, 0x07, 0x28, 0x33, 0x3E, 0x36, 0x14, 0x14, 0x29, 0x32, + // (0x21) Display Inversion On + // This command is used to recover from display inversion mode. No parameters. + 0x21, 0, + // (0x29) Display On + // This command is used to recover from DISPLAY OFF mode. No parameters. + 0x29, 0 | DELAY, 255, +}; + +static void display_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_GPIO7, // CLK + &pin_GPIO6, // MOSI + NULL, // MISO not connected + false); // Not half-duplex + + common_hal_busio_spi_never_reset(spi); + + bus->base.type = &fourwire_fourwire_type; + + common_hal_fourwire_fourwire_construct( + bus, + spi, + &pin_GPIO15, // DC + &pin_GPIO14, // CS + &pin_GPIO21, // RST + 80000000, // baudrate + 0, // polarity + 0 // phase + ); + + busdisplay_busdisplay_obj_t *display = &allocate_display()->display; + display->base.type = &busdisplay_busdisplay_type; + + common_hal_busdisplay_busdisplay_construct( + display, + bus, + 172, // width (after rotation) + 320, // height (after rotation) + 34, // 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), + &pin_GPIO22, // backlight pin + NO_BRIGHTNESS_COMMAND, + 1.0f, // brightness + false, // single_byte_bounds + false, // data_as_commands + true, // auto_refresh + 60, // native_frames_per_second + true, // backlight_on_high + false, // SH1107_addressing + 50000 // backlight pwm frequency + ); +} + +void board_init(void) { + // Display + display_init(); +} + +// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. From 87dd04fe54fae38675008f8e21748ba5ec623bb1 Mon Sep 17 00:00:00 2001 From: Benjamin Shockley Date: Sat, 18 Jan 2025 19:52:13 -0600 Subject: [PATCH 2/5] Adding initial files --- .../mpconfigboard.h | 32 +++++++++++ .../mpconfigboard.mk | 8 +++ .../boards/waveshare_esp32_c6_lcd_1_47/pins.c | 57 +++++++++++++++++++ .../waveshare_esp32_c6_lcd_1_47/sdkconfig | 14 +++++ 4 files changed, 111 insertions(+) create mode 100644 ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.h create mode 100644 ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.mk create mode 100644 ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/pins.c create mode 100644 ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/sdkconfig diff --git a/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.h b/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.h new file mode 100644 index 0000000000000..0bda0edafba13 --- /dev/null +++ b/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.h @@ -0,0 +1,32 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2025 Benjamin Shockley +// +// SPDX-License-Identifier: MIT + +#pragma once + +// Micropython setup + +#define MICROPY_HW_BOARD_NAME "Waveshare ESP32-C6 LCD 1.47" +#define MICROPY_HW_MCU_NAME "ESP32-C6FH4" + +#define MICROPY_HW_NEOPIXEL (&pin_GPIO8) + +// I2C +#define CIRCUITPY_BOARD_I2C (1) +#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO0, .sda = &pin_GPIO1}} + +// SPI +#define CIRCUITPY_BOARD_SPI (1) +#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO7, .mosi = &pin_GPIO6, .miso = &pin_GPIO5}} + +// TXD0 and RXD0 +#define CIRCUITPY_BOARD_UART (1) +#define CIRCUITPY_BOARD_UART_PIN {{.tx = &pin_GPIO16, .rx = &pin_GPIO17}} + +// For entering safe mode, use BOOT button +#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO9) + +// Explanation of how a user got into safe mode +#define BOARD_USER_SAFE_MODE_ACTION MP_ERROR_TEXT("You pressed the BOOT button at start up.") \ No newline at end of file diff --git a/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.mk b/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.mk new file mode 100644 index 0000000000000..4804383e4e937 --- /dev/null +++ b/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.mk @@ -0,0 +1,8 @@ +CIRCUITPY_CREATOR_ID = 0x1BBB0000 +CIRCUITPY_CREATION_ID = 0x00C60002 + +IDF_TARGET = esp32c6 + +CIRCUITPY_ESP_FLASH_MODE = qio +CIRCUITPY_ESP_FLASH_FREQ = 80m +CIRCUITPY_ESP_FLASH_SIZE = 4MB \ No newline at end of file diff --git a/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/pins.c b/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/pins.c new file mode 100644 index 0000000000000..698ad6785e504 --- /dev/null +++ b/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/pins.c @@ -0,0 +1,57 @@ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2025 Benjamin Shockley +// +// SPDX-License-Identifier: MIT + +#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_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO0) }, + + { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_GPIO1) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO1) }, + + { MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO2) }, + { MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) }, + + { MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO3) }, + { MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) }, + + { MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_GPIO4) }, + { MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) }, + + { MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) }, + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO5) }, + + { MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) }, + + { 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_IO23), MP_ROM_PTR(&pin_GPIO23) }, + + { MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_IO17), MP_ROM_PTR(&pin_GPIO17) }, + + { MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO16) }, + { MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) }, + + // Frome Board Definitions + { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO8) }, + { 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); diff --git a/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/sdkconfig b/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/sdkconfig new file mode 100644 index 0000000000000..bf83b68a7c7f4 --- /dev/null +++ b/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/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 \ No newline at end of file From bcef69b7a66211a7b87efcd4e5347503f3c9e767 Mon Sep 17 00:00:00 2001 From: Benjamin Shockley Date: Sat, 18 Jan 2025 20:33:40 -0600 Subject: [PATCH 3/5] Update sdkconfig Added new line at end of file. --- ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/sdkconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/sdkconfig b/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/sdkconfig index bf83b68a7c7f4..2013f109c2fac 100644 --- a/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/sdkconfig +++ b/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/sdkconfig @@ -11,4 +11,4 @@ # end of Component config -# end of Espressif IoT Development Framework Configuration \ No newline at end of file +# end of Espressif IoT Development Framework Configuration From 252ebec929fbef023f8c99e5a423cb72b8667d56 Mon Sep 17 00:00:00 2001 From: Benjamin Shockley Date: Sat, 18 Jan 2025 21:15:39 -0600 Subject: [PATCH 4/5] Update mpconfigboard.h --- .../boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.h b/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.h index 0bda0edafba13..254e3dc37045f 100644 --- a/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.h +++ b/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.h @@ -29,4 +29,4 @@ #define CIRCUITPY_BOOT_BUTTON (&pin_GPIO9) // Explanation of how a user got into safe mode -#define BOARD_USER_SAFE_MODE_ACTION MP_ERROR_TEXT("You pressed the BOOT button at start up.") \ No newline at end of file +#define BOARD_USER_SAFE_MODE_ACTION MP_ERROR_TEXT("You pressed the BOOT button at start up.") From c8749b8be9be292bc0bd4312a43e6ffa85b252df Mon Sep 17 00:00:00 2001 From: Benjamin Shockley Date: Sat, 18 Jan 2025 21:16:22 -0600 Subject: [PATCH 5/5] Update mpconfigboard.mk --- .../boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.mk b/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.mk index 4804383e4e937..5e605633bd081 100644 --- a/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.mk +++ b/ports/espressif/boards/waveshare_esp32_c6_lcd_1_47/mpconfigboard.mk @@ -5,4 +5,4 @@ IDF_TARGET = esp32c6 CIRCUITPY_ESP_FLASH_MODE = qio CIRCUITPY_ESP_FLASH_FREQ = 80m -CIRCUITPY_ESP_FLASH_SIZE = 4MB \ No newline at end of file +CIRCUITPY_ESP_FLASH_SIZE = 4MB