mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2026-09-12 09:39:30 +00:00
gracefully handle i2c error (#2838)
This commit is contained in:
@@ -79,8 +79,7 @@ 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;
|
||||||
|
|
||||||
@@ -105,8 +104,7 @@ 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),
|
||||||
@@ -127,8 +125,7 @@ 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),
|
||||||
@@ -149,8 +146,7 @@ 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);
|
||||||
@@ -182,11 +178,11 @@ i2cflags_t i2cGetErrors(I2CDriver *i2cp) {
|
|||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp,
|
msg_t i2cMasterTransmitTimeout(I2CDriver* i2cp,
|
||||||
i2caddr_t addr,
|
i2caddr_t addr,
|
||||||
const uint8_t *txbuf,
|
const uint8_t* txbuf,
|
||||||
size_t txbytes,
|
size_t txbytes,
|
||||||
uint8_t *rxbuf,
|
uint8_t* rxbuf,
|
||||||
size_t rxbytes,
|
size_t rxbytes,
|
||||||
systime_t timeout) {
|
systime_t timeout) {
|
||||||
msg_t rdymsg;
|
msg_t rdymsg;
|
||||||
@@ -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;
|
||||||
@@ -233,12 +231,11 @@ msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp,
|
|||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
msg_t i2cMasterReceiveTimeout(I2CDriver *i2cp,
|
msg_t i2cMasterReceiveTimeout(I2CDriver* i2cp,
|
||||||
i2caddr_t addr,
|
i2caddr_t addr,
|
||||||
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;
|
||||||
@@ -273,8 +272,7 @@ 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
|
||||||
@@ -293,8 +291,7 @@ 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