Actually use the device

This commit is contained in:
Pokechu22 2022-09-03 18:27:55 -07:00
parent 6b21b41b2f
commit 89a5108e46
2 changed files with 45 additions and 25 deletions

View File

@ -15,15 +15,6 @@
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Core/Debugger/Debugger_SymbolMap.h" #include "Core/Debugger/Debugger_SymbolMap.h"
namespace IOS
{
struct AVEState;
extern AVEState ave_state;
extern std::bitset<0x100> ave_ever_logged; // For logging only; not saved
std::string_view GetAVERegisterName(u8 address);
} // namespace IOS
namespace Common namespace Common
{ {
void I2CBusBase::AddSlave(I2CSlave* slave) void I2CBusBase::AddSlave(I2CSlave* slave)
@ -211,9 +202,25 @@ void I2CBus::SCLRisingEdge(const bool sda)
{ {
// Start of a read. // Start of a read.
ASSERT(device_address.has_value()); // Implied by the state transition in falling edge ASSERT(device_address.has_value()); // Implied by the state transition in falling edge
current_byte = reinterpret_cast<u8*>(&IOS::ave_state)[device_address.value()]; ASSERT(i2c_address.has_value());
INFO_LOG_FMT(WII_IPC, "AVE: Read from {:02x} ({}) -> {:02x}", device_address.value(), I2CSlave* slave = GetSlave(i2c_address.value());
IOS::GetAVERegisterName(device_address.value()), current_byte); ASSERT_MSG(WII_IPC, slave != nullptr,
"Expected device with ID {:02x} to be on the I2C bus as it was earlier",
i2c_address.value());
std::optional<u8> byte = slave->ReadByte(device_address.value());
if (!byte.has_value())
{
WARN_LOG_FMT(WII_IPC, "Failed to read from device {:02x} at address {:02x}",
i2c_address.value(), device_address.value());
// TODO
current_byte = 0xff;
}
else
{
current_byte = byte.value();
}
// INFO_LOG_FMT(WII_IPC, "AVE: Read from {:02x} ({}) -> {:02x}", device_address.value(),
// IOS::GetAVERegisterName(device_address.value()), current_byte);
} }
// Dolphin_Debugger::PrintCallstack(Common::Log::LogType::WII_IPC, Common::Log::LogLevel::LINFO); // Dolphin_Debugger::PrintCallstack(Common::Log::LogType::WII_IPC, Common::Log::LogLevel::LINFO);
} }
@ -247,7 +254,8 @@ void I2CBus::SCLFallingEdge(const bool sda)
// Write finished. // Write finished.
if (state == State::SetI2CAddress) if (state == State::SetI2CAddress)
{ {
if ((current_byte >> 1) != 0x70) I2CSlave* slave = GetSlave(current_byte);
if (slave != nullptr)
{ {
state = State::Inactive; // NACK state = State::Inactive; // NACK
WARN_LOG_FMT(WII_IPC, "AVE: Unknown I2C address {:02x}", current_byte); WARN_LOG_FMT(WII_IPC, "AVE: Unknown I2C address {:02x}", current_byte);
@ -267,20 +275,32 @@ void I2CBus::SCLFallingEdge(const bool sda)
// Actual write // Actual write
ASSERT(state == State::WriteToDevice); ASSERT(state == State::WriteToDevice);
ASSERT(device_address.has_value()); // implied by state transition ASSERT(device_address.has_value()); // implied by state transition
const u8 old_ave_value = reinterpret_cast<u8*>(&IOS::ave_state)[device_address.value()]; ASSERT(i2c_address.has_value());
reinterpret_cast<u8*>(&IOS::ave_state)[device_address.value()] = current_byte; I2CSlave* slave = GetSlave(i2c_address.value());
if (!IOS::ave_ever_logged[device_address.value()] || old_ave_value != current_byte) ASSERT_MSG(WII_IPC, slave != nullptr,
"Expected device with ID {:02x} to be on the I2C bus as it was earlier",
i2c_address.value());
if (slave == nullptr)
{ {
INFO_LOG_FMT(WII_IPC, "AVE: Wrote {:02x} to {:02x} ({})", current_byte, state = State::Inactive; // NACK
device_address.value(), IOS::GetAVERegisterName(device_address.value()));
IOS::ave_ever_logged[device_address.value()] = true;
} }
else else
{ {
DEBUG_LOG_FMT(WII_IPC, "AVE: Wrote {:02x} to {:02x} ({})", current_byte, slave->WriteByte(device_address.value(), current_byte);
device_address.value(), IOS::GetAVERegisterName(device_address.value())); /* if (!IOS::ave_ever_logged[device_address.value()] || old_ave_value != current_byte)
{
INFO_LOG_FMT(WII_IPC, "AVE: Wrote {:02x} to {:02x} ({})", current_byte,
device_address.value(), IOS::GetAVERegisterName(device_address.value()));
IOS::ave_ever_logged[device_address.value()] = true;
}
else
{
DEBUG_LOG_FMT(WII_IPC, "AVE: Wrote {:02x} to {:02x} ({})", current_byte,
device_address.value(),
IOS::GetAVERegisterName(device_address.value()));
}*/
device_address = device_address.value() + 1;
} }
device_address = device_address.value() + 1;
} }
} }
} }

View File

@ -120,7 +120,7 @@ struct AVEState
}; };
#pragma pack() #pragma pack()
static_assert(sizeof(AVEState) == 0x100); static_assert(sizeof(AVEState) == 0x100);
AVEState ave_state; Common::I2CSlaveSimple<0x70, AVEState> ave_state;
std::bitset<sizeof(AVEState)> ave_ever_logged; std::bitset<sizeof(AVEState)> ave_ever_logged;
Common::I2CBus i2c_state; Common::I2CBus i2c_state;
@ -145,7 +145,7 @@ void WiiIPC::DoState(PointerWrap& p)
p.Do(m_gpio_dir); p.Do(m_gpio_dir);
p.Do(m_gpio_out); p.Do(m_gpio_out);
i2c_state.DoState(p); i2c_state.DoState(p);
p.Do(ave_state); p.Do(ave_state.data);
p.Do(m_resets); p.Do(m_resets);
} }
@ -178,7 +178,7 @@ void WiiIPC::InitState()
i2c_state = {}; i2c_state = {};
ave_state = {}; ave_state = {};
ave_state.video_output_config = 0x23; ave_state.data.video_output_config = 0x23;
ave_ever_logged.reset(); ave_ever_logged.reset();
} }