Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
GamingMouse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Carl Österberg
GamingMouse
Commits
a60f4551
Commit
a60f4551
authored
4 years ago
by
Otto Kalliorinne
Browse files
Options
Downloads
Patches
Plain Diff
sensor working
parent
7c1c1315
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
code/.gitignore
+0
-0
0 additions, 0 deletions
code/.gitignore
code/examples/pmw3389.rs
+16
-17
16 additions, 17 deletions
code/examples/pmw3389.rs
code/examples/rtt_rtic_usb_mouse.rs
+42
-17
42 additions, 17 deletions
code/examples/rtt_rtic_usb_mouse.rs
with
58 additions
and
34 deletions
code/gitignore
→
code/
.
gitignore
+
0
−
0
View file @
a60f4551
File moved
This diff is collapsed.
Click to expand it.
code/examples/pmw3389.rs
+
16
−
17
View file @
a60f4551
...
@@ -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
::{
PC
2
,
PC
3
},
gpioc
::{
PC
10
,
PC
11
,
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
::
SPI
2
,
stm32f4xx_hal
::
stm32
::
SPI
3
,
(
(
P
B
10
<
Alternate
<
stm32f4xx_hal
::
gpio
::
AF
5
>>
,
P
C
10
<
Alternate
<
stm32f4xx_hal
::
gpio
::
AF
6
>>
,
PC
2
<
Alternate
<
stm32f4xx_hal
::
gpio
::
AF
5
>>
,
PC
11
<
Alternate
<
stm32f4xx_hal
::
gpio
::
AF
6
>>
,
PC
3
<
Alternate
<
stm32f4xx_hal
::
gpio
::
AF
5
>>
,
PC
12
<
Alternate
<
stm32f4xx_hal
::
gpio
::
AF
6
>>
,
),
),
>
,
>
,
P
B4
<
Output
<
PushPull
>>
,
P
A15
<
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
gpio
b
=
device
.GPIO
B
.split
();
let
gpio
a
=
device
.GPIO
A
.split
();
let
gpioc
=
device
.GPIOC
.split
();
let
gpioc
=
device
.GPIOC
.split
();
let
sck
=
gpio
b
.p
b
10
.into_alternate_af
5
();
let
sck
=
gpio
c
.p
c
10
.into_alternate_af
6
();
let
miso
=
gpioc
.pc
2
.into_alternate_af
5
();
let
miso
=
gpioc
.pc
11
.into_alternate_af
6
();
let
mosi
=
gpioc
.pc
3
.into_alternate_af
5
();
let
mosi
=
gpioc
.pc
12
.into_alternate_af
6
();
let
cs
=
gpio
b
.p
b4
.into_push_pull_output
()
.set_speed
(
Speed
::
High
);
let
cs
=
gpio
a
.p
a15
.into_push_pull_output
()
.set_speed
(
Speed
::
High
);
let
spi
=
Spi
::
spi
2
(
let
spi
=
Spi
::
spi
3
(
device
.SPI
2
,
device
.SPI
3
,
(
sck
,
miso
,
mosi
),
(
sck
,
miso
,
mosi
),
MODE_3
,
MODE_3
,
stm32f4xx_hal
::
time
::
KiloHertz
(
2000
)
.into
(),
stm32f4xx_hal
::
time
::
KiloHertz
(
2000
)
.into
(),
...
...
This diff is collapsed.
Click to expand it.
code/examples/rtt_rtic_usb_mouse.rs
+
42
−
17
View file @
a60f4551
...
@@ -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
>
,
)
{
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment