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

Ported examples from rp-pico #90

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
23 changes: 23 additions & 0 deletions boards/pimoroni-pico-lipo-16mb/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## 0.8.1 - 2024-10-05

### Added

- Ported PWM blink example from rp-pico
- Ported USB serial example from rp-pico
- Ported countdown blinky example from rp-pico
- Ported OLED display SSD1306 example from rp-pico (not tested with display)
- Ported PIO PWM example from rp-pico
- Ported interpolator example from rp-pico
- Ported GPIO in/out example from rp-pico
- Ported USB serial interrupt example from rp-pico
- Ported UART IRQ Buffer example from rp-pico
- Ported UART IRQ Echo example from rp-pico
- Ported USB twitchy mouse example from rp-pico
- Ported ws2812led example from rp-pico (not tested with actual LEDs)
- Ported SPI SD Card example from rp-pico (not tested, Failed to build : rust-lld: error: undefined symbol: _defmt_timestamp)
- Ported HD44780 diplay example from rp-pico (not tested with display)
- Ported I2C PIO example from rp-pico (not tested with sensor)
- Ported PWM servo example from rp-pico (not tested with servo)
- Ported rtic example from rp-pico
- Ported rtic monotonic example from rp-pico

## 0.8.0 - 2024-04-07

### Changed
Expand Down
30 changes: 28 additions & 2 deletions boards/pimoroni-pico-lipo-16mb/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pimoroni-pico-lipo-16mb"
version = "0.8.0"
version = "0.8.1"
authors = ["Hmvp <[email protected]>", "The rp-rs Developers"]
edition = "2018"
homepage = "https://github.com/rp-rs/rp-hal-boards/tree/main/boards/pimoroni-pico-lipo-16mb"
Expand All @@ -12,14 +12,36 @@ repository = "https://github.com/rp-rs/rp-hal-boards.git"

[dependencies]
cortex-m-rt = { workspace = true, optional = true }
fugit.workspace = true
rp2040-boot2 = { workspace = true, optional = true }
rp2040-hal.workspace = true
usb-device.workspace = true

[dev-dependencies]

cortex-m.workspace = true
panic-halt.workspace = true
cortex-m-rtic.workspace = true
critical-section.workspace = true
embedded-graphics.workspace = true
embedded-hal.workspace = true
embedded-hal-nb.workspace = true
embedded-sdmmc.workspace = true
hd44780-driver.workspace = true
heapless.workspace = true
i2c-pio.workspace = true
nb.workspace = true
panic-halt.workspace = true
pio.workspace = true
pio-proc.workspace = true
rp2040-hal = { workspace = true, features = [ "defmt" ] }
smart-leds.workspace = true
ssd1306.workspace = true
usbd-hid.workspace = true
usbd-serial.workspace = true
ws2812-pio.workspace = true

defmt.workspace = true
defmt-rtt.workspace = true

[features]
# This is the set of features we enable by default
Expand All @@ -46,3 +68,7 @@ disable-intrinsics = ["rp2040-hal/disable-intrinsics"]

# This enables ROM functions for f64 math that were not present in the earliest RP2040s
rom-v2-intrinsics = ["rp2040-hal/rom-v2-intrinsics"]

[[example]]
name = "pimoroni_pico_lipo_16mb_rtic_monotonic"
required-features = ["rp2040-hal/rtic-monotonic"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//! # Pimoroni Pico LiPo 16mb Countdown Blinky Example
//!
//! Blinks the LED on a Pimoroni Pico LiPo 16mb board, using an RP2040 Timer in Count-down mode.
//!
//! This will blink an LED attached to GP25, which is the pin the Pico LiPo uses for
//! the on-board LED.
//!
//! See the `Cargo.toml` file for Copyright and license details.

#![no_std]
#![no_main]

// The macro for our start-up function
use pimoroni_pico_lipo_16mb::entry;

use cortex_m::prelude::*;

// GPIO traits
use embedded_hal::digital::OutputPin;

// Traits for converting integers to amounts of time
use fugit::ExtU32;

// Ensure we halt the program on panic (if we don't mention this crate it won't
// be linked)
use panic_halt as _;

// A shorter alias for the Peripheral Access Crate, which provides low-level
// register access
use pimoroni_pico_lipo_16mb::hal::pac;

// A shorter alias for the Hardware Abstraction Layer, which provides
// higher-level drivers.
use pimoroni_pico_lipo_16mb::hal;

#[entry]
fn main() -> ! {
// Grab our singleton objects
let mut pac = pac::Peripherals::take().unwrap();

// Set up the watchdog driver - needed by the clock setup code
let mut watchdog = hal::Watchdog::new(pac.WATCHDOG);

// Configure the clocks
//
// The default is to generate a 125 MHz system clock
let clocks = hal::clocks::init_clocks_and_plls(
pimoroni_pico_lipo_16mb::XOSC_CRYSTAL_FREQ,
pac.XOSC,
pac.CLOCKS,
pac.PLL_SYS,
pac.PLL_USB,
&mut pac.RESETS,
&mut watchdog,
)
.ok()
.unwrap();

// Configure the Timer peripheral in count-down mode
let timer = hal::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks);
let mut count_down = timer.count_down();

// The single-cycle I/O block controls our GPIO pins
let sio = hal::Sio::new(pac.SIO);

// Set the pins up according to their function on this particular board
let pins = pimoroni_pico_lipo_16mb::Pins::new(
pac.IO_BANK0,
pac.PADS_BANK0,
sio.gpio_bank0,
&mut pac.RESETS,
);

let mut led_pin = pins.led.into_push_pull_output();

// Blink the LED at 1 Hz
loop {
// LED on, and wait for 500ms
led_pin.set_high().unwrap();
count_down.start(500.millis());
let _ = nb::block!(count_down.wait());

// LED off, and wait for 500ms
led_pin.set_low().unwrap();
count_down.start(500.millis());
let _ = nb::block!(count_down.wait());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//! # Pimoroni Pico LiPo 16mb GPIO In/Out Example
//!
//! Toggles the LED based on GPIO input.
//!
//! This will control an LED on GP25 based on a button hooked up to GP15. The
//! button should cause the line to be grounded, as the input pin is pulled high
//! internally by this example. When the button is pressed, the LED will turn
//! off.
//!
//! See the `Cargo.toml` file for Copyright and license details.

#![no_std]
#![no_main]

// The macro for our start-up function
use pimoroni_pico_lipo_16mb::entry;

// GPIO traits
use embedded_hal::digital::{InputPin, OutputPin};

// Ensure we halt the program on panic (if we don't mention this crate it won't
// be linked)
use panic_halt as _;

// A shorter alias for the Peripheral Access Crate, which provides low-level
// register access
use pimoroni_pico_lipo_16mb::hal::pac;

// A shorter alias for the Hardware Abstraction Layer, which provides
// higher-level drivers.
use pimoroni_pico_lipo_16mb::hal;

/// Entry point to our bare-metal application.
///
/// The `#[entry]` macro ensures the Cortex-M start-up code calls this function
/// as soon as all global variables are initialised.
///
/// The function configures the RP2040 peripherals, then just reads the button
/// and sets the LED appropriately.
#[entry]
fn main() -> ! {
// Grab our singleton objects
let mut pac = pac::Peripherals::take().unwrap();

// Note - we don't do any clock set-up in this example. The RP2040 will run
// at it's default clock speed.

// The single-cycle I/O block controls our GPIO pins
let sio = hal::Sio::new(pac.SIO);

// Set the pins up according to their function on this particular board
let pins = pimoroni_pico_lipo_16mb::Pins::new(
pac.IO_BANK0,
pac.PADS_BANK0,
sio.gpio_bank0,
&mut pac.RESETS,
);

// Our LED output
let mut led_pin = pins.led.into_push_pull_output();

// Our button input
let mut button_pin = pins.gpio15.into_pull_up_input();

// Run forever, setting the LED according to the button
loop {
if button_pin.is_low().unwrap() {
led_pin.set_high().unwrap();
} else {
led_pin.set_low().unwrap();
}
}
}

// End of file
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
//! # LCD Display Example
//!
//! In this example, the RP2040 is configured to drive a small two-line
//! alphanumeric LCD using the
//! [HD44780](https://crates.io/crates/hd44780-driver) driver.
//!
//! This example drives the LCD by pushing data out of six GPIO pins, writing
//! the data four bits at a time. A faster alternative can be created using
//! HD44780::new_8bit() but requiring an additional four GPIO pins.
//!
//! See the `Cargo.toml` file for Copyright and license details.
//!
//! ```text
//! /--------------------------------------\
//! ____________ | /-------------------------\ |
//! | 1 GND|-------+---\ | _|USB|_ | |
//! | 2 VDD|-------+---+----/ |1 R 40|-VBUS-o v
//! | 3 VS|-------/ | |2 P 39| ||POT||
//! | 4 RS|--\ o-----------GND-|3 38|-GND----------o
//! | 5 RW|--+--------/ /------GP2-|4 P 37|
//! | 6 EN|--+-\ /--+------GP3-|5 I 36|
//! | 7 | | | /--+--+------GP4-|6 C |
//! | 8 | | | /--+--+--+------GP5-|7 O |
//! | 9 | | \--+--+--+--+---\ |8 |
//! | 10 | \----+--+--+--+-\ \-GP6-|9 |
//! | 11 D4|-------/ | | | \---GP7-|10 |
//! | 12 D5|----------/ | | .........
//! | 13 D6|-------------/ | |20 21|
//! | 14 D7|----------------/ """""""
//! ..............
//! Symbols:
//! - (+) crossing lines, not connected
//! - (o) connected lines
//! ```
//!
//! See the `Cargo.toml` file for Copyright and license details.

#![no_std]
#![no_main]

// Ensure we halt the program on panic (if we don't mention this crate it won't
// be linked)
use panic_halt as _;

// Pull in any important traits
use pimoroni_pico_lipo_16mb::hal::prelude::*;

// GPIO traits
use embedded_hal::digital::OutputPin;

// For LCD display
use hd44780_driver::HD44780;

/// Entry point to our bare-metal application.
///
/// The `#[pimoroni_pico_lipo_16mb::entry]` macro ensures the Cortex-M start-up code calls this function
/// as soon as all global variables and the spinlock are initialised.
#[pimoroni_pico_lipo_16mb::entry]
fn main() -> ! {
// Grab our singleton objects
let mut pac = pimoroni_pico_lipo_16mb::hal::pac::Peripherals::take().unwrap();
let core = pimoroni_pico_lipo_16mb::hal::pac::CorePeripherals::take().unwrap();

// Set up the watchdog driver - needed by the clock setup code
let mut watchdog = pimoroni_pico_lipo_16mb::hal::Watchdog::new(pac.WATCHDOG);

// Configure the clocks
// The default is to generate a 125 MHz system clock
let clocks = pimoroni_pico_lipo_16mb::hal::clocks::init_clocks_and_plls(
pimoroni_pico_lipo_16mb::XOSC_CRYSTAL_FREQ,
pac.XOSC,
pac.CLOCKS,
pac.PLL_SYS,
pac.PLL_USB,
&mut pac.RESETS,
&mut watchdog,
)
.ok()
.unwrap();

// The single-cycle I/O block controls our GPIO pins
let sio = pimoroni_pico_lipo_16mb::hal::Sio::new(pac.SIO);

// Set the pins up according to their function on this particular board
let pins = pimoroni_pico_lipo_16mb::Pins::new(
pac.IO_BANK0,
pac.PADS_BANK0,
sio.gpio_bank0,
&mut pac.RESETS,
);

let mut led_pin = pins.led.into_push_pull_output();

// The delay object lets us wait for specified amounts of time
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());

// Init pins
let rs = pins.gpio7.into_push_pull_output();
let en = pins.gpio6.into_push_pull_output();
let d4 = pins.gpio5.into_push_pull_output();
let d5 = pins.gpio4.into_push_pull_output();
let d6 = pins.gpio3.into_push_pull_output();
let d7 = pins.gpio2.into_push_pull_output();

// LCD Init
let mut lcd = HD44780::new_4bit(rs, en, d4, d5, d6, d7, &mut delay).unwrap();

loop {
// Clear the screen
lcd.reset(&mut delay).unwrap();
lcd.clear(&mut delay).unwrap();

// Write to the top line
lcd.write_str("rp-hal on", &mut delay).unwrap();

// Move the cursor
lcd.set_cursor_pos(40, &mut delay).unwrap();

// Write more more text
lcd.write_str("HD44780! ", &mut delay).unwrap();
let mut char_count = 9;
for ch in "move along!.. ".chars() {
if char_count > 15 {
// Switch autoscroll on
lcd.set_autoscroll(true, &mut delay).unwrap();
}
led_pin.set_high().unwrap();
lcd.write_char(ch, &mut delay).unwrap();
char_count += 1;
delay.delay_us(400_000); //0.4s
led_pin.set_low().unwrap();
delay.delay_us(100_000); //0.1s
}
lcd.set_autoscroll(false, &mut delay).unwrap();
}
}
Loading