mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-12 14:58:36 -07:00
Merge remote-tracking branch 'UFW/dev' into cc1101_ext
This commit is contained in:
@@ -145,6 +145,7 @@ Header,+,lib/mlib/m-list.h,,
|
||||
Header,+,lib/mlib/m-rbtree.h,,
|
||||
Header,+,lib/mlib/m-tuple.h,,
|
||||
Header,+,lib/mlib/m-variant.h,,
|
||||
Header,+,lib/music_worker/music_worker.h,,
|
||||
Header,+,lib/nfc/nfc_device.h,,
|
||||
Header,+,lib/nfc/protocols/nfc_util.h,,
|
||||
Header,+,lib/one_wire/maxim_crc.h,,
|
||||
@@ -801,7 +802,8 @@ Function,+,elements_slightly_rounded_box,void,"Canvas*, uint8_t, uint8_t, uint8_
|
||||
Function,+,elements_slightly_rounded_frame,void,"Canvas*, uint8_t, uint8_t, uint8_t, uint8_t"
|
||||
Function,+,elements_string_fit_width,void,"Canvas*, FuriString*, uint8_t"
|
||||
Function,+,elements_text_box,void,"Canvas*, uint8_t, uint8_t, uint8_t, uint8_t, Align, Align, const char*, _Bool"
|
||||
Function,+,elf_resolve_from_hashtable,_Bool,"const ElfApiInterface*, const char*, Elf32_Addr*"
|
||||
Function,+,elf_resolve_from_hashtable,_Bool,"const ElfApiInterface*, uint32_t, Elf32_Addr*"
|
||||
Function,+,elf_symbolname_hash,uint32_t,const char*
|
||||
Function,+,empty_screen_alloc,EmptyScreen*,
|
||||
Function,+,empty_screen_free,void,EmptyScreen*
|
||||
Function,+,empty_screen_get_view,View*,EmptyScreen*
|
||||
@@ -885,9 +887,11 @@ Function,-,finitel,int,long double
|
||||
Function,-,fiprintf,int,"FILE*, const char*, ..."
|
||||
Function,-,fiscanf,int,"FILE*, const char*, ..."
|
||||
Function,+,flipper_application_alloc,FlipperApplication*,"Storage*, const ElfApiInterface*"
|
||||
Function,+,flipper_application_alloc_thread,FuriThread*,"FlipperApplication*, const char*"
|
||||
Function,+,flipper_application_free,void,FlipperApplication*
|
||||
Function,+,flipper_application_get_manifest,const FlipperApplicationManifest*,FlipperApplication*
|
||||
Function,+,flipper_application_is_plugin,_Bool,FlipperApplication*
|
||||
Function,+,flipper_application_load_name_and_icon,_Bool,"FuriString*, Storage*, uint8_t**, FuriString*"
|
||||
Function,+,flipper_application_load_status_to_string,const char*,FlipperApplicationLoadStatus
|
||||
Function,+,flipper_application_manifest_is_compatible,_Bool,"const FlipperApplicationManifest*, const ElfApiInterface*"
|
||||
Function,+,flipper_application_manifest_is_target_compatible,_Bool,const FlipperApplicationManifest*
|
||||
@@ -897,7 +901,6 @@ Function,+,flipper_application_plugin_get_descriptor,const FlipperAppPluginDescr
|
||||
Function,+,flipper_application_preload,FlipperApplicationPreloadStatus,"FlipperApplication*, const char*"
|
||||
Function,+,flipper_application_preload_manifest,FlipperApplicationPreloadStatus,"FlipperApplication*, const char*"
|
||||
Function,+,flipper_application_preload_status_to_string,const char*,FlipperApplicationPreloadStatus
|
||||
Function,+,flipper_application_spawn,FuriThread*,"FlipperApplication*, void*"
|
||||
Function,+,flipper_format_buffered_file_alloc,FlipperFormat*,Storage*
|
||||
Function,+,flipper_format_buffered_file_close,_Bool,FlipperFormat*
|
||||
Function,+,flipper_format_buffered_file_open_always,_Bool,"FlipperFormat*, const char*"
|
||||
@@ -1226,6 +1229,8 @@ Function,+,furi_hal_nfc_deinit,void,
|
||||
Function,+,furi_hal_nfc_detect,_Bool,"FuriHalNfcDevData*, uint32_t"
|
||||
Function,+,furi_hal_nfc_emulate_nfca,_Bool,"uint8_t*, uint8_t, uint8_t*, uint8_t, FuriHalNfcEmulateCallback, void*, uint32_t"
|
||||
Function,+,furi_hal_nfc_exit_sleep,void,
|
||||
Function,+,furi_hal_nfc_field_detect_start,void,
|
||||
Function,+,furi_hal_nfc_field_is_present,_Bool,
|
||||
Function,+,furi_hal_nfc_field_off,void,
|
||||
Function,+,furi_hal_nfc_field_on,void,
|
||||
Function,+,furi_hal_nfc_init,void,
|
||||
@@ -1286,6 +1291,7 @@ Function,+,furi_hal_power_sleep,void,
|
||||
Function,+,furi_hal_power_sleep_available,_Bool,
|
||||
Function,+,furi_hal_power_suppress_charge_enter,void,
|
||||
Function,+,furi_hal_power_suppress_charge_exit,void,
|
||||
Function,+,furi_hal_pwm_is_running,_Bool,FuriHalPwmOutputId
|
||||
Function,+,furi_hal_pwm_set_params,void,"FuriHalPwmOutputId, uint32_t, uint8_t"
|
||||
Function,+,furi_hal_pwm_start,void,"FuriHalPwmOutputId, uint32_t, uint8_t"
|
||||
Function,+,furi_hal_pwm_stop,void,FuriHalPwmOutputId
|
||||
@@ -1305,6 +1311,9 @@ Function,-,furi_hal_resources_init_early,void,
|
||||
Function,+,furi_hal_rfid_comp_set_callback,void,"FuriHalRfidCompCallback, void*"
|
||||
Function,+,furi_hal_rfid_comp_start,void,
|
||||
Function,+,furi_hal_rfid_comp_stop,void,
|
||||
Function,+,furi_hal_rfid_field_detect_start,void,
|
||||
Function,+,furi_hal_rfid_field_detect_stop,void,
|
||||
Function,+,furi_hal_rfid_field_is_present,_Bool,uint32_t*
|
||||
Function,-,furi_hal_rfid_init,void,
|
||||
Function,+,furi_hal_rfid_pin_pull_pulldown,void,
|
||||
Function,+,furi_hal_rfid_pin_pull_release,void,
|
||||
@@ -1838,7 +1847,8 @@ Function,+,loader_get_pubsub,FuriPubSub*,Loader*
|
||||
Function,+,loader_is_locked,_Bool,Loader*
|
||||
Function,+,loader_lock,_Bool,Loader*
|
||||
Function,+,loader_show_menu,void,Loader*
|
||||
Function,+,loader_start,LoaderStatus,"Loader*, const char*, const char*"
|
||||
Function,+,loader_start,LoaderStatus,"Loader*, const char*, const char*, FuriString*"
|
||||
Function,+,loader_start_with_gui_error,LoaderStatus,"Loader*, const char*, const char*"
|
||||
Function,+,loader_unlock,void,Loader*
|
||||
Function,+,loading_alloc,Loading*,
|
||||
Function,+,loading_free,void,Loading*
|
||||
@@ -2067,6 +2077,18 @@ Function,-,modf,double,"double, double*"
|
||||
Function,-,modff,float,"float, float*"
|
||||
Function,-,modfl,long double,"long double, long double*"
|
||||
Function,-,mrand48,long,
|
||||
Function,-,music_worker_alloc,MusicWorker*,
|
||||
Function,-,music_worker_clear,void,MusicWorker*
|
||||
Function,-,music_worker_free,void,MusicWorker*
|
||||
Function,-,music_worker_is_playing,_Bool,MusicWorker*
|
||||
Function,-,music_worker_load,_Bool,"MusicWorker*, const char*"
|
||||
Function,-,music_worker_load_fmf_from_file,_Bool,"MusicWorker*, const char*"
|
||||
Function,-,music_worker_load_rtttl_from_file,_Bool,"MusicWorker*, const char*"
|
||||
Function,-,music_worker_load_rtttl_from_string,_Bool,"MusicWorker*, const char*"
|
||||
Function,-,music_worker_set_callback,void,"MusicWorker*, MusicWorkerCallback, void*"
|
||||
Function,-,music_worker_set_volume,void,"MusicWorker*, float"
|
||||
Function,-,music_worker_start,void,MusicWorker*
|
||||
Function,-,music_worker_stop,void,MusicWorker*
|
||||
Function,-,nan,double,const char*
|
||||
Function,-,nanf,float,const char*
|
||||
Function,-,nanl,long double,const char*
|
||||
@@ -2784,6 +2806,7 @@ Function,+,subghz_receiver_search_decoder_base_by_name,SubGhzProtocolDecoderBase
|
||||
Function,+,subghz_receiver_set_filter,void,"SubGhzReceiver*, SubGhzProtocolFlag"
|
||||
Function,+,subghz_receiver_set_rx_callback,void,"SubGhzReceiver*, SubGhzReceiverCallback, void*"
|
||||
Function,+,subghz_setting_alloc,SubGhzSetting*,
|
||||
Function,-,subghz_setting_customs_presets_to_log,uint8_t,SubGhzSetting*
|
||||
Function,+,subghz_setting_delete_custom_preset,_Bool,"SubGhzSetting*, const char*"
|
||||
Function,+,subghz_setting_free,void,SubGhzSetting*
|
||||
Function,+,subghz_setting_get_default_frequency,uint32_t,SubGhzSetting*
|
||||
|
||||
|
@@ -22,8 +22,17 @@
|
||||
|
||||
#define FURI_HAL_BT_HARDFAULT_INFO_MAGIC 0x1170FD0F
|
||||
|
||||
FuriMutex* furi_hal_bt_core2_mtx = NULL;
|
||||
static FuriHalBtStack furi_hal_bt_stack = FuriHalBtStackUnknown;
|
||||
typedef struct {
|
||||
FuriMutex* core2_mtx;
|
||||
FuriTimer* hardfault_check_timer;
|
||||
FuriHalBtStack stack;
|
||||
} FuriHalBt;
|
||||
|
||||
static FuriHalBt furi_hal_bt = {
|
||||
.core2_mtx = NULL,
|
||||
.hardfault_check_timer = NULL,
|
||||
.stack = FuriHalBtStackUnknown,
|
||||
};
|
||||
|
||||
typedef void (*FuriHalBtProfileStart)(void);
|
||||
typedef void (*FuriHalBtProfileStop)(void);
|
||||
@@ -80,6 +89,13 @@ FuriHalBtProfileConfig profile_config[FuriHalBtProfileNumber] = {
|
||||
};
|
||||
FuriHalBtProfileConfig* current_profile = NULL;
|
||||
|
||||
static void furi_hal_bt_hardfault_check(void* context) {
|
||||
UNUSED(context);
|
||||
if(furi_hal_bt_get_hardfault_info()) {
|
||||
furi_crash("ST(R) Copro(R) HardFault");
|
||||
}
|
||||
}
|
||||
|
||||
void furi_hal_bt_init() {
|
||||
furi_hal_bus_enable(FuriHalBusHSEM);
|
||||
furi_hal_bus_enable(FuriHalBusIPCC);
|
||||
@@ -87,9 +103,15 @@ void furi_hal_bt_init() {
|
||||
furi_hal_bus_enable(FuriHalBusPKA);
|
||||
furi_hal_bus_enable(FuriHalBusCRC);
|
||||
|
||||
if(!furi_hal_bt_core2_mtx) {
|
||||
furi_hal_bt_core2_mtx = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
furi_assert(furi_hal_bt_core2_mtx);
|
||||
if(!furi_hal_bt.core2_mtx) {
|
||||
furi_hal_bt.core2_mtx = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
furi_assert(furi_hal_bt.core2_mtx);
|
||||
}
|
||||
|
||||
if(!furi_hal_bt.hardfault_check_timer) {
|
||||
furi_hal_bt.hardfault_check_timer =
|
||||
furi_timer_alloc(furi_hal_bt_hardfault_check, FuriTimerTypePeriodic, NULL);
|
||||
furi_timer_start(furi_hal_bt.hardfault_check_timer, 5000);
|
||||
}
|
||||
|
||||
// Explicitly tell that we are in charge of CLK48 domain
|
||||
@@ -100,13 +122,13 @@ void furi_hal_bt_init() {
|
||||
}
|
||||
|
||||
void furi_hal_bt_lock_core2() {
|
||||
furi_assert(furi_hal_bt_core2_mtx);
|
||||
furi_check(furi_mutex_acquire(furi_hal_bt_core2_mtx, FuriWaitForever) == FuriStatusOk);
|
||||
furi_assert(furi_hal_bt.core2_mtx);
|
||||
furi_check(furi_mutex_acquire(furi_hal_bt.core2_mtx, FuriWaitForever) == FuriStatusOk);
|
||||
}
|
||||
|
||||
void furi_hal_bt_unlock_core2() {
|
||||
furi_assert(furi_hal_bt_core2_mtx);
|
||||
furi_check(furi_mutex_release(furi_hal_bt_core2_mtx) == FuriStatusOk);
|
||||
furi_assert(furi_hal_bt.core2_mtx);
|
||||
furi_check(furi_mutex_release(furi_hal_bt.core2_mtx) == FuriStatusOk);
|
||||
}
|
||||
|
||||
static bool furi_hal_bt_radio_stack_is_supported(const BleGlueC2Info* info) {
|
||||
@@ -114,26 +136,26 @@ static bool furi_hal_bt_radio_stack_is_supported(const BleGlueC2Info* info) {
|
||||
if(info->StackType == INFO_STACK_TYPE_BLE_LIGHT) {
|
||||
if(info->VersionMajor >= FURI_HAL_BT_STACK_VERSION_MAJOR &&
|
||||
info->VersionMinor >= FURI_HAL_BT_STACK_VERSION_MINOR) {
|
||||
furi_hal_bt_stack = FuriHalBtStackLight;
|
||||
furi_hal_bt.stack = FuriHalBtStackLight;
|
||||
supported = true;
|
||||
}
|
||||
} else if(info->StackType == INFO_STACK_TYPE_BLE_FULL) {
|
||||
if(info->VersionMajor >= FURI_HAL_BT_STACK_VERSION_MAJOR &&
|
||||
info->VersionMinor >= FURI_HAL_BT_STACK_VERSION_MINOR) {
|
||||
furi_hal_bt_stack = FuriHalBtStackFull;
|
||||
furi_hal_bt.stack = FuriHalBtStackFull;
|
||||
supported = true;
|
||||
}
|
||||
} else {
|
||||
furi_hal_bt_stack = FuriHalBtStackUnknown;
|
||||
furi_hal_bt.stack = FuriHalBtStackUnknown;
|
||||
}
|
||||
return supported;
|
||||
}
|
||||
|
||||
bool furi_hal_bt_start_radio_stack() {
|
||||
bool res = false;
|
||||
furi_assert(furi_hal_bt_core2_mtx);
|
||||
furi_assert(furi_hal_bt.core2_mtx);
|
||||
|
||||
furi_mutex_acquire(furi_hal_bt_core2_mtx, FuriWaitForever);
|
||||
furi_mutex_acquire(furi_hal_bt.core2_mtx, FuriWaitForever);
|
||||
|
||||
// Explicitly tell that we are in charge of CLK48 domain
|
||||
furi_check(LL_HSEM_1StepLock(HSEM, CFG_HW_CLK48_CONFIG_SEMID) == 0);
|
||||
@@ -167,17 +189,17 @@ bool furi_hal_bt_start_radio_stack() {
|
||||
}
|
||||
res = true;
|
||||
} while(false);
|
||||
furi_mutex_release(furi_hal_bt_core2_mtx);
|
||||
furi_mutex_release(furi_hal_bt.core2_mtx);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
FuriHalBtStack furi_hal_bt_get_radio_stack() {
|
||||
return furi_hal_bt_stack;
|
||||
return furi_hal_bt.stack;
|
||||
}
|
||||
|
||||
bool furi_hal_bt_is_ble_gatt_gap_supported() {
|
||||
if(furi_hal_bt_stack == FuriHalBtStackLight || furi_hal_bt_stack == FuriHalBtStackFull) {
|
||||
if(furi_hal_bt.stack == FuriHalBtStackLight || furi_hal_bt.stack == FuriHalBtStackFull) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
@@ -185,7 +207,7 @@ bool furi_hal_bt_is_ble_gatt_gap_supported() {
|
||||
}
|
||||
|
||||
bool furi_hal_bt_is_testing_supported() {
|
||||
if(furi_hal_bt_stack == FuriHalBtStackFull) {
|
||||
if(furi_hal_bt.stack == FuriHalBtStackFull) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@@ -819,3 +819,17 @@ FuriHalNfcReturn furi_hal_nfc_ll_txrx_bits(
|
||||
void furi_hal_nfc_ll_poll() {
|
||||
rfalWorker();
|
||||
}
|
||||
|
||||
void furi_hal_nfc_field_detect_start() {
|
||||
st25r3916WriteRegister(
|
||||
ST25R3916_REG_OP_CONTROL,
|
||||
ST25R3916_REG_OP_CONTROL_en | ST25R3916_REG_OP_CONTROL_en_fd_mask);
|
||||
st25r3916WriteRegister(ST25R3916_REG_MODE, ST25R3916_REG_MODE_targ | ST25R3916_REG_MODE_om0);
|
||||
}
|
||||
|
||||
bool furi_hal_nfc_field_is_present() {
|
||||
return st25r3916CheckReg(
|
||||
ST25R3916_REG_AUX_DISPLAY,
|
||||
ST25R3916_REG_AUX_DISPLAY_efd_o,
|
||||
ST25R3916_REG_AUX_DISPLAY_efd_o);
|
||||
}
|
||||
@@ -423,6 +423,10 @@ FuriHalNfcReturn furi_hal_nfc_ll_txrx_bits(
|
||||
|
||||
void furi_hal_nfc_ll_poll();
|
||||
|
||||
void furi_hal_nfc_field_detect_start();
|
||||
|
||||
bool furi_hal_nfc_field_is_present();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -82,6 +82,15 @@ void furi_hal_pwm_stop(FuriHalPwmOutputId channel) {
|
||||
}
|
||||
}
|
||||
|
||||
bool furi_hal_pwm_is_running(FuriHalPwmOutputId channel) {
|
||||
if(channel == FuriHalPwmOutputIdTim1PA7) {
|
||||
return furi_hal_bus_is_enabled(FuriHalBusTIM1);
|
||||
} else if(channel == FuriHalPwmOutputIdLptim2PA4) {
|
||||
return furi_hal_bus_is_enabled(FuriHalBusLPTIM2);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void furi_hal_pwm_set_params(FuriHalPwmOutputId channel, uint32_t freq, uint8_t duty) {
|
||||
furi_assert(freq > 0);
|
||||
uint32_t freq_div = 64000000LU / freq;
|
||||
|
||||
@@ -9,6 +9,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef enum {
|
||||
FuriHalPwmOutputIdTim1PA7,
|
||||
@@ -37,6 +38,13 @@ void furi_hal_pwm_stop(FuriHalPwmOutputId channel);
|
||||
*/
|
||||
void furi_hal_pwm_set_params(FuriHalPwmOutputId channel, uint32_t freq, uint8_t duty);
|
||||
|
||||
/** Is PWM channel running?
|
||||
*
|
||||
* @param[in] channel PWM channel (FuriHalPwmOutputId)
|
||||
* @return bool - true if running
|
||||
*/
|
||||
bool furi_hal_pwm_is_running(FuriHalPwmOutputId channel);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -25,6 +25,19 @@
|
||||
#define RFID_CAPTURE_IND_CH LL_TIM_CHANNEL_CH3
|
||||
#define RFID_CAPTURE_DIR_CH LL_TIM_CHANNEL_CH4
|
||||
|
||||
// Field presence detection
|
||||
#define FURI_HAL_RFID_FIELD_FREQUENCY_MIN 80000
|
||||
#define FURI_HAL_RFID_FIELD_FREQUENCY_MAX 200000
|
||||
|
||||
#define FURI_HAL_RFID_FIELD_COUNTER_TIMER TIM2
|
||||
#define FURI_HAL_RFID_FIELD_COUNTER_TIMER_BUS FuriHalBusTIM2
|
||||
#define FURI_HAL_RFID_FIELD_COUNTER_TIMER_CHANNEL LL_TIM_CHANNEL_CH3
|
||||
|
||||
#define FURI_HAL_RFID_FIELD_TIMEOUT_TIMER TIM1
|
||||
#define FURI_HAL_RFID_FIELD_TIMEOUT_TIMER_BUS FuriHalBusTIM1
|
||||
|
||||
#define FURI_HAL_RFID_FIELD_DMAMUX_DMA LL_DMAMUX_REQ_TIM1_UP
|
||||
|
||||
/* DMA Channels definition */
|
||||
#define RFID_DMA DMA2
|
||||
#define RFID_DMA_CH1_CHANNEL LL_DMA_CHANNEL_1
|
||||
@@ -33,10 +46,16 @@
|
||||
#define RFID_DMA_CH1_DEF RFID_DMA, RFID_DMA_CH1_CHANNEL
|
||||
#define RFID_DMA_CH2_DEF RFID_DMA, RFID_DMA_CH2_CHANNEL
|
||||
|
||||
typedef struct {
|
||||
uint32_t counter;
|
||||
uint32_t set_tim_counter_cnt;
|
||||
} FuriHalRfidField;
|
||||
|
||||
typedef struct {
|
||||
FuriHalRfidDMACallback dma_callback;
|
||||
FuriHalRfidReadCaptureCallback read_capture_callback;
|
||||
void* context;
|
||||
FuriHalRfidField field;
|
||||
} FuriHalRfid;
|
||||
|
||||
FuriHalRfid* furi_hal_rfid = NULL;
|
||||
@@ -51,6 +70,8 @@ FuriHalRfid* furi_hal_rfid = NULL;
|
||||
void furi_hal_rfid_init() {
|
||||
furi_assert(furi_hal_rfid == NULL);
|
||||
furi_hal_rfid = malloc(sizeof(FuriHalRfid));
|
||||
furi_hal_rfid->field.counter = 0;
|
||||
furi_hal_rfid->field.set_tim_counter_cnt = 0;
|
||||
|
||||
furi_hal_rfid_pins_reset();
|
||||
|
||||
@@ -133,6 +154,23 @@ static void furi_hal_rfid_pins_read() {
|
||||
furi_hal_gpio_init(&gpio_rfid_data_in, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
}
|
||||
|
||||
static void furi_hal_rfid_pins_field() {
|
||||
// ibutton low
|
||||
furi_hal_ibutton_pin_configure();
|
||||
furi_hal_ibutton_pin_write(false);
|
||||
|
||||
// pull pin to timer out
|
||||
furi_hal_gpio_init(&gpio_nfc_irq_rfid_pull, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_write(&gpio_nfc_irq_rfid_pull, false);
|
||||
|
||||
// pull rfid antenna from carrier side
|
||||
furi_hal_gpio_init(&gpio_rfid_carrier_out, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
furi_hal_gpio_write(&gpio_rfid_carrier_out, false);
|
||||
|
||||
furi_hal_gpio_init_ex(
|
||||
&gpio_rfid_carrier, GpioModeAltFunctionPushPull, GpioPullNo, GpioSpeedLow, GpioAltFn2TIM2);
|
||||
}
|
||||
|
||||
void furi_hal_rfid_pin_pull_release() {
|
||||
furi_hal_gpio_write(&gpio_nfc_irq_rfid_pull, true);
|
||||
}
|
||||
@@ -427,3 +465,124 @@ void COMP_IRQHandler() {
|
||||
furi_hal_rfid_comp_callback_context);
|
||||
}
|
||||
}
|
||||
|
||||
static void furi_hal_rfid_field_tim_setup() {
|
||||
// setup timer counter
|
||||
furi_hal_bus_enable(FURI_HAL_RFID_FIELD_COUNTER_TIMER_BUS);
|
||||
|
||||
LL_TIM_SetPrescaler(FURI_HAL_RFID_FIELD_COUNTER_TIMER, 0);
|
||||
LL_TIM_SetCounterMode(FURI_HAL_RFID_FIELD_COUNTER_TIMER, LL_TIM_COUNTERMODE_UP);
|
||||
LL_TIM_SetAutoReload(FURI_HAL_RFID_FIELD_COUNTER_TIMER, 0xFFFFFFFF);
|
||||
LL_TIM_DisableARRPreload(FURI_HAL_RFID_FIELD_COUNTER_TIMER);
|
||||
LL_TIM_SetRepetitionCounter(FURI_HAL_RFID_FIELD_COUNTER_TIMER, 0);
|
||||
|
||||
LL_TIM_SetClockDivision(FURI_HAL_RFID_FIELD_COUNTER_TIMER, LL_TIM_CLOCKDIVISION_DIV1);
|
||||
LL_TIM_SetClockSource(FURI_HAL_RFID_FIELD_COUNTER_TIMER, LL_TIM_CLOCKSOURCE_EXT_MODE2);
|
||||
LL_TIM_ConfigETR(
|
||||
FURI_HAL_RFID_FIELD_COUNTER_TIMER,
|
||||
LL_TIM_ETR_POLARITY_INVERTED,
|
||||
LL_TIM_ETR_PRESCALER_DIV1,
|
||||
LL_TIM_ETR_FILTER_FDIV1);
|
||||
|
||||
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 = 1;
|
||||
LL_TIM_OC_Init(
|
||||
FURI_HAL_RFID_FIELD_COUNTER_TIMER,
|
||||
FURI_HAL_RFID_FIELD_COUNTER_TIMER_CHANNEL,
|
||||
&TIM_OC_InitStruct);
|
||||
|
||||
LL_TIM_GenerateEvent_UPDATE(FURI_HAL_RFID_FIELD_COUNTER_TIMER);
|
||||
LL_TIM_OC_SetPolarity(
|
||||
FURI_HAL_RFID_FIELD_COUNTER_TIMER,
|
||||
FURI_HAL_RFID_FIELD_COUNTER_TIMER_CHANNEL,
|
||||
LL_TIM_OCPOLARITY_HIGH);
|
||||
LL_TIM_EnableDMAReq_UPDATE(FURI_HAL_RFID_FIELD_COUNTER_TIMER);
|
||||
|
||||
// setup timer timeouts dma
|
||||
furi_hal_bus_enable(FURI_HAL_RFID_FIELD_TIMEOUT_TIMER_BUS);
|
||||
|
||||
LL_TIM_SetPrescaler(FURI_HAL_RFID_FIELD_TIMEOUT_TIMER, 64000 - 1);
|
||||
LL_TIM_SetCounterMode(FURI_HAL_RFID_FIELD_TIMEOUT_TIMER, LL_TIM_COUNTERMODE_UP);
|
||||
LL_TIM_SetAutoReload(FURI_HAL_RFID_FIELD_TIMEOUT_TIMER, 100 - 1); // 100 ms
|
||||
LL_TIM_SetClockDivision(FURI_HAL_RFID_FIELD_TIMEOUT_TIMER, LL_TIM_CLOCKDIVISION_DIV1);
|
||||
LL_TIM_SetClockSource(FURI_HAL_RFID_FIELD_TIMEOUT_TIMER, LL_TIM_CLOCKSOURCE_INTERNAL);
|
||||
|
||||
LL_TIM_DisableARRPreload(FURI_HAL_RFID_FIELD_TIMEOUT_TIMER);
|
||||
|
||||
LL_TIM_EnableDMAReq_UPDATE(FURI_HAL_RFID_FIELD_TIMEOUT_TIMER);
|
||||
LL_TIM_GenerateEvent_UPDATE(FURI_HAL_RFID_FIELD_TIMEOUT_TIMER);
|
||||
}
|
||||
|
||||
void furi_hal_rfid_field_detect_start(void) {
|
||||
// setup pins
|
||||
furi_hal_rfid_pins_field();
|
||||
|
||||
// configure timer
|
||||
furi_hal_rfid_field_tim_setup();
|
||||
|
||||
// configure DMA "TIM_COUNTER_CNT -> counter"
|
||||
LL_DMA_SetMemoryAddress(RFID_DMA_CH1_DEF, (uint32_t) & (furi_hal_rfid->field.counter));
|
||||
LL_DMA_SetPeriphAddress(
|
||||
RFID_DMA_CH1_DEF, (uint32_t) & (FURI_HAL_RFID_FIELD_COUNTER_TIMER->CNT));
|
||||
LL_DMA_ConfigTransfer(
|
||||
RFID_DMA_CH1_DEF,
|
||||
LL_DMA_DIRECTION_PERIPH_TO_MEMORY | LL_DMA_MODE_CIRCULAR | LL_DMA_PERIPH_NOINCREMENT |
|
||||
LL_DMA_MEMORY_NOINCREMENT | LL_DMA_PDATAALIGN_WORD | LL_DMA_MDATAALIGN_WORD |
|
||||
LL_DMA_PRIORITY_MEDIUM);
|
||||
LL_DMA_SetDataLength(RFID_DMA_CH1_DEF, 1);
|
||||
LL_DMA_SetPeriphRequest(RFID_DMA_CH1_DEF, FURI_HAL_RFID_FIELD_DMAMUX_DMA);
|
||||
LL_DMA_EnableChannel(RFID_DMA_CH1_DEF);
|
||||
|
||||
// configure DMA "mem -> TIM_COUNTER_CNT"
|
||||
LL_DMA_SetMemoryAddress(
|
||||
RFID_DMA_CH2_DEF, (uint32_t) & (furi_hal_rfid->field.set_tim_counter_cnt));
|
||||
LL_DMA_SetPeriphAddress(
|
||||
RFID_DMA_CH2_DEF, (uint32_t) & (FURI_HAL_RFID_FIELD_COUNTER_TIMER->CNT));
|
||||
LL_DMA_ConfigTransfer(
|
||||
RFID_DMA_CH2_DEF,
|
||||
LL_DMA_DIRECTION_MEMORY_TO_PERIPH | LL_DMA_MODE_CIRCULAR | LL_DMA_PERIPH_NOINCREMENT |
|
||||
LL_DMA_MEMORY_NOINCREMENT | LL_DMA_PDATAALIGN_WORD | LL_DMA_MDATAALIGN_WORD |
|
||||
LL_DMA_PRIORITY_LOW);
|
||||
LL_DMA_SetDataLength(RFID_DMA_CH2_DEF, 1);
|
||||
LL_DMA_SetPeriphRequest(RFID_DMA_CH2_DEF, FURI_HAL_RFID_FIELD_DMAMUX_DMA);
|
||||
LL_DMA_EnableChannel(RFID_DMA_CH2_DEF);
|
||||
|
||||
// start tim counter
|
||||
LL_TIM_EnableAllOutputs(FURI_HAL_RFID_FIELD_COUNTER_TIMER);
|
||||
|
||||
LL_TIM_SetCounter(FURI_HAL_RFID_FIELD_COUNTER_TIMER, 0);
|
||||
LL_TIM_EnableCounter(FURI_HAL_RFID_FIELD_COUNTER_TIMER);
|
||||
|
||||
// start tim timeout
|
||||
LL_TIM_SetCounter(FURI_HAL_RFID_FIELD_TIMEOUT_TIMER, 0);
|
||||
LL_TIM_EnableCounter(FURI_HAL_RFID_FIELD_TIMEOUT_TIMER);
|
||||
LL_TIM_EnableIT_UPDATE(FURI_HAL_RFID_FIELD_TIMEOUT_TIMER);
|
||||
}
|
||||
|
||||
void furi_hal_rfid_field_detect_stop(void) {
|
||||
LL_TIM_DisableCounter(FURI_HAL_RFID_FIELD_COUNTER_TIMER);
|
||||
LL_TIM_DisableAllOutputs(FURI_HAL_RFID_FIELD_COUNTER_TIMER);
|
||||
|
||||
LL_TIM_DisableCounter(FURI_HAL_RFID_FIELD_TIMEOUT_TIMER);
|
||||
|
||||
FURI_CRITICAL_ENTER();
|
||||
|
||||
LL_DMA_DeInit(RFID_DMA_CH1_DEF);
|
||||
LL_DMA_DeInit(RFID_DMA_CH2_DEF);
|
||||
|
||||
furi_hal_bus_disable(FURI_HAL_RFID_FIELD_COUNTER_TIMER_BUS);
|
||||
furi_hal_bus_disable(FURI_HAL_RFID_FIELD_TIMEOUT_TIMER_BUS);
|
||||
|
||||
furi_hal_rfid_pins_reset();
|
||||
|
||||
FURI_CRITICAL_EXIT();
|
||||
}
|
||||
|
||||
bool furi_hal_rfid_field_is_present(uint32_t* frequency) {
|
||||
*frequency = furi_hal_rfid->field.counter * 10;
|
||||
return (
|
||||
(*frequency >= FURI_HAL_RFID_FIELD_FREQUENCY_MIN) &&
|
||||
(*frequency <= FURI_HAL_RFID_FIELD_FREQUENCY_MAX));
|
||||
}
|
||||
@@ -87,6 +87,20 @@ typedef void (*FuriHalRfidCompCallback)(bool level, void* context);
|
||||
/** Set comparator callback */
|
||||
void furi_hal_rfid_comp_set_callback(FuriHalRfidCompCallback callback, void* context);
|
||||
|
||||
/** Start/Enable Field Presence detect */
|
||||
void furi_hal_rfid_field_detect_start();
|
||||
|
||||
/** Stop/Disable Field Presence detect */
|
||||
void furi_hal_rfid_field_detect_stop();
|
||||
|
||||
/** Check Field Presence
|
||||
*
|
||||
* @param[out] frequency pointer to frequency value to be set if filed detected
|
||||
*
|
||||
* @return true if field is present, false if not
|
||||
*/
|
||||
bool furi_hal_rfid_field_is_present(uint32_t* frequency);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
"assets",
|
||||
"one_wire",
|
||||
"ibutton",
|
||||
"music_worker",
|
||||
"misc",
|
||||
"mbedtls",
|
||||
"lfrfid",
|
||||
|
||||
Reference in New Issue
Block a user