GBA: Hook up light sensor API
Jeffrey Pfau jeffrey@endrift.com
Thu, 25 Dec 2014 02:53:43 -0800
5 files changed,
23 insertions(+),
2 deletions(-)
M
src/gba/gba-gpio.c
→
src/gba/gba-gpio.c
@@ -322,6 +322,7 @@ void GBAGPIOInitLightSensor(struct GBACartridgeGPIO* gpio) {
gpio->gpioDevices |= GPIO_LIGHT_SENSOR; gpio->lightCounter = 0; gpio->lightEdge = false; + gpio->lightSample = 0xFF; } void _lightReadPins(struct GBACartridgeGPIO* gpio) {@@ -330,15 +331,22 @@ // Boktai chip select
return; } if (gpio->p1) { + struct GBALuminanceSource* lux = gpio->p->luminanceSource; GBALog(0, GBA_LOG_DEBUG, "[SOLAR] Got reset"); gpio->lightCounter = 0; + if (lux) { + lux->sample(lux); + gpio->lightSample = lux->readLuminance(lux); + } else { + gpio->lightSample = 0xFF; + } } if (gpio->p0 && gpio->lightEdge) { ++gpio->lightCounter; } gpio->lightEdge = !gpio->p0; - bool sendBit = gpio->lightCounter >= 0x80; + bool sendBit = gpio->lightCounter >= gpio->lightSample; _outputPins(gpio, sendBit << 3); GBALog(0, GBA_LOG_DEBUG, "[SOLAR] Output %u with pins %u", gpio->lightCounter, gpio->pinState); }
M
src/gba/gba-gpio.h
→
src/gba/gba-gpio.h
@@ -104,7 +104,8 @@
uint16_t gyroSample; bool gyroEdge; - int lightCounter : 12; + unsigned lightCounter : 12; + uint8_t lightSample; bool lightEdge; };
M
src/gba/gba-sensors.h
→
src/gba/gba-sensors.h
@@ -17,4 +17,10 @@
int32_t (*readGyroZ)(struct GBARotationSource*); }; +struct GBALuminanceSource { + void (*sample)(struct GBALuminanceSource*); + + uint8_t (*readLuminance)(struct GBALuminanceSource*); +}; + #endif
M
src/gba/gba.c
→
src/gba/gba.c
@@ -732,6 +732,10 @@ if (_overrides[i].gpio & GPIO_RUMBLE) {
GBAGPIOInitRumble(&gba->memory.gpio); } + if (_overrides[i].gpio & GPIO_LIGHT_SENSOR) { + GBAGPIOInitLightSensor(&gba->memory.gpio); + } + gba->busyLoop = _overrides[i].busyLoop; return; }
M
src/gba/gba.h
→
src/gba/gba.h
@@ -115,7 +115,9 @@ uint32_t biosChecksum;
int* keySource; uint32_t busyLoop; struct GBARotationSource* rotationSource; + struct GBALuminanceSource* luminanceSource; struct GBARumble* rumble; + struct GBARRContext* rr; void* pristineRom; size_t pristineRomSize;