Rename api-hal to furi-hal (#629)
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#include "main.h"
|
||||
#include "api-hal-spi.h"
|
||||
#include "furi-hal-spi.h"
|
||||
|
||||
#define SD_DUMMY_BYTE 0xFF
|
||||
|
||||
const uint32_t SpiTimeout = 1000;
|
||||
uint8_t SD_IO_WriteByte(uint8_t Data);
|
||||
static const ApiHalSpiDevice* sd_spi_dev = &api_hal_spi_devices[ApiHalSpiDeviceIdSdCardFast];
|
||||
static const FuriHalSpiDevice* sd_spi_dev = &furi_hal_spi_devices[FuriHalSpiDeviceIdSdCardFast];
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
@@ -18,7 +18,7 @@ static const ApiHalSpiDevice* sd_spi_dev = &api_hal_spi_devices[ApiHalSpiDeviceI
|
||||
*/
|
||||
static void SPIx_Error(void) {
|
||||
/* Re-Initiaize the SPI communication BUS */
|
||||
api_hal_spi_bus_reset(sd_spi_dev->bus);
|
||||
furi_hal_spi_bus_reset(sd_spi_dev->bus);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,7 +29,7 @@ static void SPIx_Error(void) {
|
||||
* @retval None
|
||||
*/
|
||||
static void SPIx_WriteReadData(const uint8_t* DataIn, uint8_t* DataOut, uint16_t DataLength) {
|
||||
bool status = api_hal_spi_bus_trx(sd_spi_dev->bus, (uint8_t*)DataIn, DataOut, DataLength, SpiTimeout);
|
||||
bool status = furi_hal_spi_bus_trx(sd_spi_dev->bus, (uint8_t*)DataIn, DataOut, DataLength, SpiTimeout);
|
||||
|
||||
/* Check the communication status */
|
||||
if(!status) {
|
||||
@@ -46,7 +46,7 @@ static void SPIx_WriteReadData(const uint8_t* DataIn, uint8_t* DataOut, uint16_t
|
||||
__attribute__((unused)) static void SPIx_Write(uint8_t Value) {
|
||||
uint8_t data;
|
||||
|
||||
bool status = api_hal_spi_bus_trx(sd_spi_dev->bus, (uint8_t*)&Value, &data, 1, SpiTimeout);
|
||||
bool status = furi_hal_spi_bus_trx(sd_spi_dev->bus, (uint8_t*)&Value, &data, 1, SpiTimeout);
|
||||
|
||||
/* Check the communication status */
|
||||
if(!status) {
|
||||
|
@@ -92,10 +92,10 @@
|
||||
#include "string.h"
|
||||
#include "stdio.h"
|
||||
#include "spi.h"
|
||||
#include <api-hal-spi.h>
|
||||
#include <api-hal-power.h>
|
||||
#include <api-hal-delay.h>
|
||||
#include <api-hal-sd.h>
|
||||
#include <furi-hal-spi.h>
|
||||
#include <furi-hal-power.h>
|
||||
#include <furi-hal-delay.h>
|
||||
#include <furi-hal-sd.h>
|
||||
|
||||
/** @addtogroup BSP
|
||||
* @{
|
||||
@@ -295,14 +295,14 @@ static uint8_t SD_ReadData(void);
|
||||
*/
|
||||
uint8_t BSP_SD_Init(bool reset_card) {
|
||||
/* Slow speed init */
|
||||
const ApiHalSpiDevice* sd_spi_slow_dev = &api_hal_spi_devices[ApiHalSpiDeviceIdSdCardSlow];
|
||||
api_hal_spi_bus_lock(sd_spi_slow_dev->bus);
|
||||
api_hal_spi_bus_configure(sd_spi_slow_dev->bus, sd_spi_slow_dev->config);
|
||||
const FuriHalSpiDevice* sd_spi_slow_dev = &furi_hal_spi_devices[FuriHalSpiDeviceIdSdCardSlow];
|
||||
furi_hal_spi_bus_lock(sd_spi_slow_dev->bus);
|
||||
furi_hal_spi_bus_configure(sd_spi_slow_dev->bus, sd_spi_slow_dev->config);
|
||||
|
||||
/* We must reset card in spi_lock context */
|
||||
if(reset_card) {
|
||||
/* disable power and set low on all bus pins */
|
||||
api_hal_power_disable_external_3_3v();
|
||||
furi_hal_power_disable_external_3_3v();
|
||||
SD_SPI_Bus_To_Down_State();
|
||||
hal_sd_detect_set_low();
|
||||
delay(250);
|
||||
@@ -310,7 +310,7 @@ uint8_t BSP_SD_Init(bool reset_card) {
|
||||
/* reinit bus and enable power */
|
||||
SD_SPI_Bus_To_Normal_State();
|
||||
hal_sd_detect_init();
|
||||
api_hal_power_enable_external_3_3v();
|
||||
furi_hal_power_enable_external_3_3v();
|
||||
delay(100);
|
||||
}
|
||||
|
||||
@@ -326,7 +326,7 @@ uint8_t BSP_SD_Init(bool reset_card) {
|
||||
if(res == BSP_SD_OK) break;
|
||||
}
|
||||
|
||||
api_hal_spi_bus_unlock(sd_spi_slow_dev->bus);
|
||||
furi_hal_spi_bus_unlock(sd_spi_slow_dev->bus);
|
||||
|
||||
/* SD initialized and set to SPI mode properly */
|
||||
return res;
|
||||
|
@@ -36,7 +36,7 @@
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "user_diskio.h"
|
||||
#include "spi.h"
|
||||
#include "api-hal-spi.h"
|
||||
#include "furi-hal-spi.h"
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
|
||||
@@ -53,7 +53,7 @@ static DSTATUS User_CheckStatus(BYTE lun) {
|
||||
return Stat;
|
||||
}
|
||||
|
||||
static const ApiHalSpiDevice* sd_spi_fast_dev = &api_hal_spi_devices[ApiHalSpiDeviceIdSdCardFast];
|
||||
static const FuriHalSpiDevice* sd_spi_fast_dev = &furi_hal_spi_devices[FuriHalSpiDeviceIdSdCardFast];
|
||||
/* USER CODE END DECL */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
@@ -89,12 +89,12 @@ Diskio_drvTypeDef USER_Driver = {
|
||||
DSTATUS USER_initialize(BYTE pdrv) {
|
||||
/* USER CODE BEGIN INIT */
|
||||
|
||||
api_hal_spi_bus_lock(sd_spi_fast_dev->bus);
|
||||
api_hal_spi_bus_configure(sd_spi_fast_dev->bus, sd_spi_fast_dev->config);
|
||||
furi_hal_spi_bus_lock(sd_spi_fast_dev->bus);
|
||||
furi_hal_spi_bus_configure(sd_spi_fast_dev->bus, sd_spi_fast_dev->config);
|
||||
|
||||
DSTATUS status = User_CheckStatus(pdrv);
|
||||
|
||||
api_hal_spi_bus_unlock(sd_spi_fast_dev->bus);
|
||||
furi_hal_spi_bus_unlock(sd_spi_fast_dev->bus);
|
||||
|
||||
return status;
|
||||
/* USER CODE END INIT */
|
||||
@@ -123,8 +123,8 @@ DRESULT USER_read(BYTE pdrv, BYTE* buff, DWORD sector, UINT count) {
|
||||
/* USER CODE BEGIN READ */
|
||||
DRESULT res = RES_ERROR;
|
||||
|
||||
api_hal_spi_bus_lock(sd_spi_fast_dev->bus);
|
||||
api_hal_spi_bus_configure(sd_spi_fast_dev->bus, sd_spi_fast_dev->config);
|
||||
furi_hal_spi_bus_lock(sd_spi_fast_dev->bus);
|
||||
furi_hal_spi_bus_configure(sd_spi_fast_dev->bus, sd_spi_fast_dev->config);
|
||||
|
||||
if(BSP_SD_ReadBlocks((uint32_t*)buff, (uint32_t)(sector), count, SD_DATATIMEOUT) == MSD_OK) {
|
||||
/* wait until the read operation is finished */
|
||||
@@ -133,7 +133,7 @@ DRESULT USER_read(BYTE pdrv, BYTE* buff, DWORD sector, UINT count) {
|
||||
res = RES_OK;
|
||||
}
|
||||
|
||||
api_hal_spi_bus_unlock(sd_spi_fast_dev->bus);
|
||||
furi_hal_spi_bus_unlock(sd_spi_fast_dev->bus);
|
||||
|
||||
return res;
|
||||
/* USER CODE END READ */
|
||||
@@ -153,8 +153,8 @@ DRESULT USER_write(BYTE pdrv, const BYTE* buff, DWORD sector, UINT count) {
|
||||
/* USER CODE HERE */
|
||||
DRESULT res = RES_ERROR;
|
||||
|
||||
api_hal_spi_bus_lock(sd_spi_fast_dev->bus);
|
||||
api_hal_spi_bus_configure(sd_spi_fast_dev->bus, sd_spi_fast_dev->config);
|
||||
furi_hal_spi_bus_lock(sd_spi_fast_dev->bus);
|
||||
furi_hal_spi_bus_configure(sd_spi_fast_dev->bus, sd_spi_fast_dev->config);
|
||||
|
||||
if(BSP_SD_WriteBlocks((uint32_t*)buff, (uint32_t)(sector), count, SD_DATATIMEOUT) == MSD_OK) {
|
||||
/* wait until the Write operation is finished */
|
||||
@@ -163,7 +163,7 @@ DRESULT USER_write(BYTE pdrv, const BYTE* buff, DWORD sector, UINT count) {
|
||||
res = RES_OK;
|
||||
}
|
||||
|
||||
api_hal_spi_bus_unlock(sd_spi_fast_dev->bus);
|
||||
furi_hal_spi_bus_unlock(sd_spi_fast_dev->bus);
|
||||
|
||||
return res;
|
||||
/* USER CODE END WRITE */
|
||||
@@ -185,8 +185,8 @@ DRESULT USER_ioctl(BYTE pdrv, BYTE cmd, void* buff) {
|
||||
|
||||
if(Stat & STA_NOINIT) return RES_NOTRDY;
|
||||
|
||||
api_hal_spi_bus_lock(sd_spi_fast_dev->bus);
|
||||
api_hal_spi_bus_configure(sd_spi_fast_dev->bus, sd_spi_fast_dev->config);
|
||||
furi_hal_spi_bus_lock(sd_spi_fast_dev->bus);
|
||||
furi_hal_spi_bus_configure(sd_spi_fast_dev->bus, sd_spi_fast_dev->config);
|
||||
|
||||
switch(cmd) {
|
||||
/* Make sure that no pending write process */
|
||||
@@ -219,7 +219,7 @@ DRESULT USER_ioctl(BYTE pdrv, BYTE cmd, void* buff) {
|
||||
res = RES_PARERR;
|
||||
}
|
||||
|
||||
api_hal_spi_bus_unlock(sd_spi_fast_dev->bus);
|
||||
furi_hal_spi_bus_unlock(sd_spi_fast_dev->bus);
|
||||
|
||||
return res;
|
||||
/* USER CODE END IOCTL */
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#include "fatfs/fatfs.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <api-hal.h>
|
||||
#include <furi-hal.h>
|
||||
#include <flipper.h>
|
||||
|
||||
int main(void) {
|
||||
@@ -13,8 +13,8 @@ int main(void) {
|
||||
// Initialize ST HAL
|
||||
HAL_Init();
|
||||
|
||||
// Flipper API HAL
|
||||
api_hal_init();
|
||||
// Flipper FURI HAL
|
||||
furi_hal_init();
|
||||
|
||||
// 3rd party
|
||||
MX_FATFS_Init();
|
||||
|
@@ -51,11 +51,11 @@
|
||||
|
||||
/* USER CODE BEGIN PRIVATE_TYPES */
|
||||
|
||||
extern void _api_hal_vcp_init();
|
||||
extern void _api_hal_vcp_deinit();
|
||||
extern void _api_hal_vcp_control_line(uint8_t state);
|
||||
extern void _api_hal_vcp_rx_callback(char* buffer, size_t size);
|
||||
extern void _api_hal_vcp_tx_complete(size_t size);
|
||||
extern void _furi_hal_vcp_init();
|
||||
extern void _furi_hal_vcp_deinit();
|
||||
extern void _furi_hal_vcp_control_line(uint8_t state);
|
||||
extern void _furi_hal_vcp_rx_callback(char* buffer, size_t size);
|
||||
extern void _furi_hal_vcp_tx_complete(size_t size);
|
||||
|
||||
/* USER CODE END PRIVATE_TYPES */
|
||||
|
||||
@@ -162,7 +162,7 @@ static int8_t CDC_Init_FS(void)
|
||||
/* Set Application Buffers */
|
||||
USBD_CDC_SetTxBuffer(&hUsbDeviceFS, UserTxBufferFS, 0);
|
||||
USBD_CDC_SetRxBuffer(&hUsbDeviceFS, UserRxBufferFS);
|
||||
_api_hal_vcp_init();
|
||||
_furi_hal_vcp_init();
|
||||
return (USBD_OK);
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
@@ -174,7 +174,7 @@ static int8_t CDC_Init_FS(void)
|
||||
static int8_t CDC_DeInit_FS(void)
|
||||
{
|
||||
/* USER CODE BEGIN 4 */
|
||||
_api_hal_vcp_deinit();
|
||||
_furi_hal_vcp_deinit();
|
||||
return (USBD_OK);
|
||||
/* USER CODE END 4 */
|
||||
}
|
||||
@@ -214,7 +214,7 @@ static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
|
||||
/*******************************************************************************/
|
||||
} else if (cmd == CDC_GET_LINE_CODING) {
|
||||
} else if (cmd == CDC_SET_CONTROL_LINE_STATE) {
|
||||
_api_hal_vcp_control_line(((USBD_SetupReqTypedef*)pbuf)->wValue);
|
||||
_furi_hal_vcp_control_line(((USBD_SetupReqTypedef*)pbuf)->wValue);
|
||||
} else if (cmd == CDC_SEND_BREAK) {
|
||||
} else {
|
||||
}
|
||||
@@ -241,7 +241,7 @@ static int8_t CDC_Control_FS(uint8_t cmd, uint8_t* pbuf, uint16_t length)
|
||||
static int8_t CDC_Receive_FS(uint8_t* Buf, uint32_t *Len)
|
||||
{
|
||||
/* USER CODE BEGIN 6 */
|
||||
_api_hal_vcp_rx_callback((char*)Buf, *Len);
|
||||
_furi_hal_vcp_rx_callback((char*)Buf, *Len);
|
||||
USBD_CDC_ReceivePacket(&hUsbDeviceFS);
|
||||
return (USBD_OK);
|
||||
/* USER CODE END 6 */
|
||||
@@ -291,7 +291,7 @@ static int8_t CDC_TransmitCplt_FS(uint8_t *Buf, uint32_t *Len, uint8_t epnum)
|
||||
/* USER CODE BEGIN 13 */
|
||||
UNUSED(Buf);
|
||||
UNUSED(epnum);
|
||||
_api_hal_vcp_tx_complete(*Len);
|
||||
_furi_hal_vcp_tx_complete(*Len);
|
||||
/* USER CODE END 13 */
|
||||
return result;
|
||||
}
|
||||
|
@@ -23,7 +23,7 @@
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_desc.h"
|
||||
#include "usbd_conf.h"
|
||||
#include "api-hal-version.h"
|
||||
#include "furi-hal-version.h"
|
||||
/* USER CODE BEGIN INCLUDE */
|
||||
|
||||
/* USER CODE END INCLUDE */
|
||||
@@ -245,7 +245,7 @@ uint8_t * USBD_CDC_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length
|
||||
*/
|
||||
uint8_t * USBD_CDC_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
USBD_GetString((uint8_t*)api_hal_version_get_device_name_ptr(), USBD_StrDesc, length);
|
||||
USBD_GetString((uint8_t*)furi_hal_version_get_device_name_ptr(), USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
@@ -275,9 +275,9 @@ uint8_t * USBD_CDC_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length
|
||||
|
||||
/* Update the serial number string descriptor with the data from the unique
|
||||
* ID */
|
||||
if(api_hal_version_get_name_ptr()){
|
||||
if(furi_hal_version_get_name_ptr()){
|
||||
char buffer[14] = "flip_";
|
||||
strncat(buffer, api_hal_version_get_name_ptr(), 8);
|
||||
strncat(buffer, furi_hal_version_get_name_ptr(), 8);
|
||||
USBD_GetString((uint8_t*) buffer, USBD_StringSerial, length);
|
||||
} else {
|
||||
Get_SerialNum();
|
||||
|
@@ -1,10 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
/** Initialize clocks */
|
||||
void api_hal_clock_init();
|
||||
|
||||
/** Switch to HSI clock */
|
||||
void api_hal_clock_switch_to_hsi();
|
||||
|
||||
/** Switch to PLL clock */
|
||||
void api_hal_clock_switch_to_pll();
|
@@ -1,88 +0,0 @@
|
||||
#include <api-hal-flash.h>
|
||||
#include <api-hal-bt.h>
|
||||
#include <stm32wbxx.h>
|
||||
#include <furi.h>
|
||||
|
||||
/* Free flash space borders, exported by linker */
|
||||
extern const void __free_flash_start__;
|
||||
extern const void __free_flash_end__;
|
||||
|
||||
#define API_HAL_FLASH_READ_BLOCK 8
|
||||
#define API_HAL_FLASH_WRITE_BLOCK 8
|
||||
#define API_HAL_FLASH_PAGE_SIZE 4096
|
||||
#define API_HAL_FLASH_CYCLES_COUNT 10000
|
||||
|
||||
size_t api_hal_flash_get_base() {
|
||||
return FLASH_BASE;
|
||||
}
|
||||
|
||||
size_t api_hal_flash_get_read_block_size() {
|
||||
return API_HAL_FLASH_READ_BLOCK;
|
||||
}
|
||||
|
||||
size_t api_hal_flash_get_write_block_size() {
|
||||
return API_HAL_FLASH_WRITE_BLOCK;
|
||||
}
|
||||
|
||||
size_t api_hal_flash_get_page_size() {
|
||||
return API_HAL_FLASH_PAGE_SIZE;
|
||||
}
|
||||
|
||||
size_t api_hal_flash_get_cycles_count() {
|
||||
return API_HAL_FLASH_CYCLES_COUNT;
|
||||
}
|
||||
|
||||
const void* api_hal_flash_get_free_start_address() {
|
||||
return &__free_flash_start__;
|
||||
}
|
||||
|
||||
const void* api_hal_flash_get_free_end_address() {
|
||||
return &__free_flash_end__;
|
||||
}
|
||||
|
||||
size_t api_hal_flash_get_free_page_start_address() {
|
||||
size_t start = (size_t)api_hal_flash_get_free_start_address();
|
||||
size_t page_start = start - start % API_HAL_FLASH_PAGE_SIZE;
|
||||
if (page_start != start) {
|
||||
page_start += API_HAL_FLASH_PAGE_SIZE;
|
||||
}
|
||||
return page_start;
|
||||
}
|
||||
|
||||
size_t api_hal_flash_get_free_page_count() {
|
||||
size_t end = (size_t)api_hal_flash_get_free_end_address();
|
||||
size_t page_start = (size_t)api_hal_flash_get_free_page_start_address();
|
||||
return (end-page_start) / API_HAL_FLASH_PAGE_SIZE;
|
||||
}
|
||||
|
||||
bool api_hal_flash_erase(uint8_t page, uint8_t count) {
|
||||
if (!api_hal_bt_lock_flash()) {
|
||||
return false;
|
||||
}
|
||||
FLASH_EraseInitTypeDef erase;
|
||||
erase.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||
erase.Page = page;
|
||||
erase.NbPages = count;
|
||||
uint32_t error;
|
||||
HAL_StatusTypeDef status = HAL_FLASHEx_Erase(&erase, &error);
|
||||
api_hal_bt_unlock_flash();
|
||||
return status == HAL_OK;
|
||||
}
|
||||
|
||||
bool api_hal_flash_write_dword(size_t address, uint64_t data) {
|
||||
if (!api_hal_bt_lock_flash()) {
|
||||
return false;
|
||||
}
|
||||
HAL_StatusTypeDef status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, address, data);
|
||||
api_hal_bt_unlock_flash();
|
||||
return status == HAL_OK;
|
||||
}
|
||||
|
||||
bool api_hal_flash_write_dword_from(size_t address, size_t source_address) {
|
||||
if (!api_hal_bt_lock_flash()) {
|
||||
return false;
|
||||
}
|
||||
HAL_StatusTypeDef status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_FAST, address, source_address);
|
||||
api_hal_bt_unlock_flash();
|
||||
return status == HAL_OK;
|
||||
}
|
@@ -1,64 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <stm32wbxx_ll_lptim.h>
|
||||
#include <stm32wbxx_ll_bus.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// Timer used for system ticks
|
||||
#define API_HAL_OS_TIMER_MAX 0xFFFF
|
||||
#define API_HAL_OS_TIMER_REG_LOAD_DLY 0x1
|
||||
#define API_HAL_OS_TIMER LPTIM2
|
||||
#define API_HAL_OS_TIMER_IRQ LPTIM2_IRQn
|
||||
|
||||
static inline void api_hal_os_timer_init() {
|
||||
// Configure clock source
|
||||
LL_RCC_SetLPTIMClockSource(LL_RCC_LPTIM2_CLKSOURCE_LSE);
|
||||
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_LPTIM2);
|
||||
// Set interrupt priority and enable them
|
||||
NVIC_SetPriority(API_HAL_OS_TIMER_IRQ, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 15, 0));
|
||||
NVIC_EnableIRQ(API_HAL_OS_TIMER_IRQ);
|
||||
}
|
||||
|
||||
static inline void api_hal_os_timer_continuous(uint32_t count) {
|
||||
// Enable timer
|
||||
LL_LPTIM_Enable(API_HAL_OS_TIMER);
|
||||
while(!LL_LPTIM_IsEnabled(API_HAL_OS_TIMER));
|
||||
|
||||
// Enable rutoreload match interrupt
|
||||
LL_LPTIM_EnableIT_ARRM(API_HAL_OS_TIMER);
|
||||
|
||||
// Set autoreload and start counter
|
||||
LL_LPTIM_SetAutoReload(API_HAL_OS_TIMER, count);
|
||||
LL_LPTIM_StartCounter(API_HAL_OS_TIMER, LL_LPTIM_OPERATING_MODE_CONTINUOUS);
|
||||
}
|
||||
|
||||
static inline void api_hal_os_timer_single(uint32_t count) {
|
||||
// Enable timer
|
||||
LL_LPTIM_Enable(API_HAL_OS_TIMER);
|
||||
while(!LL_LPTIM_IsEnabled(API_HAL_OS_TIMER));
|
||||
|
||||
// Enable compare match interrupt
|
||||
LL_LPTIM_EnableIT_CMPM(API_HAL_OS_TIMER);
|
||||
|
||||
// Set compare, autoreload and start counter
|
||||
// Include some marging to workaround ARRM behaviour
|
||||
LL_LPTIM_SetCompare(API_HAL_OS_TIMER, count-3);
|
||||
LL_LPTIM_SetAutoReload(API_HAL_OS_TIMER, count);
|
||||
LL_LPTIM_StartCounter(API_HAL_OS_TIMER, LL_LPTIM_OPERATING_MODE_ONESHOT);
|
||||
}
|
||||
|
||||
static inline void api_hal_os_timer_reset() {
|
||||
// Hard reset timer
|
||||
// THE ONLY RELIABLEWAY to stop it according to errata
|
||||
LL_LPTIM_DeInit(API_HAL_OS_TIMER);
|
||||
}
|
||||
|
||||
static inline uint32_t api_hal_os_timer_get_cnt() {
|
||||
uint32_t counter = LL_LPTIM_GetCounter(API_HAL_OS_TIMER);
|
||||
uint32_t counter_shadow = LL_LPTIM_GetCounter(API_HAL_OS_TIMER);
|
||||
while(counter != counter_shadow) {
|
||||
counter = counter_shadow;
|
||||
counter_shadow = LL_LPTIM_GetCounter(API_HAL_OS_TIMER);
|
||||
}
|
||||
return counter;
|
||||
}
|
@@ -1,67 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <api-hal-gpio.h>
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern const SPI_InitTypeDef api_hal_spi_config_nfc;
|
||||
extern const SPI_InitTypeDef api_hal_spi_config_subghz;
|
||||
extern const SPI_InitTypeDef api_hal_spi_config_display;
|
||||
extern const SPI_InitTypeDef api_hal_spi_config_sd_fast;
|
||||
extern const SPI_InitTypeDef api_hal_spi_config_sd_slow;
|
||||
|
||||
/** API HAL SPI BUS handler
|
||||
* Structure content may change at some point
|
||||
*/
|
||||
typedef struct {
|
||||
const SPI_HandleTypeDef* spi;
|
||||
const osMutexId_t* mutex;
|
||||
const GpioPin* miso;
|
||||
const GpioPin* mosi;
|
||||
const GpioPin* clk;
|
||||
} ApiHalSpiBus;
|
||||
|
||||
/** API HAL SPI Device handler
|
||||
* Structure content may change at some point
|
||||
*/
|
||||
typedef struct {
|
||||
const ApiHalSpiBus* bus;
|
||||
const SPI_InitTypeDef* config;
|
||||
const GpioPin* chip_select;
|
||||
} ApiHalSpiDevice;
|
||||
|
||||
/** API HAL SPI Standard Device IDs */
|
||||
typedef enum {
|
||||
ApiHalSpiDeviceIdSubGhz, /** SubGhz: CC1101, non-standard SPI usage */
|
||||
ApiHalSpiDeviceIdDisplay, /** Display: ERC12864, only have MOSI */
|
||||
ApiHalSpiDeviceIdSdCardFast, /** SDCARD: fast mode, after initialization */
|
||||
ApiHalSpiDeviceIdSdCardSlow, /** SDCARD: slow mode, before initialization */
|
||||
ApiHalSpiDeviceIdNfc, /** NFC: ST25R3916, pretty standard, but RFAL makes it complex */
|
||||
|
||||
ApiHalSpiDeviceIdMax, /** Service Value, do not use */
|
||||
} ApiHalSpiDeviceId;
|
||||
|
||||
/** Api Hal Spi Bus R
|
||||
* CC1101, Nfc
|
||||
*/
|
||||
extern const ApiHalSpiBus spi_r;
|
||||
|
||||
/** Api Hal Spi Bus D
|
||||
* Display, SdCard
|
||||
*/
|
||||
extern const ApiHalSpiBus spi_d;
|
||||
|
||||
/** Api Hal Spi devices */
|
||||
extern const ApiHalSpiDevice api_hal_spi_devices[ApiHalSpiDeviceIdMax];
|
||||
|
||||
typedef struct {
|
||||
const ApiHalSpiBus* bus;
|
||||
const SPI_InitTypeDef config;
|
||||
} SPIDevice;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -1,106 +0,0 @@
|
||||
#include <api-hal-vcp.h>
|
||||
#include <usbd_cdc_if.h>
|
||||
#include <furi.h>
|
||||
#include <stream_buffer.h>
|
||||
|
||||
#define API_HAL_VCP_RX_BUFFER_SIZE 600
|
||||
|
||||
typedef struct {
|
||||
StreamBufferHandle_t rx_stream;
|
||||
osSemaphoreId_t tx_semaphore;
|
||||
volatile bool alive;
|
||||
volatile bool underrun;
|
||||
} ApiHalVcp;
|
||||
|
||||
static ApiHalVcp* api_hal_vcp = NULL;
|
||||
|
||||
static const uint8_t ascii_soh = 0x01;
|
||||
static const uint8_t ascii_eot = 0x04;
|
||||
|
||||
void _api_hal_vcp_init();
|
||||
void _api_hal_vcp_deinit();
|
||||
void _api_hal_vcp_control_line(uint8_t state);
|
||||
void _api_hal_vcp_rx_callback(const uint8_t* buffer, size_t size);
|
||||
void _api_hal_vcp_tx_complete(size_t size);
|
||||
|
||||
void api_hal_vcp_init() {
|
||||
api_hal_vcp = furi_alloc(sizeof(ApiHalVcp));
|
||||
api_hal_vcp->rx_stream = xStreamBufferCreate(API_HAL_VCP_RX_BUFFER_SIZE, 1);
|
||||
api_hal_vcp->tx_semaphore = osSemaphoreNew(1, 1, NULL);
|
||||
api_hal_vcp->alive = false;
|
||||
api_hal_vcp->underrun = false;
|
||||
FURI_LOG_I("FuriHalVcp", "Init OK");
|
||||
}
|
||||
|
||||
void _api_hal_vcp_init() {
|
||||
osSemaphoreRelease(api_hal_vcp->tx_semaphore);
|
||||
}
|
||||
|
||||
void _api_hal_vcp_deinit() {
|
||||
api_hal_vcp->alive = false;
|
||||
osSemaphoreRelease(api_hal_vcp->tx_semaphore);
|
||||
}
|
||||
|
||||
void _api_hal_vcp_control_line(uint8_t state) {
|
||||
// bit 0: DTR state, bit 1: RTS state
|
||||
// bool dtr = state & 0b01;
|
||||
bool dtr = state & 0b1;
|
||||
|
||||
if (dtr) {
|
||||
if (!api_hal_vcp->alive) {
|
||||
api_hal_vcp->alive = true;
|
||||
_api_hal_vcp_rx_callback(&ascii_soh, 1); // SOH
|
||||
}
|
||||
} else {
|
||||
if (api_hal_vcp->alive) {
|
||||
_api_hal_vcp_rx_callback(&ascii_eot, 1); // EOT
|
||||
api_hal_vcp->alive = false;
|
||||
}
|
||||
}
|
||||
|
||||
osSemaphoreRelease(api_hal_vcp->tx_semaphore);
|
||||
}
|
||||
|
||||
void _api_hal_vcp_rx_callback(const uint8_t* buffer, size_t size) {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
size_t ret = xStreamBufferSendFromISR(api_hal_vcp->rx_stream, buffer, size, &xHigherPriorityTaskWoken);
|
||||
if (ret != size) {
|
||||
api_hal_vcp->underrun = true;
|
||||
}
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
void _api_hal_vcp_tx_complete(size_t size) {
|
||||
osSemaphoreRelease(api_hal_vcp->tx_semaphore);
|
||||
}
|
||||
|
||||
size_t api_hal_vcp_rx(uint8_t* buffer, size_t size) {
|
||||
furi_assert(api_hal_vcp);
|
||||
return xStreamBufferReceive(api_hal_vcp->rx_stream, buffer, size, portMAX_DELAY);
|
||||
}
|
||||
|
||||
size_t api_hal_vcp_rx_with_timeout(uint8_t* buffer, size_t size, uint32_t timeout) {
|
||||
furi_assert(api_hal_vcp);
|
||||
return xStreamBufferReceive(api_hal_vcp->rx_stream, buffer, size, timeout);
|
||||
}
|
||||
|
||||
void api_hal_vcp_tx(const uint8_t* buffer, size_t size) {
|
||||
furi_assert(api_hal_vcp);
|
||||
|
||||
while (size > 0 && api_hal_vcp->alive) {
|
||||
furi_check(osSemaphoreAcquire(api_hal_vcp->tx_semaphore, osWaitForever) == osOK);
|
||||
|
||||
size_t batch_size = size;
|
||||
if (batch_size > APP_TX_DATA_SIZE) {
|
||||
batch_size = APP_TX_DATA_SIZE;
|
||||
}
|
||||
|
||||
if (CDC_Transmit_FS((uint8_t*)buffer, batch_size) == USBD_OK) {
|
||||
size -= batch_size;
|
||||
buffer += batch_size;
|
||||
} else {
|
||||
// Shouldn't be there
|
||||
osDelay(100);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,242 +0,0 @@
|
||||
#include <api-hal-version.h>
|
||||
|
||||
#include <furi.h>
|
||||
#include <stm32wbxx.h>
|
||||
#include <stm32wbxx_ll_rtc.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include "ble.h"
|
||||
|
||||
#define API_HAL_VERSION_OTP_HEADER_MAGIC 0xBABE
|
||||
#define API_HAL_VERSION_NAME_LENGTH 8
|
||||
#define API_HAL_VERSION_ARRAY_NAME_LENGTH (API_HAL_VERSION_NAME_LENGTH + 1)
|
||||
/** BLE symbol + "Flipper " + name */
|
||||
#define API_HAL_VERSION_DEVICE_NAME_LENGTH (1 + 8 + API_HAL_VERSION_ARRAY_NAME_LENGTH)
|
||||
#define API_HAL_VERSION_OTP_ADDRESS OTP_AREA_BASE
|
||||
|
||||
/** OTP Versions enum */
|
||||
typedef enum {
|
||||
ApiHalVersionOtpVersion0=0x00,
|
||||
ApiHalVersionOtpVersion1=0x01,
|
||||
ApiHalVersionOtpVersionEmpty=0xFFFFFFFE,
|
||||
ApiHalVersionOtpVersionUnknown=0xFFFFFFFF,
|
||||
} ApiHalVersionOtpVersion;
|
||||
|
||||
/** OTP V0 Structure: prototypes and early EVT */
|
||||
typedef struct {
|
||||
uint8_t board_version;
|
||||
uint8_t board_target;
|
||||
uint8_t board_body;
|
||||
uint8_t board_connect;
|
||||
uint32_t header_timestamp;
|
||||
char name[API_HAL_VERSION_NAME_LENGTH];
|
||||
} ApiHalVersionOTPv0;
|
||||
|
||||
/** OTP V1 Structure: late EVT, DVT, PVT, Production */
|
||||
typedef struct {
|
||||
/* First 64 bits: header */
|
||||
uint16_t header_magic;
|
||||
uint8_t header_version;
|
||||
uint8_t header_reserved;
|
||||
uint32_t header_timestamp;
|
||||
|
||||
/* Second 64 bits: board info */
|
||||
uint8_t board_version; /** Board version */
|
||||
uint8_t board_target; /** Board target firmware */
|
||||
uint8_t board_body; /** Board body */
|
||||
uint8_t board_connect; /** Board interconnect */
|
||||
uint8_t board_color; /** Board color */
|
||||
uint8_t board_region; /** Board region */
|
||||
uint16_t board_reserved; /** Reserved for future use, 0x0000 */
|
||||
|
||||
/* Third 64 bits: Unique Device Name */
|
||||
char name[API_HAL_VERSION_NAME_LENGTH]; /** Unique Device Name */
|
||||
} ApiHalVersionOTPv1;
|
||||
|
||||
/** Represenation Model: */
|
||||
typedef struct {
|
||||
ApiHalVersionOtpVersion otp_version;
|
||||
|
||||
uint32_t timestamp;
|
||||
|
||||
uint8_t board_version; /** Board version */
|
||||
uint8_t board_target; /** Board target firmware */
|
||||
uint8_t board_body; /** Board body */
|
||||
uint8_t board_connect; /** Board interconnect */
|
||||
uint8_t board_color; /** Board color */
|
||||
uint8_t board_region; /** Board region */
|
||||
|
||||
char name[API_HAL_VERSION_ARRAY_NAME_LENGTH]; /** \0 terminated name */
|
||||
char device_name[API_HAL_VERSION_DEVICE_NAME_LENGTH]; /** device name for special needs */
|
||||
uint8_t ble_mac[6];
|
||||
} ApiHalVersion;
|
||||
|
||||
static ApiHalVersion api_hal_version = {0};
|
||||
|
||||
static ApiHalVersionOtpVersion api_hal_version_get_otp_version() {
|
||||
if (*(uint64_t*)API_HAL_VERSION_OTP_ADDRESS == 0xFFFFFFFF) {
|
||||
return ApiHalVersionOtpVersionEmpty;
|
||||
} else {
|
||||
if (((ApiHalVersionOTPv1*)API_HAL_VERSION_OTP_ADDRESS)->header_magic == API_HAL_VERSION_OTP_HEADER_MAGIC) {
|
||||
return ApiHalVersionOtpVersion1;
|
||||
} else if (((ApiHalVersionOTPv0*)API_HAL_VERSION_OTP_ADDRESS)->board_version <= 10) {
|
||||
return ApiHalVersionOtpVersion0;
|
||||
} else {
|
||||
return ApiHalVersionOtpVersionUnknown;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void api_hal_version_set_name(const char* name) {
|
||||
if(name != NULL) {
|
||||
strlcpy(api_hal_version.name, name, API_HAL_VERSION_ARRAY_NAME_LENGTH);
|
||||
snprintf(
|
||||
api_hal_version.device_name,
|
||||
API_HAL_VERSION_DEVICE_NAME_LENGTH,
|
||||
"xFlipper %s",
|
||||
api_hal_version.name);
|
||||
} else {
|
||||
snprintf(
|
||||
api_hal_version.device_name,
|
||||
API_HAL_VERSION_DEVICE_NAME_LENGTH,
|
||||
"xFlipper");
|
||||
}
|
||||
|
||||
api_hal_version.device_name[0] = AD_TYPE_COMPLETE_LOCAL_NAME;
|
||||
|
||||
// BLE Mac address
|
||||
uint32_t udn = LL_FLASH_GetUDN();
|
||||
uint32_t company_id = LL_FLASH_GetSTCompanyID();
|
||||
uint32_t device_id = LL_FLASH_GetDeviceID();
|
||||
api_hal_version.ble_mac[0] = (uint8_t)(udn & 0x000000FF);
|
||||
api_hal_version.ble_mac[1] = (uint8_t)( (udn & 0x0000FF00) >> 8 );
|
||||
api_hal_version.ble_mac[2] = (uint8_t)( (udn & 0x00FF0000) >> 16 );
|
||||
api_hal_version.ble_mac[3] = (uint8_t)device_id;
|
||||
api_hal_version.ble_mac[4] = (uint8_t)(company_id & 0x000000FF);
|
||||
api_hal_version.ble_mac[5] = (uint8_t)( (company_id & 0x0000FF00) >> 8 );
|
||||
}
|
||||
|
||||
static void api_hal_version_load_otp_default() {
|
||||
api_hal_version_set_name(NULL);
|
||||
}
|
||||
|
||||
static void api_hal_version_load_otp_v0() {
|
||||
const ApiHalVersionOTPv0* otp = (ApiHalVersionOTPv0*)API_HAL_VERSION_OTP_ADDRESS;
|
||||
|
||||
api_hal_version.timestamp = otp->header_timestamp;
|
||||
api_hal_version.board_version = otp->board_version;
|
||||
api_hal_version.board_target = otp->board_target;
|
||||
api_hal_version.board_body = otp->board_body;
|
||||
api_hal_version.board_connect = otp->board_connect;
|
||||
api_hal_version.board_color = 0;
|
||||
api_hal_version.board_region = 0;
|
||||
|
||||
api_hal_version_set_name(otp->name);
|
||||
}
|
||||
|
||||
static void api_hal_version_load_otp_v1() {
|
||||
const ApiHalVersionOTPv1* otp = (ApiHalVersionOTPv1*)API_HAL_VERSION_OTP_ADDRESS;
|
||||
|
||||
api_hal_version.timestamp = otp->header_timestamp;
|
||||
api_hal_version.board_version = otp->board_version;
|
||||
api_hal_version.board_target = otp->board_target;
|
||||
api_hal_version.board_body = otp->board_body;
|
||||
api_hal_version.board_connect = otp->board_connect;
|
||||
api_hal_version.board_color = otp->board_color;
|
||||
api_hal_version.board_region = otp->board_region;
|
||||
|
||||
api_hal_version_set_name(otp->name);
|
||||
}
|
||||
|
||||
void api_hal_version_init() {
|
||||
api_hal_version.otp_version = api_hal_version_get_otp_version();
|
||||
switch(api_hal_version.otp_version) {
|
||||
case ApiHalVersionOtpVersionUnknown:
|
||||
api_hal_version_load_otp_default();
|
||||
break;
|
||||
case ApiHalVersionOtpVersionEmpty:
|
||||
api_hal_version_load_otp_default();
|
||||
break;
|
||||
case ApiHalVersionOtpVersion0:
|
||||
api_hal_version_load_otp_v0();
|
||||
break;
|
||||
case ApiHalVersionOtpVersion1:
|
||||
api_hal_version_load_otp_v1();
|
||||
break;
|
||||
default: furi_check(0);
|
||||
}
|
||||
FURI_LOG_I("FuriHalVersion", "Init OK");
|
||||
}
|
||||
|
||||
bool api_hal_version_do_i_belong_here() {
|
||||
return api_hal_version_get_hw_target() == 6;
|
||||
}
|
||||
|
||||
const char* api_hal_version_get_model_name() {
|
||||
return "Flipper Zero";
|
||||
}
|
||||
|
||||
const uint8_t api_hal_version_get_hw_version() {
|
||||
return api_hal_version.board_version;
|
||||
}
|
||||
|
||||
const uint8_t api_hal_version_get_hw_target() {
|
||||
return api_hal_version.board_target;
|
||||
}
|
||||
|
||||
const uint8_t api_hal_version_get_hw_body() {
|
||||
return api_hal_version.board_body;
|
||||
}
|
||||
|
||||
const ApiHalVersionColor api_hal_version_get_hw_color() {
|
||||
return api_hal_version.board_color;
|
||||
}
|
||||
|
||||
const uint8_t api_hal_version_get_hw_connect() {
|
||||
return api_hal_version.board_connect;
|
||||
}
|
||||
|
||||
const ApiHalVersionRegion api_hal_version_get_hw_region() {
|
||||
return api_hal_version.board_region;
|
||||
}
|
||||
|
||||
const uint32_t api_hal_version_get_hw_timestamp() {
|
||||
return api_hal_version.timestamp;
|
||||
}
|
||||
|
||||
const char* api_hal_version_get_name_ptr() {
|
||||
return *api_hal_version.name == 0x00 ? NULL : api_hal_version.name;
|
||||
}
|
||||
|
||||
const char* api_hal_version_get_device_name_ptr() {
|
||||
return api_hal_version.device_name + 1;
|
||||
}
|
||||
|
||||
const char* api_hal_version_get_ble_local_device_name_ptr() {
|
||||
return api_hal_version.device_name;
|
||||
}
|
||||
|
||||
const uint8_t* api_hal_version_get_ble_mac() {
|
||||
return api_hal_version.ble_mac;
|
||||
}
|
||||
|
||||
const struct Version* api_hal_version_get_firmware_version(void) {
|
||||
return version_get();
|
||||
}
|
||||
|
||||
const struct Version* api_hal_version_get_boot_version(void) {
|
||||
#ifdef NO_BOOTLOADER
|
||||
return 0;
|
||||
#else
|
||||
/* Backup register which points to structure in flash memory */
|
||||
return (const struct Version*)LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR1);
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t api_hal_version_uid_size() {
|
||||
return 64/8;
|
||||
}
|
||||
|
||||
const uint8_t* api_hal_version_uid() {
|
||||
return (const uint8_t *)UID64_BASE;
|
||||
}
|
@@ -14,7 +14,7 @@
|
||||
#include "dis_app.h"
|
||||
#include "hrs_app.h"
|
||||
|
||||
#include <api-hal.h>
|
||||
#include <furi-hal.h>
|
||||
|
||||
typedef struct _tSecurityParams {
|
||||
uint8_t ioCapability;
|
||||
@@ -223,7 +223,7 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt )
|
||||
}
|
||||
/* restart advertising */
|
||||
Adv_Request(APP_BLE_FAST_ADV);
|
||||
api_hal_power_insomnia_exit();
|
||||
furi_hal_power_insomnia_exit();
|
||||
}
|
||||
break; /* EVT_DISCONN_COMPLETE */
|
||||
|
||||
@@ -272,7 +272,7 @@ SVCCTL_UserEvtFlowStatus_t SVCCTL_App_Notification( void *pckt )
|
||||
break;
|
||||
case EVT_LE_CONN_COMPLETE:
|
||||
{
|
||||
api_hal_power_insomnia_enter();
|
||||
furi_hal_power_insomnia_enter();
|
||||
hci_le_connection_complete_event_rp0 *connection_complete_event;
|
||||
|
||||
/**
|
||||
@@ -538,7 +538,7 @@ static void Ble_Hci_Gap_Gatt_Init() {
|
||||
|
||||
if (role > 0)
|
||||
{
|
||||
const char *name = api_hal_version_get_device_name_ptr();
|
||||
const char *name = furi_hal_version_get_device_name_ptr();
|
||||
aci_gap_init(role, 0,
|
||||
strlen(name),
|
||||
&gap_service_handle, &gap_dev_name_char_handle, &gap_appearance_char_handle);
|
||||
@@ -640,7 +640,7 @@ static void Adv_Request(APP_BLE_ConnStatus_t New_Status)
|
||||
|
||||
BleApplicationContext.Device_Connection_Status = New_Status;
|
||||
|
||||
const char* name = api_hal_version_get_ble_local_device_name_ptr();
|
||||
const char* name = furi_hal_version_get_ble_local_device_name_ptr();
|
||||
|
||||
/* Start Fast or Low Power Advertising */
|
||||
ret = aci_gap_set_discoverable(
|
||||
|
@@ -27,7 +27,7 @@
|
||||
#include "shci.h"
|
||||
#include "tl.h"
|
||||
#include "dbg_trace.h"
|
||||
#include <api-hal.h>
|
||||
#include <furi-hal.h>
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@@ -358,7 +358,7 @@ void DbgOutputInit( void )
|
||||
|
||||
void DbgOutputTraces( uint8_t *p_data, uint16_t size, void (*cb)(void) )
|
||||
{
|
||||
api_hal_console_tx(p_data, size);
|
||||
furi_hal_console_tx(p_data, size);
|
||||
cb();
|
||||
}
|
||||
#endif
|
||||
|
@@ -8,7 +8,7 @@
|
||||
#include "shci_tl.h"
|
||||
#include "stm32_lpm.h"
|
||||
#include "app_debug.h"
|
||||
#include <api-hal.h>
|
||||
#include <furi-hal.h>
|
||||
|
||||
extern RTC_HandleTypeDef hrtc;
|
||||
|
||||
@@ -52,7 +52,7 @@ void APPE_Init() {
|
||||
HW_TS_Init(hw_ts_InitMode_Full, &hrtc); /**< Initialize the TimerServer */
|
||||
|
||||
// APPD_Init();
|
||||
api_hal_power_insomnia_enter();
|
||||
furi_hal_power_insomnia_enter();
|
||||
|
||||
appe_Tl_Init(); /* Initialize all transport layers */
|
||||
|
||||
@@ -144,7 +144,7 @@ static void APPE_SysUserEvtRx( void * pPayload ) {
|
||||
} else {
|
||||
ble_glue_status = BleGlueStatusBroken;
|
||||
}
|
||||
api_hal_power_insomnia_exit();
|
||||
furi_hal_power_insomnia_exit();
|
||||
}
|
||||
|
||||
/*************************************************************
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include "app_common.h"
|
||||
#include "ble.h"
|
||||
#include "dis_app.h"
|
||||
#include <api-hal-version.h>
|
||||
#include <furi-hal-version.h>
|
||||
|
||||
#if ((BLE_CFG_DIS_SYSTEM_ID != 0) || (CFG_MENU_DEVICE_INFORMATION != 0))
|
||||
static const uint8_t system_id[BLE_CFG_DIS_SYSTEM_ID_LEN_MAX] = {
|
||||
@@ -58,7 +58,7 @@ void DISAPP_Init(void) {
|
||||
* @param pPData
|
||||
* @return
|
||||
*/
|
||||
const char* name = api_hal_version_get_device_name_ptr();
|
||||
const char* name = furi_hal_version_get_device_name_ptr();
|
||||
dis_information_data.pPayload = (uint8_t*)name;
|
||||
dis_information_data.Length = strlen(name) + 1;
|
||||
DIS_UpdateChar(MODEL_NUMBER_UUID, &dis_information_data);
|
||||
|
@@ -66,7 +66,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#if (TL_SHCI_CMD_DBG_RAW_EN != 0)
|
||||
#define TL_SHCI_CMD_DBG_RAW(_PDATA_, _SIZE_) api_hal_console_tx(_PDATA_, _SIZE_)
|
||||
#define TL_SHCI_CMD_DBG_RAW(_PDATA_, _SIZE_) furi_hal_console_tx(_PDATA_, _SIZE_)
|
||||
#else
|
||||
#define TL_SHCI_CMD_DBG_RAW(...)
|
||||
#endif
|
||||
@@ -80,7 +80,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#if (TL_SHCI_EVT_DBG_RAW_EN != 0)
|
||||
#define TL_SHCI_EVT_DBG_RAW(_PDATA_, _SIZE_) api_hal_console_tx(_PDATA_, _SIZE_)
|
||||
#define TL_SHCI_EVT_DBG_RAW(_PDATA_, _SIZE_) furi_hal_console_tx(_PDATA_, _SIZE_)
|
||||
#else
|
||||
#define TL_SHCI_EVT_DBG_RAW(...)
|
||||
#endif
|
||||
@@ -97,7 +97,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#if (TL_HCI_CMD_DBG_RAW_EN != 0)
|
||||
#define TL_HCI_CMD_DBG_RAW(_PDATA_, _SIZE_) api_hal_console_tx(_PDATA_, _SIZE_)
|
||||
#define TL_HCI_CMD_DBG_RAW(_PDATA_, _SIZE_) furi_hal_console_tx(_PDATA_, _SIZE_)
|
||||
#else
|
||||
#define TL_HCI_CMD_DBG_RAW(...)
|
||||
#endif
|
||||
@@ -111,7 +111,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#if (TL_HCI_EVT_DBG_RAW_EN != 0)
|
||||
#define TL_HCI_EVT_DBG_RAW(_PDATA_, _SIZE_) api_hal_console_tx(_PDATA_, _SIZE_)
|
||||
#define TL_HCI_EVT_DBG_RAW(_PDATA_, _SIZE_) furi_hal_console_tx(_PDATA_, _SIZE_)
|
||||
#else
|
||||
#define TL_HCI_EVT_DBG_RAW(...)
|
||||
#endif
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#include <api-hal-boot.h>
|
||||
#include <furi-hal-boot.h>
|
||||
#include <stm32wbxx_ll_rtc.h>
|
||||
#include <furi.h>
|
||||
|
||||
@@ -7,25 +7,25 @@
|
||||
#define BOOT_REQUEST_CLEAN 0xDADEDADE
|
||||
#define BOOT_REQUEST_DFU 0xDF00B000
|
||||
|
||||
void api_hal_boot_init() {
|
||||
void furi_hal_boot_init() {
|
||||
#ifndef DEBUG
|
||||
LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, BOOT_REQUEST_TAINTED);
|
||||
#endif
|
||||
FURI_LOG_I("FuriHalBoot", "Init OK");
|
||||
}
|
||||
|
||||
void api_hal_boot_set_mode(ApiHalBootMode mode) {
|
||||
if (mode == ApiHalBootModeNormal) {
|
||||
void furi_hal_boot_set_mode(FuriHalBootMode mode) {
|
||||
if (mode == FuriHalBootModeNormal) {
|
||||
LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, BOOT_REQUEST_CLEAN);
|
||||
} else if (mode == ApiHalBootModeDFU) {
|
||||
} else if (mode == FuriHalBootModeDFU) {
|
||||
LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR0, BOOT_REQUEST_DFU);
|
||||
}
|
||||
}
|
||||
|
||||
void api_hal_boot_set_flags(ApiHalBootFlag flags) {
|
||||
void furi_hal_boot_set_flags(FuriHalBootFlag flags) {
|
||||
LL_RTC_BAK_SetRegister(RTC, LL_RTC_BKP_DR2, flags);
|
||||
}
|
||||
|
||||
ApiHalBootFlag api_hal_boot_get_flags() {
|
||||
FuriHalBootFlag furi_hal_boot_get_flags() {
|
||||
return LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR2);
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
#include <api-hal-bt.h>
|
||||
#include <furi-hal-bt.h>
|
||||
#include <app_entry.h>
|
||||
#include <ble.h>
|
||||
#include <stm32wbxx.h>
|
||||
@@ -6,18 +6,18 @@
|
||||
#include <cmsis_os2.h>
|
||||
#include <app_ble.h>
|
||||
|
||||
void api_hal_bt_init() {
|
||||
void furi_hal_bt_init() {
|
||||
// Explicitly tell that we are in charge of CLK48 domain
|
||||
HAL_HSEM_FastTake(CFG_HW_CLK48_CONFIG_SEMID);
|
||||
// Start Core2, init HCI and start GAP/GATT
|
||||
APPE_Init();
|
||||
}
|
||||
|
||||
bool api_hal_bt_start_app() {
|
||||
bool furi_hal_bt_start_app() {
|
||||
return APP_BLE_Start();
|
||||
}
|
||||
|
||||
void api_hal_bt_dump_state(string_t buffer) {
|
||||
void furi_hal_bt_dump_state(string_t buffer) {
|
||||
BleGlueStatus status = APPE_Status();
|
||||
if (status == BleGlueStatusStarted) {
|
||||
uint8_t HCI_Version;
|
||||
@@ -39,11 +39,11 @@ void api_hal_bt_dump_state(string_t buffer) {
|
||||
}
|
||||
}
|
||||
|
||||
bool api_hal_bt_is_alive() {
|
||||
bool furi_hal_bt_is_alive() {
|
||||
return APPE_Status() == BleGlueStatusStarted;
|
||||
}
|
||||
|
||||
bool api_hal_bt_wait_transition() {
|
||||
bool furi_hal_bt_wait_transition() {
|
||||
uint8_t counter = 0;
|
||||
while (APPE_Status() == BleGlueStatusStartup) {
|
||||
osDelay(10);
|
||||
@@ -55,8 +55,8 @@ bool api_hal_bt_wait_transition() {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool api_hal_bt_lock_flash() {
|
||||
if (!api_hal_bt_wait_transition()) {
|
||||
bool furi_hal_bt_lock_flash() {
|
||||
if (!furi_hal_bt_wait_transition()) {
|
||||
return false;
|
||||
}
|
||||
if (APPE_Status() == BleGlueStatusUninitialized) {
|
||||
@@ -72,7 +72,7 @@ bool api_hal_bt_lock_flash() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void api_hal_bt_unlock_flash() {
|
||||
void furi_hal_bt_unlock_flash() {
|
||||
if (APPE_Status() == BleGlueStatusUninitialized) {
|
||||
HAL_FLASH_Lock();
|
||||
} else {
|
||||
@@ -82,34 +82,34 @@ void api_hal_bt_unlock_flash() {
|
||||
}
|
||||
}
|
||||
|
||||
void api_hal_bt_start_tone_tx(uint8_t channel, uint8_t power) {
|
||||
void furi_hal_bt_start_tone_tx(uint8_t channel, uint8_t power) {
|
||||
aci_hal_set_tx_power_level(0, power);
|
||||
aci_hal_tone_start(channel, 0);
|
||||
}
|
||||
|
||||
void api_hal_bt_stop_tone_tx() {
|
||||
void furi_hal_bt_stop_tone_tx() {
|
||||
aci_hal_tone_stop();
|
||||
}
|
||||
|
||||
void api_hal_bt_start_packet_tx(uint8_t channel, uint8_t pattern, uint8_t datarate) {
|
||||
void furi_hal_bt_start_packet_tx(uint8_t channel, uint8_t pattern, uint8_t datarate) {
|
||||
hci_le_enhanced_transmitter_test(channel, 0x25, pattern, datarate);
|
||||
}
|
||||
|
||||
void api_hal_bt_start_packet_rx(uint8_t channel, uint8_t datarate) {
|
||||
void furi_hal_bt_start_packet_rx(uint8_t channel, uint8_t datarate) {
|
||||
hci_le_enhanced_receiver_test(channel, datarate, 0);
|
||||
}
|
||||
|
||||
uint16_t api_hal_bt_stop_packet_test() {
|
||||
uint16_t furi_hal_bt_stop_packet_test() {
|
||||
uint16_t num_of_packets;
|
||||
hci_le_test_end(&num_of_packets);
|
||||
return num_of_packets;
|
||||
}
|
||||
|
||||
void api_hal_bt_start_rx(uint8_t channel) {
|
||||
void furi_hal_bt_start_rx(uint8_t channel) {
|
||||
aci_hal_rx_start(channel);
|
||||
}
|
||||
|
||||
float api_hal_bt_get_rssi() {
|
||||
float furi_hal_bt_get_rssi() {
|
||||
float val;
|
||||
uint8_t rssi_raw[3];
|
||||
|
||||
@@ -133,12 +133,12 @@ float api_hal_bt_get_rssi() {
|
||||
return val;
|
||||
}
|
||||
|
||||
uint32_t api_hal_bt_get_transmitted_packets() {
|
||||
uint32_t furi_hal_bt_get_transmitted_packets() {
|
||||
uint32_t packets = 0;
|
||||
aci_hal_le_tx_test_packet_number(&packets);
|
||||
return packets;
|
||||
}
|
||||
|
||||
void api_hal_bt_stop_rx() {
|
||||
void furi_hal_bt_stop_rx() {
|
||||
aci_hal_rx_stop();
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
#include <api-hal-clock.h>
|
||||
#include <furi-hal-clock.h>
|
||||
|
||||
#include <main.h>
|
||||
#include <stm32wbxx_ll_pwr.h>
|
||||
@@ -8,7 +8,7 @@
|
||||
#define HS_CLOCK_IS_READY() (LL_RCC_HSE_IsReady() && LL_RCC_HSI_IsReady())
|
||||
#define LS_CLOCK_IS_READY() (LL_RCC_LSE_IsReady() && LL_RCC_LSI1_IsReady())
|
||||
|
||||
void api_hal_clock_init() {
|
||||
void furi_hal_clock_init() {
|
||||
/* Prepare Flash memory for 64mHz system clock */
|
||||
LL_FLASH_SetLatency(LL_FLASH_LATENCY_3);
|
||||
while(LL_FLASH_GetLatency() != LL_FLASH_LATENCY_3);
|
||||
@@ -113,7 +113,7 @@ void api_hal_clock_init() {
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
|
||||
}
|
||||
|
||||
void api_hal_clock_switch_to_hsi() {
|
||||
void furi_hal_clock_switch_to_hsi() {
|
||||
LL_RCC_HSI_Enable( );
|
||||
|
||||
while(!LL_RCC_HSI_IsReady());
|
||||
@@ -124,7 +124,7 @@ void api_hal_clock_switch_to_hsi() {
|
||||
while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_HSI);
|
||||
}
|
||||
|
||||
void api_hal_clock_switch_to_pll() {
|
||||
void furi_hal_clock_switch_to_pll() {
|
||||
LL_RCC_HSE_Enable();
|
||||
LL_RCC_PLL_Enable();
|
||||
|
10
firmware/targets/f6/furi-hal/furi-hal-clock.h
Normal file
10
firmware/targets/f6/furi-hal/furi-hal-clock.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
/** Initialize clocks */
|
||||
void furi_hal_clock_init();
|
||||
|
||||
/** Switch to HSI clock */
|
||||
void furi_hal_clock_switch_to_hsi();
|
||||
|
||||
/** Switch to PLL clock */
|
||||
void furi_hal_clock_switch_to_pll();
|
@@ -1,4 +1,4 @@
|
||||
#include <api-hal-console.h>
|
||||
#include <furi-hal-console.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stm32wbxx_ll_gpio.h>
|
||||
@@ -6,9 +6,9 @@
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
volatile bool api_hal_console_alive = false;
|
||||
volatile bool furi_hal_console_alive = false;
|
||||
|
||||
void api_hal_console_init() {
|
||||
void furi_hal_console_init() {
|
||||
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
GPIO_InitStruct.Pin = LL_GPIO_PIN_6|LL_GPIO_PIN_7;
|
||||
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
|
||||
@@ -35,13 +35,13 @@ void api_hal_console_init() {
|
||||
LL_USART_Enable(USART1);
|
||||
|
||||
while(!LL_USART_IsActiveFlag_TEACK(USART1)) ;
|
||||
api_hal_console_alive = true;
|
||||
furi_hal_console_alive = true;
|
||||
|
||||
FURI_LOG_I("FuriHalConsole", "Init OK");
|
||||
}
|
||||
|
||||
void api_hal_console_tx(const uint8_t* buffer, size_t buffer_size) {
|
||||
if (!api_hal_console_alive)
|
||||
void furi_hal_console_tx(const uint8_t* buffer, size_t buffer_size) {
|
||||
if (!furi_hal_console_alive)
|
||||
return;
|
||||
|
||||
while(buffer_size > 0) {
|
@@ -7,9 +7,9 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void api_hal_console_init();
|
||||
void furi_hal_console_init();
|
||||
|
||||
void api_hal_console_tx(const uint8_t* buffer, size_t buffer_size);
|
||||
void furi_hal_console_tx(const uint8_t* buffer, size_t buffer_size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
@@ -1,11 +1,11 @@
|
||||
#include "api-hal-delay.h"
|
||||
#include "furi-hal-delay.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
static uint32_t clk_per_microsecond;
|
||||
|
||||
void api_hal_delay_init(void) {
|
||||
void furi_hal_delay_init(void) {
|
||||
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
||||
DWT->CYCCNT = 0U;
|
88
firmware/targets/f6/furi-hal/furi-hal-flash.c
Normal file
88
firmware/targets/f6/furi-hal/furi-hal-flash.c
Normal file
@@ -0,0 +1,88 @@
|
||||
#include <furi-hal-flash.h>
|
||||
#include <furi-hal-bt.h>
|
||||
#include <stm32wbxx.h>
|
||||
#include <furi.h>
|
||||
|
||||
/* Free flash space borders, exported by linker */
|
||||
extern const void __free_flash_start__;
|
||||
extern const void __free_flash_end__;
|
||||
|
||||
#define FURI_HAL_FLASH_READ_BLOCK 8
|
||||
#define FURI_HAL_FLASH_WRITE_BLOCK 8
|
||||
#define FURI_HAL_FLASH_PAGE_SIZE 4096
|
||||
#define FURI_HAL_FLASH_CYCLES_COUNT 10000
|
||||
|
||||
size_t furi_hal_flash_get_base() {
|
||||
return FLASH_BASE;
|
||||
}
|
||||
|
||||
size_t furi_hal_flash_get_read_block_size() {
|
||||
return FURI_HAL_FLASH_READ_BLOCK;
|
||||
}
|
||||
|
||||
size_t furi_hal_flash_get_write_block_size() {
|
||||
return FURI_HAL_FLASH_WRITE_BLOCK;
|
||||
}
|
||||
|
||||
size_t furi_hal_flash_get_page_size() {
|
||||
return FURI_HAL_FLASH_PAGE_SIZE;
|
||||
}
|
||||
|
||||
size_t furi_hal_flash_get_cycles_count() {
|
||||
return FURI_HAL_FLASH_CYCLES_COUNT;
|
||||
}
|
||||
|
||||
const void* furi_hal_flash_get_free_start_address() {
|
||||
return &__free_flash_start__;
|
||||
}
|
||||
|
||||
const void* furi_hal_flash_get_free_end_address() {
|
||||
return &__free_flash_end__;
|
||||
}
|
||||
|
||||
size_t furi_hal_flash_get_free_page_start_address() {
|
||||
size_t start = (size_t)furi_hal_flash_get_free_start_address();
|
||||
size_t page_start = start - start % FURI_HAL_FLASH_PAGE_SIZE;
|
||||
if (page_start != start) {
|
||||
page_start += FURI_HAL_FLASH_PAGE_SIZE;
|
||||
}
|
||||
return page_start;
|
||||
}
|
||||
|
||||
size_t furi_hal_flash_get_free_page_count() {
|
||||
size_t end = (size_t)furi_hal_flash_get_free_end_address();
|
||||
size_t page_start = (size_t)furi_hal_flash_get_free_page_start_address();
|
||||
return (end-page_start) / FURI_HAL_FLASH_PAGE_SIZE;
|
||||
}
|
||||
|
||||
bool furi_hal_flash_erase(uint8_t page, uint8_t count) {
|
||||
if (!furi_hal_bt_lock_flash()) {
|
||||
return false;
|
||||
}
|
||||
FLASH_EraseInitTypeDef erase;
|
||||
erase.TypeErase = FLASH_TYPEERASE_PAGES;
|
||||
erase.Page = page;
|
||||
erase.NbPages = count;
|
||||
uint32_t error;
|
||||
HAL_StatusTypeDef status = HAL_FLASHEx_Erase(&erase, &error);
|
||||
furi_hal_bt_unlock_flash();
|
||||
return status == HAL_OK;
|
||||
}
|
||||
|
||||
bool furi_hal_flash_write_dword(size_t address, uint64_t data) {
|
||||
if (!furi_hal_bt_lock_flash()) {
|
||||
return false;
|
||||
}
|
||||
HAL_StatusTypeDef status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_DOUBLEWORD, address, data);
|
||||
furi_hal_bt_unlock_flash();
|
||||
return status == HAL_OK;
|
||||
}
|
||||
|
||||
bool furi_hal_flash_write_dword_from(size_t address, size_t source_address) {
|
||||
if (!furi_hal_bt_lock_flash()) {
|
||||
return false;
|
||||
}
|
||||
HAL_StatusTypeDef status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_FAST, address, source_address);
|
||||
furi_hal_bt_unlock_flash();
|
||||
return status == HAL_OK;
|
||||
}
|
@@ -7,47 +7,47 @@
|
||||
/** Get flash base address
|
||||
* @return pointer to flash base
|
||||
*/
|
||||
size_t api_hal_flash_get_base();
|
||||
size_t furi_hal_flash_get_base();
|
||||
|
||||
/** Get flash read block size
|
||||
* @return size in bytes
|
||||
*/
|
||||
size_t api_hal_flash_get_read_block_size();
|
||||
size_t furi_hal_flash_get_read_block_size();
|
||||
|
||||
/** Get flash write block size
|
||||
* @return size in bytes
|
||||
*/
|
||||
size_t api_hal_flash_get_write_block_size();
|
||||
size_t furi_hal_flash_get_write_block_size();
|
||||
|
||||
/** Get flash page size
|
||||
* @return size in bytes
|
||||
*/
|
||||
size_t api_hal_flash_get_page_size();
|
||||
size_t furi_hal_flash_get_page_size();
|
||||
|
||||
/** Get expected flash cycles count
|
||||
* @return count of erase-write operations
|
||||
*/
|
||||
size_t api_hal_flash_get_cycles_count();
|
||||
size_t furi_hal_flash_get_cycles_count();
|
||||
|
||||
/** Get free flash start address
|
||||
* @return pointer to free region start
|
||||
*/
|
||||
const void* api_hal_flash_get_free_start_address();
|
||||
const void* furi_hal_flash_get_free_start_address();
|
||||
|
||||
/** Get free flash end address
|
||||
* @return pointer to free region end
|
||||
*/
|
||||
const void* api_hal_flash_get_free_end_address();
|
||||
const void* furi_hal_flash_get_free_end_address();
|
||||
|
||||
/** Get first free page start address
|
||||
* @return first free page memory address
|
||||
*/
|
||||
size_t api_hal_flash_get_free_page_start_address();
|
||||
size_t furi_hal_flash_get_free_page_start_address();
|
||||
|
||||
/** Get free page count
|
||||
* @return free page count
|
||||
*/
|
||||
size_t api_hal_flash_get_free_page_count();
|
||||
size_t furi_hal_flash_get_free_page_count();
|
||||
|
||||
/*
|
||||
* Erase Flash
|
||||
@@ -55,7 +55,7 @@ size_t api_hal_flash_get_free_page_count();
|
||||
* @param page, page number
|
||||
* @param count, page count to erase
|
||||
*/
|
||||
bool api_hal_flash_erase(uint8_t page, uint8_t count);
|
||||
bool furi_hal_flash_erase(uint8_t page, uint8_t count);
|
||||
|
||||
/*
|
||||
* Write double word (64 bits)
|
||||
@@ -63,7 +63,7 @@ bool api_hal_flash_erase(uint8_t page, uint8_t count);
|
||||
* @param address - destination address, must be double word aligned.
|
||||
* @param data - data to write
|
||||
*/
|
||||
bool api_hal_flash_write_dword(size_t address, uint64_t data);
|
||||
bool furi_hal_flash_write_dword(size_t address, uint64_t data);
|
||||
|
||||
/*
|
||||
* Write double word (64 bits) from address
|
||||
@@ -71,4 +71,4 @@ bool api_hal_flash_write_dword(size_t address, uint64_t data);
|
||||
* @param address - destination address, must be block aligned
|
||||
* @param source_address - source address
|
||||
*/
|
||||
bool api_hal_flash_write_dword_from(size_t address, size_t source_address);
|
||||
bool furi_hal_flash_write_dword_from(size_t address, size_t source_address);
|
@@ -1,6 +1,6 @@
|
||||
#include <furi.h>
|
||||
#include <api-hal-gpio.h>
|
||||
#include <api-hal-version.h>
|
||||
#include <furi-hal-gpio.h>
|
||||
#include <furi-hal-version.h>
|
||||
|
||||
#define GET_SYSCFG_EXTI_PORT(gpio) \
|
||||
(((gpio) == (GPIOA)) ? LL_SYSCFG_EXTI_PORTA : \
|
||||
@@ -284,7 +284,7 @@ extern COMP_HandleTypeDef hcomp1;
|
||||
|
||||
bool hal_gpio_get_rfid_in_level() {
|
||||
bool value = false;
|
||||
if(api_hal_version_get_hw_version() > 7) {
|
||||
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);
|
@@ -1,16 +1,16 @@
|
||||
#include <api-hal-i2c.h>
|
||||
#include <api-hal-version.h>
|
||||
#include <furi-hal-i2c.h>
|
||||
#include <furi-hal-version.h>
|
||||
|
||||
#include <stm32wbxx_ll_i2c.h>
|
||||
#include <stm32wbxx_ll_gpio.h>
|
||||
#include <stm32wbxx_ll_cortex.h>
|
||||
#include <furi.h>
|
||||
|
||||
osMutexId_t api_hal_i2c_mutex = NULL;
|
||||
osMutexId_t furi_hal_i2c_mutex = NULL;
|
||||
|
||||
void api_hal_i2c_init() {
|
||||
api_hal_i2c_mutex = osMutexNew(NULL);
|
||||
furi_check(api_hal_i2c_mutex);
|
||||
void furi_hal_i2c_init() {
|
||||
furi_hal_i2c_mutex = osMutexNew(NULL);
|
||||
furi_check(furi_hal_i2c_mutex);
|
||||
|
||||
LL_I2C_InitTypeDef I2C_InitStruct = {0};
|
||||
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
@@ -31,7 +31,7 @@ void api_hal_i2c_init() {
|
||||
I2C_InitStruct.OwnAddress1 = 0;
|
||||
I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK;
|
||||
I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT;
|
||||
if (api_hal_version_get_hw_version() > 10) {
|
||||
if (furi_hal_version_get_hw_version() > 10) {
|
||||
I2C_InitStruct.Timing = POWER_I2C_TIMINGS_400;
|
||||
} else {
|
||||
I2C_InitStruct.Timing = POWER_I2C_TIMINGS_100;
|
||||
@@ -45,7 +45,7 @@ void api_hal_i2c_init() {
|
||||
FURI_LOG_I("FuriHalI2C", "Init OK");
|
||||
}
|
||||
|
||||
bool api_hal_i2c_tx(
|
||||
bool furi_hal_i2c_tx(
|
||||
I2C_TypeDef* instance,
|
||||
uint8_t address,
|
||||
const uint8_t* data,
|
||||
@@ -86,7 +86,7 @@ bool api_hal_i2c_tx(
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool api_hal_i2c_rx(
|
||||
bool furi_hal_i2c_rx(
|
||||
I2C_TypeDef* instance,
|
||||
uint8_t address,
|
||||
uint8_t* data,
|
||||
@@ -127,7 +127,7 @@ bool api_hal_i2c_rx(
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool api_hal_i2c_trx(
|
||||
bool furi_hal_i2c_trx(
|
||||
I2C_TypeDef* instance,
|
||||
uint8_t address,
|
||||
const uint8_t* tx_data,
|
||||
@@ -135,18 +135,18 @@ bool api_hal_i2c_trx(
|
||||
uint8_t* rx_data,
|
||||
uint8_t rx_size,
|
||||
uint32_t timeout) {
|
||||
if(api_hal_i2c_tx(instance, address, tx_data, tx_size, timeout) &&
|
||||
api_hal_i2c_rx(instance, address, rx_data, rx_size, timeout)) {
|
||||
if(furi_hal_i2c_tx(instance, address, tx_data, tx_size, timeout) &&
|
||||
furi_hal_i2c_rx(instance, address, rx_data, rx_size, timeout)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void api_hal_i2c_lock() {
|
||||
furi_check(osMutexAcquire(api_hal_i2c_mutex, osWaitForever) == osOK);
|
||||
void furi_hal_i2c_lock() {
|
||||
furi_check(osMutexAcquire(furi_hal_i2c_mutex, osWaitForever) == osOK);
|
||||
}
|
||||
|
||||
void api_hal_i2c_unlock() {
|
||||
furi_check(osMutexRelease(api_hal_i2c_mutex) == osOK);
|
||||
void furi_hal_i2c_unlock() {
|
||||
furi_check(osMutexRelease(furi_hal_i2c_mutex) == osOK);
|
||||
}
|
@@ -1,24 +1,24 @@
|
||||
#include <api-hal-ibutton.h>
|
||||
#include <api-hal-resources.h>
|
||||
#include <furi-hal-ibutton.h>
|
||||
#include <furi-hal-resources.h>
|
||||
|
||||
void api_hal_ibutton_start() {
|
||||
api_hal_ibutton_pin_high();
|
||||
void furi_hal_ibutton_start() {
|
||||
furi_hal_ibutton_pin_high();
|
||||
hal_gpio_init(&ibutton_gpio, GpioModeOutputOpenDrain, GpioSpeedLow, GpioPullNo);
|
||||
}
|
||||
|
||||
void api_hal_ibutton_stop() {
|
||||
api_hal_ibutton_pin_high();
|
||||
void furi_hal_ibutton_stop() {
|
||||
furi_hal_ibutton_pin_high();
|
||||
hal_gpio_init(&ibutton_gpio, GpioModeAnalog, GpioSpeedLow, GpioPullNo);
|
||||
}
|
||||
|
||||
void api_hal_ibutton_pin_low() {
|
||||
void furi_hal_ibutton_pin_low() {
|
||||
hal_gpio_write(&ibutton_gpio, false);
|
||||
}
|
||||
|
||||
void api_hal_ibutton_pin_high() {
|
||||
void furi_hal_ibutton_pin_high() {
|
||||
hal_gpio_write(&ibutton_gpio, true);
|
||||
}
|
||||
|
||||
bool api_hal_ibutton_pin_get_level() {
|
||||
bool furi_hal_ibutton_pin_get_level() {
|
||||
return hal_gpio_read(&ibutton_gpio);
|
||||
}
|
@@ -1,18 +1,18 @@
|
||||
#include "api-hal-interrupt.h"
|
||||
#include "furi-hal-interrupt.h"
|
||||
|
||||
#include <furi.h>
|
||||
#include <main.h>
|
||||
#include <stm32wbxx_ll_tim.h>
|
||||
|
||||
volatile ApiHalInterruptISR api_hal_tim_tim2_isr = NULL;
|
||||
volatile ApiHalInterruptISR api_hal_tim_tim1_isr = NULL;
|
||||
volatile FuriHalInterruptISR furi_hal_tim_tim2_isr = NULL;
|
||||
volatile FuriHalInterruptISR furi_hal_tim_tim1_isr = NULL;
|
||||
|
||||
#define API_HAL_INTERRUPT_DMA_COUNT 2
|
||||
#define API_HAL_INTERRUPT_DMA_CHANNELS_COUNT 8
|
||||
#define FURI_HAL_INTERRUPT_DMA_COUNT 2
|
||||
#define FURI_HAL_INTERRUPT_DMA_CHANNELS_COUNT 8
|
||||
|
||||
volatile ApiHalInterruptISR api_hal_dma_channel_isr[API_HAL_INTERRUPT_DMA_COUNT][API_HAL_INTERRUPT_DMA_CHANNELS_COUNT] = {0};
|
||||
volatile FuriHalInterruptISR furi_hal_dma_channel_isr[FURI_HAL_INTERRUPT_DMA_COUNT][FURI_HAL_INTERRUPT_DMA_CHANNELS_COUNT] = {0};
|
||||
|
||||
void api_hal_interrupt_init() {
|
||||
void furi_hal_interrupt_init() {
|
||||
NVIC_SetPriority(RCC_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 0, 0));
|
||||
NVIC_EnableIRQ(RCC_IRQn);
|
||||
|
||||
@@ -25,34 +25,34 @@ void api_hal_interrupt_init() {
|
||||
FURI_LOG_I("FuriHalInterrupt", "Init OK");
|
||||
}
|
||||
|
||||
void api_hal_interrupt_set_timer_isr(TIM_TypeDef* timer, ApiHalInterruptISR isr) {
|
||||
void furi_hal_interrupt_set_timer_isr(TIM_TypeDef* timer, FuriHalInterruptISR isr) {
|
||||
if (timer == TIM2) {
|
||||
if (isr) {
|
||||
furi_assert(api_hal_tim_tim2_isr == NULL);
|
||||
furi_assert(furi_hal_tim_tim2_isr == NULL);
|
||||
} else {
|
||||
furi_assert(api_hal_tim_tim2_isr != NULL);
|
||||
furi_assert(furi_hal_tim_tim2_isr != NULL);
|
||||
}
|
||||
api_hal_tim_tim2_isr = isr;
|
||||
furi_hal_tim_tim2_isr = isr;
|
||||
} else if (timer == TIM1) {
|
||||
if (isr) {
|
||||
furi_assert(api_hal_tim_tim1_isr == NULL);
|
||||
furi_assert(furi_hal_tim_tim1_isr == NULL);
|
||||
} else {
|
||||
furi_assert(api_hal_tim_tim1_isr != NULL);
|
||||
furi_assert(furi_hal_tim_tim1_isr != NULL);
|
||||
}
|
||||
api_hal_tim_tim1_isr = isr;
|
||||
furi_hal_tim_tim1_isr = isr;
|
||||
} else {
|
||||
furi_check(0);
|
||||
}
|
||||
}
|
||||
|
||||
void api_hal_interrupt_set_dma_channel_isr(DMA_TypeDef* dma, uint32_t channel, ApiHalInterruptISR isr) {
|
||||
void furi_hal_interrupt_set_dma_channel_isr(DMA_TypeDef* dma, uint32_t channel, FuriHalInterruptISR isr) {
|
||||
--channel; // Pascal
|
||||
furi_check(dma);
|
||||
furi_check(channel < API_HAL_INTERRUPT_DMA_CHANNELS_COUNT);
|
||||
furi_check(channel < FURI_HAL_INTERRUPT_DMA_CHANNELS_COUNT);
|
||||
if (dma == DMA1) {
|
||||
api_hal_dma_channel_isr[0][channel] = isr;
|
||||
furi_hal_dma_channel_isr[0][channel] = isr;
|
||||
} else if (dma == DMA2) {
|
||||
api_hal_dma_channel_isr[1][channel] = isr;
|
||||
furi_hal_dma_channel_isr[1][channel] = isr;
|
||||
} else {
|
||||
furi_check(0);
|
||||
}
|
||||
@@ -74,8 +74,8 @@ void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim) {
|
||||
|
||||
/* Timer 2 */
|
||||
void TIM2_IRQHandler(void) {
|
||||
if (api_hal_tim_tim2_isr) {
|
||||
api_hal_tim_tim2_isr();
|
||||
if (furi_hal_tim_tim2_isr) {
|
||||
furi_hal_tim_tim2_isr();
|
||||
} else {
|
||||
HAL_TIM_IRQHandler(&htim2);
|
||||
}
|
||||
@@ -83,8 +83,8 @@ void TIM2_IRQHandler(void) {
|
||||
|
||||
/* Timer 1 Update */
|
||||
void TIM1_UP_TIM16_IRQHandler(void) {
|
||||
if (api_hal_tim_tim1_isr) {
|
||||
api_hal_tim_tim1_isr();
|
||||
if (furi_hal_tim_tim1_isr) {
|
||||
furi_hal_tim_tim1_isr();
|
||||
} else {
|
||||
HAL_TIM_IRQHandler(&htim1);
|
||||
}
|
||||
@@ -92,68 +92,68 @@ void TIM1_UP_TIM16_IRQHandler(void) {
|
||||
|
||||
/* DMA 1 */
|
||||
void DMA1_Channel1_IRQHandler(void) {
|
||||
if (api_hal_dma_channel_isr[0][0]) api_hal_dma_channel_isr[0][0]();
|
||||
if (furi_hal_dma_channel_isr[0][0]) furi_hal_dma_channel_isr[0][0]();
|
||||
}
|
||||
|
||||
void DMA1_Channel2_IRQHandler(void) {
|
||||
if (api_hal_dma_channel_isr[0][1]) api_hal_dma_channel_isr[0][1]();
|
||||
if (furi_hal_dma_channel_isr[0][1]) furi_hal_dma_channel_isr[0][1]();
|
||||
}
|
||||
|
||||
void DMA1_Channel3_IRQHandler(void) {
|
||||
if (api_hal_dma_channel_isr[0][2]) api_hal_dma_channel_isr[0][2]();
|
||||
if (furi_hal_dma_channel_isr[0][2]) furi_hal_dma_channel_isr[0][2]();
|
||||
}
|
||||
|
||||
void DMA1_Channel4_IRQHandler(void) {
|
||||
if (api_hal_dma_channel_isr[0][3]) api_hal_dma_channel_isr[0][3]();
|
||||
if (furi_hal_dma_channel_isr[0][3]) furi_hal_dma_channel_isr[0][3]();
|
||||
}
|
||||
|
||||
void DMA1_Channel5_IRQHandler(void) {
|
||||
if (api_hal_dma_channel_isr[0][4]) api_hal_dma_channel_isr[0][4]();
|
||||
if (furi_hal_dma_channel_isr[0][4]) furi_hal_dma_channel_isr[0][4]();
|
||||
}
|
||||
|
||||
void DMA1_Channel6_IRQHandler(void) {
|
||||
if (api_hal_dma_channel_isr[0][5]) api_hal_dma_channel_isr[0][5]();
|
||||
if (furi_hal_dma_channel_isr[0][5]) furi_hal_dma_channel_isr[0][5]();
|
||||
}
|
||||
|
||||
void DMA1_Channel7_IRQHandler(void) {
|
||||
if (api_hal_dma_channel_isr[0][6]) api_hal_dma_channel_isr[0][6]();
|
||||
if (furi_hal_dma_channel_isr[0][6]) furi_hal_dma_channel_isr[0][6]();
|
||||
}
|
||||
|
||||
void DMA1_Channel8_IRQHandler(void) {
|
||||
if (api_hal_dma_channel_isr[0][7]) api_hal_dma_channel_isr[0][7]();
|
||||
if (furi_hal_dma_channel_isr[0][7]) furi_hal_dma_channel_isr[0][7]();
|
||||
}
|
||||
|
||||
/* DMA 2 */
|
||||
void DMA2_Channel1_IRQHandler(void) {
|
||||
if (api_hal_dma_channel_isr[1][0]) api_hal_dma_channel_isr[1][0]();
|
||||
if (furi_hal_dma_channel_isr[1][0]) furi_hal_dma_channel_isr[1][0]();
|
||||
}
|
||||
|
||||
void DMA2_Channel2_IRQHandler(void) {
|
||||
if (api_hal_dma_channel_isr[1][1]) api_hal_dma_channel_isr[1][1]();
|
||||
if (furi_hal_dma_channel_isr[1][1]) furi_hal_dma_channel_isr[1][1]();
|
||||
}
|
||||
|
||||
void DMA2_Channel3_IRQHandler(void) {
|
||||
if (api_hal_dma_channel_isr[1][2]) api_hal_dma_channel_isr[1][2]();
|
||||
if (furi_hal_dma_channel_isr[1][2]) furi_hal_dma_channel_isr[1][2]();
|
||||
}
|
||||
|
||||
void DMA2_Channel4_IRQHandler(void) {
|
||||
if (api_hal_dma_channel_isr[1][3]) api_hal_dma_channel_isr[1][3]();
|
||||
if (furi_hal_dma_channel_isr[1][3]) furi_hal_dma_channel_isr[1][3]();
|
||||
}
|
||||
|
||||
void DMA2_Channel5_IRQHandler(void) {
|
||||
if (api_hal_dma_channel_isr[1][4]) api_hal_dma_channel_isr[1][4]();
|
||||
if (furi_hal_dma_channel_isr[1][4]) furi_hal_dma_channel_isr[1][4]();
|
||||
}
|
||||
|
||||
void DMA2_Channel6_IRQHandler(void) {
|
||||
if (api_hal_dma_channel_isr[1][5]) api_hal_dma_channel_isr[1][5]();
|
||||
if (furi_hal_dma_channel_isr[1][5]) furi_hal_dma_channel_isr[1][5]();
|
||||
}
|
||||
|
||||
void DMA2_Channel7_IRQHandler(void) {
|
||||
if (api_hal_dma_channel_isr[1][6]) api_hal_dma_channel_isr[1][6]();
|
||||
if (furi_hal_dma_channel_isr[1][6]) furi_hal_dma_channel_isr[1][6]();
|
||||
}
|
||||
|
||||
void DMA2_Channel8_IRQHandler(void) {
|
||||
if (api_hal_dma_channel_isr[1][7]) api_hal_dma_channel_isr[1][7]();
|
||||
if (furi_hal_dma_channel_isr[1][7]) furi_hal_dma_channel_isr[1][7]();
|
||||
}
|
||||
|
||||
|
@@ -7,10 +7,10 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/** Timer ISR */
|
||||
typedef void (*ApiHalInterruptISR)();
|
||||
typedef void (*FuriHalInterruptISR)();
|
||||
|
||||
/** Initialize interrupt subsystem */
|
||||
void api_hal_interrupt_init();
|
||||
void furi_hal_interrupt_init();
|
||||
|
||||
/** Set DMA Channel ISR
|
||||
* We don't clear interrupt flags for you, do it by your self.
|
||||
@@ -18,7 +18,7 @@ void api_hal_interrupt_init();
|
||||
* @param channel - DMA channel
|
||||
* @param isr - your interrupt service routine or use NULL to clear
|
||||
*/
|
||||
void api_hal_interrupt_set_dma_channel_isr(DMA_TypeDef* dma, uint32_t channel, ApiHalInterruptISR isr);
|
||||
void furi_hal_interrupt_set_dma_channel_isr(DMA_TypeDef* dma, uint32_t channel, FuriHalInterruptISR isr);
|
||||
|
||||
/** Set Timer ISR
|
||||
* By default ISR is serviced by ST HAL. Use this function to override it.
|
||||
@@ -26,7 +26,7 @@ void api_hal_interrupt_set_dma_channel_isr(DMA_TypeDef* dma, uint32_t channel, A
|
||||
* @param timer - timer instance
|
||||
* @param isr - your interrupt service routine or use NULL to clear
|
||||
*/
|
||||
void api_hal_interrupt_set_timer_isr(TIM_TypeDef *timer, ApiHalInterruptISR isr);
|
||||
void furi_hal_interrupt_set_timer_isr(TIM_TypeDef *timer, FuriHalInterruptISR isr);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
@@ -1,11 +1,11 @@
|
||||
#include "api-hal-irda.h"
|
||||
#include "api-hal-delay.h"
|
||||
#include "furi-hal-irda.h"
|
||||
#include "furi-hal-delay.h"
|
||||
#include "furi/check.h"
|
||||
#include "stm32wbxx_ll_dma.h"
|
||||
#include "sys/_stdint.h"
|
||||
#include <cmsis_os2.h>
|
||||
#include <api-hal-interrupt.h>
|
||||
#include <api-hal-resources.h>
|
||||
#include <furi-hal-interrupt.h>
|
||||
#include <furi-hal-resources.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stm32wbxx_ll_tim.h>
|
||||
@@ -15,7 +15,7 @@
|
||||
#include <furi.h>
|
||||
#include <math.h>
|
||||
#include <main.h>
|
||||
#include <api-hal-pwm.h>
|
||||
#include <furi-hal-pwm.h>
|
||||
|
||||
#define IRDA_TIM_TX_DMA_BUFFER_SIZE 200
|
||||
#define IRDA_POLARITY_SHIFT 1
|
||||
@@ -24,9 +24,9 @@
|
||||
#define IRDA_TX_CCMR_LOW (TIM_CCMR2_OC3PE | LL_TIM_OCMODE_FORCED_INACTIVE) /* Space time - force low */
|
||||
|
||||
typedef struct{
|
||||
ApiHalIrdaRxCaptureCallback capture_callback;
|
||||
FuriHalIrdaRxCaptureCallback capture_callback;
|
||||
void *capture_context;
|
||||
ApiHalIrdaRxTimeoutCallback timeout_callback;
|
||||
FuriHalIrdaRxTimeoutCallback timeout_callback;
|
||||
void *timeout_context;
|
||||
} IrdaTimRx;
|
||||
|
||||
@@ -40,14 +40,14 @@ typedef struct{
|
||||
|
||||
typedef struct {
|
||||
float cycle_duration;
|
||||
ApiHalIrdaTxGetDataCallback data_callback;
|
||||
FuriHalIrdaTxGetDataCallback data_callback;
|
||||
void* data_context;
|
||||
IrdaTxBuf buffer[2];
|
||||
osSemaphoreId_t stop_semaphore;
|
||||
} IrdaTimTx;
|
||||
|
||||
typedef enum {
|
||||
IrdaStateIdle, /** Api Hal Irda is ready to start RX or TX */
|
||||
IrdaStateIdle, /** Furi Hal Irda is ready to start RX or TX */
|
||||
IrdaStateAsyncRx, /** Async RX started */
|
||||
IrdaStateAsyncTx, /** Async TX started, DMA and timer is on */
|
||||
IrdaStateAsyncTxStopReq, /** Async TX started, async stop request received */
|
||||
@@ -56,25 +56,25 @@ typedef enum {
|
||||
IrdaStateMAX,
|
||||
} IrdaState;
|
||||
|
||||
static volatile IrdaState api_hal_irda_state = IrdaStateIdle;
|
||||
static volatile IrdaState furi_hal_irda_state = IrdaStateIdle;
|
||||
static IrdaTimTx irda_tim_tx;
|
||||
static IrdaTimRx irda_tim_rx;
|
||||
|
||||
static bool api_hal_irda_tx_fill_buffer(uint8_t buf_num, uint8_t polarity_shift);
|
||||
static void api_hal_irda_async_tx_free_resources(void);
|
||||
static void api_hal_irda_tx_dma_set_polarity(uint8_t buf_num, uint8_t polarity_shift);
|
||||
static void api_hal_irda_tx_dma_set_buffer(uint8_t buf_num);
|
||||
static void api_hal_irda_tx_fill_buffer_last(uint8_t buf_num);
|
||||
static uint8_t api_hal_irda_get_current_dma_tx_buffer(void);
|
||||
static void api_hal_irda_tx_dma_polarity_isr();
|
||||
static void api_hal_irda_tx_dma_isr();
|
||||
static bool furi_hal_irda_tx_fill_buffer(uint8_t buf_num, uint8_t polarity_shift);
|
||||
static void furi_hal_irda_async_tx_free_resources(void);
|
||||
static void furi_hal_irda_tx_dma_set_polarity(uint8_t buf_num, uint8_t polarity_shift);
|
||||
static void furi_hal_irda_tx_dma_set_buffer(uint8_t buf_num);
|
||||
static void furi_hal_irda_tx_fill_buffer_last(uint8_t buf_num);
|
||||
static uint8_t furi_hal_irda_get_current_dma_tx_buffer(void);
|
||||
static void furi_hal_irda_tx_dma_polarity_isr();
|
||||
static void furi_hal_irda_tx_dma_isr();
|
||||
|
||||
static void api_hal_irda_tim_rx_isr() {
|
||||
static void furi_hal_irda_tim_rx_isr() {
|
||||
|
||||
/* Timeout */
|
||||
if(LL_TIM_IsActiveFlag_CC3(TIM2)) {
|
||||
LL_TIM_ClearFlag_CC3(TIM2);
|
||||
furi_assert(api_hal_irda_state == IrdaStateAsyncRx);
|
||||
furi_assert(furi_hal_irda_state == IrdaStateAsyncRx);
|
||||
|
||||
/* Timers CNT register starts to counting from 0 to ARR, but it is
|
||||
* reseted when Channel 1 catches interrupt. It is not reseted by
|
||||
@@ -91,7 +91,7 @@ static void api_hal_irda_tim_rx_isr() {
|
||||
/* Rising Edge */
|
||||
if(LL_TIM_IsActiveFlag_CC1(TIM2)) {
|
||||
LL_TIM_ClearFlag_CC1(TIM2);
|
||||
furi_assert(api_hal_irda_state == IrdaStateAsyncRx);
|
||||
furi_assert(furi_hal_irda_state == IrdaStateAsyncRx);
|
||||
|
||||
if(READ_BIT(TIM2->CCMR1, TIM_CCMR1_CC1S)) {
|
||||
/* Low pin level is a Mark state of IRDA signal. Invert level for further processing. */
|
||||
@@ -106,7 +106,7 @@ static void api_hal_irda_tim_rx_isr() {
|
||||
/* Falling Edge */
|
||||
if(LL_TIM_IsActiveFlag_CC2(TIM2)) {
|
||||
LL_TIM_ClearFlag_CC2(TIM2);
|
||||
furi_assert(api_hal_irda_state == IrdaStateAsyncRx);
|
||||
furi_assert(furi_hal_irda_state == IrdaStateAsyncRx);
|
||||
|
||||
if(READ_BIT(TIM2->CCMR1, TIM_CCMR1_CC2S)) {
|
||||
/* High pin level is a Space state of IRDA signal. Invert level for further processing. */
|
||||
@@ -119,8 +119,8 @@ static void api_hal_irda_tim_rx_isr() {
|
||||
}
|
||||
}
|
||||
|
||||
void api_hal_irda_async_rx_start(void) {
|
||||
furi_assert(api_hal_irda_state == IrdaStateIdle);
|
||||
void furi_hal_irda_async_rx_start(void) {
|
||||
furi_assert(furi_hal_irda_state == IrdaStateIdle);
|
||||
|
||||
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM2);
|
||||
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA);
|
||||
@@ -152,8 +152,8 @@ void api_hal_irda_async_rx_start(void) {
|
||||
LL_TIM_IC_SetActiveInput(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_ACTIVEINPUT_INDIRECTTI);
|
||||
LL_TIM_IC_SetPrescaler(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_ICPSC_DIV1);
|
||||
|
||||
api_hal_interrupt_set_timer_isr(TIM2, api_hal_irda_tim_rx_isr);
|
||||
api_hal_irda_state = IrdaStateAsyncRx;
|
||||
furi_hal_interrupt_set_timer_isr(TIM2, furi_hal_irda_tim_rx_isr);
|
||||
furi_hal_irda_state = IrdaStateAsyncRx;
|
||||
|
||||
LL_TIM_EnableIT_CC1(TIM2);
|
||||
LL_TIM_EnableIT_CC2(TIM2);
|
||||
@@ -167,41 +167,41 @@ void api_hal_irda_async_rx_start(void) {
|
||||
NVIC_EnableIRQ(TIM2_IRQn);
|
||||
}
|
||||
|
||||
void api_hal_irda_async_rx_stop(void) {
|
||||
furi_assert(api_hal_irda_state == IrdaStateAsyncRx);
|
||||
void furi_hal_irda_async_rx_stop(void) {
|
||||
furi_assert(furi_hal_irda_state == IrdaStateAsyncRx);
|
||||
LL_TIM_DeInit(TIM2);
|
||||
api_hal_interrupt_set_timer_isr(TIM2, NULL);
|
||||
furi_hal_interrupt_set_timer_isr(TIM2, NULL);
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_TIM2);
|
||||
api_hal_irda_state = IrdaStateIdle;
|
||||
furi_hal_irda_state = IrdaStateIdle;
|
||||
}
|
||||
|
||||
void api_hal_irda_async_rx_set_timeout(uint32_t timeout_ms) {
|
||||
void furi_hal_irda_async_rx_set_timeout(uint32_t timeout_ms) {
|
||||
LL_TIM_OC_SetCompareCH3(TIM2, timeout_ms * 1000);
|
||||
LL_TIM_OC_SetMode(TIM2, LL_TIM_CHANNEL_CH3, LL_TIM_OCMODE_ACTIVE);
|
||||
LL_TIM_CC_EnableChannel(TIM2, LL_TIM_CHANNEL_CH3);
|
||||
LL_TIM_EnableIT_CC3(TIM2);
|
||||
}
|
||||
|
||||
bool api_hal_irda_is_busy(void) {
|
||||
return api_hal_irda_state != IrdaStateIdle;
|
||||
bool furi_hal_irda_is_busy(void) {
|
||||
return furi_hal_irda_state != IrdaStateIdle;
|
||||
}
|
||||
|
||||
void api_hal_irda_async_rx_set_capture_isr_callback(ApiHalIrdaRxCaptureCallback callback, void *ctx) {
|
||||
void furi_hal_irda_async_rx_set_capture_isr_callback(FuriHalIrdaRxCaptureCallback callback, void *ctx) {
|
||||
irda_tim_rx.capture_callback = callback;
|
||||
irda_tim_rx.capture_context = ctx;
|
||||
}
|
||||
|
||||
void api_hal_irda_async_rx_set_timeout_isr_callback(ApiHalIrdaRxTimeoutCallback callback, void *ctx) {
|
||||
void furi_hal_irda_async_rx_set_timeout_isr_callback(FuriHalIrdaRxTimeoutCallback callback, void *ctx) {
|
||||
irda_tim_rx.timeout_callback = callback;
|
||||
irda_tim_rx.timeout_context = ctx;
|
||||
}
|
||||
|
||||
static void api_hal_irda_tx_dma_terminate(void) {
|
||||
static void furi_hal_irda_tx_dma_terminate(void) {
|
||||
LL_DMA_DisableIT_TC(DMA1, LL_DMA_CHANNEL_1);
|
||||
LL_DMA_DisableIT_HT(DMA1, LL_DMA_CHANNEL_2);
|
||||
LL_DMA_DisableIT_TC(DMA1, LL_DMA_CHANNEL_2);
|
||||
|
||||
furi_assert(api_hal_irda_state == IrdaStateAsyncTxStopInProgress);
|
||||
furi_assert(furi_hal_irda_state == IrdaStateAsyncTxStopInProgress);
|
||||
|
||||
LL_DMA_DisableIT_TC(DMA1, LL_DMA_CHANNEL_1);
|
||||
LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_2);
|
||||
@@ -209,10 +209,10 @@ static void api_hal_irda_tx_dma_terminate(void) {
|
||||
LL_TIM_DisableCounter(TIM1);
|
||||
osStatus_t status = osSemaphoreRelease(irda_tim_tx.stop_semaphore);
|
||||
furi_check(status == osOK);
|
||||
api_hal_irda_state = IrdaStateAsyncTxStopped;
|
||||
furi_hal_irda_state = IrdaStateAsyncTxStopped;
|
||||
}
|
||||
|
||||
static uint8_t api_hal_irda_get_current_dma_tx_buffer(void) {
|
||||
static uint8_t furi_hal_irda_get_current_dma_tx_buffer(void) {
|
||||
uint8_t buf_num = 0;
|
||||
uint32_t buffer_adr = LL_DMA_GetMemoryAddress(DMA1, LL_DMA_CHANNEL_2);
|
||||
if (buffer_adr == (uint32_t) irda_tim_tx.buffer[0].data) {
|
||||
@@ -225,7 +225,7 @@ static uint8_t api_hal_irda_get_current_dma_tx_buffer(void) {
|
||||
return buf_num;
|
||||
}
|
||||
|
||||
static void api_hal_irda_tx_dma_polarity_isr() {
|
||||
static void furi_hal_irda_tx_dma_polarity_isr() {
|
||||
if (LL_DMA_IsActiveFlag_TE1(DMA1)) {
|
||||
LL_DMA_ClearFlag_TE1(DMA1);
|
||||
furi_check(0);
|
||||
@@ -233,36 +233,36 @@ static void api_hal_irda_tx_dma_polarity_isr() {
|
||||
if (LL_DMA_IsActiveFlag_TC1(DMA1) && LL_DMA_IsEnabledIT_TC(DMA1, LL_DMA_CHANNEL_1)) {
|
||||
LL_DMA_ClearFlag_TC1(DMA1);
|
||||
|
||||
furi_check((api_hal_irda_state == IrdaStateAsyncTx)
|
||||
|| (api_hal_irda_state == IrdaStateAsyncTxStopReq)
|
||||
|| (api_hal_irda_state == IrdaStateAsyncTxStopInProgress));
|
||||
furi_check((furi_hal_irda_state == IrdaStateAsyncTx)
|
||||
|| (furi_hal_irda_state == IrdaStateAsyncTxStopReq)
|
||||
|| (furi_hal_irda_state == IrdaStateAsyncTxStopInProgress));
|
||||
/* actually TC2 is processed and buffer is next buffer */
|
||||
uint8_t next_buf_num = api_hal_irda_get_current_dma_tx_buffer();
|
||||
api_hal_irda_tx_dma_set_polarity(next_buf_num, 0);
|
||||
uint8_t next_buf_num = furi_hal_irda_get_current_dma_tx_buffer();
|
||||
furi_hal_irda_tx_dma_set_polarity(next_buf_num, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void api_hal_irda_tx_dma_isr() {
|
||||
static void furi_hal_irda_tx_dma_isr() {
|
||||
if (LL_DMA_IsActiveFlag_TE2(DMA1)) {
|
||||
LL_DMA_ClearFlag_TE2(DMA1);
|
||||
furi_check(0);
|
||||
}
|
||||
if (LL_DMA_IsActiveFlag_HT2(DMA1) && LL_DMA_IsEnabledIT_HT(DMA1, LL_DMA_CHANNEL_2)) {
|
||||
LL_DMA_ClearFlag_HT2(DMA1);
|
||||
uint8_t buf_num = api_hal_irda_get_current_dma_tx_buffer();
|
||||
uint8_t buf_num = furi_hal_irda_get_current_dma_tx_buffer();
|
||||
uint8_t next_buf_num = !buf_num;
|
||||
if (irda_tim_tx.buffer[buf_num].last_packet_end) {
|
||||
LL_DMA_DisableIT_HT(DMA1, LL_DMA_CHANNEL_2);
|
||||
} else if (!irda_tim_tx.buffer[buf_num].packet_end || (api_hal_irda_state == IrdaStateAsyncTx)) {
|
||||
bool result = api_hal_irda_tx_fill_buffer(next_buf_num, 0);
|
||||
} else if (!irda_tim_tx.buffer[buf_num].packet_end || (furi_hal_irda_state == IrdaStateAsyncTx)) {
|
||||
bool result = furi_hal_irda_tx_fill_buffer(next_buf_num, 0);
|
||||
if (irda_tim_tx.buffer[next_buf_num].last_packet_end) {
|
||||
LL_DMA_DisableIT_HT(DMA1, LL_DMA_CHANNEL_2);
|
||||
}
|
||||
if (!result) {
|
||||
furi_assert(0);
|
||||
api_hal_irda_state = IrdaStateAsyncTxStopReq;
|
||||
furi_hal_irda_state = IrdaStateAsyncTxStopReq;
|
||||
}
|
||||
} else if (api_hal_irda_state == IrdaStateAsyncTxStopReq) {
|
||||
} else if (furi_hal_irda_state == IrdaStateAsyncTxStopReq) {
|
||||
/* fallthrough */
|
||||
} else {
|
||||
furi_check(0);
|
||||
@@ -270,27 +270,27 @@ static void api_hal_irda_tx_dma_isr() {
|
||||
}
|
||||
if (LL_DMA_IsActiveFlag_TC2(DMA1) && LL_DMA_IsEnabledIT_TC(DMA1, LL_DMA_CHANNEL_2)) {
|
||||
LL_DMA_ClearFlag_TC2(DMA1);
|
||||
furi_check((api_hal_irda_state == IrdaStateAsyncTxStopInProgress)
|
||||
|| (api_hal_irda_state == IrdaStateAsyncTxStopReq)
|
||||
|| (api_hal_irda_state == IrdaStateAsyncTx));
|
||||
furi_check((furi_hal_irda_state == IrdaStateAsyncTxStopInProgress)
|
||||
|| (furi_hal_irda_state == IrdaStateAsyncTxStopReq)
|
||||
|| (furi_hal_irda_state == IrdaStateAsyncTx));
|
||||
|
||||
uint8_t buf_num = api_hal_irda_get_current_dma_tx_buffer();
|
||||
uint8_t buf_num = furi_hal_irda_get_current_dma_tx_buffer();
|
||||
uint8_t next_buf_num = !buf_num;
|
||||
if (api_hal_irda_state == IrdaStateAsyncTxStopInProgress) {
|
||||
api_hal_irda_tx_dma_terminate();
|
||||
if (furi_hal_irda_state == IrdaStateAsyncTxStopInProgress) {
|
||||
furi_hal_irda_tx_dma_terminate();
|
||||
} else if (irda_tim_tx.buffer[buf_num].last_packet_end
|
||||
|| (irda_tim_tx.buffer[buf_num].packet_end && (api_hal_irda_state == IrdaStateAsyncTxStopReq))) {
|
||||
api_hal_irda_state = IrdaStateAsyncTxStopInProgress;
|
||||
api_hal_irda_tx_fill_buffer_last(next_buf_num);
|
||||
api_hal_irda_tx_dma_set_buffer(next_buf_num);
|
||||
|| (irda_tim_tx.buffer[buf_num].packet_end && (furi_hal_irda_state == IrdaStateAsyncTxStopReq))) {
|
||||
furi_hal_irda_state = IrdaStateAsyncTxStopInProgress;
|
||||
furi_hal_irda_tx_fill_buffer_last(next_buf_num);
|
||||
furi_hal_irda_tx_dma_set_buffer(next_buf_num);
|
||||
} else {
|
||||
/* if it's not end of the packet - continue receiving */
|
||||
api_hal_irda_tx_dma_set_buffer(next_buf_num);
|
||||
furi_hal_irda_tx_dma_set_buffer(next_buf_num);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void api_hal_irda_configure_tim_pwm_tx(uint32_t freq, float duty_cycle)
|
||||
static void furi_hal_irda_configure_tim_pwm_tx(uint32_t freq, float duty_cycle)
|
||||
{
|
||||
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM1);
|
||||
/* LL_DBGMCU_APB2_GRP1_FreezePeriph(LL_DBGMCU_APB2_GRP1_TIM1_STOP); */
|
||||
@@ -319,7 +319,7 @@ static void api_hal_irda_configure_tim_pwm_tx(uint32_t freq, float duty_cycle)
|
||||
NVIC_EnableIRQ(TIM1_UP_TIM16_IRQn);
|
||||
}
|
||||
|
||||
static void api_hal_irda_configure_tim_cmgr2_dma_tx(void) {
|
||||
static void furi_hal_irda_configure_tim_cmgr2_dma_tx(void) {
|
||||
LL_C2_AHB1_GRP1_EnableClock(LL_C2_AHB1_GRP1_PERIPH_DMA1);
|
||||
|
||||
LL_DMA_InitTypeDef dma_config = {0};
|
||||
@@ -336,7 +336,7 @@ static void api_hal_irda_configure_tim_cmgr2_dma_tx(void) {
|
||||
dma_config.PeriphRequest = LL_DMAMUX_REQ_TIM1_UP;
|
||||
dma_config.Priority = LL_DMA_PRIORITY_VERYHIGH;
|
||||
LL_DMA_Init(DMA1, LL_DMA_CHANNEL_1, &dma_config);
|
||||
api_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_1, api_hal_irda_tx_dma_polarity_isr);
|
||||
furi_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_1, furi_hal_irda_tx_dma_polarity_isr);
|
||||
LL_DMA_ClearFlag_TE1(DMA1);
|
||||
LL_DMA_ClearFlag_TC1(DMA1);
|
||||
LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_1);
|
||||
@@ -346,7 +346,7 @@ static void api_hal_irda_configure_tim_cmgr2_dma_tx(void) {
|
||||
NVIC_EnableIRQ(DMA1_Channel1_IRQn);
|
||||
}
|
||||
|
||||
static void api_hal_irda_configure_tim_rcr_dma_tx(void) {
|
||||
static void furi_hal_irda_configure_tim_rcr_dma_tx(void) {
|
||||
LL_C2_AHB1_GRP1_EnableClock(LL_C2_AHB1_GRP1_PERIPH_DMA1);
|
||||
|
||||
LL_DMA_InitTypeDef dma_config = {0};
|
||||
@@ -362,7 +362,7 @@ static void api_hal_irda_configure_tim_rcr_dma_tx(void) {
|
||||
dma_config.PeriphRequest = LL_DMAMUX_REQ_TIM1_UP;
|
||||
dma_config.Priority = LL_DMA_PRIORITY_MEDIUM;
|
||||
LL_DMA_Init(DMA1, LL_DMA_CHANNEL_2, &dma_config);
|
||||
api_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_2, api_hal_irda_tx_dma_isr);
|
||||
furi_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_2, furi_hal_irda_tx_dma_isr);
|
||||
LL_DMA_ClearFlag_TC2(DMA1);
|
||||
LL_DMA_ClearFlag_HT2(DMA1);
|
||||
LL_DMA_ClearFlag_TE2(DMA1);
|
||||
@@ -374,10 +374,10 @@ static void api_hal_irda_configure_tim_rcr_dma_tx(void) {
|
||||
NVIC_EnableIRQ(DMA1_Channel2_IRQn);
|
||||
}
|
||||
|
||||
static void api_hal_irda_tx_fill_buffer_last(uint8_t buf_num) {
|
||||
static void furi_hal_irda_tx_fill_buffer_last(uint8_t buf_num) {
|
||||
furi_assert(buf_num < 2);
|
||||
furi_assert(api_hal_irda_state != IrdaStateAsyncRx);
|
||||
furi_assert(api_hal_irda_state < IrdaStateMAX);
|
||||
furi_assert(furi_hal_irda_state != IrdaStateAsyncRx);
|
||||
furi_assert(furi_hal_irda_state < IrdaStateMAX);
|
||||
furi_assert(irda_tim_tx.data_callback);
|
||||
IrdaTxBuf* buffer = &irda_tim_tx.buffer[buf_num];
|
||||
furi_assert(buffer->data != NULL);
|
||||
@@ -392,16 +392,16 @@ static void api_hal_irda_tx_fill_buffer_last(uint8_t buf_num) {
|
||||
irda_tim_tx.buffer[buf_num].packet_end = true;
|
||||
}
|
||||
|
||||
static bool api_hal_irda_tx_fill_buffer(uint8_t buf_num, uint8_t polarity_shift) {
|
||||
static bool furi_hal_irda_tx_fill_buffer(uint8_t buf_num, uint8_t polarity_shift) {
|
||||
furi_assert(buf_num < 2);
|
||||
furi_assert(api_hal_irda_state != IrdaStateAsyncRx);
|
||||
furi_assert(api_hal_irda_state < IrdaStateMAX);
|
||||
furi_assert(furi_hal_irda_state != IrdaStateAsyncRx);
|
||||
furi_assert(furi_hal_irda_state < IrdaStateMAX);
|
||||
furi_assert(irda_tim_tx.data_callback);
|
||||
IrdaTxBuf* buffer = &irda_tim_tx.buffer[buf_num];
|
||||
furi_assert(buffer->data != NULL);
|
||||
furi_assert(buffer->polarity != NULL);
|
||||
|
||||
ApiHalIrdaTxGetDataState status = ApiHalIrdaTxGetDataStateOk;
|
||||
FuriHalIrdaTxGetDataState status = FuriHalIrdaTxGetDataStateOk;
|
||||
uint32_t duration = 0;
|
||||
bool level = 0;
|
||||
size_t *size = &buffer->size;
|
||||
@@ -410,9 +410,9 @@ static bool api_hal_irda_tx_fill_buffer(uint8_t buf_num, uint8_t polarity_shift)
|
||||
buffer->polarity[polarity_counter++] = IRDA_TX_CCMR_LOW;
|
||||
}
|
||||
|
||||
for (*size = 0; (*size < IRDA_TIM_TX_DMA_BUFFER_SIZE) && (status == ApiHalIrdaTxGetDataStateOk); ++(*size), ++polarity_counter) {
|
||||
for (*size = 0; (*size < IRDA_TIM_TX_DMA_BUFFER_SIZE) && (status == FuriHalIrdaTxGetDataStateOk); ++(*size), ++polarity_counter) {
|
||||
status = irda_tim_tx.data_callback(irda_tim_tx.data_context, &duration, &level);
|
||||
if (status == ApiHalIrdaTxGetDataStateError) {
|
||||
if (status == FuriHalIrdaTxGetDataStateError) {
|
||||
furi_assert(0);
|
||||
break;
|
||||
}
|
||||
@@ -421,7 +421,7 @@ static bool api_hal_irda_tx_fill_buffer(uint8_t buf_num, uint8_t polarity_shift)
|
||||
|
||||
if ((buffer->data[*size] + num_of_impulses - 1) > 0xFFFF) {
|
||||
furi_assert(0);
|
||||
status = ApiHalIrdaTxGetDataStateError;
|
||||
status = FuriHalIrdaTxGetDataStateError;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -429,15 +429,15 @@ static bool api_hal_irda_tx_fill_buffer(uint8_t buf_num, uint8_t polarity_shift)
|
||||
buffer->data[*size] = num_of_impulses - 1;
|
||||
}
|
||||
|
||||
buffer->last_packet_end = (status == ApiHalIrdaTxGetDataStateLastDone);
|
||||
buffer->packet_end = buffer->last_packet_end || (status == ApiHalIrdaTxGetDataStateDone);
|
||||
buffer->last_packet_end = (status == FuriHalIrdaTxGetDataStateLastDone);
|
||||
buffer->packet_end = buffer->last_packet_end || (status == FuriHalIrdaTxGetDataStateDone);
|
||||
|
||||
return status != ApiHalIrdaTxGetDataStateError;
|
||||
return status != FuriHalIrdaTxGetDataStateError;
|
||||
}
|
||||
|
||||
static void api_hal_irda_tx_dma_set_polarity(uint8_t buf_num, uint8_t polarity_shift) {
|
||||
static void furi_hal_irda_tx_dma_set_polarity(uint8_t buf_num, uint8_t polarity_shift) {
|
||||
furi_assert(buf_num < 2);
|
||||
furi_assert(api_hal_irda_state < IrdaStateMAX);
|
||||
furi_assert(furi_hal_irda_state < IrdaStateMAX);
|
||||
IrdaTxBuf* buffer = &irda_tim_tx.buffer[buf_num];
|
||||
furi_assert(buffer->polarity != NULL);
|
||||
|
||||
@@ -454,9 +454,9 @@ static void api_hal_irda_tx_dma_set_polarity(uint8_t buf_num, uint8_t polarity_s
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
static void api_hal_irda_tx_dma_set_buffer(uint8_t buf_num) {
|
||||
static void furi_hal_irda_tx_dma_set_buffer(uint8_t buf_num) {
|
||||
furi_assert(buf_num < 2);
|
||||
furi_assert(api_hal_irda_state < IrdaStateMAX);
|
||||
furi_assert(furi_hal_irda_state < IrdaStateMAX);
|
||||
IrdaTxBuf* buffer = &irda_tim_tx.buffer[buf_num];
|
||||
furi_assert(buffer->data != NULL);
|
||||
|
||||
@@ -474,13 +474,13 @@ static void api_hal_irda_tx_dma_set_buffer(uint8_t buf_num) {
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
static void api_hal_irda_async_tx_free_resources(void) {
|
||||
furi_assert((api_hal_irda_state == IrdaStateIdle) || (api_hal_irda_state == IrdaStateAsyncTxStopped));
|
||||
static void furi_hal_irda_async_tx_free_resources(void) {
|
||||
furi_assert((furi_hal_irda_state == IrdaStateIdle) || (furi_hal_irda_state == IrdaStateAsyncTxStopped));
|
||||
osStatus_t status;
|
||||
|
||||
hal_gpio_init_ex(&gpio_irda_tx, GpioModeOutputOpenDrain, GpioPullDown, GpioSpeedLow, 0);
|
||||
api_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_1, NULL);
|
||||
api_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_2, NULL);
|
||||
furi_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_1, NULL);
|
||||
furi_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_2, NULL);
|
||||
LL_TIM_DeInit(TIM1);
|
||||
LL_APB2_GRP1_DisableClock(LL_APB2_GRP1_PERIPH_TIM1);
|
||||
LL_C2_AHB1_GRP1_DisableClock(LL_C2_AHB1_GRP1_PERIPH_DMA1);
|
||||
@@ -498,13 +498,13 @@ static void api_hal_irda_async_tx_free_resources(void) {
|
||||
irda_tim_tx.buffer[1].polarity = NULL;
|
||||
}
|
||||
|
||||
bool api_hal_irda_async_tx_start(uint32_t freq, float duty_cycle) {
|
||||
bool furi_hal_irda_async_tx_start(uint32_t freq, float duty_cycle) {
|
||||
if ((duty_cycle > 1) || (duty_cycle < 0) || (freq > 40000) || (freq < 10000) || (irda_tim_tx.data_callback == NULL)) {
|
||||
furi_assert(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
furi_assert(api_hal_irda_state == IrdaStateIdle);
|
||||
furi_assert(furi_hal_irda_state == IrdaStateIdle);
|
||||
furi_assert(irda_tim_tx.buffer[0].data == NULL);
|
||||
furi_assert(irda_tim_tx.buffer[1].data == NULL);
|
||||
furi_assert(irda_tim_tx.buffer[0].polarity == NULL);
|
||||
@@ -521,16 +521,16 @@ bool api_hal_irda_async_tx_start(uint32_t freq, float duty_cycle) {
|
||||
irda_tim_tx.stop_semaphore = osSemaphoreNew(1, 0, NULL);
|
||||
irda_tim_tx.cycle_duration = 1000000.0 / freq;
|
||||
|
||||
bool result = api_hal_irda_tx_fill_buffer(0, IRDA_POLARITY_SHIFT);
|
||||
bool result = furi_hal_irda_tx_fill_buffer(0, IRDA_POLARITY_SHIFT);
|
||||
|
||||
if (result) {
|
||||
api_hal_irda_configure_tim_pwm_tx(freq, duty_cycle);
|
||||
api_hal_irda_configure_tim_cmgr2_dma_tx();
|
||||
api_hal_irda_configure_tim_rcr_dma_tx();
|
||||
api_hal_irda_tx_dma_set_polarity(0, IRDA_POLARITY_SHIFT);
|
||||
api_hal_irda_tx_dma_set_buffer(0);
|
||||
furi_hal_irda_configure_tim_pwm_tx(freq, duty_cycle);
|
||||
furi_hal_irda_configure_tim_cmgr2_dma_tx();
|
||||
furi_hal_irda_configure_tim_rcr_dma_tx();
|
||||
furi_hal_irda_tx_dma_set_polarity(0, IRDA_POLARITY_SHIFT);
|
||||
furi_hal_irda_tx_dma_set_buffer(0);
|
||||
|
||||
api_hal_irda_state = IrdaStateAsyncTx;
|
||||
furi_hal_irda_state = IrdaStateAsyncTx;
|
||||
|
||||
LL_TIM_ClearFlag_UPDATE(TIM1);
|
||||
LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1);
|
||||
@@ -547,37 +547,37 @@ bool api_hal_irda_async_tx_start(uint32_t freq, float duty_cycle) {
|
||||
__enable_irq();
|
||||
|
||||
} else {
|
||||
api_hal_irda_async_tx_free_resources();
|
||||
furi_hal_irda_async_tx_free_resources();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void api_hal_irda_async_tx_wait_termination(void) {
|
||||
furi_assert(api_hal_irda_state >= IrdaStateAsyncTx);
|
||||
furi_assert(api_hal_irda_state < IrdaStateMAX);
|
||||
void furi_hal_irda_async_tx_wait_termination(void) {
|
||||
furi_assert(furi_hal_irda_state >= IrdaStateAsyncTx);
|
||||
furi_assert(furi_hal_irda_state < IrdaStateMAX);
|
||||
|
||||
osStatus_t status;
|
||||
status = osSemaphoreAcquire(irda_tim_tx.stop_semaphore, osWaitForever);
|
||||
furi_check(status == osOK);
|
||||
api_hal_irda_async_tx_free_resources();
|
||||
api_hal_irda_state = IrdaStateIdle;
|
||||
furi_hal_irda_async_tx_free_resources();
|
||||
furi_hal_irda_state = IrdaStateIdle;
|
||||
}
|
||||
|
||||
void api_hal_irda_async_tx_stop(void) {
|
||||
furi_assert(api_hal_irda_state >= IrdaStateAsyncTx);
|
||||
furi_assert(api_hal_irda_state < IrdaStateMAX);
|
||||
void furi_hal_irda_async_tx_stop(void) {
|
||||
furi_assert(furi_hal_irda_state >= IrdaStateAsyncTx);
|
||||
furi_assert(furi_hal_irda_state < IrdaStateMAX);
|
||||
|
||||
__disable_irq();
|
||||
if (api_hal_irda_state == IrdaStateAsyncTx)
|
||||
api_hal_irda_state = IrdaStateAsyncTxStopReq;
|
||||
if (furi_hal_irda_state == IrdaStateAsyncTx)
|
||||
furi_hal_irda_state = IrdaStateAsyncTxStopReq;
|
||||
__enable_irq();
|
||||
|
||||
api_hal_irda_async_tx_wait_termination();
|
||||
furi_hal_irda_async_tx_wait_termination();
|
||||
}
|
||||
|
||||
void api_hal_irda_async_tx_set_data_isr_callback(ApiHalIrdaTxGetDataCallback callback, void* context) {
|
||||
furi_assert(api_hal_irda_state == IrdaStateIdle);
|
||||
void furi_hal_irda_async_tx_set_data_isr_callback(FuriHalIrdaTxGetDataCallback callback, void* context) {
|
||||
furi_assert(furi_hal_irda_state == IrdaStateIdle);
|
||||
irda_tim_tx.data_callback = callback;
|
||||
irda_tim_tx.data_context = context;
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
#include <api-hal-light.h>
|
||||
#include <furi-hal-light.h>
|
||||
#include <lp5562.h>
|
||||
|
||||
#define LED_CURRENT_RED 50
|
||||
@@ -6,7 +6,7 @@
|
||||
#define LED_CURRENT_BLUE 50
|
||||
#define LED_CURRENT_WHITE 150
|
||||
|
||||
void api_hal_light_init() {
|
||||
void furi_hal_light_init() {
|
||||
lp5562_reset();
|
||||
|
||||
lp5562_set_channel_current(LP5562ChannelRed, LED_CURRENT_RED);
|
||||
@@ -24,7 +24,7 @@ void api_hal_light_init() {
|
||||
FURI_LOG_I("FuriHalLight", "Init OK");
|
||||
}
|
||||
|
||||
void api_hal_light_set(Light light, uint8_t value) {
|
||||
void furi_hal_light_set(Light light, uint8_t value) {
|
||||
switch(light) {
|
||||
case LightRed:
|
||||
lp5562_set_channel_value(LP5562ChannelRed, value);
|
@@ -1,41 +1,41 @@
|
||||
#include "api-hal-nfc.h"
|
||||
#include "furi-hal-nfc.h"
|
||||
#include <st25r3916.h>
|
||||
|
||||
static const uint32_t clocks_in_ms = 64 * 1000;
|
||||
|
||||
void api_hal_nfc_init() {
|
||||
void furi_hal_nfc_init() {
|
||||
ReturnCode ret = rfalNfcInitialize();
|
||||
if(ret == ERR_NONE) {
|
||||
api_hal_nfc_start_sleep();
|
||||
furi_hal_nfc_start_sleep();
|
||||
FURI_LOG_I("FuriHalNfc", "Init OK");
|
||||
} else {
|
||||
FURI_LOG_W("FuriHalNfc", "Initialization failed, RFAL returned: %d", ret);
|
||||
}
|
||||
}
|
||||
|
||||
bool api_hal_nfc_is_busy() {
|
||||
bool furi_hal_nfc_is_busy() {
|
||||
return rfalNfcGetState() != RFAL_NFC_STATE_IDLE;
|
||||
}
|
||||
|
||||
void api_hal_nfc_field_on() {
|
||||
api_hal_nfc_exit_sleep();
|
||||
void furi_hal_nfc_field_on() {
|
||||
furi_hal_nfc_exit_sleep();
|
||||
st25r3916TxRxOn();
|
||||
}
|
||||
|
||||
void api_hal_nfc_field_off() {
|
||||
void furi_hal_nfc_field_off() {
|
||||
st25r3916TxRxOff();
|
||||
api_hal_nfc_start_sleep();
|
||||
furi_hal_nfc_start_sleep();
|
||||
}
|
||||
|
||||
void api_hal_nfc_start_sleep() {
|
||||
void furi_hal_nfc_start_sleep() {
|
||||
rfalLowPowerModeStart();
|
||||
}
|
||||
|
||||
void api_hal_nfc_exit_sleep() {
|
||||
void furi_hal_nfc_exit_sleep() {
|
||||
rfalLowPowerModeStop();
|
||||
}
|
||||
|
||||
bool api_hal_nfc_detect(rfalNfcDevice **dev_list, uint8_t* dev_cnt, uint32_t timeout, bool deactivate) {
|
||||
bool furi_hal_nfc_detect(rfalNfcDevice **dev_list, uint8_t* dev_cnt, uint32_t timeout, bool deactivate) {
|
||||
furi_assert(dev_list);
|
||||
furi_assert(dev_cnt);
|
||||
|
||||
@@ -86,7 +86,7 @@ bool api_hal_nfc_detect(rfalNfcDevice **dev_list, uint8_t* dev_cnt, uint32_t tim
|
||||
return true;
|
||||
}
|
||||
|
||||
bool api_hal_nfc_listen(uint8_t* uid, uint8_t uid_len, uint8_t* atqa, uint8_t sak, uint32_t timeout) {
|
||||
bool furi_hal_nfc_listen(uint8_t* uid, uint8_t uid_len, uint8_t* atqa, uint8_t sak, uint32_t timeout) {
|
||||
rfalNfcState state = rfalNfcGetState();
|
||||
|
||||
if(state == RFAL_NFC_STATE_NOTINIT) {
|
||||
@@ -129,7 +129,7 @@ bool api_hal_nfc_listen(uint8_t* uid, uint8_t uid_len, uint8_t* atqa, uint8_t sa
|
||||
return true;
|
||||
}
|
||||
|
||||
ReturnCode api_hal_nfc_data_exchange(uint8_t* tx_buff, uint16_t tx_len, uint8_t** rx_buff, uint16_t** rx_len, bool deactivate) {
|
||||
ReturnCode furi_hal_nfc_data_exchange(uint8_t* tx_buff, uint16_t tx_len, uint8_t** rx_buff, uint16_t** rx_len, bool deactivate) {
|
||||
furi_assert(rx_buff);
|
||||
furi_assert(rx_len);
|
||||
|
||||
@@ -165,7 +165,7 @@ ReturnCode api_hal_nfc_data_exchange(uint8_t* tx_buff, uint16_t tx_len, uint8_t*
|
||||
return ERR_NONE;
|
||||
}
|
||||
|
||||
void api_hal_nfc_deactivate() {
|
||||
void furi_hal_nfc_deactivate() {
|
||||
rfalNfcDeactivate(false);
|
||||
rfalLowPowerModeStart();
|
||||
}
|
64
firmware/targets/f6/furi-hal/furi-hal-os-timer.h
Normal file
64
firmware/targets/f6/furi-hal/furi-hal-os-timer.h
Normal file
@@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
#include <stm32wbxx_ll_lptim.h>
|
||||
#include <stm32wbxx_ll_bus.h>
|
||||
#include <stdint.h>
|
||||
|
||||
// Timer used for system ticks
|
||||
#define FURI_HAL_OS_TIMER_MAX 0xFFFF
|
||||
#define FURI_HAL_OS_TIMER_REG_LOAD_DLY 0x1
|
||||
#define FURI_HAL_OS_TIMER LPTIM2
|
||||
#define FURI_HAL_OS_TIMER_IRQ LPTIM2_IRQn
|
||||
|
||||
static inline void furi_hal_os_timer_init() {
|
||||
// Configure clock source
|
||||
LL_RCC_SetLPTIMClockSource(LL_RCC_LPTIM2_CLKSOURCE_LSE);
|
||||
LL_APB1_GRP2_EnableClock(LL_APB1_GRP2_PERIPH_LPTIM2);
|
||||
// Set interrupt priority and enable them
|
||||
NVIC_SetPriority(FURI_HAL_OS_TIMER_IRQ, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 15, 0));
|
||||
NVIC_EnableIRQ(FURI_HAL_OS_TIMER_IRQ);
|
||||
}
|
||||
|
||||
static inline void furi_hal_os_timer_continuous(uint32_t count) {
|
||||
// Enable timer
|
||||
LL_LPTIM_Enable(FURI_HAL_OS_TIMER);
|
||||
while(!LL_LPTIM_IsEnabled(FURI_HAL_OS_TIMER));
|
||||
|
||||
// Enable rutoreload match interrupt
|
||||
LL_LPTIM_EnableIT_ARRM(FURI_HAL_OS_TIMER);
|
||||
|
||||
// Set autoreload and start counter
|
||||
LL_LPTIM_SetAutoReload(FURI_HAL_OS_TIMER, count);
|
||||
LL_LPTIM_StartCounter(FURI_HAL_OS_TIMER, LL_LPTIM_OPERATING_MODE_CONTINUOUS);
|
||||
}
|
||||
|
||||
static inline void furi_hal_os_timer_single(uint32_t count) {
|
||||
// Enable timer
|
||||
LL_LPTIM_Enable(FURI_HAL_OS_TIMER);
|
||||
while(!LL_LPTIM_IsEnabled(FURI_HAL_OS_TIMER));
|
||||
|
||||
// Enable compare match interrupt
|
||||
LL_LPTIM_EnableIT_CMPM(FURI_HAL_OS_TIMER);
|
||||
|
||||
// Set compare, autoreload and start counter
|
||||
// Include some marging to workaround ARRM behaviour
|
||||
LL_LPTIM_SetCompare(FURI_HAL_OS_TIMER, count-3);
|
||||
LL_LPTIM_SetAutoReload(FURI_HAL_OS_TIMER, count);
|
||||
LL_LPTIM_StartCounter(FURI_HAL_OS_TIMER, LL_LPTIM_OPERATING_MODE_ONESHOT);
|
||||
}
|
||||
|
||||
static inline void furi_hal_os_timer_reset() {
|
||||
// Hard reset timer
|
||||
// THE ONLY RELIABLEWAY to stop it according to errata
|
||||
LL_LPTIM_DeInit(FURI_HAL_OS_TIMER);
|
||||
}
|
||||
|
||||
static inline uint32_t furi_hal_os_timer_get_cnt() {
|
||||
uint32_t counter = LL_LPTIM_GetCounter(FURI_HAL_OS_TIMER);
|
||||
uint32_t counter_shadow = LL_LPTIM_GetCounter(FURI_HAL_OS_TIMER);
|
||||
while(counter != counter_shadow) {
|
||||
counter = counter_shadow;
|
||||
counter_shadow = LL_LPTIM_GetCounter(FURI_HAL_OS_TIMER);
|
||||
}
|
||||
return counter;
|
||||
}
|
@@ -1,17 +1,17 @@
|
||||
#include <api-hal-os.h>
|
||||
#include <api-hal-os-timer.h>
|
||||
#include <api-hal-power.h>
|
||||
#include <furi-hal-os.h>
|
||||
#include <furi-hal-os-timer.h>
|
||||
#include <furi-hal-power.h>
|
||||
#include <stm32wbxx_ll_cortex.h>
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#define API_HAL_OS_CLK_FREQUENCY 32768
|
||||
#define API_HAL_OS_TICK_PER_SECOND 1024
|
||||
#define API_HAL_OS_CLK_PER_TICK (API_HAL_OS_CLK_FREQUENCY / API_HAL_OS_TICK_PER_SECOND)
|
||||
#define API_HAL_OS_TICK_PER_EPOCH (API_HAL_OS_TIMER_MAX / API_HAL_OS_CLK_PER_TICK)
|
||||
#define API_HAL_OS_MAX_SLEEP (API_HAL_OS_TICK_PER_EPOCH - 1)
|
||||
#define FURI_HAL_OS_CLK_FREQUENCY 32768
|
||||
#define FURI_HAL_OS_TICK_PER_SECOND 1024
|
||||
#define FURI_HAL_OS_CLK_PER_TICK (FURI_HAL_OS_CLK_FREQUENCY / FURI_HAL_OS_TICK_PER_SECOND)
|
||||
#define FURI_HAL_OS_TICK_PER_EPOCH (FURI_HAL_OS_TIMER_MAX / FURI_HAL_OS_CLK_PER_TICK)
|
||||
#define FURI_HAL_OS_MAX_SLEEP (FURI_HAL_OS_TICK_PER_EPOCH - 1)
|
||||
|
||||
#ifdef API_HAL_OS_DEBUG
|
||||
#ifdef FURI_HAL_OS_DEBUG
|
||||
#include <stm32wbxx_ll_gpio.h>
|
||||
|
||||
#define LED_SLEEP_PORT GPIOA
|
||||
@@ -21,24 +21,24 @@
|
||||
#define LED_SECOND_PORT GPIOA
|
||||
#define LED_SECOND_PIN LL_GPIO_PIN_4
|
||||
|
||||
void api_hal_os_timer_callback() {
|
||||
void furi_hal_os_timer_callback() {
|
||||
LL_GPIO_TogglePin(LED_SECOND_PORT, LED_SECOND_PIN);
|
||||
}
|
||||
#endif
|
||||
|
||||
volatile uint32_t api_hal_os_skew = 0;
|
||||
volatile uint32_t furi_hal_os_skew = 0;
|
||||
|
||||
void api_hal_os_init() {
|
||||
void furi_hal_os_init() {
|
||||
LL_DBGMCU_APB1_GRP2_FreezePeriph(LL_DBGMCU_APB1_GRP2_LPTIM2_STOP);
|
||||
|
||||
api_hal_os_timer_init();
|
||||
api_hal_os_timer_continuous(API_HAL_OS_CLK_PER_TICK);
|
||||
furi_hal_os_timer_init();
|
||||
furi_hal_os_timer_continuous(FURI_HAL_OS_CLK_PER_TICK);
|
||||
|
||||
#ifdef API_HAL_OS_DEBUG
|
||||
#ifdef FURI_HAL_OS_DEBUG
|
||||
LL_GPIO_SetPinMode(LED_SLEEP_PORT, LED_SLEEP_PIN, LL_GPIO_MODE_OUTPUT);
|
||||
LL_GPIO_SetPinMode(LED_TICK_PORT, LED_TICK_PIN, LL_GPIO_MODE_OUTPUT);
|
||||
LL_GPIO_SetPinMode(LED_SECOND_PORT, LED_SECOND_PIN, LL_GPIO_MODE_OUTPUT);
|
||||
osTimerId_t second_timer = osTimerNew(api_hal_os_timer_callback, osTimerPeriodic, NULL, NULL);
|
||||
osTimerId_t second_timer = osTimerNew(furi_hal_os_timer_callback, osTimerPeriodic, NULL, NULL);
|
||||
osTimerStart(second_timer, 1024);
|
||||
#endif
|
||||
|
||||
@@ -47,67 +47,67 @@ void api_hal_os_init() {
|
||||
|
||||
void LPTIM2_IRQHandler(void) {
|
||||
// Autoreload
|
||||
if(LL_LPTIM_IsActiveFlag_ARRM(API_HAL_OS_TIMER)) {
|
||||
LL_LPTIM_ClearFLAG_ARRM(API_HAL_OS_TIMER);
|
||||
if(LL_LPTIM_IsActiveFlag_ARRM(FURI_HAL_OS_TIMER)) {
|
||||
LL_LPTIM_ClearFLAG_ARRM(FURI_HAL_OS_TIMER);
|
||||
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
|
||||
#ifdef API_HAL_OS_DEBUG
|
||||
#ifdef FURI_HAL_OS_DEBUG
|
||||
LL_GPIO_TogglePin(LED_TICK_PORT, LED_TICK_PIN);
|
||||
#endif
|
||||
xPortSysTickHandler();
|
||||
}
|
||||
}
|
||||
if(LL_LPTIM_IsActiveFlag_CMPM(API_HAL_OS_TIMER)) {
|
||||
LL_LPTIM_ClearFLAG_CMPM(API_HAL_OS_TIMER);
|
||||
if(LL_LPTIM_IsActiveFlag_CMPM(FURI_HAL_OS_TIMER)) {
|
||||
LL_LPTIM_ClearFLAG_CMPM(FURI_HAL_OS_TIMER);
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint32_t api_hal_os_sleep(TickType_t expected_idle_ticks) {
|
||||
static inline uint32_t furi_hal_os_sleep(TickType_t expected_idle_ticks) {
|
||||
// Stop ticks
|
||||
api_hal_os_timer_reset();
|
||||
furi_hal_os_timer_reset();
|
||||
LL_SYSTICK_DisableIT();
|
||||
|
||||
// Start wakeup timer
|
||||
api_hal_os_timer_single(expected_idle_ticks * API_HAL_OS_CLK_PER_TICK);
|
||||
furi_hal_os_timer_single(expected_idle_ticks * FURI_HAL_OS_CLK_PER_TICK);
|
||||
|
||||
#ifdef API_HAL_OS_DEBUG
|
||||
#ifdef FURI_HAL_OS_DEBUG
|
||||
LL_GPIO_ResetOutputPin(LED_SLEEP_PORT, LED_SLEEP_PIN);
|
||||
#endif
|
||||
|
||||
// Go to sleep mode
|
||||
api_hal_power_sleep();
|
||||
furi_hal_power_sleep();
|
||||
|
||||
#ifdef API_HAL_OS_DEBUG
|
||||
#ifdef FURI_HAL_OS_DEBUG
|
||||
LL_GPIO_SetOutputPin(LED_SLEEP_PORT, LED_SLEEP_PIN);
|
||||
#endif
|
||||
|
||||
// Calculate how much time we spent in the sleep
|
||||
uint32_t after_cnt = api_hal_os_timer_get_cnt() + api_hal_os_skew;
|
||||
uint32_t after_tick = after_cnt / API_HAL_OS_CLK_PER_TICK;
|
||||
api_hal_os_skew = after_cnt % API_HAL_OS_CLK_PER_TICK;
|
||||
uint32_t after_cnt = furi_hal_os_timer_get_cnt() + furi_hal_os_skew;
|
||||
uint32_t after_tick = after_cnt / FURI_HAL_OS_CLK_PER_TICK;
|
||||
furi_hal_os_skew = after_cnt % FURI_HAL_OS_CLK_PER_TICK;
|
||||
|
||||
bool cmpm = LL_LPTIM_IsActiveFlag_CMPM(API_HAL_OS_TIMER);
|
||||
bool arrm = LL_LPTIM_IsActiveFlag_ARRM(API_HAL_OS_TIMER);
|
||||
bool cmpm = LL_LPTIM_IsActiveFlag_CMPM(FURI_HAL_OS_TIMER);
|
||||
bool arrm = LL_LPTIM_IsActiveFlag_ARRM(FURI_HAL_OS_TIMER);
|
||||
if (cmpm && arrm) after_tick += expected_idle_ticks;
|
||||
|
||||
// Prepare tick timer for new round
|
||||
api_hal_os_timer_reset();
|
||||
furi_hal_os_timer_reset();
|
||||
|
||||
// Resume ticks
|
||||
LL_SYSTICK_EnableIT();
|
||||
api_hal_os_timer_continuous(API_HAL_OS_CLK_PER_TICK);
|
||||
furi_hal_os_timer_continuous(FURI_HAL_OS_CLK_PER_TICK);
|
||||
|
||||
return after_tick;
|
||||
}
|
||||
|
||||
void vPortSuppressTicksAndSleep(TickType_t expected_idle_ticks) {
|
||||
if(!api_hal_power_sleep_available()) {
|
||||
if(!furi_hal_power_sleep_available()) {
|
||||
__WFI();
|
||||
return;
|
||||
}
|
||||
|
||||
// Limit mount of ticks to maximum that timer can count
|
||||
if (expected_idle_ticks > API_HAL_OS_MAX_SLEEP) {
|
||||
expected_idle_ticks = API_HAL_OS_MAX_SLEEP;
|
||||
if (expected_idle_ticks > FURI_HAL_OS_MAX_SLEEP) {
|
||||
expected_idle_ticks = FURI_HAL_OS_MAX_SLEEP;
|
||||
}
|
||||
|
||||
// Stop IRQ handling, no one should disturb us till we finish
|
||||
@@ -120,7 +120,7 @@ void vPortSuppressTicksAndSleep(TickType_t expected_idle_ticks) {
|
||||
}
|
||||
|
||||
// Sleep and track how much ticks we spent sleeping
|
||||
uint32_t completed_ticks = api_hal_os_sleep(expected_idle_ticks);
|
||||
uint32_t completed_ticks = furi_hal_os_sleep(expected_idle_ticks);
|
||||
|
||||
// Reenable IRQ
|
||||
__enable_irq();
|
@@ -10,7 +10,7 @@ extern "C" {
|
||||
/* Initialize OS helpers
|
||||
* Configure and start tick timer
|
||||
*/
|
||||
void api_hal_os_init();
|
||||
void furi_hal_os_init();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
#include <api-hal-power.h>
|
||||
#include <api-hal-clock.h>
|
||||
#include <api-hal-bt.h>
|
||||
#include <furi-hal-power.h>
|
||||
#include <furi-hal-clock.h>
|
||||
#include <furi-hal-bt.h>
|
||||
|
||||
#include <stm32wbxx_ll_rcc.h>
|
||||
#include <stm32wbxx_ll_pwr.h>
|
||||
@@ -18,9 +18,9 @@
|
||||
typedef struct {
|
||||
volatile uint32_t insomnia;
|
||||
volatile uint32_t deep_insomnia;
|
||||
} ApiHalPower;
|
||||
} FuriHalPower;
|
||||
|
||||
static volatile ApiHalPower api_hal_power = {
|
||||
static volatile FuriHalPower furi_hal_power = {
|
||||
.insomnia = 0,
|
||||
.deep_insomnia = 1,
|
||||
};
|
||||
@@ -64,10 +64,10 @@ const ParamCEDV cedv = {
|
||||
|
||||
void HAL_RCC_CSSCallback(void) {
|
||||
// TODO: notify user about issue with HSE
|
||||
api_hal_power_reset();
|
||||
furi_hal_power_reset();
|
||||
}
|
||||
|
||||
void api_hal_power_init() {
|
||||
void furi_hal_power_init() {
|
||||
LL_PWR_SetRegulVoltageScaling(LL_PWR_REGU_VOLTAGE_SCALE1);
|
||||
LL_PWR_SMPS_SetMode(LL_PWR_SMPS_STEP_DOWN);
|
||||
bq27220_init(&cedv);
|
||||
@@ -75,31 +75,31 @@ void api_hal_power_init() {
|
||||
FURI_LOG_I("FuriHalPower", "Init OK");
|
||||
}
|
||||
|
||||
uint16_t api_hal_power_insomnia_level() {
|
||||
return api_hal_power.insomnia;
|
||||
uint16_t furi_hal_power_insomnia_level() {
|
||||
return furi_hal_power.insomnia;
|
||||
}
|
||||
|
||||
void api_hal_power_insomnia_enter() {
|
||||
api_hal_power.insomnia++;
|
||||
void furi_hal_power_insomnia_enter() {
|
||||
furi_hal_power.insomnia++;
|
||||
}
|
||||
|
||||
void api_hal_power_insomnia_exit() {
|
||||
api_hal_power.insomnia--;
|
||||
void furi_hal_power_insomnia_exit() {
|
||||
furi_hal_power.insomnia--;
|
||||
}
|
||||
|
||||
bool api_hal_power_sleep_available() {
|
||||
return api_hal_power.insomnia == 0;
|
||||
bool furi_hal_power_sleep_available() {
|
||||
return furi_hal_power.insomnia == 0;
|
||||
}
|
||||
|
||||
bool api_hal_power_deep_sleep_available() {
|
||||
return api_hal_bt_is_alive() && api_hal_power.deep_insomnia == 0;
|
||||
bool furi_hal_power_deep_sleep_available() {
|
||||
return furi_hal_bt_is_alive() && furi_hal_power.deep_insomnia == 0;
|
||||
}
|
||||
|
||||
void api_hal_power_light_sleep() {
|
||||
void furi_hal_power_light_sleep() {
|
||||
__WFI();
|
||||
}
|
||||
|
||||
void api_hal_power_deep_sleep() {
|
||||
void furi_hal_power_deep_sleep() {
|
||||
while( LL_HSEM_1StepLock(HSEM, CFG_HW_RCC_SEMID));
|
||||
|
||||
if (!LL_HSEM_1StepLock(HSEM, CFG_HW_ENTRY_STOP_MODE_SEMID)) {
|
||||
@@ -108,13 +108,13 @@ void api_hal_power_deep_sleep() {
|
||||
LL_HSEM_ReleaseLock(HSEM, CFG_HW_ENTRY_STOP_MODE_SEMID, 0);
|
||||
|
||||
// The switch on HSI before entering Stop Mode is required
|
||||
api_hal_clock_switch_to_hsi();
|
||||
furi_hal_clock_switch_to_hsi();
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* The switch on HSI before entering Stop Mode is required
|
||||
*/
|
||||
api_hal_clock_switch_to_hsi();
|
||||
furi_hal_clock_switch_to_hsi();
|
||||
}
|
||||
|
||||
/* Release RCC semaphore */
|
||||
@@ -137,82 +137,82 @@ void api_hal_power_deep_sleep() {
|
||||
while(LL_HSEM_1StepLock(HSEM, CFG_HW_RCC_SEMID));
|
||||
|
||||
if(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) {
|
||||
api_hal_clock_switch_to_pll();
|
||||
furi_hal_clock_switch_to_pll();
|
||||
}
|
||||
|
||||
LL_HSEM_ReleaseLock(HSEM, CFG_HW_RCC_SEMID, 0);
|
||||
}
|
||||
|
||||
void api_hal_power_sleep() {
|
||||
if(api_hal_power_deep_sleep_available()) {
|
||||
api_hal_power_deep_sleep();
|
||||
void furi_hal_power_sleep() {
|
||||
if(furi_hal_power_deep_sleep_available()) {
|
||||
furi_hal_power_deep_sleep();
|
||||
} else {
|
||||
api_hal_power_light_sleep();
|
||||
furi_hal_power_light_sleep();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint8_t api_hal_power_get_pct() {
|
||||
uint8_t furi_hal_power_get_pct() {
|
||||
return bq27220_get_state_of_charge();
|
||||
}
|
||||
|
||||
uint8_t api_hal_power_get_bat_health_pct() {
|
||||
uint8_t furi_hal_power_get_bat_health_pct() {
|
||||
return bq27220_get_state_of_health();
|
||||
}
|
||||
|
||||
bool api_hal_power_is_charging() {
|
||||
bool furi_hal_power_is_charging() {
|
||||
return bq25896_is_charging();
|
||||
}
|
||||
|
||||
void api_hal_power_off() {
|
||||
void furi_hal_power_off() {
|
||||
bq25896_poweroff();
|
||||
}
|
||||
|
||||
void api_hal_power_reset() {
|
||||
void furi_hal_power_reset() {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
void api_hal_power_enable_otg() {
|
||||
void furi_hal_power_enable_otg() {
|
||||
bq25896_enable_otg();
|
||||
}
|
||||
|
||||
void api_hal_power_disable_otg() {
|
||||
void furi_hal_power_disable_otg() {
|
||||
bq25896_disable_otg();
|
||||
}
|
||||
|
||||
uint32_t api_hal_power_get_battery_remaining_capacity() {
|
||||
uint32_t furi_hal_power_get_battery_remaining_capacity() {
|
||||
return bq27220_get_remaining_capacity();
|
||||
}
|
||||
|
||||
uint32_t api_hal_power_get_battery_full_capacity() {
|
||||
uint32_t furi_hal_power_get_battery_full_capacity() {
|
||||
return bq27220_get_full_charge_capacity();
|
||||
}
|
||||
|
||||
float api_hal_power_get_battery_voltage(ApiHalPowerIC ic) {
|
||||
if (ic == ApiHalPowerICCharger) {
|
||||
float furi_hal_power_get_battery_voltage(FuriHalPowerIC ic) {
|
||||
if (ic == FuriHalPowerICCharger) {
|
||||
return (float)bq25896_get_vbat_voltage() / 1000.0f;
|
||||
} else if (ic == ApiHalPowerICFuelGauge) {
|
||||
} else if (ic == FuriHalPowerICFuelGauge) {
|
||||
return (float)bq27220_get_voltage() / 1000.0f;
|
||||
} else {
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
float api_hal_power_get_battery_current(ApiHalPowerIC ic) {
|
||||
if (ic == ApiHalPowerICCharger) {
|
||||
float furi_hal_power_get_battery_current(FuriHalPowerIC ic) {
|
||||
if (ic == FuriHalPowerICCharger) {
|
||||
return (float)bq25896_get_vbat_current() / 1000.0f;
|
||||
} else if (ic == ApiHalPowerICFuelGauge) {
|
||||
} else if (ic == FuriHalPowerICFuelGauge) {
|
||||
return (float)bq27220_get_current() / 1000.0f;
|
||||
} else {
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
float api_hal_power_get_battery_temperature(ApiHalPowerIC ic) {
|
||||
if (ic == ApiHalPowerICCharger) {
|
||||
float furi_hal_power_get_battery_temperature(FuriHalPowerIC ic) {
|
||||
if (ic == FuriHalPowerICCharger) {
|
||||
// Linear approximation, +/- 5 C
|
||||
return (71.0f - (float)bq25896_get_ntc_mpct()/1000) / 0.6f;
|
||||
} else if (ic == ApiHalPowerICFuelGauge) {
|
||||
} else if (ic == FuriHalPowerICFuelGauge) {
|
||||
return ((float)bq27220_get_temperature() - 2731.0f) / 10.0f;
|
||||
} else {
|
||||
return 0.0f;
|
||||
@@ -220,11 +220,11 @@ float api_hal_power_get_battery_temperature(ApiHalPowerIC ic) {
|
||||
|
||||
}
|
||||
|
||||
float api_hal_power_get_usb_voltage(){
|
||||
float furi_hal_power_get_usb_voltage(){
|
||||
return (float)bq25896_get_vbus_voltage() / 1000.0f;
|
||||
}
|
||||
|
||||
void api_hal_power_dump_state() {
|
||||
void furi_hal_power_dump_state() {
|
||||
BatteryStatus battery_status;
|
||||
OperationStatus operation_status;
|
||||
if (bq27220_get_battery_status(&battery_status) == BQ27220_ERROR
|
||||
@@ -259,7 +259,7 @@ void api_hal_power_dump_state() {
|
||||
);
|
||||
printf(
|
||||
"bq27220: Voltage: %dmV, Current: %dmA, Temperature: %dC\r\n",
|
||||
bq27220_get_voltage(), bq27220_get_current(), (int)api_hal_power_get_battery_temperature(ApiHalPowerICFuelGauge)
|
||||
bq27220_get_voltage(), bq27220_get_current(), (int)furi_hal_power_get_battery_temperature(FuriHalPowerICFuelGauge)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -271,10 +271,10 @@ void api_hal_power_dump_state() {
|
||||
);
|
||||
}
|
||||
|
||||
void api_hal_power_enable_external_3_3v(){
|
||||
void furi_hal_power_enable_external_3_3v(){
|
||||
LL_GPIO_SetOutputPin(PERIPH_POWER_GPIO_Port, PERIPH_POWER_Pin);
|
||||
}
|
||||
|
||||
void api_hal_power_disable_external_3_3v(){
|
||||
void furi_hal_power_disable_external_3_3v(){
|
||||
LL_GPIO_ResetOutputPin(PERIPH_POWER_GPIO_Port, PERIPH_POWER_Pin);
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
#include "api-hal-pwm.h"
|
||||
#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;
|
@@ -1,4 +1,4 @@
|
||||
#include <api-hal-resources.h>
|
||||
#include <furi-hal-resources.h>
|
||||
#include "main.h"
|
||||
#include <furi.h>
|
||||
|
@@ -1,15 +1,15 @@
|
||||
#include <api-hal-rfid.h>
|
||||
#include <api-hal-ibutton.h>
|
||||
#include <api-hal-resources.h>
|
||||
#include <furi-hal-rfid.h>
|
||||
#include <furi-hal-ibutton.h>
|
||||
#include <furi-hal-resources.h>
|
||||
|
||||
#define LFRFID_READ_TIM htim1
|
||||
#define LFRFID_READ_CHANNEL TIM_CHANNEL_1
|
||||
#define LFRFID_EMULATE_TIM htim2
|
||||
#define LFRFID_EMULATE_CHANNEL TIM_CHANNEL_3
|
||||
|
||||
void api_hal_rfid_pins_reset() {
|
||||
void furi_hal_rfid_pins_reset() {
|
||||
// ibutton bus disable
|
||||
api_hal_ibutton_stop();
|
||||
furi_hal_ibutton_stop();
|
||||
|
||||
// pulldown rfid antenna
|
||||
hal_gpio_init(&gpio_rfid_carrier_out, GpioModeOutputPushPull, GpioSpeedLow, GpioPullNo);
|
||||
@@ -20,10 +20,10 @@ void api_hal_rfid_pins_reset() {
|
||||
hal_gpio_write(&gpio_rfid_pull, true);
|
||||
}
|
||||
|
||||
void api_hal_rfid_pins_emulate() {
|
||||
void furi_hal_rfid_pins_emulate() {
|
||||
// ibutton low
|
||||
api_hal_ibutton_start();
|
||||
api_hal_ibutton_pin_low();
|
||||
furi_hal_ibutton_start();
|
||||
furi_hal_ibutton_pin_low();
|
||||
|
||||
// pull pin to timer out
|
||||
hal_gpio_init_ex(
|
||||
@@ -34,10 +34,10 @@ void api_hal_rfid_pins_emulate() {
|
||||
hal_gpio_write(&gpio_rfid_carrier_out, false);
|
||||
}
|
||||
|
||||
void api_hal_rfid_pins_read() {
|
||||
void furi_hal_rfid_pins_read() {
|
||||
// ibutton low
|
||||
api_hal_ibutton_start();
|
||||
api_hal_ibutton_pin_low();
|
||||
furi_hal_ibutton_start();
|
||||
furi_hal_ibutton_pin_low();
|
||||
|
||||
// dont pull rfid antenna
|
||||
hal_gpio_init(&gpio_rfid_pull, GpioModeOutputPushPull, GpioSpeedLow, GpioPullNo);
|
||||
@@ -55,7 +55,7 @@ void api_hal_rfid_pins_read() {
|
||||
hal_gpio_init(&gpio_rfid_data_in, GpioModeAnalog, GpioSpeedLow, GpioPullNo);
|
||||
}
|
||||
|
||||
void api_hal_rfid_tim_read(float freq, float duty_cycle) {
|
||||
void furi_hal_rfid_tim_read(float freq, float duty_cycle) {
|
||||
// TODO LL init
|
||||
uint32_t period = (uint32_t)((SystemCoreClock) / freq) - 1;
|
||||
|
||||
@@ -121,15 +121,15 @@ void api_hal_rfid_tim_read(float freq, float duty_cycle) {
|
||||
}
|
||||
}
|
||||
|
||||
void api_hal_rfid_tim_read_start() {
|
||||
void furi_hal_rfid_tim_read_start() {
|
||||
HAL_TIMEx_PWMN_Start(&LFRFID_READ_TIM, LFRFID_READ_CHANNEL);
|
||||
}
|
||||
|
||||
void api_hal_rfid_tim_read_stop() {
|
||||
void furi_hal_rfid_tim_read_stop() {
|
||||
HAL_TIMEx_PWMN_Stop(&LFRFID_READ_TIM, LFRFID_READ_CHANNEL);
|
||||
}
|
||||
|
||||
void api_hal_rfid_tim_emulate(float freq) {
|
||||
void furi_hal_rfid_tim_emulate(float freq) {
|
||||
// TODO LL init
|
||||
uint32_t prescaler = (uint32_t)((SystemCoreClock) / freq) - 1;
|
||||
|
||||
@@ -196,7 +196,7 @@ void api_hal_rfid_tim_emulate(float freq) {
|
||||
}
|
||||
}
|
||||
|
||||
void api_hal_rfid_tim_emulate_start() {
|
||||
void furi_hal_rfid_tim_emulate_start() {
|
||||
// TODO make api for interrupts priority
|
||||
for(size_t i = WWDG_IRQn; i <= DMAMUX1_OVR_IRQn; i++) {
|
||||
HAL_NVIC_SetPriority(i, 15, 0);
|
||||
@@ -209,25 +209,25 @@ void api_hal_rfid_tim_emulate_start() {
|
||||
HAL_TIM_Base_Start_IT(&LFRFID_EMULATE_TIM);
|
||||
}
|
||||
|
||||
void api_hal_rfid_tim_emulate_stop() {
|
||||
void furi_hal_rfid_tim_emulate_stop() {
|
||||
HAL_TIM_Base_Stop(&LFRFID_EMULATE_TIM);
|
||||
HAL_TIM_PWM_Stop(&LFRFID_EMULATE_TIM, LFRFID_EMULATE_CHANNEL);
|
||||
}
|
||||
|
||||
void api_hal_rfid_tim_reset() {
|
||||
void furi_hal_rfid_tim_reset() {
|
||||
HAL_TIM_Base_DeInit(&LFRFID_READ_TIM);
|
||||
HAL_TIM_Base_DeInit(&LFRFID_EMULATE_TIM);
|
||||
}
|
||||
|
||||
bool api_hal_rfid_is_tim_emulate(TIM_HandleTypeDef* hw) {
|
||||
bool furi_hal_rfid_is_tim_emulate(TIM_HandleTypeDef* hw) {
|
||||
return (hw == &LFRFID_EMULATE_TIM);
|
||||
}
|
||||
|
||||
void api_hal_rfid_set_emulate_period(uint32_t period) {
|
||||
void furi_hal_rfid_set_emulate_period(uint32_t period) {
|
||||
LFRFID_EMULATE_TIM.Instance->ARR = period;
|
||||
}
|
||||
|
||||
void api_hal_rfid_set_emulate_pulse(uint32_t pulse) {
|
||||
void furi_hal_rfid_set_emulate_pulse(uint32_t pulse) {
|
||||
switch(LFRFID_EMULATE_CHANNEL) {
|
||||
case TIM_CHANNEL_1:
|
||||
LFRFID_EMULATE_TIM.Instance->CCR1 = pulse;
|
||||
@@ -247,11 +247,11 @@ void api_hal_rfid_set_emulate_pulse(uint32_t pulse) {
|
||||
}
|
||||
}
|
||||
|
||||
void api_hal_rfid_set_read_period(uint32_t period) {
|
||||
void furi_hal_rfid_set_read_period(uint32_t period) {
|
||||
LFRFID_TIM.Instance->ARR = period;
|
||||
}
|
||||
|
||||
void api_hal_rfid_set_read_pulse(uint32_t pulse) {
|
||||
void furi_hal_rfid_set_read_pulse(uint32_t pulse) {
|
||||
switch(LFRFID_READ_CHANNEL) {
|
||||
case TIM_CHANNEL_1:
|
||||
LFRFID_TIM.Instance->CCR1 = pulse;
|
||||
@@ -271,8 +271,8 @@ void api_hal_rfid_set_read_pulse(uint32_t pulse) {
|
||||
}
|
||||
}
|
||||
|
||||
void api_hal_rfid_change_read_config(float freq, float duty_cycle) {
|
||||
void furi_hal_rfid_change_read_config(float freq, float duty_cycle) {
|
||||
uint32_t period = (uint32_t)((SystemCoreClock) / freq) - 1;
|
||||
api_hal_rfid_set_read_period(period);
|
||||
api_hal_rfid_set_read_pulse(period * duty_cycle);
|
||||
furi_hal_rfid_set_read_period(period);
|
||||
furi_hal_rfid_set_read_pulse(period * duty_cycle);
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
#include "api-hal-sd.h"
|
||||
#include "furi-hal-sd.h"
|
||||
#include <stm32wbxx_ll_gpio.h>
|
||||
#include <furi.h>
|
||||
|
@@ -1,10 +1,10 @@
|
||||
#include <api-hal-spi-config.h>
|
||||
#include <api-hal-resources.h>
|
||||
#include <furi-hal-spi-config.h>
|
||||
#include <furi-hal-resources.h>
|
||||
|
||||
extern SPI_HandleTypeDef SPI_R;
|
||||
extern SPI_HandleTypeDef SPI_D;
|
||||
|
||||
const SPI_InitTypeDef api_hal_spi_config_nfc = {
|
||||
const SPI_InitTypeDef furi_hal_spi_config_nfc = {
|
||||
.Mode = SPI_MODE_MASTER,
|
||||
.Direction = SPI_DIRECTION_2LINES,
|
||||
.DataSize = SPI_DATASIZE_8BIT,
|
||||
@@ -20,7 +20,7 @@ const SPI_InitTypeDef api_hal_spi_config_nfc = {
|
||||
.NSSPMode = SPI_NSS_PULSE_DISABLE,
|
||||
};
|
||||
|
||||
const SPI_InitTypeDef api_hal_spi_config_subghz = {
|
||||
const SPI_InitTypeDef furi_hal_spi_config_subghz = {
|
||||
.Mode = SPI_MODE_MASTER,
|
||||
.Direction = SPI_DIRECTION_2LINES,
|
||||
.DataSize = SPI_DATASIZE_8BIT,
|
||||
@@ -36,7 +36,7 @@ const SPI_InitTypeDef api_hal_spi_config_subghz = {
|
||||
.NSSPMode = SPI_NSS_PULSE_DISABLE,
|
||||
};
|
||||
|
||||
const SPI_InitTypeDef api_hal_spi_config_display = {
|
||||
const SPI_InitTypeDef furi_hal_spi_config_display = {
|
||||
.Mode = SPI_MODE_MASTER,
|
||||
.Direction = SPI_DIRECTION_2LINES,
|
||||
.DataSize = SPI_DATASIZE_8BIT,
|
||||
@@ -55,7 +55,7 @@ const SPI_InitTypeDef api_hal_spi_config_display = {
|
||||
/**
|
||||
* SD Card in fast mode (after init)
|
||||
*/
|
||||
const SPI_InitTypeDef api_hal_spi_config_sd_fast = {
|
||||
const SPI_InitTypeDef furi_hal_spi_config_sd_fast = {
|
||||
.Mode = SPI_MODE_MASTER,
|
||||
.Direction = SPI_DIRECTION_2LINES,
|
||||
.DataSize = SPI_DATASIZE_8BIT,
|
||||
@@ -74,7 +74,7 @@ const SPI_InitTypeDef api_hal_spi_config_sd_fast = {
|
||||
/**
|
||||
* SD Card in slow mode (before init)
|
||||
*/
|
||||
const SPI_InitTypeDef api_hal_spi_config_sd_slow = {
|
||||
const SPI_InitTypeDef furi_hal_spi_config_sd_slow = {
|
||||
.Mode = SPI_MODE_MASTER,
|
||||
.Direction = SPI_DIRECTION_2LINES,
|
||||
.DataSize = SPI_DATASIZE_8BIT,
|
||||
@@ -93,7 +93,7 @@ const SPI_InitTypeDef api_hal_spi_config_sd_slow = {
|
||||
osMutexId_t spi_mutex_d = NULL;
|
||||
osMutexId_t spi_mutex_r = NULL;
|
||||
|
||||
const ApiHalSpiBus spi_r = {
|
||||
const FuriHalSpiBus spi_r = {
|
||||
.spi=&SPI_R,
|
||||
.mutex=&spi_mutex_r,
|
||||
.miso=&gpio_spi_r_miso,
|
||||
@@ -101,7 +101,7 @@ const ApiHalSpiBus spi_r = {
|
||||
.clk=&gpio_spi_r_sck,
|
||||
};
|
||||
|
||||
const ApiHalSpiBus spi_d = {
|
||||
const FuriHalSpiBus spi_d = {
|
||||
.spi=&SPI_D,
|
||||
.mutex=&spi_mutex_d,
|
||||
.miso=&gpio_spi_d_miso,
|
||||
@@ -109,10 +109,10 @@ const ApiHalSpiBus spi_d = {
|
||||
.clk=&gpio_spi_d_sck,
|
||||
};
|
||||
|
||||
const ApiHalSpiDevice api_hal_spi_devices[ApiHalSpiDeviceIdMax] = {
|
||||
{ .bus=&spi_r, .config=&api_hal_spi_config_subghz, .chip_select=&gpio_subghz_cs, },
|
||||
{ .bus=&spi_d, .config=&api_hal_spi_config_display, .chip_select=&gpio_display_cs, },
|
||||
{ .bus=&spi_d, .config=&api_hal_spi_config_sd_fast, .chip_select=&gpio_sdcard_cs, },
|
||||
{ .bus=&spi_d, .config=&api_hal_spi_config_sd_slow, .chip_select=&gpio_sdcard_cs, },
|
||||
{ .bus=&spi_r, .config=&api_hal_spi_config_nfc, .chip_select=&gpio_nfc_cs },
|
||||
const FuriHalSpiDevice furi_hal_spi_devices[FuriHalSpiDeviceIdMax] = {
|
||||
{ .bus=&spi_r, .config=&furi_hal_spi_config_subghz, .chip_select=&gpio_subghz_cs, },
|
||||
{ .bus=&spi_d, .config=&furi_hal_spi_config_display, .chip_select=&gpio_display_cs, },
|
||||
{ .bus=&spi_d, .config=&furi_hal_spi_config_sd_fast, .chip_select=&gpio_sdcard_cs, },
|
||||
{ .bus=&spi_d, .config=&furi_hal_spi_config_sd_slow, .chip_select=&gpio_sdcard_cs, },
|
||||
{ .bus=&spi_r, .config=&furi_hal_spi_config_nfc, .chip_select=&gpio_nfc_cs },
|
||||
};
|
67
firmware/targets/f6/furi-hal/furi-hal-spi-config.h
Normal file
67
firmware/targets/f6/furi-hal/furi-hal-spi-config.h
Normal file
@@ -0,0 +1,67 @@
|
||||
#pragma once
|
||||
|
||||
#include <furi-hal-gpio.h>
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern const SPI_InitTypeDef furi_hal_spi_config_nfc;
|
||||
extern const SPI_InitTypeDef furi_hal_spi_config_subghz;
|
||||
extern const SPI_InitTypeDef furi_hal_spi_config_display;
|
||||
extern const SPI_InitTypeDef furi_hal_spi_config_sd_fast;
|
||||
extern const SPI_InitTypeDef furi_hal_spi_config_sd_slow;
|
||||
|
||||
/** FURI HAL SPI BUS handler
|
||||
* Structure content may change at some point
|
||||
*/
|
||||
typedef struct {
|
||||
const SPI_HandleTypeDef* spi;
|
||||
const osMutexId_t* mutex;
|
||||
const GpioPin* miso;
|
||||
const GpioPin* mosi;
|
||||
const GpioPin* clk;
|
||||
} FuriHalSpiBus;
|
||||
|
||||
/** FURI HAL SPI Device handler
|
||||
* Structure content may change at some point
|
||||
*/
|
||||
typedef struct {
|
||||
const FuriHalSpiBus* bus;
|
||||
const SPI_InitTypeDef* config;
|
||||
const GpioPin* chip_select;
|
||||
} FuriHalSpiDevice;
|
||||
|
||||
/** FURI HAL SPI Standard Device IDs */
|
||||
typedef enum {
|
||||
FuriHalSpiDeviceIdSubGhz, /** SubGhz: CC1101, non-standard SPI usage */
|
||||
FuriHalSpiDeviceIdDisplay, /** Display: ERC12864, only have MOSI */
|
||||
FuriHalSpiDeviceIdSdCardFast, /** SDCARD: fast mode, after initialization */
|
||||
FuriHalSpiDeviceIdSdCardSlow, /** SDCARD: slow mode, before initialization */
|
||||
FuriHalSpiDeviceIdNfc, /** NFC: ST25R3916, pretty standard, but RFAL makes it complex */
|
||||
|
||||
FuriHalSpiDeviceIdMax, /** Service Value, do not use */
|
||||
} FuriHalSpiDeviceId;
|
||||
|
||||
/** Furi Hal Spi Bus R
|
||||
* CC1101, Nfc
|
||||
*/
|
||||
extern const FuriHalSpiBus spi_r;
|
||||
|
||||
/** Furi Hal Spi Bus D
|
||||
* Display, SdCard
|
||||
*/
|
||||
extern const FuriHalSpiBus spi_d;
|
||||
|
||||
/** Furi Hal Spi devices */
|
||||
extern const FuriHalSpiDevice furi_hal_spi_devices[FuriHalSpiDeviceIdMax];
|
||||
|
||||
typedef struct {
|
||||
const FuriHalSpiBus* bus;
|
||||
const SPI_InitTypeDef config;
|
||||
} SPIDevice;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@@ -1,5 +1,5 @@
|
||||
#include "api-hal-spi.h"
|
||||
#include <api-hal-resources.h>
|
||||
#include "furi-hal-spi.h"
|
||||
#include <furi-hal-resources.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <spi.h>
|
||||
@@ -8,15 +8,15 @@
|
||||
|
||||
extern void Enable_SPI(SPI_HandleTypeDef* spi);
|
||||
|
||||
void api_hal_spi_init() {
|
||||
void furi_hal_spi_init() {
|
||||
// Spi structure is const, but mutex is not
|
||||
// Need some hell-ish casting to make it work
|
||||
*(osMutexId_t*)spi_r.mutex = osMutexNew(NULL);
|
||||
*(osMutexId_t*)spi_d.mutex = osMutexNew(NULL);
|
||||
//
|
||||
for (size_t i=0; i<ApiHalSpiDeviceIdMax; ++i) {
|
||||
for (size_t i=0; i<FuriHalSpiDeviceIdMax; ++i) {
|
||||
hal_gpio_init(
|
||||
api_hal_spi_devices[i].chip_select,
|
||||
furi_hal_spi_devices[i].chip_select,
|
||||
GpioModeOutputPushPull,
|
||||
GpioPullNo,
|
||||
GpioSpeedVeryHigh
|
||||
@@ -25,21 +25,21 @@ void api_hal_spi_init() {
|
||||
FURI_LOG_I("FuriHalSpi", "Init OK");
|
||||
}
|
||||
|
||||
void api_hal_spi_bus_lock(const ApiHalSpiBus* bus) {
|
||||
void furi_hal_spi_bus_lock(const FuriHalSpiBus* bus) {
|
||||
furi_assert(bus);
|
||||
if (bus->mutex) {
|
||||
osMutexAcquire(*bus->mutex, osWaitForever);
|
||||
}
|
||||
}
|
||||
|
||||
void api_hal_spi_bus_unlock(const ApiHalSpiBus* bus) {
|
||||
void furi_hal_spi_bus_unlock(const FuriHalSpiBus* bus) {
|
||||
furi_assert(bus);
|
||||
if (bus->mutex) {
|
||||
osMutexRelease(*bus->mutex);
|
||||
}
|
||||
}
|
||||
|
||||
void api_hal_spi_bus_configure(const ApiHalSpiBus* bus, const SPI_InitTypeDef* config) {
|
||||
void furi_hal_spi_bus_configure(const FuriHalSpiBus* bus, const SPI_InitTypeDef* config) {
|
||||
furi_assert(bus);
|
||||
|
||||
if(memcmp(&bus->spi->Init, config, sizeof(SPI_InitTypeDef))) {
|
||||
@@ -51,7 +51,7 @@ void api_hal_spi_bus_configure(const ApiHalSpiBus* bus, const SPI_InitTypeDef* c
|
||||
}
|
||||
}
|
||||
|
||||
void api_hal_spi_bus_reset(const ApiHalSpiBus* bus) {
|
||||
void furi_hal_spi_bus_reset(const FuriHalSpiBus* bus) {
|
||||
furi_assert(bus);
|
||||
|
||||
HAL_SPI_DeInit((SPI_HandleTypeDef*)bus->spi);
|
||||
@@ -59,7 +59,7 @@ void api_hal_spi_bus_reset(const ApiHalSpiBus* bus) {
|
||||
Enable_SPI((SPI_HandleTypeDef*)bus->spi);
|
||||
}
|
||||
|
||||
bool api_hal_spi_bus_rx(const ApiHalSpiBus* bus, uint8_t* buffer, size_t size, uint32_t timeout) {
|
||||
bool furi_hal_spi_bus_rx(const FuriHalSpiBus* bus, uint8_t* buffer, size_t size, uint32_t timeout) {
|
||||
furi_assert(bus);
|
||||
furi_assert(buffer);
|
||||
furi_assert(size > 0);
|
||||
@@ -69,7 +69,7 @@ bool api_hal_spi_bus_rx(const ApiHalSpiBus* bus, uint8_t* buffer, size_t size, u
|
||||
return ret == HAL_OK;
|
||||
}
|
||||
|
||||
bool api_hal_spi_bus_tx(const ApiHalSpiBus* bus, uint8_t* buffer, size_t size, uint32_t timeout) {
|
||||
bool furi_hal_spi_bus_tx(const FuriHalSpiBus* bus, uint8_t* buffer, size_t size, uint32_t timeout) {
|
||||
furi_assert(bus);
|
||||
furi_assert(buffer);
|
||||
furi_assert(size > 0);
|
||||
@@ -79,7 +79,7 @@ bool api_hal_spi_bus_tx(const ApiHalSpiBus* bus, uint8_t* buffer, size_t size, u
|
||||
return ret == HAL_OK;
|
||||
}
|
||||
|
||||
bool api_hal_spi_bus_trx(const ApiHalSpiBus* bus, uint8_t* tx_buffer, uint8_t* rx_buffer, size_t size, uint32_t timeout) {
|
||||
bool furi_hal_spi_bus_trx(const FuriHalSpiBus* bus, uint8_t* tx_buffer, uint8_t* rx_buffer, size_t size, uint32_t timeout) {
|
||||
furi_assert(bus);
|
||||
furi_assert(tx_buffer);
|
||||
furi_assert(rx_buffer);
|
||||
@@ -90,12 +90,12 @@ bool api_hal_spi_bus_trx(const ApiHalSpiBus* bus, uint8_t* tx_buffer, uint8_t* r
|
||||
return ret == HAL_OK;
|
||||
}
|
||||
|
||||
const ApiHalSpiDevice* api_hal_spi_device_get(ApiHalSpiDeviceId device_id) {
|
||||
furi_assert(device_id < ApiHalSpiDeviceIdMax);
|
||||
const FuriHalSpiDevice* furi_hal_spi_device_get(FuriHalSpiDeviceId device_id) {
|
||||
furi_assert(device_id < FuriHalSpiDeviceIdMax);
|
||||
|
||||
const ApiHalSpiDevice* device = &api_hal_spi_devices[device_id];
|
||||
const FuriHalSpiDevice* device = &furi_hal_spi_devices[device_id];
|
||||
assert(device);
|
||||
api_hal_spi_bus_lock(device->bus);
|
||||
furi_hal_spi_bus_lock(device->bus);
|
||||
|
||||
if (device->config) {
|
||||
memcpy((SPI_InitTypeDef*)&device->bus->spi->Init, device->config, sizeof(SPI_InitTypeDef));
|
||||
@@ -108,11 +108,11 @@ const ApiHalSpiDevice* api_hal_spi_device_get(ApiHalSpiDeviceId device_id) {
|
||||
return device;
|
||||
}
|
||||
|
||||
void api_hal_spi_device_return(const ApiHalSpiDevice* device) {
|
||||
api_hal_spi_bus_unlock(device->bus);
|
||||
void furi_hal_spi_device_return(const FuriHalSpiDevice* device) {
|
||||
furi_hal_spi_bus_unlock(device->bus);
|
||||
}
|
||||
|
||||
bool api_hal_spi_device_rx(const ApiHalSpiDevice* device, uint8_t* buffer, size_t size, uint32_t timeout) {
|
||||
bool furi_hal_spi_device_rx(const FuriHalSpiDevice* device, uint8_t* buffer, size_t size, uint32_t timeout) {
|
||||
furi_assert(device);
|
||||
furi_assert(buffer);
|
||||
furi_assert(size > 0);
|
||||
@@ -121,7 +121,7 @@ bool api_hal_spi_device_rx(const ApiHalSpiDevice* device, uint8_t* buffer, size_
|
||||
hal_gpio_write(device->chip_select, false);
|
||||
}
|
||||
|
||||
bool ret = api_hal_spi_bus_rx(device->bus, buffer, size, HAL_MAX_DELAY);
|
||||
bool ret = furi_hal_spi_bus_rx(device->bus, buffer, size, HAL_MAX_DELAY);
|
||||
|
||||
if (device->chip_select) {
|
||||
hal_gpio_write(device->chip_select, true);
|
||||
@@ -130,7 +130,7 @@ bool api_hal_spi_device_rx(const ApiHalSpiDevice* device, uint8_t* buffer, size_
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool api_hal_spi_device_tx(const ApiHalSpiDevice* device, uint8_t* buffer, size_t size, uint32_t timeout) {
|
||||
bool furi_hal_spi_device_tx(const FuriHalSpiDevice* device, uint8_t* buffer, size_t size, uint32_t timeout) {
|
||||
furi_assert(device);
|
||||
furi_assert(buffer);
|
||||
furi_assert(size > 0);
|
||||
@@ -139,7 +139,7 @@ bool api_hal_spi_device_tx(const ApiHalSpiDevice* device, uint8_t* buffer, size_
|
||||
hal_gpio_write(device->chip_select, false);
|
||||
}
|
||||
|
||||
bool ret = api_hal_spi_bus_tx(device->bus, buffer, size, HAL_MAX_DELAY);
|
||||
bool ret = furi_hal_spi_bus_tx(device->bus, buffer, size, HAL_MAX_DELAY);
|
||||
|
||||
if (device->chip_select) {
|
||||
hal_gpio_write(device->chip_select, true);
|
||||
@@ -148,7 +148,7 @@ bool api_hal_spi_device_tx(const ApiHalSpiDevice* device, uint8_t* buffer, size_
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool api_hal_spi_device_trx(const ApiHalSpiDevice* device, uint8_t* tx_buffer, uint8_t* rx_buffer, size_t size, uint32_t timeout) {
|
||||
bool furi_hal_spi_device_trx(const FuriHalSpiDevice* device, uint8_t* tx_buffer, uint8_t* rx_buffer, size_t size, uint32_t timeout) {
|
||||
furi_assert(device);
|
||||
furi_assert(tx_buffer);
|
||||
furi_assert(rx_buffer);
|
||||
@@ -158,7 +158,7 @@ bool api_hal_spi_device_trx(const ApiHalSpiDevice* device, uint8_t* tx_buffer, u
|
||||
hal_gpio_write(device->chip_select, false);
|
||||
}
|
||||
|
||||
bool ret = api_hal_spi_bus_trx(device->bus, tx_buffer, rx_buffer, size, HAL_MAX_DELAY);
|
||||
bool ret = furi_hal_spi_bus_trx(device->bus, tx_buffer, rx_buffer, size, HAL_MAX_DELAY);
|
||||
|
||||
if (device->chip_select) {
|
||||
hal_gpio_write(device->chip_select, true);
|
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "main.h"
|
||||
#include "api-hal-spi-config.h"
|
||||
#include <api-hal-gpio.h>
|
||||
#include "furi-hal-spi-config.h"
|
||||
#include <furi-hal-gpio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -11,32 +11,32 @@ extern "C" {
|
||||
/**
|
||||
* Init SPI API
|
||||
*/
|
||||
void api_hal_spi_init();
|
||||
void furi_hal_spi_init();
|
||||
|
||||
/* Bus Level API */
|
||||
|
||||
/** Lock SPI bus
|
||||
* Takes bus mutex, if used
|
||||
*/
|
||||
void api_hal_spi_bus_lock(const ApiHalSpiBus* bus);
|
||||
void furi_hal_spi_bus_lock(const FuriHalSpiBus* bus);
|
||||
|
||||
/** Unlock SPI bus
|
||||
* Releases BUS mutex, if used
|
||||
*/
|
||||
void api_hal_spi_bus_unlock(const ApiHalSpiBus* bus);
|
||||
void furi_hal_spi_bus_unlock(const FuriHalSpiBus* bus);
|
||||
|
||||
/**
|
||||
* Configure SPI bus
|
||||
* @param bus - spi bus handler
|
||||
* @param config - spi configuration structure
|
||||
*/
|
||||
void api_hal_spi_bus_configure(const ApiHalSpiBus* bus, const SPI_InitTypeDef* config);
|
||||
void furi_hal_spi_bus_configure(const FuriHalSpiBus* bus, const SPI_InitTypeDef* config);
|
||||
|
||||
/**
|
||||
* Reset SPI bus
|
||||
* @param bus - spi bus handler
|
||||
*/
|
||||
void api_hal_spi_bus_reset(const ApiHalSpiBus* bus);
|
||||
void furi_hal_spi_bus_reset(const FuriHalSpiBus* bus);
|
||||
|
||||
/** SPI Receive
|
||||
* @param bus - spi bus handler
|
||||
@@ -44,7 +44,7 @@ void api_hal_spi_bus_reset(const ApiHalSpiBus* bus);
|
||||
* @param size - transaction size
|
||||
* @param timeout - bus operation timeout in ms
|
||||
*/
|
||||
bool api_hal_spi_bus_rx(const ApiHalSpiBus* bus, uint8_t* buffer, size_t size, uint32_t timeout);
|
||||
bool furi_hal_spi_bus_rx(const FuriHalSpiBus* bus, uint8_t* buffer, size_t size, uint32_t timeout);
|
||||
|
||||
/** SPI Transmit
|
||||
* @param bus - spi bus handler
|
||||
@@ -52,7 +52,7 @@ bool api_hal_spi_bus_rx(const ApiHalSpiBus* bus, uint8_t* buffer, size_t size, u
|
||||
* @param size - transaction size
|
||||
* @param timeout - bus operation timeout in ms
|
||||
*/
|
||||
bool api_hal_spi_bus_tx(const ApiHalSpiBus* bus, uint8_t* buffer, size_t size, uint32_t timeout);
|
||||
bool furi_hal_spi_bus_tx(const FuriHalSpiBus* bus, uint8_t* buffer, size_t size, uint32_t timeout);
|
||||
|
||||
/** SPI Transmit and Receive
|
||||
* @param bus - spi bus handlere
|
||||
@@ -61,7 +61,7 @@ bool api_hal_spi_bus_tx(const ApiHalSpiBus* bus, uint8_t* buffer, size_t size, u
|
||||
* @param size - transaction size
|
||||
* @param timeout - bus operation timeout in ms
|
||||
*/
|
||||
bool api_hal_spi_bus_trx(const ApiHalSpiBus* bus, uint8_t* tx_buffer, uint8_t* rx_buffer, size_t size, uint32_t timeout);
|
||||
bool furi_hal_spi_bus_trx(const FuriHalSpiBus* bus, uint8_t* tx_buffer, uint8_t* rx_buffer, size_t size, uint32_t timeout);
|
||||
|
||||
/* Device Level API */
|
||||
|
||||
@@ -70,13 +70,13 @@ bool api_hal_spi_bus_trx(const ApiHalSpiBus* bus, uint8_t* tx_buffer, uint8_t* r
|
||||
* @param device_id - device identifier
|
||||
* @return device handle
|
||||
*/
|
||||
const ApiHalSpiDevice* api_hal_spi_device_get(ApiHalSpiDeviceId device_id);
|
||||
const FuriHalSpiDevice* furi_hal_spi_device_get(FuriHalSpiDeviceId device_id);
|
||||
|
||||
/** Return Device handle
|
||||
* And unlock access to the corresponding SPI BUS
|
||||
* @param device - device handle
|
||||
*/
|
||||
void api_hal_spi_device_return(const ApiHalSpiDevice* device);
|
||||
void furi_hal_spi_device_return(const FuriHalSpiDevice* device);
|
||||
|
||||
/** SPI Recieve
|
||||
* @param device - device handle
|
||||
@@ -84,7 +84,7 @@ void api_hal_spi_device_return(const ApiHalSpiDevice* device);
|
||||
* @param size - transaction size
|
||||
* @param timeout - bus operation timeout in ms
|
||||
*/
|
||||
bool api_hal_spi_device_rx(const ApiHalSpiDevice* device, uint8_t* buffer, size_t size, uint32_t timeout);
|
||||
bool furi_hal_spi_device_rx(const FuriHalSpiDevice* device, uint8_t* buffer, size_t size, uint32_t timeout);
|
||||
|
||||
/** SPI Transmit
|
||||
* @param device - device handle
|
||||
@@ -92,7 +92,7 @@ bool api_hal_spi_device_rx(const ApiHalSpiDevice* device, uint8_t* buffer, size_
|
||||
* @param size - transaction size
|
||||
* @param timeout - bus operation timeout in ms
|
||||
*/
|
||||
bool api_hal_spi_device_tx(const ApiHalSpiDevice* device, uint8_t* buffer, size_t size, uint32_t timeout);
|
||||
bool furi_hal_spi_device_tx(const FuriHalSpiDevice* device, uint8_t* buffer, size_t size, uint32_t timeout);
|
||||
|
||||
/** SPI Transmit and Receive
|
||||
* @param device - device handle
|
||||
@@ -101,18 +101,18 @@ bool api_hal_spi_device_tx(const ApiHalSpiDevice* device, uint8_t* buffer, size_
|
||||
* @param size - transaction size
|
||||
* @param timeout - bus operation timeout in ms
|
||||
*/
|
||||
bool api_hal_spi_device_trx(const ApiHalSpiDevice* device, uint8_t* tx_buffer, uint8_t* rx_buffer, size_t size, uint32_t timeout);
|
||||
bool furi_hal_spi_device_trx(const FuriHalSpiDevice* device, uint8_t* tx_buffer, uint8_t* rx_buffer, size_t size, uint32_t timeout);
|
||||
|
||||
|
||||
/**
|
||||
* Lock SPI device bus and apply config if needed
|
||||
*/
|
||||
void api_hal_spi_lock_device(const SPIDevice* device);
|
||||
void furi_hal_spi_lock_device(const SPIDevice* device);
|
||||
|
||||
/**
|
||||
* Unlock SPI device bus
|
||||
*/
|
||||
void api_hal_spi_unlock_device(const SPIDevice* device);
|
||||
void furi_hal_spi_unlock_device(const SPIDevice* device);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
@@ -1,17 +1,17 @@
|
||||
#include "api-hal-subghz.h"
|
||||
#include "furi-hal-subghz.h"
|
||||
|
||||
#include <api-hal-gpio.h>
|
||||
#include <api-hal-spi.h>
|
||||
#include <api-hal-interrupt.h>
|
||||
#include <api-hal-resources.h>
|
||||
#include <furi-hal-gpio.h>
|
||||
#include <furi-hal-spi.h>
|
||||
#include <furi-hal-interrupt.h>
|
||||
#include <furi-hal-resources.h>
|
||||
|
||||
#include <furi.h>
|
||||
#include <cc1101.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static volatile SubGhzState api_hal_subghz_state = SubGhzStateInit;
|
||||
static volatile SubGhzState furi_hal_subghz_state = SubGhzStateInit;
|
||||
|
||||
static const uint8_t api_hal_subghz_preset_ook_async_regs[][2] = {
|
||||
static const uint8_t furi_hal_subghz_preset_ook_async_regs[][2] = {
|
||||
// https://e2e.ti.com/support/wireless-connectivity/sub-1-ghz-group/sub-1-ghz/f/sub-1-ghz-forum/382066/cc1101---don-t-know-the-correct-registers-configuration
|
||||
|
||||
/* GPIO GD0 */
|
||||
@@ -65,7 +65,7 @@ static const uint8_t api_hal_subghz_preset_ook_async_regs[][2] = {
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
static const uint8_t api_hal_subghz_preset_ook_async_patable[8] = {
|
||||
static const uint8_t furi_hal_subghz_preset_ook_async_patable[8] = {
|
||||
0x00,
|
||||
0xC0, // 10dBm 0xC0, 7dBm 0xC8, 5dBm 0x84, 0dBm 0x60, -10dBm 0x34, -15dBm 0x1D, -20dBm 0x0E, -30dBm 0x12
|
||||
0x00,
|
||||
@@ -76,14 +76,14 @@ static const uint8_t api_hal_subghz_preset_ook_async_patable[8] = {
|
||||
0x00
|
||||
};
|
||||
|
||||
void api_hal_subghz_init() {
|
||||
furi_assert(api_hal_subghz_state == SubGhzStateInit);
|
||||
api_hal_subghz_state = SubGhzStateIdle;
|
||||
void furi_hal_subghz_init() {
|
||||
furi_assert(furi_hal_subghz_state == SubGhzStateInit);
|
||||
furi_hal_subghz_state = SubGhzStateIdle;
|
||||
|
||||
const ApiHalSpiDevice* device = api_hal_spi_device_get(ApiHalSpiDeviceIdSubGhz);
|
||||
const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
|
||||
|
||||
#ifdef API_HAL_SUBGHZ_TX_GPIO
|
||||
hal_gpio_init(&API_HAL_SUBGHZ_TX_GPIO, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
#ifdef FURI_HAL_SUBGHZ_TX_GPIO
|
||||
hal_gpio_init(&FURI_HAL_SUBGHZ_TX_GPIO, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
#endif
|
||||
|
||||
// Reset
|
||||
@@ -113,13 +113,13 @@ void api_hal_subghz_init() {
|
||||
// Go to sleep
|
||||
cc1101_shutdown(device);
|
||||
|
||||
api_hal_spi_device_return(device);
|
||||
furi_hal_spi_device_return(device);
|
||||
FURI_LOG_I("FuriHalSubGhz", "Init OK");
|
||||
}
|
||||
|
||||
void api_hal_subghz_sleep() {
|
||||
furi_assert(api_hal_subghz_state == SubGhzStateIdle);
|
||||
const ApiHalSpiDevice* device = api_hal_spi_device_get(ApiHalSpiDeviceIdSubGhz);
|
||||
void furi_hal_subghz_sleep() {
|
||||
furi_assert(furi_hal_subghz_state == SubGhzStateIdle);
|
||||
const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
|
||||
|
||||
cc1101_switch_to_idle(device);
|
||||
|
||||
@@ -128,110 +128,110 @@ void api_hal_subghz_sleep() {
|
||||
|
||||
cc1101_shutdown(device);
|
||||
|
||||
api_hal_spi_device_return(device);
|
||||
furi_hal_spi_device_return(device);
|
||||
}
|
||||
|
||||
void api_hal_subghz_dump_state() {
|
||||
const ApiHalSpiDevice* device = api_hal_spi_device_get(ApiHalSpiDeviceIdSubGhz);
|
||||
void furi_hal_subghz_dump_state() {
|
||||
const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
|
||||
printf(
|
||||
"[api_hal_subghz] cc1101 chip %d, version %d\r\n",
|
||||
"[furi_hal_subghz] cc1101 chip %d, version %d\r\n",
|
||||
cc1101_get_partnumber(device),
|
||||
cc1101_get_version(device)
|
||||
);
|
||||
api_hal_spi_device_return(device);
|
||||
furi_hal_spi_device_return(device);
|
||||
}
|
||||
|
||||
void api_hal_subghz_load_preset(ApiHalSubGhzPreset preset) {
|
||||
if(preset == ApiHalSubGhzPresetOokAsync) {
|
||||
api_hal_subghz_load_registers(api_hal_subghz_preset_ook_async_regs);
|
||||
api_hal_subghz_load_patable(api_hal_subghz_preset_ook_async_patable);
|
||||
void furi_hal_subghz_load_preset(FuriHalSubGhzPreset preset) {
|
||||
if(preset == FuriHalSubGhzPresetOokAsync) {
|
||||
furi_hal_subghz_load_registers(furi_hal_subghz_preset_ook_async_regs);
|
||||
furi_hal_subghz_load_patable(furi_hal_subghz_preset_ook_async_patable);
|
||||
} else {
|
||||
furi_check(0);
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t api_hal_subghz_get_status() {
|
||||
const ApiHalSpiDevice* device = api_hal_spi_device_get(ApiHalSpiDeviceIdSubGhz);
|
||||
uint8_t furi_hal_subghz_get_status() {
|
||||
const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
|
||||
CC1101StatusRaw st;
|
||||
st.status = cc1101_get_status(device);
|
||||
api_hal_spi_device_return(device);
|
||||
furi_hal_spi_device_return(device);
|
||||
return st.status_raw;
|
||||
}
|
||||
|
||||
void api_hal_subghz_load_registers(const uint8_t data[][2]) {
|
||||
const ApiHalSpiDevice* device = api_hal_spi_device_get(ApiHalSpiDeviceIdSubGhz);
|
||||
void furi_hal_subghz_load_registers(const uint8_t data[][2]) {
|
||||
const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
|
||||
cc1101_reset(device);
|
||||
uint32_t i = 0;
|
||||
while (data[i][0]) {
|
||||
cc1101_write_reg(device, data[i][0], data[i][1]);
|
||||
i++;
|
||||
}
|
||||
api_hal_spi_device_return(device);
|
||||
furi_hal_spi_device_return(device);
|
||||
}
|
||||
|
||||
void api_hal_subghz_load_patable(const uint8_t data[8]) {
|
||||
const ApiHalSpiDevice* device = api_hal_spi_device_get(ApiHalSpiDeviceIdSubGhz);
|
||||
void furi_hal_subghz_load_patable(const uint8_t data[8]) {
|
||||
const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
|
||||
cc1101_set_pa_table(device, data);
|
||||
api_hal_spi_device_return(device);
|
||||
furi_hal_spi_device_return(device);
|
||||
}
|
||||
|
||||
void api_hal_subghz_write_packet(const uint8_t* data, uint8_t size) {
|
||||
const ApiHalSpiDevice* device = api_hal_spi_device_get(ApiHalSpiDeviceIdSubGhz);
|
||||
void furi_hal_subghz_write_packet(const uint8_t* data, uint8_t size) {
|
||||
const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
|
||||
cc1101_flush_tx(device);
|
||||
cc1101_write_fifo(device, data, size);
|
||||
api_hal_spi_device_return(device);
|
||||
furi_hal_spi_device_return(device);
|
||||
}
|
||||
|
||||
void api_hal_subghz_flush_rx() {
|
||||
const ApiHalSpiDevice* device = api_hal_spi_device_get(ApiHalSpiDeviceIdSubGhz);
|
||||
void furi_hal_subghz_flush_rx() {
|
||||
const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
|
||||
cc1101_flush_rx(device);
|
||||
api_hal_spi_device_return(device);
|
||||
furi_hal_spi_device_return(device);
|
||||
}
|
||||
|
||||
void api_hal_subghz_read_packet(uint8_t* data, uint8_t* size) {
|
||||
const ApiHalSpiDevice* device = api_hal_spi_device_get(ApiHalSpiDeviceIdSubGhz);
|
||||
void furi_hal_subghz_read_packet(uint8_t* data, uint8_t* size) {
|
||||
const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
|
||||
cc1101_read_fifo(device, data, size);
|
||||
api_hal_spi_device_return(device);
|
||||
furi_hal_spi_device_return(device);
|
||||
}
|
||||
|
||||
void api_hal_subghz_shutdown() {
|
||||
const ApiHalSpiDevice* device = api_hal_spi_device_get(ApiHalSpiDeviceIdSubGhz);
|
||||
void furi_hal_subghz_shutdown() {
|
||||
const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
|
||||
// Reset and shutdown
|
||||
cc1101_shutdown(device);
|
||||
api_hal_spi_device_return(device);
|
||||
furi_hal_spi_device_return(device);
|
||||
}
|
||||
|
||||
void api_hal_subghz_reset() {
|
||||
const ApiHalSpiDevice* device = api_hal_spi_device_get(ApiHalSpiDeviceIdSubGhz);
|
||||
void furi_hal_subghz_reset() {
|
||||
const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
|
||||
hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
cc1101_switch_to_idle(device);
|
||||
cc1101_reset(device);
|
||||
cc1101_write_reg(device, CC1101_IOCFG0, CC1101IocfgHighImpedance);
|
||||
api_hal_spi_device_return(device);
|
||||
furi_hal_spi_device_return(device);
|
||||
}
|
||||
|
||||
void api_hal_subghz_idle() {
|
||||
const ApiHalSpiDevice* device = api_hal_spi_device_get(ApiHalSpiDeviceIdSubGhz);
|
||||
void furi_hal_subghz_idle() {
|
||||
const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
|
||||
cc1101_switch_to_idle(device);
|
||||
api_hal_spi_device_return(device);
|
||||
furi_hal_spi_device_return(device);
|
||||
}
|
||||
|
||||
void api_hal_subghz_rx() {
|
||||
const ApiHalSpiDevice* device = api_hal_spi_device_get(ApiHalSpiDeviceIdSubGhz);
|
||||
void furi_hal_subghz_rx() {
|
||||
const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
|
||||
cc1101_switch_to_rx(device);
|
||||
api_hal_spi_device_return(device);
|
||||
furi_hal_spi_device_return(device);
|
||||
}
|
||||
|
||||
void api_hal_subghz_tx() {
|
||||
const ApiHalSpiDevice* device = api_hal_spi_device_get(ApiHalSpiDeviceIdSubGhz);
|
||||
void furi_hal_subghz_tx() {
|
||||
const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
|
||||
cc1101_switch_to_tx(device);
|
||||
api_hal_spi_device_return(device);
|
||||
furi_hal_spi_device_return(device);
|
||||
}
|
||||
|
||||
float api_hal_subghz_get_rssi() {
|
||||
const ApiHalSpiDevice* device = api_hal_spi_device_get(ApiHalSpiDeviceIdSubGhz);
|
||||
float furi_hal_subghz_get_rssi() {
|
||||
const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
|
||||
int32_t rssi_dec = cc1101_get_rssi(device);
|
||||
api_hal_spi_device_return(device);
|
||||
furi_hal_spi_device_return(device);
|
||||
|
||||
float rssi = rssi_dec;
|
||||
if(rssi_dec >= 128) {
|
||||
@@ -243,7 +243,7 @@ float api_hal_subghz_get_rssi() {
|
||||
return rssi;
|
||||
}
|
||||
|
||||
bool api_hal_subghz_is_frequency_valid(uint32_t value) {
|
||||
bool furi_hal_subghz_is_frequency_valid(uint32_t value) {
|
||||
if(!(value >= 299999755 && value <= 348000335) &&
|
||||
!(value >= 386999938 && value <= 464000000) &&
|
||||
!(value >= 778999847 && value <= 928000000)) {
|
||||
@@ -252,85 +252,85 @@ bool api_hal_subghz_is_frequency_valid(uint32_t value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
uint32_t api_hal_subghz_set_frequency_and_path(uint32_t value) {
|
||||
value = api_hal_subghz_set_frequency(value);
|
||||
uint32_t furi_hal_subghz_set_frequency_and_path(uint32_t value) {
|
||||
value = furi_hal_subghz_set_frequency(value);
|
||||
if(value >= 299999755 && value <= 348000335) {
|
||||
api_hal_subghz_set_path(ApiHalSubGhzPath315);
|
||||
furi_hal_subghz_set_path(FuriHalSubGhzPath315);
|
||||
} else if(value >= 386999938 && value <= 464000000) {
|
||||
api_hal_subghz_set_path(ApiHalSubGhzPath433);
|
||||
furi_hal_subghz_set_path(FuriHalSubGhzPath433);
|
||||
} else if(value >= 778999847 && value <= 928000000) {
|
||||
api_hal_subghz_set_path(ApiHalSubGhzPath868);
|
||||
furi_hal_subghz_set_path(FuriHalSubGhzPath868);
|
||||
} else {
|
||||
furi_check(0);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
uint32_t api_hal_subghz_set_frequency(uint32_t value) {
|
||||
const ApiHalSpiDevice* device = api_hal_spi_device_get(ApiHalSpiDeviceIdSubGhz);
|
||||
uint32_t furi_hal_subghz_set_frequency(uint32_t value) {
|
||||
const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
|
||||
|
||||
uint32_t real_frequency = cc1101_set_frequency(device, value);
|
||||
cc1101_calibrate(device);
|
||||
|
||||
api_hal_spi_device_return(device);
|
||||
furi_hal_spi_device_return(device);
|
||||
|
||||
return real_frequency;
|
||||
}
|
||||
|
||||
void api_hal_subghz_set_path(ApiHalSubGhzPath path) {
|
||||
const ApiHalSpiDevice* device = api_hal_spi_device_get(ApiHalSpiDeviceIdSubGhz);
|
||||
if (path == ApiHalSubGhzPath433) {
|
||||
void furi_hal_subghz_set_path(FuriHalSubGhzPath path) {
|
||||
const FuriHalSpiDevice* device = furi_hal_spi_device_get(FuriHalSpiDeviceIdSubGhz);
|
||||
if (path == FuriHalSubGhzPath433) {
|
||||
hal_gpio_write(&gpio_rf_sw_0, 0);
|
||||
cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW | CC1101_IOCFG_INV);
|
||||
} else if (path == ApiHalSubGhzPath315) {
|
||||
} else if (path == FuriHalSubGhzPath315) {
|
||||
hal_gpio_write(&gpio_rf_sw_0, 1);
|
||||
cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW);
|
||||
} else if (path == ApiHalSubGhzPath868) {
|
||||
} else if (path == FuriHalSubGhzPath868) {
|
||||
hal_gpio_write(&gpio_rf_sw_0, 1);
|
||||
cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW | CC1101_IOCFG_INV);
|
||||
} else if (path == ApiHalSubGhzPathIsolate) {
|
||||
} else if (path == FuriHalSubGhzPathIsolate) {
|
||||
hal_gpio_write(&gpio_rf_sw_0, 0);
|
||||
cc1101_write_reg(device, CC1101_IOCFG2, CC1101IocfgHW);
|
||||
} else {
|
||||
furi_check(0);
|
||||
}
|
||||
api_hal_spi_device_return(device);
|
||||
furi_hal_spi_device_return(device);
|
||||
}
|
||||
|
||||
volatile uint32_t api_hal_subghz_capture_delta_duration = 0;
|
||||
volatile ApiHalSubGhzCaptureCallback api_hal_subghz_capture_callback = NULL;
|
||||
volatile void* api_hal_subghz_capture_callback_context = NULL;
|
||||
volatile uint32_t furi_hal_subghz_capture_delta_duration = 0;
|
||||
volatile FuriHalSubGhzCaptureCallback furi_hal_subghz_capture_callback = NULL;
|
||||
volatile void* furi_hal_subghz_capture_callback_context = NULL;
|
||||
|
||||
static void api_hal_subghz_capture_ISR() {
|
||||
static void furi_hal_subghz_capture_ISR() {
|
||||
// Channel 1
|
||||
if(LL_TIM_IsActiveFlag_CC1(TIM2)) {
|
||||
LL_TIM_ClearFlag_CC1(TIM2);
|
||||
api_hal_subghz_capture_delta_duration = LL_TIM_IC_GetCaptureCH1(TIM2);
|
||||
if (api_hal_subghz_capture_callback) {
|
||||
api_hal_subghz_capture_callback(true, api_hal_subghz_capture_delta_duration,
|
||||
(void*)api_hal_subghz_capture_callback_context
|
||||
furi_hal_subghz_capture_delta_duration = LL_TIM_IC_GetCaptureCH1(TIM2);
|
||||
if (furi_hal_subghz_capture_callback) {
|
||||
furi_hal_subghz_capture_callback(true, furi_hal_subghz_capture_delta_duration,
|
||||
(void*)furi_hal_subghz_capture_callback_context
|
||||
);
|
||||
}
|
||||
}
|
||||
// Channel 2
|
||||
if(LL_TIM_IsActiveFlag_CC2(TIM2)) {
|
||||
LL_TIM_ClearFlag_CC2(TIM2);
|
||||
if (api_hal_subghz_capture_callback) {
|
||||
api_hal_subghz_capture_callback(false, LL_TIM_IC_GetCaptureCH2(TIM2) - api_hal_subghz_capture_delta_duration,
|
||||
(void*)api_hal_subghz_capture_callback_context
|
||||
if (furi_hal_subghz_capture_callback) {
|
||||
furi_hal_subghz_capture_callback(false, LL_TIM_IC_GetCaptureCH2(TIM2) - furi_hal_subghz_capture_delta_duration,
|
||||
(void*)furi_hal_subghz_capture_callback_context
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void api_hal_subghz_set_async_rx_callback(ApiHalSubGhzCaptureCallback callback, void* context) {
|
||||
api_hal_subghz_capture_callback = callback;
|
||||
api_hal_subghz_capture_callback_context = context;
|
||||
void furi_hal_subghz_set_async_rx_callback(FuriHalSubGhzCaptureCallback callback, void* context) {
|
||||
furi_hal_subghz_capture_callback = callback;
|
||||
furi_hal_subghz_capture_callback_context = context;
|
||||
}
|
||||
|
||||
void api_hal_subghz_start_async_rx() {
|
||||
furi_assert(api_hal_subghz_state == SubGhzStateIdle);
|
||||
api_hal_subghz_state = SubGhzStateAsyncRx;
|
||||
void furi_hal_subghz_start_async_rx() {
|
||||
furi_assert(furi_hal_subghz_state == SubGhzStateIdle);
|
||||
furi_hal_subghz_state = SubGhzStateAsyncRx;
|
||||
|
||||
hal_gpio_init_ex(&gpio_cc1101_g0, GpioModeAltFunctionPushPull, GpioPullNo, GpioSpeedLow, GpioAltFn1TIM2);
|
||||
|
||||
@@ -366,7 +366,7 @@ void api_hal_subghz_start_async_rx() {
|
||||
LL_TIM_IC_SetFilter(TIM2, LL_TIM_CHANNEL_CH2, LL_TIM_IC_FILTER_FDIV1);
|
||||
|
||||
// ISR setup
|
||||
api_hal_interrupt_set_timer_isr(TIM2, api_hal_subghz_capture_ISR);
|
||||
furi_hal_interrupt_set_timer_isr(TIM2, furi_hal_subghz_capture_ISR);
|
||||
NVIC_SetPriority(TIM2_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),5, 0));
|
||||
NVIC_EnableIRQ(TIM2_IRQn);
|
||||
|
||||
@@ -385,50 +385,50 @@ void api_hal_subghz_start_async_rx() {
|
||||
LL_TIM_EnableCounter(TIM2);
|
||||
|
||||
// Switch to RX
|
||||
api_hal_subghz_rx();
|
||||
furi_hal_subghz_rx();
|
||||
}
|
||||
|
||||
void api_hal_subghz_stop_async_rx() {
|
||||
furi_assert(api_hal_subghz_state == SubGhzStateAsyncRx);
|
||||
api_hal_subghz_state = SubGhzStateIdle;
|
||||
void furi_hal_subghz_stop_async_rx() {
|
||||
furi_assert(furi_hal_subghz_state == SubGhzStateAsyncRx);
|
||||
furi_hal_subghz_state = SubGhzStateIdle;
|
||||
|
||||
// Shutdown radio
|
||||
api_hal_subghz_idle();
|
||||
furi_hal_subghz_idle();
|
||||
|
||||
LL_TIM_DeInit(TIM2);
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_TIM2);
|
||||
api_hal_interrupt_set_timer_isr(TIM2, NULL);
|
||||
furi_hal_interrupt_set_timer_isr(TIM2, NULL);
|
||||
|
||||
hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
}
|
||||
|
||||
volatile size_t api_hal_subghz_tx_repeat = 0;
|
||||
volatile size_t furi_hal_subghz_tx_repeat = 0;
|
||||
|
||||
static void api_hal_subghz_tx_dma_isr() {
|
||||
static void furi_hal_subghz_tx_dma_isr() {
|
||||
if (LL_DMA_IsActiveFlag_TC1(DMA1)) {
|
||||
LL_DMA_ClearFlag_TC1(DMA1);
|
||||
furi_assert(api_hal_subghz_state == SubGhzStateAsyncTx);
|
||||
if (--api_hal_subghz_tx_repeat == 0) {
|
||||
api_hal_subghz_state = SubGhzStateAsyncTxLast;
|
||||
furi_assert(furi_hal_subghz_state == SubGhzStateAsyncTx);
|
||||
if (--furi_hal_subghz_tx_repeat == 0) {
|
||||
furi_hal_subghz_state = SubGhzStateAsyncTxLast;
|
||||
LL_DMA_DisableChannel(DMA1, LL_DMA_CHANNEL_1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void api_hal_subghz_tx_timer_isr() {
|
||||
static void furi_hal_subghz_tx_timer_isr() {
|
||||
if(LL_TIM_IsActiveFlag_UPDATE(TIM2)) {
|
||||
LL_TIM_ClearFlag_UPDATE(TIM2);
|
||||
if (api_hal_subghz_state == SubGhzStateAsyncTxLast) {
|
||||
if (furi_hal_subghz_state == SubGhzStateAsyncTxLast) {
|
||||
LL_TIM_DisableCounter(TIM2);
|
||||
api_hal_subghz_state = SubGhzStateAsyncTxEnd;
|
||||
furi_hal_subghz_state = SubGhzStateAsyncTxEnd;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void api_hal_subghz_start_async_tx(uint32_t* buffer, size_t buffer_size, size_t repeat) {
|
||||
furi_assert(api_hal_subghz_state == SubGhzStateIdle);
|
||||
api_hal_subghz_state = SubGhzStateAsyncTx;
|
||||
api_hal_subghz_tx_repeat = repeat;
|
||||
void furi_hal_subghz_start_async_tx(uint32_t* buffer, size_t buffer_size, size_t repeat) {
|
||||
furi_assert(furi_hal_subghz_state == SubGhzStateIdle);
|
||||
furi_hal_subghz_state = SubGhzStateAsyncTx;
|
||||
furi_hal_subghz_tx_repeat = repeat;
|
||||
|
||||
// Connect CC1101_GD0 to TIM2 as output
|
||||
hal_gpio_init_ex(&gpio_cc1101_g0, GpioModeAltFunctionPushPull, GpioPullDown, GpioSpeedLow, GpioAltFn1TIM2);
|
||||
@@ -447,7 +447,7 @@ void api_hal_subghz_start_async_tx(uint32_t* buffer, size_t buffer_size, size_t
|
||||
dma_config.PeriphRequest = LL_DMAMUX_REQ_TIM2_UP;
|
||||
dma_config.Priority = LL_DMA_MODE_NORMAL;
|
||||
LL_DMA_Init(DMA1, LL_DMA_CHANNEL_1, &dma_config);
|
||||
api_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_1, api_hal_subghz_tx_dma_isr);
|
||||
furi_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_1, furi_hal_subghz_tx_dma_isr);
|
||||
LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_1);
|
||||
LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1);
|
||||
|
||||
@@ -473,17 +473,17 @@ void api_hal_subghz_start_async_tx(uint32_t* buffer, size_t buffer_size, size_t
|
||||
LL_TIM_OC_DisableFast(TIM2, LL_TIM_CHANNEL_CH2);
|
||||
LL_TIM_DisableMasterSlaveMode(TIM2);
|
||||
|
||||
api_hal_interrupt_set_timer_isr(TIM2, api_hal_subghz_tx_timer_isr);
|
||||
furi_hal_interrupt_set_timer_isr(TIM2, furi_hal_subghz_tx_timer_isr);
|
||||
LL_TIM_EnableIT_UPDATE(TIM2);
|
||||
LL_TIM_EnableDMAReq_UPDATE(TIM2);
|
||||
LL_TIM_CC_EnableChannel(TIM2, LL_TIM_CHANNEL_CH2);
|
||||
|
||||
// Start counter
|
||||
LL_TIM_GenerateEvent_UPDATE(TIM2);
|
||||
#ifdef API_HAL_SUBGHZ_TX_GPIO
|
||||
hal_gpio_write(&API_HAL_SUBGHZ_TX_GPIO, true);
|
||||
#ifdef FURI_HAL_SUBGHZ_TX_GPIO
|
||||
hal_gpio_write(&FURI_HAL_SUBGHZ_TX_GPIO, true);
|
||||
#endif
|
||||
api_hal_subghz_tx();
|
||||
furi_hal_subghz_tx();
|
||||
|
||||
// Enable NVIC
|
||||
NVIC_SetPriority(TIM2_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),5, 0));
|
||||
@@ -493,38 +493,38 @@ void api_hal_subghz_start_async_tx(uint32_t* buffer, size_t buffer_size, size_t
|
||||
LL_TIM_EnableCounter(TIM2);
|
||||
}
|
||||
|
||||
size_t api_hal_subghz_get_async_tx_repeat_left() {
|
||||
return api_hal_subghz_tx_repeat;
|
||||
size_t furi_hal_subghz_get_async_tx_repeat_left() {
|
||||
return furi_hal_subghz_tx_repeat;
|
||||
}
|
||||
|
||||
void api_hal_subghz_wait_async_tx() {
|
||||
while(api_hal_subghz_state != SubGhzStateAsyncTxEnd) osDelay(1);
|
||||
void furi_hal_subghz_wait_async_tx() {
|
||||
while(furi_hal_subghz_state != SubGhzStateAsyncTxEnd) osDelay(1);
|
||||
}
|
||||
|
||||
void api_hal_subghz_stop_async_tx() {
|
||||
void furi_hal_subghz_stop_async_tx() {
|
||||
furi_assert(
|
||||
api_hal_subghz_state == SubGhzStateAsyncTx
|
||||
|| api_hal_subghz_state == SubGhzStateAsyncTxLast
|
||||
|| api_hal_subghz_state == SubGhzStateAsyncTxEnd
|
||||
furi_hal_subghz_state == SubGhzStateAsyncTx
|
||||
|| furi_hal_subghz_state == SubGhzStateAsyncTxLast
|
||||
|| furi_hal_subghz_state == SubGhzStateAsyncTxEnd
|
||||
);
|
||||
|
||||
// Shutdown radio
|
||||
api_hal_subghz_idle();
|
||||
#ifdef API_HAL_SUBGHZ_TX_GPIO
|
||||
hal_gpio_write(&API_HAL_SUBGHZ_TX_GPIO, false);
|
||||
furi_hal_subghz_idle();
|
||||
#ifdef FURI_HAL_SUBGHZ_TX_GPIO
|
||||
hal_gpio_write(&FURI_HAL_SUBGHZ_TX_GPIO, false);
|
||||
#endif
|
||||
|
||||
// Deinitialize Timer
|
||||
LL_TIM_DeInit(TIM2);
|
||||
LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_TIM2);
|
||||
api_hal_interrupt_set_timer_isr(TIM2, NULL);
|
||||
furi_hal_interrupt_set_timer_isr(TIM2, NULL);
|
||||
|
||||
// Deinitialize DMA
|
||||
LL_DMA_DeInit(DMA1, LL_DMA_CHANNEL_1);
|
||||
api_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_1, NULL);
|
||||
furi_hal_interrupt_set_dma_channel_isr(DMA1, LL_DMA_CHANNEL_1, NULL);
|
||||
|
||||
// Deinitialize GPIO
|
||||
hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
api_hal_subghz_state = SubGhzStateIdle;
|
||||
furi_hal_subghz_state = SubGhzStateIdle;
|
||||
}
|
@@ -1,5 +1,5 @@
|
||||
#include "cmsis_os.h"
|
||||
#include "api-hal-task.h"
|
||||
#include "furi-hal-task.h"
|
||||
|
||||
//-----------------------------cmsis_os2.c-------------------------------
|
||||
// helpers to get isr context
|
106
firmware/targets/f6/furi-hal/furi-hal-vcp.c
Normal file
106
firmware/targets/f6/furi-hal/furi-hal-vcp.c
Normal file
@@ -0,0 +1,106 @@
|
||||
#include <furi-hal-vcp.h>
|
||||
#include <usbd_cdc_if.h>
|
||||
#include <furi.h>
|
||||
#include <stream_buffer.h>
|
||||
|
||||
#define FURI_HAL_VCP_RX_BUFFER_SIZE 600
|
||||
|
||||
typedef struct {
|
||||
StreamBufferHandle_t rx_stream;
|
||||
osSemaphoreId_t tx_semaphore;
|
||||
volatile bool alive;
|
||||
volatile bool underrun;
|
||||
} FuriHalVcp;
|
||||
|
||||
static FuriHalVcp* furi_hal_vcp = NULL;
|
||||
|
||||
static const uint8_t ascii_soh = 0x01;
|
||||
static const uint8_t ascii_eot = 0x04;
|
||||
|
||||
void _furi_hal_vcp_init();
|
||||
void _furi_hal_vcp_deinit();
|
||||
void _furi_hal_vcp_control_line(uint8_t state);
|
||||
void _furi_hal_vcp_rx_callback(const uint8_t* buffer, size_t size);
|
||||
void _furi_hal_vcp_tx_complete(size_t size);
|
||||
|
||||
void furi_hal_vcp_init() {
|
||||
furi_hal_vcp = furi_alloc(sizeof(FuriHalVcp));
|
||||
furi_hal_vcp->rx_stream = xStreamBufferCreate(FURI_HAL_VCP_RX_BUFFER_SIZE, 1);
|
||||
furi_hal_vcp->tx_semaphore = osSemaphoreNew(1, 1, NULL);
|
||||
furi_hal_vcp->alive = false;
|
||||
furi_hal_vcp->underrun = false;
|
||||
FURI_LOG_I("FuriHalVcp", "Init OK");
|
||||
}
|
||||
|
||||
void _furi_hal_vcp_init() {
|
||||
osSemaphoreRelease(furi_hal_vcp->tx_semaphore);
|
||||
}
|
||||
|
||||
void _furi_hal_vcp_deinit() {
|
||||
furi_hal_vcp->alive = false;
|
||||
osSemaphoreRelease(furi_hal_vcp->tx_semaphore);
|
||||
}
|
||||
|
||||
void _furi_hal_vcp_control_line(uint8_t state) {
|
||||
// bit 0: DTR state, bit 1: RTS state
|
||||
// bool dtr = state & 0b01;
|
||||
bool dtr = state & 0b1;
|
||||
|
||||
if (dtr) {
|
||||
if (!furi_hal_vcp->alive) {
|
||||
furi_hal_vcp->alive = true;
|
||||
_furi_hal_vcp_rx_callback(&ascii_soh, 1); // SOH
|
||||
}
|
||||
} else {
|
||||
if (furi_hal_vcp->alive) {
|
||||
_furi_hal_vcp_rx_callback(&ascii_eot, 1); // EOT
|
||||
furi_hal_vcp->alive = false;
|
||||
}
|
||||
}
|
||||
|
||||
osSemaphoreRelease(furi_hal_vcp->tx_semaphore);
|
||||
}
|
||||
|
||||
void _furi_hal_vcp_rx_callback(const uint8_t* buffer, size_t size) {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
size_t ret = xStreamBufferSendFromISR(furi_hal_vcp->rx_stream, buffer, size, &xHigherPriorityTaskWoken);
|
||||
if (ret != size) {
|
||||
furi_hal_vcp->underrun = true;
|
||||
}
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
void _furi_hal_vcp_tx_complete(size_t size) {
|
||||
osSemaphoreRelease(furi_hal_vcp->tx_semaphore);
|
||||
}
|
||||
|
||||
size_t furi_hal_vcp_rx(uint8_t* buffer, size_t size) {
|
||||
furi_assert(furi_hal_vcp);
|
||||
return xStreamBufferReceive(furi_hal_vcp->rx_stream, buffer, size, portMAX_DELAY);
|
||||
}
|
||||
|
||||
size_t furi_hal_vcp_rx_with_timeout(uint8_t* buffer, size_t size, uint32_t timeout) {
|
||||
furi_assert(furi_hal_vcp);
|
||||
return xStreamBufferReceive(furi_hal_vcp->rx_stream, buffer, size, timeout);
|
||||
}
|
||||
|
||||
void furi_hal_vcp_tx(const uint8_t* buffer, size_t size) {
|
||||
furi_assert(furi_hal_vcp);
|
||||
|
||||
while (size > 0 && furi_hal_vcp->alive) {
|
||||
furi_check(osSemaphoreAcquire(furi_hal_vcp->tx_semaphore, osWaitForever) == osOK);
|
||||
|
||||
size_t batch_size = size;
|
||||
if (batch_size > APP_TX_DATA_SIZE) {
|
||||
batch_size = APP_TX_DATA_SIZE;
|
||||
}
|
||||
|
||||
if (CDC_Transmit_FS((uint8_t*)buffer, batch_size) == USBD_OK) {
|
||||
size -= batch_size;
|
||||
buffer += batch_size;
|
||||
} else {
|
||||
// Shouldn't be there
|
||||
osDelay(100);
|
||||
}
|
||||
}
|
||||
}
|
242
firmware/targets/f6/furi-hal/furi-hal-version.c
Normal file
242
firmware/targets/f6/furi-hal/furi-hal-version.c
Normal file
@@ -0,0 +1,242 @@
|
||||
#include <furi-hal-version.h>
|
||||
|
||||
#include <furi.h>
|
||||
#include <stm32wbxx.h>
|
||||
#include <stm32wbxx_ll_rtc.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include "ble.h"
|
||||
|
||||
#define FURI_HAL_VERSION_OTP_HEADER_MAGIC 0xBABE
|
||||
#define FURI_HAL_VERSION_NAME_LENGTH 8
|
||||
#define FURI_HAL_VERSION_ARRAY_NAME_LENGTH (FURI_HAL_VERSION_NAME_LENGTH + 1)
|
||||
/** BLE symbol + "Flipper " + name */
|
||||
#define FURI_HAL_VERSION_DEVICE_NAME_LENGTH (1 + 8 + FURI_HAL_VERSION_ARRAY_NAME_LENGTH)
|
||||
#define FURI_HAL_VERSION_OTP_ADDRESS OTP_AREA_BASE
|
||||
|
||||
/** OTP Versions enum */
|
||||
typedef enum {
|
||||
FuriHalVersionOtpVersion0=0x00,
|
||||
FuriHalVersionOtpVersion1=0x01,
|
||||
FuriHalVersionOtpVersionEmpty=0xFFFFFFFE,
|
||||
FuriHalVersionOtpVersionUnknown=0xFFFFFFFF,
|
||||
} FuriHalVersionOtpVersion;
|
||||
|
||||
/** OTP V0 Structure: prototypes and early EVT */
|
||||
typedef struct {
|
||||
uint8_t board_version;
|
||||
uint8_t board_target;
|
||||
uint8_t board_body;
|
||||
uint8_t board_connect;
|
||||
uint32_t header_timestamp;
|
||||
char name[FURI_HAL_VERSION_NAME_LENGTH];
|
||||
} FuriHalVersionOTPv0;
|
||||
|
||||
/** OTP V1 Structure: late EVT, DVT, PVT, Production */
|
||||
typedef struct {
|
||||
/* First 64 bits: header */
|
||||
uint16_t header_magic;
|
||||
uint8_t header_version;
|
||||
uint8_t header_reserved;
|
||||
uint32_t header_timestamp;
|
||||
|
||||
/* Second 64 bits: board info */
|
||||
uint8_t board_version; /** Board version */
|
||||
uint8_t board_target; /** Board target firmware */
|
||||
uint8_t board_body; /** Board body */
|
||||
uint8_t board_connect; /** Board interconnect */
|
||||
uint8_t board_color; /** Board color */
|
||||
uint8_t board_region; /** Board region */
|
||||
uint16_t board_reserved; /** Reserved for future use, 0x0000 */
|
||||
|
||||
/* Third 64 bits: Unique Device Name */
|
||||
char name[FURI_HAL_VERSION_NAME_LENGTH]; /** Unique Device Name */
|
||||
} FuriHalVersionOTPv1;
|
||||
|
||||
/** Represenation Model: */
|
||||
typedef struct {
|
||||
FuriHalVersionOtpVersion otp_version;
|
||||
|
||||
uint32_t timestamp;
|
||||
|
||||
uint8_t board_version; /** Board version */
|
||||
uint8_t board_target; /** Board target firmware */
|
||||
uint8_t board_body; /** Board body */
|
||||
uint8_t board_connect; /** Board interconnect */
|
||||
uint8_t board_color; /** Board color */
|
||||
uint8_t board_region; /** Board region */
|
||||
|
||||
char name[FURI_HAL_VERSION_ARRAY_NAME_LENGTH]; /** \0 terminated name */
|
||||
char device_name[FURI_HAL_VERSION_DEVICE_NAME_LENGTH]; /** device name for special needs */
|
||||
uint8_t ble_mac[6];
|
||||
} FuriHalVersion;
|
||||
|
||||
static FuriHalVersion furi_hal_version = {0};
|
||||
|
||||
static FuriHalVersionOtpVersion furi_hal_version_get_otp_version() {
|
||||
if (*(uint64_t*)FURI_HAL_VERSION_OTP_ADDRESS == 0xFFFFFFFF) {
|
||||
return FuriHalVersionOtpVersionEmpty;
|
||||
} else {
|
||||
if (((FuriHalVersionOTPv1*)FURI_HAL_VERSION_OTP_ADDRESS)->header_magic == FURI_HAL_VERSION_OTP_HEADER_MAGIC) {
|
||||
return FuriHalVersionOtpVersion1;
|
||||
} else if (((FuriHalVersionOTPv0*)FURI_HAL_VERSION_OTP_ADDRESS)->board_version <= 10) {
|
||||
return FuriHalVersionOtpVersion0;
|
||||
} else {
|
||||
return FuriHalVersionOtpVersionUnknown;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void furi_hal_version_set_name(const char* name) {
|
||||
if(name != NULL) {
|
||||
strlcpy(furi_hal_version.name, name, FURI_HAL_VERSION_ARRAY_NAME_LENGTH);
|
||||
snprintf(
|
||||
furi_hal_version.device_name,
|
||||
FURI_HAL_VERSION_DEVICE_NAME_LENGTH,
|
||||
"xFlipper %s",
|
||||
furi_hal_version.name);
|
||||
} else {
|
||||
snprintf(
|
||||
furi_hal_version.device_name,
|
||||
FURI_HAL_VERSION_DEVICE_NAME_LENGTH,
|
||||
"xFlipper");
|
||||
}
|
||||
|
||||
furi_hal_version.device_name[0] = AD_TYPE_COMPLETE_LOCAL_NAME;
|
||||
|
||||
// BLE Mac address
|
||||
uint32_t udn = LL_FLASH_GetUDN();
|
||||
uint32_t company_id = LL_FLASH_GetSTCompanyID();
|
||||
uint32_t device_id = LL_FLASH_GetDeviceID();
|
||||
furi_hal_version.ble_mac[0] = (uint8_t)(udn & 0x000000FF);
|
||||
furi_hal_version.ble_mac[1] = (uint8_t)( (udn & 0x0000FF00) >> 8 );
|
||||
furi_hal_version.ble_mac[2] = (uint8_t)( (udn & 0x00FF0000) >> 16 );
|
||||
furi_hal_version.ble_mac[3] = (uint8_t)device_id;
|
||||
furi_hal_version.ble_mac[4] = (uint8_t)(company_id & 0x000000FF);
|
||||
furi_hal_version.ble_mac[5] = (uint8_t)( (company_id & 0x0000FF00) >> 8 );
|
||||
}
|
||||
|
||||
static void furi_hal_version_load_otp_default() {
|
||||
furi_hal_version_set_name(NULL);
|
||||
}
|
||||
|
||||
static void furi_hal_version_load_otp_v0() {
|
||||
const FuriHalVersionOTPv0* otp = (FuriHalVersionOTPv0*)FURI_HAL_VERSION_OTP_ADDRESS;
|
||||
|
||||
furi_hal_version.timestamp = otp->header_timestamp;
|
||||
furi_hal_version.board_version = otp->board_version;
|
||||
furi_hal_version.board_target = otp->board_target;
|
||||
furi_hal_version.board_body = otp->board_body;
|
||||
furi_hal_version.board_connect = otp->board_connect;
|
||||
furi_hal_version.board_color = 0;
|
||||
furi_hal_version.board_region = 0;
|
||||
|
||||
furi_hal_version_set_name(otp->name);
|
||||
}
|
||||
|
||||
static void furi_hal_version_load_otp_v1() {
|
||||
const FuriHalVersionOTPv1* otp = (FuriHalVersionOTPv1*)FURI_HAL_VERSION_OTP_ADDRESS;
|
||||
|
||||
furi_hal_version.timestamp = otp->header_timestamp;
|
||||
furi_hal_version.board_version = otp->board_version;
|
||||
furi_hal_version.board_target = otp->board_target;
|
||||
furi_hal_version.board_body = otp->board_body;
|
||||
furi_hal_version.board_connect = otp->board_connect;
|
||||
furi_hal_version.board_color = otp->board_color;
|
||||
furi_hal_version.board_region = otp->board_region;
|
||||
|
||||
furi_hal_version_set_name(otp->name);
|
||||
}
|
||||
|
||||
void furi_hal_version_init() {
|
||||
furi_hal_version.otp_version = furi_hal_version_get_otp_version();
|
||||
switch(furi_hal_version.otp_version) {
|
||||
case FuriHalVersionOtpVersionUnknown:
|
||||
furi_hal_version_load_otp_default();
|
||||
break;
|
||||
case FuriHalVersionOtpVersionEmpty:
|
||||
furi_hal_version_load_otp_default();
|
||||
break;
|
||||
case FuriHalVersionOtpVersion0:
|
||||
furi_hal_version_load_otp_v0();
|
||||
break;
|
||||
case FuriHalVersionOtpVersion1:
|
||||
furi_hal_version_load_otp_v1();
|
||||
break;
|
||||
default: furi_check(0);
|
||||
}
|
||||
FURI_LOG_I("FuriHalVersion", "Init OK");
|
||||
}
|
||||
|
||||
bool furi_hal_version_do_i_belong_here() {
|
||||
return furi_hal_version_get_hw_target() == 6;
|
||||
}
|
||||
|
||||
const char* furi_hal_version_get_model_name() {
|
||||
return "Flipper Zero";
|
||||
}
|
||||
|
||||
const uint8_t furi_hal_version_get_hw_version() {
|
||||
return furi_hal_version.board_version;
|
||||
}
|
||||
|
||||
const uint8_t furi_hal_version_get_hw_target() {
|
||||
return furi_hal_version.board_target;
|
||||
}
|
||||
|
||||
const uint8_t furi_hal_version_get_hw_body() {
|
||||
return furi_hal_version.board_body;
|
||||
}
|
||||
|
||||
const FuriHalVersionColor furi_hal_version_get_hw_color() {
|
||||
return furi_hal_version.board_color;
|
||||
}
|
||||
|
||||
const uint8_t furi_hal_version_get_hw_connect() {
|
||||
return furi_hal_version.board_connect;
|
||||
}
|
||||
|
||||
const FuriHalVersionRegion furi_hal_version_get_hw_region() {
|
||||
return furi_hal_version.board_region;
|
||||
}
|
||||
|
||||
const uint32_t furi_hal_version_get_hw_timestamp() {
|
||||
return furi_hal_version.timestamp;
|
||||
}
|
||||
|
||||
const char* furi_hal_version_get_name_ptr() {
|
||||
return *furi_hal_version.name == 0x00 ? NULL : furi_hal_version.name;
|
||||
}
|
||||
|
||||
const char* furi_hal_version_get_device_name_ptr() {
|
||||
return furi_hal_version.device_name + 1;
|
||||
}
|
||||
|
||||
const char* furi_hal_version_get_ble_local_device_name_ptr() {
|
||||
return furi_hal_version.device_name;
|
||||
}
|
||||
|
||||
const uint8_t* furi_hal_version_get_ble_mac() {
|
||||
return furi_hal_version.ble_mac;
|
||||
}
|
||||
|
||||
const struct Version* furi_hal_version_get_firmware_version(void) {
|
||||
return version_get();
|
||||
}
|
||||
|
||||
const struct Version* furi_hal_version_get_boot_version(void) {
|
||||
#ifdef NO_BOOTLOADER
|
||||
return 0;
|
||||
#else
|
||||
/* Backup register which points to structure in flash memory */
|
||||
return (const struct Version*)LL_RTC_BAK_GetRegister(RTC, LL_RTC_BKP_DR1);
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t furi_hal_version_uid_size() {
|
||||
return 64/8;
|
||||
}
|
||||
|
||||
const uint8_t* furi_hal_version_uid() {
|
||||
return (const uint8_t *)UID64_BASE;
|
||||
}
|
@@ -1,13 +1,13 @@
|
||||
#include <api-hal-vibro.h>
|
||||
#include <api-hal-gpio.h>
|
||||
#include <furi-hal-vibro.h>
|
||||
#include <furi-hal-gpio.h>
|
||||
|
||||
void api_hal_vibro_init() {
|
||||
void furi_hal_vibro_init() {
|
||||
hal_gpio_init(&vibro_gpio, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
hal_gpio_write(&vibro_gpio, false);
|
||||
FURI_LOG_I("FuriHalVibro", "Init OK");
|
||||
|
||||
}
|
||||
|
||||
void api_hal_vibro_on(bool value) {
|
||||
void furi_hal_vibro_on(bool value) {
|
||||
hal_gpio_write(&vibro_gpio, value);
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
#include <api-hal.h>
|
||||
#include <furi-hal.h>
|
||||
|
||||
#include <adc.h>
|
||||
#include <aes.h>
|
||||
@@ -13,19 +13,19 @@
|
||||
#include <usb_device.h>
|
||||
#include <gpio.h>
|
||||
|
||||
void api_hal_init() {
|
||||
api_hal_clock_init();
|
||||
api_hal_console_init();
|
||||
api_hal_interrupt_init();
|
||||
api_hal_delay_init();
|
||||
void furi_hal_init() {
|
||||
furi_hal_clock_init();
|
||||
furi_hal_console_init();
|
||||
furi_hal_interrupt_init();
|
||||
furi_hal_delay_init();
|
||||
|
||||
MX_GPIO_Init();
|
||||
FURI_LOG_I("HAL", "GPIO OK");
|
||||
|
||||
MX_RTC_Init();
|
||||
FURI_LOG_I("HAL", "RTC OK");
|
||||
api_hal_boot_init();
|
||||
api_hal_version_init();
|
||||
furi_hal_boot_init();
|
||||
furi_hal_version_init();
|
||||
|
||||
MX_ADC1_Init();
|
||||
FURI_LOG_I("HAL", "ADC1 OK");
|
||||
@@ -34,7 +34,7 @@ void api_hal_init() {
|
||||
FURI_LOG_I("HAL", "SPI1 OK");
|
||||
MX_SPI2_Init();
|
||||
FURI_LOG_I("HAL", "SPI2 OK");
|
||||
api_hal_spi_init();
|
||||
furi_hal_spi_init();
|
||||
|
||||
MX_TIM1_Init();
|
||||
FURI_LOG_I("HAL", "TIM1 OK");
|
||||
@@ -58,19 +58,19 @@ void api_hal_init() {
|
||||
FURI_LOG_I("HAL", "CRC OK");
|
||||
|
||||
// VCP + USB
|
||||
api_hal_vcp_init();
|
||||
furi_hal_vcp_init();
|
||||
MX_USB_Device_Init();
|
||||
FURI_LOG_I("HAL", "USB OK");
|
||||
|
||||
api_hal_i2c_init();
|
||||
furi_hal_i2c_init();
|
||||
|
||||
// High Level
|
||||
api_hal_power_init();
|
||||
api_hal_light_init();
|
||||
api_hal_vibro_init();
|
||||
api_hal_subghz_init();
|
||||
api_hal_nfc_init();
|
||||
furi_hal_power_init();
|
||||
furi_hal_light_init();
|
||||
furi_hal_vibro_init();
|
||||
furi_hal_subghz_init();
|
||||
furi_hal_nfc_init();
|
||||
|
||||
// FreeRTOS glue
|
||||
api_hal_os_init();
|
||||
furi_hal_os_init();
|
||||
}
|
@@ -14,14 +14,14 @@ FLASH_ADDRESS = 0x08000000
|
||||
CFLAGS += -DNO_BOOTLOADER
|
||||
endif
|
||||
|
||||
API_HAL_OS_DEBUG ?= 0
|
||||
ifeq ($(API_HAL_OS_DEBUG), 1)
|
||||
CFLAGS += -DAPI_HAL_OS_DEBUG
|
||||
FURI_HAL_OS_DEBUG ?= 0
|
||||
ifeq ($(FURI_HAL_OS_DEBUG), 1)
|
||||
CFLAGS += -DFURI_HAL_OS_DEBUG
|
||||
endif
|
||||
|
||||
API_HAL_SUBGHZ_TX_GPIO ?= 0
|
||||
ifneq ($(API_HAL_SUBGHZ_TX_GPIO), 0)
|
||||
CFLAGS += -DAPI_HAL_SUBGHZ_TX_GPIO=$(API_HAL_SUBGHZ_TX_GPIO)
|
||||
FURI_HAL_SUBGHZ_TX_GPIO ?= 0
|
||||
ifneq ($(FURI_HAL_SUBGHZ_TX_GPIO), 0)
|
||||
CFLAGS += -DFURI_HAL_SUBGHZ_TX_GPIO=$(FURI_HAL_SUBGHZ_TX_GPIO)
|
||||
endif
|
||||
|
||||
ifeq ($(INVERT_RFID_IN), 1)
|
||||
@@ -39,7 +39,7 @@ CPPFLAGS += -fno-rtti -fno-use-cxa-atexit -fno-exceptions
|
||||
LDFLAGS += -Wl,--start-group -lstdc++ -lsupc++ -Wl,--end-group
|
||||
|
||||
MXPROJECT_DIR = $(TARGET_DIR)
|
||||
API_HAL_DIR = $(TARGET_DIR)
|
||||
FURI_HAL_DIR = $(TARGET_DIR)
|
||||
|
||||
CUBE_DIR = ../lib/STM32CubeWB
|
||||
C_SOURCES += \
|
||||
@@ -96,7 +96,7 @@ C_SOURCES += \
|
||||
$(CUBE_DIR)/Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c \
|
||||
$(wildcard $(MXPROJECT_DIR)/Src/*.c) \
|
||||
$(wildcard $(MXPROJECT_DIR)/Src/fatfs/*.c) \
|
||||
$(wildcard $(API_HAL_DIR)/api-hal/*.c)
|
||||
$(wildcard $(FURI_HAL_DIR)/furi-hal/*.c)
|
||||
|
||||
ASM_SOURCES += $(MXPROJECT_DIR)/startup_stm32wb55xx_cm4.s
|
||||
|
||||
@@ -124,7 +124,7 @@ CFLAGS += \
|
||||
-I$(CUBE_DIR)/Drivers/CMSIS/Include \
|
||||
-I$(MXPROJECT_DIR)/Inc \
|
||||
-I$(MXPROJECT_DIR)/Src/fatfs \
|
||||
-I$(API_HAL_DIR)/api-hal \
|
||||
-I$(FURI_HAL_DIR)/furi-hal \
|
||||
|
||||
# Ble glue
|
||||
CFLAGS += -I$(TARGET_DIR)/ble-glue \
|
||||
|
Reference in New Issue
Block a user