Skip to main content

cc1101_embassy/
lib.rs

1//! # cc1101-embassy
2//!
3//! An async [Embassy](https://embassy.dev) driver for the CC1101 sub-1 GHz
4//! RF transceiver, targeting [`embedded-hal`] 1.0 and [`embedded-hal-async`] 1.0.
5//!
6//! ## Features
7//!
8//! - Async-first design using `embedded-hal-async`'s [`Wait`] trait for GDO pin interrupts
9//! - Human-readable [`RadioConfig`] builder — no raw register values required
10//! - Hardware CRC, variable or fixed packet length, RSSI/LQI status appending
11//! - Optional [`defmt`](https://defmt.rs) logging behind the `defmt` feature flag
12//! - `no_std`, no heap allocation, works on stable Rust
13//!
14//! ## Quick start
15//!
16//! ```rust,ignore
17//! let config = RadioConfig::new()
18//!     .frequency_hz(433_920_000)
19//!     .baud_rate(38_400)
20//!     .modulation(Modulation::Gfsk)
21//!     .tx_power(TxPower::Dbm0);
22//!
23//! let mut radio = Cc1101::new(spi, gdo0, gdo2).await?;
24//! radio.configure(&config).await?;
25//!
26//! // Transmit
27//! radio.transmit(b"hello").await?;
28//!
29//! // Receive
30//! let mut buf = [0u8; 64];
31//! let packet = radio.receive(&mut buf).await?;
32//! defmt::info!("rssi: {} lqi: {}", packet.rssi_dbm, packet.lqi);
33//! ```
34//!
35//! ## Wiring (CC1101 SPI)
36//!
37//! | CC1101 pin | RP2040 (example) | Notes |
38//! |-----------|-----------------|-------|
39//! | VCC       | 3.3 V           | 1.8–3.6 V |
40//! | GND       | GND             | |
41//! | CSn       | GP5             | Active low chip select (managed by SpiDevice) |
42//! | SCLK      | GP2             | SPI clock |
43//! | MOSI (SI) | GP3             | SPI MOSI |
44//! | MISO (SO) | GP4             | SPI MISO (also GDO1) |
45//! | GDO0      | GP6             | Interrupt pin — packet RX/TX done |
46//! | GDO2      | GP7             | Optional — sync word detect / RX threshold |
47//!
48//! [`Wait`]: embedded_hal_async::digital::Wait
49//! [`RadioConfig`]: crate::config::RadioConfig
50
51#![no_std]
52#![deny(missing_docs)]
53
54pub mod config;
55pub mod error;
56pub(crate) mod regs;
57
58mod driver;
59
60pub use config::{Modulation, PacketLength, RadioConfig, SyncMode, TxPower};
61pub use driver::{Cc1101, ReceivedPacket};
62pub use error::Error;