mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-12-20 01:33:18 +00:00
338fc3afea
* Updated stack to 1.17.0 * hal: ble: Fixed stack config * Bumped stack version in config * scripts: added validation of copro stack version in update bundles * Copro: update to 1.17.2 * FuriHal: adjust tick frequency for HSE as sys clk * FuriHal: adjust systick reload on sys clock change * Sync api and format sources * scripts: updated ob.data for newer stack * FuriHal: return core2 hse pll transition on deep sleep * FuriHal: cleanup ble glue * FuriHal: rework ble glue, allow shci_send in critical section * FuriHal: sync api symbols * FuriHal: cleanup BLE glue, remove unused garbage and duplicate declarations * FuriHal: BLE glue cleanup, 2nd iteration * FuriHal: hide tick drift reports under FURI_HAL_OS_DEBUG * Lib: sync stm32wb_copro with latest dev * FuriHal: ble-glue, slightly less editable device name and duplicate definition cleanup * FuriHal: update ble config options, enable some optimizations and ext adv * FuriHal: update clock switch method documentation * FuriHal: better SNBRSA bug workaround fix * FuriHal: complete comment about tick skew * FuriHal: proper condition in clock hsi2hse transition * FuriHal: move PLL start to hse2pll routine, fix lockup caused by core2 switching to HSE before us * FuriHal: explicit HSE start before switch * FuriHal: fix documentation and move flash latency change to later stage, remove duplicate LL_RCC_SetRFWKPClockSource call --------- Co-authored-by: hedger <hedger@nanode.su> Co-authored-by: hedger <hedger@users.noreply.github.com>
99 lines
2.7 KiB
C
99 lines
2.7 KiB
C
#include <furi_hal_console.h>
|
|
#include <furi_hal_uart.h>
|
|
|
|
#include <stdbool.h>
|
|
#include <stm32wbxx_ll_gpio.h>
|
|
#include <stm32wbxx_ll_usart.h>
|
|
|
|
#include <furi.h>
|
|
|
|
#define TAG "FuriHalConsole"
|
|
|
|
#ifdef HEAP_PRINT_DEBUG
|
|
#define CONSOLE_BAUDRATE 1843200
|
|
#else
|
|
#define CONSOLE_BAUDRATE 230400
|
|
#endif
|
|
|
|
typedef struct {
|
|
bool alive;
|
|
FuriHalConsoleTxCallback tx_callback;
|
|
void* tx_callback_context;
|
|
} FuriHalConsole;
|
|
|
|
FuriHalConsole furi_hal_console = {
|
|
.alive = false,
|
|
.tx_callback = NULL,
|
|
.tx_callback_context = NULL,
|
|
};
|
|
|
|
void furi_hal_console_init() {
|
|
furi_hal_uart_init(FuriHalUartIdUSART1, CONSOLE_BAUDRATE);
|
|
furi_hal_console.alive = true;
|
|
}
|
|
|
|
void furi_hal_console_enable() {
|
|
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, NULL, NULL);
|
|
while(!LL_USART_IsActiveFlag_TC(USART1))
|
|
;
|
|
furi_hal_uart_set_br(FuriHalUartIdUSART1, CONSOLE_BAUDRATE);
|
|
furi_hal_console.alive = true;
|
|
}
|
|
|
|
void furi_hal_console_disable() {
|
|
while(!LL_USART_IsActiveFlag_TC(USART1))
|
|
;
|
|
furi_hal_console.alive = false;
|
|
}
|
|
|
|
void furi_hal_console_set_tx_callback(FuriHalConsoleTxCallback callback, void* context) {
|
|
FURI_CRITICAL_ENTER();
|
|
furi_hal_console.tx_callback = callback;
|
|
furi_hal_console.tx_callback_context = context;
|
|
FURI_CRITICAL_EXIT();
|
|
}
|
|
|
|
void furi_hal_console_tx(const uint8_t* buffer, size_t buffer_size) {
|
|
if(!furi_hal_console.alive) return;
|
|
|
|
FURI_CRITICAL_ENTER();
|
|
// Transmit data
|
|
|
|
if(furi_hal_console.tx_callback) {
|
|
furi_hal_console.tx_callback(buffer, buffer_size, furi_hal_console.tx_callback_context);
|
|
}
|
|
|
|
furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)buffer, buffer_size);
|
|
// Wait for TC flag to be raised for last char
|
|
while(!LL_USART_IsActiveFlag_TC(USART1))
|
|
;
|
|
FURI_CRITICAL_EXIT();
|
|
}
|
|
|
|
void furi_hal_console_tx_with_new_line(const uint8_t* buffer, size_t buffer_size) {
|
|
if(!furi_hal_console.alive) return;
|
|
|
|
FURI_CRITICAL_ENTER();
|
|
// Transmit data
|
|
furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)buffer, buffer_size);
|
|
// Transmit new line symbols
|
|
furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)"\r\n", 2);
|
|
// Wait for TC flag to be raised for last char
|
|
while(!LL_USART_IsActiveFlag_TC(USART1))
|
|
;
|
|
FURI_CRITICAL_EXIT();
|
|
}
|
|
|
|
void furi_hal_console_printf(const char format[], ...) {
|
|
FuriString* string;
|
|
va_list args;
|
|
va_start(args, format);
|
|
string = furi_string_alloc_vprintf(format, args);
|
|
va_end(args);
|
|
furi_hal_console_tx((const uint8_t*)furi_string_get_cstr(string), furi_string_size(string));
|
|
furi_string_free(string);
|
|
}
|
|
|
|
void furi_hal_console_puts(const char* data) {
|
|
furi_hal_console_tx((const uint8_t*)data, strlen(data));
|
|
}
|