all repos — mgba @ 7e5eada69baa4d29c56c6e45654306efae11a4ab

mGBA Game Boy Advance Emulator

src/gba/gba-gpio.c (view raw)

 1#include "gba.h"
 2
 3#include "gba-gpio.h"
 4
 5static void _readPins(struct GBACartridgeGPIO* gpio);
 6
 7static void _rtcReadPins(struct GBACartridgeGPIO* gpio);
 8
 9void GBAGPIOInit(struct GBACartridgeGPIO* gpio, uint16_t* base) {
10	gpio->gpioDevices = GPIO_NONE;
11	gpio->direction = GPIO_WRITE_ONLY;
12	gpio->gpioBase = base;
13	gpio->pinState = 0;
14	gpio->pinDirection = 0;
15}
16
17void GBAGPIOWrite(struct GBACartridgeGPIO* gpio, uint32_t address, uint16_t value) {
18	switch (address) {
19	case GPIO_REG_DATA:
20		gpio->pinState = value;
21		_readPins(gpio);
22		break;
23	case GPIO_REG_DIRECTION:
24		gpio->pinDirection = value;
25		break;
26	case GPIO_REG_CONTROL:
27		gpio->direction = value;
28		break;
29	default:
30		GBALog(0, GBA_LOG_WARN, "Invalid GPIO address");
31	}
32}
33
34void GBAGPIOInitRTC(struct GBACartridgeGPIO* gpio) {
35	// TODO
36}
37
38void _readPins(struct GBACartridgeGPIO* gpio) {
39	if (gpio->gpioDevices & GPIO_RTC) {
40		_rtcReadPins(gpio);
41	}
42}
43
44void _rtcReadPins(struct GBACartridgeGPIO* gpio) {
45	// TODO
46}