Skip to content

Commit

Permalink
Remove USB components from example
Browse files Browse the repository at this point in the history
  • Loading branch information
9names committed Apr 14, 2024
1 parent 30de879 commit 4cb67a8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 70 deletions.
3 changes: 0 additions & 3 deletions examples/rp2040-hal-blocking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ publish = false
[dependencies]
cortex-m = "0.7.3"
cortex-m-rt = "0.7.0"
# embedded-hal = { version = "0.2.7", features = ["unproven"] }
embedded-hal = "1"
embedded-time = "0.12.0"
defmt = "0.3.0"
defmt-rtt = "0.4.0"
panic-probe = { version = "0.3.0", features = ["print-defmt"] }
fugit = "0.3.6"
# usb-device = "0.2"
# usbd-human-interface-device = "0.4.5"
wii-ext = { version = "0.3.0", features = ["defmt_print",], path = "../../wii-ext" }
rp-pico = "0.9.0"

Expand Down
72 changes: 5 additions & 67 deletions examples/rp2040-hal-blocking/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,17 @@ use defmt_rtt as _;
use panic_probe as _;

use bsp::hal::{
self,
clocks::{init_clocks_and_plls, Clock},
entry,
gpio,
pac,
sio::Sio,
Timer,
watchdog::Watchdog,
self, clocks::init_clocks_and_plls, entry, gpio, pac, sio::Sio, watchdog::Watchdog, Timer,
};
use fugit::RateExtU32;
use rp_pico as bsp;
use wii_ext::{classic_sync::Classic, core::classic::ClassicReadingCalibrated};

// use embedded_hal::Delay::delay_ms;
// use usb_device::class_prelude::*;
// use usb_device::prelude::*;
// use usbd_human_interface_device::device::joystick::JoystickReport;
// use usbd_human_interface_device::prelude::*;
use wii_ext::classic_sync::Classic;
use embedded_hal::delay::DelayNs;

#[entry]
fn main() -> ! {
info!("Program start");
let mut pac = pac::Peripherals::take().unwrap();
let core = pac::CorePeripherals::take().unwrap();
let mut watchdog = Watchdog::new(pac.WATCHDOG);
let sio = Sio::new(pac.SIO);

Expand All @@ -50,7 +37,6 @@ fn main() -> ! {
.ok()
.unwrap();

// let mut delay = cortex_m::delay::Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
let mut delay = Timer::new(pac.TIMER, &mut pac.RESETS, &clocks);

let pins = bsp::Pins::new(
Expand All @@ -60,29 +46,10 @@ fn main() -> ! {
&mut pac.RESETS,
);

// let usb_bus = UsbBusAllocator::new(hal::usb::UsbBus::new(
// pac.USBCTRL_REGS,
// pac.USBCTRL_DPRAM,
// clocks.usb_clock,
// true,
// &mut pac.RESETS,
// ));

// let mut joy = UsbHidClassBuilder::new()
// .add_device(usbd_human_interface_device::device::joystick::JoystickConfig::default())
// .build(&usb_bus);

// //https://pid.codes
// let mut usb_dev = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x1209, 0x0001))
// .manufacturer("usbd-human-interface-device")
// .product("Rusty joystick")
// .serial_number("TEST")
// .build();

let sda_pin: gpio::Pin<_, gpio::FunctionI2C, _> = pins.gpio8.reconfigure();
let scl_pin: gpio::Pin<_, gpio::FunctionI2C, _> = pins.gpio9.reconfigure();

let i2c = bsp::hal::I2C::i2c0(
let i2c = hal::I2C::i2c0(
pac.I2C0,
sda_pin,
scl_pin,
Expand All @@ -106,18 +73,11 @@ fn main() -> ! {
// let mut controller = Nunchuk::new(i2c, &mut delay).unwrap();
loop {
// Some controllers need a delay between reads or they become unhappy
// delay.delay_ms(10);
delay.delay_ms(10);

// Capture the current button and axis values
let input = controller.read_blocking(&mut delay);
if let Ok(input) = input {
// match joy.device().write_report(&get_report(&input)) {
// Err(UsbHidError::WouldBlock) => {}
// Ok(_) => {}
// Err(e) => {
// core::panic!("Failed to write joystick report: {:?}", e)
// }
// }
// Print inputs from the controller
debug!("{:?}", input);
} else {
Expand All @@ -127,29 +87,7 @@ fn main() -> ! {
let _ = controller.enable_hires(&mut delay);
}
}

// if usb_dev.poll(&mut [&mut joy]) {}
}
}

// fn get_report(input: &ClassicReadingCalibrated) -> JoystickReport {
// // Read out buttons first
// let mut buttons = 0;

// buttons += input.button_b as u8;
// buttons += (input.button_a as u8) << 1;
// buttons += (input.button_y as u8) << 2;
// buttons += (input.button_x as u8) << 3;
// buttons += (input.button_trigger_l as u8) << 4;
// buttons += (input.button_trigger_r as u8) << 5;
// buttons += (input.button_minus as u8) << 6;
// buttons += (input.button_plus as u8) << 7;

// JoystickReport {
// buttons,
// x: input.joystick_left_x,
// y: -input.joystick_left_y,
// }
// }

// End of file

0 comments on commit 4cb67a8

Please sign in to comment.