-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for SparkFun Pro Micro 3.3V (8MHz)
- Loading branch information
Showing
20 changed files
with
232 additions
and
11 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
File renamed without changes.
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 @@ | ||
[package] | ||
name = "sparkfun-promicro-examples" | ||
version = "0.0.0" | ||
authors = ["Rahix <rahix@rahix.de>"] | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
panic-halt = "0.2.0" | ||
ufmt = "0.2.0" | ||
nb = "1.1.0" | ||
embedded-hal = "1.0" | ||
|
||
[dependencies.embedded-hal-v0] | ||
version = "0.2.3" | ||
package = "embedded-hal" | ||
|
||
[dependencies.arduino-hal] | ||
path = "../../arduino-hal/" | ||
features = ["sparkfun-promicro-3v3"] | ||
|
||
# The latest releases of `proc-macro2` do not support the rust toolchain that | ||
# we use. Thus, we must fix this dependency to an older version where our | ||
# toolchain is still supported. See https://github.com/Rahix/avr-hal/issues/537 | ||
[build-dependencies.proc-macro2] | ||
version = "=1.0.79" |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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-atmega32u4.json" | ||
|
||
[target.'cfg(target_arch = "avr")'] | ||
runner = "ravedude promicro" | ||
|
||
[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
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,46 @@ | ||
#![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, tmp) = ( | ||
adc.read_blocking(&adc::channel::Vbg), | ||
adc.read_blocking(&adc::channel::Gnd), | ||
adc.read_blocking(&adc::channel::Temperature), | ||
); | ||
ufmt::uwriteln!(&mut serial, "Vbandgap: {}", vbg).unwrap_infallible(); | ||
ufmt::uwriteln!(&mut serial, "Ground: {}", gnd).unwrap_infallible(); | ||
ufmt::uwriteln!(&mut serial, "Temperature: {}", tmp).unwrap_infallible(); | ||
|
||
let a0 = pins.a0.into_analog_input(&mut adc); | ||
let a1 = pins.a1.into_analog_input(&mut adc); | ||
let a2 = pins.a2.into_analog_input(&mut adc); | ||
let a3 = pins.a3.into_analog_input(&mut adc); | ||
|
||
loop { | ||
let values = [ | ||
a0.analog_read(&mut adc), | ||
a1.analog_read(&mut adc), | ||
a2.analog_read(&mut adc), | ||
a3.analog_read(&mut adc), | ||
]; | ||
|
||
for (i, v) in values.iter().enumerate() { | ||
ufmt::uwrite!(&mut serial, "A{}: {} ", i, v).unwrap_infallible(); | ||
} | ||
|
||
ufmt::uwriteln!(&mut serial, "").unwrap_infallible(); | ||
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,22 @@ | ||
#![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 led1 = pins.led_rx.into_output(); | ||
let mut led2 = pins.led_tx.into_output(); | ||
|
||
loop { | ||
led1.set_high(); | ||
led2.set_low(); | ||
arduino_hal::delay_ms(300); | ||
led1.set_low(); | ||
led2.set_high(); | ||
arduino_hal::delay_ms(300); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
examples/sparkfun-promicro-5v/src/bin/promicro-i2cdetect.rs
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,28 @@ | ||
#![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.d2.into_pull_up_input(), | ||
pins.d3.into_pull_up_input(), | ||
50000, | ||
); | ||
|
||
ufmt::uwriteln!(&mut serial, "Write direction test:\r").unwrap_infallible(); | ||
i2c.i2cdetect(&mut serial, arduino_hal::i2c::Direction::Write) | ||
.unwrap_infallible(); | ||
ufmt::uwriteln!(&mut serial, "\r\nRead direction test:\r").unwrap_infallible(); | ||
i2c.i2cdetect(&mut serial, arduino_hal::i2c::Direction::Read) | ||
.unwrap_infallible(); | ||
|
||
loop {} | ||
} |
50 changes: 50 additions & 0 deletions
50
examples/sparkfun-promicro-5v/src/bin/promicro-spi-feedback.rs
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 `~14` to pin `~16`. | ||
//! | ||
//! 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_v0::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.d15.into_output(), | ||
pins.d14.into_output(), | ||
pins.d16.into_pull_up_input(), | ||
pins.led_rx.into_output(), | ||
spi::Settings::default(), | ||
); | ||
|
||
loop { | ||
// Send a byte | ||
nb::block!(spi.send(0b00001111)).unwrap_infallible(); | ||
// Because MISO is connected to MOSI, the read data should be the same | ||
let data = nb::block!(spi.read()).unwrap_infallible(); | ||
|
||
ufmt::uwriteln!(&mut serial, "data: {}\r", data).unwrap_infallible(); | ||
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,24 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
use arduino_hal::prelude::*; | ||
use panic_halt as _; | ||
|
||
use embedded_hal_v0::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").unwrap_infallible(); | ||
|
||
loop { | ||
// Read a byte from the serial connection | ||
let b = nb::block!(serial.read()).unwrap_infallible(); | ||
|
||
// Answer | ||
ufmt::uwriteln!(&mut serial, "Got {}!\r", b).unwrap_infallible(); | ||
} | ||
} |