This commit is contained in:
parent
dcfaf9e044
commit
6f5aedd8a6
5 changed files with 81 additions and 95 deletions
19
.gitea/workflows/pull_request.yaml
Normal file
19
.gitea/workflows/pull_request.yaml
Normal file
|
@ -0,0 +1,19 @@
|
|||
name: Gavania Merge Build
|
||||
run_name: Test successful gavania build on merge request
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, reopened, edited, review_requested, synchronize]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: https://github.com/actions/checkout@v3
|
||||
|
||||
- uses: https://github.com/dtolnay/rust-toolchain@stable
|
||||
|
||||
- name: Build
|
||||
run: cargo build
|
112
src/main.rs
112
src/main.rs
|
@ -2,6 +2,7 @@
|
|||
#![no_main]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
#![feature(never_type)]
|
||||
#![allow(incomplete_features)]
|
||||
#![feature(async_fn_in_trait)]
|
||||
|
||||
#[cfg(not(feature = "serial"))]
|
||||
|
@ -19,8 +20,11 @@ use embassy_rp::{
|
|||
spi::{CsPin, Instance},
|
||||
};
|
||||
|
||||
use embassy_time::{Duration, Timer};
|
||||
use mouse_sensor::PAW3212DB_TJDT;
|
||||
use embassy_rp::peripherals::PIN_25;
|
||||
use embassy_rp::spi::{ClkPin, MisoPin, MosiPin};
|
||||
use embassy_rp::Peripheral;
|
||||
|
||||
// use embassy_time::{Duration, Timer};
|
||||
#[cfg(not(feature = "serial"))]
|
||||
use usbd_hid::descriptor::MouseReport;
|
||||
|
||||
|
@ -30,8 +34,6 @@ use crate::{mouse_hid::mouse_config::MouseConfig, mouse_hid::MouseHID};
|
|||
#[cfg(feature = "serial")]
|
||||
use crate::usb_serial::{Serial, SerialConfig};
|
||||
|
||||
use crate::usb_serial::Sender;
|
||||
|
||||
use crate::mouse_sensor::{MouseSensor, MouseSensorPins};
|
||||
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
@ -40,70 +42,16 @@ use {defmt_rtt as _, panic_probe as _};
|
|||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_rp::init(Default::default());
|
||||
|
||||
// let mouse_sensor = MouseSensor::new(
|
||||
// p.PIN_25,
|
||||
// MouseSensorPins::new(p.SPI0, p.PIN_2, p.PIN_3, p.PIN_4, p.PIN_5),
|
||||
// |_| (),
|
||||
// )
|
||||
// .await;
|
||||
|
||||
// #[cfg(not(feature = "serial"))]
|
||||
// mouse_hid(p.USB, mouse_sensor).await;
|
||||
|
||||
// #[cfg(feature = "serial")]
|
||||
// serial_hid(p.USB, mouse_sensor).await;
|
||||
#[cfg(not(feature = "serial"))]
|
||||
mouse_hid(p.USB, mouse_sensor).await;
|
||||
|
||||
#[cfg(feature = "serial")]
|
||||
{
|
||||
let serial = Serial::new(p.USB, SerialConfig::new());
|
||||
|
||||
let usb_future = Serial::run_usb().await;
|
||||
|
||||
// let mut mouse_sensor = MouseSensor::new(
|
||||
// p.PIN_25,
|
||||
// MouseSensorPins::new(p.SPI0, p.PIN_2, p.PIN_3, p.PIN_4, p.PIN_5),
|
||||
// serial,
|
||||
// )
|
||||
// .await;
|
||||
|
||||
let sensor_pins = MouseSensorPins::new(p.SPI0, p.PIN_2, p.PIN_3, p.PIN_4, p.PIN_5);
|
||||
|
||||
let mut spi_device = PAW3212DB_TJDT::new(
|
||||
sensor_pins.spi,
|
||||
sensor_pins.clk,
|
||||
sensor_pins.mosi,
|
||||
sensor_pins.miso,
|
||||
sensor_pins.cs,
|
||||
serial,
|
||||
)
|
||||
.await;
|
||||
|
||||
// Do stuff with the class!
|
||||
let hid_future = async {
|
||||
loop {
|
||||
// if let Some((x, y)) = mouse_sensor.read_movement().await {
|
||||
// // let report = MouseReport {
|
||||
// // buttons: 0,
|
||||
// // x,
|
||||
// // y,
|
||||
// // wheel: 0,
|
||||
// // pan: 0,
|
||||
// // };
|
||||
|
||||
// // serial.send_number(x, 10).await;
|
||||
// // serial.send_number(y, 10).await;
|
||||
// }
|
||||
|
||||
let id_1 = spi_device.product_id_1().await;
|
||||
spi_device.sender.send_msg("read pid1:\n").await;
|
||||
spi_device.sender.send_number(id_1, 10).await;
|
||||
spi_device.sender.send_msg("\n").await;
|
||||
Timer::after(Duration::from_secs(1)).await;
|
||||
}
|
||||
};
|
||||
|
||||
join(hid_future, usb_future).await;
|
||||
}
|
||||
serial_hid(
|
||||
p.USB,
|
||||
p.PIN_25,
|
||||
MouseSensorPins::new(p.SPI0, p.PIN_2, p.PIN_3, p.PIN_4, p.PIN_5),
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "serial"))]
|
||||
|
@ -139,15 +87,27 @@ where
|
|||
}
|
||||
|
||||
#[cfg(feature = "serial")]
|
||||
async fn serial_hid<'d, S, T, CSP>(usb: USB, mut mouse_sensor: MouseSensor<'d, S, T, CSP>)
|
||||
where
|
||||
S: Sender,
|
||||
async fn serial_hid<'d, T, CSP, Clk, Mosi, Miso, P, C, MI, MO, CS>(
|
||||
usb: USB,
|
||||
led: PIN_25,
|
||||
sensor_pins: MouseSensorPins<'d, T, Clk, Mosi, Miso, CSP, P, C, MI, MO, CS>,
|
||||
) where
|
||||
T: Instance,
|
||||
CSP: CsPin<T> + 'd,
|
||||
{
|
||||
let mut serial = Serial::new(usb, SerialConfig::new());
|
||||
|
||||
let usb_future = Serial::run_usb().await;
|
||||
CSP: CsPin<T> + 'd,
|
||||
Clk: ClkPin<T> + 'd,
|
||||
Mosi: MosiPin<T> + 'd,
|
||||
Miso: MisoPin<T> + 'd,
|
||||
|
||||
P: Peripheral<P = T> + 'd,
|
||||
C: Peripheral<P = Clk> + 'd,
|
||||
MI: Peripheral<P = Mosi> + 'd,
|
||||
MO: Peripheral<P = Miso> + 'd,
|
||||
CS: Peripheral<P = CSP> + 'd,
|
||||
{
|
||||
let (serial, usb_future) = Serial::new(usb, SerialConfig::new()).await;
|
||||
|
||||
let mut mouse_sensor = MouseSensor::new(led, sensor_pins, serial).await;
|
||||
|
||||
// Do stuff with the class!
|
||||
let hid_future = async {
|
||||
|
@ -161,8 +121,10 @@ where
|
|||
// pan: 0,
|
||||
// };
|
||||
|
||||
serial.send_number(x, 10).await;
|
||||
serial.send_number(y, 10).await;
|
||||
mouse_sensor.sender().send_number(x, 10).await;
|
||||
mouse_sensor.sender().send_msg("\n").await;
|
||||
mouse_sensor.sender().send_number(y, 10).await;
|
||||
mouse_sensor.sender().send_msg("\n").await;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -2,9 +2,7 @@ use core::mem;
|
|||
|
||||
use embassy_rp::{
|
||||
gpio::{Level, Output},
|
||||
spi::{
|
||||
Blocking, ClkPin, Config, CsPin, Instance as SpiInstance, MisoPin, MosiPin, Polarity, Spi,
|
||||
},
|
||||
spi::{Blocking, ClkPin, Config, CsPin, Instance as SpiInstance, MisoPin, MosiPin, Spi},
|
||||
Peripheral,
|
||||
};
|
||||
use embassy_time::{Duration, Timer};
|
||||
|
@ -63,7 +61,7 @@ where
|
|||
) -> PAW3212DB_TJDT<'a, S, CS, T> {
|
||||
let mut spi_config = Config::default();
|
||||
spi_config.frequency = 1_000_000;
|
||||
spi_config.polarity = Polarity::IdleHigh;
|
||||
// spi_config.polarity = Polarity::IdleHigh;
|
||||
|
||||
let spi = Spi::new_blocking(spi, clk, mosi, miso, spi_config);
|
||||
|
||||
|
|
|
@ -110,22 +110,22 @@ where
|
|||
|
||||
let mut me = Self { spi_device, led };
|
||||
|
||||
// me.led.set_high();
|
||||
me.led.set_high();
|
||||
|
||||
// // verify initialization
|
||||
// loop {
|
||||
// if me.verify_product_id_1().await {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// verify initialization
|
||||
let mut verified = false;
|
||||
|
||||
// loop {
|
||||
// if me.verify_product_id_2().await {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
for _ in 0..50 {
|
||||
if me.verify_product_id_1().await && me.verify_product_id_2().await {
|
||||
verified = true;
|
||||
}
|
||||
}
|
||||
|
||||
// me.led.set_low();
|
||||
if !verified {
|
||||
panic!();
|
||||
}
|
||||
|
||||
me.led.set_low();
|
||||
|
||||
me
|
||||
}
|
||||
|
@ -168,4 +168,8 @@ where
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sender(&mut self) -> &mut S {
|
||||
&mut self.spi_device.sender
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,10 @@ pub struct Serial<'a> {
|
|||
}
|
||||
|
||||
impl Serial<'static> {
|
||||
pub fn new(usb: USB, serial_config: SerialConfig<'static>) -> Serial<'static> {
|
||||
pub async fn new(
|
||||
usb: USB,
|
||||
serial_config: SerialConfig<'static>,
|
||||
) -> (Serial<'static>, impl Future<Output = !>) {
|
||||
// Create the driver, from the HAL.
|
||||
let irq = interrupt::take!(USBCTRL_IRQ);
|
||||
let driver = Driver::new(usb, irq);
|
||||
|
@ -78,10 +81,10 @@ impl Serial<'static> {
|
|||
USB = Some(builder.build());
|
||||
};
|
||||
|
||||
Self { class }
|
||||
(Self { class }, Self::run_usb().await)
|
||||
}
|
||||
|
||||
pub async fn run_usb() -> impl Future<Output = !> {
|
||||
async fn run_usb() -> impl Future<Output = !> {
|
||||
unsafe { USB.as_mut().unwrap().run() }
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue