I2C. Code cleanups.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3056 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
barthess 2011-06-18 13:35:26 +00:00
parent 350ae0a1a9
commit f3e571839b
4 changed files with 11 additions and 27 deletions

View File

@ -96,11 +96,7 @@ typedef enum {
/**
* @brief I2C notification callback type.
* @details This callback invoked when byte transfer finish event occurs,
* No matter sending or reading. This function designed
* for sending (re)start or stop events to I2C bus from user level.
*
* If callback function is set to NULL - driver atomaticcaly
* generate stop condition after the transfer finish.
* No matter sending or reading.
*
* @param[in] i2cp pointer to the @p I2CDriver object triggering the
* callback
@ -135,8 +131,7 @@ typedef uint8_t i2cblock_t;
struct I2CSlaveConfig{
/**
* @brief Callback pointer.
* @note Transfer finished callback. Invoke when all data transferred, or
* by DMA buffer events
* @note Transfer finished callback. Invoke when all data transferred.
* If set to @p NULL then the callback is disabled.
*/
i2ccallback_t id_callback;
@ -154,8 +149,8 @@ struct I2CSlaveConfig{
i2cblock_t *txbuf; /*!< Pointer to transmit buffer.*/
uint16_t slave_addr; /*!< Slave device address.*/
uint8_t nbit_addr; /*!< Length of address (must be 7 or 10).*/
i2cflags_t errors;
i2cflags_t flags;
i2cflags_t errors; /*!< Error flags.*/
i2cflags_t flags; /*!< State flags.*/
/* Status Change @p EventSource.*/
EventSource sevent;
};
@ -212,7 +207,7 @@ struct I2CSlaveConfig{
* - Callback invocation.
* - Waiting thread wakeup, if any.
* - Driver state transitions.
* .
*
* @note This macro is meant to be used in the low level drivers
* implementation only.
*
@ -236,7 +231,7 @@ extern "C" {
#endif
void i2cInit(void);
void i2cObjectInit(I2CDriver *i2cp);
void i2cStart(I2CDriver *i2cp, I2CConfig *config);
void i2cStart(I2CDriver *i2cp, const I2CConfig *config);
void i2cStop(I2CDriver *i2cp);
void i2cMasterTransmit(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg);
void i2cMasterReceive(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg);

View File

@ -157,15 +157,11 @@ struct I2CDriver{
/**
* @brief Current configuration data.
*/
I2CConfig *id_config;
const I2CConfig *id_config;
/**
* @brief Current slave configuration data.
*/
I2CSlaveConfig *id_slave_config;
/**
* @brief RW-bit sent to slave.
*/
uint8_t rw_bit;
uint8_t slave_addr1; // 7-bit address of the slave
uint8_t slave_addr2; // used in 10-bit address mode
@ -194,7 +190,7 @@ struct I2CDriver{
*/
#define i2c_lld_wait_bus_free(i2cp) { \
uint32_t tmo = 0xffff; \
while((i2cp->id_i2c->SR2 & I2C_SR2_BUSY) && tmo--) \
while((i2cp->id_i2c->SR2 & I2C_SR2_BUSY) && tmo--) \
; \
}

View File

@ -96,7 +96,7 @@ void i2cObjectInit(I2CDriver *i2cp) {
*
* @api
*/
void i2cStart(I2CDriver *i2cp, I2CConfig *config) {
void i2cStart(I2CDriver *i2cp, const I2CConfig *config) {
chDbgCheck((i2cp != NULL) && (config != NULL), "i2cStart");

View File

@ -8,7 +8,7 @@
#include "max1236.h"
/* I2C1 */
static I2CConfig i2cfg1 = {
static const I2CConfig i2cfg1 = {
OPMODE_I2C,
100000,
STD_DUTY_CYCLE,
@ -19,7 +19,7 @@ static I2CConfig i2cfg1 = {
};
/* I2C2 */
static I2CConfig i2cfg2 = {
static const I2CConfig i2cfg2 = {
OPMODE_I2C,
100000,
STD_DUTY_CYCLE,
@ -36,14 +36,7 @@ void I2CInit_pns(void){
i2cInit();
i2cStart(&I2CD1, &i2cfg1);
while(I2CD1.id_state != I2C_READY){ // wait ready status
chThdSleepMilliseconds(1);
}
i2cStart(&I2CD2, &i2cfg2);
while(I2CD2.id_state != I2C_READY){ // wait ready status
chThdSleepMilliseconds(1);
}
/* tune ports for I2C1*/
palSetPadMode(IOPORT2, 6, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);