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:
あく
2022-03-23 20:59:20 +03:00
committed by GitHub
parent 3857cd7d5f
commit c4a0847c99
219 changed files with 402 additions and 31552 deletions

View File

@@ -1,52 +0,0 @@
/**
******************************************************************************
* @file comp.h
* @brief This file contains all the function prototypes for
* the comp.c file
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __COMP_H__
#define __COMP_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern COMP_HandleTypeDef hcomp1;
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_COMP1_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __COMP_H__ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@@ -35,7 +35,7 @@ extern "C" {
#define HAL_MODULE_ENABLED
/*#define HAL_ADC_MODULE_ENABLED */
#define HAL_CRYP_MODULE_ENABLED
#define HAL_COMP_MODULE_ENABLED
/*#define HAL_COMP_MODULE_ENABLED */
/*#define HAL_CRC_MODULE_ENABLED */
#define HAL_HSEM_MODULE_ENABLED
/*#define HAL_I2C_MODULE_ENABLED */
@@ -185,7 +185,9 @@ extern "C" {
* @brief Uncomment the line below to expanse the "assert_param" macro in the
* HAL drivers code
*/
#ifdef APP_UNIT_TESTS
#define USE_FULL_ASSERT 1U
#endif
/* ################## SPI peripheral configuration ########################## */

View File

@@ -33,7 +33,6 @@ extern "C" {
extern TIM_HandleTypeDef htim1;
extern TIM_HandleTypeDef htim2;
extern TIM_HandleTypeDef htim16;
/* USER CODE BEGIN Private defines */
@@ -41,7 +40,6 @@ extern TIM_HandleTypeDef htim16;
void MX_TIM1_Init(void);
void MX_TIM2_Init(void);
void MX_TIM16_Init(void);
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* htim);

View File

@@ -1,93 +0,0 @@
/**
******************************************************************************
* @file comp.c
* @brief This file provides code for the configuration
* of the COMP instances.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "comp.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
COMP_HandleTypeDef hcomp1;
/* COMP1 init function */
void MX_COMP1_Init(void) {
hcomp1.Instance = COMP1;
hcomp1.Init.InputMinus = COMP_INPUT_MINUS_1_4VREFINT;
hcomp1.Init.InputPlus = COMP_INPUT_PLUS_IO1;
hcomp1.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED;
hcomp1.Init.Hysteresis = COMP_HYSTERESIS_HIGH;
hcomp1.Init.BlankingSrce = COMP_BLANKINGSRC_NONE;
hcomp1.Init.Mode = COMP_POWERMODE_MEDIUMSPEED;
hcomp1.Init.WindowMode = COMP_WINDOWMODE_DISABLE;
hcomp1.Init.TriggerMode = COMP_TRIGGERMODE_IT_RISING_FALLING;
if(HAL_COMP_Init(&hcomp1) != HAL_OK) {
Error_Handler();
}
}
void HAL_COMP_MspInit(COMP_HandleTypeDef* compHandle) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(compHandle->Instance == COMP1) {
/* USER CODE BEGIN COMP1_MspInit 0 */
/* USER CODE END COMP1_MspInit 0 */
__HAL_RCC_GPIOC_CLK_ENABLE();
/**COMP1 GPIO Configuration
PC5 ------> COMP1_INP
*/
GPIO_InitStruct.Pin = RFID_RF_IN_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(RFID_RF_IN_GPIO_Port, &GPIO_InitStruct);
/* COMP1 interrupt Init */
HAL_NVIC_SetPriority(COMP_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(COMP_IRQn);
/* USER CODE BEGIN COMP1_MspInit 1 */
/* USER CODE END COMP1_MspInit 1 */
}
}
void HAL_COMP_MspDeInit(COMP_HandleTypeDef* compHandle) {
if(compHandle->Instance == COMP1) {
/* USER CODE BEGIN COMP1_MspDeInit 0 */
/* USER CODE END COMP1_MspDeInit 0 */
/**COMP1 GPIO Configuration
PC5 ------> COMP1_INP
*/
HAL_GPIO_DeInit(RFID_RF_IN_GPIO_Port, RFID_RF_IN_Pin);
/* COMP1 interrupt Deinit */
HAL_NVIC_DisableIRQ(COMP_IRQn);
/* USER CODE BEGIN COMP1_MspDeInit 1 */
/* USER CODE END COMP1_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@@ -5,11 +5,7 @@
#include "usbd_core.h"
extern usbd_device udev;
extern COMP_HandleTypeDef hcomp1;
extern TIM_HandleTypeDef htim1;
extern TIM_HandleTypeDef htim2;
extern TIM_HandleTypeDef htim16;
extern TIM_HandleTypeDef htim17;
extern void HW_TS_RTC_Wakeup_Handler();
extern void HW_IPCC_Tx_Handler();
@@ -23,10 +19,6 @@ void USB_LP_IRQHandler(void) {
usbd_poll(&udev);
}
void COMP_IRQHandler(void) {
HAL_COMP_IRQHandler(&hcomp1);
}
void TIM1_TRG_COM_TIM17_IRQHandler(void) {
HAL_TIM_IRQHandler(&htim1);
}

View File

@@ -26,7 +26,6 @@
TIM_HandleTypeDef htim1;
TIM_HandleTypeDef htim2;
TIM_HandleTypeDef htim16;
/* TIM1 init function */
void MX_TIM1_Init(void) {
@@ -133,47 +132,6 @@ void MX_TIM2_Init(void) {
Error_Handler();
}
}
/* TIM16 init function */
void MX_TIM16_Init(void) {
TIM_OC_InitTypeDef sConfigOC = {0};
TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
htim16.Instance = TIM16;
htim16.Init.Prescaler = 500 - 1;
htim16.Init.CounterMode = TIM_COUNTERMODE_UP;
htim16.Init.Period = 291;
htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim16.Init.RepetitionCounter = 0;
htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if(HAL_TIM_Base_Init(&htim16) != HAL_OK) {
Error_Handler();
}
if(HAL_TIM_PWM_Init(&htim16) != HAL_OK) {
Error_Handler();
}
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = 145;
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;
if(HAL_TIM_PWM_ConfigChannel(&htim16, &sConfigOC, TIM_CHANNEL_1) != HAL_OK) {
Error_Handler();
}
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.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
if(HAL_TIMEx_ConfigBreakDeadTime(&htim16, &sBreakDeadTimeConfig) != HAL_OK) {
Error_Handler();
}
HAL_TIM_MspPostInit(&htim16);
}
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
@@ -214,15 +172,6 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle) {
/* USER CODE BEGIN TIM2_MspInit 1 */
/* USER CODE END TIM2_MspInit 1 */
} else if(tim_baseHandle->Instance == TIM16) {
/* USER CODE BEGIN TIM16_MspInit 0 */
/* USER CODE END TIM16_MspInit 0 */
/* TIM16 clock enable */
__HAL_RCC_TIM16_CLK_ENABLE();
/* USER CODE BEGIN TIM16_MspInit 1 */
/* USER CODE END TIM16_MspInit 1 */
}
}
void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle) {
@@ -246,25 +195,6 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle) {
/* USER CODE BEGIN TIM1_MspPostInit 1 */
/* USER CODE END TIM1_MspPostInit 1 */
} else if(timHandle->Instance == TIM16) {
/* USER CODE BEGIN TIM16_MspPostInit 0 */
/* USER CODE END TIM16_MspPostInit 0 */
__HAL_RCC_GPIOB_CLK_ENABLE();
/**TIM16 GPIO Configuration
PB8 ------> TIM16_CH1
*/
GPIO_InitStruct.Pin = SPEAKER_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF14_TIM16;
HAL_GPIO_Init(SPEAKER_GPIO_Port, &GPIO_InitStruct);
/* USER CODE BEGIN TIM16_MspPostInit 1 */
/* USER CODE END TIM16_MspPostInit 1 */
}
}
@@ -298,15 +228,6 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle) {
/* USER CODE BEGIN TIM2_MspDeInit 1 */
/* USER CODE END TIM2_MspDeInit 1 */
} else if(tim_baseHandle->Instance == TIM16) {
/* USER CODE BEGIN TIM16_MspDeInit 0 */
/* USER CODE END TIM16_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_TIM16_CLK_DISABLE();
/* USER CODE BEGIN TIM16_MspDeInit 1 */
/* USER CODE END TIM16_MspDeInit 1 */
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -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
}

View File

@@ -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

View File

@@ -15,7 +15,6 @@
#include <furi.h>
#include <math.h>
#include <main.h>
#include <furi_hal_pwm.h>
#define INFRARED_TX_DEBUG 0

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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};

View File

@@ -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

View File

@@ -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);
}
}

View 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);
}

View File

@@ -51,7 +51,6 @@ CFLAGS += \
-I$(CUBE_DIR)/Drivers/CMSIS/Include
C_SOURCES += \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_comp.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_cortex.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_cryp.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_exti.c \
@@ -66,6 +65,7 @@ C_SOURCES += \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_tim.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_tim_ex.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_adc.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_comp.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_dma.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_gpio.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_i2c.c \