Re-add the power button support with a temporary (?) bugfix

This commit is contained in:
Aurora 2016-11-14 01:56:52 +01:00
parent 2938bbd11f
commit da4f3a72af
3 changed files with 38 additions and 1 deletions

View File

@ -25,6 +25,7 @@
*/
#include "i2c.h"
#include "utils.h"
//-----------------------------------------------------------------------------
@ -115,6 +116,31 @@ static bool i2cSelectRegister(u8 bus_id, u8 reg)
//-----------------------------------------------------------------------------
u8 i2cReadRegister(u8 dev_id, u8 reg)
{
u8 bus_id = i2cGetDeviceBusId(dev_id),
dev_addr = i2cGetDeviceRegAddr(dev_id);
for(u32 i = 0; i < 8; i++)
{
if(i2cSelectDevice(bus_id, dev_addr) && i2cSelectRegister(bus_id, reg))
{
if(i2cSelectDevice(bus_id, dev_addr | 1))
{
i2cWaitBusy(bus_id);
i2cStop(bus_id, 1);
i2cWaitBusy(bus_id);
return *i2cGetDataReg(bus_id);
}
}
*i2cGetCntReg(bus_id) = 0xC5;
i2cWaitBusy(bus_id);
}
return 0xFF;
}
bool i2cWriteRegister(u8 dev_id, u8 reg, u8 data)
{
u8 bus_id = i2cGetDeviceBusId(dev_id),
@ -129,7 +155,16 @@ bool i2cWriteRegister(u8 dev_id, u8 reg, u8 data)
*i2cGetCntReg(bus_id) = 0xC1;
i2cStop(bus_id, 0);
if(i2cGetResult(bus_id)) return true;
if(i2cGetResult(bus_id))
{
if(dev_id == I2C_DEV_MCU)
{
startChrono();
while(chrono(true) < 2);
}
return true;
}
}
*i2cGetCntReg(bus_id) = 0xC5;
i2cWaitBusy(bus_id);

View File

@ -41,4 +41,5 @@
#define I2C_DEV_GYRO 10
#define I2C_DEV_IR 13
u8 i2cReadRegister(u8 dev_id, u8 reg);
bool i2cWriteRegister(u8 dev_id, u8 reg, u8 data);

View File

@ -50,6 +50,7 @@ u32 waitInput(bool isMenu)
if(!key)
{
if(i2cReadRegister(I2C_DEV_MCU, 0x10) == 1) mcuPowerOff();
oldKey = key;
dPadDelay = 0;
}