diff options
author | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-02-27 15:22:18 +0000 |
---|---|---|
committer | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-02-27 15:22:18 +0000 |
commit | 4f827c235aa25d0c0b45eca7ccd06ce2c1740a24 (patch) | |
tree | 776311d91c2d7743ad129d624d016391ede1c944 /os/hal | |
parent | e96e10761e38f07f884553c8ec6bcbaa06f42dd4 (diff) | |
download | ChibiOS-4f827c235aa25d0c0b45eca7ccd06ce2c1740a24.tar.gz ChibiOS-4f827c235aa25d0c0b45eca7ccd06ce2c1740a24.tar.bz2 ChibiOS-4f827c235aa25d0c0b45eca7ccd06ce2c1740a24.zip |
I2C. Code cleanups.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@2776 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal')
-rw-r--r-- | os/hal/include/i2c.h | 8 | ||||
-rw-r--r-- | os/hal/platforms/STM32/i2c_lld.c | 10 | ||||
-rw-r--r-- | os/hal/platforms/STM32/i2c_lld.h | 42 | ||||
-rw-r--r-- | os/hal/src/i2c.c | 41 |
4 files changed, 57 insertions, 44 deletions
diff --git a/os/hal/include/i2c.h b/os/hal/include/i2c.h index 8b057f527..5b7046627 100644 --- a/os/hal/include/i2c.h +++ b/os/hal/include/i2c.h @@ -143,13 +143,9 @@ extern "C" { void i2cStop(I2CDriver *i2cp);
void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg);
void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg);
+ void i2cMasterStart(I2CDriver *i2cp);
+ void i2cMasterStop(I2CDriver *i2cp);
-
- void i2cMasterStartI(I2CDriver *i2cp,uint16_t header);
- void i2cMasterStopI(I2CDriver *i2cp);
- void i2cMasterRestartI(I2CDriver *i2cp);
- void i2cMasterTransmitI(I2CDriver *i2cp, size_t n, const uint8_t *txbuf);
- void i2cMasterReceiveI(I2CDriver *i2cp, size_t n, uint8_t *rxbuf);
#if I2C_USE_MUTUAL_EXCLUSION
void i2cAcquireBus(I2CDriver *i2cp);
void i2cReleaseBus(I2CDriver *i2cp);
diff --git a/os/hal/platforms/STM32/i2c_lld.c b/os/hal/platforms/STM32/i2c_lld.c index ebfe9b423..53c070e7b 100644 --- a/os/hal/platforms/STM32/i2c_lld.c +++ b/os/hal/platforms/STM32/i2c_lld.c @@ -452,8 +452,6 @@ void i2c_lld_stop(I2CDriver *i2cp) { } - - void i2c_lld_master_start(I2CDriver *i2cp){ i2cp->id_i2c->CR1 |= I2C_CR1_START; while (i2cp->id_i2c->CR1 & I2C_CR1_START); @@ -468,8 +466,8 @@ void i2c_lld_master_stop(I2CDriver *i2cp){ } -void i2c_lld_master_transmitI(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ - //TODO: check txbytes <= sizeof(i2cscfg->txbuf) here, or in hylevel API +void i2c_lld_master_transmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ + //TODO: check txbytes <= sizeof(i2cscfg->txbuf) here, or in hi level API i2cp->id_slave_config = i2cscfg; i2cp->id_slave_config->rw_bit = I2C_WRITE; @@ -478,8 +476,8 @@ void i2c_lld_master_transmitI(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ i2c_lld_master_start(i2cp); } -void i2c_lld_master_receiveI(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ - //TODO: check txbytes <= sizeof(i2cscfg->txbuf) here, or in hylevel API +void i2c_lld_master_receive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ + //TODO: check txbytes <= sizeof(i2cscfg->txbuf) here, or in hi level API i2cp->id_slave_config = i2cscfg; i2cp->id_slave_config->rw_bit = I2C_READ; diff --git a/os/hal/platforms/STM32/i2c_lld.h b/os/hal/platforms/STM32/i2c_lld.h index 103e454f2..5d6f3c685 100644 --- a/os/hal/platforms/STM32/i2c_lld.h +++ b/os/hal/platforms/STM32/i2c_lld.h @@ -110,28 +110,23 @@ typedef enum { * @brief Driver configuration structure. */ typedef struct { - I2C_opMode_t opMode; /*!< Specifies the I2C mode.*/ - uint32_t ClockSpeed; /*!< Specifies the clock frequency. Must be set to a value lower than 400kHz */ + I2C_opMode_t opMode; /*!< Specifies the I2C mode.*/ + uint32_t ClockSpeed; /*!< Specifies the clock frequency. Must be set to a value lower than 400kHz */ I2C_DutyCycle_t FastModeDutyCycle;/*!< Specifies the I2C fast mode duty cycle */ - uint8_t OwnAddress7; /*!< Specifies the first device 7-bit own address. */ - uint16_t OwnAddress10; /*!< Specifies the second part of device own address in 10-bit mode. Set to NULL if not used. */ + uint8_t OwnAddress7; /*!< Specifies the first device 7-bit own address. */ + uint16_t OwnAddress10; /*!< Specifies the second part of device own address in 10-bit mode. Set to NULL if not used. */ } I2CConfig; -/** - * @brief TODO: - */ -typedef uint32_t i2cflags_t; /** - * @brief TODO: + * @brief I2C transmission data block size. */ typedef uint8_t i2cblock_t; /** * @brief Structure representing an I2C slave configuration. - * @details Each slave has its own data buffers, adress, and error flags. */ struct I2CSlaveConfig{ /** @@ -141,6 +136,7 @@ struct I2CSlaveConfig{ * If set to @p NULL then the callback is disabled. */ i2ccallback_t id_callback; + /** * @brief Callback pointer. * @note This callback will be invoked when error condition occur. @@ -159,17 +155,22 @@ struct I2CSlaveConfig{ size_t txbufhead; /** - * @brief Address word. - * @details The MSB used to switch between 10-bit and 7-bit modes - * (0 denotes 7-bit mode). Bits 0..9 contain slave address. - * Bits 10..14 ignores in 10-bit mode. - * Bits 7..14 ignores in 7-bot mode. + * @brief Contain slave address and some flags. + * @details Bits 0..9 contain slave address in 10-bit mode. + * + * Bits 0..6 contain slave address in 7-bit mode. + * + * Bits 10..14 are not used in 10-bit mode. + * Bits 7..14 are not used in 7-bit mode. + * + * Bit 15 is used to switch between 10-bit and 7-bit modes + * (0 denotes 7-bit mode). */ uint16_t address; - //TODO: join rw_bit, restart in one word. - uint8_t rw_bit; // this flag contain R/W bit - bool_t restart; // send restart or stop event after complete data tx/rx + //TODO: merge rw_bit, restart and address in one 16-bit variable. + uint8_t rw_bit; + bool_t restart; // send restart if TRUE. Else sent stop event after complete data tx/rx #if I2C_USE_WAIT @@ -249,11 +250,12 @@ void i2c_lld_set_own_address(I2CDriver *i2cp); void i2c_lld_master_start(I2CDriver *i2cp); void i2c_lld_master_stop(I2CDriver *i2cp); +void i2c_lld_master_transmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg); +void i2c_lld_master_receive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg); void i2c_lld_master_transmit_NI(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg, bool_t restart); -void i2c_lld_master_transmitI(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg); void i2c_lld_master_receive_NI(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg); -void i2c_lld_master_receiveI(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg); + #ifdef __cplusplus } #endif diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c index 04af9a6c2..7dede9f86 100644 --- a/os/hal/src/i2c.c +++ b/os/hal/src/i2c.c @@ -117,13 +117,34 @@ void i2cStop(I2CDriver *i2cp) { }
/**
+ * @brief Generate (re)start on the bus.
+ *
+ * @param[in] i2cp pointer to the @p I2CDriver object
+ */
+void i2cMasterStart(I2CDriver *i2cp){
+
+ chDbgCheck((i2cp != NULL), "i2cMasterTransmit");
+
+ i2c_lld_master_start(i2cp);
+}
+
+/**
+ * @brief Generate stop on the bus.
+ *
+ * @param[in] i2cp pointer to the @p I2CDriver object
+ */
+void i2cMasterStop(I2CDriver *i2cp){
+
+ chDbgCheck((i2cp != NULL), "i2cMasterTransmit");
+
+ i2c_lld_master_stop(i2cp);
+}
+
+/**
* @brief Sends data ever the I2C bus.
*
* @param[in] i2cp pointer to the @p I2CDriver object
- * @param[in] slave_addr1 7-bit address of the slave
- * @param[in] slave_addr1 used in 10-bit address mode
- * @param[in] n number of words to send
- * @param[in] txbuf the pointer to the transmit buffer
+ * @param[in] i2cscfg pointer to the @p I2CSlaveConfig object
*
*/
void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) {
@@ -134,19 +155,15 @@ void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { "i2cMasterTransmit(), #1",
"not active");
- i2c_lld_master_transmitI(i2cp, i2cscfg);
+ i2c_lld_master_transmit(i2cp, i2cscfg);
}
/**
* @brief Receives data from the I2C bus.
*
- * @param[in] i2cp pointer to the @p I2CDriver object
- * @param[in] slave_addr1 7-bit address of the slave
- * @param[in] slave_addr1 used in 10-bit address mode
- * @param[in] n number of words to receive
- * @param[out] rxbuf the pointer to the receive buffer
- *
+ * @param[in] i2cp pointer to the @p I2CDriver object
+ * @param[in] i2cscfg pointer to the @p I2CSlaveConfig object
*/
void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) {
@@ -156,7 +173,7 @@ void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) { "i2cMasterReceive(), #1",
"not active");
- i2c_lld_master_receiveI(i2cp, i2cscfg);
+ i2c_lld_master_receive(i2cp, i2cscfg);
}
|