-
Notifications
You must be signed in to change notification settings - Fork 65
Initial UART(E) implementation #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1b29247
Initial UART(E) implementation
hargoniX a7988c7
cargo formatting
hargoniX 7fd7df2
CHANGELOG
hargoniX 10484c6
The uart RX TX pin types have to be swapped
hargoniX ba414ab
Rely on the upstream version of nrf-hal for now
hargoniX 5c52cc0
Abstract the DMA initialization a bit away.
hargoniX c1fdffc
Formatting
hargoniX fcfc014
Fix v2-speaker example
hargoniX deaf0a8
Pull the nrf51-hal version to 0.13.0 as well
hargoniX File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use core::fmt; | ||
use embedded_hal::blocking::serial as bserial; | ||
use embedded_hal::serial; | ||
use microbit::hal::uarte::{Error, Instance, Uarte, UarteRx, UarteTx}; | ||
|
||
static mut TX_BUF: [u8; 1] = [0; 1]; | ||
static mut RX_BUF: [u8; 1] = [0; 1]; | ||
|
||
pub struct UartePort<T: Instance>(UarteTx<T>, UarteRx<T>); | ||
|
||
impl<T: Instance> UartePort<T> { | ||
pub fn new(serial: Uarte<T>) -> UartePort<T> { | ||
let (tx, rx) = serial | ||
.split(unsafe { &mut TX_BUF }, unsafe { &mut RX_BUF }) | ||
.unwrap(); | ||
UartePort(tx, rx) | ||
} | ||
} | ||
|
||
impl<T: Instance> fmt::Write for UartePort<T> { | ||
fn write_str(&mut self, s: &str) -> fmt::Result { | ||
self.0.write_str(s) | ||
} | ||
} | ||
|
||
impl<T: Instance> serial::Write<u8> for UartePort<T> { | ||
type Error = Error; | ||
|
||
fn write(&mut self, b: u8) -> nb::Result<(), Self::Error> { | ||
self.0.write(b) | ||
} | ||
|
||
fn flush(&mut self) -> nb::Result<(), Self::Error> { | ||
self.0.flush() | ||
} | ||
} | ||
|
||
impl<T: Instance> bserial::write::Default<u8> for UartePort<T> {} | ||
|
||
impl<T: Instance> serial::Read<u8> for UartePort<T> { | ||
type Error = Error; | ||
|
||
fn read(&mut self) -> nb::Result<u8, Self::Error> { | ||
self.1.read() | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.