#![no_std]
#![no_main]
use adafruit_feather_rp2040 as bsp;
use bsp::{entry, hal, XOSC_CRYSTAL_FREQ};
use hal::{fugit::RateExtU32, i2c::I2C};
use embedded_hal::{delay::DelayNs, digital::OutputPin, i2c::I2c};
#[cfg(not(feature = "defmt"))]
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
loop {}
}
#[cfg(feature = "defmt")]
use {defmt_rtt as _, panic_probe as _};
#[entry]
fn main() -> ! {
let mut pac = hal::pac::Peripherals::take().unwrap();
let _core = hal::pac::CorePeripherals::take().unwrap();
let mut watchdog = hal::watchdog::Watchdog::new(pac.WATCHDOG);
let clocks = hal::clocks::init_clocks_and_plls(
XOSC_CRYSTAL_FREQ,
pac.XOSC,
pac.CLOCKS,
pac.PLL_SYS,
pac.PLL_USB,
&mut pac.RESETS,
&mut watchdog,
)
.unwrap();
let mut timer = hal::Timer::new(pac.TIMER, &mut pac.RESETS, &clocks);
let sio = hal::Sio::new(pac.SIO);
let pins = hal::gpio::Pins::new(
pac.IO_BANK0,
pac.PADS_BANK0,
sio.gpio_bank0,
&mut pac.RESETS,
);
let mut led = pins.gpio13.into_push_pull_output();
let mut lcd_resetn = pins.gpio7.into_push_pull_output();
let mut i2c = I2C::i2c1(
pac.I2C1,
pins.gpio2.reconfigure(),
pins.gpio3.reconfigure(),
400.kHz(),
&mut pac.RESETS,
&clocks.system_clock,
);
const LCD_ADDRESS: u8 = 0x3e;
lcd_resetn.set_high().unwrap();
timer.delay_us(50_000);
i2c.write(LCD_ADDRESS, &[0b00_000000, 0b0011_1000]).unwrap();
timer.delay_us(30);
i2c.write(LCD_ADDRESS, &[0b00_000000, 0b0011_1001]).unwrap();
timer.delay_us(30);
i2c.write(LCD_ADDRESS, &[0b00_000000, 0b0001_0100]).unwrap();
timer.delay_us(30);
i2c.write(LCD_ADDRESS, &[0b00_000000, 0b0111_0000]).unwrap();
timer.delay_us(30);
i2c.write(LCD_ADDRESS, &[0b00_000000, 0b0101_0110]).unwrap();
timer.delay_us(30);
i2c.write(LCD_ADDRESS, &[0b00_000000, 0b0110_1100]).unwrap();
timer.delay_us(200_000);
i2c.write(LCD_ADDRESS, &[0b00_000000, 0b0011_1000]).unwrap();
timer.delay_us(30);
i2c.write(LCD_ADDRESS, &[0b00_000000, 0b0000_1110]).unwrap();
timer.delay_us(30);
i2c.write(LCD_ADDRESS, &[0b00_000000, 0b0000_0001]).unwrap();
timer.delay_us(2_000);
#[rustfmt::skip]
const PATTERNS: &[&[u8]] = &[
&[
0b11_000000, 0b0011_0000,
0b11_000000, 0b0011_0001,
0b11_000000, 0b0011_0010,
0b11_000000, 0b0011_0011,
0b11_000000, 0b0011_0100,
0b11_000000, 0b0011_0101,
0b11_000000, 0b0011_0110,
0b01_000000, 0b0011_0111,
],
&[
0b11_000000, 0b0100_0001,
0b11_000000, 0b0100_0010,
0b11_000000, 0b0100_0011,
0b11_000000, 0b0100_0100,
0b11_000000, 0b0100_0101,
0b11_000000, 0b0100_0110,
0b11_000000, 0b0100_0111,
0b01_000000, 0b0100_1000,
],
&[
0b11_000000, 0b0110_0001,
0b11_000000, 0b0110_0010,
0b11_000000, 0b0110_0011,
0b11_000000, 0b0110_0100,
0b11_000000, 0b0110_0101,
0b11_000000, 0b0110_0110,
0b11_000000, 0b0110_0111,
0b01_000000, 0b0110_1000,
],
&[
0b11_000000, 0b1011_0001,
0b11_000000, 0b1011_0010,
0b11_000000, 0b1011_0011,
0b11_000000, 0b1011_0100,
0b11_000000, 0b1011_0101,
0b11_000000, 0b1011_0110,
0b11_000000, 0b1011_0111,
0b01_000000, 0b1011_1000,
],
];
loop {
for (i, p) in PATTERNS.iter().enumerate() {
if i & 1 == 0 {
led.set_high().unwrap();
i2c.write(LCD_ADDRESS, &[0b00_000000, 0b1000_0000]).unwrap();
} else {
led.set_low().unwrap();
i2c.write(LCD_ADDRESS, &[0b00_000000, 0b1100_0000]).unwrap();
}
timer.delay_us(30);
i2c.write(LCD_ADDRESS, p).unwrap();
timer.delay_us(500_000);
}
}
}