aboutsummaryrefslogtreecommitdiffstats
path: root/testhal
diff options
context:
space:
mode:
authorbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-06-21 20:17:14 +0000
committerbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-06-21 20:17:14 +0000
commit70179f12dd387a82493d13fd51d5aab7e4e55674 (patch)
treeead37a5e698acfac0a69cb3247351561bc38efe0 /testhal
parentb54133ab1beba9d2923450d1d5f1b2c73dc2afa3 (diff)
downloadChibiOS-70179f12dd387a82493d13fd51d5aab7e4e55674.tar.gz
ChibiOS-70179f12dd387a82493d13fd51d5aab7e4e55674.tar.bz2
ChibiOS-70179f12dd387a82493d13fd51d5aab7e4e55674.zip
I2C. Slave config structure now have const qualifier. Moset of fields moved to the driver structure. May be broken events subsystem in driver.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3067 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'testhal')
-rw-r--r--testhal/STM32/I2C/lis3.c53
-rw-r--r--testhal/STM32/I2C/max1236.c12
-rw-r--r--testhal/STM32/I2C/tmp75.c7
3 files changed, 34 insertions, 38 deletions
diff --git a/testhal/STM32/I2C/lis3.c b/testhal/STM32/I2C/lis3.c
index a4eb40603..00bb712a1 100644
--- a/testhal/STM32/I2C/lis3.c
+++ b/testhal/STM32/I2C/lis3.c
@@ -26,20 +26,6 @@ static void i2c_lis3_error_cb(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){
while(TRUE);
}
-// Accelerometer lis3lv02dq config
-static I2CSlaveConfig lis3 = {
- NULL,
- i2c_lis3_error_cb,
- accel_rx_data,
- accel_tx_data,
- 0b0011101,
- {NULL},
-};
-
-
-
-
-
/**
* This treading need for convenient realize
* "read through write" process.
@@ -53,7 +39,7 @@ static msg_t I2CAccelThread(void *arg) {
int16_t acceleration_y = 0;
int16_t acceleration_z = 0;
- I2CDriver *i2cp;
+ I2CSlaveConfig *i2cscfg;
msg_t msg;
while (TRUE) {
@@ -65,30 +51,42 @@ static msg_t I2CAccelThread(void *arg) {
chSysUnlock();
/***************** Perform processing here. ***************************/
- i2cp = (I2CDriver *)msg;
+ i2cscfg = (I2CSlaveConfig *)msg;
/* collect measured data */
- acceleration_x = lis3.rxbuf[0] + (lis3.rxbuf[1] << 8);
- acceleration_y = lis3.rxbuf[2] + (lis3.rxbuf[3] << 8);
- acceleration_z = lis3.rxbuf[4] + (lis3.rxbuf[5] << 8);
+ acceleration_x = i2cscfg->rxbuf[0] + (i2cscfg->rxbuf[1] << 8);
+ acceleration_y = i2cscfg->rxbuf[2] + (i2cscfg->rxbuf[3] << 8);
+ acceleration_z = i2cscfg->rxbuf[4] + (i2cscfg->rxbuf[5] << 8);
}
return 0;
}
-
-
/* This callback raise up when transfer finished */
static void i2c_lis3_cb(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){
- (void) i2cscfg;
-
+ (void) i2cp;
// only wake up processing thread
if (i2c_accel_tp != NULL) {
- i2c_accel_tp->p_msg = (msg_t)i2cp;
+ i2c_accel_tp->p_msg = (msg_t)i2cscfg;
chSchReadyI(i2c_accel_tp);
i2c_accel_tp = NULL;
}
}
+
+// Accelerometer lis3lv02dq config
+static const I2CSlaveConfig lis3 = {
+ i2c_lis3_cb,
+ i2c_lis3_error_cb,
+ accel_rx_data,
+ accel_tx_data,
+ {NULL},
+};
+
+
+#define lis3_addr 0b0011101
+
+
+
/**
* Init function. Here we will also start personal serving thread.
*/
@@ -105,8 +103,8 @@ int init_lis3(void){
while (i2c_accel_tp == NULL)
chThdSleepMilliseconds(1);
-#define RXBYTES 0 //set to 0 because we need only transmit
#define TXBYTES 4
+#define RXBYTES 0 //set to 0 because we need only transmit
/* configure accelerometer */
lis3.txbuf[0] = ACCEL_CTRL_REG1 | AUTO_INCREMENT_BIT; // register address
@@ -115,9 +113,8 @@ int init_lis3(void){
lis3.txbuf[3] = 0b00000000;
/* sending */
- i2cMasterTransmit(&I2CD1, &lis3, TXBYTES, RXBYTES);
+ i2cMasterTransmit(&I2CD1, &lis3, lis3_addr, TXBYTES, RXBYTES);
chThdSleepMilliseconds(1);
- lis3.id_callback = i2c_lis3_cb;
#undef RXBYTES
#undef TXBYTES
@@ -133,7 +130,7 @@ void request_acceleration_data(void){
#define TXBYTES 1
lis3.txbuf[0] = ACCEL_OUT_DATA | AUTO_INCREMENT_BIT; // register address
i2cAcquireBus(&I2CD1);
- i2cMasterTransmit(&I2CD1, &lis3, TXBYTES, RXBYTES);
+ i2cMasterTransmit(&I2CD1, &lis3, lis3_addr, TXBYTES, RXBYTES);
i2cReleaseBus(&I2CD1);
#undef RXBYTES
#undef TXBYTES
diff --git a/testhal/STM32/I2C/max1236.c b/testhal/STM32/I2C/max1236.c
index 80e477170..ed9d12ca6 100644
--- a/testhal/STM32/I2C/max1236.c
+++ b/testhal/STM32/I2C/max1236.c
@@ -39,15 +39,15 @@ static void i2c_max1236_cb(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){
// ADC maxim MAX1236 config
-static I2CSlaveConfig max1236 = {
- NULL,
+static const I2CSlaveConfig max1236 = {
+ i2c_max1236_cb,
i2c_max1236_error_cb,
max1236_rx_data,
max1236_tx_data,
- 0b0110100,
{NULL},
};
+#define max1236_addr 0b0110100
/**
* Initilization routine. See datasheet on page 13 to understand
@@ -63,12 +63,10 @@ void init_max1236(void){
// transmit out 2 bytes
i2cAcquireBus(&I2CD2);
- i2cMasterTransmit(&I2CD2, &max1236, TXBYTES, RXBYTES);
+ i2cMasterTransmit(&I2CD2, &max1236, max1236_addr, 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
@@ -81,7 +79,7 @@ void read_max1236(void){
#define RXBYTES 8
i2cAcquireBus(&I2CD2);
- i2cMasterReceive(&I2CD2, &max1236, RXBYTES);
+ i2cMasterReceive(&I2CD2, &max1236, max1236_addr, RXBYTES);
i2cReleaseBus(&I2CD2);
#undef RXBYTES
#undef TXBYTES
diff --git a/testhal/STM32/I2C/tmp75.c b/testhal/STM32/I2C/tmp75.c
index e5f502e23..6744fe325 100644
--- a/testhal/STM32/I2C/tmp75.c
+++ b/testhal/STM32/I2C/tmp75.c
@@ -34,22 +34,23 @@ static void i2c_tmp75_cb(I2CDriver *i2cp, I2CSlaveConfig *i2cscfg){
}
// Fill TMP75 config.
-static I2CSlaveConfig tmp75 = {
+static const I2CSlaveConfig tmp75 = {
i2c_tmp75_cb,
i2c_tmp75_error_cb,
tmp75_rx_data,
tmp75_tx_data,
- 0b1001000,
{NULL},
};
+#define tmp75_addr 0b1001000
+
/* This is main function. */
void request_temperature(void){
#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, RXBYTES);
+ i2cMasterReceive(&I2CD2, &tmp75, tmp75_addr, RXBYTES);
i2cReleaseBus(&I2CD2);
}