Add actions file #1
7 changed files with 97 additions and 106 deletions
22
.gitea/workflows/pull_request.yaml
Normal file
22
.gitea/workflows/pull_request.yaml
Normal file
|
@ -0,0 +1,22 @@
|
|||
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: Install flip-link
|
||||
run: cargo install flip-link
|
||||
|
||||
- name: Build
|
||||
run: cargo build
|
10
Cargo.toml
10
Cargo.toml
|
@ -6,17 +6,15 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
embassy-executor = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
|
||||
embassy-rp = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = ["defmt", "unstable-traits", "nightly", "unstable-pac", "time-driver", "pio", "critical-section-impl"] }
|
||||
embassy-usb = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = ["defmt", "msos-descriptor"] }
|
||||
embassy-time = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = ["defmt", "defmt-timestamp-uptime"] }
|
||||
embassy-executor = { version = "0.3.0", git = "https://github.com/embassy-rs/embassy", features = ["nightly", "arch-cortex-m", "executor-thread", "integrated-timers"] }
|
||||
embassy-rp = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = ["unstable-traits", "nightly", "unstable-pac", "time-driver", "critical-section-impl"] }
|
||||
embassy-usb = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = ["msos-descriptor"] }
|
||||
embassy-time = { version = "0.1.2", git = "https://github.com/embassy-rs/embassy", features = ["defmt-timestamp-uptime"] }
|
||||
embassy-futures = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy" }
|
||||
|
||||
numtoa = "0.2.4"
|
||||
|
||||
usbd-hid = "0.6.1"
|
||||
|
||||
defmt = "0.3"
|
||||
defmt-rtt = "0.4"
|
||||
|
||||
cortex-m = { version = "0.7.6" }
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[toolchain]
|
||||
channel = "nightly-2023-04-11"
|
||||
channel = "nightly-2023-08-19"
|
||||
components = [ "rust-src", "rustfmt", "llvm-tools-preview" ]
|
||||
targets = ["thumbv6m-none-eabi"]
|
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,9 @@ use numtoa::NumToA;
|
|||
|
||||
use core::future::Future;
|
||||
|
||||
use embassy_rp::usb::Driver;
|
||||
use embassy_rp::{interrupt, peripherals::USB};
|
||||
use embassy_rp::bind_interrupts;
|
||||
use embassy_rp::peripherals::USB;
|
||||
use embassy_rp::usb::{Driver, InterruptHandler};
|
||||
|
||||
use embassy_usb::class::cdc_acm::{CdcAcmClass, State};
|
||||
use embassy_usb::{Builder, Config, UsbDevice};
|
||||
|
@ -28,15 +29,21 @@ pub trait Sender {
|
|||
T: NumToA<I>;
|
||||
}
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
USBCTRL_IRQ => InterruptHandler<USB>;
|
||||
});
|
||||
|
||||
pub struct Serial<'a> {
|
||||
class: CdcAcmClass<'a, Driver<'a, USB>>,
|
||||
}
|
||||
|
||||
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);
|
||||
let driver = Driver::new(usb, Irqs);
|
||||
|
||||
// Create embassy-usb Config
|
||||
let mut config = Config::new(
|
||||
|
@ -78,10 +85,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