Compare commits

..

No commits in common. "6d14cdbe2a45be1ab2331b082caf50a526b0e831" and "168ba6eb401b53513ef979b794861559934b88c5" have entirely different histories.

1 changed files with 14 additions and 95 deletions

View File

@ -29,8 +29,8 @@ fn send_byte<I, J, P>(
J: PinId, J: PinId,
P: PullType, P: PullType,
{ {
(0..8).for_each(|bit| { (0..7).for_each(|bit| {
if byte & (1 << (8 - bit)) > 0 { if byte & (1 << (7 - bit)) > 0 {
data.set_high(); data.set_high();
} else { } else {
data.set_low(); data.set_low();
@ -120,127 +120,46 @@ fn main() -> ! {
let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz()); 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 spi = Spi::<_, _, _, 8>::new(pac.SPI1, (spi_sdo, spi_clk));
let mut spi = spi.init( let mut spi = spi.init(
&mut pac.RESETS, &mut pac.RESETS,
clocks.peripheral_clock.freq(), clocks.peripheral_clock.freq(),
1.MHz(), 1.MHz(),
embedded_hal::spi::MODE_1, embedded_hal::spi::MODE_0,
); );
*/ */
let mut led_pin = pins.led.into_push_pull_output(); let mut led_pin = pins.led.into_push_pull_output();
let mut blue_pin = pins.gpio3.into_push_pull_output(); let mut blue_pin = pins.gpio3.into_push_pull_output();
led_pin.set_high().unwrap(); 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_clk.set_low();
spi_sdo.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 { loop {
send( send(
&mut spi_sdo, &mut spi_sdo,
&mut spi_clk, &mut spi_clk,
&mut delay, &mut delay,
bits_1, &[
0, 0, 0, 0, 0xf0, 0x80, 0x0, 0x0, 0xe1, 0x0, 0x80, 0x0, 0xe1, 0x0, 0x0, 0x80, 0xff,
0xff, 0xff, 0xff,
],
); );
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(bits_1); spi.write(&[
delay.delay_ms(500); 0, 0, 0, 0, 0xf0, 0x80, 0x0, 0x0, 0xe1, 0x0, 0x80, 0x0, 0xe1, 0x0, 0x0, 0x80, 0xff,
spi.write(bits_2); 0xff, 0xff, 0xff,
delay.delay_ms(500); ]);
spi.write(bits_3);
delay.delay_ms(500);
*/ */
/*
led_pin.set_high().unwrap(); led_pin.set_high().unwrap();
blue_pin.set_low().unwrap(); blue_pin.set_low().unwrap();
delay.delay_ms(500); delay.delay_ms(500);
led_pin.set_low().unwrap(); led_pin.set_low().unwrap();
blue_pin.set_high().unwrap(); blue_pin.set_high().unwrap();
delay.delay_ms(500); delay.delay_ms(500);
*/
} }
} }