From b4dd5c789ca0e1d9f05ccf626b6e2a72b0ce2839 Mon Sep 17 00:00:00 2001 From: bartool Date: Sun, 30 Apr 2023 07:27:59 +0200 Subject: [PATCH] [wip] working on display graph --- firmware/.vscode/settings.json | 3 +- .../func_gen_stm32f303re_nucleo/.mxproject | 26 +-- .../Core/Inc/stm32f3xx_hal_conf.h | 2 +- .../Core/Inc/tim.h | 55 +++++ .../Core/Src/main.c | 165 +++++++------- .../Core/Src/tim.c | 202 ++++++++++++++++++ firmware/func_gen_stm32f303re_nucleo/Makefile | 6 +- .../func_gen_stm32f303re_nucleo.ioc | 66 ++++-- firmware/shared_libs/bitmaps/bitmap_wave.c | 57 +++++ firmware/shared_libs/bitmaps/bitmap_wave.h | 13 ++ firmware/shared_libs/controllers/ctrl_app.c | 1 + .../shared_libs/controllers/ctrl_app_types.h | 10 +- .../shared_libs/disp_layout/disp_layout.c | 112 ++++++++-- firmware/shared_libs/display/display_gfx.c | 81 ++++++- firmware/shared_libs/display/display_gfx.h | 5 +- 15 files changed, 663 insertions(+), 141 deletions(-) create mode 100644 firmware/func_gen_stm32f303re_nucleo/Core/Inc/tim.h create mode 100644 firmware/func_gen_stm32f303re_nucleo/Core/Src/tim.c create mode 100644 firmware/shared_libs/bitmaps/bitmap_wave.c create mode 100644 firmware/shared_libs/bitmaps/bitmap_wave.h diff --git a/firmware/.vscode/settings.json b/firmware/.vscode/settings.json index c4e9d03..c36b291 100644 --- a/firmware/.vscode/settings.json +++ b/firmware/.vscode/settings.json @@ -13,6 +13,7 @@ "printf.h": "c", "disp_layout_template.h": "c", "disp_layout_types.h": "c", - "ctrl_app_types.h": "c" + "ctrl_app_types.h": "c", + "tim.h": "c" } } \ No newline at end of file diff --git a/firmware/func_gen_stm32f303re_nucleo/.mxproject b/firmware/func_gen_stm32f303re_nucleo/.mxproject index a6536c9..0debea6 100644 --- a/firmware/func_gen_stm32f303re_nucleo/.mxproject +++ b/firmware/func_gen_stm32f303re_nucleo/.mxproject @@ -1,32 +1,34 @@ [PreviousLibFiles] -LibFiles=Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_i2c.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_i2c.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_i2c_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_def.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_rcc.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_rcc_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_bus.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_rcc.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_crs.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_system.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_utils.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_gpio.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_gpio_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_gpio.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_dma_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_dma.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_dma.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_cortex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_cortex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_pwr.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_pwr_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_pwr.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_flash.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_flash_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_exti.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_exti.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_spi.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_spi_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_tim.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_tim_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_uart.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_usart.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_uart_ex.h;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_i2c.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_i2c_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_rcc.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_rcc_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_gpio.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_dma.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_cortex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_pwr.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_pwr_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_flash.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_flash_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_exti.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_spi.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_spi_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_tim.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_tim_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_uart.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_uart_ex.c;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_i2c.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_i2c.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_i2c_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_def.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_rcc.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_rcc_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_bus.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_rcc.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_crs.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_system.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_utils.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_gpio.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_gpio_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_gpio.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_dma_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_dma.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_dma.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_cortex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_cortex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_pwr.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_pwr_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_pwr.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_flash.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_flash_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_exti.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_exti.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_spi.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_spi_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_tim.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_tim_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_uart.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_usart.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_uart_ex.h;Drivers\CMSIS\Device\ST\STM32F3xx\Include\stm32f303xe.h;Drivers\CMSIS\Device\ST\STM32F3xx\Include\stm32f3xx.h;Drivers\CMSIS\Device\ST\STM32F3xx\Include\system_stm32f3xx.h;Drivers\CMSIS\Device\ST\STM32F3xx\Source\Templates\system_stm32f3xx.c;Drivers\CMSIS\Include\cmsis_armcc.h;Drivers\CMSIS\Include\cmsis_armclang.h;Drivers\CMSIS\Include\cmsis_compiler.h;Drivers\CMSIS\Include\cmsis_gcc.h;Drivers\CMSIS\Include\cmsis_iccarm.h;Drivers\CMSIS\Include\cmsis_version.h;Drivers\CMSIS\Include\core_armv8mbl.h;Drivers\CMSIS\Include\core_armv8mml.h;Drivers\CMSIS\Include\core_cm0.h;Drivers\CMSIS\Include\core_cm0plus.h;Drivers\CMSIS\Include\core_cm1.h;Drivers\CMSIS\Include\core_cm23.h;Drivers\CMSIS\Include\core_cm3.h;Drivers\CMSIS\Include\core_cm33.h;Drivers\CMSIS\Include\core_cm4.h;Drivers\CMSIS\Include\core_cm7.h;Drivers\CMSIS\Include\core_sc000.h;Drivers\CMSIS\Include\core_sc300.h;Drivers\CMSIS\Include\mpu_armv7.h;Drivers\CMSIS\Include\mpu_armv8.h;Drivers\CMSIS\Include\tz_context.h; +LibFiles=Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_i2c.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_i2c.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_i2c_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_def.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_rcc.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_rcc_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_bus.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_rcc.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_crs.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_system.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_utils.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_gpio.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_gpio_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_gpio.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_dma_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_dma.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_dma.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_cortex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_cortex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_pwr.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_pwr_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_pwr.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_flash.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_flash_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_exti.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_exti.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_spi.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_spi_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_tim.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_tim_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_tim.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_uart.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_usart.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_uart_ex.h;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_i2c.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_i2c_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_rcc.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_rcc_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_gpio.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_dma.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_cortex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_pwr.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_pwr_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_flash.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_flash_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_exti.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_spi.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_spi_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_tim.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_tim_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_uart.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_uart_ex.c;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_i2c.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_i2c.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_i2c_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\Legacy\stm32_hal_legacy.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_def.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_rcc.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_rcc_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_bus.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_rcc.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_crs.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_system.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_utils.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_gpio.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_gpio_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_gpio.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_dma_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_dma.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_dma.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_cortex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_cortex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_pwr.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_pwr_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_pwr.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_flash.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_flash_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_exti.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_exti.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_spi.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_spi_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_tim.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_tim_ex.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_tim.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_uart.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_ll_usart.h;Drivers\STM32F3xx_HAL_Driver\Inc\stm32f3xx_hal_uart_ex.h;Drivers\CMSIS\Device\ST\STM32F3xx\Include\stm32f303xe.h;Drivers\CMSIS\Device\ST\STM32F3xx\Include\stm32f3xx.h;Drivers\CMSIS\Device\ST\STM32F3xx\Include\system_stm32f3xx.h;Drivers\CMSIS\Device\ST\STM32F3xx\Source\Templates\system_stm32f3xx.c;Drivers\CMSIS\Include\cmsis_armcc.h;Drivers\CMSIS\Include\cmsis_armclang.h;Drivers\CMSIS\Include\cmsis_compiler.h;Drivers\CMSIS\Include\cmsis_gcc.h;Drivers\CMSIS\Include\cmsis_iccarm.h;Drivers\CMSIS\Include\cmsis_version.h;Drivers\CMSIS\Include\core_armv8mbl.h;Drivers\CMSIS\Include\core_armv8mml.h;Drivers\CMSIS\Include\core_cm0.h;Drivers\CMSIS\Include\core_cm0plus.h;Drivers\CMSIS\Include\core_cm1.h;Drivers\CMSIS\Include\core_cm23.h;Drivers\CMSIS\Include\core_cm3.h;Drivers\CMSIS\Include\core_cm33.h;Drivers\CMSIS\Include\core_cm4.h;Drivers\CMSIS\Include\core_cm7.h;Drivers\CMSIS\Include\core_sc000.h;Drivers\CMSIS\Include\core_sc300.h;Drivers\CMSIS\Include\mpu_armv7.h;Drivers\CMSIS\Include\mpu_armv8.h;Drivers\CMSIS\Include\tz_context.h; [PreviousUsedMakefileFiles] -SourceFiles=Core\Src\main.c;Core\Src\gpio.c;Core\Src\i2c.c;Core\Src\spi.c;Core\Src\usart.c;Core\Src\stm32f3xx_it.c;Core\Src\stm32f3xx_hal_msp.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_i2c.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_i2c_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_rcc.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_rcc_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_gpio.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_dma.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_cortex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_pwr.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_pwr_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_flash.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_flash_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_exti.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_spi.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_spi_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_tim.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_tim_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_uart.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_uart_ex.c;Drivers\CMSIS\Device\ST\STM32F3xx\Source\Templates\system_stm32f3xx.c;Core\Src\system_stm32f3xx.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_i2c.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_i2c_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_rcc.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_rcc_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_gpio.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_dma.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_cortex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_pwr.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_pwr_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_flash.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_flash_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_exti.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_spi.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_spi_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_tim.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_tim_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_uart.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_uart_ex.c;Drivers\CMSIS\Device\ST\STM32F3xx\Source\Templates\system_stm32f3xx.c;Core\Src\system_stm32f3xx.c;;; +SourceFiles=Core\Src\main.c;Core\Src\gpio.c;Core\Src\i2c.c;Core\Src\spi.c;Core\Src\tim.c;Core\Src\usart.c;Core\Src\stm32f3xx_it.c;Core\Src\stm32f3xx_hal_msp.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_i2c.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_i2c_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_rcc.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_rcc_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_gpio.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_dma.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_cortex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_pwr.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_pwr_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_flash.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_flash_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_exti.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_spi.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_spi_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_tim.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_tim_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_uart.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_uart_ex.c;Drivers\CMSIS\Device\ST\STM32F3xx\Source\Templates\system_stm32f3xx.c;Core\Src\system_stm32f3xx.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_i2c.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_i2c_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_rcc.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_rcc_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_gpio.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_dma.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_cortex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_pwr.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_pwr_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_flash.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_flash_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_exti.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_spi.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_spi_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_tim.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_tim_ex.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_uart.c;Drivers\STM32F3xx_HAL_Driver\Src\stm32f3xx_hal_uart_ex.c;Drivers\CMSIS\Device\ST\STM32F3xx\Source\Templates\system_stm32f3xx.c;Core\Src\system_stm32f3xx.c;;; HeaderPath=Drivers\STM32F3xx_HAL_Driver\Inc;Drivers\STM32F3xx_HAL_Driver\Inc\Legacy;Drivers\CMSIS\Device\ST\STM32F3xx\Include;Drivers\CMSIS\Include;Core\Inc; CDefines=USE_HAL_DRIVER;STM32F303xE;USE_HAL_DRIVER;USE_HAL_DRIVER; [PreviousGenFiles] AdvancedFolderStructure=true -HeaderFileListSize=7 +HeaderFileListSize=8 HeaderFiles#0=..\Core\Inc\gpio.h HeaderFiles#1=..\Core\Inc\i2c.h HeaderFiles#2=..\Core\Inc\spi.h -HeaderFiles#3=..\Core\Inc\usart.h -HeaderFiles#4=..\Core\Inc\stm32f3xx_it.h -HeaderFiles#5=..\Core\Inc\stm32f3xx_hal_conf.h -HeaderFiles#6=..\Core\Inc\main.h +HeaderFiles#3=..\Core\Inc\tim.h +HeaderFiles#4=..\Core\Inc\usart.h +HeaderFiles#5=..\Core\Inc\stm32f3xx_it.h +HeaderFiles#6=..\Core\Inc\stm32f3xx_hal_conf.h +HeaderFiles#7=..\Core\Inc\main.h HeaderFolderListSize=1 HeaderPath#0=..\Core\Inc HeaderFiles=; -SourceFileListSize=7 +SourceFileListSize=8 SourceFiles#0=..\Core\Src\gpio.c SourceFiles#1=..\Core\Src\i2c.c SourceFiles#2=..\Core\Src\spi.c -SourceFiles#3=..\Core\Src\usart.c -SourceFiles#4=..\Core\Src\stm32f3xx_it.c -SourceFiles#5=..\Core\Src\stm32f3xx_hal_msp.c -SourceFiles#6=..\Core\Src\main.c +SourceFiles#3=..\Core\Src\tim.c +SourceFiles#4=..\Core\Src\usart.c +SourceFiles#5=..\Core\Src\stm32f3xx_it.c +SourceFiles#6=..\Core\Src\stm32f3xx_hal_msp.c +SourceFiles#7=..\Core\Src\main.c SourceFolderListSize=1 SourcePath#0=..\Core\Src SourceFiles=; diff --git a/firmware/func_gen_stm32f303re_nucleo/Core/Inc/stm32f3xx_hal_conf.h b/firmware/func_gen_stm32f303re_nucleo/Core/Inc/stm32f3xx_hal_conf.h index 157f7a7..54801f0 100644 --- a/firmware/func_gen_stm32f303re_nucleo/Core/Inc/stm32f3xx_hal_conf.h +++ b/firmware/func_gen_stm32f303re_nucleo/Core/Inc/stm32f3xx_hal_conf.h @@ -57,7 +57,7 @@ /*#define HAL_RNG_MODULE_ENABLED */ /*#define HAL_RTC_MODULE_ENABLED */ #define HAL_SPI_MODULE_ENABLED -/*#define HAL_TIM_MODULE_ENABLED */ +#define HAL_TIM_MODULE_ENABLED #define HAL_UART_MODULE_ENABLED /*#define HAL_USART_MODULE_ENABLED */ /*#define HAL_IRDA_MODULE_ENABLED */ diff --git a/firmware/func_gen_stm32f303re_nucleo/Core/Inc/tim.h b/firmware/func_gen_stm32f303re_nucleo/Core/Inc/tim.h new file mode 100644 index 0000000..1cfd24e --- /dev/null +++ b/firmware/func_gen_stm32f303re_nucleo/Core/Inc/tim.h @@ -0,0 +1,55 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file tim.h + * @brief This file contains all the function prototypes for + * the tim.c file + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef __TIM_H__ +#define __TIM_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include "main.h" + +/* USER CODE BEGIN Includes */ + +/* USER CODE END Includes */ + +extern TIM_HandleTypeDef htim2; + +extern TIM_HandleTypeDef htim3; + +/* USER CODE BEGIN Private defines */ + +/* USER CODE END Private defines */ + +void MX_TIM2_Init(void); +void MX_TIM3_Init(void); + +/* USER CODE BEGIN Prototypes */ + +/* USER CODE END Prototypes */ + +#ifdef __cplusplus +} +#endif + +#endif /* __TIM_H__ */ + diff --git a/firmware/func_gen_stm32f303re_nucleo/Core/Src/main.c b/firmware/func_gen_stm32f303re_nucleo/Core/Src/main.c index b95a4ca..b48f5e0 100644 --- a/firmware/func_gen_stm32f303re_nucleo/Core/Src/main.c +++ b/firmware/func_gen_stm32f303re_nucleo/Core/Src/main.c @@ -20,6 +20,7 @@ #include "main.h" #include "i2c.h" #include "spi.h" +#include "tim.h" #include "usart.h" #include "gpio.h" @@ -65,38 +66,40 @@ void SystemClock_Config(void); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { - /* USER CODE BEGIN 1 */ + /* USER CODE BEGIN 1 */ - /* USER CODE END 1 */ + /* USER CODE END 1 */ - /* MCU Configuration--------------------------------------------------------*/ + /* MCU Configuration--------------------------------------------------------*/ - /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ - HAL_Init(); + /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ + HAL_Init(); - /* USER CODE BEGIN Init */ + /* USER CODE BEGIN Init */ - /* USER CODE END Init */ + /* USER CODE END Init */ - /* Configure the system clock */ - SystemClock_Config(); + /* Configure the system clock */ + SystemClock_Config(); - /* USER CODE BEGIN SysInit */ + /* USER CODE BEGIN SysInit */ - /* USER CODE END SysInit */ + /* USER CODE END SysInit */ - /* Initialize all configured peripherals */ - MX_GPIO_Init(); - MX_USART2_UART_Init(); - MX_SPI2_Init(); - MX_I2C1_Init(); - MX_SPI3_Init(); - /* USER CODE BEGIN 2 */ + /* Initialize all configured peripherals */ + MX_GPIO_Init(); + MX_USART2_UART_Init(); + MX_SPI2_Init(); + MX_I2C1_Init(); + MX_SPI3_Init(); + MX_TIM2_Init(); + MX_TIM3_Init(); + /* USER CODE BEGIN 2 */ APP_init(&app_data); hst7565.hspi = &hspi3; @@ -108,10 +111,10 @@ int main(void) hst7565.rst_pin = ST7565_RST_Pin; ST7565_Init(&hst7565, &disp); - /* USER CODE END 2 */ + /* USER CODE END 2 */ - /* Infinite loop */ - /* USER CODE BEGIN WHILE */ + /* Infinite loop */ + /* USER CODE BEGIN WHILE */ DISP_clearScreen(&disp); ST7565_DisplayAll(&hst7565); @@ -125,57 +128,61 @@ int main(void) ST7565_DisplayAll(&hst7565); LAY_drawDisplayLayout(&disp, &app_data); } - /* USER CODE END WHILE */ + /* USER CODE END WHILE */ - /* USER CODE BEGIN 3 */ + /* USER CODE BEGIN 3 */ } - /* USER CODE END 3 */ + /* USER CODE END 3 */ } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { - RCC_OscInitTypeDef RCC_OscInitStruct = {0}; - RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; - RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; + RCC_OscInitTypeDef RCC_OscInitStruct = {0}; + RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; + RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; - /** Initializes the RCC Oscillators according to the specified parameters - * in the RCC_OscInitTypeDef structure. - */ - RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; - RCC_OscInitStruct.HSIState = RCC_HSI_ON; - RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; - RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; - RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; - RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; - RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1; - if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) - { - Error_Handler(); - } + /** Initializes the RCC Oscillators according to the specified parameters + * in the RCC_OscInitTypeDef structure. + */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; + RCC_OscInitStruct.HSIState = RCC_HSI_ON; + RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; + RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; + RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1; + if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) + { + Error_Handler(); + } - /** Initializes the CPU, AHB and APB buses clocks - */ - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; - RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; - RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; - RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; - RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; + /** Initializes the CPU, AHB and APB buses clocks + */ + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK + |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; - if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) - { - Error_Handler(); - } - PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_I2C1; - PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1; - PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_HSI; - if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) - { - Error_Handler(); - } + if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) + { + Error_Handler(); + } + PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2|RCC_PERIPHCLK_I2C1 + |RCC_PERIPHCLK_TIM2|RCC_PERIPHCLK_TIM34; + PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1; + PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_HSI; + PeriphClkInit.Tim2ClockSelection = RCC_TIM2CLK_HCLK; + PeriphClkInit.Tim34ClockSelection = RCC_TIM34CLK_HCLK; + if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) + { + Error_Handler(); + } } /* USER CODE BEGIN 4 */ @@ -183,33 +190,33 @@ void SystemClock_Config(void) /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { - /* USER CODE BEGIN Error_Handler_Debug */ + /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) { } - /* USER CODE END Error_Handler_Debug */ + /* USER CODE END Error_Handler_Debug */ } -#ifdef USE_FULL_ASSERT +#ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { - /* USER CODE BEGIN 6 */ + /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ - /* USER CODE END 6 */ + /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ diff --git a/firmware/func_gen_stm32f303re_nucleo/Core/Src/tim.c b/firmware/func_gen_stm32f303re_nucleo/Core/Src/tim.c new file mode 100644 index 0000000..91b3645 --- /dev/null +++ b/firmware/func_gen_stm32f303re_nucleo/Core/Src/tim.c @@ -0,0 +1,202 @@ +/* USER CODE BEGIN Header */ +/** + ****************************************************************************** + * @file tim.c + * @brief This file provides code for the configuration + * of the TIM instances. + ****************************************************************************** + * @attention + * + * Copyright (c) 2023 STMicroelectronics. + * All rights reserved. + * + * This software is licensed under terms that can be found in the LICENSE file + * in the root directory of this software component. + * If no LICENSE file comes with this software, it is provided AS-IS. + * + ****************************************************************************** + */ +/* USER CODE END Header */ +/* Includes ------------------------------------------------------------------*/ +#include "tim.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ + +TIM_HandleTypeDef htim2; +TIM_HandleTypeDef htim3; + +/* TIM2 init function */ +void MX_TIM2_Init(void) +{ + + /* USER CODE BEGIN TIM2_Init 0 */ + + /* USER CODE END TIM2_Init 0 */ + + TIM_ClockConfigTypeDef sClockSourceConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM2_Init 1 */ + + /* USER CODE END TIM2_Init 1 */ + htim2.Instance = TIM2; + htim2.Init.Prescaler = 0; + htim2.Init.CounterMode = TIM_COUNTERMODE_UP; + htim2.Init.Period = 4294967295; + htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + if (HAL_TIM_Base_Init(&htim2) != HAL_OK) + { + Error_Handler(); + } + sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; + if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) + { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN TIM2_Init 2 */ + + /* USER CODE END TIM2_Init 2 */ + +} +/* TIM3 init function */ +void MX_TIM3_Init(void) +{ + + /* USER CODE BEGIN TIM3_Init 0 */ + + /* USER CODE END TIM3_Init 0 */ + + TIM_Encoder_InitTypeDef sConfig = {0}; + TIM_MasterConfigTypeDef sMasterConfig = {0}; + + /* USER CODE BEGIN TIM3_Init 1 */ + + /* USER CODE END TIM3_Init 1 */ + htim3.Instance = TIM3; + htim3.Init.Prescaler = 0; + htim3.Init.CounterMode = TIM_COUNTERMODE_UP; + htim3.Init.Period = 255; + htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; + htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; + sConfig.EncoderMode = TIM_ENCODERMODE_TI1; + sConfig.IC1Polarity = TIM_ICPOLARITY_RISING; + sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI; + sConfig.IC1Prescaler = TIM_ICPSC_DIV1; + sConfig.IC1Filter = 15; + sConfig.IC2Polarity = TIM_ICPOLARITY_RISING; + sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI; + sConfig.IC2Prescaler = TIM_ICPSC_DIV1; + sConfig.IC2Filter = 15; + if (HAL_TIM_Encoder_Init(&htim3, &sConfig) != HAL_OK) + { + Error_Handler(); + } + sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; + sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; + if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK) + { + Error_Handler(); + } + /* USER CODE BEGIN TIM3_Init 2 */ + + /* USER CODE END TIM3_Init 2 */ + +} + +void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) +{ + + if(tim_baseHandle->Instance==TIM2) + { + /* USER CODE BEGIN TIM2_MspInit 0 */ + + /* USER CODE END TIM2_MspInit 0 */ + /* TIM2 clock enable */ + __HAL_RCC_TIM2_CLK_ENABLE(); + /* USER CODE BEGIN TIM2_MspInit 1 */ + + /* USER CODE END TIM2_MspInit 1 */ + } +} + +void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef* tim_encoderHandle) +{ + + GPIO_InitTypeDef GPIO_InitStruct = {0}; + if(tim_encoderHandle->Instance==TIM3) + { + /* USER CODE BEGIN TIM3_MspInit 0 */ + + /* USER CODE END TIM3_MspInit 0 */ + /* TIM3 clock enable */ + __HAL_RCC_TIM3_CLK_ENABLE(); + + __HAL_RCC_GPIOA_CLK_ENABLE(); + /**TIM3 GPIO Configuration + PA6 ------> TIM3_CH1 + PA7 ------> TIM3_CH2 + */ + GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; + GPIO_InitStruct.Alternate = GPIO_AF2_TIM3; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + /* USER CODE BEGIN TIM3_MspInit 1 */ + + /* USER CODE END TIM3_MspInit 1 */ + } +} + +void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) +{ + + if(tim_baseHandle->Instance==TIM2) + { + /* USER CODE BEGIN TIM2_MspDeInit 0 */ + + /* USER CODE END TIM2_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM2_CLK_DISABLE(); + /* USER CODE BEGIN TIM2_MspDeInit 1 */ + + /* USER CODE END TIM2_MspDeInit 1 */ + } +} + +void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef* tim_encoderHandle) +{ + + if(tim_encoderHandle->Instance==TIM3) + { + /* USER CODE BEGIN TIM3_MspDeInit 0 */ + + /* USER CODE END TIM3_MspDeInit 0 */ + /* Peripheral clock disable */ + __HAL_RCC_TIM3_CLK_DISABLE(); + + /**TIM3 GPIO Configuration + PA6 ------> TIM3_CH1 + PA7 ------> TIM3_CH2 + */ + HAL_GPIO_DeInit(GPIOA, GPIO_PIN_6|GPIO_PIN_7); + + /* USER CODE BEGIN TIM3_MspDeInit 1 */ + + /* USER CODE END TIM3_MspDeInit 1 */ + } +} + +/* USER CODE BEGIN 1 */ + +/* USER CODE END 1 */ diff --git a/firmware/func_gen_stm32f303re_nucleo/Makefile b/firmware/func_gen_stm32f303re_nucleo/Makefile index 527d94f..1718e2f 100644 --- a/firmware/func_gen_stm32f303re_nucleo/Makefile +++ b/firmware/func_gen_stm32f303re_nucleo/Makefile @@ -1,5 +1,5 @@ ########################################################################################################################## -# File automatically-generated by tool: [projectgenerator] version: [3.17.1] date: [Sat Apr 01 12:37:38 CEST 2023] +# File automatically-generated by tool: [projectgenerator] version: [3.17.1] date: [Fri Apr 21 19:03:25 CEST 2023] ########################################################################################################################## # ------------------------------------------------ @@ -62,7 +62,8 @@ Core/Src/system_stm32f3xx.c \ Core/Src/spi.c \ Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_spi.c \ Drivers/STM32F3xx_HAL_Driver/Src/stm32f3xx_hal_spi_ex.c \ -Core/Src/i2c.c +Core/Src/i2c.c \ +Core/Src/tim.c ###################################### # shared libs source @@ -83,6 +84,7 @@ C_SOURCES += ../shared_libs/display/font_gfx.c # bitmaps C_SOURCES += ../shared_libs/bitmaps/bitmap_disp_buttons.c C_SOURCES += ../shared_libs/bitmaps/bitmap_font_5x7.c +C_SOURCES += ../shared_libs/bitmaps/bitmap_wave.c # display_layout C_SOURCES += ../shared_libs/disp_layout/disp_layout.c # controllers diff --git a/firmware/func_gen_stm32f303re_nucleo/func_gen_stm32f303re_nucleo.ioc b/firmware/func_gen_stm32f303re_nucleo/func_gen_stm32f303re_nucleo.ioc index 116e0e7..f61b5ca 100644 --- a/firmware/func_gen_stm32f303re_nucleo/func_gen_stm32f303re_nucleo.ioc +++ b/firmware/func_gen_stm32f303re_nucleo/func_gen_stm32f303re_nucleo.ioc @@ -13,38 +13,43 @@ Mcu.IP2=RCC Mcu.IP3=SPI2 Mcu.IP4=SPI3 Mcu.IP5=SYS -Mcu.IP6=USART2 -Mcu.IPNb=7 +Mcu.IP6=TIM2 +Mcu.IP7=TIM3 +Mcu.IP8=USART2 +Mcu.IPNb=9 Mcu.Name=STM32F303R(D-E)Tx Mcu.Package=LQFP64 Mcu.Pin0=PC13 Mcu.Pin1=PC14-OSC32_IN -Mcu.Pin10=PB11 -Mcu.Pin11=PB12 -Mcu.Pin12=PB13 -Mcu.Pin13=PB14 -Mcu.Pin14=PB15 -Mcu.Pin15=PA11 -Mcu.Pin16=PA13 -Mcu.Pin17=PA14 -Mcu.Pin18=PA15 -Mcu.Pin19=PC10 +Mcu.Pin10=PB1 +Mcu.Pin11=PB2 +Mcu.Pin12=PB11 +Mcu.Pin13=PB12 +Mcu.Pin14=PB13 +Mcu.Pin15=PB14 +Mcu.Pin16=PB15 +Mcu.Pin17=PA11 +Mcu.Pin18=PA13 +Mcu.Pin19=PA14 Mcu.Pin2=PC15-OSC32_OUT -Mcu.Pin20=PC11 -Mcu.Pin21=PC12 -Mcu.Pin22=PD2 -Mcu.Pin23=PB3 -Mcu.Pin24=PB6 -Mcu.Pin25=PB7 -Mcu.Pin26=VP_SYS_VS_Systick +Mcu.Pin20=PA15 +Mcu.Pin21=PC10 +Mcu.Pin22=PC11 +Mcu.Pin23=PC12 +Mcu.Pin24=PD2 +Mcu.Pin25=PB3 +Mcu.Pin26=PB6 +Mcu.Pin27=PB7 +Mcu.Pin28=VP_SYS_VS_Systick +Mcu.Pin29=VP_TIM2_VS_ClockSourceINT Mcu.Pin3=PF0-OSC_IN Mcu.Pin4=PF1-OSC_OUT Mcu.Pin5=PA2 Mcu.Pin6=PA3 Mcu.Pin7=PA5 -Mcu.Pin8=PB1 -Mcu.Pin9=PB2 -Mcu.PinsNb=27 +Mcu.Pin8=PA6 +Mcu.Pin9=PA7 +Mcu.PinsNb=30 Mcu.ThirdPartyNb=0 Mcu.UserConstants= Mcu.UserName=STM32F303RETx @@ -102,6 +107,9 @@ PA5.GPIO_PuPd=GPIO_NOPULL PA5.GPIO_Speed=GPIO_SPEED_FREQ_LOW PA5.Locked=true PA5.Signal=GPIO_Output +PA6.Signal=S_TIM3_CH1 +PA7.Locked=true +PA7.Signal=S_TIM3_CH2 PB1.GPIOParameters=GPIO_Label PB1.GPIO_Label=BTN1 PB1.Locked=true @@ -194,7 +202,7 @@ ProjectManager.StackSize=0x400 ProjectManager.TargetToolchain=Makefile ProjectManager.ToolChainLocation= ProjectManager.UnderRoot=false -ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USART2_UART_Init-USART2-false-HAL-true,4-MX_SPI2_Init-SPI2-false-HAL-true,5-MX_I2C1_Init-I2C1-false-HAL-true,6-MX_SPI3_Init-SPI3-false-HAL-true +ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USART2_UART_Init-USART2-false-HAL-true,4-MX_SPI2_Init-SPI2-false-HAL-true,5-MX_I2C1_Init-I2C1-false-HAL-true,6-MX_SPI3_Init-SPI3-false-HAL-true,7-MX_TIM2_Init-TIM2-false-HAL-true RCC.ADC12outputFreq_Value=72000000 RCC.ADC34outputFreq_Value=72000000 RCC.AHBFreq_Value=72000000 @@ -245,6 +253,10 @@ RCC.USBFreq_Value=72000000 RCC.VCOOutput2Freq_Value=8000000 SH.GPXTI13.0=GPIO_EXTI13 SH.GPXTI13.ConfNb=1 +SH.S_TIM3_CH1.0=TIM3_CH1,Encoder_Interface +SH.S_TIM3_CH1.ConfNb=1 +SH.S_TIM3_CH2.0=TIM3_CH2,Encoder_Interface +SH.S_TIM3_CH2.ConfNb=1 SPI2.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_32 SPI2.CalculateBaudRate=1.125 MBits/s SPI2.DataSize=SPI_DATASIZE_8BIT @@ -260,9 +272,17 @@ SPI3.Direction=SPI_DIRECTION_1LINE SPI3.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,BaudRatePrescaler,DataSize SPI3.Mode=SPI_MODE_MASTER SPI3.VirtualType=VM_MASTER +TIM2.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_DISABLE +TIM2.IPParameters=AutoReloadPreload +TIM3.IC1Filter=15 +TIM3.IC2Filter=15 +TIM3.IPParameters=Period,IC1Filter,IC2Filter +TIM3.Period=255 USART2.IPParameters=VirtualMode-Asynchronous USART2.VirtualMode-Asynchronous=VM_ASYNC VP_SYS_VS_Systick.Mode=SysTick VP_SYS_VS_Systick.Signal=SYS_VS_Systick +VP_TIM2_VS_ClockSourceINT.Mode=Internal +VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT board=NUCLEO-F303RE boardIOC=true diff --git a/firmware/shared_libs/bitmaps/bitmap_wave.c b/firmware/shared_libs/bitmaps/bitmap_wave.c new file mode 100644 index 0000000..dd7c4c6 --- /dev/null +++ b/firmware/shared_libs/bitmaps/bitmap_wave.c @@ -0,0 +1,57 @@ +#include "main.h" + +#include "bitmap_wave.h" + +// clang-format off +const uint8_t wave_sin[] = { + // res: 48x25(32) - 192 bytes + 0x00,0x00,0x80,0x60,0x10,0x08,0x04,0x04,0x02,0x02,0x01,0x01,0x01,0x01,0x02,0x02, + 0x04,0x04,0x08,0x10,0x60,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x18,0x06,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x01,0x06,0x18,0x30,0xC0,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x30, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x0C,0x10,0x20,0x40,0x40, + 0x80,0x80,0x00,0x00,0x00,0x00,0x80,0x80,0x40,0x40,0x20,0x10,0x0C,0x03,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x01,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; + +const uint8_t wave_tri[] = { + // res: 48x25(32) - 192 bytes + 0x00,0x00,0x00,0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x02,0x04,0x08, + 0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x10,0x08,0x04,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x40,0x20, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x04,0x08, + 0x10,0x20,0x40,0x80,0x00,0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, +}; +const uint8_t wave_sqr[] = { + // res: 48x25(32) - 192 bytes + 0xFF,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, + 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, + 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, +}; + +const GFX_bitmap_t wave[WAVE_MAX] = { + {48, 25, wave_sin}, + {48, 25, wave_tri}, + {48, 25, wave_sqr}, +}; diff --git a/firmware/shared_libs/bitmaps/bitmap_wave.h b/firmware/shared_libs/bitmaps/bitmap_wave.h new file mode 100644 index 0000000..929210c --- /dev/null +++ b/firmware/shared_libs/bitmaps/bitmap_wave.h @@ -0,0 +1,13 @@ +#pragma once + +#include "display_gfx.h" + +typedef enum +{ + WAVE_SIN, + WAVE_TRI, + WAVE_SQR, + WAVE_MAX +} BITMAP_wave_t; + +extern const GFX_bitmap_t wave[WAVE_MAX]; \ No newline at end of file diff --git a/firmware/shared_libs/controllers/ctrl_app.c b/firmware/shared_libs/controllers/ctrl_app.c index 49a8fbc..3d5cb34 100644 --- a/firmware/shared_libs/controllers/ctrl_app.c +++ b/firmware/shared_libs/controllers/ctrl_app.c @@ -113,6 +113,7 @@ static void _backToMain(void) _app_data->isButtonChange = 1; _app_data->isGraphChange = 1; _app_data->isValueChange = 1; + _app_data->isGraphChange = 1; } static void _blockFocusAtMaxAndMin(void) diff --git a/firmware/shared_libs/controllers/ctrl_app_types.h b/firmware/shared_libs/controllers/ctrl_app_types.h index 7423fda..91a6de9 100644 --- a/firmware/shared_libs/controllers/ctrl_app_types.h +++ b/firmware/shared_libs/controllers/ctrl_app_types.h @@ -18,6 +18,14 @@ typedef enum CHANNEL_MAX } GEN_channel_t; +typedef enum +{ + GEN_SIN, + GEN_TRI, + GEN_SQR, + GEN_WAVE_MAX, +} GEN_wave_t; + typedef enum { LAY_MAIN, @@ -53,4 +61,4 @@ typedef enum DISP_BTN_4, DISP_BTN_5, DISP_BTN_MAX, -} LAY_dispBtn_t; \ No newline at end of file +} LAY_dispBtn_t; diff --git a/firmware/shared_libs/disp_layout/disp_layout.c b/firmware/shared_libs/disp_layout/disp_layout.c index 575f3d3..1a3bc06 100644 --- a/firmware/shared_libs/disp_layout/disp_layout.c +++ b/firmware/shared_libs/disp_layout/disp_layout.c @@ -2,6 +2,9 @@ #include "printf.h" #include "bitmap_fonts.h" #include "bitmap_disp_buttons.h" +#include "bitmap_wave.h" +#include "tim.h" +#include "SEGGER_RTT.h" #include "disp_layout.h" @@ -15,7 +18,8 @@ const uint8_t marker_freq_pos_x[FREQ_MAX_DIGIT] = {76, 84, 90, 96, 105, 111, 118 const uint8_t marker_ampl_pos_x[AMPL_MAX_DIGIT] = {82, 94, 100}; // clang-format off -const GFX_bitmap_t marker = {05, 03, (uint8_t[]){0xF9,0xFB,0xFF,0xFB,0xF9,}}; +const GFX_bitmap_t marker_down = {05, 03, (uint8_t[]){0x01,0x03,0x07,0x03,0x01}};// res: 5x3(8) - 5 bytes +const GFX_bitmap_t marker_up = {05, 03, (uint8_t[]){0x04,0x06,0x07,0x06,0x04}}; // res: 5x3(8) - 5 bytes // clang-format on @@ -97,12 +101,22 @@ static void _drawButtons(GFX_display_t *disp, APP_data_t *app_data) app_data->isButtonChange = 0; } -static uint8_t _calcMarkePos(uint32_t value, uint32_t max) +static uint8_t _calcMarkerPos(uint32_t value, uint32_t max) { return ((62 * value) + (max / 2)) / max; // return (value < 0) ? ((62 * value) - (max / 2)) / max : ((62 * value) + (max / 2)) / max; } +static uint8_t _calcPhaseShiftInPxl(uint32_t value, uint32_t max) +{ + return ((48 * value) + (max / 2)) / max; +} + +static int32_t _calcVerticalShiftInPxl(int16_t value, int16_t max) +{ + return (value < 0) ? ((12 * value) - (max / 2)) / max : ((12 * value) + (max / 2)) / max; +} + static uint8_t _sizeOfCharArray(char *array) { uint8_t size = 0; @@ -122,7 +136,7 @@ static void _drawMeterHelper(GFX_display_t *disp, char *min, char *max, uint8_t DISP_writeString(disp, &font5x7Info, (uint8_t *)min, 62, 43, BM_NORMAL); DISP_writeString(disp, &font5x7Info, (uint8_t *)max, 127 - (6 * max_size), 43, BM_NORMAL); // marker 0% - 62, 100% - 123 - DISP_drawBitmap(disp, &marker, 62 + pos, 35, BM_NORMAL); + DISP_drawBitmap(disp, &marker_down, 62 + pos, 35, BM_NORMAL); } static void _drawFreqValueHelper(GFX_display_t *disp, uint32_t freq, uint8_t focus_digit) @@ -130,7 +144,7 @@ static void _drawFreqValueHelper(GFX_display_t *disp, uint32_t freq, uint8_t foc DISP_clearRegion(disp, 64, 13, 66, 40); DISP_writeString(disp, &font5x7Info, (uint8_t *)"F:", 64, 20, BM_NORMAL); _drawFreqValue(disp, freq, 20); - DISP_drawBitmap(disp, &marker, marker_freq_pos_x[(FREQ_MAX_DIGIT - 1) - focus_digit], 15, BM_NORMAL); + DISP_drawBitmap(disp, &marker_down, marker_freq_pos_x[(FREQ_MAX_DIGIT - 1) - focus_digit], 15, BM_NORMAL); } static void _drawAmplValueHelper(GFX_display_t *disp, uint32_t ampl, uint8_t focus_digit) @@ -138,7 +152,7 @@ static void _drawAmplValueHelper(GFX_display_t *disp, uint32_t ampl, uint8_t foc DISP_clearRegion(disp, 64, 13, 66, 40); DISP_writeString(disp, &font5x7Info, (uint8_t *)"A:", 64, 20, BM_NORMAL); _drawAmplValue(disp, ampl, 20); - DISP_drawBitmap(disp, &marker, marker_ampl_pos_x[(AMPL_MAX_DIGIT - 1) - focus_digit], 15, BM_NORMAL); + DISP_drawBitmap(disp, &marker_down, marker_ampl_pos_x[(AMPL_MAX_DIGIT - 1) - focus_digit], 15, BM_NORMAL); } static void _drawOffsValueHelper(GFX_display_t *disp, int32_t offs, uint8_t focus_digit) @@ -146,7 +160,7 @@ static void _drawOffsValueHelper(GFX_display_t *disp, int32_t offs, uint8_t focu DISP_clearRegion(disp, 64, 13, 66, 40); DISP_writeString(disp, &font5x7Info, (uint8_t *)"O:", 64, 20, BM_NORMAL); _drawOffsValue(disp, offs, 20); - DISP_drawBitmap(disp, &marker, marker_ampl_pos_x[(AMPL_MAX_DIGIT - 1) - focus_digit], 15, BM_NORMAL); + DISP_drawBitmap(disp, &marker_down, marker_ampl_pos_x[(AMPL_MAX_DIGIT - 1) - focus_digit], 15, BM_NORMAL); } static void _drawPhaseValueHelper(GFX_display_t *disp, uint32_t phase, uint8_t focus_digit) @@ -154,7 +168,7 @@ static void _drawPhaseValueHelper(GFX_display_t *disp, uint32_t phase, uint8_t f DISP_clearRegion(disp, 64, 13, 66, 40); DISP_writeString(disp, &font5x7Info, (uint8_t *)"P:", 64, 20, BM_NORMAL); _drawPhasValue(disp, phase, 20); - DISP_drawBitmap(disp, &marker, marker_ampl_pos_x[(AMPL_MAX_DIGIT - 1) - focus_digit], 15, BM_NORMAL); + DISP_drawBitmap(disp, &marker_down, marker_ampl_pos_x[(AMPL_MAX_DIGIT - 1) - focus_digit], 15, BM_NORMAL); } static void _drawFuncGenValues(GFX_display_t *disp, APP_data_t *app_data) @@ -164,20 +178,19 @@ static void _drawFuncGenValues(GFX_display_t *disp, APP_data_t *app_data) { case LAY_FREQ: _drawFreqValueHelper(disp, fun_gen->frequency, app_data->freq_focus_digit); - _drawMeterHelper(disp, "1", "1M", _calcMarkePos(990000, 1000000)); + _drawMeterHelper(disp, "1", "1M", _calcMarkerPos(990000, 1000000)); break; case LAY_AMPL: _drawAmplValueHelper(disp, fun_gen->amplitude, app_data->ampl_focus_digit); - _drawMeterHelper(disp, "0V", "5V", _calcMarkePos(100, 500)); + _drawMeterHelper(disp, "0V", "5V", _calcMarkerPos(100, 500)); break; case LAY_OFFS: - fun_gen->offset = -123; _drawOffsValueHelper(disp, fun_gen->offset, app_data->offs_focus_digit); - _drawMeterHelper(disp, "-5V", "+5V", _calcMarkePos(100 + 250, 500 + 250)); + _drawMeterHelper(disp, "-5V", "+5V", _calcMarkerPos(100 + 250, 500 + 250)); break; case LAY_PHAS: _drawPhaseValueHelper(disp, fun_gen->phase, app_data->phas_focus_digit); - _drawMeterHelper(disp, "0", "360", _calcMarkePos(100, 500)); + _drawMeterHelper(disp, "0", "360", _calcMarkerPos(100, 500)); break; case LAY_MAIN: DISP_clearRegion(disp, 62, 13, 66, 40); @@ -222,11 +235,74 @@ static void _drawValues(GFX_display_t *disp, APP_data_t *app_data) app_data->isValueChange = 0; } +static void _drawOffsetLine(GFX_display_t *disp, int16_t offs, uint32_t ampl) +{ + int8_t offs_shift = _calcVerticalShiftInPxl(offs, ampl); + + if (offs_shift > 20) + { + offs_shift = 20; + } + if (offs_shift < -19) + { + offs_shift = -19; + } + + DISP_drawHorizontalLine(disp, 2, 31 + offs_shift, 57, GFX_WHITE); +} + +static void _drawMaxAmpLine(GFX_display_t *disp, int16_t offs, uint32_t ampl) +{ + DISP_drawHorizontalLine(disp, 2, 12, 57, GFX_WHITE); + DISP_drawBitmap(disp, &marker_up, 0, 13, BM_NORMAL); + + DISP_drawHorizontalLine(disp, 2, 51, 57, GFX_WHITE); + DISP_drawBitmap(disp, &marker_down, 0, 48, BM_NORMAL); +} + +static void _drawFunGenGraph(GFX_display_t *disp, APP_data_t *app_data) +{ + GEN_fg_t *fun_gen = (GEN_fg_t *)app_data->generator; + + switch (fun_gen->wave) + { + case GEN_SIN: + DISP_drawBitmapShift(disp, &wave[WAVE_SIN], 6, 19, _calcPhaseShiftInPxl(fun_gen->phase, 360), BM_NORMAL); + break; + case GEN_TRI: + DISP_drawBitmapShift(disp, &wave[WAVE_TRI], 6, 19, _calcPhaseShiftInPxl(fun_gen->phase, 360), BM_NORMAL); + break; + case GEN_SQR: + DISP_drawBitmapShift(disp, &wave[WAVE_SQR], 6, 19, _calcPhaseShiftInPxl(fun_gen->phase, 360), BM_NORMAL); + break; + default: + break; + } + + _drawOffsetLine(disp, fun_gen->offset, fun_gen->amplitude); + // _drawMaxAmpLine(disp, fun_gen->offset, fun_gen->amplitude); +} +static void _drawPwmGenGraph(GFX_display_t *disp, APP_data_t *app_data) +{ +} + static void _drawGraph(GFX_display_t *disp, APP_data_t *app_data) { // input: graph type(sin, triangle, squere, pwm), frequency(info), amplitiude(value), offset(value), phase(value), invert(pwm), - // DISP_drawSin(disp, 4, 32, 16, 0, 0); - DISP_drawHorizontalLine(disp, 2, 32, 56, GFX_WHITE); + DISP_drawVerticalLine(disp, 2, 12, 40, GFX_WHITE); + + switch (app_data->curr_gen_type) + { + case GEN_FG_TYPE: + _drawFunGenGraph(disp, app_data); + break; + case GEN_PWM_TYPE: + _drawPwmGenGraph(disp, app_data); + break; + + default: + break; + } app_data->isGraphChange = 0; } @@ -234,7 +310,7 @@ static void _drawGraph(GFX_display_t *disp, APP_data_t *app_data) static void _drawChannels(GFX_display_t *disp, APP_data_t *app_data) { // input: active channel - DISP_writeString(disp, &font5x7Info, (uint8_t *)"CH1", 2, 2, CHANNEL1 == app_data->curr_channel ? BM_INVERSE : BM_NORMAL); + DISP_writeString(disp, &font5x7Info, (uint8_t *)"CH1", 2, 1, CHANNEL1 == app_data->curr_channel ? BM_INVERSE : BM_NORMAL); DISP_writeString(disp, &font5x7Info, (uint8_t *)"CH2", 23, 2, CHANNEL2 == app_data->curr_channel ? BM_INVERSE : BM_NORMAL); DISP_writeString(disp, &font5x7Info, (uint8_t *)"CH3", 44, 2, CHANNEL3 == app_data->curr_channel ? BM_INVERSE : BM_NORMAL); DISP_writeString(disp, &font5x7Info, (uint8_t *)"CH4", 65, 2, CHANNEL4 == app_data->curr_channel ? BM_INVERSE : BM_NORMAL); @@ -250,12 +326,12 @@ void LAY_drawDisplayLayout(GFX_display_t *disp, APP_data_t *app_data) if (app_data->isChannelChange) _drawChannels(disp, app_data); - if (app_data->isGraphChange) - _drawGraph(disp, app_data); - if (app_data->isValueChange) _drawValues(disp, app_data); + if (app_data->isGraphChange) + _drawGraph(disp, app_data); + if (app_data->isButtonChange) _drawButtons(disp, app_data); diff --git a/firmware/shared_libs/display/display_gfx.c b/firmware/shared_libs/display/display_gfx.c index f5b5e93..e697478 100644 --- a/firmware/shared_libs/display/display_gfx.c +++ b/firmware/shared_libs/display/display_gfx.c @@ -44,6 +44,31 @@ void DISP_drawPixel(GFX_display_t *disp, uint8_t x, uint8_t y, GFX_Color_t color break; } } +void DISP_drawBitmapSlow(GFX_display_t *disp, const GFX_bitmap_t *bitmap, uint8_t x, uint8_t y) +{ + uint8_t row_div_by_8 = 0; + uint8_t mask = 0; + uint8_t bitmap_byte = 0; + + for (uint8_t row = 0; row < bitmap->height; row++) + { + row_div_by_8 = row / 8; + mask = (row % 8); + for (uint8_t col = 0; col < bitmap->width; col++) + { + + bitmap_byte = bitmap->bitmap[row_div_by_8 * bitmap->width + col]; + if (bitmap_byte & (1 << mask)) + { + DISP_drawPixel(disp, col + x, row + y, GFX_WHITE); + } + else + { + DISP_drawPixel(disp, col + x, row + y, GFX_BLACK); + } + } + } +} /** * @brief Draw a vertical line. @@ -97,7 +122,7 @@ void DISP_drawSlashLine(GFX_display_t *disp, int16_t x0, int16_t y0, int16_t x1, /** * @brief Write a perfectly vertical line * @param disp A pointer to display struct - * @param x Top-most x coordinate + * @param x Left-most x coordinate * @param y Top-most y coordinate * @param height Height in pixels * @param color Color of pixel WHITE(0), BLACK(1) or INVERSE(2) @@ -114,11 +139,11 @@ void DISP_drawVerticalLine(GFX_display_t *disp, int16_t x, int16_t y, int16_t he @brief Write a perfectly horizontal line @param disp A pointer to display struct @param x Left-most x coordinate - @param y Left-most y coordinate + @param y Top-most y coordinate @param width Width in pixels @param color Color of pixel WHITE(0), BLACK(1) or INVERSE(2) */ -void DISP_drawHorizontalLine(GFX_display_t *disp, int16_t x, int16_t y, int16_t width, GFX_Color_t color) +void DISP_drawHorizontalLine(GFX_display_t *disp, uint8_t x, uint8_t y, uint8_t width, GFX_Color_t color) { for (int16_t i = x; i < x + width; i++) { @@ -396,6 +421,56 @@ void DISP_drawBitmap(GFX_display_t *disp, const GFX_bitmap_t *bitmap, int8_t pos } } +void DISP_drawBitmapShift(GFX_display_t *disp, const GFX_bitmap_t *bitmap, int8_t pos_x, int8_t pos_y, uint8_t shift_left, GFX_BitmapColor_t color) +{ + if (bitmap->width + pos_x < 0 || bitmap->height + pos_y < 0) + return; + + uint16_t tmp_buf16, bitmap_idx, buf_idx; + uint8_t tmp_bitmap, bitmap_row; + + buf_bitmap_boundry_t b; + _getBoundry(disp, &b, bitmap->width, bitmap->height, pos_x, pos_y); + + b.bitmap_col = (b.bitmap_col + shift_left) % bitmap->width; + for (uint8_t col = b.buf_col_first; col < b.buf_col_last; col++, b.bitmap_col = (b.bitmap_col + 1) % bitmap->width) + { + tmp_buf16 = 0; + bitmap_row = b.bitmap_row_first; + + if (b.bitmap_row_first > 0) + { + tmp_buf16 = _getBitmapByte(bitmap->bitmap, bitmap->width * (b.bitmap_row_first - 1) + b.bitmap_col, color) >> (8 - b.bitmap_shift); + } + else + { + tmp_buf16 = disp->buffor[b.buf_row_first * disp->width + col] & b.buf_mask_top; + } + + for (uint8_t buf_row = b.buf_row_first; buf_row < b.buf_row_last; buf_row++, bitmap_row++) + { + bitmap_idx = bitmap->width * bitmap_row + b.bitmap_col; + buf_idx = buf_row * disp->width + col; + + if (bitmap_idx < b.bitmap_max_idx) + { + tmp_bitmap = _getBitmapByte(bitmap->bitmap, bitmap_idx, color); + tmp_buf16 |= tmp_bitmap << b.bitmap_shift; + } + + if (b.bitmap_row_last == buf_row) + { + disp->buffor[buf_idx] = (disp->buffor[buf_idx] & b.buf_mask_bottom) | (tmp_buf16 & ~(b.buf_mask_bottom)); + } + else + { + disp->buffor[buf_idx] = (uint8_t)tmp_buf16; + } + tmp_buf16 = tmp_buf16 >> 8; + } + } +} + void DISP_drawFillRect(GFX_display_t *disp, int16_t x, int16_t y, int16_t width, int16_t height) { GFX_bitmap_t area = { diff --git a/firmware/shared_libs/display/display_gfx.h b/firmware/shared_libs/display/display_gfx.h index 6d6afe4..b3b8dee 100644 --- a/firmware/shared_libs/display/display_gfx.h +++ b/firmware/shared_libs/display/display_gfx.h @@ -51,7 +51,7 @@ typedef struct void DISP_drawPixel(GFX_display_t *disp, uint8_t x, uint8_t y, GFX_Color_t color); void DISP_drawVerticalLine(GFX_display_t *disp, int16_t x, int16_t y, int16_t height, GFX_Color_t color); -void DISP_drawHorizontalLine(GFX_display_t *disp, int16_t x, int16_t y, int16_t width, GFX_Color_t color); +void DISP_drawHorizontalLine(GFX_display_t *disp, uint8_t x, uint8_t y, uint8_t width, GFX_Color_t color); void DISP_drawSlashLine(GFX_display_t *disp, int16_t x0, int16_t y0, int16_t x1, int16_t y1, GFX_Color_t color); void DISP_drawRect(GFX_display_t *disp, int16_t x, int16_t y, int16_t width, int16_t height, GFX_Color_t color); void DISP_drawFillRect(GFX_display_t *disp, int16_t x, int16_t y, int16_t width, int16_t height); @@ -59,5 +59,8 @@ void DISP_drawCircle(GFX_display_t *disp, int16_t x0, int16_t y0, uint8_t radius void DISP_drawQuarterCircle(GFX_display_t *disp, int16_t x0, int16_t y0, uint8_t radius, GFX_CircCorners_t corner, GFX_Color_t color); void DISP_drawRoundRect(GFX_display_t *disp, int16_t x, int16_t y, int16_t width, int16_t height, int16_t radius, GFX_Color_t color); void DISP_drawBitmap(GFX_display_t *disp, const GFX_bitmap_t *bitmap, int8_t pos_x, int8_t pos_y, GFX_BitmapColor_t color); +void DISP_drawBitmapShift(GFX_display_t *disp, const GFX_bitmap_t *bitmap, int8_t pos_x, int8_t pos_y, uint8_t shift_left, GFX_BitmapColor_t color); void DISP_clearRegion(GFX_display_t *disp, int16_t x, int16_t y, int16_t width, int16_t height); void DISP_clearScreen(GFX_display_t *disp); + +void DISP_drawBitmapSlow(GFX_display_t *disp, const GFX_bitmap_t *bitmap, uint8_t x, uint8_t y);