Fix CubeMX's wrongdoing
This commit is contained in:
parent
c07df344f3
commit
171d2807d4
|
@ -7,10 +7,10 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define NUM_BUTTONS 6
|
||||
#define NUM_BUTTONS 7
|
||||
#define NUM_ENCS 2
|
||||
#define BUTTON_MIN_INTERVAL 50 // ms
|
||||
#define ENC_MAX_PHASE 50 // ms
|
||||
#define BUTTON_MIN_INTERVAL 50 // ms
|
||||
#define ENC_MAX_PHASE 50 // ms
|
||||
|
||||
typedef enum { UMK_BTN_PRESSED, UMK_ENC_CW, UMK_ENC_CCW } ButtonMessageKind;
|
||||
|
||||
|
@ -25,4 +25,4 @@ void ui_thread_entry(ULONG _);
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif // __INC_ui_H
|
||||
#endif // __INC_ui_H
|
||||
|
|
384
Core/Src/main.c
384
Core/Src/main.c
|
@ -17,12 +17,15 @@
|
|||
*/
|
||||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "app_threadx.h"
|
||||
#include "main.h"
|
||||
|
||||
#include "app_threadx.h"
|
||||
#include "app_touchgfx.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include <stdint.h>
|
||||
|
||||
#include "ft_logo_orange_rgb565.h"
|
||||
#include "ft_logo_rainbow_rgb565.h"
|
||||
#include "hx8357d.h"
|
||||
|
@ -30,8 +33,6 @@
|
|||
#include "params.h"
|
||||
#include "shorttimer.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
|
@ -100,19 +101,18 @@ static void MX_DMA2D_Init(void);
|
|||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
|
||||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
int main(void) {
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* 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();
|
||||
|
||||
/* USER CODE BEGIN Init */
|
||||
|
@ -170,11 +170,10 @@ int main(void)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void)
|
||||
{
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void) {
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||
|
||||
|
@ -182,18 +181,19 @@ void SystemClock_Config(void)
|
|||
RCC->CKGAENR = 0xFFFFFFFF;
|
||||
|
||||
/** Supply configuration update enable
|
||||
*/
|
||||
*/
|
||||
HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
|
||||
|
||||
/** Configure the main internal regulator output voltage
|
||||
*/
|
||||
*/
|
||||
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2);
|
||||
|
||||
while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
|
||||
while (!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {
|
||||
}
|
||||
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
|
@ -206,16 +206,15 @@ void SystemClock_Config(void)
|
|||
RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
|
||||
RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
|
||||
RCC_OscInitStruct.PLL.PLLFRACN = 0;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
||||
{
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
||||
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
|
||||
|RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
|
||||
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2 |
|
||||
RCC_CLOCKTYPE_D3PCLK1 | RCC_CLOCKTYPE_D1PCLK1;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV1;
|
||||
|
@ -224,20 +223,17 @@ void SystemClock_Config(void)
|
|||
RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
|
||||
RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
|
||||
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
|
||||
{
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief CRC Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_CRC_Init(void)
|
||||
{
|
||||
|
||||
* @brief CRC Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_CRC_Init(void) {
|
||||
/* USER CODE BEGIN CRC_Init 0 */
|
||||
|
||||
/* USER CODE END CRC_Init 0 */
|
||||
|
@ -251,24 +247,20 @@ static void MX_CRC_Init(void)
|
|||
hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE;
|
||||
hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE;
|
||||
hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES;
|
||||
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
||||
{
|
||||
if (HAL_CRC_Init(&hcrc) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN CRC_Init 2 */
|
||||
|
||||
/* USER CODE END CRC_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DMA2D Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_DMA2D_Init(void)
|
||||
{
|
||||
|
||||
* @brief DMA2D Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_DMA2D_Init(void) {
|
||||
/* USER CODE BEGIN DMA2D_Init 0 */
|
||||
|
||||
/* USER CODE END DMA2D_Init 0 */
|
||||
|
@ -287,28 +279,23 @@ static void MX_DMA2D_Init(void)
|
|||
hdma2d.LayerCfg[1].AlphaInverted = DMA2D_REGULAR_ALPHA;
|
||||
hdma2d.LayerCfg[1].RedBlueSwap = DMA2D_RB_REGULAR;
|
||||
hdma2d.LayerCfg[1].ChromaSubSampling = DMA2D_NO_CSS;
|
||||
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
|
||||
{
|
||||
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
|
||||
{
|
||||
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN DMA2D_Init 2 */
|
||||
|
||||
/* USER CODE END DMA2D_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief FDCAN1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_FDCAN1_Init(void)
|
||||
{
|
||||
|
||||
* @brief FDCAN1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_FDCAN1_Init(void) {
|
||||
/* USER CODE BEGIN FDCAN1_Init 0 */
|
||||
|
||||
/* USER CODE END FDCAN1_Init 0 */
|
||||
|
@ -344,24 +331,20 @@ static void MX_FDCAN1_Init(void)
|
|||
hfdcan1.Init.TxFifoQueueElmtsNbr = 1;
|
||||
hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
|
||||
hfdcan1.Init.TxElmtSize = FDCAN_DATA_BYTES_8;
|
||||
if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK)
|
||||
{
|
||||
if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN FDCAN1_Init 2 */
|
||||
|
||||
/* USER CODE END FDCAN1_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief JPEG Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_JPEG_Init(void)
|
||||
{
|
||||
|
||||
* @brief JPEG Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_JPEG_Init(void) {
|
||||
/* USER CODE BEGIN JPEG_Init 0 */
|
||||
|
||||
/* USER CODE END JPEG_Init 0 */
|
||||
|
@ -370,24 +353,20 @@ static void MX_JPEG_Init(void)
|
|||
|
||||
/* USER CODE END JPEG_Init 1 */
|
||||
hjpeg.Instance = JPEG;
|
||||
if (HAL_JPEG_Init(&hjpeg) != HAL_OK)
|
||||
{
|
||||
if (HAL_JPEG_Init(&hjpeg) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN JPEG_Init 2 */
|
||||
|
||||
/* USER CODE END JPEG_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief LTDC Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_LTDC_Init(void)
|
||||
{
|
||||
|
||||
* @brief LTDC Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_LTDC_Init(void) {
|
||||
/* USER CODE BEGIN LTDC_Init 0 */
|
||||
|
||||
/* USER CODE END LTDC_Init 0 */
|
||||
|
@ -413,8 +392,7 @@ static void MX_LTDC_Init(void)
|
|||
hltdc.Init.Backcolor.Blue = 0;
|
||||
hltdc.Init.Backcolor.Green = 0;
|
||||
hltdc.Init.Backcolor.Red = 0;
|
||||
if (HAL_LTDC_Init(&hltdc) != HAL_OK)
|
||||
{
|
||||
if (HAL_LTDC_Init(&hltdc) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
pLayerCfg.WindowX0 = 0;
|
||||
|
@ -432,24 +410,20 @@ static void MX_LTDC_Init(void)
|
|||
pLayerCfg.Backcolor.Blue = 0;
|
||||
pLayerCfg.Backcolor.Green = 0;
|
||||
pLayerCfg.Backcolor.Red = 0;
|
||||
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK)
|
||||
{
|
||||
if (HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 0) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN LTDC_Init 2 */
|
||||
|
||||
/* USER CODE END LTDC_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief OCTOSPI1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_OCTOSPI1_Init(void)
|
||||
{
|
||||
|
||||
* @brief OCTOSPI1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_OCTOSPI1_Init(void) {
|
||||
/* USER CODE BEGIN OCTOSPI1_Init 0 */
|
||||
|
||||
/* USER CODE END OCTOSPI1_Init 0 */
|
||||
|
@ -476,31 +450,27 @@ static void MX_OCTOSPI1_Init(void)
|
|||
hospi1.Init.DelayBlockBypass = HAL_OSPI_DELAY_BLOCK_BYPASSED;
|
||||
hospi1.Init.MaxTran = 0;
|
||||
hospi1.Init.Refresh = 0;
|
||||
if (HAL_OSPI_Init(&hospi1) != HAL_OK)
|
||||
{
|
||||
if (HAL_OSPI_Init(&hospi1) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sOspiManagerCfg.ClkPort = 1;
|
||||
sOspiManagerCfg.NCSPort = 1;
|
||||
sOspiManagerCfg.IOLowPort = HAL_OSPIM_IOPORT_1_LOW;
|
||||
if (HAL_OSPIM_Config(&hospi1, &sOspiManagerCfg, HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK)
|
||||
{
|
||||
if (HAL_OSPIM_Config(&hospi1, &sOspiManagerCfg,
|
||||
HAL_OSPI_TIMEOUT_DEFAULT_VALUE) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN OCTOSPI1_Init 2 */
|
||||
|
||||
/* USER CODE END OCTOSPI1_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief SPI3 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_SPI3_Init(void)
|
||||
{
|
||||
|
||||
* @brief SPI3 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_SPI3_Init(void) {
|
||||
/* USER CODE BEGIN SPI3_Init 0 */
|
||||
|
||||
/* USER CODE END SPI3_Init 0 */
|
||||
|
@ -524,31 +494,29 @@ static void MX_SPI3_Init(void)
|
|||
hspi3.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
|
||||
hspi3.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
|
||||
hspi3.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
|
||||
hspi3.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
|
||||
hspi3.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
|
||||
hspi3.Init.TxCRCInitializationPattern =
|
||||
SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
|
||||
hspi3.Init.RxCRCInitializationPattern =
|
||||
SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
|
||||
hspi3.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
|
||||
hspi3.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
|
||||
hspi3.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
|
||||
hspi3.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
|
||||
hspi3.Init.IOSwap = SPI_IO_SWAP_DISABLE;
|
||||
if (HAL_SPI_Init(&hspi3) != HAL_OK)
|
||||
{
|
||||
if (HAL_SPI_Init(&hspi3) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN SPI3_Init 2 */
|
||||
|
||||
/* USER CODE END SPI3_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TIM1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_TIM1_Init(void)
|
||||
{
|
||||
|
||||
* @brief TIM1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_TIM1_Init(void) {
|
||||
/* USER CODE BEGIN TIM1_Init 0 */
|
||||
|
||||
/* USER CODE END TIM1_Init 0 */
|
||||
|
@ -568,24 +536,20 @@ static void MX_TIM1_Init(void)
|
|||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim1.Init.RepetitionCounter = 0;
|
||||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
|
||||
{
|
||||
if (HAL_TIM_Base_Init(&htim1) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
|
||||
{
|
||||
if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_PWM_Init(&htim1) != HAL_OK)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
|
@ -595,16 +559,13 @@ static void MX_TIM1_Init(void)
|
|||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
|
||||
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
|
||||
{
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_3) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
|
||||
|
@ -618,25 +579,21 @@ static void MX_TIM1_Init(void)
|
|||
sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH;
|
||||
sBreakDeadTimeConfig.Break2Filter = 0;
|
||||
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
|
||||
if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK)
|
||||
{
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TIM2 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_TIM2_Init(void)
|
||||
{
|
||||
|
||||
* @brief TIM2 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_TIM2_Init(void) {
|
||||
/* USER CODE BEGIN TIM2_Init 0 */
|
||||
|
||||
/* USER CODE END TIM2_Init 0 */
|
||||
|
@ -654,48 +611,40 @@ static void MX_TIM2_Init(void)
|
|||
htim2.Init.Period = 99;
|
||||
htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
|
||||
{
|
||||
if (HAL_TIM_Base_Init(&htim2) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||
if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
|
||||
{
|
||||
if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_PWM_Init(&htim2) != HAL_OK)
|
||||
{
|
||||
if (HAL_TIM_PWM_Init(&htim2) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
|
||||
{
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 100;
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4) != HAL_OK)
|
||||
{
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_4) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM2_Init 2 */
|
||||
|
||||
/* USER CODE END TIM2_Init 2 */
|
||||
HAL_TIM_MspPostInit(&htim2);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TIM4 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_TIM4_Init(void)
|
||||
{
|
||||
|
||||
* @brief TIM4 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_TIM4_Init(void) {
|
||||
/* USER CODE BEGIN TIM4_Init 0 */
|
||||
|
||||
/* USER CODE END TIM4_Init 0 */
|
||||
|
@ -712,43 +661,36 @@ static void MX_TIM4_Init(void)
|
|||
htim4.Init.Period = 65535;
|
||||
htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_PWM_Init(&htim4) != HAL_OK)
|
||||
{
|
||||
if (HAL_TIM_PWM_Init(&htim4) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK)
|
||||
{
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 0;
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
|
||||
{
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
|
||||
{
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_2) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM4_Init 2 */
|
||||
|
||||
/* USER CODE END TIM4_Init 2 */
|
||||
HAL_TIM_MspPostInit(&htim4);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TIM17 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_TIM17_Init(void)
|
||||
{
|
||||
|
||||
* @brief TIM17 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_TIM17_Init(void) {
|
||||
/* USER CODE BEGIN TIM17_Init 0 */
|
||||
|
||||
/* USER CODE END TIM17_Init 0 */
|
||||
|
@ -757,28 +699,24 @@ static void MX_TIM17_Init(void)
|
|||
|
||||
/* USER CODE END TIM17_Init 1 */
|
||||
htim17.Instance = TIM17;
|
||||
htim17.Init.Prescaler = 16-1;
|
||||
htim17.Init.Prescaler = 16 - 1;
|
||||
htim17.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim17.Init.Period = 1000-1;
|
||||
htim17.Init.Period = 1000 - 1;
|
||||
htim17.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim17.Init.RepetitionCounter = 0;
|
||||
htim17.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
if (HAL_TIM_Base_Init(&htim17) != HAL_OK)
|
||||
{
|
||||
if (HAL_TIM_Base_Init(&htim17) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM17_Init 2 */
|
||||
|
||||
/* USER CODE END TIM17_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable DMA controller clock
|
||||
*/
|
||||
static void MX_DMA_Init(void)
|
||||
{
|
||||
|
||||
* Enable DMA controller clock
|
||||
*/
|
||||
static void MX_DMA_Init(void) {
|
||||
/* DMA controller clock enable */
|
||||
__HAL_RCC_DMA1_CLK_ENABLE();
|
||||
|
||||
|
@ -786,19 +724,17 @@ static void MX_DMA_Init(void)
|
|||
/* DMA1_Stream0_IRQn interrupt configuration */
|
||||
HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief GPIO Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_GPIO_Init(void)
|
||||
{
|
||||
* @brief GPIO Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_GPIO_Init(void) {
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||
/* USER CODE END MX_GPIO_Init_1 */
|
||||
/* USER CODE BEGIN MX_GPIO_Init_1 */
|
||||
/* USER CODE END MX_GPIO_Init_1 */
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOE_CLK_ENABLE();
|
||||
|
@ -811,33 +747,38 @@ static void MX_GPIO_Init(void)
|
|||
__HAL_RCC_GPIOG_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOA, STATUS1_Pin|STATUS2_Pin|DISPSPI_SCL_Pin|DISPSPI_SDA_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(
|
||||
GPIOA, STATUS1_Pin | STATUS2_Pin | DISPSPI_SCL_Pin | DISPSPI_SDA_Pin,
|
||||
GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(LED_LE_GPIO_Port, LED_LE_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOG, DISPSPI_CSX_Pin|DISPSPI_DCX_Pin|DISP_RESET_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(GPIOG, DISPSPI_CSX_Pin | DISPSPI_DCX_Pin | DISP_RESET_Pin,
|
||||
GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(BOOT0_SET_GPIO_Port, BOOT0_SET_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pins : ENC1A_Pin ENC1B_Pin ENC2A_Pin ENC2B_Pin */
|
||||
GPIO_InitStruct.Pin = ENC1A_Pin|ENC1B_Pin|ENC2A_Pin|ENC2B_Pin;
|
||||
GPIO_InitStruct.Pin = ENC1A_Pin | ENC1B_Pin | ENC2A_Pin | ENC2B_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : BTN1_Pin BTN2_Pin BTN3_Pin BTN4_Pin
|
||||
BTN5_Pin BTN6_Pin SW_DRS_Pin */
|
||||
GPIO_InitStruct.Pin = BTN1_Pin|BTN2_Pin|BTN3_Pin|BTN4_Pin
|
||||
|BTN5_Pin|BTN6_Pin|SW_DRS_Pin;
|
||||
GPIO_InitStruct.Pin = BTN1_Pin | BTN2_Pin | BTN3_Pin | BTN4_Pin | BTN5_Pin |
|
||||
BTN6_Pin | SW_DRS_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : STATUS1_Pin STATUS2_Pin DISPSPI_SCL_Pin DISPSPI_SDA_Pin */
|
||||
GPIO_InitStruct.Pin = STATUS1_Pin|STATUS2_Pin|DISPSPI_SCL_Pin|DISPSPI_SDA_Pin;
|
||||
/*Configure GPIO pins : STATUS1_Pin STATUS2_Pin DISPSPI_SCL_Pin
|
||||
* DISPSPI_SDA_Pin */
|
||||
GPIO_InitStruct.Pin =
|
||||
STATUS1_Pin | STATUS2_Pin | DISPSPI_SCL_Pin | DISPSPI_SDA_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
|
@ -851,7 +792,7 @@ static void MX_GPIO_Init(void)
|
|||
HAL_GPIO_Init(LED_LE_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : DISPSPI_CSX_Pin DISPSPI_DCX_Pin DISP_RESET_Pin */
|
||||
GPIO_InitStruct.Pin = DISPSPI_CSX_Pin|DISPSPI_DCX_Pin|DISP_RESET_Pin;
|
||||
GPIO_InitStruct.Pin = DISPSPI_CSX_Pin | DISPSPI_DCX_Pin | DISP_RESET_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
|
@ -874,8 +815,8 @@ static void MX_GPIO_Init(void)
|
|||
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
|
||||
|
||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||
/* USER CODE END MX_GPIO_Init_2 */
|
||||
/* USER CODE BEGIN MX_GPIO_Init_2 */
|
||||
/* USER CODE END MX_GPIO_Init_2 */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
|
@ -886,15 +827,14 @@ extern "C" {
|
|||
/* USER CODE END 4 */
|
||||
|
||||
/**
|
||||
* @brief Period elapsed callback in non blocking mode
|
||||
* @note This function is called when TIM6 interrupt took place, inside
|
||||
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||
* a global variable "uwTick" used as application time base.
|
||||
* @param htim : TIM handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
||||
{
|
||||
* @brief Period elapsed callback in non blocking mode
|
||||
* @note This function is called when TIM6 interrupt took place, inside
|
||||
* HAL_TIM_IRQHandler(). It makes a direct call to HAL_IncTick() to increment
|
||||
* a global variable "uwTick" used as application time base.
|
||||
* @param htim : TIM handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
||||
/* USER CODE BEGIN Callback 0 */
|
||||
|
||||
/* USER CODE END Callback 0 */
|
||||
|
@ -909,11 +849,10 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
*/
|
||||
void Error_Handler(void)
|
||||
{
|
||||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
*/
|
||||
void Error_Handler(void) {
|
||||
/* USER CODE BEGIN Error_Handler_Debug */
|
||||
/* User can add his own implementation to report the HAL error return state */
|
||||
__disable_irq();
|
||||
|
@ -929,16 +868,15 @@ void _damnyoucubemx() {
|
|||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief Reports the name of the source file and the source line number
|
||||
* where the assert_param error has occurred.
|
||||
* @param file: pointer to the source file name
|
||||
* @param line: assert_param error line source number
|
||||
* @retval None
|
||||
*/
|
||||
void assert_failed(uint8_t *file, uint32_t line)
|
||||
{
|
||||
* @brief Reports the name of the source file and the source line number
|
||||
* where the assert_param error has occurred.
|
||||
* @param file: pointer to the source file name
|
||||
* @param line: assert_param error line source number
|
||||
* @retval None
|
||||
*/
|
||||
void assert_failed(uint8_t *file, uint32_t line) {
|
||||
/* USER CODE BEGIN 6 */
|
||||
/* User 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,
|
||||
|
|
|
@ -1,21 +1,22 @@
|
|||
#include "ui.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "hx8357d.h"
|
||||
#include "leds.h"
|
||||
#include "main.h"
|
||||
#include "stm32h7a3xx.h"
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "stm32h7xx_hal_gpio.h"
|
||||
#include "tx_api.h"
|
||||
|
||||
#include "hx8357d.h"
|
||||
#include "main.h"
|
||||
#include "vehicle.h"
|
||||
#include <stdint.h>
|
||||
|
||||
void ui_thread_entry(ULONG _) {
|
||||
GPIO_TypeDef *button_ports[NUM_BUTTONS] = {BTN1_GPIO_Port, BTN2_GPIO_Port,
|
||||
BTN3_GPIO_Port, BTN4_GPIO_Port,
|
||||
BTN5_GPIO_Port, BTN6_GPIO_Port};
|
||||
uint16_t button_pins[NUM_BUTTONS] = {BTN1_Pin, BTN2_Pin, BTN3_Pin,
|
||||
BTN4_Pin, BTN5_Pin, BTN6_Pin};
|
||||
GPIO_TypeDef *button_ports[NUM_BUTTONS] = {
|
||||
BTN1_GPIO_Port, BTN2_GPIO_Port, BTN3_GPIO_Port, BTN4_GPIO_Port,
|
||||
BTN5_GPIO_Port, BTN6_GPIO_Port, SW_DRS_GPIO_Port};
|
||||
uint16_t button_pins[NUM_BUTTONS] = {BTN1_Pin, BTN2_Pin, BTN3_Pin, BTN4_Pin,
|
||||
BTN5_Pin, BTN6_Pin, SW_DRS_Pin};
|
||||
GPIO_PinState button_states[NUM_BUTTONS] = {GPIO_PIN_RESET};
|
||||
uint32_t button_press_times[NUM_BUTTONS] = {HAL_GetTick()};
|
||||
|
||||
|
@ -43,6 +44,11 @@ void ui_thread_entry(ULONG _) {
|
|||
if (press_event == 1 && button_states[1]) {
|
||||
tx_event_flags_set(&gui_update_events, GUI_UPDATE_NEXT_SCREEN, TX_OR);
|
||||
}
|
||||
|
||||
if (button_states[5] == GPIO_PIN_SET) {
|
||||
led_start_animation(ANIM_RAINBOW);
|
||||
}
|
||||
|
||||
vehicle_broadcast_buttons(button_states);
|
||||
// Release so other threads can get scheduled
|
||||
tx_thread_sleep(1);
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
#include "vehicle.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "ui.h"
|
||||
#include "vehicle_state.h"
|
||||
|
||||
#include "can-halal.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "stm32h7xx.h"
|
||||
#include "stm32h7xx_hal.h"
|
||||
#include "stm32h7xx_hal_fdcan.h"
|
||||
#include "stm32h7xx_hal_gpio.h"
|
||||
#include "tx_api.h"
|
||||
#include "ui.h"
|
||||
#include "vehicle_state.h"
|
||||
|
||||
#define CAN_ID_AMS_SLAVE_PANIC 0x9
|
||||
#define CAN_ID_AMS_STATUS 0xA
|
||||
|
@ -98,7 +96,8 @@ void vehicle_broadcast_param(ParamType param, int32_t value) {
|
|||
|
||||
void vehicle_broadcast_buttons(GPIO_PinState *button_states) {
|
||||
uint8_t data = (button_states[0] << 2) | (button_states[1] << 0) |
|
||||
(button_states[2] << 1) | (button_states[3] << 3);
|
||||
(button_states[2] << 1) | (button_states[3] << 3) |
|
||||
(button_states[6] << 4);
|
||||
ftcan_transmit(CAN_ID_STW_BUTTONS, &data, 1);
|
||||
}
|
||||
|
||||
|
@ -112,142 +111,144 @@ void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
|
|||
}
|
||||
} else {
|
||||
switch (id) {
|
||||
case CAN_ID_AMS_SLAVE_PANIC:
|
||||
vehicle_state.last_ams_slave_panic.id = data[0];
|
||||
vehicle_state.last_ams_slave_panic.kind = data[1];
|
||||
ptr = &data[2];
|
||||
vehicle_state.last_ams_slave_panic.arg =
|
||||
ftcan_unmarshal_unsigned(&ptr, 4);
|
||||
break;
|
||||
case CAN_ID_AMS_STATUS:
|
||||
vehicle_state.ts_state = data[0] & 0x7F;
|
||||
vehicle_state.sdc_closed = (data[0] & 0x80) >> 7;
|
||||
vehicle_state.soc_ts = data[1];
|
||||
ptr = &data[2];
|
||||
vehicle_state.min_cell_volt =
|
||||
ftcan_unmarshal_unsigned(&ptr, 2) * CAN_AMS_STATUS_VOLTAGE_FACTOR;
|
||||
vehicle_state.max_cell_temp =
|
||||
ftcan_unmarshal_signed(&ptr, 2) * CAN_AMS_STATUS_TEMP_FACTOR;
|
||||
vehicle_state.imd_ok = (data[6] >> 7);
|
||||
// TODO: Separate temperatures for left and right side of battery
|
||||
vehicle_state.temps.bat_l = vehicle_state.max_cell_temp;
|
||||
vehicle_state.temps.bat_r = vehicle_state.max_cell_temp;
|
||||
break;
|
||||
case CAN_ID_SDCL_TX:
|
||||
vehicle_state.sdcl_state[0] = data[0] & CAN_SDCL_STATE_1_MASK;
|
||||
vehicle_state.sdcl_state[1] = data[0] & CAN_SDCL_STATE_2_MASK;
|
||||
vehicle_state.sdcl_state[2] = data[0] & CAN_SDCL_STATE_3_MASK;
|
||||
break;
|
||||
case CAN_ID_PDU_RESPONSE:
|
||||
vehicle_state.pdu_sdc_active = data[0] & CAN_PDU_RESPONSE_SDC_TX_MASK;
|
||||
break;
|
||||
case CAN_ID_AMS_ERROR:
|
||||
vehicle_state.last_ams_error.kind = data[0];
|
||||
vehicle_state.last_ams_error.arg = data[1];
|
||||
break;
|
||||
case CAN_ID_JETSON_TX:
|
||||
vehicle_state.last_jetson_msg = HAL_GetTick();
|
||||
vehicle_state.as_ok = data[0] & CAN_JETSON_TX_AS_OK_MASK;
|
||||
vehicle_state.desired_speed =
|
||||
((int8_t)data[1]) * CAN_JETSON_TX_SPEED_FACTOR;
|
||||
vehicle_state.desired_angle =
|
||||
((int8_t)data[2]) * CAN_JETSON_TX_ANGLE_FACTOR;
|
||||
break;
|
||||
case CAN_ID_ABX_DRIVER:
|
||||
vehicle_state.brake_press_f =
|
||||
(data[1] | ((data[2] & 0x0F) << 8)) * CAN_ABX_DRIVER_PRESS_FACTOR;
|
||||
vehicle_state.brake_press_r =
|
||||
((data[2] >> 4) | (data[3] << 4)) * CAN_ABX_DRIVER_PRESS_FACTOR;
|
||||
vehicle_state.speed = data[5] * CAN_ABX_DRIVER_SPEED_FACTOR;
|
||||
break;
|
||||
case CAN_ID_ABX_HYDRAULICS:
|
||||
vehicle_state.hyd_press_a =
|
||||
(data[0] | ((data[1] & 0x0F) << 8)) * CAN_ABX_DRIVER_PRESS_FACTOR;
|
||||
vehicle_state.hyd_press_b =
|
||||
((data[1] >> 4) | (data[2] << 4)) * CAN_ABX_DRIVER_PRESS_FACTOR;
|
||||
break;
|
||||
case CAN_ID_ABX_TIMINGS:
|
||||
vehicle_state.lap_best = (data[0] | (data[1] << 8)) * 0.01f;
|
||||
vehicle_state.lap_last = (data[2] | (data[3] << 8)) * 0.01f;
|
||||
break;
|
||||
case CAN_ID_ABX_BRAKE_T:
|
||||
vehicle_state.temps.brake_fl = (data[0] | (data[1] << 8)) * 0.01f;
|
||||
vehicle_state.temps.brake_fr = (data[2] | (data[3] << 8)) * 0.01f;
|
||||
vehicle_state.temps.brake_rl = (data[4] | (data[5] << 8)) * 0.01f;
|
||||
vehicle_state.temps.brake_rr = (data[6] | (data[7] << 8)) * 0.01f;
|
||||
break;
|
||||
case CAN_ID_CS_INTERNAL:
|
||||
vehicle_state.temps.inv_l =
|
||||
(data[0] | (data[1] << 8)) * CAN_CS_INTERNAL_TEMP_FACTOR;
|
||||
vehicle_state.temps.inv_r =
|
||||
(data[2] | (data[3] << 8)) * CAN_CS_INTERNAL_TEMP_FACTOR;
|
||||
vehicle_state.temps.mot_l =
|
||||
(data[4] | (data[5] << 8)) * CAN_CS_INTERNAL_TEMP_FACTOR;
|
||||
vehicle_state.temps.mot_r =
|
||||
(data[6] | (data[7] << 8)) * CAN_CS_INTERNAL_TEMP_FACTOR;
|
||||
break;
|
||||
case CAN_ID_ABX_MISC:
|
||||
vehicle_state.distance_total =
|
||||
(data[3] | (data[4] << 8)) * CAN_ABX_MISC_DISTANCE_TOTAL_FACTOR;
|
||||
vehicle_state.soc_lv = data[5];
|
||||
vehicle_state.lv_bat_voltage =
|
||||
data[6] * CAN_ABX_MISC_LV_BAT_VOLTAGE_FACTOR;
|
||||
break;
|
||||
case CAN_ID_EPSC_OUT:
|
||||
vehicle_state.last_epsc_msg = HAL_GetTick();
|
||||
vehicle_state.measured_angle =
|
||||
((int16_t)((data[0] << 8) | (data[1]))) * CAN_EPSC_OUT_ANGLE_FACTOR;
|
||||
break;
|
||||
case CAN_ID_AS_MISSION_FB:
|
||||
vehicle_state.active_mission = data[0] & 0b111;
|
||||
break;
|
||||
case CAN_ID_STW_STATUS:
|
||||
vehicle_state.as_state = data[0] & 0b111;
|
||||
vehicle_state.r2d_progress = data[0] >> 4;
|
||||
vehicle_state.errors.invl_ready = (data[1] >> 0) & 1;
|
||||
vehicle_state.errors.invr_ready = (data[1] >> 1) & 1;
|
||||
vehicle_state.errors.sdc_bfl = (data[1] >> 2) & 1;
|
||||
vehicle_state.errors.sdc_brl = (data[1] >> 3) & 1;
|
||||
vehicle_state.errors.sdc_acc = (data[1] >> 4) & 1;
|
||||
vehicle_state.errors.sdc_hvb = (data[1] >> 5) & 1;
|
||||
vehicle_state.lap_count = data[2] & 0b111111;
|
||||
vehicle_state.ini_chk_state = data[3];
|
||||
vehicle_state.errors.err_sdc = (data[4] >> 0) & 1;
|
||||
vehicle_state.errors.err_ams = (data[4] >> 1) & 1;
|
||||
vehicle_state.errors.err_pdu = (data[4] >> 2) & 1;
|
||||
vehicle_state.errors.err_ini_chk = (data[4] >> 3) & 1;
|
||||
vehicle_state.errors.err_con_mon = (data[4] >> 4) & 1;
|
||||
vehicle_state.errors.err_scs = (data[4] >> 5) & 1;
|
||||
vehicle_state.errors.err_sbspd = (data[4] >> 6) & 1;
|
||||
vehicle_state.errors.err_appsp = (data[4] >> 7) & 1;
|
||||
vehicle_state.errors.err_as = (data[5] >> 0) & 1;
|
||||
vehicle_state.errors.err_ros = (data[5] >> 1) & 1;
|
||||
vehicle_state.errors.err_res = (data[5] >> 2) & 1;
|
||||
vehicle_state.errors.err_invl = (data[5] >> 3) & 1;
|
||||
vehicle_state.errors.err_invr = (data[5] >> 4) & 1;
|
||||
break;
|
||||
case CAN_ID_ABX_PARAM_CONFIRMED:
|
||||
vehicle_state.last_param_confirmed = data[0];
|
||||
tx_event_flags_set(&gui_update_events, GUI_UPDATE_PARAM_CONFIRMED, TX_OR);
|
||||
break;
|
||||
case CAN_ID_SHUNT_CURRENT: {
|
||||
// The first two bytes of shunt result messages are metadata
|
||||
const uint8_t *result_ptr = &data[2];
|
||||
vehicle_state.ts_current = ftcan_unmarshal_signed(&result_ptr, 4) * 1e-3;
|
||||
break;
|
||||
}
|
||||
case CAN_ID_SHUNT_VOLTAGE1: {
|
||||
const uint8_t *result_ptr = &data[2];
|
||||
vehicle_state.ts_voltage_bat =
|
||||
ftcan_unmarshal_signed(&result_ptr, 4) * 1e-3;
|
||||
break;
|
||||
}
|
||||
case CAN_ID_SHUNT_VOLTAGE2: {
|
||||
const uint8_t *result_ptr = &data[2];
|
||||
vehicle_state.ts_voltage_veh =
|
||||
ftcan_unmarshal_signed(&result_ptr, 4) * 1e-3;
|
||||
break;
|
||||
}
|
||||
case CAN_ID_AMS_SLAVE_PANIC:
|
||||
vehicle_state.last_ams_slave_panic.id = data[0];
|
||||
vehicle_state.last_ams_slave_panic.kind = data[1];
|
||||
ptr = &data[2];
|
||||
vehicle_state.last_ams_slave_panic.arg =
|
||||
ftcan_unmarshal_unsigned(&ptr, 4);
|
||||
break;
|
||||
case CAN_ID_AMS_STATUS:
|
||||
vehicle_state.ts_state = data[0] & 0x7F;
|
||||
vehicle_state.sdc_closed = (data[0] & 0x80) >> 7;
|
||||
vehicle_state.soc_ts = data[1];
|
||||
ptr = &data[2];
|
||||
vehicle_state.min_cell_volt =
|
||||
ftcan_unmarshal_unsigned(&ptr, 2) * CAN_AMS_STATUS_VOLTAGE_FACTOR;
|
||||
vehicle_state.max_cell_temp =
|
||||
ftcan_unmarshal_signed(&ptr, 2) * CAN_AMS_STATUS_TEMP_FACTOR;
|
||||
vehicle_state.imd_ok = (data[6] >> 7);
|
||||
// TODO: Separate temperatures for left and right side of battery
|
||||
vehicle_state.temps.bat_l = vehicle_state.max_cell_temp;
|
||||
vehicle_state.temps.bat_r = vehicle_state.max_cell_temp;
|
||||
break;
|
||||
case CAN_ID_SDCL_TX:
|
||||
vehicle_state.sdcl_state[0] = data[0] & CAN_SDCL_STATE_1_MASK;
|
||||
vehicle_state.sdcl_state[1] = data[0] & CAN_SDCL_STATE_2_MASK;
|
||||
vehicle_state.sdcl_state[2] = data[0] & CAN_SDCL_STATE_3_MASK;
|
||||
break;
|
||||
case CAN_ID_PDU_RESPONSE:
|
||||
vehicle_state.pdu_sdc_active = data[0] & CAN_PDU_RESPONSE_SDC_TX_MASK;
|
||||
break;
|
||||
case CAN_ID_AMS_ERROR:
|
||||
vehicle_state.last_ams_error.kind = data[0];
|
||||
vehicle_state.last_ams_error.arg = data[1];
|
||||
break;
|
||||
case CAN_ID_JETSON_TX:
|
||||
vehicle_state.last_jetson_msg = HAL_GetTick();
|
||||
vehicle_state.as_ok = data[0] & CAN_JETSON_TX_AS_OK_MASK;
|
||||
vehicle_state.desired_speed =
|
||||
((int8_t)data[1]) * CAN_JETSON_TX_SPEED_FACTOR;
|
||||
vehicle_state.desired_angle =
|
||||
((int8_t)data[2]) * CAN_JETSON_TX_ANGLE_FACTOR;
|
||||
break;
|
||||
case CAN_ID_ABX_DRIVER:
|
||||
vehicle_state.brake_press_f =
|
||||
(data[1] | ((data[2] & 0x0F) << 8)) * CAN_ABX_DRIVER_PRESS_FACTOR;
|
||||
vehicle_state.brake_press_r =
|
||||
((data[2] >> 4) | (data[3] << 4)) * CAN_ABX_DRIVER_PRESS_FACTOR;
|
||||
vehicle_state.speed = data[5] * CAN_ABX_DRIVER_SPEED_FACTOR;
|
||||
break;
|
||||
case CAN_ID_ABX_HYDRAULICS:
|
||||
vehicle_state.hyd_press_a =
|
||||
(data[0] | ((data[1] & 0x0F) << 8)) * CAN_ABX_DRIVER_PRESS_FACTOR;
|
||||
vehicle_state.hyd_press_b =
|
||||
((data[1] >> 4) | (data[2] << 4)) * CAN_ABX_DRIVER_PRESS_FACTOR;
|
||||
break;
|
||||
case CAN_ID_ABX_TIMINGS:
|
||||
vehicle_state.lap_best = (data[0] | (data[1] << 8)) * 0.01f;
|
||||
vehicle_state.lap_last = (data[2] | (data[3] << 8)) * 0.01f;
|
||||
break;
|
||||
case CAN_ID_ABX_BRAKE_T:
|
||||
vehicle_state.temps.brake_fl = (data[0] | (data[1] << 8)) * 0.01f;
|
||||
vehicle_state.temps.brake_fr = (data[2] | (data[3] << 8)) * 0.01f;
|
||||
vehicle_state.temps.brake_rl = (data[4] | (data[5] << 8)) * 0.01f;
|
||||
vehicle_state.temps.brake_rr = (data[6] | (data[7] << 8)) * 0.01f;
|
||||
break;
|
||||
case CAN_ID_CS_INTERNAL:
|
||||
vehicle_state.temps.inv_l =
|
||||
(data[0] | (data[1] << 8)) * CAN_CS_INTERNAL_TEMP_FACTOR;
|
||||
vehicle_state.temps.inv_r =
|
||||
(data[2] | (data[3] << 8)) * CAN_CS_INTERNAL_TEMP_FACTOR;
|
||||
vehicle_state.temps.mot_l =
|
||||
(data[4] | (data[5] << 8)) * CAN_CS_INTERNAL_TEMP_FACTOR;
|
||||
vehicle_state.temps.mot_r =
|
||||
(data[6] | (data[7] << 8)) * CAN_CS_INTERNAL_TEMP_FACTOR;
|
||||
break;
|
||||
case CAN_ID_ABX_MISC:
|
||||
vehicle_state.distance_total =
|
||||
(data[3] | (data[4] << 8)) * CAN_ABX_MISC_DISTANCE_TOTAL_FACTOR;
|
||||
vehicle_state.soc_lv = data[5];
|
||||
vehicle_state.lv_bat_voltage =
|
||||
data[6] * CAN_ABX_MISC_LV_BAT_VOLTAGE_FACTOR;
|
||||
break;
|
||||
case CAN_ID_EPSC_OUT:
|
||||
vehicle_state.last_epsc_msg = HAL_GetTick();
|
||||
vehicle_state.measured_angle =
|
||||
((int16_t)((data[0] << 8) | (data[1]))) * CAN_EPSC_OUT_ANGLE_FACTOR;
|
||||
break;
|
||||
case CAN_ID_AS_MISSION_FB:
|
||||
vehicle_state.active_mission = data[0] & 0b111;
|
||||
break;
|
||||
case CAN_ID_STW_STATUS:
|
||||
vehicle_state.as_state = data[0] & 0b111;
|
||||
vehicle_state.r2d_progress = data[0] >> 4;
|
||||
vehicle_state.errors.invl_ready = (data[1] >> 0) & 1;
|
||||
vehicle_state.errors.invr_ready = (data[1] >> 1) & 1;
|
||||
vehicle_state.errors.sdc_bfl = (data[1] >> 2) & 1;
|
||||
vehicle_state.errors.sdc_brl = (data[1] >> 3) & 1;
|
||||
vehicle_state.errors.sdc_acc = (data[1] >> 4) & 1;
|
||||
vehicle_state.errors.sdc_hvb = (data[1] >> 5) & 1;
|
||||
vehicle_state.lap_count = data[2] & 0b111111;
|
||||
vehicle_state.ini_chk_state = data[3];
|
||||
vehicle_state.errors.err_sdc = (data[4] >> 0) & 1;
|
||||
vehicle_state.errors.err_ams = (data[4] >> 1) & 1;
|
||||
vehicle_state.errors.err_pdu = (data[4] >> 2) & 1;
|
||||
vehicle_state.errors.err_ini_chk = (data[4] >> 3) & 1;
|
||||
vehicle_state.errors.err_con_mon = (data[4] >> 4) & 1;
|
||||
vehicle_state.errors.err_scs = (data[4] >> 5) & 1;
|
||||
vehicle_state.errors.err_sbspd = (data[4] >> 6) & 1;
|
||||
vehicle_state.errors.err_appsp = (data[4] >> 7) & 1;
|
||||
vehicle_state.errors.err_as = (data[5] >> 0) & 1;
|
||||
vehicle_state.errors.err_ros = (data[5] >> 1) & 1;
|
||||
vehicle_state.errors.err_res = (data[5] >> 2) & 1;
|
||||
vehicle_state.errors.err_invl = (data[5] >> 3) & 1;
|
||||
vehicle_state.errors.err_invr = (data[5] >> 4) & 1;
|
||||
break;
|
||||
case CAN_ID_ABX_PARAM_CONFIRMED:
|
||||
vehicle_state.last_param_confirmed = data[0];
|
||||
tx_event_flags_set(&gui_update_events, GUI_UPDATE_PARAM_CONFIRMED,
|
||||
TX_OR);
|
||||
break;
|
||||
case CAN_ID_SHUNT_CURRENT: {
|
||||
// The first two bytes of shunt result messages are metadata
|
||||
const uint8_t *result_ptr = &data[2];
|
||||
vehicle_state.ts_current =
|
||||
ftcan_unmarshal_signed(&result_ptr, 4) * 1e-3;
|
||||
break;
|
||||
}
|
||||
case CAN_ID_SHUNT_VOLTAGE1: {
|
||||
const uint8_t *result_ptr = &data[2];
|
||||
vehicle_state.ts_voltage_bat =
|
||||
ftcan_unmarshal_signed(&result_ptr, 4) * 1e-3;
|
||||
break;
|
||||
}
|
||||
case CAN_ID_SHUNT_VOLTAGE2: {
|
||||
const uint8_t *result_ptr = &data[2];
|
||||
vehicle_state.ts_voltage_veh =
|
||||
ftcan_unmarshal_signed(&result_ptr, 4) * 1e-3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
tx_event_flags_set(&gui_update_events, GUI_UPDATE_VEHICLE_STATE, TX_OR);
|
||||
|
|
50
Makefile
50
Makefile
|
@ -39,6 +39,34 @@ C_SOURCES = \
|
|||
Core/Src/main.c \
|
||||
Core/Src/stm32h7xx_it.c \
|
||||
Core/Src/stm32h7xx_hal_msp.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc_ex.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash_ex.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_gpio.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_hsem.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma_ex.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mdma.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr_ex.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c_ex.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_exti.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma2d.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_fdcan.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_jpeg.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ltdc.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ltdc_ex.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ospi.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi_ex.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim_ex.c \
|
||||
Core/Src/system_stm32h7xx.c \
|
||||
Utilities/JPEG/jpeg_utils.c \
|
||||
Core/Src/app_threadx.c \
|
||||
Core/Src/stm32h7xx_hal_timebase_tim.c \
|
||||
AZURE_RTOS/App/app_azure_rtos.c \
|
||||
|
@ -199,6 +227,8 @@ Middlewares/ST/threadx/common/src/txe_timer_deactivate.c \
|
|||
Middlewares/ST/threadx/common/src/txe_timer_delete.c \
|
||||
Middlewares/ST/threadx/common/src/txe_timer_info_get.c \
|
||||
TouchGFX/App/app_touchgfx.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_crc_ex.c
|
||||
TouchGFX/target/TouchGFXHAL.cpp \
|
||||
TouchGFX/target/STM32TouchController.cpp \
|
||||
TouchGFX/target/TouchGFXGPIO.cpp \
|
||||
|
@ -212,16 +242,16 @@ Core/Src/syscalls.c
|
|||
# ASM sources
|
||||
ASM_SOURCES = \
|
||||
startup_stm32h7a3xx.s \
|
||||
Middlewares/ST/threadx/ports/cortex_m7/gnu/src/tx_misra.S \
|
||||
Middlewares/ST/threadx/ports/cortex_m7/gnu/src/tx_thread_context_restore.S \
|
||||
Middlewares/ST/threadx/ports/cortex_m7/gnu/src/tx_thread_context_save.S \
|
||||
Middlewares/ST/threadx/ports/cortex_m7/gnu/src/tx_thread_interrupt_control.S \
|
||||
Middlewares/ST/threadx/ports/cortex_m7/gnu/src/tx_thread_interrupt_disable.S \
|
||||
Middlewares/ST/threadx/ports/cortex_m7/gnu/src/tx_thread_interrupt_restore.S \
|
||||
Middlewares/ST/threadx/ports/cortex_m7/gnu/src/tx_thread_schedule.S \
|
||||
Middlewares/ST/threadx/ports/cortex_m7/gnu/src/tx_thread_stack_build.S \
|
||||
Middlewares/ST/threadx/ports/cortex_m7/gnu/src/tx_thread_system_return.S \
|
||||
Middlewares/ST/threadx/ports/cortex_m7/gnu/src/tx_timer_interrupt.S
|
||||
Middlewares/ST/threadx/ports/cortex_m7/gnu/src/tx_misra.s \
|
||||
Middlewares/ST/threadx/ports/cortex_m7/gnu/src/tx_thread_context_restore.s \
|
||||
Middlewares/ST/threadx/ports/cortex_m7/gnu/src/tx_thread_context_save.s \
|
||||
Middlewares/ST/threadx/ports/cortex_m7/gnu/src/tx_thread_interrupt_control.s \
|
||||
Middlewares/ST/threadx/ports/cortex_m7/gnu/src/tx_thread_interrupt_disable.s \
|
||||
Middlewares/ST/threadx/ports/cortex_m7/gnu/src/tx_thread_interrupt_restore.s \
|
||||
Middlewares/ST/threadx/ports/cortex_m7/gnu/src/tx_thread_schedule.s \
|
||||
Middlewares/ST/threadx/ports/cortex_m7/gnu/src/tx_thread_stack_build.s \
|
||||
Middlewares/ST/threadx/ports/cortex_m7/gnu/src/tx_thread_system_return.s \
|
||||
Middlewares/ST/threadx/ports/cortex_m7/gnu/src/tx_timer_interrupt.s
|
||||
|
||||
|
||||
#######################################
|
||||
|
|
Loading…
Reference in New Issue