ProjektMaus/src/main.rs

86 lines
1.8 KiB
Rust
Raw Normal View History

2023-03-19 15:19:56 +00:00
#![no_std]
#![no_main]
mod custom_hid;
mod mouse_hid;
2023-03-20 20:50:34 +00:00
mod mouse_sensor;
mod serial;
2023-03-20 20:50:34 +00:00
use mouse_hid::MouseHID;
2023-03-19 15:19:56 +00:00
// Ensure we halt the program on panic (if we don't mention this crate it won't
// be linked)
use panic_halt as _;
use rp_pico as bsp;
use bsp::{
entry,
hal::{
self, pac,
pac::{interrupt, Interrupt},
prelude::*,
usb::UsbBus,
},
XOSC_CRYSTAL_FREQ,
};
use cortex_m::delay::Delay;
use usb_device::{class_prelude::*, prelude::*};
use usbd_hid::{
descriptor::{MouseReport, SerializedDescriptor},
hid_class::HIDClass,
};
2023-03-20 20:50:34 +00:00
use crate::mouse_sensor::MouseSensor;
2023-03-19 15:19:56 +00:00
#[entry]
fn main() -> ! {
// Grab our singleton objects
let mut pac = pac::Peripherals::take().unwrap();
let core = pac::CorePeripherals::take().unwrap();
// Set up the watchdog driver - needed by the clock setup code
let mut watchdog = hal::Watchdog::new(pac.WATCHDOG);
// Configure the clocks
let clocks = hal::clocks::init_clocks_and_plls(
XOSC_CRYSTAL_FREQ,
pac.XOSC,
pac.CLOCKS,
pac.PLL_SYS,
pac.PLL_USB,
&mut pac.RESETS,
&mut watchdog,
)
.ok()
.unwrap();
let peripheral_clock = clocks.peripheral_clock.freq();
let mut mouse_hid = MouseHID::new(
pac.USBCTRL_REGS,
pac.USBCTRL_DPRAM,
&mut pac.RESETS,
core,
clocks,
);
2023-03-20 20:50:34 +00:00
// The single-cycle I/O block controls our GPIO pins
let sio = hal::Sio::new(pac.SIO);
// Set the pins up according to their function on this particular board
let pins = rp_pico::Pins::new(
pac.IO_BANK0,
pac.PADS_BANK0,
sio.gpio_bank0,
&mut pac.RESETS,
);
let mouse_sensor = MouseSensor::new(pins, &mut pac.RESETS, pac.SPI0, peripheral_clock);
2023-03-19 15:19:56 +00:00
loop {
mouse_hid.run();
2023-03-19 15:19:56 +00:00
}
}