Skip to content

Commit

Permalink
added expansion disable on app init
Browse files Browse the repository at this point in the history
  • Loading branch information
frux-c committed Jun 4, 2024
1 parent 2b48fc7 commit e8633bd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
5 changes: 5 additions & 0 deletions uhf_app.c
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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()) {
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion uhf_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
49 changes: 28 additions & 21 deletions uhf_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -53,68 +57,71 @@ 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);
// furi_thread_join(uart->thread);
// 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;
}

0 comments on commit e8633bd

Please sign in to comment.