Compare commits
17 Commits
Author | SHA1 | Date |
---|---|---|
Robin Müller | bdd804f88b | |
Robin Müller | f4cd3b704b | |
Robin Müller | 7e2bb8618e | |
Robin Müller | 6931432dcd | |
Robin Müller | 742a53d63a | |
Robin Müller | 3304410a64 | |
Robin Müller | 37629f2ba1 | |
Robin Müller | bffba52fa5 | |
Robin Müller | ab439ac35d | |
Robin Müller | 1eb7deeb9f | |
Robin Müller | 2195a9f678 | |
Robin Müller | 2f503ac3b1 | |
Robin Müller | 0c5a5efea0 | |
Robin Müller | a901e4fcac | |
Robin Müller | 3025ec70ab | |
Robin Müller | 403407547d | |
Robin Müller | 850bd08eae |
|
@ -16,14 +16,11 @@ jobs:
|
|||
override: true
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
use-cross: true
|
||||
command: check
|
||||
args: --target thumbv6m-none-eabi
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
use-cross: true
|
||||
command: check
|
||||
args: --examples --target thumbv6m-none-eabi
|
||||
args: --examples
|
||||
|
||||
fmt:
|
||||
name: Rustfmt
|
||||
|
@ -55,9 +52,8 @@ jobs:
|
|||
- run: rustup component add clippy
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
use-cross: true
|
||||
command: clippy
|
||||
args: --target thumbv6m-none-eabi -- -D warnings
|
||||
args: -- -D warnings
|
||||
|
||||
ci:
|
||||
if: ${{ success() }}
|
||||
|
|
15
CHANGELOG.md
15
CHANGELOG.md
|
@ -8,6 +8,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|||
|
||||
## [unreleased]
|
||||
|
||||
## [v0.4.0]
|
||||
|
||||
- Update manifest file to have correct links and license
|
||||
- Update some dependencies
|
||||
- `cortex-m-rtic` (dev-depencency) to 1.1.2
|
||||
- Other dependencies: Only revision has changed
|
||||
|
||||
## [v0.3.2]
|
||||
|
||||
- Bump HAL dependency to v0.5.0. Changed API, especially for IRQ handling
|
||||
|
||||
## [v0.3.1]
|
||||
|
||||
- Updated ADC code and dependency
|
||||
|
||||
## [v0.3.0]
|
||||
|
||||
- Completed baseline features to support all sensors on the REB1 sevice
|
||||
|
|
36
Cargo.toml
36
Cargo.toml
|
@ -1,32 +1,38 @@
|
|||
[package]
|
||||
name = "vorago-reb1"
|
||||
version = "0.3.0"
|
||||
version = "0.4.0"
|
||||
authors = ["Robin Mueller <robin.mueller.m@gmail.com>"]
|
||||
edition = "2021"
|
||||
description = "Board Support Crate for the Vorago REB1 development board"
|
||||
homepage = "https://github.com/robamu/vorago-reb1-rs"
|
||||
repository = "https://github.com/robamu/vorago-reb1-rs"
|
||||
license = "MIT OR Apache-2.0"
|
||||
homepage = "https://egit.irs.uni-stuttgart.de/rust/vorago-reb1"
|
||||
repository = "https://egit.irs.uni-stuttgart.de/rust/vorago-reb1"
|
||||
license = "Apache-2.0"
|
||||
keywords = ["no-std", "reb1", "cortex-m", "vorago", "va108xx"]
|
||||
categories = ["embedded", "no-std", "hardware-support"]
|
||||
categories = ["aerospace", "embedded", "no-std", "hardware-support"]
|
||||
|
||||
[dependencies]
|
||||
cortex-m = "0.7.3"
|
||||
cortex-m-rt = "0.7.0"
|
||||
embedded-hal = "0.2.6"
|
||||
dummy-pin = "0.1.1"
|
||||
max116xx-10bit = "0.1.0"
|
||||
cortex-m = "0.7"
|
||||
cortex-m-rt = "0.7"
|
||||
embedded-hal = "0.2.7"
|
||||
dummy-pin = "0.1"
|
||||
max116xx-10bit = "0.2"
|
||||
|
||||
[dependencies.va108xx-hal]
|
||||
version = "0.4.2"
|
||||
version = "0.5"
|
||||
features = ["rt"]
|
||||
|
||||
[features]
|
||||
rt = ["va108xx-hal/rt"]
|
||||
|
||||
[dev-dependencies]
|
||||
cortex-m-rtic = "0.6.0-rc.4"
|
||||
panic-rtt-target = { version = "0.1", features = ["cortex-m"] }
|
||||
rtt-target = { version = "0.3", features = ["cortex-m"] }
|
||||
cortex-m-rtic = "1.1"
|
||||
panic-halt = "0.2"
|
||||
nb = "1.0.0"
|
||||
nb = "1"
|
||||
|
||||
[dev-dependencies.rtt-target]
|
||||
version = "0.3"
|
||||
features = ["cortex-m"]
|
||||
|
||||
[dev-dependencies.panic-rtt-target]
|
||||
version = "0.1"
|
||||
features = ["cortex-m"]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[![Crates.io](https://img.shields.io/crates/v/vorago-reb1)](https://crates.io/crates/vorago-reb1)
|
||||
[![ci](https://github.com/robamu-org/vorago-reb1-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/robamu-org/vorago-reb1-rs/actions/workflows/ci.yml)
|
||||
[![ci](https://github.com/us-irs/vorago-reb1-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/us-irs/vorago-reb1-rs/actions/workflows/ci.yml)
|
||||
[![docs.rs](https://img.shields.io/docsrs/vorago-reb1)](https://docs.rs/vorago-reb1)
|
||||
|
||||
# Rust BSP for the Vorago REB1 development board
|
||||
|
@ -7,7 +7,7 @@
|
|||
This is the Rust **B**oard **S**upport **P**ackage crate for the Vorago REB1 development board.
|
||||
Its aim is to provide drivers for the board features of the REB1 board
|
||||
|
||||
The BSP builds on top of the [HAL crate for VA108xx devices](https://github.com/robamu-org/va108xx-hal-rs).
|
||||
The BSP builds on top of the [HAL crate for VA108xx devices](https://egit.irs.uni-stuttgart.de/rust/va108xx-hal).
|
||||
|
||||
## Building
|
||||
|
||||
|
@ -58,8 +58,9 @@ A `jlink.gdb` file is provided to allow flashing of the board from the command l
|
|||
|
||||
## Debugging with VS Code
|
||||
|
||||
The REB1 board features an on-board JTAG, so all that is required to flash the board is a
|
||||
Micro-USB cable and an
|
||||
The REB1 board features an on-board JTAG, so all that is required to debug the board is a
|
||||
Micro-USB cable.
|
||||
|
||||
You can debug applications on the REB1 board with a graphical user interface using VS Code with
|
||||
the [`Cortex-Debug` plugin](https://marketplace.visualstudio.com/items?itemName=marus25.cortex-debug).
|
||||
|
||||
|
|
|
@ -3,11 +3,7 @@
|
|||
use cortex_m_rt::entry;
|
||||
use panic_rtt_target as _;
|
||||
use rtt_target::{rprintln, rtt_init_print};
|
||||
use va108xx_hal::{
|
||||
pac::{self, interrupt},
|
||||
prelude::*,
|
||||
timer::{default_ms_irq_handler, set_up_ms_timer, Delay},
|
||||
};
|
||||
use va108xx_hal::{pac, prelude::*, timer::set_up_ms_delay_provider};
|
||||
use vorago_reb1::temp_sensor::Adt75TempSensor;
|
||||
|
||||
#[entry]
|
||||
|
@ -15,14 +11,7 @@ fn main() -> ! {
|
|||
rtt_init_print!();
|
||||
rprintln!("-- Vorago Temperature Sensor and I2C Example --");
|
||||
let mut dp = pac::Peripherals::take().unwrap();
|
||||
let tim0 = set_up_ms_timer(
|
||||
&mut dp.SYSCONFIG,
|
||||
&mut dp.IRQSEL,
|
||||
50.mhz().into(),
|
||||
dp.TIM0,
|
||||
interrupt::OC0,
|
||||
);
|
||||
let mut delay = Delay::new(tim0);
|
||||
let mut delay = set_up_ms_delay_provider(&mut dp.SYSCONFIG, 50.mhz(), dp.TIM0);
|
||||
unsafe {
|
||||
cortex_m::peripheral::NVIC::unmask(pac::Interrupt::OC0);
|
||||
}
|
||||
|
@ -34,11 +23,6 @@ fn main() -> ! {
|
|||
.read_temperature()
|
||||
.expect("Failed reading temperature");
|
||||
rprintln!("Temperature in Celcius: {}", temp);
|
||||
delay.delay_ms(500);
|
||||
delay.delay_ms(500_u16);
|
||||
}
|
||||
}
|
||||
|
||||
#[interrupt]
|
||||
fn OC0() {
|
||||
default_ms_irq_handler();
|
||||
}
|
||||
|
|
|
@ -10,10 +10,10 @@ use panic_rtt_target as _;
|
|||
use rtt_target::{rprintln, rtt_init_print};
|
||||
use va108xx_hal::{
|
||||
gpio::PinsA,
|
||||
pac::{self, interrupt},
|
||||
pac,
|
||||
prelude::*,
|
||||
spi::{Spi, SpiConfig, TransferConfig},
|
||||
timer::{default_ms_irq_handler, set_up_ms_timer, Delay},
|
||||
timer::set_up_ms_delay_provider,
|
||||
};
|
||||
|
||||
const READ_MASK: u8 = 1 << 7;
|
||||
|
@ -28,18 +28,7 @@ fn main() -> ! {
|
|||
rtt_init_print!();
|
||||
rprintln!("-- Vorago Accelerometer Example --");
|
||||
let mut dp = pac::Peripherals::take().unwrap();
|
||||
let tim0 = set_up_ms_timer(
|
||||
&mut dp.SYSCONFIG,
|
||||
&mut dp.IRQSEL,
|
||||
50.mhz().into(),
|
||||
dp.TIM0,
|
||||
interrupt::OC0,
|
||||
);
|
||||
let mut delay = Delay::new(tim0);
|
||||
unsafe {
|
||||
cortex_m::peripheral::NVIC::unmask(pac::Interrupt::OC0);
|
||||
}
|
||||
|
||||
let mut delay = set_up_ms_delay_provider(&mut dp.SYSCONFIG, 50.mhz(), dp.TIM0);
|
||||
let pinsa = PinsA::new(&mut dp.SYSCONFIG, None, dp.PORTA);
|
||||
let spi_cfg = SpiConfig::default();
|
||||
let (sck, mosi, miso) = (
|
||||
|
@ -78,12 +67,7 @@ fn main() -> ! {
|
|||
.expect("Enabling measurement mode failed");
|
||||
|
||||
loop {
|
||||
delay.delay_ms(500);
|
||||
delay.delay_ms(500_u16);
|
||||
unimplemented!("Not implemented for now, is not populated on the board..");
|
||||
}
|
||||
}
|
||||
|
||||
#[interrupt]
|
||||
fn OC0() {
|
||||
default_ms_irq_handler();
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ use va108xx_hal::{
|
|||
pac::{self, interrupt},
|
||||
prelude::*,
|
||||
time::Hertz,
|
||||
timer::{default_ms_irq_handler, set_up_ms_timer},
|
||||
timer::{default_ms_irq_handler, set_up_ms_timer, IrqCfg},
|
||||
};
|
||||
use vorago_reb1::button::Button;
|
||||
use vorago_reb1::leds::Leds;
|
||||
|
@ -45,9 +45,9 @@ fn main() -> ! {
|
|||
// Configure an edge interrupt on the button and route it to interrupt vector 15
|
||||
let mut button = Button::new(pinsa.pa11.into_floating_input()).edge_irq(
|
||||
edge_irq,
|
||||
IrqCfg::new(pac::interrupt::OC15, true, true),
|
||||
Some(&mut dp.SYSCONFIG),
|
||||
&mut dp.IRQSEL,
|
||||
pac::interrupt::OC15,
|
||||
Some(&mut dp.IRQSEL),
|
||||
);
|
||||
|
||||
if PRESS_MODE == PressMode::Toggle {
|
||||
|
@ -61,11 +61,11 @@ fn main() -> ! {
|
|||
}
|
||||
|
||||
set_up_ms_timer(
|
||||
IrqCfg::new(pac::Interrupt::OC0, true, true),
|
||||
&mut dp.SYSCONFIG,
|
||||
&mut dp.IRQSEL,
|
||||
50.mhz().into(),
|
||||
Some(&mut dp.IRQSEL),
|
||||
50.mhz(),
|
||||
dp.TIM0,
|
||||
interrupt::OC0,
|
||||
);
|
||||
let mut leds = Leds::new(
|
||||
pinsa.pa10.into_push_pull_output(),
|
||||
|
@ -75,8 +75,6 @@ fn main() -> ! {
|
|||
for led in leds.iter_mut() {
|
||||
led.off();
|
||||
}
|
||||
// Activate the IRQs so the processors sees them as well
|
||||
unmask_irqs();
|
||||
// Make both button and LEDs accessible from the IRQ handler as well
|
||||
cortex_m::interrupt::free(|cs| {
|
||||
LEDS.borrow(cs).replace(Some(leds));
|
||||
|
@ -85,13 +83,6 @@ fn main() -> ! {
|
|||
loop {}
|
||||
}
|
||||
|
||||
fn unmask_irqs() {
|
||||
unsafe {
|
||||
cortex_m::peripheral::NVIC::unmask(pac::Interrupt::OC0);
|
||||
cortex_m::peripheral::NVIC::unmask(pac::Interrupt::OC15);
|
||||
}
|
||||
}
|
||||
|
||||
#[interrupt]
|
||||
fn OC0() {
|
||||
default_ms_irq_handler();
|
||||
|
|
|
@ -9,10 +9,10 @@ mod app {
|
|||
use va108xx_hal::{
|
||||
clock::{set_clk_div_register, FilterClkSel},
|
||||
gpio::{FilterType, InterruptEdge, PinsA},
|
||||
pac::{self, interrupt},
|
||||
pac,
|
||||
prelude::*,
|
||||
time::Hertz,
|
||||
timer::{default_ms_irq_handler, set_up_ms_timer},
|
||||
timer::{default_ms_irq_handler, set_up_ms_timer, IrqCfg},
|
||||
};
|
||||
use vorago_reb1::button::Button;
|
||||
use vorago_reb1::leds::Leds;
|
||||
|
@ -66,9 +66,9 @@ mod app {
|
|||
// Configure an edge interrupt on the button and route it to interrupt vector 15
|
||||
let mut button = Button::new(pinsa.pa11.into_floating_input()).edge_irq(
|
||||
edge_irq,
|
||||
IrqCfg::new(pac::interrupt::OC15, true, true),
|
||||
Some(&mut dp.SYSCONFIG),
|
||||
&mut dp.IRQSEL,
|
||||
pac::interrupt::OC15,
|
||||
Some(&mut dp.IRQSEL),
|
||||
);
|
||||
|
||||
if mode == PressMode::Toggle {
|
||||
|
@ -80,14 +80,6 @@ mod app {
|
|||
Hertz::from(50.khz()).0,
|
||||
);
|
||||
}
|
||||
|
||||
set_up_ms_timer(
|
||||
&mut dp.SYSCONFIG,
|
||||
&mut dp.IRQSEL,
|
||||
50.mhz().into(),
|
||||
dp.TIM0,
|
||||
interrupt::OC0,
|
||||
);
|
||||
let mut leds = Leds::new(
|
||||
pinsa.pa10.into_push_pull_output(),
|
||||
pinsa.pa7.into_push_pull_output(),
|
||||
|
@ -96,8 +88,13 @@ mod app {
|
|||
for led in leds.iter_mut() {
|
||||
led.off();
|
||||
}
|
||||
// Activate the IRQs so the processors sees them as well
|
||||
unmask_irqs();
|
||||
set_up_ms_timer(
|
||||
IrqCfg::new(pac::Interrupt::OC0, true, true),
|
||||
&mut dp.SYSCONFIG,
|
||||
Some(&mut dp.IRQSEL),
|
||||
50.mhz(),
|
||||
dp.TIM0,
|
||||
);
|
||||
(Shared {}, Local { leds, button, mode }, init::Monotonics())
|
||||
}
|
||||
|
||||
|
@ -128,13 +125,6 @@ mod app {
|
|||
default_ms_irq_handler();
|
||||
}
|
||||
|
||||
fn unmask_irqs() {
|
||||
unsafe {
|
||||
cortex_m::peripheral::NVIC::unmask(pac::Interrupt::OC0);
|
||||
cortex_m::peripheral::NVIC::unmask(pac::Interrupt::OC15);
|
||||
}
|
||||
}
|
||||
|
||||
fn prompt_mode(mut down_channel: rtt_target::DownChannel) -> PressMode {
|
||||
rprintln!("Using prompt mode");
|
||||
rprintln!("Please enter the mode [0: Toggle, 1: Keep]");
|
||||
|
@ -145,11 +135,11 @@ mod app {
|
|||
for i in 0..read {
|
||||
let val = read_buf[i] as char;
|
||||
if val == '0' || val == '1' {
|
||||
if val == '0' {
|
||||
return PressMode::Toggle;
|
||||
return if val == '0' {
|
||||
PressMode::Toggle
|
||||
} else {
|
||||
return PressMode::Keep;
|
||||
}
|
||||
PressMode::Keep
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
use cortex_m_rt::entry;
|
||||
use embedded_hal::digital::v2::ToggleableOutputPin;
|
||||
use panic_halt as _;
|
||||
use va108xx_hal::{gpio::pins::PinsA, pac, prelude::*};
|
||||
use va108xx_hal::{gpio::pins::PinsA, pac, prelude::*, timer::set_up_ms_delay_provider};
|
||||
use vorago_reb1::leds::Leds;
|
||||
|
||||
// REB LED pin definitions. All on port A
|
||||
|
@ -64,23 +64,24 @@ fn main() -> ! {
|
|||
let mut led1 = pins.pa10.into_push_pull_output();
|
||||
let mut led2 = pins.pa7.into_push_pull_output();
|
||||
let mut led3 = pins.pa6.into_push_pull_output();
|
||||
let mut delay = set_up_ms_delay_provider(&mut dp.SYSCONFIG, 50.mhz(), dp.TIM0);
|
||||
for _ in 0..10 {
|
||||
led1.set_low().ok();
|
||||
led2.set_low().ok();
|
||||
led3.set_low().ok();
|
||||
cortex_m::asm::delay(5_000_000);
|
||||
delay.delay_ms(200_u16);
|
||||
led1.set_high().ok();
|
||||
led2.set_high().ok();
|
||||
led3.set_high().ok();
|
||||
cortex_m::asm::delay(5_000_000);
|
||||
delay.delay_ms(200_u16);
|
||||
}
|
||||
loop {
|
||||
led1.toggle().ok();
|
||||
cortex_m::asm::delay(5_000_000);
|
||||
delay.delay_ms(200_u16);
|
||||
led2.toggle().ok();
|
||||
cortex_m::asm::delay(5_000_000);
|
||||
delay.delay_ms(200_u16);
|
||||
led3.toggle().ok();
|
||||
cortex_m::asm::delay(5_000_000);
|
||||
delay.delay_ms(200_u16);
|
||||
}
|
||||
}
|
||||
LibType::Bsp => {
|
||||
|
@ -90,22 +91,21 @@ fn main() -> ! {
|
|||
pinsa.pa7.into_push_pull_output(),
|
||||
pinsa.pa6.into_push_pull_output(),
|
||||
);
|
||||
let mut delay = set_up_ms_delay_provider(&mut dp.SYSCONFIG, 50.mhz(), dp.TIM0);
|
||||
loop {
|
||||
for _ in 0..10 {
|
||||
// Blink all LEDs quickly
|
||||
for led in leds.iter_mut() {
|
||||
led.toggle();
|
||||
}
|
||||
cortex_m::asm::delay(5_000_000);
|
||||
delay.delay_ms(200_u16);
|
||||
}
|
||||
// Now use a wave pattern
|
||||
loop {
|
||||
leds[0].toggle();
|
||||
cortex_m::asm::delay(5_000_000);
|
||||
leds[1].toggle();
|
||||
cortex_m::asm::delay(5_000_000);
|
||||
leds[2].toggle();
|
||||
cortex_m::asm::delay(5_000_000);
|
||||
for led in leds.iter_mut() {
|
||||
led.toggle();
|
||||
delay.delay_ms(200_u16);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,28 +2,31 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use core::panic;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use embedded_hal::spi;
|
||||
use embedded_hal::{blocking::delay::DelayUs, spi};
|
||||
use max116xx_10bit::VoltageRefMode;
|
||||
use max116xx_10bit::{AveragingConversions, AveragingResults};
|
||||
use panic_rtt_target as _;
|
||||
use rtt_target::{rprintln, rtt_init_print};
|
||||
use va108xx_hal::timer::CountDownTimer;
|
||||
use va108xx_hal::{
|
||||
gpio::PinsA,
|
||||
pac::{self, interrupt, SPIB},
|
||||
prelude::*,
|
||||
spi::{Spi, SpiBase, SpiConfig, TransferConfig},
|
||||
timer::{default_ms_irq_handler, set_up_ms_timer, Delay},
|
||||
timer::{default_ms_irq_handler, set_up_ms_timer, Delay, IrqCfg},
|
||||
utility::{port_mux, Funsel, PortSel},
|
||||
};
|
||||
use vorago_reb1::max11619::{
|
||||
max11619_externally_clocked, max11619_internally_clocked, EocPin, AN2_CHANNEL,
|
||||
POTENTIOMETER_CHANNEL,
|
||||
max11619_externally_clocked_no_wakeup, max11619_externally_clocked_with_wakeup,
|
||||
max11619_internally_clocked, EocPin, AN2_CHANNEL, POTENTIOMETER_CHANNEL,
|
||||
};
|
||||
|
||||
#[derive(Debug, PartialEq, Copy, Clone)]
|
||||
pub enum ExampleMode {
|
||||
UsingEoc,
|
||||
NotUsingEoc,
|
||||
NotUsingEocWithDelay,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Copy, Clone)]
|
||||
|
@ -31,10 +34,18 @@ pub enum ReadMode {
|
|||
Single,
|
||||
Multiple,
|
||||
MultipleNToHighest,
|
||||
AverageN,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Copy, Clone)]
|
||||
pub enum MuxMode {
|
||||
None,
|
||||
PortB19to17,
|
||||
}
|
||||
|
||||
const EXAMPLE_MODE: ExampleMode = ExampleMode::NotUsingEoc;
|
||||
const READ_MODE: ReadMode = ReadMode::Multiple;
|
||||
const MUX_MODE: MuxMode = MuxMode::None;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
|
@ -43,11 +54,11 @@ fn main() -> ! {
|
|||
|
||||
let mut dp = pac::Peripherals::take().unwrap();
|
||||
let tim0 = set_up_ms_timer(
|
||||
IrqCfg::new(pac::Interrupt::OC0, true, true),
|
||||
&mut dp.SYSCONFIG,
|
||||
&mut dp.IRQSEL,
|
||||
50.mhz().into(),
|
||||
Some(&mut dp.IRQSEL),
|
||||
50.mhz(),
|
||||
dp.TIM0,
|
||||
interrupt::OC0,
|
||||
);
|
||||
let delay = Delay::new(tim0);
|
||||
unsafe {
|
||||
|
@ -62,6 +73,12 @@ fn main() -> ! {
|
|||
pinsa.pa18.into_funsel_2(),
|
||||
);
|
||||
|
||||
if MUX_MODE == MuxMode::PortB19to17 {
|
||||
port_mux(&mut dp.IOCONFIG, PortSel::PortB, 19, Funsel::Funsel1).ok();
|
||||
port_mux(&mut dp.IOCONFIG, PortSel::PortB, 18, Funsel::Funsel1).ok();
|
||||
port_mux(&mut dp.IOCONFIG, PortSel::PortB, 17, Funsel::Funsel1).ok();
|
||||
port_mux(&mut dp.IOCONFIG, PortSel::PortB, 16, Funsel::Funsel1).ok();
|
||||
}
|
||||
// Set the accelerometer chip select low in case the board slot is populated
|
||||
let mut accel_cs = pinsa.pa16.into_push_pull_output();
|
||||
accel_cs
|
||||
|
@ -89,6 +106,10 @@ fn main() -> ! {
|
|||
ExampleMode::UsingEoc => {
|
||||
spi_example_internally_clocked(spi, delay, pinsa.pa14.into_floating_input());
|
||||
}
|
||||
ExampleMode::NotUsingEocWithDelay => {
|
||||
let delay_us = CountDownTimer::new(&mut dp.SYSCONFIG, 50.mhz(), dp.TIM2);
|
||||
spi_example_externally_clocked_with_delay(spi, delay, delay_us);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -97,9 +118,17 @@ fn OC0() {
|
|||
default_ms_irq_handler();
|
||||
}
|
||||
|
||||
/// Use the SPI clock as the conversion clock
|
||||
fn spi_example_externally_clocked(spi: SpiBase<SPIB>, mut delay: Delay) -> ! {
|
||||
let mut adc = max11619_externally_clocked(spi)
|
||||
let mut adc = max11619_externally_clocked_no_wakeup(spi)
|
||||
.expect("Creating externally clocked MAX11619 device failed");
|
||||
if READ_MODE == ReadMode::AverageN {
|
||||
adc.averaging(
|
||||
AveragingConversions::FourConversions,
|
||||
AveragingResults::FourResults,
|
||||
)
|
||||
.expect("Error setting up averaging register");
|
||||
}
|
||||
let mut cmd_buf: [u8; 32] = [0; 32];
|
||||
let mut counter = 0;
|
||||
loop {
|
||||
|
@ -108,50 +137,36 @@ fn spi_example_externally_clocked(spi: SpiBase<SPIB>, mut delay: Delay) -> ! {
|
|||
match READ_MODE {
|
||||
ReadMode::Single => {
|
||||
rprintln!("Reading single potentiometer channel");
|
||||
let pot_val = match adc.read_single_channel(&mut cmd_buf, POTENTIOMETER_CHANNEL) {
|
||||
Ok(pot_val) => pot_val,
|
||||
_ => {
|
||||
panic!("Creating externally clocked MAX11619 ADC failed");
|
||||
}
|
||||
};
|
||||
let pot_val = adc
|
||||
.read_single_channel(&mut cmd_buf, POTENTIOMETER_CHANNEL)
|
||||
.expect("Creating externally clocked MAX11619 ADC failed");
|
||||
rprintln!("Single channel read:");
|
||||
rprintln!("\tPotentiometer value: {}", pot_val);
|
||||
}
|
||||
ReadMode::Multiple => {
|
||||
let mut res_buf: [u16; 4] = [0; 4];
|
||||
match adc.read_multiple_channels_0_to_n(
|
||||
adc.read_multiple_channels_0_to_n(
|
||||
&mut cmd_buf,
|
||||
&mut res_buf.iter_mut(),
|
||||
POTENTIOMETER_CHANNEL,
|
||||
) {
|
||||
Ok(_) => {
|
||||
rprintln!("Multi channel read from 0 to 3:");
|
||||
rprintln!("\tAN0 value: {}", res_buf[0]);
|
||||
rprintln!("\tAN1 value: {}", res_buf[1]);
|
||||
rprintln!("\tAN2 value: {}", res_buf[2]);
|
||||
rprintln!("\tAN3 / Potentiometer value: {}", res_buf[3]);
|
||||
}
|
||||
_ => {
|
||||
panic!("Multi-Channel read failed");
|
||||
}
|
||||
}
|
||||
)
|
||||
.expect("Multi-Channel read failed");
|
||||
print_res_buf(&res_buf);
|
||||
}
|
||||
ReadMode::MultipleNToHighest => {
|
||||
let mut res_buf: [u16; 2] = [0; 2];
|
||||
match adc.read_multiple_channels_n_to_highest(
|
||||
adc.read_multiple_channels_n_to_highest(
|
||||
&mut cmd_buf,
|
||||
&mut res_buf.iter_mut(),
|
||||
AN2_CHANNEL,
|
||||
) {
|
||||
Ok(_) => {
|
||||
rprintln!("Multi channel read from 2 to 3:");
|
||||
rprintln!("\tAN2 value: {}", res_buf[0]);
|
||||
rprintln!("\tAN3 / Potentiometer value: {}", res_buf[1]);
|
||||
}
|
||||
_ => {
|
||||
panic!("Multi-Channel read failed");
|
||||
}
|
||||
}
|
||||
)
|
||||
.expect("Multi-Channel read failed");
|
||||
rprintln!("Multi channel read from 2 to 3:");
|
||||
rprintln!("\tAN2 value: {}", res_buf[0]);
|
||||
rprintln!("\tAN3 / Potentiometer value: {}", res_buf[1]);
|
||||
}
|
||||
ReadMode::AverageN => {
|
||||
rprintln!("Scanning and averaging not possible for externally clocked mode");
|
||||
}
|
||||
}
|
||||
counter += 1;
|
||||
|
@ -159,22 +174,122 @@ fn spi_example_externally_clocked(spi: SpiBase<SPIB>, mut delay: Delay) -> ! {
|
|||
}
|
||||
}
|
||||
|
||||
fn spi_example_internally_clocked(spi: SpiBase<SPIB>, mut delay: Delay, mut eoc_pin: EocPin) -> ! {
|
||||
let mut adc = max11619_internally_clocked(spi).expect("Creaintg MAX116xx device failed");
|
||||
fn spi_example_externally_clocked_with_delay(
|
||||
spi: SpiBase<SPIB>,
|
||||
mut delay: Delay,
|
||||
mut delay_us: impl DelayUs<u8>,
|
||||
) -> ! {
|
||||
let mut adc =
|
||||
max11619_externally_clocked_with_wakeup(spi).expect("Creating MAX116xx device failed");
|
||||
let mut cmd_buf: [u8; 32] = [0; 32];
|
||||
let mut counter = 0;
|
||||
loop {
|
||||
rprintln!("-- Measurement {} --", counter);
|
||||
match adc.request_single_channel(POTENTIOMETER_CHANNEL) {
|
||||
Ok(_) => (),
|
||||
_ => panic!("Requesting single channel value failed"),
|
||||
};
|
||||
|
||||
let pot_val = match nb::block!(adc.get_single_channel(&mut eoc_pin)) {
|
||||
Ok(pot_val) => pot_val,
|
||||
_ => panic!("Reading single channel value failed"),
|
||||
};
|
||||
rprintln!("\tPotentiometer value: {}", pot_val);
|
||||
match READ_MODE {
|
||||
ReadMode::Single => {
|
||||
rprintln!("Reading single potentiometer channel");
|
||||
let pot_val = adc
|
||||
.read_single_channel(&mut cmd_buf, POTENTIOMETER_CHANNEL, &mut delay_us)
|
||||
.expect("Creating externally clocked MAX11619 ADC failed");
|
||||
rprintln!("Single channel read:");
|
||||
rprintln!("\tPotentiometer value: {}", pot_val);
|
||||
}
|
||||
ReadMode::Multiple => {
|
||||
let mut res_buf: [u16; 4] = [0; 4];
|
||||
adc.read_multiple_channels_0_to_n(
|
||||
&mut cmd_buf,
|
||||
&mut res_buf.iter_mut(),
|
||||
POTENTIOMETER_CHANNEL,
|
||||
&mut delay_us,
|
||||
)
|
||||
.expect("Multi-Channel read failed");
|
||||
print_res_buf(&res_buf);
|
||||
}
|
||||
ReadMode::MultipleNToHighest => {
|
||||
let mut res_buf: [u16; 2] = [0; 2];
|
||||
adc.read_multiple_channels_n_to_highest(
|
||||
&mut cmd_buf,
|
||||
&mut res_buf.iter_mut(),
|
||||
AN2_CHANNEL,
|
||||
&mut delay_us,
|
||||
)
|
||||
.expect("Multi-Channel read failed");
|
||||
rprintln!("Multi channel read from 2 to 3:");
|
||||
rprintln!("\tAN2 value: {}", res_buf[0]);
|
||||
rprintln!("\tAN3 / Potentiometer value: {}", res_buf[1]);
|
||||
}
|
||||
ReadMode::AverageN => {
|
||||
rprintln!("Scanning and averaging not possible for externally clocked mode");
|
||||
}
|
||||
}
|
||||
counter += 1;
|
||||
delay.delay_ms(500);
|
||||
}
|
||||
}
|
||||
|
||||
/// This function uses the EOC pin to determine whether the conversion finished
|
||||
fn spi_example_internally_clocked(spi: SpiBase<SPIB>, mut delay: Delay, eoc_pin: EocPin) -> ! {
|
||||
let mut adc = max11619_internally_clocked(
|
||||
spi,
|
||||
eoc_pin,
|
||||
VoltageRefMode::ExternalSingleEndedNoWakeupDelay,
|
||||
)
|
||||
.expect("Creating MAX116xx device failed");
|
||||
let mut counter = 0;
|
||||
loop {
|
||||
rprintln!("-- Measurement {} --", counter);
|
||||
|
||||
match READ_MODE {
|
||||
ReadMode::Single => {
|
||||
adc.request_single_channel(POTENTIOMETER_CHANNEL)
|
||||
.expect("Requesting single channel value failed");
|
||||
|
||||
let pot_val = nb::block!(adc.get_single_channel())
|
||||
.expect("Reading single channel value failed");
|
||||
rprintln!("\tPotentiometer value: {}", pot_val);
|
||||
}
|
||||
ReadMode::Multiple => {
|
||||
adc.request_multiple_channels_0_to_n(POTENTIOMETER_CHANNEL)
|
||||
.expect("Requesting single channel value failed");
|
||||
let mut res_buf: [u16; 4] = [0; 4];
|
||||
nb::block!(adc.get_multi_channel(&mut res_buf.iter_mut()))
|
||||
.expect("Requesting multiple channel values failed");
|
||||
print_res_buf(&res_buf);
|
||||
}
|
||||
ReadMode::MultipleNToHighest => {
|
||||
adc.request_multiple_channels_n_to_highest(AN2_CHANNEL)
|
||||
.expect("Requesting single channel value failed");
|
||||
let mut res_buf: [u16; 4] = [0; 4];
|
||||
nb::block!(adc.get_multi_channel(&mut res_buf.iter_mut()))
|
||||
.expect("Requesting multiple channel values failed");
|
||||
rprintln!("Multi channel read from 2 to 3:");
|
||||
rprintln!("\tAN2 value: {}", res_buf[0]);
|
||||
rprintln!("\tAN3 / Potentiometer value: {}", res_buf[1]);
|
||||
}
|
||||
ReadMode::AverageN => {
|
||||
adc.request_channel_n_repeatedly(POTENTIOMETER_CHANNEL)
|
||||
.expect("Reading channel multiple times failed");
|
||||
let mut res_buf: [u16; 16] = [0; 16];
|
||||
nb::block!(adc.get_multi_channel(&mut res_buf.iter_mut()))
|
||||
.expect("Requesting multiple channel values failed");
|
||||
rprintln!("Reading potentiometer 4 times");
|
||||
rprintln!("\tValue 0: {}", res_buf[0]);
|
||||
rprintln!("\tValue 1: {}", res_buf[1]);
|
||||
rprintln!("\tValue 2: {}", res_buf[2]);
|
||||
rprintln!("\tValue 3: {}", res_buf[3]);
|
||||
}
|
||||
}
|
||||
|
||||
counter += 1;
|
||||
delay.delay_ms(500);
|
||||
}
|
||||
}
|
||||
|
||||
fn print_res_buf(buf: &[u16; 4]) {
|
||||
rprintln!("Multi channel read from 0 to 3:");
|
||||
rprintln!("\tAN0 value: {}", buf[0]);
|
||||
rprintln!("\tAN1 value: {}", buf[1]);
|
||||
rprintln!("\tAN2 value: {}", buf[2]);
|
||||
rprintln!("\tAN3 / Potentiometer value: {}", buf[3]);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ use va108xx_hal::{
|
|||
gpio::{FilterClkSel, FilterType, InputFloating, InterruptEdge, InterruptLevel, Pin, PA11},
|
||||
pac,
|
||||
prelude::*,
|
||||
utility::IrqCfg,
|
||||
};
|
||||
|
||||
pub struct Button {
|
||||
|
@ -28,30 +29,28 @@ impl Button {
|
|||
}
|
||||
|
||||
/// Configures an IRQ on edge.
|
||||
///
|
||||
/// Please note that you still have to unpend the Cortex-M interrupt yourself
|
||||
pub fn edge_irq(
|
||||
mut self,
|
||||
edge_type: InterruptEdge,
|
||||
irq_cfg: IrqCfg,
|
||||
syscfg: Option<&mut pac::SYSCONFIG>,
|
||||
irqsel: &mut pac::IRQSEL,
|
||||
irq: pac::interrupt,
|
||||
irqsel: Option<&mut pac::IRQSEL>,
|
||||
) -> Self {
|
||||
self.button = self.button.interrupt_edge(edge_type, syscfg, irqsel, irq);
|
||||
self.button = self
|
||||
.button
|
||||
.interrupt_edge(edge_type, irq_cfg, syscfg, irqsel);
|
||||
self
|
||||
}
|
||||
|
||||
/// Configures an IRQ on level.
|
||||
///
|
||||
/// Please note that you still have to unpend the Cortex-M interrupt yourself
|
||||
pub fn level_irq(
|
||||
mut self,
|
||||
level: InterruptLevel,
|
||||
irq_cfg: IrqCfg,
|
||||
syscfg: Option<&mut pac::SYSCONFIG>,
|
||||
irqsel: &mut pac::IRQSEL,
|
||||
irq: pac::interrupt,
|
||||
irqsel: Option<&mut pac::IRQSEL>,
|
||||
) -> Self {
|
||||
self.button = self.button.interrupt_level(level, syscfg, irqsel, irq);
|
||||
self.button = self.button.interrupt_level(level, irq_cfg, syscfg, irqsel);
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
@ -4,24 +4,20 @@
|
|||
//!
|
||||
//! - [ADC example](https://egit.irs.uni-stuttgart.de/rust/vorago-reb1/src/branch/main/examples/max11619-adc.rs)
|
||||
use core::convert::Infallible;
|
||||
|
||||
use dummy_pin::DummyPin;
|
||||
use embedded_hal::{blocking::spi::Transfer, spi::FullDuplex};
|
||||
use max116xx_10bit::{
|
||||
Error, ExternallyClocked, InternallyClockedInternallyTimedSerialInterface, Max11619,
|
||||
Max116xx10Bit, RefMode, WithoutWakeupDelay,
|
||||
Error, ExternallyClocked, InternallyClockedInternallyTimedSerialInterface, Max116xx10Bit,
|
||||
Max116xx10BitEocExt, VoltageRefMode, WithWakeupDelay, WithoutWakeupDelay,
|
||||
};
|
||||
use va108xx_hal::gpio::{Floating, Input, Pin, PA14};
|
||||
|
||||
pub type Max11619ExternallyClocked<SPI> =
|
||||
Max116xx10Bit<SPI, DummyPin, Max11619, ExternallyClocked, WithoutWakeupDelay>;
|
||||
pub type Max11619InternallyClocked<SPI> = Max116xx10Bit<
|
||||
SPI,
|
||||
DummyPin,
|
||||
Max11619,
|
||||
InternallyClockedInternallyTimedSerialInterface,
|
||||
WithoutWakeupDelay,
|
||||
>;
|
||||
pub type Max11619ExternallyClockedNoWakeup<SPI> =
|
||||
Max116xx10Bit<SPI, DummyPin, ExternallyClocked, WithoutWakeupDelay>;
|
||||
pub type Max11619ExternallyClockedWithWakeup<SPI> =
|
||||
Max116xx10Bit<SPI, DummyPin, ExternallyClocked, WithWakeupDelay>;
|
||||
pub type Max11619InternallyClocked<SPI, EOC> =
|
||||
Max116xx10BitEocExt<SPI, DummyPin, EOC, InternallyClockedInternallyTimedSerialInterface>;
|
||||
pub type EocPin = Pin<PA14, Input<Floating>>;
|
||||
|
||||
pub const AN0_CHANNEL: u8 = 0;
|
||||
|
@ -29,37 +25,42 @@ pub const AN1_CHANNEL: u8 = 1;
|
|||
pub const AN2_CHANNEL: u8 = 2;
|
||||
pub const POTENTIOMETER_CHANNEL: u8 = 3;
|
||||
|
||||
pub fn max11619_externally_clocked<SpiE, SPI>(
|
||||
pub fn max11619_externally_clocked_no_wakeup<SpiE, SPI>(
|
||||
spi: SPI,
|
||||
) -> Result<Max11619ExternallyClocked<SPI>, Error<SpiE, Infallible>>
|
||||
) -> Result<Max11619ExternallyClockedNoWakeup<SPI>, Error<SpiE, Infallible>>
|
||||
where
|
||||
SPI: Transfer<u8, Error = SpiE> + FullDuplex<u8, Error = SpiE>,
|
||||
{
|
||||
let adc: Max116xx10Bit<SPI, DummyPin, Max11619, ExternallyClocked, WithoutWakeupDelay> =
|
||||
Max116xx10Bit::new(
|
||||
spi,
|
||||
DummyPin::new_low(),
|
||||
RefMode::ExternalSingleEndedNoWakeupDelay,
|
||||
)?;
|
||||
let mut adc = Max116xx10Bit::max11619(spi, DummyPin::new_low())?;
|
||||
adc.reset(false)?;
|
||||
adc.setup()?;
|
||||
Ok(adc)
|
||||
}
|
||||
|
||||
pub fn max11619_externally_clocked_with_wakeup<SpiE, SPI>(
|
||||
spi: SPI,
|
||||
) -> Result<Max11619ExternallyClockedWithWakeup<SPI>, Error<SpiE, Infallible>>
|
||||
where
|
||||
SPI: Transfer<u8, Error = SpiE> + FullDuplex<u8, Error = SpiE>,
|
||||
{
|
||||
let mut adc = Max116xx10Bit::max11619(spi, DummyPin::new_low())?
|
||||
.into_ext_clkd_with_int_ref_wakeup_delay();
|
||||
adc.reset(false)?;
|
||||
adc.setup()?;
|
||||
Ok(adc)
|
||||
}
|
||||
|
||||
pub fn max11619_internally_clocked<SpiE, SPI>(
|
||||
spi: SPI,
|
||||
) -> Result<Max11619InternallyClocked<SPI>, Error<SpiE, Infallible>>
|
||||
eoc: EocPin,
|
||||
v_ref: VoltageRefMode,
|
||||
) -> Result<Max11619InternallyClocked<SPI, EocPin>, Error<SpiE, Infallible>>
|
||||
where
|
||||
SPI: Transfer<u8, Error = SpiE> + FullDuplex<u8, Error = SpiE>,
|
||||
{
|
||||
let adc: Max116xx10Bit<
|
||||
SPI,
|
||||
DummyPin,
|
||||
Max11619,
|
||||
InternallyClockedInternallyTimedSerialInterface,
|
||||
WithoutWakeupDelay,
|
||||
> = Max116xx10Bit::new(
|
||||
spi,
|
||||
DummyPin::new_low(),
|
||||
RefMode::ExternalSingleEndedNoWakeupDelay,
|
||||
)?;
|
||||
let mut adc = Max116xx10Bit::max11619(spi, DummyPin::new_low())?
|
||||
.into_int_clkd_int_timed_through_ser_if_without_wakeup(v_ref, eoc)?;
|
||||
adc.reset(false)?;
|
||||
adc.setup()?;
|
||||
Ok(adc)
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ pub struct Adt75TempSensor {
|
|||
current_reg: RegAddresses,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug, Copy, Clone)]
|
||||
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
|
||||
pub enum RegAddresses {
|
||||
Temperature = 0x00,
|
||||
Configuration = 0x01,
|
||||
|
@ -67,15 +67,14 @@ impl Adt75TempSensor {
|
|||
let mut reply: [u8; 2] = [0; 2];
|
||||
self.sensor_if.read(ADT75_I2C_ADDR, &mut reply)?;
|
||||
let adc_code = (((reply[0] as u16) << 8) | reply[1] as u16) >> 4;
|
||||
let temp_celcius: f32;
|
||||
if ((adc_code >> 11) & 0x01) == 0 {
|
||||
let temp_celcius: f32 = if ((adc_code >> 11) & 0x01) == 0 {
|
||||
// Sign bit not set, positiv value
|
||||
// Divide ADC code by 16 according to datasheet
|
||||
temp_celcius = adc_code as f32 / 16.0;
|
||||
adc_code as f32 / 16.0
|
||||
} else {
|
||||
// Calculation for negative values, assuming all 12 bits are used
|
||||
temp_celcius = (adc_code - 4096) as f32 / 16.0;
|
||||
}
|
||||
(adc_code - 4096) as f32 / 16.0
|
||||
};
|
||||
Ok(temp_celcius)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue