Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
f4
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
f4
Commits
158bfaa0
Commit
158bfaa0
authored
7 years ago
by
Johannes Sjölund
Browse files
Options
Downloads
Patches
Plain Diff
Refactored usart print macro a bit
parent
1ce91397
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/serial.rs
+19
-22
19 additions, 22 deletions
src/serial.rs
with
19 additions
and
22 deletions
src/serial.rs
+
19
−
22
View file @
158bfaa0
...
...
@@ -295,9 +295,7 @@ where
}
else
if
sr
.rxne
()
.bit_is_set
()
{
// NOTE(read_volatile) the register is 9 bits big but we'll only
// work with the first 8 bits
Ok
(
unsafe
{
ptr
::
read_volatile
(
&
usart2
.dr
as
*
const
_
as
*
const
u8
)
})
Ok
(
unsafe
{
ptr
::
read_volatile
(
&
usart2
.dr
as
*
const
_
as
*
const
u8
)
})
}
else
{
Err
(
nb
::
Error
::
WouldBlock
)
}
...
...
@@ -432,14 +430,7 @@ impl<'a> fmt::Write for U8Writer<'a> {
/// outside rtfm tasks.
#[macro_export]
macro_rules!
uprint
{
(
$T:ident
,
$USART:expr
,
$DMA:expr
,
$TX_BUFFER:expr
,
$s:expr
)
=>
{
use
core
::
fmt
::
Write
;
// Claim the transmit buffer and write a string literal into it
$TX_BUFFER
.claim_mut
(
$T
,
|
tx
,
_
|
{
let
len
=
(
*
tx
)
.deref
()
.borrow
()
.len
();
let
buf
=
&
mut
(
*
tx
)
.deref
()
.borrow_mut
();
write!
(
U8Writer
::
new
(
&
mut
buf
[
..
len
]),
$s
)
.unwrap
();
});
(
$T:ident
,
$USART:expr
,
$DMA:expr
,
$TX_BUFFER:expr
)
=>
{
// Transmit the contents of the buffer using DMA
$TX_BUFFER
.claim
(
$T
,
|
tx
,
t
|
{
$DMA
.claim
(
t
,
|
dma
,
t
|
{
...
...
@@ -450,22 +441,28 @@ macro_rules! uprint {
});
});
};
(
$T:ident
,
$USART:expr
,
$DMA:expr
,
$TX_BUFFER:expr
,
$s:expr
)
=>
{
use
rtfm
::{
Resource
};
use
core
::
fmt
::
Write
;
use
f4
::
U8Writer
;
// Claim the transmit buffer and write a string literal into it
$TX_BUFFER
.claim_mut
(
$T
,
|
tx
,
_
|
{
let
len
=
(
*
tx
)
.deref
()
.borrow
()
.len
();
let
buf
=
&
mut
(
*
tx
)
.deref
()
.borrow_mut
();
write!
(
U8Writer
::
new
(
&
mut
buf
[
..
len
]),
$s
)
.unwrap
();
});
uprint!
(
$T
,
$USART
,
$DMA
,
$TX_BUFFER
);
};
(
$T:ident
,
$USART:expr
,
$DMA:expr
,
$TX_BUFFER:expr
,
$
(
$arg:tt
)
*
)
=>
{
use
rtfm
::{
Resource
};
use
core
::
fmt
::
Write
;
use
f4
::
U8Writer
;
// Claim the transmit buffer and write a formatted string into it
$TX_BUFFER
.claim_mut
(
$T
,
|
tx
,
_
|
{
let
len
=
(
*
tx
)
.deref
()
.borrow
()
.len
();
let
buf
=
&
mut
(
*
tx
)
.deref
()
.borrow_mut
();
write!
(
U8Writer
::
new
(
&
mut
buf
[
..
len
]),
$
(
$arg
)
*
)
.unwrap
();
});
// Transmit the contents of the buffer using DMA
$TX_BUFFER
.claim
(
$T
,
|
tx
,
t
|
{
$DMA
.claim
(
t
,
|
dma
,
t
|
{
$USART
.claim
(
t
,
|
usart
,
_
|
{
let
serial
=
Serial
(
&**
usart
);
serial
.write_all
(
dma
,
tx
)
.unwrap
();
});
});
});
}
uprint!
(
$T
,
$USART
,
$DMA
,
$TX_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