mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-26 14:51:52 +03:00
Improve furi_hal_serial API
This commit is contained in:
parent
fee6f12684
commit
c489c956e7
@ -61,9 +61,14 @@ static void expansion_worker_serial_rx_callback(
|
||||
|
||||
ExpansionWorker* instance = context;
|
||||
|
||||
if(event == FuriHalSerialRxEventData) {
|
||||
const uint8_t data = furi_hal_serial_async_rx(handle);
|
||||
furi_stream_buffer_send(instance->rx_buf, &data, sizeof(data), 0);
|
||||
if(event & (FuriHalSerialRxEventNoiseError | FuriHalSerialRxEventFrameError |
|
||||
FuriHalSerialRxEventOverrunError)) {
|
||||
furi_thread_flags_set(furi_thread_get_id(instance->thread), ExpansionWorkerFlagError);
|
||||
} else if(event & FuriHalSerialRxEventData) {
|
||||
while(furi_hal_serial_async_rx_available(handle)) {
|
||||
const uint8_t data = furi_hal_serial_async_rx(handle);
|
||||
furi_stream_buffer_send(instance->rx_buf, &data, sizeof(data), 0);
|
||||
}
|
||||
furi_thread_flags_set(furi_thread_get_id(instance->thread), ExpansionWorkerFlagData);
|
||||
}
|
||||
}
|
||||
@ -341,7 +346,7 @@ static int32_t expansion_worker(void* context) {
|
||||
furi_hal_serial_init(instance->serial_handle, EXPANSION_PROTOCOL_DEFAULT_BAUD_RATE);
|
||||
|
||||
furi_hal_serial_async_rx_start(
|
||||
instance->serial_handle, expansion_worker_serial_rx_callback, instance, false);
|
||||
instance->serial_handle, expansion_worker_serial_rx_callback, instance, true);
|
||||
|
||||
if(expansion_worker_send_heartbeat(instance)) {
|
||||
expansion_worker_state_machine(instance);
|
||||
|
@ -189,6 +189,12 @@ bool rpc_pb_stream_read(pb_istream_t* istream, pb_byte_t* buf, size_t count) {
|
||||
furi_assert(session);
|
||||
furi_assert(istream->bytes_left);
|
||||
|
||||
/* TODO FL-3768 this function may be called after
|
||||
marking the worker for termination */
|
||||
if(session->terminate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t flags = 0;
|
||||
size_t bytes_received = 0;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
entry,status,name,type,params
|
||||
Version,+,54.0,,
|
||||
Version,v,54.1,,
|
||||
Header,+,applications/services/bt/bt_service/bt.h,,
|
||||
Header,+,applications/services/cli/cli.h,,
|
||||
Header,+,applications/services/cli/cli_vcp.h,,
|
||||
@ -1273,6 +1273,7 @@ Function,+,furi_hal_sd_presence_init,void,
|
||||
Function,+,furi_hal_sd_read_blocks,FuriStatus,"uint32_t*, uint32_t, uint32_t"
|
||||
Function,+,furi_hal_sd_write_blocks,FuriStatus,"const uint32_t*, uint32_t, uint32_t"
|
||||
Function,+,furi_hal_serial_async_rx,uint8_t,FuriHalSerialHandle*
|
||||
Function,+,furi_hal_serial_async_rx_available,_Bool,FuriHalSerialHandle*
|
||||
Function,+,furi_hal_serial_async_rx_start,void,"FuriHalSerialHandle*, FuriHalSerialAsyncRxCallback, void*, _Bool"
|
||||
Function,+,furi_hal_serial_async_rx_stop,void,FuriHalSerialHandle*
|
||||
Function,+,furi_hal_serial_control_acquire,FuriHalSerialHandle*,FuriHalSerialId
|
||||
|
|
@ -1,5 +1,5 @@
|
||||
entry,status,name,type,params
|
||||
Version,+,54.0,,
|
||||
Version,+,54.1,,
|
||||
Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,,
|
||||
Header,+,applications/services/bt/bt_service/bt.h,,
|
||||
Header,+,applications/services/cli/cli.h,,
|
||||
@ -1439,6 +1439,7 @@ Function,+,furi_hal_sd_presence_init,void,
|
||||
Function,+,furi_hal_sd_read_blocks,FuriStatus,"uint32_t*, uint32_t, uint32_t"
|
||||
Function,+,furi_hal_sd_write_blocks,FuriStatus,"const uint32_t*, uint32_t, uint32_t"
|
||||
Function,+,furi_hal_serial_async_rx,uint8_t,FuriHalSerialHandle*
|
||||
Function,+,furi_hal_serial_async_rx_available,_Bool,FuriHalSerialHandle*
|
||||
Function,+,furi_hal_serial_async_rx_start,void,"FuriHalSerialHandle*, FuriHalSerialAsyncRxCallback, void*, _Bool"
|
||||
Function,+,furi_hal_serial_async_rx_stop,void,FuriHalSerialHandle*
|
||||
Function,+,furi_hal_serial_control_acquire,FuriHalSerialHandle*,FuriHalSerialId
|
||||
|
|
@ -782,6 +782,17 @@ void furi_hal_serial_async_rx_stop(FuriHalSerialHandle* handle) {
|
||||
furi_hal_serial_async_rx_configure(handle, NULL, NULL);
|
||||
}
|
||||
|
||||
bool furi_hal_serial_async_rx_available(FuriHalSerialHandle* handle) {
|
||||
furi_check(FURI_IS_IRQ_MODE());
|
||||
furi_assert(handle->id < FuriHalSerialIdMax);
|
||||
|
||||
if(handle->id == FuriHalSerialIdUsart) {
|
||||
return LL_USART_IsActiveFlag_RXNE_RXFNE(USART1);
|
||||
} else {
|
||||
return LL_LPUART_IsActiveFlag_RXNE_RXFNE(LPUART1);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t furi_hal_serial_async_rx(FuriHalSerialHandle* handle) {
|
||||
furi_check(FURI_IS_IRQ_MODE());
|
||||
furi_assert(handle->id < FuriHalSerialIdMax);
|
||||
|
@ -130,6 +130,16 @@ void furi_hal_serial_async_rx_start(
|
||||
*/
|
||||
void furi_hal_serial_async_rx_stop(FuriHalSerialHandle* handle);
|
||||
|
||||
/** Check if there is data available for reading
|
||||
*
|
||||
* @warning This function must be called only from the callback
|
||||
* FuriHalSerialAsyncRxCallback
|
||||
*
|
||||
* @param handle Serial handle
|
||||
* @return true if data is available for reading, false otherwise
|
||||
*/
|
||||
bool furi_hal_serial_async_rx_available(FuriHalSerialHandle* handle);
|
||||
|
||||
/** Get data Serial receive
|
||||
*
|
||||
* @warning This function must be called only from the callback
|
||||
|
Loading…
Reference in New Issue
Block a user