diff --git a/testhal/STM32F1xx/I2C/Makefile b/testhal/STM32F1xx/I2C/Makefile index dc2441200..f40f6f775 100644 --- a/testhal/STM32F1xx/I2C/Makefile +++ b/testhal/STM32F1xx/I2C/Makefile @@ -82,8 +82,6 @@ CSRC = $(PORTSRC) \ $(CHIBIOS)/os/various/syscalls.c \ main.c \ i2c_pns.c \ - tmp75.c\ - max1236.c\ lis3.c\ @@ -127,7 +125,6 @@ INCDIR = $(PORTINC) $(KERNINC) $(TESTINC) \ # Compiler settings # -# -lm �������� ������ �����, ������ ��� ������ ������ MCU = cortex-m3 #TRGT = arm-elf- diff --git a/testhal/STM32F1xx/I2C/halconf.h b/testhal/STM32F1xx/I2C/halconf.h index 31d581932..3960a927c 100644 --- a/testhal/STM32F1xx/I2C/halconf.h +++ b/testhal/STM32F1xx/I2C/halconf.h @@ -192,7 +192,7 @@ * @note Disabling this option saves both code and data space. */ #if !defined(I2C_USE_WAIT) || defined(__DOXYGEN__) -#define I2C_USE_WAIT FALSE +#define I2C_USE_WAIT TRUE #endif /** @@ -202,13 +202,6 @@ #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/STM32F1xx/I2C/i2c_pns.c b/testhal/STM32F1xx/I2C/i2c_pns.c index 44f4a8a33..fac6dc965 100644 --- a/testhal/STM32F1xx/I2C/i2c_pns.c +++ b/testhal/STM32F1xx/I2C/i2c_pns.c @@ -4,29 +4,12 @@ #include "i2c_pns.h" #include "lis3.h" -#include "tmp75.h" -#include "max1236.h" /* I2C1 */ static const I2CConfig i2cfg1 = { OPMODE_I2C, 100000, STD_DUTY_CYCLE, - 0, - 0, - 0, - 0, -}; - -/* I2C2 */ -static const I2CConfig i2cfg2 = { - OPMODE_I2C, - 100000, - STD_DUTY_CYCLE, - 0, - 0, - 0, - 0, }; @@ -35,22 +18,14 @@ void I2CInit_pns(void){ i2cInit(); i2cStart(&I2CD1, &i2cfg1); - i2cStart(&I2CD2, &i2cfg2); /* tune ports for I2C1*/ palSetPadMode(IOPORT2, 6, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); palSetPadMode(IOPORT2, 7, PAL_MODE_STM32_ALTERNATE_OPENDRAIN); - /* tune ports for I2C2*/ - 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(1000); + chThdSleepMilliseconds(100); init_lis3(); - chThdSleepMilliseconds(1000); } diff --git a/testhal/STM32F1xx/I2C/lis3.c b/testhal/STM32F1xx/I2C/lis3.c index 401f56199..2300ea5cb 100644 --- a/testhal/STM32F1xx/I2C/lis3.c +++ b/testhal/STM32F1xx/I2C/lis3.c @@ -18,8 +18,8 @@ /* buffers */ -static i2cblock_t accel_rx_data[ACCEL_RX_DEPTH]; -static i2cblock_t accel_tx_data[ACCEL_TX_DEPTH]; +static uint8_t accel_rx_data[ACCEL_RX_DEPTH]; +static uint8_t accel_tx_data[ACCEL_TX_DEPTH]; static int16_t acceleration_x = 0; static int16_t acceleration_y = 0; @@ -42,8 +42,8 @@ static void i2c_lis3_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){ /* Accelerometer lis3lv02dq config */ static const I2CSlaveConfig lis3 = { - i2c_lis3_cb, - i2c_lis3_error_cb, + i2c_lis3_cb, + i2c_lis3_error_cb, }; @@ -67,9 +67,9 @@ int init_lis3(void){ */ void request_acceleration_data(void){ accel_tx_data[0] = ACCEL_OUT_DATA | AUTO_INCREMENT_BIT; // register address - //i2cAcquireBus(&I2CD1); + i2cAcquireBus(&I2CD1); i2cMasterTransmit(&I2CD1, &lis3, lis3_addr, accel_tx_data, 1, accel_rx_data, 6); - //i2cReleaseBus(&I2CD1); + i2cReleaseBus(&I2CD1); acceleration_x = accel_rx_data[0] + (accel_rx_data[1] << 8); acceleration_y = accel_rx_data[2] + (accel_rx_data[3] << 8); diff --git a/testhal/STM32F1xx/I2C/main.c b/testhal/STM32F1xx/I2C/main.c index b828953c5..bc241e180 100644 --- a/testhal/STM32F1xx/I2C/main.c +++ b/testhal/STM32F1xx/I2C/main.c @@ -17,14 +17,10 @@ * amount of time. */ -#include - #include "ch.h" #include "hal.h" #include "i2c_pns.h" -#include "tmp75.h" -#include "max1236.h" #include "lis3.h" @@ -44,39 +40,9 @@ static msg_t Blink(void *arg) { return 0; } - - -/* Temperature polling thread */ -static WORKING_AREA(PollTmp75ThreadWA, 128); -static msg_t PollTmp75Thread(void *arg) { - (void)arg; - systime_t time = chTimeNow(); - - while (TRUE) { - time += MS2ST(1001); - /* Call reading function */ - request_temperature(); - chThdSleepUntil(time); - } - return 0; -} - -/* MAX1236 polling thread */ -static WORKING_AREA(PollMax1236ThreadWA, 128); -static msg_t PollMax1236Thread(void *arg) { - (void)arg; - systime_t time = chTimeNow(); - - while (TRUE) { - time += MS2ST(200); - /* Call reading function */ - read_max1236(); - chThdSleepUntil(time); - } - return 0; -} - - +/* + * Accelerometer thread + */ static WORKING_AREA(PollAccelThreadWA, 128); static msg_t PollAccelThread(void *arg) { (void)arg; @@ -104,22 +70,6 @@ int main(void) { I2CInit_pns(); - /* Create temperature thread */ - chThdCreateStatic(PollTmp75ThreadWA, - sizeof(PollTmp75ThreadWA), - NORMALPRIO, - PollTmp75Thread, - NULL); - - - /* Create max1236 thread */ - chThdCreateStatic(PollMax1236ThreadWA, - sizeof(PollMax1236ThreadWA), - NORMALPRIO, - PollMax1236Thread, - NULL); - - /* Create accelerometer thread */ chThdCreateStatic(PollAccelThreadWA, sizeof(PollAccelThreadWA), diff --git a/testhal/STM32F1xx/I2C/max1236.c b/testhal/STM32F1xx/I2C/max1236.c deleted file mode 100644 index 09e2c8b35..000000000 --- a/testhal/STM32F1xx/I2C/max1236.c +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Maxim ADC has not so suitable default settings after startup. - * So we will create init function to tune this ADC. - */ - -#include - -#include "ch.h" -#include "hal.h" - -#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]; -/* ADC results */ -static uint16_t ch1 = 0, ch2 = 0, ch3 = 0, ch4 = 0; - - -/* Error trap */ -static void i2c_max1236_error_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){ - (void)i2cscfg; - int status = 0; - status = i2cp->id_i2c->SR1; - while(TRUE); -} - - -/* This callback raise up when transfer finished */ -static void i2c_max1236_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){ - (void)*i2cp; - (void)*i2cscfg; - /* get ADC data */ -} - - -/* ADC maxim MAX1236 config */ - -static const I2CSlaveConfig max1236 = { - i2c_max1236_cb, - i2c_max1236_error_cb, -}; - - -/** - * Initilization routine. See datasheet on page 13 to understand - * how to initialize ADC. - */ -void init_max1236(void){ - /* this data we must send via IC to setup ADC */ - 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, 2, max1236_rx_data, 0); - i2cReleaseBus(&I2CD2); -} - - -/* Now simply read 8 bytes to get all 4 ADC channels */ -void read_max1236(void){ - i2cAcquireBus(&I2CD2); - i2cMasterReceive(&I2CD2, &max1236, max1236_addr, max1236_rx_data, 8); - i2cReleaseBus(&I2CD2); - - 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/STM32F1xx/I2C/max1236.h b/testhal/STM32F1xx/I2C/max1236.h deleted file mode 100644 index aff466cf4..000000000 --- a/testhal/STM32F1xx/I2C/max1236.h +++ /dev/null @@ -1,14 +0,0 @@ -#include "ch.h" - -#ifndef MAX1236_H_ -#define MAX1236_H_ - - -#define MAX1236_RX_DEPTH 8 -#define MAX1236_TX_DEPTH 2 - - -void init_max1236(void); -void read_max1236(void); - -#endif /* MAX1236_H_ */ diff --git a/testhal/STM32F1xx/I2C/mcuconf.h b/testhal/STM32F1xx/I2C/mcuconf.h index 6afc97f28..b333e2ce6 100644 --- a/testhal/STM32F1xx/I2C/mcuconf.h +++ b/testhal/STM32F1xx/I2C/mcuconf.h @@ -174,13 +174,6 @@ #define STM32_I2C_I2C2_DMA_PRIORITY 4 #define STM32_I2C_I2C1_DMA_ERROR_HOOK() chSysHalt() #define STM32_I2C_I2C2_DMA_ERROR_HOOK() chSysHalt() -/* I2C1 */ -#define STM32_I2C_I2C1_USE_GPT_TIM GPTD1 -#define STM32_I2C_I2C1_USE_POLLING_WAIT TRUE -/* I2C2 */ -#define STM32_I2C_I2C2_USE_GPT_TIM GPTD2 -#define STM32_I2C_I2C2_USE_POLLING_WAIT TRUE - /* * USB driver system settings. diff --git a/testhal/STM32F1xx/I2C/tmp75.c b/testhal/STM32F1xx/I2C/tmp75.c deleted file mode 100644 index 72e634527..000000000 --- a/testhal/STM32F1xx/I2C/tmp75.c +++ /dev/null @@ -1,52 +0,0 @@ -/** - * TMP75 is most simple I2C device in our case. It is already useful with - * default settings after powerup. - * You only must read 2 sequential bytes from it. - */ - -#include - -#include "ch.h" -#include "hal.h" - -#include "tmp75.h" - - -/* input buffer */ -static i2cblock_t tmp75_rx_data[TMP75_RX_DEPTH]; - -/* temperature value */ -static int16_t temperature = 0; - -/* Simple error trap */ -static void i2c_tmp75_error_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){ - (void)i2cscfg; - int status = 0; - status = i2cp->id_i2c->SR1; - while(TRUE); -} - -/* This callback raise up when transfer finished */ -static void i2c_tmp75_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){ - (void)*i2cp; - (void)*i2cscfg; - /* store temperature value */ -} - -/* Fill TMP75 config. */ -static const I2CSlaveConfig tmp75 = { - i2c_tmp75_cb, - i2c_tmp75_error_cb, -}; - -#define tmp75_addr 0b1001000 - -/* This is main function. */ -void request_temperature(void){ - i2cAcquireBus(&I2CD2); - i2cMasterReceive(&I2CD2, &tmp75, tmp75_addr, tmp75_rx_data, 2); - i2cReleaseBus(&I2CD2); - temperature = (tmp75_rx_data[0] << 8) + tmp75_rx_data[1]; -} - - diff --git a/testhal/STM32F1xx/I2C/tmp75.h b/testhal/STM32F1xx/I2C/tmp75.h deleted file mode 100644 index ab4b5fa9b..000000000 --- a/testhal/STM32F1xx/I2C/tmp75.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef TMP75_H_ -#define TMP75_H_ - - - -/* buffers depth */ -#define TMP75_RX_DEPTH 2 -#define TMP75_TX_DEPTH 2 - -void init_tmp75(void); -void request_temperature(void); - -#endif /* TMP75_H_ */