Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
e7020e_2021
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
Deux Babiri Futari
e7020e_2021
Commits
50712777
Commit
50712777
authored
4 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
now with burst
parent
1a5afe5e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/pmw3389.rs
+38
-1
38 additions, 1 deletion
examples/pmw3389.rs
src/pmw3389.rs
+29
-25
29 additions, 25 deletions
src/pmw3389.rs
with
67 additions
and
26 deletions
examples/pmw3389.rs
+
38
−
1
View file @
50712777
...
@@ -10,7 +10,10 @@ use panic_halt as _;
...
@@ -10,7 +10,10 @@ use panic_halt as _;
use
rtic
::
cyccnt
::{
Instant
,
U32Ext
as
_
};
use
rtic
::
cyccnt
::{
Instant
,
U32Ext
as
_
};
use
stm32f4xx_hal
::{
dwt
::
Dwt
,
gpio
::
Speed
,
prelude
::
*
,
rcc
::
Clocks
,
spi
::
Spi
,
stm32
};
use
stm32f4xx_hal
::{
dwt
::
Dwt
,
gpio
::
Speed
,
prelude
::
*
,
rcc
::
Clocks
,
spi
::
Spi
,
stm32
};
use
app
::{
pmw3389
,
DwtDelay
};
use
app
::{
pmw3389
::{
self
,
Register
},
DwtDelay
,
};
use
rtt_target
::{
rprint
,
rprintln
,
rtt_init_print
};
use
rtt_target
::{
rprint
,
rprintln
,
rtt_init_print
};
//use crate::hal::gpio::{gpioa::PA0, Edge, Input, PullDown};
//use crate::hal::gpio::{gpioa::PA0, Edge, Input, PullDown};
...
@@ -93,6 +96,40 @@ const APP: () = {
...
@@ -93,6 +96,40 @@ const APP: () = {
let
mut
pmw3389
=
pmw3389
::
Pmw3389
::
new
(
spi
,
cs
,
delay
)
.unwrap
();
let
mut
pmw3389
=
pmw3389
::
Pmw3389
::
new
(
spi
,
cs
,
delay
)
.unwrap
();
let
mut
delay
=
DwtDelay
::
new
(
&
mut
core
.DWT
,
clocks
);
// loop {
// pmw3389.write_register(Register::Motion, 0x01).ok();
// let motion = pmw3389.read_register(Register::Motion).unwrap();
// let xl = pmw3389.read_register(Register::DeltaXL).unwrap();
// let xh = pmw3389.read_register(Register::DeltaXH).unwrap();
// let yl = pmw3389.read_register(Register::DeltaYL).unwrap();
// let yh = pmw3389.read_register(Register::DeltaYH).unwrap();
// let x = (xl as u16 + (xh as u16) << 8) as i16;
// let y = (yl as u16 + (yh as u16) << 8) as i16;
// let surface = motion & 0x08;
// let motion_detect = motion & 0x80;
// rprintln!(
// "motion {}, surface {}, (x, y) {:?}",
// motion_detect,
// surface,
// (x, y),
// );
// delay.delay_ms(200);
// }
// set in burst mode
pmw3389
.write_register
(
Register
::
MotionBurst
,
0x00
);
loop
{
pmw3389
.read_status
()
.unwrap
();
delay
.delay_ms
(
200
);
}
let
id
=
pmw3389
.product_id
()
.unwrap
();
let
id
=
pmw3389
.product_id
()
.unwrap
();
rprintln!
(
"id {}"
,
id
);
rprintln!
(
"id {}"
,
id
);
...
...
This diff is collapsed.
Click to expand it.
src/pmw3389.rs
+
29
−
25
View file @
50712777
...
@@ -181,29 +181,29 @@ where
...
@@ -181,29 +181,29 @@ where
let
srom_id
=
pmw3389
.read_register
(
Register
::
SROMId
)
?
;
let
srom_id
=
pmw3389
.read_register
(
Register
::
SROMId
)
?
;
rprintln!
(
"srom_id {}, 0x{:x}"
,
srom_id
,
srom_id
);
rprintln!
(
"srom_id {}, 0x{:x}"
,
srom_id
,
srom_id
);
loop
{
//
loop {
pmw3389
.write_register
(
Register
::
Motion
,
0x01
)
?
;
//
pmw3389.write_register(Register::Motion, 0x01)?;
let
motion
=
pmw3389
.read_register
(
Register
::
Motion
)
?
;
//
let motion = pmw3389.read_register(Register::Motion)?;
let
xl
=
pmw3389
.read_register
(
Register
::
DeltaXL
)
?
;
//
let xl = pmw3389.read_register(Register::DeltaXL)?;
let
xh
=
pmw3389
.read_register
(
Register
::
DeltaXH
)
?
;
//
let xh = pmw3389.read_register(Register::DeltaXH)?;
let
yl
=
pmw3389
.read_register
(
Register
::
DeltaYL
)
?
;
//
let yl = pmw3389.read_register(Register::DeltaYL)?;
let
yh
=
pmw3389
.read_register
(
Register
::
DeltaYH
)
?
;
//
let yh = pmw3389.read_register(Register::DeltaYH)?;
let
x
=
(
xl
as
u16
+
(
xh
as
u16
)
<<
8
)
as
i16
;
//
let x = (xl as u16 + (xh as u16) << 8) as i16;
let
y
=
(
yl
as
u16
+
(
yh
as
u16
)
<<
8
)
as
i16
;
//
let y = (yl as u16 + (yh as u16) << 8) as i16;
let
surface
=
motion
&
0x08
;
//
let surface = motion & 0x08;
let
motion_detect
=
motion
&
0x80
;
//
let motion_detect = motion & 0x80;
rprintln!
(
//
rprintln!(
"motion {}, surface {}, (x, y) {:?}"
,
//
"motion {}, surface {}, (x, y) {:?}",
motion_detect
,
//
motion_detect,
surface
,
//
surface,
(
x
,
y
),
//
(x, y),
);
//
);
pmw3389
.delay
.delay_ms
(
200
);
//
pmw3389.delay.delay_ms(200);
}
//
}
// self.spi.transfer(&mut [Register::MotionBurst.addr()])?;
// self.spi.transfer(&mut [Register::MotionBurst.addr()])?;
// self.delay.delay_ms(35); // waits for tSRAD
// self.delay.delay_ms(35); // waits for tSRAD
...
@@ -213,7 +213,7 @@ where
...
@@ -213,7 +213,7 @@ where
// pmw3389.delay.delay_ms(10);
// pmw3389.delay.delay_ms(10);
// }
// }
//
Ok(pmw3389)
Ok
(
pmw3389
)
}
}
pub
fn
read_register
(
&
mut
self
,
reg
:
Register
)
->
Result
<
u8
,
E
>
{
pub
fn
read_register
(
&
mut
self
,
reg
:
Register
)
->
Result
<
u8
,
E
>
{
...
@@ -269,10 +269,14 @@ where
...
@@ -269,10 +269,14 @@ where
}
}
/// Read status
/// Read status
pub
fn
read_status
(
&
mut
self
,
itm
:
&
mut
stm32
::
ITM
)
->
Result
<
(),
E
>
{
pub
fn
read_status
(
&
mut
self
)
->
Result
<
(),
E
>
{
self
.com_begin
();
self
.com_begin
();
// self.write_register(Register::Motion, 0x01)?;
self
.spi
.transfer
(
&
mut
[
Register
::
MotionBurst
.addr
()])
?
;
self
.spi
.transfer
(
&
mut
[
Register
::
MotionBurst
.addr
()])
?
;
// self.write_register(Register::MotionBurst, 0x00);
self
.delay
.delay_us
(
35
);
// waits for tSRAD
self
.delay
.delay_us
(
35
);
// waits for tSRAD
// read burst buffer
// read burst buffer
...
...
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