|
|
@@ -1,16 +1,13 @@
|
|
|
#include "esp_flasher_app_i.h"
|
|
|
#include "esp_flasher_uart.h"
|
|
|
|
|
|
-#define UART_CH (FuriHalUartIdUSART1)
|
|
|
-#define BAUDRATE (115200)
|
|
|
-
|
|
|
struct EspFlasherUart {
|
|
|
EspFlasherApp* app;
|
|
|
- FuriHalUartId channel;
|
|
|
FuriThread* rx_thread;
|
|
|
FuriStreamBuffer* rx_stream;
|
|
|
uint8_t rx_buf[RX_BUF_SIZE + 1];
|
|
|
void (*handle_rx_data_cb)(uint8_t* buf, size_t len, void* context);
|
|
|
+ FuriHalSerialHandle* serial_handle;
|
|
|
};
|
|
|
|
|
|
typedef enum {
|
|
|
@@ -27,10 +24,14 @@ void esp_flasher_uart_set_handle_rx_data_cb(
|
|
|
|
|
|
#define WORKER_ALL_RX_EVENTS (WorkerEvtStop | WorkerEvtRxDone)
|
|
|
|
|
|
-void esp_flasher_uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {
|
|
|
+void esp_flasher_uart_on_irq_cb(
|
|
|
+ FuriHalSerialHandle* handle,
|
|
|
+ FuriHalSerialRxEvent event,
|
|
|
+ void* context) {
|
|
|
EspFlasherUart* uart = (EspFlasherUart*)context;
|
|
|
|
|
|
- if(ev == UartIrqEventRXNE) {
|
|
|
+ if(event == FuriHalSerialRxEventData) {
|
|
|
+ uint8_t data = furi_hal_serial_async_rx(handle);
|
|
|
furi_stream_buffer_send(uart->rx_stream, &data, 1, 0);
|
|
|
furi_thread_flags_set(furi_thread_get_id(uart->rx_thread), WorkerEvtRxDone);
|
|
|
}
|
|
|
@@ -57,16 +58,19 @@ static int32_t uart_worker(void* context) {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-void esp_flasher_uart_tx(uint8_t* data, size_t len) {
|
|
|
- furi_hal_uart_tx(UART_CH, data, len);
|
|
|
+void esp_flasher_uart_tx(EspFlasherUart* uart, uint8_t* data, size_t len) {
|
|
|
+ furi_hal_serial_tx(uart->serial_handle, data, len);
|
|
|
+}
|
|
|
+
|
|
|
+void esp_flasher_uart_set_br(EspFlasherUart* uart, uint32_t baud) {
|
|
|
+ furi_hal_serial_set_br(uart->serial_handle, baud);
|
|
|
}
|
|
|
|
|
|
EspFlasherUart*
|
|
|
- esp_flasher_uart_init(EspFlasherApp* app, FuriHalUartId channel, const char* thread_name) {
|
|
|
+ esp_flasher_uart_init(EspFlasherApp* app, FuriHalSerialId channel, const char* thread_name) {
|
|
|
EspFlasherUart* uart = malloc(sizeof(EspFlasherUart));
|
|
|
|
|
|
uart->app = app;
|
|
|
- uart->channel = channel;
|
|
|
uart->rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE, 1);
|
|
|
uart->rx_thread = furi_thread_alloc();
|
|
|
furi_thread_set_name(uart->rx_thread, thread_name);
|
|
|
@@ -74,13 +78,10 @@ EspFlasherUart*
|
|
|
furi_thread_set_context(uart->rx_thread, uart);
|
|
|
furi_thread_set_callback(uart->rx_thread, uart_worker);
|
|
|
furi_thread_start(uart->rx_thread);
|
|
|
- if(channel == FuriHalUartIdUSART1) {
|
|
|
- furi_hal_console_disable();
|
|
|
- } else if(channel == FuriHalUartIdLPUART1) {
|
|
|
- furi_hal_uart_init(channel, BAUDRATE);
|
|
|
- }
|
|
|
- furi_hal_uart_set_br(channel, BAUDRATE);
|
|
|
- furi_hal_uart_set_irq_cb(channel, esp_flasher_uart_on_irq_cb, uart);
|
|
|
+ uart->serial_handle = furi_hal_serial_control_acquire(channel);
|
|
|
+ furi_check(uart->serial_handle);
|
|
|
+ furi_hal_serial_init(uart->serial_handle, BAUDRATE);
|
|
|
+ furi_hal_serial_async_rx_start(uart->serial_handle, esp_flasher_uart_on_irq_cb, uart, false);
|
|
|
|
|
|
return uart;
|
|
|
}
|
|
|
@@ -96,11 +97,8 @@ void esp_flasher_uart_free(EspFlasherUart* uart) {
|
|
|
furi_thread_join(uart->rx_thread);
|
|
|
furi_thread_free(uart->rx_thread);
|
|
|
|
|
|
- furi_hal_uart_set_irq_cb(uart->channel, NULL, NULL);
|
|
|
- if(uart->channel == FuriHalUartIdLPUART1) {
|
|
|
- furi_hal_uart_deinit(uart->channel);
|
|
|
- }
|
|
|
- furi_hal_console_enable();
|
|
|
+ furi_hal_serial_deinit(uart->serial_handle);
|
|
|
+ furi_hal_serial_control_release(uart->serial_handle);
|
|
|
|
|
|
free(uart);
|
|
|
}
|