Skip to content

Commit 2400c96

Browse files
author
Andrew Tolvstad
committed
Clean up imports and crate attributes
The imports in most files appear to have been haphazardly converted from edition 2015 to edition 2018, with duplicates and repeated prefixes. Additionally, some crate attributes were set separately when they could have been set jointly. This change cleans up imports and consolidates crate attributes. The default rustfmt behavior for `use` statements is a bit questionable for long lists like this. This change sets the rustfmt config to use "HorizontalVertical" instead of "Mixed".
1 parent 951e461 commit 2400c96

File tree

20 files changed

+154
-130
lines changed

20 files changed

+154
-130
lines changed

examples/tiva-c-connected-launchpad/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
#![no_main]
33

44
extern crate panic_halt; // you can put a breakpoint on `rust_begin_unwind` to catch panics
5-
extern crate tm4c129x_hal as hal;
65

76
use core::fmt::Write;
87
use cortex_m_rt::entry;
9-
use hal::prelude::*;
8+
use tm4c129x_hal::{self as hal, prelude::*};
109

1110
#[entry]
1211
fn main() -> ! {

examples/tiva-c-launchpad/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
#![no_main]
33

44
extern crate panic_halt; // you can put a breakpoint on `rust_begin_unwind` to catch panics
5-
extern crate tm4c123x_hal as hal;
65

76
use core::fmt::Write;
87
use cortex_m_rt::entry;
9-
use hal::prelude::*;
8+
use tm4c123x_hal::{self as hal, prelude::*};
109

1110
#[entry]
1211
fn main() -> ! {

rustfmt.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
imports_layout = "HorizontalVertical"

tm4c-hal/src/delay.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
//! Code for busy-waiting
22
3-
use crate::sysctl::Clocks;
4-
use crate::time::Hertz;
5-
use cast::u32;
6-
use cortex_m::peripheral::syst::SystClkSource;
7-
use cortex_m::peripheral::SYST;
3+
use crate::{sysctl::Clocks, time::Hertz};
4+
use cortex_m::peripheral::{syst::SystClkSource, SYST};
85
use embedded_hal::blocking::delay::{DelayMs, DelayUs};
96

107
/// System timer (SysTick) as a delay provider
@@ -38,13 +35,13 @@ impl DelayMs<u32> for Delay {
3835

3936
impl DelayMs<u16> for Delay {
4037
fn delay_ms(&mut self, ms: u16) {
41-
self.delay_ms(u32(ms));
38+
self.delay_ms(cast::u32(ms));
4239
}
4340
}
4441

4542
impl DelayMs<u8> for Delay {
4643
fn delay_ms(&mut self, ms: u8) {
47-
self.delay_ms(u32(ms));
44+
self.delay_ms(cast::u32(ms));
4845
}
4946
}
5047

@@ -75,12 +72,12 @@ impl DelayUs<u32> for Delay {
7572

7673
impl DelayUs<u16> for Delay {
7774
fn delay_us(&mut self, us: u16) {
78-
self.delay_us(u32(us))
75+
self.delay_us(cast::u32(us))
7976
}
8077
}
8178

8279
impl DelayUs<u8> for Delay {
8380
fn delay_us(&mut self, us: u8) {
84-
self.delay_us(u32(us))
81+
self.delay_us(cast::u32(us))
8582
}
8683
}

tm4c-hal/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
//! Generic implementation code for both TM4C123 and TM4C129.
22
33
#![no_std]
4-
#![deny(missing_docs)]
5-
#![deny(warnings)]
4+
#![deny(missing_docs, warnings)]
65
#![allow(deprecated)]
76

8-
extern crate embedded_hal as hal;
9-
extern crate nb;
10-
117
pub mod bb;
128
pub mod delay;
139
pub mod gpio;

tm4c123x-hal/src/gpio.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@
3434
3535
pub use tm4c_hal::gpio::*;
3636

37-
use crate::bb;
38-
use crate::hal::digital::{InputPin, OutputPin, StatefulOutputPin};
39-
use crate::sysctl;
37+
use crate::{
38+
bb,
39+
hal::digital::{InputPin, OutputPin, StatefulOutputPin},
40+
sysctl,
41+
};
4042
use core::marker::PhantomData;
4143
use tm4c_hal::gpio_macro;
4244

tm4c123x-hal/src/i2c.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@
33
use cortex_m::asm::delay;
44
use tm4c123x::{I2C0, I2C1, I2C2, I2C3};
55

6-
use crate::gpio::gpioa::{PA6, PA7};
7-
use crate::gpio::gpiob::{PB2, PB3};
8-
use crate::gpio::gpiod::{PD0, PD1};
9-
use crate::gpio::gpioe::{PE4, PE5};
10-
11-
use crate::gpio::{AlternateFunction, Floating, OpenDrain, OutputMode, AF3};
12-
13-
use crate::sysctl::{self, Clocks};
14-
15-
use crate::hal::blocking::i2c::{Read, Write, WriteRead};
16-
use crate::time::Hertz;
6+
use crate::{
7+
gpio::{
8+
gpioa::{PA6, PA7},
9+
gpiob::{PB2, PB3},
10+
gpiod::{PD0, PD1},
11+
gpioe::{PE4, PE5},
12+
AlternateFunction,
13+
Floating,
14+
OpenDrain,
15+
OutputMode,
16+
AF3,
17+
},
18+
hal::blocking::i2c::{Read, Write, WriteRead},
19+
sysctl::{self, Clocks},
20+
time::Hertz,
21+
};
1722

1823
/// I2C error
1924
#[derive(Debug)]

tm4c123x-hal/src/lib.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
//!
2020
//! [`f3`]: https://docs.rs/f3/~0.5.1
2121
22-
#![deny(missing_docs)]
23-
#![deny(warnings)]
22+
#![deny(missing_docs, warnings)]
2423
#![allow(deprecated)]
2524
#![no_std]
2625

27-
pub use tm4c_hal::bb;
28-
pub use tm4c_hal::delay;
29-
pub use tm4c_hal::time;
26+
pub use tm4c123x::{self, CorePeripherals, Peripherals};
27+
pub use tm4c_hal::{bb, delay, time};
28+
29+
use embedded_hal as hal;
3030

3131
pub mod gpio;
3232
pub mod i2c;
@@ -35,8 +35,3 @@ pub mod serial;
3535
pub mod spi;
3636
pub mod sysctl;
3737
pub mod timer;
38-
39-
extern crate embedded_hal as hal;
40-
extern crate nb;
41-
pub use tm4c123x;
42-
pub use tm4c123x::{CorePeripherals, Peripherals};

tm4c123x-hal/src/prelude.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Prelude
22
3-
pub use crate::gpio::GpioExt as _tm4c123x_hal_gpio_GpioExt;
4-
pub use crate::hal::prelude::*;
5-
pub use crate::sysctl::SysctlExt;
6-
pub use crate::time::U32Ext;
3+
pub use crate::{
4+
gpio::GpioExt as _tm4c123x_hal_gpio_GpioExt,
5+
hal::prelude::*,
6+
sysctl::SysctlExt,
7+
time::U32Ext,
8+
};

tm4c123x-hal/src/serial.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
//! Serial
22
3-
use core::fmt;
4-
use core::marker::PhantomData;
5-
6-
use crate::hal::prelude::*;
7-
use crate::hal::serial;
8-
use nb::{self, block};
93
pub use tm4c123x::{UART0, UART1, UART2, UART3, UART4, UART5, UART6, UART7};
4+
pub use tm4c_hal::{serial::*, uart_hal_macro, uart_pin_macro};
5+
6+
use crate::{
7+
gpio::{
8+
gpioa,
9+
gpiob,
10+
gpioc,
11+
gpiod,
12+
gpioe,
13+
gpiof,
14+
AlternateFunction,
15+
OutputMode,
16+
AF1,
17+
AF2,
18+
AF8,
19+
},
20+
hal::{prelude::*, serial},
21+
sysctl,
22+
sysctl::Clocks,
23+
time::Bps,
24+
};
25+
use core::{fmt, marker::PhantomData};
26+
use nb::{self, block};
1027
use void::Void;
1128

12-
use crate::gpio::{gpioa, gpiob, gpioc, gpiod, gpioe, gpiof};
13-
use crate::gpio::{AlternateFunction, OutputMode, AF1, AF2, AF8};
14-
use crate::sysctl;
15-
use crate::sysctl::Clocks;
16-
use crate::time::Bps;
17-
18-
pub use tm4c_hal::serial::*;
19-
20-
pub use tm4c_hal::serial::*;
21-
22-
pub use tm4c_hal::{uart_hal_macro, uart_pin_macro};
23-
2429
/// Serial abstraction
2530
pub struct Serial<UART, TX, RX, RTS, CTS> {
2631
uart: UART,

tm4c123x-hal/src/spi.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22
33
pub use crate::hal::spi::{Mode, MODE_0, MODE_1, MODE_2, MODE_3};
44

5-
use crate::gpio::gpioa::{PA2, PA4, PA5};
6-
use crate::gpio::gpiob::{PB4, PB6, PB7};
7-
use crate::gpio::gpiod::{PD0, PD2, PD3};
8-
use crate::gpio::{AlternateFunction, OutputMode, AF1, AF2};
9-
use crate::hal::spi::{FullDuplex, Phase, Polarity};
10-
use crate::sysctl;
11-
use crate::sysctl::Clocks;
12-
use crate::time::Hertz;
5+
use crate::{
6+
gpio::{
7+
gpioa::{PA2, PA4, PA5},
8+
gpiob::{PB4, PB6, PB7},
9+
gpiod::{PD0, PD2, PD3},
10+
AlternateFunction,
11+
OutputMode,
12+
AF1,
13+
AF2,
14+
},
15+
hal::spi::{FullDuplex, Phase, Polarity},
16+
sysctl,
17+
sysctl::Clocks,
18+
time::Hertz,
19+
};
1320

1421
use nb;
1522
use tm4c123x::{SSI0, SSI1, SSI2, SSI3};

tm4c123x-hal/src/sysctl.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
//!
2222
//! See the LM4F120 datasheet, page 228 for a full list.
2323
24-
use crate::bb;
25-
use crate::time::{Hertz, U32Ext};
26-
use cortex_m::asm::nop;
27-
2824
pub use tm4c_hal::sysctl::*;
2925

26+
use crate::{
27+
bb,
28+
time::{Hertz, U32Ext},
29+
};
30+
use cortex_m::asm::nop;
31+
3032
/// Constrained SYSCTL peripheral.
3133
pub struct Sysctl {
3234
/// Power control methods will require `&mut this.power_control` to

tm4c123x-hal/src/timer.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
//! Timers
22
3-
extern crate embedded_hal as hal;
4-
5-
use tm4c_hal::time::Hertz;
6-
7-
use crate::sysctl;
8-
use hal::timer::{CountDown, Periodic};
3+
use crate::{
4+
hal::timer::{CountDown, Periodic},
5+
sysctl::{self, Clocks},
6+
};
97
use nb;
10-
use tm4c123x::{TIMER0, TIMER1, TIMER2, TIMER3, TIMER4, TIMER5};
11-
use tm4c123x::{WTIMER0, WTIMER1, WTIMER2, WTIMER3, WTIMER4, WTIMER5};
12-
13-
use crate::sysctl::Clocks;
8+
use tm4c123x::{
9+
TIMER0,
10+
TIMER1,
11+
TIMER2,
12+
TIMER3,
13+
TIMER4,
14+
TIMER5,
15+
WTIMER0,
16+
WTIMER1,
17+
WTIMER2,
18+
WTIMER3,
19+
WTIMER4,
20+
WTIMER5,
21+
};
22+
use tm4c_hal::time::Hertz;
1423
use void::Void;
1524

1625
/// Hardware timers

tm4c129x-hal/src/gpio.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636
3737
pub use tm4c_hal::gpio::*;
3838

39-
use crate::bb;
40-
use crate::hal::digital::{InputPin, OutputPin, StatefulOutputPin};
41-
use crate::sysctl;
39+
use crate::{
40+
bb,
41+
hal::digital::{InputPin, OutputPin, StatefulOutputPin},
42+
sysctl,
43+
};
4244
use core::marker::PhantomData;
4345
use tm4c_hal::gpio_macro;
4446

tm4c129x-hal/src/i2c.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
//! Inter-Integrated Circuit (I2C) bus
22
3-
use crate::gpio::*;
4-
use crate::gpio::{AlternateFunction, Floating, OpenDrain, OutputMode, AF3};
5-
use crate::hal::blocking::i2c::{Read, Write, WriteRead};
6-
use crate::sysctl::{self, Clocks};
7-
use crate::time::Hertz;
3+
use crate::{
4+
gpio::*,
5+
hal::blocking::i2c::{Read, Write, WriteRead},
6+
sysctl::{self, Clocks},
7+
time::Hertz,
8+
};
89
use cortex_m::asm::delay;
910
use tm4c129x::{I2C0, I2C1, I2C2, I2C3};
1011

tm4c129x-hal/src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@
2525
#![deny(warnings)]
2626
#![allow(deprecated)]
2727

28-
pub use tm4c_hal::bb;
29-
pub use tm4c_hal::delay;
30-
pub use tm4c_hal::time;
28+
pub use tm4c129x::{self, CorePeripherals, Peripherals};
29+
pub use tm4c_hal::{bb, delay, time};
3130

3231
pub mod gpio;
3332
pub mod i2c;
@@ -37,5 +36,3 @@ pub mod serial;
3736
pub mod sysctl;
3837

3938
use embedded_hal as hal;
40-
pub use tm4c129x;
41-
pub use tm4c129x::{CorePeripherals, Peripherals};

tm4c129x-hal/src/prelude.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Prelude
22
3-
pub use crate::gpio::GpioExt as _tm4c129x_hal_gpio_GpioExt;
4-
pub use crate::hal::prelude::*;
5-
pub use crate::sysctl::SysctlExt;
6-
pub use crate::time::U32Ext;
3+
pub use crate::{
4+
gpio::GpioExt as _tm4c129x_hal_gpio_GpioExt,
5+
hal::prelude::*,
6+
sysctl::SysctlExt,
7+
time::U32Ext,
8+
};

0 commit comments

Comments
 (0)