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
8292aedc
Commit
8292aedc
authored
4 years ago
by
Otto Kalliorinne
Browse files
Options
Downloads
Patches
Plain Diff
working sensor but no buttons
parent
3043b359
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/8
+0
-0
0 additions, 0 deletions
code/8
code/examples/pmw3389.rs
+10
-4
10 additions, 4 deletions
code/examples/pmw3389.rs
code/examples/rtt_rtic_usb_mouse.rs
+57
-37
57 additions, 37 deletions
code/examples/rtt_rtic_usb_mouse.rs
with
67 additions
and
41 deletions
code/8
0 → 100644
+
0
−
0
View file @
8292aedc
This diff is collapsed.
Click to expand it.
code/examples/pmw3389.rs
+
10
−
4
View file @
8292aedc
...
...
@@ -59,7 +59,12 @@ const APP: () = {
// setup clocks
let
rcc
=
device
.RCC
.constrain
();
let
clocks
=
rcc
.cfgr
.freeze
();
let
clocks
=
rcc
.cfgr
.sysclk
(
84
.mhz
())
.pclk1
(
42
.mhz
())
.pclk2
(
64
.mhz
())
.freeze
();
rprintln!
(
"clocks:"
);
rprintln!
(
"hclk {}"
,
clocks
.hclk
()
.0
);
...
...
@@ -111,17 +116,18 @@ const APP: () = {
static
mut
POS_X
:
i64
=
0
;
*
COUNTER
+=
1
;
if
*
COUNTER
==
1000
/
RATIO
{
if
*
COUNTER
==
1000
0
{
cx
.spawn
.trace
(
*
POS_X
)
.unwrap
();
*
COUNTER
=
0
;
}
let
(
x
,
_y
)
=
cx
.resources.pmw3389
.read_status
()
.unwrap
();
*
POS_X
+=
x
as
i64
;
// task should run each
second N ms (16_000 cycles at 16MHz)
// task should run each
Sclck/N times each second.
cx
.schedule
.poll
(
cx
.scheduled
+
(
RATIO
*
16_0
00
)
.cycles
())
.poll
(
cx
.scheduled
+
(
84_
00
)
.cycles
())
.unwrap
();
}
...
...
This diff is collapsed.
Click to expand it.
code/examples/rtt_rtic_usb_mouse.rs
+
57
−
37
View file @
8292aedc
...
...
@@ -82,9 +82,9 @@ pub mod hid {
0xc0
,
// END_COLLECTION
];
pub
fn
report
(
x
:
i8
,
y
:
i8
)
->
[
u8
;
3
]
{
pub
fn
report
(
b
:
u8
,
x
:
i8
,
y
:
i8
)
->
[
u8
;
3
]
{
[
0x00
,
// button
: none
b
as
u8
,
// button
x
as
u8
,
// x-axis
y
as
u8
,
// y-axis
]
...
...
@@ -188,7 +188,7 @@ pub mod hid {
REQ_GET_REPORT
=>
{
// USB host requests for report
// I'm not sure what should we do here, so just send empty report
xfer
.accept_with
(
&
report
(
0
,
0
))
.ok
();
xfer
.accept_with
(
&
report
(
0
,
0
,
0
))
.ok
();
}
_
=>
{
xfer
.reject
()
.ok
();
...
...
@@ -214,10 +214,7 @@ pub mod hid {
use
hid
::
HIDClass
;
// PMW3389
use
app
::{
pmw3389
::{
self
,
Register
},
DwtDelay
,
};
use
app
::{
DwtDelay
,
pmw3389
::{
self
,
Register
},
pmw3389e
};
use
rtt_target
::{
rprintln
,
rtt_init_print
};
type
PMW3389T
=
pmw3389
::
Pmw3389
<
...
...
@@ -232,8 +229,6 @@ type PMW3389T = pmw3389::Pmw3389<
PA15
<
Output
<
PushPull
>>
,
>
;
const
PERIOD
:
u32
=
8_000_000
;
#[rtic::app(device
=
stm32f4xx_hal::stm32,
peripherals
=
true
,
monotonic
=
rtic::cyccnt::CYCCNT)]
const
APP
:
()
=
{
struct
Resources
{
...
...
@@ -243,6 +238,11 @@ const APP: () = {
pmw3389
:
PMW3389T
,
POS_X
:
i64
,
POS_Y
:
i64
,
OLD_POS_X
:
i64
,
OLD_POS_Y
:
i64
,
MB2
:
gpioc
::
PC6
<
Input
<
PullUp
>>
,
MB1
:
gpioc
::
PC7
<
Input
<
PullUp
>>
,
DPIB1
:
gpiob
::
PB13
<
Input
<
PullUp
>>
,
...
...
@@ -251,7 +251,7 @@ const APP: () = {
MB4
:
gpiob
::
PB14
<
Input
<
PullUp
>>
,
}
#[init(schedule
=
[
on_
tick]
)]
#[init(schedule
=
[
poll,
tick]
)]
fn
init
(
mut
cx
:
init
::
Context
)
->
init
::
LateResources
{
static
mut
USB_BUS
:
Option
<
bus
::
UsbBusAllocator
<
UsbBusType
>>
=
None
;
static
mut
EP_MEMORY
:
[
u32
;
1024
]
=
[
0
;
1024
];
...
...
@@ -262,20 +262,20 @@ const APP: () = {
let
mut
core
=
cx
.core
;
let
device
=
cx
.device
;
let
rcc
=
cx
.
device.RCC
.constrain
();
let
rcc
=
device
.RCC
.constrain
();
let
clocks
=
rcc
.cfgr
// .use_hse
(8.mhz())
.
sys
clk
(
4
8
.mhz
())
.pclk
1
(
2
4
.mhz
())
.sysclk
(
8
4
.mhz
())
.
p
clk
1
(
4
2
.mhz
())
.pclk
2
(
6
4
.mhz
())
.freeze
();
// assert!(clocks.usbclk_valid());
let
gpioa
=
cx
.
device.GPIOA
.split
();
let
gpioc
=
cx
.
device.GPIOC
.split
();
let
gpiob
=
cx
.
device.GPIOB
.split
();
let
gpioa
=
device
.GPIOA
.split
();
let
gpioc
=
device
.GPIOC
.split
();
let
gpiob
=
device
.GPIOB
.split
();
// Buttons
let
mb2
=
gpioc
.pc6
.into_pull_up_input
();
...
...
@@ -299,11 +299,11 @@ const APP: () = {
clocks
,
);
static
mut
OLD_POS_X
:
i64
=
0
;
static
mut
OLD_POS_Y
:
i64
=
0
;
let
mut
delay_dwt
=
DwtDelay
::
new
(
&
mut
core
.DWT
,
clocks
);
let
mut
pmw3389
=
pmw3389
::
Pmw3389
::
new
(
spi
,
cs
,
delay_dwt
)
.unwrap
();
// set in burst mode
pmw3389
.write_register
(
Register
::
MotionBurst
,
0x00
);
...
...
@@ -316,9 +316,9 @@ const APP: () = {
let
usb_dm
=
gpioa
.pa11
;
let
usb
=
USB
{
usb_global
:
cx
.
device.OTG_FS_GLOBAL
,
usb_device
:
cx
.
device.OTG_FS_DEVICE
,
usb_pwrclk
:
cx
.
device.OTG_FS_PWRCLK
,
usb_global
:
device
.OTG_FS_GLOBAL
,
usb_device
:
device
.OTG_FS_DEVICE
,
usb_pwrclk
:
device
.OTG_FS_PWRCLK
,
pin_dm
:
usb_dm
.into_alternate_af10
(),
pin_dp
:
usb_dp
.into_alternate_af10
(),
};
...
...
@@ -334,7 +334,8 @@ const APP: () = {
.device_class
(
0
)
.build
();
cx
.schedule
.on_tick
(
cx
.start
+
PERIOD
.cycles
())
.ok
();
cx
.schedule
.poll
(
cx
.start
+
(
48_000
)
.cycles
())
.ok
();
cx
.schedule
.tick
(
cx
.start
+
(
48_000
)
.cycles
())
.ok
();
init
::
LateResources
{
//counter: 0,
...
...
@@ -342,6 +343,8 @@ const APP: () = {
hid
,
MB1
:
mb1
,
MB2
:
mb2
,
MB4
:
mb4
,
MB5
:
mb5
,
DPIB1
:
dpib1
,
DPIB2
:
dpib2
,
pmw3389
,
POS_X
:
0
,
POS_Y
:
0
,
OLD_POS_X
:
0
,
OLD_POS_Y
:
0
,
}
}
...
...
@@ -353,28 +356,45 @@ const APP: () = {
}
}
#[task(schedule
=
[
on_tick]
,
resources
=
[
hid
,
pmw3389
])]
fn
on_tick
(
mut
cx
:
on_tick
::
Context
)
{
cx
.schedule
.on_tick
(
Instant
::
now
()
+
PERIOD
.cycles
())
.ok
();
#[task(resources
=
[
pmw3389,
POS_X,
POS_Y]
,
schedule
=
[
poll
])]
fn
poll
(
mut
cx
:
poll
::
Context
)
{
let
pos_x
=
cx
.resources.POS_X
;
let
pos_y
=
cx
.resources.POS_Y
;
let
(
x
,
y
)
=
cx
.resources.pmw3389
.read_status
()
.unwrap
();
*
pos_x
+=
x
as
i64
;
*
pos_y
+=
y
as
i64
;
// task should run each Sclck/N times each second. 84M/8400 = 10_000
cx
.schedule
.poll
(
cx
.scheduled
+
(
84_00
)
.cycles
())
.unwrap
();
}
#[task(resources
=
[
hid,
POS_X,
POS_Y,
OLD_POS_X,
OLD_POS_Y,
MB1,
MB2]
,
schedule
=
[
tick
])]
fn
tick
(
mut
cx
:
tick
::
Context
)
{
cx
.schedule
.tick
(
cx
.scheduled
+
(
84_000
)
.cycles
())
.unwrap
();
let
pos_x
=
cx
.resources.POS_X
;
let
pos_y
=
cx
.resources.POS_Y
;
let
old_pos_x
=
cx
.resources.OLD_POS_X
;
let
old_pos_y
=
cx
.resources.OLD_POS_Y
;
//let counter: &mut u8 = &mut cx.resources.counter;
let
hid
=
&
mut
cx
.resources.hid
;
const
P
:
u8
=
2
;
let
x
:
i8
;
let
y
:
i8
;
//*counter = (*counter + 1) % P;
(
x
,
y
)
=
cx
.resources.pmw3389
.read_status
()
.unwrap
();
// Calc movement
let
diff_x
=
*
pos_x
-*
old_pos_x
;
let
diff_y
=
*
pos_y
-*
old_pos_y
;
//
move mouse cursor horizontally (x-axis)
hid
.write
(
&
hid
::
report
(
x
,
y
));
//
Send to computer
hid
.write
(
&
hid
::
report
(
0x01
as
u8
,(
diff_x
)
as
i8
,
(
diff_y
)
as
i8
));
*
old_pos_x
=
*
pos_x
;
*
old_pos_y
=
*
pos_y
;
}
#[task(binds=OTG_FS,
resources
=
[
usb_dev,
hid]
)]
fn
usb_fs
(
mut
cx
:
usb_fs
::
Context
)
{
usb_poll
(
//&mut cx.resources.counter,
&
mut
cx
.resources.usb_dev
,
&
mut
cx
.resources.hid
,
);
...
...
@@ -382,11 +402,11 @@ const APP: () = {
extern
"C"
{
fn
EXTI0
();
fn
EXTI1
();
}
};
fn
usb_poll
<
B
:
bus
::
UsbBus
>
(
//_counter: &mut u8,
usb_dev
:
&
mut
UsbDevice
<
'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