diff --git a/esp-hal/CHANGELOG.md b/esp-hal/CHANGELOG.md index 49c9c125654..3979003ea11 100644 --- a/esp-hal/CHANGELOG.md +++ b/esp-hal/CHANGELOG.md @@ -52,7 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - More interrupts are available in `esp_hal::spi::master::SpiInterrupt`, add `enable_listen`,`interrupts` and `clear_interrupts` for ESP32/ESP32-S2 (#2833) - The `ExtU64` and `RateExtU32` traits have been added to `esp_hal::time` (#2845) -- Added `tsens::TemperatureSensor` peripheral for ESP32C6 +- Added `tsens::TemperatureSensor` peripheral for ESP32C6 and ESP32C3 (#2875) ### Changed diff --git a/esp-hal/src/soc/esp32c3/peripherals.rs b/esp-hal/src/soc/esp32c3/peripherals.rs index 00e6548a294..10180d39077 100644 --- a/esp-hal/src/soc/esp32c3/peripherals.rs +++ b/esp-hal/src/soc/esp32c3/peripherals.rs @@ -52,6 +52,7 @@ crate::peripherals! { SW_INTERRUPT <= virtual, TIMG0 <= TIMG0, TIMG1 <= TIMG1, + TSENS <= virtual, TWAI0 <= TWAI0, UART0 <= UART0, UART1 <= UART1, diff --git a/esp-hal/src/system.rs b/esp-hal/src/system.rs index c821a60a3da..38c2459cc9d 100755 --- a/esp-hal/src/system.rs +++ b/esp-hal/src/system.rs @@ -401,6 +401,10 @@ impl PeripheralClockControl { Peripheral::Systimer => { perip_clk_en0.modify(|_, w| w.systimer_clk_en().bit(enable)); } + #[cfg(tsens)] + Peripheral::Tsens => { + perip_clk_en1.modify(|_, w| w.tsens_clk_en().bit(enable)); + } } } @@ -613,11 +617,16 @@ impl PeripheralClockControl { perip_rst_en0.modify(|_, w| w.systimer_rst().set_bit()); perip_rst_en0.modify(|_, w| w.systimer_rst().clear_bit()); } - #[cfg(tsens)] + #[cfg(all(tsens, esp32c6))] Peripheral::Tsens => { perip_rst_en0.modify(|_, w| w.tsens_rst().set_bit()); perip_rst_en0.modify(|_, w| w.tsens_rst().clear_bit()); } + #[cfg(all(tsens, esp32c3))] + Peripheral::Tsens => { + perip_rst_en1.modify(|_, w| w.tsens_rst().set_bit()); + perip_rst_en1.modify(|_, w| w.tsens_rst().clear_bit()); + } }); } } diff --git a/esp-hal/src/tsens.rs b/esp-hal/src/tsens.rs index 97b55947094..1ef12812956 100644 --- a/esp-hal/src/tsens.rs +++ b/esp-hal/src/tsens.rs @@ -72,6 +72,9 @@ impl<'d> TemperatureSensor<'d> { // Power Up apb_saradc.tsens_ctrl().write(|w| w.pu().set_bit()); + // Default to XTAL_CLK source, as it works out of the box on both esp32c6 and esp32c3 + apb_saradc.tsens_ctrl2().write(|w| w.clk_sel().set_bit()); + Self { _guard: guard, _peripheral: peripheral, diff --git a/esp-metadata/devices/esp32c3.toml b/esp-metadata/devices/esp32c3.toml index 08a62907cb3..2b43f5cad1d 100644 --- a/esp-metadata/devices/esp32c3.toml +++ b/esp-metadata/devices/esp32c3.toml @@ -52,6 +52,7 @@ symbols = [ "phy", "bt", "wifi", + "tsens", # ROM capabilities "rom_crc_le", diff --git a/examples/src/bin/temperature_sensor.rs b/examples/src/bin/temperature_sensor.rs index a6e0beadefa..63d066b2c79 100644 --- a/examples/src/bin/temperature_sensor.rs +++ b/examples/src/bin/temperature_sensor.rs @@ -1,7 +1,7 @@ //! This example uses the internal temperature sensor to measure the chip's temperature //! -//% CHIPS: esp32c6 +//% CHIPS: esp32c6 esp32c3 #![no_std] #![no_main] @@ -12,6 +12,7 @@ use esp_println::println; #[entry] fn main() -> ! { + esp_println::logger::init_logger_from_env(); let peripherals = esp_hal::init(esp_hal::Config::default()); let temperature_sensor = TemperatureSensor::new(peripherals.TSENS);