onewire_master: port to STM32F4

This commit is contained in:
King Kévin 2020-12-11 20:53:58 +01:00
parent 1cbe029139
commit 5425e861e8
2 changed files with 6 additions and 6 deletions

View File

@ -165,7 +165,8 @@ void onewire_master_setup(void)
// setup GPIO with external interrupt
rcc_periph_clock_enable(GPIO_RCC(ONEWIRE_MASTER_PIN)); // enable clock for GPIO peripheral
gpio_set(GPIO_PORT(ONEWIRE_MASTER_PIN), GPIO_PIN(ONEWIRE_MASTER_PIN)); // idle is high (using pull-up resistor)
gpio_set_mode(GPIO_PORT(ONEWIRE_MASTER_PIN), GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO_PIN(ONEWIRE_MASTER_PIN)); // normal 1-Wire communication (only using external pull-up resistor)
gpio_mode_setup(GPIO_PORT(ONEWIRE_MASTER_PIN), GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN(ONEWIRE_MASTER_PIN)); // set pin as output, and expect external pull-up resistor
gpio_set_output_options(GPIO_PORT(ONEWIRE_MASTER_PIN), GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, GPIO_PIN(ONEWIRE_MASTER_PIN)); // set pin output as open-drain for normal 1-Wire communication (no parasite power)
// setup timer to generate/measure signal timing
rcc_periph_clock_enable(RCC_TIM(ONEWIRE_MASTER_TIMER)); // enable clock for timer peripheral
@ -205,7 +206,7 @@ void onewire_master_release(void)
rcc_periph_clock_disable(RCC_TIM(ONEWIRE_MASTER_TIMER)); // disable clock for timer peripheral
// release GPIO
gpio_set_mode(GPIO_PORT(ONEWIRE_MASTER_PIN), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO_PIN(ONEWIRE_MASTER_PIN)); // put back to input floating
gpio_mode_setup(GPIO_PORT(ONEWIRE_MASTER_PIN), GPIO_MODE_INPUT, GPIO_PUPD_NONE, GPIO_PIN(ONEWIRE_MASTER_PIN)); // put back to input floating
// disable timer ISR
#if defined(ONEWIRE_MASTER_TIMER_USE_INTERRUPT_TABLE) && ONEWIRE_MASTER_TIMER_USE_INTERRUPT_TABLE
@ -228,7 +229,7 @@ bool onewire_master_reset(void)
slave_presence = false; // reset state
onewire_master_state = ONEWIRE_STATE_MASTER_RESET; // set new state
gpio_set_mode(GPIO_PORT(ONEWIRE_MASTER_PIN), GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO_PIN(ONEWIRE_MASTER_PIN)); // normal 1-Wire communication (only using external pull-up resistor)
gpio_set_output_options(GPIO_PORT(ONEWIRE_MASTER_PIN), GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, GPIO_PIN(ONEWIRE_MASTER_PIN)); // set pin output as open-drain for normal 1-Wire communication (no parasite power)
gpio_clear(GPIO_PORT(ONEWIRE_MASTER_PIN), GPIO_PIN(ONEWIRE_MASTER_PIN)); // pull signal low to start reset (it's not important if it was low in the first place since the reset pulse has no maximum time)
timer_enable_counter(TIM(ONEWIRE_MASTER_TIMER)); // start timer
@ -261,7 +262,7 @@ static bool onewire_master_write(void)
timer_enable_irq(TIM(ONEWIRE_MASTER_TIMER), TIM_DIER_CC3IE); // enable compare interrupt for end of time slow
// start writing
gpio_set_mode(GPIO_PORT(ONEWIRE_MASTER_PIN), GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO_PIN(ONEWIRE_MASTER_PIN)); // normal 1-Wire communication (only using external pull-up resistor)
gpio_set_output_options(GPIO_PORT(ONEWIRE_MASTER_PIN), GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, GPIO_PIN(ONEWIRE_MASTER_PIN)); // set pin output as open-drain for normal 1-Wire communication (no parasite power)
gpio_clear(GPIO_PORT(ONEWIRE_MASTER_PIN), GPIO_PIN(ONEWIRE_MASTER_PIN)); // pull signal low to start slot
timer_enable_counter(TIM(ONEWIRE_MASTER_TIMER)); // start timer
while (onewire_master_state != ONEWIRE_STATE_DONE && onewire_master_state != ONEWIRE_STATE_ERROR) { // wait until write procedure completed
@ -297,7 +298,7 @@ static bool onewire_master_read(void)
timer_enable_irq(TIM(ONEWIRE_MASTER_TIMER), TIM_DIER_CC3IE); // enable compare interrupt for end of time slow
// start reading
gpio_set_mode(GPIO_PORT(ONEWIRE_MASTER_PIN), GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, GPIO_PIN(ONEWIRE_MASTER_PIN)); // normal 1-Wire communication (only using external pull-up resistor)
gpio_set_output_options(GPIO_PORT(ONEWIRE_MASTER_PIN), GPIO_OTYPE_OD, GPIO_OSPEED_50MHZ, GPIO_PIN(ONEWIRE_MASTER_PIN)); // set pin output as open-drain for normal 1-Wire communication (no parasite power)
gpio_clear(GPIO_PORT(ONEWIRE_MASTER_PIN), GPIO_PIN(ONEWIRE_MASTER_PIN)); // pull signal low to start slot
timer_enable_counter(TIM(ONEWIRE_MASTER_TIMER)); // start timer
while (onewire_master_state != ONEWIRE_STATE_DONE && onewire_master_state != ONEWIRE_STATE_ERROR) { // wait until read procedure completed

View File

@ -7,7 +7,6 @@
* @note overdrive mode is not provided
*/
#pragma once
#error not converted for STM32F4
/** setup 1-wire peripheral
*/