-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
227 additions
and
1,654 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,56 @@ | ||
[package] | ||
edition = "2021" | ||
name = "pico" | ||
name = "segment_led_pico" | ||
version = "0.1.0" | ||
authors = ["Zelzahn <[email protected]>"] | ||
resolver = "2" | ||
|
||
[dependencies] | ||
# embassy-embedded-hal = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git", features = ["defmt"] } | ||
# not needed | ||
# embassy-sync = { version = "0.5.0", git = "https://github.com/embassy-rs/embassy.git", features = ["defmt"] } | ||
embassy-executor = { version = "0.5.0", git = "https://github.com/embassy-rs/embassy.git", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers"] } | ||
embassy-time = { version = "0.3", git = "https://github.com/embassy-rs/embassy.git", features = ["defmt", "defmt-timestamp-uptime"] } | ||
# embassy-rp = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git", features = ["defmt", "unstable-pac", "time-driver"] } | ||
embassy-rp = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git", features = ["defmt", "unstable-pac", "time-driver", "critical-section-impl"] } | ||
# not needed | ||
# embassy-futures = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy.git" } | ||
cortex-m = "0.7" | ||
cortex-m-rt = "0.7" | ||
embedded-hal = { version = "0.2.5", features = ["unproven"] } | ||
|
||
defmt = "0.3" | ||
defmt-rtt = "0.4" | ||
# both not needed | ||
fixed = "1.23.1" | ||
fixed-macro = "1.2" | ||
|
||
cortex-m = { version = "0.7.7", features = ["inline-asm"] } | ||
cortex-m-rt = "0.7.3" | ||
panic-probe = { version = "0.3", features = ["print-defmt"] } | ||
|
||
# These 2 seems to be not needed | ||
# futures = { version = "0.3.17", default-features = false, features = ["async-await", "cfg-target-has-atomic", "unstable"] } | ||
# heapless = "0.8" | ||
|
||
|
||
embedded-hal = "1.0.0" | ||
rp2040-hal = "0.10.0" | ||
# all below not needed | ||
# embedded-hal-async = "1.0.0" | ||
# embedded-hal-bus = { version = "0.1.0", features = ["async"] } | ||
# embedded-io-async = { version = "0.6.1", features = ["defmt-03"] } | ||
#embedded-storage = { version = "0.3" } | ||
# static_cell = "2" | ||
# portable-atomic = { version = "1.5", features = ["critical-section"] } | ||
# log = "0.4" | ||
# pio-proc = "0.2" | ||
# pio = "0.2.1" | ||
# rand = { version = "0.8.5", default-features = false } | ||
# We're using a Pico by default on this template | ||
rp-pico = "0.9" | ||
fugit = "0.3.7" | ||
|
||
# If you're not going to use a Board Support Package you'll need these: | ||
# rp2040-hal = { version="0.10", features=["rt", "critical-section-impl"] } | ||
# rp2040-boot2 = "0.2" | ||
|
||
# cargo build/run | ||
[profile.dev] | ||
codegen-units = 1 | ||
debug = 2 | ||
debug-assertions = true | ||
incremental = false | ||
opt-level = 3 | ||
overflow-checks = true | ||
|
||
# cargo build/run --release | ||
[profile.release] | ||
codegen-units = 1 | ||
debug = 2 | ||
debug-assertions = false | ||
incremental = false | ||
lto = 'fat' | ||
opt-level = 3 | ||
overflow-checks = false | ||
|
||
# do not optimize proc-macro crates = faster builds from scratch | ||
[profile.dev.build-override] | ||
codegen-units = 8 | ||
debug = false | ||
debug-assertions = false | ||
opt-level = 0 | ||
overflow-checks = false | ||
|
||
[profile.release.build-override] | ||
codegen-units = 8 | ||
debug = false | ||
debug-assertions = false | ||
opt-level = 0 | ||
overflow-checks = false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
[default.probe] | ||
protocol = "Swd" | ||
speed = 20000 | ||
# If you only have one probe cargo embed will pick automatically | ||
# Otherwise: add your probe's VID/PID/serial to filter | ||
|
||
## rust-dap | ||
# usb_vid = "6666" | ||
# usb_pid = "4444" | ||
# serial = "test" | ||
|
||
|
||
[default.flashing] | ||
enabled = true | ||
|
||
[default.reset] | ||
enabled = true | ||
halt_afterwards = false | ||
|
||
[default.general] | ||
chip = "RP2040" | ||
log_level = "WARN" | ||
# RP2040 does not support connect_under_reset | ||
connect_under_reset = false | ||
|
||
[default.rtt] | ||
enabled = true | ||
up_mode = "NoBlockSkip" | ||
channels = [ | ||
{ up = 0, down = 0, name = "name", up_mode = "NoBlockSkip", format = "Defmt" }, | ||
] | ||
timeout = 3000 | ||
show_timestamps = true | ||
log_enabled = false | ||
log_path = "./logs" | ||
|
||
[default.gdb] | ||
enabled = false | ||
gdb_connection_string = "127.0.0.1:2345" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,15 @@ | ||
MEMORY { | ||
BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 | ||
FLASH : ORIGIN = 0x10000100, LENGTH = 1792K - 0x100 | ||
STORAGE : ORIGIN = ORIGIN(FLASH) + LENGTH(FLASH), LENGTH = 256K | ||
|
||
/* Pick one of the two options for RAM layout */ | ||
BOOT2 : ORIGIN = 0x10000000, LENGTH = 0x100 | ||
FLASH : ORIGIN = 0x10000100, LENGTH = 2048K - 0x100 | ||
RAM : ORIGIN = 0x20000000, LENGTH = 256K | ||
} | ||
|
||
/* OPTION A: Use all RAM banks as one big block */ | ||
/* Reasonable, unless you are doing something */ | ||
/* really particular with DMA or other concurrent */ | ||
/* access that would benefit from striping */ | ||
RAM : ORIGIN = 0x20000000, LENGTH = 264K | ||
EXTERN(BOOT2_FIRMWARE) | ||
|
||
/* OPTION B: Keep the unstriped sections separate */ | ||
/* RAM: ORIGIN = 0x20000000, LENGTH = 256K */ | ||
/* SCRATCH_A: ORIGIN = 0x20040000, LENGTH = 4K */ | ||
/* SCRATCH_B: ORIGIN = 0x20041000, LENGTH = 4K */ | ||
} | ||
__flash_size = 2097152; | ||
__storage_flash_size = 262144; | ||
__storage_flash_offset = ORIGIN(STORAGE) - ORIGIN(BOOT2); | ||
SECTIONS { | ||
/* ### Boot loader */ | ||
.boot2 ORIGIN(BOOT2) : | ||
{ | ||
KEEP(*(.boot2)); | ||
} > BOOT2 | ||
} INSERT BEFORE .text; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,104 @@ | ||
//! Blinks the LED on a Pico board | ||
//! | ||
//! This will blink an LED attached to GP25, which is the pin the Pico uses for the on-board LED. | ||
#![no_std] | ||
#![no_main] | ||
|
||
use embassy_executor::Spawner; | ||
use embassy_rp::gpio::{Level, Output}; | ||
use embassy_rp::i2c::{self, Config}; | ||
use embassy_time::Delay; | ||
use embedded_hal::delay::DelayNs; | ||
use embedded_hal::i2c::I2c; | ||
use {defmt_rtt as _, panic_probe as _}; | ||
use bsp::entry; | ||
use defmt::*; | ||
use defmt_rtt as _; | ||
use embedded_hal::blocking::i2c::Write; | ||
use panic_probe as _; | ||
|
||
const ADDRESS: u8 = 0x24; | ||
// Time handling traits: | ||
use fugit::RateExtU32; | ||
|
||
// Provide an alias for our BSP so we can switch targets quickly. | ||
// Uncomment the BSP you included in Cargo.toml, the rest of the code does not need to change. | ||
use rp_pico as bsp; | ||
// use sparkfun_pro_micro_rp2040 as bsp; | ||
|
||
use bsp::hal::{ | ||
clocks::{init_clocks_and_plls, Clock}, | ||
pac, | ||
sio::Sio, | ||
watchdog::Watchdog, | ||
}; | ||
|
||
/// The inner workings of this is a complete mystery, but it works. | ||
fn to_data(i: usize) -> u8 { | ||
[0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F][(i - 48) % 10] | ||
[0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F][i % 10] | ||
} | ||
|
||
#[embassy_executor::main] | ||
async fn main(_spawner: Spawner) { | ||
let p = embassy_rp::init(Default::default()); | ||
#[entry] | ||
fn main() -> ! { | ||
info!("Program start"); | ||
let mut pac = pac::Peripherals::take().unwrap(); | ||
let core = pac::CorePeripherals::take().unwrap(); | ||
let mut watchdog = Watchdog::new(pac.WATCHDOG); | ||
let sio = Sio::new(pac.SIO); | ||
|
||
// Blink the onboard led | ||
let mut led = Output::new(p.PIN_25, Level::Low); | ||
// External high-speed crystal on the pico board is 12Mhz | ||
let external_xtal_freq_hz = 12_000_000u32; | ||
let clocks = init_clocks_and_plls( | ||
external_xtal_freq_hz, | ||
pac.XOSC, | ||
pac.CLOCKS, | ||
pac.PLL_SYS, | ||
pac.PLL_USB, | ||
&mut pac.RESETS, | ||
&mut watchdog, | ||
) | ||
.ok() | ||
.unwrap(); | ||
|
||
let sda = p.PIN_0; | ||
let scl = p.PIN_1; | ||
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); | ||
|
||
let mut connection: i2c::I2c<'_, embassy_rp::peripherals::I2C0, i2c::Blocking> = | ||
i2c::I2c::new_blocking(p.I2C0, scl, sda, Config::default()); | ||
let mut delay = Delay; | ||
let pins = bsp::Pins::new( | ||
pac.IO_BANK0, | ||
pac.PADS_BANK0, | ||
sio.gpio_bank0, | ||
&mut pac.RESETS, | ||
); | ||
|
||
delay.delay_ns(2_000_000_000); | ||
led.set_high(); | ||
// Configure two pins as being I²C, not GPIO | ||
let sda_pin: bsp::hal::gpio::Pin<_, bsp::hal::gpio::FunctionI2C, _> = pins.gpio4.reconfigure(); | ||
let scl_pin: bsp::hal::gpio::Pin<_, bsp::hal::gpio::FunctionI2C, _> = pins.gpio5.reconfigure(); | ||
|
||
// Turn on | ||
let _ = connection.write(ADDRESS, &[0x81]); | ||
// Create the I²C driver, using the two pre-configured pins. This will fail | ||
// at compile time if the pins are in the wrong mode, or if this I²C | ||
// peripheral isn't available on these pins! | ||
let mut i2c = bsp::hal::I2C::i2c0( | ||
pac.I2C0, | ||
sda_pin, | ||
scl_pin, | ||
400.kHz(), | ||
&mut pac.RESETS, | ||
&clocks.system_clock, | ||
); | ||
|
||
// Set display on | ||
i2c.write(0x24u8, &[0x81]).unwrap(); | ||
|
||
// Set brightness to max | ||
let _ = connection.write(ADDRESS, &[(0<<4) | 0x01]); | ||
i2c.write(0x24u8, &[(0 << 4) | 0x01]).unwrap(); | ||
|
||
let now = "13:30"; | ||
let now_bytes = now.as_bytes(); | ||
// Simple incrementing counter | ||
let mut ctr: [u8; 4] = [0, 0, 0, 0]; | ||
loop { | ||
for (i, &number) in ctr.iter().enumerate() { | ||
delay.delay_ms(500); | ||
|
||
for (i, &number) in now_bytes.iter().enumerate() { | ||
let dig = to_data(number.into()); | ||
let dig = to_data(number.into()); | ||
i2c.write(0x34 + (i as u8), &[dig]).unwrap(); | ||
} | ||
|
||
let _ = connection.write(0x34 + (i as u8), &[dig]); | ||
ctr = match ctr { | ||
[a, b, c, 9] => [a, b, c + 1, 0], | ||
[a, b, 9, d] => [a, b + 1, 0, d], | ||
[a, 9, c, d] => [a + 1, 0, c, d], | ||
[9, b, c, d] => [0, b, c, d], | ||
[a, b, c, d] => [a, b, c, d + 1], | ||
}; | ||
} | ||
|
||
delay.delay_ns(1_000_000_000); | ||
led.set_low(); | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.