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
b242ea60
Commit
b242ea60
authored
4 years ago
by
Carl Österberg
Browse files
Options
Downloads
Plain Diff
change in button_test
parents
4b09c67b
3043b359
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
code/examples/rtt_rtic_usb_mouse.rs
+60
-19
60 additions, 19 deletions
code/examples/rtt_rtic_usb_mouse.rs
with
60 additions
and
19 deletions
code/examples/rtt_rtic_usb_mouse.rs
+
60
−
19
View file @
b242ea60
...
@@ -5,17 +5,20 @@
...
@@ -5,17 +5,20 @@
#![no_std]
#![no_std]
#![no_main]
#![no_main]
use
core
::
i8
;
use
panic_halt
as
_
;
use
panic_halt
as
_
;
use
cortex_m
::{
asm
::
delay
,
peripheral
::
DWT
};
use
cortex_m
::{
asm
::
delay
,
peripheral
::
DWT
};
use
embedded_hal
::
digital
::
v2
::
OutputPin
;
use
embedded_hal
::
digital
::
v2
::
OutputPin
;
use
embedded_hal
::
spi
::
MODE_3
;
use
rtic
::
cyccnt
::{
Instant
,
U32Ext
as
_
};
use
rtic
::
cyccnt
::{
Instant
,
U32Ext
as
_
};
use
stm32f4xx_hal
::{
use
stm32f4xx_hal
::{
dwt
::
Dwt
,
dwt
::
Dwt
,
gpio
::{
gpio
::{
Speed
,
Alternate
,
Input
,
Output
,
PullUp
,
PushPull
,
Speed
,
Alternate
,
Input
,
Output
,
PullUp
,
PushPull
,
gpioa
::{
PA15
},
gpioa
::{
PA15
},
gpiob
,
gpiob
::{
self
,
PB12
,
PB13
,
PB14
,
PB15
}
,
gpioc
::{
self
,
PC6
,
PC7
,
PC10
,
PC11
,
PC12
},
gpioc
::{
self
,
PC6
,
PC7
,
PC10
,
PC11
,
PC12
},
},
},
prelude
::
*
,
prelude
::
*
,
...
@@ -221,9 +224,9 @@ type PMW3389T = pmw3389::Pmw3389<
...
@@ -221,9 +224,9 @@ type PMW3389T = pmw3389::Pmw3389<
Spi
<
Spi
<
stm32f4xx_hal
::
stm32
::
SPI3
,
stm32f4xx_hal
::
stm32
::
SPI3
,
(
(
PC10
<
Alternate
<
stm32f4xx_hal
::
gpio
::
AF
5
>>
,
PC10
<
Alternate
<
stm32f4xx_hal
::
gpio
::
AF
6
>>
,
PC11
<
Alternate
<
stm32f4xx_hal
::
gpio
::
AF
5
>>
,
PC11
<
Alternate
<
stm32f4xx_hal
::
gpio
::
AF
6
>>
,
PC12
<
Alternate
<
stm32f4xx_hal
::
gpio
::
AF
5
>>
,
PC12
<
Alternate
<
stm32f4xx_hal
::
gpio
::
AF
6
>>
,
),
),
>
,
>
,
PA15
<
Output
<
PushPull
>>
,
PA15
<
Output
<
PushPull
>>
,
...
@@ -234,10 +237,12 @@ const PERIOD: u32 = 8_000_000;
...
@@ -234,10 +237,12 @@ const PERIOD: u32 = 8_000_000;
#[rtic::app(device
=
stm32f4xx_hal::stm32,
peripherals
=
true
,
monotonic
=
rtic::cyccnt::CYCCNT)]
#[rtic::app(device
=
stm32f4xx_hal::stm32,
peripherals
=
true
,
monotonic
=
rtic::cyccnt::CYCCNT)]
const
APP
:
()
=
{
const
APP
:
()
=
{
struct
Resources
{
struct
Resources
{
counter
:
u8
,
//
counter: u8,
usb_dev
:
UsbDevice
<
'static
,
UsbBusType
>
,
usb_dev
:
UsbDevice
<
'static
,
UsbBusType
>
,
hid
:
HIDClass
<
'static
,
UsbBusType
>
,
hid
:
HIDClass
<
'static
,
UsbBusType
>
,
pmw3389
:
PMW3389T
,
MB2
:
gpioc
::
PC6
<
Input
<
PullUp
>>
,
MB2
:
gpioc
::
PC6
<
Input
<
PullUp
>>
,
MB1
:
gpioc
::
PC7
<
Input
<
PullUp
>>
,
MB1
:
gpioc
::
PC7
<
Input
<
PullUp
>>
,
DPIB1
:
gpiob
::
PB13
<
Input
<
PullUp
>>
,
DPIB1
:
gpiob
::
PB13
<
Input
<
PullUp
>>
,
...
@@ -254,6 +259,9 @@ const APP: () = {
...
@@ -254,6 +259,9 @@ const APP: () = {
DWT
::
unlock
();
DWT
::
unlock
();
cx
.core.DWT
.enable_cycle_counter
();
cx
.core.DWT
.enable_cycle_counter
();
let
mut
core
=
cx
.core
;
let
device
=
cx
.device
;
let
rcc
=
cx
.device.RCC
.constrain
();
let
rcc
=
cx
.device.RCC
.constrain
();
let
clocks
=
rcc
let
clocks
=
rcc
...
@@ -269,6 +277,7 @@ const APP: () = {
...
@@ -269,6 +277,7 @@ const APP: () = {
let
gpioc
=
cx
.device.GPIOC
.split
();
let
gpioc
=
cx
.device.GPIOC
.split
();
let
gpiob
=
cx
.device.GPIOB
.split
();
let
gpiob
=
cx
.device.GPIOB
.split
();
<<<<<<<
HEAD
let
mb2
=
gpioc
.pc6
.into_pull_up_input
();
let
mb2
=
gpioc
.pc6
.into_pull_up_input
();
let
mb1
=
gpioc
.pc7
.into_pull_up_input
();
let
mb1
=
gpioc
.pc7
.into_pull_up_input
();
...
@@ -277,6 +286,37 @@ const APP: () = {
...
@@ -277,6 +286,37 @@ const APP: () = {
let
dpib1
=
gpiob
.pb13
.into_pull_up_input
();
let
dpib1
=
gpiob
.pb13
.into_pull_up_input
();
let
dpib2
=
gpiob
.pb12
.into_pull_up_input
();
let
dpib2
=
gpiob
.pb12
.into_pull_up_input
();
=======
// Buttons
let
mb2
=
gpioc
.pc6
.into_pull_up_input
();
let
mb1
=
gpioc
.pc7
.into_pull_up_input
();
let
mb5
=
gpiob
.pb15
.into_pull_up_input
();
let
mb4
=
gpiob
.pb14
.into_pull_up_input
();
let
dpib1
=
gpiob
.pb13
.into_pull_up_input
();
let
dpib2
=
gpiob
.pb12
.into_pull_up_input
();
// Sensor communcation
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
::
spi3
(
device
.SPI3
,
(
sck
,
miso
,
mosi
),
MODE_3
,
stm32f4xx_hal
::
time
::
KiloHertz
(
2000
)
.into
(),
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
);
>>>>>>>
3043
b359af07960fb4472e373824f552897ee4aa
// 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
();
...
@@ -308,10 +348,11 @@ const APP: () = {
...
@@ -308,10 +348,11 @@ const APP: () = {
cx
.schedule
.on_tick
(
cx
.start
+
PERIOD
.cycles
())
.ok
();
cx
.schedule
.on_tick
(
cx
.start
+
PERIOD
.cycles
())
.ok
();
init
::
LateResources
{
init
::
LateResources
{
counter
:
0
,
//
counter: 0,
usb_dev
,
usb_dev
,
hid
,
hid
,
MB1
:
mb1
,
MB2
:
mb2
,
MB4
:
mb4
,
MB5
:
mb5
,
DPIB1
:
dpib1
,
DPIB2
:
dpib2
MB1
:
mb1
,
MB2
:
mb2
,
MB4
:
mb4
,
MB5
:
mb5
,
DPIB1
:
dpib1
,
DPIB2
:
dpib2
,
pmw3389
,
}
}
}
}
...
@@ -323,28 +364,28 @@ const APP: () = {
...
@@ -323,28 +364,28 @@ const APP: () = {
}
}
}
}
#[task(schedule
=
[
on_tick]
,
resources
=
[
counter
,
hid
])]
#[task(schedule
=
[
on_tick]
,
resources
=
[
hid
,
pmw3389
])]
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
hid
=
&
mut
cx
.resources.hid
;
let
hid
=
&
mut
cx
.resources.hid
;
const
P
:
u8
=
2
;
const
P
:
u8
=
2
;
*
counter
=
(
*
counter
+
1
)
%
P
;
let
x
:
i8
;
let
y
:
i8
;
//*counter = (*counter + 1) % P;
(
x
,
y
)
=
cx
.resources.pmw3389
.read_status
()
.unwrap
();
// move mouse cursor horizontally (x-axis)
// move mouse cursor horizontally (x-axis)
if
*
counter
<
P
/
2
{
hid
.write
(
&
hid
::
report
(
x
,
y
));
hid
.write
(
&
hid
::
report
(
10
,
0
));
}
else
{
hid
.write
(
&
hid
::
report
(
-
10
,
0
));
}
}
}
#[task(binds=OTG_FS,
resources
=
[
counter,
usb_dev,
hid]
)]
#[task(binds=OTG_FS,
resources
=
[
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.usb_dev
,
&
mut
cx
.resources.usb_dev
,
&
mut
cx
.resources.hid
,
&
mut
cx
.resources.hid
,
);
);
...
@@ -356,7 +397,7 @@ const APP: () = {
...
@@ -356,7 +397,7 @@ const APP: () = {
};
};
fn
usb_poll
<
B
:
bus
::
UsbBus
>
(
fn
usb_poll
<
B
:
bus
::
UsbBus
>
(
_counter
:
&
mut
u8
,
//
_counter: &mut u8,
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