@@ -196,10 +196,8 @@ impl std::fmt::Display for PinUse {
196
196
}
197
197
}
198
198
199
- #[ derive( Debug ) ]
200
- struct FtInner < Device : MpsseCmdExecutor > {
201
- /// FTDI device.
202
- ft : Device ,
199
+ #[ derive( Debug , Default ) ]
200
+ struct GpioByte {
203
201
/// GPIO direction.
204
202
direction : u8 ,
205
203
/// GPIO value.
@@ -208,17 +206,58 @@ struct FtInner<Device: MpsseCmdExecutor> {
208
206
pins : [ Option < PinUse > ; 8 ] ,
209
207
}
210
208
209
+ #[ derive( Debug ) ]
210
+ struct FtInner < Device : MpsseCmdExecutor > {
211
+ /// FTDI device.
212
+ ft : Device ,
213
+ lower : GpioByte ,
214
+ upper : GpioByte ,
215
+ }
216
+
217
+ // FtInner deref's into .lower because SPI and I2C code were not adjusted yet to handle the split;
218
+ // once those are updated, the Deref implementation can go away again
219
+
220
+ impl < Device : MpsseCmdExecutor > core:: ops:: Deref for FtInner < Device > {
221
+ type Target = GpioByte ;
222
+ fn deref ( & self ) -> & GpioByte {
223
+ & self . lower
224
+ }
225
+ }
226
+
227
+ impl < Device : MpsseCmdExecutor > core:: ops:: DerefMut for FtInner < Device > {
228
+ fn deref_mut ( & mut self ) -> & mut GpioByte {
229
+ & mut self . lower
230
+ }
231
+ }
232
+
211
233
impl < Device : MpsseCmdExecutor > FtInner < Device > {
212
- /// Allocate a pin for a specific use.
234
+ /// Allocate a pin in the lower byte for a specific use.
213
235
pub fn allocate_pin ( & mut self , idx : u8 , purpose : PinUse ) {
214
236
assert ! ( idx < 8 , "Pin index {idx} is out of range 0 - 7" ) ;
215
237
216
- if let Some ( current) = self . pins [ usize:: from ( idx) ] {
238
+ if let Some ( current) = self . lower . pins [ usize:: from ( idx) ] {
217
239
panic ! (
218
- "Unable to allocate pin {idx} for {purpose}, pin is already allocated for {current}"
240
+ "Unable to allocate pin {idx} for {purpose}, pin is already allocated for {current}"
219
241
) ;
220
242
} else {
221
- self . pins [ usize:: from ( idx) ] = Some ( purpose)
243
+ self . lower . pins [ usize:: from ( idx) ] = Some ( purpose)
244
+ }
245
+ }
246
+
247
+ /// Allocate a pin for a specific use.
248
+ pub fn allocate_pin_any ( & mut self , pin : Pin , purpose : PinUse ) {
249
+ let ( byte, idx) = match pin {
250
+ Pin :: Lower ( idx) => ( & mut self . lower , idx) ,
251
+ Pin :: Upper ( idx) => ( & mut self . upper , idx) ,
252
+ } ;
253
+ assert ! ( idx < 8 , "Pin index {idx} is out of range 0 - 7" ) ;
254
+
255
+ if let Some ( current) = byte. pins [ usize:: from ( idx) ] {
256
+ panic ! (
257
+ "Unable to allocate pin {idx} for {purpose}, pin is already allocated for {current}"
258
+ ) ;
259
+ } else {
260
+ byte. pins [ usize:: from ( idx) ] = Some ( purpose)
222
261
}
223
262
}
224
263
}
@@ -227,9 +266,8 @@ impl<Device: MpsseCmdExecutor> From<Device> for FtInner<Device> {
227
266
fn from ( ft : Device ) -> Self {
228
267
FtInner {
229
268
ft,
230
- direction : 0x00 ,
231
- value : 0x00 ,
232
- pins : [ None ; 8 ] ,
269
+ lower : Default :: default ( ) ,
270
+ upper : Default :: default ( ) ,
233
271
}
234
272
}
235
273
}
@@ -585,4 +623,148 @@ where
585
623
pub fn adi7 ( & self ) -> Result < InputPin < Device > , Error < E > > {
586
624
InputPin :: new ( self . mtx . clone ( ) , Pin :: Lower ( 7 ) )
587
625
}
626
+
627
+ /// Aquire the digital output upper pin 0 for the FT232H.
628
+ ///
629
+ /// # Panics
630
+ ///
631
+ /// Panics if the pin is already in-use.
632
+ pub fn c0 ( & self ) -> Result < OutputPin < Device > , Error < E > > {
633
+ OutputPin :: new ( self . mtx . clone ( ) , Pin :: Upper ( 0 ) )
634
+ }
635
+
636
+ /// Aquire the digital input upper pin 0 for the FT232H.
637
+ ///
638
+ /// # Panics
639
+ ///
640
+ /// Panics if the pin is already in-use.
641
+ pub fn ci0 ( & self ) -> Result < InputPin < Device > , Error < E > > {
642
+ InputPin :: new ( self . mtx . clone ( ) , Pin :: Upper ( 0 ) )
643
+ }
644
+
645
+ /// Aquire the digital output upper pin 1 for the FT232H.
646
+ ///
647
+ /// # Panics
648
+ ///
649
+ /// Panics if the pin is already in-use.
650
+ pub fn c1 ( & self ) -> Result < OutputPin < Device > , Error < E > > {
651
+ OutputPin :: new ( self . mtx . clone ( ) , Pin :: Upper ( 1 ) )
652
+ }
653
+
654
+ /// Aquire the digital input upper pin 1 for the FT232H.
655
+ ///
656
+ /// # Panics
657
+ ///
658
+ /// Panics if the pin is already in-use.
659
+ pub fn ci1 ( & self ) -> Result < InputPin < Device > , Error < E > > {
660
+ InputPin :: new ( self . mtx . clone ( ) , Pin :: Upper ( 1 ) )
661
+ }
662
+
663
+ /// Aquire the digital output upper pin 2 for the FT232H.
664
+ ///
665
+ /// # Panics
666
+ ///
667
+ /// Panics if the pin is already in-use.
668
+ pub fn c2 ( & self ) -> Result < OutputPin < Device > , Error < E > > {
669
+ OutputPin :: new ( self . mtx . clone ( ) , Pin :: Upper ( 2 ) )
670
+ }
671
+
672
+ /// Aquire the digital input upper pin 2 for the FT232H.
673
+ ///
674
+ /// # Panics
675
+ ///
676
+ /// Panics if the pin is already in-use.
677
+ pub fn ci2 ( & self ) -> Result < InputPin < Device > , Error < E > > {
678
+ InputPin :: new ( self . mtx . clone ( ) , Pin :: Upper ( 2 ) )
679
+ }
680
+
681
+ /// Aquire the digital output upper pin 3 for the FT232H.
682
+ ///
683
+ /// # Panics
684
+ ///
685
+ /// Panics if the pin is already in-use.
686
+ pub fn c3 ( & self ) -> Result < OutputPin < Device > , Error < E > > {
687
+ OutputPin :: new ( self . mtx . clone ( ) , Pin :: Upper ( 3 ) )
688
+ }
689
+
690
+ /// Aquire the digital input upper pin 3 for the FT232H.
691
+ ///
692
+ /// # Panics
693
+ ///
694
+ /// Panics if the pin is already in-use.
695
+ pub fn ci3 ( & self ) -> Result < InputPin < Device > , Error < E > > {
696
+ InputPin :: new ( self . mtx . clone ( ) , Pin :: Upper ( 3 ) )
697
+ }
698
+
699
+ /// Aquire the digital output upper pin 4 for the FT232H.
700
+ ///
701
+ /// # Panics
702
+ ///
703
+ /// Panics if the pin is already in-use.
704
+ pub fn c4 ( & self ) -> Result < OutputPin < Device > , Error < E > > {
705
+ OutputPin :: new ( self . mtx . clone ( ) , Pin :: Upper ( 4 ) )
706
+ }
707
+
708
+ /// Aquire the digital input upper pin 4 for the FT232H.
709
+ ///
710
+ /// # Panics
711
+ ///
712
+ /// Panics if the pin is already in-use.
713
+ pub fn ci4 ( & self ) -> Result < InputPin < Device > , Error < E > > {
714
+ InputPin :: new ( self . mtx . clone ( ) , Pin :: Upper ( 4 ) )
715
+ }
716
+
717
+ /// Aquire the digital output upper pin 5 for the FT232H.
718
+ ///
719
+ /// # Panics
720
+ ///
721
+ /// Panics if the pin is already in-use.
722
+ pub fn c5 ( & self ) -> Result < OutputPin < Device > , Error < E > > {
723
+ OutputPin :: new ( self . mtx . clone ( ) , Pin :: Upper ( 5 ) )
724
+ }
725
+
726
+ /// Aquire the digital input upper pin 5 for the FT232H.
727
+ ///
728
+ /// # Panics
729
+ ///
730
+ /// Panics if the pin is already in-use.
731
+ pub fn ci5 ( & self ) -> Result < InputPin < Device > , Error < E > > {
732
+ InputPin :: new ( self . mtx . clone ( ) , Pin :: Upper ( 5 ) )
733
+ }
734
+
735
+ /// Aquire the digital output upper pin 6 for the FT232H.
736
+ ///
737
+ /// # Panics
738
+ ///
739
+ /// Panics if the pin is already in-use.
740
+ pub fn c6 ( & self ) -> Result < OutputPin < Device > , Error < E > > {
741
+ OutputPin :: new ( self . mtx . clone ( ) , Pin :: Upper ( 6 ) )
742
+ }
743
+
744
+ /// Aquire the digital input upper pin 6 for the FT232H.
745
+ ///
746
+ /// # Panics
747
+ ///
748
+ /// Panics if the pin is already in-use.
749
+ pub fn ci6 ( & self ) -> Result < InputPin < Device > , Error < E > > {
750
+ InputPin :: new ( self . mtx . clone ( ) , Pin :: Upper ( 6 ) )
751
+ }
752
+
753
+ /// Aquire the digital output upper pin 7 for the FT232H.
754
+ ///
755
+ /// # Panics
756
+ ///
757
+ /// Panics if the pin is already in-use.
758
+ pub fn c7 ( & self ) -> Result < OutputPin < Device > , Error < E > > {
759
+ OutputPin :: new ( self . mtx . clone ( ) , Pin :: Upper ( 7 ) )
760
+ }
761
+
762
+ /// Aquire the digital input upper pin 7 for the FT232H.
763
+ ///
764
+ /// # Panics
765
+ ///
766
+ /// Panics if the pin is already in-use.
767
+ pub fn ci7 ( & self ) -> Result < InputPin < Device > , Error < E > > {
768
+ InputPin :: new ( self . mtx . clone ( ) , Pin :: Upper ( 7 ) )
769
+ }
588
770
}
0 commit comments