2023-03-19 15:19:56 +00:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
|
2023-03-23 05:37:37 +00:00
|
|
|
#[cfg(features = "serial")]
|
2023-03-22 10:24:32 +00:00
|
|
|
mod custom_hid;
|
2023-03-23 05:37:37 +00:00
|
|
|
|
|
|
|
#[cfg(not(features = "serial"))]
|
2023-03-22 10:24:32 +00:00
|
|
|
mod mouse_hid;
|
2023-03-23 05:37:37 +00:00
|
|
|
|
2023-03-20 20:50:34 +00:00
|
|
|
mod mouse_sensor;
|
2023-03-22 10:24:32 +00:00
|
|
|
mod serial;
|
2023-03-20 20:50:34 +00:00
|
|
|
|
2023-03-23 05:37:37 +00:00
|
|
|
#[cfg(features = "serial")]
|
2023-03-22 15:29:13 +00:00
|
|
|
use custom_hid::CustomHID;
|
2023-03-23 05:37:37 +00:00
|
|
|
|
|
|
|
#[cfg(not(features = "serial"))]
|
2023-03-22 10:24:32 +00:00
|
|
|
use mouse_hid::MouseHID;
|
2023-03-22 15:29:13 +00:00
|
|
|
|
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,
|
2023-03-22 15:29:13 +00:00
|
|
|
hal::{self, pac, prelude::*},
|
2023-03-19 15:19:56 +00:00
|
|
|
XOSC_CRYSTAL_FREQ,
|
|
|
|
};
|
|
|
|
|
2023-03-22 15:29:13 +00:00
|
|
|
use crate::mouse_sensor::MouseSensor;
|
2023-03-19 15:19:56 +00:00
|
|
|
|
2023-03-22 15:29:13 +00:00
|
|
|
pub trait MouseInfoSender {
|
|
|
|
fn send(&mut self, x: i8, y: i8, buttons: u8, wheel: i8, pan: i8);
|
|
|
|
}
|
2023-03-20 20:50:34 +00:00
|
|
|
|
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();
|
|
|
|
|
2023-03-22 10:24:32 +00:00
|
|
|
let peripheral_clock = clocks.peripheral_clock.freq();
|
|
|
|
|
2023-03-23 05:37:37 +00:00
|
|
|
#[cfg(features = "serial")]
|
|
|
|
let mut hid = CustomHID::new(
|
|
|
|
pac.USBCTRL_REGS,
|
|
|
|
pac.USBCTRL_DPRAM,
|
|
|
|
&mut pac.RESETS,
|
|
|
|
clocks,
|
|
|
|
10,
|
|
|
|
);
|
|
|
|
|
|
|
|
#[cfg(not(features = "serial"))]
|
|
|
|
let mut hid = MouseHID::new(
|
|
|
|
pac.USBCTRL_REGS,
|
|
|
|
pac.USBCTRL_DPRAM,
|
|
|
|
&mut pac.RESETS,
|
|
|
|
core,
|
|
|
|
clocks,
|
|
|
|
);
|
2023-03-22 10:24:32 +00:00
|
|
|
|
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,
|
|
|
|
);
|
|
|
|
|
2023-03-22 15:29:13 +00:00
|
|
|
let mut mouse_sensor = MouseSensor::new(pins, &mut pac.RESETS, pac.SPI0, peripheral_clock);
|
2023-03-19 15:19:56 +00:00
|
|
|
|
|
|
|
loop {
|
2023-03-22 15:29:13 +00:00
|
|
|
if let Some((x, y)) = mouse_sensor.read_movement() {
|
|
|
|
hid.send(x, y, 0, 0, 0);
|
|
|
|
}
|
2023-03-19 15:19:56 +00:00
|
|
|
}
|
|
|
|
}
|