mirror of
https://gitee.com/dlmu-cone/tronone-h7-scaffold
synced 2026-07-24 03:27:45 +08:00
ioc changed soft spi tft
This commit is contained in:
@@ -36,15 +36,12 @@ extern SPI_HandleTypeDef hspi1;
|
|||||||
|
|
||||||
extern SPI_HandleTypeDef hspi2;
|
extern SPI_HandleTypeDef hspi2;
|
||||||
|
|
||||||
extern SPI_HandleTypeDef hspi6;
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Private defines */
|
/* USER CODE BEGIN Private defines */
|
||||||
|
|
||||||
/* USER CODE END Private defines */
|
/* USER CODE END Private defines */
|
||||||
|
|
||||||
void MX_SPI1_Init(void);
|
void MX_SPI1_Init(void);
|
||||||
void MX_SPI2_Init(void);
|
void MX_SPI2_Init(void);
|
||||||
void MX_SPI6_Init(void);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN Prototypes */
|
/* USER CODE BEGIN Prototypes */
|
||||||
|
|
||||||
|
|||||||
@@ -171,10 +171,17 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
|
|||||||
/* ADC1 clock enable */
|
/* ADC1 clock enable */
|
||||||
__HAL_RCC_ADC12_CLK_ENABLE();
|
__HAL_RCC_ADC12_CLK_ENABLE();
|
||||||
|
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||||
/**ADC1 GPIO Configuration
|
/**ADC1 GPIO Configuration
|
||||||
|
PA5 ------> ADC1_INP19
|
||||||
PC4 ------> ADC1_INP4
|
PC4 ------> ADC1_INP4
|
||||||
*/
|
*/
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_5;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_4;
|
GPIO_InitStruct.Pin = GPIO_PIN_4;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
@@ -231,8 +238,11 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
|
|||||||
__HAL_RCC_ADC12_CLK_DISABLE();
|
__HAL_RCC_ADC12_CLK_DISABLE();
|
||||||
|
|
||||||
/**ADC1 GPIO Configuration
|
/**ADC1 GPIO Configuration
|
||||||
|
PA5 ------> ADC1_INP19
|
||||||
PC4 ------> ADC1_INP4
|
PC4 ------> ADC1_INP4
|
||||||
*/
|
*/
|
||||||
|
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5);
|
||||||
|
|
||||||
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_4);
|
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_4);
|
||||||
|
|
||||||
/* ADC1 DMA DeInit */
|
/* ADC1 DMA DeInit */
|
||||||
|
|||||||
@@ -62,7 +62,7 @@
|
|||||||
osThreadId_t BeginTaskHandle;
|
osThreadId_t BeginTaskHandle;
|
||||||
const osThreadAttr_t BeginTask_attributes = {
|
const osThreadAttr_t BeginTask_attributes = {
|
||||||
.name = "BeginTask",
|
.name = "BeginTask",
|
||||||
.stack_size = 256 * 4,
|
.stack_size = 512 * 4,
|
||||||
.priority = (osPriority_t) osPriorityNormal,
|
.priority = (osPriority_t) osPriorityNormal,
|
||||||
};
|
};
|
||||||
/* Definitions for shoot */
|
/* Definitions for shoot */
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
* Output
|
* Output
|
||||||
* EVENT_OUT
|
* EVENT_OUT
|
||||||
* EXTI
|
* EXTI
|
||||||
|
PA7 ------> SPI6_MOSI
|
||||||
PA8 ------> RCC_MCO_1
|
PA8 ------> RCC_MCO_1
|
||||||
PC10 ------> SPI3_SCK
|
PC10 ------> SPI3_SCK
|
||||||
PC11 ------> SPI3_MISO
|
PC11 ------> SPI3_MISO
|
||||||
@@ -56,10 +57,7 @@ void MX_GPIO_Init(void)
|
|||||||
__HAL_RCC_GPIOD_CLK_ENABLE();
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
/*Configure GPIO pin Output Level */
|
||||||
HAL_GPIO_WritePin(GPIOC, Power2_Pin|Power1_Pin|Power_5V_EN_Pin|GYRO_CS_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(GPIOC, Power2_Pin|Power1_Pin|Power_5V_EN_Pin|ACC_CS_Pin|GYRO_CS_Pin, GPIO_PIN_SET);
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
|
||||||
HAL_GPIO_WritePin(ACC_CS_GPIO_Port, ACC_CS_Pin, GPIO_PIN_RESET);
|
|
||||||
|
|
||||||
/*Configure GPIO pin Output Level */
|
/*Configure GPIO pin Output Level */
|
||||||
HAL_GPIO_WritePin(GPIOA, power2_Pin|power1_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(GPIOA, power2_Pin|power1_Pin, GPIO_PIN_SET);
|
||||||
@@ -97,6 +95,20 @@ void MX_GPIO_Init(void)
|
|||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PA6 */
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_6;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
/*Configure GPIO pin : PA7 */
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_7;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
GPIO_InitStruct.Alternate = GPIO_AF8_SPI6;
|
||||||
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
|
||||||
/*Configure GPIO pins : pump3_Pin pump4_Pin */
|
/*Configure GPIO pins : pump3_Pin pump4_Pin */
|
||||||
GPIO_InitStruct.Pin = pump3_Pin|pump4_Pin;
|
GPIO_InitStruct.Pin = pump3_Pin|pump4_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
#include "buzzer.h"
|
#include "buzzer.h"
|
||||||
#include "ws2812status.h"
|
#include "ws2812status.h"
|
||||||
#include "robot.h"
|
#include "robot.h"
|
||||||
|
#include "tft.h"
|
||||||
|
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
@@ -133,10 +134,10 @@ int main(void)
|
|||||||
MX_SPI1_Init();
|
MX_SPI1_Init();
|
||||||
MX_UART5_Init();
|
MX_UART5_Init();
|
||||||
MX_TIM3_Init();
|
MX_TIM3_Init();
|
||||||
MX_SPI6_Init();
|
|
||||||
MX_ADC1_Init();
|
MX_ADC1_Init();
|
||||||
/* USER CODE BEGIN 2 */
|
/* USER CODE BEGIN 2 */
|
||||||
|
|
||||||
|
TFT_ShowBootScreen();
|
||||||
robotSelfCheck(); //自检LED
|
robotSelfCheck(); //自检LED
|
||||||
RobotInit();
|
RobotInit();
|
||||||
systemstart_song(); //开机音乐
|
systemstart_song(); //开机音乐
|
||||||
|
|||||||
101
Core/Src/spi.c
101
Core/Src/spi.c
@@ -26,7 +26,6 @@
|
|||||||
|
|
||||||
SPI_HandleTypeDef hspi1;
|
SPI_HandleTypeDef hspi1;
|
||||||
SPI_HandleTypeDef hspi2;
|
SPI_HandleTypeDef hspi2;
|
||||||
SPI_HandleTypeDef hspi6;
|
|
||||||
DMA_HandleTypeDef hdma_spi1_rx;
|
DMA_HandleTypeDef hdma_spi1_rx;
|
||||||
DMA_HandleTypeDef hdma_spi1_tx;
|
DMA_HandleTypeDef hdma_spi1_tx;
|
||||||
DMA_HandleTypeDef hdma_spi2_rx;
|
DMA_HandleTypeDef hdma_spi2_rx;
|
||||||
@@ -45,9 +44,9 @@ void MX_SPI1_Init(void)
|
|||||||
/* USER CODE END SPI1_Init 1 */
|
/* USER CODE END SPI1_Init 1 */
|
||||||
hspi1.Instance = SPI1;
|
hspi1.Instance = SPI1;
|
||||||
hspi1.Init.Mode = SPI_MODE_MASTER;
|
hspi1.Init.Mode = SPI_MODE_MASTER;
|
||||||
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
|
hspi1.Init.Direction = SPI_DIRECTION_2LINES_TXONLY;
|
||||||
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
|
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||||
hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
|
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||||
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
|
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||||
hspi1.Init.NSS = SPI_NSS_SOFT;
|
hspi1.Init.NSS = SPI_NSS_SOFT;
|
||||||
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
|
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
|
||||||
@@ -115,48 +114,6 @@ void MX_SPI2_Init(void)
|
|||||||
|
|
||||||
/* USER CODE END SPI2_Init 2 */
|
/* USER CODE END SPI2_Init 2 */
|
||||||
|
|
||||||
}
|
|
||||||
/* SPI6 init function */
|
|
||||||
void MX_SPI6_Init(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI6_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI6_Init 0 */
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI6_Init 1 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI6_Init 1 */
|
|
||||||
hspi6.Instance = SPI6;
|
|
||||||
hspi6.Init.Mode = SPI_MODE_MASTER;
|
|
||||||
hspi6.Init.Direction = SPI_DIRECTION_2LINES_TXONLY;
|
|
||||||
hspi6.Init.DataSize = SPI_DATASIZE_8BIT;
|
|
||||||
hspi6.Init.CLKPolarity = SPI_POLARITY_LOW;
|
|
||||||
hspi6.Init.CLKPhase = SPI_PHASE_2EDGE;
|
|
||||||
hspi6.Init.NSS = SPI_NSS_SOFT;
|
|
||||||
hspi6.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
|
|
||||||
hspi6.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
|
||||||
hspi6.Init.TIMode = SPI_TIMODE_DISABLE;
|
|
||||||
hspi6.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
|
||||||
hspi6.Init.CRCPolynomial = 0x0;
|
|
||||||
hspi6.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
|
|
||||||
hspi6.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
|
|
||||||
hspi6.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
|
|
||||||
hspi6.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
|
|
||||||
hspi6.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
|
|
||||||
hspi6.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
|
|
||||||
hspi6.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
|
|
||||||
hspi6.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
|
|
||||||
hspi6.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
|
|
||||||
hspi6.Init.IOSwap = SPI_IO_SWAP_DISABLE;
|
|
||||||
if (HAL_SPI_Init(&hspi6) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
/* USER CODE BEGIN SPI6_Init 2 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI6_Init 2 */
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
|
void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
|
||||||
@@ -330,41 +287,6 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
|
|||||||
|
|
||||||
/* USER CODE END SPI2_MspInit 1 */
|
/* USER CODE END SPI2_MspInit 1 */
|
||||||
}
|
}
|
||||||
else if(spiHandle->Instance==SPI6)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN SPI6_MspInit 0 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI6_MspInit 0 */
|
|
||||||
|
|
||||||
/** Initializes the peripherals clock
|
|
||||||
*/
|
|
||||||
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SPI6;
|
|
||||||
PeriphClkInitStruct.Spi6ClockSelection = RCC_SPI6CLKSOURCE_HSE;
|
|
||||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
|
||||||
{
|
|
||||||
Error_Handler();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* SPI6 clock enable */
|
|
||||||
__HAL_RCC_SPI6_CLK_ENABLE();
|
|
||||||
|
|
||||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
||||||
/**SPI6 GPIO Configuration
|
|
||||||
PA7 ------> SPI6_MOSI
|
|
||||||
*/
|
|
||||||
GPIO_InitStruct.Pin = GPIO_PIN_7;
|
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
||||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
||||||
GPIO_InitStruct.Alternate = GPIO_AF8_SPI6;
|
|
||||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI6_MspInit 1 */
|
|
||||||
/* WS2812 uses only PA7 MOSI; PA5 is LCD KEY on DM-MC-Board02. */
|
|
||||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6);
|
|
||||||
|
|
||||||
/* USER CODE END SPI6_MspInit 1 */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle)
|
void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle)
|
||||||
@@ -424,25 +346,6 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle)
|
|||||||
|
|
||||||
/* USER CODE END SPI2_MspDeInit 1 */
|
/* USER CODE END SPI2_MspDeInit 1 */
|
||||||
}
|
}
|
||||||
else if(spiHandle->Instance==SPI6)
|
|
||||||
{
|
|
||||||
/* USER CODE BEGIN SPI6_MspDeInit 0 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI6_MspDeInit 0 */
|
|
||||||
/* Peripheral clock disable */
|
|
||||||
__HAL_RCC_SPI6_CLK_DISABLE();
|
|
||||||
|
|
||||||
/**SPI6 GPIO Configuration
|
|
||||||
PA5 ------> SPI6_SCK
|
|
||||||
PA6 ------> SPI6_MISO
|
|
||||||
PA7 ------> SPI6_MOSI
|
|
||||||
*/
|
|
||||||
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
|
|
||||||
|
|
||||||
/* USER CODE BEGIN SPI6_MspDeInit 1 */
|
|
||||||
|
|
||||||
/* USER CODE END SPI6_MspDeInit 1 */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* USER CODE BEGIN 1 */
|
/* USER CODE BEGIN 1 */
|
||||||
|
|||||||
@@ -461,20 +461,19 @@ Mcu.IP10=NVIC
|
|||||||
Mcu.IP11=RCC
|
Mcu.IP11=RCC
|
||||||
Mcu.IP12=SPI1
|
Mcu.IP12=SPI1
|
||||||
Mcu.IP13=SPI2
|
Mcu.IP13=SPI2
|
||||||
Mcu.IP14=SPI6
|
Mcu.IP14=SYS
|
||||||
Mcu.IP15=SYS
|
Mcu.IP15=TIM1
|
||||||
Mcu.IP16=TIM1
|
Mcu.IP16=TIM3
|
||||||
Mcu.IP17=TIM3
|
Mcu.IP17=TIM12
|
||||||
Mcu.IP18=TIM12
|
Mcu.IP18=UART5
|
||||||
Mcu.IP19=UART5
|
Mcu.IP19=UART7
|
||||||
Mcu.IP2=CORTEX_M7
|
Mcu.IP2=CORTEX_M7
|
||||||
Mcu.IP20=UART7
|
Mcu.IP20=USART1
|
||||||
Mcu.IP21=USART1
|
Mcu.IP21=USART2
|
||||||
Mcu.IP22=USART2
|
Mcu.IP22=USART3
|
||||||
Mcu.IP23=USART3
|
Mcu.IP23=USART10
|
||||||
Mcu.IP24=USART10
|
Mcu.IP24=USB_DEVICE
|
||||||
Mcu.IP25=USB_DEVICE
|
Mcu.IP25=USB_OTG_HS
|
||||||
Mcu.IP26=USB_OTG_HS
|
|
||||||
Mcu.IP3=CRC
|
Mcu.IP3=CRC
|
||||||
Mcu.IP4=DMA
|
Mcu.IP4=DMA
|
||||||
Mcu.IP5=FDCAN1
|
Mcu.IP5=FDCAN1
|
||||||
@@ -482,7 +481,7 @@ Mcu.IP6=FDCAN2
|
|||||||
Mcu.IP7=FDCAN3
|
Mcu.IP7=FDCAN3
|
||||||
Mcu.IP8=FREERTOS
|
Mcu.IP8=FREERTOS
|
||||||
Mcu.IP9=MEMORYMAP
|
Mcu.IP9=MEMORYMAP
|
||||||
Mcu.IPNb=27
|
Mcu.IPNb=26
|
||||||
Mcu.Name=STM32H723VGTx
|
Mcu.Name=STM32H723VGTx
|
||||||
Mcu.Package=LQFP100
|
Mcu.Package=LQFP100
|
||||||
Mcu.Pin0=PE2
|
Mcu.Pin0=PE2
|
||||||
@@ -666,10 +665,11 @@ PB5.Signal=FDCAN2_RX
|
|||||||
PB6.Locked=true
|
PB6.Locked=true
|
||||||
PB6.Mode=FDCAN_Activate
|
PB6.Mode=FDCAN_Activate
|
||||||
PB6.Signal=FDCAN2_TX
|
PB6.Signal=FDCAN2_TX
|
||||||
PC0.GPIOParameters=GPIO_Speed,GPIO_Label
|
PC0.GPIOParameters=GPIO_Speed,PinState,GPIO_Label
|
||||||
PC0.GPIO_Label=ACC_CS
|
PC0.GPIO_Label=ACC_CS
|
||||||
PC0.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH
|
PC0.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH
|
||||||
PC0.Locked=true
|
PC0.Locked=true
|
||||||
|
PC0.PinState=GPIO_PIN_SET
|
||||||
PC0.Signal=GPIO_Output
|
PC0.Signal=GPIO_Output
|
||||||
PC1.GPIOParameters=GPIO_Speed
|
PC1.GPIOParameters=GPIO_Speed
|
||||||
PC1.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH
|
PC1.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH
|
||||||
@@ -815,7 +815,7 @@ ProjectManager.ToolChainLocation=
|
|||||||
ProjectManager.UAScriptAfterPath=
|
ProjectManager.UAScriptAfterPath=
|
||||||
ProjectManager.UAScriptBeforePath=
|
ProjectManager.UAScriptBeforePath=
|
||||||
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_DMA_Init-DMA-false-HAL-true,4-MX_FDCAN2_Init-FDCAN2-false-HAL-true,5-MX_FDCAN3_Init-FDCAN3-false-HAL-true,6-MX_CRC_Init-CRC-false-HAL-true,7-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false,8-MX_FDCAN1_Init-FDCAN1-false-HAL-true,9-MX_USART10_UART_Init-USART10-false-HAL-true,10-MX_SPI2_Init-SPI2-false-HAL-true,11-MX_TIM12_Init-TIM12-false-HAL-true,12-MX_UART7_Init-UART7-false-HAL-true,13-MX_TIM1_Init-TIM1-false-HAL-true,14-MX_USART1_UART_Init-USART1-false-HAL-true,15-MX_ADC3_Init-ADC3-false-HAL-true,16-MX_USART2_UART_Init-USART2-false-HAL-true,17-MX_USART3_UART_Init-USART3-false-HAL-true,18-MX_SPI1_Init-SPI1-false-HAL-true,19-MX_UART5_Init-UART5-false-HAL-true,20-MX_TIM3_Init-TIM3-false-HAL-true,21-MX_SPI6_Init-SPI6-false-HAL-true,22-MX_ADC1_Init-ADC1-false-HAL-true,0-MX_CORTEX_M7_Init-CORTEX_M7-false-HAL-true
|
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_FDCAN2_Init-FDCAN2-false-HAL-true,5-MX_FDCAN3_Init-FDCAN3-false-HAL-true,6-MX_CRC_Init-CRC-false-HAL-true,7-MX_USB_DEVICE_Init-USB_DEVICE-false-HAL-false,8-MX_FDCAN1_Init-FDCAN1-false-HAL-true,9-MX_USART10_UART_Init-USART10-false-HAL-true,10-MX_SPI2_Init-SPI2-false-HAL-true,11-MX_TIM12_Init-TIM12-false-HAL-true,12-MX_UART7_Init-UART7-false-HAL-true,13-MX_TIM1_Init-TIM1-false-HAL-true,14-MX_USART1_UART_Init-USART1-false-HAL-true,15-MX_ADC3_Init-ADC3-false-HAL-true,16-MX_USART2_UART_Init-USART2-false-HAL-true,17-MX_USART3_UART_Init-USART3-false-HAL-true,18-MX_SPI1_Init-SPI1-false-HAL-true,19-MX_UART5_Init-UART5-false-HAL-true,20-MX_TIM3_Init-TIM3-false-HAL-true,21-MX_ADC1_Init-ADC1-false-HAL-true,0-MX_CORTEX_M7_Init-CORTEX_M7-false-HAL-true
|
||||||
RCC.ADCFreq_Value=96000000
|
RCC.ADCFreq_Value=96000000
|
||||||
RCC.AHB12Freq_Value=240000000
|
RCC.AHB12Freq_Value=240000000
|
||||||
RCC.AHB4Freq_Value=240000000
|
RCC.AHB4Freq_Value=240000000
|
||||||
@@ -899,10 +899,10 @@ RCC.VCO3OutputFreq_Value=96750000
|
|||||||
RCC.VCOInput1Freq_Value=12000000
|
RCC.VCOInput1Freq_Value=12000000
|
||||||
RCC.VCOInput2Freq_Value=12000000
|
RCC.VCOInput2Freq_Value=12000000
|
||||||
RCC.VCOInput3Freq_Value=750000
|
RCC.VCOInput3Freq_Value=750000
|
||||||
SH.ADCx_INP4.0=ADC1_INP4,IN4-Single-Ended
|
|
||||||
SH.ADCx_INP4.ConfNb=1
|
|
||||||
SH.ADCx_INP19.0=ADC1_INP19,IN19-Single-Ended
|
SH.ADCx_INP19.0=ADC1_INP19,IN19-Single-Ended
|
||||||
SH.ADCx_INP19.ConfNb=1
|
SH.ADCx_INP19.ConfNb=1
|
||||||
|
SH.ADCx_INP4.0=ADC1_INP4,IN4-Single-Ended
|
||||||
|
SH.ADCx_INP4.ConfNb=1
|
||||||
SH.GPXTI10.0=GPIO_EXTI10
|
SH.GPXTI10.0=GPIO_EXTI10
|
||||||
SH.GPXTI10.ConfNb=1
|
SH.GPXTI10.ConfNb=1
|
||||||
SH.GPXTI12.0=GPIO_EXTI12
|
SH.GPXTI12.0=GPIO_EXTI12
|
||||||
@@ -915,10 +915,10 @@ SH.SharedStack_PC12.0=SPI3_MOSI
|
|||||||
SH.SharedStack_PC12.1=UART5_TX,Asynchronous
|
SH.SharedStack_PC12.1=UART5_TX,Asynchronous
|
||||||
SH.SharedStack_PC12.ConfNb=2
|
SH.SharedStack_PC12.ConfNb=2
|
||||||
SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_8
|
SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_8
|
||||||
SPI1.CLKPolarity=SPI_POLARITY_HIGH
|
SPI1.CLKPolarity=SPI_POLARITY_LOW
|
||||||
SPI1.CalculateBaudRate=15.0 MBits/s
|
SPI1.CalculateBaudRate=15.0 MBits/s
|
||||||
SPI1.DataSize=SPI_DATASIZE_8BIT
|
SPI1.DataSize=SPI_DATASIZE_8BIT
|
||||||
SPI1.Direction=SPI_DIRECTION_2LINES
|
SPI1.Direction=SPI_DIRECTION_2LINES_TXONLY
|
||||||
SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize,BaudRatePrescaler,CLKPolarity
|
SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize,BaudRatePrescaler,CLKPolarity
|
||||||
SPI1.Mode=SPI_MODE_MASTER
|
SPI1.Mode=SPI_MODE_MASTER
|
||||||
SPI1.VirtualType=VM_MASTER
|
SPI1.VirtualType=VM_MASTER
|
||||||
@@ -932,14 +932,6 @@ SPI2.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize,BaudRate
|
|||||||
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
|
||||||
SPI6.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_4
|
|
||||||
SPI6.CLKPhase=SPI_PHASE_2EDGE
|
|
||||||
SPI6.CalculateBaudRate=6.0 MBits/s
|
|
||||||
SPI6.DataSize=SPI_DATASIZE_8BIT
|
|
||||||
SPI6.Direction=SPI_DIRECTION_2LINES_TXONLY
|
|
||||||
SPI6.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize,BaudRatePrescaler,CLKPhase
|
|
||||||
SPI6.Mode=SPI_MODE_MASTER
|
|
||||||
SPI6.VirtualType=VM_MASTER
|
|
||||||
STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0.DSPOoLibraryJjLibrary_Checked=true
|
STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0.DSPOoLibraryJjLibrary_Checked=true
|
||||||
STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0.IPParameters=LibraryCcDSPOoLibraryJjDSPOoLibrary
|
STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0.IPParameters=LibraryCcDSPOoLibraryJjDSPOoLibrary
|
||||||
STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0.LibraryCcDSPOoLibraryJjDSPOoLibrary=true
|
STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0.LibraryCcDSPOoLibraryJjDSPOoLibrary=true
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
#include "tft.h"
|
#include "tft.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#define TFT_SPI_TIMEOUT_MS 100U
|
#define TFT_SPI_TIMEOUT_MS 100U
|
||||||
@@ -28,6 +27,7 @@ typedef enum
|
|||||||
} TFT_GlyphIndex_e;
|
} TFT_GlyphIndex_e;
|
||||||
|
|
||||||
static bool tft_initialized = false;
|
static bool tft_initialized = false;
|
||||||
|
static bool tft_transfer_ok = true;
|
||||||
|
|
||||||
static const uint8_t tft_font5x7[][TFT_FONT_H] = {
|
static const uint8_t tft_font5x7[][TFT_FONT_H] = {
|
||||||
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* space */
|
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* space */
|
||||||
@@ -107,15 +107,72 @@ static void tft_backlight_on(void)
|
|||||||
HAL_GPIO_WritePin(TFT_BLK_GPIO_Port, TFT_BLK_Pin, GPIO_PIN_SET);
|
HAL_GPIO_WritePin(TFT_BLK_GPIO_Port, TFT_BLK_Pin, GPIO_PIN_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void tft_bus_init(void)
|
||||||
|
{
|
||||||
|
#if TFT_USE_SOFT_SPI
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
|
||||||
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||||
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
||||||
|
|
||||||
|
GPIO_InitStruct.Pin = TFT_SCK_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(TFT_SCK_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
GPIO_InitStruct.Pin = TFT_MOSI_Pin;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
HAL_GPIO_Init(TFT_MOSI_GPIO_Port, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
HAL_GPIO_WritePin(TFT_SCK_GPIO_Port, TFT_SCK_Pin, GPIO_PIN_SET);
|
||||||
|
HAL_GPIO_WritePin(TFT_MOSI_GPIO_Port, TFT_MOSI_Pin, GPIO_PIN_RESET);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#if TFT_USE_SOFT_SPI
|
||||||
|
static void tft_write_byte(uint8_t data)
|
||||||
|
{
|
||||||
|
for (uint8_t i = 0U; i < 8U; i++)
|
||||||
|
{
|
||||||
|
HAL_GPIO_WritePin(TFT_SCK_GPIO_Port, TFT_SCK_Pin, GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(TFT_MOSI_GPIO_Port, TFT_MOSI_Pin,
|
||||||
|
(data & 0x80U) != 0U ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
||||||
|
HAL_GPIO_WritePin(TFT_SCK_GPIO_Port, TFT_SCK_Pin, GPIO_PIN_SET);
|
||||||
|
data <<= 1U;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void tft_write_bytes(const uint8_t *data, uint32_t len)
|
static void tft_write_bytes(const uint8_t *data, uint32_t len)
|
||||||
{
|
{
|
||||||
|
#if TFT_USE_SOFT_SPI
|
||||||
while (len > 0U)
|
while (len > 0U)
|
||||||
{
|
{
|
||||||
|
tft_write_byte(*data);
|
||||||
|
data++;
|
||||||
|
len--;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
while (len > 0U)
|
||||||
|
{
|
||||||
|
#if TFT_HW_SPI_BYTE_MODE
|
||||||
|
uint16_t chunk = 1U;
|
||||||
|
#else
|
||||||
uint16_t chunk = len > UINT16_MAX ? UINT16_MAX : (uint16_t) len;
|
uint16_t chunk = len > UINT16_MAX ? UINT16_MAX : (uint16_t) len;
|
||||||
(void) HAL_SPI_Transmit(&TFT_SPI_UNIT, (uint8_t *) data, chunk, TFT_SPI_TIMEOUT_MS);
|
#endif
|
||||||
|
if (HAL_SPI_Transmit(&TFT_SPI_UNIT, (uint8_t *) data, chunk, TFT_SPI_TIMEOUT_MS) != HAL_OK)
|
||||||
|
{
|
||||||
|
tft_transfer_ok = false;
|
||||||
|
tft_cs_high();
|
||||||
|
return;
|
||||||
|
}
|
||||||
data += chunk;
|
data += chunk;
|
||||||
len -= chunk;
|
len -= chunk;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lcd_write_reg(uint8_t reg)
|
static void lcd_write_reg(uint8_t reg)
|
||||||
@@ -124,6 +181,7 @@ static void lcd_write_reg(uint8_t reg)
|
|||||||
tft_dc_command();
|
tft_dc_command();
|
||||||
tft_write_bytes(®, 1U);
|
tft_write_bytes(®, 1U);
|
||||||
tft_cs_high();
|
tft_cs_high();
|
||||||
|
tft_dc_data();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lcd_write_data8(uint8_t data)
|
static void lcd_write_data8(uint8_t data)
|
||||||
@@ -157,7 +215,7 @@ static void tft_write_color_block(uint16_t color, uint32_t count)
|
|||||||
|
|
||||||
tft_cs_low();
|
tft_cs_low();
|
||||||
tft_dc_data();
|
tft_dc_data();
|
||||||
while (count > 0U)
|
while (count > 0U && tft_transfer_ok)
|
||||||
{
|
{
|
||||||
uint32_t pixels = count > (sizeof(buf) / 2U) ? (sizeof(buf) / 2U) : count;
|
uint32_t pixels = count > (sizeof(buf) / 2U) ? (sizeof(buf) / 2U) : count;
|
||||||
tft_write_bytes(buf, pixels * 2U);
|
tft_write_bytes(buf, pixels * 2U);
|
||||||
@@ -281,7 +339,7 @@ static void tft_draw_char(uint16_t x, uint16_t y, char ch, uint16_t fc, uint16_t
|
|||||||
uint32_t idx = 0U;
|
uint32_t idx = 0U;
|
||||||
for (uint8_t col = 0U; col < TFT_FONT_W; col++)
|
for (uint8_t col = 0U; col < TFT_FONT_W; col++)
|
||||||
{
|
{
|
||||||
uint16_t color = (glyph[row] & (1U << (TFT_FONT_W - 1U - col))) ? fc : bc;
|
uint16_t color = (glyph[row] & (1U << col)) ? fc : bc;
|
||||||
for (uint8_t repeat_x = 0U; repeat_x < scale; repeat_x++)
|
for (uint8_t repeat_x = 0U; repeat_x < scale; repeat_x++)
|
||||||
{
|
{
|
||||||
line[idx++] = (uint8_t) (color >> 8);
|
line[idx++] = (uint8_t) (color >> 8);
|
||||||
@@ -339,6 +397,8 @@ void LCD_Init(void)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tft_transfer_ok = true;
|
||||||
|
tft_bus_init();
|
||||||
tft_cs_high();
|
tft_cs_high();
|
||||||
tft_reset_low();
|
tft_reset_low();
|
||||||
HAL_Delay(100);
|
HAL_Delay(100);
|
||||||
@@ -429,8 +489,11 @@ void LCD_Init(void)
|
|||||||
lcd_write_reg(0x21);
|
lcd_write_reg(0x21);
|
||||||
lcd_write_reg(0x29);
|
lcd_write_reg(0x29);
|
||||||
|
|
||||||
tft_initialized = true;
|
|
||||||
TFT_Clear(TFT_COLOR_BLACK);
|
TFT_Clear(TFT_COLOR_BLACK);
|
||||||
|
if (tft_transfer_ok)
|
||||||
|
{
|
||||||
|
tft_initialized = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TFT_Init(void)
|
void TFT_Init(void)
|
||||||
@@ -438,6 +501,27 @@ void TFT_Init(void)
|
|||||||
LCD_Init();
|
LCD_Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TFT_ShowBootScreen(void)
|
||||||
|
{
|
||||||
|
if (!tft_initialized)
|
||||||
|
{
|
||||||
|
TFT_Init();
|
||||||
|
if (!tft_initialized)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tft_transfer_ok = true;
|
||||||
|
uint16_t band_h = TFT_LCD_H / 3U;
|
||||||
|
TFT_FillRect(0U, 0U, TFT_LCD_W, band_h, TFT_COLOR_BLUE);
|
||||||
|
TFT_FillRect(0U, band_h, TFT_LCD_W, band_h, TFT_COLOR_GREEN);
|
||||||
|
TFT_FillRect(0U, (uint16_t) (band_h * 2U), TFT_LCD_W, (uint16_t) (TFT_LCD_H - band_h * 2U), TFT_COLOR_RED);
|
||||||
|
TFT_DrawString(16U, 22U, "DM LCD", TFT_COLOR_WHITE, TFT_COLOR_BLUE, 3U);
|
||||||
|
TFT_DrawString(16U, (uint16_t) (band_h + 24U), "BOOT", TFT_COLOR_BLACK, TFT_COLOR_GREEN, 3U);
|
||||||
|
TFT_DrawString(16U, (uint16_t) (band_h * 2U + 24U), "WAIT IMU", TFT_COLOR_WHITE, TFT_COLOR_RED, 2U);
|
||||||
|
}
|
||||||
|
|
||||||
const char *TFT_RobotModeText(RobotMode_t mode)
|
const char *TFT_RobotModeText(RobotMode_t mode)
|
||||||
{
|
{
|
||||||
switch (mode)
|
switch (mode)
|
||||||
@@ -487,8 +571,13 @@ static int16_t tft_temperature_to_tenths(float temperature_c)
|
|||||||
static void tft_format_temperature(char *buf, size_t len, int16_t temperature_tenths)
|
static void tft_format_temperature(char *buf, size_t len, int16_t temperature_tenths)
|
||||||
{
|
{
|
||||||
uint16_t abs_temp;
|
uint16_t abs_temp;
|
||||||
|
uint16_t integer;
|
||||||
|
uint8_t decimal;
|
||||||
|
size_t idx = 0U;
|
||||||
|
char digits[5];
|
||||||
|
uint8_t digits_len = 0U;
|
||||||
|
|
||||||
if (buf == NULL || len == 0U)
|
if (buf == NULL || len < 6U)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -496,13 +585,33 @@ static void tft_format_temperature(char *buf, size_t len, int16_t temperature_te
|
|||||||
if (temperature_tenths < 0)
|
if (temperature_tenths < 0)
|
||||||
{
|
{
|
||||||
abs_temp = (uint16_t) (-temperature_tenths);
|
abs_temp = (uint16_t) (-temperature_tenths);
|
||||||
(void) snprintf(buf, len, "-%u.%u C", abs_temp / 10U, abs_temp % 10U);
|
buf[idx++] = '-';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
abs_temp = (uint16_t) temperature_tenths;
|
abs_temp = (uint16_t) temperature_tenths;
|
||||||
(void) snprintf(buf, len, "%u.%u C", abs_temp / 10U, abs_temp % 10U);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
integer = abs_temp / 10U;
|
||||||
|
decimal = (uint8_t) (abs_temp % 10U);
|
||||||
|
do
|
||||||
|
{
|
||||||
|
digits[digits_len++] = (char) ('0' + (integer % 10U));
|
||||||
|
integer /= 10U;
|
||||||
|
} while (integer > 0U && digits_len < sizeof(digits));
|
||||||
|
|
||||||
|
while (digits_len > 0U && idx + 1U < len)
|
||||||
|
{
|
||||||
|
buf[idx++] = digits[--digits_len];
|
||||||
|
}
|
||||||
|
if (idx + 4U < len)
|
||||||
|
{
|
||||||
|
buf[idx++] = '.';
|
||||||
|
buf[idx++] = (char) ('0' + decimal);
|
||||||
|
buf[idx++] = ' ';
|
||||||
|
buf[idx++] = 'C';
|
||||||
|
}
|
||||||
|
buf[idx] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tft_draw_status_layout(void)
|
static void tft_draw_status_layout(void)
|
||||||
@@ -526,27 +635,44 @@ void TFT_ShowStatus(float temperature_c, RobotMode_t mode)
|
|||||||
if (!tft_initialized)
|
if (!tft_initialized)
|
||||||
{
|
{
|
||||||
TFT_Init();
|
TFT_Init();
|
||||||
|
if (!tft_initialized)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!layout_ready)
|
if (!layout_ready)
|
||||||
{
|
{
|
||||||
|
tft_transfer_ok = true;
|
||||||
tft_draw_status_layout();
|
tft_draw_status_layout();
|
||||||
|
if (!tft_transfer_ok)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
layout_ready = true;
|
layout_ready = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (temperature_tenths != last_temperature_tenths)
|
if (temperature_tenths != last_temperature_tenths)
|
||||||
{
|
{
|
||||||
|
tft_transfer_ok = true;
|
||||||
uint16_t temperature_color = temperature_tenths >= 550 ? TFT_COLOR_RED : TFT_COLOR_WHITE;
|
uint16_t temperature_color = temperature_tenths >= 550 ? TFT_COLOR_RED : TFT_COLOR_WHITE;
|
||||||
tft_format_temperature(temperature_text, sizeof(temperature_text), temperature_tenths);
|
tft_format_temperature(temperature_text, sizeof(temperature_text), temperature_tenths);
|
||||||
TFT_FillRect(96U, 68U, 168U, 32U, TFT_COLOR_BLACK);
|
TFT_FillRect(96U, 68U, 168U, 32U, TFT_COLOR_BLACK);
|
||||||
TFT_DrawString(100U, 70U, temperature_text, temperature_color, TFT_COLOR_BLACK, 3U);
|
TFT_DrawString(100U, 70U, temperature_text, temperature_color, TFT_COLOR_BLACK, 3U);
|
||||||
last_temperature_tenths = temperature_tenths;
|
if (tft_transfer_ok)
|
||||||
|
{
|
||||||
|
last_temperature_tenths = temperature_tenths;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode != last_mode)
|
if (mode != last_mode)
|
||||||
{
|
{
|
||||||
|
tft_transfer_ok = true;
|
||||||
TFT_FillRect(96U, 124U, 184U, 32U, TFT_COLOR_BLACK);
|
TFT_FillRect(96U, 124U, 184U, 32U, TFT_COLOR_BLACK);
|
||||||
TFT_DrawString(100U, 126U, mode_text, tft_mode_color(mode), TFT_COLOR_BLACK, 3U);
|
TFT_DrawString(100U, 126U, mode_text, tft_mode_color(mode), TFT_COLOR_BLACK, 3U);
|
||||||
last_mode = mode;
|
if (tft_transfer_ok)
|
||||||
|
{
|
||||||
|
last_mode = mode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,9 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TFT_USE_HORIZONTAL 2U
|
#define TFT_USE_HORIZONTAL 2U
|
||||||
|
#define TFT_USE_SOFT_SPI 1U
|
||||||
|
#define TFT_HW_SPI_BYTE_MODE 1U
|
||||||
|
|
||||||
#if (TFT_USE_HORIZONTAL == 0U) || (TFT_USE_HORIZONTAL == 1U)
|
#if (TFT_USE_HORIZONTAL == 0U) || (TFT_USE_HORIZONTAL == 1U)
|
||||||
#define TFT_LCD_W 240U
|
#define TFT_LCD_W 240U
|
||||||
@@ -24,6 +26,16 @@ extern "C" {
|
|||||||
#define TFT_SPI_UNIT hspi1
|
#define TFT_SPI_UNIT hspi1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef TFT_SCK_GPIO_Port
|
||||||
|
#define TFT_SCK_GPIO_Port GPIOB
|
||||||
|
#define TFT_SCK_Pin GPIO_PIN_3
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef TFT_MOSI_GPIO_Port
|
||||||
|
#define TFT_MOSI_GPIO_Port GPIOD
|
||||||
|
#define TFT_MOSI_Pin GPIO_PIN_7
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(LCD_CS_GPIO_Port) && defined(LCD_CS_Pin)
|
#if defined(LCD_CS_GPIO_Port) && defined(LCD_CS_Pin)
|
||||||
#define TFT_CS_GPIO_Port LCD_CS_GPIO_Port
|
#define TFT_CS_GPIO_Port LCD_CS_GPIO_Port
|
||||||
#define TFT_CS_Pin LCD_CS_Pin
|
#define TFT_CS_Pin LCD_CS_Pin
|
||||||
@@ -68,6 +80,7 @@ extern "C" {
|
|||||||
#define TFT_COLOR_LIGHT_GRAY 0xC618U
|
#define TFT_COLOR_LIGHT_GRAY 0xC618U
|
||||||
|
|
||||||
void TFT_Init(void);
|
void TFT_Init(void);
|
||||||
|
void TFT_ShowBootScreen(void);
|
||||||
void TFT_Clear(uint16_t color);
|
void TFT_Clear(uint16_t color);
|
||||||
void TFT_FillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color);
|
void TFT_FillRect(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t color);
|
||||||
void TFT_DrawPoint(uint16_t x, uint16_t y, uint16_t color);
|
void TFT_DrawPoint(uint16_t x, uint16_t y, uint16_t color);
|
||||||
|
|||||||
@@ -22,6 +22,68 @@
|
|||||||
#define WS2812_LowLevel 0xC0 // 0码
|
#define WS2812_LowLevel 0xC0 // 0码
|
||||||
#define WS2812_HighLevel 0xF0 // 1码
|
#define WS2812_HighLevel 0xF0 // 1码
|
||||||
|
|
||||||
|
static SPI_HandleTypeDef ws2812_spi;
|
||||||
|
static uint8_t ws2812_spi_initialized = 0U;
|
||||||
|
|
||||||
|
static uint8_t WS2812_SPI_Init(void)
|
||||||
|
{
|
||||||
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||||
|
RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
|
||||||
|
|
||||||
|
if (ws2812_spi_initialized != 0U)
|
||||||
|
{
|
||||||
|
return 1U;
|
||||||
|
}
|
||||||
|
|
||||||
|
PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_SPI6;
|
||||||
|
PeriphClkInitStruct.Spi6ClockSelection = RCC_SPI6CLKSOURCE_HSE;
|
||||||
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
|
||||||
|
{
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
|
||||||
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||||
|
__HAL_RCC_SPI6_CLK_ENABLE();
|
||||||
|
|
||||||
|
GPIO_InitStruct.Pin = GPIO_PIN_7;
|
||||||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||||
|
GPIO_InitStruct.Alternate = GPIO_AF8_SPI6;
|
||||||
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||||
|
|
||||||
|
ws2812_spi.Instance = SPI6;
|
||||||
|
ws2812_spi.Init.Mode = SPI_MODE_MASTER;
|
||||||
|
ws2812_spi.Init.Direction = SPI_DIRECTION_2LINES_TXONLY;
|
||||||
|
ws2812_spi.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||||
|
ws2812_spi.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||||
|
ws2812_spi.Init.CLKPhase = SPI_PHASE_2EDGE;
|
||||||
|
ws2812_spi.Init.NSS = SPI_NSS_SOFT;
|
||||||
|
ws2812_spi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
|
||||||
|
ws2812_spi.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||||
|
ws2812_spi.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||||
|
ws2812_spi.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||||
|
ws2812_spi.Init.CRCPolynomial = 0x0;
|
||||||
|
ws2812_spi.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
|
||||||
|
ws2812_spi.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
|
||||||
|
ws2812_spi.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
|
||||||
|
ws2812_spi.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
|
||||||
|
ws2812_spi.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
|
||||||
|
ws2812_spi.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
|
||||||
|
ws2812_spi.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
|
||||||
|
ws2812_spi.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
|
||||||
|
ws2812_spi.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
|
||||||
|
ws2812_spi.Init.IOSwap = SPI_IO_SWAP_DISABLE;
|
||||||
|
|
||||||
|
if (HAL_SPI_Init(&ws2812_spi) != HAL_OK)
|
||||||
|
{
|
||||||
|
return 0U;
|
||||||
|
}
|
||||||
|
|
||||||
|
ws2812_spi_initialized = 1U;
|
||||||
|
return 1U;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief
|
* @brief
|
||||||
* @param [in] r My Param doc
|
* @param [in] r My Param doc
|
||||||
@@ -32,20 +94,26 @@ void WS2812_Ctrl(uint8_t r, uint8_t g, uint8_t b)
|
|||||||
{
|
{
|
||||||
uint8_t txbuf[24];
|
uint8_t txbuf[24];
|
||||||
uint8_t res = 0;
|
uint8_t res = 0;
|
||||||
|
|
||||||
|
if (WS2812_SPI_Init() == 0U)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 8U; i++)
|
for (uint8_t i = 0; i < 8U; i++)
|
||||||
{
|
{
|
||||||
txbuf[7 - i] = (((g >> i) & 0x01) ? WS2812_HighLevel : WS2812_LowLevel) >> 1;
|
txbuf[7 - i] = (((g >> i) & 0x01) ? WS2812_HighLevel : WS2812_LowLevel) >> 1;
|
||||||
txbuf[15 - i] = (((r >> i) & 0x01) ? WS2812_HighLevel : WS2812_LowLevel) >> 1;
|
txbuf[15 - i] = (((r >> i) & 0x01) ? WS2812_HighLevel : WS2812_LowLevel) >> 1;
|
||||||
txbuf[23 - i] = (((b >> i) & 0x01) ? WS2812_HighLevel : WS2812_LowLevel) >> 1;
|
txbuf[23 - i] = (((b >> i) & 0x01) ? WS2812_HighLevel : WS2812_LowLevel) >> 1;
|
||||||
}
|
}
|
||||||
if (HAL_SPI_Transmit(&WS2812_SPI_UNIT, txbuf, sizeof(txbuf), WS2812_SPI_TIMEOUT) != HAL_OK)
|
if (HAL_SPI_Transmit(&ws2812_spi, txbuf, sizeof(txbuf), WS2812_SPI_TIMEOUT) != HAL_OK)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t i = 0; i < WS2812_RESET_BYTES; i++)
|
for (uint8_t i = 0; i < WS2812_RESET_BYTES; i++)
|
||||||
{
|
{
|
||||||
if (HAL_SPI_Transmit(&WS2812_SPI_UNIT, &res, 1U, WS2812_SPI_TIMEOUT) != HAL_OK)
|
if (HAL_SPI_Transmit(&ws2812_spi, &res, 1U, WS2812_SPI_TIMEOUT) != HAL_OK)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,5 @@
|
|||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
#define WS2812_SPI_UNIT hspi6
|
|
||||||
extern SPI_HandleTypeDef WS2812_SPI_UNIT;
|
|
||||||
|
|
||||||
void WS2812_Ctrl(uint8_t r, uint8_t g, uint8_t b);
|
void WS2812_Ctrl(uint8_t r, uint8_t g, uint8_t b);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user