Skip to content

Commit 32964f8

Browse files
committed
initial commit
1 parent ba3d7ab commit 32964f8

File tree

5 files changed

+248
-0
lines changed

5 files changed

+248
-0
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "supervisor/board.h"
28+
#include "mpconfigboard.h"
29+
#include "shared-bindings/board/__init__.h"
30+
#include "shared-bindings/microcontroller/Pin.h"
31+
#include "shared-module/displayio/__init__.h"
32+
#include "shared-module/displayio/mipi_constants.h"
33+
#include "components/driver/gpio/include/driver/gpio.h"
34+
#include "components/hal/include/hal/gpio_hal.h"
35+
#include "common-hal/microcontroller/Pin.h"
36+
37+
38+
uint8_t display_init_sequence[] = {
39+
0x01, 0x80, 0x80, // # Software reset then delay 0x80 (128ms)
40+
0xEF, 0x03, 0x03, 0x80, 0x02,
41+
0xCF, 0x03, 0x00, 0xC1, 0x30,
42+
0xED, 0x04, 0x64, 0x03, 0x12, 0x81,
43+
0xE8, 0x03, 0x85, 0x00, 0x78,
44+
0xCB, 0x05, 0x39, 0x2C, 0x00, 0x34, 0x02,
45+
0xF7, 0x01, 0x20,
46+
0xEA, 0x02, 0x00, 0x00,
47+
0xc0, 0x01, 0x23, // # Power control VRH[5:0]
48+
0xc1, 0x01, 0x10, // # Power control SAP[2:0];BT[3:0]
49+
0xc5, 0x02, 0x3e, 0x28, // # VCM control
50+
0xc7, 0x01, 0x86, // # VCM control2
51+
0x36, 0x01, 0x38, // # Memory Access Control
52+
0x37, 0x01, 0x00, // # Vertical scroll zero
53+
0x3a, 0x01, 0x55, // # COLMOD: Pixel Format Set
54+
0xb1, 0x02, 0x00, 0x18, // # Frame Rate Control (In Normal Mode/Full Colors)
55+
0xb6, 0x03, 0x08, 0x82, 0x27, // # Display Function Control
56+
0xF2, 0x01, 0x00, // # 3Gamma Function Disable
57+
0x26, 0x01, 0x01, // # Gamma curve selected
58+
0xe0, 0x0f, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00, // # Set Gamma
59+
0xe1, 0x0f, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F, // # Set Gamma
60+
0x11, 0x80, 0x48, // # Exit Sleep then delay
61+
0x29, 0x80, 0x78, // # Display on then delay 0x78 (120ms)
62+
};
63+
64+
static void display_init(void) {
65+
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
66+
busio_spi_obj_t *spi = &bus->inline_bus;
67+
common_hal_busio_spi_construct(spi, &pin_GPIO14, &pin_GPIO13, &pin_GPIO12, false);
68+
common_hal_busio_spi_never_reset(spi);
69+
70+
bus->base.type = &fourwire_fourwire_type;
71+
common_hal_fourwire_fourwire_construct(bus,
72+
spi,
73+
&pin_GPIO2, // TFT_DC Command or data
74+
&pin_GPIO15, // TFT_CS Chip select
75+
NULL, // TFT_RST Reset
76+
6000000, // Baudrate
77+
0, // Polarity
78+
0); // Phase
79+
80+
busdisplay_busdisplay_obj_t *display = &allocate_display()->display;
81+
display->base.type = &busdisplay_busdisplay_type;
82+
common_hal_busdisplay_busdisplay_construct(display,
83+
bus,
84+
320, // Width
85+
240, // Height
86+
0, // column start
87+
0, // row start
88+
0, // rotation
89+
16, // Color depth
90+
false, // Grayscale
91+
false, // pixels in a byte share a row. Only valid for depths < 8
92+
1, // bytes per cell. Only valid for depths < 8
93+
false, // reverse_pixels_in_byte. Only valid for depths < 8
94+
true, // reverse_pixels_in_word
95+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
96+
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
97+
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command
98+
display_init_sequence,
99+
sizeof(display_init_sequence),
100+
&pin_GPIO21, // backlight pin
101+
NO_BRIGHTNESS_COMMAND,
102+
1.0f, // brightness
103+
false, // single_byte_bounds
104+
false, // data_as_commands
105+
true, // auto_refresh
106+
60, // native_frames_per_second
107+
true, // backlight_on_high
108+
false, // SH1107_addressing
109+
50000); // backlight pwm frequency
110+
}
111+
112+
void board_init(void) {
113+
display_init();
114+
}
115+
116+
bool espressif_board_reset_pin_number(gpio_num_t pin_number) {
117+
// Pull the speaker pin low to reduce noise on reset
118+
if (pin_number == 26) {
119+
// Turn on TFT
120+
gpio_set_direction(pin_number, GPIO_MODE_DEF_OUTPUT);
121+
gpio_set_level(pin_number, false);
122+
return true;
123+
}
124+
return false;
125+
}
126+
127+
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2022 Dan Halbert for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
// Micropython setup
28+
29+
#define MICROPY_HW_BOARD_NAME "sunton_esp32_2432S028"
30+
#define MICROPY_HW_MCU_NAME "ESP32"
31+
#define MICROPY_HW_LED_STATUS (&pin_GPIO17)
32+
33+
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
34+
35+
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO27)
36+
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO22)
37+
38+
#define CIRCUITPY_BOARD_SPI (3)
39+
#define CIRCUITPY_BOARD_SPI_PIN { \
40+
{.clock = &pin_GPIO18, .mosi = &pin_GPIO23, .miso = &pin_GPIO19}, /*SD*/ \
41+
{.clock = &pin_GPIO25, .mosi = &pin_GPIO32, .miso = &pin_GPIO39}, /*TOUCH*/ \
42+
{.clock = &pin_GPIO14, .mosi = &pin_GPIO13, .miso = &pin_GPIO12}, /*LCD*/ \
43+
}
44+
45+
#define CIRCUITPY_CONSOLE_UART_TX (&pin_GPIO1)
46+
#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 = 0x00AA0001
3+
4+
IDF_TARGET = esp32
5+
6+
CIRCUITPY_ESP_FLASH_MODE = qio
7+
CIRCUITPY_ESP_FLASH_FREQ = 80m
8+
CIRCUITPY_ESP_FLASH_SIZE = 4MB
9+
10+
CIRCUITPY_ESPCAMERA = 0
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include "shared-bindings/board/__init__.h"
2+
#include "shared-module/displayio/__init__.h"
3+
4+
CIRCUITPY_BOARD_BUS_SINGLETON(sd_spi, spi, 0)
5+
CIRCUITPY_BOARD_BUS_SINGLETON(touch_spi, spi, 1)
6+
CIRCUITPY_BOARD_BUS_SINGLETON(lcd_spi, spi, 2)
7+
8+
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
9+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
10+
11+
// Boot button
12+
{ MP_ROM_QSTR(MP_QSTR_BOOT0), MP_ROM_PTR(&pin_GPIO0) },
13+
{ MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO0) },
14+
15+
// RGB LED
16+
{ MP_ROM_QSTR(MP_QSTR_LED_GREEN), MP_ROM_PTR(&pin_GPIO16) },
17+
{ MP_ROM_QSTR(MP_QSTR_LED_RED), MP_ROM_PTR(&pin_GPIO4) },
18+
{ MP_ROM_QSTR(MP_QSTR_LED_BLUE), MP_ROM_PTR(&pin_GPIO17) },
19+
20+
// CDS Light sensor (Not present on all boards)
21+
{ MP_ROM_QSTR(MP_QSTR_LDR), MP_ROM_PTR(&pin_GPIO34) },
22+
23+
// Speaker pin
24+
{ MP_ROM_QSTR(MP_QSTR_SPEAKER), MP_ROM_PTR(&pin_GPIO26) },
25+
26+
// User available GPIO
27+
{ MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) }, // P3 Pin 4, shared with backlight
28+
{ MP_ROM_QSTR(MP_QSTR_IO22), MP_ROM_PTR(&pin_GPIO22) }, // P3 Pin 3, i2c_scl
29+
{ MP_ROM_QSTR(MP_QSTR_IO27), MP_ROM_PTR(&pin_GPIO27) }, // CN1 Pin 3, i2c_sda
30+
{ MP_ROM_QSTR(MP_QSTR_IO35), MP_ROM_PTR(&pin_GPIO35) }, // P3 Pin 2, input only
31+
32+
// i2c
33+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO27) },
34+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO22) },
35+
36+
// TF card slot
37+
{ MP_ROM_QSTR(MP_QSTR_SD_MOSI), MP_ROM_PTR(&pin_GPIO23) },
38+
{ MP_ROM_QSTR(MP_QSTR_SD_MISO), MP_ROM_PTR(&pin_GPIO19) },
39+
{ MP_ROM_QSTR(MP_QSTR_SD_SCK), MP_ROM_PTR(&pin_GPIO18) },
40+
{ MP_ROM_QSTR(MP_QSTR_SD_CS), MP_ROM_PTR(&pin_GPIO5) },
41+
42+
// ILI9341 dsplay (spi)
43+
{ MP_ROM_QSTR(MP_QSTR_LCD_MOSI), MP_ROM_PTR(&pin_GPIO13) },
44+
{ MP_ROM_QSTR(MP_QSTR_LCD_MISO), MP_ROM_PTR(&pin_GPIO12) },
45+
{ MP_ROM_QSTR(MP_QSTR_LCD_SCK), MP_ROM_PTR(&pin_GPIO14) },
46+
{ MP_ROM_QSTR(MP_QSTR_LCD_CS), MP_ROM_PTR(&pin_GPIO15) },
47+
{ MP_ROM_QSTR(MP_QSTR_LCD_DC), MP_ROM_PTR(&pin_GPIO2) },
48+
{ MP_ROM_QSTR(MP_QSTR_LCD_BCKL), MP_ROM_PTR(&pin_GPIO21) },
49+
50+
// XPT2046 touch (spi)
51+
{ MP_ROM_QSTR(MP_QSTR_TOUCH_MOSI), MP_ROM_PTR(&pin_GPIO32) },
52+
{ MP_ROM_QSTR(MP_QSTR_TOUCH_MISO), MP_ROM_PTR(&pin_GPIO39) },
53+
{ MP_ROM_QSTR(MP_QSTR_TOUCH_SCK), MP_ROM_PTR(&pin_GPIO25) },
54+
{ MP_ROM_QSTR(MP_QSTR_TOUCH_CS), MP_ROM_PTR(&pin_GPIO33) },
55+
{ MP_ROM_QSTR(MP_QSTR_TOUCH_INT), MP_ROM_PTR(&pin_GPIO36) },
56+
57+
// objects
58+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
59+
{ MP_ROM_QSTR(MP_QSTR_SD_SPI), MP_ROM_PTR(&board_sd_spi_obj) },
60+
{ MP_ROM_QSTR(MP_QSTR_LCD_SPI), MP_ROM_PTR(&board_lcd_spi_obj) },
61+
{ MP_ROM_QSTR(MP_QSTR_TOUCH_SPI), MP_ROM_PTR(&board_touch_spi_obj) },
62+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display) },
63+
64+
};
65+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

ports/espressif/boards/sunton_esp32_2432S028/sdkconfig

Whitespace-only changes.

0 commit comments

Comments
 (0)