feat: blink and timer
This commit is contained in:
parent
3c6bedf65a
commit
f135e2484a
24 changed files with 671 additions and 0 deletions
8
001-led_blink/.cargo/config.toml
Normal file
8
001-led_blink/.cargo/config.toml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[build]
|
||||||
|
target = "avr-specs/avr-atmega328p.json"
|
||||||
|
|
||||||
|
[target.'cfg(target_arch = "avr")']
|
||||||
|
runner = "ravedude uno -cb 57600"
|
||||||
|
|
||||||
|
[unstable]
|
||||||
|
build-std = ["core"]
|
36
001-led_blink/Cargo.toml
Normal file
36
001-led_blink/Cargo.toml
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
[package]
|
||||||
|
name = "rust-arduino"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Ahmet Kaan GÜMÜŞ <96421894+Tahinli@users.noreply.github.com>"]
|
||||||
|
edition = "2021"
|
||||||
|
license = "MIT OR Apache-2.0 OR GPL-3.0"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "rust-arduino"
|
||||||
|
test = false
|
||||||
|
bench = false
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
panic-halt = "0.2.0"
|
||||||
|
ufmt = "0.2.0"
|
||||||
|
nb = "1.1.0"
|
||||||
|
embedded-hal = "1.0.0"
|
||||||
|
avr-device = "0.5.3"
|
||||||
|
|
||||||
|
[dependencies.arduino-hal]
|
||||||
|
git = "https://github.com/rahix/avr-hal"
|
||||||
|
rev = "190f2c3cb8d29e10f71119352b912369dc5a1fb7"
|
||||||
|
features = ["arduino-uno"]
|
||||||
|
|
||||||
|
# Configure the build for minimal size - AVRs have very little program memory
|
||||||
|
[profile.dev]
|
||||||
|
panic = "abort"
|
||||||
|
lto = true
|
||||||
|
opt-level = "s"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
panic = "abort"
|
||||||
|
codegen-units = 1
|
||||||
|
debug = false
|
||||||
|
lto = true
|
||||||
|
opt-level = "s"
|
25
001-led_blink/avr-specs/avr-atmega1280.json
Normal file
25
001-led_blink/avr-specs/avr-atmega1280.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"arch": "avr",
|
||||||
|
"atomic-cas": false,
|
||||||
|
"cpu": "atmega1280",
|
||||||
|
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||||
|
"eh-frame-header": false,
|
||||||
|
"exe-suffix": ".elf",
|
||||||
|
"executables": true,
|
||||||
|
"late-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-lgcc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"linker": "avr-gcc",
|
||||||
|
"llvm-target": "avr-unknown-unknown",
|
||||||
|
"max-atomic-width": 8,
|
||||||
|
"no-default-libraries": false,
|
||||||
|
"pre-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-mmcu=atmega1280"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"target-c-int-width": "16",
|
||||||
|
"target-pointer-width": "16"
|
||||||
|
}
|
25
001-led_blink/avr-specs/avr-atmega168.json
Normal file
25
001-led_blink/avr-specs/avr-atmega168.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"arch": "avr",
|
||||||
|
"atomic-cas": false,
|
||||||
|
"cpu": "atmega168",
|
||||||
|
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||||
|
"eh-frame-header": false,
|
||||||
|
"exe-suffix": ".elf",
|
||||||
|
"executables": true,
|
||||||
|
"late-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-lgcc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"linker": "avr-gcc",
|
||||||
|
"llvm-target": "avr-unknown-unknown",
|
||||||
|
"max-atomic-width": 8,
|
||||||
|
"no-default-libraries": false,
|
||||||
|
"pre-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-mmcu=atmega168"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"target-c-int-width": "16",
|
||||||
|
"target-pointer-width": "16"
|
||||||
|
}
|
25
001-led_blink/avr-specs/avr-atmega2560.json
Normal file
25
001-led_blink/avr-specs/avr-atmega2560.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"arch": "avr",
|
||||||
|
"atomic-cas": false,
|
||||||
|
"cpu": "atmega2560",
|
||||||
|
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||||
|
"eh-frame-header": false,
|
||||||
|
"exe-suffix": ".elf",
|
||||||
|
"executables": true,
|
||||||
|
"late-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-lgcc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"linker": "avr-gcc",
|
||||||
|
"llvm-target": "avr-unknown-unknown",
|
||||||
|
"max-atomic-width": 8,
|
||||||
|
"no-default-libraries": false,
|
||||||
|
"pre-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-mmcu=atmega2560"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"target-c-int-width": "16",
|
||||||
|
"target-pointer-width": "16"
|
||||||
|
}
|
25
001-led_blink/avr-specs/avr-atmega328p.json
Normal file
25
001-led_blink/avr-specs/avr-atmega328p.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"arch": "avr",
|
||||||
|
"atomic-cas": false,
|
||||||
|
"cpu": "atmega328p",
|
||||||
|
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||||
|
"eh-frame-header": false,
|
||||||
|
"exe-suffix": ".elf",
|
||||||
|
"executables": true,
|
||||||
|
"late-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-lgcc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"linker": "avr-gcc",
|
||||||
|
"llvm-target": "avr-unknown-unknown",
|
||||||
|
"max-atomic-width": 8,
|
||||||
|
"no-default-libraries": false,
|
||||||
|
"pre-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-mmcu=atmega328p"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"target-c-int-width": "16",
|
||||||
|
"target-pointer-width": "16"
|
||||||
|
}
|
25
001-led_blink/avr-specs/avr-atmega32u4.json
Normal file
25
001-led_blink/avr-specs/avr-atmega32u4.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"arch": "avr",
|
||||||
|
"atomic-cas": false,
|
||||||
|
"cpu": "atmega32u4",
|
||||||
|
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||||
|
"eh-frame-header": false,
|
||||||
|
"exe-suffix": ".elf",
|
||||||
|
"executables": true,
|
||||||
|
"late-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-lgcc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"linker": "avr-gcc",
|
||||||
|
"llvm-target": "avr-unknown-unknown",
|
||||||
|
"max-atomic-width": 8,
|
||||||
|
"no-default-libraries": false,
|
||||||
|
"pre-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-mmcu=atmega32u4"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"target-c-int-width": "16",
|
||||||
|
"target-pointer-width": "16"
|
||||||
|
}
|
25
001-led_blink/avr-specs/avr-atmega48p.json
Normal file
25
001-led_blink/avr-specs/avr-atmega48p.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"arch": "avr",
|
||||||
|
"atomic-cas": false,
|
||||||
|
"cpu": "atmega48p",
|
||||||
|
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||||
|
"eh-frame-header": false,
|
||||||
|
"exe-suffix": ".elf",
|
||||||
|
"executables": true,
|
||||||
|
"late-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-lgcc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"linker": "avr-gcc",
|
||||||
|
"llvm-target": "avr-unknown-unknown",
|
||||||
|
"max-atomic-width": 8,
|
||||||
|
"no-default-libraries": false,
|
||||||
|
"pre-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-mmcu=atmega48p"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"target-c-int-width": "16",
|
||||||
|
"target-pointer-width": "16"
|
||||||
|
}
|
25
001-led_blink/avr-specs/avr-attiny85.json
Normal file
25
001-led_blink/avr-specs/avr-attiny85.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"arch": "avr",
|
||||||
|
"atomic-cas": false,
|
||||||
|
"cpu": "attiny85",
|
||||||
|
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||||
|
"eh-frame-header": false,
|
||||||
|
"exe-suffix": ".elf",
|
||||||
|
"executables": true,
|
||||||
|
"late-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-lgcc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"linker": "avr-gcc",
|
||||||
|
"llvm-target": "avr-unknown-unknown",
|
||||||
|
"max-atomic-width": 8,
|
||||||
|
"no-default-libraries": false,
|
||||||
|
"pre-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-mmcu=attiny85"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"target-c-int-width": "16",
|
||||||
|
"target-pointer-width": "16"
|
||||||
|
}
|
25
001-led_blink/avr-specs/avr-attiny88.json
Normal file
25
001-led_blink/avr-specs/avr-attiny88.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"arch": "avr",
|
||||||
|
"atomic-cas": false,
|
||||||
|
"cpu": "attiny88",
|
||||||
|
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||||
|
"eh-frame-header": false,
|
||||||
|
"exe-suffix": ".elf",
|
||||||
|
"executables": true,
|
||||||
|
"late-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-lgcc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"linker": "avr-gcc",
|
||||||
|
"llvm-target": "avr-unknown-unknown",
|
||||||
|
"max-atomic-width": 8,
|
||||||
|
"no-default-libraries": false,
|
||||||
|
"pre-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-mmcu=attiny88"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"target-c-int-width": "16",
|
||||||
|
"target-pointer-width": "16"
|
||||||
|
}
|
4
001-led_blink/rust-toolchain.toml
Normal file
4
001-led_blink/rust-toolchain.toml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[toolchain]
|
||||||
|
channel = "nightly-2023-08-08"
|
||||||
|
components = ["rust-src"]
|
||||||
|
profile = "minimal"
|
119
001-led_blink/src/main.rs
Normal file
119
001-led_blink/src/main.rs
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
|
||||||
|
use core::cell::RefCell;
|
||||||
|
use avr_device::interrupt;
|
||||||
|
use panic_halt as _;
|
||||||
|
|
||||||
|
type Console = arduino_hal::hal::usart::Usart0<arduino_hal::DefaultClock>;
|
||||||
|
static CONSOLE: interrupt::Mutex<RefCell<Option<Console>>> = interrupt::Mutex::new(RefCell::new(None));
|
||||||
|
|
||||||
|
macro_rules! println {
|
||||||
|
($($t:tt)*) => {
|
||||||
|
interrupt::free(
|
||||||
|
|cs|
|
||||||
|
{
|
||||||
|
if let Some(console) = CONSOLE.borrow(cs).borrow_mut().as_mut()
|
||||||
|
{
|
||||||
|
let _ = ufmt::uwriteln!(console, $($t)*);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn put_console(console:Console)
|
||||||
|
{
|
||||||
|
interrupt::free(
|
||||||
|
|cs|
|
||||||
|
{
|
||||||
|
*CONSOLE.borrow(cs).borrow_mut() = Some(console);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
#[arduino_hal::entry]
|
||||||
|
fn main() -> ! {
|
||||||
|
let dp = arduino_hal::Peripherals::take().unwrap();
|
||||||
|
let pins = arduino_hal::pins!(dp);
|
||||||
|
let serial = arduino_hal::default_serial!(dp, pins, 57600);
|
||||||
|
put_console(serial);
|
||||||
|
println!("Hello World");
|
||||||
|
|
||||||
|
|
||||||
|
let mut led02 = pins.d2.into_output();
|
||||||
|
let mut led03 = pins.d3.into_output();
|
||||||
|
let mut led04 = pins.d4.into_output();
|
||||||
|
let mut led05 = pins.d5.into_output();
|
||||||
|
let mut led06 = pins.d6.into_output();
|
||||||
|
let mut led07 = pins.d7.into_output();
|
||||||
|
//let mut led08 = pins.d8.into_output();
|
||||||
|
let mut led09 = pins.d9.into_output();
|
||||||
|
let mut led10 = pins.d10.into_output();
|
||||||
|
let mut led11 = pins.d11.into_output();
|
||||||
|
let mut led12 = pins.d12.into_output();
|
||||||
|
let mut led13 = pins.d13.into_output();
|
||||||
|
|
||||||
|
loop {
|
||||||
|
led02.toggle();
|
||||||
|
arduino_hal::delay_ms(50);
|
||||||
|
led02.toggle();
|
||||||
|
led03.toggle();
|
||||||
|
arduino_hal::delay_ms(50);
|
||||||
|
led03.toggle();
|
||||||
|
led04.toggle();
|
||||||
|
arduino_hal::delay_ms(50);
|
||||||
|
led04.toggle();
|
||||||
|
led05.toggle();
|
||||||
|
arduino_hal::delay_ms(50);
|
||||||
|
led05.toggle();
|
||||||
|
led06.toggle();
|
||||||
|
arduino_hal::delay_ms(50);
|
||||||
|
led06.toggle();
|
||||||
|
led07.toggle();
|
||||||
|
arduino_hal::delay_ms(50);
|
||||||
|
led07.toggle();
|
||||||
|
led09.toggle();
|
||||||
|
arduino_hal::delay_ms(50);
|
||||||
|
led09.toggle();
|
||||||
|
led10.toggle();
|
||||||
|
arduino_hal::delay_ms(50);
|
||||||
|
led10.toggle();
|
||||||
|
led11.toggle();
|
||||||
|
arduino_hal::delay_ms(50);
|
||||||
|
led11.toggle();
|
||||||
|
led12.toggle();
|
||||||
|
arduino_hal::delay_ms(50);
|
||||||
|
led12.toggle();
|
||||||
|
led13.toggle();
|
||||||
|
arduino_hal::delay_ms(50);
|
||||||
|
led13.toggle();
|
||||||
|
led12.toggle();
|
||||||
|
arduino_hal::delay_ms(50);
|
||||||
|
led12.toggle();
|
||||||
|
led11.toggle();
|
||||||
|
arduino_hal::delay_ms(50);
|
||||||
|
led11.toggle();
|
||||||
|
led10.toggle();
|
||||||
|
arduino_hal::delay_ms(50);
|
||||||
|
led10.toggle();
|
||||||
|
led09.toggle();
|
||||||
|
arduino_hal::delay_ms(50);
|
||||||
|
led09.toggle();
|
||||||
|
led07.toggle();
|
||||||
|
arduino_hal::delay_ms(50);
|
||||||
|
led07.toggle();
|
||||||
|
led06.toggle();
|
||||||
|
arduino_hal::delay_ms(50);
|
||||||
|
led06.toggle();
|
||||||
|
led05.toggle();
|
||||||
|
arduino_hal::delay_ms(50);
|
||||||
|
led05.toggle();
|
||||||
|
led04.toggle();
|
||||||
|
arduino_hal::delay_ms(50);
|
||||||
|
led04.toggle();
|
||||||
|
led03.toggle();
|
||||||
|
arduino_hal::delay_ms(50);
|
||||||
|
led03.toggle();
|
||||||
|
}
|
||||||
|
}
|
8
002-timer/.cargo/config.toml
Normal file
8
002-timer/.cargo/config.toml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
[build]
|
||||||
|
target = "avr-specs/avr-atmega328p.json"
|
||||||
|
|
||||||
|
[target.'cfg(target_arch = "avr")']
|
||||||
|
runner = "ravedude uno -cb 57600"
|
||||||
|
|
||||||
|
[unstable]
|
||||||
|
build-std = ["core"]
|
36
002-timer/Cargo.toml
Normal file
36
002-timer/Cargo.toml
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
[package]
|
||||||
|
name = "rust-arduino"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Ahmet Kaan GÜMÜŞ <96421894+Tahinli@users.noreply.github.com>"]
|
||||||
|
edition = "2021"
|
||||||
|
license = "MIT OR Apache-2.0 OR GPL-3.0"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "rust-arduino"
|
||||||
|
test = false
|
||||||
|
bench = false
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
panic-halt = "0.2.0"
|
||||||
|
ufmt = "0.2.0"
|
||||||
|
nb = "1.1.0"
|
||||||
|
embedded-hal = "1.0.0"
|
||||||
|
avr-device = "0.5.3"
|
||||||
|
|
||||||
|
[dependencies.arduino-hal]
|
||||||
|
git = "https://github.com/rahix/avr-hal"
|
||||||
|
rev = "190f2c3cb8d29e10f71119352b912369dc5a1fb7"
|
||||||
|
features = ["arduino-uno"]
|
||||||
|
|
||||||
|
# Configure the build for minimal size - AVRs have very little program memory
|
||||||
|
[profile.dev]
|
||||||
|
panic = "abort"
|
||||||
|
lto = true
|
||||||
|
opt-level = "s"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
panic = "abort"
|
||||||
|
codegen-units = 1
|
||||||
|
debug = false
|
||||||
|
lto = true
|
||||||
|
opt-level = "s"
|
25
002-timer/avr-specs/avr-atmega1280.json
Normal file
25
002-timer/avr-specs/avr-atmega1280.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"arch": "avr",
|
||||||
|
"atomic-cas": false,
|
||||||
|
"cpu": "atmega1280",
|
||||||
|
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||||
|
"eh-frame-header": false,
|
||||||
|
"exe-suffix": ".elf",
|
||||||
|
"executables": true,
|
||||||
|
"late-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-lgcc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"linker": "avr-gcc",
|
||||||
|
"llvm-target": "avr-unknown-unknown",
|
||||||
|
"max-atomic-width": 8,
|
||||||
|
"no-default-libraries": false,
|
||||||
|
"pre-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-mmcu=atmega1280"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"target-c-int-width": "16",
|
||||||
|
"target-pointer-width": "16"
|
||||||
|
}
|
25
002-timer/avr-specs/avr-atmega168.json
Normal file
25
002-timer/avr-specs/avr-atmega168.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"arch": "avr",
|
||||||
|
"atomic-cas": false,
|
||||||
|
"cpu": "atmega168",
|
||||||
|
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||||
|
"eh-frame-header": false,
|
||||||
|
"exe-suffix": ".elf",
|
||||||
|
"executables": true,
|
||||||
|
"late-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-lgcc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"linker": "avr-gcc",
|
||||||
|
"llvm-target": "avr-unknown-unknown",
|
||||||
|
"max-atomic-width": 8,
|
||||||
|
"no-default-libraries": false,
|
||||||
|
"pre-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-mmcu=atmega168"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"target-c-int-width": "16",
|
||||||
|
"target-pointer-width": "16"
|
||||||
|
}
|
25
002-timer/avr-specs/avr-atmega2560.json
Normal file
25
002-timer/avr-specs/avr-atmega2560.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"arch": "avr",
|
||||||
|
"atomic-cas": false,
|
||||||
|
"cpu": "atmega2560",
|
||||||
|
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||||
|
"eh-frame-header": false,
|
||||||
|
"exe-suffix": ".elf",
|
||||||
|
"executables": true,
|
||||||
|
"late-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-lgcc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"linker": "avr-gcc",
|
||||||
|
"llvm-target": "avr-unknown-unknown",
|
||||||
|
"max-atomic-width": 8,
|
||||||
|
"no-default-libraries": false,
|
||||||
|
"pre-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-mmcu=atmega2560"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"target-c-int-width": "16",
|
||||||
|
"target-pointer-width": "16"
|
||||||
|
}
|
25
002-timer/avr-specs/avr-atmega328p.json
Normal file
25
002-timer/avr-specs/avr-atmega328p.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"arch": "avr",
|
||||||
|
"atomic-cas": false,
|
||||||
|
"cpu": "atmega328p",
|
||||||
|
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||||
|
"eh-frame-header": false,
|
||||||
|
"exe-suffix": ".elf",
|
||||||
|
"executables": true,
|
||||||
|
"late-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-lgcc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"linker": "avr-gcc",
|
||||||
|
"llvm-target": "avr-unknown-unknown",
|
||||||
|
"max-atomic-width": 8,
|
||||||
|
"no-default-libraries": false,
|
||||||
|
"pre-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-mmcu=atmega328p"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"target-c-int-width": "16",
|
||||||
|
"target-pointer-width": "16"
|
||||||
|
}
|
25
002-timer/avr-specs/avr-atmega32u4.json
Normal file
25
002-timer/avr-specs/avr-atmega32u4.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"arch": "avr",
|
||||||
|
"atomic-cas": false,
|
||||||
|
"cpu": "atmega32u4",
|
||||||
|
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||||
|
"eh-frame-header": false,
|
||||||
|
"exe-suffix": ".elf",
|
||||||
|
"executables": true,
|
||||||
|
"late-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-lgcc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"linker": "avr-gcc",
|
||||||
|
"llvm-target": "avr-unknown-unknown",
|
||||||
|
"max-atomic-width": 8,
|
||||||
|
"no-default-libraries": false,
|
||||||
|
"pre-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-mmcu=atmega32u4"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"target-c-int-width": "16",
|
||||||
|
"target-pointer-width": "16"
|
||||||
|
}
|
25
002-timer/avr-specs/avr-atmega48p.json
Normal file
25
002-timer/avr-specs/avr-atmega48p.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"arch": "avr",
|
||||||
|
"atomic-cas": false,
|
||||||
|
"cpu": "atmega48p",
|
||||||
|
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||||
|
"eh-frame-header": false,
|
||||||
|
"exe-suffix": ".elf",
|
||||||
|
"executables": true,
|
||||||
|
"late-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-lgcc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"linker": "avr-gcc",
|
||||||
|
"llvm-target": "avr-unknown-unknown",
|
||||||
|
"max-atomic-width": 8,
|
||||||
|
"no-default-libraries": false,
|
||||||
|
"pre-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-mmcu=atmega48p"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"target-c-int-width": "16",
|
||||||
|
"target-pointer-width": "16"
|
||||||
|
}
|
25
002-timer/avr-specs/avr-attiny85.json
Normal file
25
002-timer/avr-specs/avr-attiny85.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"arch": "avr",
|
||||||
|
"atomic-cas": false,
|
||||||
|
"cpu": "attiny85",
|
||||||
|
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||||
|
"eh-frame-header": false,
|
||||||
|
"exe-suffix": ".elf",
|
||||||
|
"executables": true,
|
||||||
|
"late-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-lgcc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"linker": "avr-gcc",
|
||||||
|
"llvm-target": "avr-unknown-unknown",
|
||||||
|
"max-atomic-width": 8,
|
||||||
|
"no-default-libraries": false,
|
||||||
|
"pre-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-mmcu=attiny85"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"target-c-int-width": "16",
|
||||||
|
"target-pointer-width": "16"
|
||||||
|
}
|
25
002-timer/avr-specs/avr-attiny88.json
Normal file
25
002-timer/avr-specs/avr-attiny88.json
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
{
|
||||||
|
"arch": "avr",
|
||||||
|
"atomic-cas": false,
|
||||||
|
"cpu": "attiny88",
|
||||||
|
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
|
||||||
|
"eh-frame-header": false,
|
||||||
|
"exe-suffix": ".elf",
|
||||||
|
"executables": true,
|
||||||
|
"late-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-lgcc"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"linker": "avr-gcc",
|
||||||
|
"llvm-target": "avr-unknown-unknown",
|
||||||
|
"max-atomic-width": 8,
|
||||||
|
"no-default-libraries": false,
|
||||||
|
"pre-link-args": {
|
||||||
|
"gcc": [
|
||||||
|
"-mmcu=attiny88"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"target-c-int-width": "16",
|
||||||
|
"target-pointer-width": "16"
|
||||||
|
}
|
4
002-timer/rust-toolchain.toml
Normal file
4
002-timer/rust-toolchain.toml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
[toolchain]
|
||||||
|
channel = "nightly-2023-08-08"
|
||||||
|
components = ["rust-src"]
|
||||||
|
profile = "minimal"
|
56
002-timer/src/main.rs
Normal file
56
002-timer/src/main.rs
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
|
||||||
|
use core::cell::RefCell;
|
||||||
|
use avr_device::interrupt;
|
||||||
|
use panic_halt as _;
|
||||||
|
|
||||||
|
type Console = arduino_hal::hal::usart::Usart0<arduino_hal::DefaultClock>;
|
||||||
|
static CONSOLE: interrupt::Mutex<RefCell<Option<Console>>> = interrupt::Mutex::new(RefCell::new(None));
|
||||||
|
|
||||||
|
macro_rules! println {
|
||||||
|
($($t:tt)*) => {
|
||||||
|
interrupt::free(
|
||||||
|
|cs|
|
||||||
|
{
|
||||||
|
if let Some(console) = CONSOLE.borrow(cs).borrow_mut().as_mut()
|
||||||
|
{
|
||||||
|
let _ = ufmt::uwriteln!(console, $($t)*);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn put_console(console:Console)
|
||||||
|
{
|
||||||
|
interrupt::free(
|
||||||
|
|cs|
|
||||||
|
{
|
||||||
|
*CONSOLE.borrow(cs).borrow_mut() = Some(console);
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
#[arduino_hal::entry]
|
||||||
|
fn main() -> ! {
|
||||||
|
let dp = arduino_hal::Peripherals::take().unwrap();
|
||||||
|
let pins = arduino_hal::pins!(dp);
|
||||||
|
let serial = arduino_hal::default_serial!(dp, pins, 57600);
|
||||||
|
put_console(serial);
|
||||||
|
println!("Hello World");
|
||||||
|
|
||||||
|
|
||||||
|
let mut pin2 = pins.d2.into_output();
|
||||||
|
let mut pin13 = pins.d13.into_output();
|
||||||
|
loop {
|
||||||
|
for i in 0..60
|
||||||
|
{
|
||||||
|
println!("{}", i);
|
||||||
|
pin2.toggle();
|
||||||
|
arduino_hal::delay_ms(1000);
|
||||||
|
pin13.toggle();
|
||||||
|
}
|
||||||
|
println!("Minute");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue