Merge remote-tracking branch 'origin/master' into feature/adc-dac-io-macros

* origin/master:
  more nightly clippy lints
  clippy lints
  gha: clippy-check
  build(deps): bump paste from 1.0.2 to 1.0.3
  build(deps): bump panic-semihosting from 0.5.4 to 0.5.6
This commit is contained in:
Robert Jördens 2020-11-30 14:48:43 +01:00
commit c72f959933
7 changed files with 66 additions and 102 deletions

View File

@ -17,7 +17,7 @@ jobs:
- uses: actions-rs/toolchain@v1 - uses: actions-rs/toolchain@v1
with: with:
profile: minimal profile: minimal
toolchain: stable toolchain: nightly
override: true override: true
components: rustfmt components: rustfmt
- name: cargo fmt --check - name: cargo fmt --check
@ -33,15 +33,14 @@ jobs:
- uses: actions-rs/toolchain@v1 - uses: actions-rs/toolchain@v1
with: with:
profile: minimal profile: minimal
toolchain: stable toolchain: nightly
target: thumbv7em-none-eabihf target: thumbv7em-none-eabihf
override: true override: true
components: clippy components: clippy
- name: cargo clippy - uses: actions-rs/clippy-check@v1
uses: actions-rs/cargo@v1
continue-on-error: true continue-on-error: true
with: with:
command: clippy token: ${{ secrets.GITHUB_TOKEN }}
compile: compile:
runs-on: ubuntu-latest runs-on: ubuntu-latest

8
Cargo.lock generated
View File

@ -343,9 +343,9 @@ checksum = "de96540e0ebde571dc55c73d60ef407c653844e6f9a1e2fdbd40c07b9252d812"
[[package]] [[package]]
name = "panic-semihosting" name = "panic-semihosting"
version = "0.5.4" version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aed16eb761d0ee9161dd1319cb38c8007813b20f9720a5a682b283e7b8cdfe58" checksum = "c3d55dedd501dfd02514646e0af4d7016ce36bc12ae177ef52056989966a1eec"
dependencies = [ dependencies = [
"cortex-m", "cortex-m",
"cortex-m-semihosting", "cortex-m-semihosting",
@ -353,9 +353,9 @@ dependencies = [
[[package]] [[package]]
name = "paste" name = "paste"
version = "1.0.2" version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba7ae1a2180ed02ddfdb5ab70c70d596a26dd642e097bb6fe78b1bde8588ed97" checksum = "7151b083b0664ed58ed669fcdd92f01c3d2fdbf10af4931a301474950b52bfa9"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"

View File

@ -127,30 +127,27 @@ where
system_clock_multiplier: 1, system_clock_multiplier: 1,
}; };
ad9959.io_update.set_low().or_else(|_| Err(Error::Pin))?; ad9959.io_update.set_low().or(Err(Error::Pin))?;
// Reset the AD9959 // Reset the AD9959
reset_pin.set_high().or_else(|_| Err(Error::Pin))?; reset_pin.set_high().or(Err(Error::Pin))?;
// Delay for a clock cycle to allow the device to reset. // Delay for a clock cycle to allow the device to reset.
ad9959 ad9959
.delay .delay
.delay_ms((1000.0 / clock_frequency as f32) as u8); .delay_ms((1000.0 / clock_frequency as f32) as u8);
reset_pin.set_low().or_else(|_| Err(Error::Pin))?; reset_pin.set_low().or(Err(Error::Pin))?;
ad9959 ad9959
.interface .interface
.configure_mode(Mode::SingleBitTwoWire) .configure_mode(Mode::SingleBitTwoWire)
.map_err(|_| Error::Interface)?; .or(Err(Error::Interface))?;
// Program the interface configuration in the AD9959. Default to all channels enabled. // Program the interface configuration in the AD9959. Default to all channels enabled.
let mut csr: [u8; 1] = [0xF0]; let mut csr: [u8; 1] = [0xF0];
csr[0].set_bits(1..3, desired_mode as u8); csr[0].set_bits(1..3, desired_mode as u8);
ad9959 ad9959.write(Register::CSR, &csr)?;
.interface
.write(Register::CSR as u8, &csr)
.map_err(|_| Error::Interface)?;
// Latch the configuration registers to make them active. // Latch the configuration registers to make them active.
ad9959.latch_configuration()?; ad9959.latch_configuration()?;
@ -158,14 +155,11 @@ where
ad9959 ad9959
.interface .interface
.configure_mode(desired_mode) .configure_mode(desired_mode)
.map_err(|_| Error::Interface)?; .or(Err(Error::Interface))?;
// Read back the CSR to ensure it specifies the mode correctly. // Read back the CSR to ensure it specifies the mode correctly.
let mut updated_csr: [u8; 1] = [0]; let mut updated_csr: [u8; 1] = [0];
ad9959 ad9959.read(Register::CSR, &mut updated_csr)?;
.interface
.read(Register::CSR as u8, &mut updated_csr)
.map_err(|_| Error::Interface)?;
if updated_csr[0] != csr[0] { if updated_csr[0] != csr[0] {
return Err(Error::Check); return Err(Error::Check);
} }
@ -175,14 +169,26 @@ where
Ok(ad9959) Ok(ad9959)
} }
fn read(&mut self, reg: Register, data: &mut [u8]) -> Result<(), Error> {
self.interface
.read(reg as u8, data)
.or(Err(Error::Interface))
}
fn write(&mut self, reg: Register, data: &[u8]) -> Result<(), Error> {
self.interface
.write(reg as u8, data)
.or(Err(Error::Interface))
}
/// Latch the DDS configuration to ensure it is active on the output channels. /// Latch the DDS configuration to ensure it is active on the output channels.
fn latch_configuration(&mut self) -> Result<(), Error> { fn latch_configuration(&mut self) -> Result<(), Error> {
self.io_update.set_high().or_else(|_| Err(Error::Pin))?; self.io_update.set_high().or(Err(Error::Pin))?;
// The SYNC_CLK is 1/4 the system clock frequency. The IO_UPDATE pin must be latched for one // The SYNC_CLK is 1/4 the system clock frequency. The IO_UPDATE pin must be latched for one
// full SYNC_CLK pulse to register. For safety, we latch for 5 here. // full SYNC_CLK pulse to register. For safety, we latch for 5 here.
self.delay self.delay
.delay_ms((5000.0 / self.system_clock_frequency()) as u8); .delay_ms((5000.0 / self.system_clock_frequency()) as u8);
self.io_update.set_low().or_else(|_| Err(Error::Pin))?; self.io_update.set_low().or(Err(Error::Pin))?;
Ok(()) Ok(())
} }
@ -202,7 +208,7 @@ where
) -> Result<f64, Error> { ) -> Result<f64, Error> {
self.reference_clock_frequency = reference_clock_frequency; self.reference_clock_frequency = reference_clock_frequency;
if multiplier != 1 && (multiplier > 20 || multiplier < 4) { if multiplier != 1 && !(4..=20).contains(&multiplier) {
return Err(Error::Bounds); return Err(Error::Bounds);
} }
@ -214,17 +220,13 @@ where
// TODO: Update / disable any enabled channels? // TODO: Update / disable any enabled channels?
let mut fr1: [u8; 3] = [0, 0, 0]; let mut fr1: [u8; 3] = [0, 0, 0];
self.interface self.read(Register::FR1, &mut fr1)?;
.read(Register::FR1 as u8, &mut fr1)
.map_err(|_| Error::Interface)?;
fr1[0].set_bits(2..=6, multiplier); fr1[0].set_bits(2..=6, multiplier);
let vco_range = frequency > 255e6; let vco_range = frequency > 255e6;
fr1[0].set_bit(7, vco_range); fr1[0].set_bit(7, vco_range);
self.interface self.write(Register::FR1, &fr1)?;
.write(Register::FR1 as u8, &fr1)
.map_err(|_| Error::Interface)?;
self.system_clock_multiplier = multiplier; self.system_clock_multiplier = multiplier;
Ok(self.system_clock_frequency()) Ok(self.system_clock_frequency())
@ -238,9 +240,7 @@ where
/// Get the current reference clock multiplier. /// Get the current reference clock multiplier.
pub fn get_reference_clock_multiplier(&mut self) -> Result<u8, Error> { pub fn get_reference_clock_multiplier(&mut self) -> Result<u8, Error> {
let mut fr1: [u8; 3] = [0, 0, 0]; let mut fr1: [u8; 3] = [0, 0, 0];
self.interface self.read(Register::FR1, &mut fr1)?;
.read(Register::FR1 as u8, &mut fr1)
.map_err(|_| Error::Interface)?;
Ok(fr1[0].get_bits(2..=6) as u8) Ok(fr1[0].get_bits(2..=6) as u8)
} }
@ -254,46 +254,34 @@ where
/// True if the self test succeeded. False otherwise. /// True if the self test succeeded. False otherwise.
pub fn self_test(&mut self) -> Result<bool, Error> { pub fn self_test(&mut self) -> Result<bool, Error> {
let mut csr: [u8; 1] = [0]; let mut csr: [u8; 1] = [0];
self.interface self.read(Register::CSR, &mut csr)?;
.read(Register::CSR as u8, &mut csr)
.map_err(|_| Error::Interface)?;
let old_csr = csr[0]; let old_csr = csr[0];
// Enable all channels. // Enable all channels.
csr[0].set_bits(4..8, 0xF); csr[0].set_bits(4..8, 0xF);
self.interface self.write(Register::CSR, &csr)?;
.write(Register::CSR as u8, &csr)
.map_err(|_| Error::Interface)?;
// Read back the enable. // Read back the enable.
csr[0] = 0; csr[0] = 0;
self.interface self.read(Register::CSR, &mut csr)?;
.read(Register::CSR as u8, &mut csr)
.map_err(|_| Error::Interface)?;
if csr[0].get_bits(4..8) != 0xF { if csr[0].get_bits(4..8) != 0xF {
return Ok(false); return Ok(false);
} }
// Clear all channel enables. // Clear all channel enables.
csr[0].set_bits(4..8, 0x0); csr[0].set_bits(4..8, 0x0);
self.interface self.write(Register::CSR, &csr)?;
.write(Register::CSR as u8, &csr)
.map_err(|_| Error::Interface)?;
// Read back the enable. // Read back the enable.
csr[0] = 0xFF; csr[0] = 0xFF;
self.interface self.read(Register::CSR, &mut csr)?;
.read(Register::CSR as u8, &mut csr)
.map_err(|_| Error::Interface)?;
if csr[0].get_bits(4..8) != 0 { if csr[0].get_bits(4..8) != 0 {
return Ok(false); return Ok(false);
} }
// Restore the CSR. // Restore the CSR.
csr[0] = old_csr; csr[0] = old_csr;
self.interface self.write(Register::CSR, &csr)?;
.write(Register::CSR as u8, &csr)
.map_err(|_| Error::Interface)?;
Ok(true) Ok(true)
} }
@ -307,13 +295,9 @@ where
/// Enable an output channel. /// Enable an output channel.
pub fn enable_channel(&mut self, channel: Channel) -> Result<(), Error> { pub fn enable_channel(&mut self, channel: Channel) -> Result<(), Error> {
let mut csr: [u8; 1] = [0]; let mut csr: [u8; 1] = [0];
self.interface self.read(Register::CSR, &mut csr)?;
.read(Register::CSR as u8, &mut csr)
.map_err(|_| Error::Interface)?;
csr[0].set_bit(channel as usize + 4, true); csr[0].set_bit(channel as usize + 4, true);
self.interface self.write(Register::CSR, &csr)?;
.write(Register::CSR as u8, &csr)
.map_err(|_| Error::Interface)?;
Ok(()) Ok(())
} }
@ -321,13 +305,9 @@ where
/// Disable an output channel. /// Disable an output channel.
pub fn disable_channel(&mut self, channel: Channel) -> Result<(), Error> { pub fn disable_channel(&mut self, channel: Channel) -> Result<(), Error> {
let mut csr: [u8; 1] = [0]; let mut csr: [u8; 1] = [0];
self.interface self.read(Register::CSR, &mut csr)?;
.read(Register::CSR as u8, &mut csr)
.map_err(|_| Error::Interface)?;
csr[0].set_bit(channel as usize + 4, false); csr[0].set_bit(channel as usize + 4, false);
self.interface self.write(Register::CSR, &csr)?;
.write(Register::CSR as u8, &csr)
.map_err(|_| Error::Interface)?;
Ok(()) Ok(())
} }
@ -335,9 +315,7 @@ where
/// Determine if an output channel is enabled. /// Determine if an output channel is enabled.
pub fn is_enabled(&mut self, channel: Channel) -> Result<bool, Error> { pub fn is_enabled(&mut self, channel: Channel) -> Result<bool, Error> {
let mut csr: [u8; 1] = [0; 1]; let mut csr: [u8; 1] = [0; 1];
self.interface self.read(Register::CSR, &mut csr)?;
.read(Register::CSR as u8, &mut csr)
.map_err(|_| Error::Interface)?;
Ok(csr[0].get_bit(channel as usize + 4)) Ok(csr[0].get_bit(channel as usize + 4))
} }
@ -357,28 +335,20 @@ where
// Disable all other outputs so that we can update the configuration register of only the // Disable all other outputs so that we can update the configuration register of only the
// specified channel. // specified channel.
let mut csr: [u8; 1] = [0]; let mut csr: [u8; 1] = [0];
self.interface self.read(Register::CSR, &mut csr)?;
.read(Register::CSR as u8, &mut csr)
.map_err(|_| Error::Interface)?;
let mut new_csr = csr; let mut new_csr = csr;
new_csr[0].set_bits(4..8, 0); new_csr[0].set_bits(4..8, 0);
new_csr[0].set_bit(4 + channel as usize, true); new_csr[0].set_bit(4 + channel as usize, true);
self.interface self.write(Register::CSR, &new_csr)?;
.write(Register::CSR as u8, &new_csr)
.map_err(|_| Error::Interface)?;
self.interface self.write(register, &data)?;
.write(register as u8, &data)
.map_err(|_| Error::Interface)?;
// Latch the configuration and restore the previous CSR. Note that the re-enable of the // Latch the configuration and restore the previous CSR. Note that the re-enable of the
// channel happens immediately, so the CSR update does not need to be latched. // channel happens immediately, so the CSR update does not need to be latched.
self.latch_configuration()?; self.latch_configuration()?;
self.interface self.write(Register::CSR, &csr)?;
.write(Register::CSR as u8, &csr)
.map_err(|_| Error::Interface)?;
Ok(()) Ok(())
} }
@ -398,27 +368,18 @@ where
// Disable all other channels in the CSR so that we can read the configuration register of // Disable all other channels in the CSR so that we can read the configuration register of
// only the desired channel. // only the desired channel.
let mut csr: [u8; 1] = [0]; let mut csr: [u8; 1] = [0];
self.interface self.read(Register::CSR, &mut csr)?;
.read(Register::CSR as u8, &mut csr)
.map_err(|_| Error::Interface)?;
let mut new_csr = csr; let mut new_csr = csr;
new_csr[0].set_bits(4..8, 0); new_csr[0].set_bits(4..8, 0);
new_csr[0].set_bit(4 + channel as usize, true); new_csr[0].set_bit(4 + channel as usize, true);
self.interface self.write(Register::CSR, &new_csr)?;
.write(Register::CSR as u8, &new_csr) self.read(register, &mut data)?;
.map_err(|_| Error::Interface)?;
self.interface
.read(register as u8, &mut data)
.map_err(|_| Error::Interface)?;
// Restore the previous CSR. Note that the re-enable of the channel happens immediately, so // Restore the previous CSR. Note that the re-enable of the channel happens immediately, so
// the CSR update does not need to be latched. // the CSR update does not need to be latched.
self.interface self.write(Register::CSR, &csr)?;
.write(Register::CSR as u8, &csr)
.map_err(|_| Error::Interface)?;
Ok(()) Ok(())
} }
@ -477,7 +438,7 @@ where
channel: Channel, channel: Channel,
amplitude: f32, amplitude: f32,
) -> Result<f32, Error> { ) -> Result<f32, Error> {
if amplitude < 0.0 || amplitude > 1.0 { if !(0.0..=1.0).contains(&amplitude) {
return Err(Error::Bounds); return Err(Error::Bounds);
} }

View File

@ -140,6 +140,7 @@ macro_rules! route_request {
match $request.attribute { match $request.attribute {
$( $(
$read_attribute => { $read_attribute => {
#[allow(clippy::redundant_closure_call)]
let value = match $getter() { let value = match $getter() {
Ok(data) => data, Ok(data) => data,
Err(_) => return server::Response::error($request.attribute, Err(_) => return server::Response::error($request.attribute,
@ -168,6 +169,7 @@ macro_rules! route_request {
"Failed to decode value"), "Failed to decode value"),
}; };
#[allow(clippy::redundant_closure_call)]
match $setter(new_value) { match $setter(new_value) {
Ok(_) => server::Response::success($request.attribute, &$request.value), Ok(_) => server::Response::success($request.attribute, &$request.value),
Err(_) => server::Response::error($request.attribute, Err(_) => server::Response::error($request.attribute,
@ -677,7 +679,7 @@ const APP: () = {
dp.ETHERNET_MTL, dp.ETHERNET_MTL,
dp.ETHERNET_DMA, dp.ETHERNET_DMA,
&mut DES_RING, &mut DES_RING,
mac_addr.clone(), mac_addr,
ccdr.peripheral.ETH1MAC, ccdr.peripheral.ETH1MAC,
&ccdr.clocks, &ccdr.clocks,
) )
@ -925,10 +927,12 @@ const APP: () = {
} }
}), }),
"stabilizer/afe0/gain": afe::Gain, (|gain| { "stabilizer/afe0/gain": afe::Gain, (|gain| {
Ok::<(), ()>(c.resources.afes.0.set_gain(gain)) c.resources.afes.0.set_gain(gain);
Ok::<(), ()>(())
}), }),
"stabilizer/afe1/gain": afe::Gain, (|gain| { "stabilizer/afe1/gain": afe::Gain, (|gain| {
Ok::<(), ()>(c.resources.afes.1.set_gain(gain)) c.resources.afes.1.set_gain(gain);
Ok::<(), ()>(())
}) })
] ]
) )
@ -940,7 +944,7 @@ const APP: () = {
&mut sockets, &mut sockets,
net::time::Instant::from_millis(time as i64), net::time::Instant::from_millis(time as i64),
) { ) {
Ok(changed) => changed == false, Ok(changed) => !changed,
Err(net::Error::Unrecognized) => true, Err(net::Error::Unrecognized) => true,
Err(e) => { Err(e) => {
info!("iface poll error: {:?}", e); info!("iface poll error: {:?}", e);

View File

@ -19,7 +19,7 @@ pub trait AttenuatorInterface {
channel: Channel, channel: Channel,
attenuation: f32, attenuation: f32,
) -> Result<f32, Error> { ) -> Result<f32, Error> {
if attenuation > 31.5 || attenuation < 0.0 { if !(0.0..=31.5).contains(&attenuation) {
return Err(Error::Bounds); return Err(Error::Bounds);
} }

View File

@ -17,7 +17,7 @@ const ATT_RST_N_PIN: u8 = 8 + 5;
const ATT_LE3_PIN: u8 = 8 + 3; const ATT_LE3_PIN: u8 = 8 + 3;
const ATT_LE2_PIN: u8 = 8 + 2; const ATT_LE2_PIN: u8 = 8 + 2;
const ATT_LE1_PIN: u8 = 8 + 1; const ATT_LE1_PIN: u8 = 8 + 1;
const ATT_LE0_PIN: u8 = 8 + 0; const ATT_LE0_PIN: u8 = 8;
#[derive(Debug, Copy, Clone)] #[derive(Debug, Copy, Clone)]
pub enum Error { pub enum Error {

View File

@ -89,7 +89,7 @@ impl Response {
/// Args: /// Args:
/// * `attrbute` - The attribute of the success. /// * `attrbute` - The attribute of the success.
/// * `value` - The value of the attribute. /// * `value` - The value of the attribute.
pub fn success<'a, 'b>(attribute: &'a str, value: &'b str) -> Self { pub fn success(attribute: &str, value: &str) -> Self {
let mut res = Self { let mut res = Self {
code: 200, code: 200,
attribute: String::from(attribute), attribute: String::from(attribute),
@ -106,7 +106,7 @@ impl Response {
/// Args: /// Args:
/// * `attrbute` - The attribute of the success. /// * `attrbute` - The attribute of the success.
/// * `message` - The message denoting the error. /// * `message` - The message denoting the error.
pub fn error<'a, 'b>(attribute: &'a str, message: &'b str) -> Self { pub fn error(attribute: &str, message: &str) -> Self {
let mut res = Self { let mut res = Self {
code: 400, code: 400,
attribute: String::from(attribute), attribute: String::from(attribute),
@ -123,7 +123,7 @@ impl Response {
/// Args: /// Args:
/// * `attrbute` - The attribute of the success. /// * `attrbute` - The attribute of the success.
/// * `message` - The message denoting the status. /// * `message` - The message denoting the status.
pub fn custom<'a>(code: i32, message: &'a str) -> Self { pub fn custom(code: i32, message: &str) -> Self {
let mut res = Self { let mut res = Self {
code, code,
attribute: String::from(""), attribute: String::from(""),