SubGhz: fix check connect cc1101_ext (#2857)
* SubGhz: fix check connect cc1101_ext * SubGhz: fix syntax * SubGhz: enable interface pin pullups * SubGhz: fix syntax * SubGhz: fix CLI check connect CC1101_ext * SubGhz: fix CLI display of the selected device Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
+42
-41
@@ -1,14 +1,27 @@
|
||||
#include "cc1101.h"
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <furi_hal_cortex.h>
|
||||
|
||||
static bool cc1101_spi_trx(FuriHalSpiBusHandle* handle, uint8_t* tx, uint8_t* rx, uint8_t size) {
|
||||
FuriHalCortexTimer timer = furi_hal_cortex_timer_get(CC1101_TIMEOUT * 1000);
|
||||
|
||||
while(furi_hal_gpio_read(handle->miso)) {
|
||||
if(furi_hal_cortex_timer_is_expired(timer)) {
|
||||
//timeout
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(!furi_hal_spi_bus_trx(handle, tx, rx, size, CC1101_TIMEOUT)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
CC1101Status cc1101_strobe(FuriHalSpiBusHandle* handle, uint8_t strobe) {
|
||||
uint8_t tx[1] = {strobe};
|
||||
CC1101Status rx[1] = {0};
|
||||
rx[0].CHIP_RDYn = 1;
|
||||
|
||||
while(furi_hal_gpio_read(handle->miso))
|
||||
;
|
||||
furi_hal_spi_bus_trx(handle, tx, (uint8_t*)rx, 1, CC1101_TIMEOUT);
|
||||
cc1101_spi_trx(handle, tx, (uint8_t*)rx, 1);
|
||||
|
||||
assert(rx[0].CHIP_RDYn == 0);
|
||||
return rx[0];
|
||||
@@ -17,10 +30,10 @@ CC1101Status cc1101_strobe(FuriHalSpiBusHandle* handle, uint8_t strobe) {
|
||||
CC1101Status cc1101_write_reg(FuriHalSpiBusHandle* handle, uint8_t reg, uint8_t data) {
|
||||
uint8_t tx[2] = {reg, data};
|
||||
CC1101Status rx[2] = {0};
|
||||
rx[0].CHIP_RDYn = 1;
|
||||
rx[1].CHIP_RDYn = 1;
|
||||
|
||||
while(furi_hal_gpio_read(handle->miso))
|
||||
;
|
||||
furi_hal_spi_bus_trx(handle, tx, (uint8_t*)rx, 2, CC1101_TIMEOUT);
|
||||
cc1101_spi_trx(handle, tx, (uint8_t*)rx, 2);
|
||||
|
||||
assert((rx[0].CHIP_RDYn | rx[1].CHIP_RDYn) == 0);
|
||||
return rx[1];
|
||||
@@ -30,10 +43,9 @@ CC1101Status cc1101_read_reg(FuriHalSpiBusHandle* handle, uint8_t reg, uint8_t*
|
||||
assert(sizeof(CC1101Status) == 1);
|
||||
uint8_t tx[2] = {reg | CC1101_READ, 0};
|
||||
CC1101Status rx[2] = {0};
|
||||
rx[0].CHIP_RDYn = 1;
|
||||
|
||||
while(furi_hal_gpio_read(handle->miso))
|
||||
;
|
||||
furi_hal_spi_bus_trx(handle, tx, (uint8_t*)rx, 2, CC1101_TIMEOUT);
|
||||
cc1101_spi_trx(handle, tx, (uint8_t*)rx, 2);
|
||||
|
||||
assert((rx[0].CHIP_RDYn) == 0);
|
||||
*data = *(uint8_t*)&rx[1];
|
||||
@@ -58,40 +70,40 @@ uint8_t cc1101_get_rssi(FuriHalSpiBusHandle* handle) {
|
||||
return rssi;
|
||||
}
|
||||
|
||||
void cc1101_reset(FuriHalSpiBusHandle* handle) {
|
||||
cc1101_strobe(handle, CC1101_STROBE_SRES);
|
||||
CC1101Status cc1101_reset(FuriHalSpiBusHandle* handle) {
|
||||
return cc1101_strobe(handle, CC1101_STROBE_SRES);
|
||||
}
|
||||
|
||||
CC1101Status cc1101_get_status(FuriHalSpiBusHandle* handle) {
|
||||
return cc1101_strobe(handle, CC1101_STROBE_SNOP);
|
||||
}
|
||||
|
||||
void cc1101_shutdown(FuriHalSpiBusHandle* handle) {
|
||||
cc1101_strobe(handle, CC1101_STROBE_SPWD);
|
||||
CC1101Status cc1101_shutdown(FuriHalSpiBusHandle* handle) {
|
||||
return cc1101_strobe(handle, CC1101_STROBE_SPWD);
|
||||
}
|
||||
|
||||
void cc1101_calibrate(FuriHalSpiBusHandle* handle) {
|
||||
cc1101_strobe(handle, CC1101_STROBE_SCAL);
|
||||
CC1101Status cc1101_calibrate(FuriHalSpiBusHandle* handle) {
|
||||
return cc1101_strobe(handle, CC1101_STROBE_SCAL);
|
||||
}
|
||||
|
||||
void cc1101_switch_to_idle(FuriHalSpiBusHandle* handle) {
|
||||
cc1101_strobe(handle, CC1101_STROBE_SIDLE);
|
||||
CC1101Status cc1101_switch_to_idle(FuriHalSpiBusHandle* handle) {
|
||||
return cc1101_strobe(handle, CC1101_STROBE_SIDLE);
|
||||
}
|
||||
|
||||
void cc1101_switch_to_rx(FuriHalSpiBusHandle* handle) {
|
||||
cc1101_strobe(handle, CC1101_STROBE_SRX);
|
||||
CC1101Status cc1101_switch_to_rx(FuriHalSpiBusHandle* handle) {
|
||||
return cc1101_strobe(handle, CC1101_STROBE_SRX);
|
||||
}
|
||||
|
||||
void cc1101_switch_to_tx(FuriHalSpiBusHandle* handle) {
|
||||
cc1101_strobe(handle, CC1101_STROBE_STX);
|
||||
CC1101Status cc1101_switch_to_tx(FuriHalSpiBusHandle* handle) {
|
||||
return cc1101_strobe(handle, CC1101_STROBE_STX);
|
||||
}
|
||||
|
||||
void cc1101_flush_rx(FuriHalSpiBusHandle* handle) {
|
||||
cc1101_strobe(handle, CC1101_STROBE_SFRX);
|
||||
CC1101Status cc1101_flush_rx(FuriHalSpiBusHandle* handle) {
|
||||
return cc1101_strobe(handle, CC1101_STROBE_SFRX);
|
||||
}
|
||||
|
||||
void cc1101_flush_tx(FuriHalSpiBusHandle* handle) {
|
||||
cc1101_strobe(handle, CC1101_STROBE_SFTX);
|
||||
CC1101Status cc1101_flush_tx(FuriHalSpiBusHandle* handle) {
|
||||
return cc1101_strobe(handle, CC1101_STROBE_SFTX);
|
||||
}
|
||||
|
||||
uint32_t cc1101_set_frequency(FuriHalSpiBusHandle* handle, uint32_t value) {
|
||||
@@ -123,12 +135,12 @@ uint32_t cc1101_set_intermediate_frequency(FuriHalSpiBusHandle* handle, uint32_t
|
||||
void cc1101_set_pa_table(FuriHalSpiBusHandle* handle, const uint8_t value[8]) {
|
||||
uint8_t tx[9] = {CC1101_PATABLE | CC1101_BURST}; //-V1009
|
||||
CC1101Status rx[9] = {0};
|
||||
rx[0].CHIP_RDYn = 1;
|
||||
rx[8].CHIP_RDYn = 1;
|
||||
|
||||
memcpy(&tx[1], &value[0], 8);
|
||||
|
||||
while(furi_hal_gpio_read(handle->miso))
|
||||
;
|
||||
furi_hal_spi_bus_trx(handle, tx, (uint8_t*)rx, sizeof(rx), CC1101_TIMEOUT);
|
||||
cc1101_spi_trx(handle, tx, (uint8_t*)rx, sizeof(rx));
|
||||
|
||||
assert((rx[0].CHIP_RDYn | rx[8].CHIP_RDYn) == 0);
|
||||
}
|
||||
@@ -139,12 +151,7 @@ uint8_t cc1101_write_fifo(FuriHalSpiBusHandle* handle, const uint8_t* data, uint
|
||||
buff_tx[0] = CC1101_FIFO | CC1101_BURST;
|
||||
memcpy(&buff_tx[1], data, size);
|
||||
|
||||
// Start transaction
|
||||
// Wait IC to become ready
|
||||
while(furi_hal_gpio_read(handle->miso))
|
||||
;
|
||||
// Tell IC what we want
|
||||
furi_hal_spi_bus_trx(handle, buff_tx, (uint8_t*)buff_rx, size + 1, CC1101_TIMEOUT);
|
||||
cc1101_spi_trx(handle, buff_tx, (uint8_t*)buff_rx, size + 1);
|
||||
|
||||
return size;
|
||||
}
|
||||
@@ -153,13 +160,7 @@ uint8_t cc1101_read_fifo(FuriHalSpiBusHandle* handle, uint8_t* data, uint8_t* si
|
||||
uint8_t buff_trx[2];
|
||||
buff_trx[0] = CC1101_FIFO | CC1101_READ | CC1101_BURST;
|
||||
|
||||
// Start transaction
|
||||
// Wait IC to become ready
|
||||
while(furi_hal_gpio_read(handle->miso))
|
||||
;
|
||||
|
||||
// First byte - packet length
|
||||
furi_hal_spi_bus_trx(handle, buff_trx, buff_trx, 2, CC1101_TIMEOUT);
|
||||
cc1101_spi_trx(handle, buff_trx, buff_trx, 2);
|
||||
|
||||
// Check that the packet is placed in the receive buffer
|
||||
if(buff_trx[1] > 64) {
|
||||
|
||||
+20
-8
@@ -46,8 +46,10 @@ CC1101Status cc1101_read_reg(FuriHalSpiBusHandle* handle, uint8_t reg, uint8_t*
|
||||
/** Reset
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
*
|
||||
* @return CC1101Status structure
|
||||
*/
|
||||
void cc1101_reset(FuriHalSpiBusHandle* handle);
|
||||
CC1101Status cc1101_reset(FuriHalSpiBusHandle* handle);
|
||||
|
||||
/** Get status
|
||||
*
|
||||
@@ -60,8 +62,10 @@ CC1101Status cc1101_get_status(FuriHalSpiBusHandle* handle);
|
||||
/** Enable shutdown mode
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
*
|
||||
* @return CC1101Status structure
|
||||
*/
|
||||
void cc1101_shutdown(FuriHalSpiBusHandle* handle);
|
||||
CC1101Status cc1101_shutdown(FuriHalSpiBusHandle* handle);
|
||||
|
||||
/** Get Partnumber
|
||||
*
|
||||
@@ -90,38 +94,46 @@ uint8_t cc1101_get_rssi(FuriHalSpiBusHandle* handle);
|
||||
/** Calibrate oscillator
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
*
|
||||
* @return CC1101Status structure
|
||||
*/
|
||||
void cc1101_calibrate(FuriHalSpiBusHandle* handle);
|
||||
CC1101Status cc1101_calibrate(FuriHalSpiBusHandle* handle);
|
||||
|
||||
/** Switch to idle
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
*/
|
||||
void cc1101_switch_to_idle(FuriHalSpiBusHandle* handle);
|
||||
CC1101Status cc1101_switch_to_idle(FuriHalSpiBusHandle* handle);
|
||||
|
||||
/** Switch to RX
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
*
|
||||
* @return CC1101Status structure
|
||||
*/
|
||||
void cc1101_switch_to_rx(FuriHalSpiBusHandle* handle);
|
||||
CC1101Status cc1101_switch_to_rx(FuriHalSpiBusHandle* handle);
|
||||
|
||||
/** Switch to TX
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
*
|
||||
* @return CC1101Status structure
|
||||
*/
|
||||
void cc1101_switch_to_tx(FuriHalSpiBusHandle* handle);
|
||||
CC1101Status cc1101_switch_to_tx(FuriHalSpiBusHandle* handle);
|
||||
|
||||
/** Flush RX FIFO
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
*
|
||||
* @return CC1101Status structure
|
||||
*/
|
||||
void cc1101_flush_rx(FuriHalSpiBusHandle* handle);
|
||||
CC1101Status cc1101_flush_rx(FuriHalSpiBusHandle* handle);
|
||||
|
||||
/** Flush TX FIFO
|
||||
*
|
||||
* @param handle - pointer to FuriHalSpiHandle
|
||||
*/
|
||||
void cc1101_flush_tx(FuriHalSpiBusHandle* handle);
|
||||
CC1101Status cc1101_flush_tx(FuriHalSpiBusHandle* handle);
|
||||
|
||||
/** Set Frequency
|
||||
*
|
||||
|
||||
@@ -14,7 +14,7 @@ extern "C" {
|
||||
#define CC1101_IFDIV 0x400
|
||||
|
||||
/* IO Bus constants */
|
||||
#define CC1101_TIMEOUT 500
|
||||
#define CC1101_TIMEOUT 250
|
||||
|
||||
/* Bits and pieces */
|
||||
#define CC1101_READ (1 << 7) /** Read Bit */
|
||||
|
||||
Reference in New Issue
Block a user