Skip to content

Commit

Permalink
firmware improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
klownfish committed May 6, 2024
1 parent 479f282 commit 3ef7def
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 132 deletions.
9 changes: 1 addition & 8 deletions firmware/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions firmware/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ heapless = { version = "0.8", default-features = false }
micromath = "2.0.0"
log = "0.4"

radio-sx128x = { path = "./deps/radio-sx128x", default-features = false }
#arrayvec = { version = "0.7.4", default-features = false }
radio-sx128x = { path = "./deps/radio-sx128x", features = ["defmt"] }
crc = "3.2.1"
embedded-io-async = "0.6.1"
embedded-can = "0.4.1"
Expand All @@ -41,8 +40,5 @@ embassy-sync = { git = "https://github.com/embassy-rs/embassy", rev = "81cf9d114
embassy-usb-logger = { git = "https://github.com/embassy-rs/embassy", rev = "81cf9d1143d30dd7dbcbeb7d5aa6ae4aa5db8a1a" }
embassy-embedded-hal = { git = "https://github.com/embassy-rs/embassy", rev = "81cf9d1143d30dd7dbcbeb7d5aa6ae4aa5db8a1a" }

# for sx128x to work
#radio = { git = "https://github.com/rust-iot/radio-hal", rev = "7aade85b61c08161bf3422f7d148417bd38ecdc2" }

[profile.release]
debug = 2
34 changes: 4 additions & 30 deletions firmware/deps/radio-sx128x/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,29 @@ edition = "2018"

[features]

defmt-default = []
defmt-trace = []
defmt-debug = []
defmt-info = []
defmt-warn = []
defmt-error = []

std = ["driver-pal/mock", "failure/std", "hex", "thiserror" ]
poll-irq = []
defmt = []
patch-unknown-state = []
tests = [ "driver-pal/mock" ]

default = [ "std", "serde", "driver-pal/hal-cp2130", "driver-pal/hal-linux", "patch-unknown-state" ]
default = [ "defmt", "patch-unknown-state" ]

[dependencies]
embedded-hal = "1.0"
defmt = {version = "0.3.5", optional = true }

driver-pal = { version = "0.8.0-alpha.6", default_features = false, optional=true }

bitflags = "1.0.4"
libc = "0.2.123"
log = { version = "0.4.17", default_features = false }
strum = { version = "0.24.0", default_features = false, features = [ "derive" ] }

crc16 = { version = "0.4.0", optional = true }
hex = { version = "0.4.2", optional = true }

humantime = { version = "2.0.1", optional = true }
clap = { version = "4.4.7", optional = true, features = [ "derive", "env" ] }
thiserror = { version = "1.0.30", optional = true }
failure = { version = "0.1.7", features = [ "derive" ], default-features = false }
serde = { version = "1.0.144", optional = true , features = ["derive"]}

tracing = { version = "0.1.34", optional = true }
tracing-subscriber = { version = "0.2.16", optional = true }
defmt = "0.3"

[dev-dependencies]
color-backtrace = "0.5.0"
toml = "0.5.8"
serde = { version = "1.0.144", features = [ "derive" ] }
serde_derive = "1.0.0"

[[bin]]
name = "sx128x-util"
path = "src/util/main.rs"
required-features = ["util"]


[patch.crates-io]
driver-pal = { git = "https://github.com/ryankurte/rust-driver-pal", rev = "8d7d63c8f097d9413966769fbc77d5ee68eca0ef" }
driver-cp2130 = { git = "https://github.com/rust-iot/rust-driver-cp2130", rev = "0a00fa0369c2ef34b9e09c8c0af2e9903184ba98" }
toml = "0.5.8"
5 changes: 0 additions & 5 deletions firmware/deps/radio-sx128x/src/device/ble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use super::common::*;

/// BLE operating mode channel configuration
#[derive(Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct BleChannel {
/// Operating frequency
Expand All @@ -19,7 +18,6 @@ pub struct BleChannel {

/// BLE operating mode packet configuration
#[derive(Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct BleConfig {
/// BLE connection state
Expand All @@ -33,7 +31,6 @@ pub struct BleConfig {
}

#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum BleConnectionStates {
// TODO
Expand All @@ -48,7 +45,6 @@ pub enum BleConnectionStates {

/// BLE CRC field configuration
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum BleCrcFields {
/// CRC disabled
Expand All @@ -59,7 +55,6 @@ pub enum BleCrcFields {

/// BLE mode packet types
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum BlePacketTypes {
/// Pseudo Random Binary Sequence based on 9th degree polynomial
Expand Down
8 changes: 0 additions & 8 deletions firmware/deps/radio-sx128x/src/device/common.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/// Modulation shaping parameter for GFSK, FLRC and BLE modes
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "util", derive(clap::Parser))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum ModShaping {
Expand All @@ -12,7 +11,6 @@ pub enum ModShaping {

/// Preamble lengths for GFSK, FLRC modes
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum PreambleLength {
/// Preamble length: 04 bits
Expand All @@ -35,7 +33,6 @@ pub enum PreambleLength {

/// Bitrate-Bandwidth for GFSK and BLE modes
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "util", derive(clap::Parser))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum GfskBleBitrateBandwidth {
Expand Down Expand Up @@ -69,7 +66,6 @@ pub enum GfskBleBitrateBandwidth {

/// Modulation Index for GFSK and BLE modes
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum GfskBleModIndex {
MOD_IND_0_35 = 0,
Expand All @@ -92,15 +88,13 @@ pub enum GfskBleModIndex {

/// Common radio whitening mode
#[derive(Copy, Clone, PartialEq, Debug, strum::Display)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum WhiteningModes {
RADIO_WHITENING_ON = 0x00,
RADIO_WHITENING_OFF = 0x08,
}

#[derive(Copy, Clone, PartialEq, Debug, strum::Display)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum SyncWordRxMatch {
/// No correlator turned on, i.e. do not search for SyncWord
Expand All @@ -115,7 +109,6 @@ pub enum SyncWordRxMatch {
}

#[derive(Copy, Clone, PartialEq, Debug, strum::Display)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum GfskFlrcPacketLength {
/// Fixed length, no header included
Expand All @@ -125,7 +118,6 @@ pub enum GfskFlrcPacketLength {
}

#[derive(Copy, Clone, PartialEq, Debug, strum::Display)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum GfskFlrcCrcModes {
/// CRC disabled
Expand Down
5 changes: 0 additions & 5 deletions firmware/deps/radio-sx128x/src/device/flrc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use super::common::*;

/// FLRC configuration structure
#[derive(Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct FlrcChannel {
/// Operating frequency
Expand All @@ -30,7 +29,6 @@ impl Default for FlrcChannel {

/// FLRC packet configuration structure
#[derive(Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct FlrcConfig {
pub preamble_length: PreambleLength,
Expand Down Expand Up @@ -63,7 +61,6 @@ impl Default for FlrcConfig {

/// Bit rate / bandwidth pairs for FLRC mode
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum FlrcBitrate {
/// Baud: 2600 kbps Bandwidth: 2.4 MHz
Expand Down Expand Up @@ -112,7 +109,6 @@ impl std::str::FromStr for FlrcBitrate {

/// Coding rates for FLRC mode
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum FlrcCodingRate {
/// 1/2 coding rate
Expand Down Expand Up @@ -144,7 +140,6 @@ impl std::str::FromStr for FlrcCodingRate {

/// FLRC sync word length
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum FlrcSyncWordLength {
/// No sync word
Expand Down
3 changes: 0 additions & 3 deletions firmware/deps/radio-sx128x/src/device/gfsk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use super::common::*;

/// GFSK operating mode configuration
#[derive(Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct GfskChannel {
/// Operating frequency
Expand All @@ -30,7 +29,6 @@ impl Default for GfskChannel {

/// GFSK packet configuration
#[derive(Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct GfskConfig {
/// Preamble length
Expand Down Expand Up @@ -70,7 +68,6 @@ impl Default for GfskConfig {

/// GFSK sync word length configuration
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum GfskSyncWordLength {
/// Sync word length: 1 byte
Expand Down
8 changes: 0 additions & 8 deletions firmware/deps/radio-sx128x/src/device/lora.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/// LoRa mode radio configuration
#[derive(Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct LoRaConfig {
// Preamble length in symbols (defaults to 8)
Expand Down Expand Up @@ -31,7 +30,6 @@ impl Default for LoRaConfig {

/// LoRa mode channel configuration
#[derive(Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct LoRaChannel {
/// LoRa frequency in Hz (defaults to 2.4GHz)
Expand All @@ -57,7 +55,6 @@ impl Default for LoRaChannel {

/// Spreading factor for LoRa mode
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum LoRaSpreadingFactor {
Sf5 = 0x50,
Expand All @@ -72,7 +69,6 @@ pub enum LoRaSpreadingFactor {

/// Bandwidth for LoRa mode
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum LoRaBandwidth {
/// 200 kHz bandwidth mode (actually 203.125 kHz)
Expand All @@ -99,7 +95,6 @@ impl LoRaBandwidth {

/// Coding rates for LoRa mode
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum LoRaCodingRate {
/// LoRa coding rate 4/5
Expand All @@ -118,7 +113,6 @@ pub enum LoRaCodingRate {

/// CRC mode for LoRa packet types
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum LoRaCrc {
Enabled = 0x20,
Expand All @@ -127,7 +121,6 @@ pub enum LoRaCrc {

/// IQ mode for LoRa packet types
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum LoRaIq {
Normal = 0x40,
Expand All @@ -136,7 +129,6 @@ pub enum LoRaIq {

/// Header configuration for LoRa packet types
#[derive(Copy, Clone, PartialEq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum LoRaHeader {
/// Variable length packets, length header included in packet
Expand Down
Loading

0 comments on commit 3ef7def

Please sign in to comment.