all repos — mgba @ ddc1034d42a2eba9cc367ecddc331012a206bc6c

mGBA Game Boy Advance Emulator

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

 1#ifndef GBA_GPIO_H
 2#define GBA_GPIO_H
 3
 4#include <stdint.h>
 5
 6#define IS_GPIO_REGISTER(reg) ((reg) == GPIO_REG_DATA || (reg) == GPIO_REG_DIRECTION || (reg) == GPIO_REG_CONTROL)
 7
 8enum GPIODevice {
 9	GPIO_NONE = 0,
10	GPIO_RTC = 1,
11	GPIO_RUMBLE = 2,
12	GPIO_LIGHT_SENSOR = 4,
13	GPIO_GYRO = 8
14};
15
16enum GPIORegister {
17	GPIO_REG_DATA = 0xC4,
18	GPIO_REG_DIRECTION = 0xC6,
19	GPIO_REG_CONTROL = 0xC8
20};
21
22enum GPIODirection {
23	GPIO_WRITE_ONLY = 0,
24	GPIO_READ_WRITE = 1
25};
26
27struct GBARTC {
28	// TODO
29};
30
31struct GBACartridgeGPIO {
32	int gpioDevices;
33	enum GPIODirection direction;
34	uint16_t* gpioBase;
35
36	union {
37		struct {
38			unsigned p0 : 1;
39			unsigned p1 : 1;
40			unsigned p2 : 1;
41			unsigned p3 : 1;
42		};
43		uint16_t pinState;
44	};
45
46	union {
47		struct {
48			unsigned dir0 : 1;
49			unsigned dir1 : 1;
50			unsigned dir2 : 1;
51			unsigned dir3 : 1;			
52		};
53		uint16_t pinDirection;
54	};
55
56	struct GBARTC rtc;
57};
58
59void GBAGPIOInit(struct GBACartridgeGPIO* gpio, uint16_t* gpioBase);
60void GBAGPIOWrite(struct GBACartridgeGPIO* gpio, uint32_t address, uint16_t value);
61
62void GBAGPIOInitRTC(struct GBACartridgeGPIO* gpio);
63
64#endif