}
-/***************************************************************************** */
-/* SPI registers and commands access Wrappers */
+/* Read and return single register value */
+static uint8_t cc1101_read_reg(uint8_t addr)
+{
+ uint8_t ret = 0;
+ cc1101_spi_transfer((addr | CC1101_READ_OFFSET), NULL, &ret, 1);
+ return ret;
+}
+/* Read nb registers from start_addr into buffer. Return the global status byte. */
+static uint8_t cc1101_read_burst_reg(uint8_t start_addr, uint8_t* buffer, uint8_t nb)
+{
+ uint8_t addr = (start_addr | CC1101_READ_OFFSET | CC1101_BURST_MODE);
+ return cc1101_spi_transfer(addr, NULL, buffer, nb);
+}
+/* Write single register value. Return the global status byte */
+static uint8_t cc1101_write_reg(uint8_t addr, uint8_t val)
+{
+ return cc1101_spi_transfer((addr | CC1101_WRITE_OFFSET), &val, NULL, 1);
+}
+static uint8_t cc1101_write_burst_reg(uint8_t start_addr, uint8_t* buffer, uint8_t nb)
+{
+ uint8_t addr = (start_addr | CC1101_WRITE_OFFSET | CC1101_BURST_MODE);
+ return cc1101_spi_transfer(addr, buffer, NULL, nb);
+}
+
/* Send command and return global status byte */
-uint8_t cc1101_send_cmd(uint8_t addr)
+static uint8_t cc1101_send_cmd(uint8_t addr)
{
return cc1101_spi_transfer((addr | CC1101_WRITE_OFFSET), NULL, NULL, 0);
}
+
+
+/***************************************************************************** */
+/* SPI registers and commands access Wrappers */
void cc1101_reset(void)
{
cc1101_send_cmd(CC1101_CMD(reset));
cc1101_send_cmd(CC1101_CMD(flush_rx));
}
+
+/***************************************************************************** */
+/* Read global status byte */
+uint8_t cc1101_read_status(void)
+{
+ return cc1101_send_cmd(CC1101_CMD(no_op));
+}
+/* Read packet status byte */
+uint8_t cc1101_read_pkt_status(void)
+{
+ return cc1101_send_cmd(CC1101_STATUS(packet_status));
+}
+
+
+/***************************************************************************** */
+/* Change Current mode / status to RX */
void cc1101_enter_rx_mode(void)
{
cc1101_send_cmd(CC1101_CMD(state_idle));
return 0;
}
-/* Read global status byte */
-uint8_t cc1101_read_status(void)
-{
- return cc1101_send_cmd(CC1101_CMD(no_op));
-}
-
-/* Read and return single register value */
-uint8_t cc1101_read_reg(uint8_t addr)
-{
- uint8_t ret = 0;
- cc1101_spi_transfer((addr | CC1101_READ_OFFSET), NULL, &ret, 1);
- return ret;
-}
-/* Read nb registers from start_addr into buffer. Return the global status byte. */
-uint8_t cc1101_read_burst_reg(uint8_t start_addr, uint8_t* buffer, uint8_t nb)
-{
- uint8_t addr = (start_addr | CC1101_READ_OFFSET | CC1101_BURST_MODE);
- return cc1101_spi_transfer(addr, NULL, buffer, nb);
-}
-/* Write single register value. Return the global status byte */
-uint8_t cc1101_write_reg(uint8_t addr, uint8_t val)
{
- return cc1101_spi_transfer((addr | CC1101_WRITE_OFFSET), &val, NULL, 1);
-}
-uint8_t cc1101_write_burst_reg(uint8_t start_addr, uint8_t* buffer, uint8_t nb)
-{
- uint8_t addr = (start_addr | CC1101_WRITE_OFFSET | CC1101_BURST_MODE);
- return cc1101_spi_transfer(addr, buffer, NULL, nb);
}
-
/***************************************************************************** */
/* Signal strength and link quality */
cc1101_write_reg(CC1101_REGS(device_addr), address);
}
+/* Set current channel to use.
+ * The caller is responsible for checking that the channel spacing and channel bandwith are configures
+ * correctly to prevent overlaping channels, or to use only non-overlaping channel numbers.
+ * This function places the CC1101 chip in idle state.
+ */
+void cc1101_set_channel(uint8_t chan)
+{
+ cc1101_send_cmd(CC1101_CMD(state_idle));
+ cc1101_write_reg(CC1101_REGS(channel_number), chan);
+}
+
/* Change a configuration byte.
* This function places the CC1101 chip in idle state.
*/
/* 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.
+ * Puts the CC1101 chip in idle state
*/
void cc1101_update_config(uint8_t* settings, uint8_t len)
{
if (len & 0x01) {
return;
}
+ /* Chip must be in idle state when modifying any of the Frequency or channel registers.
+ * Move to idle state for all cases, easier. */
+ cc1101_send_cmd(CC1101_CMD(state_idle));
for (i = 0; i < len; i += 2) {
cc1101_write_reg(settings[i], settings[i + 1]);
}
#define CC1101_FIFO_SIZE 64
#define CC1101_CRC_OK 0x80
+#define CC1101_CARIER_SENSE 0x40
+#define CC1101_CHANNEL_CLEAR 0x10
/* Errors definitions */
/***************************************************************************** */
/* SPI registers and commands access Wrappers */
-/* Send command and return global status byte */
-uint8_t cc1101_send_cmd(uint8_t addr);
+/* Reset CC1101 chip */
void cc1101_reset(void);
/* Power Up Reset is the same as a usual reset, the function will only wait longer for
* the "chip ready" signal before starting SPI transfers .... */
void cc1101_flush_tx_fifo(void);
void cc1101_flush_rx_fifo(void);
-void cc1101_enter_rx_mode(void);
-
+/***************************************************************************** */
/* Read global status byte */
uint8_t cc1101_read_status(void);
+/* Read packet status byte */
+uint8_t cc1101_read_pkt_status(void);
-/* Read and return single register value */
-uint8_t cc1101_read_reg(uint8_t addr);
-/* Read nb registers from start_addr into buffer. Return the global status byte. */
-uint8_t cc1101_read_burst_reg(uint8_t start_addr, uint8_t* buffer, uint8_t nb);
-
-/* Write single register value. Return the global status byte */
-uint8_t cc1101_write_reg(uint8_t addr, uint8_t val);
-uint8_t cc1101_write_burst_reg(uint8_t start_addr, uint8_t* buffer, uint8_t nb);
-
+/***************************************************************************** */
+/* Enter Rx mode */
+void cc1101_enter_rx_mode(void);
/***************************************************************************** */
*/
void cc1101_set_address(uint8_t address);
+/* Set current channel to use.
+ * The caller is responsible for checking that the channel spacing and channel bandwith are configures
+ * correctly to prevent overlaping channels, or to use only non-overlaping channel numbers.
+ * This function places the CC1101 chip in idle state.
+ */
+void cc1101_set_channel(uint8_t chan);
+
/* Change a configuration byte.
* This function places the CC1101 chip in idle state.
*/
/* Configure pins, reset the CC1101, and put the CC1101 chip in idle state */
void cc1101_init(uint8_t ssp_num, const struct pio* cs_pin, const struct pio* miso_pin);
-/* Write / send all the configuration register values to the CC1101 chip */
+/* Write / send all the configuration register values to the CC1101 chip
+ * This function places the CC1101 chip in idle state.
+ */
void cc1101_config(void);
/* 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.
+ * This function places the CC1101 chip in idle state.
*/
void cc1101_update_config(uint8_t* settings, uint8_t len);