Skip to content

Commit

Permalink
Merge pull request #57 from esp-cpp/feature/cross-compatibility
Browse files Browse the repository at this point in the history
feat(compat): update hal to work across v0 and v1
  • Loading branch information
finger563 authored Jan 18, 2024
2 parents f68603e + 299dac8 commit 86d523f
Show file tree
Hide file tree
Showing 37 changed files with 198 additions and 147 deletions.
Binary file added boxart/Ninja+Gaiden+(Europe)-sms.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/Out+Run+(Europe)-gg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/Out+Run+(World)-sms.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/Out+Run+Europa+gg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/Out+Run+sms.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/R-Type-sms.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/Road+Rash+(USA)-gg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/StreetsofRage2-gg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/ghouls-n-ghosts-sms.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/source/Ninja+Gaiden+(Europe)-sms.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/source/Out+Run+(Europe)-gg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/source/Out+Run+(World)-sms.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/source/Out+Run+Europa+gg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/source/Out+Run+sms.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/source/R-Type-sms.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/source/Road+Rash+(USA)-gg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/source/StreetsofRage2-gg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/source/castle-of-illusion-gg.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/source/ghouls-n-ghosts-sms.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/source/wonder-boy-iii-dragon-trap-gg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/source/wonder-boy-iii-dragon-trap-sms.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/wonder-boy-iii-dragon-trap-gg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added boxart/wonder-boy-iii-dragon-trap-sms.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 0 additions & 19 deletions components/box-emu-hal/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
menu "BOX Emulator Configuration"

choice
prompt "Hardware Revision"
default HARDWARE_V1
help
Select the version of the hardware you're using.
config HARDWARE_V0
bool "Hardware V0"
help
This is the hardware version 0 of the BOX. It uses custom 3d printed button plastics and tactile switches.
It only supports the ESP32-S3-BOX.
config HARDWARE_V1
bool "Hardware V1"
help
This is the hardware version 1 of the BOX. It uses gameboy color button plastics and membranes
and supports both the ESP32-S3-BOX and the ESP32-S3-BOX-3. It also adds support for physical volume
buttons, battery measurement, and a battery charging LED.
endchoice

choice
prompt "Module Configuration"
default HARDWARE_BOX
Expand All @@ -26,7 +8,6 @@ menu "BOX Emulator Configuration"
config HARDWARE_BOX
bool "ESP32-S3-BOX"
config HARDWARE_BOX_3
depends on HARDWARE_V1
bool "ESP32-S3-BOX-3"
endchoice

Expand Down
3 changes: 0 additions & 3 deletions components/box-emu-hal/include/box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ 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;
Expand Down
3 changes: 0 additions & 3 deletions components/box-emu-hal/include/box_3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ 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;
Expand Down
8 changes: 3 additions & 5 deletions components/box-emu-hal/include/box_emu_hal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <sdkconfig.h>

#include <atomic>
#include <cstdint>
#include <memory>
#include <mutex>
#include <stdio.h>
Expand All @@ -19,12 +20,14 @@
#include <esp_check.h>
#include <hal/spi_types.h>

#include "aw9523.hpp"
#include "event_manager.hpp"
#include "display.hpp"
#include "i2c.hpp"
#include "keypad_input.hpp"
#include "logger.hpp"
#include "max1704x.hpp"
#include "mcp23x17.hpp"
#include "oneshot_adc.hpp"
#include "serialization.hpp"
#include "st7789.hpp"
Expand All @@ -40,13 +43,8 @@
#error "Invalid module selection"
#endif

#if CONFIG_HARDWARE_V0
#include "emu_v0.hpp"
#elif CONFIG_HARDWARE_V1
#include "emu_v1.hpp"
#else
#error "Invalid hardware version"
#endif

#include "es7210.hpp"
#include "es8311.hpp"
Expand Down
49 changes: 26 additions & 23 deletions components/box-emu-hal/include/emu_v0.hpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
#pragma once

#if CONFIG_HARDWARE_V0
#include <cstdint>

#include "mcp23x17.hpp"
using InputDriver = espp::Mcp23x17;
static constexpr uint16_t START_PIN = (1<<0) << 0; // start pin is on port a of the MCP23x17
static constexpr uint16_t SELECT_PIN = (1<<1) << 0; // select pin is on port a of the MCP23x17
static constexpr uint16_t UP_PIN = (1<<0) << 8; // up pin is on port b of the MCP23x17
static constexpr uint16_t DOWN_PIN = (1<<1) << 8; // down pin is on port b of the MCP23x17
static constexpr uint16_t LEFT_PIN = (1<<2) << 8; // left pin is on port b of the MCP23x17
static constexpr uint16_t RIGHT_PIN = (1<<3) << 8; // right pin is on port b of the MCP23x17
static constexpr uint16_t A_PIN = (1<<4) << 8; // a pin is on port b of the MCP23x17
static constexpr uint16_t B_PIN = (1<<5) << 8; // b pin is on port b of the MCP23x17
static constexpr uint16_t X_PIN = (1<<6) << 8; // x pin is on port b of the MCP23x17
static constexpr uint16_t Y_PIN = (1<<7) << 8; // y pin is on port b of the MCP23x17
static constexpr uint16_t BAT_ALERT_PIN = 0; // battery alert pin doesn't exist on the MCP23x17
static constexpr uint16_t VOL_UP_PIN = 0; // volume up pin doesn't exist on the MCP23x17
static constexpr uint16_t VOL_DOWN_PIN = 0; // volume down pin doesn't exist on the MCP23x17
static constexpr uint16_t DIRECTION_MASK = (UP_PIN | DOWN_PIN | LEFT_PIN | RIGHT_PIN | A_PIN | B_PIN | X_PIN | Y_PIN | START_PIN | SELECT_PIN);
static constexpr uint16_t INTERRUPT_MASK = (START_PIN | SELECT_PIN);
static constexpr uint16_t INVERT_MASK = (UP_PIN | DOWN_PIN | LEFT_PIN | RIGHT_PIN | A_PIN | B_PIN | X_PIN | Y_PIN | START_PIN | SELECT_PIN ); // pins are active low so invert them
static constexpr uint8_t PORT_0_DIRECTION_MASK = DIRECTION_MASK & 0xFF;
static constexpr uint8_t PORT_1_DIRECTION_MASK = (DIRECTION_MASK >> 8) & 0xFF;
static constexpr uint8_t PORT_0_INTERRUPT_MASK = INTERRUPT_MASK & 0xFF;
static constexpr uint8_t PORT_1_INTERRUPT_MASK = (INTERRUPT_MASK >> 8) & 0xFF;
#endif // CONFIG_HARDWARE_V0

class EmuV0 {
public:
static constexpr uint16_t START_PIN = (1<<0) << 0; // start pin is on port a of the MCP23x17
static constexpr uint16_t SELECT_PIN = (1<<1) << 0; // select pin is on port a of the MCP23x17
static constexpr uint16_t UP_PIN = (1<<0) << 8; // up pin is on port b of the MCP23x17
static constexpr uint16_t DOWN_PIN = (1<<1) << 8; // down pin is on port b of the MCP23x17
static constexpr uint16_t LEFT_PIN = (1<<2) << 8; // left pin is on port b of the MCP23x17
static constexpr uint16_t RIGHT_PIN = (1<<3) << 8; // right pin is on port b of the MCP23x17
static constexpr uint16_t A_PIN = (1<<4) << 8; // a pin is on port b of the MCP23x17
static constexpr uint16_t B_PIN = (1<<5) << 8; // b pin is on port b of the MCP23x17
static constexpr uint16_t X_PIN = (1<<6) << 8; // x pin is on port b of the MCP23x17
static constexpr uint16_t Y_PIN = (1<<7) << 8; // y pin is on port b of the MCP23x17
static constexpr uint16_t BAT_ALERT_PIN = 0; // battery alert pin doesn't exist on the MCP23x17
static constexpr uint16_t VOL_UP_PIN = 0; // volume up pin doesn't exist on the MCP23x17
static constexpr uint16_t VOL_DOWN_PIN = 0; // volume down pin doesn't exist on the MCP23x17
static constexpr uint16_t DIRECTION_MASK = (UP_PIN | DOWN_PIN | LEFT_PIN | RIGHT_PIN | A_PIN | B_PIN | X_PIN | Y_PIN | START_PIN | SELECT_PIN);
static constexpr uint16_t INTERRUPT_MASK = (START_PIN | SELECT_PIN);
static constexpr uint16_t INVERT_MASK = (UP_PIN | DOWN_PIN | LEFT_PIN | RIGHT_PIN | A_PIN | B_PIN | X_PIN | Y_PIN | START_PIN | SELECT_PIN ); // pins are active low so invert them
static constexpr uint8_t PORT_0_DIRECTION_MASK = DIRECTION_MASK & 0xFF;
static constexpr uint8_t PORT_1_DIRECTION_MASK = (DIRECTION_MASK >> 8) & 0xFF;
static constexpr uint8_t PORT_0_INTERRUPT_MASK = INTERRUPT_MASK & 0xFF;
static constexpr uint8_t PORT_1_INTERRUPT_MASK = (INTERRUPT_MASK >> 8) & 0xFF;
};
61 changes: 33 additions & 28 deletions components/box-emu-hal/include/emu_v1.hpp
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
#pragma once

#if CONFIG_HARDWARE_V1
#include <cstdint>

#include "aw9523.hpp"
using InputDriver = espp::Aw9523;
static constexpr gpio_num_t VBAT_SENSE_PIN = GPIO_NUM_14; // battery sense pin is on GPIO 14
static constexpr gpio_num_t AW9523_INT_PIN = GPIO_NUM_21; // interrupt pin is on GPIO 21
static constexpr uint16_t UP_PIN = (1<<0) << 0; // up pin is on port 0 of the AW9523
static constexpr uint16_t DOWN_PIN = (1<<1) << 0; // down pin is on port 0 of the AW9523
static constexpr uint16_t LEFT_PIN = (1<<2) << 0; // left pin is on port 0 of the AW9523
static constexpr uint16_t RIGHT_PIN = (1<<3) << 0; // right pin is on port 0 of the AW9523
static constexpr uint16_t A_PIN = (1<<4) << 0; // a pin is on port 0 of the AW9523
static constexpr uint16_t B_PIN = (1<<5) << 0; // b pin is on port 0 of the AW9523
static constexpr uint16_t X_PIN = (1<<6) << 0; // x pin is on port 0 of the AW9523
static constexpr uint16_t Y_PIN = (1<<7) << 0; // y pin is on port 0 of the AW9523
static constexpr uint16_t START_PIN = (1<<0) << 8; // start pin is on port 1 of the AW9523
static constexpr uint16_t SELECT_PIN = (1<<1) << 8; // select pin is on port 1 of the AW9523
static constexpr uint16_t BAT_ALERT_PIN = (1<<3) << 8; // battery alert pin is on port 1 of the AW9523
static constexpr uint16_t VOL_UP_PIN = (1<<4) << 8; // volume up pin is on port 1 of the AW9523
static constexpr uint16_t VOL_DOWN_PIN = (1<<5) << 8; // volume down pin is on port 1 of the AW9523
static constexpr uint16_t DIRECTION_MASK = (UP_PIN | DOWN_PIN | LEFT_PIN | RIGHT_PIN | A_PIN | B_PIN | X_PIN | Y_PIN | START_PIN | SELECT_PIN | BAT_ALERT_PIN | VOL_UP_PIN | VOL_DOWN_PIN);
static constexpr uint16_t INTERRUPT_MASK = (BAT_ALERT_PIN);
static constexpr uint16_t INVERT_MASK = (UP_PIN | DOWN_PIN | LEFT_PIN | RIGHT_PIN | A_PIN | B_PIN | X_PIN | Y_PIN | START_PIN | SELECT_PIN | BAT_ALERT_PIN | VOL_UP_PIN | VOL_DOWN_PIN); // pins are active low so invert them
static constexpr uint8_t PORT_0_DIRECTION_MASK = DIRECTION_MASK & 0xFF;
static constexpr uint8_t PORT_1_DIRECTION_MASK = (DIRECTION_MASK >> 8) & 0xFF;
static constexpr uint8_t PORT_0_INTERRUPT_MASK = INTERRUPT_MASK & 0xFF;
static constexpr uint8_t PORT_1_INTERRUPT_MASK = (INTERRUPT_MASK >> 8) & 0xFF;
#include "oneshot_adc.hpp"

class EmuV1 {
public:
using InputDriver = espp::Aw9523;
static constexpr gpio_num_t VBAT_SENSE_PIN = GPIO_NUM_14; // battery sense pin is on GPIO 14
static constexpr gpio_num_t AW9523_INT_PIN = GPIO_NUM_21; // interrupt pin is on GPIO 21
static constexpr uint16_t UP_PIN = (1<<0) << 0; // up pin is on port 0 of the AW9523
static constexpr uint16_t DOWN_PIN = (1<<1) << 0; // down pin is on port 0 of the AW9523
static constexpr uint16_t LEFT_PIN = (1<<2) << 0; // left pin is on port 0 of the AW9523
static constexpr uint16_t RIGHT_PIN = (1<<3) << 0; // right pin is on port 0 of the AW9523
static constexpr uint16_t A_PIN = (1<<4) << 0; // a pin is on port 0 of the AW9523
static constexpr uint16_t B_PIN = (1<<5) << 0; // b pin is on port 0 of the AW9523
static constexpr uint16_t X_PIN = (1<<6) << 0; // x pin is on port 0 of the AW9523
static constexpr uint16_t Y_PIN = (1<<7) << 0; // y pin is on port 0 of the AW9523
static constexpr uint16_t START_PIN = (1<<0) << 8; // start pin is on port 1 of the AW9523
static constexpr uint16_t SELECT_PIN = (1<<1) << 8; // select pin is on port 1 of the AW9523
static constexpr uint16_t BAT_ALERT_PIN = (1<<3) << 8; // battery alert pin is on port 1 of the AW9523
static constexpr uint16_t VOL_UP_PIN = (1<<4) << 8; // volume up pin is on port 1 of the AW9523
static constexpr uint16_t VOL_DOWN_PIN = (1<<5) << 8; // volume down pin is on port 1 of the AW9523
static constexpr uint16_t DIRECTION_MASK = (UP_PIN | DOWN_PIN | LEFT_PIN | RIGHT_PIN | A_PIN | B_PIN | X_PIN | Y_PIN | START_PIN | SELECT_PIN | BAT_ALERT_PIN | VOL_UP_PIN | VOL_DOWN_PIN);
static constexpr uint16_t INTERRUPT_MASK = (BAT_ALERT_PIN);
static constexpr uint16_t INVERT_MASK = (UP_PIN | DOWN_PIN | LEFT_PIN | RIGHT_PIN | A_PIN | B_PIN | X_PIN | Y_PIN | START_PIN | SELECT_PIN | BAT_ALERT_PIN | VOL_UP_PIN | VOL_DOWN_PIN); // pins are active low so invert them
static constexpr uint8_t PORT_0_DIRECTION_MASK = DIRECTION_MASK & 0xFF;
static constexpr uint8_t PORT_1_DIRECTION_MASK = (DIRECTION_MASK >> 8) & 0xFF;
static constexpr uint8_t PORT_0_INTERRUPT_MASK = INTERRUPT_MASK & 0xFF;
static constexpr uint8_t PORT_1_INTERRUPT_MASK = (INTERRUPT_MASK >> 8) & 0xFF;

// ADC for the battery voltage, it's on ADC2_CH3, which is IO14
static constexpr adc_unit_t BATTERY_ADC_UNIT = ADC_UNIT_2;
static constexpr adc_channel_t BATTERY_ADC_CHANNEL = ADC_CHANNEL_3;
#endif // CONFIG_HARDWARE_V1
// ADC for the battery voltage, it's on ADC2_CH3, which is IO14
static constexpr adc_unit_t BATTERY_ADC_UNIT = ADC_UNIT_2;
static constexpr adc_channel_t BATTERY_ADC_CHANNEL = ADC_CHANNEL_3;
};
4 changes: 0 additions & 4 deletions components/box-emu-hal/src/battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ static std::vector<espp::AdcConfig> channels;
using namespace std::chrono_literals;

void hal::battery_init() {
#if CONFIG_HARDWARE_V1
if (battery_initialized_) {
return;
}
Expand Down Expand Up @@ -99,9 +98,6 @@ void hal::battery_init() {
.stack_size_bytes = 3 * 1024});
battery_task_->start();
battery_initialized_ = true;
#else
fmt::print("Battery not supported on this hardware version!\n");
#endif
}

std::shared_ptr<espp::Max1704x> hal::get_battery() {
Expand Down
2 changes: 1 addition & 1 deletion components/box-emu-hal/src/box_emu_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void hal::init() {
hal::i2c_init();
// init the audio subsystem
hal::audio_init();
// init the input subsystem
// initialize the rest of the input system which is common to both v0 and v1
hal::init_input();
// initialize the video task for the emulators
hal::init_video_task();
Expand Down
Loading

0 comments on commit 86d523f

Please sign in to comment.