From: Nathael Pajani Date: Thu, 19 Nov 2020 18:45:18 +0000 (+0100) Subject: Update config part of CC1101 driver X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=82824e4fb2eb4cae008eb6830c9e426661d3537e;p=soft%2Flpc122x%2Fcore Update config part of CC1101 driver --- diff --git a/extdrv/cc1101.c b/extdrv/cc1101.c index ee0c677..9fd6a9a 100644 --- a/extdrv/cc1101.c +++ b/extdrv/cc1101.c @@ -38,11 +38,14 @@ struct cc1101_device { uint8_t spi_num; struct pio cs_pin; /* SPI CS pin, used as chip select */ struct pio miso_pin; /* SPI MISO pin, used to monitor "device ready" from CC1101 chip */ + /* Config */ + uint8_t crc_calc; /* Wether CRC calc is set or not */ /* Signal indication */ uint8_t rx_sig_strength; /* Received signal strength indication */ uint8_t link_quality; /* link quality */ }; static struct cc1101_device cc1101 = { + .crc_calc = 1, /* CRC Calc is ON by default */ .rx_sig_strength = 0, .link_quality = 0, }; @@ -350,9 +353,11 @@ int cc1101_receive_packet(uint8_t* buffer, uint8_t size, uint8_t* status) cc1101.rx_sig_strength = st_buff[0]; /* CRC error */ - if (!(cc1101.link_quality & CC1101_CRC_OK)) { - cc1101_flush_rx_fifo(); - return -CC1101_ERR_CRC; + if (cc1101.crc_calc == 1) { + if (!(cc1101.link_quality & CC1101_CRC_OK)) { + cc1101_flush_rx_fifo(); + return -CC1101_ERR_CRC; + } } /* Overflow ? */ if (rx_status & CC1101_RX_FIFO_OVERFLOW) { @@ -556,19 +561,6 @@ void cc1101_init(uint8_t ssp_num, const struct pio* cs_pin, const struct pio* mi cc1101_send_cmd(CC1101_CMD(state_idle)); } -/* Write / send all the configuration register values to the CC1101 chip */ -void cc1101_config(void) -{ - int i = 0; - cc1101_send_cmd(CC1101_CMD(state_idle)); - /* Write RF initial settings to CC1101 */ - for (i = 0; i < sizeof(rf_init_settings); i += 2) { - cc1101_write_reg(rf_init_settings[i], rf_init_settings[i + 1]); - } - /* Write PA Table value */ - cc1101_write_reg(CC1101_PATABLE, paTable[0]); -} - /* Update CC1101 config * Arguments are the settings table which is a table of address and value pairs, * and the table length, which must be even. @@ -584,13 +576,30 @@ void cc1101_update_config(uint8_t* settings, uint8_t len) * Move to idle state for all cases, easier. */ cc1101_send_cmd(CC1101_CMD(state_idle)); for (i = 0; i < len; i += 2) { + if (settings[i] == CC1101_REGS(pkt_ctrl[1])) { + cc1101.crc_calc = ((rf_init_settings[i + 1] & 0x04) ? 1 : 0); + } cc1101_write_reg(settings[i], settings[i + 1]); } } /* Change PA Table value */ -void cc1101_set_patable(uint8_t val) +void cc1101_set_patable(uint8_t* values, uint8_t len) { - cc1101_write_reg(CC1101_PATABLE, val); + if (len == 1) { + cc1101_write_reg(CC1101_PATABLE, values[0]); + } else { + cc1101_write_burst_reg(CC1101_PATABLE, values, len); + } } +/* Write / send all the configuration register values to the CC1101 chip */ +void cc1101_config(void) +{ + /* Write RF initial settings to CC1101 */ + cc1101_update_config(rf_init_settings, sizeof(rf_init_settings)); + /* Write PA Table value */ + cc1101_set_patable(paTable, 1); +} + + diff --git a/include/extdrv/cc1101.h b/include/extdrv/cc1101.h index f5496d2..65df5f3 100644 --- a/include/extdrv/cc1101.h +++ b/include/extdrv/cc1101.h @@ -300,7 +300,7 @@ void cc1101_config(void); */ void cc1101_update_config(uint8_t* settings, uint8_t len); -/* Change PA Table value */ -void cc1101_set_patable(uint8_t val); +/* Change PA Table values */ +void cc1101_set_patable(uint8_t* values, uint8_t len); #endif /* EXTDRV_CC1101_H */