2023-07-13 11:16:11 +02:00
|
|
|
//! This example shows how to use USB (Universal Serial Bus) in the RP2040 chip.
|
|
|
|
//!
|
|
|
|
//! This creates the possibility to send log::info/warn/error/debug! to USB serial port.
|
|
|
|
|
2022-11-17 09:26:15 +01:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
|
|
|
use embassy_executor::Spawner;
|
2023-05-15 15:21:05 +02:00
|
|
|
use embassy_rp::bind_interrupts;
|
2022-11-17 09:26:15 +01:00
|
|
|
use embassy_rp::peripherals::USB;
|
2023-05-15 15:21:05 +02:00
|
|
|
use embassy_rp::usb::{Driver, InterruptHandler};
|
2023-10-15 01:57:25 +02:00
|
|
|
use embassy_time::Timer;
|
2022-11-17 09:26:15 +01:00
|
|
|
use {defmt_rtt as _, panic_probe as _};
|
|
|
|
|
2023-05-15 15:21:05 +02:00
|
|
|
bind_interrupts!(struct Irqs {
|
|
|
|
USBCTRL_IRQ => InterruptHandler<USB>;
|
|
|
|
});
|
|
|
|
|
2022-11-17 09:26:15 +01:00
|
|
|
#[embassy_executor::task]
|
|
|
|
async fn logger_task(driver: Driver<'static, USB>) {
|
|
|
|
embassy_usb_logger::run!(1024, log::LevelFilter::Info, driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[embassy_executor::main]
|
|
|
|
async fn main(spawner: Spawner) {
|
|
|
|
let p = embassy_rp::init(Default::default());
|
2023-05-15 15:21:05 +02:00
|
|
|
let driver = Driver::new(p.USB, Irqs);
|
2022-11-17 09:26:15 +01:00
|
|
|
spawner.spawn(logger_task(driver)).unwrap();
|
|
|
|
|
|
|
|
let mut counter = 0;
|
|
|
|
loop {
|
|
|
|
counter += 1;
|
|
|
|
log::info!("Tick {}", counter);
|
2023-10-15 01:57:25 +02:00
|
|
|
Timer::after_secs(1).await;
|
2022-11-17 09:26:15 +01:00
|
|
|
}
|
|
|
|
}
|