Merge pull request 'Add actions file' (#1) from TestActions into master

Reviewed-on: #1
This commit is contained in:
hodasemi 2023-08-25 14:57:46 +02:00
commit da70357595
7 changed files with 97 additions and 106 deletions

View 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

View file

@ -6,17 +6,15 @@ 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.1.0", git = "https://github.com/embassy-rs/embassy", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 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 = ["defmt", "unstable-traits", "nightly", "unstable-pac", "time-driver", "pio", "critical-section-impl"] } 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 = ["defmt", "msos-descriptor"] } embassy-usb = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = ["msos-descriptor"] }
embassy-time = { version = "0.1.0", git = "https://github.com/embassy-rs/embassy", features = ["defmt", "defmt-timestamp-uptime"] } 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" } 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-04-11" channel = "nightly-2023-08-19"
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,6 +2,7 @@
#![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"))]
@ -19,8 +20,11 @@ use embassy_rp::{
spi::{CsPin, Instance}, spi::{CsPin, Instance},
}; };
use embassy_time::{Duration, Timer}; use embassy_rp::peripherals::PIN_25;
use mouse_sensor::PAW3212DB_TJDT; use embassy_rp::spi::{ClkPin, MisoPin, MosiPin};
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;
@ -30,8 +34,6 @@ 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 _};
@ -40,70 +42,16 @@ 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());
// let mouse_sensor = MouseSensor::new( #[cfg(not(feature = "serial"))]
// p.PIN_25, mouse_hid(p.USB, mouse_sensor).await;
// 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(
let serial = Serial::new(p.USB, SerialConfig::new()); p.USB,
p.PIN_25,
let usb_future = Serial::run_usb().await; MouseSensorPins::new(p.SPI0, p.PIN_2, p.PIN_3, p.PIN_4, p.PIN_5),
// 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"))]
@ -139,15 +87,27 @@ where
} }
#[cfg(feature = "serial")] #[cfg(feature = "serial")]
async fn serial_hid<'d, S, T, CSP>(usb: USB, mut mouse_sensor: MouseSensor<'d, S, T, CSP>) async fn serial_hid<'d, T, CSP, Clk, Mosi, Miso, P, C, MI, MO, CS>(
where usb: USB,
S: Sender, led: PIN_25,
sensor_pins: MouseSensorPins<'d, T, Clk, Mosi, Miso, CSP, P, C, MI, MO, CS>,
) where
T: Instance, 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! // Do stuff with the class!
let hid_future = async { let hid_future = async {
@ -161,8 +121,10 @@ where
// pan: 0, // pan: 0,
// }; // };
serial.send_number(x, 10).await; mouse_sensor.sender().send_number(x, 10).await;
serial.send_number(y, 10).await; mouse_sensor.sender().send_msg("\n").await;
mouse_sensor.sender().send_number(y, 10).await;
mouse_sensor.sender().send_msg("\n").await;
} }
} }
}; };

View file

@ -2,9 +2,7 @@ use core::mem;
use embassy_rp::{ use embassy_rp::{
gpio::{Level, Output}, gpio::{Level, Output},
spi::{ spi::{Blocking, ClkPin, Config, CsPin, Instance as SpiInstance, MisoPin, MosiPin, Spi},
Blocking, ClkPin, Config, CsPin, Instance as SpiInstance, MisoPin, MosiPin, Polarity, Spi,
},
Peripheral, Peripheral,
}; };
use embassy_time::{Duration, Timer}; use embassy_time::{Duration, Timer};
@ -63,7 +61,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
// loop { let mut verified = false;
// if me.verify_product_id_1().await {
// break;
// }
// }
// loop { for _ in 0..50 {
// if me.verify_product_id_2().await { if me.verify_product_id_1().await && me.verify_product_id_2().await {
// break; verified = true;
// } }
// } }
// me.led.set_low(); if !verified {
panic!();
}
me.led.set_low();
me me
} }
@ -168,4 +168,8 @@ where
None None
} }
} }
pub fn sender(&mut self) -> &mut S {
&mut self.spi_device.sender
}
} }

View file

@ -4,8 +4,9 @@ use numtoa::NumToA;
use core::future::Future; use core::future::Future;
use embassy_rp::usb::Driver; use embassy_rp::bind_interrupts;
use embassy_rp::{interrupt, peripherals::USB}; use embassy_rp::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};
@ -28,15 +29,21 @@ 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 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. // Create the driver, from the HAL.
let irq = interrupt::take!(USBCTRL_IRQ); let driver = Driver::new(usb, Irqs);
let driver = Driver::new(usb, irq);
// Create embassy-usb Config // Create embassy-usb Config
let mut config = Config::new( let mut config = Config::new(
@ -78,10 +85,10 @@ impl Serial<'static> {
USB = Some(builder.build()); 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() } unsafe { USB.as_mut().unwrap().run() }
} }