Apply clippy suggestions

This commit is contained in:
atse 2024-10-07 12:54:19 +08:00
parent 453360ff5e
commit 8867744d67
11 changed files with 92 additions and 112 deletions

View File

@ -199,7 +199,7 @@ impl<SPI: Transfer<u8, Error = E>, NSS: OutputPin, E: fmt::Debug> Adc<SPI, NSS>
ChecksumMode::Crc => ChecksumMode::Crc, ChecksumMode::Crc => ChecksumMode::Crc,
}); });
checksum.feed(&[address]); checksum.feed(&[address]);
checksum.feed(&reg_data); checksum.feed(reg_data);
let checksum_out = checksum.result(); let checksum_out = checksum.result();
let mut data = reg_data.clone(); let mut data = reg_data.clone();
@ -237,10 +237,10 @@ impl<SPI: Transfer<u8, Error = E>, NSS: OutputPin, E: fmt::Debug> Adc<SPI, NSS>
Ok(()) Ok(())
} }
fn transfer<'w>( fn transfer(
&mut self, &mut self,
addr: u8, addr: u8,
reg_data: &'w mut [u8], reg_data: &mut [u8],
checksum: Option<u8>, checksum: Option<u8>,
) -> Result<Option<u8>, SPI::Error> { ) -> Result<Option<u8>, SPI::Error> {
let mut addr_buf = [addr]; let mut addr_buf = [addr];

View File

@ -43,7 +43,7 @@ impl ChannelState {
adc_time: Instant::from_secs(0), adc_time: Instant::from_secs(0),
// default: 10 Hz // default: 10 Hz
adc_interval: Duration::from_millis(100), adc_interval: Duration::from_millis(100),
center: CenterPoint::Vref, center: CenterPoint::VRef,
dac_value: ElectricPotential::new::<volt>(0.0), dac_value: ElectricPotential::new::<volt>(0.0),
i_set: ElectricCurrent::new::<ampere>(0.0), i_set: ElectricCurrent::new::<ampere>(0.0),
pwm_limits: PwmLimits { pwm_limits: PwmLimits {

View File

@ -24,7 +24,7 @@ use uom::si::{
}; };
pub enum PinsAdcReadTarget { pub enum PinsAdcReadTarget {
VREF, VRef,
DacVfb, DacVfb,
ITec, ITec,
VTec, VTec,
@ -131,7 +131,7 @@ impl Channels {
/// calculate the TEC i_set centerpoint /// calculate the TEC i_set centerpoint
pub fn get_center(&mut self, channel: usize) -> ElectricPotential { pub fn get_center(&mut self, channel: usize) -> ElectricPotential {
match self.channel_state(channel).center { match self.channel_state(channel).center {
CenterPoint::Vref => self.adc_read(channel, PinsAdcReadTarget::VREF, 8), CenterPoint::VRef => self.adc_read(channel, PinsAdcReadTarget::VRef, 8),
CenterPoint::Override(center_point) => { CenterPoint::Override(center_point) => {
ElectricPotential::new::<volt>(center_point.into()) ElectricPotential::new::<volt>(center_point.into())
} }
@ -168,7 +168,7 @@ impl Channels {
Polarity::Normal => 1.0, Polarity::Normal => 1.0,
Polarity::Reversed => -1.0, Polarity::Reversed => -1.0,
}; };
let vref_meas = match channel.into() { let vref_meas = match channel {
0 => self.channel0.vref_meas, 0 => self.channel0.vref_meas,
1 => self.channel1.vref_meas, 1 => self.channel1.vref_meas,
_ => unreachable!(), _ => unreachable!(),
@ -177,8 +177,8 @@ impl Channels {
let r_sense = ElectricalResistance::new::<ohm>(R_SENSE); let r_sense = ElectricalResistance::new::<ohm>(R_SENSE);
let voltage = negate * i_set * 10.0 * r_sense + center_point; let voltage = negate * i_set * 10.0 * r_sense + center_point;
let voltage = self.set_dac(channel, voltage); let voltage = self.set_dac(channel, voltage);
let i_set = negate * (voltage - center_point) / (10.0 * r_sense);
i_set negate * (voltage - center_point) / (10.0 * r_sense)
} }
/// AN4073: ADC Reading Dispersion can be reduced through Averaging /// AN4073: ADC Reading Dispersion can be reduced through Averaging
@ -192,7 +192,7 @@ impl Channels {
match channel { match channel {
0 => { 0 => {
sample = match adc_read_target { sample = match adc_read_target {
PinsAdcReadTarget::VREF => match &self.channel0.vref_pin { PinsAdcReadTarget::VRef => match &self.channel0.vref_pin {
Channel0VRef::Analog(vref_pin) => { Channel0VRef::Analog(vref_pin) => {
for _ in (0..avg_pt).rev() { for _ in (0..avg_pt).rev() {
sample += self.pins_adc.convert( sample += self.pins_adc.convert(
@ -202,7 +202,7 @@ impl Channels {
} }
sample / avg_pt as u32 sample / avg_pt as u32
} }
Channel0VRef::Disabled(_) => 2048 as u32, Channel0VRef::Disabled(_) => 2048_u32,
}, },
PinsAdcReadTarget::DacVfb => { PinsAdcReadTarget::DacVfb => {
for _ in (0..avg_pt).rev() { for _ in (0..avg_pt).rev() {
@ -237,7 +237,7 @@ impl Channels {
} }
1 => { 1 => {
sample = match adc_read_target { sample = match adc_read_target {
PinsAdcReadTarget::VREF => match &self.channel1.vref_pin { PinsAdcReadTarget::VRef => match &self.channel1.vref_pin {
Channel1VRef::Analog(vref_pin) => { Channel1VRef::Analog(vref_pin) => {
for _ in (0..avg_pt).rev() { for _ in (0..avg_pt).rev() {
sample += self.pins_adc.convert( sample += self.pins_adc.convert(
@ -247,7 +247,7 @@ impl Channels {
} }
sample / avg_pt as u32 sample / avg_pt as u32
} }
Channel1VRef::Disabled(_) => 2048 as u32, Channel1VRef::Disabled(_) => 2048_u32,
}, },
PinsAdcReadTarget::DacVfb => { PinsAdcReadTarget::DacVfb => {
for _ in (0..avg_pt).rev() { for _ in (0..avg_pt).rev() {
@ -304,9 +304,9 @@ impl Channels {
let samples = 50; let samples = 50;
let mut target_voltage = ElectricPotential::new::<volt>(0.0); let mut target_voltage = ElectricPotential::new::<volt>(0.0);
for _ in 0..samples { for _ in 0..samples {
target_voltage = target_voltage + self.get_center(channel); target_voltage += self.get_center(channel);
} }
target_voltage = target_voltage / samples as f64; target_voltage /= samples as f64;
let mut start_value = 1; let mut start_value = 1;
let mut best_error = ElectricPotential::new::<volt>(100.0); let mut best_error = ElectricPotential::new::<volt>(100.0);
@ -378,7 +378,7 @@ impl Channels {
// Get current passing through TEC // Get current passing through TEC
pub fn get_tec_i(&mut self, channel: usize) -> ElectricCurrent { pub fn get_tec_i(&mut self, channel: usize) -> ElectricCurrent {
let tec_i = (self.adc_read(channel, PinsAdcReadTarget::ITec, 16) let tec_i = (self.adc_read(channel, PinsAdcReadTarget::ITec, 16)
- self.adc_read(channel, PinsAdcReadTarget::VREF, 16)) - self.adc_read(channel, PinsAdcReadTarget::VRef, 16))
/ ElectricalResistance::new::<ohm>(0.4); / ElectricalResistance::new::<ohm>(0.4);
match self.channel_state(channel).polarity { match self.channel_state(channel).polarity {
Polarity::Normal => tec_i, Polarity::Normal => tec_i,
@ -608,7 +608,7 @@ impl Serialize for CenterPointJson {
S: Serializer, S: Serializer,
{ {
match self.0 { match self.0 {
CenterPoint::Vref => serializer.serialize_str("vref"), CenterPoint::VRef => serializer.serialize_str("vref"),
CenterPoint::Override(vref) => serializer.serialize_f32(vref), CenterPoint::Override(vref) => serializer.serialize_f32(vref),
} }
} }

View File

@ -33,9 +33,9 @@ pub enum Handler {
#[derive(Clone, Debug, PartialEq)] #[derive(Clone, Debug, PartialEq)]
pub enum Error { pub enum Error {
ReportError, Report,
PostFilterRateError, PostFilterRate,
FlashError, Flash,
} }
pub type JsonBuffer = Vec<u8, U1024>; pub type JsonBuffer = Vec<u8, U1024>;
@ -52,7 +52,7 @@ fn send_line(socket: &mut TcpSocket, data: &[u8]) -> bool {
data.len(), data.len(),
); );
} else { } else {
match socket.send_slice(&data) { match socket.send_slice(data) {
Ok(sent) if sent == data.len() => { Ok(sent) if sent == data.len() => {
let _ = socket.send_slice(b"\n"); let _ = socket.send_slice(b"\n");
// success // success
@ -75,7 +75,7 @@ impl Handler {
Err(e) => { Err(e) => {
error!("unable to serialize report: {:?}", e); error!("unable to serialize report: {:?}", e);
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e); let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
return Err(Error::ReportError); return Err(Error::Report);
} }
} }
Ok(Handler::Handled) Ok(Handler::Handled)
@ -89,7 +89,7 @@ impl Handler {
Err(e) => { Err(e) => {
error!("unable to serialize pid summary: {:?}", e); error!("unable to serialize pid summary: {:?}", e);
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e); let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
return Err(Error::ReportError); return Err(Error::Report);
} }
} }
Ok(Handler::Handled) Ok(Handler::Handled)
@ -103,7 +103,7 @@ impl Handler {
Err(e) => { Err(e) => {
error!("unable to serialize pwm summary: {:?}", e); error!("unable to serialize pwm summary: {:?}", e);
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e); let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
return Err(Error::ReportError); return Err(Error::Report);
} }
} }
Ok(Handler::Handled) Ok(Handler::Handled)
@ -120,7 +120,7 @@ impl Handler {
Err(e) => { Err(e) => {
error!("unable to serialize steinhart-hart summaries: {:?}", e); error!("unable to serialize steinhart-hart summaries: {:?}", e);
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e); let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
return Err(Error::ReportError); return Err(Error::Report);
} }
} }
Ok(Handler::Handled) Ok(Handler::Handled)
@ -134,7 +134,7 @@ impl Handler {
Err(e) => { Err(e) => {
error!("unable to serialize postfilter summary: {:?}", e); error!("unable to serialize postfilter summary: {:?}", e);
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e); let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
return Err(Error::ReportError); return Err(Error::Report);
} }
} }
Ok(Handler::Handled) Ok(Handler::Handled)
@ -286,7 +286,7 @@ impl Handler {
socket, socket,
b"{{\"error\": \"unable to choose postfilter rate\"}}", b"{{\"error\": \"unable to choose postfilter rate\"}}",
); );
return Err(Error::PostFilterRateError); return Err(Error::PostFilterRate);
} }
} }
Ok(Handler::Handled) Ok(Handler::Handled)
@ -298,9 +298,9 @@ impl Handler {
store: &mut FlashStore, store: &mut FlashStore,
channel: Option<usize>, channel: Option<usize>,
) -> Result<Handler, Error> { ) -> Result<Handler, Error> {
for c in 0..CHANNELS { for (c, key) in CHANNEL_CONFIG_KEY.iter().enumerate().take(CHANNELS) {
if channel.is_none() || channel == Some(c) { if channel.is_none() || channel == Some(c) {
match store.read_value::<ChannelConfig>(CHANNEL_CONFIG_KEY[c]) { match store.read_value::<ChannelConfig>(key) {
Ok(Some(config)) => { Ok(Some(config)) => {
config.apply(channels, c); config.apply(channels, c);
send_line(socket, b"{}"); send_line(socket, b"{}");
@ -312,7 +312,7 @@ impl Handler {
Err(e) => { Err(e) => {
error!("unable to load config from flash: {:?}", e); error!("unable to load config from flash: {:?}", e);
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e); let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
return Err(Error::FlashError); return Err(Error::Flash);
} }
} }
} }
@ -326,18 +326,18 @@ impl Handler {
channel: Option<usize>, channel: Option<usize>,
store: &mut FlashStore, store: &mut FlashStore,
) -> Result<Handler, Error> { ) -> Result<Handler, Error> {
for c in 0..CHANNELS { for (c, key) in CHANNEL_CONFIG_KEY.iter().enumerate().take(CHANNELS) {
let mut store_value_buf = [0u8; 256]; let mut store_value_buf = [0u8; 256];
if channel.is_none() || channel == Some(c) { if channel.is_none() || channel == Some(c) {
let config = ChannelConfig::new(channels, c); let config = ChannelConfig::new(channels, c);
match store.write_value(CHANNEL_CONFIG_KEY[c], &config, &mut store_value_buf) { match store.write_value(key, &config, &mut store_value_buf) {
Ok(()) => { Ok(()) => {
send_line(socket, b"{}"); send_line(socket, b"{}");
} }
Err(e) => { Err(e) => {
error!("unable to save channel {} config to flash: {:?}", c, e); error!("unable to save channel {} config to flash: {:?}", c, e);
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e); let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
return Err(Error::FlashError); return Err(Error::Flash);
} }
} }
} }
@ -408,7 +408,7 @@ impl Handler {
Err(e) => { Err(e) => {
error!("unable to serialize fan summary: {:?}", e); error!("unable to serialize fan summary: {:?}", e);
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e); let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
Err(Error::ReportError) Err(Error::Report)
} }
} }
} }
@ -457,7 +457,7 @@ impl Handler {
Err(e) => { Err(e) => {
error!("unable to serialize HWRev summary: {:?}", e); error!("unable to serialize HWRev summary: {:?}", e);
let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e); let _ = writeln!(socket, "{{\"error\":\"{:?}\"}}", e);
Err(Error::ReportError) Err(Error::Report)
} }
} }
} }

View File

@ -126,7 +126,7 @@ pub enum PwmPin {
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum CenterPoint { pub enum CenterPoint {
Vref, VRef,
Override(f32), Override(f32),
} }
@ -208,7 +208,7 @@ fn unsigned(input: &[u8]) -> IResult<&[u8], Result<u32, Error>> {
take_while1(is_digit)(input).map(|(input, digits)| { take_while1(is_digit)(input).map(|(input, digits)| {
let result = from_utf8(digits) let result = from_utf8(digits)
.map_err(|e| e.into()) .map_err(|e| e.into())
.and_then(|digits| u32::from_str_radix(digits, 10).map_err(|e| e.into())); .and_then(|digits| digits.parse::<u32>().map_err(|e| e.into()));
(input, result) (input, result)
}) })
} }
@ -216,7 +216,7 @@ fn unsigned(input: &[u8]) -> IResult<&[u8], Result<u32, Error>> {
fn float(input: &[u8]) -> IResult<&[u8], Result<f64, Error>> { fn float(input: &[u8]) -> IResult<&[u8], Result<f64, Error>> {
let (input, sign) = opt(is_a("-"))(input)?; let (input, sign) = opt(is_a("-"))(input)?;
let negative = sign.is_some(); let negative = sign.is_some();
let (input, digits) = take_while1(|c| is_digit(c) || c == '.' as u8)(input)?; let (input, digits) = take_while1(|c| is_digit(c) || c == b'.')(input)?;
let result = from_utf8(digits) let result = from_utf8(digits)
.map_err(|e| e.into()) .map_err(|e| e.into())
.and_then(|digits| f64::from_str_radix(digits, 10).map_err(|e| e.into())) .and_then(|digits| f64::from_str_radix(digits, 10).map_err(|e| e.into()))
@ -321,7 +321,7 @@ fn center_point(input: &[u8]) -> IResult<&[u8], Result<Command, Error>> {
let (input, _) = whitespace(input)?; let (input, _) = whitespace(input)?;
let (input, channel) = channel(input)?; let (input, channel) = channel(input)?;
let (input, _) = whitespace(input)?; let (input, _) = whitespace(input)?;
let (input, center) = alt((value(Ok(CenterPoint::Vref), tag("vref")), |input| { let (input, center) = alt((value(Ok(CenterPoint::VRef), tag("vref")), |input| {
let (input, value) = float(input)?; let (input, value) = float(input)?;
Ok(( Ok((
input, input,
@ -541,13 +541,13 @@ fn fan_curve(input: &[u8]) -> IResult<&[u8], Result<Command, Error>> {
let (input, k_b) = float(input)?; let (input, k_b) = float(input)?;
let (input, _) = whitespace(input)?; let (input, _) = whitespace(input)?;
let (input, k_c) = float(input)?; let (input, k_c) = float(input)?;
if k_a.is_ok() && k_b.is_ok() && k_c.is_ok() { if let (Ok(k_a), Ok(k_b), Ok(k_c)) = (k_a, k_b, k_c) {
Ok(( Ok((
input, input,
Ok(Command::FanCurve { Ok(Command::FanCurve {
k_a: k_a.unwrap() as f32, k_a: k_a as f32,
k_b: k_b.unwrap() as f32, k_b: k_b as f32,
k_c: k_c.unwrap() as f32, k_c: k_c as f32,
}), }),
)) ))
} else { } else {
@ -584,7 +584,7 @@ fn command(input: &[u8]) -> IResult<&[u8], Result<Command, Error>> {
impl Command { impl Command {
pub fn parse(input: &[u8]) -> Result<Self, Error> { pub fn parse(input: &[u8]) -> Result<Self, Error> {
match command(input) { match command(input) {
Ok((input_remain, result)) if input_remain.len() == 0 => result, Ok((input_remain, result)) if input_remain.is_empty() => result,
Ok((input_remain, _)) => Err(Error::UnexpectedInput(input_remain[0])), Ok((input_remain, _)) => Err(Error::UnexpectedInput(input_remain[0])),
Err(e) => Err(e.into()), Err(e) => Err(e.into()),
} }
@ -808,7 +808,7 @@ mod test {
command, command,
Ok(Command::CenterPoint { Ok(Command::CenterPoint {
channel: 1, channel: 1,
center: CenterPoint::Vref, center: CenterPoint::VRef,
}) })
); );
} }

View File

@ -95,9 +95,7 @@ impl FanCtrl {
return 0f32; return 0f32;
} }
let fan = self.fan.as_mut().unwrap(); let fan = self.fan.as_mut().unwrap();
let fan_pwm = fan_pwm let fan_pwm = fan_pwm.clamp(MIN_USER_FAN_PWM as u32, MAX_USER_FAN_PWM as u32);
.min(MAX_USER_FAN_PWM as u32)
.max(MIN_USER_FAN_PWM as u32);
let duty = scale_number( let duty = scale_number(
fan_pwm as f32, fan_pwm as f32,
self.hw_settings.min_fan_pwm, self.hw_settings.min_fan_pwm,

View File

@ -74,7 +74,7 @@ fn send_line(socket: &mut TcpSocket, data: &[u8]) -> bool {
data.len(), data.len(),
); );
} else { } else {
match socket.send_slice(&data) { match socket.send_slice(data) {
Ok(sent) if sent == data.len() => { Ok(sent) if sent == data.len() => {
let _ = socket.send_slice(b"\n"); let _ = socket.send_slice(b"\n");
// success // success
@ -119,24 +119,14 @@ fn main() -> ! {
let (pins, mut leds, mut eeprom, eth_pins, usb, fan, hwrev, hw_settings) = Pins::setup( let (pins, mut leds, mut eeprom, eth_pins, usb, fan, hwrev, hw_settings) = Pins::setup(
clocks, clocks,
dp.TIM1, (dp.TIM1, dp.TIM3, dp.TIM8),
dp.TIM3, (
dp.TIM8, dp.GPIOA, dp.GPIOB, dp.GPIOC, dp.GPIOD, dp.GPIOE, dp.GPIOF, dp.GPIOG,
dp.GPIOA, ),
dp.GPIOB,
dp.GPIOC,
dp.GPIOD,
dp.GPIOE,
dp.GPIOF,
dp.GPIOG,
dp.I2C1, dp.I2C1,
dp.SPI2, (dp.SPI2, dp.SPI4, dp.SPI5),
dp.SPI4,
dp.SPI5,
dp.ADC1, dp.ADC1,
dp.OTG_FS_GLOBAL, (dp.OTG_FS_GLOBAL, dp.OTG_FS_DEVICE, dp.OTG_FS_PWRCLK),
dp.OTG_FS_DEVICE,
dp.OTG_FS_PWRCLK,
); );
leds.r1.on(); leds.r1.on();
@ -148,8 +138,8 @@ fn main() -> ! {
let mut store = flash_store::store(dp.FLASH); let mut store = flash_store::store(dp.FLASH);
let mut channels = Channels::new(pins); let mut channels = Channels::new(pins);
for c in 0..CHANNELS { for (c, key) in CHANNEL_CONFIG_KEY.iter().enumerate().take(CHANNELS) {
match store.read_value::<ChannelConfig>(CHANNEL_CONFIG_KEY[c]) { match store.read_value::<ChannelConfig>(key) {
Ok(Some(config)) => config.apply(&mut channels, c), Ok(Some(config)) => config.apply(&mut channels, c),
Ok(None) => error!("flash config not found for channel {}", c), Ok(None) => error!("flash config not found for channel {}", c),
Err(e) => error!("unable to load config {} from flash: {:?}", c, e), Err(e) => error!("unable to load config {} from flash: {:?}", c, e),
@ -264,10 +254,10 @@ fn main() -> ! {
} }
// Apply new IPv4 address/gateway // Apply new IPv4 address/gateway
new_ipv4_config.take().map(|config| { if let Some(config) = new_ipv4_config.take() {
server.set_ipv4_config(config.clone()); server.set_ipv4_config(config.clone());
ipv4_config = config; ipv4_config = config;
}); };
// Update watchdog // Update watchdog
wd.feed(); wd.feed();

View File

@ -39,7 +39,7 @@ pub struct Controller {
impl Controller { impl Controller {
pub const fn new(parameters: Parameters) -> Controller { pub const fn new(parameters: Parameters) -> Controller {
Controller { Controller {
parameters: parameters, parameters,
target: 0.0, target: 0.0,
u1: 0.0, u1: 0.0,
x1: 0.0, x1: 0.0,

View File

@ -133,24 +133,24 @@ impl Pins {
/// Setup GPIO pins and configure MCU peripherals /// Setup GPIO pins and configure MCU peripherals
pub fn setup( pub fn setup(
clocks: Clocks, clocks: Clocks,
tim1: TIM1, (tim1, tim3, tim8): (TIM1, TIM3, TIM8),
tim3: TIM3, (gpioa, gpiob, gpioc, gpiod, gpioe, gpiof, gpiog): (
tim8: TIM8, GPIOA,
gpioa: GPIOA, GPIOB,
gpiob: GPIOB, GPIOC,
gpioc: GPIOC, GPIOD,
gpiod: GPIOD, GPIOE,
gpioe: GPIOE, GPIOF,
gpiof: GPIOF, GPIOG,
gpiog: GPIOG, ),
i2c1: I2C1, i2c1: I2C1,
spi2: SPI2, (spi2, spi4, spi5): (SPI2, SPI4, SPI5),
spi4: SPI4,
spi5: SPI5,
adc1: ADC1, adc1: ADC1,
otg_fs_global: OTG_FS_GLOBAL, (otg_fs_global, otg_fs_device, otg_fs_pwrclk): (
otg_fs_device: OTG_FS_DEVICE, OTG_FS_GLOBAL,
otg_fs_pwrclk: OTG_FS_PWRCLK, OTG_FS_DEVICE,
OTG_FS_PWRCLK,
),
) -> ( ) -> (
Self, Self,
Leds, Leds,
@ -175,7 +175,11 @@ impl Pins {
let pins_adc = Adc::adc1(adc1, true, Default::default()); let pins_adc = Adc::adc1(adc1, true, Default::default());
let pwm = PwmPins::setup( let pwm = PwmPins::setup(
clocks, tim1, tim3, gpioc.pc6, gpioc.pc7, gpioe.pe9, gpioe.pe11, gpioe.pe13, gpioe.pe14, clocks,
(tim1, tim3),
(gpioc.pc6, gpioc.pc7),
(gpioe.pe9, gpioe.pe11),
(gpioe.pe13, gpioe.pe14),
); );
let hwrev = HWRev::detect_hw_rev(&HWRevPins { let hwrev = HWRev::detect_hw_rev(&HWRevPins {
@ -188,7 +192,7 @@ impl Pins {
let (dac0_spi, dac0_sync) = Self::setup_dac0(clocks, spi4, gpioe.pe2, gpioe.pe4, gpioe.pe6); let (dac0_spi, dac0_sync) = Self::setup_dac0(clocks, spi4, gpioe.pe2, gpioe.pe4, gpioe.pe6);
let mut shdn0 = gpioe.pe10.into_push_pull_output(); let mut shdn0 = gpioe.pe10.into_push_pull_output();
let _ = shdn0.set_low(); shdn0.set_low();
let vref0_pin = if hwrev.major > 2 { let vref0_pin = if hwrev.major > 2 {
Channel0VRef::Analog(gpioa.pa0.into_analog()) Channel0VRef::Analog(gpioa.pa0.into_analog())
} else { } else {
@ -209,7 +213,7 @@ impl Pins {
let (dac1_spi, dac1_sync) = Self::setup_dac1(clocks, spi5, gpiof.pf7, gpiof.pf6, gpiof.pf9); let (dac1_spi, dac1_sync) = Self::setup_dac1(clocks, spi5, gpiof.pf7, gpiof.pf6, gpiof.pf9);
let mut shdn1 = gpioe.pe15.into_push_pull_output(); let mut shdn1 = gpioe.pe15.into_push_pull_output();
let _ = shdn1.set_low(); shdn1.set_low();
let vref1_pin = if hwrev.major > 2 { let vref1_pin = if hwrev.major > 2 {
Channel1VRef::Analog(gpioa.pa3.into_analog()) Channel1VRef::Analog(gpioa.pa3.into_analog())
} else { } else {
@ -354,14 +358,10 @@ pub struct PwmPins {
impl PwmPins { impl PwmPins {
fn setup<M1, M2, M3, M4, M5, M6>( fn setup<M1, M2, M3, M4, M5, M6>(
clocks: Clocks, clocks: Clocks,
tim1: TIM1, (tim1, tim3): (TIM1, TIM3),
tim3: TIM3, (max_v0, max_v1): (PC6<M1>, PC7<M2>),
max_v0: PC6<M1>, (max_i_pos0, max_i_pos1): (PE9<M3>, PE11<M4>),
max_v1: PC7<M2>, (max_i_neg0, max_i_neg1): (PE13<M5>, PE14<M6>),
max_i_pos0: PE9<M3>,
max_i_pos1: PE11<M4>,
max_i_neg0: PE13<M5>,
max_i_neg1: PE14<M6>,
) -> PwmPins { ) -> PwmPins {
let freq = 20u32.khz(); let freq = 20u32.khz();

View File

@ -103,15 +103,10 @@ impl<'a, 'b, S: Default> Server<'a, 'b, S> {
fn set_ipv4_address(&mut self, ipv4_address: Ipv4Cidr) { fn set_ipv4_address(&mut self, ipv4_address: Ipv4Cidr) {
self.net.update_ip_addrs(|addrs| { self.net.update_ip_addrs(|addrs| {
for addr in addrs.iter_mut() { for addr in addrs.iter_mut() {
match addr { if let IpCidr::Ipv4(_) = addr {
IpCidr::Ipv4(_) => { *addr = IpCidr::Ipv4(ipv4_address);
*addr = IpCidr::Ipv4(ipv4_address); // done
// done break;
break;
}
_ => {
// skip
}
} }
} }
}); });

View File

@ -77,12 +77,9 @@ impl Session {
for (i, b) in buf.iter().enumerate() { for (i, b) in buf.iter().enumerate() {
buf_bytes = i + 1; buf_bytes = i + 1;
let line = self.reader.feed(*b); let line = self.reader.feed(*b);
match line { if let Some(line) = line {
Some(line) => { let command = Command::parse(line);
let command = Command::parse(&line); return (buf_bytes, command.into());
return (buf_bytes, command.into());
}
None => {}
} }
} }
(buf_bytes, SessionInput::Nothing) (buf_bytes, SessionInput::Nothing)