From 6a663f8b1a6bd273cd41d49e2096b8c4906e9da4 Mon Sep 17 00:00:00 2001 From: Jesse Braham Date: Tue, 27 Feb 2024 14:10:11 +0000 Subject: [PATCH] Unify: Remove the chip-specific HAL packages, adapt `esp-hal` for direct use [1/?] (#1196) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove the chip-specific HAL packages * Update some doc comments which were missed, fix build script for ESP32/S2 * Refactor/update `esp-hal-procmacros` * Create the `examples` package, add back all of the previously existing examples * Use `xtask` automation package for checking examples and documentation in CI * Combine the `rt-riscv` and `rt-xtensa` features into a single `rt` feature * Bump MSRV to 1.76.0 (shocking!) * Re-document the features for the HAL * No need to re-export the `riscv` package like this * Make clippy happy, improve CI clippy checks * Update `CHANGELOG.md` * riscv: zero bss Co-authored-by: Björn Quentin * Address a number of review comments * Correct pin number in `hello_rgb` example for ESP32-C3 * Address the remaining review comments * More small tweaks/improvements * Fix RMT examples (#11) * Fix RMT examples * Remove logger-init * Make I2S examples work on ESP32 (#12) * Make I2S examples work on ESP32 * Remove logger init * Fix the direct-vectoring examples on all RISCV chips (#10) * Update GPIOs for some examples... * Embassy timer example fixes (#13) * Switch to generic queue instead of integrated for all examples * changelog * Update GPIO in another example, make `rustfmt` happy * Fix ESP32-S2 PSRAM * Avoid UART0 and SPI flash pins (#15) * Avoid UART0 and SPI flash pins * Fix spi_eh1_device_loopback for non-ESP32 * Update examples/src/bin/gpio_interrupt.rs Co-authored-by: Juraj Sadel --------- Co-authored-by: Juraj Sadel --------- Co-authored-by: Scott Mabin Co-authored-by: Björn Quentin Co-authored-by: bjoernQ Co-authored-by: Juraj Sadel --- .github/workflows/ci.yml | 747 +++------------- CHANGELOG.md | 9 +- Cargo.toml | 6 +- esp-hal-procmacros/Cargo.toml | 54 +- esp-hal-procmacros/src/embassy.rs | 24 +- esp-hal-procmacros/src/enum_dispatch.rs | 26 +- esp-hal-procmacros/src/lib.rs | 308 +++---- esp-hal-smartled/Cargo.toml | 2 +- esp-hal/Cargo.toml | 262 +++--- esp-hal/build.rs | 43 + esp-hal/src/embassy/mod.rs | 8 +- esp-hal/src/interrupt/riscv.rs | 28 +- esp-hal/src/interrupt/xtensa.rs | 70 +- esp-hal/src/lib.rs | 47 +- esp-hal/src/prelude.rs | 2 +- esp-hal/src/soc/esp32/mod.rs | 2 +- esp-hal/src/soc/esp32c6/lp_core.rs | 2 +- esp-hal/src/soc/esp32s2/mod.rs | 2 +- esp-hal/src/soc/esp32s2/ulp_core.rs | 4 +- esp-hal/src/soc/esp32s3/mod.rs | 4 +- esp-hal/src/soc/esp32s3/ulp_core.rs | 4 +- esp-lp-hal/Cargo.toml | 8 +- esp-lp-hal/examples/i2c.rs | 2 + esp-lp-hal/examples/uart.rs | 4 + esp32-hal/.cargo/config.toml | 17 - esp32-hal/Cargo.toml | 164 ---- esp32-hal/README.md | 60 -- esp32-hal/build.rs | 36 - esp32-hal/examples/adc.rs | 40 - esp32-hal/examples/advanced_serial.rs | 64 -- esp32-hal/examples/aes.rs | 85 -- esp32-hal/examples/blinky.rs | 32 - esp32-hal/examples/blinky_erased_pins.rs | 53 -- esp32-hal/examples/clock_monitor.rs | 63 -- esp32-hal/examples/crc.rs | 96 --- esp32-hal/examples/dac.rs | 45 - esp32-hal/examples/embassy_i2s_read.rs | 89 -- esp32-hal/examples/embassy_i2s_sound.rs | 127 --- esp32-hal/examples/embassy_multiprio.rs | 91 -- esp32-hal/examples/embassy_rmt_rx.rs | 121 --- esp32-hal/examples/embassy_rmt_tx.rs | 73 -- esp32-hal/examples/gpio_interrupt.rs | 70 -- esp32-hal/examples/hello_rgb.rs | 75 -- esp32-hal/examples/hello_world.rs | 35 - .../examples/i2c_bmp180_calibration_data.rs | 40 - esp32-hal/examples/i2c_display.rs | 121 --- esp32-hal/examples/i2s_read.rs | 76 -- esp32-hal/examples/ledc.rs | 64 -- esp32-hal/examples/pcnt_encoder.rs | 134 --- esp32-hal/examples/psram.rs | 56 -- esp32-hal/examples/qspi_flash.rs | 166 ---- esp32-hal/examples/ram.rs | 97 --- esp32-hal/examples/read_efuse.rs | 25 - esp32-hal/examples/rmt_rx.rs | 91 -- esp32-hal/examples/rsa.rs | 154 ---- esp32-hal/examples/rtc_watchdog.rs | 59 -- esp32-hal/examples/serial_interrupts.rs | 84 -- esp32-hal/examples/sha.rs | 73 -- esp32-hal/examples/sleep_timer.rs | 41 - esp32-hal/examples/sleep_timer_ext0.rs | 51 -- esp32-hal/examples/sleep_timer_ext1.rs | 53 -- esp32-hal/examples/spi_eh1_device_loopback.rs | 140 --- esp32-hal/examples/spi_eh1_loopback.rs | 104 --- .../spi_halfduplex_read_manufacturer_id.rs | 101 --- esp32-hal/examples/spi_loopback.rs | 58 -- esp32-hal/examples/spi_loopback_dma.rs | 97 --- esp32-hal/examples/timer_interrupt.rs | 122 --- esp32-hal/examples/watchdog.rs | 31 - esp32-hal/rust-toolchain.toml | 4 - esp32-hal/src/lib.rs | 9 - esp32c2-hal/.cargo/config.toml | 12 - esp32c2-hal/Cargo.toml | 143 ---- esp32c2-hal/README.md | 51 -- esp32c2-hal/build.rs | 16 - esp32c2-hal/examples/adc.rs | 39 - esp32c2-hal/examples/advanced_serial.rs | 67 -- esp32c2-hal/examples/blinky.rs | 31 - esp32c2-hal/examples/blinky_erased_pins.rs | 53 -- esp32c2-hal/examples/clock_monitor.rs | 65 -- esp32c2-hal/examples/crc.rs | 95 --- esp32c2-hal/examples/debug_assist.rs | 76 -- esp32c2-hal/examples/direct-vectoring.rs | 73 -- esp32c2-hal/examples/ecc.rs | 801 ------------------ esp32c2-hal/examples/embassy_hello_world.rs | 48 -- esp32c2-hal/examples/embassy_i2c.rs | 67 -- esp32c2-hal/examples/embassy_multiprio.rs | 100 --- esp32c2-hal/examples/embassy_serial.rs | 96 --- esp32c2-hal/examples/embassy_spi.rs | 87 -- esp32c2-hal/examples/embassy_wait.rs | 44 - esp32c2-hal/examples/gpio_interrupt.rs | 59 -- esp32c2-hal/examples/hello_world.rs | 35 - .../examples/i2c_bmp180_calibration_data.rs | 40 - esp32c2-hal/examples/i2c_display.rs | 121 --- esp32c2-hal/examples/interrupt_preemption.rs | 132 --- esp32c2-hal/examples/ledc.rs | 66 -- esp32c2-hal/examples/qspi_flash.rs | 167 ---- esp32c2-hal/examples/read_efuse.rs | 21 - esp32c2-hal/examples/rng.rs | 28 - esp32c2-hal/examples/rtc_time.rs | 22 - esp32c2-hal/examples/serial_interrupts.rs | 88 -- esp32c2-hal/examples/software_interrupts.rs | 142 ---- esp32c2-hal/examples/spi_eh1_loopback.rs | 104 --- .../spi_halfduplex_read_manufacturer_id.rs | 101 --- esp32c2-hal/examples/spi_loopback.rs | 58 -- esp32c2-hal/examples/spi_slave_dma.rs | 204 ----- esp32c2-hal/examples/systimer.rs | 114 --- esp32c2-hal/src/lib.rs | 9 - esp32c3-hal/.cargo/config.toml | 12 - esp32c3-hal/Cargo.toml | 173 ---- esp32c3-hal/README.md | 51 -- esp32c3-hal/build.rs | 16 - esp32c3-hal/examples/adc.rs | 39 - esp32c3-hal/examples/adc_cal.rs | 52 -- esp32c3-hal/examples/advanced_serial.rs | 67 -- esp32c3-hal/examples/blinky.rs | 31 - esp32c3-hal/examples/blinky_erased_pins.rs | 53 -- esp32c3-hal/examples/clock_monitor.rs | 65 -- esp32c3-hal/examples/crc.rs | 95 --- esp32c3-hal/examples/debug_assist.rs | 96 --- esp32c3-hal/examples/direct-vectoring.rs | 83 -- esp32c3-hal/examples/embassy_hello_world.rs | 48 -- esp32c3-hal/examples/embassy_i2c.rs | 67 -- esp32c3-hal/examples/embassy_i2s_read.rs | 99 --- esp32c3-hal/examples/embassy_i2s_sound.rs | 136 --- esp32c3-hal/examples/embassy_multiprio.rs | 100 --- esp32c3-hal/examples/embassy_rmt_rx.rs | 110 --- esp32c3-hal/examples/embassy_rmt_tx.rs | 79 -- esp32c3-hal/examples/embassy_serial.rs | 96 --- esp32c3-hal/examples/embassy_spi.rs | 87 -- .../examples/embassy_usb_serial_jtag.rs | 89 -- esp32c3-hal/examples/embassy_wait.rs | 44 - esp32c3-hal/examples/gpio_interrupt.rs | 59 -- esp32c3-hal/examples/hello_rgb.rs | 66 -- esp32c3-hal/examples/hello_world.rs | 35 - esp32c3-hal/examples/i2c_display.rs | 121 --- esp32c3-hal/examples/i2s_read.rs | 78 -- esp32c3-hal/examples/i2s_sound.rs | 120 --- esp32c3-hal/examples/interrupt_preemption.rs | 132 --- esp32c3-hal/examples/ledc.rs | 66 -- esp32c3-hal/examples/qspi_flash.rs | 167 ---- esp32c3-hal/examples/read_efuse.rs | 21 - esp32c3-hal/examples/rmt_rx.rs | 99 --- esp32c3-hal/examples/rmt_tx.rs | 61 -- esp32c3-hal/examples/rng.rs | 28 - esp32c3-hal/examples/rsa.rs | 156 ---- esp32c3-hal/examples/rtc_time.rs | 22 - esp32c3-hal/examples/rtc_watchdog.rs | 60 -- esp32c3-hal/examples/serial_interrupts.rs | 88 -- esp32c3-hal/examples/sha.rs | 71 -- esp32c3-hal/examples/software_interrupts.rs | 142 ---- .../examples/spi_eh1_device_loopback.rs | 140 --- esp32c3-hal/examples/spi_loopback.rs | 58 -- esp32c3-hal/examples/spi_loopback_dma.rs | 97 --- esp32c3-hal/examples/spi_slave_dma.rs | 203 ----- esp32c3-hal/examples/systimer.rs | 114 --- esp32c3-hal/examples/timer_interrupt.rs | 82 -- esp32c3-hal/examples/twai.rs | 86 -- esp32c3-hal/examples/usb_serial_jtag.rs | 79 -- esp32c3-hal/examples/watchdog.rs | 31 - esp32c3-hal/src/lib.rs | 9 - esp32c6-hal/.cargo/config.toml | 12 - esp32c6-hal/Cargo.toml | 186 ---- esp32c6-hal/README.md | 51 -- esp32c6-hal/build.rs | 16 - esp32c6-hal/examples/adc.rs | 39 - esp32c6-hal/examples/adc_cal.rs | 52 -- esp32c6-hal/examples/advanced_serial.rs | 67 -- esp32c6-hal/examples/aes.rs | 85 -- esp32c6-hal/examples/aes_dma.rs | 153 ---- esp32c6-hal/examples/blinky_erased_pins.rs | 53 -- esp32c6-hal/examples/clock_monitor.rs | 65 -- esp32c6-hal/examples/crc.rs | 96 --- esp32c6-hal/examples/debug_assist.rs | 96 --- esp32c6-hal/examples/direct-vectoring.rs | 84 -- esp32c6-hal/examples/ecc.rs | 724 ---------------- esp32c6-hal/examples/embassy_hello_world.rs | 48 -- esp32c6-hal/examples/embassy_i2c.rs | 67 -- esp32c6-hal/examples/embassy_i2s_read.rs | 99 --- esp32c6-hal/examples/embassy_i2s_sound.rs | 136 --- esp32c6-hal/examples/embassy_rmt_rx.rs | 110 --- esp32c6-hal/examples/embassy_rmt_tx.rs | 79 -- esp32c6-hal/examples/embassy_serial.rs | 96 --- esp32c6-hal/examples/embassy_spi.rs | 87 -- esp32c6-hal/examples/embassy_wait.rs | 44 - esp32c6-hal/examples/gpio_interrupt.rs | 60 -- esp32c6-hal/examples/hello_rgb.rs | 65 -- esp32c6-hal/examples/hello_world.rs | 35 - esp32c6-hal/examples/hmac.rs | 121 --- .../examples/i2c_bmp180_calibration_data.rs | 40 - esp32c6-hal/examples/i2c_display.rs | 121 --- esp32c6-hal/examples/i2s_read.rs | 78 -- esp32c6-hal/examples/i2s_sound.rs | 120 --- esp32c6-hal/examples/ledc.rs | 66 -- esp32c6-hal/examples/mcpwm.rs | 49 -- esp32c6-hal/examples/parl_io_rx.rs | 70 -- esp32c6-hal/examples/pcnt_encoder.rs | 133 --- esp32c6-hal/examples/qspi_flash.rs | 167 ---- esp32c6-hal/examples/ram.rs | 94 -- esp32c6-hal/examples/read_efuse.rs | 21 - esp32c6-hal/examples/rmt_rx.rs | 99 --- esp32c6-hal/examples/rmt_tx.rs | 61 -- esp32c6-hal/examples/rng.rs | 28 - esp32c6-hal/examples/rsa.rs | 156 ---- esp32c6-hal/examples/rtc_time.rs | 22 - esp32c6-hal/examples/rtc_watchdog.rs | 60 -- esp32c6-hal/examples/serial_interrupts.rs | 88 -- esp32c6-hal/examples/sha.rs | 71 -- esp32c6-hal/examples/software_interrupts.rs | 141 --- .../examples/spi_eh1_device_loopback.rs | 140 --- esp32c6-hal/examples/spi_eh1_loopback.rs | 104 --- .../spi_halfduplex_read_manufacturer_id.rs | 101 --- esp32c6-hal/examples/spi_loopback.rs | 58 -- esp32c6-hal/examples/spi_loopback_dma.rs | 97 --- esp32c6-hal/examples/systimer.rs | 114 --- esp32c6-hal/examples/timer_interrupt.rs | 86 -- esp32c6-hal/examples/usb_serial_jtag.rs | 78 -- esp32c6-hal/examples/watchdog.rs | 31 - esp32c6-hal/src/lib.rs | 9 - esp32h2-hal/.cargo/config.toml | 12 - esp32h2-hal/Cargo.toml | 187 ---- esp32h2-hal/README.md | 51 -- esp32h2-hal/build.rs | 16 - esp32h2-hal/examples/adc.rs | 39 - esp32h2-hal/examples/advanced_serial.rs | 67 -- esp32h2-hal/examples/aes.rs | 85 -- esp32h2-hal/examples/aes_dma.rs | 153 ---- esp32h2-hal/examples/blinky.rs | 31 - esp32h2-hal/examples/blinky_erased_pins.rs | 53 -- esp32h2-hal/examples/clock_monitor.rs | 65 -- esp32h2-hal/examples/crc.rs | 96 --- esp32h2-hal/examples/embassy_hello_world.rs | 48 -- esp32h2-hal/examples/embassy_i2c.rs | 67 -- esp32h2-hal/examples/embassy_i2s_read.rs | 99 --- esp32h2-hal/examples/embassy_i2s_sound.rs | 136 --- esp32h2-hal/examples/embassy_multiprio.rs | 100 --- esp32h2-hal/examples/embassy_parl_io_rx.rs | 78 -- esp32h2-hal/examples/embassy_parl_io_tx.rs | 103 --- esp32h2-hal/examples/embassy_rmt_rx.rs | 110 --- esp32h2-hal/examples/embassy_rmt_tx.rs | 79 -- esp32h2-hal/examples/embassy_serial.rs | 96 --- esp32h2-hal/examples/embassy_spi.rs | 87 -- .../examples/embassy_usb_serial_jtag.rs | 88 -- esp32h2-hal/examples/embassy_wait.rs | 44 - esp32h2-hal/examples/etm_blinky_systimer.rs | 44 - esp32h2-hal/examples/etm_gpio.rs | 41 - esp32h2-hal/examples/gpio_interrupt.rs | 60 -- esp32h2-hal/examples/hello_rgb.rs | 65 -- esp32h2-hal/examples/hello_world.rs | 35 - esp32h2-hal/examples/hmac.rs | 121 --- .../examples/i2c_bmp180_calibration_data.rs | 40 - esp32h2-hal/examples/i2c_display.rs | 121 --- esp32h2-hal/examples/i2s_read.rs | 78 -- esp32h2-hal/examples/i2s_sound.rs | 120 --- esp32h2-hal/examples/interrupt_preemption.rs | 132 --- esp32h2-hal/examples/ledc.rs | 66 -- esp32h2-hal/examples/mcpwm.rs | 49 -- esp32h2-hal/examples/parl_io_tx.rs | 93 -- esp32h2-hal/examples/qspi_flash.rs | 167 ---- esp32h2-hal/examples/ram.rs | 94 -- esp32h2-hal/examples/read_efuse.rs | 21 - esp32h2-hal/examples/rmt_rx.rs | 99 --- esp32h2-hal/examples/rmt_tx.rs | 61 -- esp32h2-hal/examples/rng.rs | 28 - esp32h2-hal/examples/rsa.rs | 156 ---- esp32h2-hal/examples/rtc_time.rs | 22 - esp32h2-hal/examples/rtc_watchdog.rs | 60 -- esp32h2-hal/examples/serial_interrupts.rs | 88 -- esp32h2-hal/examples/sha.rs | 71 -- esp32h2-hal/examples/software_interrupts.rs | 141 --- .../examples/spi_eh1_device_loopback.rs | 140 --- esp32h2-hal/examples/spi_eh1_loopback.rs | 104 --- .../spi_halfduplex_read_manufacturer_id.rs | 101 --- esp32h2-hal/examples/spi_loopback_dma.rs | 90 -- esp32h2-hal/examples/spi_slave_dma.rs | 203 ----- esp32h2-hal/examples/systimer.rs | 114 --- esp32h2-hal/examples/timer_interrupt.rs | 86 -- esp32h2-hal/examples/usb_serial_jtag.rs | 78 -- esp32h2-hal/examples/watchdog.rs | 31 - esp32h2-hal/src/lib.rs | 9 - esp32p4-hal/.cargo/config.toml | 12 - esp32p4-hal/Cargo.toml | 97 --- esp32p4-hal/README.md | 51 -- esp32p4-hal/build.rs | 16 - esp32p4-hal/examples/hello_world.rs | 20 - esp32p4-hal/src/lib.rs | 9 - esp32s2-hal/.cargo/config.toml | 17 - esp32s2-hal/Cargo.toml | 160 ---- esp32s2-hal/README.md | 60 -- esp32s2-hal/build.rs | 36 - esp32s2-hal/examples/adc.rs | 40 - esp32s2-hal/examples/aes.rs | 85 -- esp32s2-hal/examples/blinky.rs | 31 - esp32s2-hal/examples/clock_monitor.rs | 64 -- esp32s2-hal/examples/crc.rs | 97 --- esp32s2-hal/examples/embassy_hello_world.rs | 53 -- esp32s2-hal/examples/embassy_i2c.rs | 67 -- esp32s2-hal/examples/embassy_i2s_read.rs | 97 --- esp32s2-hal/examples/embassy_i2s_sound.rs | 136 --- esp32s2-hal/examples/embassy_multiprio.rs | 100 --- esp32s2-hal/examples/embassy_serial.rs | 96 --- esp32s2-hal/examples/embassy_spi.rs | 87 -- esp32s2-hal/examples/embassy_wait.rs | 50 -- esp32s2-hal/examples/gpio_interrupt.rs | 69 -- esp32s2-hal/examples/hello_rgb.rs | 66 -- esp32s2-hal/examples/hmac.rs | 121 --- .../examples/i2c_bmp180_calibration_data.rs | 40 - esp32s2-hal/examples/i2c_display.rs | 121 --- esp32s2-hal/examples/i2s_read.rs | 76 -- esp32s2-hal/examples/i2s_sound.rs | 120 --- esp32s2-hal/examples/ledc.rs | 68 -- esp32s2-hal/examples/pcnt_encoder.rs | 134 --- esp32s2-hal/examples/psram.rs | 49 -- esp32s2-hal/examples/ram.rs | 97 --- esp32s2-hal/examples/read_efuse.rs | 21 - esp32s2-hal/examples/rmt_rx.rs | 91 -- esp32s2-hal/examples/rmt_tx.rs | 60 -- esp32s2-hal/examples/rng.rs | 28 - esp32s2-hal/examples/rsa.rs | 157 ---- esp32s2-hal/examples/rtc_time.rs | 22 - esp32s2-hal/examples/rtc_watchdog.rs | 59 -- esp32s2-hal/examples/serial_interrupts.rs | 85 -- esp32s2-hal/examples/sha.rs | 72 -- esp32s2-hal/examples/software_interrupts.rs | 139 --- .../examples/spi_eh1_device_loopback.rs | 140 --- esp32s2-hal/examples/spi_eh1_loopback.rs | 104 --- .../spi_halfduplex_read_manufacturer_id.rs | 101 --- esp32s2-hal/examples/spi_loopback.rs | 58 -- esp32s2-hal/examples/spi_loopback_dma.rs | 97 --- esp32s2-hal/examples/systimer.rs | 113 --- esp32s2-hal/examples/timer_interrupt.rs | 120 --- esp32s2-hal/examples/watchdog.rs | 31 - esp32s2-hal/rust-toolchain.toml | 4 - esp32s2-hal/src/lib.rs | 9 - esp32s3-hal/.cargo/config.toml | 17 - esp32s3-hal/Cargo.toml | 191 ----- esp32s3-hal/README.md | 60 -- esp32s3-hal/build.rs | 16 - esp32s3-hal/examples/adc.rs | 40 - esp32s3-hal/examples/adc_cal.rs | 51 -- esp32s3-hal/examples/advanced_serial.rs | 64 -- esp32s3-hal/examples/aes.rs | 85 -- esp32s3-hal/examples/aes_dma.rs | 153 ---- esp32s3-hal/examples/blinky.rs | 31 - esp32s3-hal/examples/blinky_erased_pins.rs | 53 -- esp32s3-hal/examples/debug_assist.rs | 78 -- esp32s3-hal/examples/embassy_hello_world.rs | 53 -- esp32s3-hal/examples/embassy_i2c.rs | 67 -- esp32s3-hal/examples/embassy_multicore.rs | 97 --- .../examples/embassy_multicore_interrupt.rs | 124 --- esp32s3-hal/examples/embassy_multiprio.rs | 100 --- esp32s3-hal/examples/embassy_rmt_rx.rs | 110 --- esp32s3-hal/examples/embassy_rmt_tx.rs | 79 -- esp32s3-hal/examples/embassy_serial.rs | 96 --- esp32s3-hal/examples/embassy_spi.rs | 87 -- .../examples/embassy_usb_serial_jtag.rs | 88 -- esp32s3-hal/examples/embassy_wait.rs | 50 -- esp32s3-hal/examples/hello_world.rs | 36 - esp32s3-hal/examples/hmac.rs | 121 --- .../examples/i2c_bmp180_calibration_data.rs | 40 - esp32s3-hal/examples/i2s_sound.rs | 125 --- esp32s3-hal/examples/mcpwm.rs | 49 -- esp32s3-hal/examples/multicore.rs | 70 -- esp32s3-hal/examples/pcnt_encoder.rs | 134 --- esp32s3-hal/examples/qspi_flash.rs | 167 ---- esp32s3-hal/examples/ram.rs | 97 --- esp32s3-hal/examples/read_efuse.rs | 21 - esp32s3-hal/examples/rmt_rx.rs | 99 --- esp32s3-hal/examples/rmt_tx.rs | 61 -- esp32s3-hal/examples/rng.rs | 28 - esp32s3-hal/examples/rtc_time.rs | 22 - esp32s3-hal/examples/rtc_watchdog.rs | 59 -- esp32s3-hal/examples/sha.rs | 72 -- esp32s3-hal/examples/sleep_timer.rs | 41 - esp32s3-hal/examples/sleep_timer_rtcio.rs | 58 -- esp32s3-hal/examples/software_interrupts.rs | 139 --- .../examples/spi_eh1_device_loopback.rs | 140 --- esp32s3-hal/examples/spi_eh1_loopback.rs | 104 --- .../spi_halfduplex_read_manufacturer_id.rs | 101 --- esp32s3-hal/examples/spi_loopback.rs | 58 -- esp32s3-hal/examples/spi_loopback_dma.rs | 97 --- esp32s3-hal/examples/spi_slave_dma.rs | 203 ----- esp32s3-hal/examples/timer_interrupt.rs | 118 --- esp32s3-hal/examples/ulp_riscv_core_basic.rs | 47 - esp32s3-hal/examples/usb_serial.rs | 67 -- esp32s3-hal/examples/watchdog.rs | 31 - esp32s3-hal/rust-toolchain.toml | 4 - esp32s3-hal/src/lib.rs | 9 - examples/.cargo/config.toml | 31 + examples/Cargo.toml | 72 ++ examples/README.md | 1 + examples/rustfmt.toml | 4 + examples/src/bin/adc.rs | 52 ++ .../examples => examples/src/bin}/adc_cal.rs | 29 +- .../src/bin}/advanced_serial.rs | 10 +- .../examples => examples/src/bin}/aes.rs | 29 +- .../examples => examples/src/bin}/aes_dma.rs | 27 +- .../examples => examples/src/bin}/blinky.rs | 10 +- .../src/bin}/blinky_erased_pins.rs | 32 +- .../src/bin}/clock_monitor.rs | 34 +- .../examples => examples/src/bin}/crc.rs | 13 +- .../examples => examples/src/bin}/dac.rs | 28 +- .../src/bin}/debug_assist.rs | 70 +- .../src/bin/direct_vectoring.rs | 73 +- .../examples => examples/src/bin}/ecc.rs | 127 ++- .../src/bin}/embassy_hello_world.rs | 11 +- .../src/bin}/embassy_i2c.rs | 19 +- .../src/bin}/embassy_i2s_read.rs | 54 +- .../src/bin}/embassy_i2s_sound.rs | 52 +- .../src/bin}/embassy_multicore.rs | 15 +- .../src/bin}/embassy_multicore_interrupt.rs | 15 +- .../src/bin}/embassy_multiprio.rs | 22 +- .../src/bin}/embassy_parl_io_rx.rs | 21 +- .../src/bin}/embassy_parl_io_tx.rs | 25 +- .../src/bin}/embassy_rmt_rx.rs | 68 +- .../src/bin}/embassy_rmt_tx.rs | 34 +- .../src/bin}/embassy_serial.rs | 21 +- .../src/bin}/embassy_spi.rs | 31 +- .../src/bin}/embassy_usb_serial_jtag.rs | 22 +- .../src/bin}/embassy_wait.rs | 12 +- .../src/bin}/etm_blinky_systimer.rs | 11 +- .../examples => examples/src/bin}/etm_gpio.rs | 11 +- .../src/bin}/gpio_interrupt.rs | 35 +- .../src/bin}/hello_rgb.rs | 29 +- .../src/bin}/hello_world.rs | 23 +- .../examples => examples/src/bin}/hmac.rs | 6 +- .../src/bin}/i2c_bmp180_calibration_data.rs | 16 +- .../src/bin}/i2c_display.rs | 10 +- .../examples => examples/src/bin}/i2s_read.rs | 37 +- .../src/bin}/i2s_sound.rs | 37 +- .../src/bin}/interrupt_preemption.rs | 49 +- .../src/bin}/lcd_i8080.rs | 9 +- .../examples => examples/src/bin}/ledc.rs | 10 +- .../src/bin}/lp_core_basic.rs | 18 +- .../src/bin}/lp_core_i2c.rs | 12 +- .../src/bin}/lp_core_uart.rs | 19 +- .../examples => examples/src/bin}/mcpwm.rs | 14 +- .../src/bin}/multicore.rs | 20 +- .../src/bin}/octal_psram.rs | 28 +- .../src/bin}/parl_io_rx.rs | 6 +- .../src/bin}/parl_io_tx.rs | 6 +- .../src/bin}/pcnt_encoder.rs | 46 +- .../examples => examples/src/bin}/psram.rs | 34 +- .../src/bin}/qspi_flash.rs | 52 +- .../examples => examples/src/bin}/ram.rs | 18 +- examples/src/bin/read_efuse.rs | 29 + examples/src/bin/rmt_rx.rs | 131 +++ .../examples => examples/src/bin}/rmt_tx.rs | 33 +- .../examples => examples/src/bin}/rng.rs | 8 +- .../examples => examples/src/bin}/rsa.rs | 77 +- .../examples => examples/src/bin}/rtc_time.rs | 5 +- .../src/bin}/rtc_watchdog.rs | 41 +- .../src/bin}/serial_interrupts.rs | 20 +- .../examples => examples/src/bin}/sha.rs | 29 +- .../src/bin}/sleep_lpio.rs | 6 +- .../src/bin}/sleep_timer.rs | 11 +- .../src/bin}/sleep_timer_ext0.rs | 10 +- .../src/bin}/sleep_timer_ext1.rs | 14 +- .../src/bin}/sleep_timer_rtcio.rs | 27 +- .../src/bin}/software_interrupts.rs | 41 +- .../src/bin}/spi_eh1_device_loopback.rs | 49 +- .../src/bin}/spi_eh1_loopback.rs | 21 +- .../spi_halfduplex_read_manufacturer_id.rs | 47 +- .../src/bin}/spi_loopback.rs | 18 +- .../src/bin}/spi_loopback_dma.rs | 22 +- .../src/bin}/spi_slave_dma.rs | 37 +- .../examples => examples/src/bin}/systimer.rs | 38 +- .../src/bin}/timer_interrupt.rs | 21 +- .../examples => examples/src/bin}/twai.rs | 23 +- .../src/bin}/ulp_riscv_core_basic.rs | 19 +- .../src/bin}/usb_serial.rs | 15 +- .../src/bin}/usb_serial_jtag.rs | 32 +- .../examples => examples/src/bin}/watchdog.rs | 11 +- examples/src/lib.rs | 14 + 473 files changed, 2156 insertions(+), 31731 deletions(-) delete mode 100644 esp32-hal/.cargo/config.toml delete mode 100644 esp32-hal/Cargo.toml delete mode 100644 esp32-hal/README.md delete mode 100644 esp32-hal/build.rs delete mode 100644 esp32-hal/examples/adc.rs delete mode 100644 esp32-hal/examples/advanced_serial.rs delete mode 100644 esp32-hal/examples/aes.rs delete mode 100644 esp32-hal/examples/blinky.rs delete mode 100644 esp32-hal/examples/blinky_erased_pins.rs delete mode 100644 esp32-hal/examples/clock_monitor.rs delete mode 100644 esp32-hal/examples/crc.rs delete mode 100644 esp32-hal/examples/dac.rs delete mode 100644 esp32-hal/examples/embassy_i2s_read.rs delete mode 100644 esp32-hal/examples/embassy_i2s_sound.rs delete mode 100644 esp32-hal/examples/embassy_multiprio.rs delete mode 100644 esp32-hal/examples/embassy_rmt_rx.rs delete mode 100644 esp32-hal/examples/embassy_rmt_tx.rs delete mode 100644 esp32-hal/examples/gpio_interrupt.rs delete mode 100644 esp32-hal/examples/hello_rgb.rs delete mode 100644 esp32-hal/examples/hello_world.rs delete mode 100644 esp32-hal/examples/i2c_bmp180_calibration_data.rs delete mode 100644 esp32-hal/examples/i2c_display.rs delete mode 100644 esp32-hal/examples/i2s_read.rs delete mode 100644 esp32-hal/examples/ledc.rs delete mode 100644 esp32-hal/examples/pcnt_encoder.rs delete mode 100644 esp32-hal/examples/psram.rs delete mode 100644 esp32-hal/examples/qspi_flash.rs delete mode 100644 esp32-hal/examples/ram.rs delete mode 100644 esp32-hal/examples/read_efuse.rs delete mode 100644 esp32-hal/examples/rmt_rx.rs delete mode 100644 esp32-hal/examples/rsa.rs delete mode 100644 esp32-hal/examples/rtc_watchdog.rs delete mode 100644 esp32-hal/examples/serial_interrupts.rs delete mode 100644 esp32-hal/examples/sha.rs delete mode 100644 esp32-hal/examples/sleep_timer.rs delete mode 100644 esp32-hal/examples/sleep_timer_ext0.rs delete mode 100644 esp32-hal/examples/sleep_timer_ext1.rs delete mode 100644 esp32-hal/examples/spi_eh1_device_loopback.rs delete mode 100644 esp32-hal/examples/spi_eh1_loopback.rs delete mode 100644 esp32-hal/examples/spi_halfduplex_read_manufacturer_id.rs delete mode 100644 esp32-hal/examples/spi_loopback.rs delete mode 100644 esp32-hal/examples/spi_loopback_dma.rs delete mode 100644 esp32-hal/examples/timer_interrupt.rs delete mode 100644 esp32-hal/examples/watchdog.rs delete mode 100644 esp32-hal/rust-toolchain.toml delete mode 100644 esp32-hal/src/lib.rs delete mode 100644 esp32c2-hal/.cargo/config.toml delete mode 100644 esp32c2-hal/Cargo.toml delete mode 100644 esp32c2-hal/README.md delete mode 100644 esp32c2-hal/build.rs delete mode 100644 esp32c2-hal/examples/adc.rs delete mode 100644 esp32c2-hal/examples/advanced_serial.rs delete mode 100644 esp32c2-hal/examples/blinky.rs delete mode 100644 esp32c2-hal/examples/blinky_erased_pins.rs delete mode 100644 esp32c2-hal/examples/clock_monitor.rs delete mode 100644 esp32c2-hal/examples/crc.rs delete mode 100644 esp32c2-hal/examples/debug_assist.rs delete mode 100644 esp32c2-hal/examples/direct-vectoring.rs delete mode 100644 esp32c2-hal/examples/ecc.rs delete mode 100644 esp32c2-hal/examples/embassy_hello_world.rs delete mode 100644 esp32c2-hal/examples/embassy_i2c.rs delete mode 100644 esp32c2-hal/examples/embassy_multiprio.rs delete mode 100644 esp32c2-hal/examples/embassy_serial.rs delete mode 100644 esp32c2-hal/examples/embassy_spi.rs delete mode 100644 esp32c2-hal/examples/embassy_wait.rs delete mode 100644 esp32c2-hal/examples/gpio_interrupt.rs delete mode 100644 esp32c2-hal/examples/hello_world.rs delete mode 100644 esp32c2-hal/examples/i2c_bmp180_calibration_data.rs delete mode 100644 esp32c2-hal/examples/i2c_display.rs delete mode 100644 esp32c2-hal/examples/interrupt_preemption.rs delete mode 100644 esp32c2-hal/examples/ledc.rs delete mode 100644 esp32c2-hal/examples/qspi_flash.rs delete mode 100644 esp32c2-hal/examples/read_efuse.rs delete mode 100644 esp32c2-hal/examples/rng.rs delete mode 100644 esp32c2-hal/examples/rtc_time.rs delete mode 100644 esp32c2-hal/examples/serial_interrupts.rs delete mode 100644 esp32c2-hal/examples/software_interrupts.rs delete mode 100644 esp32c2-hal/examples/spi_eh1_loopback.rs delete mode 100644 esp32c2-hal/examples/spi_halfduplex_read_manufacturer_id.rs delete mode 100644 esp32c2-hal/examples/spi_loopback.rs delete mode 100644 esp32c2-hal/examples/spi_slave_dma.rs delete mode 100644 esp32c2-hal/examples/systimer.rs delete mode 100644 esp32c2-hal/src/lib.rs delete mode 100644 esp32c3-hal/.cargo/config.toml delete mode 100644 esp32c3-hal/Cargo.toml delete mode 100644 esp32c3-hal/README.md delete mode 100644 esp32c3-hal/build.rs delete mode 100644 esp32c3-hal/examples/adc.rs delete mode 100644 esp32c3-hal/examples/adc_cal.rs delete mode 100644 esp32c3-hal/examples/advanced_serial.rs delete mode 100644 esp32c3-hal/examples/blinky.rs delete mode 100644 esp32c3-hal/examples/blinky_erased_pins.rs delete mode 100644 esp32c3-hal/examples/clock_monitor.rs delete mode 100644 esp32c3-hal/examples/crc.rs delete mode 100644 esp32c3-hal/examples/debug_assist.rs delete mode 100644 esp32c3-hal/examples/direct-vectoring.rs delete mode 100644 esp32c3-hal/examples/embassy_hello_world.rs delete mode 100644 esp32c3-hal/examples/embassy_i2c.rs delete mode 100644 esp32c3-hal/examples/embassy_i2s_read.rs delete mode 100644 esp32c3-hal/examples/embassy_i2s_sound.rs delete mode 100644 esp32c3-hal/examples/embassy_multiprio.rs delete mode 100644 esp32c3-hal/examples/embassy_rmt_rx.rs delete mode 100644 esp32c3-hal/examples/embassy_rmt_tx.rs delete mode 100644 esp32c3-hal/examples/embassy_serial.rs delete mode 100644 esp32c3-hal/examples/embassy_spi.rs delete mode 100644 esp32c3-hal/examples/embassy_usb_serial_jtag.rs delete mode 100644 esp32c3-hal/examples/embassy_wait.rs delete mode 100644 esp32c3-hal/examples/gpio_interrupt.rs delete mode 100644 esp32c3-hal/examples/hello_rgb.rs delete mode 100644 esp32c3-hal/examples/hello_world.rs delete mode 100644 esp32c3-hal/examples/i2c_display.rs delete mode 100644 esp32c3-hal/examples/i2s_read.rs delete mode 100644 esp32c3-hal/examples/i2s_sound.rs delete mode 100644 esp32c3-hal/examples/interrupt_preemption.rs delete mode 100644 esp32c3-hal/examples/ledc.rs delete mode 100644 esp32c3-hal/examples/qspi_flash.rs delete mode 100644 esp32c3-hal/examples/read_efuse.rs delete mode 100644 esp32c3-hal/examples/rmt_rx.rs delete mode 100644 esp32c3-hal/examples/rmt_tx.rs delete mode 100644 esp32c3-hal/examples/rng.rs delete mode 100644 esp32c3-hal/examples/rsa.rs delete mode 100644 esp32c3-hal/examples/rtc_time.rs delete mode 100644 esp32c3-hal/examples/rtc_watchdog.rs delete mode 100644 esp32c3-hal/examples/serial_interrupts.rs delete mode 100644 esp32c3-hal/examples/sha.rs delete mode 100644 esp32c3-hal/examples/software_interrupts.rs delete mode 100644 esp32c3-hal/examples/spi_eh1_device_loopback.rs delete mode 100644 esp32c3-hal/examples/spi_loopback.rs delete mode 100644 esp32c3-hal/examples/spi_loopback_dma.rs delete mode 100644 esp32c3-hal/examples/spi_slave_dma.rs delete mode 100644 esp32c3-hal/examples/systimer.rs delete mode 100644 esp32c3-hal/examples/timer_interrupt.rs delete mode 100644 esp32c3-hal/examples/twai.rs delete mode 100644 esp32c3-hal/examples/usb_serial_jtag.rs delete mode 100644 esp32c3-hal/examples/watchdog.rs delete mode 100644 esp32c3-hal/src/lib.rs delete mode 100644 esp32c6-hal/.cargo/config.toml delete mode 100644 esp32c6-hal/Cargo.toml delete mode 100644 esp32c6-hal/README.md delete mode 100644 esp32c6-hal/build.rs delete mode 100644 esp32c6-hal/examples/adc.rs delete mode 100644 esp32c6-hal/examples/adc_cal.rs delete mode 100644 esp32c6-hal/examples/advanced_serial.rs delete mode 100644 esp32c6-hal/examples/aes.rs delete mode 100644 esp32c6-hal/examples/aes_dma.rs delete mode 100644 esp32c6-hal/examples/blinky_erased_pins.rs delete mode 100644 esp32c6-hal/examples/clock_monitor.rs delete mode 100644 esp32c6-hal/examples/crc.rs delete mode 100644 esp32c6-hal/examples/debug_assist.rs delete mode 100644 esp32c6-hal/examples/direct-vectoring.rs delete mode 100644 esp32c6-hal/examples/ecc.rs delete mode 100644 esp32c6-hal/examples/embassy_hello_world.rs delete mode 100644 esp32c6-hal/examples/embassy_i2c.rs delete mode 100644 esp32c6-hal/examples/embassy_i2s_read.rs delete mode 100644 esp32c6-hal/examples/embassy_i2s_sound.rs delete mode 100644 esp32c6-hal/examples/embassy_rmt_rx.rs delete mode 100644 esp32c6-hal/examples/embassy_rmt_tx.rs delete mode 100644 esp32c6-hal/examples/embassy_serial.rs delete mode 100644 esp32c6-hal/examples/embassy_spi.rs delete mode 100644 esp32c6-hal/examples/embassy_wait.rs delete mode 100644 esp32c6-hal/examples/gpio_interrupt.rs delete mode 100644 esp32c6-hal/examples/hello_rgb.rs delete mode 100644 esp32c6-hal/examples/hello_world.rs delete mode 100644 esp32c6-hal/examples/hmac.rs delete mode 100644 esp32c6-hal/examples/i2c_bmp180_calibration_data.rs delete mode 100644 esp32c6-hal/examples/i2c_display.rs delete mode 100644 esp32c6-hal/examples/i2s_read.rs delete mode 100644 esp32c6-hal/examples/i2s_sound.rs delete mode 100644 esp32c6-hal/examples/ledc.rs delete mode 100644 esp32c6-hal/examples/mcpwm.rs delete mode 100644 esp32c6-hal/examples/parl_io_rx.rs delete mode 100644 esp32c6-hal/examples/pcnt_encoder.rs delete mode 100644 esp32c6-hal/examples/qspi_flash.rs delete mode 100644 esp32c6-hal/examples/ram.rs delete mode 100644 esp32c6-hal/examples/read_efuse.rs delete mode 100644 esp32c6-hal/examples/rmt_rx.rs delete mode 100644 esp32c6-hal/examples/rmt_tx.rs delete mode 100644 esp32c6-hal/examples/rng.rs delete mode 100644 esp32c6-hal/examples/rsa.rs delete mode 100644 esp32c6-hal/examples/rtc_time.rs delete mode 100644 esp32c6-hal/examples/rtc_watchdog.rs delete mode 100644 esp32c6-hal/examples/serial_interrupts.rs delete mode 100644 esp32c6-hal/examples/sha.rs delete mode 100644 esp32c6-hal/examples/software_interrupts.rs delete mode 100644 esp32c6-hal/examples/spi_eh1_device_loopback.rs delete mode 100644 esp32c6-hal/examples/spi_eh1_loopback.rs delete mode 100644 esp32c6-hal/examples/spi_halfduplex_read_manufacturer_id.rs delete mode 100644 esp32c6-hal/examples/spi_loopback.rs delete mode 100644 esp32c6-hal/examples/spi_loopback_dma.rs delete mode 100644 esp32c6-hal/examples/systimer.rs delete mode 100644 esp32c6-hal/examples/timer_interrupt.rs delete mode 100644 esp32c6-hal/examples/usb_serial_jtag.rs delete mode 100644 esp32c6-hal/examples/watchdog.rs delete mode 100644 esp32c6-hal/src/lib.rs delete mode 100644 esp32h2-hal/.cargo/config.toml delete mode 100644 esp32h2-hal/Cargo.toml delete mode 100644 esp32h2-hal/README.md delete mode 100644 esp32h2-hal/build.rs delete mode 100644 esp32h2-hal/examples/adc.rs delete mode 100644 esp32h2-hal/examples/advanced_serial.rs delete mode 100644 esp32h2-hal/examples/aes.rs delete mode 100644 esp32h2-hal/examples/aes_dma.rs delete mode 100644 esp32h2-hal/examples/blinky.rs delete mode 100644 esp32h2-hal/examples/blinky_erased_pins.rs delete mode 100644 esp32h2-hal/examples/clock_monitor.rs delete mode 100644 esp32h2-hal/examples/crc.rs delete mode 100644 esp32h2-hal/examples/embassy_hello_world.rs delete mode 100644 esp32h2-hal/examples/embassy_i2c.rs delete mode 100644 esp32h2-hal/examples/embassy_i2s_read.rs delete mode 100644 esp32h2-hal/examples/embassy_i2s_sound.rs delete mode 100644 esp32h2-hal/examples/embassy_multiprio.rs delete mode 100644 esp32h2-hal/examples/embassy_parl_io_rx.rs delete mode 100644 esp32h2-hal/examples/embassy_parl_io_tx.rs delete mode 100644 esp32h2-hal/examples/embassy_rmt_rx.rs delete mode 100644 esp32h2-hal/examples/embassy_rmt_tx.rs delete mode 100644 esp32h2-hal/examples/embassy_serial.rs delete mode 100644 esp32h2-hal/examples/embassy_spi.rs delete mode 100644 esp32h2-hal/examples/embassy_usb_serial_jtag.rs delete mode 100644 esp32h2-hal/examples/embassy_wait.rs delete mode 100644 esp32h2-hal/examples/etm_blinky_systimer.rs delete mode 100644 esp32h2-hal/examples/etm_gpio.rs delete mode 100644 esp32h2-hal/examples/gpio_interrupt.rs delete mode 100644 esp32h2-hal/examples/hello_rgb.rs delete mode 100644 esp32h2-hal/examples/hello_world.rs delete mode 100644 esp32h2-hal/examples/hmac.rs delete mode 100644 esp32h2-hal/examples/i2c_bmp180_calibration_data.rs delete mode 100644 esp32h2-hal/examples/i2c_display.rs delete mode 100644 esp32h2-hal/examples/i2s_read.rs delete mode 100644 esp32h2-hal/examples/i2s_sound.rs delete mode 100644 esp32h2-hal/examples/interrupt_preemption.rs delete mode 100644 esp32h2-hal/examples/ledc.rs delete mode 100644 esp32h2-hal/examples/mcpwm.rs delete mode 100644 esp32h2-hal/examples/parl_io_tx.rs delete mode 100644 esp32h2-hal/examples/qspi_flash.rs delete mode 100644 esp32h2-hal/examples/ram.rs delete mode 100644 esp32h2-hal/examples/read_efuse.rs delete mode 100644 esp32h2-hal/examples/rmt_rx.rs delete mode 100644 esp32h2-hal/examples/rmt_tx.rs delete mode 100644 esp32h2-hal/examples/rng.rs delete mode 100644 esp32h2-hal/examples/rsa.rs delete mode 100644 esp32h2-hal/examples/rtc_time.rs delete mode 100644 esp32h2-hal/examples/rtc_watchdog.rs delete mode 100644 esp32h2-hal/examples/serial_interrupts.rs delete mode 100644 esp32h2-hal/examples/sha.rs delete mode 100644 esp32h2-hal/examples/software_interrupts.rs delete mode 100644 esp32h2-hal/examples/spi_eh1_device_loopback.rs delete mode 100644 esp32h2-hal/examples/spi_eh1_loopback.rs delete mode 100644 esp32h2-hal/examples/spi_halfduplex_read_manufacturer_id.rs delete mode 100644 esp32h2-hal/examples/spi_loopback_dma.rs delete mode 100644 esp32h2-hal/examples/spi_slave_dma.rs delete mode 100644 esp32h2-hal/examples/systimer.rs delete mode 100644 esp32h2-hal/examples/timer_interrupt.rs delete mode 100644 esp32h2-hal/examples/usb_serial_jtag.rs delete mode 100644 esp32h2-hal/examples/watchdog.rs delete mode 100644 esp32h2-hal/src/lib.rs delete mode 100644 esp32p4-hal/.cargo/config.toml delete mode 100644 esp32p4-hal/Cargo.toml delete mode 100644 esp32p4-hal/README.md delete mode 100644 esp32p4-hal/build.rs delete mode 100644 esp32p4-hal/examples/hello_world.rs delete mode 100644 esp32p4-hal/src/lib.rs delete mode 100644 esp32s2-hal/.cargo/config.toml delete mode 100644 esp32s2-hal/Cargo.toml delete mode 100644 esp32s2-hal/README.md delete mode 100644 esp32s2-hal/build.rs delete mode 100644 esp32s2-hal/examples/adc.rs delete mode 100644 esp32s2-hal/examples/aes.rs delete mode 100644 esp32s2-hal/examples/blinky.rs delete mode 100644 esp32s2-hal/examples/clock_monitor.rs delete mode 100644 esp32s2-hal/examples/crc.rs delete mode 100644 esp32s2-hal/examples/embassy_hello_world.rs delete mode 100644 esp32s2-hal/examples/embassy_i2c.rs delete mode 100644 esp32s2-hal/examples/embassy_i2s_read.rs delete mode 100644 esp32s2-hal/examples/embassy_i2s_sound.rs delete mode 100644 esp32s2-hal/examples/embassy_multiprio.rs delete mode 100644 esp32s2-hal/examples/embassy_serial.rs delete mode 100644 esp32s2-hal/examples/embassy_spi.rs delete mode 100644 esp32s2-hal/examples/embassy_wait.rs delete mode 100644 esp32s2-hal/examples/gpio_interrupt.rs delete mode 100644 esp32s2-hal/examples/hello_rgb.rs delete mode 100644 esp32s2-hal/examples/hmac.rs delete mode 100644 esp32s2-hal/examples/i2c_bmp180_calibration_data.rs delete mode 100644 esp32s2-hal/examples/i2c_display.rs delete mode 100644 esp32s2-hal/examples/i2s_read.rs delete mode 100644 esp32s2-hal/examples/i2s_sound.rs delete mode 100644 esp32s2-hal/examples/ledc.rs delete mode 100644 esp32s2-hal/examples/pcnt_encoder.rs delete mode 100644 esp32s2-hal/examples/psram.rs delete mode 100644 esp32s2-hal/examples/ram.rs delete mode 100644 esp32s2-hal/examples/read_efuse.rs delete mode 100644 esp32s2-hal/examples/rmt_rx.rs delete mode 100644 esp32s2-hal/examples/rmt_tx.rs delete mode 100644 esp32s2-hal/examples/rng.rs delete mode 100644 esp32s2-hal/examples/rsa.rs delete mode 100644 esp32s2-hal/examples/rtc_time.rs delete mode 100644 esp32s2-hal/examples/rtc_watchdog.rs delete mode 100644 esp32s2-hal/examples/serial_interrupts.rs delete mode 100644 esp32s2-hal/examples/sha.rs delete mode 100644 esp32s2-hal/examples/software_interrupts.rs delete mode 100644 esp32s2-hal/examples/spi_eh1_device_loopback.rs delete mode 100644 esp32s2-hal/examples/spi_eh1_loopback.rs delete mode 100644 esp32s2-hal/examples/spi_halfduplex_read_manufacturer_id.rs delete mode 100644 esp32s2-hal/examples/spi_loopback.rs delete mode 100644 esp32s2-hal/examples/spi_loopback_dma.rs delete mode 100644 esp32s2-hal/examples/systimer.rs delete mode 100644 esp32s2-hal/examples/timer_interrupt.rs delete mode 100644 esp32s2-hal/examples/watchdog.rs delete mode 100644 esp32s2-hal/rust-toolchain.toml delete mode 100644 esp32s2-hal/src/lib.rs delete mode 100644 esp32s3-hal/.cargo/config.toml delete mode 100644 esp32s3-hal/Cargo.toml delete mode 100644 esp32s3-hal/README.md delete mode 100644 esp32s3-hal/build.rs delete mode 100644 esp32s3-hal/examples/adc.rs delete mode 100644 esp32s3-hal/examples/adc_cal.rs delete mode 100644 esp32s3-hal/examples/advanced_serial.rs delete mode 100644 esp32s3-hal/examples/aes.rs delete mode 100644 esp32s3-hal/examples/aes_dma.rs delete mode 100644 esp32s3-hal/examples/blinky.rs delete mode 100644 esp32s3-hal/examples/blinky_erased_pins.rs delete mode 100644 esp32s3-hal/examples/debug_assist.rs delete mode 100644 esp32s3-hal/examples/embassy_hello_world.rs delete mode 100644 esp32s3-hal/examples/embassy_i2c.rs delete mode 100644 esp32s3-hal/examples/embassy_multicore.rs delete mode 100644 esp32s3-hal/examples/embassy_multicore_interrupt.rs delete mode 100644 esp32s3-hal/examples/embassy_multiprio.rs delete mode 100644 esp32s3-hal/examples/embassy_rmt_rx.rs delete mode 100644 esp32s3-hal/examples/embassy_rmt_tx.rs delete mode 100644 esp32s3-hal/examples/embassy_serial.rs delete mode 100644 esp32s3-hal/examples/embassy_spi.rs delete mode 100644 esp32s3-hal/examples/embassy_usb_serial_jtag.rs delete mode 100644 esp32s3-hal/examples/embassy_wait.rs delete mode 100644 esp32s3-hal/examples/hello_world.rs delete mode 100644 esp32s3-hal/examples/hmac.rs delete mode 100644 esp32s3-hal/examples/i2c_bmp180_calibration_data.rs delete mode 100644 esp32s3-hal/examples/i2s_sound.rs delete mode 100644 esp32s3-hal/examples/mcpwm.rs delete mode 100644 esp32s3-hal/examples/multicore.rs delete mode 100644 esp32s3-hal/examples/pcnt_encoder.rs delete mode 100644 esp32s3-hal/examples/qspi_flash.rs delete mode 100644 esp32s3-hal/examples/ram.rs delete mode 100644 esp32s3-hal/examples/read_efuse.rs delete mode 100644 esp32s3-hal/examples/rmt_rx.rs delete mode 100644 esp32s3-hal/examples/rmt_tx.rs delete mode 100644 esp32s3-hal/examples/rng.rs delete mode 100644 esp32s3-hal/examples/rtc_time.rs delete mode 100644 esp32s3-hal/examples/rtc_watchdog.rs delete mode 100644 esp32s3-hal/examples/sha.rs delete mode 100644 esp32s3-hal/examples/sleep_timer.rs delete mode 100644 esp32s3-hal/examples/sleep_timer_rtcio.rs delete mode 100644 esp32s3-hal/examples/software_interrupts.rs delete mode 100644 esp32s3-hal/examples/spi_eh1_device_loopback.rs delete mode 100644 esp32s3-hal/examples/spi_eh1_loopback.rs delete mode 100644 esp32s3-hal/examples/spi_halfduplex_read_manufacturer_id.rs delete mode 100644 esp32s3-hal/examples/spi_loopback.rs delete mode 100644 esp32s3-hal/examples/spi_loopback_dma.rs delete mode 100644 esp32s3-hal/examples/spi_slave_dma.rs delete mode 100644 esp32s3-hal/examples/timer_interrupt.rs delete mode 100644 esp32s3-hal/examples/ulp_riscv_core_basic.rs delete mode 100644 esp32s3-hal/examples/usb_serial.rs delete mode 100644 esp32s3-hal/examples/watchdog.rs delete mode 100644 esp32s3-hal/rust-toolchain.toml delete mode 100644 esp32s3-hal/src/lib.rs create mode 100644 examples/.cargo/config.toml create mode 100644 examples/Cargo.toml create mode 100644 examples/README.md create mode 100644 examples/rustfmt.toml create mode 100644 examples/src/bin/adc.rs rename {esp32c2-hal/examples => examples/src/bin}/adc_cal.rs (64%) rename {esp32s2-hal/examples => examples/src/bin}/advanced_serial.rs (89%) rename {esp32c3-hal/examples => examples/src/bin}/aes.rs (77%) rename {esp32c3-hal/examples => examples/src/bin}/aes_dma.rs (87%) rename {esp32c6-hal/examples => examples/src/bin}/blinky.rs (68%) rename {esp32s2-hal/examples => examples/src/bin}/blinky_erased_pins.rs (55%) rename {esp32s3-hal/examples => examples/src/bin}/clock_monitor.rs (67%) rename {esp32s3-hal/examples => examples/src/bin}/crc.rs (93%) rename {esp32s2-hal/examples => examples/src/bin}/dac.rs (57%) rename {esp32h2-hal/examples => examples/src/bin}/debug_assist.rs (56%) rename esp32h2-hal/examples/direct-vectoring.rs => examples/src/bin/direct_vectoring.rs (54%) rename {esp32h2-hal/examples => examples/src/bin}/ecc.rs (90%) rename {esp32-hal/examples => examples/src/bin}/embassy_hello_world.rs (78%) rename {esp32-hal/examples => examples/src/bin}/embassy_i2c.rs (78%) rename {esp32s3-hal/examples => examples/src/bin}/embassy_i2s_read.rs (69%) rename {esp32s3-hal/examples => examples/src/bin}/embassy_i2s_sound.rs (78%) rename {esp32-hal/examples => examples/src/bin}/embassy_multicore.rs (91%) rename {esp32-hal/examples => examples/src/bin}/embassy_multicore_interrupt.rs (93%) rename {esp32c6-hal/examples => examples/src/bin}/embassy_multiprio.rs (87%) rename {esp32c6-hal/examples => examples/src/bin}/embassy_parl_io_rx.rs (82%) rename {esp32c6-hal/examples => examples/src/bin}/embassy_parl_io_tx.rs (82%) rename {esp32s2-hal/examples => examples/src/bin}/embassy_rmt_rx.rs (64%) rename {esp32s2-hal/examples => examples/src/bin}/embassy_rmt_tx.rs (74%) rename {esp32-hal/examples => examples/src/bin}/embassy_serial.rs (87%) rename {esp32-hal/examples => examples/src/bin}/embassy_spi.rs (75%) rename {esp32c6-hal/examples => examples/src/bin}/embassy_usb_serial_jtag.rs (85%) rename {esp32-hal/examples => examples/src/bin}/embassy_wait.rs (78%) rename {esp32c6-hal/examples => examples/src/bin}/etm_blinky_systimer.rs (83%) rename {esp32c6-hal/examples => examples/src/bin}/etm_gpio.rs (81%) rename {esp32s3-hal/examples => examples/src/bin}/gpio_interrupt.rs (50%) rename {esp32s3-hal/examples => examples/src/bin}/hello_rgb.rs (64%) rename {esp32s2-hal/examples => examples/src/bin}/hello_world.rs (62%) rename {esp32c3-hal/examples => examples/src/bin}/hmac.rs (98%) rename {esp32c3-hal/examples => examples/src/bin}/i2c_bmp180_calibration_data.rs (67%) rename {esp32s3-hal/examples => examples/src/bin}/i2c_display.rs (96%) rename {esp32s3-hal/examples => examples/src/bin}/i2s_read.rs (74%) rename {esp32-hal/examples => examples/src/bin}/i2s_sound.rs (82%) rename {esp32c6-hal/examples => examples/src/bin}/interrupt_preemption.rs (78%) rename {esp32s3-hal/examples => examples/src/bin}/lcd_i8080.rs (99%) rename {esp32s3-hal/examples => examples/src/bin}/ledc.rs (92%) rename {esp32c6-hal/examples => examples/src/bin}/lp_core_basic.rs (76%) rename {esp32c6-hal/examples => examples/src/bin}/lp_core_i2c.rs (84%) rename {esp32c6-hal/examples => examples/src/bin}/lp_core_uart.rs (85%) rename {esp32-hal/examples => examples/src/bin}/mcpwm.rs (84%) rename {esp32-hal/examples => examples/src/bin}/multicore.rs (81%) rename {esp32s3-hal/examples => examples/src/bin}/octal_psram.rs (63%) rename {esp32h2-hal/examples => examples/src/bin}/parl_io_rx.rs (97%) rename {esp32c6-hal/examples => examples/src/bin}/parl_io_tx.rs (98%) rename {esp32h2-hal/examples => examples/src/bin}/pcnt_encoder.rs (78%) rename {esp32s3-hal/examples => examples/src/bin}/psram.rs (62%) rename {esp32s2-hal/examples => examples/src/bin}/qspi_flash.rs (78%) rename {esp32c3-hal/examples => examples/src/bin}/ram.rs (89%) create mode 100644 examples/src/bin/read_efuse.rs create mode 100644 examples/src/bin/rmt_rx.rs rename {esp32-hal/examples => examples/src/bin}/rmt_tx.rs (68%) rename {esp32-hal/examples => examples/src/bin}/rng.rs (65%) rename {esp32s3-hal/examples => examples/src/bin}/rsa.rs (73%) rename {esp32-hal/examples => examples/src/bin}/rtc_time.rs (77%) rename {esp32c2-hal/examples => examples/src/bin}/rtc_watchdog.rs (63%) rename {esp32s3-hal/examples => examples/src/bin}/serial_interrupts.rs (86%) rename {esp32c2-hal/examples => examples/src/bin}/sha.rs (77%) rename {esp32c6-hal/examples => examples/src/bin}/sleep_lpio.rs (97%) rename {esp32c3-hal/examples => examples/src/bin}/sleep_timer.rs (89%) rename {esp32s3-hal/examples => examples/src/bin}/sleep_timer_ext0.rs (89%) rename {esp32s3-hal/examples => examples/src/bin}/sleep_timer_ext1.rs (82%) rename {esp32c3-hal/examples => examples/src/bin}/sleep_timer_rtcio.rs (67%) rename {esp32-hal/examples => examples/src/bin}/software_interrupts.rs (84%) rename {esp32c2-hal/examples => examples/src/bin}/spi_eh1_device_loopback.rs (79%) rename {esp32c3-hal/examples => examples/src/bin}/spi_eh1_loopback.rs (91%) rename {esp32c3-hal/examples => examples/src/bin}/spi_halfduplex_read_manufacturer_id.rs (71%) rename {esp32h2-hal/examples => examples/src/bin}/spi_loopback.rs (84%) rename {esp32c2-hal/examples => examples/src/bin}/spi_loopback_dma.rs (86%) rename {esp32c6-hal/examples => examples/src/bin}/spi_slave_dma.rs (90%) rename {esp32s3-hal/examples => examples/src/bin}/systimer.rs (78%) rename {esp32c2-hal/examples => examples/src/bin}/timer_interrupt.rs (75%) rename {esp32s3-hal/examples => examples/src/bin}/twai.rs (84%) rename {esp32s2-hal/examples => examples/src/bin}/ulp_riscv_core_basic.rs (79%) rename {esp32s2-hal/examples => examples/src/bin}/usb_serial.rs (83%) rename {esp32s3-hal/examples => examples/src/bin}/usb_serial_jtag.rs (84%) rename {esp32c2-hal/examples => examples/src/bin}/watchdog.rs (68%) create mode 100644 examples/src/lib.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c5d2940d9..0a927afa2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,3 +1,16 @@ +# NOTE: +# +# When adding support for a new chip to `esp-hal`, there are a number of +# updates which must be made to the CI workflow in order to reflect this; the +# changes are: +# +# 1.) In the 'esp-hal' job, add the name of the chip to the `matrix.soc` array. +# 1a.) If the device has a low-power core (which is supported in +# `esp-lp-hal`), then update the `if` condition to build prerequisites. +# 2.) In the 'msrv-riscv' job, add checks as needed for the new chip. +# 3.) In the 'clippy-riscv' job, add checks as needed for the new chip. +# 3.) In the 'rustfmt' job, add checks as needed for the new chip. + name: CI on: @@ -17,7 +30,7 @@ on: env: CARGO_TERM_COLOR: always GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - MSRV: "1.67.0" + MSRV: "1.76.0" # Cancel any currently running workflows from the same PR, branch, or # tag when a new workflow is triggered. @@ -29,69 +42,85 @@ concurrency: jobs: # -------------------------------------------------------------------------- - # Check Packages + # Build Packages - esp-hal-smartled: + esp-hal: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + soc: [ + # RISC-V devices: + "esp32c2", + "esp32c3", + "esp32c6", + "esp32h2", + "esp32p4", + # Xtensa devices: + "esp32", + "esp32s2", + "esp32s3", + ] + steps: - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@v1 + + # Install the Rust toolchain for RISC-V devices: + - if: ${{ !contains(fromJson('["esp32", "esp32s2", "esp32s3"]'), matrix.soc) }} + uses: dtolnay/rust-toolchain@v1 with: - target: riscv32imc-unknown-none-elf,riscv32imac-unknown-none-elf + target: riscv32imc-unknown-none-elf,riscv32imac-unknown-none-elf,riscv32imafc-unknown-none-elf toolchain: nightly components: rust-src - - uses: esp-rs/xtensa-toolchain@v1.5 + # Install the Rust toolchain for Xtensa devices: + - if: contains(fromJson('["esp32", "esp32s2", "esp32s3"]'), matrix.soc) + uses: esp-rs/xtensa-toolchain@v1.5 with: + buildtargets: ${{ matrix.soc }} + default: true ldproxy: false - override: false + - uses: Swatinem/rust-cache@v2 - # Build all RISC-V targets: - - name: build (esp32c3) - run: cd esp-hal-smartled/ && cargo +nightly build -Zbuild-std=core --target=riscv32imc-unknown-none-elf --features=esp32c3 - - name: build (esp32c6) - run: cd esp-hal-smartled/ && cargo +nightly build -Zbuild-std=core --target=riscv32imac-unknown-none-elf --features=esp32c6 - - name: build (esp32h2) - run: cd esp-hal-smartled/ && cargo +nightly build -Zbuild-std=core --target=riscv32imac-unknown-none-elf --features=esp32h2 - # Build all Xtensa targets: - - name: build (esp32) - run: cd esp-hal-smartled/ && cargo +esp build -Zbuild-std=core --target=xtensa-esp32-none-elf --features=esp32 - - name: build (esp32s2) - run: cd esp-hal-smartled/ && cargo +esp build -Zbuild-std=core --target=xtensa-esp32s2-none-elf --features=esp32s2 - - name: build (esp32s3) - run: cd esp-hal-smartled/ && cargo +esp build -Zbuild-std=core --target=xtensa-esp32s3-none-elf --features=esp32s3 - # Ensure documentation can be built (requires a chip feature!) - - name: rustdoc - run: cd esp-hal-smartled/ && cargo doc -Zbuild-std=core --target=riscv32imc-unknown-none-elf --features=esp32c3 + # Build all supported examples for the low-power core first (if present): + - if: contains(fromJson('["esp32c6", "esp32s2", "esp32s3"]'), matrix.soc) + name: Build prerequisites (esp-lp-hal) + run: cargo xtask build-examples esp-lp-hal ${{ matrix.soc }} + + # Build all supported examples for the specified device: + - name: Build examples + run: cargo xtask build-examples esp-hal ${{ matrix.soc }} + # Ensure we can build the documentation for the specified device: + - name: Build documentation + run: cargo xtask build-documentation esp-hal ${{ matrix.soc }} esp-lp-hal: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + soc: ["esp32c6", "esp32s2", "esp32s3"] + steps: - uses: actions/checkout@v4 + + # Install the Rust toolchain for RISC-V devices: - uses: dtolnay/rust-toolchain@v1 with: target: riscv32imc-unknown-none-elf,riscv32imac-unknown-none-elf toolchain: nightly components: rust-src + - uses: Swatinem/rust-cache@v2 - # Perform a full build initially to verify that the examples not only - # build, but also link successfully. - - name: build esp-lp-hal (esp32c6) - run: cd esp-lp-hal/ && cargo build --release --target=riscv32imac-unknown-none-elf --features=esp32c6 --examples - - name: build esp-lp-hal (esp32s2) - run: cd esp-lp-hal/ && cargo build --release --target=riscv32imc-unknown-none-elf --features=esp32s2 --examples - - name: build esp-lp-hal (esp32s3) - run: cd esp-lp-hal/ && cargo build --release --target=riscv32imc-unknown-none-elf --features=esp32s3 --examples - # Ensure documentation can be built - - name: rustdoc - run: | - cd esp-lp-hal/ - cargo doc --features=esp32c6 - cargo doc --features=esp32s2 - cargo doc --features=esp32s3 + # Build all supported examples for the specified device: + - name: Build examples + run: cargo xtask build-examples esp-lp-hal ${{ matrix.soc }} + # Ensure we can build the documentation for the specified device: + - name: Build documentation + run: cargo xtask build-documentation esp-lp-hal ${{ matrix.soc }} esp-riscv-rt: runs-on: ubuntu-latest @@ -100,519 +129,29 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@v1 with: - target: riscv32imc-unknown-none-elf,riscv32imac-unknown-none-elf + target: riscv32imc-unknown-none-elf,riscv32imac-unknown-none-elf,riscv32imafc-unknown-none-elf toolchain: nightly components: rust-src - uses: Swatinem/rust-cache@v2 + # Build for all RISC-V targets (no features): - name: Build esp-riscv-rt (riscv32imc, no features) run: cd esp-riscv-rt/ && cargo build -Zbuild-std=core --target=riscv32imc-unknown-none-elf - name: Build esp-riscv-rt (riscv32imac, no features) run: cd esp-riscv-rt/ && cargo build -Zbuild-std=core --target=riscv32imac-unknown-none-elf + - name: Build esp-riscv-rt (riscv32imafc, no features) + run: cd esp-riscv-rt/ && cargo build -Zbuild-std=core --target=riscv32imafc-unknown-none-elf + # Build for all RISC-V targets (all features): - name: Build esp-riscv-rt (riscv32imc, all features) run: cd esp-riscv-rt/ && cargo build -Zbuild-std=core --target=riscv32imc-unknown-none-elf --features=ci - name: Build esp-riscv-rt (riscv32imac, all features) run: cd esp-riscv-rt/ && cargo build -Zbuild-std=core --target=riscv32imac-unknown-none-elf --features=ci + - name: Build esp-riscv-rt (riscv32imafc, all features) + run: cd esp-riscv-rt/ && cargo build -Zbuild-std=core --target=riscv32imafc-unknown-none-elf --features=ci # Ensure documentation can be built - name: rustdoc run: cd esp-riscv-rt/ && cargo doc - esp32-hal: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - uses: esp-rs/xtensa-toolchain@v1.5 - with: - default: true - buildtargets: esp32 - ldproxy: false - - uses: Swatinem/rust-cache@v2 - - # Perform a full build initially to verify that the examples not only - # build, but also link successfully. - - name: build esp32-hal (no features) - run: cd esp32-hal/ && cargo build --examples - # Subsequent steps can just check the examples instead, as we're already - # confident that they link. - - name: check esp32-hal (common features) - run: | - cd esp32-hal/ - cargo build --examples --features=eh1,ufmt,log - cargo build --examples --features=eh1,ufmt,defmt - - name: check esp32-hal (embassy) - run: | - cd esp32-hal/ - cargo check --example=embassy_hello_world --features=embassy,embassy-time-timg0,embassy-executor-thread - cargo check --example=embassy_multicore --features=embassy,embassy-time-timg0,embassy-executor-thread - cargo check --example=embassy_multicore_interrupt --features=embassy,embassy-time-timg0,embassy-executor-interrupt - cargo check --example=embassy_multiprio --features=embassy,embassy-time-timg0,embassy-executor-thread,embassy-executor-interrupt - - name: check esp32-hal (embassy, async) - run: | - cd esp32-hal/ - cargo check --example=embassy_wait --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo check --example=embassy_spi --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo check --example=embassy_serial --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo check --example=embassy_i2c --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo check --example=embassy_i2s_read --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo check --example=embassy_i2s_sound --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo check --example=embassy_rmt_rx --features=embassy,embassy-time-timg0,async,embassy-executor-thread --release - cargo check --example=embassy_rmt_tx --features=embassy,embassy-time-timg0,async,embassy-executor-thread - - name: check esp32-hal (embassy, log/defmt) - run: | - cd esp32-hal/ - cargo check --examples --features=embassy,embassy-time-timg0,embassy-executor-interrupt,embassy-executor-thread,defmt - cargo check --examples --features=embassy,embassy-time-timg0,embassy-executor-interrupt,embassy-executor-thread,log - - name: check esp32-hal (psram) - run: cd esp32-hal/ && cargo check --example=psram --features=psram-2m --release # This example requires release! - # Make sure we can build without default features enabled, too! - - name: check esp32-hal (no default features) - run: cd esp32-hal/ && cargo build --no-default-features - # Ensure documentation can be built - - name: rustdoc - run: cd esp32-hal/ && cargo doc --features=eh1 - - esp32c2-hal: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@v1 - with: - target: riscv32imc-unknown-none-elf - toolchain: nightly - components: rust-src - - uses: Swatinem/rust-cache@v2 - - # Perform a full build initially to verify that the examples not only - # build, but also link successfully. - # We also use this as an opportunity to verify that the examples link - # for each supported image format. - - name: build esp32c2-hal (no features) - run: cd esp32c2-hal/ && cargo build --examples - # Subsequent steps can just check the examples instead, as we're already - # confident that they link. - - name: check esp32c2-hal (common features) - run: | - cd esp32c2-hal/ - cargo +nightly build --examples --features=eh1,ufmt,log - cargo +nightly build --examples --features=eh1,ufmt,defmt - - name: check esp32c2-hal (async, systick) - run: cd esp32c2-hal/ && cargo +nightly check --example=embassy_hello_world --features=embassy,embassy-time-systick,embassy-executor-thread - - name: check esp32c2-hal (async, timg0) - run: cd esp32c2-hal/ && cargo +nightly check --example=embassy_hello_world --features=embassy,embassy-time-timg0,embassy-executor-thread - - name: check esp32c2-hal (async, gpio) - run: cd esp32c2-hal/ && cargo +nightly check --example=embassy_wait --features=embassy,embassy-time-systick,embassy-executor-thread,async - - name: check esp32c2-hal (async, multiprio) - run: cd esp32c2-hal/ && cargo +nightly check --example=embassy_multiprio --features=embassy,embassy-time-systick,embassy-executor-thread,embassy-executor-interrupt - - name: check esp32c2-hal (async, spi) - run: cd esp32c2-hal/ && cargo +nightly check --example=embassy_spi --features=embassy,embassy-time-systick,embassy-executor-thread,async - - name: check esp32c2-hal (async, serial) - run: cd esp32c2-hal/ && cargo +nightly check --example=embassy_serial --features=embassy,embassy-time-systick,embassy-executor-thread,async - - name: check esp32c2-hal (async, i2c) - run: cd esp32c2-hal/ && cargo +nightly check --example=embassy_i2c --features=embassy,embassy-time-systick,embassy-executor-thread,async - - name: check esp32c2-hal (interrupt-preemption) - run: cd esp32c2-hal/ && cargo +nightly check --example=interrupt_preemption --features=interrupt-preemption - - name: check esp32c2-hal (direct-vectoring) - run: cd esp32c2-hal/ && cargo +nightly check --example=direct-vectoring --features=direct-vectoring - - name: check esp32c2-hal (embassy, log/defmt) - run: | - cd esp32c2-hal/ - cargo +nightly check --examples --features=embassy,embassy-time-timg0,embassy-executor-thread,defmt - cargo +nightly check --examples --features=embassy,embassy-time-timg0,embassy-executor-thread,log - # Make sure we can build without default features enabled, too! - - name: check esp32c2-hal (no default features) - run: cd esp32c2-hal/ && cargo build --no-default-features - # Ensure documentation can be built - - name: rustdoc - run: cd esp32c2-hal/ && cargo doc --features=eh1 - - esp32c3-hal: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@v1 - with: - target: riscv32imc-unknown-none-elf - toolchain: nightly - components: rust-src - - uses: Swatinem/rust-cache@v2 - - # Perform a full build initially to verify that the examples not only - # build, but also link successfully. - - name: build esp32c3-hal (no features) - run: cd esp32c3-hal/ && cargo +nightly build --examples - # Subsequent steps can just check the examples instead, as we're already - # confident that they link. - - name: check esp32c3-hal (common features) - run: | - cd esp32c3-hal/ - cargo +nightly build --examples --features=eh1,ufmt,log - cargo +nightly build --examples --features=eh1,ufmt,defmt - - name: check esp32c3-hal (embassy) - run: | - cd esp32c3-hal/ - cargo +nightly check --example=embassy_hello_world --features=embassy,embassy-time-timg0,embassy-executor-thread - cargo +nightly check --example=embassy_hello_world --features=embassy,embassy-time-systick,embassy-executor-thread - cargo +nightly check --example=embassy_multiprio --features=embassy,embassy-time-timg0,embassy-executor-thread,embassy-executor-interrupt - - name: check esp32c3-hal (embassy, async) - run: | - cd esp32c3-hal/ - cargo +nightly check --example=embassy_wait --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +nightly check --example=embassy_spi --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +nightly check --example=embassy_serial --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +nightly check --example=embassy_i2c --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +nightly check --example=embassy_i2s_read --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +nightly check --example=embassy_i2s_sound --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +nightly check --example=embassy_rmt_rx --features=embassy,embassy-time-timg0,async,embassy-executor-thread --release - cargo +nightly check --example=embassy_rmt_tx --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +nightly check --example=embassy_usb_serial_jtag --features=embassy,embassy-time-systick,async,embassy-executor-thread - - name: check esp32c3-hal (interrupt-preemption) - run: cd esp32c3-hal/ && cargo +nightly check --example=interrupt_preemption --features=interrupt-preemption - - name: check esp32c3-hal (direct-vectoring) - run: cd esp32c3-hal/ && cargo +nightly check --example=direct-vectoring --features=direct-vectoring - - name: check esp32c3-hal (embassy, log/defmt) - run: | - cd esp32c3-hal/ - cargo +nightly check --examples --features=embassy,embassy-time-timg0,embassy-executor-thread,defmt - cargo +nightly check --examples --features=embassy,embassy-time-timg0,embassy-executor-thread,log - # Make sure we can build without default features enabled, too! - - name: check esp32c3-hal (no default features) - run: cd esp32c3-hal/ && cargo build --no-default-features - # Ensure documentation can be built - - name: rustdoc - run: cd esp32c3-hal/ && cargo doc --features=eh1 - - esp32c6-hal: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@v1 - with: - target: riscv32imac-unknown-none-elf - toolchain: nightly - components: rust-src - - uses: Swatinem/rust-cache@v2 - - # Build the `esp-lp-hal` examples first to make sure the examples which - # expect these ELF files to be present will compile. - - name: build prerequisites - run: | - cd esp-lp-hal/ - cargo build --release --features=esp32c6 --target=riscv32imac-unknown-none-elf --examples - - # Perform a full build initially to verify that the examples not only - # build, but also link successfully. - # We also use this as an opportunity to verify that the examples link - # for each supported image format. - - name: build esp32c6-hal (no features) - run: cd esp32c6-hal/ && cargo +nightly build --examples - - name: build esp32c6-hal (flip-link feature) - run: cd esp32c6-hal/ && cargo +nightly build --examples --features=flip-link - # Subsequent steps can just check the examples instead, as we're already - # confident that they link. - - name: check esp32c6-hal (common features) - run: | - cd esp32c6-hal/ - cargo +nightly build --examples --features=eh1,ufmt,log - cargo +nightly build --examples --features=eh1,ufmt,defmt - - name: check esp32c6-hal (embassy) - run: | - cd esp32c6-hal/ - cargo +nightly check --example=embassy_hello_world --features=embassy,embassy-time-timg0,embassy-executor-thread - cargo +nightly check --example=embassy_hello_world --features=embassy,embassy-time-systick,embassy-executor-thread - cargo +nightly check --example=embassy_multiprio --features=embassy,embassy-time-timg0,embassy-executor-thread,embassy-executor-interrupt - - name: check esp32c6-hal (embassy, async) - run: | - cd esp32c6-hal/ - cargo +nightly check --example=embassy_wait --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +nightly check --example=embassy_spi --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +nightly check --example=embassy_serial --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +nightly check --example=embassy_i2c --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +nightly check --example=embassy_i2s_read --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +nightly check --example=embassy_i2s_sound --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +nightly check --example=embassy_rmt_rx --features=embassy,embassy-time-timg0,async,embassy-executor-thread --release - cargo +nightly check --example=embassy_rmt_tx --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +nightly check --example=embassy_usb_serial_jtag --features=embassy,embassy-time-systick,async,embassy-executor-thread - cargo +nightly check --example=embassy_parl_io_tx --features=embassy,embassy-time-systick,async,embassy-executor-thread - cargo +nightly check --example=embassy_parl_io_rx --features=embassy,embassy-time-systick,async,embassy-executor-thread - - name: check esp32c6-hal (interrupt-preemption) - run: cd esp32c6-hal/ && cargo +nightly check --example=interrupt_preemption --features=interrupt-preemption - - name: check esp32c6-hal (direct-vectoring) - run: cd esp32c6-hal/ && cargo +nightly check --example=direct-vectoring --features=direct-vectoring - - name: check esp32c6-hal (embassy, log/defmt) - run: | - cd esp32c6-hal/ - cargo +nightly check --examples --features=embassy,embassy-time-timg0,embassy-executor-thread,defmt - cargo +nightly check --examples --features=embassy,embassy-time-timg0,embassy-executor-thread,log - # Make sure we can build without default features enabled, too! - - name: check esp32c6-hal (no default features) - run: cd esp32c6-hal/ && cargo build --no-default-features - # Ensure documentation can be built - - name: rustdoc - run: cd esp32c6-hal/ && cargo doc --features=eh1 - - esp32h2-hal: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@v1 - with: - target: riscv32imac-unknown-none-elf - toolchain: nightly - components: rust-src - - uses: Swatinem/rust-cache@v2 - - # Perform a full build initially to verify that the examples not only - # build, but also link successfully. - # We also use this as an opportunity to verify that the examples link - # for each supported image format. - - name: build esp32h2-hal (no features) - run: cd esp32h2-hal/ && cargo +nightly build --examples - - name: build esp32h2-hal (flip-link feature) - run: cd esp32h2-hal/ && cargo +nightly build --examples --features=flip-link - # Subsequent steps can just check the examples instead, as we're already - # confident that they link. - - name: check esp32h2-hal (common features) - run: | - cd esp32h2-hal/ - cargo +nightly build --examples --features=eh1,ufmt,log - cargo +nightly build --examples --features=eh1,ufmt,defmt - - name: check esp32h2-hal (embassy) - run: | - cd esp32h2-hal/ - cargo +nightly check --example=embassy_hello_world --features=embassy,embassy-time-timg0,embassy-executor-thread - cargo +nightly check --example=embassy_hello_world --features=embassy,embassy-time-systick,embassy-executor-thread - cargo +nightly check --example=embassy_multiprio --features=embassy,embassy-time-timg0,embassy-executor-thread,embassy-executor-interrupt - - name: check esp32h2-hal (embassy, async) - run: | - cd esp32h2-hal/ - cargo +nightly check --example=embassy_wait --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +nightly check --example=embassy_spi --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +nightly check --example=embassy_serial --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +nightly check --example=embassy_i2c --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +nightly check --example=embassy_i2s_read --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +nightly check --example=embassy_i2s_sound --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +nightly check --example=embassy_rmt_rx --features=embassy,embassy-time-timg0,async,embassy-executor-thread --release - cargo +nightly check --example=embassy_rmt_tx --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +nightly check --example=embassy_usb_serial_jtag --features=embassy,embassy-time-systick,async,embassy-executor-thread - cargo +nightly check --example=embassy_parl_io_tx --features=embassy,embassy-time-systick,async,embassy-executor-thread - cargo +nightly check --example=embassy_parl_io_rx --features=embassy,embassy-time-systick,async,embassy-executor-thread - - name: check esp32h2-hal (interrupt-preemption) - run: cd esp32h2-hal/ && cargo +nightly check --example=interrupt_preemption --features=interrupt-preemption - - name: check esp32h2-hal (direct-vectoring) - run: cd esp32h2-hal/ && cargo +nightly check --example=direct-vectoring --features=direct-vectoring - - name: check esp32h2-hal (embassy, log/defmt) - run: | - cd esp32h2-hal/ - cargo +nightly check --examples --features=embassy,embassy-time-timg0,embassy-executor-thread,defmt - cargo +nightly check --examples --features=embassy,embassy-time-timg0,embassy-executor-thread,log - # Make sure we can build without default features enabled, too! - - name: check esp32h2-hal (no default features) - run: cd esp32h2-hal/ && cargo build --no-default-features - # Ensure documentation can be built - - name: rustdoc - run: cd esp32h2-hal/ && cargo doc --features=eh1 - - esp32p4-hal: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@v1 - with: - target: riscv32imafc-unknown-none-elf - toolchain: nightly - components: rust-src - - uses: Swatinem/rust-cache@v2 - - # Perform a full build initially to verify that the examples not only - # build, but also link successfully. - # We also use this as an opportunity to verify that the examples link - # for each supported image format. - - name: build esp32p4-hal (no features) - run: cd esp32p4-hal/ && cargo +nightly build --examples - # Subsequent steps can just check the examples instead, as we're already - # confident that they link. - - name: check esp32p4-hal (common features) - run: | - cd esp32p4-hal/ - cargo +nightly build --examples --features=eh1,ufmt,log - cargo +nightly build --examples --features=eh1,ufmt,defmt - # Make sure we can build without default features enabled, too! - - name: check esp32p4-hal (no default features) - run: cd esp32p4-hal/ && cargo build --no-default-features - # Ensure documentation can be built - - name: rustdoc - run: cd esp32p4-hal/ && cargo doc --features=eh1 - - esp32s2-hal: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - uses: esp-rs/xtensa-toolchain@v1.5 - with: - default: true - buildtargets: esp32s2 - ldproxy: false - - uses: dtolnay/rust-toolchain@v1 - with: - target: riscv32imc-unknown-none-elf - toolchain: nightly - components: rust-src - - uses: Swatinem/rust-cache@v2 - - # Build the `esp-lp-hal` examples first to make sure the examples which - # expect these ELF files to be present will compile. - - name: build prerequisites - run: | - cd esp-lp-hal/ - cargo +nightly build --release --features=esp32s2 --target=riscv32imc-unknown-none-elf --examples - - # Perform a full build initially to verify that the examples not only - # build, but also link successfully. - - name: check esp32s2-hal (no features) - run: cd esp32s2-hal/ && cargo +esp build --examples - # Subsequent steps can just check the examples instead, as we're already - # confident that they link. - - name: check esp32s2-hal (common features) - run: | - cd esp32s2-hal/ - cargo +esp build --examples --features=eh1,ufmt,log - cargo +esp build --examples --features=eh1,ufmt,defmt - - name: check esp32s2-hal (embassy, timg0) - run: | - cd esp32s2-hal/ - cargo +esp check --example=embassy_hello_world --features=embassy,embassy-time-timg0,embassy-executor-thread - cargo +esp check --example=embassy_multiprio --features=embassy,embassy-time-timg0,embassy-executor-thread,embassy-executor-interrupt - - name: check esp32s2-hal (embassy, systick) - run: | - cd esp32s2-hal/ - cargo +esp check --example=embassy_hello_world --features=embassy,embassy-time-systick,embassy-executor-thread - cargo +esp check --example=embassy_multiprio --features=embassy,embassy-time-systick,embassy-executor-thread,embassy-executor-interrupt - - name: check esp32s2-hal (embassy, timg0, async) - run: | - cd esp32s2-hal/ - cargo +esp check --example=embassy_wait --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +esp check --example=embassy_spi --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +esp check --example=embassy_serial --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +esp check --example=embassy_i2c --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +esp check --example=embassy_i2s_read --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +esp check --example=embassy_i2s_sound --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +esp check --example=embassy_rmt_rx --features=embassy,embassy-time-timg0,async,embassy-executor-thread --release - cargo +esp check --example=embassy_rmt_tx --features=embassy,embassy-time-timg0,async,embassy-executor-thread - - name: check esp32s2-hal (embassy, systick, async) - run: | - cd esp32s2-hal/ - cargo +esp check --example=embassy_wait --features=embassy,embassy-time-systick,async,embassy-executor-thread - cargo +esp check --example=embassy_spi --features=embassy,embassy-time-systick,async,embassy-executor-thread - cargo +esp check --example=embassy_serial --features=embassy,embassy-time-systick,async,embassy-executor-thread - cargo +esp check --example=embassy_i2c --features=embassy,embassy-time-systick,async,embassy-executor-thread - - name: check esp32s2-hal (embassy, log/defmt) - run: | - cd esp32s2-hal/ - cargo +esp check --examples --features=embassy,embassy-time-timg0,embassy-executor-interrupt,embassy-executor-thread,defmt - cargo +esp check --examples --features=embassy,embassy-time-timg0,embassy-executor-interrupt,embassy-executor-thread,log - - name: check esp32s2-hal (psram) - run: cd esp32s2-hal/ && cargo +esp check --example=psram --features=psram-2m --release # This example requires release! - # Make sure we can build without default features enabled, too! - - name: check esp32s2-hal (no default features) - run: cd esp32s2-hal/ && cargo build --no-default-features - # Ensure documentation can be built - - name: rustdoc - run: cd esp32s2-hal/ && cargo +esp doc --features=eh1 - - esp32s3-hal: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - uses: esp-rs/xtensa-toolchain@v1.5 - with: - default: true - buildtargets: esp32s3 - ldproxy: false - - uses: dtolnay/rust-toolchain@v1 - with: - target: riscv32imc-unknown-none-elf - toolchain: nightly - components: rust-src - - uses: Swatinem/rust-cache@v2 - - # Build the `esp-lp-hal` examples first to make sure the examples which - # expect these ELF files to be present will compile. - - name: build prerequisites - run: | - cd esp-lp-hal/ - cargo build --release --features=esp32s3 --target=riscv32imc-unknown-none-elf --examples - - # Perform a full build initially to verify that the examples not only - # build, but also link successfully. - # We also use this as an opportunity to verify that the examples link - # for each supported image format. - - name: build esp32s3-hal (no features) - run: cd esp32s3-hal/ && cargo +esp build --examples - # Subsequent steps can just check the examples instead, as we're already - # confident that they link. - - name: check esp32s3-hal (common features) - run: | - cd esp32s3-hal/ - cargo +esp build --examples --features=eh1,ufmt,log - cargo +esp build --examples --features=eh1,ufmt,defmt - - name: check esp32s3-hal (embassy, timg0) - run: | - cd esp32s3-hal/ - cargo +esp check --example=embassy_hello_world --features=embassy,embassy-time-timg0,embassy-executor-thread - cargo +esp check --example=embassy_multicore --features=embassy,embassy-time-timg0,embassy-executor-thread - cargo +esp check --example=embassy_multicore_interrupt --features=embassy,embassy-time-timg0,embassy-executor-interrupt - cargo +esp check --example=embassy_multiprio --features=embassy,embassy-time-timg0,embassy-executor-thread,embassy-executor-interrupt - - name: check esp32s3-hal (embassy, systick) - run: | - cd esp32s3-hal/ - cargo +esp check --example=embassy_hello_world --features=embassy,embassy-time-systick,embassy-executor-thread - cargo +esp check --example=embassy_multicore --features=embassy,embassy-time-systick,embassy-executor-thread - cargo +esp check --example=embassy_multicore_interrupt --features=embassy,embassy-time-systick,embassy-executor-interrupt - cargo +esp check --example=embassy_multiprio --features=embassy,embassy-time-systick,embassy-executor-thread,embassy-executor-interrupt - - name: check esp32s3-hal (embassy, timg0, async) - run: | - cd esp32s3-hal/ - cargo +esp check --example=embassy_wait --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +esp check --example=embassy_spi --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +esp check --example=embassy_serial --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +esp check --example=embassy_i2c --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +esp check --example=embassy_i2s_read --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +esp check --example=embassy_i2s_sound --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +esp check --example=embassy_rmt_rx --features=embassy,embassy-time-timg0,async,embassy-executor-thread - cargo +esp check --example=embassy_rmt_tx --features=embassy,embassy-time-timg0,async,embassy-executor-thread - - name: check esp32s3-hal (embassy, systick, async) - run: | - cd esp32s3-hal/ - cargo +esp check --example=embassy_wait --features=embassy,embassy-time-systick,async,embassy-executor-thread - cargo +esp check --example=embassy_spi --features=embassy,embassy-time-systick,async,embassy-executor-thread - cargo +esp check --example=embassy_serial --features=embassy,embassy-time-systick,async,embassy-executor-thread - cargo +esp check --example=embassy_i2c --features=embassy,embassy-time-systick,async,embassy-executor-thread - cargo +esp check --example=embassy_usb_serial_jtag --features=embassy,embassy-time-systick,async,embassy-executor-thread - - name: check esp32s3-hal (octal psram and psram) - run: | # This examples require release! - cd esp32s3-hal/ - cargo +esp check --example=octal_psram --features=opsram-2m --release - cargo +esp check --example=psram --features=psram-2m --release - - name: check esp32s3-hal (embassy, log/defmt) - run: | - cd esp32s3-hal/ - cargo +esp check --examples --features=embassy,embassy-time-timg0,embassy-executor-interrupt,embassy-executor-thread,defmt - cargo +esp check --examples --features=embassy,embassy-time-timg0,embassy-executor-interrupt,embassy-executor-thread,log - # Make sure we can build without default features enabled, too! - - name: check esp32s3-hal (no default features) - run: cd esp32s3-hal/ && cargo build --no-default-features - # Ensure documentation can be built - - name: rustdoc - run: cd esp32s3-hal/ && cargo doc --features=eh1 - # -------------------------------------------------------------------------- # MSRV @@ -625,56 +164,38 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@v1 with: - target: riscv32imc-unknown-none-elf,riscv32imac-unknown-none-elf #,riscv32imafc-unknown-none-elf + target: riscv32imc-unknown-none-elf,riscv32imac-unknown-none-elf toolchain: ${{ env.MSRV }} components: rust-src - uses: Swatinem/rust-cache@v2 + # TODO: + # - Enable additional (all?) features for MSRV check + # Verify the MSRV for all RISC-V chips. + - name: msrv (esp-hal) + run: | + cargo xtask build-package --features=esp32c2 --target=riscv32imc-unknown-none-elf esp-hal + cargo xtask build-package --features=esp32c3 --target=riscv32imc-unknown-none-elf esp-hal + cargo xtask build-package --features=esp32c6 --target=riscv32imac-unknown-none-elf esp-hal + cargo xtask build-package --features=esp32h2 --target=riscv32imac-unknown-none-elf esp-hal + cargo xtask build-package --features=esp32p4 --target=riscv32imafc-unknown-none-elf esp-hal - name: msrv (esp-lp-hal) run: | - cd esp-lp-hal/ - cargo build --features=esp32c6 --target=riscv32imac-unknown-none-elf - cargo build --features=esp32s2 --target=riscv32imc-unknown-none-elf - cargo build --features=esp32s3 --target=riscv32imc-unknown-none-elf - - name: msrv (esp32c2-hal) - run: | - cd esp32c2-hal/ - cargo build --features=eh1,ufmt,log - cargo build --features=defmt - - name: msrv (esp32c3-hal) - run: | - cd esp32c3-hal/ - cargo build --features=eh1,ufmt,log - cargo build --features=defmt - - name: msrv (esp32c6-hal) - run: | - cd esp32c6-hal/ - cargo build --features=eh1,ufmt,log - cargo build --features=defmt - - name: msrv (esp32h2-hal) - run: | - cd esp32h2-hal/ - cargo build --features=eh1,ufmt,log - cargo build --features=defmt - # - name: msrv (esp32p4-hal) - # run: | - # cd esp32p4-hal/ - # cargo build --features=eh1,ufmt,log - # cargo build --features=defmt + cargo xtask build-package --features=esp32c6 --target=riscv32imac-unknown-none-elf esp-lp-hal + cargo xtask build-package --features=esp32s2 --target=riscv32imc-unknown-none-elf esp-lp-hal + cargo xtask build-package --features=esp32s3 --target=riscv32imc-unknown-none-elf esp-lp-hal msrv-xtensa: runs-on: ubuntu-latest env: RUSTC_BOOTSTRAP: 1 + # TODO: + # - Enable additional (all?) features for MSRV check + steps: - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@v1 - with: - target: riscv32imc-unknown-none-elf - toolchain: ${{ env.MSRV }} - components: rust-src - uses: esp-rs/xtensa-toolchain@v1.5 with: ldproxy: false @@ -682,21 +203,11 @@ jobs: - uses: Swatinem/rust-cache@v2 # Verify the MSRV for all Xtensa chips: - - name: msrv (esp32-hal) + - name: msrv (esp-hal) run: | - cd esp32-hal/ - cargo build --features=eh1,ufmt,log - cargo build --features=defmt - - name: msrv (esp32s2-hal) - run: | - cd esp32s2-hal/ - cargo build --features=eh1,ufmt,log - cargo build --features=defmt - - name: msrv (esp32s3-hal) - run: | - cd esp32s3-hal/ - cargo build --features=eh1,ufmt,log - cargo build --features=defmt + cargo xtask build-package --toolchain=esp --features=esp32 --target=xtensa-esp32-none-elf esp-hal + cargo xtask build-package --toolchain=esp --features=esp32s2 --target=xtensa-esp32s2-none-elf esp-hal + cargo xtask build-package --toolchain=esp --features=esp32s3 --target=xtensa-esp32s3-none-elf esp-hal # -------------------------------------------------------------------------- # Lint @@ -709,28 +220,34 @@ jobs: - uses: dtolnay/rust-toolchain@v1 with: toolchain: nightly - targets: riscv32imc-unknown-none-elf,riscv32imac-unknown-none-elf # ,riscv32imafc-unknown-none-elf + targets: riscv32imc-unknown-none-elf,riscv32imac-unknown-none-elf,riscv32imafc-unknown-none-elf components: clippy,rust-src - uses: Swatinem/rust-cache@v2 # Run 'cargo clippy' on all packages targeting RISC-V: - - name: clippy (esp32c2-hal) - run: cargo clippy --manifest-path=esp-hal/Cargo.toml --target=riscv32imc-unknown-none-elf --features=esp32c2 -- -D warnings - - name: clippy (esp32c3-hal) - run: cargo clippy --manifest-path=esp-hal/Cargo.toml --target=riscv32imc-unknown-none-elf --features=esp32c3 -- -D warnings - - name: clippy (esp32c6-hal) - run: cargo clippy --manifest-path=esp-hal/Cargo.toml --target=riscv32imac-unknown-none-elf --features=esp32c6 -- -D warnings - - name: clippy (esp32h2-hal) - run: cargo clippy --manifest-path=esp-hal/Cargo.toml --target=riscv32imac-unknown-none-elf --features=esp32h2 -- -D warnings - # - name: clippy (esp32p4-hal) - # run: cargo clippy --manifest-path=esp-hal/Cargo.toml --target=riscv32imafc-unknown-none-elf --features=esp32p4 -- -D warnings - + ## esp-hal: + - name: clippy (esp-hal, esp32c2) + run: cd esp-hal && cargo clippy --features=esp32c2 --target=riscv32imc-unknown-none-elf -- -D warnings + - name: clippy (esp-hal, esp32c3) + run: cd esp-hal && cargo clippy --features=esp32c3 --target=riscv32imc-unknown-none-elf -- -D warnings + - name: clippy (esp-hal, esp32c6) + run: cd esp-hal && cargo clippy --features=esp32c6 --target=riscv32imac-unknown-none-elf -- -D warnings + - name: clippy (esp-hal, esp32h2) + run: cd esp-hal && cargo clippy --features=esp32h2 --target=riscv32imac-unknown-none-elf -- -D warnings + # TODO: Re-enable when able + # - name: clippy (esp-hal, esp32p4) + # run: cd esp-hal && cargo clippy --features=esp32p4 --target=riscv32imafc-unknown-none-elf -- -D warnings + ## esp-hal-smartled: + - name: clippy (esp-hal-smartled) + run: cd esp-hal-smartled && cargo clippy --features=esp32c6 --target=riscv32imac-unknown-none-elf -- -D warnings + ## esp-lp-hal: - name: clippy (esp-lp-hal, esp32c6) - run: cd esp-lp-hal && cargo clippy --features=esp32c6 -- -D warnings + run: cd esp-lp-hal && cargo clippy --features=esp32c6 --target=riscv32imac-unknown-none-elf -- -D warnings - name: clippy (esp-lp-hal, esp32s2) - run: cd esp-lp-hal && cargo clippy --features=esp32s2 -- -D warnings + run: cd esp-lp-hal && cargo clippy --features=esp32s2 --target=riscv32imc-unknown-none-elf -- -D warnings - name: clippy (esp-lp-hal, esp32s3) - run: cd esp-lp-hal && cargo clippy --features=esp32s3 -- -D warnings + run: cd esp-lp-hal && cargo clippy --features=esp32s3 --target=riscv32imc-unknown-none-elf -- -D warnings + # esp-riscv-rt: - name: clippy (esp-riscv-rt) run: cd esp-riscv-rt && cargo clippy --target=riscv32imc-unknown-none-elf -- -D warnings @@ -746,12 +263,12 @@ jobs: - uses: Swatinem/rust-cache@v2 # Run 'cargo clippy' on all packages targeting Xtensa: - - name: clippy (esp32-hal) - run: cargo clippy -Zbuild-std=core --manifest-path=esp-hal/Cargo.toml --target=xtensa-esp32-none-elf --features=esp32 -- -D warnings - - name: clippy (esp32s2-hal) - run: cargo clippy -Zbuild-std=core --manifest-path=esp-hal/Cargo.toml --target=xtensa-esp32s2-none-elf --features=esp32s2 -- -D warnings - - name: clippy (esp32s3-hal) - run: cargo clippy -Zbuild-std=core --manifest-path=esp-hal/Cargo.toml --target=xtensa-esp32s3-none-elf --features=esp32s3 -- -D warnings + - name: clippy (esp-hal, esp32) + run: cd esp-hal && cargo clippy -Zbuild-std=core --features=esp32 --target=xtensa-esp32-none-elf -- -D warnings + - name: clippy (esp-hal, esp32s2) + run: cd esp-hal && cargo clippy -Zbuild-std=core --features=esp32s2 --target=xtensa-esp32s2-none-elf -- -D warnings + - name: clippy (esp-hal, esp32s3) + run: cd esp-hal && cargo clippy -Zbuild-std=core --features=esp32s3 --target=xtensa-esp32s3-none-elf -- -D warnings rustfmt: runs-on: ubuntu-latest @@ -777,19 +294,5 @@ jobs: run: cargo fmt --all --manifest-path=esp-lp-hal/Cargo.toml -- --check - name: rustfmt (esp-riscv-rt) run: cargo fmt --all --manifest-path=esp-riscv-rt/Cargo.toml -- --check - - name: rustfmt (esp32-hal) - run: cargo fmt --all --manifest-path=esp32-hal/Cargo.toml -- --check - - name: rustfmt (esp32c2-hal) - run: cargo fmt --all --manifest-path=esp32c2-hal/Cargo.toml -- --check - - name: rustfmt (esp32c3-hal) - run: cargo fmt --all --manifest-path=esp32c3-hal/Cargo.toml -- --check - - name: rustfmt (esp32c6-hal) - run: cargo fmt --all --manifest-path=esp32c6-hal/Cargo.toml -- --check - - name: rustfmt (esp32h2-hal) - run: cargo fmt --all --manifest-path=esp32h2-hal/Cargo.toml -- --check - - name: rustfmt (esp32p4-hal) - run: cargo fmt --all --manifest-path=esp32p4-hal/Cargo.toml -- --check - - name: rustfmt (esp32s2-hal) - run: cargo fmt --all --manifest-path=esp32s2-hal/Cargo.toml -- --check - - name: rustfmt (esp32s3-hal) - run: cargo fmt --all --manifest-path=esp32s3-hal/Cargo.toml -- --check + - name: rustfmt (examples) + run: cargo fmt --all --manifest-path=examples/Cargo.toml -- --check diff --git a/CHANGELOG.md b/CHANGELOG.md index cd7d0e9be..55b896c45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,7 +52,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Lift the minimal buffer size requirement for I2S (#1189) ### Removed + - Remove `xtal-26mhz` and `xtal-40mhz` features (#1165) +- All chip-specific HAL packages have been removed (#1196) ### Breaking @@ -60,6 +62,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The `DAC` driver's constructor is now `new` instead of `dac`, to be more consistent with other APIs (#1100) - The DMA peripheral is now called `Dma` for devices with both PDMA and GDMA controllers (#1125) - The `ADC` driver's constructor is now `new` instead of `adc`, to be more consistent with other APIs (#1133) +- `embassy-executor`'s `integrated-timers` is no longer enabled by default. ## [0.15.0] - 2024-01-19 @@ -147,7 +150,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - RISC-V: Fix stack allocation (#988) - ESP32-C6: Fix used RAM (#997) - ESP32-H2: Fix used RAM (#1003) -- Fix SPI slave DMA dma\_read and dma\_write (#1013) +- Fix SPI slave DMA dma_read and dma_write (#1013) - ESP32-C6/H2: Fix disabling of interrupts (#1040) ### Removed @@ -160,8 +163,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `Spi::new`/`Spi::new_half_duplex` takes no gpio pin now, instead you need to call `with_pins` to setup those (#901). - ESP32-C2, ESP32-C3, ESP32-S2: atomic emulation trap has been removed. (#904) (#985) - - When upgrading you must either remove [these lines](https://github.com/esp-rs/riscv-atomic-emulation-trap#usage) from your `.cargo/config.toml`. - - Usage of `core::sync::atomic::*` in dependent crates should be replaced with [portable-atomic](https://github.com/taiki-e/portable-atomic). + - When upgrading you must either remove [these lines](https://github.com/esp-rs/riscv-atomic-emulation-trap#usage) from your `.cargo/config.toml`. + - Usage of `core::sync::atomic::*` in dependent crates should be replaced with [portable-atomic](https://github.com/taiki-e/portable-atomic). - RSA driver now takes `u32` words instead of `u8` bytes. The expected slice length is now 4 times shorter. (#981) ## [0.13.1] - 2023-11-02 diff --git a/Cargo.toml b/Cargo.toml index 661815873..0c5c8670d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [workspace] -members = ["xtask"] -exclude = [ +resolver = "2" +members = ["xtask"] +exclude = [ "esp-hal", "esp-hal-procmacros", "esp-hal-smartled", @@ -14,4 +15,5 @@ exclude = [ "esp32p4-hal", "esp32s2-hal", "esp32s3-hal", + "examples", ] diff --git a/esp-hal-procmacros/Cargo.toml b/esp-hal-procmacros/Cargo.toml index 3f766e0c4..6803aab83 100644 --- a/esp-hal-procmacros/Cargo.toml +++ b/esp-hal-procmacros/Cargo.toml @@ -2,27 +2,27 @@ name = "esp-hal-procmacros" version = "0.8.0" edition = "2021" -rust-version = "1.67.0" -description = "Procedural macros for ESP-HAL" +rust-version = "1.76.0" +description = "Procedural macros for esp-hal" repository = "https://github.com/esp-rs/esp-hal" license = "MIT OR Apache-2.0" [package.metadata.docs.rs] -features = ["esp32c3", "embassy", "interrupt", "ram"] +features = ["embassy", "has-ulp-core", "interrupt", "ram", "is-ulp-core"] [lib] proc-macro = true [dependencies] -darling = "0.20.3" -document-features = "0.2.7" +darling = "0.20.5" +document-features = "0.2.8" litrs = "0.4.1" -object = { version = "0.32.1", optional = true } -proc-macro-crate = "2.0.1" +object = { version = "0.32.2", optional = true } +proc-macro-crate = "3.1.0" proc-macro-error = "1.0.4" -proc-macro2 = "1.0.70" -quote = "1.0.33" -syn = { version = "2.0.40", features = ["extra-traits", "full"] } +proc-macro2 = "1.0.78" +quote = "1.0.35" +syn = { version = "2.0.48", features = ["extra-traits", "full"] } [features] ## Provide a `#[main]` procmacro to mark the entry point for Embassy applications. @@ -36,26 +36,14 @@ ram = [] ## Indicates the target devices has RTC slow memory available. rtc_slow = [] -#! ### Chip Support Feature Flags -## Target the ESP32. -esp32 = [] -## Target the ESP32-C2. -esp32c2 = [] -## Target the ESP32-C3. -esp32c3 = [] -## Target the ESP32-C6. -esp32c6 = ["dep:object"] -## Target the ESP32-C6's low-power core. -esp32c6-lp = [] -## Target the ESP32-H2. -esp32h2 = [] -## Target the ESP32-P4. -esp32p4 = [] -## Target the ESP32-S2. -esp32s2 = ["dep:object"] -## Target the ESP32-S2's ultra-low-power core. -esp32s2-ulp = [] -## Target the ESP32-S3. -esp32s3 = ["dep:object"] -## Target the ESP32-S3's ultra-low-power core. -esp32s3-ulp = [] +#! ### Low-power Core Feature Flags +## Indicate that the SoC contains an LP core. +has-lp-core = ["dep:object"] +## Indicate that the SoC contains a ULP core. +has-ulp-core = ["dep:object"] +## Provide an `#[entry]` macro for running applications on the ESP32-C6/P4's +## LP core. +is-lp-core = [] +## Provide an `#[entry]` macro for running applications on the ESP32-S2/S3's +## ULP core. +is-ulp-core = [] diff --git a/esp-hal-procmacros/src/embassy.rs b/esp-hal-procmacros/src/embassy.rs index d7f0ebf78..c0411330e 100644 --- a/esp-hal-procmacros/src/embassy.rs +++ b/esp-hal-procmacros/src/embassy.rs @@ -23,7 +23,7 @@ pub(crate) mod main { use darling::{export::NestedMeta, FromMeta}; use proc_macro2::{Ident, Span, TokenStream}; - use proc_macro_crate::FoundCrate; + use proc_macro_crate::{crate_name, FoundCrate}; use quote::{quote, ToTokens}; use syn::{ReturnType, Type}; @@ -162,19 +162,17 @@ pub(crate) mod main { } pub fn main() -> TokenStream { - let (hal_crate, hal_crate_name) = crate::get_hal_crate(); + let hal_crate = if cfg!(any(feature = "is-lp-core", feature = "is-ulp-core")) { + crate_name("esp-lp-hal") + } else { + crate_name("esp-hal") + }; - let executor = match hal_crate { - Ok(FoundCrate::Itself) => { - quote!( #hal_crate_name::embassy::executor::Executor ) - } - Ok(FoundCrate::Name(ref name)) => { - let ident = Ident::new(&name, Span::call_site().into()); - quote!( #ident::embassy::executor::Executor ) - } - Err(_) => { - quote!(crate::embassy::executor::Executor) - } + let executor = if let Ok(FoundCrate::Name(ref name)) = hal_crate { + let ident = Ident::new(&name, Span::call_site().into()); + quote!( #ident::embassy::executor::Executor ) + } else { + quote!(crate::embassy::executor::Executor) }; quote! { diff --git a/esp-hal-procmacros/src/enum_dispatch.rs b/esp-hal-procmacros/src/enum_dispatch.rs index 94875f358..2372be884 100644 --- a/esp-hal-procmacros/src/enum_dispatch.rs +++ b/esp-hal-procmacros/src/enum_dispatch.rs @@ -1,4 +1,5 @@ -use proc_macro2::{Group, TokenTree}; +use proc_macro2::{Group, TokenStream, TokenTree}; +use quote::{format_ident, quote}; use syn::{ parse::{Parse, ParseStream, Result}, Ident, @@ -54,3 +55,26 @@ impl Parse for MakeGpioEnumDispatchMacro { }) } } + +pub(crate) fn build_match_arms(input: MakeGpioEnumDispatchMacro) -> Vec { + let mut arms = Vec::new(); + for (gpio_type, num) in input.elements { + let enum_name = format_ident!("ErasedPin"); + let variant_name = format_ident!("Gpio{}", num); + + if input.filter.contains(&gpio_type) { + arms.push({ + quote! { #enum_name::#variant_name($target) => $body } + }); + } else { + arms.push({ + quote! { + #[allow(unused)] + #enum_name::#variant_name($target) => { panic!("Unsupported") } + } + }); + } + } + + arms +} diff --git a/esp-hal-procmacros/src/lib.rs b/esp-hal-procmacros/src/lib.rs index f913c8e12..c62061c25 100644 --- a/esp-hal-procmacros/src/lib.rs +++ b/esp-hal-procmacros/src/lib.rs @@ -75,12 +75,8 @@ #![doc = document_features::document_features!()] #![doc(html_logo_url = "https://avatars.githubusercontent.com/u/46717278")] -#[cfg(feature = "ram")] -use darling::{ast::NestedMeta, Error as DarlingError, FromMeta}; +#[allow(unused)] use proc_macro::TokenStream; -use proc_macro_error::proc_macro_error; -use quote::quote; -use syn::parse_macro_input; #[cfg(feature = "embassy")] mod embassy; @@ -88,80 +84,11 @@ mod embassy; mod enum_dispatch; #[cfg(feature = "interrupt")] mod interrupt; -#[cfg(any( - feature = "esp32c6-lp", - feature = "esp32s2-ulp", - feature = "esp32s3-ulp" -))] +#[cfg(any(feature = "is-lp-core", feature = "is-ulp-core"))] mod lp_core; -#[cfg(any( - feature = "esp32c6", - feature = "esp32s2", - feature = "esp32s3", - feature = "interrupt" -))] -fn get_hal_crate() -> ( - Result, - proc_macro2::Ident, -) { - use proc_macro::Span; - use proc_macro2::Ident; - use proc_macro_crate::crate_name; - - // Package name: - #[cfg(any( - feature = "esp32c6-lp", - feature = "esp32s2-ulp", - feature = "esp32s3-ulp" - ))] - let hal_crate = crate_name("esp-lp-hal"); - #[cfg(feature = "esp32")] - let hal_crate = crate_name("esp32-hal"); - #[cfg(feature = "esp32c2")] - let hal_crate = crate_name("esp32c2-hal"); - #[cfg(feature = "esp32c3")] - let hal_crate = crate_name("esp32c3-hal"); - #[cfg(feature = "esp32c6")] - let hal_crate = crate_name("esp32c6-hal"); - #[cfg(feature = "esp32h2")] - let hal_crate = crate_name("esp32h2-hal"); - #[cfg(feature = "esp32p4")] - let hal_crate = crate_name("esp32p4-hal"); - #[cfg(feature = "esp32s2")] - let hal_crate = crate_name("esp32s2-hal"); - #[cfg(feature = "esp32s3")] - let hal_crate = crate_name("esp32s3-hal"); - - // Crate name: - #[cfg(any( - feature = "esp32c6-lp", - feature = "esp32s2-ulp", - feature = "esp32s3-ulp" - ))] - let hal_crate_name = Ident::new("esp_lp_hal", Span::call_site().into()); - #[cfg(feature = "esp32")] - let hal_crate_name = Ident::new("esp32_hal", Span::call_site().into()); - #[cfg(feature = "esp32c2")] - let hal_crate_name = Ident::new("esp32c2_hal", Span::call_site().into()); - #[cfg(feature = "esp32c3")] - let hal_crate_name = Ident::new("esp32c3_hal", Span::call_site().into()); - #[cfg(feature = "esp32c6")] - let hal_crate_name = Ident::new("esp32c6_hal", Span::call_site().into()); - #[cfg(feature = "esp32h2")] - let hal_crate_name = Ident::new("esp32h2_hal", Span::call_site().into()); - #[cfg(feature = "esp32p4")] - let hal_crate_name = Ident::new("esp32p4_hal", Span::call_site().into()); - #[cfg(feature = "esp32s2")] - let hal_crate_name = Ident::new("esp32s2_hal", Span::call_site().into()); - #[cfg(feature = "esp32s3")] - let hal_crate_name = Ident::new("esp32s3_hal", Span::call_site().into()); - - (hal_crate, hal_crate_name) -} - #[cfg(feature = "ram")] -#[derive(Debug, Default, FromMeta)] +#[derive(Debug, Default, darling::FromMeta)] #[darling(default)] struct RamArgs { rtc_fast: bool, @@ -181,15 +108,17 @@ struct RamArgs { /// Not all targets support RTC slow ram. #[cfg(feature = "ram")] #[proc_macro_attribute] -#[proc_macro_error] +#[proc_macro_error::proc_macro_error] pub fn ram(args: TokenStream, input: TokenStream) -> TokenStream { + use darling::{ast::NestedMeta, Error, FromMeta}; use proc_macro::Span; use proc_macro_error::abort; + use syn::{parse, Item}; let attr_args = match NestedMeta::parse_meta_list(args.into()) { Ok(v) => v, Err(e) => { - return TokenStream::from(DarlingError::from(e).write_errors()); + return TokenStream::from(Error::from(e).write_errors()); } }; @@ -205,7 +134,7 @@ pub fn ram(args: TokenStream, input: TokenStream) -> TokenStream { } }; - let item: syn::Item = syn::parse(input).expect("failed to parse input"); + let item: Item = parse(input).expect("failed to parse input"); #[cfg(not(feature = "rtc_slow"))] if rtc_slow { @@ -215,7 +144,7 @@ pub fn ram(args: TokenStream, input: TokenStream) -> TokenStream { ); } - let is_fn = matches!(item, syn::Item::Fn(_)); + let is_fn = matches!(item, Item::Fn(_)); let section_name = match (is_fn, rtc_fast, rtc_slow, uninitialized, zeroed) { (true, false, false, false, false) => Ok(".rwtext"), (true, true, false, false, false) => Ok(".rtc_fast.text"), @@ -235,11 +164,11 @@ pub fn ram(args: TokenStream, input: TokenStream) -> TokenStream { }; let section = match (is_fn, section_name) { - (true, Ok(section_name)) => quote! { + (true, Ok(section_name)) => quote::quote! { #[link_section = #section_name] #[inline(never)] // make certain function is not inlined }, - (false, Ok(section_name)) => quote! { + (false, Ok(section_name)) => quote::quote! { #[link_section = #section_name] }, (_, Err(_)) => { @@ -247,7 +176,7 @@ pub fn ram(args: TokenStream, input: TokenStream) -> TokenStream { } }; - let output = quote! { + let output = quote::quote! { #section #item }; @@ -285,10 +214,12 @@ pub fn ram(args: TokenStream, input: TokenStream) -> TokenStream { pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream { use std::iter; + use darling::{ast::NestedMeta, Error}; use proc_macro::Span; use proc_macro2::Ident; - use proc_macro_crate::FoundCrate; + use proc_macro_crate::{crate_name, FoundCrate}; use proc_macro_error::abort; + use quote::quote; use syn::{ parse::Error as ParseError, spanned::Spanned, @@ -306,7 +237,7 @@ pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream { let attr_args = match NestedMeta::parse_meta_list(args.into()) { Ok(v) => v, Err(e) => { - return TokenStream::from(darling::Error::from(e).write_errors()); + return TokenStream::from(Error::from(e).write_errors()); } }; @@ -321,19 +252,16 @@ pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream { let mut ident_s = &ident.clone(); if attr_args.len() == 1 { - match &attr_args[0] { - NestedMeta::Meta(Meta::Path(x)) => { - ident_s = x.get_ident().unwrap(); - } - _ => { - abort!( - Span::call_site(), - format!( - "This attribute accepts a string attribute {:?}", - attr_args[0] - ) + if let NestedMeta::Meta(Meta::Path(x)) = &attr_args[0] { + ident_s = x.get_ident().unwrap(); + } else { + abort!( + Span::call_site(), + format!( + "This attribute accepts a string attribute {:?}", + attr_args[0] ) - } + ) } } @@ -373,19 +301,17 @@ pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream { proc_macro2::Span::call_site(), ); - let (hal_crate, hal_crate_name) = get_hal_crate(); + let hal_crate = if cfg!(any(feature = "is-lp-core", feature = "is-ulp-core")) { + crate_name("esp-lp-hal") + } else { + crate_name("esp-hal") + }; - let interrupt_in_hal_crate = match hal_crate { - Ok(FoundCrate::Itself) => { - quote!( #hal_crate_name::peripherals::Interrupt::#ident_s ) - } - Ok(FoundCrate::Name(ref name)) => { - let ident = Ident::new(&name, Span::call_site().into()); - quote!( #ident::peripherals::Interrupt::#ident_s ) - } - Err(_) => { - quote!( crate::peripherals::Interrupt::#ident_s ) - } + let interrupt_in_hal_crate = if let Ok(FoundCrate::Name(ref name)) = hal_crate { + let ident = Ident::new(&name, Span::call_site().into()); + quote!( #ident::peripherals::Interrupt::#ident_s ) + } else { + quote!( crate::peripherals::Interrupt::#ident_s ) }; f.block.stmts.extend(iter::once( @@ -406,17 +332,11 @@ pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream { let export_name = ident_s.to_string(); - let trap_frame_in_hal_crate = match hal_crate { - Ok(FoundCrate::Itself) => { - quote!(#hal_crate_name::trapframe::TrapFrame) - } - Ok(FoundCrate::Name(ref name)) => { - let ident = Ident::new(&name, Span::call_site().into()); - quote!( #ident::trapframe::TrapFrame ) - } - Err(_) => { - quote!(crate::trapframe::TrapFrame) - } + let trap_frame_in_hal_crate = if let Ok(FoundCrate::Name(ref name)) = hal_crate { + let ident = Ident::new(&name, Span::call_site().into()); + quote!( #ident::trapframe::TrapFrame ) + } else { + quote!(crate::trapframe::TrapFrame) }; let context_call = @@ -445,34 +365,14 @@ pub fn interrupt(args: TokenStream, input: TokenStream) -> TokenStream { #[cfg(feature = "enum-dispatch")] #[proc_macro] pub fn make_gpio_enum_dispatch_macro(input: TokenStream) -> TokenStream { - use quote::format_ident; + use quote::{format_ident, quote}; - use self::enum_dispatch::MakeGpioEnumDispatchMacro; + use self::enum_dispatch::{build_match_arms, MakeGpioEnumDispatchMacro}; - let input = parse_macro_input!(input as MakeGpioEnumDispatchMacro); - - let mut arms = Vec::new(); - for (gpio_type, num) in input.elements { - let enum_name = format_ident!("ErasedPin"); - let variant_name = format_ident!("Gpio{}", num); - - if input.filter.contains(&gpio_type) { - let arm = { - quote! { #enum_name::#variant_name($target) => $body } - }; - arms.push(arm); - } else { - let arm = { - quote! { - #[allow(unused)] - #enum_name::#variant_name($target) => { panic!("Unsupported") } - } - }; - arms.push(arm); - } - } + let input = syn::parse_macro_input!(input as MakeGpioEnumDispatchMacro); let macro_name = format_ident!("{}", input.name); + let arms = build_match_arms(input); quote! { #[doc(hidden)] @@ -497,35 +397,36 @@ pub fn make_gpio_enum_dispatch_macro(input: TokenStream) -> TokenStream { /// let lp_core_code = load_lp_code!("path.elf"); /// lp_core_code.run(&mut lp_core, lp_core::LpCoreWakeupSource::HpCpu, lp_pin); /// ```` -#[cfg(any(feature = "esp32c6", feature = "esp32s2", feature = "esp32s3"))] +#[cfg(any(feature = "has-lp-core", feature = "has-ulp-core"))] #[proc_macro] pub fn load_lp_code(input: TokenStream) -> TokenStream { - use std::{fs, path}; + use std::{fs, path::Path}; - use object::{Object, ObjectSection, ObjectSymbol}; + use litrs::StringLit; + use object::{File, Object, ObjectSection, ObjectSymbol, Section, SectionKind}; + use parse::Error; use proc_macro::Span; - use proc_macro_crate::FoundCrate; + use proc_macro_crate::{crate_name, FoundCrate}; + use quote::quote; use syn::{parse, Ident}; - let (hal_crate, hal_crate_name) = get_hal_crate(); + let hal_crate = if cfg!(any(feature = "is-lp-core", feature = "is-ulp-core")) { + crate_name("esp-lp-hal") + } else { + crate_name("esp-hal") + }; - let hal_crate = match hal_crate { - Ok(FoundCrate::Itself) => { - quote!( #hal_crate_name ) - } - Ok(FoundCrate::Name(ref name)) => { - let ident = Ident::new(&name, Span::call_site().into()); - quote!( #ident ) - } - Err(_) => { - quote!(crate) - } + let hal_crate = if let Ok(FoundCrate::Name(ref name)) = hal_crate { + let ident = Ident::new(&name, Span::call_site().into()); + quote!( #ident ) + } else { + quote!(crate) }; let first_token = match input.into_iter().next() { Some(token) => token, None => { - return parse::Error::new( + return Error::new( Span::call_site().into(), "You need to give the path to an ELF file", ) @@ -533,10 +434,10 @@ pub fn load_lp_code(input: TokenStream) -> TokenStream { .into(); } }; - let arg = match litrs::StringLit::try_from(&first_token) { + let arg = match StringLit::try_from(&first_token) { Ok(arg) => arg, Err(_) => { - return parse::Error::new( + return Error::new( Span::call_site().into(), "You need to give the path to an ELF file", ) @@ -546,33 +447,34 @@ pub fn load_lp_code(input: TokenStream) -> TokenStream { }; let elf_file = arg.value(); - if !path::Path::new(elf_file).exists() { - return parse::Error::new(Span::call_site().into(), "File not found") + if !Path::new(elf_file).exists() { + return Error::new(Span::call_site().into(), "File not found") .to_compile_error() .into(); } let bin_data = fs::read(elf_file).unwrap(); - let obj_file = object::File::parse(&*bin_data).unwrap(); + let obj_file = File::parse(&*bin_data).unwrap(); let sections = obj_file.sections(); - let mut sections: Vec = sections + let mut sections: Vec
= sections .into_iter() .filter(|section| match section.kind() { - object::SectionKind::Text - | object::SectionKind::ReadOnlyData - | object::SectionKind::Data - | object::SectionKind::UninitializedData => true, + SectionKind::Text + | SectionKind::ReadOnlyData + | SectionKind::Data + | SectionKind::UninitializedData => true, _ => false, }) .collect(); sections.sort_by(|a, b| a.address().partial_cmp(&b.address()).unwrap()); let mut binary: Vec = Vec::new(); - #[cfg(feature = "esp32c6")] - let mut last_address = 0x50_000_000; - #[cfg(any(feature = "esp32s2", feature = "esp32s3"))] - let mut last_address = 0x0; + let mut last_address = if cfg!(feature = "has-lp-core") { + 0x5000_0000 + } else { + 0x0 + }; for section in sections { if section.address() > last_address { @@ -590,7 +492,7 @@ pub fn load_lp_code(input: TokenStream) -> TokenStream { .find(|s| s.name().unwrap().starts_with("__ULP_MAGIC_")); if let None = magic_symbol { - return parse::Error::new( + return Error::new( Span::call_site().into(), "Given file doesn't seem to be an LP/ULP core application.", ) @@ -611,7 +513,7 @@ pub fn load_lp_code(input: TokenStream) -> TokenStream { .filter(|v: &proc_macro2::TokenStream| !v.is_empty()) .collect(); - #[cfg(feature = "esp32c6")] + #[cfg(feature = "has-lp-core")] let imports = quote! { use #hal_crate::lp_core::LpCore; use #hal_crate::lp_core::LpCoreWakeupSource; @@ -620,24 +522,23 @@ pub fn load_lp_code(input: TokenStream) -> TokenStream { use #hal_crate::uart::lp_uart::LpUart; use #hal_crate::i2c::lp_i2c::LpI2c; }; - #[cfg(any(feature = "esp32s2", feature = "esp32s3"))] + #[cfg(feature = "has-ulp-core")] let imports = quote! { use #hal_crate::ulp_core::UlpCore as LpCore; use #hal_crate::ulp_core::UlpCoreWakeupSource as LpCoreWakeupSource; use #hal_crate::gpio::*; }; - #[cfg(feature = "esp32c6")] + #[cfg(feature = "has-lp-core")] let rtc_code_start = quote! { _rtc_fast_data_start }; - #[cfg(any(feature = "esp32s2", feature = "esp32s3"))] + #[cfg(feature = "has-ulp-core")] let rtc_code_start = quote! { _rtc_slow_data_start }; quote! { { #imports - struct LpCoreCode { - } + struct LpCoreCode {} static LP_CODE: &[u8] = &[#(#binary),*]; @@ -651,34 +552,35 @@ pub fn load_lp_code(input: TokenStream) -> TokenStream { impl LpCoreCode { pub fn run( - &self, - lp_core: &mut LpCore, - wakeup_source: LpCoreWakeupSource, - #(_: #args),* - ) { + &self, + lp_core: &mut LpCore, + wakeup_source: LpCoreWakeupSource, + #(_: #args),* + ) { lp_core.run(wakeup_source); } } - LpCoreCode { - } + LpCoreCode {} } } .into() } -#[cfg(any( - feature = "esp32c6-lp", - feature = "esp32s2-ulp", - feature = "esp32s3-ulp" -))] -#[proc_macro_error] +#[cfg(any(feature = "is-lp-core", feature = "is-ulp-core"))] +#[proc_macro_error::proc_macro_error] #[proc_macro_attribute] pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { use proc_macro2::{Ident, Span}; use proc_macro_crate::{crate_name, FoundCrate}; use quote::{format_ident, quote}; - use syn::{parse, parse_macro_input, spanned::Spanned, FnArg, ItemFn}; + use syn::{ + parse::{self, Error}, + parse_macro_input, + spanned::Spanned, + FnArg, + ItemFn, + }; use self::lp_core::{extract_pin, get_simplename, make_magic_symbol_name}; @@ -692,7 +594,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { }; if !args.is_empty() { - return parse::Error::new(Span::call_site(), "This attribute accepts no arguments") + return Error::new(Span::call_site(), "This attribute accepts no arguments") .to_compile_error() .into(); } @@ -708,7 +610,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { let param_name = format_ident!("param{}", num); match arg { FnArg::Receiver(_) => { - return parse::Error::new(arg.span(), "invalid argument") + return Error::new(arg.span(), "invalid argument") .to_compile_error() .into(); } @@ -717,7 +619,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { "GpioPin" => { let pin = extract_pin(&t.ty); if used_pins.contains(&pin) { - return parse::Error::new(arg.span(), "duplicate pin") + return Error::new(arg.span(), "duplicate pin") .to_compile_error() .into(); } @@ -737,7 +639,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { )); } _ => { - return parse::Error::new(arg.span(), "invalid argument to main") + return Error::new(arg.span(), "invalid argument to main") .to_compile_error() .into(); } @@ -798,7 +700,7 @@ pub fn entry(args: TokenStream, input: TokenStream) -> TokenStream { /// // Function body /// } /// ``` -#[cfg(all(feature = "embassy"))] +#[cfg(feature = "embassy")] #[proc_macro_attribute] pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { use self::embassy::{ @@ -806,8 +708,8 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream { Args, }; - let args = parse_macro_input!(args as Args); - let f = parse_macro_input!(item as syn::ItemFn); + let args = syn::parse_macro_input!(args as Args); + let f = syn::parse_macro_input!(item as syn::ItemFn); run(&args.meta, f, main()).unwrap_or_else(|x| x).into() } diff --git a/esp-hal-smartled/Cargo.toml b/esp-hal-smartled/Cargo.toml index 32e14d181..db7527b0e 100644 --- a/esp-hal-smartled/Cargo.toml +++ b/esp-hal-smartled/Cargo.toml @@ -2,7 +2,7 @@ name = "esp-hal-smartled" version = "0.8.0" edition = "2021" -rust-version = "1.67.0" +rust-version = "1.76.0" description = "RMT adapter for smartleds" repository = "https://github.com/esp-rs/esp-hal" license = "MIT OR Apache-2.0" diff --git a/esp-hal/Cargo.toml b/esp-hal/Cargo.toml index 089ffb33f..25ceac09f 100644 --- a/esp-hal/Cargo.toml +++ b/esp-hal/Cargo.toml @@ -2,17 +2,11 @@ name = "esp-hal" version = "0.15.0" edition = "2021" -rust-version = "1.67.0" -description = "HAL implementations for peripherals common among Espressif devices; should not be used directly" +rust-version = "1.76.0" +description = "Bare-metal HAL for Espressif devices" repository = "https://github.com/esp-rs/esp-hal" license = "MIT OR Apache-2.0" - -# Prevent multiple copies of this crate in the same binary. -# Needed because different copies might get different features, causing -# confusing build errors due to expected features not getting enabled -# on the unintentional copy. -# This is especially common when mixing crates from crates.io and git. -links = "esp-hal" +links = "esp-hal" [dependencies] bitflags = "2.4.2" @@ -20,12 +14,19 @@ bitfield = "0.14.0" cfg-if = "1.0.0" critical-section = "1.1.2" defmt = { version = "=0.3.5", optional = true } +document-features = "0.2.8" +embassy-executor = { version = "0.5.0", optional = true } +embassy-futures = { version = "0.1.1", optional = true } +embassy-sync = { version = "0.5.0", optional = true } +embassy-time-driver = { version = "0.1.0", optional = true } embedded-can = { version = "0.4.1", optional = true } embedded-dma = "0.2.0" embedded-hal = { version = "0.2.7", features = ["unproven"] } embedded-hal-1 = { version = "1.0.0", optional = true, package = "embedded-hal" } +embedded-hal-async = { version = "1.0.0", optional = true } embedded-hal-nb = { version = "1.0.0", optional = true } embedded-io = { version = "0.6.1", optional = true } +embedded-io-async = { version = "0.6.1", optional = true } enumset = "1.1.3" esp-synopsys-usb-otg = { version = "0.4.0", optional = true, features = ["fs", "esp32sx"] } fugit = "0.3.7" @@ -34,134 +35,47 @@ nb = "1.1.0" paste = "1.0.14" portable-atomic = { version = "1.6.0", default-features = false } procmacros = { version = "0.8.0", features = ["enum-dispatch", "ram"], package = "esp-hal-procmacros", path = "../esp-hal-procmacros" } +riscv = { version = "0.11.0", optional = true } strum = { version = "0.25.0", default-features = false, features = ["derive"] } void = { version = "1.0.2", default-features = false } usb-device = { version = "0.3.1", optional = true } -rand_core = { version = "0.6.4" } - -# async -embedded-hal-async = { version = "1.0.0", optional = true } -embedded-io-async = { version = "0.6.1", optional = true } -embassy-executor = { version = "0.5.0", optional = true } -embassy-futures = { version = "0.1.1", optional = true } -embassy-sync = { version = "0.5.0", optional = true } -embassy-time-driver = { version = "0.1.0", optional = true } - -# RISC-V -riscv = { version = "0.11.0", optional = true } -esp-riscv-rt = { version = "0.6.1", optional = true, path = "../esp-riscv-rt" } - -# Xtensa -xtensa-lx = { version = "0.8.0", optional = true } -xtensa-lx-rt = { version = "0.16.0", optional = true } - -# Part of `ufmt` containing only `uWrite` trait -ufmt-write = { version = "0.1.0", optional = true } +rand_core = "0.6.4" +ufmt-write = { version = "0.1.0", optional = true } +xtensa-lx = { version = "0.9.0", optional = true } # IMPORTANT: # Each supported device MUST have its PAC included below along with a # corresponding feature. -esp32 = { git = "https://github.com/esp-rs/esp-pacs", rev = "ef39b1c", features = ["critical-section"], optional = true } -esp32c2 = { git = "https://github.com/esp-rs/esp-pacs", rev = "ef39b1c", features = ["critical-section"], optional = true } -esp32c3 = { git = "https://github.com/esp-rs/esp-pacs", rev = "ef39b1c", features = ["critical-section"], optional = true } -esp32c6 = { git = "https://github.com/esp-rs/esp-pacs", rev = "ef39b1c", features = ["critical-section"], optional = true } -esp32h2 = { git = "https://github.com/esp-rs/esp-pacs", rev = "ef39b1c", features = ["critical-section"], optional = true } -esp32p4 = { git = "https://github.com/esp-rs/esp-pacs", rev = "ef39b1c", features = ["critical-section"], optional = true } -esp32s2 = { git = "https://github.com/esp-rs/esp-pacs", rev = "ef39b1c", features = ["critical-section"], optional = true } -esp32s3 = { git = "https://github.com/esp-rs/esp-pacs", rev = "ef39b1c", features = ["critical-section"], optional = true } +esp32 = { git = "https://github.com/esp-rs/esp-pacs", rev = "bbf7d5a", features = ["critical-section"], optional = true } +esp32c2 = { git = "https://github.com/esp-rs/esp-pacs", rev = "bbf7d5a", features = ["critical-section"], optional = true } +esp32c3 = { git = "https://github.com/esp-rs/esp-pacs", rev = "bbf7d5a", features = ["critical-section"], optional = true } +esp32c6 = { git = "https://github.com/esp-rs/esp-pacs", rev = "bbf7d5a", features = ["critical-section"], optional = true } +esp32h2 = { git = "https://github.com/esp-rs/esp-pacs", rev = "bbf7d5a", features = ["critical-section"], optional = true } +esp32p4 = { git = "https://github.com/esp-rs/esp-pacs", rev = "bbf7d5a", features = ["critical-section"], optional = true } +esp32s2 = { git = "https://github.com/esp-rs/esp-pacs", rev = "bbf7d5a", features = ["critical-section"], optional = true } +esp32s3 = { git = "https://github.com/esp-rs/esp-pacs", rev = "bbf7d5a", features = ["critical-section"], optional = true } + +[target.'cfg(target_arch = "riscv32")'.dependencies] +esp-riscv-rt = { version = "0.6.1", optional = true } + +[target.'cfg(target_arch = "xtensa")'.dependencies] +xtensa-lx-rt = { version = "0.16.0", optional = true } [build-dependencies] basic-toml = "0.1.8" serde = { version = "1.0.195", features = ["derive"] } [features] -esp32 = ["dep:esp32", "xtensa", "procmacros/esp32", "xtensa-lx/esp32", "xtensa-lx-rt?/esp32"] -esp32c2 = ["dep:esp32c2", "riscv", "procmacros/esp32c2", "portable-atomic/unsafe-assume-single-core"] -esp32c3 = ["dep:esp32c3", "riscv", "procmacros/esp32c3", "portable-atomic/unsafe-assume-single-core"] -esp32c6 = ["dep:esp32c6", "riscv", "procmacros/esp32c6"] -esp32h2 = ["dep:esp32h2", "riscv", "procmacros/esp32h2"] -esp32p4 = ["dep:esp32p4", "riscv", "procmacros/esp32p4"] -esp32s2 = ["dep:esp32s2", "xtensa", "procmacros/esp32s2", "xtensa-lx/esp32s2", "xtensa-lx-rt?/esp32s2", "usb-otg", "portable-atomic/critical-section"] -esp32s3 = ["dep:esp32s3", "xtensa", "procmacros/esp32s3", "xtensa-lx/esp32s3", "xtensa-lx-rt?/esp32s3", "usb-otg"] +default = ["rt", "vectored"] -# Runetime support -rt-riscv = ["esp-riscv-rt/zero-bss", "esp32c2?/rt", "esp32c3?/rt", "esp32c6?/rt", "esp32h2?/rt", "esp32p4?/rt"] -rt-xtensa = ["dep:xtensa-lx-rt", "esp32?/rt", "esp32s2?/rt", "esp32s3?/rt"] +riscv = ["dep:riscv", "critical-section/restore-state-u8", "esp-riscv-rt?/zero-bss"] +xtensa = ["dep:xtensa-lx", "critical-section/restore-state-u32"] -# Only certain chips support flip-link (ESP32-C6 and ESPS32-H2) -flip-link = ["esp-riscv-rt/fix-sp"] +bluetooth = [] -# PSRAM support -psram-2m = [] -psram-4m = [] -psram-8m = [] - -# Octal RAM support -opsram-2m = [] -opsram-4m = [] -opsram-8m = [] -opsram-16m = [] - -# PSRAM 80Mhz frequency support -psram-80mhz = [] - -# USB OTG support (ESP32-S2 and ESP32-S3 only! Enabled by default) usb-otg = ["esp-synopsys-usb-otg", "usb-device"] -# Interrupt-related feature: -# - Use direct interrupt vectoring (RISC-V only!) -# - Use interrupt preemption (RISC-V only!) -# - Use vectored interrupts (calling the handlers defined in the PAC) -direct-vectoring = ["esp-riscv-rt/direct-vectoring"] -interrupt-preemption = ["esp-riscv-rt/interrupt-preemption"] -vectored = ["procmacros/interrupt"] - -# Enable logging -log = ["dep:log"] - -# Trait implementation features: -# - Implement the `embedded-hal@1.0.0-rc.x` traits (and friends) -# - Implement the `embedded-io` traits where able -# - Implement the `ufmt_write::Write` trait where able -eh1 = ["embedded-hal-1", "embedded-hal-nb", "embedded-can"] -embedded-io = ["dep:embedded-io"] -ufmt = ["ufmt-write"] - -# Support for asynchronous operation, implementing traits from -# `embedded-hal-async` and `embedded-io-async` -async = [ - "embedded-hal-async", - "eh1", - "embassy-sync", - "embassy-futures", - "embedded-io", - "embedded-io-async", -] - -# Embassy support -embassy = ["embassy-time-driver", "procmacros/embassy"] - -embassy-executor-interrupt = ["embassy", "embassy-executor"] -embassy-executor-thread = ["embassy", "embassy-executor"] - -embassy-integrated-timers = ["embassy-executor?/integrated-timers"] - -embassy-time-systick = [] -embassy-time-timg0 = [] - -# Architecture-specific features (intended for internal use) -riscv = ["dep:riscv", "critical-section/restore-state-u8"] -xtensa = ["critical-section/restore-state-u32"] - -# Initialize / clear data sections and RTC memory -rv-init-data = ["esp-riscv-rt/init-data", "esp-riscv-rt/init-rw-text"] -rv-zero-rtc-bss = ["esp-riscv-rt/zero-rtc-fast-bss"] -rv-init-rtc-data = ["esp-riscv-rt/init-rtc-fast-data", "esp-riscv-rt/init-rtc-fast-text"] - -# Configuration for placing device drivers in the IRAM for faster access -place-spi-driver-in-ram = [] - -# Enable the `impl-register-debug` feature for the selected PAC +## Enable debug features in the HAL (used for development). debug = [ "esp32?/impl-register-debug", "esp32c2?/impl-register-debug", @@ -172,8 +86,71 @@ debug = [ "esp32s2?/impl-register-debug", "esp32s3?/impl-register-debug", ] +## Enable logging output using the `log` crate. +log = ["dep:log"] +## Enable runtime support. +rt = [ + "dep:esp-riscv-rt", + "dep:xtensa-lx-rt", + "esp32?/rt", + "esp32c2?/rt", + "esp32c3?/rt", + "esp32c6?/rt", + "esp32h2?/rt", + "esp32p4?/rt", + "esp32s2?/rt", + "esp32s3?/rt", +] +## Enable interrupt vectoring. +vectored = ["procmacros/interrupt"] -# Enable support for `defmt`, for `esp-hal` and also for all our dependencies +#! ### Chip Support Feature Flags +## Target the ESP32. +esp32 = ["dep:esp32", "xtensa", "xtensa-lx/spin", "xtensa-lx-rt?/esp32"] +## Target the ESP32-C2. +esp32c2 = ["dep:esp32c2", "riscv", "portable-atomic/unsafe-assume-single-core"] +## Target the ESP32-C3. +esp32c3 = ["dep:esp32c3", "riscv", "portable-atomic/unsafe-assume-single-core", "rv-zero-rtc-bss"] +## Target the ESP32-C6. +esp32c6 = ["dep:esp32c6", "riscv", "procmacros/has-lp-core", "rv-zero-rtc-bss"] +## Target the ESP32-H2. +esp32h2 = ["dep:esp32h2", "riscv", "rv-zero-rtc-bss"] +## Target the ESP32-P4. +esp32p4 = ["dep:esp32p4", "riscv", "procmacros/has-lp-core", "rv-zero-rtc-bss"] +## Target the ESP32-S2. +esp32s2 = ["dep:esp32s2", "xtensa", "portable-atomic/critical-section", "procmacros/has-ulp-core", "xtensa-lx-rt?/esp32s2", "usb-otg"] +## Target the ESP32-S3. +esp32s3 = ["dep:esp32s3", "xtensa", "procmacros/has-ulp-core", "xtensa-lx/spin", "xtensa-lx-rt?/esp32s3", "usb-otg"] + +#! ### RISC-V Exclusive Feature Flags +## Enable direct interrupt vectoring. +direct-vectoring = ["esp-riscv-rt/direct-vectoring"] +## Move the stack to start of RAM to get zero-cost stack overflow protection +## (ESP32-C6 and ESPS32-H2 only!). +flip-link = ["esp-riscv-rt/fix-sp"] +## Enable interrupt preemption. +interrupt-preemption = ["esp-riscv-rt/interrupt-preemption"] +## Configuration for placing device drivers in the IRAM for faster access. +place-spi-driver-in-ram = [] +## Initialize the `.data` section of memory. +rv-init-data = ["esp-riscv-rt?/init-data", "esp-riscv-rt?/init-rw-text"] +## Zero the `.bss` section of low-power memory. +rv-zero-rtc-bss = ["esp-riscv-rt?/zero-rtc-fast-bss"] +## Initialize the `.data` section of low-power memory. +rv-init-rtc-data = ["esp-riscv-rt?/init-rtc-fast-data", "esp-riscv-rt?/init-rtc-fast-text"] + +#! ### Trait Implementation Feature Flags +## Enable support for asynchronous operation, with interfaces provided by +## `embedded-hal-async` and `embedded-io-async`. +async = [ + "embedded-hal-async", + "eh1", + "embassy-sync", + "embassy-futures", + "embedded-io", + "embedded-io-async", +] +## Implement `defmt::Format` on certain types. defmt = [ "dep:defmt", "embassy-executor?/defmt", @@ -183,3 +160,48 @@ defmt = [ "embedded-io/defmt-03", "embedded-io-async?/defmt-03", ] +## Implement the traits defined in the `1.0.0` releases of `embedded-hal` and +## `embedded-hal-nb` for the relevant peripherals. +eh1 = ["embedded-hal-1", "embedded-hal-nb", "embedded-can"] +## Implement the traits defined in `embedded-io` for certain peripherals. +embedded-io = ["dep:embedded-io"] +## Implement the `ufmt_write::uWrite` trait for certain peripherals. +ufmt = ["dep:ufmt-write"] + +#! ### Embassy Feature Flags +## Enable support for `embassy`, a modern asynchronous embedded framework. +embassy = ["embassy-time-driver", "procmacros/embassy"] +## Use the interrupt-mode embassy executor. +embassy-executor-interrupt = ["embassy", "embassy-executor"] +## Use the thread-mode embassy executor. +embassy-executor-thread = ["embassy", "embassy-executor"] +## Uses hardware timers as alarms for the executors. Using this feature +## limits the number of executors to the number of hardware alarms provided +## by the time driver. +embassy-integrated-timers = ["embassy-executor?/integrated-timers"] +## Enable the embassy time driver using the `SYSTIMER` peripheral. The +## `SYSTIMER` peripheral has three alarams available for use. +embassy-time-systick = [] +## Enable the embassy time driver using the `TIMG0` peripheral. The `TIMG0` +## peripheral has two alarms available for use. +embassy-time-timg0 = [] + +#! ### PSRAM Feature Flags +## Use externally connected PSRAM (2MB). +psram-2m = [] +## Use externally connected PSRAM (4MB). +psram-4m = [] +## Use externally connected PSRAM (8MB). +psram-8m = [] +## PSRAM 80Mhz frequency support +psram-80mhz = [] + +#! ### Octal RAM Feature Flags +## Use externally connected Octal RAM (2MB). +opsram-2m = [] +## Use externally connected Octal RAM (4MB). +opsram-4m = [] +## Use externally connected Octal RAM (8MB). +opsram-8m = [] +## Use externally connected Octal RAM (16MB). +opsram-16m = [] diff --git a/esp-hal/build.rs b/esp-hal/build.rs index 8f734e7d5..02e58c638 100644 --- a/esp-hal/build.rs +++ b/esp-hal/build.rs @@ -249,6 +249,9 @@ fn main() -> Result<(), Box> { copy_dir_all(&config_symbols, "ld/sections", &out)?; copy_dir_all(&config_symbols, format!("ld/{device_name}"), &out)?; + #[cfg(any(feature = "esp32", feature = "esp32s2"))] + File::create(out.join("memory_extras.x"))?.write_all(&generate_memory_extras())?; + // Generate the eFuse table from the selected device's CSV file: gen_efuse_table(device_name, out)?; @@ -412,3 +415,43 @@ fn detect_atomic_extension(ext: &str) -> bool { false } + +#[cfg(feature = "esp32")] +fn generate_memory_extras() -> Vec { + let reserve_dram = if cfg!(feature = "bluetooth") { + "0x10000" + } else { + "0x0" + }; + + format!( + " + /* reserved at the start of DRAM for e.g. the BT stack */ + RESERVE_DRAM = {reserve_dram}; + " + ) + .as_bytes() + .to_vec() +} + +#[cfg(feature = "esp32s2")] +fn generate_memory_extras() -> Vec { + let reserved_cache = if cfg!(any( + feature = "psram-2m", + feature = "psram-4m", + feature = "psram-8m" + )) { + "0x4000" + } else { + "0x2000" + }; + + format!( + " + /* reserved at the start of DRAM/IRAM */ + RESERVE_CACHES = {reserved_cache}; + " + ) + .as_bytes() + .to_vec() +} diff --git a/esp-hal/src/embassy/mod.rs b/esp-hal/src/embassy/mod.rs index 51018e4f7..1acfbfebe 100644 --- a/esp-hal/src/embassy/mod.rs +++ b/esp-hal/src/embassy/mod.rs @@ -35,7 +35,7 @@ //! #[cfg(feature = "embassy-time-systick")] //! embassy::init( //! &clocks, -//! esp32c6_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), +//! esp_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), //! ); //! //! #[cfg(feature = "embassy-time-timg0")] @@ -46,9 +46,9 @@ //! let input = io.pins.gpio9.into_pull_down_input(); //! //! // Async requires the GPIO interrupt to wake futures -//! esp32c6_hal::interrupt::enable( -//! esp32c6_hal::peripherals::Interrupt::GPIO, -//! esp32c6_hal::interrupt::Priority::Priority1, +//! esp_hal::interrupt::enable( +//! esp_hal::peripherals::Interrupt::GPIO, +//! esp_hal::interrupt::Priority::Priority1, //! ) //! .unwrap(); //! diff --git a/esp-hal/src/interrupt/riscv.rs b/esp-hal/src/interrupt/riscv.rs index 8586a9c52..7e2416ada 100644 --- a/esp-hal/src/interrupt/riscv.rs +++ b/esp-hal/src/interrupt/riscv.rs @@ -12,8 +12,11 @@ //! interrupt15() => Priority::Priority15 //! ``` -use esp_riscv_rt::riscv::register::{mcause, mtvec}; +// TODO: Add safety doc comments as needed and remove allow attribute +#![allow(clippy::missing_safety_doc)] + pub use esp_riscv_rt::TrapFrame; +use riscv::register::{mcause, mtvec}; #[cfg(not(any(plic, clic)))] pub use self::classic::*; @@ -158,7 +161,7 @@ mod vectored { let interrupt_nr = status.trailing_zeros() as u16; // safety: cast is safe because of repr(u16) if let Some(cpu_interrupt) = - get_assigned_cpu_interrupt(core::mem::transmute(interrupt_nr as u16)) + get_assigned_cpu_interrupt(core::mem::transmute(interrupt_nr)) { let prio = get_priority_by_core(core, cpu_interrupt); prios[prio as usize] |= 1 << (interrupt_nr as usize); @@ -249,8 +252,13 @@ mod vectored { // defined in each hal fn EspDefaultHandler(interrupt: Interrupt); } + let handler = peripherals::__EXTERNAL_INTERRUPTS[interrupt as usize]._handler; - if handler as *const _ == EspDefaultHandler as *const unsafe extern "C" fn() { + + if core::ptr::eq( + handler as *const _, + EspDefaultHandler as *const unsafe extern "C" fn(), + ) { EspDefaultHandler(interrupt); } else { let handler: fn(&mut TrapFrame) = core::mem::transmute(handler); @@ -739,7 +747,6 @@ mod classic { #[link_section = ".trap"] pub(super) unsafe extern "C" fn _handle_priority() -> u32 { use super::mcause; - use crate::riscv; let interrupt_id: usize = mcause::read().code(); // MSB is whether its exception or interrupt. let intr = &*crate::peripherals::INTERRUPT_CORE0::PTR; let interrupt_priority = intr @@ -763,10 +770,7 @@ mod classic { #[no_mangle] #[link_section = ".trap"] pub(super) unsafe extern "C" fn _restore_priority(stored_prio: u32) { - use crate::riscv; - unsafe { - riscv::interrupt::disable(); - } + riscv::interrupt::disable(); let intr = &*crate::peripherals::INTERRUPT_CORE0::PTR; intr.cpu_int_thresh().write(|w| w.bits(stored_prio)); } @@ -792,7 +796,7 @@ mod plic { ]; const DR_REG_PLIC_MX_BASE: u32 = 0x20001000; - const PLIC_MXINT_ENABLE_REG: u32 = DR_REG_PLIC_MX_BASE + 0x0; + const PLIC_MXINT_ENABLE_REG: u32 = DR_REG_PLIC_MX_BASE; const PLIC_MXINT_TYPE_REG: u32 = DR_REG_PLIC_MX_BASE + 0x4; const PLIC_MXINT_CLEAR_REG: u32 = DR_REG_PLIC_MX_BASE + 0x8; const PLIC_MXINT0_PRI_REG: u32 = DR_REG_PLIC_MX_BASE + 0x10; @@ -877,7 +881,6 @@ mod plic { #[link_section = ".trap"] pub(super) unsafe extern "C" fn _handle_priority() -> u32 { use super::mcause; - use crate::riscv; let plic_mxint_pri_ptr = PLIC_MXINT0_PRI_REG as *mut u32; let interrupt_id: isize = mcause::read().code().try_into().unwrap(); // MSB is whether its exception or interrupt. let interrupt_priority = plic_mxint_pri_ptr.offset(interrupt_id).read_volatile(); @@ -898,10 +901,7 @@ mod plic { #[no_mangle] #[link_section = ".trap"] pub(super) unsafe extern "C" fn _restore_priority(stored_prio: u32) { - use crate::riscv; - unsafe { - riscv::interrupt::disable(); - } + riscv::interrupt::disable(); let thresh_reg = PLIC_MXINT_THRESH_REG as *mut u32; thresh_reg.write_volatile(stored_prio); } diff --git a/esp-hal/src/interrupt/xtensa.rs b/esp-hal/src/interrupt/xtensa.rs index 2f041a5c9..776168389 100644 --- a/esp-hal/src/interrupt/xtensa.rs +++ b/esp-hal/src/interrupt/xtensa.rs @@ -1,3 +1,6 @@ +// TODO: Add safety doc comments as needed and remove allow attribute +#![allow(clippy::missing_safety_doc)] + use xtensa_lx::interrupt::{self, InterruptNumber}; use xtensa_lx_rt::exception::Context; @@ -394,41 +397,39 @@ mod vectored { if let Some(handler) = cpu_interrupt_nr_to_cpu_interrupt_handler(cpu_interrupt_nr) { handler(level, save_frame); } - } else { - if (cpu_interrupt_mask & CPU_INTERRUPT_EDGE) != 0 { - let cpu_interrupt_mask = cpu_interrupt_mask & CPU_INTERRUPT_EDGE; - let cpu_interrupt_nr = cpu_interrupt_mask.trailing_zeros(); - interrupt::clear(1 << cpu_interrupt_nr); + } else if (cpu_interrupt_mask & CPU_INTERRUPT_EDGE) != 0 { + let cpu_interrupt_mask = cpu_interrupt_mask & CPU_INTERRUPT_EDGE; + let cpu_interrupt_nr = cpu_interrupt_mask.trailing_zeros(); + interrupt::clear(1 << cpu_interrupt_nr); - // for edge interrupts cannot rely on the interrupt status - // register, therefore call all registered - // handlers for current level - let interrupt_levels = - get_configured_interrupts(crate::get_core(), chip_specific::INTERRUPT_EDGE); - let interrupt_mask = interrupt_levels[level as usize]; - let mut interrupt_mask = interrupt_mask & chip_specific::INTERRUPT_EDGE; - loop { - let interrupt_nr = interrupt_mask.trailing_zeros(); - if let Ok(interrupt) = peripherals::Interrupt::try_from(interrupt_nr as u16) { - handle_interrupt(level, interrupt, save_frame) - } else { - break; - } - interrupt_mask &= !(1u128 << interrupt_nr); - } - } else { - // finally check periperal sources and fire of handlers from pac - // peripheral mapped interrupts are cleared by the peripheral - let status = get_status(crate::get_core()); - let interrupt_levels = get_configured_interrupts(crate::get_core(), status); - let interrupt_mask = status & interrupt_levels[level as usize]; + // for edge interrupts cannot rely on the interrupt status + // register, therefore call all registered + // handlers for current level + let interrupt_levels = + get_configured_interrupts(crate::get_core(), chip_specific::INTERRUPT_EDGE); + let interrupt_mask = interrupt_levels[level as usize]; + let mut interrupt_mask = interrupt_mask & chip_specific::INTERRUPT_EDGE; + loop { let interrupt_nr = interrupt_mask.trailing_zeros(); - - // Interrupt::try_from can fail if interrupt already de-asserted: - // silently ignore if let Ok(interrupt) = peripherals::Interrupt::try_from(interrupt_nr as u16) { - handle_interrupt(level, interrupt, save_frame); + handle_interrupt(level, interrupt, save_frame) + } else { + break; } + interrupt_mask &= !(1u128 << interrupt_nr); + } + } else { + // finally check periperal sources and fire of handlers from pac + // peripheral mapped interrupts are cleared by the peripheral + let status = get_status(crate::get_core()); + let interrupt_levels = get_configured_interrupts(crate::get_core(), status); + let interrupt_mask = status & interrupt_levels[level as usize]; + let interrupt_nr = interrupt_mask.trailing_zeros(); + + // Interrupt::try_from can fail if interrupt already de-asserted: + // silently ignore + if let Ok(interrupt) = peripherals::Interrupt::try_from(interrupt_nr as u16) { + handle_interrupt(level, interrupt, save_frame); } } } @@ -441,7 +442,10 @@ mod vectored { } let handler = peripherals::__INTERRUPTS[interrupt.number() as usize]._handler; - if handler as *const _ == EspDefaultHandler as *const unsafe extern "C" fn() { + if core::ptr::eq( + handler as *const _, + EspDefaultHandler as *const unsafe extern "C" fn(), + ) { EspDefaultHandler(level, interrupt); } else { let handler: fn(&mut Context) = core::mem::transmute(handler); @@ -449,6 +453,7 @@ mod vectored { } } + #[allow(clippy::unusual_byte_groupings)] #[cfg(esp32)] mod chip_specific { use super::*; @@ -471,6 +476,7 @@ mod vectored { } } + #[allow(clippy::unusual_byte_groupings)] #[cfg(esp32s2)] mod chip_specific { use super::*; diff --git a/esp-hal/src/lib.rs b/esp-hal/src/lib.rs index 0993bb65e..8d6c168c0 100644 --- a/esp-hal/src/lib.rs +++ b/esp-hal/src/lib.rs @@ -2,43 +2,25 @@ //! Espressif devices. Implements a number of the traits defined by //! [embedded-hal]. //! -//! This crate should not be used directly; you should use one of the -//! device-specific HAL crates instead: -//! -//! - [esp32-hal] -//! - [esp32c2-hal] -//! - [esp32c3-hal] -//! - [esp32c6-hal] -//! - [esp32h2-hal] -//! - [esp32p4-hal] -//! - [esp32s2-hal] -//! - [esp32s3-hal] -//! -//! [embedded-hal]: https://docs.rs/embedded-hal/latest/embedded_hal/ -//! [esp32-hal]: https://github.com/esp-rs/esp-hal/tree/main/esp32-hal -//! [esp32c2-hal]: https://github.com/esp-rs/esp-hal/tree/main/esp32c2-hal -//! [esp32c3-hal]: https://github.com/esp-rs/esp-hal/tree/main/esp32c3-hal -//! [esp32c6-hal]: https://github.com/esp-rs/esp-hal/tree/main/esp32c6-hal -//! [esp32h2-hal]: https://github.com/esp-rs/esp-hal/tree/main/esp32h2-hal -//! [esp32p4-hal]: https://github.com/esp-rs/esp-hal/tree/main/esp32p4-hal -//! [esp32s2-hal]: https://github.com/esp-rs/esp-hal/tree/main/esp32s2-hal -//! [esp32s3-hal]: https://github.com/esp-rs/esp-hal/tree/main/esp32s3-hal - -#![no_std] -#![allow(asm_sub_register)] -#![cfg_attr(xtensa, feature(asm_experimental_arch))] -#![cfg_attr(feature = "async", allow(stable_features, async_fn_in_trait))] +//! ## Feature Flags +#![doc = document_features::document_features!()] #![doc(html_logo_url = "https://avatars.githubusercontent.com/u/46717278")] +#![allow(asm_sub_register)] +#![cfg_attr(feature = "async", allow(stable_features, async_fn_in_trait))] +#![cfg_attr(xtensa, feature(asm_experimental_arch))] +#![no_std] // MUST be the first module mod fmt; -#[cfg(feature = "rt-riscv")] -pub use esp_riscv_rt::{self, entry, riscv}; +#[cfg(all(riscv, feature = "rt"))] +pub use esp_riscv_rt::{self, entry}; pub use procmacros as macros; +#[cfg(riscv)] +pub use riscv; #[cfg(xtensa)] pub use xtensa_lx; -#[cfg(feature = "rt-xtensa")] +#[cfg(all(xtensa, feature = "rt"))] pub use xtensa_lx_rt::{self, entry}; #[cfg(adc)] @@ -99,10 +81,7 @@ pub mod hmac; pub mod i2c; #[cfg(any(i2s0, i2s1))] pub mod i2s; -#[cfg(all( - any(dport, interrupt_core0, interrupt_core1), - any(feature = "rt-riscv", feature = "rt-xtensa") -))] +#[cfg(all(any(dport, interrupt_core0, interrupt_core1), feature = "rt"))] pub mod interrupt; #[cfg(lcd_cam)] pub mod lcd_cam; @@ -151,7 +130,7 @@ pub mod uart; pub mod usb_serial_jtag; /// State of the CPU saved when entering exception or interrupt -#[cfg(any(feature = "rt-riscv", feature = "rt-xtensa"))] +#[cfg(feature = "rt")] pub mod trapframe { #[cfg(riscv)] pub use esp_riscv_rt::TrapFrame; diff --git a/esp-hal/src/prelude.rs b/esp-hal/src/prelude.rs index 21b3a36b5..359a78b9c 100644 --- a/esp-hal/src/prelude.rs +++ b/esp-hal/src/prelude.rs @@ -34,7 +34,7 @@ pub use crate::dma::{ DmaTransfer as _esp_hal_dma_DmaTransfer, DmaTransferRxTx as _esp_hal_dma_DmaTransferRxTx, }; -#[cfg(any(feature = "rt-riscv", feature = "rt-xtensa"))] +#[cfg(feature = "rt")] pub use crate::entry; #[cfg(gpio)] pub use crate::gpio::{ diff --git a/esp-hal/src/soc/esp32/mod.rs b/esp-hal/src/soc/esp32/mod.rs index 8bfef537e..2248cdade 100644 --- a/esp-hal/src/soc/esp32/mod.rs +++ b/esp-hal/src/soc/esp32/mod.rs @@ -33,7 +33,7 @@ pub(crate) mod constants { /// ENTRY point is defined in memory.x /// *Note: the pre_init function is called in the original reset handler /// after the initializations done in this function* -#[cfg(feature = "rt-xtensa")] +#[cfg(feature = "rt")] #[doc(hidden)] #[no_mangle] pub unsafe extern "C" fn ESP32Reset() -> ! { diff --git a/esp-hal/src/soc/esp32c6/lp_core.rs b/esp-hal/src/soc/esp32c6/lp_core.rs index 13ebfe763..d460e329e 100644 --- a/esp-hal/src/soc/esp32c6/lp_core.rs +++ b/esp-hal/src/soc/esp32c6/lp_core.rs @@ -36,7 +36,7 @@ //! let mut lp_pin = io.pins.gpio1.into_low_power(); //! lp_pin.output_enable(true); //! -//! let mut lp_core = esp32c6_hal::lp_core::LpCore::new(peripherals.LP_CORE); +//! let mut lp_core = esp_hal::lp_core::LpCore::new(peripherals.LP_CORE); //! lp_core.stop(); //! println!("lp core stopped"); //! diff --git a/esp-hal/src/soc/esp32s2/mod.rs b/esp-hal/src/soc/esp32s2/mod.rs index 1ac3b106d..e96e6332a 100644 --- a/esp-hal/src/soc/esp32s2/mod.rs +++ b/esp-hal/src/soc/esp32s2/mod.rs @@ -37,7 +37,7 @@ pub(crate) mod constants { /// ENTRY point is defined in memory.x /// *Note: the pre_init function is called in the original reset handler /// after the initializations done in this function* -#[cfg(feature = "rt-xtensa")] +#[cfg(feature = "rt")] #[doc(hidden)] #[no_mangle] pub unsafe extern "C" fn ESP32Reset() -> ! { diff --git a/esp-hal/src/soc/esp32s2/ulp_core.rs b/esp-hal/src/soc/esp32s2/ulp_core.rs index 6586922e2..de2b4ae33 100644 --- a/esp-hal/src/soc/esp32s2/ulp_core.rs +++ b/esp-hal/src/soc/esp32s2/ulp_core.rs @@ -14,7 +14,7 @@ //! //! ## Example //! ```no_run -//! let mut ulp_core = esp32s3_hal::ulp_core::UlpCore::new(peripherals.ULP_RISCV_CORE); +//! let mut ulp_core = esp_hal::ulp_core::UlpCore::new(peripherals.ULP_RISCV_CORE); //! ulp_core.stop(); //! println!("ulp core stopped"); //! @@ -26,7 +26,7 @@ //! println!("copied code (len {})", CODE.len()); //! //! // start ULP core -//! ulp_core.run(esp32s3_hal::ulp_core::UlpCoreWakeupSource::HpCpu); +//! ulp_core.run(esp_hal::ulp_core::UlpCoreWakeupSource::HpCpu); //! println!("ulpcore run"); //! //! unsafe { diff --git a/esp-hal/src/soc/esp32s3/mod.rs b/esp-hal/src/soc/esp32s3/mod.rs index 393379122..cd662fb93 100644 --- a/esp-hal/src/soc/esp32s3/mod.rs +++ b/esp-hal/src/soc/esp32s3/mod.rs @@ -34,7 +34,7 @@ pub(crate) mod constants { pub const SOC_DRAM_HIGH: u32 = 0x3FD0_0000; } -#[cfg(feature = "rt-xtensa")] +#[cfg(feature = "rt")] #[doc(hidden)] #[link_section = ".rwtext"] pub unsafe fn configure_cpu_caches() { @@ -69,7 +69,7 @@ pub unsafe fn configure_cpu_caches() { /// ENTRY point is defined in memory.x /// *Note: the pre_init function is called in the original reset handler /// after the initializations done in this function* -#[cfg(feature = "rt-xtensa")] +#[cfg(feature = "rt")] #[doc(hidden)] #[no_mangle] #[link_section = ".rwtext"] diff --git a/esp-hal/src/soc/esp32s3/ulp_core.rs b/esp-hal/src/soc/esp32s3/ulp_core.rs index dd30779ac..d38ab4456 100644 --- a/esp-hal/src/soc/esp32s3/ulp_core.rs +++ b/esp-hal/src/soc/esp32s3/ulp_core.rs @@ -14,7 +14,7 @@ //! //! ## Example //! ```no_run -//! let mut ulp_core = esp32s3_hal::ulp_core::UlpCore::new(peripherals.ULP_RISCV_CORE); +//! let mut ulp_core = esp_hal::ulp_core::UlpCore::new(peripherals.ULP_RISCV_CORE); //! ulp_core.stop(); //! println!("ulp core stopped"); //! @@ -26,7 +26,7 @@ //! println!("copied code (len {})", CODE.len()); //! //! // start ULP core -//! ulp_core.run(esp32s3_hal::ulp_core::UlpCoreWakeupSource::HpCpu); +//! ulp_core.run(esp_hal::ulp_core::UlpCoreWakeupSource::HpCpu); //! println!("ulpcore run"); //! //! unsafe { diff --git a/esp-lp-hal/Cargo.toml b/esp-lp-hal/Cargo.toml index 9f226f5bb..e0b840571 100644 --- a/esp-lp-hal/Cargo.toml +++ b/esp-lp-hal/Cargo.toml @@ -2,7 +2,7 @@ name = "esp-lp-hal" version = "0.1.0" edition = "2021" -rust-version = "1.67.0" +rust-version = "1.76.0" description = "HAL for low-power RISC-V coprocessors found in ESP32 devices" repository = "https://github.com/esp-rs/esp-hal" license = "MIT OR Apache-2.0" @@ -41,9 +41,9 @@ default = ["embedded-hal-02"] embedded-hal-02 = ["dep:embedded-hal-02"] embedded-hal-1 = ["dep:embedded-hal-1"] -esp32c6 = ["dep:esp32c6-lp", "procmacros/esp32c6-lp", "dep:nb", "dep:paste"] -esp32s2 = ["dep:esp32s2-ulp", "procmacros/esp32s2-ulp"] -esp32s3 = ["dep:esp32s3-ulp", "procmacros/esp32s3-ulp"] +esp32c6 = ["dep:esp32c6-lp", "procmacros/is-lp-core", "dep:nb", "dep:paste"] +esp32s2 = ["dep:esp32s2-ulp", "procmacros/is-ulp-core"] +esp32s3 = ["dep:esp32s3-ulp", "procmacros/is-ulp-core"] debug = [ "esp32c6-lp?/impl-register-debug", diff --git a/esp-lp-hal/examples/i2c.rs b/esp-lp-hal/examples/i2c.rs index 267fe530f..f8cbc15a6 100644 --- a/esp-lp-hal/examples/i2c.rs +++ b/esp-lp-hal/examples/i2c.rs @@ -7,6 +7,8 @@ //! - SDA => GPIO6 //! - SCL => GPIO7 +//% CHIPS: esp32c6 + #![no_std] #![no_main] diff --git a/esp-lp-hal/examples/uart.rs b/esp-lp-hal/examples/uart.rs index 3c6faec49..4e25b8356 100644 --- a/esp-lp-hal/examples/uart.rs +++ b/esp-lp-hal/examples/uart.rs @@ -1,8 +1,12 @@ //! Uses `LP_UART` and logs "Hello World from LP Core". +//! //! Uses GPIO4 for RX and GPIO5 for TX. GPIOs can't be changed. +//! //! It is neccessary to use Serial-Uart bridge connected to TX and RX to see //! logs from LP_UART. Make sure the LP RAM is cleared before loading the code. +//% CHIPS: esp32c6 + #![no_std] #![no_main] diff --git a/esp32-hal/.cargo/config.toml b/esp32-hal/.cargo/config.toml deleted file mode 100644 index 6b35070ac..000000000 --- a/esp32-hal/.cargo/config.toml +++ /dev/null @@ -1,17 +0,0 @@ -[target.xtensa-esp32-none-elf] -runner = "espflash flash --monitor" - -[build] -rustflags = [ - # GNU LD - "-C", "link-arg=-nostartfiles", - "-C", "link-arg=-Wl,-Tlinkall.x", - - # LLD - # "-C", "linker=rust-lld", - # "-C", "link-arg=-Tlinkall.x", -] -target = "xtensa-esp32-none-elf" - -[unstable] -build-std = ["core", "alloc"] diff --git a/esp32-hal/Cargo.toml b/esp32-hal/Cargo.toml deleted file mode 100644 index 668c8b575..000000000 --- a/esp32-hal/Cargo.toml +++ /dev/null @@ -1,164 +0,0 @@ -[package] -name = "esp32-hal" -version = "0.18.0" -edition = "2021" -rust-version = "1.67.0" -description = "HAL for ESP32 microcontrollers" -repository = "https://github.com/esp-rs/esp-hal" -license = "MIT OR Apache-2.0" - -keywords = [ - "embedded", - "embedded-hal", - "esp", - "esp32", - "no-std", -] -categories = [ - "embedded", - "hardware-support", - "no-std", -] - -[dependencies] -document-features = "0.2.7" -esp-hal = { version = "0.15.0", features = ["esp32"], path = "../esp-hal" } -embassy-time-driver = { version = "0.1.0", optional = true } - -[dev-dependencies] -aes = "0.8.3" -critical-section = "1.1.2" -crypto-bigint = { version = "0.5.5", default-features = false } -embassy-executor = { version = "0.5.0", features = ["nightly"] } -embassy-sync = "0.5.0" -embassy-time = "0.3.0" -embedded-graphics = "0.8.1" -embedded-hal-1 = { version = "1.0.0", package = "embedded-hal" } -embedded-hal-async = "1.0.0" -embedded-io-async = "0.6.1" -embedded-hal-bus = "0.1.0" -esp-alloc = "0.3.0" -esp-backtrace = { version = "0.10.0", features = ["esp32", "panic-handler", "exception-handler", "print-uart"] } -esp-hal-smartled = { version = "0.8.0", features = ["esp32"], path = "../esp-hal-smartled" } -esp-println = { version = "0.8.0", features = ["esp32"] } -heapless = "0.8.0" -lis3dh-async = "0.9.1" -sha2 = { version = "0.10.8", default-features = false} -smart-leds = "0.4.0" -ssd1306 = "0.8.4" -static_cell = { version = "2.0.0", features = ["nightly"] } - -[features] -default = ["embassy-integrated-timers", "rt", "vectored"] - -## Enable support for using the Bluetooth radio. -bluetooth = [] -## Enable debug features in the HAL (used for development). -debug = ["esp-hal/debug"] -## Enable logging output using the `log` crate. -log = ["esp-hal/log", "esp-println/log"] -## Enable runtime support. -rt = ["esp-hal/rt-xtensa"] -## Enable interrupt vectoring. -vectored = ["esp-hal/vectored"] - -#! ### Trait Implementation Feature Flags -## Enable support for asynchronous operation, with interfaces provided by -## `embedded-hal-async` and `embedded-io-async`. -async = ["esp-hal/async"] -## Implement `defmt::Format` on certain types. -defmt = ["esp-hal/defmt", "esp-println/defmt-espflash"] -## Implement the traits defined in the `1.0.0` releases of `embedded-hal` and -## `embedded-hal-nb` for the relevant peripherals. -eh1 = ["esp-hal/eh1"] -## Implement the traits defined in `embedded-io` for certain peripherals. -embedded-io = ["esp-hal/embedded-io"] -## Implement the `ufmt_write::uWrite` trait for certain peripherals. -ufmt = ["esp-hal/ufmt"] - -#! ### PSRAM Feature Flags -psram = [] -## Use externally connected PSRAM (2MB). -psram-2m = ["esp-hal/psram-2m", "psram"] -## Use externally connected PSRAM (4MB). -psram-4m = ["esp-hal/psram-4m", "psram"] -## Use externally connected PSRAM (8MB). -psram-8m = ["esp-hal/psram-8m", "psram"] - -#! ### Embassy Feature Flags -## Enable support for `embassy`, a modern asynchronous embedded framework. -embassy = ["esp-hal/embassy"] -## Use the interrupt-mode embassy executor. -embassy-executor-interrupt = ["esp-hal/embassy-executor-interrupt"] -## Use the thread-mode embassy executor. -embassy-executor-thread = ["esp-hal/embassy-executor-thread"] -## Uses hardware timers as alarms for the executors. Using this feature -## limits the number of executors to the number of hardware alarms provided -## by the time driver. -embassy-integrated-timers = ["esp-hal/embassy-integrated-timers"] -## Enable the embassy time driver using the `TIMG0` peripheral. The `TIMG0` -## peripheral has two alarms available for use. -embassy-time-timg0 = ["esp-hal/embassy-time-timg0", "embassy-time-driver/tick-hz-1_000_000"] - -[profile.release] -debug = true - -[[example]] -name = "spi_eh1_loopback" -required-features = ["eh1"] - -[[example]] -name = "spi_eh1_device_loopback" -required-features = ["eh1"] - -[[example]] -name = "embassy_hello_world" -required-features = ["embassy", "embassy-executor-thread"] - -[[example]] -name = "embassy_multicore" -required-features = ["embassy", "embassy-executor-thread"] - -[[example]] -name = "embassy_multicore_interrupt" -required-features = ["embassy", "embassy-executor-interrupt"] - -[[example]] -name = "embassy_multiprio" -required-features = ["embassy", "embassy-executor-interrupt"] - -[[example]] -name = "embassy_wait" -required-features = ["embassy", "embassy-executor-thread", "async"] - -[[example]] -name = "embassy_spi" -required-features = ["embassy", "embassy-executor-thread", "async"] - -[[example]] -name = "psram" -required-features = ["psram-2m"] - -[[example]] -name = "embassy_serial" -required-features = ["embassy", "embassy-executor-thread", "async"] - -[[example]] -name = "embassy_i2c" -required-features = ["embassy", "embassy-executor-thread", "async"] - -[[example]] -name = "embassy_rmt_tx" -required-features = ["embassy", "async"] - -[[example]] -name = "embassy_rmt_rx" -required-features = ["embassy", "async"] - -[[example]] -name = "embassy_i2s_sound" -required-features = ["embassy", "async"] - -[[example]] -name = "embassy_i2s_read" -required-features = ["embassy", "async"] diff --git a/esp32-hal/README.md b/esp32-hal/README.md deleted file mode 100644 index 60c79a027..000000000 --- a/esp32-hal/README.md +++ /dev/null @@ -1,60 +0,0 @@ -# esp32-hal - -[![Crates.io](https://img.shields.io/crates/v/esp32-hal?labelColor=1C2C2E&color=C96329&logo=Rust&style=flat-square)](https://crates.io/crates/esp32-hal) -[![docs.rs](https://img.shields.io/docsrs/esp32-hal?labelColor=1C2C2E&color=C96329&logo=rust&style=flat-square)](https://docs.rs/esp32-hal) -![Crates.io](https://img.shields.io/crates/l/esp32-hal?labelColor=1C2C2E&style=flat-square) -[![Matrix](https://img.shields.io/matrix/esp-rs:matrix.org?label=join%20matrix&labelColor=1C2C2E&color=BEC5C9&logo=matrix&style=flat-square)](https://matrix.to/#/#esp-rs:matrix.org) - -`no_std` HAL for the ESP32 from Espressif. - -Implements a number of the traits defined in [embedded-hal](https://github.com/rust-embedded/embedded-hal). - -This device uses the Xtensa ISA, which is not officially supported by the Rust compiler. In order to develop for this device, you must use the Rust compiler fork with Xtensa support, found at [esp-rs/rust](https://github.com/esp-rs/rust). - -Please refer to the documentation for more information. - -## [Documentation] - -[documentation]: https://docs.rs/esp32-hal/ - -## Resources - -- [Datasheet](https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf) -- [Technical Reference Manual](https://www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf) -- [The Rust Programming Language](https://doc.rust-lang.org/book/) -- [The Embedded Rust Book](https://docs.rust-embedded.org/book/index.html) -- [The Rust on ESP Book](https://esp-rs.github.io/book/) - -## Getting Started - -### Installing the Rust Compiler - -We provide a tool, [espup](https://github.com/esp-rs/espup/), for easily installing the Rust toolchain with Xtensa support: - -```shell -cargo install espup -espup install -``` - -Following installation of the Xtensa toolchain, if you are running a Unix-like operating system (macOS, Linux) then you must additionally export the necessary environment variables: - -```shell -. $HOME/export-esp.sh -``` - -See the [Installation chapter of The Rust on ESP Book](https://esp-rs.github.io/book/installation/index.html) for more details. - -## License - -Licensed under either of: - -- Apache License, Version 2.0 ([LICENSE-APACHE](../LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) -- MIT license ([LICENSE-MIT](../LICENSE-MIT) or http://opensource.org/licenses/MIT) - -at your option. - -### Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in -the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without -any additional terms or conditions. diff --git a/esp32-hal/build.rs b/esp32-hal/build.rs deleted file mode 100644 index 5b96f6a64..000000000 --- a/esp32-hal/build.rs +++ /dev/null @@ -1,36 +0,0 @@ -use std::{env, error::Error, fs::File, io::Write, path::PathBuf}; - -fn main() -> Result<(), Box> { - // Put the linker script somewhere the linker can find it - let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - println!("cargo:rustc-link-search={}", out.display()); - - let memory_extras = generate_memory_extras(); - File::create(out.join("memory_extras.x"))?.write_all(&memory_extras)?; - - // Only re-run the build script when memory.x is changed, - // instead of when any part of the source code changes. - println!("cargo:rerun-if-changed=ld/memory.x"); - - #[cfg(feature = "defmt")] - println!("cargo:rustc-link-arg=-Tdefmt.x"); - - Ok(()) -} - -fn generate_memory_extras() -> Vec { - let reserve_dram = if cfg!(feature = "bluetooth") { - "0x10000" - } else { - "0x0" - }; - - format!( - " - /* reserved at the start of DRAM for e.g. the BT stack */ - RESERVE_DRAM = {reserve_dram}; - " - ) - .as_bytes() - .to_vec() -} diff --git a/esp32-hal/examples/adc.rs b/esp32-hal/examples/adc.rs deleted file mode 100644 index b1e83647a..000000000 --- a/esp32-hal/examples/adc.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! Connect a potentiometer to PIN25 and see the read values change when -//! rotating the shaft. Alternatively you could also connect the PIN to GND or -//! 3V3 to see the maximum and minimum raw values read. - -#![no_std] -#![no_main] - -use esp32_hal::{ - adc::{AdcConfig, Attenuation, ADC}, - clock::ClockControl, - gpio::IO, - peripherals::{Peripherals, ADC2}, - prelude::*, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create ADC instances - let mut adc2_config = AdcConfig::new(); - let mut pin25 = - adc2_config.enable_pin(io.pins.gpio25.into_analog(), Attenuation::Attenuation11dB); - let mut adc2 = ADC::::new(peripherals.ADC2, adc2_config); - - let mut delay = Delay::new(&clocks); - - loop { - let pin25_value: u16 = nb::block!(adc2.read(&mut pin25)).unwrap(); - println!("PIN25 ADC reading = {}", pin25_value); - delay.delay_ms(1500u32); - } -} diff --git a/esp32-hal/examples/advanced_serial.rs b/esp32-hal/examples/advanced_serial.rs deleted file mode 100644 index bc7ad7e09..000000000 --- a/esp32-hal/examples/advanced_serial.rs +++ /dev/null @@ -1,64 +0,0 @@ -//! This shows how to configure UART -//! You can short the TX and RX pin and see it reads what was written. -//! Additionally you can connect a logic analzyer to TX and see how the changes -//! of the configuration change the output signal. -//! -//! The following wiring is assumed: -//! - TX => GPIO16 -//! - RX => GPIO17 - -#![no_std] -#![no_main] - -use esp32_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - uart::{ - config::{Config, DataBits, Parity, StopBits}, - TxRxPins, - }, - Delay, - Uart, -}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let config = Config { - baudrate: 115200, - data_bits: DataBits::DataBits8, - parity: Parity::ParityNone, - stop_bits: StopBits::STOP1, - }; - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let pins = TxRxPins::new_tx_rx( - io.pins.gpio16.into_push_pull_output(), - io.pins.gpio17.into_floating_input(), - ); - - let mut serial1 = Uart::new_with_config(peripherals.UART1, config, Some(pins), &clocks); - - let mut delay = Delay::new(&clocks); - - println!("Start"); - loop { - serial1.write(0x42).ok(); - let read = block!(serial1.read()); - - match read { - Ok(read) => println!("Read 0x{:02x}", read), - Err(err) => println!("Error {:?}", err), - } - - delay.delay_ms(250u32); - } -} diff --git a/esp32-hal/examples/aes.rs b/esp32-hal/examples/aes.rs deleted file mode 100644 index 849157864..000000000 --- a/esp32-hal/examples/aes.rs +++ /dev/null @@ -1,85 +0,0 @@ -//! Encrypt/Decrypt a message using AES - -#![no_std] -#![no_main] -use aes::{ - cipher::{generic_array::GenericArray, BlockDecrypt, BlockEncrypt, KeyInit}, - Aes128 as Aes128SW, -}; -use esp32_hal::{ - aes::{Aes, Mode}, - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - xtensa_lx, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut aes = Aes::new(peripherals.AES); - - let keytext = "SUp4SeCp@sSw0rd".as_bytes(); - let plaintext = "message".as_bytes(); - - // create an array with aes128 key size - let mut keybuf = [0_u8; 16]; - keybuf[..keytext.len()].copy_from_slice(keytext); - - // create an array with aes block size - let mut block_buf = [0_u8; 16]; - block_buf[..plaintext.len()].copy_from_slice(plaintext); - - let mut block = block_buf.clone(); - let pre_hw_encrypt = xtensa_lx::timer::get_cycle_count(); - aes.process(&mut block, Mode::Encryption128, &keybuf); - let post_hw_encrypt = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for hw encrypt", - post_hw_encrypt - pre_hw_encrypt - ); - let hw_encrypted = block.clone(); - let pre_hw_decrypt = xtensa_lx::timer::get_cycle_count(); - aes.process(&mut block, Mode::Decryption128, &keybuf); - let post_hw_decrypt = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for hw decrypt", - post_hw_decrypt - pre_hw_decrypt - ); - let hw_decrypted = block; - - let key = GenericArray::from(keybuf); - let mut block = GenericArray::from(block_buf); - let cipher = Aes128SW::new(&key); - let pre_sw_encrypt = xtensa_lx::timer::get_cycle_count(); - cipher.encrypt_block(&mut block); - let post_sw_encrypt = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for sw encrypt", - post_sw_encrypt - pre_sw_encrypt - ); - let sw_encrypted = block.clone(); - let pre_sw_decrypt = xtensa_lx::timer::get_cycle_count(); - cipher.decrypt_block(&mut block); - let post_sw_decrypt = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for sw decrypt", - post_sw_decrypt - pre_sw_decrypt - ); - let sw_decrypted = block; - - assert!(eq(&sw_encrypted.into(), &hw_encrypted)); - assert!(eq(&sw_decrypted.into(), &hw_decrypted)); - - println!("done"); - - loop {} -} -fn eq(slice1: &[u8; 16], slice2: &[u8; 16]) -> bool { - slice1.iter().zip(slice2.iter()).all(|(a, b)| a == b) -} diff --git a/esp32-hal/examples/blinky.rs b/esp32-hal/examples/blinky.rs deleted file mode 100644 index cf705f082..000000000 --- a/esp32-hal/examples/blinky.rs +++ /dev/null @@ -1,32 +0,0 @@ -//! Blinks an LED -//! -//! This assumes that a LED is connected to the pin assigned to `led` (GPIO2). -//! For the the DOIT ESP32 Devkit v1, GPIO2 is the onboard LED pin. - -#![no_std] -#![no_main] - -use esp32_hal::{clock::ClockControl, gpio::IO, peripherals::Peripherals, prelude::*, Delay}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Set GPIO2 as an output, and set its state high initially. - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut led = io.pins.gpio2.into_push_pull_output(); - - led.set_high().unwrap(); - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - loop { - led.toggle().unwrap(); - delay.delay_ms(500u32); - } -} diff --git a/esp32-hal/examples/blinky_erased_pins.rs b/esp32-hal/examples/blinky_erased_pins.rs deleted file mode 100644 index e02d40c1d..000000000 --- a/esp32-hal/examples/blinky_erased_pins.rs +++ /dev/null @@ -1,53 +0,0 @@ -//! Blinks three LEDs -//! -//! This assumes that LEDs are connected to GPIO25, 26 and 27. - -#![no_std] -#![no_main] - -use esp32_hal::{ - clock::ClockControl, - gpio::{AnyPin, Input, Output, PullDown, PushPull, IO}, - peripherals::Peripherals, - prelude::*, - Delay, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Set LED GPIOs as an output. - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let led1 = io.pins.gpio25.into_push_pull_output(); - let led2 = io.pins.gpio26.into_push_pull_output(); - let led3 = io.pins.gpio27.into_push_pull_output(); - - // Set GPIO9 as an input. - let button = io.pins.gpio0.into_pull_down_input().into(); - - // You can use `into` or `degrade` - let mut pins = [led1.into(), led2.into(), led3.degrade().into()]; - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - loop { - toggle_pins(&mut pins, &button); - delay.delay_ms(500u32); - } -} - -fn toggle_pins(leds: &mut [AnyPin>], button: &AnyPin>) { - for pin in leds.iter_mut() { - pin.toggle().unwrap(); - } - - if button.is_low().unwrap() { - esp_println::println!("Button"); - } -} diff --git a/esp32-hal/examples/clock_monitor.rs b/esp32-hal/examples/clock_monitor.rs deleted file mode 100644 index 931cfa31e..000000000 --- a/esp32-hal/examples/clock_monitor.rs +++ /dev/null @@ -1,63 +0,0 @@ -//! This demos a simple monitor for the XTAL frequency, by relying on a special -//! feature of the TIMG0 (Timer Group 0). This feature counts the number of XTAL -//! clock cycles within a given number of RTC_SLOW_CLK cycles. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, - Rtc, -}; -use esp_backtrace as _; - -static RTC: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rtc = Rtc::new(peripherals.LPWR); - rtc.rwdt.start(2000u64.millis()); - rtc.rwdt.listen(); - - esp_println::println!( - "{: <10} XTAL frequency: {} MHz", - "[Expected]", - clocks.xtal_clock.to_MHz() - ); - - interrupt::enable( - peripherals::Interrupt::RTC_CORE, - interrupt::Priority::Priority1, - ) - .unwrap(); - - critical_section::with(|cs| RTC.borrow_ref_mut(cs).replace(rtc)); - - loop {} -} - -#[interrupt] -fn RTC_CORE() { - critical_section::with(|cs| { - let mut rtc = RTC.borrow_ref_mut(cs); - let rtc = rtc.as_mut().unwrap(); - - esp_println::println!( - "{: <10} XTAL frequency: {} MHz", - "[Monitor]", - rtc.estimate_xtal_frequency() - ); - - rtc.rwdt.clear_interrupt(); - }); -} diff --git a/esp32-hal/examples/crc.rs b/esp32-hal/examples/crc.rs deleted file mode 100644 index 0ebce485a..000000000 --- a/esp32-hal/examples/crc.rs +++ /dev/null @@ -1,96 +0,0 @@ -//! This shows example usage of the CRC functions in ROM - -#![no_std] -#![no_main] - -use core::fmt::Write; - -use esp32_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - rom::{crc, md5}, - timer::TimerGroup, - Uart, -}; -use esp_backtrace as _; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - - timer0.start(1u64.secs()); - - let data = "123456789"; - let sentence = "The quick brown fox jumps over a lazy dog"; - - writeln!( - uart0, - "Performing CRC calculations on test string \"{data}\"" - ) - .unwrap(); - - loop { - let crc_hdlc = crc::crc32_le(!0xffffffff, data.as_ref()); - let crc_bzip2 = crc::crc32_be(!0xffffffff, data.as_ref()); - let crc_mpeg2 = !crc::crc32_be(!0xffffffff, data.as_ref()); - let crc_cksum = crc::crc32_be(!0, data.as_ref()); - let crc_kermit = !crc::crc16_le(!0, data.as_ref()); - let crc_genibus = crc::crc16_be(!0xffff, data.as_ref()); - let crc_rohc = !crc::crc8_le(!0xff, data.as_ref()); - let crc_smbus = !crc::crc8_be(!0, data.as_ref()); - - assert_eq!(crc_hdlc, 0xcbf43926); - assert_eq!(crc_bzip2, 0xfc891918); - assert_eq!(crc_mpeg2, 0x0376e6e7); - assert_eq!(crc_cksum, 0x765e7680); - assert_eq!(crc_kermit, 0x2189); - assert_eq!(crc_genibus, 0xd64e); - assert_eq!(crc_rohc, 0xd0); - assert_eq!(crc_smbus, 0xf4); - - // Hash the sentence one word at a time to *really* test the context - // Use Peekable while iter_intersperse is unstable - let mut md5_ctx = md5::Context::new(); - let mut it = sentence.split_whitespace().peekable(); - while let Some(word) = it.next() { - md5_ctx.consume(word); - if it.peek().is_some() { - md5_ctx.consume(" "); - } - } - let md5_digest = md5_ctx.compute(); - - assert_eq!( - md5_digest, - md5::Digest([ - 0x30, 0xde, 0xd8, 0x07, 0xd6, 0x5e, 0xe0, 0x37, 0x0f, 0xc6, 0xd7, 0x3d, 0x6a, 0xb5, - 0x5a, 0x95 - ]) - ); - - writeln!( - uart0, - "{:08x} {:08x} {:08x} {:08x} {:04x} {:04x} {:02x} {:02x} {}", - crc_hdlc, - crc_bzip2, - crc_mpeg2, - crc_cksum, - crc_kermit, - crc_genibus, - crc_rohc, - crc_smbus, - md5_digest - ) - .unwrap(); - - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32-hal/examples/dac.rs b/esp32-hal/examples/dac.rs deleted file mode 100644 index 71825ac69..000000000 --- a/esp32-hal/examples/dac.rs +++ /dev/null @@ -1,45 +0,0 @@ -//! This example shows how to use the DAC on PIN 25 and 26 -//! You can connect an LED (with a suitable resistor) or check the changing -//! voltage using a voltmeter on those pins. - -#![no_std] -#![no_main] - -use esp32_hal::{ - clock::ClockControl, - dac::{DAC1, DAC2}, - gpio::IO, - peripherals::Peripherals, - prelude::*, - Delay, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let pin25 = io.pins.gpio25.into_analog(); - let pin26 = io.pins.gpio26.into_analog(); - - // Create DAC instances - let mut dac1 = DAC1::new(peripherals.DAC1, pin25); - let mut dac2 = DAC2::new(peripherals.DAC2, pin26); - - let mut delay = Delay::new(&clocks); - - let mut voltage_dac1: u8 = 200; - let mut voltage_dac2: u8 = 255; - loop { - // Change voltage on the pins using write function - voltage_dac1 = voltage_dac1.wrapping_add(1); - dac1.write(voltage_dac1); - - voltage_dac2 = voltage_dac2.wrapping_sub(1); - dac2.write(voltage_dac2); - delay.delay_ms(50u32); - } -} diff --git a/esp32-hal/examples/embassy_i2s_read.rs b/esp32-hal/examples/embassy_i2s_read.rs deleted file mode 100644 index d14904647..000000000 --- a/esp32-hal/examples/embassy_i2s_read.rs +++ /dev/null @@ -1,89 +0,0 @@ -//! This shows how to continously receive data via I2S -//! -//! Pins used -//! BCLK GPIO12 -//! WS GPIO13 -//! DIN GPIO14 -//! -//! Without an additional I2S source device you can connect 3V3 or GND to DIN to -//! read 0 or 0xFF or connect DIN to WS to read two different values -//! -//! You can also inspect the BCLK and WS with a logic analyzer - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use esp32_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - embassy::{self}, - i2s::{asynch::*, DataFormat, I2s, Standard}, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -#[main] -async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.i2s0channel; - - let (_, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(0, 4092 * 4); - - let i2s = I2s::new( - peripherals.I2S0, - Standard::Philips, - DataFormat::Data16Channel16, - 44100u32.Hz(), - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - &clocks, - ); - - let i2s_rx = i2s - .i2s_rx - .with_bclk(io.pins.gpio12) - .with_ws(io.pins.gpio13) - .with_din(io.pins.gpio14) - .build(); - - let buffer = rx_buffer; - println!("Start"); - - let mut data = [0u8; 5000]; - let mut transaction = i2s_rx.read_dma_circular_async(buffer).unwrap(); - loop { - let avail = transaction.available().await; - println!("available {}", avail); - - let count = transaction.pop(&mut data).await.unwrap(); - println!( - "got {} bytes, {:x?}..{:x?}", - count, - &data[..10], - &data[count - 10..count] - ); - } -} diff --git a/esp32-hal/examples/embassy_i2s_sound.rs b/esp32-hal/examples/embassy_i2s_sound.rs deleted file mode 100644 index b84233ec8..000000000 --- a/esp32-hal/examples/embassy_i2s_sound.rs +++ /dev/null @@ -1,127 +0,0 @@ -//! This shows how to transmit data continously via I2S -//! -//! Pins used -//! BCLK GPIO12 -//! WS GPIO13 -//! DOUT GPIO14 -//! -//! Without an additional I2S sink device you can inspect the MCLK, BCLK, WS and -//! DOUT with a logic analyzer -//! -//! You can also connect e.g. a PCM510x to hear an annoying loud sine tone (full -//! scale), so turn down the volume before running this example. -//! -//! Wiring is like this -//! -//! | Pin | Connected to | -//! |-------|-----------------| -//! | BCK | GPIO12 | -//! | DIN | GPIO14 | -//! | LRCK | GPIO13 | -//! | SCK | Gnd | -//! | GND | Gnd | -//! | VIN | +3V3 | -//! | FLT | Gnd | -//! | FMT | Gnd | -//! | DEMP | Gnd | -//! | XSMT | +3V3 | - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use esp32_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - embassy::{self}, - i2s::{asynch::*, DataFormat, I2s, Standard}, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -const SINE: [i16; 64] = [ - 0, 3211, 6392, 9511, 12539, 15446, 18204, 20787, 23169, 25329, 27244, 28897, 30272, 31356, - 32137, 32609, 32767, 32609, 32137, 31356, 30272, 28897, 27244, 25329, 23169, 20787, 18204, - 15446, 12539, 9511, 6392, 3211, 0, -3211, -6392, -9511, -12539, -15446, -18204, -20787, -23169, - -25329, -27244, -28897, -30272, -31356, -32137, -32609, -32767, -32609, -32137, -31356, -30272, - -28897, -27244, -25329, -23169, -20787, -18204, -15446, -12539, -9511, -6392, -3211, -]; - -#[main] -async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.i2s0channel; - - let (tx_buffer, mut tx_descriptors, _, mut rx_descriptors) = dma_buffers!(32000, 0); - - let i2s = I2s::new( - peripherals.I2S0, - Standard::Philips, - DataFormat::Data16Channel16, - 44100u32.Hz(), - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - &clocks, - ); - - let i2s_tx = i2s - .i2s_tx - .with_bclk(io.pins.gpio12) - .with_ws(io.pins.gpio13) - .with_dout(io.pins.gpio14) - .build(); - - let data = - unsafe { core::slice::from_raw_parts(&SINE as *const _ as *const u8, SINE.len() * 2) }; - - let buffer = tx_buffer; - let mut idx = 0; - for i in 0..usize::min(data.len(), buffer.len()) { - buffer[i] = data[idx]; - - idx += 1; - - if idx >= data.len() { - idx = 0; - } - } - - let mut filler = [0u8; 10000]; - let mut idx = 32000 % data.len(); - - println!("Start"); - let mut transaction = i2s_tx.write_dma_circular_async(buffer).unwrap(); - - loop { - for i in 0..filler.len() { - filler[i] = data[(idx + i) % data.len()]; - } - println!("Next"); - - let written = transaction.push(&filler).await.unwrap(); - idx = (idx + written) % data.len(); - println!("written {}", written); - } -} diff --git a/esp32-hal/examples/embassy_multiprio.rs b/esp32-hal/examples/embassy_multiprio.rs deleted file mode 100644 index 7528122f0..000000000 --- a/esp32-hal/examples/embassy_multiprio.rs +++ /dev/null @@ -1,91 +0,0 @@ -//! This example shows how to use the interrupt executors to prioritize some -//! tasks over others. -//! -//! The example creates three tasks: -//! - A low priority task that is not actually async, but simulates some -//! blocking work. This task will run for 5 seconds, then sleep for 5 -//! seconds. -//! - A low priority task that is actually async, but will not be able to run -//! while the blocking task is running. -//! - A high priority task that prints something every second. The example -//! demonstrates that this task will continue to run even while the low -//! priority blocking task is running. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Instant, Ticker, Timer}; -use esp32_hal::{ - clock::ClockControl, - embassy::{ - self, - executor::{FromCpu1, InterruptExecutor}, - }, - interrupt::Priority, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; -use esp_println::println; - -static INT_EXECUTOR_0: InterruptExecutor = InterruptExecutor::new(); - -#[interrupt] -fn FROM_CPU_INTR1() { - unsafe { INT_EXECUTOR_0.on_interrupt() } -} - -/// Periodically print something. -#[embassy_executor::task] -async fn high_prio() { - println!("Starting high_prio()"); - let mut ticker = Ticker::every(Duration::from_secs(1)); - loop { - println!("High priority ticks"); - ticker.next().await; - } -} - -/// Simulates some blocking (badly behaving) task. -#[embassy_executor::task] -async fn low_prio_blocking() { - println!("Starting low-priority task that isn't actually async"); - loop { - println!("Doing some long and complicated calculation"); - let start = Instant::now(); - while start.elapsed() < Duration::from_secs(5) {} - println!("Calculation finished"); - Timer::after(Duration::from_secs(5)).await; - } -} - -/// A well-behaved, but starved async task. -#[embassy_executor::task] -async fn low_prio_async() { - println!("Starting low-priority task that will not be able to run while the blocking task is running"); - let mut ticker = Ticker::every(Duration::from_secs(1)); - loop { - println!("Low priority ticks"); - ticker.next().await; - } -} - -#[main] -async fn main(low_prio_spawner: Spawner) { - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = esp32_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - - let spawner = INT_EXECUTOR_0.start(Priority::Priority2); - spawner.must_spawn(high_prio()); - - println!("Spawning low-priority tasks"); - low_prio_spawner.must_spawn(low_prio_async()); - low_prio_spawner.must_spawn(low_prio_blocking()); -} diff --git a/esp32-hal/examples/embassy_rmt_rx.rs b/esp32-hal/examples/embassy_rmt_rx.rs deleted file mode 100644 index ac13f3b98..000000000 --- a/esp32-hal/examples/embassy_rmt_rx.rs +++ /dev/null @@ -1,121 +0,0 @@ -//! Demonstrates decoding pulse sequences with RMT -//! Connect GPIO15 to GPIO4 - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32_hal::{ - clock::ClockControl, - embassy::{self}, - gpio::{Gpio15, Output, PushPull}, - peripherals::Peripherals, - prelude::*, - rmt::{asynch::RxChannelAsync, PulseCode, RxChannelConfig, RxChannelCreator}, - Rmt, - IO, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -const WIDTH: usize = 80; - -#[cfg(debug_assertions)] -compile_error!("Run this example in release mode"); - -#[embassy_executor::task] -async fn signal_task(mut pin: Gpio15>) { - loop { - for _ in 0..10 { - pin.toggle().unwrap(); - Timer::after(Duration::from_micros(10)).await; - } - Timer::after(Duration::from_millis(1000)).await; - } -} - -#[main] -async fn main(spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let rmt = Rmt::new(peripherals.RMT, 80u32.MHz(), &clocks).unwrap(); - - let mut channel = rmt - .channel2 - .configure( - io.pins.gpio4, - RxChannelConfig { - clk_divider: 1, - idle_threshold: 0b111_1111_1111_1111, - ..RxChannelConfig::default() - }, - ) - .unwrap(); - - spawner - .spawn(signal_task(io.pins.gpio15.into_push_pull_output())) - .unwrap(); - - let mut data = [PulseCode { - level1: true, - length1: 1, - level2: false, - length2: 1, - }; 48]; - - loop { - println!("receive"); - channel.receive(&mut data).await.unwrap(); - let mut total = 0usize; - for entry in &data[..data.len()] { - if entry.length1 == 0 { - break; - } - total += entry.length1 as usize; - - if entry.length2 == 0 { - break; - } - total += entry.length2 as usize; - } - - for entry in &data[..data.len()] { - if entry.length1 == 0 { - break; - } - - let count = WIDTH / (total / entry.length1 as usize); - let c = if entry.level1 { '-' } else { '_' }; - for _ in 0..count + 1 { - print!("{}", c); - } - - if entry.length2 == 0 { - break; - } - - let count = WIDTH / (total / entry.length2 as usize); - let c = if entry.level2 { '-' } else { '_' }; - for _ in 0..count + 1 { - print!("{}", c); - } - } - - println!(); - } -} diff --git a/esp32-hal/examples/embassy_rmt_tx.rs b/esp32-hal/examples/embassy_rmt_tx.rs deleted file mode 100644 index 366b42dc6..000000000 --- a/esp32-hal/examples/embassy_rmt_tx.rs +++ /dev/null @@ -1,73 +0,0 @@ -//! Demonstrates generating pulse sequences with RMT -//! Connect a logic analyzer to GPIO4 to see the generated pulses. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32_hal::{ - clock::ClockControl, - embassy::{self}, - peripherals::Peripherals, - prelude::*, - rmt::{asynch::TxChannelAsync, PulseCode, TxChannelConfig, TxChannelCreator}, - Rmt, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -#[main] -async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let rmt = Rmt::new(peripherals.RMT, 80u32.MHz(), &clocks).unwrap(); - - let mut channel = rmt - .channel0 - .configure( - io.pins.gpio4.into_push_pull_output(), - TxChannelConfig { - clk_divider: 255, - ..TxChannelConfig::default() - }, - ) - .unwrap(); - - let mut data = [PulseCode { - level1: true, - length1: 200, - level2: false, - length2: 50, - }; 20]; - - data[data.len() - 2] = PulseCode { - level1: true, - length1: 3000, - level2: false, - length2: 500, - }; - data[data.len() - 1] = PulseCode::default(); - - loop { - println!("transmit"); - channel.transmit(&data).await.unwrap(); - println!("transmitted\n"); - Timer::after(Duration::from_millis(500)).await; - } -} diff --git a/esp32-hal/examples/gpio_interrupt.rs b/esp32-hal/examples/gpio_interrupt.rs deleted file mode 100644 index e870a8a0b..000000000 --- a/esp32-hal/examples/gpio_interrupt.rs +++ /dev/null @@ -1,70 +0,0 @@ -//! GPIO interrupt -//! -//! This prints "Interrupt" when the boot button is pressed. -//! It also blinks an LED like the blinky example. - -#![no_std] -#![no_main] - -use core::{borrow::BorrowMut, cell::RefCell}; - -use critical_section::Mutex; -use esp32_hal::{ - clock::ClockControl, - gpio::{Event, Gpio0, Input, PullDown, IO}, - interrupt, - macros::ram, - peripherals::{self, Peripherals}, - prelude::*, - xtensa_lx, - Delay, -}; -use esp_backtrace as _; - -static BUTTON: Mutex>>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Set GPIO15 as an output, and set its state high initially. - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut led = io.pins.gpio15.into_push_pull_output(); - let mut button = io.pins.gpio0.into_pull_down_input(); - button.listen(Event::FallingEdge); - - critical_section::with(|cs| BUTTON.borrow_ref_mut(cs).replace(button)); - - interrupt::enable(peripherals::Interrupt::GPIO, interrupt::Priority::Priority2).unwrap(); - - led.set_high().unwrap(); - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - loop { - led.toggle().unwrap(); - delay.delay_ms(500u32); - } -} - -#[ram] -#[interrupt] -unsafe fn GPIO() { - esp_println::println!( - "GPIO Interrupt with priority {}", - xtensa_lx::interrupt::get_level() - ); - - critical_section::with(|cs| { - BUTTON - .borrow_ref_mut(cs) - .borrow_mut() - .as_mut() - .unwrap() - .clear_interrupt(); - }); -} diff --git a/esp32-hal/examples/hello_rgb.rs b/esp32-hal/examples/hello_rgb.rs deleted file mode 100644 index f657c7234..000000000 --- a/esp32-hal/examples/hello_rgb.rs +++ /dev/null @@ -1,75 +0,0 @@ -//! RGB LED Demo -//! -//! This example drives an 12-element RGB ring that is connected to GPIO33 -//! -//! The LEDs in the ring are transitioning though the HSV color spectrum for -//! - Saturation: 255 -//! - Hue: 0 - 255 -//! - Value: 255 -//! -//! For the 12-element RGB ring to work, building the release version is going -//! to be required. - -#![no_std] -#![no_main] - -use esp32_hal::{clock::ClockControl, peripherals, prelude::*, rmt::Rmt, Delay, IO}; -use esp_backtrace as _; -use esp_hal_smartled::{smartLedBuffer, SmartLedsAdapter}; -use smart_leds::{ - brightness, - gamma, - hsv::{hsv2rgb, Hsv}, - SmartLedsWrite, -}; - -#[entry] -fn main() -> ! { - let peripherals = peripherals::Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Configure RMT peripheral globally - let rmt = Rmt::new(peripherals.RMT, 80u32.MHz(), &clocks).unwrap(); - - // We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can - // be used directly with all `smart_led` implementations - // -> We need to use the macro `smartLedBuffer!` with the number of addressed - // LEDs here to initialize the internal LED pulse buffer to the correct - // size! - let rmt_buffer = smartLedBuffer!(12); - let mut led = SmartLedsAdapter::new(rmt.channel0, io.pins.gpio33, rmt_buffer, &clocks); - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - let mut color = Hsv { - hue: 0, - sat: 255, - val: 255, - }; - let mut data; - - loop { - // Iterate over the rainbow! - for hue in 0..=255 { - color.hue = hue; - // Convert from the HSV color space (where we can easily transition from one - // color to the other) to the RGB color space that we can then send to the LED - let rgb_color = hsv2rgb(color); - - // Assign new color to all 12 LEDs - data = [rgb_color; 12]; - - // When sending to the LED, we do a gamma correction first (see smart_leds - // documentation for details) and then limit the brightness to 10 out of 255 so - // that the output it's not too bright. - led.write(brightness(gamma(data.iter().cloned()), 10)) - .unwrap(); - delay.delay_ms(20u8); - } - } -} diff --git a/esp32-hal/examples/hello_world.rs b/esp32-hal/examples/hello_world.rs deleted file mode 100644 index 46b62fb8c..000000000 --- a/esp32-hal/examples/hello_world.rs +++ /dev/null @@ -1,35 +0,0 @@ -//! This shows how to write text to uart0. -//! You can see the output with `espflash` if you provide the `--monitor` option - -#![no_std] -#![no_main] - -use core::fmt::Write; - -use esp32_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, - Uart, -}; -use esp_backtrace as _; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - - timer0.start(1u64.secs()); - - loop { - writeln!(uart0, "Hello world!").unwrap(); - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32-hal/examples/i2c_bmp180_calibration_data.rs b/esp32-hal/examples/i2c_bmp180_calibration_data.rs deleted file mode 100644 index c265c2a1c..000000000 --- a/esp32-hal/examples/i2c_bmp180_calibration_data.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! Read calibration data from BMP180 sensor -//! -//! This example dumps the calibration data from a BMP180 sensor -//! -//! The following wiring is assumed: -//! - SDA => GPIO32 -//! - SCL => GPIO33 - -#![no_std] -#![no_main] - -use esp32_hal::{clock::ClockControl, gpio::IO, i2c::I2C, peripherals::Peripherals, prelude::*}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create a new peripheral object with the described wiring - // and standard I2C clock speed - let mut i2c = I2C::new( - peripherals.I2C0, - io.pins.gpio32, - io.pins.gpio33, - 100u32.kHz(), - &clocks, - ); - - loop { - let mut data = [0u8; 22]; - i2c.write_read(0x77, &[0xaa], &mut data).ok(); - - println!("{:02x?}", data); - } -} diff --git a/esp32-hal/examples/i2c_display.rs b/esp32-hal/examples/i2c_display.rs deleted file mode 100644 index 8dc8236f7..000000000 --- a/esp32-hal/examples/i2c_display.rs +++ /dev/null @@ -1,121 +0,0 @@ -//! I2C Display example -//! -//! This example prints some text on an SSD1306-based -//! display (via I2C) -//! -//! The following wiring is assumed: -//! - SDA => GPIO32 -//! - SCL => GPIO33 - -#![no_std] -#![no_main] - -use embedded_graphics::{ - mono_font::{ - ascii::{FONT_6X10, FONT_9X18_BOLD}, - MonoTextStyleBuilder, - }, - pixelcolor::BinaryColor, - prelude::*, - text::{Alignment, Text}, -}; -use esp32_hal::{ - clock::ClockControl, - gpio::IO, - i2c::I2C, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, -}; -use esp_backtrace as _; -use nb::block; -use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create a new peripheral object with the described wiring - // and standard I2C clock speed - let i2c = I2C::new( - peripherals.I2C0, - io.pins.gpio32, - io.pins.gpio33, - 100u32.kHz(), - &clocks, - ); - - // Start timer (5 second interval) - timer0.start(5u64.secs()); - - // Initialize display - let interface = I2CDisplayInterface::new(i2c); - let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0) - .into_buffered_graphics_mode(); - display.init().unwrap(); - - // Specify different text styles - let text_style = MonoTextStyleBuilder::new() - .font(&FONT_6X10) - .text_color(BinaryColor::On) - .build(); - let text_style_big = MonoTextStyleBuilder::new() - .font(&FONT_9X18_BOLD) - .text_color(BinaryColor::On) - .build(); - - loop { - // Fill display bufffer with a centered text with two lines (and two text - // styles) - Text::with_alignment( - "esp-hal", - display.bounding_box().center() + Point::new(0, 0), - text_style_big, - Alignment::Center, - ) - .draw(&mut display) - .unwrap(); - - Text::with_alignment( - "Chip: ESP32", - display.bounding_box().center() + Point::new(0, 14), - text_style, - Alignment::Center, - ) - .draw(&mut display) - .unwrap(); - - // Write buffer to display - display.flush().unwrap(); - // Clear display buffer - display.clear(BinaryColor::Off).unwrap(); - - // Wait 5 seconds - block!(timer0.wait()).unwrap(); - - // Write single-line centered text "Hello World" to buffer - Text::with_alignment( - "Hello World!", - display.bounding_box().center(), - text_style_big, - Alignment::Center, - ) - .draw(&mut display) - .unwrap(); - - // Write buffer to display - display.flush().unwrap(); - // Clear display buffer - display.clear(BinaryColor::Off).unwrap(); - - // Wait 5 seconds - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32-hal/examples/i2s_read.rs b/esp32-hal/examples/i2s_read.rs deleted file mode 100644 index 4deadfb70..000000000 --- a/esp32-hal/examples/i2s_read.rs +++ /dev/null @@ -1,76 +0,0 @@ -//! This shows how to continously receive data via I2S -//! -//! Pins used -//! BCLK GPIO12 -//! WS GPIO13 -//! DIN GPIO14 -//! -//! Without an additional I2S source device you can connect 3V3 or GND to DIN to -//! read 0 or 0xFF or connect DIN to WS to read two different values -//! -//! You can also inspect the MCLK, BCLK and WS with a logic analyzer - -#![no_std] -#![no_main] - -use esp32_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - i2s::{DataFormat, I2s, I2sReadDma, Standard}, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.i2s0channel; - - let (_, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(0, 4092 * 4); - - let i2s = I2s::new( - peripherals.I2S0, - Standard::Philips, - DataFormat::Data16Channel16, - 44100u32.Hz(), - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - &clocks, - ); - - let i2s_rx = i2s - .i2s_rx - .with_bclk(io.pins.gpio12) - .with_ws(io.pins.gpio13) - .with_din(io.pins.gpio14) - .build(); - - let buffer = rx_buffer; - - let mut transfer = i2s_rx.read_dma_circular(buffer).unwrap(); - println!("Started transfer"); - - loop { - let avail = transfer.available(); - - if avail > 0 { - let mut rcv = [0u8; 5000]; - transfer.pop(&mut rcv[..avail]).unwrap(); - println!("Received {:x?}...", &rcv[..30]); - } - } -} diff --git a/esp32-hal/examples/ledc.rs b/esp32-hal/examples/ledc.rs deleted file mode 100644 index 534e519d5..000000000 --- a/esp32-hal/examples/ledc.rs +++ /dev/null @@ -1,64 +0,0 @@ -//! Turns on LED with the option to change LED intensity depending on `duty` -//! value. Possible values (`u32`) are in range 0..100. -//! -//! This assumes that a LED is connected to the pin assigned to `led`. (GPIO4) - -#![no_std] -#![no_main] - -use esp32_hal::{ - clock::ClockControl, - gpio::IO, - ledc::{ - channel::{self, ChannelIFace}, - timer::{self, TimerIFace}, - HighSpeed, - LEDC, - }, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let led = io.pins.gpio4.into_push_pull_output(); - - let ledc = LEDC::new(peripherals.LEDC, &clocks); - let mut hstimer0 = ledc.get_timer::(timer::Number::Timer0); - - hstimer0 - .configure(timer::config::Config { - duty: timer::config::Duty::Duty5Bit, - clock_source: timer::HSClockSource::APBClk, - frequency: 24u32.kHz(), - }) - .unwrap(); - - let mut channel0 = ledc.get_channel(channel::Number::Channel0, led); - channel0 - .configure(channel::config::Config { - timer: &hstimer0, - duty_pct: 10, - pin_config: channel::config::PinConfig::PushPull, - }) - .unwrap(); - - channel0.start_duty_fade(0, 100, 2000).expect_err( - "Fading from 0% to 100%, at 24kHz and 5-bit resolution, over 2 seconds, should fail", - ); - - loop { - // Set up a breathing LED: fade from off to on over a second, then - // from on back off over the next second. Then loop. - channel0.start_duty_fade(0, 100, 1000).unwrap(); - while channel0.is_duty_fade_running() {} - channel0.start_duty_fade(100, 0, 1000).unwrap(); - while channel0.is_duty_fade_running() {} - } -} diff --git a/esp32-hal/examples/pcnt_encoder.rs b/esp32-hal/examples/pcnt_encoder.rs deleted file mode 100644 index 5d66b2db5..000000000 --- a/esp32-hal/examples/pcnt_encoder.rs +++ /dev/null @@ -1,134 +0,0 @@ -//! PCNT Encoder Demo -//! -//! This example decodes a quadrature encoder -//! -//! Since the PCNT units reset to zero when they reach their limits -//! we enable an interrupt on the upper and lower limits and -//! track the overflow in an AtomicI32 - -#![no_std] -#![no_main] -use core::{ - cell::RefCell, - cmp::min, - sync::atomic::{AtomicI32, Ordering}, -}; - -use critical_section::Mutex; -use esp32_hal as esp_hal; -use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - interrupt, - pcnt::{channel, channel::PcntSource, unit, PCNT}, - peripherals::{self, Peripherals}, - prelude::*, - IO, -}; -use esp_println::println; - -static UNIT0: Mutex>> = Mutex::new(RefCell::new(None)); -static VALUE: AtomicI32 = AtomicI32::new(0); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let unit_number = unit::Number::Unit1; - - // setup a pulse couter - println!("setup pulse counter unit 0"); - let pcnt = PCNT::new(peripherals.PCNT); - let mut u0 = pcnt.get_unit(unit_number); - u0.configure(unit::Config { - low_limit: -100, - high_limit: 100, - filter: Some(min(10u16 * 80, 1023u16)), - ..Default::default() - }) - .unwrap(); - - println!("setup channel 0"); - let mut ch0 = u0.get_channel(channel::Number::Channel0); - let mut pin_a = io.pins.gpio22.into_pull_up_input(); - let mut pin_b = io.pins.gpio23.into_pull_up_input(); - - ch0.configure( - PcntSource::from_pin(&mut pin_a), - PcntSource::from_pin(&mut pin_b), - channel::Config { - lctrl_mode: channel::CtrlMode::Reverse, - hctrl_mode: channel::CtrlMode::Keep, - pos_edge: channel::EdgeMode::Decrement, - neg_edge: channel::EdgeMode::Increment, - invert_ctrl: false, - invert_sig: false, - }, - ); - - println!("setup channel 1"); - let mut ch1 = u0.get_channel(channel::Number::Channel1); - ch1.configure( - PcntSource::from_pin(&mut pin_b), - PcntSource::from_pin(&mut pin_a), - channel::Config { - lctrl_mode: channel::CtrlMode::Reverse, - hctrl_mode: channel::CtrlMode::Keep, - pos_edge: channel::EdgeMode::Increment, - neg_edge: channel::EdgeMode::Decrement, - invert_ctrl: false, - invert_sig: false, - }, - ); - println!("subscribing to events"); - u0.events(unit::Events { - low_limit: true, - high_limit: true, - thresh0: false, - thresh1: false, - zero: false, - }); - - println!("enabling interrupts"); - u0.listen(); - println!("resume pulse counter unit 0"); - u0.resume(); - - critical_section::with(|cs| UNIT0.borrow_ref_mut(cs).replace(u0)); - - interrupt::enable(peripherals::Interrupt::PCNT, interrupt::Priority::Priority2).unwrap(); - - let mut last_value: i32 = 0; - loop { - critical_section::with(|cs| { - let mut u0 = UNIT0.borrow_ref_mut(cs); - let u0 = u0.as_mut().unwrap(); - let value: i32 = u0.get_value() as i32 + VALUE.load(Ordering::SeqCst); - if value != last_value { - println!("value: {value}"); - last_value = value; - } - }); - } -} - -#[interrupt] -fn PCNT() { - critical_section::with(|cs| { - let mut u0 = UNIT0.borrow_ref_mut(cs); - let u0 = u0.as_mut().unwrap(); - if u0.interrupt_set() { - let events = u0.get_events(); - if events.high_limit { - VALUE.fetch_add(100, Ordering::SeqCst); - } else if events.low_limit { - VALUE.fetch_add(-100, Ordering::SeqCst); - } - u0.reset_interrupt(); - } - }); -} diff --git a/esp32-hal/examples/psram.rs b/esp32-hal/examples/psram.rs deleted file mode 100644 index 4257d2dcd..000000000 --- a/esp32-hal/examples/psram.rs +++ /dev/null @@ -1,56 +0,0 @@ -//! This shows how to use PSRAM as heap-memory via esp-alloc -//! -//! You need an ESP32 with at least 2 MB of PSRAM memory. - -#![no_std] -#![no_main] - -use esp32_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, psram}; -use esp_backtrace as _; -use esp_println::println; - -extern crate alloc; - -#[global_allocator] -static ALLOCATOR: esp_alloc::EspHeap = esp_alloc::EspHeap::empty(); - -fn init_psram_heap() { - unsafe { - ALLOCATOR.init(psram::PSRAM_VADDR_START as *mut u8, psram::PSRAM_BYTES); - } -} - -#[entry] -fn main() -> ! { - #[cfg(debug_assertions)] - compile_error!("PSRAM on ESP32 needs to be built in release mode"); - - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); - - let peripherals = Peripherals::take(); - psram::init_psram(peripherals.PSRAM); - init_psram_heap(); - - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - println!("Going to access PSRAM"); - - let mut large_vec: alloc::vec::Vec = alloc::vec::Vec::with_capacity(500 * 1024 / 4); - - for i in 0..(500 * 1024 / 4) { - large_vec.push((i & 0xff) as u32); - } - - println!("vec size = {} bytes", large_vec.len() * 4); - println!("vec address = {:p}", large_vec.as_ptr()); - println!("{:?}", &large_vec[..100]); - - let string = alloc::string::String::from("A string allocated in PSRAM"); - println!("'{}' allocated at {:p}", &string, string.as_ptr()); - - println!("done"); - - loop {} -} diff --git a/esp32-hal/examples/qspi_flash.rs b/esp32-hal/examples/qspi_flash.rs deleted file mode 100644 index a8736a45e..000000000 --- a/esp32-hal/examples/qspi_flash.rs +++ /dev/null @@ -1,166 +0,0 @@ -//! SPI write and read a flash chip -//! -//! Folowing pins are used: -//! SCLK GPIO19 -//! MISO/IO0 GPIO18 -//! MOSI/IO1 GPIO5 -//! IO2 GPIO17 -//! IO3 GPIO16 -//! CS GPIO4 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! Connect a flash chip (GD25Q64C was used) and make sure QE in the status -//! register is set. - -#![no_std] -#![no_main] - -use esp32_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{prelude::*, Address, Command, Spi}, - SpiDataMode, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio19; - let miso = io.pins.gpio18; - let mosi = io.pins.gpio5; - let sio2 = io.pins.gpio17; - let sio3 = io.pins.gpio16; - let cs = io.pins.gpio4; - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.spi2channel; - - let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(256, 320); - - let mut spi = Spi::new_half_duplex(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(sio2), - Some(sio3), - Some(cs), - ) - .with_dma(dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let mut delay = Delay::new(&clocks); - - let mut zero_buf = zero_buffer(); - let send = tx_buffer; - let mut receive = rx_buffer; - - // write enable - let transfer = spi - .write( - SpiDataMode::Single, - Command::Command8(0x06, SpiDataMode::Single), - Address::None, - 0, - zero_buf, - ) - .unwrap(); - (zero_buf, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - // erase sector - let transfer = spi - .write( - SpiDataMode::Single, - Command::Command8(0x20, SpiDataMode::Single), - Address::Address24(0x000000, SpiDataMode::Single), - 0, - zero_buf, - ) - .unwrap(); - (zero_buf, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - // write enable - let transfer = spi - .write( - SpiDataMode::Single, - Command::Command8(0x06, SpiDataMode::Single), - Address::None, - 0, - zero_buf, - ) - .unwrap(); - (_, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - // write data / program page - send.fill(b'!'); - send[0..][..5].copy_from_slice(&b"Hello"[..]); - let transfer = spi - .write( - SpiDataMode::Quad, - Command::Command8(0x32, SpiDataMode::Single), - Address::Address24(0x000000, SpiDataMode::Single), - 0, - send, - ) - .unwrap(); - (_, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - loop { - // quad fast read - let transfer = spi - .read( - SpiDataMode::Quad, - Command::Command8(0xeb, SpiDataMode::Single), - Address::Address32(0x000000 << 8, SpiDataMode::Quad), - 4, - receive, - ) - .unwrap(); - - // here we could do something else while DMA transfer is in progress - // the buffers and spi is moved into the transfer and we can get it back via - // `wait` - (receive, spi) = transfer.wait().unwrap(); - - println!("{:x?}", &receive); - for b in &mut receive.iter() { - if *b >= 32 && *b <= 127 { - print!("{}", *b as char); - } else { - print!("."); - } - } - println!(); - - delay.delay_ms(250u32); - } -} - -fn zero_buffer() -> &'static mut [u8; 0] { - static mut BUFFER: [u8; 0] = [0u8; 0]; - unsafe { &mut BUFFER } -} diff --git a/esp32-hal/examples/ram.rs b/esp32-hal/examples/ram.rs deleted file mode 100644 index a76d8107f..000000000 --- a/esp32-hal/examples/ram.rs +++ /dev/null @@ -1,97 +0,0 @@ -//! This shows how to use RTC memory. -//! RTC memory is retained during resets and during most sleep modes. -//! Initialized memory is always re-initialized on startup. -//! Uninitialzed memory isn't initialized on startup and can be used to keep -//! data during resets. Zeroed memory is initialized to zero on startup. -//! We can also run code from RTC memory. - -#![no_std] -#![no_main] - -use esp32_hal::{ - clock::ClockControl, - macros::ram, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, - Rtc, -}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; - -#[ram(rtc_fast)] -static mut SOME_INITED_DATA: [u8; 2] = [0xaa, 0xbb]; - -#[ram(rtc_fast, uninitialized)] -static mut SOME_UNINITED_DATA: [u8; 2] = [0; 2]; - -#[ram(rtc_fast, zeroed)] -static mut SOME_ZEROED_DATA: [u8; 8] = [0; 8]; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - // The RWDT flash boot protection must be enabled, as it is triggered as part of - // the example. - let mut rtc = Rtc::new(peripherals.LPWR); - rtc.rwdt.enable(); - - timer0.start(1u64.secs()); - - println!( - "IRAM function located at {:p}", - function_in_ram as *const () - ); - unsafe { - println!("SOME_INITED_DATA {:x?}", SOME_INITED_DATA); - println!("SOME_UNINITED_DATA {:x?}", SOME_UNINITED_DATA); - println!("SOME_ZEROED_DATA {:x?}", SOME_ZEROED_DATA); - - SOME_INITED_DATA[0] = 0xff; - SOME_ZEROED_DATA[0] = 0xff; - - println!("SOME_INITED_DATA {:x?}", SOME_INITED_DATA); - println!("SOME_UNINITED_DATA {:x?}", SOME_UNINITED_DATA); - println!("SOME_ZEROED_DATA {:x?}", SOME_ZEROED_DATA); - - if SOME_UNINITED_DATA[0] != 0 { - SOME_UNINITED_DATA[0] = 0; - SOME_UNINITED_DATA[1] = 0; - } - - if SOME_UNINITED_DATA[1] == 0xff { - SOME_UNINITED_DATA[1] = 0; - } - - println!("Counter {}", SOME_UNINITED_DATA[1]); - SOME_UNINITED_DATA[1] += 1; - } - - println!( - "RTC_FAST function located at {:p}", - function_in_rtc_ram as *const () - ); - println!("Result {}", function_in_rtc_ram()); - - loop { - function_in_ram(); - block!(timer0.wait()).unwrap(); - } -} - -#[ram] -fn function_in_ram() { - println!("Hello world!"); -} - -#[ram(rtc_fast)] -fn function_in_rtc_ram() -> u32 { - 42 -} diff --git a/esp32-hal/examples/read_efuse.rs b/esp32-hal/examples/read_efuse.rs deleted file mode 100644 index f1a43ef19..000000000 --- a/esp32-hal/examples/read_efuse.rs +++ /dev/null @@ -1,25 +0,0 @@ -//! This shows how to read selected information from eFuses. -//! e.g. the MAC address - -#![no_std] -#![no_main] - -use esp32_hal::{clock::ClockControl, efuse::Efuse, peripherals::Peripherals, prelude::*}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - println!("MAC address {:02x?}", Efuse::get_mac_address()); - println!("Core Count {}", Efuse::get_core_count()); - println!("Bluetooth enabled {}", Efuse::is_bluetooth_enabled()); - println!("Chip type {:?}", Efuse::get_chip_type()); - println!("Max CPU clock {:?}", Efuse::get_max_cpu_frequency()); - println!("Flash Encryption {:?}", Efuse::get_flash_encryption()); - - loop {} -} diff --git a/esp32-hal/examples/rmt_rx.rs b/esp32-hal/examples/rmt_rx.rs deleted file mode 100644 index 3c482de61..000000000 --- a/esp32-hal/examples/rmt_rx.rs +++ /dev/null @@ -1,91 +0,0 @@ -//! Demonstrates decoding pulse sequences with RMT -//! Connect GPIO15 to GPIO4 - -#![no_std] -#![no_main] - -use esp32_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - rmt::{PulseCode, RxChannel, RxChannelConfig, RxChannelCreator}, - Delay, - Rmt, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut out = io.pins.gpio15.into_push_pull_output(); - - let rmt = Rmt::new(peripherals.RMT, 80u32.MHz(), &clocks).unwrap(); - - let mut channel = rmt - .channel0 - .configure( - io.pins.gpio4, - RxChannelConfig { - clk_divider: 1, - idle_threshold: 0b111_1111_1111_1111, - ..RxChannelConfig::default() - }, - ) - .unwrap(); - - let mut delay = Delay::new(&clocks); - - let mut data = [PulseCode { - level1: true, - length1: 1, - level2: false, - length2: 1, - }; 48]; - - loop { - for x in data.iter_mut() { - x.length1 = 0; - x.length2 = 0; - } - - let transaction = channel.receive(&mut data).unwrap(); - - // simulate input - for i in 0u32..5u32 { - out.set_high().unwrap(); - delay.delay_us(i * 10 + 20); - out.set_low().unwrap(); - delay.delay_us(i * 20 + 20); - } - - match transaction.wait() { - Ok(channel_res) => { - channel = channel_res; - for entry in &data[..data.len()] { - if entry.length1 == 0 { - break; - } - println!("{} {}", entry.level1, entry.length1); - - if entry.length2 == 0 { - break; - } - println!("{} {}", entry.level2, entry.length2); - } - println!(); - } - Err((_err, channel_res)) => { - channel = channel_res; - println!("Error"); - } - } - - delay.delay_ms(1500u32); - } -} diff --git a/esp32-hal/examples/rsa.rs b/esp32-hal/examples/rsa.rs deleted file mode 100644 index a2ec1bf73..000000000 --- a/esp32-hal/examples/rsa.rs +++ /dev/null @@ -1,154 +0,0 @@ -//! Demonstrates the use of the RSA peripheral and compares the speed of -//! multiple arithmetic operations. - -#![no_std] -#![no_main] - -use crypto_bigint::{ - modular::runtime_mod::{DynResidue, DynResidueParams}, - Uint, - U1024, - U512, -}; -use esp32_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - rsa::{ - operand_sizes, - Rsa, - RsaModularExponentiation, - RsaModularMultiplication, - RsaMultiplication, - }, - xtensa_lx, -}; -use esp_backtrace as _; -use esp_println::println; - -const BIGNUM_1: U512 = Uint::from_be_hex( - "c7f61058f96db3bd87dbab08ab03b4f7f2f864eac249144adea6a65f97803b719d8ca980b7b3c0389c1c7c6\ -7dc353c5e0ec11f5fc8ce7f6073796cc8f73fa878", -); -const BIGNUM_2: U512 = Uint::from_be_hex( - "1763db3344e97be15d04de4868badb12a38046bb793f7630d87cf100aa1c759afac15a01f3c4c83ec2d2f66\ -6bd22f71c3c1f075ec0e2cb0cb29994d091b73f51", -); -const BIGNUM_3: U512 = Uint::from_be_hex( - "6b6bb3d2b6cbeb45a769eaa0384e611e1b89b0c9b45a045aca1c5fd6e8785b38df7118cf5dd45b9b63d293b\ -67aeafa9ba25feb8712f188cb139b7d9b9af1c361", -); - -const fn compute_r(modulus: &U512) -> U512 { - let mut d = [0_u32; U512::LIMBS * 2 + 1]; - d[d.len() - 1] = 1; - let d = Uint::from_words(d); - d.const_rem(&modulus.resize()).0.resize() -} - -const fn compute_mprime(modulus: &U512) -> u32 { - let m_inv = modulus.inv_mod2k(32).to_words()[0]; - (-1 * m_inv as i64 % 4294967296) as u32 -} - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let rsa = peripherals.RSA; - let mut rsa = Rsa::new(rsa); - nb::block!(rsa.ready()).unwrap(); - mod_exp_example(&mut rsa); - mod_multi_example(&mut rsa); - multiplication_example(&mut rsa); - loop {} -} - -fn mod_multi_example(rsa: &mut Rsa) { - let mut outbuf = [0_u32; U512::LIMBS]; - let mut mod_multi = RsaModularMultiplication::::new( - rsa, - BIGNUM_3.as_words(), - compute_mprime(&BIGNUM_3), - ); - let r = compute_r(&BIGNUM_3); - let pre_hw_modmul = xtensa_lx::timer::get_cycle_count(); - mod_multi.start_step1(BIGNUM_1.as_words(), r.as_words()); - mod_multi.start_step2(BIGNUM_2.as_words()); - mod_multi.read_results(&mut outbuf); - let post_hw_modmul = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for hw modular multiplication", - post_hw_modmul - pre_hw_modmul - ); - - let residue_params = DynResidueParams::new(&BIGNUM_3); - let residue_num1 = DynResidue::new(&BIGNUM_1, residue_params); - let residue_num2 = DynResidue::new(&BIGNUM_2, residue_params); - let pre_sw_exp = xtensa_lx::timer::get_cycle_count(); - let sw_out = residue_num1.mul(&residue_num2); - let post_sw_exp = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for sw modular multiplication", - post_sw_exp - pre_sw_exp - ); - assert_eq!(U512::from_words(outbuf), sw_out.retrieve()); - println!("modular multiplication done"); -} - -fn mod_exp_example(rsa: &mut Rsa) { - let mut outbuf = [0_u32; U512::LIMBS]; - let mut mod_exp = RsaModularExponentiation::::new( - rsa, - BIGNUM_2.as_words(), - BIGNUM_3.as_words(), - compute_mprime(&BIGNUM_3), - ); - let r = compute_r(&BIGNUM_3); - let base = &BIGNUM_1.as_words(); - let pre_hw_exp = xtensa_lx::timer::get_cycle_count(); - mod_exp.start_exponentiation(base, r.as_words()); - mod_exp.read_results(&mut outbuf); - let post_hw_exp = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for hw modular exponentiation", - post_hw_exp - pre_hw_exp - ); - let residue_params = DynResidueParams::new(&BIGNUM_3); - let residue = DynResidue::new(&BIGNUM_1, residue_params); - let pre_sw_exp = xtensa_lx::timer::get_cycle_count(); - let sw_out = residue.pow(&BIGNUM_2); - let post_sw_exp = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for sw modular exponentiation", - post_sw_exp - pre_sw_exp - ); - assert_eq!(U512::from_words(outbuf), sw_out.retrieve()); - println!("modular exponentiation done"); -} - -fn multiplication_example(rsa: &mut Rsa) { - let mut out = [0_u32; U1024::LIMBS]; - let mut rsamulti = RsaMultiplication::::new(rsa); - let operand_a = BIGNUM_1.as_words(); - let operand_b = BIGNUM_2.as_words(); - let pre_hw_mul = xtensa_lx::timer::get_cycle_count(); - rsamulti.start_multiplication(operand_a, operand_b); - rsamulti.read_results(&mut out); - let post_hw_mul = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for hw multiplication", - post_hw_mul - pre_hw_mul - ); - let pre_sw_mul = xtensa_lx::timer::get_cycle_count(); - let sw_out = BIGNUM_1.mul_wide(&BIGNUM_2); - let post_sw_mul = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for sw multiplication", - post_sw_mul - pre_sw_mul - ); - assert_eq!(U1024::from_words(out), sw_out.1.concat(&sw_out.0)); - println!("multiplication done"); -} diff --git a/esp32-hal/examples/rtc_watchdog.rs b/esp32-hal/examples/rtc_watchdog.rs deleted file mode 100644 index e531b6a02..000000000 --- a/esp32-hal/examples/rtc_watchdog.rs +++ /dev/null @@ -1,59 +0,0 @@ -//! This demos the RTC Watchdog Timer (RWDT). -//! The RWDT is initially configured to trigger an interrupt after a given -//! timeout. Then, upon expiration, the RWDT is restarted and then reconfigured -//! to reset both the main system and the RTC. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, - Rtc, - Rwdt, -}; -use esp_backtrace as _; - -static RWDT: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rtc = Rtc::new(peripherals.LPWR); - rtc.rwdt.start(2000u64.millis()); - rtc.rwdt.listen(); - - critical_section::with(|cs| RWDT.borrow_ref_mut(cs).replace(rtc.rwdt)); - - interrupt::enable( - peripherals::Interrupt::RTC_CORE, - interrupt::Priority::Priority1, - ) - .unwrap(); - - loop {} -} - -#[interrupt] -fn RTC_CORE() { - critical_section::with(|cs| { - esp_println::println!("RWDT Interrupt"); - - let mut rwdt = RWDT.borrow_ref_mut(cs); - let rwdt = rwdt.as_mut().unwrap(); - rwdt.clear_interrupt(); - - esp_println::println!("Restarting in 5 seconds..."); - - rwdt.start(5000u64.millis()); - rwdt.unlisten(); - }); -} diff --git a/esp32-hal/examples/serial_interrupts.rs b/esp32-hal/examples/serial_interrupts.rs deleted file mode 100644 index 7585268b9..000000000 --- a/esp32-hal/examples/serial_interrupts.rs +++ /dev/null @@ -1,84 +0,0 @@ -//! This shows some of the interrupts that can be generated by UART/Serial. -//! Use a proper serial terminal to connect to the board (espmonitor and -//! espflash won't work) - -#![no_std] -#![no_main] - -use core::{cell::RefCell, fmt::Write}; - -use critical_section::Mutex; -use esp32_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals, UART0}, - prelude::*, - timer::TimerGroup, - uart::config::AtCmdConfig, - Uart, -}; -use esp_backtrace as _; -use nb::block; - -static SERIAL: Mutex>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - uart0.set_at_cmd(AtCmdConfig::new(None, None, None, b'#', None)); - uart0.set_rx_fifo_full_threshold(30).unwrap(); - uart0.listen_at_cmd(); - uart0.listen_rx_fifo_full(); - - interrupt::enable( - peripherals::Interrupt::UART0, - interrupt::Priority::Priority2, - ) - .unwrap(); - - timer0.start(1u64.secs()); - - critical_section::with(|cs| SERIAL.borrow_ref_mut(cs).replace(uart0)); - - loop { - critical_section::with(|cs| { - let mut serial = SERIAL.borrow_ref_mut(cs); - let serial = serial.as_mut().unwrap(); - writeln!(serial, "Hello World! Send a single `#` character or send at least 30 characters and see the interrupts trigger.").ok(); - }); - - block!(timer0.wait()).unwrap(); - } -} - -#[interrupt] -fn UART0() { - critical_section::with(|cs| { - let mut serial = SERIAL.borrow_ref_mut(cs); - let serial = serial.as_mut().unwrap(); - - let mut cnt = 0; - while let nb::Result::Ok(_c) = serial.read() { - cnt += 1; - } - writeln!(serial, "Read {} bytes", cnt,).ok(); - - writeln!( - serial, - "Interrupt AT-CMD: {} RX-FIFO-FULL: {}", - serial.at_cmd_interrupt_set(), - serial.rx_fifo_full_interrupt_set(), - ) - .ok(); - - serial.reset_at_cmd_interrupt(); - serial.reset_rx_fifo_full_interrupt(); - }); -} diff --git a/esp32-hal/examples/sha.rs b/esp32-hal/examples/sha.rs deleted file mode 100644 index 66292cb76..000000000 --- a/esp32-hal/examples/sha.rs +++ /dev/null @@ -1,73 +0,0 @@ -//! Demonstrates the use of the SHA peripheral and compares the speed of -//! hardware-accelerated and pure software hashing. - -#![no_std] -#![no_main] - -use esp32_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - sha::{Sha, ShaMode}, - xtensa_lx, -}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; -use sha2::{Digest, Sha512}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let source_data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".as_bytes(); - let mut remaining = source_data; - let mut hasher = Sha::new(peripherals.SHA, ShaMode::SHA512); - - // Short hashes can be created by decreasing the output buffer to the desired - // length - let mut output = [0u8; 64]; - - let pre_calc = xtensa_lx::timer::get_cycle_count(); - // The hardware implementation takes a subslice of the input, and returns the - // unprocessed parts The unprocessed parts can be input in the next - // iteration, you can always add more data until finish() is called. After - // finish() is called update()'s will contribute to a new hash which - // can be extracted again with finish(). - - while remaining.len() > 0 { - // Can add println to view progress, however println takes a few orders of - // magnitude longer than the Sha function itself so not useful for - // comparing processing time println!("Remaining len: {}", - // remaining.len()); - - // All the HW Sha functions are infallible so unwrap is fine to use if you use - // block! - remaining = block!(hasher.update(remaining)).unwrap(); - } - - // Finish can be called as many times as desired to get mutliple copies of the - // output. - block!(hasher.finish(output.as_mut_slice())).unwrap(); - - let post_calc = xtensa_lx::timer::get_cycle_count(); - let hw_time = post_calc - pre_calc; - println!("Took {} cycles", hw_time); - println!("SHA512 Hash output {:02x?}", output); - - let pre_calc = xtensa_lx::timer::get_cycle_count(); - let mut hasher = Sha512::new(); - hasher.update(source_data); - let soft_result = hasher.finalize(); - let post_calc = xtensa_lx::timer::get_cycle_count(); - let soft_time = post_calc - pre_calc; - println!("Took {} cycles", soft_time); - println!("SHA512 Hash output {:02x?}", soft_result); - - assert_eq!(output, soft_result[..]); - println!("HW SHA is {}x faster", soft_time / hw_time); - - loop {} -} diff --git a/esp32-hal/examples/sleep_timer.rs b/esp32-hal/examples/sleep_timer.rs deleted file mode 100644 index 691b442cd..000000000 --- a/esp32-hal/examples/sleep_timer.rs +++ /dev/null @@ -1,41 +0,0 @@ -//! Demonstrates deep sleep with timer wakeup - -#![no_std] -#![no_main] - -use core::time::Duration; - -use esp32_hal::{ - clock::ClockControl, - entry, - peripherals::Peripherals, - prelude::*, - rtc_cntl::{get_reset_reason, get_wakeup_cause, sleep::TimerWakeupSource, SocResetReason}, - Cpu, - Delay, - Rtc, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rtc = Rtc::new(peripherals.LPWR); - - println!("up and runnning!"); - let reason = get_reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn); - println!("reset reason: {:?}", reason); - let wake_reason = get_wakeup_cause(); - println!("wake reason: {:?}", wake_reason); - - let mut delay = Delay::new(&clocks); - - let timer = TimerWakeupSource::new(Duration::from_secs(30)); - println!("sleeping!"); - delay.delay_ms(100u32); - rtc.sleep_deep(&[&timer], &mut delay); -} diff --git a/esp32-hal/examples/sleep_timer_ext0.rs b/esp32-hal/examples/sleep_timer_ext0.rs deleted file mode 100644 index 72a639998..000000000 --- a/esp32-hal/examples/sleep_timer_ext0.rs +++ /dev/null @@ -1,51 +0,0 @@ -//! Demonstrates deep sleep with timer and ext0 (using gpio27) wakeup - -#![no_std] -#![no_main] - -use core::time::Duration; - -use esp32_hal::{ - clock::ClockControl, - entry, - peripherals::Peripherals, - prelude::*, - rtc_cntl::{ - get_reset_reason, - get_wakeup_cause, - sleep::{Ext0WakeupSource, TimerWakeupSource, WakeupLevel}, - SocResetReason, - }, - Cpu, - Delay, - Rtc, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rtc = Rtc::new(peripherals.LPWR); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut ext0_pin = io.pins.gpio27; - - println!("up and runnning!"); - let reason = get_reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn); - println!("reset reason: {:?}", reason); - let wake_reason = get_wakeup_cause(); - println!("wake reason: {:?}", wake_reason); - - let mut delay = Delay::new(&clocks); - - let timer = TimerWakeupSource::new(Duration::from_secs(30)); - let ext0 = Ext0WakeupSource::new(&mut ext0_pin, WakeupLevel::High); - println!("sleeping!"); - delay.delay_ms(100u32); - rtc.sleep_deep(&[&timer, &ext0], &mut delay); -} diff --git a/esp32-hal/examples/sleep_timer_ext1.rs b/esp32-hal/examples/sleep_timer_ext1.rs deleted file mode 100644 index aa9559bb6..000000000 --- a/esp32-hal/examples/sleep_timer_ext1.rs +++ /dev/null @@ -1,53 +0,0 @@ -//! Demonstrates deep sleep with timer and ext1 (using gpio27 & gpio23) wakeup - -#![no_std] -#![no_main] - -use core::time::Duration; - -use esp32_hal::{ - clock::ClockControl, - entry, - gpio::{RTCPin, IO}, - peripherals::Peripherals, - prelude::*, - rtc_cntl::{ - get_reset_reason, - get_wakeup_cause, - sleep::{Ext1WakeupSource, TimerWakeupSource, WakeupLevel}, - SocResetReason, - }, - Cpu, - Delay, - Rtc, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rtc = Rtc::new(peripherals.LPWR); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut pin27 = io.pins.gpio27; - let mut pin32 = io.pins.gpio32; - - println!("up and runnning!"); - let reason = get_reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn); - println!("reset reason: {:?}", reason); - let wake_reason = get_wakeup_cause(); - println!("wake reason: {:?}", wake_reason); - - let mut delay = Delay::new(&clocks); - - let timer = TimerWakeupSource::new(Duration::from_secs(30)); - let mut wakeup_pins: [&mut dyn RTCPin; 2] = [&mut pin27, &mut pin32]; - let ext1 = Ext1WakeupSource::new(&mut wakeup_pins, WakeupLevel::High); - println!("sleeping!"); - delay.delay_ms(100u32); - rtc.sleep_deep(&[&timer, &ext1], &mut delay); -} diff --git a/esp32-hal/examples/spi_eh1_device_loopback.rs b/esp32-hal/examples/spi_eh1_device_loopback.rs deleted file mode 100644 index b20977c73..000000000 --- a/esp32-hal/examples/spi_eh1_device_loopback.rs +++ /dev/null @@ -1,140 +0,0 @@ -//! SPI loopback test -//! -//! Folowing pins are used: -//! SCLK GPIO19 -//! MISO GPIO25 -//! MOSI GPIO23 -//! CS 1 GPIO12 -//! CS 2 GPIO13 -//! CS 3 GPIO14 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use embedded_hal_1::spi::SpiDevice; -use embedded_hal_bus::spi::RefCellDevice; -use esp32_hal::{ - clock::ClockControl, - gpio::{self, IO}, - peripherals::Peripherals, - prelude::*, - spi::{master::Spi, SpiMode}, - Delay, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio19; - let miso = io.pins.gpio25; - let mosi = io.pins.gpio23; - - let spi_bus = Spi::new(peripherals.SPI2, 1000u32.kHz(), SpiMode::Mode0, &clocks).with_pins( - Some(sclk), - Some(mosi), - Some(miso), - gpio::NO_PIN, - ); - let spi_bus = RefCell::new(spi_bus); - let mut spi_device_1 = - RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio12.into_push_pull_output()); - let mut spi_device_2 = - RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio13.into_push_pull_output()); - let mut spi_device_3 = - RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio14.into_push_pull_output()); - - let mut delay = Delay::new(&clocks); - println!("=== SPI example with embedded-hal-1 traits ==="); - - loop { - // --- Symmetric transfer (Read as much as we write) --- - print!("Starting symmetric transfer..."); - let write = [0xde, 0xad, 0xbe, 0xef]; - let mut read: [u8; 4] = [0x00u8; 4]; - - spi_device_1.transfer(&mut read[..], &write[..]).unwrap(); - assert_eq!(write, read); - spi_device_2.transfer(&mut read[..], &write[..]).unwrap(); - spi_device_3.transfer(&mut read[..], &write[..]).unwrap(); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Asymmetric transfer (Read more than we write) --- - print!("Starting asymetric transfer (read > write)..."); - let mut read: [u8; 4] = [0x00; 4]; - - spi_device_1 - .transfer(&mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - assert_eq!(write[0], read[0]); - assert_eq!(read[2], 0x00u8); - spi_device_2 - .transfer(&mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - spi_device_3 - .transfer(&mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer --- - // Only your RAM is the limit! - print!("Starting huge transfer..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - let mut read = [0x00u8; 4096]; - - spi_device_1 - .transfer(&mut read[..], &write[..]) - .expect("Huge transfer failed"); - assert_eq!(write, read); - spi_device_2 - .transfer(&mut read[..], &write[..]) - .expect("Huge transfer failed"); - spi_device_3 - .transfer(&mut read[..], &write[..]) - .expect("Huge transfer failed"); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer in-place (No additional allocation - // needed) --- - print!("Starting huge transfer (in-place)..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - - spi_device_1 - .transfer_in_place(&mut write[..]) - .expect("Huge transfer failed"); - for byte in 0..write.len() { - assert_eq!(write[byte], byte as u8); - } - spi_device_2 - .transfer_in_place(&mut write[..]) - .expect("Huge transfer failed"); - spi_device_3 - .transfer_in_place(&mut write[..]) - .expect("Huge transfer failed"); - println!(" SUCCESS"); - delay.delay_ms(250u32); - } -} diff --git a/esp32-hal/examples/spi_eh1_loopback.rs b/esp32-hal/examples/spi_eh1_loopback.rs deleted file mode 100644 index 578c6eb50..000000000 --- a/esp32-hal/examples/spi_eh1_loopback.rs +++ /dev/null @@ -1,104 +0,0 @@ -//! SPI loopback test -//! -//! Folowing pins are used: -//! SCLK GPIO19 -//! MISO GPIO25 -//! MOSI GPIO23 -//! CS GPIO22 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use embedded_hal_1::spi::SpiBus; -use esp32_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{master::Spi, SpiMode}, - Delay, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio19; - let miso = io.pins.gpio25; - let mosi = io.pins.gpio23; - let cs = io.pins.gpio22; - - let mut spi = Spi::new(peripherals.SPI2, 1000u32.kHz(), SpiMode::Mode0, &clocks).with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(cs), - ); - - let mut delay = Delay::new(&clocks); - println!("=== SPI example with embedded-hal-1 traits ==="); - - loop { - // --- Symmetric transfer (Read as much as we write) --- - print!("Starting symmetric transfer..."); - let write = [0xde, 0xad, 0xbe, 0xef]; - let mut read: [u8; 4] = [0x00u8; 4]; - - SpiBus::transfer(&mut spi, &mut read[..], &write[..]).expect("Symmetric transfer failed"); - assert_eq!(write, read); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Asymmetric transfer (Read more than we write) --- - print!("Starting asymetric transfer (read > write)..."); - let mut read: [u8; 4] = [0x00; 4]; - - SpiBus::transfer(&mut spi, &mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - assert_eq!(write[0], read[0]); - assert_eq!(read[2], 0x00u8); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer --- - // Only your RAM is the limit! - print!("Starting huge transfer..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - let mut read = [0x00u8; 4096]; - - SpiBus::transfer(&mut spi, &mut read[..], &write[..]).expect("Huge transfer failed"); - assert_eq!(write, read); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer in-place (No additional allocation - // needed) --- - print!("Starting huge transfer (in-place)..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - - SpiBus::transfer_in_place(&mut spi, &mut write[..]).expect("Huge transfer failed"); - for byte in 0..write.len() { - assert_eq!(write[byte], byte as u8); - } - println!(" SUCCESS"); - delay.delay_ms(250u32); - } -} diff --git a/esp32-hal/examples/spi_halfduplex_read_manufacturer_id.rs b/esp32-hal/examples/spi_halfduplex_read_manufacturer_id.rs deleted file mode 100644 index 258f410d6..000000000 --- a/esp32-hal/examples/spi_halfduplex_read_manufacturer_id.rs +++ /dev/null @@ -1,101 +0,0 @@ -//! SPI read manufacturer id from flash chip -//! -//! Folowing pins are used: -//! SCLK GPIO19 -//! MISO/IO0 GPIO18 -//! MOSI/IO1 GPIO5 -//! IO2 GPIO17 -//! IO3 GPIO16 -//! CS GPIO4 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! Connect a flash chip (GD25Q64C was used) and make sure QE in the status -//! register is set. - -#![no_std] -#![no_main] - -use esp32_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{Address, Command, HalfDuplexReadWrite, Spi}, - SpiDataMode, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio19; - let miso = io.pins.gpio18; - let mosi = io.pins.gpio5; - let sio2 = io.pins.gpio17; - let sio3 = io.pins.gpio16; - let cs = io.pins.gpio4; - - let mut spi = Spi::new_half_duplex(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(sio2), - Some(sio3), - Some(cs), - ); - - let mut delay = Delay::new(&clocks); - - loop { - // READ MANUFACTURER ID FROM FLASH CHIP - let mut data = [0u8; 2]; - spi.read( - SpiDataMode::Single, - Command::Command8(0x90, SpiDataMode::Single), - Address::Address24(0x000000, SpiDataMode::Single), - 0, - &mut data, - ) - .unwrap(); - println!("Single {:x?}", data); - delay.delay_ms(250u32); - - // READ MANUFACTURER ID FROM FLASH CHIP - let mut data = [0u8; 2]; - spi.read( - SpiDataMode::Dual, - Command::Command8(0x92, SpiDataMode::Single), - Address::Address32(0x000000_00, SpiDataMode::Dual), - 0, - &mut data, - ) - .unwrap(); - println!("Dual {:x?}", data); - delay.delay_ms(250u32); - - // READ MANUFACTURER ID FROM FLASH CHIP - let mut data = [0u8; 2]; - spi.read( - SpiDataMode::Quad, - Command::Command8(0x94, SpiDataMode::Single), - Address::Address32(0x000000_00, SpiDataMode::Quad), - 4, - &mut data, - ) - .unwrap(); - println!("Quad {:x?}", data); - delay.delay_ms(1500u32); - } -} diff --git a/esp32-hal/examples/spi_loopback.rs b/esp32-hal/examples/spi_loopback.rs deleted file mode 100644 index 3720a2362..000000000 --- a/esp32-hal/examples/spi_loopback.rs +++ /dev/null @@ -1,58 +0,0 @@ -//! SPI loopback test -//! -//! Folowing pins are used: -//! SCLK GPIO19 -//! MISO GPIO25 -//! MOSI GPIO23 -//! CS GPIO22 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use esp32_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{master::Spi, SpiMode}, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio19; - let miso = io.pins.gpio25; - let mosi = io.pins.gpio23; - let cs = io.pins.gpio22; - - let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks).with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(cs), - ); - - let mut delay = Delay::new(&clocks); - - loop { - let mut data = [0xde, 0xca, 0xfb, 0xad]; - spi.transfer(&mut data).unwrap(); - println!("{:x?}", data); - - delay.delay_ms(250u32); - } -} diff --git a/esp32-hal/examples/spi_loopback_dma.rs b/esp32-hal/examples/spi_loopback_dma.rs deleted file mode 100644 index 4b75efdb7..000000000 --- a/esp32-hal/examples/spi_loopback_dma.rs +++ /dev/null @@ -1,97 +0,0 @@ -//! SPI loopback test using DMA -//! -//! Folowing pins are used: -//! SCLK GPIO19 -//! MISO GPIO25 -//! MOSI GPIO23 -//! CS GPIO22 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use esp32_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{prelude::*, Spi}, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio19; - let miso = io.pins.gpio25; - let mosi = io.pins.gpio23; - let cs = io.pins.gpio22; - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.spi2channel; - - let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(32000); - - let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) - .with_dma(dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let mut delay = Delay::new(&clocks); - - // DMA buffer require a static life-time - let mut send = tx_buffer; - let mut receive = rx_buffer; - let mut i = 0; - - for (i, v) in send.iter_mut().enumerate() { - *v = (i % 255) as u8; - } - - loop { - send[0] = i; - send[send.len() - 1] = i; - i = i.wrapping_add(1); - - let transfer = spi.dma_transfer(send, receive).unwrap(); - // here we could do something else while DMA transfer is in progress - let mut n = 0; - // Check is_done until the transfer is almost done (32000 bytes at 100kHz is - // 2.56 seconds), then move to wait(). - while !transfer.is_done() && n < 10 { - delay.delay_ms(250u32); - n += 1; - } - // the buffers and spi is moved into the transfer and we can get it back via - // `wait` - (receive, send, spi) = transfer.wait().unwrap(); - println!( - "{:x?} .. {:x?}", - &receive[..10], - &receive[receive.len() - 10..] - ); - - delay.delay_ms(250u32); - } -} diff --git a/esp32-hal/examples/timer_interrupt.rs b/esp32-hal/examples/timer_interrupt.rs deleted file mode 100644 index 19fa0f9d2..000000000 --- a/esp32-hal/examples/timer_interrupt.rs +++ /dev/null @@ -1,122 +0,0 @@ -//! This shows how to use the TIMG peripheral interrupts. -//! There is TIMG0 and TIMG1 each of them containing two general purpose timers -//! and a watchdog timer. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32_hal::{ - clock::ClockControl, - interrupt, - interrupt::Priority, - peripherals::{self, Peripherals, TIMG0, TIMG1}, - prelude::*, - timer::{Timer, Timer0, Timer1, TimerGroup}, -}; -use esp_backtrace as _; - -static TIMER00: Mutex>>>> = Mutex::new(RefCell::new(None)); -static TIMER01: Mutex>>>> = Mutex::new(RefCell::new(None)); -static TIMER10: Mutex>>>> = Mutex::new(RefCell::new(None)); -static TIMER11: Mutex>>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer00 = timer_group0.timer0; - let mut timer01 = timer_group0.timer1; - - let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks); - let mut timer10 = timer_group1.timer0; - let mut timer11 = timer_group1.timer1; - - interrupt::enable(peripherals::Interrupt::TG0_T0_LEVEL, Priority::Priority2).unwrap(); - interrupt::enable(peripherals::Interrupt::TG0_T1_LEVEL, Priority::Priority2).unwrap(); - interrupt::enable(peripherals::Interrupt::TG1_T0_LEVEL, Priority::Priority3).unwrap(); - interrupt::enable(peripherals::Interrupt::TG1_T1_LEVEL, Priority::Priority3).unwrap(); - - timer00.start(500u64.millis()); - timer00.listen(); - timer01.start(2500u64.millis()); - timer01.listen(); - timer10.start(1u64.secs()); - timer10.listen(); - timer11.start(3u64.secs()); - timer11.listen(); - - critical_section::with(|cs| { - TIMER00.borrow_ref_mut(cs).replace(timer00); - TIMER01.borrow_ref_mut(cs).replace(timer01); - TIMER10.borrow_ref_mut(cs).replace(timer10); - TIMER11.borrow_ref_mut(cs).replace(timer11); - }); - - loop {} -} - -#[interrupt] -fn TG0_T0_LEVEL() { - critical_section::with(|cs| { - let mut timer = TIMER00.borrow_ref_mut(cs); - let timer = timer.as_mut().unwrap(); - - if timer.is_interrupt_set() { - timer.clear_interrupt(); - timer.start(500u64.millis()); - - esp_println::println!("Interrupt Level 2 - Timer0"); - } - }); -} - -#[interrupt] -fn TG0_T1_LEVEL() { - critical_section::with(|cs| { - let mut timer = TIMER01.borrow_ref_mut(cs); - let timer = timer.as_mut().unwrap(); - - if timer.is_interrupt_set() { - timer.clear_interrupt(); - timer.start(2500u64.millis()); - - esp_println::println!("Interrupt Level 2 - Timer1"); - } - }); -} - -#[interrupt] -fn TG1_T0_LEVEL() { - critical_section::with(|cs| { - let mut timer = TIMER10.borrow_ref_mut(cs); - let timer = timer.as_mut().unwrap(); - - if timer.is_interrupt_set() { - timer.clear_interrupt(); - timer.start(1u64.secs()); - - esp_println::println!("Interrupt Level 3 - Timer0"); - } - }); -} - -#[interrupt] -fn TG1_T1_LEVEL() { - critical_section::with(|cs| { - let mut timer = TIMER10.borrow_ref_mut(cs); - let timer = timer.as_mut().unwrap(); - - if timer.is_interrupt_set() { - timer.clear_interrupt(); - timer.start(3u64.secs()); - - esp_println::println!("Interrupt Level 3 - Timer1"); - } - }); -} diff --git a/esp32-hal/examples/watchdog.rs b/esp32-hal/examples/watchdog.rs deleted file mode 100644 index 7544561ef..000000000 --- a/esp32-hal/examples/watchdog.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! This demos the watchdog timer. -//! Basically the same as `hello_world` but if you remove the call to -//! `wdt.feed()` the watchdog will reset the system. - -#![no_std] -#![no_main] - -use esp32_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, timer::TimerGroup}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - let mut wdt = timer_group0.wdt; - - wdt.start(2u64.secs()); - timer0.start(1u64.secs()); - - loop { - wdt.feed(); - println!("Hello world!"); - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32-hal/rust-toolchain.toml b/esp32-hal/rust-toolchain.toml deleted file mode 100644 index 90aabae96..000000000 --- a/esp32-hal/rust-toolchain.toml +++ /dev/null @@ -1,4 +0,0 @@ -[toolchain] -channel = "esp" -components = ["rustfmt", "rustc-dev"] -targets = ["xtensa-esp32-none-elf"] diff --git a/esp32-hal/src/lib.rs b/esp32-hal/src/lib.rs deleted file mode 100644 index 1cacd8c03..000000000 --- a/esp32-hal/src/lib.rs +++ /dev/null @@ -1,9 +0,0 @@ -//! A bare-metal (`no_std`) Hardware Abstraction Layer for the ESP32 from -//! Espressif. -//! -//! ## Feature Flags -#![doc = document_features::document_features!()] -#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/46717278")] -#![no_std] - -pub use esp_hal::*; diff --git a/esp32c2-hal/.cargo/config.toml b/esp32c2-hal/.cargo/config.toml deleted file mode 100644 index c1bf8bdad..000000000 --- a/esp32c2-hal/.cargo/config.toml +++ /dev/null @@ -1,12 +0,0 @@ -[target.riscv32imc-unknown-none-elf] -runner = "espflash flash --monitor" -rustflags = [ - "-C", "link-arg=-Tlinkall.x", - "-C", "force-frame-pointers", -] - -[build] -target = "riscv32imc-unknown-none-elf" - -[unstable] -build-std = ["core"] diff --git a/esp32c2-hal/Cargo.toml b/esp32c2-hal/Cargo.toml deleted file mode 100644 index 888d34367..000000000 --- a/esp32c2-hal/Cargo.toml +++ /dev/null @@ -1,143 +0,0 @@ -[package] -name = "esp32c2-hal" -version = "0.13.0" -edition = "2021" -rust-version = "1.67.0" -description = "HAL for ESP32-C2 microcontrollers" -repository = "https://github.com/esp-rs/esp-hal" -license = "MIT OR Apache-2.0" - -keywords = [ - "embedded", - "embedded-hal", - "esp", - "esp32c2", - "no-std", -] -categories = [ - "embedded", - "hardware-support", - "no-std", -] - -[package.metadata.docs.rs] -targets = ["riscv32imc-unknown-none-elf"] - -[dependencies] -document-features = "0.2.7" -esp-hal = { version = "0.15.0", features = ["esp32c2"], path = "../esp-hal" } -embassy-time-driver = { version = "0.1.0", optional = true } - -[dev-dependencies] -critical-section = "1.1.2" -crypto-bigint = { version = "0.5.5", default-features = false } -elliptic-curve = { version = "0.13.8", default-features = false, features = ["sec1"] } -embassy-executor = { version = "0.5.0", features = ["nightly"] } -embassy-sync = "0.5.0" -embassy-time = "0.3.0" -embedded-graphics = "0.8.1" -embedded-hal-1 = { version = "1.0.0", package = "embedded-hal" } -embedded-hal-async = "1.0.0" -embedded-io-async = "0.6.1" -embedded-hal-bus = "0.1.0" -esp-backtrace = { version = "0.10.0", features = ["esp32c2", "panic-handler", "exception-handler", "print-uart"] } -esp-println = { version = "0.8.0", features = ["esp32c2"] } -heapless = "0.8.0" -hex-literal = "0.4.1" -lis3dh-async = "0.9.1" -p192 = { version = "0.13.0", default-features = false, features = ["arithmetic"] } -p256 = { version = "0.13.2", default-features = false, features = ["arithmetic"] } -sha2 = { version = "0.10.8", default-features = false} -ssd1306 = "0.8.4" -static_cell = { version = "2.0.0", features = ["nightly"] } - -[features] -default = ["embassy-integrated-timers", "rt", "vectored"] - -## Enable debug features in the HAL (used for development). -debug = ["esp-hal/debug"] -## Enable direct interrupt vectoring. -direct-vectoring = ["esp-hal/direct-vectoring"] -## Enable interrupt preemption. -interrupt-preemption = ["esp-hal/interrupt-preemption"] -## Enable logging output using the `log` crate. -log = ["esp-hal/log", "esp-println/log"] -## Enable runtime support. -rt = ["esp-hal/rt-riscv"] -## Enable interrupt vectoring. -vectored = ["esp-hal/vectored"] - -#! ### Trait Implementation Feature Flags -## Enable support for asynchronous operation, with interfaces provided by -## `embedded-hal-async` and `embedded-io-async`. -async = ["esp-hal/async"] -## Implement `defmt::Format` on certain types. -defmt = ["esp-hal/defmt", "esp-println/defmt-espflash"] -## Implement the traits defined in the `1.0.0` releases of `embedded-hal` and -## `embedded-hal-nb` for the relevant peripherals. -eh1 = ["esp-hal/eh1"] -## Implement the traits defined in `embedded-io` for certain peripherals. -embedded-io = ["esp-hal/embedded-io"] -## Implement the `ufmt_write::uWrite` trait for certain peripherals. -ufmt = ["esp-hal/ufmt"] - -#! ### Embassy Feature Flags -## Enable support for `embassy`, a modern asynchronous embedded framework. -embassy = ["esp-hal/embassy"] -## Use the interrupt-mode embassy executor. -embassy-executor-interrupt = ["esp-hal/embassy-executor-interrupt"] -## Use the thread-mode embassy executor. -embassy-executor-thread = ["esp-hal/embassy-executor-thread"] -## Uses hardware timers as alarms for the executors. Using this feature -## limits the number of executors to the number of hardware alarms provided -## by the time driver. -embassy-integrated-timers = ["esp-hal/embassy-integrated-timers"] -## Enable the embassy time driver using the `SYSTIMER` peripheral. The -## `SYSTIMER` peripheral has three alarams available for use. -embassy-time-systick = ["esp-hal/embassy-time-systick", "embassy-time-driver/tick-hz-16_000_000"] -## Enable the embassy time driver using the `TIMG0` peripheral. The `TIMG0` -## peripheral has two alarms available for use. -embassy-time-timg0 = ["esp-hal/embassy-time-timg0", "embassy-time-driver/tick-hz-1_000_000"] - -[profile.release] -debug = true - -[[example]] -name = "spi_eh1_loopback" -required-features = ["eh1"] - -[[example]] -name = "spi_eh1_device_loopback" -required-features = ["eh1"] - -[[example]] -name = "embassy_hello_world" -required-features = ["embassy", "embassy-executor-thread"] - -[[example]] -name = "embassy_multiprio" -required-features = ["embassy", "embassy-executor-thread", "embassy-executor-interrupt"] - -[[example]] -name = "embassy_wait" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_spi" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "interrupt_preemption" -required-features = ["interrupt-preemption"] - -[[example]] -name = "embassy_serial" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_i2c" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "direct-vectoring" -required-features = ["direct-vectoring"] diff --git a/esp32c2-hal/README.md b/esp32c2-hal/README.md deleted file mode 100644 index 242e4134f..000000000 --- a/esp32c2-hal/README.md +++ /dev/null @@ -1,51 +0,0 @@ -# esp32c2-hal - -[![Crates.io](https://img.shields.io/crates/v/esp32c2-hal?labelColor=1C2C2E&color=C96329&logo=Rust&style=flat-square)](https://crates.io/crates/esp32c2-hal) -[![docs.rs](https://img.shields.io/docsrs/esp32c2-hal?labelColor=1C2C2E&color=C96329&logo=rust&style=flat-square)](https://docs.rs/esp32c2-hal) -![Crates.io](https://img.shields.io/crates/l/esp32c2-hal?labelColor=1C2C2E&style=flat-square) -[![Matrix](https://img.shields.io/matrix/esp-rs:matrix.org?label=join%20matrix&labelColor=1C2C2E&color=BEC5C9&logo=matrix&style=flat-square)](https://matrix.to/#/#esp-rs:matrix.org) - -`no_std` HAL for the ESP32-C2 from Espressif. - -Implements a number of the traits defined in [embedded-hal](https://github.com/rust-embedded/embedded-hal). - -This device uses the RISC-V ISA, which is officially supported by the Rust compiler via the `riscv32imc-unknown-none-elf` target. - -Please refer to the documentation for more information. - -## [Documentation] - -[documentation]: https://docs.rs/esp32c2-hal/ - -## Resources - -- [Datasheet](https://www.espressif.com/sites/default/files/documentation/esp8684_datasheet_en.pdf) -- [Technical Reference Manual](https://www.espressif.com/sites/default/files/documentation/esp8684_technical_reference_manual_en.pdf) -- [The Rust Programming Language](https://doc.rust-lang.org/book/) -- [The Embedded Rust Book](https://docs.rust-embedded.org/book/index.html) -- [The Rust on ESP Book](https://esp-rs.github.io/book/) - -## Getting Started - -### Installing the Rust Compiler Target - -The compilation target for this device is officially supported by the mainline Rust compiler and can be installed using [rustup](https://rustup.rs/): - -```shell -rustup target add riscv32imc-unknown-none-elf -``` - -## License - -Licensed under either of: - -- Apache License, Version 2.0 ([LICENSE-APACHE](../LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) -- MIT license ([LICENSE-MIT](../LICENSE-MIT) or http://opensource.org/licenses/MIT) - -at your option. - -### Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in -the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without -any additional terms or conditions. diff --git a/esp32c2-hal/build.rs b/esp32c2-hal/build.rs deleted file mode 100644 index 023b7905b..000000000 --- a/esp32c2-hal/build.rs +++ /dev/null @@ -1,16 +0,0 @@ -use std::{env, error::Error, path::PathBuf}; - -fn main() -> Result<(), Box> { - // Put the linker script somewhere the linker can find it - let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - println!("cargo:rustc-link-search={}", out.display()); - - // Only re-run the build script when memory.x is changed, - // instead of when any part of the source code changes. - println!("cargo:rerun-if-changed=ld/memory.x"); - - #[cfg(feature = "defmt")] - println!("cargo:rustc-link-arg=-Tdefmt.x"); - - Ok(()) -} diff --git a/esp32c2-hal/examples/adc.rs b/esp32c2-hal/examples/adc.rs deleted file mode 100644 index 22dc19576..000000000 --- a/esp32c2-hal/examples/adc.rs +++ /dev/null @@ -1,39 +0,0 @@ -//! Connect a potentiometer to PIN2 and see the read values change when -//! rotating the shaft. Alternatively you could also connect the PIN to GND or -//! 3V3 to see the maximum and minimum raw values read. - -#![no_std] -#![no_main] - -use esp32c2_hal::{ - adc::{AdcConfig, Attenuation, ADC}, - clock::ClockControl, - gpio::IO, - peripherals::{Peripherals, ADC1}, - prelude::*, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create ADC instances - let mut adc1_config = AdcConfig::new(); - let mut pin = adc1_config.enable_pin(io.pins.gpio2.into_analog(), Attenuation::Attenuation11dB); - let mut adc1 = ADC::::new(peripherals.ADC1, adc1_config); - - let mut delay = Delay::new(&clocks); - - loop { - let pin_value: u16 = nb::block!(adc1.read(&mut pin)).unwrap(); - println!("PIN2 ADC reading = {}", pin_value); - delay.delay_ms(1500u32); - } -} diff --git a/esp32c2-hal/examples/advanced_serial.rs b/esp32c2-hal/examples/advanced_serial.rs deleted file mode 100644 index 2946bce18..000000000 --- a/esp32c2-hal/examples/advanced_serial.rs +++ /dev/null @@ -1,67 +0,0 @@ -//! This shows how to configure UART -//! You can short the TX and RX pin and see it reads what was written. -//! Additionally you can connect a logic analzyer to TX and see how the changes -//! of the configuration change the output signal. -//! -//! The following wiring is assumed: -//! - TX => GPIO1 -//! - RX => GPIO2 - -#![no_std] -#![no_main] - -use esp32c2_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, - uart::{ - config::{Config, DataBits, Parity, StopBits}, - TxRxPins, - }, - Uart, - IO, -}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let config = Config { - baudrate: 115200, - data_bits: DataBits::DataBits8, - parity: Parity::ParityNone, - stop_bits: StopBits::STOP1, - }; - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let pins = TxRxPins::new_tx_rx( - io.pins.gpio1.into_push_pull_output(), - io.pins.gpio2.into_floating_input(), - ); - - let mut serial1 = Uart::new_with_config(peripherals.UART1, config, Some(pins), &clocks); - - timer0.start(250u64.millis()); - - println!("Start"); - loop { - serial1.write(0x42).ok(); - let read = block!(serial1.read()); - - match read { - Ok(read) => println!("Read 0x{:02x}", read), - Err(err) => println!("Error {:?}", err), - } - - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32c2-hal/examples/blinky.rs b/esp32c2-hal/examples/blinky.rs deleted file mode 100644 index c3ba7e715..000000000 --- a/esp32c2-hal/examples/blinky.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! Blinks an LED -//! -//! This assumes that a LED is connected to the pin assigned to `led`. (GPIO5) - -#![no_std] -#![no_main] - -use esp32c2_hal::{clock::ClockControl, gpio::IO, peripherals::Peripherals, prelude::*, Delay}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Set GPIO5 as an output, and set its state high initially. - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut led = io.pins.gpio5.into_push_pull_output(); - - led.set_high().unwrap(); - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - loop { - led.toggle().unwrap(); - delay.delay_ms(500u32); - } -} diff --git a/esp32c2-hal/examples/blinky_erased_pins.rs b/esp32c2-hal/examples/blinky_erased_pins.rs deleted file mode 100644 index ae57ad2b3..000000000 --- a/esp32c2-hal/examples/blinky_erased_pins.rs +++ /dev/null @@ -1,53 +0,0 @@ -//! Blinks an LED -//! -//! This assumes that LEDs are connected to GPIO3, 4 and 5. - -#![no_std] -#![no_main] - -use esp32c2_hal::{ - clock::ClockControl, - gpio::{AnyPin, Input, Output, PullDown, PushPull, IO}, - peripherals::Peripherals, - prelude::*, - Delay, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Set LED GPIOs as an output. - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let led1 = io.pins.gpio3.into_push_pull_output(); - let led2 = io.pins.gpio4.into_push_pull_output(); - let led3 = io.pins.gpio5.into_push_pull_output(); - - // Set GPIO9 as an input. - let button = io.pins.gpio9.into_pull_down_input().into(); - - // You can use `into` or `degrade` - let mut pins = [led1.into(), led2.into(), led3.degrade().into()]; - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - loop { - toggle_pins(&mut pins, &button); - delay.delay_ms(500u32); - } -} - -fn toggle_pins(leds: &mut [AnyPin>], button: &AnyPin>) { - for pin in leds.iter_mut() { - pin.toggle().unwrap(); - } - - if button.is_low().unwrap() { - esp_println::println!("Button"); - } -} diff --git a/esp32c2-hal/examples/clock_monitor.rs b/esp32c2-hal/examples/clock_monitor.rs deleted file mode 100644 index cb7589c21..000000000 --- a/esp32c2-hal/examples/clock_monitor.rs +++ /dev/null @@ -1,65 +0,0 @@ -//! This demos a simple monitor for the XTAL frequency, by relying on a special -//! feature of the TIMG0 (Timer Group 0). This feature counts the number of XTAL -//! clock cycles within a given number of RTC_SLOW_CLK cycles. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32c2_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, - Rtc, -}; -use esp_backtrace as _; - -static RTC: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rtc = Rtc::new(peripherals.LPWR); - rtc.rwdt.start(2000u64.millis()); - rtc.rwdt.listen(); - - esp_println::println!( - "{: <10} XTAL frequency: {} MHz", - "[Expected]", - clocks.xtal_clock.to_MHz() - ); - - interrupt::enable( - peripherals::Interrupt::RTC_CORE, - interrupt::Priority::Priority1, - ) - .unwrap(); - - critical_section::with(|cs| { - RTC.borrow_ref_mut(cs).replace(rtc); - }); - - loop {} -} - -#[interrupt] -fn RTC_CORE() { - critical_section::with(|cs| { - let mut rtc = RTC.borrow(cs).borrow_mut(); - let rtc = rtc.as_mut().unwrap(); - - esp_println::println!( - "{: <10} XTAL frequency: {} MHz", - "[Monitor]", - rtc.estimate_xtal_frequency() - ); - - rtc.rwdt.clear_interrupt(); - }); -} diff --git a/esp32c2-hal/examples/crc.rs b/esp32c2-hal/examples/crc.rs deleted file mode 100644 index 8223fc83c..000000000 --- a/esp32c2-hal/examples/crc.rs +++ /dev/null @@ -1,95 +0,0 @@ -//! This shows example usage of the CRC functions in ROM - -#![no_std] -#![no_main] - -use core::fmt::Write; - -use esp32c2_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - rom::{crc, md5}, - timer::TimerGroup, - Uart, -}; -use esp_backtrace as _; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - timer0.start(1u64.secs()); - - let data = "123456789"; - let sentence = "The quick brown fox jumps over a lazy dog"; - - writeln!( - uart0, - "Performing CRC calculations on test string \"{data}\"" - ) - .unwrap(); - - loop { - let crc_hdlc = crc::crc32_le(!0xffffffff, data.as_ref()); - let crc_bzip2 = crc::crc32_be(!0xffffffff, data.as_ref()); - let crc_mpeg2 = !crc::crc32_be(!0xffffffff, data.as_ref()); - let crc_cksum = crc::crc32_be(!0, data.as_ref()); - let crc_kermit = !crc::crc16_le(!0, data.as_ref()); - let crc_genibus = crc::crc16_be(!0xffff, data.as_ref()); - let crc_rohc = !crc::crc8_le(!0xff, data.as_ref()); - let crc_smbus = !crc::crc8_be(!0, data.as_ref()); - - assert_eq!(crc_hdlc, 0xcbf43926); - assert_eq!(crc_bzip2, 0xfc891918); - assert_eq!(crc_mpeg2, 0x0376e6e7); - assert_eq!(crc_cksum, 0x765e7680); - assert_eq!(crc_kermit, 0x2189); - assert_eq!(crc_genibus, 0xd64e); - assert_eq!(crc_rohc, 0xd0); - assert_eq!(crc_smbus, 0xf4); - - // Hash the sentence one word at a time to *really* test the context - // Use Peekable while iter_intersperse is unstable - let mut md5_ctx = md5::Context::new(); - let mut it = sentence.split_whitespace().peekable(); - while let Some(word) = it.next() { - md5_ctx.consume(word); - if it.peek().is_some() { - md5_ctx.consume(" "); - } - } - let md5_digest = md5_ctx.compute(); - - assert_eq!( - md5_digest, - md5::Digest([ - 0x30, 0xde, 0xd8, 0x07, 0xd6, 0x5e, 0xe0, 0x37, 0x0f, 0xc6, 0xd7, 0x3d, 0x6a, 0xb5, - 0x5a, 0x95 - ]) - ); - - writeln!( - uart0, - "{:08x} {:08x} {:08x} {:08x} {:04x} {:04x} {:02x} {:02x} {}", - crc_hdlc, - crc_bzip2, - crc_mpeg2, - crc_cksum, - crc_kermit, - crc_genibus, - crc_rohc, - crc_smbus, - md5_digest - ) - .unwrap(); - - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32c2-hal/examples/debug_assist.rs b/esp32c2-hal/examples/debug_assist.rs deleted file mode 100644 index 7b55990db..000000000 --- a/esp32c2-hal/examples/debug_assist.rs +++ /dev/null @@ -1,76 +0,0 @@ -//! This shows debug-assist - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32c2_hal::{ - assist_debug::DebugAssist, - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, -}; -use esp_backtrace as _; -use esp_println::println; - -static DA: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut da = DebugAssist::new(peripherals.ASSIST_DEBUG); - - extern "C" { - // top of stack - static mut _stack_start: u32; - // bottom of stack - static mut _stack_end: u32; - } - - let stack_top = unsafe { &mut _stack_start } as *mut _ as u32; - let stack_bottom = unsafe { &mut _stack_end } as *mut _ as u32; - - da.enable_sp_monitor(stack_bottom + 4096, stack_top); - - critical_section::with(|cs| DA.borrow_ref_mut(cs).replace(da)); - - interrupt::enable( - peripherals::Interrupt::ASSIST_DEBUG, - interrupt::Priority::Priority3, - ) - .unwrap(); - - eat_up_stack(0); - - loop {} -} - -#[allow(unconditional_recursion)] -fn eat_up_stack(v: u32) { - println!("Iteration {v}"); - eat_up_stack(v + 1); -} - -#[interrupt] -fn ASSIST_DEBUG() { - critical_section::with(|cs| { - println!("\n\nDEBUG_ASSIST interrupt"); - let mut da = DA.borrow_ref_mut(cs); - let da = da.as_mut().unwrap(); - - if da.is_sp_monitor_interrupt_set() { - println!("SP MONITOR TRIGGERED"); - da.clear_sp_monitor_interrupt(); - let pc = da.get_sp_monitor_pc(); - println!("PC = 0x{:x}", pc); - } - - loop {} - }); -} diff --git a/esp32c2-hal/examples/direct-vectoring.rs b/esp32c2-hal/examples/direct-vectoring.rs deleted file mode 100644 index 115371250..000000000 --- a/esp32c2-hal/examples/direct-vectoring.rs +++ /dev/null @@ -1,73 +0,0 @@ -#![no_main] -#![no_std] -#![feature(naked_functions)] -use core::{arch::asm, cell::RefCell}; - -use critical_section::Mutex; -use esp32c2_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - system::{SoftwareInterrupt, SoftwareInterruptControl}, -}; -use esp_backtrace as _; - -static SWINT: Mutex>> = Mutex::new(RefCell::new(None)); -#[entry] -unsafe fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clockctrl = system.clock_control; - let sw_int = system.software_interrupt_control; - let _clocks = ClockControl::boot_defaults(clockctrl).freeze(); - - critical_section::with(|cs| SWINT.borrow_ref_mut(cs).replace(sw_int)); - unsafe { - asm!( - " - csrrwi x0, 0x7e0, 1 #what to count, for cycles write 1 for instructions write 2 - csrrwi x0, 0x7e1, 0 #disable counter - csrrwi x0, 0x7e2, 0 #reset counter - " - ); - } - esp_println::println!("MPC:{}", unsafe { fetch_performance_timer() }); - // interrupt is raised from assembly for max timer granularity. - unsafe { - asm!( - " - li t0, 0x600C0028 #FROM_CPU_INTR0 address - li t1, 1 #Flip flag - csrrwi x0, 0x7e1, 1 #enable timer - sw t1, 0(t0) #trigger FROM_CPU_INTR0 - " - ) - } - esp_println::println!("Returned"); - loop {} -} - -#[no_mangle] -fn cpu_int_1_handler() { - unsafe { asm!("csrrwi x0, 0x7e1, 0 #disable timer") } - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt0); - }); - esp_println::println!("Performance counter:{}", unsafe { - fetch_performance_timer() - }); -} -#[naked] -unsafe extern "C" fn fetch_performance_timer() -> i32 { - asm!( - " - csrr a0, 0x7e2 - jr ra - ", - options(noreturn) - ); -} diff --git a/esp32c2-hal/examples/ecc.rs b/esp32c2-hal/examples/ecc.rs deleted file mode 100644 index ec87daf49..000000000 --- a/esp32c2-hal/examples/ecc.rs +++ /dev/null @@ -1,801 +0,0 @@ -//! Demonstrates the use of the ECC peripheral and compares the speed of -//! hardware-accelerated and pure software ECC. - -#![no_std] -#![no_main] - -use core::ops::Mul; - -use crypto_bigint::{ - modular::runtime_mod::{DynResidue, DynResidueParams}, - Encoding, - U192, - U256, -}; -use elliptic_curve::sec1::ToEncodedPoint; -use esp32c2_hal::{ - ecc::{Ecc, EllipticCurve, Error}, - peripherals::Peripherals, - prelude::*, - systimer::SystemTimer, - Rng, -}; -use esp_backtrace as _; -use esp_println::{print, println}; -use hex_literal::hex; - -struct TestParams<'a> { - prime_fields: &'a [&'a [u8]], - nb_loop_mul: usize, - nb_loop_inv: usize, -} - -const TEST_PARAMS_VECTOR: TestParams = TestParams { - prime_fields: &[ - &hex!("fffffffffffffffffffffffffffffffeffffffffffffffff"), - &hex!("ffffffff00000001000000000000000000000000ffffffffffffffffffffffff"), - ], - nb_loop_mul: 10, - nb_loop_inv: 20, -}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let _system = peripherals.SYSTEM.split(); - - let mut rng = Rng::new(peripherals.RNG); - - println!("ECC example"); - - let mut hw_ecc = Ecc::new(peripherals.ECC); - - println!("Beginning stress tests..."); - test_affine_point_multiplication(&mut hw_ecc, &mut rng); - test_finite_field_division(&mut hw_ecc, &mut rng); - test_affine_point_verification(&mut hw_ecc, &mut rng); - test_afine_point_verification_multiplication(&mut hw_ecc, &mut rng); - test_jacobian_point_multiplication(&mut hw_ecc, &mut rng); - test_jacobian_point_verification(&mut hw_ecc, &mut rng); - test_afine_point_verification_jacobian_multiplication(&mut hw_ecc, &mut rng); - println!("Finished stress tests!"); - - loop {} -} - -fn test_affine_point_multiplication(ecc: &mut Ecc, rng: &mut Rng) { - for &prime_field in TEST_PARAMS_VECTOR.prime_fields { - print!("Beginning affine point multiplication tests over "); - match prime_field.len() { - 24 => print!("secp192r1..."), - _ => print!("secp256r1..."), - }; - let t1 = &mut [0_u8; 96]; - let (k, x) = t1.split_at_mut(prime_field.len()); - let (x, y) = x.split_at_mut(prime_field.len()); - let (y, _) = y.split_at_mut(prime_field.len()); - let mut delta_time = 0; - for _ in 0..TEST_PARAMS_VECTOR.nb_loop_mul { - loop { - rng.read(k).unwrap(); - let is_zero = k.iter().all(|&elt| elt == 0); - let is_modulus = k.iter().zip(prime_field).all(|(&a, &b)| a == b); - if is_zero == false && is_modulus == false { - break; - } - } - let curve = match prime_field.len() { - 24 => { - x.copy_from_slice( - p192::AffinePoint::GENERATOR - .to_encoded_point(false) - .x() - .unwrap(), - ); - y.copy_from_slice( - p192::AffinePoint::GENERATOR - .to_encoded_point(false) - .y() - .unwrap(), - ); - &EllipticCurve::P192 - } - 32 => { - x.copy_from_slice( - p256::AffinePoint::GENERATOR - .to_encoded_point(false) - .x() - .unwrap(), - ); - y.copy_from_slice( - p256::AffinePoint::GENERATOR - .to_encoded_point(false) - .y() - .unwrap(), - ); - &EllipticCurve::P256 - } - _ => unimplemented!(), - }; - - let begin_time = SystemTimer::now(); - ecc.affine_point_multiplication(curve, k, x, y) - .expect("Inputs data doesn't match the key length selected."); - let end_time = SystemTimer::now(); - delta_time += end_time - begin_time; - - let t2 = &mut [0_u8; 64]; - - let (sw_x, sw_y) = t2.split_at_mut(prime_field.len()); - let (sw_y, _) = sw_y.split_at_mut(prime_field.len()); - - match prime_field.len() { - 24 => { - let sw_k = - p192::Scalar::from(elliptic_curve::ScalarPrimitive::from_slice(k).unwrap()); - let q = p192::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - sw_x.copy_from_slice(q.x().unwrap().as_slice()); - sw_y.copy_from_slice(q.y().unwrap().as_slice()); - } - 32 => { - let sw_k = - p256::Scalar::from(elliptic_curve::ScalarPrimitive::from_slice(k).unwrap()); - let q = p256::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - sw_x.copy_from_slice(q.x().unwrap().as_slice()); - sw_y.copy_from_slice(q.y().unwrap().as_slice()); - } - _ => unimplemented!(), - }; - - for (a, b) in x.iter().zip(sw_x) { - assert_eq!( - a, b, - "ECC failed during affine point multiplication with d_a = {:02X?} ({:02X?} != {:02X?})", - k, a, b, - ); - } - - for (a, b) in y.iter().zip(sw_y) { - assert_eq!( - a, b, - "ECC failed during affine point multiplication with d_a = {:02X?} ({:02X?} != {:02X?})", - k, a, b, - ); - } - } - println!( - "ok (it took {} cycles in average)", - delta_time / (TEST_PARAMS_VECTOR.nb_loop_mul as u64) - ); - } -} - -fn test_finite_field_division(ecc: &mut Ecc, rng: &mut Rng) { - for &prime_field in TEST_PARAMS_VECTOR.prime_fields { - print!("Beginning finite field division tests over "); - match prime_field.len() { - 24 => print!("P-192..."), - 32 => print!("P-256..."), - _ => unimplemented!(), - }; - let t1 = &mut [0_u8; 64]; - let (k, y) = t1.split_at_mut(prime_field.len()); - let (y, _) = y.split_at_mut(prime_field.len()); - let mut delta_time = 0; - for _ in 0..TEST_PARAMS_VECTOR.nb_loop_inv { - loop { - rng.read(k).unwrap(); - rng.read(y).unwrap(); - let is_zero = k.iter().all(|&elt| elt == 0) || y.iter().all(|&elt| elt == 0); - let is_modulus = k.iter().zip(prime_field).all(|(&a, &b)| a == b) - || y.iter().zip(prime_field).all(|(&a, &b)| a == b); - if is_zero == false && is_modulus == false { - break; - } - } - let t2 = &mut [0_u8; 96]; - let (sw_y, sw_k) = t2.split_at_mut(prime_field.len()); - let (sw_k, sw_res) = sw_k.split_at_mut(prime_field.len()); - let (sw_res, _) = sw_res.split_at_mut(prime_field.len()); - sw_y.copy_from_slice(y); - sw_k.copy_from_slice(k); - let curve = match prime_field.len() { - 24 => &EllipticCurve::P192, - 32 => &EllipticCurve::P256, - _ => unimplemented!(), - }; - - let begin_time = SystemTimer::now(); - ecc.finite_field_division(curve, k, y) - .expect("Inputs data doesn't match the key length selected."); - let end_time = SystemTimer::now(); - delta_time += end_time - begin_time; - - match prime_field.len() { - 24 => { - let modulus = DynResidueParams::new(&U192::from_be_slice(prime_field)); - let sw_y = DynResidue::new(&U192::from_be_slice(sw_y), modulus); - let sw_k = DynResidue::new(&U192::from_be_slice(sw_k), modulus); - let sw_inv_k = sw_k.invert().0; - sw_res.copy_from_slice(sw_y.mul(&sw_inv_k).retrieve().to_be_bytes().as_slice()); - } - 32 => { - let modulus = DynResidueParams::new(&U256::from_be_slice(prime_field)); - let sw_y = DynResidue::new(&U256::from_be_slice(sw_y), modulus); - let sw_k = DynResidue::new(&U256::from_be_slice(sw_k), modulus); - let sw_inv_k = sw_k.invert().0; - sw_res.copy_from_slice(sw_y.mul(&sw_inv_k).retrieve().to_be_bytes().as_slice()); - } - _ => unimplemented!(), - }; - - for (a, b) in y.iter().zip(sw_res) { - assert_eq!( - a, b, - "ECC failed during finite field division with \np_y = {:02X?}\nk= {:02X?}", - sw_y, sw_k, - ); - } - } - println!( - "ok (it took {} cycles in average)", - delta_time / (TEST_PARAMS_VECTOR.nb_loop_inv as u64) - ); - } -} - -fn test_affine_point_verification(ecc: &mut Ecc, rng: &mut Rng) { - for &prime_field in TEST_PARAMS_VECTOR.prime_fields { - print!("Beginning affine point verification tests over "); - match prime_field.len() { - 24 => print!("secp192r1..."), - _ => print!("secp256r1..."), - }; - let t1 = &mut [0_u8; 96]; - let (k, x) = t1.split_at_mut(prime_field.len()); - let (x, y) = x.split_at_mut(prime_field.len()); - let (y, _) = y.split_at_mut(prime_field.len()); - let mut delta_time = 0; - for _ in 0..TEST_PARAMS_VECTOR.nb_loop_mul { - loop { - rng.read(k).unwrap(); - let is_zero = k.iter().all(|&elt| elt == 0); - let is_modulus = k.iter().zip(prime_field).all(|(&a, &b)| a == b); - if is_zero == false && is_modulus == false { - break; - } - } - - let curve = match prime_field.len() { - 24 => { - let sw_k = - p192::Scalar::from(elliptic_curve::ScalarPrimitive::from_slice(k).unwrap()); - let q = p192::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - x.copy_from_slice(q.x().unwrap().as_slice()); - y.copy_from_slice(q.y().unwrap().as_slice()); - &EllipticCurve::P192 - } - 32 => { - let sw_k = - p256::Scalar::from(elliptic_curve::ScalarPrimitive::from_slice(k).unwrap()); - let q = p256::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - x.copy_from_slice(q.x().unwrap().as_slice()); - y.copy_from_slice(q.y().unwrap().as_slice()); - &EllipticCurve::P256 - } - _ => unimplemented!(), - }; - - let begin_time = SystemTimer::now(); - match ecc.affine_point_verification(&curve, x, y) { - Err(Error::SizeMismatchCurve) => { - assert!(false, "Inputs data doesn't match the key length selected.") - } - Err(Error::PointNotOnSelectedCurve) => assert!( - false, - "ECC failed while affine point verification with x = {:02X?} and y = {:02X?}.", - x, y, - ), - _ => {} - } - let end_time = SystemTimer::now(); - delta_time += end_time - begin_time; - } - println!( - "ok (it took {} cycles in average)", - delta_time / (TEST_PARAMS_VECTOR.nb_loop_mul as u64) - ); - } -} - -fn test_afine_point_verification_multiplication(ecc: &mut Ecc, rng: &mut Rng) { - for &prime_field in TEST_PARAMS_VECTOR.prime_fields { - print!("Beginning affine point verification + multiplication tests over "); - match prime_field.len() { - 24 => print!("secp192r1..."), - _ => print!("secp256r1..."), - }; - let t1 = &mut [0_u8; 96]; - let (k, x) = t1.split_at_mut(prime_field.len()); - let (x, y) = x.split_at_mut(prime_field.len()); - let (y, _) = y.split_at_mut(prime_field.len()); - let mut delta_time = 0; - for _ in 0..TEST_PARAMS_VECTOR.nb_loop_mul { - loop { - rng.read(k).unwrap(); - let is_zero = k.iter().all(|&elt| elt == 0); - let is_modulus = k.iter().zip(prime_field).all(|(&a, &b)| a == b); - if is_zero == false && is_modulus == false { - break; - } - } - let curve = match prime_field.len() { - 24 => { - x.copy_from_slice( - p192::AffinePoint::GENERATOR - .to_encoded_point(false) - .x() - .unwrap(), - ); - y.copy_from_slice( - p192::AffinePoint::GENERATOR - .to_encoded_point(false) - .y() - .unwrap(), - ); - &EllipticCurve::P192 - } - 32 => { - x.copy_from_slice( - p256::AffinePoint::GENERATOR - .to_encoded_point(false) - .x() - .unwrap(), - ); - y.copy_from_slice( - p256::AffinePoint::GENERATOR - .to_encoded_point(false) - .y() - .unwrap(), - ); - &EllipticCurve::P256 - } - _ => unimplemented!(), - }; - - let begin_time = SystemTimer::now(); - match ecc.affine_point_verification_multiplication(curve, k, x, y) { - Err(Error::SizeMismatchCurve) => assert!(false, "Inputs data doesn't match the key length selected."), - Err(Error::PointNotOnSelectedCurve) => assert!( - false, "ECC failed while affine point verification + multiplication with x = {:02X?} and y = {:02X?}.", - x, y, - ), - _ => {}, - } - let end_time = SystemTimer::now(); - delta_time += end_time - begin_time; - - let t2 = &mut [0_u8; 64]; - - let (sw_x, sw_y) = t2.split_at_mut(prime_field.len()); - let (sw_y, _) = sw_y.split_at_mut(prime_field.len()); - - match prime_field.len() { - 24 => { - let sw_k = - p192::Scalar::from(elliptic_curve::ScalarPrimitive::from_slice(k).unwrap()); - let q = p192::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - sw_x.copy_from_slice(q.x().unwrap().as_slice()); - sw_y.copy_from_slice(q.y().unwrap().as_slice()); - } - 32 => { - let sw_k = - p256::Scalar::from(elliptic_curve::ScalarPrimitive::from_slice(k).unwrap()); - let q = p256::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - sw_x.copy_from_slice(q.x().unwrap().as_slice()); - sw_y.copy_from_slice(q.y().unwrap().as_slice()); - } - _ => unimplemented!(), - }; - - for (a, b) in x.iter().zip(sw_x) { - assert_eq!( - a, b, - "ECC failed during affine point verification + multiplication with d_a = {:02X?} ({:02X?} != {:02X?})", - k, a, b, - ); - } - - for (a, b) in y.iter().zip(sw_y) { - assert_eq!( - a, b, - "ECC failed during affine point verification + multiplication with d_a = {:02X?} ({:02X?} != {:02X?})", - k, a, b, - ); - } - } - println!( - "ok (it took {} cycles in average)", - delta_time / (TEST_PARAMS_VECTOR.nb_loop_mul as u64) - ); - } -} - -fn test_jacobian_point_multiplication(ecc: &mut Ecc, rng: &mut Rng) { - for &prime_field in TEST_PARAMS_VECTOR.prime_fields { - print!("Beginning jacobian point multiplication tests over "); - match prime_field.len() { - 24 => print!("secp192r1..."), - _ => print!("secp256r1..."), - }; - let t1 = &mut [0_u8; 96]; - let (k, x) = t1.split_at_mut(prime_field.len()); - let (x, y) = x.split_at_mut(prime_field.len()); - let (y, _) = y.split_at_mut(prime_field.len()); - let mut delta_time = 0; - for _ in 0..TEST_PARAMS_VECTOR.nb_loop_mul { - let t2 = &mut [0_u8; 96]; - - let (sw_x, sw_y) = t2.split_at_mut(prime_field.len()); - let (sw_y, sw_k) = sw_y.split_at_mut(prime_field.len()); - let (sw_k, _) = sw_k.split_at_mut(prime_field.len()); - - loop { - rng.read(k).unwrap(); - let is_zero = k.iter().all(|&elt| elt == 0); - let is_modulus = k.iter().zip(prime_field).all(|(&a, &b)| a == b); - if is_zero == false && is_modulus == false { - break; - } - } - sw_k.copy_from_slice(k); - let curve = match prime_field.len() { - 24 => { - x.copy_from_slice( - p192::AffinePoint::GENERATOR - .to_encoded_point(false) - .x() - .unwrap(), - ); - y.copy_from_slice( - p192::AffinePoint::GENERATOR - .to_encoded_point(false) - .y() - .unwrap(), - ); - &EllipticCurve::P192 - } - 32 => { - x.copy_from_slice( - p256::AffinePoint::GENERATOR - .to_encoded_point(false) - .x() - .unwrap(), - ); - y.copy_from_slice( - p256::AffinePoint::GENERATOR - .to_encoded_point(false) - .y() - .unwrap(), - ); - &EllipticCurve::P256 - } - _ => unimplemented!(), - }; - - let begin_time = SystemTimer::now(); - ecc.jacobian_point_multiplication(curve, k, x, y) - .expect("Inputs data doesn't match the key length selected."); - let end_time = SystemTimer::now(); - delta_time += end_time - begin_time; - - match prime_field.len() { - 24 => { - let sw_k = p192::Scalar::from( - elliptic_curve::ScalarPrimitive::from_slice(sw_k).unwrap(), - ); - let q = p192::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - let modulus = DynResidueParams::new(&U192::from_be_slice(prime_field)); - let x_affine = - DynResidue::new(&U192::from_be_slice(q.x().unwrap().as_slice()), modulus); - let y_affine = - DynResidue::new(&U192::from_be_slice(q.y().unwrap().as_slice()), modulus); - let z = DynResidue::new(&U192::from_be_slice(k), modulus); - let x_jacobian = x_affine * z * z; - let y_jacobian = y_affine * z * z * z; - sw_x.copy_from_slice(x_jacobian.retrieve().to_be_bytes().as_slice()); - sw_y.copy_from_slice(y_jacobian.retrieve().to_be_bytes().as_slice()); - } - 32 => { - let sw_k = p256::Scalar::from( - elliptic_curve::ScalarPrimitive::from_slice(sw_k).unwrap(), - ); - let q = p256::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - let modulus = DynResidueParams::new(&U256::from_be_slice(prime_field)); - let x_affine = - DynResidue::new(&U256::from_be_slice(q.x().unwrap().as_slice()), modulus); - let y_affine = - DynResidue::new(&U256::from_be_slice(q.y().unwrap().as_slice()), modulus); - let z = DynResidue::new(&U256::from_be_slice(k), modulus); - let x_jacobian = x_affine * z * z; - let y_jacobian = y_affine * z * z * z; - sw_x.copy_from_slice(x_jacobian.retrieve().to_be_bytes().as_slice()); - sw_y.copy_from_slice(y_jacobian.retrieve().to_be_bytes().as_slice()); - } - _ => unimplemented!(), - }; - - for (a, b) in x.iter().zip(sw_x.iter()) { - assert_eq!( - a, b, - "ECC failed during jacobian point multiplication.\nX = {:02X?}\nX = {:02X?}", - x, sw_x, - ); - } - - for (a, b) in y.iter().zip(sw_y.iter()) { - assert_eq!( - a, b, - "ECC failed during jacobian point multiplication.\nY = {:02X?}\nY = {:02X?}", - y, sw_y, - ); - } - } - println!( - "ok (it took {} cycles in average)", - delta_time / (TEST_PARAMS_VECTOR.nb_loop_mul as u64) - ); - } -} - -fn test_jacobian_point_verification(ecc: &mut Ecc, rng: &mut Rng) { - for &prime_field in TEST_PARAMS_VECTOR.prime_fields { - print!("Beginning jacobian point verification tests over "); - match prime_field.len() { - 24 => print!("secp192r1..."), - _ => print!("secp256r1..."), - }; - let t1 = &mut [0_u8; 128]; - let (k, x) = t1.split_at_mut(prime_field.len()); - let (x, y) = x.split_at_mut(prime_field.len()); - let (y, z) = y.split_at_mut(prime_field.len()); - let (z, _) = z.split_at_mut(prime_field.len()); - let mut delta_time = 0; - for _ in 0..TEST_PARAMS_VECTOR.nb_loop_mul { - loop { - rng.read(k).unwrap(); - rng.read(z).unwrap(); - let is_zero = k.iter().all(|&elt| elt == 0) || z.iter().all(|&elt| elt == 0); - let is_modulus = k.iter().zip(prime_field).all(|(&a, &b)| a == b) - || z.iter().zip(prime_field).all(|(&a, &b)| a == b); - if is_zero == false && is_modulus == false { - break; - } - } - - let curve = match prime_field.len() { - 24 => { - let sw_k = - p192::Scalar::from(elliptic_curve::ScalarPrimitive::from_slice(k).unwrap()); - let q = p192::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - let modulus = DynResidueParams::new(&U192::from_be_slice(prime_field)); - let x_affine = - DynResidue::new(&U192::from_be_slice(q.x().unwrap().as_slice()), modulus); - let y_affine = - DynResidue::new(&U192::from_be_slice(q.y().unwrap().as_slice()), modulus); - let z = DynResidue::new(&U192::from_be_slice(z), modulus); - let x_jacobian = x_affine * z * z; - let y_jacobian = y_affine * z * z * z; - x.copy_from_slice(x_jacobian.retrieve().to_be_bytes().as_slice()); - y.copy_from_slice(y_jacobian.retrieve().to_be_bytes().as_slice()); - &EllipticCurve::P192 - } - 32 => { - let sw_k = - p256::Scalar::from(elliptic_curve::ScalarPrimitive::from_slice(k).unwrap()); - let q = p256::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - let modulus = DynResidueParams::new(&U256::from_be_slice(prime_field)); - let x_affine = - DynResidue::new(&U256::from_be_slice(q.x().unwrap().as_slice()), modulus); - let y_affine = - DynResidue::new(&U256::from_be_slice(q.y().unwrap().as_slice()), modulus); - let z = DynResidue::new(&U256::from_be_slice(z), modulus); - let x_jacobian = x_affine * z * z; - let y_jacobian = y_affine * z * z * z; - x.copy_from_slice(x_jacobian.retrieve().to_be_bytes().as_slice()); - y.copy_from_slice(y_jacobian.retrieve().to_be_bytes().as_slice()); - &EllipticCurve::P256 - } - _ => unimplemented!(), - }; - - let begin_time = SystemTimer::now(); - match ecc.jacobian_point_verification(&curve, x, y, z) { - Err(Error::SizeMismatchCurve) => { - assert!(false, "Inputs data doesn't match the key length selected.") - } - Err(Error::PointNotOnSelectedCurve) => assert!( - false, - "ECC failed while base point verification with x = {:02X?} and y = {:02X?}.", - x, y, - ), - _ => {} - } - let end_time = SystemTimer::now(); - delta_time += end_time - begin_time; - } - println!( - "ok (it took {} cycles in average)", - delta_time / (TEST_PARAMS_VECTOR.nb_loop_mul as u64) - ); - } -} - -fn test_afine_point_verification_jacobian_multiplication(ecc: &mut Ecc, rng: &mut Rng) { - for &prime_field in TEST_PARAMS_VECTOR.prime_fields { - print!("Beginning affine point verification + jacobian point multiplication tests over "); - match prime_field.len() { - 24 => print!("secp192r1..."), - _ => print!("secp256r1..."), - }; - let t1 = &mut [0_u8; 96]; - let (k, x) = t1.split_at_mut(prime_field.len()); - let (x, y) = x.split_at_mut(prime_field.len()); - let (y, _) = y.split_at_mut(prime_field.len()); - let mut delta_time = 0; - for _ in 0..TEST_PARAMS_VECTOR.nb_loop_mul { - let t2 = &mut [0_u8; 96]; - - let (sw_x, sw_y) = t2.split_at_mut(prime_field.len()); - let (sw_y, sw_k) = sw_y.split_at_mut(prime_field.len()); - let (sw_k, _) = sw_k.split_at_mut(prime_field.len()); - - loop { - rng.read(k).unwrap(); - let is_zero = k.iter().all(|&elt| elt == 0); - let is_modulus = k.iter().zip(prime_field).all(|(&a, &b)| a == b); - if is_zero == false && is_modulus == false { - break; - } - } - sw_k.copy_from_slice(k); - let curve = match prime_field.len() { - 24 => { - x.copy_from_slice( - p192::AffinePoint::GENERATOR - .to_encoded_point(false) - .x() - .unwrap(), - ); - y.copy_from_slice( - p192::AffinePoint::GENERATOR - .to_encoded_point(false) - .y() - .unwrap(), - ); - &EllipticCurve::P192 - } - 32 => { - x.copy_from_slice( - p256::AffinePoint::GENERATOR - .to_encoded_point(false) - .x() - .unwrap(), - ); - y.copy_from_slice( - p256::AffinePoint::GENERATOR - .to_encoded_point(false) - .y() - .unwrap(), - ); - &EllipticCurve::P256 - } - _ => unimplemented!(), - }; - - let begin_time = SystemTimer::now(); - match ecc.affine_point_verification_jacobian_multiplication(curve, k, x, y) { - Err(Error::SizeMismatchCurve) => assert!(false, "Inputs data doesn't match the key length selected."), - Err(Error::PointNotOnSelectedCurve) => assert!( - false, "ECC failed while affine point verification + multiplication with x = {:02X?} and y = {:02X?}.", - x, y, - ), - _ => {}, - } - let end_time = SystemTimer::now(); - delta_time += end_time - begin_time; - - match prime_field.len() { - 24 => { - let sw_k = p192::Scalar::from( - elliptic_curve::ScalarPrimitive::from_slice(sw_k).unwrap(), - ); - let q = p192::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - let modulus = DynResidueParams::new(&U192::from_be_slice(prime_field)); - let x_affine = - DynResidue::new(&U192::from_be_slice(q.x().unwrap().as_slice()), modulus); - let y_affine = - DynResidue::new(&U192::from_be_slice(q.y().unwrap().as_slice()), modulus); - let z = DynResidue::new(&U192::from_be_slice(k), modulus); - let x_jacobian = x_affine * z * z; - let y_jacobian = y_affine * z * z * z; - sw_x.copy_from_slice(x_jacobian.retrieve().to_be_bytes().as_slice()); - sw_y.copy_from_slice(y_jacobian.retrieve().to_be_bytes().as_slice()); - } - 32 => { - let sw_k = p256::Scalar::from( - elliptic_curve::ScalarPrimitive::from_slice(sw_k).unwrap(), - ); - let q = p256::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - let modulus = DynResidueParams::new(&U256::from_be_slice(prime_field)); - let x_affine = - DynResidue::new(&U256::from_be_slice(q.x().unwrap().as_slice()), modulus); - let y_affine = - DynResidue::new(&U256::from_be_slice(q.y().unwrap().as_slice()), modulus); - let z = DynResidue::new(&U256::from_be_slice(k), modulus); - let x_jacobian = x_affine * z * z; - let y_jacobian = y_affine * z * z * z; - sw_x.copy_from_slice(x_jacobian.retrieve().to_be_bytes().as_slice()); - sw_y.copy_from_slice(y_jacobian.retrieve().to_be_bytes().as_slice()); - } - _ => unimplemented!(), - }; - - for (a, b) in x.iter().zip(sw_x.iter()) { - assert_eq!( - a, b, - "ECC failed during affine point verification + jacobian point multiplication.\nX = {:02X?}\nX = {:02X?}", - x, sw_x, - ); - } - - for (a, b) in y.iter().zip(sw_y.iter()) { - assert_eq!( - a, b, - "ECC failed during affine point verification + jacobian point multiplication.\nY = {:02X?}\nY = {:02X?}", - y, sw_y, - ); - } - } - println!( - "ok (it took {} cycles in average)", - delta_time / (TEST_PARAMS_VECTOR.nb_loop_mul as u64) - ); - } -} diff --git a/esp32c2-hal/examples/embassy_hello_world.rs b/esp32c2-hal/examples/embassy_hello_world.rs deleted file mode 100644 index 4c32f9c22..000000000 --- a/esp32c2-hal/examples/embassy_hello_world.rs +++ /dev/null @@ -1,48 +0,0 @@ -//! embassy hello world -//! -//! This is an example of running the embassy executor with multiple tasks -//! concurrently. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32c2_hal::{clock::ClockControl, embassy, peripherals::Peripherals, prelude::*}; -use esp_backtrace as _; - -#[embassy_executor::task] -async fn run() { - loop { - esp_println::println!("Hello world from embassy using esp-hal-async!"); - Timer::after(Duration::from_millis(1_000)).await; - } -} - -#[main] -async fn main(spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32c2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - spawner.spawn(run()).ok(); - - loop { - esp_println::println!("Bing!"); - Timer::after(Duration::from_millis(5_000)).await; - } -} diff --git a/esp32c2-hal/examples/embassy_i2c.rs b/esp32c2-hal/examples/embassy_i2c.rs deleted file mode 100644 index f63cf271b..000000000 --- a/esp32c2-hal/examples/embassy_i2c.rs +++ /dev/null @@ -1,67 +0,0 @@ -//! Embassy I2C -//! -//! Folowing pins are used: -//! SDA GPIO1 -//! SCL GPIO2 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This is an example of running the embassy executor with IC2. It uses an -//! LIS3DH to get accelerometer data. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32c2_hal::{ - clock::ClockControl, - embassy, - i2c::I2C, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; -use lis3dh_async::{Lis3dh, Range, SlaveAddr}; - -#[main] -async fn main(_spawner: Spawner) { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32c2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let i2c0 = I2C::new( - peripherals.I2C0, - io.pins.gpio1, - io.pins.gpio2, - 400u32.kHz(), - &clocks, - ); - - let mut lis3dh = Lis3dh::new_i2c(i2c0, SlaveAddr::Alternate).await.unwrap(); - lis3dh.set_range(Range::G8).await.unwrap(); - - loop { - let norm = lis3dh.accel_norm().await.unwrap(); - esp_println::println!("X: {:+.5} Y: {:+.5} Z: {:+.5}", norm.x, norm.y, norm.z); - - Timer::after(Duration::from_millis(100)).await; - } -} diff --git a/esp32c2-hal/examples/embassy_multiprio.rs b/esp32c2-hal/examples/embassy_multiprio.rs deleted file mode 100644 index d60fdca73..000000000 --- a/esp32c2-hal/examples/embassy_multiprio.rs +++ /dev/null @@ -1,100 +0,0 @@ -//! This example shows how to use the interrupt executors to prioritize some -//! tasks over others. -//! -//! The example creates three tasks: -//! - A low priority task that is not actually async, but simulates some -//! blocking work. This task will run for 5 seconds, then sleep for 5 -//! seconds. -//! - A low priority task that is actually async, but will not be able to run -//! while the blocking task is running. -//! - A high priority task that prints something every second. The example -//! demonstrates that this task will continue to run even while the low -//! priority blocking task is running. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Instant, Ticker, Timer}; -use esp32c2_hal::{ - clock::ClockControl, - embassy::{ - self, - executor::{FromCpu1, InterruptExecutor}, - }, - interrupt::Priority, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; -use esp_println::println; - -static INT_EXECUTOR_0: InterruptExecutor = InterruptExecutor::new(); - -#[interrupt] -fn FROM_CPU_INTR1() { - unsafe { INT_EXECUTOR_0.on_interrupt() } -} - -/// Periodically print something. -#[embassy_executor::task] -async fn high_prio() { - println!("Starting high_prio()"); - let mut ticker = Ticker::every(Duration::from_secs(1)); - loop { - println!("High priority ticks"); - ticker.next().await; - } -} - -/// Simulates some blocking (badly behaving) task. -#[embassy_executor::task] -async fn low_prio_blocking() { - println!("Starting low-priority task that isn't actually async"); - loop { - println!("Doing some long and complicated calculation"); - let start = Instant::now(); - while start.elapsed() < Duration::from_secs(5) {} - println!("Calculation finished"); - Timer::after(Duration::from_secs(5)).await; - } -} - -/// A well-behaved, but starved async task. -#[embassy_executor::task] -async fn low_prio_async() { - println!("Starting low-priority task that will not be able to run while the blocking task is running"); - let mut ticker = Ticker::every(Duration::from_secs(1)); - loop { - println!("Low priority ticks"); - ticker.next().await; - } -} - -#[main] -async fn main(low_prio_spawner: Spawner) { - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32c2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let spawner = INT_EXECUTOR_0.start(Priority::Priority2); - spawner.must_spawn(high_prio()); - - println!("Spawning low-priority tasks"); - low_prio_spawner.must_spawn(low_prio_async()); - low_prio_spawner.must_spawn(low_prio_blocking()); -} diff --git a/esp32c2-hal/examples/embassy_serial.rs b/esp32c2-hal/examples/embassy_serial.rs deleted file mode 100644 index 7c52fe423..000000000 --- a/esp32c2-hal/examples/embassy_serial.rs +++ /dev/null @@ -1,96 +0,0 @@ -//! embassy serial -//! -//! This is an example of running the embassy executor and asynchronously -//! writing to and reading from uart - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_sync::{blocking_mutex::raw::NoopRawMutex, signal::Signal}; -use esp32c2_hal::{ - clock::ClockControl, - embassy, - peripherals::{Peripherals, UART0}, - prelude::*, - uart::{config::AtCmdConfig, UartRx, UartTx}, - Uart, -}; -use esp_backtrace as _; -use static_cell::make_static; - -// rx_fifo_full_threshold -const READ_BUF_SIZE: usize = 64; -// EOT (CTRL-D) -const AT_CMD: u8 = 0x04; - -#[embassy_executor::task] -async fn writer(mut tx: UartTx<'static, UART0>, signal: &'static Signal) { - use core::fmt::Write; - embedded_io_async::Write::write( - &mut tx, - b"Hello async serial. Enter something ended with EOT (CTRL-D).\r\n", - ) - .await - .unwrap(); - embedded_io_async::Write::flush(&mut tx).await.unwrap(); - loop { - let bytes_read = signal.wait().await; - signal.reset(); - write!(&mut tx, "\r\n-- received {} bytes --\r\n", bytes_read).unwrap(); - embedded_io_async::Write::flush(&mut tx).await.unwrap(); - } -} - -#[embassy_executor::task] -async fn reader(mut rx: UartRx<'static, UART0>, signal: &'static Signal) { - const MAX_BUFFER_SIZE: usize = 10 * READ_BUF_SIZE + 16; - - let mut rbuf: [u8; MAX_BUFFER_SIZE] = [0u8; MAX_BUFFER_SIZE]; - let mut offset = 0; - loop { - let r = embedded_io_async::Read::read(&mut rx, &mut rbuf[offset..]).await; - match r { - Ok(len) => { - offset += len; - esp_println::println!("Read: {len}, data: {:?}", &rbuf[..offset]); - offset = 0; - signal.signal(len); - } - Err(e) => esp_println::println!("RX Error: {:?}", e), - } - } -} - -#[main] -async fn main(spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32c2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - uart0.set_at_cmd(AtCmdConfig::new(None, None, None, AT_CMD, None)); - uart0 - .set_rx_fifo_full_threshold(READ_BUF_SIZE as u16) - .unwrap(); - let (tx, rx) = uart0.split(); - - let signal = &*make_static!(Signal::new()); - - spawner.spawn(reader(rx, &signal)).ok(); - spawner.spawn(writer(tx, &signal)).ok(); -} diff --git a/esp32c2-hal/examples/embassy_spi.rs b/esp32c2-hal/examples/embassy_spi.rs deleted file mode 100644 index 97c73e9be..000000000 --- a/esp32c2-hal/examples/embassy_spi.rs +++ /dev/null @@ -1,87 +0,0 @@ -//! Embassy SPI -//! -//! Folowing pins are used: -//! SCLK GPIO6 -//! MISO GPIO2 -//! MOSI GPIO7 -//! CS GPIO10 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. -//! -//! This is an example of running the embassy executor with SPI. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32c2_hal::{ - clock::ClockControl, - dma::{DmaPriority, *}, - dma_descriptors, - embassy, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{prelude::*, Spi}, - SpiMode, - }, - IO, -}; -use esp_backtrace as _; - -#[main] -async fn main(_spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32c2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio6; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio7; - let cs = io.pins.gpio10; - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (mut descriptors, mut rx_descriptors) = dma_descriptors!(32000); - - let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) - .with_dma(dma_channel.configure( - false, - &mut descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let send_buffer = [0, 1, 2, 3, 4, 5, 6, 7]; - loop { - let mut buffer = [0; 8]; - esp_println::println!("Sending bytes"); - embedded_hal_async::spi::SpiBus::transfer(&mut spi, &mut buffer, &send_buffer) - .await - .unwrap(); - esp_println::println!("Bytes recieved: {:?}", buffer); - Timer::after(Duration::from_millis(5_000)).await; - } -} diff --git a/esp32c2-hal/examples/embassy_wait.rs b/esp32c2-hal/examples/embassy_wait.rs deleted file mode 100644 index efa9c2188..000000000 --- a/esp32c2-hal/examples/embassy_wait.rs +++ /dev/null @@ -1,44 +0,0 @@ -//! embassy wait -//! -//! This is an example of asynchronously `Wait`ing for a pin state to change. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use embedded_hal_async::digital::Wait; -use esp32c2_hal::{clock::ClockControl, embassy, peripherals::Peripherals, prelude::*, IO}; -use esp_backtrace as _; - -#[main] -async fn main(_spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32c2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - // GPIO 9 as input - let mut input = io.pins.gpio9.into_pull_down_input(); - - loop { - esp_println::println!("Waiting..."); - input.wait_for_rising_edge().await.unwrap(); - esp_println::println!("Ping!"); - Timer::after(Duration::from_millis(100)).await; - } -} diff --git a/esp32c2-hal/examples/gpio_interrupt.rs b/esp32c2-hal/examples/gpio_interrupt.rs deleted file mode 100644 index 4b95d5f5d..000000000 --- a/esp32c2-hal/examples/gpio_interrupt.rs +++ /dev/null @@ -1,59 +0,0 @@ -//! GPIO interrupt -//! -//! This prints "Interrupt" when the boot button is pressed. -//! It also blinks an LED like the blinky example. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32c2_hal::{ - clock::ClockControl, - gpio::{Event, Gpio9, Input, PullDown, IO}, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, - Delay, -}; -use esp_backtrace as _; - -static BUTTON: Mutex>>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Set GPIO5 as an output - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut led = io.pins.gpio5.into_push_pull_output(); - - // Set GPIO9 as an input - let mut button = io.pins.gpio9.into_pull_down_input(); - button.listen(Event::FallingEdge); - - critical_section::with(|cs| BUTTON.borrow_ref_mut(cs).replace(button)); - - interrupt::enable(peripherals::Interrupt::GPIO, interrupt::Priority::Priority3).unwrap(); - - let mut delay = Delay::new(&clocks); - loop { - led.toggle().unwrap(); - delay.delay_ms(500u32); - } -} - -#[interrupt] -fn GPIO() { - critical_section::with(|cs| { - esp_println::println!("GPIO interrupt"); - BUTTON - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .clear_interrupt(); - }); -} diff --git a/esp32c2-hal/examples/hello_world.rs b/esp32c2-hal/examples/hello_world.rs deleted file mode 100644 index 50ba6f7c3..000000000 --- a/esp32c2-hal/examples/hello_world.rs +++ /dev/null @@ -1,35 +0,0 @@ -//! This shows how to write text to uart0. -//! You can see the output with `espflash` if you provide the `--monitor` option - -#![no_std] -#![no_main] - -use core::fmt::Write; - -use esp32c2_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, - Uart, -}; -use esp_backtrace as _; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - timer0.start(1u64.secs()); - - loop { - writeln!(uart0, "Hello world!").unwrap(); - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32c2-hal/examples/i2c_bmp180_calibration_data.rs b/esp32c2-hal/examples/i2c_bmp180_calibration_data.rs deleted file mode 100644 index b07628197..000000000 --- a/esp32c2-hal/examples/i2c_bmp180_calibration_data.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! Read calibration data from BMP180 sensor -//! -//! This example dumps the calibration data from a BMP180 sensor -//! -//! The following wiring is assumed: -//! - SDA => GPIO1 -//! - SCL => GPIO2 - -#![no_std] -#![no_main] - -use esp32c2_hal::{clock::ClockControl, gpio::IO, i2c::I2C, peripherals::Peripherals, prelude::*}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create a new peripheral object with the described wiring - // and standard I2C clock speed - let mut i2c = I2C::new( - peripherals.I2C0, - io.pins.gpio1, - io.pins.gpio2, - 100u32.kHz(), - &clocks, - ); - - loop { - let mut data = [0u8; 22]; - i2c.write_read(0x77, &[0xaa], &mut data).ok(); - - println!("{:02x?}", data); - } -} diff --git a/esp32c2-hal/examples/i2c_display.rs b/esp32c2-hal/examples/i2c_display.rs deleted file mode 100644 index 2e17fe086..000000000 --- a/esp32c2-hal/examples/i2c_display.rs +++ /dev/null @@ -1,121 +0,0 @@ -//! I2C Display example -//! -//! This example prints some text on an SSD1306-based -//! display (via I2C) -//! -//! The following wiring is assumed: -//! - SDA => GPIO1 -//! - SCL => GPIO2 - -#![no_std] -#![no_main] - -use embedded_graphics::{ - mono_font::{ - ascii::{FONT_6X10, FONT_9X18_BOLD}, - MonoTextStyleBuilder, - }, - pixelcolor::BinaryColor, - prelude::*, - text::{Alignment, Text}, -}; -use esp32c2_hal::{ - clock::ClockControl, - gpio::IO, - i2c::I2C, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, -}; -use esp_backtrace as _; -use nb::block; -use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create a new peripheral object with the described wiring - // and standard I2C clock speed - let i2c = I2C::new( - peripherals.I2C0, - io.pins.gpio1, - io.pins.gpio2, - 100u32.kHz(), - &clocks, - ); - - // Start timer (5 second interval) - timer0.start(5u64.secs()); - - // Initialize display - let interface = I2CDisplayInterface::new(i2c); - let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0) - .into_buffered_graphics_mode(); - display.init().unwrap(); - - // Specify different text styles - let text_style = MonoTextStyleBuilder::new() - .font(&FONT_6X10) - .text_color(BinaryColor::On) - .build(); - let text_style_big = MonoTextStyleBuilder::new() - .font(&FONT_9X18_BOLD) - .text_color(BinaryColor::On) - .build(); - - loop { - // Fill display bufffer with a centered text with two lines (and two text - // styles) - Text::with_alignment( - "esp-hal", - display.bounding_box().center() + Point::new(0, 0), - text_style_big, - Alignment::Center, - ) - .draw(&mut display) - .unwrap(); - - Text::with_alignment( - "Chip: ESP32-C2", - display.bounding_box().center() + Point::new(0, 14), - text_style, - Alignment::Center, - ) - .draw(&mut display) - .unwrap(); - - // Write buffer to display - display.flush().unwrap(); - // Clear display buffer - display.clear(BinaryColor::Off).unwrap(); - - // Wait 5 seconds - block!(timer0.wait()).unwrap(); - - // Write single-line centered text "Hello World" to buffer - Text::with_alignment( - "Hello World!", - display.bounding_box().center(), - text_style_big, - Alignment::Center, - ) - .draw(&mut display) - .unwrap(); - - // Write buffer to display - display.flush().unwrap(); - // Clear display buffer - display.clear(BinaryColor::Off).unwrap(); - - // Wait 5 seconds - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32c2-hal/examples/interrupt_preemption.rs b/esp32c2-hal/examples/interrupt_preemption.rs deleted file mode 100644 index 2bb9c5781..000000000 --- a/esp32c2-hal/examples/interrupt_preemption.rs +++ /dev/null @@ -1,132 +0,0 @@ -//! Interrupt Preemption -//! -//! An example of how an interrupt can be preempted by another with higher -//! priority. Should show higher-numbered software interrupts happening during -//! the handling of lower-numbered ones. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32c2_hal::{ - clock::ClockControl, - interrupt::{self}, - peripherals::{self, Peripherals}, - prelude::*, - riscv, - system::{SoftwareInterrupt, SoftwareInterruptControl}, -}; -use esp_backtrace as _; - -static SWINT: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clockctrl = system.clock_control; - let sw_int = system.software_interrupt_control; - let _clocks = ClockControl::boot_defaults(clockctrl).freeze(); - - critical_section::with(|cs| SWINT.borrow_ref_mut(cs).replace(sw_int)); - - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR0, - interrupt::Priority::Priority1, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR1, - interrupt::Priority::Priority2, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR2, - interrupt::Priority::Priority2, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR3, - interrupt::Priority::Priority15, - ) - .unwrap(); - unsafe { riscv::interrupt::enable() } - - // raise mid priority interrupt. - // The handler raises one interrupt at lower priority, one at same and one at - // higher. We expect to see the higher priority served immeiately before - // exiting the handler Once the handler is exited we expect to see same - // priority and low priority interrupts served in that order - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt1); - }); - loop {} -} - -#[interrupt] -fn FROM_CPU_INTR0() { - esp_println::println!("SW interrupt0"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt0); - }); -} -#[interrupt] -fn FROM_CPU_INTR1() { - esp_println::println!("SW interrupt1 entry"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt1); - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt2); // raise interrupt at same priority - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt3); // raise interrupt at higher priority - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt0); // raise interrupt at - // lower priority - }); - esp_println::println!("SW interrupt1 exit"); -} -#[interrupt] -fn FROM_CPU_INTR2() { - esp_println::println!("SW interrupt2"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt2); - }); -} -#[interrupt] -fn FROM_CPU_INTR3() { - esp_println::println!("SW interrupt3"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt3); - }); -} diff --git a/esp32c2-hal/examples/ledc.rs b/esp32c2-hal/examples/ledc.rs deleted file mode 100644 index 89ac68d9f..000000000 --- a/esp32c2-hal/examples/ledc.rs +++ /dev/null @@ -1,66 +0,0 @@ -//! Turns on LED with the option to change LED intensity depending on `duty` -//! value, then fades it. Possible starting values (`u32`) are in range 0..100. -//! -//! This assumes that a LED is connected to the pin assigned to `led`. (GPIO4) - -#![no_std] -#![no_main] - -use esp32c2_hal::{ - clock::ClockControl, - gpio::IO, - ledc::{ - channel::{self, ChannelIFace}, - timer::{self, TimerIFace}, - LSGlobalClkSource, - LowSpeed, - LEDC, - }, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let led = io.pins.gpio4.into_push_pull_output(); - - let mut ledc = LEDC::new(peripherals.LEDC, &clocks); - ledc.set_global_slow_clock(LSGlobalClkSource::APBClk); - let mut lstimer0 = ledc.get_timer::(timer::Number::Timer2); - - lstimer0 - .configure(timer::config::Config { - duty: timer::config::Duty::Duty5Bit, - clock_source: timer::LSClockSource::APBClk, - frequency: 24u32.kHz(), - }) - .unwrap(); - - let mut channel0 = ledc.get_channel(channel::Number::Channel0, led); - channel0 - .configure(channel::config::Config { - timer: &lstimer0, - duty_pct: 10, - pin_config: channel::config::PinConfig::PushPull, - }) - .unwrap(); - - channel0.start_duty_fade(0, 100, 2000).expect_err( - "Fading from 0% to 100%, at 24kHz and 5-bit resolution, over 2 seconds, should fail", - ); - - loop { - // Set up a breathing LED: fade from off to on over a second, then - // from on back off over the next second. Then loop. - channel0.start_duty_fade(0, 100, 1000).unwrap(); - while channel0.is_duty_fade_running() {} - channel0.start_duty_fade(100, 0, 1000).unwrap(); - while channel0.is_duty_fade_running() {} - } -} diff --git a/esp32c2-hal/examples/qspi_flash.rs b/esp32c2-hal/examples/qspi_flash.rs deleted file mode 100644 index 4c35cf805..000000000 --- a/esp32c2-hal/examples/qspi_flash.rs +++ /dev/null @@ -1,167 +0,0 @@ -//! SPI write and read a flash chip -//! -//! Folowing pins are used: -//! SCLK GPIO4 -//! MISOI/IO0 GPIO5 -//! MOSI/IO1 GPIO6 -//! IO2 GPIO7 -//! IO3 GPIO8 -//! CS GPIO9 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! Connect a flash chip (GD25Q64C was used) and make sure QE in the status -//! register is set. - -#![no_std] -#![no_main] - -use esp32c2_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{prelude::*, Address, Command, Spi}, - SpiDataMode, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio4; - let miso = io.pins.gpio5; - let mosi = io.pins.gpio6; - let sio2 = io.pins.gpio7; - let sio3 = io.pins.gpio8; - let cs = io.pins.gpio9; - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(256, 320); - - let mut spi = Spi::new_half_duplex(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(sio2), - Some(sio3), - Some(cs), - ) - .with_dma(dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let mut delay = Delay::new(&clocks); - - // DMA buffer require a static life-time - let mut zero_buf = zero_buffer(); - let send = tx_buffer; - let mut receive = rx_buffer; - - // write enable - let transfer = spi - .write( - SpiDataMode::Single, - Command::Command8(0x06, SpiDataMode::Single), - Address::None, - 0, - zero_buf, - ) - .unwrap(); - (zero_buf, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - // erase sector - let transfer = spi - .write( - SpiDataMode::Single, - Command::Command8(0x20, SpiDataMode::Single), - Address::Address24(0x000000, SpiDataMode::Single), - 0, - zero_buf, - ) - .unwrap(); - (zero_buf, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - // write enable - let transfer = spi - .write( - SpiDataMode::Single, - Command::Command8(0x06, SpiDataMode::Single), - Address::None, - 0, - zero_buf, - ) - .unwrap(); - (_, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - // write data / program page - send.fill(b'!'); - send[0..][..5].copy_from_slice(&b"Hello"[..]); - let transfer = spi - .write( - SpiDataMode::Quad, - Command::Command8(0x32, SpiDataMode::Single), - Address::Address24(0x000000, SpiDataMode::Single), - 0, - send, - ) - .unwrap(); - (_, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - loop { - // quad fast read - let transfer = spi - .read( - SpiDataMode::Quad, - Command::Command8(0xeb, SpiDataMode::Single), - Address::Address32(0x000000 << 8, SpiDataMode::Quad), - 4, - receive, - ) - .unwrap(); - - // here we could do something else while DMA transfer is in progress - // the buffers and spi is moved into the transfer and we can get it back via - // `wait` - (receive, spi) = transfer.wait().unwrap(); - - println!("{:x?}", &receive); - for b in &mut receive.iter() { - if *b >= 32 && *b <= 127 { - print!("{}", *b as char); - } else { - print!("."); - } - } - println!(); - - delay.delay_ms(250u32); - } -} - -fn zero_buffer() -> &'static mut [u8; 0] { - static mut BUFFER: [u8; 0] = [0u8; 0]; - unsafe { &mut BUFFER } -} diff --git a/esp32c2-hal/examples/read_efuse.rs b/esp32c2-hal/examples/read_efuse.rs deleted file mode 100644 index 22d26ac4b..000000000 --- a/esp32c2-hal/examples/read_efuse.rs +++ /dev/null @@ -1,21 +0,0 @@ -//! This shows how to read selected information from eFuses. -//! e.g. the MAC address - -#![no_std] -#![no_main] - -use esp32c2_hal::{clock::ClockControl, efuse::Efuse, peripherals::Peripherals, prelude::*}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - println!("MAC address {:02x?}", Efuse::get_mac_address()); - println!("Flash Encryption {:?}", Efuse::get_flash_encryption()); - - loop {} -} diff --git a/esp32c2-hal/examples/rng.rs b/esp32c2-hal/examples/rng.rs deleted file mode 100644 index ef9d6faa7..000000000 --- a/esp32c2-hal/examples/rng.rs +++ /dev/null @@ -1,28 +0,0 @@ -//! Demonstrates the use of the hardware Random Number Generator (RNG) - -#![no_std] -#![no_main] - -use esp32c2_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Rng}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Instantiate the Random Number Generator peripheral: - let mut rng = Rng::new(peripherals.RNG); - - // Generate a random word (u32): - println!("Random u32: {}", rng.random()); - - // Fill a buffer with random bytes: - let mut buf = [0u8; 16]; - rng.read(&mut buf).unwrap(); - println!("Random bytes: {:?}", buf); - - loop {} -} diff --git a/esp32c2-hal/examples/rtc_time.rs b/esp32c2-hal/examples/rtc_time.rs deleted file mode 100644 index 400abbf3b..000000000 --- a/esp32c2-hal/examples/rtc_time.rs +++ /dev/null @@ -1,22 +0,0 @@ -//! Prints time in milliseconds from the RTC Timer - -#![no_std] -#![no_main] - -use esp32c2_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Delay, Rtc}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let rtc = Rtc::new(peripherals.LPWR); - let mut delay = Delay::new(&clocks); - - loop { - esp_println::println!("rtc time in milliseconds is {}", rtc.get_time_ms()); - delay.delay_ms(1000u32); - } -} diff --git a/esp32c2-hal/examples/serial_interrupts.rs b/esp32c2-hal/examples/serial_interrupts.rs deleted file mode 100644 index 430ed0f39..000000000 --- a/esp32c2-hal/examples/serial_interrupts.rs +++ /dev/null @@ -1,88 +0,0 @@ -//! This shows some of the interrupts that can be generated by UART/Serial. -//! Use a proper serial terminal to connect to the board (espmonitor and -//! espflash won't work) - -#![no_std] -#![no_main] - -use core::{cell::RefCell, fmt::Write}; - -use critical_section::Mutex; -use esp32c2_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals, UART0}, - prelude::*, - timer::TimerGroup, - uart::config::AtCmdConfig, - Cpu, - Uart, -}; -use esp_backtrace as _; -use nb::block; - -static SERIAL: Mutex>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - uart0.set_at_cmd(AtCmdConfig::new(None, None, None, b'#', None)); - uart0.set_rx_fifo_full_threshold(30).unwrap(); - uart0.listen_at_cmd(); - uart0.listen_rx_fifo_full(); - - timer0.start(1u64.secs()); - - critical_section::with(|cs| SERIAL.borrow_ref_mut(cs).replace(uart0)); - - interrupt::enable( - peripherals::Interrupt::UART0, - interrupt::Priority::Priority1, - ) - .unwrap(); - interrupt::set_kind( - Cpu::ProCpu, - interrupt::CpuInterrupt::Interrupt1, // Interrupt 1 handles priority one interrupts - interrupt::InterruptKind::Edge, - ); - - loop { - critical_section::with(|cs| { - writeln!(SERIAL.borrow_ref_mut(cs).as_mut().unwrap(), "Hello World! Send a single `#` character or send at least 30 characters and see the interrupts trigger.").ok(); - }); - - block!(timer0.wait()).unwrap(); - } -} - -#[interrupt] -fn UART0() { - critical_section::with(|cs| { - let mut serial = SERIAL.borrow_ref_mut(cs); - let serial = serial.as_mut().unwrap(); - - let mut cnt = 0; - while let nb::Result::Ok(_c) = serial.read() { - cnt += 1; - } - writeln!(serial, "Read {} bytes", cnt,).ok(); - - writeln!( - serial, - "Interrupt AT-CMD: {} RX-FIFO-FULL: {}", - serial.at_cmd_interrupt_set(), - serial.rx_fifo_full_interrupt_set(), - ) - .ok(); - - serial.reset_at_cmd_interrupt(); - serial.reset_rx_fifo_full_interrupt(); - }); -} diff --git a/esp32c2-hal/examples/software_interrupts.rs b/esp32c2-hal/examples/software_interrupts.rs deleted file mode 100644 index 10ed27cc7..000000000 --- a/esp32c2-hal/examples/software_interrupts.rs +++ /dev/null @@ -1,142 +0,0 @@ -//! Software Interrupts -//! -//! An example of how software interrupts can be raised and reset -//! Should rotate through all of the available interrupts printing their number -//! when raised. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32c2_hal::{ - clock::ClockControl, - interrupt::{self}, - peripherals::{self, Peripherals}, - prelude::*, - riscv, - system::{SoftwareInterrupt, SoftwareInterruptControl}, - Delay, -}; -use esp_backtrace as _; - -static SWINT: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clockctrl = system.clock_control; - let sw_int = system.software_interrupt_control; - let clocks = ClockControl::boot_defaults(clockctrl).freeze(); - - critical_section::with(|cs| SWINT.borrow_ref_mut(cs).replace(sw_int)); - - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR0, - interrupt::Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR1, - interrupt::Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR2, - interrupt::Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR3, - interrupt::Priority::Priority3, - ) - .unwrap(); - unsafe { riscv::interrupt::enable() } - let mut delay = Delay::new(&clocks); - let mut counter = 0; - loop { - delay.delay_ms(500u32); - match counter { - 0 => critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt0); - }), - 1 => critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt1); - }), - 2 => critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt2); - }), - 3 => { - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt3); - }); - counter = -1 - } - _ => {} - } - counter += 1; - } -} - -#[interrupt] -fn FROM_CPU_INTR0() { - esp_println::println!("SW interrupt0"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt0); - }); -} -#[interrupt] -fn FROM_CPU_INTR1() { - esp_println::println!("SW interrupt1"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt1); - }); -} -#[interrupt] -fn FROM_CPU_INTR2() { - esp_println::println!("SW interrupt2"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt2); - }); -} -#[interrupt] -fn FROM_CPU_INTR3() { - esp_println::println!("SW interrupt3"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt3); - }); -} diff --git a/esp32c2-hal/examples/spi_eh1_loopback.rs b/esp32c2-hal/examples/spi_eh1_loopback.rs deleted file mode 100644 index f7b3b97b3..000000000 --- a/esp32c2-hal/examples/spi_eh1_loopback.rs +++ /dev/null @@ -1,104 +0,0 @@ -//! SPI loopback test -//! -//! Folowing pins are used: -//! SCLK GPIO6 -//! MISO GPIO2 -//! MOSI GPIO7 -//! CS GPIO10 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use embedded_hal_1::spi::SpiBus; -use esp32c2_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{master::Spi, SpiMode}, - Delay, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio6; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio7; - let cs = io.pins.gpio10; - - let mut spi = Spi::new(peripherals.SPI2, 1000u32.kHz(), SpiMode::Mode0, &clocks).with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(cs), - ); - - let mut delay = Delay::new(&clocks); - println!("=== SPI example with embedded-hal-1 traits ==="); - - loop { - // --- Symmetric transfer (Read as much as we write) --- - print!("Starting symmetric transfer..."); - let write = [0xde, 0xad, 0xbe, 0xef]; - let mut read: [u8; 4] = [0x00u8; 4]; - - SpiBus::transfer(&mut spi, &mut read[..], &write[..]).expect("Symmetric transfer failed"); - assert_eq!(write, read); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Asymmetric transfer (Read more than we write) --- - print!("Starting asymetric transfer (read > write)..."); - let mut read: [u8; 4] = [0x00; 4]; - - SpiBus::transfer(&mut spi, &mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - assert_eq!(write[0], read[0]); - assert_eq!(read[2], 0x00u8); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer --- - // Only your RAM is the limit! - print!("Starting huge transfer..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - let mut read = [0x00u8; 4096]; - - SpiBus::transfer(&mut spi, &mut read[..], &write[..]).expect("Huge transfer failed"); - assert_eq!(write, read); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer in-place (No additional allocation - // needed) --- - print!("Starting huge transfer (in-place)..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - - SpiBus::transfer_in_place(&mut spi, &mut write[..]).expect("Huge transfer failed"); - for byte in 0..write.len() { - assert_eq!(write[byte], byte as u8); - } - println!(" SUCCESS"); - delay.delay_ms(250u32); - } -} diff --git a/esp32c2-hal/examples/spi_halfduplex_read_manufacturer_id.rs b/esp32c2-hal/examples/spi_halfduplex_read_manufacturer_id.rs deleted file mode 100644 index 460ad8923..000000000 --- a/esp32c2-hal/examples/spi_halfduplex_read_manufacturer_id.rs +++ /dev/null @@ -1,101 +0,0 @@ -//! SPI read manufacturer id from flash chip -//! -//! Folowing pins are used: -//! SCLK GPIO4 -//! MISOI/IO0 GPIO5 -//! MOSI/IO1 GPIO6 -//! IO2 GPIO7 -//! IO3 GPIO8 -//! CS GPIO9 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! Connect a flash chip (GD25Q64C was used) and make sure QE in the status -//! register is set. - -#![no_std] -#![no_main] - -use esp32c2_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{Address, Command, HalfDuplexReadWrite, Spi}, - SpiDataMode, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio4; - let miso = io.pins.gpio5; - let mosi = io.pins.gpio6; - let sio2 = io.pins.gpio7; - let sio3 = io.pins.gpio8; - let cs = io.pins.gpio9; - - let mut spi = Spi::new_half_duplex(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(sio2), - Some(sio3), - Some(cs), - ); - - let mut delay = Delay::new(&clocks); - - loop { - // READ MANUFACTURER ID FROM FLASH CHIP - let mut data = [0u8; 2]; - spi.read( - SpiDataMode::Single, - Command::Command8(0x90, SpiDataMode::Single), - Address::Address24(0x000000, SpiDataMode::Single), - 0, - &mut data, - ) - .unwrap(); - println!("Single {:x?}", data); - delay.delay_ms(250u32); - - // READ MANUFACTURER ID FROM FLASH CHIP - let mut data = [0u8; 2]; - spi.read( - SpiDataMode::Dual, - Command::Command8(0x92, SpiDataMode::Single), - Address::Address32(0x000000_00, SpiDataMode::Dual), - 0, - &mut data, - ) - .unwrap(); - println!("Dual {:x?}", data); - delay.delay_ms(250u32); - - // READ MANUFACTURER ID FROM FLASH CHIP - let mut data = [0u8; 2]; - spi.read( - SpiDataMode::Quad, - Command::Command8(0x94, SpiDataMode::Single), - Address::Address32(0x000000_00, SpiDataMode::Quad), - 4, - &mut data, - ) - .unwrap(); - println!("Quad {:x?}", data); - delay.delay_ms(1500u32); - } -} diff --git a/esp32c2-hal/examples/spi_loopback.rs b/esp32c2-hal/examples/spi_loopback.rs deleted file mode 100644 index cd13bd2d3..000000000 --- a/esp32c2-hal/examples/spi_loopback.rs +++ /dev/null @@ -1,58 +0,0 @@ -//! SPI loopback test -//! -//! Folowing pins are used: -//! SCLK GPIO6 -//! MISO GPIO2 -//! MOSI GPIO7 -//! CS GPIO10 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use esp32c2_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{master::Spi, SpiMode}, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio6; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio7; - let cs = io.pins.gpio10; - - let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks).with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(cs), - ); - - let mut delay = Delay::new(&clocks); - - loop { - let mut data = [0xde, 0xca, 0xfb, 0xad]; - spi.transfer(&mut data).unwrap(); - println!("{:x?}", data); - - delay.delay_ms(250u32); - } -} diff --git a/esp32c2-hal/examples/spi_slave_dma.rs b/esp32c2-hal/examples/spi_slave_dma.rs deleted file mode 100644 index eca8e68d6..000000000 --- a/esp32c2-hal/examples/spi_slave_dma.rs +++ /dev/null @@ -1,204 +0,0 @@ -//! SPI slave loopback test using DMA -//! -//! Following pins are used for the slave: -//! SCLK GPIO6 -//! MISO GPIO2 -//! MOSI GPIO7 -//! CS GPIO10 -//! -//! Following pins are used for the (bitbang) master: -//! SCLK GPIO5 -//! MISO GPIO1 -//! MOSI GPIO8 -//! CS GPIO9 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect corresponding master and slave pins to see the outgoing data is read -//! as incoming data. The master-side pins are chosen to make these connections -//! easy for the barebones ESP32C3 chip; all are immediate neighbors of the -//! slave-side pins except SCLK. SCLK is between MOSI and VDD3P3_RTC on the -//! barebones ESP32C3, so no immediate neighbor is available. - -#![no_std] -#![no_main] - -use esp32c2_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - slave::{prelude::*, Spi}, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let slave_sclk = io.pins.gpio6; - let mut master_sclk = io.pins.gpio5.into_push_pull_output(); - let slave_miso = io.pins.gpio2; - let master_miso = io.pins.gpio1.into_floating_input(); - let slave_mosi = io.pins.gpio7; - let mut master_mosi = io.pins.gpio8.into_push_pull_output(); - let slave_cs = io.pins.gpio10; - let mut master_cs = io.pins.gpio9.into_push_pull_output(); - master_cs.set_high().unwrap(); - master_sclk.set_low().unwrap(); - master_mosi.set_low().unwrap(); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(3200); - - let mut spi = Spi::new( - peripherals.SPI2, - slave_sclk, - slave_mosi, - slave_miso, - slave_cs, - SpiMode::Mode0, - ) - .with_dma(dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let mut delay = Delay::new(&clocks); - - // DMA buffer require a static life-time - let master_send = &mut [0u8; 3200]; - let master_receive = &mut [0u8; 3200]; - let mut slave_send = tx_buffer; - let mut slave_receive = rx_buffer; - let mut i = 0; - - for (i, v) in master_send.iter_mut().enumerate() { - *v = (i % 255) as u8; - } - for (i, v) in slave_send.iter_mut().enumerate() { - *v = (254 - (i % 255)) as u8; - } - - loop { - master_send[0] = i; - master_send[master_send.len() - 1] = i; - slave_send[0] = i; - slave_send[slave_send.len() - 1] = i; - slave_receive.fill(0xff); - i = i.wrapping_add(1); - - let transfer = spi.dma_transfer(slave_send, slave_receive).unwrap(); - // Bit-bang out the contents of master_send and read into master_receive - // as quickly as manageable. MSB first. Mode 0, so sampled on the rising - // edge and set on the falling edge. - master_cs.set_low().unwrap(); - for (j, v) in master_send.iter().enumerate() { - let mut b = *v; - let mut rb = 0u8; - for _ in 0..8 { - if b & 128 != 0 { - master_mosi.set_high().unwrap(); - } else { - master_mosi.set_low().unwrap(); - } - master_sclk.set_low().unwrap(); - b <<= 1; - rb <<= 1; - // Delay to ensure the SPI peripheral notices the low clock. - // One microsecond is about twice as long as we need to pause, - // but it'll still work. - delay.delay_us(1u32); - master_sclk.set_high().unwrap(); - if master_miso.is_high().unwrap() { - rb |= 1; - } - } - master_receive[j] = rb; - } - master_cs.set_high().unwrap(); - master_sclk.set_low().unwrap(); - // the buffers and spi is moved into the transfer and we can get it back via - // `wait` - (slave_receive, slave_send, spi) = transfer.wait().unwrap(); - println!( - "slave got {:x?} .. {:x?}, master got {:x?} .. {:x?}", - &slave_receive[..10], - &slave_receive[slave_receive.len() - 10..], - &master_receive[..10], - &master_receive[master_receive.len() - 10..] - ); - - delay.delay_ms(250u32); - - slave_receive.fill(0xff); - let transfer = spi.dma_read(slave_receive).unwrap(); - master_cs.set_high().unwrap(); - - master_cs.set_low().unwrap(); - for v in master_send.iter() { - let mut b = *v; - for _ in 0..8 { - if b & 128 != 0 { - master_mosi.set_high().unwrap(); - } else { - master_mosi.set_low().unwrap(); - } - b <<= 1; - master_sclk.set_low().unwrap(); - master_sclk.set_high().unwrap(); - } - } - master_cs.set_high().unwrap(); - (slave_receive, spi) = transfer.wait().unwrap(); - println!( - "slave got {:x?} .. {:x?}", - &slave_receive[..10], - &slave_receive[slave_receive.len() - 10..], - ); - - delay.delay_ms(250u32); - let transfer = spi.dma_write(slave_send).unwrap(); - - master_receive.fill(0); - - master_cs.set_low().unwrap(); - for (j, _) in master_send.iter().enumerate() { - let mut rb = 0u8; - for _ in 0..8 { - master_sclk.set_low().unwrap(); - rb <<= 1; - master_sclk.set_high().unwrap(); - if master_miso.is_high().unwrap() { - rb |= 1; - } - } - master_receive[j] = rb; - } - master_cs.set_high().unwrap(); - (slave_send, spi) = transfer.wait().unwrap(); - - println!( - "master got {:x?} .. {:x?}", - &master_receive[..10], - &master_receive[master_receive.len() - 10..], - ); - println!(); - } -} diff --git a/esp32c2-hal/examples/systimer.rs b/esp32c2-hal/examples/systimer.rs deleted file mode 100644 index 00c717798..000000000 --- a/esp32c2-hal/examples/systimer.rs +++ /dev/null @@ -1,114 +0,0 @@ -//! This shows how to use the SYSTIMER peripheral including interrupts. -//! It's an additional timer besides the TIMG peripherals. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32c2_hal::{ - clock::ClockControl, - interrupt, - interrupt::Priority, - peripherals::{self, Peripherals}, - prelude::*, - systimer::{Alarm, Periodic, SystemTimer, Target}, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -static ALARM0: Mutex>>> = Mutex::new(RefCell::new(None)); -static ALARM1: Mutex>>> = Mutex::new(RefCell::new(None)); -static ALARM2: Mutex>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let syst = SystemTimer::new(peripherals.SYSTIMER); - - println!("SYSTIMER Current value = {}", SystemTimer::now()); - - let alarm0 = syst.alarm0.into_periodic(); - alarm0.set_period(1u32.secs()); - alarm0.clear_interrupt(); - alarm0.enable_interrupt(true); - - let alarm1 = syst.alarm1; - alarm1.set_target(SystemTimer::now() + (SystemTimer::TICKS_PER_SECOND * 2)); - alarm1.enable_interrupt(true); - - let alarm2 = syst.alarm2; - alarm2.set_target(SystemTimer::now() + (SystemTimer::TICKS_PER_SECOND * 3)); - alarm2.enable_interrupt(true); - - critical_section::with(|cs| { - ALARM0.borrow_ref_mut(cs).replace(alarm0); - ALARM1.borrow_ref_mut(cs).replace(alarm1); - ALARM2.borrow_ref_mut(cs).replace(alarm2); - }); - - interrupt::enable( - peripherals::Interrupt::SYSTIMER_TARGET0, - Priority::Priority1, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::SYSTIMER_TARGET1, - Priority::Priority2, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::SYSTIMER_TARGET2, - Priority::Priority2, - ) - .unwrap(); - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - loop { - delay.delay_ms(500u32); - } -} - -#[interrupt] -fn SYSTIMER_TARGET0() { - println!("Interrupt lvl1 (alarm0)"); - critical_section::with(|cs| { - ALARM0 - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .clear_interrupt() - }); -} - -#[interrupt] -fn SYSTIMER_TARGET1() { - println!("Interrupt lvl2 (alarm1)"); - critical_section::with(|cs| { - ALARM1 - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .clear_interrupt() - }); -} - -#[interrupt] -fn SYSTIMER_TARGET2() { - println!("Interrupt lvl2 (alarm2)"); - critical_section::with(|cs| { - ALARM2 - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .clear_interrupt() - }); -} diff --git a/esp32c2-hal/src/lib.rs b/esp32c2-hal/src/lib.rs deleted file mode 100644 index 123b1aa33..000000000 --- a/esp32c2-hal/src/lib.rs +++ /dev/null @@ -1,9 +0,0 @@ -//! A bare-metal (`no_std`) Hardware Abstraction Layer for the ESP32-C2 from -//! Espressif. -//! -//! ## Feature Flags -#![doc = document_features::document_features!()] -#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/46717278")] -#![no_std] - -pub use esp_hal::*; diff --git a/esp32c3-hal/.cargo/config.toml b/esp32c3-hal/.cargo/config.toml deleted file mode 100644 index 4f0290eac..000000000 --- a/esp32c3-hal/.cargo/config.toml +++ /dev/null @@ -1,12 +0,0 @@ -[target.riscv32imc-unknown-none-elf] -runner = "espflash flash --monitor" -rustflags = [ - "-C", "link-arg=-Tlinkall.x", - "-C", "force-frame-pointers", -] - -[build] -target = "riscv32imc-unknown-none-elf" - -[unstable] -build-std = [ "core" ] diff --git a/esp32c3-hal/Cargo.toml b/esp32c3-hal/Cargo.toml deleted file mode 100644 index 5ca2cdfc1..000000000 --- a/esp32c3-hal/Cargo.toml +++ /dev/null @@ -1,173 +0,0 @@ -[package] -name = "esp32c3-hal" -version = "0.15.0" -edition = "2021" -rust-version = "1.67.0" -description = "HAL for ESP32-C3 microcontrollers" -repository = "https://github.com/esp-rs/esp-hal" -license = "MIT OR Apache-2.0" - -keywords = [ - "embedded", - "embedded-hal", - "esp", - "esp32c3", - "no-std", -] -categories = [ - "embedded", - "hardware-support", - "no-std", -] - -[package.metadata.docs.rs] -targets = ["riscv32imc-unknown-none-elf"] - -[dependencies] -document-features = "0.2.7" -esp-hal = { version = "0.15.0", features = ["esp32c3"], path = "../esp-hal" } -embassy-time-driver = { version = "0.1.0", optional = true } - -[dev-dependencies] -aes = "0.8.3" -critical-section = "1.1.2" -crypto-bigint = { version = "0.5.5", default-features = false } -embassy-executor = { version = "0.5.0", features = ["nightly"] } -embassy-sync = "0.5.0" -embassy-time = "0.3.0" -embedded-can = "0.4.1" -embedded-graphics = "0.8.1" -embedded-hal = { version = "0.2.7", features = ["unproven"] } -embedded-hal-1 = { version = "1.0.0", package = "embedded-hal" } -embedded-hal-async = "1.0.0" -embedded-io-async = "0.6.1" -embedded-hal-bus = "0.1.0" -esp-backtrace = { version = "0.10.0", features = ["esp32c3", "panic-handler", "exception-handler", "print-uart"] } -esp-hal-smartled = { version = "0.8.0", features = ["esp32c3"], path = "../esp-hal-smartled" } -esp-println = { version = "0.8.0", features = ["esp32c3"] } -heapless = "0.8.0" -hmac = { version = "0.12.1", default-features = false } -lis3dh-async = "0.9.1" -sha2 = { version = "0.10.8", default-features = false } -smart-leds = "0.4.0" -ssd1306 = "0.8.4" -static_cell = { version = "2.0.0", features = ["nightly"] } - -[features] -default = ["embassy-integrated-timers", "rt", "vectored", "zero-rtc-bss"] - -## Enable debug features in the HAL (used for development). -debug = ["esp-hal/debug"] -## Enable direct interrupt vectoring. -direct-vectoring = ["esp-hal/direct-vectoring"] -## Enable interrupt preemption. -interrupt-preemption = ["esp-hal/interrupt-preemption"] -## Enable logging output using the `log` crate. -log = ["esp-hal/log", "esp-println/log"] -## Enable runtime support. -rt = ["esp-hal/rt-riscv"] -## Enable interrupt vectoring. -vectored = ["esp-hal/vectored"] - -#! ### Trait Implementation Feature Flags -## Enable support for asynchronous operation, with interfaces provided by -## `embedded-hal-async` and `embedded-io-async`. -async = ["esp-hal/async"] -## Implement `defmt::Format` on certain types. -defmt = ["esp-hal/defmt", "esp-println/defmt-espflash"] -## Implement the traits defined in the `1.0.0` releases of `embedded-hal` and -## `embedded-hal-nb` for the relevant peripherals. -eh1 = ["esp-hal/eh1"] -## Implement the traits defined in `embedded-io` for certain peripherals. -embedded-io = ["esp-hal/embedded-io"] -## Implement the `ufmt_write::uWrite` trait for certain peripherals. -ufmt = ["esp-hal/ufmt"] - -#! ### Memory Initialization Feature Flags -## Zero the `.bss` section of low-power memory. -zero-rtc-bss = ["esp-hal/rv-zero-rtc-bss"] -## Initialize the `.data` section of memory. -init-data = ["esp-hal/rv-init-data"] -## Initialize the `.data` section of low-power memory. -init-rtc-data = ["esp-hal/rv-init-rtc-data"] - -#! ### Embassy Feature Flags -## Enable support for `embassy`, a modern asynchronous embedded framework. -embassy = ["esp-hal/embassy"] -## Use the interrupt-mode embassy executor. -embassy-executor-interrupt = ["esp-hal/embassy-executor-interrupt"] -## Use the thread-mode embassy executor. -embassy-executor-thread = ["esp-hal/embassy-executor-thread"] -## Uses hardware timers as alarms for the executors. Using this feature -## limits the number of executors to the number of hardware alarms provided -## by the time driver. -embassy-integrated-timers = ["esp-hal/embassy-integrated-timers"] -## Enable the embassy time driver using the `SYSTIMER` peripheral. The -## `SYSTIMER` peripheral has three alarams available for use. -embassy-time-systick = ["esp-hal/embassy-time-systick", "embassy-time-driver/tick-hz-16_000_000"] -## Enable the embassy time driver using the `TIMG0` peripheral. The `TIMG0` -## peripheral has two alarms available for use. -embassy-time-timg0 = ["esp-hal/embassy-time-timg0", "embassy-time-driver/tick-hz-1_000_000"] - -[profile.release] -debug = true - -[[example]] -name = "spi_eh1_loopback" -required-features = ["eh1"] - -[[example]] -name = "spi_eh1_device_loopback" -required-features = ["eh1"] - -[[example]] -name = "embassy_hello_world" -required-features = ["embassy", "embassy-executor-thread"] - -[[example]] -name = "embassy_multiprio" -required-features = ["embassy", "embassy-executor-thread", "embassy-executor-interrupt"] - -[[example]] -name = "embassy_wait" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "interrupt_preemption" -required-features = ["interrupt-preemption"] - -[[example]] -name = "embassy_spi" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_serial" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_i2c" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_rmt_tx" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_rmt_rx" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_i2s_sound" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_i2s_read" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_usb_serial_jtag" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "direct-vectoring" -required-features = ["direct-vectoring"] diff --git a/esp32c3-hal/README.md b/esp32c3-hal/README.md deleted file mode 100644 index b750205d4..000000000 --- a/esp32c3-hal/README.md +++ /dev/null @@ -1,51 +0,0 @@ -# esp32c3-hal - -[![Crates.io](https://img.shields.io/crates/v/esp32c3-hal?labelColor=1C2C2E&color=C96329&logo=Rust&style=flat-square)](https://crates.io/crates/esp32c3-hal) -[![docs.rs](https://img.shields.io/docsrs/esp32c3-hal?labelColor=1C2C2E&color=C96329&logo=rust&style=flat-square)](https://docs.rs/esp32c3-hal) -![Crates.io](https://img.shields.io/crates/l/esp32c3-hal?labelColor=1C2C2E&style=flat-square) -[![Matrix](https://img.shields.io/matrix/esp-rs:matrix.org?label=join%20matrix&labelColor=1C2C2E&color=BEC5C9&logo=matrix&style=flat-square)](https://matrix.to/#/#esp-rs:matrix.org) - -`no_std` HAL for the ESP32-C3 from Espressif. - -Implements a number of the traits defined in [embedded-hal](https://github.com/rust-embedded/embedded-hal). - -This device uses the RISC-V ISA, which is officially supported by the Rust compiler via the `riscv32imc-unknown-none-elf` target. - -Please refer to the documentation for more information. - -## [Documentation] - -[documentation]: https://docs.rs/esp32c3-hal/ - -## Resources - -- [Datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c3_datasheet_en.pdf) -- [Technical Reference Manual](https://www.espressif.com/sites/default/files/documentation/esp32-c3_technical_reference_manual_en.pdf) -- [The Rust Programming Language](https://doc.rust-lang.org/book/) -- [The Embedded Rust Book](https://docs.rust-embedded.org/book/index.html) -- [The Rust on ESP Book](https://esp-rs.github.io/book/) - -## Getting Started - -### Installing the Rust Compiler Target - -The compilation target for this device is officially supported by the mainline Rust compiler and can be installed using [rustup](https://rustup.rs/): - -```shell -rustup target add riscv32imc-unknown-none-elf -``` - -## License - -Licensed under either of: - -- Apache License, Version 2.0 ([LICENSE-APACHE](../LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) -- MIT license ([LICENSE-MIT](../LICENSE-MIT) or http://opensource.org/licenses/MIT) - -at your option. - -### Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in -the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without -any additional terms or conditions. diff --git a/esp32c3-hal/build.rs b/esp32c3-hal/build.rs deleted file mode 100644 index 023b7905b..000000000 --- a/esp32c3-hal/build.rs +++ /dev/null @@ -1,16 +0,0 @@ -use std::{env, error::Error, path::PathBuf}; - -fn main() -> Result<(), Box> { - // Put the linker script somewhere the linker can find it - let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - println!("cargo:rustc-link-search={}", out.display()); - - // Only re-run the build script when memory.x is changed, - // instead of when any part of the source code changes. - println!("cargo:rerun-if-changed=ld/memory.x"); - - #[cfg(feature = "defmt")] - println!("cargo:rustc-link-arg=-Tdefmt.x"); - - Ok(()) -} diff --git a/esp32c3-hal/examples/adc.rs b/esp32c3-hal/examples/adc.rs deleted file mode 100644 index a0d062228..000000000 --- a/esp32c3-hal/examples/adc.rs +++ /dev/null @@ -1,39 +0,0 @@ -//! Connect a potentiometer to PIN2 and see the read values change when -//! rotating the shaft. Alternatively you could also connect the PIN to GND or -//! 3V3 to see the maximum and minimum raw values read. - -#![no_std] -#![no_main] - -use esp32c3_hal::{ - adc::{AdcConfig, Attenuation, ADC}, - clock::ClockControl, - gpio::IO, - peripherals::{Peripherals, ADC1}, - prelude::*, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create ADC instances - let mut adc1_config = AdcConfig::new(); - let mut pin = adc1_config.enable_pin(io.pins.gpio2.into_analog(), Attenuation::Attenuation11dB); - let mut adc1 = ADC::::new(peripherals.ADC1, adc1_config); - - let mut delay = Delay::new(&clocks); - - loop { - let pin_value = nb::block!(adc1.read(&mut pin)).unwrap(); - println!("PIN2 ADC reading = {}", pin_value); - delay.delay_ms(1500u32); - } -} diff --git a/esp32c3-hal/examples/adc_cal.rs b/esp32c3-hal/examples/adc_cal.rs deleted file mode 100644 index 7ec564c34..000000000 --- a/esp32c3-hal/examples/adc_cal.rs +++ /dev/null @@ -1,52 +0,0 @@ -//! Connect a potentiometer to PIN2 and see the read values change when -//! rotating the shaft. Alternatively you could also connect the PIN to GND or -//! 3V3 to see the maximum and minimum raw values read. - -#![no_std] -#![no_main] - -use esp32c3_hal::{ - adc, - adc::{AdcConfig, Attenuation, ADC}, - clock::ClockControl, - gpio::IO, - peripherals::{Peripherals, ADC1}, - prelude::*, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create ADC instances - // You can try any of the following calibration methods by uncommenting them. - // Note that only AdcCalLine and AdcCalCurve return readings in mV; the other - // two return raw readings in some unspecified scale. - // - // type AdcCal = (); - // type AdcCal = adc::AdcCalBasic; - // type AdcCal = adc::AdcCalLine; - type AdcCal = adc::AdcCalCurve; - - let mut adc1_config = AdcConfig::new(); - let mut pin = adc1_config.enable_pin_with_cal::<_, AdcCal>( - io.pins.gpio2.into_analog(), - Attenuation::Attenuation11dB, - ); - let mut adc1 = ADC::::new(peripherals.ADC1, adc1_config); - - let mut delay = Delay::new(&clocks); - - loop { - let pin_mv = nb::block!(adc1.read(&mut pin)).unwrap(); - println!("PIN2 ADC reading = {pin_mv} mV"); - delay.delay_ms(1500u32); - } -} diff --git a/esp32c3-hal/examples/advanced_serial.rs b/esp32c3-hal/examples/advanced_serial.rs deleted file mode 100644 index 5dad2133a..000000000 --- a/esp32c3-hal/examples/advanced_serial.rs +++ /dev/null @@ -1,67 +0,0 @@ -//! This shows how to configure UART -//! You can short the TX and RX pin and see it reads what was written. -//! Additionally you can connect a logic analzyer to TX and see how the changes -//! of the configuration change the output signal. -//! -//! The following wiring is assumed: -//! - TX => GPIO1 -//! - RX => GPIO2 - -#![no_std] -#![no_main] - -use esp32c3_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, - uart::{ - config::{Config, DataBits, Parity, StopBits}, - TxRxPins, - }, - Uart, - IO, -}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let config = Config { - baudrate: 115200, - data_bits: DataBits::DataBits8, - parity: Parity::ParityNone, - stop_bits: StopBits::STOP1, - }; - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let pins = TxRxPins::new_tx_rx( - io.pins.gpio1.into_push_pull_output(), - io.pins.gpio2.into_floating_input(), - ); - - let mut serial1 = Uart::new_with_config(peripherals.UART1, config, Some(pins), &clocks); - - timer0.start(250u64.millis()); - - println!("Start"); - loop { - serial1.write(0x42).ok(); - let read = block!(serial1.read()); - - match read { - Ok(read) => println!("Read 0x{:02x}", read), - Err(err) => println!("Error {:?}", err), - } - - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32c3-hal/examples/blinky.rs b/esp32c3-hal/examples/blinky.rs deleted file mode 100644 index 79d7d48bb..000000000 --- a/esp32c3-hal/examples/blinky.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! Blinks an LED -//! -//! This assumes that a LED is connected to the pin assigned to `led`. (GPIO5) - -#![no_std] -#![no_main] - -use esp32c3_hal::{clock::ClockControl, gpio::IO, peripherals::Peripherals, prelude::*, Delay}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Set GPIO5 as an output, and set its state high initially. - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut led = io.pins.gpio5.into_push_pull_output(); - - led.set_high().unwrap(); - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - loop { - led.toggle().unwrap(); - delay.delay_ms(500u32); - } -} diff --git a/esp32c3-hal/examples/blinky_erased_pins.rs b/esp32c3-hal/examples/blinky_erased_pins.rs deleted file mode 100644 index 3a46a0553..000000000 --- a/esp32c3-hal/examples/blinky_erased_pins.rs +++ /dev/null @@ -1,53 +0,0 @@ -//! Blinks an LED -//! -//! This assumes that LEDs are connected to GPIO3, 4 and 5. - -#![no_std] -#![no_main] - -use esp32c3_hal::{ - clock::ClockControl, - gpio::{AnyPin, Input, Output, PullDown, PushPull, IO}, - peripherals::Peripherals, - prelude::*, - Delay, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Set LED GPIOs as an output. - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let led1 = io.pins.gpio3.into_push_pull_output(); - let led2 = io.pins.gpio4.into_push_pull_output(); - let led3 = io.pins.gpio5.into_push_pull_output(); - - // Set GPIO9 as an input. - let button = io.pins.gpio9.into_pull_down_input().into(); - - // You can use `into` or `degrade` - let mut pins = [led1.into(), led2.into(), led3.degrade().into()]; - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - loop { - toggle_pins(&mut pins, &button); - delay.delay_ms(500u32); - } -} - -fn toggle_pins(leds: &mut [AnyPin>], button: &AnyPin>) { - for pin in leds.iter_mut() { - pin.toggle().unwrap(); - } - - if button.is_low().unwrap() { - esp_println::println!("Button"); - } -} diff --git a/esp32c3-hal/examples/clock_monitor.rs b/esp32c3-hal/examples/clock_monitor.rs deleted file mode 100644 index 2069e5ac4..000000000 --- a/esp32c3-hal/examples/clock_monitor.rs +++ /dev/null @@ -1,65 +0,0 @@ -//! This demos a simple monitor for the XTAL frequency, by relying on a special -//! feature of the TIMG0 (Timer Group 0). This feature counts the number of XTAL -//! clock cycles within a given number of RTC_SLOW_CLK cycles. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32c3_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, - Rtc, -}; -use esp_backtrace as _; - -static RTC: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rtc = Rtc::new(peripherals.LPWR); - rtc.rwdt.start(2000u64.millis()); - rtc.rwdt.listen(); - - esp_println::println!( - "{: <10} XTAL frequency: {} MHz", - "[Expected]", - clocks.xtal_clock.to_MHz() - ); - - interrupt::enable( - peripherals::Interrupt::RTC_CORE, - interrupt::Priority::Priority1, - ) - .unwrap(); - - critical_section::with(|cs| { - RTC.borrow_ref_mut(cs).replace(rtc); - }); - - loop {} -} - -#[interrupt] -fn RTC_CORE() { - critical_section::with(|cs| { - let mut rtc = RTC.borrow(cs).borrow_mut(); - let rtc = rtc.as_mut().unwrap(); - - esp_println::println!( - "{: <10} XTAL frequency: {} MHz", - "[Monitor]", - rtc.estimate_xtal_frequency() - ); - - rtc.rwdt.clear_interrupt(); - }); -} diff --git a/esp32c3-hal/examples/crc.rs b/esp32c3-hal/examples/crc.rs deleted file mode 100644 index 482f5e77b..000000000 --- a/esp32c3-hal/examples/crc.rs +++ /dev/null @@ -1,95 +0,0 @@ -//! This shows example usage of the CRC functions in ROM - -#![no_std] -#![no_main] - -use core::fmt::Write; - -use esp32c3_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - rom::{crc, md5}, - timer::TimerGroup, - Uart, -}; -use esp_backtrace as _; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - timer0.start(1u64.secs()); - - let data = "123456789"; - let sentence = "The quick brown fox jumps over a lazy dog"; - - writeln!( - uart0, - "Performing CRC calculations on test string \"{data}\"" - ) - .unwrap(); - - loop { - let crc_hdlc = crc::crc32_le(!0xffffffff, data.as_ref()); - let crc_bzip2 = crc::crc32_be(!0xffffffff, data.as_ref()); - let crc_mpeg2 = !crc::crc32_be(!0xffffffff, data.as_ref()); - let crc_cksum = crc::crc32_be(!0, data.as_ref()); - let crc_kermit = !crc::crc16_le(!0, data.as_ref()); - let crc_genibus = crc::crc16_be(!0xffff, data.as_ref()); - let crc_rohc = !crc::crc8_le(!0xff, data.as_ref()); - let crc_smbus = !crc::crc8_be(!0, data.as_ref()); - - assert_eq!(crc_hdlc, 0xcbf43926); - assert_eq!(crc_bzip2, 0xfc891918); - assert_eq!(crc_mpeg2, 0x0376e6e7); - assert_eq!(crc_cksum, 0x765e7680); - assert_eq!(crc_kermit, 0x2189); - assert_eq!(crc_genibus, 0xd64e); - assert_eq!(crc_rohc, 0xd0); - assert_eq!(crc_smbus, 0xf4); - - // Hash the sentence one word at a time to *really* test the context - // Use Peekable while iter_intersperse is unstable - let mut md5_ctx = md5::Context::new(); - let mut it = sentence.split_whitespace().peekable(); - while let Some(word) = it.next() { - md5_ctx.consume(word); - if it.peek().is_some() { - md5_ctx.consume(" "); - } - } - let md5_digest = md5_ctx.compute(); - - assert_eq!( - md5_digest, - md5::Digest([ - 0x30, 0xde, 0xd8, 0x07, 0xd6, 0x5e, 0xe0, 0x37, 0x0f, 0xc6, 0xd7, 0x3d, 0x6a, 0xb5, - 0x5a, 0x95 - ]) - ); - - writeln!( - uart0, - "{:08x} {:08x} {:08x} {:08x} {:04x} {:04x} {:02x} {:02x} {}", - crc_hdlc, - crc_bzip2, - crc_mpeg2, - crc_cksum, - crc_kermit, - crc_genibus, - crc_rohc, - crc_smbus, - md5_digest - ) - .unwrap(); - - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32c3-hal/examples/debug_assist.rs b/esp32c3-hal/examples/debug_assist.rs deleted file mode 100644 index 75b410680..000000000 --- a/esp32c3-hal/examples/debug_assist.rs +++ /dev/null @@ -1,96 +0,0 @@ -//! This shows debug-assist -//! -//! Uncomment the functionality you want to test - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32c3_hal::{ - assist_debug::DebugAssist, - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, -}; -use esp_backtrace as _; -use esp_println::println; - -static DA: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _ = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut da = DebugAssist::new(peripherals.ASSIST_DEBUG); - - extern "C" { - // top of stack - static mut _stack_start: u32; - // bottom of stack - static mut _stack_end: u32; - } - - let stack_top = unsafe { &mut _stack_start } as *mut _ as u32; - let stack_bottom = unsafe { &mut _stack_end } as *mut _ as u32; - - // uncomment the functionality you want to test - - da.enable_sp_monitor(stack_bottom + 4096, stack_top); - // da.enable_region0_monitor(stack_bottom, stack_bottom + 4096, true, true); - // da.enable_region1_monitor(stack_bottom, stack_bottom + 4096, true, true); - - critical_section::with(|cs| DA.borrow_ref_mut(cs).replace(da)); - - interrupt::enable( - peripherals::Interrupt::ASSIST_DEBUG, - interrupt::Priority::Priority3, - ) - .unwrap(); - - eat_up_stack(0); - - loop {} -} - -#[allow(unconditional_recursion)] -fn eat_up_stack(v: u32) { - println!("Iteration {v}"); - eat_up_stack(v + 1); -} - -#[interrupt] -fn ASSIST_DEBUG() { - critical_section::with(|cs| { - println!("\n\nDEBUG_ASSIST interrupt"); - let mut da = DA.borrow_ref_mut(cs); - let da = da.as_mut().unwrap(); - - if da.is_sp_monitor_interrupt_set() { - println!("SP MONITOR TRIGGERED"); - da.clear_sp_monitor_interrupt(); - let pc = da.get_sp_monitor_pc(); - println!("PC = 0x{:x}", pc); - } - - if da.is_region0_monitor_interrupt_set() { - println!("REGION0 MONITOR TRIGGERED"); - da.clear_region0_monitor_interrupt(); - let pc = da.get_region_monitor_pc(); - println!("PC = 0x{:x}", pc); - } - - if da.is_region1_monitor_interrupt_set() { - println!("REGION1 MONITOR TRIGGERED"); - da.clear_region1_monitor_interrupt(); - let pc = da.get_region_monitor_pc(); - println!("PC = 0x{:x}", pc); - } - - loop {} - }); -} diff --git a/esp32c3-hal/examples/direct-vectoring.rs b/esp32c3-hal/examples/direct-vectoring.rs deleted file mode 100644 index 65ccfb968..000000000 --- a/esp32c3-hal/examples/direct-vectoring.rs +++ /dev/null @@ -1,83 +0,0 @@ -#![no_main] -#![no_std] -#![feature(naked_functions)] -use core::{arch::asm, cell::RefCell}; - -use critical_section::Mutex; -use esp32c3_hal::{ - clock::ClockControl, - interrupt::{ - CpuInterrupt, - {self}, - }, - peripherals::{self, Peripherals}, - prelude::*, - system::{SoftwareInterrupt, SoftwareInterruptControl}, -}; -use esp_backtrace as _; - -static SWINT: Mutex>> = Mutex::new(RefCell::new(None)); -#[entry] -unsafe fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clockctrl = system.clock_control; - let sw_int = system.software_interrupt_control; - let _clocks = ClockControl::boot_defaults(clockctrl).freeze(); - - critical_section::with(|cs| SWINT.borrow_ref_mut(cs).replace(sw_int)); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR0, - interrupt::Priority::Priority3, - CpuInterrupt::Interrupt1, - ) - .unwrap(); - unsafe { - asm!( - " - csrrwi x0, 0x7e0, 1 #what to count, for cycles write 1 for instructions write 2 - csrrwi x0, 0x7e1, 0 #disable counter - csrrwi x0, 0x7e2, 0 #reset counter - " - ); - } - esp_println::println!("MPC:{}", unsafe { fetch_performance_timer() }); - // interrupt is raised from assembly for max timer granularity. - unsafe { - asm!( - " - li t0, 0x600C0028 #FROM_CPU_INTR0 address - li t1, 1 #Flip flag - csrrwi x0, 0x7e1, 1 #enable timer - sw t1, 0(t0) #trigger FROM_CPU_INTR0 - " - ) - } - esp_println::println!("Returned"); - loop {} -} - -#[no_mangle] -fn cpu_int_1_handler() { - unsafe { asm!("csrrwi x0, 0x7e1, 0 #disable timer") } - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt0); - }); - esp_println::println!("Performance counter:{}", unsafe { - fetch_performance_timer() - }); -} -#[naked] -unsafe extern "C" fn fetch_performance_timer() -> i32 { - asm!( - " - csrr a0, 0x7e2 - jr ra - ", - options(noreturn) - ); -} diff --git a/esp32c3-hal/examples/embassy_hello_world.rs b/esp32c3-hal/examples/embassy_hello_world.rs deleted file mode 100644 index 3b0519ba1..000000000 --- a/esp32c3-hal/examples/embassy_hello_world.rs +++ /dev/null @@ -1,48 +0,0 @@ -//! embassy hello world -//! -//! This is an example of running the embassy executor with multiple tasks -//! concurrently. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32c3_hal::{clock::ClockControl, embassy, peripherals::Peripherals, prelude::*}; -use esp_backtrace as _; - -#[embassy_executor::task] -async fn run() { - loop { - esp_println::println!("Hello world from embassy using esp-hal-async!"); - Timer::after(Duration::from_millis(1_000)).await; - } -} - -#[main] -async fn main(spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32c3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - spawner.spawn(run()).ok(); - - loop { - esp_println::println!("Bing!"); - Timer::after(Duration::from_millis(5_000)).await; - } -} diff --git a/esp32c3-hal/examples/embassy_i2c.rs b/esp32c3-hal/examples/embassy_i2c.rs deleted file mode 100644 index 604309a2f..000000000 --- a/esp32c3-hal/examples/embassy_i2c.rs +++ /dev/null @@ -1,67 +0,0 @@ -//! Embassy I2C -//! -//! Folowing pins are used: -//! SDA GPIO1 -//! SCL GPIO2 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This is an example of running the embassy executor with IC2. It uses an -//! LIS3DH to get accelerometer data. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32c3_hal::{ - clock::ClockControl, - embassy, - i2c::I2C, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; -use lis3dh_async::{Lis3dh, Range, SlaveAddr}; - -#[main] -async fn main(_spawner: Spawner) { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32c3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let i2c0 = I2C::new( - peripherals.I2C0, - io.pins.gpio1, - io.pins.gpio2, - 400u32.kHz(), - &clocks, - ); - - let mut lis3dh = Lis3dh::new_i2c(i2c0, SlaveAddr::Alternate).await.unwrap(); - lis3dh.set_range(Range::G8).await.unwrap(); - - loop { - let norm = lis3dh.accel_norm().await.unwrap(); - esp_println::println!("X: {:+.5} Y: {:+.5} Z: {:+.5}", norm.x, norm.y, norm.z); - - Timer::after(Duration::from_millis(100)).await; - } -} diff --git a/esp32c3-hal/examples/embassy_i2s_read.rs b/esp32c3-hal/examples/embassy_i2s_read.rs deleted file mode 100644 index 2ea8ee7ef..000000000 --- a/esp32c3-hal/examples/embassy_i2s_read.rs +++ /dev/null @@ -1,99 +0,0 @@ -//! This shows how to continously receive data via I2S -//! -//! Pins used -//! MCLK GPIO4 -//! BCLK GPIO1 -//! WS GPIO2 -//! DIN GPIO5 -//! -//! Without an additional I2S source device you can connect 3V3 or GND to DIN to -//! read 0 or 0xFF or connect DIN to WS to read two different values -//! -//! You can also inspect the MCLK, BCLK and WS with a logic analyzer - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use esp32c3_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - embassy, - i2s::{asynch::*, DataFormat, I2s, Standard}, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -#[main] -async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32c3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (_, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(0, 4092 * 4); - - let i2s = I2s::new( - peripherals.I2S0, - Standard::Philips, - DataFormat::Data16Channel16, - 44100u32.Hz(), - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - &clocks, - ) - .with_mclk(io.pins.gpio4); - - let i2s_rx = i2s - .i2s_rx - .with_bclk(io.pins.gpio1) - .with_ws(io.pins.gpio2) - .with_din(io.pins.gpio5) - .build(); - - let buffer = rx_buffer; - println!("Start"); - - let mut data = [0u8; 5000]; - let mut transaction = i2s_rx.read_dma_circular_async(buffer).unwrap(); - loop { - let avail = transaction.available().await; - println!("available {}", avail); - - let count = transaction.pop(&mut data).await.unwrap(); - println!( - "got {} bytes, {:x?}..{:x?}", - count, - &data[..10], - &data[count - 10..count] - ); - } -} diff --git a/esp32c3-hal/examples/embassy_i2s_sound.rs b/esp32c3-hal/examples/embassy_i2s_sound.rs deleted file mode 100644 index b34c847f8..000000000 --- a/esp32c3-hal/examples/embassy_i2s_sound.rs +++ /dev/null @@ -1,136 +0,0 @@ -//! This shows how to transmit data continuously via I2S -//! -//! Pins used -//! MCLK GPIO4 -//! BCLK GPIO1 -//! WS GPIO2 -//! DOUT GPIO3 -//! -//! Without an additional I2S sink device you can inspect the MCLK, BCLK, WS and -//! DOUT with a logic analyzer -//! -//! You can also connect e.g. a PCM510x to hear an annoying loud sine tone (full -//! scale), so turn down the volume before running this example. -//! -//! Wiring is like this -//! -//! | Pin | Connected to | -//! |-------|-----------------| -//! | BCK | GPIO1 | -//! | DIN | GPIO3 | -//! | LRCK | GPIO2 | -//! | SCK | Gnd | -//! | GND | Gnd | -//! | VIN | +3V3 | -//! | FLT | Gnd | -//! | FMT | Gnd | -//! | DEMP | Gnd | -//! | XSMT | +3V3 | - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use esp32c3_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - embassy, - i2s::{asynch::*, DataFormat, I2s, Standard}, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -const SINE: [i16; 64] = [ - 0, 3211, 6392, 9511, 12539, 15446, 18204, 20787, 23169, 25329, 27244, 28897, 30272, 31356, - 32137, 32609, 32767, 32609, 32137, 31356, 30272, 28897, 27244, 25329, 23169, 20787, 18204, - 15446, 12539, 9511, 6392, 3211, 0, -3211, -6392, -9511, -12539, -15446, -18204, -20787, -23169, - -25329, -27244, -28897, -30272, -31356, -32137, -32609, -32767, -32609, -32137, -31356, -30272, - -28897, -27244, -25329, -23169, -20787, -18204, -15446, -12539, -9511, -6392, -3211, -]; - -#[main] -async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32c3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (tx_buffer, mut tx_descriptors, _, mut rx_descriptors) = dma_buffers!(32000, 0); - - let i2s = I2s::new( - peripherals.I2S0, - Standard::Philips, - DataFormat::Data16Channel16, - 44100u32.Hz(), - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - &clocks, - ) - .with_mclk(io.pins.gpio4); - - let i2s_tx = i2s - .i2s_tx - .with_bclk(io.pins.gpio1) - .with_ws(io.pins.gpio2) - .with_dout(io.pins.gpio3) - .build(); - - let data = - unsafe { core::slice::from_raw_parts(&SINE as *const _ as *const u8, SINE.len() * 2) }; - - let buffer = tx_buffer; - let mut idx = 0; - for i in 0..usize::min(data.len(), buffer.len()) { - buffer[i] = data[idx]; - - idx += 1; - - if idx >= data.len() { - idx = 0; - } - } - - let mut filler = [0u8; 10000]; - let mut idx = 32000 % data.len(); - - println!("Start"); - let mut transaction = i2s_tx.write_dma_circular_async(buffer).unwrap(); - loop { - for i in 0..filler.len() { - filler[i] = data[(idx + i) % data.len()]; - } - println!("Next"); - - let written = transaction.push(&filler).await.unwrap(); - idx = (idx + written) % data.len(); - println!("written {}", written); - } -} diff --git a/esp32c3-hal/examples/embassy_multiprio.rs b/esp32c3-hal/examples/embassy_multiprio.rs deleted file mode 100644 index d9469b446..000000000 --- a/esp32c3-hal/examples/embassy_multiprio.rs +++ /dev/null @@ -1,100 +0,0 @@ -//! This example shows how to use the interrupt executors to prioritize some -//! tasks over others. -//! -//! The example creates three tasks: -//! - A low priority task that is not actually async, but simulates some -//! blocking work. This task will run for 5 seconds, then sleep for 5 -//! seconds. -//! - A low priority task that is actually async, but will not be able to run -//! while the blocking task is running. -//! - A high priority task that prints something every second. The example -//! demonstrates that this task will continue to run even while the low -//! priority blocking task is running. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Instant, Ticker, Timer}; -use esp32c3_hal::{ - clock::ClockControl, - embassy::{ - self, - executor::{FromCpu1, InterruptExecutor}, - }, - interrupt::Priority, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; -use esp_println::println; - -static INT_EXECUTOR_0: InterruptExecutor = InterruptExecutor::new(); - -#[interrupt] -fn FROM_CPU_INTR1() { - unsafe { INT_EXECUTOR_0.on_interrupt() } -} - -/// Periodically print something. -#[embassy_executor::task] -async fn high_prio() { - println!("Starting high_prio()"); - let mut ticker = Ticker::every(Duration::from_secs(1)); - loop { - println!("High priority ticks"); - ticker.next().await; - } -} - -/// Simulates some blocking (badly behaving) task. -#[embassy_executor::task] -async fn low_prio_blocking() { - println!("Starting low-priority task that isn't actually async"); - loop { - println!("Doing some long and complicated calculation"); - let start = Instant::now(); - while start.elapsed() < Duration::from_secs(5) {} - println!("Calculation finished"); - Timer::after(Duration::from_secs(5)).await; - } -} - -/// A well-behaved, but starved async task. -#[embassy_executor::task] -async fn low_prio_async() { - println!("Starting low-priority task that will not be able to run while the blocking task is running"); - let mut ticker = Ticker::every(Duration::from_secs(1)); - loop { - println!("Low priority ticks"); - ticker.next().await; - } -} - -#[main] -async fn main(low_prio_spawner: Spawner) { - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32c3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let spawner = INT_EXECUTOR_0.start(Priority::Priority2); - spawner.must_spawn(high_prio()); - - println!("Spawning low-priority tasks"); - low_prio_spawner.must_spawn(low_prio_async()); - low_prio_spawner.must_spawn(low_prio_blocking()); -} diff --git a/esp32c3-hal/examples/embassy_rmt_rx.rs b/esp32c3-hal/examples/embassy_rmt_rx.rs deleted file mode 100644 index b96e88a64..000000000 --- a/esp32c3-hal/examples/embassy_rmt_rx.rs +++ /dev/null @@ -1,110 +0,0 @@ -//! Demonstrates decoding pulse sequences with RMT -//! This uses the boot button as input - press the button a couple of -//! times to generate a pulse sequence and then wait for the idle timeout to see -//! the recorded pulse sequence - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use esp32c3_hal::{ - clock::ClockControl, - embassy::{self}, - peripherals::Peripherals, - prelude::*, - rmt::{asynch::RxChannelAsync, PulseCode, RxChannelConfig, RxChannelCreator}, - Rmt, - IO, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -const WIDTH: usize = 80; - -#[main] -async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32c3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let rmt = Rmt::new(peripherals.RMT, 8u32.MHz(), &clocks).unwrap(); - - let mut channel = rmt - .channel2 - .configure( - io.pins.gpio9, - RxChannelConfig { - clk_divider: 255, - idle_threshold: 10000, - ..RxChannelConfig::default() - }, - ) - .unwrap(); - - let mut data = [PulseCode { - level1: true, - length1: 1, - level2: false, - length2: 1, - }; 48]; - - loop { - println!("receive"); - channel.receive(&mut data).await.unwrap(); - println!("received"); - let mut total = 0usize; - for entry in &data[..data.len()] { - if entry.length1 == 0 { - break; - } - total += entry.length1 as usize; - - if entry.length2 == 0 { - break; - } - total += entry.length2 as usize; - } - - for entry in &data[..data.len()] { - if entry.length1 == 0 { - break; - } - - let count = WIDTH / (total / entry.length1 as usize); - let c = if entry.level1 { '-' } else { '_' }; - for _ in 0..count + 1 { - print!("{}", c); - } - - if entry.length2 == 0 { - break; - } - - let count = WIDTH / (total / entry.length2 as usize); - let c = if entry.level2 { '-' } else { '_' }; - for _ in 0..count + 1 { - print!("{}", c); - } - } - - println!(); - } -} diff --git a/esp32c3-hal/examples/embassy_rmt_tx.rs b/esp32c3-hal/examples/embassy_rmt_tx.rs deleted file mode 100644 index 50e889364..000000000 --- a/esp32c3-hal/examples/embassy_rmt_tx.rs +++ /dev/null @@ -1,79 +0,0 @@ -//! Demonstrates generating pulse sequences with RMT -//! Connect a logic analyzer to GPIO1 to see the generated pulses. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32c3_hal::{ - clock::ClockControl, - embassy, - peripherals::Peripherals, - prelude::*, - rmt::{asynch::TxChannelAsync, PulseCode, TxChannelConfig, TxChannelCreator}, - Rmt, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -#[main] -async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32c3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let rmt = Rmt::new(peripherals.RMT, 8u32.MHz(), &clocks).unwrap(); - - let mut channel = rmt - .channel0 - .configure( - io.pins.gpio1.into_push_pull_output(), - TxChannelConfig { - clk_divider: 255, - ..TxChannelConfig::default() - }, - ) - .unwrap(); - - let mut data = [PulseCode { - level1: true, - length1: 200, - level2: false, - length2: 50, - }; 20]; - - data[data.len() - 2] = PulseCode { - level1: true, - length1: 3000, - level2: false, - length2: 500, - }; - data[data.len() - 1] = PulseCode::default(); - - loop { - println!("transmit"); - channel.transmit(&data).await.unwrap(); - println!("transmitted\n"); - Timer::after(Duration::from_millis(500)).await; - } -} diff --git a/esp32c3-hal/examples/embassy_serial.rs b/esp32c3-hal/examples/embassy_serial.rs deleted file mode 100644 index 9e1ac29c7..000000000 --- a/esp32c3-hal/examples/embassy_serial.rs +++ /dev/null @@ -1,96 +0,0 @@ -//! embassy serial -//! -//! This is an example of running the embassy executor and asynchronously -//! writing to and reading from uart - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_sync::{blocking_mutex::raw::NoopRawMutex, signal::Signal}; -use esp32c3_hal::{ - clock::ClockControl, - embassy, - peripherals::{Peripherals, UART0}, - prelude::*, - uart::{config::AtCmdConfig, UartRx, UartTx}, - Uart, -}; -use esp_backtrace as _; -use static_cell::make_static; - -// rx_fifo_full_threshold -const READ_BUF_SIZE: usize = 64; -// EOT (CTRL-D) -const AT_CMD: u8 = 0x04; - -#[embassy_executor::task] -async fn writer(mut tx: UartTx<'static, UART0>, signal: &'static Signal) { - use core::fmt::Write; - embedded_io_async::Write::write( - &mut tx, - b"Hello async serial. Enter something ended with EOT (CTRL-D).\r\n", - ) - .await - .unwrap(); - embedded_io_async::Write::flush(&mut tx).await.unwrap(); - loop { - let bytes_read = signal.wait().await; - signal.reset(); - write!(&mut tx, "\r\n-- received {} bytes --\r\n", bytes_read).unwrap(); - embedded_io_async::Write::flush(&mut tx).await.unwrap(); - } -} - -#[embassy_executor::task] -async fn reader(mut rx: UartRx<'static, UART0>, signal: &'static Signal) { - const MAX_BUFFER_SIZE: usize = 10 * READ_BUF_SIZE + 16; - - let mut rbuf: [u8; MAX_BUFFER_SIZE] = [0u8; MAX_BUFFER_SIZE]; - let mut offset = 0; - loop { - let r = embedded_io_async::Read::read(&mut rx, &mut rbuf[offset..]).await; - match r { - Ok(len) => { - offset += len; - esp_println::println!("Read: {len}, data: {:?}", &rbuf[..offset]); - offset = 0; - signal.signal(len); - } - Err(e) => esp_println::println!("RX Error: {:?}", e), - } - } -} - -#[main] -async fn main(spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32c3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - uart0.set_at_cmd(AtCmdConfig::new(None, None, None, AT_CMD, None)); - uart0 - .set_rx_fifo_full_threshold(READ_BUF_SIZE as u16) - .unwrap(); - let (tx, rx) = uart0.split(); - - let signal = &*make_static!(Signal::new()); - - spawner.spawn(reader(rx, &signal)).ok(); - spawner.spawn(writer(tx, &signal)).ok(); -} diff --git a/esp32c3-hal/examples/embassy_spi.rs b/esp32c3-hal/examples/embassy_spi.rs deleted file mode 100644 index 28250fedf..000000000 --- a/esp32c3-hal/examples/embassy_spi.rs +++ /dev/null @@ -1,87 +0,0 @@ -//! Embassy SPI -//! -//! Folowing pins are used: -//! SCLK GPIO6 -//! MISO GPIO2 -//! MOSI GPIO7 -//! CS GPIO10 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. -//! -//! This is an example of running the embassy executor with SPI. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32c3_hal::{ - clock::ClockControl, - dma::{DmaPriority, *}, - dma_descriptors, - embassy, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{prelude::*, Spi}, - SpiMode, - }, - IO, -}; -use esp_backtrace as _; - -#[main] -async fn main(_spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32c3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio6; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio7; - let cs = io.pins.gpio10; - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (mut descriptors, mut rx_descriptors) = dma_descriptors!(32000); - - let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) - .with_dma(dma_channel.configure( - false, - &mut descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let send_buffer = [0, 1, 2, 3, 4, 5, 6, 7]; - loop { - let mut buffer = [0; 8]; - esp_println::println!("Sending bytes"); - embedded_hal_async::spi::SpiBus::transfer(&mut spi, &mut buffer, &send_buffer) - .await - .unwrap(); - esp_println::println!("Bytes recieved: {:?}", buffer); - Timer::after(Duration::from_millis(5_000)).await; - } -} diff --git a/esp32c3-hal/examples/embassy_usb_serial_jtag.rs b/esp32c3-hal/examples/embassy_usb_serial_jtag.rs deleted file mode 100644 index b1a399f39..000000000 --- a/esp32c3-hal/examples/embassy_usb_serial_jtag.rs +++ /dev/null @@ -1,89 +0,0 @@ -//! This shows how to read and write text via USB Serial/JTAG using embassy. -//! You need to connect via the Serial/JTAG interface to see any output. -//! Most dev-kits use a USB-UART-bridge - in that case you won't see any output. -//! This will work with the ESP32-C3-DevKit-RUST-1 - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_sync::{blocking_mutex::raw::NoopRawMutex, signal::Signal}; -use esp32c3_hal::{ - clock::ClockControl, - embassy, - peripherals::Peripherals, - prelude::*, - UsbSerialJtag, -}; -use esp_backtrace as _; -use esp_hal::usb_serial_jtag::{UsbSerialJtagRx, UsbSerialJtagTx}; -use static_cell::make_static; - -const MAX_BUFFER_SIZE: usize = 512; - -#[embassy_executor::task] -async fn writer( - mut tx: UsbSerialJtagTx<'static>, - signal: &'static Signal>, -) { - use core::fmt::Write; - embedded_io_async::Write::write_all( - &mut tx, - b"Hello async USB Serial JTAG. Type something.\r\n", - ) - .await - .unwrap(); - loop { - let message = signal.wait().await; - signal.reset(); - write!(&mut tx, "-- received '{}' --\r\n", message).unwrap(); - embedded_io_async::Write::flush(&mut tx).await.unwrap(); - } -} - -#[embassy_executor::task] -async fn reader( - mut rx: UsbSerialJtagRx<'static>, - signal: &'static Signal>, -) { - let mut rbuf = [0u8; MAX_BUFFER_SIZE]; - loop { - let r = embedded_io_async::Read::read(&mut rx, &mut rbuf).await; - match r { - Ok(len) => { - let mut string_buffer: heapless::Vec<_, MAX_BUFFER_SIZE> = heapless::Vec::new(); - string_buffer.extend_from_slice(&rbuf[..len]).unwrap(); - signal.signal(heapless::String::from_utf8(string_buffer).unwrap()); - } - Err(e) => esp_println::println!("RX Error: {:?}", e), - } - } -} - -#[main] -async fn main(spawner: Spawner) -> () { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32c3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let (tx, rx) = UsbSerialJtag::new(peripherals.USB_DEVICE).split(); - - let signal = &*make_static!(Signal::new()); - - spawner.spawn(reader(rx, &signal)).unwrap(); - spawner.spawn(writer(tx, &signal)).unwrap(); -} diff --git a/esp32c3-hal/examples/embassy_wait.rs b/esp32c3-hal/examples/embassy_wait.rs deleted file mode 100644 index fb00a937b..000000000 --- a/esp32c3-hal/examples/embassy_wait.rs +++ /dev/null @@ -1,44 +0,0 @@ -//! embassy wait -//! -//! This is an example of asynchronously `Wait`ing for a pin state to change. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use embedded_hal_async::digital::Wait; -use esp32c3_hal::{clock::ClockControl, embassy, peripherals::Peripherals, prelude::*, IO}; -use esp_backtrace as _; - -#[main] -async fn main(_spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32c3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - // GPIO 9 as input - let mut input = io.pins.gpio9.into_pull_down_input(); - - loop { - esp_println::println!("Waiting..."); - input.wait_for_rising_edge().await.unwrap(); - esp_println::println!("Ping!"); - Timer::after(Duration::from_millis(100)).await; - } -} diff --git a/esp32c3-hal/examples/gpio_interrupt.rs b/esp32c3-hal/examples/gpio_interrupt.rs deleted file mode 100644 index bb0a1bed0..000000000 --- a/esp32c3-hal/examples/gpio_interrupt.rs +++ /dev/null @@ -1,59 +0,0 @@ -//! GPIO interrupt -//! -//! This prints "Interrupt" when the boot button is pressed. -//! It also blinks an LED like the blinky example. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32c3_hal::{ - clock::ClockControl, - gpio::{Event, Gpio9, Input, PullDown, IO}, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, - Delay, -}; -use esp_backtrace as _; - -static BUTTON: Mutex>>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Set GPIO5 as an output - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut led = io.pins.gpio5.into_push_pull_output(); - - // Set GPIO9 as an input - let mut button = io.pins.gpio9.into_pull_down_input(); - button.listen(Event::FallingEdge); - - critical_section::with(|cs| BUTTON.borrow_ref_mut(cs).replace(button)); - - interrupt::enable(peripherals::Interrupt::GPIO, interrupt::Priority::Priority3).unwrap(); - - let mut delay = Delay::new(&clocks); - loop { - led.toggle().unwrap(); - delay.delay_ms(500u32); - } -} - -#[interrupt] -fn GPIO() { - critical_section::with(|cs| { - esp_println::println!("GPIO interrupt"); - BUTTON - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .clear_interrupt(); - }); -} diff --git a/esp32c3-hal/examples/hello_rgb.rs b/esp32c3-hal/examples/hello_rgb.rs deleted file mode 100644 index 02d2e148f..000000000 --- a/esp32c3-hal/examples/hello_rgb.rs +++ /dev/null @@ -1,66 +0,0 @@ -//! //! RGB LED Demo -//! -//! This example drives an SK68XX RGB LED that is connected to the GPIO8 pin. -//! A RGB LED is connected to that pin on the ESP32-C3-DevKitM-1 and -//! ESP32-C3-DevKitC-02 boards. -//! -//! The demo will leverage the [`smart_leds`](https://crates.io/crates/smart-leds) -//! crate functionality to circle through the HSV hue color space (with -//! saturation and value both at 255). Additionally, we apply a gamma correction -//! and limit the brightness to 10 (out of 255). -#![no_std] -#![no_main] - -use esp32c3_hal::{clock::ClockControl, peripherals, prelude::*, rmt::Rmt, Delay, IO}; -use esp_backtrace as _; -use esp_hal_smartled::{smartLedBuffer, SmartLedsAdapter}; -use smart_leds::{ - brightness, - gamma, - hsv::{hsv2rgb, Hsv}, - SmartLedsWrite, -}; - -#[entry] -fn main() -> ! { - let peripherals = peripherals::Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Configure RMT peripheral globally - let rmt = Rmt::new(peripherals.RMT, 80u32.MHz(), &clocks).unwrap(); - - // We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can - // be used directly with all `smart_led` implementations - let rmt_buffer = smartLedBuffer!(1); - let mut led = SmartLedsAdapter::new(rmt.channel0, io.pins.gpio2, rmt_buffer, &clocks); - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - let mut color = Hsv { - hue: 0, - sat: 255, - val: 255, - }; - let mut data; - - loop { - // Iterate over the rainbow! - for hue in 0..=255 { - color.hue = hue; - // Convert from the HSV color space (where we can easily transition from one - // color to the other) to the RGB color space that we can then send to the LED - data = [hsv2rgb(color)]; - // When sending to the LED, we do a gamma correction first (see smart_leds - // documentation for details) and then limit the brightness to 10 out of 255 so - // that the output it's not too bright. - led.write(brightness(gamma(data.iter().cloned()), 10)) - .unwrap(); - delay.delay_ms(20u8); - } - } -} diff --git a/esp32c3-hal/examples/hello_world.rs b/esp32c3-hal/examples/hello_world.rs deleted file mode 100644 index dbebbec28..000000000 --- a/esp32c3-hal/examples/hello_world.rs +++ /dev/null @@ -1,35 +0,0 @@ -//! This shows how to write text to uart0. -//! You can see the output with `espflash` if you provide the `--monitor` option - -#![no_std] -#![no_main] - -use core::fmt::Write; - -use esp32c3_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, - Uart, -}; -use esp_backtrace as _; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - timer0.start(1u64.secs()); - - loop { - writeln!(uart0, "Hello world!").unwrap(); - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32c3-hal/examples/i2c_display.rs b/esp32c3-hal/examples/i2c_display.rs deleted file mode 100644 index bdc68022c..000000000 --- a/esp32c3-hal/examples/i2c_display.rs +++ /dev/null @@ -1,121 +0,0 @@ -//! I2C Display example -//! -//! This example prints some text on an SSD1306-based -//! display (via I2C) -//! -//! The following wiring is assumed: -//! - SDA => GPIO1 -//! - SCL => GPIO2 - -#![no_std] -#![no_main] - -use embedded_graphics::{ - mono_font::{ - ascii::{FONT_6X10, FONT_9X18_BOLD}, - MonoTextStyleBuilder, - }, - pixelcolor::BinaryColor, - prelude::*, - text::{Alignment, Text}, -}; -use esp32c3_hal::{ - clock::ClockControl, - gpio::IO, - i2c::I2C, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, -}; -use esp_backtrace as _; -use nb::block; -use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create a new peripheral object with the described wiring - // and standard I2C clock speed - let i2c = I2C::new( - peripherals.I2C0, - io.pins.gpio1, - io.pins.gpio2, - 100u32.kHz(), - &clocks, - ); - - // Start timer (5 second interval) - timer0.start(5u64.secs()); - - // Initialize display - let interface = I2CDisplayInterface::new(i2c); - let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0) - .into_buffered_graphics_mode(); - display.init().unwrap(); - - // Specify different text styles - let text_style = MonoTextStyleBuilder::new() - .font(&FONT_6X10) - .text_color(BinaryColor::On) - .build(); - let text_style_big = MonoTextStyleBuilder::new() - .font(&FONT_9X18_BOLD) - .text_color(BinaryColor::On) - .build(); - - loop { - // Fill display bufffer with a centered text with two lines (and two text - // styles) - Text::with_alignment( - "esp-hal", - display.bounding_box().center() + Point::new(0, 0), - text_style_big, - Alignment::Center, - ) - .draw(&mut display) - .unwrap(); - - Text::with_alignment( - "Chip: ESP32-C3", - display.bounding_box().center() + Point::new(0, 14), - text_style, - Alignment::Center, - ) - .draw(&mut display) - .unwrap(); - - // Write buffer to display - display.flush().unwrap(); - // Clear display buffer - display.clear(BinaryColor::Off).unwrap(); - - // Wait 5 seconds - block!(timer0.wait()).unwrap(); - - // Write single-line centered text "Hello World" to buffer - Text::with_alignment( - "Hello World!", - display.bounding_box().center(), - text_style_big, - Alignment::Center, - ) - .draw(&mut display) - .unwrap(); - - // Write buffer to display - display.flush().unwrap(); - // Clear display buffer - display.clear(BinaryColor::Off).unwrap(); - - // Wait 5 seconds - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32c3-hal/examples/i2s_read.rs b/esp32c3-hal/examples/i2s_read.rs deleted file mode 100644 index d0e128b4e..000000000 --- a/esp32c3-hal/examples/i2s_read.rs +++ /dev/null @@ -1,78 +0,0 @@ -//! This shows how to continously receive data via I2S -//! -//! Pins used -//! MCLK GPIO4 -//! BCLK GPIO1 -//! WS GPIO2 -//! DIN GPIO5 -//! -//! Without an additional I2S source device you can connect 3V3 or GND to DIN to -//! read 0 or 0xFF or connect DIN to WS to read two different values -//! -//! You can also inspect the MCLK, BCLK and WS with a logic analyzer - -#![no_std] -#![no_main] - -use esp32c3_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - i2s::{DataFormat, I2s, I2sReadDma, Standard}, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (_, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(0, 4092 * 4); - - let i2s = I2s::new( - peripherals.I2S0, - Standard::Philips, - DataFormat::Data16Channel16, - 44100u32.Hz(), - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - &clocks, - ) - .with_mclk(io.pins.gpio4); - - let i2s_rx = i2s - .i2s_rx - .with_bclk(io.pins.gpio1) - .with_ws(io.pins.gpio2) - .with_din(io.pins.gpio5) - .build(); - - let buffer = rx_buffer; - - let mut transfer = i2s_rx.read_dma_circular(buffer).unwrap(); - println!("Started transfer"); - - loop { - let avail = transfer.available(); - - if avail > 0 { - let mut rcv = [0u8; 5000]; - transfer.pop(&mut rcv[..avail]).unwrap(); - println!("Received {:x?}...", &rcv[..30]); - } - } -} diff --git a/esp32c3-hal/examples/i2s_sound.rs b/esp32c3-hal/examples/i2s_sound.rs deleted file mode 100644 index 4014fec2d..000000000 --- a/esp32c3-hal/examples/i2s_sound.rs +++ /dev/null @@ -1,120 +0,0 @@ -//! This shows how to transmit data continously via I2S -//! -//! Pins used -//! MCLK GPIO4 -//! BCLK GPIO1 -//! WS GPIO2 -//! DOUT GPIO3 -//! -//! Without an additional I2S sink device you can inspect the MCLK, BCLK, WS and -//! DOUT with a logic analyzer -//! -//! You can also connect e.g. a PCM510x to hear an annoying loud sine tone (full -//! scale), so turn down the volume before running this example. -//! -//! Wiring is like this -//! -//! | Pin | Connected to | -//! |-------|-----------------| -//! | BCK | GPIO1 | -//! | DIN | GPIO3 | -//! | LRCK | GPIO2 | -//! | SCK | Gnd | -//! | GND | Gnd | -//! | VIN | +3V3 | -//! | FLT | Gnd | -//! | FMT | Gnd | -//! | DEMP | Gnd | -//! | XSMT | +3V3 | - -#![no_std] -#![no_main] - -use esp32c3_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - i2s::{DataFormat, I2s, I2sWriteDma, Standard}, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; - -const SINE: [i16; 64] = [ - 0, 3211, 6392, 9511, 12539, 15446, 18204, 20787, 23169, 25329, 27244, 28897, 30272, 31356, - 32137, 32609, 32767, 32609, 32137, 31356, 30272, 28897, 27244, 25329, 23169, 20787, 18204, - 15446, 12539, 9511, 6392, 3211, 0, -3211, -6392, -9511, -12539, -15446, -18204, -20787, -23169, - -25329, -27244, -28897, -30272, -31356, -32137, -32609, -32767, -32609, -32137, -31356, -30272, - -28897, -27244, -25329, -23169, -20787, -18204, -15446, -12539, -9511, -6392, -3211, -]; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (tx_buffer, mut tx_descriptors, _, mut rx_descriptors) = dma_buffers!(32000, 0); - - let i2s = I2s::new( - peripherals.I2S0, - Standard::Philips, - DataFormat::Data16Channel16, - 44100u32.Hz(), - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - &clocks, - ) - .with_mclk(io.pins.gpio4); - - let i2s_tx = i2s - .i2s_tx - .with_bclk(io.pins.gpio1) - .with_ws(io.pins.gpio2) - .with_dout(io.pins.gpio3) - .build(); - - let data = - unsafe { core::slice::from_raw_parts(&SINE as *const _ as *const u8, SINE.len() * 2) }; - - let buffer = tx_buffer; - let mut idx = 0; - for i in 0..usize::min(data.len(), buffer.len()) { - buffer[i] = data[idx]; - - idx += 1; - - if idx >= data.len() { - idx = 0; - } - } - - let mut filler = [0u8; 10000]; - - let mut transfer = i2s_tx.write_dma_circular(buffer).unwrap(); - loop { - let avail = transfer.available(); - if avail > 0 { - let avail = usize::min(10000, avail); - for bidx in 0..avail { - filler[bidx] = data[idx]; - idx += 1; - - if idx >= data.len() { - idx = 0; - } - } - transfer.push(&filler[0..avail]).unwrap(); - } - } -} diff --git a/esp32c3-hal/examples/interrupt_preemption.rs b/esp32c3-hal/examples/interrupt_preemption.rs deleted file mode 100644 index 5581df8ce..000000000 --- a/esp32c3-hal/examples/interrupt_preemption.rs +++ /dev/null @@ -1,132 +0,0 @@ -//! Interrupt Preemption -//! -//! An example of how an interrupt can be preempted by another with higher -//! priority. Should show higher-numbered software interrupts happening during -//! the handling of lower-numbered ones. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32c3_hal::{ - clock::ClockControl, - interrupt::{self}, - peripherals::{self, Peripherals}, - prelude::*, - riscv, - system::{SoftwareInterrupt, SoftwareInterruptControl}, -}; -use esp_backtrace as _; - -static SWINT: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clockctrl = system.clock_control; - let sw_int = system.software_interrupt_control; - let _clocks = ClockControl::boot_defaults(clockctrl).freeze(); - - critical_section::with(|cs| SWINT.borrow_ref_mut(cs).replace(sw_int)); - - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR0, - interrupt::Priority::Priority1, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR1, - interrupt::Priority::Priority2, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR2, - interrupt::Priority::Priority2, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR3, - interrupt::Priority::Priority15, - ) - .unwrap(); - unsafe { riscv::interrupt::enable() } - - // raise mid priority interrupt. - // The handler raises one interrupt at lower priority, one at same and one at - // higher. We expect to see the higher priority served immeiately before - // exiting the handler Once the handler is exited we expect to see same - // priority and low priority interrupts served in that order - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt1); - }); - loop {} -} - -#[interrupt] -fn FROM_CPU_INTR0() { - esp_println::println!("SW interrupt0"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt0); - }); -} -#[interrupt] -fn FROM_CPU_INTR1() { - esp_println::println!("SW interrupt1 entry"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt1); - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt2); // raise interrupt at same priority - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt3); // raise interrupt at higher priority - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt0); // raise interrupt at - // lower priority - }); - esp_println::println!("SW interrupt1 exit"); -} -#[interrupt] -fn FROM_CPU_INTR2() { - esp_println::println!("SW interrupt2"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt2); - }); -} -#[interrupt] -fn FROM_CPU_INTR3() { - esp_println::println!("SW interrupt3"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt3); - }); -} diff --git a/esp32c3-hal/examples/ledc.rs b/esp32c3-hal/examples/ledc.rs deleted file mode 100644 index d94186fa5..000000000 --- a/esp32c3-hal/examples/ledc.rs +++ /dev/null @@ -1,66 +0,0 @@ -//! Turns on LED with the option to change LED intensity depending on `duty` -//! value, then fades it. Possible starting values (`u32`) are in range 0..100. -//! -//! This assumes that a LED is connected to the pin assigned to `led`. (GPIO4) - -#![no_std] -#![no_main] - -use esp32c3_hal::{ - clock::ClockControl, - gpio::IO, - ledc::{ - channel::{self, ChannelIFace}, - timer::{self, TimerIFace}, - LSGlobalClkSource, - LowSpeed, - LEDC, - }, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let led = io.pins.gpio4.into_push_pull_output(); - - let mut ledc = LEDC::new(peripherals.LEDC, &clocks); - ledc.set_global_slow_clock(LSGlobalClkSource::APBClk); - let mut lstimer0 = ledc.get_timer::(timer::Number::Timer2); - - lstimer0 - .configure(timer::config::Config { - duty: timer::config::Duty::Duty5Bit, - clock_source: timer::LSClockSource::APBClk, - frequency: 24u32.kHz(), - }) - .unwrap(); - - let mut channel0 = ledc.get_channel(channel::Number::Channel0, led); - channel0 - .configure(channel::config::Config { - timer: &lstimer0, - duty_pct: 10, - pin_config: channel::config::PinConfig::PushPull, - }) - .unwrap(); - - channel0.start_duty_fade(0, 100, 2000).expect_err( - "Fading from 0% to 100%, at 24kHz and 5-bit resolution, over 2 seconds, should fail", - ); - - loop { - // Set up a breathing LED: fade from off to on over a second, then - // from on back off over the next second. Then loop. - channel0.start_duty_fade(0, 100, 1000).unwrap(); - while channel0.is_duty_fade_running() {} - channel0.start_duty_fade(100, 0, 1000).unwrap(); - while channel0.is_duty_fade_running() {} - } -} diff --git a/esp32c3-hal/examples/qspi_flash.rs b/esp32c3-hal/examples/qspi_flash.rs deleted file mode 100644 index 87787f672..000000000 --- a/esp32c3-hal/examples/qspi_flash.rs +++ /dev/null @@ -1,167 +0,0 @@ -//! SPI write and read a flash chip -//! -//! Folowing pins are used: -//! SCLK GPIO6 -//! MISOI/IO0 GPIO2 -//! MOSI/IO1 GPIO3 -//! IO2 GPIO4 -//! IO3 GPIO5 -//! CS GPIO10 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! Connect a flash chip (GD25Q64C was used) and make sure QE in the status -//! register is set. - -#![no_std] -#![no_main] - -use esp32c3_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{prelude::*, Address, Command, Spi}, - SpiDataMode, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio6; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio3; - let sio2 = io.pins.gpio4; - let sio3 = io.pins.gpio5; - let cs = io.pins.gpio10; - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(256, 320); - - let mut spi = Spi::new_half_duplex(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(sio2), - Some(sio3), - Some(cs), - ) - .with_dma(dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let mut delay = Delay::new(&clocks); - - // DMA buffer require a static life-time - let mut zero_buf = zero_buffer(); - let send = tx_buffer; - let mut receive = rx_buffer; - - // write enable - let transfer = spi - .write( - SpiDataMode::Single, - Command::Command8(0x06, SpiDataMode::Single), - Address::None, - 0, - zero_buf, - ) - .unwrap(); - (zero_buf, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - // erase sector - let transfer = spi - .write( - SpiDataMode::Single, - Command::Command8(0x20, SpiDataMode::Single), - Address::Address24(0x000000, SpiDataMode::Single), - 0, - zero_buf, - ) - .unwrap(); - (zero_buf, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - // write enable - let transfer = spi - .write( - SpiDataMode::Single, - Command::Command8(0x06, SpiDataMode::Single), - Address::None, - 0, - zero_buf, - ) - .unwrap(); - (_, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - // write data / program page - send.fill(b'!'); - send[0..][..5].copy_from_slice(&b"Hello"[..]); - let transfer = spi - .write( - SpiDataMode::Quad, - Command::Command8(0x32, SpiDataMode::Single), - Address::Address24(0x000000, SpiDataMode::Single), - 0, - send, - ) - .unwrap(); - (_, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - loop { - // quad fast read - let transfer = spi - .read( - SpiDataMode::Quad, - Command::Command8(0xeb, SpiDataMode::Single), - Address::Address32(0x000000 << 8, SpiDataMode::Quad), - 4, - receive, - ) - .unwrap(); - - // here we could do something else while DMA transfer is in progress - // the buffers and spi is moved into the transfer and we can get it back via - // `wait` - (receive, spi) = transfer.wait().unwrap(); - - println!("{:x?}", &receive); - for b in &mut receive.iter() { - if *b >= 32 && *b <= 127 { - print!("{}", *b as char); - } else { - print!("."); - } - } - println!(); - - delay.delay_ms(250u32); - } -} - -fn zero_buffer() -> &'static mut [u8; 0] { - static mut BUFFER: [u8; 0] = [0u8; 0]; - unsafe { &mut BUFFER } -} diff --git a/esp32c3-hal/examples/read_efuse.rs b/esp32c3-hal/examples/read_efuse.rs deleted file mode 100644 index c96427c1d..000000000 --- a/esp32c3-hal/examples/read_efuse.rs +++ /dev/null @@ -1,21 +0,0 @@ -//! This shows how to read selected information from eFuses. -//! e.g. the MAC address - -#![no_std] -#![no_main] - -use esp32c3_hal::{clock::ClockControl, efuse::Efuse, peripherals::Peripherals, prelude::*}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - println!("MAC address {:02x?}", Efuse::get_mac_address()); - println!("Flash Encryption {:?}", Efuse::get_flash_encryption()); - - loop {} -} diff --git a/esp32c3-hal/examples/rmt_rx.rs b/esp32c3-hal/examples/rmt_rx.rs deleted file mode 100644 index a5c01d975..000000000 --- a/esp32c3-hal/examples/rmt_rx.rs +++ /dev/null @@ -1,99 +0,0 @@ -//! Demonstrates decoding pulse sequences with RMT -//! This uses the boot button as input - press the button a couple of -//! times to generate a pulse sequence and then wait for the idle timeout to see -//! the recorded pulse sequence - -#![no_std] -#![no_main] - -use esp32c3_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - rmt::{PulseCode, RxChannel, RxChannelConfig, RxChannelCreator}, - Delay, - Rmt, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -const WIDTH: usize = 80; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let rmt = Rmt::new(peripherals.RMT, 1u32.MHz(), &clocks).unwrap(); - - let mut channel = rmt - .channel2 - .configure( - io.pins.gpio9, - RxChannelConfig { - clk_divider: 255, - idle_threshold: 10000, - ..RxChannelConfig::default() - }, - ) - .unwrap(); - - let mut delay = Delay::new(&clocks); - - let mut data = [PulseCode { - level1: true, - length1: 1, - level2: false, - length2: 1, - }; 48]; - - loop { - let transaction = channel.receive(&mut data).unwrap(); - channel = transaction.wait().unwrap(); - - let mut total = 0usize; - for entry in &data[..data.len()] { - if entry.length1 == 0 { - break; - } - total += entry.length1 as usize; - - if entry.length2 == 0 { - break; - } - total += entry.length2 as usize; - } - - for entry in &data[..data.len()] { - if entry.length1 == 0 { - break; - } - - let count = WIDTH / (total / entry.length1 as usize); - let c = if entry.level1 { '-' } else { '_' }; - for _ in 0..count + 1 { - print!("{}", c); - } - - if entry.length2 == 0 { - break; - } - - let count = WIDTH / (total / entry.length2 as usize); - let c = if entry.level2 { '-' } else { '_' }; - for _ in 0..count + 1 { - print!("{}", c); - } - } - - println!(); - println!(); - println!(); - - delay.delay_ms(500u32); - } -} diff --git a/esp32c3-hal/examples/rmt_tx.rs b/esp32c3-hal/examples/rmt_tx.rs deleted file mode 100644 index b5b7d9bb6..000000000 --- a/esp32c3-hal/examples/rmt_tx.rs +++ /dev/null @@ -1,61 +0,0 @@ -//! Demonstrates generating pulse sequences with RMT -//! Connect a logic analyzer to GPIO1 to see the generated pulses. - -#![no_std] -#![no_main] - -use esp32c3_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - rmt::{PulseCode, TxChannel, TxChannelConfig, TxChannelCreator}, - Delay, - Rmt, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let rmt = Rmt::new(peripherals.RMT, 8u32.MHz(), &clocks).unwrap(); - - let mut channel = rmt - .channel0 - .configure( - io.pins.gpio1.into_push_pull_output(), - TxChannelConfig { - clk_divider: 255, - ..TxChannelConfig::default() - }, - ) - .unwrap(); - - let mut delay = Delay::new(&clocks); - - let mut data = [PulseCode { - level1: true, - length1: 200, - level2: false, - length2: 50, - }; 20]; - - data[data.len() - 2] = PulseCode { - level1: true, - length1: 3000, - level2: false, - length2: 500, - }; - data[data.len() - 1] = PulseCode::default(); - - loop { - let transaction = channel.transmit(&data); - channel = transaction.wait().unwrap(); - delay.delay_ms(500u32); - } -} diff --git a/esp32c3-hal/examples/rng.rs b/esp32c3-hal/examples/rng.rs deleted file mode 100644 index 05685e70c..000000000 --- a/esp32c3-hal/examples/rng.rs +++ /dev/null @@ -1,28 +0,0 @@ -//! Demonstrates the use of the hardware Random Number Generator (RNG) - -#![no_std] -#![no_main] - -use esp32c3_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Rng}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Instantiate the Random Number Generator peripheral: - let mut rng = Rng::new(peripherals.RNG); - - // Generate a random word (u32): - println!("Random u32: {}", rng.random()); - - // Fill a buffer with random bytes: - let mut buf = [0u8; 16]; - rng.read(&mut buf).unwrap(); - println!("Random bytes: {:?}", buf); - - loop {} -} diff --git a/esp32c3-hal/examples/rsa.rs b/esp32c3-hal/examples/rsa.rs deleted file mode 100644 index ba1a77543..000000000 --- a/esp32c3-hal/examples/rsa.rs +++ /dev/null @@ -1,156 +0,0 @@ -//! Demonstrates the use of the RSA peripheral and compares the speed of -//! multiple arithmetic operations. - -#![no_std] -#![no_main] - -use crypto_bigint::{ - modular::runtime_mod::{DynResidue, DynResidueParams}, - Uint, - U1024, - U512, -}; -use esp32c3_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - rsa::{ - operand_sizes, - Rsa, - RsaModularExponentiation, - RsaModularMultiplication, - RsaMultiplication, - }, - systimer::SystemTimer, -}; -use esp_backtrace as _; -use esp_println::println; - -const BIGNUM_1: U512 = Uint::from_be_hex( - "c7f61058f96db3bd87dbab08ab03b4f7f2f864eac249144adea6a65f97803b719d8ca980b7b3c0389c1c7c6\ -7dc353c5e0ec11f5fc8ce7f6073796cc8f73fa878", -); -const BIGNUM_2: U512 = Uint::from_be_hex( - "1763db3344e97be15d04de4868badb12a38046bb793f7630d87cf100aa1c759afac15a01f3c4c83ec2d2f66\ -6bd22f71c3c1f075ec0e2cb0cb29994d091b73f51", -); -const BIGNUM_3: U512 = Uint::from_be_hex( - "6b6bb3d2b6cbeb45a769eaa0384e611e1b89b0c9b45a045aca1c5fd6e8785b38df7118cf5dd45b9b63d293b\ -67aeafa9ba25feb8712f188cb139b7d9b9af1c361", -); - -const fn compute_r(modulus: &U512) -> U512 { - let mut d = [0_u32; U512::LIMBS * 2 + 1]; - d[d.len() - 1] = 1; - let d = Uint::from_words(d); - d.const_rem(&modulus.resize()).0.resize() -} - -const fn compute_mprime(modulus: &U512) -> u32 { - let m_inv = modulus.inv_mod2k(32).to_words()[0]; - (-1 * m_inv as i64 % 4294967296) as u32 -} - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rsa = Rsa::new(peripherals.RSA); - - nb::block!(rsa.ready()).unwrap(); - mod_exp_example(&mut rsa); - mod_multi_example(&mut rsa); - multiplication_example(&mut rsa); - loop {} -} - -fn mod_multi_example(rsa: &mut Rsa) { - let mut outbuf = [0_u32; U512::LIMBS]; - let mut mod_multi = RsaModularMultiplication::::new( - rsa, - BIGNUM_1.as_words(), - BIGNUM_2.as_words(), - BIGNUM_3.as_words(), - compute_mprime(&BIGNUM_3), - ); - let r = compute_r(&BIGNUM_3); - let pre_hw_modmul = SystemTimer::now(); - mod_multi.start_modular_multiplication(r.as_words()); - mod_multi.read_results(&mut outbuf); - let post_hw_modmul = SystemTimer::now(); - println!( - "it took {} cycles for hw modular multiplication", - post_hw_modmul - pre_hw_modmul - ); - let residue_params = DynResidueParams::new(&BIGNUM_3); - let residue_num1 = DynResidue::new(&BIGNUM_1, residue_params); - let residue_num2 = DynResidue::new(&BIGNUM_2, residue_params); - let pre_sw_exp = SystemTimer::now(); - let sw_out = residue_num1.mul(&residue_num2); - let post_sw_exp = SystemTimer::now(); - println!( - "it took {} cycles for sw modular multiplication", - post_sw_exp - pre_sw_exp - ); - assert_eq!(U512::from_words(outbuf), sw_out.retrieve()); - println!("modular multiplication done"); -} - -fn mod_exp_example(rsa: &mut Rsa) { - rsa.enable_disable_constant_time_acceleration(true); - rsa.enable_disable_search_acceleration(true); - let mut outbuf = [0_u32; U512::LIMBS]; - let mut mod_exp = RsaModularExponentiation::::new( - rsa, - BIGNUM_2.as_words(), - BIGNUM_3.as_words(), - compute_mprime(&BIGNUM_3), - ); - let r = compute_r(&BIGNUM_3); - let base = &BIGNUM_1.as_words(); - let pre_hw_exp = SystemTimer::now(); - mod_exp.start_exponentiation(&base, r.as_words()); - mod_exp.read_results(&mut outbuf); - let post_hw_exp = SystemTimer::now(); - println!( - "it took {} cycles for hw modular exponentiation", - post_hw_exp - pre_hw_exp - ); - let residue_params = DynResidueParams::new(&BIGNUM_3); - let residue = DynResidue::new(&BIGNUM_1, residue_params); - let pre_sw_exp = SystemTimer::now(); - let sw_out = residue.pow(&BIGNUM_2); - let post_sw_exp = SystemTimer::now(); - println!( - "it took {} cycles for sw modular exponentiation", - post_sw_exp - pre_sw_exp - ); - assert_eq!(U512::from_words(outbuf), sw_out.retrieve()); - println!("modular exponentiation done"); -} - -fn multiplication_example(rsa: &mut Rsa) { - let mut out = [0_u32; U1024::LIMBS]; - let operand_a = BIGNUM_1; - let operand_b = BIGNUM_2; - let mut rsamulti = RsaMultiplication::::new(rsa, operand_a.as_words()); - let pre_hw_mul = SystemTimer::now(); - rsamulti.start_multiplication(operand_b.as_words()); - rsamulti.read_results(&mut out); - let post_hw_mul = SystemTimer::now(); - println!( - "it took {} cycles for hw multiplication", - post_hw_mul - pre_hw_mul - ); - let pre_sw_mul = SystemTimer::now(); - let sw_out = BIGNUM_1.mul_wide(&BIGNUM_2); - let post_sw_mul = SystemTimer::now(); - println!( - "it took {} cycles for sw multiplication", - post_sw_mul - pre_sw_mul - ); - assert_eq!(U1024::from_words(out), sw_out.1.concat(&sw_out.0)); - println!("multiplication done"); -} diff --git a/esp32c3-hal/examples/rtc_time.rs b/esp32c3-hal/examples/rtc_time.rs deleted file mode 100644 index 93b71bcfe..000000000 --- a/esp32c3-hal/examples/rtc_time.rs +++ /dev/null @@ -1,22 +0,0 @@ -//! Prints time in milliseconds from the RTC Timer - -#![no_std] -#![no_main] - -use esp32c3_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Delay, Rtc}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let rtc = Rtc::new(peripherals.LPWR); - let mut delay = Delay::new(&clocks); - - loop { - esp_println::println!("rtc time in milliseconds is {}", rtc.get_time_ms()); - delay.delay_ms(1000u32); - } -} diff --git a/esp32c3-hal/examples/rtc_watchdog.rs b/esp32c3-hal/examples/rtc_watchdog.rs deleted file mode 100644 index 194f65f4f..000000000 --- a/esp32c3-hal/examples/rtc_watchdog.rs +++ /dev/null @@ -1,60 +0,0 @@ -//! This demos the RTC Watchdog Timer (RWDT). -//! The RWDT is initially configured to trigger an interrupt after a given -//! timeout. Then, upon expiration, the RWDT is restarted and then reconfigured -//! to reset both the main system and the RTC. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32c3_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, - Rtc, - Rwdt, -}; -use esp_backtrace as _; - -static RWDT: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rtc = Rtc::new(peripherals.LPWR); - rtc.rwdt.start(2000u64.millis()); - rtc.rwdt.listen(); - - interrupt::enable( - peripherals::Interrupt::RTC_CORE, - interrupt::Priority::Priority1, - ) - .unwrap(); - - critical_section::with(|cs| RWDT.borrow_ref_mut(cs).replace(rtc.rwdt)); - - loop {} -} - -#[interrupt] -fn RTC_CORE() { - critical_section::with(|cs| { - esp_println::println!("RWDT Interrupt"); - - let mut rwdt = RWDT.borrow_ref_mut(cs); - let rwdt = rwdt.as_mut().unwrap(); - - rwdt.clear_interrupt(); - - esp_println::println!("Restarting in 5 seconds..."); - - rwdt.start(5000u64.millis()); - rwdt.unlisten(); - }); -} diff --git a/esp32c3-hal/examples/serial_interrupts.rs b/esp32c3-hal/examples/serial_interrupts.rs deleted file mode 100644 index 7b2b47640..000000000 --- a/esp32c3-hal/examples/serial_interrupts.rs +++ /dev/null @@ -1,88 +0,0 @@ -//! This shows some of the interrupts that can be generated by UART/Serial. -//! Use a proper serial terminal to connect to the board (espmonitor and -//! espflash won't work) - -#![no_std] -#![no_main] - -use core::{cell::RefCell, fmt::Write}; - -use critical_section::Mutex; -use esp32c3_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals, UART0}, - prelude::*, - timer::TimerGroup, - uart::config::AtCmdConfig, - Cpu, - Uart, -}; -use esp_backtrace as _; -use nb::block; - -static SERIAL: Mutex>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - uart0.set_at_cmd(AtCmdConfig::new(None, None, None, b'#', None)); - uart0.set_rx_fifo_full_threshold(30).unwrap(); - uart0.listen_at_cmd(); - uart0.listen_rx_fifo_full(); - - timer0.start(1u64.secs()); - - critical_section::with(|cs| SERIAL.borrow_ref_mut(cs).replace(uart0)); - - interrupt::enable( - peripherals::Interrupt::UART0, - interrupt::Priority::Priority1, - ) - .unwrap(); - interrupt::set_kind( - Cpu::ProCpu, - interrupt::CpuInterrupt::Interrupt1, // Interrupt 1 handles priority one interrupts - interrupt::InterruptKind::Edge, - ); - - loop { - critical_section::with(|cs| { - writeln!(SERIAL.borrow_ref_mut(cs).as_mut().unwrap(), "Hello World! Send a single `#` character or send at least 30 characters and see the interrupts trigger.").ok(); - }); - - block!(timer0.wait()).unwrap(); - } -} - -#[interrupt] -fn UART0() { - critical_section::with(|cs| { - let mut serial = SERIAL.borrow_ref_mut(cs); - let serial = serial.as_mut().unwrap(); - - let mut cnt = 0; - while let nb::Result::Ok(_c) = serial.read() { - cnt += 1; - } - writeln!(serial, "Read {} bytes", cnt,).ok(); - - writeln!( - serial, - "Interrupt AT-CMD: {} RX-FIFO-FULL: {}", - serial.at_cmd_interrupt_set(), - serial.rx_fifo_full_interrupt_set(), - ) - .ok(); - - serial.reset_at_cmd_interrupt(); - serial.reset_rx_fifo_full_interrupt(); - }); -} diff --git a/esp32c3-hal/examples/sha.rs b/esp32c3-hal/examples/sha.rs deleted file mode 100644 index 6a5a1cd17..000000000 --- a/esp32c3-hal/examples/sha.rs +++ /dev/null @@ -1,71 +0,0 @@ -//! Demonstrates the use of the SHA peripheral and compares the speed of -//! hardware-accelerated and pure software hashing. - -#![no_std] -#![no_main] - -use esp32c3_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - sha::{Sha, ShaMode}, -}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; -use sha2::{Digest, Sha256}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let source_data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".as_bytes(); - let mut remaining = source_data; - let mut hasher = Sha::new(peripherals.SHA, ShaMode::SHA256); - - // Short hashes can be created by decreasing the output buffer to the desired - // length - let mut output = [0u8; 32]; - - // let pre_calc = xtensa_lx::timer::get_cycle_count(); - // The hardware implementation takes a subslice of the input, and returns the - // unprocessed parts The unprocessed parts can be input in the next - // iteration, you can always add more data until finish() is called. After - // finish() is called update()'s will contribute to a new hash which - // can be extracted again with finish(). - - while remaining.len() > 0 { - // Can add println to view progress, however println takes a few orders of - // magnitude longer than the Sha function itself so not useful for - // comparing processing time println!("Remaining len: {}", - // remaining.len()); - - // All the HW Sha functions are infallible so unwrap is fine to use if you use - // block! - remaining = block!(hasher.update(remaining)).unwrap(); - } - - // Finish can be called as many times as desired to get mutliple copies of the - // output. - block!(hasher.finish(output.as_mut_slice())).unwrap(); - // let post_calc = xtensa_lx::timer::get_cycle_count(); - // let hw_time = post_calc - pre_calc; - // println!("Took {} cycles", hw_time); - println!("SHA256 Hash output {:02x?}", output); - - // let pre_calc = xtensa_lx::timer::get_cycle_count(); - let mut hasher = Sha256::new(); - hasher.update(source_data); - let soft_result = hasher.finalize(); - // let post_calc = xtensa_lx::timer::get_cycle_count(); - // let soft_time = post_calc - pre_calc; - // println!("Took {} cycles", soft_time); - println!("SHA256 Hash output {:02x?}", soft_result); - - assert_eq!(output, soft_result[..]); - // println!("HW SHA is {}x faster", soft_time/hw_time); - - loop {} -} diff --git a/esp32c3-hal/examples/software_interrupts.rs b/esp32c3-hal/examples/software_interrupts.rs deleted file mode 100644 index 3dc1fed8d..000000000 --- a/esp32c3-hal/examples/software_interrupts.rs +++ /dev/null @@ -1,142 +0,0 @@ -//! Software Interrupts -//! -//! An example of how software interrupts can be raised and reset -//! Should rotate through all of the available interrupts printing their number -//! when raised. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32c3_hal::{ - clock::ClockControl, - interrupt::{self}, - peripherals::{self, Peripherals}, - prelude::*, - riscv, - system::{SoftwareInterrupt, SoftwareInterruptControl}, - Delay, -}; -use esp_backtrace as _; - -static SWINT: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clockctrl = system.clock_control; - let sw_int = system.software_interrupt_control; - let clocks = ClockControl::boot_defaults(clockctrl).freeze(); - - critical_section::with(|cs| SWINT.borrow_ref_mut(cs).replace(sw_int)); - - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR0, - interrupt::Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR1, - interrupt::Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR2, - interrupt::Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR3, - interrupt::Priority::Priority3, - ) - .unwrap(); - unsafe { riscv::interrupt::enable() } - let mut delay = Delay::new(&clocks); - let mut counter = 0; - loop { - delay.delay_ms(500u32); - match counter { - 0 => critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt0); - }), - 1 => critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt1); - }), - 2 => critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt2); - }), - 3 => { - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt3); - }); - counter = -1 - } - _ => {} - } - counter += 1; - } -} - -#[interrupt] -fn FROM_CPU_INTR0() { - esp_println::println!("SW interrupt0"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt0); - }); -} -#[interrupt] -fn FROM_CPU_INTR1() { - esp_println::println!("SW interrupt1"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt1); - }); -} -#[interrupt] -fn FROM_CPU_INTR2() { - esp_println::println!("SW interrupt2"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt2); - }); -} -#[interrupt] -fn FROM_CPU_INTR3() { - esp_println::println!("SW interrupt3"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt3); - }); -} diff --git a/esp32c3-hal/examples/spi_eh1_device_loopback.rs b/esp32c3-hal/examples/spi_eh1_device_loopback.rs deleted file mode 100644 index ace928bbe..000000000 --- a/esp32c3-hal/examples/spi_eh1_device_loopback.rs +++ /dev/null @@ -1,140 +0,0 @@ -//! SPI loopback test -//! -//! Folowing pins are used: -//! SCLK GPIO6 -//! MISO GPIO2 -//! MOSI GPIO7 -//! CS 1 GPIO3 -//! CS 2 GPIO4 -//! CS 3 GPIO5 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use embedded_hal_1::spi::SpiDevice; -use embedded_hal_bus::spi::RefCellDevice; -use esp32c3_hal::{ - clock::ClockControl, - gpio::{self, IO}, - peripherals::Peripherals, - prelude::*, - spi::{master::Spi, SpiMode}, - Delay, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio6; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio7; - - let spi_bus = Spi::new(peripherals.SPI2, 1000u32.kHz(), SpiMode::Mode0, &clocks).with_pins( - Some(sclk), - Some(mosi), - Some(miso), - gpio::NO_PIN, - ); - let spi_bus = RefCell::new(spi_bus); - let mut spi_device_1 = - RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio3.into_push_pull_output()); - let mut spi_device_2 = - RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio4.into_push_pull_output()); - let mut spi_device_3 = - RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio5.into_push_pull_output()); - - let mut delay = Delay::new(&clocks); - println!("=== SPI example with embedded-hal-1 traits ==="); - - loop { - // --- Symmetric transfer (Read as much as we write) --- - print!("Starting symmetric transfer..."); - let write = [0xde, 0xad, 0xbe, 0xef]; - let mut read: [u8; 4] = [0x00u8; 4]; - - spi_device_1.transfer(&mut read[..], &write[..]).unwrap(); - assert_eq!(write, read); - spi_device_2.transfer(&mut read[..], &write[..]).unwrap(); - spi_device_3.transfer(&mut read[..], &write[..]).unwrap(); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Asymmetric transfer (Read more than we write) --- - print!("Starting asymetric transfer (read > write)..."); - let mut read: [u8; 4] = [0x00; 4]; - - spi_device_1 - .transfer(&mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - assert_eq!(write[0], read[0]); - assert_eq!(read[2], 0x00u8); - spi_device_2 - .transfer(&mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - spi_device_3 - .transfer(&mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer --- - // Only your RAM is the limit! - print!("Starting huge transfer..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - let mut read = [0x00u8; 4096]; - - spi_device_1 - .transfer(&mut read[..], &write[..]) - .expect("Huge transfer failed"); - assert_eq!(write, read); - spi_device_2 - .transfer(&mut read[..], &write[..]) - .expect("Huge transfer failed"); - spi_device_3 - .transfer(&mut read[..], &write[..]) - .expect("Huge transfer failed"); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer in-place (No additional allocation - // needed) --- - print!("Starting huge transfer (in-place)..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - - spi_device_1 - .transfer_in_place(&mut write[..]) - .expect("Huge transfer failed"); - for byte in 0..write.len() { - assert_eq!(write[byte], byte as u8); - } - spi_device_2 - .transfer_in_place(&mut write[..]) - .expect("Huge transfer failed"); - spi_device_3 - .transfer_in_place(&mut write[..]) - .expect("Huge transfer failed"); - println!(" SUCCESS"); - delay.delay_ms(250u32); - } -} diff --git a/esp32c3-hal/examples/spi_loopback.rs b/esp32c3-hal/examples/spi_loopback.rs deleted file mode 100644 index 811293cc1..000000000 --- a/esp32c3-hal/examples/spi_loopback.rs +++ /dev/null @@ -1,58 +0,0 @@ -//! SPI loopback test -//! -//! Folowing pins are used: -//! SCLK GPIO6 -//! MISO GPIO2 -//! MOSI GPIO7 -//! CS GPIO10 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use esp32c3_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{master::Spi, SpiMode}, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio6; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio7; - let cs = io.pins.gpio10; - - let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks).with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(cs), - ); - - let mut delay = Delay::new(&clocks); - - loop { - let mut data = [0xde, 0xca, 0xfb, 0xad]; - spi.transfer(&mut data).unwrap(); - println!("{:x?}", data); - - delay.delay_ms(250u32); - } -} diff --git a/esp32c3-hal/examples/spi_loopback_dma.rs b/esp32c3-hal/examples/spi_loopback_dma.rs deleted file mode 100644 index 41ebda924..000000000 --- a/esp32c3-hal/examples/spi_loopback_dma.rs +++ /dev/null @@ -1,97 +0,0 @@ -//! SPI loopback test using DMA -//! -//! Folowing pins are used: -//! SCLK GPIO6 -//! MISO GPIO2 -//! MOSI GPIO7 -//! CS GPIO10 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use esp32c3_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{prelude::*, Spi}, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio6; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio7; - let cs = io.pins.gpio10; - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(32000); - - let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) - .with_dma(dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let mut delay = Delay::new(&clocks); - - // DMA buffer require a static life-time - let mut send = tx_buffer; - let mut receive = rx_buffer; - let mut i = 0; - - for (i, v) in send.iter_mut().enumerate() { - *v = (i % 255) as u8; - } - - loop { - send[0] = i; - send[send.len() - 1] = i; - i = i.wrapping_add(1); - - let transfer = spi.dma_transfer(send, receive).unwrap(); - // here we could do something else while DMA transfer is in progress - let mut n = 0; - // Check is_done until the transfer is almost done (32000 bytes at 100kHz is - // 2.56 seconds), then move to wait(). - while !transfer.is_done() && n < 10 { - delay.delay_ms(250u32); - n += 1; - } - // the buffers and spi is moved into the transfer and we can get it back via - // `wait` - (receive, send, spi) = transfer.wait().unwrap(); - println!( - "{:x?} .. {:x?}", - &receive[..10], - &receive[receive.len() - 10..] - ); - - delay.delay_ms(250u32); - } -} diff --git a/esp32c3-hal/examples/spi_slave_dma.rs b/esp32c3-hal/examples/spi_slave_dma.rs deleted file mode 100644 index 606bae8ad..000000000 --- a/esp32c3-hal/examples/spi_slave_dma.rs +++ /dev/null @@ -1,203 +0,0 @@ -//! SPI slave loopback test using DMA -//! -//! Following pins are used for the slave: -//! SCLK GPIO6 -//! MISO GPIO2 -//! MOSI GPIO7 -//! CS GPIO10 -//! -//! Following pins are used for the (bitbang) master: -//! SCLK GPIO5 -//! MISO GPIO1 -//! MOSI GPIO8 -//! CS GPIO9 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect corresponding master and slave pins to see the outgoing data is read -//! as incoming data. The master-side pins are chosen to make these connections -//! easy for the barebones ESP32C3 chip; all are immediate neighbors of the -//! slave-side pins except SCLK. SCLK is between MOSI and VDD3P3_RTC on the -//! barebones ESP32C3, so no immediate neighbor is available. - -#![no_std] -#![no_main] - -use esp32c3_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - slave::{prelude::*, Spi}, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let slave_sclk = io.pins.gpio6; - let mut master_sclk = io.pins.gpio5.into_push_pull_output(); - let slave_miso = io.pins.gpio2; - let master_miso = io.pins.gpio1.into_floating_input(); - let slave_mosi = io.pins.gpio7; - let mut master_mosi = io.pins.gpio8.into_push_pull_output(); - let slave_cs = io.pins.gpio10; - let mut master_cs = io.pins.gpio9.into_push_pull_output(); - master_cs.set_high().unwrap(); - master_sclk.set_low().unwrap(); - master_mosi.set_low().unwrap(); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(32000); - - let mut spi = Spi::new( - peripherals.SPI2, - slave_sclk, - slave_mosi, - slave_miso, - slave_cs, - SpiMode::Mode0, - ) - .with_dma(dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let mut delay = Delay::new(&clocks); - - // DMA buffer require a static life-time - let master_send = &mut [0u8; 32000]; - let master_receive = &mut [0u8; 32000]; - let mut slave_send = tx_buffer; - let mut slave_receive = rx_buffer; - let mut i = 0; - - for (i, v) in master_send.iter_mut().enumerate() { - *v = (i % 255) as u8; - } - for (i, v) in slave_send.iter_mut().enumerate() { - *v = (254 - (i % 255)) as u8; - } - - loop { - master_send[0] = i; - master_send[master_send.len() - 1] = i; - slave_send[0] = i; - slave_send[slave_send.len() - 1] = i; - slave_receive.fill(0xff); - i = i.wrapping_add(1); - - let transfer = spi.dma_transfer(slave_send, slave_receive).unwrap(); - // Bit-bang out the contents of master_send and read into master_receive - // as quickly as manageable. MSB first. Mode 0, so sampled on the rising - // edge and set on the falling edge. - master_cs.set_low().unwrap(); - for (j, v) in master_send.iter().enumerate() { - let mut b = *v; - let mut rb = 0u8; - for _ in 0..8 { - if b & 128 != 0 { - master_mosi.set_high().unwrap(); - } else { - master_mosi.set_low().unwrap(); - } - master_sclk.set_low().unwrap(); - b <<= 1; - rb <<= 1; - // NB: adding about 24 NOPs here makes the clock's duty cycle - // run at about 50% ... but we don't strictly need the delay, - // either. - master_sclk.set_high().unwrap(); - if master_miso.is_high().unwrap() { - rb |= 1; - } - } - master_receive[j] = rb; - } - master_cs.set_high().unwrap(); - master_sclk.set_low().unwrap(); - // the buffers and spi is moved into the transfer and we can get it back via - // `wait` - (slave_receive, slave_send, spi) = transfer.wait().unwrap(); - println!( - "slave got {:x?} .. {:x?}, master got {:x?} .. {:x?}", - &slave_receive[..10], - &slave_receive[slave_receive.len() - 10..], - &master_receive[..10], - &master_receive[master_receive.len() - 10..] - ); - - delay.delay_ms(250u32); - - slave_receive.fill(0xff); - let transfer = spi.dma_read(slave_receive).unwrap(); - master_cs.set_high().unwrap(); - - master_cs.set_low().unwrap(); - for v in master_send.iter() { - let mut b = *v; - for _ in 0..8 { - if b & 128 != 0 { - master_mosi.set_high().unwrap(); - } else { - master_mosi.set_low().unwrap(); - } - b <<= 1; - master_sclk.set_low().unwrap(); - master_sclk.set_high().unwrap(); - } - } - master_cs.set_high().unwrap(); - (slave_receive, spi) = transfer.wait().unwrap(); - println!( - "slave got {:x?} .. {:x?}", - &slave_receive[..10], - &slave_receive[slave_receive.len() - 10..], - ); - - delay.delay_ms(250u32); - let transfer = spi.dma_write(slave_send).unwrap(); - - master_receive.fill(0); - - master_cs.set_low().unwrap(); - for (j, _) in master_send.iter().enumerate() { - let mut rb = 0u8; - for _ in 0..8 { - master_sclk.set_low().unwrap(); - rb <<= 1; - master_sclk.set_high().unwrap(); - if master_miso.is_high().unwrap() { - rb |= 1; - } - } - master_receive[j] = rb; - } - master_cs.set_high().unwrap(); - (slave_send, spi) = transfer.wait().unwrap(); - - println!( - "master got {:x?} .. {:x?}", - &master_receive[..10], - &master_receive[master_receive.len() - 10..], - ); - println!(); - } -} diff --git a/esp32c3-hal/examples/systimer.rs b/esp32c3-hal/examples/systimer.rs deleted file mode 100644 index 7a9b42113..000000000 --- a/esp32c3-hal/examples/systimer.rs +++ /dev/null @@ -1,114 +0,0 @@ -//! This shows how to use the SYSTIMER peripheral including interrupts. -//! It's an additional timer besides the TIMG peripherals. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32c3_hal::{ - clock::ClockControl, - interrupt, - interrupt::Priority, - peripherals::{self, Peripherals}, - prelude::*, - systimer::{Alarm, Periodic, SystemTimer, Target}, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -static ALARM0: Mutex>>> = Mutex::new(RefCell::new(None)); -static ALARM1: Mutex>>> = Mutex::new(RefCell::new(None)); -static ALARM2: Mutex>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let syst = SystemTimer::new(peripherals.SYSTIMER); - - println!("SYSTIMER Current value = {}", SystemTimer::now()); - - let alarm0 = syst.alarm0.into_periodic(); - alarm0.set_period(1u32.secs()); - alarm0.clear_interrupt(); - alarm0.enable_interrupt(true); - - let alarm1 = syst.alarm1; - alarm1.set_target(SystemTimer::now() + (SystemTimer::TICKS_PER_SECOND * 2)); - alarm1.enable_interrupt(true); - - let alarm2 = syst.alarm2; - alarm2.set_target(SystemTimer::now() + (SystemTimer::TICKS_PER_SECOND * 3)); - alarm2.enable_interrupt(true); - - critical_section::with(|cs| { - ALARM0.borrow_ref_mut(cs).replace(alarm0); - ALARM1.borrow_ref_mut(cs).replace(alarm1); - ALARM2.borrow_ref_mut(cs).replace(alarm2); - }); - - interrupt::enable( - peripherals::Interrupt::SYSTIMER_TARGET0, - Priority::Priority1, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::SYSTIMER_TARGET1, - Priority::Priority2, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::SYSTIMER_TARGET2, - Priority::Priority2, - ) - .unwrap(); - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - loop { - delay.delay_ms(500u32); - } -} - -#[interrupt] -fn SYSTIMER_TARGET0() { - println!("Interrupt lvl1 (alarm0)"); - critical_section::with(|cs| { - ALARM0 - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .clear_interrupt() - }); -} - -#[interrupt] -fn SYSTIMER_TARGET1() { - println!("Interrupt lvl2 (alarm1)"); - critical_section::with(|cs| { - ALARM1 - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .clear_interrupt() - }); -} - -#[interrupt] -fn SYSTIMER_TARGET2() { - println!("Interrupt lvl2 (alarm2)"); - critical_section::with(|cs| { - ALARM2 - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .clear_interrupt() - }); -} diff --git a/esp32c3-hal/examples/timer_interrupt.rs b/esp32c3-hal/examples/timer_interrupt.rs deleted file mode 100644 index 74b98e8bc..000000000 --- a/esp32c3-hal/examples/timer_interrupt.rs +++ /dev/null @@ -1,82 +0,0 @@ -//! This shows how to use the TIMG peripheral interrupts. -//! There is TIMG0 and TIMG1 each of them containing a general purpose timer and -//! a watchdog timer. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32c3_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals, TIMG0, TIMG1}, - prelude::*, - timer::{Timer, Timer0, TimerGroup}, -}; -use esp_backtrace as _; - -static TIMER0: Mutex>>>> = Mutex::new(RefCell::new(None)); -static TIMER1: Mutex>>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks); - let mut timer1 = timer_group1.timer0; - - interrupt::enable( - peripherals::Interrupt::TG0_T0_LEVEL, - interrupt::Priority::Priority1, - ) - .unwrap(); - timer0.start(500u64.millis()); - timer0.listen(); - - interrupt::enable( - peripherals::Interrupt::TG1_T0_LEVEL, - interrupt::Priority::Priority1, - ) - .unwrap(); - timer1.start(1u64.secs()); - timer1.listen(); - - critical_section::with(|cs| { - TIMER0.borrow_ref_mut(cs).replace(timer0); - TIMER1.borrow_ref_mut(cs).replace(timer1); - }); - - loop {} -} - -#[interrupt] -fn TG0_T0_LEVEL() { - critical_section::with(|cs| { - esp_println::println!("Interrupt 1"); - - let mut timer0 = TIMER0.borrow_ref_mut(cs); - let timer0 = timer0.as_mut().unwrap(); - - timer0.clear_interrupt(); - timer0.start(500u64.millis()); - }); -} - -#[interrupt] -fn TG1_T0_LEVEL() { - critical_section::with(|cs| { - esp_println::println!("Interrupt 11"); - - let mut timer1 = TIMER1.borrow_ref_mut(cs); - let timer1 = timer1.as_mut().unwrap(); - - timer1.clear_interrupt(); - timer1.start(1u64.secs()); - }); -} diff --git a/esp32c3-hal/examples/twai.rs b/esp32c3-hal/examples/twai.rs deleted file mode 100644 index 6c15e5b46..000000000 --- a/esp32c3-hal/examples/twai.rs +++ /dev/null @@ -1,86 +0,0 @@ -#![no_std] -#![no_main] - -// Run this example with the eh1 feature enabled to use embedded-can instead of -// embedded-hal-0.2.7. embedded-can was split off from embedded-hal before it's -// upgrade to 1.0.0. cargo run --example twai --features eh1 --release -#[cfg(feature = "eh1")] -use embedded_can::{nb::Can, Frame, Id}; -// Run this example without the eh1 flag to use the embedded-hal 0.2.7 CAN traits. -// cargo run --example twai --release -#[cfg(not(feature = "eh1"))] -use embedded_hal::can::{Can, Frame, Id}; -use esp32c3_hal::{clock::ClockControl, gpio::IO, peripherals::Peripherals, prelude::*, twai}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Use GPIO pins 2 and 3 to connect to the respective pins on the CAN - // transceiver. - let can_tx_pin = io.pins.gpio2; - let can_rx_pin = io.pins.gpio3; - - // The speed of the CAN bus. - const CAN_BAUDRATE: twai::BaudRate = twai::BaudRate::B1000K; - - // Begin configuring the TWAI peripheral. The peripheral is in a reset like - // state that prevents transmission but allows configuration. - let mut can_config = twai::TwaiConfiguration::new( - peripherals.TWAI0, - can_tx_pin, - can_rx_pin, - &clocks, - CAN_BAUDRATE, - ); - - // Partially filter the incoming messages to reduce overhead of receiving - // undesired messages. Note that due to how the hardware filters messages, - // standard ids and extended ids may both match a filter. Frame ids should - // be explicitly checked in the application instead of fully relying on - // these partial acceptance filters to exactly match. A filter that matches - // standard ids of an even value. - const FILTER: twai::filter::SingleStandardFilter = - twai::filter::SingleStandardFilter::new(b"xxxxxxxxxx0", b"x", [b"xxxxxxxx", b"xxxxxxxx"]); - can_config.set_filter(FILTER); - - // Start the peripheral. This locks the configuration settings of the peripheral - // and puts it into operation mode, allowing packets to be sent and - // received. - let mut can = can_config.start(); - - loop { - // Wait for a frame to be received. - let frame = block!(can.receive()).unwrap(); - - println!("Received a frame:"); - - // Print different messages based on the frame id type. - match frame.id() { - Id::Standard(id) => { - println!("\tStandard Id: {:?}", id); - } - Id::Extended(id) => { - println!("\tExtended Id: {:?}", id); - } - } - - // Print out the frame data or the requested data length code for a remote - // transmission request frame. - if frame.is_data_frame() { - println!("\tData: {:?}", frame.data()); - } else { - println!("\tRemote Frame. Data Length Code: {}", frame.dlc()); - } - - // Transmit the frame back. - let _result = block!(can.transmit(&frame)).unwrap(); - } -} diff --git a/esp32c3-hal/examples/usb_serial_jtag.rs b/esp32c3-hal/examples/usb_serial_jtag.rs deleted file mode 100644 index 82684e85c..000000000 --- a/esp32c3-hal/examples/usb_serial_jtag.rs +++ /dev/null @@ -1,79 +0,0 @@ -//! This shows how to output text via USB Serial/JTAG. -//! You need to connect via the Serial/JTAG interface to see any output. -//! Most dev-kits use a USB-UART-bridge - in that case you won't see any output. -//! This will work with the ESP32-C3-DevKit-RUST-1 - -#![no_std] -#![no_main] - -use core::{cell::RefCell, fmt::Write}; - -use critical_section::Mutex; -use esp32c3_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, - timer::TimerGroup, - Cpu, - UsbSerialJtag, -}; -use esp_backtrace as _; -use nb::block; - -static USB_SERIAL: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let mut usb_serial = UsbSerialJtag::new(peripherals.USB_DEVICE); - - usb_serial.listen_rx_packet_recv_interrupt(); - - timer0.start(1u64.secs()); - - critical_section::with(|cs| USB_SERIAL.borrow_ref_mut(cs).replace(usb_serial)); - - interrupt::enable( - peripherals::Interrupt::USB_DEVICE, - interrupt::Priority::Priority1, - ) - .unwrap(); - - interrupt::set_kind( - Cpu::ProCpu, - interrupt::CpuInterrupt::Interrupt1, - interrupt::InterruptKind::Edge, - ); - - loop { - critical_section::with(|cs| { - writeln!( - USB_SERIAL.borrow_ref_mut(cs).as_mut().unwrap(), - "Hello world!" - ) - .ok(); - }); - - block!(timer0.wait()).unwrap(); - } -} - -#[interrupt] -fn USB_DEVICE() { - critical_section::with(|cs| { - let mut usb_serial = USB_SERIAL.borrow_ref_mut(cs); - let usb_serial = usb_serial.as_mut().unwrap(); - writeln!(usb_serial, "USB serial interrupt").unwrap(); - while let nb::Result::Ok(c) = usb_serial.read_byte() { - writeln!(usb_serial, "Read byte: {:02x}", c).unwrap(); - } - usb_serial.reset_rx_packet_recv_interrupt(); - }); -} diff --git a/esp32c3-hal/examples/watchdog.rs b/esp32c3-hal/examples/watchdog.rs deleted file mode 100644 index 67366a490..000000000 --- a/esp32c3-hal/examples/watchdog.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! This demos the watchdog timer. -//! Basically the same as `hello_world` but if you remove the call to -//! `wdt.feed()` the watchdog will reset the system. - -#![no_std] -#![no_main] - -use esp32c3_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, timer::TimerGroup}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - let mut wdt0 = timer_group0.wdt; - - wdt0.start(2u64.secs()); - timer0.start(1u64.secs()); - - loop { - wdt0.feed(); - println!("Hello world!"); - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32c3-hal/src/lib.rs b/esp32c3-hal/src/lib.rs deleted file mode 100644 index 76788e54c..000000000 --- a/esp32c3-hal/src/lib.rs +++ /dev/null @@ -1,9 +0,0 @@ -//! A bare-metal (`no_std`) Hardware Abstraction Layer for the ESP32-C3 from -//! Espressif. -//! -//! ## Feature Flags -#![doc = document_features::document_features!()] -#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/46717278")] -#![no_std] - -pub use esp_hal::*; diff --git a/esp32c6-hal/.cargo/config.toml b/esp32c6-hal/.cargo/config.toml deleted file mode 100644 index 68c020c7c..000000000 --- a/esp32c6-hal/.cargo/config.toml +++ /dev/null @@ -1,12 +0,0 @@ -[target.riscv32imac-unknown-none-elf] -runner = "espflash flash --monitor" -rustflags = [ - "-C", "link-arg=-Tlinkall.x", - "-C", "force-frame-pointers", -] - -[build] -target = "riscv32imac-unknown-none-elf" - -[unstable] -build-std = [ "core" ] diff --git a/esp32c6-hal/Cargo.toml b/esp32c6-hal/Cargo.toml deleted file mode 100644 index 038329516..000000000 --- a/esp32c6-hal/Cargo.toml +++ /dev/null @@ -1,186 +0,0 @@ -[package] -name = "esp32c6-hal" -version = "0.8.0" -edition = "2021" -rust-version = "1.67.0" -description = "HAL for ESP32-C6 microcontrollers" -repository = "https://github.com/esp-rs/esp-hal" -license = "MIT OR Apache-2.0" - -keywords = [ - "embedded", - "embedded-hal", - "esp", - "esp32c6", - "no-std", -] -categories = [ - "embedded", - "hardware-support", - "no-std", -] - -[package.metadata.docs.rs] -targets = ["riscv32imac-unknown-none-elf"] - -[dependencies] -document-features = "0.2.7" -esp-hal = { version = "0.15.0", features = ["esp32c6"], path = "../esp-hal" } -embassy-time-driver = { version = "0.1.0", optional = true } - -[dev-dependencies] -aes = "0.8.3" -critical-section = "1.1.2" -crypto-bigint = { version = "0.5.5", default-features = false} -elliptic-curve = { version = "0.13.8", default-features = false, features = ["sec1"] } -embassy-executor = { version = "0.5.0", features = ["nightly"] } -embassy-sync = "0.5.0" -embassy-time = "0.3.0" -embedded-graphics = "0.8.1" -embedded-hal-1 = { version = "1.0.0", package = "embedded-hal" } -embedded-hal-async = "1.0.0" -embedded-can = "0.4.1" -embedded-io-async = "0.6.1" -embedded-hal-bus = "0.1.0" -esp-backtrace = { version = "0.10.0", features = ["esp32c6", "panic-handler", "exception-handler", "print-uart"] } -esp-hal-smartled = { version = "0.8.0", features = ["esp32c6"], path = "../esp-hal-smartled" } -esp-println = { version = "0.8.0", features = ["esp32c6"] } -heapless = "0.8.0" -hex-literal = "0.4.1" -hmac = { version = "0.12.1", default-features = false } -lis3dh-async = "0.9.1" -p192 = { version = "0.13.0", default-features = false, features = ["arithmetic"] } -p256 = { version = "0.13.2", default-features = false, features = ["arithmetic"] } -sha2 = { version = "0.10.8", default-features = false} -smart-leds = "0.4.0" -ssd1306 = "0.8.4" -static_cell = { version = "2.0.0", features = ["nightly"] } - -[features] -default = ["embassy-integrated-timers", "rt", "vectored", "zero-rtc-bss"] - -## Enable debug features in the HAL (used for development). -debug = ["esp-hal/debug"] -## Enable direct interrupt vectoring. -direct-vectoring = ["esp-hal/direct-vectoring"] -## TODO: ??? -flip-link = ["esp-hal/flip-link"] -## Enable interrupt preemption. -interrupt-preemption = ["esp-hal/interrupt-preemption"] -## Enable logging output using the `log` crate. -log = ["esp-hal/log", "esp-println/log"] -## Enable runtime support. -rt = ["esp-hal/rt-riscv"] -## Enable interrupt vectoring. -vectored = ["esp-hal/vectored"] - -#! ### Trait Implementation Feature Flags -## Enable support for asynchronous operation, with interfaces provided by -## `embedded-hal-async` and `embedded-io-async`. -async = ["esp-hal/async"] -## Implement `defmt::Format` on certain types. -defmt = ["esp-hal/defmt", "esp-println/defmt-espflash"] -## Implement the traits defined in the `1.0.0` releases of `embedded-hal` and -## `embedded-hal-nb` for the relevant peripherals. -eh1 = ["esp-hal/eh1"] -## Implement the traits defined in `embedded-io` for certain peripherals. -embedded-io = ["esp-hal/embedded-io"] -## Implement the `ufmt_write::uWrite` trait for certain peripherals. -ufmt = ["esp-hal/ufmt"] - -#! ### Memory Initialization Feature Flags -## Zero the `.bss` section of low-power memory. -zero-rtc-bss = ["esp-hal/rv-zero-rtc-bss"] -## Initialize the `.data` section of memory. -init-data = ["esp-hal/rv-init-data"] -## Initialize the `.data` section of low-power memory. -init-rtc-data = ["esp-hal/rv-init-rtc-data"] - -#! ### Embassy Feature Flags -## Enable support for `embassy`, a modern asynchronous embedded framework. -embassy = ["esp-hal/embassy"] -## Use the interrupt-mode embassy executor. -embassy-executor-interrupt = ["esp-hal/embassy-executor-interrupt"] -## Use the thread-mode embassy executor. -embassy-executor-thread = ["esp-hal/embassy-executor-thread"] -## Uses hardware timers as alarms for the executors. Using this feature -## limits the number of executors to the number of hardware alarms provided -## by the time driver. -embassy-integrated-timers = ["esp-hal/embassy-integrated-timers"] -## Enable the embassy time driver using the `SYSTIMER` peripheral. The -## `SYSTIMER` peripheral has three alarams available for use. -embassy-time-systick = ["esp-hal/embassy-time-systick", "embassy-time-driver/tick-hz-16_000_000"] -## Enable the embassy time driver using the `TIMG0` peripheral. The `TIMG0` -## peripheral has two alarms available for use. -embassy-time-timg0 = ["esp-hal/embassy-time-timg0", "embassy-time-driver/tick-hz-1_000_000"] - -[profile.release] -debug = true - -[[example]] -name = "spi_eh1_loopback" -required-features = ["eh1"] - -[[example]] -name = "spi_eh1_device_loopback" -required-features = ["eh1"] - -[[example]] -name = "embassy_hello_world" -required-features = ["embassy", "embassy-executor-thread"] - -[[example]] -name = "embassy_multiprio" -required-features = ["embassy", "embassy-executor-thread", "embassy-executor-interrupt"] - -[[example]] -name = "embassy_wait" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_spi" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "interrupt_preemption" -required-features = ["interrupt-preemption"] - -[[example]] -name = "embassy_serial" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_i2c" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "direct-vectoring" -required-features = ["direct-vectoring"] - -[[example]] -name = "embassy_rmt_tx" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_rmt_rx" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_i2s_sound" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_i2s_read" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_parl_io_tx" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_parl_io_rx" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_usb_serial_jtag" -required-features = ["embassy", "async", "embassy-executor-thread"] diff --git a/esp32c6-hal/README.md b/esp32c6-hal/README.md deleted file mode 100644 index 5bfe90b83..000000000 --- a/esp32c6-hal/README.md +++ /dev/null @@ -1,51 +0,0 @@ -# esp32c6-hal - -[![Crates.io](https://img.shields.io/crates/v/esp32c6-hal?labelColor=1C2C2E&color=C96329&logo=Rust&style=flat-square)](https://crates.io/crates/esp32c6-hal) -[![docs.rs](https://img.shields.io/docsrs/esp32c6-hal?labelColor=1C2C2E&color=C96329&logo=rust&style=flat-square)](https://docs.rs/esp32c6-hal) -![Crates.io](https://img.shields.io/crates/l/esp32c6-hal?labelColor=1C2C2E&style=flat-square) -[![Matrix](https://img.shields.io/matrix/esp-rs:matrix.org?label=join%20matrix&labelColor=1C2C2E&color=BEC5C9&logo=matrix&style=flat-square)](https://matrix.to/#/#esp-rs:matrix.org) - -`no_std` HAL for the ESP32-C6 from Espressif. - -Implements a number of the traits defined in [embedded-hal](https://github.com/rust-embedded/embedded-hal). - -This device uses the RISC-V ISA, which is officially supported by the Rust compiler via the `riscv32imac-unknown-none-elf` target. - -Please refer to the documentation for more information. - -## [Documentation] - -[documentation]: https://docs.rs/esp32c6-hal/ - -## Resources - -- [Datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf) -- [Technical Reference Manual](https://www.espressif.com/sites/default/files/documentation/esp32-c6_technical_reference_manual_en.pdf) -- [The Rust Programming Language](https://doc.rust-lang.org/book/) -- [The Embedded Rust Book](https://docs.rust-embedded.org/book/index.html) -- [The Rust on ESP Book](https://esp-rs.github.io/book/) - -## Getting Started - -### Installing the Rust Compiler Target - -The compilation target for this device is officially supported by the mainline Rust compiler and can be installed using [rustup](https://rustup.rs/): - -```shell -rustup target add riscv32imac-unknown-none-elf -``` - -## License - -Licensed under either of: - -- Apache License, Version 2.0 ([LICENSE-APACHE](../LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) -- MIT license ([LICENSE-MIT](../LICENSE-MIT) or http://opensource.org/licenses/MIT) - -at your option. - -### Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in -the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without -any additional terms or conditions. diff --git a/esp32c6-hal/build.rs b/esp32c6-hal/build.rs deleted file mode 100644 index 023b7905b..000000000 --- a/esp32c6-hal/build.rs +++ /dev/null @@ -1,16 +0,0 @@ -use std::{env, error::Error, path::PathBuf}; - -fn main() -> Result<(), Box> { - // Put the linker script somewhere the linker can find it - let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - println!("cargo:rustc-link-search={}", out.display()); - - // Only re-run the build script when memory.x is changed, - // instead of when any part of the source code changes. - println!("cargo:rerun-if-changed=ld/memory.x"); - - #[cfg(feature = "defmt")] - println!("cargo:rustc-link-arg=-Tdefmt.x"); - - Ok(()) -} diff --git a/esp32c6-hal/examples/adc.rs b/esp32c6-hal/examples/adc.rs deleted file mode 100644 index 7c48620fc..000000000 --- a/esp32c6-hal/examples/adc.rs +++ /dev/null @@ -1,39 +0,0 @@ -//! Connect a potentiometer to PIN2 and see the read values change when -//! rotating the shaft. Alternatively you could also connect the PIN to GND or -//! 3V3 to see the maximum and minimum raw values read. - -#![no_std] -#![no_main] - -use esp32c6_hal::{ - adc::{AdcConfig, Attenuation, ADC}, - clock::ClockControl, - gpio::IO, - peripherals::{Peripherals, ADC1}, - prelude::*, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create ADC instances - let mut adc1_config = AdcConfig::new(); - let mut pin = adc1_config.enable_pin(io.pins.gpio2.into_analog(), Attenuation::Attenuation11dB); - let mut adc1 = ADC::::new(peripherals.ADC1, adc1_config); - - let mut delay = Delay::new(&clocks); - - loop { - let pin_value: u16 = nb::block!(adc1.read(&mut pin)).unwrap(); - println!("PIN2 ADC reading = {}", pin_value); - delay.delay_ms(1500u32); - } -} diff --git a/esp32c6-hal/examples/adc_cal.rs b/esp32c6-hal/examples/adc_cal.rs deleted file mode 100644 index 410f40755..000000000 --- a/esp32c6-hal/examples/adc_cal.rs +++ /dev/null @@ -1,52 +0,0 @@ -//! Connect a potentiometer to PIN2 and see the read values change when -//! rotating the shaft. Alternatively you could also connect the PIN to GND or -//! 3V3 to see the maximum and minimum raw values read. - -#![no_std] -#![no_main] - -use esp32c6_hal::{ - adc, - adc::{AdcConfig, Attenuation, ADC}, - clock::ClockControl, - gpio::IO, - peripherals::{Peripherals, ADC1}, - prelude::*, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create ADC instances - // You can try any of the following calibration methods by uncommenting them. - // Note that only AdcCalLine and AdcCalCurve return readings in mV; the other - // two return raw readings in some unspecified scale. - // - // type AdcCal = (); - // type AdcCal = adc::AdcCalBasic; - // type AdcCal = adc::AdcCalLine; - type AdcCal = adc::AdcCalCurve; - - let mut adc1_config = AdcConfig::new(); - let mut pin = adc1_config.enable_pin_with_cal::<_, AdcCal>( - io.pins.gpio2.into_analog(), - Attenuation::Attenuation11dB, - ); - let mut adc1 = ADC::::new(peripherals.ADC1, adc1_config); - - let mut delay = Delay::new(&clocks); - - loop { - let pin_mv = nb::block!(adc1.read(&mut pin)).unwrap(); - println!("PIN2 ADC reading = {pin_mv} mV"); - delay.delay_ms(1500u32); - } -} diff --git a/esp32c6-hal/examples/advanced_serial.rs b/esp32c6-hal/examples/advanced_serial.rs deleted file mode 100644 index 4ca2cc459..000000000 --- a/esp32c6-hal/examples/advanced_serial.rs +++ /dev/null @@ -1,67 +0,0 @@ -//! This shows how to configure UART -//! You can short the TX and RX pin and see it reads what was written. -//! Additionally you can connect a logic analzyer to TX and see how the changes -//! of the configuration change the output signal. -//! -//! The following wiring is assumed: -//! - TX => GPIO1 -//! - RX => GPIO2 - -#![no_std] -#![no_main] - -use esp32c6_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, - uart::{ - config::{Config, DataBits, Parity, StopBits}, - TxRxPins, - }, - Uart, - IO, -}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let config = Config { - baudrate: 115200, - data_bits: DataBits::DataBits8, - parity: Parity::ParityNone, - stop_bits: StopBits::STOP1, - }; - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let pins = TxRxPins::new_tx_rx( - io.pins.gpio1.into_push_pull_output(), - io.pins.gpio2.into_floating_input(), - ); - - let mut serial1 = Uart::new_with_config(peripherals.UART1, config, Some(pins), &clocks); - - timer0.start(250u64.millis()); - - println!("Start"); - loop { - serial1.write(0x42).ok(); - let read = block!(serial1.read()); - - match read { - Ok(read) => println!("Read 0x{:02x}", read), - Err(err) => println!("Error {:?}", err), - } - - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32c6-hal/examples/aes.rs b/esp32c6-hal/examples/aes.rs deleted file mode 100644 index dae093457..000000000 --- a/esp32c6-hal/examples/aes.rs +++ /dev/null @@ -1,85 +0,0 @@ -//! Encrypt/Decrypt a message using AES. - -#![no_std] -#![no_main] -use aes::{ - cipher::{generic_array::GenericArray, BlockDecrypt, BlockEncrypt, KeyInit}, - Aes128 as Aes128SW, -}; -use esp32c6_hal::{ - aes::{Aes, Mode}, - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - systimer::SystemTimer, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut aes = Aes::new(peripherals.AES); - - let keytext = "SUp4SeCp@sSw0rd".as_bytes(); - let plaintext = "message".as_bytes(); - - // create an array with aes128 key size - let mut keybuf = [0_u8; 16]; - keybuf[..keytext.len()].copy_from_slice(keytext); - - // create an array with aes block size - let mut block_buf = [0_u8; 16]; - block_buf[..plaintext.len()].copy_from_slice(plaintext); - - let mut block = block_buf.clone(); - let pre_hw_encrypt = SystemTimer::now(); - aes.process(&mut block, Mode::Encryption128, &keybuf); - let post_hw_encrypt = SystemTimer::now(); - println!( - "it took {} cycles for hw encrypt", - post_hw_encrypt - pre_hw_encrypt - ); - let hw_encrypted = block.clone(); - let pre_hw_decrypt = SystemTimer::now(); - aes.process(&mut block, Mode::Decryption128, &keybuf); - let post_hw_decrypt = SystemTimer::now(); - println!( - "it took {} cycles for hw decrypt", - post_hw_decrypt - pre_hw_decrypt - ); - let hw_decrypted = block; - - let key = GenericArray::from(keybuf); - let mut block = GenericArray::from(block_buf); - let cipher = Aes128SW::new(&key); - let pre_sw_encrypt = SystemTimer::now(); - cipher.encrypt_block(&mut block); - let post_sw_encrypt = SystemTimer::now(); - println!( - "it took {} cycles for sw encrypt", - post_sw_encrypt - pre_sw_encrypt - ); - let sw_encrypted = block.clone(); - let pre_sw_decrypt = SystemTimer::now(); - cipher.decrypt_block(&mut block); - let post_sw_decrypt = SystemTimer::now(); - println!( - "it took {} cycles for sw decrypt", - post_sw_decrypt - pre_sw_decrypt - ); - let sw_decrypted = block; - - assert!(eq(&sw_encrypted.into(), &hw_encrypted)); - assert!(eq(&sw_decrypted.into(), &hw_decrypted)); - - println!("done"); - - loop {} -} -fn eq(slice1: &[u8; 16], slice2: &[u8; 16]) -> bool { - slice1.iter().zip(slice2.iter()).all(|(a, b)| a == b) -} diff --git a/esp32c6-hal/examples/aes_dma.rs b/esp32c6-hal/examples/aes_dma.rs deleted file mode 100644 index 23346d21d..000000000 --- a/esp32c6-hal/examples/aes_dma.rs +++ /dev/null @@ -1,153 +0,0 @@ -//! Encrypt/Decrypt a message using AES - -#![no_std] -#![no_main] -use aes::{ - cipher::{generic_array::GenericArray, BlockDecrypt, BlockEncrypt, KeyInit}, - Aes128 as Aes128SW, -}; -use esp32c6_hal::{ - aes::{ - dma::{CipherMode, WithDmaAes}, - Aes, - Mode, - }, - clock::ClockControl, - dma::{Dma, DmaDescriptor, DmaPriority}, - peripherals::Peripherals, - prelude::*, - systimer::SystemTimer, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let mut descriptors = [DmaDescriptor::EMPTY; 1]; - let mut rx_descriptors = [DmaDescriptor::EMPTY; 1]; - - let aes = Aes::new(peripherals.AES).with_dma(dma_channel.configure( - false, - &mut descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let keytext = buffer1(); - let plaintext = buffer2(); - plaintext.copy_from_slice(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); - keytext.copy_from_slice(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); - - // create an array with aes128 key size - let mut keybuf = [0_u8; 16]; - keybuf[..keytext.len()].copy_from_slice(keytext); - - // create an array with aes block size - let mut block_buf = [0_u8; 16]; - block_buf[..plaintext.len()].copy_from_slice(plaintext); - - let hw_encrypted = buffer3(); - let pre_hw_encrypt = SystemTimer::now(); - let transfer = aes - .process( - plaintext, - hw_encrypted, - Mode::Encryption128, - CipherMode::Ecb, - keybuf, - ) - .unwrap(); - let (hw_encrypted, plaintext, aes) = transfer.wait().unwrap(); - let post_hw_encrypt = SystemTimer::now(); - println!( - "it took {} cycles for hw encrypt", - post_hw_encrypt - pre_hw_encrypt - ); - - let keytext = buffer4(); - plaintext.copy_from_slice(hw_encrypted); - keytext.copy_from_slice(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); - - let mut keybuf = [0_u8; 16]; - keybuf[..keytext.len()].copy_from_slice(keytext); - - let hw_decrypted = buffer5(); - let pre_hw_decrypt = SystemTimer::now(); - let transfer = aes - .process( - plaintext, - hw_decrypted, - Mode::Decryption128, - CipherMode::Ecb, - keybuf, - ) - .unwrap(); - let (hw_decrypted, _, _) = transfer.wait().unwrap(); - let post_hw_decrypt = SystemTimer::now(); - println!( - "it took {} cycles for hw decrypt", - post_hw_decrypt - pre_hw_decrypt - ); - - let key = GenericArray::from(keybuf); - let mut block = GenericArray::from(block_buf); - let cipher = Aes128SW::new(&key); - let pre_sw_encrypt = SystemTimer::now(); - cipher.encrypt_block(&mut block); - let post_sw_encrypt = SystemTimer::now(); - println!( - "it took {} cycles for sw encrypt", - post_sw_encrypt - pre_sw_encrypt - ); - let sw_encrypted = block.clone(); - let pre_sw_decrypt = SystemTimer::now(); - cipher.decrypt_block(&mut block); - let post_sw_decrypt = SystemTimer::now(); - println!( - "it took {} cycles for sw decrypt", - post_sw_decrypt - pre_sw_decrypt - ); - let sw_decrypted = block.clone(); - - assert!(eq(&sw_encrypted.into(), &hw_encrypted)); - assert!(eq(&sw_decrypted.into(), &hw_decrypted)); - - println!("done"); - loop {} -} - -fn buffer1() -> &'static mut [u8; 16] { - static mut BUFFER: [u8; 16] = [0u8; 16]; - unsafe { &mut BUFFER } -} - -fn buffer2() -> &'static mut [u8; 16] { - static mut BUFFER: [u8; 16] = [0u8; 16]; - unsafe { &mut BUFFER } -} - -fn buffer3() -> &'static mut [u8; 16] { - static mut BUFFER: [u8; 16] = [0u8; 16]; - unsafe { &mut BUFFER } -} - -fn buffer4() -> &'static mut [u8; 16] { - static mut BUFFER: [u8; 16] = [0u8; 16]; - unsafe { &mut BUFFER } -} - -fn buffer5() -> &'static mut [u8; 16] { - static mut BUFFER: [u8; 16] = [0u8; 16]; - unsafe { &mut BUFFER } -} - -fn eq(slice1: &[u8; 16], slice2: &[u8; 16]) -> bool { - slice1.iter().zip(slice2.iter()).all(|(a, b)| a == b) -} diff --git a/esp32c6-hal/examples/blinky_erased_pins.rs b/esp32c6-hal/examples/blinky_erased_pins.rs deleted file mode 100644 index 24eb8efab..000000000 --- a/esp32c6-hal/examples/blinky_erased_pins.rs +++ /dev/null @@ -1,53 +0,0 @@ -//! Blinks an LED -//! -//! This assumes that LEDs are connected to GPIO3, 4 and 5. - -#![no_std] -#![no_main] - -use esp32c6_hal::{ - clock::ClockControl, - gpio::{AnyPin, Input, Output, PullDown, PushPull, IO}, - peripherals::Peripherals, - prelude::*, - Delay, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Set LED GPIOs as an output. - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let led1 = io.pins.gpio3.into_push_pull_output(); - let led2 = io.pins.gpio4.into_push_pull_output(); - let led3 = io.pins.gpio5.into_push_pull_output(); - - // Set GPIO9 as an input. - let button = io.pins.gpio9.into_pull_down_input().into(); - - // You can use `into` or `degrade` - let mut pins = [led1.into(), led2.into(), led3.degrade().into()]; - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - loop { - toggle_pins(&mut pins, &button); - delay.delay_ms(500u32); - } -} - -fn toggle_pins(leds: &mut [AnyPin>], button: &AnyPin>) { - for pin in leds.iter_mut() { - pin.toggle().unwrap(); - } - - if button.is_low().unwrap() { - esp_println::println!("Button"); - } -} diff --git a/esp32c6-hal/examples/clock_monitor.rs b/esp32c6-hal/examples/clock_monitor.rs deleted file mode 100644 index b61cc6757..000000000 --- a/esp32c6-hal/examples/clock_monitor.rs +++ /dev/null @@ -1,65 +0,0 @@ -//! This demos a simple monitor for the XTAL frequency, by relying on a special -//! feature of the TIMG0 (Timer Group 0). This feature counts the number of XTAL -//! clock cycles within a given number of RTC_SLOW_CLK cycles. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32c6_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, - Rtc, -}; -use esp_backtrace as _; - -static RTC: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rtc = Rtc::new(peripherals.LPWR); - rtc.rwdt.start(2000u64.millis()); - rtc.rwdt.listen(); - - esp_println::println!( - "{: <10} XTAL frequency: {} MHz", - "[Expected]", - clocks.xtal_clock.to_MHz() - ); - - interrupt::enable( - peripherals::Interrupt::LP_WDT, - interrupt::Priority::Priority1, - ) - .unwrap(); - - critical_section::with(|cs| { - RTC.borrow_ref_mut(cs).replace(rtc); - }); - - loop {} -} - -#[interrupt] -fn LP_WDT() { - critical_section::with(|cs| { - let mut rtc = RTC.borrow(cs).borrow_mut(); - let rtc = rtc.as_mut().unwrap(); - - esp_println::println!( - "{: <10} XTAL frequency: {} MHz", - "[Monitor]", - rtc.estimate_xtal_frequency() - ); - - rtc.rwdt.clear_interrupt(); - }); -} diff --git a/esp32c6-hal/examples/crc.rs b/esp32c6-hal/examples/crc.rs deleted file mode 100644 index e226148f0..000000000 --- a/esp32c6-hal/examples/crc.rs +++ /dev/null @@ -1,96 +0,0 @@ -//! This shows example usage of the CRC functions in ROM - -#![no_std] -#![no_main] - -use core::fmt::Write; - -use esp32c6_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - rom::{crc, md5}, - timer::TimerGroup, - Uart, -}; -use esp_backtrace as _; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - timer0.start(1u64.secs()); - - let data = "123456789"; - let sentence = "The quick brown fox jumps over a lazy dog"; - - writeln!( - uart0, - "Performing CRC calculations on test string \"{data}\"" - ) - .unwrap(); - - loop { - let crc_hdlc = crc::crc32_le(!0xffffffff, data.as_ref()); - let crc_bzip2 = crc::crc32_be(!0xffffffff, data.as_ref()); - let crc_mpeg2 = !crc::crc32_be(!0xffffffff, data.as_ref()); - let crc_cksum = crc::crc32_be(!0, data.as_ref()); - let crc_kermit = !crc::crc16_le(!0, data.as_ref()); - let crc_genibus = crc::crc16_be(!0xffff, data.as_ref()); - let crc_rohc = !crc::crc8_le(!0xff, data.as_ref()); - let crc_smbus = !crc::crc8_be(!0, data.as_ref()); - - assert_eq!(crc_hdlc, 0xcbf43926); - assert_eq!(crc_bzip2, 0xfc891918); - assert_eq!(crc_mpeg2, 0x0376e6e7); - assert_eq!(crc_cksum, 0x765e7680); - assert_eq!(crc_kermit, 0x2189); - assert_eq!(crc_genibus, 0xd64e); - assert_eq!(crc_rohc, 0xd0); - assert_eq!(crc_smbus, 0xf4); - - // Hash the sentence one word at a time to *really* test the context - // Use Peekable while iter_intersperse is unstable - let mut md5_ctx = md5::Context::new(); - let mut it = sentence.split_whitespace().peekable(); - while let Some(word) = it.next() { - md5_ctx.consume(word); - if it.peek().is_some() { - md5_ctx.consume(" "); - } - } - let md5_digest = md5_ctx.compute(); - - assert_eq!( - md5_digest, - md5::Digest([ - 0x30, 0xde, 0xd8, 0x07, 0xd6, 0x5e, 0xe0, 0x37, 0x0f, 0xc6, 0xd7, 0x3d, 0x6a, 0xb5, - 0x5a, 0x95 - ]) - ); - - writeln!( - uart0, - "{:08x} {:08x} {:08x} {:08x} {:04x} {:04x} {:02x} {:02x} {}", - crc_hdlc, - crc_bzip2, - crc_mpeg2, - crc_cksum, - crc_kermit, - crc_genibus, - crc_rohc, - crc_smbus, - md5_digest - ) - .unwrap(); - - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32c6-hal/examples/debug_assist.rs b/esp32c6-hal/examples/debug_assist.rs deleted file mode 100644 index e32e55bfc..000000000 --- a/esp32c6-hal/examples/debug_assist.rs +++ /dev/null @@ -1,96 +0,0 @@ -//! This shows debug-assist -//! -//! Uncomment the functionality you want to test - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32c6_hal::{ - assist_debug::DebugAssist, - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, -}; -use esp_backtrace as _; -use esp_println::println; - -static DA: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut da = DebugAssist::new(peripherals.ASSIST_DEBUG); - - extern "C" { - // top of stack - static mut _stack_start: u32; - // bottom of stack - static mut _stack_end: u32; - } - - let stack_top = unsafe { &mut _stack_start } as *mut _ as u32; - let stack_bottom = unsafe { &mut _stack_end } as *mut _ as u32; - - // uncomment the functionality you want to test - - da.enable_sp_monitor(stack_bottom + 4096, stack_top); - // da.enable_region0_monitor(stack_bottom, stack_bottom + 4096, true, true); - // da.enable_region1_monitor(stack_bottom, stack_bottom + 4096, true, true); - - critical_section::with(|cs| DA.borrow_ref_mut(cs).replace(da)); - - interrupt::enable( - peripherals::Interrupt::ASSIST_DEBUG, - interrupt::Priority::Priority3, - ) - .unwrap(); - - eat_up_stack(0); - - loop {} -} - -#[allow(unconditional_recursion)] -fn eat_up_stack(v: u32) { - println!("Iteration {v}"); - eat_up_stack(v + 1); -} - -#[interrupt] -fn ASSIST_DEBUG() { - critical_section::with(|cs| { - println!("\n\nDEBUG_ASSIST interrupt"); - let mut da = DA.borrow_ref_mut(cs); - let da = da.as_mut().unwrap(); - - if da.is_sp_monitor_interrupt_set() { - println!("SP MONITOR TRIGGERED"); - da.clear_sp_monitor_interrupt(); - let pc = da.get_sp_monitor_pc(); - println!("PC = 0x{:x}", pc); - } - - if da.is_region0_monitor_interrupt_set() { - println!("REGION0 MONITOR TRIGGERED"); - da.clear_region0_monitor_interrupt(); - let pc = da.get_region_monitor_pc(); - println!("PC = 0x{:x}", pc); - } - - if da.is_region1_monitor_interrupt_set() { - println!("REGION1 MONITOR TRIGGERED"); - da.clear_region1_monitor_interrupt(); - let pc = da.get_region_monitor_pc(); - println!("PC = 0x{:x}", pc); - } - - loop {} - }); -} diff --git a/esp32c6-hal/examples/direct-vectoring.rs b/esp32c6-hal/examples/direct-vectoring.rs deleted file mode 100644 index d2b26188e..000000000 --- a/esp32c6-hal/examples/direct-vectoring.rs +++ /dev/null @@ -1,84 +0,0 @@ -#![no_main] -#![no_std] -#![feature(naked_functions)] -use core::{arch::asm, cell::RefCell}; - -use critical_section::Mutex; -use esp32c6_hal::{ - clock::ClockControl, - interrupt::{ - CpuInterrupt, - {self}, - }, - peripherals::{self, Peripherals}, - prelude::*, - system::{SoftwareInterrupt, SoftwareInterruptControl}, -}; -use esp_backtrace as _; - -static SWINT: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clockctrl = system.clock_control; - let sw_int = system.software_interrupt_control; - let _clocks = ClockControl::boot_defaults(clockctrl).freeze(); - - critical_section::with(|cs| SWINT.borrow_ref_mut(cs).replace(sw_int)); - unsafe { - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR0, - interrupt::Priority::Priority3, - CpuInterrupt::Interrupt1, - ) - .unwrap(); - asm!( - " - csrrwi x0, 0x7e0, 1 #what to count, for cycles write 1 for instructions write 2 - csrrwi x0, 0x7e1, 0 #disable counter - csrrwi x0, 0x7e2, 0 #reset counter - " - ); - } - esp_println::println!("MPC:{}", unsafe { fetch_performance_timer() }); - // interrupt is raised from assembly for max timer granularity. - unsafe { - asm!( - " - li t0, 0x600C5090 #FROM_CPU_INTR0 address - li t1, 1 #Flip flag - csrrwi x0, 0x7e1, 1 #enable timer - sw t1, 0(t0) #trigger FROM_CPU_INTR0 - " - ) - } - esp_println::println!("Returned"); - loop {} -} - -#[no_mangle] -fn cpu_int_1_handler() { - unsafe { asm!("csrrwi x0, 0x7e1, 0 #disable timer") } - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt0); - }); - esp_println::println!("Performance counter:{}", unsafe { - fetch_performance_timer() - }); -} -#[naked] -unsafe extern "C" fn fetch_performance_timer() -> i32 { - asm!( - " - csrr a0, 0x7e2 - jr ra - ", - options(noreturn) - ); -} diff --git a/esp32c6-hal/examples/ecc.rs b/esp32c6-hal/examples/ecc.rs deleted file mode 100644 index dc3a7b914..000000000 --- a/esp32c6-hal/examples/ecc.rs +++ /dev/null @@ -1,724 +0,0 @@ -//! Demonstrates the use of the ECC peripheral and compares the speed of -//! hardware-accelerated and pure software ECC. - -#![no_std] -#![no_main] - -use core::ops::Mul; - -use crypto_bigint::{ - modular::runtime_mod::{DynResidue, DynResidueParams}, - Encoding, - U192, - U256, -}; -use elliptic_curve::sec1::ToEncodedPoint; -use esp32c6_hal::{ - ecc::{Ecc, EllipticCurve, Error}, - peripherals::Peripherals, - prelude::*, - systimer::SystemTimer, - Rng, -}; -use esp_backtrace as _; -use esp_println::{print, println}; -use hex_literal::hex; - -struct TestParams<'a> { - prime_fields: &'a [&'a [u8]], - nb_loop_mul: usize, -} - -const TEST_PARAMS_VECTOR: TestParams = TestParams { - prime_fields: &[ - &hex!("fffffffffffffffffffffffffffffffeffffffffffffffff"), - &hex!("ffffffff00000001000000000000000000000000ffffffffffffffffffffffff"), - ], - nb_loop_mul: 10, -}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let _system = peripherals.SYSTEM.split(); - - let mut rng = Rng::new(peripherals.RNG); - - println!("ECC example"); - - let mut hw_ecc = Ecc::new(peripherals.ECC); - - println!("Beginning stress tests..."); - test_affine_point_multiplication(&mut hw_ecc, &mut rng); - test_affine_point_verification(&mut hw_ecc, &mut rng); - test_afine_point_verification_multiplication(&mut hw_ecc, &mut rng); - test_jacobian_point_multiplication(&mut hw_ecc, &mut rng); - test_jacobian_point_verification(&mut hw_ecc, &mut rng); - test_afine_point_verification_jacobian_multiplication(&mut hw_ecc, &mut rng); - println!("Finished stress tests!"); - - loop {} -} - -fn test_affine_point_multiplication(ecc: &mut Ecc, rng: &mut Rng) { - for &prime_field in TEST_PARAMS_VECTOR.prime_fields { - print!("Beginning affine point multiplication tests over "); - match prime_field.len() { - 24 => print!("secp192r1..."), - _ => print!("secp256r1..."), - }; - let t1 = &mut [0_u8; 96]; - let (k, x) = t1.split_at_mut(prime_field.len()); - let (x, y) = x.split_at_mut(prime_field.len()); - let (y, _) = y.split_at_mut(prime_field.len()); - let mut delta_time = 0; - for _ in 0..TEST_PARAMS_VECTOR.nb_loop_mul { - loop { - rng.read(k).unwrap(); - let is_zero = k.iter().all(|&elt| elt == 0); - let is_modulus = k.iter().zip(prime_field).all(|(&a, &b)| a == b); - if is_zero == false && is_modulus == false { - break; - } - } - let curve = match prime_field.len() { - 24 => { - x.copy_from_slice( - p192::AffinePoint::GENERATOR - .to_encoded_point(false) - .x() - .unwrap(), - ); - y.copy_from_slice( - p192::AffinePoint::GENERATOR - .to_encoded_point(false) - .y() - .unwrap(), - ); - &EllipticCurve::P192 - } - 32 => { - x.copy_from_slice( - p256::AffinePoint::GENERATOR - .to_encoded_point(false) - .x() - .unwrap(), - ); - y.copy_from_slice( - p256::AffinePoint::GENERATOR - .to_encoded_point(false) - .y() - .unwrap(), - ); - &EllipticCurve::P256 - } - _ => unimplemented!(), - }; - - let begin_time = SystemTimer::now(); - ecc.affine_point_multiplication(curve, k, x, y) - .expect("Inputs data doesn't match the key length selected."); - let end_time = SystemTimer::now(); - delta_time += end_time - begin_time; - - let t2 = &mut [0_u8; 64]; - - let (sw_x, sw_y) = t2.split_at_mut(prime_field.len()); - let (sw_y, _) = sw_y.split_at_mut(prime_field.len()); - - match prime_field.len() { - 24 => { - let sw_k = - p192::Scalar::from(elliptic_curve::ScalarPrimitive::from_slice(k).unwrap()); - let q = p192::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - sw_x.copy_from_slice(q.x().unwrap().as_slice()); - sw_y.copy_from_slice(q.y().unwrap().as_slice()); - } - 32 => { - let sw_k = - p256::Scalar::from(elliptic_curve::ScalarPrimitive::from_slice(k).unwrap()); - let q = p256::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - sw_x.copy_from_slice(q.x().unwrap().as_slice()); - sw_y.copy_from_slice(q.y().unwrap().as_slice()); - } - _ => unimplemented!(), - }; - - for (a, b) in x.iter().zip(sw_x) { - assert_eq!( - a, b, - "ECC failed during affine point multiplication with d_a = {:02X?} ({:02X?} != {:02X?})", - k, a, b, - ); - } - - for (a, b) in y.iter().zip(sw_y) { - assert_eq!( - a, b, - "ECC failed during affine point multiplication with d_a = {:02X?} ({:02X?} != {:02X?})", - k, a, b, - ); - } - } - println!( - "ok (it took {} cycles in average)", - delta_time / (TEST_PARAMS_VECTOR.nb_loop_mul as u64) - ); - } -} - -fn test_affine_point_verification(ecc: &mut Ecc, rng: &mut Rng) { - for &prime_field in TEST_PARAMS_VECTOR.prime_fields { - print!("Beginning affine point verification tests over "); - match prime_field.len() { - 24 => print!("secp192r1..."), - _ => print!("secp256r1..."), - }; - let t1 = &mut [0_u8; 96]; - let (k, x) = t1.split_at_mut(prime_field.len()); - let (x, y) = x.split_at_mut(prime_field.len()); - let (y, _) = y.split_at_mut(prime_field.len()); - let mut delta_time = 0; - for _ in 0..TEST_PARAMS_VECTOR.nb_loop_mul { - loop { - rng.read(k).unwrap(); - let is_zero = k.iter().all(|&elt| elt == 0); - let is_modulus = k.iter().zip(prime_field).all(|(&a, &b)| a == b); - if is_zero == false && is_modulus == false { - break; - } - } - - let curve = match prime_field.len() { - 24 => { - let sw_k = - p192::Scalar::from(elliptic_curve::ScalarPrimitive::from_slice(k).unwrap()); - let q = p192::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - x.copy_from_slice(q.x().unwrap().as_slice()); - y.copy_from_slice(q.y().unwrap().as_slice()); - &EllipticCurve::P192 - } - 32 => { - let sw_k = - p256::Scalar::from(elliptic_curve::ScalarPrimitive::from_slice(k).unwrap()); - let q = p256::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - x.copy_from_slice(q.x().unwrap().as_slice()); - y.copy_from_slice(q.y().unwrap().as_slice()); - &EllipticCurve::P256 - } - _ => unimplemented!(), - }; - - let begin_time = SystemTimer::now(); - match ecc.affine_point_verification(&curve, x, y) { - Err(Error::SizeMismatchCurve) => { - assert!(false, "Inputs data doesn't match the key length selected.") - } - Err(Error::PointNotOnSelectedCurve) => assert!( - false, - "ECC failed while affine point verification with x = {:02X?} and y = {:02X?}.", - x, y, - ), - _ => {} - } - let end_time = SystemTimer::now(); - delta_time += end_time - begin_time; - } - println!( - "ok (it took {} cycles in average)", - delta_time / (TEST_PARAMS_VECTOR.nb_loop_mul as u64) - ); - } -} - -fn test_afine_point_verification_multiplication(ecc: &mut Ecc, rng: &mut Rng) { - for &prime_field in TEST_PARAMS_VECTOR.prime_fields { - print!("Beginning affine point verification + multiplication tests over "); - match prime_field.len() { - 24 => print!("secp192r1..."), - _ => print!("secp256r1..."), - }; - let t1 = &mut [0_u8; 96]; - let (k, x) = t1.split_at_mut(prime_field.len()); - let (x, y) = x.split_at_mut(prime_field.len()); - let (y, _) = y.split_at_mut(prime_field.len()); - let mut delta_time = 0; - for _ in 0..TEST_PARAMS_VECTOR.nb_loop_mul { - loop { - rng.read(k).unwrap(); - let is_zero = k.iter().all(|&elt| elt == 0); - let is_modulus = k.iter().zip(prime_field).all(|(&a, &b)| a == b); - if is_zero == false && is_modulus == false { - break; - } - } - let curve = match prime_field.len() { - 24 => { - x.copy_from_slice( - p192::AffinePoint::GENERATOR - .to_encoded_point(false) - .x() - .unwrap(), - ); - y.copy_from_slice( - p192::AffinePoint::GENERATOR - .to_encoded_point(false) - .y() - .unwrap(), - ); - &EllipticCurve::P192 - } - 32 => { - x.copy_from_slice( - p256::AffinePoint::GENERATOR - .to_encoded_point(false) - .x() - .unwrap(), - ); - y.copy_from_slice( - p256::AffinePoint::GENERATOR - .to_encoded_point(false) - .y() - .unwrap(), - ); - &EllipticCurve::P256 - } - _ => unimplemented!(), - }; - - let begin_time = SystemTimer::now(); - match ecc.affine_point_verification_multiplication(curve, k, x, y) { - Err(Error::SizeMismatchCurve) => assert!(false, "Inputs data doesn't match the key length selected."), - Err(Error::PointNotOnSelectedCurve) => assert!( - false, "ECC failed while affine point verification + multiplication with x = {:02X?} and y = {:02X?}.", - x, y, - ), - _ => {}, - } - let end_time = SystemTimer::now(); - delta_time += end_time - begin_time; - - let t2 = &mut [0_u8; 64]; - - let (sw_x, sw_y) = t2.split_at_mut(prime_field.len()); - let (sw_y, _) = sw_y.split_at_mut(prime_field.len()); - - match prime_field.len() { - 24 => { - let sw_k = - p192::Scalar::from(elliptic_curve::ScalarPrimitive::from_slice(k).unwrap()); - let q = p192::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - sw_x.copy_from_slice(q.x().unwrap().as_slice()); - sw_y.copy_from_slice(q.y().unwrap().as_slice()); - } - 32 => { - let sw_k = - p256::Scalar::from(elliptic_curve::ScalarPrimitive::from_slice(k).unwrap()); - let q = p256::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - sw_x.copy_from_slice(q.x().unwrap().as_slice()); - sw_y.copy_from_slice(q.y().unwrap().as_slice()); - } - _ => unimplemented!(), - }; - - for (a, b) in x.iter().zip(sw_x) { - assert_eq!( - a, b, - "ECC failed during affine point verification + multiplication with d_a = {:02X?} ({:02X?} != {:02X?})", - k, a, b, - ); - } - - for (a, b) in y.iter().zip(sw_y) { - assert_eq!( - a, b, - "ECC failed during affine point verification + multiplication with d_a = {:02X?} ({:02X?} != {:02X?})", - k, a, b, - ); - } - } - println!( - "ok (it took {} cycles in average)", - delta_time / (TEST_PARAMS_VECTOR.nb_loop_mul as u64) - ); - } -} - -fn test_jacobian_point_multiplication(ecc: &mut Ecc, rng: &mut Rng) { - for &prime_field in TEST_PARAMS_VECTOR.prime_fields { - print!("Beginning jacobian point multiplication tests over "); - match prime_field.len() { - 24 => print!("secp192r1..."), - _ => print!("secp256r1..."), - }; - let t1 = &mut [0_u8; 96]; - let (k, x) = t1.split_at_mut(prime_field.len()); - let (x, y) = x.split_at_mut(prime_field.len()); - let (y, _) = y.split_at_mut(prime_field.len()); - let mut delta_time = 0; - for _ in 0..TEST_PARAMS_VECTOR.nb_loop_mul { - let t2 = &mut [0_u8; 96]; - - let (sw_x, sw_y) = t2.split_at_mut(prime_field.len()); - let (sw_y, sw_k) = sw_y.split_at_mut(prime_field.len()); - let (sw_k, _) = sw_k.split_at_mut(prime_field.len()); - - loop { - rng.read(k).unwrap(); - let is_zero = k.iter().all(|&elt| elt == 0); - let is_modulus = k.iter().zip(prime_field).all(|(&a, &b)| a == b); - if is_zero == false && is_modulus == false { - break; - } - } - sw_k.copy_from_slice(k); - let curve = match prime_field.len() { - 24 => { - x.copy_from_slice( - p192::AffinePoint::GENERATOR - .to_encoded_point(false) - .x() - .unwrap(), - ); - y.copy_from_slice( - p192::AffinePoint::GENERATOR - .to_encoded_point(false) - .y() - .unwrap(), - ); - &EllipticCurve::P192 - } - 32 => { - x.copy_from_slice( - p256::AffinePoint::GENERATOR - .to_encoded_point(false) - .x() - .unwrap(), - ); - y.copy_from_slice( - p256::AffinePoint::GENERATOR - .to_encoded_point(false) - .y() - .unwrap(), - ); - &EllipticCurve::P256 - } - _ => unimplemented!(), - }; - - let begin_time = SystemTimer::now(); - ecc.jacobian_point_multiplication(curve, k, x, y) - .expect("Inputs data doesn't match the key length selected."); - let end_time = SystemTimer::now(); - delta_time += end_time - begin_time; - - match prime_field.len() { - 24 => { - let sw_k = p192::Scalar::from( - elliptic_curve::ScalarPrimitive::from_slice(sw_k).unwrap(), - ); - let q = p192::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - let modulus = DynResidueParams::new(&U192::from_be_slice(prime_field)); - let x_affine = - DynResidue::new(&U192::from_be_slice(q.x().unwrap().as_slice()), modulus); - let y_affine = - DynResidue::new(&U192::from_be_slice(q.y().unwrap().as_slice()), modulus); - let z = DynResidue::new(&U192::from_be_slice(k), modulus); - let x_jacobian = x_affine * z * z; - let y_jacobian = y_affine * z * z * z; - sw_x.copy_from_slice(x_jacobian.retrieve().to_be_bytes().as_slice()); - sw_y.copy_from_slice(y_jacobian.retrieve().to_be_bytes().as_slice()); - } - 32 => { - let sw_k = p256::Scalar::from( - elliptic_curve::ScalarPrimitive::from_slice(sw_k).unwrap(), - ); - let q = p256::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - let modulus = DynResidueParams::new(&U256::from_be_slice(prime_field)); - let x_affine = - DynResidue::new(&U256::from_be_slice(q.x().unwrap().as_slice()), modulus); - let y_affine = - DynResidue::new(&U256::from_be_slice(q.y().unwrap().as_slice()), modulus); - let z = DynResidue::new(&U256::from_be_slice(k), modulus); - let x_jacobian = x_affine * z * z; - let y_jacobian = y_affine * z * z * z; - sw_x.copy_from_slice(x_jacobian.retrieve().to_be_bytes().as_slice()); - sw_y.copy_from_slice(y_jacobian.retrieve().to_be_bytes().as_slice()); - } - _ => unimplemented!(), - }; - - for (a, b) in x.iter().zip(sw_x.iter()) { - assert_eq!( - a, b, - "ECC failed during jacobian point multiplication.\nX = {:02X?}\nX = {:02X?}", - x, sw_x, - ); - } - - for (a, b) in y.iter().zip(sw_y.iter()) { - assert_eq!( - a, b, - "ECC failed during jacobian point multiplication.\nY = {:02X?}\nY = {:02X?}", - y, sw_y, - ); - } - } - println!( - "ok (it took {} cycles in average)", - delta_time / (TEST_PARAMS_VECTOR.nb_loop_mul as u64) - ); - } -} - -fn test_jacobian_point_verification(ecc: &mut Ecc, rng: &mut Rng) { - for &prime_field in TEST_PARAMS_VECTOR.prime_fields { - print!("Beginning jacobian point verification tests over "); - match prime_field.len() { - 24 => print!("secp192r1..."), - _ => print!("secp256r1..."), - }; - let t1 = &mut [0_u8; 128]; - let (k, x) = t1.split_at_mut(prime_field.len()); - let (x, y) = x.split_at_mut(prime_field.len()); - let (y, z) = y.split_at_mut(prime_field.len()); - let (z, _) = z.split_at_mut(prime_field.len()); - let mut delta_time = 0; - for _ in 0..TEST_PARAMS_VECTOR.nb_loop_mul { - loop { - rng.read(k).unwrap(); - rng.read(z).unwrap(); - let is_zero = k.iter().all(|&elt| elt == 0) || z.iter().all(|&elt| elt == 0); - let is_modulus = k.iter().zip(prime_field).all(|(&a, &b)| a == b) - || z.iter().zip(prime_field).all(|(&a, &b)| a == b); - if is_zero == false && is_modulus == false { - break; - } - } - - let curve = match prime_field.len() { - 24 => { - let sw_k = - p192::Scalar::from(elliptic_curve::ScalarPrimitive::from_slice(k).unwrap()); - let q = p192::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - let modulus = DynResidueParams::new(&U192::from_be_slice(prime_field)); - let x_affine = - DynResidue::new(&U192::from_be_slice(q.x().unwrap().as_slice()), modulus); - let y_affine = - DynResidue::new(&U192::from_be_slice(q.y().unwrap().as_slice()), modulus); - let z = DynResidue::new(&U192::from_be_slice(z), modulus); - let x_jacobian = x_affine * z * z; - let y_jacobian = y_affine * z * z * z; - x.copy_from_slice(x_jacobian.retrieve().to_be_bytes().as_slice()); - y.copy_from_slice(y_jacobian.retrieve().to_be_bytes().as_slice()); - &EllipticCurve::P192 - } - 32 => { - let sw_k = - p256::Scalar::from(elliptic_curve::ScalarPrimitive::from_slice(k).unwrap()); - let q = p256::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - let modulus = DynResidueParams::new(&U256::from_be_slice(prime_field)); - let x_affine = - DynResidue::new(&U256::from_be_slice(q.x().unwrap().as_slice()), modulus); - let y_affine = - DynResidue::new(&U256::from_be_slice(q.y().unwrap().as_slice()), modulus); - let z = DynResidue::new(&U256::from_be_slice(z), modulus); - let x_jacobian = x_affine * z * z; - let y_jacobian = y_affine * z * z * z; - x.copy_from_slice(x_jacobian.retrieve().to_be_bytes().as_slice()); - y.copy_from_slice(y_jacobian.retrieve().to_be_bytes().as_slice()); - &EllipticCurve::P256 - } - _ => unimplemented!(), - }; - - let begin_time = SystemTimer::now(); - match ecc.jacobian_point_verification(&curve, x, y, z) { - Err(Error::SizeMismatchCurve) => { - assert!(false, "Inputs data doesn't match the key length selected.") - } - Err(Error::PointNotOnSelectedCurve) => assert!( - false, - "ECC failed while base point verification with x = {:02X?} and y = {:02X?}.", - x, y, - ), - _ => {} - } - let end_time = SystemTimer::now(); - delta_time += end_time - begin_time; - } - println!( - "ok (it took {} cycles in average)", - delta_time / (TEST_PARAMS_VECTOR.nb_loop_mul as u64) - ); - } -} - -fn test_afine_point_verification_jacobian_multiplication(ecc: &mut Ecc, rng: &mut Rng) { - for &prime_field in TEST_PARAMS_VECTOR.prime_fields { - print!("Beginning affine point verification + jacobian point multiplication tests over "); - match prime_field.len() { - 24 => print!("secp192r1..."), - _ => print!("secp256r1..."), - }; - let t1 = &mut [0_u8; 96]; - let (k, x) = t1.split_at_mut(prime_field.len()); - let (x, y) = x.split_at_mut(prime_field.len()); - let (y, _) = y.split_at_mut(prime_field.len()); - let mut delta_time = 0; - for _ in 0..TEST_PARAMS_VECTOR.nb_loop_mul { - let t2 = &mut [0_u8; 96]; - - let (sw_x, sw_y) = t2.split_at_mut(prime_field.len()); - let (sw_y, sw_k) = sw_y.split_at_mut(prime_field.len()); - let (sw_k, _) = sw_k.split_at_mut(prime_field.len()); - - loop { - rng.read(k).unwrap(); - let is_zero = k.iter().all(|&elt| elt == 0); - let is_modulus = k.iter().zip(prime_field).all(|(&a, &b)| a == b); - if is_zero == false && is_modulus == false { - break; - } - } - sw_k.copy_from_slice(k); - let curve = match prime_field.len() { - 24 => { - x.copy_from_slice( - p192::AffinePoint::GENERATOR - .to_encoded_point(false) - .x() - .unwrap(), - ); - y.copy_from_slice( - p192::AffinePoint::GENERATOR - .to_encoded_point(false) - .y() - .unwrap(), - ); - &EllipticCurve::P192 - } - 32 => { - x.copy_from_slice( - p256::AffinePoint::GENERATOR - .to_encoded_point(false) - .x() - .unwrap(), - ); - y.copy_from_slice( - p256::AffinePoint::GENERATOR - .to_encoded_point(false) - .y() - .unwrap(), - ); - &EllipticCurve::P256 - } - _ => unimplemented!(), - }; - - let begin_time = SystemTimer::now(); - match ecc.affine_point_verification_jacobian_multiplication(curve, k, x, y) { - Err(Error::SizeMismatchCurve) => assert!(false, "Inputs data doesn't match the key length selected."), - Err(Error::PointNotOnSelectedCurve) => assert!( - false, "ECC failed while affine point verification + multiplication with x = {:02X?} and y = {:02X?}.", - x, y, - ), - _ => {}, - } - let end_time = SystemTimer::now(); - delta_time += end_time - begin_time; - - match prime_field.len() { - 24 => { - let sw_k = p192::Scalar::from( - elliptic_curve::ScalarPrimitive::from_slice(sw_k).unwrap(), - ); - let q = p192::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - let modulus = DynResidueParams::new(&U192::from_be_slice(prime_field)); - let x_affine = - DynResidue::new(&U192::from_be_slice(q.x().unwrap().as_slice()), modulus); - let y_affine = - DynResidue::new(&U192::from_be_slice(q.y().unwrap().as_slice()), modulus); - let z = DynResidue::new(&U192::from_be_slice(k), modulus); - let x_jacobian = x_affine * z * z; - let y_jacobian = y_affine * z * z * z; - sw_x.copy_from_slice(x_jacobian.retrieve().to_be_bytes().as_slice()); - sw_y.copy_from_slice(y_jacobian.retrieve().to_be_bytes().as_slice()); - } - 32 => { - let sw_k = p256::Scalar::from( - elliptic_curve::ScalarPrimitive::from_slice(sw_k).unwrap(), - ); - let q = p256::AffinePoint::GENERATOR - .mul(sw_k) - .to_affine() - .to_encoded_point(false); - let modulus = DynResidueParams::new(&U256::from_be_slice(prime_field)); - let x_affine = - DynResidue::new(&U256::from_be_slice(q.x().unwrap().as_slice()), modulus); - let y_affine = - DynResidue::new(&U256::from_be_slice(q.y().unwrap().as_slice()), modulus); - let z = DynResidue::new(&U256::from_be_slice(k), modulus); - let x_jacobian = x_affine * z * z; - let y_jacobian = y_affine * z * z * z; - sw_x.copy_from_slice(x_jacobian.retrieve().to_be_bytes().as_slice()); - sw_y.copy_from_slice(y_jacobian.retrieve().to_be_bytes().as_slice()); - } - _ => unimplemented!(), - }; - - for (a, b) in x.iter().zip(sw_x.iter()) { - assert_eq!( - a, b, - "ECC failed during affine point verification + jacobian point multiplication.\nX = {:02X?}\nX = {:02X?}", - x, sw_x, - ); - } - - for (a, b) in y.iter().zip(sw_y.iter()) { - assert_eq!( - a, b, - "ECC failed during affine point verification + jacobian point multiplication.\nY = {:02X?}\nY = {:02X?}", - y, sw_y, - ); - } - } - println!( - "ok (it took {} cycles in average)", - delta_time / (TEST_PARAMS_VECTOR.nb_loop_mul as u64) - ); - } -} diff --git a/esp32c6-hal/examples/embassy_hello_world.rs b/esp32c6-hal/examples/embassy_hello_world.rs deleted file mode 100644 index 4f1039348..000000000 --- a/esp32c6-hal/examples/embassy_hello_world.rs +++ /dev/null @@ -1,48 +0,0 @@ -//! embassy hello world -//! -//! This is an example of running the embassy executor with multiple tasks -//! concurrently. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32c6_hal::{clock::ClockControl, embassy, peripherals::Peripherals, prelude::*}; -use esp_backtrace as _; - -#[embassy_executor::task] -async fn run() { - loop { - esp_println::println!("Hello world from embassy using esp-hal-async!"); - Timer::after(Duration::from_millis(1_000)).await; - } -} - -#[main] -async fn main(spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c6_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32c6_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - spawner.spawn(run()).ok(); - - loop { - esp_println::println!("Bing!"); - Timer::after(Duration::from_millis(5_000)).await; - } -} diff --git a/esp32c6-hal/examples/embassy_i2c.rs b/esp32c6-hal/examples/embassy_i2c.rs deleted file mode 100644 index 4b83e6e37..000000000 --- a/esp32c6-hal/examples/embassy_i2c.rs +++ /dev/null @@ -1,67 +0,0 @@ -//! Embassy I2C -//! -//! Folowing pins are used: -//! SDA GPIO1 -//! SCL GPIO2 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This is an example of running the embassy executor with IC2. It uses an -//! LIS3DH to get accelerometer data. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32c6_hal::{ - clock::ClockControl, - embassy, - i2c::I2C, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; -use lis3dh_async::{Lis3dh, Range, SlaveAddr}; - -#[main] -async fn main(_spawner: Spawner) { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c6_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32c6_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let i2c0 = I2C::new( - peripherals.I2C0, - io.pins.gpio1, - io.pins.gpio2, - 400u32.kHz(), - &clocks, - ); - - let mut lis3dh = Lis3dh::new_i2c(i2c0, SlaveAddr::Alternate).await.unwrap(); - lis3dh.set_range(Range::G8).await.unwrap(); - - loop { - let norm = lis3dh.accel_norm().await.unwrap(); - esp_println::println!("X: {:+.5} Y: {:+.5} Z: {:+.5}", norm.x, norm.y, norm.z); - - Timer::after(Duration::from_millis(100)).await; - } -} diff --git a/esp32c6-hal/examples/embassy_i2s_read.rs b/esp32c6-hal/examples/embassy_i2s_read.rs deleted file mode 100644 index 1814032bd..000000000 --- a/esp32c6-hal/examples/embassy_i2s_read.rs +++ /dev/null @@ -1,99 +0,0 @@ -//! This shows how to continuously receive data via I2S -//! -//! Pins used -//! MCLK GPIO4 -//! BCLK GPIO1 -//! WS GPIO2 -//! DIN GPIO5 -//! -//! Without an additional I2S source device you can connect 3V3 or GND to DIN to -//! read 0 or 0xFF or connect DIN to WS to read two different values -//! -//! You can also inspect the MCLK, BCLK and WS with a logic analyzer - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use esp32c6_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - embassy, - i2s::{asynch::*, DataFormat, I2s, Standard}, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -#[main] -async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c6_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32c6_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (_, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(0, 4092 * 4); - - let i2s = I2s::new( - peripherals.I2S0, - Standard::Philips, - DataFormat::Data16Channel16, - 44100u32.Hz(), - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - &clocks, - ) - .with_mclk(io.pins.gpio4); - - let i2s_rx = i2s - .i2s_rx - .with_bclk(io.pins.gpio1) - .with_ws(io.pins.gpio2) - .with_din(io.pins.gpio5) - .build(); - - let buffer = rx_buffer; - println!("Start"); - - let mut data = [0u8; 5000]; - let mut transaction = i2s_rx.read_dma_circular_async(buffer).unwrap(); - loop { - let avail = transaction.available().await; - println!("available {}", avail); - - let count = transaction.pop(&mut data).await.unwrap(); - println!( - "got {} bytes, {:x?}..{:x?}", - count, - &data[..10], - &data[count - 10..count] - ); - } -} diff --git a/esp32c6-hal/examples/embassy_i2s_sound.rs b/esp32c6-hal/examples/embassy_i2s_sound.rs deleted file mode 100644 index 599bada5a..000000000 --- a/esp32c6-hal/examples/embassy_i2s_sound.rs +++ /dev/null @@ -1,136 +0,0 @@ -//! This shows how to transmit data continuously via I2S -//! -//! Pins used -//! MCLK GPIO4 -//! BCLK GPIO1 -//! WS GPIO2 -//! DOUT GPIO3 -//! -//! Without an additional I2S sink device you can inspect the MCLK, BCLK, WS and -//! DOUT with a logic analyzer -//! -//! You can also connect e.g. a PCM510x to hear an annoying loud sine tone (full -//! scale), so turn down the volume before running this example. -//! -//! Wiring is like this -//! -//! | Pin | Connected to | -//! |-------|-----------------| -//! | BCK | GPIO1 | -//! | DIN | GPIO3 | -//! | LRCK | GPIO2 | -//! | SCK | Gnd | -//! | GND | Gnd | -//! | VIN | +3V3 | -//! | FLT | Gnd | -//! | FMT | Gnd | -//! | DEMP | Gnd | -//! | XSMT | +3V3 | - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use esp32c6_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - embassy, - i2s::{asynch::*, DataFormat, I2s, Standard}, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -const SINE: [i16; 64] = [ - 0, 3211, 6392, 9511, 12539, 15446, 18204, 20787, 23169, 25329, 27244, 28897, 30272, 31356, - 32137, 32609, 32767, 32609, 32137, 31356, 30272, 28897, 27244, 25329, 23169, 20787, 18204, - 15446, 12539, 9511, 6392, 3211, 0, -3211, -6392, -9511, -12539, -15446, -18204, -20787, -23169, - -25329, -27244, -28897, -30272, -31356, -32137, -32609, -32767, -32609, -32137, -31356, -30272, - -28897, -27244, -25329, -23169, -20787, -18204, -15446, -12539, -9511, -6392, -3211, -]; - -#[main] -async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c6_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32c6_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (tx_buffer, mut tx_descriptors, _, mut rx_descriptors) = dma_buffers!(32000, 0); - - let i2s = I2s::new( - peripherals.I2S0, - Standard::Philips, - DataFormat::Data16Channel16, - 44100u32.Hz(), - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - &clocks, - ) - .with_mclk(io.pins.gpio4); - - let i2s_tx = i2s - .i2s_tx - .with_bclk(io.pins.gpio1) - .with_ws(io.pins.gpio2) - .with_dout(io.pins.gpio3) - .build(); - - let data = - unsafe { core::slice::from_raw_parts(&SINE as *const _ as *const u8, SINE.len() * 2) }; - - let buffer = tx_buffer; - let mut idx = 0; - for i in 0..usize::min(data.len(), buffer.len()) { - buffer[i] = data[idx]; - - idx += 1; - - if idx >= data.len() { - idx = 0; - } - } - - let mut filler = [0u8; 10000]; - let mut idx = 32000 % data.len(); - - println!("Start"); - let mut transaction = i2s_tx.write_dma_circular_async(buffer).unwrap(); - loop { - for i in 0..filler.len() { - filler[i] = data[(idx + i) % data.len()]; - } - println!("Next"); - - let written = transaction.push(&filler).await.unwrap(); - idx = (idx + written) % data.len(); - println!("written {}", written); - } -} diff --git a/esp32c6-hal/examples/embassy_rmt_rx.rs b/esp32c6-hal/examples/embassy_rmt_rx.rs deleted file mode 100644 index 5ff4cc370..000000000 --- a/esp32c6-hal/examples/embassy_rmt_rx.rs +++ /dev/null @@ -1,110 +0,0 @@ -//! Demonstrates decoding pulse sequences with RMT -//! This uses the boot button as input - press the button a couple of -//! times to generate a pulse sequence and then wait for the idle timeout to see -//! the recorded pulse sequence - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use esp32c6_hal::{ - clock::ClockControl, - embassy::{self}, - peripherals::Peripherals, - prelude::*, - rmt::{asynch::RxChannelAsync, PulseCode, RxChannelConfig, RxChannelCreator}, - Rmt, - IO, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -const WIDTH: usize = 80; - -#[main] -async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c6_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32c6_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let rmt = Rmt::new(peripherals.RMT, 8u32.MHz(), &clocks).unwrap(); - - let mut channel = rmt - .channel2 - .configure( - io.pins.gpio9, - RxChannelConfig { - clk_divider: 255, - idle_threshold: 10000, - ..RxChannelConfig::default() - }, - ) - .unwrap(); - - let mut data = [PulseCode { - level1: true, - length1: 1, - level2: false, - length2: 1, - }; 48]; - - loop { - println!("receive"); - channel.receive(&mut data).await.unwrap(); - println!("received"); - let mut total = 0usize; - for entry in &data[..data.len()] { - if entry.length1 == 0 { - break; - } - total += entry.length1 as usize; - - if entry.length2 == 0 { - break; - } - total += entry.length2 as usize; - } - - for entry in &data[..data.len()] { - if entry.length1 == 0 { - break; - } - - let count = WIDTH / (total / entry.length1 as usize); - let c = if entry.level1 { '-' } else { '_' }; - for _ in 0..count + 1 { - print!("{}", c); - } - - if entry.length2 == 0 { - break; - } - - let count = WIDTH / (total / entry.length2 as usize); - let c = if entry.level2 { '-' } else { '_' }; - for _ in 0..count + 1 { - print!("{}", c); - } - } - - println!(); - } -} diff --git a/esp32c6-hal/examples/embassy_rmt_tx.rs b/esp32c6-hal/examples/embassy_rmt_tx.rs deleted file mode 100644 index 852f29707..000000000 --- a/esp32c6-hal/examples/embassy_rmt_tx.rs +++ /dev/null @@ -1,79 +0,0 @@ -//! Demonstrates generating pulse sequences with RMT -//! Connect a logic analyzer to GPIO1 to see the generated pulses. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32c6_hal::{ - clock::ClockControl, - embassy, - peripherals::Peripherals, - prelude::*, - rmt::{asynch::TxChannelAsync, PulseCode, TxChannelConfig, TxChannelCreator}, - Rmt, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -#[main] -async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c6_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32c6_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let rmt = Rmt::new(peripherals.RMT, 8u32.MHz(), &clocks).unwrap(); - - let mut channel = rmt - .channel0 - .configure( - io.pins.gpio1.into_push_pull_output(), - TxChannelConfig { - clk_divider: 255, - ..TxChannelConfig::default() - }, - ) - .unwrap(); - - let mut data = [PulseCode { - level1: true, - length1: 200, - level2: false, - length2: 50, - }; 20]; - - data[data.len() - 2] = PulseCode { - level1: true, - length1: 3000, - level2: false, - length2: 500, - }; - data[data.len() - 1] = PulseCode::default(); - - loop { - println!("transmit"); - channel.transmit(&data).await.unwrap(); - println!("transmitted\n"); - Timer::after(Duration::from_millis(500)).await; - } -} diff --git a/esp32c6-hal/examples/embassy_serial.rs b/esp32c6-hal/examples/embassy_serial.rs deleted file mode 100644 index f539274e1..000000000 --- a/esp32c6-hal/examples/embassy_serial.rs +++ /dev/null @@ -1,96 +0,0 @@ -//! embassy serial -//! -//! This is an example of running the embassy executor and asynchronously -//! writing to and reading from uart - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_sync::{blocking_mutex::raw::NoopRawMutex, signal::Signal}; -use esp32c6_hal::{ - clock::ClockControl, - embassy, - peripherals::{Peripherals, UART0}, - prelude::*, - uart::{config::AtCmdConfig, UartRx, UartTx}, - Uart, -}; -use esp_backtrace as _; -use static_cell::make_static; - -// rx_fifo_full_threshold -const READ_BUF_SIZE: usize = 64; -// EOT (CTRL-D) -const AT_CMD: u8 = 0x04; - -#[embassy_executor::task] -async fn writer(mut tx: UartTx<'static, UART0>, signal: &'static Signal) { - use core::fmt::Write; - embedded_io_async::Write::write( - &mut tx, - b"Hello async serial. Enter something ended with EOT (CTRL-D).\r\n", - ) - .await - .unwrap(); - embedded_io_async::Write::flush(&mut tx).await.unwrap(); - loop { - let bytes_read = signal.wait().await; - signal.reset(); - write!(&mut tx, "\r\n-- received {} bytes --\r\n", bytes_read).unwrap(); - embedded_io_async::Write::flush(&mut tx).await.unwrap(); - } -} - -#[embassy_executor::task] -async fn reader(mut rx: UartRx<'static, UART0>, signal: &'static Signal) { - const MAX_BUFFER_SIZE: usize = 10 * READ_BUF_SIZE + 16; - - let mut rbuf: [u8; MAX_BUFFER_SIZE] = [0u8; MAX_BUFFER_SIZE]; - let mut offset = 0; - loop { - let r = embedded_io_async::Read::read(&mut rx, &mut rbuf[offset..]).await; - match r { - Ok(len) => { - offset += len; - esp_println::println!("Read: {len}, data: {:?}", &rbuf[..offset]); - offset = 0; - signal.signal(len); - } - Err(e) => esp_println::println!("RX Error: {:?}", e), - } - } -} - -#[main] -async fn main(spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c6_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32c6_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - uart0.set_at_cmd(AtCmdConfig::new(None, None, None, AT_CMD, None)); - uart0 - .set_rx_fifo_full_threshold(READ_BUF_SIZE as u16) - .unwrap(); - let (tx, rx) = uart0.split(); - - let signal = &*make_static!(Signal::new()); - - spawner.spawn(reader(rx, &signal)).ok(); - spawner.spawn(writer(tx, &signal)).ok(); -} diff --git a/esp32c6-hal/examples/embassy_spi.rs b/esp32c6-hal/examples/embassy_spi.rs deleted file mode 100644 index 917bb3f48..000000000 --- a/esp32c6-hal/examples/embassy_spi.rs +++ /dev/null @@ -1,87 +0,0 @@ -//! Embassy SPI -//! -//! Folowing pins are used: -//! SCLK GPIO6 -//! MISO GPIO2 -//! MOSI GPIO7 -//! CS GPIO10 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. -//! -//! This is an example of running the embassy executor with SPI. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32c6_hal::{ - clock::ClockControl, - dma::{DmaPriority, *}, - dma_descriptors, - embassy, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{prelude::*, Spi}, - SpiMode, - }, - IO, -}; -use esp_backtrace as _; - -#[main] -async fn main(_spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c6_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32c6_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio6; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio7; - let cs = io.pins.gpio10; - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (mut descriptors, mut rx_descriptors) = dma_descriptors!(32000); - - let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) - .with_dma(dma_channel.configure( - false, - &mut descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let send_buffer = [0, 1, 2, 3, 4, 5, 6, 7]; - loop { - let mut buffer = [0; 8]; - esp_println::println!("Sending bytes"); - embedded_hal_async::spi::SpiBus::transfer(&mut spi, &mut buffer, &send_buffer) - .await - .unwrap(); - esp_println::println!("Bytes recieved: {:?}", buffer); - Timer::after(Duration::from_millis(5_000)).await; - } -} diff --git a/esp32c6-hal/examples/embassy_wait.rs b/esp32c6-hal/examples/embassy_wait.rs deleted file mode 100644 index 69f2977d7..000000000 --- a/esp32c6-hal/examples/embassy_wait.rs +++ /dev/null @@ -1,44 +0,0 @@ -//! embassy wait -//! -//! This is an example of asynchronously `Wait`ing for a pin state to change. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use embedded_hal_async::digital::Wait; -use esp32c6_hal::{clock::ClockControl, embassy, peripherals::Peripherals, prelude::*, IO}; -use esp_backtrace as _; - -#[main] -async fn main(_spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c6_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32c6_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - // GPIO 9 as input - let mut input = io.pins.gpio9.into_pull_down_input(); - - loop { - esp_println::println!("Waiting..."); - input.wait_for_rising_edge().await.unwrap(); - esp_println::println!("Ping!"); - Timer::after(Duration::from_millis(100)).await; - } -} diff --git a/esp32c6-hal/examples/gpio_interrupt.rs b/esp32c6-hal/examples/gpio_interrupt.rs deleted file mode 100644 index 386cb97b3..000000000 --- a/esp32c6-hal/examples/gpio_interrupt.rs +++ /dev/null @@ -1,60 +0,0 @@ -//! GPIO interrupt -//! -//! This prints "Interrupt" when the boot button is pressed. -//! It also blinks an LED like the blinky example. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32c6_hal::{ - clock::ClockControl, - gpio::{Event, Gpio9, Input, PullDown, IO}, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, - Delay, -}; -use esp_backtrace as _; - -static BUTTON: Mutex>>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Set GPIO5 as an output - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut led = io.pins.gpio5.into_push_pull_output(); - - // Set GPIO9 as an input - let mut button = io.pins.gpio9.into_pull_down_input(); - button.listen(Event::FallingEdge); - - critical_section::with(|cs| BUTTON.borrow_ref_mut(cs).replace(button)); - - interrupt::enable(peripherals::Interrupt::GPIO, interrupt::Priority::Priority3).unwrap(); - - let mut delay = Delay::new(&clocks); - loop { - led.toggle().unwrap(); - delay.delay_ms(500u32); - } -} - -#[interrupt] -fn GPIO() { - critical_section::with(|cs| { - esp_println::println!("Interrupt"); - - BUTTON - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .clear_interrupt(); - }); -} diff --git a/esp32c6-hal/examples/hello_rgb.rs b/esp32c6-hal/examples/hello_rgb.rs deleted file mode 100644 index e05b7c3d4..000000000 --- a/esp32c6-hal/examples/hello_rgb.rs +++ /dev/null @@ -1,65 +0,0 @@ -//! //! RGB LED Demo -//! -//! This example drives an SK68XX RGB LED that is connected to the GPIO8 pin. -//! A RGB LED is connected to that pin on the ESP32-C6-DevKitC-1 and board. -//! -//! The demo will leverage the [`smart_leds`](https://crates.io/crates/smart-leds) -//! crate functionality to circle through the HSV hue color space (with -//! saturation and value both at 255). Additionally, we apply a gamma correction -//! and limit the brightness to 10 (out of 255). -#![no_std] -#![no_main] - -use esp32c6_hal::{clock::ClockControl, peripherals, prelude::*, rmt::Rmt, Delay, IO}; -use esp_backtrace as _; -use esp_hal_smartled::{smartLedBuffer, SmartLedsAdapter}; -use smart_leds::{ - brightness, - gamma, - hsv::{hsv2rgb, Hsv}, - SmartLedsWrite, -}; - -#[entry] -fn main() -> ! { - let peripherals = peripherals::Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Configure RMT peripheral globally - let rmt = Rmt::new(peripherals.RMT, 80u32.MHz(), &clocks).unwrap(); - - // We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can - // be used directly with all `smart_led` implementations - let rmt_buffer = smartLedBuffer!(1); - let mut led = SmartLedsAdapter::new(rmt.channel0, io.pins.gpio8, rmt_buffer, &clocks); - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - let mut color = Hsv { - hue: 0, - sat: 255, - val: 255, - }; - let mut data; - - loop { - // Iterate over the rainbow! - for hue in 0..=255 { - color.hue = hue; - // Convert from the HSV color space (where we can easily transition from one - // color to the other) to the RGB color space that we can then send to the LED - data = [hsv2rgb(color)]; - // When sending to the LED, we do a gamma correction first (see smart_leds - // documentation for details) and then limit the brightness to 10 out of 255 so - // that the output it's not too bright. - led.write(brightness(gamma(data.iter().cloned()), 10)) - .unwrap(); - delay.delay_ms(20u8); - } - } -} diff --git a/esp32c6-hal/examples/hello_world.rs b/esp32c6-hal/examples/hello_world.rs deleted file mode 100644 index 5d529f7e1..000000000 --- a/esp32c6-hal/examples/hello_world.rs +++ /dev/null @@ -1,35 +0,0 @@ -//! This shows how to write text to uart0. -//! You can see the output with `espflash` if you provide the `--monitor` option - -#![no_std] -#![no_main] - -use core::fmt::Write; - -use esp32c6_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, - Uart, -}; -use esp_backtrace as _; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - timer0.start(1u64.secs()); - - loop { - writeln!(uart0, "Hello world!").unwrap(); - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32c6-hal/examples/hmac.rs b/esp32c6-hal/examples/hmac.rs deleted file mode 100644 index dd774ba64..000000000 --- a/esp32c6-hal/examples/hmac.rs +++ /dev/null @@ -1,121 +0,0 @@ -//! Demonstrates the use of the HMAC peripheral and compares the speed of -//! hardware-accelerated and pure software hashing. -//! -//! # Writing key -//! Before using the HMAC accelerator in upstream mode, you first need to -//! prepare a secret 256-bit HMAC key and burn the key to an empty eFuse block. -//! -//! ## ⚠️ Before writing ⚠️ -//! - From the factory, the eFuse keyblocks are programmed to be 32-byte 0x00. -//! - This example is programmed to use this value so you can skip this step if -//! you don't want to burn an eFuse key. -//! - If you skip the skip burning a custom key, you still need to [burn the -//! purpose](#burn-key-purpose). -//! - [Read more about eFuses](https://docs.espressif.com/projects/esptool/en/latest/esp32c6/espefuse/index.html) -//! -//! ## Burn key purpose -//! You first need to burn the efuse key purpose for the specified key below -//! (Default Key0). Purposes: -//! -//! | Purpose | Mode | Value | Description | -//! |--------------------------------|------------|-------|-----------------------------------------------| -//! | JTAG Re-enable | Downstream | 6 | EFUSE_KEY_PURPOSE_HMAC_DOWN_JTAG | -//! | DS Key Derivation | Downstream | 7 | EFUSE_KEY_PURPOSE_HMAC_DOWN_DIGITAL_SIGNATURE | -//! | HMAC Calculation | Upstream | 8 | EFUSE_KEY_PURPOSE_HMAC_UP | -//! | Both JTAG Re-enable and DS KDF | Downstream | 5 | EFUSE_KEY_PURPOSE_HMAC_DOWN_ALL | -//! -//! To burn the efuse key purpose `HMAC_UP` to `Key0`: -//! ```sh -//! espefuse.py burn_efuse KEY_PURPOSE_0 8 -//! ``` -//! -//! ## Use a custom key -//! You can generate a custom key file from a string using the following command -//! ```sh -//! echo -n "" | openssl dgst -sha256 -binary > key.bin -//! ``` -//! -//! You can then write your key using the following command -//! - `BLOCK_KEY0` The keyblock to program the key to. By default this example -//! uses key0. -//! - `HMAC_UP` The purpose for the key. Use HMAC_UP for upstream. -//! - `--no-read-protect` Allow to read the key from software, after writing it. -//! ```sh -//! espefuse.py burn_key BLOCK_KEY0 key.bin HMAC_UP --no-read-protect -//! ``` -//! To see the key in bytes, you can do the following: -//! ```sh -//! echo -n "" | openssl dgst -sha256 -binary | xxd -p -//! ``` -//! or from the binary file -//! ```sh -//! xxd -p key.bin -//! ``` - -#![no_std] -#![no_main] - -use esp32c6_hal::{ - clock::ClockControl, - hmac::{Hmac, HmacPurpose, KeyId}, - peripherals::Peripherals, - prelude::*, - systimer::SystemTimer, - Rng, -}; -use esp_backtrace as _; -use esp_println::println; -use hmac::{Hmac as HmacSw, Mac}; -use nb::block; -use sha2::Sha256; - -type HmacSha256 = HmacSw; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rng = Rng::new(peripherals.RNG); - - // Set sw key - let key = [0_u8; 32].as_ref(); - - let mut hw_hmac = Hmac::new(peripherals.HMAC); - - let mut src = [0_u8; 1024]; - rng.read(src.as_mut_slice()).unwrap(); - // println!("HMAC input {:02X?}", src); - - let mut output = [0u8; 32]; - - println!("Beginning stress tests..."); - println!("Testing length from 0 to {:?} bytes for HMAC...", src.len()); - for i in 0..src.len() + 1 { - let (nsrc, _) = src.split_at(i); - let mut remaining = nsrc; - hw_hmac.init(); - block!(hw_hmac.configure(HmacPurpose::ToUser, KeyId::Key0)).expect("Key purpose mismatch"); - let pre_hw_hmac = SystemTimer::now(); - while remaining.len() > 0 { - remaining = block!(hw_hmac.update(remaining)).unwrap(); - } - block!(hw_hmac.finalize(output.as_mut_slice())).unwrap(); - let post_hw_hmac = SystemTimer::now(); - let hw_time = post_hw_hmac - pre_hw_hmac; - let mut sw_hmac = HmacSha256::new_from_slice(key).expect("HMAC can take key of any size"); - let pre_sw_hash = SystemTimer::now(); - sw_hmac.update(nsrc); - let soft_result = sw_hmac.finalize().into_bytes(); - let post_sw_hash = SystemTimer::now(); - let soft_time = post_sw_hash - pre_sw_hash; - for (a, b) in output.iter().zip(soft_result) { - assert_eq!(*a, b); - } - println!("Testing for length: {:>4} | HW: {:>6} cycles, SW: {:>7} cycles (HW HMAC is {:>2}x faster)", i, hw_time, soft_time, soft_time / hw_time); - } - println!("Finished stress tests!"); - - loop {} -} diff --git a/esp32c6-hal/examples/i2c_bmp180_calibration_data.rs b/esp32c6-hal/examples/i2c_bmp180_calibration_data.rs deleted file mode 100644 index 1fae321c5..000000000 --- a/esp32c6-hal/examples/i2c_bmp180_calibration_data.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! Read calibration data from BMP180 sensor -//! -//! This example dumps the calibration data from a BMP180 sensor -//! -//! The following wiring is assumed: -//! - SDA => GPIO1 -//! - SCL => GPIO2 - -#![no_std] -#![no_main] - -use esp32c6_hal::{clock::ClockControl, gpio::IO, i2c::I2C, peripherals::Peripherals, prelude::*}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create a new peripheral object with the described wiring - // and standard I2C clock speed - let mut i2c = I2C::new( - peripherals.I2C0, - io.pins.gpio1, - io.pins.gpio2, - 100u32.kHz(), - &clocks, - ); - - loop { - let mut data = [0u8; 22]; - i2c.write_read(0x77, &[0xaa], &mut data).ok(); - - println!("{:02x?}", data); - } -} diff --git a/esp32c6-hal/examples/i2c_display.rs b/esp32c6-hal/examples/i2c_display.rs deleted file mode 100644 index a1d19671f..000000000 --- a/esp32c6-hal/examples/i2c_display.rs +++ /dev/null @@ -1,121 +0,0 @@ -//! I2C Display example -//! -//! This example prints some text on an SSD1306-based -//! display (via I2C) -//! -//! The following wiring is assumed: -//! - SDA => GPIO1 -//! - SCL => GPIO2 - -#![no_std] -#![no_main] - -use embedded_graphics::{ - mono_font::{ - ascii::{FONT_6X10, FONT_9X18_BOLD}, - MonoTextStyleBuilder, - }, - pixelcolor::BinaryColor, - prelude::*, - text::{Alignment, Text}, -}; -use esp32c6_hal::{ - clock::ClockControl, - gpio::IO, - i2c::I2C, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, -}; -use esp_backtrace as _; -use nb::block; -use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create a new peripheral object with the described wiring - // and standard I2C clock speed - let i2c = I2C::new( - peripherals.I2C0, - io.pins.gpio1, - io.pins.gpio2, - 100u32.kHz(), - &clocks, - ); - - // Start timer (5 second interval) - timer0.start(5u64.secs()); - - // Initialize display - let interface = I2CDisplayInterface::new(i2c); - let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0) - .into_buffered_graphics_mode(); - display.init().unwrap(); - - // Specify different text styles - let text_style = MonoTextStyleBuilder::new() - .font(&FONT_6X10) - .text_color(BinaryColor::On) - .build(); - let text_style_big = MonoTextStyleBuilder::new() - .font(&FONT_9X18_BOLD) - .text_color(BinaryColor::On) - .build(); - - loop { - // Fill display bufffer with a centered text with two lines (and two text - // styles) - Text::with_alignment( - "esp-hal", - display.bounding_box().center() + Point::new(0, 0), - text_style_big, - Alignment::Center, - ) - .draw(&mut display) - .unwrap(); - - Text::with_alignment( - "Chip: ESP32-C6", - display.bounding_box().center() + Point::new(0, 14), - text_style, - Alignment::Center, - ) - .draw(&mut display) - .unwrap(); - - // Write buffer to display - display.flush().unwrap(); - // Clear display buffer - display.clear(BinaryColor::Off).unwrap(); - - // Wait 5 seconds - block!(timer0.wait()).unwrap(); - - // Write single-line centered text "Hello World" to buffer - Text::with_alignment( - "Hello World!", - display.bounding_box().center(), - text_style_big, - Alignment::Center, - ) - .draw(&mut display) - .unwrap(); - - // Write buffer to display - display.flush().unwrap(); - // Clear display buffer - display.clear(BinaryColor::Off).unwrap(); - - // Wait 5 seconds - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32c6-hal/examples/i2s_read.rs b/esp32c6-hal/examples/i2s_read.rs deleted file mode 100644 index b0a396ab0..000000000 --- a/esp32c6-hal/examples/i2s_read.rs +++ /dev/null @@ -1,78 +0,0 @@ -//! This shows how to continuously receive data via I2S -//! -//! Pins used -//! MCLK GPIO4 -//! BCLK GPIO1 -//! WS GPIO2 -//! DIN GPIO5 -//! -//! Without an additional I2S source device you can connect 3V3 or GND to DIN to -//! read 0 or 0xFF or connect DIN to WS to read two different values -//! -//! You can also inspect the MCLK, BCLK and WS with a logic analyzer - -#![no_std] -#![no_main] - -use esp32c6_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - i2s::{DataFormat, I2s, I2sReadDma, Standard}, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (_, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(0, 4 * 4092); - - let i2s = I2s::new( - peripherals.I2S0, - Standard::Philips, - DataFormat::Data16Channel16, - 44100u32.Hz(), - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - &clocks, - ) - .with_mclk(io.pins.gpio4); - - let i2s_rx = i2s - .i2s_rx - .with_bclk(io.pins.gpio1) - .with_ws(io.pins.gpio2) - .with_din(io.pins.gpio5) - .build(); - - let buffer = rx_buffer; - - let mut transfer = i2s_rx.read_dma_circular(buffer).unwrap(); - println!("Started transfer"); - - loop { - let avail = transfer.available(); - - if avail > 0 { - let mut rcv = [0u8; 5000]; - transfer.pop(&mut rcv[..avail]).unwrap(); - println!("Received {:x?}...", &rcv[..30]); - } - } -} diff --git a/esp32c6-hal/examples/i2s_sound.rs b/esp32c6-hal/examples/i2s_sound.rs deleted file mode 100644 index 353bac781..000000000 --- a/esp32c6-hal/examples/i2s_sound.rs +++ /dev/null @@ -1,120 +0,0 @@ -//! This shows how to transmit data continously via I2S -//! -//! Pins used -//! MCLK GPIO4 -//! BCLK GPIO1 -//! WS GPIO2 -//! DOUT GPIO3 -//! -//! Without an additional I2S sink device you can inspect the MCLK, BCLK, WS and -//! DOUT with a logic analyzer -//! -//! You can also connect e.g. a PCM510x to hear an annoying loud sine tone (full -//! scale), so turn down the volume before running this example. -//! -//! Wiring is like this -//! -//! | Pin | Connected to | -//! |-------|-----------------| -//! | BCK | GPIO1 | -//! | DIN | GPIO3 | -//! | LRCK | GPIO2 | -//! | SCK | Gnd | -//! | GND | Gnd | -//! | VIN | +3V3 | -//! | FLT | Gnd | -//! | FMT | Gnd | -//! | DEMP | Gnd | -//! | XSMT | +3V3 | - -#![no_std] -#![no_main] - -use esp32c6_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - i2s::{DataFormat, I2s, I2sWriteDma, Standard}, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; - -const SINE: [i16; 64] = [ - 0, 3211, 6392, 9511, 12539, 15446, 18204, 20787, 23169, 25329, 27244, 28897, 30272, 31356, - 32137, 32609, 32767, 32609, 32137, 31356, 30272, 28897, 27244, 25329, 23169, 20787, 18204, - 15446, 12539, 9511, 6392, 3211, 0, -3211, -6392, -9511, -12539, -15446, -18204, -20787, -23169, - -25329, -27244, -28897, -30272, -31356, -32137, -32609, -32767, -32609, -32137, -31356, -30272, - -28897, -27244, -25329, -23169, -20787, -18204, -15446, -12539, -9511, -6392, -3211, -]; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (tx_buffer, mut tx_descriptors, _, mut rx_descriptors) = dma_buffers!(32000, 0); - - let i2s = I2s::new( - peripherals.I2S0, - Standard::Philips, - DataFormat::Data16Channel16, - 44100u32.Hz(), - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - &clocks, - ) - .with_mclk(io.pins.gpio4); - - let i2s_tx = i2s - .i2s_tx - .with_bclk(io.pins.gpio1) - .with_ws(io.pins.gpio2) - .with_dout(io.pins.gpio3) - .build(); - - let data = - unsafe { core::slice::from_raw_parts(&SINE as *const _ as *const u8, SINE.len() * 2) }; - - let buffer = tx_buffer; - let mut idx = 0; - for i in 0..usize::min(data.len(), buffer.len()) { - buffer[i] = data[idx]; - - idx += 1; - - if idx >= data.len() { - idx = 0; - } - } - - let mut filler = [0u8; 10000]; - - let mut transfer = i2s_tx.write_dma_circular(buffer).unwrap(); - loop { - let avail = transfer.available(); - if avail > 0 { - let avail = usize::min(10000, avail); - for bidx in 0..avail { - filler[bidx] = data[idx]; - idx += 1; - - if idx >= data.len() { - idx = 0; - } - } - transfer.push(&filler[0..avail]).unwrap(); - } - } -} diff --git a/esp32c6-hal/examples/ledc.rs b/esp32c6-hal/examples/ledc.rs deleted file mode 100644 index 9b9367516..000000000 --- a/esp32c6-hal/examples/ledc.rs +++ /dev/null @@ -1,66 +0,0 @@ -//! Turns on LED with the option to change LED intensity depending on `duty` -//! value. Possible values (`u32`) are in range 0..100. -//! -//! This assumes that a LED is connected to the pin assigned to `led`. (GPIO4) - -#![no_std] -#![no_main] - -use esp32c6_hal::{ - clock::ClockControl, - gpio::IO, - ledc::{ - channel::{self, ChannelIFace}, - timer::{self, TimerIFace}, - LSGlobalClkSource, - LowSpeed, - LEDC, - }, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let led = io.pins.gpio4.into_push_pull_output(); - - let mut ledc = LEDC::new(peripherals.LEDC, &clocks); - ledc.set_global_slow_clock(LSGlobalClkSource::APBClk); - let mut lstimer0 = ledc.get_timer::(timer::Number::Timer2); - - lstimer0 - .configure(timer::config::Config { - duty: timer::config::Duty::Duty5Bit, - clock_source: timer::LSClockSource::APBClk, - frequency: 24u32.kHz(), - }) - .unwrap(); - - let mut channel0 = ledc.get_channel(channel::Number::Channel0, led); - channel0 - .configure(channel::config::Config { - timer: &lstimer0, - duty_pct: 10, - pin_config: channel::config::PinConfig::PushPull, - }) - .unwrap(); - - channel0.start_duty_fade(0, 100, 2000).expect_err( - "Fading from 0% to 100%, at 24kHz and 5-bit resolution, over 2 seconds, should fail", - ); - - loop { - // Set up a breathing LED: fade from off to on over a second, then - // from on back off over the next second. Then loop. - channel0.start_duty_fade(0, 100, 1000).unwrap(); - while channel0.is_duty_fade_running() {} - channel0.start_duty_fade(100, 0, 1000).unwrap(); - while channel0.is_duty_fade_running() {} - } -} diff --git a/esp32c6-hal/examples/mcpwm.rs b/esp32c6-hal/examples/mcpwm.rs deleted file mode 100644 index e036fdb14..000000000 --- a/esp32c6-hal/examples/mcpwm.rs +++ /dev/null @@ -1,49 +0,0 @@ -//! Uses timer0 and operator0 of the MCPWM0 peripheral to output a 50% duty -//! signal at 20 kHz. -//! -//! The signal will be output to the pin assigned to `pin`. (GPIO4) - -#![no_std] -#![no_main] - -use esp32c6_hal::{ - clock::ClockControl, - gpio::IO, - mcpwm::{operator::PwmPinConfig, timer::PwmWorkingMode, PeripheralClockConfig, MCPWM}, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let pin = io.pins.gpio4; - - // initialize peripheral - let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 40u32.MHz()).unwrap(); - let mut mcpwm = MCPWM::new(peripherals.MCPWM0, clock_cfg); - - // connect operator0 to timer0 - mcpwm.operator0.set_timer(&mcpwm.timer0); - // connect operator0 to pin - let mut pwm_pin = mcpwm - .operator0 - .with_pin_a(pin, PwmPinConfig::UP_ACTIVE_HIGH); - - // start timer with timestamp values in the range of 0..=99 and a frequency of - // 20 kHz - let timer_clock_cfg = clock_cfg - .timer_clock_with_frequency(99, PwmWorkingMode::Increase, 20u32.kHz()) - .unwrap(); - mcpwm.timer0.start(timer_clock_cfg); - - // pin will be high 50% of the time - pwm_pin.set_timestamp(50); - - loop {} -} diff --git a/esp32c6-hal/examples/parl_io_rx.rs b/esp32c6-hal/examples/parl_io_rx.rs deleted file mode 100644 index 4e92603d1..000000000 --- a/esp32c6-hal/examples/parl_io_rx.rs +++ /dev/null @@ -1,70 +0,0 @@ -//! This shows using Parallel IO to input 4 bit parallel data at 1MHz clock -//! rate. -//! -//! Uses GPIO 1, 2, 3 and 4 as the data pins. - -#![no_std] -#![no_main] - -use esp32c6_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - gpio::IO, - parl_io::{BitPackOrder, NoClkPin, ParlIoRxOnly, RxFourBits}, - peripherals::Peripherals, - prelude::*, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let (_, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(0, 32000); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let rx_pins = RxFourBits::new(io.pins.gpio1, io.pins.gpio2, io.pins.gpio3, io.pins.gpio4); - - let parl_io = ParlIoRxOnly::new( - peripherals.PARL_IO, - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - 1u32.MHz(), - &clocks, - ) - .unwrap(); - - let mut parl_io_rx = parl_io - .rx - .with_config(rx_pins, NoClkPin, BitPackOrder::Msb, Some(0xfff)) - .unwrap(); - - let mut buffer = rx_buffer; - buffer.fill(0u8); - - let mut delay = Delay::new(&clocks); - - loop { - let transfer = parl_io_rx.read_dma(buffer).unwrap(); - - // the buffer and driver is moved into the transfer and we can get it back via - // `wait` - (buffer, parl_io_rx) = transfer.wait().unwrap(); - println!("Received: {:02x?} ...", &buffer[..30]); - - delay.delay_ms(500u32); - } -} diff --git a/esp32c6-hal/examples/pcnt_encoder.rs b/esp32c6-hal/examples/pcnt_encoder.rs deleted file mode 100644 index c88876305..000000000 --- a/esp32c6-hal/examples/pcnt_encoder.rs +++ /dev/null @@ -1,133 +0,0 @@ -//! PCNT Encoder Demo -//! -//! This example decodes a quadrature encoder -//! -//! Since the PCNT units reset to zero when they reach their limits -//! we enable an interrupt on the upper and lower limits and -//! track the overflow in an AtomicI32 - -#![no_std] -#![no_main] -use core::{ - cell::RefCell, - cmp::min, - sync::atomic::{AtomicI32, Ordering}, -}; - -use critical_section::Mutex; -use esp32c6_hal as esp_hal; -use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - interrupt, - pcnt::{channel, channel::PcntSource, unit, PCNT}, - peripherals::{self, Peripherals}, - prelude::*, - IO, -}; -use esp_println::println; - -static UNIT0: Mutex>> = Mutex::new(RefCell::new(None)); -static VALUE: AtomicI32 = AtomicI32::new(0); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let unit_number = unit::Number::Unit1; - - // setup a pulse couter - println!("setup pulse counter unit 0"); - let pcnt = PCNT::new(peripherals.PCNT); - let mut u0 = pcnt.get_unit(unit_number); - u0.configure(unit::Config { - low_limit: -100, - high_limit: 100, - filter: Some(min(10u16 * 80, 1023u16)), - ..Default::default() - }) - .unwrap(); - - println!("setup channel 0"); - let mut ch0 = u0.get_channel(channel::Number::Channel0); - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut pin_a = io.pins.gpio5.into_pull_up_input(); - let mut pin_b = io.pins.gpio6.into_pull_up_input(); - - ch0.configure( - PcntSource::from_pin(&mut pin_a), - PcntSource::from_pin(&mut pin_b), - channel::Config { - lctrl_mode: channel::CtrlMode::Reverse, - hctrl_mode: channel::CtrlMode::Keep, - pos_edge: channel::EdgeMode::Decrement, - neg_edge: channel::EdgeMode::Increment, - invert_ctrl: false, - invert_sig: false, - }, - ); - - println!("setup channel 1"); - let mut ch1 = u0.get_channel(channel::Number::Channel1); - ch1.configure( - PcntSource::from_pin(&mut pin_b), - PcntSource::from_pin(&mut pin_a), - channel::Config { - lctrl_mode: channel::CtrlMode::Reverse, - hctrl_mode: channel::CtrlMode::Keep, - pos_edge: channel::EdgeMode::Increment, - neg_edge: channel::EdgeMode::Decrement, - invert_ctrl: false, - invert_sig: false, - }, - ); - println!("subscribing to events"); - u0.events(unit::Events { - low_limit: true, - high_limit: true, - thresh0: false, - thresh1: false, - zero: false, - }); - - println!("enabling interrupts"); - u0.listen(); - println!("resume pulse counter unit 0"); - u0.resume(); - - critical_section::with(|cs| UNIT0.borrow_ref_mut(cs).replace(u0)); - - interrupt::enable(peripherals::Interrupt::PCNT, interrupt::Priority::Priority2).unwrap(); - - let mut last_value: i32 = 0; - loop { - critical_section::with(|cs| { - let mut u0 = UNIT0.borrow_ref_mut(cs); - let u0 = u0.as_mut().unwrap(); - let value: i32 = u0.get_value() as i32 + VALUE.load(Ordering::SeqCst); - if value != last_value { - println!("value: {value}"); - last_value = value; - } - }); - } -} - -#[interrupt] -fn PCNT() { - critical_section::with(|cs| { - let mut u0 = UNIT0.borrow_ref_mut(cs); - let u0 = u0.as_mut().unwrap(); - if u0.interrupt_set() { - let events = u0.get_events(); - if events.high_limit { - VALUE.fetch_add(100, Ordering::SeqCst); - } else if events.low_limit { - VALUE.fetch_add(-100, Ordering::SeqCst); - } - u0.reset_interrupt(); - } - }); -} diff --git a/esp32c6-hal/examples/qspi_flash.rs b/esp32c6-hal/examples/qspi_flash.rs deleted file mode 100644 index e0d269458..000000000 --- a/esp32c6-hal/examples/qspi_flash.rs +++ /dev/null @@ -1,167 +0,0 @@ -//! SPI write and read a flash chip -//! -//! Folowing pins are used: -//! SCLK GPIO4 -//! MISOI/IO0 GPIO5 -//! MOSI/IO1 GPIO6 -//! IO2 GPIO7 -//! IO3 GPIO0 -//! CS GPIO1 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! Connect a flash chip (GD25Q64C was used) and make sure QE in the status -//! register is set. - -#![no_std] -#![no_main] - -use esp32c6_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{prelude::*, Address, Command, Spi}, - SpiDataMode, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio4; - let miso = io.pins.gpio5; - let mosi = io.pins.gpio6; - let sio2 = io.pins.gpio7; - let sio3 = io.pins.gpio0; - let cs = io.pins.gpio1; - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(256, 320); - - let mut spi = Spi::new_half_duplex(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(sio2), - Some(sio3), - Some(cs), - ) - .with_dma(dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let mut delay = Delay::new(&clocks); - - // DMA buffer require a static life-time - let mut zero_buf = zero_buffer(); - let send = tx_buffer; - let mut receive = rx_buffer; - - // write enable - let transfer = spi - .write( - SpiDataMode::Single, - Command::Command8(0x06, SpiDataMode::Single), - Address::None, - 0, - zero_buf, - ) - .unwrap(); - (zero_buf, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - // erase sector - let transfer = spi - .write( - SpiDataMode::Single, - Command::Command8(0x20, SpiDataMode::Single), - Address::Address24(0x000000, SpiDataMode::Single), - 0, - zero_buf, - ) - .unwrap(); - (zero_buf, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - // write enable - let transfer = spi - .write( - SpiDataMode::Single, - Command::Command8(0x06, SpiDataMode::Single), - Address::None, - 0, - zero_buf, - ) - .unwrap(); - (_, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - // write data / program page - send.fill(b'!'); - send[0..][..5].copy_from_slice(&b"Hello"[..]); - let transfer = spi - .write( - SpiDataMode::Quad, - Command::Command8(0x32, SpiDataMode::Single), - Address::Address24(0x000000, SpiDataMode::Single), - 0, - send, - ) - .unwrap(); - (_, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - loop { - // quad fast read - let transfer = spi - .read( - SpiDataMode::Quad, - Command::Command8(0xeb, SpiDataMode::Single), - Address::Address32(0x000000 << 8, SpiDataMode::Quad), - 4, - receive, - ) - .unwrap(); - - // here we could do something else while DMA transfer is in progress - // the buffers and spi is moved into the transfer and we can get it back via - // `wait` - (receive, spi) = transfer.wait().unwrap(); - - println!("{:x?}", &receive); - for b in &mut receive.iter() { - if *b >= 32 && *b <= 127 { - print!("{}", *b as char); - } else { - print!("."); - } - } - println!(); - - delay.delay_ms(250u32); - } -} - -fn zero_buffer() -> &'static mut [u8; 0] { - static mut BUFFER: [u8; 0] = [0u8; 0]; - unsafe { &mut BUFFER } -} diff --git a/esp32c6-hal/examples/ram.rs b/esp32c6-hal/examples/ram.rs deleted file mode 100644 index 5f42c5bb6..000000000 --- a/esp32c6-hal/examples/ram.rs +++ /dev/null @@ -1,94 +0,0 @@ -//! This shows how to use RTC memory. -//! RTC memory is retained during resets and during most sleep modes. -//! Initialized memory is always re-initialized on startup. -//! Uninitialzed memory isn't initialized on startup and can be used to keep -//! data during resets. Zeroed memory is initialized to zero on startup. -//! We can also run code from RTC memory. - -#![no_std] -#![no_main] - -use esp32c6_hal::{ - clock::ClockControl, - macros::ram, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, - Rtc, -}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; - -#[ram(rtc_fast)] -static mut SOME_INITED_DATA: [u8; 2] = [0xaa, 0xbb]; - -#[ram(rtc_fast, uninitialized)] -static mut SOME_UNINITED_DATA: [u8; 2] = [0; 2]; - -#[ram(rtc_fast, zeroed)] -static mut SOME_ZEROED_DATA: [u8; 8] = [0; 8]; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - // The RWDT flash boot protection must be enabled, as it is triggered as part of - // the example. - let mut rtc = Rtc::new(peripherals.LPWR); - rtc.rwdt.enable(); - - timer0.start(1u64.secs()); - - println!("RAM function located at {:p}", function_in_ram as *const ()); - unsafe { - println!("SOME_INITED_DATA {:x?}", SOME_INITED_DATA); - println!("SOME_UNINITED_DATA {:x?}", SOME_UNINITED_DATA); - println!("SOME_ZEROED_DATA {:x?}", SOME_ZEROED_DATA); - - SOME_INITED_DATA[0] = 0xff; - SOME_ZEROED_DATA[0] = 0xff; - - println!("SOME_INITED_DATA {:x?}", SOME_INITED_DATA); - println!("SOME_UNINITED_DATA {:x?}", SOME_UNINITED_DATA); - println!("SOME_ZEROED_DATA {:x?}", SOME_ZEROED_DATA); - - if SOME_UNINITED_DATA[0] != 0 { - SOME_UNINITED_DATA[0] = 0; - SOME_UNINITED_DATA[1] = 0; - } - - if SOME_UNINITED_DATA[1] == 0xff { - SOME_UNINITED_DATA[1] = 0; - } - - println!("Counter {}", SOME_UNINITED_DATA[1]); - SOME_UNINITED_DATA[1] += 1; - } - - println!( - "RTC_FAST function located at {:p}", - function_in_rtc_ram as *const () - ); - println!("Result {}", function_in_rtc_ram()); - - loop { - function_in_ram(); - block!(timer0.wait()).unwrap(); - } -} - -#[ram] -fn function_in_ram() { - println!("Hello world!"); -} - -#[ram(rtc_fast)] -fn function_in_rtc_ram() -> u32 { - 42 -} diff --git a/esp32c6-hal/examples/read_efuse.rs b/esp32c6-hal/examples/read_efuse.rs deleted file mode 100644 index 98b35a6e6..000000000 --- a/esp32c6-hal/examples/read_efuse.rs +++ /dev/null @@ -1,21 +0,0 @@ -//! This shows how to read selected information from eFuses. -//! e.g. the MAC address - -#![no_std] -#![no_main] - -use esp32c6_hal::{clock::ClockControl, efuse::Efuse, peripherals::Peripherals, prelude::*}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - println!("MAC address {:02x?}", Efuse::get_mac_address()); - println!("Flash Encryption {:?}", Efuse::get_flash_encryption()); - - loop {} -} diff --git a/esp32c6-hal/examples/rmt_rx.rs b/esp32c6-hal/examples/rmt_rx.rs deleted file mode 100644 index ecff7606a..000000000 --- a/esp32c6-hal/examples/rmt_rx.rs +++ /dev/null @@ -1,99 +0,0 @@ -//! Demonstrates decoding pulse sequences with RMT -//! This uses the boot button as input - press the button a couple of -//! times to generate a pulse sequence and then wait for the idle timeout to see -//! the recorded pulse sequence - -#![no_std] -#![no_main] - -use esp32c6_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - rmt::{PulseCode, RxChannel, RxChannelConfig, RxChannelCreator}, - Delay, - Rmt, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -const WIDTH: usize = 80; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let rmt = Rmt::new(peripherals.RMT, 1u32.MHz(), &clocks).unwrap(); - - let mut channel = rmt - .channel2 - .configure( - io.pins.gpio9, - RxChannelConfig { - clk_divider: 255, - idle_threshold: 10000, - ..RxChannelConfig::default() - }, - ) - .unwrap(); - - let mut delay = Delay::new(&clocks); - - let mut data = [PulseCode { - level1: true, - length1: 1, - level2: false, - length2: 1, - }; 48]; - - loop { - let transaction = channel.receive(&mut data).unwrap(); - channel = transaction.wait().unwrap(); - - let mut total = 0usize; - for entry in &data[..data.len()] { - if entry.length1 == 0 { - break; - } - total += entry.length1 as usize; - - if entry.length2 == 0 { - break; - } - total += entry.length2 as usize; - } - - for entry in &data[..data.len()] { - if entry.length1 == 0 { - break; - } - - let count = WIDTH / (total / entry.length1 as usize); - let c = if entry.level1 { '-' } else { '_' }; - for _ in 0..count + 1 { - print!("{}", c); - } - - if entry.length2 == 0 { - break; - } - - let count = WIDTH / (total / entry.length2 as usize); - let c = if entry.level2 { '-' } else { '_' }; - for _ in 0..count + 1 { - print!("{}", c); - } - } - - println!(); - println!(); - println!(); - - delay.delay_ms(500u32); - } -} diff --git a/esp32c6-hal/examples/rmt_tx.rs b/esp32c6-hal/examples/rmt_tx.rs deleted file mode 100644 index ebfe40607..000000000 --- a/esp32c6-hal/examples/rmt_tx.rs +++ /dev/null @@ -1,61 +0,0 @@ -//! Demonstrates generating pulse sequences with RMT -//! Connect a logic analyzer to GPIO1 to see the generated pulses. - -#![no_std] -#![no_main] - -use esp32c6_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - rmt::{PulseCode, TxChannel, TxChannelConfig, TxChannelCreator}, - Delay, - Rmt, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let rmt = Rmt::new(peripherals.RMT, 8u32.MHz(), &clocks).unwrap(); - - let mut channel = rmt - .channel0 - .configure( - io.pins.gpio1, - TxChannelConfig { - clk_divider: 255, - ..TxChannelConfig::default() - }, - ) - .unwrap(); - - let mut delay = Delay::new(&clocks); - - let mut data = [PulseCode { - level1: true, - length1: 200, - level2: false, - length2: 50, - }; 20]; - - data[data.len() - 2] = PulseCode { - level1: true, - length1: 3000, - level2: false, - length2: 500, - }; - data[data.len() - 1] = PulseCode::default(); - - loop { - let transaction = channel.transmit(&data); - channel = transaction.wait().unwrap(); - delay.delay_ms(500u32); - } -} diff --git a/esp32c6-hal/examples/rng.rs b/esp32c6-hal/examples/rng.rs deleted file mode 100644 index fb6541bfb..000000000 --- a/esp32c6-hal/examples/rng.rs +++ /dev/null @@ -1,28 +0,0 @@ -//! Demonstrates the use of the hardware Random Number Generator (RNG) - -#![no_std] -#![no_main] - -use esp32c6_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Rng}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Instantiate the Random Number Generator peripheral: - let mut rng = Rng::new(peripherals.RNG); - - // Generate a random word (u32): - println!("Random u32: {}", rng.random()); - - // Fill a buffer with random bytes: - let mut buf = [0u8; 16]; - rng.read(&mut buf).unwrap(); - println!("Random bytes: {:?}", buf); - - loop {} -} diff --git a/esp32c6-hal/examples/rsa.rs b/esp32c6-hal/examples/rsa.rs deleted file mode 100644 index 032ae0df4..000000000 --- a/esp32c6-hal/examples/rsa.rs +++ /dev/null @@ -1,156 +0,0 @@ -//! Demonstrates the use of the RSA peripheral and compares the speed of -//! multiple arithmetic operations. - -#![no_std] -#![no_main] - -use crypto_bigint::{ - modular::runtime_mod::{DynResidue, DynResidueParams}, - Uint, - U1024, - U512, -}; -use esp32c6_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - rsa::{ - operand_sizes, - Rsa, - RsaModularExponentiation, - RsaModularMultiplication, - RsaMultiplication, - }, - systimer::SystemTimer, -}; -use esp_backtrace as _; -use esp_println::println; - -const BIGNUM_1: U512 = Uint::from_be_hex( - "c7f61058f96db3bd87dbab08ab03b4f7f2f864eac249144adea6a65f97803b719d8ca980b7b3c0389c1c7c6\ -7dc353c5e0ec11f5fc8ce7f6073796cc8f73fa878", -); -const BIGNUM_2: U512 = Uint::from_be_hex( - "1763db3344e97be15d04de4868badb12a38046bb793f7630d87cf100aa1c759afac15a01f3c4c83ec2d2f66\ -6bd22f71c3c1f075ec0e2cb0cb29994d091b73f51", -); -const BIGNUM_3: U512 = Uint::from_be_hex( - "6b6bb3d2b6cbeb45a769eaa0384e611e1b89b0c9b45a045aca1c5fd6e8785b38df7118cf5dd45b9b63d293b\ -67aeafa9ba25feb8712f188cb139b7d9b9af1c361", -); - -const fn compute_r(modulus: &U512) -> U512 { - let mut d = [0_u32; U512::LIMBS * 2 + 1]; - d[d.len() - 1] = 1; - let d = Uint::from_words(d); - d.const_rem(&modulus.resize()).0.resize() -} - -const fn compute_mprime(modulus: &U512) -> u32 { - let m_inv = modulus.inv_mod2k(32).to_words()[0]; - (-1 * m_inv as i64 % 4294967296) as u32 -} - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rsa = Rsa::new(peripherals.RSA); - - nb::block!(rsa.ready()).unwrap(); - mod_exp_example(&mut rsa); - mod_multi_example(&mut rsa); - multiplication_example(&mut rsa); - loop {} -} - -fn mod_multi_example(rsa: &mut Rsa) { - let mut outbuf = [0_u32; U512::LIMBS]; - let mut mod_multi = RsaModularMultiplication::::new( - rsa, - BIGNUM_1.as_words(), - BIGNUM_2.as_words(), - BIGNUM_3.as_words(), - compute_mprime(&BIGNUM_3), - ); - let r = compute_r(&BIGNUM_3); - let pre_hw_modmul = SystemTimer::now(); - mod_multi.start_modular_multiplication(r.as_words()); - mod_multi.read_results(&mut outbuf); - let post_hw_modmul = SystemTimer::now(); - println!( - "it took {} cycles for hw modular multiplication", - post_hw_modmul - pre_hw_modmul - ); - let residue_params = DynResidueParams::new(&BIGNUM_3); - let residue_num1 = DynResidue::new(&BIGNUM_1, residue_params); - let residue_num2 = DynResidue::new(&BIGNUM_2, residue_params); - let pre_sw_exp = SystemTimer::now(); - let sw_out = residue_num1.mul(&residue_num2); - let post_sw_exp = SystemTimer::now(); - println!( - "it took {} cycles for sw modular multiplication", - post_sw_exp - pre_sw_exp - ); - assert_eq!(U512::from_words(outbuf), sw_out.retrieve()); - println!("modular multiplication done"); -} - -fn mod_exp_example(rsa: &mut Rsa) { - rsa.enable_disable_constant_time_acceleration(true); - rsa.enable_disable_search_acceleration(true); - let mut outbuf = [0_u32; U512::LIMBS]; - let mut mod_exp = RsaModularExponentiation::::new( - rsa, - BIGNUM_2.as_words(), - BIGNUM_3.as_words(), - compute_mprime(&BIGNUM_3), - ); - let r = compute_r(&BIGNUM_3); - let base = BIGNUM_1.as_words(); - let pre_hw_exp = SystemTimer::now(); - mod_exp.start_exponentiation(base, r.as_words()); - mod_exp.read_results(&mut outbuf); - let post_hw_exp = SystemTimer::now(); - println!( - "it took {} cycles for hw modular exponentiation", - post_hw_exp - pre_hw_exp - ); - let residue_params = DynResidueParams::new(&BIGNUM_3); - let residue = DynResidue::new(&BIGNUM_1, residue_params); - let pre_sw_exp = SystemTimer::now(); - let sw_out = residue.pow(&BIGNUM_2); - let post_sw_exp = SystemTimer::now(); - println!( - "it took {} cycles for sw modular exponentiation", - post_sw_exp - pre_sw_exp - ); - assert_eq!(U512::from_words(outbuf), sw_out.retrieve()); - println!("modular exponentiation done"); -} - -fn multiplication_example(rsa: &mut Rsa) { - let mut out = [0_u32; U1024::LIMBS]; - let operand_a = BIGNUM_1.as_words(); - let operand_b = BIGNUM_2.as_words(); - let mut rsamulti = RsaMultiplication::::new(rsa, operand_a); - let pre_hw_mul = SystemTimer::now(); - rsamulti.start_multiplication(operand_b); - rsamulti.read_results(&mut out); - let post_hw_mul = SystemTimer::now(); - println!( - "it took {} cycles for hw multiplication", - post_hw_mul - pre_hw_mul - ); - let pre_sw_mul = SystemTimer::now(); - let sw_out = BIGNUM_1.mul_wide(&BIGNUM_2); - let post_sw_mul = SystemTimer::now(); - println!( - "it took {} cycles for sw multiplication", - post_sw_mul - pre_sw_mul - ); - assert_eq!(U1024::from_words(out), sw_out.1.concat(&sw_out.0)); - println!("multiplication done"); -} diff --git a/esp32c6-hal/examples/rtc_time.rs b/esp32c6-hal/examples/rtc_time.rs deleted file mode 100644 index 9cf66a901..000000000 --- a/esp32c6-hal/examples/rtc_time.rs +++ /dev/null @@ -1,22 +0,0 @@ -//! Prints time in milliseconds from the RTC Timer - -#![no_std] -#![no_main] - -use esp32c6_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Delay, Rtc}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let rtc = Rtc::new(peripherals.LPWR); - let mut delay = Delay::new(&clocks); - - loop { - esp_println::println!("rtc time in milliseconds is {}", rtc.get_time_ms()); - delay.delay_ms(1000u32); - } -} diff --git a/esp32c6-hal/examples/rtc_watchdog.rs b/esp32c6-hal/examples/rtc_watchdog.rs deleted file mode 100644 index 966864829..000000000 --- a/esp32c6-hal/examples/rtc_watchdog.rs +++ /dev/null @@ -1,60 +0,0 @@ -//! This demos the RTC Watchdog Timer (RWDT). -//! The RWDT is initially configured to trigger an interrupt after a given -//! timeout. Then, upon expiration, the RWDT is restarted and then reconfigured -//! to reset both the main system and the RTC. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32c6_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, - Rtc, - Rwdt, -}; -use esp_backtrace as _; - -static RWDT: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rtc = Rtc::new(peripherals.LPWR); - rtc.rwdt.start(2000u64.millis()); - rtc.rwdt.listen(); - - interrupt::enable( - peripherals::Interrupt::LP_WDT, - interrupt::Priority::Priority1, - ) - .unwrap(); - - critical_section::with(|cs| RWDT.borrow_ref_mut(cs).replace(rtc.rwdt)); - - loop {} -} - -#[interrupt] -fn LP_WDT() { - critical_section::with(|cs| { - esp_println::println!("RWDT Interrupt"); - - let mut rwdt = RWDT.borrow_ref_mut(cs); - let rwdt = rwdt.as_mut().unwrap(); - - rwdt.clear_interrupt(); - - esp_println::println!("Restarting in 5 seconds..."); - - rwdt.start(5000u64.millis()); - rwdt.unlisten(); - }); -} diff --git a/esp32c6-hal/examples/serial_interrupts.rs b/esp32c6-hal/examples/serial_interrupts.rs deleted file mode 100644 index 1b58e9425..000000000 --- a/esp32c6-hal/examples/serial_interrupts.rs +++ /dev/null @@ -1,88 +0,0 @@ -//! This shows some of the interrupts that can be generated by UART/Serial. -//! Use a proper serial terminal to connect to the board (espmonitor and -//! espflash won't work) - -#![no_std] -#![no_main] - -use core::{cell::RefCell, fmt::Write}; - -use critical_section::Mutex; -use esp32c6_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals, UART0}, - prelude::*, - timer::TimerGroup, - uart::config::AtCmdConfig, - Cpu, - Uart, -}; -use esp_backtrace as _; -use nb::block; - -static SERIAL: Mutex>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - uart0.set_at_cmd(AtCmdConfig::new(None, None, None, b'#', None)); - uart0.set_rx_fifo_full_threshold(30).unwrap(); - uart0.listen_at_cmd(); - uart0.listen_rx_fifo_full(); - - timer0.start(1u64.secs()); - - critical_section::with(|cs| SERIAL.borrow_ref_mut(cs).replace(uart0)); - - interrupt::enable( - peripherals::Interrupt::UART0, - interrupt::Priority::Priority1, - ) - .unwrap(); - interrupt::set_kind( - Cpu::ProCpu, - interrupt::CpuInterrupt::Interrupt1, // Interrupt 1 handles priority one interrupts - interrupt::InterruptKind::Edge, - ); - - loop { - critical_section::with(|cs| { - writeln!(SERIAL.borrow_ref_mut(cs).as_mut().unwrap(), "Hello World! Send a single `#` character or send at least 30 characters and see the interrupts trigger.").ok(); - }); - - block!(timer0.wait()).unwrap(); - } -} - -#[interrupt] -fn UART0() { - critical_section::with(|cs| { - let mut serial = SERIAL.borrow_ref_mut(cs); - let serial = serial.as_mut().unwrap(); - - let mut cnt = 0; - while let nb::Result::Ok(_c) = serial.read() { - cnt += 1; - } - writeln!(serial, "Read {} bytes", cnt,).ok(); - - writeln!( - serial, - "Interrupt AT-CMD: {} RX-FIFO-FULL: {}", - serial.at_cmd_interrupt_set(), - serial.rx_fifo_full_interrupt_set(), - ) - .ok(); - - serial.reset_at_cmd_interrupt(); - serial.reset_rx_fifo_full_interrupt(); - }); -} diff --git a/esp32c6-hal/examples/sha.rs b/esp32c6-hal/examples/sha.rs deleted file mode 100644 index a43626cb2..000000000 --- a/esp32c6-hal/examples/sha.rs +++ /dev/null @@ -1,71 +0,0 @@ -//! Demonstrates the use of the SHA peripheral and compares the speed of -//! hardware-accelerated and pure software hashing. - -#![no_std] -#![no_main] - -use esp32c6_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - sha::{Sha, ShaMode}, -}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; -use sha2::{Digest, Sha256}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let source_data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".as_bytes(); - let mut remaining = source_data; - let mut hasher = Sha::new(peripherals.SHA, ShaMode::SHA256); - - // Short hashes can be created by decreasing the output buffer to the desired - // length - let mut output = [0u8; 32]; - - // let pre_calc = xtensa_lx::timer::get_cycle_count(); - // The hardware implementation takes a subslice of the input, and returns the - // unprocessed parts The unprocessed parts can be input in the next - // iteration, you can always add more data until finish() is called. After - // finish() is called update()'s will contribute to a new hash which - // can be extracted again with finish(). - - while remaining.len() > 0 { - // Can add println to view progress, however println takes a few orders of - // magnitude longer than the Sha function itself so not useful for - // comparing processing time println!("Remaining len: {}", - // remaining.len()); - - // All the HW Sha functions are infallible so unwrap is fine to use if you use - // block! - remaining = block!(hasher.update(remaining)).unwrap(); - } - - // Finish can be called as many times as desired to get mutliple copies of the - // output. - block!(hasher.finish(output.as_mut_slice())).unwrap(); - // let post_calc = xtensa_lx::timer::get_cycle_count(); - // let hw_time = post_calc - pre_calc; - // println!("Took {} cycles", hw_time); - println!("SHA256 Hash output {:02x?}", output); - - // let pre_calc = xtensa_lx::timer::get_cycle_count(); - let mut hasher = Sha256::new(); - hasher.update(source_data); - let soft_result = hasher.finalize(); - // let post_calc = xtensa_lx::timer::get_cycle_count(); - // let soft_time = post_calc - pre_calc; - // println!("Took {} cycles", soft_time); - println!("SHA256 Hash output {:02x?}", soft_result); - - assert_eq!(output, soft_result[..]); - // println!("HW SHA is {}x faster", soft_time/hw_time); - - loop {} -} diff --git a/esp32c6-hal/examples/software_interrupts.rs b/esp32c6-hal/examples/software_interrupts.rs deleted file mode 100644 index fb4d720b2..000000000 --- a/esp32c6-hal/examples/software_interrupts.rs +++ /dev/null @@ -1,141 +0,0 @@ -//! Software Interrupts -//! -//! An example of how software interrupts can be raised and reset -//! Should rotate through all of the available interrupts printing their number -//! when raised. -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32c6_hal::{ - clock::ClockControl, - interrupt::{self}, - peripherals::{self, Peripherals}, - prelude::*, - riscv, - system::{SoftwareInterrupt, SoftwareInterruptControl}, - Delay, -}; -use esp_backtrace as _; - -static SWINT: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clockctrl = system.clock_control; - let sw_int = system.software_interrupt_control; - let clocks = ClockControl::boot_defaults(clockctrl).freeze(); - - critical_section::with(|cs| SWINT.borrow_ref_mut(cs).replace(sw_int)); - - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR0, - interrupt::Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR1, - interrupt::Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR2, - interrupt::Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR3, - interrupt::Priority::Priority3, - ) - .unwrap(); - unsafe { riscv::interrupt::enable() } - let mut delay = Delay::new(&clocks); - let mut counter = 0; - loop { - delay.delay_ms(500u32); - match counter { - 0 => critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt0); - }), - 1 => critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt1); - }), - 2 => critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt2); - }), - 3 => { - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt3); - }); - counter = -1 - } - _ => {} - } - counter += 1; - } -} - -#[interrupt] -fn FROM_CPU_INTR0() { - esp_println::println!("SW interrupt0"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt0); - }); -} -#[interrupt] -fn FROM_CPU_INTR1() { - esp_println::println!("SW interrupt1"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt1); - }); -} -#[interrupt] -fn FROM_CPU_INTR2() { - esp_println::println!("SW interrupt2"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt2); - }); -} -#[interrupt] -fn FROM_CPU_INTR3() { - esp_println::println!("SW interrupt3"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt3); - }); -} diff --git a/esp32c6-hal/examples/spi_eh1_device_loopback.rs b/esp32c6-hal/examples/spi_eh1_device_loopback.rs deleted file mode 100644 index 0971b275f..000000000 --- a/esp32c6-hal/examples/spi_eh1_device_loopback.rs +++ /dev/null @@ -1,140 +0,0 @@ -//! SPI loopback test -//! -//! Folowing pins are used: -//! SCLK GPIO6 -//! MISO GPIO2 -//! MOSI GPIO7 -//! CS 1 GPIO3 -//! CS 2 GPIO4 -//! CS 3 GPIO5 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use embedded_hal_1::spi::SpiDevice; -use embedded_hal_bus::spi::RefCellDevice; -use esp32c6_hal::{ - clock::ClockControl, - gpio::{self, IO}, - peripherals::Peripherals, - prelude::*, - spi::{master::Spi, SpiMode}, - Delay, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio6; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio7; - - let spi_bus = Spi::new(peripherals.SPI2, 1000u32.kHz(), SpiMode::Mode0, &clocks).with_pins( - Some(sclk), - Some(mosi), - Some(miso), - gpio::NO_PIN, - ); - let spi_bus = RefCell::new(spi_bus); - let mut spi_device_1 = - RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio3.into_push_pull_output()); - let mut spi_device_2 = - RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio4.into_push_pull_output()); - let mut spi_device_3 = - RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio5.into_push_pull_output()); - - let mut delay = Delay::new(&clocks); - println!("=== SPI example with embedded-hal-1 traits ==="); - - loop { - // --- Symmetric transfer (Read as much as we write) --- - print!("Starting symmetric transfer..."); - let write = [0xde, 0xad, 0xbe, 0xef]; - let mut read: [u8; 4] = [0x00u8; 4]; - - spi_device_1.transfer(&mut read[..], &write[..]).unwrap(); - assert_eq!(write, read); - spi_device_2.transfer(&mut read[..], &write[..]).unwrap(); - spi_device_3.transfer(&mut read[..], &write[..]).unwrap(); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Asymmetric transfer (Read more than we write) --- - print!("Starting asymetric transfer (read > write)..."); - let mut read: [u8; 4] = [0x00; 4]; - - spi_device_1 - .transfer(&mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - assert_eq!(write[0], read[0]); - assert_eq!(read[2], 0x00u8); - spi_device_2 - .transfer(&mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - spi_device_3 - .transfer(&mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer --- - // Only your RAM is the limit! - print!("Starting huge transfer..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - let mut read = [0x00u8; 4096]; - - spi_device_1 - .transfer(&mut read[..], &write[..]) - .expect("Huge transfer failed"); - assert_eq!(write, read); - spi_device_2 - .transfer(&mut read[..], &write[..]) - .expect("Huge transfer failed"); - spi_device_3 - .transfer(&mut read[..], &write[..]) - .expect("Huge transfer failed"); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer in-place (No additional allocation - // needed) --- - print!("Starting huge transfer (in-place)..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - - spi_device_1 - .transfer_in_place(&mut write[..]) - .expect("Huge transfer failed"); - for byte in 0..write.len() { - assert_eq!(write[byte], byte as u8); - } - spi_device_2 - .transfer_in_place(&mut write[..]) - .expect("Huge transfer failed"); - spi_device_3 - .transfer_in_place(&mut write[..]) - .expect("Huge transfer failed"); - println!(" SUCCESS"); - delay.delay_ms(250u32); - } -} diff --git a/esp32c6-hal/examples/spi_eh1_loopback.rs b/esp32c6-hal/examples/spi_eh1_loopback.rs deleted file mode 100644 index aab5dbfb0..000000000 --- a/esp32c6-hal/examples/spi_eh1_loopback.rs +++ /dev/null @@ -1,104 +0,0 @@ -//! SPI loopback test -//! -//! Folowing pins are used: -//! SCLK GPIO6 -//! MISO GPIO2 -//! MOSI GPIO7 -//! CS GPIO10 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use embedded_hal_1::spi::SpiBus; -use esp32c6_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{master::Spi, SpiMode}, - Delay, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio6; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio7; - let cs = io.pins.gpio10; - - let mut spi = Spi::new(peripherals.SPI2, 1000u32.kHz(), SpiMode::Mode0, &clocks).with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(cs), - ); - - let mut delay = Delay::new(&clocks); - println!("=== SPI example with embedded-hal-1 traits ==="); - - loop { - // --- Symmetric transfer (Read as much as we write) --- - print!("Starting symmetric transfer..."); - let write = [0xde, 0xad, 0xbe, 0xef]; - let mut read: [u8; 4] = [0x00u8; 4]; - - SpiBus::transfer(&mut spi, &mut read[..], &write[..]).expect("Symmetric transfer failed"); - assert_eq!(write, read); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Asymmetric transfer (Read more than we write) --- - print!("Starting asymetric transfer (read > write)..."); - let mut read: [u8; 4] = [0x00; 4]; - - SpiBus::transfer(&mut spi, &mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - assert_eq!(write[0], read[0]); - assert_eq!(read[2], 0x00u8); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer --- - // Only your RAM is the limit! - print!("Starting huge transfer..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - let mut read = [0x00u8; 4096]; - - SpiBus::transfer(&mut spi, &mut read[..], &write[..]).expect("Huge transfer failed"); - assert_eq!(write, read); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer in-place (No additional allocation - // needed) --- - print!("Starting huge transfer (in-place)..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - - SpiBus::transfer_in_place(&mut spi, &mut write[..]).expect("Huge transfer failed"); - for byte in 0..write.len() { - assert_eq!(write[byte], byte as u8); - } - println!(" SUCCESS"); - delay.delay_ms(250u32); - } -} diff --git a/esp32c6-hal/examples/spi_halfduplex_read_manufacturer_id.rs b/esp32c6-hal/examples/spi_halfduplex_read_manufacturer_id.rs deleted file mode 100644 index d15d4ff21..000000000 --- a/esp32c6-hal/examples/spi_halfduplex_read_manufacturer_id.rs +++ /dev/null @@ -1,101 +0,0 @@ -//! SPI read manufacturer id from flash chip -//! -//! Folowing pins are used: -//! SCLK GPIO4 -//! MISOI/IO0 GPIO5 -//! MOSI/IO1 GPIO6 -//! IO2 GPIO7 -//! IO3 GPIO0 -//! CS GPIO1 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! Connect a flash chip (GD25Q64C was used) and make sure QE in the status -//! register is set. - -#![no_std] -#![no_main] - -use esp32c6_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{Address, Command, HalfDuplexReadWrite, Spi}, - SpiDataMode, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio4; - let miso = io.pins.gpio5; - let mosi = io.pins.gpio6; - let sio2 = io.pins.gpio7; - let sio3 = io.pins.gpio0; - let cs = io.pins.gpio1; - - let mut spi = Spi::new_half_duplex(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(sio2), - Some(sio3), - Some(cs), - ); - - let mut delay = Delay::new(&clocks); - - loop { - // READ MANUFACTURER ID FROM FLASH CHIP - let mut data = [0u8; 2]; - spi.read( - SpiDataMode::Single, - Command::Command8(0x90, SpiDataMode::Single), - Address::Address24(0x000000, SpiDataMode::Single), - 0, - &mut data, - ) - .unwrap(); - println!("Single {:x?}", data); - delay.delay_ms(250u32); - - // READ MANUFACTURER ID FROM FLASH CHIP - let mut data = [0u8; 2]; - spi.read( - SpiDataMode::Dual, - Command::Command8(0x92, SpiDataMode::Single), - Address::Address32(0x000000_00, SpiDataMode::Dual), - 0, - &mut data, - ) - .unwrap(); - println!("Dual {:x?}", data); - delay.delay_ms(250u32); - - // READ MANUFACTURER ID FROM FLASH CHIP - let mut data = [0u8; 2]; - spi.read( - SpiDataMode::Quad, - Command::Command8(0x94, SpiDataMode::Single), - Address::Address32(0x000000_00, SpiDataMode::Quad), - 4, - &mut data, - ) - .unwrap(); - println!("Quad {:x?}", data); - delay.delay_ms(1500u32); - } -} diff --git a/esp32c6-hal/examples/spi_loopback.rs b/esp32c6-hal/examples/spi_loopback.rs deleted file mode 100644 index 21102c493..000000000 --- a/esp32c6-hal/examples/spi_loopback.rs +++ /dev/null @@ -1,58 +0,0 @@ -//! SPI loopback test -//! -//! Folowing pins are used: -//! SCLK GPIO6 -//! MISO GPIO2 -//! MOSI GPIO7 -//! CS GPIO10 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use esp32c6_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{master::Spi, SpiMode}, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio6; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio7; - let cs = io.pins.gpio10; - - let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks).with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(cs), - ); - - let mut delay = Delay::new(&clocks); - - loop { - let mut data = [0xde, 0xca, 0xfb, 0xad]; - spi.transfer(&mut data).unwrap(); - println!("{:x?}", data); - - delay.delay_ms(250u32); - } -} diff --git a/esp32c6-hal/examples/spi_loopback_dma.rs b/esp32c6-hal/examples/spi_loopback_dma.rs deleted file mode 100644 index 3d183a151..000000000 --- a/esp32c6-hal/examples/spi_loopback_dma.rs +++ /dev/null @@ -1,97 +0,0 @@ -//! SPI loopback test using DMA -//! -//! Folowing pins are used: -//! SCLK GPIO6 -//! MISO GPIO2 -//! MOSI GPIO7 -//! CS GPIO10 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use esp32c6_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{prelude::*, Spi}, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio6; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio7; - let cs = io.pins.gpio10; - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(32000); - - let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) - .with_dma(dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let mut delay = Delay::new(&clocks); - - // DMA buffer require a static life-time - let mut send = tx_buffer; - let mut receive = rx_buffer; - let mut i = 0; - - for (i, v) in send.iter_mut().enumerate() { - *v = (i % 255) as u8; - } - - loop { - send[0] = i; - send[send.len() - 1] = i; - i = i.wrapping_add(1); - - let transfer = spi.dma_transfer(send, receive).unwrap(); - // here we could do something else while DMA transfer is in progress - let mut n = 0; - // Check is_done until the transfer is almost done (32000 bytes at 100kHz is - // 2.56 seconds), then move to wait(). - while !transfer.is_done() && n < 10 { - delay.delay_ms(250u32); - n += 1; - } - // the buffers and spi is moved into the transfer and we can get it back via - // `wait` - (receive, send, spi) = transfer.wait().unwrap(); - println!( - "{:x?} .. {:x?}", - &receive[..10], - &receive[receive.len() - 10..] - ); - - delay.delay_ms(250u32); - } -} diff --git a/esp32c6-hal/examples/systimer.rs b/esp32c6-hal/examples/systimer.rs deleted file mode 100644 index e2372e5f4..000000000 --- a/esp32c6-hal/examples/systimer.rs +++ /dev/null @@ -1,114 +0,0 @@ -//! This shows how to use the SYSTIMER peripheral including interrupts. -//! It's an additional timer besides the TIMG peripherals. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32c6_hal::{ - clock::ClockControl, - interrupt, - interrupt::Priority, - peripherals::{self, Peripherals}, - prelude::*, - systimer::{Alarm, Periodic, SystemTimer, Target}, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -static ALARM0: Mutex>>> = Mutex::new(RefCell::new(None)); -static ALARM1: Mutex>>> = Mutex::new(RefCell::new(None)); -static ALARM2: Mutex>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let syst = SystemTimer::new(peripherals.SYSTIMER); - - println!("SYSTIMER Current value = {}", SystemTimer::now()); - - let alarm0 = syst.alarm0.into_periodic(); - alarm0.set_period(1u32.secs()); - alarm0.clear_interrupt(); - alarm0.enable_interrupt(true); - - let alarm1 = syst.alarm1; - alarm1.set_target(SystemTimer::now() + (SystemTimer::TICKS_PER_SECOND * 2)); - alarm1.enable_interrupt(true); - - let alarm2 = syst.alarm2; - alarm2.set_target(SystemTimer::now() + (SystemTimer::TICKS_PER_SECOND * 3)); - alarm2.enable_interrupt(true); - - critical_section::with(|cs| { - ALARM0.borrow_ref_mut(cs).replace(alarm0); - ALARM1.borrow_ref_mut(cs).replace(alarm1); - ALARM2.borrow_ref_mut(cs).replace(alarm2); - }); - - interrupt::enable( - peripherals::Interrupt::SYSTIMER_TARGET0, - Priority::Priority1, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::SYSTIMER_TARGET1, - Priority::Priority2, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::SYSTIMER_TARGET2, - Priority::Priority2, - ) - .unwrap(); - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - loop { - delay.delay_ms(10000u32); - } -} - -#[interrupt] -fn SYSTIMER_TARGET0() { - println!("Interrupt lvl1 (alarm0)"); - critical_section::with(|cs| { - ALARM0 - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .clear_interrupt() - }); -} - -#[interrupt] -fn SYSTIMER_TARGET1() { - println!("Interrupt lvl2 (alarm1)"); - critical_section::with(|cs| { - ALARM1 - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .clear_interrupt() - }); -} - -#[interrupt] -fn SYSTIMER_TARGET2() { - println!("Interrupt lvl2 (alarm2)"); - critical_section::with(|cs| { - ALARM2 - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .clear_interrupt() - }); -} diff --git a/esp32c6-hal/examples/timer_interrupt.rs b/esp32c6-hal/examples/timer_interrupt.rs deleted file mode 100644 index 89063278d..000000000 --- a/esp32c6-hal/examples/timer_interrupt.rs +++ /dev/null @@ -1,86 +0,0 @@ -//! This shows how to use the TIMG peripheral interrupts. -//! There is TIMG0 and TIMG1 each of them containing a general purpose timer and -//! a watchdog timer. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32c6_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals, TIMG0, TIMG1}, - prelude::*, - timer::{Timer, Timer0, TimerGroup}, -}; -use esp_backtrace as _; - -static TIMER0: Mutex>>>> = Mutex::new(RefCell::new(None)); -static TIMER1: Mutex>>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks); - let mut timer1 = timer_group1.timer0; - - interrupt::enable( - peripherals::Interrupt::TG0_T0_LEVEL, - interrupt::Priority::Priority2, - ) - .unwrap(); - - timer0.start(500u64.millis()); - - timer0.listen(); - - interrupt::enable( - peripherals::Interrupt::TG1_T0_LEVEL, - interrupt::Priority::Priority2, - ) - .unwrap(); - - timer1.start(1u64.secs()); - timer1.listen(); - - critical_section::with(|cs| { - TIMER0.borrow_ref_mut(cs).replace(timer0); - TIMER1.borrow_ref_mut(cs).replace(timer1); - }); - - loop {} -} - -#[interrupt] -fn TG0_T0_LEVEL() { - critical_section::with(|cs| { - esp_println::println!("Interrupt 1"); - - let mut timer0 = TIMER0.borrow_ref_mut(cs); - let timer0 = timer0.as_mut().unwrap(); - - timer0.clear_interrupt(); - timer0.start(500u64.millis()); - }); -} - -#[interrupt] -fn TG1_T0_LEVEL() { - critical_section::with(|cs| { - esp_println::println!("Interrupt 11"); - - let mut timer1 = TIMER1.borrow_ref_mut(cs); - let timer1 = timer1.as_mut().unwrap(); - - timer1.clear_interrupt(); - timer1.start(1u64.secs()); - }); -} diff --git a/esp32c6-hal/examples/usb_serial_jtag.rs b/esp32c6-hal/examples/usb_serial_jtag.rs deleted file mode 100644 index 78a4b6955..000000000 --- a/esp32c6-hal/examples/usb_serial_jtag.rs +++ /dev/null @@ -1,78 +0,0 @@ -//! This shows how to output text via USB Serial/JTAG. -//! You need to connect via the Serial/JTAG interface to see any output. -//! Most dev-kits use a USB-UART-bridge - in that case you won't see any output. - -#![no_std] -#![no_main] - -use core::{cell::RefCell, fmt::Write}; - -use critical_section::Mutex; -use esp32c6_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, - timer::TimerGroup, - Cpu, - UsbSerialJtag, -}; -use esp_backtrace as _; -use nb::block; - -static USB_SERIAL: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let mut usb_serial = UsbSerialJtag::new(peripherals.USB_DEVICE); - - usb_serial.listen_rx_packet_recv_interrupt(); - - timer0.start(1u64.secs()); - - critical_section::with(|cs| USB_SERIAL.borrow_ref_mut(cs).replace(usb_serial)); - - interrupt::enable( - peripherals::Interrupt::USB_DEVICE, - interrupt::Priority::Priority1, - ) - .unwrap(); - - interrupt::set_kind( - Cpu::ProCpu, - interrupt::CpuInterrupt::Interrupt1, - interrupt::InterruptKind::Edge, - ); - - loop { - critical_section::with(|cs| { - writeln!( - USB_SERIAL.borrow_ref_mut(cs).as_mut().unwrap(), - "Hello world!" - ) - .ok(); - }); - - block!(timer0.wait()).unwrap(); - } -} - -#[interrupt] -fn USB_DEVICE() { - critical_section::with(|cs| { - let mut usb_serial = USB_SERIAL.borrow_ref_mut(cs); - let usb_serial = usb_serial.as_mut().unwrap(); - writeln!(usb_serial, "USB serial interrupt").unwrap(); - while let nb::Result::Ok(c) = usb_serial.read_byte() { - writeln!(usb_serial, "Read byte: {:02x}", c).unwrap(); - } - usb_serial.reset_rx_packet_recv_interrupt(); - }); -} diff --git a/esp32c6-hal/examples/watchdog.rs b/esp32c6-hal/examples/watchdog.rs deleted file mode 100644 index 3664980cf..000000000 --- a/esp32c6-hal/examples/watchdog.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! This demos the watchdog timer. -//! Basically the same as `hello_world` but if you remove the call to -//! `wdt.feed()` the watchdog will reset the system. - -#![no_std] -#![no_main] - -use esp32c6_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, timer::TimerGroup}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - let mut wdt0 = timer_group0.wdt; - - wdt0.start(2u64.secs()); - timer0.start(1u64.secs()); - - loop { - wdt0.feed(); - println!("Hello world!"); - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32c6-hal/src/lib.rs b/esp32c6-hal/src/lib.rs deleted file mode 100644 index 5d9ffdbd9..000000000 --- a/esp32c6-hal/src/lib.rs +++ /dev/null @@ -1,9 +0,0 @@ -//! A bare-metal (`no_std`) Hardware Abstraction Layer for the ESP32-C6 from -//! Espressif. -//! -//! ## Feature Flags -#![doc = document_features::document_features!()] -#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/46717278")] -#![no_std] - -pub use esp_hal::*; diff --git a/esp32h2-hal/.cargo/config.toml b/esp32h2-hal/.cargo/config.toml deleted file mode 100644 index 68c020c7c..000000000 --- a/esp32h2-hal/.cargo/config.toml +++ /dev/null @@ -1,12 +0,0 @@ -[target.riscv32imac-unknown-none-elf] -runner = "espflash flash --monitor" -rustflags = [ - "-C", "link-arg=-Tlinkall.x", - "-C", "force-frame-pointers", -] - -[build] -target = "riscv32imac-unknown-none-elf" - -[unstable] -build-std = [ "core" ] diff --git a/esp32h2-hal/Cargo.toml b/esp32h2-hal/Cargo.toml deleted file mode 100644 index e94059e48..000000000 --- a/esp32h2-hal/Cargo.toml +++ /dev/null @@ -1,187 +0,0 @@ -[package] -name = "esp32h2-hal" -version = "0.6.0" -edition = "2021" -rust-version = "1.67.0" -description = "HAL for ESP32-H2 microcontrollers" -repository = "https://github.com/esp-rs/esp-hal" -license = "MIT OR Apache-2.0" - -keywords = [ - "embedded", - "embedded-hal", - "esp", - "esp32h2", - "no-std", -] -categories = [ - "embedded", - "hardware-support", - "no-std", -] - -[package.metadata.docs.rs] -targets = ["riscv32imac-unknown-none-elf"] - -[dependencies] -document-features = "0.2.7" -esp-hal = { version = "0.15.0", features = ["esp32h2"], path = "../esp-hal" } -embassy-time-driver = { version = "0.1.0", optional = true } - -[dev-dependencies] -aes = "0.8.3" -critical-section = "1.1.2" -crypto-bigint = { version = "0.5.5", default-features = false } -elliptic-curve = { version = "0.13.8", default-features = false, features = ["sec1"] } -embassy-executor = { version = "0.5.0", features = ["nightly"] } -embassy-sync = "0.5.0" -embassy-time = "0.3.0" -embedded-graphics = "0.8.1" -embedded-hal-1 = { version = "1.0.0", package = "embedded-hal" } -embedded-hal-async = "1.0.0" -embedded-can = "0.4.1" -embedded-io-async = "0.6.1" -embedded-hal-bus = "0.1.0" -esp-backtrace = { version = "0.10.0", features = ["esp32h2", "panic-handler", "exception-handler", "print-uart"] } -esp-hal-smartled = { version = "0.8.0", features = ["esp32h2"], path = "../esp-hal-smartled" } -esp-println = { version = "0.8.0", features = ["esp32h2"] } -heapless = "0.8.0" -hex-literal = "0.4.1" -hmac = { version = "0.12.1", default-features = false } -lis3dh-async = "0.9.1" -p192 = { version = "0.13.0", default-features = false, features = ["arithmetic"] } -p256 = { version = "0.13.2", default-features = false, features = ["arithmetic"] } -sha2 = { version = "0.10.8", default-features = false} -smart-leds = "0.4.0" -ssd1306 = "0.8.4" -static_cell = { version = "2.0.0", features = ["nightly"] } -rand_core = "0.6.4" - -[features] -default = ["embassy-integrated-timers", "rt", "vectored", "zero-rtc-bss"] - -## Enable debug features in the HAL (used for development). -debug = ["esp-hal/debug"] -## Enable direct interrupt vectoring. -direct-vectoring = ["esp-hal/direct-vectoring"] -## TODO: ??? -flip-link = ["esp-hal/flip-link"] -## Enable interrupt preemption. -interrupt-preemption = ["esp-hal/interrupt-preemption"] -## Enable logging output using the `log` crate. -log = ["esp-hal/log", "esp-println/log"] -## Enable runtime support. -rt = ["esp-hal/rt-riscv"] -## Enable interrupt vectoring. -vectored = ["esp-hal/vectored"] - -#! ### Trait Implementation Feature Flags -## Enable support for asynchronous operation, with interfaces provided by -## `embedded-hal-async` and `embedded-io-async`. -async = ["esp-hal/async"] -## Implement `defmt::Format` on certain types. -defmt = ["esp-hal/defmt", "esp-println/defmt-espflash"] -## Implement the traits defined in the `1.0.0` releases of `embedded-hal` and -## `embedded-hal-nb` for the relevant peripherals. -eh1 = ["esp-hal/eh1"] -## Implement the traits defined in `embedded-io` for certain peripherals. -embedded-io = ["esp-hal/embedded-io"] -## Implement the `ufmt_write::uWrite` trait for certain peripherals. -ufmt = ["esp-hal/ufmt"] - -#! ### Memory Initialization Feature Flags -## Zero the `.bss` section of low-power memory. -zero-rtc-bss = ["esp-hal/rv-zero-rtc-bss"] -## Initialize the `.data` section of memory. -init-data = ["esp-hal/rv-init-data"] -## Initialize the `.data` section of low-power memory. -init-rtc-data = ["esp-hal/rv-init-rtc-data"] - -#! ### Embassy Feature Flags -## Enable support for `embassy`, a modern asynchronous embedded framework. -embassy = ["esp-hal/embassy"] -## Use the interrupt-mode embassy executor. -embassy-executor-interrupt = ["esp-hal/embassy-executor-interrupt"] -## Use the thread-mode embassy executor. -embassy-executor-thread = ["esp-hal/embassy-executor-thread"] -## Uses hardware timers as alarms for the executors. Using this feature -## limits the number of executors to the number of hardware alarms provided -## by the time driver. -embassy-integrated-timers = ["esp-hal/embassy-integrated-timers"] -## Enable the embassy time driver using the `SYSTIMER` peripheral. The -## `SYSTIMER` peripheral has three alarams available for use. -embassy-time-systick = ["esp-hal/embassy-time-systick", "embassy-time-driver/tick-hz-16_000_000"] -## Enable the embassy time driver using the `TIMG0` peripheral. The `TIMG0` -## peripheral has two alarms available for use. -embassy-time-timg0 = ["esp-hal/embassy-time-timg0", "embassy-time-driver/tick-hz-1_000_000"] - -[profile.release] -debug = true - -[[example]] -name = "spi_eh1_loopback" -required-features = ["eh1"] - -[[example]] -name = "spi_eh1_device_loopback" -required-features = ["eh1"] - -[[example]] -name = "embassy_hello_world" -required-features = ["embassy", "embassy-executor-thread"] - -[[example]] -name = "embassy_multiprio" -required-features = ["embassy", "embassy-executor-thread", "embassy-executor-interrupt"] - -[[example]] -name = "embassy_i2c" -required-features = ["async", "embassy", "embassy-executor-thread"] - -[[example]] -name = "embassy_serial" -required-features = ["async", "embassy", "embassy-executor-thread"] - -[[example]] -name = "embassy_spi" -required-features = ["async", "embassy", "embassy-executor-thread"] - -[[example]] -name = "embassy_wait" -required-features = ["async", "embassy", "embassy-executor-thread"] - -[[example]] -name = "embassy_rmt_tx" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_rmt_rx" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "interrupt_preemption" -required-features = ["interrupt-preemption"] - -[[example]] -name = "direct-vectoring" -required-features = ["direct-vectoring"] - -[[example]] -name = "embassy_i2s_sound" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_i2s_read" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_parl_io_tx" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_parl_io_rx" -required-features = ["embassy", "async", "embassy-executor-thread"] - -[[example]] -name = "embassy_usb_serial_jtag" -required-features = ["embassy", "async", "embassy-executor-thread"] diff --git a/esp32h2-hal/README.md b/esp32h2-hal/README.md deleted file mode 100644 index c37165f81..000000000 --- a/esp32h2-hal/README.md +++ /dev/null @@ -1,51 +0,0 @@ -# esp32h2-hal - -[![Crates.io](https://img.shields.io/crates/v/esp32h2-hal?labelColor=1C2C2E&color=C96329&logo=Rust&style=flat-square)](https://crates.io/crates/esp32h2-hal) -[![docs.rs](https://img.shields.io/docsrs/esp32h2-hal?labelColor=1C2C2E&color=C96329&logo=rust&style=flat-square)](https://docs.rs/esp32h2-hal) -![Crates.io](https://img.shields.io/crates/l/esp32h2-hal?labelColor=1C2C2E&style=flat-square) -[![Matrix](https://img.shields.io/matrix/esp-rs:matrix.org?label=join%20matrix&labelColor=1C2C2E&color=BEC5C9&logo=matrix&style=flat-square)](https://matrix.to/#/#esp-rs:matrix.org) - -`no_std` HAL for the ESP32-H2 from Espressif. - -Implements a number of the traits defined in [embedded-hal](https://github.com/rust-embedded/embedded-hal). - -This device uses the RISC-V ISA, which is officially supported by the Rust compiler via the `riscv32imac-unknown-none-elf` target. - -Please refer to the documentation for more information. - -## [Documentation] - -[documentation]: https://docs.rs/esp32h2-hal/ - -## Resources - -- [Datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-h2_datasheet_en.pdf) -- [Technical Reference Manual](https://www.espressif.com/sites/default/files/documentation/esp32-h2_technical_reference_manual_en.pdf) -- [The Rust Programming Language](https://doc.rust-lang.org/book/) -- [The Embedded Rust Book](https://docs.rust-embedded.org/book/index.html) -- [The Rust on ESP Book](https://esp-rs.github.io/book/) - -## Getting Started - -### Installing the Rust Compiler Target - -The compilation target for this device is officially supported by the mainline Rust compiler and can be installed using [rustup](https://rustup.rs/): - -```shell -rustup target add riscv32imac-unknown-none-elf -``` - -## License - -Licensed under either of: - -- Apache License, Version 2.0 ([LICENSE-APACHE](../LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) -- MIT license ([LICENSE-MIT](../LICENSE-MIT) or http://opensource.org/licenses/MIT) - -at your option. - -### Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in -the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without -any additional terms or conditions. diff --git a/esp32h2-hal/build.rs b/esp32h2-hal/build.rs deleted file mode 100644 index 023b7905b..000000000 --- a/esp32h2-hal/build.rs +++ /dev/null @@ -1,16 +0,0 @@ -use std::{env, error::Error, path::PathBuf}; - -fn main() -> Result<(), Box> { - // Put the linker script somewhere the linker can find it - let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - println!("cargo:rustc-link-search={}", out.display()); - - // Only re-run the build script when memory.x is changed, - // instead of when any part of the source code changes. - println!("cargo:rerun-if-changed=ld/memory.x"); - - #[cfg(feature = "defmt")] - println!("cargo:rustc-link-arg=-Tdefmt.x"); - - Ok(()) -} diff --git a/esp32h2-hal/examples/adc.rs b/esp32h2-hal/examples/adc.rs deleted file mode 100644 index 62b1f4d00..000000000 --- a/esp32h2-hal/examples/adc.rs +++ /dev/null @@ -1,39 +0,0 @@ -//! Connect a potentiometer to PIN2 and see the read values change when -//! rotating the shaft. Alternatively you could also connect the PIN to GND or -//! 3V3 to see the maximum and minimum raw values read. - -#![no_std] -#![no_main] - -use esp32h2_hal::{ - adc::{AdcConfig, Attenuation, ADC}, - clock::ClockControl, - gpio::IO, - peripherals::{Peripherals, ADC1}, - prelude::*, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create ADC instances - let mut adc1_config = AdcConfig::new(); - let mut pin = adc1_config.enable_pin(io.pins.gpio2.into_analog(), Attenuation::Attenuation11dB); - let mut adc1 = ADC::::new(peripherals.ADC1, adc1_config); - - let mut delay = Delay::new(&clocks); - - loop { - let pin_value: u16 = nb::block!(adc1.read(&mut pin)).unwrap(); - println!("PIN2 ADC reading = {}", pin_value); - delay.delay_ms(1500u32); - } -} diff --git a/esp32h2-hal/examples/advanced_serial.rs b/esp32h2-hal/examples/advanced_serial.rs deleted file mode 100644 index ce63d72ce..000000000 --- a/esp32h2-hal/examples/advanced_serial.rs +++ /dev/null @@ -1,67 +0,0 @@ -//! This shows how to configure UART -//! You can short the TX and RX pin and see it reads what was written. -//! Additionally you can connect a logic analzyer to TX and see how the changes -//! of the configuration change the output signal. -//! -//! The following wiring is assumed: -//! - TX => GPIO1 -//! - RX => GPIO2 - -#![no_std] -#![no_main] - -use esp32h2_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, - uart::{ - config::{Config, DataBits, Parity, StopBits}, - TxRxPins, - }, - Uart, - IO, -}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let config = Config { - baudrate: 115200, - data_bits: DataBits::DataBits8, - parity: Parity::ParityNone, - stop_bits: StopBits::STOP1, - }; - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let pins = TxRxPins::new_tx_rx( - io.pins.gpio1.into_push_pull_output(), - io.pins.gpio2.into_floating_input(), - ); - - let mut serial1 = Uart::new_with_config(peripherals.UART1, config, Some(pins), &clocks); - - timer0.start(250u64.millis()); - - println!("Start"); - loop { - serial1.write(0x42).ok(); - let read = block!(serial1.read()); - - match read { - Ok(read) => println!("Read 0x{:02x}", read), - Err(err) => println!("Error {:?}", err), - } - - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32h2-hal/examples/aes.rs b/esp32h2-hal/examples/aes.rs deleted file mode 100644 index cb900bb80..000000000 --- a/esp32h2-hal/examples/aes.rs +++ /dev/null @@ -1,85 +0,0 @@ -//! Encrypt/Decrypt a message using AES. - -#![no_std] -#![no_main] -use aes::{ - cipher::{generic_array::GenericArray, BlockDecrypt, BlockEncrypt, KeyInit}, - Aes128 as Aes128SW, -}; -use esp32h2_hal::{ - aes::{Aes, Mode}, - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - systimer::SystemTimer, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut aes = Aes::new(peripherals.AES); - - let keytext = "SUp4SeCp@sSw0rd".as_bytes(); - let plaintext = "message".as_bytes(); - - // create an array with aes128 key size - let mut keybuf = [0_u8; 16]; - keybuf[..keytext.len()].copy_from_slice(keytext); - - // create an array with aes block size - let mut block_buf = [0_u8; 16]; - block_buf[..plaintext.len()].copy_from_slice(plaintext); - - let mut block = block_buf.clone(); - let pre_hw_encrypt = SystemTimer::now(); - aes.process(&mut block, Mode::Encryption128, &keybuf); - let post_hw_encrypt = SystemTimer::now(); - println!( - "it took {} cycles for hw encrypt", - post_hw_encrypt - pre_hw_encrypt - ); - let hw_encrypted = block.clone(); - let pre_hw_decrypt = SystemTimer::now(); - aes.process(&mut block, Mode::Decryption128, &keybuf); - let post_hw_decrypt = SystemTimer::now(); - println!( - "it took {} cycles for hw decrypt", - post_hw_decrypt - pre_hw_decrypt - ); - let hw_decrypted = block; - - let key = GenericArray::from(keybuf); - let mut block = GenericArray::from(block_buf); - let cipher = Aes128SW::new(&key); - let pre_sw_encrypt = SystemTimer::now(); - cipher.encrypt_block(&mut block); - let post_sw_encrypt = SystemTimer::now(); - println!( - "it took {} cycles for sw encrypt", - post_sw_encrypt - pre_sw_encrypt - ); - let sw_encrypted = block.clone(); - let pre_sw_decrypt = SystemTimer::now(); - cipher.decrypt_block(&mut block); - let post_sw_decrypt = SystemTimer::now(); - println!( - "it took {} cycles for sw decrypt", - post_sw_decrypt - pre_sw_decrypt - ); - let sw_decrypted = block; - - assert!(eq(&sw_encrypted.into(), &hw_encrypted)); - assert!(eq(&sw_decrypted.into(), &hw_decrypted)); - - println!("done"); - - loop {} -} -fn eq(slice1: &[u8; 16], slice2: &[u8; 16]) -> bool { - slice1.iter().zip(slice2.iter()).all(|(a, b)| a == b) -} diff --git a/esp32h2-hal/examples/aes_dma.rs b/esp32h2-hal/examples/aes_dma.rs deleted file mode 100644 index 369be2e05..000000000 --- a/esp32h2-hal/examples/aes_dma.rs +++ /dev/null @@ -1,153 +0,0 @@ -//! Encrypt/Decrypt a message using AES - -#![no_std] -#![no_main] -use aes::{ - cipher::{generic_array::GenericArray, BlockDecrypt, BlockEncrypt, KeyInit}, - Aes128 as Aes128SW, -}; -use esp32h2_hal::{ - aes::{ - dma::{CipherMode, WithDmaAes}, - Aes, - Mode, - }, - clock::ClockControl, - dma::{Dma, DmaDescriptor, DmaPriority}, - peripherals::Peripherals, - prelude::*, - systimer::SystemTimer, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let mut descriptors = [DmaDescriptor::EMPTY; 1]; - let mut rx_descriptors = [DmaDescriptor::EMPTY; 1]; - - let aes = Aes::new(peripherals.AES).with_dma(dma_channel.configure( - false, - &mut descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let keytext = buffer1(); - let plaintext = buffer2(); - plaintext.copy_from_slice(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); - keytext.copy_from_slice(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); - - // create an array with aes128 key size - let mut keybuf = [0_u8; 16]; - keybuf[..keytext.len()].copy_from_slice(keytext); - - // create an array with aes block size - let mut block_buf = [0_u8; 16]; - block_buf[..plaintext.len()].copy_from_slice(plaintext); - - let hw_encrypted = buffer3(); - let pre_hw_encrypt = SystemTimer::now(); - let transfer = aes - .process( - plaintext, - hw_encrypted, - Mode::Encryption128, - CipherMode::Ecb, - keybuf, - ) - .unwrap(); - let (hw_encrypted, plaintext, aes) = transfer.wait().unwrap(); - let post_hw_encrypt = SystemTimer::now(); - println!( - "it took {} cycles for hw encrypt", - post_hw_encrypt - pre_hw_encrypt - ); - - let keytext = buffer4(); - plaintext.copy_from_slice(hw_encrypted); - keytext.copy_from_slice(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); - - let mut keybuf = [0_u8; 16]; - keybuf[..keytext.len()].copy_from_slice(keytext); - - let hw_decrypted = buffer5(); - let pre_hw_decrypt = SystemTimer::now(); - let transfer = aes - .process( - plaintext, - hw_decrypted, - Mode::Decryption128, - CipherMode::Ecb, - keybuf, - ) - .unwrap(); - let (hw_decrypted, _, _) = transfer.wait().unwrap(); - let post_hw_decrypt = SystemTimer::now(); - println!( - "it took {} cycles for hw decrypt", - post_hw_decrypt - pre_hw_decrypt - ); - - let key = GenericArray::from(keybuf); - let mut block = GenericArray::from(block_buf); - let cipher = Aes128SW::new(&key); - let pre_sw_encrypt = SystemTimer::now(); - cipher.encrypt_block(&mut block); - let post_sw_encrypt = SystemTimer::now(); - println!( - "it took {} cycles for sw encrypt", - post_sw_encrypt - pre_sw_encrypt - ); - let sw_encrypted = block.clone(); - let pre_sw_decrypt = SystemTimer::now(); - cipher.decrypt_block(&mut block); - let post_sw_decrypt = SystemTimer::now(); - println!( - "it took {} cycles for sw decrypt", - post_sw_decrypt - pre_sw_decrypt - ); - let sw_decrypted = block.clone(); - - assert!(eq(&sw_encrypted.into(), &hw_encrypted)); - assert!(eq(&sw_decrypted.into(), &hw_decrypted)); - - println!("done"); - loop {} -} - -fn buffer1() -> &'static mut [u8; 16] { - static mut BUFFER: [u8; 16] = [0u8; 16]; - unsafe { &mut BUFFER } -} - -fn buffer2() -> &'static mut [u8; 16] { - static mut BUFFER: [u8; 16] = [0u8; 16]; - unsafe { &mut BUFFER } -} - -fn buffer3() -> &'static mut [u8; 16] { - static mut BUFFER: [u8; 16] = [0u8; 16]; - unsafe { &mut BUFFER } -} - -fn buffer4() -> &'static mut [u8; 16] { - static mut BUFFER: [u8; 16] = [0u8; 16]; - unsafe { &mut BUFFER } -} - -fn buffer5() -> &'static mut [u8; 16] { - static mut BUFFER: [u8; 16] = [0u8; 16]; - unsafe { &mut BUFFER } -} - -fn eq(slice1: &[u8; 16], slice2: &[u8; 16]) -> bool { - slice1.iter().zip(slice2.iter()).all(|(a, b)| a == b) -} diff --git a/esp32h2-hal/examples/blinky.rs b/esp32h2-hal/examples/blinky.rs deleted file mode 100644 index ceb8e73bf..000000000 --- a/esp32h2-hal/examples/blinky.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! Blinks an LED -//! -//! This assumes that a LED is connected to the pin assigned to `led`. (GPIO5) - -#![no_std] -#![no_main] - -use esp32h2_hal::{clock::ClockControl, gpio::IO, peripherals::Peripherals, prelude::*, Delay}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Set GPIO5 as an output, and set its state high initially. - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut led = io.pins.gpio5.into_push_pull_output(); - - led.set_high().unwrap(); - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - loop { - led.toggle().unwrap(); - delay.delay_ms(500u32); - } -} diff --git a/esp32h2-hal/examples/blinky_erased_pins.rs b/esp32h2-hal/examples/blinky_erased_pins.rs deleted file mode 100644 index 4dc0b83bc..000000000 --- a/esp32h2-hal/examples/blinky_erased_pins.rs +++ /dev/null @@ -1,53 +0,0 @@ -//! Blinks an LED -//! -//! This assumes that LEDs are connected to GPIO3, 4 and 5. - -#![no_std] -#![no_main] - -use esp32h2_hal::{ - clock::ClockControl, - gpio::{AnyPin, Input, Output, PullDown, PushPull, IO}, - peripherals::Peripherals, - prelude::*, - Delay, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Set LED GPIOs as an output. - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let led1 = io.pins.gpio3.into_push_pull_output(); - let led2 = io.pins.gpio4.into_push_pull_output(); - let led3 = io.pins.gpio5.into_push_pull_output(); - - // Set GPIO9 as an input. - let button = io.pins.gpio9.into_pull_down_input().into(); - - // You can use `into` or `degrade` - let mut pins = [led1.into(), led2.into(), led3.degrade().into()]; - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - loop { - toggle_pins(&mut pins, &button); - delay.delay_ms(500u32); - } -} - -fn toggle_pins(leds: &mut [AnyPin>], button: &AnyPin>) { - for pin in leds.iter_mut() { - pin.toggle().unwrap(); - } - - if button.is_low().unwrap() { - esp_println::println!("Button"); - } -} diff --git a/esp32h2-hal/examples/clock_monitor.rs b/esp32h2-hal/examples/clock_monitor.rs deleted file mode 100644 index d0febcbae..000000000 --- a/esp32h2-hal/examples/clock_monitor.rs +++ /dev/null @@ -1,65 +0,0 @@ -//! This demos a simple monitor for the XTAL frequency, by relying on a special -//! feature of the TIMG0 (Timer Group 0). This feature counts the number of XTAL -//! clock cycles within a given number of RTC_SLOW_CLK cycles. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32h2_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, - Rtc, -}; -use esp_backtrace as _; - -static RTC: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rtc = Rtc::new(peripherals.LPWR); - rtc.rwdt.start(2000u64.millis()); - rtc.rwdt.listen(); - - esp_println::println!( - "{: <10} XTAL frequency: {} MHz", - "[Expected]", - clocks.xtal_clock.to_MHz() - ); - - interrupt::enable( - peripherals::Interrupt::LP_WDT, - interrupt::Priority::Priority1, - ) - .unwrap(); - - critical_section::with(|cs| { - RTC.borrow_ref_mut(cs).replace(rtc); - }); - - loop {} -} - -#[interrupt] -fn LP_WDT() { - critical_section::with(|cs| { - let mut rtc = RTC.borrow(cs).borrow_mut(); - let rtc = rtc.as_mut().unwrap(); - - esp_println::println!( - "{: <10} XTAL frequency: {} MHz", - "[Monitor]", - rtc.estimate_xtal_frequency() - ); - - rtc.rwdt.clear_interrupt(); - }); -} diff --git a/esp32h2-hal/examples/crc.rs b/esp32h2-hal/examples/crc.rs deleted file mode 100644 index fb93e978d..000000000 --- a/esp32h2-hal/examples/crc.rs +++ /dev/null @@ -1,96 +0,0 @@ -//! This shows example usage of the CRC functions in ROM - -#![no_std] -#![no_main] - -use core::fmt::Write; - -use esp32h2_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - rom::{crc, md5}, - timer::TimerGroup, - Uart, -}; -use esp_backtrace as _; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - timer0.start(1u64.secs()); - - let data = "123456789"; - let sentence = "The quick brown fox jumps over a lazy dog"; - - writeln!( - uart0, - "Performing CRC calculations on test string \"{data}\"" - ) - .unwrap(); - - loop { - let crc_hdlc = crc::crc32_le(!0xffffffff, data.as_ref()); - let crc_bzip2 = crc::crc32_be(!0xffffffff, data.as_ref()); - let crc_mpeg2 = !crc::crc32_be(!0xffffffff, data.as_ref()); - let crc_cksum = crc::crc32_be(!0, data.as_ref()); - let crc_kermit = !crc::crc16_le(!0, data.as_ref()); - let crc_genibus = crc::crc16_be(!0xffff, data.as_ref()); - let crc_rohc = !crc::crc8_le(!0xff, data.as_ref()); - let crc_smbus = !crc::crc8_be(!0, data.as_ref()); - - assert_eq!(crc_hdlc, 0xcbf43926); - assert_eq!(crc_bzip2, 0xfc891918); - assert_eq!(crc_mpeg2, 0x0376e6e7); - assert_eq!(crc_cksum, 0x765e7680); - assert_eq!(crc_kermit, 0x2189); - assert_eq!(crc_genibus, 0xd64e); - assert_eq!(crc_rohc, 0xd0); - assert_eq!(crc_smbus, 0xf4); - - // Hash the sentence one word at a time to *really* test the context - // Use Peekable while iter_intersperse is unstable - let mut md5_ctx = md5::Context::new(); - let mut it = sentence.split_whitespace().peekable(); - while let Some(word) = it.next() { - md5_ctx.consume(word); - if it.peek().is_some() { - md5_ctx.consume(" "); - } - } - let md5_digest = md5_ctx.compute(); - - assert_eq!( - md5_digest, - md5::Digest([ - 0x30, 0xde, 0xd8, 0x07, 0xd6, 0x5e, 0xe0, 0x37, 0x0f, 0xc6, 0xd7, 0x3d, 0x6a, 0xb5, - 0x5a, 0x95 - ]) - ); - - writeln!( - uart0, - "{:08x} {:08x} {:08x} {:08x} {:04x} {:04x} {:02x} {:02x} {}", - crc_hdlc, - crc_bzip2, - crc_mpeg2, - crc_cksum, - crc_kermit, - crc_genibus, - crc_rohc, - crc_smbus, - md5_digest - ) - .unwrap(); - - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32h2-hal/examples/embassy_hello_world.rs b/esp32h2-hal/examples/embassy_hello_world.rs deleted file mode 100644 index 071c49df1..000000000 --- a/esp32h2-hal/examples/embassy_hello_world.rs +++ /dev/null @@ -1,48 +0,0 @@ -//! embassy hello world -//! -//! This is an example of running the embassy executor with multiple tasks -//! concurrently. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32h2_hal::{clock::ClockControl, embassy, peripherals::Peripherals, prelude::*}; -use esp_backtrace as _; - -#[embassy_executor::task] -async fn run() { - loop { - esp_println::println!("Hello world from embassy using esp-hal-async!"); - Timer::after(Duration::from_millis(1_000)).await; - } -} - -#[main] -async fn main(spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32h2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32h2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - spawner.spawn(run()).ok(); - - loop { - esp_println::println!("Bing!"); - Timer::after(Duration::from_millis(5_000)).await; - } -} diff --git a/esp32h2-hal/examples/embassy_i2c.rs b/esp32h2-hal/examples/embassy_i2c.rs deleted file mode 100644 index 78c201490..000000000 --- a/esp32h2-hal/examples/embassy_i2c.rs +++ /dev/null @@ -1,67 +0,0 @@ -//! Embassy I2C -//! -//! Folowing pins are used: -//! SDA GPIO1 -//! SCL GPIO2 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This is an example of running the embassy executor with IC2. It uses an -//! LIS3DH to get accelerometer data. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32h2_hal::{ - clock::ClockControl, - embassy, - i2c::I2C, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; -use lis3dh_async::{Lis3dh, Range, SlaveAddr}; - -#[main] -async fn main(_spawner: Spawner) { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32h2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32h2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let i2c0 = I2C::new( - peripherals.I2C0, - io.pins.gpio1, - io.pins.gpio2, - 400u32.kHz(), - &clocks, - ); - - let mut lis3dh = Lis3dh::new_i2c(i2c0, SlaveAddr::Alternate).await.unwrap(); - lis3dh.set_range(Range::G8).await.unwrap(); - - loop { - let norm = lis3dh.accel_norm().await.unwrap(); - esp_println::println!("X: {:+.5} Y: {:+.5} Z: {:+.5}", norm.x, norm.y, norm.z); - - Timer::after(Duration::from_millis(100)).await; - } -} diff --git a/esp32h2-hal/examples/embassy_i2s_read.rs b/esp32h2-hal/examples/embassy_i2s_read.rs deleted file mode 100644 index f77f44fd4..000000000 --- a/esp32h2-hal/examples/embassy_i2s_read.rs +++ /dev/null @@ -1,99 +0,0 @@ -//! This shows how to continuously receive data via I2S -//! -//! Pins used -//! MCLK GPIO4 -//! BCLK GPIO1 -//! WS GPIO2 -//! DIN GPIO5 -//! -//! Without an additional I2S source device you can connect 3V3 or GND to DIN to -//! read 0 or 0xFF or connect DIN to WS to read two different values -//! -//! You can also inspect the MCLK, BCLK and WS with a logic analyzer - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use esp32h2_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - embassy, - i2s::{asynch::*, DataFormat, I2s, Standard}, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -#[main] -async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32h2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32h2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (_, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(0, 4092 * 4); - - let i2s = I2s::new( - peripherals.I2S0, - Standard::Philips, - DataFormat::Data16Channel16, - 44100u32.Hz(), - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - &clocks, - ) - .with_mclk(io.pins.gpio4); - - let i2s_rx = i2s - .i2s_rx - .with_bclk(io.pins.gpio1) - .with_ws(io.pins.gpio2) - .with_din(io.pins.gpio5) - .build(); - - let buffer = rx_buffer; - println!("Start"); - - let mut data = [0u8; 5000]; - let mut transaction = i2s_rx.read_dma_circular_async(buffer).unwrap(); - loop { - let avail = transaction.available().await; - println!("available {}", avail); - - let count = transaction.pop(&mut data).await.unwrap(); - println!( - "got {} bytes, {:x?}..{:x?}", - count, - &data[..10], - &data[count - 10..count] - ); - } -} diff --git a/esp32h2-hal/examples/embassy_i2s_sound.rs b/esp32h2-hal/examples/embassy_i2s_sound.rs deleted file mode 100644 index aaaa24f10..000000000 --- a/esp32h2-hal/examples/embassy_i2s_sound.rs +++ /dev/null @@ -1,136 +0,0 @@ -//! This shows how to transmit data continuously via I2S -//! -//! Pins used -//! MCLK GPIO4 -//! BCLK GPIO1 -//! WS GPIO2 -//! DOUT GPIO3 -//! -//! Without an additional I2S sink device you can inspect the MCLK, BCLK, WS and -//! DOUT with a logic analyzer -//! -//! You can also connect e.g. a PCM510x to hear an annoying loud sine tone (full -//! scale), so turn down the volume before running this example. -//! -//! Wiring is like this -//! -//! | Pin | Connected to | -//! |-------|-----------------| -//! | BCK | GPIO1 | -//! | DIN | GPIO3 | -//! | LRCK | GPIO2 | -//! | SCK | Gnd | -//! | GND | Gnd | -//! | VIN | +3V3 | -//! | FLT | Gnd | -//! | FMT | Gnd | -//! | DEMP | Gnd | -//! | XSMT | +3V3 | - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use esp32h2_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - embassy, - i2s::{asynch::*, DataFormat, I2s, Standard}, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -const SINE: [i16; 64] = [ - 0, 3211, 6392, 9511, 12539, 15446, 18204, 20787, 23169, 25329, 27244, 28897, 30272, 31356, - 32137, 32609, 32767, 32609, 32137, 31356, 30272, 28897, 27244, 25329, 23169, 20787, 18204, - 15446, 12539, 9511, 6392, 3211, 0, -3211, -6392, -9511, -12539, -15446, -18204, -20787, -23169, - -25329, -27244, -28897, -30272, -31356, -32137, -32609, -32767, -32609, -32137, -31356, -30272, - -28897, -27244, -25329, -23169, -20787, -18204, -15446, -12539, -9511, -6392, -3211, -]; - -#[main] -async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32h2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32h2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (tx_buffer, mut tx_descriptors, _, mut rx_descriptors) = dma_buffers!(32000, 0); - - let i2s = I2s::new( - peripherals.I2S0, - Standard::Philips, - DataFormat::Data16Channel16, - 44100u32.Hz(), - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - &clocks, - ) - .with_mclk(io.pins.gpio4); - - let i2s_tx = i2s - .i2s_tx - .with_bclk(io.pins.gpio1) - .with_ws(io.pins.gpio2) - .with_dout(io.pins.gpio3) - .build(); - - let data = - unsafe { core::slice::from_raw_parts(&SINE as *const _ as *const u8, SINE.len() * 2) }; - - let buffer = tx_buffer; - let mut idx = 0; - for i in 0..usize::min(data.len(), buffer.len()) { - buffer[i] = data[idx]; - - idx += 1; - - if idx >= data.len() { - idx = 0; - } - } - - let mut filler = [0u8; 10000]; - let mut idx = 32000 % data.len(); - - println!("Start"); - let mut transaction = i2s_tx.write_dma_circular_async(buffer).unwrap(); - loop { - for i in 0..filler.len() { - filler[i] = data[(idx + i) % data.len()]; - } - println!("Next"); - - let written = transaction.push(&filler).await.unwrap(); - idx = (idx + written) % data.len(); - println!("written {}", written); - } -} diff --git a/esp32h2-hal/examples/embassy_multiprio.rs b/esp32h2-hal/examples/embassy_multiprio.rs deleted file mode 100644 index e66b467e0..000000000 --- a/esp32h2-hal/examples/embassy_multiprio.rs +++ /dev/null @@ -1,100 +0,0 @@ -//! This example shows how to use the interrupt executors to prioritize some -//! tasks over others. -//! -//! The example creates three tasks: -//! - A low priority task that is not actually async, but simulates some -//! blocking work. This task will run for 5 seconds, then sleep for 5 -//! seconds. -//! - A low priority task that is actually async, but will not be able to run -//! while the blocking task is running. -//! - A high priority task that prints something every second. The example -//! demonstrates that this task will continue to run even while the low -//! priority blocking task is running. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Instant, Ticker, Timer}; -use esp32h2_hal::{ - clock::ClockControl, - embassy::{ - self, - executor::{FromCpu1, InterruptExecutor}, - }, - interrupt::Priority, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; -use esp_println::println; - -static INT_EXECUTOR_0: InterruptExecutor = InterruptExecutor::new(); - -#[interrupt] -fn FROM_CPU_INTR1() { - unsafe { INT_EXECUTOR_0.on_interrupt() } -} - -/// Periodically print something. -#[embassy_executor::task] -async fn high_prio() { - println!("Starting high_prio()"); - let mut ticker = Ticker::every(Duration::from_secs(1)); - loop { - println!("High priority ticks"); - ticker.next().await; - } -} - -/// Simulates some blocking (badly behaving) task. -#[embassy_executor::task] -async fn low_prio_blocking() { - println!("Starting low-priority task that isn't actually async"); - loop { - println!("Doing some long and complicated calculation"); - let start = Instant::now(); - while start.elapsed() < Duration::from_secs(5) {} - println!("Calculation finished"); - Timer::after(Duration::from_secs(5)).await; - } -} - -/// A well-behaved, but starved async task. -#[embassy_executor::task] -async fn low_prio_async() { - println!("Starting low-priority task that will not be able to run while the blocking task is running"); - let mut ticker = Ticker::every(Duration::from_secs(1)); - loop { - println!("Low priority ticks"); - ticker.next().await; - } -} - -#[main] -async fn main(low_prio_spawner: Spawner) { - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32h2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32h2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let spawner = INT_EXECUTOR_0.start(Priority::Priority2); - spawner.must_spawn(high_prio()); - - println!("Spawning low-priority tasks"); - low_prio_spawner.must_spawn(low_prio_async()); - low_prio_spawner.must_spawn(low_prio_blocking()); -} diff --git a/esp32h2-hal/examples/embassy_parl_io_rx.rs b/esp32h2-hal/examples/embassy_parl_io_rx.rs deleted file mode 100644 index 2d2ea1aa7..000000000 --- a/esp32h2-hal/examples/embassy_parl_io_rx.rs +++ /dev/null @@ -1,78 +0,0 @@ -//! This shows using Parallel IO to input 4 bit parallel data at 1MHz clock -//! rate. -//! -//! Uses GPIO 1, 2, 3 and 4 as the data pins. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32h2_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - embassy, - gpio::IO, - parl_io::{BitPackOrder, NoClkPin, ParlIoRxOnly, RxFourBits}, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; -use esp_println::println; - -#[main] -async fn main(_spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32h2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32h2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let (_, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(0, 32000); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let rx_pins = RxFourBits::new(io.pins.gpio1, io.pins.gpio2, io.pins.gpio3, io.pins.gpio4); - - let parl_io = ParlIoRxOnly::new( - peripherals.PARL_IO, - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - 1u32.MHz(), - &clocks, - ) - .unwrap(); - - let mut parl_io_rx = parl_io - .rx - .with_config(rx_pins, NoClkPin, BitPackOrder::Msb, Some(0xfff)) - .unwrap(); - - let buffer = rx_buffer; - loop { - parl_io_rx.read_dma_async(buffer).await.unwrap(); - println!("Received: {:02x?} ...", &buffer[..30]); - - Timer::after(Duration::from_millis(500)).await; - } -} diff --git a/esp32h2-hal/examples/embassy_parl_io_tx.rs b/esp32h2-hal/examples/embassy_parl_io_tx.rs deleted file mode 100644 index 62026034b..000000000 --- a/esp32h2-hal/examples/embassy_parl_io_tx.rs +++ /dev/null @@ -1,103 +0,0 @@ -//! This shows using Parallel IO to output 4 bit parallel data at 1MHz clock -//! rate. -//! -//! Uses GPIO 1, 2, 3 and 4 as the data pins. -//! GPIO 5 as the "valid pin" (driven high during an active transfer) and GPIO -//! 6 as the clock signal output. -//! -//! You can use a logic analyzer to see how the pins are used. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32h2_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - embassy, - gpio::IO, - parl_io::{ - BitPackOrder, - ClkOutPin, - ParlIoTxOnly, - SampleEdge, - TxFourBits, - TxPinConfigWithValidPin, - }, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; -use esp_println::println; - -#[main] -async fn main(_spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32h2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32h2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let (tx_buffer, mut tx_descriptors, _, mut rx_descriptors) = dma_buffers!(32000, 0); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let tx_pins = TxFourBits::new(io.pins.gpio1, io.pins.gpio2, io.pins.gpio3, io.pins.gpio4); - - let pin_conf = TxPinConfigWithValidPin::new(tx_pins, io.pins.gpio5); - - let parl_io = ParlIoTxOnly::new( - peripherals.PARL_IO, - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - 1u32.MHz(), - &clocks, - ) - .unwrap(); - - let clock_pin = ClkOutPin::new(io.pins.gpio6); - - let mut parl_io_tx = parl_io - .tx - .with_config( - pin_conf, - clock_pin, - 0, - SampleEdge::Normal, - BitPackOrder::Msb, - ) - .unwrap(); - - let buffer = tx_buffer; - for i in 0..buffer.len() { - buffer[i] = (i % 255) as u8; - } - - loop { - parl_io_tx.write_dma_async(buffer).await.unwrap(); - println!("Transferred {} bytes", buffer.len()); - - Timer::after(Duration::from_millis(500)).await; - } -} diff --git a/esp32h2-hal/examples/embassy_rmt_rx.rs b/esp32h2-hal/examples/embassy_rmt_rx.rs deleted file mode 100644 index df20174dd..000000000 --- a/esp32h2-hal/examples/embassy_rmt_rx.rs +++ /dev/null @@ -1,110 +0,0 @@ -//! Demonstrates decoding pulse sequences with RMT -//! This uses the boot button as input - press the button a couple of -//! times to generate a pulse sequence and then wait for the idle timeout to see -//! the recorded pulse sequence - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use esp32h2_hal::{ - clock::ClockControl, - embassy::{self}, - peripherals::Peripherals, - prelude::*, - rmt::{asynch::RxChannelAsync, PulseCode, RxChannelConfig, RxChannelCreator}, - Rmt, - IO, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -const WIDTH: usize = 80; - -#[main] -async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32h2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32h2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let rmt = Rmt::new(peripherals.RMT, 8u32.MHz(), &clocks).unwrap(); - - let mut channel = rmt - .channel2 - .configure( - io.pins.gpio9, - RxChannelConfig { - clk_divider: 255, - idle_threshold: 10000, - ..RxChannelConfig::default() - }, - ) - .unwrap(); - - let mut data = [PulseCode { - level1: true, - length1: 1, - level2: false, - length2: 1, - }; 48]; - - loop { - println!("receive"); - channel.receive(&mut data).await.unwrap(); - println!("received"); - let mut total = 0usize; - for entry in &data[..data.len()] { - if entry.length1 == 0 { - break; - } - total += entry.length1 as usize; - - if entry.length2 == 0 { - break; - } - total += entry.length2 as usize; - } - - for entry in &data[..data.len()] { - if entry.length1 == 0 { - break; - } - - let count = WIDTH / (total / entry.length1 as usize); - let c = if entry.level1 { '-' } else { '_' }; - for _ in 0..count + 1 { - print!("{}", c); - } - - if entry.length2 == 0 { - break; - } - - let count = WIDTH / (total / entry.length2 as usize); - let c = if entry.level2 { '-' } else { '_' }; - for _ in 0..count + 1 { - print!("{}", c); - } - } - - println!(); - } -} diff --git a/esp32h2-hal/examples/embassy_rmt_tx.rs b/esp32h2-hal/examples/embassy_rmt_tx.rs deleted file mode 100644 index 285348bc5..000000000 --- a/esp32h2-hal/examples/embassy_rmt_tx.rs +++ /dev/null @@ -1,79 +0,0 @@ -//! Demonstrates generating pulse sequences with RMT -//! Connect a logic analyzer to GPIO1 to see the generated pulses. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32h2_hal::{ - clock::ClockControl, - embassy, - peripherals::Peripherals, - prelude::*, - rmt::{asynch::TxChannelAsync, PulseCode, TxChannelConfig, TxChannelCreator}, - Rmt, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -#[main] -async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32h2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32h2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let rmt = Rmt::new(peripherals.RMT, 8u32.MHz(), &clocks).unwrap(); - - let mut channel = rmt - .channel0 - .configure( - io.pins.gpio1.into_push_pull_output(), - TxChannelConfig { - clk_divider: 255, - ..TxChannelConfig::default() - }, - ) - .unwrap(); - - let mut data = [PulseCode { - level1: true, - length1: 200, - level2: false, - length2: 50, - }; 20]; - - data[data.len() - 2] = PulseCode { - level1: true, - length1: 3000, - level2: false, - length2: 500, - }; - data[data.len() - 1] = PulseCode::default(); - - loop { - println!("transmit"); - channel.transmit(&data).await.unwrap(); - println!("transmitted\n"); - Timer::after(Duration::from_millis(500)).await; - } -} diff --git a/esp32h2-hal/examples/embassy_serial.rs b/esp32h2-hal/examples/embassy_serial.rs deleted file mode 100644 index 759650517..000000000 --- a/esp32h2-hal/examples/embassy_serial.rs +++ /dev/null @@ -1,96 +0,0 @@ -//! embassy serial -//! -//! This is an example of running the embassy executor and asynchronously -//! writing to and reading from uart - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_sync::{blocking_mutex::raw::NoopRawMutex, signal::Signal}; -use esp32h2_hal::{ - clock::ClockControl, - embassy, - peripherals::{Peripherals, UART0}, - prelude::*, - uart::{config::AtCmdConfig, UartRx, UartTx}, - Uart, -}; -use esp_backtrace as _; -use static_cell::make_static; - -// rx_fifo_full_threshold -const READ_BUF_SIZE: usize = 64; -// EOT (CTRL-D) -const AT_CMD: u8 = 0x04; - -#[embassy_executor::task] -async fn writer(mut tx: UartTx<'static, UART0>, signal: &'static Signal) { - use core::fmt::Write; - embedded_io_async::Write::write( - &mut tx, - b"Hello async serial. Enter something ended with EOT (CTRL-D).\r\n", - ) - .await - .unwrap(); - embedded_io_async::Write::flush(&mut tx).await.unwrap(); - loop { - let bytes_read = signal.wait().await; - signal.reset(); - write!(&mut tx, "\r\n-- received {} bytes --\r\n", bytes_read).unwrap(); - embedded_io_async::Write::flush(&mut tx).await.unwrap(); - } -} - -#[embassy_executor::task] -async fn reader(mut rx: UartRx<'static, UART0>, signal: &'static Signal) { - const MAX_BUFFER_SIZE: usize = 10 * READ_BUF_SIZE + 16; - - let mut rbuf: [u8; MAX_BUFFER_SIZE] = [0u8; MAX_BUFFER_SIZE]; - let mut offset = 0; - loop { - let r = embedded_io_async::Read::read(&mut rx, &mut rbuf[offset..]).await; - match r { - Ok(len) => { - offset += len; - esp_println::println!("Read: {len}, data: {:?}", &rbuf[..offset]); - offset = 0; - signal.signal(len); - } - Err(e) => esp_println::println!("RX Error: {:?}", e), - } - } -} - -#[main] -async fn main(spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32h2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32h2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - uart0.set_at_cmd(AtCmdConfig::new(None, None, None, AT_CMD, None)); - uart0 - .set_rx_fifo_full_threshold(READ_BUF_SIZE as u16) - .unwrap(); - let (tx, rx) = uart0.split(); - - let signal = &*make_static!(Signal::new()); - - spawner.spawn(reader(rx, &signal)).ok(); - spawner.spawn(writer(tx, &signal)).ok(); -} diff --git a/esp32h2-hal/examples/embassy_spi.rs b/esp32h2-hal/examples/embassy_spi.rs deleted file mode 100644 index d60ae7edb..000000000 --- a/esp32h2-hal/examples/embassy_spi.rs +++ /dev/null @@ -1,87 +0,0 @@ -//! Embassy SPI -//! -//! Folowing pins are used: -//! SCLK GPIO1 -//! MISO GPIO2 -//! MOSI GPIO3 -//! CS GPIO11 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. -//! -//! This is an example of running the embassy executor with SPI. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32h2_hal::{ - clock::ClockControl, - dma::{DmaPriority, *}, - dma_descriptors, - embassy, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{prelude::*, Spi}, - SpiMode, - }, - IO, -}; -use esp_backtrace as _; - -#[main] -async fn main(_spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32h2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32h2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio1; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio3; - let cs = io.pins.gpio11; - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (mut descriptors, mut rx_descriptors) = dma_descriptors!(32000); - - let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) - .with_dma(dma_channel.configure( - false, - &mut descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let send_buffer = [0, 1, 2, 3, 4, 5, 6, 7]; - loop { - let mut buffer = [0; 8]; - esp_println::println!("Sending bytes"); - embedded_hal_async::spi::SpiBus::transfer(&mut spi, &mut buffer, &send_buffer) - .await - .unwrap(); - esp_println::println!("Bytes recieved: {:?}", buffer); - Timer::after(Duration::from_millis(5_000)).await; - } -} diff --git a/esp32h2-hal/examples/embassy_usb_serial_jtag.rs b/esp32h2-hal/examples/embassy_usb_serial_jtag.rs deleted file mode 100644 index ec2e83333..000000000 --- a/esp32h2-hal/examples/embassy_usb_serial_jtag.rs +++ /dev/null @@ -1,88 +0,0 @@ -//! This shows how to read and write text via USB Serial/JTAG using embassy. -//! You need to connect via the Serial/JTAG interface to see any output. -//! Most dev-kits use a USB-UART-bridge - in that case you won't see any output. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_sync::{blocking_mutex::raw::NoopRawMutex, signal::Signal}; -use esp32h2_hal::{ - clock::ClockControl, - embassy, - peripherals::Peripherals, - prelude::*, - UsbSerialJtag, -}; -use esp_backtrace as _; -use esp_hal::usb_serial_jtag::{UsbSerialJtagRx, UsbSerialJtagTx}; -use static_cell::make_static; - -const MAX_BUFFER_SIZE: usize = 512; - -#[embassy_executor::task] -async fn writer( - mut tx: UsbSerialJtagTx<'static>, - signal: &'static Signal>, -) { - use core::fmt::Write; - embedded_io_async::Write::write_all( - &mut tx, - b"Hello async USB Serial JTAG. Type something.\r\n", - ) - .await - .unwrap(); - loop { - let message = signal.wait().await; - signal.reset(); - write!(&mut tx, "-- received '{}' --\r\n", message).unwrap(); - embedded_io_async::Write::flush(&mut tx).await.unwrap(); - } -} - -#[embassy_executor::task] -async fn reader( - mut rx: UsbSerialJtagRx<'static>, - signal: &'static Signal>, -) { - let mut rbuf = [0u8; MAX_BUFFER_SIZE]; - loop { - let r = embedded_io_async::Read::read(&mut rx, &mut rbuf).await; - match r { - Ok(len) => { - let mut string_buffer: heapless::Vec<_, MAX_BUFFER_SIZE> = heapless::Vec::new(); - string_buffer.extend_from_slice(&rbuf[..len]).unwrap(); - signal.signal(heapless::String::from_utf8(string_buffer).unwrap()); - } - Err(e) => esp_println::println!("RX Error: {:?}", e), - } - } -} - -#[main] -async fn main(spawner: Spawner) -> () { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32h2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32h2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let (tx, rx) = UsbSerialJtag::new(peripherals.USB_DEVICE).split(); - - let signal = &*make_static!(Signal::new()); - - spawner.spawn(reader(rx, &signal)).unwrap(); - spawner.spawn(writer(tx, &signal)).unwrap(); -} diff --git a/esp32h2-hal/examples/embassy_wait.rs b/esp32h2-hal/examples/embassy_wait.rs deleted file mode 100644 index 23a793b1c..000000000 --- a/esp32h2-hal/examples/embassy_wait.rs +++ /dev/null @@ -1,44 +0,0 @@ -//! embassy wait -//! -//! This is an example of asynchronously `Wait`ing for a pin state to change. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use embedded_hal_async::digital::Wait; -use esp32h2_hal::{clock::ClockControl, embassy, peripherals::Peripherals, prelude::*, IO}; -use esp_backtrace as _; - -#[main] -async fn main(_spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32h2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32h2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - // GPIO 9 as input - let mut input = io.pins.gpio9.into_pull_down_input(); - - loop { - esp_println::println!("Waiting..."); - input.wait_for_rising_edge().await.unwrap(); - esp_println::println!("Ping!"); - Timer::after(Duration::from_millis(100)).await; - } -} diff --git a/esp32h2-hal/examples/etm_blinky_systimer.rs b/esp32h2-hal/examples/etm_blinky_systimer.rs deleted file mode 100644 index 1c3b9b65d..000000000 --- a/esp32h2-hal/examples/etm_blinky_systimer.rs +++ /dev/null @@ -1,44 +0,0 @@ -//! Control LED on GPIO 1 by the systimer via ETM - -#![no_std] -#![no_main] - -use esp32h2_hal::{ - clock::ClockControl, - etm::Etm, - gpio::{etm::GpioEtmChannels, IO}, - peripherals::Peripherals, - prelude::*, - systimer::{etm::SysTimerEtmEvent, SystemTimer}, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let syst = SystemTimer::new(peripherals.SYSTIMER); - let mut alarm0 = syst.alarm0.into_periodic(); - alarm0.set_period(1u32.secs()); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut led = io.pins.gpio1.into_push_pull_output(); - - // setup ETM - let gpio_ext = GpioEtmChannels::new(peripherals.GPIO_SD); - let led_task = gpio_ext.channel0_task.toggle(&mut led); - - let timer_event = SysTimerEtmEvent::new(&mut alarm0); - - let etm = Etm::new(peripherals.SOC_ETM); - let channel0 = etm.channel0; - - // make sure the configured channel doesn't get dropped - dropping it will - // disable the channel - let _configured_channel = channel0.setup(&timer_event, &led_task); - - // the LED is controlled by the timer without involving the CPU - loop {} -} diff --git a/esp32h2-hal/examples/etm_gpio.rs b/esp32h2-hal/examples/etm_gpio.rs deleted file mode 100644 index 470e344ab..000000000 --- a/esp32h2-hal/examples/etm_gpio.rs +++ /dev/null @@ -1,41 +0,0 @@ -//! Control LED on GPIO 1 by the BOOT-BUTTON via ETM - -#![no_std] -#![no_main] - -use esp32h2_hal::{ - clock::ClockControl, - etm::Etm, - gpio::{etm::GpioEtmChannels, IO}, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut led = io.pins.gpio1.into_push_pull_output(); - let button = io.pins.gpio9.into_pull_down_input(); - - led.set_high().unwrap(); - - // setup ETM - let gpio_ext = GpioEtmChannels::new(peripherals.GPIO_SD); - let led_task = gpio_ext.channel0_task.toggle(&mut led); - let button_event = gpio_ext.channel0_event.falling_edge(button); - - let etm = Etm::new(peripherals.SOC_ETM); - let channel0 = etm.channel0; - - // make sure the configured channel doesn't get dropped - dropping it will - // disable the channel - let _configured_channel = channel0.setup(&button_event, &led_task); - - // the LED is controlled by the button without involving the CPU - loop {} -} diff --git a/esp32h2-hal/examples/gpio_interrupt.rs b/esp32h2-hal/examples/gpio_interrupt.rs deleted file mode 100644 index 9fd41c579..000000000 --- a/esp32h2-hal/examples/gpio_interrupt.rs +++ /dev/null @@ -1,60 +0,0 @@ -//! GPIO interrupt -//! -//! This prints "Interrupt" when the boot button is pressed. -//! It also blinks an LED like the blinky example. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32h2_hal::{ - clock::ClockControl, - gpio::{Event, Gpio9, Input, PullDown, IO}, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, - Delay, -}; -use esp_backtrace as _; - -static BUTTON: Mutex>>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Set GPIO5 as an output - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut led = io.pins.gpio5.into_push_pull_output(); - - // Set GPIO9 as an input - let mut button = io.pins.gpio9.into_pull_down_input(); - button.listen(Event::FallingEdge); - - critical_section::with(|cs| BUTTON.borrow_ref_mut(cs).replace(button)); - - interrupt::enable(peripherals::Interrupt::GPIO, interrupt::Priority::Priority3).unwrap(); - - let mut delay = Delay::new(&clocks); - loop { - led.toggle().unwrap(); - delay.delay_ms(500u32); - } -} - -#[interrupt] -fn GPIO() { - critical_section::with(|cs| { - esp_println::println!("Interrupt"); - - BUTTON - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .clear_interrupt(); - }); -} diff --git a/esp32h2-hal/examples/hello_rgb.rs b/esp32h2-hal/examples/hello_rgb.rs deleted file mode 100644 index 6fe7d9580..000000000 --- a/esp32h2-hal/examples/hello_rgb.rs +++ /dev/null @@ -1,65 +0,0 @@ -//! //! RGB LED Demo -//! -//! This example drives an SK68XX RGB LED that is connected to the GPIO8 pin. -//! A RGB LED is connected to that pin on the ESP32-H2-DevKitM-1 and board. -//! -//! The demo will leverage the [`smart_leds`](https://crates.io/crates/smart-leds) -//! crate functionality to circle through the HSV hue color space (with -//! saturation and value both at 255). Additionally, we apply a gamma correction -//! and limit the brightness to 10 (out of 255). -#![no_std] -#![no_main] - -use esp32h2_hal::{clock::ClockControl, peripherals, prelude::*, rmt::Rmt, Delay, IO}; -use esp_backtrace as _; -use esp_hal_smartled::{smartLedBuffer, SmartLedsAdapter}; -use smart_leds::{ - brightness, - gamma, - hsv::{hsv2rgb, Hsv}, - SmartLedsWrite, -}; - -#[entry] -fn main() -> ! { - let peripherals = peripherals::Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Configure RMT peripheral globally - let rmt = Rmt::new(peripherals.RMT, 32u32.MHz(), &clocks).unwrap(); - - // We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can - // be used directly with all `smart_led` implementations - let rmt_buffer = smartLedBuffer!(1); - let mut led = SmartLedsAdapter::new(rmt.channel0, io.pins.gpio8, rmt_buffer, &clocks); - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - let mut color = Hsv { - hue: 0, - sat: 255, - val: 255, - }; - let mut data; - - loop { - // Iterate over the rainbow! - for hue in 0..=255 { - color.hue = hue; - // Convert from the HSV color space (where we can easily transition from one - // color to the other) to the RGB color space that we can then send to the LED - data = [hsv2rgb(color)]; - // When sending to the LED, we do a gamma correction first (see smart_leds - // documentation for details) and then limit the brightness to 10 out of 255 so - // that the output it's not too bright. - led.write(brightness(gamma(data.iter().cloned()), 10)) - .unwrap(); - delay.delay_ms(20u8); - } - } -} diff --git a/esp32h2-hal/examples/hello_world.rs b/esp32h2-hal/examples/hello_world.rs deleted file mode 100644 index 8886f5538..000000000 --- a/esp32h2-hal/examples/hello_world.rs +++ /dev/null @@ -1,35 +0,0 @@ -//! This shows how to write text to uart0. -//! You can see the output with `espflash` if you provide the `--monitor` option - -#![no_std] -#![no_main] - -use core::fmt::Write; - -use esp32h2_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, - Uart, -}; -use esp_backtrace as _; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - timer0.start(1u64.secs()); - - loop { - writeln!(uart0, "Hello world!").unwrap(); - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32h2-hal/examples/hmac.rs b/esp32h2-hal/examples/hmac.rs deleted file mode 100644 index a73941f3e..000000000 --- a/esp32h2-hal/examples/hmac.rs +++ /dev/null @@ -1,121 +0,0 @@ -//! Demonstrates the use of the HMAC peripheral and compares the speed of -//! hardware-accelerated and pure software hashing. -//! -//! # Writing key -//! Before using the HMAC accelerator in upstream mode, you first need to -//! prepare a secret 256-bit HMAC key and burn the key to an empty eFuse block. -//! -//! ## ⚠️ Before writing ⚠️ -//! - From the factory, the eFuse keyblocks are programmed to be 32-byte 0x00. -//! - This example is programmed to use this value so you can skip this step if -//! you don't want to burn an eFuse key. -//! - If you skip the skip burning a custom key, you still need to [burn the -//! purpose](#burn-key-purpose). -//! - [Read more about eFuses](https://docs.espressif.com/projects/esptool/en/latest/esp32h2/espefuse/index.html) -//! -//! ## Burn key purpose -//! You first need to burn the efuse key purpose for the specified key below -//! (Default Key0). Purposes: -//! -//! | Purpose | Mode | Value | Description | -//! |--------------------------------|------------|-------|-----------------------------------------------| -//! | JTAG Re-enable | Downstream | 6 | EFUSE_KEY_PURPOSE_HMAC_DOWN_JTAG | -//! | DS Key Derivation | Downstream | 7 | EFUSE_KEY_PURPOSE_HMAC_DOWN_DIGITAL_SIGNATURE | -//! | HMAC Calculation | Upstream | 8 | EFUSE_KEY_PURPOSE_HMAC_UP | -//! | Both JTAG Re-enable and DS KDF | Downstream | 5 | EFUSE_KEY_PURPOSE_HMAC_DOWN_ALL | -//! -//! To burn the efuse key purpose `HMAC_UP` to `Key0`: -//! ```sh -//! espefuse.py burn_efuse KEY_PURPOSE_0 8 -//! ``` -//! -//! ## Use a custom key -//! You can generate a custom key file from a string using the following command -//! ```sh -//! echo -n "" | openssl dgst -sha256 -binary > key.bin -//! ``` -//! -//! You can then write your key using the following command -//! - `BLOCK_KEY0` The keyblock to program the key to. By default this example -//! uses key0. -//! - `HMAC_UP` The purpose for the key. Use HMAC_UP for upstream. -//! - `--no-read-protect` Allow to read the key from software, after writing it. -//! ```sh -//! espefuse.py burn_key BLOCK_KEY0 key.bin HMAC_UP --no-read-protect -//! ``` -//! To see the key in bytes, you can do the following: -//! ```sh -//! echo -n "" | openssl dgst -sha256 -binary | xxd -p -//! ``` -//! or from the binary file -//! ```sh -//! xxd -p key.bin -//! ``` - -#![no_std] -#![no_main] - -use esp32h2_hal::{ - clock::ClockControl, - hmac::{Hmac, HmacPurpose, KeyId}, - peripherals::Peripherals, - prelude::*, - systimer::SystemTimer, - Rng, -}; -use esp_backtrace as _; -use esp_println::println; -use hmac::{Hmac as HmacSw, Mac}; -use nb::block; -use sha2::Sha256; - -type HmacSha256 = HmacSw; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rng = Rng::new(peripherals.RNG); - - // Set sw key - let key = [0_u8; 32].as_ref(); - - let mut hw_hmac = Hmac::new(peripherals.HMAC); - - let mut src = [0_u8; 1024]; - rng.read(src.as_mut_slice()).unwrap(); - // println!("HMAC input {:02X?}", src); - - let mut output = [0u8; 32]; - - println!("Beginning stress tests..."); - println!("Testing length from 0 to {:?} bytes for HMAC...", src.len()); - for i in 0..src.len() + 1 { - let (nsrc, _) = src.split_at(i); - let mut remaining = nsrc; - hw_hmac.init(); - block!(hw_hmac.configure(HmacPurpose::ToUser, KeyId::Key0)).expect("Key purpose mismatch"); - let pre_hw_hmac = SystemTimer::now(); - while remaining.len() > 0 { - remaining = block!(hw_hmac.update(remaining)).unwrap(); - } - block!(hw_hmac.finalize(output.as_mut_slice())).unwrap(); - let post_hw_hmac = SystemTimer::now(); - let hw_time = post_hw_hmac - pre_hw_hmac; - let mut sw_hmac = HmacSha256::new_from_slice(key).expect("HMAC can take key of any size"); - let pre_sw_hash = SystemTimer::now(); - sw_hmac.update(nsrc); - let soft_result = sw_hmac.finalize().into_bytes(); - let post_sw_hash = SystemTimer::now(); - let soft_time = post_sw_hash - pre_sw_hash; - for (a, b) in output.iter().zip(soft_result) { - assert_eq!(*a, b); - } - println!("Testing for length: {:>4} | HW: {:>6} cycles, SW: {:>7} cycles (HW HMAC is {:>2}x faster)", i, hw_time, soft_time, soft_time / hw_time); - } - println!("Finished stress tests!"); - - loop {} -} diff --git a/esp32h2-hal/examples/i2c_bmp180_calibration_data.rs b/esp32h2-hal/examples/i2c_bmp180_calibration_data.rs deleted file mode 100644 index d5c2e1602..000000000 --- a/esp32h2-hal/examples/i2c_bmp180_calibration_data.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! Read calibration data from BMP180 sensor -//! -//! This example dumps the calibration data from a BMP180 sensor -//! -//! The following wiring is assumed: -//! - SDA => GPIO1 -//! - SCL => GPIO2 - -#![no_std] -#![no_main] - -use esp32h2_hal::{clock::ClockControl, gpio::IO, i2c::I2C, peripherals::Peripherals, prelude::*}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create a new peripheral object with the described wiring - // and standard I2C clock speed - let mut i2c = I2C::new( - peripherals.I2C0, - io.pins.gpio1, - io.pins.gpio2, - 100u32.kHz(), - &clocks, - ); - - loop { - let mut data = [0u8; 22]; - i2c.write_read(0x77, &[0xaa], &mut data).ok(); - - println!("{:02x?}", data); - } -} diff --git a/esp32h2-hal/examples/i2c_display.rs b/esp32h2-hal/examples/i2c_display.rs deleted file mode 100644 index 3c0d291b5..000000000 --- a/esp32h2-hal/examples/i2c_display.rs +++ /dev/null @@ -1,121 +0,0 @@ -//! I2C Display example -//! -//! This example prints some text on an SSD1306-based -//! display (via I2C) -//! -//! The following wiring is assumed: -//! - SDA => GPIO1 -//! - SCL => GPIO2 - -#![no_std] -#![no_main] - -use embedded_graphics::{ - mono_font::{ - ascii::{FONT_6X10, FONT_9X18_BOLD}, - MonoTextStyleBuilder, - }, - pixelcolor::BinaryColor, - prelude::*, - text::{Alignment, Text}, -}; -use esp32h2_hal::{ - clock::ClockControl, - gpio::IO, - i2c::I2C, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, -}; -use esp_backtrace as _; -use nb::block; -use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create a new peripheral object with the described wiring - // and standard I2C clock speed - let i2c = I2C::new( - peripherals.I2C0, - io.pins.gpio1, - io.pins.gpio2, - 100u32.kHz(), - &clocks, - ); - - // Start timer (5 second interval) - timer0.start(5u64.secs()); - - // Initialize display - let interface = I2CDisplayInterface::new(i2c); - let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0) - .into_buffered_graphics_mode(); - display.init().unwrap(); - - // Specify different text styles - let text_style = MonoTextStyleBuilder::new() - .font(&FONT_6X10) - .text_color(BinaryColor::On) - .build(); - let text_style_big = MonoTextStyleBuilder::new() - .font(&FONT_9X18_BOLD) - .text_color(BinaryColor::On) - .build(); - - loop { - // Fill display bufffer with a centered text with two lines (and two text - // styles) - Text::with_alignment( - "esp-hal", - display.bounding_box().center() + Point::new(0, 0), - text_style_big, - Alignment::Center, - ) - .draw(&mut display) - .unwrap(); - - Text::with_alignment( - "Chip: ESP32-H2", - display.bounding_box().center() + Point::new(0, 14), - text_style, - Alignment::Center, - ) - .draw(&mut display) - .unwrap(); - - // Write buffer to display - display.flush().unwrap(); - // Clear display buffer - display.clear(BinaryColor::Off).unwrap(); - - // Wait 5 seconds - block!(timer0.wait()).unwrap(); - - // Write single-line centered text "Hello World" to buffer - Text::with_alignment( - "Hello World!", - display.bounding_box().center(), - text_style_big, - Alignment::Center, - ) - .draw(&mut display) - .unwrap(); - - // Write buffer to display - display.flush().unwrap(); - // Clear display buffer - display.clear(BinaryColor::Off).unwrap(); - - // Wait 5 seconds - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32h2-hal/examples/i2s_read.rs b/esp32h2-hal/examples/i2s_read.rs deleted file mode 100644 index cfb15ecdb..000000000 --- a/esp32h2-hal/examples/i2s_read.rs +++ /dev/null @@ -1,78 +0,0 @@ -//! This shows how to continuously receive data via I2S -//! -//! Pins used -//! MCLK GPIO4 -//! BCLK GPIO1 -//! WS GPIO2 -//! DIN GPIO5 -//! -//! Without an additional I2S source device you can connect 3V3 or GND to DIN to -//! read 0 or 0xFF or connect DIN to WS to read two different values -//! -//! You can also inspect the MCLK, BCLK and WS with a logic analyzer - -#![no_std] -#![no_main] - -use esp32h2_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - i2s::{DataFormat, I2s, I2sReadDma, Standard}, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (_, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(0, 4 * 4092); - - let i2s = I2s::new( - peripherals.I2S0, - Standard::Philips, - DataFormat::Data16Channel16, - 44100u32.Hz(), - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - &clocks, - ) - .with_mclk(io.pins.gpio4); - - let i2s_rx = i2s - .i2s_rx - .with_bclk(io.pins.gpio1) - .with_ws(io.pins.gpio2) - .with_din(io.pins.gpio5) - .build(); - - let buffer = rx_buffer; - - let mut transfer = i2s_rx.read_dma_circular(buffer).unwrap(); - println!("Started transfer"); - - loop { - let avail = transfer.available(); - - if avail > 0 { - let mut rcv = [0u8; 5000]; - transfer.pop(&mut rcv[..avail]).unwrap(); - println!("Received {:x?}...", &rcv[..30]); - } - } -} diff --git a/esp32h2-hal/examples/i2s_sound.rs b/esp32h2-hal/examples/i2s_sound.rs deleted file mode 100644 index 77bf92176..000000000 --- a/esp32h2-hal/examples/i2s_sound.rs +++ /dev/null @@ -1,120 +0,0 @@ -//! This shows how to transmit data continously via I2S -//! -//! Pins used -//! MCLK GPIO4 -//! BCLK GPIO1 -//! WS GPIO2 -//! DOUT GPIO3 -//! -//! Without an additional I2S sink device you can inspect the MCLK, BCLK, WS and -//! DOUT with a logic analyzer -//! -//! You can also connect e.g. a PCM510x to hear an annoying loud sine tone (full -//! scale), so turn down the volume before running this example. -//! -//! Wiring is like this -//! -//! | Pin | Connected to | -//! |-------|-----------------| -//! | BCK | GPIO1 | -//! | DIN | GPIO3 | -//! | LRCK | GPIO2 | -//! | SCK | Gnd | -//! | GND | Gnd | -//! | VIN | +3V3 | -//! | FLT | Gnd | -//! | FMT | Gnd | -//! | DEMP | Gnd | -//! | XSMT | +3V3 | - -#![no_std] -#![no_main] - -use esp32h2_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - i2s::{DataFormat, I2s, I2sWriteDma, Standard}, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; - -const SINE: [i16; 64] = [ - 0, 3211, 6392, 9511, 12539, 15446, 18204, 20787, 23169, 25329, 27244, 28897, 30272, 31356, - 32137, 32609, 32767, 32609, 32137, 31356, 30272, 28897, 27244, 25329, 23169, 20787, 18204, - 15446, 12539, 9511, 6392, 3211, 0, -3211, -6392, -9511, -12539, -15446, -18204, -20787, -23169, - -25329, -27244, -28897, -30272, -31356, -32137, -32609, -32767, -32609, -32137, -31356, -30272, - -28897, -27244, -25329, -23169, -20787, -18204, -15446, -12539, -9511, -6392, -3211, -]; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (tx_buffer, mut tx_descriptors, _, mut rx_descriptors) = dma_buffers!(32000, 0); - - let i2s = I2s::new( - peripherals.I2S0, - Standard::Philips, - DataFormat::Data16Channel16, - 44100u32.Hz(), - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - &clocks, - ) - .with_mclk(io.pins.gpio4); - - let i2s_tx = i2s - .i2s_tx - .with_bclk(io.pins.gpio1) - .with_ws(io.pins.gpio2) - .with_dout(io.pins.gpio3) - .build(); - - let data = - unsafe { core::slice::from_raw_parts(&SINE as *const _ as *const u8, SINE.len() * 2) }; - - let buffer = tx_buffer; - let mut idx = 0; - for i in 0..usize::min(data.len(), buffer.len()) { - buffer[i] = data[idx]; - - idx += 1; - - if idx >= data.len() { - idx = 0; - } - } - - let mut filler = [0u8; 10000]; - - let mut transfer = i2s_tx.write_dma_circular(buffer).unwrap(); - loop { - let avail = transfer.available(); - if avail > 0 { - let avail = usize::min(10000, avail); - for bidx in 0..avail { - filler[bidx] = data[idx]; - idx += 1; - - if idx >= data.len() { - idx = 0; - } - } - transfer.push(&filler[0..avail]).unwrap(); - } - } -} diff --git a/esp32h2-hal/examples/interrupt_preemption.rs b/esp32h2-hal/examples/interrupt_preemption.rs deleted file mode 100644 index 4d001dc5f..000000000 --- a/esp32h2-hal/examples/interrupt_preemption.rs +++ /dev/null @@ -1,132 +0,0 @@ -//! Interrupt Preemption -//! -//! An example of how an interrupt can be preempted by another with higher -//! priority. Should show higher-numbered software interrupts happening during -//! the handling of lower-numbered ones. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32h2_hal::{ - clock::ClockControl, - interrupt::{self}, - peripherals::{self, Peripherals}, - prelude::*, - riscv, - system::{SoftwareInterrupt, SoftwareInterruptControl}, -}; -use esp_backtrace as _; - -static SWINT: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clockctrl = system.clock_control; - let sw_int = system.software_interrupt_control; - let _clocks = ClockControl::boot_defaults(clockctrl).freeze(); - - critical_section::with(|cs| SWINT.borrow_ref_mut(cs).replace(sw_int)); - - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR0, - interrupt::Priority::Priority1, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR1, - interrupt::Priority::Priority2, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR2, - interrupt::Priority::Priority2, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR3, - interrupt::Priority::Priority15, - ) - .unwrap(); - unsafe { riscv::interrupt::enable() } - - // raise mid priority interrupt. - // The handler raises one interrupt at lower priority, one at same and one at - // higher. We expect to see the higher priority served immeiately before - // exiting the handler Once the handler is exited we expect to see same - // priority and low priority interrupts served in that order - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt1); - }); - loop {} -} - -#[interrupt] -fn FROM_CPU_INTR0() { - esp_println::println!("SW interrupt0"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt0); - }); -} -#[interrupt] -fn FROM_CPU_INTR1() { - esp_println::println!("SW interrupt1 entry"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt1); - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt2); // raise interrupt at same priority - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt3); // raise interrupt at higher priority - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt0); // raise interrupt at - // lower priority - }); - esp_println::println!("SW interrupt1 exit"); -} -#[interrupt] -fn FROM_CPU_INTR2() { - esp_println::println!("SW interrupt2"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt2); - }); -} -#[interrupt] -fn FROM_CPU_INTR3() { - esp_println::println!("SW interrupt3"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt3); - }); -} diff --git a/esp32h2-hal/examples/ledc.rs b/esp32h2-hal/examples/ledc.rs deleted file mode 100644 index 2661f364d..000000000 --- a/esp32h2-hal/examples/ledc.rs +++ /dev/null @@ -1,66 +0,0 @@ -//! Turns on LED with the option to change LED intensity depending on `duty` -//! value. Possible values (`u32`) are in range 0..100. -//! -//! This assumes that a LED is connected to the pin assigned to `led`. (GPIO4) - -#![no_std] -#![no_main] - -use esp32h2_hal::{ - clock::ClockControl, - gpio::IO, - ledc::{ - channel::{self, ChannelIFace}, - timer::{self, TimerIFace}, - LSGlobalClkSource, - LowSpeed, - LEDC, - }, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let led = io.pins.gpio4.into_push_pull_output(); - - let mut ledc = LEDC::new(peripherals.LEDC, &clocks); - ledc.set_global_slow_clock(LSGlobalClkSource::APBClk); - let mut lstimer0 = ledc.get_timer::(timer::Number::Timer2); - - lstimer0 - .configure(timer::config::Config { - duty: timer::config::Duty::Duty5Bit, - clock_source: timer::LSClockSource::APBClk, - frequency: 24u32.kHz(), - }) - .unwrap(); - - let mut channel0 = ledc.get_channel(channel::Number::Channel0, led); - channel0 - .configure(channel::config::Config { - timer: &lstimer0, - duty_pct: 10, - pin_config: channel::config::PinConfig::PushPull, - }) - .unwrap(); - - channel0.start_duty_fade(0, 100, 2000).expect_err( - "Fading from 0% to 100%, at 24kHz and 5-bit resolution, over 2 seconds, should fail", - ); - - loop { - // Set up a breathing LED: fade from off to on over a second, then - // from on back off over the next second. Then loop. - channel0.start_duty_fade(0, 100, 1000).unwrap(); - while channel0.is_duty_fade_running() {} - channel0.start_duty_fade(100, 0, 1000).unwrap(); - while channel0.is_duty_fade_running() {} - } -} diff --git a/esp32h2-hal/examples/mcpwm.rs b/esp32h2-hal/examples/mcpwm.rs deleted file mode 100644 index 84f2ff0ef..000000000 --- a/esp32h2-hal/examples/mcpwm.rs +++ /dev/null @@ -1,49 +0,0 @@ -//! Uses timer0 and operator0 of the MCPWM0 peripheral to output a 50% duty -//! signal at 20 kHz. -//! -//! The signal will be output to the pin assigned to `pin`. (GPIO4) - -#![no_std] -#![no_main] - -use esp32h2_hal::{ - clock::ClockControl, - gpio::IO, - mcpwm::{operator::PwmPinConfig, timer::PwmWorkingMode, PeripheralClockConfig, MCPWM}, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let pin = io.pins.gpio4; - - // initialize peripheral - let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 32u32.MHz()).unwrap(); - let mut mcpwm = MCPWM::new(peripherals.MCPWM0, clock_cfg); - - // connect operator0 to timer0 - mcpwm.operator0.set_timer(&mcpwm.timer0); - // connect operator0 to pin - let mut pwm_pin = mcpwm - .operator0 - .with_pin_a(pin, PwmPinConfig::UP_ACTIVE_HIGH); - - // start timer with timestamp values in the range of 0..=99 and a frequency of - // 20 kHz - let timer_clock_cfg = clock_cfg - .timer_clock_with_frequency(99, PwmWorkingMode::Increase, 20u32.kHz()) - .unwrap(); - mcpwm.timer0.start(timer_clock_cfg); - - // pin will be high 50% of the time - pwm_pin.set_timestamp(50); - - loop {} -} diff --git a/esp32h2-hal/examples/parl_io_tx.rs b/esp32h2-hal/examples/parl_io_tx.rs deleted file mode 100644 index 2d35302d9..000000000 --- a/esp32h2-hal/examples/parl_io_tx.rs +++ /dev/null @@ -1,93 +0,0 @@ -//! This shows using Parallel IO to output 4 bit parallel data at 1MHz clock -//! rate. -//! -//! Uses GPIO 1, 2, 3 and 4 as the data pins. -//! GPIO 5 as the "valid pin" (driven high during an active transfer) and GPIO -//! 10 as the clock signal output. -//! -//! You can use a logic analyzer to see how the pins are used. - -#![no_std] -#![no_main] - -use esp32h2_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - gpio::IO, - parl_io::{ - BitPackOrder, - ClkOutPin, - ParlIoTxOnly, - SampleEdge, - TxFourBits, - TxPinConfigWithValidPin, - }, - peripherals::Peripherals, - prelude::*, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let (tx_buffer, mut tx_descriptors, _, mut rx_descriptors) = dma_buffers!(32000, 0); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let tx_pins = TxFourBits::new(io.pins.gpio1, io.pins.gpio2, io.pins.gpio3, io.pins.gpio4); - - let pin_conf = TxPinConfigWithValidPin::new(tx_pins, io.pins.gpio5); - - let parl_io = ParlIoTxOnly::new( - peripherals.PARL_IO, - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - 1u32.MHz(), - &clocks, - ) - .unwrap(); - - let clock_pin = ClkOutPin::new(io.pins.gpio10); - - let mut parl_io_tx = parl_io - .tx - .with_config( - pin_conf, - clock_pin, - 0, - SampleEdge::Normal, - BitPackOrder::Msb, - ) - .unwrap(); - - let mut buffer = tx_buffer; - for i in 0..buffer.len() { - buffer[i] = (i % 255) as u8; - } - - let mut delay = Delay::new(&clocks); - - loop { - let transfer = parl_io_tx.write_dma(buffer).unwrap(); - - // the buffer and driver is moved into the transfer and we can get it back via - // `wait` - (buffer, parl_io_tx) = transfer.wait().unwrap(); - println!("Transferred {} bytes", buffer.len()); - - delay.delay_ms(500u32); - } -} diff --git a/esp32h2-hal/examples/qspi_flash.rs b/esp32h2-hal/examples/qspi_flash.rs deleted file mode 100644 index 0e8acd10a..000000000 --- a/esp32h2-hal/examples/qspi_flash.rs +++ /dev/null @@ -1,167 +0,0 @@ -//! SPI write and read a flash chip -//! -//! Folowing pins are used: -//! SCLK GPIO1 -//! MISOI/IO0 GPIO2 -//! MOSI/IO1 GPIO3 -//! IO2 GPIO4 -//! IO3 GPIO5 -//! CS GPIO11 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! Connect a flash chip (GD25Q64C was used) and make sure QE in the status -//! register is set. - -#![no_std] -#![no_main] - -use esp32h2_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{prelude::*, Address, Command, Spi}, - SpiDataMode, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio1; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio3; - let sio2 = io.pins.gpio4; - let sio3 = io.pins.gpio5; - let cs = io.pins.gpio11; - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(256, 320); - - let mut spi = Spi::new_half_duplex(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(sio2), - Some(sio3), - Some(cs), - ) - .with_dma(dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let mut delay = Delay::new(&clocks); - - // DMA buffer require a static life-time - let mut zero_buf = zero_buffer(); - let send = tx_buffer; - let mut receive = rx_buffer; - - // write enable - let transfer = spi - .write( - SpiDataMode::Single, - Command::Command8(0x06, SpiDataMode::Single), - Address::None, - 0, - zero_buf, - ) - .unwrap(); - (zero_buf, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - // erase sector - let transfer = spi - .write( - SpiDataMode::Single, - Command::Command8(0x20, SpiDataMode::Single), - Address::Address24(0x000000, SpiDataMode::Single), - 0, - zero_buf, - ) - .unwrap(); - (zero_buf, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - // write enable - let transfer = spi - .write( - SpiDataMode::Single, - Command::Command8(0x06, SpiDataMode::Single), - Address::None, - 0, - zero_buf, - ) - .unwrap(); - (_, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - // write data / program page - send.fill(b'!'); - send[0..][..5].copy_from_slice(&b"Hello"[..]); - let transfer = spi - .write( - SpiDataMode::Quad, - Command::Command8(0x32, SpiDataMode::Single), - Address::Address24(0x000000, SpiDataMode::Single), - 0, - send, - ) - .unwrap(); - (_, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - loop { - // quad fast read - let transfer = spi - .read( - SpiDataMode::Quad, - Command::Command8(0xeb, SpiDataMode::Single), - Address::Address32(0x000000 << 8, SpiDataMode::Quad), - 4, - receive, - ) - .unwrap(); - - // here we could do something else while DMA transfer is in progress - // the buffers and spi is moved into the transfer and we can get it back via - // `wait` - (receive, spi) = transfer.wait().unwrap(); - - println!("{:x?}", &receive); - for b in &mut receive.iter() { - if *b >= 32 && *b <= 127 { - print!("{}", *b as char); - } else { - print!("."); - } - } - println!(); - - delay.delay_ms(250u32); - } -} - -fn zero_buffer() -> &'static mut [u8; 0] { - static mut BUFFER: [u8; 0] = [0u8; 0]; - unsafe { &mut BUFFER } -} diff --git a/esp32h2-hal/examples/ram.rs b/esp32h2-hal/examples/ram.rs deleted file mode 100644 index 97ad9f380..000000000 --- a/esp32h2-hal/examples/ram.rs +++ /dev/null @@ -1,94 +0,0 @@ -//! This shows how to use RTC memory. -//! RTC memory is retained during resets and during most sleep modes. -//! Initialized memory is always re-initialized on startup. -//! Uninitialzed memory isn't initialized on startup and can be used to keep -//! data during resets. Zeroed memory is initialized to zero on startup. -//! We can also run code from RTC memory. - -#![no_std] -#![no_main] - -use esp32h2_hal::{ - clock::ClockControl, - macros::ram, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, - Rtc, -}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; - -#[ram(rtc_fast)] -static mut SOME_INITED_DATA: [u8; 2] = [0xaa, 0xbb]; - -#[ram(rtc_fast, uninitialized)] -static mut SOME_UNINITED_DATA: [u8; 2] = [0; 2]; - -#[ram(rtc_fast, zeroed)] -static mut SOME_ZEROED_DATA: [u8; 8] = [0; 8]; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - // The RWDT flash boot protection must be enabled, as it is triggered as part of - // the example. - let mut rtc = Rtc::new(peripherals.LPWR); - rtc.rwdt.enable(); - - timer0.start(1u64.secs()); - - println!("RAM function located at {:p}", function_in_ram as *const ()); - unsafe { - println!("SOME_INITED_DATA {:x?}", SOME_INITED_DATA); - println!("SOME_UNINITED_DATA {:x?}", SOME_UNINITED_DATA); - println!("SOME_ZEROED_DATA {:x?}", SOME_ZEROED_DATA); - - SOME_INITED_DATA[0] = 0xff; - SOME_ZEROED_DATA[0] = 0xff; - - println!("SOME_INITED_DATA {:x?}", SOME_INITED_DATA); - println!("SOME_UNINITED_DATA {:x?}", SOME_UNINITED_DATA); - println!("SOME_ZEROED_DATA {:x?}", SOME_ZEROED_DATA); - - if SOME_UNINITED_DATA[0] != 0 { - SOME_UNINITED_DATA[0] = 0; - SOME_UNINITED_DATA[1] = 0; - } - - if SOME_UNINITED_DATA[1] == 0xff { - SOME_UNINITED_DATA[1] = 0; - } - - println!("Counter {}", SOME_UNINITED_DATA[1]); - SOME_UNINITED_DATA[1] += 1; - } - - println!( - "RTC_FAST function located at {:p}", - function_in_rtc_ram as *const () - ); - println!("Result {}", function_in_rtc_ram()); - - loop { - function_in_ram(); - block!(timer0.wait()).unwrap(); - } -} - -#[ram] -fn function_in_ram() { - println!("Hello world!"); -} - -#[ram(rtc_fast)] -fn function_in_rtc_ram() -> u32 { - 42 -} diff --git a/esp32h2-hal/examples/read_efuse.rs b/esp32h2-hal/examples/read_efuse.rs deleted file mode 100644 index 27d116375..000000000 --- a/esp32h2-hal/examples/read_efuse.rs +++ /dev/null @@ -1,21 +0,0 @@ -//! This shows how to read selected information from eFuses. -//! e.g. the MAC address - -#![no_std] -#![no_main] - -use esp32h2_hal::{clock::ClockControl, efuse::Efuse, peripherals::Peripherals, prelude::*}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - println!("MAC address {:02x?}", Efuse::get_mac_address()); - println!("Flash Encryption {:?}", Efuse::get_flash_encryption()); - - loop {} -} diff --git a/esp32h2-hal/examples/rmt_rx.rs b/esp32h2-hal/examples/rmt_rx.rs deleted file mode 100644 index 4e2ff72a6..000000000 --- a/esp32h2-hal/examples/rmt_rx.rs +++ /dev/null @@ -1,99 +0,0 @@ -//! Demonstrates decoding pulse sequences with RMT -//! This uses the boot button as input - press the button a couple of -//! times to generate a pulse sequence and then wait for the idle timeout to see -//! the recorded pulse sequence - -#![no_std] -#![no_main] - -use esp32h2_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - rmt::{PulseCode, RxChannel, RxChannelConfig, RxChannelCreator}, - Delay, - Rmt, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -const WIDTH: usize = 80; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let rmt = Rmt::new(peripherals.RMT, 1u32.MHz(), &clocks).unwrap(); - - let mut channel = rmt - .channel2 - .configure( - io.pins.gpio9, - RxChannelConfig { - clk_divider: 255, - idle_threshold: 10000, - ..RxChannelConfig::default() - }, - ) - .unwrap(); - - let mut delay = Delay::new(&clocks); - - let mut data = [PulseCode { - level1: true, - length1: 1, - level2: false, - length2: 1, - }; 48]; - - loop { - let transaction = channel.receive(&mut data).unwrap(); - channel = transaction.wait().unwrap(); - - let mut total = 0usize; - for entry in &data[..data.len()] { - if entry.length1 == 0 { - break; - } - total += entry.length1 as usize; - - if entry.length2 == 0 { - break; - } - total += entry.length2 as usize; - } - - for entry in &data[..data.len()] { - if entry.length1 == 0 { - break; - } - - let count = WIDTH / (total / entry.length1 as usize); - let c = if entry.level1 { '-' } else { '_' }; - for _ in 0..count + 1 { - print!("{}", c); - } - - if entry.length2 == 0 { - break; - } - - let count = WIDTH / (total / entry.length2 as usize); - let c = if entry.level2 { '-' } else { '_' }; - for _ in 0..count + 1 { - print!("{}", c); - } - } - - println!(); - println!(); - println!(); - - delay.delay_ms(500u32); - } -} diff --git a/esp32h2-hal/examples/rmt_tx.rs b/esp32h2-hal/examples/rmt_tx.rs deleted file mode 100644 index 9f003d4e0..000000000 --- a/esp32h2-hal/examples/rmt_tx.rs +++ /dev/null @@ -1,61 +0,0 @@ -//! Demonstrates generating pulse sequences with RMT -//! Connect a logic analyzer to GPIO1 to see the generated pulses. - -#![no_std] -#![no_main] - -use esp32h2_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - rmt::{PulseCode, TxChannel, TxChannelConfig, TxChannelCreator}, - Delay, - Rmt, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let rmt = Rmt::new(peripherals.RMT, 8u32.MHz(), &clocks).unwrap(); - - let mut channel = rmt - .channel0 - .configure( - io.pins.gpio1, - TxChannelConfig { - clk_divider: 255, - ..TxChannelConfig::default() - }, - ) - .unwrap(); - - let mut delay = Delay::new(&clocks); - - let mut data = [PulseCode { - level1: true, - length1: 200, - level2: false, - length2: 50, - }; 20]; - - data[data.len() - 2] = PulseCode { - level1: true, - length1: 3000, - level2: false, - length2: 500, - }; - data[data.len() - 1] = PulseCode::default(); - - loop { - let transaction = channel.transmit(&data); - channel = transaction.wait().unwrap(); - delay.delay_ms(500u32); - } -} diff --git a/esp32h2-hal/examples/rng.rs b/esp32h2-hal/examples/rng.rs deleted file mode 100644 index 04689e3b2..000000000 --- a/esp32h2-hal/examples/rng.rs +++ /dev/null @@ -1,28 +0,0 @@ -//! Demonstrates the use of the hardware Random Number Generator (RNG) - -#![no_std] -#![no_main] - -use esp32h2_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Rng}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Instantiate the Random Number Generator peripheral: - let mut rng = Rng::new(peripherals.RNG); - - // Generate a random word (u32): - println!("Random u32: {}", rng.random()); - - // Fill a buffer with random bytes: - let mut buf = [0u8; 16]; - rng.read(&mut buf).unwrap(); - println!("Random bytes: {:?}", buf); - - loop {} -} diff --git a/esp32h2-hal/examples/rsa.rs b/esp32h2-hal/examples/rsa.rs deleted file mode 100644 index 6d49dcc0f..000000000 --- a/esp32h2-hal/examples/rsa.rs +++ /dev/null @@ -1,156 +0,0 @@ -//! Demonstrates the use of the RSA peripheral and compares the speed of -//! multiple arithmetic operations. - -#![no_std] -#![no_main] - -use crypto_bigint::{ - modular::runtime_mod::{DynResidue, DynResidueParams}, - Uint, - U1024, - U512, -}; -use esp32h2_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - rsa::{ - operand_sizes, - Rsa, - RsaModularExponentiation, - RsaModularMultiplication, - RsaMultiplication, - }, - systimer::SystemTimer, -}; -use esp_backtrace as _; -use esp_println::println; - -const BIGNUM_1: U512 = Uint::from_be_hex( - "c7f61058f96db3bd87dbab08ab03b4f7f2f864eac249144adea6a65f97803b719d8ca980b7b3c0389c1c7c6\ -7dc353c5e0ec11f5fc8ce7f6073796cc8f73fa878", -); -const BIGNUM_2: U512 = Uint::from_be_hex( - "1763db3344e97be15d04de4868badb12a38046bb793f7630d87cf100aa1c759afac15a01f3c4c83ec2d2f66\ -6bd22f71c3c1f075ec0e2cb0cb29994d091b73f51", -); -const BIGNUM_3: U512 = Uint::from_be_hex( - "6b6bb3d2b6cbeb45a769eaa0384e611e1b89b0c9b45a045aca1c5fd6e8785b38df7118cf5dd45b9b63d293b\ -67aeafa9ba25feb8712f188cb139b7d9b9af1c361", -); - -const fn compute_r(modulus: &U512) -> U512 { - let mut d = [0_u32; U512::LIMBS * 2 + 1]; - d[d.len() - 1] = 1; - let d = Uint::from_words(d); - d.const_rem(&modulus.resize()).0.resize() -} - -const fn compute_mprime(modulus: &U512) -> u32 { - let m_inv = modulus.inv_mod2k(32).to_words()[0]; - (-1 * m_inv as i64 % 4294967296) as u32 -} - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rsa = Rsa::new(peripherals.RSA); - - nb::block!(rsa.ready()).unwrap(); - mod_exp_example(&mut rsa); - mod_multi_example(&mut rsa); - multiplication_example(&mut rsa); - loop {} -} - -fn mod_multi_example(rsa: &mut Rsa) { - let mut outbuf = [0_u32; U512::LIMBS]; - let mut mod_multi = RsaModularMultiplication::::new( - rsa, - BIGNUM_1.as_words(), - BIGNUM_2.as_words(), - BIGNUM_3.as_words(), - compute_mprime(&BIGNUM_3), - ); - let r = compute_r(&BIGNUM_3); - let pre_hw_modmul = SystemTimer::now(); - mod_multi.start_modular_multiplication(r.as_words()); - mod_multi.read_results(&mut outbuf); - let post_hw_modmul = SystemTimer::now(); - println!( - "it took {} cycles for hw modular multiplication", - post_hw_modmul - pre_hw_modmul - ); - let residue_params = DynResidueParams::new(&BIGNUM_3); - let residue_num1 = DynResidue::new(&BIGNUM_1, residue_params); - let residue_num2 = DynResidue::new(&BIGNUM_2, residue_params); - let pre_sw_exp = SystemTimer::now(); - let sw_out = residue_num1.mul(&residue_num2); - let post_sw_exp = SystemTimer::now(); - println!( - "it took {} cycles for sw modular multiplication", - post_sw_exp - pre_sw_exp - ); - assert_eq!(U512::from_words(outbuf), sw_out.retrieve()); - println!("modular multiplication done"); -} - -fn mod_exp_example(rsa: &mut Rsa) { - rsa.enable_disable_constant_time_acceleration(true); - rsa.enable_disable_search_acceleration(true); - let mut outbuf = [0_u32; U512::LIMBS]; - let mut mod_exp = RsaModularExponentiation::::new( - rsa, - BIGNUM_2.as_words(), - BIGNUM_3.as_words(), - compute_mprime(&BIGNUM_3), - ); - let r = compute_r(&BIGNUM_3); - let base = BIGNUM_1.as_words(); - let pre_hw_exp = SystemTimer::now(); - mod_exp.start_exponentiation(base, r.as_words()); - mod_exp.read_results(&mut outbuf); - let post_hw_exp = SystemTimer::now(); - println!( - "it took {} cycles for hw modular exponentiation", - post_hw_exp - pre_hw_exp - ); - let residue_params = DynResidueParams::new(&BIGNUM_3); - let residue = DynResidue::new(&BIGNUM_1, residue_params); - let pre_sw_exp = SystemTimer::now(); - let sw_out = residue.pow(&BIGNUM_2); - let post_sw_exp = SystemTimer::now(); - println!( - "it took {} cycles for sw modular exponentiation", - post_sw_exp - pre_sw_exp - ); - assert_eq!(U512::from_words(outbuf), sw_out.retrieve()); - println!("modular exponentiation done"); -} - -fn multiplication_example(rsa: &mut Rsa) { - let mut out = [0_u32; U1024::LIMBS]; - let operand_a = BIGNUM_1.as_words(); - let operand_b = BIGNUM_2.as_words(); - let mut rsamulti = RsaMultiplication::::new(rsa, operand_a); - let pre_hw_mul = SystemTimer::now(); - rsamulti.start_multiplication(operand_b); - rsamulti.read_results(&mut out); - let post_hw_mul = SystemTimer::now(); - println!( - "it took {} cycles for hw multiplication", - post_hw_mul - pre_hw_mul - ); - let pre_sw_mul = SystemTimer::now(); - let sw_out = BIGNUM_1.mul_wide(&BIGNUM_2); - let post_sw_mul = SystemTimer::now(); - println!( - "it took {} cycles for sw multiplication", - post_sw_mul - pre_sw_mul - ); - assert_eq!(U1024::from_words(out), sw_out.1.concat(&sw_out.0)); - println!("multiplication done"); -} diff --git a/esp32h2-hal/examples/rtc_time.rs b/esp32h2-hal/examples/rtc_time.rs deleted file mode 100644 index 1597025f0..000000000 --- a/esp32h2-hal/examples/rtc_time.rs +++ /dev/null @@ -1,22 +0,0 @@ -//! Prints time in milliseconds from the RTC Timer - -#![no_std] -#![no_main] - -use esp32h2_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Delay, Rtc}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let rtc = Rtc::new(peripherals.LPWR); - let mut delay = Delay::new(&clocks); - - loop { - esp_println::println!("rtc time in milliseconds is {}", rtc.get_time_ms()); - delay.delay_ms(1000u32); - } -} diff --git a/esp32h2-hal/examples/rtc_watchdog.rs b/esp32h2-hal/examples/rtc_watchdog.rs deleted file mode 100644 index ac737cf1d..000000000 --- a/esp32h2-hal/examples/rtc_watchdog.rs +++ /dev/null @@ -1,60 +0,0 @@ -//! This demos the RTC Watchdog Timer (RWDT). -//! The RWDT is initially configured to trigger an interrupt after a given -//! timeout. Then, upon expiration, the RWDT is restarted and then reconfigured -//! to reset both the main system and the RTC. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32h2_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, - Rtc, - Rwdt, -}; -use esp_backtrace as _; - -static RWDT: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rtc = Rtc::new(peripherals.LPWR); - rtc.rwdt.start(2000u64.millis()); - rtc.rwdt.listen(); - - interrupt::enable( - peripherals::Interrupt::LP_WDT, - interrupt::Priority::Priority1, - ) - .unwrap(); - - critical_section::with(|cs| RWDT.borrow_ref_mut(cs).replace(rtc.rwdt)); - - loop {} -} - -#[interrupt] -fn LP_WDT() { - critical_section::with(|cs| { - esp_println::println!("RWDT Interrupt"); - - let mut rwdt = RWDT.borrow_ref_mut(cs); - let rwdt = rwdt.as_mut().unwrap(); - - rwdt.clear_interrupt(); - - esp_println::println!("Restarting in 5 seconds..."); - - rwdt.start(5000u64.millis()); - rwdt.unlisten(); - }); -} diff --git a/esp32h2-hal/examples/serial_interrupts.rs b/esp32h2-hal/examples/serial_interrupts.rs deleted file mode 100644 index 4d58db876..000000000 --- a/esp32h2-hal/examples/serial_interrupts.rs +++ /dev/null @@ -1,88 +0,0 @@ -//! This shows some of the interrupts that can be generated by UART/Serial. -//! Use a proper serial terminal to connect to the board (espmonitor and -//! espflash won't work) - -#![no_std] -#![no_main] - -use core::{cell::RefCell, fmt::Write}; - -use critical_section::Mutex; -use esp32h2_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals, UART0}, - prelude::*, - timer::TimerGroup, - uart::config::AtCmdConfig, - Cpu, - Uart, -}; -use esp_backtrace as _; -use nb::block; - -static SERIAL: Mutex>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - uart0.set_at_cmd(AtCmdConfig::new(None, None, None, b'#', None)); - uart0.set_rx_fifo_full_threshold(30).unwrap(); - uart0.listen_at_cmd(); - uart0.listen_rx_fifo_full(); - - timer0.start(1u64.secs()); - - critical_section::with(|cs| SERIAL.borrow_ref_mut(cs).replace(uart0)); - - interrupt::enable( - peripherals::Interrupt::UART0, - interrupt::Priority::Priority1, - ) - .unwrap(); - interrupt::set_kind( - Cpu::ProCpu, - interrupt::CpuInterrupt::Interrupt1, // Interrupt 1 handles priority one interrupts - interrupt::InterruptKind::Edge, - ); - - loop { - critical_section::with(|cs| { - writeln!(SERIAL.borrow_ref_mut(cs).as_mut().unwrap(), "Hello World! Send a single `#` character or send at least 30 characters and see the interrupts trigger.").ok(); - }); - - block!(timer0.wait()).unwrap(); - } -} - -#[interrupt] -fn UART0() { - critical_section::with(|cs| { - let mut serial = SERIAL.borrow_ref_mut(cs); - let serial = serial.as_mut().unwrap(); - - let mut cnt = 0; - while let nb::Result::Ok(_c) = serial.read() { - cnt += 1; - } - writeln!(serial, "Read {} bytes", cnt,).ok(); - - writeln!( - serial, - "Interrupt AT-CMD: {} RX-FIFO-FULL: {}", - serial.at_cmd_interrupt_set(), - serial.rx_fifo_full_interrupt_set(), - ) - .ok(); - - serial.reset_at_cmd_interrupt(); - serial.reset_rx_fifo_full_interrupt(); - }); -} diff --git a/esp32h2-hal/examples/sha.rs b/esp32h2-hal/examples/sha.rs deleted file mode 100644 index d62523e36..000000000 --- a/esp32h2-hal/examples/sha.rs +++ /dev/null @@ -1,71 +0,0 @@ -//! Demonstrates the use of the SHA peripheral and compares the speed of -//! hardware-accelerated and pure software hashing. - -#![no_std] -#![no_main] - -use esp32h2_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - sha::{Sha, ShaMode}, -}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; -use sha2::{Digest, Sha256}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let source_data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".as_bytes(); - let mut remaining = source_data; - let mut hasher = Sha::new(peripherals.SHA, ShaMode::SHA256); - - // Short hashes can be created by decreasing the output buffer to the desired - // length - let mut output = [0u8; 32]; - - // let pre_calc = xtensa_lx::timer::get_cycle_count(); - // The hardware implementation takes a subslice of the input, and returns the - // unprocessed parts The unprocessed parts can be input in the next - // iteration, you can always add more data until finish() is called. After - // finish() is called update()'s will contribute to a new hash which - // can be extracted again with finish(). - - while remaining.len() > 0 { - // Can add println to view progress, however println takes a few orders of - // magnitude longer than the Sha function itself so not useful for - // comparing processing time println!("Remaining len: {}", - // remaining.len()); - - // All the HW Sha functions are infallible so unwrap is fine to use if you use - // block! - remaining = block!(hasher.update(remaining)).unwrap(); - } - - // Finish can be called as many times as desired to get mutliple copies of the - // output. - block!(hasher.finish(output.as_mut_slice())).unwrap(); - // let post_calc = xtensa_lx::timer::get_cycle_count(); - // let hw_time = post_calc - pre_calc; - // println!("Took {} cycles", hw_time); - println!("SHA256 Hash output {:02x?}", output); - - // let pre_calc = xtensa_lx::timer::get_cycle_count(); - let mut hasher = Sha256::new(); - hasher.update(source_data); - let soft_result = hasher.finalize(); - // let post_calc = xtensa_lx::timer::get_cycle_count(); - // let soft_time = post_calc - pre_calc; - // println!("Took {} cycles", soft_time); - println!("SHA256 Hash output {:02x?}", soft_result); - - assert_eq!(output, soft_result[..]); - // println!("HW SHA is {}x faster", soft_time/hw_time); - - loop {} -} diff --git a/esp32h2-hal/examples/software_interrupts.rs b/esp32h2-hal/examples/software_interrupts.rs deleted file mode 100644 index 5779a4333..000000000 --- a/esp32h2-hal/examples/software_interrupts.rs +++ /dev/null @@ -1,141 +0,0 @@ -//! Software Interrupts -//! -//! An example of how software interrupts can be raised and reset -//! Should rotate through all of the available interrupts printing their number -//! when raised. -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32h2_hal::{ - clock::ClockControl, - interrupt::{self}, - peripherals::{self, Peripherals}, - prelude::*, - riscv, - system::{SoftwareInterrupt, SoftwareInterruptControl}, - Delay, -}; -use esp_backtrace as _; - -static SWINT: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clockctrl = system.clock_control; - let sw_int = system.software_interrupt_control; - let clocks = ClockControl::boot_defaults(clockctrl).freeze(); - - critical_section::with(|cs| SWINT.borrow_ref_mut(cs).replace(sw_int)); - - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR0, - interrupt::Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR1, - interrupt::Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR2, - interrupt::Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR3, - interrupt::Priority::Priority3, - ) - .unwrap(); - unsafe { riscv::interrupt::enable() } - let mut delay = Delay::new(&clocks); - let mut counter = 0; - loop { - delay.delay_ms(500u32); - match counter { - 0 => critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt0); - }), - 1 => critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt1); - }), - 2 => critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt2); - }), - 3 => { - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt3); - }); - counter = -1 - } - _ => {} - } - counter += 1; - } -} - -#[interrupt] -fn FROM_CPU_INTR0() { - esp_println::println!("SW interrupt0"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt0); - }); -} -#[interrupt] -fn FROM_CPU_INTR1() { - esp_println::println!("SW interrupt1"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt1); - }); -} -#[interrupt] -fn FROM_CPU_INTR2() { - esp_println::println!("SW interrupt2"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt2); - }); -} -#[interrupt] -fn FROM_CPU_INTR3() { - esp_println::println!("SW interrupt3"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt3); - }); -} diff --git a/esp32h2-hal/examples/spi_eh1_device_loopback.rs b/esp32h2-hal/examples/spi_eh1_device_loopback.rs deleted file mode 100644 index ff022969c..000000000 --- a/esp32h2-hal/examples/spi_eh1_device_loopback.rs +++ /dev/null @@ -1,140 +0,0 @@ -//! SPI loopback test -//! -//! Folowing pins are used: -//! SCLK GPIO1 -//! MISO GPIO2 -//! MOSI GPIO3 -//! CS 1 GPIO11 -//! CS 2 GPIO12 -//! CS 3 GPIO25 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use embedded_hal_1::spi::SpiDevice; -use embedded_hal_bus::spi::RefCellDevice; -use esp32h2_hal::{ - clock::ClockControl, - gpio::{self, IO}, - peripherals::Peripherals, - prelude::*, - spi::{master::Spi, SpiMode}, - Delay, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio1; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio3; - - let spi_bus = Spi::new(peripherals.SPI2, 1000u32.kHz(), SpiMode::Mode0, &clocks).with_pins( - Some(sclk), - Some(mosi), - Some(miso), - gpio::NO_PIN, - ); - let spi_bus = RefCell::new(spi_bus); - let mut spi_device_1 = - RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio11.into_push_pull_output()); - let mut spi_device_2 = - RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio12.into_push_pull_output()); - let mut spi_device_3 = - RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio25.into_push_pull_output()); - - let mut delay = Delay::new(&clocks); - println!("=== SPI example with embedded-hal-1 traits ==="); - - loop { - // --- Symmetric transfer (Read as much as we write) --- - print!("Starting symmetric transfer..."); - let write = [0xde, 0xad, 0xbe, 0xef]; - let mut read: [u8; 4] = [0x00u8; 4]; - - spi_device_1.transfer(&mut read[..], &write[..]).unwrap(); - assert_eq!(write, read); - spi_device_2.transfer(&mut read[..], &write[..]).unwrap(); - spi_device_3.transfer(&mut read[..], &write[..]).unwrap(); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Asymmetric transfer (Read more than we write) --- - print!("Starting asymetric transfer (read > write)..."); - let mut read: [u8; 4] = [0x00; 4]; - - spi_device_1 - .transfer(&mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - assert_eq!(write[0], read[0]); - assert_eq!(read[2], 0x00u8); - spi_device_2 - .transfer(&mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - spi_device_3 - .transfer(&mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer --- - // Only your RAM is the limit! - print!("Starting huge transfer..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - let mut read = [0x00u8; 4096]; - - spi_device_1 - .transfer(&mut read[..], &write[..]) - .expect("Huge transfer failed"); - assert_eq!(write, read); - spi_device_2 - .transfer(&mut read[..], &write[..]) - .expect("Huge transfer failed"); - spi_device_3 - .transfer(&mut read[..], &write[..]) - .expect("Huge transfer failed"); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer in-place (No additional allocation - // needed) --- - print!("Starting huge transfer (in-place)..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - - spi_device_1 - .transfer_in_place(&mut write[..]) - .expect("Huge transfer failed"); - for byte in 0..write.len() { - assert_eq!(write[byte], byte as u8); - } - spi_device_2 - .transfer_in_place(&mut write[..]) - .expect("Huge transfer failed"); - spi_device_3 - .transfer_in_place(&mut write[..]) - .expect("Huge transfer failed"); - println!(" SUCCESS"); - delay.delay_ms(250u32); - } -} diff --git a/esp32h2-hal/examples/spi_eh1_loopback.rs b/esp32h2-hal/examples/spi_eh1_loopback.rs deleted file mode 100644 index 08a683713..000000000 --- a/esp32h2-hal/examples/spi_eh1_loopback.rs +++ /dev/null @@ -1,104 +0,0 @@ -//! SPI loopback test -//! -//! Folowing pins are used: -//! SCLK GPIO1 -//! MISO GPIO2 -//! MOSI GPIO3 -//! CS GPIO11 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use embedded_hal_1::spi::SpiBus; -use esp32h2_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{master::Spi, SpiMode}, - Delay, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio1; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio3; - let cs = io.pins.gpio11; - - let mut spi = Spi::new(peripherals.SPI2, 1000u32.kHz(), SpiMode::Mode0, &clocks).with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(cs), - ); - - let mut delay = Delay::new(&clocks); - println!("=== SPI example with embedded-hal-1 traits ==="); - - loop { - // --- Symmetric transfer (Read as much as we write) --- - print!("Starting symmetric transfer..."); - let write = [0xde, 0xad, 0xbe, 0xef]; - let mut read: [u8; 4] = [0x00u8; 4]; - - SpiBus::transfer(&mut spi, &mut read[..], &write[..]).expect("Symmetric transfer failed"); - assert_eq!(write, read); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Asymmetric transfer (Read more than we write) --- - print!("Starting asymetric transfer (read > write)..."); - let mut read: [u8; 4] = [0x00; 4]; - - SpiBus::transfer(&mut spi, &mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - assert_eq!(write[0], read[0]); - assert_eq!(read[2], 0x00u8); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer --- - // Only your RAM is the limit! - print!("Starting huge transfer..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - let mut read = [0x00u8; 4096]; - - SpiBus::transfer(&mut spi, &mut read[..], &write[..]).expect("Huge transfer failed"); - assert_eq!(write, read); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer in-place (No additional allocation - // needed) --- - print!("Starting huge transfer (in-place)..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - - SpiBus::transfer_in_place(&mut spi, &mut write[..]).expect("Huge transfer failed"); - for byte in 0..write.len() { - assert_eq!(write[byte], byte as u8); - } - println!(" SUCCESS"); - delay.delay_ms(250u32); - } -} diff --git a/esp32h2-hal/examples/spi_halfduplex_read_manufacturer_id.rs b/esp32h2-hal/examples/spi_halfduplex_read_manufacturer_id.rs deleted file mode 100644 index 8f820cd9c..000000000 --- a/esp32h2-hal/examples/spi_halfduplex_read_manufacturer_id.rs +++ /dev/null @@ -1,101 +0,0 @@ -//! SPI read manufacturer id from flash chip -//! -//! Folowing pins are used: -//! SCLK GPIO1 -//! MISOI/IO0 GPIO2 -//! MOSI/IO1 GPIO3 -//! IO2 GPIO4 -//! IO3 GPIO5 -//! CS GPIO11 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! Connect a flash chip (GD25Q64C was used) and make sure QE in the status -//! register is set. - -#![no_std] -#![no_main] - -use esp32h2_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{Address, Command, HalfDuplexReadWrite, Spi}, - SpiDataMode, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio1; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio3; - let sio2 = io.pins.gpio4; - let sio3 = io.pins.gpio5; - let cs = io.pins.gpio11; - - let mut spi = Spi::new_half_duplex(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(sio2), - Some(sio3), - Some(cs), - ); - - let mut delay = Delay::new(&clocks); - - loop { - // READ MANUFACTURER ID FROM FLASH CHIP - let mut data = [0u8; 2]; - spi.read( - SpiDataMode::Single, - Command::Command8(0x90, SpiDataMode::Single), - Address::Address24(0x000000, SpiDataMode::Single), - 0, - &mut data, - ) - .unwrap(); - println!("Single {:x?}", data); - delay.delay_ms(250u32); - - // READ MANUFACTURER ID FROM FLASH CHIP - let mut data = [0u8; 2]; - spi.read( - SpiDataMode::Dual, - Command::Command8(0x92, SpiDataMode::Single), - Address::Address32(0x000000_00, SpiDataMode::Dual), - 0, - &mut data, - ) - .unwrap(); - println!("Dual {:x?}", data); - delay.delay_ms(250u32); - - // READ MANUFACTURER ID FROM FLASH CHIP - let mut data = [0u8; 2]; - spi.read( - SpiDataMode::Quad, - Command::Command8(0x94, SpiDataMode::Single), - Address::Address32(0x000000_00, SpiDataMode::Quad), - 4, - &mut data, - ) - .unwrap(); - println!("Quad {:x?}", data); - delay.delay_ms(1500u32); - } -} diff --git a/esp32h2-hal/examples/spi_loopback_dma.rs b/esp32h2-hal/examples/spi_loopback_dma.rs deleted file mode 100644 index 57a85a5c6..000000000 --- a/esp32h2-hal/examples/spi_loopback_dma.rs +++ /dev/null @@ -1,90 +0,0 @@ -//! SPI loopback test using DMA -//! -//! Folowing pins are used: -//! SCLK GPIO1 -//! MISO GPIO2 -//! MOSI GPIO3 -//! CS GPIO11 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use esp32h2_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{prelude::*, Spi}, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio1; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio3; - let cs = io.pins.gpio11; - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(32000); - - let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) - .with_dma(dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let mut delay = Delay::new(&clocks); - - // DMA buffer require a static life-time - let mut send = tx_buffer; - let mut receive = rx_buffer; - let mut i = 0; - - for (i, v) in send.iter_mut().enumerate() { - *v = (i % 255) as u8; - } - - loop { - send[0] = i; - send[send.len() - 1] = i; - i = i.wrapping_add(1); - - let transfer = spi.dma_transfer(send, receive).unwrap(); - // here we could do something else while DMA transfer is in progress - // the buffers and spi is moved into the transfer and we can get it back via - // `wait` - (receive, send, spi) = transfer.wait().unwrap(); - println!( - "{:x?} .. {:x?}", - &receive[..10], - &receive[receive.len() - 10..] - ); - - delay.delay_ms(250u32); - } -} diff --git a/esp32h2-hal/examples/spi_slave_dma.rs b/esp32h2-hal/examples/spi_slave_dma.rs deleted file mode 100644 index 473918be0..000000000 --- a/esp32h2-hal/examples/spi_slave_dma.rs +++ /dev/null @@ -1,203 +0,0 @@ -//! SPI slave loopback test using DMA -//! -//! Following pins are used for the slave: -//! SCLK GPIO6 -//! MISO GPIO2 -//! MOSI GPIO7 -//! CS GPIO10 -//! -//! Following pins are used for the (bitbang) master: -//! SCLK GPIO5 -//! MISO GPIO1 -//! MOSI GPIO8 -//! CS GPIO9 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect corresponding master and slave pins to see the outgoing data is read -//! as incoming data. The master-side pins are chosen to make these connections -//! easy for the barebones ESP32C3 chip; all are immediate neighbors of the -//! slave-side pins except SCLK. SCLK is between MOSI and VDD3P3_RTC on the -//! barebones ESP32C3, so no immediate neighbor is available. - -#![no_std] -#![no_main] - -use esp32h2_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - slave::{prelude::*, Spi}, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let slave_sclk = io.pins.gpio4; - let mut master_sclk = io.pins.gpio5.into_push_pull_output(); - let slave_miso = io.pins.gpio2; - let master_miso = io.pins.gpio1.into_floating_input(); - let slave_mosi = io.pins.gpio12; - let mut master_mosi = io.pins.gpio11.into_push_pull_output(); - let slave_cs = io.pins.gpio10; - let mut master_cs = io.pins.gpio9.into_push_pull_output(); - master_cs.set_high().unwrap(); - master_sclk.set_low().unwrap(); - master_mosi.set_low().unwrap(); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(32000); - - let mut spi = Spi::new( - peripherals.SPI2, - slave_sclk, - slave_mosi, - slave_miso, - slave_cs, - SpiMode::Mode0, - ) - .with_dma(dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let mut delay = Delay::new(&clocks); - - // DMA buffer require a static life-time - let master_send = &mut [0u8; 32000]; - let master_receive = &mut [0u8; 32000]; - let mut slave_send = tx_buffer; - let mut slave_receive = rx_buffer; - let mut i = 0; - - for (i, v) in master_send.iter_mut().enumerate() { - *v = (i % 255) as u8; - } - for (i, v) in slave_send.iter_mut().enumerate() { - *v = (254 - (i % 255)) as u8; - } - - loop { - master_send[0] = i; - master_send[master_send.len() - 1] = i; - slave_send[0] = i; - slave_send[slave_send.len() - 1] = i; - slave_receive.fill(0xff); - i = i.wrapping_add(1); - - let transfer = spi.dma_transfer(slave_send, slave_receive).unwrap(); - // Bit-bang out the contents of master_send and read into master_receive - // as quickly as manageable. MSB first. Mode 0, so sampled on the rising - // edge and set on the falling edge. - master_cs.set_low().unwrap(); - for (j, v) in master_send.iter().enumerate() { - let mut b = *v; - let mut rb = 0u8; - for _ in 0..8 { - if b & 128 != 0 { - master_mosi.set_high().unwrap(); - } else { - master_mosi.set_low().unwrap(); - } - master_sclk.set_low().unwrap(); - b <<= 1; - rb <<= 1; - // NB: adding about 24 NOPs here makes the clock's duty cycle - // run at about 50% ... but we don't strictly need the delay, - // either. - master_sclk.set_high().unwrap(); - if master_miso.is_high().unwrap() { - rb |= 1; - } - } - master_receive[j] = rb; - } - master_cs.set_high().unwrap(); - master_sclk.set_low().unwrap(); - // the buffers and spi is moved into the transfer and we can get it back via - // `wait` - (slave_receive, slave_send, spi) = transfer.wait().unwrap(); - println!( - "slave got {:x?} .. {:x?}, master got {:x?} .. {:x?}", - &slave_receive[..10], - &slave_receive[slave_receive.len() - 10..], - &master_receive[..10], - &master_receive[master_receive.len() - 10..] - ); - - delay.delay_ms(250u32); - - slave_receive.fill(0xff); - let transfer = spi.dma_read(slave_receive).unwrap(); - master_cs.set_high().unwrap(); - - master_cs.set_low().unwrap(); - for v in master_send.iter() { - let mut b = *v; - for _ in 0..8 { - if b & 128 != 0 { - master_mosi.set_high().unwrap(); - } else { - master_mosi.set_low().unwrap(); - } - b <<= 1; - master_sclk.set_low().unwrap(); - master_sclk.set_high().unwrap(); - } - } - master_cs.set_high().unwrap(); - (slave_receive, spi) = transfer.wait().unwrap(); - println!( - "slave got {:x?} .. {:x?}", - &slave_receive[..10], - &slave_receive[slave_receive.len() - 10..], - ); - - delay.delay_ms(250u32); - let transfer = spi.dma_write(slave_send).unwrap(); - - master_receive.fill(0); - - master_cs.set_low().unwrap(); - for (j, _) in master_send.iter().enumerate() { - let mut rb = 0u8; - for _ in 0..8 { - master_sclk.set_low().unwrap(); - rb <<= 1; - master_sclk.set_high().unwrap(); - if master_miso.is_high().unwrap() { - rb |= 1; - } - } - master_receive[j] = rb; - } - master_cs.set_high().unwrap(); - (slave_send, spi) = transfer.wait().unwrap(); - - println!( - "master got {:x?} .. {:x?}", - &master_receive[..10], - &master_receive[master_receive.len() - 10..], - ); - println!(); - } -} diff --git a/esp32h2-hal/examples/systimer.rs b/esp32h2-hal/examples/systimer.rs deleted file mode 100644 index c17922c62..000000000 --- a/esp32h2-hal/examples/systimer.rs +++ /dev/null @@ -1,114 +0,0 @@ -//! This shows how to use the SYSTIMER peripheral including interrupts. -//! It's an additional timer besides the TIMG peripherals. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32h2_hal::{ - clock::ClockControl, - interrupt, - interrupt::Priority, - peripherals::{self, Peripherals}, - prelude::*, - systimer::{Alarm, Periodic, SystemTimer, Target}, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -static ALARM0: Mutex>>> = Mutex::new(RefCell::new(None)); -static ALARM1: Mutex>>> = Mutex::new(RefCell::new(None)); -static ALARM2: Mutex>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let syst = SystemTimer::new(peripherals.SYSTIMER); - - println!("SYSTIMER Current value = {}", SystemTimer::now()); - - let alarm0 = syst.alarm0.into_periodic(); - alarm0.set_period(1u32.secs()); - alarm0.clear_interrupt(); - alarm0.enable_interrupt(true); - - let alarm1 = syst.alarm1; - alarm1.set_target(SystemTimer::now() + (SystemTimer::TICKS_PER_SECOND * 2)); - alarm1.enable_interrupt(true); - - let alarm2 = syst.alarm2; - alarm2.set_target(SystemTimer::now() + (SystemTimer::TICKS_PER_SECOND * 3)); - alarm2.enable_interrupt(true); - - critical_section::with(|cs| { - ALARM0.borrow_ref_mut(cs).replace(alarm0); - ALARM1.borrow_ref_mut(cs).replace(alarm1); - ALARM2.borrow_ref_mut(cs).replace(alarm2); - }); - - interrupt::enable( - peripherals::Interrupt::SYSTIMER_TARGET0, - Priority::Priority1, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::SYSTIMER_TARGET1, - Priority::Priority2, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::SYSTIMER_TARGET2, - Priority::Priority2, - ) - .unwrap(); - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - loop { - delay.delay_ms(10000u32); - } -} - -#[interrupt] -fn SYSTIMER_TARGET0() { - println!("Interrupt lvl1 (alarm0)"); - critical_section::with(|cs| { - ALARM0 - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .clear_interrupt() - }); -} - -#[interrupt] -fn SYSTIMER_TARGET1() { - println!("Interrupt lvl2 (alarm1)"); - critical_section::with(|cs| { - ALARM1 - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .clear_interrupt() - }); -} - -#[interrupt] -fn SYSTIMER_TARGET2() { - println!("Interrupt lvl2 (alarm2)"); - critical_section::with(|cs| { - ALARM2 - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .clear_interrupt() - }); -} diff --git a/esp32h2-hal/examples/timer_interrupt.rs b/esp32h2-hal/examples/timer_interrupt.rs deleted file mode 100644 index d4e2c7f56..000000000 --- a/esp32h2-hal/examples/timer_interrupt.rs +++ /dev/null @@ -1,86 +0,0 @@ -//! This shows how to use the TIMG peripheral interrupts. -//! There is TIMG0 and TIMG1 each of them containing a general purpose timer and -//! a watchdog timer. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32h2_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals, TIMG0, TIMG1}, - prelude::*, - timer::{Timer, Timer0, TimerGroup}, -}; -use esp_backtrace as _; - -static TIMER0: Mutex>>>> = Mutex::new(RefCell::new(None)); -static TIMER1: Mutex>>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks); - let mut timer1 = timer_group1.timer0; - - interrupt::enable( - peripherals::Interrupt::TG0_T0_LEVEL, - interrupt::Priority::Priority2, - ) - .unwrap(); - - timer0.start(500u64.millis()); - - timer0.listen(); - - interrupt::enable( - peripherals::Interrupt::TG1_T0_LEVEL, - interrupt::Priority::Priority2, - ) - .unwrap(); - - timer1.start(1u64.secs()); - timer1.listen(); - - critical_section::with(|cs| { - TIMER0.borrow_ref_mut(cs).replace(timer0); - TIMER1.borrow_ref_mut(cs).replace(timer1); - }); - - loop {} -} - -#[interrupt] -fn TG0_T0_LEVEL() { - critical_section::with(|cs| { - esp_println::println!("Interrupt 1"); - - let mut timer0 = TIMER0.borrow_ref_mut(cs); - let timer0 = timer0.as_mut().unwrap(); - - timer0.clear_interrupt(); - timer0.start(500u64.millis()); - }); -} - -#[interrupt] -fn TG1_T0_LEVEL() { - critical_section::with(|cs| { - esp_println::println!("Interrupt 11"); - - let mut timer1 = TIMER1.borrow_ref_mut(cs); - let timer1 = timer1.as_mut().unwrap(); - - timer1.clear_interrupt(); - timer1.start(1u64.secs()); - }); -} diff --git a/esp32h2-hal/examples/usb_serial_jtag.rs b/esp32h2-hal/examples/usb_serial_jtag.rs deleted file mode 100644 index 8d65b1e10..000000000 --- a/esp32h2-hal/examples/usb_serial_jtag.rs +++ /dev/null @@ -1,78 +0,0 @@ -//! This shows how to output text via USB Serial/JTAG. -//! You need to connect via the Serial/JTAG interface to see any output. -//! Most dev-kits use a USB-UART-bridge - in that case you won't see any output. - -#![no_std] -#![no_main] - -use core::{cell::RefCell, fmt::Write}; - -use critical_section::Mutex; -use esp32h2_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, - timer::TimerGroup, - Cpu, - UsbSerialJtag, -}; -use esp_backtrace as _; -use nb::block; - -static USB_SERIAL: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let mut usb_serial = UsbSerialJtag::new(peripherals.USB_DEVICE); - - usb_serial.listen_rx_packet_recv_interrupt(); - - timer0.start(1u64.secs()); - - critical_section::with(|cs| USB_SERIAL.borrow_ref_mut(cs).replace(usb_serial)); - - interrupt::enable( - peripherals::Interrupt::USB_DEVICE, - interrupt::Priority::Priority1, - ) - .unwrap(); - - interrupt::set_kind( - Cpu::ProCpu, - interrupt::CpuInterrupt::Interrupt1, - interrupt::InterruptKind::Edge, - ); - - loop { - critical_section::with(|cs| { - writeln!( - USB_SERIAL.borrow_ref_mut(cs).as_mut().unwrap(), - "Hello world!" - ) - .ok(); - }); - - block!(timer0.wait()).unwrap(); - } -} - -#[interrupt] -fn USB_DEVICE() { - critical_section::with(|cs| { - let mut usb_serial = USB_SERIAL.borrow_ref_mut(cs); - let usb_serial = usb_serial.as_mut().unwrap(); - writeln!(usb_serial, "USB serial interrupt").unwrap(); - while let nb::Result::Ok(c) = usb_serial.read_byte() { - writeln!(usb_serial, "Read byte: {:02x}", c).unwrap(); - } - usb_serial.reset_rx_packet_recv_interrupt(); - }); -} diff --git a/esp32h2-hal/examples/watchdog.rs b/esp32h2-hal/examples/watchdog.rs deleted file mode 100644 index 863a8ab6c..000000000 --- a/esp32h2-hal/examples/watchdog.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! This demos the watchdog timer. -//! Basically the same as `hello_world` but if you remove the call to -//! `wdt.feed()` the watchdog will reset the system. - -#![no_std] -#![no_main] - -use esp32h2_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, timer::TimerGroup}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - let mut wdt0 = timer_group0.wdt; - - wdt0.start(2u64.secs()); - timer0.start(1u64.secs()); - - loop { - wdt0.feed(); - println!("Hello world!"); - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32h2-hal/src/lib.rs b/esp32h2-hal/src/lib.rs deleted file mode 100644 index f8f7ef7b9..000000000 --- a/esp32h2-hal/src/lib.rs +++ /dev/null @@ -1,9 +0,0 @@ -//! A bare-metal (`no_std`) Hardware Abstraction Layer for the ESP32-H2 from -//! Espressif. -//! -//! ## Feature Flags -#![doc = document_features::document_features!()] -#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/46717278")] -#![no_std] - -pub use esp_hal::*; diff --git a/esp32p4-hal/.cargo/config.toml b/esp32p4-hal/.cargo/config.toml deleted file mode 100644 index a3cbbc562..000000000 --- a/esp32p4-hal/.cargo/config.toml +++ /dev/null @@ -1,12 +0,0 @@ -[target.riscv32imafc-unknown-none-elf] -runner = "espflash flash --monitor" -rustflags = [ - "-C", "link-arg=-Tlinkall.x", - "-C", "force-frame-pointers", -] - -[build] -target = "riscv32imafc-unknown-none-elf" - -[unstable] -build-std = ["core"] diff --git a/esp32p4-hal/Cargo.toml b/esp32p4-hal/Cargo.toml deleted file mode 100644 index c73c3bf28..000000000 --- a/esp32p4-hal/Cargo.toml +++ /dev/null @@ -1,97 +0,0 @@ -[package] -name = "esp32p4-hal" -version = "0.1.0" -edition = "2021" -rust-version = "1.67.0" -description = "HAL for ESP32-P4 microcontrollers" -repository = "https://github.com/esp-rs/esp-hal" -license = "MIT OR Apache-2.0" - -keywords = [ - "embedded", - "embedded-hal", - "esp", - "esp32p4", - "no-std", -] -categories = [ - "embedded", - "hardware-support", - "no-std", -] - -[package.metadata.docs.rs] -targets = ["riscv32imafc-unknown-none-elf"] - -[dependencies] -document-features = "0.2.7" -esp-hal = { version = "0.15.0", features = ["esp32p4"], path = "../esp-hal" } -embassy-time-driver = { version = "0.1.0", optional = true } - -[dev-dependencies] -embassy-time = "0.3.0" -esp-backtrace = { version = "0.10.0", features = ["esp32p4", "exception-handler", "panic-handler", "println"] } -esp-println = { version = "0.8.0", features = ["esp32p4"] } - -[features] -default = ["embassy-integrated-timers", "rt", "vectored", "zero-rtc-bss"] - -## Enable debug features in the HAL (used for development). -debug = ["esp-hal/debug"] -## Enable direct interrupt vectoring. -direct-vectoring = ["esp-hal/direct-vectoring"] -## Enable interrupt preemption. -interrupt-preemption = ["esp-hal/interrupt-preemption"] -## Enable logging output using the `log` crate. -log = ["esp-hal/log", "esp-println/log"] -## Enable runtime support. -rt = ["esp-hal/rt-riscv"] -## Enable interrupt vectoring. -vectored = ["esp-hal/vectored"] - -#! ### Trait Implementation Feature Flags -## Enable support for asynchronous operation, with interfaces provided by -## `embedded-hal-async` and `embedded-io-async`. -async = ["esp-hal/async"] -## Implement `defmt::Format` on certain types. -defmt = ["esp-hal/defmt", "esp-println/defmt-espflash"] -## Implement the traits defined in the `1.0.0` releases of `embedded-hal` and -## `embedded-hal-nb` for the relevant peripherals. -eh1 = ["esp-hal/eh1"] -## Implement the traits defined in `embedded-io` for certain peripherals. -embedded-io = ["esp-hal/embedded-io"] -## Implement the `ufmt_write::uWrite` trait for certain peripherals. -ufmt = ["esp-hal/ufmt"] - -#! ### Memory Initialization Feature Flags -## Zero the `.bss` section of low-power memory. -zero-rtc-bss = ["esp-hal/rv-zero-rtc-bss"] -## Initialize the `.data` section of memory. -init-data = ["esp-hal/rv-init-data"] -## Initialize the `.data` section of low-power memory. -init-rtc-data = ["esp-hal/rv-init-rtc-data"] - -#! ### Embassy Feature Flags -## Enable support for `embassy`, a modern asynchronous embedded framework. -embassy = ["esp-hal/embassy"] -## Use the interrupt-mode embassy executor. -embassy-executor-interrupt = ["esp-hal/embassy-executor-interrupt"] -## Use the thread-mode embassy executor. -embassy-executor-thread = ["esp-hal/embassy-executor-thread"] -## Uses hardware timers as alarms for the executors. Using this feature -## limits the number of executors to the number of hardware alarms provided -## by the time driver. -embassy-integrated-timers = ["esp-hal/embassy-integrated-timers"] -## Enable the embassy time driver using the `SYSTIMER` peripheral. The -## `SYSTIMER` peripheral has three alarams available for use. -embassy-time-systick = ["esp-hal/embassy-time-systick", "embassy-time-driver/tick-hz-16_000_000"] -## Enable the embassy time driver using the `TIMG0` peripheral. The `TIMG0` -## peripheral has two alarms available for use. -embassy-time-timg0 = ["esp-hal/embassy-time-timg0", "embassy-time-driver/tick-hz-1_000_000"] - -[profile.release] -debug = true - -[patch.crates-io] -esp-backtrace = { git = "https://github.com/esp-rs/esp-backtrace", rev = "edf2387" } -esp-println = { git = "https://github.com/esp-rs/esp-println", rev = "1f628e3" } diff --git a/esp32p4-hal/README.md b/esp32p4-hal/README.md deleted file mode 100644 index 5e32c5198..000000000 --- a/esp32p4-hal/README.md +++ /dev/null @@ -1,51 +0,0 @@ -# esp32p4-hal - -[![Crates.io](https://img.shields.io/crates/v/esp32p4-hal?labelColor=1C2C2E&color=C96329&logo=Rust&style=flat-square)](https://crates.io/crates/esp32p4-hal) -[![docs.rs](https://img.shields.io/docsrs/esp32p4-hal?labelColor=1C2C2E&color=C96329&logo=rust&style=flat-square)](https://docs.rs/esp32p4-hal) -![Crates.io](https://img.shields.io/crates/l/esp32p4-hal?labelColor=1C2C2E&style=flat-square) -[![Matrix](https://img.shields.io/matrix/esp-rs:matrix.org?label=join%20matrix&labelColor=1C2C2E&color=BEC5C9&logo=matrix&style=flat-square)](https://matrix.to/#/#esp-rs:matrix.org) - -`no_std` HAL for the ESP32-P4 from Espressif. - -Implements a number of the traits defined in [embedded-hal](https://github.com/rust-embedded/embedded-hal). - -This device uses the RISC-V ISA, which is officially supported by the Rust compiler via the `riscv32imafc-unknown-none-elf` target. - -Please refer to the documentation for more information. - -## [Documentation] - -[documentation]: https://docs.rs/esp32p4-hal/ - -## Resources - -- [Datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-p4_datasheet_en.pdf) -- [Technical Reference Manual](https://www.espressif.com/sites/default/files/documentation/esp32-p4_technical_reference_manual_en.pdf) -- [The Rust Programming Language](https://doc.rust-lang.org/book/) -- [The Embedded Rust Book](https://docs.rust-embedded.org/book/index.html) -- [The Rust on ESP Book](https://esp-rs.github.io/book/) - -## Getting Started - -### Installing the Rust Compiler Target - -The compilation target for this device is officially supported by the mainline Rust compiler and can be installed using [rustup](https://rustup.rs/): - -```shell -rustup target add riscv32imafc-unknown-none-elf -``` - -## License - -Licensed under either of: - -- Apache License, Version 2.0 ([LICENSE-APACHE](../LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) -- MIT license ([LICENSE-MIT](../LICENSE-MIT) or http://opensource.org/licenses/MIT) - -at your option. - -### Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in -the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without -any additional terms or conditions. diff --git a/esp32p4-hal/build.rs b/esp32p4-hal/build.rs deleted file mode 100644 index 023b7905b..000000000 --- a/esp32p4-hal/build.rs +++ /dev/null @@ -1,16 +0,0 @@ -use std::{env, error::Error, path::PathBuf}; - -fn main() -> Result<(), Box> { - // Put the linker script somewhere the linker can find it - let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - println!("cargo:rustc-link-search={}", out.display()); - - // Only re-run the build script when memory.x is changed, - // instead of when any part of the source code changes. - println!("cargo:rerun-if-changed=ld/memory.x"); - - #[cfg(feature = "defmt")] - println!("cargo:rustc-link-arg=-Tdefmt.x"); - - Ok(()) -} diff --git a/esp32p4-hal/examples/hello_world.rs b/esp32p4-hal/examples/hello_world.rs deleted file mode 100644 index 341a85355..000000000 --- a/esp32p4-hal/examples/hello_world.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![no_std] -#![no_main] - -use esp32p4_hal::{ - clock::{ClockControl, CpuClock}, - peripherals::Peripherals, - prelude::*, - system::SystemExt, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::configure(system.clock_control, CpuClock::Clock90MHz).freeze(); - - esp_println::println!("Hello, world!"); - loop {} -} diff --git a/esp32p4-hal/src/lib.rs b/esp32p4-hal/src/lib.rs deleted file mode 100644 index 630b9b79d..000000000 --- a/esp32p4-hal/src/lib.rs +++ /dev/null @@ -1,9 +0,0 @@ -//! A bare-metal (`no_std`) Hardware Abstraction Layer for the ESP32-P4 from -//! Espressif. -//! -//! ## Feature Flags -#![doc = document_features::document_features!()] -#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/46717278")] -#![no_std] - -pub use esp_hal::*; diff --git a/esp32s2-hal/.cargo/config.toml b/esp32s2-hal/.cargo/config.toml deleted file mode 100644 index 6dc7d859d..000000000 --- a/esp32s2-hal/.cargo/config.toml +++ /dev/null @@ -1,17 +0,0 @@ -[target.xtensa-esp32s2-none-elf] -runner = "espflash flash --monitor" - -[build] -rustflags = [ - # GNU LD - "-C", "link-arg=-nostartfiles", - "-C", "link-arg=-Wl,-Tlinkall.x", - - # LLD - # "-C", "linker=rust-lld", - # "-C", "link-arg=-Tlinkall.x", -] -target = "xtensa-esp32s2-none-elf" - -[unstable] -build-std = ["core", "alloc"] diff --git a/esp32s2-hal/Cargo.toml b/esp32s2-hal/Cargo.toml deleted file mode 100644 index 0a87a1fcd..000000000 --- a/esp32s2-hal/Cargo.toml +++ /dev/null @@ -1,160 +0,0 @@ -[package] -name = "esp32s2-hal" -version = "0.15.0" -edition = "2021" -rust-version = "1.67.0" -description = "HAL for ESP32-S2 microcontrollers" -repository = "https://github.com/esp-rs/esp-hal" -license = "MIT OR Apache-2.0" - -keywords = [ - "embedded", - "embedded-hal", - "esp", - "esp32s2", - "no-std", -] -categories = [ - "embedded", - "hardware-support", - "no-std", -] - -[dependencies] -document-features = "0.2.7" -esp-hal = { version = "0.15.0", features = ["esp32s2"], path = "../esp-hal" } -embassy-time-driver = { version = "0.1.0", optional = true } - -[dev-dependencies] -aes = "0.8.3" -critical-section = "1.1.2" -crypto-bigint = { version = "0.5.5", default-features = false } -embassy-executor = { version = "0.5.0", features = ["nightly"] } -embassy-sync = "0.5.0" -embassy-time = "0.3.0" -embedded-graphics = "0.8.1" -embedded-hal-1 = { version = "1.0.0", package = "embedded-hal" } -embedded-hal-async = "1.0.0" -embedded-io-async = "0.6.1" -embedded-hal-bus = "0.1.0" -esp-alloc = "0.3.0" -esp-backtrace = { version = "0.10.0", features = ["esp32s2", "panic-handler", "print-uart", "exception-handler"] } -esp-hal-smartled = { version = "0.8.0", features = ["esp32s2"], path = "../esp-hal-smartled" } -esp-println = { version = "0.8.0", features = ["esp32s2"] } -heapless = { version = "0.8.0", features = ["portable-atomic"] } -hmac = { version = "0.12.1", default-features = false } -lis3dh-async = "0.9.1" -sha2 = { version = "0.10.8", default-features = false } -smart-leds = "0.4.0" -ssd1306 = "0.8.4" -static_cell = { version = "2.0.0", features = ["nightly"] } -usb-device = "0.3.1" -usbd-serial = "0.2.0" - -[features] -default = ["embassy-integrated-timers", "rt", "vectored"] - -## Enable debug features in the HAL (used for development). -debug = ["esp-hal/debug"] -## Enable logging output using the `log` crate. -log = ["esp-hal/log", "esp-println/log"] -## Enable runtime support. -rt = ["esp-hal/rt-xtensa"] -## Enable interrupt vectoring. -vectored = ["esp-hal/vectored"] - -#! ### Trait Implementation Feature Flags -## Enable support for asynchronous operation, with interfaces provided by -## `embedded-hal-async` and `embedded-io-async`. -async = ["esp-hal/async"] -## Implement `defmt::Format` on certain types. -defmt = ["esp-hal/defmt", "esp-println/defmt-espflash"] -## Implement the traits defined in the `1.0.0` releases of `embedded-hal` and -## `embedded-hal-nb` for the relevant peripherals. -eh1 = ["esp-hal/eh1"] -## Implement the traits defined in `embedded-io` for certain peripherals. -embedded-io = ["esp-hal/embedded-io"] -## Implement the `ufmt_write::uWrite` trait for certain peripherals. -ufmt = ["esp-hal/ufmt"] - -#! ### PSRAM Feature Flags -psram = [] -## Use externally connected PSRAM (2MB). -psram-2m = ["esp-hal/psram-2m", "psram"] -## Use externally connected PSRAM (4MB). -psram-4m = ["esp-hal/psram-4m", "psram"] -## Use externally connected PSRAM (8MB). -psram-8m = ["esp-hal/psram-8m", "psram"] - -#! ### Embassy Feature Flags -## Enable support for `embassy`, a modern asynchronous embedded framework. -embassy = ["esp-hal/embassy"] -## Use the interrupt-mode embassy executor. -embassy-executor-interrupt = ["esp-hal/embassy-executor-interrupt"] -## Use the thread-mode embassy executor. -embassy-executor-thread = ["esp-hal/embassy-executor-thread"] -## Uses hardware timers as alarms for the executors. Using this feature -## limits the number of executors to the number of hardware alarms provided -## by the time driver. -embassy-integrated-timers = ["esp-hal/embassy-integrated-timers"] -## Enable the embassy time driver using the `SYSTIMER` peripheral. The -## `SYSTIMER` peripheral has three alarams available for use. -embassy-time-systick = ["esp-hal/embassy-time-systick", "embassy-time-driver/tick-hz-80_000_000"] -## Enable the embassy time driver using the `TIMG0` peripheral. The `TIMG0` -## peripheral has two alarms available for use. -embassy-time-timg0 = ["esp-hal/embassy-time-timg0", "embassy-time-driver/tick-hz-1_000_000"] - -[profile.release] -debug = true - -[[example]] -name = "spi_eh1_loopback" -required-features = ["eh1"] - -[[example]] -name = "spi_eh1_device_loopback" -required-features = ["eh1"] - -[[example]] -name = "embassy_hello_world" -required-features = ["embassy", "embassy-executor-thread"] - -[[example]] -name = "embassy_multiprio" -required-features = ["embassy", "embassy-executor-interrupt"] - -[[example]] -name = "embassy_wait" -required-features = ["embassy", "embassy-executor-thread", "async"] - -[[example]] -name = "embassy_spi" -required-features = ["embassy", "embassy-executor-thread", "async"] - -[[example]] -name = "psram" -required-features = ["psram-2m"] - -[[example]] -name = "embassy_serial" -required-features = ["embassy", "embassy-executor-thread", "async"] - -[[example]] -name = "embassy_i2c" -required-features = ["embassy", "embassy-executor-thread", "async"] - -[[example]] -name = "embassy_rmt_tx" -required-features = ["embassy", "async"] - -[[example]] -name = "embassy_rmt_rx" -required-features = ["embassy", "async"] - -[[example]] -name = "embassy_i2s_sound" -required-features = ["embassy", "async"] - -[[example]] -name = "embassy_i2s_read" -required-features = ["embassy", "async"] diff --git a/esp32s2-hal/README.md b/esp32s2-hal/README.md deleted file mode 100644 index 03bbb46f0..000000000 --- a/esp32s2-hal/README.md +++ /dev/null @@ -1,60 +0,0 @@ -# esp32s2-hal - -[![Crates.io](https://img.shields.io/crates/v/esp32s2-hal?labelColor=1C2C2E&color=C96329&logo=Rust&style=flat-square)](https://crates.io/crates/esp32s2-hal) -[![docs.rs](https://img.shields.io/docsrs/esp32s2-hal?labelColor=1C2C2E&color=C96329&logo=rust&style=flat-square)](https://docs.rs/esp32s2-hal) -![Crates.io](https://img.shields.io/crates/l/esp32s2-hal?labelColor=1C2C2E&style=flat-square) -[![Matrix](https://img.shields.io/matrix/esp-rs:matrix.org?label=join%20matrix&labelColor=1C2C2E&color=BEC5C9&logo=matrix&style=flat-square)](https://matrix.to/#/#esp-rs:matrix.org) - -`no_std` HAL for the ESP32 from Espressif. - -Implements a number of the traits defined in [embedded-hal](https://github.com/rust-embedded/embedded-hal). - -This device uses the Xtensa ISA, which is not officially supported by the Rust compiler. In order to develop for this device, you must use the Rust compiler fork with Xtensa support, found at [esp-rs/rust](https://github.com/esp-rs/rust). - -Please refer to the documentation for more information. - -## [Documentation] - -[documentation]: https://docs.rs/esp32s2-hal/ - -## Resources - -- [Datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s2_datasheet_en.pdf) -- [Technical Reference Manual](https://www.espressif.com/sites/default/files/documentation/esp32-s2_technical_reference_manual_en.pdf) -- [The Rust Programming Language](https://doc.rust-lang.org/book/) -- [The Embedded Rust Book](https://docs.rust-embedded.org/book/index.html) -- [The Rust on ESP Book](https://esp-rs.github.io/book/) - -## Getting Started - -### Installing the Rust Compiler - -We provide a tool, [espup](https://github.com/esp-rs/espup/), for easily installing the Rust toolchain with Xtensa support: - -```shell -cargo install espup -espup install -``` - -Following installation of the Xtensa toolchain, if you are running a Unix-like operating system (macOS, Linux) then you must additionally export the necessary environment variables: - -```shell -. $HOME/export-esp.sh -``` - -See the [Installation chapter of The Rust on ESP Book](https://esp-rs.github.io/book/installation/index.html) for more details. - -## License - -Licensed under either of: - -- Apache License, Version 2.0 ([LICENSE-APACHE](../LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) -- MIT license ([LICENSE-MIT](../LICENSE-MIT) or http://opensource.org/licenses/MIT) - -at your option. - -### Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in -the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without -any additional terms or conditions. diff --git a/esp32s2-hal/build.rs b/esp32s2-hal/build.rs deleted file mode 100644 index 67e3ba808..000000000 --- a/esp32s2-hal/build.rs +++ /dev/null @@ -1,36 +0,0 @@ -use std::{env, error::Error, fs::File, io::Write, path::PathBuf}; - -fn main() -> Result<(), Box> { - // Put the linker script somewhere the linker can find it - let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - println!("cargo:rustc-link-search={}", out.display()); - - let memory_extras = generate_memory_extras(); - File::create(out.join("memory_extras.x"))?.write_all(&memory_extras)?; - - // Only re-run the build script when memory.x is changed, - // instead of when any part of the source code changes. - println!("cargo:rerun-if-changed=ld/memory.x"); - - #[cfg(feature = "defmt")] - println!("cargo:rustc-link-arg=-Tdefmt.x"); - - Ok(()) -} - -fn generate_memory_extras() -> Vec { - let reserved_cache = if cfg!(feature = "psram") { - "0x4000" - } else { - "0x2000" - }; - - format!( - " - /* reserved at the start of DRAM/IRAM */ - RESERVE_CACHES = {reserved_cache}; - " - ) - .as_bytes() - .to_vec() -} diff --git a/esp32s2-hal/examples/adc.rs b/esp32s2-hal/examples/adc.rs deleted file mode 100644 index 4baec96e6..000000000 --- a/esp32s2-hal/examples/adc.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! Connect a potentiometer to PIN3 and see the read values change when -//! rotating the shaft. Alternatively you could also connect the PIN to GND or -//! 3V3 to see the maximum and minimum raw values read. - -#![no_std] -#![no_main] - -use esp32s2_hal::{ - adc::{AdcConfig, Attenuation, ADC}, - clock::ClockControl, - gpio::IO, - peripherals::{Peripherals, ADC1}, - prelude::*, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create ADC instances - let mut adc1_config = AdcConfig::new(); - let mut pin3 = - adc1_config.enable_pin(io.pins.gpio3.into_analog(), Attenuation::Attenuation11dB); - let mut adc1 = ADC::::new(peripherals.ADC1, adc1_config); - - let mut delay = Delay::new(&clocks); - - loop { - let pin3_value: u16 = nb::block!(adc1.read(&mut pin3)).unwrap(); - println!("PIN3 ADC reading = {}", pin3_value); - delay.delay_ms(1500u32); - } -} diff --git a/esp32s2-hal/examples/aes.rs b/esp32s2-hal/examples/aes.rs deleted file mode 100644 index 14955466c..000000000 --- a/esp32s2-hal/examples/aes.rs +++ /dev/null @@ -1,85 +0,0 @@ -//! Encrypt/Decrypt a message using AES. - -#![no_std] -#![no_main] -use aes::{ - cipher::{generic_array::GenericArray, BlockDecrypt, BlockEncrypt, KeyInit}, - Aes128 as Aes128SW, -}; -use esp32s2_hal::{ - aes::{Aes, Mode}, - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - xtensa_lx, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut aes = Aes::new(peripherals.AES); - - let keytext = "SUp4SeCp@sSw0rd".as_bytes(); - let plaintext = "message".as_bytes(); - - // create an array with aes128 key size - let mut keybuf = [0_u8; 16]; - keybuf[..keytext.len()].copy_from_slice(keytext); - - // create an array with aes block size - let mut block_buf = [0_u8; 16]; - block_buf[..plaintext.len()].copy_from_slice(plaintext); - - let mut block = block_buf.clone(); - let pre_hw_encrypt = xtensa_lx::timer::get_cycle_count(); - aes.process(&mut block, Mode::Encryption128, &keybuf); - let post_hw_encrypt = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for hw encrypt", - post_hw_encrypt - pre_hw_encrypt - ); - let hw_encrypted = block.clone(); - let pre_hw_decrypt = xtensa_lx::timer::get_cycle_count(); - aes.process(&mut block, Mode::Decryption128, &keybuf); - let post_hw_decrypt = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for hw decrypt", - post_hw_decrypt - pre_hw_decrypt - ); - let hw_decrypted = block; - - let key = GenericArray::from(keybuf); - let mut block = GenericArray::from(block_buf); - let cipher = Aes128SW::new(&key); - let pre_sw_encrypt = xtensa_lx::timer::get_cycle_count(); - cipher.encrypt_block(&mut block); - let post_sw_encrypt = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for sw encrypt", - post_sw_encrypt - pre_sw_encrypt - ); - let sw_encrypted = block.clone(); - let pre_sw_decrypt = xtensa_lx::timer::get_cycle_count(); - cipher.decrypt_block(&mut block); - let post_sw_decrypt = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for sw decrypt", - post_sw_decrypt - pre_sw_decrypt - ); - let sw_decrypted = block; - - assert!(eq(&sw_encrypted.into(), &hw_encrypted)); - assert!(eq(&sw_decrypted.into(), &hw_decrypted)); - - println!("done"); - - loop {} -} -fn eq(slice1: &[u8; 16], slice2: &[u8; 16]) -> bool { - slice1.iter().zip(slice2.iter()).all(|(a, b)| a == b) -} diff --git a/esp32s2-hal/examples/blinky.rs b/esp32s2-hal/examples/blinky.rs deleted file mode 100644 index 922c6489b..000000000 --- a/esp32s2-hal/examples/blinky.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! Blinks an LED -//! -//! This assumes that a LED is connected to the pin assigned to `led`. (GPIO4) - -#![no_std] -#![no_main] - -use esp32s2_hal::{clock::ClockControl, gpio::IO, peripherals::Peripherals, prelude::*, Delay}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Set GPIO4 as an output, and set its state high initially. - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut led = io.pins.gpio4.into_push_pull_output(); - - led.set_high().unwrap(); - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - loop { - led.toggle().unwrap(); - delay.delay_ms(500u32); - } -} diff --git a/esp32s2-hal/examples/clock_monitor.rs b/esp32s2-hal/examples/clock_monitor.rs deleted file mode 100644 index 8ddfbda16..000000000 --- a/esp32s2-hal/examples/clock_monitor.rs +++ /dev/null @@ -1,64 +0,0 @@ -//! This demos a simple monitor for the XTAL frequency, by relying on a special -//! feature of the TIMG0 (Timer Group 0). This feature counts the number of XTAL -//! clock cycles within a given number of RTC_SLOW_CLK cycles. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32s2_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, - Rtc, -}; -use esp_backtrace as _; -use esp_println::println; - -static RTC: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rtc = Rtc::new(peripherals.LPWR); - rtc.rwdt.start(2000u64.millis()); - rtc.rwdt.listen(); - - println!( - "{: <10} XTAL frequency: {} MHz", - "[Expected]", - clocks.xtal_clock.to_MHz() - ); - - interrupt::enable( - peripherals::Interrupt::RTC_CORE, - interrupt::Priority::Priority1, - ) - .unwrap(); - - critical_section::with(|cs| RTC.borrow_ref_mut(cs).replace(rtc)); - - loop {} -} - -#[interrupt] -fn RTC_CORE() { - critical_section::with(|cs| { - let mut rtc = RTC.borrow_ref_mut(cs); - let rtc = rtc.as_mut().unwrap(); - - println!( - "{: <10} XTAL frequency: {} MHz", - "[Monitor]", - rtc.estimate_xtal_frequency() - ); - - rtc.rwdt.clear_interrupt(); - }); -} diff --git a/esp32s2-hal/examples/crc.rs b/esp32s2-hal/examples/crc.rs deleted file mode 100644 index 205eebbc5..000000000 --- a/esp32s2-hal/examples/crc.rs +++ /dev/null @@ -1,97 +0,0 @@ -//! This shows example usage of the CRC functions in ROM - -#![no_std] -#![no_main] - -use core::fmt::Write; - -use esp32s2_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - rom::{crc, md5}, - timer::TimerGroup, - Uart, -}; -use esp_backtrace as _; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - - timer0.start(1u64.secs()); - - let data = "123456789"; - let sentence = "The quick brown fox jumps over a lazy dog"; - - writeln!( - uart0, - "Performing CRC calculations on test string \"{data}\"" - ) - .unwrap(); - - loop { - let crc_hdlc = crc::crc32_le(!0xffffffff, data.as_ref()); - let crc_bzip2 = crc::crc32_be(!0xffffffff, data.as_ref()); - let crc_mpeg2 = !crc::crc32_be(!0xffffffff, data.as_ref()); - let crc_cksum = crc::crc32_be(!0, data.as_ref()); - let crc_kermit = !crc::crc16_le(!0, data.as_ref()); - let crc_genibus = crc::crc16_be(!0xffff, data.as_ref()); - let crc_rohc = !crc::crc8_le(!0xff, data.as_ref()); - let crc_smbus = !crc::crc8_be(!0, data.as_ref()); - - assert_eq!(crc_hdlc, 0xcbf43926); - assert_eq!(crc_bzip2, 0xfc891918); - assert_eq!(crc_mpeg2, 0x0376e6e7); - assert_eq!(crc_cksum, 0x765e7680); - assert_eq!(crc_kermit, 0x2189); - assert_eq!(crc_genibus, 0xd64e); - assert_eq!(crc_rohc, 0xd0); - assert_eq!(crc_smbus, 0xf4); - - // Hash the sentence one word at a time to *really* test the context - // Use Peekable while iter_intersperse is unstable - let mut md5_ctx = md5::Context::new(); - let mut it = sentence.split_whitespace().peekable(); - while let Some(word) = it.next() { - md5_ctx.consume(word); - if it.peek().is_some() { - md5_ctx.consume(" "); - } - } - let md5_digest = md5_ctx.compute(); - - assert_eq!( - md5_digest, - md5::Digest([ - 0x30, 0xde, 0xd8, 0x07, 0xd6, 0x5e, 0xe0, 0x37, 0x0f, 0xc6, 0xd7, 0x3d, 0x6a, 0xb5, - 0x5a, 0x95 - ]) - ); - - writeln!( - uart0, - "{:08x} {:08x} {:08x} {:08x} {:04x} {:04x} {:02x} {:02x} {}", - crc_hdlc, - crc_bzip2, - crc_mpeg2, - crc_cksum, - crc_kermit, - crc_genibus, - crc_rohc, - crc_smbus, - md5_digest - ) - .unwrap(); - - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32s2-hal/examples/embassy_hello_world.rs b/esp32s2-hal/examples/embassy_hello_world.rs deleted file mode 100644 index 1ecb0bcc7..000000000 --- a/esp32s2-hal/examples/embassy_hello_world.rs +++ /dev/null @@ -1,53 +0,0 @@ -//! embassy hello world -//! -//! This is an example of running the embassy executor with multiple tasks -//! concurrently. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32s2_hal::{ - clock::ClockControl, - embassy::{self}, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; - -#[embassy_executor::task] -async fn run() { - loop { - esp_println::println!("Hello world from embassy using esp-hal-async!"); - Timer::after(Duration::from_millis(1_000)).await; - } -} - -#[main] -async fn main(spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32s2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - spawner.spawn(run()).ok(); - - loop { - esp_println::println!("Bing!"); - Timer::after(Duration::from_millis(5_000)).await; - } -} diff --git a/esp32s2-hal/examples/embassy_i2c.rs b/esp32s2-hal/examples/embassy_i2c.rs deleted file mode 100644 index 3460b89b6..000000000 --- a/esp32s2-hal/examples/embassy_i2c.rs +++ /dev/null @@ -1,67 +0,0 @@ -//! Embassy I2C -//! -//! Folowing pins are used: -//! SDA GPIO1 -//! SCL GPIO2 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This is an example of running the embassy executor with IC2. It uses an -//! LIS3DH to get accelerometer data. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32s2_hal::{ - clock::ClockControl, - embassy::{self}, - i2c::I2C, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; -use lis3dh_async::{Lis3dh, Range, SlaveAddr}; - -#[main] -async fn main(_spawner: Spawner) { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32s2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let i2c0 = I2C::new( - peripherals.I2C0, - io.pins.gpio1, - io.pins.gpio2, - 400u32.kHz(), - &clocks, - ); - - let mut lis3dh = Lis3dh::new_i2c(i2c0, SlaveAddr::Alternate).await.unwrap(); - lis3dh.set_range(Range::G8).await.unwrap(); - - loop { - let norm = lis3dh.accel_norm().await.unwrap(); - esp_println::println!("X: {:+.5} Y: {:+.5} Z: {:+.5}", norm.x, norm.y, norm.z); - - Timer::after(Duration::from_millis(100)).await; - } -} diff --git a/esp32s2-hal/examples/embassy_i2s_read.rs b/esp32s2-hal/examples/embassy_i2s_read.rs deleted file mode 100644 index 8bc98be56..000000000 --- a/esp32s2-hal/examples/embassy_i2s_read.rs +++ /dev/null @@ -1,97 +0,0 @@ -//! This shows how to continuously receive data via I2S -//! -//! Pins used -//! BCLK GPIO1 -//! WS GPIO2 -//! DIN GPIO3 -//! -//! Without an additional I2S source device you can connect 3V3 or GND to DIN to -//! read 0 or 0xFF or connect DIN to WS to read two different values -//! -//! You can also inspect the BCLK and WS with a logic analyzer - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use esp32s2_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - embassy::{self}, - i2s::{asynch::*, DataFormat, I2s, Standard}, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -#[main] -async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32s2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.i2s0channel; - - let (_, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(0, 4092 * 4); - - let i2s = I2s::new( - peripherals.I2S0, - Standard::Philips, - DataFormat::Data16Channel16, - 44100u32.Hz(), - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - &clocks, - ); - - let i2s_rx = i2s - .i2s_rx - .with_bclk(io.pins.gpio1) - .with_ws(io.pins.gpio2) - .with_din(io.pins.gpio5) - .build(); - - let buffer = rx_buffer; - println!("Start"); - - let mut data = [0u8; 5000]; - let mut transaction = i2s_rx.read_dma_circular_async(buffer).unwrap(); - loop { - let avail = transaction.available().await; - println!("available {}", avail); - - let count = transaction.pop(&mut data).await.unwrap(); - println!( - "got {} bytes, {:x?}..{:x?}", - count, - &data[..10], - &data[count - 10..count] - ); - } -} diff --git a/esp32s2-hal/examples/embassy_i2s_sound.rs b/esp32s2-hal/examples/embassy_i2s_sound.rs deleted file mode 100644 index 36d57fdbb..000000000 --- a/esp32s2-hal/examples/embassy_i2s_sound.rs +++ /dev/null @@ -1,136 +0,0 @@ -//! This shows how to transmit data continously via I2S -//! -//! Pins used -//! MCLK GPIO4 -//! BCLK GPIO1 -//! WS GPIO2 -//! DOUT GPIO3 -//! -//! Without an additional I2S sink device you can inspect the MCLK, BCLK, WS and -//! DOUT with a logic analyzer -//! -//! You can also connect e.g. a PCM510x to hear an annoying loud sine tone (full -//! scale), so turn down the volume before running this example. -//! -//! Wiring is like this -//! -//! | Pin | Connected to | -//! |-------|-----------------| -//! | BCK | GPIO1 | -//! | DIN | GPIO3 | -//! | LRCK | GPIO2 | -//! | SCK | Gnd | -//! | GND | Gnd | -//! | VIN | +3V3 | -//! | FLT | Gnd | -//! | FMT | Gnd | -//! | DEMP | Gnd | -//! | XSMT | +3V3 | - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use esp32s2_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - embassy::{self}, - i2s::{asynch::*, DataFormat, I2s, Standard}, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -const SINE: [i16; 64] = [ - 0, 3211, 6392, 9511, 12539, 15446, 18204, 20787, 23169, 25329, 27244, 28897, 30272, 31356, - 32137, 32609, 32767, 32609, 32137, 31356, 30272, 28897, 27244, 25329, 23169, 20787, 18204, - 15446, 12539, 9511, 6392, 3211, 0, -3211, -6392, -9511, -12539, -15446, -18204, -20787, -23169, - -25329, -27244, -28897, -30272, -31356, -32137, -32609, -32767, -32609, -32137, -31356, -30272, - -28897, -27244, -25329, -23169, -20787, -18204, -15446, -12539, -9511, -6392, -3211, -]; - -#[main] -async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32s2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.i2s0channel; - - let (tx_buffer, mut tx_descriptors, _, mut rx_descriptors) = dma_buffers!(32000, 0); - - let i2s = I2s::new( - peripherals.I2S0, - Standard::Philips, - DataFormat::Data16Channel16, - 44100u32.Hz(), - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - &clocks, - ); - - let i2s_tx = i2s - .i2s_tx - .with_bclk(io.pins.gpio1) - .with_ws(io.pins.gpio2) - .with_dout(io.pins.gpio3) - .build(); - - let data = - unsafe { core::slice::from_raw_parts(&SINE as *const _ as *const u8, SINE.len() * 2) }; - - let buffer = tx_buffer; - let mut idx = 0; - for i in 0..usize::min(data.len(), buffer.len()) { - buffer[i] = data[idx]; - - idx += 1; - - if idx >= data.len() { - idx = 0; - } - } - - let mut filler = [0u8; 10000]; - let mut idx = 32000 % data.len(); - - println!("Start"); - let mut transaction = i2s_tx.write_dma_circular_async(buffer).unwrap(); - - loop { - for i in 0..filler.len() { - filler[i] = data[(idx + i) % data.len()]; - } - println!("Next"); - - let written = transaction.push(&filler).await.unwrap(); - idx = (idx + written) % data.len(); - println!("written {}", written); - } -} diff --git a/esp32s2-hal/examples/embassy_multiprio.rs b/esp32s2-hal/examples/embassy_multiprio.rs deleted file mode 100644 index 1d040fec2..000000000 --- a/esp32s2-hal/examples/embassy_multiprio.rs +++ /dev/null @@ -1,100 +0,0 @@ -//! This example shows how to use the interrupt executors to prioritize some -//! tasks over others. -//! -//! The example creates three tasks: -//! - A low priority task that is not actually async, but simulates some -//! blocking work. This task will run for 5 seconds, then sleep for 5 -//! seconds. -//! - A low priority task that is actually async, but will not be able to run -//! while the blocking task is running. -//! - A high priority task that prints something every second. The example -//! demonstrates that this task will continue to run even while the low -//! priority blocking task is running. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Instant, Ticker, Timer}; -use esp32s2_hal::{ - clock::ClockControl, - embassy::{ - self, - executor::{FromCpu1, InterruptExecutor}, - }, - interrupt::Priority, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; -use esp_println::println; - -static INT_EXECUTOR_0: InterruptExecutor = InterruptExecutor::new(); - -#[interrupt] -fn FROM_CPU_INTR1() { - unsafe { INT_EXECUTOR_0.on_interrupt() } -} - -/// Periodically print something. -#[embassy_executor::task] -async fn high_prio() { - println!("Starting high_prio()"); - let mut ticker = Ticker::every(Duration::from_secs(1)); - loop { - println!("High priority ticks"); - ticker.next().await; - } -} - -/// Simulates some blocking (badly behaving) task. -#[embassy_executor::task] -async fn low_prio_blocking() { - println!("Starting low-priority task that isn't actually async"); - loop { - println!("Doing some long and complicated calculation"); - let start = Instant::now(); - while start.elapsed() < Duration::from_secs(5) {} - println!("Calculation finished"); - Timer::after(Duration::from_secs(5)).await; - } -} - -/// A well-behaved, but starved async task. -#[embassy_executor::task] -async fn low_prio_async() { - println!("Starting low-priority task that will not be able to run while the blocking task is running"); - let mut ticker = Ticker::every(Duration::from_secs(1)); - loop { - println!("Low priority ticks"); - ticker.next().await; - } -} - -#[main] -async fn main(low_prio_spawner: Spawner) { - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32s2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let spawner = INT_EXECUTOR_0.start(Priority::Priority2); - spawner.must_spawn(high_prio()); - - println!("Spawning low-priority tasks"); - low_prio_spawner.must_spawn(low_prio_async()); - low_prio_spawner.must_spawn(low_prio_blocking()); -} diff --git a/esp32s2-hal/examples/embassy_serial.rs b/esp32s2-hal/examples/embassy_serial.rs deleted file mode 100644 index 9e94ad0fc..000000000 --- a/esp32s2-hal/examples/embassy_serial.rs +++ /dev/null @@ -1,96 +0,0 @@ -//! embassy serial -//! -//! This is an example of running the embassy executor and asynchronously -//! writing to and reading from uart - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_sync::{blocking_mutex::raw::NoopRawMutex, signal::Signal}; -use esp32s2_hal::{ - clock::ClockControl, - embassy, - peripherals::{Peripherals, UART0}, - prelude::*, - uart::{config::AtCmdConfig, UartRx, UartTx}, - Uart, -}; -use esp_backtrace as _; -use static_cell::make_static; - -// rx_fifo_full_threshold -const READ_BUF_SIZE: usize = 64; -// EOT (CTRL-D) -const AT_CMD: u8 = 0x04; - -#[embassy_executor::task] -async fn writer(mut tx: UartTx<'static, UART0>, signal: &'static Signal) { - use core::fmt::Write; - embedded_io_async::Write::write( - &mut tx, - b"Hello async serial. Enter something ended with EOT (CTRL-D).\r\n", - ) - .await - .unwrap(); - embedded_io_async::Write::flush(&mut tx).await.unwrap(); - loop { - let bytes_read = signal.wait().await; - signal.reset(); - write!(&mut tx, "\r\n-- received {} bytes --\r\n", bytes_read).unwrap(); - embedded_io_async::Write::flush(&mut tx).await.unwrap(); - } -} - -#[embassy_executor::task] -async fn reader(mut rx: UartRx<'static, UART0>, signal: &'static Signal) { - const MAX_BUFFER_SIZE: usize = 10 * READ_BUF_SIZE + 16; - - let mut rbuf: [u8; MAX_BUFFER_SIZE] = [0u8; MAX_BUFFER_SIZE]; - let mut offset = 0; - loop { - let r = embedded_io_async::Read::read(&mut rx, &mut rbuf[offset..]).await; - match r { - Ok(len) => { - offset += len; - esp_println::println!("Read: {len}, data: {:?}", &rbuf[..offset]); - offset = 0; - signal.signal(len); - } - Err(e) => esp_println::println!("RX Error: {:?}", e), - } - } -} - -#[main] -async fn main(spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32s2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - uart0.set_at_cmd(AtCmdConfig::new(None, None, None, AT_CMD, None)); - uart0 - .set_rx_fifo_full_threshold(READ_BUF_SIZE as u16) - .unwrap(); - let (tx, rx) = uart0.split(); - - let signal = &*make_static!(Signal::new()); - - spawner.spawn(reader(rx, &signal)).ok(); - spawner.spawn(writer(tx, &signal)).ok(); -} diff --git a/esp32s2-hal/examples/embassy_spi.rs b/esp32s2-hal/examples/embassy_spi.rs deleted file mode 100644 index bdc6f42d0..000000000 --- a/esp32s2-hal/examples/embassy_spi.rs +++ /dev/null @@ -1,87 +0,0 @@ -//! Embassy SPI -//! -//! Folowing pins are used: -//! SCLK GPIO36 -//! MISO GPIO37 -//! MOSI GPIO35 -//! CS GPIO34 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. -//! -//! This is an example of running the embassy executor with SPI. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32s2_hal::{ - clock::ClockControl, - dma::{DmaPriority, *}, - dma_descriptors, - embassy::{self}, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{prelude::*, Spi}, - SpiMode, - }, - IO, -}; -use esp_backtrace as _; - -#[main] -async fn main(_spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32s2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio36; - let miso = io.pins.gpio37; - let mosi = io.pins.gpio35; - let cs = io.pins.gpio34; - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.spi2channel; - - let (mut descriptors, mut rx_descriptors) = dma_descriptors!(32000); - - let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) - .with_dma(dma_channel.configure( - false, - &mut descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let send_buffer = [0, 1, 2, 3, 4, 5, 6, 7]; - loop { - let mut buffer = [0; 8]; - esp_println::println!("Sending bytes"); - embedded_hal_async::spi::SpiBus::transfer(&mut spi, &mut buffer, &send_buffer) - .await - .unwrap(); - esp_println::println!("Bytes recieved: {:?}", buffer); - Timer::after(Duration::from_millis(5_000)).await; - } -} diff --git a/esp32s2-hal/examples/embassy_wait.rs b/esp32s2-hal/examples/embassy_wait.rs deleted file mode 100644 index 5c15e70c6..000000000 --- a/esp32s2-hal/examples/embassy_wait.rs +++ /dev/null @@ -1,50 +0,0 @@ -//! embassy wait -//! -//! This is an example of asynchronously `Wait`ing for a pin state to change. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use embedded_hal_async::digital::Wait; -use esp32s2_hal::{ - clock::ClockControl, - embassy::{self}, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; - -#[main] -async fn main(_spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32s2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - // GPIO 0 as input - let mut input = io.pins.gpio0.into_pull_down_input(); - - loop { - esp_println::println!("Waiting..."); - input.wait_for_rising_edge().await.unwrap(); - esp_println::println!("Ping!"); - Timer::after(Duration::from_millis(100)).await; - } -} diff --git a/esp32s2-hal/examples/gpio_interrupt.rs b/esp32s2-hal/examples/gpio_interrupt.rs deleted file mode 100644 index d40012a2e..000000000 --- a/esp32s2-hal/examples/gpio_interrupt.rs +++ /dev/null @@ -1,69 +0,0 @@ -//! GPIO interrupt -//! -//! This prints "Interrupt" when the boot button is pressed. -//! It also blinks an LED like the blinky example. - -#![no_std] -#![no_main] -#![feature(asm_experimental_arch)] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32s2_hal::{ - clock::ClockControl, - gpio::{Event, Gpio0, Input, PullDown, IO}, - interrupt, - macros::ram, - peripherals::{self, Peripherals}, - prelude::*, - xtensa_lx, - Delay, -}; -use esp_backtrace as _; - -static BUTTON: Mutex>>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Set GPIO15 as an output, and set its state high initially. - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut led = io.pins.gpio15.into_push_pull_output(); - let mut button = io.pins.gpio0.into_pull_down_input(); - button.listen(Event::FallingEdge); - - critical_section::with(|cs| BUTTON.borrow_ref_mut(cs).replace(button)); - - interrupt::enable(peripherals::Interrupt::GPIO, interrupt::Priority::Priority2).unwrap(); - - led.set_high().unwrap(); - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - loop { - led.toggle().unwrap(); - delay.delay_ms(500u32); - } -} - -#[ram] -#[interrupt] -fn GPIO() { - esp_println::println!( - "GPIO Interrupt with priority {}", - xtensa_lx::interrupt::get_level() - ); - critical_section::with(|cs| { - BUTTON - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .clear_interrupt() - }); -} diff --git a/esp32s2-hal/examples/hello_rgb.rs b/esp32s2-hal/examples/hello_rgb.rs deleted file mode 100644 index b72064340..000000000 --- a/esp32s2-hal/examples/hello_rgb.rs +++ /dev/null @@ -1,66 +0,0 @@ -//! RGB LED Demo -//! -//! This example drives an SK68XX RGB LED that is connected to GPIO18. -//! A RGB LED is connected to that pin on the official DevKits. -//! -//! The demo will leverage the [`smart_leds`](https://crates.io/crates/smart-leds) -//! crate functionality to circle through the HSV hue color space (with -//! saturation and value both at 255). Additionally, we apply a gamma correction -//! and limit the brightness to 10 (out of 255). - -#![no_std] -#![no_main] - -use esp32s2_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, rmt::Rmt, Delay, IO}; -use esp_backtrace as _; -use esp_hal_smartled::{smartLedBuffer, SmartLedsAdapter}; -use smart_leds::{ - brightness, - gamma, - hsv::{hsv2rgb, Hsv}, - SmartLedsWrite, -}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Configure RMT peripheral globally - let rmt = Rmt::new(peripherals.RMT, 80u32.MHz(), &clocks).unwrap(); - - // We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can - // be used directly with all `smart_led` implementations - let rmt_buffer = smartLedBuffer!(1); - let mut led = SmartLedsAdapter::new(rmt.channel0, io.pins.gpio18, rmt_buffer, &clocks); - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - let mut color = Hsv { - hue: 0, - sat: 255, - val: 255, - }; - let mut data; - - loop { - // Iterate over the rainbow! - for hue in 0..=255 { - color.hue = hue; - // Convert from the HSV color space (where we can easily transition from one - // color to the other) to the RGB color space that we can then send to the LED - data = [hsv2rgb(color)]; - // When sending to the LED, we do a gamma correction first (see smart_leds - // documentation for details) and then limit the brightness to 10 out of 255 so - // that the output it's not too bright. - led.write(brightness(gamma(data.iter().cloned()), 10)) - .unwrap(); - delay.delay_ms(20u8); - } - } -} diff --git a/esp32s2-hal/examples/hmac.rs b/esp32s2-hal/examples/hmac.rs deleted file mode 100644 index 1a4fcfed2..000000000 --- a/esp32s2-hal/examples/hmac.rs +++ /dev/null @@ -1,121 +0,0 @@ -//! Demonstrates the use of the HMAC peripheral and compares the speed of -//! hardware-accelerated and pure software hashing. -//! -//! # Writing key -//! Before using the HMAC accelerator in upstream mode, you first need to -//! prepare a secret 256-bit HMAC key and burn the key to an empty eFuse block. -//! -//! ## ⚠️ Before writing ⚠️ -//! - From the factory, the eFuse keyblocks are programmed to be 32-byte 0x00. -//! - This example is programmed to use this value so you can skip this step if -//! you don't want to burn an eFuse key. -//! - If you skip the skip burning a custom key, you still need to [burn the -//! purpose](#burn-key-purpose). -//! - [Read more about eFuses](https://docs.espressif.com/projects/esptool/en/latest/esp32s3/espefuse/index.html) -//! -//! ## Burn key purpose -//! You first need to burn the efuse key purpose for the specified key below -//! (Default Key0). Purposes: -//! -//! | Purpose | Mode | Value | Description | -//! |--------------------------------|------------|-------|-----------------------------------------------| -//! | JTAG Re-enable | Downstream | 6 | EFUSE_KEY_PURPOSE_HMAC_DOWN_JTAG | -//! | DS Key Derivation | Downstream | 7 | EFUSE_KEY_PURPOSE_HMAC_DOWN_DIGITAL_SIGNATURE | -//! | HMAC Calculation | Upstream | 8 | EFUSE_KEY_PURPOSE_HMAC_UP | -//! | Both JTAG Re-enable and DS KDF | Downstream | 5 | EFUSE_KEY_PURPOSE_HMAC_DOWN_ALL | -//! -//! To burn the efuse key purpose `HMAC_UP` to `Key0`: -//! ```sh -//! espefuse.py burn_efuse KEY_PURPOSE_0 8 -//! ``` -//! -//! ## Use a custom key -//! You can generate a custom key file from a string using the following command -//! ```sh -//! echo -n "" | openssl dgst -sha256 -binary > key.bin -//! ``` -//! -//! You can then write your key using the following command -//! - `BLOCK_KEY0` The keyblock to program the key to. By default this example -//! uses key0. -//! - `HMAC_UP` The purpose for the key. Use HMAC_UP for upstream. -//! - `--no-read-protect` Allow to read the key from software, after writing it. -//! ```sh -//! espefuse.py burn_key BLOCK_KEY0 key.bin HMAC_UP --no-read-protect -//! ``` -//! To see the key in bytes, you can do the following: -//! ```sh -//! echo -n "" | openssl dgst -sha256 -binary | xxd -p -//! ``` -//! or from the binary file -//! ```sh -//! xxd -p key.bin -//! ``` - -#![no_std] -#![no_main] - -use esp32s2_hal::{ - clock::ClockControl, - hmac::{Hmac, HmacPurpose, KeyId}, - peripherals::Peripherals, - prelude::*, - systimer::SystemTimer, - Rng, -}; -use esp_backtrace as _; -use esp_println::println; -use hmac::{Hmac as HmacSw, Mac}; -use nb::block; -use sha2::Sha256; - -type HmacSha256 = HmacSw; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rng = Rng::new(peripherals.RNG); - - // Set sw key - let key = [0_u8; 32].as_ref(); - - let mut hw_hmac = Hmac::new(peripherals.HMAC); - - let mut src = [0_u8; 1024]; - rng.read(src.as_mut_slice()).unwrap(); - // println!("HMAC input {:02X?}", src); - - let mut output = [0u8; 32]; - - println!("Beginning stress tests..."); - println!("Testing length from 0 to {:?} bytes for HMAC...", src.len()); - for i in 0..src.len() + 1 { - let (nsrc, _) = src.split_at(i); - let mut remaining = nsrc; - hw_hmac.init(); - block!(hw_hmac.configure(HmacPurpose::ToUser, KeyId::Key0)).expect("Key purpose mismatch"); - let pre_hw_hmac = SystemTimer::now(); - while remaining.len() > 0 { - remaining = block!(hw_hmac.update(remaining)).unwrap(); - } - block!(hw_hmac.finalize(output.as_mut_slice())).unwrap(); - let post_hw_hmac = SystemTimer::now(); - let hw_time = post_hw_hmac - pre_hw_hmac; - let mut sw_hmac = HmacSha256::new_from_slice(key).expect("HMAC can take key of any size"); - let pre_sw_hash = SystemTimer::now(); - sw_hmac.update(nsrc); - let soft_result = sw_hmac.finalize().into_bytes(); - let post_sw_hash = SystemTimer::now(); - let soft_time = post_sw_hash - pre_sw_hash; - for (a, b) in output.iter().zip(soft_result) { - assert_eq!(*a, b); - } - println!("Testing for length: {:>4} | HW: {:>6} cycles, SW: {:>7} cycles (HW HMAC is {:>2}x faster)", i, hw_time, soft_time, soft_time / hw_time); - } - println!("Finished stress tests!"); - - loop {} -} diff --git a/esp32s2-hal/examples/i2c_bmp180_calibration_data.rs b/esp32s2-hal/examples/i2c_bmp180_calibration_data.rs deleted file mode 100644 index 7d73fd9a8..000000000 --- a/esp32s2-hal/examples/i2c_bmp180_calibration_data.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! Read calibration data from BMP180 sensor -//! -//! This example dumps the calibration data from a BMP180 sensor -//! -//! The following wiring is assumed: -//! - SDA => GPIO35 -//! - SCL => GPIO36 - -#![no_std] -#![no_main] - -use esp32s2_hal::{clock::ClockControl, gpio::IO, i2c::I2C, peripherals::Peripherals, prelude::*}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create a new peripheral object with the described wiring - // and standard I2C clock speed - let mut i2c = I2C::new( - peripherals.I2C0, - io.pins.gpio35, - io.pins.gpio36, - 100u32.kHz(), - &clocks, - ); - - loop { - let mut data = [0u8; 22]; - i2c.write_read(0x77, &[0xaa], &mut data).ok(); - - println!("{:02x?}", data); - } -} diff --git a/esp32s2-hal/examples/i2c_display.rs b/esp32s2-hal/examples/i2c_display.rs deleted file mode 100644 index dd801b621..000000000 --- a/esp32s2-hal/examples/i2c_display.rs +++ /dev/null @@ -1,121 +0,0 @@ -//! I2C Display example -//! -//! This example prints some text on an SSD1306-based -//! display (via I2C) -//! -//! The following wiring is assumed: -//! - SDA => GPIO35 -//! - SCL => GPIO36 - -#![no_std] -#![no_main] - -use embedded_graphics::{ - mono_font::{ - ascii::{FONT_6X10, FONT_9X18_BOLD}, - MonoTextStyleBuilder, - }, - pixelcolor::BinaryColor, - prelude::*, - text::{Alignment, Text}, -}; -use esp32s2_hal::{ - clock::ClockControl, - gpio::IO, - i2c::I2C, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, -}; -use esp_backtrace as _; -use nb::block; -use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create a new peripheral object with the described wiring - // and standard I2C clock speed - let i2c = I2C::new( - peripherals.I2C0, - io.pins.gpio35, - io.pins.gpio36, - 100u32.kHz(), - &clocks, - ); - - // Start timer (5 second interval) - timer0.start(5u64.secs()); - - // Initialize display - let interface = I2CDisplayInterface::new(i2c); - let mut display = Ssd1306::new(interface, DisplaySize128x64, DisplayRotation::Rotate0) - .into_buffered_graphics_mode(); - display.init().unwrap(); - - // Specify different text styles - let text_style = MonoTextStyleBuilder::new() - .font(&FONT_6X10) - .text_color(BinaryColor::On) - .build(); - let text_style_big = MonoTextStyleBuilder::new() - .font(&FONT_9X18_BOLD) - .text_color(BinaryColor::On) - .build(); - - loop { - // Fill display bufffer with a centered text with two lines (and two text - // styles) - Text::with_alignment( - "esp-hal", - display.bounding_box().center() + Point::new(0, 0), - text_style_big, - Alignment::Center, - ) - .draw(&mut display) - .unwrap(); - - Text::with_alignment( - "Chip: ESP32S2", - display.bounding_box().center() + Point::new(0, 14), - text_style, - Alignment::Center, - ) - .draw(&mut display) - .unwrap(); - - // Write buffer to display - display.flush().unwrap(); - // Clear display buffer - display.clear(BinaryColor::Off).unwrap(); - - // Wait 5 seconds - block!(timer0.wait()).unwrap(); - - // Write single-line centered text "Hello World" to buffer - Text::with_alignment( - "Hello World!", - display.bounding_box().center(), - text_style_big, - Alignment::Center, - ) - .draw(&mut display) - .unwrap(); - - // Write buffer to display - display.flush().unwrap(); - // Clear display buffer - display.clear(BinaryColor::Off).unwrap(); - - // Wait 5 seconds - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32s2-hal/examples/i2s_read.rs b/esp32s2-hal/examples/i2s_read.rs deleted file mode 100644 index 9264f660c..000000000 --- a/esp32s2-hal/examples/i2s_read.rs +++ /dev/null @@ -1,76 +0,0 @@ -//! This shows how to continously receive data via I2S -//! -//! Pins used -//! BCLK GPIO1 -//! WS GPIO2 -//! DIN GPIO5 -//! -//! Without an additional I2S source device you can connect 3V3 or GND to DIN to -//! read 0 or 0xFF or connect DIN to WS to read two different values -//! -//! You can also inspect the MCLK, BCLK and WS with a logic analyzer - -#![no_std] -#![no_main] - -use esp32s2_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - i2s::{DataFormat, I2s, I2sReadDma, Standard}, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.i2s0channel; - - let (_, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(0, 4092 * 4); - - let i2s = I2s::new( - peripherals.I2S0, - Standard::Philips, - DataFormat::Data16Channel16, - 44100u32.Hz(), - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - &clocks, - ); - - let i2s_rx = i2s - .i2s_rx - .with_bclk(io.pins.gpio1) - .with_ws(io.pins.gpio2) - .with_din(io.pins.gpio5) - .build(); - - let buffer = rx_buffer; - - let mut transfer = i2s_rx.read_dma_circular(buffer).unwrap(); - println!("Started transfer"); - - loop { - let avail = transfer.available(); - - if avail > 0 { - let mut rcv = [0u8; 4092 * 4]; - transfer.pop(&mut rcv[..avail]).unwrap(); - println!("Received {:x?}...", &rcv[..30]); - } - } -} diff --git a/esp32s2-hal/examples/i2s_sound.rs b/esp32s2-hal/examples/i2s_sound.rs deleted file mode 100644 index d10fbbecc..000000000 --- a/esp32s2-hal/examples/i2s_sound.rs +++ /dev/null @@ -1,120 +0,0 @@ -//! This shows how to transmit data continously via I2S -//! -//! Pins used -//! MCLK GPIO4 -//! BCLK GPIO1 -//! WS GPIO2 -//! DOUT GPIO3 -//! -//! Without an additional I2S sink device you can inspect the MCLK, BCLK, WS and -//! DOUT with a logic analyzer -//! -//! You can also connect e.g. a PCM510x to hear an annoying loud sine tone (full -//! scale), so turn down the volume before running this example. -//! -//! Wiring is like this -//! -//! | Pin | Connected to | -//! |-------|-----------------| -//! | BCK | GPIO1 | -//! | DIN | GPIO3 | -//! | LRCK | GPIO2 | -//! | SCK | Gnd | -//! | GND | Gnd | -//! | VIN | +3V3 | -//! | FLT | Gnd | -//! | FMT | Gnd | -//! | DEMP | Gnd | -//! | XSMT | +3V3 | - -#![no_std] -#![no_main] - -use esp32s2_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - i2s::{DataFormat, I2s, I2sWriteDma, Standard}, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; - -const SINE: [i16; 64] = [ - 0, 3211, 6392, 9511, 12539, 15446, 18204, 20787, 23169, 25329, 27244, 28897, 30272, 31356, - 32137, 32609, 32767, 32609, 32137, 31356, 30272, 28897, 27244, 25329, 23169, 20787, 18204, - 15446, 12539, 9511, 6392, 3211, 0, -3211, -6392, -9511, -12539, -15446, -18204, -20787, -23169, - -25329, -27244, -28897, -30272, -31356, -32137, -32609, -32767, -32609, -32137, -31356, -30272, - -28897, -27244, -25329, -23169, -20787, -18204, -15446, -12539, -9511, -6392, -3211, -]; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.i2s0channel; - - let (tx_buffer, mut tx_descriptors, _, mut rx_descriptors) = dma_buffers!(32000, 0); - - let i2s = I2s::new( - peripherals.I2S0, - Standard::Philips, - DataFormat::Data16Channel16, - 44100u32.Hz(), - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - &clocks, - ) - .with_mclk(io.pins.gpio4); - - let i2s_tx = i2s - .i2s_tx - .with_bclk(io.pins.gpio1) - .with_ws(io.pins.gpio2) - .with_dout(io.pins.gpio3) - .build(); - - let data = - unsafe { core::slice::from_raw_parts(&SINE as *const _ as *const u8, SINE.len() * 2) }; - - let buffer = tx_buffer; - let mut idx = 0; - for i in 0..usize::min(data.len(), buffer.len()) { - buffer[i] = data[idx]; - - idx += 1; - - if idx >= data.len() { - idx = 0; - } - } - - let mut filler = [0u8; 10000]; - - let mut transfer = i2s_tx.write_dma_circular(buffer).unwrap(); - loop { - let avail = transfer.available(); - if avail > 0 { - let avail = usize::min(10000, avail); - for bidx in 0..avail { - filler[bidx] = data[idx]; - idx += 1; - - if idx >= data.len() { - idx = 0; - } - } - transfer.push(&filler[0..avail]).unwrap(); - } - } -} diff --git a/esp32s2-hal/examples/ledc.rs b/esp32s2-hal/examples/ledc.rs deleted file mode 100644 index c3bcc5ba5..000000000 --- a/esp32s2-hal/examples/ledc.rs +++ /dev/null @@ -1,68 +0,0 @@ -//! Turns on LED with the option to change LED intensity depending on `duty` -//! value. Possible values (`u32`) are in range 0..100. -//! -//! This assumes that a LED is connected to the pin assigned to `led`. (GPIO4) - -#![no_std] -#![no_main] - -use esp32s2_hal::{ - clock::ClockControl, - gpio::IO, - ledc::{ - channel::{self, ChannelIFace}, - timer::{self, TimerIFace}, - LSGlobalClkSource, - LowSpeed, - LEDC, - }, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let led = io.pins.gpio4.into_push_pull_output(); - - let mut ledc = LEDC::new(peripherals.LEDC, &clocks); - - ledc.set_global_slow_clock(LSGlobalClkSource::APBClk); - - let mut lstimer0 = ledc.get_timer::(timer::Number::Timer2); - - lstimer0 - .configure(timer::config::Config { - duty: timer::config::Duty::Duty5Bit, - clock_source: timer::LSClockSource::APBClk, - frequency: 24u32.kHz(), - }) - .unwrap(); - - let mut channel0 = ledc.get_channel(channel::Number::Channel0, led); - channel0 - .configure(channel::config::Config { - timer: &lstimer0, - duty_pct: 10, - pin_config: channel::config::PinConfig::PushPull, - }) - .unwrap(); - - channel0.start_duty_fade(0, 100, 2000).expect_err( - "Fading from 0% to 100%, at 24kHz and 5-bit resolution, over 2 seconds, should fail", - ); - - loop { - // Set up a breathing LED: fade from off to on over a second, then - // from on back off over the next second. Then loop. - channel0.start_duty_fade(0, 100, 1000).unwrap(); - while channel0.is_duty_fade_running() {} - channel0.start_duty_fade(100, 0, 1000).unwrap(); - while channel0.is_duty_fade_running() {} - } -} diff --git a/esp32s2-hal/examples/pcnt_encoder.rs b/esp32s2-hal/examples/pcnt_encoder.rs deleted file mode 100644 index a6b30004e..000000000 --- a/esp32s2-hal/examples/pcnt_encoder.rs +++ /dev/null @@ -1,134 +0,0 @@ -//! PCNT Encoder Demo -//! -//! This example decodes a quadrature encoder -//! -//! Since the PCNT units reset to zero when they reach their limits -//! we enable an interrupt on the upper and lower limits and -//! track the overflow in an AtomicI32 - -#![no_std] -#![no_main] -use core::{ - cell::RefCell, - cmp::min, - sync::atomic::{AtomicI32, Ordering}, -}; - -use critical_section::Mutex; -use esp32s2_hal as esp_hal; -use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - interrupt, - pcnt::{channel, channel::PcntSource, unit, PCNT}, - peripherals::{self, Peripherals}, - prelude::*, - IO, -}; -use esp_println::println; - -static UNIT0: Mutex>> = Mutex::new(RefCell::new(None)); -static VALUE: AtomicI32 = AtomicI32::new(0); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let unit_number = unit::Number::Unit1; - - // setup a pulse couter - println!("setup pulse counter unit 0"); - let pcnt = PCNT::new(peripherals.PCNT); - let mut u0 = pcnt.get_unit(unit_number); - u0.configure(unit::Config { - low_limit: -100, - high_limit: 100, - filter: Some(min(10u16 * 80, 1023u16)), - ..Default::default() - }) - .unwrap(); - - println!("setup channel 0"); - let mut ch0 = u0.get_channel(channel::Number::Channel0); - let mut pin_a = io.pins.gpio5.into_pull_up_input(); - let mut pin_b = io.pins.gpio6.into_pull_up_input(); - - ch0.configure( - PcntSource::from_pin(&mut pin_a), - PcntSource::from_pin(&mut pin_b), - channel::Config { - lctrl_mode: channel::CtrlMode::Reverse, - hctrl_mode: channel::CtrlMode::Keep, - pos_edge: channel::EdgeMode::Decrement, - neg_edge: channel::EdgeMode::Increment, - invert_ctrl: false, - invert_sig: false, - }, - ); - - println!("setup channel 1"); - let mut ch1 = u0.get_channel(channel::Number::Channel1); - ch1.configure( - PcntSource::from_pin(&mut pin_b), - PcntSource::from_pin(&mut pin_a), - channel::Config { - lctrl_mode: channel::CtrlMode::Reverse, - hctrl_mode: channel::CtrlMode::Keep, - pos_edge: channel::EdgeMode::Increment, - neg_edge: channel::EdgeMode::Decrement, - invert_ctrl: false, - invert_sig: false, - }, - ); - println!("subscribing to events"); - u0.events(unit::Events { - low_limit: true, - high_limit: true, - thresh0: false, - thresh1: false, - zero: false, - }); - - println!("enabling interrupts"); - u0.listen(); - println!("resume pulse counter unit 0"); - u0.resume(); - - critical_section::with(|cs| UNIT0.borrow_ref_mut(cs).replace(u0)); - - interrupt::enable(peripherals::Interrupt::PCNT, interrupt::Priority::Priority2).unwrap(); - - let mut last_value: i32 = 0; - loop { - critical_section::with(|cs| { - let mut u0 = UNIT0.borrow_ref_mut(cs); - let u0 = u0.as_mut().unwrap(); - let value: i32 = u0.get_value() as i32 + VALUE.load(Ordering::SeqCst); - if value != last_value { - println!("value: {value}"); - last_value = value; - } - }); - } -} - -#[interrupt] -fn PCNT() { - critical_section::with(|cs| { - let mut u0 = UNIT0.borrow_ref_mut(cs); - let u0 = u0.as_mut().unwrap(); - if u0.interrupt_set() { - let events = u0.get_events(); - if events.high_limit { - VALUE.store(VALUE.load(Ordering::SeqCst) + 100, Ordering::SeqCst); - } else if events.low_limit { - VALUE.store(VALUE.load(Ordering::SeqCst) - 100, Ordering::SeqCst); - } - u0.reset_interrupt(); - } - }); -} diff --git a/esp32s2-hal/examples/psram.rs b/esp32s2-hal/examples/psram.rs deleted file mode 100644 index e688fb091..000000000 --- a/esp32s2-hal/examples/psram.rs +++ /dev/null @@ -1,49 +0,0 @@ -//! This shows how to use PSRAM as heap-memory via esp-alloc -//! -//! You need an ESP32-S2 with at least 2 MB of PSRAM memory. - -#![no_std] -#![no_main] - -use esp32s2_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, psram}; -use esp_backtrace as _; -use esp_println::println; - -extern crate alloc; - -#[global_allocator] -static ALLOCATOR: esp_alloc::EspHeap = esp_alloc::EspHeap::empty(); - -fn init_psram_heap() { - unsafe { - ALLOCATOR.init(psram::PSRAM_VADDR_START as *mut u8, psram::PSRAM_BYTES); - } -} - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - psram::init_psram(peripherals.PSRAM); - init_psram_heap(); - - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - println!("Going to access PSRAM"); - - let mut large_vec: alloc::vec::Vec = alloc::vec::Vec::with_capacity(500 * 1024 / 4); - - for i in 0..(500 * 1024 / 4) { - large_vec.push((i & 0xff) as u32); - } - - println!("vec size = {} bytes", large_vec.len() * 4); - println!("vec address = {:p}", large_vec.as_ptr()); - - let string = alloc::string::String::from("A string allocated in PSRAM"); - println!("'{}' allocated at {:p}", &string, string.as_ptr()); - - println!("done"); - - loop {} -} diff --git a/esp32s2-hal/examples/ram.rs b/esp32s2-hal/examples/ram.rs deleted file mode 100644 index 98ce1e5f5..000000000 --- a/esp32s2-hal/examples/ram.rs +++ /dev/null @@ -1,97 +0,0 @@ -//! This shows how to use RTC memory. -//! RTC memory is retained during resets and during most sleep modes. -//! Initialized memory is always re-initialized on startup. -//! Uninitialzed memory isn't initialized on startup and can be used to keep -//! data during resets. Zeroed memory is initialized to zero on startup. -//! We can also run code from RTC memory. - -#![no_std] -#![no_main] - -use esp32s2_hal::{ - clock::ClockControl, - macros::ram, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, - Rtc, -}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; - -#[ram(rtc_fast)] -static mut SOME_INITED_DATA: [u8; 2] = [0xaa, 0xbb]; - -#[ram(rtc_fast, uninitialized)] -static mut SOME_UNINITED_DATA: [u8; 2] = [0; 2]; - -#[ram(rtc_fast, zeroed)] -static mut SOME_ZEROED_DATA: [u8; 8] = [0; 8]; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - // The RWDT flash boot protection must be enabled, as it is triggered as part of - // the example. - let mut rtc = Rtc::new(peripherals.LPWR); - rtc.rwdt.enable(); - - timer0.start(1u64.secs()); - - println!( - "IRAM function located at {:p}", - function_in_ram as *const () - ); - unsafe { - println!("SOME_INITED_DATA {:x?}", SOME_INITED_DATA); - println!("SOME_UNINITED_DATA {:x?}", SOME_UNINITED_DATA); - println!("SOME_ZEROED_DATA {:x?}", SOME_ZEROED_DATA); - - SOME_INITED_DATA[0] = 0xff; - SOME_ZEROED_DATA[0] = 0xff; - - println!("SOME_INITED_DATA {:x?}", SOME_INITED_DATA); - println!("SOME_UNINITED_DATA {:x?}", SOME_UNINITED_DATA); - println!("SOME_ZEROED_DATA {:x?}", SOME_ZEROED_DATA); - - if SOME_UNINITED_DATA[0] != 0 { - SOME_UNINITED_DATA[0] = 0; - SOME_UNINITED_DATA[1] = 0; - } - - if SOME_UNINITED_DATA[1] == 0xff { - SOME_UNINITED_DATA[1] = 0; - } - - println!("Counter {}", SOME_UNINITED_DATA[1]); - SOME_UNINITED_DATA[1] += 1; - } - - println!( - "RTC_FAST function located at {:p}", - function_in_rtc_ram as *const () - ); - println!("Result {}", function_in_rtc_ram()); - - loop { - function_in_ram(); - block!(timer0.wait()).unwrap(); - } -} - -#[ram] -fn function_in_ram() { - println!("Hello world!"); -} - -#[ram(rtc_fast)] -fn function_in_rtc_ram() -> u32 { - 42 -} diff --git a/esp32s2-hal/examples/read_efuse.rs b/esp32s2-hal/examples/read_efuse.rs deleted file mode 100644 index fb9f28b04..000000000 --- a/esp32s2-hal/examples/read_efuse.rs +++ /dev/null @@ -1,21 +0,0 @@ -//! This shows how to read selected information from eFuses. -//! e.g. the MAC address - -#![no_std] -#![no_main] - -use esp32s2_hal::{clock::ClockControl, efuse::Efuse, peripherals::Peripherals, prelude::*}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - println!("MAC address {:02x?}", Efuse::get_mac_address()); - println!("Flash Encryption {:?}", Efuse::get_flash_encryption()); - - loop {} -} diff --git a/esp32s2-hal/examples/rmt_rx.rs b/esp32s2-hal/examples/rmt_rx.rs deleted file mode 100644 index 8c8cbb21b..000000000 --- a/esp32s2-hal/examples/rmt_rx.rs +++ /dev/null @@ -1,91 +0,0 @@ -//! Demonstrates decoding pulse sequences with RMT -//! Connect GPIO15 to GPIO4 - -#![no_std] -#![no_main] - -use esp32s2_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - rmt::{PulseCode, RxChannel, RxChannelConfig, RxChannelCreator}, - Delay, - Rmt, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut out = io.pins.gpio15.into_push_pull_output(); - - let rmt = Rmt::new(peripherals.RMT, 80u32.MHz(), &clocks).unwrap(); - - let mut channel = rmt - .channel0 - .configure( - io.pins.gpio4, - RxChannelConfig { - clk_divider: 1, - idle_threshold: 0b111_1111_1111_1111, - ..RxChannelConfig::default() - }, - ) - .unwrap(); - - let mut delay = Delay::new(&clocks); - - let mut data = [PulseCode { - level1: true, - length1: 1, - level2: false, - length2: 1, - }; 48]; - - loop { - for x in data.iter_mut() { - x.length1 = 0; - x.length2 = 0; - } - - let transaction = channel.receive(&mut data).unwrap(); - - // simulate input - for i in 0u32..5u32 { - out.set_high().unwrap(); - delay.delay_us(i * 10 + 20); - out.set_low().unwrap(); - delay.delay_us(i * 20 + 20); - } - - match transaction.wait() { - Ok(channel_res) => { - channel = channel_res; - for entry in &data[..data.len()] { - if entry.length1 == 0 { - break; - } - println!("{} {}", entry.level1, entry.length1); - - if entry.length2 == 0 { - break; - } - println!("{} {}", entry.level2, entry.length2); - } - println!(); - } - Err((_err, channel_res)) => { - channel = channel_res; - println!("Error"); - } - } - - delay.delay_ms(1500u32); - } -} diff --git a/esp32s2-hal/examples/rmt_tx.rs b/esp32s2-hal/examples/rmt_tx.rs deleted file mode 100644 index 57a34a426..000000000 --- a/esp32s2-hal/examples/rmt_tx.rs +++ /dev/null @@ -1,60 +0,0 @@ -//! Demonstrates generating pulse sequences with RMT -//! Connect a logic analyzer to GPIO4 to see the generated pulses. - -#![no_std] -#![no_main] - -use esp32s2_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - rmt::{PulseCode, TxChannel, TxChannelConfig, TxChannelCreator}, - Delay, - Rmt, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut delay = Delay::new(&clocks); - - let rmt = Rmt::new(peripherals.RMT, 80u32.MHz(), &clocks).unwrap(); - - let mut channel = rmt - .channel2 - .configure( - io.pins.gpio4, - TxChannelConfig { - clk_divider: 255, - ..TxChannelConfig::default() - }, - ) - .unwrap(); - - let mut data = [PulseCode { - level1: true, - length1: 200, - level2: false, - length2: 50, - }; 20]; - - data[data.len() - 2] = PulseCode { - level1: true, - length1: 3000, - level2: false, - length2: 500, - }; - data[data.len() - 1] = PulseCode::default(); - - loop { - let transaction = channel.transmit(&data); - channel = transaction.wait().unwrap(); - delay.delay_ms(500u32); - } -} diff --git a/esp32s2-hal/examples/rng.rs b/esp32s2-hal/examples/rng.rs deleted file mode 100644 index 0b49de22c..000000000 --- a/esp32s2-hal/examples/rng.rs +++ /dev/null @@ -1,28 +0,0 @@ -//! Demonstrates the use of the hardware Random Number Generator (RNG) - -#![no_std] -#![no_main] - -use esp32s2_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Rng}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Instantiate the Random Number Generator peripheral: - let mut rng = Rng::new(peripherals.RNG); - - // Generate a random word (u32): - println!("Random u32: {}", rng.random()); - - // Fill a buffer with random bytes: - let mut buf = [0u8; 16]; - rng.read(&mut buf).unwrap(); - println!("Random bytes: {:?}", buf); - - loop {} -} diff --git a/esp32s2-hal/examples/rsa.rs b/esp32s2-hal/examples/rsa.rs deleted file mode 100644 index ff11ae5a7..000000000 --- a/esp32s2-hal/examples/rsa.rs +++ /dev/null @@ -1,157 +0,0 @@ -//! Demonstrates the use of the RSA peripheral and compares the speed of -//! multiple arithmetic operations. - -#![no_std] -#![no_main] - -use crypto_bigint::{ - modular::runtime_mod::{DynResidue, DynResidueParams}, - Uint, - U1024, - U512, -}; -use esp32s2_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - rsa::{ - operand_sizes, - Rsa, - RsaModularExponentiation, - RsaModularMultiplication, - RsaMultiplication, - }, - xtensa_lx, -}; -use esp_backtrace as _; -use esp_println::println; - -const BIGNUM_1: U512 = Uint::from_be_hex( - "c7f61058f96db3bd87dbab08ab03b4f7f2f864eac249144adea6a65f97803b719d8ca980b7b3c0389c1c7c6\ - 7dc353c5e0ec11f5fc8ce7f6073796cc8f73fa878", -); -const BIGNUM_2: U512 = Uint::from_be_hex( - "1763db3344e97be15d04de4868badb12a38046bb793f7630d87cf100aa1c759afac15a01f3c4c83ec2d2f66\ - 6bd22f71c3c1f075ec0e2cb0cb29994d091b73f51", -); -const BIGNUM_3: U512 = Uint::from_be_hex( - "6b6bb3d2b6cbeb45a769eaa0384e611e1b89b0c9b45a045aca1c5fd6e8785b38df7118cf5dd45b9b63d293b\ - 67aeafa9ba25feb8712f188cb139b7d9b9af1c361", -); - -const fn compute_r(modulus: &U512) -> U512 { - let mut d = [0_u32; U512::LIMBS * 2 + 1]; - d[d.len() - 1] = 1; - let d = Uint::from_words(d); - d.const_rem(&modulus.resize()).0.resize() -} - -const fn compute_mprime(modulus: &U512) -> u32 { - let m_inv = modulus.inv_mod2k(32).to_words()[0]; - (-1 * m_inv as i64 % 4294967296) as u32 -} - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rsa = Rsa::new(peripherals.RSA); - - nb::block!(rsa.ready()).unwrap(); - mod_exp_example(&mut rsa); - mod_multi_example(&mut rsa); - multiplication_example(&mut rsa); - - loop {} -} - -fn mod_multi_example(rsa: &mut Rsa) { - let mut outbuf = [0_u32; U512::LIMBS]; - let mut mod_multi = RsaModularMultiplication::::new( - rsa, - BIGNUM_1.as_words(), - BIGNUM_2.as_words(), - BIGNUM_3.as_words(), - compute_mprime(&BIGNUM_3), - ); - let r = compute_r(&BIGNUM_3); - let pre_hw_modmul = xtensa_lx::timer::get_cycle_count(); - mod_multi.start_modular_multiplication(r.as_words()); - mod_multi.read_results(&mut outbuf); - let post_hw_modmul = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for hw modular multiplication", - post_hw_modmul - pre_hw_modmul - ); - let residue_params = DynResidueParams::new(&BIGNUM_3); - let residue_num1 = DynResidue::new(&BIGNUM_1, residue_params); - let residue_num2 = DynResidue::new(&BIGNUM_2, residue_params); - let pre_sw_exp = xtensa_lx::timer::get_cycle_count(); - let sw_out = residue_num1.mul(&residue_num2); - let post_sw_exp = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for sw modular multiplication", - post_sw_exp - pre_sw_exp - ); - assert_eq!(U512::from_words(outbuf), sw_out.retrieve()); - println!("modular multiplication done"); -} - -fn mod_exp_example(rsa: &mut Rsa) { - rsa.enable_disable_constant_time_acceleration(true); - rsa.enable_disable_search_acceleration(true); - let mut outbuf = [0_u32; U512::LIMBS]; - let mut mod_exp = RsaModularExponentiation::::new( - rsa, - BIGNUM_2.as_words(), - BIGNUM_3.as_words(), - compute_mprime(&BIGNUM_3), - ); - let r = compute_r(&BIGNUM_3); - let base = BIGNUM_1.as_words(); - let pre_hw_exp = xtensa_lx::timer::get_cycle_count(); - mod_exp.start_exponentiation(base, r.as_words()); - mod_exp.read_results(&mut outbuf); - let post_hw_exp = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for hw modular exponentiation", - post_hw_exp - pre_hw_exp - ); - let residue_params = DynResidueParams::new(&BIGNUM_3); - let residue = DynResidue::new(&BIGNUM_1, residue_params); - let pre_sw_exp = xtensa_lx::timer::get_cycle_count(); - let sw_out = residue.pow(&BIGNUM_2); - let post_sw_exp = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for sw modular exponentiation", - post_sw_exp - pre_sw_exp - ); - assert_eq!(U512::from_words(outbuf), sw_out.retrieve()); - println!("modular exponentiation done"); -} - -fn multiplication_example(rsa: &mut Rsa) { - let mut out = [0_u32; U1024::LIMBS]; - let operand_a = BIGNUM_1.as_words(); - let operand_b = BIGNUM_2.as_words(); - let mut rsamulti = RsaMultiplication::::new(rsa, operand_a); - let pre_hw_mul = xtensa_lx::timer::get_cycle_count(); - rsamulti.start_multiplication(operand_b); - rsamulti.read_results(&mut out); - let post_hw_mul = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for hw multiplication", - post_hw_mul - pre_hw_mul - ); - let pre_sw_mul = xtensa_lx::timer::get_cycle_count(); - let sw_out = BIGNUM_1.mul_wide(&BIGNUM_2); - let post_sw_mul = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for sw multiplication", - post_sw_mul - pre_sw_mul - ); - assert_eq!(U1024::from_words(out), sw_out.1.concat(&sw_out.0)); - println!("multiplication done"); -} diff --git a/esp32s2-hal/examples/rtc_time.rs b/esp32s2-hal/examples/rtc_time.rs deleted file mode 100644 index da4b8072a..000000000 --- a/esp32s2-hal/examples/rtc_time.rs +++ /dev/null @@ -1,22 +0,0 @@ -//! Prints time in milliseconds from the RTC Timer - -#![no_std] -#![no_main] - -use esp32s2_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Delay, Rtc}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let rtc = Rtc::new(peripherals.LPWR); - let mut delay = Delay::new(&clocks); - - loop { - esp_println::println!("rtc time in milliseconds is {}", rtc.get_time_ms()); - delay.delay_ms(1000u32); - } -} diff --git a/esp32s2-hal/examples/rtc_watchdog.rs b/esp32s2-hal/examples/rtc_watchdog.rs deleted file mode 100644 index 9138be8ce..000000000 --- a/esp32s2-hal/examples/rtc_watchdog.rs +++ /dev/null @@ -1,59 +0,0 @@ -//! This demos the RTC Watchdog Timer (RWDT). -//! The RWDT is initially configured to trigger an interrupt after a given -//! timeout. Then, upon expiration, the RWDT is restarted and then reconfigured -//! to reset both the main system and the RTC. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32s2_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, - Rtc, - Rwdt, -}; -use esp_backtrace as _; - -static RWDT: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rtc = Rtc::new(peripherals.LPWR); - rtc.rwdt.start(2000u64.millis()); - rtc.rwdt.listen(); - - critical_section::with(|cs| RWDT.borrow_ref_mut(cs).replace(rtc.rwdt)); - - interrupt::enable( - peripherals::Interrupt::RTC_CORE, - interrupt::Priority::Priority1, - ) - .unwrap(); - - loop {} -} - -#[interrupt] -fn RTC_CORE() { - critical_section::with(|cs| { - esp_println::println!("RWDT Interrupt"); - - let mut rwdt = RWDT.borrow_ref_mut(cs); - let rwdt = rwdt.as_mut().unwrap(); - rwdt.clear_interrupt(); - - esp_println::println!("Restarting in 5 seconds..."); - - rwdt.start(5000u64.millis()); - rwdt.unlisten(); - }); -} diff --git a/esp32s2-hal/examples/serial_interrupts.rs b/esp32s2-hal/examples/serial_interrupts.rs deleted file mode 100644 index 715e47d3a..000000000 --- a/esp32s2-hal/examples/serial_interrupts.rs +++ /dev/null @@ -1,85 +0,0 @@ -//! This shows some of the interrupts that can be generated by UART/Serial. -//! Use a proper serial terminal to connect to the board (espmonitor and -//! espflash won't work) - -#![no_std] -#![no_main] - -use core::{cell::RefCell, fmt::Write}; - -use critical_section::Mutex; -use esp32s2_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals, UART0}, - prelude::*, - timer::TimerGroup, - uart::config::AtCmdConfig, - Uart, -}; -use esp_backtrace as _; -use nb::block; - -static SERIAL: Mutex>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Disable the TIMG watchdog timer. - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - uart0.set_at_cmd(AtCmdConfig::new(None, None, None, b'#', None)); - uart0.set_rx_fifo_full_threshold(30).unwrap(); - uart0.listen_at_cmd(); - uart0.listen_rx_fifo_full(); - - interrupt::enable( - peripherals::Interrupt::UART0, - interrupt::Priority::Priority2, - ) - .unwrap(); - - timer0.start(1u64.secs()); - - critical_section::with(|cs| SERIAL.borrow_ref_mut(cs).replace(uart0)); - - loop { - critical_section::with(|cs| { - let mut serial = SERIAL.borrow_ref_mut(cs); - let serial = serial.as_mut().unwrap(); - writeln!(serial, "Hello World! Send a single `#` character or send at least 30 characters and see the interrupts trigger.").ok(); - }); - - block!(timer0.wait()).unwrap(); - } -} - -#[interrupt] -fn UART0() { - critical_section::with(|cs| { - let mut serial = SERIAL.borrow_ref_mut(cs); - let serial = serial.as_mut().unwrap(); - - let mut cnt = 0; - while let nb::Result::Ok(_c) = serial.read() { - cnt += 1; - } - writeln!(serial, "Read {} bytes", cnt,).ok(); - - writeln!( - serial, - "Interrupt AT-CMD: {} RX-FIFO-FULL: {}", - serial.at_cmd_interrupt_set(), - serial.rx_fifo_full_interrupt_set(), - ) - .ok(); - - serial.reset_at_cmd_interrupt(); - serial.reset_rx_fifo_full_interrupt(); - }); -} diff --git a/esp32s2-hal/examples/sha.rs b/esp32s2-hal/examples/sha.rs deleted file mode 100644 index df97f9a38..000000000 --- a/esp32s2-hal/examples/sha.rs +++ /dev/null @@ -1,72 +0,0 @@ -//! Demonstrates the use of the SHA peripheral and compares the speed of -//! hardware-accelerated and pure software hashing. - -#![no_std] -#![no_main] - -use esp32s2_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - sha::{Sha, ShaMode}, - xtensa_lx, -}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; -use sha2::{Digest, Sha512}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let source_data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".as_bytes(); - let mut remaining = source_data; - let mut hasher = Sha::new(peripherals.SHA, ShaMode::SHA512); - - // Short hashes can be created by decreasing the output buffer to the desired - // length - let mut output = [0u8; 64]; - - let pre_calc = xtensa_lx::timer::get_cycle_count(); - // The hardware implementation takes a subslice of the input, and returns the - // unprocessed parts The unprocessed parts can be input in the next - // iteration, you can always add more data until finish() is called. After - // finish() is called update()'s will contribute to a new hash which - // can be extracted again with finish(). - - while remaining.len() > 0 { - // Can add println to view progress, however println takes a few orders of - // magnitude longer than the Sha function itself so not useful for - // comparing processing time println!("Remaining len: {}", - // remaining.len()); - - // All the HW Sha functions are infallible so unwrap is fine to use if you use - // block! - remaining = block!(hasher.update(remaining)).unwrap(); - } - - // Finish can be called as many times as desired to get mutliple copies of the - // output. - block!(hasher.finish(output.as_mut_slice())).unwrap(); - let post_calc = xtensa_lx::timer::get_cycle_count(); - let hw_time = post_calc - pre_calc; - println!("Took {} cycles", hw_time); - println!("SHA512 Hash output {:02x?}", output); - - let pre_calc = xtensa_lx::timer::get_cycle_count(); - let mut hasher = Sha512::new(); - hasher.update(source_data); - let soft_result = hasher.finalize(); - let post_calc = xtensa_lx::timer::get_cycle_count(); - let soft_time = post_calc - pre_calc; - println!("Took {} cycles", soft_time); - println!("SHA512 Hash output {:02x?}", soft_result); - - assert_eq!(output, soft_result[..]); - println!("HW SHA is {}x faster", soft_time / hw_time); - - loop {} -} diff --git a/esp32s2-hal/examples/software_interrupts.rs b/esp32s2-hal/examples/software_interrupts.rs deleted file mode 100644 index bc13b6d05..000000000 --- a/esp32s2-hal/examples/software_interrupts.rs +++ /dev/null @@ -1,139 +0,0 @@ -//! Software Interrupts -//! -//! An example of how software interrupts can be raised and reset -//! Should rotate through all of the available interrupts printing their number -//! when raised. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32s2_hal::{ - clock::ClockControl, - interrupt::{self}, - peripherals::{self, Peripherals}, - prelude::*, - system::{SoftwareInterrupt, SoftwareInterruptControl}, - Delay, -}; -use esp_backtrace as _; - -static SWINT: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let sw_int = system.software_interrupt_control; - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - critical_section::with(|cs| SWINT.borrow_ref_mut(cs).replace(sw_int)); - - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR0, - interrupt::Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR1, - interrupt::Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR2, - interrupt::Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR3, - interrupt::Priority::Priority3, - ) - .unwrap(); - let mut delay = Delay::new(&clocks); - let mut counter = 0; - loop { - delay.delay_ms(500u32); - match counter { - 0 => critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt0); - }), - 1 => critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt1); - }), - 2 => critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt2); - }), - 3 => { - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt3); - }); - counter = -1 - } - _ => {} - } - counter += 1; - } -} - -#[interrupt] -fn FROM_CPU_INTR0() { - esp_println::println!("SW interrupt0"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt0); - }); -} -#[interrupt] -fn FROM_CPU_INTR1() { - esp_println::println!("SW interrupt1"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt1); - }); -} -#[interrupt] -fn FROM_CPU_INTR2() { - esp_println::println!("SW interrupt2"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt2); - }); -} -#[interrupt] -fn FROM_CPU_INTR3() { - esp_println::println!("SW interrupt3"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt3); - }); -} diff --git a/esp32s2-hal/examples/spi_eh1_device_loopback.rs b/esp32s2-hal/examples/spi_eh1_device_loopback.rs deleted file mode 100644 index edeb69d23..000000000 --- a/esp32s2-hal/examples/spi_eh1_device_loopback.rs +++ /dev/null @@ -1,140 +0,0 @@ -//! SPI loopback test -//! -//! Folowing pins are used: -//! SCLK GPIO36 -//! MISO GPIO37 -//! MOSI GPIO35 -//! CS 1 GPIO1 -//! CS 2 GPIO2 -//! CS 3 GPIO3 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use embedded_hal_1::spi::SpiDevice; -use embedded_hal_bus::spi::RefCellDevice; -use esp32s2_hal::{ - clock::ClockControl, - gpio::{self, IO}, - peripherals::Peripherals, - prelude::*, - spi::{master::Spi, SpiMode}, - Delay, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio36; - let miso = io.pins.gpio37; - let mosi = io.pins.gpio35; - - let spi_bus = Spi::new(peripherals.SPI2, 1000u32.kHz(), SpiMode::Mode0, &clocks).with_pins( - Some(sclk), - Some(mosi), - Some(miso), - gpio::NO_PIN, - ); - let spi_bus = RefCell::new(spi_bus); - let mut spi_device_1 = - RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio1.into_push_pull_output()); - let mut spi_device_2 = - RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio2.into_push_pull_output()); - let mut spi_device_3 = - RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio3.into_push_pull_output()); - - let mut delay = Delay::new(&clocks); - println!("=== SPI example with embedded-hal-1 traits ==="); - - loop { - // --- Symmetric transfer (Read as much as we write) --- - print!("Starting symmetric transfer..."); - let write = [0xde, 0xad, 0xbe, 0xef]; - let mut read: [u8; 4] = [0x00u8; 4]; - - spi_device_1.transfer(&mut read[..], &write[..]).unwrap(); - assert_eq!(write, read); - spi_device_2.transfer(&mut read[..], &write[..]).unwrap(); - spi_device_3.transfer(&mut read[..], &write[..]).unwrap(); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Asymmetric transfer (Read more than we write) --- - print!("Starting asymetric transfer (read > write)..."); - let mut read: [u8; 4] = [0x00; 4]; - - spi_device_1 - .transfer(&mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - assert_eq!(write[0], read[0]); - assert_eq!(read[2], 0x00u8); - spi_device_2 - .transfer(&mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - spi_device_3 - .transfer(&mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer --- - // Only your RAM is the limit! - print!("Starting huge transfer..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - let mut read = [0x00u8; 4096]; - - spi_device_1 - .transfer(&mut read[..], &write[..]) - .expect("Huge transfer failed"); - assert_eq!(write, read); - spi_device_2 - .transfer(&mut read[..], &write[..]) - .expect("Huge transfer failed"); - spi_device_3 - .transfer(&mut read[..], &write[..]) - .expect("Huge transfer failed"); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer in-place (No additional allocation - // needed) --- - print!("Starting huge transfer (in-place)..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - - spi_device_1 - .transfer_in_place(&mut write[..]) - .expect("Huge transfer failed"); - for byte in 0..write.len() { - assert_eq!(write[byte], byte as u8); - } - spi_device_2 - .transfer_in_place(&mut write[..]) - .expect("Huge transfer failed"); - spi_device_3 - .transfer_in_place(&mut write[..]) - .expect("Huge transfer failed"); - println!(" SUCCESS"); - delay.delay_ms(250u32); - } -} diff --git a/esp32s2-hal/examples/spi_eh1_loopback.rs b/esp32s2-hal/examples/spi_eh1_loopback.rs deleted file mode 100644 index d35a4c36a..000000000 --- a/esp32s2-hal/examples/spi_eh1_loopback.rs +++ /dev/null @@ -1,104 +0,0 @@ -//! SPI loopback test -//! -//! Folowing pins are used: -//! SCLK GPIO36 -//! MISO GPIO37 -//! MOSI GPIO35 -//! CS GPIO34 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use embedded_hal_1::spi::SpiBus; -use esp32s2_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{master::Spi, SpiMode}, - Delay, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio36; - let miso = io.pins.gpio37; - let mosi = io.pins.gpio35; - let cs = io.pins.gpio34; - - let mut spi = Spi::new(peripherals.SPI2, 1000u32.kHz(), SpiMode::Mode0, &clocks).with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(cs), - ); - - let mut delay = Delay::new(&clocks); - println!("=== SPI example with embedded-hal-1 traits ==="); - - loop { - // --- Symmetric transfer (Read as much as we write) --- - print!("Starting symmetric transfer..."); - let write = [0xde, 0xad, 0xbe, 0xef]; - let mut read: [u8; 4] = [0x00u8; 4]; - - SpiBus::transfer(&mut spi, &mut read[..], &write[..]).expect("Symmetric transfer failed"); - assert_eq!(write, read); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Asymmetric transfer (Read more than we write) --- - print!("Starting asymetric transfer (read > write)..."); - let mut read: [u8; 4] = [0x00; 4]; - - SpiBus::transfer(&mut spi, &mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - assert_eq!(write[0], read[0]); - assert_eq!(read[2], 0x00u8); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer --- - // Only your RAM is the limit! - print!("Starting huge transfer..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - let mut read = [0x00u8; 4096]; - - SpiBus::transfer(&mut spi, &mut read[..], &write[..]).expect("Huge transfer failed"); - assert_eq!(write, read); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer in-place (No additional allocation - // needed) --- - print!("Starting huge transfer (in-place)..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - - SpiBus::transfer_in_place(&mut spi, &mut write[..]).expect("Huge transfer failed"); - for byte in 0..write.len() { - assert_eq!(write[byte], byte as u8); - } - println!(" SUCCESS"); - delay.delay_ms(250u32); - } -} diff --git a/esp32s2-hal/examples/spi_halfduplex_read_manufacturer_id.rs b/esp32s2-hal/examples/spi_halfduplex_read_manufacturer_id.rs deleted file mode 100644 index d6db4ee5f..000000000 --- a/esp32s2-hal/examples/spi_halfduplex_read_manufacturer_id.rs +++ /dev/null @@ -1,101 +0,0 @@ -//! SPI read manufacturer id from flash chip -//! -//! Folowing pins are used: -//! SCLK GPIO4 -//! MISO/IO0 GPIO5 -//! MOSI/IO1 GPIO6 -//! IO2 GPIO7 -//! IO3 GPIO15 -//! CS GPIO16 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! Connect a flash chip (GD25Q64C was used) and make sure QE in the status -//! register is set. - -#![no_std] -#![no_main] - -use esp32s2_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{Address, Command, HalfDuplexReadWrite, Spi}, - SpiDataMode, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio4; - let miso = io.pins.gpio5; - let mosi = io.pins.gpio6; - let sio2 = io.pins.gpio7; - let sio3 = io.pins.gpio15; - let cs = io.pins.gpio16; - - let mut spi = Spi::new_half_duplex(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(sio2), - Some(sio3), - Some(cs), - ); - - let mut delay = Delay::new(&clocks); - - loop { - // READ MANUFACTURER ID FROM FLASH CHIP - let mut data = [0u8; 2]; - spi.read( - SpiDataMode::Single, - Command::Command8(0x90, SpiDataMode::Single), - Address::Address24(0x000000, SpiDataMode::Single), - 0, - &mut data, - ) - .unwrap(); - println!("Single {:x?}", data); - delay.delay_ms(250u32); - - // READ MANUFACTURER ID FROM FLASH CHIP - let mut data = [0u8; 2]; - spi.read( - SpiDataMode::Dual, - Command::Command8(0x92, SpiDataMode::Single), - Address::Address32(0x000000_00, SpiDataMode::Dual), - 0, - &mut data, - ) - .unwrap(); - println!("Dual {:x?}", data); - delay.delay_ms(250u32); - - // READ MANUFACTURER ID FROM FLASH CHIP - let mut data = [0u8; 2]; - spi.read( - SpiDataMode::Quad, - Command::Command8(0x94, SpiDataMode::Single), - Address::Address32(0x000000_00, SpiDataMode::Quad), - 4, - &mut data, - ) - .unwrap(); - println!("Quad {:x?}", data); - delay.delay_ms(1500u32); - } -} diff --git a/esp32s2-hal/examples/spi_loopback.rs b/esp32s2-hal/examples/spi_loopback.rs deleted file mode 100644 index bcfdb7531..000000000 --- a/esp32s2-hal/examples/spi_loopback.rs +++ /dev/null @@ -1,58 +0,0 @@ -//! SPI loopback test -//! -//! Folowing pins are used: -//! SCLK GPIO36 -//! MISO GPIO37 -//! MOSI GPIO35 -//! CS GPIO34 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use esp32s2_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{master::Spi, SpiMode}, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio36; - let miso = io.pins.gpio37; - let mosi = io.pins.gpio35; - let cs = io.pins.gpio34; - - let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks).with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(cs), - ); - - let mut delay = Delay::new(&clocks); - - loop { - let mut data = [0xde, 0xca, 0xfb, 0xad]; - spi.transfer(&mut data).unwrap(); - println!("{:x?}", data); - - delay.delay_ms(250u32); - } -} diff --git a/esp32s2-hal/examples/spi_loopback_dma.rs b/esp32s2-hal/examples/spi_loopback_dma.rs deleted file mode 100644 index f738581dc..000000000 --- a/esp32s2-hal/examples/spi_loopback_dma.rs +++ /dev/null @@ -1,97 +0,0 @@ -//! SPI loopback test using DMA -//! -//! Folowing pins are used: -//! SCLK GPIO36 -//! MISO GPIO37 -//! MOSI GPIO35 -//! CS GPIO34 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use esp32s2_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{prelude::*, Spi}, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio36; - let miso = io.pins.gpio37; - let mosi = io.pins.gpio35; - let cs = io.pins.gpio34; - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.spi2channel; - - let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(32000); - - let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) - .with_dma(dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let mut delay = Delay::new(&clocks); - - // DMA buffer require a static life-time - let mut send = tx_buffer; - let mut receive = rx_buffer; - let mut i = 0; - - for (i, v) in send.iter_mut().enumerate() { - *v = (i % 255) as u8; - } - - loop { - send[0] = i; - send[send.len() - 1] = i; - i = i.wrapping_add(1); - - let transfer = spi.dma_transfer(send, receive).unwrap(); - // here we could do something else while DMA transfer is in progress - let mut n = 0; - // Check is_done until the transfer is almost done (32000 bytes at 100kHz is - // 2.56 seconds), then move to wait(). - while !transfer.is_done() && n < 10 { - delay.delay_ms(250u32); - n += 1; - } - // the buffers and spi is moved into the transfer and we can get it back via - // `wait` - (receive, send, spi) = transfer.wait().unwrap(); - println!( - "{:x?} .. {:x?}", - &receive[..10], - &receive[receive.len() - 10..] - ); - - delay.delay_ms(250u32); - } -} diff --git a/esp32s2-hal/examples/systimer.rs b/esp32s2-hal/examples/systimer.rs deleted file mode 100644 index 93455e4b1..000000000 --- a/esp32s2-hal/examples/systimer.rs +++ /dev/null @@ -1,113 +0,0 @@ -//! This shows how to use the SYSTIMER peripheral including interrupts. -//! It's an additional timer besides the TIMG peripherals. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32s2_hal::{ - clock::ClockControl, - interrupt, - interrupt::Priority, - peripherals::{self, Peripherals}, - prelude::*, - systimer::{Alarm, Periodic, SystemTimer, Target}, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -static ALARM0: Mutex>>> = Mutex::new(RefCell::new(None)); -static ALARM1: Mutex>>> = Mutex::new(RefCell::new(None)); -static ALARM2: Mutex>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let syst = SystemTimer::new(peripherals.SYSTIMER); - - println!("SYSTIMER Current value = {}", SystemTimer::now()); - - let alarm0 = syst.alarm0.into_periodic(); - alarm0.set_period(1u32.secs()); - alarm0.enable_interrupt(true); - - let alarm1 = syst.alarm1; - alarm1.set_target(SystemTimer::now() + (SystemTimer::TICKS_PER_SECOND * 2)); - alarm1.enable_interrupt(true); - - let alarm2 = syst.alarm2; - alarm2.set_target(SystemTimer::now() + (SystemTimer::TICKS_PER_SECOND * 3)); - alarm2.enable_interrupt(true); - - critical_section::with(|cs| { - ALARM0.borrow_ref_mut(cs).replace(alarm0); - ALARM1.borrow_ref_mut(cs).replace(alarm1); - ALARM2.borrow_ref_mut(cs).replace(alarm2); - }); - - interrupt::enable( - peripherals::Interrupt::SYSTIMER_TARGET0, - Priority::Priority1, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::SYSTIMER_TARGET1, - Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::SYSTIMER_TARGET2, - Priority::Priority3, - ) - .unwrap(); - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - loop { - delay.delay_ms(500u32); - } -} - -#[interrupt] -fn SYSTIMER_TARGET0() { - println!("Interrupt lvl1 (alarm0)"); - critical_section::with(|cs| { - ALARM0 - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .clear_interrupt() - }); -} - -#[interrupt] -fn SYSTIMER_TARGET1() { - println!("Interrupt lvl3 (alarm1)"); - critical_section::with(|cs| { - ALARM1 - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .clear_interrupt() - }); -} - -#[interrupt] -fn SYSTIMER_TARGET2() { - println!("Interrupt lvl3 (alarm2)"); - critical_section::with(|cs| { - ALARM2 - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .clear_interrupt() - }); -} diff --git a/esp32s2-hal/examples/timer_interrupt.rs b/esp32s2-hal/examples/timer_interrupt.rs deleted file mode 100644 index dc6a99667..000000000 --- a/esp32s2-hal/examples/timer_interrupt.rs +++ /dev/null @@ -1,120 +0,0 @@ -//! This shows how to use the TIMG peripheral interrupts. -//! There is TIMG0 and TIMG1 each of them containing two general purpose timers -//! and a watchdog timer. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32s2_hal::{ - clock::ClockControl, - interrupt, - interrupt::Priority, - peripherals::{self, Peripherals, TIMG0, TIMG1}, - prelude::*, - timer::{Timer, Timer0, Timer1, TimerGroup}, -}; -use esp_backtrace as _; -use esp_println::println; - -static TIMER00: Mutex>>>> = Mutex::new(RefCell::new(None)); -static TIMER01: Mutex>>>> = Mutex::new(RefCell::new(None)); -static TIMER10: Mutex>>>> = Mutex::new(RefCell::new(None)); -static TIMER11: Mutex>>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Disable the TIMG watchdog timer. - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer00 = timer_group0.timer0; - let mut timer01 = timer_group0.timer1; - - let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks); - let mut timer10 = timer_group1.timer0; - let mut timer11 = timer_group1.timer1; - - interrupt::enable(peripherals::Interrupt::TG0_T0_LEVEL, Priority::Priority2).unwrap(); - interrupt::enable(peripherals::Interrupt::TG0_T1_LEVEL, Priority::Priority2).unwrap(); - interrupt::enable(peripherals::Interrupt::TG1_T0_LEVEL, Priority::Priority3).unwrap(); - interrupt::enable(peripherals::Interrupt::TG1_T1_LEVEL, Priority::Priority3).unwrap(); - - timer00.start(500u64.millis()); - timer00.listen(); - timer01.start(2500u64.millis()); - timer01.listen(); - timer10.start(1u64.secs()); - timer10.listen(); - timer11.start(3u64.secs()); - timer11.listen(); - - critical_section::with(|cs| { - TIMER00.borrow_ref_mut(cs).replace(timer00); - TIMER01.borrow_ref_mut(cs).replace(timer01); - TIMER10.borrow_ref_mut(cs).replace(timer10); - TIMER11.borrow_ref_mut(cs).replace(timer11); - }); - - loop {} -} - -#[interrupt] -fn TG0_T0_LEVEL() { - critical_section::with(|cs| { - let mut timer = TIMER00.borrow_ref_mut(cs); - let timer = timer.as_mut().unwrap(); - - if timer.is_interrupt_set() { - timer.clear_interrupt(); - timer.start(500u64.millis()); - println!("Interrupt Level 2 - Timer0"); - } - }); -} - -#[interrupt] -fn TG0_T1_LEVEL() { - critical_section::with(|cs| { - let mut timer = TIMER01.borrow_ref_mut(cs); - let timer = timer.as_mut().unwrap(); - - if timer.is_interrupt_set() { - timer.clear_interrupt(); - timer.start(500u64.millis()); - println!("Interrupt Level 2 - Timer1"); - } - }); -} - -#[interrupt] -fn TG1_T0_LEVEL() { - critical_section::with(|cs| { - let mut timer = TIMER10.borrow_ref_mut(cs); - let timer = timer.as_mut().unwrap(); - - if timer.is_interrupt_set() { - timer.clear_interrupt(); - timer.start(500u64.millis()); - println!("Interrupt Level 3 - Timer0"); - } - }); -} - -#[interrupt] -fn TG1_T1_LEVEL() { - critical_section::with(|cs| { - let mut timer = TIMER11.borrow_ref_mut(cs); - let timer = timer.as_mut().unwrap(); - - if timer.is_interrupt_set() { - timer.clear_interrupt(); - timer.start(500u64.millis()); - println!("Interrupt Level 3 - Timer1"); - } - }); -} diff --git a/esp32s2-hal/examples/watchdog.rs b/esp32s2-hal/examples/watchdog.rs deleted file mode 100644 index 9d3a3603c..000000000 --- a/esp32s2-hal/examples/watchdog.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! This demos the watchdog timer. -//! Basically the same as `hello_world` but if you remove the call to -//! `wdt.feed()` the watchdog will reset the system. - -#![no_std] -#![no_main] - -use esp32s2_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, timer::TimerGroup}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - let mut wdt = timer_group0.wdt; - - wdt.start(2u64.secs()); - timer0.start(1u64.secs()); - - loop { - wdt.feed(); - println!("Hello world!"); - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32s2-hal/rust-toolchain.toml b/esp32s2-hal/rust-toolchain.toml deleted file mode 100644 index 292fa818b..000000000 --- a/esp32s2-hal/rust-toolchain.toml +++ /dev/null @@ -1,4 +0,0 @@ -[toolchain] -channel = "esp" -components = ["rustfmt", "rustc-dev"] -targets = ["xtensa-esp32s2-none-elf"] diff --git a/esp32s2-hal/src/lib.rs b/esp32s2-hal/src/lib.rs deleted file mode 100644 index 4e794459e..000000000 --- a/esp32s2-hal/src/lib.rs +++ /dev/null @@ -1,9 +0,0 @@ -//! A bare-metal (`no_std`) Hardware Abstraction Layer for the ESP32-S2 from -//! Espressif. -//! -//! ## Feature Flags -#![doc = document_features::document_features!()] -#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/46717278")] -#![no_std] - -pub use esp_hal::*; diff --git a/esp32s3-hal/.cargo/config.toml b/esp32s3-hal/.cargo/config.toml deleted file mode 100644 index 54a89652e..000000000 --- a/esp32s3-hal/.cargo/config.toml +++ /dev/null @@ -1,17 +0,0 @@ -[target.xtensa-esp32s3-none-elf] -runner = "espflash flash --monitor" - -[build] -rustflags = [ - # GNU LD - "-C", "link-arg=-nostartfiles", - "-C", "link-arg=-Wl,-Tlinkall.x", - - # LLD - # "-C", "linker=rust-lld", - # "-C", "link-arg=-Tlinkall.x", -] -target = "xtensa-esp32s3-none-elf" - -[unstable] -build-std = ["core", "alloc"] diff --git a/esp32s3-hal/Cargo.toml b/esp32s3-hal/Cargo.toml deleted file mode 100644 index fa0706621..000000000 --- a/esp32s3-hal/Cargo.toml +++ /dev/null @@ -1,191 +0,0 @@ -[package] -name = "esp32s3-hal" -version = "0.15.0" -edition = "2021" -rust-version = "1.67.0" -description = "HAL for ESP32-S3 microcontrollers" -repository = "https://github.com/esp-rs/esp-hal" -license = "MIT OR Apache-2.0" - -keywords = [ - "embedded", - "embedded-hal", - "esp", - "esp32s3", - "no-std", -] -categories = [ - "embedded", - "hardware-support", - "no-std", -] - -[dependencies] -document-features = "0.2.7" -esp-hal = { version = "0.15.0", features = ["esp32s3"], path = "../esp-hal" } -r0 = { version = "1.0.0", optional = true } -embassy-time-driver = { version = "0.1.0", optional = true } - -[dev-dependencies] -aes = "0.8.3" -critical-section = "1.1.2" -crypto-bigint = { version = "0.5.5", default-features = false } -embassy-executor = { version = "0.5.0", features = ["nightly"] } -embassy-sync = "0.5.0" -embassy-time = "0.3.0" -embedded-graphics = "0.8.1" -embedded-hal = { version = "0.2.7", features = ["unproven"] } -embedded-hal-1 = { version = "1.0.0", package = "embedded-hal" } -embedded-hal-async = "1.0.0" -embedded-can = "0.4.1" -embedded-io-async = "0.6.1" -embedded-hal-bus = "0.1.0" -esp-alloc = "0.3.0" -esp-backtrace = { version = "0.10.0", features = ["esp32s3", "panic-handler", "exception-handler", "print-uart"] } -esp-hal-smartled = { version = "0.8.0", features = ["esp32s3"], path = "../esp-hal-smartled" } -esp-println = { version = "0.8.0", features = ["esp32s3"] } -heapless = "0.8.0" -hmac = { version = "0.12.1", default-features = false } -lis3dh-async = "0.9.1" -sha2 = { version = "0.10.8", default-features = false } -smart-leds = "0.4.0" -ssd1306 = "0.8.4" -static_cell = { version = "2.0.0", features = ["nightly"] } -usb-device = "0.3.1" -usbd-serial = "0.2.0" - -[features] -default = ["embassy-integrated-timers", "rt", "vectored"] - -## Enable debug features in the HAL (used for development). -debug = ["esp-hal/debug"] -## Enable logging output using the `log` crate. -log = ["esp-hal/log", "esp-println/log"] -## Enable runtime support. -rt = ["esp-hal/rt-xtensa"] -## Enable interrupt vectoring. -vectored = ["esp-hal/vectored"] - -#! ### Trait Implementation Feature Flags -## Enable support for asynchronous operation, with interfaces provided by -## `embedded-hal-async` and `embedded-io-async`. -async = ["esp-hal/async"] -## Implement `defmt::Format` on certain types. -defmt = ["esp-hal/defmt", "esp-println/defmt-espflash"] -## Implement the traits defined in the `1.0.0` releases of `embedded-hal` and -## `embedded-hal-nb` for the relevant peripherals. -eh1 = ["esp-hal/eh1"] -## Implement the traits defined in `embedded-io` for certain peripherals. -embedded-io = ["esp-hal/embedded-io"] -## Implement the `ufmt_write::uWrite` trait for certain peripherals. -ufmt = ["esp-hal/ufmt"] - -#! ### PSRAM Feature Flags -psram = [] -## Use externally connected PSRAM (2MB). -psram-2m = ["esp-hal/psram-2m", "psram"] -## Use externally connected PSRAM (4MB). -psram-4m = ["esp-hal/psram-4m", "psram"] -## Use externally connected PSRAM (8MB). -psram-8m = ["esp-hal/psram-8m", "psram"] -## Connected PSRAM has 80MHz frequency. -psram-80mhz = ["esp-hal/psram-80mhz"] - -#! ### Octal RAM Feature Flags -## Use externally connected Octal RAM (2MB). -opsram-2m = ["esp-hal/opsram-2m", "psram"] -## Use externally connected Octal RAM (4MB). -opsram-4m = ["esp-hal/opsram-4m", "psram"] -## Use externally connected Octal RAM (8MB). -opsram-8m = ["esp-hal/opsram-8m", "psram"] -## Use externally connected Octal RAM (16MB). -opsram-16m = ["esp-hal/opsram-16m", "psram"] - -#! ### Embassy Feature Flags -## Enable support for `embassy`, a modern asynchronous embedded framework. -embassy = ["esp-hal/embassy"] -## Use the interrupt-mode embassy executor. -embassy-executor-interrupt = ["esp-hal/embassy-executor-interrupt"] -## Use the thread-mode embassy executor. -embassy-executor-thread = ["esp-hal/embassy-executor-thread"] -## Uses hardware timers as alarms for the executors. Using this feature -## limits the number of executors to the number of hardware alarms provided -## by the time driver. -embassy-integrated-timers = ["esp-hal/embassy-integrated-timers"] -## Enable the embassy time driver using the `SYSTIMER` peripheral. The -## `SYSTIMER` peripheral has three alarams available for use. -embassy-time-systick = ["esp-hal/embassy-time-systick", "embassy-time-driver/tick-hz-16_000_000"] -## Enable the embassy time driver using the `TIMG0` peripheral. The `TIMG0` -## peripheral has two alarms available for use. -embassy-time-timg0 = ["esp-hal/embassy-time-timg0", "embassy-time-driver/tick-hz-1_000_000"] - -[profile.release] -debug = true - -[[example]] -name = "spi_eh1_loopback" -required-features = ["eh1"] - -[[example]] -name = "spi_eh1_device_loopback" -required-features = ["eh1"] - -[[example]] -name = "embassy_hello_world" -required-features = ["embassy", "embassy-executor-thread"] - -[[example]] -name = "embassy_multicore" -required-features = ["embassy", "embassy-executor-thread"] - -[[example]] -name = "embassy_multicore_interrupt" -required-features = ["embassy", "embassy-executor-interrupt"] - -[[example]] -name = "embassy_multiprio" -required-features = ["embassy", "embassy-executor-interrupt"] - -[[example]] -name = "embassy_wait" -required-features = ["embassy", "embassy-executor-thread", "async"] - -[[example]] -name = "embassy_spi" -required-features = ["embassy", "embassy-executor-thread", "async"] - -[[example]] -name = "psram" -required-features = ["psram-2m"] - -[[example]] -name = "octal_psram" -required-features = ["opsram-2m"] - -[[example]] -name = "embassy_serial" -required-features = ["embassy", "embassy-executor-thread", "async"] - -[[example]] -name = "embassy_i2c" -required-features = ["embassy", "embassy-executor-thread", "async"] - -[[example]] -name = "embassy_rmt_tx" -required-features = ["embassy", "async"] - -[[example]] -name = "embassy_rmt_rx" -required-features = ["embassy", "async"] - -[[example]] -name = "embassy_i2s_sound" -required-features = ["embassy", "async"] - -[[example]] -name = "embassy_i2s_read" -required-features = ["embassy", "async"] - -[[example]] -name = "embassy_usb_serial_jtag" -required-features = ["embassy", "async"] diff --git a/esp32s3-hal/README.md b/esp32s3-hal/README.md deleted file mode 100644 index 8b82b3315..000000000 --- a/esp32s3-hal/README.md +++ /dev/null @@ -1,60 +0,0 @@ -# esp32s3-hal - -[![Crates.io](https://img.shields.io/crates/v/esp32s3-hal?labelColor=1C2C2E&color=C96329&logo=Rust&style=flat-square)](https://crates.io/crates/esp32s3-hal) -[![docs.rs](https://img.shields.io/docsrs/esp32s3-hal?labelColor=1C2C2E&color=C96329&logo=rust&style=flat-square)](https://docs.rs/esp32s3-hal) -![Crates.io](https://img.shields.io/crates/l/esp32s3-hal?labelColor=1C2C2E&style=flat-square) -[![Matrix](https://img.shields.io/matrix/esp-rs:matrix.org?label=join%20matrix&labelColor=1C2C2E&color=BEC5C9&logo=matrix&style=flat-square)](https://matrix.to/#/#esp-rs:matrix.org) - -`no_std` HAL for the ESP32 from Espressif. - -Implements a number of the traits defined in [embedded-hal](https://github.com/rust-embedded/embedded-hal). - -This device uses the Xtensa ISA, which is not officially supported by the Rust compiler. In order to develop for this device, you must use the Rust compiler fork with Xtensa support, found at [esp-rs/rust](https://github.com/esp-rs/rust). - -Please refer to the documentation for more information. - -## [Documentation] - -[documentation]: https://docs.rs/esp32s3-hal/ - -## Resources - -- [Datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-s3_datasheet_en.pdf) -- [Technical Reference Manual](https://www.espressif.com/sites/default/files/documentation/esp32-s3_technical_reference_manual_en.pdf) -- [The Rust Programming Language](https://doc.rust-lang.org/book/) -- [The Embedded Rust Book](https://docs.rust-embedded.org/book/index.html) -- [The Rust on ESP Book](https://esp-rs.github.io/book/) - -## Getting Started - -### Installing the Rust Compiler - -We provide a tool, [espup](https://github.com/esp-rs/espup/), for easily installing the Rust toolchain with Xtensa support: - -```shell -cargo install espup -espup install -``` - -Following installation of the Xtensa toolchain, if you are running a Unix-like operating system (macOS, Linux) then you must additionally export the necessary environment variables: - -```shell -. $HOME/export-esp.sh -``` - -See the [Installation chapter of The Rust on ESP Book](https://esp-rs.github.io/book/installation/index.html) for more details. - -## License - -Licensed under either of: - -- Apache License, Version 2.0 ([LICENSE-APACHE](../LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) -- MIT license ([LICENSE-MIT](../LICENSE-MIT) or http://opensource.org/licenses/MIT) - -at your option. - -### Contribution - -Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in -the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without -any additional terms or conditions. diff --git a/esp32s3-hal/build.rs b/esp32s3-hal/build.rs deleted file mode 100644 index 023b7905b..000000000 --- a/esp32s3-hal/build.rs +++ /dev/null @@ -1,16 +0,0 @@ -use std::{env, error::Error, path::PathBuf}; - -fn main() -> Result<(), Box> { - // Put the linker script somewhere the linker can find it - let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap()); - println!("cargo:rustc-link-search={}", out.display()); - - // Only re-run the build script when memory.x is changed, - // instead of when any part of the source code changes. - println!("cargo:rerun-if-changed=ld/memory.x"); - - #[cfg(feature = "defmt")] - println!("cargo:rustc-link-arg=-Tdefmt.x"); - - Ok(()) -} diff --git a/esp32s3-hal/examples/adc.rs b/esp32s3-hal/examples/adc.rs deleted file mode 100644 index 27d5ec291..000000000 --- a/esp32s3-hal/examples/adc.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! Connect a potentiometer to PIN3 and see the read values change when -//! rotating the shaft. Alternatively you could also connect the PIN to GND or -//! 3V3 to see the maximum and minimum raw values read. - -#![no_std] -#![no_main] - -use esp32s3_hal::{ - adc::{AdcConfig, Attenuation, ADC}, - clock::ClockControl, - gpio::IO, - peripherals::{Peripherals, ADC1}, - prelude::*, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create ADC instances - let mut adc1_config = AdcConfig::new(); - let mut pin3 = - adc1_config.enable_pin(io.pins.gpio3.into_analog(), Attenuation::Attenuation11dB); - let mut adc1 = ADC::::new(peripherals.ADC1, adc1_config); - - let mut delay = Delay::new(&clocks); - - loop { - let pin3_value: u16 = nb::block!(adc1.read(&mut pin3)).unwrap(); - println!("PIN3 ADC reading = {}", pin3_value); - delay.delay_ms(1500u32); - } -} diff --git a/esp32s3-hal/examples/adc_cal.rs b/esp32s3-hal/examples/adc_cal.rs deleted file mode 100644 index 4e865f464..000000000 --- a/esp32s3-hal/examples/adc_cal.rs +++ /dev/null @@ -1,51 +0,0 @@ -//! Connect a potentiometer to PIN3 and see the read values change when -//! rotating the shaft. Alternatively you could also connect the PIN to GND or -//! 3V3 to see the maximum and minimum raw values read. - -#![no_std] -#![no_main] - -use esp32s3_hal::{ - adc::{self, AdcConfig, Attenuation, ADC}, - clock::ClockControl, - gpio::IO, - peripherals::{Peripherals, ADC1}, - prelude::*, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create ADC instances - // You can try any of the following calibration methods by uncommenting them. - // Note that only AdcCalLine and AdcCalCurve return readings in mV; the other - // two return raw readings in some unspecified scale. - // - // type AdcCal = (); - // type AdcCal = adc::AdcCalBasic; - // type AdcCal = adc::AdcCalLine; - type AdcCal = adc::AdcCalCurve; - - let mut adc1_config = AdcConfig::new(); - let mut pin = adc1_config.enable_pin_with_cal::<_, AdcCal>( - io.pins.gpio3.into_analog(), - Attenuation::Attenuation11dB, - ); - let mut adc1 = ADC::::new(peripherals.ADC1, adc1_config); - - let mut delay = Delay::new(&clocks); - - loop { - let pin_mv = nb::block!(adc1.read(&mut pin)).unwrap(); - println!("PIN2 ADC reading = {pin_mv} mV"); - delay.delay_ms(1500u32); - } -} diff --git a/esp32s3-hal/examples/advanced_serial.rs b/esp32s3-hal/examples/advanced_serial.rs deleted file mode 100644 index 6dd575c72..000000000 --- a/esp32s3-hal/examples/advanced_serial.rs +++ /dev/null @@ -1,64 +0,0 @@ -//! This shows how to configure UART -//! You can short the TX and RX pin and see it reads what was written. -//! Additionally you can connect a logic analzyer to TX and see how the changes -//! of the configuration change the output signal. -//! -//! The following wiring is assumed: -//! - TX => GPIO1 -//! - RX => GPIO2 - -#![no_std] -#![no_main] - -use esp32s3_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - uart::{ - config::{Config, DataBits, Parity, StopBits}, - TxRxPins, - }, - Delay, - Uart, -}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let config = Config { - baudrate: 115200, - data_bits: DataBits::DataBits8, - parity: Parity::ParityNone, - stop_bits: StopBits::STOP1, - }; - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let pins = TxRxPins::new_tx_rx( - io.pins.gpio1.into_push_pull_output(), - io.pins.gpio2.into_floating_input(), - ); - - let mut serial1 = Uart::new_with_config(peripherals.UART1, config, Some(pins), &clocks); - - let mut delay = Delay::new(&clocks); - - println!("Start"); - loop { - serial1.write(0x42).ok(); - let read = block!(serial1.read()); - - match read { - Ok(read) => println!("Read 0x{:02x}", read), - Err(err) => println!("Error {:?}", err), - } - - delay.delay_ms(250u32); - } -} diff --git a/esp32s3-hal/examples/aes.rs b/esp32s3-hal/examples/aes.rs deleted file mode 100644 index ec5eaf3fc..000000000 --- a/esp32s3-hal/examples/aes.rs +++ /dev/null @@ -1,85 +0,0 @@ -//! Encrypt/Decrypt a message using AES. - -#![no_std] -#![no_main] -use aes::{ - cipher::{generic_array::GenericArray, BlockDecrypt, BlockEncrypt, KeyInit}, - Aes128 as Aes128SW, -}; -use esp32s3_hal::{ - aes::{Aes, Mode}, - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - xtensa_lx, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut aes = Aes::new(peripherals.AES); - - let keytext = "SUp4SeCp@sSw0rd".as_bytes(); - let plaintext = "message".as_bytes(); - - // create an array with aes128 key size - let mut keybuf = [0_u8; 16]; - keybuf[..keytext.len()].copy_from_slice(keytext); - - // create an array with aes block size - let mut block_buf = [0_u8; 16]; - block_buf[..plaintext.len()].copy_from_slice(plaintext); - - let mut block = block_buf.clone(); - let pre_hw_encrypt = xtensa_lx::timer::get_cycle_count(); - aes.process(&mut block, Mode::Encryption128, &keybuf); - let post_hw_encrypt = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for hw encrypt", - post_hw_encrypt - pre_hw_encrypt - ); - let hw_encrypted = block.clone(); - let pre_hw_decrypt = xtensa_lx::timer::get_cycle_count(); - aes.process(&mut block, Mode::Decryption128, &keybuf); - let post_hw_decrypt = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for hw decrypt", - post_hw_decrypt - pre_hw_decrypt - ); - let hw_decrypted = block; - - let key = GenericArray::from(keybuf); - let mut block = GenericArray::from(block_buf); - let cipher = Aes128SW::new(&key); - let pre_sw_encrypt = xtensa_lx::timer::get_cycle_count(); - cipher.encrypt_block(&mut block); - let post_sw_encrypt = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for sw encrypt", - post_sw_encrypt - pre_sw_encrypt - ); - let sw_encrypted = block.clone(); - let pre_sw_decrypt = xtensa_lx::timer::get_cycle_count(); - cipher.decrypt_block(&mut block); - let post_sw_decrypt = xtensa_lx::timer::get_cycle_count(); - println!( - "it took {} cycles for sw decrypt", - post_sw_decrypt - pre_sw_decrypt - ); - let sw_decrypted = block; - - assert!(eq(&sw_encrypted.into(), &hw_encrypted)); - assert!(eq(&sw_decrypted.into(), &hw_decrypted)); - - println!("done"); - - loop {} -} -fn eq(slice1: &[u8; 16], slice2: &[u8; 16]) -> bool { - slice1.iter().zip(slice2.iter()).all(|(a, b)| a == b) -} diff --git a/esp32s3-hal/examples/aes_dma.rs b/esp32s3-hal/examples/aes_dma.rs deleted file mode 100644 index 742e8185c..000000000 --- a/esp32s3-hal/examples/aes_dma.rs +++ /dev/null @@ -1,153 +0,0 @@ -//! Encrypt/Decrypt a message using AES - -#![no_std] -#![no_main] -use aes::{ - cipher::{generic_array::GenericArray, BlockDecrypt, BlockEncrypt, KeyInit}, - Aes128 as Aes128SW, -}; -use esp32s3_hal::{ - aes::{ - dma::{CipherMode, WithDmaAes}, - Aes, - Mode, - }, - clock::ClockControl, - dma::{Dma, DmaDescriptor, DmaPriority}, - peripherals::Peripherals, - prelude::*, - systimer::SystemTimer, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let mut descriptors = [DmaDescriptor::EMPTY; 1]; - let mut rx_descriptors = [DmaDescriptor::EMPTY; 1]; - - let aes = Aes::new(peripherals.AES).with_dma(dma_channel.configure( - false, - &mut descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let keytext = buffer1(); - let plaintext = buffer2(); - plaintext.copy_from_slice(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); - keytext.copy_from_slice(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); - - // create an array with aes128 key size - let mut keybuf = [0_u8; 16]; - keybuf[..keytext.len()].copy_from_slice(keytext); - - // create an array with aes block size - let mut block_buf = [0_u8; 16]; - block_buf[..plaintext.len()].copy_from_slice(plaintext); - - let hw_encrypted = buffer3(); - let pre_hw_encrypt = SystemTimer::now(); - let transfer = aes - .process( - plaintext, - hw_encrypted, - Mode::Encryption128, - CipherMode::Ecb, - keybuf, - ) - .unwrap(); - let (hw_encrypted, plaintext, aes) = transfer.wait().unwrap(); - let post_hw_encrypt = SystemTimer::now(); - println!( - "it took {} cycles for hw encrypt", - post_hw_encrypt - pre_hw_encrypt - ); - - let keytext = buffer4(); - plaintext.copy_from_slice(hw_encrypted); - keytext.copy_from_slice(&[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]); - - let mut keybuf = [0_u8; 16]; - keybuf[..keytext.len()].copy_from_slice(keytext); - - let hw_decrypted = buffer5(); - let pre_hw_decrypt = SystemTimer::now(); - let transfer = aes - .process( - plaintext, - hw_decrypted, - Mode::Decryption128, - CipherMode::Ecb, - keybuf, - ) - .unwrap(); - let (hw_decrypted, _, _) = transfer.wait().unwrap(); - let post_hw_decrypt = SystemTimer::now(); - println!( - "it took {} cycles for hw decrypt", - post_hw_decrypt - pre_hw_decrypt - ); - - let key = GenericArray::from(keybuf); - let mut block = GenericArray::from(block_buf); - let cipher = Aes128SW::new(&key); - let pre_sw_encrypt = SystemTimer::now(); - cipher.encrypt_block(&mut block); - let post_sw_encrypt = SystemTimer::now(); - println!( - "it took {} cycles for sw encrypt", - post_sw_encrypt - pre_sw_encrypt - ); - let sw_encrypted = block.clone(); - let pre_sw_decrypt = SystemTimer::now(); - cipher.decrypt_block(&mut block); - let post_sw_decrypt = SystemTimer::now(); - println!( - "it took {} cycles for sw decrypt", - post_sw_decrypt - pre_sw_decrypt - ); - let sw_decrypted = block.clone(); - - assert!(eq(&sw_encrypted.into(), &hw_encrypted)); - assert!(eq(&sw_decrypted.into(), &hw_decrypted)); - - println!("done"); - loop {} -} - -fn buffer1() -> &'static mut [u8; 16] { - static mut BUFFER: [u8; 16] = [0u8; 16]; - unsafe { &mut BUFFER } -} - -fn buffer2() -> &'static mut [u8; 16] { - static mut BUFFER: [u8; 16] = [0u8; 16]; - unsafe { &mut BUFFER } -} - -fn buffer3() -> &'static mut [u8; 16] { - static mut BUFFER: [u8; 16] = [0u8; 16]; - unsafe { &mut BUFFER } -} - -fn buffer4() -> &'static mut [u8; 16] { - static mut BUFFER: [u8; 16] = [0u8; 16]; - unsafe { &mut BUFFER } -} - -fn buffer5() -> &'static mut [u8; 16] { - static mut BUFFER: [u8; 16] = [0u8; 16]; - unsafe { &mut BUFFER } -} - -fn eq(slice1: &[u8; 16], slice2: &[u8; 16]) -> bool { - slice1.iter().zip(slice2.iter()).all(|(a, b)| a == b) -} diff --git a/esp32s3-hal/examples/blinky.rs b/esp32s3-hal/examples/blinky.rs deleted file mode 100644 index 9502bb199..000000000 --- a/esp32s3-hal/examples/blinky.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! Blinks an LED -//! -//! This assumes that a LED is connected to the pin assigned to `led`. (GPIO4) - -#![no_std] -#![no_main] - -use esp32s3_hal::{clock::ClockControl, gpio::IO, peripherals::Peripherals, prelude::*, Delay}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Set GPIO4 as an output, and set its state high initially. - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut led = io.pins.gpio4.into_push_pull_output(); - - led.set_high().unwrap(); - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - loop { - led.toggle().unwrap(); - delay.delay_ms(500u32); - } -} diff --git a/esp32s3-hal/examples/blinky_erased_pins.rs b/esp32s3-hal/examples/blinky_erased_pins.rs deleted file mode 100644 index 842488ca2..000000000 --- a/esp32s3-hal/examples/blinky_erased_pins.rs +++ /dev/null @@ -1,53 +0,0 @@ -//! Blinks an LED -//! -//! This assumes that LEDs are connected to GPIO3, 4 and 5. - -#![no_std] -#![no_main] - -use esp32s3_hal::{ - clock::ClockControl, - gpio::{AnyPin, Input, Output, PullDown, PushPull, IO}, - peripherals::Peripherals, - prelude::*, - Delay, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Set LED GPIOs as an output. - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let led1 = io.pins.gpio3.into_push_pull_output(); - let led2 = io.pins.gpio4.into_push_pull_output(); - let led3 = io.pins.gpio5.into_push_pull_output(); - - // Set GPIO9 as an input. - let button = io.pins.gpio0.into_pull_down_input().into(); - - // You can use `into` or `degrade` - let mut pins = [led1.into(), led2.into(), led3.degrade().into()]; - - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. - let mut delay = Delay::new(&clocks); - - loop { - toggle_pins(&mut pins, &button); - delay.delay_ms(500u32); - } -} - -fn toggle_pins(leds: &mut [AnyPin>], button: &AnyPin>) { - for pin in leds.iter_mut() { - pin.toggle().unwrap(); - } - - if button.is_low().unwrap() { - esp_println::println!("Button"); - } -} diff --git a/esp32s3-hal/examples/debug_assist.rs b/esp32s3-hal/examples/debug_assist.rs deleted file mode 100644 index 67f1599d0..000000000 --- a/esp32s3-hal/examples/debug_assist.rs +++ /dev/null @@ -1,78 +0,0 @@ -//! This shows debug-assist -//! -//! Uncomment the functionality you want to test - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32s3_hal::{ - assist_debug::DebugAssist, - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, -}; -use esp_backtrace as _; -use esp_println::println; - -static DA: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut da = DebugAssist::new(peripherals.ASSIST_DEBUG); - - // uncomment the functionality you want to test - - da.enable_region0_monitor(0x3fcce000, 0x3fcce100, true, true); - // da.enable_region1_monitor(0x3fcce000, 0x3fcce100, true, true); - - critical_section::with(|cs| DA.borrow_ref_mut(cs).replace(da)); - - interrupt::enable( - peripherals::Interrupt::ASSIST_DEBUG, - interrupt::Priority::Priority3, - ) - .unwrap(); - - eat_up_stack(0); - - loop {} -} - -#[allow(unconditional_recursion)] -fn eat_up_stack(v: u32) { - println!("Iteration {v}"); - eat_up_stack(v + 1); -} - -#[interrupt] -fn ASSIST_DEBUG() { - critical_section::with(|cs| { - println!("\n\nDEBUG_ASSIST interrupt"); - let mut da = DA.borrow_ref_mut(cs); - let da = da.as_mut().unwrap(); - - if da.is_region0_monitor_interrupt_set() { - println!("REGION0 MONITOR TRIGGERED"); - da.clear_region0_monitor_interrupt(); - let pc = da.get_region_monitor_pc(); - println!("PC = 0x{:x}", pc); - } - - if da.is_region1_monitor_interrupt_set() { - println!("REGION1 MONITOR TRIGGERED"); - da.clear_region1_monitor_interrupt(); - let pc = da.get_region_monitor_pc(); - println!("PC = 0x{:x}", pc); - } - - loop {} - }); -} diff --git a/esp32s3-hal/examples/embassy_hello_world.rs b/esp32s3-hal/examples/embassy_hello_world.rs deleted file mode 100644 index 82daacd65..000000000 --- a/esp32s3-hal/examples/embassy_hello_world.rs +++ /dev/null @@ -1,53 +0,0 @@ -//! embassy hello world -//! -//! This is an example of running the embassy executor with multiple tasks -//! concurrently. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32s3_hal::{ - clock::ClockControl, - embassy::{self}, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; - -#[embassy_executor::task] -async fn run() { - loop { - esp_println::println!("Hello world from embassy using esp-hal-async!"); - Timer::after(Duration::from_millis(1_000)).await; - } -} - -#[main] -async fn main(spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32s3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - spawner.spawn(run()).ok(); - - loop { - esp_println::println!("Bing!"); - Timer::after(Duration::from_millis(5_000)).await; - } -} diff --git a/esp32s3-hal/examples/embassy_i2c.rs b/esp32s3-hal/examples/embassy_i2c.rs deleted file mode 100644 index a4f1d3161..000000000 --- a/esp32s3-hal/examples/embassy_i2c.rs +++ /dev/null @@ -1,67 +0,0 @@ -//! Embassy I2C -//! -//! Folowing pins are used: -//! SDA GPIO1 -//! SCL GPIO2 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This is an example of running the embassy executor with IC2. It uses an -//! LIS3DH to get accelerometer data. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32s3_hal::{ - clock::ClockControl, - embassy::{self}, - i2c::I2C, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; -use lis3dh_async::{Lis3dh, Range, SlaveAddr}; - -#[main] -async fn main(_spawner: Spawner) { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32s3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let i2c0 = I2C::new( - peripherals.I2C0, - io.pins.gpio1, - io.pins.gpio2, - 400u32.kHz(), - &clocks, - ); - - let mut lis3dh = Lis3dh::new_i2c(i2c0, SlaveAddr::Alternate).await.unwrap(); - lis3dh.set_range(Range::G8).await.unwrap(); - - loop { - let norm = lis3dh.accel_norm().await.unwrap(); - esp_println::println!("X: {:+.5} Y: {:+.5} Z: {:+.5}", norm.x, norm.y, norm.z); - - Timer::after(Duration::from_millis(100)).await; - } -} diff --git a/esp32s3-hal/examples/embassy_multicore.rs b/esp32s3-hal/examples/embassy_multicore.rs deleted file mode 100644 index 67b857b50..000000000 --- a/esp32s3-hal/examples/embassy_multicore.rs +++ /dev/null @@ -1,97 +0,0 @@ -//! This example shows how to spawn async tasks on the second core. -//! The second core runs a simple LED blinking task, that is controlled by a -//! signal set by the task running on the other core. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, signal::Signal}; -use embassy_time::{Duration, Ticker}; -use esp32s3_hal::{ - clock::ClockControl, - cpu_control::{CpuControl, Stack}, - embassy::{self, executor::Executor}, - get_core, - gpio::{GpioPin, Output, PushPull, IO}, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; -use esp_println::println; -use static_cell::make_static; - -static mut APP_CORE_STACK: Stack<8192> = Stack::new(); - -/// Waits for a message that contains a duration, then flashes a led for that -/// duration of time. -#[embassy_executor::task] -async fn control_led( - mut led: GpioPin, 0>, - control: &'static Signal, -) { - println!("Starting control_led() on core {}", get_core() as usize); - loop { - if control.wait().await { - esp_println::println!("LED on"); - led.set_low().unwrap(); - } else { - esp_println::println!("LED off"); - led.set_high().unwrap(); - } - } -} - -#[main] -async fn main(_spawner: Spawner) { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Set GPIO2 as an output, and set its state high initially. - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32s3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let mut cpu_control = CpuControl::new(system.cpu_control); - - let led_ctrl_signal = &*make_static!(Signal::new()); - - let led = io.pins.gpio0.into_push_pull_output(); - let cpu1_fnctn = move || { - let executor = make_static!(Executor::new()); - executor.run(|spawner| { - spawner.spawn(control_led(led, led_ctrl_signal)).ok(); - }); - }; - let _guard = cpu_control - .start_app_core(unsafe { &mut APP_CORE_STACK }, cpu1_fnctn) - .unwrap(); - - // Sends periodic messages to control_led, enabling or disabling it. - println!( - "Starting enable_disable_led() on core {}", - get_core() as usize - ); - let mut ticker = Ticker::every(Duration::from_secs(1)); - loop { - esp_println::println!("Sending LED on"); - led_ctrl_signal.signal(true); - ticker.next().await; - - esp_println::println!("Sending LED off"); - led_ctrl_signal.signal(false); - ticker.next().await; - } -} diff --git a/esp32s3-hal/examples/embassy_multicore_interrupt.rs b/esp32s3-hal/examples/embassy_multicore_interrupt.rs deleted file mode 100644 index 522139ab9..000000000 --- a/esp32s3-hal/examples/embassy_multicore_interrupt.rs +++ /dev/null @@ -1,124 +0,0 @@ -//! This example shows how to use the interrupt executors on either core. -//! The second core runs a simple LED blinking task, that is controlled by a -//! signal set by the task running on the other core. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, signal::Signal}; -use embassy_time::{Duration, Ticker}; -use esp32s3_hal::{ - clock::ClockControl, - cpu_control::{CpuControl, Stack}, - embassy::{ - self, - executor::{FromCpu1, FromCpu2, InterruptExecutor}, - }, - get_core, - gpio::{GpioPin, Output, PushPull, IO}, - interrupt::Priority, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; -use esp_println::println; -use static_cell::make_static; - -static mut APP_CORE_STACK: Stack<8192> = Stack::new(); - -static INT_EXECUTOR_CORE_0: InterruptExecutor = InterruptExecutor::new(); -static INT_EXECUTOR_CORE_1: InterruptExecutor = InterruptExecutor::new(); - -#[interrupt] -fn FROM_CPU_INTR1() { - unsafe { INT_EXECUTOR_CORE_0.on_interrupt() } -} - -#[interrupt] -fn FROM_CPU_INTR2() { - unsafe { INT_EXECUTOR_CORE_1.on_interrupt() } -} - -/// Waits for a message that contains a duration, then flashes a led for that -/// duration of time. -#[embassy_executor::task] -async fn control_led( - mut led: GpioPin, 0>, - control: &'static Signal, -) { - println!("Starting control_led() on core {}", get_core() as usize); - loop { - if control.wait().await { - esp_println::println!("LED on"); - led.set_low().unwrap(); - } else { - esp_println::println!("LED off"); - led.set_high().unwrap(); - } - } -} - -/// Sends periodic messages to control_led, enabling or disabling it. -#[embassy_executor::task] -async fn enable_disable_led(control: &'static Signal) { - println!( - "Starting enable_disable_led() on core {}", - get_core() as usize - ); - let mut ticker = Ticker::every(Duration::from_secs(1)); - loop { - esp_println::println!("Sending LED on"); - control.signal(true); - ticker.next().await; - - esp_println::println!("Sending LED off"); - control.signal(false); - ticker.next().await; - } -} - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Set GPIO2 as an output, and set its state high initially. - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32s3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let mut cpu_control = CpuControl::new(system.cpu_control); - - let led_ctrl_signal = &*make_static!(Signal::new()); - - let led = io.pins.gpio0.into_push_pull_output(); - let cpu1_fnctn = move || { - let spawner = INT_EXECUTOR_CORE_1.start(Priority::Priority1); - - spawner.spawn(control_led(led, led_ctrl_signal)).ok(); - - // Just loop to show that the main thread does not need to poll the executor. - loop {} - }; - let _guard = cpu_control - .start_app_core(unsafe { &mut APP_CORE_STACK }, cpu1_fnctn) - .unwrap(); - - let spawner = INT_EXECUTOR_CORE_0.start(Priority::Priority1); - spawner.spawn(enable_disable_led(led_ctrl_signal)).ok(); - - // Just loop to show that the main thread does not need to poll the executor. - loop {} -} diff --git a/esp32s3-hal/examples/embassy_multiprio.rs b/esp32s3-hal/examples/embassy_multiprio.rs deleted file mode 100644 index 06ebdf932..000000000 --- a/esp32s3-hal/examples/embassy_multiprio.rs +++ /dev/null @@ -1,100 +0,0 @@ -//! This example shows how to use the interrupt executors to prioritize some -//! tasks over others. -//! -//! The example creates three tasks: -//! - A low priority task that is not actually async, but simulates some -//! blocking work. This task will run for 5 seconds, then sleep for 5 -//! seconds. -//! - A low priority task that is actually async, but will not be able to run -//! while the blocking task is running. -//! - A high priority task that prints something every second. The example -//! demonstrates that this task will continue to run even while the low -//! priority blocking task is running. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Instant, Ticker, Timer}; -use esp32s3_hal::{ - clock::ClockControl, - embassy::{ - self, - executor::{FromCpu1, InterruptExecutor}, - }, - interrupt::Priority, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; -use esp_println::println; - -static INT_EXECUTOR_0: InterruptExecutor = InterruptExecutor::new(); - -#[interrupt] -fn FROM_CPU_INTR1() { - unsafe { INT_EXECUTOR_0.on_interrupt() } -} - -/// Periodically print something. -#[embassy_executor::task] -async fn high_prio() { - println!("Starting high_prio()"); - let mut ticker = Ticker::every(Duration::from_secs(1)); - loop { - println!("High priority ticks"); - ticker.next().await; - } -} - -/// Simulates some blocking (badly behaving) task. -#[embassy_executor::task] -async fn low_prio_blocking() { - println!("Starting low-priority task that isn't actually async"); - loop { - println!("Doing some long and complicated calculation"); - let start = Instant::now(); - while start.elapsed() < Duration::from_secs(5) {} - println!("Calculation finished"); - Timer::after(Duration::from_secs(5)).await; - } -} - -/// A well-behaved, but starved async task. -#[embassy_executor::task] -async fn low_prio_async() { - println!("Starting low-priority task that will not be able to run while the blocking task is running"); - let mut ticker = Ticker::every(Duration::from_secs(1)); - loop { - println!("Low priority ticks"); - ticker.next().await; - } -} - -#[main] -async fn main(low_prio_spawner: Spawner) { - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32s3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let spawner = INT_EXECUTOR_0.start(Priority::Priority2); - spawner.must_spawn(high_prio()); - - println!("Spawning low-priority tasks"); - low_prio_spawner.must_spawn(low_prio_async()); - low_prio_spawner.must_spawn(low_prio_blocking()); -} diff --git a/esp32s3-hal/examples/embassy_rmt_rx.rs b/esp32s3-hal/examples/embassy_rmt_rx.rs deleted file mode 100644 index 1d3e8da01..000000000 --- a/esp32s3-hal/examples/embassy_rmt_rx.rs +++ /dev/null @@ -1,110 +0,0 @@ -//! Demonstrates decoding pulse sequences with RMT -//! This uses the boot button as input - press the button a couple of -//! times to generate a pulse sequence and then wait for the idle timeout to see -//! the recorded pulse sequence - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use esp32s3_hal::{ - clock::ClockControl, - embassy::{self}, - peripherals::Peripherals, - prelude::*, - rmt::{asynch::RxChannelAsync, PulseCode, RxChannelConfig, RxChannelCreator}, - Rmt, - IO, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -const WIDTH: usize = 80; - -#[main] -async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32s3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let rmt = Rmt::new(peripherals.RMT, 8u32.MHz(), &clocks).unwrap(); - - let mut channel = rmt - .channel4 - .configure( - io.pins.gpio0, - RxChannelConfig { - clk_divider: 255, - idle_threshold: 10000, - ..RxChannelConfig::default() - }, - ) - .unwrap(); - - let mut data = [PulseCode { - level1: true, - length1: 1, - level2: false, - length2: 1, - }; 48]; - - loop { - println!("receive"); - channel.receive(&mut data).await.unwrap(); - println!("received"); - let mut total = 0usize; - for entry in &data[..data.len()] { - if entry.length1 == 0 { - break; - } - total += entry.length1 as usize; - - if entry.length2 == 0 { - break; - } - total += entry.length2 as usize; - } - - for entry in &data[..data.len()] { - if entry.length1 == 0 { - break; - } - - let count = WIDTH / (total / entry.length1 as usize); - let c = if entry.level1 { '-' } else { '_' }; - for _ in 0..count + 1 { - print!("{}", c); - } - - if entry.length2 == 0 { - break; - } - - let count = WIDTH / (total / entry.length2 as usize); - let c = if entry.level2 { '-' } else { '_' }; - for _ in 0..count + 1 { - print!("{}", c); - } - } - - println!(); - } -} diff --git a/esp32s3-hal/examples/embassy_rmt_tx.rs b/esp32s3-hal/examples/embassy_rmt_tx.rs deleted file mode 100644 index ad2c412ee..000000000 --- a/esp32s3-hal/examples/embassy_rmt_tx.rs +++ /dev/null @@ -1,79 +0,0 @@ -//! Demonstrates generating pulse sequences with RMT -//! Connect a logic analyzer to GPIO1 to see the generated pulses. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32s3_hal::{ - clock::ClockControl, - embassy::{self}, - peripherals::Peripherals, - prelude::*, - rmt::{asynch::TxChannelAsync, PulseCode, TxChannelConfig, TxChannelCreator}, - Rmt, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -#[main] -async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); - println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32s3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let rmt = Rmt::new(peripherals.RMT, 8u32.MHz(), &clocks).unwrap(); - - let mut channel = rmt - .channel0 - .configure( - io.pins.gpio1.into_push_pull_output(), - TxChannelConfig { - clk_divider: 255, - ..TxChannelConfig::default() - }, - ) - .unwrap(); - - let mut data = [PulseCode { - level1: true, - length1: 200, - level2: false, - length2: 50, - }; 20]; - - data[data.len() - 2] = PulseCode { - level1: true, - length1: 3000, - level2: false, - length2: 500, - }; - data[data.len() - 1] = PulseCode::default(); - - loop { - println!("transmit"); - channel.transmit(&data).await.unwrap(); - println!("transmitted\n"); - Timer::after(Duration::from_millis(500)).await; - } -} diff --git a/esp32s3-hal/examples/embassy_serial.rs b/esp32s3-hal/examples/embassy_serial.rs deleted file mode 100644 index 3805c5220..000000000 --- a/esp32s3-hal/examples/embassy_serial.rs +++ /dev/null @@ -1,96 +0,0 @@ -//! embassy serial -//! -//! This is an example of running the embassy executor and asynchronously -//! writing to and reading from uart - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_sync::{blocking_mutex::raw::NoopRawMutex, signal::Signal}; -use esp32s3_hal::{ - clock::ClockControl, - embassy, - peripherals::{Peripherals, UART0}, - prelude::*, - uart::{config::AtCmdConfig, UartRx, UartTx}, - Uart, -}; -use esp_backtrace as _; -use static_cell::make_static; - -// rx_fifo_full_threshold -const READ_BUF_SIZE: usize = 64; -// EOT (CTRL-D) -const AT_CMD: u8 = 0x04; - -#[embassy_executor::task] -async fn writer(mut tx: UartTx<'static, UART0>, signal: &'static Signal) { - use core::fmt::Write; - embedded_io_async::Write::write( - &mut tx, - b"Hello async serial. Enter something ended with EOT (CTRL-D).\r\n", - ) - .await - .unwrap(); - embedded_io_async::Write::flush(&mut tx).await.unwrap(); - loop { - let bytes_read = signal.wait().await; - signal.reset(); - write!(&mut tx, "\r\n-- received {} bytes --\r\n", bytes_read).unwrap(); - embedded_io_async::Write::flush(&mut tx).await.unwrap(); - } -} - -#[embassy_executor::task] -async fn reader(mut rx: UartRx<'static, UART0>, signal: &'static Signal) { - const MAX_BUFFER_SIZE: usize = 10 * READ_BUF_SIZE + 16; - - let mut rbuf: [u8; MAX_BUFFER_SIZE] = [0u8; MAX_BUFFER_SIZE]; - let mut offset = 0; - loop { - let r = embedded_io_async::Read::read(&mut rx, &mut rbuf[offset..]).await; - match r { - Ok(len) => { - offset += len; - esp_println::println!("Read: {len}, data: {:?}", &rbuf[..offset]); - offset = 0; - signal.signal(len); - } - Err(e) => esp_println::println!("RX Error: {:?}", e), - } - } -} - -#[main] -async fn main(spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32s3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - uart0.set_at_cmd(AtCmdConfig::new(None, None, None, AT_CMD, None)); - uart0 - .set_rx_fifo_full_threshold(READ_BUF_SIZE as u16) - .unwrap(); - let (tx, rx) = uart0.split(); - - let signal = &*make_static!(Signal::new()); - - spawner.spawn(reader(rx, &signal)).ok(); - spawner.spawn(writer(tx, &signal)).ok(); -} diff --git a/esp32s3-hal/examples/embassy_spi.rs b/esp32s3-hal/examples/embassy_spi.rs deleted file mode 100644 index ff0f51ed5..000000000 --- a/esp32s3-hal/examples/embassy_spi.rs +++ /dev/null @@ -1,87 +0,0 @@ -//! Embassy SPI -//! -//! Folowing pins are used: -//! SCLK GPIO6 -//! MISO GPIO2 -//! MOSI GPIO7 -//! CS GPIO10 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. -//! -//! This is an example of running the embassy executor with SPI. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use esp32s3_hal::{ - clock::ClockControl, - dma::{DmaPriority, *}, - dma_descriptors, - embassy::{self}, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{prelude::*, Spi}, - SpiMode, - }, - IO, -}; -use esp_backtrace as _; - -#[main] -async fn main(_spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32s3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio6; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio7; - let cs = io.pins.gpio10; - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (mut descriptors, mut rx_descriptors) = dma_descriptors!(32000); - - let mut spi = Spi::new(peripherals.SPI3, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) - .with_dma(dma_channel.configure( - false, - &mut descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let send_buffer = [0, 1, 2, 3, 4, 5, 6, 7]; - loop { - let mut buffer = [0; 8]; - esp_println::println!("Sending bytes"); - embedded_hal_async::spi::SpiBus::transfer(&mut spi, &mut buffer, &send_buffer) - .await - .unwrap(); - esp_println::println!("Bytes recieved: {:?}", buffer); - Timer::after(Duration::from_millis(5_000)).await; - } -} diff --git a/esp32s3-hal/examples/embassy_usb_serial_jtag.rs b/esp32s3-hal/examples/embassy_usb_serial_jtag.rs deleted file mode 100644 index f6c811e8b..000000000 --- a/esp32s3-hal/examples/embassy_usb_serial_jtag.rs +++ /dev/null @@ -1,88 +0,0 @@ -//! This shows how to read and write text via USB Serial/JTAG using embassy. -//! You need to connect via the Serial/JTAG interface to see any output. -//! Most dev-kits use a USB-UART-bridge - in that case you won't see any output. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_sync::{blocking_mutex::raw::NoopRawMutex, signal::Signal}; -use esp32s3_hal::{ - clock::ClockControl, - embassy, - peripherals::Peripherals, - prelude::*, - UsbSerialJtag, -}; -use esp_backtrace as _; -use esp_hal::usb_serial_jtag::{UsbSerialJtagRx, UsbSerialJtagTx}; -use static_cell::make_static; - -const MAX_BUFFER_SIZE: usize = 512; - -#[embassy_executor::task] -async fn writer( - mut tx: UsbSerialJtagTx<'static>, - signal: &'static Signal>, -) { - use core::fmt::Write; - embedded_io_async::Write::write_all( - &mut tx, - b"Hello async USB Serial JTAG. Type something.\r\n", - ) - .await - .unwrap(); - loop { - let message = signal.wait().await; - signal.reset(); - write!(&mut tx, "-- received '{}' --\r\n", message).unwrap(); - embedded_io_async::Write::flush(&mut tx).await.unwrap(); - } -} - -#[embassy_executor::task] -async fn reader( - mut rx: UsbSerialJtagRx<'static>, - signal: &'static Signal>, -) { - let mut rbuf = [0u8; MAX_BUFFER_SIZE]; - loop { - let r = embedded_io_async::Read::read(&mut rx, &mut rbuf).await; - match r { - Ok(len) => { - let mut string_buffer: heapless::Vec<_, MAX_BUFFER_SIZE> = heapless::Vec::new(); - string_buffer.extend_from_slice(&rbuf[..len]).unwrap(); - signal.signal(heapless::String::from_utf8(string_buffer).unwrap()); - } - Err(e) => esp_println::println!("RX Error: {:?}", e), - } - } -} - -#[main] -async fn main(spawner: Spawner) -> () { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32s3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); - - let (tx, rx) = UsbSerialJtag::new(peripherals.USB_DEVICE).split(); - - let signal = &*make_static!(Signal::new()); - - spawner.spawn(reader(rx, &signal)).unwrap(); - spawner.spawn(writer(tx, &signal)).unwrap(); -} diff --git a/esp32s3-hal/examples/embassy_wait.rs b/esp32s3-hal/examples/embassy_wait.rs deleted file mode 100644 index 5e26a449d..000000000 --- a/esp32s3-hal/examples/embassy_wait.rs +++ /dev/null @@ -1,50 +0,0 @@ -//! embassy wait -//! -//! This is an example of asynchronously `Wait`ing for a pin state to change. - -#![no_std] -#![no_main] -#![feature(type_alias_impl_trait)] - -use embassy_executor::Spawner; -use embassy_time::{Duration, Timer}; -use embedded_hal_async::digital::Wait; -use esp32s3_hal::{ - clock::ClockControl, - embassy::{self}, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; - -#[main] -async fn main(_spawner: Spawner) { - esp_println::println!("Init!"); - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32s3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - // GPIO 0 as input - let mut input = io.pins.gpio0.into_pull_down_input(); - - loop { - esp_println::println!("Waiting..."); - input.wait_for_rising_edge().await.unwrap(); - esp_println::println!("Ping!"); - Timer::after(Duration::from_millis(100)).await; - } -} diff --git a/esp32s3-hal/examples/hello_world.rs b/esp32s3-hal/examples/hello_world.rs deleted file mode 100644 index 47a8f8d0a..000000000 --- a/esp32s3-hal/examples/hello_world.rs +++ /dev/null @@ -1,36 +0,0 @@ -//! This shows how to write text to uart0. -//! You can see the output with `espflash` if you provide the `--monitor` option - -#![no_std] -#![no_main] - -use core::fmt::Write; - -use esp32s3_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, - Uart, -}; -use esp_backtrace as _; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let mut uart0 = Uart::new(peripherals.UART0, &clocks); - - timer0.start(1u64.secs()); - - loop { - writeln!(uart0, "Hello world!").unwrap(); - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32s3-hal/examples/hmac.rs b/esp32s3-hal/examples/hmac.rs deleted file mode 100644 index 37036aebd..000000000 --- a/esp32s3-hal/examples/hmac.rs +++ /dev/null @@ -1,121 +0,0 @@ -//! Demonstrates the use of the HMAC peripheral and compares the speed of -//! hardware-accelerated and pure software hashing. -//! -//! # Writing key -//! Before using the HMAC accelerator in upstream mode, you first need to -//! prepare a secret 256-bit HMAC key and burn the key to an empty eFuse block. -//! -//! ## ⚠️ Before writing ⚠️ -//! - From the factory, the eFuse keyblocks are programmed to be 32-byte 0x00. -//! - This example is programmed to use this value so you can skip this step if -//! you don't want to burn an eFuse key. -//! - If you skip the skip burning a custom key, you still need to [burn the -//! purpose](#burn-key-purpose). -//! - [Read more about eFuses](https://docs.espressif.com/projects/esptool/en/latest/esp32s3/espefuse/index.html) -//! -//! ## Burn key purpose -//! You first need to burn the efuse key purpose for the specified key below -//! (Default Key0). Purposes: -//! -//! | Purpose | Mode | Value | Description | -//! |--------------------------------|------------|-------|-----------------------------------------------| -//! | JTAG Re-enable | Downstream | 6 | EFUSE_KEY_PURPOSE_HMAC_DOWN_JTAG | -//! | DS Key Derivation | Downstream | 7 | EFUSE_KEY_PURPOSE_HMAC_DOWN_DIGITAL_SIGNATURE | -//! | HMAC Calculation | Upstream | 8 | EFUSE_KEY_PURPOSE_HMAC_UP | -//! | Both JTAG Re-enable and DS KDF | Downstream | 5 | EFUSE_KEY_PURPOSE_HMAC_DOWN_ALL | -//! -//! To burn the efuse key purpose `HMAC_UP` to `Key0`: -//! ```sh -//! espefuse.py burn_efuse KEY_PURPOSE_0 8 -//! ``` -//! -//! ## Use a custom key -//! You can generate a custom key file from a string using the following command -//! ```sh -//! echo -n "" | openssl dgst -sha256 -binary > key.bin -//! ``` -//! -//! You can then write your key using the following command -//! - `BLOCK_KEY0` The keyblock to program the key to. By default this example -//! uses key0. -//! - `HMAC_UP` The purpose for the key. Use HMAC_UP for upstream. -//! - `--no-read-protect` Allow to read the key from software, after writing it. -//! ```sh -//! espefuse.py burn_key BLOCK_KEY0 key.bin HMAC_UP --no-read-protect -//! ``` -//! To see the key in bytes, you can do the following: -//! ```sh -//! echo -n "" | openssl dgst -sha256 -binary | xxd -p -//! ``` -//! or from the binary file -//! ```sh -//! xxd -p key.bin -//! ``` - -#![no_std] -#![no_main] - -use esp32s3_hal::{ - clock::ClockControl, - hmac::{Hmac, HmacPurpose, KeyId}, - peripherals::Peripherals, - prelude::*, - systimer::SystemTimer, - Rng, -}; -use esp_backtrace as _; -use esp_println::println; -use hmac::{Hmac as HmacSw, Mac}; -use nb::block; -use sha2::Sha256; - -type HmacSha256 = HmacSw; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rng = Rng::new(peripherals.RNG); - - // Set sw key - let key = [0_u8; 32].as_ref(); - - let mut hw_hmac = Hmac::new(peripherals.HMAC); - - let mut src = [0_u8; 1024]; - rng.read(src.as_mut_slice()).unwrap(); - // println!("HMAC input {:02X?}", src); - - let mut output = [0u8; 32]; - - println!("Beginning stress tests..."); - println!("Testing length from 0 to {:?} bytes for HMAC...", src.len()); - for i in 0..src.len() + 1 { - let (nsrc, _) = src.split_at(i); - let mut remaining = nsrc; - hw_hmac.init(); - block!(hw_hmac.configure(HmacPurpose::ToUser, KeyId::Key0)).expect("Key purpose mismatch"); - let pre_hw_hmac = SystemTimer::now(); - while remaining.len() > 0 { - remaining = block!(hw_hmac.update(remaining)).unwrap(); - } - block!(hw_hmac.finalize(output.as_mut_slice())).unwrap(); - let post_hw_hmac = SystemTimer::now(); - let hw_time = post_hw_hmac - pre_hw_hmac; - let mut sw_hmac = HmacSha256::new_from_slice(key).expect("HMAC can take key of any size"); - let pre_sw_hash = SystemTimer::now(); - sw_hmac.update(nsrc); - let soft_result = sw_hmac.finalize().into_bytes(); - let post_sw_hash = SystemTimer::now(); - let soft_time = post_sw_hash - pre_sw_hash; - for (a, b) in output.iter().zip(soft_result) { - assert_eq!(*a, b); - } - println!("Testing for length: {:>4} | HW: {:>6} cycles, SW: {:>7} cycles (HW HMAC is {:>2}x faster)", i, hw_time, soft_time, soft_time / hw_time); - } - println!("Finished stress tests!"); - - loop {} -} diff --git a/esp32s3-hal/examples/i2c_bmp180_calibration_data.rs b/esp32s3-hal/examples/i2c_bmp180_calibration_data.rs deleted file mode 100644 index 9ce5f38f8..000000000 --- a/esp32s3-hal/examples/i2c_bmp180_calibration_data.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! Read calibration data from BMP180 sensor -//! -//! This example dumps the calibration data from a BMP180 sensor -//! -//! The following wiring is assumed: -//! - SDA => GPIO1 -//! - SCL => GPIO2 - -#![no_std] -#![no_main] - -use esp32s3_hal::{clock::ClockControl, gpio::IO, i2c::I2C, peripherals::Peripherals, prelude::*}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - // Create a new peripheral object with the described wiring - // and standard I2C clock speed - let mut i2c = I2C::new( - peripherals.I2C0, - io.pins.gpio1, - io.pins.gpio2, - 100u32.kHz(), - &clocks, - ); - - loop { - let mut data = [0u8; 22]; - i2c.write_read(0x77, &[0xaa], &mut data).ok(); - - println!("{:02x?}", data); - } -} diff --git a/esp32s3-hal/examples/i2s_sound.rs b/esp32s3-hal/examples/i2s_sound.rs deleted file mode 100644 index 78018f2ac..000000000 --- a/esp32s3-hal/examples/i2s_sound.rs +++ /dev/null @@ -1,125 +0,0 @@ -//! This shows how to transmit data continously via I2S -//! -//! Pins used -//! MCLK GPIO4 -//! BCLK GPIO1 -//! WS GPIO2 -//! DOUT GPIO3 -//! -//! Without an additional I2S sink device you can inspect the MCLK, BCLK, WS and -//! DOUT with a logic analyzer -//! -//! You can also connect e.g. a PCM510x to hear an annoying loud sine tone (full -//! scale), so turn down the volume before running this example. -//! -//! Wiring is like this -//! -//! | Pin | Connected to | -//! |-------|-----------------| -//! | BCK | GPIO1 | -//! | DIN | GPIO3 | -//! | LRCK | GPIO2 | -//! | SCK | Gnd | -//! | GND | Gnd | -//! | VIN | +3V3 | -//! | FLT | Gnd | -//! | FMT | Gnd | -//! | DEMP | Gnd | -//! | XSMT | +3V3 | - -#![no_std] -#![no_main] - -use esp32s3_hal::{ - clock::ClockControl, - dma::{Dma, DmaDescriptor, DmaPriority}, - i2s::{DataFormat, I2s, I2sWriteDma, Standard}, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; - -const SINE: [i16; 64] = [ - 0, 3211, 6392, 9511, 12539, 15446, 18204, 20787, 23169, 25329, 27244, 28897, 30272, 31356, - 32137, 32609, 32767, 32609, 32137, 31356, 30272, 28897, 27244, 25329, 23169, 20787, 18204, - 15446, 12539, 9511, 6392, 3211, 0, -3211, -6392, -9511, -12539, -15446, -18204, -20787, -23169, - -25329, -27244, -28897, -30272, -31356, -32137, -32609, -32767, -32609, -32137, -31356, -30272, - -28897, -27244, -25329, -23169, -20787, -18204, -15446, -12539, -9511, -6392, -3211, -]; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let mut tx_descriptors = [DmaDescriptor::EMPTY; 20]; - let mut rx_descriptors = [DmaDescriptor::EMPTY; 8]; - - let i2s = I2s::new( - peripherals.I2S0, - Standard::Philips, - DataFormat::Data16Channel16, - 44100u32.Hz(), - dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - ), - &clocks, - ) - .with_mclk(io.pins.gpio4); - - let i2s_tx = i2s - .i2s_tx - .with_bclk(io.pins.gpio1) - .with_ws(io.pins.gpio2) - .with_dout(io.pins.gpio3) - .build(); - - let data = - unsafe { core::slice::from_raw_parts(&SINE as *const _ as *const u8, SINE.len() * 2) }; - - let buffer = dma_buffer(); - let mut idx = 0; - for i in 0..usize::min(data.len(), buffer.len()) { - buffer[i] = data[idx]; - - idx += 1; - - if idx >= data.len() { - idx = 0; - } - } - - let mut filler = [0u8; 10000]; - - let mut transfer = i2s_tx.write_dma_circular(buffer).unwrap(); - loop { - let avail = transfer.available(); - if avail > 0 { - let avail = usize::min(10000, avail); - for bidx in 0..avail { - filler[bidx] = data[idx]; - idx += 1; - - if idx >= data.len() { - idx = 0; - } - } - transfer.push(&filler[0..avail]).unwrap(); - } - } -} - -fn dma_buffer() -> &'static mut [u8; 32000] { - static mut BUFFER: [u8; 32000] = [0u8; 32000]; - unsafe { &mut BUFFER } -} diff --git a/esp32s3-hal/examples/mcpwm.rs b/esp32s3-hal/examples/mcpwm.rs deleted file mode 100644 index b3c995545..000000000 --- a/esp32s3-hal/examples/mcpwm.rs +++ /dev/null @@ -1,49 +0,0 @@ -//! Uses timer0 and operator0 of the MCPWM0 peripheral to output a 50% duty -//! signal at 20 kHz. -//! -//! The signal will be output to the pin assigned to `pin`. (GPIO4) - -#![no_std] -#![no_main] - -use esp32s3_hal::{ - clock::ClockControl, - gpio::IO, - mcpwm::{operator::PwmPinConfig, timer::PwmWorkingMode, PeripheralClockConfig, MCPWM}, - peripherals::Peripherals, - prelude::*, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let pin = io.pins.gpio4; - - // initialize peripheral - let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 40u32.MHz()).unwrap(); - let mut mcpwm = MCPWM::new(peripherals.MCPWM0, clock_cfg); - - // connect operator0 to timer0 - mcpwm.operator0.set_timer(&mcpwm.timer0); - // connect operator0 to pin - let mut pwm_pin = mcpwm - .operator0 - .with_pin_a(pin, PwmPinConfig::UP_ACTIVE_HIGH); - - // start timer with timestamp values in the range of 0..=99 and a frequency of - // 20 kHz - let timer_clock_cfg = clock_cfg - .timer_clock_with_frequency(99, PwmWorkingMode::Increase, 20u32.kHz()) - .unwrap(); - mcpwm.timer0.start(timer_clock_cfg); - - // pin will be high 50% of the time - pwm_pin.set_timestamp(50); - - loop {} -} diff --git a/esp32s3-hal/examples/multicore.rs b/esp32s3-hal/examples/multicore.rs deleted file mode 100644 index 59d63a362..000000000 --- a/esp32s3-hal/examples/multicore.rs +++ /dev/null @@ -1,70 +0,0 @@ -//! This shows how to spawn a task on the second core. -//! The first core will print the value of a counter which is incremented by the -//! second core. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32s3_hal::{ - clock::ClockControl, - cpu_control::{CpuControl, Stack}, - peripherals::{Peripherals, TIMG1}, - prelude::*, - timer::{Timer, Timer0, TimerGroup}, -}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; - -static mut APP_CORE_STACK: Stack<8192> = Stack::new(); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks); - let mut timer1 = timer_group1.timer0; - - timer0.start(1u64.secs()); - timer1.start(500u64.millis()); - - let counter = Mutex::new(RefCell::new(0)); - - let mut cpu_control = CpuControl::new(system.cpu_control); - let cpu1_fnctn = || { - cpu1_task(&mut timer1, &counter); - }; - let _guard = cpu_control - .start_app_core(unsafe { &mut APP_CORE_STACK }, cpu1_fnctn) - .unwrap(); - - loop { - block!(timer0.wait()).unwrap(); - - let count = critical_section::with(|cs| *counter.borrow_ref(cs)); - println!("Hello World - Core 0! Counter is {}", count); - } -} - -fn cpu1_task( - timer: &mut Timer>, - counter: &critical_section::Mutex>, -) -> ! { - println!("Hello World - Core 1!"); - loop { - block!(timer.wait()).unwrap(); - - critical_section::with(|cs| { - let new_val = counter.borrow_ref_mut(cs).wrapping_add(1); - *counter.borrow_ref_mut(cs) = new_val; - }); - } -} diff --git a/esp32s3-hal/examples/pcnt_encoder.rs b/esp32s3-hal/examples/pcnt_encoder.rs deleted file mode 100644 index 17ef78b09..000000000 --- a/esp32s3-hal/examples/pcnt_encoder.rs +++ /dev/null @@ -1,134 +0,0 @@ -//! PCNT Encoder Demo -//! -//! This example decodes a quadrature encoder -//! -//! Since the PCNT units reset to zero when they reach their limits -//! we enable an interrupt on the upper and lower limits and -//! track the overflow in an AtomicI32 - -#![no_std] -#![no_main] -use core::{ - cell::RefCell, - cmp::min, - sync::atomic::{AtomicI32, Ordering}, -}; - -use critical_section::Mutex; -use esp32s3_hal as esp_hal; -use esp_backtrace as _; -use esp_hal::{ - clock::ClockControl, - interrupt, - pcnt::{channel, channel::PcntSource, unit, PCNT}, - peripherals::{self, Peripherals}, - prelude::*, - IO, -}; -use esp_println::println; - -static UNIT0: Mutex>> = Mutex::new(RefCell::new(None)); -static VALUE: AtomicI32 = AtomicI32::new(0); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let unit_number = unit::Number::Unit1; - - // setup a pulse couter - println!("setup pulse counter unit 0"); - let pcnt = PCNT::new(peripherals.PCNT); - let mut u0 = pcnt.get_unit(unit_number); - u0.configure(unit::Config { - low_limit: -100, - high_limit: 100, - filter: Some(min(10u16 * 80, 1023u16)), - ..Default::default() - }) - .unwrap(); - - println!("setup channel 0"); - let mut ch0 = u0.get_channel(channel::Number::Channel0); - let mut pin_a = io.pins.gpio5.into_pull_up_input(); - let mut pin_b = io.pins.gpio6.into_pull_up_input(); - - ch0.configure( - PcntSource::from_pin(&mut pin_a), - PcntSource::from_pin(&mut pin_b), - channel::Config { - lctrl_mode: channel::CtrlMode::Reverse, - hctrl_mode: channel::CtrlMode::Keep, - pos_edge: channel::EdgeMode::Decrement, - neg_edge: channel::EdgeMode::Increment, - invert_ctrl: false, - invert_sig: false, - }, - ); - - println!("setup channel 1"); - let mut ch1 = u0.get_channel(channel::Number::Channel1); - ch1.configure( - PcntSource::from_pin(&mut pin_b), - PcntSource::from_pin(&mut pin_a), - channel::Config { - lctrl_mode: channel::CtrlMode::Reverse, - hctrl_mode: channel::CtrlMode::Keep, - pos_edge: channel::EdgeMode::Increment, - neg_edge: channel::EdgeMode::Decrement, - invert_ctrl: false, - invert_sig: false, - }, - ); - println!("subscribing to events"); - u0.events(unit::Events { - low_limit: true, - high_limit: true, - thresh0: false, - thresh1: false, - zero: false, - }); - - println!("enabling interrupts"); - u0.listen(); - println!("resume pulse counter unit 0"); - u0.resume(); - - critical_section::with(|cs| UNIT0.borrow_ref_mut(cs).replace(u0)); - - interrupt::enable(peripherals::Interrupt::PCNT, interrupt::Priority::Priority2).unwrap(); - - let mut last_value: i32 = 0; - loop { - critical_section::with(|cs| { - let mut u0 = UNIT0.borrow_ref_mut(cs); - let u0 = u0.as_mut().unwrap(); - let value: i32 = u0.get_value() as i32 + VALUE.load(Ordering::SeqCst); - if value != last_value { - println!("value: {value}"); - last_value = value; - } - }); - } -} - -#[interrupt] -fn PCNT() { - critical_section::with(|cs| { - let mut u0 = UNIT0.borrow_ref_mut(cs); - let u0 = u0.as_mut().unwrap(); - if u0.interrupt_set() { - let events = u0.get_events(); - if events.high_limit { - VALUE.fetch_add(100, Ordering::SeqCst); - } else if events.low_limit { - VALUE.fetch_add(-100, Ordering::SeqCst); - } - u0.reset_interrupt(); - } - }); -} diff --git a/esp32s3-hal/examples/qspi_flash.rs b/esp32s3-hal/examples/qspi_flash.rs deleted file mode 100644 index c3d9b3bc1..000000000 --- a/esp32s3-hal/examples/qspi_flash.rs +++ /dev/null @@ -1,167 +0,0 @@ -//! SPI write and read a flash chip -//! -//! Folowing pins are used: -//! SCLK GPIO4 -//! MISOI/IO0 GPIO5 -//! MOSI/IO1 GPIO6 -//! IO2 GPIO7 -//! IO3 GPIO15 -//! CS GPIO16 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! Connect a flash chip (GD25Q64C was used) and make sure QE in the status -//! register is set. - -#![no_std] -#![no_main] - -use esp32s3_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{prelude::*, Address, Command, Spi}, - SpiDataMode, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio4; - let miso = io.pins.gpio5; - let mosi = io.pins.gpio6; - let sio2 = io.pins.gpio7; - let sio3 = io.pins.gpio15; - let cs = io.pins.gpio16; - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(256, 320); - - let mut spi = Spi::new_half_duplex(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(sio2), - Some(sio3), - Some(cs), - ) - .with_dma(dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let mut delay = Delay::new(&clocks); - - // DMA buffer require a static life-time - let mut zero_buf = zero_buffer(); - let send = tx_buffer; - let mut receive = rx_buffer; - - // write enable - let transfer = spi - .write( - SpiDataMode::Single, - Command::Command8(0x06, SpiDataMode::Single), - Address::None, - 0, - zero_buf, - ) - .unwrap(); - (zero_buf, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - // erase sector - let transfer = spi - .write( - SpiDataMode::Single, - Command::Command8(0x20, SpiDataMode::Single), - Address::Address24(0x000000, SpiDataMode::Single), - 0, - zero_buf, - ) - .unwrap(); - (zero_buf, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - // write enable - let transfer = spi - .write( - SpiDataMode::Single, - Command::Command8(0x06, SpiDataMode::Single), - Address::None, - 0, - zero_buf, - ) - .unwrap(); - (_, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - // write data / program page - send.fill(b'!'); - send[0..][..5].copy_from_slice(&b"Hello"[..]); - let transfer = spi - .write( - SpiDataMode::Quad, - Command::Command8(0x32, SpiDataMode::Single), - Address::Address24(0x000000, SpiDataMode::Single), - 0, - send, - ) - .unwrap(); - (_, spi) = transfer.wait().unwrap(); - delay.delay_ms(250u32); - - loop { - // quad fast read - let transfer = spi - .read( - SpiDataMode::Quad, - Command::Command8(0xeb, SpiDataMode::Single), - Address::Address32(0x000000 << 8, SpiDataMode::Quad), - 4, - receive, - ) - .unwrap(); - - // here we could do something else while DMA transfer is in progress - // the buffers and spi is moved into the transfer and we can get it back via - // `wait` - (receive, spi) = transfer.wait().unwrap(); - - println!("{:x?}", &receive); - for b in &mut receive.iter() { - if *b >= 32 && *b <= 127 { - print!("{}", *b as char); - } else { - print!("."); - } - } - println!(); - - delay.delay_ms(250u32); - } -} - -fn zero_buffer() -> &'static mut [u8; 0] { - static mut BUFFER: [u8; 0] = [0u8; 0]; - unsafe { &mut BUFFER } -} diff --git a/esp32s3-hal/examples/ram.rs b/esp32s3-hal/examples/ram.rs deleted file mode 100644 index a8927ca4e..000000000 --- a/esp32s3-hal/examples/ram.rs +++ /dev/null @@ -1,97 +0,0 @@ -//! This shows how to use RTC memory. -//! RTC memory is retained during resets and during most sleep modes. -//! Initialized memory is always re-initialized on startup. -//! Uninitialzed memory isn't initialized on startup and can be used to keep -//! data during resets. Zeroed memory is initialized to zero on startup. -//! We can also run code from RTC memory. - -#![no_std] -#![no_main] - -use esp32s3_hal::{ - clock::ClockControl, - macros::ram, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, - Rtc, -}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; - -#[ram(rtc_fast)] -static mut SOME_INITED_DATA: [u8; 2] = [0xaa, 0xbb]; - -#[ram(rtc_fast, uninitialized)] -static mut SOME_UNINITED_DATA: [u8; 2] = [0; 2]; - -#[ram(rtc_fast, zeroed)] -static mut SOME_ZEROED_DATA: [u8; 8] = [0; 8]; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - // The RWDT flash boot protection must be enabled, as it is triggered as part of - // the example. - let mut rtc = Rtc::new(peripherals.LPWR); - rtc.rwdt.enable(); - - timer0.start(1u64.secs()); - - println!( - "IRAM function located at {:p}", - function_in_ram as *const () - ); - unsafe { - println!("SOME_INITED_DATA {:x?}", SOME_INITED_DATA); - println!("SOME_UNINITED_DATA {:x?}", SOME_UNINITED_DATA); - println!("SOME_ZEROED_DATA {:x?}", SOME_ZEROED_DATA); - - SOME_INITED_DATA[0] = 0xff; - SOME_ZEROED_DATA[0] = 0xff; - - println!("SOME_INITED_DATA {:x?}", SOME_INITED_DATA); - println!("SOME_UNINITED_DATA {:x?}", SOME_UNINITED_DATA); - println!("SOME_ZEROED_DATA {:x?}", SOME_ZEROED_DATA); - - if SOME_UNINITED_DATA[0] != 0 { - SOME_UNINITED_DATA[0] = 0; - SOME_UNINITED_DATA[1] = 0; - } - - if SOME_UNINITED_DATA[1] == 0xff { - SOME_UNINITED_DATA[1] = 0; - } - - println!("Counter {}", SOME_UNINITED_DATA[1]); - SOME_UNINITED_DATA[1] += 1; - } - - println!( - "RTC_FAST function located at {:p}", - function_in_rtc_ram as *const () - ); - println!("Result {}", function_in_rtc_ram()); - - loop { - function_in_ram(); - block!(timer0.wait()).unwrap(); - } -} - -#[ram] -fn function_in_ram() { - println!("Hello world!"); -} - -#[ram(rtc_fast)] -fn function_in_rtc_ram() -> u32 { - 42 -} diff --git a/esp32s3-hal/examples/read_efuse.rs b/esp32s3-hal/examples/read_efuse.rs deleted file mode 100644 index 1329cd71a..000000000 --- a/esp32s3-hal/examples/read_efuse.rs +++ /dev/null @@ -1,21 +0,0 @@ -//! This shows how to read selected information from eFuses. -//! e.g. the MAC address - -#![no_std] -#![no_main] - -use esp32s3_hal::{clock::ClockControl, efuse::Efuse, peripherals::Peripherals, prelude::*}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - println!("MAC address {:02x?}", Efuse::get_mac_address()); - println!("Flash Encryption {:?}", Efuse::get_flash_encryption()); - - loop {} -} diff --git a/esp32s3-hal/examples/rmt_rx.rs b/esp32s3-hal/examples/rmt_rx.rs deleted file mode 100644 index 2fb3fb9a6..000000000 --- a/esp32s3-hal/examples/rmt_rx.rs +++ /dev/null @@ -1,99 +0,0 @@ -//! Demonstrates decoding pulse sequences with RMT -//! This uses the boot button as input - press the button a couple of -//! times to generate a pulse sequence and then wait for the idle timeout to see -//! the recorded pulse sequence - -#![no_std] -#![no_main] - -use esp32s3_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - rmt::{PulseCode, RxChannel, RxChannelConfig, RxChannelCreator}, - Delay, - Rmt, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -const WIDTH: usize = 80; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let rmt = Rmt::new(peripherals.RMT, 1u32.MHz(), &clocks).unwrap(); - - let mut channel = rmt - .channel7 - .configure( - io.pins.gpio0, - RxChannelConfig { - clk_divider: 255, - idle_threshold: 10000, - ..RxChannelConfig::default() - }, - ) - .unwrap(); - - let mut delay = Delay::new(&clocks); - - let mut data = [PulseCode { - level1: true, - length1: 1, - level2: false, - length2: 1, - }; 48]; - - loop { - let transaction = channel.receive(&mut data).unwrap(); - channel = transaction.wait().unwrap(); - - let mut total = 0usize; - for entry in &data[..data.len()] { - if entry.length1 == 0 { - break; - } - total += entry.length1 as usize; - - if entry.length2 == 0 { - break; - } - total += entry.length2 as usize; - } - - for entry in &data[..data.len()] { - if entry.length1 == 0 { - break; - } - - let count = WIDTH / (total / entry.length1 as usize); - let c = if entry.level1 { '-' } else { '_' }; - for _ in 0..count + 1 { - print!("{}", c); - } - - if entry.length2 == 0 { - break; - } - - let count = WIDTH / (total / entry.length2 as usize); - let c = if entry.level2 { '-' } else { '_' }; - for _ in 0..count + 1 { - print!("{}", c); - } - } - - println!(); - println!(); - println!(); - - delay.delay_ms(500u32); - } -} diff --git a/esp32s3-hal/examples/rmt_tx.rs b/esp32s3-hal/examples/rmt_tx.rs deleted file mode 100644 index d270e77c6..000000000 --- a/esp32s3-hal/examples/rmt_tx.rs +++ /dev/null @@ -1,61 +0,0 @@ -//! Demonstrates generating pulse sequences with RMT -//! Connect a logic analyzer to GPIO1 to see the generated pulses. - -#![no_std] -#![no_main] - -use esp32s3_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - rmt::{PulseCode, TxChannel, TxChannelConfig, TxChannelCreator}, - Delay, - Rmt, -}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let rmt = Rmt::new(peripherals.RMT, 8u32.MHz(), &clocks).unwrap(); - - let mut channel = rmt - .channel0 - .configure( - io.pins.gpio1, - TxChannelConfig { - clk_divider: 255, - ..TxChannelConfig::default() - }, - ) - .unwrap(); - - let mut delay = Delay::new(&clocks); - - let mut data = [PulseCode { - level1: true, - length1: 200, - level2: false, - length2: 50, - }; 20]; - - data[data.len() - 2] = PulseCode { - level1: true, - length1: 3000, - level2: false, - length2: 500, - }; - data[data.len() - 1] = PulseCode::default(); - - loop { - let transaction = channel.transmit(&data); - channel = transaction.wait().unwrap(); - delay.delay_ms(500u32); - } -} diff --git a/esp32s3-hal/examples/rng.rs b/esp32s3-hal/examples/rng.rs deleted file mode 100644 index 280d4c52c..000000000 --- a/esp32s3-hal/examples/rng.rs +++ /dev/null @@ -1,28 +0,0 @@ -//! Demonstrates the use of the hardware Random Number Generator (RNG) - -#![no_std] -#![no_main] - -use esp32s3_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Rng}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Instantiate the Random Number Generator peripheral: - let mut rng = Rng::new(peripherals.RNG); - - // Generate a random word (u32): - println!("Random u32: {}", rng.random()); - - // Fill a buffer with random bytes: - let mut buf = [0u8; 16]; - rng.read(&mut buf).unwrap(); - println!("Random bytes: {:?}", buf); - - loop {} -} diff --git a/esp32s3-hal/examples/rtc_time.rs b/esp32s3-hal/examples/rtc_time.rs deleted file mode 100644 index db3bfecf0..000000000 --- a/esp32s3-hal/examples/rtc_time.rs +++ /dev/null @@ -1,22 +0,0 @@ -//! Prints time in milliseconds from the RTC Timer - -#![no_std] -#![no_main] - -use esp32s3_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Delay, Rtc}; -use esp_backtrace as _; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let rtc = Rtc::new(peripherals.LPWR); - let mut delay = Delay::new(&clocks); - - loop { - esp_println::println!("rtc time in milliseconds is {}", rtc.get_time_ms()); - delay.delay_ms(1000u32); - } -} diff --git a/esp32s3-hal/examples/rtc_watchdog.rs b/esp32s3-hal/examples/rtc_watchdog.rs deleted file mode 100644 index a1655546f..000000000 --- a/esp32s3-hal/examples/rtc_watchdog.rs +++ /dev/null @@ -1,59 +0,0 @@ -//! This demos the RTC Watchdog Timer (RWDT). -//! The RWDT is initially configured to trigger an interrupt after a given -//! timeout. Then, upon expiration, the RWDT is restarted and then reconfigured -//! to reset both the main system and the RTC. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32s3_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, - prelude::*, - Rtc, - Rwdt, -}; -use esp_backtrace as _; - -static RWDT: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rtc = Rtc::new(peripherals.LPWR); - rtc.rwdt.start(2000u64.millis()); - rtc.rwdt.listen(); - - critical_section::with(|cs| RWDT.borrow_ref_mut(cs).replace(rtc.rwdt)); - - interrupt::enable( - peripherals::Interrupt::RTC_CORE, - interrupt::Priority::Priority1, - ) - .unwrap(); - - loop {} -} - -#[interrupt] -fn RTC_CORE() { - critical_section::with(|cs| { - esp_println::println!("RWDT Interrupt"); - - let mut rwdt = RWDT.borrow_ref_mut(cs); - let rwdt = rwdt.as_mut().unwrap(); - rwdt.clear_interrupt(); - - esp_println::println!("Restarting in 5 seconds..."); - - rwdt.start(5000u64.millis()); - rwdt.unlisten(); - }); -} diff --git a/esp32s3-hal/examples/sha.rs b/esp32s3-hal/examples/sha.rs deleted file mode 100644 index 0a61f0505..000000000 --- a/esp32s3-hal/examples/sha.rs +++ /dev/null @@ -1,72 +0,0 @@ -//! Demonstrates the use of the SHA peripheral and compares the speed of -//! hardware-accelerated and pure software hashing. - -#![no_std] -#![no_main] - -use esp32s3_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - sha::{Sha, ShaMode}, - xtensa_lx, -}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; -use sha2::{Digest, Sha512}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let source_data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".as_bytes(); - let mut remaining = source_data; - let mut hasher = Sha::new(peripherals.SHA, ShaMode::SHA512); - - // Short hashes can be created by decreasing the output buffer to the desired - // length - let mut output = [0u8; 64]; - - let pre_calc = xtensa_lx::timer::get_cycle_count(); - // The hardware implementation takes a subslice of the input, and returns the - // unprocessed parts The unprocessed parts can be input in the next - // iteration, you can always add more data until finish() is called. After - // finish() is called update()'s will contribute to a new hash which - // can be extracted again with finish(). - - while remaining.len() > 0 { - // Can add println to view progress, however println takes a few orders of - // magnitude longer than the Sha function itself so not useful for - // comparing processing time println!("Remaining len: {}", - // remaining.len()); - - // All the HW Sha functions are infallible so unwrap is fine to use if you use - // block! - remaining = block!(hasher.update(remaining)).unwrap(); - } - - // Finish can be called as many times as desired to get mutliple copies of the - // output. - block!(hasher.finish(output.as_mut_slice())).unwrap(); - let post_calc = xtensa_lx::timer::get_cycle_count(); - let hw_time = post_calc - pre_calc; - println!("Took {} cycles", hw_time); - println!("SHA512 Hash output {:02x?}", output); - - let pre_calc = xtensa_lx::timer::get_cycle_count(); - let mut hasher = Sha512::new(); - hasher.update(source_data); - let soft_result = hasher.finalize(); - let post_calc = xtensa_lx::timer::get_cycle_count(); - let soft_time = post_calc - pre_calc; - println!("Took {} cycles", soft_time); - println!("SHA512 Hash output {:02x?}", soft_result); - - assert_eq!(output, soft_result[..]); - println!("HW SHA is {}x faster", soft_time / hw_time); - - loop {} -} diff --git a/esp32s3-hal/examples/sleep_timer.rs b/esp32s3-hal/examples/sleep_timer.rs deleted file mode 100644 index 2aeec4422..000000000 --- a/esp32s3-hal/examples/sleep_timer.rs +++ /dev/null @@ -1,41 +0,0 @@ -//! Demonstrates deep sleep with timer wakeup - -#![no_std] -#![no_main] - -use core::time::Duration; - -use esp32s3_hal::{ - clock::ClockControl, - entry, - peripherals::Peripherals, - prelude::*, - rtc_cntl::{get_reset_reason, get_wakeup_cause, sleep::TimerWakeupSource, SocResetReason}, - Cpu, - Delay, - Rtc, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rtc = Rtc::new(peripherals.LPWR); - - println!("up and runnning!"); - let reason = get_reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn); - println!("reset reason: {:?}", reason); - let wake_reason = get_wakeup_cause(); - println!("wake reason: {:?}", wake_reason); - - let mut delay = Delay::new(&clocks); - - let timer = TimerWakeupSource::new(Duration::from_secs(30)); - println!("sleeping!"); - delay.delay_ms(100u32); - rtc.sleep_deep(&[&timer], &mut delay); -} diff --git a/esp32s3-hal/examples/sleep_timer_rtcio.rs b/esp32s3-hal/examples/sleep_timer_rtcio.rs deleted file mode 100644 index d6d44e25f..000000000 --- a/esp32s3-hal/examples/sleep_timer_rtcio.rs +++ /dev/null @@ -1,58 +0,0 @@ -//! Demonstrates deep sleep with timer and ext0 (using gpio18) wakeup - -#![no_std] -#![no_main] - -use core::time::Duration; - -use esp32s3_hal::{ - clock::ClockControl, - entry, - gpio::{RTCPin, RTCPinWithResistors}, - peripherals::Peripherals, - prelude::*, - rtc_cntl::{ - get_reset_reason, - get_wakeup_cause, - sleep::{RtcioWakeupSource, TimerWakeupSource, WakeupLevel}, - SocResetReason, - }, - Cpu, - Delay, - Rtc, - IO, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let mut rtc = Rtc::new(peripherals.LPWR); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut rtcio_pin18 = io.pins.gpio18; - - rtcio_pin18.rtcio_pad_hold(true); - rtcio_pin18.rtcio_pullup(true); - - println!("up and runnning!"); - let reason = get_reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn); - println!("reset reason: {:?}", reason); - let wake_reason = get_wakeup_cause(); - println!("wake reason: {:?}", wake_reason); - - let mut delay = Delay::new(&clocks); - - let timer = TimerWakeupSource::new(Duration::from_secs(30)); - - let mut wakeup_pins: [(&mut dyn RTCPin, WakeupLevel); 1] = - [(&mut rtcio_pin18, WakeupLevel::Low)]; - let rtcio = RtcioWakeupSource::new(&mut wakeup_pins); - println!("sleeping!"); - delay.delay_ms(100u32); - rtc.sleep_deep(&[&timer, &rtcio], &mut delay); -} diff --git a/esp32s3-hal/examples/software_interrupts.rs b/esp32s3-hal/examples/software_interrupts.rs deleted file mode 100644 index 88d6bc1b5..000000000 --- a/esp32s3-hal/examples/software_interrupts.rs +++ /dev/null @@ -1,139 +0,0 @@ -//! Software Interrupts -//! -//! An example of how software interrupts can be raised and reset -//! Should rotate through all of the available interrupts printing their number -//! when raised. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32s3_hal::{ - clock::ClockControl, - interrupt::{self}, - peripherals::{self, Peripherals}, - prelude::*, - system::{SoftwareInterrupt, SoftwareInterruptControl}, - Delay, -}; -use esp_backtrace as _; - -static SWINT: Mutex>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let sw_int = system.software_interrupt_control; - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - critical_section::with(|cs| SWINT.borrow_ref_mut(cs).replace(sw_int)); - - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR0, - interrupt::Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR1, - interrupt::Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR2, - interrupt::Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR3, - interrupt::Priority::Priority3, - ) - .unwrap(); - let mut delay = Delay::new(&clocks); - let mut counter = 0; - loop { - delay.delay_ms(500u32); - match counter { - 0 => critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt0); - }), - 1 => critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt1); - }), - 2 => critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt2); - }), - 3 => { - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .raise(SoftwareInterrupt::SoftwareInterrupt3); - }); - counter = -1 - } - _ => {} - } - counter += 1; - } -} - -#[interrupt] -fn FROM_CPU_INTR0() { - esp_println::println!("SW interrupt0"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt0); - }); -} -#[interrupt] -fn FROM_CPU_INTR1() { - esp_println::println!("SW interrupt1"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt1); - }); -} -#[interrupt] -fn FROM_CPU_INTR2() { - esp_println::println!("SW interrupt2"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt2); - }); -} -#[interrupt] -fn FROM_CPU_INTR3() { - esp_println::println!("SW interrupt3"); - critical_section::with(|cs| { - SWINT - .borrow_ref_mut(cs) - .as_mut() - .unwrap() - .reset(SoftwareInterrupt::SoftwareInterrupt3); - }); -} diff --git a/esp32s3-hal/examples/spi_eh1_device_loopback.rs b/esp32s3-hal/examples/spi_eh1_device_loopback.rs deleted file mode 100644 index 9066463de..000000000 --- a/esp32s3-hal/examples/spi_eh1_device_loopback.rs +++ /dev/null @@ -1,140 +0,0 @@ -//! SPI loopback test -//! -//! Folowing pins are used: -//! SCLK GPIO12 -//! MISO GPIO11 -//! MOSI GPIO13 -//! CS 1 GPIO4 -//! CS 2 GPIO5 -//! CS 3 GPIO6 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use embedded_hal_1::spi::SpiDevice; -use embedded_hal_bus::spi::RefCellDevice; -use esp32s3_hal::{ - clock::ClockControl, - gpio::{self, IO}, - peripherals::Peripherals, - prelude::*, - spi::{master::Spi, SpiMode}, - Delay, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio12; - let miso = io.pins.gpio11; - let mosi = io.pins.gpio13; - - let spi_bus = Spi::new(peripherals.SPI2, 1000u32.kHz(), SpiMode::Mode0, &clocks).with_pins( - Some(sclk), - Some(mosi), - Some(miso), - gpio::NO_PIN, - ); - let spi_bus = RefCell::new(spi_bus); - let mut spi_device_1 = - RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio4.into_push_pull_output()); - let mut spi_device_2 = - RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio5.into_push_pull_output()); - let mut spi_device_3 = - RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio6.into_push_pull_output()); - - let mut delay = Delay::new(&clocks); - println!("=== SPI example with embedded-hal-1 traits ==="); - - loop { - // --- Symmetric transfer (Read as much as we write) --- - print!("Starting symmetric transfer..."); - let write = [0xde, 0xad, 0xbe, 0xef]; - let mut read: [u8; 4] = [0x00u8; 4]; - - spi_device_1.transfer(&mut read[..], &write[..]).unwrap(); - assert_eq!(write, read); - spi_device_2.transfer(&mut read[..], &write[..]).unwrap(); - spi_device_3.transfer(&mut read[..], &write[..]).unwrap(); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Asymmetric transfer (Read more than we write) --- - print!("Starting asymetric transfer (read > write)..."); - let mut read: [u8; 4] = [0x00; 4]; - - spi_device_1 - .transfer(&mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - assert_eq!(write[0], read[0]); - assert_eq!(read[2], 0x00u8); - spi_device_2 - .transfer(&mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - spi_device_3 - .transfer(&mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer --- - // Only your RAM is the limit! - print!("Starting huge transfer..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - let mut read = [0x00u8; 4096]; - - spi_device_1 - .transfer(&mut read[..], &write[..]) - .expect("Huge transfer failed"); - assert_eq!(write, read); - spi_device_2 - .transfer(&mut read[..], &write[..]) - .expect("Huge transfer failed"); - spi_device_3 - .transfer(&mut read[..], &write[..]) - .expect("Huge transfer failed"); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer in-place (No additional allocation - // needed) --- - print!("Starting huge transfer (in-place)..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - - spi_device_1 - .transfer_in_place(&mut write[..]) - .expect("Huge transfer failed"); - for byte in 0..write.len() { - assert_eq!(write[byte], byte as u8); - } - spi_device_2 - .transfer_in_place(&mut write[..]) - .expect("Huge transfer failed"); - spi_device_3 - .transfer_in_place(&mut write[..]) - .expect("Huge transfer failed"); - println!(" SUCCESS"); - delay.delay_ms(250u32); - } -} diff --git a/esp32s3-hal/examples/spi_eh1_loopback.rs b/esp32s3-hal/examples/spi_eh1_loopback.rs deleted file mode 100644 index 6dd026738..000000000 --- a/esp32s3-hal/examples/spi_eh1_loopback.rs +++ /dev/null @@ -1,104 +0,0 @@ -//! SPI loopback test -//! -//! Folowing pins are used: -//! SCLK GPIO12 -//! MISO GPIO11 -//! MOSI GPIO13 -//! CS GPIO10 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use embedded_hal_1::spi::SpiBus; -use esp32s3_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{master::Spi, SpiMode}, - Delay, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio12; - let miso = io.pins.gpio11; - let mosi = io.pins.gpio13; - let cs = io.pins.gpio10; - - let mut spi = Spi::new(peripherals.SPI2, 1000u32.kHz(), SpiMode::Mode0, &clocks).with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(cs), - ); - - let mut delay = Delay::new(&clocks); - println!("=== SPI example with embedded-hal-1 traits ==="); - - loop { - // --- Symmetric transfer (Read as much as we write) --- - print!("Starting symmetric transfer..."); - let write = [0xde, 0xad, 0xbe, 0xef]; - let mut read: [u8; 4] = [0x00u8; 4]; - - SpiBus::transfer(&mut spi, &mut read[..], &write[..]).expect("Symmetric transfer failed"); - assert_eq!(write, read); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Asymmetric transfer (Read more than we write) --- - print!("Starting asymetric transfer (read > write)..."); - let mut read: [u8; 4] = [0x00; 4]; - - SpiBus::transfer(&mut spi, &mut read[0..2], &write[..]) - .expect("Asymmetric transfer failed"); - assert_eq!(write[0], read[0]); - assert_eq!(read[2], 0x00u8); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer --- - // Only your RAM is the limit! - print!("Starting huge transfer..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - let mut read = [0x00u8; 4096]; - - SpiBus::transfer(&mut spi, &mut read[..], &write[..]).expect("Huge transfer failed"); - assert_eq!(write, read); - println!(" SUCCESS"); - delay.delay_ms(250u32); - - // --- Symmetric transfer with huge buffer in-place (No additional allocation - // needed) --- - print!("Starting huge transfer (in-place)..."); - let mut write = [0x55u8; 4096]; - for byte in 0..write.len() { - write[byte] = byte as u8; - } - - SpiBus::transfer_in_place(&mut spi, &mut write[..]).expect("Huge transfer failed"); - for byte in 0..write.len() { - assert_eq!(write[byte], byte as u8); - } - println!(" SUCCESS"); - delay.delay_ms(250u32); - } -} diff --git a/esp32s3-hal/examples/spi_halfduplex_read_manufacturer_id.rs b/esp32s3-hal/examples/spi_halfduplex_read_manufacturer_id.rs deleted file mode 100644 index 1b3eefb00..000000000 --- a/esp32s3-hal/examples/spi_halfduplex_read_manufacturer_id.rs +++ /dev/null @@ -1,101 +0,0 @@ -//! SPI read manufacturer id from flash chip -//! -//! Folowing pins are used: -//! SCLK GPIO4 -//! MISO/IO0 GPIO5 -//! MOSI/IO1 GPIO6 -//! IO2 GPIO7 -//! IO3 GPIO15 -//! CS GPIO16 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! Connect a flash chip (GD25Q64C was used) and make sure QE in the status -//! register is set. - -#![no_std] -#![no_main] - -use esp32s3_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{Address, Command, HalfDuplexReadWrite, Spi}, - SpiDataMode, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio4; - let miso = io.pins.gpio5; - let mosi = io.pins.gpio6; - let sio2 = io.pins.gpio7; - let sio3 = io.pins.gpio15; - let cs = io.pins.gpio16; - - let mut spi = Spi::new_half_duplex(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(sio2), - Some(sio3), - Some(cs), - ); - - let mut delay = Delay::new(&clocks); - - loop { - // READ MANUFACTURER ID FROM FLASH CHIP - let mut data = [0u8; 2]; - spi.read( - SpiDataMode::Single, - Command::Command8(0x90, SpiDataMode::Single), - Address::Address24(0x000000, SpiDataMode::Single), - 0, - &mut data, - ) - .unwrap(); - println!("Single {:x?}", data); - delay.delay_ms(250u32); - - // READ MANUFACTURER ID FROM FLASH CHIP - let mut data = [0u8; 2]; - spi.read( - SpiDataMode::Dual, - Command::Command8(0x92, SpiDataMode::Single), - Address::Address32(0x000000_00, SpiDataMode::Dual), - 0, - &mut data, - ) - .unwrap(); - println!("Dual {:x?}", data); - delay.delay_ms(250u32); - - // READ MANUFACTURER ID FROM FLASH CHIP - let mut data = [0u8; 2]; - spi.read( - SpiDataMode::Quad, - Command::Command8(0x94, SpiDataMode::Single), - Address::Address32(0x000000_00, SpiDataMode::Quad), - 4, - &mut data, - ) - .unwrap(); - println!("Quad {:x?}", data); - delay.delay_ms(1500u32); - } -} diff --git a/esp32s3-hal/examples/spi_loopback.rs b/esp32s3-hal/examples/spi_loopback.rs deleted file mode 100644 index 8a7bf6b9b..000000000 --- a/esp32s3-hal/examples/spi_loopback.rs +++ /dev/null @@ -1,58 +0,0 @@ -//! SPI loopback test -//! -//! Folowing pins are used: -//! SCLK GPIO12 -//! MISO GPIO11 -//! MOSI GPIO13 -//! CS GPIO10 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use esp32s3_hal::{ - clock::ClockControl, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{master::Spi, SpiMode}, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio12; - let miso = io.pins.gpio11; - let mosi = io.pins.gpio13; - let cs = io.pins.gpio10; - - let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks).with_pins( - Some(sclk), - Some(mosi), - Some(miso), - Some(cs), - ); - - let mut delay = Delay::new(&clocks); - - loop { - let mut data = [0xde, 0xca, 0xfb, 0xad]; - spi.transfer(&mut data).unwrap(); - println!("{:x?}", data); - - delay.delay_ms(250u32); - } -} diff --git a/esp32s3-hal/examples/spi_loopback_dma.rs b/esp32s3-hal/examples/spi_loopback_dma.rs deleted file mode 100644 index f81faf294..000000000 --- a/esp32s3-hal/examples/spi_loopback_dma.rs +++ /dev/null @@ -1,97 +0,0 @@ -//! SPI loopback test using DMA -//! -//! Folowing pins are used: -//! SCLK GPIO6 -//! MISO GPIO2 -//! MOSI GPIO7 -//! CS GPIO10 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect MISO and MOSI pins to see the outgoing data is read as incoming -//! data. - -#![no_std] -#![no_main] - -use esp32s3_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - master::{prelude::*, Spi}, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio6; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio7; - let cs = io.pins.gpio10; - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(32000); - - let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) - .with_pins(Some(sclk), Some(mosi), Some(miso), Some(cs)) - .with_dma(dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let mut delay = Delay::new(&clocks); - - // DMA buffer require a static life-time - let mut send = tx_buffer; - let mut receive = rx_buffer; - let mut i = 0; - - for (i, v) in send.iter_mut().enumerate() { - *v = (i % 255) as u8; - } - - loop { - send[0] = i; - send[send.len() - 1] = i; - i = i.wrapping_add(1); - - let transfer = spi.dma_transfer(send, receive).unwrap(); - // here we could do something else while DMA transfer is in progress - let mut n = 0; - // Check is_done until the transfer is almost done (32000 bytes at 100kHz is - // 2.56 seconds), then move to wait(). - while !transfer.is_done() && n < 10 { - delay.delay_ms(250u32); - n += 1; - } - // the buffers and spi is moved into the transfer and we can get it back via - // `wait` - (receive, send, spi) = transfer.wait().unwrap(); - println!( - "{:x?} .. {:x?}", - &receive[..10], - &receive[receive.len() - 10..] - ); - - delay.delay_ms(250u32); - } -} diff --git a/esp32s3-hal/examples/spi_slave_dma.rs b/esp32s3-hal/examples/spi_slave_dma.rs deleted file mode 100644 index 11f7ebdc2..000000000 --- a/esp32s3-hal/examples/spi_slave_dma.rs +++ /dev/null @@ -1,203 +0,0 @@ -//! SPI slave loopback test using DMA -//! -//! Following pins are used for the slave: -//! SCLK GPIO6 -//! MISO GPIO2 -//! MOSI GPIO7 -//! CS GPIO10 -//! -//! Following pins are used for the (bitbang) master: -//! SCLK GPIO5 -//! MISO GPIO1 -//! MOSI GPIO8 -//! CS GPIO9 -//! -//! Depending on your target and the board you are using you have to change the -//! pins. -//! -//! This example transfers data via SPI. -//! Connect corresponding master and slave pins to see the outgoing data is read -//! as incoming data. The master-side pins are chosen to make these connections -//! easy for the barebones ESP32C3 chip; all are immediate neighbors of the -//! slave-side pins except SCLK. SCLK is between MOSI and VDD3P3_RTC on the -//! barebones ESP32C3, so no immediate neighbor is available. - -#![no_std] -#![no_main] - -use esp32s3_hal::{ - clock::ClockControl, - dma::{Dma, DmaPriority}, - dma_buffers, - gpio::IO, - peripherals::Peripherals, - prelude::*, - spi::{ - slave::{prelude::*, Spi}, - SpiMode, - }, - Delay, -}; -use esp_backtrace as _; -use esp_println::println; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let slave_sclk = io.pins.gpio6; - let mut master_sclk = io.pins.gpio5.into_push_pull_output(); - let slave_miso = io.pins.gpio2; - let master_miso = io.pins.gpio1.into_floating_input(); - let slave_mosi = io.pins.gpio7; - let mut master_mosi = io.pins.gpio8.into_push_pull_output(); - let slave_cs = io.pins.gpio10; - let mut master_cs = io.pins.gpio9.into_push_pull_output(); - master_cs.set_high().unwrap(); - master_sclk.set_low().unwrap(); - master_mosi.set_low().unwrap(); - - let dma = Dma::new(peripherals.DMA); - let dma_channel = dma.channel0; - - let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(32000); - - let mut spi = Spi::new( - peripherals.SPI2, - slave_sclk, - slave_mosi, - slave_miso, - slave_cs, - SpiMode::Mode0, - ) - .with_dma(dma_channel.configure( - false, - &mut tx_descriptors, - &mut rx_descriptors, - DmaPriority::Priority0, - )); - - let mut delay = Delay::new(&clocks); - - // DMA buffer require a static life-time - let master_send = &mut [0u8; 32000]; - let master_receive = &mut [0u8; 32000]; - let mut slave_send = tx_buffer; - let mut slave_receive = rx_buffer; - let mut i = 0; - - for (i, v) in master_send.iter_mut().enumerate() { - *v = (i % 255) as u8; - } - for (i, v) in slave_send.iter_mut().enumerate() { - *v = (254 - (i % 255)) as u8; - } - - loop { - master_send[0] = i; - master_send[master_send.len() - 1] = i; - slave_send[0] = i; - slave_send[slave_send.len() - 1] = i; - slave_receive.fill(0xff); - i = i.wrapping_add(1); - - let transfer = spi.dma_transfer(slave_send, slave_receive).unwrap(); - // Bit-bang out the contents of master_send and read into master_receive - // as quickly as manageable. MSB first. Mode 0, so sampled on the rising - // edge and set on the falling edge. - master_cs.set_low().unwrap(); - for (j, v) in master_send.iter().enumerate() { - let mut b = *v; - let mut rb = 0u8; - for _ in 0..8 { - if b & 128 != 0 { - master_mosi.set_high().unwrap(); - } else { - master_mosi.set_low().unwrap(); - } - master_sclk.set_low().unwrap(); - b <<= 1; - rb <<= 1; - // NB: adding about 24 NOPs here makes the clock's duty cycle - // run at about 50% ... but we don't strictly need the delay, - // either. - master_sclk.set_high().unwrap(); - if master_miso.is_high().unwrap() { - rb |= 1; - } - } - master_receive[j] = rb; - } - master_cs.set_high().unwrap(); - master_sclk.set_low().unwrap(); - // the buffers and spi is moved into the transfer and we can get it back via - // `wait` - (slave_receive, slave_send, spi) = transfer.wait().unwrap(); - println!( - "slave got {:x?} .. {:x?}, master got {:x?} .. {:x?}", - &slave_receive[..10], - &slave_receive[slave_receive.len() - 10..], - &master_receive[..10], - &master_receive[master_receive.len() - 10..] - ); - - delay.delay_ms(250u32); - - slave_receive.fill(0xff); - let transfer = spi.dma_read(slave_receive).unwrap(); - master_cs.set_high().unwrap(); - - master_cs.set_low().unwrap(); - for v in master_send.iter() { - let mut b = *v; - for _ in 0..8 { - if b & 128 != 0 { - master_mosi.set_high().unwrap(); - } else { - master_mosi.set_low().unwrap(); - } - b <<= 1; - master_sclk.set_low().unwrap(); - master_sclk.set_high().unwrap(); - } - } - master_cs.set_high().unwrap(); - (slave_receive, spi) = transfer.wait().unwrap(); - println!( - "slave got {:x?} .. {:x?}", - &slave_receive[..10], - &slave_receive[slave_receive.len() - 10..], - ); - - delay.delay_ms(250u32); - let transfer = spi.dma_write(slave_send).unwrap(); - - master_receive.fill(0); - - master_cs.set_low().unwrap(); - for (j, _) in master_send.iter().enumerate() { - let mut rb = 0u8; - for _ in 0..8 { - master_sclk.set_low().unwrap(); - rb <<= 1; - master_sclk.set_high().unwrap(); - if master_miso.is_high().unwrap() { - rb |= 1; - } - } - master_receive[j] = rb; - } - master_cs.set_high().unwrap(); - (slave_send, spi) = transfer.wait().unwrap(); - - println!( - "master got {:x?} .. {:x?}", - &master_receive[..10], - &master_receive[master_receive.len() - 10..], - ); - println!(); - } -} diff --git a/esp32s3-hal/examples/timer_interrupt.rs b/esp32s3-hal/examples/timer_interrupt.rs deleted file mode 100644 index 08eb304dd..000000000 --- a/esp32s3-hal/examples/timer_interrupt.rs +++ /dev/null @@ -1,118 +0,0 @@ -//! This shows how to use the TIMG peripheral interrupts. -//! There is TIMG0 and TIMG1 each of them containing two general purpose timers -//! and a watchdog timer. - -#![no_std] -#![no_main] - -use core::cell::RefCell; - -use critical_section::Mutex; -use esp32s3_hal::{ - clock::ClockControl, - interrupt, - interrupt::Priority, - peripherals::{self, Peripherals, TIMG0, TIMG1}, - prelude::*, - timer::{Timer, Timer0, Timer1, TimerGroup}, -}; -use esp_backtrace as _; -use esp_println::println; - -static TIMER00: Mutex>>>> = Mutex::new(RefCell::new(None)); -static TIMER01: Mutex>>>> = Mutex::new(RefCell::new(None)); -static TIMER10: Mutex>>>> = Mutex::new(RefCell::new(None)); -static TIMER11: Mutex>>>> = Mutex::new(RefCell::new(None)); - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer00 = timer_group0.timer0; - let mut timer01 = timer_group0.timer1; - - let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks); - let mut timer10 = timer_group1.timer0; - let mut timer11 = timer_group1.timer1; - - interrupt::enable(peripherals::Interrupt::TG0_T0_LEVEL, Priority::Priority2).unwrap(); - interrupt::enable(peripherals::Interrupt::TG0_T1_LEVEL, Priority::Priority2).unwrap(); - interrupt::enable(peripherals::Interrupt::TG1_T0_LEVEL, Priority::Priority3).unwrap(); - interrupt::enable(peripherals::Interrupt::TG1_T1_LEVEL, Priority::Priority3).unwrap(); - timer00.start(500u64.millis()); - timer00.listen(); - timer01.start(2500u64.millis()); - timer01.listen(); - timer10.start(1u64.secs()); - timer10.listen(); - timer11.start(3u64.secs()); - timer11.listen(); - - critical_section::with(|cs| { - TIMER00.borrow_ref_mut(cs).replace(timer00); - TIMER01.borrow_ref_mut(cs).replace(timer01); - TIMER10.borrow_ref_mut(cs).replace(timer10); - TIMER11.borrow_ref_mut(cs).replace(timer11); - }); - - loop {} -} - -#[interrupt] -fn TG0_T0_LEVEL() { - critical_section::with(|cs| { - let mut timer = TIMER00.borrow_ref_mut(cs); - let timer = timer.as_mut().unwrap(); - - if timer.is_interrupt_set() { - timer.clear_interrupt(); - timer.start(500u64.millis()); - println!("Interrupt Level 2 - Timer0"); - } - }); -} - -#[interrupt] -fn TG0_T1_LEVEL() { - critical_section::with(|cs| { - let mut timer = TIMER01.borrow_ref_mut(cs); - let timer = timer.as_mut().unwrap(); - - if timer.is_interrupt_set() { - timer.clear_interrupt(); - timer.start(500u64.millis()); - println!("Interrupt Level 2 - Timer1"); - } - }); -} - -#[interrupt] -fn TG1_T0_LEVEL() { - critical_section::with(|cs| { - let mut timer = TIMER10.borrow_ref_mut(cs); - let timer = timer.as_mut().unwrap(); - - if timer.is_interrupt_set() { - timer.clear_interrupt(); - timer.start(500u64.millis()); - println!("Interrupt Level 3 - Timer0"); - } - }); -} - -#[interrupt] -fn TG1_T1_LEVEL() { - critical_section::with(|cs| { - let mut timer = TIMER11.borrow_ref_mut(cs); - let timer = timer.as_mut().unwrap(); - - if timer.is_interrupt_set() { - timer.clear_interrupt(); - timer.start(500u64.millis()); - println!("Interrupt Level 3 - Timer1"); - } - }); -} diff --git a/esp32s3-hal/examples/ulp_riscv_core_basic.rs b/esp32s3-hal/examples/ulp_riscv_core_basic.rs deleted file mode 100644 index 3da9c57b1..000000000 --- a/esp32s3-hal/examples/ulp_riscv_core_basic.rs +++ /dev/null @@ -1,47 +0,0 @@ -//! This shows a very basic example of running code on the ULP RISCV core. -//! -//! Code on ULP core just increments a counter and blinks GPIO 1. The current -//! value is printed by the HP core. - -#![no_std] -#![no_main] - -use esp32s3_hal::{ - clock::ClockControl, - gpio::rtc_io::*, - peripherals::Peripherals, - prelude::*, - ulp_core, - IO, -}; -use esp_backtrace as _; -use esp_println::{print, println}; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let pin = io.pins.gpio1.into_low_power().into_push_pull_output(); - - let mut ulp_core = ulp_core::UlpCore::new(peripherals.ULP_RISCV_CORE); - ulp_core.stop(); - println!("ulp core stopped"); - - // load code to LP core - let lp_core_code = - load_lp_code!("../esp-lp-hal/target/riscv32imc-unknown-none-elf/release/examples/blinky"); - - // start LP core - lp_core_code.run(&mut ulp_core, ulp_core::UlpCoreWakeupSource::HpCpu, pin); - println!("ulpcore run"); - - let data = (0x5000_0400) as *mut u32; - loop { - print!("Current {:x} \u{000d}", unsafe { - data.read_volatile() - }); - } -} diff --git a/esp32s3-hal/examples/usb_serial.rs b/esp32s3-hal/examples/usb_serial.rs deleted file mode 100644 index 11668d621..000000000 --- a/esp32s3-hal/examples/usb_serial.rs +++ /dev/null @@ -1,67 +0,0 @@ -//! CDC-ACM serial port example using polling in a busy loop. -//! -//! This example should be built in release mode. - -#![no_std] -#![no_main] - -use esp32s3_hal::{ - clock::{ClockControl, CpuClock}, - otg_fs::{UsbBus, USB}, - peripherals::Peripherals, - prelude::*, - IO, -}; -use esp_backtrace as _; -use usb_device::prelude::{UsbDeviceBuilder, UsbVidPid}; - -static mut EP_MEMORY: [u32; 1024] = [0; 1024]; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::configure(system.clock_control, CpuClock::Clock240MHz).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - - let usb = USB::new(peripherals.USB0, io.pins.gpio19, io.pins.gpio20); - - let usb_bus = UsbBus::new(usb, unsafe { &mut EP_MEMORY }); - - let mut serial = usbd_serial::SerialPort::new(&usb_bus); - - let mut usb_dev = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd)) - .device_class(usbd_serial::USB_CLASS_CDC) - .build(); - - loop { - if !usb_dev.poll(&mut [&mut serial]) { - continue; - } - - let mut buf = [0u8; 64]; - - match serial.read(&mut buf) { - Ok(count) if count > 0 => { - // Echo back in upper case - for c in buf[0..count].iter_mut() { - if 0x61 <= *c && *c <= 0x7a { - *c &= !0x20; - } - } - - let mut write_offset = 0; - while write_offset < count { - match serial.write(&buf[write_offset..count]) { - Ok(len) if len > 0 => { - write_offset += len; - } - _ => {} - } - } - } - _ => {} - } - } -} diff --git a/esp32s3-hal/examples/watchdog.rs b/esp32s3-hal/examples/watchdog.rs deleted file mode 100644 index 7412f5e5b..000000000 --- a/esp32s3-hal/examples/watchdog.rs +++ /dev/null @@ -1,31 +0,0 @@ -//! This demos the watchdog timer. -//! Basically the same as `hello_world` but if you remove the call to -//! `wdt.feed()` the watchdog will reset the system. - -#![no_std] -#![no_main] - -use esp32s3_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, timer::TimerGroup}; -use esp_backtrace as _; -use esp_println::println; -use nb::block; - -#[entry] -fn main() -> ! { - let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - let mut wdt = timer_group0.wdt; - - wdt.start(2u64.secs()); - timer0.start(1u64.secs()); - - loop { - wdt.feed(); - println!("Hello world!"); - block!(timer0.wait()).unwrap(); - } -} diff --git a/esp32s3-hal/rust-toolchain.toml b/esp32s3-hal/rust-toolchain.toml deleted file mode 100644 index de5cd8048..000000000 --- a/esp32s3-hal/rust-toolchain.toml +++ /dev/null @@ -1,4 +0,0 @@ -[toolchain] -channel = "esp" -components = ["rustfmt", "rustc-dev"] -targets = ["xtensa-esp32s3-none-elf"] diff --git a/esp32s3-hal/src/lib.rs b/esp32s3-hal/src/lib.rs deleted file mode 100644 index 5f55a435f..000000000 --- a/esp32s3-hal/src/lib.rs +++ /dev/null @@ -1,9 +0,0 @@ -//! A bare-metal (`no_std`) Hardware Abstraction Layer for the ESP32-S3 from -//! Espressif. -//! -//! ## Feature Flags -#![doc = document_features::document_features!()] -#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/46717278")] -#![no_std] - -pub use esp_hal::*; diff --git a/examples/.cargo/config.toml b/examples/.cargo/config.toml new file mode 100644 index 000000000..f71714003 --- /dev/null +++ b/examples/.cargo/config.toml @@ -0,0 +1,31 @@ +[alias] +esp32 = "run --release --features=esp32 --target=xtensa-esp32-none-elf" +esp32c2 = "run --release --features=esp32c2 --target=riscv32imc-unknown-none-elf" +esp32c3 = "run --release --features=esp32c3 --target=riscv32imc-unknown-none-elf" +esp32c6 = "run --release --features=esp32c6 --target=riscv32imac-unknown-none-elf" +esp32h2 = "run --release --features=esp32h2 --target=riscv32imac-unknown-none-elf" +esp32p4 = "run --release --features=esp32p4 --target=riscv32imafc-unknown-none-elf" +esp32s2 = "run --release --features=esp32s2 --target=xtensa-esp32s2-none-elf" +esp32s3 = "run --release --features=esp32s3 --target=xtensa-esp32s3-none-elf" + +[target.'cfg(target_arch = "riscv32")'] +runner = "espflash flash --monitor" +rustflags = [ + "-C", "link-arg=-Tlinkall.x", + "-C", "force-frame-pointers", +] + +[target.'cfg(target_arch = "xtensa")'] +runner = "espflash flash --monitor" +rustflags = [ + # GNU LD + "-C", "link-arg=-Wl,-Tlinkall.x", + "-C", "link-arg=-nostartfiles", + + # LLD + # "-C", "link-arg=-Tlinkall.x", + # "-C", "linker=rust-lld", +] + +[unstable] +build-std = ["alloc", "core"] diff --git a/examples/Cargo.toml b/examples/Cargo.toml new file mode 100644 index 000000000..3b5f33592 --- /dev/null +++ b/examples/Cargo.toml @@ -0,0 +1,72 @@ +[package] +name = "examples" +version = "0.0.0" +edition = "2021" +license = "MIT OR Apache-2.0" +publish = false + +[dependencies] +aes = "0.8.3" +cfg-if = "1.0.0" +critical-section = "1.1.2" +crypto-bigint = { version = "0.5.5", default-features = false } +elliptic-curve = { version = "0.13.8", default-features = false, features = ["sec1"] } +embassy-executor = { version = "0.5.0", features = ["nightly"] } +embassy-sync = "0.5.0" +embassy-time = "0.3.0" +embassy-time-driver = { version = "0.1.0", optional = true } +embedded-graphics = "0.8.1" +embedded-hal = "1.0.0" +embedded-hal-02 = { version = "0.2.7", package = "embedded-hal" } +embedded-hal-async = "1.0.0" +embedded-hal-bus = "0.1.0" +embedded-io-async = "0.6.1" +esp-alloc = "0.3.0" +esp-backtrace = { version = "0.11.0", features = ["exception-handler", "panic-handler", "println"] } +esp-hal = { version = "0.15.0", path = "../esp-hal" } +esp-hal-smartled = { version = "0.8.0", path = "../esp-hal-smartled", optional = true } +esp-println = "0.9.0" +heapless = "0.8.0" +hex-literal = "0.4.1" +hmac = { version = "0.12.1", default-features = false } +lis3dh-async = "0.9.1" +nb = "1.1.0" +p192 = { version = "0.13.0", default-features = false, features = ["arithmetic"] } +p256 = { version = "0.13.2", default-features = false, features = ["arithmetic"] } +sha2 = { version = "0.10.8", default-features = false} +smart-leds = "0.4.0" +ssd1306 = "0.8.4" +static_cell = { version = "2.0.0", features = ["nightly"] } +usb-device = "0.3.1" +usbd-serial = "0.2.0" + +[features] +esp32 = ["esp-hal/esp32", "esp-backtrace/esp32", "esp-println/esp32", "esp-hal-smartled/esp32"] +esp32c2 = ["esp-hal/esp32c2", "esp-backtrace/esp32c2", "esp-println/esp32c2"] +esp32c3 = ["esp-hal/esp32c3", "esp-backtrace/esp32c3", "esp-println/esp32c3", "esp-hal-smartled/esp32c3"] +esp32c6 = ["esp-hal/esp32c6", "esp-backtrace/esp32c6", "esp-println/esp32c6", "esp-hal-smartled/esp32c6"] +esp32h2 = ["esp-hal/esp32h2", "esp-backtrace/esp32h2", "esp-println/esp32h2", "esp-hal-smartled/esp32h2"] +esp32p4 = ["esp-hal/esp32p4", "esp-backtrace/esp32p4", "esp-println/esp32p4"] +esp32s2 = ["esp-hal/esp32s2", "esp-backtrace/esp32s2", "esp-println/esp32s2", "esp-hal-smartled/esp32s2"] +esp32s3 = ["esp-hal/esp32s3", "esp-backtrace/esp32s3", "esp-println/esp32s3", "esp-hal-smartled/esp32s3"] + +async = ["esp-hal/async"] + +eh1 = ["esp-hal/eh1"] + +embassy = ["esp-hal/embassy"] + +embassy-executor-thread = ["esp-hal/embassy-executor-thread"] +embassy-executor-interrupt = ["esp-hal/embassy-executor-interrupt"] + +embassy-time-timg0 = ["esp-hal/embassy-time-timg0", "embassy-time-driver/tick-hz-1_000_000"] +embassy-generic-timers = ["embassy-time/generic-queue-8"] + +direct-vectoring = ["esp-hal/direct-vectoring"] +interrupt-preemption = ["esp-hal/interrupt-preemption"] + +opsram-2m = ["esp-hal/opsram-2m"] +psram-2m = ["esp-hal/psram-2m"] + +[profile.release] +debug = true diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 000000000..df635b4e6 --- /dev/null +++ b/examples/README.md @@ -0,0 +1 @@ +# Examples diff --git a/examples/rustfmt.toml b/examples/rustfmt.toml new file mode 100644 index 000000000..5389fac19 --- /dev/null +++ b/examples/rustfmt.toml @@ -0,0 +1,4 @@ +# Imports +group_imports = "StdExternalCrate" +imports_granularity = "Crate" +imports_layout = "HorizontalVertical" diff --git a/examples/src/bin/adc.rs b/examples/src/bin/adc.rs new file mode 100644 index 000000000..c4087baa7 --- /dev/null +++ b/examples/src/bin/adc.rs @@ -0,0 +1,52 @@ +//! Connect a potentiometer to an IO pin and see the read values change when +//! rotating the shaft. +//! +//! Alternatively, you could also connect the IO pin to GND or 3V3 to see the +//! maximum and minimum raw values read. + +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + +#![no_std] +#![no_main] + +use esp_backtrace as _; +use esp_hal::{ + adc::{AdcConfig, Attenuation, ADC}, + clock::ClockControl, + gpio::IO, + peripherals::{Peripherals, ADC1}, + prelude::*, + Delay, +}; +use esp_println::println; + +#[entry] +fn main() -> ! { + let peripherals = Peripherals::take(); + let system = peripherals.SYSTEM.split(); + let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + + let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); + cfg_if::cfg_if! { + if #[cfg(feature = "esp32")] { + let analog_pin = io.pins.gpio32.into_analog(); + } else if #[cfg(any(feature = "esp32s2", feature = "esp32s3"))] { + let analog_pin = io.pins.gpio3.into_analog(); + } else { + let analog_pin = io.pins.gpio2.into_analog(); + } + } + + // Create ADC instances + let mut adc1_config = AdcConfig::new(); + let mut adc1_pin = adc1_config.enable_pin(analog_pin, Attenuation::Attenuation11dB); + let mut adc1 = ADC::::new(peripherals.ADC1, adc1_config); + + let mut delay = Delay::new(&clocks); + + loop { + let pin_value: u16 = nb::block!(adc1.read(&mut adc1_pin)).unwrap(); + println!("ADC reading = {}", pin_value); + delay.delay_ms(1500u32); + } +} diff --git a/esp32c2-hal/examples/adc_cal.rs b/examples/src/bin/adc_cal.rs similarity index 64% rename from esp32c2-hal/examples/adc_cal.rs rename to examples/src/bin/adc_cal.rs index 64230a6b8..68e51f80d 100644 --- a/esp32c2-hal/examples/adc_cal.rs +++ b/examples/src/bin/adc_cal.rs @@ -2,11 +2,13 @@ //! rotating the shaft. Alternatively you could also connect the PIN to GND or //! 3V3 to see the maximum and minimum raw values read. +//% CHIPS: esp32c2 esp32c3 esp32c6 esp32s3 + #![no_std] #![no_main] -use esp32c2_hal::{ - adc, +use esp_backtrace as _; +use esp_hal::{ adc::{AdcConfig, Attenuation, ADC}, clock::ClockControl, gpio::IO, @@ -14,7 +16,6 @@ use esp32c2_hal::{ prelude::*, Delay, }; -use esp_backtrace as _; use esp_println::println; #[entry] @@ -24,27 +25,33 @@ fn main() -> ! { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); + cfg_if::cfg_if! { + if #[cfg(feature = "esp32s3")] { + let analog_pin = io.pins.gpio3.into_analog(); + } else { + let analog_pin = io.pins.gpio2.into_analog(); + } + } // Create ADC instances // You can try any of the following calibration methods by uncommenting // them. Note that only AdcCalLine returns readings in mV; the other two // return raw readings in some unspecified scale. // - // type AdcCal = (); - // type AdcCal = adc::AdcCalBasic; - type AdcCal = adc::AdcCalLine; + type AdcCal = (); + // type AdcCal = esp_hal::adc::AdcCalBasic; + // type AdcCal = esp_hal::adc::AdcCalLine; + // type AdcCal = esp_hal::adc::AdcCalCurve; let mut adc1_config = AdcConfig::new(); - let mut pin = adc1_config.enable_pin_with_cal::<_, AdcCal>( - io.pins.gpio2.into_analog(), - Attenuation::Attenuation11dB, - ); + let mut adc1_pin = + adc1_config.enable_pin_with_cal::<_, AdcCal>(analog_pin, Attenuation::Attenuation11dB); let mut adc1 = ADC::::new(peripherals.ADC1, adc1_config); let mut delay = Delay::new(&clocks); loop { - let pin_mv = nb::block!(adc1.read(&mut pin)).unwrap(); + let pin_mv = nb::block!(adc1.read(&mut adc1_pin)).unwrap(); println!("PIN2 ADC reading = {pin_mv} mV"); delay.delay_ms(1500u32); } diff --git a/esp32s2-hal/examples/advanced_serial.rs b/examples/src/bin/advanced_serial.rs similarity index 89% rename from esp32s2-hal/examples/advanced_serial.rs rename to examples/src/bin/advanced_serial.rs index 8803ad99a..8c8954beb 100644 --- a/esp32s2-hal/examples/advanced_serial.rs +++ b/examples/src/bin/advanced_serial.rs @@ -7,10 +7,13 @@ //! - TX => GPIO1 //! - RX => GPIO2 +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] -use esp32s2_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, gpio::IO, peripherals::Peripherals, @@ -22,7 +25,6 @@ use esp32s2_hal::{ Delay, Uart, }; -use esp_backtrace as _; use esp_println::println; use nb::block; @@ -41,8 +43,8 @@ fn main() -> ! { let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); let pins = TxRxPins::new_tx_rx( - io.pins.gpio1.into_push_pull_output(), - io.pins.gpio2.into_floating_input(), + io.pins.gpio4.into_push_pull_output(), + io.pins.gpio5.into_floating_input(), ); let mut serial1 = Uart::new_with_config(peripherals.UART1, config, Some(pins), &clocks); diff --git a/esp32c3-hal/examples/aes.rs b/examples/src/bin/aes.rs similarity index 77% rename from esp32c3-hal/examples/aes.rs rename to examples/src/bin/aes.rs index 928923c03..ae513f5b3 100644 --- a/esp32c3-hal/examples/aes.rs +++ b/examples/src/bin/aes.rs @@ -1,26 +1,26 @@ //! Encrypt/Decrypt a message using AES +//% CHIPS: esp32 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] + use aes::{ cipher::{generic_array::GenericArray, BlockDecrypt, BlockEncrypt, KeyInit}, Aes128 as Aes128SW, }; -use esp32c3_hal::{ +use esp_backtrace as _; +use esp_hal::{ aes::{Aes, Mode}, - clock::ClockControl, peripherals::Peripherals, prelude::*, - systimer::SystemTimer, }; -use esp_backtrace as _; use esp_println::println; +use examples::cycles; #[entry] fn main() -> ! { let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let mut aes = Aes::new(peripherals.AES); @@ -36,17 +36,17 @@ fn main() -> ! { block_buf[..plaintext.len()].copy_from_slice(plaintext); let mut block = block_buf.clone(); - let pre_hw_encrypt = SystemTimer::now(); + let pre_hw_encrypt = cycles(); aes.process(&mut block, Mode::Encryption128, &keybuf); - let post_hw_encrypt = SystemTimer::now(); + let post_hw_encrypt = cycles(); println!( "it took {} cycles for hw encrypt", post_hw_encrypt - pre_hw_encrypt ); let hw_encrypted = block.clone(); - let pre_hw_decrypt = SystemTimer::now(); + let pre_hw_decrypt = cycles(); aes.process(&mut block, Mode::Decryption128, &keybuf); - let post_hw_decrypt = SystemTimer::now(); + let post_hw_decrypt = cycles(); println!( "it took {} cycles for hw decrypt", post_hw_decrypt - pre_hw_decrypt @@ -56,17 +56,17 @@ fn main() -> ! { let key = GenericArray::from(keybuf); let mut block = GenericArray::from(block_buf); let cipher = Aes128SW::new(&key); - let pre_sw_encrypt = SystemTimer::now(); + let pre_sw_encrypt = cycles(); cipher.encrypt_block(&mut block); - let post_sw_encrypt = SystemTimer::now(); + let post_sw_encrypt = cycles(); println!( "it took {} cycles for sw encrypt", post_sw_encrypt - pre_sw_encrypt ); let sw_encrypted = block.clone(); - let pre_sw_decrypt = SystemTimer::now(); + let pre_sw_decrypt = cycles(); cipher.decrypt_block(&mut block); - let post_sw_decrypt = SystemTimer::now(); + let post_sw_decrypt = cycles(); println!( "it took {} cycles for sw decrypt", post_sw_decrypt - pre_sw_decrypt @@ -80,6 +80,7 @@ fn main() -> ! { loop {} } + fn eq(slice1: &[u8; 16], slice2: &[u8; 16]) -> bool { slice1.iter().zip(slice2.iter()).all(|(a, b)| a == b) } diff --git a/esp32c3-hal/examples/aes_dma.rs b/examples/src/bin/aes_dma.rs similarity index 87% rename from esp32c3-hal/examples/aes_dma.rs rename to examples/src/bin/aes_dma.rs index 8da505ead..b901c2c46 100644 --- a/esp32c3-hal/examples/aes_dma.rs +++ b/examples/src/bin/aes_dma.rs @@ -1,5 +1,7 @@ //! Encrypt/Decrypt a message using AES +//% CHIPS: esp32c3 esp32c6 esp32h2 esp32s3 + #![no_std] #![no_main] @@ -7,26 +9,23 @@ use aes::{ cipher::{generic_array::GenericArray, BlockDecrypt, BlockEncrypt, KeyInit}, Aes128 as Aes128SW, }; -use esp32c3_hal::{ +use esp_backtrace as _; +use esp_hal::{ aes::{ dma::{CipherMode, WithDmaAes}, Aes, Mode, }, - clock::ClockControl, dma::{Dma, DmaDescriptor, DmaPriority}, peripherals::Peripherals, prelude::*, - systimer::SystemTimer, }; -use esp_backtrace as _; use esp_println::println; +use examples::cycles; #[entry] fn main() -> ! { let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let dma = Dma::new(peripherals.DMA); let dma_channel = dma.channel0; @@ -55,7 +54,7 @@ fn main() -> ! { block_buf[..plaintext.len()].copy_from_slice(plaintext); let hw_encrypted = buffer3(); - let pre_hw_encrypt = SystemTimer::now(); + let pre_hw_encrypt = cycles(); let transfer = aes .process( plaintext, @@ -66,7 +65,7 @@ fn main() -> ! { ) .unwrap(); let (hw_encrypted, plaintext, aes) = transfer.wait().unwrap(); - let post_hw_encrypt = SystemTimer::now(); + let post_hw_encrypt = cycles(); println!( "it took {} cycles for hw encrypt", post_hw_encrypt - pre_hw_encrypt @@ -80,7 +79,7 @@ fn main() -> ! { keybuf[..keytext.len()].copy_from_slice(keytext); let hw_decrypted = buffer5(); - let pre_hw_decrypt = SystemTimer::now(); + let pre_hw_decrypt = cycles(); let transfer = aes .process( plaintext, @@ -91,7 +90,7 @@ fn main() -> ! { ) .unwrap(); let (hw_decrypted, _, _) = transfer.wait().unwrap(); - let post_hw_decrypt = SystemTimer::now(); + let post_hw_decrypt = cycles(); println!( "it took {} cycles for hw decrypt", post_hw_decrypt - pre_hw_decrypt @@ -100,17 +99,17 @@ fn main() -> ! { let key = GenericArray::from(keybuf); let mut block = GenericArray::from(block_buf); let cipher = Aes128SW::new(&key); - let pre_sw_encrypt = SystemTimer::now(); + let pre_sw_encrypt = cycles(); cipher.encrypt_block(&mut block); - let post_sw_encrypt = SystemTimer::now(); + let post_sw_encrypt = cycles(); println!( "it took {} cycles for sw encrypt", post_sw_encrypt - pre_sw_encrypt ); let sw_encrypted = block.clone(); - let pre_sw_decrypt = SystemTimer::now(); + let pre_sw_decrypt = cycles(); cipher.decrypt_block(&mut block); - let post_sw_decrypt = SystemTimer::now(); + let post_sw_decrypt = cycles(); println!( "it took {} cycles for sw decrypt", post_sw_decrypt - pre_sw_decrypt diff --git a/esp32c6-hal/examples/blinky.rs b/examples/src/bin/blinky.rs similarity index 68% rename from esp32c6-hal/examples/blinky.rs rename to examples/src/bin/blinky.rs index e6b73ddf8..b4e8ef3bb 100644 --- a/esp32c6-hal/examples/blinky.rs +++ b/examples/src/bin/blinky.rs @@ -1,12 +1,14 @@ //! Blinks an LED //! -//! This assumes that a LED is connected to the pin assigned to `led`. (GPIO5) +//! This assumes that a LED is connected to the pin assigned to `led`. (GPIO0) + +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 #![no_std] #![no_main] -use esp32c6_hal::{clock::ClockControl, gpio::IO, peripherals::Peripherals, prelude::*, Delay}; use esp_backtrace as _; +use esp_hal::{clock::ClockControl, gpio::IO, peripherals::Peripherals, prelude::*, Delay}; #[entry] fn main() -> ! { @@ -14,9 +16,9 @@ fn main() -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - // Set GPIO5 as an output, and set its state high initially. + // Set GPIO0 as an output, and set its state high initially. let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut led = io.pins.gpio5.into_push_pull_output(); + let mut led = io.pins.gpio0.into_push_pull_output(); led.set_high().unwrap(); diff --git a/esp32s2-hal/examples/blinky_erased_pins.rs b/examples/src/bin/blinky_erased_pins.rs similarity index 55% rename from esp32s2-hal/examples/blinky_erased_pins.rs rename to examples/src/bin/blinky_erased_pins.rs index 90bae4353..b1bab1f88 100644 --- a/esp32s2-hal/examples/blinky_erased_pins.rs +++ b/examples/src/bin/blinky_erased_pins.rs @@ -1,18 +1,23 @@ -//! Blinks an LED +//! Blinks 3 LEDs //! -//! This assumes that LEDs are connected to GPIO3, 4 and 5. +//! This assumes that LEDs are connected to GPIO8, 9 and 10. +//! +//! GPIO1 is treated as an input, and will print a message when pressed. This +//! Additionally demonstrates passing GPIO to a function in a generic way. + +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 #![no_std] #![no_main] -use esp32s2_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, gpio::{AnyPin, Input, Output, PullDown, PushPull, IO}, peripherals::Peripherals, prelude::*, Delay, }; -use esp_backtrace as _; #[entry] fn main() -> ! { @@ -20,20 +25,21 @@ fn main() -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - // Set LED GPIOs as an output. let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let led1 = io.pins.gpio3.into_push_pull_output(); - let led2 = io.pins.gpio4.into_push_pull_output(); - let led3 = io.pins.gpio5.into_push_pull_output(); - // Set GPIO9 as an input. + // Set LED GPIOs as an output: + let led1 = io.pins.gpio8.into_push_pull_output(); + let led2 = io.pins.gpio9.into_push_pull_output(); + let led3 = io.pins.gpio10.into_push_pull_output(); + + // Set GPIO0 as an input: let button = io.pins.gpio0.into_pull_down_input().into(); - // You can use `into` or `degrade` + // You can use `into` or `degrade`: let mut pins = [led1.into(), led2.into(), led3.degrade().into()]; - // Initialize the Delay peripheral, and use it to toggle the LED state in a - // loop. + // Initialize the `Delay` peripheral, and use it to toggle the LED state + // in a loop: let mut delay = Delay::new(&clocks); loop { @@ -48,6 +54,6 @@ fn toggle_pins(leds: &mut [AnyPin>], button: &AnyPin>> = Mutex::new(RefCell::new(None)); @@ -36,19 +38,17 @@ fn main() -> ! { clocks.xtal_clock.to_MHz() ); - interrupt::enable( - peripherals::Interrupt::RTC_CORE, - interrupt::Priority::Priority1, - ) - .unwrap(); + #[cfg(any(feature = "esp32c6", feature = "esp32h2"))] + interrupt::enable(Interrupt::LP_WDT, Priority::Priority1).unwrap(); + #[cfg(not(any(feature = "esp32c6", feature = "esp32h2")))] + interrupt::enable(Interrupt::RTC_CORE, Priority::Priority1).unwrap(); critical_section::with(|cs| RTC.borrow_ref_mut(cs).replace(rtc)); loop {} } -#[interrupt] -fn RTC_CORE() { +fn interrupt_handler() { critical_section::with(|cs| { let mut rtc = RTC.borrow_ref_mut(cs); let rtc = rtc.as_mut().unwrap(); @@ -62,3 +62,15 @@ fn RTC_CORE() { rtc.rwdt.clear_interrupt(); }); } + +#[cfg(any(feature = "esp32c6", feature = "esp32h2"))] +#[interrupt] +fn LP_WDT() { + interrupt_handler(); +} + +#[cfg(not(any(feature = "esp32c6", feature = "esp32h2")))] +#[interrupt] +fn RTC_CORE() { + interrupt_handler(); +} diff --git a/esp32s3-hal/examples/crc.rs b/examples/src/bin/crc.rs similarity index 93% rename from esp32s3-hal/examples/crc.rs rename to examples/src/bin/crc.rs index ac05da313..bff35cae2 100644 --- a/esp32s3-hal/examples/crc.rs +++ b/examples/src/bin/crc.rs @@ -1,11 +1,14 @@ //! This shows example usage of the CRC functions in ROM +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] use core::fmt::Write; -use esp32s3_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, peripherals::Peripherals, prelude::*, @@ -13,7 +16,6 @@ use esp32s3_hal::{ timer::TimerGroup, Uart, }; -use esp_backtrace as _; use nb::block; #[entry] @@ -22,13 +24,12 @@ fn main() -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let mut timer0 = timg0.timer0; + timer0.start(1u64.secs()); let mut uart0 = Uart::new(peripherals.UART0, &clocks); - timer0.start(1u64.secs()); - let data = "123456789"; let sentence = "The quick brown fox jumps over a lazy dog"; diff --git a/esp32s2-hal/examples/dac.rs b/examples/src/bin/dac.rs similarity index 57% rename from esp32s2-hal/examples/dac.rs rename to examples/src/bin/dac.rs index a179b01ee..d842cacb8 100644 --- a/esp32s2-hal/examples/dac.rs +++ b/examples/src/bin/dac.rs @@ -1,11 +1,18 @@ -//! This example shows how to use the DAC on PIN 17 and 18 +//! This example shows how to use the DAC +//! //! You can connect an LED (with a suitable resistor) or check the changing //! voltage using a voltmeter on those pins. +//! +//! When targeting the ESP32, the pins for `DAC1` and `DAC2` are GPIO25 and +//! GPIO26 respectively; for the ESP32-S2, they are GPIO17 and GPIO18. + +//% CHIPS: esp32 esp32s2 #![no_std] #![no_main] -use esp32s2_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, dac::{DAC1, DAC2}, gpio::IO, @@ -13,7 +20,6 @@ use esp32s2_hal::{ prelude::*, Delay, }; -use esp_backtrace as _; #[entry] fn main() -> ! { @@ -22,12 +28,20 @@ fn main() -> ! { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let pin17 = io.pins.gpio17.into_analog(); - let pin18 = io.pins.gpio18.into_analog(); + + cfg_if::cfg_if! { + if #[cfg(feature = "esp32")] { + let dac1_pin = io.pins.gpio25.into_analog(); + let dac2_pin = io.pins.gpio26.into_analog(); + } else if #[cfg(feature = "esp32s2")] { + let dac1_pin = io.pins.gpio17.into_analog(); + let dac2_pin = io.pins.gpio18.into_analog(); + } + } // Create DAC instances - let mut dac1 = DAC1::new(peripherals.DAC1, pin17); - let mut dac2 = DAC2::new(peripherals.DAC2, pin18); + let mut dac1 = DAC1::new(peripherals.DAC1, dac1_pin); + let mut dac2 = DAC2::new(peripherals.DAC2, dac2_pin); let mut delay = Delay::new(&clocks); diff --git a/esp32h2-hal/examples/debug_assist.rs b/examples/src/bin/debug_assist.rs similarity index 56% rename from esp32h2-hal/examples/debug_assist.rs rename to examples/src/bin/debug_assist.rs index ecbe690ff..38ddc9cd7 100644 --- a/esp32h2-hal/examples/debug_assist.rs +++ b/examples/src/bin/debug_assist.rs @@ -2,20 +2,22 @@ //! //! Uncomment the functionality you want to test +//% CHIPS: esp32c2 esp32c3 esp32c6 esp32h2 esp32s3 + #![no_std] #![no_main] use core::cell::RefCell; use critical_section::Mutex; -use esp32h2_hal::{ +use esp_backtrace as _; +use esp_hal::{ assist_debug::DebugAssist, clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, + interrupt::{self, Priority}, + peripherals::{Interrupt, Peripherals}, prelude::*, }; -use esp_backtrace as _; use esp_println::println; static DA: Mutex>> = Mutex::new(RefCell::new(None)); @@ -28,36 +30,45 @@ fn main() -> ! { let mut da = DebugAssist::new(peripherals.ASSIST_DEBUG); - extern "C" { - // top of stack - static mut _stack_start: u32; - // bottom of stack - static mut _stack_end: u32; + cfg_if::cfg_if! { + if #[cfg(not(feature = "esp32s3"))] { + extern "C" { + // top of stack + static mut _stack_start: u32; + // bottom of stack + static mut _stack_end: u32; + } + + let stack_top = unsafe { &mut _stack_start } as *mut _ as u32; + let stack_bottom = unsafe { &mut _stack_end } as *mut _ as u32; + + let size = 4096; + } else { + let stack_bottom = 0x3fcce000; + + let size = 256; + } } - let stack_top = unsafe { &mut _stack_start } as *mut _ as u32; - let stack_bottom = unsafe { &mut _stack_end } as *mut _ as u32; + // Monitor the SP so as to prevent stack overflow or erroneous push/pop. + // When the SP exceeds the minimum or maximum threshold, the module will + // record the PC pointer and generate an interrupt. + #[cfg(not(feature = "esp32s3"))] + da.enable_sp_monitor(stack_bottom + size, stack_top); - // uncomment the functionality you want to test - - // Monitor the SP so as to prevent stack overflow or erroneous push/pop. When - // the SP exceeds the minimum or maximum threshold, the module will record the - // PC pointer and generate an interrupt - da.enable_sp_monitor(stack_bottom + 4096, stack_top); - - // Monitor reads/writes performed by the CPU over data bus and peripheral bus - // in a certain address space, i.e., memory region. Whenever the bus reads or - // writes in the specified address space, an interrupt will be triggered - // da.enable_region0_monitor(stack_bottom, stack_bottom + 4096, true, true); - // da.enable_region1_monitor(stack_bottom, stack_bottom + 4096, true, true); + // Monitor reads/writes performed by the CPU over data bus and peripheral + // bus in a certain address space, i.e., memory region. Whenever the bus + // reads or writes in the specified address space, an interrupt will be + // triggered. + #[cfg(not(feature = "esp32c2"))] + { + da.enable_region0_monitor(stack_bottom, stack_bottom + size, true, true); + da.enable_region1_monitor(stack_bottom, stack_bottom + size, true, true); + } critical_section::with(|cs| DA.borrow_ref_mut(cs).replace(da)); - interrupt::enable( - peripherals::Interrupt::ASSIST_DEBUG, - interrupt::Priority::Priority3, - ) - .unwrap(); + interrupt::enable(Interrupt::ASSIST_DEBUG, Priority::Priority3).unwrap(); eat_up_stack(0); @@ -77,6 +88,7 @@ fn ASSIST_DEBUG() { let mut da = DA.borrow_ref_mut(cs); let da = da.as_mut().unwrap(); + #[cfg(not(feature = "esp32s3"))] if da.is_sp_monitor_interrupt_set() { println!("SP MONITOR TRIGGERED"); da.clear_sp_monitor_interrupt(); @@ -84,6 +96,7 @@ fn ASSIST_DEBUG() { println!("PC = 0x{:x}", pc); } + #[cfg(not(feature = "esp32c2"))] if da.is_region0_monitor_interrupt_set() { println!("REGION0 MONITOR TRIGGERED"); da.clear_region0_monitor_interrupt(); @@ -91,6 +104,7 @@ fn ASSIST_DEBUG() { println!("PC = 0x{:x}", pc); } + #[cfg(not(feature = "esp32c2"))] if da.is_region1_monitor_interrupt_set() { println!("REGION1 MONITOR TRIGGERED"); da.clear_region1_monitor_interrupt(); diff --git a/esp32h2-hal/examples/direct-vectoring.rs b/examples/src/bin/direct_vectoring.rs similarity index 54% rename from esp32h2-hal/examples/direct-vectoring.rs rename to examples/src/bin/direct_vectoring.rs index 89b390f10..ab09e5836 100644 --- a/esp32h2-hal/examples/direct-vectoring.rs +++ b/examples/src/bin/direct_vectoring.rs @@ -1,39 +1,46 @@ #![no_main] #![no_std] -#![feature(naked_functions)] + +//% CHIPS: esp32c2 esp32c3 esp32c6 esp32h2 +//% FEATURES: direct-vectoring + use core::{arch::asm, cell::RefCell}; use critical_section::Mutex; -use esp32h2_hal::{ - clock::ClockControl, - interrupt::{ - CpuInterrupt, - {self}, - }, - peripherals::{self, Peripherals}, +use esp_backtrace as _; +use esp_hal::{ + interrupt::{self, CpuInterrupt, Priority}, + peripherals::{Interrupt, Peripherals}, prelude::*, system::{SoftwareInterrupt, SoftwareInterruptControl}, }; -use esp_backtrace as _; static SWINT: Mutex>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { let peripherals = Peripherals::take(); + cfg_if::cfg_if! { + if #[cfg(any(feature = "esp32c6", feature = "esp32h2"))] { + let cpu_intr = &peripherals.INTPRI; + } else { + let cpu_intr = &peripherals.SYSTEM; + } + } + let sw0_trigger_addr = cpu_intr.cpu_intr_from_cpu_0() as *const _ as u32; + let system = peripherals.SYSTEM.split(); - let clockctrl = system.clock_control; let sw_int = system.software_interrupt_control; - let _clocks = ClockControl::boot_defaults(clockctrl).freeze(); critical_section::with(|cs| SWINT.borrow_ref_mut(cs).replace(sw_int)); unsafe { interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR0, - interrupt::Priority::Priority3, + Interrupt::FROM_CPU_INTR0, + Priority::Priority3, CpuInterrupt::Interrupt1, ) .unwrap(); + asm!( " csrrwi x0, 0x7e0, 1 #what to count, for cycles write 1 for instructions write 2 @@ -42,19 +49,22 @@ fn main() -> ! { " ); } - esp_println::println!("MPC:{}", unsafe { fetch_performance_timer() }); + // interrupt is raised from assembly for max timer granularity. unsafe { asm!( " - li t0, 0x600C5090 #FROM_CPU_INTR0 address - li t1, 1 #Flip flag - csrrwi x0, 0x7e1, 1 #enable timer - sw t1, 0(t0) #trigger FROM_CPU_INTR0 - " + li {bit}, 1 # Flip flag (bit 0) + csrrwi x0, 0x7e1, 1 # enable timer + sw {bit}, 0({addr}) # trigger FROM_CPU_INTR0 + ", + options(nostack), + addr = in(reg) sw0_trigger_addr, + bit = out(reg) _, ) } esp_println::println!("Returned"); + loop {} } @@ -68,17 +78,16 @@ fn cpu_int_1_handler() { .unwrap() .reset(SoftwareInterrupt::SoftwareInterrupt0); }); - esp_println::println!("Performance counter:{}", unsafe { - fetch_performance_timer() - }); -} -#[naked] -unsafe extern "C" fn fetch_performance_timer() -> i32 { - asm!( - " - csrr a0, 0x7e2 - jr ra - ", - options(noreturn) - ); + + let mut perf_counter: u32 = 0; + unsafe { + asm!( + " + csrr {x}, 0x7e2 + ", + options(nostack), + x = inout(reg) perf_counter, + ) + }; + esp_println::println!("Performance counter:{}", perf_counter); } diff --git a/esp32h2-hal/examples/ecc.rs b/examples/src/bin/ecc.rs similarity index 90% rename from esp32h2-hal/examples/ecc.rs rename to examples/src/bin/ecc.rs index 35c5a4b90..20d593da2 100644 --- a/esp32h2-hal/examples/ecc.rs +++ b/examples/src/bin/ecc.rs @@ -1,6 +1,8 @@ //! Demonstrates the use of the ECC peripheral and compares the speed of //! hardware-accelerated and pure software ECC. +//% CHIPS: esp32c2 esp32c6 esp32h2 + #![no_std] #![no_main] @@ -13,20 +15,22 @@ use crypto_bigint::{ U256, }; use elliptic_curve::sec1::ToEncodedPoint; -use esp32h2_hal::{ +use esp_backtrace as _; +use esp_hal::{ ecc::{Ecc, EllipticCurve, Error, WorkMode}, peripherals::Peripherals, prelude::*, systimer::SystemTimer, Rng, }; -use esp_backtrace as _; use esp_println::{print, println}; use hex_literal::hex; struct TestParams<'a> { prime_fields: &'a [&'a [u8]], nb_loop_mul: usize, + #[cfg(feature = "esp32c2")] + nb_loop_inv: usize, } const TEST_PARAMS_VECTOR: TestParams = TestParams { @@ -35,18 +39,16 @@ const TEST_PARAMS_VECTOR: TestParams = TestParams { &hex!("ffffffff00000001000000000000000000000000ffffffffffffffffffffffff"), ], nb_loop_mul: 10, + #[cfg(feature = "esp32c2")] + nb_loop_inv: 20, }; #[entry] fn main() -> ! { let peripherals = Peripherals::take(); - let _system = peripherals.SYSTEM.split(); - - let mut rng = Rng::new(peripherals.RNG); - - println!("ECC example"); let mut hw_ecc = Ecc::new(peripherals.ECC); + let mut rng = Rng::new(peripherals.RNG); println!("Beginning stress tests..."); test_affine_point_multiplication(&mut hw_ecc, &mut rng); @@ -55,10 +57,17 @@ fn main() -> ! { test_jacobian_point_multiplication(&mut hw_ecc, &mut rng); test_jacobian_point_verification(&mut hw_ecc, &mut rng); test_afine_point_verification_jacobian_multiplication(&mut hw_ecc, &mut rng); - test_mod_operations_256(&mut hw_ecc); - test_mod_operations_192(&mut hw_ecc); - test_point_addition_256(&mut hw_ecc); - test_point_addition_192(&mut hw_ecc); + #[cfg(feature = "esp32c2")] + { + test_finite_field_division(&mut hw_ecc, &mut rng); + } + #[cfg(feature = "esp32h2")] + { + test_mod_operations_256(&mut hw_ecc); + test_mod_operations_192(&mut hw_ecc); + test_point_addition_256(&mut hw_ecc); + test_point_addition_192(&mut hw_ecc); + } println!("Finished stress tests!"); loop {} @@ -259,8 +268,11 @@ fn test_afine_point_verification_multiplication(ecc: &mut Ecc, rng: &mut Rng) { let (px, py) = px.split_at_mut(prime_field.len()); let (py, _) = py.split_at_mut(prime_field.len()); let mut delta_time = 0; + #[cfg(feature = "esp32h2")] let qx = &mut [0u8; 8]; + #[cfg(feature = "esp32h2")] let qy = &mut [0u8; 8]; + #[cfg(feature = "esp32h2")] let qz = &mut [0u8; 8]; for _ in 0..TEST_PARAMS_VECTOR.nb_loop_mul { loop { @@ -306,7 +318,11 @@ fn test_afine_point_verification_multiplication(ecc: &mut Ecc, rng: &mut Rng) { }; let begin_time = SystemTimer::now(); - match ecc.affine_point_verification_multiplication(curve, k, px, py, qx, qy, qz) { + #[cfg(not(feature = "esp32h2"))] + let result = ecc.affine_point_verification_multiplication(curve, k, px, py); + #[cfg(feature = "esp32h2")] + let result = ecc.affine_point_verification_multiplication(curve, k, px, py, qx, qy, qz); + match result { Err(Error::SizeMismatchCurve) => assert!(false, "Inputs data doesn't match the key length selected."), Err(Error::PointNotOnSelectedCurve) => assert!( false, "ECC failed while affine point verification + multiplication with x = {:02X?} and y = {:02X?}.", @@ -730,7 +746,83 @@ fn test_afine_point_verification_jacobian_multiplication(ecc: &mut Ecc, rng: &mu } } -// all values are Little-Endian +#[cfg(feature = "esp32c2")] +fn test_finite_field_division(ecc: &mut Ecc, rng: &mut Rng) { + for &prime_field in TEST_PARAMS_VECTOR.prime_fields { + print!("Beginning finite field division tests over "); + match prime_field.len() { + 24 => print!("P-192..."), + 32 => print!("P-256..."), + _ => unimplemented!(), + }; + let t1 = &mut [0_u8; 64]; + let (k, y) = t1.split_at_mut(prime_field.len()); + let (y, _) = y.split_at_mut(prime_field.len()); + let mut delta_time = 0; + for _ in 0..TEST_PARAMS_VECTOR.nb_loop_inv { + loop { + rng.read(k).unwrap(); + rng.read(y).unwrap(); + let is_zero = k.iter().all(|&elt| elt == 0) || y.iter().all(|&elt| elt == 0); + let is_modulus = k.iter().zip(prime_field).all(|(&a, &b)| a == b) + || y.iter().zip(prime_field).all(|(&a, &b)| a == b); + if is_zero == false && is_modulus == false { + break; + } + } + let t2 = &mut [0_u8; 96]; + let (sw_y, sw_k) = t2.split_at_mut(prime_field.len()); + let (sw_k, sw_res) = sw_k.split_at_mut(prime_field.len()); + let (sw_res, _) = sw_res.split_at_mut(prime_field.len()); + sw_y.copy_from_slice(y); + sw_k.copy_from_slice(k); + let curve = match prime_field.len() { + 24 => &EllipticCurve::P192, + 32 => &EllipticCurve::P256, + _ => unimplemented!(), + }; + + let begin_time = SystemTimer::now(); + ecc.finite_field_division(curve, k, y) + .expect("Inputs data doesn't match the key length selected."); + let end_time = SystemTimer::now(); + delta_time += end_time - begin_time; + + match prime_field.len() { + 24 => { + let modulus = DynResidueParams::new(&U192::from_be_slice(prime_field)); + let sw_y = DynResidue::new(&U192::from_be_slice(sw_y), modulus); + let sw_k = DynResidue::new(&U192::from_be_slice(sw_k), modulus); + let sw_inv_k = sw_k.invert().0; + sw_res.copy_from_slice(sw_y.mul(&sw_inv_k).retrieve().to_be_bytes().as_slice()); + } + 32 => { + let modulus = DynResidueParams::new(&U256::from_be_slice(prime_field)); + let sw_y = DynResidue::new(&U256::from_be_slice(sw_y), modulus); + let sw_k = DynResidue::new(&U256::from_be_slice(sw_k), modulus); + let sw_inv_k = sw_k.invert().0; + sw_res.copy_from_slice(sw_y.mul(&sw_inv_k).retrieve().to_be_bytes().as_slice()); + } + _ => unimplemented!(), + }; + + for (a, b) in y.iter().zip(sw_res) { + assert_eq!( + a, b, + "ECC failed during finite field division with \np_y = {:02X?}\nk= {:02X?}", + sw_y, sw_k, + ); + } + } + println!( + "ok (it took {} cycles in average)", + delta_time / (TEST_PARAMS_VECTOR.nb_loop_inv as u64) + ); + } +} + +// All values are Little-Endian +#[cfg(feature = "esp32h2")] fn test_point_addition_256(ecc: &mut Ecc) { const ECC_256_X: [u8; 32] = [ 0x96, 0xC2, 0x98, 0xD8, 0x45, 0x39, 0xA1, 0xF4, 0xA0, 0x33, 0xEB, 0x2D, 0x81, 0x7D, 0x03, @@ -798,7 +890,8 @@ fn test_point_addition_256(ecc: &mut Ecc) { ); } -// all values are Little-Endian +// All values are Little-Endian +#[cfg(feature = "esp32h2")] fn test_point_addition_192(ecc: &mut Ecc) { const ECC_192_X: [u8; 24] = [ 0x12, 0x10, 0xFF, 0x82, 0xFD, 0x0A, 0xFF, 0xF4, 0x00, 0x88, 0xA1, 0x43, 0xEB, 0x20, 0xBF, @@ -860,7 +953,8 @@ fn test_point_addition_192(ecc: &mut Ecc) { ); } -// all values are Little-Endian +// All values are Little-Endian +#[cfg(feature = "esp32h2")] fn test_mod_operations_256(ecc: &mut Ecc) { const ECC_256_X: [u8; 32] = [ 0x96, 0xC2, 0x98, 0xD8, 0x45, 0x39, 0xA1, 0xF4, 0xA0, 0x33, 0xEB, 0x2D, 0x81, 0x7D, 0x03, @@ -974,7 +1068,8 @@ fn test_mod_operations_256(ecc: &mut Ecc) { println!("Mod operation (256) tests successful!"); } -// all values are Little-Endian +// All values are Little-Endian +#[cfg(feature = "esp32h2")] fn test_mod_operations_192(ecc: &mut Ecc) { const ECC_192_X: [u8; 24] = [ 0x1A, 0x80, 0xA1, 0x5F, 0x1F, 0xB7, 0x59, 0x1B, 0x9F, 0xD7, 0xFB, 0xAE, 0xA9, 0xF9, 0x1E, diff --git a/esp32-hal/examples/embassy_hello_world.rs b/examples/src/bin/embassy_hello_world.rs similarity index 78% rename from esp32-hal/examples/embassy_hello_world.rs rename to examples/src/bin/embassy_hello_world.rs index 841c65713..90c16e2e5 100644 --- a/esp32-hal/examples/embassy_hello_world.rs +++ b/examples/src/bin/embassy_hello_world.rs @@ -3,20 +3,23 @@ //! This is an example of running the embassy executor with multiple tasks //! concurrently. +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 +//% FEATURES: embassy embassy-time-timg0 embassy-executor-thread embassy-generic-timers + #![no_std] #![no_main] #![feature(type_alias_impl_trait)] use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; -use esp32_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, embassy::{self}, peripherals::Peripherals, prelude::*, timer::TimerGroup, }; -use esp_backtrace as _; #[embassy_executor::task] async fn run() { @@ -33,8 +36,8 @@ async fn main(spawner: Spawner) { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + embassy::init(&clocks, timg0); spawner.spawn(run()).ok(); diff --git a/esp32-hal/examples/embassy_i2c.rs b/examples/src/bin/embassy_i2c.rs similarity index 78% rename from esp32-hal/examples/embassy_i2c.rs rename to examples/src/bin/embassy_i2c.rs index e8b848f7a..d9aa857d6 100644 --- a/esp32-hal/examples/embassy_i2c.rs +++ b/examples/src/bin/embassy_i2c.rs @@ -1,8 +1,8 @@ //! Embassy I2C //! //! Folowing pins are used: -//! SDA GPIO32 -//! SCL GPIO33 +//! SDA GPIO4 +//! SCL GPIO5 //! //! Depending on your target and the board you are using you have to change the //! pins. @@ -10,13 +10,17 @@ //! This is an example of running the embassy executor with IC2. It uses an //! LIS3DH to get accelerometer data. +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 +//% FEATURES: async embassy embassy-executor-thread embassy-time-timg0 embassy-generic-timers + #![no_std] #![no_main] #![feature(type_alias_impl_trait)] use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; -use esp32_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, embassy::{self}, i2c::I2C, @@ -25,7 +29,6 @@ use esp32_hal::{ timer::TimerGroup, IO, }; -use esp_backtrace as _; use lis3dh_async::{Lis3dh, Range, SlaveAddr}; #[main] @@ -34,15 +37,15 @@ async fn main(_spawner: Spawner) { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + embassy::init(&clocks, timg0); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); let i2c0 = I2C::new( peripherals.I2C0, - io.pins.gpio32, - io.pins.gpio33, + io.pins.gpio4, + io.pins.gpio5, 400u32.kHz(), &clocks, ); diff --git a/esp32s3-hal/examples/embassy_i2s_read.rs b/examples/src/bin/embassy_i2s_read.rs similarity index 69% rename from esp32s3-hal/examples/embassy_i2s_read.rs rename to examples/src/bin/embassy_i2s_read.rs index 13809e72a..929c6965d 100644 --- a/esp32s3-hal/examples/embassy_i2s_read.rs +++ b/examples/src/bin/embassy_i2s_read.rs @@ -1,22 +1,26 @@ -//! This shows how to continously receive data via I2S +//! This shows how to continously receive data via I2S. //! -//! Pins used -//! MCLK GPIO4 -//! BCLK GPIO1 -//! WS GPIO2 +//! Pins used: +//! MCLK GPIO0 (not ESP32) +//! BCLK GPIO2 +//! WS GPIO4 //! DIN GPIO5 //! -//! Without an additional I2S source device you can connect 3V3 or GND to DIN to -//! read 0 or 0xFF or connect DIN to WS to read two different values +//! Without an additional I2S source device you can connect 3V3 or GND to DIN +//! to read 0 or 0xFF or connect DIN to WS to read two different values. //! -//! You can also inspect the MCLK, BCLK and WS with a logic analyzer +//! You can also inspect the MCLK, BCLK and WS with a logic analyzer. + +//% CHIPS: esp32 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 +//% FEATURES: async embassy embassy-executor-thread embassy-time-timg0 embassy-generic-timers #![no_std] #![no_main] #![feature(type_alias_impl_trait)] use embassy_executor::Spawner; -use esp32s3_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, @@ -24,35 +28,27 @@ use esp32s3_hal::{ i2s::{asynch::*, DataFormat, I2s, Standard}, peripherals::Peripherals, prelude::*, + timer::TimerGroup, IO, }; -use esp_backtrace as _; use esp_println::println; #[main] async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); println!("Init!"); let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32s3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + embassy::init(&clocks, timg0); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); let dma = Dma::new(peripherals.DMA); + #[cfg(any(feature = "esp32", feature = "esp32s2"))] + let dma_channel = dma.i2s0channel; + #[cfg(not(any(feature = "esp32", feature = "esp32s2")))] let dma_channel = dma.channel0; let (_, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(0, 4092 * 4); @@ -69,13 +65,17 @@ async fn main(_spawner: Spawner) { DmaPriority::Priority0, ), &clocks, - ) - .with_mclk(io.pins.gpio4); + ); + + #[cfg(esp32)] + { + i2s.with_mclk(io.pins.gpio0); + } let i2s_rx = i2s .i2s_rx - .with_bclk(io.pins.gpio1) - .with_ws(io.pins.gpio2) + .with_bclk(io.pins.gpio2) + .with_ws(io.pins.gpio4) .with_din(io.pins.gpio5) .build(); diff --git a/esp32s3-hal/examples/embassy_i2s_sound.rs b/examples/src/bin/embassy_i2s_sound.rs similarity index 78% rename from esp32s3-hal/examples/embassy_i2s_sound.rs rename to examples/src/bin/embassy_i2s_sound.rs index 1f5797b1d..c7c4d8dea 100644 --- a/esp32s3-hal/examples/embassy_i2s_sound.rs +++ b/examples/src/bin/embassy_i2s_sound.rs @@ -1,18 +1,17 @@ -//! This shows how to transmit data continously via I2S +//! This shows how to transmit data continously via I2S. //! -//! Pins used -//! MCLK GPIO4 -//! BCLK GPIO1 -//! WS GPIO2 -//! DOUT GPIO3 +//! Pins used: +//! BCLK GPIO2 +//! WS GPIO4 +//! DOUT GPIO5 //! -//! Without an additional I2S sink device you can inspect the MCLK, BCLK, WS and -//! DOUT with a logic analyzer +//! Without an additional I2S sink device you can inspect the BCLK, WS +//! and DOUT with a logic analyzer. //! //! You can also connect e.g. a PCM510x to hear an annoying loud sine tone (full //! scale), so turn down the volume before running this example. //! -//! Wiring is like this +//! Wiring is like this: //! //! | Pin | Connected to | //! |-------|-----------------| @@ -27,12 +26,16 @@ //! | DEMP | Gnd | //! | XSMT | +3V3 | +//% CHIPS: esp32 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 +//% FEATURES: async embassy embassy-executor-thread embassy-time-timg0 embassy-generic-timers + #![no_std] #![no_main] #![feature(type_alias_impl_trait)] use embassy_executor::Spawner; -use esp32s3_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, @@ -40,9 +43,9 @@ use esp32s3_hal::{ i2s::{asynch::*, DataFormat, I2s, Standard}, peripherals::Peripherals, prelude::*, + timer::TimerGroup, IO, }; -use esp_backtrace as _; use esp_println::println; const SINE: [i16; 64] = [ @@ -55,28 +58,20 @@ const SINE: [i16; 64] = [ #[main] async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); println!("Init!"); let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s3_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32s3_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + embassy::init(&clocks, timg0); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); let dma = Dma::new(peripherals.DMA); + #[cfg(any(feature = "esp32", feature = "esp32s2"))] + let dma_channel = dma.i2s0channel; + #[cfg(not(any(feature = "esp32", feature = "esp32s2")))] let dma_channel = dma.channel0; let (tx_buffer, mut tx_descriptors, _, mut rx_descriptors) = dma_buffers!(32000, 0); @@ -93,14 +88,13 @@ async fn main(_spawner: Spawner) { DmaPriority::Priority0, ), &clocks, - ) - .with_mclk(io.pins.gpio4); + ); let i2s_tx = i2s .i2s_tx - .with_bclk(io.pins.gpio1) - .with_ws(io.pins.gpio2) - .with_dout(io.pins.gpio3) + .with_bclk(io.pins.gpio2) + .with_ws(io.pins.gpio4) + .with_dout(io.pins.gpio5) .build(); let data = diff --git a/esp32-hal/examples/embassy_multicore.rs b/examples/src/bin/embassy_multicore.rs similarity index 91% rename from esp32-hal/examples/embassy_multicore.rs rename to examples/src/bin/embassy_multicore.rs index 6364dca5b..45354e7f1 100644 --- a/esp32-hal/examples/embassy_multicore.rs +++ b/examples/src/bin/embassy_multicore.rs @@ -1,7 +1,11 @@ //! This example shows how to spawn async tasks on the second core. +//! //! The second core runs a simple LED blinking task, that is controlled by a //! signal set by the task running on the other core. +//% CHIPS: esp32 esp32s3 +//% FEATURES: embassy embassy-executor-thread embassy-time-timg0 embassy-generic-timers + #![no_std] #![no_main] #![feature(type_alias_impl_trait)] @@ -9,7 +13,8 @@ use embassy_executor::Spawner; use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, signal::Signal}; use embassy_time::{Duration, Ticker}; -use esp32_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, cpu_control::{CpuControl, Stack}, embassy::{self, executor::Executor}, @@ -19,7 +24,6 @@ use esp32_hal::{ prelude::*, timer::TimerGroup, }; -use esp_backtrace as _; use esp_println::println; use static_cell::make_static; @@ -50,12 +54,11 @@ async fn main(_spawner: Spawner) { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - - // Set GPIO2 as an output, and set its state high initially. let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + embassy::init(&clocks, timg0); + let mut cpu_control = CpuControl::new(system.cpu_control); let led_ctrl_signal = &*make_static!(Signal::new()); diff --git a/esp32-hal/examples/embassy_multicore_interrupt.rs b/examples/src/bin/embassy_multicore_interrupt.rs similarity index 93% rename from esp32-hal/examples/embassy_multicore_interrupt.rs rename to examples/src/bin/embassy_multicore_interrupt.rs index b3098c305..c139e6ef9 100644 --- a/esp32-hal/examples/embassy_multicore_interrupt.rs +++ b/examples/src/bin/embassy_multicore_interrupt.rs @@ -1,14 +1,19 @@ //! This example shows how to use the interrupt executors on either core. +//! //! The second core runs a simple LED blinking task, that is controlled by a //! signal set by the task running on the other core. +//% CHIPS: esp32 esp32s3 +//% FEATURES: embassy embassy-executor-interrupt embassy-time-timg0 embassy-generic-timers + #![no_std] #![no_main] #![feature(type_alias_impl_trait)] use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, signal::Signal}; use embassy_time::{Duration, Ticker}; -use esp32_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, cpu_control::{CpuControl, Stack}, embassy::{ @@ -22,7 +27,6 @@ use esp32_hal::{ prelude::*, timer::TimerGroup, }; -use esp_backtrace as _; use esp_println::println; use static_cell::make_static; @@ -85,12 +89,11 @@ fn main() -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - - // Set GPIO2 as an output, and set its state high initially. let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + embassy::init(&clocks, timg0); + let mut cpu_control = CpuControl::new(system.cpu_control); let led_ctrl_signal = &*make_static!(Signal::new()); diff --git a/esp32c6-hal/examples/embassy_multiprio.rs b/examples/src/bin/embassy_multiprio.rs similarity index 87% rename from esp32c6-hal/examples/embassy_multiprio.rs rename to examples/src/bin/embassy_multiprio.rs index ac4f3a021..ba26af899 100644 --- a/esp32c6-hal/examples/embassy_multiprio.rs +++ b/examples/src/bin/embassy_multiprio.rs @@ -11,13 +11,18 @@ //! demonstrates that this task will continue to run even while the low //! priority blocking task is running. +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 +// FIXME: We should not need *two* executor features enabled here... +//% FEATURES: embassy embassy-executor-interrupt embassy-executor-thread embassy-time-timg0 embassy-generic-timers + #![no_std] #![no_main] #![feature(type_alias_impl_trait)] use embassy_executor::Spawner; use embassy_time::{Duration, Instant, Ticker, Timer}; -use esp32c6_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, embassy::{ self, @@ -26,8 +31,8 @@ use esp32c6_hal::{ interrupt::Priority, peripherals::Peripherals, prelude::*, + timer::TimerGroup, }; -use esp_backtrace as _; use esp_println::println; static INT_EXECUTOR_0: InterruptExecutor = InterruptExecutor::new(); @@ -79,17 +84,8 @@ async fn main(low_prio_spawner: Spawner) { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c6_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32c6_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + embassy::init(&clocks, timg0); let spawner = INT_EXECUTOR_0.start(Priority::Priority2); spawner.must_spawn(high_prio()); diff --git a/esp32c6-hal/examples/embassy_parl_io_rx.rs b/examples/src/bin/embassy_parl_io_rx.rs similarity index 82% rename from esp32c6-hal/examples/embassy_parl_io_rx.rs rename to examples/src/bin/embassy_parl_io_rx.rs index 51611a305..576214a94 100644 --- a/esp32c6-hal/examples/embassy_parl_io_rx.rs +++ b/examples/src/bin/embassy_parl_io_rx.rs @@ -3,13 +3,17 @@ //! //! Uses GPIO 1, 2, 3 and 4 as the data pins. +//% CHIPS: esp32c6 esp32h2 +//% FEATURES: async embassy embassy-executor-thread embassy-time-timg0 embassy-generic-timers + #![no_std] #![no_main] #![feature(type_alias_impl_trait)] use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; -use esp32c6_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, @@ -18,8 +22,8 @@ use esp32c6_hal::{ parl_io::{BitPackOrder, NoClkPin, ParlIoRxOnly, RxFourBits}, peripherals::Peripherals, prelude::*, + timer::TimerGroup, }; -use esp_backtrace as _; use esp_println::println; #[main] @@ -29,17 +33,8 @@ async fn main(_spawner: Spawner) { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c6_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32c6_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + embassy::init(&clocks, timg0); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); diff --git a/esp32c6-hal/examples/embassy_parl_io_tx.rs b/examples/src/bin/embassy_parl_io_tx.rs similarity index 82% rename from esp32c6-hal/examples/embassy_parl_io_tx.rs rename to examples/src/bin/embassy_parl_io_tx.rs index 3ad12f776..a3f02ae71 100644 --- a/esp32c6-hal/examples/embassy_parl_io_tx.rs +++ b/examples/src/bin/embassy_parl_io_tx.rs @@ -3,17 +3,21 @@ //! //! Uses GPIO 1, 2, 3 and 4 as the data pins. //! GPIO 5 as the "valid pin" (driven high during an active transfer) and GPIO -//! 6 as the clock signal output. +//! 8 as the clock signal output. //! //! You can use a logic analyzer to see how the pins are used. +//% CHIPS: esp32c6 esp32h2 +//% FEATURES: async embassy embassy-executor-thread embassy-time-timg0 embassy-generic-timers + #![no_std] #![no_main] #![feature(type_alias_impl_trait)] use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; -use esp32c6_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, @@ -29,8 +33,8 @@ use esp32c6_hal::{ }, peripherals::Peripherals, prelude::*, + timer::TimerGroup, }; -use esp_backtrace as _; use esp_println::println; #[main] @@ -40,17 +44,8 @@ async fn main(_spawner: Spawner) { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c6_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32c6_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + embassy::init(&clocks, timg0); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); @@ -76,7 +71,7 @@ async fn main(_spawner: Spawner) { ) .unwrap(); - let clock_pin = ClkOutPin::new(io.pins.gpio6); + let clock_pin = ClkOutPin::new(io.pins.gpio8); let mut parl_io_tx = parl_io .tx diff --git a/esp32s2-hal/examples/embassy_rmt_rx.rs b/examples/src/bin/embassy_rmt_rx.rs similarity index 64% rename from esp32s2-hal/examples/embassy_rmt_rx.rs rename to examples/src/bin/embassy_rmt_rx.rs index 28ad974f5..549590c17 100644 --- a/esp32s2-hal/examples/embassy_rmt_rx.rs +++ b/examples/src/bin/embassy_rmt_rx.rs @@ -1,5 +1,8 @@ //! Demonstrates decoding pulse sequences with RMT -//! Connect GPIO15 to GPIO4 +//! Connect GPIO5 to GPIO4 + +//% CHIPS: esp32 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 +//% FEATURES: async embassy embassy-executor-thread embassy-time-timg0 embassy-generic-timers #![no_std] #![no_main] @@ -7,17 +10,17 @@ use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; -use esp32s2_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, embassy::{self}, - gpio::{Gpio15, Output, PushPull}, + gpio::{Gpio5, Output, PushPull}, peripherals::Peripherals, prelude::*, rmt::{asynch::RxChannelAsync, PulseCode, RxChannelConfig, RxChannelCreator}, Rmt, IO, }; -use esp_backtrace as _; use esp_println::{print, println}; const WIDTH: usize = 80; @@ -26,7 +29,7 @@ const WIDTH: usize = 80; compile_error!("Run this example in release mode"); #[embassy_executor::task] -async fn signal_task(mut pin: Gpio15>) { +async fn signal_task(mut pin: Gpio5>) { loop { for _ in 0..10 { pin.toggle().unwrap(); @@ -38,44 +41,45 @@ async fn signal_task(mut pin: Gpio15>) { #[main] async fn main(spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); println!("Init!"); let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32s2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } + let timer_group0 = esp_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); + embassy::init(&clocks, timer_group0); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let rmt = Rmt::new(peripherals.RMT, 80u32.MHz(), &clocks).unwrap(); + cfg_if::cfg_if! { + if #[cfg(feature = "esp32h2")] { + let freq = 32u32.MHz(); + } else { + let freq = 80u32.MHz(); + } + }; - let mut channel = rmt - .channel2 - .configure( - io.pins.gpio4, - RxChannelConfig { - clk_divider: 1, - idle_threshold: 0b111_1111_1111_1111, - ..RxChannelConfig::default() - }, - ) - .unwrap(); + let rmt = Rmt::new(peripherals.RMT, freq, &clocks).unwrap(); + let rx_config = RxChannelConfig { + clk_divider: 255, + idle_threshold: 10000, + ..RxChannelConfig::default() + }; + + cfg_if::cfg_if! { + if #[cfg(any(feature = "esp32", feature = "esp32s2"))] { + let mut channel = rmt.channel0.configure(io.pins.gpio4, rx_config).unwrap(); + } else if #[cfg(feature = "esp32s3")] { + let mut channel = rmt.channel7.configure(io.pins.gpio4, rx_config).unwrap(); + } else { + let mut channel = rmt.channel2.configure(io.pins.gpio4, rx_config).unwrap(); + } + } spawner - .spawn(signal_task(io.pins.gpio15.into_push_pull_output())) - .ok(); + .spawn(signal_task(io.pins.gpio5.into_push_pull_output())) + .unwrap(); + let mut data = [PulseCode { level1: true, length1: 1, diff --git a/esp32s2-hal/examples/embassy_rmt_tx.rs b/examples/src/bin/embassy_rmt_tx.rs similarity index 74% rename from esp32s2-hal/examples/embassy_rmt_tx.rs rename to examples/src/bin/embassy_rmt_tx.rs index dd557c90d..93a13841c 100644 --- a/esp32s2-hal/examples/embassy_rmt_tx.rs +++ b/examples/src/bin/embassy_rmt_tx.rs @@ -1,48 +1,50 @@ //! Demonstrates generating pulse sequences with RMT +//! //! Connect a logic analyzer to GPIO4 to see the generated pulses. +//% CHIPS: esp32 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 +//% FEATURES: async embassy embassy-executor-thread embassy-time-timg0 embassy-generic-timers + #![no_std] #![no_main] #![feature(type_alias_impl_trait)] use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; -use esp32s2_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, embassy::{self}, peripherals::Peripherals, prelude::*, rmt::{asynch::TxChannelAsync, PulseCode, TxChannelConfig, TxChannelCreator}, + timer::TimerGroup, Rmt, IO, }; -use esp_backtrace as _; use esp_println::println; #[main] async fn main(_spawner: Spawner) { - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); println!("Init!"); let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32s2_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32s2_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + embassy::init(&clocks, timg0); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let rmt = Rmt::new(peripherals.RMT, 80u32.MHz(), &clocks).unwrap(); + cfg_if::cfg_if! { + if #[cfg(feature = "esp32h2")] { + let freq = 32u32.MHz(); + } else { + let freq = 80u32.MHz(); + } + }; + + let rmt = Rmt::new(peripherals.RMT, freq, &clocks).unwrap(); let mut channel = rmt .channel0 diff --git a/esp32-hal/examples/embassy_serial.rs b/examples/src/bin/embassy_serial.rs similarity index 87% rename from esp32-hal/examples/embassy_serial.rs rename to examples/src/bin/embassy_serial.rs index 8f5e02f70..195ab2d4e 100644 --- a/esp32-hal/examples/embassy_serial.rs +++ b/examples/src/bin/embassy_serial.rs @@ -7,17 +7,21 @@ #![no_main] #![feature(type_alias_impl_trait)] +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 +//% FEATURES: async embassy embassy-executor-thread embassy-time-timg0 embassy-generic-timers + use embassy_executor::Spawner; use embassy_sync::{blocking_mutex::raw::NoopRawMutex, signal::Signal}; -use esp32_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, embassy, peripherals::{Peripherals, UART0}, prelude::*, + timer::TimerGroup, uart::{config::AtCmdConfig, UartRx, UartTx}, Uart, }; -use esp_backtrace as _; use static_cell::make_static; // rx_fifo_full_threshold @@ -70,17 +74,8 @@ async fn main(spawner: Spawner) { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - { - let timer_group0 = esp32_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); - } + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + embassy::init(&clocks, timg0); let mut uart0 = Uart::new(peripherals.UART0, &clocks); uart0.set_at_cmd(AtCmdConfig::new(None, None, None, AT_CMD, None)); diff --git a/esp32-hal/examples/embassy_spi.rs b/examples/src/bin/embassy_spi.rs similarity index 75% rename from esp32-hal/examples/embassy_spi.rs rename to examples/src/bin/embassy_spi.rs index 74b7be9ff..56852b4df 100644 --- a/esp32-hal/examples/embassy_spi.rs +++ b/examples/src/bin/embassy_spi.rs @@ -1,10 +1,10 @@ //! Embassy SPI //! //! Folowing pins are used: -//! SCLK GPIO19 -//! MISO GPIO25 -//! MOSI GPIO23 -//! CS GPIO22 +//! SCLK GPIO0 +//! MISO GPIO1 +//! MOSI GPIO2 +//! CS GPIO3 //! //! Depending on your target and the board you are using you have to change the //! pins. @@ -14,13 +14,17 @@ //! //! This is an example of running the embassy executor with SPI. +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 +//% FEATURES: async embassy embassy-executor-thread embassy-time-timg0 embassy-generic-timers + #![no_std] #![no_main] #![feature(type_alias_impl_trait)] use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; -use esp32_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, dma::{DmaPriority, *}, dma_descriptors, @@ -34,7 +38,6 @@ use esp32_hal::{ timer::TimerGroup, IO, }; -use esp_backtrace as _; #[main] async fn main(_spawner: Spawner) { @@ -43,17 +46,21 @@ async fn main(_spawner: Spawner) { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + embassy::init(&clocks, timg0); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio19; - let miso = io.pins.gpio25; - let mosi = io.pins.gpio23; - let cs = io.pins.gpio22; + let sclk = io.pins.gpio0; + let miso = io.pins.gpio1; + let mosi = io.pins.gpio2; + let cs = io.pins.gpio3; let dma = Dma::new(peripherals.DMA); + + #[cfg(any(feature = "esp32", feature = "esp32s2"))] let dma_channel = dma.spi2channel; + #[cfg(not(any(feature = "esp32", feature = "esp32s2")))] + let dma_channel = dma.channel0; let (mut descriptors, mut rx_descriptors) = dma_descriptors!(32000); diff --git a/esp32c6-hal/examples/embassy_usb_serial_jtag.rs b/examples/src/bin/embassy_usb_serial_jtag.rs similarity index 85% rename from esp32c6-hal/examples/embassy_usb_serial_jtag.rs rename to examples/src/bin/embassy_usb_serial_jtag.rs index 2a1a24e75..a5013a6c6 100644 --- a/esp32c6-hal/examples/embassy_usb_serial_jtag.rs +++ b/examples/src/bin/embassy_usb_serial_jtag.rs @@ -2,21 +2,25 @@ //! You need to connect via the Serial/JTAG interface to see any output. //! Most dev-kits use a USB-UART-bridge - in that case you won't see any output. +//% CHIPS: esp32c3 esp32c6 esp32h2 esp32s3 +//% FEATURES: async embassy embassy-executor-thread embassy-time-timg0 embassy-generic-timers + #![no_std] #![no_main] #![feature(type_alias_impl_trait)] use embassy_executor::Spawner; use embassy_sync::{blocking_mutex::raw::NoopRawMutex, signal::Signal}; -use esp32c6_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, embassy, peripherals::Peripherals, prelude::*, + timer::TimerGroup, + usb_serial_jtag::{UsbSerialJtagRx, UsbSerialJtagTx}, UsbSerialJtag, }; -use esp_backtrace as _; -use esp_hal::usb_serial_jtag::{UsbSerialJtagRx, UsbSerialJtagTx}; use static_cell::make_static; const MAX_BUFFER_SIZE: usize = 512; @@ -67,17 +71,7 @@ async fn main(spawner: Spawner) -> () { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - #[cfg(feature = "embassy-time-systick")] - embassy::init( - &clocks, - esp32c6_hal::systimer::SystemTimer::new(peripherals.SYSTIMER), - ); - - #[cfg(feature = "embassy-time-timg0")] - embassy::init( - &clocks, - esp32c6_hal::timer::TimerGroup::new(peripherals.TIMG0, &clocks), - ); + embassy::init(&clocks, TimerGroup::new(peripherals.TIMG0, &clocks)); let (tx, rx) = UsbSerialJtag::new(peripherals.USB_DEVICE).split(); diff --git a/esp32-hal/examples/embassy_wait.rs b/examples/src/bin/embassy_wait.rs similarity index 78% rename from esp32-hal/examples/embassy_wait.rs rename to examples/src/bin/embassy_wait.rs index 112b13057..e00f43742 100644 --- a/esp32-hal/examples/embassy_wait.rs +++ b/examples/src/bin/embassy_wait.rs @@ -2,6 +2,9 @@ //! //! This is an example of asynchronously `Wait`ing for a pin state to change. +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 +//% FEATURES: async embassy embassy-executor-thread embassy-time-timg0 embassy-generic-timers + #![no_std] #![no_main] #![feature(type_alias_impl_trait)] @@ -9,7 +12,8 @@ use embassy_executor::Spawner; use embassy_time::{Duration, Timer}; use embedded_hal_async::digital::Wait; -use esp32_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, embassy::{self}, peripherals::Peripherals, @@ -17,7 +21,6 @@ use esp32_hal::{ timer::TimerGroup, IO, }; -use esp_backtrace as _; #[main] async fn main(_spawner: Spawner) { @@ -26,11 +29,10 @@ async fn main(_spawner: Spawner) { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - embassy::init(&clocks, timer_group0); + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + embassy::init(&clocks, timg0); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - // GPIO 0 as input let mut input = io.pins.gpio0.into_pull_down_input(); loop { diff --git a/esp32c6-hal/examples/etm_blinky_systimer.rs b/examples/src/bin/etm_blinky_systimer.rs similarity index 83% rename from esp32c6-hal/examples/etm_blinky_systimer.rs rename to examples/src/bin/etm_blinky_systimer.rs index 77c795a0a..4d6cc0235 100644 --- a/esp32c6-hal/examples/etm_blinky_systimer.rs +++ b/examples/src/bin/etm_blinky_systimer.rs @@ -1,23 +1,22 @@ -//! Control LED on GPIO 1 by the systimer via ETM +//! Control LED on GPIO1 by the systimer via ETM + +//% CHIPS: esp32c6 esp32h2 #![no_std] #![no_main] -use esp32c6_hal::{ - clock::ClockControl, +use esp_backtrace as _; +use esp_hal::{ etm::Etm, gpio::{etm::GpioEtmChannels, IO}, peripherals::Peripherals, prelude::*, systimer::{etm::SysTimerEtmEvent, SystemTimer}, }; -use esp_backtrace as _; #[entry] fn main() -> ! { let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let syst = SystemTimer::new(peripherals.SYSTIMER); let mut alarm0 = syst.alarm0.into_periodic(); diff --git a/esp32c6-hal/examples/etm_gpio.rs b/examples/src/bin/etm_gpio.rs similarity index 81% rename from esp32c6-hal/examples/etm_gpio.rs rename to examples/src/bin/etm_gpio.rs index d2f4f2227..900ad1c32 100644 --- a/esp32c6-hal/examples/etm_gpio.rs +++ b/examples/src/bin/etm_gpio.rs @@ -1,22 +1,21 @@ -//! Control LED on GPIO 1 by the BOOT-BUTTON via ETM +//! Control LED on GPIO1 by the BOOT-BUTTON via ETM + +//% CHIPS: esp32c6 esp32h2 #![no_std] #![no_main] -use esp32c6_hal::{ - clock::ClockControl, +use esp_backtrace as _; +use esp_hal::{ etm::Etm, gpio::{etm::GpioEtmChannels, IO}, peripherals::Peripherals, prelude::*, }; -use esp_backtrace as _; #[entry] fn main() -> ! { let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); let mut led = io.pins.gpio1.into_push_pull_output(); diff --git a/esp32s3-hal/examples/gpio_interrupt.rs b/examples/src/bin/gpio_interrupt.rs similarity index 50% rename from esp32s3-hal/examples/gpio_interrupt.rs rename to examples/src/bin/gpio_interrupt.rs index fd40f43cd..a2303b51f 100644 --- a/esp32s3-hal/examples/gpio_interrupt.rs +++ b/examples/src/bin/gpio_interrupt.rs @@ -3,25 +3,31 @@ //! This prints "Interrupt" when the boot button is pressed. //! It also blinks an LED like the blinky example. +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] use core::cell::RefCell; use critical_section::Mutex; -use esp32s3_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, - gpio::{Event, Gpio0, Input, PullDown, IO}, - interrupt, + gpio::{self, Event, Input, PullDown, IO}, + interrupt::{self, Priority}, macros::ram, - peripherals::{self, Peripherals}, + peripherals::{Interrupt, Peripherals}, prelude::*, - xtensa_lx, Delay, }; -use esp_backtrace as _; -static BUTTON: Mutex>>>> = Mutex::new(RefCell::new(None)); +#[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] +static BUTTON: Mutex>>>> = + Mutex::new(RefCell::new(None)); +#[cfg(not(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3")))] +static BUTTON: Mutex>>>> = + Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { @@ -29,15 +35,19 @@ fn main() -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - // Set GPIO15 as an output, and set its state high initially. + // Set GPIO2 as an output, and set its state high initially. let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut led = io.pins.gpio15.into_push_pull_output(); + let mut led = io.pins.gpio2.into_push_pull_output(); + + #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] let mut button = io.pins.gpio0.into_pull_down_input(); + #[cfg(not(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3")))] + let mut button = io.pins.gpio9.into_pull_down_input(); button.listen(Event::FallingEdge); critical_section::with(|cs| BUTTON.borrow_ref_mut(cs).replace(button)); - interrupt::enable(peripherals::Interrupt::GPIO, interrupt::Priority::Priority2).unwrap(); + interrupt::enable(Interrupt::GPIO, Priority::Priority2).unwrap(); led.set_high().unwrap(); @@ -54,10 +64,13 @@ fn main() -> ! { #[ram] #[interrupt] fn GPIO() { + #[cfg(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3"))] esp_println::println!( "GPIO Interrupt with priority {}", - xtensa_lx::interrupt::get_level() + esp_hal::xtensa_lx::interrupt::get_level() ); + #[cfg(not(any(feature = "esp32", feature = "esp32s2", feature = "esp32s3")))] + esp_println::println!("GPIO Interrupt"); critical_section::with(|cs| { BUTTON diff --git a/esp32s3-hal/examples/hello_rgb.rs b/examples/src/bin/hello_rgb.rs similarity index 64% rename from esp32s3-hal/examples/hello_rgb.rs rename to examples/src/bin/hello_rgb.rs index 1ef7bead3..04c37ade0 100644 --- a/esp32s3-hal/examples/hello_rgb.rs +++ b/examples/src/bin/hello_rgb.rs @@ -1,18 +1,20 @@ //! RGB LED Demo //! -//! This example drives an SK68XX RGB LED that is connected to the GPI48 pin. -//! A RGB LED is connected to that pin on the official DevKits. +//! This example drives an SK68XX RGB LED, which is connected to a pin on the +//! official DevKits. //! //! The demo will leverage the [`smart_leds`](https://crates.io/crates/smart-leds) //! crate functionality to circle through the HSV hue color space (with //! saturation and value both at 255). Additionally, we apply a gamma correction //! and limit the brightness to 10 (out of 255). +//% CHIPS: esp32 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] -use esp32s3_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, rmt::Rmt, Delay, IO}; use esp_backtrace as _; +use esp_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, rmt::Rmt, Delay, IO}; use esp_hal_smartled::{smartLedBuffer, SmartLedsAdapter}; use smart_leds::{ brightness, @@ -29,13 +31,32 @@ fn main() -> ! { let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); + // Each devkit uses a unique GPIO for the RGB LED, so in order to support + // all chips we must unfortunately use `#[cfg]`s: + cfg_if::cfg_if! { + if #[cfg(feature = "esp32")] { + let led_pin = io.pins.gpio33; + } else if #[cfg(feature = "esp32c3")] { + let led_pin = io.pins.gpio8; + } else if #[cfg(any(feature = "esp32c6", feature = "esp32h2"))] { + let led_pin = io.pins.gpio8; + } else if #[cfg(feature = "esp32s2")] { + let led_pin = io.pins.gpio18; + } else if #[cfg(feature = "esp32s3")] { + let led_pin = io.pins.gpio48; + } + } + // Configure RMT peripheral globally + #[cfg(not(feature = "esp32h2"))] let rmt = Rmt::new(peripherals.RMT, 80u32.MHz(), &clocks).unwrap(); + #[cfg(feature = "esp32h2")] + let rmt = Rmt::new(peripherals.RMT, 32u32.MHz(), &clocks).unwrap(); // We use one of the RMT channels to instantiate a `SmartLedsAdapter` which can // be used directly with all `smart_led` implementations let rmt_buffer = smartLedBuffer!(1); - let mut led = SmartLedsAdapter::new(rmt.channel0, io.pins.gpio48, rmt_buffer, &clocks); + let mut led = SmartLedsAdapter::new(rmt.channel0, led_pin, rmt_buffer, &clocks); // Initialize the Delay peripheral, and use it to toggle the LED state in a // loop. diff --git a/esp32s2-hal/examples/hello_world.rs b/examples/src/bin/hello_world.rs similarity index 62% rename from esp32s2-hal/examples/hello_world.rs rename to examples/src/bin/hello_world.rs index ce29d0d0b..d71ab9aab 100644 --- a/esp32s2-hal/examples/hello_world.rs +++ b/examples/src/bin/hello_world.rs @@ -1,19 +1,17 @@ -//! This shows how to write text to uart0. -//! You can see the output with `espflash` if you provide the `--monitor` option +//! This shows how to write text to UART0. +//! +//! You can see the output with `espflash` if you provide the `--monitor` +//! option. + +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 #![no_std] #![no_main] use core::fmt::Write; -use esp32s2_hal::{ - clock::ClockControl, - peripherals::Peripherals, - prelude::*, - timer::TimerGroup, - Uart, -}; use esp_backtrace as _; +use esp_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, timer::TimerGroup, Uart}; use nb::block; #[entry] @@ -22,13 +20,12 @@ fn main() -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let mut timer0 = timg0.timer0; + timer0.start(1u64.secs()); let mut uart0 = Uart::new(peripherals.UART0, &clocks); - timer0.start(1u64.secs()); - loop { writeln!(uart0, "Hello world!").unwrap(); block!(timer0.wait()).unwrap(); diff --git a/esp32c3-hal/examples/hmac.rs b/examples/src/bin/hmac.rs similarity index 98% rename from esp32c3-hal/examples/hmac.rs rename to examples/src/bin/hmac.rs index 78f80ae7b..3fdd700a2 100644 --- a/esp32c3-hal/examples/hmac.rs +++ b/examples/src/bin/hmac.rs @@ -52,10 +52,13 @@ //! xxd -p key.bin //! ``` +//% CHIPS: esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] -use esp32c3_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, hmac::{Hmac, HmacPurpose, KeyId}, peripherals::Peripherals, @@ -63,7 +66,6 @@ use esp32c3_hal::{ systimer::SystemTimer, Rng, }; -use esp_backtrace as _; use esp_println::println; use hmac::{Hmac as HmacSw, Mac}; use nb::block; diff --git a/esp32c3-hal/examples/i2c_bmp180_calibration_data.rs b/examples/src/bin/i2c_bmp180_calibration_data.rs similarity index 67% rename from esp32c3-hal/examples/i2c_bmp180_calibration_data.rs rename to examples/src/bin/i2c_bmp180_calibration_data.rs index b6e288958..cfd6c25ee 100644 --- a/esp32c3-hal/examples/i2c_bmp180_calibration_data.rs +++ b/examples/src/bin/i2c_bmp180_calibration_data.rs @@ -3,14 +3,16 @@ //! This example dumps the calibration data from a BMP180 sensor //! //! The following wiring is assumed: -//! - SDA => GPIO1 -//! - SCL => GPIO2 +//! - SDA => GPIO4 +//! - SCL => GPIO5 + +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 #![no_std] #![no_main] -use esp32c3_hal::{clock::ClockControl, gpio::IO, i2c::I2C, peripherals::Peripherals, prelude::*}; use esp_backtrace as _; +use esp_hal::{clock::ClockControl, gpio::IO, i2c::I2C, peripherals::Peripherals, prelude::*}; use esp_println::println; #[entry] @@ -21,12 +23,12 @@ fn main() -> ! { let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - // Create a new peripheral object with the described wiring - // and standard I2C clock speed + // Create a new peripheral object with the described wiring and standard + // I2C clock speed: let mut i2c = I2C::new( peripherals.I2C0, - io.pins.gpio1, - io.pins.gpio2, + io.pins.gpio4, + io.pins.gpio5, 100u32.kHz(), &clocks, ); diff --git a/esp32s3-hal/examples/i2c_display.rs b/examples/src/bin/i2c_display.rs similarity index 96% rename from esp32s3-hal/examples/i2c_display.rs rename to examples/src/bin/i2c_display.rs index fe1c35479..402b1dfb5 100644 --- a/esp32s3-hal/examples/i2c_display.rs +++ b/examples/src/bin/i2c_display.rs @@ -7,6 +7,8 @@ //! - SDA => GPIO1 //! - SCL => GPIO2 +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] @@ -19,7 +21,8 @@ use embedded_graphics::{ prelude::*, text::{Alignment, Text}, }; -use esp32s3_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, gpio::IO, i2c::I2C, @@ -27,7 +30,6 @@ use esp32s3_hal::{ prelude::*, timer::TimerGroup, }; -use esp_backtrace as _; use nb::block; use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306}; @@ -46,8 +48,8 @@ fn main() -> ! { // and standard I2C clock speed let i2c = I2C::new( peripherals.I2C0, - io.pins.gpio1, - io.pins.gpio2, + io.pins.gpio4, + io.pins.gpio5, 100u32.kHz(), &clocks, ); diff --git a/esp32s3-hal/examples/i2s_read.rs b/examples/src/bin/i2s_read.rs similarity index 74% rename from esp32s3-hal/examples/i2s_read.rs rename to examples/src/bin/i2s_read.rs index 295875b02..d325130bf 100644 --- a/esp32s3-hal/examples/i2s_read.rs +++ b/examples/src/bin/i2s_read.rs @@ -1,20 +1,23 @@ -//! This shows how to continously receive data via I2S +//! This shows how to continously receive data via I2S. //! -//! Pins used -//! MCLK GPIO4 -//! BCLK GPIO1 -//! WS GPIO2 +//! Pins used: +//! MCLK GPIO0 (not ESP32) +//! BCLK GPIO2 +//! WS GPIO4 //! DIN GPIO5 //! -//! Without an additional I2S source device you can connect 3V3 or GND to DIN to -//! read 0 or 0xFF or connect DIN to WS to read two different values +//! Without an additional I2S source device you can connect 3V3 or GND to DIN +//! to read 0 or 0xFF or connect DIN to WS to read two different values. //! -//! You can also inspect the MCLK, BCLK and WS with a logic analyzer +//! You can also inspect the MCLK, BCLK and WS with a logic analyzer. + +//% CHIPS: esp32 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 #![no_std] #![no_main] -use esp32s3_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, @@ -23,7 +26,6 @@ use esp32s3_hal::{ prelude::*, IO, }; -use esp_backtrace as _; use esp_println::println; #[entry] @@ -35,6 +37,9 @@ fn main() -> ! { let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); let dma = Dma::new(peripherals.DMA); + #[cfg(any(feature = "esp32", feature = "esp32s2"))] + let dma_channel = dma.i2s0channel; + #[cfg(not(any(feature = "esp32", feature = "esp32s2")))] let dma_channel = dma.channel0; let (_, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(0, 4 * 4092); @@ -55,13 +60,17 @@ fn main() -> ! { DmaPriority::Priority0, ), &clocks, - ) - .with_mclk(io.pins.gpio4); + ); + + #[cfg(esp32)] + { + i2s.with_mclk(io.pins.gpio0); + } let i2s_rx = i2s .i2s_rx - .with_bclk(io.pins.gpio1) - .with_ws(io.pins.gpio2) + .with_bclk(io.pins.gpio2) + .with_ws(io.pins.gpio4) .with_din(io.pins.gpio5) .build(); diff --git a/esp32-hal/examples/i2s_sound.rs b/examples/src/bin/i2s_sound.rs similarity index 82% rename from esp32-hal/examples/i2s_sound.rs rename to examples/src/bin/i2s_sound.rs index d032d19d9..ec5dba669 100644 --- a/esp32-hal/examples/i2s_sound.rs +++ b/examples/src/bin/i2s_sound.rs @@ -1,23 +1,23 @@ -//! This shows how to transmit data continously via I2S +//! This shows how to transmit data continously via I2S. //! -//! Pins used -//! BCLK GPIO12 -//! WS GPIO13 -//! DOUT GPIO14 +//! Pins used: +//! BCLK GPIO2 +//! WS GPIO4 +//! DOUT GPIO5 //! -//! Without an additional I2S sink device you can inspect the MCLK, BCLK, WS and -//! DOUT with a logic analyzer +//! Without an additional I2S sink device you can inspect the MCLK, BCLK, WS +//! andDOUT with a logic analyzer. //! //! You can also connect e.g. a PCM510x to hear an annoying loud sine tone (full //! scale), so turn down the volume before running this example. //! -//! Wiring is like this +//! Wiring is like this: //! //! | Pin | Connected to | //! |-------|-----------------| -//! | BCK | GPIO12 | -//! | DIN | GPIO14 | -//! | LRCK | GPIO13 | +//! | BCK | GPIO0 | +//! | DIN | GPIO2 | +//! | LRCK | GPIO1 | //! | SCK | Gnd | //! | GND | Gnd | //! | VIN | +3V3 | @@ -26,10 +26,13 @@ //! | DEMP | Gnd | //! | XSMT | +3V3 | +//% CHIPS: esp32 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] -use esp32_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, @@ -38,7 +41,6 @@ use esp32_hal::{ prelude::*, IO, }; -use esp_backtrace as _; const SINE: [i16; 64] = [ 0, 3211, 6392, 9511, 12539, 15446, 18204, 20787, 23169, 25329, 27244, 28897, 30272, 31356, @@ -57,7 +59,10 @@ fn main() -> ! { let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); let dma = Dma::new(peripherals.DMA); + #[cfg(any(feature = "esp32", feature = "esp32s2"))] let dma_channel = dma.i2s0channel; + #[cfg(not(any(feature = "esp32", feature = "esp32s2")))] + let dma_channel = dma.channel0; let (tx_buffer, mut tx_descriptors, _, mut rx_descriptors) = dma_buffers!(32000, 0); @@ -77,9 +82,9 @@ fn main() -> ! { let i2s_tx = i2s .i2s_tx - .with_bclk(io.pins.gpio12) - .with_ws(io.pins.gpio13) - .with_dout(io.pins.gpio14) + .with_bclk(io.pins.gpio2) + .with_ws(io.pins.gpio4) + .with_dout(io.pins.gpio5) .build(); let data = diff --git a/esp32c6-hal/examples/interrupt_preemption.rs b/examples/src/bin/interrupt_preemption.rs similarity index 78% rename from esp32c6-hal/examples/interrupt_preemption.rs rename to examples/src/bin/interrupt_preemption.rs index d1fb3a666..e80515c76 100644 --- a/esp32c6-hal/examples/interrupt_preemption.rs +++ b/examples/src/bin/interrupt_preemption.rs @@ -4,21 +4,22 @@ //! priority. Should show higher-numbered software interrupts happening during //! the handling of lower-numbered ones. +//% CHIPS: esp32c2 esp32c3 esp32c6 esp32h2 +//% FEATURES: interrupt-preemption + #![no_std] #![no_main] use core::cell::RefCell; use critical_section::Mutex; -use esp32c6_hal::{ - clock::ClockControl, - interrupt::{self}, - peripherals::{self, Peripherals}, +use esp_backtrace as _; +use esp_hal::{ + interrupt::{self, Priority}, + peripherals::{Interrupt, Peripherals}, prelude::*, - riscv, system::{SoftwareInterrupt, SoftwareInterruptControl}, }; -use esp_backtrace as _; static SWINT: Mutex>> = Mutex::new(RefCell::new(None)); @@ -26,39 +27,21 @@ static SWINT: Mutex>> = Mutex::new(RefC fn main() -> ! { let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); - let clockctrl = system.clock_control; let sw_int = system.software_interrupt_control; - let _clocks = ClockControl::boot_defaults(clockctrl).freeze(); critical_section::with(|cs| SWINT.borrow_ref_mut(cs).replace(sw_int)); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR0, - interrupt::Priority::Priority1, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR1, - interrupt::Priority::Priority2, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR2, - interrupt::Priority::Priority2, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR3, - interrupt::Priority::Priority15, - ) - .unwrap(); - unsafe { riscv::interrupt::enable() } + interrupt::enable(Interrupt::FROM_CPU_INTR0, Priority::Priority1).unwrap(); + interrupt::enable(Interrupt::FROM_CPU_INTR1, Priority::Priority2).unwrap(); + interrupt::enable(Interrupt::FROM_CPU_INTR2, Priority::Priority2).unwrap(); + interrupt::enable(Interrupt::FROM_CPU_INTR3, Priority::Priority15).unwrap(); - // raise mid priority interrupt. + // Raise mid priority interrupt. + // // The handler raises one interrupt at lower priority, one at same and one at // higher. We expect to see the higher priority served immeiately before // exiting the handler Once the handler is exited we expect to see same - // priority and low priority interrupts served in that order + // priority and low priority interrupts served in that order. critical_section::with(|cs| { SWINT .borrow_ref_mut(cs) @@ -66,6 +49,7 @@ fn main() -> ! { .unwrap() .raise(SoftwareInterrupt::SoftwareInterrupt1); }); + loop {} } @@ -80,6 +64,7 @@ fn FROM_CPU_INTR0() { .reset(SoftwareInterrupt::SoftwareInterrupt0); }); } + #[interrupt] fn FROM_CPU_INTR1() { esp_println::println!("SW interrupt1 entry"); @@ -108,6 +93,7 @@ fn FROM_CPU_INTR1() { }); esp_println::println!("SW interrupt1 exit"); } + #[interrupt] fn FROM_CPU_INTR2() { esp_println::println!("SW interrupt2"); @@ -119,6 +105,7 @@ fn FROM_CPU_INTR2() { .reset(SoftwareInterrupt::SoftwareInterrupt2); }); } + #[interrupt] fn FROM_CPU_INTR3() { esp_println::println!("SW interrupt3"); diff --git a/esp32s3-hal/examples/lcd_i8080.rs b/examples/src/bin/lcd_i8080.rs similarity index 99% rename from esp32s3-hal/examples/lcd_i8080.rs rename to examples/src/bin/lcd_i8080.rs index ac912c708..b9f96246b 100644 --- a/esp32s3-hal/examples/lcd_i8080.rs +++ b/examples/src/bin/lcd_i8080.rs @@ -2,7 +2,8 @@ //! //! This example clears the screen with red and then blue every second. //! -//! Pins used +//! Pins used: +//! //! Backlight GPIO45 //! Reset GPIO4 //! CD GPIO0 @@ -16,10 +17,13 @@ //! D6 GPIO16 //! D7 GPIO15 +//% CHIPS: esp32s3 + #![no_std] #![no_main] -use esp32s3_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, @@ -32,7 +36,6 @@ use esp32s3_hal::{ prelude::*, Delay, }; -use esp_backtrace as _; use esp_println::println; #[entry] diff --git a/esp32s3-hal/examples/ledc.rs b/examples/src/bin/ledc.rs similarity index 92% rename from esp32s3-hal/examples/ledc.rs rename to examples/src/bin/ledc.rs index 1a85fe6cb..ddde7ee56 100644 --- a/esp32s3-hal/examples/ledc.rs +++ b/examples/src/bin/ledc.rs @@ -1,12 +1,15 @@ //! Turns on LED with the option to change LED intensity depending on `duty` //! value. Possible values (`u32`) are in range 0..100. //! -//! This assumes that a LED is connected to the pin assigned to `led`. (GPIO4) +//! This assumes that a LED is connected to the pin assigned to `led`. (GPIO0) + +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 #![no_std] #![no_main] -use esp32s3_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, gpio::IO, ledc::{ @@ -19,7 +22,6 @@ use esp32s3_hal::{ peripherals::Peripherals, prelude::*, }; -use esp_backtrace as _; #[entry] fn main() -> ! { @@ -28,7 +30,7 @@ fn main() -> ! { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let led = io.pins.gpio4.into_push_pull_output(); + let led = io.pins.gpio0.into_push_pull_output(); let mut ledc = LEDC::new(peripherals.LEDC, &clocks); diff --git a/esp32c6-hal/examples/lp_core_basic.rs b/examples/src/bin/lp_core_basic.rs similarity index 76% rename from esp32c6-hal/examples/lp_core_basic.rs rename to examples/src/bin/lp_core_basic.rs index 9a08c5518..caa1c951d 100644 --- a/esp32c6-hal/examples/lp_core_basic.rs +++ b/examples/src/bin/lp_core_basic.rs @@ -5,32 +5,30 @@ //! //! Make sure to first compile the `esp-lp-hal/examples/blinky.rs` example +//% CHIPS: esp32c6 + #![no_std] #![no_main] -use esp32c6_hal::{ - clock::ClockControl, +use esp_backtrace as _; +use esp_hal::{ gpio::lp_gpio::IntoLowPowerPin, - lp_core, + lp_core::{LpCore, LpCoreWakeupSource}, peripherals::Peripherals, prelude::*, IO, }; -use esp_backtrace as _; use esp_println::{print, println}; #[entry] fn main() -> ! { let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); // configure GPIO 1 as LP output pin + let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); let lp_pin = io.pins.gpio1.into_low_power().into_push_pull_output(); - let mut lp_core = esp32c6_hal::lp_core::LpCore::new(peripherals.LP_CORE); + let mut lp_core = LpCore::new(peripherals.LP_CORE); lp_core.stop(); println!("lp core stopped"); @@ -39,7 +37,7 @@ fn main() -> ! { load_lp_code!("../esp-lp-hal/target/riscv32imac-unknown-none-elf/release/examples/blinky"); // start LP core - lp_core_code.run(&mut lp_core, lp_core::LpCoreWakeupSource::HpCpu, lp_pin); + lp_core_code.run(&mut lp_core, LpCoreWakeupSource::HpCpu, lp_pin); println!("lpcore run"); let data = (0x5000_2000) as *mut u32; diff --git a/esp32c6-hal/examples/lp_core_i2c.rs b/examples/src/bin/lp_core_i2c.rs similarity index 84% rename from esp32c6-hal/examples/lp_core_i2c.rs rename to examples/src/bin/lp_core_i2c.rs index 01022ba05..089c6ba4b 100644 --- a/esp32c6-hal/examples/lp_core_i2c.rs +++ b/examples/src/bin/lp_core_i2c.rs @@ -5,18 +5,20 @@ //! //! Make sure to first compile the `esp-lp-hal/examples/i2c.rs` example +//% CHIPS: esp32c6 + #![no_std] #![no_main] -use esp32c6_hal::{ +use esp_backtrace as _; +use esp_hal::{ gpio::lp_gpio::IntoLowPowerPin, i2c::lp_i2c::LpI2c, - lp_core, + lp_core::{LpCore, LpCoreWakeupSource}, peripherals::Peripherals, prelude::*, IO, }; -use esp_backtrace as _; use esp_println::println; #[entry] @@ -30,7 +32,7 @@ fn main() -> ! { let lp_i2c = LpI2c::new(peripherals.LP_I2C0, lp_sda, lp_scl, 100u32.kHz()); - let mut lp_core = esp32c6_hal::lp_core::LpCore::new(peripherals.LP_CORE); + let mut lp_core = LpCore::new(peripherals.LP_CORE); lp_core.stop(); println!("lp core stopped"); @@ -39,7 +41,7 @@ fn main() -> ! { load_lp_code!("../esp-lp-hal/target/riscv32imac-unknown-none-elf/release/examples/i2c"); // start LP core - lp_core_code.run(&mut lp_core, lp_core::LpCoreWakeupSource::HpCpu, lp_i2c); + lp_core_code.run(&mut lp_core, LpCoreWakeupSource::HpCpu, lp_i2c); println!("lpcore run"); loop {} diff --git a/esp32c6-hal/examples/lp_core_uart.rs b/examples/src/bin/lp_core_uart.rs similarity index 85% rename from esp32c6-hal/examples/lp_core_uart.rs rename to examples/src/bin/lp_core_uart.rs index a8bde0ac4..638668415 100644 --- a/esp32c6-hal/examples/lp_core_uart.rs +++ b/examples/src/bin/lp_core_uart.rs @@ -1,17 +1,20 @@ //! This shows a very basic example of running code on the LP core. //! //! Code on LP core uses LP_UART initialized on HP core. For more information -//! check `lp_core_uart` example in the `esp-lp-hal`. +//! check `lp_core_uart` example in the `esp-lp-hal. //! //! Make sure to first compile the `esp-lp-hal/examples/uart.rs` example +//% CHIPS: esp32c6 + #![no_std] #![no_main] -use esp32c6_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, gpio::lp_gpio::IntoLowPowerPin, - lp_core, + lp_core::{LpCore, LpCoreWakeupSource}, peripherals::Peripherals, prelude::*, uart::{ @@ -22,7 +25,6 @@ use esp32c6_hal::{ Uart, IO, }; -use esp_backtrace as _; use esp_println::println; #[entry] @@ -52,19 +54,18 @@ fn main() -> ! { // Set up (LP) UART: let lp_tx = io.pins.gpio5.into_low_power().into_push_pull_output(); let lp_rx = io.pins.gpio4.into_low_power().into_floating_input(); - let lp_uart = LpUart::new(peripherals.LP_UART, lp_tx, lp_rx); - let mut lp_core = esp32c6_hal::lp_core::LpCore::new(peripherals.LP_CORE); + let mut lp_core = LpCore::new(peripherals.LP_CORE); lp_core.stop(); println!("lp core stopped"); - // load code to LP core + // Load code to LP core: let lp_core_code = load_lp_code!("../esp-lp-hal/target/riscv32imac-unknown-none-elf/release/examples/uart"); - // start LP core - lp_core_code.run(&mut lp_core, lp_core::LpCoreWakeupSource::HpCpu, lp_uart); + // Start LP core: + lp_core_code.run(&mut lp_core, LpCoreWakeupSource::HpCpu, lp_uart); println!("lpcore run"); loop { diff --git a/esp32-hal/examples/mcpwm.rs b/examples/src/bin/mcpwm.rs similarity index 84% rename from esp32-hal/examples/mcpwm.rs rename to examples/src/bin/mcpwm.rs index bbc04ce39..aa94f94d7 100644 --- a/esp32-hal/examples/mcpwm.rs +++ b/examples/src/bin/mcpwm.rs @@ -1,19 +1,21 @@ //! Uses timer0 and operator0 of the MCPWM0 peripheral to output a 50% duty //! signal at 20 kHz. //! -//! The signal will be output to the pin assigned to `pin`. (GPIO4) +//! The signal will be output to the pin assigned to `pin`. (GPIO0) + +//% CHIPS: esp32 esp32c6 esp32h2 esp32s3 #![no_std] #![no_main] -use esp32_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, gpio::IO, mcpwm::{operator::PwmPinConfig, timer::PwmWorkingMode, PeripheralClockConfig, MCPWM}, peripherals::Peripherals, prelude::*, }; -use esp_backtrace as _; #[entry] fn main() -> ! { @@ -22,10 +24,14 @@ fn main() -> ! { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let pin = io.pins.gpio4; + let pin = io.pins.gpio0; // initialize peripheral + #[cfg(feature = "esp32h2")] let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 40u32.MHz()).unwrap(); + #[cfg(not(feature = "esp32h2"))] + let clock_cfg = PeripheralClockConfig::with_frequency(&clocks, 32u32.MHz()).unwrap(); + let mut mcpwm = MCPWM::new(peripherals.MCPWM0, clock_cfg); // connect operator0 to timer0 diff --git a/esp32-hal/examples/multicore.rs b/examples/src/bin/multicore.rs similarity index 81% rename from esp32-hal/examples/multicore.rs rename to examples/src/bin/multicore.rs index 0bc796f39..dc506beb1 100644 --- a/esp32-hal/examples/multicore.rs +++ b/examples/src/bin/multicore.rs @@ -1,21 +1,24 @@ //! This shows how to spawn a task on the second core. +//! //! The first core will print the value of a counter which is incremented by the //! second core. +//% CHIPS: esp32 esp32s3 + #![no_std] #![no_main] use core::cell::RefCell; use critical_section::Mutex; -use esp32_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, cpu_control::{CpuControl, Stack}, peripherals::{Peripherals, TIMG1}, prelude::*, timer::{Timer, Timer0, TimerGroup}, }; -use esp_backtrace as _; use esp_println::println; use nb::block; @@ -27,11 +30,11 @@ fn main() -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let mut timer0 = timg0.timer0; - let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks); - let mut timer1 = timer_group1.timer0; + let timg1 = TimerGroup::new(peripherals.TIMG1, &clocks); + let mut timer1 = timg1.timer0; timer0.start(1u64.secs()); timer1.start(500u64.millis()); @@ -54,10 +57,7 @@ fn main() -> ! { } } -fn cpu1_task( - timer: &mut Timer>, - counter: &critical_section::Mutex>, -) -> ! { +fn cpu1_task(timer: &mut Timer>, counter: &Mutex>) -> ! { println!("Hello World - Core 1!"); loop { block!(timer.wait()).unwrap(); diff --git a/esp32s3-hal/examples/octal_psram.rs b/examples/src/bin/octal_psram.rs similarity index 63% rename from esp32s3-hal/examples/octal_psram.rs rename to examples/src/bin/octal_psram.rs index e2b46563a..1916ba4d0 100644 --- a/esp32s3-hal/examples/octal_psram.rs +++ b/examples/src/bin/octal_psram.rs @@ -2,15 +2,20 @@ //! //! You need an ESP32-S3 with at least 2 MB of PSRAM memory. +//% CHIPS: esp32s3 +//% FEATURES: opsram-2m + #![no_std] #![no_main] -use esp32s3_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, psram}; -use esp_backtrace as _; -use esp_println::println; - extern crate alloc; +use alloc::{string::String, vec::Vec}; + +use esp_backtrace as _; +use esp_hal::{peripherals::Peripherals, prelude::*, psram}; +use esp_println::println; + #[global_allocator] static ALLOCATOR: esp_alloc::EspHeap = esp_alloc::EspHeap::empty(); @@ -23,22 +28,15 @@ fn init_psram_heap() { #[entry] fn main() -> ! { #[cfg(debug_assertions)] - compile_error!("PSRAM on ESP32-S3 needs to be built in release mode"); - - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); + compile_error!("This example MUST be built in release mode!"); let peripherals = Peripherals::take(); + psram::init_psram(peripherals.PSRAM); init_psram_heap(); - let system = peripherals.SYSTEM.split(); - let _clocks = - ClockControl::configure(system.clock_control, esp_hal::clock::CpuClock::Clock240MHz) - .freeze(); - println!("Going to access PSRAM"); - let mut large_vec: alloc::vec::Vec = alloc::vec::Vec::with_capacity(500 * 1024 / 4); + let mut large_vec: Vec = Vec::with_capacity(500 * 1024 / 4); for i in 0..(500 * 1024 / 4) { large_vec.push((i & 0xff) as u32); @@ -48,7 +46,7 @@ fn main() -> ! { println!("vec address = {:p}", large_vec.as_ptr()); println!("vec[..100] = {:?}", &large_vec[..100]); - let string = alloc::string::String::from("A string allocated in PSRAM"); + let string = String::from("A string allocated in PSRAM"); println!("'{}' allocated at {:p}", &string, string.as_ptr()); println!("done"); diff --git a/esp32h2-hal/examples/parl_io_rx.rs b/examples/src/bin/parl_io_rx.rs similarity index 97% rename from esp32h2-hal/examples/parl_io_rx.rs rename to examples/src/bin/parl_io_rx.rs index ddff6ac2c..2cf7afc3b 100644 --- a/esp32h2-hal/examples/parl_io_rx.rs +++ b/examples/src/bin/parl_io_rx.rs @@ -3,10 +3,13 @@ //! //! Uses GPIO 1, 2, 3 and 4 as the data pins. +//% CHIPS: esp32c6 esp32h2 + #![no_std] #![no_main] -use esp32h2_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, @@ -16,7 +19,6 @@ use esp32h2_hal::{ prelude::*, Delay, }; -use esp_backtrace as _; use esp_println::println; #[entry] diff --git a/esp32c6-hal/examples/parl_io_tx.rs b/examples/src/bin/parl_io_tx.rs similarity index 98% rename from esp32c6-hal/examples/parl_io_tx.rs rename to examples/src/bin/parl_io_tx.rs index 6a152c2dd..6e02af1db 100644 --- a/esp32c6-hal/examples/parl_io_tx.rs +++ b/examples/src/bin/parl_io_tx.rs @@ -7,10 +7,13 @@ //! //! You can use a logic analyzer to see how the pins are used. +//% CHIPS: esp32c6 esp32h2 + #![no_std] #![no_main] -use esp32c6_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, @@ -27,7 +30,6 @@ use esp32c6_hal::{ prelude::*, Delay, }; -use esp_backtrace as _; use esp_println::println; #[entry] diff --git a/esp32h2-hal/examples/pcnt_encoder.rs b/examples/src/bin/pcnt_encoder.rs similarity index 78% rename from esp32h2-hal/examples/pcnt_encoder.rs rename to examples/src/bin/pcnt_encoder.rs index 99e356c22..af402fdc3 100644 --- a/esp32h2-hal/examples/pcnt_encoder.rs +++ b/examples/src/bin/pcnt_encoder.rs @@ -6,8 +6,11 @@ //! we enable an interrupt on the upper and lower limits and //! track the overflow in an AtomicI32 +//% CHIPS: esp32 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] + use core::{ cell::RefCell, cmp::min, @@ -15,13 +18,11 @@ use core::{ }; use critical_section::Mutex; -use esp32h2_hal as esp_hal; use esp_backtrace as _; use esp_hal::{ - clock::ClockControl, - interrupt, + interrupt::{self, Priority}, pcnt::{channel, channel::PcntSource, unit, PCNT}, - peripherals::{self, Peripherals}, + peripherals::{Interrupt, Peripherals}, prelude::*, IO, }; @@ -33,15 +34,13 @@ static VALUE: AtomicI32 = AtomicI32::new(0); #[entry] fn main() -> ! { let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - let unit_number = unit::Number::Unit1; + let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - // setup a pulse couter + // Set up a pulse counter: println!("setup pulse counter unit 0"); let pcnt = PCNT::new(peripherals.PCNT); - let mut u0 = pcnt.get_unit(unit_number); + let mut u0 = pcnt.get_unit(unit::Number::Unit1); u0.configure(unit::Config { low_limit: -100, high_limit: 100, @@ -52,7 +51,6 @@ fn main() -> ! { println!("setup channel 0"); let mut ch0 = u0.get_channel(channel::Number::Channel0); - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); let mut pin_a = io.pins.gpio4.into_pull_up_input(); let mut pin_b = io.pins.gpio5.into_pull_up_input(); @@ -99,7 +97,7 @@ fn main() -> ! { critical_section::with(|cs| UNIT0.borrow_ref_mut(cs).replace(u0)); - interrupt::enable(peripherals::Interrupt::PCNT, interrupt::Priority::Priority2).unwrap(); + interrupt::enable(Interrupt::PCNT, Priority::Priority2).unwrap(); let mut last_value: i32 = 0; loop { @@ -115,8 +113,8 @@ fn main() -> ! { } } -#[interrupt] -fn PCNT() { +#[cfg(not(feature = "esp32s2"))] +fn interrupt_handler() { critical_section::with(|cs| { let mut u0 = UNIT0.borrow_ref_mut(cs); let u0 = u0.as_mut().unwrap(); @@ -131,3 +129,25 @@ fn PCNT() { } }); } + +#[cfg(feature = "esp32s2")] +fn interrupt_handler() { + critical_section::with(|cs| { + let mut u0 = UNIT0.borrow_ref_mut(cs); + let u0 = u0.as_mut().unwrap(); + if u0.interrupt_set() { + let events = u0.get_events(); + if events.high_limit { + VALUE.store(VALUE.load(Ordering::SeqCst) + 100, Ordering::SeqCst); + } else if events.low_limit { + VALUE.store(VALUE.load(Ordering::SeqCst) - 100, Ordering::SeqCst); + } + u0.reset_interrupt(); + } + }); +} + +#[interrupt] +fn PCNT() { + interrupt_handler(); +} diff --git a/esp32s3-hal/examples/psram.rs b/examples/src/bin/psram.rs similarity index 62% rename from esp32s3-hal/examples/psram.rs rename to examples/src/bin/psram.rs index e2b46563a..cc369fad8 100644 --- a/esp32s3-hal/examples/psram.rs +++ b/examples/src/bin/psram.rs @@ -1,16 +1,26 @@ //! This shows how to use PSRAM as heap-memory via esp-alloc //! -//! You need an ESP32-S3 with at least 2 MB of PSRAM memory. +//! You need an ESP32, ESP32-S2, or ESP32-S3 with at least 2 MB of PSRAM memory. + +//% CHIPS: esp32 esp32s2 esp32s3 +//% FEATURES: psram-2m #![no_std] #![no_main] -use esp32s3_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, psram}; -use esp_backtrace as _; -use esp_println::println; - extern crate alloc; +use alloc::{string::String, vec::Vec}; + +use esp_backtrace as _; +use esp_hal::{ + clock::{ClockControl, CpuClock}, + peripherals::Peripherals, + prelude::*, + psram, +}; +use esp_println::println; + #[global_allocator] static ALLOCATOR: esp_alloc::EspHeap = esp_alloc::EspHeap::empty(); @@ -23,22 +33,18 @@ fn init_psram_heap() { #[entry] fn main() -> ! { #[cfg(debug_assertions)] - compile_error!("PSRAM on ESP32-S3 needs to be built in release mode"); - - #[cfg(feature = "log")] - esp_println::logger::init_logger_from_env(); + compile_error!("PSRAM example must be built in release mode!"); let peripherals = Peripherals::take(); + psram::init_psram(peripherals.PSRAM); init_psram_heap(); let system = peripherals.SYSTEM.split(); - let _clocks = - ClockControl::configure(system.clock_control, esp_hal::clock::CpuClock::Clock240MHz) - .freeze(); + let _clocks = ClockControl::max(system.clock_control).freeze(); println!("Going to access PSRAM"); - let mut large_vec: alloc::vec::Vec = alloc::vec::Vec::with_capacity(500 * 1024 / 4); + let mut large_vec = Vec::::with_capacity(500 * 1024 / 4); for i in 0..(500 * 1024 / 4) { large_vec.push((i & 0xff) as u32); @@ -48,7 +54,7 @@ fn main() -> ! { println!("vec address = {:p}", large_vec.as_ptr()); println!("vec[..100] = {:?}", &large_vec[..100]); - let string = alloc::string::String::from("A string allocated in PSRAM"); + let string = String::from("A string allocated in PSRAM"); println!("'{}' allocated at {:p}", &string, string.as_ptr()); println!("done"); diff --git a/esp32s2-hal/examples/qspi_flash.rs b/examples/src/bin/qspi_flash.rs similarity index 78% rename from esp32s2-hal/examples/qspi_flash.rs rename to examples/src/bin/qspi_flash.rs index e16e6d307..3b919ce97 100644 --- a/esp32s2-hal/examples/qspi_flash.rs +++ b/examples/src/bin/qspi_flash.rs @@ -1,12 +1,20 @@ //! SPI write and read a flash chip //! //! Folowing pins are used: -//! SCLK GPIO4 -//! MISO/IO0 GPIO5 -//! MOSI/IO1 GPIO6 -//! IO2 GPIO7 -//! IO3 GPIO15 -//! CS GPIO16 +//! SCLK GPIO0 +//! MISO/IO0 GPIO1 +//! MOSI/IO1 GPIO2 +//! IO2 GPIO3 +//! IO3 GPIO4 +//! CS GPIO5 +//! +//! Folowing pins are used for ESP32: +//! SCLK GPIO0 +//! MISO/IO0 GPIO2 +//! MOSI/IO1 GPIO4 +//! IO2 GPIO5 +//! IO3 GPIO13 +//! CS GPIO14 //! //! Depending on your target and the board you are using you have to change the //! pins. @@ -14,10 +22,13 @@ //! Connect a flash chip (GD25Q64C was used) and make sure QE in the status //! register is set. +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] -use esp32s2_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, @@ -31,7 +42,6 @@ use esp32s2_hal::{ }, Delay, }; -use esp_backtrace as _; use esp_println::{print, println}; #[entry] @@ -41,15 +51,29 @@ fn main() -> ! { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio4; - let miso = io.pins.gpio5; - let mosi = io.pins.gpio6; - let sio2 = io.pins.gpio7; - let sio3 = io.pins.gpio15; - let cs = io.pins.gpio16; + cfg_if::cfg_if! { + if #[cfg(feature = "esp32")] { + let sclk = io.pins.gpio0; + let miso = io.pins.gpio2; + let mosi = io.pins.gpio4; + let sio2 = io.pins.gpio5; + let sio3 = io.pins.gpio13; + let cs = io.pins.gpio14; + } else { + let sclk = io.pins.gpio0; + let miso = io.pins.gpio1; + let mosi = io.pins.gpio2; + let sio2 = io.pins.gpio3; + let sio3 = io.pins.gpio4; + let cs = io.pins.gpio5; + } + } let dma = Dma::new(peripherals.DMA); + #[cfg(any(feature = "esp32", feature = "esp32s2"))] let dma_channel = dma.spi2channel; + #[cfg(not(any(feature = "esp32", feature = "esp32s2")))] + let dma_channel = dma.channel0; let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(256, 320); diff --git a/esp32c3-hal/examples/ram.rs b/examples/src/bin/ram.rs similarity index 89% rename from esp32c3-hal/examples/ram.rs rename to examples/src/bin/ram.rs index 571f6efb4..028c387ca 100644 --- a/esp32c3-hal/examples/ram.rs +++ b/examples/src/bin/ram.rs @@ -1,14 +1,23 @@ //! This shows how to use RTC memory. +//! //! RTC memory is retained during resets and during most sleep modes. +//! //! Initialized memory is always re-initialized on startup. +//! //! Uninitialzed memory isn't initialized on startup and can be used to keep -//! data during resets. Zeroed memory is initialized to zero on startup. +//! data during resets. +//! +//! Zeroed memory is initialized to zero on startup. +//! //! We can also run code from RTC memory. +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] -use esp32c3_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, macros::ram, peripherals::Peripherals, @@ -16,7 +25,6 @@ use esp32c3_hal::{ timer::TimerGroup, Rtc, }; -use esp_backtrace as _; use esp_println::println; use nb::block; @@ -35,8 +43,8 @@ fn main() -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let mut timer0 = timg0.timer0; // The RWDT flash boot protection must be enabled, as it is triggered as part of // the example. diff --git a/examples/src/bin/read_efuse.rs b/examples/src/bin/read_efuse.rs new file mode 100644 index 000000000..b3d7163ec --- /dev/null +++ b/examples/src/bin/read_efuse.rs @@ -0,0 +1,29 @@ +//! This shows how to read selected information from eFuses. +//! +//! Depending on which chip is being targeted, certain efuses may or may not be +//! available. + +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + +#![no_std] +#![no_main] + +use esp_backtrace as _; +use esp_hal::{efuse::Efuse, prelude::*}; +use esp_println::println; + +#[entry] +fn main() -> ! { + println!("MAC address {:02x?}", Efuse::get_mac_address()); + println!("Flash Encryption {:?}", Efuse::get_flash_encryption()); + + #[cfg(feature = "esp32")] + { + println!("Core Count {}", Efuse::get_core_count()); + println!("Bluetooth enabled {}", Efuse::is_bluetooth_enabled()); + println!("Chip type {:?}", Efuse::get_chip_type()); + println!("Max CPU clock {:?}", Efuse::get_max_cpu_frequency()); + } + + loop {} +} diff --git a/examples/src/bin/rmt_rx.rs b/examples/src/bin/rmt_rx.rs new file mode 100644 index 000000000..d2a55ca91 --- /dev/null +++ b/examples/src/bin/rmt_rx.rs @@ -0,0 +1,131 @@ +//! Demonstrates decoding pulse sequences with RMT +//! Connect GPIO5 to GPIO4 + +//% CHIPS: esp32 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + +#![no_std] +#![no_main] + +use esp_backtrace as _; +use esp_hal::{ + clock::ClockControl, + gpio::IO, + peripherals::Peripherals, + prelude::*, + rmt::{PulseCode, RxChannel, RxChannelConfig, RxChannelCreator}, + Delay, + Rmt, +}; +use esp_println::{print, println}; + +const WIDTH: usize = 80; + +#[entry] +fn main() -> ! { + let peripherals = Peripherals::take(); + let system = peripherals.SYSTEM.split(); + let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + + let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); + let mut out = io.pins.gpio5.into_push_pull_output(); + + cfg_if::cfg_if! { + if #[cfg(feature = "esp32h2")] { + let freq = 32u32.MHz(); + } else { + let freq = 80u32.MHz(); + } + }; + + let rmt = Rmt::new(peripherals.RMT, freq, &clocks).unwrap(); + + let rx_config = RxChannelConfig { + clk_divider: 1, + idle_threshold: 10000, + ..RxChannelConfig::default() + }; + + cfg_if::cfg_if! { + if #[cfg(any(feature = "esp32", feature = "esp32s2"))] { + let mut channel = rmt.channel0.configure(io.pins.gpio4, rx_config).unwrap(); + } else if #[cfg(feature = "esp32s3")] { + let mut channel = rmt.channel7.configure(io.pins.gpio4, rx_config).unwrap(); + } else { + let mut channel = rmt.channel2.configure(io.pins.gpio4, rx_config).unwrap(); + } + } + + let mut delay = Delay::new(&clocks); + + let mut data = [PulseCode { + level1: true, + length1: 1, + level2: false, + length2: 1, + }; 48]; + + loop { + for x in data.iter_mut() { + x.length1 = 0; + x.length2 = 0; + } + + let transaction = channel.receive(&mut data).unwrap(); + + // simulate input + for i in 0u32..5u32 { + out.set_high().unwrap(); + delay.delay_us(i * 10 + 20); + out.set_low().unwrap(); + delay.delay_us(i * 20 + 20); + } + + match transaction.wait() { + Ok(channel_res) => { + channel = channel_res; + let mut total = 0usize; + for entry in &data[..data.len()] { + if entry.length1 == 0 { + break; + } + total += entry.length1 as usize; + + if entry.length2 == 0 { + break; + } + total += entry.length2 as usize; + } + + for entry in &data[..data.len()] { + if entry.length1 == 0 { + break; + } + + let count = WIDTH / (total / entry.length1 as usize); + let c = if entry.level1 { '-' } else { '_' }; + for _ in 0..count + 1 { + print!("{}", c); + } + + if entry.length2 == 0 { + break; + } + + let count = WIDTH / (total / entry.length2 as usize); + let c = if entry.level2 { '-' } else { '_' }; + for _ in 0..count + 1 { + print!("{}", c); + } + } + + println!(); + } + Err((_err, channel_res)) => { + channel = channel_res; + println!("Error"); + } + } + + delay.delay_ms(1500u32); + } +} diff --git a/esp32-hal/examples/rmt_tx.rs b/examples/src/bin/rmt_tx.rs similarity index 68% rename from esp32-hal/examples/rmt_tx.rs rename to examples/src/bin/rmt_tx.rs index 99ed38e74..9cf505e80 100644 --- a/esp32-hal/examples/rmt_tx.rs +++ b/examples/src/bin/rmt_tx.rs @@ -1,10 +1,14 @@ //! Demonstrates generating pulse sequences with RMT +//! //! Connect a logic analyzer to GPIO4 to see the generated pulses. +//% CHIPS: esp32 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] -use esp32_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, gpio::IO, peripherals::Peripherals, @@ -13,7 +17,6 @@ use esp32_hal::{ Delay, Rmt, }; -use esp_backtrace as _; #[entry] fn main() -> ! { @@ -23,18 +26,22 @@ fn main() -> ! { let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let rmt = Rmt::new(peripherals.RMT, 80u32.MHz(), &clocks).unwrap(); + cfg_if::cfg_if! { + if #[cfg(feature = "esp32h2")] { + let freq = 32u32.MHz(); + } else { + let freq = 80u32.MHz(); + } + }; - let mut channel = rmt - .channel0 - .configure( - io.pins.gpio4, - TxChannelConfig { - clk_divider: 255, - ..TxChannelConfig::default() - }, - ) - .unwrap(); + let rmt = Rmt::new(peripherals.RMT, freq, &clocks).unwrap(); + + let tx_config = TxChannelConfig { + clk_divider: 255, + ..TxChannelConfig::default() + }; + + let mut channel = rmt.channel0.configure(io.pins.gpio4, tx_config).unwrap(); let mut delay = Delay::new(&clocks); diff --git a/esp32-hal/examples/rng.rs b/examples/src/bin/rng.rs similarity index 65% rename from esp32-hal/examples/rng.rs rename to examples/src/bin/rng.rs index c76db67a1..23b0ccf04 100644 --- a/esp32-hal/examples/rng.rs +++ b/examples/src/bin/rng.rs @@ -1,19 +1,17 @@ //! Demonstrates the use of the hardware Random Number Generator (RNG) +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] -use esp32_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Rng}; use esp_backtrace as _; +use esp_hal::{peripherals::Peripherals, prelude::*, Rng}; use esp_println::println; #[entry] fn main() -> ! { let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - - // Instantiate the Random Number Generator peripheral: let mut rng = Rng::new(peripherals.RNG); // Generate a random word (u32): diff --git a/esp32s3-hal/examples/rsa.rs b/examples/src/bin/rsa.rs similarity index 73% rename from esp32s3-hal/examples/rsa.rs rename to examples/src/bin/rsa.rs index 42998f7b7..5e9c7cf7c 100644 --- a/esp32s3-hal/examples/rsa.rs +++ b/examples/src/bin/rsa.rs @@ -1,6 +1,8 @@ //! Demonstrates the use of the RSA peripheral and compares the speed of //! multiple arithmetic operations. +//% CHIPS: esp32 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] @@ -10,8 +12,8 @@ use crypto_bigint::{ U1024, U512, }; -use esp32s3_hal::{ - clock::ClockControl, +use esp_backtrace as _; +use esp_hal::{ peripherals::Peripherals, prelude::*, rsa::{ @@ -21,10 +23,9 @@ use esp32s3_hal::{ RsaModularMultiplication, RsaMultiplication, }, - xtensa_lx, }; -use esp_backtrace as _; use esp_println::println; +use examples::cycles; const BIGNUM_1: U512 = Uint::from_be_hex( "c7f61058f96db3bd87dbab08ab03b4f7f2f864eac249144adea6a65f97803b719d8ca980b7b3c0389c1c7c6\ @@ -54,12 +55,10 @@ const fn compute_mprime(modulus: &U512) -> u32 { #[entry] fn main() -> ! { let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let mut rsa = Rsa::new(peripherals.RSA); - nb::block!(rsa.ready()).unwrap(); + mod_exp_example(&mut rsa); mod_multi_example(&mut rsa); multiplication_example(&mut rsa); @@ -71,26 +70,37 @@ fn mod_multi_example(rsa: &mut Rsa) { let mut outbuf = [0_u32; U512::LIMBS]; let mut mod_multi = RsaModularMultiplication::::new( rsa, + #[cfg(not(feature = "esp32"))] BIGNUM_1.as_words(), + #[cfg(not(feature = "esp32"))] BIGNUM_2.as_words(), BIGNUM_3.as_words(), compute_mprime(&BIGNUM_3), ); let r = compute_r(&BIGNUM_3); - let pre_hw_modmul = xtensa_lx::timer::get_cycle_count(); - mod_multi.start_modular_multiplication(r.as_words()); + let pre_hw_modmul = cycles(); + #[cfg(feature = "esp32")] + { + mod_multi.start_step1(BIGNUM_1.as_words(), r.as_words()); + mod_multi.start_step2(BIGNUM_2.as_words()); + } + #[cfg(not(feature = "esp32"))] + { + mod_multi.start_modular_multiplication(r.as_words()); + } mod_multi.read_results(&mut outbuf); - let post_hw_modmul = xtensa_lx::timer::get_cycle_count(); + let post_hw_modmul = cycles(); println!( "it took {} cycles for hw modular multiplication", post_hw_modmul - pre_hw_modmul ); + let residue_params = DynResidueParams::new(&BIGNUM_3); let residue_num1 = DynResidue::new(&BIGNUM_1, residue_params); let residue_num2 = DynResidue::new(&BIGNUM_2, residue_params); - let pre_sw_exp = xtensa_lx::timer::get_cycle_count(); + let pre_sw_exp = cycles(); let sw_out = residue_num1.mul(&residue_num2); - let post_sw_exp = xtensa_lx::timer::get_cycle_count(); + let post_sw_exp = cycles(); println!( "it took {} cycles for sw modular multiplication", post_sw_exp - pre_sw_exp @@ -100,8 +110,12 @@ fn mod_multi_example(rsa: &mut Rsa) { } fn mod_exp_example(rsa: &mut Rsa) { - rsa.enable_disable_constant_time_acceleration(true); - rsa.enable_disable_search_acceleration(true); + #[cfg(not(feature = "esp32"))] + { + rsa.enable_disable_constant_time_acceleration(true); + rsa.enable_disable_search_acceleration(true); + } + let mut outbuf = [0_u32; U512::LIMBS]; let mut mod_exp = RsaModularExponentiation::::new( rsa, @@ -111,19 +125,19 @@ fn mod_exp_example(rsa: &mut Rsa) { ); let r = compute_r(&BIGNUM_3); let base = &BIGNUM_1.as_words(); - let pre_hw_exp = xtensa_lx::timer::get_cycle_count(); + let pre_hw_exp = cycles(); mod_exp.start_exponentiation(&base, r.as_words()); mod_exp.read_results(&mut outbuf); - let post_hw_exp = xtensa_lx::timer::get_cycle_count(); + let post_hw_exp = cycles(); println!( "it took {} cycles for hw modular exponentiation", post_hw_exp - pre_hw_exp ); let residue_params = DynResidueParams::new(&BIGNUM_3); let residue = DynResidue::new(&BIGNUM_1, residue_params); - let pre_sw_exp = xtensa_lx::timer::get_cycle_count(); + let pre_sw_exp = cycles(); let sw_out = residue.pow(&BIGNUM_2); - let post_sw_exp = xtensa_lx::timer::get_cycle_count(); + let post_sw_exp = cycles(); println!( "it took {} cycles for sw modular exponentiation", post_sw_exp - pre_sw_exp @@ -134,20 +148,33 @@ fn mod_exp_example(rsa: &mut Rsa) { fn multiplication_example(rsa: &mut Rsa) { let mut out = [0_u32; U1024::LIMBS]; + let operand_a = BIGNUM_1.as_words(); let operand_b = BIGNUM_2.as_words(); - let mut rsamulti = RsaMultiplication::::new(rsa, operand_a); - let pre_hw_mul = xtensa_lx::timer::get_cycle_count(); - rsamulti.start_multiplication(operand_b); - rsamulti.read_results(&mut out); - let post_hw_mul = xtensa_lx::timer::get_cycle_count(); + + let pre_hw_mul = cycles(); + + #[cfg(feature = "esp32")] + { + let mut rsamulti = RsaMultiplication::::new(rsa); + rsamulti.start_multiplication(operand_a, operand_b); + rsamulti.read_results(&mut out); + } + #[cfg(not(feature = "esp32"))] + { + let mut rsamulti = RsaMultiplication::::new(rsa, operand_a); + rsamulti.start_multiplication(operand_b); + rsamulti.read_results(&mut out); + } + + let post_hw_mul = cycles(); println!( "it took {} cycles for hw multiplication", post_hw_mul - pre_hw_mul ); - let pre_sw_mul = xtensa_lx::timer::get_cycle_count(); + let pre_sw_mul = cycles(); let sw_out = BIGNUM_1.mul_wide(&BIGNUM_2); - let post_sw_mul = xtensa_lx::timer::get_cycle_count(); + let post_sw_mul = cycles(); println!( "it took {} cycles for sw multiplication", post_sw_mul - pre_sw_mul diff --git a/esp32-hal/examples/rtc_time.rs b/examples/src/bin/rtc_time.rs similarity index 77% rename from esp32-hal/examples/rtc_time.rs rename to examples/src/bin/rtc_time.rs index e0ff2da49..a9caa4650 100644 --- a/esp32-hal/examples/rtc_time.rs +++ b/examples/src/bin/rtc_time.rs @@ -1,10 +1,12 @@ //! Prints time in milliseconds from the RTC Timer +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] -use esp32_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Delay, Rtc}; use esp_backtrace as _; +use esp_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, Delay, Rtc}; #[entry] fn main() -> ! { @@ -13,7 +15,6 @@ fn main() -> ! { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let rtc = Rtc::new(peripherals.LPWR); - let mut delay = Delay::new(&clocks); loop { diff --git a/esp32c2-hal/examples/rtc_watchdog.rs b/examples/src/bin/rtc_watchdog.rs similarity index 63% rename from esp32c2-hal/examples/rtc_watchdog.rs rename to examples/src/bin/rtc_watchdog.rs index aeb2df903..87cd922b3 100644 --- a/esp32c2-hal/examples/rtc_watchdog.rs +++ b/examples/src/bin/rtc_watchdog.rs @@ -1,55 +1,52 @@ //! This demos the RTC Watchdog Timer (RWDT). +//! //! The RWDT is initially configured to trigger an interrupt after a given //! timeout. Then, upon expiration, the RWDT is restarted and then reconfigured //! to reset both the main system and the RTC. +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] use core::cell::RefCell; use critical_section::Mutex; -use esp32c2_hal::{ - clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, +use esp_backtrace as _; +use esp_hal::{ + interrupt::{self, Priority}, + peripherals::{Interrupt, Peripherals}, prelude::*, Rtc, Rwdt, }; -use esp_backtrace as _; static RWDT: Mutex>> = Mutex::new(RefCell::new(None)); #[entry] fn main() -> ! { let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let mut rtc = Rtc::new(peripherals.LPWR); rtc.rwdt.start(2000u64.millis()); rtc.rwdt.listen(); - interrupt::enable( - peripherals::Interrupt::RTC_CORE, - interrupt::Priority::Priority1, - ) - .unwrap(); - critical_section::with(|cs| RWDT.borrow_ref_mut(cs).replace(rtc.rwdt)); + #[cfg(any(feature = "esp32c6", feature = "esp32h2"))] + interrupt::enable(Interrupt::LP_WDT, Priority::Priority1).unwrap(); + #[cfg(not(any(feature = "esp32c6", feature = "esp32h2")))] + interrupt::enable(Interrupt::RTC_CORE, Priority::Priority1).unwrap(); + loop {} } -#[interrupt] -fn RTC_CORE() { +fn interrupt_handler() { critical_section::with(|cs| { esp_println::println!("RWDT Interrupt"); let mut rwdt = RWDT.borrow_ref_mut(cs); let rwdt = rwdt.as_mut().unwrap(); - rwdt.clear_interrupt(); esp_println::println!("Restarting in 5 seconds..."); @@ -58,3 +55,15 @@ fn RTC_CORE() { rwdt.unlisten(); }); } + +#[cfg(any(feature = "esp32c6", feature = "esp32h2"))] +#[interrupt] +fn LP_WDT() { + interrupt_handler(); +} + +#[cfg(not(any(feature = "esp32c6", feature = "esp32h2")))] +#[interrupt] +fn RTC_CORE() { + interrupt_handler(); +} diff --git a/esp32s3-hal/examples/serial_interrupts.rs b/examples/src/bin/serial_interrupts.rs similarity index 86% rename from esp32s3-hal/examples/serial_interrupts.rs rename to examples/src/bin/serial_interrupts.rs index 3e4fb25c9..fc5c7a1ed 100644 --- a/esp32s3-hal/examples/serial_interrupts.rs +++ b/examples/src/bin/serial_interrupts.rs @@ -2,22 +2,24 @@ //! Use a proper serial terminal to connect to the board (espmonitor and //! espflash won't work) +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] use core::{cell::RefCell, fmt::Write}; use critical_section::Mutex; -use esp32s3_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, - interrupt, - peripherals::{self, Peripherals, UART0}, + interrupt::{self, Priority}, + peripherals::{Interrupt, Peripherals, UART0}, prelude::*, timer::TimerGroup, uart::config::AtCmdConfig, Uart, }; -use esp_backtrace as _; use nb::block; static SERIAL: Mutex>>> = Mutex::new(RefCell::new(None)); @@ -28,8 +30,8 @@ fn main() -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let mut timer0 = timg0.timer0; let mut uart0 = Uart::new(peripherals.UART0, &clocks); uart0.set_at_cmd(AtCmdConfig::new(None, None, None, b'#', None)); @@ -37,11 +39,7 @@ fn main() -> ! { uart0.listen_at_cmd(); uart0.listen_rx_fifo_full(); - interrupt::enable( - peripherals::Interrupt::UART0, - interrupt::Priority::Priority2, - ) - .unwrap(); + interrupt::enable(Interrupt::UART0, Priority::Priority2).unwrap(); timer0.start(1u64.secs()); diff --git a/esp32c2-hal/examples/sha.rs b/examples/src/bin/sha.rs similarity index 77% rename from esp32c2-hal/examples/sha.rs rename to examples/src/bin/sha.rs index 9a9017ff3..bd2537c3c 100644 --- a/esp32c2-hal/examples/sha.rs +++ b/examples/src/bin/sha.rs @@ -1,25 +1,25 @@ //! Demonstrates the use of the SHA peripheral and compares the speed of //! hardware-accelerated and pure software hashing. +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] -use esp32c2_hal::{ - clock::ClockControl, +use esp_backtrace as _; +use esp_hal::{ peripherals::Peripherals, prelude::*, sha::{Sha, ShaMode}, }; -use esp_backtrace as _; use esp_println::println; +use examples::cycles; use nb::block; use sha2::{Digest, Sha256}; #[entry] fn main() -> ! { let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let source_data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".as_bytes(); let mut remaining = source_data; @@ -29,7 +29,7 @@ fn main() -> ! { // length let mut output = [0u8; 32]; - // let pre_calc = xtensa_lx::timer::get_cycle_count(); + let pre_calc = cycles(); // The hardware implementation takes a subslice of the input, and returns the // unprocessed parts The unprocessed parts can be input in the next // iteration, you can always add more data until finish() is called. After @@ -50,22 +50,23 @@ fn main() -> ! { // Finish can be called as many times as desired to get mutliple copies of the // output. block!(hasher.finish(output.as_mut_slice())).unwrap(); - // let post_calc = xtensa_lx::timer::get_cycle_count(); - // let hw_time = post_calc - pre_calc; - // println!("Took {} cycles", hw_time); + + let post_calc = cycles(); + let hw_time = post_calc - pre_calc; + println!("Took {} cycles", hw_time); println!("SHA256 Hash output {:02x?}", output); - // let pre_calc = xtensa_lx::timer::get_cycle_count(); + let pre_calc = cycles(); let mut hasher = Sha256::new(); hasher.update(source_data); let soft_result = hasher.finalize(); - // let post_calc = xtensa_lx::timer::get_cycle_count(); - // let soft_time = post_calc - pre_calc; - // println!("Took {} cycles", soft_time); + let post_calc = cycles(); + let soft_time = post_calc - pre_calc; + println!("Took {} cycles", soft_time); println!("SHA256 Hash output {:02x?}", soft_result); assert_eq!(output, soft_result[..]); - // println!("HW SHA is {}x faster", soft_time/hw_time); + println!("HW SHA is {}x faster", soft_time / hw_time); loop {} } diff --git a/esp32c6-hal/examples/sleep_lpio.rs b/examples/src/bin/sleep_lpio.rs similarity index 97% rename from esp32c6-hal/examples/sleep_lpio.rs rename to examples/src/bin/sleep_lpio.rs index 164d460e4..c30b921b2 100644 --- a/esp32c6-hal/examples/sleep_lpio.rs +++ b/examples/src/bin/sleep_lpio.rs @@ -1,9 +1,12 @@ //! Demonstrates deep sleep with gpio2 (low) and gpio3 (high) as wakeup sources. +//% CHIPS: esp32c6 + #![no_std] #![no_main] -use esp32c6_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, entry, gpio::RTCPinWithResistors, @@ -20,7 +23,6 @@ use esp32c6_hal::{ Rtc, IO, }; -use esp_backtrace as _; use esp_println::println; #[entry] diff --git a/esp32c3-hal/examples/sleep_timer.rs b/examples/src/bin/sleep_timer.rs similarity index 89% rename from esp32c3-hal/examples/sleep_timer.rs rename to examples/src/bin/sleep_timer.rs index 760ddd8e4..8c0c474b1 100644 --- a/esp32c3-hal/examples/sleep_timer.rs +++ b/examples/src/bin/sleep_timer.rs @@ -1,11 +1,14 @@ //! Demonstrates deep sleep with timer wakeup +//% CHIPS: esp32 esp32c3 esp32s3 + #![no_std] #![no_main] use core::time::Duration; -use esp32c3_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, entry, peripherals::Peripherals, @@ -15,7 +18,6 @@ use esp32c3_hal::{ Delay, Rtc, }; -use esp_backtrace as _; use esp_println::println; #[entry] @@ -24,6 +26,7 @@ fn main() -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let mut delay = Delay::new(&clocks); let mut rtc = Rtc::new(peripherals.LPWR); println!("up and runnning!"); @@ -32,9 +35,7 @@ fn main() -> ! { let wake_reason = get_wakeup_cause(); println!("wake reason: {:?}", wake_reason); - let mut delay = Delay::new(&clocks); - - let timer = TimerWakeupSource::new(Duration::from_secs(30)); + let timer = TimerWakeupSource::new(Duration::from_secs(5)); println!("sleeping!"); delay.delay_ms(100u32); rtc.sleep_deep(&[&timer], &mut delay); diff --git a/esp32s3-hal/examples/sleep_timer_ext0.rs b/examples/src/bin/sleep_timer_ext0.rs similarity index 89% rename from esp32s3-hal/examples/sleep_timer_ext0.rs rename to examples/src/bin/sleep_timer_ext0.rs index 9210a6a26..38f7397e0 100644 --- a/esp32s3-hal/examples/sleep_timer_ext0.rs +++ b/examples/src/bin/sleep_timer_ext0.rs @@ -1,11 +1,14 @@ -//! Demonstrates deep sleep with timer and ext0 (using gpio18) wakeup +//! Demonstrates deep sleep with timer and ext0 (using gpio4) wakeup + +//% CHIPS: esp32 esp32s3 #![no_std] #![no_main] use core::time::Duration; -use esp32s3_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, entry, peripherals::Peripherals, @@ -21,7 +24,6 @@ use esp32s3_hal::{ Rtc, IO, }; -use esp_backtrace as _; use esp_println::println; #[entry] @@ -33,7 +35,7 @@ fn main() -> ! { let mut rtc = Rtc::new(peripherals.LPWR); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut ext0_pin = io.pins.gpio18; + let mut ext0_pin = io.pins.gpio4; println!("up and runnning!"); let reason = get_reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn); diff --git a/esp32s3-hal/examples/sleep_timer_ext1.rs b/examples/src/bin/sleep_timer_ext1.rs similarity index 82% rename from esp32s3-hal/examples/sleep_timer_ext1.rs rename to examples/src/bin/sleep_timer_ext1.rs index 61cf56e75..ee2b8df26 100644 --- a/esp32s3-hal/examples/sleep_timer_ext1.rs +++ b/examples/src/bin/sleep_timer_ext1.rs @@ -1,11 +1,14 @@ -//! Demonstrates deep sleep with timer and ext1 (using gpio18 & gpio19) wakeup +//! Demonstrates deep sleep with timer and ext1 (using gpio4 & gpio2) wakeup + +//% CHIPS: esp32 esp32s3 #![no_std] #![no_main] use core::time::Duration; -use esp32s3_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, entry, gpio::{RTCPin, IO}, @@ -21,7 +24,6 @@ use esp32s3_hal::{ Delay, Rtc, }; -use esp_backtrace as _; use esp_println::println; #[entry] @@ -33,8 +35,8 @@ fn main() -> ! { let mut rtc = Rtc::new(peripherals.LPWR); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut pin18 = io.pins.gpio18; - let mut pin19 = io.pins.gpio19; + let mut pin_0 = io.pins.gpio4; + let mut pin_2 = io.pins.gpio2; println!("up and runnning!"); let reason = get_reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn); @@ -45,7 +47,7 @@ fn main() -> ! { let mut delay = Delay::new(&clocks); let timer = TimerWakeupSource::new(Duration::from_secs(30)); - let mut wakeup_pins: [&mut dyn RTCPin; 2] = [&mut pin18, &mut pin19]; + let mut wakeup_pins: [&mut dyn RTCPin; 2] = [&mut pin_0, &mut pin_2]; let ext1 = Ext1WakeupSource::new(&mut wakeup_pins, WakeupLevel::High); println!("sleeping!"); delay.delay_ms(100u32); diff --git a/esp32c3-hal/examples/sleep_timer_rtcio.rs b/examples/src/bin/sleep_timer_rtcio.rs similarity index 67% rename from esp32c3-hal/examples/sleep_timer_rtcio.rs rename to examples/src/bin/sleep_timer_rtcio.rs index b181936ba..32eca3e12 100644 --- a/esp32c3-hal/examples/sleep_timer_rtcio.rs +++ b/examples/src/bin/sleep_timer_rtcio.rs @@ -1,15 +1,18 @@ -//! Demonstrates deep sleep with timer, using gpio2 (low) and gpio3 (high) as +//! Demonstrates deep sleep with timer, using GPIO2 (low) and GPIO3 (high) as //! wakeup. +//% CHIPS: esp32c3 esp32s3 + #![no_std] #![no_main] use core::time::Duration; -use esp32c3_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, entry, - gpio::RTCPinWithResistors, + gpio, peripherals::Peripherals, prelude::*, rtc_cntl::{ @@ -23,7 +26,6 @@ use esp32c3_hal::{ Rtc, IO, }; -use esp_backtrace as _; use esp_println::println; #[entry] @@ -32,12 +34,9 @@ fn main() -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let mut io = IO::new(peripherals.GPIO, peripherals.IO_MUX); let mut rtc = Rtc::new(peripherals.LPWR); - let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let mut pin2 = io.pins.gpio2; - let mut pin3 = io.pins.gpio3; - println!("up and runnning!"); let reason = get_reset_reason(Cpu::ProCpu).unwrap_or(SocResetReason::ChipPowerOn); println!("reset reason: {:?}", reason); @@ -46,11 +45,17 @@ fn main() -> ! { let mut delay = Delay::new(&clocks); let timer = TimerWakeupSource::new(Duration::from_secs(10)); - let wakeup_pins: &mut [(&mut dyn RTCPinWithResistors, WakeupLevel)] = &mut [ - (&mut pin2, WakeupLevel::Low), - (&mut pin3, WakeupLevel::High), + + #[cfg(feature = "esp32c3")] + let wakeup_pins: &mut [(&mut dyn gpio::RTCPinWithResistors, WakeupLevel)] = &mut [ + (&mut io.pins.gpio2, WakeupLevel::Low), + (&mut io.pins.gpio3, WakeupLevel::High), ]; + #[cfg(feature = "esp32s3")] + let mut wakeup_pins: &mut [(&mut dyn gpio::RTCPin, WakeupLevel)] = + &mut [(&mut io.pins.gpio18, WakeupLevel::Low)]; + let rtcio = RtcioWakeupSource::new(wakeup_pins); println!("sleeping!"); delay.delay_ms(100u32); diff --git a/esp32-hal/examples/software_interrupts.rs b/examples/src/bin/software_interrupts.rs similarity index 84% rename from esp32-hal/examples/software_interrupts.rs rename to examples/src/bin/software_interrupts.rs index 29eb3670a..d35ca8c95 100644 --- a/esp32-hal/examples/software_interrupts.rs +++ b/examples/src/bin/software_interrupts.rs @@ -4,21 +4,23 @@ //! Should rotate through all of the available interrupts printing their number //! when raised. +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] use core::cell::RefCell; use critical_section::Mutex; -use esp32_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, - interrupt::{self}, - peripherals::{self, Peripherals}, + interrupt::{self, Priority}, + peripherals::{Interrupt, Peripherals}, prelude::*, system::{SoftwareInterrupt, SoftwareInterruptControl}, Delay, }; -use esp_backtrace as _; static SWINT: Mutex>> = Mutex::new(RefCell::new(None)); @@ -26,33 +28,19 @@ static SWINT: Mutex>> = Mutex::new(RefC fn main() -> ! { let peripherals = Peripherals::take(); let system = peripherals.SYSTEM.split(); - let sw_int = system.software_interrupt_control; let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); + let sw_int = system.software_interrupt_control; critical_section::with(|cs| SWINT.borrow_ref_mut(cs).replace(sw_int)); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR0, - interrupt::Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR1, - interrupt::Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR2, - interrupt::Priority::Priority3, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::FROM_CPU_INTR3, - interrupt::Priority::Priority3, - ) - .unwrap(); + interrupt::enable(Interrupt::FROM_CPU_INTR0, Priority::Priority3).unwrap(); + interrupt::enable(Interrupt::FROM_CPU_INTR1, Priority::Priority3).unwrap(); + interrupt::enable(Interrupt::FROM_CPU_INTR2, Priority::Priority3).unwrap(); + interrupt::enable(Interrupt::FROM_CPU_INTR3, Priority::Priority3).unwrap(); + let mut delay = Delay::new(&clocks); let mut counter = 0; + loop { delay.delay_ms(500u32); match counter { @@ -104,6 +92,7 @@ fn FROM_CPU_INTR0() { .reset(SoftwareInterrupt::SoftwareInterrupt0); }); } + #[interrupt] fn FROM_CPU_INTR1() { esp_println::println!("SW interrupt1"); @@ -115,6 +104,7 @@ fn FROM_CPU_INTR1() { .reset(SoftwareInterrupt::SoftwareInterrupt1); }); } + #[interrupt] fn FROM_CPU_INTR2() { esp_println::println!("SW interrupt2"); @@ -126,6 +116,7 @@ fn FROM_CPU_INTR2() { .reset(SoftwareInterrupt::SoftwareInterrupt2); }); } + #[interrupt] fn FROM_CPU_INTR3() { esp_println::println!("SW interrupt3"); diff --git a/esp32c2-hal/examples/spi_eh1_device_loopback.rs b/examples/src/bin/spi_eh1_device_loopback.rs similarity index 79% rename from esp32c2-hal/examples/spi_eh1_device_loopback.rs rename to examples/src/bin/spi_eh1_device_loopback.rs index c7d9dfa01..e0ca08141 100644 --- a/esp32c2-hal/examples/spi_eh1_device_loopback.rs +++ b/examples/src/bin/spi_eh1_device_loopback.rs @@ -1,12 +1,20 @@ //! SPI loopback test //! //! Folowing pins are used: -//! SCLK GPIO6 +//! SCLK GPIO0 //! MISO GPIO2 -//! MOSI GPIO7 -//! CS 1 GPIO3 -//! CS 2 GPIO4 -//! CS 3 GPIO5 +//! MOSI GPIO4 +//! CS 1 GPIO5 +//! CS 2 GPIO6 +//! CS 3 GPIO7 +//! +//! Folowing pins are used for ESP32: +//! SCLK GPIO0 +//! MISO GPIO2 +//! MOSI GPIO4 +//! CS 1 GPIO5 +//! CS 2 GPIO13 +//! CS 3 GPIO14 //! //! Depending on your target and the board you are using you have to change the //! pins. @@ -15,14 +23,18 @@ //! Connect MISO and MOSI pins to see the outgoing data is read as incoming //! data. +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 +//% FEATURES: eh1 + #![no_std] #![no_main] use core::cell::RefCell; -use embedded_hal_1::spi::SpiDevice; +use embedded_hal::spi::SpiDevice; use embedded_hal_bus::spi::RefCellDevice; -use esp32c2_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, gpio::{self, IO}, peripherals::Peripherals, @@ -30,7 +42,6 @@ use esp32c2_hal::{ spi::{master::Spi, SpiMode}, Delay, }; -use esp_backtrace as _; use esp_println::{print, println}; #[entry] @@ -40,9 +51,9 @@ fn main() -> ! { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio6; + let sclk = io.pins.gpio0; let miso = io.pins.gpio2; - let mosi = io.pins.gpio7; + let mosi = io.pins.gpio4; let spi_bus = Spi::new(peripherals.SPI2, 1000u32.kHz(), SpiMode::Mode0, &clocks).with_pins( Some(sclk), @@ -52,12 +63,22 @@ fn main() -> ! { ); let spi_bus = RefCell::new(spi_bus); let mut spi_device_1 = - RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio3.into_push_pull_output()); - let mut spi_device_2 = - RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio4.into_push_pull_output()); - let mut spi_device_3 = RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio5.into_push_pull_output()); + cfg_if::cfg_if! { + if #[cfg(feature = "esp32")] { + let mut spi_device_2 = + RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio13.into_push_pull_output()); + let mut spi_device_3 = + RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio14.into_push_pull_output()); + } else { + let mut spi_device_2 = + RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio6.into_push_pull_output()); + let mut spi_device_3 = + RefCellDevice::new_no_delay(&spi_bus, io.pins.gpio7.into_push_pull_output()); + } + } + let mut delay = Delay::new(&clocks); println!("=== SPI example with embedded-hal-1 traits ==="); diff --git a/esp32c3-hal/examples/spi_eh1_loopback.rs b/examples/src/bin/spi_eh1_loopback.rs similarity index 91% rename from esp32c3-hal/examples/spi_eh1_loopback.rs rename to examples/src/bin/spi_eh1_loopback.rs index 7531f7d65..0e7f154a4 100644 --- a/esp32c3-hal/examples/spi_eh1_loopback.rs +++ b/examples/src/bin/spi_eh1_loopback.rs @@ -1,10 +1,10 @@ //! SPI loopback test //! //! Folowing pins are used: -//! SCLK GPIO6 +//! SCLK GPIO0 //! MISO GPIO2 -//! MOSI GPIO7 -//! CS GPIO10 +//! MOSI GPIO4 +//! CS GPIO5 //! //! Depending on your target and the board you are using you have to change the //! pins. @@ -13,11 +13,15 @@ //! Connect MISO and MOSI pins to see the outgoing data is read as incoming //! data. +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 +//% FEATURES: eh1 + #![no_std] #![no_main] -use embedded_hal_1::spi::SpiBus; -use esp32c3_hal::{ +use embedded_hal::spi::SpiBus; +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, gpio::IO, peripherals::Peripherals, @@ -25,7 +29,6 @@ use esp32c3_hal::{ spi::{master::Spi, SpiMode}, Delay, }; -use esp_backtrace as _; use esp_println::{print, println}; #[entry] @@ -35,10 +38,10 @@ fn main() -> ! { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio6; + let sclk = io.pins.gpio0; let miso = io.pins.gpio2; - let mosi = io.pins.gpio7; - let cs = io.pins.gpio10; + let mosi = io.pins.gpio4; + let cs = io.pins.gpio5; let mut spi = Spi::new(peripherals.SPI2, 1000u32.kHz(), SpiMode::Mode0, &clocks).with_pins( Some(sclk), diff --git a/esp32c3-hal/examples/spi_halfduplex_read_manufacturer_id.rs b/examples/src/bin/spi_halfduplex_read_manufacturer_id.rs similarity index 71% rename from esp32c3-hal/examples/spi_halfduplex_read_manufacturer_id.rs rename to examples/src/bin/spi_halfduplex_read_manufacturer_id.rs index 9a76c70f6..5877c047c 100644 --- a/esp32c3-hal/examples/spi_halfduplex_read_manufacturer_id.rs +++ b/examples/src/bin/spi_halfduplex_read_manufacturer_id.rs @@ -1,12 +1,20 @@ //! SPI read manufacturer id from flash chip //! //! Folowing pins are used: -//! SCLK GPIO6 +//! SCLK GPIO0 +//! MISO/IO0 GPIO1 +//! MOSI/IO1 GPIO2 +//! IO2 GPIO3 +//! IO3 GPIO4 +//! CS GPIO5 +//! +//! Folowing pins are used for ESP32: +//! SCLK GPIO0 //! MISO/IO0 GPIO2 -//! MOSI/IO1 GPIO3 -//! IO2 GPIO4 -//! IO3 GPIO5 -//! CS GPIO10 +//! MOSI/IO1 GPIO4 +//! IO2 GPIO5 +//! IO3 GPIO13 +//! CS GPIO14 //! //! Depending on your target and the board you are using you have to change the //! pins. @@ -14,10 +22,13 @@ //! Connect a flash chip (GD25Q64C was used) and make sure QE in the status //! register is set. +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] -use esp32c3_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, gpio::IO, peripherals::Peripherals, @@ -29,7 +40,6 @@ use esp32c3_hal::{ }, Delay, }; -use esp_backtrace as _; use esp_println::println; #[entry] @@ -39,12 +49,23 @@ fn main() -> ! { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio6; - let miso = io.pins.gpio2; - let mosi = io.pins.gpio3; - let sio2 = io.pins.gpio4; - let sio3 = io.pins.gpio5; - let cs = io.pins.gpio10; + cfg_if::cfg_if! { + if #[cfg(feature = "esp32")] { + let sclk = io.pins.gpio0; + let miso = io.pins.gpio2; + let mosi = io.pins.gpio4; + let sio2 = io.pins.gpio5; + let sio3 = io.pins.gpio13; + let cs = io.pins.gpio14; + } else { + let sclk = io.pins.gpio0; + let miso = io.pins.gpio1; + let mosi = io.pins.gpio2; + let sio2 = io.pins.gpio3; + let sio3 = io.pins.gpio4; + let cs = io.pins.gpio5; + } + } let mut spi = Spi::new_half_duplex(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks) .with_pins( diff --git a/esp32h2-hal/examples/spi_loopback.rs b/examples/src/bin/spi_loopback.rs similarity index 84% rename from esp32h2-hal/examples/spi_loopback.rs rename to examples/src/bin/spi_loopback.rs index 18f34e72c..8da6e896f 100644 --- a/esp32h2-hal/examples/spi_loopback.rs +++ b/examples/src/bin/spi_loopback.rs @@ -1,10 +1,10 @@ //! SPI loopback test //! //! Folowing pins are used: -//! SCLK GPIO1 +//! SCLK GPIO0 //! MISO GPIO2 -//! MOSI GPIO3 -//! CS GPIO11 +//! MOSI GPIO4 +//! CS GPIO5 //! //! Depending on your target and the board you are using you have to change the //! pins. @@ -13,10 +13,13 @@ //! Connect MISO and MOSI pins to see the outgoing data is read as incoming //! data. +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] -use esp32h2_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, gpio::IO, peripherals::Peripherals, @@ -24,7 +27,6 @@ use esp32h2_hal::{ spi::{master::Spi, SpiMode}, Delay, }; -use esp_backtrace as _; use esp_println::println; #[entry] @@ -34,10 +36,10 @@ fn main() -> ! { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio1; + let sclk = io.pins.gpio0; let miso = io.pins.gpio2; - let mosi = io.pins.gpio3; - let cs = io.pins.gpio11; + let mosi = io.pins.gpio4; + let cs = io.pins.gpio5; let mut spi = Spi::new(peripherals.SPI2, 100u32.kHz(), SpiMode::Mode0, &clocks).with_pins( Some(sclk), diff --git a/esp32c2-hal/examples/spi_loopback_dma.rs b/examples/src/bin/spi_loopback_dma.rs similarity index 86% rename from esp32c2-hal/examples/spi_loopback_dma.rs rename to examples/src/bin/spi_loopback_dma.rs index e1141957a..aaa519071 100644 --- a/esp32c2-hal/examples/spi_loopback_dma.rs +++ b/examples/src/bin/spi_loopback_dma.rs @@ -1,10 +1,10 @@ //! SPI loopback test using DMA //! //! Folowing pins are used: -//! SCLK GPIO6 +//! SCLK GPIO0 //! MISO GPIO2 -//! MOSI GPIO7 -//! CS GPIO10 +//! MOSI GPIO4 +//! CS GPIO5 //! //! Depending on your target and the board you are using you have to change the //! pins. @@ -13,10 +13,13 @@ //! Connect MISO and MOSI pins to see the outgoing data is read as incoming //! data. +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] -use esp32c2_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, @@ -29,7 +32,6 @@ use esp32c2_hal::{ }, Delay, }; -use esp_backtrace as _; use esp_println::println; #[entry] @@ -39,12 +41,16 @@ fn main() -> ! { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let sclk = io.pins.gpio6; + let sclk = io.pins.gpio0; let miso = io.pins.gpio2; - let mosi = io.pins.gpio7; - let cs = io.pins.gpio10; + let mosi = io.pins.gpio4; + let cs = io.pins.gpio5; let dma = Dma::new(peripherals.DMA); + + #[cfg(any(feature = "esp32", feature = "esp32s2"))] + let dma_channel = dma.spi2channel; + #[cfg(not(any(feature = "esp32", feature = "esp32s2")))] let dma_channel = dma.channel0; let (tx_buffer, mut tx_descriptors, rx_buffer, mut rx_descriptors) = dma_buffers!(32000); diff --git a/esp32c6-hal/examples/spi_slave_dma.rs b/examples/src/bin/spi_slave_dma.rs similarity index 90% rename from esp32c6-hal/examples/spi_slave_dma.rs rename to examples/src/bin/spi_slave_dma.rs index b6bbbd1cb..89a115f9f 100644 --- a/esp32c6-hal/examples/spi_slave_dma.rs +++ b/examples/src/bin/spi_slave_dma.rs @@ -1,14 +1,14 @@ //! SPI slave loopback test using DMA //! //! Following pins are used for the slave: -//! SCLK GPIO6 -//! MISO GPIO2 -//! MOSI GPIO7 -//! CS GPIO10 +//! SCLK GPIO0 +//! MISO GPIO1 +//! MOSI GPIO2 +//! CS GPIO3 //! //! Following pins are used for the (bitbang) master: -//! SCLK GPIO5 -//! MISO GPIO1 +//! SCLK GPIO4 +//! MISO GPIO5 //! MOSI GPIO8 //! CS GPIO9 //! @@ -16,16 +16,20 @@ //! pins. //! //! This example transfers data via SPI. +//! //! Connect corresponding master and slave pins to see the outgoing data is read //! as incoming data. The master-side pins are chosen to make these connections -//! easy for the barebones ESP32C3 chip; all are immediate neighbors of the -//! slave-side pins except SCLK. SCLK is between MOSI and VDD3P3_RTC on the -//! barebones ESP32C3, so no immediate neighbor is available. +//! easy for the barebones chip; all are immediate neighbors of the slave-side +//! pins except SCLK. SCLK is between MOSI and VDD3P3_RTC on the barebones chip, +//! so no immediate neighbor is available. + +//% CHIPS: esp32c2 esp32c3 esp32c6 esp32h2 esp32s3 #![no_std] #![no_main] -use esp32c6_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, dma::{Dma, DmaPriority}, dma_buffers, @@ -38,7 +42,6 @@ use esp32c6_hal::{ }, Delay, }; -use esp_backtrace as _; use esp_println::println; #[entry] @@ -48,13 +51,13 @@ fn main() -> ! { let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); - let slave_sclk = io.pins.gpio6; - let mut master_sclk = io.pins.gpio5.into_push_pull_output(); - let slave_miso = io.pins.gpio2; - let master_miso = io.pins.gpio1.into_floating_input(); - let slave_mosi = io.pins.gpio7; + let slave_sclk = io.pins.gpio0; + let mut master_sclk = io.pins.gpio4.into_push_pull_output(); + let slave_miso = io.pins.gpio1; + let master_miso = io.pins.gpio5.into_floating_input(); + let slave_mosi = io.pins.gpio2; let mut master_mosi = io.pins.gpio8.into_push_pull_output(); - let slave_cs = io.pins.gpio10; + let slave_cs = io.pins.gpio3; let mut master_cs = io.pins.gpio9.into_push_pull_output(); master_cs.set_high().unwrap(); master_sclk.set_low().unwrap(); diff --git a/esp32s3-hal/examples/systimer.rs b/examples/src/bin/systimer.rs similarity index 78% rename from esp32s3-hal/examples/systimer.rs rename to examples/src/bin/systimer.rs index 328bb898e..d7ee77552 100644 --- a/esp32s3-hal/examples/systimer.rs +++ b/examples/src/bin/systimer.rs @@ -1,22 +1,24 @@ //! This shows how to use the SYSTIMER peripheral including interrupts. +//! //! It's an additional timer besides the TIMG peripherals. +//% CHIPS: esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] use core::cell::RefCell; use critical_section::Mutex; -use esp32s3_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, - interrupt, - interrupt::Priority, - peripherals::{self, Peripherals}, + interrupt::{self, Priority}, + peripherals::{Interrupt, Peripherals}, prelude::*, systimer::{Alarm, Periodic, SystemTimer, Target}, Delay, }; -use esp_backtrace as _; use esp_println::println; static ALARM0: Mutex>>> = Mutex::new(RefCell::new(None)); @@ -29,19 +31,19 @@ fn main() -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - let syst = SystemTimer::new(peripherals.SYSTIMER); + let systimer = SystemTimer::new(peripherals.SYSTIMER); println!("SYSTIMER Current value = {}", SystemTimer::now()); - let alarm0 = syst.alarm0.into_periodic(); + let alarm0 = systimer.alarm0.into_periodic(); alarm0.set_period(1u32.secs()); alarm0.enable_interrupt(true); - let alarm1 = syst.alarm1; + let alarm1 = systimer.alarm1; alarm1.set_target(SystemTimer::now() + (SystemTimer::TICKS_PER_SECOND * 2)); alarm1.enable_interrupt(true); - let alarm2 = syst.alarm2; + let alarm2 = systimer.alarm2; alarm2.set_target(SystemTimer::now() + (SystemTimer::TICKS_PER_SECOND * 3)); alarm2.enable_interrupt(true); @@ -51,21 +53,9 @@ fn main() -> ! { ALARM2.borrow_ref_mut(cs).replace(alarm2); }); - interrupt::enable( - peripherals::Interrupt::SYSTIMER_TARGET0, - Priority::Priority1, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::SYSTIMER_TARGET1, - Priority::Priority2, - ) - .unwrap(); - interrupt::enable( - peripherals::Interrupt::SYSTIMER_TARGET2, - Priority::Priority3, - ) - .unwrap(); + interrupt::enable(Interrupt::SYSTIMER_TARGET0, Priority::Priority1).unwrap(); + interrupt::enable(Interrupt::SYSTIMER_TARGET1, Priority::Priority3).unwrap(); + interrupt::enable(Interrupt::SYSTIMER_TARGET2, Priority::Priority3).unwrap(); // Initialize the Delay peripheral, and use it to toggle the LED state in a // loop. diff --git a/esp32c2-hal/examples/timer_interrupt.rs b/examples/src/bin/timer_interrupt.rs similarity index 75% rename from esp32c2-hal/examples/timer_interrupt.rs rename to examples/src/bin/timer_interrupt.rs index f8d81ed4a..62e4194f9 100644 --- a/esp32c2-hal/examples/timer_interrupt.rs +++ b/examples/src/bin/timer_interrupt.rs @@ -1,20 +1,23 @@ //! This shows how to use the TIMG peripheral interrupts. +//! //! There is TIMG0 which contains a general purpose timer and a watchdog timer. +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] use core::cell::RefCell; use critical_section::Mutex; -use esp32c2_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, - interrupt, - peripherals::{self, Peripherals, TIMG0}, + interrupt::{self, Priority}, + peripherals::{Interrupt, Peripherals, TIMG0}, prelude::*, timer::{Timer, Timer0, TimerGroup}, }; -use esp_backtrace as _; static TIMER0: Mutex>>>> = Mutex::new(RefCell::new(None)); @@ -24,14 +27,10 @@ fn main() -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let mut timer0 = timg0.timer0; - interrupt::enable( - peripherals::Interrupt::TG0_T0_LEVEL, - interrupt::Priority::Priority1, - ) - .unwrap(); + interrupt::enable(Interrupt::TG0_T0_LEVEL, Priority::Priority1).unwrap(); timer0.start(500u64.millis()); timer0.listen(); diff --git a/esp32s3-hal/examples/twai.rs b/examples/src/bin/twai.rs similarity index 84% rename from esp32s3-hal/examples/twai.rs rename to examples/src/bin/twai.rs index 962f3c176..0ca79a729 100644 --- a/esp32s3-hal/examples/twai.rs +++ b/examples/src/bin/twai.rs @@ -7,10 +7,12 @@ //! * adding a pull-up to the signal pins //! //! ESP1/GND --- ESP2/GND -//! ESP1/IO2 --- ESP1/IO3 --- ESP2/IO2 --- ESP2/IO3 --- 4.8kOhm --- ESP1/5V +//! ESP1/IO0 --- ESP1/IO1 --- ESP2/IO0 --- ESP2/IO1 --- 4.8kOhm --- ESP1/5V //! //! `IS_FIRST_SENDER` below must be set to false on one of the ESP's +//% CHIPS: esp32c3 esp32s3 + #![no_std] #![no_main] @@ -24,9 +26,16 @@ use embedded_can::{nb::Can, Frame, StandardId}; // Run this example without the eh1 flag to use the embedded-hal 0.2.7 CAN traits. // cargo run --example twai --release #[cfg(not(feature = "eh1"))] -use embedded_hal::can::{Can, Frame, StandardId}; -use esp32s3_hal::{clock::ClockControl, gpio::IO, peripherals::Peripherals, prelude::*, twai}; +use embedded_hal_02::can::{Can, Frame, StandardId}; use esp_backtrace as _; +use esp_hal::{ + clock::ClockControl, + gpio::IO, + peripherals::Peripherals, + prelude::*, + twai, + twai::filter::SingleStandardFilter, +}; use esp_println::println; use nb::block; @@ -39,8 +48,8 @@ fn main() -> ! { let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); // Set the tx pin as open drain. Skip this if using transceivers. - let can_tx_pin = io.pins.gpio2.into_open_drain_output(); - let can_rx_pin = io.pins.gpio3; + let can_tx_pin = io.pins.gpio0.into_open_drain_output(); + let can_rx_pin = io.pins.gpio1; // The speed of the CAN bus. const CAN_BAUDRATE: twai::BaudRate = twai::BaudRate::B1000K; @@ -61,8 +70,8 @@ fn main() -> ! { // be explicitly checked in the application instead of fully relying on // these partial acceptance filters to exactly match. // A filter that matches StandardId::ZERO. - const FILTER: twai::filter::SingleStandardFilter = - twai::filter::SingleStandardFilter::new(b"00000000000", b"x", [b"xxxxxxxx", b"xxxxxxxx"]); + const FILTER: SingleStandardFilter = + SingleStandardFilter::new(b"00000000000", b"x", [b"xxxxxxxx", b"xxxxxxxx"]); can_config.set_filter(FILTER); // Start the peripheral. This locks the configuration settings of the peripheral diff --git a/esp32s2-hal/examples/ulp_riscv_core_basic.rs b/examples/src/bin/ulp_riscv_core_basic.rs similarity index 79% rename from esp32s2-hal/examples/ulp_riscv_core_basic.rs rename to examples/src/bin/ulp_riscv_core_basic.rs index 509e18875..cb223e456 100644 --- a/esp32s2-hal/examples/ulp_riscv_core_basic.rs +++ b/examples/src/bin/ulp_riscv_core_basic.rs @@ -3,31 +3,30 @@ //! Code on ULP core just increments a counter and blinks GPIO 1. The current //! value is printed by the HP core. +//% CHIPS: esp32s2 esp32s3 + #![no_std] #![no_main] -use esp32s2_hal::{ - clock::ClockControl, - gpio::rtc_io::*, - peripherals::Peripherals, - prelude::*, - ulp_core, - IO, -}; use esp_backtrace as _; +use esp_hal::{gpio::rtc_io::*, peripherals::Peripherals, prelude::*, ulp_core, IO}; use esp_println::{print, println}; #[entry] fn main() -> ! { let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::boot_defaults(system.clock_control).freeze(); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); let pin = io.pins.gpio1.into_low_power().into_push_pull_output(); let mut ulp_core = ulp_core::UlpCore::new(peripherals.ULP_RISCV_CORE); + #[cfg(feature = "esp32s3")] + { + ulp_core.stop(); + println!("ulp core stopped"); + } + // load code to LP core let lp_core_code = load_lp_code!("../esp-lp-hal/target/riscv32imc-unknown-none-elf/release/examples/blinky"); diff --git a/esp32s2-hal/examples/usb_serial.rs b/examples/src/bin/usb_serial.rs similarity index 83% rename from esp32s2-hal/examples/usb_serial.rs rename to examples/src/bin/usb_serial.rs index fec94536b..6a48bc1d4 100644 --- a/esp32s2-hal/examples/usb_serial.rs +++ b/examples/src/bin/usb_serial.rs @@ -2,37 +2,36 @@ //! //! This example should be built in release mode. +//% CHIPS: esp32s2 esp32s3 + #![no_std] #![no_main] -use esp32s2_hal::{ - clock::{ClockControl, CpuClock}, +use esp_backtrace as _; +use esp_hal::{ otg_fs::{UsbBus, USB}, peripherals::Peripherals, prelude::*, IO, }; -use esp_backtrace as _; use usb_device::prelude::{UsbDeviceBuilder, UsbVidPid}; +use usbd_serial::{SerialPort, USB_CLASS_CDC}; static mut EP_MEMORY: [u32; 1024] = [0; 1024]; #[entry] fn main() -> ! { let peripherals = Peripherals::take(); - let system = peripherals.SYSTEM.split(); - let _clocks = ClockControl::configure(system.clock_control, CpuClock::Clock240MHz).freeze(); let io = IO::new(peripherals.GPIO, peripherals.IO_MUX); let usb = USB::new(peripherals.USB0, io.pins.gpio19, io.pins.gpio20); - let usb_bus = UsbBus::new(usb, unsafe { &mut EP_MEMORY }); - let mut serial = usbd_serial::SerialPort::new(&usb_bus); + let mut serial = SerialPort::new(&usb_bus); let mut usb_dev = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd)) - .device_class(usbd_serial::USB_CLASS_CDC) + .device_class(USB_CLASS_CDC) .build(); loop { diff --git a/esp32s3-hal/examples/usb_serial_jtag.rs b/examples/src/bin/usb_serial_jtag.rs similarity index 84% rename from esp32s3-hal/examples/usb_serial_jtag.rs rename to examples/src/bin/usb_serial_jtag.rs index e277db189..cfb13aef6 100644 --- a/esp32s3-hal/examples/usb_serial_jtag.rs +++ b/examples/src/bin/usb_serial_jtag.rs @@ -1,22 +1,25 @@ //! This shows how to output text via USB Serial/JTAG. +//! //! You need to connect via the Serial/JTAG interface to see any output. //! Most dev-kits use a USB-UART-bridge - in that case you won't see any output. +//% CHIPS: esp32c3 esp32c6 esp32h2 esp32s3 + #![no_std] #![no_main] use core::{cell::RefCell, fmt::Write}; use critical_section::Mutex; -use esp32s3_hal::{ +use esp_backtrace as _; +use esp_hal::{ clock::ClockControl, - interrupt, - peripherals::{self, Peripherals}, + interrupt::{self, Priority}, + peripherals::{Interrupt, Peripherals}, prelude::*, timer::TimerGroup, UsbSerialJtag, }; -use esp_backtrace as _; use nb::block; static USB_SERIAL: Mutex>> = Mutex::new(RefCell::new(None)); @@ -27,22 +30,16 @@ fn main() -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - - let mut usb_serial = UsbSerialJtag::new(peripherals.USB_DEVICE); - - usb_serial.listen_rx_packet_recv_interrupt(); + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let mut timer0 = timg0.timer0; timer0.start(1u64.secs()); - critical_section::with(|cs| USB_SERIAL.borrow_ref_mut(cs).replace(usb_serial)); + let mut usb_serial = UsbSerialJtag::new(peripherals.USB_DEVICE); + usb_serial.listen_rx_packet_recv_interrupt(); - interrupt::enable( - peripherals::Interrupt::USB_DEVICE, - interrupt::Priority::Priority1, - ) - .unwrap(); + critical_section::with(|cs| USB_SERIAL.borrow_ref_mut(cs).replace(usb_serial)); + interrupt::enable(Interrupt::USB_DEVICE, Priority::Priority1).unwrap(); loop { critical_section::with(|cs| { @@ -62,10 +59,13 @@ fn USB_DEVICE() { critical_section::with(|cs| { let mut usb_serial = USB_SERIAL.borrow_ref_mut(cs); let usb_serial = usb_serial.as_mut().unwrap(); + writeln!(usb_serial, "USB serial interrupt").unwrap(); + while let nb::Result::Ok(c) = usb_serial.read_byte() { writeln!(usb_serial, "Read byte: {:02x}", c).unwrap(); } + usb_serial.reset_rx_packet_recv_interrupt(); }); } diff --git a/esp32c2-hal/examples/watchdog.rs b/examples/src/bin/watchdog.rs similarity index 68% rename from esp32c2-hal/examples/watchdog.rs rename to examples/src/bin/watchdog.rs index be8bca070..12f07e707 100644 --- a/esp32c2-hal/examples/watchdog.rs +++ b/examples/src/bin/watchdog.rs @@ -1,12 +1,15 @@ //! This demos the watchdog timer. +//! //! Basically the same as `hello_world` but if you remove the call to //! `wdt.feed()` the watchdog will reset the system. +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + #![no_std] #![no_main] -use esp32c2_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, timer::TimerGroup}; use esp_backtrace as _; +use esp_hal::{clock::ClockControl, peripherals::Peripherals, prelude::*, timer::TimerGroup}; use esp_println::println; use nb::block; @@ -16,9 +19,9 @@ fn main() -> ! { let system = peripherals.SYSTEM.split(); let clocks = ClockControl::boot_defaults(system.clock_control).freeze(); - let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks); - let mut timer0 = timer_group0.timer0; - let mut wdt0 = timer_group0.wdt; + let timg0 = TimerGroup::new(peripherals.TIMG0, &clocks); + let mut timer0 = timg0.timer0; + let mut wdt0 = timg0.wdt; wdt0.start(2u64.secs()); timer0.start(1u64.secs()); diff --git a/examples/src/lib.rs b/examples/src/lib.rs new file mode 100644 index 000000000..b90f3a7b4 --- /dev/null +++ b/examples/src/lib.rs @@ -0,0 +1,14 @@ +#![no_std] + +#[cfg(not(feature = "esp32p4"))] // TODO: Remove me +pub fn cycles() -> u64 { + #[cfg(feature = "esp32")] + { + esp_hal::xtensa_lx::timer::get_cycle_count() as u64 + } + + #[cfg(not(feature = "esp32"))] + { + esp_hal::systimer::SystemTimer::now() + } +}