Furi: core refactoring and CMSIS removal part 2 (#1410)
* Furi: rename and move core * Furi: drop CMSIS_OS header and unused api, partially refactor and cleanup the rest * Furi: CMSIS_OS drop and refactoring. * Furi: refactoring, remove cmsis legacy * Furi: fix incorrect assert on queue deallocation, cleanup timer * Furi: improve delay api, get rid of floats * hal: dropped furi_hal_crc * Furi: move DWT based delay to cortex HAL * Furi: update core documentation Co-authored-by: hedger <hedger@nanode.su>
This commit is contained in:
@@ -7,8 +7,9 @@
|
||||
#define TAG "FuriHal"
|
||||
|
||||
void furi_hal_init_early() {
|
||||
furi_hal_cortex_init_early();
|
||||
|
||||
furi_hal_clock_init_early();
|
||||
furi_hal_delay_init();
|
||||
|
||||
furi_hal_resources_init_early();
|
||||
|
||||
|
@@ -2,7 +2,6 @@
|
||||
#include <ble.h>
|
||||
#include <stm32wbxx.h>
|
||||
#include <shci.h>
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
#include <furi_hal_version.h>
|
||||
#include <furi_hal_bt_hid.h>
|
||||
@@ -19,7 +18,7 @@
|
||||
/* Time, in ms, to wait for mode transition before crashing */
|
||||
#define C2_MODE_SWITCH_TIMEOUT 10000
|
||||
|
||||
osMutexId_t furi_hal_bt_core2_mtx = NULL;
|
||||
FuriMutex* furi_hal_bt_core2_mtx = NULL;
|
||||
static FuriHalBtStack furi_hal_bt_stack = FuriHalBtStackUnknown;
|
||||
|
||||
typedef void (*FuriHalBtProfileStart)(void);
|
||||
@@ -79,7 +78,7 @@ FuriHalBtProfileConfig* current_profile = NULL;
|
||||
|
||||
void furi_hal_bt_init() {
|
||||
if(!furi_hal_bt_core2_mtx) {
|
||||
furi_hal_bt_core2_mtx = osMutexNew(NULL);
|
||||
furi_hal_bt_core2_mtx = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
furi_assert(furi_hal_bt_core2_mtx);
|
||||
}
|
||||
|
||||
@@ -94,12 +93,12 @@ void furi_hal_bt_init() {
|
||||
|
||||
void furi_hal_bt_lock_core2() {
|
||||
furi_assert(furi_hal_bt_core2_mtx);
|
||||
furi_check(osMutexAcquire(furi_hal_bt_core2_mtx, osWaitForever) == osOK);
|
||||
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(osMutexRelease(furi_hal_bt_core2_mtx) == osOK);
|
||||
furi_check(furi_mutex_release(furi_hal_bt_core2_mtx) == FuriStatusOk);
|
||||
}
|
||||
|
||||
static bool furi_hal_bt_radio_stack_is_supported(const BleGlueC2Info* info) {
|
||||
@@ -126,7 +125,7 @@ bool furi_hal_bt_start_radio_stack() {
|
||||
bool res = false;
|
||||
furi_assert(furi_hal_bt_core2_mtx);
|
||||
|
||||
osMutexAcquire(furi_hal_bt_core2_mtx, osWaitForever);
|
||||
furi_mutex_acquire(furi_hal_bt_core2_mtx, FuriWaitForever);
|
||||
|
||||
// Explicitly tell that we are in charge of CLK48 domain
|
||||
if(!LL_HSEM_IsSemaphoreLocked(HSEM, CFG_HW_CLK48_CONFIG_SEMID)) {
|
||||
@@ -162,7 +161,7 @@ bool furi_hal_bt_start_radio_stack() {
|
||||
}
|
||||
res = true;
|
||||
} while(false);
|
||||
osMutexRelease(furi_hal_bt_core2_mtx);
|
||||
furi_mutex_release(furi_hal_bt_core2_mtx);
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -255,7 +254,7 @@ void furi_hal_bt_reinit() {
|
||||
FURI_LOG_I(TAG, "Reset SHCI");
|
||||
furi_check(ble_glue_reinit_c2());
|
||||
|
||||
osDelay(100);
|
||||
furi_delay_ms(100);
|
||||
ble_glue_thread_stop();
|
||||
|
||||
FURI_LOG_I(TAG, "Start BT initialization");
|
||||
@@ -292,7 +291,7 @@ void furi_hal_bt_stop_advertising() {
|
||||
if(furi_hal_bt_is_active()) {
|
||||
gap_stop_advertising();
|
||||
while(furi_hal_bt_is_active()) {
|
||||
osDelay(1);
|
||||
furi_delay_tick(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -436,7 +435,7 @@ bool furi_hal_bt_ensure_c2_mode(BleGlueC2Mode mode) {
|
||||
return true;
|
||||
} else if(fw_start_res == BleGlueCommandResultRestartPending) {
|
||||
// Do nothing and wait for system reset
|
||||
osDelay(C2_MODE_SWITCH_TIMEOUT);
|
||||
furi_delay_ms(C2_MODE_SWITCH_TIMEOUT);
|
||||
furi_crash("Waiting for FUS->radio stack transition");
|
||||
return true;
|
||||
}
|
||||
|
20
firmware/targets/f7/furi_hal/furi_hal_cortex.c
Normal file
20
firmware/targets/f7/furi_hal/furi_hal_cortex.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "furi_hal_cortex.h"
|
||||
|
||||
#include <stm32wbxx.h>
|
||||
|
||||
void furi_hal_cortex_init_early() {
|
||||
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
||||
DWT->CYCCNT = 0U;
|
||||
}
|
||||
|
||||
void furi_hal_cortex_delay_us(uint32_t microseconds) {
|
||||
uint32_t start = DWT->CYCCNT;
|
||||
uint32_t time_ticks = SystemCoreClock / 1000000 * microseconds;
|
||||
while((DWT->CYCCNT - start) < time_ticks) {
|
||||
};
|
||||
}
|
||||
|
||||
uint32_t furi_hal_cortex_instructions_per_microsecond() {
|
||||
return SystemCoreClock / 1000000;
|
||||
}
|
@@ -1,93 +0,0 @@
|
||||
#include <furi_hal.h>
|
||||
#include <stm32wbxx_ll_crc.h>
|
||||
|
||||
typedef enum {
|
||||
CRC_State_Reset,
|
||||
CRC_State_Ready,
|
||||
CRC_State_Busy,
|
||||
} CRC_State;
|
||||
|
||||
typedef struct {
|
||||
CRC_State state;
|
||||
osMutexId_t mtx;
|
||||
} HAL_CRC_Control;
|
||||
|
||||
static volatile HAL_CRC_Control hal_crc_control = {
|
||||
.state = CRC_State_Reset,
|
||||
.mtx = NULL,
|
||||
};
|
||||
|
||||
void furi_hal_crc_init(bool synchronize) {
|
||||
/* initialize peripheral with default generating polynomial */
|
||||
LL_CRC_SetInputDataReverseMode(CRC, LL_CRC_INDATA_REVERSE_BYTE);
|
||||
LL_CRC_SetOutputDataReverseMode(CRC, LL_CRC_OUTDATA_REVERSE_BIT);
|
||||
LL_CRC_SetPolynomialCoef(CRC, LL_CRC_DEFAULT_CRC32_POLY);
|
||||
LL_CRC_SetPolynomialSize(CRC, LL_CRC_POLYLENGTH_32B);
|
||||
LL_CRC_SetInitialData(CRC, LL_CRC_DEFAULT_CRC_INITVALUE);
|
||||
|
||||
if(synchronize) {
|
||||
hal_crc_control.mtx = osMutexNew(NULL);
|
||||
}
|
||||
hal_crc_control.state = CRC_State_Ready;
|
||||
}
|
||||
|
||||
void furi_hal_crc_reset() {
|
||||
furi_check(hal_crc_control.state == CRC_State_Ready);
|
||||
if(hal_crc_control.mtx) {
|
||||
furi_check(osMutexGetOwner(hal_crc_control.mtx) == furi_thread_get_current_id());
|
||||
osMutexRelease(hal_crc_control.mtx);
|
||||
}
|
||||
LL_CRC_ResetCRCCalculationUnit(CRC);
|
||||
}
|
||||
|
||||
static uint32_t furi_hal_crc_handle_8(uint8_t pBuffer[], uint32_t BufferLength) {
|
||||
uint32_t i; /* input data buffer index */
|
||||
hal_crc_control.state = CRC_State_Busy;
|
||||
/* Processing time optimization: 4 bytes are entered in a row with a single word write,
|
||||
* last bytes must be carefully fed to the CRC calculator to ensure a correct type
|
||||
* handling by the peripheral */
|
||||
for(i = 0U; i < (BufferLength / 4U); i++) {
|
||||
LL_CRC_FeedData32(
|
||||
CRC,
|
||||
((uint32_t)pBuffer[4U * i] << 24U) | ((uint32_t)pBuffer[(4U * i) + 1U] << 16U) |
|
||||
((uint32_t)pBuffer[(4U * i) + 2U] << 8U) | (uint32_t)pBuffer[(4U * i) + 3U]);
|
||||
}
|
||||
/* last bytes specific handling */
|
||||
if((BufferLength % 4U) != 0U) {
|
||||
if((BufferLength % 4U) == 1U) {
|
||||
LL_CRC_FeedData8(CRC, pBuffer[4U * i]);
|
||||
} else if((BufferLength % 4U) == 2U) {
|
||||
LL_CRC_FeedData16(
|
||||
CRC, ((uint16_t)(pBuffer[4U * i]) << 8U) | (uint16_t)pBuffer[(4U * i) + 1U]);
|
||||
} else if((BufferLength % 4U) == 3U) {
|
||||
LL_CRC_FeedData16(
|
||||
CRC, ((uint16_t)(pBuffer[4U * i]) << 8U) | (uint16_t)pBuffer[(4U * i) + 1U]);
|
||||
LL_CRC_FeedData8(CRC, pBuffer[(4U * i) + 2U]);
|
||||
}
|
||||
}
|
||||
|
||||
hal_crc_control.state = CRC_State_Ready;
|
||||
/* Return the CRC computed value */
|
||||
return LL_CRC_ReadData32(CRC);
|
||||
}
|
||||
|
||||
static uint32_t furi_hal_crc_accumulate(uint32_t pBuffer[], uint32_t BufferLength) {
|
||||
furi_check(hal_crc_control.state == CRC_State_Ready);
|
||||
if(hal_crc_control.mtx) {
|
||||
furi_check(osMutexGetOwner(hal_crc_control.mtx) != NULL);
|
||||
}
|
||||
return furi_hal_crc_handle_8((uint8_t*)pBuffer, BufferLength);
|
||||
}
|
||||
|
||||
uint32_t furi_hal_crc_feed(void* data, uint16_t length) {
|
||||
return ~furi_hal_crc_accumulate(data, length);
|
||||
}
|
||||
|
||||
bool furi_hal_crc_acquire(uint32_t timeout) {
|
||||
furi_assert(hal_crc_control.mtx);
|
||||
if(osMutexAcquire(hal_crc_control.mtx, timeout) == osOK) {
|
||||
LL_CRC_ResetCRCCalculationUnit(CRC);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
@@ -1,35 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Configure for CRC32 calculation
|
||||
* @param synchronize enforce acquisition & release in multithreaded environment
|
||||
*/
|
||||
void furi_hal_crc_init(bool synchronize);
|
||||
|
||||
/** Blocking call to get control of CRC block. Mandatory while RTOS is running
|
||||
* @param timeout time to wait for CRC to be available. Can be osWaitForever
|
||||
* @return bool acquisition success
|
||||
*/
|
||||
bool furi_hal_crc_acquire(uint32_t timeout);
|
||||
|
||||
/** Reset current calculation state and release CRC block
|
||||
*/
|
||||
void furi_hal_crc_reset();
|
||||
|
||||
/** Process data block. Does not reset current state,
|
||||
* allowing to process arbitrary data lengths
|
||||
* @param data pointer to data
|
||||
* @param length data length
|
||||
* @return uint32_t CRC32 value
|
||||
*/
|
||||
uint32_t furi_hal_crc_feed(void* data, uint16_t length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -23,7 +23,7 @@
|
||||
#define CRYPTO_KEYSIZE_256B (AES_CR_KEYSIZE)
|
||||
#define CRYPTO_AES_CBC (AES_CR_CHMOD_0)
|
||||
|
||||
static osMutexId_t furi_hal_crypto_mutex = NULL;
|
||||
static FuriMutex* furi_hal_crypto_mutex = NULL;
|
||||
static bool furi_hal_crypto_mode_init_done = false;
|
||||
|
||||
static const uint8_t enclave_signature_iv[ENCLAVE_FACTORY_KEY_SLOTS][16] = {
|
||||
@@ -66,7 +66,7 @@ static const uint8_t enclave_signature_expected[ENCLAVE_FACTORY_KEY_SLOTS][ENCLA
|
||||
};
|
||||
|
||||
void furi_hal_crypto_init() {
|
||||
furi_hal_crypto_mutex = osMutexNew(NULL);
|
||||
furi_hal_crypto_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot) {
|
||||
furi_assert(key);
|
||||
furi_assert(slot);
|
||||
|
||||
furi_check(osMutexAcquire(furi_hal_crypto_mutex, osWaitForever) == osOK);
|
||||
furi_check(furi_mutex_acquire(furi_hal_crypto_mutex, FuriWaitForever) == FuriStatusOk);
|
||||
|
||||
if(!furi_hal_bt_is_alive()) {
|
||||
return false;
|
||||
@@ -176,7 +176,7 @@ bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot) {
|
||||
memcpy(pParam.KeyData, key->data, key_data_size);
|
||||
|
||||
SHCI_CmdStatus_t shci_state = SHCI_C2_FUS_StoreUsrKey(&pParam, slot);
|
||||
furi_check(osMutexRelease(furi_hal_crypto_mutex) == osOK);
|
||||
furi_check(furi_mutex_release(furi_hal_crypto_mutex) == FuriStatusOk);
|
||||
return (shci_state == SHCI_Success);
|
||||
}
|
||||
|
||||
@@ -239,7 +239,7 @@ static bool crypto_process_block(uint32_t* in, uint32_t* out, uint8_t blk_len) {
|
||||
bool furi_hal_crypto_store_load_key(uint8_t slot, const uint8_t* iv) {
|
||||
furi_assert(slot > 0 && slot <= 100);
|
||||
furi_assert(furi_hal_crypto_mutex);
|
||||
furi_check(osMutexAcquire(furi_hal_crypto_mutex, osWaitForever) == osOK);
|
||||
furi_check(furi_mutex_acquire(furi_hal_crypto_mutex, FuriWaitForever) == FuriStatusOk);
|
||||
|
||||
if(!furi_hal_bt_is_alive()) {
|
||||
return false;
|
||||
@@ -252,7 +252,7 @@ bool furi_hal_crypto_store_load_key(uint8_t slot, const uint8_t* iv) {
|
||||
return true;
|
||||
} else {
|
||||
CLEAR_BIT(AES1->CR, AES_CR_EN);
|
||||
furi_check(osMutexRelease(furi_hal_crypto_mutex) == osOK);
|
||||
furi_check(furi_mutex_release(furi_hal_crypto_mutex) == FuriStatusOk);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -272,7 +272,7 @@ bool furi_hal_crypto_store_unload_key(uint8_t slot) {
|
||||
LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_AES1);
|
||||
FURI_CRITICAL_EXIT();
|
||||
|
||||
furi_check(osMutexRelease(furi_hal_crypto_mutex) == osOK);
|
||||
furi_check(furi_mutex_release(furi_hal_crypto_mutex) == FuriStatusOk);
|
||||
return (shci_state == SHCI_Success);
|
||||
}
|
||||
|
||||
|
@@ -1,45 +0,0 @@
|
||||
#include "furi_hal_delay.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <cmsis_os2.h>
|
||||
#include <stm32wbxx_ll_utils.h>
|
||||
|
||||
#define TAG "FuriHalDelay"
|
||||
|
||||
void furi_hal_delay_init() {
|
||||
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
||||
DWT->CYCCNT = 0U;
|
||||
}
|
||||
|
||||
uint32_t furi_hal_delay_instructions_per_microsecond() {
|
||||
return SystemCoreClock / 1000000;
|
||||
}
|
||||
|
||||
uint32_t furi_hal_get_tick(void) {
|
||||
return osKernelGetTickCount();
|
||||
}
|
||||
|
||||
uint32_t furi_hal_ms_to_ticks(float milliseconds) {
|
||||
return milliseconds / (1000.0f / osKernelGetTickFreq());
|
||||
}
|
||||
|
||||
void furi_hal_delay_us(float microseconds) {
|
||||
uint32_t start = DWT->CYCCNT;
|
||||
uint32_t time_ticks = microseconds * furi_hal_delay_instructions_per_microsecond();
|
||||
while((DWT->CYCCNT - start) < time_ticks) {
|
||||
};
|
||||
}
|
||||
|
||||
// cannot be used in ISR
|
||||
// TODO add delay_ISR variant
|
||||
void furi_hal_delay_ms(float milliseconds) {
|
||||
if(!FURI_IS_ISR() && osKernelGetState() == osKernelRunning) {
|
||||
uint32_t ticks = milliseconds / (1000.0f / osKernelGetTickFreq());
|
||||
osStatus_t result = osDelay(ticks);
|
||||
(void)result;
|
||||
furi_assert(result == osOK);
|
||||
} else {
|
||||
furi_hal_delay_us(milliseconds * 1000);
|
||||
}
|
||||
}
|
@@ -1,5 +1,4 @@
|
||||
#include <furi_hal_i2c.h>
|
||||
#include <furi_hal_delay.h>
|
||||
#include <furi_hal_version.h>
|
||||
#include <furi_hal_power.h>
|
||||
|
||||
@@ -61,11 +60,11 @@ bool furi_hal_i2c_tx(
|
||||
furi_assert(timeout > 0);
|
||||
|
||||
bool ret = true;
|
||||
uint32_t timeout_tick = furi_hal_get_tick() + timeout;
|
||||
uint32_t timeout_tick = furi_get_tick() + timeout;
|
||||
|
||||
do {
|
||||
while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c)) {
|
||||
if(furi_hal_get_tick() >= timeout_tick) {
|
||||
if(furi_get_tick() >= timeout_tick) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
@@ -90,7 +89,7 @@ bool furi_hal_i2c_tx(
|
||||
size--;
|
||||
}
|
||||
|
||||
if(furi_hal_get_tick() >= timeout_tick) {
|
||||
if(furi_get_tick() >= timeout_tick) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
@@ -112,11 +111,11 @@ bool furi_hal_i2c_rx(
|
||||
furi_assert(timeout > 0);
|
||||
|
||||
bool ret = true;
|
||||
uint32_t timeout_tick = furi_hal_get_tick() + timeout;
|
||||
uint32_t timeout_tick = furi_get_tick() + timeout;
|
||||
|
||||
do {
|
||||
while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c)) {
|
||||
if(furi_hal_get_tick() >= timeout_tick) {
|
||||
if(furi_get_tick() >= timeout_tick) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
@@ -141,7 +140,7 @@ bool furi_hal_i2c_rx(
|
||||
size--;
|
||||
}
|
||||
|
||||
if(furi_hal_get_tick() >= timeout_tick) {
|
||||
if(furi_get_tick() >= timeout_tick) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
@@ -176,11 +175,11 @@ bool furi_hal_i2c_is_device_ready(FuriHalI2cBusHandle* handle, uint8_t i2c_addr,
|
||||
furi_assert(timeout > 0);
|
||||
|
||||
bool ret = true;
|
||||
uint32_t timeout_tick = furi_hal_get_tick() + timeout;
|
||||
uint32_t timeout_tick = furi_get_tick() + timeout;
|
||||
|
||||
do {
|
||||
while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c)) {
|
||||
if(furi_hal_get_tick() >= timeout_tick) {
|
||||
if(furi_get_tick() >= timeout_tick) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -191,14 +190,14 @@ bool furi_hal_i2c_is_device_ready(FuriHalI2cBusHandle* handle, uint8_t i2c_addr,
|
||||
|
||||
while((!LL_I2C_IsActiveFlag_NACK(handle->bus->i2c)) &&
|
||||
(!LL_I2C_IsActiveFlag_STOP(handle->bus->i2c))) {
|
||||
if(furi_hal_get_tick() >= timeout_tick) {
|
||||
if(furi_get_tick() >= timeout_tick) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(LL_I2C_IsActiveFlag_NACK(handle->bus->i2c)) {
|
||||
while(!LL_I2C_IsActiveFlag_STOP(handle->bus->i2c)) {
|
||||
if(furi_hal_get_tick() >= timeout_tick) {
|
||||
if(furi_get_tick() >= timeout_tick) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -215,7 +214,7 @@ bool furi_hal_i2c_is_device_ready(FuriHalI2cBusHandle* handle, uint8_t i2c_addr,
|
||||
}
|
||||
|
||||
while(!LL_I2C_IsActiveFlag_STOP(handle->bus->i2c)) {
|
||||
if(furi_hal_get_tick() >= timeout_tick) {
|
||||
if(furi_get_tick() >= timeout_tick) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -309,11 +308,11 @@ bool furi_hal_i2c_write_mem(
|
||||
|
||||
bool ret = true;
|
||||
uint8_t size = len + 1;
|
||||
uint32_t timeout_tick = furi_hal_get_tick() + timeout;
|
||||
uint32_t timeout_tick = furi_get_tick() + timeout;
|
||||
|
||||
do {
|
||||
while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c)) {
|
||||
if(furi_hal_get_tick() >= timeout_tick) {
|
||||
if(furi_get_tick() >= timeout_tick) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
@@ -342,7 +341,7 @@ bool furi_hal_i2c_write_mem(
|
||||
size--;
|
||||
}
|
||||
|
||||
if(furi_hal_get_tick() >= timeout_tick) {
|
||||
if(furi_get_tick() >= timeout_tick) {
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
|
@@ -16,26 +16,27 @@
|
||||
*/
|
||||
#define FURI_HAL_I2C_CONFIG_POWER_I2C_TIMINGS_400 0x00602173
|
||||
|
||||
osMutexId_t furi_hal_i2c_bus_power_mutex = NULL;
|
||||
FuriMutex* furi_hal_i2c_bus_power_mutex = NULL;
|
||||
|
||||
static void furi_hal_i2c_bus_power_event(FuriHalI2cBus* bus, FuriHalI2cBusEvent event) {
|
||||
if(event == FuriHalI2cBusEventInit) {
|
||||
furi_hal_i2c_bus_power_mutex = osMutexNew(NULL);
|
||||
furi_hal_i2c_bus_power_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
FURI_CRITICAL_ENTER();
|
||||
LL_RCC_SetI2CClockSource(LL_RCC_I2C1_CLKSOURCE_PCLK1);
|
||||
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_I2C1);
|
||||
FURI_CRITICAL_EXIT();
|
||||
bus->current_handle = NULL;
|
||||
} else if(event == FuriHalI2cBusEventDeinit) {
|
||||
furi_check(osMutexDelete(furi_hal_i2c_bus_power_mutex) == osOK);
|
||||
furi_mutex_free(furi_hal_i2c_bus_power_mutex);
|
||||
FURI_CRITICAL_ENTER();
|
||||
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_I2C1);
|
||||
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_I2C1);
|
||||
FURI_CRITICAL_EXIT();
|
||||
} else if(event == FuriHalI2cBusEventLock) {
|
||||
furi_check(osMutexAcquire(furi_hal_i2c_bus_power_mutex, osWaitForever) == osOK);
|
||||
furi_check(
|
||||
furi_mutex_acquire(furi_hal_i2c_bus_power_mutex, FuriWaitForever) == FuriStatusOk);
|
||||
} else if(event == FuriHalI2cBusEventUnlock) {
|
||||
furi_check(osMutexRelease(furi_hal_i2c_bus_power_mutex) == osOK);
|
||||
furi_check(furi_mutex_release(furi_hal_i2c_bus_power_mutex) == FuriStatusOk);
|
||||
} else if(event == FuriHalI2cBusEventActivate) {
|
||||
FURI_CRITICAL_ENTER();
|
||||
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_I2C1);
|
||||
@@ -52,26 +53,27 @@ FuriHalI2cBus furi_hal_i2c_bus_power = {
|
||||
.callback = furi_hal_i2c_bus_power_event,
|
||||
};
|
||||
|
||||
osMutexId_t furi_hal_i2c_bus_external_mutex = NULL;
|
||||
FuriMutex* furi_hal_i2c_bus_external_mutex = NULL;
|
||||
|
||||
static void furi_hal_i2c_bus_external_event(FuriHalI2cBus* bus, FuriHalI2cBusEvent event) {
|
||||
if(event == FuriHalI2cBusEventInit) {
|
||||
furi_hal_i2c_bus_external_mutex = osMutexNew(NULL);
|
||||
furi_hal_i2c_bus_external_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
FURI_CRITICAL_ENTER();
|
||||
LL_RCC_SetI2CClockSource(LL_RCC_I2C3_CLKSOURCE_PCLK1);
|
||||
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_I2C3);
|
||||
FURI_CRITICAL_EXIT();
|
||||
bus->current_handle = NULL;
|
||||
} else if(event == FuriHalI2cBusEventDeinit) {
|
||||
furi_check(osMutexDelete(furi_hal_i2c_bus_external_mutex) == osOK);
|
||||
furi_mutex_free(furi_hal_i2c_bus_external_mutex);
|
||||
FURI_CRITICAL_ENTER();
|
||||
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_I2C3);
|
||||
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_I2C3);
|
||||
FURI_CRITICAL_EXIT();
|
||||
} else if(event == FuriHalI2cBusEventLock) {
|
||||
furi_check(osMutexAcquire(furi_hal_i2c_bus_external_mutex, osWaitForever) == osOK);
|
||||
furi_check(
|
||||
furi_mutex_acquire(furi_hal_i2c_bus_external_mutex, FuriWaitForever) == FuriStatusOk);
|
||||
} else if(event == FuriHalI2cBusEventUnlock) {
|
||||
furi_check(osMutexRelease(furi_hal_i2c_bus_external_mutex) == osOK);
|
||||
furi_check(furi_mutex_release(furi_hal_i2c_bus_external_mutex) == FuriStatusOk);
|
||||
} else if(event == FuriHalI2cBusEventActivate) {
|
||||
FURI_CRITICAL_ENTER();
|
||||
LL_RCC_SetI2CClockSource(LL_RCC_I2C3_CLKSOURCE_PCLK1);
|
||||
|
@@ -1,9 +1,7 @@
|
||||
#include "furi_hal_infrared.h"
|
||||
#include "furi_hal_delay.h"
|
||||
#include "furi/check.h"
|
||||
#include <core/check.h>
|
||||
#include "stm32wbxx_ll_dma.h"
|
||||
#include "sys/_stdint.h"
|
||||
#include <cmsis_os2.h>
|
||||
#include <furi_hal_interrupt.h>
|
||||
#include <furi_hal_resources.h>
|
||||
|
||||
@@ -52,7 +50,7 @@ typedef struct {
|
||||
void* data_context;
|
||||
void* signal_sent_context;
|
||||
InfraredTxBuf buffer[2];
|
||||
osSemaphoreId_t stop_semaphore;
|
||||
FuriSemaphore* stop_semaphore;
|
||||
uint32_t
|
||||
tx_timing_rest_duration; /** if timing is too long (> 0xFFFF), send it in few iterations */
|
||||
bool tx_timing_rest_level;
|
||||
@@ -225,8 +223,8 @@ static void furi_hal_infrared_tx_dma_terminate(void) {
|
||||
LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_2);
|
||||
LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_1);
|
||||
LL_TIM_DisableCounter(TIM1);
|
||||
osStatus_t status = osSemaphoreRelease(infrared_tim_tx.stop_semaphore);
|
||||
furi_check(status == osOK);
|
||||
FuriStatus status = furi_semaphore_release(infrared_tim_tx.stop_semaphore);
|
||||
furi_check(status == FuriStatusOk);
|
||||
furi_hal_infrared_state = InfraredStateAsyncTxStopped;
|
||||
}
|
||||
|
||||
@@ -545,15 +543,13 @@ static void furi_hal_infrared_async_tx_free_resources(void) {
|
||||
furi_assert(
|
||||
(furi_hal_infrared_state == InfraredStateIdle) ||
|
||||
(furi_hal_infrared_state == InfraredStateAsyncTxStopped));
|
||||
osStatus_t status;
|
||||
|
||||
furi_hal_gpio_init(&gpio_infrared_tx, GpioModeOutputOpenDrain, GpioPullDown, GpioSpeedLow);
|
||||
furi_hal_interrupt_set_isr(FuriHalInterruptIdDma1Ch1, NULL, NULL);
|
||||
furi_hal_interrupt_set_isr(FuriHalInterruptIdDma1Ch2, NULL, NULL);
|
||||
LL_TIM_DeInit(TIM1);
|
||||
|
||||
status = osSemaphoreDelete(infrared_tim_tx.stop_semaphore);
|
||||
furi_check(status == osOK);
|
||||
furi_semaphore_free(infrared_tim_tx.stop_semaphore);
|
||||
free(infrared_tim_tx.buffer[0].data);
|
||||
free(infrared_tim_tx.buffer[1].data);
|
||||
free(infrared_tim_tx.buffer[0].polarity);
|
||||
@@ -586,7 +582,7 @@ void furi_hal_infrared_async_tx_start(uint32_t freq, float duty_cycle) {
|
||||
infrared_tim_tx.buffer[0].polarity = malloc(alloc_size_polarity);
|
||||
infrared_tim_tx.buffer[1].polarity = malloc(alloc_size_polarity);
|
||||
|
||||
infrared_tim_tx.stop_semaphore = osSemaphoreNew(1, 0, NULL);
|
||||
infrared_tim_tx.stop_semaphore = furi_semaphore_alloc(1, 0);
|
||||
infrared_tim_tx.cycle_duration = 1000000.0 / freq;
|
||||
infrared_tim_tx.tx_timing_rest_duration = 0;
|
||||
|
||||
@@ -603,9 +599,9 @@ void furi_hal_infrared_async_tx_start(uint32_t freq, float duty_cycle) {
|
||||
LL_TIM_ClearFlag_UPDATE(TIM1);
|
||||
LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1);
|
||||
LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_2);
|
||||
furi_hal_delay_us(5);
|
||||
furi_delay_us(5);
|
||||
LL_TIM_GenerateEvent_UPDATE(TIM1); /* DMA -> TIMx_RCR */
|
||||
furi_hal_delay_us(5);
|
||||
furi_delay_us(5);
|
||||
LL_GPIO_ResetOutputPin(
|
||||
gpio_infrared_tx.port, gpio_infrared_tx.pin); /* when disable it prevents false pulse */
|
||||
furi_hal_gpio_init_ex(
|
||||
@@ -621,9 +617,9 @@ void furi_hal_infrared_async_tx_wait_termination(void) {
|
||||
furi_assert(furi_hal_infrared_state >= InfraredStateAsyncTx);
|
||||
furi_assert(furi_hal_infrared_state < InfraredStateMAX);
|
||||
|
||||
osStatus_t status;
|
||||
status = osSemaphoreAcquire(infrared_tim_tx.stop_semaphore, osWaitForever);
|
||||
furi_check(status == osOK);
|
||||
FuriStatus status;
|
||||
status = furi_semaphore_acquire(infrared_tim_tx.stop_semaphore, FuriWaitForever);
|
||||
furi_check(status == FuriStatusOk);
|
||||
furi_hal_infrared_async_tx_free_resources();
|
||||
furi_hal_infrared_state = InfraredStateIdle;
|
||||
}
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#include "furi_hal_interrupt.h"
|
||||
#include "furi_hal_delay.h"
|
||||
#include "furi_hal_os.h"
|
||||
|
||||
#include <furi.h>
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#include "furi/common_defines.h"
|
||||
#include <core/common_defines.h>
|
||||
#include "furi_hal_resources.h"
|
||||
#include <furi_hal_light.h>
|
||||
#include <furi_hal_delay.h>
|
||||
#include <lp5562.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -108,9 +107,9 @@ void furi_hal_light_sequence(const char* sequence) {
|
||||
} else if(*sequence == 'w') {
|
||||
furi_hal_light_set(LightBacklight, 0x00);
|
||||
} else if(*sequence == '.') {
|
||||
furi_hal_delay_ms(250);
|
||||
furi_delay_ms(250);
|
||||
} else if(*sequence == '-') {
|
||||
furi_hal_delay_ms(500);
|
||||
furi_delay_ms(500);
|
||||
}
|
||||
sequence++;
|
||||
} while(*sequence != 0);
|
||||
|
@@ -7,16 +7,16 @@
|
||||
#include <m-string.h>
|
||||
|
||||
#include <lib/digital_signal/digital_signal.h>
|
||||
#include <furi_hal_delay.h>
|
||||
#include <furi_hal_spi.h>
|
||||
#include <furi_hal_gpio.h>
|
||||
#include <furi_hal_cortex.h>
|
||||
#include <furi_hal_resources.h>
|
||||
|
||||
#define TAG "FuriHalNfc"
|
||||
|
||||
static const uint32_t clocks_in_ms = 64 * 1000;
|
||||
|
||||
osEventFlagsId_t event = NULL;
|
||||
FuriEventFlag* event = NULL;
|
||||
#define EVENT_FLAG_INTERRUPT (1UL << 0)
|
||||
#define EVENT_FLAG_STATE_CHANGED (1UL << 1)
|
||||
#define EVENT_FLAG_STOP (1UL << 2)
|
||||
@@ -28,7 +28,7 @@ void furi_hal_nfc_init() {
|
||||
ReturnCode ret = rfalNfcInitialize();
|
||||
if(ret == ERR_NONE) {
|
||||
furi_hal_nfc_start_sleep();
|
||||
event = osEventFlagsNew(NULL);
|
||||
event = furi_event_flag_alloc();
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
} else {
|
||||
FURI_LOG_W(TAG, "Initialization failed, RFAL returned: %d", ret);
|
||||
@@ -109,7 +109,7 @@ bool furi_hal_nfc_detect(FuriHalNfcDevData* nfc_data, uint32_t timeout) {
|
||||
FURI_LOG_T(TAG, "Timeout");
|
||||
break;
|
||||
}
|
||||
osDelay(1);
|
||||
furi_delay_tick(1);
|
||||
}
|
||||
rfalNfcGetDevicesFound(&dev_list, &dev_cnt);
|
||||
if(detected) {
|
||||
@@ -243,7 +243,7 @@ bool furi_hal_nfc_listen(
|
||||
rfalNfcDeactivate(true);
|
||||
return false;
|
||||
}
|
||||
osDelay(1);
|
||||
furi_delay_tick(1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -273,7 +273,7 @@ bool furi_hal_nfc_listen_rx(FuriHalNfcTxRxContext* tx_rx, uint32_t timeout_ms) {
|
||||
furi_assert(tx_rx);
|
||||
|
||||
// Wait for interrupts
|
||||
uint32_t start = osKernelGetTickCount();
|
||||
uint32_t start = furi_get_tick();
|
||||
bool data_received = false;
|
||||
while(true) {
|
||||
if(furi_hal_gpio_read(&gpio_nfc_irq_rfid_pull) == true) {
|
||||
@@ -285,9 +285,9 @@ bool furi_hal_nfc_listen_rx(FuriHalNfcTxRxContext* tx_rx, uint32_t timeout_ms) {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if(osKernelGetTickCount() - start > timeout_ms) {
|
||||
if(furi_get_tick() - start > timeout_ms) {
|
||||
FURI_LOG_T(TAG, "Interrupt waiting timeout");
|
||||
osDelay(1);
|
||||
furi_delay_tick(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -352,17 +352,17 @@ void furi_hal_nfc_listen_start(FuriHalNfcDevData* nfc_data) {
|
||||
}
|
||||
|
||||
void rfal_interrupt_callback_handler() {
|
||||
osEventFlagsSet(event, EVENT_FLAG_INTERRUPT);
|
||||
furi_event_flag_set(event, EVENT_FLAG_INTERRUPT);
|
||||
}
|
||||
|
||||
void rfal_state_changed_callback(void* context) {
|
||||
UNUSED(context);
|
||||
osEventFlagsSet(event, EVENT_FLAG_STATE_CHANGED);
|
||||
furi_event_flag_set(event, EVENT_FLAG_STATE_CHANGED);
|
||||
}
|
||||
|
||||
void furi_hal_nfc_stop() {
|
||||
if(event) {
|
||||
osEventFlagsSet(event, EVENT_FLAG_STOP);
|
||||
furi_event_flag_set(event, EVENT_FLAG_STOP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,8 +405,8 @@ bool furi_hal_nfc_emulate_nfca(
|
||||
while(true) {
|
||||
buff_rx_len = 0;
|
||||
buff_tx_len = 0;
|
||||
uint32_t flag = osEventFlagsWait(event, EVENT_FLAG_ALL, osFlagsWaitAny, timeout);
|
||||
if(flag == osFlagsErrorTimeout || flag == EVENT_FLAG_STOP) {
|
||||
uint32_t flag = furi_event_flag_wait(event, EVENT_FLAG_ALL, FuriFlagWaitAny, timeout);
|
||||
if(flag == FuriFlagErrorTimeout || flag == EVENT_FLAG_STOP) {
|
||||
break;
|
||||
}
|
||||
bool data_received = false;
|
||||
@@ -515,7 +515,7 @@ static bool furi_hal_nfc_transparent_tx_rx(FuriHalNfcTxRxContext* tx_rx, uint16_
|
||||
}
|
||||
}
|
||||
uint32_t timeout = DWT->CYCCNT - start;
|
||||
if(timeout / furi_hal_delay_instructions_per_microsecond() > timeout_ms * 1000) {
|
||||
if(timeout / furi_hal_cortex_instructions_per_microsecond() > timeout_ms * 1000) {
|
||||
FURI_LOG_D(TAG, "Interrupt waiting timeout");
|
||||
break;
|
||||
}
|
||||
@@ -668,7 +668,7 @@ bool furi_hal_nfc_tx_rx(FuriHalNfcTxRxContext* tx_rx, uint16_t timeout_ms) {
|
||||
} else {
|
||||
start = DWT->CYCCNT;
|
||||
}
|
||||
osDelay(1);
|
||||
furi_delay_tick(1);
|
||||
}
|
||||
|
||||
if(tx_rx->tx_rx_type == FuriHalNfcTxRxTypeRaw ||
|
||||
|
@@ -47,8 +47,9 @@ void furi_hal_os_init() {
|
||||
furi_hal_gpio_init_simple(&gpio_ext_pa7, GpioModeOutputPushPull);
|
||||
furi_hal_gpio_init_simple(&gpio_ext_pa6, GpioModeOutputPushPull);
|
||||
furi_hal_gpio_init_simple(&gpio_ext_pa4, GpioModeOutputPushPull);
|
||||
osTimerId_t second_timer = osTimerNew(furi_hal_os_timer_callback, osTimerPeriodic, NULL, NULL);
|
||||
osTimerStart(second_timer, FURI_HAL_OS_TICK_HZ);
|
||||
FuriTimer* second_timer =
|
||||
furi_timer_alloc(furi_hal_os_timer_callback, FuriTimerTypePeriodic, NULL);
|
||||
furi_timer_start(second_timer, FURI_HAL_OS_TICK_HZ);
|
||||
#endif
|
||||
|
||||
FURI_LOG_I(TAG, "Init OK");
|
||||
|
@@ -1,6 +1,5 @@
|
||||
#include <furi_hal_power.h>
|
||||
#include <furi_hal_clock.h>
|
||||
#include <furi_hal_delay.h>
|
||||
#include <furi_hal_bt.h>
|
||||
#include <furi_hal_resources.h>
|
||||
#include <furi_hal_uart.h>
|
||||
@@ -302,7 +301,7 @@ void furi_hal_power_shutdown() {
|
||||
void furi_hal_power_off() {
|
||||
// Crutch: shutting down with ext 3V3 off is causing LSE to stop
|
||||
furi_hal_power_enable_external_3_3v();
|
||||
furi_hal_delay_us(1000);
|
||||
furi_delay_us(1000);
|
||||
// Send poweroff to charger
|
||||
furi_hal_i2c_acquire(&furi_hal_i2c_handle_power);
|
||||
bq25896_poweroff(&furi_hal_i2c_handle_power);
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#include <furi_hal_resources.h>
|
||||
#include <furi_hal_delay.h>
|
||||
#include <furi.h>
|
||||
|
||||
#include <stm32wbxx_ll_rcc.h>
|
||||
@@ -98,7 +97,7 @@ void furi_hal_resources_init_early() {
|
||||
furi_hal_gpio_init_simple(&gpio_usb_dp, GpioModeOutputOpenDrain);
|
||||
furi_hal_gpio_write(&gpio_usb_dm, 0);
|
||||
furi_hal_gpio_write(&gpio_usb_dp, 0);
|
||||
furi_hal_delay_us(5); // Device Driven disconnect: 2.5us + extra to compensate cables
|
||||
furi_delay_us(5); // Device Driven disconnect: 2.5us + extra to compensate cables
|
||||
furi_hal_gpio_write(&gpio_usb_dm, 1);
|
||||
furi_hal_gpio_write(&gpio_usb_dp, 1);
|
||||
furi_hal_gpio_init_simple(&gpio_usb_dm, GpioModeAnalog);
|
||||
|
@@ -70,25 +70,25 @@ const LL_SPI_InitTypeDef furi_hal_spi_preset_1edge_low_2m = {
|
||||
|
||||
/* SPI Buses */
|
||||
|
||||
osMutexId_t furi_hal_spi_bus_r_mutex = NULL;
|
||||
FuriMutex* furi_hal_spi_bus_r_mutex = NULL;
|
||||
|
||||
static void furi_hal_spi_bus_r_event_callback(FuriHalSpiBus* bus, FuriHalSpiBusEvent event) {
|
||||
if(event == FuriHalSpiBusEventInit) {
|
||||
furi_hal_spi_bus_r_mutex = osMutexNew(NULL);
|
||||
furi_hal_spi_bus_r_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
FURI_CRITICAL_ENTER();
|
||||
LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_SPI1);
|
||||
FURI_CRITICAL_EXIT();
|
||||
bus->current_handle = NULL;
|
||||
} else if(event == FuriHalSpiBusEventDeinit) {
|
||||
furi_check(osMutexDelete(furi_hal_spi_bus_r_mutex) == osOK);
|
||||
furi_mutex_free(furi_hal_spi_bus_r_mutex);
|
||||
FURI_CRITICAL_ENTER();
|
||||
LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_SPI1);
|
||||
LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_SPI1);
|
||||
FURI_CRITICAL_EXIT();
|
||||
} else if(event == FuriHalSpiBusEventLock) {
|
||||
furi_check(osMutexAcquire(furi_hal_spi_bus_r_mutex, osWaitForever) == osOK);
|
||||
furi_check(furi_mutex_acquire(furi_hal_spi_bus_r_mutex, FuriWaitForever) == FuriStatusOk);
|
||||
} else if(event == FuriHalSpiBusEventUnlock) {
|
||||
furi_check(osMutexRelease(furi_hal_spi_bus_r_mutex) == osOK);
|
||||
furi_check(furi_mutex_release(furi_hal_spi_bus_r_mutex) == FuriStatusOk);
|
||||
} else if(event == FuriHalSpiBusEventActivate) {
|
||||
FURI_CRITICAL_ENTER();
|
||||
LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_SPI1);
|
||||
@@ -105,25 +105,25 @@ FuriHalSpiBus furi_hal_spi_bus_r = {
|
||||
.callback = furi_hal_spi_bus_r_event_callback,
|
||||
};
|
||||
|
||||
osMutexId_t furi_hal_spi_bus_d_mutex = NULL;
|
||||
FuriMutex* furi_hal_spi_bus_d_mutex = NULL;
|
||||
|
||||
static void furi_hal_spi_bus_d_event_callback(FuriHalSpiBus* bus, FuriHalSpiBusEvent event) {
|
||||
if(event == FuriHalSpiBusEventInit) {
|
||||
furi_hal_spi_bus_d_mutex = osMutexNew(NULL);
|
||||
furi_hal_spi_bus_d_mutex = furi_mutex_alloc(FuriMutexTypeNormal);
|
||||
FURI_CRITICAL_ENTER();
|
||||
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_SPI2);
|
||||
FURI_CRITICAL_EXIT();
|
||||
bus->current_handle = NULL;
|
||||
} else if(event == FuriHalSpiBusEventDeinit) {
|
||||
furi_check(osMutexDelete(furi_hal_spi_bus_d_mutex) == osOK);
|
||||
furi_mutex_free(furi_hal_spi_bus_d_mutex);
|
||||
FURI_CRITICAL_ENTER();
|
||||
LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_SPI2);
|
||||
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_SPI2);
|
||||
FURI_CRITICAL_EXIT();
|
||||
} else if(event == FuriHalSpiBusEventLock) {
|
||||
furi_check(osMutexAcquire(furi_hal_spi_bus_d_mutex, osWaitForever) == osOK);
|
||||
furi_check(furi_mutex_acquire(furi_hal_spi_bus_d_mutex, FuriWaitForever) == FuriStatusOk);
|
||||
} else if(event == FuriHalSpiBusEventUnlock) {
|
||||
furi_check(osMutexRelease(furi_hal_spi_bus_d_mutex) == osOK);
|
||||
furi_check(furi_mutex_release(furi_hal_spi_bus_d_mutex) == FuriStatusOk);
|
||||
} else if(event == FuriHalSpiBusEventActivate) {
|
||||
FURI_CRITICAL_ENTER();
|
||||
LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_SPI2);
|
||||
|
@@ -6,7 +6,6 @@
|
||||
#include <furi_hal_resources.h>
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal_delay.h>
|
||||
|
||||
static bool furi_hal_usart_prev_enabled[2];
|
||||
|
||||
|
@@ -240,8 +240,8 @@ static int32_t furi_hal_usb_thread(void* context) {
|
||||
}
|
||||
|
||||
while(true) {
|
||||
uint32_t flags = furi_thread_flags_wait(USB_SRV_ALL_EVENTS, osFlagsWaitAny, 500);
|
||||
if((flags & osFlagsError) == 0) {
|
||||
uint32_t flags = furi_thread_flags_wait(USB_SRV_ALL_EVENTS, FuriFlagWaitAny, 500);
|
||||
if((flags & FuriFlagError) == 0) {
|
||||
if(flags & EventModeChange) {
|
||||
if(usb.if_next != usb.if_cur) {
|
||||
if_new = usb.if_next;
|
||||
@@ -250,7 +250,7 @@ static int32_t furi_hal_usb_thread(void* context) {
|
||||
susp_evt(&udev, 0, 0);
|
||||
usbd_connect(&udev, false);
|
||||
usb.enabled = false;
|
||||
osDelay(USB_RECONNECT_DELAY);
|
||||
furi_delay_ms(USB_RECONNECT_DELAY);
|
||||
}
|
||||
flags |= EventModeChangeStart;
|
||||
}
|
||||
@@ -267,7 +267,7 @@ static int32_t furi_hal_usb_thread(void* context) {
|
||||
usbd_enable(&udev, true);
|
||||
|
||||
if_new = usb.if_cur;
|
||||
osDelay(USB_RECONNECT_DELAY);
|
||||
furi_delay_ms(USB_RECONNECT_DELAY);
|
||||
flags |= EventModeChangeStart;
|
||||
}
|
||||
if(flags & EventModeChangeStart) { // Second stage of mode change process
|
||||
|
@@ -254,7 +254,7 @@ static bool hid_send_report(uint8_t report_id);
|
||||
static usbd_respond hid_ep_config(usbd_device* dev, uint8_t cfg);
|
||||
static usbd_respond hid_control(usbd_device* dev, usbd_ctlreq* req, usbd_rqc_callback* callback);
|
||||
static usbd_device* usb_dev;
|
||||
static osSemaphoreId_t hid_semaphore = NULL;
|
||||
static FuriSemaphore* hid_semaphore = NULL;
|
||||
static bool hid_connected = false;
|
||||
static HidStateCallback callback;
|
||||
static void* cb_ctx;
|
||||
@@ -372,7 +372,7 @@ static void* hid_set_string_descr(char* str) {
|
||||
static void hid_init(usbd_device* dev, FuriHalUsbInterface* intf, void* ctx) {
|
||||
UNUSED(intf);
|
||||
FuriHalUsbHidConfig* cfg = (FuriHalUsbHidConfig*)ctx;
|
||||
if(hid_semaphore == NULL) hid_semaphore = osSemaphoreNew(1, 1, NULL);
|
||||
if(hid_semaphore == NULL) hid_semaphore = furi_semaphore_alloc(1, 1);
|
||||
usb_dev = dev;
|
||||
hid_report.keyboard.report_id = ReportIdKeyboard;
|
||||
hid_report.mouse.report_id = ReportIdMouse;
|
||||
@@ -428,7 +428,7 @@ static void hid_on_suspend(usbd_device* dev) {
|
||||
UNUSED(dev);
|
||||
if(hid_connected) {
|
||||
hid_connected = false;
|
||||
osSemaphoreRelease(hid_semaphore);
|
||||
furi_semaphore_release(hid_semaphore);
|
||||
if(callback != NULL) {
|
||||
callback(false, cb_ctx);
|
||||
}
|
||||
@@ -438,7 +438,7 @@ static void hid_on_suspend(usbd_device* dev) {
|
||||
static bool hid_send_report(uint8_t report_id) {
|
||||
if((hid_semaphore == NULL) || (hid_connected == false)) return false;
|
||||
|
||||
furi_check(osSemaphoreAcquire(hid_semaphore, osWaitForever) == osOK);
|
||||
furi_check(furi_semaphore_acquire(hid_semaphore, FuriWaitForever) == FuriStatusOk);
|
||||
if(hid_connected == true) {
|
||||
if(report_id == ReportIdKeyboard)
|
||||
usbd_ep_write(usb_dev, HID_EP_IN, &hid_report.keyboard, sizeof(hid_report.keyboard));
|
||||
@@ -454,7 +454,7 @@ static bool hid_send_report(uint8_t report_id) {
|
||||
static void hid_txrx_ep_callback(usbd_device* dev, uint8_t event, uint8_t ep) {
|
||||
UNUSED(dev);
|
||||
if(event == usbd_evt_eptx) {
|
||||
osSemaphoreRelease(hid_semaphore);
|
||||
furi_semaphore_release(hid_semaphore);
|
||||
} else {
|
||||
struct HidReportLED leds;
|
||||
usbd_ep_read(usb_dev, ep, &leds, 2);
|
||||
|
@@ -147,7 +147,7 @@ static usbd_respond hid_u2f_ep_config(usbd_device* dev, uint8_t cfg);
|
||||
static usbd_respond
|
||||
hid_u2f_control(usbd_device* dev, usbd_ctlreq* req, usbd_rqc_callback* callback);
|
||||
static usbd_device* usb_dev;
|
||||
static osSemaphoreId_t hid_u2f_semaphore = NULL;
|
||||
static FuriSemaphore* hid_u2f_semaphore = NULL;
|
||||
static bool hid_u2f_connected = false;
|
||||
|
||||
static HidU2fCallback callback;
|
||||
@@ -193,7 +193,7 @@ static void hid_u2f_init(usbd_device* dev, FuriHalUsbInterface* intf, void* ctx)
|
||||
UNUSED(intf);
|
||||
UNUSED(ctx);
|
||||
if(hid_u2f_semaphore == NULL) {
|
||||
hid_u2f_semaphore = osSemaphoreNew(1, 1, NULL);
|
||||
hid_u2f_semaphore = furi_semaphore_alloc(1, 1);
|
||||
}
|
||||
usb_dev = dev;
|
||||
|
||||
@@ -220,7 +220,7 @@ static void hid_u2f_on_suspend(usbd_device* dev) {
|
||||
UNUSED(dev);
|
||||
if(hid_u2f_connected) {
|
||||
hid_u2f_connected = false;
|
||||
osSemaphoreRelease(hid_u2f_semaphore);
|
||||
furi_semaphore_release(hid_u2f_semaphore);
|
||||
if(callback != NULL) {
|
||||
callback(HidU2fDisconnected, cb_ctx);
|
||||
}
|
||||
@@ -229,7 +229,7 @@ static void hid_u2f_on_suspend(usbd_device* dev) {
|
||||
|
||||
void furi_hal_hid_u2f_send_response(uint8_t* data, uint8_t len) {
|
||||
if((hid_u2f_semaphore == NULL) || (hid_u2f_connected == false)) return;
|
||||
furi_check(osSemaphoreAcquire(hid_u2f_semaphore, osWaitForever) == osOK);
|
||||
furi_check(furi_semaphore_acquire(hid_u2f_semaphore, FuriWaitForever) == FuriStatusOk);
|
||||
if(hid_u2f_connected == true) {
|
||||
usbd_ep_write(usb_dev, HID_EP_OUT, data, len);
|
||||
}
|
||||
@@ -253,7 +253,7 @@ static void hid_u2f_tx_ep_callback(usbd_device* dev, uint8_t event, uint8_t ep)
|
||||
UNUSED(dev);
|
||||
UNUSED(event);
|
||||
UNUSED(ep);
|
||||
osSemaphoreRelease(hid_u2f_semaphore);
|
||||
furi_semaphore_release(hid_u2f_semaphore);
|
||||
}
|
||||
|
||||
static void hid_u2f_txrx_ep_callback(usbd_device* dev, uint8_t event, uint8_t ep) {
|
||||
|
Reference in New Issue
Block a user