Skip to content
Snippets Groups Projects
Commit a60f4551 authored by Otto Kalliorinne's avatar Otto Kalliorinne
Browse files

sensor working

parent 7c1c1315
No related branches found
No related tags found
No related merge requests found
File moved
...@@ -12,7 +12,7 @@ use stm32f4xx_hal::{ ...@@ -12,7 +12,7 @@ use stm32f4xx_hal::{
gpio::Speed, gpio::Speed,
gpio::{ gpio::{
gpioa::{PA15}, gpioa::{PA15},
gpioc::{PC2, PC3}, gpioc::{PC10, PC11, PC12},
Alternate, Output, PushPull, Alternate, Output, PushPull,
}, },
prelude::*, prelude::*,
...@@ -29,14 +29,14 @@ use rtt_target::{rprintln, rtt_init_print}; ...@@ -29,14 +29,14 @@ use rtt_target::{rprintln, rtt_init_print};
type PMW3389T = pmw3389::Pmw3389< type PMW3389T = pmw3389::Pmw3389<
Spi< Spi<
stm32f4xx_hal::stm32::SPI2, stm32f4xx_hal::stm32::SPI3,
( (
PB10<Alternate<stm32f4xx_hal::gpio::AF5>>, PC10<Alternate<stm32f4xx_hal::gpio::AF6>>,
PC2<Alternate<stm32f4xx_hal::gpio::AF5>>, PC11<Alternate<stm32f4xx_hal::gpio::AF6>>,
PC3<Alternate<stm32f4xx_hal::gpio::AF5>>, PC12<Alternate<stm32f4xx_hal::gpio::AF6>>,
), ),
>, >,
PB4<Output<PushPull>>, PA15<Output<PushPull>>,
>; >;
#[rtic::app(device = stm32f4xx_hal::stm32, monotonic = rtic::cyccnt::CYCCNT, peripherals = true)] #[rtic::app(device = stm32f4xx_hal::stm32, monotonic = rtic::cyccnt::CYCCNT, peripherals = true)]
...@@ -66,24 +66,23 @@ const APP: () = { ...@@ -66,24 +66,23 @@ const APP: () = {
// Configure SPI // Configure SPI
// spi2 // spi2
// sck - pb10, (yellow) // sck - pb10, (yellow)
// miso - pc2, (red) // miso - pc11, (red)
// mosi - pc3, (orange) // mosi - pc12, (orange)
// ncs - pb4, (long yellow) // ncs - pa15, (long yellow)
// motion - (brown)
// //
// +5, (white) // +5, (white)
// gnd, (black) // gnd, (black)
let gpiob = device.GPIOB.split(); let gpioa = device.GPIOA.split();
let gpioc = device.GPIOC.split(); let gpioc = device.GPIOC.split();
let sck = gpiob.pb10.into_alternate_af5(); let sck = gpioc.pc10.into_alternate_af6();
let miso = gpioc.pc2.into_alternate_af5(); let miso = gpioc.pc11.into_alternate_af6();
let mosi = gpioc.pc3.into_alternate_af5(); let mosi = gpioc.pc12.into_alternate_af6();
let cs = gpiob.pb4.into_push_pull_output().set_speed(Speed::High); let cs = gpioa.pa15.into_push_pull_output().set_speed(Speed::High);
let spi = Spi::spi2( let spi = Spi::spi3(
device.SPI2, device.SPI3,
(sck, miso, mosi), (sck, miso, mosi),
MODE_3, MODE_3,
stm32f4xx_hal::time::KiloHertz(2000).into(), stm32f4xx_hal::time::KiloHertz(2000).into(),
......
...@@ -11,7 +11,17 @@ use cortex_m::{asm::delay, peripheral::DWT}; ...@@ -11,7 +11,17 @@ use cortex_m::{asm::delay, peripheral::DWT};
use embedded_hal::digital::v2::OutputPin; use embedded_hal::digital::v2::OutputPin;
use rtic::cyccnt::{Instant, U32Ext as _}; use rtic::cyccnt::{Instant, U32Ext as _};
use stm32f4xx_hal::{ 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}, otg_fs::{UsbBus, UsbBusType, USB},
prelude::*, prelude::*,
}; };
...@@ -200,7 +210,24 @@ pub mod hid { ...@@ -200,7 +210,24 @@ pub mod hid {
use hid::HIDClass; 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; const PERIOD: u32 = 8_000_000;
...@@ -208,10 +235,15 @@ const PERIOD: u32 = 8_000_000; ...@@ -208,10 +235,15 @@ const PERIOD: u32 = 8_000_000;
const APP: () = { const APP: () = {
struct Resources { struct Resources {
counter: u8, counter: u8,
led: LED,
usb_dev: UsbDevice<'static, UsbBusType>, usb_dev: UsbDevice<'static, UsbBusType>,
hid: HIDClass<'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])] #[init(schedule = [on_tick])]
...@@ -234,7 +266,6 @@ const APP: () = { ...@@ -234,7 +266,6 @@ const APP: () = {
// assert!(clocks.usbclk_valid()); // assert!(clocks.usbclk_valid());
let gpioa = cx.device.GPIOA.split(); 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. // Pull the D+ pin down to send a RESET condition to the USB bus.
let mut usb_dp = gpioa.pa12.into_push_pull_output(); let mut usb_dp = gpioa.pa12.into_push_pull_output();
...@@ -257,8 +288,8 @@ const APP: () = { ...@@ -257,8 +288,8 @@ const APP: () = {
let hid = HIDClass::new(USB_BUS.as_ref().unwrap()); let hid = HIDClass::new(USB_BUS.as_ref().unwrap());
let usb_dev = UsbDeviceBuilder::new(USB_BUS.as_ref().unwrap(), UsbVidPid(0xc410, 0x0000)) let usb_dev = UsbDeviceBuilder::new(USB_BUS.as_ref().unwrap(), UsbVidPid(0xc410, 0x0000))
.manufacturer("Fake company") .manufacturer("Albatraoz")
.product("mouse") .product("VRM")
.serial_number("TEST") .serial_number("TEST")
.device_class(0) .device_class(0)
.build(); .build();
...@@ -267,10 +298,9 @@ const APP: () = { ...@@ -267,10 +298,9 @@ const APP: () = {
init::LateResources { init::LateResources {
counter: 0, counter: 0,
led,
usb_dev, usb_dev,
hid, hid,
MB1:mb1, MB2:mb2, MB4:mb4, MB5:mb5, DPIB1:dpib1, DPIB2:dpib2
} }
} }
...@@ -282,32 +312,28 @@ const APP: () = { ...@@ -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) { fn on_tick(mut cx: on_tick::Context) {
cx.schedule.on_tick(Instant::now() + PERIOD.cycles()).ok(); cx.schedule.on_tick(Instant::now() + PERIOD.cycles()).ok();
let counter: &mut u8 = &mut cx.resources.counter; let counter: &mut u8 = &mut cx.resources.counter;
let led = &mut cx.resources.led;
let hid = &mut cx.resources.hid; let hid = &mut cx.resources.hid;
const P: u8 = 2; const P: u8 = 2;
*counter = (*counter + 1) % P; *counter = (*counter + 1) % P;
// move mouse cursor horizontally (x-axis) while blinking LED // move mouse cursor horizontally (x-axis)
if *counter < P / 2 { if *counter < P / 2 {
led.set_high().ok();
hid.write(&hid::report(10, 0)); hid.write(&hid::report(10, 0));
} else { } else {
led.set_low().ok();
hid.write(&hid::report(-10, 0)); 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) { fn usb_fs(mut cx: usb_fs::Context) {
usb_poll( usb_poll(
&mut cx.resources.counter, &mut cx.resources.counter,
&mut cx.resources.led,
&mut cx.resources.usb_dev, &mut cx.resources.usb_dev,
&mut cx.resources.hid, &mut cx.resources.hid,
); );
...@@ -320,7 +346,6 @@ const APP: () = { ...@@ -320,7 +346,6 @@ const APP: () = {
fn usb_poll<B: bus::UsbBus>( fn usb_poll<B: bus::UsbBus>(
_counter: &mut u8, _counter: &mut u8,
_led: &mut LED,
usb_dev: &mut UsbDevice<'static, B>, usb_dev: &mut UsbDevice<'static, B>,
hid: &mut HIDClass<'static, B>, hid: &mut HIDClass<'static, B>,
) { ) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment