Skip to content

Commit c6da0a4

Browse files
authored
Merge pull request #9316 from bablokb/sunton_3.2in_cyd
added board Sunton 3.2in ESP32 240x320 capacitive touch display
2 parents 64e4648 + 1259682 commit c6da0a4

File tree

5 files changed

+211
-0
lines changed

5 files changed

+211
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "supervisor/board.h"
8+
#include "mpconfigboard.h"
9+
#include "shared-bindings/busio/SPI.h"
10+
#include "shared-bindings/fourwire/FourWire.h"
11+
#include "shared-bindings/microcontroller/Pin.h"
12+
#include "shared-module/displayio/__init__.h"
13+
#include "shared-bindings/board/__init__.h"
14+
#include "supervisor/shared/board.h"
15+
16+
#include "shared-module/displayio/mipi_constants.h"
17+
#include "components/driver/gpio/include/driver/gpio.h"
18+
#include "components/hal/include/hal/gpio_hal.h"
19+
#include "common-hal/microcontroller/Pin.h"
20+
21+
#define DELAY 0x80
22+
23+
// ST7789
24+
uint8_t display_init_sequence[] = {
25+
0x01, 0 | DELAY, 0x96, // _SWRESET and Delay 150ms
26+
0x11, 0 | DELAY, 0xFF, // _SLPOUT and Delay 500ms
27+
0x3A, 0x81, 0x55, 0x0A, // _COLMOD and Delay 10ms
28+
0x36, 0x01, 0x08, // _MADCTL (BGR)
29+
0x21, 0 | DELAY, 0x0A, // _INVON Hack and Delay 10ms
30+
0x13, 0 | DELAY, 0x0A, // _NORON and Delay 10ms
31+
0x36, 0x01, 0xA0, // _MADCTL (Landscape)
32+
0xE0, 0x0E, 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x32, 0x44,
33+
0x42, 0x06, 0x0E, 0x12, 0x14, 0x17, // gamma-curve positive
34+
0xE1, 0x0E, 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x31, 0x54,
35+
0x47, 0x0E, 0x1C, 0x17, 0x1B, 0x1E, // gamma-curve negative
36+
0x29, 0 | DELAY, 0xFF, // _DISPON and Delay 500ms
37+
};
38+
39+
static void display_init(void) {
40+
busio_spi_obj_t *spi = common_hal_board_create_spi(0);
41+
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
42+
bus->base.type = &fourwire_fourwire_type;
43+
44+
common_hal_fourwire_fourwire_construct(
45+
bus,
46+
spi,
47+
&pin_GPIO2, // TFT_DC
48+
&pin_GPIO15, // TFT_CS
49+
NULL, // TFT_RST
50+
26600000, // Baudrate
51+
0, // Polarity
52+
0 // Phase
53+
);
54+
55+
busdisplay_busdisplay_obj_t *display = &allocate_display()->display;
56+
display->base.type = &busdisplay_busdisplay_type;
57+
58+
common_hal_busdisplay_busdisplay_construct(display,
59+
bus,
60+
320, // Width
61+
240, // Height
62+
0, // column start
63+
0, // row start
64+
0, // rotation
65+
16, // Color depth
66+
false, // Grayscale
67+
false, // pixels in a byte share a row. Only valid for depths < 8
68+
1, // bytes per cell. Only valid for depths < 8
69+
false, // reverse_pixels_in_byte. Only valid for depths < 8
70+
true, // reverse_pixels_in_word
71+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
72+
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
73+
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command
74+
display_init_sequence,
75+
sizeof(display_init_sequence),
76+
&pin_GPIO27, // backlight pin
77+
NO_BRIGHTNESS_COMMAND,
78+
1.0f, // brightness
79+
false, // single_byte_bounds
80+
false, // data_as_commands
81+
true, // auto_refresh
82+
60, // native_frames_per_second
83+
true, // backlight_on_high
84+
false, // SH1107_addressing
85+
50000); // backlight pwm frequency
86+
}
87+
88+
void board_init(void) {
89+
display_init();
90+
}
91+
92+
bool espressif_board_reset_pin_number(gpio_num_t pin_number) {
93+
// Pull the speaker pin low to reduce noise on reset
94+
if (pin_number == 26) {
95+
// Turn on audio
96+
gpio_set_direction(pin_number, GPIO_MODE_DEF_OUTPUT);
97+
gpio_set_level(pin_number, false);
98+
return true;
99+
}
100+
return false;
101+
}
102+
103+
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#pragma once
8+
9+
// Micropython setup
10+
11+
#define MICROPY_HW_BOARD_NAME "sunton_esp32_2432S032C"
12+
#define MICROPY_HW_MCU_NAME "ESP32"
13+
#define MICROPY_HW_LED_STATUS (&pin_GPIO16)
14+
#define MICROPY_HW_LED_STATUS_INVERTED (1)
15+
16+
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
17+
18+
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO21)
19+
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO22)
20+
21+
#define CIRCUITPY_BOARD_SPI (2)
22+
#define CIRCUITPY_BOARD_SPI_PIN { \
23+
{.clock = &pin_GPIO14, .mosi = &pin_GPIO13, .miso = &pin_GPIO12}, /*LCD*/ \
24+
{.clock = &pin_GPIO18, .mosi = &pin_GPIO23, .miso = &pin_GPIO19}, /*SD*/ \
25+
}
26+
27+
#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO1)
28+
#define CIRCUITPY_CONSOLE_UART_RX (&pin_GPIO3)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CIRCUITPY_CREATOR_ID = 0x19991000
2+
CIRCUITPY_CREATION_ID = 0x00AA032C
3+
4+
IDF_TARGET = esp32
5+
6+
CIRCUITPY_ESP_FLASH_MODE = qio
7+
CIRCUITPY_ESP_FLASH_FREQ = 40m
8+
CIRCUITPY_ESP_FLASH_SIZE = 4MB
9+
10+
CIRCUITPY_ESPCAMERA = 0
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// This file is part of the CircuitPython project: https://circuitpython.org
2+
//
3+
// SPDX-FileCopyrightText: Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
4+
//
5+
// SPDX-License-Identifier: MIT
6+
7+
#include "shared-bindings/board/__init__.h"
8+
#include "shared-module/displayio/__init__.h"
9+
10+
CIRCUITPY_BOARD_BUS_SINGLETON(lcd_spi, spi, 0)
11+
CIRCUITPY_BOARD_BUS_SINGLETON(sd_spi, spi, 1)
12+
13+
static const mp_rom_map_elem_t board_module_globals_table[] = {
14+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
15+
16+
// Boot button
17+
{ MP_ROM_QSTR(MP_QSTR_BOOT0), MP_ROM_PTR(&pin_GPIO0) },
18+
{ MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO0) },
19+
20+
// RGB LED
21+
{ MP_ROM_QSTR(MP_QSTR_LED_GREEN), MP_ROM_PTR(&pin_GPIO16) },
22+
{ MP_ROM_QSTR(MP_QSTR_LED_RED), MP_ROM_PTR(&pin_GPIO4) },
23+
{ MP_ROM_QSTR(MP_QSTR_LED_BLUE), MP_ROM_PTR(&pin_GPIO17) },
24+
25+
// CDS Light sensor (Not present on all boards)
26+
{ MP_ROM_QSTR(MP_QSTR_LDR), MP_ROM_PTR(&pin_GPIO34) },
27+
28+
// Speaker pin
29+
{ MP_ROM_QSTR(MP_QSTR_SPEAKER), MP_ROM_PTR(&pin_GPIO26) },
30+
31+
// User available GPIOs:
32+
// P3 pin 1 and CN1 pin 2, shared with touch-interrupt and SDA
33+
{ MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) },
34+
// P3 pin 2 and CN1 pin 3, shared with SCL
35+
{ MP_ROM_QSTR(MP_QSTR_IO22), MP_ROM_PTR(&pin_GPIO22) },
36+
// P3 pin 3, input only
37+
{ MP_ROM_QSTR(MP_QSTR_IO35), MP_ROM_PTR(&pin_GPIO35) },
38+
39+
// I2C
40+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO21) },
41+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO22) },
42+
43+
// TF card slot (SPI)
44+
{ MP_ROM_QSTR(MP_QSTR_SD_MOSI), MP_ROM_PTR(&pin_GPIO23) },
45+
{ MP_ROM_QSTR(MP_QSTR_SD_MISO), MP_ROM_PTR(&pin_GPIO19) },
46+
{ MP_ROM_QSTR(MP_QSTR_SD_SCK), MP_ROM_PTR(&pin_GPIO18) },
47+
{ MP_ROM_QSTR(MP_QSTR_SD_CS), MP_ROM_PTR(&pin_GPIO5) },
48+
49+
// ST7789 (SPI)
50+
{ MP_ROM_QSTR(MP_QSTR_LCD_MOSI), MP_ROM_PTR(&pin_GPIO13) },
51+
{ MP_ROM_QSTR(MP_QSTR_LCD_MISO), MP_ROM_PTR(&pin_GPIO12) },
52+
{ MP_ROM_QSTR(MP_QSTR_LCD_SCK), MP_ROM_PTR(&pin_GPIO14) },
53+
{ MP_ROM_QSTR(MP_QSTR_LCD_CS), MP_ROM_PTR(&pin_GPIO15) },
54+
{ MP_ROM_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_GPIO2) },
55+
{ MP_ROM_QSTR(MP_QSTR_LCD_BCKL), MP_ROM_PTR(&pin_GPIO27) },
56+
57+
// GT911 (I2C)
58+
{ MP_ROM_QSTR(MP_QSTR_TOUCH_SDA), MP_ROM_PTR(&pin_GPIO33) },
59+
{ MP_ROM_QSTR(MP_QSTR_TOUCH_SCL), MP_ROM_PTR(&pin_GPIO32) },
60+
{ MP_ROM_QSTR(MP_QSTR_TOUCH_RST), MP_ROM_PTR(&pin_GPIO25) },
61+
{ MP_ROM_QSTR(MP_QSTR_TOUCH_INT), MP_ROM_PTR(&pin_GPIO21) },
62+
63+
// objects
64+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
65+
{ MP_ROM_QSTR(MP_QSTR_LCD_SPI), MP_ROM_PTR(&board_lcd_spi_obj) },
66+
{ MP_ROM_QSTR(MP_QSTR_SD_SPI), MP_ROM_PTR(&board_sd_spi_obj) },
67+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display) },
68+
69+
};
70+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

ports/espressif/boards/sunton_esp32_2432S032C/sdkconfig

Whitespace-only changes.

0 commit comments

Comments
 (0)