Skip to content

Instantly share code, notes, and snippets.

@Yatekii
Created June 26, 2020 19:02
Show Gist options
  • Save Yatekii/0326cd67f52e3756068b03bc6eec546c to your computer and use it in GitHub Desktop.
Save Yatekii/0326cd67f52e3756068b03bc6eec546c to your computer and use it in GitHub Desktop.
#![no_main]
#![no_std]
use panic_halt as _;
use core::fmt::Write;
use cortex_m_rt::entry;
use rtt_target::rtt_init;
#[entry]
fn main() -> ! {
let channels = rtt_init! {
up: {
0: {
size: 512
mode: BlockIfFull
name: "Up zero"
}
1: {
size: 128
name: "Up one"
}
2: {
size: 128
name: "Up two"
}
}
down: {
0: {
size: 512
mode: BlockIfFull
name: "Down zero"
}
}
};
let mut output2 = channels.up.1;
writeln!(
output2,
"Hi! I will turn anything you type on channel 0 into upper case."
)
.ok();
let mut output = channels.up.0;
let mut log = channels.up.2;
let mut input = channels.down.0;
let mut buf = [0u8; 512];
if let Some(p) = microbit::Peripherals::take() {
p.GPIO.pin_cnf[4].write(|w| w.dir().output());
p.GPIO.pin_cnf[13].write(|w| w.dir().output());
p.GPIO.out.write(|w| unsafe { w.bits(1 << 13) });
let mut count: u8 = 0;
loop {
let bytes = input.read(&mut buf[..]);
if bytes > 0 {
for c in buf.iter_mut() {
c.make_ascii_uppercase();
}
let mut p = 0;
while p < bytes {
p += output.write(&buf[p..bytes]);
}
}
writeln!(log, "Messsge no. {}/{}\nKEKEKE\nKEKEKEKE\nKEKEKEKkasdflasdfasdflkjasdkfljasdlkfölkasjflkasdjflöasjdlfjasdlkjflkasdjfklasdjflasjdflkasd", count, bytes).ok();
count += 1;
if count & 1 == 1 {
p.GPIO.out.write(|w| unsafe { w.bits(1 << 13) });
} else {
p.GPIO.out.write(|w| unsafe { w.bits(0) });
}
for _ in 0..1_000_000 {
cortex_m::asm::nop();
}
}
};
loop {
continue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment