FuriHal: replace HAL with LL in RFID Part 1. Drop F6. (#1049)
* FuriHal: new speaker HAL * FuriHal: drop PWM * FuriHal: move COMP1 to LL * FuriHal: move COMP1 to LL backport to F6 * FuriHal: remove missing gpio_rfid_carrier from F6 * FurHal: use LL for system controls in flash HAL * Drop F6 source tree * Drop F6 from GitHub workflow * Tie USE_FULL_ASSERT with APP_UNIT_TESTS * Speaker: return to old volume calculation * FreeRTOS: move TCB header to glue Co-authored-by: DrZlo13 <who.just.the.doctor@gmail.com>
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
#include <furi_hal.h>
|
||||
|
||||
#include <comp.h>
|
||||
#include <tim.h>
|
||||
#include <gpio.h>
|
||||
|
||||
@@ -27,10 +26,8 @@ void furi_hal_init() {
|
||||
FURI_LOG_I(TAG, "TIM1 OK");
|
||||
MX_TIM2_Init();
|
||||
FURI_LOG_I(TAG, "TIM2 OK");
|
||||
MX_TIM16_Init();
|
||||
FURI_LOG_I(TAG, "TIM16 OK");
|
||||
MX_COMP1_Init();
|
||||
FURI_LOG_I(TAG, "COMP1 OK");
|
||||
furi_hal_speaker_init();
|
||||
FURI_LOG_I(TAG, "Speaker OK");
|
||||
|
||||
furi_hal_crypto_init();
|
||||
|
||||
@@ -73,4 +70,4 @@ void furi_hal_init() {
|
||||
void furi_hal_init_critical() {
|
||||
furi_hal_clock_init();
|
||||
furi_hal_console_init();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,21 +174,23 @@ static void furi_hal_flush_cache(void) {
|
||||
/* Flush instruction cache */
|
||||
if(READ_BIT(FLASH->ACR, FLASH_ACR_ICEN) == FLASH_ACR_ICEN) {
|
||||
/* Disable instruction cache */
|
||||
__HAL_FLASH_INSTRUCTION_CACHE_DISABLE();
|
||||
LL_FLASH_DisableInstCache();
|
||||
/* Reset instruction cache */
|
||||
__HAL_FLASH_INSTRUCTION_CACHE_RESET();
|
||||
LL_FLASH_EnableInstCacheReset();
|
||||
LL_FLASH_DisableInstCacheReset();
|
||||
/* Enable instruction cache */
|
||||
__HAL_FLASH_INSTRUCTION_CACHE_ENABLE();
|
||||
LL_FLASH_EnableInstCache();
|
||||
}
|
||||
|
||||
/* Flush data cache */
|
||||
if(READ_BIT(FLASH->ACR, FLASH_ACR_DCEN) == FLASH_ACR_DCEN) {
|
||||
/* Disable data cache */
|
||||
__HAL_FLASH_DATA_CACHE_DISABLE();
|
||||
LL_FLASH_DisableDataCache();
|
||||
/* Reset data cache */
|
||||
__HAL_FLASH_DATA_CACHE_RESET();
|
||||
LL_FLASH_EnableDataCacheReset();
|
||||
LL_FLASH_DisableDataCacheReset();
|
||||
/* Enable data cache */
|
||||
__HAL_FLASH_DATA_CACHE_ENABLE();
|
||||
LL_FLASH_EnableDataCache();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <furi.h>
|
||||
#include <furi_hal_gpio.h>
|
||||
#include <furi_hal_version.h>
|
||||
#include <stm32wbxx_ll_comp.h>
|
||||
|
||||
#define GET_SYSCFG_EXTI_PORT(gpio) \
|
||||
(((gpio) == (GPIOA)) ? LL_SYSCFG_EXTI_PORTA : \
|
||||
@@ -305,20 +306,3 @@ void EXTI15_10_IRQHandler(void) {
|
||||
hal_gpio_int_call(15);
|
||||
}
|
||||
}
|
||||
|
||||
extern COMP_HandleTypeDef hcomp1;
|
||||
|
||||
bool hal_gpio_get_rfid_in_level() {
|
||||
bool value = false;
|
||||
if(furi_hal_version_get_hw_version() > 7) {
|
||||
value = (HAL_COMP_GetOutputLevel(&hcomp1) == COMP_OUTPUT_LEVEL_LOW);
|
||||
} else {
|
||||
value = (HAL_COMP_GetOutputLevel(&hcomp1) == COMP_OUTPUT_LEVEL_HIGH);
|
||||
}
|
||||
|
||||
#ifdef INVERT_RFID_IN
|
||||
return !value;
|
||||
#else
|
||||
return value;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -253,12 +253,6 @@ static inline bool hal_gpio_read(const GpioPin* gpio) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get RFID IN level
|
||||
* @return false = LOW, true = HIGH
|
||||
*/
|
||||
bool hal_gpio_get_rfid_in_level();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#include <furi.h>
|
||||
#include <math.h>
|
||||
#include <main.h>
|
||||
#include <furi_hal_pwm.h>
|
||||
|
||||
#define INFRARED_TX_DEBUG 0
|
||||
|
||||
|
||||
@@ -68,12 +68,6 @@ void furi_hal_interrupt_set_dma_channel_isr(
|
||||
extern void api_interrupt_call(InterruptType type, void* hw);
|
||||
|
||||
/* ST HAL symbols */
|
||||
|
||||
/* Comparator trigger event */
|
||||
void HAL_COMP_TriggerCallback(COMP_HandleTypeDef* hcomp) {
|
||||
api_interrupt_call(InterruptTypeComparatorTrigger, hcomp);
|
||||
}
|
||||
|
||||
/* Timer update event */
|
||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim) {
|
||||
api_interrupt_call(InterruptTypeTimerUpdate, htim);
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
#include "furi_hal_pwm.h"
|
||||
|
||||
void hal_pwm_set(float value, float freq, TIM_HandleTypeDef* tim, uint32_t channel) {
|
||||
tim->Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
tim->Init.Period = (uint32_t)((SystemCoreClock / (tim->Init.Prescaler + 1)) / freq) - 1;
|
||||
tim->Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
tim->Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
HAL_TIM_PWM_Init(tim);
|
||||
|
||||
TIM_OC_InitTypeDef sConfigOC;
|
||||
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = (uint16_t)(tim->Init.Period * value);
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
|
||||
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
||||
HAL_TIM_PWM_ConfigChannel(tim, &sConfigOC, channel);
|
||||
HAL_TIM_PWM_Start(tim, channel);
|
||||
}
|
||||
|
||||
void hal_pwmn_set(float value, float freq, TIM_HandleTypeDef* tim, uint32_t channel) {
|
||||
tim->Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
tim->Init.Period = (uint32_t)((SystemCoreClock / (tim->Init.Prescaler + 1)) / freq) - 1;
|
||||
tim->Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
tim->Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||
HAL_TIM_PWM_Init(tim);
|
||||
|
||||
TIM_OC_InitTypeDef sConfigOC;
|
||||
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = (uint16_t)(tim->Init.Period * value);
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
|
||||
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
||||
HAL_TIM_PWM_ConfigChannel(tim, &sConfigOC, channel);
|
||||
HAL_TIMEx_PWMN_Start(tim, channel);
|
||||
}
|
||||
|
||||
void hal_pwm_stop(TIM_HandleTypeDef* tim, uint32_t channel) {
|
||||
HAL_TIM_PWM_Stop(tim, channel);
|
||||
}
|
||||
|
||||
void hal_pwmn_stop(TIM_HandleTypeDef* tim, uint32_t channel) {
|
||||
HAL_TIMEx_PWMN_Stop(tim, channel);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
#pragma once
|
||||
#include "main.h"
|
||||
#include "stdbool.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void hal_pwm_set(float value, float freq, TIM_HandleTypeDef* tim, uint32_t channel);
|
||||
void hal_pwmn_set(float value, float freq, TIM_HandleTypeDef* tim, uint32_t channel);
|
||||
void hal_pwm_stop(TIM_HandleTypeDef* tim, uint32_t channel);
|
||||
void hal_pwmn_stop(TIM_HandleTypeDef* tim, uint32_t channel);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -79,3 +79,5 @@ const GpioPin gpio_usart_rx = {.port = USART1_RX_Port, .pin = USART1_RX_Pin};
|
||||
|
||||
const GpioPin gpio_i2c_power_sda = {.port = GPIOA, .pin = LL_GPIO_PIN_10};
|
||||
const GpioPin gpio_i2c_power_scl = {.port = GPIOA, .pin = LL_GPIO_PIN_9};
|
||||
|
||||
const GpioPin gpio_speaker = {.port = GPIOB, .pin = LL_GPIO_PIN_8};
|
||||
|
||||
@@ -84,6 +84,8 @@ extern const GpioPin gpio_usart_rx;
|
||||
extern const GpioPin gpio_i2c_power_sda;
|
||||
extern const GpioPin gpio_i2c_power_scl;
|
||||
|
||||
extern const GpioPin gpio_speaker;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#include <furi_hal_rfid.h>
|
||||
#include <furi_hal_ibutton.h>
|
||||
#include <furi_hal_resources.h>
|
||||
#include <furi_hal_version.h>
|
||||
|
||||
#include <stm32wbxx_ll_tim.h>
|
||||
#include <stm32wbxx_ll_comp.h>
|
||||
|
||||
#define LFRFID_READ_TIM htim1
|
||||
#define LFRFID_READ_CHANNEL TIM_CHANNEL_1
|
||||
@@ -11,6 +13,29 @@
|
||||
|
||||
void furi_hal_rfid_init() {
|
||||
furi_hal_rfid_pins_reset();
|
||||
|
||||
LL_COMP_InitTypeDef COMP_InitStruct = {0};
|
||||
COMP_InitStruct.PowerMode = LL_COMP_POWERMODE_MEDIUMSPEED;
|
||||
COMP_InitStruct.InputPlus = LL_COMP_INPUT_PLUS_IO1;
|
||||
COMP_InitStruct.InputMinus = LL_COMP_INPUT_MINUS_1_2VREFINT;
|
||||
COMP_InitStruct.InputHysteresis = LL_COMP_HYSTERESIS_HIGH;
|
||||
#ifdef INVERT_RFID_IN
|
||||
COMP_InitStruct.OutputPolarity = LL_COMP_OUTPUTPOL_INVERTED;
|
||||
#else
|
||||
COMP_InitStruct.OutputPolarity = LL_COMP_OUTPUTPOL_NONINVERTED;
|
||||
#endif
|
||||
COMP_InitStruct.OutputBlankingSource = LL_COMP_BLANKINGSRC_NONE;
|
||||
LL_COMP_Init(COMP1, &COMP_InitStruct);
|
||||
LL_COMP_SetCommonWindowMode(__LL_COMP_COMMON_INSTANCE(COMP1), LL_COMP_WINDOWMODE_DISABLE);
|
||||
|
||||
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_20);
|
||||
LL_EXTI_EnableFallingTrig_0_31(LL_EXTI_LINE_20);
|
||||
LL_EXTI_EnableRisingTrig_0_31(LL_EXTI_LINE_20);
|
||||
LL_EXTI_DisableEvent_0_31(LL_EXTI_LINE_20);
|
||||
LL_EXTI_EnableIT_0_31(LL_EXTI_LINE_20);
|
||||
|
||||
NVIC_SetPriority(COMP_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
|
||||
NVIC_EnableIRQ(COMP_IRQn);
|
||||
}
|
||||
|
||||
void furi_hal_rfid_pins_reset() {
|
||||
@@ -26,6 +51,8 @@ void furi_hal_rfid_pins_reset() {
|
||||
hal_gpio_write(&gpio_rfid_pull, true);
|
||||
|
||||
hal_gpio_init_simple(&gpio_rfid_carrier, GpioModeAnalog);
|
||||
|
||||
hal_gpio_init(&gpio_rfid_data_in, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
}
|
||||
|
||||
void furi_hal_rfid_pins_emulate() {
|
||||
@@ -284,3 +311,39 @@ void furi_hal_rfid_change_read_config(float freq, float duty_cycle) {
|
||||
furi_hal_rfid_set_read_period(period);
|
||||
furi_hal_rfid_set_read_pulse(period * duty_cycle);
|
||||
}
|
||||
|
||||
void furi_hal_rfid_comp_start() {
|
||||
LL_COMP_Enable(COMP1);
|
||||
// Magic
|
||||
uint32_t wait_loop_index = ((80 / 10UL) * ((SystemCoreClock / (100000UL * 2UL)) + 1UL));
|
||||
while(wait_loop_index) {
|
||||
wait_loop_index--;
|
||||
}
|
||||
}
|
||||
|
||||
void furi_hal_rfid_comp_stop() {
|
||||
LL_COMP_Disable(COMP1);
|
||||
}
|
||||
|
||||
FuriHalRfidCompCallback furi_hal_rfid_comp_callback = NULL;
|
||||
void* furi_hal_rfid_comp_callback_context = NULL;
|
||||
|
||||
void furi_hal_rfid_comp_set_callback(FuriHalRfidCompCallback callback, void* context) {
|
||||
FURI_CRITICAL_ENTER();
|
||||
furi_hal_rfid_comp_callback = callback;
|
||||
furi_hal_rfid_comp_callback_context = context;
|
||||
__DMB();
|
||||
FURI_CRITICAL_EXIT();
|
||||
}
|
||||
|
||||
/* Comparator trigger event */
|
||||
void COMP_IRQHandler() {
|
||||
if(LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_20)) {
|
||||
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_20);
|
||||
}
|
||||
if(furi_hal_rfid_comp_callback) {
|
||||
furi_hal_rfid_comp_callback(
|
||||
(LL_COMP_ReadOutputLevel(COMP1) == LL_COMP_OUTPUT_LEVEL_LOW),
|
||||
furi_hal_rfid_comp_callback_context);
|
||||
}
|
||||
}
|
||||
|
||||
54
firmware/targets/f7/furi_hal/furi_hal_speaker.c
Normal file
54
firmware/targets/f7/furi_hal/furi_hal_speaker.c
Normal file
@@ -0,0 +1,54 @@
|
||||
#include <furi_hal_speaker.h>
|
||||
#include <furi_hal_gpio.h>
|
||||
#include <furi_hal_resources.h>
|
||||
|
||||
#include <stm32wbxx_ll_tim.h>
|
||||
|
||||
#define FURI_HAL_SPEAKER_TIMER TIM16
|
||||
#define FURI_HAL_SPEAKER_CHANNEL LL_TIM_CHANNEL_CH1
|
||||
#define FURI_HAL_SPEAKER_PRESCALER 500
|
||||
#define FURI_HAL_SPEAKER_MAX_VOLUME 60
|
||||
|
||||
// #define FURI_HAL_SPEAKER_NEW_VOLUME
|
||||
|
||||
void furi_hal_speaker_init() {
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM16);
|
||||
LL_TIM_DeInit(FURI_HAL_SPEAKER_TIMER);
|
||||
hal_gpio_init_ex(
|
||||
&gpio_speaker, GpioModeAltFunctionPushPull, GpioPullNo, GpioSpeedLow, GpioAltFn14TIM16);
|
||||
}
|
||||
|
||||
void furi_hal_speaker_start(float frequency, float volume) {
|
||||
if(volume < 0) volume = 0;
|
||||
if(volume > 1) volume = 1;
|
||||
volume = volume * volume * volume;
|
||||
|
||||
LL_TIM_InitTypeDef TIM_InitStruct = {0};
|
||||
TIM_InitStruct.Prescaler = FURI_HAL_SPEAKER_PRESCALER - 1;
|
||||
TIM_InitStruct.Autoreload = ((SystemCoreClock / FURI_HAL_SPEAKER_PRESCALER) / frequency) - 1;
|
||||
LL_TIM_Init(FURI_HAL_SPEAKER_TIMER, &TIM_InitStruct);
|
||||
|
||||
#ifdef FURI_HAL_SPEAKER_NEW_VOLUME
|
||||
uint16_t compare_value = volume * FURI_HAL_SPEAKER_MAX_VOLUME;
|
||||
uint16_t clip_value = volume * TIM_InitStruct.Autoreload / 2;
|
||||
if(compare_value > clip_value) {
|
||||
compare_value = clip_value;
|
||||
}
|
||||
#else
|
||||
uint16_t compare_value = volume * TIM_InitStruct.Autoreload / 2;
|
||||
#endif
|
||||
|
||||
LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
|
||||
TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
|
||||
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_ENABLE;
|
||||
TIM_OC_InitStruct.CompareValue = compare_value;
|
||||
LL_TIM_OC_Init(FURI_HAL_SPEAKER_TIMER, FURI_HAL_SPEAKER_CHANNEL, &TIM_OC_InitStruct);
|
||||
|
||||
LL_TIM_EnableAllOutputs(FURI_HAL_SPEAKER_TIMER);
|
||||
LL_TIM_EnableCounter(FURI_HAL_SPEAKER_TIMER);
|
||||
}
|
||||
|
||||
void furi_hal_speaker_stop() {
|
||||
LL_TIM_CC_DisableChannel(FURI_HAL_SPEAKER_TIMER, FURI_HAL_SPEAKER_CHANNEL);
|
||||
LL_TIM_DisableCounter(FURI_HAL_SPEAKER_TIMER);
|
||||
}
|
||||
Reference in New Issue
Block a user