flipperzero-firmware/firmware/targets/f6/furi-hal/furi-hal-console.c
SG 9d38f28de7
[FL-1682] Faster file receiving function. Storage management scripts. (#647)
* Storage-cli: the file write function is splitted into a function for working with text and function for raw data
* Storage-cli: read_chunks, renamed write_raw to write_chunk
* Storage-cli: fix typo
* SD Hal: fixed wrong read/write block address
* HAL-console: printf
* Storage benchmark: more popular sizes
* Toolbox: md5
* Storage-cli: better read_chunks function, md5 hash function
* Notification: fixed incorrect error message when loading settings
* Storage-cli: stat command
* Storage-cli: stat, "/" is also storage
* Scripts: add storage managment script
* Scripts, storage lib: send command with known response syntax instead of SOH
* Scripts: python3 from env
* Storage-cli: fixed mess with error texts
* Storage-cli: write, show welcome message only if we didn't have any errors
* Storage: poorly fixed folders copying
* Storage: close an old file if an error occurred while opening a new file
* Storage-cli: fixed storage info spacing
* Scripts: use positional arguments in storage.
* Scripts: explicit string encoding and decoding, documentation in comments.

Co-authored-by: あく <alleteam@gmail.com>
2021-08-19 01:06:18 +03:00

69 lines
2.1 KiB
C

#include <furi-hal-console.h>
#include <stdbool.h>
#include <stm32wbxx_ll_gpio.h>
#include <stm32wbxx_ll_usart.h>
#include <m-string.h>
#include <furi.h>
volatile bool furi_hal_console_alive = false;
void furi_hal_console_init() {
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
GPIO_InitStruct.Pin = LL_GPIO_PIN_6|LL_GPIO_PIN_7;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
GPIO_InitStruct.Alternate = LL_GPIO_AF_7;
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
LL_USART_InitTypeDef USART_InitStruct = {0};
USART_InitStruct.PrescalerValue = LL_USART_PRESCALER_DIV1;
USART_InitStruct.BaudRate = 230400;
USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
USART_InitStruct.Parity = LL_USART_PARITY_NONE;
USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX;
USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
USART_InitStruct.OverSampling = LL_USART_OVERSAMPLING_16;
LL_USART_Init(USART1, &USART_InitStruct);
LL_USART_SetTXFIFOThreshold(USART1, LL_USART_FIFOTHRESHOLD_1_2);
LL_USART_EnableFIFO(USART1);
LL_USART_ConfigAsyncMode(USART1);
LL_USART_Enable(USART1);
while(!LL_USART_IsActiveFlag_TEACK(USART1)) ;
furi_hal_console_alive = true;
FURI_LOG_I("FuriHalConsole", "Init OK");
}
void furi_hal_console_tx(const uint8_t* buffer, size_t buffer_size) {
if (!furi_hal_console_alive)
return;
while(buffer_size > 0) {
while (!LL_USART_IsActiveFlag_TXE(USART1));
LL_USART_TransmitData8(USART1, *buffer);
buffer++;
buffer_size--;
}
/* Wait for TC flag to be raised for last char */
while (!LL_USART_IsActiveFlag_TC(USART1));
}
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);
}