Skip to content

Commit

Permalink
Merge branch 'main' into calibration-calc-overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
yuri-ncs authored Feb 5, 2025
2 parents 2b112b8 + 3bca047 commit e1dd6a3
Show file tree
Hide file tree
Showing 120 changed files with 1,314 additions and 915 deletions.
11 changes: 5 additions & 6 deletions esp-hal-embassy/src/time_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use embassy_time_driver::Driver;
use esp_hal::{
interrupt::{InterruptHandler, Priority},
sync::Locked,
time::{now, ExtU64},
time::{Duration, Instant},
timer::OneShotTimer,
Blocking,
};
Expand Down Expand Up @@ -203,11 +203,10 @@ impl EmbassyTimer {
/// Returns `true` if the timer was armed, `false` if the timestamp is in
/// the past.
fn arm(timer: &mut Timer, timestamp: u64) -> bool {
let now = now().duration_since_epoch();
let ts = timestamp.micros();
let now = Instant::now().duration_since_epoch().as_micros();

if ts > now {
let timeout = ts - now;
if timestamp > now {
let timeout = Duration::from_micros(timestamp - now);
unwrap!(timer.schedule(timeout));
true
} else {
Expand Down Expand Up @@ -295,7 +294,7 @@ impl EmbassyTimer {

impl Driver for EmbassyTimer {
fn now(&self) -> u64 {
now().ticks()
Instant::now().duration_since_epoch().as_micros()
}

fn schedule_wake(&self, at: u64, waker: &core::task::Waker) {
Expand Down
4 changes: 3 additions & 1 deletion esp-hal-embassy/src/timer_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ impl TimerQueue {
}

pub fn dispatch(&self) {
let now = esp_hal::time::now().ticks();
let now = esp_hal::time::Instant::now()
.duration_since_epoch()
.as_micros();
self.arm_alarm(now);
}

Expand Down
8 changes: 7 additions & 1 deletion esp-hal/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added

- SPI: Added support for 3-wire SPI (#2919)
- UART: Add separate config for Rx and Tx (#2965)
- Added accessor methods to config structs (#3011)
- `esp_hal::time::{Rate, Duration, Instant}` (#3083)
- Async support for ADC oneshot reads for ESP32C2, ESP32C3, ESP32C6 and ESP32H2 (#2925, #3082)
- `ESP_HAL_CONFIG_XTAL_FREQUENCY` configuration. For now, chips other than ESP32 and ESP32-C2 have a single option only. (#3054)

### Changed

Expand All @@ -33,6 +36,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `flip-link` feature is now a config option (`ESP_HAL_CONFIG_FLIP_LINK`) (#3001)
- Migrate AES driver to DMA move API (#3084)
- Removed features `psram-quad` and `psram-octal` - replaced by `psram` and the `ESP_HAL_CONFIG_PSRAM_MODE` (`quad`/`octal`) (#3001)
- The `esp_hal::time` module no longer reexports `fugit` types (#3083)

- I2C: Async functions are postfixed with `_async`, non-async functions are available in async-mode (#3056)

Expand All @@ -42,14 +46,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed an issue that caused LCD_CAM drivers to turn off their clocks unexpectedly (#3007)
- Fixed an issue where DMA-driver peripherals started transferring before the data was ready (#3003)
- Fixed an issue where ADC Curve Calibration overflows when converting from a value > 3095 (#3061)

- Fixed an issue on ESP32 and S2 where short asynchronous Timer delays would never resolve (#3093)
- ESP32-S2: Fixed linker script (#3096)

### Removed

- Removed `Pin`, `RtcPin` and `RtcPinWithResistors` implementations from `Flex` (#2938)
- OutputOpenDrain has been removed (#3029)
- The fields of config structs are no longer public (#3011)
- Removed the dysfunctional `DmaChannel::set_priority` function (#3088)
- `esp_hal::time::now()`, which has been replaced by `esp_hal::time::Instant::now()` (#3083)

## [0.23.1] - 2025-01-15

Expand Down
1 change: 1 addition & 0 deletions esp-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ embedded-io = { version = "0.6.1", optional = true }
embedded-io-async = { version = "0.6.1", optional = true }
enumset = "1.1.5"
esp-build = { version = "0.2.0", path = "../esp-build" }
esp-config = { version = "0.3.0", path = "../esp-config" }
esp-synopsys-usb-otg = { version = "0.4.2", optional = true, features = ["fs", "esp32sx"] }
fugit = "0.3.7"
instability = "0.3.7"
Expand Down
15 changes: 15 additions & 0 deletions esp-hal/MIGRATING-0.23.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ All async functions now include the `_async` postfix. Additionally the non-async
```diff
- let result = i2c.write_read(0x77, &[0xaa], &mut data).await;
+ let result = i2c.write_read_async(0x77, &[0xaa], &mut data).await;
```

## ADC Changes

Expand All @@ -277,3 +278,17 @@ NOTE: Async support is only supported in ESP32C3 and ESP32C6 for now
- Adc<'d, ADC>
+ Adc<'d, ADC, Blocking>
```

## time API changes

ESP-HAL no longer publicly exposes `fugit` and no longer exposes the concept of a `tick`.
This comes with a number of changes:

- The `RateExtU32` and similar traits are no longer used, which means `.kHz()` and similar suffix
conversions are no longer available. A number of matching constructors are available. For example,
instead of `1.MHz()` you need to write `Rate::from_mhz(1)`.
- Methods on `esp_hal::time` types are named differently.
- Getters are prefixed with `as_`, e.g. `Duration::as_secs`.
- Constructors are prefixed with `from`, e.g. `Rate::from_mhz`.
- A number of functions that convert from a number into a time type (e.g. `Duration::from_ticks`)
are not available. Use conversions from physical units of time, like `Duration::from_millis`.
24 changes: 23 additions & 1 deletion esp-hal/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,28 @@ fn main() -> Result<(), Box<dyn Error>> {
Value::Bool(false),
None
),
// Ideally, we should be able to set any clock frequency for any chip. However, currently
// only the 32 and C2 implements any sort of configurability, and the rest have a fixed
// clock frequeny.
// TODO: only show this configuration for chips that have multiple valid options.
(
"xtal-frequency",
"The frequency of the crystal oscillator, in MHz. Set to `auto` to automatically detect the frequency. `auto` may not be able to identify the clock frequency in some cases. Also, configuring a specific frequency may increase performance slightly.",
Value::String(match device_name {
"esp32" | "esp32c2" => String::from("auto"),
// The rest has only one option
"esp32c3" | "esp32c6" | "esp32s2" | "esp32s3" => String::from("40"),
"esp32h2" => String::from("32"),
_ => unreachable!(),
}),
Some(Validator::Enumeration(match device_name {
"esp32" | "esp32c2" => vec![String::from("auto"), String::from("26"), String::from("40")],
// The rest has only one option
"esp32c3" | "esp32c6" | "esp32s2" | "esp32s3" => vec![String::from("40")],
"esp32h2" => vec![String::from("32")],
_ => unreachable!(),
})),
),
// ideally we should only offer this for ESP32 but the config system doesn't
// support per target configs, yet
(
Expand All @@ -98,7 +120,7 @@ fn main() -> Result<(), Box<dyn Error>> {
"(ESP32, ESP32-S2 and ESP32-S3 only, `octal` is only supported for ESP32-S3) SPIRAM chip mode",
Value::String(String::from("quad")),
Some(Validator::Enumeration(
vec![String::from("quad"), String::from("octal")]
vec![String::from("quad"), String::from("octal")]
)),
)
], true);
Expand Down
2 changes: 1 addition & 1 deletion esp-hal/ld/esp32s2/esp32s2.x
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ INCLUDE exception.x
SECTIONS {
.rwdata_dummy (NOLOAD) : ALIGN(4)
{
. = ORIGIN(RWDATA) + SIZEOF(.rwtext) + SIZEOF(.rwtext.wifi);
. = . + SIZEOF(.rwtext) + SIZEOF(.rwtext.wifi);
} > RWDATA
}
INSERT BEFORE .data;
Expand Down
1 change: 1 addition & 0 deletions esp-hal/src/clock/clocks_ll/esp32s2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub(crate) fn set_cpu_clock(cpu_clock_speed: CpuClock) {
} as u8)
});

// FIXME untangle this
let value = (((80 * MHZ) >> 12) & UINT16_MAX) | ((((80 * MHZ) >> 12) & UINT16_MAX) << 16);
rtc_cntl.store5().modify(|_, w| w.scratch5().bits(value));
}
Expand Down
5 changes: 1 addition & 4 deletions esp-hal/src/clock/clocks_ll/esp32s3.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use core::ops::Div;

use crate::{
clock::{Clock, CpuClock},
rom,
Expand All @@ -24,6 +22,5 @@ pub(crate) fn set_cpu_clock(cpu_clock_speed: CpuClock) {
});
}

let ticks_per_us = cpu_clock_speed.frequency().div(1_000_000);
rom::ets_update_cpu_frequency_rom(ticks_per_us.raw());
rom::ets_update_cpu_frequency_rom(cpu_clock_speed.frequency().as_mhz());
}
Loading

0 comments on commit e1dd6a3

Please sign in to comment.