Nfc: switch to HAL ticks. ApiHal: small cleanup and refactoring. (#609)

This commit is contained in:
あく 2021-07-28 11:45:42 +03:00 committed by GitHub
parent 4c1ac2a13d
commit 1c58de24f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 36 additions and 41 deletions

View File

@ -19,7 +19,6 @@ void nfc_cli_detect(Cli* cli, string_t args, void* context) {
rfalNfcDevice* dev_list;
uint8_t dev_cnt = 0;
bool cmd_exit = false;
api_hal_nfc_init();
api_hal_nfc_exit_sleep();
printf("Detecting nfc...\r\nPress Ctrl+C to abort\r\n");
while(!cmd_exit) {
@ -51,7 +50,6 @@ void nfc_cli_emulate(Cli* cli, string_t args, void* context) {
return;
}
api_hal_nfc_init();
api_hal_nfc_exit_sleep();
printf("Emulating NFC-A Type: T2T UID: CF72D440 SAK: 20 ATQA: 00/04\r\n");
printf("Press Ctrl+C to abort\r\n");

View File

@ -15,9 +15,7 @@ NfcWorker* nfc_worker_alloc() {
nfc_worker->callback = NULL;
nfc_worker->context = NULL;
// Initialize rfal
nfc_worker->error = api_hal_nfc_init();
if(nfc_worker->error == ERR_NONE) {
api_hal_nfc_start_sleep();
if(!api_hal_nfc_is_busy()) {
nfc_worker_change_state(nfc_worker, NfcWorkerStateReady);
} else {
nfc_worker_change_state(nfc_worker, NfcWorkerStateBroken);
@ -35,10 +33,6 @@ NfcWorkerState nfc_worker_get_state(NfcWorker* nfc_worker) {
return nfc_worker->state;
}
ReturnCode nfc_worker_get_error(NfcWorker* nfc_worker) {
return nfc_worker->error;
}
void nfc_worker_start(
NfcWorker* nfc_worker,
NfcWorkerState state,

View File

@ -28,8 +28,6 @@ NfcWorker* nfc_worker_alloc();
NfcWorkerState nfc_worker_get_state(NfcWorker* nfc_worker);
ReturnCode nfc_worker_get_error(NfcWorker* nfc_worker);
void nfc_worker_free(NfcWorker* nfc_worker);
void nfc_worker_start(

View File

@ -26,7 +26,6 @@ struct NfcWorker {
void* context;
NfcWorkerState state;
ReturnCode error;
};
void nfc_worker_change_state(NfcWorker* nfc_worker, NfcWorkerState state);

View File

@ -14,7 +14,7 @@ extern "C" {
/**
* Init nfc
*/
ReturnCode api_hal_nfc_init();
void api_hal_nfc_init();
/**
* Check if nfc worker is busy

View File

@ -1,5 +1,6 @@
#include <api-hal-boot.h>
#include <stm32wbxx_ll_rtc.h>
#include <furi.h>
// Boot request enum
#define BOOT_REQUEST_TAINTED 0x00000000
@ -10,6 +11,7 @@ void api_hal_boot_init() {
#ifndef DEBUG
LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, BOOT_REQUEST_TAINTED);
#endif
FURI_LOG_I("FuriHalBoot", "Init OK");
}
void api_hal_boot_set_mode(ApiHalBootMode mode) {

View File

@ -4,6 +4,8 @@
#include <stm32wbxx_ll_gpio.h>
#include <stm32wbxx_ll_usart.h>
#include <furi.h>
volatile bool api_hal_console_alive = false;
void api_hal_console_init() {
@ -34,6 +36,8 @@ void api_hal_console_init() {
while(!LL_USART_IsActiveFlag_TEACK(USART1)) ;
api_hal_console_alive = true;
FURI_LOG_I("FuriHalConsole", "Init OK");
}
void api_hal_console_tx(const uint8_t* buffer, size_t buffer_size) {

View File

@ -10,6 +10,7 @@ void api_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");
}
void delay_us(float microseconds) {

View File

@ -42,6 +42,7 @@ void api_hal_i2c_init() {
LL_I2C_DisableOwnAddress2(POWER_I2C);
LL_I2C_DisableGeneralCall(POWER_I2C);
LL_I2C_EnableClockStretching(POWER_I2C);
FURI_LOG_I("FuriHalI2C", "Init OK");
}
bool api_hal_i2c_tx(

View File

@ -14,6 +14,7 @@ volatile ApiHalInterruptISR api_hal_dma_channel_isr[API_HAL_INTERRUPT_DMA_COUNT]
void api_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");
}
void api_hal_interrupt_set_timer_isr(TIM_TypeDef* timer, ApiHalInterruptISR isr) {

View File

@ -21,6 +21,7 @@ void api_hal_light_init() {
lp5562_enable();
lp5562_configure();
FURI_LOG_I("FuriHalLight", "Init OK");
}
void api_hal_light_set(Light light, uint8_t value) {

View File

@ -3,20 +3,18 @@
static const uint32_t clocks_in_ms = 64 * 1000;
ReturnCode api_hal_nfc_init() {
// Check if Nfc worker was started
rfalNfcState state = rfalNfcGetState();
if(state == RFAL_NFC_STATE_NOTINIT) {
return rfalNfcInitialize();
} else if(state == RFAL_NFC_STATE_IDLE) {
return ERR_NONE;
void api_hal_nfc_init() {
ReturnCode ret = rfalNfcInitialize();
if(ret == ERR_NONE) {
api_hal_nfc_start_sleep();
FURI_LOG_I("FuriHalNfc", "Init OK");
} else {
return ERR_BUSY;
FURI_LOG_W("FuriHalNfc", "Initialization failed, RFAL returned: %d", ret);
}
}
bool api_hal_nfc_is_busy() {
return rfalNfcGetState() > RFAL_NFC_STATE_IDLE;
return rfalNfcGetState() != RFAL_NFC_STATE_IDLE;
}
void api_hal_nfc_field_on() {

View File

@ -3,8 +3,7 @@
#include <api-hal-power.h>
#include <stm32wbxx_ll_cortex.h>
#include <FreeRTOS.h>
#include <cmsis_os.h>
#include <furi.h>
#define API_HAL_OS_CLK_FREQUENCY 32768
#define API_HAL_OS_TICK_PER_SECOND 1024
@ -42,6 +41,8 @@ void api_hal_os_init() {
osTimerId_t second_timer = osTimerNew(api_hal_os_timer_callback, osTimerPeriodic, NULL, NULL);
osTimerStart(second_timer, 1024);
#endif
FURI_LOG_I("FuriHalOs", "Init OK");
}
void LPTIM2_IRQHandler(void) {

View File

@ -13,6 +13,8 @@
#include <bq27220.h>
#include <bq25896.h>
#include <furi.h>
typedef struct {
volatile uint32_t insomnia;
volatile uint32_t deep_insomnia;
@ -70,6 +72,7 @@ void api_hal_power_init() {
LL_PWR_SMPS_SetMode(LL_PWR_SMPS_STEP_DOWN);
bq27220_init(&cedv);
bq25896_init();
FURI_LOG_I("FuriHalPower", "Init OK");
}
uint16_t api_hal_power_insomnia_level() {

View File

@ -22,6 +22,7 @@ void api_hal_spi_init() {
GpioSpeedVeryHigh
);
}
FURI_LOG_I("FuriHalSpi", "Init OK");
}
void api_hal_spi_bus_lock(const ApiHalSpiBus* bus) {

View File

@ -114,6 +114,7 @@ void api_hal_subghz_init() {
cc1101_shutdown(device);
api_hal_spi_device_return(device);
FURI_LOG_I("FuriHalSubGhz", "Init OK");
}
void api_hal_subghz_sleep() {

View File

@ -29,6 +29,7 @@ void api_hal_vcp_init() {
api_hal_vcp->tx_semaphore = osSemaphoreNew(1, 1, NULL);
api_hal_vcp->alive = false;
api_hal_vcp->underrun = false;
FURI_LOG_I("FuriHalVcp", "Init OK");
}
void _api_hal_vcp_init() {

View File

@ -165,6 +165,7 @@ void api_hal_version_init() {
break;
default: furi_check(0);
}
FURI_LOG_I("FuriHalVersion", "Init OK");
}
bool api_hal_version_do_i_belong_here() {

View File

@ -4,6 +4,8 @@
void api_hal_vibro_init() {
hal_gpio_init(&vibro_gpio, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
hal_gpio_write(&vibro_gpio, false);
FURI_LOG_I("FuriHalVibro", "Init OK");
}
void api_hal_vibro_on(bool value) {

View File

@ -16,11 +16,8 @@
void api_hal_init() {
api_hal_clock_init();
api_hal_console_init();
FURI_LOG_I("FURI_HAL", "CLOCK and CONSOLE OK");
api_hal_interrupt_init();
FURI_LOG_I("FURI_HAL", "INTERRUPT OK");
api_hal_delay_init();
FURI_LOG_I("FURI_HAL", "DELAY OK");
MX_GPIO_Init();
FURI_LOG_I("HAL", "GPIO OK");
@ -28,9 +25,7 @@ void api_hal_init() {
MX_RTC_Init();
FURI_LOG_I("HAL", "RTC OK");
api_hal_boot_init();
FURI_LOG_I("FURI_HAL", "BOOT OK");
api_hal_version_init();
FURI_LOG_I("FURI_HAL", "VERSION OK");
MX_ADC1_Init();
FURI_LOG_I("HAL", "ADC1 OK");
@ -40,7 +35,6 @@ void api_hal_init() {
MX_SPI2_Init();
FURI_LOG_I("HAL", "SPI2 OK");
api_hal_spi_init();
FURI_LOG_I("FURI_HAL", "SPI OK");
MX_TIM1_Init();
FURI_LOG_I("HAL", "TIM1 OK");
@ -65,24 +59,18 @@ void api_hal_init() {
// VCP + USB
api_hal_vcp_init();
FURI_LOG_I("FURI_HAL", "VCP OK");
MX_USB_Device_Init();
FURI_LOG_I("HAL", "USB OK");
api_hal_i2c_init();
FURI_LOG_I("FURI_HAL", "I2C OK");
// High Level
api_hal_power_init();
FURI_LOG_I("FURI_HAL", "POWER OK");
api_hal_light_init();
FURI_LOG_I("FURI_HAL", "LIGHT OK");
api_hal_vibro_init();
FURI_LOG_I("FURI_HAL", "VIBRO OK");
api_hal_subghz_init();
FURI_LOG_I("FURI_HAL", "SUBGHZ OK");
api_hal_nfc_init();
// FreeRTOS glue
api_hal_os_init();
FURI_LOG_I("FURI_HAL", "OS OK");
}

View File

@ -67,7 +67,7 @@ static uint32_t timerStopwatchTick;
/*******************************************************************************/
uint32_t timerCalculateTimer( uint16_t time )
{
return (osKernelGetTickCount() + time);
return (HAL_GetTick() + time);
}
@ -77,7 +77,7 @@ bool timerIsExpired( uint32_t timer )
uint32_t uDiff;
int32_t sDiff;
uDiff = (timer - osKernelGetTickCount()); /* Calculate the diff between the timers */
uDiff = (timer - HAL_GetTick()); /* Calculate the diff between the timers */
sDiff = uDiff; /* Convert the diff to a signed var */
/* Check if the given timer has expired already */
@ -104,13 +104,13 @@ void timerDelay( uint16_t tOut )
/*******************************************************************************/
void timerStopwatchStart( void )
{
timerStopwatchTick = osKernelGetTickCount();
timerStopwatchTick = HAL_GetTick();
}
/*******************************************************************************/
uint32_t timerStopwatchMeasure( void )
{
return (uint32_t)(osKernelGetTickCount() - timerStopwatchTick);
return (uint32_t)(HAL_GetTick() - timerStopwatchTick);
}