Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove get_ prefix from functions #2528

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions esp-hal-embassy/src/executor/interrupt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::{cell::UnsafeCell, mem::MaybeUninit};

use embassy_executor::{raw, SendSpawner};
use esp_hal::{
get_core,
core,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we drop core() in favour of Cpu::current()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just in this file, or in general?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general I think, I don't know if Rust can cope with a function core and the core crate together. Though I guess if it can, we can leave it and come back later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay will do so in another PR, this one is a bit of a beast and I don't really want to touch it if CI is happy and I don't need to 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make get_core private and use Cpu::current() everywhere (though we don't have to do that here if we can get away with it).

interrupt::{self, software::SoftwareInterrupt, InterruptHandler},
};
use portable_atomic::{AtomicUsize, Ordering};
Expand Down Expand Up @@ -87,7 +87,7 @@ impl<const SWI: u8> InterruptExecutor<SWI> {
.core
.compare_exchange(
usize::MAX,
get_core() as usize,
core() as usize,
Ordering::Acquire,
Ordering::Relaxed,
)
Expand Down
8 changes: 4 additions & 4 deletions esp-hal-embassy/src/executor/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use core::marker::PhantomData;

use embassy_executor::{raw, Spawner};
use esp_hal::{get_core, Cpu};
use esp_hal::{core, Cpu};
#[cfg(multi_core)]
use esp_hal::{interrupt::software::SoftwareInterrupt, macros::handler};
#[cfg(low_power_wait)]
Expand Down Expand Up @@ -35,7 +35,7 @@ pub(crate) fn pend_thread_mode(_core: usize) {
// If we are pending a task on the current core, we're done. Otherwise, we
// need to make sure the other core wakes up.
#[cfg(multi_core)]
if _core != get_core() as usize {
if _core != core() as usize {
// We need to clear the interrupt from software. We don't actually
// need it to trigger and run the interrupt handler, we just need to
// kick waiti to return.
Expand Down Expand Up @@ -74,7 +74,7 @@ This will use software-interrupt 3 which isn't available for anything else to wa
}

Self {
inner: raw::Executor::new((THREAD_MODE_CONTEXT + get_core() as usize) as *mut ()),
inner: raw::Executor::new((THREAD_MODE_CONTEXT + core() as usize) as *mut ()),
not_send: PhantomData,
}
}
Expand Down Expand Up @@ -103,7 +103,7 @@ This will use software-interrupt 3 which isn't available for anything else to wa
init(self.inner.spawner());

#[cfg(low_power_wait)]
let cpu = get_core() as usize;
let cpu = core() as usize;

loop {
unsafe { self.inner.poll() };
Expand Down
4 changes: 2 additions & 2 deletions esp-hal-procmacros/src/lp_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
res
}

pub(crate) fn get_simplename(t: &Type) -> String {
pub(crate) fn simplename(t: &Type) -> String {
match t {
Type::Path(p) => p.path.segments.last().unwrap().ident.to_string(),
_ => String::new(),
Expand Down Expand Up @@ -125,7 +125,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream {
.into();
}
FnArg::Typed(t) => {
match get_simplename(&t.ty).as_str() {
match simplename(&t.ty).as_str() {
"Output" => {
let pin = extract_pin(&t.ty);
if used_pins.contains(&pin) {
Expand Down
2 changes: 2 additions & 0 deletions esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added

- A new config option `PLACE_SWITCH_TABLES_IN_RAM` to improve performance (especially for interrupts) at the cost of slightly more RAM usage (#2331)
- A new config option `PLACE_ANON_IN_RAM` to improve performance (especially for interrupts) at the cost of RAM usage (#2331)
- Add burst transfer support to DMA buffers (#2336)
Expand Down Expand Up @@ -63,6 +64,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The `I2c` master driver has been moved from `esp_hal::i2c` to `esp_hal::i2c::master`. (#2476)
- `I2c` SCL timeout is now defined in bus clock cycles. (#2477)
- Trying to send a single-shot RMT transmission will result in an error now, `RMT` deals with `u32` now, `PulseCode` is a convenience trait now (#2463)
- Removed `get_` prefixes from functions (#2528)

### Fixed

Expand Down
9 changes: 8 additions & 1 deletion esp-hal/MIGRATING-0.21.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ You can now use the `UartInterrupt` enum and the corresponding `listen`, `unlist
Use `interrupts` in place of `<INTERRUPT>_interrupt_set` and `clear_interrupts` in place of the old `reset_` functions.

`UartInterrupt`:

- `AtCmd`
- `TxDone`
- `RxFifoFull`
Expand Down Expand Up @@ -359,6 +360,7 @@ refer to the `Config` struct as `uart::Config`.
## I8080 driver split `set_byte_order()` into `set_8bits_order()` and `set_byte_order()`.

If you were using an 8-bit bus.

```diff
- i8080.set_byte_order(ByteOrder::default());
+ i8080.set_8bits_order(ByteOrder::default());
Expand All @@ -369,7 +371,6 @@ If you were using an 16-bit bus, you don't need to change anything, `set_byte_or
If you were sharing the bus between an 8-bit and 16-bit device, you will have to call the corresponding method when
you switch between devices. Be sure to read the documentation of the new methods.


## `rmt::Channel::transmit` now returns `Result`, `PulseCode` is now `u32`

When trying to send a one-shot transmission will fail if it doesn't end with an end-marker.
Expand Down Expand Up @@ -412,3 +413,9 @@ You can use `gpio::NoPin` instead.
+let mut rx_clk_pin = NoPin;
+parl_io.rx.with_config(&mut rx_pins, &mut rx_clk_pin, BitPackOrder::Msb, Some(0xfff))
```

## `get_` prefixes have been removed from functions

In order to better comply with the Rust API Guidelines [getter names convention], we have removed the `get_` prefixes from all functions which previously had it. Due to the number of changes it's not practical to list all changes here, however if a function previous began with `get_`, you can simply remove this prefix.

[getter names convention]: https://rust-lang.github.io/api-guidelines/naming.html#c-getter
4 changes: 2 additions & 2 deletions esp-hal/src/aes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl<'d> Aes<'d> {
self.set_block(block);
self.start();
while !(self.is_idle()) {}
self.get_block(block);
self.block(block);
}

fn set_mode(&mut self, mode: u8) {
Expand All @@ -181,7 +181,7 @@ impl<'d> Aes<'d> {
self.write_block(block);
}

fn get_block(&self, block: &mut [u8; 16]) {
fn block(&self, block: &mut [u8; 16]) {
self.read_block(block);
}

Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/analog/adc/calibration/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ where
fn new_cal(atten: Attenuation) -> Self {
// Try to get init code (Dout0) from efuse
// Dout0 means mean raw ADC value when zero voltage applied to input.
let cal_val = ADCI::get_init_code(atten).unwrap_or_else(|| {
let cal_val = ADCI::init_code(atten).unwrap_or_else(|| {
// As a fallback try to calibrate via connecting input to ground internally.
AdcConfig::<ADCI>::adc_calibrate(atten, AdcCalSource::Gnd)
});
Expand Down
4 changes: 2 additions & 2 deletions esp-hal/src/analog/adc/calibration/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ where

// Try get the reference point (Dout, Vin) from efuse
// Dout means mean raw ADC value when specified Vin applied to input.
let (code, mv) = ADCI::get_cal_code(atten)
.map(|code| (code, ADCI::get_cal_mv(atten)))
let (code, mv) = ADCI::cal_code(atten)
.map(|code| (code, ADCI::cal_mv(atten)))
.unwrap_or_else(|| {
// As a fallback try to calibrate using reference voltage source.
// This method is not too good because actual reference voltage may varies
Expand Down
6 changes: 3 additions & 3 deletions esp-hal/src/analog/adc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,17 @@ trait AdcCalEfuse {
/// Get ADC calibration init code
///
/// Returns digital value for zero voltage for a given attenuation
fn get_init_code(atten: Attenuation) -> Option<u16>;
fn init_code(atten: Attenuation) -> Option<u16>;

/// Get ADC calibration reference point voltage
///
/// Returns reference voltage (millivolts) for a given attenuation
fn get_cal_mv(atten: Attenuation) -> u16;
fn cal_mv(atten: Attenuation) -> u16;

/// Get ADC calibration reference point digital value
///
/// Returns digital value for reference voltage for a given attenuation
fn get_cal_code(atten: Attenuation) -> Option<u16>;
fn cal_code(atten: Attenuation) -> Option<u16>;
}

macro_rules! impl_adc_interface {
Expand Down
24 changes: 12 additions & 12 deletions esp-hal/src/analog/adc/riscv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,31 +502,31 @@ where

#[cfg(any(esp32c2, esp32c3, esp32c6))]
impl super::AdcCalEfuse for crate::peripherals::ADC1 {
fn get_init_code(atten: Attenuation) -> Option<u16> {
Efuse::get_rtc_calib_init_code(1, atten)
fn init_code(atten: Attenuation) -> Option<u16> {
Efuse::rtc_calib_init_code(1, atten)
}

fn get_cal_mv(atten: Attenuation) -> u16 {
Efuse::get_rtc_calib_cal_mv(1, atten)
fn cal_mv(atten: Attenuation) -> u16 {
Efuse::rtc_calib_cal_mv(1, atten)
}

fn get_cal_code(atten: Attenuation) -> Option<u16> {
Efuse::get_rtc_calib_cal_code(1, atten)
fn cal_code(atten: Attenuation) -> Option<u16> {
Efuse::rtc_calib_cal_code(1, atten)
}
}

#[cfg(esp32c3)]
impl super::AdcCalEfuse for crate::peripherals::ADC2 {
fn get_init_code(atten: Attenuation) -> Option<u16> {
Efuse::get_rtc_calib_init_code(2, atten)
fn init_code(atten: Attenuation) -> Option<u16> {
Efuse::rtc_calib_init_code(2, atten)
}

fn get_cal_mv(atten: Attenuation) -> u16 {
Efuse::get_rtc_calib_cal_mv(2, atten)
fn cal_mv(atten: Attenuation) -> u16 {
Efuse::rtc_calib_cal_mv(2, atten)
}

fn get_cal_code(atten: Attenuation) -> Option<u16> {
Efuse::get_rtc_calib_cal_code(2, atten)
fn cal_code(atten: Attenuation) -> Option<u16> {
Efuse::rtc_calib_cal_code(2, atten)
}
}

Expand Down
24 changes: 12 additions & 12 deletions esp-hal/src/analog/adc/xtensa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,31 +562,31 @@ where

#[cfg(esp32s3)]
impl super::AdcCalEfuse for crate::peripherals::ADC1 {
fn get_init_code(atten: Attenuation) -> Option<u16> {
Efuse::get_rtc_calib_init_code(1, atten)
fn init_code(atten: Attenuation) -> Option<u16> {
Efuse::rtc_calib_init_code(1, atten)
}

fn get_cal_mv(atten: Attenuation) -> u16 {
Efuse::get_rtc_calib_cal_mv(1, atten)
fn cal_mv(atten: Attenuation) -> u16 {
Efuse::rtc_calib_cal_mv(1, atten)
}

fn get_cal_code(atten: Attenuation) -> Option<u16> {
Efuse::get_rtc_calib_cal_code(1, atten)
fn cal_code(atten: Attenuation) -> Option<u16> {
Efuse::rtc_calib_cal_code(1, atten)
}
}

#[cfg(esp32s3)]
impl super::AdcCalEfuse for crate::peripherals::ADC2 {
fn get_init_code(atten: Attenuation) -> Option<u16> {
Efuse::get_rtc_calib_init_code(2, atten)
fn init_code(atten: Attenuation) -> Option<u16> {
Efuse::rtc_calib_init_code(2, atten)
}

fn get_cal_mv(atten: Attenuation) -> u16 {
Efuse::get_rtc_calib_cal_mv(2, atten)
fn cal_mv(atten: Attenuation) -> u16 {
Efuse::rtc_calib_cal_mv(2, atten)
}

fn get_cal_code(atten: Attenuation) -> Option<u16> {
Efuse::get_rtc_calib_cal_code(2, atten)
fn cal_code(atten: Attenuation) -> Option<u16> {
Efuse::rtc_calib_cal_code(2, atten)
}
}

Expand Down
8 changes: 4 additions & 4 deletions esp-hal/src/assist_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl DebugAssist<'_> {
}

/// Get SP monitoring PC value on main core.
pub fn get_sp_monitor_pc(&self) -> u32 {
pub fn sp_monitor_pc(&self) -> u32 {
self.debug_assist
.core_0_sp_pc()
.read()
Expand Down Expand Up @@ -219,7 +219,7 @@ impl<'d> DebugAssist<'d> {
}

/// Get SP monitoring PC value on secondary core.
pub fn get_core1_sp_monitor_pc(&self) -> u32 {
pub fn core1_sp_monitor_pc(&self) -> u32 {
self.debug_assist.core_1_sp_pc.read().core_1_sp_pc().bits()
}
}
Expand Down Expand Up @@ -382,7 +382,7 @@ impl DebugAssist<'_> {
}

/// Get region monitoring PC value on main core.
pub fn get_region_monitor_pc(&self) -> u32 {
pub fn region_monitor_pc(&self) -> u32 {
self.debug_assist
.core_0_area_pc()
.read()
Expand Down Expand Up @@ -548,7 +548,7 @@ impl<'d> DebugAssist<'d> {
}

/// Get region monitoring PC value on secondary core.
pub fn get_core1_region_monitor_pc(&self) -> u32 {
pub fn core1_region_monitor_pc(&self) -> u32 {
self.debug_assist
.core_1_area_pc()
.read()
Expand Down
4 changes: 2 additions & 2 deletions esp-hal/src/dma/gdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,11 +522,11 @@ macro_rules! impl_channel {
}

impl DmaChannelExt for [<DmaChannel $num>] {
fn get_rx_interrupts() -> impl InterruptAccess<DmaRxInterrupt> {
fn rx_interrupts() -> impl InterruptAccess<DmaRxInterrupt> {
ChannelRxImpl(SpecificGdmaChannel::<$num> {})
}

fn get_tx_interrupts() -> impl InterruptAccess<DmaTxInterrupt> {
fn tx_interrupts() -> impl InterruptAccess<DmaTxInterrupt> {
ChannelTxImpl(SpecificGdmaChannel::<$num> {})
}
}
Expand Down
8 changes: 4 additions & 4 deletions esp-hal/src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1581,8 +1581,8 @@ pub trait DmaChannel: crate::private::Sealed + Sized {

#[doc(hidden)]
pub trait DmaChannelExt: DmaChannel {
fn get_rx_interrupts() -> impl InterruptAccess<DmaRxInterrupt>;
fn get_tx_interrupts() -> impl InterruptAccess<DmaTxInterrupt>;
fn rx_interrupts() -> impl InterruptAccess<DmaRxInterrupt>;
fn tx_interrupts() -> impl InterruptAccess<DmaTxInterrupt>;
}

#[diagnostic::on_unimplemented(
Expand Down Expand Up @@ -2885,8 +2885,8 @@ pub(crate) mod asynch {
}

fn handle_interrupt<CH: DmaChannelExt>() {
let rx = CH::get_rx_interrupts();
let tx = CH::get_tx_interrupts();
let rx = CH::rx_interrupts();
let tx = CH::tx_interrupts();

if rx.pending_interrupts().is_disjoint(
DmaRxInterrupt::DescriptorError
Expand Down
8 changes: 4 additions & 4 deletions esp-hal/src/dma/pdma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,10 @@ macro_rules! ImplSpiChannel {
}

impl DmaChannelExt for [<Spi $num DmaChannel>] {
fn get_rx_interrupts() -> impl InterruptAccess<DmaRxInterrupt> {
fn rx_interrupts() -> impl InterruptAccess<DmaRxInterrupt> {
SpiDmaRxChannelImpl(Self {})
}
fn get_tx_interrupts() -> impl InterruptAccess<DmaTxInterrupt> {
fn tx_interrupts() -> impl InterruptAccess<DmaTxInterrupt> {
SpiDmaTxChannelImpl(Self {})
}
}
Expand Down Expand Up @@ -780,10 +780,10 @@ macro_rules! ImplI2sChannel {
}

impl DmaChannelExt for [<I2s $num DmaChannel>] {
fn get_rx_interrupts() -> impl InterruptAccess<DmaRxInterrupt> {
fn rx_interrupts() -> impl InterruptAccess<DmaRxInterrupt> {
I2sDmaRxChannelImpl(Self {})
}
fn get_tx_interrupts() -> impl InterruptAccess<DmaTxInterrupt> {
fn tx_interrupts() -> impl InterruptAccess<DmaTxInterrupt> {
I2sDmaTxChannelImpl(Self {})
}
}
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/src/gpio/interconnect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl InputSignal {
}

/// Returns the current signal level.
pub fn get_level(&self) -> Level {
pub fn level(&self) -> Level {
self.is_input_high(private::Internal).into()
}

Expand Down
Loading