Merge branch 'feature/disp_layout'
This commit is contained in:
17
firmware/.vscode/c_cpp_properties.json
vendored
17
firmware/.vscode/c_cpp_properties.json
vendored
@@ -3,16 +3,25 @@
|
||||
{
|
||||
"name": "Win32",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/func_gen_stm32f303re_nucleo/Core/**",
|
||||
"${workspaceFolder}/func_gen_stm32f303re_nucleo/Drivers/**",
|
||||
"${workspaceFolder}/shared_libs/**"
|
||||
"${workspaceFolder}/func_gen_stm32f303re_nucleo/Core/Inc",
|
||||
"${workspaceFolder}/func_gen_stm32f303re_nucleo/Drivers/CMSIS/Core/Include",
|
||||
"${workspaceFolder}/func_gen_stm32f303re_nucleo/Drivers/CMSIS/Device/ST/STM32F3xx/Include",
|
||||
"${workspaceFolder}/func_gen_stm32f303re_nucleo/Drivers/STM32F3xx_HAL_Driver/Inc",
|
||||
"${workspaceFolder}/shared_libs",
|
||||
"${workspaceFolder}/shared_libs/bitmaps",
|
||||
"${workspaceFolder}/shared_libs/controllers",
|
||||
"${workspaceFolder}/shared_libs/disp_layout",
|
||||
"${workspaceFolder}/shared_libs/display",
|
||||
"${workspaceFolder}/shared_libs/drivers/**",
|
||||
"${workspaceFolder}/shared_libs/utils/**"
|
||||
],
|
||||
"defines": [
|
||||
"_DEBUG",
|
||||
"UNICODE",
|
||||
"_UNICODE",
|
||||
"STM32F303xE",
|
||||
"USE_HAL_DRIVER"
|
||||
"USE_HAL_DRIVER",
|
||||
"ULOG_ENABLED"
|
||||
],
|
||||
"compilerPath": "C:/MyApps/arm-gcc/gcc-arm-none-eabi-10.3-2021.10/bin/arm-none-eabi-gcc.exe",
|
||||
"cStandard": "c11",
|
||||
|
||||
57
firmware/.vscode/launch.json
vendored
57
firmware/.vscode/launch.json
vendored
@@ -16,6 +16,7 @@
|
||||
"interface": "swd",
|
||||
"runToMain": true,
|
||||
"svdFile": "STM32F303xE.svd",
|
||||
"preLaunchTask": "${defaultBuildTask}",
|
||||
"rttConfig": {
|
||||
"enabled": true,
|
||||
"address": "auto",
|
||||
@@ -26,36 +27,36 @@
|
||||
"type": "console",
|
||||
"timestamp": true
|
||||
},
|
||||
{
|
||||
"label": "RTT graph",
|
||||
"port": 0,
|
||||
"encoding": "unsigned",
|
||||
"graphId": "1",
|
||||
"scale": 1
|
||||
}
|
||||
// {
|
||||
// "label": "RTT graph",
|
||||
// "port": 0,
|
||||
// "encoding": "unsigned",
|
||||
// "graphId": "1",
|
||||
// "scale": 1
|
||||
// }
|
||||
]
|
||||
},
|
||||
"graphConfig": [
|
||||
{
|
||||
"label": "Graph 1",
|
||||
"type": "realtime",
|
||||
"minimum": 0,
|
||||
"maximum": 65535,
|
||||
"timespan": 30,
|
||||
"plots": [
|
||||
{
|
||||
"graphId": "1",
|
||||
"label": "data 1",
|
||||
"color": "#53753c",
|
||||
},
|
||||
{
|
||||
"graphId": "2",
|
||||
"label": "data 2",
|
||||
"color": "#955f20"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
// "graphConfig": [
|
||||
// {
|
||||
// "label": "Graph 1",
|
||||
// "type": "realtime",
|
||||
// "minimum": 0,
|
||||
// "maximum": 65535,
|
||||
// "timespan": 30,
|
||||
// "plots": [
|
||||
// {
|
||||
// "graphId": "1",
|
||||
// "label": "data 1",
|
||||
// "color": "#53753c",
|
||||
// },
|
||||
// {
|
||||
// "graphId": "2",
|
||||
// "label": "data 2",
|
||||
// "color": "#955f20"
|
||||
// }
|
||||
// ]
|
||||
// }
|
||||
// ]
|
||||
}
|
||||
]
|
||||
}
|
||||
16
firmware/.vscode/settings.json
vendored
16
firmware/.vscode/settings.json
vendored
@@ -1,6 +1,20 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"ad9833_def.h": "c",
|
||||
"ad9833.h": "c"
|
||||
"ad9833.h": "c",
|
||||
"disp_layout.h": "c",
|
||||
"bitmap_disp_buttons.h": "c",
|
||||
"bitmap_fonts.h": "c",
|
||||
"font_gfx.h": "c",
|
||||
"display_gfx.h": "c",
|
||||
"main.h": "c",
|
||||
"ctrl_button.h": "c",
|
||||
"ctrl_bottom_button.h": "c",
|
||||
"printf.h": "c",
|
||||
"disp_layout_template.h": "c",
|
||||
"disp_layout_types.h": "c",
|
||||
"ctrl_app_types.h": "c",
|
||||
"tim.h": "c",
|
||||
"ulog.h": "c"
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -1,21 +1,21 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.h
|
||||
* @brief : Header for main.c file.
|
||||
* This file contains the common defines of the application.
|
||||
******************************************************************************
|
||||
* @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.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
******************************************************************************
|
||||
* @file : main.h
|
||||
* @brief : Header for main.c file.
|
||||
* This file contains the common defines of the application.
|
||||
******************************************************************************
|
||||
* @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 -------------------------------------*/
|
||||
@@ -23,7 +23,8 @@
|
||||
#define __MAIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
@@ -31,26 +32,27 @@ extern "C" {
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
// #include "SEGGER_RTT.h"
|
||||
#include "ulog.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
/* USER CODE END ET */
|
||||
|
||||
/* USER CODE END ET */
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EC */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EC */
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* USER CODE END EC */
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EM */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EM */
|
||||
/* USER CODE END EM */
|
||||
|
||||
/* USER CODE END EM */
|
||||
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
void Error_Handler(void);
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
void Error_Handler(void);
|
||||
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
@@ -65,15 +67,35 @@ void Error_Handler(void);
|
||||
#define USART_RX_GPIO_Port GPIOA
|
||||
#define LD2_Pin GPIO_PIN_5
|
||||
#define LD2_GPIO_Port GPIOA
|
||||
#define BTN1_Pin GPIO_PIN_1
|
||||
#define BTN1_GPIO_Port GPIOB
|
||||
#define BTN2_Pin GPIO_PIN_2
|
||||
#define BTN2_GPIO_Port GPIOB
|
||||
#define BTN3_Pin GPIO_PIN_11
|
||||
#define BTN3_GPIO_Port GPIOB
|
||||
#define BTN4_Pin GPIO_PIN_12
|
||||
#define BTN4_GPIO_Port GPIOB
|
||||
#define BTN5_Pin GPIO_PIN_11
|
||||
#define BTN5_GPIO_Port GPIOA
|
||||
#define TMS_Pin GPIO_PIN_13
|
||||
#define TMS_GPIO_Port GPIOA
|
||||
#define TCK_Pin GPIO_PIN_14
|
||||
#define TCK_GPIO_Port GPIOA
|
||||
#define ST7565_CS_Pin GPIO_PIN_15
|
||||
#define ST7565_CS_GPIO_Port GPIOA
|
||||
#define ST7565_SCK_Pin GPIO_PIN_10
|
||||
#define ST7565_SCK_GPIO_Port GPIOC
|
||||
#define ST7565_RST_Pin GPIO_PIN_11
|
||||
#define ST7565_RST_GPIO_Port GPIOC
|
||||
#define ST7565_MOSI_Pin GPIO_PIN_12
|
||||
#define ST7565_MOSI_GPIO_Port GPIOC
|
||||
#define ST7565_A0_Pin GPIO_PIN_2
|
||||
#define ST7565_A0_GPIO_Port GPIOD
|
||||
#define SWO_Pin GPIO_PIN_3
|
||||
#define SWO_GPIO_Port GPIOB
|
||||
/* USER CODE BEGIN Private defines */
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -34,11 +34,14 @@ extern "C" {
|
||||
|
||||
extern SPI_HandleTypeDef hspi2;
|
||||
|
||||
extern SPI_HandleTypeDef hspi3;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_SPI2_Init(void);
|
||||
void MX_SPI3_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
55
firmware/func_gen_stm32f303re_nucleo/Core/Inc/tim.h
Normal file
55
firmware/func_gen_stm32f303re_nucleo/Core/Inc/tim.h
Normal file
@@ -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__ */
|
||||
|
||||
@@ -49,9 +49,16 @@ void MX_GPIO_Init(void)
|
||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOA, LD2_Pin|ST7565_CS_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(ST7565_RST_GPIO_Port, ST7565_RST_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(ST7565_A0_GPIO_Port, ST7565_A0_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin : PtPin */
|
||||
GPIO_InitStruct.Pin = B1_Pin;
|
||||
@@ -59,12 +66,38 @@ void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PtPin */
|
||||
GPIO_InitStruct.Pin = LD2_Pin;
|
||||
/*Configure GPIO pins : PAPin PAPin */
|
||||
GPIO_InitStruct.Pin = LD2_Pin|ST7565_CS_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct);
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : PBPin PBPin PBPin PBPin */
|
||||
GPIO_InitStruct.Pin = BTN1_Pin|BTN2_Pin|BTN3_Pin|BTN4_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PtPin */
|
||||
GPIO_InitStruct.Pin = BTN5_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(BTN5_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PtPin */
|
||||
GPIO_InitStruct.Pin = ST7565_RST_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(ST7565_RST_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : PtPin */
|
||||
GPIO_InitStruct.Pin = ST7565_A0_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(ST7565_A0_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -20,12 +20,17 @@
|
||||
#include "main.h"
|
||||
#include "i2c.h"
|
||||
#include "spi.h"
|
||||
#include "tim.h"
|
||||
#include "usart.h"
|
||||
#include "gpio.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
#include "ctrl_app.h"
|
||||
#include "display_gfx.h"
|
||||
#include "disp_layout.h"
|
||||
#include "st7565.h"
|
||||
#include "SEGGER_RTT.h"
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@@ -45,13 +50,15 @@
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
st7565_handle_t hst7565;
|
||||
GFX_display_t disp;
|
||||
APP_data_t app_data;
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void SystemClock_Config(void);
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
void RTT_console_logger(ulog_level_t severity, char *msg);
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
@@ -60,130 +67,167 @@ 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();
|
||||
/* 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 */
|
||||
ulog_init();
|
||||
ulog_subscribe(RTT_console_logger, ULOG_DEBUG_LEVEL);
|
||||
|
||||
/* USER CODE END 2 */
|
||||
APP_init(&app_data);
|
||||
HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL);
|
||||
// SEGGER_RTT_WriteString(0, "App start...\n");
|
||||
ULOG_INFO("start app...");
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
hst7565.hspi = &hspi3;
|
||||
hst7565.cs_port = ST7565_CS_GPIO_Port;
|
||||
hst7565.cs_pin = ST7565_CS_Pin;
|
||||
hst7565.a0_port = ST7565_A0_GPIO_Port;
|
||||
hst7565.a0_pin = ST7565_A0_Pin;
|
||||
hst7565.rst_port = ST7565_RST_GPIO_Port;
|
||||
hst7565.rst_pin = ST7565_RST_Pin;
|
||||
ST7565_Init(&hst7565, &disp);
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
DISP_clearScreen(&disp);
|
||||
ST7565_DisplayAll(&hst7565);
|
||||
|
||||
uint32_t last_tick = HAL_GetTick();
|
||||
while (1)
|
||||
{
|
||||
/* USER CODE END WHILE */
|
||||
CTRL_buttonsHandler();
|
||||
if (HAL_GetTick() - last_tick > 100)
|
||||
{
|
||||
last_tick = HAL_GetTick();
|
||||
ST7565_DisplayAll(&hst7565);
|
||||
LAY_drawDisplayLayout(&disp, &app_data);
|
||||
}
|
||||
/* 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 */
|
||||
|
||||
void RTT_console_logger(ulog_level_t severity, char *msg)
|
||||
{
|
||||
SEGGER_RTT_printf(0, "[%s]: %s\n",
|
||||
// HAL_GetTick(), // user defined function
|
||||
ulog_level_name(severity),
|
||||
msg);
|
||||
}
|
||||
/* 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 */
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
/* USER CODE END 0 */
|
||||
|
||||
SPI_HandleTypeDef hspi2;
|
||||
SPI_HandleTypeDef hspi3;
|
||||
|
||||
/* SPI2 init function */
|
||||
void MX_SPI2_Init(void)
|
||||
@@ -59,6 +60,40 @@ void MX_SPI2_Init(void)
|
||||
|
||||
/* USER CODE END SPI2_Init 2 */
|
||||
|
||||
}
|
||||
/* SPI3 init function */
|
||||
void MX_SPI3_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN SPI3_Init 0 */
|
||||
|
||||
/* USER CODE END SPI3_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN SPI3_Init 1 */
|
||||
|
||||
/* USER CODE END SPI3_Init 1 */
|
||||
hspi3.Instance = SPI3;
|
||||
hspi3.Init.Mode = SPI_MODE_MASTER;
|
||||
hspi3.Init.Direction = SPI_DIRECTION_1LINE;
|
||||
hspi3.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||
hspi3.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||
hspi3.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||
hspi3.Init.NSS = SPI_NSS_SOFT;
|
||||
hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_64;
|
||||
hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
hspi3.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||
hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||
hspi3.Init.CRCPolynomial = 7;
|
||||
hspi3.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
|
||||
hspi3.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
|
||||
if (HAL_SPI_Init(&hspi3) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN SPI3_Init 2 */
|
||||
|
||||
/* USER CODE END SPI3_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
|
||||
@@ -90,6 +125,30 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
|
||||
|
||||
/* USER CODE END SPI2_MspInit 1 */
|
||||
}
|
||||
else if(spiHandle->Instance==SPI3)
|
||||
{
|
||||
/* USER CODE BEGIN SPI3_MspInit 0 */
|
||||
|
||||
/* USER CODE END SPI3_MspInit 0 */
|
||||
/* SPI3 clock enable */
|
||||
__HAL_RCC_SPI3_CLK_ENABLE();
|
||||
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
/**SPI3 GPIO Configuration
|
||||
PC10 ------> SPI3_SCK
|
||||
PC12 ------> SPI3_MOSI
|
||||
*/
|
||||
GPIO_InitStruct.Pin = ST7565_SCK_Pin|ST7565_MOSI_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
/* USER CODE BEGIN SPI3_MspInit 1 */
|
||||
|
||||
/* USER CODE END SPI3_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle)
|
||||
@@ -114,6 +173,24 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle)
|
||||
|
||||
/* USER CODE END SPI2_MspDeInit 1 */
|
||||
}
|
||||
else if(spiHandle->Instance==SPI3)
|
||||
{
|
||||
/* USER CODE BEGIN SPI3_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END SPI3_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_SPI3_CLK_DISABLE();
|
||||
|
||||
/**SPI3 GPIO Configuration
|
||||
PC10 ------> SPI3_SCK
|
||||
PC12 ------> SPI3_MOSI
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOC, ST7565_SCK_Pin|ST7565_MOSI_Pin);
|
||||
|
||||
/* USER CODE BEGIN SPI3_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END SPI3_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
202
firmware/func_gen_stm32f303re_nucleo/Core/Src/tim.c
Normal file
202
firmware/func_gen_stm32f303re_nucleo/Core/Src/tim.c
Normal file
@@ -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 */
|
||||
@@ -1,5 +1,5 @@
|
||||
##########################################################################################################################
|
||||
# File automatically-generated by tool: [projectgenerator] version: [3.17.1] date: [Sat Mar 25 21:51:05 CET 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,12 +84,22 @@ 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
|
||||
C_SOURCES += ../shared_libs/controllers/ctrl_bottom_button.c
|
||||
C_SOURCES += ../shared_libs/controllers/ctrl_channel_button.c
|
||||
C_SOURCES += ../shared_libs/controllers/ctrl_app.c
|
||||
C_SOURCES += ../shared_libs/controllers/ctrl_encoder.c
|
||||
|
||||
# utils/printf
|
||||
C_SOURCES += ../shared_libs/utils/printf/printf.c
|
||||
# utils/rtt
|
||||
C_SOURCES += ../shared_libs/utils/rtt/SEGGER_RTT.c
|
||||
C_SOURCES += ../shared_libs/utils/rtt/SEGGER_RTT_printf.c
|
||||
# utils/ulog
|
||||
C_SOURCES += ../shared_libs/utils/ulog/ulog.c
|
||||
|
||||
# ASM sources
|
||||
ASM_SOURCES = \
|
||||
@@ -137,7 +148,8 @@ AS_DEFS =
|
||||
# C defines
|
||||
C_DEFS = \
|
||||
-DUSE_HAL_DRIVER \
|
||||
-DSTM32F303xE
|
||||
-DSTM32F303xE \
|
||||
-DULOG_ENABLED
|
||||
|
||||
|
||||
# AS includes
|
||||
@@ -165,10 +177,16 @@ C_INCLUDES += -I../shared_libs/drivers/hw_button
|
||||
C_INCLUDES += -I../shared_libs/display
|
||||
# bitmaps includes
|
||||
C_INCLUDES += -I../shared_libs/bitmaps
|
||||
# display layout includes
|
||||
C_INCLUDES += -I../shared_libs/disp_layout
|
||||
# controllers includes
|
||||
C_INCLUDES += -I../shared_libs/controllers
|
||||
|
||||
# utils/print includes
|
||||
# utils includes
|
||||
C_INCLUDES += -I../shared_libs/utils/printf
|
||||
C_INCLUDES += -I../shared_libs/utils/rtt
|
||||
C_INCLUDES += -I../shared_libs/utils/ulog
|
||||
|
||||
|
||||
# compile gcc flags
|
||||
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
|
||||
|
||||
@@ -11,29 +11,45 @@ Mcu.IP0=I2C1
|
||||
Mcu.IP1=NVIC
|
||||
Mcu.IP2=RCC
|
||||
Mcu.IP3=SPI2
|
||||
Mcu.IP4=SYS
|
||||
Mcu.IP5=USART2
|
||||
Mcu.IPNb=6
|
||||
Mcu.IP4=SPI3
|
||||
Mcu.IP5=SYS
|
||||
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=PB15
|
||||
Mcu.Pin11=PA13
|
||||
Mcu.Pin12=PA14
|
||||
Mcu.Pin13=PB3
|
||||
Mcu.Pin14=PB6
|
||||
Mcu.Pin15=PB7
|
||||
Mcu.Pin16=VP_SYS_VS_Systick
|
||||
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=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=PB13
|
||||
Mcu.Pin9=PB14
|
||||
Mcu.PinsNb=17
|
||||
Mcu.Pin8=PA6
|
||||
Mcu.Pin9=PA7
|
||||
Mcu.PinsNb=30
|
||||
Mcu.ThirdPartyNb=0
|
||||
Mcu.UserConstants=
|
||||
Mcu.UserName=STM32F303RETx
|
||||
@@ -50,6 +66,10 @@ NVIC.PriorityGroup=NVIC_PRIORITYGROUP_0
|
||||
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||
NVIC.SysTick_IRQn=true\:0\:0\:true\:false\:true\:true\:true\:false
|
||||
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:false
|
||||
PA11.GPIOParameters=GPIO_Label
|
||||
PA11.GPIO_Label=BTN5
|
||||
PA11.Locked=true
|
||||
PA11.Signal=GPIO_Input
|
||||
PA13.GPIOParameters=GPIO_Label
|
||||
PA13.GPIO_Label=TMS
|
||||
PA13.Locked=true
|
||||
@@ -60,6 +80,10 @@ PA14.GPIO_Label=TCK
|
||||
PA14.Locked=true
|
||||
PA14.Mode=Serial_Wire
|
||||
PA14.Signal=SYS_JTCK-SWCLK
|
||||
PA15.GPIOParameters=GPIO_Label
|
||||
PA15.GPIO_Label=ST7565_CS
|
||||
PA15.Locked=true
|
||||
PA15.Signal=GPIO_Output
|
||||
PA2.GPIOParameters=GPIO_Speed,GPIO_PuPd,GPIO_Label,GPIO_Mode
|
||||
PA2.GPIO_Label=USART_TX
|
||||
PA2.GPIO_Mode=GPIO_MODE_AF_PP
|
||||
@@ -83,12 +107,31 @@ 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
|
||||
PB1.Signal=GPIO_Input
|
||||
PB11.GPIOParameters=GPIO_Label
|
||||
PB11.GPIO_Label=BTN3
|
||||
PB11.Locked=true
|
||||
PB11.Signal=GPIO_Input
|
||||
PB12.GPIOParameters=GPIO_Label
|
||||
PB12.GPIO_Label=BTN4
|
||||
PB12.Locked=true
|
||||
PB12.Signal=GPIO_Input
|
||||
PB13.Mode=Full_Duplex_Master
|
||||
PB13.Signal=SPI2_SCK
|
||||
PB14.Mode=Full_Duplex_Master
|
||||
PB14.Signal=SPI2_MISO
|
||||
PB15.Mode=Full_Duplex_Master
|
||||
PB15.Signal=SPI2_MOSI
|
||||
PB2.GPIOParameters=GPIO_Label
|
||||
PB2.GPIO_Label=BTN2
|
||||
PB2.Locked=true
|
||||
PB2.Signal=GPIO_Input
|
||||
PB3.GPIOParameters=GPIO_Label
|
||||
PB3.GPIO_Label=SWO
|
||||
PB3.Locked=true
|
||||
@@ -98,6 +141,19 @@ PB6.Mode=I2C
|
||||
PB6.Signal=I2C1_SCL
|
||||
PB7.Mode=I2C
|
||||
PB7.Signal=I2C1_SDA
|
||||
PC10.GPIOParameters=GPIO_Label
|
||||
PC10.GPIO_Label=ST7565_SCK
|
||||
PC10.Locked=true
|
||||
PC10.Mode=Simplex_Bidirectional_Master
|
||||
PC10.Signal=SPI3_SCK
|
||||
PC11.GPIOParameters=GPIO_Label
|
||||
PC11.GPIO_Label=ST7565_RST
|
||||
PC11.Locked=true
|
||||
PC11.Signal=GPIO_Output
|
||||
PC12.GPIOParameters=GPIO_Label
|
||||
PC12.GPIO_Label=ST7565_MOSI
|
||||
PC12.Mode=Simplex_Bidirectional_Master
|
||||
PC12.Signal=SPI3_MOSI
|
||||
PC13.GPIOParameters=GPIO_Label,GPIO_ModeDefaultEXTI
|
||||
PC13.GPIO_Label=B1 [Blue PushButton]
|
||||
PC13.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_FALLING
|
||||
@@ -109,6 +165,10 @@ PC14-OSC32_IN.Signal=RCC_OSC32_IN
|
||||
PC15-OSC32_OUT.Locked=true
|
||||
PC15-OSC32_OUT.Mode=LSE-External-Oscillator
|
||||
PC15-OSC32_OUT.Signal=RCC_OSC32_OUT
|
||||
PD2.GPIOParameters=GPIO_Label
|
||||
PD2.GPIO_Label=ST7565_A0
|
||||
PD2.Locked=true
|
||||
PD2.Signal=GPIO_Output
|
||||
PF0-OSC_IN.Locked=true
|
||||
PF0-OSC_IN.Mode=HSE-External-Clock-Source
|
||||
PF0-OSC_IN.Signal=RCC_OSC_IN
|
||||
@@ -142,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
|
||||
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
|
||||
@@ -193,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
|
||||
@@ -201,9 +265,24 @@ SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize,NSSPMode
|
||||
SPI2.Mode=SPI_MODE_MASTER
|
||||
SPI2.NSSPMode=SPI_NSS_PULSE_ENABLE
|
||||
SPI2.VirtualType=VM_MASTER
|
||||
SPI3.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_64
|
||||
SPI3.CalculateBaudRate=562.5 KBits/s
|
||||
SPI3.DataSize=SPI_DATASIZE_8BIT
|
||||
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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "main.h"
|
||||
#include "display_gfx.h"
|
||||
|
||||
#include "bitmap_disp_buttons.h"
|
||||
|
||||
// clang-format off
|
||||
@@ -198,10 +198,17 @@ const uint8_t btn_x10_inverse[] = {
|
||||
0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFE,0xFE,0xFF,0xFF,0xFE,0xFE,0xFE,0xFF,0xFF,0xFF,
|
||||
0xFB,0xF9,
|
||||
};
|
||||
const uint8_t btn_empty[] = {
|
||||
// res: 25x11 - 50 bytes
|
||||
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,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,
|
||||
};
|
||||
|
||||
// clang-format on
|
||||
|
||||
GFX_bitmap_t btn_bottom[DISP_BTN_MAX] = {
|
||||
const GFX_bitmap_t bitmap_btnBottom[BITMAP_BTN_MAX] = {
|
||||
{25, 11, btn_fre},
|
||||
{25, 11, btn_fre_inverse},
|
||||
{25, 11, btn_amp},
|
||||
@@ -226,6 +233,7 @@ GFX_bitmap_t btn_bottom[DISP_BTN_MAX] = {
|
||||
{25, 11, btn_x1_inverse},
|
||||
{25, 11, btn_x10},
|
||||
{25, 11, btn_x10_inverse},
|
||||
{25, 11, btn_empty},
|
||||
|
||||
{0, 0, NULL},
|
||||
};
|
||||
|
||||
@@ -1,33 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include "display_gfx.h"
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DISP_BTN_FREQ,
|
||||
DISP_BTN_FREQ_INVERSE,
|
||||
DISP_BTN_AMPL,
|
||||
DISP_BTN_AMPL_INVERSE,
|
||||
DISP_BTN_OFFS,
|
||||
DISP_BTN_OFFS_INVERSE,
|
||||
DISP_BTN_PHAS,
|
||||
DISP_BTN_PHAS_INVERSE,
|
||||
DISP_BTN_WAVE,
|
||||
DISP_BTN_WAVE_INVERSE,
|
||||
DISP_BTN_BACK,
|
||||
DISP_BTN_BACK_INVERSE,
|
||||
DISP_BTN_LEFT,
|
||||
DISP_BTN_LEFT_INVERSE,
|
||||
DISP_BTN_RIGHT,
|
||||
DISP_BTN_RIGHT_INVERSE,
|
||||
DISP_BTN_X0_01,
|
||||
DISP_BTN_X0_01_INVERSE,
|
||||
DISP_BTN_X0_1,
|
||||
DISP_BTN_X0_1_INVERSE,
|
||||
DISP_BTN_X1,
|
||||
DISP_BTN_X1_INVERSE,
|
||||
DISP_BTN_X10,
|
||||
DISP_BTN_X10_INVERSE,
|
||||
DISP_BTN_NONE,
|
||||
DISP_BTN_MAX,
|
||||
BITMAP_BTN_FREQ,
|
||||
BITMAP_BTN_FREQ_INVERSE,
|
||||
BITMAP_BTN_AMPL,
|
||||
BITMAP_BTN_AMPL_INVERSE,
|
||||
BITMAP_BTN_OFFS,
|
||||
BITMAP_BTN_OFFS_INVERSE,
|
||||
BITMAP_BTN_PHAS,
|
||||
BITMAP_BTN_PHAS_INVERSE,
|
||||
BITMAP_BTN_WAVE,
|
||||
BITMAP_BTN_WAVE_INVERSE,
|
||||
BITMAP_BTN_BACK,
|
||||
BITMAP_BTN_BACK_INVERSE,
|
||||
BITMAP_BTN_LEFT,
|
||||
BITMAP_BTN_LEFT_INVERSE,
|
||||
BITMAP_BTN_RIGHT,
|
||||
BITMAP_BTN_RIGHT_INVERSE,
|
||||
BITMAP_BTN_X0_01,
|
||||
BITMAP_BTN_X0_01_INVERSE,
|
||||
BITMAP_BTN_X0_1,
|
||||
BITMAP_BTN_X0_1_INVERSE,
|
||||
BITMAP_BTN_X1,
|
||||
BITMAP_BTN_X1_INVERSE,
|
||||
BITMAP_BTN_X10,
|
||||
BITMAP_BTN_X10_INVERSE,
|
||||
BITMAP_BTN_EMPTY,
|
||||
BITMAP_BTN_NONE,
|
||||
BITMAP_BTN_MAX,
|
||||
} BITMAP_buttonName_t;
|
||||
|
||||
extern GFX_bitmap_t btn_bottom[DISP_BTN_MAX];
|
||||
extern const GFX_bitmap_t bitmap_btnBottom[BITMAP_BTN_MAX];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "main.h"
|
||||
#include "font_gfx.h"
|
||||
|
||||
#include "bitmap_fonts.h"
|
||||
|
||||
// clang-format off
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "font_gfx.h"
|
||||
|
||||
/* Font data for standard 5x7t */
|
||||
extern const uint8_t font5x7[];
|
||||
extern const GFX_font_t font5x7Info;
|
||||
|
||||
57
firmware/shared_libs/bitmaps/bitmap_wave.c
Normal file
57
firmware/shared_libs/bitmaps/bitmap_wave.c
Normal file
@@ -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},
|
||||
};
|
||||
13
firmware/shared_libs/bitmaps/bitmap_wave.h
Normal file
13
firmware/shared_libs/bitmaps/bitmap_wave.h
Normal file
@@ -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];
|
||||
551
firmware/shared_libs/controllers/ctrl_app.c
Normal file
551
firmware/shared_libs/controllers/ctrl_app.c
Normal file
@@ -0,0 +1,551 @@
|
||||
#include "main.h"
|
||||
#include "hw_button.h"
|
||||
#include "ctrl_bottom_button.h"
|
||||
#include "ctrl_channel_button.h"
|
||||
#include "ctrl_encoder.h"
|
||||
|
||||
#include "ctrl_app.h"
|
||||
|
||||
typedef void (*btn_action_t)(void);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
btn_action_t command;
|
||||
BITMAP_buttonName_t bitmap_name;
|
||||
} CMD_button_t;
|
||||
|
||||
static GEN_fg_t func_gen[3];
|
||||
static GEN_pwm_t pwm_gen[3];
|
||||
|
||||
static const CMD_button_t btn_command[BTN_STATE_MAX][DISP_BTN_MAX];
|
||||
static const LAY_dispBtn_t btn_hw_to_disp[BTN_BOT_MAX] = {DISP_BTN_1, DISP_BTN_2, DISP_BTN_3, DISP_BTN_4, DISP_BTN_5};
|
||||
static const uint32_t pow_of_10[7] = {1, 10, 100, 1000, 10000, 100000, 1000000};
|
||||
|
||||
static HW_BotBtnName_t last_key;
|
||||
static APP_data_t *_app_data;
|
||||
|
||||
static const GENERATOR_t generators[CHANNEL_MAX] = {
|
||||
{.gen_type = GEN_FG_TYPE, .gen = &func_gen[0]},
|
||||
{.gen_type = GEN_FG_TYPE, .gen = &func_gen[1]},
|
||||
{.gen_type = GEN_FG_TYPE, .gen = &func_gen[2]},
|
||||
{.gen_type = GEN_PWM_TYPE, .gen = &pwm_gen[0]},
|
||||
{.gen_type = GEN_PWM_TYPE, .gen = &pwm_gen[1]},
|
||||
{.gen_type = GEN_PWM_TYPE, .gen = &pwm_gen[2]},
|
||||
};
|
||||
|
||||
void APP_init(APP_data_t *app_data)
|
||||
{
|
||||
_app_data = app_data;
|
||||
_app_data->freq_focus_digit = 4;
|
||||
_app_data->ampl_focus_digit = 1;
|
||||
_app_data->offs_focus_digit = 1;
|
||||
_app_data->phas_focus_digit = 0;
|
||||
_app_data->duty_focus_digit = 0;
|
||||
|
||||
_app_data->curr_gen_type = GEN_FG_TYPE;
|
||||
_app_data->generator = generators[CHANNEL1].gen;
|
||||
|
||||
_app_data->curr_state_lay = LAY_MAIN;
|
||||
_app_data->curr_state_btn = BTN_MAIN_FG;
|
||||
|
||||
_app_data->isChannelChange = 1;
|
||||
_app_data->isGraphChange = 1;
|
||||
_app_data->isValueChange = 1;
|
||||
_app_data->isButtonChange = 1;
|
||||
_app_data->isButtonBlink = 1;
|
||||
|
||||
CTRL_buttonsInit();
|
||||
}
|
||||
|
||||
void CTRL_buttonsInit(void)
|
||||
{
|
||||
|
||||
CTRL_bottomButtonInit();
|
||||
// CTRL_channelButtonInit();
|
||||
}
|
||||
|
||||
void CTRL_buttonsHandler(void)
|
||||
{
|
||||
CTRL_bottomButtonsHandler();
|
||||
CTRL_channelButtonsHandler();
|
||||
CTRL_encoderHandler();
|
||||
}
|
||||
|
||||
void CTRL_pushedDispBtnEvent(ButtonKey_t *key)
|
||||
{
|
||||
ULOG_TRACE("Disp btn: %d", key->instance);
|
||||
last_key = btn_hw_to_disp[key->instance];
|
||||
btn_command[_app_data->curr_state_btn][last_key].command();
|
||||
}
|
||||
|
||||
void CTRL_pushedChanBtnEvent(ButtonKey_t *key)
|
||||
{
|
||||
ULOG_TRACE("Chan btn: %d", key->instance);
|
||||
UNUSED(key);
|
||||
}
|
||||
|
||||
static void _changeValueFunGen(int8_t dir)
|
||||
{
|
||||
GEN_fg_t *gen = (GEN_fg_t *)_app_data->generator;
|
||||
|
||||
switch (_app_data->curr_state_lay)
|
||||
{
|
||||
case LAY_FREQ:
|
||||
{
|
||||
uint32_t new_freq = dir * pow_of_10[_app_data->freq_focus_digit] + gen->frequency;
|
||||
ULOG_DEBUG("<FG> New freq: %lu", new_freq);
|
||||
if (new_freq > MAX_FREQ)
|
||||
{
|
||||
return;
|
||||
}
|
||||
gen->frequency = new_freq;
|
||||
break;
|
||||
}
|
||||
case LAY_AMPL:
|
||||
{
|
||||
uint16_t new_ampl = dir * pow_of_10[_app_data->ampl_focus_digit] + gen->amplitude;
|
||||
ULOG_DEBUG("<FG> New ampl: %u", new_ampl);
|
||||
if (gen->offset + new_ampl > MAX_VOLT_POS || gen->offset - new_ampl < MAX_VOLT_NEG)
|
||||
{
|
||||
return;
|
||||
}
|
||||
gen->amplitude = new_ampl;
|
||||
break;
|
||||
}
|
||||
case LAY_OFFS:
|
||||
{
|
||||
int16_t new_offs = dir * pow_of_10[_app_data->offs_focus_digit] + gen->offset;
|
||||
ULOG_DEBUG("<FG> New offs: %i", new_offs);
|
||||
if (new_offs + gen->amplitude > MAX_VOLT_POS || new_offs - gen->amplitude < MAX_VOLT_NEG)
|
||||
{
|
||||
return;
|
||||
}
|
||||
gen->offset = new_offs;
|
||||
break;
|
||||
}
|
||||
case LAY_PHAS:
|
||||
{
|
||||
uint16_t new_phas = dir * pow_of_10[_app_data->phas_focus_digit] + gen->phase;
|
||||
ULOG_DEBUG("<FG> New phas: %u", new_phas);
|
||||
if (new_phas > MAX_PHAS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
gen->phase = new_phas;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ULOG_ERROR("%s:%d: Unknown layout: %d", __FILE__, __LINE__, _app_data->curr_state_lay);
|
||||
return;
|
||||
}
|
||||
|
||||
_app_data->isValueChange = 1;
|
||||
_app_data->isGraphChange = 1;
|
||||
}
|
||||
|
||||
static void _changeValuePwmGen(int8_t dir)
|
||||
{
|
||||
GEN_pwm_t *gen = (GEN_pwm_t *)_app_data->generator;
|
||||
|
||||
switch (_app_data->curr_state_lay)
|
||||
{
|
||||
case LAY_FREQ:
|
||||
{
|
||||
uint32_t new_freq = dir * pow_of_10[_app_data->freq_focus_digit] + gen->frequency;
|
||||
ULOG_DEBUG("<PWM> New freq: %lu", new_freq);
|
||||
if (new_freq > MAX_FREQ)
|
||||
{
|
||||
return;
|
||||
}
|
||||
gen->frequency = new_freq;
|
||||
break;
|
||||
}
|
||||
case LAY_AMPL:
|
||||
{
|
||||
uint16_t new_ampl = dir * pow_of_10[_app_data->ampl_focus_digit] + gen->amplitude;
|
||||
ULOG_DEBUG("<PWM> New ampl: %u", new_ampl);
|
||||
if (gen->offset + new_ampl > MAX_VOLT_POS || gen->offset - new_ampl < MAX_VOLT_NEG)
|
||||
{
|
||||
return;
|
||||
}
|
||||
gen->amplitude = new_ampl;
|
||||
break;
|
||||
}
|
||||
case LAY_OFFS:
|
||||
{
|
||||
int16_t new_offs = dir * pow_of_10[_app_data->offs_focus_digit] + gen->offset;
|
||||
ULOG_DEBUG("<PWM> New offs: %i", new_offs);
|
||||
if (new_offs + gen->amplitude > MAX_VOLT_POS || new_offs - gen->amplitude < MAX_VOLT_NEG)
|
||||
{
|
||||
return;
|
||||
}
|
||||
gen->offset = new_offs;
|
||||
break;
|
||||
}
|
||||
case LAY_PHAS:
|
||||
{
|
||||
uint16_t new_phas = dir * pow_of_10[_app_data->phas_focus_digit] + gen->phase;
|
||||
ULOG_DEBUG("<PWM> New phas: %u", new_phas);
|
||||
if (new_phas > MAX_PHAS)
|
||||
{
|
||||
return;
|
||||
}
|
||||
gen->phase = new_phas;
|
||||
break;
|
||||
}
|
||||
case LAY_DUTY:
|
||||
{
|
||||
uint8_t new_duty = dir * pow_of_10[_app_data->duty_focus_digit] + gen->duty;
|
||||
ULOG_DEBUG("<PWM> New duty: %u", new_duty);
|
||||
if (new_duty > MAX_DUTY)
|
||||
{
|
||||
return;
|
||||
}
|
||||
gen->duty = new_duty;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
ULOG_ERROR("%s:%d: Unknown layout: %d", __FILE__, __LINE__, _app_data->curr_state_lay);
|
||||
return;
|
||||
}
|
||||
|
||||
_app_data->isValueChange = 1;
|
||||
_app_data->isGraphChange = 1;
|
||||
}
|
||||
|
||||
void CTRL_encoderEvent(int8_t enc)
|
||||
{
|
||||
ULOG_TRACE("Enco event: %i", enc);
|
||||
switch (_app_data->curr_gen_type)
|
||||
{
|
||||
case GEN_FG_TYPE:
|
||||
_changeValueFunGen(enc / 2);
|
||||
break;
|
||||
case GEN_PWM_TYPE:
|
||||
_changeValuePwmGen(enc / 2);
|
||||
break;
|
||||
|
||||
default:
|
||||
ULOG_ERROR("%s:%d: Unknown generator type: %d", __FILE__, __LINE__, _app_data->curr_gen_type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
inline BITMAP_buttonName_t CTRL_getBitmapName(LAY_dispBtn_t disp_btn)
|
||||
{
|
||||
return btn_command[_app_data->curr_state_btn][disp_btn].bitmap_name;
|
||||
}
|
||||
|
||||
static void _doNoting(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
static void _backToMain(void)
|
||||
{
|
||||
_app_data->curr_state_lay = LAY_MAIN;
|
||||
|
||||
switch (_app_data->curr_gen_type)
|
||||
{
|
||||
case GEN_FG_TYPE:
|
||||
_app_data->curr_state_btn = BTN_MAIN_FG;
|
||||
break;
|
||||
|
||||
case GEN_PWM_TYPE:
|
||||
_app_data->curr_state_btn = BTN_MAIN_PWM;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
_app_data->isButtonChange = 1;
|
||||
_app_data->isGraphChange = 1;
|
||||
_app_data->isValueChange = 1;
|
||||
_app_data->isGraphChange = 1;
|
||||
}
|
||||
|
||||
static void _blockFocusAtMaxAndMin(void)
|
||||
{
|
||||
switch (_app_data->curr_state_btn)
|
||||
{
|
||||
case BTN_FREQ_MIN:
|
||||
if (_app_data->freq_focus_digit > 0)
|
||||
{
|
||||
_app_data->curr_state_btn = BTN_FREQ;
|
||||
_app_data->isButtonChange = 1;
|
||||
}
|
||||
break;
|
||||
case BTN_FREQ_MAX:
|
||||
if (_app_data->freq_focus_digit < FUN_GEN_FOCUS_MAX)
|
||||
{
|
||||
_app_data->curr_state_btn = BTN_FREQ;
|
||||
_app_data->isButtonChange = 1;
|
||||
}
|
||||
break;
|
||||
case BTN_FREQ:
|
||||
if (_app_data->freq_focus_digit == 0)
|
||||
{
|
||||
_app_data->curr_state_btn = BTN_FREQ_MIN;
|
||||
_app_data->isButtonChange = 1;
|
||||
}
|
||||
else if (_app_data->freq_focus_digit == FUN_GEN_FOCUS_MAX)
|
||||
{
|
||||
_app_data->curr_state_btn = BTN_FREQ_MAX;
|
||||
_app_data->isButtonChange = 1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void _enterToFreqLayout(void)
|
||||
{
|
||||
_app_data->curr_state_lay = LAY_FREQ;
|
||||
_app_data->curr_state_btn = BTN_FREQ;
|
||||
_blockFocusAtMaxAndMin();
|
||||
|
||||
_app_data->isButtonChange = 1;
|
||||
_app_data->isGraphChange = 1;
|
||||
_app_data->isValueChange = 1;
|
||||
}
|
||||
|
||||
static void _enterToAmplLayout(void)
|
||||
{
|
||||
_app_data->curr_state_lay = LAY_AMPL;
|
||||
_app_data->curr_state_btn = BTN_AMPL;
|
||||
|
||||
_app_data->isButtonChange = 1;
|
||||
_app_data->isGraphChange = 1;
|
||||
_app_data->isValueChange = 1;
|
||||
}
|
||||
|
||||
static void _enterToOffslLayout(void)
|
||||
{
|
||||
_app_data->curr_state_lay = LAY_OFFS;
|
||||
_app_data->curr_state_btn = BTN_OFFS;
|
||||
|
||||
_app_data->isButtonChange = 1;
|
||||
_app_data->isGraphChange = 1;
|
||||
_app_data->isValueChange = 1;
|
||||
}
|
||||
|
||||
static void _enterToPhasLayout(void)
|
||||
{
|
||||
_app_data->curr_state_lay = LAY_PHAS;
|
||||
_app_data->curr_state_btn = BTN_PHAS;
|
||||
|
||||
_app_data->isButtonChange = 1;
|
||||
_app_data->isGraphChange = 1;
|
||||
_app_data->isValueChange = 1;
|
||||
}
|
||||
|
||||
static void _enterToDutyLayout(void)
|
||||
{
|
||||
_app_data->curr_state_lay = LAY_DUTY;
|
||||
_app_data->curr_state_btn = BTN_DUTY;
|
||||
|
||||
_app_data->isButtonChange = 1;
|
||||
_app_data->isGraphChange = 1;
|
||||
_app_data->isValueChange = 1;
|
||||
}
|
||||
|
||||
static void _enterToWavelLayout(void)
|
||||
{
|
||||
_app_data->curr_state_lay = LAY_WAVE;
|
||||
_app_data->curr_state_btn = BTN_WAVE;
|
||||
|
||||
_app_data->isButtonChange = 1;
|
||||
_app_data->isGraphChange = 1;
|
||||
_app_data->isValueChange = 1;
|
||||
}
|
||||
|
||||
static void _moveToLeftFocusFreqNumber(void)
|
||||
{
|
||||
_app_data->freq_focus_digit += 1;
|
||||
_app_data->isValueChange = 1;
|
||||
|
||||
_blockFocusAtMaxAndMin();
|
||||
_app_data->timer_blink[last_key] = 2;
|
||||
_app_data->isButtonBlink |= (1 << last_key);
|
||||
}
|
||||
|
||||
static void _moveToRighttFocusFreqNumber(void)
|
||||
{
|
||||
_app_data->freq_focus_digit -= 1;
|
||||
_app_data->isValueChange = 1;
|
||||
|
||||
_blockFocusAtMaxAndMin();
|
||||
_app_data->timer_blink[last_key] = 2;
|
||||
_app_data->isButtonBlink |= (1 << last_key);
|
||||
}
|
||||
|
||||
static void _setTo0_01xFocusNumber(void)
|
||||
{
|
||||
switch (_app_data->curr_state_lay)
|
||||
{
|
||||
case LAY_AMPL:
|
||||
_app_data->ampl_focus_digit = 0;
|
||||
break;
|
||||
case LAY_OFFS:
|
||||
_app_data->offs_focus_digit = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
_app_data->timer_blink[last_key] = 2;
|
||||
_app_data->isButtonBlink |= (1 << last_key);
|
||||
_app_data->isValueChange = 1;
|
||||
}
|
||||
static void _setTo0_1xFocusNumber(void)
|
||||
{
|
||||
switch (_app_data->curr_state_lay)
|
||||
{
|
||||
case LAY_AMPL:
|
||||
_app_data->ampl_focus_digit = 1;
|
||||
break;
|
||||
case LAY_OFFS:
|
||||
_app_data->offs_focus_digit = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
_app_data->timer_blink[last_key] = 2;
|
||||
_app_data->isButtonBlink |= (1 << last_key);
|
||||
_app_data->isValueChange = 1;
|
||||
}
|
||||
static void _setTo1xFocusNumber(void)
|
||||
{
|
||||
switch (_app_data->curr_state_lay)
|
||||
{
|
||||
case LAY_AMPL:
|
||||
_app_data->ampl_focus_digit = 2;
|
||||
break;
|
||||
case LAY_OFFS:
|
||||
_app_data->offs_focus_digit = 2;
|
||||
break;
|
||||
case LAY_PHAS:
|
||||
_app_data->phas_focus_digit = 0;
|
||||
break;
|
||||
case LAY_DUTY:
|
||||
_app_data->duty_focus_digit = 0;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
_app_data->timer_blink[last_key] = 2;
|
||||
_app_data->isButtonBlink |= (1 << last_key);
|
||||
_app_data->isValueChange = 1;
|
||||
}
|
||||
static void _setTo10xFocusNumber(void)
|
||||
{
|
||||
switch (_app_data->curr_state_lay)
|
||||
{
|
||||
case LAY_AMPL:
|
||||
_app_data->ampl_focus_digit = 3;
|
||||
break;
|
||||
case LAY_OFFS:
|
||||
_app_data->offs_focus_digit = 3;
|
||||
break;
|
||||
case LAY_PHAS:
|
||||
_app_data->phas_focus_digit = 1;
|
||||
break;
|
||||
case LAY_DUTY:
|
||||
_app_data->duty_focus_digit = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
_app_data->timer_blink[last_key] = 2;
|
||||
_app_data->isButtonBlink |= (1 << last_key);
|
||||
_app_data->isValueChange = 1;
|
||||
}
|
||||
|
||||
static const CMD_button_t btn_command[BTN_STATE_MAX][DISP_BTN_MAX] = {
|
||||
{
|
||||
// BTN_MAIN_FG
|
||||
{_enterToFreqLayout, BITMAP_BTN_FREQ},
|
||||
{_enterToAmplLayout, BITMAP_BTN_AMPL},
|
||||
{_enterToOffslLayout, BITMAP_BTN_OFFS},
|
||||
{_enterToPhasLayout, BITMAP_BTN_PHAS},
|
||||
{_enterToWavelLayout, BITMAP_BTN_WAVE},
|
||||
},
|
||||
{
|
||||
// BTN_MAIN_PWM
|
||||
{_enterToFreqLayout, BITMAP_BTN_FREQ},
|
||||
{_enterToAmplLayout, BITMAP_BTN_AMPL},
|
||||
{_enterToOffslLayout, BITMAP_BTN_OFFS},
|
||||
{_enterToPhasLayout, BITMAP_BTN_PHAS},
|
||||
{_enterToDutyLayout, BITMAP_BTN_NONE},
|
||||
},
|
||||
{
|
||||
// BTN_FREQ
|
||||
{_moveToLeftFocusFreqNumber, BITMAP_BTN_LEFT},
|
||||
{_moveToRighttFocusFreqNumber, BITMAP_BTN_RIGHT},
|
||||
{_doNoting, BITMAP_BTN_NONE},
|
||||
{_doNoting, BITMAP_BTN_NONE},
|
||||
{_backToMain, BITMAP_BTN_BACK},
|
||||
},
|
||||
{
|
||||
// BTN_FREQ_MIN
|
||||
{_moveToLeftFocusFreqNumber, BITMAP_BTN_LEFT},
|
||||
{_doNoting, BITMAP_BTN_EMPTY},
|
||||
{_doNoting, BITMAP_BTN_NONE},
|
||||
{_doNoting, BITMAP_BTN_NONE},
|
||||
{_backToMain, BITMAP_BTN_BACK},
|
||||
},
|
||||
{
|
||||
// BTN_FREQ_MAX
|
||||
{_doNoting, BITMAP_BTN_EMPTY},
|
||||
{_moveToRighttFocusFreqNumber, BITMAP_BTN_RIGHT},
|
||||
{_doNoting, BITMAP_BTN_NONE},
|
||||
{_doNoting, BITMAP_BTN_NONE},
|
||||
{_backToMain, BITMAP_BTN_BACK},
|
||||
},
|
||||
{
|
||||
// BTN_AMPL
|
||||
{_setTo1xFocusNumber, BITMAP_BTN_X1},
|
||||
{_setTo0_1xFocusNumber, BITMAP_BTN_X0_1},
|
||||
{_setTo0_01xFocusNumber, BITMAP_BTN_X0_01},
|
||||
{_doNoting, BITMAP_BTN_NONE},
|
||||
{_backToMain, BITMAP_BTN_BACK},
|
||||
},
|
||||
{
|
||||
// BTN_OFFS
|
||||
{_setTo1xFocusNumber, BITMAP_BTN_X1},
|
||||
{_setTo0_1xFocusNumber, BITMAP_BTN_X0_1},
|
||||
{_setTo0_01xFocusNumber, BITMAP_BTN_X0_01},
|
||||
{_doNoting, BITMAP_BTN_NONE},
|
||||
{_backToMain, BITMAP_BTN_BACK},
|
||||
},
|
||||
{
|
||||
// BTN_PHAS
|
||||
{_setTo10xFocusNumber, BITMAP_BTN_X10},
|
||||
{_setTo1xFocusNumber, BITMAP_BTN_X1},
|
||||
{_doNoting, BITMAP_BTN_NONE},
|
||||
{_doNoting, BITMAP_BTN_NONE},
|
||||
{_backToMain, BITMAP_BTN_BACK},
|
||||
},
|
||||
{
|
||||
// BTN_DUTY
|
||||
{_setTo10xFocusNumber, BITMAP_BTN_X10},
|
||||
{_setTo1xFocusNumber, BITMAP_BTN_X1},
|
||||
{_doNoting, BITMAP_BTN_NONE},
|
||||
{_doNoting, BITMAP_BTN_NONE},
|
||||
{_backToMain, BITMAP_BTN_BACK},
|
||||
},
|
||||
{
|
||||
// BTN_WAVE
|
||||
{_doNoting, BITMAP_BTN_NONE},
|
||||
{_doNoting, BITMAP_BTN_NONE},
|
||||
{_doNoting, BITMAP_BTN_NONE},
|
||||
{_doNoting, BITMAP_BTN_NONE},
|
||||
{_backToMain, BITMAP_BTN_BACK},
|
||||
},
|
||||
|
||||
};
|
||||
63
firmware/shared_libs/controllers/ctrl_app.h
Normal file
63
firmware/shared_libs/controllers/ctrl_app.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
#include "hw_button.h"
|
||||
#include "bitmap_disp_buttons.h"
|
||||
#include "ctrl_app_types.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t frequency;
|
||||
uint16_t amplitude;
|
||||
int16_t offset;
|
||||
uint16_t phase;
|
||||
uint8_t duty;
|
||||
uint8_t enabled;
|
||||
} GEN_pwm_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t frequency;
|
||||
uint16_t amplitude;
|
||||
int16_t offset;
|
||||
uint16_t phase;
|
||||
uint8_t wave;
|
||||
uint8_t enabled;
|
||||
uint8_t link;
|
||||
} GEN_fg_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GEN_type_t gen_type;
|
||||
void *const gen;
|
||||
} GENERATOR_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint8_t freq_focus_digit;
|
||||
uint8_t ampl_focus_digit;
|
||||
uint8_t offs_focus_digit;
|
||||
uint8_t phas_focus_digit;
|
||||
uint8_t duty_focus_digit;
|
||||
|
||||
GEN_type_t curr_gen_type;
|
||||
void *generator;
|
||||
|
||||
GEN_channel_t curr_channel;
|
||||
STATE_layout_t curr_state_lay;
|
||||
STATE_button_t curr_state_btn;
|
||||
|
||||
uint8_t isChannelChange;
|
||||
uint8_t isGraphChange;
|
||||
uint8_t isValueChange;
|
||||
uint8_t isButtonChange;
|
||||
uint8_t isButtonBlink;
|
||||
uint8_t timer_blink[DISP_BTN_MAX];
|
||||
|
||||
} APP_data_t;
|
||||
|
||||
void APP_init(APP_data_t *app_data);
|
||||
void CTRL_buttonsInit(void);
|
||||
void CTRL_buttonsHandler(void);
|
||||
void CTRL_pushedDispBtnEvent(ButtonKey_t *key);
|
||||
void CTRL_pushedChanBtnEvent(ButtonKey_t *key);
|
||||
void CTRL_encoderEvent(int8_t enc);
|
||||
BITMAP_buttonName_t CTRL_getBitmapName(LAY_dispBtn_t disp_btn);
|
||||
72
firmware/shared_libs/controllers/ctrl_app_types.h
Normal file
72
firmware/shared_libs/controllers/ctrl_app_types.h
Normal file
@@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
#define FUN_GEN_FOCUS_MAX 6U
|
||||
#define PWM_GEN_FOCUS_MAX 4U
|
||||
#define MAX_FREQ 1000000U
|
||||
#define MAX_VOLT_POS 500
|
||||
#define MAX_VOLT_NEG -500
|
||||
#define MAX_PHAS 360
|
||||
#define MAX_DUTY 100
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GEN_FG_TYPE,
|
||||
GEN_PWM_TYPE,
|
||||
GEN_TYPE_MAX
|
||||
} GEN_type_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CHANNEL1,
|
||||
CHANNEL2,
|
||||
CHANNEL3,
|
||||
CHANNEL4,
|
||||
CHANNEL5,
|
||||
CHANNEL6,
|
||||
CHANNEL_MAX
|
||||
} GEN_channel_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GEN_SIN,
|
||||
GEN_TRI,
|
||||
GEN_SQR,
|
||||
GEN_WAVE_MAX,
|
||||
} GEN_wave_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LAY_MAIN,
|
||||
LAY_FREQ,
|
||||
LAY_AMPL,
|
||||
LAY_OFFS,
|
||||
LAY_PHAS,
|
||||
LAY_DUTY,
|
||||
LAY_WAVE,
|
||||
LAY_STATE_MAX
|
||||
} STATE_layout_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BTN_MAIN_FG,
|
||||
BTN_MAIN_PWM,
|
||||
BTN_FREQ,
|
||||
BTN_FREQ_MIN,
|
||||
BTN_FREQ_MAX,
|
||||
BTN_AMPL,
|
||||
BTN_OFFS,
|
||||
BTN_PHAS,
|
||||
BTN_DUTY,
|
||||
BTN_WAVE,
|
||||
BTN_STATE_MAX
|
||||
} STATE_button_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DISP_BTN_1,
|
||||
DISP_BTN_2,
|
||||
DISP_BTN_3,
|
||||
DISP_BTN_4,
|
||||
DISP_BTN_5,
|
||||
DISP_BTN_MAX,
|
||||
} LAY_dispBtn_t;
|
||||
60
firmware/shared_libs/controllers/ctrl_bottom_button.c
Normal file
60
firmware/shared_libs/controllers/ctrl_bottom_button.c
Normal file
@@ -0,0 +1,60 @@
|
||||
#include "main.h"
|
||||
#include "hw_button.h"
|
||||
// #include "ctrl_app.h"
|
||||
#include "ctrl_bottom_button.h"
|
||||
|
||||
static ButtonKey_t bottom_buttons[BTN_BOT_MAX];
|
||||
|
||||
void CTRL_bottomButtonInit(void)
|
||||
{
|
||||
bottom_buttons[BTN_BOT_1].instance = BTN_BOT_1;
|
||||
bottom_buttons[BTN_BOT_1].buttonPressed = CTRL_pushedDispBtnEvent;
|
||||
bottom_buttons[BTN_BOT_1].gpio_port = BTN1_GPIO_Port;
|
||||
bottom_buttons[BTN_BOT_1].gpio_pin = BTN1_Pin;
|
||||
bottom_buttons[BTN_BOT_1].pushed_state = GPIO_PIN_SET;
|
||||
|
||||
bottom_buttons[BTN_BOT_2].instance = BTN_BOT_2;
|
||||
bottom_buttons[BTN_BOT_2].buttonPressed = CTRL_pushedDispBtnEvent;
|
||||
bottom_buttons[BTN_BOT_2].gpio_port = BTN2_GPIO_Port;
|
||||
bottom_buttons[BTN_BOT_2].gpio_pin = BTN2_Pin;
|
||||
bottom_buttons[BTN_BOT_2].pushed_state = GPIO_PIN_SET;
|
||||
|
||||
bottom_buttons[BTN_BOT_3].instance = BTN_BOT_3;
|
||||
bottom_buttons[BTN_BOT_3].buttonPressed = CTRL_pushedDispBtnEvent;
|
||||
bottom_buttons[BTN_BOT_3].gpio_port = BTN3_GPIO_Port;
|
||||
bottom_buttons[BTN_BOT_3].gpio_pin = BTN3_Pin;
|
||||
bottom_buttons[BTN_BOT_3].pushed_state = GPIO_PIN_SET;
|
||||
|
||||
bottom_buttons[BTN_BOT_4].instance = BTN_BOT_4;
|
||||
bottom_buttons[BTN_BOT_4].buttonPressed = CTRL_pushedDispBtnEvent;
|
||||
bottom_buttons[BTN_BOT_4].gpio_port = BTN4_GPIO_Port;
|
||||
bottom_buttons[BTN_BOT_4].gpio_pin = BTN4_Pin;
|
||||
bottom_buttons[BTN_BOT_4].pushed_state = GPIO_PIN_SET;
|
||||
|
||||
bottom_buttons[BTN_BOT_5].instance = BTN_BOT_5;
|
||||
bottom_buttons[BTN_BOT_5].buttonPressed = CTRL_pushedDispBtnEvent;
|
||||
bottom_buttons[BTN_BOT_5].gpio_port = BTN5_GPIO_Port;
|
||||
bottom_buttons[BTN_BOT_5].gpio_pin = BTN5_Pin;
|
||||
bottom_buttons[BTN_BOT_5].pushed_state = GPIO_PIN_SET;
|
||||
|
||||
for (HW_BotBtnName_t btn_key = BTN_BOT_1; btn_key < BTN_BOT_MAX; btn_key++)
|
||||
{
|
||||
bottom_buttons[btn_key].state = IDLE;
|
||||
bottom_buttons[btn_key].timer_debounce = BTN_DEFAULT_DEBOUNCE_MS;
|
||||
bottom_buttons[btn_key].timer_long_pressed = BTN_DEFAULT_LONGPRESSED_MS;
|
||||
bottom_buttons[btn_key].timer_repeat_delay = BTN_DEFAULT_REPEAT_MS;
|
||||
}
|
||||
}
|
||||
|
||||
void CTRL_bottomButtonsHandler(void)
|
||||
{
|
||||
for (HW_BotBtnName_t btn_key = BTN_BOT_1; btn_key < BTN_BOT_MAX; btn_key++)
|
||||
{
|
||||
buttonHandler(&bottom_buttons[btn_key]);
|
||||
}
|
||||
}
|
||||
|
||||
__weak void CTRL_pushedDispBtnEvent(ButtonKey_t *key)
|
||||
{
|
||||
UNUSED(key);
|
||||
}
|
||||
15
firmware/shared_libs/controllers/ctrl_bottom_button.h
Normal file
15
firmware/shared_libs/controllers/ctrl_bottom_button.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BTN_BOT_1,
|
||||
BTN_BOT_2,
|
||||
BTN_BOT_3,
|
||||
BTN_BOT_4,
|
||||
BTN_BOT_5,
|
||||
BTN_BOT_MAX,
|
||||
} HW_BotBtnName_t;
|
||||
|
||||
void CTRL_bottomButtonInit(void);
|
||||
void CTRL_bottomButtonsHandler(void);
|
||||
void CTRL_pushedDispBtnEvent(ButtonKey_t *key);
|
||||
68
firmware/shared_libs/controllers/ctrl_channel_button.c
Normal file
68
firmware/shared_libs/controllers/ctrl_channel_button.c
Normal file
@@ -0,0 +1,68 @@
|
||||
#include "main.h"
|
||||
#include "hw_button.h"
|
||||
#include "ctrl_channel_button.h"
|
||||
|
||||
#define DUMMY_GPIO_Port GPIOA
|
||||
#define DUMMY_GPIO_Pin GPIO_PIN_0
|
||||
|
||||
static ButtonKey_t channel_buttons[BTN_CH_MAX];
|
||||
|
||||
void CTRL_channelButtonInit(void)
|
||||
{
|
||||
channel_buttons[BTN_CH_1].instance = BTN_CH_1;
|
||||
channel_buttons[BTN_CH_1].buttonPressed = CTRL_pushedChanBtnEvent;
|
||||
channel_buttons[BTN_CH_1].gpio_port = DUMMY_GPIO_Port;
|
||||
channel_buttons[BTN_CH_1].gpio_pin = DUMMY_GPIO_Pin;
|
||||
channel_buttons[BTN_CH_1].pushed_state = GPIO_PIN_SET;
|
||||
|
||||
channel_buttons[BTN_CH_2].instance = BTN_CH_2;
|
||||
channel_buttons[BTN_CH_2].buttonPressed = CTRL_pushedChanBtnEvent;
|
||||
channel_buttons[BTN_CH_2].gpio_port = DUMMY_GPIO_Port;
|
||||
channel_buttons[BTN_CH_2].gpio_pin = DUMMY_GPIO_Pin;
|
||||
channel_buttons[BTN_CH_2].pushed_state = GPIO_PIN_SET;
|
||||
|
||||
channel_buttons[BTN_CH_3].instance = BTN_CH_3;
|
||||
channel_buttons[BTN_CH_3].buttonPressed = CTRL_pushedChanBtnEvent;
|
||||
channel_buttons[BTN_CH_3].gpio_port = DUMMY_GPIO_Port;
|
||||
channel_buttons[BTN_CH_3].gpio_pin = DUMMY_GPIO_Pin;
|
||||
channel_buttons[BTN_CH_3].pushed_state = GPIO_PIN_SET;
|
||||
|
||||
channel_buttons[BTN_CH_4].instance = BTN_CH_4;
|
||||
channel_buttons[BTN_CH_4].buttonPressed = CTRL_pushedChanBtnEvent;
|
||||
channel_buttons[BTN_CH_4].gpio_port = DUMMY_GPIO_Port;
|
||||
channel_buttons[BTN_CH_4].gpio_pin = DUMMY_GPIO_Pin;
|
||||
channel_buttons[BTN_CH_4].pushed_state = GPIO_PIN_SET;
|
||||
|
||||
channel_buttons[BTN_CH_5].instance = BTN_CH_5;
|
||||
channel_buttons[BTN_CH_5].buttonPressed = CTRL_pushedChanBtnEvent;
|
||||
channel_buttons[BTN_CH_5].gpio_port = DUMMY_GPIO_Port;
|
||||
channel_buttons[BTN_CH_5].gpio_pin = DUMMY_GPIO_Pin;
|
||||
channel_buttons[BTN_CH_5].pushed_state = GPIO_PIN_SET;
|
||||
|
||||
channel_buttons[BTN_CH_6].instance = BTN_CH_6;
|
||||
channel_buttons[BTN_CH_6].buttonPressed = CTRL_pushedChanBtnEvent;
|
||||
channel_buttons[BTN_CH_6].gpio_port = DUMMY_GPIO_Port;
|
||||
channel_buttons[BTN_CH_6].gpio_pin = DUMMY_GPIO_Pin;
|
||||
channel_buttons[BTN_CH_6].pushed_state = GPIO_PIN_SET;
|
||||
|
||||
for (HW_chanBtnName_t btn_key = BTN_CH_1; btn_key < BTN_CH_MAX; btn_key++)
|
||||
{
|
||||
channel_buttons[btn_key].state = IDLE;
|
||||
channel_buttons[btn_key].timer_debounce = BTN_DEFAULT_DEBOUNCE_MS;
|
||||
channel_buttons[btn_key].timer_long_pressed = BTN_DEFAULT_LONGPRESSED_MS;
|
||||
channel_buttons[btn_key].timer_repeat_delay = BTN_DEFAULT_REPEAT_MS;
|
||||
}
|
||||
}
|
||||
|
||||
void CTRL_channelButtonsHandler(void)
|
||||
{
|
||||
for (HW_chanBtnName_t btn_key = BTN_CH_1; btn_key < BTN_CH_MAX; btn_key++)
|
||||
{
|
||||
buttonHandler(&channel_buttons[btn_key]);
|
||||
}
|
||||
}
|
||||
|
||||
__weak void CTRL_pushedChanBtnEvent(ButtonKey_t *key)
|
||||
{
|
||||
UNUSED(key);
|
||||
}
|
||||
16
firmware/shared_libs/controllers/ctrl_channel_button.h
Normal file
16
firmware/shared_libs/controllers/ctrl_channel_button.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BTN_CH_1,
|
||||
BTN_CH_2,
|
||||
BTN_CH_3,
|
||||
BTN_CH_4,
|
||||
BTN_CH_5,
|
||||
BTN_CH_6,
|
||||
BTN_CH_MAX,
|
||||
} HW_chanBtnName_t;
|
||||
|
||||
void CTRL_channelButtonInit(void);
|
||||
void CTRL_channelButtonsHandler(void);
|
||||
void CTRL_pushedChanBtnEvent(ButtonKey_t *key);
|
||||
16
firmware/shared_libs/controllers/ctrl_encoder.c
Normal file
16
firmware/shared_libs/controllers/ctrl_encoder.c
Normal file
@@ -0,0 +1,16 @@
|
||||
#include "main.h"
|
||||
#include "tim.h"
|
||||
#include "ctrl_app.h"
|
||||
|
||||
void CTRL_encoderHandler(void)
|
||||
{
|
||||
static uint8_t cnt;
|
||||
if (htim3.Instance->CNT == cnt || htim3.Instance->CNT % 2 == 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// SEGGER_RTT_printf(0, "TIM3.cnt: %d\n", htim3.Instance->CNT);
|
||||
CTRL_encoderEvent(htim3.Instance->CNT - cnt);
|
||||
cnt = (uint8_t)htim3.Instance->CNT;
|
||||
}
|
||||
3
firmware/shared_libs/controllers/ctrl_encoder.h
Normal file
3
firmware/shared_libs/controllers/ctrl_encoder.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
void CTRL_encoderHandler(void);
|
||||
343
firmware/shared_libs/disp_layout/disp_layout.c
Normal file
343
firmware/shared_libs/disp_layout/disp_layout.c
Normal file
@@ -0,0 +1,343 @@
|
||||
#include "main.h"
|
||||
#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"
|
||||
|
||||
#define ABS(x) ((x) < 0 ? -(x) : (x))
|
||||
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
|
||||
|
||||
#define SEVEN_DIGIT 7
|
||||
#define FOUR_DIGIT 3
|
||||
#define THREE_DIGIT 2
|
||||
|
||||
const uint8_t btn_pos_x[DISP_BTN_MAX] = {0, 26, 52, 78, 104};
|
||||
const uint8_t marker_pos_7dig[SEVEN_DIGIT] = {76, 84, 90, 96, 105, 111, 118};
|
||||
const uint8_t marker_pos_4dig[FOUR_DIGIT] = {82, 94, 100};
|
||||
const uint8_t marker_pos_3dig[THREE_DIGIT] = {82, 88};
|
||||
|
||||
// clang-format off
|
||||
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
|
||||
|
||||
static void _drawFreqValue(GFX_display_t *disp, uint32_t freq, uint8_t pos_y)
|
||||
{
|
||||
uint8_t data[8];
|
||||
snprintf((char *)data, 8, "%07u", freq);
|
||||
DISP_writeString(disp, &font5x7Info, (uint8_t[]){data[0], 0}, 76, pos_y, BM_NORMAL);
|
||||
DISP_writeString(disp, &font5x7Info, (uint8_t[]){data[1], data[2], data[3], 0}, 84, pos_y, BM_NORMAL);
|
||||
DISP_writeString(disp, &font5x7Info, (uint8_t[]){data[4], data[5], data[6], 0}, 105, pos_y, BM_NORMAL);
|
||||
}
|
||||
|
||||
static void _drawAmplValue(GFX_display_t *disp, uint16_t ampl, uint8_t pos_y)
|
||||
{
|
||||
uint8_t data[8];
|
||||
snprintf((char *)data, 8, "%02d.%02d V", ampl / 100, ampl % 100);
|
||||
DISP_writeString(disp, &font5x7Info, data, 76, pos_y, BM_NORMAL);
|
||||
}
|
||||
|
||||
static void _drawOffsValue(GFX_display_t *disp, int16_t offs, uint8_t pos_y)
|
||||
{
|
||||
uint8_t data[8];
|
||||
snprintf((char *)data, 8, "%+01d.%02d V", offs / 100, ABS(offs) % 100);
|
||||
if (offs < 0)
|
||||
{
|
||||
data[0] = '-';
|
||||
}
|
||||
DISP_writeString(disp, &font5x7Info, data, 76, pos_y, BM_NORMAL);
|
||||
}
|
||||
|
||||
static void _drawPhasValue(GFX_display_t *disp, uint16_t phase, uint8_t pos_y)
|
||||
{
|
||||
uint8_t data[8];
|
||||
snprintf((char *)data, 8, "%03u'", phase);
|
||||
DISP_writeString(disp, &font5x7Info, data, 76, pos_y, BM_NORMAL);
|
||||
}
|
||||
|
||||
// static void _drawDutyValue(GFX_display_t *disp, uint8_t duty, uint8_t pos_y)
|
||||
// {
|
||||
// uint8_t data[8];
|
||||
// snprintf((char *)data, 8, "%03u%%", duty);
|
||||
// DISP_writeString(disp, &font5x7Info, data, 76, pos_y, BM_NORMAL);
|
||||
// }
|
||||
|
||||
static void _blinkButtons(GFX_display_t *disp, APP_data_t *app_data)
|
||||
{
|
||||
// input: display buttons, invert
|
||||
BITMAP_buttonName_t bitmap_idx;
|
||||
for (LAY_dispBtn_t btn_idx = DISP_BTN_1; btn_idx < DISP_BTN_MAX; btn_idx++)
|
||||
{
|
||||
if (!(app_data->isButtonBlink & (1 << btn_idx)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
bitmap_idx = CTRL_getBitmapName(btn_idx);
|
||||
if (app_data->timer_blink[btn_idx] > 0)
|
||||
{
|
||||
DISP_drawBitmap(disp, &bitmap_btnBottom[bitmap_idx + 1], btn_pos_x[btn_idx], 53, BM_NORMAL);
|
||||
app_data->timer_blink[btn_idx]--;
|
||||
}
|
||||
else
|
||||
{
|
||||
DISP_drawBitmap(disp, &bitmap_btnBottom[bitmap_idx], btn_pos_x[btn_idx], 53, BM_NORMAL);
|
||||
app_data->isButtonBlink &= ~(1 << btn_idx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void _drawButtons(GFX_display_t *disp, APP_data_t *app_data)
|
||||
{
|
||||
// input: display buttons, invert
|
||||
BITMAP_buttonName_t bitmap_idx;
|
||||
DISP_clearRegion(disp, 0, 53, disp->width, 11);
|
||||
|
||||
for (LAY_dispBtn_t btn_idx = DISP_BTN_1; btn_idx < DISP_BTN_MAX; btn_idx++)
|
||||
{
|
||||
bitmap_idx = CTRL_getBitmapName(btn_idx);
|
||||
DISP_drawBitmap(disp, &bitmap_btnBottom[bitmap_idx], btn_pos_x[btn_idx], 53, BM_NORMAL);
|
||||
}
|
||||
|
||||
app_data->isButtonChange = 0;
|
||||
}
|
||||
|
||||
static uint8_t _calcMarkerPos(uint32_t value, uint32_t max)
|
||||
{
|
||||
return ((61 * 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;
|
||||
while (*array++)
|
||||
{
|
||||
size++;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
static void _drawMeterHelper(GFX_display_t *disp, char *min, char *max, uint8_t pos)
|
||||
{
|
||||
uint8_t max_size = _sizeOfCharArray(max);
|
||||
DISP_drawPixel(disp, 64, 40, GFX_WHITE);
|
||||
DISP_drawPixel(disp, 125, 40, GFX_WHITE);
|
||||
DISP_drawHorizontalLine(disp, 64, 41, 62, GFX_WHITE);
|
||||
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_down, 62 + pos, 35, BM_NORMAL);
|
||||
}
|
||||
|
||||
static void _drawFreqValueHelper(GFX_display_t *disp, uint32_t freq, uint8_t focus_digit)
|
||||
{
|
||||
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_down, marker_pos_7dig[(SEVEN_DIGIT - 1) - focus_digit], 15, BM_NORMAL);
|
||||
}
|
||||
|
||||
static void _drawAmplValueHelper(GFX_display_t *disp, uint32_t ampl, uint8_t focus_digit)
|
||||
{
|
||||
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_down, marker_pos_4dig[(FOUR_DIGIT - 1) - focus_digit], 15, BM_NORMAL);
|
||||
}
|
||||
|
||||
static void _drawOffsValueHelper(GFX_display_t *disp, int32_t offs, uint8_t focus_digit)
|
||||
{
|
||||
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_down, marker_pos_4dig[(FOUR_DIGIT - 1) - focus_digit], 15, BM_NORMAL);
|
||||
}
|
||||
|
||||
static void _drawPhaseValueHelper(GFX_display_t *disp, uint32_t phase, uint8_t focus_digit)
|
||||
{
|
||||
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_down, marker_pos_3dig[(THREE_DIGIT - 1) - focus_digit], 15, BM_NORMAL);
|
||||
}
|
||||
|
||||
static void _drawFuncGenValues(GFX_display_t *disp, APP_data_t *app_data)
|
||||
{
|
||||
GEN_fg_t *fun_gen = (GEN_fg_t *)app_data->generator;
|
||||
switch (app_data->curr_state_lay)
|
||||
{
|
||||
case LAY_FREQ:
|
||||
_drawFreqValueHelper(disp, fun_gen->frequency, app_data->freq_focus_digit);
|
||||
_drawMeterHelper(disp, "1", "1M", _calcMarkerPos(fun_gen->frequency, MAX_FREQ));
|
||||
break;
|
||||
case LAY_AMPL:
|
||||
_drawAmplValueHelper(disp, fun_gen->amplitude, app_data->ampl_focus_digit);
|
||||
_drawMeterHelper(disp, "0V", "5V", _calcMarkerPos(fun_gen->amplitude, MAX_VOLT_POS));
|
||||
break;
|
||||
case LAY_OFFS:
|
||||
_drawOffsValueHelper(disp, fun_gen->offset, app_data->offs_focus_digit);
|
||||
_drawMeterHelper(disp, "-5V", "+5V", _calcMarkerPos(MAX_VOLT_POS + fun_gen->offset, MAX_VOLT_POS * 2));
|
||||
break;
|
||||
case LAY_PHAS:
|
||||
_drawPhaseValueHelper(disp, fun_gen->phase, app_data->phas_focus_digit);
|
||||
_drawMeterHelper(disp, "0", "360", _calcMarkerPos(fun_gen->phase, MAX_PHAS));
|
||||
break;
|
||||
case LAY_MAIN:
|
||||
DISP_clearRegion(disp, 62, 13, 66, 40);
|
||||
DISP_writeString(disp, &font5x7Info, (uint8_t *)"F:", 64, 13, BM_NORMAL);
|
||||
DISP_writeString(disp, &font5x7Info, (uint8_t *)"A:", 64, 23, BM_NORMAL);
|
||||
DISP_writeString(disp, &font5x7Info, (uint8_t *)"O:", 64, 33, BM_NORMAL);
|
||||
DISP_writeString(disp, &font5x7Info, (uint8_t *)"P:", 64, 43, BM_NORMAL);
|
||||
|
||||
_drawFreqValue(disp, fun_gen->frequency, 13);
|
||||
_drawAmplValue(disp, fun_gen->amplitude, 23);
|
||||
_drawOffsValue(disp, fun_gen->offset, 33);
|
||||
_drawPhasValue(disp, fun_gen->phase, 43);
|
||||
break;
|
||||
|
||||
default:
|
||||
// focus
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void _drawPwmGenValues(GFX_display_t *disp, APP_data_t *app_data)
|
||||
{
|
||||
// GEN_pwm_t *pwm_gen = app_data->generator;
|
||||
}
|
||||
|
||||
static void _drawValues(GFX_display_t *disp, APP_data_t *app_data)
|
||||
{
|
||||
// input: frequency(value), amplitiude(value), offset(value), phase(value), duty(value), invert(info), position(value)
|
||||
switch (app_data->curr_gen_type)
|
||||
{
|
||||
case GEN_FG_TYPE:
|
||||
_drawFuncGenValues(disp, app_data);
|
||||
break;
|
||||
case GEN_PWM_TYPE:
|
||||
_drawPwmGenValues(disp, app_data);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
app_data->isValueChange = 0;
|
||||
}
|
||||
|
||||
static void _drawOffsetLine(GFX_display_t *disp, int16_t offs, uint32_t ampl)
|
||||
{
|
||||
int8_t vert_shift = _calcVerticalShiftInPxl(offs, ampl);
|
||||
|
||||
vert_shift = MIN(vert_shift, 20);
|
||||
vert_shift = MAX(vert_shift, -19);
|
||||
|
||||
ULOG_TRACE("<OFFSLINE> shift: %i", vert_shift);
|
||||
DISP_drawHorizontalLine(disp, 2, 31 + vert_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;
|
||||
DISP_clearRegion(disp, 3, 12, 57, 40);
|
||||
|
||||
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_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;
|
||||
}
|
||||
|
||||
static void _drawChannels(GFX_display_t *disp, APP_data_t *app_data)
|
||||
{
|
||||
// input: active channel
|
||||
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);
|
||||
DISP_writeString(disp, &font5x7Info, (uint8_t *)"CH5", 86, 2, CHANNEL5 == app_data->curr_channel ? BM_INVERSE : BM_NORMAL);
|
||||
DISP_writeString(disp, &font5x7Info, (uint8_t *)"CH6", 107, 2, CHANNEL6 == app_data->curr_channel ? BM_INVERSE : BM_NORMAL);
|
||||
DISP_drawHorizontalLine(disp, 0, 10, 127, GFX_WHITE);
|
||||
|
||||
app_data->isChannelChange = 0;
|
||||
}
|
||||
|
||||
void LAY_drawDisplayLayout(GFX_display_t *disp, APP_data_t *app_data)
|
||||
{
|
||||
if (app_data->isChannelChange)
|
||||
_drawChannels(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);
|
||||
|
||||
if (app_data->isButtonBlink)
|
||||
_blinkButtons(disp, app_data);
|
||||
}
|
||||
6
firmware/shared_libs/disp_layout/disp_layout.h
Normal file
6
firmware/shared_libs/disp_layout/disp_layout.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "display_gfx.h"
|
||||
#include "ctrl_app.h"
|
||||
|
||||
void LAY_drawDisplayLayout(GFX_display_t *disp, APP_data_t *app_data);
|
||||
@@ -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++)
|
||||
{
|
||||
@@ -347,7 +372,7 @@ static inline uint8_t _getBitmapByte(const uint8_t *bitmap, uint16_t index, GFX_
|
||||
* @param pos_y Top left corner y coordinate
|
||||
* @param color Color of pixel BM_NORMAL or BM_INVERSE for bitmap. BM_WHITE or BM_BLACK for fill region.
|
||||
*/
|
||||
void DISP_drawBitmap(GFX_display_t *disp, GFX_bitmap_t *bitmap, int8_t pos_x, int8_t pos_y, GFX_BitmapColor_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)
|
||||
{
|
||||
if (bitmap->width + pos_x < 0 || bitmap->height + pos_y < 0)
|
||||
return;
|
||||
@@ -396,6 +421,56 @@ void DISP_drawBitmap(GFX_display_t *disp, GFX_bitmap_t *bitmap, int8_t pos_x, in
|
||||
}
|
||||
}
|
||||
|
||||
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 = {
|
||||
|
||||
@@ -51,13 +51,16 @@ 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);
|
||||
void DISP_drawCircle(GFX_display_t *disp, int16_t x0, int16_t y0, uint8_t radius, GFX_Color_t color);
|
||||
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, GFX_bitmap_t *bitmap, int8_t pos_x, int8_t pos_y, GFX_BitmapColor_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);
|
||||
|
||||
154
firmware/shared_libs/utils/ulog/ulog.c
Normal file
154
firmware/shared_libs/utils/ulog/ulog.c
Normal file
@@ -0,0 +1,154 @@
|
||||
/**
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 R. Dunbar Poor <rdpoor@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file ulog.c
|
||||
*
|
||||
* \brief uLog: lightweight logging for embedded systems
|
||||
*
|
||||
* See ulog.h for sparse documentation.
|
||||
*/
|
||||
|
||||
#include "ulog.h"
|
||||
|
||||
#ifdef ULOG_ENABLED // whole file...
|
||||
|
||||
// #include <stdio.h>
|
||||
#include "printf.h"
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
// =============================================================================
|
||||
// types and definitions
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ulog_function_t fn;
|
||||
ulog_level_t threshold;
|
||||
} subscriber_t;
|
||||
|
||||
// =============================================================================
|
||||
// local storage
|
||||
|
||||
static subscriber_t s_subscribers[ULOG_MAX_SUBSCRIBERS];
|
||||
static char s_message[ULOG_MAX_MESSAGE_LENGTH];
|
||||
|
||||
// =============================================================================
|
||||
// user-visible code
|
||||
|
||||
void ulog_init()
|
||||
{
|
||||
memset(s_subscribers, 0, sizeof(s_subscribers));
|
||||
}
|
||||
|
||||
// search the s_subscribers table to install or update fn
|
||||
ulog_err_t ulog_subscribe(ulog_function_t fn, ulog_level_t threshold)
|
||||
{
|
||||
int available_slot = -1;
|
||||
int i;
|
||||
for (i = 0; i < ULOG_MAX_SUBSCRIBERS; i++)
|
||||
{
|
||||
if (s_subscribers[i].fn == fn)
|
||||
{
|
||||
// already subscribed: update threshold and return immediately.
|
||||
s_subscribers[i].threshold = threshold;
|
||||
return ULOG_ERR_NONE;
|
||||
}
|
||||
else if (s_subscribers[i].fn == NULL)
|
||||
{
|
||||
// found a free slot
|
||||
available_slot = i;
|
||||
}
|
||||
}
|
||||
// fn is not yet a subscriber. assign if possible.
|
||||
if (available_slot == -1)
|
||||
{
|
||||
return ULOG_ERR_SUBSCRIBERS_EXCEEDED;
|
||||
}
|
||||
s_subscribers[available_slot].fn = fn;
|
||||
s_subscribers[available_slot].threshold = threshold;
|
||||
return ULOG_ERR_NONE;
|
||||
}
|
||||
|
||||
// search the s_subscribers table to remove
|
||||
ulog_err_t ulog_unsubscribe(ulog_function_t fn)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < ULOG_MAX_SUBSCRIBERS; i++)
|
||||
{
|
||||
if (s_subscribers[i].fn == fn)
|
||||
{
|
||||
s_subscribers[i].fn = NULL; // mark as empty
|
||||
return ULOG_ERR_NONE;
|
||||
}
|
||||
}
|
||||
return ULOG_ERR_NOT_SUBSCRIBED;
|
||||
}
|
||||
|
||||
const char *ulog_level_name(ulog_level_t severity)
|
||||
{
|
||||
switch (severity)
|
||||
{
|
||||
case ULOG_TRACE_LEVEL:
|
||||
return "TRACE";
|
||||
case ULOG_DEBUG_LEVEL:
|
||||
return "DEBUG";
|
||||
case ULOG_INFO_LEVEL:
|
||||
return "INFO";
|
||||
case ULOG_WARNING_LEVEL:
|
||||
return "WARNING";
|
||||
case ULOG_ERROR_LEVEL:
|
||||
return "ERROR";
|
||||
case ULOG_CRITICAL_LEVEL:
|
||||
return "CRITICAL";
|
||||
case ULOG_ALWAYS_LEVEL:
|
||||
return "ALWAYS";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
void ulog_message(ulog_level_t severity, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int i;
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(s_message, ULOG_MAX_MESSAGE_LENGTH, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
for (i = 0; i < ULOG_MAX_SUBSCRIBERS; i++)
|
||||
{
|
||||
if (s_subscribers[i].fn != NULL)
|
||||
{
|
||||
if (severity >= s_subscribers[i].threshold)
|
||||
{
|
||||
s_subscribers[i].fn(severity, s_message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// private code
|
||||
|
||||
#endif // #ifdef ULOG_ENABLED
|
||||
188
firmware/shared_libs/utils/ulog/ulog.h
Normal file
188
firmware/shared_libs/utils/ulog/ulog.h
Normal file
@@ -0,0 +1,188 @@
|
||||
/**
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 R. Dunbar Poor <rdpoor@gmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
*
|
||||
* \brief uLog: lightweight logging for embedded systems
|
||||
*
|
||||
* A quick intro by example:
|
||||
*
|
||||
* #include "ulog.h"
|
||||
*
|
||||
* // To use uLog, you must define a function to process logging messages.
|
||||
* // It can write the messages to a console, to a file, to an in-memory
|
||||
* // buffer: the choice is yours. And you get to choose the format of
|
||||
* // the message. This example prints to the console. One caveat: msg
|
||||
* // is a static string and will be over-written at the next call to ULOG.
|
||||
* // You may print it or copy it, but saving a pointer to it will lead to
|
||||
* // confusion and astonishment.
|
||||
* //
|
||||
* void my_console_logger(ulog_level_t level, const char *msg) {
|
||||
* printf("%s [%s]: %s\n",
|
||||
* get_timestamp(),
|
||||
* ulog_level_name(level),
|
||||
* msg);
|
||||
* }
|
||||
*
|
||||
* int main() {
|
||||
* ULOG_INIT();
|
||||
*
|
||||
* // log to the console messages that are WARNING or more severe. You
|
||||
* // can re-subscribe at any point to change the severity level.
|
||||
* ULOG_SUBSCRIBE(my_console_logger, ULOG_WARNING);
|
||||
*
|
||||
* // log to a file messages that are DEBUG or more severe
|
||||
* ULOG_SUBSCRIBE(my_file_logger, ULOG_DEBUG);
|
||||
*
|
||||
* int arg = 42;
|
||||
* ULOG_INFO("Arg is %d", arg); // logs to file but not console
|
||||
* }
|
||||
*/
|
||||
|
||||
#ifndef ULOG_H_
|
||||
#define ULOG_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ULOG_TRACE_LEVEL = 100,
|
||||
ULOG_DEBUG_LEVEL,
|
||||
ULOG_INFO_LEVEL,
|
||||
ULOG_WARNING_LEVEL,
|
||||
ULOG_ERROR_LEVEL,
|
||||
ULOG_CRITICAL_LEVEL,
|
||||
ULOG_ALWAYS_LEVEL
|
||||
} ulog_level_t;
|
||||
|
||||
// The following macros enable or disable uLog. If `ULOG_ENABLED` is
|
||||
// defined at compile time, a macro such as `ULOG_INFO(...)` expands
|
||||
// into `ulog_message(ULOG_INFO_LEVEL, ...)`. If `ULOG_ENABLED` is not
|
||||
// defined, then the same macro expands into `do {} while(0)` and will
|
||||
// not generate any code at all.
|
||||
//
|
||||
// There are two ways to enable uLog: you can uncomment the following
|
||||
// line, or -- if it is commented out -- you can add -DULOG_ENABLED to
|
||||
// your compiler switches.
|
||||
// #define ULOG_ENABLED
|
||||
|
||||
#ifdef ULOG_ENABLED
|
||||
#define ULOG_INIT() ulog_init()
|
||||
#define ULOG_SUBSCRIBE(a, b) ulog_subscribe(a, b)
|
||||
#define ULOG_UNSUBSCRIBE(a) ulog_unsubscribe(a)
|
||||
#define ULOG_LEVEL_NAME(a) ulog_level_name(a)
|
||||
#define ULOG(...) ulog_message(__VA_ARGS__)
|
||||
#define ULOG_TRACE(...) ulog_message(ULOG_TRACE_LEVEL, __VA_ARGS__)
|
||||
#define ULOG_DEBUG(...) ulog_message(ULOG_DEBUG_LEVEL, __VA_ARGS__)
|
||||
#define ULOG_INFO(...) ulog_message(ULOG_INFO_LEVEL, __VA_ARGS__)
|
||||
#define ULOG_WARNING(...) ulog_message(ULOG_WARNING_LEVEL, __VA_ARGS__)
|
||||
#define ULOG_ERROR(...) ulog_message(ULOG_ERROR_LEVEL, __VA_ARGS__)
|
||||
#define ULOG_CRITICAL(...) ulog_message(ULOG_CRITICAL_LEVEL, __VA_ARGS__)
|
||||
#define ULOG_ALWAYS(...) ulog_message(ULOG_ALWAYS_LEVEL, __VA_ARGS__)
|
||||
#else
|
||||
// uLog vanishes when disabled at compile time...
|
||||
#define ULOG_INIT() \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#define ULOG_SUBSCRIBE(a, b) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#define ULOG_UNSUBSCRIBE(a) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#define ULOG_LEVEL_NAME(a) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#define ULOG(s, f, ...) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#define ULOG_TRACE(f, ...) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#define ULOG_DEBUG(f, ...) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#define ULOG_INFO(f, ...) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#define ULOG_WARNING(f, ...) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#define ULOG_ERROR(f, ...) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#define ULOG_CRITICAL(f, ...) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#define ULOG_ALWAYS(f, ...) \
|
||||
do \
|
||||
{ \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ULOG_ERR_NONE = 0,
|
||||
ULOG_ERR_SUBSCRIBERS_EXCEEDED,
|
||||
ULOG_ERR_NOT_SUBSCRIBED,
|
||||
} ulog_err_t;
|
||||
|
||||
// define the maximum number of concurrent subscribers
|
||||
#ifndef ULOG_MAX_SUBSCRIBERS
|
||||
#define ULOG_MAX_SUBSCRIBERS 6
|
||||
#endif
|
||||
// maximum length of formatted log message
|
||||
#ifndef ULOG_MAX_MESSAGE_LENGTH
|
||||
#define ULOG_MAX_MESSAGE_LENGTH 120
|
||||
#endif
|
||||
/**
|
||||
* @brief: prototype for uLog subscribers.
|
||||
*/
|
||||
typedef void (*ulog_function_t)(ulog_level_t severity, char *msg);
|
||||
|
||||
void ulog_init(void);
|
||||
ulog_err_t ulog_subscribe(ulog_function_t fn, ulog_level_t threshold);
|
||||
ulog_err_t ulog_unsubscribe(ulog_function_t fn);
|
||||
const char *ulog_level_name(ulog_level_t level);
|
||||
void ulog_message(ulog_level_t severity, const char *fmt, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ULOG_H_ */
|
||||
Reference in New Issue
Block a user