[FL-950] CC1101 Stage1, SPI Refactoring, Drivers layer (#386)
* API HAL SPI: refactoring, split into layers, prepare ST HAL separation. API HAL SubGhz: initialize on start. Drivers: add basic cc1101 driver. Update API usage. Debug: increase max debugger port speed. Remove subghz apps. * CC1101: chip status handling. ApiHalSpi: increase SubGhz bus speed to 8mhz. F4: backport subghz initialization. * Api Hal SubGhz: rx path and frequency. CC1101: frequency control. * SubGhz Application: basic tests * SubGhz app: tone and packet test. API HAL SUBGHZ: update configs, add missing bits and pieces.
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
static osThreadAttr_t platform_irq_thread_attr;
|
||||
static volatile osThreadId_t platform_irq_thread_id = NULL;
|
||||
static volatile PlatformIrqCallback platform_irq_callback = NULL;
|
||||
static ApiHalSpiDevice* platform_st25r3916 = NULL;
|
||||
|
||||
void nfc_isr(void* _pin, void* _ctx) {
|
||||
uint32_t pin = (uint32_t)_pin;
|
||||
@@ -36,27 +37,30 @@ void platformSetIrqCallback(PlatformIrqCallback callback) {
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef platformSpiTxRx(const uint8_t *txBuf, uint8_t *rxBuf, uint16_t len) {
|
||||
HAL_StatusTypeDef ret;
|
||||
bool ret = false;
|
||||
if (txBuf && rxBuf) {
|
||||
ret = HAL_SPI_TransmitReceive(&SPI_R, (uint8_t*)txBuf, rxBuf, len, HAL_MAX_DELAY);
|
||||
ret = api_hal_spi_bus_trx(platform_st25r3916->bus, (uint8_t*)txBuf, rxBuf, len, 1000);
|
||||
} else if (txBuf) {
|
||||
ret = HAL_SPI_Transmit(&SPI_R, (uint8_t*)txBuf, len, HAL_MAX_DELAY);
|
||||
ret = api_hal_spi_bus_tx(platform_st25r3916->bus, (uint8_t*)txBuf, len, 1000);
|
||||
} else if (rxBuf) {
|
||||
ret = HAL_SPI_Receive(&SPI_R, (uint8_t*)rxBuf, len, HAL_MAX_DELAY);
|
||||
ret = api_hal_spi_bus_rx(platform_st25r3916->bus, (uint8_t*)rxBuf, len, 1000);
|
||||
}
|
||||
|
||||
if(ret != HAL_OK) {
|
||||
|
||||
if(!ret) {
|
||||
asm("bkpt 1");
|
||||
exit(255);
|
||||
return HAL_ERROR;
|
||||
} else {
|
||||
return HAL_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void platformProtectST25RComm() {
|
||||
api_hal_spi_lock(&SPI_R);
|
||||
NFC_SPI_Reconfigure();
|
||||
furi_assert(platform_st25r3916 == NULL);
|
||||
platform_st25r3916 = (ApiHalSpiDevice*)api_hal_spi_device_get(ApiHalSpiDeviceIdNfc);
|
||||
}
|
||||
|
||||
void platformUnprotectST25RComm() {
|
||||
api_hal_spi_unlock(&SPI_R);
|
||||
furi_assert(platform_st25r3916);
|
||||
api_hal_spi_device_return(platform_st25r3916);
|
||||
platform_st25r3916 = NULL;
|
||||
}
|
||||
|
@@ -58,40 +58,40 @@ void platformUnprotectST25RComm();
|
||||
|
||||
#define platformIrqST25RSetCallback( cb ) platformSetIrqCallback(cb)
|
||||
|
||||
#define platformProtectST25RIrqStatus() platformProtectST25RComm() /*!< Protect unique access to IRQ status var - IRQ disable on single thread environment (MCU) ; Mutex lock on a multi thread environment */
|
||||
#define platformUnprotectST25RIrqStatus() platformUnprotectST25RComm() /*!< Unprotect the IRQ status var - IRQ enable on a single thread environment (MCU) ; Mutex unlock on a multi thread environment */
|
||||
#define platformProtectST25RIrqStatus() platformProtectST25RComm() /*!< Protect unique access to IRQ status var - IRQ disable on single thread environment (MCU) ; Mutex lock on a multi thread environment */
|
||||
#define platformUnprotectST25RIrqStatus() platformUnprotectST25RComm() /*!< Unprotect the IRQ status var - IRQ enable on a single thread environment (MCU) ; Mutex unlock on a multi thread environment */
|
||||
|
||||
#define platformLedOff( port, pin ) api_hal_light_set(pin, 0x00)
|
||||
#define platformLedOn( port, pin ) api_hal_light_set(pin, 0xFF)
|
||||
#define platformLedOff( port, pin ) api_hal_light_set(pin, 0x00)
|
||||
#define platformLedOn( port, pin ) api_hal_light_set(pin, 0xFF)
|
||||
|
||||
#define platformGpioSet( port, pin ) HAL_GPIO_WritePin(port, pin, GPIO_PIN_SET) /*!< Turns the given GPIO High */
|
||||
#define platformGpioClear( port, pin ) HAL_GPIO_WritePin(port, pin, GPIO_PIN_RESET) /*!< Turns the given GPIO Low */
|
||||
#define platformGpioToogle( port, pin ) HAL_GPIO_TogglePin(port, pin) /*!< Toogles the given GPIO */
|
||||
#define platformGpioIsHigh( port, pin ) (HAL_GPIO_ReadPin(port, pin) == GPIO_PIN_SET) /*!< Checks if the given LED is High */
|
||||
#define platformGpioIsLow( port, pin ) (!platformGpioIsHigh(port, pin)) /*!< Checks if the given LED is Low */
|
||||
#define platformGpioSet( port, pin ) HAL_GPIO_WritePin(port, pin, GPIO_PIN_SET) /*!< Turns the given GPIO High */
|
||||
#define platformGpioClear( port, pin ) HAL_GPIO_WritePin(port, pin, GPIO_PIN_RESET) /*!< Turns the given GPIO Low */
|
||||
#define platformGpioToogle( port, pin ) HAL_GPIO_TogglePin(port, pin) /*!< Toogles the given GPIO */
|
||||
#define platformGpioIsHigh( port, pin ) (HAL_GPIO_ReadPin(port, pin) == GPIO_PIN_SET) /*!< Checks if the given LED is High */
|
||||
#define platformGpioIsLow( port, pin ) (!platformGpioIsHigh(port, pin)) /*!< Checks if the given LED is Low */
|
||||
|
||||
#define platformTimerCreate( t ) timerCalculateTimer(t) /*!< Create a timer with the given time (ms) */
|
||||
#define platformTimerIsExpired( timer ) timerIsExpired(timer) /*!< Checks if the given timer is expired */
|
||||
#define platformDelay( t ) osDelay( t ) /*!< Performs a delay for the given time (ms) */
|
||||
#define platformTimerCreate( t ) timerCalculateTimer(t) /*!< Create a timer with the given time (ms) */
|
||||
#define platformTimerIsExpired( timer ) timerIsExpired(timer) /*!< Checks if the given timer is expired */
|
||||
#define platformDelay( t ) osDelay( t ) /*!< Performs a delay for the given time (ms) */
|
||||
|
||||
#define platformGetSysTick() osKernelGetTickCount() /*!< Get System Tick (1 tick = 1 ms) */
|
||||
#define platformGetSysTick() osKernelGetTickCount() /*!< Get System Tick (1 tick = 1 ms) */
|
||||
|
||||
#define platformAssert( exp ) assert_param( exp ) /*!< Asserts whether the given expression is true*/
|
||||
// #define platformErrorHandle() Error_Handler() /*!< Global error handle\trap */
|
||||
#define platformAssert( exp ) assert_param( exp ) /*!< Asserts whether the given expression is true*/
|
||||
#define platformErrorHandle() Error_Handler() /*!< Global error handle\trap */
|
||||
|
||||
#define platformSpiSelect() platformGpioClear( ST25R_SS_PORT, ST25R_SS_PIN ) /*!< SPI SS\CS: Chip|Slave Select */
|
||||
#define platformSpiDeselect() platformGpioSet( ST25R_SS_PORT, ST25R_SS_PIN ) /*!< SPI SS\CS: Chip|Slave Deselect */
|
||||
#define platformSpiSelect() platformGpioClear( ST25R_SS_PORT, ST25R_SS_PIN ) /*!< SPI SS\CS: Chip|Slave Select */
|
||||
#define platformSpiDeselect() platformGpioSet( ST25R_SS_PORT, ST25R_SS_PIN ) /*!< SPI SS\CS: Chip|Slave Deselect */
|
||||
|
||||
|
||||
#define platformI2CTx( txBuf, len, last, txOnly ) /*!< I2C Transmit */
|
||||
#define platformI2CRx( txBuf, len ) /*!< I2C Receive */
|
||||
#define platformI2CStart() /*!< I2C Start condition */
|
||||
#define platformI2CStop() /*!< I2C Stop condition */
|
||||
#define platformI2CRepeatStart() /*!< I2C Repeat Start */
|
||||
#define platformI2CSlaveAddrWR(add) /*!< I2C Slave address for Write operation */
|
||||
#define platformI2CSlaveAddrRD(add) /*!< I2C Slave address for Read operation */
|
||||
#define platformI2CTx( txBuf, len, last, txOnly ) /*!< I2C Transmit */
|
||||
#define platformI2CRx( txBuf, len ) /*!< I2C Receive */
|
||||
#define platformI2CStart() /*!< I2C Start condition */
|
||||
#define platformI2CStop() /*!< I2C Stop condition */
|
||||
#define platformI2CRepeatStart() /*!< I2C Repeat Start */
|
||||
#define platformI2CSlaveAddrWR(add) /*!< I2C Slave address for Write operation */
|
||||
#define platformI2CSlaveAddrRD(add) /*!< I2C Slave address for Read operation */
|
||||
|
||||
#define platformLog(...) /*!< Log method */
|
||||
#define platformLog(...) /*!< Log method */
|
||||
|
||||
/*
|
||||
******************************************************************************
|
||||
|
Reference in New Issue
Block a user