Skip to content

Commit 862210b

Browse files
authored
Merge pull request #6135 from CircuitART/main
merge hexky_s2 board
2 parents beddf9d + 43bd2c4 commit 862210b

File tree

5 files changed

+311
-0
lines changed

5 files changed

+311
-0
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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/busio/SPI.h"
30+
#include "shared-bindings/displayio/FourWire.h"
31+
#include "shared-bindings/microcontroller/Pin.h"
32+
#include "shared-module/displayio/__init__.h"
33+
#include "shared-module/displayio/mipi_constants.h"
34+
#include "shared-bindings/board/__init__.h"
35+
36+
displayio_fourwire_obj_t board_display_obj;
37+
38+
#define DELAY 0x80
39+
40+
// display init sequence according to LilyGO example app
41+
uint8_t display_init_sequence[] = {
42+
// sw reset
43+
0x01, 0 | DELAY, 150,
44+
// sleep out
45+
0x11, 0 | DELAY, 255,
46+
// normal display mode on
47+
0x13, 0,
48+
// display and color format settings
49+
0x36, 1, 0x68,
50+
0xB6, 2, 0x0A, 0x82,
51+
0x3A, 1 | DELAY, 0x55, 10,
52+
// ST7789V frame rate setting
53+
0xB2, 5, 0x0C, 0x0C, 0x00, 0x33, 0x33,
54+
// voltages: VGH / VGL
55+
0xB7, 1, 0x35,
56+
// ST7789V power setting
57+
0xBB, 1, 0x28,
58+
0xC0, 1, 0x0C,
59+
0xC2, 2, 0x01, 0xFF,
60+
0xC3, 1, 0x10,
61+
0xC4, 1, 0x20,
62+
0xC6, 1, 0x0F,
63+
0xD0, 2, 0xA4, 0xA1,
64+
// ST7789V gamma setting
65+
0xE0, 14, 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x32, 0x44, 0x42, 0x06, 0x0E, 0x12, 0x14, 0x17,
66+
0xE1, 14, 0xD0, 0x00, 0x02, 0x07, 0x0A, 0x28, 0x31, 0x54, 0x47, 0x0E, 0x1C, 0x17, 0x1B, 0x1E,
67+
0x21, 0,
68+
// display on
69+
0x29, 0 | DELAY, 255,
70+
};
71+
72+
73+
void board_init(void) {
74+
busio_spi_obj_t *spi = common_hal_board_create_spi(0);
75+
displayio_fourwire_obj_t *bus = &displays[0].fourwire_bus;
76+
bus->base.type = &displayio_fourwire_type;
77+
78+
common_hal_displayio_fourwire_construct(
79+
bus,
80+
spi,
81+
&pin_GPIO34, // DC
82+
&pin_GPIO33, // CS
83+
&pin_GPIO41, // RST
84+
40000000, // baudrate
85+
0, // polarity
86+
0 // phase
87+
);
88+
displayio_display_obj_t *display = &displays[0].display;
89+
display->base.type = &displayio_display_type;
90+
91+
// workaround as board_init() is called before reset_port() in main.c
92+
pwmout_reset();
93+
94+
common_hal_displayio_display_construct(
95+
display,
96+
bus,
97+
240, // width (after rotation)
98+
240, // height (after rotation)
99+
0, // column start
100+
0, // row start
101+
90, // rotation
102+
16, // color depth
103+
false, // grayscale
104+
false, // pixels in a byte share a row. Only valid for depths < 8
105+
1, // bytes per cell. Only valid for depths < 8
106+
false, // reverse_pixels_in_byte. Only valid for depths < 8
107+
true, // reverse_pixels_in_word
108+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // set column command
109+
MIPI_COMMAND_SET_PAGE_ADDRESS, // set row command
110+
MIPI_COMMAND_WRITE_MEMORY_START, // write memory command
111+
display_init_sequence,
112+
sizeof(display_init_sequence),
113+
&pin_GPIO45, // backlight pin
114+
NO_BRIGHTNESS_COMMAND,
115+
1.0f, // brightness (ignored)
116+
false, // auto_brightness
117+
false, // single_byte_bounds
118+
false, // data_as_commands
119+
true, // auto_refresh
120+
60, // native_frames_per_second
121+
true, // backlight_on_high
122+
false // SH1107_addressing
123+
);
124+
125+
common_hal_never_reset_pin(&pin_GPIO45); // backlight pin
126+
}
127+
128+
bool board_requests_safe_mode(void) {
129+
return false;
130+
}
131+
132+
bool espressif_board_reset_pin_number(gpio_num_t pin_number) {
133+
// Override the I2C/TFT power pin reset to prevent resetting the display.
134+
if (pin_number == 21) {
135+
// Turn on TFT and I2C
136+
gpio_set_direction(21, GPIO_MODE_DEF_OUTPUT);
137+
gpio_set_level(21, true);
138+
return true;
139+
}
140+
return false;
141+
}
142+
143+
void reset_board(void) {
144+
}
145+
146+
void board_deinit(void) {
147+
// TODO: Should we turn off the display when asleep?
148+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 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+
// Micropython setup
28+
29+
#define MICROPY_HW_BOARD_NAME "HexKyS2"
30+
#define MICROPY_HW_MCU_NAME "ESP32S2"
31+
32+
#define MICROPY_HW_NEOPIXEL (&pin_GPIO40)
33+
#define CIRCUITPY_STATUS_LED_POWER (&pin_GPIO39)
34+
35+
#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0)
36+
37+
#define BOARD_USER_SAFE_MODE_ACTION translate("pressing boot button at start up.\n")
38+
#define AUTORESET_DELAY_MS 500
39+
40+
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO9)
41+
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO8)
42+
43+
#define DEFAULT_SPI_BUS_SCK (&pin_GPIO36)
44+
#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO35)
45+
#define DEFAULT_SPI_BUS_MISO (&pin_GPIO37)
46+
47+
#define DEFAULT_UART_BUS_RX (&pin_GPIO44)
48+
#define DEFAULT_UART_BUS_TX (&pin_GPIO43)
49+
50+
#define DOUBLE_TAP_PIN (&pin_GPIO38)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
USB_VID = 0x303A
2+
USB_PID = 0x80D9
3+
4+
USB_PRODUCT = "HexKy_S2"
5+
USB_MANUFACTURER = "FutureKeys"
6+
7+
IDF_TARGET = esp32s2
8+
9+
INTERNAL_FLASH_FILESYSTEM = 1
10+
LONGINT_IMPL = MPZ
11+
12+
# The default queue depth of 16 overflows on release builds,
13+
# so increase it to 32.
14+
CFLAGS += -DCFG_TUD_TASK_QUEUE_SZ=32
15+
16+
CIRCUITPY_ESP_FLASH_MODE=qio
17+
CIRCUITPY_ESP_FLASH_FREQ=40m
18+
CIRCUITPY_ESP_FLASH_SIZE=4MB
19+
20+
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include "shared-bindings/board/__init__.h"
2+
3+
#include "shared-module/displayio/__init__.h"
4+
5+
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
6+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
7+
// ANALOG PINS
8+
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO1) },
9+
{ MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO3) },
10+
{ MP_ROM_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_GPIO2) },
11+
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO7) },
12+
{ MP_ROM_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_GPIO17) },
13+
{ MP_ROM_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_GPIO18) },
14+
{ MP_ROM_QSTR(MP_QSTR_DAC1), MP_ROM_PTR(&pin_GPIO17) },
15+
{ MP_ROM_QSTR(MP_QSTR_DAC2), MP_ROM_PTR(&pin_GPIO18) },
16+
// DIGITAL PINS
17+
{ MP_ROM_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_GPIO5) },
18+
{ MP_ROM_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_GPIO6) },
19+
{ MP_ROM_QSTR(MP_QSTR_D4), MP_ROM_PTR(&pin_GPIO4) },
20+
{ MP_ROM_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_GPIO11) },
21+
{ MP_ROM_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_GPIO10) },
22+
{ MP_ROM_QSTR(MP_QSTR_D7), MP_ROM_PTR(&pin_GPIO12) },
23+
{ MP_ROM_QSTR(MP_QSTR_D8), MP_ROM_PTR(&pin_GPIO10) },
24+
// USER Buttons
25+
{ MP_ROM_QSTR(MP_QSTR_SW1), MP_ROM_PTR(&pin_GPIO21) },
26+
{ MP_ROM_QSTR(MP_QSTR_SW2), MP_ROM_PTR(&pin_GPIO42) },
27+
// Not broken out - LED
28+
{ MP_ROM_QSTR(MP_QSTR_D13_LED), MP_ROM_PTR(&pin_GPIO39) },
29+
// Not broken out - NEOPIXEL
30+
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO40) },
31+
// Not broken out - VBAT_SENSE
32+
{ MP_ROM_QSTR(MP_QSTR_VBAT_SENSE), MP_ROM_PTR(&pin_GPIO13) },
33+
// Not broken out - ST7789 LCD PINS
34+
{ MP_ROM_QSTR(MP_QSTR_TFT_CS), MP_ROM_PTR(&pin_GPIO33) },
35+
{ MP_ROM_QSTR(MP_QSTR_TFT_DC), MP_ROM_PTR(&pin_GPIO34) },
36+
{ MP_ROM_QSTR(MP_QSTR_TFT_RST), MP_ROM_PTR(&pin_GPIO41) },
37+
// UART
38+
{ MP_ROM_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_GPIO43) },
39+
{ MP_ROM_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_GPIO44) },
40+
// I2C
41+
{ MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO9) },
42+
{ MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO8) },
43+
// SPI
44+
{ MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO36) },
45+
{ MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO37) },
46+
{ MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO35) },
47+
// DFU Button
48+
{ MP_ROM_QSTR(MP_QSTR_BOOT), MP_ROM_PTR(&pin_GPIO0) },
49+
50+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
51+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
52+
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
53+
54+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)}
55+
};
56+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
CONFIG_ESP32S2_SPIRAM_SUPPORT=y
2+
#
3+
# SPI RAM config
4+
#
5+
# CONFIG_SPIRAM_TYPE_AUTO is not set
6+
CONFIG_SPIRAM_TYPE_ESPPSRAM16=y
7+
# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set
8+
# CONFIG_SPIRAM_TYPE_ESPPSRAM64 is not set
9+
CONFIG_SPIRAM_SIZE=2097152
10+
# end of SPI RAM config
11+
12+
CONFIG_DEFAULT_PSRAM_CLK_IO=30
13+
#
14+
# PSRAM clock and cs IO for ESP32S2
15+
#
16+
CONFIG_DEFAULT_PSRAM_CS_IO=26
17+
# end of PSRAM clock and cs IO for ESP32S2
18+
19+
# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set
20+
# CONFIG_SPIRAM_RODATA is not set
21+
# CONFIG_SPIRAM_SPEED_80M is not set
22+
CONFIG_SPIRAM_SPEED_40M=y
23+
# CONFIG_SPIRAM_SPEED_26M is not set
24+
# CONFIG_SPIRAM_SPEED_20M is not set
25+
CONFIG_SPIRAM=y
26+
CONFIG_SPIRAM_BOOT_INIT=y
27+
# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set
28+
CONFIG_SPIRAM_USE_MEMMAP=y
29+
# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set
30+
# CONFIG_SPIRAM_USE_MALLOC is not set
31+
CONFIG_SPIRAM_MEMTEST=y
32+
# CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY is not set
33+
#
34+
# LWIP
35+
#
36+
CONFIG_LWIP_LOCAL_HOSTNAME="espressif"
37+
# end of LWIP

0 commit comments

Comments
 (0)