diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-10-27 15:37:35 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-10-27 15:37:35 +0200 |
commit | 94e31069df88c3d5e50b4160705c2b7aa27e152b (patch) | |
tree | fac20382f2055fc47fdee182b0b12d3dc564a888 /stm32f091/esp8266.c | |
parent | 4dbb57fe63d3c59893d1a670fecdde7ea20c9a4a (diff) |
WIP server parser
Diffstat (limited to 'stm32f091/esp8266.c')
-rw-r--r-- | stm32f091/esp8266.c | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/stm32f091/esp8266.c b/stm32f091/esp8266.c index 4daba34..c98528e 100644 --- a/stm32f091/esp8266.c +++ b/stm32f091/esp8266.c @@ -15,13 +15,22 @@ uint8_t g_ws_esp8266_dma_tx_buffer[WS_DMA_TX_BUFFER_SIZE]; void DMA1_Ch1_IRQHandler(void) { HAL_DMA_IRQHandler(&hdma_usart1_rx); } void DMA1_Ch2_3_DMA2_Ch1_2_IRQHandler(void) { HAL_DMA_IRQHandler(&hdma_usart1_tx); } -void USART1_IRQHandler(void) { HAL_UART_IRQHandler(&huart1); } +void USART1_IRQHandler(void) { + if (__HAL_UART_GET_FLAG(&huart1, UART_FLAG_IDLE)) { + __HAL_UART_CLEAR_IDLEFLAG(&huart1); + HAL_UART_RxCpltCallback(&huart1); + HAL_UART_DMAStop(&huart1); + ws_esp8266_start_receive(); + } + HAL_UART_IRQHandler(&huart1); +} void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart) { - ws_server_req_incoming(g_ws_esp8266_dma_rx_buffer, WS_DMA_RX_BUFFER_SIZE); + size_t len = strlen((char*) g_ws_esp8266_dma_rx_buffer); + if (len > 0) ws_server_req_incoming(g_ws_esp8266_dma_rx_buffer, len); - HAL_UART_Receive_DMA(&huart1, g_ws_esp8266_dma_rx_buffer, WS_DMA_RX_BUFFER_SIZE); - __HAL_DMA_DISABLE_IT(&hdma_usart1_rx, DMA_IT_HT); + memset(g_ws_esp8266_dma_rx_buffer, 0, WS_DMA_RX_BUFFER_SIZE); + ws_esp8266_start_receive(); } void ws_esp8266_send(uint8_t* data, size_t size) { @@ -29,10 +38,20 @@ void ws_esp8266_send(uint8_t* data, size_t size) { memcpy(g_ws_esp8266_dma_tx_buffer, data, limited_size); g_ws_esp8266_dma_tx_buffer[limited_size] = 0x00; +#ifdef WS_DBG_PRINT_ESP_OVER_USART2 + uint8_t green[] = { 0x1b, 0x5b, 0x33, 0x32, 0x6d }; + HAL_UART_Transmit(&huart2, green, sizeof(green), 100); + HAL_UART_Transmit(&huart2, g_ws_esp8266_dma_tx_buffer, strlen((char*) g_ws_esp8266_dma_tx_buffer), 100); +#endif + HAL_UART_Transmit_DMA(&huart1, g_ws_esp8266_dma_tx_buffer, strlen((char*) g_ws_esp8266_dma_tx_buffer)); __HAL_UART_ENABLE_IT(&huart1, UART_IT_TXE); } +void ws_esp8266_start_receive() { + HAL_UART_Receive_DMA(&huart1, g_ws_esp8266_dma_rx_buffer, WS_DMA_RX_BUFFER_SIZE); + __HAL_DMA_DISABLE_IT(&hdma_usart1_rx, DMA_IT_HT); +} // TODO: refactor code from here to EOF void ws_esp8266_ATsendCommand(uint8_t* data){ |