diff --git a/code/gitignore b/code/.gitignore similarity index 100% rename from code/gitignore rename to code/.gitignore diff --git a/code/examples/pmw3389.rs b/code/examples/pmw3389.rs index b6a86f99f281e9d6147007345618d498b8794615..ae9d5d499a70434085b3f8d718f560ba631774eb 100644 --- a/code/examples/pmw3389.rs +++ b/code/examples/pmw3389.rs @@ -12,7 +12,7 @@ use stm32f4xx_hal::{ gpio::Speed, gpio::{ gpioa::{PA15}, - gpioc::{PC2, PC3}, + gpioc::{PC10, PC11, PC12}, Alternate, Output, PushPull, }, prelude::*, @@ -29,14 +29,14 @@ use rtt_target::{rprintln, rtt_init_print}; type PMW3389T = pmw3389::Pmw3389< Spi< - stm32f4xx_hal::stm32::SPI2, + stm32f4xx_hal::stm32::SPI3, ( - PB10<Alternate<stm32f4xx_hal::gpio::AF5>>, - PC2<Alternate<stm32f4xx_hal::gpio::AF5>>, - PC3<Alternate<stm32f4xx_hal::gpio::AF5>>, + PC10<Alternate<stm32f4xx_hal::gpio::AF6>>, + PC11<Alternate<stm32f4xx_hal::gpio::AF6>>, + PC12<Alternate<stm32f4xx_hal::gpio::AF6>>, ), >, - PB4<Output<PushPull>>, + PA15<Output<PushPull>>, >; #[rtic::app(device = stm32f4xx_hal::stm32, monotonic = rtic::cyccnt::CYCCNT, peripherals = true)] @@ -66,24 +66,23 @@ const APP: () = { // Configure SPI // spi2 // sck - pb10, (yellow) - // miso - pc2, (red) - // mosi - pc3, (orange) - // ncs - pb4, (long yellow) - // motion - (brown) + // miso - pc11, (red) + // mosi - pc12, (orange) + // ncs - pa15, (long yellow) // // +5, (white) // gnd, (black) - let gpiob = device.GPIOB.split(); + let gpioa = device.GPIOA.split(); let gpioc = device.GPIOC.split(); - let sck = gpiob.pb10.into_alternate_af5(); - let miso = gpioc.pc2.into_alternate_af5(); - let mosi = gpioc.pc3.into_alternate_af5(); - let cs = gpiob.pb4.into_push_pull_output().set_speed(Speed::High); + let sck = gpioc.pc10.into_alternate_af6(); + let miso = gpioc.pc11.into_alternate_af6(); + let mosi = gpioc.pc12.into_alternate_af6(); + let cs = gpioa.pa15.into_push_pull_output().set_speed(Speed::High); - let spi = Spi::spi2( - device.SPI2, + let spi = Spi::spi3( + device.SPI3, (sck, miso, mosi), MODE_3, stm32f4xx_hal::time::KiloHertz(2000).into(), diff --git a/code/examples/rtt_rtic_usb_mouse.rs b/code/examples/rtt_rtic_usb_mouse.rs index 7bb3347a607f48c70bc23c468a133d1776c0fcb2..c1c4d088f0c2f17f62c99fea184d3f79f9579e48 100644 --- a/code/examples/rtt_rtic_usb_mouse.rs +++ b/code/examples/rtt_rtic_usb_mouse.rs @@ -11,7 +11,17 @@ use cortex_m::{asm::delay, peripheral::DWT}; use embedded_hal::digital::v2::OutputPin; use rtic::cyccnt::{Instant, U32Ext as _}; use stm32f4xx_hal::{ - gpio, + dwt::Dwt, + gpio::{ + Speed, Alternate, Input, Output, PullUp, PushPull, + gpioa::{PA15}, + gpiob::{}, + gpioc::{PC6, PC7, PC10, PC11, PC12}, + }, + prelude::*, + rcc::Clocks, + spi::Spi, + stm32, otg_fs::{UsbBus, UsbBusType, USB}, prelude::*, }; @@ -200,7 +210,24 @@ pub mod hid { use hid::HIDClass; -type LED = gpio::gpioa::PA5<gpio::Output<gpio::PushPull>>; +// PMW3389 +use app::{ + pmw3389::{self, Register}, + DwtDelay, +}; +use rtt_target::{rprintln, rtt_init_print}; + +type PMW3389T = pmw3389::Pmw3389< + Spi< + stm32f4xx_hal::stm32::SPI3, + ( + PC10<Alternate<stm32f4xx_hal::gpio::AF5>>, + PC11<Alternate<stm32f4xx_hal::gpio::AF5>>, + PC12<Alternate<stm32f4xx_hal::gpio::AF5>>, + ), + >, + PA15<Output<PushPull>>, +>; const PERIOD: u32 = 8_000_000; @@ -208,10 +235,15 @@ const PERIOD: u32 = 8_000_000; const APP: () = { struct Resources { counter: u8, - led: LED, - usb_dev: UsbDevice<'static, UsbBusType>, hid: HIDClass<'static, UsbBusType>, + + MB2: gpioc::PC6<Input<PullUp>>, + MB1: gpioc::PC7<Input<PullUp>>, + DPIB1: gpiob::PB13<Input<PullUp>>, + DPIB2: gpiob::PB12<Input<PullUp>>, + MB5: gpiob::PB15<Input<PullUp>>, + MB4: gpiob::PB14<Input<PullUp>>, } #[init(schedule = [on_tick])] @@ -234,7 +266,6 @@ const APP: () = { // assert!(clocks.usbclk_valid()); let gpioa = cx.device.GPIOA.split(); - let led = gpioa.pa5.into_push_pull_output(); // Pull the D+ pin down to send a RESET condition to the USB bus. let mut usb_dp = gpioa.pa12.into_push_pull_output(); @@ -257,8 +288,8 @@ const APP: () = { let hid = HIDClass::new(USB_BUS.as_ref().unwrap()); let usb_dev = UsbDeviceBuilder::new(USB_BUS.as_ref().unwrap(), UsbVidPid(0xc410, 0x0000)) - .manufacturer("Fake company") - .product("mouse") + .manufacturer("Albatraoz") + .product("VRM") .serial_number("TEST") .device_class(0) .build(); @@ -267,10 +298,9 @@ const APP: () = { init::LateResources { counter: 0, - led, - usb_dev, hid, + MB1:mb1, MB2:mb2, MB4:mb4, MB5:mb5, DPIB1:dpib1, DPIB2:dpib2 } } @@ -282,32 +312,28 @@ const APP: () = { } } - #[task(schedule = [on_tick], resources = [counter, led, hid])] + #[task(schedule = [on_tick], resources = [counter, hid])] fn on_tick(mut cx: on_tick::Context) { cx.schedule.on_tick(Instant::now() + PERIOD.cycles()).ok(); let counter: &mut u8 = &mut cx.resources.counter; - let led = &mut cx.resources.led; let hid = &mut cx.resources.hid; const P: u8 = 2; *counter = (*counter + 1) % P; - // move mouse cursor horizontally (x-axis) while blinking LED + // move mouse cursor horizontally (x-axis) if *counter < P / 2 { - led.set_high().ok(); hid.write(&hid::report(10, 0)); } else { - led.set_low().ok(); hid.write(&hid::report(-10, 0)); } } - #[task(binds=OTG_FS, resources = [counter, led, usb_dev, hid])] + #[task(binds=OTG_FS, resources = [counter, usb_dev, hid])] fn usb_fs(mut cx: usb_fs::Context) { usb_poll( &mut cx.resources.counter, - &mut cx.resources.led, &mut cx.resources.usb_dev, &mut cx.resources.hid, ); @@ -320,7 +346,6 @@ const APP: () = { fn usb_poll<B: bus::UsbBus>( _counter: &mut u8, - _led: &mut LED, usb_dev: &mut UsbDevice<'static, B>, hid: &mut HIDClass<'static, B>, ) {