From c78c5431a4d93ad417ccba0e1eaee5b9ffc68ed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20J=C3=A4ger?= Date: Mon, 17 Aug 2020 20:12:25 +0200 Subject: [PATCH] Enable load short circuit comp for PWM 2420 LUS --- src/load_driver.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/load_driver.c b/src/load_driver.c index 0e8fa54..2e9c83f 100644 --- a/src/load_driver.c +++ b/src/load_driver.c @@ -34,9 +34,9 @@ static struct device *dev_usb; #include "hardware.h" #include "leds.h" -/* TODO: porting and testing of comparator copied from mbed */ +// short circuit detection comparator only present in PWM 2420 LUS board so far +#ifdef CONFIG_BOARD_PWM_2420_LUS -#if defined(PIN_I_LOAD_COMP) && PIN_LOAD_DIS == PB_2 static void lptim_init() { // Enable peripheral clock of GPIOB @@ -84,9 +84,6 @@ static void lptim_init() //LPTIM1->CR |= LPTIM_CR_CNTSTRT; //LPTIM1->CR |= LPTIM_CR_SNGSTRT; } -#endif - -#ifdef PIN_I_LOAD_COMP void ADC1_COMP_IRQHandler(void *args) { @@ -101,12 +98,8 @@ void ADC1_COMP_IRQHandler(void *args) EXTI->PR |= EXTI_PR_PIF22; } -#endif // PIN_I_LOAD_COMP - void short_circuit_comp_init() { -#if defined(PIN_I_LOAD_COMP) - // set GPIO pin to analog RCC->IOPENR |= RCC_IOPENR_GPIOBEN; GPIOB->MODER &= ~(GPIO_MODER_MODE4); @@ -146,9 +139,10 @@ void short_circuit_comp_init() // 1 = second-highest priority of STM32L0/F0 IRQ_CONNECT(ADC1_COMP_IRQn, 1, ADC1_COMP_IRQHandler, 0, 0); irq_enable(ADC1_COMP_IRQn); -#endif } +#endif + void load_out_set(bool status) { #if LED_EXISTS(load) @@ -159,7 +153,7 @@ void load_out_set(bool status) gpio_pin_configure(dev_load, DT_GPIO_PIN(LOAD_GPIO, gpios), DT_GPIO_FLAGS(LOAD_GPIO, gpios) | GPIO_OUTPUT_INACTIVE); if (status == true) { -#ifdef PIN_I_LOAD_COMP +#ifdef CONFIG_BOARD_PWM_2420_LUS lptim_init(); #else gpio_pin_set(dev_load, DT_GPIO_PIN(LOAD_GPIO, gpios), 1); @@ -254,7 +248,9 @@ void load_out_init() #endif // analog comparator to detect short circuits and trigger immediate load switch-off +#ifdef CONFIG_BOARD_PWM_2420_LUS short_circuit_comp_init(); +#endif #if DT_NODE_EXISTS(DT_CHILD(DT_PATH(outputs), charge_pump)) // enable charge pump for high-side switches (if existing)