Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for sunton_esp32_2432S024C board #9238

Closed
Closed
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
127 changes: 127 additions & 0 deletions ports/espressif/boards/sunton_esp32_2432S024C/board.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2024 Chris Drake, 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/board/__init__.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-module/displayio/__init__.h"
#include "shared-module/displayio/mipi_constants.h"
#include "components/driver/gpio/include/driver/gpio.h"
#include "components/hal/include/hal/gpio_hal.h"
#include "common-hal/microcontroller/Pin.h"


uint8_t display_init_sequence[] = {
0x01, 0x80, 0x80, // # Software reset then delay 0x80 (128ms)
0xEF, 0x03, 0x03, 0x80, 0x02,
0xCF, 0x03, 0x00, 0xC1, 0x30,
0xED, 0x04, 0x64, 0x03, 0x12, 0x81,
0xE8, 0x03, 0x85, 0x00, 0x78,
0xCB, 0x05, 0x39, 0x2C, 0x00, 0x34, 0x02,
0xF7, 0x01, 0x20,
0xEA, 0x02, 0x00, 0x00,
0xc0, 0x01, 0x23, // # Power control VRH[5:0]
0xc1, 0x01, 0x10, // # Power control SAP[2:0];BT[3:0]
0xc5, 0x02, 0x3e, 0x28, // # VCM control
0xc7, 0x01, 0x86, // # VCM control2
0x36, 0x01, 0x38, // # Memory Access Control
0x37, 0x01, 0x00, // # Vertical scroll zero
0x3a, 0x01, 0x55, // # COLMOD: Pixel Format Set
0xb1, 0x02, 0x00, 0x18, // # Frame Rate Control (In Normal Mode/Full Colors)
0xb6, 0x03, 0x08, 0x82, 0x27, // # Display Function Control
0xF2, 0x01, 0x00, // # 3Gamma Function Disable
0x26, 0x01, 0x01, // # Gamma curve selected
0xe0, 0x0f, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00, // # Set Gamma
0xe1, 0x0f, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F, // # Set Gamma
0x11, 0x80, 0x48, // # Exit Sleep then delay
0x29, 0x80, 0x78, // # Display on then delay 0x78 (120ms)
};

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_GPIO14, &pin_GPIO13, &pin_GPIO12, false);
common_hal_busio_spi_never_reset(spi);

bus->base.type = &fourwire_fourwire_type;
common_hal_fourwire_fourwire_construct(bus,
spi,
&pin_GPIO2, // TFT_DC Command or data
&pin_GPIO15, // TFT_CS Chip select
NULL, // TFT_RST Reset
6000000, // 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,
320, // Width
240, // Height
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),
&pin_GPIO27, // 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_init();
}

bool espressif_board_reset_pin_number(gpio_num_t pin_number) {
// Pull the speaker pin low to reduce noise on reset
if (pin_number == 26) {
// Turn on TFT
gpio_set_direction(pin_number, GPIO_MODE_DEF_OUTPUT);
gpio_set_level(pin_number, false);
return true;
}
return false;
}

// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
46 changes: 46 additions & 0 deletions ports/espressif/boards/sunton_esp32_2432S024C/mpconfigboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2024 Chris Drake, 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.
*/

// Micropython setup

#define MICROPY_HW_BOARD_NAME "sunton_esp32_2432S024"
#define MICROPY_HW_MCU_NAME "ESP32"
#define MICROPY_HW_LED_STATUS (&pin_GPIO17)

#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)

#define DEFAULT_I2C_BUS_SDA (&pin_GPIO27)
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO22)

#define CIRCUITPY_BOARD_SPI (3)
#define CIRCUITPY_BOARD_SPI_PIN { \
{.clock = &pin_GPIO18, .mosi = &pin_GPIO23, .miso = &pin_GPIO19}, /*SD*/ \
{.clock = &pin_GPIO25, .mosi = &pin_GPIO32, .miso = &pin_GPIO39}, /*TOUCH*/ \
{.clock = &pin_GPIO14, .mosi = &pin_GPIO13, .miso = &pin_GPIO12}, /*LCD*/ \
}

#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO1)
#define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO3)
10 changes: 10 additions & 0 deletions ports/espressif/boards/sunton_esp32_2432S024C/mpconfigboard.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CIRCUITPY_CREATOR_ID = 0x19991000
CIRCUITPY_CREATION_ID = 0x00AA0024

IDF_TARGET = esp32

CIRCUITPY_ESP_FLASH_MODE = qio
CIRCUITPY_ESP_FLASH_FREQ = 80m
CIRCUITPY_ESP_FLASH_SIZE = 4MB

CIRCUITPY_ESPCAMERA = 0
65 changes: 65 additions & 0 deletions ports/espressif/boards/sunton_esp32_2432S024C/pins.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "shared-bindings/board/__init__.h"
#include "shared-module/displayio/__init__.h"

CIRCUITPY_BOARD_BUS_SINGLETON(sd_spi, spi, 0)
CIRCUITPY_BOARD_BUS_SINGLETON(touch_spi, spi, 1)
CIRCUITPY_BOARD_BUS_SINGLETON(lcd_spi, spi, 2)

STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS

// Boot button
{ MP_ROM_QSTR(MP_QSTR_BOOT0), MP_ROM_PTR(&pin_GPIO0) },
{ MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO0) },

// RGB LED
{ MP_ROM_QSTR(MP_QSTR_LED_GREEN), MP_ROM_PTR(&pin_GPIO16) },
{ MP_ROM_QSTR(MP_QSTR_LED_RED), MP_ROM_PTR(&pin_GPIO4) },
{ MP_ROM_QSTR(MP_QSTR_LED_BLUE), MP_ROM_PTR(&pin_GPIO17) },

// CDS Light sensor (Not present on all boards)
{ MP_ROM_QSTR(MP_QSTR_LDR), MP_ROM_PTR(&pin_GPIO34) },

// Speaker pin
{ MP_ROM_QSTR(MP_QSTR_SPEAKER), MP_ROM_PTR(&pin_GPIO26) },

// User available GPIO
{ MP_ROM_QSTR(MP_QSTR_IO27), MP_ROM_PTR(&pin_GPIO27) }, // P3 Pin 4, shared with backlight
{ MP_ROM_QSTR(MP_QSTR_IO22), MP_ROM_PTR(&pin_GPIO22) }, // P3 Pin 3, i2c_scl
{ MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) }, // CN1 Pin 3, i2c_sda
{ MP_ROM_QSTR(MP_QSTR_IO35), MP_ROM_PTR(&pin_GPIO35) }, // P3 Pin 2, input only

// i2c
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO21) },
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO22) },

// TF card slot
{ MP_ROM_QSTR(MP_QSTR_SD_MOSI), MP_ROM_PTR(&pin_GPIO23) },
{ MP_ROM_QSTR(MP_QSTR_SD_MISO), MP_ROM_PTR(&pin_GPIO19) },
{ MP_ROM_QSTR(MP_QSTR_SD_SCK), MP_ROM_PTR(&pin_GPIO18) },
{ MP_ROM_QSTR(MP_QSTR_SD_CS), MP_ROM_PTR(&pin_GPIO5) },

// ILI9341 dsplay (spi)
{ MP_ROM_QSTR(MP_QSTR_LCD_MOSI), MP_ROM_PTR(&pin_GPIO13) }, // 13
{ MP_ROM_QSTR(MP_QSTR_LCD_MISO), MP_ROM_PTR(&pin_GPIO12) }, // 12
{ MP_ROM_QSTR(MP_QSTR_LCD_SCK), MP_ROM_PTR(&pin_GPIO14) }, // 14
{ MP_ROM_QSTR(MP_QSTR_LCD_CS), MP_ROM_PTR(&pin_GPIO15) }, // 15
{ MP_ROM_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_GPIO2) }, // 2
{ MP_ROM_QSTR(MP_QSTR_LCD_BCKL), MP_ROM_PTR(&pin_GPIO27) }, // 27 (was 21 on sunton_esp32_2432S028)

// XPT2046 touch (spi)
{ MP_ROM_QSTR(MP_QSTR_TOUCH_MOSI), MP_ROM_PTR(&pin_GPIO32) },
{ MP_ROM_QSTR(MP_QSTR_TOUCH_MISO), MP_ROM_PTR(&pin_GPIO39) },
{ MP_ROM_QSTR(MP_QSTR_TOUCH_SCK), MP_ROM_PTR(&pin_GPIO25) },
{ MP_ROM_QSTR(MP_QSTR_TOUCH_CS), MP_ROM_PTR(&pin_GPIO33) },
{ MP_ROM_QSTR(MP_QSTR_TOUCH_INT), MP_ROM_PTR(&pin_GPIO36) },

// objects
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_SD_SPI), MP_ROM_PTR(&board_sd_spi_obj) },
{ MP_ROM_QSTR(MP_QSTR_LCD_SPI), MP_ROM_PTR(&board_lcd_spi_obj) },
{ MP_ROM_QSTR(MP_QSTR_TOUCH_SPI), MP_ROM_PTR(&board_touch_spi_obj) },
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display) },

};
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
Empty file.