Skip to content

Commit

Permalink
Define clock in one place per project.
Browse files Browse the repository at this point in the history
  • Loading branch information
armandas committed Apr 1, 2024
1 parent 2a53fd1 commit 18b58b2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
10 changes: 6 additions & 4 deletions examples/atmega2560/src/bin/atmega2560-adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@
#![no_main]

use atmega_hal::adc::channel;
use atmega_hal::clock;
use atmega_hal::delay::Delay;
use atmega_hal::usart::{Baudrate, Usart};
use embedded_hal::delay::DelayNs;
use panic_halt as _;

type Adc = atmega_hal::adc::Adc<clock::MHz16>;
// Define core clock in the root crate
type CoreClock = atmega_hal::clock::MHz16;
// Use it as follows in the rest of the project
type Adc = atmega_hal::adc::Adc<crate::CoreClock>;

#[avr_device::entry]
fn main() -> ! {
let dp = atmega_hal::Peripherals::take().unwrap();
let pins = atmega_hal::pins!(dp);

let mut delay = Delay::<clock::MHz16>::new();
let mut delay = Delay::<crate::CoreClock>::new();

// set up serial interface for text output
let mut serial = Usart::new(
dp.USART0,
pins.pe0,
pins.pe1.into_output(),
Baudrate::<clock::MHz16>::new(57600),
Baudrate::<crate::CoreClock>::new(57600),
);

let mut adc = Adc::new(dp.ADC, Default::default());
Expand Down
6 changes: 4 additions & 2 deletions examples/atmega2560/src/bin/atmega2560-blink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
#![no_main]

use panic_halt as _;
use atmega_hal::clock;
use atmega_hal::delay::Delay;
use embedded_hal::delay::DelayNs;

// Define core clock. This can be used in the rest of the project.
type CoreClock = atmega_hal::clock::MHz16;

#[avr_device::entry]
fn main() -> ! {
let dp = atmega_hal::Peripherals::take().unwrap();
let pins = atmega_hal::pins!(dp);
let mut delay = Delay::<clock::MHz16>::new();
let mut delay = Delay::<crate::CoreClock>::new();

let mut led = pins.pb7.into_output();

Expand Down
8 changes: 5 additions & 3 deletions examples/atmega2560/src/bin/atmega2560-i2cdetect.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#![no_std]
#![no_main]

use atmega_hal::clock;
use atmega_hal::usart::{Baudrate, Usart};
use panic_halt as _;

type I2c = atmega_hal::i2c::I2c<clock::MHz16>;
// Define core clock in the root crate
type CoreClock = atmega_hal::clock::MHz16;
// Use it as follows in the rest of the project
type I2c = atmega_hal::i2c::I2c<crate::CoreClock>;

#[avr_device::entry]
fn main() -> ! {
Expand All @@ -17,7 +19,7 @@ fn main() -> ! {
dp.USART0,
pins.pe0,
pins.pe1.into_output(),
Baudrate::<clock::MHz16>::new(57600),
Baudrate::<crate::CoreClock>::new(57600),
);

let mut i2c = I2c::new(
Expand Down
8 changes: 5 additions & 3 deletions examples/atmega2560/src/bin/atmega2560-spi-feedback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,29 @@
#![no_std]
#![no_main]

use atmega_hal::clock;
use atmega_hal::spi;
use atmega_hal::usart::{Baudrate, Usart};
use atmega_hal::delay::Delay;
use embedded_hal::delay::DelayNs;
use embedded_hal::spi::SpiBus;
use panic_halt as _;

// Define core clock. This can be used in the rest of the project.
type CoreClock = atmega_hal::clock::MHz16;

#[avr_device::entry]
fn main() -> ! {
let dp = atmega_hal::Peripherals::take().unwrap();
let pins = atmega_hal::pins!(dp);

let mut delay = Delay::<clock::MHz16>::new();
let mut delay = Delay::<crate::CoreClock>::new();

// set up serial interface for text output
let mut serial = Usart::new(
dp.USART0,
pins.pe0,
pins.pe1.into_output(),
Baudrate::<clock::MHz16>::new(57600),
Baudrate::<crate::CoreClock>::new(57600),
);

// Create SPI interface.
Expand Down
6 changes: 4 additions & 2 deletions examples/atmega2560/src/bin/atmega2560-usart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
#![no_main]

use atmega_hal::prelude::*;
use atmega_hal::clock;
use atmega_hal::usart::{Baudrate, Usart};
use panic_halt as _;

// Define core clock. This can be used in the rest of the project.
type CoreClock = atmega_hal::clock::MHz16;

#[avr_device::entry]
fn main() -> ! {
let dp = atmega_hal::Peripherals::take().unwrap();
Expand All @@ -14,7 +16,7 @@ fn main() -> ! {
dp.USART0,
pins.pe0,
pins.pe1.into_output(),
Baudrate::<clock::MHz16>::new(57600),
Baudrate::<crate::CoreClock>::new(57600),
);

ufmt::uwriteln!(&mut serial, "Hello from ATmega!\r").unwrap();
Expand Down

0 comments on commit 18b58b2

Please sign in to comment.