rtc_dcf77: minor, use newer GPIO definition
This commit is contained in:
parent
4b2e43a94b
commit
4a1470401c
|
@ -37,10 +37,8 @@
|
|||
/** @defgroup rtc_dcf77_gpio output to enable DCF module and input to capture DCF signal
|
||||
* @{
|
||||
*/
|
||||
#define RTC_DCF77_ENABLE_PORT A /**< GPIO port to enable the module */
|
||||
#define RTC_DCF77_ENABLE_PIN 2 /**< GPIO pinto enable the module */
|
||||
#define RTC_DCF77_SIGNAL_PORT A /**< GPIO port to capture the DCF signal */
|
||||
#define RTC_DCF77_SIGNAL_PIN 3 /**< GPIO pin to capture the DCF signal */
|
||||
#define RTC_DCF77_ENABLE_PIN PA2 /**< GPIO pinto enable the module */
|
||||
#define RTC_DCF77_SIGNAL_PIN PA3 /**< GPIO pin to capture the DCF signal */
|
||||
/** @} */
|
||||
|
||||
/** @defgroup rtc_dcf77_timer timer to sample DCF77 signal
|
||||
|
@ -80,13 +78,13 @@ static uint8_t rtc_dcf77_invalid = 0;
|
|||
void rtc_dcf77_setup(void)
|
||||
{
|
||||
// setup enable output
|
||||
rcc_periph_clock_enable(RCC_GPIO(RTC_DCF77_ENABLE_PORT)); // enable clock GPIO peripheral
|
||||
gpio_set_mode(GPIO(RTC_DCF77_ENABLE_PORT), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO(RTC_DCF77_ENABLE_PIN)); // set pin to output push-pull to be able to enable the module
|
||||
rcc_periph_clock_enable(GPIO_RCC(RTC_DCF77_ENABLE_PIN)); // enable clock GPIO peripheral
|
||||
gpio_set_mode(GPIO_PORT(RTC_DCF77_ENABLE_PIN), GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO_PIN(RTC_DCF77_ENABLE_PIN)); // set pin to output push-pull to be able to enable the module
|
||||
rtc_dcf77_off(); // disable module at start
|
||||
|
||||
// setup signal input
|
||||
rcc_periph_clock_enable(RCC_GPIO(RTC_DCF77_SIGNAL_PORT)); // enable clock for signal input peripheral
|
||||
gpio_set_mode(GPIO(RTC_DCF77_SIGNAL_PORT), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO(RTC_DCF77_SIGNAL_PIN)); // set signal pin to input
|
||||
rcc_periph_clock_enable(GPIO_RCC(RTC_DCF77_SIGNAL_PIN)); // enable clock for signal input peripheral
|
||||
gpio_set_mode(GPIO_PORT(RTC_DCF77_SIGNAL_PIN), GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, GPIO_PIN(RTC_DCF77_SIGNAL_PIN)); // set signal pin to input
|
||||
|
||||
// setup timer to sample signal at 1kHz
|
||||
rcc_periph_clock_enable(RCC_TIM(RTC_DCF77_TIMER)); // enable clock for timer peripheral
|
||||
|
@ -102,21 +100,21 @@ void rtc_dcf77_setup(void)
|
|||
|
||||
void rtc_dcf77_on(void)
|
||||
{
|
||||
if (!gpio_get(GPIO(RTC_DCF77_ENABLE_PORT), GPIO(RTC_DCF77_ENABLE_PIN))) { // receiver is already turned on
|
||||
if (!gpio_get(GPIO_PORT(RTC_DCF77_ENABLE_PIN), GPIO_PIN(RTC_DCF77_ENABLE_PIN))) { // receiver is already turned on
|
||||
return; // do nothing
|
||||
}
|
||||
rtc_dcf77_frame = 0; // reset frame
|
||||
rtc_dcf77_phase_locked = false; // reset phase lock
|
||||
rtc_dcf77_phase_max = INT16_MIN; // restart searching for phase
|
||||
rtc_dcf77_invalid = 0; // reset invalid count
|
||||
gpio_clear(GPIO(RTC_DCF77_ENABLE_PORT), GPIO(RTC_DCF77_ENABLE_PIN)); // enable module by pulling pin low
|
||||
gpio_clear(GPIO_PORT(RTC_DCF77_ENABLE_PIN), GPIO_PIN(RTC_DCF77_ENABLE_PIN)); // enable module by pulling pin low
|
||||
timer_set_counter(TIM(RTC_DCF77_TIMER), 0); // reset timer counter
|
||||
timer_enable_counter(TIM(RTC_DCF77_TIMER)); // start timer to sample signal
|
||||
}
|
||||
|
||||
void rtc_dcf77_off(void)
|
||||
{
|
||||
gpio_set(GPIO(RTC_DCF77_ENABLE_PORT), GPIO(RTC_DCF77_ENABLE_PIN)); // disable module by pull pin high
|
||||
gpio_set(GPIO_PORT(RTC_DCF77_ENABLE_PIN), GPIO_PIN(RTC_DCF77_ENABLE_PIN)); // disable module by pull pin high
|
||||
timer_disable_counter(TIM(RTC_DCF77_TIMER)); // stop timer since we don't need to sample anymore
|
||||
}
|
||||
|
||||
|
@ -236,7 +234,7 @@ void TIM_ISR(RTC_DCF77_TIMER)(void)
|
|||
if (timer_get_flag(TIM(RTC_DCF77_TIMER), TIM_SR_UIF)) { // overflow update event happened
|
||||
timer_clear_flag(TIM(RTC_DCF77_TIMER), TIM_SR_UIF); // clear flag
|
||||
// fill bin with current sample state
|
||||
if (gpio_get(GPIO(RTC_DCF77_SIGNAL_PORT), GPIO(RTC_DCF77_SIGNAL_PIN))) {
|
||||
if (gpio_get(GPIO_PORT(RTC_DCF77_SIGNAL_PIN), GPIO_PIN(RTC_DCF77_SIGNAL_PIN))) {
|
||||
rtc_dcf77_bins[bin_i]++; // only need to increase if the signal is high
|
||||
}
|
||||
bin_state++; // remember we filled the bin
|
||||
|
|
Loading…
Reference in New Issue