mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 13:42:47 +00:00
Fix I2C delays
This commit is contained in:
parent
2861b9516b
commit
27426eae44
@ -1,6 +1,5 @@
|
|||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
|
#include "timer.h"
|
||||||
void wait(u64 amount);
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -89,6 +88,7 @@ u8 i2cReadRegister(u8 dev_id, u8 reg) {
|
|||||||
i2cWaitBusy(bus_id);
|
i2cWaitBusy(bus_id);
|
||||||
i2cStop(bus_id, 1);
|
i2cStop(bus_id, 1);
|
||||||
i2cWaitBusy(bus_id);
|
i2cWaitBusy(bus_id);
|
||||||
|
wait_msec(3ULL);
|
||||||
return *i2cGetDataReg(bus_id);
|
return *i2cGetDataReg(bus_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,8 +96,7 @@ u8 i2cReadRegister(u8 dev_id, u8 reg) {
|
|||||||
i2cWaitBusy(bus_id);
|
i2cWaitBusy(bus_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
wait(3ULL);
|
wait_msec(3ULL);
|
||||||
|
|
||||||
return 0xff;
|
return 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,8 +112,10 @@ bool i2cReadRegisterBuffer(unsigned int dev_id, int reg, u8* buffer, size_t buf_
|
|||||||
i2cWaitBusy(bus_id);
|
i2cWaitBusy(bus_id);
|
||||||
*i2cGetCntReg(bus_id) = 0xC5;
|
*i2cGetCntReg(bus_id) = 0xC5;
|
||||||
i2cWaitBusy(bus_id);
|
i2cWaitBusy(bus_id);
|
||||||
if (++j >= 8)
|
if (++j >= 8) {
|
||||||
|
wait_msec(3ULL);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf_size != 1) {
|
if (buf_size != 1) {
|
||||||
@ -131,8 +132,7 @@ bool i2cReadRegisterBuffer(unsigned int dev_id, int reg, u8* buffer, size_t buf_
|
|||||||
i2cWaitBusy(bus_id);
|
i2cWaitBusy(bus_id);
|
||||||
buffer[buf_size - 1] = *i2cGetDataReg(bus_id);
|
buffer[buf_size - 1] = *i2cGetDataReg(bus_id);
|
||||||
|
|
||||||
wait(3ULL);
|
wait_msec(3ULL);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,14 +146,15 @@ bool i2cWriteRegister(u8 dev_id, u8 reg, u8 data) {
|
|||||||
*i2cGetDataReg(bus_id) = data;
|
*i2cGetDataReg(bus_id) = data;
|
||||||
*i2cGetCntReg(bus_id) = 0xC1;
|
*i2cGetCntReg(bus_id) = 0xC1;
|
||||||
i2cStop(bus_id, 0);
|
i2cStop(bus_id, 0);
|
||||||
if (i2cGetResult(bus_id))
|
if (i2cGetResult(bus_id)) {
|
||||||
|
wait_msec(3ULL);
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*i2cGetCntReg(bus_id) = 0xC5;
|
*i2cGetCntReg(bus_id) = 0xC5;
|
||||||
i2cWaitBusy(bus_id);
|
i2cWaitBusy(bus_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
wait(3ULL);
|
wait_msec(3ULL);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user