Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DC motor driver hat
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
Container 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
Software
DC motor driver hat
Commits
e63eed4c
Commit
e63eed4c
authored
8 months ago
by
Samuel Tardieu
Browse files
Options
Downloads
Patches
Plain Diff
Ignore malformed messages
parent
f4579f24
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
controller/src/logic.rs
+6
-6
6 additions, 6 deletions
controller/src/logic.rs
i2c2-target/src/lib.rs
+21
-3
21 additions, 3 deletions
i2c2-target/src/lib.rs
with
27 additions
and
9 deletions
controller/src/logic.rs
+
6
−
6
View file @
e63eed4c
...
@@ -57,7 +57,7 @@ fn handle_command(command: &[u8], response: &mut Deque<u8, MESSAGE_SIZE>) {
...
@@ -57,7 +57,7 @@ fn handle_command(command: &[u8], response: &mut Deque<u8, MESSAGE_SIZE>) {
[
WHO_AM_I
,
..
]
=>
{
[
WHO_AM_I
,
..
]
=>
{
let
_
=
response
.push_back
(
0x57
);
let
_
=
response
.push_back
(
0x57
);
}
}
&
[
MAX_MOTOR_PERCENTAGE
,
p
,
..
]
=>
{
&
[
MAX_MOTOR_PERCENTAGE
,
p
]
=>
{
if
(
1
..=
100
)
.contains
(
&
p
)
{
if
(
1
..=
100
)
.contains
(
&
p
)
{
state
.max_motor_percentage
=
p
;
state
.max_motor_percentage
=
p
;
}
else
{
}
else
{
...
@@ -67,7 +67,7 @@ fn handle_command(command: &[u8], response: &mut Deque<u8, MESSAGE_SIZE>) {
...
@@ -67,7 +67,7 @@ fn handle_command(command: &[u8], response: &mut Deque<u8, MESSAGE_SIZE>) {
[
MAX_MOTOR_PERCENTAGE
]
=>
{
[
MAX_MOTOR_PERCENTAGE
]
=>
{
let
_
=
response
.push_back
(
state
.max_motor_percentage
);
let
_
=
response
.push_back
(
state
.max_motor_percentage
);
}
}
[
MOTOR_SPEED
,
ms
@
..
]
if
ms
.len
()
>
=
2
=>
{
[
MOTOR_SPEED
,
ms
@
..
]
if
ms
.len
()
=
=
2
=>
{
let
(
max_pwm
,
mmp
)
=
(
let
(
max_pwm
,
mmp
)
=
(
state
.motors
.max_pwm
()
as
i32
,
state
.motors
.max_pwm
()
as
i32
,
i32
::
from
(
state
.max_motor_percentage
),
i32
::
from
(
state
.max_motor_percentage
),
...
@@ -93,12 +93,12 @@ fn handle_command(command: &[u8], response: &mut Deque<u8, MESSAGE_SIZE>) {
...
@@ -93,12 +93,12 @@ fn handle_command(command: &[u8], response: &mut Deque<u8, MESSAGE_SIZE>) {
}
}
}
}
}
}
[
MOTOR_SPEED
,
..
]
=>
{
[
MOTOR_SPEED
]
=>
{
for
&
s
in
&
state
.motor_speed
{
for
&
s
in
&
state
.motor_speed
{
let
_
=
response
.push_back
(
s
);
let
_
=
response
.push_back
(
s
);
}
}
}
}
[
ENCODER_TICKS
,
..
]
=>
{
[
ENCODER_TICKS
]
=>
{
let
(
left
,
right
)
=
state
.encoders
.ticks
();
let
(
left
,
right
)
=
state
.encoders
.ticks
();
let
(
left
,
right
)
=
(
left
.to_le_bytes
(),
right
.to_le_bytes
());
let
(
left
,
right
)
=
(
left
.to_le_bytes
(),
right
.to_le_bytes
());
let
_
=
response
.push_back
(
left
[
0
]);
let
_
=
response
.push_back
(
left
[
0
]);
...
@@ -106,8 +106,8 @@ fn handle_command(command: &[u8], response: &mut Deque<u8, MESSAGE_SIZE>) {
...
@@ -106,8 +106,8 @@ fn handle_command(command: &[u8], response: &mut Deque<u8, MESSAGE_SIZE>) {
let
_
=
response
.push_back
(
right
[
0
]);
let
_
=
response
.push_back
(
right
[
0
]);
let
_
=
response
.push_back
(
right
[
1
]);
let
_
=
response
.push_back
(
right
[
1
]);
}
}
&
[
idx
,
..
]
=>
{
&
[
_
,
..
]
=>
{
defmt
::
warn!
(
"unknown
register
{:#04x}"
,
idx
);
defmt
::
warn!
(
"unknown
command or args
{:#04x}"
,
command
);
}
}
&
[]
=>
{
&
[]
=>
{
defmt
::
warn!
(
"received empty command"
);
defmt
::
warn!
(
"received empty command"
);
...
...
This diff is collapsed.
Click to expand it.
i2c2-target/src/lib.rs
+
21
−
3
View file @
e63eed4c
...
@@ -110,9 +110,15 @@ impl I2C2 {
...
@@ -110,9 +110,15 @@ impl I2C2 {
let
af_num
=
SclPin
::
af_num
(
&
pb10
);
let
af_num
=
SclPin
::
af_num
(
&
pb10
);
assert_eq!
(
af_num
,
SdaPin
::
af_num
(
&
pb11
));
assert_eq!
(
af_num
,
SdaPin
::
af_num
(
&
pb11
));
let
mut
pb10
=
Flex
::
new
(
pb10
);
let
mut
pb10
=
Flex
::
new
(
pb10
);
pb10
.set_as_af_unchecked
(
af_num
,
AfType
::
output
(
OutputType
::
OpenDrain
,
Speed
::
Low
));
pb10
.set_as_af_unchecked
(
af_num
,
AfType
::
output
(
OutputType
::
OpenDrain
,
Speed
::
VeryHigh
),
);
let
mut
pb11
=
Flex
::
new
(
pb11
);
let
mut
pb11
=
Flex
::
new
(
pb11
);
pb11
.set_as_af_unchecked
(
af_num
,
AfType
::
output
(
OutputType
::
OpenDrain
,
Speed
::
Low
));
pb11
.set_as_af_unchecked
(
af_num
,
AfType
::
output
(
OutputType
::
OpenDrain
,
Speed
::
VeryHigh
),
);
// Turn I2C2 clock on
// Turn I2C2 clock on
pac
::
RCC
.apb1enr
()
.modify
(|
w
|
w
.set_i2c2en
(
true
));
pac
::
RCC
.apb1enr
()
.modify
(|
w
|
w
.set_i2c2en
(
true
));
...
@@ -131,6 +137,7 @@ impl I2C2 {
...
@@ -131,6 +137,7 @@ impl I2C2 {
// Enable I2C2
// Enable I2C2
pac
::
I2C2
.cr1
()
.write
(|
w
|
{
pac
::
I2C2
.cr1
()
.write
(|
w
|
{
w
.set_pe
(
true
);
w
.set_pe
(
true
);
w
.set_nostretch
(
false
);
});
});
// Set ack generation
// Set ack generation
pac
::
I2C2
.cr1
()
.modify
(|
w
|
{
pac
::
I2C2
.cr1
()
.modify
(|
w
|
{
...
@@ -162,11 +169,19 @@ unsafe fn I2C2_EV() {
...
@@ -162,11 +169,19 @@ unsafe fn I2C2_EV() {
pac
::
I2C2
.cr1
()
.read
()
.0
,
pac
::
I2C2
.cr1
()
.read
()
.0
,
pac
::
I2C2
.cr2
()
.read
()
.0
pac
::
I2C2
.cr2
()
.read
()
.0
);
);
if
sr1
.ovr
()
{
defmt
::
error!
(
"overrun detected"
);
pac
::
I2C2
.sr1
()
.modify
(|
w
|
w
.set_ovr
(
false
));
}
let
state
=
unsafe
{
STATE
.as_mut
()
.unwrap
()
};
let
state
=
unsafe
{
STATE
.as_mut
()
.unwrap
()
};
if
sr1
.rxne
()
{
if
sr1
.rxne
()
{
defmt
::
trace!
(
"I2C2_EV RXNE"
);
defmt
::
trace!
(
"I2C2_EV RXNE"
);
let
b
=
pac
::
I2C2
.dr
()
.read
()
.0
as
u8
;
let
b
=
pac
::
I2C2
.dr
()
.read
()
.0
as
u8
;
defmt
::
trace!
(
"received byte {:#04x}"
,
&
b
);
defmt
::
trace!
(
"received byte {:#04x} - sr1 is now {:#06x}"
,
&
b
,
pac
::
I2C2
.sr1
()
.read
()
.0
);
if
state
.incoming
.push
(
b
)
.is_err
()
{
if
state
.incoming
.push
(
b
)
.is_err
()
{
defmt
::
error!
(
"I2C byte has overfilled the buffer"
);
defmt
::
error!
(
"I2C byte has overfilled the buffer"
);
}
}
...
@@ -215,5 +230,8 @@ unsafe fn I2C2_EV() {
...
@@ -215,5 +230,8 @@ unsafe fn I2C2_EV() {
}
else
{
}
else
{
state
.set_write_in_progress
();
state
.set_write_in_progress
();
}
}
// Read DR to avoid overrun
pac
::
I2C2
.dr
()
.read
();
defmt
::
trace!
(
"sr1 is now {:#06x}"
,
pac
::
I2C2
.sr1
()
.read
()
.0
);
}
}
}
}
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