This commit is contained in:
Astro 2019-09-14 21:40:49 +02:00
parent b969f5c057
commit ee4d24de6a
5 changed files with 19 additions and 5 deletions

View File

@ -2,7 +2,7 @@ use embedded_hal::digital::v2::OutputPin;
use embedded_hal::blocking::spi::Transfer; use embedded_hal::blocking::spi::Transfer;
use super::checksum::{ChecksumMode, Checksum}; use super::checksum::{ChecksumMode, Checksum};
use super::AdcError; use super::AdcError;
use super::{regs, regs::RegisterData, Input, RefSource}; use super::{regs, regs::RegisterData, Input};
/// AD7172-2 implementation /// AD7172-2 implementation
/// ///

View File

@ -63,16 +63,19 @@ macro_rules! def_reg {
macro_rules! reg_bit { macro_rules! reg_bit {
($getter: ident, $byte: expr, $bit: expr, $doc: expr) => { ($getter: ident, $byte: expr, $bit: expr, $doc: expr) => {
#[allow(unused)]
#[doc = $doc] #[doc = $doc]
pub fn $getter(&self) -> bool { pub fn $getter(&self) -> bool {
self.0[$byte].get_bit($bit) self.0[$byte].get_bit($bit)
} }
}; };
($getter: ident, $setter: ident, $byte: expr, $bit: expr, $doc: expr) => { ($getter: ident, $setter: ident, $byte: expr, $bit: expr, $doc: expr) => {
#[allow(unused)]
#[doc = $doc] #[doc = $doc]
pub fn $getter(&self) -> bool { pub fn $getter(&self) -> bool {
self.0[$byte].get_bit($bit) self.0[$byte].get_bit($bit)
} }
#[allow(unused)]
#[doc = $doc] #[doc = $doc]
pub fn $setter(&mut self, value: bool) { pub fn $setter(&mut self, value: bool) {
self.0[$byte].set_bit($bit, value); self.0[$byte].set_bit($bit, value);
@ -82,32 +85,38 @@ macro_rules! reg_bit {
macro_rules! reg_bits { macro_rules! reg_bits {
($getter: ident, $byte: expr, $bits: expr, $doc: expr) => { ($getter: ident, $byte: expr, $bits: expr, $doc: expr) => {
#[allow(unused)]
#[doc = $doc] #[doc = $doc]
pub fn $getter(&self) -> u8 { pub fn $getter(&self) -> u8 {
self.0[$byte].get_bits($bits) self.0[$byte].get_bits($bits)
} }
}; };
($getter: ident, $setter: ident, $byte: expr, $bits: expr, $doc: expr) => { ($getter: ident, $setter: ident, $byte: expr, $bits: expr, $doc: expr) => {
#[allow(unused)]
#[doc = $doc] #[doc = $doc]
pub fn $getter(&self) -> u8 { pub fn $getter(&self) -> u8 {
self.0[$byte].get_bits($bits) self.0[$byte].get_bits($bits)
} }
#[allow(unused)]
#[doc = $doc] #[doc = $doc]
pub fn $setter(&mut self, value: u8) { pub fn $setter(&mut self, value: u8) {
self.0[$byte].set_bits($bits, value); self.0[$byte].set_bits($bits, value);
} }
}; };
($getter: ident, $byte: expr, $bits: expr, $ty: ty, $doc: expr) => { ($getter: ident, $byte: expr, $bits: expr, $ty: ty, $doc: expr) => {
#[allow(unused)]
#[doc = $doc] #[doc = $doc]
pub fn $getter(&self) -> $ty { pub fn $getter(&self) -> $ty {
self.0[$byte].get_bits($bits) as $ty self.0[$byte].get_bits($bits) as $ty
} }
}; };
($getter: ident, $setter: ident, $byte: expr, $bits: expr, $ty: ty, $doc: expr) => { ($getter: ident, $setter: ident, $byte: expr, $bits: expr, $ty: ty, $doc: expr) => {
#[allow(unused)]
#[doc = $doc] #[doc = $doc]
pub fn $getter(&self) -> $ty { pub fn $getter(&self) -> $ty {
self.0[$byte].get_bits($bits).into() self.0[$byte].get_bits($bits).into()
} }
#[allow(unused)]
#[doc = $doc] #[doc = $doc]
pub fn $setter(&mut self, value: $ty) { pub fn $setter(&mut self, value: $ty) {
self.0[$byte].set_bits($bits, value as u8); self.0[$byte].set_bits($bits, value as u8);
@ -156,11 +165,13 @@ impl channel::Data {
reg_bits!(setup, set_setup, 0, 4..=5, "Setup number"); reg_bits!(setup, set_setup, 0, 4..=5, "Setup number");
/// Which input is connected to positive input of this channel /// Which input is connected to positive input of this channel
#[allow(unused)]
pub fn a_in_pos(&self) -> Input { pub fn a_in_pos(&self) -> Input {
((self.0[0].get_bits(0..=1) << 3) | ((self.0[0].get_bits(0..=1) << 3) |
self.0[1].get_bits(5..=7)).into() self.0[1].get_bits(5..=7)).into()
} }
/// Set which input is connected to positive input of this channel /// Set which input is connected to positive input of this channel
#[allow(unused)]
pub fn set_a_in_pos(&mut self, value: Input) { pub fn set_a_in_pos(&mut self, value: Input) {
let value = value as u8; let value = value as u8;
self.0[0].set_bits(0..=1, value >> 3); self.0[0].set_bits(0..=1, value >> 3);
@ -207,11 +218,13 @@ impl filt_con::Data {
def_reg!(Offset, u8, offset, 0x30, 3); def_reg!(Offset, u8, offset, 0x30, 3);
impl offset::Data { impl offset::Data {
#[allow(unused)]
pub fn offset(&self) -> u32 { pub fn offset(&self) -> u32 {
(u32::from(self.0[0]) << 16) | (u32::from(self.0[0]) << 16) |
(u32::from(self.0[1]) << 8) | (u32::from(self.0[1]) << 8) |
u32::from(self.0[2]) u32::from(self.0[2])
} }
#[allow(unused)]
pub fn set_offset(&mut self, value: u32) { pub fn set_offset(&mut self, value: u32) {
self.0[0] = (value >> 16) as u8; self.0[0] = (value >> 16) as u8;
self.0[1] = (value >> 8) as u8; self.0[1] = (value >> 8) as u8;
@ -221,11 +234,13 @@ impl offset::Data {
def_reg!(Gain, u8, gain, 0x38, 3); def_reg!(Gain, u8, gain, 0x38, 3);
impl gain::Data { impl gain::Data {
#[allow(unused)]
pub fn gain(&self) -> u32 { pub fn gain(&self) -> u32 {
(u32::from(self.0[0]) << 16) | (u32::from(self.0[0]) << 16) |
(u32::from(self.0[1]) << 8) | (u32::from(self.0[1]) << 8) |
u32::from(self.0[2]) u32::from(self.0[2])
} }
#[allow(unused)]
pub fn set_gain(&mut self, value: u32) { pub fn set_gain(&mut self, value: u32) {
self.0[0] = (value >> 16) as u8; self.0[0] = (value >> 16) as u8;
self.0[1] = (value >> 8) as u8; self.0[1] = (value >> 8) as u8;

View File

@ -5,7 +5,7 @@ use nom::{
bytes::complete::{tag, take_while1}, bytes::complete::{tag, take_while1},
character::{is_digit, complete::char}, character::{is_digit, complete::char},
combinator::{map, value}, combinator::{map, value},
sequence::{preceded, tuple, Tuple}, sequence::preceded,
multi::fold_many1, multi::fold_many1,
error::ErrorKind, error::ErrorKind,
}; };

View File

@ -2,7 +2,7 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
use cortex_m_rt::{entry, heap_start}; use cortex_m_rt::entry;
use core::fmt::{self, Write}; use core::fmt::{self, Write};
use smoltcp::time::Instant; use smoltcp::time::Instant;
use smoltcp::wire::{IpCidr, IpAddress, EthernetAddress}; use smoltcp::wire::{IpCidr, IpAddress, EthernetAddress};
@ -212,7 +212,7 @@ fn main() -> ! {
// ADC input // ADC input
adc.data_ready() adc.data_ready()
.unwrap_or_else(|e| { .unwrap_or_else(|e| {
writeln!(stdout, "ADC error: {:?}", e); writeln!(stdout, "ADC error: {:?}", e).unwrap();
None None
}).map(|channel| { }).map(|channel| {
let data = adc.read_data().unwrap(); let data = adc.read_data().unwrap();

View File

@ -67,7 +67,6 @@ impl fmt::Display for ReportMode {
ReportMode::Off => "off", ReportMode::Off => "off",
ReportMode::Once => "once", ReportMode::Once => "once",
ReportMode::Continuous => "continuous", ReportMode::Continuous => "continuous",
_ => "<INVALID>",
}.fmt(fmt) }.fmt(fmt)
} }
} }