162 lines
3.9 KiB
Rust
162 lines
3.9 KiB
Rust
#![no_std]
|
|
#![no_main]
|
|
|
|
#[cfg(feature = "serial")]
|
|
mod custom_hid;
|
|
|
|
#[cfg(not(feature = "serial"))]
|
|
mod mouse_hid;
|
|
|
|
mod mouse_sensor;
|
|
mod serial;
|
|
|
|
use core::panic::PanicInfo;
|
|
|
|
use cortex_m::delay::Delay;
|
|
#[cfg(feature = "serial")]
|
|
use custom_hid::CustomHID;
|
|
|
|
#[cfg(not(feature = "serial"))]
|
|
use mouse_hid::MouseHID;
|
|
|
|
#[panic_handler]
|
|
fn panic(_info: &PanicInfo) -> ! {
|
|
loop {}
|
|
}
|
|
|
|
use rp_pico as bsp;
|
|
|
|
use bsp::{
|
|
entry,
|
|
hal::{self, pac, prelude::*},
|
|
XOSC_CRYSTAL_FREQ,
|
|
};
|
|
|
|
use crate::mouse_sensor::MouseSensor;
|
|
|
|
pub trait MouseInfoSender {
|
|
fn send(&mut self, x: i8, y: i8, buttons: u8, wheel: i8, pan: i8);
|
|
fn heart_beat(&mut self);
|
|
}
|
|
|
|
#[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 delay = Delay::new(core.SYST, clocks.system_clock.freq().to_Hz());
|
|
|
|
#[cfg(feature = "serial")]
|
|
let mut hid = CustomHID::new(
|
|
pac.USBCTRL_REGS,
|
|
pac.USBCTRL_DPRAM,
|
|
&mut pac.RESETS,
|
|
clocks,
|
|
10,
|
|
);
|
|
|
|
#[cfg(not(feature = "serial"))]
|
|
let mut hid = MouseHID::new(
|
|
pac.USBCTRL_REGS,
|
|
pac.USBCTRL_DPRAM,
|
|
&mut pac.RESETS,
|
|
core,
|
|
clocks,
|
|
);
|
|
|
|
// 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 mut mouse_sensor = MouseSensor::new(
|
|
pins,
|
|
&mut pac.RESETS,
|
|
pac.SPI0,
|
|
peripheral_clock,
|
|
delay,
|
|
|msg| {
|
|
#[cfg(feature = "serial")]
|
|
critical_section::with(|_| {
|
|
custom_hid::serial().send_text(msg);
|
|
});
|
|
},
|
|
);
|
|
|
|
// #[cfg(feature = "serial")]
|
|
// {
|
|
// hid.serial(|serial| {
|
|
// serial.send_number(mouse_sensor.product_id_1(), 10);
|
|
// serial.send_number(mouse_sensor.product_id_2(), 10);
|
|
// });
|
|
// }
|
|
|
|
let mut c = 0;
|
|
|
|
loop {
|
|
// if let Some((x, y)) = mouse_sensor.read_movement() {
|
|
// hid.send(x, y, 0, 0, 0);
|
|
// }
|
|
|
|
c += 1;
|
|
|
|
if c == 10_000_000 {
|
|
c = 0;
|
|
|
|
#[cfg(feature = "serial")]
|
|
critical_section::with(|_| {
|
|
let serial = custom_hid::serial();
|
|
|
|
// serial.send_text("---");
|
|
// serial.send_number(mouse_sensor.product_id_1(), 10);
|
|
// serial.send_text(" - ");
|
|
// serial.send_number(0x30, 10);
|
|
|
|
// serial.send_text("---");
|
|
// serial.send_number(mouse_sensor.product_id_2(), 10);
|
|
// serial.send_text(" - ");
|
|
// serial.send_number(0x02, 10);
|
|
|
|
// custom_hid::serial().send_number(mouse_sensor.spi_device.product_id_2(), 10);
|
|
|
|
custom_hid::serial().send_text("verify ids:");
|
|
custom_hid::serial().send_text(if mouse_sensor.verify_product_id_1() {
|
|
"PID1 true"
|
|
} else {
|
|
"PID1 false"
|
|
});
|
|
custom_hid::serial().send_text(if mouse_sensor.verify_product_id_2() {
|
|
"PID2 true"
|
|
} else {
|
|
"PID2 false"
|
|
});
|
|
});
|
|
}
|
|
|
|
// hid.heart_beat();
|
|
}
|
|
}
|