Integrate all the progress into master #6
|
@ -0,0 +1,52 @@
|
|||
#pragma once
|
||||
#include "../ioport.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace Periphery_IO_Values {
|
||||
__declare_io_value(JOY_BAUD, uint16_t) {
|
||||
static constexpr JOY_BAUD create() {
|
||||
return JOY_BAUD{0x0088};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_value(JOY_CTRL, uint16_t) {
|
||||
static constexpr auto TXEnable = Bit(0);
|
||||
static constexpr auto SelectJoy = Bit(1);
|
||||
static constexpr auto ACK = Bit(4);
|
||||
static constexpr auto ACKIrqEnable = Bit(12);
|
||||
static constexpr auto PortBSelected = Bit(13);
|
||||
static constexpr auto PortASelected = !PortBSelected;
|
||||
|
||||
static constexpr JOY_CTRL create_for(uint16_t port) {
|
||||
return JOY_CTRL{static_cast<uint16_t>(port << PortBSelected)}.set(TXEnable, SelectJoy, ACKIrqEnable);
|
||||
}
|
||||
|
||||
static constexpr JOY_CTRL close() {
|
||||
return JOY_CTRL{0};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_value(JOY_MODE, uint16_t) {
|
||||
static constexpr JOY_MODE create() {
|
||||
return JOY_MODE{0x000D};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_value(JOY_RX_DATA, uint8_t) {
|
||||
};
|
||||
|
||||
__declare_io_value(JOY_STAT, uint32_t) {
|
||||
static constexpr auto TXReadyStart = Bit(0);
|
||||
static constexpr auto RXFifoNonEmpty = Bit(1);
|
||||
static constexpr auto TXReadyFinished = Bit(2);
|
||||
static constexpr auto RXParityError = Bit(3);
|
||||
static constexpr auto ACKIrqLow = Bit(7);
|
||||
};
|
||||
|
||||
__declare_io_value(JOY_TX_DATA, uint32_t) {
|
||||
static constexpr JOY_TX_DATA create(uint8_t byte) {
|
||||
return JOY_TX_DATA{byte};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,67 +1,31 @@
|
|||
#pragma once
|
||||
#include "ioport.hpp"
|
||||
#include "IOValues/periphery_io_values.hpp"
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace Periphery_IO {
|
||||
__declare_io_value(JOY_TX_DATA, uint32_t) {
|
||||
static constexpr JOY_TX_DATA create(uint8_t byte) {
|
||||
return JOY_TX_DATA{byte};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_value(JOY_RX_DATA, uint8_t) {
|
||||
};
|
||||
|
||||
__declare_io_value(JOY_STAT, uint32_t) {
|
||||
static constexpr auto TXReadyStart = Bit(0);
|
||||
static constexpr auto RXFifoNonEmpty = Bit(1);
|
||||
static constexpr auto TXReadyFinished = Bit(2);
|
||||
static constexpr auto RXParityError = Bit(3);
|
||||
static constexpr auto ACKIrqLow = Bit(7);
|
||||
namespace Value = Periphery_IO_Values;
|
||||
|
||||
struct JOY_STAT_IO : public IOPort<Value::JOY_STAT> {
|
||||
inline bool has_response() const {
|
||||
return this->is_set(RXFifoNonEmpty);
|
||||
return this->read().is_set(Value::JOY_STAT::RXFifoNonEmpty);
|
||||
}
|
||||
|
||||
inline bool is_ready_transfer() const {
|
||||
return this->is_set(TXReadyFinished);
|
||||
return this->read().is_set(Value::JOY_STAT::TXReadyFinished);
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_value(JOY_CTRL, uint16_t) {
|
||||
static constexpr auto TXEnable = Bit(0);
|
||||
static constexpr auto SelectJoy = Bit(1);
|
||||
static constexpr auto ACK = Bit(4);
|
||||
static constexpr auto ACKIrqEnable = Bit(12);
|
||||
static constexpr auto PortBSelected = Bit(13);
|
||||
static constexpr auto PortASelected = !PortBSelected;
|
||||
using JOY_BAUD_IO = IOPort<Value::JOY_BAUD>;
|
||||
using JOY_CTRL_IO = IOPort<Value::JOY_CTRL>;
|
||||
using JOY_MODE_IO = IOPort<Value::JOY_MODE>;
|
||||
using JOY_RX_DATA_IO = IOPort<Value::JOY_RX_DATA>;
|
||||
using JOY_TX_DATA_IO = IOPort<Value::JOY_TX_DATA>;
|
||||
|
||||
static constexpr JOY_CTRL create_for(uint16_t port) {
|
||||
return JOY_CTRL{static_cast<uint16_t>(port << PortBSelected)}.set(TXEnable, SelectJoy, ACKIrqEnable);
|
||||
}
|
||||
|
||||
static constexpr JOY_CTRL close() {
|
||||
return JOY_CTRL{0};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_value(JOY_MODE, uint16_t) {
|
||||
static constexpr JOY_MODE create() {
|
||||
return JOY_MODE{0x000D};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_value(JOY_BAUD, uint16_t) {
|
||||
static constexpr JOY_BAUD create() {
|
||||
return JOY_BAUD{0x0088};
|
||||
}
|
||||
};
|
||||
|
||||
__declare_io_port(, JOY_TX_DATA, 0x1F801040);
|
||||
__declare_io_port(const, JOY_RX_DATA, 0x1F801040);
|
||||
__declare_io_port(const, JOY_STAT, 0x1F801044);
|
||||
__declare_io_port(, JOY_MODE, 0x1F801048);
|
||||
__declare_io_port(, JOY_CTRL, 0x1F80104A);
|
||||
__declare_io_port(, JOY_BAUD, 0x1F80104E);
|
||||
static auto& JOY_TX_DATA = __new_declare_io_port(JOY_TX_DATA_IO, 0x1F801040);
|
||||
static const auto& JOY_RX_DATA = __new_declare_io_port(JOY_RX_DATA_IO, 0x1F801040);
|
||||
static const auto& JOY_STAT = __new_declare_io_port(JOY_STAT_IO, 0x1F801044);
|
||||
static auto& JOY_MODE = __new_declare_io_port(JOY_MODE_IO, 0x1F801048);
|
||||
static auto& JOY_CTRL = __new_declare_io_port(JOY_CTRL_IO, 0x1F80104A);
|
||||
static auto& JOY_BAUD = __new_declare_io_port(JOY_BAUD_IO, 0x1F80104E);
|
||||
}
|
||||
}
|
|
@ -11,27 +11,27 @@ namespace JabyEngine {
|
|||
using namespace Periphery_IO;
|
||||
|
||||
static void connect_to(uint16_t port) {
|
||||
JOY_CTRL.write(JOY_CTRL::create_for(port));
|
||||
JOY_CTRL.write(Value::JOY_CTRL::create_for(port));
|
||||
busy_loop(500);
|
||||
}
|
||||
|
||||
static void close_connection() {
|
||||
JOY_CTRL.write(JOY_CTRL::close());
|
||||
JOY_CTRL.write(Value::JOY_CTRL::close());
|
||||
}
|
||||
|
||||
static void send_byte(uint8_t byte) {
|
||||
while(!JOY_STAT.read().is_ready_transfer());
|
||||
JOY_TX_DATA.write(JOY_TX_DATA::create(byte));
|
||||
while(!JOY_STAT.is_ready_transfer());
|
||||
JOY_TX_DATA.write(Value::JOY_TX_DATA::create(byte));
|
||||
}
|
||||
|
||||
static uint8_t read_byte() {
|
||||
while(!JOY_STAT.read().has_response());
|
||||
while(!JOY_STAT.has_response());
|
||||
return JOY_RX_DATA.read().raw;
|
||||
}
|
||||
|
||||
static void acknowledge() {
|
||||
while(JOY_STAT.read().is_set(JOY_STAT::ACKIrqLow));
|
||||
JOY_CTRL.write(JOY_CTRL.read().set(JOY_CTRL::ACK));
|
||||
while(JOY_STAT.read().is_set(Value::JOY_STAT::ACKIrqLow));
|
||||
JOY_CTRL.write(JOY_CTRL.read().set(Value::JOY_CTRL::ACK));
|
||||
|
||||
Interrupt::ack_irq(Interrupt::Periphery);
|
||||
}
|
||||
|
|
|
@ -5,8 +5,8 @@ namespace JabyEngine {
|
|||
namespace boot {
|
||||
namespace Periphery {
|
||||
void setup() {
|
||||
Periphery_IO::JOY_MODE.write(Periphery_IO::JOY_MODE::create());
|
||||
Periphery_IO::JOY_BAUD.write(Periphery_IO::JOY_BAUD::create());
|
||||
Periphery_IO::JOY_MODE.write(Periphery_IO_Values::JOY_MODE::create());
|
||||
Periphery_IO::JOY_BAUD.write(Periphery_IO_Values::JOY_BAUD::create());
|
||||
|
||||
SysCall::EnterCriticalSection();
|
||||
Interrupt::disable_irq(Interrupt::Periphery);
|
||||
|
|
Loading…
Reference in New Issue