forked from espressif/arduino-esp32
Update IDF and Camera
This commit is contained in:
@ -390,61 +390,6 @@ static inline void i2s_ll_set_rx_eof_num(i2s_dev_t *hw, uint32_t val)
|
||||
hw->rx_eof_num = val / 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get I2S tx pdm fp
|
||||
*
|
||||
* @param hw Peripheral I2S hardware instance address.
|
||||
* @param val value to get tx pdm fp
|
||||
*/
|
||||
static inline void i2s_ll_get_tx_pdm_fp(i2s_dev_t *hw, uint32_t *val)
|
||||
{
|
||||
*val = hw->pdm_freq_conf.tx_pdm_fp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get I2S tx pdm fs
|
||||
*
|
||||
* @param hw Peripheral I2S hardware instance address.
|
||||
* @param val value to get tx pdm fs
|
||||
*/
|
||||
static inline void i2s_ll_get_tx_pdm_fs(i2s_dev_t *hw, uint32_t *val)
|
||||
{
|
||||
*val = hw->pdm_freq_conf.tx_pdm_fs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set I2S tx pdm fp
|
||||
*
|
||||
* @param hw Peripheral I2S hardware instance address.
|
||||
* @param val value to set tx pdm fp
|
||||
*/
|
||||
static inline void i2s_ll_set_tx_pdm_fp(i2s_dev_t *hw, uint32_t val)
|
||||
{
|
||||
hw->pdm_freq_conf.tx_pdm_fp = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set I2S tx pdm fs
|
||||
*
|
||||
* @param hw Peripheral I2S hardware instance address.
|
||||
* @param val value to set tx pdm fs
|
||||
*/
|
||||
static inline void i2s_ll_set_tx_pdm_fs(i2s_dev_t *hw, uint32_t val)
|
||||
{
|
||||
hw->pdm_freq_conf.tx_pdm_fs = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get I2S rx sinc dsr 16 en
|
||||
*
|
||||
* @param hw Peripheral I2S hardware instance address.
|
||||
* @param val value to get rx sinc dsr 16 en
|
||||
*/
|
||||
static inline void i2s_ll_get_rx_sinc_dsr_16_en(i2s_dev_t *hw, bool *val)
|
||||
{
|
||||
*val = hw->pdm_conf.rx_sinc_dsr_16_en;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set I2S clkm div num
|
||||
*
|
||||
@ -533,17 +478,6 @@ static inline void i2s_ll_set_rx_bits_mod(i2s_dev_t *hw, uint32_t val)
|
||||
hw->sample_rate_conf.rx_bits_mod = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set I2S rx sinc dsr 16 en
|
||||
*
|
||||
* @param hw Peripheral I2S hardware instance address.
|
||||
* @param val value to set rx sinc dsr 16 en
|
||||
*/
|
||||
static inline void i2s_ll_set_rx_sinc_dsr_16_en(i2s_dev_t *hw, bool val)
|
||||
{
|
||||
hw->pdm_conf.rx_sinc_dsr_16_en = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set I2S dscr en
|
||||
*
|
||||
@ -577,50 +511,6 @@ static inline void i2s_ll_set_camera_en(i2s_dev_t *hw, bool val)
|
||||
hw->conf2.camera_en = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set I2S pcm2pdm conv en
|
||||
*
|
||||
* @param hw Peripheral I2S hardware instance address.
|
||||
* @param val value to set pcm2pdm conv en
|
||||
*/
|
||||
static inline void i2s_ll_set_pcm2pdm_conv_en(i2s_dev_t *hw, bool val)
|
||||
{
|
||||
hw->pdm_conf.pcm2pdm_conv_en = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set I2S pdm2pcm conv en
|
||||
*
|
||||
* @param hw Peripheral I2S hardware instance address.
|
||||
* @param val value to set pdm2pcm conv en
|
||||
*/
|
||||
static inline void i2s_ll_set_pdm2pcm_conv_en(i2s_dev_t *hw, bool val)
|
||||
{
|
||||
hw->pdm_conf.pdm2pcm_conv_en = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set I2S rx pdm en
|
||||
*
|
||||
* @param hw Peripheral I2S hardware instance address.
|
||||
* @param val value to set rx pdm en
|
||||
*/
|
||||
static inline void i2s_ll_set_rx_pdm_en(i2s_dev_t *hw, bool val)
|
||||
{
|
||||
hw->pdm_conf.rx_pdm_en = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set I2S tx pdm en
|
||||
*
|
||||
* @param hw Peripheral I2S hardware instance address.
|
||||
* @param val value to set tx pdm en
|
||||
*/
|
||||
static inline void i2s_ll_set_tx_pdm_en(i2s_dev_t *hw, bool val)
|
||||
{
|
||||
hw->pdm_conf.tx_pdm_en = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set I2S tx fifo mod force en
|
||||
*
|
||||
@ -753,17 +643,6 @@ static inline void i2s_ll_set_rx_mono(i2s_dev_t *hw, uint32_t val)
|
||||
hw->conf.rx_mono = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set I2S tx sinc osr2
|
||||
*
|
||||
* @param hw Peripheral I2S hardware instance address.
|
||||
* @param val value to set tx sinc osr2
|
||||
*/
|
||||
static inline void i2s_ll_set_tx_sinc_osr2(i2s_dev_t *hw, uint32_t val)
|
||||
{
|
||||
hw->pdm_conf.tx_sinc_osr2 = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set I2S sig loopback
|
||||
*
|
||||
@ -863,35 +742,6 @@ static inline void i2s_ll_set_rx_pcm_long(i2s_dev_t *hw)
|
||||
hw->conf.rx_msb_shift = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure I2S TX pdm
|
||||
*
|
||||
* @param sample_rate The sample rate to be set.
|
||||
* @param hw Peripheral I2S hardware instance address.
|
||||
*/
|
||||
static inline void i2s_ll_tx_pdm_cfg(i2s_dev_t *hw, uint32_t sample_rate)
|
||||
{
|
||||
uint32_t fp = 96;
|
||||
uint32_t fs = sample_rate / 1000 * 10;
|
||||
hw->pdm_freq_conf.tx_pdm_fp = fp;
|
||||
hw->pdm_freq_conf.tx_pdm_fs = fs;
|
||||
hw->pdm_conf.tx_sinc_osr2 = fp/fs;
|
||||
hw->pdm_conf.pcm2pdm_conv_en = 1;
|
||||
hw->pdm_conf.tx_pdm_en = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure I2S TX pdm
|
||||
*
|
||||
* @param hw Peripheral I2S hardware instance address.
|
||||
*/
|
||||
static inline void i2s_ll_rx_pdm_cfg(i2s_dev_t *hw)
|
||||
{
|
||||
hw->pdm_conf.rx_sinc_dsr_16_en = 0;
|
||||
hw->pdm_conf.pdm2pcm_conv_en = 1;
|
||||
hw->pdm_conf.rx_pdm_en = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable I2S build in ADC mode
|
||||
*
|
||||
@ -919,6 +769,82 @@ static inline void i2s_ll_build_in_dac_ena(i2s_dev_t *hw)
|
||||
hw->conf.tx_short_sync = 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enable I2S RX PDM mode
|
||||
*
|
||||
* @param hw Peripheral I2S hardware instance address.
|
||||
* @param pdm_en Set true to enable rx PDM mode
|
||||
*/
|
||||
static inline void i2s_ll_set_rx_pdm_en(i2s_dev_t *hw, bool pdm_en)
|
||||
{
|
||||
hw->pdm_conf.rx_pdm_en = pdm_en;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable I2S tx pdm mode
|
||||
*
|
||||
* @param hw Peripheral I2S hardware instance address.
|
||||
* @param pdm_en Set true to enable tx PDM mode
|
||||
*/
|
||||
static inline void i2s_ll_set_tx_pdm_en(i2s_dev_t *hw, bool pdm_en)
|
||||
{
|
||||
hw->pdm_conf.tx_pdm_en = pdm_en;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure I2S tx PDM filter module group0
|
||||
*
|
||||
* @param hw Peripheral I2S hardware instance address.
|
||||
* @param fp The fp value of TX PDM filter module group0.
|
||||
* @param fs The fs value of TX PDM filter module group0.
|
||||
*/
|
||||
static inline void i2s_ll_tx_pdm_cfg(i2s_dev_t *hw, uint32_t fp, uint32_t fs)
|
||||
{
|
||||
hw->pdm_freq_conf.tx_pdm_fp = fp;
|
||||
hw->pdm_freq_conf.tx_pdm_fs = fs;
|
||||
hw->pdm_conf.tx_sinc_osr2 = fp/fs;
|
||||
hw->pdm_conf.pcm2pdm_conv_en = 1;
|
||||
hw->pdm_conf.tx_pdm_en = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure I2S rx PDM
|
||||
*
|
||||
* @param hw Peripheral I2S hardware instance address.
|
||||
* @param dsr Down-sampling rate value of rx PDM
|
||||
*/
|
||||
static inline void i2s_ll_rx_pdm_cfg(i2s_dev_t *hw, uint32_t dsr)
|
||||
{
|
||||
hw->pdm_conf.rx_sinc_dsr_16_en = dsr;
|
||||
hw->pdm_conf.pdm2pcm_conv_en = 1;
|
||||
hw->pdm_conf.rx_pdm_en = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get I2S tx PDM configuration
|
||||
*
|
||||
* @param hw Peripheral I2S hardware instance address.
|
||||
* @param fp Pointer to store tx PDM fp configuration
|
||||
* @param fs Pointer to store tx PDM fs configuration
|
||||
*/
|
||||
static inline void i2s_ll_get_tx_pdm(i2s_dev_t *hw, uint32_t *fp, uint32_t *fs)
|
||||
{
|
||||
*fp = hw->pdm_freq_conf.tx_pdm_fp;
|
||||
*fs = hw->pdm_freq_conf.tx_pdm_fs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get I2S rx PDM configuration
|
||||
*
|
||||
* @param hw Peripheral I2S hardware instance address.
|
||||
* @param dsr Pointer to stoe the rx PDM down-sample rate configuration
|
||||
*/
|
||||
static inline void i2s_ll_get_rx_pdm(i2s_dev_t *hw, uint32_t *dsr)
|
||||
{
|
||||
*dsr = hw->pdm_conf.rx_sinc_dsr_16_en;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -0,0 +1,105 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include "soc/soc_caps.h"
|
||||
#include "soc/soc.h"
|
||||
#include "xtensa/xtensa_api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief enable interrupts specified by the mask
|
||||
*
|
||||
* @param mask bitmask of interrupts that needs to be enabled
|
||||
*/
|
||||
static inline void intr_cntrl_ll_enable_interrupts(uint32_t mask)
|
||||
{
|
||||
xt_ints_on(mask);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief disable interrupts specified by the mask
|
||||
*
|
||||
* @param mask bitmask of interrupts that needs to be disabled
|
||||
*/
|
||||
static inline void intr_cntrl_ll_disable_interrupts(uint32_t mask)
|
||||
{
|
||||
xt_ints_off(mask);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief checks if given interrupt number has a valid handler
|
||||
*
|
||||
* @param intr interrupt number ranged from 0 to 31
|
||||
* @param cpu cpu number ranged betweeen 0 to SOC_CPU_CORES_NUM - 1
|
||||
* @return true for valid handler, false otherwise
|
||||
*/
|
||||
static inline bool intr_cntrl_ll_has_handler(uint8_t intr, uint8_t cpu)
|
||||
{
|
||||
return xt_int_has_handler(intr, cpu);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief sets interrupt handler and optional argument of a given interrupt number
|
||||
*
|
||||
* @param intr interrupt number ranged from 0 to 31
|
||||
* @param handler handler invoked when an interrupt occurs
|
||||
* @param arg optional argument to pass to the handler
|
||||
*/
|
||||
static inline void intr_cntrl_ll_set_int_handler(uint8_t intr, interrupt_handler_t handler, void * arg)
|
||||
{
|
||||
xt_set_interrupt_handler(intr, (xt_handler)handler, arg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets argument passed to handler of a given interrupt number
|
||||
*
|
||||
* @param intr interrupt number ranged from 0 to 31
|
||||
*
|
||||
* @return argument used by handler of passed interrupt number
|
||||
*/
|
||||
static inline void * intr_cntrl_ll_get_int_handler_arg(uint8_t intr)
|
||||
{
|
||||
return xt_get_interrupt_handler_arg(intr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables interrupts that are not located in iram
|
||||
*
|
||||
* @param newmask mask of interrupts needs to be disabled
|
||||
* @return oldmask where to store old interrupts state
|
||||
*/
|
||||
static inline uint32_t intr_cntrl_ll_disable_int_mask(uint32_t newmask)
|
||||
{
|
||||
return xt_int_disable_mask(newmask);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables interrupts that are not located in iram
|
||||
*
|
||||
* @param newmask mask of interrupts needs to be disabled
|
||||
*/
|
||||
static inline void intr_cntrl_ll_enable_int_mask(uint32_t newmask)
|
||||
{
|
||||
xt_int_enable_mask(newmask);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
156
tools/sdk/esp32/include/hal/esp32/include/hal/sha_ll.h
Normal file
156
tools/sdk/esp32/include/hal/esp32/include/hal/sha_ll.h
Normal file
@ -0,0 +1,156 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "hal/sha_types.h"
|
||||
#include "soc/hwcrypto_reg.h"
|
||||
#include "soc/dport_access.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SHA_LL_TYPE_OFFSET 0x10
|
||||
|
||||
/**
|
||||
* @brief Returns the LOAD_REG register address for the given sha type
|
||||
*
|
||||
* @param sha_type The SHA algorithm type
|
||||
* @return uint32_t the LOAD_REG register address
|
||||
*/
|
||||
inline static uint32_t SHA_LOAD_REG(esp_sha_type sha_type)
|
||||
{
|
||||
return SHA_1_LOAD_REG + sha_type * SHA_LL_TYPE_OFFSET;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the BUSY register address for the given sha type
|
||||
*
|
||||
* @param sha_type The SHA algorithm type
|
||||
* @return uint32_t the BUSY register address
|
||||
*/
|
||||
inline static uint32_t SHA_BUSY_REG(esp_sha_type sha_type)
|
||||
{
|
||||
return SHA_1_BUSY_REG + sha_type * SHA_LL_TYPE_OFFSET;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the START register address for the given sha type
|
||||
*
|
||||
* @param sha_type The SHA algorithm type
|
||||
* @return uint32_t the START register address
|
||||
*/
|
||||
inline static uint32_t SHA_START_REG(esp_sha_type sha_type)
|
||||
{
|
||||
return SHA_1_START_REG + sha_type * SHA_LL_TYPE_OFFSET;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the CONTINUE register address for the given sha type
|
||||
*
|
||||
* @param sha_type The SHA algorithm type
|
||||
* @return uint32_t the CONTINUE register address
|
||||
*/
|
||||
inline static uint32_t SHA_CONTINUE_REG(esp_sha_type sha_type)
|
||||
{
|
||||
return SHA_1_CONTINUE_REG + sha_type * SHA_LL_TYPE_OFFSET;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Start a new SHA block conversion (no initial hash in HW)
|
||||
*
|
||||
* @param sha_type The SHA algorithm type
|
||||
*/
|
||||
static inline void sha_ll_start_block(esp_sha_type sha_type)
|
||||
{
|
||||
DPORT_REG_WRITE(SHA_START_REG(sha_type), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Continue a SHA block conversion (initial hash in HW)
|
||||
*
|
||||
* @param sha_type The SHA algorithm type
|
||||
*/
|
||||
static inline void sha_ll_continue_block(esp_sha_type sha_type)
|
||||
{
|
||||
DPORT_REG_WRITE(SHA_CONTINUE_REG(sha_type), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Load the current hash digest to digest register
|
||||
*
|
||||
* @param sha_type The SHA algorithm type
|
||||
*/
|
||||
static inline void sha_ll_load(esp_sha_type sha_type)
|
||||
{
|
||||
DPORT_REG_WRITE(SHA_LOAD_REG(sha_type), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if the SHA engine is currently busy hashing a block
|
||||
*
|
||||
* @return true SHA engine busy
|
||||
* @return false SHA engine idle
|
||||
*/
|
||||
static inline bool sha_ll_busy(void)
|
||||
{
|
||||
return (DPORT_REG_READ(SHA_1_BUSY_REG) || DPORT_REG_READ(SHA_256_BUSY_REG)
|
||||
|| DPORT_REG_READ(SHA_384_BUSY_REG) || DPORT_REG_READ(SHA_512_BUSY_REG));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write a text (message) block to the SHA engine
|
||||
*
|
||||
* @param input_text Input buffer to be written to the SHA engine
|
||||
* @param block_word_len Number of words in block
|
||||
*/
|
||||
static inline void sha_ll_fill_text_block(const void *input_text, size_t block_word_len)
|
||||
{
|
||||
uint32_t *reg_addr_buf = NULL;
|
||||
uint32_t *data_words = NULL;
|
||||
reg_addr_buf = (uint32_t *)(SHA_TEXT_BASE);
|
||||
data_words = (uint32_t *)input_text;
|
||||
for (int i = 0; i < block_word_len; i++) {
|
||||
reg_addr_buf[i] = __builtin_bswap32(data_words[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read the message digest from the SHA engine
|
||||
*
|
||||
* @param sha_type The SHA algorithm type
|
||||
* @param digest_state Buffer that message digest will be written to
|
||||
* @param digest_word_len Length of the message digest
|
||||
*/
|
||||
static inline void sha_ll_read_digest(esp_sha_type sha_type, void *digest_state, size_t digest_word_len)
|
||||
{
|
||||
uint32_t *digest_state_words = (uint32_t *)digest_state;
|
||||
uint32_t *reg_addr_buf = (uint32_t *)(SHA_TEXT_BASE);
|
||||
if (sha_type == SHA2_384 || sha_type == SHA2_512) {
|
||||
/* for these ciphers using 64-bit states, swap each pair of words */
|
||||
DPORT_INTERRUPT_DISABLE(); // Disable interrupt only on current CPU.
|
||||
for (int i = 0; i < digest_word_len; i += 2) {
|
||||
digest_state_words[i + 1] = DPORT_SEQUENCE_REG_READ((uint32_t)®_addr_buf[i]);
|
||||
digest_state_words[i] = DPORT_SEQUENCE_REG_READ((uint32_t)®_addr_buf[i + 1]);
|
||||
}
|
||||
DPORT_INTERRUPT_RESTORE(); // restore the previous interrupt level
|
||||
} else {
|
||||
esp_dport_access_read_buffer(digest_state_words, (uint32_t)®_addr_buf[0], digest_word_len);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -224,7 +224,7 @@ static inline void spi_flash_ll_user_start(spi_dev_t *dev)
|
||||
*/
|
||||
static inline bool spi_flash_ll_host_idle(const spi_dev_t *dev)
|
||||
{
|
||||
return dev->ext2.st != 0;
|
||||
return dev->ext2.st == 0;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
@ -390,4 +390,4 @@ static inline void spi_flash_ll_set_dummy(spi_dev_t *dev, uint32_t dummy_n)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
@ -34,7 +34,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
/// Registers to reset during initialization. Don't use in app.
|
||||
#define SPI_LL_RST_MASK (SPI_OUT_RST | SPI_IN_RST | SPI_AHBM_RST | SPI_AHBM_FIFO_RST)
|
||||
#define SPI_LL_DMA_FIFO_RST_MASK (SPI_AHBM_RST | SPI_AHBM_FIFO_RST)
|
||||
/// Interrupt not used. Don't use in app.
|
||||
#define SPI_LL_UNUSED_INT_MASK (SPI_INT_EN | SPI_SLV_WR_STA_DONE | SPI_SLV_RD_STA_DONE | SPI_SLV_WR_BUF_DONE | SPI_SLV_RD_BUF_DONE)
|
||||
/// Swap the bit order to its correct place to send
|
||||
@ -49,6 +49,9 @@ extern "C" {
|
||||
*/
|
||||
typedef uint32_t spi_ll_clock_val_t;
|
||||
|
||||
//On ESP32-S2 and earlier chips, DMA registers are part of SPI registers. So set the registers of SPI peripheral to control DMA.
|
||||
typedef spi_dev_t spi_dma_dev_t;
|
||||
|
||||
/** IO modes supported by the master. */
|
||||
typedef enum {
|
||||
SPI_LL_IO_MODE_NORMAL = 0, ///< 1-bit mode for all phases
|
||||
@ -58,11 +61,6 @@ typedef enum {
|
||||
SPI_LL_IO_MODE_QUAD, ///< 4-bit mode for data phases only, 1-bit mode for command and address phases
|
||||
} spi_ll_io_mode_t;
|
||||
|
||||
/// Interrupt type for different working pattern
|
||||
typedef enum {
|
||||
SPI_LL_INT_TYPE_NORMAL = 0, ///< Typical pattern, only wait for trans done
|
||||
} spi_ll_slave_intr_type;
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Control
|
||||
@ -74,11 +72,6 @@ typedef enum {
|
||||
*/
|
||||
static inline void spi_ll_master_init(spi_dev_t *hw)
|
||||
{
|
||||
//Reset DMA
|
||||
hw->dma_conf.val |= SPI_LL_RST_MASK;
|
||||
hw->dma_out_link.start = 0;
|
||||
hw->dma_in_link.start = 0;
|
||||
hw->dma_conf.val &= ~SPI_LL_RST_MASK;
|
||||
//Reset timing
|
||||
hw->ctrl2.val = 0;
|
||||
|
||||
@ -105,10 +98,6 @@ static inline void spi_ll_slave_init(spi_dev_t *hw)
|
||||
hw->user.doutdin = 1; //we only support full duplex
|
||||
hw->user.sio = 0;
|
||||
hw->slave.slave_mode = 1;
|
||||
hw->dma_conf.val |= SPI_LL_RST_MASK;
|
||||
hw->dma_out_link.start = 0;
|
||||
hw->dma_in_link.start = 0;
|
||||
hw->dma_conf.val &= ~SPI_LL_RST_MASK;
|
||||
hw->slave.sync_reset = 1;
|
||||
hw->slave.sync_reset = 0;
|
||||
//use all 64 bytes of the buffer
|
||||
@ -119,84 +108,6 @@ static inline void spi_ll_slave_init(spi_dev_t *hw)
|
||||
hw->slave.val &= ~SPI_LL_UNUSED_INT_MASK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset TX and RX DMAs.
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
*/
|
||||
static inline void spi_ll_reset_dma(spi_dev_t *hw)
|
||||
{
|
||||
//Reset DMA peripheral
|
||||
hw->dma_conf.val |= SPI_LL_RST_MASK;
|
||||
hw->dma_out_link.start = 0;
|
||||
hw->dma_in_link.start = 0;
|
||||
hw->dma_conf.val &= ~SPI_LL_RST_MASK;
|
||||
hw->dma_conf.out_data_burst_en = 1;
|
||||
hw->dma_conf.indscr_burst_en = 1;
|
||||
hw->dma_conf.outdscr_burst_en = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start RX DMA.
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
* @param addr Address of the beginning DMA descriptor.
|
||||
*/
|
||||
static inline void spi_ll_rxdma_start(spi_dev_t *hw, lldesc_t *addr)
|
||||
{
|
||||
hw->dma_in_link.addr = (int) addr & 0xFFFFF;
|
||||
hw->dma_in_link.start = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start TX DMA.
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
* @param addr Address of the beginning DMA descriptor.
|
||||
*/
|
||||
static inline void spi_ll_txdma_start(spi_dev_t *hw, lldesc_t *addr)
|
||||
{
|
||||
hw->dma_out_link.addr = (int) addr & 0xFFFFF;
|
||||
hw->dma_out_link.start = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to SPI buffer.
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
* @param buffer_to_send Data address to copy to the buffer.
|
||||
* @param bitlen Length to copy, in bits.
|
||||
*/
|
||||
static inline void spi_ll_write_buffer(spi_dev_t *hw, const uint8_t *buffer_to_send, size_t bitlen)
|
||||
{
|
||||
for (int x = 0; x < bitlen; x += 32) {
|
||||
//Use memcpy to get around alignment issues for txdata
|
||||
uint32_t word;
|
||||
memcpy(&word, &buffer_to_send[x / 8], 4);
|
||||
hw->data_buf[(x / 32)] = word;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from SPI buffer.
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
* @param buffer_to_rcv Address to copy buffer data to.
|
||||
* @param bitlen Length to copy, in bits.
|
||||
*/
|
||||
static inline void spi_ll_read_buffer(spi_dev_t *hw, uint8_t *buffer_to_rcv, size_t bitlen)
|
||||
{
|
||||
for (int x = 0; x < bitlen; x += 32) {
|
||||
//Do a memcpy to get around possible alignment issues in rx_buffer
|
||||
uint32_t word = hw->data_buf[x / 32];
|
||||
int len = bitlen - x;
|
||||
if (len > 32) {
|
||||
len = 32;
|
||||
}
|
||||
memcpy(&buffer_to_rcv[x / 8], &word, (len + 7) / 8);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether user-defined transaction is done.
|
||||
*
|
||||
@ -232,48 +143,110 @@ static inline uint32_t spi_ll_get_running_cmd(spi_dev_t *hw)
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the trans_done interrupt.
|
||||
* Reset SPI CPU FIFO
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
*/
|
||||
static inline void spi_ll_disable_int(spi_dev_t *hw)
|
||||
static inline void spi_ll_cpu_fifo_reset(spi_dev_t *hw)
|
||||
{
|
||||
hw->slave.trans_inten = 0;
|
||||
//This is not used in esp32
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the trans_done interrupt.
|
||||
* Reset SPI DMA FIFO
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
*/
|
||||
static inline void spi_ll_clear_int_stat(spi_dev_t *hw)
|
||||
static inline void spi_ll_dma_fifo_reset(spi_dev_t *hw)
|
||||
{
|
||||
hw->slave.trans_done = 0;
|
||||
hw->dma_conf.val |= SPI_LL_DMA_FIFO_RST_MASK;
|
||||
hw->dma_conf.val &= ~SPI_LL_DMA_FIFO_RST_MASK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the trans_done interrupt.
|
||||
*
|
||||
* Clear in fifo full error
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
*/
|
||||
static inline void spi_ll_set_int_stat(spi_dev_t *hw)
|
||||
static inline void spi_ll_infifo_full_clr(spi_dev_t *hw)
|
||||
{
|
||||
hw->slave.trans_done = 1;
|
||||
//This is not used in esp32
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the trans_done interrupt.
|
||||
*
|
||||
* Clear out fifo empty error
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
*/
|
||||
static inline void spi_ll_enable_int(spi_dev_t *hw)
|
||||
static inline void spi_ll_outfifo_empty_clr(spi_dev_t *hw)
|
||||
{
|
||||
hw->slave.trans_inten = 1;
|
||||
//This is not used in esp32
|
||||
}
|
||||
|
||||
static inline void spi_ll_slave_set_int_type(spi_dev_t *hw, spi_ll_slave_intr_type int_type)
|
||||
/*------------------------------------------------------------------------------
|
||||
* SPI configuration for DMA
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Enable/Disable RX DMA (Peripherals->DMA->RAM)
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
* @param enable 1: enable; 2: disable
|
||||
*/
|
||||
static inline void spi_ll_dma_rx_enable(spi_dev_t *hw, bool enable)
|
||||
{
|
||||
hw->slave.trans_inten = 1;
|
||||
//This is not used in esp32
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable/Disable TX DMA (RAM->DMA->Peripherals)
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
* @param enable 1: enable; 2: disable
|
||||
*/
|
||||
static inline void spi_ll_dma_tx_enable(spi_dev_t *hw, bool enable)
|
||||
{
|
||||
//This is not used in esp32
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Buffer
|
||||
*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Write to SPI buffer.
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
* @param buffer_to_send Data address to copy to the buffer.
|
||||
* @param bitlen Length to copy, in bits.
|
||||
*/
|
||||
static inline void spi_ll_write_buffer(spi_dev_t *hw, const uint8_t *buffer_to_send, size_t bitlen)
|
||||
{
|
||||
for (int x = 0; x < bitlen; x += 32) {
|
||||
//Use memcpy to get around alignment issues for txdata
|
||||
uint32_t word;
|
||||
memcpy(&word, &buffer_to_send[x / 8], 4);
|
||||
hw->data_buf[(x / 32)] = word;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read from SPI buffer.
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
* @param buffer_to_rcv Address to copy buffer data to.
|
||||
* @param bitlen Length to copy, in bits.
|
||||
*/
|
||||
static inline void spi_ll_read_buffer(spi_dev_t *hw, uint8_t *buffer_to_rcv, size_t bitlen)
|
||||
{
|
||||
for (int x = 0; x < bitlen; x += 32) {
|
||||
//Do a memcpy to get around possible alignment issues in rx_buffer
|
||||
uint32_t word = hw->data_buf[x / 32];
|
||||
int len = bitlen - x;
|
||||
if (len > 32) {
|
||||
len = 32;
|
||||
}
|
||||
memcpy(&buffer_to_rcv[x / 8], &word, (len + 7) / 8);
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
@ -291,7 +264,7 @@ static inline void spi_ll_master_set_pos_cs(spi_dev_t *hw, int cs, uint32_t pos_
|
||||
if (pos_cs) {
|
||||
hw->pin.master_cs_pol |= (1 << cs);
|
||||
} else {
|
||||
hw->pin.master_cs_pol &= (1 << cs);
|
||||
hw->pin.master_cs_pol &= ~(1 << cs);
|
||||
}
|
||||
}
|
||||
|
||||
@ -485,7 +458,7 @@ static inline void spi_ll_master_select_cs(spi_dev_t *hw, int cs_id)
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
* @param val stored clock configuration calculated before (by ``spi_ll_cal_clock``).
|
||||
*/
|
||||
static inline void spi_ll_master_set_clock_by_reg(spi_dev_t *hw, spi_ll_clock_val_t *val)
|
||||
static inline void spi_ll_master_set_clock_by_reg(spi_dev_t *hw, const spi_ll_clock_val_t *val)
|
||||
{
|
||||
hw->clock.val = *(uint32_t *)val;
|
||||
}
|
||||
@ -615,7 +588,7 @@ static inline void spi_ll_master_set_cksel(spi_dev_t *hw, int cs, uint32_t cksel
|
||||
if (cksel) {
|
||||
hw->pin.master_ck_sel |= (1 << cs);
|
||||
} else {
|
||||
hw->pin.master_ck_sel &= (1 << cs);
|
||||
hw->pin.master_ck_sel &= ~(1 << cs);
|
||||
}
|
||||
}
|
||||
|
||||
@ -875,6 +848,167 @@ static inline uint32_t spi_ll_slave_get_rcv_bitlen(spi_dev_t *hw)
|
||||
return hw->slv_rd_bit.slv_rdata_bit;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Interrupts
|
||||
*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Disable the trans_done interrupt.
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
*/
|
||||
static inline void spi_ll_disable_int(spi_dev_t *hw)
|
||||
{
|
||||
hw->slave.trans_inten = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the trans_done interrupt.
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
*/
|
||||
static inline void spi_ll_clear_int_stat(spi_dev_t *hw)
|
||||
{
|
||||
hw->slave.trans_done = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the trans_done interrupt.
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
*/
|
||||
static inline void spi_ll_set_int_stat(spi_dev_t *hw)
|
||||
{
|
||||
hw->slave.trans_done = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the trans_done interrupt.
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
*/
|
||||
static inline void spi_ll_enable_int(spi_dev_t *hw)
|
||||
{
|
||||
hw->slave.trans_inten = 1;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* DMA:
|
||||
* RX DMA (Peripherals->DMA->RAM)
|
||||
* TX DMA (RAM->DMA->Peripherals)
|
||||
*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Reset RX DMA which stores the data received from a peripheral into RAM.
|
||||
*
|
||||
* @param dma_in Beginning address of the DMA peripheral registers which stores the data received from a peripheral into RAM.
|
||||
*/
|
||||
static inline void spi_dma_ll_rx_reset(spi_dma_dev_t *dma_in)
|
||||
{
|
||||
//Reset RX DMA peripheral
|
||||
dma_in->dma_conf.in_rst = 1;
|
||||
dma_in->dma_conf.in_rst = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start RX DMA.
|
||||
*
|
||||
* @param dma_in Beginning address of the DMA peripheral registers which stores the data received from a peripheral into RAM.
|
||||
* @param addr Address of the beginning DMA descriptor.
|
||||
*/
|
||||
static inline void spi_dma_ll_rx_start(spi_dma_dev_t *dma_in, lldesc_t *addr)
|
||||
{
|
||||
dma_in->dma_in_link.addr = (int) addr & 0xFFFFF;
|
||||
dma_in->dma_in_link.start = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable DMA RX channel burst for data
|
||||
*
|
||||
* @param dma_in Beginning address of the DMA peripheral registers which stores the data received from a peripheral into RAM.
|
||||
* @param enable True to enable, false to disable
|
||||
*/
|
||||
static inline void spi_dma_ll_rx_enable_burst_data(spi_dma_dev_t *dma_out, bool enable)
|
||||
{
|
||||
//This is not supported in esp32
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable DMA RX channel burst for descriptor
|
||||
*
|
||||
* @param dma_in Beginning address of the DMA peripheral registers which stores the data received from a peripheral into RAM.
|
||||
* @param enable True to enable, false to disable
|
||||
*/
|
||||
static inline void spi_dma_ll_rx_enable_burst_desc(spi_dma_dev_t *dma_in, bool enable)
|
||||
{
|
||||
dma_in->dma_conf.indscr_burst_en = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configuration of RX DMA EOF interrupt generation way
|
||||
*
|
||||
* @param dma_in Beginning address of the DMA peripheral registers which stores the data received from a peripheral into RAM.
|
||||
* @param enable 1: spi_dma_inlink_eof is set when the number of dma pushed data bytes is equal to the value of spi_slv/mst_dma_rd_bytelen[19:0] in spi dma transition. 0: spi_dma_inlink_eof is set by spi_trans_done in non-seg-trans or spi_dma_seg_trans_done in seg-trans.
|
||||
*/
|
||||
static inline void spi_dma_ll_set_rx_eof_generation(spi_dma_dev_t *dma_in, bool enable)
|
||||
{
|
||||
//does not available in ESP32
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset TX DMA which transmits the data from RAM to a peripheral.
|
||||
*
|
||||
* @param dma_out Beginning address of the DMA peripheral registers which transmits the data from RAM to a peripheral.
|
||||
*/
|
||||
static inline void spi_dma_ll_tx_reset(spi_dma_dev_t *dma_out)
|
||||
{
|
||||
//Reset TX DMA peripheral
|
||||
dma_out->dma_conf.out_rst = 1;
|
||||
dma_out->dma_conf.out_rst = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start TX DMA.
|
||||
*
|
||||
* @param dma_out Beginning address of the DMA peripheral registers which transmits the data from RAM to a peripheral.
|
||||
* @param addr Address of the beginning DMA descriptor.
|
||||
*/
|
||||
static inline void spi_dma_ll_tx_start(spi_dma_dev_t *dma_out, lldesc_t *addr)
|
||||
{
|
||||
dma_out->dma_out_link.addr = (int) addr & 0xFFFFF;
|
||||
dma_out->dma_out_link.start = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable DMA TX channel burst for data
|
||||
*
|
||||
* @param dma_out Beginning address of the DMA peripheral registers which transmits the data from RAM to a peripheral.
|
||||
* @param enable True to enable, false to disable
|
||||
*/
|
||||
static inline void spi_dma_ll_tx_enable_burst_data(spi_dma_dev_t *dma_out, bool enable)
|
||||
{
|
||||
dma_out->dma_conf.out_data_burst_en = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable DMA TX channel burst for descriptor
|
||||
*
|
||||
* @param dma_out Beginning address of the DMA peripheral registers which transmits the data from RAM to a peripheral.
|
||||
* @param enable True to enable, false to disable
|
||||
*/
|
||||
static inline void spi_dma_ll_tx_enable_burst_desc(spi_dma_dev_t *dma_out, bool enable)
|
||||
{
|
||||
dma_out->dma_conf.outdscr_burst_en = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable automatic outlink-writeback
|
||||
*
|
||||
* @param dma_out Beginning address of the DMA peripheral registers which transmits the data from RAM to a peripheral.
|
||||
* @param enable True to enable, false to disable
|
||||
*/
|
||||
static inline void spi_dma_ll_enable_out_auto_wrback(spi_dma_dev_t *dma_out, bool enable)
|
||||
{
|
||||
//does not configure it in ESP32
|
||||
}
|
||||
|
||||
#undef SPI_LL_RST_MASK
|
||||
#undef SPI_LL_UNUSED_INT_MASK
|
||||
|
@ -40,7 +40,7 @@ typedef struct {
|
||||
Note: Unreasonable settings can cause waveform to be oversaturated. Range: -128 ~ 127. */
|
||||
} dac_cw_config_t;
|
||||
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32S2
|
||||
#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
|
||||
|
||||
/**
|
||||
* @brief DAC digital controller (DMA mode) work mode.
|
||||
|
45
tools/sdk/esp32/include/hal/include/hal/dma_types.h
Normal file
45
tools/sdk/esp32/include/hal/include/hal/dma_types.h
Normal file
@ -0,0 +1,45 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* @brief Type of DMA descriptor
|
||||
*
|
||||
*/
|
||||
typedef struct dma_descriptor_s {
|
||||
struct {
|
||||
uint32_t size : 12; /*!< Buffer size */
|
||||
uint32_t length : 12; /*!< Number of valid bytes in the buffer */
|
||||
uint32_t reversed24_27 : 4; /*!< Reserved */
|
||||
uint32_t err_eof : 1; /*!< Whether the received buffer contains error */
|
||||
uint32_t reserved29 : 1; /*!< Reserved */
|
||||
uint32_t suc_eof : 1; /*!< Whether the descriptor is the last one in the link */
|
||||
uint32_t owner : 1; /*!< Who is allowed to access the buffer that this descriptor points to */
|
||||
} dw0; /*!< Descriptor Word 0 */
|
||||
void *buffer; /*!< Pointer to the buffer */
|
||||
struct dma_descriptor_s *next; /*!< Pointer to the next descriptor (set to NULL if the descriptor is the last one, e.g. suc_eof=1) */
|
||||
} dma_descriptor_t;
|
||||
|
||||
_Static_assert(sizeof(dma_descriptor_t) == 12, "dma_descriptor_t should occupy 12 bytes in memory");
|
||||
|
||||
#define DMA_DESCRIPTOR_BUFFER_OWNER_CPU (0) /*!< DMA buffer is allowed to be accessed by CPU */
|
||||
#define DMA_DESCRIPTOR_BUFFER_OWNER_DMA (1) /*!< DMA buffer is allowed to be accessed by DMA engine */
|
||||
#define DMA_DESCRIPTOR_BUFFER_MAX_SIZE (4095) /*!< Maximum size of the buffer that can be attached to descriptor */
|
35
tools/sdk/esp32/include/hal/include/hal/gdma_hal.h
Normal file
35
tools/sdk/esp32/include/hal/include/hal/gdma_hal.h
Normal file
@ -0,0 +1,35 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/*******************************************************************************
|
||||
* NOTICE
|
||||
* The HAL is not public api, don't use in application code.
|
||||
* See readme.md in soc/README.md
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "soc/gdma_struct.h"
|
||||
|
||||
typedef struct {
|
||||
gdma_dev_t *dev;
|
||||
} gdma_hal_context_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -151,25 +151,6 @@ void i2s_hal_set_rx_mode(i2s_hal_context_t *hal, i2s_channel_t ch, i2s_bits_per_
|
||||
*/
|
||||
void i2s_hal_set_in_link(i2s_hal_context_t *hal, uint32_t rx_eof_num, uint32_t addr);
|
||||
|
||||
#if SOC_I2S_SUPPORTS_PDM
|
||||
/**
|
||||
* @brief Get I2S tx pdm
|
||||
*
|
||||
* @param hal Context of the HAL layer
|
||||
* @param fp tx pdm fp
|
||||
* @param fs tx pdm fs
|
||||
*/
|
||||
void i2s_hal_get_tx_pdm(i2s_hal_context_t *hal, int *fp, int *fs);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Get I2S rx sinc dsr 16 en
|
||||
*
|
||||
* @param hal Context of the HAL layer
|
||||
* @param en 0: disable, 1: enable
|
||||
*/
|
||||
#define i2s_hal_get_rx_sinc_dsr_16_en(hal, en) i2s_ll_get_rx_sinc_dsr_16_en((hal)->dev, en)
|
||||
|
||||
/**
|
||||
* @brief Set I2S clk div
|
||||
*
|
||||
@ -241,16 +222,6 @@ void i2s_hal_stop_tx(i2s_hal_context_t *hal);
|
||||
*/
|
||||
void i2s_hal_stop_rx(i2s_hal_context_t *hal);
|
||||
|
||||
#if SOC_I2S_SUPPORTS_PDM
|
||||
/**
|
||||
* @brief Set I2S pdm rx down sample
|
||||
*
|
||||
* @param hal Context of the HAL layer
|
||||
* @param dsr 0:disable, 1: enable
|
||||
*/
|
||||
#define i2s_hal_set_pdm_rx_down_sample(hal, dsr) i2s_ll_set_rx_sinc_dsr_16_en((hal)->dev, dsr)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Config I2S param
|
||||
*
|
||||
@ -288,6 +259,42 @@ void i2s_hal_enable_slave_mode(i2s_hal_context_t *hal);
|
||||
*/
|
||||
void i2s_hal_init(i2s_hal_context_t *hal, int i2s_num);
|
||||
|
||||
#if SOC_I2S_SUPPORTS_PDM
|
||||
/**
|
||||
* @brief Set I2S tx pdm
|
||||
*
|
||||
* @param hal Context of the HAL layer
|
||||
* @param fp tx pdm fp
|
||||
* @param fs tx pdm fs
|
||||
*/
|
||||
void i2s_hal_tx_pdm_cfg(i2s_hal_context_t *hal, uint32_t fp, uint32_t fs);
|
||||
|
||||
/**
|
||||
* @brief Get I2S tx pdm
|
||||
*
|
||||
* @param hal Context of the HAL layer
|
||||
* @param dsr rx pdm dsr
|
||||
*/
|
||||
void i2s_hal_rx_pdm_cfg(i2s_hal_context_t *hal, uint32_t dsr);
|
||||
|
||||
/**
|
||||
* @brief Get I2S tx pdm configuration
|
||||
*
|
||||
* @param hal Context of the HAL layer
|
||||
* @param fp Pointer to receive tx PDM fp configuration
|
||||
* @param fs Pointer to receive tx PDM fs configuration
|
||||
*/
|
||||
void i2s_hal_get_tx_pdm(i2s_hal_context_t *hal, uint32_t *fp, uint32_t *fs);
|
||||
|
||||
/**
|
||||
* @brief Get I2S rx pdm configuration
|
||||
*
|
||||
* @param hal Context of the HAL layer
|
||||
* @param dsr rx pdm dsr
|
||||
*/
|
||||
void i2s_hal_get_rx_pdm(i2s_hal_context_t *hal, uint32_t *dsr);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -0,0 +1,170 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "hal/interrupt_controller_types.h"
|
||||
#include "hal/interrupt_controller_ll.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Gets target platform interrupt descriptor table
|
||||
*
|
||||
* @return Address of interrupt descriptor table
|
||||
*/
|
||||
__attribute__((pure)) const int_desc_t *interrupt_controller_hal_desc_table(void);
|
||||
|
||||
/**
|
||||
* @brief Gets the interrupt type given an interrupt number.
|
||||
*
|
||||
* @param interrupt_number Interrupt number 0 to 31
|
||||
* @return interrupt type
|
||||
*/
|
||||
__attribute__((pure)) int_type_t interrupt_controller_hal_desc_type(int interrupt_number);
|
||||
|
||||
/**
|
||||
* @brief Gets the interrupt level given an interrupt number.
|
||||
*
|
||||
* @param interrupt_number Interrupt number 0 to 31
|
||||
* @return interrupt level bitmask
|
||||
*/
|
||||
__attribute__((pure)) int interrupt_controller_hal_desc_level(int interrupt_number);
|
||||
|
||||
/**
|
||||
* @brief Gets the cpu flags given the interrupt number and target cpu.
|
||||
*
|
||||
* @param interrupt_number Interrupt number 0 to 31
|
||||
* @param cpu_number CPU number between 0 and SOC_CPU_CORES_NUM - 1
|
||||
* @return flags for that interrupt number
|
||||
*/
|
||||
__attribute__((pure)) uint32_t interrupt_controller_hal_desc_flags(int interrupt_number, int cpu_number);
|
||||
|
||||
/**
|
||||
* @brief Gets the interrupt type given an interrupt number.
|
||||
*
|
||||
* @param interrupt_number Interrupt number 0 to 31
|
||||
* @return interrupt type
|
||||
*/
|
||||
static inline int_type_t interrupt_controller_hal_get_type(int interrupt_number)
|
||||
{
|
||||
return interrupt_controller_hal_desc_type(interrupt_number);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the interrupt level given an interrupt number.
|
||||
*
|
||||
* @param interrupt_number Interrupt number 0 to 31
|
||||
* @return interrupt level bitmask
|
||||
*/
|
||||
static inline int interrupt_controller_hal_get_level(int interrupt_number)
|
||||
{
|
||||
return interrupt_controller_hal_desc_level(interrupt_number);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the cpu flags given the interrupt number and target cpu.
|
||||
*
|
||||
* @param interrupt_number Interrupt number 0 to 31
|
||||
* @param cpu_number CPU number between 0 and SOC_CPU_CORES_NUM - 1
|
||||
* @return flags for that interrupt number
|
||||
*/
|
||||
static inline uint32_t interrupt_controller_hal_get_cpu_desc_flags(int interrupt_number, int cpu_number)
|
||||
{
|
||||
return interrupt_controller_hal_desc_flags(interrupt_number, cpu_number);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief enable interrupts specified by the mask
|
||||
*
|
||||
* @param mask bitmask of interrupts that needs to be enabled
|
||||
*/
|
||||
static inline void interrupt_controller_hal_enable_interrupts(uint32_t mask)
|
||||
{
|
||||
intr_cntrl_ll_enable_interrupts(mask);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief disable interrupts specified by the mask
|
||||
*
|
||||
* @param mask bitmask of interrupts that needs to be disabled
|
||||
*/
|
||||
static inline void interrupt_controller_hal_disable_interrupts(uint32_t mask)
|
||||
{
|
||||
intr_cntrl_ll_disable_interrupts(mask);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief checks if given interrupt number has a valid handler
|
||||
*
|
||||
* @param intr interrupt number ranged from 0 to 31
|
||||
* @param cpu cpu number ranged betweeen 0 to SOC_CPU_CORES_NUM - 1
|
||||
* @return true for valid handler, false otherwise
|
||||
*/
|
||||
static inline bool interrupt_controller_hal_has_handler(int intr, int cpu)
|
||||
{
|
||||
return intr_cntrl_ll_has_handler(intr, cpu);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief sets interrupt handler and optional argument of a given interrupt number
|
||||
*
|
||||
* @param intr interrupt number ranged from 0 to 31
|
||||
* @param handler handler invoked when an interrupt occurs
|
||||
* @param arg optional argument to pass to the handler
|
||||
*/
|
||||
static inline void interrupt_controller_hal_set_int_handler(uint8_t intr, interrupt_handler_t handler, void *arg)
|
||||
{
|
||||
intr_cntrl_ll_set_int_handler(intr, handler, arg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets argument passed to handler of a given interrupt number
|
||||
*
|
||||
* @param intr interrupt number ranged from 0 to 31
|
||||
*
|
||||
* @return argument used by handler of passed interrupt number
|
||||
*/
|
||||
static inline void * interrupt_controller_hal_get_int_handler_arg(uint8_t intr)
|
||||
{
|
||||
return intr_cntrl_ll_get_int_handler_arg(intr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Disables interrupts that are not located in iram
|
||||
*
|
||||
* @param newmask mask of interrupts needs to be disabled
|
||||
* @return oldmask where to store old interrupts state
|
||||
*/
|
||||
static inline uint32_t interrupt_controller_hal_disable_int_mask(uint32_t newmask)
|
||||
{
|
||||
return intr_cntrl_ll_disable_int_mask(newmask);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enables interrupts that are not located in iram
|
||||
*
|
||||
* @param newmask mask of interrupts needs to be disabled
|
||||
*/
|
||||
static inline void interrupt_controller_hal_enable_int_mask(uint32_t newmask)
|
||||
{
|
||||
intr_cntrl_ll_enable_int_mask(newmask);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -0,0 +1,46 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
#include "soc/soc.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
INTDESC_NORMAL=0,
|
||||
INTDESC_RESVD,
|
||||
INTDESC_SPECIAL
|
||||
} int_desc_flag_t;
|
||||
|
||||
typedef enum {
|
||||
INTTP_LEVEL=0,
|
||||
INTTP_EDGE,
|
||||
INTTP_NA
|
||||
} int_type_t;
|
||||
|
||||
typedef struct {
|
||||
int level;
|
||||
int_type_t type;
|
||||
int_desc_flag_t cpuflags[SOC_CPU_CORES_NUM];
|
||||
} int_desc_t;
|
||||
|
||||
typedef void (*interrupt_handler_t)(void *arg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -17,6 +17,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include "soc/rmt_struct.h"
|
||||
#include "soc/rmt_caps.h"
|
||||
|
||||
|
33
tools/sdk/esp32/include/hal/include/hal/rtc_hal.h
Normal file
33
tools/sdk/esp32/include/hal/include/hal/rtc_hal.h
Normal file
@ -0,0 +1,33 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "hal/gpio_types.h"
|
||||
#include "hal/rtc_io_ll.h"
|
||||
#include "hal/rtc_cntl_ll.h"
|
||||
|
||||
#define rtc_hal_ext1_get_wakeup_pins() rtc_cntl_ll_ext1_get_wakeup_pins()
|
||||
|
||||
#define rtc_hal_ext1_set_wakeup_pins(mask, mode) rtc_cntl_ll_ext1_set_wakeup_pins(mask, mode)
|
||||
|
||||
#define rtc_hal_ext1_clear_wakeup_pins() rtc_cntl_ll_ext1_clear_wakeup_pins()
|
||||
|
||||
#define rtc_hal_set_wakeup_timer(ticks) rtc_cntl_ll_set_wakeup_timer(ticks)
|
||||
|
||||
/*
|
||||
* Enable wakeup from ULP coprocessor.
|
||||
*/
|
||||
#define rtc_hal_ulp_wakeup_enable() rtc_cntl_ll_ulp_wakeup_enable()
|
||||
|
38
tools/sdk/esp32/include/hal/include/hal/sha_types.h
Normal file
38
tools/sdk/esp32/include/hal/include/hal/sha_types.h
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
/* Use enum from rom for backwards compatibility */
|
||||
#if CONFIG_IDF_TARGET_ESP32
|
||||
#include "esp32/rom/sha.h"
|
||||
typedef enum SHA_TYPE esp_sha_type;
|
||||
#elif CONFIG_IDF_TARGET_ESP32S2
|
||||
#include "esp32s2/rom/sha.h"
|
||||
typedef SHA_TYPE esp_sha_type;
|
||||
#elif CONFIG_IDF_TARGET_ESP32S3
|
||||
#include "esp32s3/rom/sha.h"
|
||||
typedef SHA_TYPE esp_sha_type;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -38,83 +38,115 @@
|
||||
#include <esp_err.h>
|
||||
#include "soc/lldesc.h"
|
||||
|
||||
/**
|
||||
* Input parameters to the ``spi_hal_cal_clock_conf`` to calculate the timing configuration
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t half_duplex; ///< Whether half duplex mode is used, device specific
|
||||
uint32_t no_compensate; ///< No need to add dummy to compensate the timing, device specific
|
||||
uint32_t clock_speed_hz; ///< Desired frequency.
|
||||
uint32_t duty_cycle; ///< Desired duty cycle of SPI clock
|
||||
uint32_t input_delay_ns; /**< Maximum delay between SPI launch clock and the data to be valid.
|
||||
* This is used to compensate/calculate the maximum frequency allowed.
|
||||
* Left 0 if not known.
|
||||
*/
|
||||
bool use_gpio; ///< True if the GPIO matrix is used, otherwise false
|
||||
} spi_hal_timing_param_t;
|
||||
|
||||
/**
|
||||
* Timing configuration structure that should be calculated by
|
||||
* ``spi_hal_setup_clock`` at initialization and hold. Filled into the
|
||||
* ``spi_hal_cal_clock_conf`` at initialization and hold. Filled into the
|
||||
* ``timing_conf`` member of the context of HAL before setup a device.
|
||||
*/
|
||||
typedef struct {
|
||||
spi_ll_clock_val_t clock_reg; ///< Register value used by the LL layer
|
||||
int timing_dummy; ///< Extra dummy needed to compensate the timing
|
||||
int timing_miso_delay; ///< Extra miso delay clocks to compensate the timing
|
||||
spi_ll_clock_val_t clock_reg; ///< Register value used by the LL layer
|
||||
int timing_dummy; ///< Extra dummy needed to compensate the timing
|
||||
int timing_miso_delay; ///< Extra miso delay clocks to compensate the timing
|
||||
} spi_hal_timing_conf_t;
|
||||
|
||||
/**
|
||||
* DMA configuration structure
|
||||
* Should be set by driver at initialization
|
||||
*/
|
||||
typedef struct {
|
||||
spi_dma_dev_t *dma_in; ///< Input DMA(DMA -> RAM) peripheral register address
|
||||
spi_dma_dev_t *dma_out; ///< Output DMA(RAM -> DMA) peripheral register address
|
||||
lldesc_t *dmadesc_tx; /**< Array of DMA descriptor used by the TX DMA.
|
||||
* The amount should be larger than dmadesc_n. The driver should ensure that
|
||||
* the data to be sent is shorter than the descriptors can hold.
|
||||
*/
|
||||
lldesc_t *dmadesc_rx; /**< Array of DMA descriptor used by the RX DMA.
|
||||
* The amount should be larger than dmadesc_n. The driver should ensure that
|
||||
* the data to be sent is shorter than the descriptors can hold.
|
||||
*/
|
||||
int dmadesc_n; ///< The amount of descriptors of both ``dmadesc_tx`` and ``dmadesc_rx`` that the HAL can use.
|
||||
} spi_hal_dma_config_t;
|
||||
|
||||
/**
|
||||
* Transaction configuration structure, this should be assigned by driver each time.
|
||||
* All these parameters will be updated to the peripheral every transaction.
|
||||
*/
|
||||
typedef struct {
|
||||
uint16_t cmd; ///< Command value to be sent
|
||||
int cmd_bits; ///< Length (in bits) of the command phase
|
||||
int addr_bits; ///< Length (in bits) of the address phase
|
||||
int dummy_bits; ///< Base length (in bits) of the dummy phase. Note when the compensation is enabled, some extra dummy bits may be appended.
|
||||
int tx_bitlen; ///< TX length, in bits
|
||||
int rx_bitlen; ///< RX length, in bits
|
||||
uint64_t addr; ///< Address value to be sent
|
||||
uint8_t *send_buffer; ///< Data to be sent
|
||||
uint8_t *rcv_buffer; ///< Buffer to hold the receive data.
|
||||
spi_ll_io_mode_t io_mode; ///< IO mode of the master
|
||||
} spi_hal_trans_config_t;
|
||||
|
||||
/**
|
||||
* Context that should be maintained by both the driver and the HAL.
|
||||
*/
|
||||
typedef struct {
|
||||
/* configured by driver at initialization, don't touch */
|
||||
spi_dev_t *hw; ///< Beginning address of the peripheral registers.
|
||||
/* should be configured by driver at initialization */
|
||||
lldesc_t *dmadesc_tx; /**< Array of DMA descriptor used by the TX DMA.
|
||||
* The amount should be larger than dmadesc_n. The driver should ensure that
|
||||
* the data to be sent is shorter than the descriptors can hold.
|
||||
*/
|
||||
lldesc_t *dmadesc_rx; /**< Array of DMA descriptor used by the RX DMA.
|
||||
* The amount should be larger than dmadesc_n. The driver should ensure that
|
||||
* the data to be sent is shorter than the descriptors can hold.
|
||||
*/
|
||||
int dmadesc_n; ///< The amount of descriptors of both ``dmadesc_tx`` and ``dmadesc_rx`` that the HAL can use.
|
||||
/*
|
||||
* Device specific, all these parameters will be updated to the peripheral
|
||||
* only when ``spi_hal_setup_device``. They may not get updated when
|
||||
* ``spi_hal_setup_trans``.
|
||||
*/
|
||||
/* Configured by driver at initialization, don't touch */
|
||||
spi_dev_t *hw; ///< Beginning address of the peripheral registers.
|
||||
spi_dma_dev_t *dma_in; ///< Address of the DMA peripheral registers which stores the data received from a peripheral into RAM (DMA -> RAM).
|
||||
spi_dma_dev_t *dma_out; ///< Address of the DMA peripheral registers which transmits the data from RAM to a peripheral (RAM -> DMA).
|
||||
bool dma_enabled; ///< Whether the DMA is enabled, do not update after initialization
|
||||
spi_hal_dma_config_t dma_config; ///< DMA configuration
|
||||
|
||||
/* Internal parameters, don't touch */
|
||||
spi_hal_trans_config_t trans_config; ///< Transaction configuration
|
||||
} spi_hal_context_t;
|
||||
|
||||
/**
|
||||
* Device configuration structure, this should be initialised by driver based on different devices respectively.
|
||||
* All these parameters will be updated to the peripheral only when ``spi_hal_setup_device``.
|
||||
* They may not get updated when ``spi_hal_setup_trans``.
|
||||
*/
|
||||
typedef struct {
|
||||
int mode; ///< SPI mode, device specific
|
||||
int cs_setup; ///< Setup time of CS active edge before the first SPI clock, device specific
|
||||
int cs_hold; ///< Hold time of CS inactive edge after the last SPI clock, device specific
|
||||
int cs_pin_id; ///< CS pin to use, 0-2, otherwise all the CS pins are not used. Device specific
|
||||
spi_hal_timing_conf_t *timing_conf; /**< Pointer to an structure holding
|
||||
* the pre-calculated timing configuration for the device at initialization,
|
||||
* device specific
|
||||
spi_hal_timing_conf_t timing_conf; /**< This structure holds the pre-calculated timing configuration for the device
|
||||
* at initialization, device specific
|
||||
*/
|
||||
struct {
|
||||
uint32_t sio : 1; ///< Whether to use SIO mode, device specific
|
||||
uint32_t half_duplex : 1; ///< Whether half duplex mode is used, device specific
|
||||
uint32_t tx_lsbfirst : 1; ///< Whether LSB is sent first for TX data, device specific
|
||||
uint32_t rx_lsbfirst : 1; ///< Whether LSB is received first for RX data, device specific
|
||||
uint32_t dma_enabled : 1; ///< Whether the DMA is enabled, do not update after initialization
|
||||
uint32_t no_compensate : 1; ///< No need to add dummy to compensate the timing, device specific
|
||||
uint32_t sio : 1; ///< Whether to use SIO mode, device specific
|
||||
uint32_t half_duplex : 1; ///< Whether half duplex mode is used, device specific
|
||||
uint32_t tx_lsbfirst : 1; ///< Whether LSB is sent first for TX data, device specific
|
||||
uint32_t rx_lsbfirst : 1; ///< Whether LSB is received first for RX data, device specific
|
||||
uint32_t no_compensate : 1; ///< No need to add dummy to compensate the timing, device specific
|
||||
#ifdef SOC_SPI_SUPPORT_AS_CS
|
||||
uint32_t as_cs : 1; ///< Whether to toggle the CS while the clock toggles, device specific
|
||||
uint32_t as_cs : 1; ///< Whether to toggle the CS while the clock toggles, device specific
|
||||
#endif
|
||||
uint32_t positive_cs : 1; ///< Whether the postive CS feature is abled, device specific
|
||||
uint32_t positive_cs : 1; ///< Whether the postive CS feature is abled, device specific
|
||||
};//boolean configurations
|
||||
|
||||
/*
|
||||
* Transaction specific (data), all these parameters will be updated to the
|
||||
* peripheral every transaction.
|
||||
*/
|
||||
uint16_t cmd; ///< Command value to be sent
|
||||
int cmd_bits; ///< Length (in bits) of the command phase
|
||||
int addr_bits; ///< Length (in bits) of the address phase
|
||||
int dummy_bits; ///< Base length (in bits) of the dummy phase. Note when the compensation is enabled, some extra dummy bits may be appended.
|
||||
int tx_bitlen; ///< TX length, in bits
|
||||
int rx_bitlen; ///< RX length, in bits
|
||||
uint64_t addr; ///< Address value to be sent
|
||||
uint8_t *send_buffer; ///< Data to be sent
|
||||
uint8_t *rcv_buffer; ///< Buffer to hold the receive data.
|
||||
spi_ll_io_mode_t io_mode; ///< IO mode of the master
|
||||
|
||||
} spi_hal_context_t;
|
||||
} spi_hal_dev_config_t;
|
||||
|
||||
/**
|
||||
* Init the peripheral and the context.
|
||||
*
|
||||
* @param hal Context of the HAL layer.
|
||||
* @param hal Context of the HAL layer.
|
||||
* @param host_id Index of the SPI peripheral. 0 for SPI1, 1 for HSPI (SPI2) and 2 for VSPI (SPI3).
|
||||
*/
|
||||
void spi_hal_init(spi_hal_context_t *hal, int host_id);
|
||||
void spi_hal_init(spi_hal_context_t *hal, uint32_t host_id, const spi_hal_dma_config_t *hal_dma_config);
|
||||
|
||||
/**
|
||||
* Deinit the peripheral (and the context if needed).
|
||||
@ -126,23 +158,28 @@ void spi_hal_deinit(spi_hal_context_t *hal);
|
||||
/**
|
||||
* Setup device-related configurations according to the settings in the context.
|
||||
*
|
||||
* @param hal Context of the HAL layer.
|
||||
* @param hal Context of the HAL layer.
|
||||
* @param hal_dev Device configuration
|
||||
*/
|
||||
void spi_hal_setup_device(const spi_hal_context_t *hal);
|
||||
void spi_hal_setup_device(spi_hal_context_t *hal, const spi_hal_dev_config_t *hal_dev);
|
||||
|
||||
/**
|
||||
* Setup transaction related configurations according to the settings in the context.
|
||||
*
|
||||
* @param hal Context of the HAL layer.
|
||||
* @param hal Context of the HAL layer.
|
||||
* @param hal_dev Device configuration
|
||||
* @param hal_trans Transaction configuration
|
||||
*/
|
||||
void spi_hal_setup_trans(const spi_hal_context_t *hal);
|
||||
void spi_hal_setup_trans(spi_hal_context_t *hal, const spi_hal_dev_config_t *hal_dev, const spi_hal_trans_config_t *hal_trans);
|
||||
|
||||
/**
|
||||
* Prepare the data for the current transaction.
|
||||
*
|
||||
* @param hal Context of the HAL layer.
|
||||
* @param hal Context of the HAL layer.
|
||||
* @param hal_dev Device configuration
|
||||
* @param hal_trans Transaction configuration
|
||||
*/
|
||||
void spi_hal_prepare_data(const spi_hal_context_t *hal);
|
||||
void spi_hal_prepare_data(spi_hal_context_t *hal, const spi_hal_dev_config_t *hal_dev, const spi_hal_trans_config_t *hal_trans);
|
||||
|
||||
/**
|
||||
* Trigger start a user-defined transaction.
|
||||
@ -161,7 +198,7 @@ bool spi_hal_usr_is_done(const spi_hal_context_t *hal);
|
||||
/**
|
||||
* Post transaction operations, mainly fetch data from the buffer.
|
||||
*
|
||||
* @param hal Context of the HAL layer.
|
||||
* @param hal Context of the HAL layer.
|
||||
*/
|
||||
void spi_hal_fetch_result(const spi_hal_context_t *hal);
|
||||
|
||||
@ -173,50 +210,44 @@ void spi_hal_fetch_result(const spi_hal_context_t *hal);
|
||||
*
|
||||
* It is highly suggested to do this at initialization, since it takes long time.
|
||||
*
|
||||
* @param hal Context of the HAL layer.
|
||||
* @param speed_hz Desired frequency.
|
||||
* @param duty_cycle Desired duty cycle of SPI clock
|
||||
* @param use_gpio true if the GPIO matrix is used, otherwise false
|
||||
* @param input_delay_ns Maximum delay between SPI launch clock and the data to
|
||||
* be valid. This is used to compensate/calculate the maximum frequency
|
||||
* allowed. Left 0 if not known.
|
||||
* @param out_freq Output of the actual frequency, left NULL if not required.
|
||||
* @param timing_conf Output of the timing configuration.
|
||||
* @param timing_param Input parameters to calculate timing configuration
|
||||
* @param out_freq Output of the actual frequency, left NULL if not required.
|
||||
* @param timing_conf Output of the timing configuration.
|
||||
*
|
||||
* @return ESP_OK if desired is available, otherwise fail.
|
||||
*/
|
||||
esp_err_t spi_hal_cal_clock_conf(const spi_hal_context_t *hal, int speed_hz, int duty_cycle, bool use_gpio, int input_delay_ns, int *out_freq, spi_hal_timing_conf_t *timing_conf);
|
||||
esp_err_t spi_hal_cal_clock_conf(const spi_hal_timing_param_t *timing_param, int *out_freq, spi_hal_timing_conf_t *timing_conf);
|
||||
|
||||
/**
|
||||
* Get the frequency actual used.
|
||||
*
|
||||
* @param hal Context of the HAL layer.
|
||||
* @param fapb APB clock frequency.
|
||||
* @param hz Desired frequencyc.
|
||||
* @param duty_cycle Desired duty cycle.
|
||||
* @param hal Context of the HAL layer.
|
||||
* @param fapb APB clock frequency.
|
||||
* @param hz Desired frequencyc.
|
||||
* @param duty_cycle Desired duty cycle.
|
||||
*/
|
||||
int spi_hal_master_cal_clock(int fapb, int hz, int duty_cycle);
|
||||
|
||||
/**
|
||||
* Get the timing configuration for given parameters.
|
||||
*
|
||||
* @param eff_clk Actual SPI clock frequency
|
||||
* @param gpio_is_used true if the GPIO matrix is used, otherwise false.
|
||||
* @param eff_clk Actual SPI clock frequency
|
||||
* @param gpio_is_used true if the GPIO matrix is used, otherwise false.
|
||||
* @param input_delay_ns Maximum delay between SPI launch clock and the data to
|
||||
* be valid. This is used to compensate/calculate the maximum frequency
|
||||
* allowed. Left 0 if not known.
|
||||
* @param dummy_n Dummy cycles required to correctly read the data.
|
||||
* @param miso_delay_n suggested delay on the MISO line, in APB clocks.
|
||||
* be valid. This is used to compensate/calculate the maximum frequency
|
||||
* allowed. Left 0 if not known.
|
||||
* @param dummy_n Dummy cycles required to correctly read the data.
|
||||
* @param miso_delay_n suggested delay on the MISO line, in APB clocks.
|
||||
*/
|
||||
void spi_hal_cal_timing(int eff_clk, bool gpio_is_used, int input_delay_ns, int *dummy_n, int *miso_delay_n);
|
||||
|
||||
/**
|
||||
* Get the maximum frequency allowed to read if no compensation is used.
|
||||
*
|
||||
* @param gpio_is_used true if the GPIO matrix is used, otherwise false.
|
||||
* @param gpio_is_used true if the GPIO matrix is used, otherwise false.
|
||||
* @param input_delay_ns Maximum delay between SPI launch clock and the data to
|
||||
* be valid. This is used to compensate/calculate the maximum frequency
|
||||
* allowed. Left 0 if not known.
|
||||
* be valid. This is used to compensate/calculate the maximum frequency
|
||||
* allowed. Left 0 if not known.
|
||||
*/
|
||||
int spi_hal_get_freq_limit(bool gpio_is_used, int input_delay_ns);
|
||||
|
||||
|
@ -36,32 +36,35 @@
|
||||
#include "soc/spi_struct.h"
|
||||
#include <esp_types.h>
|
||||
#include "soc/spi_caps.h"
|
||||
#include "hal/spi_ll.h"
|
||||
|
||||
/**
|
||||
* Context that should be maintained by both the driver and the HAL.
|
||||
*/
|
||||
typedef struct {
|
||||
/* configured by driver at initialization, don't touch */
|
||||
spi_dev_t *hw; ///< Beginning address of the peripheral registers.
|
||||
spi_dev_t *hw; ///< Beginning address of the peripheral registers.
|
||||
spi_dma_dev_t *dma_in; ///< Address of the DMA peripheral registers which stores the data received from a peripheral into RAM.
|
||||
spi_dma_dev_t *dma_out; ///< Address of the DMA peripheral registers which transmits the data from RAM to a peripheral.
|
||||
/* should be configured by driver at initialization */
|
||||
lldesc_t *dmadesc_rx; /**< Array of DMA descriptor used by the TX DMA.
|
||||
* The amount should be larger than dmadesc_n. The driver should ensure that
|
||||
* the data to be sent is shorter than the descriptors can hold.
|
||||
*/
|
||||
lldesc_t *dmadesc_tx; /**< Array of DMA descriptor used by the RX DMA.
|
||||
* The amount should be larger than dmadesc_n. The driver should ensure that
|
||||
* the data to be sent is shorter than the descriptors can hold.
|
||||
*/
|
||||
int dmadesc_n; ///< The amount of descriptors of both ``dmadesc_tx`` and ``dmadesc_rx`` that the HAL can use.
|
||||
lldesc_t *dmadesc_rx; /**< Array of DMA descriptor used by the TX DMA.
|
||||
* The amount should be larger than dmadesc_n. The driver should ensure that
|
||||
* the data to be sent is shorter than the descriptors can hold.
|
||||
*/
|
||||
lldesc_t *dmadesc_tx; /**< Array of DMA descriptor used by the RX DMA.
|
||||
* The amount should be larger than dmadesc_n. The driver should ensure that
|
||||
* the data to be sent is shorter than the descriptors can hold.
|
||||
*/
|
||||
int dmadesc_n; ///< The amount of descriptors of both ``dmadesc_tx`` and ``dmadesc_rx`` that the HAL can use.
|
||||
|
||||
/*
|
||||
* configurations to be filled after ``spi_slave_hal_init``. Updated to
|
||||
* peripheral registers when ``spi_slave_hal_setup_device`` is called.
|
||||
*/
|
||||
struct {
|
||||
uint32_t rx_lsbfirst : 1;
|
||||
uint32_t tx_lsbfirst : 1;
|
||||
uint32_t use_dma : 1;
|
||||
uint32_t rx_lsbfirst : 1;
|
||||
uint32_t tx_lsbfirst : 1;
|
||||
uint32_t use_dma : 1;
|
||||
};
|
||||
int mode;
|
||||
|
||||
@ -69,21 +72,27 @@ typedef struct {
|
||||
* Transaction specific (data), all these parameters will be updated to the
|
||||
* peripheral every transaction.
|
||||
*/
|
||||
uint32_t bitlen; ///< Expected maximum length of the transaction, in bits.
|
||||
const void *tx_buffer; ///< Data to be sent
|
||||
void *rx_buffer; ///< Buffer to hold the received data.
|
||||
uint32_t bitlen; ///< Expected maximum length of the transaction, in bits.
|
||||
const void *tx_buffer; ///< Data to be sent
|
||||
void *rx_buffer; ///< Buffer to hold the received data.
|
||||
|
||||
/* Other transaction result after one transaction */
|
||||
uint32_t rcv_bitlen; ///< Length of the last transaction, in bits.
|
||||
uint32_t rcv_bitlen; ///< Length of the last transaction, in bits.
|
||||
} spi_slave_hal_context_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t host_id; ///< SPI controller ID
|
||||
spi_dma_dev_t *dma_in; ///< Input DMA(DMA -> RAM) peripheral register address
|
||||
spi_dma_dev_t *dma_out; ///< Output DMA(RAM -> DMA) peripheral register address
|
||||
} spi_slave_hal_config_t;
|
||||
|
||||
/**
|
||||
* Init the peripheral and the context.
|
||||
*
|
||||
* @param hal Context of the HAL layer.
|
||||
* @param hal Context of the HAL layer.
|
||||
* @param host_id Index of the SPI peripheral. 0 for SPI1, 1 for HSPI (SPI2) and 2 for VSPI (SPI3).
|
||||
*/
|
||||
void spi_slave_hal_init(spi_slave_hal_context_t *hal, int host_id);
|
||||
void spi_slave_hal_init(spi_slave_hal_context_t *hal, const spi_slave_hal_config_t *hal_config);
|
||||
|
||||
/**
|
||||
* Deinit the peripheral (and the context if needed).
|
||||
|
@ -22,7 +22,7 @@
|
||||
* The HAL layer for SPI Slave HD mode, currently only segment mode is supported
|
||||
*
|
||||
* Usage:
|
||||
* - Firstly, initialize the slave with `slave_hd_hal_init`
|
||||
* - Firstly, initialize the slave with `spi_slave_hd_hal_init`
|
||||
*
|
||||
* - Event handling:
|
||||
* - (Optional) Call ``spi_slave_hd_hal_enable_event_intr`` to enable the used interrupts
|
||||
@ -56,54 +56,56 @@
|
||||
#include "hal/spi_ll.h"
|
||||
#include "hal/spi_types.h"
|
||||
|
||||
|
||||
/// Configuration of the HAL
|
||||
typedef struct {
|
||||
int host_id; ///< Host ID of the spi peripheral
|
||||
int spics_io_num; ///< CS GPIO pin for this device
|
||||
uint8_t mode; ///< SPI mode (0-3)
|
||||
int command_bits; ///< command field bits, multiples of 8 and at least 8.
|
||||
int address_bits; ///< address field bits, multiples of 8 and at least 8.
|
||||
int dummy_bits; ///< dummy field bits, multiples of 8 and at least 8.
|
||||
uint32_t host_id; ///< Host ID of the spi peripheral
|
||||
spi_dma_dev_t *dma_in; ///< Input DMA(DMA -> RAM) peripheral register address
|
||||
spi_dma_dev_t *dma_out; ///< Output DMA(RAM -> DMA) peripheral register address
|
||||
uint32_t spics_io_num; ///< CS GPIO pin for this device
|
||||
uint8_t mode; ///< SPI mode (0-3)
|
||||
uint32_t command_bits; ///< command field bits, multiples of 8 and at least 8.
|
||||
uint32_t address_bits; ///< address field bits, multiples of 8 and at least 8.
|
||||
uint32_t dummy_bits; ///< dummy field bits, multiples of 8 and at least 8.
|
||||
|
||||
struct {
|
||||
uint32_t tx_lsbfirst : 1;///< Whether TX data should be sent with LSB first.
|
||||
uint32_t rx_lsbfirst : 1;///< Whether RX data should be read with LSB first.
|
||||
uint32_t tx_lsbfirst : 1; ///< Whether TX data should be sent with LSB first.
|
||||
uint32_t rx_lsbfirst : 1; ///< Whether RX data should be read with LSB first.
|
||||
};
|
||||
int dma_chan; ///< The dma channel used.
|
||||
uint32_t dma_chan; ///< The dma channel used.
|
||||
} spi_slave_hd_hal_config_t;
|
||||
|
||||
/// Context of the HAL, initialized by :cpp:func:`slave_hd_hal_init`.
|
||||
/// Context of the HAL, initialized by :cpp:func:`spi_slave_hd_hal_init`.
|
||||
typedef struct {
|
||||
spi_dev_t* dev; ///< Beginning address of the peripheral registers.
|
||||
lldesc_t *dmadesc_tx; /**< Array of DMA descriptor used by the TX DMA.
|
||||
* The amount should be larger than dmadesc_n. The driver should ensure that
|
||||
* the data to be sent is shorter than the descriptors can hold.
|
||||
*/
|
||||
lldesc_t *dmadesc_rx; /**< Array of DMA descriptor used by the RX DMA.
|
||||
* The amount should be larger than dmadesc_n. The driver should ensure that
|
||||
* the data to be sent is shorter than the descriptors can hold.
|
||||
*/
|
||||
spi_dev_t *dev; ///< Beginning address of the peripheral registers.
|
||||
spi_dma_dev_t *dma_in; ///< Address of the DMA peripheral registers which stores the data received from a peripheral into RAM.
|
||||
spi_dma_dev_t *dma_out; ///< Address of the DMA peripheral registers which transmits the data from RAM to a peripheral.
|
||||
lldesc_t *dmadesc_tx; /**< Array of DMA descriptor used by the TX DMA.
|
||||
* The amount should be larger than dmadesc_n. The driver should ensure that
|
||||
* the data to be sent is shorter than the descriptors can hold.
|
||||
*/
|
||||
lldesc_t *dmadesc_rx; /**< Array of DMA descriptor used by the RX DMA.
|
||||
* The amount should be larger than dmadesc_n. The driver should ensure that
|
||||
* the data to be sent is shorter than the descriptors can hold.
|
||||
*/
|
||||
|
||||
/* Internal status used by the HAL implementation, initialized as 0. */
|
||||
uint32_t intr_not_triggered;
|
||||
uint32_t intr_not_triggered;
|
||||
} spi_slave_hd_hal_context_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize the hardware and part of the context
|
||||
*
|
||||
* @param hal Context of the HAL layer
|
||||
* @param config Configuration of the HAL
|
||||
* @param hal Context of the HAL layer
|
||||
* @param hal_config Configuration of the HAL
|
||||
*/
|
||||
void slave_hd_hal_init(spi_slave_hd_hal_context_t *hal, const spi_slave_hd_hal_config_t *config);
|
||||
void spi_slave_hd_hal_init(spi_slave_hd_hal_context_t *hal, const spi_slave_hd_hal_config_t *hal_config);
|
||||
|
||||
/**
|
||||
* @brief Check and clear signal of one event
|
||||
*
|
||||
* @param hal Context of the HAL layer
|
||||
* @param ev Event to check
|
||||
* @return true if event triggered, otherwise false
|
||||
* @return True if event triggered, otherwise false
|
||||
*/
|
||||
bool spi_slave_hd_hal_check_clear_event(spi_slave_hd_hal_context_t* hal, spi_event_t ev);
|
||||
|
||||
@ -116,7 +118,7 @@ bool spi_slave_hd_hal_check_clear_event(spi_slave_hd_hal_context_t* hal, spi_eve
|
||||
*
|
||||
* @param hal Context of the HAL layer
|
||||
* @param ev Event to check and disable
|
||||
* @return true if event triggered, otherwise false
|
||||
* @return True if event triggered, otherwise false
|
||||
*/
|
||||
bool spi_slave_hd_hal_check_disable_event(spi_slave_hd_hal_context_t* hal, spi_event_t ev);
|
||||
|
||||
@ -156,7 +158,7 @@ void spi_slave_hd_hal_rxdma(spi_slave_hd_hal_context_t *hal, uint8_t *out_buf, s
|
||||
* @brief Get the length of total received data
|
||||
*
|
||||
* @param hal Context of the HAL layer
|
||||
* @return The received length
|
||||
* @return The received length
|
||||
*/
|
||||
int spi_slave_hd_hal_rxdma_get_len(spi_slave_hd_hal_context_t *hal);
|
||||
|
||||
@ -167,8 +169,8 @@ int spi_slave_hd_hal_rxdma_get_len(spi_slave_hd_hal_context_t *hal);
|
||||
* @brief Start the TX DMA operation with the specified buffer
|
||||
*
|
||||
* @param hal Context of the HAL layer
|
||||
* @param data Buffer of data to send
|
||||
* @param len Size of the buffer, also the maximum length to send
|
||||
* @param data Buffer of data to send
|
||||
* @param len Size of the buffer, also the maximum length to send
|
||||
*/
|
||||
void spi_slave_hd_hal_txdma(spi_slave_hd_hal_context_t *hal, uint8_t *data, size_t len);
|
||||
|
||||
@ -179,9 +181,9 @@ void spi_slave_hd_hal_txdma(spi_slave_hd_hal_context_t *hal, uint8_t *data, size
|
||||
* @brief Read from the shared register buffer
|
||||
*
|
||||
* @param hal Context of the HAL layer
|
||||
* @param addr Address of the shared regsiter to read
|
||||
* @param out_data Buffer to store the read data
|
||||
* @param len Length to read from the shared buffer
|
||||
* @param addr Address of the shared regsiter to read
|
||||
* @param out_data Buffer to store the read data
|
||||
* @param len Length to read from the shared buffer
|
||||
*/
|
||||
void spi_slave_hd_hal_read_buffer(spi_slave_hd_hal_context_t *hal, int addr, uint8_t *out_data, size_t len);
|
||||
|
||||
@ -199,7 +201,7 @@ void spi_slave_hd_hal_write_buffer(spi_slave_hd_hal_context_t *hal, int addr, ui
|
||||
* @brief Get the length of previous transaction.
|
||||
*
|
||||
* @param hal Context of the HAL layer
|
||||
* @return The length of previous transaction
|
||||
* @return The length of previous transaction
|
||||
*/
|
||||
int spi_slave_hd_hal_get_rxlen(spi_slave_hd_hal_context_t *hal);
|
||||
|
||||
@ -207,6 +209,6 @@ int spi_slave_hd_hal_get_rxlen(spi_slave_hd_hal_context_t *hal);
|
||||
* @brief Get the address of last transaction
|
||||
*
|
||||
* @param hal Context of the HAL layer
|
||||
* @return The address of last transaction
|
||||
* @return The address of last transaction
|
||||
*/
|
||||
int spi_slave_hd_hal_get_last_addr(spi_slave_hd_hal_context_t *hal);
|
||||
|
Reference in New Issue
Block a user