DeterministicESPAsyncWebServer v6.28.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
cc1101.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file cc1101.h
6 * @brief CC1101 sub-GHz radio driver (DETWS_ENABLE_CC1101) - TI 300-928 MHz over SPI.
7 *
8 * A radio driver plugin for the gateway (DETWS_ENABLE_GATEWAY): generic ISM-band remotes and sensors
9 * (OOK / 2-FSK on 315/433/868/915 MHz) bridged to the web stack. Like the nRF24, the CC1101 speaks an
10 * **SPI header protocol** - every transaction begins with a header byte (bit7 = read, bit6 = burst,
11 * bits5-0 = address) and returns the **chip status byte** (CHIP_RDYn, the 3-bit state machine value, and
12 * the FIFO-bytes-available count). Config registers live at 0x00-0x2E, the 13 command **strobes** at
13 * 0x30-0x3D (a single write triggers the command), the read-only **status** registers at 0x30-0x3D read
14 * with the burst bit set, and both FIFOs at 0x3F.
15 *
16 * The huge modem configuration (band, data rate, deviation, sync word) is board/tool-specific, so the
17 * caller supplies it as a register table (a TI SmartRF Studio export); the driver resets the chip, writes
18 * that table, sets the channel, and verifies the VERSION status register talks back. Packets use variable
19 * length mode (a leading length byte) with appended RSSI/LQI status. Bridge received payloads northbound
20 * with det_gw_uplink. The register/strobe/FIFO protocol is host-testable against a mock; the RF link
21 * needs the module.
22 */
23
24#ifndef DETERMINISTICESPASYNCWEBSERVER_CC1101_H
25#define DETERMINISTICESPASYNCWEBSERVER_CC1101_H
26
27#include "ServerConfig.h"
28
29#if DETWS_ENABLE_CC1101
30
31#include <stddef.h>
32#include <stdint.h>
33
34/** @brief Full-duplex SPI transfer of @p len bytes (chip-select toggled by the callback). */
35typedef void (*cc1101_spi_fn)(const uint8_t *tx, uint8_t *rx, uint8_t len, void *ctx);
36
37/** @brief The bus a driver call uses: your SPI transfer behind it. */
38struct cc1101_bus
39{
40 cc1101_spi_fn spi;
41 void *ctx;
42};
43
44/** @brief One modem-config register write (address + value). */
45struct cc1101_reg
46{
47 uint8_t addr;
48 uint8_t value;
49};
50
51/** @brief Radio configuration applied by cc1101_init(). */
52struct cc1101_config
53{
54 const cc1101_reg *regs; ///< SmartRF-exported register settings (may be null for none).
55 size_t nregs;
56 uint8_t channel; ///< CHANNR (0x0A): channel number on top of the base frequency.
57};
58
59/**
60 * @brief Reset the CC1101, apply @p cfg, set the channel, and confirm it is present.
61 * @return true; false if the VERSION status register reads 0x00 / 0xFF (the bus is not talking).
62 */
63bool cc1101_init(const cc1101_bus *bus, const cc1101_config *cfg);
64
65/**
66 * @brief Transmit @p len bytes as a variable-length packet (leading length byte), then strobe TX.
67 * @return true; false if @p len is 0 or exceeds 63 (one FIFO fill).
68 */
69bool cc1101_send(const cc1101_bus *bus, const uint8_t *data, uint8_t len);
70
71/** @brief True once the state machine has returned to IDLE after a transmit. */
72bool cc1101_tx_done(const cc1101_bus *bus);
73
74/** @brief Flush RX and enter receive mode (strobe RX). Then poll cc1101_recv(). */
75void cc1101_set_rx(const cc1101_bus *bus);
76
77/**
78 * @brief If a packet is waiting, read it (length byte + payload + appended RSSI/LQI status).
79 * @param[out] rssi_dbm set to the decoded RSSI in dBm (may be null).
80 * @return the payload length (capped at @p cap), or -1 if the RX FIFO is empty.
81 */
82int cc1101_recv(const cc1101_bus *bus, uint8_t *buf, uint8_t cap, int16_t *rssi_dbm);
83
84/** @brief Convert a raw CC1101 RSSI register value to dBm (TI datasheet formula). Pure. */
85int16_t cc1101_rssi_dbm(uint8_t raw);
86
87#endif // DETWS_ENABLE_CC1101
88
89#endif // DETERMINISTICESPASYNCWEBSERVER_CC1101_H
User-facing configuration for DeterministicESPAsyncWebServer.