RPC: Add Virtual Display & Unify log tags (#814)
* RPC: Update protobuf sources * RPC: Add Virtual Display * Unify log tags * RPC: Virtual Display placeholder * Rpc: clear frame buffer callback before confirm. * Firmware: full assert for hal, move fatfs initialization to furi hal. * FuriHal: VCP optimizations, thread safe console. Rpc: adjust buffer sizes. Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
#include <stm32wbxx_ll_rtc.h>
|
||||
#include <furi.h>
|
||||
|
||||
#define TAG "FuriHalBoot"
|
||||
|
||||
// Boot request enum
|
||||
#define BOOT_REQUEST_TAINTED 0x00000000
|
||||
#define BOOT_REQUEST_CLEAN 0xDADEDADE
|
||||
@@ -11,7 +13,7 @@ void furi_hal_bootloader_init() {
|
||||
#ifndef DEBUG
|
||||
LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, BOOT_REQUEST_TAINTED);
|
||||
#endif
|
||||
FURI_LOG_I("FuriHalBoot", "Init OK");
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
}
|
||||
|
||||
void furi_hal_bootloader_set_mode(FuriHalBootloaderMode mode) {
|
||||
|
@@ -5,6 +5,8 @@
|
||||
#include <stm32wbxx_ll_rcc.h>
|
||||
#include <stm32wbxx_ll_utils.h>
|
||||
|
||||
#define TAG "FuriHalClock"
|
||||
|
||||
#define HS_CLOCK_IS_READY() (LL_RCC_HSE_IsReady() && LL_RCC_HSI_IsReady())
|
||||
#define LS_CLOCK_IS_READY() (LL_RCC_LSE_IsReady() && LL_RCC_LSI1_IsReady())
|
||||
|
||||
@@ -123,7 +125,7 @@ void furi_hal_clock_init() {
|
||||
// APB2
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
|
||||
|
||||
FURI_LOG_I("FuriHalClock", "Init OK");
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
}
|
||||
|
||||
void furi_hal_clock_switch_to_hsi() {
|
||||
|
@@ -4,6 +4,8 @@
|
||||
#include <lib/heatshrink/heatshrink_encoder.h>
|
||||
#include <lib/heatshrink/heatshrink_decoder.h>
|
||||
|
||||
#define TAG "FuriHalCompress"
|
||||
|
||||
#define FURI_HAL_COMPRESS_ICON_ENCODED_BUFF_SIZE (512)
|
||||
#define FURI_HAL_COMPRESS_ICON_DECODED_BUFF_SIZE (1024)
|
||||
|
||||
@@ -46,7 +48,7 @@ void furi_hal_compress_icon_init() {
|
||||
FURI_HAL_COMPRESS_LOOKAHEAD_BUFF_SIZE_LOG);
|
||||
heatshrink_decoder_reset(icon_decoder->decoder);
|
||||
memset(icon_decoder->decoded_buff, 0, sizeof(icon_decoder->decoded_buff));
|
||||
FURI_LOG_I("FuriHalCompress", "Init OK");
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
}
|
||||
|
||||
void furi_hal_compress_icon_decode(const uint8_t* icon_data, uint8_t** decoded_buff) {
|
||||
|
@@ -6,8 +6,12 @@
|
||||
#include <stm32wbxx_ll_usart.h>
|
||||
#include <m-string.h>
|
||||
|
||||
#include <utilities_conf.h>
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#define TAG "FuriHalConsole"
|
||||
|
||||
#define CONSOLE_BAUDRATE 230400
|
||||
|
||||
volatile bool furi_hal_console_alive = false;
|
||||
@@ -16,7 +20,7 @@ void furi_hal_console_init() {
|
||||
furi_hal_uart_init(FuriHalUartIdUSART1, CONSOLE_BAUDRATE);
|
||||
furi_hal_console_alive = true;
|
||||
|
||||
FURI_LOG_I("FuriHalConsole", "Init OK");
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
}
|
||||
|
||||
void furi_hal_console_enable() {
|
||||
@@ -35,22 +39,26 @@ void furi_hal_console_tx(const uint8_t* buffer, size_t buffer_size) {
|
||||
if (!furi_hal_console_alive)
|
||||
return;
|
||||
|
||||
UTILS_ENTER_CRITICAL_SECTION();
|
||||
// Transmit data
|
||||
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));
|
||||
UTILS_EXIT_CRITICAL_SECTION();
|
||||
}
|
||||
|
||||
void furi_hal_console_tx_with_new_line(const uint8_t* buffer, size_t buffer_size) {
|
||||
if (!furi_hal_console_alive)
|
||||
return;
|
||||
|
||||
UTILS_ENTER_CRITICAL_SECTION();
|
||||
// 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));
|
||||
UTILS_EXIT_CRITICAL_SECTION();
|
||||
}
|
||||
|
||||
void furi_hal_console_printf(const char format[], ...) {
|
||||
|
@@ -3,10 +3,12 @@
|
||||
#include <furi.h>
|
||||
#include <shci.h>
|
||||
|
||||
#define TAG "FuriHalCrypto"
|
||||
|
||||
CRYP_HandleTypeDef crypt;
|
||||
|
||||
void furi_hal_crypto_init() {
|
||||
FURI_LOG_I("FuriHalCrypto", "Init OK");
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
}
|
||||
|
||||
bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot) {
|
||||
|
@@ -3,6 +3,8 @@
|
||||
#include <furi.h>
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
#define TAG "FuriHalDelay"
|
||||
|
||||
static uint32_t clk_per_microsecond;
|
||||
|
||||
void furi_hal_delay_init(void) {
|
||||
@@ -10,7 +12,7 @@ void furi_hal_delay_init(void) {
|
||||
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
||||
DWT->CYCCNT = 0U;
|
||||
clk_per_microsecond = SystemCoreClock / 1000000.0f;
|
||||
FURI_LOG_I("FuriHalDelay", "Init OK");
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
}
|
||||
|
||||
void delay_us(float microseconds) {
|
||||
|
@@ -6,6 +6,8 @@
|
||||
#include <stm32wbxx_ll_cortex.h>
|
||||
#include <furi.h>
|
||||
|
||||
#define TAG "FuriHalI2C"
|
||||
|
||||
osMutexId_t furi_hal_i2c_mutex = NULL;
|
||||
|
||||
void furi_hal_i2c_init() {
|
||||
@@ -42,7 +44,7 @@ void furi_hal_i2c_init() {
|
||||
LL_I2C_DisableOwnAddress2(POWER_I2C);
|
||||
LL_I2C_DisableGeneralCall(POWER_I2C);
|
||||
LL_I2C_EnableClockStretching(POWER_I2C);
|
||||
FURI_LOG_I("FuriHalI2C", "Init OK");
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
}
|
||||
|
||||
bool furi_hal_i2c_tx(
|
||||
|
@@ -4,6 +4,8 @@
|
||||
#include <main.h>
|
||||
#include <stm32wbxx_ll_tim.h>
|
||||
|
||||
#define TAG "FuriHalInterrupt"
|
||||
|
||||
volatile FuriHalInterruptISR furi_hal_tim_tim2_isr = NULL;
|
||||
volatile FuriHalInterruptISR furi_hal_tim_tim1_isr = NULL;
|
||||
|
||||
@@ -22,7 +24,7 @@ void furi_hal_interrupt_init() {
|
||||
NVIC_SetPriority(DMA1_Channel1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
|
||||
NVIC_EnableIRQ(DMA1_Channel1_IRQn);
|
||||
|
||||
FURI_LOG_I("FuriHalInterrupt", "Init OK");
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
}
|
||||
|
||||
void furi_hal_interrupt_set_timer_isr(TIM_TypeDef* timer, FuriHalInterruptISR isr) {
|
||||
@@ -161,10 +163,10 @@ void TAMP_STAMP_LSECSS_IRQHandler(void) {
|
||||
if (LL_RCC_IsActiveFlag_LSECSS()) {
|
||||
LL_RCC_ClearFlag_LSECSS();
|
||||
if (!LL_RCC_LSE_IsReady()) {
|
||||
FURI_LOG_E("FuriHalInterrupt", "LSE CSS fired: resetting system");
|
||||
FURI_LOG_E(TAG, "LSE CSS fired: resetting system");
|
||||
NVIC_SystemReset();
|
||||
} else {
|
||||
FURI_LOG_E("FuriHalInterrupt", "LSE CSS fired: but LSE is alive");
|
||||
FURI_LOG_E(TAG, "LSE CSS fired: but LSE is alive");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -176,7 +178,7 @@ void RCC_IRQHandler(void) {
|
||||
void NMI_Handler(void) {
|
||||
if (LL_RCC_IsActiveFlag_HSECSS()) {
|
||||
LL_RCC_ClearFlag_HSECSS();
|
||||
FURI_LOG_E("FuriHalInterrupt", "HSE CSS fired: resetting system");
|
||||
FURI_LOG_E(TAG, "HSE CSS fired: resetting system");
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,8 @@
|
||||
#include <furi-hal-light.h>
|
||||
#include <lp5562.h>
|
||||
|
||||
#define TAG "FuriHalLight"
|
||||
|
||||
#define LED_CURRENT_RED 50
|
||||
#define LED_CURRENT_GREEN 50
|
||||
#define LED_CURRENT_BLUE 50
|
||||
@@ -21,7 +23,7 @@ void furi_hal_light_init() {
|
||||
|
||||
lp5562_enable();
|
||||
lp5562_configure();
|
||||
FURI_LOG_I("FuriHalLight", "Init OK");
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
}
|
||||
|
||||
void furi_hal_light_set(Light light, uint8_t value) {
|
||||
|
@@ -1,15 +1,17 @@
|
||||
#include "furi-hal-nfc.h"
|
||||
#include <st25r3916.h>
|
||||
|
||||
#define TAG "FuriHalNfc"
|
||||
|
||||
static const uint32_t clocks_in_ms = 64 * 1000;
|
||||
|
||||
void furi_hal_nfc_init() {
|
||||
ReturnCode ret = rfalNfcInitialize();
|
||||
if(ret == ERR_NONE) {
|
||||
furi_hal_nfc_start_sleep();
|
||||
FURI_LOG_I("FuriHalNfc", "Init OK");
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
} else {
|
||||
FURI_LOG_W("FuriHalNfc", "Initialization failed, RFAL returned: %d", ret);
|
||||
FURI_LOG_W(TAG, "Initialization failed, RFAL returned: %d", ret);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +65,7 @@ bool furi_hal_nfc_detect(rfalNfcDevice **dev_list, uint8_t* dev_cnt, uint32_t ti
|
||||
while(state != RFAL_NFC_STATE_ACTIVATED) {
|
||||
rfalNfcWorker();
|
||||
state = rfalNfcGetState();
|
||||
FURI_LOG_D("HAL NFC", "Current state %d", state);
|
||||
FURI_LOG_D(TAG, "Current state %d", state);
|
||||
if(state == RFAL_NFC_STATE_POLL_ACTIVATION) {
|
||||
start = DWT->CYCCNT;
|
||||
continue;
|
||||
@@ -73,7 +75,7 @@ bool furi_hal_nfc_detect(rfalNfcDevice **dev_list, uint8_t* dev_cnt, uint32_t ti
|
||||
}
|
||||
if(DWT->CYCCNT - start > timeout * clocks_in_ms) {
|
||||
rfalNfcDeactivate(true);
|
||||
FURI_LOG_D("HAL NFC", "Timeout");
|
||||
FURI_LOG_D(TAG, "Timeout");
|
||||
return false;
|
||||
}
|
||||
osThreadYield();
|
||||
|
@@ -5,6 +5,8 @@
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#define TAG "FuriHalOs"
|
||||
|
||||
#define FURI_HAL_OS_CLK_FREQUENCY 32768
|
||||
#define FURI_HAL_OS_TICK_PER_SECOND 1024
|
||||
#define FURI_HAL_OS_CLK_PER_TICK (FURI_HAL_OS_CLK_FREQUENCY / FURI_HAL_OS_TICK_PER_SECOND)
|
||||
@@ -44,7 +46,7 @@ void furi_hal_os_init() {
|
||||
osTimerStart(second_timer, 1024);
|
||||
#endif
|
||||
|
||||
FURI_LOG_I("FuriHalOs", "Init OK");
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
}
|
||||
|
||||
void LPTIM2_IRQHandler(void) {
|
||||
|
@@ -15,6 +15,8 @@
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#define TAG "FuriHalPower"
|
||||
|
||||
typedef struct {
|
||||
volatile uint8_t insomnia;
|
||||
volatile uint8_t deep_insomnia;
|
||||
@@ -74,7 +76,7 @@ void furi_hal_power_init() {
|
||||
LL_PWR_SMPS_SetMode(LL_PWR_SMPS_STEP_DOWN);
|
||||
bq27220_init(&cedv);
|
||||
bq25896_init();
|
||||
FURI_LOG_I("FuriHalPower", "Init OK");
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
}
|
||||
|
||||
uint16_t furi_hal_power_insomnia_level() {
|
||||
|
@@ -104,7 +104,7 @@ void furi_hal_rfid_tim_read(float freq, float duty_cycle) {
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
|
||||
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
||||
if(HAL_TIM_OC_ConfigChannel(&LFRFID_READ_TIM, &sConfigOC, LFRFID_READ_CHANNEL) != HAL_OK) {
|
||||
if(HAL_TIM_PWM_ConfigChannel(&LFRFID_READ_TIM, &sConfigOC, LFRFID_READ_CHANNEL) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
@@ -142,7 +142,6 @@ void furi_hal_rfid_tim_emulate(float freq) {
|
||||
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
|
||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||
TIM_OC_InitTypeDef sConfigOC = {0};
|
||||
TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
|
||||
|
||||
// basic PWM setup with needed freq and internal clock
|
||||
LFRFID_EMULATE_TIM.Init.Prescaler = prescaler;
|
||||
@@ -182,24 +181,6 @@ void furi_hal_rfid_tim_emulate(float freq) {
|
||||
HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
// no deadtime
|
||||
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
|
||||
sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
|
||||
sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
|
||||
sBreakDeadTimeConfig.DeadTime = 0;
|
||||
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
|
||||
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
|
||||
sBreakDeadTimeConfig.BreakFilter = 0;
|
||||
sBreakDeadTimeConfig.BreakAFMode = TIM_BREAK_AFMODE_INPUT;
|
||||
sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE;
|
||||
sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH;
|
||||
sBreakDeadTimeConfig.Break2Filter = 0;
|
||||
sBreakDeadTimeConfig.Break2AFMode = TIM_BREAK_AFMODE_INPUT;
|
||||
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
|
||||
if(HAL_TIMEx_ConfigBreakDeadTime(&LFRFID_EMULATE_TIM, &sBreakDeadTimeConfig) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
void furi_hal_rfid_tim_emulate_start() {
|
||||
|
@@ -9,6 +9,8 @@
|
||||
#include <stm32wbxx_ll_utils.h>
|
||||
#include <stm32wbxx_ll_cortex.h>
|
||||
|
||||
#define TAG "FuriHalSpi"
|
||||
|
||||
void furi_hal_spi_init() {
|
||||
// Spi structure is const, but mutex is not
|
||||
// Need some hell-ish casting to make it work
|
||||
@@ -33,7 +35,7 @@ void furi_hal_spi_init() {
|
||||
hal_gpio_init_ex(&gpio_spi_d_mosi, GpioModeAltFunctionPushPull, GpioPullUp, GpioSpeedVeryHigh, GpioAltFn5SPI2);
|
||||
hal_gpio_init_ex(&gpio_spi_d_sck, GpioModeAltFunctionPushPull, GpioPullUp, GpioSpeedVeryHigh, GpioAltFn5SPI2);
|
||||
|
||||
FURI_LOG_I("FuriHalSpi", "Init OK");
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
}
|
||||
|
||||
void furi_hal_spi_bus_lock(const FuriHalSpiBus* bus) {
|
||||
|
@@ -10,6 +10,8 @@
|
||||
#include <cc1101.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define TAG "FuriHalSubGhz"
|
||||
|
||||
static volatile SubGhzState furi_hal_subghz_state = SubGhzStateInit;
|
||||
static volatile SubGhzRegulation furi_hal_subghz_regulation = SubGhzRegulationTxRx;
|
||||
|
||||
@@ -303,7 +305,7 @@ void furi_hal_subghz_init() {
|
||||
cc1101_shutdown(device);
|
||||
|
||||
furi_hal_spi_device_return(device);
|
||||
FURI_LOG_I("FuriHalSubGhz", "Init OK");
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
}
|
||||
|
||||
void furi_hal_subghz_sleep() {
|
||||
|
@@ -5,6 +5,8 @@
|
||||
|
||||
#include "usb.h"
|
||||
|
||||
#define TAG "FuriHalUsb"
|
||||
|
||||
#define USB_RECONNECT_DELAY 500
|
||||
|
||||
extern struct UsbInterface usb_cdc_single;
|
||||
@@ -64,7 +66,7 @@ void furi_hal_usb_init(void) {
|
||||
HAL_NVIC_SetPriority(USB_LP_IRQn, 5, 0);
|
||||
NVIC_EnableIRQ(USB_LP_IRQn);
|
||||
|
||||
FURI_LOG_I("FuriHalUsb", "Init OK");
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
}
|
||||
|
||||
void furi_hal_usb_set_config(UsbMode new_mode) {
|
||||
@@ -81,7 +83,7 @@ void furi_hal_usb_set_config(UsbMode new_mode) {
|
||||
usb_if_modes[usb_config.mode_cur]->deinit(&udev);
|
||||
if (usb_if_modes[new_mode] != NULL) {
|
||||
usb_if_modes[new_mode]->init(&udev, usb_if_modes[new_mode]);
|
||||
FURI_LOG_I("FuriHalUsb", "USB mode change %u -> %u", usb_config.mode_cur, new_mode);
|
||||
FURI_LOG_I(TAG, "USB mode change %u -> %u", usb_config.mode_cur, new_mode);
|
||||
usb_config.enabled = true;
|
||||
usb_config.mode_cur = new_mode;
|
||||
}
|
||||
@@ -98,7 +100,7 @@ void furi_hal_usb_disable() {
|
||||
susp_evt(&udev, 0, 0);
|
||||
usbd_connect(&udev, false);
|
||||
usb_config.enabled = false;
|
||||
FURI_LOG_I("FuriHalUsb", "USB Disable");
|
||||
FURI_LOG_I(TAG, "USB Disable");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +108,7 @@ void furi_hal_usb_enable() {
|
||||
if ((!usb_config.enabled) && (usb_if_modes[usb_config.mode_cur] != NULL)) {
|
||||
usbd_connect(&udev, true);
|
||||
usb_config.enabled = true;
|
||||
FURI_LOG_I("FuriHalUsb", "USB Enable");
|
||||
FURI_LOG_I(TAG, "USB Enable");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,8 +1,10 @@
|
||||
#include <furi-hal-usb-cdc_i.h>
|
||||
|
||||
#include <furi-hal-console.h>
|
||||
#include <furi.h>
|
||||
#include <stream_buffer.h>
|
||||
|
||||
#define TAG "FuriHalVcp"
|
||||
|
||||
#define USB_CDC_PKT_LEN CDC_DATA_SZ
|
||||
#define VCP_RX_BUF_SIZE (USB_CDC_PKT_LEN * 3)
|
||||
#define VCP_TX_BUF_SIZE (USB_CDC_PKT_LEN * 3)
|
||||
@@ -17,11 +19,11 @@ typedef enum {
|
||||
VcpEvtDisable = (1 << 4),
|
||||
VcpEvtRx = (1 << 5),
|
||||
VcpEvtTx = (1 << 6),
|
||||
VcpEvtRxDone = (1 << 7),
|
||||
VcpEvtTxDone = (1 << 8),
|
||||
VcpEvtStreamRx = (1 << 7),
|
||||
VcpEvtStreamTx = (1 << 8),
|
||||
} WorkerEvtFlags;
|
||||
|
||||
#define VCP_THREAD_FLAG_ALL (VcpEvtConnect | VcpEvtDisconnect | VcpEvtEnable | VcpEvtDisable | VcpEvtRx | VcpEvtTx | VcpEvtRxDone | VcpEvtTxDone)
|
||||
#define VCP_THREAD_FLAG_ALL (VcpEvtConnect | VcpEvtDisconnect | VcpEvtEnable | VcpEvtDisable | VcpEvtRx | VcpEvtTx | VcpEvtStreamRx | VcpEvtStreamTx)
|
||||
|
||||
typedef struct {
|
||||
FuriThread* thread;
|
||||
@@ -62,61 +64,69 @@ void furi_hal_vcp_init() {
|
||||
|
||||
vcp->thread = furi_thread_alloc();
|
||||
furi_thread_set_name(vcp->thread, "VcpWorker");
|
||||
furi_thread_set_stack_size(vcp->thread, 512);
|
||||
furi_thread_set_stack_size(vcp->thread, 1024);
|
||||
furi_thread_set_callback(vcp->thread, vcp_worker);
|
||||
furi_thread_start(vcp->thread);
|
||||
|
||||
FURI_LOG_I("FuriHalVcp", "Init OK");
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
}
|
||||
|
||||
static int32_t vcp_worker(void* context) {
|
||||
bool enabled = true;
|
||||
bool tx_idle = false;
|
||||
bool rx_pending = false;
|
||||
size_t missed_rx = 0;
|
||||
|
||||
furi_hal_cdc_set_callbacks(VCP_IF_NUM, &cdc_cb);
|
||||
|
||||
|
||||
while (1) {
|
||||
uint32_t flags = osThreadFlagsWait(VCP_THREAD_FLAG_ALL, osFlagsWaitAny, osWaitForever);
|
||||
furi_assert((flags & osFlagsError) == 0);
|
||||
|
||||
// New data received
|
||||
if((flags & VcpEvtRxDone) && enabled) {
|
||||
if((flags & VcpEvtStreamRx) && enabled && missed_rx > 0) {
|
||||
#ifdef FURI_HAL_USB_VCP_DEBUG
|
||||
furi_hal_console_puts("VCP StreamRx\r\n");
|
||||
#endif
|
||||
if (xStreamBufferSpacesAvailable(vcp->rx_stream) >= USB_CDC_PKT_LEN) {
|
||||
size_t len = furi_hal_cdc_receive(VCP_IF_NUM, vcp->data_buffer, USB_CDC_PKT_LEN);
|
||||
if (len > 0)
|
||||
xStreamBufferSend(vcp->rx_stream, vcp->data_buffer, len, osWaitForever);
|
||||
else
|
||||
rx_pending = false;
|
||||
} else
|
||||
rx_pending = true; // Buffer is full, retry later
|
||||
flags |= VcpEvtRx;
|
||||
missed_rx--;
|
||||
}
|
||||
}
|
||||
|
||||
// Rx buffer was read, maybe there is enough space for new data?
|
||||
if((flags & VcpEvtRx) && rx_pending) {
|
||||
if((flags & VcpEvtRx)) {
|
||||
if (xStreamBufferSpacesAvailable(vcp->rx_stream) >= USB_CDC_PKT_LEN) {
|
||||
size_t len = furi_hal_cdc_receive(VCP_IF_NUM, vcp->data_buffer, USB_CDC_PKT_LEN);
|
||||
if (len > 0)
|
||||
xStreamBufferSend(vcp->rx_stream, vcp->data_buffer, len, osWaitForever);
|
||||
else
|
||||
rx_pending = false;
|
||||
int32_t len = furi_hal_cdc_receive(VCP_IF_NUM, vcp->data_buffer, USB_CDC_PKT_LEN);
|
||||
#ifdef FURI_HAL_USB_VCP_DEBUG
|
||||
furi_hal_console_printf("VCP Rx %d\r\n", len);
|
||||
#endif
|
||||
if (len > 0) {
|
||||
furi_check(xStreamBufferSend(vcp->rx_stream, vcp->data_buffer, len, osWaitForever) == len);
|
||||
}
|
||||
} else {
|
||||
#ifdef FURI_HAL_USB_VCP_DEBUG
|
||||
furi_hal_console_puts("VCP Rx missed\r\n");
|
||||
#endif
|
||||
missed_rx++;
|
||||
}
|
||||
}
|
||||
|
||||
// New data in Tx buffer
|
||||
if((flags & VcpEvtTx) && enabled) {
|
||||
if((flags & VcpEvtStreamTx) && enabled) {
|
||||
#ifdef FURI_HAL_USB_VCP_DEBUG
|
||||
furi_hal_console_puts("VCP StreamTx\r\n");
|
||||
#endif
|
||||
if (tx_idle) {
|
||||
size_t len = xStreamBufferReceive(vcp->tx_stream, vcp->data_buffer, USB_CDC_PKT_LEN, 0);
|
||||
if (len > 0) {
|
||||
tx_idle = false;
|
||||
furi_hal_cdc_send(VCP_IF_NUM, vcp->data_buffer, len);
|
||||
}
|
||||
flags |= VcpEvtTx;
|
||||
}
|
||||
}
|
||||
|
||||
// CDC write transfer done
|
||||
if((flags & VcpEvtTxDone) && enabled) {
|
||||
if((flags & VcpEvtTx) && enabled) {
|
||||
size_t len = xStreamBufferReceive(vcp->tx_stream, vcp->data_buffer, USB_CDC_PKT_LEN, 0);
|
||||
#ifdef FURI_HAL_USB_VCP_DEBUG
|
||||
furi_hal_console_printf("VCP Tx %d\r\n", len);
|
||||
#endif
|
||||
if (len > 0) { // Some data left in Tx buffer. Sending it now
|
||||
tx_idle = false;
|
||||
furi_hal_cdc_send(VCP_IF_NUM, vcp->data_buffer, len);
|
||||
@@ -127,6 +137,9 @@ static int32_t vcp_worker(void* context) {
|
||||
|
||||
// VCP session opened
|
||||
if((flags & VcpEvtConnect) && enabled) {
|
||||
#ifdef FURI_HAL_USB_VCP_DEBUG
|
||||
furi_hal_console_puts("VCP Connect\r\n");
|
||||
#endif
|
||||
if (vcp->connected == false) {
|
||||
vcp->connected = true;
|
||||
xStreamBufferSend(vcp->rx_stream, &ascii_soh, 1, osWaitForever);
|
||||
@@ -135,6 +148,9 @@ static int32_t vcp_worker(void* context) {
|
||||
|
||||
// VCP session closed
|
||||
if((flags & VcpEvtDisconnect) && enabled) {
|
||||
#ifdef FURI_HAL_USB_VCP_DEBUG
|
||||
furi_hal_console_puts("VCP Disconnect\r\n");
|
||||
#endif
|
||||
if (vcp->connected == true) {
|
||||
vcp->connected = false;
|
||||
xStreamBufferSend(vcp->rx_stream, &ascii_eot, 1, osWaitForever);
|
||||
@@ -143,6 +159,9 @@ static int32_t vcp_worker(void* context) {
|
||||
|
||||
// VCP enabled
|
||||
if((flags & VcpEvtEnable) && !enabled){
|
||||
#ifdef FURI_HAL_USB_VCP_DEBUG
|
||||
furi_hal_console_puts("VCP Enable\r\n");
|
||||
#endif
|
||||
furi_hal_cdc_set_callbacks(VCP_IF_NUM, &cdc_cb);
|
||||
enabled = true;
|
||||
furi_hal_cdc_receive(VCP_IF_NUM, vcp->data_buffer, USB_CDC_PKT_LEN); // flush Rx buffer
|
||||
@@ -154,6 +173,9 @@ static int32_t vcp_worker(void* context) {
|
||||
|
||||
// VCP disabled
|
||||
if((flags & VcpEvtDisable) && enabled) {
|
||||
#ifdef FURI_HAL_USB_VCP_DEBUG
|
||||
furi_hal_console_puts("VCP Disable\r\n");
|
||||
#endif
|
||||
enabled = false;
|
||||
vcp->connected = false;
|
||||
xStreamBufferSend(vcp->rx_stream, &ascii_eot, 1, osWaitForever);
|
||||
@@ -182,9 +204,9 @@ size_t furi_hal_vcp_rx_with_timeout(uint8_t* buffer, size_t size, uint32_t timeo
|
||||
batch_size = VCP_RX_BUF_SIZE;
|
||||
|
||||
size_t len = xStreamBufferReceive(vcp->rx_stream, buffer, batch_size, timeout);
|
||||
osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtRx);
|
||||
if (len == 0)
|
||||
break;
|
||||
osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtStreamRx);
|
||||
size -= len;
|
||||
buffer += len;
|
||||
rx_cnt += len;
|
||||
@@ -207,7 +229,7 @@ void furi_hal_vcp_tx(const uint8_t* buffer, size_t size) {
|
||||
batch_size = VCP_TX_BUF_SIZE;
|
||||
|
||||
xStreamBufferSend(vcp->tx_stream, buffer, batch_size, osWaitForever);
|
||||
osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtTx);
|
||||
osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtStreamTx);
|
||||
|
||||
size -= batch_size;
|
||||
buffer += batch_size;
|
||||
@@ -215,6 +237,9 @@ void furi_hal_vcp_tx(const uint8_t* buffer, size_t size) {
|
||||
}
|
||||
|
||||
static void vcp_state_callback(uint8_t state) {
|
||||
#ifdef FURI_HAL_USB_VCP_DEBUG
|
||||
furi_hal_console_puts("VCP State\r\n");
|
||||
#endif
|
||||
if (state == 0) {
|
||||
osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtDisconnect);
|
||||
}
|
||||
@@ -223,7 +248,9 @@ static void vcp_state_callback(uint8_t state) {
|
||||
static void vcp_on_cdc_control_line(uint8_t state) {
|
||||
// bit 0: DTR state, bit 1: RTS state
|
||||
bool dtr = state & (1 << 0);
|
||||
|
||||
#ifdef FURI_HAL_USB_VCP_DEBUG
|
||||
furi_hal_console_puts("VCP CtrlLine\r\n");
|
||||
#endif
|
||||
if (dtr == true) {
|
||||
osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtConnect);
|
||||
} else {
|
||||
@@ -232,12 +259,12 @@ static void vcp_on_cdc_control_line(uint8_t state) {
|
||||
}
|
||||
|
||||
static void vcp_on_cdc_rx() {
|
||||
uint32_t ret = osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtRxDone);
|
||||
uint32_t ret = osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtRx);
|
||||
furi_assert((ret & osFlagsError) == 0);
|
||||
}
|
||||
|
||||
static void vcp_on_cdc_tx_complete() {
|
||||
osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtTxDone);
|
||||
osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtTx);
|
||||
}
|
||||
|
||||
bool furi_hal_vcp_is_connected(void) {
|
||||
|
@@ -7,6 +7,8 @@
|
||||
#include <stdio.h>
|
||||
#include "ble.h"
|
||||
|
||||
#define TAG "FuriHalVersion"
|
||||
|
||||
#define FURI_HAL_VERSION_OTP_HEADER_MAGIC 0xBABE
|
||||
#define FURI_HAL_VERSION_OTP_ADDRESS OTP_AREA_BASE
|
||||
|
||||
@@ -191,7 +193,7 @@ void furi_hal_version_init() {
|
||||
break;
|
||||
default: furi_crash(NULL);
|
||||
}
|
||||
FURI_LOG_I("FuriHalVersion", "Init OK");
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
}
|
||||
|
||||
bool furi_hal_version_do_i_belong_here() {
|
||||
|
@@ -1,10 +1,12 @@
|
||||
#include <furi-hal-vibro.h>
|
||||
#include <furi-hal-gpio.h>
|
||||
|
||||
#define TAG "FuriHalVibro"
|
||||
|
||||
void furi_hal_vibro_init() {
|
||||
hal_gpio_init(&vibro_gpio, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
hal_gpio_write(&vibro_gpio, false);
|
||||
FURI_LOG_I("FuriHalVibro", "Init OK");
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
|
||||
}
|
||||
|
||||
|
@@ -7,6 +7,10 @@
|
||||
|
||||
#include <stm32wbxx_ll_cortex.h>
|
||||
|
||||
#include <fatfs.h>
|
||||
|
||||
#define TAG "FuriHal"
|
||||
|
||||
void furi_hal_init() {
|
||||
furi_hal_clock_init();
|
||||
furi_hal_console_init();
|
||||
@@ -14,23 +18,23 @@ void furi_hal_init() {
|
||||
furi_hal_delay_init();
|
||||
|
||||
MX_GPIO_Init();
|
||||
FURI_LOG_I("HAL", "GPIO OK");
|
||||
FURI_LOG_I(TAG, "GPIO OK");
|
||||
|
||||
MX_RTC_Init();
|
||||
FURI_LOG_I("HAL", "RTC OK");
|
||||
FURI_LOG_I(TAG, "RTC OK");
|
||||
furi_hal_bootloader_init();
|
||||
furi_hal_version_init();
|
||||
|
||||
furi_hal_spi_init();
|
||||
|
||||
MX_TIM1_Init();
|
||||
FURI_LOG_I("HAL", "TIM1 OK");
|
||||
FURI_LOG_I(TAG, "TIM1 OK");
|
||||
MX_TIM2_Init();
|
||||
FURI_LOG_I("HAL", "TIM2 OK");
|
||||
FURI_LOG_I(TAG, "TIM2 OK");
|
||||
MX_TIM16_Init();
|
||||
FURI_LOG_I("HAL", "TIM16 OK");
|
||||
FURI_LOG_I(TAG, "TIM16 OK");
|
||||
MX_COMP1_Init();
|
||||
FURI_LOG_I("HAL", "COMP1 OK");
|
||||
FURI_LOG_I(TAG, "COMP1 OK");
|
||||
|
||||
furi_hal_crypto_init();
|
||||
|
||||
@@ -38,7 +42,7 @@ void furi_hal_init() {
|
||||
furi_hal_usb_init();
|
||||
furi_hal_usb_set_config(UsbModeVcpSingle);
|
||||
furi_hal_vcp_init();
|
||||
FURI_LOG_I("HAL", "USB OK");
|
||||
FURI_LOG_I(TAG, "USB OK");
|
||||
|
||||
furi_hal_i2c_init();
|
||||
|
||||
@@ -55,6 +59,10 @@ void furi_hal_init() {
|
||||
// FreeRTOS glue
|
||||
furi_hal_os_init();
|
||||
|
||||
// FatFS driver initialization
|
||||
MX_FATFS_Init();
|
||||
FURI_LOG_I(TAG, "FATFS OK");
|
||||
|
||||
// Partial null pointer dereference protection
|
||||
LL_MPU_Disable();
|
||||
LL_MPU_ConfigRegion(
|
||||
|
Reference in New Issue
Block a user