diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-07-30 15:31:23 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-07-30 15:31:23 +0000 |
commit | 291ccd2db69524176b349100a5710e451039a8ec (patch) | |
tree | 84b3fb4f6f18ac36555df5677a8e0dfcde91af16 /nuttx/arch/arm/src/stm32/stm32_i2c.c | |
parent | 04c0868c718d4c98d6af747cf08f613bc45d1c2c (diff) | |
download | px4-nuttx-291ccd2db69524176b349100a5710e451039a8ec.tar.gz px4-nuttx-291ccd2db69524176b349100a5710e451039a8ec.tar.bz2 px4-nuttx-291ccd2db69524176b349100a5710e451039a8ec.zip |
More TSC2007 driver updates
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3830 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/arch/arm/src/stm32/stm32_i2c.c')
-rw-r--r-- | nuttx/arch/arm/src/stm32/stm32_i2c.c | 37 |
1 files changed, 6 insertions, 31 deletions
diff --git a/nuttx/arch/arm/src/stm32/stm32_i2c.c b/nuttx/arch/arm/src/stm32/stm32_i2c.c index 84f099ba1..91a0aca34 100644 --- a/nuttx/arch/arm/src/stm32/stm32_i2c.c +++ b/nuttx/arch/arm/src/stm32/stm32_i2c.c @@ -62,6 +62,10 @@ * - Be ready for IPMI **/ +/************************************************************************************ + * Included Files + ************************************************************************************/ + #include <nuttx/config.h> #include <nuttx/arch.h> #include <nuttx/irq.h> @@ -84,7 +88,6 @@ #include "stm32_i2c.h" #include "stm32_waste.h" - #if defined(CONFIG_STM32_I2C1) || defined(CONFIG_STM32_I2C2) /************************************************************************************ @@ -108,7 +111,6 @@ struct stm32_i2c_priv_s { uint32_t status; }; - /** I2C Device, Instance */ struct stm32_i2c_inst_s { @@ -120,7 +122,6 @@ struct stm32_i2c_inst_s { uint16_t flags; }; - /************************************************************************************ * Private Data ************************************************************************************/ @@ -139,7 +140,6 @@ struct stm32_i2c_priv_s stm32_i2c2_priv = { }; #endif - /************************************************************************************ * Private Functions ************************************************************************************/ @@ -150,21 +150,18 @@ static inline uint16_t stm32_i2c_getreg(FAR struct stm32_i2c_priv_s *priv, uint8 return getreg16(priv->base + offset); } - /** Put register value by offset */ static inline void stm32_i2c_putreg(FAR struct stm32_i2c_priv_s *priv, uint8_t offset, uint16_t value) { putreg16(value, priv->base + offset); } - /** Modify register value by offset */ static inline void stm32_i2c_modifyreg(FAR struct stm32_i2c_priv_s *priv, uint8_t offset, uint16_t clearbits, uint16_t setbits) { modifyreg16(priv->base + offset, clearbits, setbits); } - void inline stm32_i2c_sem_wait(FAR struct i2c_dev_s *dev) { while( sem_wait( &((struct stm32_i2c_inst_s *)dev)->priv->sem_excl ) != 0 ) { @@ -172,7 +169,6 @@ void inline stm32_i2c_sem_wait(FAR struct i2c_dev_s *dev) } } - int inline stm32_i2c_sem_waitisr(FAR struct i2c_dev_s *dev) { while( sem_wait( &((struct stm32_i2c_inst_s *)dev)->priv->sem_isr ) != 0 ) { @@ -181,27 +177,23 @@ int inline stm32_i2c_sem_waitisr(FAR struct i2c_dev_s *dev) return OK; } - void inline stm32_i2c_sem_post(FAR struct i2c_dev_s *dev) { sem_post( &((struct stm32_i2c_inst_s *)dev)->priv->sem_excl ); } - void inline stm32_i2c_sem_init(FAR struct i2c_dev_s *dev) { sem_init( &((struct stm32_i2c_inst_s *)dev)->priv->sem_excl, 0, 1); sem_init( &((struct stm32_i2c_inst_s *)dev)->priv->sem_isr, 0, 0); } - void inline stm32_i2c_sem_destroy(FAR struct i2c_dev_s *dev) { sem_destroy( &((struct stm32_i2c_inst_s *)dev)->priv->sem_excl ); sem_destroy( &((struct stm32_i2c_inst_s *)dev)->priv->sem_isr ); } - static void stm32_i2c_setclock(FAR struct stm32_i2c_priv_s *priv, uint32_t frequency) { /* Disable Peripheral if rising time is to be changed, @@ -238,20 +230,17 @@ static void stm32_i2c_setclock(FAR struct stm32_i2c_priv_s *priv, uint32_t frequ stm32_i2c_putreg(priv, STM32_I2C_CR1_OFFSET, cr1); } - static inline void stm32_i2c_sendstart(FAR struct stm32_i2c_priv_s *priv) { /* Disable ACK on receive by default and generate START */ stm32_i2c_modifyreg(priv, STM32_I2C_CR1_OFFSET, I2C_CR1_ACK, I2C_CR1_START); } - static inline void stm32_i2c_sendstop(FAR struct stm32_i2c_priv_s *priv) { stm32_i2c_modifyreg(priv, STM32_I2C_CR1_OFFSET, I2C_CR1_ACK, I2C_CR1_STOP); } - static inline uint32_t stm32_i2c_getstatus(FAR struct stm32_i2c_priv_s *priv) { uint32_t status = stm32_i2c_getreg(priv, STM32_I2C_SR1_OFFSET); @@ -259,7 +248,6 @@ static inline uint32_t stm32_i2c_getstatus(FAR struct stm32_i2c_priv_s *priv) return status; } - /************************************************************************************ * Interrupt Service Routines ************************************************************************************/ @@ -425,8 +413,6 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s * priv) priv->status = status; return OK; } - - /* Decode ***************************************************************************/ @@ -444,7 +430,6 @@ static int stm32_i2c2_isr(int irq, void *context) } #endif - /************************************************************************************ * Private Initialization and Deinitialization ************************************************************************************/ @@ -511,7 +496,6 @@ static int stm32_i2c_init(FAR struct stm32_i2c_priv_s *priv) return OK; } - /** Shutdown the I2C hardware */ static int stm32_i2c_deinit(FAR struct stm32_i2c_priv_s *priv) { @@ -555,7 +539,6 @@ static int stm32_i2c_deinit(FAR struct stm32_i2c_priv_s *priv) return OK; } - /************************************************************************************ * Device Driver OPS - Blocking Type ************************************************************************************/ @@ -574,7 +557,6 @@ uint32_t stm32_i2c_setfrequency(FAR struct i2c_dev_s *dev, uint32_t frequency) return ((struct stm32_i2c_inst_s *)dev)->frequency; } - int stm32_i2c_setaddress(FAR struct i2c_dev_s *dev, int addr, int nbits) { stm32_i2c_sem_wait(dev); @@ -586,7 +568,6 @@ int stm32_i2c_setaddress(FAR struct i2c_dev_s *dev, int addr, int nbits) return OK; } - int stm32_i2c_process(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *msgs, int count) { struct stm32_i2c_inst_s *inst = (struct stm32_i2c_inst_s *)dev; @@ -666,7 +647,6 @@ int stm32_i2c_process(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *msgs, int return -status_errno; } - int stm32_i2c_write(FAR struct i2c_dev_s *dev, const uint8_t *buffer, int buflen) { stm32_i2c_sem_wait(dev); /* ensure that address or flags don't change meanwhile */ @@ -681,7 +661,6 @@ int stm32_i2c_write(FAR struct i2c_dev_s *dev, const uint8_t *buffer, int buflen return stm32_i2c_process(dev, &msgv, 1); } - int stm32_i2c_read(FAR struct i2c_dev_s *dev, uint8_t *buffer, int buflen) { stm32_i2c_sem_wait(dev); /* ensure that address or flags don't change meanwhile */ @@ -696,7 +675,6 @@ int stm32_i2c_read(FAR struct i2c_dev_s *dev, uint8_t *buffer, int buflen) return stm32_i2c_process(dev, &msgv, 1); } - #ifdef CONFIG_I2C_WRITEREAD int stm32_i2c_writeread(FAR struct i2c_dev_s *dev, const uint8_t *wbuffer, int wbuflen, uint8_t *buffer, int buflen) @@ -722,7 +700,6 @@ int stm32_i2c_writeread(FAR struct i2c_dev_s *dev, const uint8_t *wbuffer, int w } #endif - #ifdef CONFIG_I2C_TRANSFER int stm32_i2c_transfer(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *msgs, int count) { @@ -731,7 +708,6 @@ int stm32_i2c_transfer(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *msgs, in } #endif - /************************************************************************************ * Device Structures, Instantiation ************************************************************************************/ @@ -740,9 +716,9 @@ struct i2c_ops_s stm32_i2c_ops = { .setfrequency = stm32_i2c_setfrequency, .setaddress = stm32_i2c_setaddress, .write = stm32_i2c_write, - .read = stm32_i2c_read, + .read = stm32_i2c_read #ifdef CONFIG_I2C_WRITEREAD - .writeread = stm32_i2c_writeread + , .writeread = stm32_i2c_writeread #endif #ifdef CONFIG_I2C_TRANSFER , .transfer = stm32_i2c_transfer @@ -753,7 +729,6 @@ struct i2c_ops_s stm32_i2c_ops = { #endif }; - /************************************************************************************ * Public Function - Initialization ************************************************************************************/ |