generated from melfely/embassy-template-rp2350
71 lines
1.9 KiB
Rust
71 lines
1.9 KiB
Rust
#![no_std]
|
|
#![no_main]
|
|
|
|
use defmt::*;
|
|
use defmt_rtt as _;
|
|
use embassy_executor::Spawner;
|
|
use embassy_rp::{
|
|
bind_interrupts,
|
|
peripherals::USB,
|
|
usb::{Driver as UsbDriver, InterruptHandler as UsbInterruptHandler},
|
|
};
|
|
use embassy_time::Timer;
|
|
use panic_probe as _;
|
|
|
|
use crate::usb::{USB_TX_CHANNEL, handle_usb};
|
|
use usb_communication_shared::response::*;
|
|
|
|
mod usb;
|
|
|
|
bind_interrupts!(struct Irqs{
|
|
USBCTRL_IRQ => UsbInterruptHandler<USB>;
|
|
});
|
|
|
|
#[embassy_executor::main(
|
|
executor = "embassy_rp::executor::Executor",
|
|
entry = "cortex_m_rt::entry"
|
|
)]
|
|
async fn main(spawner: Spawner) {
|
|
let p = embassy_rp::init(Default::default());
|
|
|
|
let usb_driver = UsbDriver::new(p.USB, Irqs);
|
|
|
|
let pin = embassy_rp::gpio::Output::new(p.PIN_26, true);
|
|
|
|
spawner.spawn(handle_usb(usb_driver).unwrap());
|
|
|
|
let led_future = async {
|
|
loop {
|
|
info!("led on!");
|
|
let response = Packet::LedStatus(LedStatus {
|
|
id: 0,
|
|
status: LedState::On,
|
|
});
|
|
USB_TX_CHANNEL.send(response).await;
|
|
|
|
Timer::after_millis(500).await;
|
|
|
|
info!("led off!");
|
|
let response = Packet::LedStatus(LedStatus {
|
|
id: 0,
|
|
status: LedState::Off,
|
|
});
|
|
USB_TX_CHANNEL.send(response).await;
|
|
Timer::after_millis(500).await;
|
|
}
|
|
};
|
|
|
|
led_future.await;
|
|
}
|
|
|
|
// Program metadata for `picotool info`.
|
|
// This isn't needed, but it's recommended to have these minimal entries.
|
|
#[unsafe(link_section = ".bi_entries")]
|
|
#[used]
|
|
pub static PICOTOOL_ENTRIES: [embassy_rp::binary_info::EntryAddr; 4] = [
|
|
embassy_rp::binary_info::rp_program_name!(c"USB-Communication"),
|
|
embassy_rp::binary_info::rp_program_description!(c"USB-Communication System"),
|
|
embassy_rp::binary_info::rp_cargo_version!(),
|
|
embassy_rp::binary_info::rp_program_build_attribute!(),
|
|
];
|