Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check source formatting during CI #43

Merged
merged 2 commits into from Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions .circleci/config.yml
@@ -1,5 +1,12 @@
version: 2

workflows:
version: 2
build-and-test:
jobs:
- build
- fmt

jobs:
build:
docker:
Expand All @@ -10,3 +17,11 @@ jobs:
- run: apt install -y gcc-arm-none-eabi
- run: rustup target add thumbv6m-none-eabi
- run: cargo build --release

fmt:
docker:
- image: rust:1.32.0
steps:
- checkout
- run: rustup component add rustfmt
- run: cargo fmt -- --check
26 changes: 13 additions & 13 deletions src/leds.rs
@@ -1,6 +1,6 @@
//! Control the debug LEDs on the PCB.

use lpc11uxx::{IOCON, GPIO_PORT};
use lpc11uxx::{GPIO_PORT, IOCON};

/// The colors of the debug LEDs.
pub enum Color {
Expand All @@ -21,23 +21,23 @@ impl Leds {
/// * Set pin direction (output)
pub fn init(iocon: &mut IOCON, gpio: &mut GPIO_PORT) -> Self {
// Set port functions
(*iocon).pio1_22.write(|w| w
.func().pio1_22()
.mode().inactive());
(*iocon).pio0_17.write(|w| w
.func().pio0_17()
.mode().inactive());
(*iocon).pio1_16.write(|w| w
.func().pio1_16()
.mode().inactive());
(*iocon)
.pio1_22
.write(|w| w.func().pio1_22().mode().inactive());
(*iocon)
.pio0_17
.write(|w| w.func().pio0_17().mode().inactive());
(*iocon)
.pio1_16
.write(|w| w.func().pio1_16().mode().inactive());

unsafe {
// Set pin directions to output
(*gpio).dir[1].modify(|r, w| w.bits(r.bits() | (1<<16) | (1<<22)));
(*gpio).dir[0].modify(|r, w| w.bits(r.bits() | (1<<17)));
(*gpio).dir[1].modify(|r, w| w.bits(r.bits() | (1 << 16) | (1 << 22)));
(*gpio).dir[0].modify(|r, w| w.bits(r.bits() | (1 << 17)));
}

Leds { }
Leds {}
}

/// Enable the specified LED.
Expand Down
47 changes: 27 additions & 20 deletions src/main.rs
Expand Up @@ -5,25 +5,24 @@
extern crate cortex_m;
extern crate cortex_m_rt;
extern crate cortex_m_semihosting as sh;
extern crate embedded_hal;
extern crate lpc11uxx_hal;
extern crate panic_semihosting;
extern crate embedded_hal;

mod leds;

use core::fmt::Write;

use lpc11uxx::{CorePeripherals, Peripherals, SYSCON};
use lpc11uxx_hal::delay::Delay;
use lpc11uxx_hal::lpc11uxx;
use lpc11uxx::{CorePeripherals, Peripherals, SYSCON};

use embedded_hal::blocking::delay::DelayMs;

use cortex_m::asm;
use cortex_m_rt::entry;
use leds::{Color, Leds};
use sh::hio;
use leds::{Leds, Color};


/// Busy-loop the specified number of cycles.
fn sleep(cycles: u32) {
Expand All @@ -41,9 +40,8 @@ const SYSAHBCLKDIV_VAL: u32 = 0x00000001; // Reset: 0x001
/// Configure clock for external 12MHz crystal
fn clock_setup(syscon: &mut SYSCON) {
unsafe {

// Power-up system oscillator
syscon.pdruncfg.modify(|_,w| w.sysosc_pd().powered());
syscon.pdruncfg.modify(|_, w| w.sysosc_pd().powered());
syscon.sysoscctrl.write(|w| w.bits(SYSOSCCTRL_VAL));
sleep(200);

Expand All @@ -55,13 +53,11 @@ fn clock_setup(syscon: &mut SYSCON) {
syscon.syspllclkuen.write(|w| w.bits(0x00));
syscon.syspllclkuen.write(|w| w.bits(0x01));
// wait until updated
while syscon.syspllclkuen.read().bits() & 0x01 == 0 {
}
while syscon.syspllclkuen.read().bits() & 0x01 == 0 {}

// power-up SYSPLL
syscon.syspllctrl.write(|w| w.bits(SYSPLLCTRL_VAL));
syscon.pdruncfg.modify(|_,w| w.syspll_pd().powered());

syscon.pdruncfg.modify(|_, w| w.syspll_pd().powered());

// select PLL clock output
syscon.mainclksel.write(|w| w.bits(MAINCLKSEL_VAL));
Expand All @@ -71,19 +67,20 @@ fn clock_setup(syscon: &mut SYSCON) {
syscon.mainclkuen.write(|w| w.bits(0x00));
syscon.mainclkuen.write(|w| w.bits(0x01));
// wait until updated
while syscon.mainclkuen.read().bits() & 0x01 == 0 {
}
while syscon.mainclkuen.read().bits() & 0x01 == 0 {}
syscon.sysahbclkdiv.write(|w| w.bits(SYSAHBCLKDIV_VAL));

// power-down USB PHY and PLL
syscon.pdruncfg.modify(|_,w| w
.usbpad_pd().usb_transceiver_poweered_down()
.usbpll_pd().powered_down()
);
syscon.pdruncfg.modify(|_, w| {
w.usbpad_pd()
.usb_transceiver_poweered_down()
.usbpll_pd()
.powered_down()
});

// System clock to the IOCON needs to be enabled for most of the I/O
// related peripherals to work
syscon.sysahbclkctrl.modify(|_,w| w.iocon().enabled());
syscon.sysahbclkctrl.modify(|_, w| w.iocon().enabled());
}
}

Expand All @@ -102,9 +99,19 @@ fn main() -> ! {
let mut delay = Delay::new(cp.SYST, 48_000_000);

// Enable GPIO clock
writeln!(stdout, "SYSAHBCLKCTRL: {:#b}", (*syscon).sysahbclkctrl.read().bits()).unwrap();
(*syscon).sysahbclkctrl.modify(|_, w| { w.gpio().enabled() });
writeln!(stdout, "SYSAHBCLKCTRL: {:#b}", (*syscon).sysahbclkctrl.read().bits()).unwrap();
writeln!(
stdout,
"SYSAHBCLKCTRL: {:#b}",
(*syscon).sysahbclkctrl.read().bits()
)
.unwrap();
(*syscon).sysahbclkctrl.modify(|_, w| w.gpio().enabled());
writeln!(
stdout,
"SYSAHBCLKCTRL: {:#b}",
(*syscon).sysahbclkctrl.read().bits()
)
.unwrap();

let mut leds = Leds::init(&mut iocon, &mut gpio);

Expand Down