diff --git a/Makefile b/Makefile index dfbbf07..be32f54 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ CFLAGS+=-Ifxplib/include -DPOINTPOS=16 LDFLAGS+=-Lfxplib/lib/$(BUILD) -lfxp_stm32l0 # generic linking -LDFLAGS+=-Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group +LDFLAGS+=-Wl,--start-group -lc -lm -lgcc -lnosys -Wl,--end-group # build type specific flags CFLAGS_debug=-O0 -ggdb -DDEBUG diff --git a/src/main.c b/src/main.c index ebe55d9..4915387 100644 --- a/src/main.c +++ b/src/main.c @@ -17,10 +17,11 @@ static void clock_setup(void) { /* We are running on MSI (2.1 MHz) after boot. */ rcc_periph_clock_enable(RCC_GPIOA); // for basically everything - rcc_periph_clock_enable(RCC_GPIOC); // for UART only - /* Enable clocks for USART2. */ + /* Enable clocks for peripherals. */ rcc_periph_clock_enable(RCC_USART2); + rcc_periph_clock_enable(RCC_ADC1); + rcc_periph_clock_enable(RCC_TIM21); } /* Set up systick to fire freq times per second */ @@ -59,7 +60,8 @@ int main(void) fan_ctrl_pwm_enable(); // TODO: make DC/PWM configurable - // triggered every 1 ms + uint8_t last_duty = 0; + while (1) { if(systick_triggered) { systick_triggered = false; @@ -77,7 +79,17 @@ int main(void) uint8_t duty = fan_controller_update(temperature); + // handle fan power-on and power-off + if(last_duty == 0 && duty != 0) { + fan_ctrl_pwm_enable(); + } else if(last_duty != 0 && duty == 0) { + fan_ctrl_pwm_disable(); + } + + // set the updated duty cycle fan_ctrl_pwm_set_duty(duty); + + last_duty = duty; } __WFI();