@@ -100,6 +100,11 @@ use neotron_common_bios as common;
100100/// The type of our IRQ input pin from the MCP23S17.
101101type IrqPin = Pin < bank0:: Gpio20 , Input < PullUp > > ;
102102
103+ type I2cPins = (
104+ Pin < bank0:: Gpio14 , Function < hal:: gpio:: I2C > > ,
105+ Pin < bank0:: Gpio15 , Function < hal:: gpio:: I2C > > ,
106+ ) ;
107+
103108/// All the hardware we use on the Pico
104109struct Hardware {
105110 /// All the pins we use on the Raspberry Pi Pico
@@ -124,18 +129,11 @@ struct Hardware {
124129 /// The number of IRQs we've had
125130 irq_count : u32 ,
126131 /// Our I2C Bus
127- i2c : shared_bus:: BusManagerSimple <
128- hal:: i2c:: I2C <
129- pac:: I2C1 ,
130- (
131- Pin < bank0:: Gpio14 , Function < hal:: gpio:: I2C > > ,
132- Pin < bank0:: Gpio15 , Function < hal:: gpio:: I2C > > ,
133- ) ,
134- hal:: i2c:: Controller ,
135- > ,
136- > ,
132+ i2c : shared_bus:: BusManagerSimple < hal:: i2c:: I2C < pac:: I2C1 , I2cPins , hal:: i2c:: Controller > > ,
137133 /// Our RTC
138134 rtc : rtc:: Rtc ,
135+ /// A Timer
136+ timer : hal:: timer:: Timer ,
139137}
140138
141139/// Flips between true and false so we always send a unique read request
@@ -388,6 +386,7 @@ fn main() -> ! {
388386 pp. I2C1 ,
389387 clocks,
390388 delay,
389+ pp. TIMER ,
391390 ) ;
392391 hw. init_io_chip ( ) ;
393392 hw. set_hdd_led ( false ) ;
@@ -507,6 +506,7 @@ impl Hardware {
507506 /// Build all our hardware drivers.
508507 ///
509508 /// Puts the pins into the right modes, builds the SPI driver, etc.
509+ #[ allow( clippy:: too_many_arguments) ]
510510 fn build (
511511 bank : pac:: IO_BANK0 ,
512512 pads : pac:: PADS_BANK0 ,
@@ -516,6 +516,7 @@ impl Hardware {
516516 i2c : pac:: I2C1 ,
517517 clocks : ClocksManager ,
518518 delay : cortex_m:: delay:: Delay ,
519+ timer : pac:: TIMER ,
519520 ) -> ( Hardware , IrqPin ) {
520521 let hal_pins = rp_pico:: Pins :: new ( bank, pads, sio, resets) ;
521522 // We construct the pin here and then throw it away. Then Core 1 does
@@ -544,6 +545,7 @@ impl Hardware {
544545 let i2c = shared_bus:: BusManagerSimple :: new ( raw_i2c) ;
545546 let proxy = i2c. acquire_i2c ( ) ;
546547 let rtc = rtc:: Rtc :: new ( proxy) ;
548+ let timer = hal:: timer:: Timer :: new ( timer, resets) ;
547549
548550 (
549551 Hardware {
@@ -694,6 +696,7 @@ impl Hardware {
694696 irq_count : 0 ,
695697 i2c,
696698 rtc,
699+ timer,
697700 } ,
698701 hal_pins. gpio20 . into_pull_up_input ( ) ,
699702 )
@@ -1770,14 +1773,18 @@ extern "C" fn power_idle() {
17701773 }
17711774}
17721775
1773- /// TODO: Get the monotonic run-time of the system from SysTick.
17741776extern "C" fn time_ticks_get ( ) -> common:: Ticks {
1775- common:: Ticks ( 0 )
1777+ critical_section:: with ( |cs| {
1778+ let mut lock = HARDWARE . borrow_ref_mut ( cs) ;
1779+ let hw = lock. as_mut ( ) . unwrap ( ) ;
1780+ let now = hw. timer . get_counter ( ) ;
1781+ common:: Ticks ( now. ticks ( ) )
1782+ } )
17761783}
17771784
1778- /// We have a 1 kHz SysTick
1785+ /// We have a 1 MHz timer
17791786extern "C" fn time_ticks_per_second ( ) -> common:: Ticks {
1780- common:: Ticks ( 1000 )
1787+ common:: Ticks ( 1_000_000 )
17811788}
17821789
17831790static IRQ_PIN : Mutex < RefCell < Option < IrqPin > > > = Mutex :: new ( RefCell :: new ( None ) ) ;
0 commit comments