diff options
Diffstat (limited to 'testhal/STM32/STM32F4xx/onewire/onewire_test.c')
-rw-r--r-- | testhal/STM32/STM32F4xx/onewire/onewire_test.c | 79 |
1 files changed, 46 insertions, 33 deletions
diff --git a/testhal/STM32/STM32F4xx/onewire/onewire_test.c b/testhal/STM32/STM32F4xx/onewire/onewire_test.c index 7d0de69..682ed71 100644 --- a/testhal/STM32/STM32F4xx/onewire/onewire_test.c +++ b/testhal/STM32/STM32F4xx/onewire/onewire_test.c @@ -24,35 +24,48 @@ ****************************************************************************** */ -#if defined(BOARD_ST_STM32F4_DISCOVERY) -#if ONEWIRE_USE_STRONG_PULLUP -#error "F4 Discovery board has not enough voltage for this feature" -#endif +#if defined(BOARD_ST_STM32F4_DISCOVERY) || \ + defined(BOARD_ST_STM32F0_DISCOVERY) || \ + defined(BOARD_ST_STM32F0308_DISCOVERY) + #if ONEWIRE_USE_STRONG_PULLUP + #error "This board has not enough voltage for this feature" + #endif #endif -#if defined(BOARD_ST_STM32F4_DISCOVERY) -#define GPIOB_ONEWIRE GPIOB_PIN8 -#define ONEWIRE_PAD_MODE_ACTIVE (PAL_MODE_ALTERNATE(2) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUDR_PULLUP) -#define search_led_off() (palClearPad(GPIOD, GPIOD_LED4)) -#define search_led_on() (palSetPad(GPIOD, GPIOD_LED4)) -#define ONEWIRE_MASTER_CHANNEL 2 -#define ONEWIRE_SAMPLE_CHANNEL 3 +#if defined(BOARD_ST_STM32F0308_DISCOVERY) + #define ONEWIRE_PORT GPIOB + #define ONEWIRE_PIN GPIOB_PIN0 + #define ONEWIRE_PAD_MODE_ACTIVE (PAL_MODE_ALTERNATE(1) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUDR_PULLUP) + #define search_led_off() (palClearPad(GPIOC, GPIOC_LED4)) + #define search_led_on() (palSetPad(GPIOC, GPIOC_LED4)) + #define ONEWIRE_MASTER_CHANNEL 2 + #define ONEWIRE_SAMPLE_CHANNEL 3 +#elif defined(BOARD_ST_STM32F4_DISCOVERY) + #define ONEWIRE_PORT GPIOB + #define ONEWIRE_PIN GPIOB_PIN0 + #define ONEWIRE_PAD_MODE_ACTIVE (PAL_MODE_ALTERNATE(2) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUDR_PULLUP) + #define search_led_off() (palClearPad(GPIOD, GPIOD_LED4)) + #define search_led_on() (palSetPad(GPIOD, GPIOD_LED4)) + #define ONEWIRE_MASTER_CHANNEL 2 + #define ONEWIRE_SAMPLE_CHANNEL 3 #elif defined(BOARD_OLIMEX_STM32_103STK) -#define GPIOB_ONEWIRE 8 -#define ONEWIRE_PAD_MODE_IDLE PAL_MODE_INPUT -#define ONEWIRE_PAD_MODE_ACTIVE PAL_MODE_STM32_ALTERNATE_OPENDRAIN -#define search_led_on() (palClearPad(GPIOC, GPIOC_LED)) -#define search_led_off() (palSetPad(GPIOC, GPIOC_LED)) -#define ONEWIRE_MASTER_CHANNEL 2 -#define ONEWIRE_SAMPLE_CHANNEL 3 + #define ONEWIRE_PORT GPIOB + #define ONEWIRE_PIN 0 + #define ONEWIRE_PAD_MODE_IDLE PAL_MODE_INPUT + #define ONEWIRE_PAD_MODE_ACTIVE PAL_MODE_STM32_ALTERNATE_OPENDRAIN + #define search_led_on() (palClearPad(GPIOC, GPIOC_LED)) + #define search_led_off() (palSetPad(GPIOC, GPIOC_LED)) + #define ONEWIRE_MASTER_CHANNEL 2 + #define ONEWIRE_SAMPLE_CHANNEL 3 #else -#define GPIOB_ONEWIRE GPIOB_TACHOMETER -#include "pads.h" -#define ONEWIRE_PAD_MODE_ACTIVE (PAL_MODE_ALTERNATE(2) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUDR_PULLUP) -#define search_led_on red_led_on -#define search_led_off red_led_off -#define ONEWIRE_MASTER_CHANNEL 2 -#define ONEWIRE_SAMPLE_CHANNEL 3 + #define ONEWIRE_PORT GPIOB + #define GPIOB_ONEWIRE GPIOB_TACHOMETER + #include "pads.h" + #define ONEWIRE_PAD_MODE_ACTIVE (PAL_MODE_ALTERNATE(2) | PAL_STM32_OTYPE_OPENDRAIN | PAL_STM32_PUDR_PULLUP) + #define search_led_on red_led_on + #define search_led_off red_led_off + #define ONEWIRE_MASTER_CHANNEL 2 + #define ONEWIRE_SAMPLE_CHANNEL 3 #endif /* @@ -82,17 +95,17 @@ static void strong_pullup_release(void); static uint8_t testbuf[12]; -static float temperature[3]; +static int32_t temperature[3]; /* * */ static const onewireConfig ow_cfg = { - &PWMD4, + &PWMD3, ONEWIRE_MASTER_CHANNEL, ONEWIRE_SAMPLE_CHANNEL, - GPIOB, - GPIOB_ONEWIRE, + ONEWIRE_PORT, + ONEWIRE_PIN, #if defined(STM32F1XX) ONEWIRE_PAD_MODE_IDLE, #endif @@ -140,11 +153,11 @@ static void strong_pullup_release(void) { */ void onewireTest(void) { - uint16_t tmp; + int16_t tmp; uint8_t rombuf[24]; size_t devices_on_bus = 0; size_t i = 0; - volatile bool presence; + bool presence; onewireObjectInit(&OWD1); onewireStart(&OWD1, &ow_cfg); @@ -209,11 +222,11 @@ void onewireTest(void) { osalDbgCheck(testbuf[8] == onewireCRC(testbuf, 8)); tmp = 0; tmp |= (testbuf[1] << 8) | testbuf[0]; - temperature[i] = tmp * 0.0625; + temperature[i] = (tmp * 625) / 10; } } else { - osalSysHalt(""); + osalSysHalt("No devices found"); } osalThreadSleep(1); /* enforce ChibiOS's stack overflow check */ } |