mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-11-18 19:20:43 -05:00
gracefully handle i2c error (#2838)
This commit is contained in:
parent
d3373734e9
commit
7041d507ca
1 changed files with 85 additions and 88 deletions
|
|
@ -79,8 +79,7 @@ void i2cInit(void) {
|
|||
*
|
||||
* @init
|
||||
*/
|
||||
void i2cObjectInit(I2CDriver *i2cp) {
|
||||
|
||||
void i2cObjectInit(I2CDriver* i2cp) {
|
||||
i2cp->state = I2C_STOP;
|
||||
i2cp->config = NULL;
|
||||
|
||||
|
|
@ -105,8 +104,7 @@ void i2cObjectInit(I2CDriver *i2cp) {
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
void i2cStart(I2CDriver *i2cp, const I2CConfig *config) {
|
||||
|
||||
void i2cStart(I2CDriver* i2cp, const I2CConfig* config) {
|
||||
chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart");
|
||||
chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY) ||
|
||||
(i2cp->state == I2C_LOCKED),
|
||||
|
|
@ -127,8 +125,7 @@ void i2cStart(I2CDriver *i2cp, const I2CConfig *config) {
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
void i2cStop(I2CDriver *i2cp) {
|
||||
|
||||
void i2cStop(I2CDriver* i2cp) {
|
||||
chDbgCheck(i2cp != NULL, "i2cStop");
|
||||
chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY) ||
|
||||
(i2cp->state == I2C_LOCKED),
|
||||
|
|
@ -149,8 +146,7 @@ void i2cStop(I2CDriver *i2cp) {
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
i2cflags_t i2cGetErrors(I2CDriver *i2cp) {
|
||||
|
||||
i2cflags_t i2cGetErrors(I2CDriver* i2cp) {
|
||||
chDbgCheck(i2cp != NULL, "i2cGetErrors");
|
||||
|
||||
return i2c_lld_get_errors(i2cp);
|
||||
|
|
@ -182,11 +178,11 @@ i2cflags_t i2cGetErrors(I2CDriver *i2cp) {
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp,
|
||||
msg_t i2cMasterTransmitTimeout(I2CDriver* i2cp,
|
||||
i2caddr_t addr,
|
||||
const uint8_t *txbuf,
|
||||
const uint8_t* txbuf,
|
||||
size_t txbytes,
|
||||
uint8_t *rxbuf,
|
||||
uint8_t* rxbuf,
|
||||
size_t rxbytes,
|
||||
systime_t timeout) {
|
||||
msg_t rdymsg;
|
||||
|
|
@ -197,8 +193,10 @@ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp,
|
|||
(timeout != TIME_IMMEDIATE),
|
||||
"i2cMasterTransmitTimeout");
|
||||
|
||||
chDbgAssert(i2cp->state == I2C_READY,
|
||||
"i2cMasterTransmitTimeout(), #1", "not ready");
|
||||
// chDbgAssert(i2cp->state == I2C_READY, "i2cMasterTransmitTimeout(), #1", "not ready");
|
||||
if (i2cp->state != I2C_READY) {
|
||||
return RDY_TIMEOUT;
|
||||
}
|
||||
|
||||
chSysLock();
|
||||
i2cp->errors = I2CD_NO_ERROR;
|
||||
|
|
@ -233,12 +231,11 @@ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp,
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp,
|
||||
msg_t i2cMasterReceiveTimeout(I2CDriver* i2cp,
|
||||
i2caddr_t addr,
|
||||
uint8_t *rxbuf,
|
||||
uint8_t* rxbuf,
|
||||
size_t rxbytes,
|
||||
systime_t timeout){
|
||||
|
||||
systime_t timeout) {
|
||||
msg_t rdymsg;
|
||||
|
||||
chDbgCheck((i2cp != NULL) && (addr != 0) &&
|
||||
|
|
@ -246,8 +243,10 @@ msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp,
|
|||
(timeout != TIME_IMMEDIATE),
|
||||
"i2cMasterReceiveTimeout");
|
||||
|
||||
chDbgAssert(i2cp->state == I2C_READY,
|
||||
"i2cMasterReceive(), #1", "not ready");
|
||||
// chDbgAssert(i2cp->state == I2C_READY, "i2cMasterReceive(), #1", "not ready");
|
||||
if (i2cp->state != I2C_READY) {
|
||||
return RDY_TIMEOUT;
|
||||
}
|
||||
|
||||
chSysLock();
|
||||
i2cp->errors = I2CD_NO_ERROR;
|
||||
|
|
@ -273,8 +272,7 @@ msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp,
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
void i2cAcquireBus(I2CDriver *i2cp) {
|
||||
|
||||
void i2cAcquireBus(I2CDriver* i2cp) {
|
||||
chDbgCheck(i2cp != NULL, "i2cAcquireBus");
|
||||
|
||||
#if CH_USE_MUTEXES
|
||||
|
|
@ -293,8 +291,7 @@ void i2cAcquireBus(I2CDriver *i2cp) {
|
|||
*
|
||||
* @api
|
||||
*/
|
||||
void i2cReleaseBus(I2CDriver *i2cp) {
|
||||
|
||||
void i2cReleaseBus(I2CDriver* i2cp) {
|
||||
chDbgCheck(i2cp != NULL, "i2cReleaseBus");
|
||||
|
||||
#if CH_USE_MUTEXES
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue