Compare commits

..

No commits in common. "da7035759542de33df64fa9846c0f57fb7b81dd8" and "dcfaf9e044e6faf5d349691d777d5890f201dd4b" have entirely different histories.

7 changed files with 104 additions and 95 deletions

View file

@ -1,22 +0,0 @@
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

View file

@ -6,15 +6,17 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
embassy-executor = { version = "0.3.0", git = "https://github.com/embassy-rs/embassy", features = ["nightly", "arch-cortex-m", "executor-thread", "integrated-timers"] } 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 = ["unstable-traits", "nightly", "unstable-pac", "time-driver", "critical-section-impl"] } 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 = ["msos-descriptor"] } embassy-usb = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = ["defmt", "msos-descriptor"] }
embassy-time = { version = "0.1.2", git = "https://github.com/embassy-rs/embassy", features = ["defmt-timestamp-uptime"] } embassy-time = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = ["defmt", "defmt-timestamp-uptime"] }
embassy-futures = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy" } embassy-futures = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy" }
numtoa = "0.2.4" numtoa = "0.2.4"
usbd-hid = "0.6.1" usbd-hid = "0.6.1"
defmt = "0.3"
defmt-rtt = "0.4" defmt-rtt = "0.4"
cortex-m = { version = "0.7.6" } cortex-m = { version = "0.7.6" }

View file

@ -1,4 +1,4 @@
[toolchain] [toolchain]
channel = "nightly-2023-08-19" channel = "nightly-2023-04-11"
components = [ "rust-src", "rustfmt", "llvm-tools-preview" ] components = [ "rust-src", "rustfmt", "llvm-tools-preview" ]
targets = ["thumbv6m-none-eabi"] targets = ["thumbv6m-none-eabi"]

View file

@ -2,7 +2,6 @@
#![no_main] #![no_main]
#![feature(type_alias_impl_trait)] #![feature(type_alias_impl_trait)]
#![feature(never_type)] #![feature(never_type)]
#![allow(incomplete_features)]
#![feature(async_fn_in_trait)] #![feature(async_fn_in_trait)]
#[cfg(not(feature = "serial"))] #[cfg(not(feature = "serial"))]
@ -20,11 +19,8 @@ use embassy_rp::{
spi::{CsPin, Instance}, spi::{CsPin, Instance},
}; };
use embassy_rp::peripherals::PIN_25; use embassy_time::{Duration, Timer};
use embassy_rp::spi::{ClkPin, MisoPin, MosiPin}; use mouse_sensor::PAW3212DB_TJDT;
use embassy_rp::Peripheral;
// use embassy_time::{Duration, Timer};
#[cfg(not(feature = "serial"))] #[cfg(not(feature = "serial"))]
use usbd_hid::descriptor::MouseReport; use usbd_hid::descriptor::MouseReport;
@ -34,6 +30,8 @@ use crate::{mouse_hid::mouse_config::MouseConfig, mouse_hid::MouseHID};
#[cfg(feature = "serial")] #[cfg(feature = "serial")]
use crate::usb_serial::{Serial, SerialConfig}; use crate::usb_serial::{Serial, SerialConfig};
use crate::usb_serial::Sender;
use crate::mouse_sensor::{MouseSensor, MouseSensorPins}; use crate::mouse_sensor::{MouseSensor, MouseSensorPins};
use {defmt_rtt as _, panic_probe as _}; use {defmt_rtt as _, panic_probe as _};
@ -42,16 +40,70 @@ use {defmt_rtt as _, panic_probe as _};
async fn main(_spawner: Spawner) { async fn main(_spawner: Spawner) {
let p = embassy_rp::init(Default::default()); let p = embassy_rp::init(Default::default());
#[cfg(not(feature = "serial"))] // let mouse_sensor = MouseSensor::new(
mouse_hid(p.USB, mouse_sensor).await; // 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(feature = "serial")] #[cfg(feature = "serial")]
serial_hid( {
p.USB, let serial = Serial::new(p.USB, SerialConfig::new());
p.PIN_25,
MouseSensorPins::new(p.SPI0, p.PIN_2, p.PIN_3, p.PIN_4, p.PIN_5), 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; .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;
}
} }
#[cfg(not(feature = "serial"))] #[cfg(not(feature = "serial"))]
@ -87,27 +139,15 @@ where
} }
#[cfg(feature = "serial")] #[cfg(feature = "serial")]
async fn serial_hid<'d, T, CSP, Clk, Mosi, Miso, P, C, MI, MO, CS>( async fn serial_hid<'d, S, T, CSP>(usb: USB, mut mouse_sensor: MouseSensor<'d, S, T, CSP>)
usb: USB, where
led: PIN_25, S: Sender,
sensor_pins: MouseSensorPins<'d, T, Clk, Mosi, Miso, CSP, P, C, MI, MO, CS>,
) where
T: Instance, T: Instance,
CSP: CsPin<T> + 'd, 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 serial = Serial::new(usb, SerialConfig::new());
let mut mouse_sensor = MouseSensor::new(led, sensor_pins, serial).await; let usb_future = Serial::run_usb().await;
// Do stuff with the class! // Do stuff with the class!
let hid_future = async { let hid_future = async {
@ -121,10 +161,8 @@ async fn serial_hid<'d, T, CSP, Clk, Mosi, Miso, P, C, MI, MO, CS>(
// pan: 0, // pan: 0,
// }; // };
mouse_sensor.sender().send_number(x, 10).await; serial.send_number(x, 10).await;
mouse_sensor.sender().send_msg("\n").await; serial.send_number(y, 10).await;
mouse_sensor.sender().send_number(y, 10).await;
mouse_sensor.sender().send_msg("\n").await;
} }
} }
}; };

View file

@ -2,7 +2,9 @@ use core::mem;
use embassy_rp::{ use embassy_rp::{
gpio::{Level, Output}, gpio::{Level, Output},
spi::{Blocking, ClkPin, Config, CsPin, Instance as SpiInstance, MisoPin, MosiPin, Spi}, spi::{
Blocking, ClkPin, Config, CsPin, Instance as SpiInstance, MisoPin, MosiPin, Polarity, Spi,
},
Peripheral, Peripheral,
}; };
use embassy_time::{Duration, Timer}; use embassy_time::{Duration, Timer};
@ -61,7 +63,7 @@ where
) -> PAW3212DB_TJDT<'a, S, CS, T> { ) -> PAW3212DB_TJDT<'a, S, CS, T> {
let mut spi_config = Config::default(); let mut spi_config = Config::default();
spi_config.frequency = 1_000_000; 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); let spi = Spi::new_blocking(spi, clk, mosi, miso, spi_config);

View file

@ -110,22 +110,22 @@ where
let mut me = Self { spi_device, led }; let mut me = Self { spi_device, led };
me.led.set_high(); // me.led.set_high();
// verify initialization // // verify initialization
let mut verified = false; // loop {
// if me.verify_product_id_1().await {
// break;
// }
// }
for _ in 0..50 { // loop {
if me.verify_product_id_1().await && me.verify_product_id_2().await { // if me.verify_product_id_2().await {
verified = true; // break;
} // }
} // }
if !verified { // me.led.set_low();
panic!();
}
me.led.set_low();
me me
} }
@ -168,8 +168,4 @@ where
None None
} }
} }
pub fn sender(&mut self) -> &mut S {
&mut self.spi_device.sender
}
} }

View file

@ -4,9 +4,8 @@ use numtoa::NumToA;
use core::future::Future; use core::future::Future;
use embassy_rp::bind_interrupts; use embassy_rp::usb::Driver;
use embassy_rp::peripherals::USB; use embassy_rp::{interrupt, peripherals::USB};
use embassy_rp::usb::{Driver, InterruptHandler};
use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; use embassy_usb::class::cdc_acm::{CdcAcmClass, State};
use embassy_usb::{Builder, Config, UsbDevice}; use embassy_usb::{Builder, Config, UsbDevice};
@ -29,21 +28,15 @@ pub trait Sender {
T: NumToA<I>; T: NumToA<I>;
} }
bind_interrupts!(struct Irqs {
USBCTRL_IRQ => InterruptHandler<USB>;
});
pub struct Serial<'a> { pub struct Serial<'a> {
class: CdcAcmClass<'a, Driver<'a, USB>>, class: CdcAcmClass<'a, Driver<'a, USB>>,
} }
impl Serial<'static> { impl Serial<'static> {
pub async fn new( pub fn new(usb: USB, serial_config: SerialConfig<'static>) -> Serial<'static> {
usb: USB,
serial_config: SerialConfig<'static>,
) -> (Serial<'static>, impl Future<Output = !>) {
// Create the driver, from the HAL. // Create the driver, from the HAL.
let driver = Driver::new(usb, Irqs); let irq = interrupt::take!(USBCTRL_IRQ);
let driver = Driver::new(usb, irq);
// Create embassy-usb Config // Create embassy-usb Config
let mut config = Config::new( let mut config = Config::new(
@ -85,10 +78,10 @@ impl Serial<'static> {
USB = Some(builder.build()); USB = Some(builder.build());
}; };
(Self { class }, Self::run_usb().await) Self { class }
} }
async fn run_usb() -> impl Future<Output = !> { pub async fn run_usb() -> impl Future<Output = !> {
unsafe { USB.as_mut().unwrap().run() } unsafe { USB.as_mut().unwrap().run() }
} }