I2C. API changed. Transmit and receive buffers removed from I2CSlaveConfig. Now pointers to that buffers pass in functions arguments.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3099 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
73ce7b4fe0
commit
f73960c8dc
|
@ -144,10 +144,6 @@ struct I2CSlaveConfig{
|
||||||
* If set to @p NULL then the callback is disabled.
|
* If set to @p NULL then the callback is disabled.
|
||||||
*/
|
*/
|
||||||
i2cerrorcallback_t id_err_callback;
|
i2cerrorcallback_t id_err_callback;
|
||||||
|
|
||||||
i2cblock_t *rxbuf; /*!< Pointer to receive buffer. */
|
|
||||||
i2cblock_t *txbuf; /*!< Pointer to transmit buffer.*/
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -229,9 +225,11 @@ extern "C" {
|
||||||
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, const I2CSlaveConfig *i2cscfg,
|
void i2cMasterTransmit(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg,
|
||||||
uint16_t slave_addr, size_t txbytes, size_t rxbytes);
|
uint16_t slave_addr,
|
||||||
|
uint8_t *txbuf, size_t txbytes,
|
||||||
|
uint8_t *rxbuf, size_t rxbytes);
|
||||||
void i2cMasterReceive(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg,
|
void i2cMasterReceive(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg,
|
||||||
uint16_t slave_addr, size_t rxbytes);
|
uint16_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);
|
||||||
|
|
|
@ -70,7 +70,7 @@ static void i2c_serve_event_interrupt(I2CDriver *i2cp) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* Initialize the transmit buffer pointer */
|
/* Initialize the transmit buffer pointer */
|
||||||
txBuffp = (uint8_t*)i2cp->id_slave_config->txbuf;
|
txBuffp = (uint8_t*)i2cp->txbuf;
|
||||||
i2cp->txbytes--;
|
i2cp->txbytes--;
|
||||||
/* If no further data to be sent, disable the I2C ITBUF in order
|
/* If no further data to be sent, disable the I2C ITBUF in order
|
||||||
* to not have a TxE interrupt */
|
* to not have a TxE interrupt */
|
||||||
|
@ -107,7 +107,7 @@ static void i2c_serve_event_interrupt(I2CDriver *i2cp) {
|
||||||
/* Disable ITEVT In order to not have again a BTF IT */
|
/* Disable ITEVT In order to not have again a BTF IT */
|
||||||
dp->CR2 &= (uint16_t)~I2C_CR2_ITEVTEN;
|
dp->CR2 &= (uint16_t)~I2C_CR2_ITEVTEN;
|
||||||
/* send restart and begin reading operations */
|
/* send restart and begin reading operations */
|
||||||
i2c_lld_master_receive(i2cp, i2cp->slave_addr, i2cp->rxbytes);
|
i2c_lld_master_receive(i2cp, i2cp->slave_addr, i2cp->rxbuf, i2cp->rxbytes);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ static void i2c_serve_event_interrupt(I2CDriver *i2cp) {
|
||||||
}
|
}
|
||||||
chSysUnlockFromIsr();
|
chSysUnlockFromIsr();
|
||||||
/* Initialize receive buffer pointer */
|
/* Initialize receive buffer pointer */
|
||||||
rxBuffp = i2cp->id_slave_config->rxbuf;
|
rxBuffp = i2cp->rxbuf;
|
||||||
break;
|
break;
|
||||||
case I2C_EV7_MASTER_REC_BYTE_RECEIVED:
|
case I2C_EV7_MASTER_REC_BYTE_RECEIVED:
|
||||||
if(i2cp->rxbytes != 3) {
|
if(i2cp->rxbytes != 3) {
|
||||||
|
@ -530,10 +530,14 @@ void i2c_lld_stop(I2CDriver *i2cp) {
|
||||||
* @param[in] rxbytes number of bytes to be received
|
* @param[in] rxbytes number of bytes to be received
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void i2c_lld_master_transmit(I2CDriver *i2cp, uint16_t slave_addr, size_t txbytes, size_t rxbytes) {
|
void i2c_lld_master_transmit(I2CDriver *i2cp, uint16_t slave_addr,
|
||||||
|
uint8_t *txbuf, size_t txbytes, uint8_t *rxbuf, size_t rxbytes) {
|
||||||
|
|
||||||
i2cp->slave_addr = slave_addr;
|
i2cp->slave_addr = slave_addr;
|
||||||
i2cp->txbytes = txbytes;
|
i2cp->txbytes = txbytes;
|
||||||
i2cp->rxbytes = rxbytes;
|
i2cp->rxbytes = rxbytes;
|
||||||
|
i2cp->txbuf = txbuf;
|
||||||
|
i2cp->rxbuf = rxbuf;
|
||||||
|
|
||||||
/* enable ERR, EVT & BUF ITs */
|
/* enable ERR, EVT & BUF ITs */
|
||||||
i2cp->id_i2c->CR2 |= (I2C_CR2_ITERREN|I2C_CR2_ITEVTEN|I2C_CR2_ITBUFEN);
|
i2cp->id_i2c->CR2 |= (I2C_CR2_ITERREN|I2C_CR2_ITEVTEN|I2C_CR2_ITBUFEN);
|
||||||
|
@ -579,9 +583,12 @@ void i2c_lld_master_transmit(I2CDriver *i2cp, uint16_t slave_addr, size_t txbyte
|
||||||
* @param[in] rxbytes number of bytes to be received
|
* @param[in] rxbytes number of bytes to be received
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void i2c_lld_master_receive(I2CDriver *i2cp, uint16_t slave_addr, size_t rxbytes){
|
void i2c_lld_master_receive(I2CDriver *i2cp, uint16_t slave_addr,
|
||||||
|
uint8_t *rxbuf, size_t rxbytes){
|
||||||
|
|
||||||
i2cp->slave_addr = slave_addr;
|
i2cp->slave_addr = slave_addr;
|
||||||
i2cp->rxbytes = rxbytes;
|
i2cp->rxbytes = rxbytes;
|
||||||
|
i2cp->rxbuf = rxbuf;
|
||||||
|
|
||||||
/* enable ERR, EVT & BUF ITs */
|
/* enable ERR, EVT & BUF ITs */
|
||||||
i2cp->id_i2c->CR2 |= (I2C_CR2_ITERREN|I2C_CR2_ITEVTEN|I2C_CR2_ITBUFEN);
|
i2cp->id_i2c->CR2 |= (I2C_CR2_ITERREN|I2C_CR2_ITEVTEN|I2C_CR2_ITBUFEN);
|
||||||
|
|
|
@ -165,6 +165,8 @@ struct I2CDriver{
|
||||||
|
|
||||||
size_t txbytes; /*!< Number of bytes to be transmitted. */
|
size_t txbytes; /*!< Number of bytes to be transmitted. */
|
||||||
size_t rxbytes; /*!< Number of bytes to be received. */
|
size_t rxbytes; /*!< Number of bytes to be received. */
|
||||||
|
uint8_t *rxbuf; /*!< Pointer to receive buffer. */
|
||||||
|
uint8_t *txbuf; /*!< Pointer to transmit buffer.*/
|
||||||
uint8_t *rxbuff_p; /*!< Pointer to the current byte in slave rx buffer. */
|
uint8_t *rxbuff_p; /*!< Pointer to the current byte in slave rx buffer. */
|
||||||
uint8_t *txbuff_p; /*!< Pointer to the current byte in slave tx buffer. */
|
uint8_t *txbuff_p; /*!< Pointer to the current byte in slave tx buffer. */
|
||||||
|
|
||||||
|
@ -228,9 +230,9 @@ void i2c_lld_set_own_address(I2CDriver *i2cp);
|
||||||
void i2c_lld_start(I2CDriver *i2cp);
|
void i2c_lld_start(I2CDriver *i2cp);
|
||||||
void i2c_lld_stop(I2CDriver *i2cp);
|
void i2c_lld_stop(I2CDriver *i2cp);
|
||||||
void i2c_lld_master_transmit(I2CDriver *i2cp, uint16_t slave_addr,
|
void i2c_lld_master_transmit(I2CDriver *i2cp, uint16_t slave_addr,
|
||||||
size_t txbytes, size_t rxbytes);
|
uint8_t *txbuf, size_t txbytes, uint8_t *rxbuf, size_t rxbytes);
|
||||||
void i2c_lld_master_receive(I2CDriver *i2cp, uint16_t slave_addr,
|
void i2c_lld_master_receive(I2CDriver *i2cp, uint16_t slave_addr,
|
||||||
size_t rxbytes);
|
uint8_t *rxbuf, size_t rxbytes);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,19 +141,23 @@ void i2cStop(I2CDriver *i2cp) {
|
||||||
* device address. Bit 15 must be set to 1 if 10-bit
|
* device address. Bit 15 must be set to 1 if 10-bit
|
||||||
* addressing modes used. Otherwise keep it cleared.
|
* addressing modes used. Otherwise keep it cleared.
|
||||||
* Bits 10-14 unused.
|
* Bits 10-14 unused.
|
||||||
* @param[in] txbytes number of bytes to be transmited
|
* @param[in] txbytes number of bytes to be transmitted
|
||||||
|
* @param[in] txbuf pointer to transmit buffer
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
void i2cMasterTransmit(I2CDriver *i2cp,
|
void i2cMasterTransmit(I2CDriver *i2cp,
|
||||||
const I2CSlaveConfig *i2cscfg,
|
const I2CSlaveConfig *i2cscfg,
|
||||||
uint16_t slave_addr,
|
uint16_t slave_addr,
|
||||||
|
uint8_t *txbuf,
|
||||||
size_t txbytes,
|
size_t txbytes,
|
||||||
|
uint8_t *rxbuf,
|
||||||
size_t rxbytes) {
|
size_t rxbytes) {
|
||||||
|
|
||||||
chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\
|
chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\
|
||||||
(slave_addr != 0) &&\
|
(slave_addr != 0) &&\
|
||||||
(txbytes > 0) &&\
|
(txbytes > 0) &&\
|
||||||
(i2cscfg->txbuf != NULL),
|
(txbuf != NULL),
|
||||||
"i2cMasterTransmit");
|
"i2cMasterTransmit");
|
||||||
|
|
||||||
/* init slave config field in driver */
|
/* init slave config field in driver */
|
||||||
|
@ -174,7 +178,7 @@ void i2cMasterTransmit(I2CDriver *i2cp,
|
||||||
"i2cMasterTransmit(), #1", "not ready");
|
"i2cMasterTransmit(), #1", "not ready");
|
||||||
|
|
||||||
i2cp->id_state = I2C_ACTIVE;
|
i2cp->id_state = I2C_ACTIVE;
|
||||||
i2c_lld_master_transmit(i2cp, slave_addr, txbytes, rxbytes);
|
i2c_lld_master_transmit(i2cp, slave_addr, txbuf, txbytes, rxbuf, rxbytes);
|
||||||
_i2c_wait_s(i2cp);
|
_i2c_wait_s(i2cp);
|
||||||
#if !I2C_USE_WAIT
|
#if !I2C_USE_WAIT
|
||||||
i2c_lld_wait_bus_free(i2cp);
|
i2c_lld_wait_bus_free(i2cp);
|
||||||
|
@ -198,12 +202,13 @@ void i2cMasterTransmit(I2CDriver *i2cp,
|
||||||
void i2cMasterReceive(I2CDriver *i2cp,
|
void i2cMasterReceive(I2CDriver *i2cp,
|
||||||
const I2CSlaveConfig *i2cscfg,
|
const I2CSlaveConfig *i2cscfg,
|
||||||
uint16_t slave_addr,
|
uint16_t slave_addr,
|
||||||
|
uint8_t *rxbuf,
|
||||||
size_t rxbytes){
|
size_t rxbytes){
|
||||||
|
|
||||||
chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\
|
chDbgCheck((i2cp != NULL) && (i2cscfg != NULL) &&\
|
||||||
(slave_addr != 0) &&\
|
(slave_addr != 0) &&\
|
||||||
(rxbytes > 0) && \
|
(rxbytes > 0) && \
|
||||||
(i2cscfg->rxbuf != NULL),
|
(rxbuf != NULL),
|
||||||
"i2cMasterReceive");
|
"i2cMasterReceive");
|
||||||
|
|
||||||
/* init slave config field in driver */
|
/* init slave config field in driver */
|
||||||
|
@ -224,7 +229,7 @@ void i2cMasterReceive(I2CDriver *i2cp,
|
||||||
"i2cMasterReceive(), #1", "not ready");
|
"i2cMasterReceive(), #1", "not ready");
|
||||||
|
|
||||||
i2cp->id_state = I2C_ACTIVE;
|
i2cp->id_state = I2C_ACTIVE;
|
||||||
i2c_lld_master_receive(i2cp, slave_addr, rxbytes);
|
i2c_lld_master_receive(i2cp, slave_addr, rxbuf, rxbytes);
|
||||||
_i2c_wait_s(i2cp);
|
_i2c_wait_s(i2cp);
|
||||||
#if !I2C_USE_WAIT
|
#if !I2C_USE_WAIT
|
||||||
i2c_lld_wait_bus_free(i2cp);
|
i2c_lld_wait_bus_free(i2cp);
|
||||||
|
|
Loading…
Reference in New Issue