From 7b2cf2336484fcf833c74b4d2ec36093224968e0 Mon Sep 17 00:00:00 2001 From: Josh Gao Date: Sat, 8 Jun 2019 00:56:23 -0700 Subject: [PATCH] Implement serial::{Tx,Rx}::{listen,unlisten}. --- CHANGELOG.md | 1 + src/serial.rs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67cf978e..fef99dce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Add ADC1 reading functions for channels 16 (temperature) and 17 (internal reference voltage) - Update existing ADC example according to ADC API changes - Add new ADC example to read ambient temperature using ADC1 CH16 +- Add `listen` and `unlisten` to `serial::Tx` and `serial::Rx`. ### Breaking changes diff --git a/src/serial.rs b/src/serial.rs index 7b37557d..9f819770 100644 --- a/src/serial.rs +++ b/src/serial.rs @@ -326,6 +326,26 @@ macro_rules! hal { } } + impl Tx<$USARTX> { + pub fn listen(&mut self) { + unsafe { (*$USARTX::ptr()).cr1.modify(|_, w| w.txeie().set_bit()) }; + } + + pub fn unlisten(&mut self) { + unsafe { (*$USARTX::ptr()).cr1.modify(|_, w| w.txeie().clear_bit()) }; + } + } + + impl Rx<$USARTX> { + pub fn listen(&mut self) { + unsafe { (*$USARTX::ptr()).cr1.modify(|_, w| w.rxneie().set_bit()) }; + } + + pub fn unlisten(&mut self) { + unsafe { (*$USARTX::ptr()).cr1.modify(|_, w| w.rxneie().clear_bit()) }; + } + } + impl crate::hal::serial::Read for Rx<$USARTX> { type Error = Error;