Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

box-emu: Update to explicitly define io address and improve loggingg #83

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions components/box-emu/include/box-emu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class BoxEmu : public espp::BaseComponent {
struct version0 {
using InputDriver = espp::Mcp23x17;
typedef Input<version0, InputDriver> InputType;
static constexpr auto input_address = InputDriver::DEFAULT_ADDRESS;
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
Expand All @@ -227,6 +228,7 @@ class BoxEmu : public espp::BaseComponent {
struct version1 {
using InputDriver = espp::Aw9523;
typedef Input<version1, InputDriver> InputType;
static constexpr auto input_address = InputDriver::DEFAULT_ADDRESS;
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
Expand Down
12 changes: 8 additions & 4 deletions components/box-emu/src/box-emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ BoxEmu::Version BoxEmu::version() const {
}

void BoxEmu::detect() {
bool mcp23x17_found = external_i2c_.probe_device(espp::Mcp23x17::DEFAULT_ADDRESS);
bool aw9523_found = external_i2c_.probe_device(espp::Aw9523::DEFAULT_ADDRESS);
if (aw9523_found) {
bool version0_found = external_i2c_.probe_device(version0::input_address);
bool version1_found = external_i2c_.probe_device(version1::input_address);
if (version1_found) {
// Version 1
version_ = BoxEmu::Version::V1;
} else if (mcp23x17_found) {
} else if (version0_found) {
// Version 0
version_ = BoxEmu::Version::V0;
} else {
logger_.warn("No box-emu hardware detected");
logger_.warn("\tProbed for MCP23x17 (version0) at 0x{:02x}", version0::input_address);
logger_.warn("\tProbed for AW9523 (version1) at 0x{:02x}", version1::input_address);
// No box detected
version_ = BoxEmu::Version::UNKNOWN;
return;
Expand Down Expand Up @@ -230,6 +232,7 @@ bool BoxEmu::initialize_gamepad() {
if (version_ == BoxEmu::Version::V0) {
auto raw_input = new version0::InputType(
std::make_shared<version0::InputDriver>(version0::InputDriver::Config{
.device_address = version0::input_address,
.port_0_direction_mask = version0::PORT_0_DIRECTION_MASK,
.port_0_interrupt_mask = version0::PORT_0_INTERRUPT_MASK,
.port_1_direction_mask = version0::PORT_1_DIRECTION_MASK,
Expand All @@ -243,6 +246,7 @@ bool BoxEmu::initialize_gamepad() {
} else if (version_ == BoxEmu::Version::V1) {
auto raw_input = new version1::InputType(
std::make_shared<version1::InputDriver>(version1::InputDriver::Config{
.device_address = version1::input_address,
.port_0_direction_mask = version1::PORT_0_DIRECTION_MASK,
.port_0_interrupt_mask = version1::PORT_0_INTERRUPT_MASK,
.port_1_direction_mask = version1::PORT_1_DIRECTION_MASK,
Expand Down