Enabled SysTick interrupt, fixed LED toggle bug
This commit is contained in:
parent
7e48b82c9d
commit
a3bfe95c57
@ -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;
|
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():
|
* led_off():
|
||||||
* Set LED intensity to 0 for each color
|
* 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
|
// e.g. for 1 kHz handler freq and 25 Hz PWM freq, we only have
|
||||||
// resolution of 40 steps for pwm
|
// resolution of 40 steps for pwm
|
||||||
led_pwm_max = pwm_handler_freq / pwm_freq;
|
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);
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ int main(void)
|
|||||||
led_context.green_led_pin = LED_G_Pin;
|
led_context.green_led_pin = LED_G_Pin;
|
||||||
led_context.blue_led_pin = LED_B_Pin;
|
led_context.blue_led_pin = LED_B_Pin;
|
||||||
led_init(&led_context, 50, 1000);
|
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 init (for SHT4x and SCD4x) */
|
||||||
i2c_context_t i2c_context;
|
i2c_context_t i2c_context;
|
||||||
i2c_context.i2c = I2C1;
|
i2c_context.i2c = I2C1;
|
||||||
@ -120,7 +120,6 @@ int main(void)
|
|||||||
sht4x_measure(&T, &RH);
|
sht4x_measure(&T, &RH);
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
led_pwm_handler(); // TODO temporary, should be placed in timer interrupt (SysTick)
|
|
||||||
/* USER CODE END WHILE */
|
/* USER CODE END WHILE */
|
||||||
/* USER CODE BEGIN 3 */
|
/* USER CODE BEGIN 3 */
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,7 @@ int sht4x_measure(int *temperature, int *relative_humidity)
|
|||||||
if (result != I2C_OK) {
|
if (result != I2C_OK) {
|
||||||
return SHT4X_ERROR;
|
return SHT4X_ERROR;
|
||||||
}
|
}
|
||||||
// busy delay (LL_mDelay uses SysTick which doesn't work at the moment) TODO
|
LL_mDelay(100); // 10 ms should be enough
|
||||||
for (volatile int j = 0; j < 100000; j++);
|
|
||||||
// read out
|
// read out
|
||||||
result = i2c_receive(SHT4X_I2C_ADDRESS, buffer, 6);
|
result = i2c_receive(SHT4X_I2C_ADDRESS, buffer, 6);
|
||||||
if (result != I2C_OK) {
|
if (result != I2C_OK) {
|
||||||
|
@ -131,7 +131,7 @@ void SysTick_Handler(void)
|
|||||||
/* USER CODE END SysTick_IRQn 0 */
|
/* USER CODE END SysTick_IRQn 0 */
|
||||||
|
|
||||||
/* USER CODE BEGIN SysTick_IRQn 1 */
|
/* USER CODE BEGIN SysTick_IRQn 1 */
|
||||||
// led_pwm_handler();
|
led_pwm_handler();
|
||||||
/* USER CODE END SysTick_IRQn 1 */
|
/* USER CODE END SysTick_IRQn 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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->LOAD = (uint32_t)((HCLKFrequency / Ticks) - 1UL); /* set reload register */
|
||||||
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
|
SysTick->VAL = 0UL; /* Load the SysTick Counter Value */
|
||||||
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk |
|
||||||
|
SysTick_CTRL_TICKINT_Msk |
|
||||||
SysTick_CTRL_ENABLE_Msk; /* Enable the Systick Timer */
|
SysTick_CTRL_ENABLE_Msk; /* Enable the Systick Timer */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user