Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
stm32f4-hal
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
Model registry
Operate
Environments
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
Per Lindgren
stm32f4-hal
Commits
e5385e11
Commit
e5385e11
authored
7 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
rtfm-blinky systick
parent
5d5fb65b
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/lib.rs
+1
-1
1 addition, 1 deletion
src/lib.rs
src/timer.rs
+61
-1
61 additions, 1 deletion
src/timer.rs
with
62 additions
and
2 deletions
src/lib.rs
+
1
−
1
View file @
e5385e11
...
...
@@ -37,6 +37,6 @@ pub mod rcc;
pub
mod
serial
;
// pub mod spi;
pub
mod
time
;
//
pub mod timer;
pub
mod
timer
;
pub
mod
led
;
This diff is collapsed.
Click to expand it.
src/timer.rs
+
61
−
1
View file @
e5385e11
//! Timers
use
cortex_m
::
peripheral
::
SYST
;
use
cortex_m
::
peripheral
::
syst
::
SystClkSource
;
use
cast
::{
u16
,
u32
};
use
hal
::
timer
::{
CountDown
,
Periodic
};
use
nb
;
use
stm32f
30
x
::{
TIM2
,
TIM3
,
TIM4
,
TIM6
,
TIM7
};
use
stm32f
4
x
::{
TIM2
,
TIM3
,
TIM4
,
TIM6
,
TIM7
};
use
rcc
::{
APB1
,
Clocks
};
use
time
::
Hertz
;
...
...
@@ -21,6 +23,64 @@ pub enum Event {
TimeOut
,
}
impl
Timer
<
SYST
>
{
/// start systic timer
pub
fn
syst
<
T
>
(
mut
syst
:
SYST
,
timeout
:
T
,
clocks
:
Clocks
)
->
Self
where
T
:
Into
<
Hertz
>
,
{
syst
.set_clock_source
(
SystClkSource
::
Core
);
let
mut
timer
=
Timer
{
tim
:
syst
,
clocks
:
clocks
,
timeout
:
Hertz
(
0
),
};
timer
.start
(
timeout
);
timer
}
/// Starts listening for an `event`
pub
fn
listen
(
&
mut
self
,
event
:
Event
)
{
match
event
{
Event
::
TimeOut
=>
self
.tim
.enable_interrupt
(),
}
}
/// Stops listening for an `event`
pub
fn
unlisten
(
&
mut
self
,
event
:
Event
)
{
match
event
{
Event
::
TimeOut
=>
self
.tim
.disable_interrupt
(),
}
}
}
impl
CountDown
for
Timer
<
SYST
>
{
type
Time
=
Hertz
;
fn
start
<
T
>
(
&
mut
self
,
timeout
:
T
)
where
T
:
Into
<
Hertz
>
,
{
let
rvr
=
self
.clocks
.sysclk
()
.0
/
timeout
.into
()
.0
-
1
;
assert!
(
rvr
<
(
1
<<
24
));
self
.tim
.set_reload
(
rvr
);
self
.tim
.clear_current
();
self
.tim
.enable_counter
();
}
fn
wait
(
&
mut
self
)
->
nb
::
Result
<
(),
!>
{
if
self
.tim
.has_wrapped
()
{
Ok
(())
}
else
{
Err
(
nb
::
Error
::
WouldBlock
)
}
}
}
impl
Periodic
for
Timer
<
SYST
>
{}
macro_rules!
hal
{
(
$
(
$TIM:ident
:
(
$tim:ident
,
$timXen:ident
,
$timXrst:ident
),)
+
)
=>
{
$
(
...
...
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