Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add internal DAC outputs to available opamp inputs. #123

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/opamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ pub enum NonInvertingGain {
Gain64 = 5,
}

/// Internal output of DAC 3 channel 1.
pub struct Dac3Out1;

/// Internal output of DAC 3 channel 2.
pub struct Dac3Out2;

/// Internal output of DAC 4 channel 1.
pub struct Dac4Out1;

/// Internal output of DAC 4 channel 2.
pub struct Dac4Out2;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the channel types from the dac module if we want to use those. I believe that would force the user to pass in the DAC they actually initialized, reducing the risk of error.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea but I don't think taking ownership of the DAC channel works in this case, for two reasons:

  1. The same DAC output can be used as input for multiple opamps (dac3ch1 can go to opamps 1 and 6 simultaneously, verified that this works).
  2. The user wouldn't be able to set the DAC's value (or other configuration) after setting up the opamp. There's some cases where that's ok (if using DMA) but the easiest setup would become impossible.

Copy link
Contributor

@usbalbin usbalbin Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing by reference would probably be enough. As long as the OPAMP does not keep the reference, the dac can still be modified and similar which I believe would solve both 1 and 2?

Copy link
Contributor

@usbalbin usbalbin Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something similar is done for the comparator.

Usage looks like this

macro_rules! opamps {
{
$(
Expand Down Expand Up @@ -557,6 +569,7 @@ opamps! {
crate::gpio::gpioa::PA1<crate::gpio::Analog>: vinp0,
crate::gpio::gpioa::PA3<crate::gpio::Analog>: vinp1,
crate::gpio::gpioa::PA7<crate::gpio::Analog>: vinp2,
crate::opamp::Dac3Out1: dac3_ch1,
},
output: crate::gpio::gpioa::PA2<crate::gpio::Analog>,
},
Expand Down Expand Up @@ -584,6 +597,7 @@ opamps! {
crate::gpio::gpiob::PB0<crate::gpio::Analog>: vinp0,
crate::gpio::gpiob::PB13<crate::gpio::Analog>: vinp1,
crate::gpio::gpioa::PA1<crate::gpio::Analog>: vinp2,
crate::opamp::Dac3Out2: dac3_ch2,
},
output: crate::gpio::gpiob::PB1<crate::gpio::Analog>,
},
Expand All @@ -606,6 +620,7 @@ opamps! {
crate::gpio::gpioa::PA1<crate::gpio::Analog>: vinp0,
crate::gpio::gpioa::PA3<crate::gpio::Analog>: vinp1,
crate::gpio::gpioa::PA7<crate::gpio::Analog>: vinp2,
crate::opamp::Dac3Out1: dac3_ch1,
},
output: crate::gpio::gpioa::PA2<crate::gpio::Analog>,
},
Expand Down Expand Up @@ -633,6 +648,7 @@ opamps! {
crate::gpio::gpiob::PB0<crate::gpio::Analog>: vinp0,
crate::gpio::gpiob::PB13<crate::gpio::Analog>: vinp1,
crate::gpio::gpioa::PA1<crate::gpio::Analog>: vinp2,
crate::opamp::Dac3Out2: dac3_ch2,
},
output: crate::gpio::gpiob::PB1<crate::gpio::Analog>,
},
Expand All @@ -646,6 +662,7 @@ opamps! {
crate::gpio::gpiob::PB13<crate::gpio::Analog>: vinp0,
crate::gpio::gpiod::PD11<crate::gpio::Analog>: vinp1,
crate::gpio::gpiob::PB11<crate::gpio::Analog>: vinp2,
crate::opamp::Dac4Out1: dac4_ch1,
},
output: crate::gpio::gpiob::PB12<crate::gpio::Analog>,
},
Expand All @@ -659,6 +676,7 @@ opamps! {
crate::gpio::gpiob::PB14<crate::gpio::Analog>: vinp0,
crate::gpio::gpiod::PD12<crate::gpio::Analog>: vinp1,
crate::gpio::gpioc::PC3<crate::gpio::Analog>: vinp2,
crate::opamp::Dac4Out2: dac4_ch2,
},
output: crate::gpio::gpioa::PA8<crate::gpio::Analog>,
},
Expand All @@ -672,6 +690,7 @@ opamps! {
crate::gpio::gpiob::PB12<crate::gpio::Analog>: vinp0,
crate::gpio::gpiod::PD9<crate::gpio::Analog>: vinp1,
crate::gpio::gpiob::PB13<crate::gpio::Analog>: vinp2,
crate::opamp::Dac3Out1: dac3_ch1,
},
output: crate::gpio::gpiob::PB11<crate::gpio::Analog>,
},
Expand Down