diff options
author | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-06-21 18:30:50 +0000 |
---|---|---|
committer | barthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2011-06-21 18:30:50 +0000 |
commit | b54133ab1beba9d2923450d1d5f1b2c73dc2afa3 (patch) | |
tree | 035bf75674c3919bf7c5d870b11ed6eb3ad2f597 /testhal | |
parent | 30c130dc10cd5f890c2ad534b97de1ceb2182d0a (diff) | |
download | ChibiOS-b54133ab1beba9d2923450d1d5f1b2c73dc2afa3.tar.gz ChibiOS-b54133ab1beba9d2923450d1d5f1b2c73dc2afa3.tar.bz2 ChibiOS-b54133ab1beba9d2923450d1d5f1b2c73dc2afa3.zip |
I2C. Some fields from I2CSlaveConfig moved to driver.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3066 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'testhal')
-rw-r--r-- | testhal/STM32/I2C/Makefile | 8 | ||||
-rw-r--r-- | testhal/STM32/I2C/lis3.c | 21 | ||||
-rw-r--r-- | testhal/STM32/I2C/max1236.c | 21 | ||||
-rw-r--r-- | testhal/STM32/I2C/tmp75.c | 10 |
4 files changed, 30 insertions, 30 deletions
diff --git a/testhal/STM32/I2C/Makefile b/testhal/STM32/I2C/Makefile index 62eef3874..9f95a5914 100644 --- a/testhal/STM32/I2C/Makefile +++ b/testhal/STM32/I2C/Makefile @@ -77,9 +77,11 @@ CSRC = $(PORTSRC) \ $(CHIBIOS)/os/various/syscalls.c \
main.c \
i2c_pns.c \
- lis3.c\
- max1236.c\
- tmp75.c\
+ tmp75.c\
+ max1236.c\
+ lis3.c\
+
+
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
# setting.
diff --git a/testhal/STM32/I2C/lis3.c b/testhal/STM32/I2C/lis3.c index b07a51f13..a4eb40603 100644 --- a/testhal/STM32/I2C/lis3.c +++ b/testhal/STM32/I2C/lis3.c @@ -30,13 +30,9 @@ static void i2c_lis3_error_cb(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ static I2CSlaveConfig lis3 = {
NULL,
i2c_lis3_error_cb,
- 0,
- 0,
accel_rx_data,
accel_tx_data,
0b0011101,
- 0,
- 0,
{NULL},
};
@@ -109,20 +105,23 @@ int init_lis3(void){ while (i2c_accel_tp == NULL)
chThdSleepMilliseconds(1);
- lis3.rxbytes = 0; //set to 0 because we need only transmit
+#define RXBYTES 0 //set to 0 because we need only transmit
+#define TXBYTES 4
/* configure accelerometer */
- lis3.txbytes = 4;
lis3.txbuf[0] = ACCEL_CTRL_REG1 | AUTO_INCREMENT_BIT; // register address
lis3.txbuf[1] = 0b11100111;
lis3.txbuf[2] = 0b01000001;
lis3.txbuf[3] = 0b00000000;
/* sending */
- i2cMasterTransmit(&I2CD1, &lis3);
+ i2cMasterTransmit(&I2CD1, &lis3, TXBYTES, RXBYTES);
chThdSleepMilliseconds(1);
lis3.id_callback = i2c_lis3_cb;
+#undef RXBYTES
+#undef TXBYTES
+
return 0;
}
@@ -130,11 +129,13 @@ int init_lis3(void){ *
*/
void request_acceleration_data(void){
+#define RXBYTES 6
+#define TXBYTES 1
lis3.txbuf[0] = ACCEL_OUT_DATA | AUTO_INCREMENT_BIT; // register address
- lis3.txbytes = 1;
- lis3.rxbytes = 6;
i2cAcquireBus(&I2CD1);
- i2cMasterTransmit(&I2CD1, &lis3);
+ i2cMasterTransmit(&I2CD1, &lis3, TXBYTES, RXBYTES);
i2cReleaseBus(&I2CD1);
+#undef RXBYTES
+#undef TXBYTES
}
diff --git a/testhal/STM32/I2C/max1236.c b/testhal/STM32/I2C/max1236.c index f5f88bfc4..80e477170 100644 --- a/testhal/STM32/I2C/max1236.c +++ b/testhal/STM32/I2C/max1236.c @@ -42,13 +42,9 @@ static void i2c_max1236_cb(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ static I2CSlaveConfig max1236 = {
NULL,
i2c_max1236_error_cb,
- 0,
- 0,
max1236_rx_data,
max1236_tx_data,
0b0110100,
- 0,
- 0,
{NULL},
};
@@ -59,29 +55,34 @@ static I2CSlaveConfig max1236 = { */
void init_max1236(void){
/* this data we must send via IC to setup ADC */
- max1236.rxbytes = 0;
- max1236.txbytes = 2; // total 2 bytes to be sent
+#define RXBYTES 0
+#define TXBYTES 2
max1236.txbuf[0] = 0b10000011; // config register content. Consult datasheet
max1236.txbuf[1] = 0b00000111; // config register content. Consult datasheet
// transmit out 2 bytes
i2cAcquireBus(&I2CD2);
- i2cMasterTransmit(&I2CD2, &max1236);
+ i2cMasterTransmit(&I2CD2, &max1236, TXBYTES, RXBYTES);
while(I2CD2.id_state != I2C_READY){
chThdSleepMilliseconds(1);
}
/* now add pointer to callback function */
max1236.id_callback = i2c_max1236_cb;
i2cReleaseBus(&I2CD2);
+#undef RXBYTES
+#undef TXBYTES
}
/* Now simply read 8 bytes to get all 4 ADC channels */
void read_max1236(void){
- max1236.txbytes = 0;
- max1236.rxbytes = 8;
+#define TXBYTES 0
+#define RXBYTES 8
+
i2cAcquireBus(&I2CD2);
- i2cMasterReceive(&I2CD2, &max1236);
+ i2cMasterReceive(&I2CD2, &max1236, RXBYTES);
i2cReleaseBus(&I2CD2);
+#undef RXBYTES
+#undef TXBYTES
}
diff --git a/testhal/STM32/I2C/tmp75.c b/testhal/STM32/I2C/tmp75.c index 80aa352ee..e5f502e23 100644 --- a/testhal/STM32/I2C/tmp75.c +++ b/testhal/STM32/I2C/tmp75.c @@ -37,23 +37,19 @@ static void i2c_tmp75_cb(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){ static I2CSlaveConfig tmp75 = {
i2c_tmp75_cb,
i2c_tmp75_error_cb,
- 0,
- 0,
tmp75_rx_data,
tmp75_tx_data,
0b1001000,
- 0,
- 0,
{NULL},
};
/* This is main function. */
void request_temperature(void){
- tmp75.txbytes = 0; // set to zero because we need only reading
- tmp75.rxbytes = 2; // we need to read 2 bytes
+#define TXBYTES 0 // set to zero because we need only reading
+#define RXBYTES 2 // we need to read 2 bytes
i2cAcquireBus(&I2CD2);
- i2cMasterReceive(&I2CD2, &tmp75);
+ i2cMasterReceive(&I2CD2, &tmp75, RXBYTES);
i2cReleaseBus(&I2CD2);
}
|