From 6d14cdbe2a45be1ab2331b082caf50a526b0e831 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Tue, 14 Nov 2023 08:04:31 -0500 Subject: [PATCH] Build a color test pattern. --- pico-blink/src/main.rs | 104 +++++++++++++++++++++++++++++++++++------ 1 file changed, 91 insertions(+), 13 deletions(-) diff --git a/pico-blink/src/main.rs b/pico-blink/src/main.rs index 57ff34a..e857ac9 100644 --- a/pico-blink/src/main.rs +++ b/pico-blink/src/main.rs @@ -120,49 +120,127 @@ fn main() -> ! { let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); - let mut spi_clk = pins.gpio10.into_push_pull_output(); - let mut spi_sdo = pins.gpio11.into_push_pull_output(); - /* + let mut spi_clk = pins.gpio10.into_function(); + let mut spi_sdo = pins.gpio11.into_function(); let spi = Spi::<_, _, _, 8>::new(pac.SPI1, (spi_sdo, spi_clk)); let mut spi = spi.init( &mut pac.RESETS, clocks.peripheral_clock.freq(), 1.MHz(), - embedded_hal::spi::MODE_0, + embedded_hal::spi::MODE_1, ); */ let mut led_pin = pins.led.into_push_pull_output(); let mut blue_pin = pins.gpio3.into_push_pull_output(); led_pin.set_high().unwrap(); + delay.delay_ms(500); + led_pin.set_low().unwrap(); + + let mut spi_clk = pins.gpio10.into_push_pull_output(); + let mut spi_sdo = pins.gpio11.into_push_pull_output(); spi_clk.set_low(); spi_sdo.set_low(); + + let bits_1 = &[ + 0, 0, 0, 0, + 0xe1, 0x80, 0x00, 0x00, + 0xe1, 0x00, 0x80, 0x00, + 0xe1, 0x00, 0x00, 0x80, + 0xe1, 0x80, 0x00, 0x00, + 0xe1, 0x00, 0x80, 0x00, + 0xe1, 0x00, 0x00, 0x80, + 0xe1, 0x80, 0x00, 0x00, + 0xe1, 0x00, 0x80, 0x00, + 0xe1, 0x00, 0x00, 0x80, + 0xe1, 0x80, 0x00, 0x00, + 0xe1, 0x00, 0x80, 0x00, + 0xe1, 0x00, 0x00, 0x80, + 0xff, 0xff, 0xff, 0xff, + ]; + let bits_2 = &[ + 0, 0, 0, 0, + 0xe1, 0x00, 0x80, 0x00, + 0xe1, 0x00, 0x00, 0x80, + 0xe1, 0x80, 0x00, 0x00, + 0xe1, 0x00, 0x80, 0x00, + 0xe1, 0x00, 0x00, 0x80, + 0xe1, 0x80, 0x00, 0x00, + 0xe1, 0x00, 0x80, 0x00, + 0xe1, 0x00, 0x00, 0x80, + 0xe1, 0x80, 0x00, 0x00, + 0xe1, 0x00, 0x80, 0x00, + 0xe1, 0x00, 0x00, 0x80, + 0xe1, 0x80, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff, + ]; + let bits_3 = &[ + 0, 0, 0, 0, + 0xe1, 0x00, 0x00, 0x80, + 0xe1, 0x80, 0x00, 0x00, + 0xe1, 0x00, 0x80, 0x00, + 0xe1, 0x00, 0x00, 0x80, + 0xe1, 0x80, 0x00, 0x00, + 0xe1, 0x00, 0x80, 0x00, + 0xe1, 0x00, 0x00, 0x80, + 0xe1, 0x80, 0x00, 0x00, + 0xe1, 0x00, 0x80, 0x00, + 0xe1, 0x00, 0x00, 0x80, + 0xe1, 0x80, 0x00, 0x00, + 0xe1, 0x00, 0x80, 0x00, + 0xff, 0xff, 0xff, 0xff, + ]; + + let a = 15 / 2; + loop { send( &mut spi_sdo, &mut spi_clk, &mut delay, - &[ - 0xe1, 0x80, 0x00, 0x00, - 0xe1, 0x00, 0x80, 0x00, - 0xe1, 0x00, 0x00, 0x80, - ], + bits_1, ); spi_clk.set_low(); spi_sdo.set_low(); + delay.delay_ms(500); + + send( + &mut spi_sdo, + &mut spi_clk, + &mut delay, + bits_2, + ); + spi_clk.set_low(); + spi_sdo.set_low(); + delay.delay_ms(500); + + send( + &mut spi_sdo, + &mut spi_clk, + &mut delay, + bits_3, + ); + spi_clk.set_low(); + spi_sdo.set_low(); + delay.delay_ms(500); + /* - spi.write(&[ - 0, 0, 0, 0, 0xf0, 0x80, 0x0, 0x0, 0xe1, 0x0, 0x80, 0x0, 0xe1, 0x0, 0x0, 0x80, 0xff, - 0xff, 0xff, 0xff, - ]); + spi.write(bits_1); + delay.delay_ms(500); + spi.write(bits_2); + delay.delay_ms(500); + spi.write(bits_3); + delay.delay_ms(500); */ + /* led_pin.set_high().unwrap(); blue_pin.set_low().unwrap(); delay.delay_ms(500); led_pin.set_low().unwrap(); blue_pin.set_high().unwrap(); delay.delay_ms(500); + */ } }