This repository was archived by the owner on Jul 6, 2019. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717SPI peripheral
1818*/
1919
20+ use hal:: spi;
21+
22+ #[ path="../../lib/wait_for.rs" ] mod wait_for;
23+
24+ pub enum ChipSelect {
25+ CS0 = 0 ,
26+ CS1 = 1 ,
27+ CS2 = 2 ,
28+ CS3 = 3 ,
29+ CS4 = 4 ,
30+ CS5 = 5 ,
31+ }
32+
33+ /// An SPI peripheral instance
34+ pub struct DSPI {
35+ reg : & ' static reg:: DSPI ,
36+ cs : ChipSelect ,
37+ }
38+
39+ impl DSPI {
40+ fn new ( reg : & ' static reg:: DSPI , cs : ChipSelect ) -> DSPI {
41+ reg. mcr . set_halt ( false ) ;
42+ DSPI { reg : reg, cs : cs}
43+ }
44+ }
45+
46+ impl spi:: SPI for DSPI {
47+ fn write ( & self , value : u8 ) {
48+ wait_for ! ( self . reg. sr. tfff( ) ) ;
49+ self . reg . sr . clear_tfff ( ) ;
50+ // TODO(bgamari): Need to ensure this doesn't read
51+ self . reg . pushr
52+ . set_txdata ( value as u32 )
53+ . set_pcs ( self . cs as u32 ) ;
54+ }
55+
56+ fn read ( & self ) -> u8 {
57+ wait_for ! ( self . reg. sr. rfdf( ) ) ;
58+ self . reg . popr . rxdata ( ) as u8
59+ }
60+ }
61+
2062/// Registers
2163pub mod reg {
2264 use lib:: volatile_cell:: VolatileCell ;
You can’t perform that action at this time.
0 commit comments