diff --git a/fw/.cproject b/fw/.cproject
index d0b83b4..8fd8e0b 100644
--- a/fw/.cproject
+++ b/fw/.cproject
@@ -23,7 +23,7 @@
-
+
@@ -168,4 +168,5 @@
+
diff --git a/fw/.mxproject b/fw/.mxproject
index 7c0e167..4092066 100644
--- a/fw/.mxproject
+++ b/fw/.mxproject
@@ -9,17 +9,17 @@ CDefines=USE_HAL_DRIVER;STM32L011xx;USE_HAL_DRIVER;USE_HAL_DRIVER;
[PreviousGenFiles]
AdvancedFolderStructure=true
HeaderFileListSize=3
-HeaderFiles#0=/home/user/STM32CubeIDE/workspace_1.5.0/iaq_wired_sensor/Core/Inc/stm32l0xx_it.h
-HeaderFiles#1=/home/user/STM32CubeIDE/workspace_1.5.0/iaq_wired_sensor/Core/Inc/stm32l0xx_hal_conf.h
-HeaderFiles#2=/home/user/STM32CubeIDE/workspace_1.5.0/iaq_wired_sensor/Core/Inc/main.h
+HeaderFiles#0=/home/user/HDIoT/iaq_wired_sensor/fw/Core/Inc/stm32l0xx_it.h
+HeaderFiles#1=/home/user/HDIoT/iaq_wired_sensor/fw/Core/Inc/stm32l0xx_hal_conf.h
+HeaderFiles#2=/home/user/HDIoT/iaq_wired_sensor/fw/Core/Inc/main.h
HeaderFolderListSize=1
-HeaderPath#0=/home/user/STM32CubeIDE/workspace_1.5.0/iaq_wired_sensor/Core/Inc
+HeaderPath#0=/home/user/HDIoT/iaq_wired_sensor/fw/Core/Inc
HeaderFiles=;
SourceFileListSize=3
-SourceFiles#0=/home/user/STM32CubeIDE/workspace_1.5.0/iaq_wired_sensor/Core/Src/stm32l0xx_it.c
-SourceFiles#1=/home/user/STM32CubeIDE/workspace_1.5.0/iaq_wired_sensor/Core/Src/stm32l0xx_hal_msp.c
-SourceFiles#2=/home/user/STM32CubeIDE/workspace_1.5.0/iaq_wired_sensor/Core/Src/main.c
+SourceFiles#0=/home/user/HDIoT/iaq_wired_sensor/fw/Core/Src/stm32l0xx_it.c
+SourceFiles#1=/home/user/HDIoT/iaq_wired_sensor/fw/Core/Src/stm32l0xx_hal_msp.c
+SourceFiles#2=/home/user/HDIoT/iaq_wired_sensor/fw/Core/Src/main.c
SourceFolderListSize=1
-SourcePath#0=/home/user/STM32CubeIDE/workspace_1.5.0/iaq_wired_sensor/Core/Src
+SourcePath#0=/home/user/HDIoT/iaq_wired_sensor/fw/Core/Src
SourceFiles=;
diff --git a/fw/Core/Inc/led.h b/fw/Core/Inc/led.h
index 7031759..08a95ee 100644
--- a/fw/Core/Inc/led.h
+++ b/fw/Core/Inc/led.h
@@ -39,14 +39,9 @@ extern int led_blue_intensity;
* Function prototypes
*/
-void led_test();
void led_set_color(float red, float green, float blue);
-// led_off(): turn off all LEDs
void led_off();
-// led_pwm_handler(): handles switching LEDs on/off according to desired intensity;
-// should be regularly called in timer routine, preferably in SysTick_Handler()
void led_pwm_handler();
void led_init(led_context_t *context, int pwm_freq, int pwm_handler_freq);
-void led_test(int r, int g, int b);
#endif /* INC_LED_H_ */
diff --git a/fw/Core/Src/led.c b/fw/Core/Src/led.c
index 96a35d0..2ca35fc 100644
--- a/fw/Core/Src/led.c
+++ b/fw/Core/Src/led.c
@@ -19,7 +19,7 @@ int led_blue_intensity;
int led_red_state;
int led_green_state;
int led_blue_state;
-led_context_t *led_context;
+led_context_t *led_context = NULL;
/*
* Functions
@@ -60,6 +60,12 @@ void led_pwm_handler()
{
int new_red_state, new_green_state, new_blue_state;
+ if (led_context == NULL) {
+ // led_pwm_handler() may be called before led_init() was called;
+ // this would result in a crash
+ return;
+ }
+
new_red_state = led_pwm_counter >= led_red_intensity ? 1 : 0;
new_green_state = led_pwm_counter >= led_green_intensity ? 1 : 0;
new_blue_state = led_pwm_counter >= led_blue_intensity ? 1 : 0;
@@ -76,7 +82,7 @@ void led_pwm_handler()
HAL_GPIO_WritePin(led_context->blue_led_port, led_context->blue_led_pin, new_blue_state);
led_blue_state = new_blue_state;
}
- if (++led_pwm_counter > led_pwm_max) {
+ if (++led_pwm_counter >= led_pwm_max) {
led_pwm_counter = 0;
}
}
@@ -112,10 +118,3 @@ void led_init(led_context_t *context, int pwm_freq, int pwm_handler_freq)
// resolution of 40 steps for pwm
led_pwm_max = pwm_handler_freq / pwm_freq;
}
-
-void led_test(int r, int g, int b)
-{
- HAL_GPIO_WritePin(led_context->red_led_port, led_context->red_led_pin, r);
- HAL_GPIO_WritePin(led_context->green_led_port, led_context->green_led_pin, g);
- HAL_GPIO_WritePin(led_context->blue_led_port, led_context->blue_led_pin, b);
-}
diff --git a/fw/Core/Src/main.c b/fw/Core/Src/main.c
index 656fd92..328294b 100644
--- a/fw/Core/Src/main.c
+++ b/fw/Core/Src/main.c
@@ -101,24 +101,24 @@ int main(void)
led_context.green_led_pin = LED_G_Pin;
led_context.blue_led_port = LED_B_GPIO_Port;
led_context.blue_led_pin = LED_B_Pin;
- led_init(&led_context, 25, 1000);
+ // TODO tady je neco spatne, jako by SysTick nemel 1 kHz?
+ // TODO premerit osciloskopem frekvenci spinani led
+ led_init(&led_context, 50, 1000);
/* Turn off all LEDs */
led_off();
- led_set_color(0.1, 0.0, 0.0);
-// led_test(0,0,0);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
+ // LED PWM test
int counter = 0;
float R = 0.0, G = 0.0, B = 0.0;
while (1)
{
- led_pwm_handler();
if (counter % 1000 == 0) {
- R += 0.05;
- G += 0.01;
- B += 0.02;
+ R += 0.035;
+ G += 0.015;
+ B += 0.005;
if (R > 1.0) R = 0;
if (G > 1.0) G = 0;
if (B > 1.0) B = 0;
diff --git a/fw/Core/Src/stm32l0xx_it.c b/fw/Core/Src/stm32l0xx_it.c
index 33758c5..5158a87 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 */
HAL_IncTick();
/* USER CODE BEGIN SysTick_IRQn 1 */
-// led_pwm_handler();
+ led_pwm_handler();
/* USER CODE END SysTick_IRQn 1 */
}
diff --git a/fw/iaq_wired_sensor.ioc b/fw/iaq_wired_sensor.ioc
index 2de9f4b..310fb6c 100644
--- a/fw/iaq_wired_sensor.ioc
+++ b/fw/iaq_wired_sensor.ioc
@@ -89,7 +89,7 @@ ProjectManager.StackSize=0x400
ProjectManager.TargetToolchain=STM32CubeIDE
ProjectManager.ToolChainLocation=
ProjectManager.UnderRoot=true
-ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false
+ProjectManager.functionlistsort=1-MX_GPIO_Init-GPIO-false-HAL-true,2-SystemClock_Config-RCC-false-HAL-false,3-MX_I2C1_Init-I2C1-false-HAL-true,4-MX_LPUART1_UART_Init-LPUART1-false-HAL-true,5-MX_LPTIM1_Init-LPTIM1-false-HAL-true
RCC.AHBFreq_Value=2097000
RCC.APB1Freq_Value=2097000
RCC.APB1TimFreq_Value=2097000