aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-08-17 13:23:41 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2010-08-17 13:23:41 +0000
commit4e26a3b42cb49974f63d1b8727d7b1d1830c9c81 (patch)
tree12c7970c2a76583baff5108acedd0d4cc395abf7 /os
parent8b45c58317683148179c9964e67c8f7d0683257b (diff)
downloadChibiOS-4e26a3b42cb49974f63d1b8727d7b1d1830c9c81.tar.gz
ChibiOS-4e26a3b42cb49974f63d1b8727d7b1d1830c9c81.tar.bz2
ChibiOS-4e26a3b42cb49974f63d1b8727d7b1d1830c9c81.zip
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2133 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r--os/hal/include/i2c.h45
-rw-r--r--os/hal/src/i2c.c31
-rw-r--r--os/hal/templates/i2c_lld.c15
-rw-r--r--os/hal/templates/i2c_lld.h3
4 files changed, 86 insertions, 8 deletions
diff --git a/os/hal/include/i2c.h b/os/hal/include/i2c.h
index 3ee38a52e..1ffba8a3e 100644
--- a/os/hal/include/i2c.h
+++ b/os/hal/include/i2c.h
@@ -60,9 +60,10 @@ typedef enum {
I2C_UNINIT = 0, /**< @brief Not initialized. */
I2C_STOP = 1, /**< @brief Stopped. */
I2C_READY = 2, /**< @brief Ready. */
- I2C_MREADY = 3, /**< @brief START sent. */
+ I2C_MREADY = 3, /**< @brief START and address sent. */
I2C_MTRANSMIT = 4, /**< @brief Master transmitting. */
I2C_MRECEIVE = 5, /**< @brief Master receiving. */
+ I2C_MERROR = 6 /**< @brief Error condition. */
} i2cstate_t;
#include "i2c_lld.h"
@@ -71,6 +72,43 @@ typedef enum {
/* Driver macros. */
/*===========================================================================*/
+/**
+ * @brief Read mode.
+ */
+#define I2C_READ 1
+
+/**
+ * @brief Write mode.
+ */
+#define I2C_WRITE 0
+
+/**
+ * @brief Seven bits addresses header builder.
+ *
+ * @param[in] addr seven bits address value
+ * @param[in] rw read/write flag
+ *
+ * @return A 16 bit value representing the header, the most
+ * significant byte is always zero.
+ */
+#define I2C_ADDR7(addr, rw) (uint16_t)((addr) << 1 | (rw))
+
+
+/**
+ * @brief Ten bits addresses header builder.
+ *
+ * @param[in] addr ten bits address value
+ * @param[in] rw read/write flag
+ *
+ * @return A 16 bit value representing the header, the most
+ * significant byte is the first one to be transmitted.
+ */
+#define I2C_ADDR10(addr, rw) \
+ (uint16_t)(0xF000 | \
+ (((addr) & 0x0300) << 1) | \
+ (((rw) << 8)) | \
+ ((addr) & 0x00FF))
+
/*===========================================================================*/
/* External declarations. */
/*===========================================================================*/
@@ -82,8 +120,11 @@ extern "C" {
void i2cObjectInit(I2CDriver *i2cp);
void i2cStart(I2CDriver *i2cp, const I2CConfig *config);
void i2cStop(I2CDriver *i2cp);
- void i2cMasterStartI(I2CDriver *i2cp, i2ccallback_t callback);
+ void i2cMasterStartI(I2CDriver *i2cp,
+ uint16_t header,
+ i2ccallback_t callback);
void i2cMasterStopI(I2CDriver *i2cp, i2ccallback_t callback);
+ void i2cMasterRestartI(I2CDriver *i2cp, i2ccallback_t callback);
void i2cMasterTransmitI(I2CDriver *i2cp, size_t n, const uint8_t *txbuf,
i2ccallback_t callback);
void i2cMasterReceiveI(I2CDriver *i2cp, size_t n, uint8_t *rxbuf,
diff --git a/os/hal/src/i2c.c b/os/hal/src/i2c.c
index 03d882446..cc48c4147 100644
--- a/os/hal/src/i2c.c
+++ b/os/hal/src/i2c.c
@@ -104,19 +104,24 @@ void i2cStop(I2CDriver *i2cp) {
}
/**
- * @brief Initiates a master bus transaction.
+ * @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
*/
-void i2cMasterStartI(I2CDriver *i2cp, i2ccallback_t callback) {
+void i2cMasterStartI(I2CDriver *i2cp,
+ uint16_t header,
+ i2ccallback_t callback) {
chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterStartI");
- chDbgAssert((i2cp->i2c_state == I2C_READY) || (i2cp->i2c_state == I2C_MREADY),
+ chDbgAssert(i2cp->i2c_state == I2C_READY,
"i2cMasterStartI(), #1", "invalid state");
i2cp->id_callback = callback;
- i2c_lld_master_start(i2cp);
+ i2c_lld_master_start(i2cp, header);
}
/**
@@ -135,6 +140,24 @@ void i2cMasterStopI(I2CDriver *i2cp, i2ccallback_t callback) {
i2c_lld_master_stop(i2cp);
}
+
+/**
+ * @brief Sends a restart bit.
+ * @details Restart bits are required by some types of I2C transactions.
+ *
+ * @param[in] i2cp pointer to the @p I2CDriver object
+ * @param[in] callback operation complete callback
+ */
+void i2cMasterRestartI(I2CDriver *i2cp, i2ccallback_t callback) {
+
+ chDbgCheck((i2cp != NULL) && (callback != NULL), "i2cMasterRestartI");
+ chDbgAssert(i2cp->i2c_state == I2C_MREADY,
+ "i2cMasterRestartI(), #1", "invalid state");
+
+ i2cp->id_callback = callback;
+ i2c_lld_master_restart(i2cp);
+}
+
/**
* @brief Master transmission.
*
diff --git a/os/hal/templates/i2c_lld.c b/os/hal/templates/i2c_lld.c
index 334088aeb..e41cc3b29 100644
--- a/os/hal/templates/i2c_lld.c
+++ b/os/hal/templates/i2c_lld.c
@@ -81,10 +81,13 @@ void i2c_lld_stop(I2CDriver *i2cp) {
/**
* @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
*/
-void i2c_lld_master_start(I2CDriver *i2cp) {
+void i2c_lld_master_start(I2CDriver *i2cp, uint16_t header) {
}
@@ -98,6 +101,16 @@ void i2c_lld_master_stop(I2CDriver *i2cp) {
}
/**
+ * @brief Sends a restart bit.
+ * @details Restart bits are required by some types of I2C transactions.
+ *
+ * @param[in] i2cp pointer to the @p I2CDriver object
+ */
+void i2c_lld_master_restart(I2CDriver *i2cp) {
+
+}
+
+/**
* @brief Master transmission.
*
* @param[in] i2cp pointer to the @p I2CDriver object
diff --git a/os/hal/templates/i2c_lld.h b/os/hal/templates/i2c_lld.h
index 250c827e5..3a2ceb4aa 100644
--- a/os/hal/templates/i2c_lld.h
+++ b/os/hal/templates/i2c_lld.h
@@ -91,8 +91,9 @@ extern "C" {
void i2c_lld_init(void);
void i2c_lld_start(I2CDriver *i2cp);
void i2c_lld_stop(I2CDriver *i2cp);
- void i2c_lld_master_start(I2CDriver *i2cp);
+ void i2c_lld_master_start(I2CDriver *i2cp, uint16_t header);
void i2c_lld_master_stop(I2CDriver *i2cp);
+ void i2c_lld_master_restart(I2CDriver *i2cp);
void i2c_lld_master_transmit(I2CDriver *i2cp, size_t n,
const uint8_t *txbuf);
void i2c_lld_master_receive(I2CDriver *i2cp, size_t n, uint8_t *rxbuf);