forked from espressif/arduino-esp32
Update IDF and Camera
This commit is contained in:
@ -69,62 +69,6 @@ typedef enum {
|
||||
ADC2_CTRL_FORCE_DIG = 6, /*!<For ADC2. Arbiter in shield mode. Force select digital controller work. */
|
||||
} adc_controller_t;
|
||||
|
||||
/* ADC calibration defines. */
|
||||
#define ADC_LL_I2C_ADC 0X69
|
||||
#define ADC_LL_I2C_ADC_HOSTID 0
|
||||
|
||||
#define ADC_LL_ANA_CONFIG2_REG 0x6000E048
|
||||
|
||||
#define ADC_LL_SAR1_ENCAL_GND_ADDR 0x7
|
||||
#define ADC_LL_SAR1_ENCAL_GND_ADDR_MSB 5
|
||||
#define ADC_LL_SAR1_ENCAL_GND_ADDR_LSB 5
|
||||
|
||||
#define ADC_LL_SAR2_ENCAL_GND_ADDR 0x7
|
||||
#define ADC_LL_SAR2_ENCAL_GND_ADDR_MSB 7
|
||||
#define ADC_LL_SAR2_ENCAL_GND_ADDR_LSB 7
|
||||
|
||||
#define ADC_LL_SAR1_INITIAL_CODE_HIGH_ADDR 0x1
|
||||
#define ADC_LL_SAR1_INITIAL_CODE_HIGH_ADDR_MSB 0x3
|
||||
#define ADC_LL_SAR1_INITIAL_CODE_HIGH_ADDR_LSB 0x0
|
||||
|
||||
#define ADC_LL_SAR1_INITIAL_CODE_LOW_ADDR 0x0
|
||||
#define ADC_LL_SAR1_INITIAL_CODE_LOW_ADDR_MSB 0x7
|
||||
#define ADC_LL_SAR1_INITIAL_CODE_LOW_ADDR_LSB 0x0
|
||||
|
||||
#define ADC_LL_SAR2_INITIAL_CODE_HIGH_ADDR 0x4
|
||||
#define ADC_LL_SAR2_INITIAL_CODE_HIGH_ADDR_MSB 0x3
|
||||
#define ADC_LL_SAR2_INITIAL_CODE_HIGH_ADDR_LSB 0x0
|
||||
|
||||
#define ADC_LL_SAR2_INITIAL_CODE_LOW_ADDR 0x3
|
||||
#define ADC_LL_SAR2_INITIAL_CODE_LOW_ADDR_MSB 0x7
|
||||
#define ADC_LL_SAR2_INITIAL_CODE_LOW_ADDR_LSB 0x0
|
||||
|
||||
#define ADC_LL_SAR1_DREF_ADDR 0x2
|
||||
#define ADC_LL_SAR1_DREF_ADDR_MSB 0x6
|
||||
#define ADC_LL_SAR1_DREF_ADDR_LSB 0x4
|
||||
|
||||
#define ADC_LL_SAR2_DREF_ADDR 0x5
|
||||
#define ADC_LL_SAR2_DREF_ADDR_MSB 0x6
|
||||
#define ADC_LL_SAR2_DREF_ADDR_LSB 0x4
|
||||
|
||||
#define ADC_LL_SAR1_SAMPLE_CYCLE_ADDR 0x2
|
||||
#define ADC_LL_SAR1_SAMPLE_CYCLE_ADDR_MSB 0x2
|
||||
#define ADC_LL_SAR1_SAMPLE_CYCLE_ADDR_LSB 0x0
|
||||
|
||||
#define ADC_LL_SARADC_DTEST_RTC_ADDR 0x7
|
||||
#define ADC_LL_SARADC_DTEST_RTC_ADDR_MSB 1
|
||||
#define ADC_LL_SARADC_DTEST_RTC_ADDR_LSB 0
|
||||
|
||||
#define ADC_LL_SARADC_ENT_TSENS_ADDR 0x7
|
||||
#define ADC_LL_SARADC_ENT_TSENS_ADDR_MSB 2
|
||||
#define ADC_LL_SARADC_ENT_TSENS_ADDR_LSB 2
|
||||
|
||||
#define ADC_LL_SARADC_ENT_RTC_ADDR 0x7
|
||||
#define ADC_LL_SARADC_ENT_RTC_ADDR_MSB 3
|
||||
#define ADC_LL_SARADC_ENT_RTC_ADDR_LSB 3
|
||||
|
||||
/* ADC calibration defines end. */
|
||||
|
||||
/*---------------------------------------------------------------
|
||||
Digital controller setting
|
||||
---------------------------------------------------------------*/
|
||||
@ -155,13 +99,11 @@ static inline void adc_ll_digi_set_fsm_time(uint32_t rst_wait, uint32_t start_wa
|
||||
static inline void adc_ll_set_sample_cycle(uint32_t sample_cycle)
|
||||
{
|
||||
/* Should be called before writing I2C registers. */
|
||||
void phy_get_romfunc_addr(void);
|
||||
phy_get_romfunc_addr();
|
||||
SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PU_M);
|
||||
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, BIT(18));
|
||||
SET_PERI_REG_MASK(ADC_LL_ANA_CONFIG2_REG, BIT(16));
|
||||
SET_PERI_REG_MASK(ADC_ANA_CONFIG2_REG, BIT(16));
|
||||
|
||||
I2C_WRITEREG_MASK_RTC(ADC_LL_I2C_ADC, ADC_LL_SAR1_SAMPLE_CYCLE_ADDR, sample_cycle);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_SAR_ADC, ADC_SAR1_SAMPLE_CYCLE_ADDR, sample_cycle);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1194,27 +1136,25 @@ static inline void adc_ll_disable_sleep_controller(void)
|
||||
static inline void adc_ll_calibration_prepare(adc_ll_num_t adc_n, adc_channel_t channel, bool internal_gnd)
|
||||
{
|
||||
/* Should be called before writing I2C registers. */
|
||||
void phy_get_romfunc_addr(void);
|
||||
phy_get_romfunc_addr();
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PD_M);
|
||||
SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PU_M);
|
||||
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, BIT(18));
|
||||
SET_PERI_REG_MASK(ADC_LL_ANA_CONFIG2_REG, BIT(16));
|
||||
SET_PERI_REG_MASK(ADC_ANA_CONFIG2_REG, BIT(16));
|
||||
|
||||
/* Enable/disable internal connect GND (for calibration). */
|
||||
if (adc_n == ADC_NUM_1) {
|
||||
I2C_WRITEREG_MASK_RTC(ADC_LL_I2C_ADC, ADC_LL_SAR1_DREF_ADDR, 4);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_SAR_ADC, ADC_SAR1_DREF_ADDR, 4);
|
||||
if (internal_gnd) {
|
||||
I2C_WRITEREG_MASK_RTC(ADC_LL_I2C_ADC, ADC_LL_SAR1_ENCAL_GND_ADDR, 1);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_SAR_ADC, ADC_SAR1_ENCAL_GND_ADDR, 1);
|
||||
} else {
|
||||
I2C_WRITEREG_MASK_RTC(ADC_LL_I2C_ADC, ADC_LL_SAR1_ENCAL_GND_ADDR, 0);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_SAR_ADC, ADC_SAR1_ENCAL_GND_ADDR, 0);
|
||||
}
|
||||
} else {
|
||||
I2C_WRITEREG_MASK_RTC(ADC_LL_I2C_ADC, ADC_LL_SAR2_DREF_ADDR, 4);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_SAR_ADC, ADC_SAR2_DREF_ADDR, 4);
|
||||
if (internal_gnd) {
|
||||
I2C_WRITEREG_MASK_RTC(ADC_LL_I2C_ADC, ADC_LL_SAR2_ENCAL_GND_ADDR, 1);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_SAR_ADC, ADC_SAR2_ENCAL_GND_ADDR, 1);
|
||||
} else {
|
||||
I2C_WRITEREG_MASK_RTC(ADC_LL_I2C_ADC, ADC_LL_SAR2_ENCAL_GND_ADDR, 0);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_SAR_ADC, ADC_SAR2_ENCAL_GND_ADDR, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1227,9 +1167,9 @@ static inline void adc_ll_calibration_prepare(adc_ll_num_t adc_n, adc_channel_t
|
||||
static inline void adc_ll_calibration_finish(adc_ll_num_t adc_n)
|
||||
{
|
||||
if (adc_n == ADC_NUM_1) {
|
||||
I2C_WRITEREG_MASK_RTC(ADC_LL_I2C_ADC, ADC_LL_SAR1_ENCAL_GND_ADDR, 0);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_SAR_ADC, ADC_SAR1_ENCAL_GND_ADDR, 0);
|
||||
} else {
|
||||
I2C_WRITEREG_MASK_RTC(ADC_LL_I2C_ADC, ADC_LL_SAR2_ENCAL_GND_ADDR, 0);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_SAR_ADC, ADC_SAR2_ENCAL_GND_ADDR, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1245,18 +1185,16 @@ static inline void adc_ll_set_calibration_param(adc_ll_num_t adc_n, uint32_t par
|
||||
uint8_t msb = param >> 8;
|
||||
uint8_t lsb = param & 0xFF;
|
||||
/* Should be called before writing I2C registers. */
|
||||
void phy_get_romfunc_addr(void);
|
||||
phy_get_romfunc_addr();
|
||||
SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PU_M);
|
||||
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, BIT(18));
|
||||
SET_PERI_REG_MASK(ADC_LL_ANA_CONFIG2_REG, BIT(16));
|
||||
SET_PERI_REG_MASK(ADC_ANA_CONFIG2_REG, BIT(16));
|
||||
|
||||
if (adc_n == ADC_NUM_1) {
|
||||
I2C_WRITEREG_MASK_RTC(ADC_LL_I2C_ADC, ADC_LL_SAR1_INITIAL_CODE_HIGH_ADDR, msb);
|
||||
I2C_WRITEREG_MASK_RTC(ADC_LL_I2C_ADC, ADC_LL_SAR1_INITIAL_CODE_LOW_ADDR, lsb);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_SAR_ADC, ADC_SAR1_INITIAL_CODE_HIGH_ADDR, msb);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_SAR_ADC, ADC_SAR1_INITIAL_CODE_LOW_ADDR, lsb);
|
||||
} else {
|
||||
I2C_WRITEREG_MASK_RTC(ADC_LL_I2C_ADC, ADC_LL_SAR2_INITIAL_CODE_HIGH_ADDR, msb);
|
||||
I2C_WRITEREG_MASK_RTC(ADC_LL_I2C_ADC, ADC_LL_SAR2_INITIAL_CODE_LOW_ADDR, lsb);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_SAR_ADC, ADC_SAR2_INITIAL_CODE_HIGH_ADDR, msb);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_SAR_ADC, ADC_SAR2_INITIAL_CODE_LOW_ADDR, lsb);
|
||||
}
|
||||
}
|
||||
/* Temp code end. */
|
||||
@ -1275,23 +1213,21 @@ static inline void adc_ll_set_calibration_param(adc_ll_num_t adc_n, uint32_t par
|
||||
static inline void adc_ll_vref_output(adc_ll_num_t adc, adc_channel_t channel, bool en)
|
||||
{
|
||||
/* Should be called before writing I2C registers. */
|
||||
void phy_get_romfunc_addr(void);
|
||||
phy_get_romfunc_addr();
|
||||
SET_PERI_REG_MASK(RTC_CNTL_ANA_CONF_REG, RTC_CNTL_SAR_I2C_FORCE_PU_M);
|
||||
CLEAR_PERI_REG_MASK(ANA_CONFIG_REG, BIT(18));
|
||||
SET_PERI_REG_MASK(ADC_LL_ANA_CONFIG2_REG, BIT(16));
|
||||
SET_PERI_REG_MASK(ADC_ANA_CONFIG2_REG, BIT(16));
|
||||
|
||||
if (en) {
|
||||
if (adc == ADC_NUM_1) {
|
||||
/* Config test mux to route v_ref to ADC1 Channels */
|
||||
I2C_WRITEREG_MASK_RTC(ADC_LL_I2C_ADC, ADC_LL_SARADC_DTEST_RTC_ADDR, 1);
|
||||
I2C_WRITEREG_MASK_RTC(ADC_LL_I2C_ADC, ADC_LL_SARADC_ENT_TSENS_ADDR, 0);
|
||||
I2C_WRITEREG_MASK_RTC(ADC_LL_I2C_ADC, ADC_LL_SARADC_ENT_RTC_ADDR, 1);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_SAR_ADC, ADC_SARADC_DTEST_RTC_ADDR, 1);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_SAR_ADC, ADC_SARADC_ENT_TSENS_ADDR, 0);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_SAR_ADC, ADC_SARADC_ENT_RTC_ADDR, 1);
|
||||
} else {
|
||||
/* Config test mux to route v_ref to ADC2 Channels */
|
||||
I2C_WRITEREG_MASK_RTC(ADC_LL_I2C_ADC, ADC_LL_SARADC_DTEST_RTC_ADDR, 0);
|
||||
I2C_WRITEREG_MASK_RTC(ADC_LL_I2C_ADC, ADC_LL_SARADC_ENT_TSENS_ADDR, 1);
|
||||
I2C_WRITEREG_MASK_RTC(ADC_LL_I2C_ADC, ADC_LL_SARADC_ENT_RTC_ADDR, 0);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_SAR_ADC, ADC_SARADC_DTEST_RTC_ADDR, 0);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_SAR_ADC, ADC_SARADC_ENT_TSENS_ADDR, 1);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_SAR_ADC, ADC_SARADC_ENT_RTC_ADDR, 0);
|
||||
}
|
||||
//in sleep force to use rtc to control ADC
|
||||
SENS.sar_meas2_mux.sar2_rtc_force = 1;
|
||||
@ -1302,8 +1238,8 @@ static inline void adc_ll_vref_output(adc_ll_num_t adc, adc_channel_t channel, b
|
||||
//set en_pad for ADC2 channels (bits 0x380)
|
||||
SENS.sar_meas2_ctrl2.sar2_en_pad = 1 << channel;
|
||||
} else {
|
||||
I2C_WRITEREG_MASK_RTC(ADC_LL_I2C_ADC, ADC_LL_SARADC_ENT_TSENS_ADDR, 0);
|
||||
I2C_WRITEREG_MASK_RTC(ADC_LL_I2C_ADC, ADC_LL_SARADC_ENT_RTC_ADDR, 0);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_SAR_ADC, ADC_SARADC_ENT_TSENS_ADDR, 0);
|
||||
I2C_WRITEREG_MASK_RTC(I2C_SAR_ADC, ADC_SARADC_ENT_RTC_ADDR, 0);
|
||||
SENS.sar_meas2_mux.sar2_rtc_force = 0;
|
||||
//set sar2_en_test
|
||||
SENS.sar_meas2_ctrl1.sar2_en_test = 0;
|
||||
|
@ -33,48 +33,29 @@ extern "C" {
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_attr.h"
|
||||
#include "hal/dma_types.h"
|
||||
#include "soc/cp_dma_struct.h"
|
||||
|
||||
typedef struct cp_dma_descriptor {
|
||||
struct {
|
||||
uint32_t size : 12; /*!< buffer size */
|
||||
uint32_t length : 12; /*!< specify number of valid bytes in the buffer */
|
||||
uint32_t reversed24_27 : 4; /*!< reserved */
|
||||
uint32_t err : 1; /*!< specify whether a received buffer contains error */
|
||||
uint32_t reserved29 : 1; /*!< reserved */
|
||||
uint32_t eof : 1; /*!< if this dma link is the last one, you shoule set this bit 1 */
|
||||
uint32_t owner : 1; /*!< specify the owner of buffer that this descriptor points to, 1=DMA, 0=CPU. DMA will clear it after use. */
|
||||
} dw0; /*!< descriptor word 0 */
|
||||
void *buffer; /*!< pointer to the buffer */
|
||||
struct cp_dma_descriptor *next; /*!< pointer to the next descriptor or NULL if this descriptor is the last one */
|
||||
} cp_dma_descriptor_t;
|
||||
|
||||
_Static_assert(sizeof(cp_dma_descriptor_t) == 12, "cp_dma_descriptor_t should occupy 12 bytes in memory");
|
||||
|
||||
/**
|
||||
* @brief HAL context
|
||||
*
|
||||
* @note `tx_desc` and `rx_desc` are internal state of the HAL, will be modified during the operations.
|
||||
* Upper layer of HAL should keep the buffer address themselves and make sure the buffers are freed when the HAL is no longer used.
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
cp_dma_dev_t *dev;
|
||||
cp_dma_descriptor_t *tx_desc;
|
||||
cp_dma_descriptor_t *rx_desc;
|
||||
cp_dma_descriptor_t *next_rx_desc_to_check;
|
||||
} cp_dma_hal_context_t;
|
||||
|
||||
typedef struct {
|
||||
dma_descriptor_t *outlink_base; /*!< Address of the first outlink descriptor */
|
||||
dma_descriptor_t *inlink_base; /*!< Address of the first inlink descriptor */
|
||||
} cp_dma_hal_config_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize HAL layer context
|
||||
*
|
||||
* @param hal HAL layer context, memroy should be allocated at driver layer
|
||||
* @param tx_descriptors out link descriptor pool
|
||||
* @param tx_desc_num number of out link descriptors
|
||||
* @param rx_descriptors in line descriptor pool
|
||||
* @param rx_desc_num number of in link descriptors
|
||||
* @param hal HAL layer context, whose memroy should be allocated at driver layer
|
||||
* @param config configuration for the HAL layer
|
||||
*/
|
||||
void cp_dma_hal_init(cp_dma_hal_context_t *hal, cp_dma_descriptor_t *tx_descriptors[], uint32_t tx_desc_num, cp_dma_descriptor_t *rx_descriptors[], uint32_t rx_desc_num);
|
||||
void cp_dma_hal_init(cp_dma_hal_context_t *hal, const cp_dma_hal_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Deinitialize HAL layer context
|
||||
@ -105,39 +86,6 @@ uint32_t cp_dma_hal_get_intr_status(cp_dma_hal_context_t *hal) IRAM_ATTR;
|
||||
*/
|
||||
void cp_dma_hal_clear_intr_status(cp_dma_hal_context_t *hal, uint32_t mask) IRAM_ATTR;
|
||||
|
||||
/**
|
||||
* @brief Get next RX descriptor that needs recycling
|
||||
*
|
||||
* @param eof_desc EOF descriptor for this iteration
|
||||
* @param[out] next_desc Next descriptor needs to check
|
||||
* @return Whether to continue
|
||||
*/
|
||||
bool cp_dma_hal_get_next_rx_descriptor(cp_dma_hal_context_t *hal, cp_dma_descriptor_t *eof_desc, cp_dma_descriptor_t **next_desc);
|
||||
|
||||
/**
|
||||
* @brief Prepare buffer to be transmitted
|
||||
*
|
||||
* @param hal HAL layer context
|
||||
* @param buffer buffer address
|
||||
* @param len buffer size
|
||||
* @param[out] start_desc The first descriptor that carry the TX transaction
|
||||
* @param[out] end_desc The last descriptor that carry the TX transaction
|
||||
* @return Number of bytes has been parepared to transmit
|
||||
*/
|
||||
int cp_dma_hal_prepare_transmit(cp_dma_hal_context_t *hal, void *buffer, size_t len, cp_dma_descriptor_t **start_desc, cp_dma_descriptor_t **end_desc);
|
||||
|
||||
/**
|
||||
* @brief Prepare buffer to receive
|
||||
*
|
||||
* @param hal HAL layer context
|
||||
* @param buffer buffer address
|
||||
* @param size buffer size
|
||||
* @param[out] start_desc The first descriptor that carries the RX transaction
|
||||
* @param[out] end_desc The last descriptor that carries the RX transaction
|
||||
* @return Number of bytes has been parepared to receive
|
||||
*/
|
||||
int cp_dma_hal_prepare_receive(cp_dma_hal_context_t *hal, void *buffer, size_t size, cp_dma_descriptor_t **start_desc, cp_dma_descriptor_t **end_desc);
|
||||
|
||||
/**@{*/
|
||||
/**
|
||||
* @brief Give the owner of descriptors between [start_desc, end_desc] to DMA, and restart DMA HW engine
|
||||
@ -146,8 +94,8 @@ int cp_dma_hal_prepare_receive(cp_dma_hal_context_t *hal, void *buffer, size_t s
|
||||
* @param start_desc The first descriptor that carries one transaction
|
||||
* @param end_desc The last descriptor that carries one transaction
|
||||
*/
|
||||
void cp_dma_hal_restart_tx(cp_dma_hal_context_t *hal, cp_dma_descriptor_t *start_desc, cp_dma_descriptor_t *end_desc);
|
||||
void cp_dma_hal_restart_rx(cp_dma_hal_context_t *hal, cp_dma_descriptor_t *start_desc, cp_dma_descriptor_t *end_desc);
|
||||
void cp_dma_hal_restart_tx(cp_dma_hal_context_t *hal);
|
||||
void cp_dma_hal_restart_rx(cp_dma_hal_context_t *hal);
|
||||
/**@}*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -0,0 +1,81 @@
|
||||
// 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 ll is not public api, don't use in application code.
|
||||
* See readme.md in soc/include/hal/readme.md
|
||||
******************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "soc/hwcrypto_reg.h"
|
||||
#include "soc/dport_reg.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
CRYPTO_DMA_AES = 0,
|
||||
CRYPTO_DMA_SHA,
|
||||
} crypto_dma_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Resets set the outlink
|
||||
*
|
||||
*/
|
||||
static inline void crypto_dma_ll_outlink_reset(void)
|
||||
{
|
||||
SET_PERI_REG_MASK(CRYPTO_DMA_CONF0_REG, CONF0_REG_AHBM_RST | CONF0_REG_OUT_RST | CONF0_REG_AHBM_FIFO_RST);
|
||||
CLEAR_PERI_REG_MASK(CRYPTO_DMA_CONF0_REG, CONF0_REG_AHBM_RST | CONF0_REG_OUT_RST | CONF0_REG_AHBM_FIFO_RST);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Selects the crypto DMA mode
|
||||
*
|
||||
* @param mode Mode to use, AES or SHA
|
||||
*/
|
||||
static inline void crypto_dma_ll_set_mode(crypto_dma_mode_t mode)
|
||||
{
|
||||
REG_WRITE(CRYPTO_DMA_AES_SHA_SELECT_REG, mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets up the outlink for a transfer
|
||||
*
|
||||
* @param outlink_addr Address of the outlink buffer
|
||||
*/
|
||||
static inline void crypto_dma_ll_outlink_set(uint32_t outlink_addr)
|
||||
{
|
||||
CLEAR_PERI_REG_MASK(CRYPTO_DMA_OUT_LINK_REG, OUT_LINK_REG_OUTLINK_ADDR);
|
||||
SET_PERI_REG_MASK(CRYPTO_DMA_OUT_LINK_REG, outlink_addr & OUT_LINK_REG_OUTLINK_ADDR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Starts the outlink
|
||||
*
|
||||
*/
|
||||
static inline void crypto_dma_ll_outlink_start(void)
|
||||
{
|
||||
SET_PERI_REG_MASK(CRYPTO_DMA_OUT_LINK_REG, OUT_LINK_REG_OUTLINK_START);
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
76
tools/sdk/esp32s2/include/hal/esp32s2/include/hal/dac_hal.h
Normal file
76
tools/sdk/esp32s2/include/hal/esp32s2/include/hal/dac_hal.h
Normal file
@ -0,0 +1,76 @@
|
||||
// Copyright 2019 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 hal/include/hal/readme.md
|
||||
******************************************************************************/
|
||||
|
||||
// The HAL layer for DAC (esp32s2 specific part)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "hal/dac_ll.h"
|
||||
#include "hal/dac_types.h"
|
||||
|
||||
#include_next "hal/dac_hal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*---------------------------------------------------------------
|
||||
Digital controller setting
|
||||
---------------------------------------------------------------*/
|
||||
/**
|
||||
* Digital controller initialization.
|
||||
*/
|
||||
void dac_hal_digi_init(void);
|
||||
|
||||
/**
|
||||
* Digital controller deinitialization.
|
||||
*/
|
||||
void dac_hal_digi_deinit(void);
|
||||
|
||||
/**
|
||||
* Setting the DAC digital controller.
|
||||
*
|
||||
* @param cfg Pointer to digital controller paramter.
|
||||
*/
|
||||
void dac_hal_digi_controller_config(const dac_digi_config_t *cfg);
|
||||
|
||||
/**
|
||||
* DAC digital controller start output voltage.
|
||||
*/
|
||||
void dac_hal_digi_start(void);
|
||||
|
||||
/**
|
||||
* DAC digital controller stop output voltage.
|
||||
*/
|
||||
void dac_hal_digi_stop(void);
|
||||
|
||||
/**
|
||||
* Reset DAC digital controller FIFO.
|
||||
*/
|
||||
#define dac_hal_digi_fifo_reset() dac_ll_digi_fifo_reset()
|
||||
|
||||
/**
|
||||
* Reset DAC digital controller.
|
||||
*/
|
||||
#define dac_hal_digi_reset() dac_ll_digi_reset()
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -156,7 +156,7 @@ static inline void gpspi_flash_ll_user_start(spi_dev_t *dev)
|
||||
*/
|
||||
static inline bool gpspi_flash_ll_host_idle(const spi_dev_t *dev)
|
||||
{
|
||||
return dev->fsm.st != 0;
|
||||
return dev->fsm.st == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
File diff suppressed because it is too large
Load Diff
173
tools/sdk/esp32s2/include/hal/esp32s2/include/hal/sha_ll.h
Normal file
173
tools/sdk/esp32s2/include/hal/esp32s2/include/hal/sha_ll.h
Normal file
@ -0,0 +1,173 @@
|
||||
// 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 "soc/hwcrypto_reg.h"
|
||||
#include "hal/sha_types.h"
|
||||
#include "soc/dport_reg.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief Start a new SHA block conversions (no initial hash in HW)
|
||||
*
|
||||
* @param sha_type The SHA algorithm type
|
||||
*/
|
||||
static inline void sha_ll_start_block(esp_sha_type sha_type)
|
||||
{
|
||||
REG_WRITE(SHA_MODE_REG, sha_type);
|
||||
REG_WRITE(SHA_START_REG, 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)
|
||||
{
|
||||
REG_WRITE(SHA_MODE_REG, sha_type);
|
||||
REG_WRITE(SHA_CONTINUE_REG, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Start a new SHA message conversion using DMA (no initial hash in HW)
|
||||
*
|
||||
* @param sha_type The SHA algorithm type
|
||||
*/
|
||||
static inline void sha_ll_start_dma(esp_sha_type sha_type)
|
||||
{
|
||||
REG_WRITE(SHA_MODE_REG, sha_type);
|
||||
REG_WRITE(SHA_DMA_START_REG, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Continue a SHA message conversion using DMA (initial hash in HW)
|
||||
*
|
||||
* @param sha_type The SHA algorithm type
|
||||
*/
|
||||
static inline void sha_ll_continue_dma(esp_sha_type sha_type)
|
||||
{
|
||||
REG_WRITE(SHA_MODE_REG, sha_type);
|
||||
REG_WRITE(SHA_DMA_CONTINUE_REG, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Load the current hash digest to digest register
|
||||
*
|
||||
* @note Happens automatically on ESP32S2
|
||||
*
|
||||
* @param sha_type The SHA algorithm type
|
||||
*/
|
||||
static inline void sha_ll_load(esp_sha_type sha_type)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the number of message blocks to be hashed
|
||||
*
|
||||
* @note DMA operation only
|
||||
*
|
||||
* @param num_blocks Number of message blocks to process
|
||||
*/
|
||||
static inline void sha_ll_set_block_num(size_t num_blocks)
|
||||
{
|
||||
REG_WRITE(SHA_BLOCK_NUM_REG, num_blocks);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 REG_READ(SHA_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 *data_words = (uint32_t *)input_text;
|
||||
uint32_t *reg_addr_buf = (uint32_t *)(SHA_TEXT_BASE);
|
||||
|
||||
for (int i = 0; i < block_word_len; i++) {
|
||||
REG_WRITE(®_addr_buf[i], 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;
|
||||
|
||||
esp_dport_access_read_buffer(digest_state_words, SHA_H_BASE, digest_word_len);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Write the message digest to the SHA engine
|
||||
*
|
||||
* @param sha_type The SHA algorithm type
|
||||
* @param digest_state Message digest to be written to SHA engine
|
||||
* @param digest_word_len Length of the message digest
|
||||
*/
|
||||
static inline void sha_ll_write_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_H_BASE);
|
||||
|
||||
for (int i = 0; i < digest_word_len; i++) {
|
||||
REG_WRITE(®_addr_buf[i], digest_state_words[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets SHA512_t T_string parameter
|
||||
*
|
||||
* @param t_string T_string parameter
|
||||
*/
|
||||
static inline void sha_ll_t_string_set(uint32_t t_string)
|
||||
{
|
||||
REG_WRITE(SHA_T_STRING_REG, t_string);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets SHA512_t T_string parameter's length
|
||||
*
|
||||
* @param t_len T_string parameter length
|
||||
*/
|
||||
static inline void sha_ll_t_len_set(uint8_t t_len)
|
||||
{
|
||||
REG_WRITE(SHA_T_LENGTH_REG, t_len);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
@ -35,7 +35,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_TRANS_DONE_EN | SPI_INT_WR_DMA_DONE_EN | SPI_INT_RD_DMA_DONE_EN | SPI_INT_WR_BUF_DONE_EN | SPI_INT_RD_BUF_DONE_EN)
|
||||
/// Swap the bit order to its correct place to send
|
||||
@ -50,6 +50,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
|
||||
@ -59,12 +62,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_INT_TYPE_SEG = 1, ///< Wait for DMA signals
|
||||
} spi_ll_slave_intr_type;
|
||||
|
||||
/// Type definition of all supported interrupts
|
||||
typedef enum {
|
||||
SPI_LL_INTR_TRANS_DONE = BIT(0), ///< A transaction has done
|
||||
@ -104,11 +101,6 @@ FLAG_ATTR(spi_ll_trans_len_cond_t)
|
||||
*/
|
||||
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;
|
||||
|
||||
@ -137,52 +129,26 @@ 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.soft_reset = 1;
|
||||
hw->slave.soft_reset = 0;
|
||||
//use all 64 bytes of the buffer
|
||||
hw->user.usr_miso_highpart = 0;
|
||||
hw->user.usr_mosi_highpart = 0;
|
||||
//by default seg mode is disabled
|
||||
hw->dma_conf.dma_continue = 0;
|
||||
|
||||
//Disable unneeded ints
|
||||
hw->slave.val &= ~SPI_LL_UNUSED_INT_MASK;
|
||||
hw->dma_int_ena.val = 0;
|
||||
}
|
||||
|
||||
static inline void spi_ll_slave_hd_init(spi_dev_t* hw)
|
||||
static inline void spi_ll_slave_hd_init(spi_dev_t *hw)
|
||||
{
|
||||
hw->clock.val = 0;
|
||||
hw->user.val = 0;
|
||||
hw->ctrl.val = 0;
|
||||
hw->user.sio = 0;
|
||||
//hw->user.tx_start_bit = 7;
|
||||
|
||||
hw->slave.soft_reset = 1;
|
||||
hw->slave.soft_reset = 0;
|
||||
|
||||
//Reset DMA
|
||||
hw->dma_conf.val |= SPI_OUT_RST | SPI_IN_RST | SPI_AHBM_RST | SPI_AHBM_FIFO_RST;
|
||||
hw->dma_out_link.start = 0;
|
||||
hw->dma_in_link.start = 0;
|
||||
hw->dma_conf.val &= ~(SPI_OUT_RST | SPI_IN_RST | SPI_AHBM_RST | SPI_AHBM_FIFO_RST);
|
||||
|
||||
if (hw == &GPSPI2) {
|
||||
hw->dma_conf.out_data_burst_en = 1;
|
||||
} else {
|
||||
hw->dma_conf.out_data_burst_en = 0;
|
||||
}
|
||||
hw->dma_conf.outdscr_burst_en = 1;
|
||||
hw->dma_conf.indscr_burst_en = 1;
|
||||
|
||||
hw->dma_conf.rx_eof_en = 0;
|
||||
hw->dma_conf.out_eof_mode = 1;
|
||||
hw->dma_conf.out_auto_wrback = 1;
|
||||
|
||||
hw->user.doutdin = 0; //we only support full duplex
|
||||
hw->slave.slave_mode = 1;
|
||||
}
|
||||
@ -221,103 +187,83 @@ static inline uint32_t spi_ll_get_running_cmd(spi_dev_t *hw)
|
||||
return hw->cmd.val;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* DMA
|
||||
*----------------------------------------------------------------------------*/
|
||||
/**
|
||||
* Reset TX and RX DMAs.
|
||||
* Reset SPI CPU FIFO
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
*/
|
||||
static inline void spi_ll_reset_dma(spi_dev_t *hw)
|
||||
static inline void spi_ll_cpu_fifo_reset(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 = 0;
|
||||
hw->dma_conf.indscr_burst_en = 1;
|
||||
hw->dma_conf.outdscr_burst_en = 1;
|
||||
hw->dma_in_link.dma_rx_ena = 0;
|
||||
assert(hw->dma_in_link.dma_rx_ena == 0);
|
||||
//This is not used in esp32s2
|
||||
}
|
||||
|
||||
/**
|
||||
* Start RX DMA.
|
||||
* Reset SPI DMA FIFO
|
||||
*
|
||||
* @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)
|
||||
static inline void spi_ll_dma_fifo_reset(spi_dev_t *hw)
|
||||
{
|
||||
hw->dma_in_link.addr = (int) addr & 0xFFFFF;
|
||||
hw->dma_in_link.start = 1;
|
||||
hw->dma_conf.val |= SPI_LL_DMA_FIFO_RST_MASK;
|
||||
hw->dma_conf.val &= ~SPI_LL_DMA_FIFO_RST_MASK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start TX DMA.
|
||||
*
|
||||
* Clear in fifo full error
|
||||
*
|
||||
* @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)
|
||||
static inline void spi_ll_infifo_full_clr(spi_dev_t *hw)
|
||||
{
|
||||
hw->dma_out_link.addr = (int) addr & 0xFFFFF;
|
||||
hw->dma_out_link.start = 1;
|
||||
}
|
||||
|
||||
static inline void spi_ll_rxdma_reset(spi_dev_t* hw)
|
||||
{
|
||||
hw->dma_conf.in_rst = 1;
|
||||
hw->dma_conf.in_rst = 0;
|
||||
hw->dma_conf.infifo_full_clr = 1;
|
||||
hw->dma_conf.infifo_full_clr = 0;
|
||||
}
|
||||
|
||||
static inline void spi_ll_txdma_reset(spi_dev_t* hw)
|
||||
/**
|
||||
* Clear out fifo empty error
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
*/
|
||||
static inline void spi_ll_outfifo_empty_clr(spi_dev_t *hw)
|
||||
{
|
||||
hw->dma_conf.out_rst = 1;
|
||||
hw->dma_conf.out_rst = 0;
|
||||
hw->dma_conf.outfifo_empty_clr = 1;
|
||||
hw->dma_conf.outfifo_empty_clr = 0;
|
||||
}
|
||||
|
||||
static inline void spi_ll_rxdma_restart(spi_dev_t* hw)
|
||||
/*------------------------------------------------------------------------------
|
||||
* 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->dma_in_link.restart = 1;
|
||||
//This is not used in esp32s2
|
||||
}
|
||||
|
||||
static inline void spi_ll_txdma_restart(spi_dev_t* hw)
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
hw->dma_out_link.restart = 1;
|
||||
//This is not used in esp32s2
|
||||
}
|
||||
|
||||
static inline void spi_ll_rxdma_disable(spi_dev_t* hw)
|
||||
/**
|
||||
* Configuration of OUT EOF flag generation way
|
||||
*
|
||||
* @param dma_out Beginning address of the DMA peripheral registers which transmits the data from RAM to a peripheral.
|
||||
* @param enable 1: when dma pop all data from fifo 0:when ahb push all data to fifo.
|
||||
*/
|
||||
static inline void spi_ll_dma_set_out_eof_generation(spi_dma_dev_t *dma_out, bool enable)
|
||||
{
|
||||
hw->dma_in_link.dma_rx_ena = 0;
|
||||
}
|
||||
|
||||
static inline void spi_ll_txdma_disable(spi_dev_t* hw)
|
||||
{
|
||||
hw->dma_out_link.dma_tx_ena = 0;
|
||||
hw->dma_out_link.stop = 1;
|
||||
}
|
||||
|
||||
static inline void spi_ll_rxdma_clr_err(spi_dev_t* hw)
|
||||
{
|
||||
hw->dma_conf.infifo_full_clr = 1;
|
||||
hw->dma_conf.infifo_full_clr = 0;
|
||||
}
|
||||
|
||||
static inline void spi_ll_txdma_clr_err(spi_dev_t* hw)
|
||||
{
|
||||
hw->dma_int_clr.outfifo_empty_err= 1;
|
||||
}
|
||||
|
||||
static inline bool spi_ll_txdma_get_empty_err(spi_dev_t* hw)
|
||||
{
|
||||
return hw->dma_int_raw.outfifo_empty_err;
|
||||
dma_out->dma_conf.out_eof_mode = enable;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
@ -415,7 +361,7 @@ static inline void spi_ll_master_set_pos_cs(spi_dev_t *hw, int cs, uint32_t pos_
|
||||
if (pos_cs) {
|
||||
hw->misc.master_cs_pol |= (1 << cs);
|
||||
} else {
|
||||
hw->misc.master_cs_pol &= (1 << cs);
|
||||
hw->misc.master_cs_pol &= ~(1 << cs);
|
||||
}
|
||||
}
|
||||
|
||||
@ -559,7 +505,7 @@ static inline void spi_ll_master_set_io_mode(spi_dev_t *hw, spi_ll_io_mode_t io_
|
||||
}
|
||||
}
|
||||
|
||||
static inline void spi_ll_slave_set_seg_mode(spi_dev_t* hw, bool seg_trans)
|
||||
static inline void spi_ll_slave_set_seg_mode(spi_dev_t *hw, bool seg_trans)
|
||||
{
|
||||
hw->dma_conf.dma_seg_trans_en = seg_trans;
|
||||
hw->dma_conf.rx_eof_en = seg_trans;
|
||||
@ -590,7 +536,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;
|
||||
}
|
||||
@ -784,7 +730,7 @@ static inline void spi_ll_master_set_cs_setup(spi_dev_t *hw, uint8_t setup)
|
||||
* Enable/disable the segment transfer feature for the slave.
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
* @param en true to enable, false to disable.
|
||||
* @param en true to enable, false to disable.
|
||||
*/
|
||||
static inline void spi_ll_slave_set_seg_en(spi_dev_t *hw, bool en)
|
||||
{
|
||||
@ -982,7 +928,7 @@ static inline uint32_t spi_ll_slave_get_rcv_bitlen(spi_dev_t *hw)
|
||||
item(SPI_LL_INTR_OUT_EOF, dma_int_ena.out_eof, dma_int_raw.out_eof, dma_int_clr.out_eof=1) \
|
||||
item(SPI_LL_INTR_OUT_TOTAL_EOF, dma_int_ena.out_total_eof, dma_int_raw.out_total_eof, dma_int_clr.out_total_eof=1) \
|
||||
item(SPI_LL_INTR_SEG_DONE, slave.int_dma_seg_trans_en, hold.dma_seg_trans_done, hold.dma_seg_trans_done=0) \
|
||||
item(SPI_LL_INTR_IN_FULL, dma_int_ena.infifo_full_err, dma_int_raw.infifo_full_err, dma_int_clr.infifo_full_err=1) \
|
||||
item(SPI_LL_INTR_IN_FULL, dma_int_ena.infifo_full_err, dma_int_raw.infifo_full_err, dma_int_clr.infifo_full_err=1) \
|
||||
item(SPI_LL_INTR_OUT_EMPTY, dma_int_ena.outfifo_empty_err, dma_int_raw.outfifo_empty_err, dma_int_clr.outfifo_empty_err=1) \
|
||||
item(SPI_LL_INTR_WR_DONE, dma_int_ena.cmd7, dma_int_raw.cmd7, dma_int_clr.cmd7=1) \
|
||||
item(SPI_LL_INTR_CMD8, dma_int_ena.cmd8, dma_int_raw.cmd8, dma_int_clr.cmd8=1) \
|
||||
@ -1047,7 +993,6 @@ static inline void spi_ll_disable_int(spi_dev_t *hw)
|
||||
static inline void spi_ll_clear_int_stat(spi_dev_t *hw)
|
||||
{
|
||||
hw->slave.trans_done = 0;
|
||||
hw->dma_int_clr.val = UINT32_MAX;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1070,27 +1015,6 @@ static inline void spi_ll_enable_int(spi_dev_t *hw)
|
||||
hw->slave.int_trans_done_en = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set different interrupt types for the slave.
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
* @param int_type Interrupt type
|
||||
*/
|
||||
static inline void spi_ll_slave_set_int_type(spi_dev_t *hw, spi_ll_slave_intr_type int_type)
|
||||
{
|
||||
switch (int_type) {
|
||||
case SPI_LL_INT_TYPE_SEG:
|
||||
hw->dma_int_ena.in_suc_eof = 1;
|
||||
hw->dma_int_ena.out_total_eof = 1;
|
||||
hw->slave.int_trans_done_en = 0;
|
||||
break;
|
||||
default:
|
||||
hw->dma_int_ena.in_suc_eof = 0;
|
||||
hw->dma_int_ena.out_total_eof = 0;
|
||||
hw->slave.int_trans_done_en = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Slave HD
|
||||
*----------------------------------------------------------------------------*/
|
||||
@ -1111,6 +1035,157 @@ static inline uint32_t spi_ll_slave_hd_get_last_addr(spi_dev_t* hw)
|
||||
{
|
||||
return hw->slave1.last_addr;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* 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 hw Beginning address of the peripheral registers.
|
||||
* @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_in_link.dma_rx_ena = 0;
|
||||
assert(dma_in->dma_in_link.dma_rx_ena == 0);
|
||||
|
||||
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 esp32s2
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable DMA TX 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)
|
||||
{
|
||||
dma_in->dma_conf.rx_eof_en = enable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset TX DMA which transmits the data from RAM to a peripheral.
|
||||
*
|
||||
* @param hw Beginning address of the peripheral registers.
|
||||
* @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)
|
||||
{
|
||||
dma_out->dma_conf.out_auto_wrback = enable;
|
||||
}
|
||||
|
||||
static inline void spi_dma_ll_rx_restart(spi_dma_dev_t *dma_in)
|
||||
{
|
||||
dma_in->dma_in_link.restart = 1;
|
||||
}
|
||||
|
||||
static inline void spi_dma_ll_tx_restart(spi_dma_dev_t *dma_out)
|
||||
{
|
||||
dma_out->dma_out_link.restart = 1;
|
||||
}
|
||||
|
||||
static inline void spi_dma_ll_rx_disable(spi_dma_dev_t *dma_in)
|
||||
{
|
||||
dma_in->dma_in_link.dma_rx_ena = 0;
|
||||
}
|
||||
|
||||
static inline void spi_dma_ll_tx_disable(spi_dma_dev_t *dma_out)
|
||||
{
|
||||
dma_out->dma_out_link.dma_tx_ena = 0;
|
||||
dma_out->dma_out_link.stop = 1;
|
||||
}
|
||||
|
||||
static inline bool spi_ll_tx_get_empty_err(spi_dev_t *hw)
|
||||
{
|
||||
return hw->dma_int_raw.outfifo_empty_err;
|
||||
}
|
||||
|
||||
#undef SPI_LL_RST_MASK
|
||||
#undef SPI_LL_UNUSED_INT_MASK
|
||||
|
||||
|
@ -202,7 +202,7 @@ static inline void spimem_flash_ll_user_start(spi_mem_dev_t *dev)
|
||||
*/
|
||||
static inline bool spimem_flash_ll_host_idle(const spi_mem_dev_t *dev)
|
||||
{
|
||||
return dev->fsm.st != 0;
|
||||
return dev->fsm.st == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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/esp32s2/include/hal/include/hal/dma_types.h
Normal file
45
tools/sdk/esp32s2/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/esp32s2/include/hal/include/hal/gdma_hal.h
Normal file
35
tools/sdk/esp32s2/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/esp32s2/include/hal/include/hal/rtc_hal.h
Normal file
33
tools/sdk/esp32s2/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/esp32s2/include/hal/include/hal/sha_types.h
Normal file
38
tools/sdk/esp32s2/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