Commit Graph

615 Commits

Author SHA1 Message Date
Jesse Braham
661a9de5eb
Add some miscellaneous examples for the ESP32-H2 (#548)
* Add some miscellaneous examples for the ESP32-H2

* Update the CHANGELOG
2023-05-17 07:13:47 -07:00
Björn Quentin
3be64df304
Merge pull request #546 from bjoernQ/esp32s3-move-psram-functions-to-ram
ESP32-S3: Move PSRAM functions to RAM
2023-05-17 15:37:03 +02:00
bjoernQ
b931e27d8e Update CHANGELOG.md 2023-05-17 12:38:14 +02:00
bjoernQ
fc25c84578 ESP32-S3: Move PSRAM functions to RAM 2023-05-17 12:35:59 +02:00
Scott Mabin
ffe167e64c Update changelog 2023-05-16 10:23:58 -07:00
Sergio Gasquez Arcos
a7e4400fb5
Initial support for MCPWM in ESP32-H2 (#544)
* feat:  Enable mcpwm peripheral

* feat:  Initial support MCPWM

* fix: 🐛 Select the rigth clock

* fix: 🐛 Select the XTAL clock

* docs: 📝 Update changelog
2023-05-16 09:00:11 -07:00
Scott Mabin
45f855abf5
Support for multicore async GPIO: (#542)
* Support for multicore async GPIO:

Use the correct registers depending on which core the interrupt is being
serviced on. Fixed a bug in the `esp32::gpio_intr` which would enable
the interrupt on both cores. It now enables the interrupt for the core
in which `listen()` is called.

* add changelog item

* Simplify GPIO interrupt status
2023-05-16 15:46:36 +01:00
Björn Quentin
d0a5e95f8c
Merge pull request #475 from BryanKadzban/add-hw-fade
Add LEDC duty-cycle fading support
2023-05-16 08:25:51 +02: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
dimi
c4fec98cb3 implement Copy and Eq for EspTwaiError 2023-05-15 08:20:12 -07:00
Sergio Gasquez Arcos
e2442f2d47
Initial support for I2C in ESP32-H2 (#538)
* feat:  Enable i2c peripheral

* feat:  Add I2cExt1 for H2

* feat:  Initial i2c support

* feat:  Add i2c examples

* ci:  Add embassy_i2c check

* ci: 🐛 Fix features

* docs: 📝 Update changelog

* feat:  Add read_efuse example
2023-05-15 16:20:01 +02:00
Björn Quentin
4dde817530
Merge pull request #536 from bjoernQ/bugfix/set-vecbase-for-core1
Bugfix/set vecbase for core1
2023-05-15 16:18:39 +02:00
bjoernQ
add8447df8 Add reference to the PR to changelog 2023-05-15 16:10:36 +02:00
bjoernQ
c0e67aa5c7 Update CHANGELOG 2023-05-15 16:10:12 +02:00
bjoernQ
7f769612b9 Set vecbase on core1 2023-05-15 16:09:43 +02:00
Scott Mabin
eb3a449d90
async gpio fixes (#537)
* async gpio fixes

- Fix pin number calculation for bank1
- Clear interrupt status after disabling interrupt to avoid hardware
  pending another interrupt
- Clear interrupt status per pin when we create the input future

* add changelog item
2023-05-15 14:53:04 +01:00
Sergio Gasquez Arcos
70e453902c
Initial support for RSA in ESP32-H2 (#526)
* feat:  Initial support for RSA

* docs: 📝 Update docstring

* docs: 📝 Update changelog

* fix: 🔥 Remove duplicated code
2023-05-15 09:42:19 +01: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
Sergio Gasquez Arcos
5b47c37449
Initial support for AES in ESP32-H2 (#528)
* feat:  Initial support for AES

* docs: 📝 Update changelog
2023-05-12 13:46:22 +02:00
Sergio Gasquez
b811198939 docs: 📝 Update changelog 2023-05-11 09:30:40 -07:00
Sergio Gasquez
29757abe07 feat: Initial support for SHA 2023-05-11 09:30:40 -07:00
Jesse Braham
d316b066b0 Improve the pre-commit hook
Now handles directories starting with `esp` which do *not* contain a `Cargo.toml` file!
2023-05-11 08:53:03 -07:00
Björn Quentin
ca7c0b377f
Merge pull request #529 from bjoernQ/enable-change_bus_frequency-for-spi-dma
Enable change bus frequency for spi dma
2023-05-11 13:16:28 +02:00
bjoernQ
c1685cacb6 Update CHANGELOG.md 2023-05-11 11:25:43 +02:00
bjoernQ
068a6453de Fix the PR template 2023-05-11 11:22:42 +02:00
bjoernQ
5052c3335d Enable change_bus_frequency for SpiDma 2023-05-11 11:17:40 +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
Sergio Gasquez
f2b12b79bb ci: 📌 Unpin nightly version 2023-05-10 07:56:10 -07:00
Björn Quentin
66dda572e3
Merge pull request #522 from bjoernQ/add-ESP32S3-PSRAM-to-changelog
Add esp32 s3 psram to changelog
2023-05-10 16:44:17 +02:00
bjoernQ
d221fe2d65 Add changelog check in CI 2023-05-10 16:35:07 +02:00
Scott Mabin
5a5eb41411 simplify timg time driver impl
Once the timer has been initialized, all other operations are atomic.
Therefore we can simply `steal` the timer where needed, instead of
holding it in a mutex/refcell.
2023-05-10 07:10:16 -07:00
bjoernQ
b77d05f009 Add a PR template 2023-05-10 08:35:42 +02:00
bjoernQ
a7a29eb8b5 Add ESP32-S3 PSRAM feature to CHANGELOG.md 2023-05-10 08:35:32 +02:00
Jesse Braham
36fc6347c2 Add missing link to README 2023-05-09 10:34:22 -07:00
Jesse Braham
c5d8cc62b8
Merge pull request #513 from esp-rs/feature/esp32h2
Add initial support for the ESP32-H2
2023-05-09 10:06:32 -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
Jesse Braham
5de726f034 Rebase branch, update rtc_cntl implementation, add rtc_time example 2023-05-08 08:10:34 -07:00
Jesse Braham
ca54d29fcb Update the top-level README and CHANGELOG, fix blinky example 2023-05-08 08:03:08 -07:00
Kirill Mikhailov
ad0b4e4bef Update CI
Comment direct-boot test, still only buildable, but requires fixes for Real HW
2023-05-08 08:03:08 -07:00
Jesse Braham
fc2dd38d83 Fix build errors after rebasing 2023-05-08 08:03:08 -07:00
Kirill Mikhailov
7d72acb2d7 Added WDT support for ESP32-H2 (#511)
* Added init function

* Populated enums

* Adding enums

* Add TODO (according to IDF update)

* Added WDT support for ESP32-H2

* Updated hello_world example

* Add two examples for both watchdog and RTC watchdog

* Add specific bit initialization for TIMG0 and TIMG1

* Cleaning the code

* adjusting for rustfmt

* uncommented direct-boot feature test in CI
2023-05-08 08:03:08 -07:00
Jesse Braham
4e9e1d1fea Add ESP32-H2 support for TIMG and UART (#500)
* Begin working on `PeripheralClockControl` for the ESP32-H2

* Update `UART` driver to add H2 support

* Update `TIMG` driver to add H2 support

* Update the hello_world example to use `TIMG` and `UART`
2023-05-08 08:03:08 -07:00
Jesse Braham
c3b4e83846 Add initial ADC/GPIO implementation for ESP32-H2 (#494)
* Add `esp32h2-hal` package to the VS Code workspace and CI workflow

* Add initial (not quite complete) implementation of GPIO/ADC for ESP32-H2
2023-05-08 08:03:08 -07:00
Sergio Gasquez Arcos
854e52c417 Add ESP32- H2 soc/efuse methods (#486)
* feat:  Implement efuse methods

* feat:  Add NUM_PINS

* doc: Update link to point at specific commit

Co-authored-by: Jesse Braham <jessebraham@users.noreply.github.com>

---------

Co-authored-by: Jesse Braham <jessebraham@users.noreply.github.com>
2023-05-08 08:03:08 -07:00
Kirill Mikhailov
9493b38a1b Started adding ESP32-H2 support (#482) 2023-05-08 08:03:08 -07: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
onsdagens
fe84e74151
Adding priority based interrupt preemption (#448)
* Software interrupt support added, not sure if the code is good

* Added support for remaining SW interrupts

* Added support for remaining SW interrupts

* Added support for remaining SW interrupts

* Added support for esp32c2, esp32s2, esp32s3

* Added support for esp32c2, esp32s2, esp32s3

* Added support for esp32c2, esp32s2, esp32s3

* Added support for esp32c2, esp32s2, esp32s3

* Software interrupt example for esp32c3

* Added support for esp32c2, esp32s2, esp32s3

* Software interrupt example for esp32c3

* prio based preemption only, vector table reverted

* prio based preemption only, vector table reverted

* fixed a rare bug causing misaligned memory accesses

* fixed a rare bug causing misaligned memory accesses

* fixed a rare bug causing misaligned memory accesses

* fixed rare bug causing misaligned memory access when emulating atomics

* fixed a rare bug causing misaligned memory accesses

* fixed a rare bug causing misaligned memory accesses

* broke something

* broke something

* fixed alignment bug

* Tentative: added support for interrupt preemption without involving the rt

* Added feature enabling priority based interrupt preemption

* Fixed failed merge

* Tagged preemption helpers with inline always

* Disable interrupts before restoring context to avoid ruining it

* Fix max priority edge case

* Fix broken merge

* Added examples for the remaining RISC-V ESPs

* Update esp-hal-common/src/interrupt/riscv.rs

Co-authored-by: sethp <seth.pellegrino@gmail.com>

* Update esp32c2-hal/examples/interrupt_preemption.rs

Co-authored-by: sethp <seth.pellegrino@gmail.com>

* Update esp-hal-common/src/interrupt/riscv.rs

Co-authored-by: sethp <seth.pellegrino@gmail.com>

* Example comments courtesy of @sethp

* Reverted irrelevant changes, raised high prio interrupt to max prio

* Rolling back an irrelevant change

* Rolling back an irrelevant change

* Update esp-hal-common/src/interrupt/riscv.rs

Co-authored-by: Scott Mabin <scott@mabez.dev>

* Update esp-hal-common/src/interrupt/riscv.rs

Co-authored-by: Scott Mabin <scott@mabez.dev>

* Moved imports to avoid warnings, moved functions to ram, moved interrupt disable to before prio threshold is restored

* Added preemption for the ESP32C6

* Moved helper functions into the relevant modules, changed threshold for ESP32C6 to machine mode one

* ESP32C6 Threshold register changed to machine mode one, corrected threshold set.

---------

Co-authored-by: sethp <seth.pellegrino@gmail.com>
Co-authored-by: Scott Mabin <scott@mabez.dev>
2023-05-05 11:40:54 +01:00