Compare commits
11 Commits
5e82e8a771
...
0c5a5efea0
| Author | SHA1 | Date | |
|---|---|---|---|
| 0c5a5efea0 | |||
| a901e4fcac | |||
| 3025ec70ab | |||
| 403407547d | |||
| 850bd08eae | |||
| 09c5dcd171 | |||
| 2f71f2b9a6 | |||
| ed9da82daf | |||
| 46aec1f62f | |||
| a2a824cfcf | |||
| a912dd3971 |
5
.github/workflows/ci.yml
vendored
5
.github/workflows/ci.yml
vendored
@@ -18,12 +18,11 @@ jobs:
|
||||
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
|
||||
@@ -57,7 +56,7 @@ jobs:
|
||||
with:
|
||||
use-cross: true
|
||||
command: clippy
|
||||
args: --target thumbv6m-none-eabi -- -D warnings
|
||||
args: -- -D warnings
|
||||
|
||||
ci:
|
||||
if: ${{ success() }}
|
||||
|
||||
@@ -8,6 +8,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [unreleased]
|
||||
|
||||
## [v0.3.1]
|
||||
|
||||
- Updated ADC code and dependency
|
||||
|
||||
## [v0.3.0]
|
||||
|
||||
- Completed baseline features to support all sensors on the REB1 sevice
|
||||
- Relicensed as Apache-2.0 and moved to https://egit.irs.uni-stuttgart.de/rust/vorago-reb1
|
||||
|
||||
## [v0.2.3]
|
||||
|
||||
- Added basic accelerometer example. Board in not populated so it is not complete, but
|
||||
|
||||
21
Cargo.toml
21
Cargo.toml
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "vorago-reb1"
|
||||
version = "0.2.2"
|
||||
version = "0.3.1"
|
||||
authors = ["Robin Mueller <robin.mueller.m@gmail.com>"]
|
||||
edition = "2021"
|
||||
description = "Board Support Crate for the Vorago REB1 development board"
|
||||
@@ -15,13 +15,10 @@ cortex-m = "0.7.3"
|
||||
cortex-m-rt = "0.7.0"
|
||||
embedded-hal = "0.2.6"
|
||||
dummy-pin = "0.1.1"
|
||||
|
||||
[dependencies.max116xx-10bit]
|
||||
path = "../max116xx-10bit"
|
||||
max116xx-10bit = "0.2.1"
|
||||
|
||||
[dependencies.va108xx-hal]
|
||||
path = "../va108xx-hal"
|
||||
# version = "0.4.1"
|
||||
version = "0.4.2"
|
||||
features = ["rt"]
|
||||
|
||||
[features]
|
||||
@@ -33,15 +30,3 @@ panic-rtt-target = { version = "0.1", features = ["cortex-m"] }
|
||||
rtt-target = { version = "0.3", features = ["cortex-m"] }
|
||||
panic-halt = "0.2"
|
||||
nb = "1.0.0"
|
||||
|
||||
[[example]]
|
||||
name = "blinky-button-rtic"
|
||||
required-features = ["rt"]
|
||||
|
||||
[[example]]
|
||||
name = "adxl343-accelerometer"
|
||||
required-features = ["rt"]
|
||||
|
||||
[[example]]
|
||||
name = "max11619-adc"
|
||||
required-features = ["rt", "nb"]
|
||||
|
||||
201
LICENSE
201
LICENSE
@@ -1,201 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
25
LICENSE-MIT
25
LICENSE-MIT
@@ -1,25 +0,0 @@
|
||||
Copyright (c) 2021 Robin Mueller
|
||||
|
||||
Permission is hereby granted, free of charge, to any
|
||||
person obtaining a copy of this software and associated
|
||||
documentation files (the "Software"), to deal in the
|
||||
Software without restriction, including without
|
||||
limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software
|
||||
is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice
|
||||
shall be included in all copies or substantial portions
|
||||
of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
||||
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
3
NOTICE
Normal file
3
NOTICE
Normal file
@@ -0,0 +1,3 @@
|
||||
Rust Board Support Package (HAL) crate for the Vorago REB1 development board
|
||||
|
||||
This software contains code developed at the University of Stuttgart.
|
||||
11
automation/Dockerfile
Normal file
11
automation/Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
||||
# Run the following commands from root directory to build and run locally
|
||||
# docker build -f automation/Dockerfile -t <NAME> .
|
||||
# docker run -it <NAME>
|
||||
FROM rust:latest
|
||||
RUN apt-get update
|
||||
RUN apt-get --yes upgrade
|
||||
# tzdata is a dependency, won't install otherwise
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
RUN rustup target add thumbv6m-none-eabi && \
|
||||
rustup component add rustfmt clippy
|
||||
50
automation/Jenkinsfile
vendored
Normal file
50
automation/Jenkinsfile
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
pipeline {
|
||||
agent any
|
||||
|
||||
stages {
|
||||
stage('Clippy') {
|
||||
agent {
|
||||
dockerfile {
|
||||
dir 'automation'
|
||||
reuseNode true
|
||||
}
|
||||
}
|
||||
steps {
|
||||
sh 'cargo clippy'
|
||||
}
|
||||
}
|
||||
stage('Rustfmt') {
|
||||
agent {
|
||||
dockerfile {
|
||||
dir 'automation'
|
||||
reuseNode true
|
||||
}
|
||||
}
|
||||
steps {
|
||||
sh 'cargo fmt'
|
||||
}
|
||||
}
|
||||
stage('Check') {
|
||||
agent {
|
||||
dockerfile {
|
||||
dir 'automation'
|
||||
reuseNode true
|
||||
}
|
||||
}
|
||||
steps {
|
||||
sh 'cargo check --target thumbv6m-none-eabi'
|
||||
}
|
||||
}
|
||||
stage('Check Examples') {
|
||||
agent {
|
||||
dockerfile {
|
||||
dir 'automation'
|
||||
reuseNode true
|
||||
}
|
||||
}
|
||||
steps {
|
||||
sh 'cargo check --target thumbv6m-none-eabi --examples'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,7 +79,7 @@ fn main() -> ! {
|
||||
|
||||
loop {
|
||||
delay.delay_ms(500);
|
||||
todo!("Not implemented for now, is not populated on the board..");
|
||||
unimplemented!("Not implemented for now, is not populated on the board..");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,30 +1,31 @@
|
||||
//! MAX11619 ADC example applikcation
|
||||
#![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},
|
||||
utility::*,
|
||||
utility::{port_mux, PortSel, Funsel}
|
||||
};
|
||||
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)]
|
||||
@@ -32,10 +33,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::PortB19to17;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
@@ -56,18 +65,19 @@ fn main() -> ! {
|
||||
}
|
||||
|
||||
let pinsa = PinsA::new(&mut dp.SYSCONFIG, None, dp.PORTA);
|
||||
let mut spi_cfg = SpiConfig::default();
|
||||
spi_cfg.scrdv = 0x07;
|
||||
let spi_cfg = SpiConfig::default();
|
||||
let (sck, mosi, miso) = (
|
||||
pinsa.pa20.into_funsel_2(),
|
||||
pinsa.pa19.into_funsel_2(),
|
||||
pinsa.pa18.into_funsel_2(),
|
||||
);
|
||||
|
||||
port_mux(&mut dp.IOCONFIG, PortSel::PortB, 16, Funsel::Funsel1).ok();
|
||||
// port_mux(&mut dp.IOCONFIG, PortSel::PortB, 17, Funsel::Funsel1).ok();
|
||||
port_mux(&mut dp.IOCONFIG, PortSel::PortB, 18, Funsel::Funsel1).ok();
|
||||
port_mux(&mut dp.IOCONFIG, PortSel::PortB, 19, Funsel::Funsel1).ok();
|
||||
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
|
||||
@@ -95,6 +105,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,9 +117,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 {
|
||||
@@ -114,50 +136,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;
|
||||
@@ -165,22 +173,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]);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user