Fixed for update to latest embedded and rp hal stuff

This commit is contained in:
JP Stringham
2025-12-26 18:26:13 -05:00
parent 025979f520
commit 2e48b4927b
5 changed files with 20 additions and 1947 deletions

1899
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -11,8 +11,6 @@ defmt-rtt = "1.0.0"
embedded-hal = "1.0.0" embedded-hal = "1.0.0"
rp2040-boot2 = "0.3.0" rp2040-boot2 = "0.3.0"
rp2040-hal = "0.11.0" rp2040-hal = "0.11.0"
tiny-rng = "0.2.0"
probe-rs = "0.30.0"
panic-probe = { version = "1.0.0", features = [ "print-rtt" ] } panic-probe = { version = "1.0.0", features = [ "print-rtt" ] }

View File

@@ -1,5 +1,5 @@
use embedded_hal::digital::v2::InputPin;
use rp2040_hal::gpio::{Pin, DynPinId, FunctionSioInput, PullUp}; use rp2040_hal::gpio::{Pin, DynPinId, FunctionSioInput, PullUp};
use embedded_hal::digital::InputPin;
pub struct Dpad { pub struct Dpad {
pinarray: [Pin<DynPinId, FunctionSioInput, PullUp>; 4] pinarray: [Pin<DynPinId, FunctionSioInput, PullUp>; 4]
@@ -14,7 +14,7 @@ impl Dpad {
} }
} }
pub fn get_state(&self) -> DpadState { pub fn get_state(&mut self) -> DpadState {
let up = self.pinarray[0].is_low().unwrap(); let up = self.pinarray[0].is_low().unwrap();
let right = self.pinarray[1].is_low().unwrap(); let right = self.pinarray[1].is_low().unwrap();
let down = self.pinarray[2].is_low().unwrap(); let down = self.pinarray[2].is_low().unwrap();

View File

@@ -1,12 +1,12 @@
#![no_std] #![no_std]
#![no_main] #![no_main]
use embedded_hal::digital::v2::{OutputPin, InputPin}; use embedded_hal::{
digital::OutputPin,
use embedded_hal::blocking::i2c::Write; i2c::I2c
};
use hal::gpio::bank0::{Gpio0, Gpio1}; use hal::gpio::bank0::{Gpio8, Gpio9};
use hal::gpio::PullDown; use rp2040_hal::gpio::PullUp;
use rp2040_hal as hal; use rp2040_hal as hal;
use hal::{ use hal::{
pac as pac, pac as pac,
@@ -14,12 +14,10 @@ use hal::{
fugit::RateExtU32, fugit::RateExtU32,
}; };
use defmt as _;
use panic_probe as _; use panic_probe as _;
mod sprite; mod sprite;
mod dpad;
use crate::dpad::Dpad;
use crate::sprite::*; use crate::sprite::*;
#[link_section = ".boot_loader"] #[link_section = ".boot_loader"]
@@ -86,8 +84,8 @@ fn main() -> ! {
// peripheral isn't available on these pins! // peripheral isn't available on these pins!
let mut i2c = hal::I2C::i2c0( let mut i2c = hal::I2C::i2c0(
pac.I2C0, pac.I2C0,
pins.gpio0.into_function(), pins.gpio8.reconfigure(),
pins.gpio1.into_function(), // Try `not_an_scl_pin` here pins.gpio9.reconfigure(), // Try `not_an_scl_pin` here
400.kHz(), 400.kHz(),
&mut pac.RESETS, &mut pac.RESETS,
&clocks.system_clock, &clocks.system_clock,
@@ -132,18 +130,6 @@ fn main() -> ! {
sprites[0].y = 30; sprites[0].y = 30;
sprites[0].visible = true; sprites[0].visible = true;
let dpad = Dpad::new([
pins.gpio2.into_pull_up_input().into_dyn_pin(),
pins.gpio3.into_pull_up_input().into_dyn_pin(),
pins.gpio4.into_pull_up_input().into_dyn_pin(),
pins.gpio5.into_pull_up_input().into_dyn_pin(),
]);
// let dpad_down = pins.gpio2.into_pull_up_input();
// let dpad_left = pins.gpio3.into_pull_up_input();
// let dpad_up = pins.gpio4.into_pull_up_input();
// let dpad_right = pins.gpio5.into_pull_up_input();
loop { loop {
gfx_buf.iter_mut().for_each(|x| *x = 0); gfx_buf.iter_mut().for_each(|x| *x = 0);
@@ -152,24 +138,6 @@ fn main() -> ! {
if s.visible { if s.visible {
sprite_atlas.draw_sprite(s.sprite_index, s.x as u8, s.y as u8, s.flip, &mut gfx_buf); sprite_atlas.draw_sprite(s.sprite_index, s.x as u8, s.y as u8, s.flip, &mut gfx_buf);
} }
let dpad_state = dpad.get_state();
if dpad_state.up {
s.y -= 1;
}
if dpad_state.down {
s.y += 1;
}
if dpad_state.left {
s.x -= 1;
s.flip = SpriteFlip::None;
}
if dpad_state.right {
s.x += 1;
s.flip = SpriteFlip::Horizontal;
}
}); });
sprite_atlas.draw_string(10, 10, "Hello World!", &mut gfx_buf); sprite_atlas.draw_string(10, 10, "Hello World!", &mut gfx_buf);
@@ -239,7 +207,7 @@ fn draw_bresenham_line(
fn blit_framebuffer( fn blit_framebuffer(
i2c: &mut hal::I2C<pac::I2C0, (Pin<Gpio0, FunctionI2C, PullDown>, Pin<Gpio1, FunctionI2C, PullDown>)>, i2c: &mut hal::I2C<pac::I2C0, (Pin<Gpio8, FunctionI2C, PullUp>, Pin<Gpio9, FunctionI2C, PullUp>)>,
graphic: &[u8; 8192]) { graphic: &[u8; 8192]) {
// for each row of 8x8 pixels // for each row of 8x8 pixels
@@ -299,7 +267,7 @@ fn blit_framebuffer(
// transformed_graphic // transformed_graphic
// } // }
fn set_col(i2c: &mut hal::I2C<pac::I2C0, (Pin<Gpio0, FunctionI2C, PullDown>, Pin<Gpio1, FunctionI2C, PullDown>)>, fn set_col(i2c: &mut hal::I2C<pac::I2C0, (Pin<Gpio8, FunctionI2C, PullUp>, Pin<Gpio9, FunctionI2C, PullUp>)>,
col: u8) { col: u8) {
let col_lo = col & 0b0000_1111; let col_lo = col & 0b0000_1111;
let col_hi = (col & 0b1111_0000) >> 4; let col_hi = (col & 0b1111_0000) >> 4;
@@ -308,12 +276,12 @@ fn set_col(i2c: &mut hal::I2C<pac::I2C0, (Pin<Gpio0, FunctionI2C, PullDown>, Pin
send_command(i2c, &SH1106Cmd::SetColumnHi, col_hi); send_command(i2c, &SH1106Cmd::SetColumnHi, col_hi);
} }
fn set_page(i2c: &mut hal::I2C<pac::I2C0, (Pin<Gpio0, FunctionI2C, PullDown>, Pin<Gpio1, FunctionI2C, PullDown>)>, fn set_page(i2c: &mut hal::I2C<pac::I2C0, (Pin<Gpio8, FunctionI2C, PullUp>, Pin<Gpio9, FunctionI2C, PullUp>)>,
page: u8) { page: u8) {
send_command(i2c, &SH1106Cmd::SetPage, page & 0b0000_0111); send_command(i2c, &SH1106Cmd::SetPage, page & 0b0000_0111);
} }
fn clr_screen(i2c: &mut hal::I2C<pac::I2C0, (Pin<Gpio0, FunctionI2C, PullDown>, Pin<Gpio1, FunctionI2C, PullDown>)>) { fn clr_screen(i2c: &mut hal::I2C<pac::I2C0, (Pin<Gpio8, FunctionI2C, PullUp>, Pin<Gpio9, FunctionI2C, PullUp>)>) {
let mut writebuf = [0u8; 132*8+1]; let mut writebuf = [0u8; 132*8+1];
writebuf[0] = 0b0100_0000; writebuf[0] = 0b0100_0000;
@@ -329,7 +297,7 @@ fn clr_screen(i2c: &mut hal::I2C<pac::I2C0, (Pin<Gpio0, FunctionI2C, PullDown>,
fn write_cel_pixels( fn write_cel_pixels(
i2c: &mut hal::I2C<pac::I2C0, (Pin<Gpio0, FunctionI2C, PullDown>, Pin<Gpio1, FunctionI2C, PullDown>)>, i2c: &mut hal::I2C<pac::I2C0, (Pin<Gpio8, FunctionI2C, PullUp>, Pin<Gpio9, FunctionI2C, PullUp>)>,
data: &[u8]) { data: &[u8]) {
let mut writebuf = [0b0100_0000u8; 9]; let mut writebuf = [0b0100_0000u8; 9];
@@ -343,7 +311,7 @@ fn write_cel_pixels(
} }
fn send_command(i2c: &mut hal::I2C<pac::I2C0, (Pin<Gpio0, FunctionI2C, PullDown>, Pin<Gpio1, FunctionI2C, PullDown>)>, fn send_command(i2c: &mut hal::I2C<pac::I2C0, (Pin<Gpio8, FunctionI2C, PullUp>, Pin<Gpio9, FunctionI2C, PullUp>)>,
command: &SH1106Cmd, command: &SH1106Cmd,
data:u8) { data:u8) {
let mut writebuf: [u8; 2] = [0; 2]; let mut writebuf: [u8; 2] = [0; 2];