lol rgb memery

This commit is contained in:
Edward Shen 2020-02-06 18:42:45 -05:00
parent 57a2df7ff6
commit 1291a267d8
No known key found for this signature in database
GPG Key ID: 19182661E818369F
3 changed files with 237 additions and 2 deletions

1
Cargo.lock generated
View File

@ -144,6 +144,7 @@ dependencies = [
"cortex-m 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"cortex-m-rt 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)",
"cortex-m-semihosting 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"metro_m0 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"panic-halt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

View File

@ -6,11 +6,12 @@ name = "onyx"
version = "0.1.0"
[dependencies]
cortex-m = "0.6.0"
cortex-m = { version ="0.6.0", features = [ "inline-asm" ] }
cortex-m-rt = "0.6.10"
cortex-m-semihosting = "0.3.3"
panic-halt = "0.2.0"
metro_m0 = { version = "0.6.0", features = ["default", "unproven"] }
embedded-hal = "0.2.3"
# Uncomment for the panic example.
# panic-itm = "0.4.1"

View File

@ -9,12 +9,196 @@ extern crate panic_halt; // you can put a breakpoint on `rust_begin_unwind` to c
use metro_m0 as hal;
use cortex_m::asm;
use embedded_hal;
use hal::clock::GenericClockController;
use hal::delay::Delay;
use hal::entry;
use hal::pac::{CorePeripherals, Peripherals};
use hal::prelude::*;
macro_rules! write_rgb_zero {
($pin:expr, $delay:expr) => {
$pin.set_high().unwrap();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
$pin.set_low().unwrap();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
// 12
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
// 24
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
// 36
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
};
}
macro_rules! write_rgb_one {
($pin:expr, $delay:expr) => {
$pin.set_high().unwrap();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
$pin.set_low().unwrap();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
asm::nop();
};
}
// #[proc_macro]
// pub fn write_rgb(item: TokenStream) -> TokenStream {
// item
// }
// macro_rules! write_rgb {
// ($pin:expr, $delay:expr, $uint8:expr) => {
// for i in (0..8).rev() {
// if ($uint8 >> i) & 1 == 1 {
// write_rgb_one!($pin, $delay);
// } else {
// write_rgb_zero!($pin, $delay);
// }
// }
// };
// }
#[entry]
fn main() -> ! {
let mut peripherals = Peripherals::take().unwrap();
@ -27,16 +211,65 @@ fn main() -> ! {
);
let mut pins = hal::Pins::new(peripherals.PORT);
let mut red_led = pins.d13.into_push_pull_output(&mut pins.port);
let mut assert_pin = pins.d12.into_push_pull_output(&mut pins.port);
let switch = pins.d3.into_pull_down_input(&mut pins.port);
let mut rgb_meme = pins.neopixel.into_push_pull_output(&mut pins.port);
let mut delay = Delay::new(core.SYST, &mut clocks);
loop {
// delay.delay_ms(255u8);
delay.delay_us(255u8);
assert_pin.set_high().unwrap();
if switch.is_high().unwrap() {
red_led.set_high().unwrap();
} else {
red_led.set_low().unwrap();
}
assert_pin.set_low().unwrap();
lol(&mut rgb_meme, &mut delay);
}
}
#[no_mangle]
fn lol(
pin: &mut metro_m0::gpio::Pa30<metro_m0::gpio::Output<metro_m0::gpio::PushPull>>,
delay: &mut hal::delay::Delay,
) {
pin.set_low().unwrap();
delay.delay_us(60u8);
// write_rgb!(pin, delay, 10);
// write_rgb!(pin, delay, 0);
// write_rgb!(pin, delay, 0);
// write_rgb!(pin, delay, 128);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_zero!(pin, delay);
write_rgb_one!(pin, delay);
}