Skip to content

Commit

Permalink
Merge pull request #34 from esp-cpp/feature/29-box-3-firmware-support
Browse files Browse the repository at this point in the history
Feature: Firmware support for ESP32-S3-BOX-3
  • Loading branch information
finger563 authored Nov 10, 2023
2 parents 9ac58bf + 7188c78 commit 7b478c0
Show file tree
Hide file tree
Showing 14 changed files with 290 additions and 91 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ https://user-images.githubusercontent.com/213467/236730090-56c3bd64-86e4-4b9b-a9

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

As of https://github.com/esp-cpp/esp-box-emu/pull/34 I am starting to add
initial support for the new ESP32-S3-BOX-3.

## Description

This project is a little retro game emulation system running on ESP32-S3-BOX. It
Expand Down
2 changes: 1 addition & 1 deletion components/box-emu-hal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
idf_component_register(
INCLUDE_DIRS "include"
SRC_DIRS "src"
REQUIRES "driver" "heap" "fatfs" "esp_lcd" "esp_psram" "spi_flash" "nvs_flash" "codec" "display" "display_drivers" "mcp23x17" "input_drivers" "tt21100" "drv2605" "event_manager" "i2c"
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"
)
16 changes: 16 additions & 0 deletions components/box-emu-hal/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
menu "BOX Emulator HAL Configuration"

choice
prompt "Hardware Configuration"
default HARDWARE_BOX
help
Select the dev-kit / hardware you're using.
config HARDWARE_BOX
bool "ESP BOX"
config HARDWARE_BOX_3
bool "ESP BOX 3"
config HARDWARE_TDECK
bool "LILYGO T DECK"
endchoice

endmenu
75 changes: 75 additions & 0 deletions components/box-emu-hal/include/box.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#pragma once

#include "hal/spi_types.h"
#include "driver/gpio.h"
#include "driver/i2s_std.h"
#include "driver/spi_master.h"

#include "i2c.hpp"
#include "st7789.hpp"
#include "touchpad_input.hpp"
#include "tt21100.hpp"

namespace box_hal {

static constexpr std::string_view dev_kit = "ESP32-S3-BOX";

// internal i2c (touchscreen, audio codec)
static constexpr auto internal_i2c_port = I2C_NUM_0;
static constexpr auto internal_i2c_clock_speed = 400 * 1000;
static constexpr gpio_num_t internal_i2c_sda = GPIO_NUM_8;
static constexpr gpio_num_t internal_i2c_scl = GPIO_NUM_18;

// external I2c (peripherals)
static constexpr auto external_i2c_port = I2C_NUM_1;
static constexpr auto external_i2c_clock_speed = 400 * 1000;
static constexpr gpio_num_t external_i2c_sda = GPIO_NUM_41;
static constexpr gpio_num_t external_i2c_scl = GPIO_NUM_40;

// LCD
static constexpr int lcd_clock_speed = 60 * 1000 * 1000;
static constexpr auto lcd_spi_num = SPI2_HOST;
static constexpr gpio_num_t lcd_cs = GPIO_NUM_5;
static constexpr gpio_num_t lcd_mosi = GPIO_NUM_6;
static constexpr gpio_num_t lcd_sclk = GPIO_NUM_7;
static constexpr gpio_num_t lcd_reset = GPIO_NUM_48;
static constexpr gpio_num_t lcd_dc = GPIO_NUM_4;
static constexpr gpio_num_t backlight = GPIO_NUM_45;
static constexpr size_t display_width = 320;
static constexpr size_t display_height = 240;
static constexpr bool backlight_value = true;
static constexpr bool reset_value = false;
static constexpr bool invert_colors = true;
static constexpr auto rotation = espp::Display::Rotation::LANDSCAPE;
static constexpr bool mirror_x = true;
static constexpr bool mirror_y = true;
using DisplayDriver = espp::St7789;

// touch
static constexpr bool touch_swap_xy = false;
static constexpr bool touch_invert_x = true;
static constexpr bool touch_invert_y = false;
static constexpr gpio_num_t touch_interrupt = GPIO_NUM_3;
using TouchDriver = espp::Tt21100;
#define TOUCH_DRIVER_USE_WRITE 0
#define TOUCH_DRIVER_USE_READ 1
#define TOUCH_DRIVER_USE_WRITE_READ 0

// sound
static constexpr gpio_num_t sound_power_pin = GPIO_NUM_46;
static constexpr auto i2s_port = I2S_NUM_0;
static constexpr gpio_num_t i2s_mck_io = GPIO_NUM_2;
static constexpr gpio_num_t i2s_bck_io = GPIO_NUM_17;
static constexpr gpio_num_t i2s_ws_io = GPIO_NUM_47;
static constexpr gpio_num_t i2s_do_io = GPIO_NUM_15;
static constexpr gpio_num_t i2s_di_io = GPIO_NUM_16;
static constexpr gpio_num_t mute_pin = GPIO_NUM_1;

// uSD card
static constexpr gpio_num_t sdcard_cs = GPIO_NUM_10;
static constexpr gpio_num_t sdcard_mosi = GPIO_NUM_11;
static constexpr gpio_num_t sdcard_miso = GPIO_NUM_13;
static constexpr gpio_num_t sdcard_sclk = GPIO_NUM_12;
static constexpr auto sdcard_spi_num = SPI3_HOST;

} // namespace box_hal
75 changes: 75 additions & 0 deletions components/box-emu-hal/include/box_3.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#pragma once

#include "hal/spi_types.h"
#include "driver/gpio.h"
#include "driver/i2s_std.h"
#include "driver/spi_master.h"

#include "i2c.hpp"
#include "st7789.hpp"
#include "touchpad_input.hpp"
#include "gt911.hpp"

namespace box_hal {

static constexpr std::string_view dev_kit = "ESP32-S3-BOX-3";

// internal i2c (touchscreen, audio codec)
static constexpr auto internal_i2c_port = I2C_NUM_0;
static constexpr auto internal_i2c_clock_speed = 400 * 1000;
static constexpr gpio_num_t internal_i2c_sda = GPIO_NUM_8;
static constexpr gpio_num_t internal_i2c_scl = GPIO_NUM_18;

// external I2c (peripherals)
static constexpr auto external_i2c_port = I2C_NUM_1;
static constexpr auto external_i2c_clock_speed = 400 * 1000;
static constexpr gpio_num_t external_i2c_sda = GPIO_NUM_41;
static constexpr gpio_num_t external_i2c_scl = GPIO_NUM_40;

// LCD
static constexpr int lcd_clock_speed = 60 * 1000 * 1000;
static constexpr auto lcd_spi_num = SPI2_HOST;
static constexpr gpio_num_t lcd_cs = GPIO_NUM_5;
static constexpr gpio_num_t lcd_mosi = GPIO_NUM_6;
static constexpr gpio_num_t lcd_sclk = GPIO_NUM_7;
static constexpr gpio_num_t lcd_reset = GPIO_NUM_48;
static constexpr gpio_num_t lcd_dc = GPIO_NUM_4;
static constexpr gpio_num_t backlight = GPIO_NUM_47; // was 45 on ESP32-S3-BOX
static constexpr size_t display_width = 320;
static constexpr size_t display_height = 240;
static constexpr bool backlight_value = true;
static constexpr bool reset_value = true; // was false on ESP32-S3-BOX
static constexpr bool invert_colors = true;
static constexpr auto rotation = espp::Display::Rotation::LANDSCAPE;
static constexpr bool mirror_x = true;
static constexpr bool mirror_y = true;
using DisplayDriver = espp::St7789;

// touch
static constexpr bool touch_swap_xy = false;
static constexpr bool touch_invert_x = false;
static constexpr bool touch_invert_y = false;
static constexpr gpio_num_t touch_interrupt = GPIO_NUM_3;
using TouchDriver = espp::Gt911;
#define TOUCH_DRIVER_USE_WRITE 1
#define TOUCH_DRIVER_USE_READ 0
#define TOUCH_DRIVER_USE_WRITE_READ 1

// sound
static constexpr gpio_num_t sound_power_pin = GPIO_NUM_46;
static constexpr auto i2s_port = I2S_NUM_0;
static constexpr gpio_num_t i2s_mck_io = GPIO_NUM_2;
static constexpr gpio_num_t i2s_bck_io = GPIO_NUM_17;
static constexpr gpio_num_t i2s_ws_io = GPIO_NUM_45; // was 47 on ESP32-S3-BOX
static constexpr gpio_num_t i2s_do_io = GPIO_NUM_15;
static constexpr gpio_num_t i2s_di_io = GPIO_NUM_16;
static constexpr gpio_num_t mute_pin = GPIO_NUM_1;

// uSD card
static constexpr gpio_num_t sdcard_cs = GPIO_NUM_10;
static constexpr gpio_num_t sdcard_mosi = GPIO_NUM_11;
static constexpr gpio_num_t sdcard_miso = GPIO_NUM_13;
static constexpr gpio_num_t sdcard_sclk = GPIO_NUM_12;
static constexpr auto sdcard_spi_num = SPI3_HOST;

} // namespace box_hal
2 changes: 2 additions & 0 deletions components/box-emu-hal/include/fs_init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
#include "sdmmc_cmd.h"
#define MOUNT_POINT "/sdcard"

#include "hal.hpp"

void fs_init();
11 changes: 11 additions & 0 deletions components/box-emu-hal/include/hal.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include <sdkconfig.h>

#if defined(CONFIG_HARDWARE_BOX)
#include "box.hpp"
#elif defined(CONFIG_HARDWARE_BOX_3)
#include "box_3.hpp"
#else
#error "Unsupported hardware configuration specified"
#endif
1 change: 1 addition & 0 deletions components/box-emu-hal/include/hal_i2c.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <memory>

#include "hal.hpp"
#include "i2c.hpp"

extern std::shared_ptr<espp::I2c> internal_i2c;
Expand Down
12 changes: 7 additions & 5 deletions components/box-emu-hal/src/fs_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "format.hpp"

using namespace box_hal;

static void sdcard_init() {
esp_err_t ret;

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

spi_bus_config_t bus_cfg = {
.mosi_io_num = GPIO_NUM_11,
.miso_io_num = GPIO_NUM_13,
.sclk_io_num = GPIO_NUM_12,
.mosi_io_num = sdcard_mosi,
.miso_io_num = sdcard_miso,
.sclk_io_num = sdcard_sclk,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = 8192,
Expand All @@ -48,7 +50,7 @@ static void sdcard_init() {
// This initializes the slot without card detect (CD) and write protect (WP) signals.
// Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
slot_config.gpio_cs = GPIO_NUM_10;
slot_config.gpio_cs = sdcard_cs;
slot_config.host_id = host_id;

fmt::print("Mounting filesystem\n");
Expand Down
21 changes: 8 additions & 13 deletions components/box-emu-hal/src/hal_i2c.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
#include "hal_i2c.hpp"

// Only used for the touchpad and the imu
static constexpr i2c_port_t I2C_INTERNAL = I2C_NUM_0;
// used for our peripherals (external to the ESP S3 BOX)
static constexpr i2c_port_t I2C_EXTERNAL = I2C_NUM_1;
static constexpr int I2C_FREQ_HZ = (400*1000);
static constexpr int I2C_TIMEOUT_MS = 10;

std::shared_ptr<espp::I2c> internal_i2c = nullptr;
std::shared_ptr<espp::I2c> external_i2c = nullptr;

static bool initialized = false;

using namespace box_hal;

void i2c_init() {
if (initialized) return;
internal_i2c = std::make_shared<espp::I2c>(espp::I2c::Config{
.port = I2C_INTERNAL,
.sda_io_num = GPIO_NUM_8,
.scl_io_num = GPIO_NUM_18,
.port = internal_i2c_port,
.sda_io_num = internal_i2c_sda,
.scl_io_num = internal_i2c_scl,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE});
external_i2c = std::make_shared<espp::I2c>(espp::I2c::Config{
.port = I2C_EXTERNAL,
.sda_io_num = GPIO_NUM_41,
.scl_io_num = GPIO_NUM_40,
.port = external_i2c_port,
.sda_io_num = external_i2c_sda,
.scl_io_num = external_i2c_scl,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE});
initialized = true;
Expand Down
Loading

0 comments on commit 7b478c0

Please sign in to comment.