diff --git a/fw/Core/Src/led.c b/fw/Core/Src/led.c index 7914e04..0cc7f91 100644 --- a/fw/Core/Src/led.c +++ b/fw/Core/Src/led.c @@ -46,6 +46,22 @@ void led_set_color(uint8_t red, uint8_t green, uint8_t blue) led_blue_intensity = (int)blue * led_pwm_max / 255; } +void led_gpio_off(GPIO_TypeDef *port, uint32_t pin_mask) +{ + uint32_t port_value; + port_value = LL_GPIO_ReadInputPort(port); + port_value &= ~pin_mask; + LL_GPIO_WriteOutputPort(port, port_value); +} + +void led_gpio_on(GPIO_TypeDef *port, uint32_t pin_mask) +{ + uint32_t port_value; + port_value = LL_GPIO_ReadInputPort(port); + port_value |= pin_mask; + LL_GPIO_WriteOutputPort(port, port_value); +} + /* * led_off(): * Set LED intensity to 0 for each color @@ -123,4 +139,8 @@ void led_init(led_context_t *context, int pwm_freq, int pwm_handler_freq) // e.g. for 1 kHz handler freq and 25 Hz PWM freq, we only have // resolution of 40 steps for pwm led_pwm_max = pwm_handler_freq / pwm_freq; + // turn off all LEDs (inverted) + led_gpio_on(led_context->red_led_port, led_context->red_led_pin); + led_gpio_on(led_context->green_led_port, led_context->green_led_pin); + led_gpio_on(led_context->blue_led_port, led_context->blue_led_pin); } diff --git a/fw/Core/Src/main.c b/fw/Core/Src/main.c index 6007773..2b27a57 100644 --- a/fw/Core/Src/main.c +++ b/fw/Core/Src/main.c @@ -107,7 +107,7 @@ int main(void) led_context.green_led_pin = LED_G_Pin; led_context.blue_led_pin = LED_B_Pin; led_init(&led_context, 50, 1000); - led_set_color(80, 0, 0); + led_set_color(0, 20, 0); /* I2C context init (for SHT4x and SCD4x) */ i2c_context_t i2c_context; i2c_context.i2c = I2C1; @@ -120,7 +120,6 @@ int main(void) sht4x_measure(&T, &RH); while (1) { - led_pwm_handler(); // TODO temporary, should be placed in timer interrupt (SysTick) /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ } diff --git a/fw/Core/Src/sht4x.c b/fw/Core/Src/sht4x.c index 9f14b54..50521da 100644 --- a/fw/Core/Src/sht4x.c +++ b/fw/Core/Src/sht4x.c @@ -28,8 +28,7 @@ int sht4x_measure(int *temperature, int *relative_humidity) if (result != I2C_OK) { return SHT4X_ERROR; } - // busy delay (LL_mDelay uses SysTick which doesn't work at the moment) TODO - for (volatile int j = 0; j < 100000; j++); + LL_mDelay(100); // 10 ms should be enough // read out result = i2c_receive(SHT4X_I2C_ADDRESS, buffer, 6); if (result != I2C_OK) { diff --git a/fw/Core/Src/stm32l0xx_it.c b/fw/Core/Src/stm32l0xx_it.c index 9009e6d..063906f 100644 --- a/fw/Core/Src/stm32l0xx_it.c +++ b/fw/Core/Src/stm32l0xx_it.c @@ -131,7 +131,7 @@ void SysTick_Handler(void) /* USER CODE END SysTick_IRQn 0 */ /* USER CODE BEGIN SysTick_IRQn 1 */ -// led_pwm_handler(); + led_pwm_handler(); /* USER CODE END SysTick_IRQn 1 */ } diff --git a/fw/Drivers/STM32L0xx_HAL_Driver/Inc/stm32l0xx_ll_utils.h b/fw/Drivers/STM32L0xx_HAL_Driver/Inc/stm32l0xx_ll_utils.h index 129bd8b..e6861f0 100644 --- a/fw/Drivers/STM32L0xx_HAL_Driver/Inc/stm32l0xx_ll_utils.h +++ b/fw/Drivers/STM32L0xx_HAL_Driver/Inc/stm32l0xx_ll_utils.h @@ -223,6 +223,7 @@ __STATIC_INLINE void LL_InitTick(uint32_t HCLKFrequency, uint32_t Ticks) SysTick->LOAD = (uint32_t)((HCLKFrequency / Ticks) - 1UL); /* set reload register */ SysTick->VAL = 0UL; /* Load the SysTick Counter Value */ SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | + SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk; /* Enable the Systick Timer */ }