[FL-3669] Expansion module protocol (#3250)

* ApiSymbols: add furi_record_destroy
* FuriHal: cleanup serial API, add logging configuration in RTC
* FuriHal: hide private part in _i header. Toolbox: cleanup value index. SystemSettings: logging device and baudrate.
* FuriHal: RTC logging method documentation
* Synchronize API Symbols
* Furi: mark HEAP_PRINT_DEBUG as broken
* FuriHal: furi_hal_serial, add custom IRQ func
* Fix PR review issues
* Implement basic external module detection and echo
* Update api symbols for f18
* Minimally working implementation (can create directory via rpc)
* Make expansion protocol parser a header-only library
* Rename a function
* Improve thread syncronisation
* Implement multi-packet transmissions
* Improve test application
* Clean up expansion worker code
* Send heartbeat when host is ready
* Update API symbols
* Add draft documentation
* Expansion worker: proper timeout and error handling
* Expansion worker: correct TX, do not disable expansion callback
* Expansion protocol: pc side test script
* PC side expansion test: trying to change baudrate
* Working comms between 2 flippers
* Cleaner exit from expansion worker thread
* Better checks
* Add debug logs
* Remove unneeded delays
* Use USART as default expansion port
* Refactor furi_hal_serial_control, fix crash
* Improve furi_hal abstraction, wait for stable rx pin
* Remove rogue include
* Set proper exit reason on RPC error
* Remove rogue comment
* Remove RX stability check as potentially problematic
* Improve expansion_test application
* Remove rogue define
* Give up on TODO
* Implement expansion protocol checksum support
* Update ExpansionModules.md
* RPC: reverse input
* Assets: sync protobuf
* Fix typos
* FuriHal: UART add reception DMA (#3220)
* FuriHal: add DMA serial rx mode
* usb_uart_bridge: switch to working with DMA
* Sync api symbol versions
* FuriHal: update serial docs and api
* FuriHal: Selial added similar API for simple reception mode as with DMA
* FuriHal: Update API target H18
* API: ver API H7
* FuriHal: Serial error processing
* FuriHal: fix furi_hal_serial set baudrate
* Sync api symbols
* FuriHal: cleanup serial isr and various flag handling procedures
* FuriHal: cleanup and simplify serial API
* Debug: update UART Echo serial related flags
* FuriHal: update serial API symbols naming
* Make expansion_test compile
* Remove unneeded file
* Make PVS-studio happy
* Optimise stack usage
* Optimise heap usage, improve api signature
* Fix typo
* Clean up code
* Update expansion_protocol.h
* Fix unit tests
* Add doxygen comments to expansion.h
* Update/add doxygen comments
* Update ExpansionModules.md
* Github: new global code owner
* FuriHal: naming in serial control
* Expansion: check mutex acquire return result

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
Co-authored-by: hedger <hedger@users.noreply.github.com>
Co-authored-by: SkorP <skorpionm@yandex.ru>
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: Skorpionm <85568270+Skorpionm@users.noreply.github.com>
This commit is contained in:
Georgii Surkov
2024-01-16 09:18:56 +00:00
committed by GitHub
parent f9f67e6d54
commit 95737958ad
30 changed files with 2279 additions and 114 deletions

View File

@@ -31,6 +31,59 @@ typedef struct {
void* context;
} FuriHalSerial;
typedef void (*FuriHalSerialControlFunc)(USART_TypeDef*);
typedef struct {
USART_TypeDef* periph;
GpioAltFn alt_fn;
const GpioPin* gpio[FuriHalSerialDirectionMax];
FuriHalSerialControlFunc enable[FuriHalSerialDirectionMax];
FuriHalSerialControlFunc disable[FuriHalSerialDirectionMax];
} FuriHalSerialConfig;
static const FuriHalSerialConfig furi_hal_serial_config[FuriHalSerialIdMax] = {
[FuriHalSerialIdUsart] =
{
.periph = USART1,
.alt_fn = GpioAltFn7USART1,
.gpio =
{
[FuriHalSerialDirectionTx] = &gpio_usart_tx,
[FuriHalSerialDirectionRx] = &gpio_usart_rx,
},
.enable =
{
[FuriHalSerialDirectionTx] = LL_USART_EnableDirectionTx,
[FuriHalSerialDirectionRx] = LL_USART_EnableDirectionRx,
},
.disable =
{
[FuriHalSerialDirectionTx] = LL_USART_DisableDirectionTx,
[FuriHalSerialDirectionRx] = LL_USART_DisableDirectionRx,
},
},
[FuriHalSerialIdLpuart] =
{
.periph = LPUART1,
.alt_fn = GpioAltFn8LPUART1,
.gpio =
{
[FuriHalSerialDirectionTx] = &gpio_ext_pc1,
[FuriHalSerialDirectionRx] = &gpio_ext_pc0,
},
.enable =
{
[FuriHalSerialDirectionTx] = LL_LPUART_EnableDirectionTx,
[FuriHalSerialDirectionRx] = LL_LPUART_EnableDirectionRx,
},
.disable =
{
[FuriHalSerialDirectionTx] = LL_LPUART_DisableDirectionTx,
[FuriHalSerialDirectionRx] = LL_LPUART_DisableDirectionRx,
},
},
};
static FuriHalSerial furi_hal_serial[FuriHalSerialIdMax] = {0};
static size_t furi_hal_serial_dma_bytes_available(FuriHalSerialId ch);
@@ -451,6 +504,11 @@ void furi_hal_serial_init(FuriHalSerialHandle* handle, uint32_t baud) {
}
}
bool furi_hal_serial_is_baud_rate_supported(FuriHalSerialHandle* handle, uint32_t baud) {
furi_check(handle);
return baud >= 9600UL && baud <= 4000000UL;
}
static uint32_t furi_hal_serial_get_prescaler(FuriHalSerialHandle* handle, uint32_t baud) {
uint32_t uartclk = LL_RCC_GetUSARTClockFreq(LL_RCC_USART1_CLKSOURCE);
uint32_t divisor = (uartclk / baud);
@@ -836,3 +894,44 @@ void furi_hal_serial_dma_rx_stop(FuriHalSerialHandle* handle) {
furi_hal_serial_event_deinit(handle);
furi_hal_serial_dma_configure(handle, NULL, NULL);
}
void furi_hal_serial_enable_direction(
FuriHalSerialHandle* handle,
FuriHalSerialDirection direction) {
furi_check(handle);
furi_check(handle->id < FuriHalSerialIdMax);
furi_check(direction < FuriHalSerialDirectionMax);
USART_TypeDef* periph = furi_hal_serial_config[handle->id].periph;
furi_hal_serial_config[handle->id].enable[direction](periph);
const GpioPin* gpio = furi_hal_serial_config[handle->id].gpio[direction];
const GpioAltFn alt_fn = furi_hal_serial_config[handle->id].alt_fn;
furi_hal_gpio_init_ex(
gpio, GpioModeAltFunctionPushPull, GpioPullUp, GpioSpeedVeryHigh, alt_fn);
}
void furi_hal_serial_disable_direction(
FuriHalSerialHandle* handle,
FuriHalSerialDirection direction) {
furi_check(handle);
furi_check(handle->id < FuriHalSerialIdMax);
furi_check(direction < FuriHalSerialDirectionMax);
USART_TypeDef* periph = furi_hal_serial_config[handle->id].periph;
furi_hal_serial_config[handle->id].disable[direction](periph);
const GpioPin* gpio = furi_hal_serial_config[handle->id].gpio[direction];
furi_hal_gpio_init(gpio, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
}
const GpioPin*
furi_hal_serial_get_gpio_pin(FuriHalSerialHandle* handle, FuriHalSerialDirection direction) {
furi_check(handle);
furi_check(handle->id < FuriHalSerialIdMax);
furi_check(direction < FuriHalSerialDirectionMax);
return furi_hal_serial_config[handle->id].gpio[direction];
}