Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
gaming_mouse
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
e7020e_2021_group_edwkll-7
gaming_mouse
Commits
58ff8fba
Commit
58ff8fba
authored
4 years ago
by
Edward
Browse files
Options
Downloads
Patches
Plain Diff
fix leds + cleanup
parent
9d83537e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
code/Project_Mouse.rs
+19
-48
19 additions, 48 deletions
code/Project_Mouse.rs
with
19 additions
and
48 deletions
code/Project_Mouse.rs
+
19
−
48
View file @
58ff8fba
...
@@ -3,19 +3,18 @@
...
@@ -3,19 +3,18 @@
use
embedded_hal
::
spi
::
MODE_3
;
use
embedded_hal
::
spi
::
MODE_3
;
use
panic_rtt_target
as
_
;
use
panic_rtt_target
as
_
;
use
rtt_target
as
_
;
use
rtt_target
as
_
;
use
cortex_m
::{
asm
::
delay
,
peripheral
::
DWT
};
use
cortex_m
::{
peripheral
::
DWT
};
use
embedded_hal
::
digital
::
v2
::{
OutputPin
,
ToggleableOutputPin
};
use
embedded_hal
::
digital
::
v2
::{
OutputPin
};
use
stm32f4xx_hal
::{
use
stm32f4xx_hal
::{
gpio
,
otg_fs
::{
UsbBus
,
UsbBusType
,
USB
},
otg_fs
::{
UsbBus
,
UsbBusType
,
USB
},
prelude
::
*
,
prelude
::
*
,
};
};
use
usb_device
::{
bus
::
UsbBusAllocator
,
prelude
::
*
};
use
usb_device
::{
bus
::
UsbBusAllocator
,
prelude
::
*
};
use
usbd_hid
::{
use
usbd_hid
::{
descriptor
::{
generator_prelude
::
*
,
MouseReport
},
descriptor
::{
generator_prelude
::
*
},
hid_class
::
HIDClass
hid_class
::
HIDClass
};
};
use
app
::{
DwtDelay
,
pmw3389
::{
self
,
Register
}
,
pmw3389e
};
use
app
::{
DwtDelay
,
pmw3389
::{
self
,
Register
}};
use
usbd_hid
::
descriptor
::
SerializedDescriptor
;
use
usbd_hid
::
descriptor
::
SerializedDescriptor
;
use
usbd_hid
::
descriptor
::
AsInputReport
;
use
usbd_hid
::
descriptor
::
AsInputReport
;
use
usbd_hid
::
descriptor
::
gen_hid_descriptor
;
use
usbd_hid
::
descriptor
::
gen_hid_descriptor
;
...
@@ -46,19 +45,15 @@ pub struct PMouseReport {
...
@@ -46,19 +45,15 @@ pub struct PMouseReport {
pub
wheel
:
i8
,
// Scroll down (negative) or up (positive) this many units
pub
wheel
:
i8
,
// Scroll down (negative) or up (positive) this many units
}
}
use
rtic
::
cyccnt
::{
Instant
,
U32Ext
as
_
};
use
rtic
::
cyccnt
::{
U32Ext
as
_
};
use
stm32f4xx_hal
::{
use
stm32f4xx_hal
::{
dwt
::
Dwt
,
gpio
::
Speed
,
gpio
::
Speed
,
gpio
::{
gpio
::{
gpiob
::{
PB10
,
PB12
},
gpiob
::{
PB10
,
PB12
},
gpioc
::{
PC2
,
PC3
},
gpioc
::{
PC2
,
PC3
},
Alternate
,
Output
,
PushPull
,
Alternate
,
Output
,
PushPull
,
},
},
prelude
::
*
,
rcc
::
Clocks
,
spi
::
Spi
,
spi
::
Spi
,
stm32
,
};
};
type
PMW3389T
=
pmw3389
::
Pmw3389
<
type
PMW3389T
=
pmw3389
::
Pmw3389
<
...
@@ -73,15 +68,10 @@ type PMW3389T = pmw3389::Pmw3389<
...
@@ -73,15 +68,10 @@ type PMW3389T = pmw3389::Pmw3389<
PB12
<
Output
<
PushPull
>>
,
PB12
<
Output
<
PushPull
>>
,
>
;
>
;
use
rtt_target
::{
rprintln
,
rtt_init_print
};
use
rtt_target
::{
rprintln
,
rtt_init_print
};
use
stm32f4xx_hal
::
nb
::
block
;
//use rtic_core::Mutex;
use
stm32f4xx_hal
::{
use
stm32f4xx_hal
::{
gpio
::{
gpioa
::
PA7
,
gpioa
::
PA8
,
gpioa
::
PA9
},
gpio
::{
gpioa
::
PA7
,
gpioa
::
PA8
,
gpioa
::
PA9
},
gpio
::{
gpioa
::
PA0
,
gpioa
::
PA1
,
gpioa
::
PA2
,
gpioa
::
PA3
,
gpioa
::
PA4
,
gpioa
::
PA5
,
gpioa
::
PA6
,
gpioa
::
PA10
,
gpioa
::
PA15
,
Input
,
PullUp
},
gpio
::{
gpioa
::
PA0
,
gpioa
::
PA1
,
gpioa
::
PA2
,
gpioa
::
PA3
,
gpioa
::
PA4
,
gpioa
::
PA5
,
gpioa
::
PA6
,
gpioa
::
PA10
,
gpioa
::
PA15
,
Input
,
PullUp
},
//gpio::{gpioc::PC10},
//gpio::{gpioc::PC12},
prelude
::
*
,
};
};
const
OFFSET
:
u32
=
1_000_000
;
const
OFFSET
:
u32
=
1_000_000
;
...
@@ -107,6 +97,7 @@ const APP: () = {
...
@@ -107,6 +97,7 @@ const APP: () = {
scroll_down
:
PA15
<
Input
<
PullUp
>>
,
scroll_down
:
PA15
<
Input
<
PullUp
>>
,
Scaler
:
f32
,
//rtic::Mutex,
Scaler
:
f32
,
//rtic::Mutex,
Counter
:
u8
,
Counter
:
u8
,
Led_Counter
:
u16
,
Scale_modify
:
bool
,
Scale_modify
:
bool
,
}
}
...
@@ -125,23 +116,13 @@ const APP: () = {
...
@@ -125,23 +116,13 @@ const APP: () = {
let
clocks
=
rcc
let
clocks
=
rcc
.cfgr
.cfgr
// .use_hse(8.mhz())
.sysclk
(
48
.mhz
())
.sysclk
(
48
.mhz
())
.pclk1
(
24
.mhz
())
.pclk1
(
24
.mhz
())
.freeze
();
.freeze
();
// assert!(clocks.usbclk_valid());
let
gpioa
=
cx
.device.GPIOA
.split
();
let
gpioa
=
cx
.device.GPIOA
.split
();
// Pull the D+ pin down to send a RESET condition to the USB bus.
//let mut usb_dp = gpioa.pa12.into_push_pull_output();
//usb_dp.set_low().ok();
//delay(clocks.sysclk().0 / 100);
//let usb_dp = usb_dp.into_floating_input();
//cortex_m::asm::delay(100);
//let usb_dm = gpioa.pa11;
let
usb
=
USB
{
let
usb
=
USB
{
usb_global
:
cx
.device.OTG_FS_GLOBAL
,
usb_global
:
cx
.device.OTG_FS_GLOBAL
,
...
@@ -188,12 +169,9 @@ const APP: () = {
...
@@ -188,12 +169,9 @@ const APP: () = {
let
now
=
cx
.start
;
let
now
=
cx
.start
;
cx
.schedule
.toggle_speed
(
now
+
((
OFFSET
))
.cycles
())
.unwrap
();
cx
.schedule
.toggle_speed
(
now
+
((
OFFSET
))
.cycles
())
.unwrap
();
//cx.schedule.toggle(now + ((OFFSET)).cycles()).unwrap();
//let mut led = ;
//led.set_low().ok();
// pass on late resources
// pass on late resources
init
::
LateResources
{
init
::
LateResources
{
//GPIOA: device.GPIOA,
hid
,
hid
,
usb_dev
,
usb_dev
,
led_r
:
gpioa
.pa7
.into_push_pull_output
(),
led_r
:
gpioa
.pa7
.into_push_pull_output
(),
...
@@ -210,6 +188,7 @@ const APP: () = {
...
@@ -210,6 +188,7 @@ const APP: () = {
scroll_down
:
gpioa
.pa15
.into_pull_up_input
(),
scroll_down
:
gpioa
.pa15
.into_pull_up_input
(),
Scaler
:
scaler
,
Scaler
:
scaler
,
Counter
:
0
,
Counter
:
0
,
Led_Counter
:
0
,
Scale_modify
:
scale_modify
,
Scale_modify
:
scale_modify
,
pmw3389
,
pmw3389
,
}
}
...
@@ -226,8 +205,8 @@ const APP: () = {
...
@@ -226,8 +205,8 @@ const APP: () = {
//Increase or lower frequency
//Increase or lower frequency
#[task(resources
=
[
scl_minus,
scl_plus,
Scaler,
Scale_modify]
,
priority
=
1
,
schedule
=
[
toggle_speed
])]
#[task(resources
=
[
scl_minus,
scl_plus,
Scaler,
Scale_modify]
,
priority
=
1
,
schedule
=
[
toggle_speed
])]
fn
toggle_speed
(
mut
cx
:
toggle_speed
::
Context
)
{
fn
toggle_speed
(
mut
cx
:
toggle_speed
::
Context
)
{
let
Scale_modify
=
*
cx
.resources.Scale_modify
;
if
(
cx
.resources.scl_plus
.is_high
()
.unwrap
()
&&
!*
cx
.resources.Scale_modify
)
{
if
cx
.resources.scl_plus
.is_high
()
.unwrap
()
&&
!*
cx
.resources.Scale_modify
{
*
cx
.resources.Scale_modify
=
true
;
*
cx
.resources.Scale_modify
=
true
;
cx
.resources.Scaler
.lock
(|
Scaler
|
{
cx
.resources.Scaler
.lock
(|
Scaler
|
{
*
Scaler
+=
0.1
;
*
Scaler
+=
0.1
;
...
@@ -238,7 +217,7 @@ const APP: () = {
...
@@ -238,7 +217,7 @@ const APP: () = {
*
cx
.resources.Scale_modify
=
false
;
*
cx
.resources.Scale_modify
=
false
;
}
}
}
}
if
(
cx
.resources.scl_minus
.is_high
()
.unwrap
()
&&
!*
cx
.resources.Scale_modify
)
{
if
cx
.resources.scl_minus
.is_high
()
.unwrap
()
&&
!*
cx
.resources.Scale_modify
{
*
cx
.resources.Scale_modify
=
true
;
*
cx
.resources.Scale_modify
=
true
;
cx
.resources.Scaler
.lock
(|
Scaler
|
{
cx
.resources.Scaler
.lock
(|
Scaler
|
{
if
*
Scaler
!=
1.0
&&
!
(
*
Scaler
<
1.0
){
if
*
Scaler
!=
1.0
&&
!
(
*
Scaler
<
1.0
){
...
@@ -285,13 +264,11 @@ const APP: () = {
...
@@ -285,13 +264,11 @@ const APP: () = {
let
wheel_count
=
calculate_scroll
(
up
,
down
,
*
PREV_UP
,
*
PREV_DOWN
);
let
wheel_count
=
calculate_scroll
(
up
,
down
,
*
PREV_UP
,
*
PREV_DOWN
);
*
PREV_UP
=
up
;
*
PREV_UP
=
up
;
*
PREV_DOWN
=
down
;
*
PREV_DOWN
=
down
;
let
mut
POS_X
:
i64
=
0
;
let
mut
POS_Y
:
i64
=
0
;
//LEDs
//LEDs
let
mut
state
:
i8
=
0
;
let
state
:
i8
;
if
*
Led_Counter
==
10
{
if
*
Led_Counter
==
10
00
{
*
Led_Counter
=
0
as
u
8
;
*
Led_Counter
=
0
as
u
16
;
if
l_click
.is_high
()
.unwrap
(){
if
l_click
.is_high
()
.unwrap
(){
if
led_r
.is_high
()
.unwrap
(){
if
led_r
.is_high
()
.unwrap
(){
state
=
1
;
state
=
1
;
...
@@ -300,7 +277,7 @@ const APP: () = {
...
@@ -300,7 +277,7 @@ const APP: () = {
state
=
2
;
state
=
2
;
}
}
}
}
if
l_click
.is_low
()
.unwrap
()
&&
r_click
.is_high
()
.unwrap
(){
else
if
l_click
.is_low
()
.unwrap
()
&&
r_click
.is_high
()
.unwrap
(){
if
led_b
.is_high
()
.unwrap
(){
if
led_b
.is_high
()
.unwrap
(){
state
=
3
;
state
=
3
;
}
}
...
@@ -319,21 +296,19 @@ const APP: () = {
...
@@ -319,21 +296,19 @@ const APP: () = {
toggle_led
(
state
,
led_r
,
led_g
,
led_b
);
toggle_led
(
state
,
led_r
,
led_g
,
led_b
);
}
}
else
{
else
{
*
Led_Counter
=
*
Led_Counter
+
1
as
u8
;
*
Led_Counter
=
*
Led_Counter
+
1
;
}
}
let
(
x
,
y
)
=
cx
.resources.pmw3389
.read_status
()
.unwrap
();
let
(
x
,
y
)
=
cx
.resources.pmw3389
.read_status
()
.unwrap
();
//rprintln!("{} {}", x as i64, y as i64);
POS_X
=
x
as
f32
;
POS_Y
=
y
as
f32
;
let
report
=
PMouseReport
{
let
report
=
PMouseReport
{
buttons
:
((
M1_click
.is_high
()
.unwrap
()
as
u8
)
<<
4
buttons
:
((
M1_click
.is_high
()
.unwrap
()
as
u8
)
<<
4
|
(
M2_click
.is_high
()
.unwrap
()
as
u8
)
<<
3
|
(
M2_click
.is_high
()
.unwrap
()
as
u8
)
<<
3
|
(
w_click
.is_high
()
.unwrap
()
as
u8
)
<<
2
|
(
w_click
.is_high
()
.unwrap
()
as
u8
)
<<
2
|
(
r_click
.is_high
()
.unwrap
()
as
u8
)
<<
1
|
(
r_click
.is_high
()
.unwrap
()
as
u8
)
<<
1
|
(
l_click
.is_high
()
.unwrap
()
as
u8
)),
|
(
l_click
.is_high
()
.unwrap
()
as
u8
)),
x
:
((
-
POS_X
*
*
myScaler
)
as
i8
)
>>
1
,
x
:
((
-
x
as
f32
*
*
myScaler
)
as
i8
)
>>
1
,
y
:
((
-
POS_Y
*
*
myScaler
)
as
i8
)
>>
1
,
y
:
((
-
y
as
f32
*
*
myScaler
)
as
i8
)
>>
1
,
wheel
:
wheel_count
,
wheel
:
wheel_count
,
};
};
hid
.push_input
(
&
report
)
.ok
();
hid
.push_input
(
&
report
)
.ok
();
...
@@ -343,7 +318,6 @@ const APP: () = {
...
@@ -343,7 +318,6 @@ const APP: () = {
}
}
//cx.schedule.toggle(cx.scheduled + ((*myScaler as u32 * OFFSET)).cycles()).unwrap();
}
}
extern
"C"
{
extern
"C"
{
...
@@ -355,9 +329,6 @@ const APP: () = {
...
@@ -355,9 +329,6 @@ const APP: () = {
}
}
};
};
fn
_toggleable_generic
<
E
>
(
led
:
&
mut
dyn
ToggleableOutputPin
<
Error
=
E
>
)
{
led
.toggle
()
.ok
();
}
fn
toggle_led
<
E
>
(
state
:
i8
,
led_r
:
&
mut
dyn
OutputPin
<
Error
=
E
>
,
led_g
:
&
mut
dyn
OutputPin
<
Error
=
E
>
,
led_b
:
&
mut
dyn
OutputPin
<
Error
=
E
>
)
{
fn
toggle_led
<
E
>
(
state
:
i8
,
led_r
:
&
mut
dyn
OutputPin
<
Error
=
E
>
,
led_g
:
&
mut
dyn
OutputPin
<
Error
=
E
>
,
led_b
:
&
mut
dyn
OutputPin
<
Error
=
E
>
)
{
if
state
==
1
{
if
state
==
1
{
...
...
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