Skip to content

Commit 8280d36

Browse files
committed
More exploration/debug
1 parent 444e391 commit 8280d36

File tree

4 files changed

+126
-75
lines changed

4 files changed

+126
-75
lines changed

esp-hal/Cargo.toml

Lines changed: 91 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,122 @@
11
[package]
2-
name = "esp-hal"
3-
version = "1.0.0-beta.1"
4-
edition = "2024"
5-
rust-version = "1.88.0"
6-
description = "Bare-metal HAL for Espressif devices"
2+
name = "esp-hal"
3+
version = "1.0.0-beta.1"
4+
edition = "2024"
5+
rust-version = "1.88.0"
6+
description = "Bare-metal HAL for Espressif devices"
77
documentation = "https://docs.espressif.com/projects/rust/esp-hal/latest/"
8-
keywords = ["embedded", "embedded-hal", "esp32", "espressif", "hal"]
9-
categories = ["embedded", "hardware-support", "no-std"]
10-
repository = "https://github.com/esp-rs/esp-hal"
11-
license = "MIT OR Apache-2.0"
12-
exclude = [ "api-baseline", "MIGRATING-*", "CHANGELOG.md" ]
8+
keywords = ["embedded", "embedded-hal", "esp32", "espressif", "hal"]
9+
categories = ["embedded", "hardware-support", "no-std"]
10+
repository = "https://github.com/esp-rs/esp-hal"
11+
license = "MIT OR Apache-2.0"
12+
exclude = ["api-baseline", "MIGRATING-*", "CHANGELOG.md"]
1313

1414
[package.metadata.docs.rs]
1515
default-target = "riscv32imac-unknown-none-elf"
16-
features = ["esp32c6", "unstable"]
17-
rustdoc-args = ["--cfg", "docsrs"]
16+
features = ["esp32c6", "unstable"]
17+
rustdoc-args = ["--cfg", "docsrs"]
1818

1919
[lib]
2020
bench = false
21-
test = false
21+
test = false
2222

2323
[dependencies]
24-
bitflags = "2.9.0"
25-
bytemuck = "1.22.0"
26-
cfg-if = "1.0.0"
27-
critical-section = { version = "1.2.0", features = ["restore-state-u32"] }
28-
embedded-hal = "1.0.0"
29-
embedded-hal-async = "1.0.0"
30-
enumset = "1.1.6"
31-
paste = "1.0.15"
32-
portable-atomic = { version = "1.11.0", default-features = false }
33-
34-
esp-rom-sys = { version = "0.1.0", path = "../esp-rom-sys" }
24+
bitflags = "2.9.0"
25+
bytemuck = "1.22.0"
26+
cfg-if = "1.0.0"
27+
critical-section = { version = "1.2.0", features = ["restore-state-u32"] }
28+
embedded-hal = "1.0.0"
29+
embedded-hal-async = "1.0.0"
30+
enumset = "1.1.6"
31+
paste = "1.0.15"
32+
portable-atomic = { version = "1.11.0", default-features = false }
33+
34+
esp-rom-sys = { version = "0.1.0", path = "../esp-rom-sys" }
3535

3636
# Unstable dependencies that are not (strictly) part of the public API
37-
bitfield = "0.19.0"
38-
delegate = "0.13.3"
39-
document-features = "0.2.11"
40-
embassy-futures = "0.1.1"
41-
embassy-sync = "0.6.2"
42-
fugit = "0.3.7"
43-
instability = "0.3.7"
44-
strum = { version = "0.27.1", default-features = false, features = ["derive"] }
45-
46-
esp-config = { version = "0.4.0", path = "../esp-config" }
47-
esp-metadata-generated = { version = "0.0.1", path = "../esp-metadata-generated" }
48-
procmacros = { version = "0.18.0", package = "esp-hal-procmacros", path = "../esp-hal-procmacros" }
37+
bitfield = "0.19.0"
38+
delegate = "0.13.3"
39+
document-features = "0.2.11"
40+
embassy-futures = "0.1.1"
41+
embassy-sync = "0.6.2"
42+
fugit = "0.3.7"
43+
instability = "0.3.7"
44+
strum = { version = "0.27.1", default-features = false, features = ["derive"] }
45+
46+
esp-config = { version = "0.4.0", path = "../esp-config" }
47+
esp-metadata-generated = { version = "0.0.1", path = "../esp-metadata-generated" }
48+
procmacros = { version = "0.18.0", package = "esp-hal-procmacros", path = "../esp-hal-procmacros" }
4949

5050
# Dependencies that are optional because they are used by unstable drivers.
5151
# They are needed when using the `unstable` feature.
52-
digest = { version = "0.10.7", default-features = false, optional = true }
53-
embassy-usb-driver = { version = "0.1.0", optional = true }
52+
digest = { version = "0.10.7", default-features = false, optional = true }
53+
embassy-usb-driver = { version = "0.1.0", optional = true }
5454
embassy-usb-synopsys-otg = { version = "0.2.0", optional = true }
55-
embedded-can = { version = "0.4.1", optional = true }
56-
esp-synopsys-usb-otg = { version = "0.4.2", optional = true }
57-
nb = { version = "1.1.0", optional = true }
55+
embedded-can = { version = "0.4.1", optional = true }
56+
esp-synopsys-usb-otg = { version = "0.4.2", optional = true }
57+
nb = { version = "1.1.0", optional = true }
5858

5959
# Logging interfaces, they are mutually exclusive so they need to be behind separate features.
60-
defmt = { version = "1.0.1", optional = true }
61-
log-04 = { package = "log", version = "0.4.27", optional = true }
60+
defmt = { version = "1.0.1", optional = true }
61+
log-04 = { package = "log", version = "0.4.27", optional = true }
6262

6363
# Optional dependencies that enable ecosystem support.
6464
# We could support individually enabling them, but there is no big downside to just
6565
# enabling them all via the `unstable` feature.
66-
embassy-embedded-hal = { version = "0.3.0", optional = true }
67-
embedded-io = { version = "0.6.1", optional = true }
68-
embedded-io-async = { version = "0.6.1", optional = true }
69-
rand_core-06 = { package = "rand_core", version = "0.6.4", optional = true }
70-
rand_core-09 = { package = "rand_core", version = "0.9.0", optional = true }
71-
ufmt-write = { version = "0.1.0", optional = true }
66+
embassy-embedded-hal = { version = "0.3.0", optional = true }
67+
embedded-io = { version = "0.6.1", optional = true }
68+
embedded-io-async = { version = "0.6.1", optional = true }
69+
rand_core-06 = { package = "rand_core", version = "0.6.4", optional = true }
70+
rand_core-09 = { package = "rand_core", version = "0.9.0", optional = true }
71+
ufmt-write = { version = "0.1.0", optional = true }
7272

7373
# IMPORTANT:
7474
# Each supported device MUST have its PAC included below along with a
7575
# corresponding feature.
76-
esp32 = { version = "0.38.0", features = ["critical-section", "rt"], optional = true }
77-
esp32c2 = { version = "0.27.0", features = ["critical-section", "rt"], optional = true }
78-
esp32c3 = { version = "0.30.0", features = ["critical-section", "rt"], optional = true }
79-
esp32c6 = { version = "0.21.0", features = ["critical-section", "rt"], optional = true }
80-
esp32h2 = { version = "0.17.0", features = ["critical-section", "rt"], optional = true }
81-
esp32s2 = { version = "0.29.0", features = ["critical-section", "rt"], optional = true }
82-
esp32s3 = { version = "0.33.0", features = ["critical-section", "rt"], optional = true }
76+
esp32 = { version = "0.38.0", features = [
77+
"critical-section",
78+
"rt",
79+
], optional = true }
80+
esp32c2 = { version = "0.27.0", features = [
81+
"critical-section",
82+
"rt",
83+
], optional = true }
84+
esp32c3 = { version = "0.30.0", features = [
85+
"critical-section",
86+
"rt",
87+
], optional = true }
88+
esp32c6 = { version = "0.21.0", features = [
89+
"critical-section",
90+
"rt",
91+
], optional = true }
92+
esp32h2 = { version = "0.17.0", features = [
93+
"critical-section",
94+
"rt",
95+
], optional = true }
96+
esp32s2 = { path = "../../esp-pacs/esp32s2", features = [
97+
"critical-section",
98+
"rt",
99+
], optional = true }
100+
esp32s3 = { version = "0.33.0", features = [
101+
"critical-section",
102+
"rt",
103+
], optional = true }
83104

84105
[target.'cfg(target_arch = "riscv32")'.dependencies]
85-
riscv = { version = "0.12.1" }
86-
esp-riscv-rt = { version = "0.11.0", path = "../esp-riscv-rt", optional = true }
106+
riscv = { version = "0.12.1" }
107+
esp-riscv-rt = { version = "0.11.0", path = "../esp-riscv-rt", optional = true }
87108

88109
[target.'cfg(target_arch = "xtensa")'.dependencies]
89-
xtensa-lx = { version = "0.11.0", path = "../xtensa-lx" }
90-
xtensa-lx-rt = { version = "0.19.0", path = "../xtensa-lx-rt", optional = true }
110+
xtensa-lx = { version = "0.11.0", path = "../xtensa-lx" }
111+
xtensa-lx-rt = { version = "0.19.0", path = "../xtensa-lx-rt", optional = true }
91112

92113
[build-dependencies]
93-
cfg-if = "1.0.0"
94-
esp-metadata-generated = { version = "0.0.1", path = "../esp-metadata-generated", features = ["build-script"] }
95-
esp-config = { version = "0.4.0", path = "../esp-config", features = ["build"] }
96-
serde = { version = "1.0.219", default-features = false, features = ["derive"] }
114+
cfg-if = "1.0.0"
115+
esp-metadata-generated = { version = "0.0.1", path = "../esp-metadata-generated", features = [
116+
"build-script",
117+
] }
118+
esp-config = { version = "0.4.0", path = "../esp-config", features = ["build"] }
119+
serde = { version = "1.0.219", default-features = false, features = ["derive"] }
97120

98121
[dev-dependencies]
99122
jiff = { version = "0.2.10", default-features = false, features = ["static"] }
@@ -118,7 +141,7 @@ __usb_otg = [
118141

119142
# Chip Support Feature Flags
120143
# Target the ESP32.
121-
esp32 = [
144+
esp32 = [
122145
"dep:esp32",
123146
"procmacros/rtc-slow",
124147
"esp-rom-sys/esp32",
@@ -247,4 +270,6 @@ requires-unstable = []
247270
mixed_attributes_style = "allow"
248271

249272
[lints.rust]
250-
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(host_os, values("windows"))'] }
273+
unexpected_cfgs = { level = "warn", check-cfg = [
274+
'cfg(host_os, values("windows"))',
275+
] }

esp-hal/src/analog/adc/calibration/line.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ where
6666
.map(|code| (code, ADCI::cal_mv(atten)))
6767
.unwrap_or_else(|| {
6868
// As a fallback try to calibrate using reference voltage source.
69-
// This method is not too good because actual reference voltage may varies
69+
// This method is not too good because actual reference voltage varies
7070
// in range 1000..=1200 mV and this value currently cannot be read from efuse.
7171
(
7272
AdcConfig::<ADCI>::adc_calibrate(atten, AdcCalSource::Ref),
@@ -114,7 +114,8 @@ where
114114
let transformed = {
115115
use defmt::println;
116116
println!(
117-
"Tranforming {} + {} into {}",
117+
"Transforming {} -> {} + {} into {}",
118+
val,
118119
transformed,
119120
self.offset,
120121
(transformed as i32 + self.offset, 0)

esp-hal/src/analog/adc/xtensa.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::{AdcCalScheme, AdcCalSource, AdcChannel, AdcConfig, AdcPin, Attenuati
66
#[cfg(any(esp32s2, esp32s3))]
77
use crate::efuse::Efuse;
88
use crate::{
9-
peripherals::{APB_SARADC, SENS},
9+
peripherals::{APB_SARADC, I2C_ANA_MST, LPWR, SENS},
1010
soc::regi2c,
1111
system::{GenericPeripheralGuard, Peripheral},
1212
};
@@ -252,6 +252,19 @@ impl RegisterAccess for crate::peripherals::ADC1<'_> {
252252
fn set_init_code(data: u16) {
253253
let [msb, lsb] = data.to_be_bytes();
254254

255+
use defmt::println;
256+
println!("Writing {} HIGH={} LOW={}", data, msb, lsb);
257+
258+
LPWR::regs().ana_conf().modify(|_, w| {
259+
w.sar_i2c_force_pd().clear_bit();
260+
w.sar_i2c_force_pu().set_bit()
261+
});
262+
I2C_ANA_MST::regs()
263+
.config1()
264+
.modify(|_, w| w.sar().clear_bit());
265+
I2C_ANA_MST::regs()
266+
.config0()
267+
.modify(|_, w| w.sar_cfg2().set_bit());
255268
regi2c::ADC_SAR1_INITIAL_CODE_HIGH.write_field(msb);
256269
regi2c::ADC_SAR1_INITIAL_CODE_LOW.write_field(lsb);
257270
}
@@ -477,6 +490,8 @@ where
477490
.sar_amp_ctrl2()
478491
.modify(|_, w| unsafe { w.sar_amp_wait3().bits(1) });
479492

493+
// TODO: ADC2 arbiter: https://github.com/espressif/esp-idf/blob/84df38aab927d50f7ee22d34516d7263f3e96068/components/hal/adc_oneshot_hal.c#L92
494+
480495
Adc {
481496
_adc: adc_instance,
482497
active_channel: None,
@@ -500,6 +515,8 @@ where
500515

501516
// Get converted value
502517
let converted_value = ADCI::read_data();
518+
use defmt::println;
519+
println!("Actual raw={}", converted_value);
503520
ADCI::reset();
504521

505522
// Postprocess converted value according to calibration scheme used for pin
@@ -557,6 +574,8 @@ where
557574
PIN: AdcChannel,
558575
CS: AdcCalScheme<ADCI>,
559576
{
577+
ADCI::set_en_pad(PIN::CHANNEL);
578+
560579
// Set ADC unit calibration according used scheme for pin
561580
let init_code = pin.cal_scheme.adc_cal();
562581
if self.last_init_code != init_code {
@@ -566,8 +585,6 @@ where
566585
self.last_init_code = init_code;
567586
}
568587

569-
ADCI::set_en_pad(PIN::CHANNEL);
570-
571588
ADCI::clear_start_sample();
572589
ADCI::start_sample();
573590
}

esp-hal/src/soc/esp32s2/regi2c.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,18 +196,26 @@ pub(crate) fn regi2c_read(block: u8, _host_id: u8, reg_add: u8) -> u8 {
196196
I2C_ANA_MST::regs().config2().read().data().bits()
197197
}
198198

199-
pub(crate) fn regi2c_write(block: u8, _host_id: u8, reg_add: u8, data: u8) {
199+
pub(crate) fn regi2c_write(block: u8, host_id: u8, reg_add: u8, data: u8) {
200+
use defmt::println;
200201
i2c_rtc_enable_block(block);
201202

202-
I2C_ANA_MST::regs().config2().modify(|_, w| unsafe {
203-
w.slave_id()
203+
I2C_ANA_MST::regs().config2().write(|w| unsafe {
204+
let v = w
205+
.slave_id()
204206
.bits(block)
205207
.addr()
206208
.bits(reg_add)
207209
.wr_cntl()
208210
.bit(true)
209211
.data()
210-
.bits(data)
212+
.bits(data);
213+
214+
println!(
215+
"regi2c_write({=u8:#x}, {=u8:#x}, {=u8:#x}, {=u8:#x}) = {=u32:#x}",
216+
block, host_id, reg_add, data, v.bits
217+
);
218+
v
211219
});
212220

213221
while I2C_ANA_MST::regs().config2().read().busy().bit_is_set() {}

0 commit comments

Comments
 (0)