Compare commits
1 Commits
master
...
dependency
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
271fb8f6c4 |
30
Cargo.toml
30
Cargo.toml
@@ -16,8 +16,8 @@ members = [
|
||||
]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.4.6"
|
||||
edition = "2021"
|
||||
version = "0.5.0"
|
||||
edition = "2024"
|
||||
repository = "https://git.bfpower.io/BFPOWER/physical"
|
||||
readme = "README.md"
|
||||
license = "MIT"
|
||||
@@ -30,14 +30,14 @@ default-features = false
|
||||
[workspace.dependencies.libm]
|
||||
version = "0.2.*"
|
||||
[workspace.dependencies.float-cmp]
|
||||
version = "0.9.*"
|
||||
version = "0.10.*"
|
||||
# Logging
|
||||
[workspace.dependencies.tracing]
|
||||
version = "0.1.*"
|
||||
[workspace.dependencies.defmt]
|
||||
version = "0.3.*"
|
||||
version = "1.0.*"
|
||||
[workspace.dependencies.defmt-rtt]
|
||||
version = "0.4.*"
|
||||
version = "1.1.*"
|
||||
# Embedded-HAL
|
||||
[workspace.dependencies.embedded-hal]
|
||||
version = "1.0.*"
|
||||
@@ -57,32 +57,34 @@ version = "0.7.*"
|
||||
[workspace.dependencies.cortex-m-rt]
|
||||
version = "0.7.*"
|
||||
[workspace.dependencies.panic-probe]
|
||||
version = "0.3.*"
|
||||
version = "1.0.*"
|
||||
features = ["print-defmt"]
|
||||
# Embassy
|
||||
[workspace.dependencies.embassy-futures]
|
||||
version = "0.1.*"
|
||||
[workspace.dependencies.embassy-time]
|
||||
version = "0.3.*"
|
||||
version = "0.5.*"
|
||||
features = ["defmt", "defmt-timestamp-uptime"]
|
||||
[workspace.dependencies.embassy-sync]
|
||||
version = "0.6.*"
|
||||
version = "0.7.*"
|
||||
features = ["defmt"]
|
||||
[workspace.dependencies.embassy-embedded-hal]
|
||||
version = "0.1.*"
|
||||
[workspace.dependencies.embassy-executor]
|
||||
version = "0.5.*"
|
||||
features = ["defmt", "arch-cortex-m", "integrated-timers", "executor-interrupt", "executor-thread"]
|
||||
[workspace.dependencies.embassy-executor]
|
||||
version = "0.9.*"
|
||||
features = ["defmt", "arch-cortex-m", "executor-interrupt", "executor-thread"]
|
||||
[workspace.dependencies.embassy-usb]
|
||||
version = "0.2.*"
|
||||
version = "0.5.*"
|
||||
features = ["defmt"]
|
||||
[workspace.dependencies.embassy-stm32]
|
||||
version = "0.1.*"
|
||||
version = "0.5.*"
|
||||
features = ["defmt", "unstable-pac"]
|
||||
[workspace.dependencies.embassy-nrf]
|
||||
version = "0.1.*"
|
||||
version = "0.9.*"
|
||||
features = ["defmt"]
|
||||
# Meta
|
||||
[workspace.dependencies.cfg-if]
|
||||
version = "1.0.*"
|
||||
[workspace.dependencies.derive_more]
|
||||
version = "0.99.*"
|
||||
[workspace.dependencies.syn]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
drate, mux, opcodes, status, AdControl, Ads1256, BlockingDelay, CalibrationCommand, Conversion,
|
||||
DataRate, Gain, Multiplexer, Status,
|
||||
DataRate, Multiplexer, Status,
|
||||
};
|
||||
use embedded_hal::digital::OutputPin;
|
||||
use embedded_hal::spi;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
pub mod input {
|
||||
use crate::{Buffer, Config, DataRate, Gain, Multiplexer, MuxInput};
|
||||
use crate::{Multiplexer, MuxInput};
|
||||
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
|
||||
|
||||
@@ -1,27 +1,25 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use cortex_m::prelude::{_embedded_hal_blocking_delay_DelayMs, _embedded_hal_blocking_delay_DelayUs};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
use {embassy_executor as executor, embassy_stm32 as stm32};
|
||||
|
||||
use ads1256::{
|
||||
AdControl, Ads1256, AutoCal, BitOrder, Buffer, ClockOut, Config, DState, DataRate, DigitalIo,
|
||||
DigitalIoDirection, DigitalIoState, DioDirection, Gain, Multiplexer, MuxInput, OutputPin, Sdcs,
|
||||
SpiBus, Status, Wait, BlockingDelay
|
||||
AdControl, Ads1256, AutoCal, BitOrder, Buffer, ClockOut, Config,
|
||||
DataRate, DigitalIo, DigitalIoDirection, DigitalIoState, Gain, Multiplexer,
|
||||
MuxInput, OutputPin, Sdcs, SpiBus, Status, Wait,
|
||||
};
|
||||
use embassy_time::{Delay, Timer};
|
||||
use embassy_time::Delay;
|
||||
use executor::Spawner;
|
||||
use physical::quantity::Quantity;
|
||||
use stm32::dma::NoDma;
|
||||
use stm32::exti::ExtiInput;
|
||||
use stm32::gpio::{Input, Level, Output, Pull, Speed};
|
||||
use stm32::gpio::{Level, Output, Pull, Speed};
|
||||
use stm32::spi::Spi;
|
||||
use stm32::time::Hertz;
|
||||
use stm32::{pac, spi};
|
||||
|
||||
use defmt::{debug, error, info, trace, unwrap};
|
||||
use defmt::info;
|
||||
|
||||
const AUTOCAL_CONF: Config = Config {
|
||||
status: Status::setting(Buffer::Enabled, AutoCal::Enabled, BitOrder::MostSigFirst),
|
||||
@@ -33,15 +31,17 @@ const AUTOCAL_CONF: Config = Config {
|
||||
|
||||
const ADS1256_DELAY: ads1256::DefaultDelay<Delay> = ads1256::DefaultDelay::new(Delay);
|
||||
|
||||
stm32::bind_interrupts!(struct Irqs {
|
||||
EXTI3 => stm32::exti::InterruptHandler<stm32::interrupt::typelevel::EXTI3>;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
unsafe {
|
||||
pac::FLASH.acr().modify(|v| {
|
||||
v.set_prften(true);
|
||||
v.set_icen(true);
|
||||
v.set_dcen(true);
|
||||
});
|
||||
}
|
||||
pac::FLASH.acr().modify(|v| {
|
||||
v.set_prften(true);
|
||||
v.set_icen(true);
|
||||
v.set_dcen(true);
|
||||
});
|
||||
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
|
||||
@@ -50,18 +50,10 @@ async fn main(spawner: Spawner) {
|
||||
spi_conf.bit_order = spi::BitOrder::MsbFirst;
|
||||
spi_conf.frequency = Hertz(ads1256::defaults::SPI_CLK_HZ);
|
||||
|
||||
let ads1256_data_ready = ExtiInput::new(Input::new(p.PA3, Pull::Up), p.EXTI3);
|
||||
let ads1256_data_ready = ExtiInput::new(p.PA3, p.EXTI3, Pull::Up, Irqs);
|
||||
let select_ads1256 = Output::new(p.PA1, Level::High, Speed::VeryHigh);
|
||||
|
||||
let mut spi = Spi::new(
|
||||
p.SPI1,
|
||||
p.PA5,
|
||||
p.PA7,
|
||||
p.PA6,
|
||||
NoDma,
|
||||
NoDma,
|
||||
spi_conf,
|
||||
);
|
||||
let mut spi = Spi::new_blocking(p.SPI1, p.PA5, p.PA7, p.PA6, spi_conf);
|
||||
|
||||
let mut ads_1256 = Ads1256::new(ADS1256_DELAY, select_ads1256, ads1256_data_ready);
|
||||
// single_conversion(&mut spi, &mut ads_1256).await;
|
||||
@@ -78,7 +70,11 @@ async fn single_conversion<DelayerT: ads1256::BlockingDelay, SST: OutputPin, Drd
|
||||
ads_1256.delayer.t11_1_delay();
|
||||
ads_1256.conversion_init(spi).unwrap();
|
||||
let data = ads_1256.cmd_read_data(spi).await.unwrap();
|
||||
info!("data: {}, volts: {}", data, data.to_voltage(AUTOCAL_CONF.ad_control.gain()).fmt(Some(5)));
|
||||
info!(
|
||||
"data: {}, volts: {}",
|
||||
data,
|
||||
data.to_voltage(AUTOCAL_CONF.ad_control.gain()).fmt(Some(5))
|
||||
);
|
||||
}
|
||||
|
||||
async fn read_continuous<DelayerT: ads1256::BlockingDelay, SST: OutputPin, DrdyT: Wait>(
|
||||
@@ -90,7 +86,11 @@ async fn read_continuous<DelayerT: ads1256::BlockingDelay, SST: OutputPin, DrdyT
|
||||
ads_1256.start_rdatac(spi).await.unwrap();
|
||||
loop {
|
||||
let data = ads_1256.read_data(spi).await.unwrap();
|
||||
info!("data: {}, volts: {}", data, data.to_voltage(AUTOCAL_CONF.ad_control.gain()).fmt(Some(5)));
|
||||
info!(
|
||||
"data: {}, volts: {}",
|
||||
data,
|
||||
data.to_voltage(AUTOCAL_CONF.ad_control.gain()).fmt(Some(5))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,19 +113,30 @@ async fn cycle_multiplexer<DelayerT: ads1256::BlockingDelay, SST: OutputPin, Drd
|
||||
.autocal_convert(spi, INPUT_1, None, Some(ad_control.with_gain(Gain::X4)), None, false)
|
||||
.await
|
||||
.unwrap();
|
||||
info!("Input 1: data: {}, volts: {}", data, data.to_voltage(ad_control.gain()).fmt(Some(5)));
|
||||
info!(
|
||||
"Input 1: data: {}, volts: {}",
|
||||
data,
|
||||
data.to_voltage(ad_control.gain()).fmt(Some(5))
|
||||
);
|
||||
let ad_control = ad_control.with_gain(Gain::X8);
|
||||
let data = ads_1256
|
||||
.autocal_convert(spi, INPUT_2, None, Some(ad_control.with_gain(Gain::X8)), None, false)
|
||||
.await
|
||||
.unwrap();
|
||||
info!("Input 2: data: {}, volts: {}", data, data.to_voltage(ad_control.gain()).fmt(Some(5)));
|
||||
info!(
|
||||
"Input 2: data: {}, volts: {}",
|
||||
data,
|
||||
data.to_voltage(ad_control.gain()).fmt(Some(5))
|
||||
);
|
||||
let ad_control = ad_control.with_gain(Gain::X16);
|
||||
let data = ads_1256
|
||||
.autocal_convert(spi, INPUT_3, None, Some(ad_control.with_gain(Gain::X16)), None, false)
|
||||
.await
|
||||
.unwrap();
|
||||
info!("Input 3: data: {}, volts: {}", data, data.to_voltage(ad_control.gain()).fmt(Some(5)));
|
||||
info!(
|
||||
"Input 3: data: {}, volts: {}",
|
||||
data,
|
||||
data.to_voltage(ad_control.gain()).fmt(Some(5))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use cortex_m::prelude::_embedded_hal_blocking_delay_DelayUs;
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
use embassy_stm32::bind_interrupts;
|
||||
use {embassy_executor as executor, embassy_stm32 as stm32};
|
||||
|
||||
use ads1256::{
|
||||
@@ -13,26 +13,28 @@ use ads1256::{
|
||||
};
|
||||
use embassy_time::Delay;
|
||||
use executor::Spawner;
|
||||
use stm32::dma::NoDma;
|
||||
|
||||
use stm32::exti::ExtiInput;
|
||||
use stm32::gpio::{Input, Level, Output, Pull, Speed};
|
||||
use stm32::gpio::{Level, Output, Pull, Speed};
|
||||
use stm32::spi::Spi;
|
||||
use stm32::time::Hertz;
|
||||
use stm32::{pac, spi};
|
||||
|
||||
use defmt::{debug, error, info, trace, unwrap};
|
||||
use defmt::info;
|
||||
|
||||
const ADS1256_DELAY: ads1256::DefaultDelay<Delay> = ads1256::DefaultDelay::new(Delay);
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
EXTI3 => stm32::exti::InterruptHandler<stm32::interrupt::typelevel::EXTI3>;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(spawner: Spawner) {
|
||||
unsafe {
|
||||
pac::FLASH.acr().modify(|v| {
|
||||
v.set_prften(true);
|
||||
v.set_icen(true);
|
||||
v.set_dcen(true);
|
||||
});
|
||||
}
|
||||
pac::FLASH.acr().modify(|v| {
|
||||
v.set_prften(true);
|
||||
v.set_icen(true);
|
||||
v.set_dcen(true);
|
||||
});
|
||||
|
||||
let p = embassy_stm32::init(Default::default());
|
||||
|
||||
@@ -41,18 +43,10 @@ async fn main(spawner: Spawner) {
|
||||
spi_conf.bit_order = spi::BitOrder::MsbFirst;
|
||||
spi_conf.frequency = Hertz(ads1256::defaults::SPI_CLK_HZ);
|
||||
|
||||
let ads1256_data_ready = ExtiInput::new(Input::new(p.PA3, Pull::Up), p.EXTI3);
|
||||
let ads1256_data_ready = ExtiInput::new(p.PA3, p.EXTI3, Pull::Up, Irqs);
|
||||
let select_ads1256 = Output::new(p.PA1, Level::High, Speed::VeryHigh);
|
||||
|
||||
let mut spi = Spi::new(
|
||||
p.SPI1,
|
||||
p.PA5,
|
||||
p.PA7,
|
||||
p.PA6,
|
||||
NoDma,
|
||||
NoDma,
|
||||
spi_conf,
|
||||
);
|
||||
let mut spi = Spi::new_blocking(p.SPI1, p.PA5, p.PA7, p.PA6, spi_conf);
|
||||
|
||||
let mut ads_1256 = Ads1256::new(ADS1256_DELAY, select_ads1256, ads1256_data_ready);
|
||||
// status(&mut spi, &mut ads_1256);
|
||||
@@ -60,7 +54,7 @@ async fn main(spawner: Spawner) {
|
||||
// ad_control(&mut spi, &mut ads_1256);
|
||||
// data_rate(&mut spi, &mut ads_1256);
|
||||
// gpio(&mut spi, &mut ads_1256);
|
||||
config(&mut spi, &mut ads_1256);
|
||||
config(&mut spi, &mut ads_1256);
|
||||
}
|
||||
|
||||
fn status<DelayerT: ads1256::BlockingDelay, SST: OutputPin, DrdyT: Wait>(
|
||||
|
||||
@@ -15,6 +15,8 @@ stm32 = ["embassy-stm32", "physical/stm32"]
|
||||
|
||||
[dependencies.physical]
|
||||
path = ".."
|
||||
[dependencies.cfg-if]
|
||||
workspace = true
|
||||
[dependencies.embedded-hal]
|
||||
workspace = true
|
||||
[dependencies.embedded-hal-async]
|
||||
|
||||
@@ -3,28 +3,30 @@
|
||||
|
||||
use crate::comms;
|
||||
use embassy_stm32::peripherals::USB_OTG_FS;
|
||||
use embassy_stm32::usb_otg::{Driver, Endpoint, In, Out};
|
||||
use embassy_usb::driver::{EndpointIn, EndpointOut};
|
||||
use embassy_stm32::usb::Driver as StmUsbDriver;
|
||||
use embassy_usb::driver::{Driver as UsbDriverTrait, EndpointIn, EndpointOut};
|
||||
use embassy_usb::UsbDevice;
|
||||
|
||||
pub type TypedUSB = UsbDevice<'static, Driver<'static, USB_OTG_FS>>;
|
||||
pub type TypedInterIn = Endpoint<'static, USB_OTG_FS, In>;
|
||||
pub type TypedInterOut = Endpoint<'static, USB_OTG_FS, Out>;
|
||||
type UsbDriver = StmUsbDriver<'static, USB_OTG_FS>;
|
||||
type InterIn = <UsbDriver as UsbDriverTrait<'static>>::EndpointIn;
|
||||
type InterOut = <UsbDriver as UsbDriverTrait<'static>>::EndpointOut;
|
||||
|
||||
pub type TypedUSB = UsbDevice<'static, UsbDriver>;
|
||||
|
||||
pub struct UsbIO {
|
||||
/// Send to master
|
||||
pub interrupt_in: TypedInterIn,
|
||||
pub interrupt_in: InterIn,
|
||||
/// Recieve from master
|
||||
pub interrupt_out: TypedInterOut,
|
||||
pub interrupt_out: InterOut,
|
||||
}
|
||||
|
||||
impl comms::Sender for TypedInterIn {
|
||||
impl<T: EndpointIn> comms::Sender for T {
|
||||
async fn send(&mut self, msg: &[u8]) -> Result<(), comms::Reset> {
|
||||
self.write(msg).await.map_err(|_| comms::Reset)
|
||||
}
|
||||
}
|
||||
|
||||
impl comms::Receiver for TypedInterOut {
|
||||
impl<T: EndpointOut> comms::Receiver for T {
|
||||
#[cfg(feature = "single-packet-msgs")]
|
||||
async fn receive(&mut self, buffer: &mut [u8]) -> Result<(), comms::Reset> {
|
||||
// This is OK when all our messages are smaller than a single packet.
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# Before upgrading check that everything is available on all tier1 targets here:
|
||||
# https://rust-lang.github.io/rustup-components-history
|
||||
[toolchain]
|
||||
channel = "1.82"
|
||||
components = [ "rust-src", "rustfmt", "llvm-tools" ]
|
||||
channel = "1.93.1"
|
||||
components = [ "rust-src", "rustfmt" ]
|
||||
targets = [
|
||||
"thumbv7em-none-eabi",
|
||||
"thumbv7m-none-eabi",
|
||||
|
||||
@@ -3,6 +3,6 @@ format_strings = true
|
||||
wrap_comments = true
|
||||
match_block_trailing_comma = true
|
||||
enum_discrim_align_threshold = 25
|
||||
fn_call_width = 100
|
||||
fn_call_width = 110
|
||||
single_line_if_else_max_width = 110
|
||||
comment_width = 120
|
||||
single_line_if_else_max_width = 100
|
||||
Reference in New Issue
Block a user