Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c679d5d

Browse filesBrowse files
committed
Initial commit
0 parents  commit c679d5d
Copy full SHA for c679d5d

File tree

10 files changed

+367
-0
lines changed
Filter options

10 files changed

+367
-0
lines changed

‎.cargo/config.toml

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[build]
2+
target = "avr-atmega328p.json"
3+
4+
[unstable]
5+
build-std = ["core"]

‎.gitignore

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

‎Cargo.lock

Copy file name to clipboardExpand all lines: Cargo.lock
+221Lines changed: 221 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

Copy file name to clipboard
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
name = "rust-arduino-blink"
3+
version = "0.1.0"
4+
authors = ["creativcoder <creativcoders@gmail.com>"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
panic-halt = "0.2.0"
11+
12+
[dependencies.arduino-uno]
13+
git = "https://github.com/Rahix/avr-hal"
14+
15+
# Configure the build for minimal size
16+
[profile.dev]
17+
panic = "abort"
18+
lto = true
19+
opt-level = "s"
20+
21+
[profile.release]
22+
panic = "abort"
23+
codegen-units = 1
24+
debug = true
25+
lto = true
26+
opt-level = "s"

‎LICENSE

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 creativcoder
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎README.md

Copy file name to clipboard
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
## Blink program in Rust for Arduino Uno
3+
4+
![Rust-on-arduino](assets/rust-arduino.gif)
5+
6+
Accompanying blog post: https://creativcoder.dev/rust-on-arduino-uno
7+
8+
## Getting up and running:
9+
10+
```bash
11+
./flash.sh target/avr-atmega328p/debug/rust-arduino-blink.elf
12+
```

‎assets/rust-arduino.gif

Copy file name to clipboard
6.41 MB
Loading

‎avr-atmega328p.json

Copy file name to clipboard
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"llvm-target": "avr-unknown-unknown",
3+
"cpu": "atmega328p",
4+
"target-endian": "little",
5+
"target-pointer-width": "16",
6+
"target-c-int-width": "16",
7+
"os": "unknown",
8+
"target-env": "",
9+
"target-vendor": "unknown",
10+
"arch": "avr",
11+
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
12+
13+
"executables": true,
14+
15+
"linker": "avr-gcc",
16+
"linker-flavor": "gcc",
17+
"pre-link-args": {
18+
"gcc": ["-Os", "-mmcu=atmega328p"]
19+
},
20+
"exe-suffix": ".elf",
21+
"post-link-args": {
22+
"gcc": ["-Wl,--gc-sections"]
23+
},
24+
25+
"singlethread": false,
26+
"no-builtins": false,
27+
28+
"no-default-libraries": false,
29+
30+
"eh-frame-header": false
31+
}
32+

‎flash.sh

Copy file name to clipboard
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#! /usr/bin/zsh
2+
3+
set -e
4+
5+
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
6+
echo "usage: $0 <path-to-binary.elf>" >&2
7+
exit 1
8+
fi
9+
10+
if [ "$#" -lt 1 ]; then
11+
echo "$0: Expecting a .elf file" >&2
12+
exit 1
13+
fi
14+
15+
sudo -u $USER cargo build
16+
avrdude -q -C/etc/avrdude.conf -patmega328p -carduino -P/dev/ttyACM0 -D "-Uflash:w:$1:e"

‎src/main.rs

Copy file name to clipboard
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// main.rs
2+
3+
#![no_std]
4+
#![no_main]
5+
6+
extern crate panic_halt;
7+
use arduino_uno::prelude::*;
8+
use arduino_uno::hal::port::portb::PB5;
9+
use arduino_uno::hal::port::mode::Output;
10+
11+
fn stutter_blink(led: &mut PB5<Output>, times: usize) {
12+
(0..times).take(times).map(|i| i * 10).for_each(|i| {
13+
led.toggle().void_unwrap();
14+
arduino_uno::delay_ms(i as u16);
15+
});
16+
}
17+
18+
#[arduino_uno::entry]
19+
fn main() -> ! {
20+
let peripherals = arduino_uno::Peripherals::take().unwrap();
21+
22+
let mut pins = arduino_uno::Pins::new(
23+
peripherals.PORTB,
24+
peripherals.PORTC,
25+
peripherals.PORTD,
26+
);
27+
28+
let mut led = pins.d13.into_output(&mut pins.ddr);
29+
30+
loop {
31+
stutter_blink(&mut led, 25);
32+
}
33+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.