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

View File

@@ -1,12 +1,12 @@
#![no_std]
#![no_main]
use embedded_hal::digital::v2::{OutputPin, InputPin};
use embedded_hal::blocking::i2c::Write;
use hal::gpio::bank0::{Gpio0, Gpio1};
use hal::gpio::PullDown;
use embedded_hal::{
digital::OutputPin,
i2c::I2c
};
use hal::gpio::bank0::{Gpio8, Gpio9};
use rp2040_hal::gpio::PullUp;
use rp2040_hal as hal;
use hal::{
pac as pac,
@@ -14,12 +14,10 @@ use hal::{
fugit::RateExtU32,
};
use defmt as _;
use panic_probe as _;
mod sprite;
mod dpad;
use crate::dpad::Dpad;
use crate::sprite::*;
#[link_section = ".boot_loader"]
@@ -86,8 +84,8 @@ fn main() -> ! {
// peripheral isn't available on these pins!
let mut i2c = hal::I2C::i2c0(
pac.I2C0,
pins.gpio0.into_function(),
pins.gpio1.into_function(), // Try `not_an_scl_pin` here
pins.gpio8.reconfigure(),
pins.gpio9.reconfigure(), // Try `not_an_scl_pin` here
400.kHz(),
&mut pac.RESETS,
&clocks.system_clock,
@@ -132,18 +130,6 @@ fn main() -> ! {
sprites[0].y = 30;
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 {
gfx_buf.iter_mut().for_each(|x| *x = 0);
@@ -152,24 +138,6 @@ fn main() -> ! {
if s.visible {
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);
@@ -239,7 +207,7 @@ fn draw_bresenham_line(
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]) {
// for each row of 8x8 pixels
@@ -299,7 +267,7 @@ fn blit_framebuffer(
// 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) {
let col_lo = col & 0b0000_1111;
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);
}
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) {
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];
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(
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]) {
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,
data:u8) {
let mut writebuf: [u8; 2] = [0; 2];