Upgrade ruduino
This commit is contained in:
67
Cargo.lock
generated
67
Cargo.lock
generated
@@ -1,11 +1,22 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "avr-mcu"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"json 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"target-cpu-fetch 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"xmltree 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "blink"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"futures 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ruduino 0.1.1",
|
||||
"ruduino 0.2.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -62,6 +73,16 @@ dependencies = [
|
||||
"pin-utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "json"
|
||||
version = "0.12.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "pin-project"
|
||||
version = "0.4.22"
|
||||
@@ -103,7 +124,12 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ruduino"
|
||||
version = "0.1.1"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"avr-mcu 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"target-cpu-fetch 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"target-cpu-macro 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
@@ -115,12 +141,43 @@ dependencies = [
|
||||
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "target-cpu-fetch"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"json 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "target-cpu-macro"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"json 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"target-cpu-fetch 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "xml-rs"
|
||||
version = "0.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "xmltree"
|
||||
version = "0.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"xml-rs 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[metadata]
|
||||
"checksum avr-mcu 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4c72808d438e648fa04c2b5a655eb59fc202622f1fb446182dd4a363b389af16"
|
||||
"checksum futures 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1e05b85ec287aac0dc34db7d4a569323df697f9c55b99b15d6b4ef8cde49f613"
|
||||
"checksum futures-channel 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f366ad74c28cca6ba456d95e6422883cfb4b252a83bed929c83abfdbbf2967d5"
|
||||
"checksum futures-core 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "59f5fff90fd5d971f936ad674802482ba441b6f09ba5e15fd8b39145582ca399"
|
||||
@@ -128,10 +185,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum futures-sink 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3f2032893cb734c7a05d85ce0cc8b8c4075278e93b24b66f9de99d6eb0fa8acc"
|
||||
"checksum futures-task 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "bdb66b5f09e22019b1ab0830f7785bcea8e7a42148683f99214f73f8ec21a626"
|
||||
"checksum futures-util 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8764574ff08b701a084482c3c7031349104b07ac897393010494beaa18ce32c6"
|
||||
"checksum json 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)" = "078e285eafdfb6c4b434e0d31e8cfcb5115b651496faca5749b88fafd4f23bfd"
|
||||
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
"checksum pin-project 0.4.22 (registry+https://github.com/rust-lang/crates.io-index)" = "12e3a6cdbfe94a5e4572812a0201f8c0ed98c1c452c7b8563ce2276988ef9c17"
|
||||
"checksum pin-project-internal 0.4.22 (registry+https://github.com/rust-lang/crates.io-index)" = "6a0ffd45cf79d88737d7cc85bfd5d2894bee1139b356e616fe85dc389c61aaf7"
|
||||
"checksum pin-utils 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
|
||||
"checksum proc-macro2 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa"
|
||||
"checksum quote 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
|
||||
"checksum syn 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)" = "e8d5d96e8cbb005d6959f119f773bfaebb5684296108fb32600c00cde305b2cd"
|
||||
"checksum target-cpu-fetch 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b362c2489eca702c03a77e3ef0753de5a68d8e2314fc784a6dfbba5069e05def"
|
||||
"checksum target-cpu-macro 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "382a642e3ca83cf65746ff7e570bf330bd0a9a985753fdcf78a78cb2c9a24580"
|
||||
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
|
||||
"checksum xml-rs 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b07db065a5cf61a7e4ba64f29e67db906fb1787316516c4e6e5ff0fea1efcd8a"
|
||||
"checksum xmltree 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f76badaccb0313f1f0cb6582c2973f2dd0620f9652eb7a5ff6ced0cc3ac922b3"
|
||||
|
||||
@@ -11,6 +11,4 @@ opt-level = "z"
|
||||
|
||||
[dependencies]
|
||||
futures = { version = "0.3.5", default-features = false }
|
||||
|
||||
[dependencies.ruduino]
|
||||
path = "./ruduino"
|
||||
ruduino = { path = "./ruduino", default-features = false }
|
||||
|
||||
2
ruduino
2
ruduino
Submodule ruduino updated: f6a8e85436...754716d5e2
53
src/main.rs
53
src/main.rs
@@ -8,7 +8,7 @@
|
||||
#![no_main]
|
||||
|
||||
use core::{prelude::v1::*, ptr};
|
||||
use ruduino::{prelude::*, *};
|
||||
use ruduino::{prelude::*, legacy::serial, cores::atmega328, Register, Pin};
|
||||
|
||||
#[allow(unused_macros)]
|
||||
macro_rules! println {
|
||||
@@ -44,8 +44,8 @@ fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "avr-interrupt" fn _ivr_timer1_compare_a() {
|
||||
let prev_value = ptr::read_volatile(PORTB);
|
||||
ptr::write_volatile(PORTB, prev_value ^ PINB5);
|
||||
let prev_value = ptr::read_volatile(atmega328::PORTB::ADDRESS);
|
||||
ptr::write_volatile(atmega328::PORTB::ADDRESS, prev_value ^ atmega328::port::B5::MASK);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -142,27 +142,30 @@ mod initialize {
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn main() -> ! {
|
||||
use ruduino::modules::{timer::timer16, Timer16};
|
||||
|
||||
// TODO: we know interrupts are off, don't we?
|
||||
without_interrupts(|| {
|
||||
unsafe {
|
||||
// The ABI requires that r1 starts as zero
|
||||
llvm_asm!("eor r1, r1");
|
||||
ptr::write_volatile(SP, CPU_INITIAL_STACK_POINTER);
|
||||
ptr::write_volatile(atmega328::SP::ADDRESS, CPU_INITIAL_STACK_POINTER);
|
||||
initialize::memory();
|
||||
}
|
||||
|
||||
unsafe {
|
||||
// Configure all Port B pins as outputs
|
||||
ptr::write_volatile(DDRB, 0xFF);
|
||||
ptr::write_volatile(atmega328::DDRB::ADDRESS, 0xFF);
|
||||
// Turn on all Port B pins
|
||||
// ptr::write_volatile(PORTB, 0xFF);
|
||||
}
|
||||
|
||||
timer1::Timer::new()
|
||||
// TODO: Why is this called timer16 when the interrupt calls it timer1 ?
|
||||
atmega328::Timer16::setup()
|
||||
.waveform_generation_mode(
|
||||
timer1::WaveformGenerationMode::ClearOnTimerMatchOutputCompare,
|
||||
timer16::WaveformGenerationMode::ClearOnTimerMatchOutputCompare,
|
||||
)
|
||||
.clock_source(timer1::ClockSource::Prescale1024)
|
||||
.clock_source(timer16::ClockSource::Prescale1024)
|
||||
.output_compare_1(Some(INTERRUPT_EVERY_1_HZ_1024_PRESCALER))
|
||||
.configure();
|
||||
|
||||
@@ -239,7 +242,7 @@ fn bracketed_echo() -> ! {
|
||||
mod exercise {
|
||||
use crate::write;
|
||||
use core::{fmt::Write, ptr};
|
||||
use ruduino::serial;
|
||||
use ruduino::legacy::serial;
|
||||
|
||||
pub fn serial() {
|
||||
serial::transmit(b'A');
|
||||
@@ -395,7 +398,7 @@ mod exercise {
|
||||
#[allow(unused)]
|
||||
mod write {
|
||||
use core::fmt::{self, Write};
|
||||
use ruduino::serial;
|
||||
use ruduino::legacy::serial;
|
||||
|
||||
pub static TO_HEX: &[u8; 16] = b"0123456789ABCDEF";
|
||||
pub const SERIAL: SuperSerial = SuperSerial(());
|
||||
@@ -466,23 +469,23 @@ mod fut {
|
||||
ptr,
|
||||
task::{Context, Poll, Waker},
|
||||
};
|
||||
// use embrio_async::embrio_async;
|
||||
use ruduino::{serial, RXCIE0, UCSR0B, UDRIE0};
|
||||
use crate::write;
|
||||
use ruduino::{legacy::serial, cores::atmega328, Register, RegisterBits};
|
||||
|
||||
fn set_bit_in(register: *mut u8, bit: u8) {
|
||||
// ruduino doesn't appear to use volatile yet... ?
|
||||
fn set_bit<R: Register<T = u8>>(bit: RegisterBits<R>) {
|
||||
unsafe {
|
||||
let old = ptr::read_volatile(register);
|
||||
let new = old | bit;
|
||||
ptr::write_volatile(register, new);
|
||||
let old = ptr::read_volatile(R::ADDRESS);
|
||||
let new = old | u8::from(bit);
|
||||
ptr::write_volatile(R::ADDRESS, new);
|
||||
}
|
||||
}
|
||||
|
||||
fn unset_bit_in(register: *mut u8, bit: u8) {
|
||||
// ruduino doesn't appear to use volatile yet... ?
|
||||
fn unset_bit<R: Register<T = u8>>(bit: RegisterBits<R>) {
|
||||
unsafe {
|
||||
let old = ptr::read_volatile(register);
|
||||
let new = old ^ bit;
|
||||
ptr::write_volatile(register, new);
|
||||
let old = ptr::read_volatile(R::ADDRESS);
|
||||
let new = old ^ u8::from(bit);
|
||||
ptr::write_volatile(R::ADDRESS, new);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -537,11 +540,11 @@ mod fut {
|
||||
}
|
||||
|
||||
fn enable_serial_rx_interrupt() {
|
||||
set_bit_in(UCSR0B, RXCIE0);
|
||||
set_bit(atmega328::UCSR0B::RXCIE0);
|
||||
}
|
||||
|
||||
fn disable_serial_rx_interrupt() {
|
||||
unset_bit_in(UCSR0B, RXCIE0);
|
||||
unset_bit(atmega328::UCSR0B::RXCIE0);
|
||||
}
|
||||
|
||||
impl<'a> Future for SerialRx<'a> {
|
||||
@@ -590,11 +593,11 @@ mod fut {
|
||||
}
|
||||
|
||||
fn enable_serial_tx_empty_interrupt() {
|
||||
set_bit_in(UCSR0B, UDRIE0);
|
||||
set_bit(atmega328::UCSR0B::UDRIE0);
|
||||
}
|
||||
|
||||
fn disable_serial_tx_empty_interrupt() {
|
||||
unset_bit_in(UCSR0B, UDRIE0);
|
||||
unset_bit(atmega328::UCSR0B::UDRIE0);
|
||||
}
|
||||
|
||||
impl Future for SerialTx {
|
||||
|
||||
Reference in New Issue
Block a user