@@ -174,6 +174,8 @@ macro_rules! opamps {
174
174
175
175
/// States for opampX.
176
176
pub mod $opamp {
177
+ use core:: { borrow:: Borrow , marker:: PhantomData } ;
178
+
177
179
#[ allow( unused_imports) ]
178
180
use crate :: gpio:: gpioa:: * ;
179
181
@@ -219,18 +221,18 @@ macro_rules! opamps {
219
221
220
222
/// State type for opamp running in programmable-gain mode.
221
223
pub struct Pga <NonInverting , MODE > {
222
- non_inverting: NonInverting ,
224
+ non_inverting: PhantomData < NonInverting > ,
223
225
config: MODE ,
224
226
output: Option <$output>,
225
227
}
226
228
227
229
/// Trait for opamps that can be run in programmable gain mode.
228
- pub trait IntoPga <IntoNonInverting , MODE , IntoOutput , NonInverting >
230
+ pub trait IntoPga <MODE , IntoOutput , NonInverting >
229
231
where
230
232
IntoOutput : Into <$output>,
231
233
{
232
234
/// Configures the opamp for programmable gain operation.
233
- fn pga( self , non_inverting: IntoNonInverting , config: MODE , output: Option <IntoOutput >)
235
+ fn pga< B : Borrow < NonInverting >> ( self , non_inverting: B , config: MODE , output: Option <IntoOutput >)
234
236
-> Pga <NonInverting , MODE >;
235
237
}
236
238
@@ -295,9 +297,9 @@ macro_rules! opamps {
295
297
impl <NonInverting , MODE > Pga <NonInverting , MODE > {
296
298
297
299
/// Disables the opamp and returns the resources it held.
298
- pub fn disable( self ) -> ( Disabled , NonInverting , MODE , Option <$output>) {
300
+ pub fn disable( self ) -> ( Disabled , MODE , Option <$output>) {
299
301
unsafe { ( * crate :: stm32:: OPAMP :: ptr( ) ) . [ <$opamp _csr>] . reset( ) }
300
- ( Disabled , self . non_inverting , self . config, self . output)
302
+ ( Disabled , self . config, self . output)
301
303
}
302
304
303
305
/// Enables the external output pin.
@@ -504,19 +506,16 @@ macro_rules! opamps {
504
506
$mode: ty
505
507
} => {
506
508
paste:: paste!{
507
- impl <IntoNonInverting , IntoOutput > IntoPga
508
- <IntoNonInverting , $mode, IntoOutput , $non_inverting> for Disabled
509
+ impl <IntoOutput > IntoPga <$mode, IntoOutput , $non_inverting> for Disabled
509
510
where
510
- IntoNonInverting : Into <$non_inverting>,
511
511
IntoOutput : Into <$output>,
512
512
{
513
- fn pga(
513
+ fn pga< B : Borrow <$non_inverting>> (
514
514
self ,
515
- non_inverting : IntoNonInverting ,
515
+ _non_inverting : B ,
516
516
config: $mode,
517
517
output: Option <IntoOutput >,
518
518
) -> Pga <$non_inverting, $mode> {
519
- let non_inverting = non_inverting. into( ) ;
520
519
let output = output. map( |output| output. into( ) ) ;
521
520
unsafe {
522
521
use crate :: stm32:: opamp:: [ <$opamp _csr>] :: OPAINTOEN_A ;
@@ -539,7 +538,7 @@ macro_rules! opamps {
539
538
. enabled( )
540
539
) ;
541
540
}
542
- Pga { non_inverting, config, output}
541
+ Pga { non_inverting: PhantomData , config, output}
543
542
}
544
543
}
545
544
}
0 commit comments