From e8633bd4e541b4badf16605c4895e31c6e60dfba Mon Sep 17 00:00:00 2001 From: frux-c Date: Mon, 3 Jun 2024 20:18:34 -0600 Subject: [PATCH] added expansion disable on app init --- uhf_app.c | 5 +++++ uhf_module.c | 2 +- uhf_uart.c | 49 ++++++++++++++++++++++++++++--------------------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/uhf_app.c b/uhf_app.c index c02ab6a3e1e..3cdbb6ba979 100644 --- a/uhf_app.c +++ b/uhf_app.c @@ -1,4 +1,5 @@ #include "uhf_app_i.h" +#include "expansion/expansion.h" char* convertToHexString(uint8_t* array, size_t length) { if(array == NULL || length == 0) { @@ -195,6 +196,8 @@ void uhf_show_loading_popup(void* ctx, bool show) { int32_t uhf_app_main(void* ctx) { UNUSED(ctx); + Expansion* expansion = furi_record_open(RECORD_EXPANSION); + expansion_disable(expansion); bool is_5v_enabled_by_app = false; // enable 5v pin if not enabled if(!furi_hal_power_is_otg_enabled()) { @@ -211,5 +214,7 @@ int32_t uhf_app_main(void* ctx) { } // exit app uhf_free(uhf_app); + expansion_enable(expansion); + furi_record_close(RECORD_EXPANSION); return 0; } \ No newline at end of file diff --git a/uhf_module.c b/uhf_module.c index e4f40e6136c..a17afd01f6b 100644 --- a/uhf_module.c +++ b/uhf_module.c @@ -46,7 +46,7 @@ M100Module* m100_module_alloc() { module->region = DEFAULT_WORKING_REGION; module->info = m100_module_info_alloc(); module->uart = uhf_uart_alloc(); - module->write_mask = WRITE_EPC; + module->write_mask = WRITE_EPC; // default to write epc only return module; } diff --git a/uhf_uart.c b/uhf_uart.c index 7ff77c3d971..45d9b2b9734 100644 --- a/uhf_uart.c +++ b/uhf_uart.c @@ -30,21 +30,25 @@ // return 0; // } -void uhf_uart_default_rx_callback(FuriHalSerialHandle *handle, FuriHalSerialRxEvent event, void* ctx) { +void uhf_uart_default_rx_callback( + FuriHalSerialHandle* handle, + FuriHalSerialRxEvent event, + void* ctx) { UHFUart* uart = (UHFUart*)ctx; // FURI_LOG_E("UHF_UART", "UHF UART RX CALLBACK"); - if((event & FuriHalSerialRxEventData) == FuriHalSerialRxEventData){ + if((event & FuriHalSerialRxEventData) == FuriHalSerialRxEventData) { uint8_t data = furi_hal_serial_async_rx(handle); // if(data == UHF_UART_FRAME_START){ // uhf_buffer_reset(uart->buffer); // } - if(uhf_is_buffer_closed(uart->buffer)){ + if(uhf_is_buffer_closed(uart->buffer)) { return; } - if(data == UHF_UART_FRAME_END){ + if(data == UHF_UART_FRAME_END) { uhf_buffer_append_single(uart->buffer, data); uhf_buffer_close(uart->buffer); - FURI_LOG_E("UHF_UART", "UHF Total length read = %u", uhf_buffer_get_size(uart->buffer)); + FURI_LOG_E( + "UHF_UART", "UHF Total length read = %u", uhf_buffer_get_size(uart->buffer)); } uhf_buffer_append_single(uart->buffer, data); uhf_uart_tick_reset(uart); @@ -53,28 +57,27 @@ void uhf_uart_default_rx_callback(FuriHalSerialHandle *handle, FuriHalSerialRxEv } } -UHFUart* uhf_uart_alloc(){ - UHFUart *uart = (UHFUart*)malloc(sizeof(UHFUart)); +UHFUart* uhf_uart_alloc() { + UHFUart* uart = (UHFUart*)malloc(sizeof(UHFUart)); uart->bus = FuriHalBusUSART1; uart->handle = furi_hal_serial_control_acquire(FuriHalSerialIdUsart); - // uart->rx_buff_stream = furi_stream_buffer_alloc(UHF_UART_RX_BUFFER_SIZE, 1); + furi_check(uart->handle, "UHF UART HANDLE IS NULL"); uart->init_by_app = !furi_hal_bus_is_enabled(uart->bus); uart->tick = UHF_UART_WAIT_TICK; uart->baudrate = UHF_UART_DEFAULT_BAUDRATE; // expansion_disable(); - if(uart->init_by_app){ + if(uart->init_by_app) { FURI_LOG_E("UHF_UART", "UHF UART INIT BY APP"); furi_hal_serial_init(uart->handle, uart->baudrate); - } - else{ + } else { FURI_LOG_E("UHF_UART", "UHF UART INIT BY HAL"); } uart->buffer = uhf_buffer_alloc(UHF_UART_RX_BUFFER_SIZE); furi_hal_serial_async_rx_start(uart->handle, uhf_uart_default_rx_callback, uart, false); return uart; -} +} -void uhf_uart_free(UHFUart* uart){ +void uhf_uart_free(UHFUart* uart) { furi_assert(uart); // furi_assert(uart->thread); // furi_thread_flags_set(furi_thread_get_id(uart->thread), UHFUartWorkerExitingFlag); @@ -82,39 +85,43 @@ void uhf_uart_free(UHFUart* uart){ // furi_thread_free(uart->thread); // furi_stream_buffer_free(uart->rx_buff_stream); uhf_buffer_free(uart->buffer); - if(uart->init_by_app){ + if(uart->init_by_app) { furi_hal_serial_deinit(uart->handle); } furi_hal_serial_control_release(uart->handle); free(uart); } -void uhf_uart_set_receive_byte_callback(UHFUart* uart, FuriHalSerialAsyncRxCallback callback, void *ctx, bool report_errors){ +void uhf_uart_set_receive_byte_callback( + UHFUart* uart, + FuriHalSerialAsyncRxCallback callback, + void* ctx, + bool report_errors) { furi_hal_serial_async_rx_start(uart->handle, callback, ctx, report_errors); } -void uhf_uart_send(UHFUart* uart, uint8_t* data, size_t size){ +void uhf_uart_send(UHFUart* uart, uint8_t* data, size_t size) { furi_hal_serial_tx(uart->handle, data, size); } -void uhf_uart_send_wait(UHFUart* uart, uint8_t* data, size_t size){ +void uhf_uart_send_wait(UHFUart* uart, uint8_t* data, size_t size) { uhf_uart_send(uart, data, size); furi_hal_serial_tx_wait_complete(uart->handle); // furi_thread_flags_set(furi_thread_get_id(uart->thread), UHFUartWorkerWaitingDataFlag); } -void uhf_uart_set_baudrate(UHFUart* uart, uint32_t baudrate){ +void uhf_uart_set_baudrate(UHFUart* uart, uint32_t baudrate) { furi_hal_serial_set_br(uart->handle, baudrate); uart->baudrate = baudrate; } -bool uhf_uart_tick(UHFUart* uart){ - if(uart->tick > 0){ +bool uhf_uart_tick(UHFUart* uart) { + if(uart->tick > 0) { uart->tick--; } return uart->tick == 0; } -void uhf_uart_tick_reset(UHFUart* uart){ +void uhf_uart_tick_reset(UHFUart* uart) { uart->tick = UHF_UART_WAIT_TICK; } \ No newline at end of file