Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions ports/espressif/boards/waveshare_esp32_c6_touch_lcd_1_47/board.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// 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-bindings/busio/SPI.h"
#include "shared-bindings/fourwire/FourWire.h"
#include "shared-module/displayio/__init__.h"
#include "shared-module/displayio/mipi_constants.h"
#include "shared-bindings/board/__init__.h"

#define DELAY 0x80
// Board used for this commit : https://www.waveshare.com/wiki/ESP32-C6-Touch-LCD-1.47

// Driver is ST7789V3 https://www.waveshare.com/w/upload/a/ad/ST7789VW.pdf
// Display Panel is LBS147TC-IF15
// 172 X 320 Pixels RGB 18-bit

// Init Sequence format
// Addr, seq length, data
uint8_t display_init_sequence[] = {
0x01, 0 | DELAY, 120, // Software Reset - SWRESET
0x11, 0 | DELAY, 120, // Sleep Out - SLPOUT
0x13, 0, // Normal Display Mode ON - NORON
0x36, 1, 0x88, // Memory Data Access Control - MADCTL
//0x3A, 1 | DELAY, 0x05, 10, // Interface Pixel Format - COLMOD 0x05= 16bits/pixel ,0x10
0x3A, 1 | DELAY, 0x55, 10, // Interface Pixel Format - COLMOD 0x05= 16bits/pixel ,0x10
0xB2, 5, 0x0C, 0x0C, 0x00, 0x33, 0x33, // Porch Setting - PORCTRL
0xB7, 1, 0x35, // Gate Control - GCTRL
0xBB, 1, 0x20, // VCOM Setting - VCOMS
0xC0, 1, 0x2C, // LCM Control - LCMCTRL
0xC2, 2, 0x01, 0xFF, // VDV and VRH Command Enable - VDVVRHEN
0xC3, 1, 0x13, // VRH Set - VRHS
0xC4, 1, 0x20, // VDV Set - VDVS
0xC6, 1, 0x0F, // Frame Rate CTRL in Normal Mode - FRCTRL2
0xD0, 2, 0xA4, 0xA1, // Power Control 1 - PWCTRL1
0xE0, 14, 0xF0, 0x00, 0x04, 0x04, 0x04, 0x05, 0x29, 0x33, 0x3E, 0x38, 0x12, 0x12, 0x28, 0x30, // Positive Voltage Gamma Control
0xE1, 14, 0xF0, 0x07, 0x0A, 0x0D, 0x0B, 0x07, 0x28, 0x33, 0x3E, 0x36, 0x14, 0x14, 0x29, 0x32, // Negative Voltage Gamma Control
0x21, 0, // Display Inversion On - INVON
0x29, 0 | DELAY, 255, // Display ON - DISPON
};
// MADCTL D7->D2 = MY,MX,MV,ML,RGB,MH,0,0
// MY = PAge Address ORder 0=Top to Bottom 1= Bottom to Top
// MX = Column Address order 0 = left to right 1 = right to left
// MV = Page column order 0 = Normal 1=Reverse
// ML = Line Address Order 0=Top-Bottom 1=Bottom-top
// RGB 0=RGB 1=BGR
// MH = Display Data Latch Data Order 0=Left2Right 1=Right2LEft
// 0x0C 1100
//
static void display_init(void) {
busio_spi_obj_t *spi = common_hal_board_create_spi(0);
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
bus->base.type = &fourwire_fourwire_type;

common_hal_fourwire_fourwire_construct(
bus,
spi,
&pin_GPIO15, // DC
&pin_GPIO14, // CS
&pin_GPIO22, // RST changed from 21 to 22 for TOUCH version
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
false, // reverse_pixels_in_word
MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command 0x2A
MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command 0x2B
MIPI_COMMAND_WRITE_MEMORY_START, // write memory command 0x2C
display_init_sequence,
sizeof(display_init_sequence),
&pin_GPIO23, // backlight pin from 22 to 23 for TOUCH version
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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 for https://www.waveshare.com/wiki/ESP32-C6-Touch-LCD-1.47

#define MICROPY_HW_BOARD_NAME "Waveshare ESP32-C6 TOUCH LCD 1.47"
#define MICROPY_HW_MCU_NAME "ESP32-C6FH4"

// I2C
#define CIRCUITPY_BOARD_I2C (1)
#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO19, .sda = &pin_GPIO18}}

// SPI
#define CIRCUITPY_BOARD_SPI (1)
#define CIRCUITPY_BOARD_SPI_PIN {{.clock = &pin_GPIO1, .mosi = &pin_GPIO2, .miso = &pin_GPIO3}}

// 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.")
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CIRCUITPY_CREATOR_ID = 0x1BBB0000
CIRCUITPY_CREATION_ID = 0x00C60002
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please grab a new id here for the touch version: https://github.com/creationid/creators/blob/main/creations/waveshare.md


IDF_TARGET = esp32c6

CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB

# Board was originally defined with a 2MB firmware, almost 2MB user filesystem. Leave it that way.
CIRCUITPY_4MB_FLASH_LARGE_USER_FS_LAYOUT = 1
Comment on lines +9 to +11
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this since it is a new board.

80 changes: 80 additions & 0 deletions ports/espressif/boards/waveshare_esp32_c6_touch_lcd_1_47/pins.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// 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"

#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_A0), MP_ROM_PTR(&pin_GPIO0) },
{ MP_ROM_QSTR(MP_QSTR_IO0), 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_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_SD_CS), 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_IMU_INT1), MP_ROM_PTR(&pin_GPIO5) },


{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO3) },

{ MP_ROM_QSTR(MP_QSTR_IO6), MP_ROM_PTR(&pin_GPIO6) },
{ MP_ROM_QSTR(MP_QSTR_IMU_INT2), MP_ROM_PTR(&pin_GPIO6) },


{ MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO7) },

{ MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) },

{ MP_ROM_QSTR(MP_QSTR_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_SDA), MP_ROM_PTR(&pin_GPIO18) },

{ MP_ROM_QSTR(MP_QSTR_IO19), MP_ROM_PTR(&pin_GPIO19) },
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO19) },

{ MP_ROM_QSTR(MP_QSTR_IO20), MP_ROM_PTR(&pin_GPIO20) },

{ MP_ROM_QSTR(MP_QSTR_TOUCH_RST), MP_ROM_PTR(&pin_GPIO20) },
{ MP_ROM_QSTR(MP_QSTR_TOUCH_INT), MP_ROM_PTR(&pin_GPIO21) },


{ 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) },

{ MP_ROM_QSTR(MP_QSTR_TFT_CS), MP_ROM_PTR(&pin_GPIO14) },
{ MP_ROM_QSTR(MP_QSTR_TFT_DC), MP_ROM_PTR(&pin_GPIO15) },
{ MP_ROM_QSTR(MP_QSTR_TFT_RESET), MP_ROM_PTR(&pin_GPIO22) },
{ MP_ROM_QSTR(MP_QSTR_TFT_BACKLIGHT), MP_ROM_PTR(&pin_GPIO21) },

//{ 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_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);
14 changes: 14 additions & 0 deletions ports/espressif/boards/waveshare_esp32_c6_touch_lcd_1_47/sdkconfig
Original file line number Diff line number Diff line change
@@ -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
Loading
Loading