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
a412a7d3
Commit
a412a7d3
authored
8 months ago
by
Samuel Tardieu
Browse files
Options
Downloads
Patches
Plain Diff
Separate blinker into its own module and add pattern updater
parent
a604a98e
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Cargo.lock
+1
-0
1 addition, 0 deletions
Cargo.lock
controller/Cargo.toml
+1
-0
1 addition, 0 deletions
controller/Cargo.toml
controller/src/blinker.rs
+49
-0
49 additions, 0 deletions
controller/src/blinker.rs
controller/src/main.rs
+3
-37
3 additions, 37 deletions
controller/src/main.rs
with
54 additions
and
37 deletions
Cargo.lock
+
1
−
0
View file @
a412a7d3
...
...
@@ -138,6 +138,7 @@ dependencies = [
"defmt-rtt",
"embassy-executor",
"embassy-stm32",
"embassy-sync",
"embassy-time",
"heapless",
"i2c2-target",
...
...
This diff is collapsed.
Click to expand it.
controller/Cargo.toml
+
1
−
0
View file @
a412a7d3
...
...
@@ -12,6 +12,7 @@ defmt = "0.3.8"
defmt-rtt
=
"0.4.1"
embassy-executor
=
{
git
=
"https://github.com/embassy-rs/embassy"
,
features
=
[
"arch-cortex-m"
,
"executor-thread"
,
"defmt"
,
"integrated-timers"
]
}
embassy-stm32
=
{
git
=
"https://github.com/embassy-rs/embassy"
,
features
=
[
"defmt"
,
"stm32f103c8"
,
"unstable-pac"
,
"time-driver-tim4"
,
"memory-x"
]
}
embassy-sync
=
{
git
=
"https://github.com/embassy-rs/embassy"
,
features
=
[
"defmt"
]
}
embassy-time
=
{
git
=
"https://github.com/embassy-rs/embassy"
,
features
=
[
"defmt"
,
"defmt-timestamp-uptime"
,
"tick-hz-32_768"
]
}
heapless
=
"0.8.0"
i2c2-target
=
{
path
=
"../i2c2-target"
}
...
...
This diff is collapsed.
Click to expand it.
controller/src/blinker.rs
0 → 100644
+
49
−
0
View file @
a412a7d3
use
embassy_stm32
::{
gpio
::{
Level
,
Output
,
Speed
},
peripherals
::
PB15
,
};
use
embassy_sync
::{
blocking_mutex
::
raw
::
CriticalSectionRawMutex
,
signal
::
Signal
};
use
embassy_time
::
Timer
;
static
BLINK_PATTERN
:
Signal
<
CriticalSectionRawMutex
,
&
'static
str
>
=
Signal
::
new
();
pub
fn
set_blink_pattern
(
pattern
:
&
'static
str
)
{
BLINK_PATTERN
.signal
(
pattern
);
}
#[embassy_executor::task]
pub
async
fn
blink
(
pin
:
PB15
,
initial_pattern
:
&
'static
str
)
{
let
mut
led
=
Output
::
new
(
pin
,
Level
::
High
,
Speed
::
Low
);
let
mut
pattern
=
initial_pattern
;
loop
{
if
let
Some
(
new_pattern
)
=
BLINK_PATTERN
.try_take
()
{
pattern
=
new_pattern
;
}
for
b
in
pattern
.chars
()
{
match
b
{
' '
=>
{
Timer
::
after_millis
(
200
)
.await
;
}
'.'
=>
{
led
.toggle
();
Timer
::
after_millis
(
150
)
.await
;
led
.toggle
();
Timer
::
after_millis
(
200
)
.await
;
}
'-'
=>
{
led
.toggle
();
Timer
::
after_millis
(
300
)
.await
;
led
.toggle
();
Timer
::
after_millis
(
200
)
.await
;
}
_
=>
{
defmt
::
error!
(
"unknown pattern letter {}"
,
b
);
led
.toggle
();
Timer
::
after_secs
(
5
)
.await
;
led
.toggle
();
}
}
}
Timer
::
after_secs
(
1
)
.await
;
}
}
This diff is collapsed.
Click to expand it.
controller/src/main.rs
+
3
−
37
View file @
a412a7d3
...
...
@@ -5,17 +5,16 @@ use crate::{encoders::Encoders, tb6612fng::Tb6612fng};
use
defmt_rtt
as
_
;
use
embassy_executor
::
Spawner
;
use
embassy_stm32
::{
gpio
::{
Level
,
Output
,
Speed
},
interrupt
::
Priority
,
pac
,
peripherals
::
{
PB15
,
RCC
}
,
peripherals
::
RCC
,
rcc
::{
APBPrescaler
,
Hse
,
HseMode
,
Pll
,
PllMul
,
PllPreDiv
,
PllSource
,
Sysclk
},
time
::{
khz
,
mhz
},
Config
,
};
use
embassy_time
::
Timer
;
use
panic_probe
as
_
;
pub
mod
blinker
;
mod
encoders
;
mod
logic
;
mod
tb6612fng
;
...
...
@@ -88,7 +87,7 @@ async fn main(spawner: Spawner) {
);
spawner
.spawn
(
blink
(
p
.PB15
,
blink_pattern
(
reset_cause
)))
.spawn
(
blinker
::
blink
(
p
.PB15
,
blink_pattern
(
reset_cause
)))
.unwrap
();
let
motors
=
Tb6612fng
::
new
(
...
...
@@ -111,36 +110,3 @@ async fn main(spawner: Spawner) {
.spawn
(
logic
::
start_i2c_target
(
i2c2
,
motors
,
encoders
,
p
.WWDG
))
.unwrap
();
}
#[embassy_executor::task]
async
fn
blink
(
pin
:
PB15
,
pattern
:
&
'static
str
)
{
let
mut
led
=
Output
::
new
(
pin
,
Level
::
High
,
Speed
::
Low
);
loop
{
for
b
in
pattern
.chars
()
{
match
b
{
' '
=>
{
Timer
::
after_millis
(
200
)
.await
;
}
'.'
=>
{
led
.toggle
();
Timer
::
after_millis
(
150
)
.await
;
led
.toggle
();
Timer
::
after_millis
(
200
)
.await
;
}
'-'
=>
{
led
.toggle
();
Timer
::
after_millis
(
300
)
.await
;
led
.toggle
();
Timer
::
after_millis
(
200
)
.await
;
}
_
=>
{
defmt
::
error!
(
"unknown pattern letter {}"
,
b
);
led
.toggle
();
Timer
::
after_secs
(
5
)
.await
;
led
.toggle
();
}
}
}
Timer
::
after_secs
(
1
)
.await
;
}
}
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