mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-09-12 17:49:31 +00:00
gracefully handle i2c error (#2838)
This commit is contained in:
@@ -80,7 +80,6 @@ void i2cInit(void) {
|
|||||||
* @init
|
* @init
|
||||||
*/
|
*/
|
||||||
void i2cObjectInit(I2CDriver* i2cp) {
|
void i2cObjectInit(I2CDriver* i2cp) {
|
||||||
|
|
||||||
i2cp->state = I2C_STOP;
|
i2cp->state = I2C_STOP;
|
||||||
i2cp->config = NULL;
|
i2cp->config = NULL;
|
||||||
|
|
||||||
@@ -106,7 +105,6 @@ void i2cObjectInit(I2CDriver *i2cp) {
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
void i2cStart(I2CDriver* i2cp, const I2CConfig* config) {
|
void i2cStart(I2CDriver* i2cp, const I2CConfig* config) {
|
||||||
|
|
||||||
chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart");
|
chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart");
|
||||||
chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY) ||
|
chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY) ||
|
||||||
(i2cp->state == I2C_LOCKED),
|
(i2cp->state == I2C_LOCKED),
|
||||||
@@ -128,7 +126,6 @@ void i2cStart(I2CDriver *i2cp, const I2CConfig *config) {
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
void i2cStop(I2CDriver* i2cp) {
|
void i2cStop(I2CDriver* i2cp) {
|
||||||
|
|
||||||
chDbgCheck(i2cp != NULL, "i2cStop");
|
chDbgCheck(i2cp != NULL, "i2cStop");
|
||||||
chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY) ||
|
chDbgAssert((i2cp->state == I2C_STOP) || (i2cp->state == I2C_READY) ||
|
||||||
(i2cp->state == I2C_LOCKED),
|
(i2cp->state == I2C_LOCKED),
|
||||||
@@ -150,7 +147,6 @@ void i2cStop(I2CDriver *i2cp) {
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
i2cflags_t i2cGetErrors(I2CDriver* i2cp) {
|
i2cflags_t i2cGetErrors(I2CDriver* i2cp) {
|
||||||
|
|
||||||
chDbgCheck(i2cp != NULL, "i2cGetErrors");
|
chDbgCheck(i2cp != NULL, "i2cGetErrors");
|
||||||
|
|
||||||
return i2c_lld_get_errors(i2cp);
|
return i2c_lld_get_errors(i2cp);
|
||||||
@@ -197,8 +193,10 @@ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp,
|
|||||||
(timeout != TIME_IMMEDIATE),
|
(timeout != TIME_IMMEDIATE),
|
||||||
"i2cMasterTransmitTimeout");
|
"i2cMasterTransmitTimeout");
|
||||||
|
|
||||||
chDbgAssert(i2cp->state == I2C_READY,
|
// chDbgAssert(i2cp->state == I2C_READY, "i2cMasterTransmitTimeout(), #1", "not ready");
|
||||||
"i2cMasterTransmitTimeout(), #1", "not ready");
|
if (i2cp->state != I2C_READY) {
|
||||||
|
return RDY_TIMEOUT;
|
||||||
|
}
|
||||||
|
|
||||||
chSysLock();
|
chSysLock();
|
||||||
i2cp->errors = I2CD_NO_ERROR;
|
i2cp->errors = I2CD_NO_ERROR;
|
||||||
@@ -238,7 +236,6 @@ msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp,
|
|||||||
uint8_t* rxbuf,
|
uint8_t* rxbuf,
|
||||||
size_t rxbytes,
|
size_t rxbytes,
|
||||||
systime_t timeout) {
|
systime_t timeout) {
|
||||||
|
|
||||||
msg_t rdymsg;
|
msg_t rdymsg;
|
||||||
|
|
||||||
chDbgCheck((i2cp != NULL) && (addr != 0) &&
|
chDbgCheck((i2cp != NULL) && (addr != 0) &&
|
||||||
@@ -246,8 +243,10 @@ msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp,
|
|||||||
(timeout != TIME_IMMEDIATE),
|
(timeout != TIME_IMMEDIATE),
|
||||||
"i2cMasterReceiveTimeout");
|
"i2cMasterReceiveTimeout");
|
||||||
|
|
||||||
chDbgAssert(i2cp->state == I2C_READY,
|
// chDbgAssert(i2cp->state == I2C_READY, "i2cMasterReceive(), #1", "not ready");
|
||||||
"i2cMasterReceive(), #1", "not ready");
|
if (i2cp->state != I2C_READY) {
|
||||||
|
return RDY_TIMEOUT;
|
||||||
|
}
|
||||||
|
|
||||||
chSysLock();
|
chSysLock();
|
||||||
i2cp->errors = I2CD_NO_ERROR;
|
i2cp->errors = I2CD_NO_ERROR;
|
||||||
@@ -274,7 +273,6 @@ msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp,
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
void i2cAcquireBus(I2CDriver* i2cp) {
|
void i2cAcquireBus(I2CDriver* i2cp) {
|
||||||
|
|
||||||
chDbgCheck(i2cp != NULL, "i2cAcquireBus");
|
chDbgCheck(i2cp != NULL, "i2cAcquireBus");
|
||||||
|
|
||||||
#if CH_USE_MUTEXES
|
#if CH_USE_MUTEXES
|
||||||
@@ -294,7 +292,6 @@ void i2cAcquireBus(I2CDriver *i2cp) {
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
void i2cReleaseBus(I2CDriver* i2cp) {
|
void i2cReleaseBus(I2CDriver* i2cp) {
|
||||||
|
|
||||||
chDbgCheck(i2cp != NULL, "i2cReleaseBus");
|
chDbgCheck(i2cp != NULL, "i2cReleaseBus");
|
||||||
|
|
||||||
#if CH_USE_MUTEXES
|
#if CH_USE_MUTEXES
|
||||||
|
|||||||
Reference in New Issue
Block a user