stm32-rs / stm32l0xx-hal

A hardware abstraction layer (HAL) for the STM32L0 series microcontrollers written in Rust
BSD Zero Clause License
96 stars 60 forks source link

Add methods to check idle, tx empty and rx not empty for serial #206

Closed azerupi closed 2 years ago

azerupi commented 2 years ago

There is currently already a method pending_event that allows to get events when the interrupts are enabled. But the idle flag and the txe and rxne flags can also be used when interrupts are disabled (idleie=0, txeie=0 and rxneie=0 respectively).

This PR adds methods on Rx and Tx to read the state of those flags and reset the idle flag. This is inspired by https://github.com/stm32-rs/stm32f1xx-hal/blob/master/src/serial.rs#L303-L324

These methods are also more intuitive IMHO than the pending_event method.

We tested is_idle and clear_idle_interrupt and confirmed that it worked. What do you guys think?