Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Reusable components for the Arduino Uno.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
NotificationsYou must be signed in to change notification settings

avr-rust/ruduino

Repository files navigation

This library provides a set of reusable components for the Arduino Uno.

Overview

Register and bit definitions

use ruduino::cores::current::PORTB;// Registeruse ruduino::cores::current::PORTB7;// Pin

Prelude

Disable interrupts.

without_interrupts(||{unsafe{write_volatile(DDRB,0xFF)}})

Timers

Configure a timer.

constDESIRED_HZ_TIM1:f64 =2.0;constTIM1_PRESCALER:u64 =1024;constINTERRUPT_EVERY_1_HZ_1024_PRESCALER:u16 =((ruduino::config::CPU_FREQUENCY_HZasf64 /(DESIRED_HZ_TIM1*TIM1_PRESCALERasf64))asu64 -1)asu16;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.

#[no_mangle]pubunsafeextern"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.

constBAUD:u64 =9600;constUBRR:u16 =(ruduino::config::CPU_FREQUENCY_HZ /16 /BAUD -1)asu16;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.

for&binb"OK"{    serial::transmit(b);}

Read a byte if there's something available.

ifletSome(b) = serial::try_receive(){    serial::transmit(b);    serial::transmit(b);}

About

Reusable components for the Arduino Uno.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Contributors6

Languages


[8]ページ先頭

©2009-2025 Movatter.jp