aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/src/i2c.c
diff options
context:
space:
mode:
Diffstat (limited to 'os/hal/src/i2c.c')
-rw-r--r--os/hal/src/i2c.c125
1 files changed, 34 insertions, 91 deletions
diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c
index 2b5971b6f..5a0471e0f 100644
--- a/os/hal/src/i2c.c
+++ b/os/hal/src/i2c.c
@@ -54,7 +54,6 @@
* @init
*/
void i2cInit(void) {
-
i2c_lld_init();
}
@@ -67,8 +66,9 @@ void i2cInit(void) {
*/
void i2cObjectInit(I2CDriver *i2cp) {
- i2cp->i2c_state = I2C_STOP;
- i2cp->i2c_config = NULL;
+ i2cp->id_state = I2C_STOP;
+ i2cp->id_config = NULL;
+ i2cp->id_slave_config = NULL;
#if defined(I2C_DRIVER_EXT_INIT_HOOK)
I2C_DRIVER_EXT_INIT_HOOK(i2cp);
#endif
@@ -82,17 +82,17 @@ void i2cObjectInit(I2CDriver *i2cp) {
*
* @api
*/
-void i2cStart(I2CDriver *i2cp, const I2CConfig *config) {
+void i2cStart(I2CDriver *i2cp, I2CConfig *config) {
chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart");
chSysLock();
- chDbgAssert((i2cp->i2c_state == I2C_STOP) || (i2cp->i2c_state == I2C_READY),
+ chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY),
"i2cStart(), #1",
"invalid state");
- i2cp->i2c_config = config;
+ i2cp->id_config = config;
i2c_lld_start(i2cp);
- i2cp->i2c_state = I2C_READY;
+ i2cp->id_state = I2C_READY;
chSysUnlock();
}
@@ -108,118 +108,61 @@ void i2cStop(I2CDriver *i2cp) {
chDbgCheck(i2cp != NULL, "i2cStop");
chSysLock();
- chDbgAssert((i2cp->i2c_state == I2C_STOP) || (i2cp->i2c_state == I2C_READY),
+ chDbgAssert((i2cp->id_state == I2C_STOP) || (i2cp->id_state == I2C_READY),
"i2cStop(), #1",
"invalid state");
i2c_lld_stop(i2cp);
- i2cp->i2c_state = I2C_STOP;
+ i2cp->id_state = I2C_STOP;
chSysUnlock();
}
/**
- * @brief Initiates a master bus transaction.
- * @details This function sends a start bit followed by an one or two bytes
- * header.
- *
- * @param[in] i2cp pointer to the @p I2CDriver object
- * @param[in] header transaction header
- * @param[in] callback operation complete callback
- *
- * @iclass
- */
-void i2cMasterStartI(I2CDriver *i2cp,
- uint16_t header,
- i2ccallback_t callback) {
-
- chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterStartI");
- chDbgAssert(i2cp->i2c_state == I2C_READY,
- "i2cMasterStartI(), #1", "invalid state");
-
- i2cp->id_callback = callback;
- i2c_lld_master_start(i2cp, header);
-}
-
-/**
- * @brief Terminates a master bus transaction.
+ * @brief Sends data ever the I2C bus.
*
- * @param[in] i2cp pointer to the @p I2CDriver object
- * @param[in] callback operation complete callback
+ * @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
*
- * @iclass
*/
-void i2cMasterStopI(I2CDriver *i2cp, i2ccallback_t callback) {
+void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) {
- chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterStopI");
- chDbgAssert(i2cp->i2c_state == I2C_MREADY,
- "i2cMasterStopI(), #1", "invalid state");
+ chDbgCheck((i2cp != NULL) && (i2cscfg != NULL),
+ "i2cMasterTransmit");
+ chDbgAssert(i2cp->id_state == I2C_READY,
+ "i2cMasterTransmit(), #1",
+ "not active");
- i2cp->id_callback = callback;
- i2c_lld_master_stop(i2cp);
+ i2c_lld_master_transmitI(i2cp, i2cscfg);
}
/**
- * @brief Sends a restart bit.
- * @details Restart bits are required by some types of I2C transactions.
+ * @brief Receives data from the I2C bus.
*
* @param[in] i2cp pointer to the @p I2CDriver object
- * @param[in] callback operation complete callback
+ * @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
*
- * @iclass
*/
-void i2cMasterRestartI(I2CDriver *i2cp, i2ccallback_t callback) {
+void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg) {
- chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterRestartI");
- chDbgAssert(i2cp->i2c_state == I2C_MREADY,
- "i2cMasterRestartI(), #1", "invalid state");
+ chDbgCheck((i2cp != NULL) && (i2cscfg != NULL),
+ "i2cMasterReceive");
+ chDbgAssert(i2cp->id_state == I2C_READY,
+ "i2cMasterReceive(), #1",
+ "not active");
- i2cp->id_callback = callback;
- i2c_lld_master_restart(i2cp);
+ i2c_lld_master_receiveI(i2cp, i2cscfg);
}
-/**
- * @brief Master transmission.
- *
- * @param[in] i2cp pointer to the @p I2CDriver object
- * @param[in] n number of bytes to be transmitted
- * @param[in] txbuf transmit data buffer pointer
- * @param[in] callback operation complete callback
- *
- * @iclass
- */
-void i2cMasterTransmitI(I2CDriver *i2cp, size_t n, const uint8_t *txbuf,
- i2ccallback_t callback) {
-
- chDbgCheck((i2cp != NULL) && (n > 0) &&
- (txbuf != NULL) && (callback != NULL), "i2cMasterTransmitI");
- chDbgAssert(i2cp->i2c_state == I2C_MREADY,
- "i2cMasterTransmitI(), #1", "invalid state");
- i2cp->id_callback = callback;
- i2c_lld_master_transmit(i2cp, n, txbuf);
-}
-/**
- * @brief Master receive.
- *
- * @param[in] i2cp pointer to the @p I2CDriver object
- * @param[in] n number of bytes to be transmitted
- * @param[in] rxbuf receive data buffer pointer
- * @param[in] callback operation complete callback
- *
- * @iclass
- */
-void i2cMasterReceiveI(I2CDriver *i2cp, size_t n, uint8_t *rxbuf,
- i2ccallback_t callback) {
- chDbgCheck((i2cp != NULL) && (n > 0) &&
- (rxbuf != NULL) && (callback != NULL), "i2cMasterReceiveI");
- chDbgAssert(i2cp->i2c_state == I2C_MREADY,
- "i2cMasterReceiveI(), #1", "invalid state");
- i2cp->id_callback = callback;
- i2c_lld_master_receive(i2cp, n, rxbuf);
-}
#if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__)
/**