git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@2133 35acf78f-673a-0410-8e92-d51de3d6d3f4

This commit is contained in:
gdisirio 2010-08-17 13:23:41 +00:00
parent 8b45c58317
commit 4e26a3b42c
4 changed files with 86 additions and 8 deletions

View File

@ -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,

View File

@ -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.
*

View File

@ -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) {
}
@ -97,6 +100,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.
*

View File

@ -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);