aboutsummaryrefslogtreecommitdiffstats
path: root/testhal/STM32
diff options
context:
space:
mode:
Diffstat (limited to 'testhal/STM32')
-rw-r--r--testhal/STM32/I2C/chconf.h2
-rw-r--r--testhal/STM32/I2C/halconf.h9
-rw-r--r--testhal/STM32/I2C/i2c_pns.c8
-rw-r--r--testhal/STM32/I2C/lis3.c91
-rw-r--r--testhal/STM32/I2C/main.c4
-rw-r--r--testhal/STM32/I2C/max1236.c31
-rw-r--r--testhal/STM32/I2C/mcuconf.h4
-rw-r--r--testhal/STM32/I2C/tmp75.c8
8 files changed, 47 insertions, 110 deletions
diff --git a/testhal/STM32/I2C/chconf.h b/testhal/STM32/I2C/chconf.h
index 9f5273ba5..a293288d3 100644
--- a/testhal/STM32/I2C/chconf.h
+++ b/testhal/STM32/I2C/chconf.h
@@ -188,7 +188,7 @@
* @note The default is @p TRUE.
*/
#if !defined(CH_USE_MUTEXES) || defined(__DOXYGEN__)
-#define CH_USE_MUTEXES FALSE
+#define CH_USE_MUTEXES TRUE
#endif
/**
diff --git a/testhal/STM32/I2C/halconf.h b/testhal/STM32/I2C/halconf.h
index f64120126..da52785c0 100644
--- a/testhal/STM32/I2C/halconf.h
+++ b/testhal/STM32/I2C/halconf.h
@@ -178,7 +178,7 @@
* @note Disabling this option saves both code and data space.
*/
#if !defined(I2C_USE_WAIT) || defined(__DOXYGEN__)
-#define I2C_USE_WAIT TRUE
+#define I2C_USE_WAIT FALSE
#endif
/**
@@ -188,6 +188,13 @@
#define I2C_USE_MUTUAL_EXCLUSION TRUE
#endif
+/**
+ * @brief Switch to asynchronouse driver with callbacks.
+ */
+#if !defined(I2C_SUPPORTS_CALLBACKS) || defined(__DOXYGEN__)
+#define I2C_SUPPORTS_CALLBACKS TRUE
+#endif
+
/*===========================================================================*/
/* MAC driver related settings. */
/*===========================================================================*/
diff --git a/testhal/STM32/I2C/i2c_pns.c b/testhal/STM32/I2C/i2c_pns.c
index 63f7d99bd..44f4a8a33 100644
--- a/testhal/STM32/I2C/i2c_pns.c
+++ b/testhal/STM32/I2C/i2c_pns.c
@@ -32,7 +32,6 @@ static const I2CConfig i2cfg2 = {
void I2CInit_pns(void){
-
i2cInit();
i2cStart(&I2CD1, &i2cfg1);
@@ -46,13 +45,12 @@ void I2CInit_pns(void){
palSetPadMode(IOPORT2, 10, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
palSetPadMode(IOPORT2, 11, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
-
/* startups. Pauses added just to be safe */
+ chThdSleepMilliseconds(1000);
init_max1236();
- chThdSleepMilliseconds(100);
-
+ chThdSleepMilliseconds(1000);
init_lis3();
- chThdSleepMilliseconds(100);
+ chThdSleepMilliseconds(1000);
}
diff --git a/testhal/STM32/I2C/lis3.c b/testhal/STM32/I2C/lis3.c
index 26a3292f5..401f56199 100644
--- a/testhal/STM32/I2C/lis3.c
+++ b/testhal/STM32/I2C/lis3.c
@@ -14,10 +14,17 @@
#include "lis3.h"
+#define lis3_addr 0b0011101
+
+
/* buffers */
static i2cblock_t accel_rx_data[ACCEL_RX_DEPTH];
static i2cblock_t accel_tx_data[ACCEL_TX_DEPTH];
+static int16_t acceleration_x = 0;
+static int16_t acceleration_y = 0;
+static int16_t acceleration_z = 0;
+
/* Error trap */
static void i2c_lis3_error_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){
(void)i2cscfg;
@@ -26,50 +33,10 @@ static void i2c_lis3_error_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){
while(TRUE);
}
-/**
- * This treading need for convenient realize
- * "read through write" process.
- */
-static WORKING_AREA(I2CAccelThreadWA, 128);
-static Thread *i2c_accel_tp = NULL;
-static msg_t I2CAccelThread(void *arg) {
- (void)arg;
-
- int16_t acceleration_x = 0;
- int16_t acceleration_y = 0;
- int16_t acceleration_z = 0;
-
- I2CSlaveConfig *i2cscfg;
- msg_t msg;
-
- while (TRUE) {
- /* Waiting for wake up */
- chSysLock();
- i2c_accel_tp = chThdSelf();
- chSchGoSleepS(THD_STATE_SUSPENDED);
- msg = chThdSelf()->p_msg; /* Retrieving the message, optional.*/
- chSysUnlock();
-
- /***************** Perform processing here. ***************************/
- i2cscfg = (I2CSlaveConfig *)msg;
-
- /* collect measured data */
- acceleration_x = accel_rx_data[0] + (accel_rx_data[1] << 8);
- acceleration_y = accel_rx_data[2] + (accel_rx_data[3] << 8);
- acceleration_z = accel_rx_data[4] + (accel_rx_data[5] << 8);
- }
- return 0;
-}
-
/* This callback raise up when transfer finished */
static void i2c_lis3_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){
- (void) i2cp;
- /* only wake up processing thread */
- if (i2c_accel_tp != NULL) {
- i2c_accel_tp->p_msg = (msg_t)i2cscfg;
- chSchReadyI(i2c_accel_tp);
- i2c_accel_tp = NULL;
- }
+ (void)i2cp;
+ (void)i2cscfg;
}
@@ -80,29 +47,10 @@ static const I2CSlaveConfig lis3 = {
};
-#define lis3_addr 0b0011101
-
-
-
/**
* Init function. Here we will also start personal serving thread.
*/
int init_lis3(void){
-
- /* Starting the accelerometer serving thread.*/
- i2c_accel_tp = chThdCreateStatic(I2CAccelThreadWA,
- sizeof(I2CAccelThreadWA),
- HIGHPRIO,
- I2CAccelThread,
- NULL);
-
- /* wait thread statup */
- while (i2c_accel_tp == NULL)
- chThdSleepMilliseconds(1);
-
-#define TXBYTES 4
-#define RXBYTES 0 /* set to 0 because we need only transmit */
-
/* configure accelerometer */
accel_tx_data[0] = ACCEL_CTRL_REG1 | AUTO_INCREMENT_BIT; /* register address */
accel_tx_data[1] = 0b11100111;
@@ -110,12 +58,7 @@ int init_lis3(void){
accel_tx_data[3] = 0b00000000;
/* sending */
- i2cMasterTransmit(&I2CD1, &lis3, lis3_addr, accel_tx_data, TXBYTES, accel_rx_data, RXBYTES);
- chThdSleepMilliseconds(1);
-
-#undef RXBYTES
-#undef TXBYTES
-
+ i2cMasterTransmit(&I2CD1, &lis3, lis3_addr, accel_tx_data, 4, accel_rx_data, 0);
return 0;
}
@@ -123,13 +66,13 @@ int init_lis3(void){
*
*/
void request_acceleration_data(void){
-#define RXBYTES 6
-#define TXBYTES 1
accel_tx_data[0] = ACCEL_OUT_DATA | AUTO_INCREMENT_BIT; // register address
- i2cAcquireBus(&I2CD1);
- i2cMasterTransmit(&I2CD1, &lis3, lis3_addr, accel_tx_data, TXBYTES, accel_rx_data, RXBYTES);
- i2cReleaseBus(&I2CD1);
-#undef RXBYTES
-#undef TXBYTES
+ //i2cAcquireBus(&I2CD1);
+ i2cMasterTransmit(&I2CD1, &lis3, lis3_addr, accel_tx_data, 1, accel_rx_data, 6);
+ //i2cReleaseBus(&I2CD1);
+
+ acceleration_x = accel_rx_data[0] + (accel_rx_data[1] << 8);
+ acceleration_y = accel_rx_data[2] + (accel_rx_data[3] << 8);
+ acceleration_z = accel_rx_data[4] + (accel_rx_data[5] << 8);
}
diff --git a/testhal/STM32/I2C/main.c b/testhal/STM32/I2C/main.c
index ce8cb5522..b828953c5 100644
--- a/testhal/STM32/I2C/main.c
+++ b/testhal/STM32/I2C/main.c
@@ -68,7 +68,7 @@ static msg_t PollMax1236Thread(void *arg) {
systime_t time = chTimeNow();
while (TRUE) {
- time += MS2ST(20);
+ time += MS2ST(200);
/* Call reading function */
read_max1236();
chThdSleepUntil(time);
@@ -83,7 +83,7 @@ static msg_t PollAccelThread(void *arg) {
systime_t time = chTimeNow();
while (TRUE) {
- time += MS2ST(2);
+ time += MS2ST(20);
request_acceleration_data();
chThdSleepUntil(time);
}
diff --git a/testhal/STM32/I2C/max1236.c b/testhal/STM32/I2C/max1236.c
index 3e3dbd0c1..09e2c8b35 100644
--- a/testhal/STM32/I2C/max1236.c
+++ b/testhal/STM32/I2C/max1236.c
@@ -10,6 +10,10 @@
#include "max1236.h"
+
+#define max1236_addr 0b0110100
+
+
/* Data buffers */
static i2cblock_t max1236_rx_data[MAX1236_RX_DEPTH];
static i2cblock_t max1236_tx_data[MAX1236_TX_DEPTH];
@@ -31,10 +35,6 @@ static void i2c_max1236_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){
(void)*i2cp;
(void)*i2cscfg;
/* get ADC data */
- ch1 = ((max1236_rx_data[0] & 0xF) << 8) + max1236_rx_data[1];
- ch2 = ((max1236_rx_data[2] & 0xF) << 8) + max1236_rx_data[3];
- ch3 = ((max1236_rx_data[4] & 0xF) << 8) + max1236_rx_data[5];
- ch4 = ((max1236_rx_data[6] & 0xF) << 8) + max1236_rx_data[7];
}
@@ -45,7 +45,6 @@ static const I2CSlaveConfig max1236 = {
i2c_max1236_error_cb,
};
-#define max1236_addr 0b0110100
/**
* Initilization routine. See datasheet on page 13 to understand
@@ -53,32 +52,24 @@ static const I2CSlaveConfig max1236 = {
*/
void init_max1236(void){
/* this data we must send via IC to setup ADC */
-#define RXBYTES 0
-#define TXBYTES 2
max1236_tx_data[0] = 0b10000011; /* config register content. Consult datasheet */
max1236_tx_data[1] = 0b00000111; /* config register content. Consult datasheet */
-
/* transmit out 2 bytes */
i2cAcquireBus(&I2CD2);
- i2cMasterTransmit(&I2CD2, &max1236, max1236_addr, max1236_tx_data, TXBYTES, max1236_rx_data, RXBYTES);
- while(I2CD2.id_state != I2C_READY){
- chThdSleepMilliseconds(1);
- }
+ i2cMasterTransmit(&I2CD2, &max1236, max1236_addr, max1236_tx_data, 2, max1236_rx_data, 0);
i2cReleaseBus(&I2CD2);
-#undef RXBYTES
-#undef TXBYTES
}
/* Now simply read 8 bytes to get all 4 ADC channels */
void read_max1236(void){
-#define TXBYTES 0
-#define RXBYTES 8
-
i2cAcquireBus(&I2CD2);
- i2cMasterReceive(&I2CD2, &max1236, max1236_addr, max1236_rx_data, RXBYTES);
+ i2cMasterReceive(&I2CD2, &max1236, max1236_addr, max1236_rx_data, 8);
i2cReleaseBus(&I2CD2);
-#undef RXBYTES
-#undef TXBYTES
+
+ ch1 = ((max1236_rx_data[0] & 0xF) << 8) + max1236_rx_data[1];
+ ch2 = ((max1236_rx_data[2] & 0xF) << 8) + max1236_rx_data[3];
+ ch3 = ((max1236_rx_data[4] & 0xF) << 8) + max1236_rx_data[5];
+ ch4 = ((max1236_rx_data[6] & 0xF) << 8) + max1236_rx_data[7];
}
diff --git a/testhal/STM32/I2C/mcuconf.h b/testhal/STM32/I2C/mcuconf.h
index 105c168f4..809c3abd2 100644
--- a/testhal/STM32/I2C/mcuconf.h
+++ b/testhal/STM32/I2C/mcuconf.h
@@ -159,10 +159,10 @@
#define STM32_I2C_I2C2_DMA_ERROR_HOOK() chSysHalt()
/* I2C1 */
#define STM32_I2C_I2C1_USE_GPT_TIM GPTD1
-#define STM32_I2C_I2C1_USE_POLLING_WAIT FALSE
+#define STM32_I2C_I2C1_USE_POLLING_WAIT TRUE
/* I2C2 */
#define STM32_I2C_I2C2_USE_GPT_TIM GPTD2
-#define STM32_I2C_I2C2_USE_POLLING_WAIT FALSE
+#define STM32_I2C_I2C2_USE_POLLING_WAIT TRUE
/*
diff --git a/testhal/STM32/I2C/tmp75.c b/testhal/STM32/I2C/tmp75.c
index 6276e7c8e..72e634527 100644
--- a/testhal/STM32/I2C/tmp75.c
+++ b/testhal/STM32/I2C/tmp75.c
@@ -14,6 +14,7 @@
/* input buffer */
static i2cblock_t tmp75_rx_data[TMP75_RX_DEPTH];
+
/* temperature value */
static int16_t temperature = 0;
@@ -30,7 +31,6 @@ static void i2c_tmp75_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){
(void)*i2cp;
(void)*i2cscfg;
/* store temperature value */
- temperature = (tmp75_rx_data[0] << 8) + tmp75_rx_data[1];
}
/* Fill TMP75 config. */
@@ -43,12 +43,10 @@ static const I2CSlaveConfig tmp75 = {
/* 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, tmp75_addr, tmp75_rx_data, RXBYTES);
+ i2cMasterReceive(&I2CD2, &tmp75, tmp75_addr, tmp75_rx_data, 2);
i2cReleaseBus(&I2CD2);
+ temperature = (tmp75_rx_data[0] << 8) + tmp75_rx_data[1];
}