2014-12-03 08:39:06 +00:00
|
|
|
/* Copyright (c) 2013-2014 Jeffrey Pfau
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2013-10-21 01:08:18 +00:00
|
|
|
#ifndef GBA_GPIO_H
|
|
|
|
#define GBA_GPIO_H
|
|
|
|
|
2014-10-12 01:18:47 +00:00
|
|
|
#include "util/common.h"
|
2013-10-21 01:08:18 +00:00
|
|
|
|
|
|
|
#define IS_GPIO_REGISTER(reg) ((reg) == GPIO_REG_DATA || (reg) == GPIO_REG_DIRECTION || (reg) == GPIO_REG_CONTROL)
|
|
|
|
|
|
|
|
enum GPIODevice {
|
|
|
|
GPIO_NONE = 0,
|
|
|
|
GPIO_RTC = 1,
|
|
|
|
GPIO_RUMBLE = 2,
|
|
|
|
GPIO_LIGHT_SENSOR = 4,
|
2014-07-20 22:53:15 +00:00
|
|
|
GPIO_GYRO = 8,
|
|
|
|
GPIO_TILT = 16
|
2013-10-21 01:08:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum GPIORegister {
|
|
|
|
GPIO_REG_DATA = 0xC4,
|
|
|
|
GPIO_REG_DIRECTION = 0xC6,
|
|
|
|
GPIO_REG_CONTROL = 0xC8
|
|
|
|
};
|
|
|
|
|
|
|
|
enum GPIODirection {
|
|
|
|
GPIO_WRITE_ONLY = 0,
|
|
|
|
GPIO_READ_WRITE = 1
|
|
|
|
};
|
|
|
|
|
2013-10-21 04:39:47 +00:00
|
|
|
union RTCControl {
|
|
|
|
struct {
|
|
|
|
unsigned : 3;
|
|
|
|
unsigned minIRQ : 1;
|
|
|
|
unsigned : 2;
|
|
|
|
unsigned hour24 : 1;
|
|
|
|
unsigned poweroff : 1;
|
|
|
|
};
|
|
|
|
uint8_t packed;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum RTCCommand {
|
|
|
|
RTC_RESET = 0,
|
|
|
|
RTC_DATETIME = 2,
|
|
|
|
RTC_FORCE_IRQ = 3,
|
|
|
|
RTC_CONTROL = 4,
|
|
|
|
RTC_TIME = 6
|
|
|
|
};
|
|
|
|
|
|
|
|
union RTCCommandData {
|
|
|
|
struct {
|
|
|
|
unsigned magic : 4;
|
|
|
|
enum RTCCommand command : 3;
|
|
|
|
unsigned reading : 1;
|
|
|
|
};
|
|
|
|
uint8_t packed;
|
|
|
|
};
|
|
|
|
|
2013-10-21 01:08:18 +00:00
|
|
|
struct GBARTC {
|
2013-10-21 04:39:47 +00:00
|
|
|
int bytesRemaining;
|
|
|
|
int transferStep;
|
|
|
|
int bitsRead;
|
|
|
|
int bits;
|
|
|
|
int commandActive;
|
|
|
|
union RTCCommandData command;
|
|
|
|
union RTCControl control;
|
|
|
|
uint8_t time[7];
|
2014-07-20 22:53:15 +00:00
|
|
|
} __attribute__((packed));
|
2013-10-21 01:08:18 +00:00
|
|
|
|
2013-10-22 04:50:29 +00:00
|
|
|
struct GBARumble {
|
|
|
|
void (*setRumble)(struct GBARumble*, int enable);
|
|
|
|
};
|
|
|
|
|
2013-10-21 01:08:18 +00:00
|
|
|
struct GBACartridgeGPIO {
|
2013-10-21 09:54:52 +00:00
|
|
|
struct GBA* p;
|
2013-10-21 01:08:18 +00:00
|
|
|
int gpioDevices;
|
2013-10-21 04:39:47 +00:00
|
|
|
enum GPIODirection readWrite;
|
2013-10-21 01:08:18 +00:00
|
|
|
uint16_t* gpioBase;
|
|
|
|
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
unsigned p0 : 1;
|
|
|
|
unsigned p1 : 1;
|
|
|
|
unsigned p2 : 1;
|
|
|
|
unsigned p3 : 1;
|
|
|
|
};
|
|
|
|
uint16_t pinState;
|
|
|
|
};
|
|
|
|
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
unsigned dir0 : 1;
|
|
|
|
unsigned dir1 : 1;
|
|
|
|
unsigned dir2 : 1;
|
|
|
|
unsigned dir3 : 1;
|
|
|
|
};
|
2013-10-21 04:39:47 +00:00
|
|
|
uint16_t direction;
|
2013-10-21 01:08:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct GBARTC rtc;
|
2013-10-21 09:54:52 +00:00
|
|
|
|
|
|
|
uint16_t gyroSample;
|
2014-07-20 22:53:15 +00:00
|
|
|
bool gyroEdge;
|
2014-12-25 10:38:10 +00:00
|
|
|
|
2014-12-25 10:53:43 +00:00
|
|
|
unsigned lightCounter : 12;
|
|
|
|
uint8_t lightSample;
|
2014-12-25 10:38:10 +00:00
|
|
|
bool lightEdge;
|
2013-10-21 01:08:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void GBAGPIOInit(struct GBACartridgeGPIO* gpio, uint16_t* gpioBase);
|
|
|
|
void GBAGPIOWrite(struct GBACartridgeGPIO* gpio, uint32_t address, uint16_t value);
|
|
|
|
|
|
|
|
void GBAGPIOInitRTC(struct GBACartridgeGPIO* gpio);
|
2013-10-21 09:54:52 +00:00
|
|
|
void GBAGPIOInitGyro(struct GBACartridgeGPIO* gpio);
|
2013-10-22 04:50:29 +00:00
|
|
|
void GBAGPIOInitRumble(struct GBACartridgeGPIO* gpio);
|
2014-12-25 10:38:10 +00:00
|
|
|
void GBAGPIOInitLightSensor(struct GBACartridgeGPIO* gpio);
|
2014-12-31 12:43:06 +00:00
|
|
|
void GBAGPIOInitTilt(struct GBACartridgeGPIO* gpio);
|
2014-12-25 10:38:10 +00:00
|
|
|
|
2014-07-20 22:53:15 +00:00
|
|
|
struct GBASerializedState;
|
|
|
|
void GBAGPIOSerialize(struct GBACartridgeGPIO* gpio, struct GBASerializedState* state);
|
|
|
|
void GBAGPIODeserialize(struct GBACartridgeGPIO* gpio, struct GBASerializedState* state);
|
|
|
|
|
2013-10-21 01:08:18 +00:00
|
|
|
#endif
|