diff --git a/FlashDebug.jscript b/FlashDebug.jscript
new file mode 100644
index 0000000..dea9eb1
--- /dev/null
+++ b/FlashDebug.jscript
@@ -0,0 +1,4 @@
+h
+loadbin bin\Debug\MKS-TFT32.hex, 0
+r
+q
diff --git a/Inc/ui.h b/Inc/ui.h
index 6a9c93a..10e1970 100644
--- a/Inc/ui.h
+++ b/Inc/ui.h
@@ -66,16 +66,20 @@ typedef struct
SDCARD_INSERT,
SDCARD_REMOVE,
USBDRIVE_INSERT,
- USBDRIVE_REMOVE
+ USBDRIVE_REMOVE,
+ SHOW_STATUS
} ucEventID;
union {
unsigned int touchXY;
} ucData;
-} xEvent_t;
+} xUIEvent_t;
extern QueueHandle_t xUIEventQueue;
-typedef void (*volatile eventProcessor_t) (xEvent_t *);
+#define MAXSTATSIZE 320/8
+extern uint8_t statString[MAXSTATSIZE+1];
+
+typedef void (*volatile eventProcessor_t) (xUIEvent_t *);
extern eventProcessor_t processEvent;
typedef enum {
diff --git a/MKS-TFT32.ebp b/MKS-TFT32.ebp
index d7dc001..8a37257 100644
--- a/MKS-TFT32.ebp
+++ b/MKS-TFT32.ebp
@@ -36,6 +36,11 @@
+
+
+
+
+
@@ -197,6 +202,9 @@
+
+
+
@@ -304,6 +312,9 @@
+
+
+
@@ -325,6 +336,9 @@
+
+
+
@@ -356,7 +370,15 @@
-
+
+
+
+
+
+
+
+
+
@@ -373,7 +395,7 @@
-
+
diff --git a/MKS_TFT.jflash b/MKS_TFT.jflash
new file mode 100644
index 0000000..b5cde0b
--- /dev/null
+++ b/MKS_TFT.jflash
@@ -0,0 +1,73 @@
+ AppVersion = 61206
+ FileVersion = 2
+[GENERAL]
+ ConnectMode = 0
+ CurrentFile = ""
+ DataFileSAddr = 0x00000000
+ GUIMode = 0
+ HostName = ""
+ TargetIF = 1
+ USBPort = 0
+ USBSerialNo = 0x00000000
+[JTAG]
+ IRLen = 0
+ MultipleTargets = 0
+ NumDevices = 0
+ Speed0 = 4000
+ Speed1 = 4000
+ TAP_Number = 0
+ UseAdaptive0 = 0
+ UseAdaptive1 = 0
+ UseMaxSpeed0 = 0
+ UseMaxSpeed1 = 0
+[CPU]
+ NumInitSteps = 1
+ InitStep0_Action = "Reset"
+ InitStep0_Value0 = 0x00000000
+ InitStep0_Value1 = 0x00000000
+ InitStep0_Comment = "Reset and halt target"
+ NumExitSteps = 0
+ UseScriptFile = 0
+ ScriptFile = ""
+ UseRAM = 1
+ RAMAddr = 0x20000000
+ RAMSize = 0x00010000
+ CheckCoreID = 1
+ CoreID = 0x3BA00477
+ CoreIDMask = 0x0F000FFF
+ UseAutoSpeed = 0x00000001
+ ClockSpeed = 0x00000000
+ EndianMode = 0
+ ChipName = "ST STM32F107VC"
+[FLASH]
+ aRangeSel[1] = 0-127
+ BankName = "Internal flash"
+ BankSelMode = 1
+ BaseAddr = 0x08000000
+ NumBanks = 1
+[PRODUCTION]
+ AutoPerformsErase = 1
+ AutoPerformsProgram = 1
+ AutoPerformsSecure = 0
+ AutoPerformsStartApp = 0
+ AutoPerformsUnsecure = 0
+ AutoPerformsVerify = 1
+ EnableTargetPower = 0
+ EraseType = 2
+ MonitorVTref = 0
+ MonitorVTrefMax = 0x0000157C
+ MonitorVTrefMin = 0x000003E8
+ OverrideTimeouts = 0
+ ProgramSN = 0
+ SerialFile = ""
+ SNAddr = 0x00000000
+ SNInc = 0x00000001
+ SNLen = 0x00000004
+ SNListFile = ""
+ SNValue = 0x00000001
+ StartAppType = 0
+ TargetPowerDelay = 0x00000014
+ TimeoutErase = 0x00003A98
+ TimeoutProgram = 0x00002710
+ TimeoutVerify = 0x00002710
+ VerifyType = 1
diff --git a/Src/main.c b/Src/main.c
index 61663d9..da12bbb 100644
--- a/Src/main.c
+++ b/Src/main.c
@@ -50,6 +50,7 @@ SPI_HandleTypeDef hspi3;
UART_HandleTypeDef huart2;
UART_HandleTypeDef huart3;
+DMA_HandleTypeDef hdma_usart2_rx;
TIM_HandleTypeDef htim2;
@@ -65,12 +66,19 @@ static osThreadId sdcardHandlerHandle; // sd card insert/remove
QueueHandle_t xUIEventQueue;
QueueHandle_t xPCommEventQueue;
+#define MAXCOMM1SIZE 0xff // Biggest string the user will type
+static uint8_t comm1RxBuffer = '\000'; // where we store that one character that just came in
+static uint8_t comm1RxString[MAXCOMM1SIZE]; // where we build our string from characters coming in
+static int comm1RxIndex = 0; // index for going though comm1RxString
+
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
void Error_Handler(void);
+
static void MX_GPIO_Init(void);
+static void MX_DMA_Init(void);
static void MX_TIM2_Init(void);
static void MX_I2C1_Init(void);
static void MX_SPI1_Init(void);
@@ -92,6 +100,8 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
/* USER CODE BEGIN 0 */
static SemaphoreHandle_t xTouchSemaphore;
static SemaphoreHandle_t xSDSemaphore;
+static SemaphoreHandle_t xComm1Semaphore;
+static SemaphoreHandle_t xComm2Semaphore;
/* USER CODE END 0 */
int main(void)
@@ -110,6 +120,7 @@ int main(void)
/* Initialize all configured peripherals */
MX_GPIO_Init();
+ MX_DMA_Init();
MX_TIM2_Init();
MX_I2C1_Init();
MX_SPI1_Init();
@@ -128,7 +139,9 @@ int main(void)
/* USER CODE BEGIN RTOS_SEMAPHORES */
/* add semaphores, ... */
xTouchSemaphore = xSemaphoreCreateBinary();
- xSDSemaphore = xSemaphoreCreateBinary();
+ xSDSemaphore = xSemaphoreCreateBinary();
+ xComm1Semaphore = xSemaphoreCreateBinary();
+ xComm2Semaphore = xSemaphoreCreateBinary();
/* USER CODE END RTOS_SEMAPHORES */
/* USER CODE BEGIN RTOS_TIMERS */
@@ -158,12 +171,12 @@ int main(void)
/* USER CODE BEGIN RTOS_QUEUES */
/* add queues, ... */
- xUIEventQueue = xQueueCreate(1, sizeof(xEvent_t));
+ xUIEventQueue = xQueueCreate(1, sizeof(xUIEvent_t));
if (xUIEventQueue == NULL) {
/* Queue was not created and must not be used. */
}
- xPCommEventQueue = xQueueCreate(10, sizeof(xEvent_t));
+ xPCommEventQueue = xQueueCreate(10, sizeof(xUIEvent_t));
if (xPCommEventQueue == NULL) {
/* Queue was not created and must not be used. */
}
@@ -341,6 +354,20 @@ static void MX_USART3_UART_Init(void)
}
+/**
+ * Enable DMA controller clock
+ */
+static void MX_DMA_Init(void)
+{
+ /* DMA controller clock enable */
+ __HAL_RCC_DMA1_CLK_ENABLE();
+
+ /* DMA interrupt init */
+ /* DMA1_Channel6_IRQn interrupt configuration */
+ HAL_NVIC_SetPriority(DMA1_Channel6_IRQn, 5, 0);
+ HAL_NVIC_EnableIRQ(DMA1_Channel6_IRQn);
+}
+
/** Configure pins as
* Analog
* Input
@@ -576,7 +603,7 @@ void StartTouchHandlerTask(void const * argument) {
HAL_GPIO_WritePin(TOUCH_nCS_GPIO_Port, TOUCH_nCS_Pin, GPIO_PIN_SET);
- xEvent_t event;
+ xUIEvent_t event;
event.ucEventID = TOUCH_DOWN_EVENT;
xTouchX = Lcd_Touch_Get_Closest_Average(x);
@@ -590,7 +617,7 @@ void StartTouchHandlerTask(void const * argument) {
} else {
if (xTouchX && xTouchY) {
- xEvent_t event;
+ xUIEvent_t event;
event.ucEventID = TOUCH_UP_EVENT;
event.ucData.touchXY = ((unsigned int) xTouchX << 16) + xTouchY;
xQueueSendToBack(xUIEventQueue, &event, 1000);
@@ -614,7 +641,7 @@ void StartSDHandlerTask(void const * argument) {
osDelay(100);
- xEvent_t event;
+ xUIEvent_t event;
event.ucEventID =
(HAL_GPIO_ReadPin(SDCARD_DETECT_GPIO_Port, SDCARD_DETECT_Pin)
== GPIO_PIN_RESET) ? SDCARD_INSERT : SDCARD_REMOVE;
@@ -625,8 +652,24 @@ void StartSDHandlerTask(void const * argument) {
void StartComm1Task(void const * argument) {
+ __HAL_UART_FLUSH_DRREGISTER(&huart2);
+ HAL_UART_Receive_DMA(&huart2, &comm1RxBuffer, 1);
+
while (1) {
- osDelay(1);
+ if(xSemaphoreTake(xComm1Semaphore, 5000 /* FIXME */ ) == pdTRUE ) {
+
+ xUIEvent_t event;
+ event.ucEventID = SHOW_STATUS;
+ xQueueSendToBack(xUIEventQueue, &event, 1000);
+ }
+ else
+ {
+ // osDelay(1);
+ static const char m115[] = "M115";
+
+ HAL_UART_Transmit(&huart2, m115, /* sizeof(m115)*/ 4, 1000);
+ osDelay(20);
+ }
}
}
@@ -637,6 +680,39 @@ void StartComm2Task(void const * argument) {
}
}
+void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
+{
+ if (huart->Instance == USART2)
+ {
+ __HAL_UART_FLUSH_DRREGISTER(&huart2); // Clear the buffer to prevent overrun
+
+ int i = 0;
+
+ if (comm1RxBuffer == '\n' || comm1RxBuffer == '\r') // If Enter
+ {
+ snprintf(statString, MAXSTATSIZE, "%s", comm1RxString);
+
+
+ comm1RxString[comm1RxIndex] = 0;
+ comm1RxIndex = 0;
+ for (i = 0; i < MAXSTATSIZE; i++) comm1RxString[i] = 0; // Clear the string buffer
+
+ BaseType_t xHigherPriorityTaskWoken = pdFALSE;
+ xSemaphoreGiveFromISR(xComm1Semaphore, &xHigherPriorityTaskWoken);
+ }
+ else
+ {
+ comm1RxString[comm1RxIndex] = comm1RxBuffer; // Add that character to the string
+ comm1RxIndex++;
+ if (comm1RxIndex > MAXSTATSIZE) // User typing too much, we can't have commands that big
+ {
+ comm1RxIndex = 0;
+ for (i = 0; i < MAXSTATSIZE; i++) comm1RxString[i] = 0; // Clear the string buffer
+ }
+ }
+ //
+ }
+}
/* USER CODE END 4 */
/* StartUITask function */
@@ -653,7 +729,7 @@ void StartUITask(void const * argument) {
osDelay(50);
HAL_TIM_OC_Stop_IT(&htim2, TIM_CHANNEL_3);
- xEvent_t event;
+ xUIEvent_t event;
event.ucEventID = INIT_EVENT;
(*processEvent) (&event);
@@ -662,7 +738,7 @@ void StartUITask(void const * argument) {
for (;;) {
if (xUIEventQueue != 0) {
- xEvent_t event;
+ xUIEvent_t event;
if (xQueueReceive(xUIEventQueue, &event, (TickType_t ) 500)) {
diff --git a/Src/serial_io.c b/Src/serial_io.c
new file mode 100644
index 0000000..3e9e6f6
--- /dev/null
+++ b/Src/serial_io.c
@@ -0,0 +1,76 @@
+
+#include
+#include "stm32f1xx_hal.h"
+
+static uint16_t numChars = 0;
+static uint8_t checksum = 0;
+static unsigned int lineNumber = 0;
+
+static void rawSendChar(char c);
+static void sendChar(char c);
+static void sendCharAndChecksum(char c);
+
+extern UART_HandleTypeDef huart2;
+
+static void rawSendChar(char c)
+{
+ HAL_UART_Transmit(&huart2, &c, 1, 1000);
+}
+
+static void sendCharAndChecksum(char c)
+{
+ checksum ^= c;
+ rawSendChar(c);
+ ++numChars;
+}
+
+void sendInt(int i)
+{
+ if (i < 0)
+ {
+ sendChar('-');
+ i = -i;
+ }
+ if (i >= 10)
+ {
+ sendInt(i/10);
+ i %= 10;
+ }
+ sendChar((char)((char)i + '0'));
+}
+
+static void sendChar(char c)
+{
+ if (c == '\n')
+ {
+ if (numChars != 0)
+ {
+ // Send the checksum
+ rawSendChar('*');
+ char digit0 = checksum % 10 + '0';
+ checksum /= 10;
+ char digit1 = checksum % 10 + '0';
+ checksum /= 10;
+ if (checksum != 0)
+ {
+ rawSendChar(checksum + '0');
+ }
+ rawSendChar(digit1);
+ rawSendChar(digit0);
+ }
+ rawSendChar(c);
+ numChars = 0;
+ }
+ else
+ {
+ if (numChars == 0)
+ {
+ checksum = 0;
+ // Send a dummy line number
+ sendCharAndChecksum('N');
+ sendInt(lineNumber++); // numChars is no longer zero, so only recurses once
+ sendCharAndChecksum(' ');
+ }
+ sendCharAndChecksum(c);
+ }
+}
diff --git a/Src/stm32f1xx_hal_msp.c b/Src/stm32f1xx_hal_msp.c
index 6402f02..ce45133 100644
--- a/Src/stm32f1xx_hal_msp.c
+++ b/Src/stm32f1xx_hal_msp.c
@@ -1,7 +1,7 @@
/**
******************************************************************************
* File Name : stm32f1xx_hal_msp.c
- * Description : This file provides code for the MSP Initialization
+ * Description : This file provides code for the MSP Initialization
* and de-Initialization codes.
******************************************************************************
*
@@ -34,6 +34,8 @@
/* Includes ------------------------------------------------------------------*/
#include "stm32f1xx_hal.h"
+extern DMA_HandleTypeDef hdma_usart2_rx;
+
extern void Error_Handler(void);
/* USER CODE BEGIN 0 */
@@ -68,7 +70,7 @@ void HAL_MspInit(void)
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
- /**NOJTAG: JTAG-DP Disabled and SW-DP Enabled
+ /**NOJTAG: JTAG-DP Disabled and SW-DP Enabled
*/
__HAL_AFIO_REMAP_SWJ_NOJTAG();
@@ -89,10 +91,10 @@ void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
__HAL_RCC_I2C1_CLK_ENABLE();
/* USER CODE END I2C1_MspInit 0 */
-
- /**I2C1 GPIO Configuration
+
+ /**I2C1 GPIO Configuration
PB6 ------> I2C1_SCL
- PB7 ------> I2C1_SDA
+ PB7 ------> I2C1_SDA
*/
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
@@ -114,10 +116,10 @@ void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
/* USER CODE END I2C1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_I2C1_CLK_DISABLE();
-
- /**I2C1 GPIO Configuration
+
+ /**I2C1 GPIO Configuration
PB6 ------> I2C1_SCL
- PB7 ------> I2C1_SDA
+ PB7 ------> I2C1_SDA
*/
HAL_GPIO_DeInit(GPIOB, GPIO_PIN_6|GPIO_PIN_7);
@@ -139,11 +141,11 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
/* USER CODE END SPI1_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_SPI1_CLK_ENABLE();
-
- /**SPI1 GPIO Configuration
+
+ /**SPI1 GPIO Configuration
PA5 ------> SPI1_SCK
PA6 ------> SPI1_MISO
- PA7 ------> SPI1_MOSI
+ PA7 ------> SPI1_MOSI
*/
GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
@@ -166,11 +168,11 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
/* USER CODE END SPI3_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_SPI3_CLK_ENABLE();
-
- /**SPI3 GPIO Configuration
+
+ /**SPI3 GPIO Configuration
PC10 ------> SPI3_SCK
PC11 ------> SPI3_MISO
- PC12 ------> SPI3_MOSI
+ PC12 ------> SPI3_MOSI
*/
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
@@ -201,11 +203,11 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
/* USER CODE END SPI1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_SPI1_CLK_DISABLE();
-
- /**SPI1 GPIO Configuration
+
+ /**SPI1 GPIO Configuration
PA5 ------> SPI1_SCK
PA6 ------> SPI1_MISO
- PA7 ------> SPI1_MOSI
+ PA7 ------> SPI1_MOSI
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7);
@@ -220,11 +222,11 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
/* USER CODE END SPI3_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_SPI3_CLK_DISABLE();
-
- /**SPI3 GPIO Configuration
+
+ /**SPI3 GPIO Configuration
PC10 ------> SPI3_SCK
PC11 ------> SPI3_MISO
- PC12 ------> SPI3_MOSI
+ PC12 ------> SPI3_MOSI
*/
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12);
@@ -246,10 +248,10 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
/* USER CODE END USART2_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_USART2_CLK_ENABLE();
-
- /**USART2 GPIO Configuration
+
+ /**USART2 GPIO Configuration
PD5 ------> USART2_TX
- PD6 ------> USART2_RX
+ PD6 ------> USART2_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
@@ -263,6 +265,27 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
__HAL_AFIO_REMAP_USART2_ENABLE();
+ /* Peripheral DMA init*/
+
+ hdma_usart2_rx.Instance = DMA1_Channel6;
+ hdma_usart2_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
+ hdma_usart2_rx.Init.PeriphInc = DMA_PINC_DISABLE;
+ hdma_usart2_rx.Init.MemInc = DMA_MINC_DISABLE;
+ hdma_usart2_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE;
+ hdma_usart2_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE;
+ hdma_usart2_rx.Init.Mode = DMA_CIRCULAR;
+ hdma_usart2_rx.Init.Priority = DMA_PRIORITY_LOW;
+ if (HAL_DMA_Init(&hdma_usart2_rx) != HAL_OK)
+ {
+ Error_Handler();
+ }
+
+ __HAL_LINKDMA(huart,hdmarx,hdma_usart2_rx);
+
+ /* Peripheral interrupt init */
+ HAL_NVIC_SetPriority(USART2_IRQn, 5, 0);
+ HAL_NVIC_EnableIRQ(USART2_IRQn);
+
/* USER CODE BEGIN USART2_MspInit 1 */
/* USER CODE END USART2_MspInit 1 */
@@ -274,10 +297,10 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
/* USER CODE END USART3_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_USART3_CLK_ENABLE();
-
- /**USART3 GPIO Configuration
+
+ /**USART3 GPIO Configuration
PD8 ------> USART3_TX
- PD9 ------> USART3_RX
+ PD9 ------> USART3_RX
*/
GPIO_InitStruct.Pin = GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
@@ -291,6 +314,10 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
__HAL_AFIO_REMAP_USART3_ENABLE();
+ /* Peripheral interrupt init */
+ HAL_NVIC_SetPriority(USART3_IRQn, 5, 0);
+ HAL_NVIC_EnableIRQ(USART3_IRQn);
+
/* USER CODE BEGIN USART3_MspInit 1 */
/* USER CODE END USART3_MspInit 1 */
@@ -308,13 +335,19 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
/* USER CODE END USART2_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_USART2_CLK_DISABLE();
-
- /**USART2 GPIO Configuration
+
+ /**USART2 GPIO Configuration
PD5 ------> USART2_TX
- PD6 ------> USART2_RX
+ PD6 ------> USART2_RX
*/
HAL_GPIO_DeInit(GPIOD, GPIO_PIN_5|GPIO_PIN_6);
+ /* Peripheral DMA DeInit*/
+ HAL_DMA_DeInit(huart->hdmarx);
+
+ /* Peripheral interrupt DeInit*/
+ HAL_NVIC_DisableIRQ(USART2_IRQn);
+
/* USER CODE BEGIN USART2_MspDeInit 1 */
/* USER CODE END USART2_MspDeInit 1 */
@@ -326,13 +359,16 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart)
/* USER CODE END USART3_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_USART3_CLK_DISABLE();
-
- /**USART3 GPIO Configuration
+
+ /**USART3 GPIO Configuration
PD8 ------> USART3_TX
- PD9 ------> USART3_RX
+ PD9 ------> USART3_RX
*/
HAL_GPIO_DeInit(GPIOD, GPIO_PIN_8|GPIO_PIN_9);
+ /* Peripheral interrupt DeInit*/
+ HAL_NVIC_DisableIRQ(USART3_IRQn);
+
/* USER CODE BEGIN USART3_MspDeInit 1 */
/* USER CODE END USART3_MspDeInit 1 */
diff --git a/Src/stm32f1xx_it.c b/Src/stm32f1xx_it.c
index 1144027..f911eda 100644
--- a/Src/stm32f1xx_it.c
+++ b/Src/stm32f1xx_it.c
@@ -42,11 +42,14 @@
/* External variables --------------------------------------------------------*/
extern HCD_HandleTypeDef hhcd_USB_OTG_FS;
+extern DMA_HandleTypeDef hdma_usart2_rx;
extern TIM_HandleTypeDef htim7;
extern TIM_HandleTypeDef htim2;
+extern UART_HandleTypeDef huart2;
+extern UART_HandleTypeDef huart3;
/******************************************************************************/
-/* Cortex-M3 Processor Interruption and Exception Handlers */
+/* Cortex-M3 Processor Interruption and Exception Handlers */
/******************************************************************************/
/**
@@ -188,6 +191,20 @@ void EXTI1_IRQHandler(void)
/* USER CODE END EXTI1_IRQn 1 */
}
+/**
+* @brief This function handles DMA1 channel6 global interrupt.
+*/
+void DMA1_Channel6_IRQHandler(void)
+{
+ /* USER CODE BEGIN DMA1_Channel6_IRQn 0 */
+
+ /* USER CODE END DMA1_Channel6_IRQn 0 */
+ HAL_DMA_IRQHandler(&hdma_usart2_rx);
+ /* USER CODE BEGIN DMA1_Channel6_IRQn 1 */
+
+ /* USER CODE END DMA1_Channel6_IRQn 1 */
+}
+
/**
* @brief This function handles EXTI line[9:5] interrupts.
*/
@@ -217,6 +234,33 @@ void EXTI15_10_IRQHandler(void)
/* USER CODE END EXTI15_10_IRQn 1 */
}
+/**
+* @brief This function handles USART2 global interrupt.
+*/
+void USART2_IRQHandler(void)
+{
+ /* USER CODE BEGIN USART2_IRQn 0 */
+
+ /* USER CODE END USART2_IRQn 0 */
+ HAL_UART_IRQHandler(&huart2);
+ /* USER CODE BEGIN USART2_IRQn 1 */
+
+ /* USER CODE END USART2_IRQn 1 */
+}
+
+/**
+* @brief This function handles USART3 global interrupt.
+*/
+void USART3_IRQHandler(void)
+{
+ /* USER CODE BEGIN USART3_IRQn 0 */
+
+ /* USER CODE END USART3_IRQn 0 */
+ HAL_UART_IRQHandler(&huart3);
+ /* USER CODE BEGIN USART3_IRQn 1 */
+
+ /* USER CODE END USART3_IRQn 1 */
+}
/**
* @brief This function handles TIM7 global interrupt.
diff --git a/Src/ui.c b/Src/ui.c
index 4cb0ca4..2be8aef 100644
--- a/Src/ui.c
+++ b/Src/ui.c
@@ -49,6 +49,8 @@ extern TIM_HandleTypeDef htim2;
#define READY_PRINT "MyFirmware"
+uint8_t statString[MAXSTATSIZE+1];
+
uint8_t moveStep = MOVE_10;
uint8_t offMode = MANUAL_OFF;
uint8_t connectSpeed = CONNECT_115200;
@@ -63,45 +65,45 @@ uint8_t selectedFs = FS_SD;
* user callback declaration
*/
-void uiInitialize (xEvent_t *pxEvent);
-void uiMainMenu (xEvent_t *pxEvent);
-void uiPreheatMenu(xEvent_t *pxEvent);
-void uiHomeMenu (xEvent_t *pxEvent);
+void uiInitialize (xUIEvent_t *pxEvent);
+void uiMainMenu (xUIEvent_t *pxEvent);
+void uiPreheatMenu(xUIEvent_t *pxEvent);
+void uiHomeMenu (xUIEvent_t *pxEvent);
-void uiPreheatMenu(xEvent_t *pxEvent);
-void uiPreheatSelectDev(xEvent_t *pxEvent);
-void uiPreheatSelectStep(xEvent_t *pxEvent);
+void uiPreheatMenu(xUIEvent_t *pxEvent);
+void uiPreheatSelectDev(xUIEvent_t *pxEvent);
+void uiPreheatSelectStep(xUIEvent_t *pxEvent);
-void uiExtrudeMenu(xEvent_t *pxEvent);
-void uiExtrudeSelectDev(xEvent_t *pxEvent);
-void uiExtrudeSelectStep(xEvent_t *pxEvent);
-void uiExtrudeSelectSpeed(xEvent_t *pxEvent);
+void uiExtrudeMenu(xUIEvent_t *pxEvent);
+void uiExtrudeSelectDev(xUIEvent_t *pxEvent);
+void uiExtrudeSelectStep(xUIEvent_t *pxEvent);
+void uiExtrudeSelectSpeed(xUIEvent_t *pxEvent);
-void uiMoveMenu (xEvent_t *pxEvent);
-void uiMoveMenuStepChange(xEvent_t *pxEvent);
+void uiMoveMenu (xUIEvent_t *pxEvent);
+void uiMoveMenuStepChange(xUIEvent_t *pxEvent);
-void uiFanMenu (xEvent_t *pxEvent);
+void uiFanMenu (xUIEvent_t *pxEvent);
-void uiSetupMenu (xEvent_t *pxEvent);
-void uiSetupMenuOffMode(xEvent_t *pxEvent);
+void uiSetupMenu (xUIEvent_t *pxEvent);
+void uiSetupMenuOffMode(xUIEvent_t *pxEvent);
-void uiSetupFilesystemMenu(xEvent_t *pxEvent);
-void uiSetupFilesystemSD(xEvent_t *pxEvent);
-void uiSetupFilesystemUSB(xEvent_t *pxEvent);
+void uiSetupFilesystemMenu(xUIEvent_t *pxEvent);
+void uiSetupFilesystemSD(xUIEvent_t *pxEvent);
+void uiSetupFilesystemUSB(xUIEvent_t *pxEvent);
-void uiSetupConnectMenu(xEvent_t *pxEvent);
-void uiSetupConnect9600(xEvent_t *pxEvent);
-void uiSetupConnect57600(xEvent_t *pxEvent);
-void uiSetupConnect115200(xEvent_t *pxEvent);
-void uiSetupConnect250000(xEvent_t *pxEvent);
+void uiSetupConnectMenu(xUIEvent_t *pxEvent);
+void uiSetupConnect9600(xUIEvent_t *pxEvent);
+void uiSetupConnect57600(xUIEvent_t *pxEvent);
+void uiSetupConnect115200(xUIEvent_t *pxEvent);
+void uiSetupConnect250000(xUIEvent_t *pxEvent);
-void uiSetupWifi (xEvent_t *pxEvent);
-void uiSetupAbout (xEvent_t *pxEvent);
+void uiSetupWifi (xUIEvent_t *pxEvent);
+void uiSetupAbout (xUIEvent_t *pxEvent);
-void uiMoreMenu (xEvent_t *pxEvent);
-void uiFileBrowse (xEvent_t *pxEvent);
+void uiMoreMenu (xUIEvent_t *pxEvent);
+void uiFileBrowse (xUIEvent_t *pxEvent);
-typedef void (*volatile eventProcessor_t) (xEvent_t *);
+typedef void (*volatile eventProcessor_t) (xUIEvent_t *);
eventProcessor_t processEvent = uiInitialize;
/*
@@ -116,9 +118,9 @@ static void uiDrawBinIcon(const TCHAR *path, uint16_t x, uint16_t y,
uint16_t width, uint16_t height, uint8_t resetWindow);
-__STATIC_INLINE void uiNextState(void (*volatile next) (xEvent_t *pxEvent)) {
+__STATIC_INLINE void uiNextState(void (*volatile next) (xUIEvent_t *pxEvent)) {
processEvent = next;
- xEvent_t event = { INIT_EVENT };
+ xUIEvent_t event = { INIT_EVENT };
xQueueSendToFront(xUIEventQueue, &event, 1000);
}
@@ -151,7 +153,7 @@ __STATIC_INLINE void uiDrawMenu(const xMenuItem_t *pMenu) {
static uint16_t touchX, touchY;
-__STATIC_INLINE void uiMenuHandleEventDefault(const xMenuItem_t *pMenu, xEvent_t *pxEvent) {
+__STATIC_INLINE void uiMenuHandleEventDefault(const xMenuItem_t *pMenu, xUIEvent_t *pxEvent) {
if (pxEvent) {
switch (pxEvent->ucEventID) {
@@ -162,11 +164,16 @@ __STATIC_INLINE void uiMenuHandleEventDefault(const xMenuItem_t *pMenu, xEvent_t
uiMediaStateChange(pxEvent->ucEventID);
break;
+ case SHOW_STATUS:
+ Lcd_Fill_Rect(0, LCD_MAX_Y - 9, LCD_MAX_X, LCD_MAX_Y, 0);
+ Lcd_Put_Text(10, LCD_MAX_Y - 9, 8, statString, 0xffffu);
+ break;
+
case INIT_EVENT:
if (pMenu) {
Lcd_Fill_Screen(Lcd_Get_RGB565(0, 0, 0));
uiDrawMenu(pMenu);
-#if 1
+#if 0
char buffer[12];
sprintf(buffer, "%03u:%03u", touchX, touchY);
Lcd_Put_Text(10, LCD_MAX_Y - 9, 8, buffer, 0xffffu);
@@ -230,7 +237,7 @@ __STATIC_INLINE void uiMenuHandleEventDefault(const xMenuItem_t *pMenu, xEvent_t
* user callback definition
*/
-void uiInitialize (xEvent_t *pxEvent) {
+void uiInitialize (xUIEvent_t *pxEvent) {
if (INIT_EVENT == pxEvent->ucEventID) {
@@ -310,7 +317,7 @@ void uiInitialize (xEvent_t *pxEvent) {
uiMenuHandleEventDefault(NULL, pxEvent);
}
-void uiMainMenu (xEvent_t *pxEvent) {
+void uiMainMenu (xUIEvent_t *pxEvent) {
static const xMenuItem_t mainMenu[8] = {
{ MKS_PIC_FL "/bmp_preHeat.bin", uiPreheatMenu },
@@ -339,7 +346,7 @@ static xMenuItem_t setupMenu[8] = {
{ MKS_PIC_FL "/bmp_return.bin", uiMainMenu }
};
-void uiSetupMenu (xEvent_t *pxEvent) {
+void uiSetupMenu (xUIEvent_t *pxEvent) {
switch(offMode) {
case MANUAL_OFF:
@@ -356,7 +363,7 @@ void uiSetupMenu (xEvent_t *pxEvent) {
Lcd_Put_Text(0, 0, 16, READY_PRINT ">Set", 0xffffu);
}
-void uiSetupMenuOffMode(xEvent_t *pxEvent) {
+void uiSetupMenuOffMode(xUIEvent_t *pxEvent) {
if (INIT_EVENT == pxEvent->ucEventID) {
switch(offMode) {
@@ -371,7 +378,7 @@ void uiSetupMenuOffMode(xEvent_t *pxEvent) {
}
processEvent = uiSetupMenu;
- xEvent_t event = { UPDATE7_EVENT };
+ xUIEvent_t event = { UPDATE7_EVENT };
xQueueSendToFront(xUIEventQueue, &event, 1000);
}
@@ -386,7 +393,7 @@ static xMenuItem_t setupFilesystemMenu[8] = {
{ MKS_PIC_FL "/bmp_return.bin", uiSetupMenu }
};
-void uiSetupFilesystemMenu (xEvent_t *pxEvent) {
+void uiSetupFilesystemMenu (xUIEvent_t *pxEvent) {
switch(selectedFs) {
case FS_SD:
@@ -405,23 +412,23 @@ void uiSetupFilesystemMenu (xEvent_t *pxEvent) {
Lcd_Put_Text(0, 0, 16, READY_PRINT ">Set>Filesystem", 0xffffu);
}
-void uiSetupFilesystemSD (xEvent_t *pxEvent) {
+void uiSetupFilesystemSD (xUIEvent_t *pxEvent) {
if (INIT_EVENT == pxEvent->ucEventID) {
selectedFs = FS_SD;
}
processEvent = uiSetupFilesystemMenu;
- xEvent_t event = { UPDATE12_EVENT };
+ xUIEvent_t event = { UPDATE12_EVENT };
xQueueSendToFront(xUIEventQueue, &event, 1000);
}
-void uiSetupFilesystemUSB (xEvent_t *pxEvent) {
+void uiSetupFilesystemUSB (xUIEvent_t *pxEvent) {
if (INIT_EVENT == pxEvent->ucEventID) {
selectedFs = FS_USB;
}
processEvent = uiSetupFilesystemMenu;
- xEvent_t event = { UPDATE12_EVENT };
+ xUIEvent_t event = { UPDATE12_EVENT };
xQueueSendToFront(xUIEventQueue, &event, 1000);
}
@@ -436,7 +443,7 @@ static xMenuItem_t setupConnectMenu[8] = {
{ MKS_PIC_FL "/bmp_return.bin", uiSetupMenu }
};
-void uiSetupConnectMenu(xEvent_t *pxEvent) {
+void uiSetupConnectMenu(xUIEvent_t *pxEvent) {
setupConnectMenu[0].pIconFile =
(connectSpeed == CONNECT_9600) ?
@@ -460,35 +467,35 @@ void uiSetupConnectMenu(xEvent_t *pxEvent) {
Lcd_Put_Text(0, 0, 16, READY_PRINT ">Set>ConnectSpeed", 0xffffu);
}
-void uiSetupConnect9600(xEvent_t *pxEvent) {
+void uiSetupConnect9600(xUIEvent_t *pxEvent) {
connectSpeed = CONNECT_9600;
processEvent = uiSetupConnectMenu;
- xEvent_t event = { UPDATE14_EVENT };
+ xUIEvent_t event = { UPDATE14_EVENT };
xQueueSendToFront(xUIEventQueue, &event, 1000);
}
-void uiSetupConnect57600(xEvent_t *pxEvent) {
+void uiSetupConnect57600(xUIEvent_t *pxEvent) {
connectSpeed = CONNECT_57600;
processEvent = uiSetupConnectMenu;
- xEvent_t event = { UPDATE14_EVENT };
+ xUIEvent_t event = { UPDATE14_EVENT };
xQueueSendToFront(xUIEventQueue, &event, 1000);
}
-void uiSetupConnect115200(xEvent_t *pxEvent) {
+void uiSetupConnect115200(xUIEvent_t *pxEvent) {
connectSpeed = CONNECT_115200;
processEvent = uiSetupConnectMenu;
- xEvent_t event = { UPDATE14_EVENT };
+ xUIEvent_t event = { UPDATE14_EVENT };
xQueueSendToFront(xUIEventQueue, &event, 1000);
}
-void uiSetupConnect250000(xEvent_t *pxEvent) {
+void uiSetupConnect250000(xUIEvent_t *pxEvent) {
connectSpeed = CONNECT_250000;
processEvent = uiSetupConnectMenu;
- xEvent_t event = { UPDATE14_EVENT };
+ xUIEvent_t event = { UPDATE14_EVENT };
xQueueSendToFront(xUIEventQueue, &event, 1000);
}
-void uiSetupWifi (xEvent_t *pxEvent) {
+void uiSetupWifi (xUIEvent_t *pxEvent) {
static const xMenuItem_t setupWifiMenu[8] = {
{ NULL, NULL },
@@ -506,7 +513,7 @@ void uiSetupWifi (xEvent_t *pxEvent) {
Lcd_Put_Text(0, 0, 16, READY_PRINT ">Set>Wifi", 0xffffu);
}
-void uiSetupAbout(xEvent_t *pxEvent) {
+void uiSetupAbout(xUIEvent_t *pxEvent) {
static const xMenuItem_t setupAboutMenu[8] = {
{ NULL, NULL },
@@ -524,7 +531,7 @@ void uiSetupAbout(xEvent_t *pxEvent) {
Lcd_Put_Text(0, 0, 16, READY_PRINT ">Set>About", 0xffffu);
}
-void uiHomeMenu (xEvent_t *pxEvent) {
+void uiHomeMenu (xUIEvent_t *pxEvent) {
static const xMenuItem_t homeMenu[8] = {
{ MKS_PIC_FL "/bmp_zeroA.bin", NULL },
@@ -542,7 +549,7 @@ void uiHomeMenu (xEvent_t *pxEvent) {
Lcd_Put_Text(0, 0, 16, READY_PRINT ">Home", 0xffffu);
}
-void uiFanMenu (xEvent_t *pxEvent) {
+void uiFanMenu (xUIEvent_t *pxEvent) {
static const xMenuItem_t fanMenu[8] = {
{ MKS_PIC_FL "/bmp_Add.bin", NULL },
@@ -571,7 +578,7 @@ static xMenuItem_t moveMenu[8] = {
{ MKS_PIC_FL "/bmp_return.bin", uiMainMenu }
};
-void uiMoveMenu (xEvent_t *pxEvent) {
+void uiMoveMenu (xUIEvent_t *pxEvent) {
switch(moveStep) {
case MOVE_10:
@@ -604,7 +611,7 @@ static xMenuItem_t preheatMenu[8] = {
{ MKS_PIC_FL "/bmp_return.bin", uiMainMenu }
};
-void uiPreheatMenu(xEvent_t *pxEvent) {
+void uiPreheatMenu(xUIEvent_t *pxEvent) {
switch(preheatDev)
{
@@ -642,7 +649,7 @@ void uiPreheatMenu(xEvent_t *pxEvent) {
Lcd_Put_Text(0, 0, 16, READY_PRINT ">Preheat", 0xffffu);
}
-void uiPreheatSelectDev(xEvent_t *pxEvent) {
+void uiPreheatSelectDev(xUIEvent_t *pxEvent) {
if (INIT_EVENT == pxEvent->ucEventID) {
switch(preheatDev) {
@@ -661,11 +668,11 @@ void uiPreheatSelectDev(xEvent_t *pxEvent) {
}
processEvent = uiPreheatMenu;
- xEvent_t event = { UPDATE5_EVENT };
+ xUIEvent_t event = { UPDATE5_EVENT };
xQueueSendToFront(xUIEventQueue, &event, 1000);
}
-void uiPreheatSelectStep(xEvent_t *pxEvent) {
+void uiPreheatSelectStep(xUIEvent_t *pxEvent) {
if (INIT_EVENT == pxEvent->ucEventID) {
switch (preheatSelDegree) {
@@ -685,7 +692,7 @@ void uiPreheatSelectStep(xEvent_t *pxEvent) {
}
processEvent = uiPreheatMenu;
- xEvent_t event = { UPDATE6_EVENT };
+ xUIEvent_t event = { UPDATE6_EVENT };
xQueueSendToFront(xUIEventQueue, &event, 1000);
}
@@ -700,7 +707,7 @@ static xMenuItem_t extrudeMenu[8] = {
{ MKS_PIC_FL "/bmp_return.bin", uiMainMenu }
};
-void uiExtrudeMenu(xEvent_t *pxEvent) {
+void uiExtrudeMenu(xUIEvent_t *pxEvent) {
switch(extrudeDev)
{
@@ -750,7 +757,7 @@ void uiExtrudeMenu(xEvent_t *pxEvent) {
Lcd_Put_Text(0, 0, 16, READY_PRINT ">Extrude", 0xffffu);
}
-void uiExtrudeSelectDev(xEvent_t *pxEvent) {
+void uiExtrudeSelectDev(xUIEvent_t *pxEvent) {
if (INIT_EVENT == pxEvent->ucEventID) {
switch(extrudeDev) {
@@ -766,11 +773,11 @@ void uiExtrudeSelectDev(xEvent_t *pxEvent) {
}
processEvent = uiExtrudeMenu;
- xEvent_t event = { UPDATE5_EVENT };
+ xUIEvent_t event = { UPDATE5_EVENT };
xQueueSendToFront(xUIEventQueue, &event, 1000);
}
-void uiExtrudeSelectStep(xEvent_t *pxEvent) {
+void uiExtrudeSelectStep(xUIEvent_t *pxEvent) {
if (INIT_EVENT == pxEvent->ucEventID) {
switch (extrudeDistance) {
@@ -790,11 +797,11 @@ void uiExtrudeSelectStep(xEvent_t *pxEvent) {
}
processEvent = uiExtrudeMenu;
- xEvent_t event = { UPDATE6_EVENT };
+ xUIEvent_t event = { UPDATE6_EVENT };
xQueueSendToFront(xUIEventQueue, &event, 1000);
}
-void uiExtrudeSelectSpeed(xEvent_t *pxEvent) {
+void uiExtrudeSelectSpeed(xUIEvent_t *pxEvent) {
if (INIT_EVENT == pxEvent->ucEventID) {
switch (extrudeSelSpeed) {
@@ -814,11 +821,11 @@ void uiExtrudeSelectSpeed(xEvent_t *pxEvent) {
}
processEvent = uiExtrudeMenu;
- xEvent_t event = { UPDATE7_EVENT };
+ xUIEvent_t event = { UPDATE7_EVENT };
xQueueSendToFront(xUIEventQueue, &event, 1000);
}
-void uiMoveMenuStepChange (xEvent_t *pxEvent) {
+void uiMoveMenuStepChange (xUIEvent_t *pxEvent) {
if (INIT_EVENT == pxEvent->ucEventID) {
switch(moveStep) {
@@ -838,11 +845,11 @@ void uiMoveMenuStepChange (xEvent_t *pxEvent) {
}
processEvent = uiMoveMenu;
- xEvent_t event = { UPDATE4_EVENT };
+ xUIEvent_t event = { UPDATE4_EVENT };
xQueueSendToFront(xUIEventQueue, &event, 1000);
}
-void uiMoreMenu (xEvent_t *pxEvent) {
+void uiMoreMenu (xUIEvent_t *pxEvent) {
static const xMenuItem_t moreMenu[8] = {
{ MKS_PIC_FL /* "/bmp_morefunc1.bin" */ "/bmp_custom1.bin", NULL },
@@ -866,7 +873,7 @@ static int row_selected = -1;
static TCHAR cwd[_MAX_LFN + 1];
-void uiFileBrowse(xEvent_t *pxEvent) {
+void uiFileBrowse(xUIEvent_t *pxEvent) {
switch (pxEvent->ucEventID) {
case TOUCH_DOWN_EVENT:
diff --git a/Src/usb_host.c b/Src/usb_host.c
index 9022dcc..86e0d57 100644
--- a/Src/usb_host.c
+++ b/Src/usb_host.c
@@ -2,7 +2,7 @@
******************************************************************************
* @file : USB_HOST
* @version : v1.0_Cube
- * @brief : This file implements the USB Host
+ * @brief : This file implements the USB Host
******************************************************************************
* COPYRIGHT(c) 2016 STMicroelectronics
*
@@ -44,24 +44,24 @@ USBH_HandleTypeDef hUsbHostFS;
/**
* -- Insert your variables declaration here --
-*/
+*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/*
* user callback declaration
-*/
+*/
static void USBH_UserProcess (USBH_HandleTypeDef *phost, uint8_t id);
/**
* -- Insert your external function declaration here --
-*/
+*/
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
-/* init function */
+/* init function */
void MX_USB_HOST_Init(void)
{
/* Init Host Library,Add Supported Class and Start the library*/
@@ -72,11 +72,11 @@ void MX_USB_HOST_Init(void)
/*
* user callback definition
-*/
+*/
static void USBH_UserProcess (USBH_HandleTypeDef *phost, uint8_t id)
{
/* USER CODE BEGIN 2 */
- xEvent_t event;
+ xUIEvent_t event;
switch (id) {
case HOST_USER_DISCONNECTION: