Skip to content

Commit 7b478c0

Browse files
authored
Merge pull request #34 from esp-cpp/feature/29-box-3-firmware-support
Feature: Firmware support for ESP32-S3-BOX-3
2 parents 9ac58bf + 7188c78 commit 7b478c0

File tree

14 files changed

+290
-91
lines changed

14 files changed

+290
-91
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ https://user-images.githubusercontent.com/213467/236730090-56c3bd64-86e4-4b9b-a9
66

77
https://user-images.githubusercontent.com/213467/220791336-eb24116d-0958-4ab7-88bd-f6a5bd6d7eb1.mp4
88

9+
As of https://github.com/esp-cpp/esp-box-emu/pull/34 I am starting to add
10+
initial support for the new ESP32-S3-BOX-3.
11+
912
## Description
1013

1114
This project is a little retro game emulation system running on ESP32-S3-BOX. It
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
idf_component_register(
22
INCLUDE_DIRS "include"
33
SRC_DIRS "src"
4-
REQUIRES "driver" "heap" "fatfs" "esp_lcd" "esp_psram" "spi_flash" "nvs_flash" "codec" "display" "display_drivers" "mcp23x17" "input_drivers" "tt21100" "drv2605" "event_manager" "i2c"
4+
REQUIRES "driver" "heap" "fatfs" "esp_lcd" "esp_psram" "spi_flash" "nvs_flash" "codec" "display" "display_drivers" "mcp23x17" "input_drivers" "tt21100" "gt911" "drv2605" "event_manager" "i2c"
55
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
menu "BOX Emulator HAL Configuration"
2+
3+
choice
4+
prompt "Hardware Configuration"
5+
default HARDWARE_BOX
6+
help
7+
Select the dev-kit / hardware you're using.
8+
config HARDWARE_BOX
9+
bool "ESP BOX"
10+
config HARDWARE_BOX_3
11+
bool "ESP BOX 3"
12+
config HARDWARE_TDECK
13+
bool "LILYGO T DECK"
14+
endchoice
15+
16+
endmenu
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#pragma once
2+
3+
#include "hal/spi_types.h"
4+
#include "driver/gpio.h"
5+
#include "driver/i2s_std.h"
6+
#include "driver/spi_master.h"
7+
8+
#include "i2c.hpp"
9+
#include "st7789.hpp"
10+
#include "touchpad_input.hpp"
11+
#include "tt21100.hpp"
12+
13+
namespace box_hal {
14+
15+
static constexpr std::string_view dev_kit = "ESP32-S3-BOX";
16+
17+
// internal i2c (touchscreen, audio codec)
18+
static constexpr auto internal_i2c_port = I2C_NUM_0;
19+
static constexpr auto internal_i2c_clock_speed = 400 * 1000;
20+
static constexpr gpio_num_t internal_i2c_sda = GPIO_NUM_8;
21+
static constexpr gpio_num_t internal_i2c_scl = GPIO_NUM_18;
22+
23+
// external I2c (peripherals)
24+
static constexpr auto external_i2c_port = I2C_NUM_1;
25+
static constexpr auto external_i2c_clock_speed = 400 * 1000;
26+
static constexpr gpio_num_t external_i2c_sda = GPIO_NUM_41;
27+
static constexpr gpio_num_t external_i2c_scl = GPIO_NUM_40;
28+
29+
// LCD
30+
static constexpr int lcd_clock_speed = 60 * 1000 * 1000;
31+
static constexpr auto lcd_spi_num = SPI2_HOST;
32+
static constexpr gpio_num_t lcd_cs = GPIO_NUM_5;
33+
static constexpr gpio_num_t lcd_mosi = GPIO_NUM_6;
34+
static constexpr gpio_num_t lcd_sclk = GPIO_NUM_7;
35+
static constexpr gpio_num_t lcd_reset = GPIO_NUM_48;
36+
static constexpr gpio_num_t lcd_dc = GPIO_NUM_4;
37+
static constexpr gpio_num_t backlight = GPIO_NUM_45;
38+
static constexpr size_t display_width = 320;
39+
static constexpr size_t display_height = 240;
40+
static constexpr bool backlight_value = true;
41+
static constexpr bool reset_value = false;
42+
static constexpr bool invert_colors = true;
43+
static constexpr auto rotation = espp::Display::Rotation::LANDSCAPE;
44+
static constexpr bool mirror_x = true;
45+
static constexpr bool mirror_y = true;
46+
using DisplayDriver = espp::St7789;
47+
48+
// touch
49+
static constexpr bool touch_swap_xy = false;
50+
static constexpr bool touch_invert_x = true;
51+
static constexpr bool touch_invert_y = false;
52+
static constexpr gpio_num_t touch_interrupt = GPIO_NUM_3;
53+
using TouchDriver = espp::Tt21100;
54+
#define TOUCH_DRIVER_USE_WRITE 0
55+
#define TOUCH_DRIVER_USE_READ 1
56+
#define TOUCH_DRIVER_USE_WRITE_READ 0
57+
58+
// sound
59+
static constexpr gpio_num_t sound_power_pin = GPIO_NUM_46;
60+
static constexpr auto i2s_port = I2S_NUM_0;
61+
static constexpr gpio_num_t i2s_mck_io = GPIO_NUM_2;
62+
static constexpr gpio_num_t i2s_bck_io = GPIO_NUM_17;
63+
static constexpr gpio_num_t i2s_ws_io = GPIO_NUM_47;
64+
static constexpr gpio_num_t i2s_do_io = GPIO_NUM_15;
65+
static constexpr gpio_num_t i2s_di_io = GPIO_NUM_16;
66+
static constexpr gpio_num_t mute_pin = GPIO_NUM_1;
67+
68+
// uSD card
69+
static constexpr gpio_num_t sdcard_cs = GPIO_NUM_10;
70+
static constexpr gpio_num_t sdcard_mosi = GPIO_NUM_11;
71+
static constexpr gpio_num_t sdcard_miso = GPIO_NUM_13;
72+
static constexpr gpio_num_t sdcard_sclk = GPIO_NUM_12;
73+
static constexpr auto sdcard_spi_num = SPI3_HOST;
74+
75+
} // namespace box_hal
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#pragma once
2+
3+
#include "hal/spi_types.h"
4+
#include "driver/gpio.h"
5+
#include "driver/i2s_std.h"
6+
#include "driver/spi_master.h"
7+
8+
#include "i2c.hpp"
9+
#include "st7789.hpp"
10+
#include "touchpad_input.hpp"
11+
#include "gt911.hpp"
12+
13+
namespace box_hal {
14+
15+
static constexpr std::string_view dev_kit = "ESP32-S3-BOX-3";
16+
17+
// internal i2c (touchscreen, audio codec)
18+
static constexpr auto internal_i2c_port = I2C_NUM_0;
19+
static constexpr auto internal_i2c_clock_speed = 400 * 1000;
20+
static constexpr gpio_num_t internal_i2c_sda = GPIO_NUM_8;
21+
static constexpr gpio_num_t internal_i2c_scl = GPIO_NUM_18;
22+
23+
// external I2c (peripherals)
24+
static constexpr auto external_i2c_port = I2C_NUM_1;
25+
static constexpr auto external_i2c_clock_speed = 400 * 1000;
26+
static constexpr gpio_num_t external_i2c_sda = GPIO_NUM_41;
27+
static constexpr gpio_num_t external_i2c_scl = GPIO_NUM_40;
28+
29+
// LCD
30+
static constexpr int lcd_clock_speed = 60 * 1000 * 1000;
31+
static constexpr auto lcd_spi_num = SPI2_HOST;
32+
static constexpr gpio_num_t lcd_cs = GPIO_NUM_5;
33+
static constexpr gpio_num_t lcd_mosi = GPIO_NUM_6;
34+
static constexpr gpio_num_t lcd_sclk = GPIO_NUM_7;
35+
static constexpr gpio_num_t lcd_reset = GPIO_NUM_48;
36+
static constexpr gpio_num_t lcd_dc = GPIO_NUM_4;
37+
static constexpr gpio_num_t backlight = GPIO_NUM_47; // was 45 on ESP32-S3-BOX
38+
static constexpr size_t display_width = 320;
39+
static constexpr size_t display_height = 240;
40+
static constexpr bool backlight_value = true;
41+
static constexpr bool reset_value = true; // was false on ESP32-S3-BOX
42+
static constexpr bool invert_colors = true;
43+
static constexpr auto rotation = espp::Display::Rotation::LANDSCAPE;
44+
static constexpr bool mirror_x = true;
45+
static constexpr bool mirror_y = true;
46+
using DisplayDriver = espp::St7789;
47+
48+
// touch
49+
static constexpr bool touch_swap_xy = false;
50+
static constexpr bool touch_invert_x = false;
51+
static constexpr bool touch_invert_y = false;
52+
static constexpr gpio_num_t touch_interrupt = GPIO_NUM_3;
53+
using TouchDriver = espp::Gt911;
54+
#define TOUCH_DRIVER_USE_WRITE 1
55+
#define TOUCH_DRIVER_USE_READ 0
56+
#define TOUCH_DRIVER_USE_WRITE_READ 1
57+
58+
// sound
59+
static constexpr gpio_num_t sound_power_pin = GPIO_NUM_46;
60+
static constexpr auto i2s_port = I2S_NUM_0;
61+
static constexpr gpio_num_t i2s_mck_io = GPIO_NUM_2;
62+
static constexpr gpio_num_t i2s_bck_io = GPIO_NUM_17;
63+
static constexpr gpio_num_t i2s_ws_io = GPIO_NUM_45; // was 47 on ESP32-S3-BOX
64+
static constexpr gpio_num_t i2s_do_io = GPIO_NUM_15;
65+
static constexpr gpio_num_t i2s_di_io = GPIO_NUM_16;
66+
static constexpr gpio_num_t mute_pin = GPIO_NUM_1;
67+
68+
// uSD card
69+
static constexpr gpio_num_t sdcard_cs = GPIO_NUM_10;
70+
static constexpr gpio_num_t sdcard_mosi = GPIO_NUM_11;
71+
static constexpr gpio_num_t sdcard_miso = GPIO_NUM_13;
72+
static constexpr gpio_num_t sdcard_sclk = GPIO_NUM_12;
73+
static constexpr auto sdcard_spi_num = SPI3_HOST;
74+
75+
} // namespace box_hal

components/box-emu-hal/include/fs_init.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010
#include "sdmmc_cmd.h"
1111
#define MOUNT_POINT "/sdcard"
1212

13+
#include "hal.hpp"
14+
1315
void fs_init();
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#include <sdkconfig.h>
4+
5+
#if defined(CONFIG_HARDWARE_BOX)
6+
#include "box.hpp"
7+
#elif defined(CONFIG_HARDWARE_BOX_3)
8+
#include "box_3.hpp"
9+
#else
10+
#error "Unsupported hardware configuration specified"
11+
#endif

components/box-emu-hal/include/hal_i2c.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <memory>
44

5+
#include "hal.hpp"
56
#include "i2c.hpp"
67

78
extern std::shared_ptr<espp::I2c> internal_i2c;

components/box-emu-hal/src/fs_init.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include "format.hpp"
44

5+
using namespace box_hal;
6+
57
static void sdcard_init() {
68
esp_err_t ret;
79

@@ -27,13 +29,13 @@ static void sdcard_init() {
2729
// For setting a specific frequency, use host.max_freq_khz (range 400kHz - 20MHz for SDSPI)
2830
// Example: for fixed frequency of 10MHz, use host.max_freq_khz = 10000;
2931
sdmmc_host_t host = SDSPI_HOST_DEFAULT();
30-
host.slot = SPI3_HOST;
32+
host.slot = sdcard_spi_num;
3133
// host.max_freq_khz = 10 * 1000;
3234

3335
spi_bus_config_t bus_cfg = {
34-
.mosi_io_num = GPIO_NUM_11,
35-
.miso_io_num = GPIO_NUM_13,
36-
.sclk_io_num = GPIO_NUM_12,
36+
.mosi_io_num = sdcard_mosi,
37+
.miso_io_num = sdcard_miso,
38+
.sclk_io_num = sdcard_sclk,
3739
.quadwp_io_num = -1,
3840
.quadhd_io_num = -1,
3941
.max_transfer_sz = 8192,
@@ -48,7 +50,7 @@ static void sdcard_init() {
4850
// This initializes the slot without card detect (CD) and write protect (WP) signals.
4951
// Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
5052
sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
51-
slot_config.gpio_cs = GPIO_NUM_10;
53+
slot_config.gpio_cs = sdcard_cs;
5254
slot_config.host_id = host_id;
5355

5456
fmt::print("Mounting filesystem\n");

components/box-emu-hal/src/hal_i2c.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
11
#include "hal_i2c.hpp"
22

3-
// Only used for the touchpad and the imu
4-
static constexpr i2c_port_t I2C_INTERNAL = I2C_NUM_0;
5-
// used for our peripherals (external to the ESP S3 BOX)
6-
static constexpr i2c_port_t I2C_EXTERNAL = I2C_NUM_1;
7-
static constexpr int I2C_FREQ_HZ = (400*1000);
8-
static constexpr int I2C_TIMEOUT_MS = 10;
9-
103
std::shared_ptr<espp::I2c> internal_i2c = nullptr;
114
std::shared_ptr<espp::I2c> external_i2c = nullptr;
125

136
static bool initialized = false;
147

8+
using namespace box_hal;
9+
1510
void i2c_init() {
1611
if (initialized) return;
1712
internal_i2c = std::make_shared<espp::I2c>(espp::I2c::Config{
18-
.port = I2C_INTERNAL,
19-
.sda_io_num = GPIO_NUM_8,
20-
.scl_io_num = GPIO_NUM_18,
13+
.port = internal_i2c_port,
14+
.sda_io_num = internal_i2c_sda,
15+
.scl_io_num = internal_i2c_scl,
2116
.sda_pullup_en = GPIO_PULLUP_ENABLE,
2217
.scl_pullup_en = GPIO_PULLUP_ENABLE});
2318
external_i2c = std::make_shared<espp::I2c>(espp::I2c::Config{
24-
.port = I2C_EXTERNAL,
25-
.sda_io_num = GPIO_NUM_41,
26-
.scl_io_num = GPIO_NUM_40,
19+
.port = external_i2c_port,
20+
.sda_io_num = external_i2c_sda,
21+
.scl_io_num = external_i2c_scl,
2722
.sda_pullup_en = GPIO_PULLUP_ENABLE,
2823
.scl_pullup_en = GPIO_PULLUP_ENABLE});
2924
initialized = true;

0 commit comments

Comments
 (0)