-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
693 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "common.h" | ||
#include "RomGpioRtc.h" | ||
#include "RomGpio.h" | ||
|
||
RomGpio gRomGpio; | ||
static RomGpioRtc sRomGpioRtc; | ||
|
||
void RomGpio::Initialize(rio_registers_t* romGpioRegisters) | ||
{ | ||
_registers = romGpioRegisters; | ||
_registersRomData = *romGpioRegisters; | ||
Reset(); | ||
} | ||
|
||
void RomGpio::Reset() | ||
{ | ||
_inputData = 0; | ||
_outputData = 0; | ||
_direction = 0; | ||
_control = RIO_CONTROL_READ_DISABLE; | ||
UpdateRomRegisters(); | ||
} | ||
|
||
void RomGpio::UpdateRomRegisters() | ||
{ | ||
if (_control == RIO_CONTROL_READ_DISABLE) | ||
{ | ||
// When reading of the registers is disabled, the original rom data is read. | ||
*_registers = _registersRomData; | ||
} | ||
else | ||
{ | ||
_registers->data = GetGpioState(); | ||
_registers->direction = _direction; | ||
_registers->control = RIO_CONTROL_READ_ENABLE; | ||
} | ||
} | ||
|
||
static void updateRomGpioPeripherals() | ||
{ | ||
sRomGpioRtc.Update(gRomGpio); | ||
} | ||
|
||
extern "C" void rio_write(u32 offset, u16 value) | ||
{ | ||
switch (offset) | ||
{ | ||
case offsetof(rio_registers_t, data): | ||
{ | ||
gRomGpio.WriteDataRegister(value); | ||
updateRomGpioPeripherals(); | ||
break; | ||
} | ||
case offsetof(rio_registers_t, direction): | ||
{ | ||
gRomGpio.WriteDirectionRegister(value); | ||
updateRomGpioPeripherals(); | ||
break; | ||
} | ||
case offsetof(rio_registers_t, control): | ||
{ | ||
gRomGpio.WriteControlRegister(value); | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#pragma once | ||
|
||
#define RIO_GBA_ADDRESS 0x080000C4 | ||
|
||
#define RIO_PIN_MASK 0xF | ||
|
||
#define RIO_CONTROL_READ_DISABLE 0 | ||
#define RIO_CONTROL_READ_ENABLE 1 | ||
#define RIO_CONTROL_MASK 1 | ||
|
||
struct rio_registers_t | ||
{ | ||
u16 data; | ||
u16 direction; | ||
u16 control; | ||
}; | ||
|
||
class RomGpio | ||
{ | ||
public: | ||
void Initialize(rio_registers_t* romGpioRegisters); | ||
void Reset(); | ||
void UpdateRomRegisters(); | ||
|
||
void WriteDataRegister(u16 value) | ||
{ | ||
_outputData = value & RIO_PIN_MASK; | ||
UpdateRomRegisters(); | ||
} | ||
|
||
void WriteDirectionRegister(u16 value) | ||
{ | ||
_direction = value & RIO_PIN_MASK; | ||
UpdateRomRegisters(); | ||
} | ||
|
||
void WriteControlRegister(u16 value) | ||
{ | ||
_control = value & RIO_CONTROL_MASK; | ||
UpdateRomRegisters(); | ||
} | ||
|
||
bool GetPinState(u32 pin) | ||
{ | ||
return (GetGpioState() >> pin) & 1; | ||
} | ||
|
||
void SetPinState(u32 pin, bool isHigh) | ||
{ | ||
u32 mask = (1 << pin) & RIO_PIN_MASK; | ||
if (isHigh) | ||
{ | ||
_inputData |= mask; | ||
} | ||
else | ||
{ | ||
_inputData &= ~mask; | ||
} | ||
|
||
UpdateRomRegisters(); | ||
} | ||
|
||
private: | ||
/// @brief Pointer to the actual registers readable by the GBA side. | ||
rio_registers_t* _registers; | ||
|
||
/// @brief The rom data behind the gpio registers. | ||
rio_registers_t _registersRomData; | ||
|
||
/// @brief The input data from the gpio pins. | ||
u16 _inputData; | ||
|
||
/// @brief The internal output data register. | ||
u16 _outputData; | ||
|
||
/// @brief The internal direction register. | ||
u16 _direction; | ||
|
||
/// @brief The internal control register. | ||
u16 _control; | ||
|
||
u32 GetGpioState() | ||
{ | ||
return (_inputData & ~_direction) | (_outputData & _direction); | ||
} | ||
}; | ||
|
||
extern RomGpio gRomGpio; |
Oops, something went wrong.