88 Commits

Author SHA1 Message Date
ivmarkov
a67bf2fd3d
Compatibility with ESP-IDF 5.4.x, 5.5.x and master (#541)
* Compatibility with ESP-IDF 4.x, 5.x and master

* Run main CI againzst released ESP-IDF
2025-08-13 09:02:33 +03:00
ivmarkov
9459b65bbe
Remove the experimental support from the SD card (#540) 2025-08-11 16:27:35 +02:00
ivmarkov
9f65b7a6d9 Nit: move the check at the top of the file 2025-01-01 19:35:10 +00:00
ivmarkov
0c912c8600
Expose the USB-serial-jtag peripheral (#503)
* add BlockingIoDriver to make stdin/out/err calls blocking

* gate sys imports

* use at least enumset 1.1.4 to make EnumSet::empty() a const fn

* add missing trait impl

* fix wrong macro usage

* fix macro

* Remove all VFS code in prep to move it to esp_idf_svc::io::vfs

---------

Co-authored-by: Frederick Vollbrecht <frederick@vollbrecht.cc>
2025-01-01 11:13:11 +02:00
GamerBene19
a619f13871
Add support for ESP internal temperature sensor (#337)
* Add first version of temp sensor driver

Code is very rudimentary and still suspect to change.
Notably, error handling is not implemented yet.

* Change cfg attribute to not any

* Rename TemperatureSensor to TemperatureSensorDriver

* Switch to `core::ptr`

* Add error handling

* Build the internal temperature sensor only on supported targets

* Fix the derives in TemperatureSensorConfig, TemperatureSensorClockSource

* Implement From<TemperatureSensorConfig> for temperature_sensor_config_t

* Use right clocks for temperature sensor depending on target

* Rename config and move it into own module

* Provide const new constructor for temperature sensor config

* Change config argument to be a reference

* Rename TemperatureSensor to TempSensor

* Avoid cloning config in temp driver constructor

* Add back derived Copy trait for TempSensorClockSource

* Add non_exhaustive option to TempSensorConfig

* Add temp sensor peripheral

* Cause panic if uninstalling the temp driver fails

* Implement Send for TempSensorDriver

* Make use of esp_idf_soc_temp_sensor_supported

* Add an example for temperature_sensor

---------

Co-authored-by: Luca Barbato <lu_zero@gentoo.org>
2024-09-09 19:46:26 +03:00
DaneSlattery
aa0e257ffe
RMT Onewire Peripheral (#454)
* commit test 1

test commit 2

next device

asd

* try example, haven't built yet

* Add feature flags for legacy RMT examples

Remove references to the ds18b20 specific device.

Add a feature flag `rmt-legacy` that, when enabled, will build the
original rmt modules from v4 of the esp-idf. When disabled, the v5
rmt interface can be used for one wire applications.

Implement the Iterator trait for a device search and use the Iterator
in the example.

* Add more feature guards to examples compile

* Add alternative main functions for examples

* Use std threading

* Add std to thread sleep

* use std duration

* correct use for legacy rmt component

* Remove local bindings and use the esp-idf-sys master

* fix a typo

* Remove esp-idf component inclusion

* Update gitignore

* Fix examples

* mut-ex out the example compilation

* add implementation for temperature readings

* Conditional compile

* esp4.4 compile

* Changes to cargo and config

* Remove OWDevice and simplify API

* Remove phantomdata that is not required

* adjust lifetimes for single search at a time

* Keep RMT peripheral and add channel to onewire

Moves the RMT driver into a private `driver` module, which will only be compiled in rmt-legacy mode.

Also reduce the number of cfg feature flags in examples by wrapping the implementation in a module.

* modularise examples

* Fix for CI

* update example name to make it pop

---------

Co-authored-by: Dane Slattery <dane@polarmonitoring.com>
Co-authored-by: DaneSlattery <dane_s@umantec.net>
2024-08-10 16:11:38 +03:00
ivmarkov
72f6448c64 Fix no_std build 2024-08-05 21:46:52 +00:00
ivmarkov
b186a3be4c Bugfix: sdmmc_card_t needs to be boxed, because ESP IDF takes long living references to it in the VFS layer 2024-08-05 07:39:28 +00:00
ivmarkov
d04dcf5880
SD Card driver; SD Card host drivers (SPI and SDMMC) (#457)
* SD Card driver; SD Card host drivers (SPI and SDMMC)

* fmt

* fix typo

* Fix riscv32 build

* Better names for the GPIO matrix constructors

* Fix CI for esp32s3 and esp32p4

* Fix CI for esp32s3 and esp32p4

* SD-MMC finally works

* Address feedback from code review
2024-07-23 09:58:41 +03:00
ivmarkov
140865a34f Fix CI 2024-05-06 18:37:06 +00:00
empirephoenix
a2bb85c6e7
Enable pcnt for esp32c6 (#407)
* Enable pcnt for esp32c6 as well https://docs.espressif.com/projects/esp-idf/en/stable/esp32c6/api-reference/peripherals/pcnt.html

* Also enable pcnt peripherals for esp32c6

* also initialize the pcnt peripherals

---------

Co-authored-by: Empire <empirephoenix@yahoo.de>
2024-04-21 22:53:51 +03:00
ivmarkov
201ef13ab6 Always use the core prelude 2024-02-21 10:05:52 +00:00
ivmarkov
e79df5a873 Get rid of the riscv-ulp-hal feature 2024-01-18 20:12:27 +00:00
ivmarkov
2e7b0688a9 Allow unknown lints by default 2024-01-12 16:52:53 +00:00
ivmarkov
5532468962 Prep for a new release 2024-01-10 07:31:45 +00:00
ivmarkov
05140a3056 The crate now does build with cargo --all-features 2024-01-05 16:26:26 +00:00
ivmarkov
7206328cef Fix conditionals 2023-10-16 19:36:46 +00:00
ivmarkov
9bd6d8300f SPI async: optimize memory; only enable for non-IRAM ISRs 2023-10-16 19:17:35 +00:00
ivmarkov
4381d62aed ESP IDF 4.4 i2s fixes 2023-10-06 19:02:36 +00:00
ivmarkov
ebeef0fcc8
All executors (#315)
* Support for all async executors

* Make all Notifiucation primitives a public API

* Address a small typo

* Address a small typo

* Fix CI

* Tighten the notify APIs by not taking 0s

* Fix CI

* Fix changelog

* Fix changelog

* Fix the examples

* edge-executor support moved to edge-executor

* wake-from-isr feature for edge-executor

* Fix CI

* Bugfixing

* Clippy
2023-10-06 22:01:20 +03:00
ivmarkov
dd06b698ae Fix CI 2023-10-01 07:17:42 +00:00
David Cuthbert
e6603eb766
Fix building for ESP32C2. (#311)
Fixes https://github.com/esp-rs/esp-idf-hal/issues/282.
2023-09-26 06:41:41 +03:00
David Cuthbert
29360a2fb8
Documentation and API adjustments for I2S (#309)
* Fix mono mode slot mask.

This changes the slot mask configuration in standard mode for
non ESP32/ESP32-S3 chips to use left-channel only mode. This behavior
differs from the ESP-IDF SDK, which appears to be in error due when
a preprocessor macro was renamed.

* Improve I2S documentation.

* Run cargo fmt.

* Fix clippy issues on 4.4.

* Fix another instance of dma_desc for 4.4.

* Add missing doc() attr.
2023-09-23 14:11:00 +03:00
ivmarkov
bed45e741e
Upgrade to e-hal 1.0-rc1 (#295)
* Upgrade to e-hal 1.0-rc1

* e-hal is no longer alpha

* Fix for ESP IDF < 5

* Unite all delay impls in a single module

* Model delays between transactions

* SPI: Make queueing it a bit more readable

* SPI: Plug delays

* Shorten the threshold for the Delay provider

* Clippy

* Fix the examples

* SPI: Detect last transaction in the presence of delays

* SPI: Introduce CsPin

* SPI: Introduce CsPin

* SPI: Mark delays with TODO

* Clippy

* SPI: Rename CsPin to CsCtl

* Transfer_transaction not necessary
2023-09-06 09:36:48 +03:00
ivmarkov
b61a2b11c7 #284 2023-08-22 12:52:05 +00:00
ivmarkov
9fc2e8c61e
Async drivers (#279)
* Continuous mode ADC

* GPIO: Switch to the common notification; remove alloc req for async

* (WIP) async SPI

* Notification callbacks in async SPI

* SPI: Lower the code repetition

* Fix the build

* I2S pre-async simplification

* Async methods for I2S

* SPI: Wait for the transaction to complete on drop

* More flexibility in PinDriver::wait_for

* Remove the gargantuan mutex for now

* Arrays supported as ADC channels

* Fix timeouts

* ADC: measurement shape

* Fix the dependencies

* Fix CI

* ADC: cont config

* ADC: better atten API; fix delays

* ADC: Raw handle access

* I2S: Make config more symmetric with the other drivers

* I2S: Remove unnecessary generics

* Improve the semantics of read/write vrt partial r/w

* Review feedback

* Clippy

* Shorten static array initializers

* Do not glob-import all of esp-idf-sys

* SPI: make notifications non-static

* SPI: Remove the async fetch() hack; extend async support

* Fix the CI

* SPI: Restore WriteIter impl

* Bugfix: tx/rx handles mismatch

* I2S: Utility methods to write the whole buffer

* I2S Bugfix: wrong translation to native format

* More ergonomic API for TickType

* unsubscribe during reset will fail if ISR service is not enabled yet

* Typo

* Same defaults

* No need for unsafe here

Co-authored-by: Dominic Fischer <14130965+Dominaezzz@users.noreply.github.com>

* Assert that ESP_ERR_TIMEOUT should never happen

* Safe variant of completion

* ADC: wrong timeout conversion

* Proof of posession of i2s0/spi3 for esp32/esp32s2

* write_async only available on ESP IDF 5+

* Option to transmute the adc buffer to pcm

* ADC: only expose PCM conversion where it is possible (esp32/esp32s2)

* ADC: Fix channel chaining

* ADC: fix the CI

* ADC: Nullify everything

* ADC: as_pcm32 for riscv and esp32s3

* ADC: as_pcm32 for riscv and esp32s3

* ADC: read_raw

* I2S: Proper driver shutdown

* ADC: Fix clippy and compile errors on ESP-IDF 4

* Compat with ESP-IDF master

---------

Co-authored-by: Dominic Fischer <14130965+Dominaezzz@users.noreply.github.com>
2023-08-22 15:39:02 +03:00
David Cuthbert
de7dee4799
Implement I2S (#232)
* Basic structure of the I2S driver.

This does not yet work, but outlines the approach I'm taking to bind
the Rust HAL layer to the ESP-IDF SDK 5.0.

* Fix issues with AtomicBool ordering.

* Add StdClockConfig::from_sample_rate ctor.

This is equivalent to the I2S_STD_CLK_DEFAULT_CONFIG macro, but
much cleaner.

* Add #[inline(always)] where appropriate.

* Add open_tx_channel method.

* Add constructors for StdSlotConfig.

* Add drop impl for I2sDriver.

* Add event handler interface.

I'm not entirely certain I'm happy with this interface. In particular,
there's virtual dispatch involved, and it's called in the context of
an ISR. This shouldn't be a problem, but it would be nice to be able
to avoid it. That might not be possible.

* Fix generics issues with I2S.

This fixes generics issues found with the I2S driver found in
actual use. This requires the changes to esp-idf-sys in
https://github.com/esp-rs/esp-idf-sys/pull/187 to use.

* Pass callback handlers by reference.

This removes some unsafe pointer handling that was previously being
used as a direct transliteration of the equivalent C code.

* Add allow(unused) annotations for PCM/PDM.

These structures will be used when PCM and PDM support is implemented.

* Remove bindings.h.

* Refactoring based on PR comments.

This moves standard mode to its own driver. The channel structs are
no longer separate from the driver; instead, the driver implements
I2sRxChannel and/or I2sTxChannel depending on a generic it takes,
which can be I2sRxSupported and/or I2sTxSupported.

Alas, the separate I2sStdDriverInternal struct is still there. This is
required because it has to be pinned in memory to serve as callback
data for the interrupt handler, while I2sStdDriver can be moved
around as Rust pleases.

Stubs configs have been created for PCM and PDM modes.

* Fix pin usage in doc examples.

* Make traits more ergonomic.

This moves default implementations for I2sRxChannel and I2sTxChannel
into the traits themselves where it makes sense, and will make it
easier to implement the PDM and TDM modes.

This also moves I2sStd{Rx,Tx}Callback into I2s{Rx,Tx}Callback and
removes lifetimes associated with them. It turns out that attempting
to use the lifetimes in any callback implementations suffered from
the self-referential lifetime problem, where the lifetime of the
callback and the lifetime of the driver are the same. Now the driver
owns the callback instead.

* Add notes about bugs with callbacks.

The callback implementation in ESP-IDF appears to be broken. The
DMA buffers need to be released to i2s_dma_rx/tx_callback at some
point, but it is impossible to do this since the message queue is
hidden behind the opaque i2s_chan_handle_t type.

* Comment fix.

* Move channel to main i2s.rs.

This moves the channel implementation (which turns out to be
generic) to the main i2s.rs file in preparation for PDM and TDM mode
implementation.

* Add pulse density modulation support for I2S.

This driver is more complex than the standard mode driver since not
support for PDM mode is not universal across the ESP32 line.
In particular, the ESP32S2 does not support PDM mode at all, and the
ESP32C3 only supports PDM transmission.

* Add TDM mode support for I2S.

This adds time-division multiplexing (TDM) for the I2S peripheral.
Note that this is only supported on ESP32C3 and ESP32S3 devices.

* Remove unnecessary pub(super) from config.

This removes unnecessary pub(super) modifiers from various I2S
standard mode config struct fields.

* Compiling for v4.4.x and v5.0.x.

I have not yet tested the v4.4 version, or the PDM/TDM modes on either
version; I need to get some hardware together for this.

* Add drop impl for v4.

* Remove whitespace at EOL

* Derive Default for TdmSlotMask.

This eliminates a clippy error about impl Default being able to be
derived.

* Fix preload_data in v5.1.

This fixes the preload_data default impl on the I2sRxChannel trait
to conform to the C signature.

* Add bclk_div to TdmClkConfig on v5.1.

The ESP-IDF v5.1 driver adds a new field, bclk_div, to the
i2s_tdm_clk_config_t structure that has a default value (8) but can
be overridden by users in case transmits are lagging in target mode.

* Allow multiple PDM RX pins.

Also ran cargo fmt.

* Wrap new_rx_multi in v5.1 cfg.

* Enable no_std builds.

This removes the use of Box when building for no_std at the cost of
static allocations that are incurred whether the I2S driver is used or
not. This is 16 bytes/channel, 32 bytes per I2S device.

* A few cfg fixes for clippy.

* Make unsafe decls match for create_rx/tx.

This isn't strictly necessary in alloc mode, but it makes the code
easier to use.

* Add missing field in clone().

* Actually put comm_fmt in clone().

* Don't create pools on v4.4.

Channels aren't used, so pools aren't needed (and the types aren't
valid).

* Derive Debug, Default.

Add Debug derivations where missing.
Add Default derivations to enums now that MSRV supports them.

* Make callbacks functions.

This makes the rx/tx callbacks into functions instead of traits
per @ivmarkov's recommendations. This helps with a number of ergonomic
issues with the code (particularly around channels and lifetimes).

* Remove PCM compression support.

This mode was only supported in the v4 driver series, and not all that
well at that. This doesn't appear to be a standard I2S operating mode
anyway.

* I2S_PORT_COUNT, UnsafeCallback unused in 4.4.

* Remove duplicate cfg block.

* Use core::slice instead of std::slice.
2023-06-23 08:50:58 +03:00
Jordan Halase
bf4a5afc5f
Add safe abstractions to CRC functions in ESP ROM (#261)
* Add safe abstractions to CRC functions in ESP ROM

* Do not include ROM functions if esp-ulp-hal is enabled

* Run cargo fmt and clippy
2023-06-12 08:49:26 +03:00
ivmarkov
6ba4323e1d Make Clippy happy 2023-05-09 13:41:18 +00:00
ivmarkov
88aee9489f Make Clippy happy 2023-05-09 13:38:50 +00:00
ivmarkov
d5dce7f108 New chips 2023-05-08 20:19:52 +00:00
Frederick Vollbrecht
b739c46b12
Embedded-Hal PR - incoorparate e-hal master changes in spi / i2c / gpio / delay (#224)
* embedded-hal::delay no longer returns Error

* embedded_hal::digital add generic GpioError

* spi: init work: from closure to Operation pattern

* first full implementation

* i2c: remove iter fn droped by e-hal master

* make ci work by temp. refere to e-hal master

* more ci fix

* make clippy happy

* more ci fighting

* gpio: cursed repair of ulp_processor

* fmt

* spi: repair example + get rid of generic's

* dep: change to new e-hal release

* fix e-hal 0.2 comp &  fix bus

* fmt

* clippy

* remove debug artifacts

* test ci with e-hal-nb-alpha.1

* e-hal-nb to alpha.2

* modified comments

* impl e-hal delay to general purpose provider

* use embedded_hal_error macro for riscv-ulp-hal

* typo

* impl pwm alpha10

* fixed wrong return error on async gpio

* duplicated impl error macro for ulp
2023-05-08 20:59:45 +03:00
Daniel Berlin
cbb27dec28
Implement async Wait traits from embedded-hal-async (#218)
* Start work on async

* Fix trailing whitespace in lib.rs

cargo fmt seems to be having an issue with this according to the checks.

* Fix clippy errors, remove useless enable_interrupt call

* Make embedded-hal-async optional

* Remove extra comment in lib.rs

* Rename wait_async to wait_asynch

* Use atomic wakers

* Reduce size of unsafe blocks

* Update for review comments

* Missed a few cfg(nightly)'s

* Remove unused import

* address review comments

---------

Co-authored-by: Scott Mabin <scott@mabez.dev>
2023-03-23 20:21:05 +02:00
liebman
72c0aacf74
PCNT implementation for v4 esp-idf api (will work for on v5 with v4 api) (#157)
* WIP - PCNT implementation for idf v4

* use from core not std
pass pins as PeripheralRef
store PinDriver in PcntPin

* try a allocate/deallocate stratagy for PCNT UNITS (like esp-idf v5)

* update pcnt example

* WIP - PCNT implementation for idf v4

* use from core not std
pass pins as PeripheralRef
store PinDriver in PcntPin

* try a allocate/deallocate stratagy for PCNT UNITS (like esp-idf v5)

* update pcnt example

* use Arc/Mutex for PcntPin so Pnct can be Send

* update pcnt encoder example

* add partial esp-idf 5 pulse_cnt support (no watches/events)
requires update in esp-idf-sys to choose implementation
uses pcnt on esp-idf 4
uses pulse_cnt by default on esp-idf 5

* fix pcnt compilation on esp-idf 4

* implement interrupt service

* added some documentation

* fix subscribe - trampoline did not work with captured values.
update example to support either

* no need to initialize logging in example

* use esp_idf_sys::*

* Implement From not Into

* switch from bitflags to enumset

* typo

* switch #[doc] to /// style

* gate uses of Box with alloc feature and use alloc::boxed::Box

* rename to PcntDriver and make Pcnt Peripherals

* use `impl Peripheral<P = impl InputPin>` instead of `AnyInputPin`

* small cleanup

* rename config() -> channel_config()
implement defaults on PcntChannelConfig

* some cleanup on idf v5 pulse_ctr

* no need for PcntChanConfig, just use flags

* use comment style documentation not `#[doc=""]`

* small tweak to pnct example

* review fixes (the easy ones)

* added deps for the pcnt example (dev-dependencies)

* cargo fmt

* pub const fn new for PcntChanFlags

* pub const fn new for PcntUnitFlags

* fix compilation for esp-idf 4

* pass in all pins in PcntDriver::new
use PinIndex to specify pins to a channel

* remove unused lifetime

* use a simple macro to convert Option<> pin to a pin number

* cargo fmt

* remove V5 for now
fix #cfg's for when/where pcnt is available

* fix #cfg's for when/where pcnt is available

* fix #cfg's for when/where pcnt is available

* gate access to ISR_HANDLERS in drop with `alloc`
no need for `not(feature = "riscv-ulp-hal")` as pcnt is not included for `riscv-ulp-hal`

* cargo fmt / clippy

* stub out the pcnt example on an unsuported device

* - drop esp-idf-svc from dev-deps (compile error on esp-idf 5)
- use println!() instead of log::info!() in pcnt example

* fix ocnt example compile for riscv32imc-esp-espidf

---------

Co-authored-by: Chris Liebman <chris.l@taboola.com>
2023-02-21 09:07:45 +02:00
Michael de Silva
719fd2aa81
Fix typo in doc copy (#181) 2022-12-06 11:08:08 +02:00
ivmarkov
a8318018f0 Move cs::CriticalSection to the task module 2022-10-18 14:47:31 +03:00
ivmarkov
f1ebc6102d Latest edge-executor support 2022-10-17 11:11:24 +03:00
ivmarkov
341fc871d7 restart method 2022-09-22 10:31:44 +03:00
Cody P Schafer
961cd10b98 reset_reason: wrap esp_reset_reason()
Primarily useful because this gives me a readable `Debug` impl for the
reset reason. There may be a way to have `esp-idf-sys` generate some
more reasonable code as an alternative.
2022-09-22 10:25:40 +03:00
ivmarkov
67f2484966 Hardware timers
Use only ISR terminology

Remove unused imports

Simplify subscription code

timer subscription callbacks

No need for e-hal timer error

More meaningful timer periph names for esp32c3

embassy-time driver
2022-09-18 11:01:33 +03:00
Ivan Markov
1f69f24773 Seal the Peripheral trait 2022-09-18 11:01:33 +03:00
Ivan Markov
8416c73034 RTC GPIO; fix ulp-hal mode
Expose RTC GPIO only where it exists

Expose RTC GPIO only where it exists

Expose RTC GPIO only where it exists
2022-09-18 11:01:33 +03:00
Ivan Markov
2ace88dc58 PeripheralRef support; critical-section support 2022-09-18 11:01:33 +03:00
Ivan Markov
549a870008 Remove embedded-svc dep, compat with critical-section, modem and mac peripherals 2022-09-18 11:01:33 +03:00
Ivan Markov
7273949436 remove deps on nightly features 2022-09-18 11:01:33 +03:00
ivmarkov
3366568564 GATs stabilized 2022-09-16 12:52:56 +03:00
Scott Mabin
dd8558357d
hide hall module for esp-idf v5 (#121) 2022-08-28 09:06:51 +03:00
ivmarkov
e441b44daf Compatibility with CMake build 2022-05-02 15:26:27 +03:00
ivmarkov
f877556d5a Interrupt module no longer experimental 2022-04-09 17:39:40 +03:00
ivmarkov
34709e310a Finish the unfinished work on supporting CAN via e-hal 0.2.7 2022-03-30 12:44:35 +03:00