Skip to content

Commit

Permalink
Ensure all structs are consistently CamelCased
Browse files Browse the repository at this point in the history
  • Loading branch information
MabezDev committed Apr 18, 2024
1 parent be06c57 commit b66e36e
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 114 deletions.
8 changes: 4 additions & 4 deletions esp-hal/src/analog/adc/esp32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ impl RegisterAccess for ADC2 {
}

/// Analog-to-Digital Converter peripheral driver.
pub struct ADC<'d, ADC> {
pub struct Adc<'d, ADC> {
_adc: PeripheralRef<'d, ADC>,
attenuations: [Option<Attenuation>; NUM_ATTENS],
active_channel: Option<u8>,
}

impl<'d, ADCI> ADC<'d, ADCI>
impl<'d, ADCI> Adc<'d, ADCI>
where
ADCI: RegisterAccess,
{
Expand Down Expand Up @@ -323,7 +323,7 @@ where
}
}

impl<'d, ADC1> ADC<'d, ADC1> {
impl<'d, ADC1> Adc<'d, ADC1> {
pub fn enable_hall_sensor() {
// Connect hall sensor
unsafe { &*RTC_IO::ptr() }
Expand All @@ -341,7 +341,7 @@ impl<'d, ADC1> ADC<'d, ADC1> {

#[cfg(feature = "embedded-hal-02")]
impl<'d, ADCI, PIN> embedded_hal_02::adc::OneShot<ADCI, u16, super::AdcPin<PIN, ADCI>>
for ADC<'d, ADCI>
for Adc<'d, ADCI>
where
PIN: embedded_hal_02::adc::Channel<ADCI, ID = u8> + super::AdcChannel,
ADCI: RegisterAccess,
Expand Down
6 changes: 3 additions & 3 deletions esp-hal/src/analog/adc/riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,13 @@ impl super::CalibrationAccess for crate::peripherals::ADC2 {
}

/// Analog-to-Digital Converter peripheral driver.
pub struct ADC<'d, ADCI> {
pub struct Adc<'d, ADCI> {
_adc: PeripheralRef<'d, ADCI>,
attenuations: [Option<Attenuation>; NUM_ATTENS],
active_channel: Option<u8>,
}

impl<'d, ADCI> ADC<'d, ADCI>
impl<'d, ADCI> Adc<'d, ADCI>
where
ADCI: RegisterAccess + 'd,
{
Expand Down Expand Up @@ -540,7 +540,7 @@ impl super::AdcCalEfuse for crate::peripherals::ADC2 {

#[cfg(feature = "embedded-hal-02")]
impl<'d, ADCI, PIN, CS> embedded_hal_02::adc::OneShot<ADCI, u16, super::AdcPin<PIN, ADCI, CS>>
for ADC<'d, ADCI>
for Adc<'d, ADCI>
where
PIN: embedded_hal_02::adc::Channel<ADCI, ID = u8> + super::AdcChannel,
ADCI: RegisterAccess,
Expand Down
6 changes: 3 additions & 3 deletions esp-hal/src/analog/adc/xtensa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,13 +401,13 @@ impl super::CalibrationAccess for crate::peripherals::ADC2 {
}

/// Analog-to-Digital Converter peripheral driver.
pub struct ADC<'d, ADC> {
pub struct Adc<'d, ADC> {
_adc: PeripheralRef<'d, ADC>,
active_channel: Option<u8>,
last_init_code: u16,
}

impl<'d, ADCI> ADC<'d, ADCI>
impl<'d, ADCI> Adc<'d, ADCI>
where
ADCI: RegisterAccess,
{
Expand Down Expand Up @@ -605,7 +605,7 @@ impl super::AdcCalEfuse for crate::peripherals::ADC2 {

#[cfg(feature = "embedded-hal-02")]
impl<'d, ADCI, PIN, CS> embedded_hal_02::adc::OneShot<ADCI, u16, AdcPin<PIN, ADCI, CS>>
for ADC<'d, ADCI>
for Adc<'d, ADCI>
where
PIN: embedded_hal_02::adc::Channel<ADCI, ID = u8> + AdcChannel,
ADCI: RegisterAccess,
Expand Down
8 changes: 4 additions & 4 deletions esp-hal/src/analog/dac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ cfg_if::cfg_if! {
}

/// Digital-to-Analog Converter (DAC) Channel 1
pub struct DAC1<'d> {
pub struct Dac1<'d> {
_inner: PeripheralRef<'d, peripherals::DAC1>,
}

impl<'d> DAC1<'d> {
impl<'d> Dac1<'d> {
/// Constructs a new DAC instance.
pub fn new(dac: impl Peripheral<P = peripherals::DAC1> + 'd, _pin: Dac1Gpio) -> Self {
crate::into_ref!(dac);
Expand Down Expand Up @@ -90,11 +90,11 @@ impl<'d> DAC1<'d> {
}

/// Digital-to-Analog Converter (DAC) Channel 2
pub struct DAC2<'d> {
pub struct Dac2<'d> {
_inner: PeripheralRef<'d, peripherals::DAC2>,
}

impl<'d> DAC2<'d> {
impl<'d> Dac2<'d> {
/// Constructs a new DAC instance.
pub fn new(dac: impl Peripheral<P = peripherals::DAC2> + 'd, _pin: Dac2Gpio) -> Self {
crate::into_ref!(dac);
Expand Down
4 changes: 2 additions & 2 deletions esp-hal/src/gpio/lp_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ macro_rules! lp_gpio {
}
}

impl<MODE> $crate::gpio::RTCPin for GpioPin<MODE, $gpionum> {
impl<MODE> $crate::gpio::RtcPin for GpioPin<MODE, $gpionum> {
unsafe fn apply_wakeup(&mut self, wakeup: bool, level: u8) {
let lp_io = &*$crate::peripherals::LP_IO::ptr();
lp_io.[< pin $gpionum >]().modify(|_, w| {
Expand Down Expand Up @@ -232,7 +232,7 @@ macro_rules! lp_gpio {
}
}

impl<MODE> $crate::gpio::RTCPinWithResistors for GpioPin<MODE, $gpionum> {
impl<MODE> $crate::gpio::RtcPinWithResistors for GpioPin<MODE, $gpionum> {
fn rtcio_pullup(&mut self, enable: bool) {
let lp_io = unsafe { &*$crate::peripherals::LP_IO::ptr() };
lp_io.[< gpio $gpionum >]().modify(|_, w| w.fun_wpu().bit(enable));
Expand Down
88 changes: 19 additions & 69 deletions esp-hal/src/gpio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
//! interface for GPIO pins.
//!
//! To get access to the pins, you first need to convert them into a HAL
//! designed struct from the pac struct `GPIO` and `IO_MUX` using `IO::new`.
//! designed struct from the pac struct `GPIO` and `IO_MUX` using `Io::new`.
//!
//! ## Example
//! ```no_run
//! let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
//! let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
//! let mut led = io.pins.gpio5.into_push_pull_output();
//! ```
//!
Expand Down Expand Up @@ -100,7 +100,7 @@ impl InputMode for Unknown {
}

/// RTC input pin mode
pub struct RTCInput<MODE> {
pub struct RtcInput<MODE> {
_mode: PhantomData<MODE>,
}

Expand Down Expand Up @@ -142,7 +142,7 @@ impl OutputMode for Unknown {
}

/// RTC output pin mode
pub struct RTCOutput<MODE> {
pub struct RtcOutput<MODE> {
_mode: PhantomData<MODE>,
}

Expand All @@ -155,20 +155,6 @@ pub struct PushPull;
/// Analog mode
pub struct Analog;

/// Alternate mode
pub struct Alternate<MODE> {
_mode: PhantomData<MODE>,
}

#[doc(hidden)]
pub struct AF0;

#[doc(hidden)]
pub struct AF1;

#[doc(hidden)]
pub struct AF2;

/// Drive strength (values are approximates)
#[allow(missing_docs)]
pub enum DriveStrength {
Expand Down Expand Up @@ -199,7 +185,7 @@ pub enum RtcFunction {
}

/// Trait implemented by RTC pins
pub trait RTCPin: Pin {
pub trait RtcPin: Pin {
/// RTC number of the pin
#[cfg(xtensa)]
fn rtc_number(&self) -> u8;
Expand All @@ -221,23 +207,23 @@ pub trait RTCPin: Pin {

/// Trait implemented by RTC pins which supporting internal pull-up / pull-down
/// resistors.
pub trait RTCPinWithResistors: RTCPin {
pub trait RtcPinWithResistors: RtcPin {
/// Enable/disable the internal pull-up resistor
fn rtcio_pullup(&mut self, enable: bool);
/// Enable/disable the internal pull-down resistor
fn rtcio_pulldown(&mut self, enable: bool);
}

/// Marker for RTC pins which support input mode
pub trait RTCInputPin: RTCPin {}
pub trait RtcInputPin: RtcPin {}
/// Marker for RTC pins which support output mode
pub trait RTCOutputPin: RTCPin {}
pub trait RtcOutputPin: RtcPin {}

/// Marker for pins which support analog mode
pub trait AnalogPin {}

/// Common trait implemented by pins
pub trait Pin {
pub trait Pin: crate::private::Sealed {
/// GPIO number
fn number(&self) -> u8;

Expand Down Expand Up @@ -304,7 +290,7 @@ pub trait InputPin: Pin {

/// Remove a connected `signal` from this input pin.
///
/// Clears the entry in the GPIO matrix / IO mux that associates this input
/// Clears the entry in the GPIO matrix / Io mux that associates this input
/// pin with the given [input `signal`](`InputSignal`). Any other
/// connected signals remain intact.
fn disconnect_input_from_peripheral(&mut self, signal: InputSignal) -> &mut Self;
Expand Down Expand Up @@ -374,7 +360,7 @@ pub trait OutputPin: Pin {

/// Remove this output pin from a connected [signal](`InputSignal`).
///
/// Clears the entry in the GPIO matrix / IO mux that associates this output
/// Clears the entry in the GPIO matrix / Io mux that associates this output
/// pin with a previously connected [signal](`InputSignal`). Any other
/// outputs connected to the signal remain intact.
fn disconnect_peripheral_from_output(&mut self) -> &mut Self;
Expand Down Expand Up @@ -1146,30 +1132,6 @@ where
}
}

impl<const GPIONUM: u8> From<GpioPin<Unknown, GPIONUM>> for GpioPin<Alternate<AF1>, GPIONUM>
where
Self: GpioProperties,
<Self as GpioProperties>::PinType: IsOutputPin,
GpioPin<Unknown, GPIONUM>: GpioProperties,
<GpioPin<Unknown, GPIONUM> as GpioProperties>::PinType: IsOutputPin,
{
fn from(pin: GpioPin<Unknown, GPIONUM>) -> Self {
pin.into_alternate_1()
}
}

impl<const GPIONUM: u8> From<GpioPin<Unknown, GPIONUM>> for GpioPin<Alternate<AF2>, GPIONUM>
where
Self: GpioProperties,
<Self as GpioProperties>::PinType: IsOutputPin,
GpioPin<Unknown, GPIONUM>: GpioProperties,
<GpioPin<Unknown, GPIONUM> as GpioProperties>::PinType: IsOutputPin,
{
fn from(pin: GpioPin<Unknown, GPIONUM>) -> Self {
pin.into_alternate_2()
}
}

impl<MODE, const GPIONUM: u8> GpioPin<MODE, GPIONUM>
where
Self: GpioProperties,
Expand Down Expand Up @@ -1246,18 +1208,6 @@ where
self.init_output(GPIO_FUNCTION, true);
GpioPin { _mode: PhantomData }
}

/// Configures the pin into alternate mode one.
pub fn into_alternate_1(self) -> GpioPin<Alternate<AF1>, GPIONUM> {
self.init_output(AlternateFunction::Function1, false);
GpioPin { _mode: PhantomData }
}

/// Configures the pin into alternate mode two.
pub fn into_alternate_2(self) -> GpioPin<Alternate<AF2>, GPIONUM> {
self.init_output(AlternateFunction::Function2, false);
GpioPin { _mode: PhantomData }
}
}

impl<MODE, const GPIONUM: u8> OutputPin for GpioPin<MODE, GPIONUM>
Expand Down Expand Up @@ -1878,13 +1828,13 @@ impl<MODE, TYPE> AnyPin<Input<MODE>, TYPE> {
}

/// General Purpose Input/Output driver
pub struct IO {
pub struct Io {
_io_mux: IO_MUX,
/// The pins available on this chip
pub pins: Pins,
}

impl IO {
impl Io {
/// Initialize the I/O driver.
pub fn new(gpio: GPIO, io_mux: IO_MUX) -> Self {
Self::new_with_priority(gpio, io_mux, crate::interrupt::Priority::min())
Expand All @@ -1903,7 +1853,7 @@ impl IO {

let pins = gpio.split();

IO {
Io {
_io_mux: io_mux,
pins,
}
Expand Down Expand Up @@ -2112,7 +2062,7 @@ macro_rules! rtc_pins {
(
$pin_num:expr, $rtc_pin:expr, $pin_reg:expr, $prefix:pat, $hold:ident $(, $rue:ident, $rde:ident)?
) => {
impl<MODE> $crate::gpio::RTCPin for GpioPin<MODE, $pin_num>
impl<MODE> $crate::gpio::RtcPin for GpioPin<MODE, $pin_num>
{
fn rtc_number(&self) -> u8 {
$rtc_pin
Expand Down Expand Up @@ -2152,7 +2102,7 @@ macro_rules! rtc_pins {
}

$(
impl<MODE> $crate::gpio::RTCPinWithResistors for GpioPin<MODE, $pin_num>
impl<MODE> $crate::gpio::RtcPinWithResistors for GpioPin<MODE, $pin_num>
{
fn rtcio_pullup(&mut self, enable: bool) {
let rtcio = unsafe { &*$crate::peripherals::RTC_IO::PTR };
Expand All @@ -2175,7 +2125,7 @@ macro_rules! rtc_pins {
paste::paste!{
impl<MODE> $crate::gpio::rtc_io::IntoLowPowerPin<$pin_num> for GpioPin<MODE, $pin_num> {
fn into_low_power(mut self) -> $crate::gpio::rtc_io::LowPowerPin<Unknown, $pin_num> {
use $crate::gpio::RTCPin;
use $crate::gpio::RtcPin;

self.rtc_set_config(false, true, $crate::gpio::RtcFunction::Rtc);

Expand Down Expand Up @@ -2204,7 +2154,7 @@ macro_rules! rtc_pins {
(
$pin_num:expr
) => {
impl<MODE> $crate::gpio::RTCPin for GpioPin<MODE, $pin_num> {
impl<MODE> $crate::gpio::RtcPin for GpioPin<MODE, $pin_num> {
unsafe fn apply_wakeup(&mut self, wakeup: bool, level: u8) {
let rtc_cntl = unsafe { &*$crate::peripherals::RTC_CNTL::ptr() };
paste::paste! {
Expand All @@ -2221,7 +2171,7 @@ macro_rules! rtc_pins {
}
}

impl<MODE> $crate::gpio::RTCPinWithResistors for GpioPin<MODE, $pin_num> {
impl<MODE> $crate::gpio::RtcPinWithResistors for GpioPin<MODE, $pin_num> {
fn rtcio_pullup(&mut self, enable: bool) {
let io_mux = unsafe { &*$crate::peripherals::IO_MUX::ptr() };
io_mux.gpio($pin_num).modify(|_, w| w.fun_wpu().bit(enable));
Expand Down
4 changes: 2 additions & 2 deletions esp-hal/src/ledc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub enum LSGlobalClkSource {
}

/// LEDC (LED PWM Controller)
pub struct LEDC<'d> {
pub struct Ledc<'d> {
_instance: PeripheralRef<'d, crate::peripherals::LEDC>,
ledc: &'d crate::peripherals::ledc::RegisterBlock,
clock_control_config: &'d Clocks<'d>,
Expand All @@ -108,7 +108,7 @@ impl Speed for LowSpeed {
const IS_HS: bool = false;
}

impl<'d> LEDC<'d> {
impl<'d> Ledc<'d> {
/// Return a new LEDC
pub fn new(
_instance: impl Peripheral<P = crate::peripherals::LEDC> + 'd,
Expand Down
4 changes: 2 additions & 2 deletions esp-hal/src/mcpwm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type RegisterBlock = crate::peripherals::mcpwm0::RegisterBlock;

/// The MCPWM peripheral
#[non_exhaustive]
pub struct MCPWM<'d, PWM> {
pub struct McPwm<'d, PWM> {
_inner: PeripheralRef<'d, PWM>,
/// Timer0
pub timer0: Timer<0, PWM>,
Expand All @@ -97,7 +97,7 @@ pub struct MCPWM<'d, PWM> {
pub operator2: Operator<2, PWM>,
}

impl<'d, PWM: PwmPeripheral> MCPWM<'d, PWM> {
impl<'d, PWM: PwmPeripheral> McPwm<'d, PWM> {
/// `pwm_clk = clocks.crypto_pwm_clock / (prescaler + 1)`
// clocks.crypto_pwm_clock normally is 160 MHz
pub fn new(
Expand Down
Loading

0 comments on commit b66e36e

Please sign in to comment.