Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
toolchain: stable
target: ${{ matrix.target }}
override: true
components: llvm-tools-preview
components: llvm-tools-preview,clippy,rustfmt

- name: Build
run: cargo build --release --verbose --target ${{ matrix.target }}
Expand Down
24 changes: 17 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,53 @@ block-buffer = "0.10"
cipher = "0.4"
cortex-m = "0.7"
digest = "0.10"
embedded-hal = { version = "0.2", features = ["unproven"] }
embedded-hal = { version = "1" }
embedded-time = "0.12"
generic-array = "1.0.0"
lpc55-pac = "0.5"
nb = "1"
rand_core = "0.6"
rand_core06 = { package = "rand_core", version = "0.6", optional = true}
rand_core09 = { package = "rand_core", version = "0.9", optional = true}
usb-device = "0.2"
vcell = "0.1"
void = { version = "1", default-features = false }

# optional dependencies
# cortex-m-rtic = { version = "0.5", optional = true }
littlefs2 = { version = "0.5", optional = true }
embedded-io = "0.6.1"

[dev-dependencies]
aes = "0.8"
cortex-m-rt = "0.7"
rtic = { package = "cortex-m-rtic", version = "1" }
cortex-m-semihosting = "0.5"
heapless = "0.7"
panic-halt = "0.2"
panic-semihosting = { version = "0.5", features = ["jlink-quirks"] }
rtt-target = { version = "0.3", features = ["cortex-m"] }
heapless = "0.9"
panic-halt = "1"
panic-semihosting = { version = "0.6", features = ["jlink-quirks"] }
rtt-target = { version = "0.6" }
sha2 = { version = "0.10", default-features = false }
ssd1306 = "0.3"
ssd1306 = "0.10"
sha-1 = { version = "0.10", default-features = false }
usbd-serial = "0.1"
embedded-hal-bus = "0.3.0"

[features]
default = ["rt"]
littlefs = ["littlefs2"]
rt = ["lpc55-pac/rt"]
# no longer a HAL feature, just for the usb examples
highspeed-usb-example = []
rand-core-06 = ["dep:rand_core06"]
rand-core-09 = ["dep:rand_core09"]

[[example]]
name = "rng"
required-features = ["rand-core-09"]

[profile.release]
codegen-units = 1
debug = true
lto = true
opt-level = "z"

12 changes: 6 additions & 6 deletions examples/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ fn main() -> ! {
let i2c = I2cMaster::new(i2c, (scl, sda), Hertz::try_from(1_u32.MHz()).unwrap());

// OLED
let mut display: TerminalMode<_> = ssd1306::Builder::new()
.size(DisplaySize::Display128x32)
// .size(DisplaySize::Display70x40) // <-- TODO
.with_i2c_addr(0x3c)
.connect_i2c(i2c)
.into();
let mut display = ssd1306::Ssd1306::new(
ssd1306::I2CDisplayInterface::new(i2c),
ssd1306::size::DisplaySize128x32,
DisplayRotation::Rotate0,
)
.into_terminal_mode();

display.init().ok();
display.clear().ok();
Expand Down
4 changes: 2 additions & 2 deletions examples/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ mod app {

#[local]
struct LocalResources {
p: Producer<'static, u32, 4>,
c: Consumer<'static, u32, 4>,
p: Producer<'static, u32>,
c: Consumer<'static, u32>,
}

#[init]
Expand Down
4 changes: 1 addition & 3 deletions examples/measure_frequency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ extern crate panic_semihosting; // 4004 bytes
use cortex_m_rt::entry;
use cortex_m_semihosting::heprintln;

use hal::traits::wg::timer::Cancel;

use hal::{
drivers::{timer::Elapsed, Timer},
prelude::*,
Expand Down Expand Up @@ -57,7 +55,7 @@ fn main() -> ! {
delay_cycles(10_000_000);

let us = timer.elapsed().0;
timer.cancel().ok();
timer.cancel();

heprintln!("{} MHz", 10_000_000 / us);
}
Expand Down
28 changes: 12 additions & 16 deletions examples/pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use core::f32;

use cortex_m_rt::entry;

use embedded_hal::pwm::SetDutyCycle;
use hal::drivers::{Pins, Pwm, Timer};
use hal::prelude::*;
pub use hal::typestates::pin::state;
Expand All @@ -23,7 +24,7 @@ fn sin(x: f32) -> f32 {
let mut fact = 1f32;
for i in 0..5 {
res += pow / fact;
pow *= -1f32 * x * x;
pow *= -x * x;
fact *= ((2 * (i + 1)) * (2 * (i + 1) + 1)) as f32;
}

Expand Down Expand Up @@ -69,23 +70,22 @@ fn main() -> ! {
let green = pins.pio0_5.into_match_output(&mut iocon);
let blue = pins.pio1_19.into_match_output(&mut iocon);

pwm.scale_max_duty_by(10);
let (mut green_pwm, mut blue_pwm, mut red_pwm) = pwm.channels();
green_pwm.set_duty_cycle(0).unwrap();
red_pwm.set_duty_cycle(0).unwrap();
blue_pwm.set_duty_cycle(0).unwrap();
// 0 = 100% high voltage / off
// 128 = 50% high/low voltage
// 255 = 0% high voltage/ fully on
pwm.set_duty(green.get_channel(), 0);
pwm.set_duty(red.get_channel(), 0);
pwm.set_duty(blue.get_channel(), 0);
pwm.enable(green.get_channel());
pwm.enable(red.get_channel());
pwm.enable(blue.get_channel());

print_type_of(&red);
print_type_of(&green);
print_type_of(&blue);

let mut duties = [0f32, 30f32, 60f32];
let increments = [0.3f32, 0.2f32, 0.1f32];

pwm.scale_max_duty_by(10);

loop {
delay_timer.start(5_000.microseconds());
block!(delay_timer.wait()).unwrap();
Expand All @@ -103,14 +103,10 @@ fn main() -> ! {
match i {
0 => {
// need to tune down red some
pwm.set_duty(red.get_channel(), duty as u16);
}
1 => {
pwm.set_duty(green.get_channel(), duty * 2);
}
2 => {
pwm.set_duty(blue.get_channel(), duty * 2);
red_pwm.set_duty_cycle(duty).unwrap()
}
1 => green_pwm.set_duty_cycle(duty * 2).unwrap(),
2 => blue_pwm.set_duty_cycle(duty * 2).unwrap(),
_ => {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use cortex_m::asm;
use cortex_m_rt::entry;
use cortex_m_semihosting::dbg;

use hal::traits::rand_core::RngCore;
use lpc55_hal as hal;
use rand_core09::RngCore;

#[entry]
fn main() -> ! {
Expand Down
12 changes: 7 additions & 5 deletions examples/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ extern crate panic_semihosting;
use cortex_m_rt::entry;
// use core::fmt::Write;

use embedded_io::{Read, Write};
use hal::prelude::*;
use lpc55_hal as hal;

use hal::drivers::{Pins, Serial};

#[allow(unused_imports)]
use cortex_m_semihosting::{dbg, hprintln};
use nb::block;

#[entry]
fn main() -> ! {
Expand Down Expand Up @@ -54,16 +54,18 @@ fn main() -> ! {

// The `block!` macro makes an operation block until it finishes

block!(tx.write(sent)).ok();
tx.write(&[sent]).ok();
hprintln!("sent");

block!(tx.flush()).ok();
tx.flush().ok();
hprintln!("flushed");

let received = block!(rx.read()).unwrap();
let mut buf = [0];
let received = rx.read(&mut buf).unwrap();
hprintln!("received");

assert_eq!(received, sent);
assert_eq!(received, 1);
assert_eq!(buf, [sent]);
hprintln!("equal");

loop {
Expand Down
25 changes: 14 additions & 11 deletions examples/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ extern crate panic_halt;
use core::{convert::TryFrom, fmt::Write};
use cortex_m_rt::entry;

use lpc55_hal as hal;
use lpc55_hal::{self as hal, drivers::pins::Level};

use hal::{
drivers::{Pins, SpiMaster},
time::{Hertz, RateExtensions},
traits::wg::spi::{Mode, Phase, Polarity},
traits::wg1::spi::{Mode, Phase, Polarity},
typestates::pin::flexcomm::{NoCs, NoMiso},
};

Expand Down Expand Up @@ -44,7 +44,6 @@ fn main() -> ! {
let mosi = pins.pio0_26.into_spi8_mosi_pin(&mut iocon);
// let miso = pins.pio1_3.into_spi8_miso_pin(&mut iocon);
let miso = NoMiso;
// let cs = pins.pio1_1.into_spi8_cs_pin(&mut iocon);
let cs = NoCs;

// try this: currently no way to use SWCLK pin
Expand All @@ -63,21 +62,25 @@ fn main() -> ! {
Hertz::try_from(100_u32.kHz()).unwrap(),
spi_mode,
);
let cs = pins
.pio1_1
.into_gpio_pin(&mut iocon, &mut gpio)
.into_output(Level::Low);
let spi = embedded_hal_bus::spi::ExclusiveDevice::new_no_delay(spi, cs).unwrap();

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

// OLED
let mut display: TerminalMode<_> = ssd1306::Builder::new()
.size(DisplaySize::Display128x32)
// .size(DisplaySize::Display70x40) // <-- TODO
// .with_rotation(DisplayRotation::Rotate90)
.connect_spi(spi, dc)
.into();

display.init().unwrap();
let mut display = ssd1306::Ssd1306::new(
SPIInterface::new(spi, dc),
DisplaySize128x32,
DisplayRotation::Rotate0,
)
.into_terminal_mode();

display.clear().ok();

loop {
Expand Down
2 changes: 2 additions & 0 deletions src/drivers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ pub use timer::Timer;

pub mod touch;
pub use touch::TouchSensor;

pub mod delay;
15 changes: 15 additions & 0 deletions src/drivers/delay.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use embedded_time::duration::Microseconds;

use super::Timer;

use crate::{peripherals::ctimer::Ctimer, traits::wg1::delay::DelayNs, typestates::init_state};

impl<TIMER> DelayNs for Timer<TIMER>
where
TIMER: Ctimer<init_state::Enabled>,
{
fn delay_ns(&mut self, ns: u32) {
self.start(Microseconds::new(ns.max(1).saturating_mul(1000)));
nb::block!(self.wait()).ok();
}
}
Loading
Loading