Skip to content

Commit 5b7603b

Browse files
authored
Merge pull request #51 from IsaacDynamo/rprint-flush
Add flush() and is_empty() to channels
2 parents d391e46 + 2a537f9 commit 5b7603b

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

rtt-target/src/lib.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,19 @@ impl UpChannel {
258258
Some(UpChannel(ptr))
259259
}
260260

261+
/// Returns true if the channel is empty.
262+
pub fn is_empty(&self) -> bool {
263+
let (write, read) = self.channel().read_pointers();
264+
write == read
265+
}
266+
261267
/// Wait until all data has been read by the debugger.
262268
///
263269
/// *Note: This means that if no debugger is connected or if it isn't reading the rtt data,*
264270
/// *this function will wait indefinitely.*
265271
pub fn flush(&self) {
266272
loop {
267-
let (write, read) = self.channel().read_pointers();
268-
if write == read {
273+
if self.is_empty() {
269274
break;
270275
}
271276
core::hint::spin_loop();
@@ -401,6 +406,19 @@ impl TerminalChannel {
401406
pub fn set_mode(&mut self, mode: ChannelMode) {
402407
self.channel.set_mode(mode)
403408
}
409+
410+
/// Returns true if the channel is empty.
411+
pub fn is_empty(&self) -> bool {
412+
self.channel.is_empty()
413+
}
414+
415+
/// Wait until all data has been read by the debugger.
416+
///
417+
/// *Note: This means that if no debugger is connected or if it isn't reading the rtt data,*
418+
/// *this function will wait indefinitely.*
419+
pub fn flush(&self) {
420+
self.channel.flush();
421+
}
404422
}
405423

406424
/// Formatted writing operation. Don't store an instance of this, but rather create a new one for

0 commit comments

Comments
 (0)