From 54ab1ba86db2022a82d042da240bf4aaa018f7b2 Mon Sep 17 00:00:00 2001 From: Andy Killorin <37423245+Speedy6451@users.noreply.github.com> Date: Wed, 1 May 2024 14:50:07 -0500 Subject: [PATCH] template --- .cargo/config.toml | 8 +++++++ .gitignore | 1 + Cargo.toml | 40 +++++++++++++++++++++++++++++++++++ avr-specs/avr-atmega1280.json | 25 ++++++++++++++++++++++ avr-specs/avr-atmega168.json | 25 ++++++++++++++++++++++ avr-specs/avr-atmega2560.json | 25 ++++++++++++++++++++++ avr-specs/avr-atmega328p.json | 25 ++++++++++++++++++++++ avr-specs/avr-atmega32u4.json | 25 ++++++++++++++++++++++ avr-specs/avr-atmega48p.json | 25 ++++++++++++++++++++++ avr-specs/avr-attiny85.json | 25 ++++++++++++++++++++++ avr-specs/avr-attiny88.json | 25 ++++++++++++++++++++++ rust-toolchain.toml | 4 ++++ src/main.rs | 27 +++++++++++++++++++++++ 13 files changed, 280 insertions(+) create mode 100644 .cargo/config.toml create mode 100644 .gitignore create mode 100644 Cargo.toml create mode 100644 avr-specs/avr-atmega1280.json create mode 100644 avr-specs/avr-atmega168.json create mode 100644 avr-specs/avr-atmega2560.json create mode 100644 avr-specs/avr-atmega328p.json create mode 100644 avr-specs/avr-atmega32u4.json create mode 100644 avr-specs/avr-atmega48p.json create mode 100644 avr-specs/avr-attiny85.json create mode 100644 avr-specs/avr-attiny88.json create mode 100644 rust-toolchain.toml create mode 100644 src/main.rs diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..d502ee5 --- /dev/null +++ b/.cargo/config.toml @@ -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"] diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..49aa2c1 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,40 @@ +[package] +name = "pick-n-place" +version = "0.1.0" +authors = ["Andy Killorin <37423245+Speedy6451@users.noreply.github.com>"] +edition = "2021" + +[[bin]] +name = "pick-n-place" +test = false +bench = false + +[dependencies] +panic-halt = "0.2.0" +ufmt = "0.2.0" +nb = "0.1.2" +embedded-hal = "0.2.3" + +[dependencies.arduino-hal] +git = "https://github.com/rahix/avr-hal" +rev = "3e362624547462928a219c40f9ea8e3a64f21e5f" +features = ["arduino-uno"] + +# The latest releases of `proc-macro2` do not support the rust toolchain that +# we use. Thus, we must fix this dependency to an older version where our +# toolchain is still supported. See https://github.com/Rahix/avr-hal/issues/537 +[build-dependencies.proc-macro2] +version = "=1.0.79" + +# 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 = true +lto = true +opt-level = "s" diff --git a/avr-specs/avr-atmega1280.json b/avr-specs/avr-atmega1280.json new file mode 100644 index 0000000..5fbc931 --- /dev/null +++ b/avr-specs/avr-atmega1280.json @@ -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", + "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" + ] + }, + "relocation-model": "static", + "target-c-int-width": "16", + "target-pointer-width": "16" +} diff --git a/avr-specs/avr-atmega168.json b/avr-specs/avr-atmega168.json new file mode 100644 index 0000000..baac32a --- /dev/null +++ b/avr-specs/avr-atmega168.json @@ -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", + "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" + ] + }, + "relocation-model": "static", + "target-c-int-width": "16", + "target-pointer-width": "16" +} diff --git a/avr-specs/avr-atmega2560.json b/avr-specs/avr-atmega2560.json new file mode 100644 index 0000000..5d33bfe --- /dev/null +++ b/avr-specs/avr-atmega2560.json @@ -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", + "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" + ] + }, + "relocation-model": "static", + "target-c-int-width": "16", + "target-pointer-width": "16" +} diff --git a/avr-specs/avr-atmega328p.json b/avr-specs/avr-atmega328p.json new file mode 100644 index 0000000..7d7d82c --- /dev/null +++ b/avr-specs/avr-atmega328p.json @@ -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", + "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" + ] + }, + "relocation-model": "static", + "target-c-int-width": "16", + "target-pointer-width": "16" +} diff --git a/avr-specs/avr-atmega32u4.json b/avr-specs/avr-atmega32u4.json new file mode 100644 index 0000000..f078d2e --- /dev/null +++ b/avr-specs/avr-atmega32u4.json @@ -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", + "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" + ] + }, + "relocation-model": "static", + "target-c-int-width": "16", + "target-pointer-width": "16" +} diff --git a/avr-specs/avr-atmega48p.json b/avr-specs/avr-atmega48p.json new file mode 100644 index 0000000..b13938d --- /dev/null +++ b/avr-specs/avr-atmega48p.json @@ -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", + "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" + ] + }, + "relocation-model": "static", + "target-c-int-width": "16", + "target-pointer-width": "16" +} diff --git a/avr-specs/avr-attiny85.json b/avr-specs/avr-attiny85.json new file mode 100644 index 0000000..9d577da --- /dev/null +++ b/avr-specs/avr-attiny85.json @@ -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", + "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" + ] + }, + "relocation-model": "static", + "target-c-int-width": "16", + "target-pointer-width": "16" +} diff --git a/avr-specs/avr-attiny88.json b/avr-specs/avr-attiny88.json new file mode 100644 index 0000000..5ab1e58 --- /dev/null +++ b/avr-specs/avr-attiny88.json @@ -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", + "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" + ] + }, + "relocation-model": "static", + "target-c-int-width": "16", + "target-pointer-width": "16" +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..3523320 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "nightly-2024-03-22" +components = ["rust-src"] +profile = "minimal" diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..7a6a7ba --- /dev/null +++ b/src/main.rs @@ -0,0 +1,27 @@ +#![no_std] +#![no_main] + +use panic_halt as _; + +#[arduino_hal::entry] +fn main() -> ! { + let dp = arduino_hal::Peripherals::take().unwrap(); + let pins = arduino_hal::pins!(dp); + + /* + * For examples (and inspiration), head to + * + * https://github.com/Rahix/avr-hal/tree/main/examples + * + * NOTE: Not all examples were ported to all boards! There is a good chance though, that code + * for a different board can be adapted for yours. The Arduino Uno currently has the most + * examples available. + */ + + let mut led = pins.d13.into_output(); + + loop { + led.toggle(); + arduino_hal::delay_ms(1000); + } +}