Skip to content

Commit 5c70be5

Browse files
committed
Replace homegrown "time" with embedded-time
1 parent 84f257b commit 5c70be5

28 files changed

+128
-348
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
88
- Add INPUTMUX and PINT peripherals
99
- Add example using PINT + INPUTMUX to make an external interrupt on a pin
1010

11+
## [v0.2.0] - 2021-05-02
12+
Bump lpc55-pac and cipher
13+
Replace homegrown "time" with embedded-time
14+
1115
## [v0.1.1] - 2021-04-23
1216
USB fix
1317

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ cipher = "0.3"
2121
cortex-m = "0.7"
2222
digest = "0.9"
2323
embedded-hal = { version = "0.2", features = ["unproven"] }
24+
embedded-time = "0.10.1"
2425
generic-array = "0.14.2"
2526
lpc55-pac = "0.4"
2627
nb = "1"
@@ -43,6 +44,7 @@ cortex-m-semihosting = "0.3"
4344
heapless = "0.6"
4445
panic-halt = "0.2"
4546
panic-semihosting = { version = "0.5", features = ["jlink-quirks"] }
47+
rtt-target = { version = "0.3", features = ["cortex-m"] }
4648
sha2 = { version = "0.9", default-features = false }
4749
ssd1306 = "0.3"
4850
sha-1 = { version = "0.9", default-features = false }

examples/adc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn main() -> ! {
5050
let mut hal = hal::new();
5151

5252
let _clocks = hal::ClockRequirements::default()
53-
.system_frequency(12.mhz())
53+
.system_frequency(12.MHz())
5454
.configure(&mut hal.anactrl, &mut hal.pmc, &mut hal.syscon)
5555
.unwrap();
5656

examples/aes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use hal::prelude::*;
1515
use lpc55_hal as hal;
1616

1717
use aes_soft::cipher::{BlockCipher, NewBlockCipher};
18+
use hal::traits::cipher::{BlockDecrypt, BlockEncrypt};
1819

1920
use generic_array::GenericArray;
2021

examples/ctimer.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn main() -> ! {
2929
let mut hal = hal::new();
3030

3131
let clocks = hal::ClockRequirements::default()
32-
.system_frequency(12.mhz())
32+
.system_frequency(12.MHz())
3333
.configure(&mut hal.anactrl, &mut hal.pmc, &mut hal.syscon)
3434
.unwrap();
3535

@@ -39,10 +39,10 @@ fn main() -> ! {
3939
heprintln!("looping 1 Hz").unwrap();
4040
let mut c = 0;
4141
loop {
42-
cdriver.start(1.s());
42+
cdriver.start(1_000_000.microseconds());
4343
dbg!(c * 1_000_000);
4444
dbg!(cdriver.lap().0);
4545
c += 1;
4646
block!(cdriver.wait()).unwrap(); // blocks for 1 second
4747
}
48-
}
48+
}

examples/external_interrupts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn main() -> ! {
3434
let mut hal = hal::new();
3535

3636
let _clocks = hal::ClockRequirements::default()
37-
.system_frequency(12.mhz())
37+
.system_frequency(12.MHz())
3838
.configure(&mut hal.anactrl, &mut hal.pmc, &mut hal.syscon)
3939
.unwrap();
4040

examples/flash.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn main() -> ! {
4242
let mut syscon = hal.syscon;
4343

4444
hal::ClockRequirements::default()
45-
.system_frequency(12.mhz())
45+
.system_frequency(12.MHz())
4646
.configure(&mut anactrl, &mut pmc, &mut syscon)
4747
.unwrap();
4848

examples/i2c.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![no_main]
22
#![no_std]
33

4+
use core::convert::TryFrom;
45
// extern crate panic_semihosting;
56
extern crate panic_halt;
67
use cortex_m_rt::entry;
@@ -14,6 +15,7 @@ use hal::{
1415
Pins,
1516
I2cMaster,
1617
},
18+
time::Hertz,
1719
};
1820

1921
use ssd1306;
@@ -31,7 +33,7 @@ fn main() -> ! {
3133
let mut iocon = hal.iocon.enabled(&mut syscon);
3234

3335
let clocks = hal::ClockRequirements::default()
34-
.system_frequency(50.mhz())
36+
.system_frequency(50.MHz())
3537
// .support_flexcomm()
3638
.configure(&mut anactrl, &mut pmc, &mut syscon)
3739
.unwrap();
@@ -47,7 +49,7 @@ fn main() -> ! {
4749
let sda = pins.pio1_21.into_i2c4_sda_pin(&mut iocon);
4850

4951
// let i2c = I2cMaster::new(i2c, (scl, sda), 400.khz());
50-
let i2c = I2cMaster::new(i2c, (scl, sda), 1.mhz());
52+
let i2c = I2cMaster::new(i2c, (scl, sda), Hertz::try_from(1_u32.MHz()).unwrap());
5153

5254
// OLED
5355
let mut display: TerminalMode<_> = ssd1306::Builder::new()

examples/itm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn main() -> ! {
5858

5959
hal::ClockRequirements::default()
6060
// .support_usbfs()
61-
.system_frequency(12.mhz())
61+
.system_frequency(12.MHz())
6262
.configure(&mut anactrl, &mut pmc, &mut syscon)
6363
.unwrap();
6464

examples/jump-to-bootloader.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,17 @@ extern crate panic_halt; // 672 bytes
66

77
use cortex_m_rt::entry;
88

9-
use hal::{drivers::pins::Level, prelude::*};
109
use lpc55_hal as hal;
1110

1211
#[entry]
1312
fn main() -> ! {
1413
let hal = hal::new();
1514

1615
let mut syscon = hal.syscon;
17-
let mut iocon = hal.iocon.enabled(&mut syscon).release();
16+
let iocon = hal.iocon.enabled(&mut syscon).release();
1817

1918
// Conor's trick: make the bootloader think ISP0 is asserted,
2019
// even though it's not!
21-
iocon.pio0_5.modify(|r, w| w.invert().set_bit());
20+
iocon.pio0_5.modify(|_, w| w.invert().set_bit());
2221
unsafe { cortex_m::asm::bootload(0x03000000 as *const u32); }
2322
}

examples/measure_frequency.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn main() -> ! {
4040
let mut syscon = hal.syscon;
4141

4242
let clocks = hal::ClockRequirements::default()
43-
.system_frequency(150.mhz())
43+
.system_frequency(150.MHz())
4444
.configure(&mut anactrl, &mut pmc, &mut syscon)
4545
.unwrap();
4646

@@ -50,7 +50,7 @@ fn main() -> ! {
5050

5151
loop {
5252

53-
timer.start(1.s());
53+
timer.start(1_000_000.microseconds());
5454

5555
delay_cycles(10_000_000);
5656

examples/pfr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn main() -> ! {
6060

6161

6262
let clocks = hal::ClockRequirements::default()
63-
.system_frequency(96.mhz())
63+
.system_frequency(96.MHz())
6464
.configure(&mut anactrl, &mut pmc, &mut syscon)
6565
.unwrap();
6666

examples/prince.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn main() -> ! {
3535
const DATA_ADDR: usize = 0x00080000 + 0;
3636

3737
let _clocks = hal::ClockRequirements::default()
38-
.system_frequency(12.mhz())
38+
.system_frequency(12.MHz())
3939
.configure(&mut anactrl, &mut pmc, &mut syscon)
4040
.unwrap();
4141

examples/pwm.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn main() -> ! {
4747
let mut hal = hal::new();
4848

4949
let clocks = hal::ClockRequirements::default()
50-
.system_frequency(96.mhz())
50+
.system_frequency(96.MHz())
5151
.configure(&mut hal.anactrl, &mut hal.pmc, &mut hal.syscon)
5252
.unwrap();
5353

@@ -87,7 +87,7 @@ fn main() -> ! {
8787

8888
loop {
8989

90-
delay_timer.start(5.ms());
90+
delay_timer.start(5_000.microseconds());
9191
block!(delay_timer.wait()).unwrap();
9292

9393
for i in 0..3 {
@@ -116,4 +116,4 @@ fn main() -> ! {
116116
}
117117

118118
}
119-
}
119+
}

examples/rtc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn main() -> ! {
3333
let mut syscon = hal.syscon;
3434

3535
let clocks = hal::ClockRequirements::default()
36-
.system_frequency(96.mhz())
36+
.system_frequency(96.MHz())
3737
.configure(&mut anactrl, &mut pmc, &mut syscon)
3838
.unwrap();
3939

examples/rtt.rs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#![no_main]
2+
#![no_std]
3+
4+
// extern crate panic_semihosting; // 4004 bytes
5+
extern crate panic_halt; // 672 bytes
6+
7+
use cortex_m_rt::entry;
8+
use rtt_target::{rtt_init_print, rprintln};
9+
10+
use hal::{drivers::pins::Level, prelude::*};
11+
use lpc55_hal as hal;
12+
13+
// pub type RedLedPin = pins::Pio1_4;
14+
// pub type GreenLedPin = pins::Pio1_7;
15+
// pub type BlueLedPin = pins::Pio1_6;
16+
17+
#[entry]
18+
fn main() -> ! {
19+
let hal = hal::new();
20+
rtt_init_print!();
21+
22+
let mut syscon = hal.syscon;
23+
let mut gpio = hal.gpio.enabled(&mut syscon);
24+
let mut iocon = hal.iocon.enabled(&mut syscon);
25+
26+
let pins = hal::Pins::take().unwrap();
27+
28+
// R = pio1_6 (for lpcxpresso)
29+
let mut red = pins
30+
.pio1_6
31+
.into_gpio_pin(&mut iocon, &mut gpio)
32+
// on = low, off = high
33+
.into_output(Level::High);
34+
35+
loop {
36+
for _ in 0..50_000 {
37+
red.set_low().unwrap();
38+
}
39+
for _ in 0..50_000 {
40+
red.set_high().unwrap();
41+
}
42+
43+
rprintln!("toggled LED");
44+
}
45+
}

examples/serial.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn main() -> ! {
3131
let mut iocon = hal.iocon.enabled(&mut syscon);
3232

3333
let clocks = hal::ClockRequirements::default()
34-
.system_frequency(50.mhz())
34+
.system_frequency(50.MHz())
3535
// .support_flexcomm()
3636
.configure(&mut anactrl, &mut pmc, &mut syscon)
3737
.unwrap();
@@ -48,7 +48,7 @@ fn main() -> ! {
4848
let rx = pins.pio1_24.into_usart2_rx_pin(&mut iocon);
4949

5050
let config = hal::drivers::serial::config::Config::default()
51-
.speed(19_200.hz());
51+
.speed(19_200.Hz());
5252
hprintln!("config = {:?}", config).ok();
5353

5454
let serial = Serial::new(usart, (tx, rx), config);

examples/spi.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
// extern crate panic_semihosting;
55
extern crate panic_halt;
66
use cortex_m_rt::entry;
7-
use core::fmt::Write;
7+
use core::{convert::TryFrom, fmt::Write};
88

9-
use hal::prelude::*;
109
use lpc55_hal as hal;
1110

1211
use hal::{
@@ -20,6 +19,7 @@ use hal::{
2019
NoCs,
2120
},
2221
},
22+
time::{Hertz, RateExtensions},
2323
traits::wg::spi::{
2424
Mode,
2525
Phase,
@@ -74,7 +74,7 @@ fn main() -> ! {
7474
phase: Phase::CaptureOnFirstTransition,
7575
};
7676

77-
let spi = SpiMaster::new(spi, spi_pins, 100.khz(), spi_mode);
77+
let spi = SpiMaster::new(spi, spi_pins, Hertz::try_from(100_u32.kHz()).unwrap(), spi_mode);
7878

7979
let dc = pins.pio1_5.into_gpio_pin(&mut iocon, &mut gpio).into_output_high();
8080

examples/touch.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn main() -> ! {
3636
let mut hal = hal::new();
3737

3838
let clocks = hal::ClockRequirements::default()
39-
.system_frequency(96.mhz())
39+
.system_frequency(96.MHz())
4040
.configure(&mut hal.anactrl, &mut hal.pmc, &mut hal.syscon)
4141
.unwrap();
4242
let fro_token = clocks.support_1mhz_fro_token().unwrap();
@@ -102,7 +102,7 @@ fn main() -> ! {
102102
}
103103
}
104104

105-
delay_timer.start(300.ms());
105+
delay_timer.start(300_000.microseconds());
106106
block!(delay_timer.wait()).unwrap();
107107

108108
loop {

examples/usb.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ use hal::prelude::*;
1111
#[allow(unused_imports)]
1212
use lpc55_hal as hal;
1313

14-
// use hal::{reg_read, reg_modify};
15-
1614
use usbd_serial::{CdcAcmClass, /*SerialPort*/};
1715
use usb_device::device::{UsbDeviceBuilder, UsbVidPid};
1816
use hal::drivers::{
@@ -46,7 +44,7 @@ fn main() -> ! {
4644
let clocks = hal::ClockRequirements::default()
4745
// .system_frequency(24.mhz())
4846
// .system_frequency(72.mhz())
49-
.system_frequency(96.mhz())
47+
.system_frequency(96.MHz())
5048
.configure(&mut anactrl, &mut pmc, &mut syscon)
5149
.unwrap();
5250

examples/usb_test_class.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn main() -> ! {
3232
iocon.disabled(&mut syscon); // perfectionist ;)
3333

3434
let clocks = hal::ClockRequirements::default()
35-
.system_frequency(96.mhz())
35+
.system_frequency(96.MHz())
3636
.configure(&mut anactrl, &mut pmc, &mut syscon)
3737
.expect("Clock configuration failed");
3838

0 commit comments

Comments
 (0)