Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring RF channel state machine #177

Merged
merged 11 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ embedded-time = { version = "0.12.0", optional = true }
miniconf = { version = "0.3", features = ["mqtt-client"]}
minimq = "0.5"
w5500 = { version = "0.4", optional = true }
smlang= "0.5"

[build-dependencies]
built = { version = "0.5", features = ["git2", "chrono"], default-features = false }
Expand Down
28 changes: 17 additions & 11 deletions src/hardware/booster_channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ use enum_iterator::IntoEnumIterator;
use stm32f4xx_hal as hal;
use tca9548::{self, Tca9548};

use super::rf_channel::{ChannelPins as RfChannelPins, RfChannel};
use super::rf_channel::{ChannelPins as RfChannelPins, RfChannel, RfChannelWrapper};
use super::{I2cBusManager, I2cProxy};
use crate::Error;
use embedded_hal::blocking::delay::DelayUs;

/// Represents a control structure for interfacing to booster RF channels.
pub struct BoosterChannels {
channels: [Option<RfChannel>; 8],
channels: [Option<RfChannelWrapper>; 8],
adc: hal::adc::Adc<hal::stm32::ADC3>,
mux: Tca9548<I2cProxy>,
}
Expand Down Expand Up @@ -59,7 +59,7 @@ impl BoosterChannels {
mut pins: [Option<RfChannelPins>; 8],
delay: &mut impl DelayUs<u16>,
) -> Self {
let mut rf_channels: [Option<RfChannel>; 8] =
let mut rf_channels: [Option<RfChannelWrapper>; 8] =
[None, None, None, None, None, None, None, None];

for channel in Channel::into_enum_iter() {
Expand All @@ -71,13 +71,10 @@ impl BoosterChannels {
.take()
.expect("Channel pins not available");

match RfChannel::new(&manager, control_pins, delay) {
Some(rf_channel) => {
rf_channels[channel as usize].replace(rf_channel);
}
None => {
info!("Channel {} did not enumerate", channel as usize);
}
if let Some(rf_channel) = RfChannel::new(&manager, control_pins, delay) {
rf_channels[channel as usize].replace(RfChannelWrapper::new(rf_channel));
} else {
info!("Channel {} did not enumerate", channel as usize);
}
}

Expand Down Expand Up @@ -105,7 +102,16 @@ impl BoosterChannels {
.ok_or(Error::NotPresent)
.and_then(|ch| {
mux.select_bus(Some(channel.into())).unwrap();
func(ch, adc)
func(ch.0.context_mut(), adc)
})
}

pub fn channel_mut(&mut self, channel: Channel) -> Result<&mut RfChannelWrapper, Error> {
if let Some(ref mut rf_channel) = self.channels[channel as usize] {
self.mux.select_bus(Some(channel.into())).unwrap();
Ok(rf_channel)
} else {
Err(Error::NotPresent)
}
}
}
Loading