Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/avr-rust/ruduino
Reusable components for the Arduino Uno.
https://github.com/avr-rust/ruduino
Last synced: about 2 months ago
JSON representation
Reusable components for the Arduino Uno.
- Host: GitHub
- URL: https://github.com/avr-rust/ruduino
- Owner: avr-rust
- License: apache-2.0
- Created: 2016-07-06T23:27:41.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-22T06:53:37.000Z (almost 2 years ago)
- Last Synced: 2024-08-09T14:58:25.867Z (4 months ago)
- Language: Rust
- Size: 125 KB
- Stars: 699
- Watchers: 28
- Forks: 50
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
- awesome-rust-cn - avr-rust/ruduino
- awesome-rust - avr-rust/ruduino
- awesome-rust - avr-rust/ruduino
- awesome-rust-cn - avr-rust/ruduino
- awesome-rust-zh - avr-rust/ruduino
- awesome-rust - avr-rust/ruduino - Reusable components for the Arduino Uno. (Development tools / Embedded)
- awesome-rust - avr-rust/ruduino
- fucking-awesome-rust - avr-rust/ruduino - Reusable components for the Arduino Uno. (Development tools / Embedded)
- fucking-awesome-rust - avr-rust/ruduino - Reusable components for the Arduino Uno. (Development tools / Embedded)
README
# Ruduino
This library provides a set of reusable components for the Arduino Uno.
## Overview
### Register and bit definitions
```rust
use ruduino::cores::current::PORTB; // Register
use ruduino::cores::current::PORTB7; // Pin
```### Prelude
Disable interrupts.
```rust
without_interrupts(|| {
unsafe { write_volatile(DDRB, 0xFF) }
})
```### Timers
Configure a timer.
```rust
const DESIRED_HZ_TIM1: f64 = 2.0;
const TIM1_PRESCALER: u64 = 1024;
const INTERRUPT_EVERY_1_HZ_1024_PRESCALER: u16 =
((ruduino::config::CPU_FREQUENCY_HZ as f64 / (DESIRED_HZ_TIM1 * TIM1_PRESCALER as f64)) as u64 - 1) as u16;timer1::Timer::new()
.waveform_generation_mode(timer1::WaveformGenerationMode::ClearOnTimerMatchOutputCompare)
.clock_source(timer1::ClockSource::Prescale1024)
.output_compare_1(Some(INTERRUPT_EVERY_1_HZ_1024_PRESCALER))
.configure();
```Set up an interrupt handler that will be called when the timer fires.
```rust
#[no_mangle]
pub unsafe extern "avr-interrupt" fn _ivr_timer1_compare_a() {
let prev_value = read_volatile(PORTB);
write_volatile(PORTB, prev_value ^ PINB5);
}
```### Hardware Serial Port
Configure the serial port.
```rust
const BAUD: u64 = 9600;
const UBRR: u16 = (ruduino::config::CPU_FREQUENCY_HZ / 16 / BAUD - 1) as u16;serial::Serial::new(UBRR)
.character_size(serial::CharacterSize::EightBits)
.mode(serial::Mode::Asynchronous)
.parity(serial::Parity::Disabled)
.stop_bits(serial::StopBits::OneBit)
.configure();
```Transmit a sequence of bytes.
```rust
for &b in b"OK" {
serial::transmit(b);
}
```Read a byte if there's something available.
```rust
if let Some(b) = serial::try_receive() {
serial::transmit(b);
serial::transmit(b);
}
```