I2C. Error handling from userland code added.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3572 35acf78f-673a-0410-8e92-d51de3d6d3f4
master
barthess 2011-12-07 19:23:09 +00:00
parent b9df6d7c80
commit 3799bf56f5
2 changed files with 13 additions and 4 deletions

View File

@ -181,15 +181,16 @@ extern "C" {
void i2cObjectInit(I2CDriver *i2cp); void i2cObjectInit(I2CDriver *i2cp);
void i2cStart(I2CDriver *i2cp, const I2CConfig *config); void i2cStart(I2CDriver *i2cp, const I2CConfig *config);
void i2cStop(I2CDriver *i2cp); void i2cStop(I2CDriver *i2cp);
void i2cMasterTransmit(I2CDriver *i2cp, i2cflags_t i2cMasterTransmit(I2CDriver *i2cp,
uint8_t slave_addr, uint8_t slave_addr,
uint8_t *txbuf, size_t txbytes, uint8_t *txbuf, size_t txbytes,
uint8_t *rxbuf, size_t rxbytes); uint8_t *rxbuf, size_t rxbytes);
void i2cMasterReceive(I2CDriver *i2cp, i2cflags_t i2cMasterReceive(I2CDriver *i2cp,
uint8_t slave_addr, uint8_t *rxbuf, size_t rxbytes); uint8_t slave_addr, uint8_t *rxbuf, size_t rxbytes);
void i2cMasterStart(I2CDriver *i2cp); void i2cMasterStart(I2CDriver *i2cp);
void i2cMasterStop(I2CDriver *i2cp); void i2cMasterStop(I2CDriver *i2cp);
void i2cAddFlagsI(I2CDriver *i2cp, i2cflags_t mask); void i2cAddFlagsI(I2CDriver *i2cp, i2cflags_t mask);
i2cflags_t i2cGetAndClearFlags(I2CDriver *i2cp);
#if I2C_USE_MUTUAL_EXCLUSION #if I2C_USE_MUTUAL_EXCLUSION
void i2cAcquireBus(I2CDriver *i2cp); void i2cAcquireBus(I2CDriver *i2cp);

View File

@ -149,8 +149,10 @@ void i2cStop(I2CDriver *i2cp) {
* @param[in] rxbuf pointer to receive buffer * @param[in] rxbuf pointer to receive buffer
* @param[in] rxbytes number of bytes to be received, set it to 0 if * @param[in] rxbytes number of bytes to be received, set it to 0 if
* you want transmit only * you want transmit only
*
* @return Zero if no errors, otherwise return error code.
*/ */
void i2cMasterTransmit(I2CDriver *i2cp, i2cflags_t i2cMasterTransmit(I2CDriver *i2cp,
uint8_t slave_addr, uint8_t slave_addr,
uint8_t *txbuf, uint8_t *txbuf,
size_t txbytes, size_t txbytes,
@ -173,6 +175,8 @@ void i2cMasterTransmit(I2CDriver *i2cp,
i2cp->id_state = I2C_ACTIVE_TRANSMIT; i2cp->id_state = I2C_ACTIVE_TRANSMIT;
i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes); i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes);
_i2c_wait_s(i2cp); _i2c_wait_s(i2cp);
return i2cGetAndClearFlags(i2cp);
} }
/** /**
@ -184,8 +188,10 @@ void i2cMasterTransmit(I2CDriver *i2cp,
* @param[in] slave_addr slave device address (7 bits) without R/W bit * @param[in] slave_addr slave device address (7 bits) without R/W bit
* @param[in] rxbytes number of bytes to be received * @param[in] rxbytes number of bytes to be received
* @param[in] rxbuf pointer to receive buffer * @param[in] rxbuf pointer to receive buffer
*
* @return Zero if no errors, otherwise return error code.
*/ */
void i2cMasterReceive(I2CDriver *i2cp, i2cflags_t i2cMasterReceive(I2CDriver *i2cp,
uint8_t slave_addr, uint8_t slave_addr,
uint8_t *rxbuf, uint8_t *rxbuf,
size_t rxbytes){ size_t rxbytes){
@ -205,6 +211,8 @@ void i2cMasterReceive(I2CDriver *i2cp,
i2cp->id_state = I2C_ACTIVE_RECEIVE; i2cp->id_state = I2C_ACTIVE_RECEIVE;
i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes); i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes);
_i2c_wait_s(i2cp); _i2c_wait_s(i2cp);
return i2cGetAndClearFlags(i2cp);
} }
/** /**