#ifndef STM32F407XX_ESP8266_H
#define STM32F407XX_ESP8266_H

#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_uart.h"

#ifdef __cplusplus
extern "C" {
#endif

// ESP8266 AT firmware UART: USART3, PD8 = TX and PD9 = RX
#define ESP8266_UART_INSTANCE    USART3
#define ESP8266_UART_BAUD_RATE   115200U

// ESP8266 hardware reset: PD10, active low
#define ESP8266_RST_GPIO_PORT    GPIOD
#define ESP8266_RST_PIN          GPIO_PIN_10

extern UART_HandleTypeDef hesp8266_uart;

HAL_StatusTypeDef ESP8266_Init(void);
void ESP8266_Reset(void);
HAL_StatusTypeDef ESP8266_Test(uint32_t attempts);
HAL_StatusTypeDef ESP8266_SetStationMode(void);
HAL_StatusTypeDef ESP8266_JoinAccessPoint(const char *ssid,
		const char *password);
HAL_StatusTypeDef ESP8266_SetSingleConnection(void);
HAL_StatusTypeDef ESP8266_ConnectTcp(const char *server_ip,
		uint16_t server_port);
HAL_StatusTypeDef ESP8266_EnterTransparentMode(void);
HAL_StatusTypeDef ESP8266_ExitTransparentMode(void);
HAL_StatusTypeDef ESP8266_Transmit(const uint8_t *data, uint16_t length,
		uint32_t timeout_ms);
uint8_t ESP8266_ReadByte(uint8_t *data);

#ifdef __cplusplus
}
#endif

#endif
