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
1cd99b24
Commit
1cd99b24
authored
8 months ago
by
Samuel Tardieu
Browse files
Options
Downloads
Patches
Plain Diff
Prefix commands with CMD_
parent
fa9ac741
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
controller/src/logic.rs
+20
-20
20 additions, 20 deletions
controller/src/logic.rs
with
20 additions
and
20 deletions
controller/src/logic.rs
+
20
−
20
View file @
1cd99b24
...
@@ -159,14 +159,14 @@ fn i2c_callback(command: &[u8], response: &mut Deque<u8, MESSAGE_SIZE>) {
...
@@ -159,14 +159,14 @@ fn i2c_callback(command: &[u8], response: &mut Deque<u8, MESSAGE_SIZE>) {
}
}
}
}
const
FIRMWARE_VERSION
:
u8
=
0x08
;
const
CMD_
FIRMWARE_VERSION
:
u8
=
0x08
;
const
WHO_AM_I
:
u8
=
0x0f
;
const
CMD_
WHO_AM_I
:
u8
=
0x0f
;
const
PWM_FREQUENCY
:
u8
=
0x10
;
const
CMD_
PWM_FREQUENCY
:
u8
=
0x10
;
const
MAX_MOTOR_PERCENTAGE
:
u8
=
0x11
;
const
CMD_
MAX_MOTOR_PERCENTAGE
:
u8
=
0x11
;
const
MOTOR_SHUTDOWN_TIMEOUT
:
u8
=
0x28
;
const
CMD_
MOTOR_SHUTDOWN_TIMEOUT
:
u8
=
0x28
;
const
MOTOR_SPEED
:
u8
=
0x30
;
const
CMD_
MOTOR_SPEED
:
u8
=
0x30
;
const
ENCODER_TICKS
:
u8
=
0x32
;
const
CMD_
ENCODER_TICKS
:
u8
=
0x32
;
const
STATUS
:
u8
=
0x36
;
const
CMD_
STATUS
:
u8
=
0x36
;
include!
(
concat!
(
env!
(
"OUT_DIR"
),
"/version.rs"
));
include!
(
concat!
(
env!
(
"OUT_DIR"
),
"/version.rs"
));
...
@@ -177,15 +177,15 @@ fn process_command(
...
@@ -177,15 +177,15 @@ fn process_command(
)
->
bool
{
)
->
bool
{
defmt
::
trace!
(
"Processing command {:?}"
,
command
);
defmt
::
trace!
(
"Processing command {:?}"
,
command
);
match
command
{
match
command
{
[
FIRMWARE_VERSION
]
=>
{
[
CMD_
FIRMWARE_VERSION
]
=>
{
for
b
in
PKG_VERSION
{
for
b
in
PKG_VERSION
{
response
.push_back
(
b
)
.unwrap
();
response
.push_back
(
b
)
.unwrap
();
}
}
}
}
[
WHO_AM_I
,
..
]
=>
{
[
CMD_
WHO_AM_I
,
..
]
=>
{
response
.push_back
(
0x57
)
.unwrap
();
response
.push_back
(
0x57
)
.unwrap
();
}
}
&
[
PWM_FREQUENCY
,
a
,
b
,
c
]
=>
{
&
[
CMD_
PWM_FREQUENCY
,
a
,
b
,
c
]
=>
{
let
f
=
u32
::
from_le_bytes
([
a
,
b
,
c
,
0
]);
let
f
=
u32
::
from_le_bytes
([
a
,
b
,
c
,
0
]);
if
(
1
..=
100_000
)
.contains
(
&
f
)
{
if
(
1
..=
100_000
)
.contains
(
&
f
)
{
state
.motors
.set_frequency
(
hz
(
f
));
state
.motors
.set_frequency
(
hz
(
f
));
...
@@ -194,13 +194,13 @@ fn process_command(
...
@@ -194,13 +194,13 @@ fn process_command(
return
false
;
return
false
;
}
}
}
}
[
PWM_FREQUENCY
]
=>
{
[
CMD_
PWM_FREQUENCY
]
=>
{
let
freq
=
state
.motors
.get_frequency
()
.0
;
let
freq
=
state
.motors
.get_frequency
()
.0
;
for
&
b
in
&
freq
.to_le_bytes
()[
..
3
]
{
for
&
b
in
&
freq
.to_le_bytes
()[
..
3
]
{
response
.push_back
(
b
)
.unwrap
();
response
.push_back
(
b
)
.unwrap
();
}
}
}
}
&
[
MAX_MOTOR_PERCENTAGE
,
p
]
=>
{
&
[
CMD_
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
{
...
@@ -208,17 +208,17 @@ fn process_command(
...
@@ -208,17 +208,17 @@ fn process_command(
return
false
;
return
false
;
}
}
}
}
[
MAX_MOTOR_PERCENTAGE
]
=>
{
[
CMD_
MAX_MOTOR_PERCENTAGE
]
=>
{
response
.push_back
(
state
.max_motor_percentage
)
.unwrap
();
response
.push_back
(
state
.max_motor_percentage
)
.unwrap
();
}
}
[
MOTOR_SPEED
,
ms
@
..
]
if
ms
.len
()
==
2
=>
{
[
CMD_
MOTOR_SPEED
,
ms
@
..
]
if
ms
.len
()
==
2
=>
{
state
.set_motor_speed
([
ms
[
0
],
ms
[
1
]]);
state
.set_motor_speed
([
ms
[
0
],
ms
[
1
]]);
}
}
[
MOTOR_SPEED
]
=>
{
[
CMD_
MOTOR_SPEED
]
=>
{
response
.push_back
(
state
.motor_speed
[
0
])
.unwrap
();
response
.push_back
(
state
.motor_speed
[
0
])
.unwrap
();
response
.push_back
(
state
.motor_speed
[
1
])
.unwrap
();
response
.push_back
(
state
.motor_speed
[
1
])
.unwrap
();
}
}
&
[
MOTOR_SHUTDOWN_TIMEOUT
,
ticks
]
=>
{
&
[
CMD_
MOTOR_SHUTDOWN_TIMEOUT
,
ticks
]
=>
{
if
(
1
..=
100
)
.contains
(
&
ticks
)
{
if
(
1
..=
100
)
.contains
(
&
ticks
)
{
WATCHDOG_TICKS
.store
(
ticks
,
Ordering
::
Relaxed
);
WATCHDOG_TICKS
.store
(
ticks
,
Ordering
::
Relaxed
);
}
else
{
}
else
{
...
@@ -226,12 +226,12 @@ fn process_command(
...
@@ -226,12 +226,12 @@ fn process_command(
return
false
;
return
false
;
}
}
}
}
[
MOTOR_SHUTDOWN_TIMEOUT
]
=>
{
[
CMD_
MOTOR_SHUTDOWN_TIMEOUT
]
=>
{
response
response
.push_back
(
WATCHDOG_TICKS
.load
(
Ordering
::
Relaxed
))
.push_back
(
WATCHDOG_TICKS
.load
(
Ordering
::
Relaxed
))
.unwrap
();
.unwrap
();
}
}
[
ENCODER_TICKS
]
=>
{
[
CMD_
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
());
response
.push_back
(
left
[
0
])
.unwrap
();
response
.push_back
(
left
[
0
])
.unwrap
();
...
@@ -239,7 +239,7 @@ fn process_command(
...
@@ -239,7 +239,7 @@ fn process_command(
response
.push_back
(
right
[
0
])
.unwrap
();
response
.push_back
(
right
[
0
])
.unwrap
();
response
.push_back
(
right
[
1
])
.unwrap
();
response
.push_back
(
right
[
1
])
.unwrap
();
}
}
[
STATUS
]
=>
{
[
CMD_
STATUS
]
=>
{
response
.push_back
(
u8
::
from
(
state
.is_moving
()))
.unwrap
();
response
.push_back
(
u8
::
from
(
state
.is_moving
()))
.unwrap
();
}
}
_
=>
{
_
=>
{
...
...
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