diff options
Diffstat (limited to 'sw/deps/hd44780-driver/examples/metro_m0')
7 files changed, 299 insertions, 0 deletions
diff --git a/sw/deps/hd44780-driver/examples/metro_m0/.cargo/config b/sw/deps/hd44780-driver/examples/metro_m0/.cargo/config new file mode 100644 index 0000000..ce9679d --- /dev/null +++ b/sw/deps/hd44780-driver/examples/metro_m0/.cargo/config @@ -0,0 +1,13 @@ +# samd21 is a Cortex-M0 and thus thumbv6m + +[build] +target = "thumbv6m-none-eabi" + +[target.thumbv6m-none-eabi] +runner = 'arm-none-eabi-gdb' +rustflags = [ + "-C", "link-arg=-Tlink.x", + "-C", "linker=lld", + "-Z", "linker-flavor=ld.lld", + "-Z", "thinlto=no", +]
\ No newline at end of file diff --git a/sw/deps/hd44780-driver/examples/metro_m0/.gdbinit b/sw/deps/hd44780-driver/examples/metro_m0/.gdbinit new file mode 100644 index 0000000..7b9b83b --- /dev/null +++ b/sw/deps/hd44780-driver/examples/metro_m0/.gdbinit @@ -0,0 +1,20 @@ +set auto-load safe-path / + +# print demangled symbols by default +set print asm-demangle on + +# JLink +target extended-remote :2331 +monitor flash breakpoints 1 +# allow hprints to show up in gdb +monitor semihosting enable +monitor semihosting IOClient 3 + +monitor reset +load + +# OpenOCD +#target extended-remote :3333 +#monitor arm semihosting enable +#load +#step
\ No newline at end of file diff --git a/sw/deps/hd44780-driver/examples/metro_m0/Cargo.toml b/sw/deps/hd44780-driver/examples/metro_m0/Cargo.toml new file mode 100644 index 0000000..bd88b22 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/metro_m0/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "metro_m0_hd44780_examples" +version = "0.2.0" +authors = ["John Doneth <doneth7@gmail.com>"] +keywords = ["no-std", "arm", "cortex-m", "embedded-hal"] +license = "MIT" + +[dependencies] +cortex-m = "~0.4" +hd44780-driver = { path = "../.." } +atsamd21-hal = "~0.1" +embedded-hal = "~0.2" +metro_m0 = { git = "https://github.com/wez/atsamd21-rs.git" } + +cortex-m-rt = "*" + +[dev-dependencies] +panic-abort = "~0.1" +panic-semihosting = "~0.1" +cortex-m-semihosting = "~0.2" +cortex-m-rtfm = "~0.3" +sx1509 = "~0.2" + +[features] +# ask the HAL to enable atsamd21g18a support +default = ["rt", "atsamd21-hal/samd21g18a"] +rt = ["atsamd21-hal/rt"] +unproven = ["atsamd21-hal/unproven"] +use_semihosting = [] diff --git a/sw/deps/hd44780-driver/examples/metro_m0/examples/4bit.rs b/sw/deps/hd44780-driver/examples/metro_m0/examples/4bit.rs new file mode 100644 index 0000000..5cf46c3 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/metro_m0/examples/4bit.rs @@ -0,0 +1,71 @@ +#![feature(used)] +#![no_std] + +extern crate cortex_m_semihosting; + +#[cfg(not(feature = "use_semihosting"))] +extern crate panic_abort; + +#[cfg(feature = "use_semihosting")] +extern crate panic_semihosting; + +extern crate cortex_m; +extern crate cortex_m_rt; +extern crate atsamd21_hal; +extern crate metro_m0; + +use metro_m0::clock::GenericClockController; +use metro_m0::delay::Delay; +use metro_m0::{CorePeripherals, Peripherals}; + +extern crate hd44780_driver; + +use hd44780_driver::HD44780; + +extern crate embedded_hal; + +fn main() { + let mut peripherals = Peripherals::take().unwrap(); + + let core = CorePeripherals::take().unwrap(); + + let mut clocks = GenericClockController::new( + peripherals.GCLK, + &mut peripherals.PM, + &mut peripherals.SYSCTRL, + &mut peripherals.NVMCTRL, + ); + + let mut pins = metro_m0::pins(peripherals.PORT); + let delay = Delay::new(core.SYST, &mut clocks); + + let mut lcd = HD44780::new_4bit( + + pins.d4.into_open_drain_output(&mut pins.port), // Register Select pin + pins.d3.into_open_drain_output(&mut pins.port), // Enable pin + + pins.d9.into_open_drain_output(&mut pins.port), // d4 + pins.d10.into_open_drain_output(&mut pins.port), // d5 + pins.d11.into_open_drain_output(&mut pins.port), // d6 + pins.d12.into_open_drain_output(&mut pins.port), // d7 + + delay, + ); + + // Unshift display and set cursor to 0 + lcd.reset(); + + // Clear existing characters + lcd.clear(); + + // Display the following string + lcd.write_str("Hello, world!"); + + // Move the cursor to the second line + lcd.set_cursor_pos(40); + + // Display the following string on the second line + lcd.write_str("I'm on line 2!"); + + loop { } +} diff --git a/sw/deps/hd44780-driver/examples/metro_m0/examples/basic.rs b/sw/deps/hd44780-driver/examples/metro_m0/examples/basic.rs new file mode 100644 index 0000000..2adb5b0 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/metro_m0/examples/basic.rs @@ -0,0 +1,67 @@ +#![feature(used)] +#![no_std] + +extern crate cortex_m_semihosting; + +#[cfg(not(feature = "use_semihosting"))] +extern crate panic_abort; + +#[cfg(feature = "use_semihosting")] +extern crate panic_semihosting; + +extern crate cortex_m; +extern crate cortex_m_rt; +extern crate atsamd21_hal; +extern crate metro_m0; + +use metro_m0::clock::GenericClockController; +use metro_m0::delay::Delay; +use metro_m0::{CorePeripherals, Peripherals}; + +extern crate hd44780_driver; + +use hd44780_driver::HD44780; + +fn main() { + let mut peripherals = Peripherals::take().unwrap(); + + let core = CorePeripherals::take().unwrap(); + + let mut clocks = GenericClockController::new( + peripherals.GCLK, + &mut peripherals.PM, + &mut peripherals.SYSCTRL, + &mut peripherals.NVMCTRL, + ); + + let mut pins = metro_m0::pins(peripherals.PORT); + let delay = Delay::new(core.SYST, &mut clocks); + + let mut lcd = HD44780::new_8bit( + + pins.d4.into_open_drain_output(&mut pins.port), // Register Select pin + pins.d3.into_open_drain_output(&mut pins.port), // Enable pin + + pins.d5.into_open_drain_output(&mut pins.port), // d0 + pins.d6.into_open_drain_output(&mut pins.port), // d1 + pins.d7.into_open_drain_output(&mut pins.port), // d2 + pins.d8.into_open_drain_output(&mut pins.port), // d3 + pins.d9.into_open_drain_output(&mut pins.port), // d4 + pins.d10.into_open_drain_output(&mut pins.port), // d5 + pins.d11.into_open_drain_output(&mut pins.port), // d6 + pins.d12.into_open_drain_output(&mut pins.port), // d7 + + delay, + ); + + // Unshift display and set cursor to 0 + lcd.reset(); + + // Clear existing characters + lcd.clear(); + + // Display the following string + lcd.write_str("Hello, world!"); + + loop { } +} diff --git a/sw/deps/hd44780-driver/examples/metro_m0/examples/scrolling.rs b/sw/deps/hd44780-driver/examples/metro_m0/examples/scrolling.rs new file mode 100644 index 0000000..f02a752 --- /dev/null +++ b/sw/deps/hd44780-driver/examples/metro_m0/examples/scrolling.rs @@ -0,0 +1,91 @@ +#![feature(used)] +#![no_std] + +extern crate cortex_m_semihosting; + +#[cfg(not(feature = "use_semihosting"))] +extern crate panic_abort; + +#[cfg(feature = "use_semihosting")] +extern crate panic_semihosting; + +extern crate cortex_m; +extern crate cortex_m_rt; +extern crate atsamd21_hal; +extern crate metro_m0; + +use metro_m0::clock::GenericClockController; +use metro_m0::delay::Delay; +use metro_m0::{CorePeripherals, Peripherals}; + +extern crate hd44780_driver; + +use hd44780_driver::{HD44780, DisplayMode, Display, Cursor, CursorBlink}; + +extern crate embedded_hal; + +fn busy_loop(){ + #[allow(unused_variables)] + let mut i = 0; + + for _ in 0..50000 { + i += 1; + } +} + +fn main() { + let mut peripherals = Peripherals::take().unwrap(); + + let core = CorePeripherals::take().unwrap(); + + let mut clocks = GenericClockController::new( + peripherals.GCLK, + &mut peripherals.PM, + &mut peripherals.SYSCTRL, + &mut peripherals.NVMCTRL, + ); + + let mut pins = metro_m0::pins(peripherals.PORT); + let delay = Delay::new(core.SYST, &mut clocks); + + let mut lcd = HD44780::new_8bit( + + pins.d4.into_open_drain_output(&mut pins.port), // Register Select pin + pins.d3.into_open_drain_output(&mut pins.port), // Enable pin + + pins.d5.into_open_drain_output(&mut pins.port), // d0 + pins.d6.into_open_drain_output(&mut pins.port), // d1 + pins.d7.into_open_drain_output(&mut pins.port), // d2 + pins.d8.into_open_drain_output(&mut pins.port), // d3 + pins.d9.into_open_drain_output(&mut pins.port), // d4 + pins.d10.into_open_drain_output(&mut pins.port), // d5 + pins.d11.into_open_drain_output(&mut pins.port), // d6 + pins.d12.into_open_drain_output(&mut pins.port), // d7 + + delay, + ); + + //lcd.set_cursor_mode(CursorMode::Increment); + lcd.set_autoscroll(true); + + lcd.set_display_mode(DisplayMode { + cursor_visible : Cursor::Invisible, + cursor_blink : CursorBlink::On, + display_visible : Display::On, + }); + + let string = "Hello, world! "; + + // Display the following string + loop { + + for c in string.chars() { + lcd.write_char(c); + + busy_loop(); + } + + } + + +} diff --git a/sw/deps/hd44780-driver/examples/metro_m0/memory.x b/sw/deps/hd44780-driver/examples/metro_m0/memory.x new file mode 100644 index 0000000..859903b --- /dev/null +++ b/sw/deps/hd44780-driver/examples/metro_m0/memory.x @@ -0,0 +1,8 @@ +MEMORY +{ + /* Leave 8k for the default bootloader on the Metro M0 */ + FLASH (rx) : ORIGIN = 0x00000000 + 8K, LENGTH = 256K - 8K + RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K +} +_stack_start = ORIGIN(RAM) + LENGTH(RAM); + |