forked from Rahix/avr-hal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
arduino-hal: Add support for Arduino Mega 1280
- Loading branch information
1 parent
4a70d2d
commit 54cffc3
Showing
15 changed files
with
229 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[build] | ||
target = "../../avr-specs/avr-atmega1280.json" | ||
|
||
[target.'cfg(target_arch = "avr")'] | ||
runner = "ravedude -cb 57600 mega1280" | ||
|
||
[unstable] | ||
build-std = ["core"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = "arduino-mega1280-examples" | ||
version = "0.0.0" | ||
authors = ["Rahix <[email protected]>"] | ||
edition = "2018" | ||
publish = false | ||
|
||
[dependencies] | ||
panic-halt = "0.2.0" | ||
ufmt = "0.1.0" | ||
nb = "0.1.2" | ||
embedded-hal = "0.2.3" | ||
|
||
[dependencies.arduino-hal] | ||
path = "../../arduino-hal/" | ||
features = ["arduino-mega1280"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
The `Mega1280` board cannot be auto-detected by ravedude, you need to specify the port explicitly. | ||
|
||
This can be done in two ways: | ||
|
||
* Add the `-P` flag to the ravedude invocation such as in the `.cargo/config.toml`, for example: | ||
```toml | ||
runner = "ravedude -P /dev/ttyUSB0 -cb 57600 mega1280" | ||
``` | ||
|
||
* Set the `RAVEDUDE_PORT` environment variable, for example: | ||
```bash | ||
RAVEDUDE_PORT=/dev/ttyUSB0 cargo run --bin mega1280-i2cdetect | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use arduino_hal::prelude::*; | ||
use panic_halt as _; | ||
|
||
use arduino_hal::adc; | ||
|
||
#[arduino_hal::entry] | ||
fn main() -> ! { | ||
let dp = arduino_hal::Peripherals::take().unwrap(); | ||
let pins = arduino_hal::pins!(dp); | ||
let mut serial = arduino_hal::default_serial!(dp, pins, 57600); | ||
|
||
let mut adc = arduino_hal::Adc::new(dp.ADC, Default::default()); | ||
|
||
let (vbg, gnd) = ( | ||
adc.read_blocking(&adc::channel::Vbg), | ||
adc.read_blocking(&adc::channel::Gnd), | ||
); | ||
ufmt::uwriteln!(&mut serial, "Vbandgap: {}", vbg).void_unwrap(); | ||
ufmt::uwriteln!(&mut serial, "Ground: {}", gnd).void_unwrap(); | ||
|
||
// To store multiple channels in an array, we use the `into_channel()` method. | ||
let channels: [adc::Channel; 16] = [ | ||
pins.a0.into_analog_input(&mut adc).into_channel(), | ||
pins.a1.into_analog_input(&mut adc).into_channel(), | ||
pins.a2.into_analog_input(&mut adc).into_channel(), | ||
pins.a3.into_analog_input(&mut adc).into_channel(), | ||
pins.a4.into_analog_input(&mut adc).into_channel(), | ||
pins.a5.into_analog_input(&mut adc).into_channel(), | ||
pins.a6.into_analog_input(&mut adc).into_channel(), | ||
pins.a7.into_analog_input(&mut adc).into_channel(), | ||
pins.a8.into_analog_input(&mut adc).into_channel(), | ||
pins.a9.into_analog_input(&mut adc).into_channel(), | ||
pins.a10.into_analog_input(&mut adc).into_channel(), | ||
pins.a11.into_analog_input(&mut adc).into_channel(), | ||
pins.a12.into_analog_input(&mut adc).into_channel(), | ||
pins.a13.into_analog_input(&mut adc).into_channel(), | ||
pins.a14.into_analog_input(&mut adc).into_channel(), | ||
pins.a15.into_analog_input(&mut adc).into_channel(), | ||
]; | ||
|
||
loop { | ||
for (i, ch) in channels.iter().enumerate() { | ||
let v = adc.read_blocking(ch); | ||
ufmt::uwrite!(&mut serial, "A{}: {} ", i, v).void_unwrap(); | ||
} | ||
|
||
ufmt::uwriteln!(&mut serial, "").void_unwrap(); | ||
arduino_hal::delay_ms(1000); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#![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); | ||
|
||
let mut led = pins.d13.into_output().downgrade(); | ||
|
||
loop { | ||
led.toggle(); | ||
arduino_hal::delay_ms(1000); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use arduino_hal::prelude::*; | ||
use panic_halt as _; | ||
|
||
#[arduino_hal::entry] | ||
fn main() -> ! { | ||
let dp = arduino_hal::Peripherals::take().unwrap(); | ||
let pins = arduino_hal::pins!(dp); | ||
let mut serial = arduino_hal::default_serial!(dp, pins, 57600); | ||
|
||
let mut i2c = arduino_hal::I2c::new( | ||
dp.TWI, | ||
pins.d20.into_pull_up_input(), | ||
pins.d21.into_pull_up_input(), | ||
50000, | ||
); | ||
|
||
ufmt::uwriteln!(&mut serial, "Write direction test:\r").void_unwrap(); | ||
i2c.i2cdetect(&mut serial, arduino_hal::i2c::Direction::Write).void_unwrap(); | ||
ufmt::uwriteln!(&mut serial, "\r\nRead direction test:\r").void_unwrap(); | ||
i2c.i2cdetect(&mut serial, arduino_hal::i2c::Direction::Read).void_unwrap(); | ||
|
||
loop {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use arduino_hal::prelude::*; | ||
use panic_halt as _; | ||
|
||
use embedded_hal::serial::Read; | ||
|
||
#[arduino_hal::entry] | ||
fn main() -> ! { | ||
let dp = arduino_hal::Peripherals::take().unwrap(); | ||
let pins = arduino_hal::pins!(dp); | ||
let mut serial = arduino_hal::default_serial!(dp, pins, 57600); | ||
|
||
ufmt::uwriteln!(&mut serial, "Hello from Arduino!\r").void_unwrap(); | ||
|
||
loop { | ||
// Read a byte from the serial connection | ||
let b = nb::block!(serial.read()).void_unwrap(); | ||
|
||
// Answer | ||
ufmt::uwriteln!(&mut serial, "Got {}!\r", b).void_unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//! This example demonstrates how to set up a SPI interface and communicate | ||
//! over it. The physical hardware configuation consists of connecting a | ||
//! jumper directly from pin `d50` (MISO/PB3) to pin `d51` (MOSI/PB2). | ||
//! | ||
//! Once this program is written to the board, the serial output can be | ||
//! accessed with | ||
//! | ||
//! ``` | ||
//! sudo screen /dev/ttyACM0 57600 | ||
//! ``` | ||
//! | ||
//! You should see it output the line `data: 15` repeatedly (aka 0b00001111). | ||
//! If the output you see is `data: 255`, you may need to check your jumper. | ||
#![no_std] | ||
#![no_main] | ||
|
||
use arduino_hal::prelude::*; | ||
use arduino_hal::spi; | ||
use embedded_hal::spi::FullDuplex; | ||
use panic_halt as _; | ||
|
||
#[arduino_hal::entry] | ||
fn main() -> ! { | ||
let dp = arduino_hal::Peripherals::take().unwrap(); | ||
let pins = arduino_hal::pins!(dp); | ||
|
||
// set up serial interface for text output | ||
let mut serial = arduino_hal::default_serial!(dp, pins, 57600); | ||
|
||
// Create SPI interface. | ||
let (mut spi, _) = arduino_hal::Spi::new( | ||
dp.SPI, | ||
pins.d52.into_output(), | ||
pins.d51.into_output(), | ||
pins.d50.into_pull_up_input(), | ||
pins.d53.into_output(), | ||
spi::Settings::default(), | ||
); | ||
|
||
loop { | ||
// Send a byte | ||
nb::block!(spi.send(0b00001111)).void_unwrap(); | ||
// Because MISO is connected to MOSI, the read data should be the same | ||
let data = nb::block!(spi.read()).void_unwrap(); | ||
|
||
ufmt::uwriteln!(&mut serial, "data: {}\r", data).void_unwrap(); | ||
arduino_hal::delay_ms(1000); | ||
} | ||
} |