Skip to content

Commit

Permalink
misc: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
rrbutani committed Oct 9, 2019
1 parent 63dc51f commit 5f71438
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 71 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ tui = "0.6.2"

[[example]]
name = "tui"
path = "bins/tui/main.rs"
path = "examples/tui/main.rs"
required-features = ["shims"]
2 changes: 1 addition & 1 deletion examples/tui/main.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fn main() { }
fn main() {}
3 changes: 1 addition & 2 deletions src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
//! implementation of Control; instead the 'shim' is an instruction level
//! simulator that lives in the [interp module](../interp).
use super::{Addr, Word};
use super::error::Error;
use super::{Addr, Word};
use core::future::Future;

pub const MAX_BREAKPOINTS: usize = 10;
Expand Down Expand Up @@ -105,7 +105,6 @@ pub trait Control {
fn get_pwm_config();
fn get_clock();


// So with some of these functions that are basically straight wrappers over their Memory/Peripheral trait counterparts,
// we have a bit of a choice. We can make Control a super trait of those traits so that we can have default impls of said
// functions or we can make the implementor of Control manually wrap those functions.
Expand Down
17 changes: 11 additions & 6 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use super::peripherals::gpio::{
GpioMiscError, /* GpioInterruptRegisterError */
GpioReadError, GpioReadErrors, GpioWriteError, GpioWriteErrors,
};
use super::Word;
use super::peripherals::gpio::{GpioReadError, GpioWriteError, GpioReadErrors, GpioWriteErrors, GpioMiscError/* GpioInterruptRegisterError */};


// Lots of open questions here:
// - should this be implementation defined?
Expand All @@ -17,8 +19,8 @@ pub enum Error {
InvalidGpioRead(GpioReadError),
InvalidGpioReads(GpioReadErrors),
GpioMiscError(GpioMiscError), // Unclear if we want to expose these kind of errors in the Control interface or just make the interpreter deal with them (probably expose...) (TODO)
// InvalidGpioInterruptRegistration(GpioInterruptRegisterError),
///// TODO: finish
// InvalidGpioInterruptRegistration(GpioInterruptRegisterError),
///// TODO: finish
}

// TODO: automate away with a proc macro (this is a common enough pattern...)
Expand Down Expand Up @@ -53,7 +55,10 @@ err!(GpioWriteError, Error::InvalidGpioWrite);
pub enum ErrorHandlingStrategy {
DefaultValue(Word),
Silent,
FireException { interrupt_vector_table_number: u8, payload: Option<Word> },
FireException {
interrupt_vector_table_number: u8,
payload: Option<Word>,
},
}

impl From<Error> for ErrorHandlingStrategy {
Expand All @@ -68,7 +73,7 @@ impl From<Error> for ErrorHandlingStrategy {
InvalidGpioReads(err) => {
unimplemented!()
// TODO: set all the mismatched bits to 0, etc.
},
}
GpioMiscError(_) => Silent,
}
}
Expand Down
1 change: 1 addition & 0 deletions src/interp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

75 changes: 39 additions & 36 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
#![feature(stmt_expr_attributes)]
#![feature(trace_macros)]

// TODO: forbid
#![warn(bad_style,
const_err,
dead_code,
improper_ctypes,
legacy_directory_ownership,
non_shorthand_field_patterns,
no_mangle_generic_items,
overflowing_literals,
path_statements ,
patterns_in_fns_without_body,
plugin_as_library,
private_in_public,
safe_extern_statics,
unconditional_recursion,
unions_with_drop_fields,
unused,
unused_allocation,
unused_lifetimes,
unused_comparisons,
unused_parens,
while_true)]

#![warn(
bad_style,
const_err,
dead_code,
improper_ctypes,
legacy_directory_ownership,
non_shorthand_field_patterns,
no_mangle_generic_items,
overflowing_literals,
path_statements,
patterns_in_fns_without_body,
plugin_as_library,
private_in_public,
safe_extern_statics,
unconditional_recursion,
unions_with_drop_fields,
unused,
unused_allocation,
unused_lifetimes,
unused_comparisons,
unused_parens,
while_true
)]
// TODO: deny
#![warn(missing_debug_implementations,
missing_docs,
unsafe_code,
trivial_casts,
trivial_numeric_casts,
unused_extern_crates,
unused_import_braces,
unused_qualifications,
unused_results)]

#![warn(
missing_debug_implementations,
missing_docs,
unsafe_code,
trivial_casts,
trivial_numeric_casts,
unused_extern_crates,
unused_import_braces,
unused_qualifications,
unused_results
)]
// Mark the crate as no_std if the `no_std` feature is enabled.
#![cfg_attr(feature = "no_std", no_std)]

Expand All @@ -43,8 +44,10 @@ mod shims;

// Can't have `no_std` and `shims` enabled!
#[cfg(all(feature = "no_std", feature = "shims"))]
compile_error!("Sorry! Can't provide shims for no_std targets. Either disable \
the `no_std` feature or the `shims` feature.");
compile_error!(
"Sorry! Can't provide shims for no_std targets. Either disable \
the `no_std` feature or the `shims` feature."
);

pub type Addr = u16;
pub type Word = u16;
Expand All @@ -55,5 +58,5 @@ pub mod control;
pub mod memory;
pub mod peripherals;

pub mod isa;
pub mod interp;
pub mod isa;
37 changes: 25 additions & 12 deletions src/peripherals/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct GpioWriteError(GpioStateMismatch);

type GpioPinArr<T> = [T; NUM_GPIO_PINS as usize];

type GpioStateMismatches = GpioPinArr<Option<GpioStateMismatch>>;// [Option<GpioStateMismatch>; NUM_GPIO_PINS as usize];
type GpioStateMismatches = GpioPinArr<Option<GpioStateMismatch>>; // [Option<GpioStateMismatch>; NUM_GPIO_PINS as usize];

#[derive(Copy, Clone)]
pub struct GpioReadErrors(GpioStateMismatches);
Expand Down Expand Up @@ -92,9 +92,13 @@ pub trait Gpio {

let mut errors = [Ok(()); NUM_GPIO_PINS as usize];

GPIO_PINS.iter().zip(bits.iter()).enumerate().for_each(|(idx, (pin, bit))| {
errors[idx] = self.write(*pin, *bit);
});
GPIO_PINS
.iter()
.zip(bits.iter())
.enumerate()
.for_each(|(idx, (pin, bit))| {
errors[idx] = self.write(*pin, *bit);
});

errors
}
Expand All @@ -112,13 +116,19 @@ pub trait Gpio {
// fn register_interrupt(&mut self, pin: GpioPin, func: impl FnMut(bool)) -> Result<(), GpioInterruptRegisterError>;

// Gonne switch to MiscError for now then (TODO ^^^^^^):
fn register_interrupt(&mut self, pin: GpioPin, func: impl FnMut(bool)) -> Result<(), GpioMiscError>;
fn register_interrupt(
&mut self,
pin: GpioPin,
func: impl FnMut(bool),
) -> Result<(), GpioMiscError>;
}

impl TryFrom<GpioPinArr<Result<bool, GpioReadError>>> for GpioReadErrors {
type Error = ();

fn try_from(read_errors: GpioPinArr<Result<bool, GpioReadError>>) -> Result<GpioReadErrors, ()> {
fn try_from(
read_errors: GpioPinArr<Result<bool, GpioReadError>>,
) -> Result<GpioReadErrors, ()> {
if read_errors.iter().all(|r| r.is_ok()) {
Err(()) // No error!
} else {
Expand All @@ -127,9 +137,9 @@ impl TryFrom<GpioPinArr<Result<bool, GpioReadError>>> for GpioReadErrors {
read_errors
.iter()
.enumerate()
.filter_map(|(idx, res)|
.filter_map(|(idx, res)| {
res.map_err(|gpio_read_error| (idx, gpio_read_error)).err()
)
})
.for_each(|(idx, gpio_read_error)| {
errors[idx] = Some(gpio_read_error.0);
});
Expand All @@ -142,7 +152,9 @@ impl TryFrom<GpioPinArr<Result<bool, GpioReadError>>> for GpioReadErrors {
impl TryFrom<GpioPinArr<Result<(), GpioWriteError>>> for GpioWriteErrors {
type Error = ();

fn try_from(write_errors: GpioPinArr<Result<(), GpioWriteError>>) -> Result<GpioWriteErrors, ()> {
fn try_from(
write_errors: GpioPinArr<Result<(), GpioWriteError>>,
) -> Result<GpioWriteErrors, ()> {
if write_errors.iter().all(|w| w.is_ok()) {
// None
Err(())
Expand All @@ -152,9 +164,10 @@ impl TryFrom<GpioPinArr<Result<(), GpioWriteError>>> for GpioWriteErrors {
write_errors
.iter()
.enumerate()
.filter_map(|(idx, res)|
res.map_err(|gpio_write_error| (idx, gpio_write_error)).err()
)
.filter_map(|(idx, res)| {
res.map_err(|gpio_write_error| (idx, gpio_write_error))
.err()
})
.for_each(|(idx, gpio_write_error)| {
errors[idx] = Some(gpio_write_error.0);
});
Expand Down
4 changes: 1 addition & 3 deletions src/peripherals/input.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//! [`Input` device trait](trait.Input.html) and related things.
pub trait Input {

}
pub trait Input {}
11 changes: 5 additions & 6 deletions src/peripherals/mod.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
//! Peripherals! The [`Peripherals` supertrait](trait.Peripherals.html) and the
//! rest of the peripheral and device traits.
pub mod gpio;
pub mod adc;
pub mod clock;
pub mod gpio;
pub mod pwm;
pub mod timers;
pub mod clock;

pub mod input;
pub mod output;

use gpio::Gpio;
use adc::Adc;
use clock::Clock;
use gpio::Gpio;
use pwm::Pwm;
use timers::Timers;
use clock::Clock;

use input::Input;
use output::Output;
Expand All @@ -39,7 +39,7 @@ where
timers: T,
clock: C,
input: I,
output: O
output: O,
}

#[doc(hidden)]
Expand Down Expand Up @@ -119,7 +119,6 @@ macro_rules! func_sig {
($nom:ident, ) => {};
}


// impl<G, A, P, T, C, I, O> Gpio for PeripheralSet<G, A, P, T, C, I, O>
// where
// G: Gpio,
Expand Down
4 changes: 1 addition & 3 deletions src/peripherals/output.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//! [`Output` device trait](trait.Output.html) and friends.
pub trait Output {

}
pub trait Output {}
1 change: 1 addition & 0 deletions src/shims/gpio.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 0 additions & 1 deletion src/shims/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// Peripherals:
mod gpio;


// Devices:

// Memory:

0 comments on commit 5f71438

Please sign in to comment.