Add build features
This commit is contained in:
parent
3494ee5bd8
commit
2de4c0638e
4 changed files with 58 additions and 24 deletions
25
.vscode/tasks.json
vendored
Normal file
25
.vscode/tasks.json
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "cargo",
|
||||
"command": "run",
|
||||
"problemMatcher": [
|
||||
"$rustc"
|
||||
],
|
||||
"label": "rust: Install to Pico (Mouse HID)"
|
||||
},
|
||||
{
|
||||
"type": "cargo",
|
||||
"command": "run",
|
||||
"args": [
|
||||
"--features",
|
||||
"serial"
|
||||
],
|
||||
"problemMatcher": [
|
||||
"$rustc"
|
||||
],
|
||||
"label": "rust: Install to Pico (Serial HID)"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -18,3 +18,6 @@ embedded-hal = "0.2.7"
|
|||
fugit = "0.3.6"
|
||||
numtoa = "0.2.4"
|
||||
usbd-serial = "0.1.1"
|
||||
|
||||
[features]
|
||||
serial = []
|
||||
|
|
46
src/main.rs
46
src/main.rs
|
@ -1,15 +1,19 @@
|
|||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
#[cfg(features = "serial")]
|
||||
mod custom_hid;
|
||||
|
||||
#[cfg(not(features = "serial"))]
|
||||
mod mouse_hid;
|
||||
|
||||
mod mouse_sensor;
|
||||
mod serial;
|
||||
|
||||
use alloc::boxed::Box;
|
||||
#[cfg(features = "serial")]
|
||||
use custom_hid::CustomHID;
|
||||
|
||||
#[cfg(not(features = "serial"))]
|
||||
use mouse_hid::MouseHID;
|
||||
|
||||
// Ensure we halt the program on panic (if we don't mention this crate it won't
|
||||
|
@ -26,8 +30,6 @@ use bsp::{
|
|||
|
||||
use crate::mouse_sensor::MouseSensor;
|
||||
|
||||
const SERIAL: bool = true;
|
||||
|
||||
pub trait MouseInfoSender {
|
||||
fn send(&mut self, x: i8, y: i8, buttons: u8, wheel: i8, pan: i8);
|
||||
}
|
||||
|
@ -56,23 +58,23 @@ fn main() -> ! {
|
|||
|
||||
let peripheral_clock = clocks.peripheral_clock.freq();
|
||||
|
||||
let mut hid: Box<dyn MouseInfoSender> = if SERIAL {
|
||||
Box::new(CustomHID::new(
|
||||
pac.USBCTRL_REGS,
|
||||
pac.USBCTRL_DPRAM,
|
||||
&mut pac.RESETS,
|
||||
clocks,
|
||||
10,
|
||||
))
|
||||
} else {
|
||||
Box::new(MouseHID::new(
|
||||
pac.USBCTRL_REGS,
|
||||
pac.USBCTRL_DPRAM,
|
||||
&mut pac.RESETS,
|
||||
core,
|
||||
clocks,
|
||||
))
|
||||
};
|
||||
#[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,
|
||||
);
|
||||
|
||||
// The single-cycle I/O block controls our GPIO pins
|
||||
let sio = hal::Sio::new(pac.SIO);
|
||||
|
|
|
@ -27,15 +27,19 @@ impl<'a> Serial<'a> {
|
|||
pub fn send_number<T>(&mut self, i: impl NumToA<T>, base: T) {
|
||||
let s = i.numtoa_str(base, &mut self.buf);
|
||||
|
||||
self.send_text(s);
|
||||
Self::send(&mut self.serial, s);
|
||||
}
|
||||
|
||||
pub fn send_text(&mut self, s: &str) {
|
||||
Self::send(&mut self.serial, s);
|
||||
}
|
||||
|
||||
fn send(serial: &mut SerialPort<'a, UsbBus>, s: &str) {
|
||||
// Send back to the host
|
||||
let mut wr_ptr = s.as_bytes();
|
||||
|
||||
while !wr_ptr.is_empty() {
|
||||
match self.serial.write(wr_ptr) {
|
||||
match serial.write(wr_ptr) {
|
||||
Ok(len) => wr_ptr = &wr_ptr[len..],
|
||||
// On error, just drop unwritten data.
|
||||
// One possible error is Err(WouldBlock), meaning the USB
|
||||
|
|
Loading…
Reference in a new issue