Skip to content

Commit a2ab553

Browse files
committed
Add board definition for uGame S3
uGame S3 is a handheld game console with an ESP32-S3 chip. More information at https://deshipu.art/projects/project-178061/
1 parent 34cdb47 commit a2ab553

File tree

5 files changed

+243
-0
lines changed

5 files changed

+243
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
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+
30+
#include "shared-bindings/busio/SPI.h"
31+
#include "shared-bindings/fourwire/FourWire.h"
32+
#include "shared-bindings/microcontroller/Pin.h"
33+
#include "shared-module/displayio/__init__.h"
34+
#include "shared-module/displayio/mipi_constants.h"
35+
#include "shared-bindings/board/__init__.h"
36+
37+
#include "esp_log.h"
38+
#include "esp_err.h"
39+
40+
fourwire_fourwire_obj_t board_display_obj;
41+
42+
#define DELAY 0x80
43+
44+
uint8_t display_init_sequence[] = {
45+
0x01, 0 | DELAY, 0x80, // Software reset then delay 0x80 (128ms)
46+
0xEF, 3, 0x03, 0x80, 0x02,
47+
0xCF, 3, 0x00, 0xC1, 0x30,
48+
0xED, 4, 0x64, 0x03, 0x12, 0x81,
49+
0xE8, 3, 0x85, 0x00, 0x78,
50+
0xCB, 5, 0x39, 0x2C, 0x00, 0x34, 0x02,
51+
0xF7, 1, 0x20,
52+
0xEA, 2, 0x00, 0x00,
53+
0xc0, 1, 0x23, // Power control VRH[5:0]
54+
0xc1, 1, 0x10, // Power control SAP[2:0];BT[3:0]
55+
0xc5, 2, 0x3e, 0x28, // VCM control
56+
0xc7, 1, 0x86, // VCM control2
57+
0x37, 1, 0x00, // Vertical scroll zero
58+
0x3a, 1, 0x55, // COLMOD: Pixel Format Set
59+
0xb1, 2, 0x00, 0x18, // Frame Rate Control (In Normal Mode/Full Colors)
60+
0xb6, 3, 0x08, 0x82, 0x27, // Display Function Control
61+
0xF2, 1, 0x00, // 3Gamma Function Disable
62+
0x26, 1, 0x01, // Gamma curve selected
63+
0xe0, 15, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00, // Set Gamma
64+
0xe1, 15, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F, // Set Gamma
65+
0x11, 0 | DELAY, 0x78, // Exit Sleep then delay 0x78 (120ms)
66+
0x29, 0 | DELAY, 0x78, // Display on then delay 0x78 (120ms)
67+
0x36, 1, 0x38,
68+
};
69+
70+
71+
void board_init(void) {
72+
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
73+
busio_spi_obj_t *spi = &bus->inline_bus;
74+
common_hal_busio_spi_construct(spi, &pin_GPIO12, &pin_GPIO11, NULL, false);
75+
common_hal_busio_spi_never_reset(spi);
76+
77+
bus->base.type = &fourwire_fourwire_type;
78+
common_hal_fourwire_fourwire_construct(bus,
79+
spi,
80+
MP_OBJ_FROM_PTR(&pin_GPIO9), // TFT_DC Command or data
81+
MP_OBJ_FROM_PTR(&pin_GPIO10), // TFT_CS Chip select
82+
MP_OBJ_FROM_PTR(&pin_GPIO13), // TFT_RESET Reset
83+
80000000L, // Baudrate
84+
0, // Polarity
85+
0); // Phase
86+
87+
busdisplay_busdisplay_obj_t *display = &allocate_display()->display;
88+
display->base.type = &busdisplay_busdisplay_type;
89+
common_hal_busdisplay_busdisplay_construct(
90+
display,
91+
bus,
92+
320, // Width (after rotation)
93+
240, // Height (after rotation)
94+
0, // column start
95+
0, // row start
96+
0, // rotation
97+
16, // Color depth
98+
false, // Grayscale
99+
false, // Pixels in a byte share a row. Only used for depth < 8
100+
1, // bytes per cell. Only valid for depths < 8
101+
false, // reverse_pixels_in_byte. Only valid for depths < 8
102+
true, // reverse_pixels_in_word
103+
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
104+
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
105+
MIPI_COMMAND_WRITE_MEMORY_START, // Write memory command
106+
display_init_sequence,
107+
sizeof(display_init_sequence),
108+
&pin_GPIO21, // backlight pin
109+
NO_BRIGHTNESS_COMMAND,
110+
1.0f, // brightness
111+
false, // single_byte_bounds
112+
false, // data_as_commands
113+
true, // auto_refresh
114+
20, // native_frames_per_second
115+
true, // backlight_on_high
116+
false, // not SH1107
117+
50000); // backlight pwm frequency
118+
}
119+
120+
void board_deinit(void) {
121+
}
122+
123+
// 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+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2023 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+
#define MICROPY_HW_BOARD_NAME "uGame S3"
28+
#define MICROPY_HW_MCU_NAME "ESP32S3"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
USB_VID = 0x1209
2+
USB_PID = 0xD187
3+
USB_PRODUCT = "uGameS3"
4+
USB_MANUFACTURER = "deshipu"
5+
6+
IDF_TARGET = esp32s3
7+
8+
CIRCUITPY_ESP_FLASH_MODE = qio
9+
CIRCUITPY_ESP_FLASH_FREQ = 80m
10+
CIRCUITPY_ESP_FLASH_SIZE = 16MB
11+
12+
CIRCUITPY_ESP_PSRAM_SIZE = 8MB
13+
CIRCUITPY_ESP_PSRAM_MODE = opi
14+
CIRCUITPY_ESP_PSRAM_FREQ = 80m
15+
16+
CIRCUITPY_STAGE = 1
17+
CIRCUITPY_KEYPAD = 1
18+
19+
CIRCUITPY_CANIO = 0
20+
CIRCUITPY_DUALBANK = 0
21+
CIRCUITPY_ESPCAMERA = 0
22+
CIRCUITPY_FRAMEBUFFERIO = 0
23+
CIRCUITPY_PARALLELDISPLAYBUS = 0
24+
CIRCUITPY_RGBMATRIX = 0
25+
CIRCUITPY_ROTARYIO = 0
26+
27+
FROZEN_MPY_DIRS += $(TOP)/frozen/circuitpython-stage/ugame_s3
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include "py/objtuple.h"
2+
#include "shared-bindings/board/__init__.h"
3+
#include "shared-module/displayio/__init__.h"
4+
5+
6+
static const mp_rom_map_elem_t board_module_globals_table[] = {
7+
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
8+
9+
{ MP_ROM_QSTR(MP_QSTR_P1), MP_ROM_PTR(&pin_GPIO43) },
10+
{ MP_ROM_QSTR(MP_QSTR_P2), MP_ROM_PTR(&pin_GPIO44) },
11+
{ MP_ROM_QSTR(MP_QSTR_P3), MP_ROM_PTR(&pin_GPIO3) },
12+
{ MP_ROM_QSTR(MP_QSTR_P4), MP_ROM_PTR(&pin_GPIO4) },
13+
{ MP_ROM_QSTR(MP_QSTR_P5), MP_ROM_PTR(&pin_GPIO5) },
14+
{ MP_ROM_QSTR(MP_QSTR_P6), MP_ROM_PTR(&pin_GPIO6) },
15+
{ MP_ROM_QSTR(MP_QSTR_P7), MP_ROM_PTR(&pin_GPIO7) },
16+
17+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_LEFT), MP_ROM_PTR(&pin_GPIO1) },
18+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_UP), MP_ROM_PTR(&pin_GPIO2) },
19+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_RIGHT), MP_ROM_PTR(&pin_GPIO42) },
20+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_DOWN), MP_ROM_PTR(&pin_GPIO41) },
21+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_X), MP_ROM_PTR(&pin_GPIO0) },
22+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_O), MP_ROM_PTR(&pin_GPIO48) },
23+
{ MP_ROM_QSTR(MP_QSTR_BUTTON_Z), MP_ROM_PTR(&pin_GPIO47) },
24+
25+
{ MP_ROM_QSTR(MP_QSTR_LIGHT), MP_ROM_PTR(&pin_GPIO14) },
26+
{ MP_ROM_QSTR(MP_QSTR_BATTERY), MP_ROM_PTR(&pin_GPIO8) },
27+
28+
29+
{ MP_ROM_QSTR(MP_QSTR_AUDIO_BCLK), MP_ROM_PTR(&pin_GPIO15) },
30+
{ MP_ROM_QSTR(MP_QSTR_AUDIO_LRCLK), MP_ROM_PTR(&pin_GPIO16) },
31+
{ MP_ROM_QSTR(MP_QSTR_AUDIO_DATA), MP_ROM_PTR(&pin_GPIO17) },
32+
{ MP_ROM_QSTR(MP_QSTR_AUDIO_GAIN), MP_ROM_PTR(&pin_GPIO18) },
33+
34+
{ MP_ROM_QSTR(MP_QSTR_TFT_RESET), MP_ROM_PTR(&pin_GPIO13) },
35+
{ MP_ROM_QSTR(MP_QSTR_TFT_CS), MP_ROM_PTR(&pin_GPIO10) },
36+
{ MP_ROM_QSTR(MP_QSTR_TFT_DC), MP_ROM_PTR(&pin_GPIO9) },
37+
{ MP_ROM_QSTR(MP_QSTR_TFT_BACKLIGHT), MP_ROM_PTR(&pin_GPIO21) },
38+
{ MP_ROM_QSTR(MP_QSTR_TFT_SCK), MP_ROM_PTR(&pin_GPIO12) },
39+
{ MP_ROM_QSTR(MP_QSTR_TFT_MOSI), MP_ROM_PTR(&pin_GPIO11) },
40+
41+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].display)},
42+
};
43+
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#
2+
# Espressif IoT Development Framework Configuration
3+
#
4+
#
5+
# Component config
6+
#
7+
#
8+
# LWIP
9+
#
10+
CONFIG_LWIP_LOCAL_HOSTNAME="espressif-esp32s3"
11+
# end of LWIP
12+
13+
#
14+
# Camera configuration
15+
#
16+
# CONFIG_OV7725_SUPPORT is not set
17+
# CONFIG_OV3660_SUPPORT is not set
18+
# end of Camera configuration
19+
20+
# end of Component config
21+
22+
# end of Espressif IoT Development Framework Configuration

0 commit comments

Comments
 (0)