Extend Periphery code
This commit is contained in:
31
src/Library/internal-include/periphery_internal.hpp
Normal file
31
src/Library/internal-include/periphery_internal.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include <PSX/System/IOPorts/periphery_io.hpp>
|
||||
#include <PSX/System/IOPorts/interrupt_io.hpp>
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace Periphery {
|
||||
using namespace Periphery_IO;
|
||||
|
||||
static void busy_cycle(uint32_t cycles) {
|
||||
while(cycles--) {
|
||||
asm("");
|
||||
}
|
||||
}
|
||||
|
||||
static void connect_to(uint16_t port) {
|
||||
JOY_CTRL.write(JOY_CTRL::create_for(port));
|
||||
busy_cycle(500);
|
||||
}
|
||||
|
||||
static void close_connection() {
|
||||
JOY_CTRL.write(JOY_CTRL::close());
|
||||
}
|
||||
|
||||
static void acknowledge() {
|
||||
while(JOY_STAT.read().is_set(JOY_STAT::ACKIrqLow));
|
||||
JOY_CTRL.write(JOY_CTRL.read().set(JOY_CTRL::ACK));
|
||||
|
||||
Interrupt::ack_irq(Interrupt::Periphery);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
#include <PSX/System/IOPorts/periphery_io.hpp>
|
||||
#include "../../internal-include/periphery_internal.hpp"
|
||||
#include <PSX/System/syscalls.hpp>
|
||||
|
||||
namespace JabyEngine {
|
||||
namespace boot {
|
||||
@@ -6,6 +7,11 @@ namespace JabyEngine {
|
||||
void setup() {
|
||||
Periphery_IO::JOY_MODE.write(Periphery_IO::JOY_MODE::create());
|
||||
Periphery_IO::JOY_BAUD.write(Periphery_IO::JOY_BAUD::create());
|
||||
|
||||
SysCall::EnterCriticalSection();
|
||||
Interrupt::enable_irq(Interrupt::Periphery);
|
||||
Interrupt::ack_irq(Interrupt::Periphery);
|
||||
SysCall::ExitCriticalSection();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user