diff --git a/src/main.rs b/src/main.rs index 5f0be98..9e7eec9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,6 +31,12 @@ bind_interrupts!(struct Irqs { UARTE3_SPIM3_SPIS3_TWIM3_TWIS3 => embassy_nrf::spim::InterruptHandler; }); +/// Embassy task to blink a LED +/// +/// # Arguments +/// pin - Any valid pin is accepted +/// blink_delay - a `Duration` with the amount of time +/// to wait between LED toggles. #[embassy_executor::task] async fn blink(pin: AnyPin, blink_delay: Duration) -> ! { let mut led = Output::new(pin, Level::Low, OutputDrive::Standard); @@ -43,6 +49,22 @@ async fn blink(pin: AnyPin, blink_delay: Duration) -> ! { } } +/// Create a function to run the demo +/// +/// # Arguments +/// This function takes in a variable of a generic type `D`. +/// With the restriction that the generic type `D` implements +/// `DrawTarget`, aka that it is a display. +/// +/// I've also said it needs to use a certain colormode, because +/// that is the color mode I use in the demo. +/// +/// While this may seem a little clunky this function now accepts _any_ +/// display as long as it uses the standard 565 colormode. +/// +/// # Returns +/// The function returns a `Result` containing either an empty tuple +/// or the error type associated with the generic type `D`. fn display_demo(display: &mut D) -> Result<(), D::Error> where D: DrawTarget, @@ -107,7 +129,12 @@ async fn main(spawner: Spawner) { // Spawn the blink task spawner - .spawn(blink(p.P0_02.degrade(), Duration::from_millis(250))) + .spawn( + // Here we give the task to spawn, `.degrade()` turns the specific + // pin on the nRF into the `anyPin` type used above. + // It is basically a conversion between hardware pin and generic pin. + blink(p.P0_02.degrade(), Duration::from_millis(250)), + ) .expect("Failed to start blink task"); ////////////////