Skip to content

Commit

Permalink
Resolve naming violations for DataBits and StopBits enums
Browse files Browse the repository at this point in the history
  • Loading branch information
jessebraham committed Jan 6, 2025
1 parent d95a115 commit 19413e1
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions esp-hal/src/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,14 @@ const UART_TOUT_THRESH_DEFAULT: u8 = 10;
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum DataBits {
/// 5 data bits per frame.
DataBits5 = 0,
_5 = 0,
/// 6 data bits per frame.
DataBits6 = 1,
_6 = 1,
/// 7 data bits per frame.
DataBits7 = 2,
/// 8 data bits per frame (most common).
_7 = 2,
/// 8 data bits per frame.
#[default]
DataBits8 = 3,
_8 = 3,
}

/// Parity check
Expand Down Expand Up @@ -388,15 +388,14 @@ pub enum Parity {
/// bits.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[allow(clippy::enum_variant_names)] // FIXME: resolve this
pub enum StopBits {
/// 1 stop bit.
#[default]
Stop1 = 1,
_1 = 1,
/// 1.5 stop bits.
Stop1P5 = 2,
_1p5 = 2,
/// 2 stop bits.
Stop2 = 3,
_2 = 3,
}

/// UART Configuration
Expand Down Expand Up @@ -427,17 +426,17 @@ impl Config {
fn symbol_length(&self) -> u8 {
let mut length: u8 = 1; // start bit
length += match self.data_bits {
DataBits::DataBits5 => 5,
DataBits::DataBits6 => 6,
DataBits::DataBits7 => 7,
DataBits::DataBits8 => 8,
DataBits::_5 => 5,
DataBits::_6 => 6,
DataBits::_7 => 7,
DataBits::_8 => 8,
};
length += match self.parity {
Parity::None => 0,
_ => 1,
};
length += match self.stop_bits {
StopBits::Stop1 => 1,
StopBits::_1 => 1,
_ => 2, // esp-idf also counts 2 bits for settings 1.5 and 2 stop bits
};
length
Expand Down Expand Up @@ -2557,18 +2556,14 @@ impl Info {
#[cfg(esp32)]
{
// workaround for hardware issue, when UART stop bit set as 2-bit mode.
if stop_bits == StopBits::Stop2 {
if stop_bits == StopBits::_2 {
self.register_block()
.rs485_conf()
.modify(|_, w| w.dl1_en().bit(stop_bits == StopBits::Stop2));

self.register_block().conf0().modify(|_, w| {
if stop_bits == StopBits::Stop2 {
unsafe { w.stop_bit_num().bits(1) }
} else {
unsafe { w.stop_bit_num().bits(stop_bits as u8) }
}
});
.modify(|_, w| w.dl1_en().bit(stop_bits == StopBits::_2));

self.register_block()
.conf0()
.modify(|_, w| unsafe { w.stop_bit_num().bits(1) });
}
}

Expand Down

0 comments on commit 19413e1

Please sign in to comment.