Skip to content

Commit 99cf766

Browse files
committed
feat: add basic support for temperature sensor (tsens) for esp32c3
1 parent 72e6c1f commit 99cf766

File tree

6 files changed

+18
-3
lines changed

6 files changed

+18
-3
lines changed

esp-hal/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5252
- More interrupts are available in `esp_hal::spi::master::SpiInterrupt`, add `enable_listen`,`interrupts` and `clear_interrupts` for ESP32/ESP32-S2 (#2833)
5353

5454
- The `ExtU64` and `RateExtU32` traits have been added to `esp_hal::time` (#2845)
55-
- Added `tsens::TemperatureSensor` peripheral for ESP32C6
55+
- Added `tsens::TemperatureSensor` peripheral for ESP32C6 and ESP32C3 (#2875)
5656

5757
### Changed
5858

esp-hal/src/soc/esp32c3/peripherals.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ crate::peripherals! {
5252
SW_INTERRUPT <= virtual,
5353
TIMG0 <= TIMG0,
5454
TIMG1 <= TIMG1,
55+
TSENS <= virtual,
5556
TWAI0 <= TWAI0,
5657
UART0 <= UART0,
5758
UART1 <= UART1,

esp-hal/src/system.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,10 @@ impl PeripheralClockControl {
401401
Peripheral::Systimer => {
402402
perip_clk_en0.modify(|_, w| w.systimer_clk_en().bit(enable));
403403
}
404+
#[cfg(tsens)]
405+
Peripheral::Tsens => {
406+
perip_clk_en1.modify(|_, w| w.tsens_clk_en().bit(enable));
407+
}
404408
}
405409
}
406410

@@ -613,11 +617,16 @@ impl PeripheralClockControl {
613617
perip_rst_en0.modify(|_, w| w.systimer_rst().set_bit());
614618
perip_rst_en0.modify(|_, w| w.systimer_rst().clear_bit());
615619
}
616-
#[cfg(tsens)]
620+
#[cfg(all(tsens, esp32c6))]
617621
Peripheral::Tsens => {
618622
perip_rst_en0.modify(|_, w| w.tsens_rst().set_bit());
619623
perip_rst_en0.modify(|_, w| w.tsens_rst().clear_bit());
620624
}
625+
#[cfg(all(tsens, esp32c3))]
626+
Peripheral::Tsens => {
627+
perip_rst_en1.modify(|_, w| w.tsens_rst().set_bit());
628+
perip_rst_en1.modify(|_, w| w.tsens_rst().clear_bit());
629+
}
621630
});
622631
}
623632
}

esp-hal/src/tsens.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ impl<'d> TemperatureSensor<'d> {
7272
// Power Up
7373
apb_saradc.tsens_ctrl().write(|w| w.pu().set_bit());
7474

75+
// Default to XTAL_CLK source, as it works out of the box on both esp32c6 and esp32c3
76+
apb_saradc.tsens_ctrl2().write(|w| w.clk_sel().set_bit());
77+
7578
Self {
7679
_guard: guard,
7780
_peripheral: peripheral,

esp-metadata/devices/esp32c3.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ symbols = [
5252
"phy",
5353
"bt",
5454
"wifi",
55+
"tsens",
5556

5657
# ROM capabilities
5758
"rom_crc_le",

examples/src/bin/temperature_sensor.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! This example uses the internal temperature sensor to measure the chip's temperature
22
//!
33
4-
//% CHIPS: esp32c6
4+
//% CHIPS: esp32c6 esp32c3
55

66
#![no_std]
77
#![no_main]
@@ -12,6 +12,7 @@ use esp_println::println;
1212

1313
#[entry]
1414
fn main() -> ! {
15+
esp_println::logger::init_logger_from_env();
1516
let peripherals = esp_hal::init(esp_hal::Config::default());
1617

1718
let temperature_sensor = TemperatureSensor::new(peripherals.TSENS);

0 commit comments

Comments
 (0)