mirror of
https://github.com/TomHarte/CLK.git
synced 2025-08-08 14:25:05 +00:00
Transfer logging responsibility.
This commit is contained in:
@@ -8,8 +8,16 @@
|
|||||||
|
|
||||||
#include "I2C.hpp"
|
#include "I2C.hpp"
|
||||||
|
|
||||||
|
#include "../../Outputs/Log.hpp"
|
||||||
|
|
||||||
using namespace I2C;
|
using namespace I2C;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
Log::Logger<Log::Source::I2C> logger;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void Bus::set_data(bool pulled) {
|
void Bus::set_data(bool pulled) {
|
||||||
set_clock_data(clock_, pulled);
|
set_clock_data(clock_, pulled);
|
||||||
}
|
}
|
||||||
@@ -34,6 +42,8 @@ void Bus::set_clock_data(bool clock_pulled, bool data_pulled) {
|
|||||||
clock_ = clock_pulled;
|
clock_ = clock_pulled;
|
||||||
data_ = data_pulled;
|
data_ = data_pulled;
|
||||||
|
|
||||||
|
logger.info().append("C:%d D:%d", clock_, data_);
|
||||||
|
|
||||||
// Advance peripheral input from peripheral if clock
|
// Advance peripheral input from peripheral if clock
|
||||||
// transitions from high to low.
|
// transitions from high to low.
|
||||||
if(peripheral_bits_ && prior_clock && !clock_) {
|
if(peripheral_bits_ && prior_clock && !clock_) {
|
||||||
@@ -48,11 +58,18 @@ void Bus::set_clock_data(bool clock_pulled, bool data_pulled) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const auto await_byte = [&] {
|
||||||
|
peripheral_response_ = 0;
|
||||||
|
peripheral_bits_ = 2;
|
||||||
|
phase_ = Phase::AwaitingByte;
|
||||||
|
logger.info().append("Waiting for byte");
|
||||||
|
};
|
||||||
|
|
||||||
// Check for stop condition at any time.
|
// Check for stop condition at any time.
|
||||||
// "A LOW-to-HIGH transition of the data line
|
// "A LOW-to-HIGH transition of the data line
|
||||||
// while the clock is HIGH is defined as the STOP condition".
|
// while the clock is HIGH is defined as the STOP condition".
|
||||||
if(prior_data && !data_ && !clock_) {
|
if(prior_data && !data_ && !clock_) {
|
||||||
printf("Stopped\n");
|
logger.info().append("Stopped");
|
||||||
phase_ = Phase::AwaitingStart;
|
phase_ = Phase::AwaitingStart;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,44 +81,44 @@ void Bus::set_clock_data(bool clock_pulled, bool data_pulled) {
|
|||||||
phase_ = Phase::CollectingAddress;
|
phase_ = Phase::CollectingAddress;
|
||||||
input_count_ = 0;
|
input_count_ = 0;
|
||||||
input_ = 0;
|
input_ = 0;
|
||||||
printf("Waiting for [remainder of] address\n");
|
logger.info().append("Waiting for [remainder of] address");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Phase::CollectingAddress:
|
case Phase::CollectingAddress:
|
||||||
capture_bit();
|
capture_bit();
|
||||||
if(input_count_ == 8) {
|
if(input_count_ == 8) {
|
||||||
printf("Addressed %02x?\n", uint8_t(input_));
|
logger.info().append("Addressed %02x with %s?", uint8_t(input_) & 0xfe, input_ & 1 ? "read" : "write");
|
||||||
|
|
||||||
auto pair = peripherals_.find(uint8_t(input_));
|
auto pair = peripherals_.find(uint8_t(input_) & 0xfe);
|
||||||
if(pair != peripherals_.end()) {
|
if(pair != peripherals_.end()) {
|
||||||
active_peripheral_ = pair->second;
|
active_peripheral_ = pair->second;
|
||||||
|
|
||||||
peripheral_response_ = 0;
|
await_byte();
|
||||||
peripheral_bits_ = 1;
|
|
||||||
phase_ = Phase::AwaitingByte;
|
|
||||||
printf("Waiting for byte\n");
|
|
||||||
} else {
|
} else {
|
||||||
phase_ = Phase::AwaitingStart;
|
phase_ = Phase::AwaitingStart;
|
||||||
printf("No device\n");
|
logger.info().append("No device; not acknowledging");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Phase::AwaitingByte:
|
case Phase::AwaitingByte:
|
||||||
// Run down the clock on the acknowledge bit.
|
// Run down the clock on the acknowledge bit.
|
||||||
if(!peripheral_bits_) {
|
if(peripheral_bits_) {
|
||||||
printf("Beginning byte\n");
|
return;
|
||||||
phase_ = Phase::CollectingByte;
|
|
||||||
input_count_ = 0;
|
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
logger.info().append("Beginning byte");
|
||||||
|
phase_ = Phase::CollectingByte;
|
||||||
|
input_count_ = 0;
|
||||||
|
[[fallthrough]];
|
||||||
|
|
||||||
case Phase::CollectingByte:
|
case Phase::CollectingByte:
|
||||||
capture_bit();
|
capture_bit();
|
||||||
if(input_count_ == 8) {
|
if(input_count_ == 8) {
|
||||||
printf("Got byte %02x?\n", uint8_t(input_));
|
logger.info().append("Got byte %02x?", uint8_t(input_));
|
||||||
phase_ = Phase::AwaitingByte;
|
|
||||||
|
await_byte();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -389,10 +389,10 @@ struct Interrupts {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x3200000 & AddressMask:
|
case 0x3200000 & AddressMask:
|
||||||
logger.error().append("TODO: IOC control read");
|
value = control_ | 0xc0;
|
||||||
value = control_;
|
|
||||||
value &= ~(i2c_.clock() ? 2 : 0);
|
value &= ~(i2c_.clock() ? 2 : 0);
|
||||||
value &= ~(i2c_.data() ? 1 : 0);
|
value &= ~(i2c_.data() ? 1 : 0);
|
||||||
|
// logger.error().append("IOC control read: C:%d D:%d", !(value & 2), !(value & 1));
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case 0x3200004 & AddressMask:
|
case 0x3200004 & AddressMask:
|
||||||
@@ -472,11 +472,11 @@ struct Interrupts {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x320'0000 & AddressMask:
|
case 0x320'0000 & AddressMask:
|
||||||
|
// TODO: does the rest of the control register relate to anything?
|
||||||
|
// logger.error().append("TODO: IOC control write: C:%d D:%d", !(value & 2), !(value & 1));
|
||||||
|
|
||||||
control_ = value;
|
control_ = value;
|
||||||
i2c_.set_clock_data(!(value & 2), !(value & 1));
|
i2c_.set_clock_data(!(value & 2), !(value & 1));
|
||||||
|
|
||||||
// TODO: rest relates to floppy control, maybe?
|
|
||||||
logger.error().append("TODO: IOC control write %02x", value);
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case 0x320'0004 & AddressMask:
|
case 0x320'0004 & AddressMask:
|
||||||
|
@@ -31,6 +31,7 @@ enum class Source {
|
|||||||
DirectAccessDevice,
|
DirectAccessDevice,
|
||||||
Enterprise,
|
Enterprise,
|
||||||
i8272,
|
i8272,
|
||||||
|
I2C,
|
||||||
IntelligentKeyboard,
|
IntelligentKeyboard,
|
||||||
IWM,
|
IWM,
|
||||||
M50740,
|
M50740,
|
||||||
@@ -95,6 +96,7 @@ constexpr const char *prefix(Source source) {
|
|||||||
case Source::DirectAccessDevice: return "Direct Access Device";
|
case Source::DirectAccessDevice: return "Direct Access Device";
|
||||||
case Source::Enterprise: return "Enterprise";
|
case Source::Enterprise: return "Enterprise";
|
||||||
case Source::i8272: return "i8272";
|
case Source::i8272: return "i8272";
|
||||||
|
case Source::I2C: return "I2C";
|
||||||
case Source::IntelligentKeyboard: return "IKYB";
|
case Source::IntelligentKeyboard: return "IKYB";
|
||||||
case Source::IWM: return "IWM";
|
case Source::IWM: return "IWM";
|
||||||
case Source::M50740: return "M50740";
|
case Source::M50740: return "M50740";
|
||||||
|
Reference in New Issue
Block a user