Skip to content
Snippets Groups Projects
Commit e7b4b18d authored by Tommy Andersson's avatar Tommy Andersson
Browse files

All buttons implemented, scroll forward and backwards needs tuning. No anti bounce implemented.

parents 2e2211ed 5e550406
No related branches found
No related tags found
No related merge requests found
# Changelog
<<<<<<< HEAD
<<<<<<< HEAD
=======
## 2021-03-18
......@@ -7,6 +8,8 @@
- examples/usb-mouse.rs, a very small example using external hid library.
>>>>>>> 8d3a36604d8080052d125e924e11622c6bf8b01c
=======
>>>>>>> 5e5504062ee4477abe60461125dac9cfae10ea99
## 2021-03-07
- examples/rtic_bare7.rs, using embedded HAL.
......
......@@ -18,7 +18,7 @@ usb-device = "0.2.7"
panic-halt = "0.2.0"
# Uncomment for the itm panic examples.
panic-itm = "0.4.2"
#panic-itm = "0.4.2"
# Uncomment for the rtt-timing examples.
panic-rtt-target = { version = "0.1.1", features = ["cortex-m"] }
......@@ -36,6 +36,10 @@ version = "0.13.0"
features = ["stm32f411", "rt"]
# [dependencies.stm32f4]
# version = "0.13.0"
# features = ["stm32f411", "rt"]
# [dependencies.stm32f4]
# version = "0.13.0"
# features = ["stm32f411", "rt"]
......@@ -64,3 +68,17 @@ codegen-units = 1 # better optimizations
debug = true # symbols are nice and they don't increase the size on Flash
lto = true # better optimizations
<<<<<<< HEAD
=======
# [features]
# nightly = ["cortex-m/inline-asm"]
# # this lets you use `cargo fix`!
# [[bin]]
# name = "app"
# test = false
# bench = false
>>>>>>> 5e5504062ee4477abe60461125dac9cfae10ea99
......@@ -11,7 +11,11 @@ use stm32f4xx_hal::{
dwt::Dwt,
gpio::Speed,
gpio::{
<<<<<<< HEAD
gpiob::{PB10, PB12},
=======
gpiob::{PB10, PB4},
>>>>>>> 5e5504062ee4477abe60461125dac9cfae10ea99
gpioc::{PC2, PC3},
Alternate, Output, PushPull,
},
......@@ -36,7 +40,11 @@ type PMW3389T = pmw3389::Pmw3389<
PC3<Alternate<stm32f4xx_hal::gpio::AF5>>,
),
>,
<<<<<<< HEAD
PB12<Output<PushPull>>,
=======
PB4<Output<PushPull>>,
>>>>>>> 5e5504062ee4477abe60461125dac9cfae10ea99
>;
#[rtic::app(device = stm32f4xx_hal::stm32, monotonic = rtic::cyccnt::CYCCNT, peripherals = true)]
......@@ -80,7 +88,11 @@ const APP: () = {
let sck = gpiob.pb10.into_alternate_af5();
let miso = gpioc.pc2.into_alternate_af5();
let mosi = gpioc.pc3.into_alternate_af5();
<<<<<<< HEAD
let cs = gpiob.pb12.into_push_pull_output().set_speed(Speed::High);
=======
let cs = gpiob.pb4.into_push_pull_output().set_speed(Speed::High);
>>>>>>> 5e5504062ee4477abe60461125dac9cfae10ea99
let spi = Spi::spi2(
device.SPI2,
......
......@@ -181,8 +181,8 @@ const APP: () = {
gpioa.MODER.write(r | 0b01 << (5 * 2)); // set output mode
// test_modify();
test_modify();
test_modify();
loop {
// set PA5 high
......@@ -246,6 +246,12 @@ const APP: () = {
// What if we could automatically generate that from Vendors specifications (SVD files)?
// Wouldn't that be great?
//
// I got the first assert to work. But I don't understand the second. What are we supposed to do?
// ** your answer here **
// I got the first assert to work. But I don't understand the second. What are we supposed to do?
//
// Commit your answers (bare5_2)
// > cargo run usb-mouse
// or
// > cargo run usb-mouse --release
#![no_main]
#![no_std]
use stm32f4xx_hal::{
gpio::{gpioc::PC13, Input, PullUp},
otg_fs::{UsbBus, UsbBusType, USB},
prelude::*,
};
use usb_device::{bus::UsbBusAllocator, prelude::*};
use usbd_hid::{
descriptor::{generator_prelude::*, MouseReport},
hid_class::HIDClass,
};
use panic_rtt_target as _;
use rtt_target::{rprintln, rtt_init_print};
#[rtic::app(device = stm32f4xx_hal::stm32, peripherals = true)]
const APP: () = {
struct Resources {
btn: PC13<Input<PullUp>>,
hid: HIDClass<'static, UsbBusType>,
usb_dev: UsbDevice<'static, UsbBus<USB>>,
}
#[init]
fn init(ctx: init::Context) -> init::LateResources {
static mut EP_MEMORY: [u32; 1024] = [0; 1024];
static mut USB_BUS: Option<UsbBusAllocator<UsbBusType>> = None;
rtt_init_print!();
rprintln!("init");
// Set up the system clock.
let rcc = ctx.device.RCC.constrain();
let _clocks = rcc.cfgr.sysclk(48.mhz()).require_pll48clk().freeze();
let gpioc = ctx.device.GPIOC.split();
let btn = gpioc.pc13.into_pull_up_input();
let gpioa = ctx.device.GPIOA.split();
let usb = USB {
usb_global: ctx.device.OTG_FS_GLOBAL,
usb_device: ctx.device.OTG_FS_DEVICE,
usb_pwrclk: ctx.device.OTG_FS_PWRCLK,
pin_dm: gpioa.pa11.into_alternate_af10(),
pin_dp: gpioa.pa12.into_alternate_af10(),
};
USB_BUS.replace(UsbBus::new(usb, EP_MEMORY));
let hid = HIDClass::new(USB_BUS.as_ref().unwrap(), MouseReport::desc(), 1);
let usb_dev = UsbDeviceBuilder::new(USB_BUS.as_ref().unwrap(), UsbVidPid(0xc410, 0x0000))
.manufacturer("E70011E")
.product("Mouse")
.serial_number("1.0")
.device_class(0)
.build();
init::LateResources { btn, hid, usb_dev }
}
#[task(binds=OTG_FS, resources = [btn, hid, usb_dev])]
fn on_usb(ctx: on_usb::Context) {
static mut COUNTER: u16 = 0;
// destruct the context
let (btn, usb_dev, hid) = (ctx.resources.btn, ctx.resources.usb_dev, ctx.resources.hid);
let report = MouseReport {
x: match *COUNTER {
// reached after 100ms
100 => {
rprintln!("10");
10
}
// reached after 199ms
199 => {
rprintln!("-10");
-10
}
_ => 0,
},
y: 0,
buttons: btn.is_low().unwrap().into(), // (into takes a bool into an integer)
wheel: 0,
};
// wraps around after 200ms
*COUNTER = (*COUNTER + 1) % 200;
// push the report
hid.push_input(&report).ok();
// update the usb device state
if usb_dev.poll(&mut [hid]) {
return;
}
}
#[idle]
fn idle(_cx: idle::Context) -> ! {
rprintln!("idle");
loop {
continue;
}
}
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment