aboutsummaryrefslogtreecommitdiff
path: root/stm32f091/esp8266.c
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-10-26 16:20:39 +0200
committerlonkaars <loek@pipeframe.xyz>2022-10-26 16:20:39 +0200
commitd945680142d5b16d8809ea200833edd97caec2f8 (patch)
treeba1e23bf440181e8a2c61587b5274877563fe880 /stm32f091/esp8266.c
parente2ae9e96ba05baa389ebc49a65a941bada87e3aa (diff)
esp send with dma in seperate function
Diffstat (limited to 'stm32f091/esp8266.c')
-rw-r--r--stm32f091/esp8266.c57
1 files changed, 13 insertions, 44 deletions
diff --git a/stm32f091/esp8266.c b/stm32f091/esp8266.c
index 98c4e10..24860a1 100644
--- a/stm32f091/esp8266.c
+++ b/stm32f091/esp8266.c
@@ -7,57 +7,26 @@
#include "esp8266.h"
#include "setup.h"
#include "consts.h"
+#include "util.h"
-char g_ws_esp8266_dma_rx_buffer[WS_DMA_RX_BUFFER_SIZE];
-char MainBuf[WS_DMA_RX_BUFFER_SIZE]; // TODO: remove
-int isOK = 0; // TODO: remove
-uint16_t g_ws_esp8266_dma_old_pos = 0;
-uint16_t g_ws_esp8266_dma_new_pos = 0;
-
-/*
-// when rx receives data handle the message. this function is in stm32. this name needs to stay the same or else it wont work.
-void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size){
- if(huart->Instance == USART1) {
- g_ws_esp8266_dma_old_pos = g_ws_esp8266_dma_new_pos; // Update the last position before copying new data
-
- if(g_ws_esp8266_dma_old_pos+Size > WS_DMA_RX_BUFFER_SIZE) { // if the current position + new data is greater than the main buffer
- uint16_t dataToCopy = WS_DMA_RX_BUFFER_SIZE-g_ws_esp8266_dma_old_pos; // find remaining space left
- memcpy ((uint8_t*)MainBuf+g_ws_esp8266_dma_old_pos,g_ws_esp8266_dma_rx_buffer,dataToCopy); // copy data in the remaining space
-
- g_ws_esp8266_dma_old_pos = 0; // point to the start of the buffer
- memcpy ((uint8_t*)MainBuf,(uint8_t*)g_ws_esp8266_dma_rx_buffer+dataToCopy,(Size-dataToCopy)); // copy the remaing data
- g_ws_esp8266_dma_new_pos = (Size-dataToCopy); // update position
- }
- // if data is less than new data
- else {
- memcpy ((uint8_t*)MainBuf+g_ws_esp8266_dma_old_pos,g_ws_esp8266_dma_rx_buffer,Size);
- g_ws_esp8266_dma_new_pos = Size+g_ws_esp8266_dma_old_pos;
- }
- // start DMA again
- // memset(g_ws_esp8266_dma_rx_buffer,'\0',g_ws_esp8266_dma_rx_buffer_Size); // clear rx_buff
- HAL_UART_Receive_DMA(&huart1, (uint8_t*) g_ws_esp8266_dma_rx_buffer, WS_DMA_RX_BUFFER_SIZE);
- __HAL_DMA_DISABLE_IT(&hdma_usart1_rx,DMA_IT_HT);
- }
+uint8_t g_ws_esp8266_dma_rx_buffer[WS_DMA_RX_BUFFER_SIZE];
+uint8_t g_ws_esp8266_dma_tx_buffer[WS_DMA_TX_BUFFER_SIZE];
- // check for OK messagge
- for(int i=0;i<Size;i++){
- if(g_ws_esp8266_dma_rx_buffer[i]=='O' && g_ws_esp8266_dma_rx_buffer[i+1]=='K'){
- isOK=1;
- //memset(MainBuf,'\0',MainBuf_Size); // clear main buffer if OK is in the main buffer.
- //memset(g_ws_esp8266_dma_rx_buffer,'\0',g_ws_esp8266_dma_rx_buffer_Size); // clear rx_buff
+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); }
- }
- else if(strncmp(g_ws_esp8266_dma_rx_buffer, "+IPD", 4) == 0){
+void ws_esp8266_send(uint8_t* data, size_t size) {
+ size_t limited_size = WS_MIN(size, WS_DMA_TX_BUFFER_SIZE - 1);
+ memcpy(g_ws_esp8266_dma_tx_buffer, data, limited_size);
+ g_ws_esp8266_dma_tx_buffer[limited_size] = 0x00;
- }
- }
+ 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 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); }
+// TODO: refactor code from here to EOF
void ws_esp8266_ATsendCommand(uint8_t* data){
char dataChar[20];
uint8_t Tx_send[]="AT+CIPSEND=0,";