139 Commits

Author SHA1 Message Date
Scott Mabin
94a07da47b
Fix Async UART (#871)
* Fix Async UART

The uart handler was `writing` to the enable register instead of
`modify`, which meant any wake would see the cleared enabled bit and
think the event had occurred. This wasn't seen before the split of uart
because it was only possible to listen to one thing at a time.

This PR also removes the ReadBufferFull error in favour of returning the
max bytes in the buffer.

The serial examples has been updated to actually have some cross task
communication.

* changelog

* fix dev deps
2023-10-25 10:25:25 -07:00
Jesse Braham
33bfe80d95
Prelude improvements/fixes (#860)
* Move SPI-related traits into their own preludes in the `spi` module

* Remove the `embedded-hal-async` trait re-exports and the `eh1` module from the prelude

* Update `CHANGELOG.md`
2023-10-20 06:56:17 -07:00
Jesse Braham
f81dc50748
Refactor the spi and spi_slave modules into a common spi module (#843)
* Refactor the `spi` and `spi_slave` modules into a single `spi` module

* Update import paths in examples as needed

* Extract some common types from `spi::master` into the root `spi` module

* Fix imports in examples (again)

* Documentation fixes/improvements

* Remove unnecessary re-exports

* Update `CHANGELOG.md`
2023-10-11 11:38:38 -07:00
Björn Quentin
a0ebdf0399
embassy #[main] convenience for RISC-V / Xtensa (#841) 2023-10-11 12:10:14 +01:00
Bryan Kadzban
0aa0232f1b
SPI slave support (#580)
* Duplicate spi to spi_slave

* Restore spi

* Add barebones SPI slave mode, DMA only.

This setup allows registering buffers for future transactions the master
does (lowering cs, toggling sclk, and raising cs again). The transfer
struct returned from the registration API will complete its wait() or
return true from is_done() after cs has been raised.

Copied from spi.rs, so most of the changes are deleting code that
handles e.g. segmented transfers or synchronous operations.

Fix non-c3 devices' builds

* Limit spi_slave to non-pdma devices

* SPI slave DMA example

Ensure the API "feels" right.

Since there's no way to route GPIOs to other peripherals, we choose four
other wires and bit-bang SPI for the master side, relying on the person
running the example to connect the bus.  This way we ensure the slave
code works, since we created the master ourselves.

Also, it's not really possible to use a second ESP device as the master
anyway: all the digital lines have glitches on startup, and those
glitches cause the slave's DMA engine to skip descriptors (it thinks
they're intended CS indicators); this causes it to lose data.

Then, fix the bitbang master (recording the progression here)

- When bitbanging, iterate the bits by "for _ in 0..8", instead of the
  broken "for _ in [0..8]".  The latter only runs the iteration once,
  since there's only one list given ... and because the code uses _
  instead of a real loop variable, type checking didn't save us.
- When bitbanging, send the bits out (and read them in) MSB first, since
  that's actually how we have the slave configured.

* Add changelog entry

* Split DMA prepare_transfer into two fns.

The first does everything but write to the start bit and check for an
error. The second does those. We need 2 fns because the  SPI slave needs
to start the transfer only after resetting the various afifo hardware
components (if it starts the transfer before, the first 8 bytes will be
lost when that reset happens).

Use the split fns everywhere.

Also split flush().  It needs to be pollable, so split it into one fn that
polls and one that waits until the poll returns clear. Also call the poll
fn from the is_done() fn, so we don't trample in-progress transfers.

* Make example code fill rx buffer before transfer

This way we can tell if it's ever touching certain bytes - 0xff is never
added to the master transmit buffer.

While I'm changing this, make the slave tx buffer never contain 0xff
either (go from 254 to 0).

---------

Co-authored-by: Jesse Braham <jessebraham@users.noreply.github.com>
2023-10-10 09:00:18 -07:00
Dániel Buga
44e968f7a8
Make sure examples can actually build with defmt enabled, build some examples in CI (#810)
* Make sure examples can build with defmt

* Remove duplicate example checks

* Fix examples

* Add changelog entry

* Actually build some examples with defmt feature enabled

* Add the defmt linker script in each package's build script
2023-10-05 12:13:09 -07:00
Scott Mabin
db409ffe7b
Unify the system peripheral (#832)
* Unify the system peripheral

Whilst the PCR, SYSTEM and DPORT peripherals are different, we currently
use them all in the same way. This PR unifies the peripheral name in the
hal to `SYSTEM`. The idea is that they all do the same sort of thing, so
we can collect them under the same name, and later down the line we can
being to expose differences under an extended API.

The benifits to this are imo quite big, the examples now are all identical,
which makes things easier for esp-wifi, and paves a path towards the
multichip hal.

Why not do this in the PAC? Imo the pac should be as close to the
hardware as possible, and the HAL is where we should abstractions such
as this.

* changelog
2023-09-29 08:14:50 -07:00
Juraj Sadel
9f76798e64
Warnings cleanup and add missing PSRAM examples to the CI (#826)
* Warnings cleanup

* Add PSRAM examples to the CI
2023-09-28 08:41:55 +02:00
Juraj Sadel
ca4e1b3a26
(G)DMA AES working mode support (#821)
* Add (G)DMA AES initial support

* Modify AES examples to the driver changes

* Add DMA examples(tests)

* fmt

* changelog

* review changes

* typo
2023-09-27 09:08:14 -07:00
Kirill Mikhailov
24c5e8cb79
Adding async support for RSA peripheral (#790)
* Adding async support for RSA peripheral

* Add esp32 support (doesn't work properly yet)

* Xtensa chips are supported (except of esp32)

Add modular multiplication for esp32

Adding a CHANGELOG entry

Rebase issue fix

* Code cleanup

* Add `.await` on `RsaFuture::new()` calls

* Refactor and rebase

Made `read_results` functions to be `async`, got rid of `nb` usage

* Change API methods naming + refactor `start_step2` method

* Adjust example to the API change + documentation

* Code cleaning + refactoring

Update examples
2023-09-27 09:03:06 -07:00
Jesse Braham
0064766ef2
No longer publicly expose the PeripheralClockControl struct (#817)
* No longer publicly expose the `PeripheralClockControl` struct

* Update examples as needed to get things building again

* Update CHANGELOG.md

* Address review feedback, fix a warning

* Use a critical section for all devices other than the ESP32-C6/H2, as they modify multiple registers

* Rebase and update `etm` driver to fix build errors
2023-09-26 09:07:57 -07:00
Scott Mabin
eeb2d1db6f
Fix UART to handle CPU/APB clock changes (#808)
* Ensure that uart is configured to account for clock changes, not just boot defaults

* fix examples

* changelog

---------

Co-authored-by: Jesse Braham <jessebraham@users.noreply.github.com>
2023-09-21 09:06:56 -07:00
Björn Quentin
434a32763c
Async I2S support (#801)
* Async I2S support

* Add CHANGELOG.md entry
2023-09-20 22:23:50 +00:00
Georges
107732b111
Add support for splitting esp32 uart into TX and RX (#754)
* Add support for splitting esp32 uart into TX and RX

* Keeps existing API for uart, but wraps it in Tx and Rx sub-types
* Adds split() method similar to embassy-rs nRF/stm32/rp for getting indepdendent TX and RX
parts
* Implements e-h traits for TX and RX types
* Add esp32s3 example

* finish implementing

* rebase examples

* declare new examples

* fix fmt

* rebase on 0.12.0

* fix fmt

* fix fmt

* merge embassy_serial_split example with embassy_serial

* fix changelog

* fix changelog
2023-09-20 13:19:34 +01:00
Björn Quentin
a642ee40da
Async RMT (#787)
* Async RMT

* Add CHANGELOG item

* Pin toml_edit transitive dependency
2023-09-13 09:02:36 +02:00
Jesse Braham
d12a3dbac5
Update all examples to remove unnecessary disabling of watchdogs (#768)
* Update `esp32-hal` examples

* Update `esp32c2-hal` examples

* Update `esp32c3-hal` examples

* Update `esp32c6-hal` examples

* Update `esp32h2-hal` examples

* Update `esp32s2-hal` examples

* Update `esp32s3-hal` examples

* Fix the `ram.rs` examples
2023-08-31 07:17:12 -07:00
Jesse Braham
4dd9fbdb7b
Disable all watchdog timers at startup by default (#763)
* Rework watchdog timer drivers to allow enabling/disabling and feeding without traits

* Disable all watchdogs prior to `main` using the `__post_init` hook

* Update all watchdog-related examples

* Update CHANGELOG

* Address review comment
2023-08-30 08:54:01 -07:00
Dániel Buga
e082d47a87
Multicore-aware executors (#723)
* Implement multicore-aware executors

* Add examples

* Use pre-defined config to import SystemPeripheral

* Use static_cell::make_static
2023-08-28 10:05:42 -07:00
Dániel Buga
bf4efcfd7f
Take FnOnce closure by value in start_app_core (#739) 2023-08-22 16:33:32 +02:00
Jesse Braham
7fce6e32f2
Update to 1.0.0-rc.1 version of embedded-hal-* crates (#747)
* Update a bunch of dependencies

* Implement `embedded-io` and `embedded-io-async` traits for USB Serial JTAG

* Implement `embedded-io` and `embedded-io-async` traits for UART

* Fix `embassy_serial` examples

* Update CHANGELOG

* Address review comments
2023-08-22 14:53:41 +01:00
Björn Quentin
92bda00296
Remove heap related symbols, use all remaining memory for the stack (#716)
* Use all remaining memory for stack(s)

* Remove HEAP related code from RISCV linker scripts

* Fix direct-boot / mcu-boot linker scripts

* Use a statically allocated stack for core-1
2023-08-14 13:38:36 +02:00
Jesse Braham
a95f6efb35
Update esp-hal-smartled to use the new rmt driver, remove old pulse_control driver (#694)
* Remove the old `pulse_control` driver

* Update `esp-hal-smartled` to use the new `rmt` driver instead

* Update the `hello_rgb` example for each chip

* Update CHANGELOG
2023-07-27 16:07:15 +01:00
Alex Johnson
debe2b8004
fixed async read w/o at_cmd (#652)
* fixed async read w/o at_cmd

* configurtion checks  for async `read`

* remove fifo thrhd check
2023-07-25 12:19:59 +01:00
Björn Quentin
170d590b67
Make in-progress DMA transfers potentially fallible (#665) 2023-07-22 20:14:57 +01:00
Björn Quentin
213dde9304
Add a new RMT driver (#653)
* Add a new RMT driver

* Add CHANGELOG entry

* Fix typos
2023-07-19 10:54:52 -07:00
liebman
37466fd9c7
deep sleep api for esp32 (#574)
* deep sleep api for esp32

* move to list of wakeup sources

* improve Ext0WakeupSource - still WIP

* add deep sleep with timer wakeup example
add Ext0 wakeup source (WIP/Non-working)

* removed alloc (using heapless now)

* Sleep: ext0 wakeup working

* add sleep_timer_ext0 example

* API change: move sleep into RTC as sleep, sleep_deep, sleep_light

* fix sleep examples for new API

* sleep only implemented for esp32 at this time

* sleep only implemented for esp32 at this time

* Implement a simple RTCPin trait to support sleep

* implement RTCPin for all xtensa SOC

* cargo fmt & update changelog

* fix change log order (accidentally swaped during rebase)

* implement Drop for Ext0WakeupSource

* added Ext1 wakeup source

* cargo fmt

* healpess was unused, removed

* fix pase macro usage
2023-07-14 15:44:13 +00:00
Dániel Buga
b1e8c6e818
Some minor cleanup (#642)
* Fix typo

* Don't require importing paste

* Clean up warnings

* Clean up Clippy warnings
2023-07-05 11:09:04 -07:00
Hannah Kolbeck
a86c2ac310
Clean up a stray comment in rtc_time examples (#630)
Co-authored-by: Hannah Kolbeck <hskolbeck@gmail.com>
2023-06-30 12:30:05 +01:00
Jesse Braham
6869f8c783 Update embedded-graphics and ssd1306, address breaking changes 2023-06-28 09:47:43 -07:00
Dániel Buga
2371c30542
Simplify user-facing DMA channel types (#626)
* Introduce a trait for DMA channels

This trait is then used to hold types related to the particular DMA channel. This change allows us to simplify user-facing types.

* Remove private type from I2s

* Remove redundant spi3 example, update examples

* Merge markdown sections

* Add changelog entry
2023-06-28 13:03:49 +01:00
Alex Johnson
bce7210b01
Async serial uart read (#620)
* implement embassy async uart read

* Add embassy async read support for uart

* changes based on review

* fix CI failures

* change review #2

* fixed re-opened PR number

* changes review no.3

---------

Co-authored-by: Scott Mabin <scott@mabez.dev>
2023-06-26 16:56:32 +01:00
Jordan Halase
a562863cde
Add MD5 functionality from ESP ROM (#618)
* Add ROM MD5 definitions in linker and devices

* Add initial MD5 support

* Implement traits and add comments to MD5 module

* Add MD5 example to ESP32-C3

* Test MD5 context on the quick brown fox

* Implemenr From<Context> for Digest

* Add MD5 to the rest of the examples

* Add docs for MD5

* Remove #[repr(transparent)] from md5::Digest

* Update CHANGELOG.md
2023-06-26 09:01:34 +02:00
Jesse Braham
5af8b6387a
Clean up re-exports and make small improvements to documentation (#607)
* Create issue_handler.yml

* No longer re-export `embedded-hal`, hide exported macros in documentation

* Add simple package-level documentation for each HAL package

* Clean up/simplify re-exports

* Fix the examples that I broke

* Ensure top-level modules/types/functions have doc comments

* Update CHANGELOG

* Re-export the `soc::psram` module where available

---------

Co-authored-by: Sergio Gasquez Arcos <sergio.gasquez@gmail.com>
2023-06-22 06:46:50 -07:00
Sergio Gasquez Arcos
310809a5bf
Update documentation (#606)
* docs: 📝 Update documentation

* docs: 🐛 Fix typo
2023-06-21 04:03:15 -07:00
Sergio Gasquez Arcos
e3b77418c4
ESP32H2: Improve examples documentation (#598)
* style: 🎨 Improve print format

* docs: 📝 Update advanced_serial documentation

* docs: 📝 Update examples documentation
2023-06-19 07:14:12 -07:00
Juraj Sadel
3b689b2a52
H2: Add I2S support (#597)
* H2: Add initial i2s support and i2s_read and i2s_sound examples

* Add I2S_SCLK and I2S_DEFAULT_CLK_SRC constants for all chips

* Update I2S driver

* fmt

* Add changelog

* Change DIN GPIO17 to GPIO14 in ESP32 i2s_read example
2023-06-19 06:24:09 -07:00
Jordan Halase
f22cd7370d
Add CRC functionality from ESP ROM (#587)
* Add ESP ROM CRC and fallbacks to HAL

* Cargo fmt

* Add CRC examples

* Cargo fmt

* Cargo fmt and clippy (all)

* Update CHANGELOG.md
2023-06-14 05:40:51 -07:00
Nathan Marley
c41e156a88
Use built-in LED pin (gpio2) in blinky example (#581)
* Use built-in LED pin (gpio2) in blinky example

Hi, I was just running the blinky example and noticed the comments about an LED
being connected to pin GPIO25. I was thinking it might makes more sense to use
the built-in LED pin instead, and no external hardware would be required.

* Add note on GPIO2 led

* Add GPIO2 LED pin change to changelog
2023-06-14 02:16:38 -07:00
Jesse Braham
a92c46f309 Correct a number of comments in various examples 2023-05-25 06:02:15 -07:00
Bryan Kadzban
a6835d9cec Add examples for polling DMA transfers.
Only in the SPI case, but the I2S case has the same API so this should
be fine.
2023-05-25 06:37:09 +00:00
Sergio Gasquez Arcos
14ac8c3c80
Initial support for RMT in ESP32-H2 (#556)
* feat:  Enable RMT peripheral

* feat:  Rename RMT GPIOs

* feat:  Add clock source, ram size and ram start

* feat:  Rename GPIOs

* feat:  Add pulse_control example

* fix: 🐛 Fix example clock

* feat:  Initial support for H2

* fix: 📝 Fix typo

* ci:  Enable check on H2

* build: 📌 Update esp-pac revision, use fork

* docs: 📝 Update example documentation

* docs: 📝 Add todo

* docs: 📝 Update changelog

* feat:  Add ram example

* build: 📌 Update H2 PAC

* docs: 📝 Remove todo
2023-05-23 10:14:17 -07:00
Bryan Kadzban
01d4b8686a Add duty-cycle fading support
For now, only the -c3.

---

Open up LEDC fade support to all chips.

The C6 chip needs some special handling because its fade registers also
handle gamma, and the ESP chip needs some special handling because it
has two banks of channels.  The code to handle these is already present
in channel.rs, but needs to be copied and adapted.  Do that, and drop
all the esp32c3 feature checks.

---

Add a function to poll the duty-fade state

Use the unmasked interrupt bit in the LEDC register block, since that
will get updated by the hardware whether or not we've connected anything
to the interrupt source.  Also be sure to clear that bit before starting
a new fade, so it's always clear while fading.

This will allow dumb (non-async-code) polling of the fade state after
one is started by the start_duty_fade API.

---

Fix non-C3 devices to use the right int_raw bits

These are inconsistently named between the esp32 variants.

---

Add examples of hardware duty-cycle fading

Just a relatively simple zero to 100 and back to zero, over a total of 2
seconds, to get a breathing effect.

This does make the main loop{} have a 2-second period instead of the
current nearly-zero period, but nothing else is happening so that's
fine.

---

Fix two bugs in hardware fading

When figuring out how many duty-cycle changes need to happen per counter
overflow, we need to use the absolute value of the difference between
the start and end duty values, not the raw difference.  When fading from
(e.g.) 100% to 0, this will overflow, and both the debug-mode panic and
the release-mode wrapping behavior give the wrong delta value.

So calculate an absolute value difference first, and use that.

Then, when running through the while loop that allocates bits between
pwm_cycles and duty_cycle, the check on pwm_cycles was wrong -- since
the value reduces each time through the loop, we need to keep looping as
long as it's *above* some threshold, not below.

---

Simplify and refactor duty-cycle fade code

I'm not sure if this will fix the extremely-short fade times that we're
seeing with the older code, but we'll see.

Move all the calculations out of the ChannelHW implementations, and make
those *just* set registers.  The calculations are the same for all chip
variants, so don't need to be duplicated for each chip feature, like the
register macros are.

Change the calculations from a loop doing bit shifts, to an explicit
division and a couple of range checks.  This way we can get a lot closer
to the requested percentages and durations.

Use the u32::abs_diff function instead of open-coding it (now that I see
it exists).

Use u16::try_from() to limit the range of values, and use try_into<u16>
and map_err and the ? operator to more clearly handle numbers out of
range.

Drop the Result<> return type from the ChannelHW function, as it can't
fail anymore.

Fix the duty_range value -- before, when duty_exp was (say) 8,
duty_range would be 256, and if one of the *_duty_pct values was 100,
the start or end duty value would be too big.  The range of start and
end duty values is 0..255, so we have to subtract one to handle 100%.

Finally, add a comment on the is_duty_fade_running{,_hw} methods.

---

Some fades can't work; return errors for them.

Add a new Error enum value with a sub-error enum with more details.
Return it from the error cases in the fade method.

If the calculated cycles_per_step is more than 10 bits, fail as well;
the field in the register is only 10 bits wide.

Fix all the examples to run a 1-second fade instead of a 2-second, since
the 2-second fade will run into this error.  (Assert that, as well.)

---

When fading on a -c6 chip, set two more registers

The gamma functionality of -c6 chips needs two more fields set.  One
tells the chip how many gamma stages it should iterate through, but we
only implement linear fading, so always use 1.  The other tells the chip
to latch the value of the other gamma registers into the chosen slot, so
even though its value never changes, the write needs to happen.

---

Add changelog entry
2023-05-15 17:11:31 +00:00
Sergio Gasquez Arcos
fa3627c1fd
Add blinky_erased_pins example for ESP32-H2 (#530)
* feat:  Add blinky_erased_pins example

* docs: 📝 Update docstrings

* docs: 📝 Update changelog
2023-05-12 14:18:04 +02:00
Sergio Gasquez Arcos
b90ea68931
Improve examples documentation (#533)
* docs: 📝 Doccument embassy I2C example

* docs: 📝 Improve documentation of embassy SPI example

* docs: 📝 Doccument AES and RSA example

* docs: 📝 Update changelog
2023-05-12 13:46:56 +02:00
Jesse Braham
b43516682e
Add async support to the I2C driver (#519)
* Small refactor to extract functions for setting up reads/writes

* Implement async capabilities for `I2C` driver

* Add async I2C examples for each supported chip

* Update CHANGELOG
2023-05-10 10:38:16 -07:00
Björn Quentin
94b909fcb8
Merge pull request #517 from bjoernQ/feature/ESP32-S3-PSRAM
ESP32-S3: Initial PSRAM Support
2023-05-09 12:39:24 +02:00
bjoernQ
f0882e8d62 ESP32-S3: Initial PSRAM Support 2023-05-08 17:38:33 +02:00
liebman
905c0af154
implement fetching the RTC timer value in milliseconds and mircroseconds (#476)
* implement fetching the rtc timer value in miliseconds and mircroseconds

* fmt cleanup

* add rtc_time examples

* get_time_raw/esp32: delay 1us between time update checks like esp-idf

* cargo fmt
2023-05-08 07:59:37 -07:00
Scott Mabin
1731169112
Async serial write (#510)
* Initial async_{write|flush} implementations

- ESP32C3 + UART0 example

* Support UART1 & UART2

* Add examples for all chips

* reduce number of wakers depending on uart count
2023-05-05 09:05:15 -07:00
Björn Quentin
13acedf69a
ESP32: Initial PSRAM Support (#506)
* ESP32: Initial PSRAM Support

* Update CHANGELOG, fmt
2023-05-04 12:21:24 +01:00