2021-08-08 21:03:25 +03:00
|
|
|
#include <furi-hal-console.h>
|
2021-10-26 21:41:56 +03:00
|
|
|
#include <furi-hal-uart.h>
|
2021-07-20 20:14:42 +03:00
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stm32wbxx_ll_gpio.h>
|
|
|
|
#include <stm32wbxx_ll_usart.h>
|
2021-08-19 01:06:18 +03:00
|
|
|
#include <m-string.h>
|
2021-07-20 20:14:42 +03:00
|
|
|
|
2021-11-12 16:04:35 +03:00
|
|
|
#include <utilities_conf.h>
|
|
|
|
|
2021-07-28 11:45:42 +03:00
|
|
|
#include <furi.h>
|
|
|
|
|
2021-11-12 16:04:35 +03:00
|
|
|
#define TAG "FuriHalConsole"
|
|
|
|
|
2021-10-21 21:12:20 +03:00
|
|
|
#define CONSOLE_BAUDRATE 230400
|
|
|
|
|
2021-08-08 21:03:25 +03:00
|
|
|
volatile bool furi_hal_console_alive = false;
|
2021-07-20 20:14:42 +03:00
|
|
|
|
2021-08-08 21:03:25 +03:00
|
|
|
void furi_hal_console_init() {
|
2021-10-26 21:41:56 +03:00
|
|
|
furi_hal_uart_init(FuriHalUartIdUSART1, CONSOLE_BAUDRATE);
|
2021-08-08 21:03:25 +03:00
|
|
|
furi_hal_console_alive = true;
|
2021-07-28 11:45:42 +03:00
|
|
|
|
2021-11-12 16:04:35 +03:00
|
|
|
FURI_LOG_I(TAG, "Init OK");
|
2021-07-20 20:14:42 +03:00
|
|
|
}
|
|
|
|
|
2021-10-26 21:41:56 +03:00
|
|
|
void furi_hal_console_enable() {
|
2021-11-20 01:19:31 +03:00
|
|
|
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, NULL, NULL);
|
2021-10-21 21:12:20 +03:00
|
|
|
while (!LL_USART_IsActiveFlag_TC(USART1));
|
2021-10-26 21:41:56 +03:00
|
|
|
furi_hal_uart_set_br(FuriHalUartIdUSART1, CONSOLE_BAUDRATE);
|
2021-10-21 21:12:20 +03:00
|
|
|
furi_hal_console_alive = true;
|
|
|
|
}
|
|
|
|
|
2021-10-26 21:41:56 +03:00
|
|
|
void furi_hal_console_disable() {
|
|
|
|
while (!LL_USART_IsActiveFlag_TC(USART1));
|
|
|
|
furi_hal_console_alive = false;
|
2021-10-21 21:12:20 +03:00
|
|
|
}
|
|
|
|
|
2021-09-21 12:48:08 +03:00
|
|
|
void furi_hal_console_tx(const uint8_t* buffer, size_t buffer_size) {
|
|
|
|
if (!furi_hal_console_alive)
|
|
|
|
return;
|
|
|
|
|
2021-12-01 01:07:17 +03:00
|
|
|
FURI_CRITICAL_ENTER();
|
2021-09-21 12:48:08 +03:00
|
|
|
// Transmit data
|
2021-10-26 21:41:56 +03:00
|
|
|
furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)buffer, buffer_size);
|
2021-09-21 12:48:08 +03:00
|
|
|
// Wait for TC flag to be raised for last char
|
|
|
|
while (!LL_USART_IsActiveFlag_TC(USART1));
|
2021-12-01 01:07:17 +03:00
|
|
|
FURI_CRITICAL_EXIT();
|
2021-09-21 12:48:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void furi_hal_console_tx_with_new_line(const uint8_t* buffer, size_t buffer_size) {
|
|
|
|
if (!furi_hal_console_alive)
|
|
|
|
return;
|
2021-07-20 20:14:42 +03:00
|
|
|
|
2021-12-01 01:07:17 +03:00
|
|
|
FURI_CRITICAL_ENTER();
|
2021-09-21 12:48:08 +03:00
|
|
|
// Transmit data
|
2021-10-26 21:41:56 +03:00
|
|
|
furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)buffer, buffer_size);
|
2021-09-21 12:48:08 +03:00
|
|
|
// Transmit new line symbols
|
2021-10-26 21:41:56 +03:00
|
|
|
furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)"\r\n", 2);
|
2021-09-21 12:48:08 +03:00
|
|
|
// Wait for TC flag to be raised for last char
|
2021-07-20 20:14:42 +03:00
|
|
|
while (!LL_USART_IsActiveFlag_TC(USART1));
|
2021-12-01 01:07:17 +03:00
|
|
|
FURI_CRITICAL_EXIT();
|
2021-08-19 01:06:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void furi_hal_console_printf(const char format[], ...) {
|
|
|
|
string_t string;
|
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
string_init_vprintf(string, format, args);
|
|
|
|
va_end(args);
|
|
|
|
furi_hal_console_tx((const uint8_t*)string_get_cstr(string), string_size(string));
|
|
|
|
string_clear(string);
|
2021-08-22 13:43:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void furi_hal_console_puts(const char *data) {
|
|
|
|
furi_hal_console_tx((const uint8_t*)data, strlen(data));
|
2021-10-26 21:41:56 +03:00
|
|
|
}
|