Compare commits
12 Commits
99d4347938
...
feature/ct
| Author | SHA1 | Date | |
|---|---|---|---|
| 3e7c5c5089 | |||
| 76ba24e527 | |||
| dd8c727f0b | |||
| 843e74ded0 | |||
| 527585217c | |||
| d3d896a419 | |||
| a690f3a209 | |||
| d7e25af8bf | |||
| 40e0ca1d0c | |||
| 26f5cfe3ce | |||
| 6d313aaa54 | |||
| 2bc91de389 |
@@ -1 +1 @@
|
|||||||
[]
|
[{"node":"ADC1","expanded":true,"format":0,"pinned":false}]
|
||||||
1
firmware/.vscode/launch.json
vendored
1
firmware/.vscode/launch.json
vendored
@@ -14,7 +14,6 @@
|
|||||||
"servertype": "jlink",
|
"servertype": "jlink",
|
||||||
"device": "STM32F303RE",
|
"device": "STM32F303RE",
|
||||||
"interface": "swd",
|
"interface": "swd",
|
||||||
"runToMain": true,
|
|
||||||
"svdFile": "STM32F303xE.svd",
|
"svdFile": "STM32F303xE.svd",
|
||||||
"preLaunchTask": "${defaultBuildTask}",
|
"preLaunchTask": "${defaultBuildTask}",
|
||||||
"rttConfig": {
|
"rttConfig": {
|
||||||
|
|||||||
14
firmware/.vscode/settings.json
vendored
14
firmware/.vscode/settings.json
vendored
@@ -15,6 +15,16 @@
|
|||||||
"disp_layout_types.h": "c",
|
"disp_layout_types.h": "c",
|
||||||
"ctrl_app_types.h": "c",
|
"ctrl_app_types.h": "c",
|
||||||
"tim.h": "c",
|
"tim.h": "c",
|
||||||
"ulog.h": "c"
|
"ulog.h": "c",
|
||||||
}
|
"ctrl_generator.h": "c",
|
||||||
|
"type_traits": "c",
|
||||||
|
"ctrl_gen_types.h": "c",
|
||||||
|
"mcp41x.h": "c",
|
||||||
|
"ctrl_channel_button.h": "c",
|
||||||
|
"ctrl_encoder.h": "c",
|
||||||
|
"ctrl_disp_button.h": "c",
|
||||||
|
"ctrl_app.h": "c",
|
||||||
|
"ctrl_app_defs.h": "c"
|
||||||
|
},
|
||||||
|
"cortex-debug.variableUseNaturalFormat": true
|
||||||
}
|
}
|
||||||
@@ -23,8 +23,7 @@
|
|||||||
#define __MAIN_H
|
#define __MAIN_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C"
|
extern "C" {
|
||||||
{
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -34,25 +33,25 @@ extern "C"
|
|||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
// #include "SEGGER_RTT.h"
|
// #include "SEGGER_RTT.h"
|
||||||
#include "ulog.h"
|
#include "ulog.h"
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
/* Exported types ------------------------------------------------------------*/
|
/* Exported types ------------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN ET */
|
/* USER CODE BEGIN ET */
|
||||||
|
|
||||||
/* USER CODE END ET */
|
/* USER CODE END ET */
|
||||||
|
|
||||||
/* Exported constants --------------------------------------------------------*/
|
/* Exported constants --------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN EC */
|
/* USER CODE BEGIN EC */
|
||||||
|
|
||||||
/* USER CODE END EC */
|
/* USER CODE END EC */
|
||||||
|
|
||||||
/* Exported macro ------------------------------------------------------------*/
|
/* Exported macro ------------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN EM */
|
/* USER CODE BEGIN EM */
|
||||||
|
|
||||||
/* USER CODE END EM */
|
/* USER CODE END EM */
|
||||||
|
|
||||||
/* Exported functions prototypes ---------------------------------------------*/
|
/* Exported functions prototypes ---------------------------------------------*/
|
||||||
void Error_Handler(void);
|
void Error_Handler(void);
|
||||||
|
|
||||||
/* USER CODE BEGIN EFP */
|
/* USER CODE BEGIN EFP */
|
||||||
|
|
||||||
@@ -61,41 +60,55 @@ extern "C"
|
|||||||
/* Private defines -----------------------------------------------------------*/
|
/* Private defines -----------------------------------------------------------*/
|
||||||
#define B1_Pin GPIO_PIN_13
|
#define B1_Pin GPIO_PIN_13
|
||||||
#define B1_GPIO_Port GPIOC
|
#define B1_GPIO_Port GPIOC
|
||||||
|
#define BTN1_Pin GPIO_PIN_0
|
||||||
|
#define BTN1_GPIO_Port GPIOA
|
||||||
|
#define BTN2_Pin GPIO_PIN_1
|
||||||
|
#define BTN2_GPIO_Port GPIOA
|
||||||
#define USART_TX_Pin GPIO_PIN_2
|
#define USART_TX_Pin GPIO_PIN_2
|
||||||
#define USART_TX_GPIO_Port GPIOA
|
#define USART_TX_GPIO_Port GPIOA
|
||||||
#define USART_RX_Pin GPIO_PIN_3
|
#define USART_RX_Pin GPIO_PIN_3
|
||||||
#define USART_RX_GPIO_Port GPIOA
|
#define USART_RX_GPIO_Port GPIOA
|
||||||
#define LD2_Pin GPIO_PIN_5
|
#define BTN3_Pin GPIO_PIN_4
|
||||||
#define LD2_GPIO_Port GPIOA
|
#define BTN3_GPIO_Port GPIOA
|
||||||
#define BTN1_Pin GPIO_PIN_1
|
#define BTN4_Pin GPIO_PIN_5
|
||||||
#define BTN1_GPIO_Port GPIOB
|
#define BTN4_GPIO_Port GPIOA
|
||||||
#define BTN2_Pin GPIO_PIN_2
|
#define DDS2_CS_Pin GPIO_PIN_10
|
||||||
#define BTN2_GPIO_Port GPIOB
|
#define DDS2_CS_GPIO_Port GPIOB
|
||||||
#define BTN3_Pin GPIO_PIN_11
|
#define AMP1_CS_Pin GPIO_PIN_11
|
||||||
#define BTN3_GPIO_Port GPIOB
|
#define AMP1_CS_GPIO_Port GPIOB
|
||||||
#define BTN4_Pin GPIO_PIN_12
|
#define DDS1_CS_Pin GPIO_PIN_12
|
||||||
#define BTN4_GPIO_Port GPIOB
|
#define DDS1_CS_GPIO_Port GPIOB
|
||||||
#define BTN5_Pin GPIO_PIN_11
|
#define ST7565_RST_Pin GPIO_PIN_8
|
||||||
|
#define ST7565_RST_GPIO_Port GPIOC
|
||||||
|
#define ST7565_A0_Pin GPIO_PIN_9
|
||||||
|
#define ST7565_A0_GPIO_Port GPIOC
|
||||||
|
#define BTN5_Pin GPIO_PIN_8
|
||||||
#define BTN5_GPIO_Port GPIOA
|
#define BTN5_GPIO_Port GPIOA
|
||||||
|
#define BTN_CH1_Pin GPIO_PIN_9
|
||||||
|
#define BTN_CH1_GPIO_Port GPIOA
|
||||||
|
#define LED_CH1_Pin GPIO_PIN_10
|
||||||
|
#define LED_CH1_GPIO_Port GPIOA
|
||||||
|
#define BTN_CH2_Pin GPIO_PIN_11
|
||||||
|
#define BTN_CH2_GPIO_Port GPIOA
|
||||||
|
#define LED_CH2_Pin GPIO_PIN_12
|
||||||
|
#define LED_CH2_GPIO_Port GPIOA
|
||||||
#define TMS_Pin GPIO_PIN_13
|
#define TMS_Pin GPIO_PIN_13
|
||||||
#define TMS_GPIO_Port GPIOA
|
#define TMS_GPIO_Port GPIOA
|
||||||
#define TCK_Pin GPIO_PIN_14
|
#define TCK_Pin GPIO_PIN_14
|
||||||
#define TCK_GPIO_Port GPIOA
|
#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_Pin GPIO_PIN_10
|
||||||
#define ST7565_SCK_GPIO_Port GPIOC
|
#define ST7565_SCK_GPIO_Port GPIOC
|
||||||
#define ST7565_RST_Pin GPIO_PIN_11
|
#define ST7565_CS_Pin GPIO_PIN_11
|
||||||
#define ST7565_RST_GPIO_Port GPIOC
|
#define ST7565_CS_GPIO_Port GPIOC
|
||||||
#define ST7565_MOSI_Pin GPIO_PIN_12
|
#define ST7565_MOSI_Pin GPIO_PIN_12
|
||||||
#define ST7565_MOSI_GPIO_Port GPIOC
|
#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_Pin GPIO_PIN_3
|
||||||
#define SWO_GPIO_Port GPIOB
|
#define SWO_GPIO_Port GPIOB
|
||||||
/* USER CODE BEGIN Private defines */
|
#define AMP2_CS_Pin GPIO_PIN_9
|
||||||
|
#define AMP2_CS_GPIO_Port GPIOB
|
||||||
|
/* USER CODE BEGIN Private defines */
|
||||||
|
|
||||||
/* USER CODE END Private defines */
|
/* USER CODE END Private defines */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ extern "C" {
|
|||||||
|
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
|
extern TIM_HandleTypeDef htim1;
|
||||||
|
|
||||||
extern TIM_HandleTypeDef htim2;
|
extern TIM_HandleTypeDef htim2;
|
||||||
|
|
||||||
extern TIM_HandleTypeDef htim3;
|
extern TIM_HandleTypeDef htim3;
|
||||||
@@ -40,9 +42,12 @@ extern TIM_HandleTypeDef htim3;
|
|||||||
|
|
||||||
/* USER CODE END Private defines */
|
/* USER CODE END Private defines */
|
||||||
|
|
||||||
|
void MX_TIM1_Init(void);
|
||||||
void MX_TIM2_Init(void);
|
void MX_TIM2_Init(void);
|
||||||
void MX_TIM3_Init(void);
|
void MX_TIM3_Init(void);
|
||||||
|
|
||||||
|
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
|
||||||
|
|
||||||
/* USER CODE BEGIN Prototypes */
|
/* USER CODE BEGIN Prototypes */
|
||||||
|
|
||||||
/* USER CODE END Prototypes */
|
/* USER CODE END Prototypes */
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
/* USER CODE BEGIN Header */
|
/* USER CODE BEGIN Header */
|
||||||
/**
|
/**
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @file gpio.c
|
* @file gpio.c
|
||||||
* @brief This file provides code for the configuration
|
* @brief This file provides code for the configuration
|
||||||
* of all used GPIO pins.
|
* of all used GPIO pins.
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
* @attention
|
* @attention
|
||||||
*
|
*
|
||||||
* Copyright (c) 2023 STMicroelectronics.
|
* Copyright (c) 2023 STMicroelectronics.
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This software is licensed under terms that can be found in the LICENSE file
|
* This software is licensed under terms that can be found in the LICENSE file
|
||||||
* in the root directory of this software component.
|
* in the root directory of this software component.
|
||||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
/* USER CODE END Header */
|
/* USER CODE END Header */
|
||||||
|
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
@@ -49,16 +49,15 @@ void MX_GPIO_Init(void)
|
|||||||
__HAL_RCC_GPIOF_CLK_ENABLE();
|
__HAL_RCC_GPIOF_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
/*Configure GPIO pin Output Level */
|
||||||
HAL_GPIO_WritePin(GPIOA, LD2_Pin|ST7565_CS_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(GPIOB, DDS2_CS_Pin|AMP1_CS_Pin|DDS1_CS_Pin|AMP2_CS_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
/*Configure GPIO pin Output Level */
|
||||||
HAL_GPIO_WritePin(ST7565_RST_GPIO_Port, ST7565_RST_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(GPIOC, ST7565_RST_Pin|ST7565_A0_Pin|ST7565_CS_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
/*Configure GPIO pin Output Level */
|
||||||
HAL_GPIO_WritePin(ST7565_A0_GPIO_Port, ST7565_A0_Pin, GPIO_PIN_RESET);
|
HAL_GPIO_WritePin(GPIOA, LED_CH1_Pin|LED_CH2_Pin, GPIO_PIN_RESET);
|
||||||
|
|
||||||
/*Configure GPIO pin : PtPin */
|
/*Configure GPIO pin : PtPin */
|
||||||
GPIO_InitStruct.Pin = B1_Pin;
|
GPIO_InitStruct.Pin = B1_Pin;
|
||||||
@@ -66,39 +65,35 @@ void MX_GPIO_Init(void)
|
|||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(B1_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : PAPin PAPin PAPin PAPin
|
||||||
|
PAPin PAPin PAPin */
|
||||||
|
GPIO_InitStruct.Pin = BTN1_Pin|BTN2_Pin|BTN3_Pin|BTN4_Pin
|
||||||
|
|BTN5_Pin|BTN_CH1_Pin|BTN_CH2_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : PBPin PBPin PBPin PBPin */
|
||||||
|
GPIO_InitStruct.Pin = DDS2_CS_Pin|AMP1_CS_Pin|DDS1_CS_Pin|AMP2_CS_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pins : PCPin PCPin PCPin */
|
||||||
|
GPIO_InitStruct.Pin = ST7565_RST_Pin|ST7565_A0_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(GPIOC, &GPIO_InitStruct);
|
||||||
|
|
||||||
/*Configure GPIO pins : PAPin PAPin */
|
/*Configure GPIO pins : PAPin PAPin */
|
||||||
GPIO_InitStruct.Pin = LD2_Pin|ST7565_CS_Pin;
|
GPIO_InitStruct.Pin = LED_CH1_Pin|LED_CH2_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
HAL_GPIO_Init(GPIOA, &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);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* USER CODE BEGIN 2 */
|
/* USER CODE BEGIN 2 */
|
||||||
|
|||||||
@@ -67,167 +67,175 @@ void RTT_console_logger(ulog_level_t severity, char *msg);
|
|||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The application entry point.
|
* @brief The application entry point.
|
||||||
* @retval int
|
* @retval int
|
||||||
*/
|
*/
|
||||||
int main(void)
|
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. */
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
||||||
HAL_Init();
|
HAL_Init();
|
||||||
|
|
||||||
/* USER CODE BEGIN Init */
|
/* USER CODE BEGIN Init */
|
||||||
|
|
||||||
/* USER CODE END Init */
|
/* USER CODE END Init */
|
||||||
|
|
||||||
/* Configure the system clock */
|
/* Configure the system clock */
|
||||||
SystemClock_Config();
|
SystemClock_Config();
|
||||||
|
|
||||||
/* USER CODE BEGIN SysInit */
|
/* USER CODE BEGIN SysInit */
|
||||||
|
|
||||||
/* USER CODE END SysInit */
|
/* USER CODE END SysInit */
|
||||||
|
|
||||||
/* Initialize all configured peripherals */
|
/* Initialize all configured peripherals */
|
||||||
MX_GPIO_Init();
|
MX_GPIO_Init();
|
||||||
MX_USART2_UART_Init();
|
MX_USART2_UART_Init();
|
||||||
MX_SPI2_Init();
|
MX_SPI2_Init();
|
||||||
MX_I2C1_Init();
|
MX_I2C1_Init();
|
||||||
MX_SPI3_Init();
|
MX_SPI3_Init();
|
||||||
MX_TIM2_Init();
|
MX_TIM2_Init();
|
||||||
MX_TIM3_Init();
|
MX_TIM3_Init();
|
||||||
/* USER CODE BEGIN 2 */
|
MX_TIM1_Init();
|
||||||
ulog_init();
|
/* USER CODE BEGIN 2 */
|
||||||
ulog_subscribe(RTT_console_logger, ULOG_DEBUG_LEVEL);
|
ulog_init();
|
||||||
|
ulog_subscribe(RTT_console_logger, ULOG_TRACE_LEVEL);
|
||||||
|
|
||||||
APP_init(&app_data);
|
HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL);
|
||||||
HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL);
|
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_2);
|
||||||
// SEGGER_RTT_WriteString(0, "App start...\n");
|
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_3);
|
||||||
ULOG_INFO("start app...");
|
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_4);
|
||||||
|
// SEGGER_RTT_WriteString(0, "App start...\n");
|
||||||
|
ULOG_INFO("start app...");
|
||||||
|
|
||||||
hst7565.hspi = &hspi3;
|
hst7565.hspi = &hspi3;
|
||||||
hst7565.cs_port = ST7565_CS_GPIO_Port;
|
hst7565.cs_port = ST7565_CS_GPIO_Port;
|
||||||
hst7565.cs_pin = ST7565_CS_Pin;
|
hst7565.cs_pin = ST7565_CS_Pin;
|
||||||
hst7565.a0_port = ST7565_A0_GPIO_Port;
|
hst7565.a0_port = ST7565_A0_GPIO_Port;
|
||||||
hst7565.a0_pin = ST7565_A0_Pin;
|
hst7565.a0_pin = ST7565_A0_Pin;
|
||||||
hst7565.rst_port = ST7565_RST_GPIO_Port;
|
hst7565.rst_port = ST7565_RST_GPIO_Port;
|
||||||
hst7565.rst_pin = ST7565_RST_Pin;
|
hst7565.rst_pin = ST7565_RST_Pin;
|
||||||
ST7565_Init(&hst7565, &disp);
|
ST7565_Init(&hst7565, &disp);
|
||||||
|
|
||||||
/* USER CODE END 2 */
|
/* USER CODE END 2 */
|
||||||
|
|
||||||
/* Infinite loop */
|
/* Infinite loop */
|
||||||
/* USER CODE BEGIN WHILE */
|
/* USER CODE BEGIN WHILE */
|
||||||
DISP_clearScreen(&disp);
|
DISP_clearScreen(&disp);
|
||||||
ST7565_DisplayAll(&hst7565);
|
ST7565_DisplayAll(&hst7565);
|
||||||
|
HAL_Delay(1000);
|
||||||
|
uint32_t last_tick = HAL_GetTick();
|
||||||
|
APP_init(&app_data);
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
CTRL_buttonsHandler();
|
||||||
|
if (HAL_GetTick() - last_tick > 100)
|
||||||
|
{
|
||||||
|
last_tick = HAL_GetTick();
|
||||||
|
ST7565_DisplayAll(&hst7565);
|
||||||
|
LAY_drawDisplayLayout(&disp, &app_data);
|
||||||
|
}
|
||||||
|
/* USER CODE END WHILE */
|
||||||
|
|
||||||
uint32_t last_tick = HAL_GetTick();
|
/* USER CODE BEGIN 3 */
|
||||||
while (1)
|
}
|
||||||
{
|
/* USER CODE END 3 */
|
||||||
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 END 3 */
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief System Clock Configuration
|
* @brief System Clock Configuration
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void SystemClock_Config(void)
|
void SystemClock_Config(void)
|
||||||
{
|
{
|
||||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
||||||
|
|
||||||
/** Initializes the RCC Oscillators according to the specified parameters
|
/** Initializes the RCC Oscillators according to the specified parameters
|
||||||
* in the RCC_OscInitTypeDef structure.
|
* in the RCC_OscInitTypeDef structure.
|
||||||
*/
|
*/
|
||||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||||
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||||
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
|
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
|
||||||
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
|
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1;
|
||||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||||
{
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Initializes the CPU, AHB and APB buses clocks
|
/** 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.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
||||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
|
||||||
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||||
|
|
||||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
|
||||||
{
|
{
|
||||||
Error_Handler();
|
Error_Handler();
|
||||||
}
|
}
|
||||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2 | RCC_PERIPHCLK_I2C1 | RCC_PERIPHCLK_TIM2 | RCC_PERIPHCLK_TIM34;
|
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2|RCC_PERIPHCLK_I2C1
|
||||||
PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
|
|RCC_PERIPHCLK_TIM1|RCC_PERIPHCLK_TIM2
|
||||||
PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_HSI;
|
|RCC_PERIPHCLK_TIM34;
|
||||||
PeriphClkInit.Tim2ClockSelection = RCC_TIM2CLK_HCLK;
|
PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
|
||||||
PeriphClkInit.Tim34ClockSelection = RCC_TIM34CLK_HCLK;
|
PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_HSI;
|
||||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
PeriphClkInit.Tim1ClockSelection = RCC_TIM1CLK_PLLCLK;
|
||||||
{
|
PeriphClkInit.Tim2ClockSelection = RCC_TIM2CLK_HCLK;
|
||||||
Error_Handler();
|
PeriphClkInit.Tim34ClockSelection = RCC_TIM34CLK_HCLK;
|
||||||
}
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* USER CODE BEGIN 4 */
|
/* USER CODE BEGIN 4 */
|
||||||
void RTT_console_logger(ulog_level_t severity, char *msg)
|
void RTT_console_logger(ulog_level_t severity, char *msg)
|
||||||
{
|
{
|
||||||
SEGGER_RTT_printf(0, "[%s]: %s\n",
|
SEGGER_RTT_printf(0, "[%s]: %s\n",
|
||||||
// HAL_GetTick(), // user defined function
|
// HAL_GetTick(), // user defined function
|
||||||
ulog_level_name(severity),
|
ulog_level_name(severity),
|
||||||
msg);
|
msg);
|
||||||
}
|
}
|
||||||
/* USER CODE END 4 */
|
/* USER CODE END 4 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief This function is executed in case of error occurrence.
|
* @brief This function is executed in case of error occurrence.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void Error_Handler(void)
|
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 */
|
/* User can add his own implementation to report the HAL error return state */
|
||||||
__disable_irq();
|
__disable_irq();
|
||||||
while (1)
|
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
|
* @brief Reports the name of the source file and the source line number
|
||||||
* where the assert_param error has occurred.
|
* where the assert_param error has occurred.
|
||||||
* @param file: pointer to the source file name
|
* @param file: pointer to the source file name
|
||||||
* @param line: assert_param error line source number
|
* @param line: assert_param error line source number
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void assert_failed(uint8_t *file, uint32_t line)
|
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,
|
/* 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) */
|
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 */
|
#endif /* USE_FULL_ASSERT */
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ void MX_SPI2_Init(void)
|
|||||||
hspi2.Init.Mode = SPI_MODE_MASTER;
|
hspi2.Init.Mode = SPI_MODE_MASTER;
|
||||||
hspi2.Init.Direction = SPI_DIRECTION_2LINES;
|
hspi2.Init.Direction = SPI_DIRECTION_2LINES;
|
||||||
hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
|
hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||||
hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
|
hspi2.Init.CLKPolarity = SPI_POLARITY_HIGH;
|
||||||
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
|
hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||||
hspi2.Init.NSS = SPI_NSS_SOFT;
|
hspi2.Init.NSS = SPI_NSS_SOFT;
|
||||||
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
|
hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
|
||||||
|
|||||||
@@ -24,9 +24,94 @@
|
|||||||
|
|
||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
|
TIM_HandleTypeDef htim1;
|
||||||
TIM_HandleTypeDef htim2;
|
TIM_HandleTypeDef htim2;
|
||||||
TIM_HandleTypeDef htim3;
|
TIM_HandleTypeDef htim3;
|
||||||
|
|
||||||
|
/* TIM1 init function */
|
||||||
|
void MX_TIM1_Init(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 0 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 0 */
|
||||||
|
|
||||||
|
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||||
|
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||||
|
TIM_OC_InitTypeDef sConfigOC = {0};
|
||||||
|
TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_Init 1 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 1 */
|
||||||
|
htim1.Instance = TIM1;
|
||||||
|
htim1.Init.Prescaler = 0;
|
||||||
|
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
|
htim1.Init.Period = 5;
|
||||||
|
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
|
htim1.Init.RepetitionCounter = 0;
|
||||||
|
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
|
||||||
|
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||||
|
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (HAL_TIM_PWM_Init(&htim1) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||||
|
sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
|
||||||
|
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||||
|
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||||
|
sConfigOC.Pulse = 3;
|
||||||
|
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||||
|
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
||||||
|
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||||
|
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
|
||||||
|
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
||||||
|
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
|
||||||
|
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
|
||||||
|
sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
|
||||||
|
sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
|
||||||
|
sBreakDeadTimeConfig.DeadTime = 0;
|
||||||
|
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
|
||||||
|
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
|
||||||
|
sBreakDeadTimeConfig.BreakFilter = 0;
|
||||||
|
sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE;
|
||||||
|
sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH;
|
||||||
|
sBreakDeadTimeConfig.Break2Filter = 0;
|
||||||
|
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
|
||||||
|
if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK)
|
||||||
|
{
|
||||||
|
Error_Handler();
|
||||||
|
}
|
||||||
|
/* USER CODE BEGIN TIM1_Init 2 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_Init 2 */
|
||||||
|
HAL_TIM_MspPostInit(&htim1);
|
||||||
|
|
||||||
|
}
|
||||||
/* TIM2 init function */
|
/* TIM2 init function */
|
||||||
void MX_TIM2_Init(void)
|
void MX_TIM2_Init(void)
|
||||||
{
|
{
|
||||||
@@ -115,7 +200,18 @@ void MX_TIM3_Init(void)
|
|||||||
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
|
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(tim_baseHandle->Instance==TIM2)
|
if(tim_baseHandle->Instance==TIM1)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN TIM1_MspInit 0 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_MspInit 0 */
|
||||||
|
/* TIM1 clock enable */
|
||||||
|
__HAL_RCC_TIM1_CLK_ENABLE();
|
||||||
|
/* USER CODE BEGIN TIM1_MspInit 1 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_MspInit 1 */
|
||||||
|
}
|
||||||
|
else if(tim_baseHandle->Instance==TIM2)
|
||||||
{
|
{
|
||||||
/* USER CODE BEGIN TIM2_MspInit 0 */
|
/* USER CODE BEGIN TIM2_MspInit 0 */
|
||||||
|
|
||||||
@@ -157,11 +253,51 @@ void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef* tim_encoderHandle)
|
|||||||
/* USER CODE END TIM3_MspInit 1 */
|
/* USER CODE END TIM3_MspInit 1 */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle)
|
||||||
|
{
|
||||||
|
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
if(timHandle->Instance==TIM1)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN TIM1_MspPostInit 0 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_MspPostInit 0 */
|
||||||
|
|
||||||
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||||
|
/**TIM1 GPIO Configuration
|
||||||
|
PC1 ------> TIM1_CH2
|
||||||
|
PC2 ------> TIM1_CH3
|
||||||
|
PC3 ------> TIM1_CH4
|
||||||
|
*/
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||||
|
GPIO_InitStruct.Alternate = GPIO_AF2_TIM1;
|
||||||
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/* USER CODE BEGIN TIM1_MspPostInit 1 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_MspPostInit 1 */
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
|
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(tim_baseHandle->Instance==TIM2)
|
if(tim_baseHandle->Instance==TIM1)
|
||||||
|
{
|
||||||
|
/* USER CODE BEGIN TIM1_MspDeInit 0 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_MspDeInit 0 */
|
||||||
|
/* Peripheral clock disable */
|
||||||
|
__HAL_RCC_TIM1_CLK_DISABLE();
|
||||||
|
/* USER CODE BEGIN TIM1_MspDeInit 1 */
|
||||||
|
|
||||||
|
/* USER CODE END TIM1_MspDeInit 1 */
|
||||||
|
}
|
||||||
|
else if(tim_baseHandle->Instance==TIM2)
|
||||||
{
|
{
|
||||||
/* USER CODE BEGIN TIM2_MspDeInit 0 */
|
/* USER CODE BEGIN TIM2_MspDeInit 0 */
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
##########################################################################################################################
|
##########################################################################################################################
|
||||||
# File automatically-generated by tool: [projectgenerator] version: [3.17.1] date: [Fri Apr 21 19:03:25 CEST 2023]
|
# File automatically-generated by tool: [projectgenerator] version: [3.17.1] date: [Sat Aug 12 20:39:38 CEST 2023]
|
||||||
##########################################################################################################################
|
##########################################################################################################################
|
||||||
|
|
||||||
# ------------------------------------------------
|
# ------------------------------------------------
|
||||||
@@ -78,20 +78,30 @@ C_SOURCES += ../shared_libs/drivers/mcp41x/mcp41x.c
|
|||||||
C_SOURCES += ../shared_libs/drivers/st7565/st7565.c
|
C_SOURCES += ../shared_libs/drivers/st7565/st7565.c
|
||||||
# hw_button
|
# hw_button
|
||||||
C_SOURCES += ../shared_libs/drivers/hw_button/hw_button.c
|
C_SOURCES += ../shared_libs/drivers/hw_button/hw_button.c
|
||||||
|
# led
|
||||||
|
C_SOURCES += ../shared_libs/drivers/led/led.c
|
||||||
|
# mcu_cs
|
||||||
|
C_SOURCES += ../shared_libs/drivers/mcu_cs/mcu_cs.c
|
||||||
|
|
||||||
# display
|
# display
|
||||||
C_SOURCES += ../shared_libs/display/display_gfx.c
|
C_SOURCES += ../shared_libs/display/display_gfx.c
|
||||||
C_SOURCES += ../shared_libs/display/font_gfx.c
|
C_SOURCES += ../shared_libs/display/font_gfx.c
|
||||||
|
|
||||||
# bitmaps
|
# bitmaps
|
||||||
C_SOURCES += ../shared_libs/bitmaps/bitmap_disp_buttons.c
|
C_SOURCES += ../shared_libs/bitmaps/bitmap_disp_buttons.c
|
||||||
C_SOURCES += ../shared_libs/bitmaps/bitmap_font_5x7.c
|
C_SOURCES += ../shared_libs/bitmaps/bitmap_font_5x7.c
|
||||||
C_SOURCES += ../shared_libs/bitmaps/bitmap_wave.c
|
C_SOURCES += ../shared_libs/bitmaps/bitmap_wave.c
|
||||||
|
|
||||||
# display_layout
|
# display_layout
|
||||||
C_SOURCES += ../shared_libs/disp_layout/disp_layout.c
|
C_SOURCES += ../shared_libs/disp_layout/disp_layout.c
|
||||||
|
|
||||||
# controllers
|
# controllers
|
||||||
|
C_SOURCES += ../shared_libs/controllers/ctrl_app.c
|
||||||
C_SOURCES += ../shared_libs/controllers/ctrl_bottom_button.c
|
C_SOURCES += ../shared_libs/controllers/ctrl_bottom_button.c
|
||||||
C_SOURCES += ../shared_libs/controllers/ctrl_channel_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_disp_button.c
|
||||||
C_SOURCES += ../shared_libs/controllers/ctrl_encoder.c
|
C_SOURCES += ../shared_libs/controllers/ctrl_encoder.c
|
||||||
|
C_SOURCES += ../shared_libs/controllers/ctrl_signal_gen.c
|
||||||
|
|
||||||
# utils/printf
|
# utils/printf
|
||||||
C_SOURCES += ../shared_libs/utils/printf/printf.c
|
C_SOURCES += ../shared_libs/utils/printf/printf.c
|
||||||
@@ -173,6 +183,10 @@ C_INCLUDES += -I../shared_libs/drivers/mcp41x
|
|||||||
C_INCLUDES += -I../shared_libs/drivers/st7565
|
C_INCLUDES += -I../shared_libs/drivers/st7565
|
||||||
# hw_button includes
|
# hw_button includes
|
||||||
C_INCLUDES += -I../shared_libs/drivers/hw_button
|
C_INCLUDES += -I../shared_libs/drivers/hw_button
|
||||||
|
# led includes
|
||||||
|
C_INCLUDES += -I../shared_libs/drivers/led
|
||||||
|
# mcu_cs includes
|
||||||
|
C_INCLUDES += -I../shared_libs/drivers/mcu_cs
|
||||||
# display includes
|
# display includes
|
||||||
C_INCLUDES += -I../shared_libs/display
|
C_INCLUDES += -I../shared_libs/display
|
||||||
# bitmaps includes
|
# bitmaps includes
|
||||||
@@ -186,6 +200,7 @@ C_INCLUDES += -I../shared_libs/controllers
|
|||||||
C_INCLUDES += -I../shared_libs/utils/printf
|
C_INCLUDES += -I../shared_libs/utils/printf
|
||||||
C_INCLUDES += -I../shared_libs/utils/rtt
|
C_INCLUDES += -I../shared_libs/utils/rtt
|
||||||
C_INCLUDES += -I../shared_libs/utils/ulog
|
C_INCLUDES += -I../shared_libs/utils/ulog
|
||||||
|
C_INCLUDES += -I../shared_libs/utils/spi_cs
|
||||||
|
|
||||||
|
|
||||||
# compile gcc flags
|
# compile gcc flags
|
||||||
|
|||||||
@@ -13,43 +13,55 @@ Mcu.IP2=RCC
|
|||||||
Mcu.IP3=SPI2
|
Mcu.IP3=SPI2
|
||||||
Mcu.IP4=SPI3
|
Mcu.IP4=SPI3
|
||||||
Mcu.IP5=SYS
|
Mcu.IP5=SYS
|
||||||
Mcu.IP6=TIM2
|
Mcu.IP6=TIM1
|
||||||
Mcu.IP7=TIM3
|
Mcu.IP7=TIM2
|
||||||
Mcu.IP8=USART2
|
Mcu.IP8=TIM3
|
||||||
Mcu.IPNb=9
|
Mcu.IP9=USART2
|
||||||
|
Mcu.IPNb=10
|
||||||
Mcu.Name=STM32F303R(D-E)Tx
|
Mcu.Name=STM32F303R(D-E)Tx
|
||||||
Mcu.Package=LQFP64
|
Mcu.Package=LQFP64
|
||||||
Mcu.Pin0=PC13
|
Mcu.Pin0=PC13
|
||||||
Mcu.Pin1=PC14-OSC32_IN
|
Mcu.Pin1=PC14-OSC32_IN
|
||||||
Mcu.Pin10=PB1
|
Mcu.Pin10=PA2
|
||||||
Mcu.Pin11=PB2
|
Mcu.Pin11=PA3
|
||||||
Mcu.Pin12=PB11
|
Mcu.Pin12=PA4
|
||||||
Mcu.Pin13=PB12
|
Mcu.Pin13=PA5
|
||||||
Mcu.Pin14=PB13
|
Mcu.Pin14=PA6
|
||||||
Mcu.Pin15=PB14
|
Mcu.Pin15=PA7
|
||||||
Mcu.Pin16=PB15
|
Mcu.Pin16=PB10
|
||||||
Mcu.Pin17=PA11
|
Mcu.Pin17=PB11
|
||||||
Mcu.Pin18=PA13
|
Mcu.Pin18=PB12
|
||||||
Mcu.Pin19=PA14
|
Mcu.Pin19=PB13
|
||||||
Mcu.Pin2=PC15-OSC32_OUT
|
Mcu.Pin2=PC15-OSC32_OUT
|
||||||
Mcu.Pin20=PA15
|
Mcu.Pin20=PB14
|
||||||
Mcu.Pin21=PC10
|
Mcu.Pin21=PB15
|
||||||
Mcu.Pin22=PC11
|
Mcu.Pin22=PC8
|
||||||
Mcu.Pin23=PC12
|
Mcu.Pin23=PC9
|
||||||
Mcu.Pin24=PD2
|
Mcu.Pin24=PA8
|
||||||
Mcu.Pin25=PB3
|
Mcu.Pin25=PA9
|
||||||
Mcu.Pin26=PB6
|
Mcu.Pin26=PA10
|
||||||
Mcu.Pin27=PB7
|
Mcu.Pin27=PA11
|
||||||
Mcu.Pin28=VP_SYS_VS_Systick
|
Mcu.Pin28=PA12
|
||||||
Mcu.Pin29=VP_TIM2_VS_ClockSourceINT
|
Mcu.Pin29=PA13
|
||||||
Mcu.Pin3=PF0-OSC_IN
|
Mcu.Pin3=PF0-OSC_IN
|
||||||
|
Mcu.Pin30=PA14
|
||||||
|
Mcu.Pin31=PC10
|
||||||
|
Mcu.Pin32=PC11
|
||||||
|
Mcu.Pin33=PC12
|
||||||
|
Mcu.Pin34=PB3
|
||||||
|
Mcu.Pin35=PB6
|
||||||
|
Mcu.Pin36=PB7
|
||||||
|
Mcu.Pin37=PB9
|
||||||
|
Mcu.Pin38=VP_SYS_VS_Systick
|
||||||
|
Mcu.Pin39=VP_TIM1_VS_ClockSourceINT
|
||||||
Mcu.Pin4=PF1-OSC_OUT
|
Mcu.Pin4=PF1-OSC_OUT
|
||||||
Mcu.Pin5=PA2
|
Mcu.Pin40=VP_TIM2_VS_ClockSourceINT
|
||||||
Mcu.Pin6=PA3
|
Mcu.Pin5=PC1
|
||||||
Mcu.Pin7=PA5
|
Mcu.Pin6=PC2
|
||||||
Mcu.Pin8=PA6
|
Mcu.Pin7=PC3
|
||||||
Mcu.Pin9=PA7
|
Mcu.Pin8=PA0
|
||||||
Mcu.PinsNb=30
|
Mcu.Pin9=PA1
|
||||||
|
Mcu.PinsNb=41
|
||||||
Mcu.ThirdPartyNb=0
|
Mcu.ThirdPartyNb=0
|
||||||
Mcu.UserConstants=
|
Mcu.UserConstants=
|
||||||
Mcu.UserName=STM32F303RETx
|
Mcu.UserName=STM32F303RETx
|
||||||
@@ -66,10 +78,26 @@ NVIC.PriorityGroup=NVIC_PRIORITYGROUP_0
|
|||||||
NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
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.SysTick_IRQn=true\:0\:0\:true\:false\:true\:true\:true\:false
|
||||||
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:false
|
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:true\:false\:false
|
||||||
|
PA0.GPIOParameters=GPIO_Label
|
||||||
|
PA0.GPIO_Label=BTN1
|
||||||
|
PA0.Locked=true
|
||||||
|
PA0.Signal=GPIO_Input
|
||||||
|
PA1.GPIOParameters=GPIO_Label
|
||||||
|
PA1.GPIO_Label=BTN2
|
||||||
|
PA1.Locked=true
|
||||||
|
PA1.Signal=GPIO_Input
|
||||||
|
PA10.GPIOParameters=GPIO_Label
|
||||||
|
PA10.GPIO_Label=LED_CH1
|
||||||
|
PA10.Locked=true
|
||||||
|
PA10.Signal=GPIO_Output
|
||||||
PA11.GPIOParameters=GPIO_Label
|
PA11.GPIOParameters=GPIO_Label
|
||||||
PA11.GPIO_Label=BTN5
|
PA11.GPIO_Label=BTN_CH2
|
||||||
PA11.Locked=true
|
PA11.Locked=true
|
||||||
PA11.Signal=GPIO_Input
|
PA11.Signal=GPIO_Input
|
||||||
|
PA12.GPIOParameters=GPIO_Label
|
||||||
|
PA12.GPIO_Label=LED_CH2
|
||||||
|
PA12.Locked=true
|
||||||
|
PA12.Signal=GPIO_Output
|
||||||
PA13.GPIOParameters=GPIO_Label
|
PA13.GPIOParameters=GPIO_Label
|
||||||
PA13.GPIO_Label=TMS
|
PA13.GPIO_Label=TMS
|
||||||
PA13.Locked=true
|
PA13.Locked=true
|
||||||
@@ -80,10 +108,6 @@ PA14.GPIO_Label=TCK
|
|||||||
PA14.Locked=true
|
PA14.Locked=true
|
||||||
PA14.Mode=Serial_Wire
|
PA14.Mode=Serial_Wire
|
||||||
PA14.Signal=SYS_JTCK-SWCLK
|
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.GPIOParameters=GPIO_Speed,GPIO_PuPd,GPIO_Label,GPIO_Mode
|
||||||
PA2.GPIO_Label=USART_TX
|
PA2.GPIO_Label=USART_TX
|
||||||
PA2.GPIO_Mode=GPIO_MODE_AF_PP
|
PA2.GPIO_Mode=GPIO_MODE_AF_PP
|
||||||
@@ -100,38 +124,43 @@ PA3.GPIO_Speed=GPIO_SPEED_FREQ_LOW
|
|||||||
PA3.Locked=true
|
PA3.Locked=true
|
||||||
PA3.Mode=Asynchronous
|
PA3.Mode=Asynchronous
|
||||||
PA3.Signal=USART2_RX
|
PA3.Signal=USART2_RX
|
||||||
PA5.GPIOParameters=GPIO_Speed,GPIO_PuPd,GPIO_Label,GPIO_Mode
|
PA4.GPIOParameters=GPIO_Label
|
||||||
PA5.GPIO_Label=LD2 [Green Led]
|
PA4.GPIO_Label=BTN3
|
||||||
PA5.GPIO_Mode=GPIO_MODE_OUTPUT_PP
|
PA4.Locked=true
|
||||||
PA5.GPIO_PuPd=GPIO_NOPULL
|
PA4.Signal=GPIO_Input
|
||||||
PA5.GPIO_Speed=GPIO_SPEED_FREQ_LOW
|
PA5.GPIOParameters=GPIO_Label
|
||||||
|
PA5.GPIO_Label=BTN4
|
||||||
PA5.Locked=true
|
PA5.Locked=true
|
||||||
PA5.Signal=GPIO_Output
|
PA5.Signal=GPIO_Input
|
||||||
PA6.Signal=S_TIM3_CH1
|
PA6.Signal=S_TIM3_CH1
|
||||||
PA7.Locked=true
|
PA7.Locked=true
|
||||||
PA7.Signal=S_TIM3_CH2
|
PA7.Signal=S_TIM3_CH2
|
||||||
PB1.GPIOParameters=GPIO_Label
|
PA8.GPIOParameters=GPIO_Label
|
||||||
PB1.GPIO_Label=BTN1
|
PA8.GPIO_Label=BTN5
|
||||||
PB1.Locked=true
|
PA8.Locked=true
|
||||||
PB1.Signal=GPIO_Input
|
PA8.Signal=GPIO_Input
|
||||||
|
PA9.GPIOParameters=GPIO_Label
|
||||||
|
PA9.GPIO_Label=BTN_CH1
|
||||||
|
PA9.Locked=true
|
||||||
|
PA9.Signal=GPIO_Input
|
||||||
|
PB10.GPIOParameters=GPIO_Label
|
||||||
|
PB10.GPIO_Label=DDS2_CS
|
||||||
|
PB10.Locked=true
|
||||||
|
PB10.Signal=GPIO_Output
|
||||||
PB11.GPIOParameters=GPIO_Label
|
PB11.GPIOParameters=GPIO_Label
|
||||||
PB11.GPIO_Label=BTN3
|
PB11.GPIO_Label=AMP1_CS
|
||||||
PB11.Locked=true
|
PB11.Locked=true
|
||||||
PB11.Signal=GPIO_Input
|
PB11.Signal=GPIO_Output
|
||||||
PB12.GPIOParameters=GPIO_Label
|
PB12.GPIOParameters=GPIO_Label
|
||||||
PB12.GPIO_Label=BTN4
|
PB12.GPIO_Label=DDS1_CS
|
||||||
PB12.Locked=true
|
PB12.Locked=true
|
||||||
PB12.Signal=GPIO_Input
|
PB12.Signal=GPIO_Output
|
||||||
PB13.Mode=Full_Duplex_Master
|
PB13.Mode=Full_Duplex_Master
|
||||||
PB13.Signal=SPI2_SCK
|
PB13.Signal=SPI2_SCK
|
||||||
PB14.Mode=Full_Duplex_Master
|
PB14.Mode=Full_Duplex_Master
|
||||||
PB14.Signal=SPI2_MISO
|
PB14.Signal=SPI2_MISO
|
||||||
PB15.Mode=Full_Duplex_Master
|
PB15.Mode=Full_Duplex_Master
|
||||||
PB15.Signal=SPI2_MOSI
|
PB15.Signal=SPI2_MOSI
|
||||||
PB2.GPIOParameters=GPIO_Label
|
|
||||||
PB2.GPIO_Label=BTN2
|
|
||||||
PB2.Locked=true
|
|
||||||
PB2.Signal=GPIO_Input
|
|
||||||
PB3.GPIOParameters=GPIO_Label
|
PB3.GPIOParameters=GPIO_Label
|
||||||
PB3.GPIO_Label=SWO
|
PB3.GPIO_Label=SWO
|
||||||
PB3.Locked=true
|
PB3.Locked=true
|
||||||
@@ -141,13 +170,20 @@ PB6.Mode=I2C
|
|||||||
PB6.Signal=I2C1_SCL
|
PB6.Signal=I2C1_SCL
|
||||||
PB7.Mode=I2C
|
PB7.Mode=I2C
|
||||||
PB7.Signal=I2C1_SDA
|
PB7.Signal=I2C1_SDA
|
||||||
|
PB9.GPIOParameters=GPIO_Label
|
||||||
|
PB9.GPIO_Label=AMP2_CS
|
||||||
|
PB9.Locked=true
|
||||||
|
PB9.Signal=GPIO_Output
|
||||||
|
PC1.GPIOParameters=GPIO_Speed
|
||||||
|
PC1.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
|
||||||
|
PC1.Signal=S_TIM1_CH2
|
||||||
PC10.GPIOParameters=GPIO_Label
|
PC10.GPIOParameters=GPIO_Label
|
||||||
PC10.GPIO_Label=ST7565_SCK
|
PC10.GPIO_Label=ST7565_SCK
|
||||||
PC10.Locked=true
|
PC10.Locked=true
|
||||||
PC10.Mode=Simplex_Bidirectional_Master
|
PC10.Mode=Simplex_Bidirectional_Master
|
||||||
PC10.Signal=SPI3_SCK
|
PC10.Signal=SPI3_SCK
|
||||||
PC11.GPIOParameters=GPIO_Label
|
PC11.GPIOParameters=GPIO_Label
|
||||||
PC11.GPIO_Label=ST7565_RST
|
PC11.GPIO_Label=ST7565_CS
|
||||||
PC11.Locked=true
|
PC11.Locked=true
|
||||||
PC11.Signal=GPIO_Output
|
PC11.Signal=GPIO_Output
|
||||||
PC12.GPIOParameters=GPIO_Label
|
PC12.GPIOParameters=GPIO_Label
|
||||||
@@ -165,10 +201,20 @@ PC14-OSC32_IN.Signal=RCC_OSC32_IN
|
|||||||
PC15-OSC32_OUT.Locked=true
|
PC15-OSC32_OUT.Locked=true
|
||||||
PC15-OSC32_OUT.Mode=LSE-External-Oscillator
|
PC15-OSC32_OUT.Mode=LSE-External-Oscillator
|
||||||
PC15-OSC32_OUT.Signal=RCC_OSC32_OUT
|
PC15-OSC32_OUT.Signal=RCC_OSC32_OUT
|
||||||
PD2.GPIOParameters=GPIO_Label
|
PC2.GPIOParameters=GPIO_Speed
|
||||||
PD2.GPIO_Label=ST7565_A0
|
PC2.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
|
||||||
PD2.Locked=true
|
PC2.Signal=S_TIM1_CH3
|
||||||
PD2.Signal=GPIO_Output
|
PC3.GPIOParameters=GPIO_Speed
|
||||||
|
PC3.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
|
||||||
|
PC3.Signal=S_TIM1_CH4
|
||||||
|
PC8.GPIOParameters=GPIO_Label
|
||||||
|
PC8.GPIO_Label=ST7565_RST
|
||||||
|
PC8.Locked=true
|
||||||
|
PC8.Signal=GPIO_Output
|
||||||
|
PC9.GPIOParameters=GPIO_Label
|
||||||
|
PC9.GPIO_Label=ST7565_A0
|
||||||
|
PC9.Locked=true
|
||||||
|
PC9.Signal=GPIO_Output
|
||||||
PF0-OSC_IN.Locked=true
|
PF0-OSC_IN.Locked=true
|
||||||
PF0-OSC_IN.Mode=HSE-External-Clock-Source
|
PF0-OSC_IN.Mode=HSE-External-Clock-Source
|
||||||
PF0-OSC_IN.Signal=RCC_OSC_IN
|
PF0-OSC_IN.Signal=RCC_OSC_IN
|
||||||
@@ -202,7 +248,7 @@ ProjectManager.StackSize=0x400
|
|||||||
ProjectManager.TargetToolchain=Makefile
|
ProjectManager.TargetToolchain=Makefile
|
||||||
ProjectManager.ToolChainLocation=
|
ProjectManager.ToolChainLocation=
|
||||||
ProjectManager.UnderRoot=false
|
ProjectManager.UnderRoot=false
|
||||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_USART2_UART_Init-USART2-false-HAL-true,4-MX_SPI2_Init-SPI2-false-HAL-true,5-MX_I2C1_Init-I2C1-false-HAL-true,6-MX_SPI3_Init-SPI3-false-HAL-true,7-MX_TIM2_Init-TIM2-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,8-MX_TIM3_Init-TIM3-false-HAL-true,9-MX_TIM17_Init-TIM17-false-HAL-true,10-MX_TIM1_Init-TIM1-false-HAL-true
|
||||||
RCC.ADC12outputFreq_Value=72000000
|
RCC.ADC12outputFreq_Value=72000000
|
||||||
RCC.ADC34outputFreq_Value=72000000
|
RCC.ADC34outputFreq_Value=72000000
|
||||||
RCC.AHBFreq_Value=72000000
|
RCC.AHBFreq_Value=72000000
|
||||||
@@ -221,9 +267,9 @@ RCC.I2C1Freq_Value=8000000
|
|||||||
RCC.I2C2Freq_Value=8000000
|
RCC.I2C2Freq_Value=8000000
|
||||||
RCC.I2C3Freq_Value=8000000
|
RCC.I2C3Freq_Value=8000000
|
||||||
RCC.I2SClocksFreq_Value=72000000
|
RCC.I2SClocksFreq_Value=72000000
|
||||||
RCC.IPParameters=ADC12outputFreq_Value,ADC34outputFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2SClocksFreq_Value,LSI_VALUE,MCOFreq_Value,PLLCLKFreq_Value,PLLM,PLLMCOFreq_Value,PLLMUL,PLLN,PLLP,PLLQ,RCC_PLLsource_Clock_Source_FROM_HSE,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,SYSCLKSourceVirtual,TIM15Freq_Value,TIM16Freq_Value,TIM17Freq_Value,TIM1Freq_Value,TIM20Freq_Value,TIM2Freq_Value,TIM3Freq_Value,TIM8Freq_Value,UART4Freq_Value,UART5Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOOutput2Freq_Value
|
RCC.IPParameters=ADC12outputFreq_Value,ADC34outputFreq_Value,AHBFreq_Value,APB1CLKDivider,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CortexFreq_Value,FCLKCortexFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2SClocksFreq_Value,LSI_VALUE,MCOFreq_Value,PLLCLKFreq_Value,PLLM,PLLMCOFreq_Value,PLLMUL,PLLN,PLLP,PLLQ,RCC_MCODiv,RCC_MCOSource,RCC_PLLsource_Clock_Source_FROM_HSE,RTCFreq_Value,RTCHSEDivFreq_Value,SYSCLKFreq_VALUE,SYSCLKSourceVirtual,TIM15Freq_Value,TIM16Freq_Value,TIM17Freq_Value,TIM1Freq_Value,TIM1Selection,TIM20Freq_Value,TIM2Freq_Value,TIM3Freq_Value,TIM8Freq_Value,UART4Freq_Value,UART5Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOOutput2Freq_Value
|
||||||
RCC.LSI_VALUE=40000
|
RCC.LSI_VALUE=40000
|
||||||
RCC.MCOFreq_Value=72000000
|
RCC.MCOFreq_Value=9000000
|
||||||
RCC.PLLCLKFreq_Value=72000000
|
RCC.PLLCLKFreq_Value=72000000
|
||||||
RCC.PLLM=8
|
RCC.PLLM=8
|
||||||
RCC.PLLMCOFreq_Value=72000000
|
RCC.PLLMCOFreq_Value=72000000
|
||||||
@@ -231,6 +277,8 @@ RCC.PLLMUL=RCC_PLL_MUL9
|
|||||||
RCC.PLLN=336
|
RCC.PLLN=336
|
||||||
RCC.PLLP=RCC_PLLP_DIV4
|
RCC.PLLP=RCC_PLLP_DIV4
|
||||||
RCC.PLLQ=7
|
RCC.PLLQ=7
|
||||||
|
RCC.RCC_MCODiv=RCC_MCODIV_8
|
||||||
|
RCC.RCC_MCOSource=RCC_MCO1SOURCE_PLLCLK
|
||||||
RCC.RCC_PLLsource_Clock_Source_FROM_HSE=RCC_HSE_PREDIV_DIV2
|
RCC.RCC_PLLsource_Clock_Source_FROM_HSE=RCC_HSE_PREDIV_DIV2
|
||||||
RCC.RTCFreq_Value=40000
|
RCC.RTCFreq_Value=40000
|
||||||
RCC.RTCHSEDivFreq_Value=250000
|
RCC.RTCHSEDivFreq_Value=250000
|
||||||
@@ -239,7 +287,8 @@ RCC.SYSCLKSourceVirtual=RCC_SYSCLKSOURCE_PLLCLK
|
|||||||
RCC.TIM15Freq_Value=72000000
|
RCC.TIM15Freq_Value=72000000
|
||||||
RCC.TIM16Freq_Value=72000000
|
RCC.TIM16Freq_Value=72000000
|
||||||
RCC.TIM17Freq_Value=72000000
|
RCC.TIM17Freq_Value=72000000
|
||||||
RCC.TIM1Freq_Value=72000000
|
RCC.TIM1Freq_Value=144000000
|
||||||
|
RCC.TIM1Selection=RCC_TIM1CLK_PLLCLK
|
||||||
RCC.TIM20Freq_Value=72000000
|
RCC.TIM20Freq_Value=72000000
|
||||||
RCC.TIM2Freq_Value=72000000
|
RCC.TIM2Freq_Value=72000000
|
||||||
RCC.TIM3Freq_Value=72000000
|
RCC.TIM3Freq_Value=72000000
|
||||||
@@ -253,15 +302,22 @@ RCC.USBFreq_Value=72000000
|
|||||||
RCC.VCOOutput2Freq_Value=8000000
|
RCC.VCOOutput2Freq_Value=8000000
|
||||||
SH.GPXTI13.0=GPIO_EXTI13
|
SH.GPXTI13.0=GPIO_EXTI13
|
||||||
SH.GPXTI13.ConfNb=1
|
SH.GPXTI13.ConfNb=1
|
||||||
|
SH.S_TIM1_CH2.0=TIM1_CH2,PWM Generation2 CH2
|
||||||
|
SH.S_TIM1_CH2.ConfNb=1
|
||||||
|
SH.S_TIM1_CH3.0=TIM1_CH3,PWM Generation3 CH3
|
||||||
|
SH.S_TIM1_CH3.ConfNb=1
|
||||||
|
SH.S_TIM1_CH4.0=TIM1_CH4,PWM Generation4 CH4
|
||||||
|
SH.S_TIM1_CH4.ConfNb=1
|
||||||
SH.S_TIM3_CH1.0=TIM3_CH1,Encoder_Interface
|
SH.S_TIM3_CH1.0=TIM3_CH1,Encoder_Interface
|
||||||
SH.S_TIM3_CH1.ConfNb=1
|
SH.S_TIM3_CH1.ConfNb=1
|
||||||
SH.S_TIM3_CH2.0=TIM3_CH2,Encoder_Interface
|
SH.S_TIM3_CH2.0=TIM3_CH2,Encoder_Interface
|
||||||
SH.S_TIM3_CH2.ConfNb=1
|
SH.S_TIM3_CH2.ConfNb=1
|
||||||
SPI2.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_32
|
SPI2.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_32
|
||||||
|
SPI2.CLKPolarity=SPI_POLARITY_HIGH
|
||||||
SPI2.CalculateBaudRate=1.125 MBits/s
|
SPI2.CalculateBaudRate=1.125 MBits/s
|
||||||
SPI2.DataSize=SPI_DATASIZE_8BIT
|
SPI2.DataSize=SPI_DATASIZE_8BIT
|
||||||
SPI2.Direction=SPI_DIRECTION_2LINES
|
SPI2.Direction=SPI_DIRECTION_2LINES
|
||||||
SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize,NSSPMode,BaudRatePrescaler
|
SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize,NSSPMode,BaudRatePrescaler,CLKPolarity
|
||||||
SPI2.Mode=SPI_MODE_MASTER
|
SPI2.Mode=SPI_MODE_MASTER
|
||||||
SPI2.NSSPMode=SPI_NSS_PULSE_ENABLE
|
SPI2.NSSPMode=SPI_NSS_PULSE_ENABLE
|
||||||
SPI2.VirtualType=VM_MASTER
|
SPI2.VirtualType=VM_MASTER
|
||||||
@@ -272,6 +328,16 @@ SPI3.Direction=SPI_DIRECTION_1LINE
|
|||||||
SPI3.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,BaudRatePrescaler,DataSize
|
SPI3.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,BaudRatePrescaler,DataSize
|
||||||
SPI3.Mode=SPI_MODE_MASTER
|
SPI3.Mode=SPI_MODE_MASTER
|
||||||
SPI3.VirtualType=VM_MASTER
|
SPI3.VirtualType=VM_MASTER
|
||||||
|
TIM1.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_ENABLE
|
||||||
|
TIM1.Channel-PWM\ Generation2\ CH2=TIM_CHANNEL_2
|
||||||
|
TIM1.Channel-PWM\ Generation3\ CH3=TIM_CHANNEL_3
|
||||||
|
TIM1.Channel-PWM\ Generation4\ CH4=TIM_CHANNEL_4
|
||||||
|
TIM1.IPParameters=Channel-PWM Generation4 CH4,Channel-PWM Generation3 CH3,Channel-PWM Generation2 CH2,Period,Pulse-PWM Generation2 CH2,Pulse-PWM Generation3 CH3,Pulse-PWM Generation4 CH4,AutoReloadPreload,OCFastMode_PWM-PWM Generation4 CH4
|
||||||
|
TIM1.OCFastMode_PWM-PWM\ Generation4\ CH4=TIM_OCFAST_ENABLE
|
||||||
|
TIM1.Period=5
|
||||||
|
TIM1.Pulse-PWM\ Generation2\ CH2=3
|
||||||
|
TIM1.Pulse-PWM\ Generation3\ CH3=3
|
||||||
|
TIM1.Pulse-PWM\ Generation4\ CH4=3
|
||||||
TIM2.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_DISABLE
|
TIM2.AutoReloadPreload=TIM_AUTORELOAD_PRELOAD_DISABLE
|
||||||
TIM2.IPParameters=AutoReloadPreload
|
TIM2.IPParameters=AutoReloadPreload
|
||||||
TIM3.IC1Filter=15
|
TIM3.IC1Filter=15
|
||||||
@@ -282,6 +348,8 @@ USART2.IPParameters=VirtualMode-Asynchronous
|
|||||||
USART2.VirtualMode-Asynchronous=VM_ASYNC
|
USART2.VirtualMode-Asynchronous=VM_ASYNC
|
||||||
VP_SYS_VS_Systick.Mode=SysTick
|
VP_SYS_VS_Systick.Mode=SysTick
|
||||||
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
|
VP_SYS_VS_Systick.Signal=SYS_VS_Systick
|
||||||
|
VP_TIM1_VS_ClockSourceINT.Mode=Internal
|
||||||
|
VP_TIM1_VS_ClockSourceINT.Signal=TIM1_VS_ClockSourceINT
|
||||||
VP_TIM2_VS_ClockSourceINT.Mode=Internal
|
VP_TIM2_VS_ClockSourceINT.Mode=Internal
|
||||||
VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT
|
VP_TIM2_VS_ClockSourceINT.Signal=TIM2_VS_ClockSourceINT
|
||||||
board=NUCLEO-F303RE
|
board=NUCLEO-F303RE
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "hw_button.h"
|
#include "tim.h"
|
||||||
#include "ctrl_bottom_button.h"
|
#include "ctrl_bottom_button.h"
|
||||||
#include "ctrl_channel_button.h"
|
#include "ctrl_channel_button.h"
|
||||||
#include "ctrl_encoder.h"
|
#include "ctrl_encoder.h"
|
||||||
|
#include "ctrl_disp_button.h"
|
||||||
|
#include "ctrl_signal_gen.h"
|
||||||
|
|
||||||
#include "ctrl_app.h"
|
#include "ctrl_app.h"
|
||||||
|
|
||||||
typedef void (*btn_action_t)(void);
|
typedef void (*btn_action_t)(APP_data_t *app_data);
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
@@ -14,24 +16,47 @@ typedef struct
|
|||||||
BITMAP_buttonName_t bitmap_name;
|
BITMAP_buttonName_t bitmap_name;
|
||||||
} CMD_button_t;
|
} 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 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 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 GEN_channel_t btn_ch_to_chan[CHANNEL_MAX] = {CHANNEL1, CHANNEL2, CHANNEL3, CHANNEL4, CHANNEL5, CHANNEL6};
|
||||||
static const uint32_t pow_of_10[7] = {1, 10, 100, 1000, 10000, 100000, 1000000};
|
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 APP_data_t *_app_data;
|
||||||
|
|
||||||
static const GENERATOR_t generators[CHANNEL_MAX] = {
|
static dds_gen_t dds_gen[DDS_CH_MAX] = {
|
||||||
{.gen_type = GEN_FG_TYPE, .gen = &func_gen[0]},
|
{.super.type = GEN_FG_TYPE, .dds_ch = DDS_CH1},
|
||||||
{.gen_type = GEN_FG_TYPE, .gen = &func_gen[1]},
|
{.super.type = GEN_FG_TYPE, .dds_ch = DDS_CH2},
|
||||||
{.gen_type = GEN_FG_TYPE, .gen = &func_gen[2]},
|
{.super.type = GEN_FG_TYPE, .dds_ch = DDS_CH3},
|
||||||
{.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]},
|
|
||||||
};
|
};
|
||||||
|
static pwm_gen_t pwm_gen[PWM_CH_MAX] = {
|
||||||
|
{.super.type = GEN_PWM_TYPE, .pwm_ch = PWM_CH1},
|
||||||
|
{.super.type = GEN_PWM_TYPE, .pwm_ch = PWM_CH2},
|
||||||
|
{.super.type = GEN_PWM_TYPE, .pwm_ch = PWM_CH3},
|
||||||
|
};
|
||||||
|
|
||||||
|
static signal_gen_t *signal_gen[CHANNEL_MAX] = {
|
||||||
|
&dds_gen[DDS_CH1].super,
|
||||||
|
&dds_gen[DDS_CH2].super,
|
||||||
|
&dds_gen[DDS_CH3].super,
|
||||||
|
&pwm_gen[PWM_CH1].super,
|
||||||
|
&pwm_gen[PWM_CH2].super,
|
||||||
|
&pwm_gen[PWM_CH3].super,
|
||||||
|
};
|
||||||
|
|
||||||
|
static void _setGenInitailState(GEN_channel_t channel);
|
||||||
|
static void _signalGenDefaultValues(void);
|
||||||
|
static void _changeValueDdsGen(int8_t dir);
|
||||||
|
static void _changeValuePwmGen(int8_t dir);
|
||||||
|
|
||||||
|
//****************************
|
||||||
|
// Initialization
|
||||||
|
//****************************
|
||||||
|
|
||||||
|
void CTRL_buttonsInit(void)
|
||||||
|
{
|
||||||
|
CTRL_bottomButtonInit();
|
||||||
|
CTRL_channelButtonInit();
|
||||||
|
}
|
||||||
|
|
||||||
void APP_init(APP_data_t *app_data)
|
void APP_init(APP_data_t *app_data)
|
||||||
{
|
{
|
||||||
@@ -42,27 +67,29 @@ void APP_init(APP_data_t *app_data)
|
|||||||
_app_data->phas_focus_digit = 0;
|
_app_data->phas_focus_digit = 0;
|
||||||
_app_data->duty_focus_digit = 0;
|
_app_data->duty_focus_digit = 0;
|
||||||
|
|
||||||
_app_data->curr_gen_type = GEN_FG_TYPE;
|
_app_data->curr_gen = signal_gen[CHANNEL1];
|
||||||
_app_data->generator = generators[CHANNEL1].gen;
|
|
||||||
|
|
||||||
_app_data->curr_state_lay = LAY_MAIN;
|
_app_data->curr_state_lay = LAY_MAIN;
|
||||||
_app_data->curr_state_btn = BTN_MAIN_FG;
|
_app_data->curr_state_btn = BTN_MAIN_FG;
|
||||||
|
_app_data->curr_channel = CHANNEL1;
|
||||||
|
|
||||||
_app_data->isChannelChange = 1;
|
// _app_data->isChannelChange = 1;
|
||||||
_app_data->isGraphChange = 1;
|
// _app_data->isGraphChange = 1;
|
||||||
_app_data->isValueChange = 1;
|
// _app_data->isValueChange = 1;
|
||||||
_app_data->isButtonChange = 1;
|
// _app_data->isButtonChange = 1;
|
||||||
_app_data->isButtonBlink = 1;
|
// _app_data->isButtonBlink = 1;
|
||||||
|
_app_data->disp_update |= UPDATE_BUTTON | UPDATE_GRAPH | UPDATE_VALUE | UPDATE_CHANNEL;
|
||||||
|
|
||||||
CTRL_buttonsInit();
|
CTRL_buttonsInit();
|
||||||
|
_signalGenDefaultValues();
|
||||||
|
GEN_init(signal_gen);
|
||||||
|
_setGenInitailState(CHANNEL1);
|
||||||
|
_setGenInitailState(CHANNEL2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CTRL_buttonsInit(void)
|
//****************************
|
||||||
{
|
// Handlers
|
||||||
|
//****************************
|
||||||
CTRL_bottomButtonInit();
|
|
||||||
// CTRL_channelButtonInit();
|
|
||||||
}
|
|
||||||
|
|
||||||
void CTRL_buttonsHandler(void)
|
void CTRL_buttonsHandler(void)
|
||||||
{
|
{
|
||||||
@@ -71,481 +98,352 @@ void CTRL_buttonsHandler(void)
|
|||||||
CTRL_encoderHandler();
|
CTRL_encoderHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//****************************
|
||||||
|
// Events
|
||||||
|
//****************************
|
||||||
|
|
||||||
void CTRL_pushedDispBtnEvent(ButtonKey_t *key)
|
void CTRL_pushedDispBtnEvent(ButtonKey_t *key)
|
||||||
{
|
{
|
||||||
ULOG_TRACE("Disp btn: %d", key->instance);
|
ULOG_TRACE("Disp btn: %d", key->instance);
|
||||||
last_key = btn_hw_to_disp[key->instance];
|
_app_data->last_key = btn_hw_to_disp[key->instance];
|
||||||
btn_command[_app_data->curr_state_btn][last_key].command();
|
btn_command[_app_data->curr_state_btn][_app_data->last_key].command(_app_data);
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
void CTRL_encoderEvent(int8_t enc)
|
||||||
{
|
{
|
||||||
ULOG_TRACE("Enco event: %i", enc);
|
ULOG_TRACE("Enco event: %i", enc);
|
||||||
switch (_app_data->curr_gen_type)
|
switch (_app_data->curr_gen->type)
|
||||||
{
|
{
|
||||||
case GEN_FG_TYPE:
|
case GEN_FG_TYPE:
|
||||||
_changeValueFunGen(enc / 2);
|
_changeValueDdsGen(enc / 2);
|
||||||
break;
|
break;
|
||||||
case GEN_PWM_TYPE:
|
case GEN_PWM_TYPE:
|
||||||
_changeValuePwmGen(enc / 2);
|
_changeValuePwmGen(enc / 2);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ULOG_ERROR("%s:%d: Unknown generator type: %d", __FILE__, __LINE__, _app_data->curr_gen_type);
|
ULOG_ERROR("%s:%d: Unknown generator type: %d", __FILE__, __LINE__, _app_data->curr_gen->type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CTRL_pushedChanBtnEvent(ButtonKey_t *key)
|
||||||
|
{
|
||||||
|
ULOG_TRACE("Chan btn: %d", key->instance);
|
||||||
|
GEN_channel_t channel = btn_ch_to_chan[key->instance];
|
||||||
|
|
||||||
|
_app_data->curr_gen = signal_gen[channel];
|
||||||
|
|
||||||
|
_app_data->curr_state_lay = LAY_MAIN;
|
||||||
|
_app_data->curr_state_btn = BTN_MAIN_FG;
|
||||||
|
_app_data->curr_channel = channel;
|
||||||
|
|
||||||
|
// _app_data->isChannelChange = 1;
|
||||||
|
// _app_data->isGraphChange = 1;
|
||||||
|
// _app_data->isValueChange = 1;
|
||||||
|
// _app_data->isButtonChange = 1;
|
||||||
|
// _app_data->isButtonBlink = 1;
|
||||||
|
_app_data->disp_update |= UPDATE_BUTTON | UPDATE_GRAPH | UPDATE_VALUE | UPDATE_CHANNEL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CTRL_longPushedChanBtnEvent(ButtonKey_t *key)
|
||||||
|
{
|
||||||
|
ULOG_TRACE("Chan btn(long): %d", key->instance);
|
||||||
|
GEN_channel_t channel = btn_ch_to_chan[key->instance];
|
||||||
|
|
||||||
|
switch (signal_gen[channel]->type)
|
||||||
|
{
|
||||||
|
case GEN_FG_TYPE:
|
||||||
|
{
|
||||||
|
dds_gen_t *dds_gen = (dds_gen_t *)signal_gen[channel];
|
||||||
|
dds_gen->settings.enabled = dds_gen->settings.enabled ? FALSE : TRUE;
|
||||||
|
setEnabled(signal_gen[channel]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case GEN_PWM_TYPE:
|
||||||
|
{
|
||||||
|
pwm_gen_t *pwm_gen = (pwm_gen_t *)signal_gen[channel];
|
||||||
|
pwm_gen->settings.enabled = pwm_gen->settings.enabled ? FALSE : TRUE;
|
||||||
|
setEnabled(signal_gen[channel]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
ULOG_ERROR("%s:%d: Unknown generator type: %d", __FILE__, __LINE__, _app_data->curr_gen->type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//*******************************************************************
|
||||||
|
|
||||||
|
static void _changeValueDdsGen(int8_t dir)
|
||||||
|
{
|
||||||
|
dds_gen_t *dds_gen = (dds_gen_t *)_app_data->curr_gen;
|
||||||
|
|
||||||
|
switch (_app_data->curr_state_lay)
|
||||||
|
{
|
||||||
|
case LAY_FREQ:
|
||||||
|
{
|
||||||
|
uint32_t new_freq = dir * pow_of_10[_app_data->freq_focus_digit] + dds_gen->settings.frequency;
|
||||||
|
ULOG_DEBUG("<FG> New freq: %lu", new_freq);
|
||||||
|
if (new_freq > MAX_FREQ)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dds_gen->settings.frequency = new_freq;
|
||||||
|
setFrequency(&dds_gen->super);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LAY_AMPL:
|
||||||
|
{
|
||||||
|
uint16_t new_ampl = dir * pow_of_10[_app_data->ampl_focus_digit] + dds_gen->settings.amplitude;
|
||||||
|
ULOG_DEBUG("<FG> New ampl: %u", new_ampl);
|
||||||
|
if (dds_gen->settings.offset + new_ampl > MAX_VOLT_POS || dds_gen->settings.offset - new_ampl < MAX_VOLT_NEG)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dds_gen->settings.amplitude = new_ampl;
|
||||||
|
setAmplitude(&dds_gen->super);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LAY_OFFS:
|
||||||
|
{
|
||||||
|
int16_t new_offs = dir * pow_of_10[_app_data->offs_focus_digit] + dds_gen->settings.offset;
|
||||||
|
ULOG_DEBUG("<FG> New offs: %i", new_offs);
|
||||||
|
if (new_offs + dds_gen->settings.amplitude > MAX_VOLT_POS || new_offs - dds_gen->settings.amplitude < MAX_VOLT_NEG)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dds_gen->settings.offset = new_offs;
|
||||||
|
setOfsset(&dds_gen->super);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LAY_PHAS:
|
||||||
|
{
|
||||||
|
uint16_t new_phas = dir * pow_of_10[_app_data->phas_focus_digit] + dds_gen->settings.phase;
|
||||||
|
ULOG_DEBUG("<FG> New phas: %u", new_phas);
|
||||||
|
if (new_phas > MAX_PHAS)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
dds_gen->settings.phase = new_phas;
|
||||||
|
setPhase(&dds_gen->super);
|
||||||
|
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;
|
||||||
|
_app_data->disp_update |= UPDATE_GRAPH | UPDATE_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _changeValuePwmGen(int8_t dir)
|
||||||
|
{
|
||||||
|
pwm_gen_t *pwm_gen = (pwm_gen_t *)_app_data->curr_gen;
|
||||||
|
|
||||||
|
switch (_app_data->curr_state_lay)
|
||||||
|
{
|
||||||
|
case LAY_FREQ:
|
||||||
|
{
|
||||||
|
uint32_t new_freq = dir * pow_of_10[_app_data->freq_focus_digit] + pwm_gen->settings.frequency;
|
||||||
|
ULOG_DEBUG("<PWM> New freq: %lu", new_freq);
|
||||||
|
if (new_freq > MAX_FREQ)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pwm_gen->settings.frequency = new_freq;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LAY_AMPL:
|
||||||
|
{
|
||||||
|
uint16_t new_ampl = dir * pow_of_10[_app_data->ampl_focus_digit] + pwm_gen->settings.amplitude;
|
||||||
|
ULOG_DEBUG("<PWM> New ampl: %u", new_ampl);
|
||||||
|
if (pwm_gen->settings.offset + new_ampl > MAX_VOLT_POS || pwm_gen->settings.offset - new_ampl < MAX_VOLT_NEG)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pwm_gen->settings.amplitude = new_ampl;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LAY_OFFS:
|
||||||
|
{
|
||||||
|
int16_t new_offs = dir * pow_of_10[_app_data->offs_focus_digit] + pwm_gen->settings.offset;
|
||||||
|
ULOG_DEBUG("<PWM> New offs: %i", new_offs);
|
||||||
|
if (new_offs + pwm_gen->settings.amplitude > MAX_VOLT_POS || new_offs - pwm_gen->settings.amplitude < MAX_VOLT_NEG)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pwm_gen->settings.offset = new_offs;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LAY_PHAS:
|
||||||
|
{
|
||||||
|
uint16_t new_phas = dir * pow_of_10[_app_data->phas_focus_digit] + pwm_gen->settings.phase;
|
||||||
|
ULOG_DEBUG("<PWM> New phas: %u", new_phas);
|
||||||
|
if (new_phas > MAX_PHAS)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pwm_gen->settings.phase = new_phas;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case LAY_DUTY:
|
||||||
|
{
|
||||||
|
uint8_t new_duty = dir * pow_of_10[_app_data->duty_focus_digit] + pwm_gen->settings.duty;
|
||||||
|
ULOG_DEBUG("<PWM> New duty: %u", new_duty);
|
||||||
|
if (new_duty > MAX_DUTY)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pwm_gen->settings.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;
|
||||||
|
_app_data->disp_update |= UPDATE_GRAPH | UPDATE_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _signalGenDefaultValues(void)
|
||||||
|
{
|
||||||
|
for (GEN_channel_t channel = CHANNEL1; channel < CHANNEL_MAX; channel++)
|
||||||
|
{
|
||||||
|
switch (signal_gen[channel]->type)
|
||||||
|
{
|
||||||
|
case GEN_FG_TYPE:
|
||||||
|
{
|
||||||
|
dds_gen_t *dds_gen = (dds_gen_t *)signal_gen[channel];
|
||||||
|
dds_gen->settings.frequency = 1000;
|
||||||
|
dds_gen->settings.amplitude = 100;
|
||||||
|
dds_gen->settings.offset = 165;
|
||||||
|
dds_gen->settings.phase = 0;
|
||||||
|
dds_gen->settings.wave = GEN_SIN;
|
||||||
|
dds_gen->settings.link = 0;
|
||||||
|
dds_gen->settings.enabled = FALSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case GEN_PWM_TYPE:
|
||||||
|
{
|
||||||
|
pwm_gen_t *pwm_gen = (pwm_gen_t *)signal_gen[channel];
|
||||||
|
pwm_gen->settings.frequency = 1000;
|
||||||
|
pwm_gen->settings.amplitude = 100;
|
||||||
|
pwm_gen->settings.offset = 0;
|
||||||
|
pwm_gen->settings.phase = 0;
|
||||||
|
pwm_gen->settings.duty = 50;
|
||||||
|
pwm_gen->settings.link = 0;
|
||||||
|
pwm_gen->settings.enabled = FALSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _setGenInitailState(GEN_channel_t channel)
|
||||||
|
{
|
||||||
|
setFrequency(signal_gen[channel]);
|
||||||
|
setWave(signal_gen[channel]);
|
||||||
|
setPhase(signal_gen[channel]);
|
||||||
|
setAmplitude(signal_gen[channel]);
|
||||||
|
setEnabled(signal_gen[channel]);
|
||||||
|
// setOfsset(signal_gen[channel]);
|
||||||
|
}
|
||||||
|
|
||||||
inline BITMAP_buttonName_t CTRL_getBitmapName(LAY_dispBtn_t disp_btn)
|
inline BITMAP_buttonName_t CTRL_getBitmapName(LAY_dispBtn_t disp_btn)
|
||||||
{
|
{
|
||||||
return btn_command[_app_data->curr_state_btn][disp_btn].bitmap_name;
|
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] = {
|
static const CMD_button_t btn_command[BTN_STATE_MAX][DISP_BTN_MAX] = {
|
||||||
{
|
{
|
||||||
// BTN_MAIN_FG
|
// BTN_MAIN_FG
|
||||||
{_enterToFreqLayout, BITMAP_BTN_FREQ},
|
{enterToFreqLayout, BITMAP_BTN_FREQ},
|
||||||
{_enterToAmplLayout, BITMAP_BTN_AMPL},
|
{enterToAmplLayout, BITMAP_BTN_AMPL},
|
||||||
{_enterToOffslLayout, BITMAP_BTN_OFFS},
|
{enterToOffslLayout, BITMAP_BTN_OFFS},
|
||||||
{_enterToPhasLayout, BITMAP_BTN_PHAS},
|
{enterToPhasLayout, BITMAP_BTN_PHAS},
|
||||||
{_enterToWavelLayout, BITMAP_BTN_WAVE},
|
{enterToWavelLayout, BITMAP_BTN_WAVE},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// BTN_MAIN_PWM
|
// BTN_MAIN_PWM
|
||||||
{_enterToFreqLayout, BITMAP_BTN_FREQ},
|
{enterToFreqLayout, BITMAP_BTN_FREQ},
|
||||||
{_enterToAmplLayout, BITMAP_BTN_AMPL},
|
{enterToAmplLayout, BITMAP_BTN_AMPL},
|
||||||
{_enterToOffslLayout, BITMAP_BTN_OFFS},
|
{enterToOffslLayout, BITMAP_BTN_OFFS},
|
||||||
{_enterToPhasLayout, BITMAP_BTN_PHAS},
|
{enterToPhasLayout, BITMAP_BTN_PHAS},
|
||||||
{_enterToDutyLayout, BITMAP_BTN_NONE},
|
{enterToDutyLayout, BITMAP_BTN_NONE},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// BTN_FREQ
|
// BTN_FREQ
|
||||||
{_moveToLeftFocusFreqNumber, BITMAP_BTN_LEFT},
|
{moveToLeftFocusFreqNumber, BITMAP_BTN_LEFT},
|
||||||
{_moveToRighttFocusFreqNumber, BITMAP_BTN_RIGHT},
|
{moveToRighttFocusFreqNumber, BITMAP_BTN_RIGHT},
|
||||||
{_doNoting, BITMAP_BTN_NONE},
|
{doNoting, BITMAP_BTN_NONE},
|
||||||
{_doNoting, BITMAP_BTN_NONE},
|
{doNoting, BITMAP_BTN_NONE},
|
||||||
{_backToMain, BITMAP_BTN_BACK},
|
{backToMain, BITMAP_BTN_BACK},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// BTN_FREQ_MIN
|
// BTN_FREQ_MIN
|
||||||
{_moveToLeftFocusFreqNumber, BITMAP_BTN_LEFT},
|
{moveToLeftFocusFreqNumber, BITMAP_BTN_LEFT},
|
||||||
{_doNoting, BITMAP_BTN_EMPTY},
|
{doNoting, BITMAP_BTN_EMPTY},
|
||||||
{_doNoting, BITMAP_BTN_NONE},
|
{doNoting, BITMAP_BTN_NONE},
|
||||||
{_doNoting, BITMAP_BTN_NONE},
|
{doNoting, BITMAP_BTN_NONE},
|
||||||
{_backToMain, BITMAP_BTN_BACK},
|
{backToMain, BITMAP_BTN_BACK},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// BTN_FREQ_MAX
|
// BTN_FREQ_MAX
|
||||||
{_doNoting, BITMAP_BTN_EMPTY},
|
{doNoting, BITMAP_BTN_EMPTY},
|
||||||
{_moveToRighttFocusFreqNumber, BITMAP_BTN_RIGHT},
|
{moveToRighttFocusFreqNumber, BITMAP_BTN_RIGHT},
|
||||||
{_doNoting, BITMAP_BTN_NONE},
|
{doNoting, BITMAP_BTN_NONE},
|
||||||
{_doNoting, BITMAP_BTN_NONE},
|
{doNoting, BITMAP_BTN_NONE},
|
||||||
{_backToMain, BITMAP_BTN_BACK},
|
{backToMain, BITMAP_BTN_BACK},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// BTN_AMPL
|
// BTN_AMPL
|
||||||
{_setTo1xFocusNumber, BITMAP_BTN_X1},
|
{setTo1xFocusNumber, BITMAP_BTN_X1},
|
||||||
{_setTo0_1xFocusNumber, BITMAP_BTN_X0_1},
|
{setTo0_1xFocusNumber, BITMAP_BTN_X0_1},
|
||||||
{_setTo0_01xFocusNumber, BITMAP_BTN_X0_01},
|
{setTo0_01xFocusNumber, BITMAP_BTN_X0_01},
|
||||||
{_doNoting, BITMAP_BTN_NONE},
|
{doNoting, BITMAP_BTN_NONE},
|
||||||
{_backToMain, BITMAP_BTN_BACK},
|
{backToMain, BITMAP_BTN_BACK},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// BTN_OFFS
|
// BTN_OFFS
|
||||||
{_setTo1xFocusNumber, BITMAP_BTN_X1},
|
{setTo1xFocusNumber, BITMAP_BTN_X1},
|
||||||
{_setTo0_1xFocusNumber, BITMAP_BTN_X0_1},
|
{setTo0_1xFocusNumber, BITMAP_BTN_X0_1},
|
||||||
{_setTo0_01xFocusNumber, BITMAP_BTN_X0_01},
|
{setTo0_01xFocusNumber, BITMAP_BTN_X0_01},
|
||||||
{_doNoting, BITMAP_BTN_NONE},
|
{doNoting, BITMAP_BTN_NONE},
|
||||||
{_backToMain, BITMAP_BTN_BACK},
|
{backToMain, BITMAP_BTN_BACK},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// BTN_PHAS
|
// BTN_PHAS
|
||||||
{_setTo10xFocusNumber, BITMAP_BTN_X10},
|
{setTo10xFocusNumber, BITMAP_BTN_X10},
|
||||||
{_setTo1xFocusNumber, BITMAP_BTN_X1},
|
{setTo1xFocusNumber, BITMAP_BTN_X1},
|
||||||
{_doNoting, BITMAP_BTN_NONE},
|
{doNoting, BITMAP_BTN_NONE},
|
||||||
{_doNoting, BITMAP_BTN_NONE},
|
{doNoting, BITMAP_BTN_NONE},
|
||||||
{_backToMain, BITMAP_BTN_BACK},
|
{backToMain, BITMAP_BTN_BACK},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// BTN_DUTY
|
// BTN_DUTY
|
||||||
{_setTo10xFocusNumber, BITMAP_BTN_X10},
|
{setTo10xFocusNumber, BITMAP_BTN_X10},
|
||||||
{_setTo1xFocusNumber, BITMAP_BTN_X1},
|
{setTo1xFocusNumber, BITMAP_BTN_X1},
|
||||||
{_doNoting, BITMAP_BTN_NONE},
|
{doNoting, BITMAP_BTN_NONE},
|
||||||
{_doNoting, BITMAP_BTN_NONE},
|
{doNoting, BITMAP_BTN_NONE},
|
||||||
{_backToMain, BITMAP_BTN_BACK},
|
{backToMain, BITMAP_BTN_BACK},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// BTN_WAVE
|
// BTN_WAVE
|
||||||
{_doNoting, BITMAP_BTN_NONE},
|
{doNoting, BITMAP_BTN_NONE},
|
||||||
{_doNoting, BITMAP_BTN_NONE},
|
{doNoting, BITMAP_BTN_NONE},
|
||||||
{_doNoting, BITMAP_BTN_NONE},
|
{doNoting, BITMAP_BTN_NONE},
|
||||||
{_doNoting, BITMAP_BTN_NONE},
|
{doNoting, BITMAP_BTN_NONE},
|
||||||
{_backToMain, BITMAP_BTN_BACK},
|
{backToMain, BITMAP_BTN_BACK},
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -3,56 +3,6 @@
|
|||||||
#include "bitmap_disp_buttons.h"
|
#include "bitmap_disp_buttons.h"
|
||||||
#include "ctrl_app_types.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 APP_init(APP_data_t *app_data);
|
||||||
void CTRL_buttonsInit(void);
|
void CTRL_buttonsInit(void);
|
||||||
|
|||||||
124
firmware/shared_libs/controllers/ctrl_app_defs.h
Normal file
124
firmware/shared_libs/controllers/ctrl_app_defs.h
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define FUN_GEN_FOCUS_MAX 6U
|
||||||
|
#define PWM_GEN_FOCUS_MAX 4U
|
||||||
|
#define MAX_FREQ 1000000U
|
||||||
|
#define MAX_VOLT_POS 360
|
||||||
|
#define MAX_VOLT_NEG 0
|
||||||
|
#define MAX_PHAS 360
|
||||||
|
#define MAX_DUTY 100
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
FALSE,
|
||||||
|
TRUE
|
||||||
|
} bool_t;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
GEN_FG_TYPE,
|
||||||
|
GEN_PWM_TYPE,
|
||||||
|
GEN_TYPE_MAX
|
||||||
|
} GEN_type_t;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
DDS_CH1,
|
||||||
|
DDS_CH2,
|
||||||
|
DDS_CH3,
|
||||||
|
DDS_CH_MAX,
|
||||||
|
} DDS_channel_t;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
PWM_CH1,
|
||||||
|
PWM_CH2,
|
||||||
|
PWM_CH3,
|
||||||
|
PWM_CH_MAX,
|
||||||
|
} PWM_channel_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;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
UPDATE_CHANNEL = 1,
|
||||||
|
UPDATE_GRAPH = 2,
|
||||||
|
UPDATE_VALUE = 4,
|
||||||
|
UPDATE_BUTTON = 8,
|
||||||
|
UPDATE_ALL = 15,
|
||||||
|
} LAY_update_t;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
FREQ_LINK1 = 1,
|
||||||
|
FREQ_LINK2 = 2,
|
||||||
|
AMPL_LINK1 = 4,
|
||||||
|
AMPL_LINK2 = 8,
|
||||||
|
OFFS_LINK1 = 16,
|
||||||
|
OFFS_LINK2 = 32,
|
||||||
|
PHAS_LINK1 = 64,
|
||||||
|
PHAS_LINK2 = 128,
|
||||||
|
} GEN_linkMask_t;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
MCU_CS1,
|
||||||
|
MCU_CS2,
|
||||||
|
MCU_CS3,
|
||||||
|
MCU_CS4,
|
||||||
|
MCU_CS_MAX,
|
||||||
|
} MCU_cs_count_t;
|
||||||
@@ -1,72 +1,106 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "main.h"
|
||||||
|
#include "ad9833.h"
|
||||||
|
#include "mcp41x.h"
|
||||||
|
#include "ltc2631.h"
|
||||||
|
#include "ctrl_app_defs.h"
|
||||||
|
|
||||||
#define FUN_GEN_FOCUS_MAX 6U
|
typedef struct
|
||||||
#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,
|
uint32_t frequency;
|
||||||
GEN_PWM_TYPE,
|
uint16_t amplitude;
|
||||||
GEN_TYPE_MAX
|
int16_t offset;
|
||||||
} GEN_type_t;
|
uint16_t phase;
|
||||||
|
uint8_t duty;
|
||||||
|
uint8_t link;
|
||||||
|
bool_t enabled;
|
||||||
|
} pwm_settings_t;
|
||||||
|
|
||||||
typedef enum
|
typedef struct
|
||||||
{
|
{
|
||||||
CHANNEL1,
|
uint32_t frequency;
|
||||||
CHANNEL2,
|
uint16_t amplitude;
|
||||||
CHANNEL3,
|
int16_t offset;
|
||||||
CHANNEL4,
|
uint16_t phase;
|
||||||
CHANNEL5,
|
uint8_t wave;
|
||||||
CHANNEL6,
|
uint8_t link;
|
||||||
CHANNEL_MAX
|
uint8_t enabled;
|
||||||
} GEN_channel_t;
|
} dds_settings_t;
|
||||||
|
|
||||||
typedef enum
|
typedef struct
|
||||||
{
|
{
|
||||||
GEN_SIN,
|
GPIO_TypeDef *port;
|
||||||
GEN_TRI,
|
uint16_t pin;
|
||||||
GEN_SQR,
|
} led_handle_t;
|
||||||
GEN_WAVE_MAX,
|
|
||||||
} GEN_wave_t;
|
|
||||||
|
|
||||||
typedef enum
|
typedef struct FG_handle_s
|
||||||
{
|
{
|
||||||
LAY_MAIN,
|
ad9833_handle_t hdds;
|
||||||
LAY_FREQ,
|
ltc2631_handle_t hoffs;
|
||||||
LAY_AMPL,
|
mcp41x_handle_t hampl;
|
||||||
LAY_OFFS,
|
led_handle_t hled;
|
||||||
LAY_PHAS,
|
} dds_handle_t;
|
||||||
LAY_DUTY,
|
|
||||||
LAY_WAVE,
|
|
||||||
LAY_STATE_MAX
|
|
||||||
} STATE_layout_t;
|
|
||||||
|
|
||||||
typedef enum
|
typedef uint8_t timer_handle_t;
|
||||||
|
typedef struct
|
||||||
{
|
{
|
||||||
BTN_MAIN_FG,
|
timer_handle_t hpwm;
|
||||||
BTN_MAIN_PWM,
|
ltc2631_handle_t hoffs;
|
||||||
BTN_FREQ,
|
mcp41x_handle_t hampl;
|
||||||
BTN_FREQ_MIN,
|
led_handle_t hled;
|
||||||
BTN_FREQ_MAX,
|
} pwm_handle_t;
|
||||||
BTN_AMPL,
|
|
||||||
BTN_OFFS,
|
|
||||||
BTN_PHAS,
|
|
||||||
BTN_DUTY,
|
|
||||||
BTN_WAVE,
|
|
||||||
BTN_STATE_MAX
|
|
||||||
} STATE_button_t;
|
|
||||||
|
|
||||||
typedef enum
|
typedef struct
|
||||||
{
|
{
|
||||||
DISP_BTN_1,
|
GEN_type_t const type;
|
||||||
DISP_BTN_2,
|
} signal_gen_t;
|
||||||
DISP_BTN_3,
|
|
||||||
DISP_BTN_4,
|
typedef struct
|
||||||
DISP_BTN_5,
|
{
|
||||||
DISP_BTN_MAX,
|
signal_gen_t *next;
|
||||||
} LAY_dispBtn_t;
|
signal_gen_t *prev;
|
||||||
|
} link_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
signal_gen_t super;
|
||||||
|
DDS_channel_t const dds_ch;
|
||||||
|
dds_settings_t settings;
|
||||||
|
dds_handle_t handle;
|
||||||
|
link_t link;
|
||||||
|
} dds_gen_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
signal_gen_t super;
|
||||||
|
PWM_channel_t const pwm_ch;
|
||||||
|
pwm_settings_t settings;
|
||||||
|
pwm_handle_t handle;
|
||||||
|
link_t link;
|
||||||
|
} pwm_gen_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;
|
||||||
|
|
||||||
|
signal_gen_t *curr_gen;
|
||||||
|
|
||||||
|
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;
|
||||||
|
LAY_update_t disp_update;
|
||||||
|
uint8_t button_blink;
|
||||||
|
uint8_t timer_blink[DISP_BTN_MAX];
|
||||||
|
|
||||||
|
LAY_dispBtn_t last_key;
|
||||||
|
|
||||||
|
} APP_data_t;
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "hw_button.h"
|
|
||||||
// #include "ctrl_app.h"
|
|
||||||
#include "ctrl_bottom_button.h"
|
#include "ctrl_bottom_button.h"
|
||||||
|
|
||||||
static ButtonKey_t bottom_buttons[BTN_BOT_MAX];
|
static ButtonKey_t bottom_buttons[BTN_BOT_MAX];
|
||||||
@@ -11,31 +9,31 @@ void CTRL_bottomButtonInit(void)
|
|||||||
bottom_buttons[BTN_BOT_1].buttonPressed = CTRL_pushedDispBtnEvent;
|
bottom_buttons[BTN_BOT_1].buttonPressed = CTRL_pushedDispBtnEvent;
|
||||||
bottom_buttons[BTN_BOT_1].gpio_port = BTN1_GPIO_Port;
|
bottom_buttons[BTN_BOT_1].gpio_port = BTN1_GPIO_Port;
|
||||||
bottom_buttons[BTN_BOT_1].gpio_pin = BTN1_Pin;
|
bottom_buttons[BTN_BOT_1].gpio_pin = BTN1_Pin;
|
||||||
bottom_buttons[BTN_BOT_1].pushed_state = GPIO_PIN_SET;
|
bottom_buttons[BTN_BOT_1].pushed_state = GPIO_PIN_RESET;
|
||||||
|
|
||||||
bottom_buttons[BTN_BOT_2].instance = BTN_BOT_2;
|
bottom_buttons[BTN_BOT_2].instance = BTN_BOT_2;
|
||||||
bottom_buttons[BTN_BOT_2].buttonPressed = CTRL_pushedDispBtnEvent;
|
bottom_buttons[BTN_BOT_2].buttonPressed = CTRL_pushedDispBtnEvent;
|
||||||
bottom_buttons[BTN_BOT_2].gpio_port = BTN2_GPIO_Port;
|
bottom_buttons[BTN_BOT_2].gpio_port = BTN2_GPIO_Port;
|
||||||
bottom_buttons[BTN_BOT_2].gpio_pin = BTN2_Pin;
|
bottom_buttons[BTN_BOT_2].gpio_pin = BTN2_Pin;
|
||||||
bottom_buttons[BTN_BOT_2].pushed_state = GPIO_PIN_SET;
|
bottom_buttons[BTN_BOT_2].pushed_state = GPIO_PIN_RESET;
|
||||||
|
|
||||||
bottom_buttons[BTN_BOT_3].instance = BTN_BOT_3;
|
bottom_buttons[BTN_BOT_3].instance = BTN_BOT_3;
|
||||||
bottom_buttons[BTN_BOT_3].buttonPressed = CTRL_pushedDispBtnEvent;
|
bottom_buttons[BTN_BOT_3].buttonPressed = CTRL_pushedDispBtnEvent;
|
||||||
bottom_buttons[BTN_BOT_3].gpio_port = BTN3_GPIO_Port;
|
bottom_buttons[BTN_BOT_3].gpio_port = BTN3_GPIO_Port;
|
||||||
bottom_buttons[BTN_BOT_3].gpio_pin = BTN3_Pin;
|
bottom_buttons[BTN_BOT_3].gpio_pin = BTN3_Pin;
|
||||||
bottom_buttons[BTN_BOT_3].pushed_state = GPIO_PIN_SET;
|
bottom_buttons[BTN_BOT_3].pushed_state = GPIO_PIN_RESET;
|
||||||
|
|
||||||
bottom_buttons[BTN_BOT_4].instance = BTN_BOT_4;
|
bottom_buttons[BTN_BOT_4].instance = BTN_BOT_4;
|
||||||
bottom_buttons[BTN_BOT_4].buttonPressed = CTRL_pushedDispBtnEvent;
|
bottom_buttons[BTN_BOT_4].buttonPressed = CTRL_pushedDispBtnEvent;
|
||||||
bottom_buttons[BTN_BOT_4].gpio_port = BTN4_GPIO_Port;
|
bottom_buttons[BTN_BOT_4].gpio_port = BTN4_GPIO_Port;
|
||||||
bottom_buttons[BTN_BOT_4].gpio_pin = BTN4_Pin;
|
bottom_buttons[BTN_BOT_4].gpio_pin = BTN4_Pin;
|
||||||
bottom_buttons[BTN_BOT_4].pushed_state = GPIO_PIN_SET;
|
bottom_buttons[BTN_BOT_4].pushed_state = GPIO_PIN_RESET;
|
||||||
|
|
||||||
bottom_buttons[BTN_BOT_5].instance = BTN_BOT_5;
|
bottom_buttons[BTN_BOT_5].instance = BTN_BOT_5;
|
||||||
bottom_buttons[BTN_BOT_5].buttonPressed = CTRL_pushedDispBtnEvent;
|
bottom_buttons[BTN_BOT_5].buttonPressed = CTRL_pushedDispBtnEvent;
|
||||||
bottom_buttons[BTN_BOT_5].gpio_port = BTN5_GPIO_Port;
|
bottom_buttons[BTN_BOT_5].gpio_port = BTN5_GPIO_Port;
|
||||||
bottom_buttons[BTN_BOT_5].gpio_pin = BTN5_Pin;
|
bottom_buttons[BTN_BOT_5].gpio_pin = BTN5_Pin;
|
||||||
bottom_buttons[BTN_BOT_5].pushed_state = GPIO_PIN_SET;
|
bottom_buttons[BTN_BOT_5].pushed_state = GPIO_PIN_RESET;
|
||||||
|
|
||||||
for (HW_BotBtnName_t btn_key = BTN_BOT_1; btn_key < BTN_BOT_MAX; btn_key++)
|
for (HW_BotBtnName_t btn_key = BTN_BOT_1; btn_key < BTN_BOT_MAX; btn_key++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "hw_button.h"
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
BTN_BOT_1,
|
BTN_BOT_1,
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "hw_button.h"
|
|
||||||
#include "ctrl_channel_button.h"
|
#include "ctrl_channel_button.h"
|
||||||
|
|
||||||
#define DUMMY_GPIO_Port GPIOA
|
#define DUMMY_GPIO_Port B1_GPIO_Port
|
||||||
#define DUMMY_GPIO_Pin GPIO_PIN_0
|
#define DUMMY_GPIO_Pin B1_Pin
|
||||||
|
|
||||||
static ButtonKey_t channel_buttons[BTN_CH_MAX];
|
static ButtonKey_t channel_buttons[BTN_CH_MAX];
|
||||||
|
|
||||||
@@ -11,39 +10,41 @@ void CTRL_channelButtonInit(void)
|
|||||||
{
|
{
|
||||||
channel_buttons[BTN_CH_1].instance = BTN_CH_1;
|
channel_buttons[BTN_CH_1].instance = BTN_CH_1;
|
||||||
channel_buttons[BTN_CH_1].buttonPressed = CTRL_pushedChanBtnEvent;
|
channel_buttons[BTN_CH_1].buttonPressed = CTRL_pushedChanBtnEvent;
|
||||||
channel_buttons[BTN_CH_1].gpio_port = DUMMY_GPIO_Port;
|
channel_buttons[BTN_CH_1].buttonLongPressed = CTRL_longPushedChanBtnEvent;
|
||||||
channel_buttons[BTN_CH_1].gpio_pin = DUMMY_GPIO_Pin;
|
channel_buttons[BTN_CH_1].gpio_port = BTN_CH1_GPIO_Port;
|
||||||
channel_buttons[BTN_CH_1].pushed_state = GPIO_PIN_SET;
|
channel_buttons[BTN_CH_1].gpio_pin = BTN_CH1_Pin;
|
||||||
|
channel_buttons[BTN_CH_1].pushed_state = GPIO_PIN_RESET;
|
||||||
|
|
||||||
channel_buttons[BTN_CH_2].instance = BTN_CH_2;
|
channel_buttons[BTN_CH_2].instance = BTN_CH_2;
|
||||||
channel_buttons[BTN_CH_2].buttonPressed = CTRL_pushedChanBtnEvent;
|
channel_buttons[BTN_CH_2].buttonPressed = CTRL_pushedChanBtnEvent;
|
||||||
channel_buttons[BTN_CH_2].gpio_port = DUMMY_GPIO_Port;
|
channel_buttons[BTN_CH_2].buttonLongPressed = CTRL_longPushedChanBtnEvent;
|
||||||
channel_buttons[BTN_CH_2].gpio_pin = DUMMY_GPIO_Pin;
|
channel_buttons[BTN_CH_2].gpio_port = BTN_CH2_GPIO_Port;
|
||||||
channel_buttons[BTN_CH_2].pushed_state = GPIO_PIN_SET;
|
channel_buttons[BTN_CH_2].gpio_pin = BTN_CH2_Pin;
|
||||||
|
channel_buttons[BTN_CH_2].pushed_state = GPIO_PIN_RESET;
|
||||||
|
|
||||||
channel_buttons[BTN_CH_3].instance = BTN_CH_3;
|
channel_buttons[BTN_CH_3].instance = BTN_CH_3;
|
||||||
channel_buttons[BTN_CH_3].buttonPressed = CTRL_pushedChanBtnEvent;
|
channel_buttons[BTN_CH_3].buttonPressed = CTRL_pushedChanBtnEvent;
|
||||||
channel_buttons[BTN_CH_3].gpio_port = DUMMY_GPIO_Port;
|
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].gpio_pin = DUMMY_GPIO_Pin;
|
||||||
channel_buttons[BTN_CH_3].pushed_state = GPIO_PIN_SET;
|
channel_buttons[BTN_CH_3].pushed_state = GPIO_PIN_RESET;
|
||||||
|
|
||||||
channel_buttons[BTN_CH_4].instance = BTN_CH_4;
|
channel_buttons[BTN_CH_4].instance = BTN_CH_4;
|
||||||
channel_buttons[BTN_CH_4].buttonPressed = CTRL_pushedChanBtnEvent;
|
channel_buttons[BTN_CH_4].buttonPressed = CTRL_pushedChanBtnEvent;
|
||||||
channel_buttons[BTN_CH_4].gpio_port = DUMMY_GPIO_Port;
|
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].gpio_pin = DUMMY_GPIO_Pin;
|
||||||
channel_buttons[BTN_CH_4].pushed_state = GPIO_PIN_SET;
|
channel_buttons[BTN_CH_4].pushed_state = GPIO_PIN_RESET;
|
||||||
|
|
||||||
channel_buttons[BTN_CH_5].instance = BTN_CH_5;
|
channel_buttons[BTN_CH_5].instance = BTN_CH_5;
|
||||||
channel_buttons[BTN_CH_5].buttonPressed = CTRL_pushedChanBtnEvent;
|
channel_buttons[BTN_CH_5].buttonPressed = CTRL_pushedChanBtnEvent;
|
||||||
channel_buttons[BTN_CH_5].gpio_port = DUMMY_GPIO_Port;
|
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].gpio_pin = DUMMY_GPIO_Pin;
|
||||||
channel_buttons[BTN_CH_5].pushed_state = GPIO_PIN_SET;
|
channel_buttons[BTN_CH_5].pushed_state = GPIO_PIN_RESET;
|
||||||
|
|
||||||
channel_buttons[BTN_CH_6].instance = BTN_CH_6;
|
channel_buttons[BTN_CH_6].instance = BTN_CH_6;
|
||||||
channel_buttons[BTN_CH_6].buttonPressed = CTRL_pushedChanBtnEvent;
|
channel_buttons[BTN_CH_6].buttonPressed = CTRL_pushedChanBtnEvent;
|
||||||
channel_buttons[BTN_CH_6].gpio_port = DUMMY_GPIO_Port;
|
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].gpio_pin = DUMMY_GPIO_Pin;
|
||||||
channel_buttons[BTN_CH_6].pushed_state = GPIO_PIN_SET;
|
channel_buttons[BTN_CH_6].pushed_state = GPIO_PIN_RESET;
|
||||||
|
|
||||||
for (HW_chanBtnName_t btn_key = BTN_CH_1; btn_key < BTN_CH_MAX; btn_key++)
|
for (HW_chanBtnName_t btn_key = BTN_CH_1; btn_key < BTN_CH_MAX; btn_key++)
|
||||||
{
|
{
|
||||||
@@ -63,6 +64,11 @@ void CTRL_channelButtonsHandler(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
__weak void CTRL_pushedChanBtnEvent(ButtonKey_t *key)
|
__weak void CTRL_pushedChanBtnEvent(ButtonKey_t *key)
|
||||||
|
{
|
||||||
|
UNUSED(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
__weak void CTRL_longPushedChanBtnEvent(ButtonKey_t *key)
|
||||||
{
|
{
|
||||||
UNUSED(key);
|
UNUSED(key);
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "hw_button.h"
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
BTN_CH_1,
|
BTN_CH_1,
|
||||||
@@ -13,4 +15,5 @@ typedef enum
|
|||||||
|
|
||||||
void CTRL_channelButtonInit(void);
|
void CTRL_channelButtonInit(void);
|
||||||
void CTRL_channelButtonsHandler(void);
|
void CTRL_channelButtonsHandler(void);
|
||||||
void CTRL_pushedChanBtnEvent(ButtonKey_t *key);
|
void CTRL_pushedChanBtnEvent(ButtonKey_t *key);
|
||||||
|
void CTRL_longPushedChanBtnEvent(ButtonKey_t *key);
|
||||||
244
firmware/shared_libs/controllers/ctrl_disp_button.c
Normal file
244
firmware/shared_libs/controllers/ctrl_disp_button.c
Normal file
@@ -0,0 +1,244 @@
|
|||||||
|
#include "ctrl_disp_button.h"
|
||||||
|
|
||||||
|
void doNoting(APP_data_t *app_data)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void backToMain(APP_data_t *app_data)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
app_data->disp_update = UPDATE_ALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void blockFocusAtMaxAndMin(APP_data_t *app_data)
|
||||||
|
{
|
||||||
|
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->disp_update |= UPDATE_BUTTON;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BTN_FREQ_MAX:
|
||||||
|
if (app_data->freq_focus_digit < FUN_GEN_FOCUS_MAX)
|
||||||
|
{
|
||||||
|
app_data->curr_state_btn = BTN_FREQ;
|
||||||
|
app_data->disp_update |= UPDATE_BUTTON;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case BTN_FREQ:
|
||||||
|
if (app_data->freq_focus_digit == 0)
|
||||||
|
{
|
||||||
|
app_data->curr_state_btn = BTN_FREQ_MIN;
|
||||||
|
app_data->disp_update |= UPDATE_BUTTON;
|
||||||
|
}
|
||||||
|
else if (app_data->freq_focus_digit == FUN_GEN_FOCUS_MAX)
|
||||||
|
{
|
||||||
|
app_data->curr_state_btn = BTN_FREQ_MAX;
|
||||||
|
app_data->disp_update |= UPDATE_BUTTON;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void enterToFreqLayout(APP_data_t *app_data)
|
||||||
|
{
|
||||||
|
app_data->curr_state_lay = LAY_FREQ;
|
||||||
|
app_data->curr_state_btn = BTN_FREQ;
|
||||||
|
blockFocusAtMaxAndMin(app_data);
|
||||||
|
|
||||||
|
// app_data->isButtonChange = 1;
|
||||||
|
// app_data->isGraphChange = 1;
|
||||||
|
// app_data->isValueChange = 1;
|
||||||
|
app_data->disp_update |= UPDATE_BUTTON | UPDATE_GRAPH | UPDATE_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void enterToAmplLayout(APP_data_t *app_data)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
app_data->disp_update |= UPDATE_BUTTON | UPDATE_GRAPH | UPDATE_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void enterToOffslLayout(APP_data_t *app_data)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
app_data->disp_update |= UPDATE_BUTTON | UPDATE_GRAPH | UPDATE_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void enterToPhasLayout(APP_data_t *app_data)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
app_data->disp_update |= UPDATE_BUTTON | UPDATE_GRAPH | UPDATE_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void enterToDutyLayout(APP_data_t *app_data)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
app_data->disp_update |= UPDATE_BUTTON | UPDATE_GRAPH | UPDATE_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void enterToWavelLayout(APP_data_t *app_data)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
app_data->disp_update |= UPDATE_BUTTON | UPDATE_GRAPH | UPDATE_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void moveToLeftFocusFreqNumber(APP_data_t *app_data)
|
||||||
|
{
|
||||||
|
app_data->freq_focus_digit += 1;
|
||||||
|
// app_data->isValueChange = 1;
|
||||||
|
app_data->disp_update |= UPDATE_VALUE;
|
||||||
|
|
||||||
|
blockFocusAtMaxAndMin(app_data);
|
||||||
|
app_data->timer_blink[app_data->last_key] = 2;
|
||||||
|
app_data->button_blink |= (1 << app_data->last_key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void moveToRighttFocusFreqNumber(APP_data_t *app_data)
|
||||||
|
{
|
||||||
|
app_data->freq_focus_digit -= 1;
|
||||||
|
// app_data->isValueChange = 1;
|
||||||
|
app_data->disp_update |= UPDATE_VALUE;
|
||||||
|
|
||||||
|
blockFocusAtMaxAndMin(app_data);
|
||||||
|
app_data->timer_blink[app_data->last_key] = 2;
|
||||||
|
app_data->button_blink |= (1 << app_data->last_key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setTo0_01xFocusNumber(APP_data_t *app_data)
|
||||||
|
{
|
||||||
|
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[app_data->last_key] = 2;
|
||||||
|
app_data->button_blink |= (1 << app_data->last_key);
|
||||||
|
// app_data->isValueChange = 1;
|
||||||
|
app_data->disp_update |= UPDATE_VALUE;
|
||||||
|
}
|
||||||
|
void setTo0_1xFocusNumber(APP_data_t *app_data)
|
||||||
|
{
|
||||||
|
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[app_data->last_key] = 2;
|
||||||
|
app_data->button_blink |= (1 << app_data->last_key);
|
||||||
|
// app_data->isValueChange = 1;
|
||||||
|
app_data->disp_update |= UPDATE_VALUE;
|
||||||
|
}
|
||||||
|
void setTo1xFocusNumber(APP_data_t *app_data)
|
||||||
|
{
|
||||||
|
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[app_data->last_key] = 2;
|
||||||
|
app_data->button_blink |= (1 << app_data->last_key);
|
||||||
|
// app_data->isValueChange = 1;
|
||||||
|
app_data->disp_update |= UPDATE_VALUE;
|
||||||
|
}
|
||||||
|
void setTo10xFocusNumber(APP_data_t *app_data)
|
||||||
|
{
|
||||||
|
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[app_data->last_key] = 2;
|
||||||
|
app_data->button_blink |= (1 << app_data->last_key);
|
||||||
|
// app_data->isValueChange = 1;
|
||||||
|
app_data->disp_update |= UPDATE_VALUE;
|
||||||
|
}
|
||||||
18
firmware/shared_libs/controllers/ctrl_disp_button.h
Normal file
18
firmware/shared_libs/controllers/ctrl_disp_button.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "ctrl_app_types.h"
|
||||||
|
|
||||||
|
void doNoting(APP_data_t *app_data);
|
||||||
|
void backToMain(APP_data_t *app_data);
|
||||||
|
void blockFocusAtMaxAndMin(APP_data_t *app_data);
|
||||||
|
void enterToFreqLayout(APP_data_t *app_data);
|
||||||
|
void enterToAmplLayout(APP_data_t *app_data);
|
||||||
|
void enterToOffslLayout(APP_data_t *app_data);
|
||||||
|
void enterToPhasLayout(APP_data_t *app_data);
|
||||||
|
void enterToDutyLayout(APP_data_t *app_data);
|
||||||
|
void enterToWavelLayout(APP_data_t *app_data);
|
||||||
|
void moveToLeftFocusFreqNumber(APP_data_t *app_data);
|
||||||
|
void moveToRighttFocusFreqNumber(APP_data_t *app_data);
|
||||||
|
void setTo0_01xFocusNumber(APP_data_t *app_data);
|
||||||
|
void setTo0_1xFocusNumber(APP_data_t *app_data);
|
||||||
|
void setTo1xFocusNumber(APP_data_t *app_data);
|
||||||
|
void setTo10xFocusNumber(APP_data_t *app_data);
|
||||||
478
firmware/shared_libs/controllers/ctrl_signal_gen.c
Normal file
478
firmware/shared_libs/controllers/ctrl_signal_gen.c
Normal file
@@ -0,0 +1,478 @@
|
|||||||
|
#include "spi.h"
|
||||||
|
#include "ctrl_app_types.h"
|
||||||
|
#include "mcu_cs.h"
|
||||||
|
#include "led.h"
|
||||||
|
|
||||||
|
static MCU_cs_t mcu_cs[MCU_CS_MAX];
|
||||||
|
|
||||||
|
// ************************
|
||||||
|
// INITIALIZATION
|
||||||
|
// ************************
|
||||||
|
|
||||||
|
static void _dds_init(dds_gen_t *dds_gen)
|
||||||
|
{
|
||||||
|
dds_gen->link.next = &dds_gen->super;
|
||||||
|
dds_gen->link.prev = &dds_gen->super;
|
||||||
|
|
||||||
|
switch (dds_gen->dds_ch)
|
||||||
|
{
|
||||||
|
case DDS_CH1:
|
||||||
|
mcu_cs_init(&mcu_cs[MCU_CS1], DDS1_CS_GPIO_Port, DDS1_CS_Pin, GPIO_PIN_SET);
|
||||||
|
ad9833_init(&dds_gen->handle.hdds, &hspi2, &mcu_cs[MCU_CS1].super);
|
||||||
|
|
||||||
|
mcu_cs_init(&mcu_cs[MCU_CS2], AMP1_CS_GPIO_Port, AMP1_CS_Pin, GPIO_PIN_SET);
|
||||||
|
mcp41x_init(&dds_gen->handle.hampl, &hspi2, &mcu_cs[MCU_CS2].super, MCP41X_10K);
|
||||||
|
|
||||||
|
led_init(&dds_gen->handle.hled, LED_CH1_GPIO_Port, LED_CH1_Pin);
|
||||||
|
break;
|
||||||
|
case DDS_CH2:
|
||||||
|
mcu_cs_init(&mcu_cs[MCU_CS3], DDS2_CS_GPIO_Port, DDS2_CS_Pin, GPIO_PIN_SET);
|
||||||
|
ad9833_init(&dds_gen->handle.hdds, &hspi2, &mcu_cs[MCU_CS3].super);
|
||||||
|
|
||||||
|
mcu_cs_init(&mcu_cs[MCU_CS4], AMP2_CS_GPIO_Port, AMP2_CS_Pin, GPIO_PIN_SET);
|
||||||
|
mcp41x_init(&dds_gen->handle.hampl, &hspi2, &mcu_cs[MCU_CS4].super, MCP41X_10K);
|
||||||
|
|
||||||
|
led_init(&dds_gen->handle.hled, LED_CH2_GPIO_Port, LED_CH2_Pin);
|
||||||
|
break;
|
||||||
|
case DDS_CH3:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _pwm_init(pwm_gen_t *pwm_gen)
|
||||||
|
{
|
||||||
|
switch (pwm_gen->pwm_ch)
|
||||||
|
{
|
||||||
|
case PWM_CH1:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case PWM_CH2:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case PWM_CH3:
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GEN_init(signal_gen_t **signal_gen)
|
||||||
|
{
|
||||||
|
for (GEN_channel_t channel = CHANNEL1; channel < CHANNEL_MAX; channel++)
|
||||||
|
{
|
||||||
|
switch (signal_gen[channel]->type)
|
||||||
|
{
|
||||||
|
case GEN_FG_TYPE:
|
||||||
|
_dds_init((dds_gen_t *)signal_gen[channel]);
|
||||||
|
case GEN_PWM_TYPE:
|
||||||
|
_pwm_init((pwm_gen_t *)signal_gen[channel]);
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ad9833_init(&dds_gen[FG_CHAN3].hdds, &hspi2, DDS3_CS_PORT, DDS3_CS_PIN);
|
||||||
|
|
||||||
|
// ltc2631_init(&dds_gen[FG_CHAN1].hoffs, &hi2c1, 0x00, LTC2631_8BIT, LTC_REF_2V5);
|
||||||
|
// ltc2631_init(&dds_gen[FG_CHAN2].hoffs, &hi2c1, 0x01, LTC2631_8BIT, LTC_REF_2V5);
|
||||||
|
// ltc2631_init(&dds_gen[FG_CHAN3].hoffs, &hi2c1, 0x02, LTC2631_8BIT, LTC_REF_2V5);
|
||||||
|
|
||||||
|
// mcp41x_init(&dds_gen[FG_CHAN3].hampl, &hspi2, AMP3_CS_PORT, AMP3_CS_PIN, MCP41X_10K);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ************************
|
||||||
|
// AMPLITIUDE
|
||||||
|
// ************************
|
||||||
|
|
||||||
|
static void _setAmpliude(mcp41x_handle_t *hampl, uint16_t ampl_x100)
|
||||||
|
{
|
||||||
|
uint8_t value = (ampl_x100 * UINT8_MAX) / MAX_VOLT_POS;
|
||||||
|
ULOG_DEBUG("(%d:_setAmplitude) ampl_x100: %d, value: %d", __LINE__, ampl_x100, value);
|
||||||
|
|
||||||
|
mcp41x_setValue(hampl, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setAmplitude(signal_gen_t *sig_gen)
|
||||||
|
{
|
||||||
|
static signal_gen_t *curr_sig_gen = NULL;
|
||||||
|
|
||||||
|
if (curr_sig_gen == NULL)
|
||||||
|
{
|
||||||
|
curr_sig_gen = sig_gen;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (sig_gen->type)
|
||||||
|
{
|
||||||
|
case GEN_FG_TYPE:
|
||||||
|
{
|
||||||
|
dds_gen_t *dds_gen = (dds_gen_t *)sig_gen;
|
||||||
|
signal_gen_t *next_sig_gen = dds_gen->link.next;
|
||||||
|
|
||||||
|
_setAmpliude(&dds_gen->handle.hampl, dds_gen->settings.amplitude);
|
||||||
|
|
||||||
|
if (next_sig_gen != curr_sig_gen)
|
||||||
|
{
|
||||||
|
setAmplitude(next_sig_gen);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
curr_sig_gen = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case GEN_PWM_TYPE:
|
||||||
|
{
|
||||||
|
pwm_gen_t *pwm_gen = (pwm_gen_t *)sig_gen;
|
||||||
|
signal_gen_t *next_sig_gen = pwm_gen->link.next;
|
||||||
|
|
||||||
|
_setAmpliude(&pwm_gen->handle.hampl, pwm_gen->settings.amplitude);
|
||||||
|
|
||||||
|
if (next_sig_gen != curr_sig_gen)
|
||||||
|
{
|
||||||
|
setAmplitude(next_sig_gen);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
curr_sig_gen = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
ULOG_ERROR("%s:%d: Unknown generator type: %d", __FILE__, __LINE__, sig_gen->type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ************************
|
||||||
|
// OFFSET
|
||||||
|
// ************************
|
||||||
|
|
||||||
|
static void _setOffset(ltc2631_handle_t *hoffs, int16_t offs_x100)
|
||||||
|
{
|
||||||
|
uint32_t value = (offs_x100 + MAX_VOLT_POS) * LTC_REF_2V5;
|
||||||
|
ULOG_DEBUG("(%d:_setOffset) offs_x100: %d, value: %d", __LINE__, offs_x100, value);
|
||||||
|
ltc2631_setOutputVoltage_u(hoffs, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setOfsset(signal_gen_t *sig_gen)
|
||||||
|
{
|
||||||
|
static signal_gen_t *curr_sig_gen = NULL;
|
||||||
|
|
||||||
|
if (curr_sig_gen == NULL)
|
||||||
|
{
|
||||||
|
curr_sig_gen = sig_gen;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (sig_gen->type)
|
||||||
|
{
|
||||||
|
case GEN_FG_TYPE:
|
||||||
|
{
|
||||||
|
dds_gen_t *dds_gen = (dds_gen_t *)sig_gen;
|
||||||
|
signal_gen_t *next_sig_gen = dds_gen->link.next;
|
||||||
|
|
||||||
|
_setOffset(&dds_gen->handle.hoffs, dds_gen->settings.offset);
|
||||||
|
|
||||||
|
if (next_sig_gen != curr_sig_gen)
|
||||||
|
{
|
||||||
|
setOfsset(next_sig_gen);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
curr_sig_gen = NULL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case GEN_PWM_TYPE:
|
||||||
|
{
|
||||||
|
pwm_gen_t *pwm_gen = (pwm_gen_t *)sig_gen;
|
||||||
|
signal_gen_t *next_sig_gen = pwm_gen->link.next;
|
||||||
|
|
||||||
|
_setOffset(&pwm_gen->handle.hoffs, pwm_gen->settings.offset);
|
||||||
|
|
||||||
|
if (next_sig_gen != curr_sig_gen)
|
||||||
|
{
|
||||||
|
setOfsset(next_sig_gen);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
curr_sig_gen = NULL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
ULOG_ERROR("%s:%d: Unknown generator type: %d", __FILE__, __LINE__, sig_gen->type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ************************
|
||||||
|
// FREQUENCY
|
||||||
|
// ************************
|
||||||
|
|
||||||
|
static void _setFreqDdsGen(ad9833_handle_t *hdds, uint32_t freq)
|
||||||
|
{
|
||||||
|
ULOG_DEBUG("(%d:_setFreqDdsGen) freq: %d", __LINE__, freq);
|
||||||
|
ad9833_setFrequency(hdds, CHAN_0, freq);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _setFreqPwmGen(timer_handle_t *hpwm, uint32_t freq)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void setFrequency(signal_gen_t *sig_gen)
|
||||||
|
{
|
||||||
|
static signal_gen_t *curr_sig_gen = NULL;
|
||||||
|
|
||||||
|
if (curr_sig_gen == NULL)
|
||||||
|
{
|
||||||
|
curr_sig_gen = sig_gen;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (sig_gen->type)
|
||||||
|
{
|
||||||
|
case GEN_FG_TYPE:
|
||||||
|
{
|
||||||
|
dds_gen_t *dds_gen = (dds_gen_t *)sig_gen;
|
||||||
|
signal_gen_t *next_sig_gen = dds_gen->link.next;
|
||||||
|
|
||||||
|
ad9833_spi_activate(&dds_gen->handle.hdds);
|
||||||
|
|
||||||
|
if (next_sig_gen != curr_sig_gen)
|
||||||
|
{
|
||||||
|
setFrequency(next_sig_gen);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_setFreqDdsGen(&dds_gen->handle.hdds, dds_gen->settings.frequency);
|
||||||
|
curr_sig_gen = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ad9833_spi_deactivate(&dds_gen->handle.hdds);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case GEN_PWM_TYPE:
|
||||||
|
{
|
||||||
|
pwm_gen_t *pwm_gen = (pwm_gen_t *)sig_gen;
|
||||||
|
signal_gen_t *next_sig_gen = pwm_gen->link.next;
|
||||||
|
|
||||||
|
_setFreqPwmGen(&pwm_gen->handle.hpwm, pwm_gen->settings.frequency);
|
||||||
|
|
||||||
|
if (next_sig_gen != curr_sig_gen)
|
||||||
|
{
|
||||||
|
setFrequency(next_sig_gen);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
curr_sig_gen = NULL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
ULOG_ERROR("%s:%d: Unknown generator type: %d", __FILE__, __LINE__, sig_gen->type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ************************
|
||||||
|
// PHASE
|
||||||
|
// ************************
|
||||||
|
|
||||||
|
static void _setPhaseDdsGen(ad9833_handle_t *hdds, uint32_t phas)
|
||||||
|
{
|
||||||
|
ULOG_DEBUG("(%d:_setPhaseDdsGen) phase: %d", __LINE__, phas);
|
||||||
|
ad9833_setPhase(hdds, CHAN_0, phas);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _setPhasePwmGen(timer_handle_t *hpwm, uint16_t phas)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void setPhase(signal_gen_t *sig_gen)
|
||||||
|
{
|
||||||
|
static signal_gen_t *curr_sig_gen = NULL;
|
||||||
|
|
||||||
|
if (curr_sig_gen == NULL)
|
||||||
|
{
|
||||||
|
curr_sig_gen = sig_gen;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (sig_gen->type)
|
||||||
|
{
|
||||||
|
case GEN_FG_TYPE:
|
||||||
|
{
|
||||||
|
dds_gen_t *dds_gen = (dds_gen_t *)sig_gen;
|
||||||
|
signal_gen_t *next_sig_gen = dds_gen->link.next;
|
||||||
|
|
||||||
|
ad9833_spi_activate(&dds_gen->handle.hdds);
|
||||||
|
|
||||||
|
if (next_sig_gen != curr_sig_gen)
|
||||||
|
{
|
||||||
|
setPhase(next_sig_gen);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_setPhaseDdsGen(&dds_gen->handle.hdds, dds_gen->settings.phase);
|
||||||
|
curr_sig_gen = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ad9833_spi_deactivate(&dds_gen->handle.hdds);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case GEN_PWM_TYPE:
|
||||||
|
{
|
||||||
|
pwm_gen_t *pwm_gen = (pwm_gen_t *)sig_gen;
|
||||||
|
signal_gen_t *next_sig_gen = pwm_gen->link.next;
|
||||||
|
|
||||||
|
_setPhasePwmGen(&pwm_gen->handle.hpwm, pwm_gen->settings.phase);
|
||||||
|
|
||||||
|
if (next_sig_gen != curr_sig_gen)
|
||||||
|
{
|
||||||
|
setPhase(next_sig_gen);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
curr_sig_gen = NULL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
ULOG_ERROR("%s:%d: Unknown generator type: %d", __FILE__, __LINE__, sig_gen->type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ************************
|
||||||
|
// DUTY
|
||||||
|
// ************************
|
||||||
|
|
||||||
|
static void _setDutyPwmGen(timer_handle_t *hpwm, uint8_t duty)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void setDuty(signal_gen_t *sig_gen)
|
||||||
|
{
|
||||||
|
switch (sig_gen->type)
|
||||||
|
{
|
||||||
|
case GEN_PWM_TYPE:
|
||||||
|
{
|
||||||
|
pwm_gen_t *pwm_gen = (pwm_gen_t *)sig_gen;
|
||||||
|
_setDutyPwmGen(&pwm_gen->handle.hpwm, pwm_gen->settings.duty);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
ULOG_ERROR("%s:%d: Unknown generator type: %d", __FILE__, __LINE__, sig_gen->type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ************************
|
||||||
|
// WAVE
|
||||||
|
// ************************
|
||||||
|
|
||||||
|
static void _setWaveDdsGen(ad9833_handle_t *hdds, GEN_wave_t wave)
|
||||||
|
{
|
||||||
|
ULOG_DEBUG("(%d:_setWaveDdsGen) wave: %d", __LINE__, wave);
|
||||||
|
switch (wave)
|
||||||
|
{
|
||||||
|
case GEN_SIN:
|
||||||
|
ad9833_setMode(hdds, MODE_SINE);
|
||||||
|
break;
|
||||||
|
case GEN_TRI:
|
||||||
|
ad9833_setMode(hdds, MODE_TRIANGLE);
|
||||||
|
break;
|
||||||
|
case GEN_SQR:
|
||||||
|
ad9833_setMode(hdds, MODE_SQUARE1);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
ULOG_ERROR("%s:%d: Unknown wave type: %d", __FILE__, __LINE__, wave);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setWave(signal_gen_t *sig_gen)
|
||||||
|
{
|
||||||
|
switch (sig_gen->type)
|
||||||
|
{
|
||||||
|
case GEN_FG_TYPE:
|
||||||
|
{
|
||||||
|
dds_gen_t *dds_gen = (dds_gen_t *)sig_gen;
|
||||||
|
_setWaveDdsGen(&dds_gen->handle.hdds, dds_gen->settings.wave);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
ULOG_ERROR("%s:%d: Unknown generator type: %d", __FILE__, __LINE__, sig_gen->type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ************************
|
||||||
|
// ENABLE
|
||||||
|
// ************************
|
||||||
|
|
||||||
|
static void _setEnabledDdsGen(dds_handle_t *hfg, dds_settings_t *settings)
|
||||||
|
{
|
||||||
|
ULOG_DEBUG("(%d:_setEnabledDdsGen) enabled: %d", __LINE__, settings->enabled);
|
||||||
|
switch (settings->enabled)
|
||||||
|
{
|
||||||
|
case FALSE:
|
||||||
|
ad9833_setMode(&hfg->hdds, MODE_OFF);
|
||||||
|
led_off(&hfg->hled);
|
||||||
|
break;
|
||||||
|
case TRUE:
|
||||||
|
_setWaveDdsGen(&hfg->hdds, settings->wave);
|
||||||
|
led_on(&hfg->hled);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
ULOG_ERROR("%s:%d: Value out of range: %d", __FILE__, __LINE__, settings->enabled);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _setEnabledPwmGen(timer_handle_t *hpwm, bool_t en)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void setEnabled(signal_gen_t *sig_gen)
|
||||||
|
{
|
||||||
|
switch (sig_gen->type)
|
||||||
|
{
|
||||||
|
case GEN_FG_TYPE:
|
||||||
|
{
|
||||||
|
dds_gen_t *dds_gen = (dds_gen_t *)sig_gen;
|
||||||
|
_setEnabledDdsGen(&dds_gen->handle, &dds_gen->settings);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case GEN_PWM_TYPE:
|
||||||
|
{
|
||||||
|
pwm_gen_t *pwm_gen = (pwm_gen_t *)sig_gen;
|
||||||
|
_setEnabledPwmGen(&pwm_gen->handle.hpwm, pwm_gen->settings.enabled);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
ULOG_ERROR("%s:%d: Unknown generator type: %d", __FILE__, __LINE__, sig_gen->type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ************************
|
||||||
|
// LINK
|
||||||
|
// ************************
|
||||||
|
|
||||||
|
void setLink(signal_gen_t *source_gen, signal_gen_t *dest_gen)
|
||||||
|
{
|
||||||
|
}
|
||||||
12
firmware/shared_libs/controllers/ctrl_signal_gen.h
Normal file
12
firmware/shared_libs/controllers/ctrl_signal_gen.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "ctrl_app_types.h"
|
||||||
|
|
||||||
|
void setLink(signal_gen_t *source_gen, signal_gen_t *dest_gen);
|
||||||
|
void setEnabled(signal_gen_t *gen);
|
||||||
|
void setDuty(signal_gen_t *gen);
|
||||||
|
void setWave(signal_gen_t *gen);
|
||||||
|
void setPhase(signal_gen_t *gen);
|
||||||
|
void setOfsset(signal_gen_t *gen);
|
||||||
|
void setAmplitude(signal_gen_t *gen);
|
||||||
|
void setFrequency(signal_gen_t *gen);
|
||||||
|
void GEN_init(signal_gen_t **signal_gen);
|
||||||
@@ -74,7 +74,7 @@ static void _blinkButtons(GFX_display_t *disp, APP_data_t *app_data)
|
|||||||
BITMAP_buttonName_t bitmap_idx;
|
BITMAP_buttonName_t bitmap_idx;
|
||||||
for (LAY_dispBtn_t btn_idx = DISP_BTN_1; btn_idx < DISP_BTN_MAX; btn_idx++)
|
for (LAY_dispBtn_t btn_idx = DISP_BTN_1; btn_idx < DISP_BTN_MAX; btn_idx++)
|
||||||
{
|
{
|
||||||
if (!(app_data->isButtonBlink & (1 << btn_idx)))
|
if (!(app_data->button_blink & (1 << btn_idx)))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ static void _blinkButtons(GFX_display_t *disp, APP_data_t *app_data)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
DISP_drawBitmap(disp, &bitmap_btnBottom[bitmap_idx], btn_pos_x[btn_idx], 53, BM_NORMAL);
|
DISP_drawBitmap(disp, &bitmap_btnBottom[bitmap_idx], btn_pos_x[btn_idx], 53, BM_NORMAL);
|
||||||
app_data->isButtonBlink &= ~(1 << btn_idx);
|
app_data->button_blink &= ~(1 << btn_idx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,7 +105,7 @@ static void _drawButtons(GFX_display_t *disp, APP_data_t *app_data)
|
|||||||
DISP_drawBitmap(disp, &bitmap_btnBottom[bitmap_idx], btn_pos_x[btn_idx], 53, BM_NORMAL);
|
DISP_drawBitmap(disp, &bitmap_btnBottom[bitmap_idx], btn_pos_x[btn_idx], 53, BM_NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
app_data->isButtonChange = 0;
|
app_data->disp_update &= ~(UPDATE_BUTTON);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t _calcMarkerPos(uint32_t value, uint32_t max)
|
static uint8_t _calcMarkerPos(uint32_t value, uint32_t max)
|
||||||
@@ -180,24 +180,24 @@ static void _drawPhaseValueHelper(GFX_display_t *disp, uint32_t phase, uint8_t f
|
|||||||
|
|
||||||
static void _drawFuncGenValues(GFX_display_t *disp, APP_data_t *app_data)
|
static void _drawFuncGenValues(GFX_display_t *disp, APP_data_t *app_data)
|
||||||
{
|
{
|
||||||
GEN_fg_t *fun_gen = (GEN_fg_t *)app_data->generator;
|
dds_gen_t *fun_gen = (dds_gen_t *)app_data->curr_gen;
|
||||||
switch (app_data->curr_state_lay)
|
switch (app_data->curr_state_lay)
|
||||||
{
|
{
|
||||||
case LAY_FREQ:
|
case LAY_FREQ:
|
||||||
_drawFreqValueHelper(disp, fun_gen->frequency, app_data->freq_focus_digit);
|
_drawFreqValueHelper(disp, fun_gen->settings.frequency, app_data->freq_focus_digit);
|
||||||
_drawMeterHelper(disp, "1", "1M", _calcMarkerPos(fun_gen->frequency, MAX_FREQ));
|
_drawMeterHelper(disp, "1", "1M", _calcMarkerPos(fun_gen->settings.frequency, MAX_FREQ));
|
||||||
break;
|
break;
|
||||||
case LAY_AMPL:
|
case LAY_AMPL:
|
||||||
_drawAmplValueHelper(disp, fun_gen->amplitude, app_data->ampl_focus_digit);
|
_drawAmplValueHelper(disp, fun_gen->settings.amplitude, app_data->ampl_focus_digit);
|
||||||
_drawMeterHelper(disp, "0V", "5V", _calcMarkerPos(fun_gen->amplitude, MAX_VOLT_POS));
|
_drawMeterHelper(disp, "0V", "5V", _calcMarkerPos(fun_gen->settings.amplitude, MAX_VOLT_POS));
|
||||||
break;
|
break;
|
||||||
case LAY_OFFS:
|
case LAY_OFFS:
|
||||||
_drawOffsValueHelper(disp, fun_gen->offset, app_data->offs_focus_digit);
|
_drawOffsValueHelper(disp, fun_gen->settings.offset, app_data->offs_focus_digit);
|
||||||
_drawMeterHelper(disp, "-5V", "+5V", _calcMarkerPos(MAX_VOLT_POS + fun_gen->offset, MAX_VOLT_POS * 2));
|
_drawMeterHelper(disp, "-5V", "+5V", _calcMarkerPos(MAX_VOLT_POS + fun_gen->settings.offset, MAX_VOLT_POS * 2));
|
||||||
break;
|
break;
|
||||||
case LAY_PHAS:
|
case LAY_PHAS:
|
||||||
_drawPhaseValueHelper(disp, fun_gen->phase, app_data->phas_focus_digit);
|
_drawPhaseValueHelper(disp, fun_gen->settings.phase, app_data->phas_focus_digit);
|
||||||
_drawMeterHelper(disp, "0", "360", _calcMarkerPos(fun_gen->phase, MAX_PHAS));
|
_drawMeterHelper(disp, "0", "360", _calcMarkerPos(fun_gen->settings.phase, MAX_PHAS));
|
||||||
break;
|
break;
|
||||||
case LAY_MAIN:
|
case LAY_MAIN:
|
||||||
DISP_clearRegion(disp, 62, 13, 66, 40);
|
DISP_clearRegion(disp, 62, 13, 66, 40);
|
||||||
@@ -206,10 +206,10 @@ static void _drawFuncGenValues(GFX_display_t *disp, APP_data_t *app_data)
|
|||||||
DISP_writeString(disp, &font5x7Info, (uint8_t *)"O:", 64, 33, BM_NORMAL);
|
DISP_writeString(disp, &font5x7Info, (uint8_t *)"O:", 64, 33, BM_NORMAL);
|
||||||
DISP_writeString(disp, &font5x7Info, (uint8_t *)"P:", 64, 43, BM_NORMAL);
|
DISP_writeString(disp, &font5x7Info, (uint8_t *)"P:", 64, 43, BM_NORMAL);
|
||||||
|
|
||||||
_drawFreqValue(disp, fun_gen->frequency, 13);
|
_drawFreqValue(disp, fun_gen->settings.frequency, 13);
|
||||||
_drawAmplValue(disp, fun_gen->amplitude, 23);
|
_drawAmplValue(disp, fun_gen->settings.amplitude, 23);
|
||||||
_drawOffsValue(disp, fun_gen->offset, 33);
|
_drawOffsValue(disp, fun_gen->settings.offset, 33);
|
||||||
_drawPhasValue(disp, fun_gen->phase, 43);
|
_drawPhasValue(disp, fun_gen->settings.phase, 43);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -220,13 +220,13 @@ static void _drawFuncGenValues(GFX_display_t *disp, APP_data_t *app_data)
|
|||||||
|
|
||||||
static void _drawPwmGenValues(GFX_display_t *disp, APP_data_t *app_data)
|
static void _drawPwmGenValues(GFX_display_t *disp, APP_data_t *app_data)
|
||||||
{
|
{
|
||||||
// GEN_pwm_t *pwm_gen = app_data->generator;
|
// GEN_pwm_t *pwm_gen = app_data->curr_gen;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _drawValues(GFX_display_t *disp, APP_data_t *app_data)
|
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)
|
// input: frequency(value), amplitiude(value), offset(value), phase(value), duty(value), invert(info), position(value)
|
||||||
switch (app_data->curr_gen_type)
|
switch (app_data->curr_gen->type)
|
||||||
{
|
{
|
||||||
case GEN_FG_TYPE:
|
case GEN_FG_TYPE:
|
||||||
_drawFuncGenValues(disp, app_data);
|
_drawFuncGenValues(disp, app_data);
|
||||||
@@ -239,7 +239,7 @@ static void _drawValues(GFX_display_t *disp, APP_data_t *app_data)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
app_data->isValueChange = 0;
|
app_data->disp_update &= ~(UPDATE_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _drawOffsetLine(GFX_display_t *disp, int16_t offs, uint32_t ampl)
|
static void _drawOffsetLine(GFX_display_t *disp, int16_t offs, uint32_t ampl)
|
||||||
@@ -249,7 +249,7 @@ static void _drawOffsetLine(GFX_display_t *disp, int16_t offs, uint32_t ampl)
|
|||||||
vert_shift = MIN(vert_shift, 20);
|
vert_shift = MIN(vert_shift, 20);
|
||||||
vert_shift = MAX(vert_shift, -19);
|
vert_shift = MAX(vert_shift, -19);
|
||||||
|
|
||||||
ULOG_TRACE("<OFFSLINE> shift: %i", vert_shift);
|
// ULOG_DEBUG("<OFFSLINE> shift: %i", vert_shift);
|
||||||
DISP_drawHorizontalLine(disp, 2, 31 + vert_shift, 57, GFX_WHITE);
|
DISP_drawHorizontalLine(disp, 2, 31 + vert_shift, 57, GFX_WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,26 +264,26 @@ static void _drawOffsetLine(GFX_display_t *disp, int16_t offs, uint32_t ampl)
|
|||||||
|
|
||||||
static void _drawFunGenGraph(GFX_display_t *disp, APP_data_t *app_data)
|
static void _drawFunGenGraph(GFX_display_t *disp, APP_data_t *app_data)
|
||||||
{
|
{
|
||||||
GEN_fg_t *fun_gen = (GEN_fg_t *)app_data->generator;
|
dds_gen_t *fun_gen = (dds_gen_t *)app_data->curr_gen;
|
||||||
DISP_clearRegion(disp, 3, 12, 57, 40);
|
DISP_clearRegion(disp, 3, 12, 57, 40);
|
||||||
|
|
||||||
switch (fun_gen->wave)
|
switch (fun_gen->settings.wave)
|
||||||
{
|
{
|
||||||
case GEN_SIN:
|
case GEN_SIN:
|
||||||
DISP_drawBitmapShift(disp, &wave[WAVE_SIN], 6, 19, _calcPhaseShiftInPxl(fun_gen->phase, 360), BM_NORMAL);
|
DISP_drawBitmapShift(disp, &wave[WAVE_SIN], 6, 19, _calcPhaseShiftInPxl(fun_gen->settings.phase, 360), BM_NORMAL);
|
||||||
break;
|
break;
|
||||||
case GEN_TRI:
|
case GEN_TRI:
|
||||||
DISP_drawBitmapShift(disp, &wave[WAVE_TRI], 6, 19, _calcPhaseShiftInPxl(fun_gen->phase, 360), BM_NORMAL);
|
DISP_drawBitmapShift(disp, &wave[WAVE_TRI], 6, 19, _calcPhaseShiftInPxl(fun_gen->settings.phase, 360), BM_NORMAL);
|
||||||
break;
|
break;
|
||||||
case GEN_SQR:
|
case GEN_SQR:
|
||||||
DISP_drawBitmapShift(disp, &wave[WAVE_SQR], 6, 19, _calcPhaseShiftInPxl(fun_gen->phase, 360), BM_NORMAL);
|
DISP_drawBitmapShift(disp, &wave[WAVE_SQR], 6, 19, _calcPhaseShiftInPxl(fun_gen->settings.phase, 360), BM_NORMAL);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
_drawOffsetLine(disp, fun_gen->offset, fun_gen->amplitude);
|
_drawOffsetLine(disp, fun_gen->settings.offset, fun_gen->settings.amplitude);
|
||||||
// _drawMaxAmpLine(disp, fun_gen->offset, fun_gen->amplitude);
|
// _drawMaxAmpLine(disp, fun_gen->settings.offset, fun_gen->settings.amplitude);
|
||||||
}
|
}
|
||||||
static void _drawPwmGenGraph(GFX_display_t *disp, APP_data_t *app_data)
|
static void _drawPwmGenGraph(GFX_display_t *disp, APP_data_t *app_data)
|
||||||
{
|
{
|
||||||
@@ -294,7 +294,7 @@ 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),
|
// 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);
|
DISP_drawVerticalLine(disp, 2, 12, 40, GFX_WHITE);
|
||||||
|
|
||||||
switch (app_data->curr_gen_type)
|
switch (app_data->curr_gen->type)
|
||||||
{
|
{
|
||||||
case GEN_FG_TYPE:
|
case GEN_FG_TYPE:
|
||||||
_drawFunGenGraph(disp, app_data);
|
_drawFunGenGraph(disp, app_data);
|
||||||
@@ -307,7 +307,7 @@ static void _drawGraph(GFX_display_t *disp, APP_data_t *app_data)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
app_data->isGraphChange = 0;
|
app_data->disp_update &= ~(UPDATE_GRAPH);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _drawChannels(GFX_display_t *disp, APP_data_t *app_data)
|
static void _drawChannels(GFX_display_t *disp, APP_data_t *app_data)
|
||||||
@@ -321,23 +321,23 @@ static void _drawChannels(GFX_display_t *disp, APP_data_t *app_data)
|
|||||||
DISP_writeString(disp, &font5x7Info, (uint8_t *)"CH6", 107, 2, CHANNEL6 == 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);
|
DISP_drawHorizontalLine(disp, 0, 10, 127, GFX_WHITE);
|
||||||
|
|
||||||
app_data->isChannelChange = 0;
|
app_data->disp_update &= ~(UPDATE_CHANNEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LAY_drawDisplayLayout(GFX_display_t *disp, APP_data_t *app_data)
|
void LAY_drawDisplayLayout(GFX_display_t *disp, APP_data_t *app_data)
|
||||||
{
|
{
|
||||||
if (app_data->isChannelChange)
|
if (app_data->disp_update & UPDATE_CHANNEL)
|
||||||
_drawChannels(disp, app_data);
|
_drawChannels(disp, app_data);
|
||||||
|
|
||||||
if (app_data->isValueChange)
|
if (app_data->disp_update & UPDATE_VALUE)
|
||||||
_drawValues(disp, app_data);
|
_drawValues(disp, app_data);
|
||||||
|
|
||||||
if (app_data->isGraphChange)
|
if (app_data->disp_update & UPDATE_GRAPH)
|
||||||
_drawGraph(disp, app_data);
|
_drawGraph(disp, app_data);
|
||||||
|
|
||||||
if (app_data->isButtonChange)
|
if (app_data->disp_update & UPDATE_BUTTON)
|
||||||
_drawButtons(disp, app_data);
|
_drawButtons(disp, app_data);
|
||||||
|
|
||||||
if (app_data->isButtonBlink)
|
if (app_data->button_blink)
|
||||||
_blinkButtons(disp, app_data);
|
_blinkButtons(disp, app_data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,18 +4,30 @@
|
|||||||
#include "ad9833.h"
|
#include "ad9833.h"
|
||||||
|
|
||||||
// Convenience calculations
|
// Convenience calculations
|
||||||
static uint32_t ad9833_calcFreq(float f); // Calculate AD9833 frequency register from a frequency
|
// static uint32_t ad9833_calcFreq(float f); // Calculate AD9833 frequency register from a frequency
|
||||||
static uint16_t ad9833_calcPhase(float a); // Calculate AD9833 phase register from phase
|
// static uint16_t ad9833_calcPhase(float a); // Calculate AD9833 phase register from phase
|
||||||
|
|
||||||
|
void ad9833_spi_activate(ad9833_handle_t *hfg)
|
||||||
|
{
|
||||||
|
// HAL_GPIO_WritePin(hfg->cs_port, hfg->cs_pin, GPIO_PIN_RESET);
|
||||||
|
hfg->hcs->cs_on(hfg->hcs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ad9833_spi_deactivate(ad9833_handle_t *hfg)
|
||||||
|
{
|
||||||
|
// HAL_GPIO_WritePin(hfg->cs_port, hfg->cs_pin, GPIO_PIN_SET);
|
||||||
|
hfg->hcs->cs_off(hfg->hcs);
|
||||||
|
}
|
||||||
|
|
||||||
static void ad9833_transmit16(ad9833_handle_t *hfg, uint16_t data)
|
static void ad9833_transmit16(ad9833_handle_t *hfg, uint16_t data)
|
||||||
{
|
{
|
||||||
uint8_t data8;
|
uint8_t data8;
|
||||||
HAL_GPIO_WritePin(hfg->cs_port, hfg->cs_pin, GPIO_PIN_RESET);
|
ad9833_spi_activate(hfg);
|
||||||
data8 = (uint8_t)((data >> 8) & 0x00FF);
|
data8 = (uint8_t)((data >> 8) & 0x00FF);
|
||||||
HAL_SPI_Transmit(hfg->hspi, &data8, 1, 1);
|
HAL_SPI_Transmit(hfg->hspi, &data8, 1, HAL_MAX_DELAY);
|
||||||
data8 = (uint8_t)(data & 0x00FF);
|
data8 = (uint8_t)(data & 0x00FF);
|
||||||
HAL_SPI_Transmit(hfg->hspi, &data8, 1, 1);
|
HAL_SPI_Transmit(hfg->hspi, &data8, 1, HAL_MAX_DELAY);
|
||||||
HAL_GPIO_WritePin(hfg->cs_port, hfg->cs_pin, GPIO_PIN_SET);
|
ad9833_spi_deactivate(hfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ad9833_reset(ad9833_handle_t *hfg, uint8_t hold)
|
void ad9833_reset(ad9833_handle_t *hfg, uint8_t hold)
|
||||||
@@ -31,14 +43,15 @@ void ad9833_reset(ad9833_handle_t *hfg, uint8_t hold)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ad9833_init(ad9833_handle_t *hfg, SPI_HandleTypeDef *hspi, GPIO_TypeDef *cs_port, uint16_t cs_pin)
|
void ad9833_init(ad9833_handle_t *hfg, SPI_HandleTypeDef *hspi, cs_handle_t *hcs)
|
||||||
// Initialise the AD9833 and then set up safe values for the AD9833 device
|
// Initialise the AD9833 and then set up safe values for the AD9833 device
|
||||||
// Procedure from Figure 27 of in the AD9833 Data Sheet
|
// Procedure from Figure 27 of in the AD9833 Data Sheet
|
||||||
{
|
{
|
||||||
// initialise our preferred CS pin (could be same as SS)
|
// initialise our preferred CS pin (could be same as SS)
|
||||||
hfg->hspi = hspi;
|
hfg->hspi = hspi;
|
||||||
hfg->cs_port = cs_port;
|
hfg->hcs = hcs;
|
||||||
hfg->cs_pin = cs_pin;
|
|
||||||
|
hfg->hcs->cs_off(hfg->hcs);
|
||||||
|
|
||||||
hfg->_regCtl = 0;
|
hfg->_regCtl = 0;
|
||||||
hfg->_regCtl |= (1 << AD_B28); // always write 2 words consecutively for frequency
|
hfg->_regCtl |= (1 << AD_B28); // always write 2 words consecutively for frequency
|
||||||
@@ -49,11 +62,10 @@ void ad9833_init(ad9833_handle_t *hfg, SPI_HandleTypeDef *hspi, GPIO_TypeDef *cs
|
|||||||
ad9833_setFrequency(hfg, CHAN_1, AD_DEFAULT_FREQ);
|
ad9833_setFrequency(hfg, CHAN_1, AD_DEFAULT_FREQ);
|
||||||
ad9833_setPhase(hfg, CHAN_0, AD_DEFAULT_PHASE);
|
ad9833_setPhase(hfg, CHAN_0, AD_DEFAULT_PHASE);
|
||||||
ad9833_setPhase(hfg, CHAN_1, AD_DEFAULT_PHASE);
|
ad9833_setPhase(hfg, CHAN_1, AD_DEFAULT_PHASE);
|
||||||
ad9833_reset(hfg, 0); // full transition
|
|
||||||
|
|
||||||
ad9833_setMode(hfg, MODE_OFF);
|
|
||||||
ad9833_setActiveChannelFreq(hfg, CHAN_0);
|
|
||||||
ad9833_setActiveChannelPhase(hfg, CHAN_0);
|
ad9833_setActiveChannelPhase(hfg, CHAN_0);
|
||||||
|
ad9833_setActiveChannelFreq(hfg, CHAN_0);
|
||||||
|
ad9833_setMode(hfg, MODE_OFF);
|
||||||
|
ad9833_reset(hfg, 0); // full transition
|
||||||
}
|
}
|
||||||
|
|
||||||
void ad9833_setActiveChannelFreq(ad9833_handle_t *hfg, AD_channel_t chan)
|
void ad9833_setActiveChannelFreq(ad9833_handle_t *hfg, AD_channel_t chan)
|
||||||
@@ -144,26 +156,33 @@ void ad9833_setMode(ad9833_handle_t *hfg, AD_mode_t mode)
|
|||||||
ad9833_transmit16(hfg, hfg->_regCtl);
|
ad9833_transmit16(hfg, hfg->_regCtl);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t ad9833_calcFreq(float f)
|
// static uint32_t ad9833_calcFreq(float f)
|
||||||
// Calculate register value for AD9833 frequency register from a frequency
|
// // Calculate register value for AD9833 frequency register from a frequency
|
||||||
|
// {
|
||||||
|
// return (uint32_t)((f * AD_2POW28 / AD_MCLK) + 0.5f);
|
||||||
|
// }
|
||||||
|
|
||||||
|
static uint32_t ad9833_calcFreq_uint(uint32_t f)
|
||||||
{
|
{
|
||||||
return (uint32_t)((f * AD_2POW28 / AD_MCLK) + 0.5f);
|
return ((f * AD_2POW28 + AD_MCLK_DIV2) / AD_MCLK); // ((n + d/2)/d)
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16_t ad9833_calcPhase(float a)
|
// static uint16_t ad9833_calcPhase(float a)
|
||||||
// Calculate the value for AD9833 phase register from given phase in tenths of a degree
|
// // Calculate the value for AD9833 phase register from given phase in tenths of a degree
|
||||||
{
|
// {
|
||||||
return (uint16_t)((512.0f * (a / 10) / 45) + 0.5f);
|
// return (uint16_t)((512.0f * (a / 10) / 45) + 0.5f);
|
||||||
}
|
// }
|
||||||
|
|
||||||
void ad9833_setFrequency(ad9833_handle_t *hfg, AD_channel_t chan, float freq)
|
static uint16_t ad9833_calcPhase_uint(uint16_t p)
|
||||||
|
{
|
||||||
|
return ((p * 4096U + 180) / 360);
|
||||||
|
}
|
||||||
|
void ad9833_setFrequency(ad9833_handle_t *hfg, AD_channel_t chan, uint32_t freq)
|
||||||
{
|
{
|
||||||
// PRINT("\nsetFreq CHAN_", chan);
|
// PRINT("\nsetFreq CHAN_", chan);
|
||||||
uint16_t freq_channel = 0;
|
uint16_t freq_channel = 0;
|
||||||
|
|
||||||
hfg->_freq[chan] = freq;
|
hfg->_regFreq[chan] = ad9833_calcFreq_uint(freq);
|
||||||
|
|
||||||
hfg->_regFreq[chan] = ad9833_calcFreq(freq);
|
|
||||||
|
|
||||||
// select the address mask
|
// select the address mask
|
||||||
|
|
||||||
@@ -195,8 +214,7 @@ void ad9833_setPhase(ad9833_handle_t *hfg, AD_channel_t chan, uint16_t phase)
|
|||||||
// PRINT("\nsetPhase CHAN_", chan);
|
// PRINT("\nsetPhase CHAN_", chan);
|
||||||
uint16_t phase_channel = 0;
|
uint16_t phase_channel = 0;
|
||||||
|
|
||||||
hfg->_phase[chan] = phase;
|
hfg->_regPhase[chan] = ad9833_calcPhase_uint(phase);
|
||||||
hfg->_regPhase[chan] = ad9833_calcPhase(phase);
|
|
||||||
|
|
||||||
// select the address mask
|
// select the address mask
|
||||||
switch (chan)
|
switch (chan)
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define AD_DEFAULT_FREQ 1000U ///< Default initialisation frequency (Hz)
|
#include "spi_cs_if.h"
|
||||||
#define AD_DEFAULT_PHASE 0 ///< Default initialisation phase angle (degrees)
|
|
||||||
#define AD_MCLK 25000000UL ///< Clock speed of the AD9833 reference clock in Hz
|
#define AD_DEFAULT_FREQ 1000U ///< Default initialisation frequency (Hz)
|
||||||
|
#define AD_DEFAULT_PHASE 0 ///< Default initialisation phase angle (degrees)
|
||||||
|
#define AD_MCLK 25000000U ///< Clock speed of the AD9833 reference clock in Hz
|
||||||
|
#define AD_MCLK_DIV2 12500000U ///< Clock speed of the AD9833 reference clock in Hz
|
||||||
/**
|
/**
|
||||||
* Channel enumerated type.
|
* Channel enumerated type.
|
||||||
*
|
*
|
||||||
@@ -36,21 +39,20 @@ typedef struct
|
|||||||
uint32_t _regFreq[2]; // frequency registers
|
uint32_t _regFreq[2]; // frequency registers
|
||||||
uint32_t _regPhase[2]; // phase registers
|
uint32_t _regPhase[2]; // phase registers
|
||||||
|
|
||||||
AD_mode_t _mode; // last set mode
|
AD_mode_t _mode; // last set mode
|
||||||
float _freq[2]; // last frequencies set
|
|
||||||
uint16_t _phase[2]; // last phase setting
|
|
||||||
|
|
||||||
SPI_HandleTypeDef *hspi;
|
SPI_HandleTypeDef *hspi;
|
||||||
GPIO_TypeDef *cs_port;
|
cs_handle_t *hcs;
|
||||||
uint16_t cs_pin;
|
|
||||||
} ad9833_handle_t;
|
} ad9833_handle_t;
|
||||||
|
|
||||||
void ad9833_init(ad9833_handle_t *hfg, SPI_HandleTypeDef *hspi, GPIO_TypeDef *cs_port, uint16_t cs_pin);
|
void ad9833_init(ad9833_handle_t *hfg, SPI_HandleTypeDef *hspi, cs_handle_t *hcs);
|
||||||
|
void ad9833_spi_activate(ad9833_handle_t *hfg);
|
||||||
|
void ad9833_spi_deactivate(ad9833_handle_t *hfg);
|
||||||
void ad9833_reset(ad9833_handle_t *hfg, uint8_t hold);
|
void ad9833_reset(ad9833_handle_t *hfg, uint8_t hold);
|
||||||
void ad9833_setActiveChannelFreq(ad9833_handle_t *hfg, AD_channel_t chan);
|
void ad9833_setActiveChannelFreq(ad9833_handle_t *hfg, AD_channel_t chan);
|
||||||
AD_channel_t ad9833_getActiveChannelFreq(ad9833_handle_t *hfg);
|
AD_channel_t ad9833_getActiveChannelFreq(ad9833_handle_t *hfg);
|
||||||
void ad9833_setActiveChannelPhase(ad9833_handle_t *hfg, AD_channel_t chan);
|
void ad9833_setActiveChannelPhase(ad9833_handle_t *hfg, AD_channel_t chan);
|
||||||
AD_channel_t ad9833_getActiveChannelPhase(ad9833_handle_t *hfg);
|
AD_channel_t ad9833_getActiveChannelPhase(ad9833_handle_t *hfg);
|
||||||
void ad9833_setMode(ad9833_handle_t *hfg, AD_mode_t mode);
|
void ad9833_setMode(ad9833_handle_t *hfg, AD_mode_t mode);
|
||||||
void ad9833_setFrequency(ad9833_handle_t *hfg, AD_channel_t chan, float freq);
|
void ad9833_setFrequency(ad9833_handle_t *hfg, AD_channel_t chan, uint32_t freq);
|
||||||
void ad9833_setPhase(ad9833_handle_t *hfg, AD_channel_t chan, uint16_t phase);
|
void ad9833_setPhase(ad9833_handle_t *hfg, AD_channel_t chan, uint16_t phase);
|
||||||
@@ -41,4 +41,4 @@
|
|||||||
#define SEL_PHASE1 (1 << AD_FREQ0 | 1 << AD_FREQ1 | 1 << AD_PHASE)
|
#define SEL_PHASE1 (1 << AD_FREQ0 | 1 << AD_FREQ1 | 1 << AD_PHASE)
|
||||||
|
|
||||||
// AD9833 frequency and phase calculation macros
|
// AD9833 frequency and phase calculation macros
|
||||||
#define AD_2POW28 (1UL << 28) ///< Used when calculating output frequency
|
#define AD_2POW28 (1ULL << 28) ///< Used when calculating output frequency
|
||||||
|
|||||||
@@ -45,10 +45,10 @@ static void buttonDebounceRoutine(ButtonKey_t *key)
|
|||||||
|
|
||||||
key->state = PRESSED;
|
key->state = PRESSED;
|
||||||
key->last_tick = HAL_GetTick();
|
key->last_tick = HAL_GetTick();
|
||||||
if (key->buttonPressed)
|
// if (key->buttonPressed)
|
||||||
{
|
// {
|
||||||
key->buttonPressed(key);
|
// key->buttonPressed(key);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
static void buttonPressedRoutine(ButtonKey_t *key)
|
static void buttonPressedRoutine(ButtonKey_t *key)
|
||||||
@@ -56,9 +56,13 @@ static void buttonPressedRoutine(ButtonKey_t *key)
|
|||||||
if (key->pushed_state != HAL_GPIO_ReadPin(key->gpio_port, key->gpio_pin))
|
if (key->pushed_state != HAL_GPIO_ReadPin(key->gpio_port, key->gpio_pin))
|
||||||
{
|
{
|
||||||
key->state = IDLE;
|
key->state = IDLE;
|
||||||
if (key->buttonReleased)
|
// if (key->buttonReleased)
|
||||||
|
// {
|
||||||
|
// key->buttonReleased(key);
|
||||||
|
// }
|
||||||
|
if (key->buttonPressed)
|
||||||
{
|
{
|
||||||
key->buttonReleased(key);
|
key->buttonPressed(key);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
19
firmware/shared_libs/drivers/led/led.c
Normal file
19
firmware/shared_libs/drivers/led/led.c
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#include "led.h"
|
||||||
|
|
||||||
|
void led_init(led_handle_t *hled, GPIO_TypeDef *port, uint16_t pin)
|
||||||
|
{
|
||||||
|
hled->port = port;
|
||||||
|
hled->pin = pin;
|
||||||
|
|
||||||
|
HAL_GPIO_WritePin(port, pin, GPIO_PIN_SET);
|
||||||
|
}
|
||||||
|
|
||||||
|
void led_on(led_handle_t *hled)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(hled->port, hled->pin, GPIO_PIN_RESET);
|
||||||
|
}
|
||||||
|
|
||||||
|
void led_off(led_handle_t *hled)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(hled->port, hled->pin, GPIO_PIN_SET);
|
||||||
|
}
|
||||||
8
firmware/shared_libs/drivers/led/led.h
Normal file
8
firmware/shared_libs/drivers/led/led.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "gpio.h"
|
||||||
|
#include "ctrl_app_types.h"
|
||||||
|
|
||||||
|
void led_init(led_handle_t *hled, GPIO_TypeDef *port, uint16_t pin);
|
||||||
|
void led_on(led_handle_t *hled);
|
||||||
|
void led_off(led_handle_t *hled);
|
||||||
@@ -5,18 +5,19 @@ static uint32_t pot_value[MCP41X_RES_MAX] = {10000, 50000, 100000};
|
|||||||
|
|
||||||
static void mcp41x_transmit(mcp41x_handle_t *hpot, uint8_t *data)
|
static void mcp41x_transmit(mcp41x_handle_t *hpot, uint8_t *data)
|
||||||
{
|
{
|
||||||
HAL_GPIO_WritePin(hpot->cs_port, hpot->cs_pin, GPIO_PIN_RESET);
|
hpot->hcs->cs_on(hpot->hcs);
|
||||||
HAL_SPI_Transmit(hpot->hspi, data, 2, 1);
|
HAL_SPI_Transmit(hpot->hspi, data, 2, HAL_MAX_DELAY);
|
||||||
HAL_GPIO_WritePin(hpot->cs_port, hpot->cs_pin, GPIO_PIN_SET);
|
hpot->hcs->cs_off(hpot->hcs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mcp41x_init(mcp41x_handle_t *hpot, SPI_HandleTypeDef *hspi, GPIO_TypeDef *cs_port, uint16_t cs_pin, mcp41x_res_t res)
|
void mcp41x_init(mcp41x_handle_t *hpot, SPI_HandleTypeDef *hspi, cs_handle_t *hcs, mcp41x_res_t res)
|
||||||
{
|
{
|
||||||
hpot->hspi = hspi;
|
hpot->hspi = hspi;
|
||||||
hpot->cs_port = cs_port;
|
hpot->hcs = hcs;
|
||||||
hpot->cs_pin = cs_pin;
|
|
||||||
hpot->max_res = res;
|
hpot->max_res = res;
|
||||||
hpot->dir = MCP41X_ATOB;
|
hpot->dir = MCP41X_ATOB;
|
||||||
|
|
||||||
|
hpot->hcs->cs_off(hcs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mcp41x_setValue(mcp41x_handle_t *hpot, uint8_t value)
|
void mcp41x_setValue(mcp41x_handle_t *hpot, uint8_t value)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "spi_cs_if.h"
|
||||||
|
|
||||||
#define MCP41X_C1 5
|
#define MCP41X_C1 5
|
||||||
#define MCP41X_C0 4
|
#define MCP41X_C0 4
|
||||||
#define MCP41X_P1 1
|
#define MCP41X_P1 1
|
||||||
@@ -36,11 +38,10 @@ typedef struct
|
|||||||
uint8_t value;
|
uint8_t value;
|
||||||
|
|
||||||
SPI_HandleTypeDef *hspi;
|
SPI_HandleTypeDef *hspi;
|
||||||
GPIO_TypeDef *cs_port;
|
cs_handle_t *hcs;
|
||||||
uint16_t cs_pin;
|
|
||||||
} mcp41x_handle_t;
|
} mcp41x_handle_t;
|
||||||
|
|
||||||
void mcp41x_init(mcp41x_handle_t *hpot, SPI_HandleTypeDef *hspi, GPIO_TypeDef *cs_port, uint16_t cs_pin, mcp41x_res_t res);
|
void mcp41x_init(mcp41x_handle_t *hpot, SPI_HandleTypeDef *hspi, cs_handle_t *hcs, mcp41x_res_t res);
|
||||||
void mcp41x_setValue(mcp41x_handle_t *hpot, uint8_t value);
|
void mcp41x_setValue(mcp41x_handle_t *hpot, uint8_t value);
|
||||||
void mcp41x_setVolume(mcp41x_handle_t *hpot, uint8_t volume);
|
void mcp41x_setVolume(mcp41x_handle_t *hpot, uint8_t volume);
|
||||||
uint8_t mcp41x_getVolume(mcp41x_handle_t *hpot);
|
uint8_t mcp41x_getVolume(mcp41x_handle_t *hpot);
|
||||||
|
|||||||
24
firmware/shared_libs/drivers/mcu_cs/mcu_cs.c
Normal file
24
firmware/shared_libs/drivers/mcu_cs/mcu_cs.c
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include "mcu_cs.h"
|
||||||
|
|
||||||
|
// static cs_handle_t const _cs_handle = {.cs_on = mcu_cs_on, .cs_off = mcu_cs_off};
|
||||||
|
|
||||||
|
void mcu_cs_init(MCU_cs_t *hcs, GPIO_TypeDef *cs_port, uint16_t cs_pin, uint8_t cs_idle)
|
||||||
|
{
|
||||||
|
hcs->super.cs_on = mcu_cs_on;
|
||||||
|
hcs->super.cs_off = mcu_cs_off;
|
||||||
|
hcs->cs_port = cs_port;
|
||||||
|
hcs->cs_pin = cs_pin;
|
||||||
|
hcs->cs_idle = cs_idle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mcu_cs_on(cs_handle_t *hcs)
|
||||||
|
{
|
||||||
|
MCU_cs_t *_hcs = (MCU_cs_t *)hcs;
|
||||||
|
HAL_GPIO_WritePin(_hcs->cs_port, _hcs->cs_pin, !_hcs->cs_idle);
|
||||||
|
}
|
||||||
|
|
||||||
|
void mcu_cs_off(cs_handle_t *hcs)
|
||||||
|
{
|
||||||
|
MCU_cs_t *_hcs = (MCU_cs_t *)hcs;
|
||||||
|
HAL_GPIO_WritePin(_hcs->cs_port, _hcs->cs_pin, _hcs->cs_idle);
|
||||||
|
}
|
||||||
16
firmware/shared_libs/drivers/mcu_cs/mcu_cs.h
Normal file
16
firmware/shared_libs/drivers/mcu_cs/mcu_cs.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
#include "spi_cs_if.h"
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
cs_handle_t super;
|
||||||
|
GPIO_TypeDef *cs_port;
|
||||||
|
uint16_t cs_pin;
|
||||||
|
uint8_t cs_idle;
|
||||||
|
} MCU_cs_t;
|
||||||
|
|
||||||
|
void mcu_cs_init(MCU_cs_t *hcs, GPIO_TypeDef *cs_port, uint16_t cs_pin, uint8_t cs_idle);
|
||||||
|
void mcu_cs_on(cs_handle_t *me);
|
||||||
|
void mcu_cs_off(cs_handle_t *me);
|
||||||
14
firmware/shared_libs/utils/spi_cs/spi_cs_if.h
Normal file
14
firmware/shared_libs/utils/spi_cs/spi_cs_if.h
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
typedef struct cs_handle_t cs_handle_t;
|
||||||
|
|
||||||
|
typedef void (*cs_on_t)(cs_handle_t *hcs);
|
||||||
|
typedef void (*cs_off_t)(cs_handle_t *hcs);
|
||||||
|
|
||||||
|
struct cs_handle_t
|
||||||
|
{
|
||||||
|
cs_on_t cs_on;
|
||||||
|
cs_off_t cs_off;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user