Moved PWM handler to SysTick and created LED demo
This commit is contained in:
parent
9d08b7df59
commit
eedfcba0a5
@ -23,7 +23,7 @@
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid.1986434241" name="CpuId" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_cpuid" useByScannerDiscovery="false" value="0" valueType="string"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid.731481840" name="CpuCoreId" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_coreid" useByScannerDiscovery="false" value="0" valueType="string"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board.1992458385" name="Board" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.target_board" useByScannerDiscovery="false" value="genericBoard" valueType="string"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.1211256952" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.3 || Debug || true || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.toolchain.base.gnu-tools-for-stm32 || STM32L011F4Ux || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Core/Inc | ../Drivers/STM32L0xx_HAL_Driver/Inc | ../Drivers/STM32L0xx_HAL_Driver/Inc/Legacy | ../Drivers/CMSIS/Device/ST/STM32L0xx/Include | ../Drivers/CMSIS/Include || || || USE_HAL_DRIVER | STM32L011xx || || Drivers | Core/Startup | Core || || || ${workspace_loc:/${ProjName}/STM32L011F4UX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || " valueType="string"/>
|
||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults.1211256952" name="Defaults" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.option.defaults" useByScannerDiscovery="false" value="com.st.stm32cube.ide.common.services.build.inputs.revA.1.0.3 || Debug || true || Executable || com.st.stm32cube.ide.mcu.gnu.managedbuild.toolchain.base.gnu-tools-for-stm32 || STM32L011F4Ux || 0 || 0 || arm-none-eabi- || ${gnu_tools_for_stm32_compiler_path} || ../Drivers/CMSIS/Include | ../Core/Inc | ../Drivers/STM32L0xx_HAL_Driver/Inc | ../Drivers/CMSIS/Device/ST/STM32L0xx/Include | ../Drivers/STM32L0xx_HAL_Driver/Inc/Legacy || || || USE_HAL_DRIVER | STM32L011xx || || Drivers | Core/Startup | Core || || || ${workspace_loc:/${ProjName}/STM32L011F4UX_FLASH.ld} || true || NonSecure || || secure_nsclib.o || " valueType="string"/>
|
||||
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.ELF" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform.445833440" isAbstract="false" osList="all" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.targetplatform"/>
|
||||
<builder buildPath="${workspace_loc:/iaq_wired_sensor}/Debug" id="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder.1606920792" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="Gnu Make Builder" parallelBuildOn="true" parallelizationNumber="optimal" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.builder"/>
|
||||
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler.469616765" name="MCU GCC Assembler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.assembler">
|
||||
@ -168,4 +168,5 @@
|
||||
<autodiscovery enabled="false" problemReportingEnabled="true" selectedProfileId=""/>
|
||||
</scannerConfigBuildInfo>
|
||||
</storageModule>
|
||||
<storageModule moduleId="refreshScope"/>
|
||||
</cproject>
|
||||
|
@ -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=;
|
||||
|
||||
|
@ -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_ */
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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 */
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user