mirror of
https://github.com/0xFEEDC0DE64/arduino-esp32.git
synced 2025-07-02 05:20:59 +02:00
Update IDF to 3.2-3276a13 and esptool.py to 2.5.0 (#1878)
* TX Flow Control and Code cleanup * Use semaphore instead of delay TX functionality is done. * Use single buffer and empty queue on exit * Fix compile issues because of LwIP code relocation * Add temporary header to fix Azure not compiling * Fix AsyncUDP early init * AsyncUDP Multicast fixes * Add source mac address and rework multicast * Allow redefinition of default pins for Serials 1 and 2 * Update IDF to 3276a13 * Update esptool.py to 2.5.0 * Fix sketches * Fix log level in BluetoothSetial
This commit is contained in:
400
tools/sdk/include/driver/driver/can.h
Normal file
400
tools/sdk/include/driver/driver/can.h
Normal file
@ -0,0 +1,400 @@
|
||||
// Copyright 2015-2018 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.
|
||||
|
||||
#ifndef _DRIVER_CAN_H_
|
||||
#define _DRIVER_CAN_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "esp_types.h"
|
||||
#include "esp_intr.h"
|
||||
#include "esp_err.h"
|
||||
#include "gpio.h"
|
||||
|
||||
/* -------------------- Default initializers and flags ---------------------- */
|
||||
/** @cond */ //Doxy command to hide preprocessor definitions from docs
|
||||
/**
|
||||
* @brief Initializer macro for general configuration structure.
|
||||
*
|
||||
* This initializer macros allows the TX GPIO, RX GPIO, and operating mode to be
|
||||
* configured. The other members of the general configuration structure are
|
||||
* assigned default values.
|
||||
*/
|
||||
#define CAN_GENERAL_CONFIG_DEFAULT(tx_io_num, rx_io_num, op_mode) {.mode = op_mode, .tx_io = tx_io_num, .rx_io = rx_io_num, \
|
||||
.clkout_io = CAN_IO_UNUSED, .bus_off_io = CAN_IO_UNUSED, \
|
||||
.tx_queue_len = 5, .rx_queue_len = 5, \
|
||||
.alerts_enabled = CAN_ALERT_NONE, .clkout_divider = 0, }
|
||||
|
||||
/**
|
||||
* @brief Initializer macros for timing configuration structure
|
||||
*
|
||||
* The following initializer macros offer commonly found bit rates.
|
||||
*
|
||||
* @note These timing values are based on the assumption APB clock is at 80MHz
|
||||
*/
|
||||
#define CAN_TIMING_CONFIG_25KBITS() {.brp = 128, .tseg_1 = 16, .tseg_2 = 8, .sjw = 3, .triple_sampling = false}
|
||||
#define CAN_TIMING_CONFIG_50KBITS() {.brp = 80, .tseg_1 = 15, .tseg_2 = 4, .sjw = 3, .triple_sampling = false}
|
||||
#define CAN_TIMING_CONFIG_100KBITS() {.brp = 40, .tseg_1 = 15, .tseg_2 = 4, .sjw = 3, .triple_sampling = false}
|
||||
#define CAN_TIMING_CONFIG_125KBITS() {.brp = 32, .tseg_1 = 15, .tseg_2 = 4, .sjw = 3, .triple_sampling = false}
|
||||
#define CAN_TIMING_CONFIG_250KBITS() {.brp = 16, .tseg_1 = 15, .tseg_2 = 4, .sjw = 3, .triple_sampling = false}
|
||||
#define CAN_TIMING_CONFIG_500KBITS() {.brp = 8, .tseg_1 = 15, .tseg_2 = 4, .sjw = 3, .triple_sampling = false}
|
||||
#define CAN_TIMING_CONFIG_800KBITS() {.brp = 4, .tseg_1 = 16, .tseg_2 = 8, .sjw = 3, .triple_sampling = false}
|
||||
#define CAN_TIMING_CONFIG_1MBITS() {.brp = 4, .tseg_1 = 15, .tseg_2 = 4, .sjw = 3, .triple_sampling = false}
|
||||
|
||||
/**
|
||||
* @brief Initializer macro for filter configuration to accept all IDs
|
||||
*/
|
||||
#define CAN_FILTER_CONFIG_ACCEPT_ALL() {.acceptance_code = 0, .acceptance_mask = 0xFFFFFFFF, .single_filter = true}
|
||||
|
||||
/**
|
||||
* @brief Alert flags
|
||||
*
|
||||
* The following flags represents the various kind of alerts available in
|
||||
* the CAN driver. These flags can be used when configuring/reconfiguring
|
||||
* alerts, or when calling can_read_alerts().
|
||||
*
|
||||
* @note The CAN_ALERT_AND_LOG flag is not an actual alert, but will configure
|
||||
* the CAN driver to log to UART when an enabled alert occurs.
|
||||
*/
|
||||
#define CAN_ALERT_TX_IDLE 0x0001 /**< Alert(1): No more messages to transmit */
|
||||
#define CAN_ALERT_TX_SUCCESS 0x0002 /**< Alert(2): The previous transmission was successful */
|
||||
#define CAN_ALERT_BELOW_ERR_WARN 0x0004 /**< Alert(4): Both error counters have dropped below error warning limit */
|
||||
#define CAN_ALERT_ERR_ACTIVE 0x0008 /**< Alert(8): CAN controller has become error active */
|
||||
#define CAN_ALERT_RECOVERY_IN_PROGRESS 0x0010 /**< Alert(16): CAN controller is undergoing bus recovery */
|
||||
#define CAN_ALERT_BUS_RECOVERED 0x0020 /**< Alert(32): CAN controller has successfully completed bus recovery */
|
||||
#define CAN_ALERT_ARB_LOST 0x0040 /**< Alert(64): The previous transmission lost arbitration */
|
||||
#define CAN_ALERT_ABOVE_ERR_WARN 0x0080 /**< Alert(128): One of the error counters have exceeded the error warning limit */
|
||||
#define CAN_ALERT_BUS_ERROR 0x0100 /**< Alert(256): A (Bit, Stuff, CRC, Form, ACK) error has occurred on the bus */
|
||||
#define CAN_ALERT_TX_FAILED 0x0200 /**< Alert(512): The previous transmission has failed (for single shot transmission) */
|
||||
#define CAN_ALERT_RX_QUEUE_FULL 0x0400 /**< Alert(1024): The RX queue is full causing a frame to be lost */
|
||||
#define CAN_ALERT_ERR_PASS 0x0800 /**< Alert(2048): CAN controller has become error passive */
|
||||
#define CAN_ALERT_BUS_OFF 0x1000 /**< Alert(4096): Bus-off condition occurred. CAN controller can no longer influence bus */
|
||||
#define CAN_ALERT_ALL 0x1FFF /**< Bit mask to enable all alerts during configuration */
|
||||
#define CAN_ALERT_NONE 0x0000 /**< Bit mask to disable all alerts during configuration */
|
||||
#define CAN_ALERT_AND_LOG 0x2000 /**< Bit mask to enable alerts to also be logged when they occur */
|
||||
|
||||
/**
|
||||
* @brief Message flags
|
||||
*
|
||||
* The message flags are used to indicate the type of message transmitted/received.
|
||||
* Some flags also specify the type of transmission.
|
||||
*/
|
||||
#define CAN_MSG_FLAG_NONE 0x00 /**< No message flags (Standard Frame Format) */
|
||||
#define CAN_MSG_FLAG_EXTD 0x01 /**< Extended Frame Format (29bit ID) */
|
||||
#define CAN_MSG_FLAG_RTR 0x02 /**< Message is a Remote Transmit Request */
|
||||
#define CAN_MSG_FLAG_SS 0x04 /**< Transmit as a Single Shot Transmission */
|
||||
#define CAN_MSG_FLAG_SELF 0x08 /**< Transmit as a Self Reception Request */
|
||||
#define CAN_MSG_FLAG_DLC_NON_COMP 0x10 /**< Message's Data length code is larger than 8. This will break compliance with CAN2.0B */
|
||||
|
||||
/**
|
||||
* @brief Miscellaneous macros
|
||||
*/
|
||||
#define CAN_EXTD_ID_MASK 0x1FFFFFFF /**< Bit mask for 29 bit Extended Frame Format ID */
|
||||
#define CAN_STD_ID_MASK 0x7FF /**< Bit mask for 11 bit Standard Frame Format ID */
|
||||
#define CAN_MAX_DATA_LEN 8 /**< Maximum number of data bytes in a CAN2.0B frame */
|
||||
#define CAN_IO_UNUSED (-1) /**< Marks GPIO as unused in CAN configuration */
|
||||
/** @endcond */
|
||||
|
||||
/* ----------------------- Enum and Struct Definitions ---------------------- */
|
||||
|
||||
/**
|
||||
* @brief CAN driver operating modes
|
||||
*/
|
||||
typedef enum {
|
||||
CAN_MODE_NORMAL, /**< Normal operating mode where CAN controller can send/receive/acknowledge messages */
|
||||
CAN_MODE_NO_ACK, /**< Transmission does not require acknowledgment. Use this mode for self testing */
|
||||
CAN_MODE_LISTEN_ONLY, /**< The CAN controller will not influence the bus (No transmissions or acknowledgments) but can receive messages */
|
||||
} can_mode_t;
|
||||
|
||||
/**
|
||||
* @brief CAN driver states
|
||||
*/
|
||||
typedef enum {
|
||||
CAN_STATE_STOPPED, /**< Stopped state. The CAN controller will not participate in any CAN bus activities */
|
||||
CAN_STATE_RUNNING, /**< Running state. The CAN controller can transmit and receive messages */
|
||||
CAN_STATE_BUS_OFF, /**< Bus-off state. The CAN controller cannot participate in bus activities until it has recovered */
|
||||
CAN_STATE_RECOVERING, /**< Recovering state. The CAN controller is undergoing bus recovery */
|
||||
} can_state_t;
|
||||
|
||||
/**
|
||||
* @brief Structure for general configuration of the CAN driver
|
||||
*
|
||||
* @note Macro initializers are available for this structure
|
||||
*/
|
||||
typedef struct {
|
||||
can_mode_t mode; /**< Mode of CAN controller */
|
||||
gpio_num_t tx_io; /**< Transmit GPIO number */
|
||||
gpio_num_t rx_io; /**< Receive GPIO number */
|
||||
gpio_num_t clkout_io; /**< CLKOUT GPIO number (optional, set to -1 if unused) */
|
||||
gpio_num_t bus_off_io; /**< Bus off indicator GPIO number (optional, set to -1 if unused) */
|
||||
uint32_t tx_queue_len; /**< Number of messages TX queue can hold (set to 0 to disable TX Queue) */
|
||||
uint32_t rx_queue_len; /**< Number of messages RX queue can hold */
|
||||
uint32_t alerts_enabled; /**< Bit field of alerts to enable (see documentation) */
|
||||
uint32_t clkout_divider; /**< CLKOUT divider. Can be 1 or any even number from 2 to 14 (optional, set to 0 if unused) */
|
||||
} can_general_config_t;
|
||||
|
||||
/**
|
||||
* @brief Structure for bit timing configuration of the CAN driver
|
||||
*
|
||||
* @note Macro initializers are available for this structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t brp; /**< Baudrate prescaler (APB clock divider, even number from 2 to 128) */
|
||||
uint8_t tseg_1; /**< Timing segment 1 (Number of time quanta, between 1 to 16) */
|
||||
uint8_t tseg_2; /**< Timing segment 2 (Number of time quanta, 1 to 8) */
|
||||
uint8_t sjw; /**< Synchronization Jump Width (Max time quanta jump for synchronize from 1 to 4) */
|
||||
bool triple_sampling; /**< Enables triple sampling when the CAN controller samples a bit */
|
||||
} can_timing_config_t;
|
||||
|
||||
/**
|
||||
* @brief Structure for acceptance filter configuration of the CAN driver (see documentation)
|
||||
*
|
||||
* @note Macro initializers are available for this structure
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t acceptance_code; /**< 32-bit acceptance code */
|
||||
uint32_t acceptance_mask; /**< 32-bit acceptance mask */
|
||||
bool single_filter; /**< Use Single Filter Mode (see documentation) */
|
||||
} can_filter_config_t;
|
||||
|
||||
/**
|
||||
* @brief Structure to store status information of CAN driver
|
||||
*/
|
||||
typedef struct {
|
||||
can_state_t state; /**< Current state of CAN controller (Stopped/Running/Bus-Off/Recovery) */
|
||||
uint32_t msgs_to_tx; /**< Number of messages queued for transmission or awaiting transmission completion */
|
||||
uint32_t msgs_to_rx; /**< Number of messages in RX queue waiting to be read */
|
||||
uint32_t tx_error_counter; /**< Current value of Transmit Error Counter */
|
||||
uint32_t rx_error_counter; /**< Current value of Receive Error Counter */
|
||||
uint32_t tx_failed_count; /**< Number of messages that failed transmissions */
|
||||
uint32_t rx_missed_count; /**< Number of messages that were lost due to a full RX queue */
|
||||
uint32_t arb_lost_count; /**< Number of instances arbitration was lost */
|
||||
uint32_t bus_error_count; /**< Number of instances a bus error has occurred */
|
||||
} can_status_info_t;
|
||||
|
||||
/**
|
||||
* @brief Structure to store a CAN message
|
||||
*
|
||||
* @note The flags member is used to control the message type, and transmission
|
||||
* type (see documentation for message flags)
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t flags; /**< Bit field of message flags indicates frame/transmission type (see documentation) */
|
||||
uint32_t identifier; /**< 11 or 29 bit identifier */
|
||||
uint8_t data_length_code; /**< Data length code */
|
||||
uint8_t data[CAN_MAX_DATA_LEN]; /**< Data bytes (not relevant in RTR frame) */
|
||||
} can_message_t;
|
||||
|
||||
/* ----------------------------- Public API -------------------------------- */
|
||||
|
||||
/**
|
||||
* @brief Install CAN driver
|
||||
*
|
||||
* This function installs the CAN driver using three configuration structures.
|
||||
* The required memory is allocated and the CAN driver is placed in the stopped
|
||||
* state after running this function.
|
||||
*
|
||||
* @param[in] g_config General configuration structure
|
||||
* @param[in] t_config Timing configuration structure
|
||||
* @param[in] f_config Filter configuration structure
|
||||
*
|
||||
* @note Macro initializers are available for the configuration structures (see documentation)
|
||||
*
|
||||
* @note To reinstall the CAN driver, call can_driver_uninstall() first
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Successfully installed CAN driver
|
||||
* - ESP_ERR_INVALID_ARG: Arguments are invalid
|
||||
* - ESP_ERR_NO_MEM: Insufficient memory
|
||||
* - ESP_ERR_INVALID_STATE: Driver is already installed
|
||||
*/
|
||||
esp_err_t can_driver_install(const can_general_config_t *g_config, const can_timing_config_t *t_config, const can_filter_config_t *f_config);
|
||||
|
||||
/**
|
||||
* @brief Uninstall the CAN driver
|
||||
*
|
||||
* This function uninstalls the CAN driver, freeing the memory utilized by the
|
||||
* driver. This function can only be called when the driver is in the stopped
|
||||
* state or the bus-off state.
|
||||
*
|
||||
* @warning The application must ensure that no tasks are blocked on TX/RX
|
||||
* queues or alerts when this function is called.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Successfully uninstalled CAN driver
|
||||
* - ESP_ERR_INVALID_STATE: Driver is not in stopped/bus-off state, or is not installed
|
||||
*/
|
||||
esp_err_t can_driver_uninstall();
|
||||
|
||||
/**
|
||||
* @brief Start the CAN driver
|
||||
*
|
||||
* This function starts the CAN driver, putting the CAN driver into the running
|
||||
* state. This allows the CAN driver to participate in CAN bus activities such
|
||||
* as transmitting/receiving messages. The RX queue is reset in this function,
|
||||
* clearing any unread messages. This function can only be called when the CAN
|
||||
* driver is in the stopped state.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: CAN driver is now running
|
||||
* - ESP_ERR_INVALID_STATE: Driver is not in stopped state, or is not installed
|
||||
*/
|
||||
esp_err_t can_start();
|
||||
|
||||
/**
|
||||
* @brief Stop the CAN driver
|
||||
*
|
||||
* This function stops the CAN driver, preventing any further message from being
|
||||
* transmitted or received until can_start() is called. Any messages in the TX
|
||||
* queue are cleared. Any messages in the RX queue should be read by the
|
||||
* application after this function is called. This function can only be called
|
||||
* when the CAN driver is in the running state.
|
||||
*
|
||||
* @warning A message currently being transmitted/received on the CAN bus will
|
||||
* be ceased immediately. This may lead to other CAN nodes interpreting
|
||||
* the unfinished message as an error.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: CAN driver is now Stopped
|
||||
* - ESP_ERR_INVALID_STATE: Driver is not in running state, or is not installed
|
||||
*/
|
||||
esp_err_t can_stop();
|
||||
|
||||
/**
|
||||
* @brief Transmit a CAN message
|
||||
*
|
||||
* This function queues a CAN message for transmission. Transmission will start
|
||||
* immediately if no other messages are queued for transmission. If the TX queue
|
||||
* is full, this function will block until more space becomes available or until
|
||||
* it timesout. If the TX queue is disabled (TX queue length = 0 in configuration),
|
||||
* this function will return immediately if another message is undergoing
|
||||
* transmission. This function can only be called when the CAN driver is in the
|
||||
* running state and cannot be called under Listen Only Mode.
|
||||
*
|
||||
* @param[in] message Message to transmit
|
||||
* @param[in] ticks_to_wait Number of FreeRTOS ticks to block on the TX queue
|
||||
*
|
||||
* @note This function does not guarantee that the transmission is successful.
|
||||
* The TX_SUCCESS/TX_FAILED alert can be enabled to alert the application
|
||||
* upon the success/failure of a transmission.
|
||||
*
|
||||
* @note The TX_IDLE alert can be used to alert the application when no other
|
||||
* messages are awaiting transmission.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Transmission successfully queued/initiated
|
||||
* - ESP_ERR_INVALID_ARG: Arguments are invalid
|
||||
* - ESP_ERR_TIMEOUT: Timed out waiting for space on TX queue
|
||||
* - ESP_FAIL: TX queue is disabled and another message is currently transmitting
|
||||
* - ESP_ERR_INVALID_STATE: CAN driver is not in running state, or is not installed
|
||||
* - ESP_ERR_NOT_SUPPORTED: Listen Only Mode does not support transmissions
|
||||
*/
|
||||
esp_err_t can_transmit(const can_message_t *message, TickType_t ticks_to_wait);
|
||||
|
||||
/**
|
||||
* @brief Receive a CAN message
|
||||
*
|
||||
* This function receives a message from the RX queue. The flags field of the
|
||||
* message structure will indicate the type of message received. This function
|
||||
* will block if there are no messages in the RX queue
|
||||
*
|
||||
* @param[out] message Received message
|
||||
* @param[in] ticks_to_wait Number of FreeRTOS ticks to block on RX queue
|
||||
*
|
||||
* @warning The flags field of the received message should be checked to determine
|
||||
* if the received message contains any data bytes.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Message successfully received from RX queue
|
||||
* - ESP_ERR_TIMEOUT: Timed out waiting for message
|
||||
* - ESP_ERR_INVALID_ARG: Arguments are invalid
|
||||
* - ESP_ERR_INVALID_STATE: CAN driver is not installed
|
||||
*/
|
||||
esp_err_t can_receive(can_message_t *message, TickType_t ticks_to_wait);
|
||||
|
||||
/**
|
||||
* @brief Read CAN driver alerts
|
||||
*
|
||||
* This function will read the alerts raised by the CAN driver. If no alert has
|
||||
* been when this function is called, this function will block until an alert
|
||||
* occurs or until it timeouts.
|
||||
*
|
||||
* @param[out] alerts Bit field of raised alerts (see documentation for alert flags)
|
||||
* @param[in] ticks_to_wait Number of FreeRTOS ticks to block for alert
|
||||
*
|
||||
* @note Multiple alerts can be raised simultaneously. The application should
|
||||
* check for all alerts that have been enabled.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Alerts read
|
||||
* - ESP_ERR_TIMEOUT: Timed out waiting for alerts
|
||||
* - ESP_ERR_INVALID_ARG: Arguments are invalid
|
||||
* - ESP_ERR_INVALID_STATE: CAN driver is not installed
|
||||
*/
|
||||
esp_err_t can_read_alerts(uint32_t *alerts, TickType_t ticks_to_wait);
|
||||
|
||||
/**
|
||||
* @brief Reconfigure which alerts are enabled
|
||||
*
|
||||
* This function reconfigures which alerts are enabled. If there are alerts
|
||||
* which have not been read whilst reconfiguring, this function can read those
|
||||
* alerts.
|
||||
*
|
||||
* @param[in] alerts_enabled Bit field of alerts to enable (see documentation for alert flags)
|
||||
* @param[out] current_alerts Bit field of currently raised alerts. Set to NULL if unused
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Alerts reconfigured
|
||||
* - ESP_ERR_INVALID_STATE: CAN driver is not installed
|
||||
*/
|
||||
esp_err_t can_reconfigure_alerts(uint32_t alerts_enabled, uint32_t *current_alerts);
|
||||
|
||||
/**
|
||||
* @brief Start the bus recovery process
|
||||
*
|
||||
* This function initiates the bus recovery process when the CAN driver is in
|
||||
* the bus-off state. Once initiated, the CAN driver will enter the recovering
|
||||
* state and wait for 128 occurrences of the bus-free signal on the CAN bus
|
||||
* before returning to the stopped state. This function will reset the TX queue,
|
||||
* clearing any messages pending transmission.
|
||||
*
|
||||
* @note The BUS_RECOVERED alert can be enabled to alert the application when
|
||||
* the bus recovery process completes.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Bus recovery started
|
||||
* - ESP_ERR_INVALID_STATE: CAN driver is not in the bus-off state, or is not installed
|
||||
*/
|
||||
esp_err_t can_initiate_recovery();
|
||||
|
||||
/**
|
||||
* @brief Get current status information of the CAN driver
|
||||
*
|
||||
* @param[out] status_info Status information
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Status information retrieved
|
||||
* - ESP_ERR_INVALID_ARG: Arguments are invalid
|
||||
* - ESP_ERR_INVALID_STATE: CAN driver is not installed
|
||||
*/
|
||||
esp_err_t can_get_status_info(can_status_info_t *status_info);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_DRIVER_CAN_H_*/
|
||||
|
@ -249,13 +249,13 @@ esp_err_t gpio_config(const gpio_config_t *pGPIOConfig);
|
||||
|
||||
/**
|
||||
* @brief Reset an gpio to default state (select gpio function, enable pullup and disable input and output).
|
||||
*
|
||||
*
|
||||
* @param gpio_num GPIO number.
|
||||
*
|
||||
*
|
||||
* @note This function also configures the IOMUX for this pin to the GPIO
|
||||
* function, and disconnects any other peripheral output configured via GPIO
|
||||
* Matrix.
|
||||
*
|
||||
*
|
||||
* @return Always return ESP_OK.
|
||||
*/
|
||||
esp_err_t gpio_reset_pin(gpio_num_t gpio_num);
|
||||
@ -359,27 +359,27 @@ esp_err_t gpio_set_direction(gpio_num_t gpio_num, gpio_mode_t mode);
|
||||
esp_err_t gpio_set_pull_mode(gpio_num_t gpio_num, gpio_pull_mode_t pull);
|
||||
|
||||
/**
|
||||
* @brief Enable GPIO wake-up function.
|
||||
*
|
||||
* @param gpio_num GPIO number.
|
||||
*
|
||||
* @param intr_type GPIO wake-up type. Only GPIO_INTR_LOW_LEVEL or GPIO_INTR_HIGH_LEVEL can be used.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
* @brief Enable GPIO wake-up function.
|
||||
*
|
||||
* @param gpio_num GPIO number.
|
||||
*
|
||||
* @param intr_type GPIO wake-up type. Only GPIO_INTR_LOW_LEVEL or GPIO_INTR_HIGH_LEVEL can be used.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type);
|
||||
|
||||
/**
|
||||
* @brief Disable GPIO wake-up function.
|
||||
*
|
||||
* @param gpio_num GPIO number
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
* @brief Disable GPIO wake-up function.
|
||||
*
|
||||
* @param gpio_num GPIO number
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t gpio_wakeup_disable(gpio_num_t gpio_num);
|
||||
|
||||
/**
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -455,7 +455,7 @@ void ledc_fade_func_uninstall();
|
||||
esp_err_t ledc_fade_start(ledc_mode_t speed_mode, ledc_channel_t channel, ledc_fade_mode_t fade_mode);
|
||||
|
||||
/**
|
||||
* @brief A thread-safe API to set duty for LEDC channel and update the settings immediately
|
||||
* @brief A thread-safe API to set duty for LEDC channel and return when duty updated.
|
||||
* @note If a fade operation is running in progress on that channel, the driver would not allow it to be stopped.
|
||||
* Other duty operations will have to wait until the fade operation has finished.
|
||||
*
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -98,6 +98,8 @@ typedef intr_handle_t pcnt_isr_handle_t;
|
||||
|
||||
/**
|
||||
* @brief Configure Pulse Counter unit
|
||||
* @note
|
||||
* This function will disable three events: PCNT_EVT_L_LIM, PCNT_EVT_H_LIM, PCNT_EVT_ZERO.
|
||||
*
|
||||
* @param pcnt_config Pointer of Pulse Counter unit configure parameter
|
||||
*
|
||||
@ -233,16 +235,19 @@ esp_err_t pcnt_get_event_value(pcnt_unit_t unit, pcnt_evt_type_t evt_type, int16
|
||||
/**
|
||||
* @brief Register PCNT interrupt handler, the handler is an ISR.
|
||||
* The handler will be attached to the same CPU core that this function is running on.
|
||||
* Please do not use pcnt_isr_service_install if this function was called.
|
||||
*
|
||||
* @param fn Interrupt handler function.
|
||||
* @param arg Parameter for handler function
|
||||
* @param intr_alloc_flags Flags used to allocate the interrupt. One or multiple (ORred)
|
||||
* ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info.
|
||||
* @param handle Pointer to return handle. If non-NULL, a handle for the interrupt will
|
||||
* be returned here.
|
||||
* be returned here. Calling esp_intr_free to unregister this ISR service if needed,
|
||||
* but only if the handle is not NULL.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_NOT_FOUND Can not find the interrupt that matches the flags.
|
||||
* - ESP_ERR_INVALID_ARG Function pointer error.
|
||||
*/
|
||||
esp_err_t pcnt_isr_register(void (*fn)(void*), void * arg, int intr_alloc_flags, pcnt_isr_handle_t *handle);
|
||||
@ -358,7 +363,8 @@ esp_err_t pcnt_isr_handler_add(pcnt_unit_t unit, void(*isr_handler)(void *), voi
|
||||
/**
|
||||
* @brief Install PCNT ISR service.
|
||||
* @note We can manage different interrupt service for each unit.
|
||||
* Please do not use pcnt_isr_register if this function was called.
|
||||
* This function will use the default ISR handle service, Calling pcnt_isr_service_uninstall to
|
||||
* uninstall the default service if needed. Please do not use pcnt_isr_register if this function was called.
|
||||
*
|
||||
* @param intr_alloc_flags Flags used to allocate the interrupt. One or multiple (ORred)
|
||||
* ESP_INTR_FLAG_* values. See esp_intr_alloc.h for more info.
|
||||
|
@ -35,7 +35,7 @@ typedef enum {
|
||||
* @brief Determine if the specified GPIO is a valid RTC GPIO.
|
||||
*
|
||||
* @param gpio_num GPIO number
|
||||
* @return true if GPIO is valid for RTC GPIO use. talse otherwise.
|
||||
* @return true if GPIO is valid for RTC GPIO use. false otherwise.
|
||||
*/
|
||||
inline static bool rtc_gpio_is_valid_gpio(gpio_num_t gpio_num)
|
||||
{
|
||||
@ -223,29 +223,52 @@ esp_err_t rtc_gpio_isolate(gpio_num_t gpio_num);
|
||||
void rtc_gpio_force_hold_dis_all();
|
||||
|
||||
/**
|
||||
* @brief Set RTC GPIO pad drive capability
|
||||
*
|
||||
* @param gpio_num GPIO number, only support output GPIOs
|
||||
* @param strength Drive capability of the pad
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
* @brief Set RTC GPIO pad drive capability
|
||||
*
|
||||
* @param gpio_num GPIO number, only support output GPIOs
|
||||
* @param strength Drive capability of the pad
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t rtc_gpio_set_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t strength);
|
||||
|
||||
/**
|
||||
* @brief Get RTC GPIO pad drive capability
|
||||
*
|
||||
* @param gpio_num GPIO number, only support output GPIOs
|
||||
* @param strength Pointer to accept drive capability of the pad
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
* @brief Get RTC GPIO pad drive capability
|
||||
*
|
||||
* @param gpio_num GPIO number, only support output GPIOs
|
||||
* @param strength Pointer to accept drive capability of the pad
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t rtc_gpio_get_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t* strength);
|
||||
|
||||
/**
|
||||
* @brief Enable wakeup from sleep mode using specific GPIO
|
||||
* @param gpio_num GPIO number
|
||||
* @param intr_type Wakeup on high level (GPIO_INTR_HIGH_LEVEL) or low level
|
||||
* (GPIO_INTR_LOW_LEVEL)
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG if gpio_num is not an RTC IO, or intr_type is not
|
||||
* one of GPIO_INTR_HIGH_LEVEL, GPIO_INTR_LOW_LEVEL.
|
||||
*/
|
||||
esp_err_t rtc_gpio_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type);
|
||||
|
||||
/**
|
||||
* @brief Disable wakeup from sleep mode using specific GPIO
|
||||
* @param gpio_num GPIO number
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG if gpio_num is not an RTC IO
|
||||
*/
|
||||
esp_err_t rtc_gpio_wakeup_disable(gpio_num_t gpio_num);
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -47,10 +47,12 @@ typedef enum {
|
||||
|
||||
/// Timing of SDIO slave
|
||||
typedef enum {
|
||||
SDIO_SLAVE_TIMING_NSEND_PSAMPLE = 0,///< Send at negedge, and sample at posedge. Default value for SD protocol.
|
||||
SDIO_SLAVE_TIMING_NSEND_NSAMPLE, ///< Send at negedge, and sample at negedge
|
||||
SDIO_SLAVE_TIMING_PSEND_PSAMPLE, ///< Send at posedge, and sample at posedge
|
||||
SDIO_SLAVE_TIMING_PSEND_PSAMPLE = 0,/**< Send at posedge, and sample at posedge. Default value for HS mode.
|
||||
* Normally there's no problem using this to work in DS mode.
|
||||
*/
|
||||
SDIO_SLAVE_TIMING_NSEND_PSAMPLE ,///< Send at negedge, and sample at posedge. Default value for DS mode and below.
|
||||
SDIO_SLAVE_TIMING_PSEND_NSAMPLE, ///< Send at posedge, and sample at negedge
|
||||
SDIO_SLAVE_TIMING_NSEND_NSAMPLE, ///< Send at negedge, and sample at negedge
|
||||
} sdio_slave_timing_t;
|
||||
|
||||
/// Configuration of SDIO slave mode
|
||||
@ -72,20 +74,20 @@ typedef struct {
|
||||
///< Buffer size of the slave pre-defined between host and slave before communication. All receive buffer given to the driver should be larger than this.
|
||||
sdio_event_cb_t event_cb; ///< when the host interrupts slave, this callback will be called with interrupt number (0-7).
|
||||
uint32_t flags; ///< Features to be enabled for the slave, combinations of ``SDIO_SLAVE_FLAG_*``.
|
||||
#define SDIO_SLAVE_FLAG_DAT2_DISABLED BIT(0) /**< It is required by the SD specification that all 4 data
|
||||
lines should be used and pulled up even in 1-bit mode or SPI mode. However, as a feature, the user can speicfy
|
||||
this flag to make use of DAT2 pin in 1-bit mode. Note that the host cannot read CCCR registers to know we don't
|
||||
#define SDIO_SLAVE_FLAG_DAT2_DISABLED BIT(0) /**< It is required by the SD specification that all 4 data
|
||||
lines should be used and pulled up even in 1-bit mode or SPI mode. However, as a feature, the user can specify
|
||||
this flag to make use of DAT2 pin in 1-bit mode. Note that the host cannot read CCCR registers to know we don't
|
||||
support 4-bit mode anymore, please do this at your own risk.
|
||||
*/
|
||||
#define SDIO_SLAVE_FLAG_HOST_INTR_DISABLED BIT(1) /**< The DAT1 line is used as the interrupt line in SDIO
|
||||
protocol. However, as a feature, the user can speicfy this flag to make use of DAT1 pin of the slave in 1-bit
|
||||
#define SDIO_SLAVE_FLAG_HOST_INTR_DISABLED BIT(1) /**< The DAT1 line is used as the interrupt line in SDIO
|
||||
protocol. However, as a feature, the user can specify this flag to make use of DAT1 pin of the slave in 1-bit
|
||||
mode. Note that the host has to do polling to the interrupt registers to know whether there are interrupts from
|
||||
the slave. And it cannot read CCCR registers to know we don't support 4-bit mode anymore, please do this at
|
||||
the slave. And it cannot read CCCR registers to know we don't support 4-bit mode anymore, please do this at
|
||||
your own risk.
|
||||
*/
|
||||
#define SDIO_SLAVE_FLAG_INTERNAL_PULLUP BIT(2) /**< Enable internal pullups for enabled pins. It is required
|
||||
by the SD specification that all the 4 data lines should be pulled up even in 1-bit mode or SPI mode. Note that
|
||||
the internal pull-ups are not sufficient for stable communication, please do connect external pull-ups on the
|
||||
#define SDIO_SLAVE_FLAG_INTERNAL_PULLUP BIT(2) /**< Enable internal pullups for enabled pins. It is required
|
||||
by the SD specification that all the 4 data lines should be pulled up even in 1-bit mode or SPI mode. Note that
|
||||
the internal pull-ups are not sufficient for stable communication, please do connect external pull-ups on the
|
||||
bus. This is only for example and debug use.
|
||||
*/
|
||||
} sdio_slave_config_t;
|
||||
@ -214,12 +216,12 @@ uint8_t* sdio_slave_recv_get_buf(sdio_slave_buf_handle_t handle, size_t *len_o);
|
||||
esp_err_t sdio_slave_send_queue(uint8_t* addr, size_t len, void* arg, TickType_t wait);
|
||||
|
||||
/** Return the ownership of a finished transaction.
|
||||
* @param arg_o Argument of the finished transaction.
|
||||
* @param out_arg Argument of the finished transaction. Set to NULL if unused.
|
||||
* @param wait Time to wait if there's no finished sending transaction.
|
||||
*
|
||||
* @return ESP_ERR_TIMEOUT if no transaction finished, or ESP_OK if succeed.
|
||||
*/
|
||||
esp_err_t sdio_slave_send_get_finished(void** arg_o, TickType_t wait);
|
||||
esp_err_t sdio_slave_send_get_finished(void** out_arg, TickType_t wait);
|
||||
|
||||
/** Start a new sending transfer, and wait for it (blocked) to be finished.
|
||||
*
|
||||
|
@ -31,11 +31,13 @@
|
||||
#define MMC_SEND_EXT_CSD 8 /* R1 */
|
||||
#define MMC_SEND_CSD 9 /* R2 */
|
||||
#define MMC_SEND_CID 10 /* R1 */
|
||||
#define MMC_READ_DAT_UNTIL_STOP 11 /* R1 */
|
||||
#define MMC_STOP_TRANSMISSION 12 /* R1B */
|
||||
#define MMC_SEND_STATUS 13 /* R1 */
|
||||
#define MMC_SET_BLOCKLEN 16 /* R1 */
|
||||
#define MMC_READ_BLOCK_SINGLE 17 /* R1 */
|
||||
#define MMC_READ_BLOCK_MULTIPLE 18 /* R1 */
|
||||
#define MMC_WRITE_DAT_UNTIL_STOP 20 /* R1 */
|
||||
#define MMC_SET_BLOCK_COUNT 23 /* R1 */
|
||||
#define MMC_WRITE_BLOCK_SINGLE 24 /* R1 */
|
||||
#define MMC_WRITE_BLOCK_MULTIPLE 25 /* R1 */
|
||||
@ -89,6 +91,7 @@
|
||||
/* SD mode R1 response type bits */
|
||||
#define MMC_R1_READY_FOR_DATA (1<<8) /* ready for next transfer */
|
||||
#define MMC_R1_APP_CMD (1<<5) /* app. commands supported */
|
||||
#define MMC_R1_SWITCH_ERROR (1<<7) /* switch command did not succeed */
|
||||
|
||||
/* SPI mode R1 response type bits */
|
||||
#define SD_SPI_R1_IDLE_STATE (1<<0)
|
||||
@ -129,6 +132,13 @@
|
||||
#define EXT_CSD_STRUCTURE 194 /* RO */
|
||||
#define EXT_CSD_CARD_TYPE 196 /* RO */
|
||||
#define EXT_CSD_SEC_COUNT 212 /* RO */
|
||||
#define EXT_CSD_PWR_CL_26_360 203 /* RO */
|
||||
#define EXT_CSD_PWR_CL_52_360 202 /* RO */
|
||||
#define EXT_CSD_PWR_CL_26_195 201 /* RO */
|
||||
#define EXT_CSD_PWR_CL_52_195 200 /* RO */
|
||||
#define EXT_CSD_POWER_CLASS 187 /* R/W */
|
||||
#define EXT_CSD_CMD_SET 191 /* R/W */
|
||||
#define EXT_CSD_S_CMD_SET 504 /* RO */
|
||||
|
||||
/* EXT_CSD field definitions */
|
||||
#define EXT_CSD_CMD_SET_NORMAL (1U << 0)
|
||||
@ -151,16 +161,19 @@
|
||||
/* EXT_CSD_CARD_TYPE */
|
||||
/* The only currently valid values for this field are 0x01, 0x03, 0x07,
|
||||
* 0x0B and 0x0F. */
|
||||
#define EXT_CSD_CARD_TYPE_F_26M (1 << 0)
|
||||
#define EXT_CSD_CARD_TYPE_F_52M (1 << 1)
|
||||
#define EXT_CSD_CARD_TYPE_F_52M_1_8V (1 << 2)
|
||||
#define EXT_CSD_CARD_TYPE_F_52M_1_2V (1 << 3)
|
||||
#define EXT_CSD_CARD_TYPE_F_26M (1 << 0) /* SDR at "rated voltages */
|
||||
#define EXT_CSD_CARD_TYPE_F_52M (1 << 1) /* SDR at "rated voltages */
|
||||
#define EXT_CSD_CARD_TYPE_F_52M_1_8V (1 << 2) /* DDR, 1.8V or 3.3V I/O */
|
||||
#define EXT_CSD_CARD_TYPE_F_52M_1_2V (1 << 3) /* DDR, 1.2V I/O */
|
||||
#define EXT_CSD_CARD_TYPE_26M 0x01
|
||||
#define EXT_CSD_CARD_TYPE_52M 0x03
|
||||
#define EXT_CSD_CARD_TYPE_52M_V18 0x07
|
||||
#define EXT_CSD_CARD_TYPE_52M_V12 0x0b
|
||||
#define EXT_CSD_CARD_TYPE_52M_V12_18 0x0f
|
||||
|
||||
/* EXT_CSD MMC */
|
||||
#define EXT_CSD_MMC_SIZE 512
|
||||
|
||||
/* MMC_SWITCH access mode */
|
||||
#define MMC_SWITCH_MODE_CMD_SET 0x00 /* Change the command set */
|
||||
#define MMC_SWITCH_MODE_SET_BITS 0x01 /* Set bits in value */
|
||||
@ -445,5 +458,9 @@ static inline uint32_t MMC_RSP_BITS(uint32_t *src, int start, int len)
|
||||
/* CISTPL_FUNCID codes */
|
||||
#define TPLFID_FUNCTION_SDIO 0x0c
|
||||
|
||||
/* Timing */
|
||||
#define SDMMC_TIMING_LEGACY 0
|
||||
#define SDMMC_TIMING_HIGHSPEED 1
|
||||
#define SDMMC_TIMING_MMC_DDR52 2
|
||||
|
||||
#endif //_SDMMC_DEFS_H_
|
||||
|
@ -33,13 +33,17 @@ extern "C" {
|
||||
* Uses SDMMC peripheral, with 4-bit mode enabled, and max frequency set to 20MHz
|
||||
*/
|
||||
#define SDMMC_HOST_DEFAULT() {\
|
||||
.flags = SDMMC_HOST_FLAG_4BIT, \
|
||||
.flags = SDMMC_HOST_FLAG_8BIT | \
|
||||
SDMMC_HOST_FLAG_4BIT | \
|
||||
SDMMC_HOST_FLAG_1BIT | \
|
||||
SDMMC_HOST_FLAG_DDR, \
|
||||
.slot = SDMMC_HOST_SLOT_1, \
|
||||
.max_freq_khz = SDMMC_FREQ_DEFAULT, \
|
||||
.io_voltage = 3.3f, \
|
||||
.init = &sdmmc_host_init, \
|
||||
.set_bus_width = &sdmmc_host_set_bus_width, \
|
||||
.get_bus_width = &sdmmc_host_get_slot_width, \
|
||||
.set_bus_ddr_mode = &sdmmc_host_set_bus_ddr_mode, \
|
||||
.set_card_clk = &sdmmc_host_set_card_clk, \
|
||||
.do_transaction = &sdmmc_host_do_transaction, \
|
||||
.deinit = &sdmmc_host_deinit, \
|
||||
@ -150,6 +154,16 @@ size_t sdmmc_host_get_slot_width(int slot);
|
||||
*/
|
||||
esp_err_t sdmmc_host_set_card_clk(int slot, uint32_t freq_khz);
|
||||
|
||||
/**
|
||||
* @brief Enable or disable DDR mode of SD interface
|
||||
* @param slot slot number (SDMMC_HOST_SLOT_0 or SDMMC_HOST_SLOT_1)
|
||||
* @param ddr_enabled enable or disable DDR mode
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_NOT_SUPPORTED if DDR mode is not supported on this slot
|
||||
*/
|
||||
esp_err_t sdmmc_host_set_bus_ddr_mode(int slot, bool ddr_enabled);
|
||||
|
||||
/**
|
||||
* @brief Send command to the card and get response
|
||||
*
|
||||
|
@ -56,6 +56,13 @@ typedef struct {
|
||||
int bus_width; /*!< bus widths supported by card: BIT(0) — 1-bit bus, BIT(2) — 4-bit bus */
|
||||
} sdmmc_scr_t;
|
||||
|
||||
/**
|
||||
* Decoded values of Extended Card Specific Data
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t power_class; /*!< Power class used by the card */
|
||||
} sdmmc_ext_csd_t;
|
||||
|
||||
/**
|
||||
* SD/MMC command response buffer
|
||||
*/
|
||||
@ -103,6 +110,8 @@ typedef struct {
|
||||
#define SCF_RSP_R5B (SCF_RSP_PRESENT|SCF_RSP_CRC|SCF_RSP_IDX|SCF_RSP_BSY)
|
||||
#define SCF_RSP_R6 (SCF_RSP_PRESENT|SCF_RSP_CRC|SCF_RSP_IDX)
|
||||
#define SCF_RSP_R7 (SCF_RSP_PRESENT|SCF_RSP_CRC|SCF_RSP_IDX)
|
||||
/* special flags */
|
||||
#define SCF_WAIT_BUSY 0x2000 /*!< Wait for completion of card busy signal before returning */
|
||||
/** @endcond */
|
||||
esp_err_t error; /*!< error returned from transfer */
|
||||
int timeout_ms; /*!< response timeout, in milliseconds */
|
||||
@ -120,15 +129,19 @@ typedef struct {
|
||||
#define SDMMC_HOST_FLAG_4BIT BIT(1) /*!< host supports 4-line SD and MMC protocol */
|
||||
#define SDMMC_HOST_FLAG_8BIT BIT(2) /*!< host supports 8-line MMC protocol */
|
||||
#define SDMMC_HOST_FLAG_SPI BIT(3) /*!< host supports SPI protocol */
|
||||
#define SDMMC_HOST_FLAG_DDR BIT(4) /*!< host supports DDR mode for SD/MMC */
|
||||
int slot; /*!< slot number, to be passed to host functions */
|
||||
int max_freq_khz; /*!< max frequency supported by the host */
|
||||
#define SDMMC_FREQ_DEFAULT 20000 /*!< SD/MMC Default speed (limited by clock divider) */
|
||||
#define SDMMC_FREQ_HIGHSPEED 40000 /*!< SD High speed (limited by clock divider) */
|
||||
#define SDMMC_FREQ_PROBING 400 /*!< SD/MMC probing speed */
|
||||
#define SDMMC_FREQ_52M 52000 /*!< MMC 52MHz speed */
|
||||
#define SDMMC_FREQ_26M 26000 /*!< MMC 26MHz speed */
|
||||
float io_voltage; /*!< I/O voltage used by the controller (voltage switching is not supported) */
|
||||
esp_err_t (*init)(void); /*!< Host function to initialize the driver */
|
||||
esp_err_t (*set_bus_width)(int slot, size_t width); /*!< host function to set bus width */
|
||||
size_t (*get_bus_width)(int slot); /*!< host function to get bus width */
|
||||
esp_err_t (*set_bus_ddr_mode)(int slot, bool ddr_enable); /*!< host function to set DDR mode */
|
||||
esp_err_t (*set_card_clk)(int slot, uint32_t freq_khz); /*!< host function to set card clock frequency */
|
||||
esp_err_t (*do_transaction)(int slot, sdmmc_command_t* cmdinfo); /*!< host function to do a transaction */
|
||||
esp_err_t (*deinit)(void); /*!< host function to deinitialize the driver */
|
||||
@ -146,11 +159,16 @@ typedef struct {
|
||||
sdmmc_cid_t cid; /*!< decoded CID (Card IDentification) register value */
|
||||
sdmmc_csd_t csd; /*!< decoded CSD (Card-Specific Data) register value */
|
||||
sdmmc_scr_t scr; /*!< decoded SCR (SD card Configuration Register) value */
|
||||
sdmmc_ext_csd_t ext_csd; /*!< decoded EXT_CSD (Extended Card Specific Data) register value */
|
||||
uint16_t rca; /*!< RCA (Relative Card Address) */
|
||||
uint16_t max_freq_khz; /*!< Maximum frequency, in kHz, supported by the card */
|
||||
uint32_t is_mem : 1; /*!< Bit indicates if the card is a memory card */
|
||||
uint32_t is_sdio : 1; /*!< Bit indicates if the card is an IO card */
|
||||
uint32_t is_mmc : 1; /*!< Bit indicates if the card is MMC */
|
||||
uint32_t num_io_functions : 3; /*!< If is_sdio is 1, contains the number of IO functions on the card */
|
||||
uint32_t reserved : 27; /*!< Reserved for future expansion */
|
||||
uint32_t log_bus_width : 2; /*!< log2(bus width supported by card) */
|
||||
uint32_t is_ddr : 1; /*!< Card supports DDR mode */
|
||||
uint32_t reserved : 23; /*!< Reserved for future expansion */
|
||||
} sdmmc_card_t;
|
||||
|
||||
|
||||
|
@ -41,6 +41,7 @@ extern "C" {
|
||||
.init = &sdspi_host_init, \
|
||||
.set_bus_width = NULL, \
|
||||
.get_bus_width = NULL, \
|
||||
.set_bus_ddr_mode = NULL, \
|
||||
.set_card_clk = &sdspi_host_set_card_clk, \
|
||||
.do_transaction = &sdspi_host_do_transaction, \
|
||||
.deinit = &sdspi_host_deinit, \
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include "esp_err.h"
|
||||
#include "rom/lldesc.h"
|
||||
#include "soc/spi_periph.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
@ -31,6 +32,34 @@ extern "C"
|
||||
//Maximum amount of bytes that can be put in one DMA descriptor
|
||||
#define SPI_MAX_DMA_LEN (4096-4)
|
||||
|
||||
/**
|
||||
* Transform unsigned integer of length <= 32 bits to the format which can be
|
||||
* sent by the SPI driver directly.
|
||||
*
|
||||
* E.g. to send 9 bits of data, you can:
|
||||
*
|
||||
* uint16_t data = SPI_SWAP_DATA_TX(0x145, 9);
|
||||
*
|
||||
* Then points tx_buffer to ``&data``.
|
||||
*
|
||||
* @param data Data to be sent, can be uint8_t, uint16_t or uint32_t. @param
|
||||
* len Length of data to be sent, since the SPI peripheral sends from the MSB,
|
||||
* this helps to shift the data to the MSB.
|
||||
*/
|
||||
#define SPI_SWAP_DATA_TX(data, len) __builtin_bswap32((uint32_t)data<<(32-len))
|
||||
|
||||
/**
|
||||
* Transform received data of length <= 32 bits to the format of an unsigned integer.
|
||||
*
|
||||
* E.g. to transform the data of 15 bits placed in a 4-byte array to integer:
|
||||
*
|
||||
* uint16_t data = SPI_SWAP_DATA_RX(*(uint32_t*)t->rx_data, 15);
|
||||
*
|
||||
* @param data Data to be rearranged, can be uint8_t, uint16_t or uint32_t.
|
||||
* @param len Length of data received, since the SPI peripheral writes from
|
||||
* the MSB, this helps to shift the data to the LSB.
|
||||
*/
|
||||
#define SPI_SWAP_DATA_RX(data, len) (__builtin_bswap32(data)>>(32-len))
|
||||
|
||||
/**
|
||||
* @brief Enum with the three SPI peripherals that are software-accessible in it
|
||||
@ -45,7 +74,7 @@ typedef enum {
|
||||
* @brief This is a configuration structure for a SPI bus.
|
||||
*
|
||||
* You can use this structure to specify the GPIO pins of the bus. Normally, the driver will use the
|
||||
* GPIO matrix to route the signals. An exception is made when all signals either can be routed through
|
||||
* GPIO matrix to route the signals. An exception is made when all signals either can be routed through
|
||||
* the IO_MUX or are -1. In that case, the IO_MUX is used, allowing for >40MHz speeds.
|
||||
*
|
||||
* @note Be advised that the slave driver does not use the quadwp/quadhd lines and fields in spi_bus_config_t refering to these lines will be ignored and can thus safely be left uninitialized.
|
||||
@ -81,20 +110,20 @@ bool spicommon_periph_free(spi_host_device_t host);
|
||||
|
||||
/**
|
||||
* @brief Try to claim a SPI DMA channel
|
||||
*
|
||||
*
|
||||
* Call this if your driver wants to use SPI with a DMA channnel.
|
||||
*
|
||||
*
|
||||
* @param dma_chan channel to claim
|
||||
*
|
||||
*
|
||||
* @return True if success; false otherwise.
|
||||
*/
|
||||
bool spicommon_dma_chan_claim(int dma_chan);
|
||||
|
||||
/**
|
||||
* @brief Return the SPI DMA channel so other driver can claim it, or just to power down DMA.
|
||||
*
|
||||
*
|
||||
* @param dma_chan channel to return
|
||||
*
|
||||
*
|
||||
* @return True if success; false otherwise.
|
||||
*/
|
||||
bool spicommon_dma_chan_free(int dma_chan);
|
||||
@ -113,7 +142,7 @@ bool spicommon_dma_chan_free(int dma_chan);
|
||||
* @brief Connect a SPI peripheral to GPIO pins
|
||||
*
|
||||
* This routine is used to connect a SPI peripheral to the IO-pads and DMA channel given in
|
||||
* the arguments. Depending on the IO-pads requested, the routing is done either using the
|
||||
* the arguments. Depending on the IO-pads requested, the routing is done either using the
|
||||
* IO_mux or using the GPIO matrix.
|
||||
*
|
||||
* @param host SPI peripheral to be routed
|
||||
@ -123,7 +152,7 @@ bool spicommon_dma_chan_free(int dma_chan);
|
||||
* - ``SPICOMMON_BUSFLAG_MASTER``: Initialize I/O in master mode
|
||||
* - ``SPICOMMON_BUSFLAG_SLAVE``: Initialize I/O in slave mode
|
||||
* - ``SPICOMMON_BUSFLAG_NATIVE_PINS``: Pins set should match the iomux pins of the controller.
|
||||
* - ``SPICOMMON_BUSFLAG_SCLK``, ``SPICOMMON_BUSFLAG_MISO``, ``SPICOMMON_BUSFLAG_MOSI``:
|
||||
* - ``SPICOMMON_BUSFLAG_SCLK``, ``SPICOMMON_BUSFLAG_MISO``, ``SPICOMMON_BUSFLAG_MOSI``:
|
||||
* Make sure SCLK/MISO/MOSI is/are set to a valid GPIO. Also check output capability according to the mode.
|
||||
* - ``SPICOMMON_BUSFLAG_DUAL``: Make sure both MISO and MOSI are output capable so that DIO mode is capable.
|
||||
* - ``SPICOMMON_BUSFLAG_WPHD`` Make sure WP and HD are set to valid output GPIOs.
|
||||
@ -136,7 +165,7 @@ bool spicommon_dma_chan_free(int dma_chan);
|
||||
* - ``SPICOMMON_BUSFLAG_DUAL``: The bus is capable with DIO mode.
|
||||
* - ``SPICOMMON_BUSFLAG_WPHD`` The bus has WP and HD connected.
|
||||
* - ``SPICOMMON_BUSFLAG_QUAD``: Combination of ``SPICOMMON_BUSFLAG_DUAL`` and ``SPICOMMON_BUSFLAG_WPHD``.
|
||||
* @return
|
||||
* @return
|
||||
* - ESP_ERR_INVALID_ARG if parameter is invalid
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
@ -145,10 +174,10 @@ esp_err_t spicommon_bus_initialize_io(spi_host_device_t host, const spi_bus_conf
|
||||
/**
|
||||
* @brief Free the IO used by a SPI peripheral
|
||||
* @deprecated Use spicommon_bus_free_io_cfg instead.
|
||||
*
|
||||
*
|
||||
* @param host SPI peripheral to be freed
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @return
|
||||
* - ESP_ERR_INVALID_ARG if parameter is invalid
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
@ -158,8 +187,8 @@ esp_err_t spicommon_bus_free_io(spi_host_device_t host) __attribute__((deprecate
|
||||
* @brief Free the IO used by a SPI peripheral
|
||||
*
|
||||
* @param bus_cfg Bus config struct which defines which pins to be used.
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @return
|
||||
* - ESP_ERR_INVALID_ARG if parameter is invalid
|
||||
* - ESP_OK on success
|
||||
*/
|
||||
@ -240,10 +269,10 @@ typedef void(*dmaworkaround_cb_t)(void *arg);
|
||||
* @note In some (well-defined) cases in the ESP32 (at least rev v.0 and v.1), a SPI DMA channel will get confused. This can be remedied
|
||||
* by resetting the SPI DMA hardware in case this happens. Unfortunately, the reset knob used for thsi will reset _both_ DMA channels, and
|
||||
* as such can only done safely when both DMA channels are idle. These functions coordinate this.
|
||||
*
|
||||
*
|
||||
* Essentially, when a reset is needed, a driver can request this using spicommon_dmaworkaround_req_reset. This is supposed to be called
|
||||
* with an user-supplied function as an argument. If both DMA channels are idle, this call will reset the DMA subsystem and return true.
|
||||
* If the other DMA channel is still busy, it will return false; as soon as the other DMA channel is done, however, it will reset the
|
||||
* with an user-supplied function as an argument. If both DMA channels are idle, this call will reset the DMA subsystem and return true.
|
||||
* If the other DMA channel is still busy, it will return false; as soon as the other DMA channel is done, however, it will reset the
|
||||
* DMA subsystem and call the callback. The callback is then supposed to be used to continue the SPI drivers activity.
|
||||
*
|
||||
* @param dmachan DMA channel associated with the SPI host that needs a reset
|
||||
|
@ -122,6 +122,7 @@ esp_err_t touch_pad_init();
|
||||
|
||||
/**
|
||||
* @brief Un-install touch pad driver.
|
||||
* @note After this function is called, other touch functions are prohibited from being called.
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_FAIL Touch pad driver not initialized
|
||||
@ -550,6 +551,15 @@ esp_err_t touch_pad_filter_stop();
|
||||
*/
|
||||
esp_err_t touch_pad_filter_delete();
|
||||
|
||||
/**
|
||||
* @brief Get the touch pad which caused wakeup from sleep
|
||||
* @param pad_num pointer to touch pad which caused wakeup
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_FAIL get status err
|
||||
*/
|
||||
esp_err_t touch_pad_get_wakeup_status(touch_pad_t *pad_num);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -46,6 +46,17 @@ extern "C" {
|
||||
#define UART_INVERSE_TXD (UART_TXD_INV_M) /*!< UART TXD output inverse*/
|
||||
#define UART_INVERSE_RTS (UART_RTS_INV_M) /*!< UART RTS output inverse*/
|
||||
|
||||
/**
|
||||
* @brief UART mode selection
|
||||
*/
|
||||
typedef enum {
|
||||
UART_MODE_UART = 0x00, /*!< mode: regular UART mode*/
|
||||
UART_MODE_RS485_HALF_DUPLEX = 0x01, /*!< mode: half duplex RS485 UART mode control by RTS pin */
|
||||
UART_MODE_IRDA = 0x02, /*!< mode: IRDA UART mode*/
|
||||
UART_MODE_RS485_COLLISION_DETECT = 0x03, /*!< mode: RS485 collision detection UART mode (used for test purposes)*/
|
||||
UART_MODE_RS485_APP_CTRL = 0x04, /*!< mode: application control RS485 UART mode (used for test purposes)*/
|
||||
} uart_mode_t;
|
||||
|
||||
/**
|
||||
* @brief UART word length constants
|
||||
*/
|
||||
@ -54,7 +65,7 @@ typedef enum {
|
||||
UART_DATA_6_BITS = 0x1, /*!< word length: 6bits*/
|
||||
UART_DATA_7_BITS = 0x2, /*!< word length: 7bits*/
|
||||
UART_DATA_8_BITS = 0x3, /*!< word length: 8bits*/
|
||||
UART_DATA_BITS_MAX = 0X4,
|
||||
UART_DATA_BITS_MAX = 0x4,
|
||||
} uart_word_length_t;
|
||||
|
||||
/**
|
||||
@ -249,8 +260,8 @@ esp_err_t uart_get_baudrate(uart_port_t uart_num, uint32_t* baudrate);
|
||||
* @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2
|
||||
* @param inverse_mask Choose the wires that need to be inverted.
|
||||
* Inverse_mask should be chosen from
|
||||
UART_INVERSE_RXD / UART_INVERSE_TXD / UART_INVERSE_RTS / UART_INVERSE_CTS,
|
||||
combined with OR operation.
|
||||
* UART_INVERSE_RXD / UART_INVERSE_TXD / UART_INVERSE_RTS / UART_INVERSE_CTS,
|
||||
* combined with OR operation.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
@ -474,7 +485,7 @@ esp_err_t uart_set_dtr(uart_port_t uart_num, int level);
|
||||
esp_err_t uart_set_tx_idle_num(uart_port_t uart_num, uint16_t idle_num);
|
||||
|
||||
/**
|
||||
* @brief Set UART configuration parameters.
|
||||
* @brief Set UART configuration parameters.
|
||||
*
|
||||
* @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2
|
||||
* @param uart_config UART parameter settings
|
||||
@ -486,7 +497,7 @@ esp_err_t uart_set_tx_idle_num(uart_port_t uart_num, uint16_t idle_num);
|
||||
esp_err_t uart_param_config(uart_port_t uart_num, const uart_config_t *uart_config);
|
||||
|
||||
/**
|
||||
* @brief Configure UART interrupts.
|
||||
* @brief Configure UART interrupts.
|
||||
*
|
||||
* @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2
|
||||
* @param intr_conf UART interrupt settings
|
||||
@ -552,8 +563,8 @@ esp_err_t uart_wait_tx_done(uart_port_t uart_num, TickType_t ticks_to_wait);
|
||||
* @note This function should only be used when UART TX buffer is not enabled.
|
||||
*
|
||||
* @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2
|
||||
* @param buffer data buffer address
|
||||
* @param len data length to send
|
||||
* @param buffer data buffer address
|
||||
* @param len data length to send
|
||||
*
|
||||
* @return
|
||||
* - (-1) Parameter error
|
||||
@ -571,8 +582,8 @@ int uart_tx_chars(uart_port_t uart_num, const char* buffer, uint32_t len);
|
||||
* UART ISR will then move data from the ring buffer to TX FIFO gradually.
|
||||
*
|
||||
* @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2
|
||||
* @param src data buffer address
|
||||
* @param size data length to send
|
||||
* @param src data buffer address
|
||||
* @param size data length to send
|
||||
*
|
||||
* @return
|
||||
* - (-1) Parameter error
|
||||
@ -581,7 +592,7 @@ int uart_tx_chars(uart_port_t uart_num, const char* buffer, uint32_t len);
|
||||
int uart_write_bytes(uart_port_t uart_num, const char* src, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Send data to the UART port from a given buffer and length.
|
||||
* @brief Send data to the UART port from a given buffer and length,
|
||||
*
|
||||
* If the UART driver's parameter 'tx_buffer_size' is set to zero:
|
||||
* This function will not return until all the data and the break signal have been sent out.
|
||||
@ -641,9 +652,10 @@ esp_err_t uart_flush(uart_port_t uart_num);
|
||||
esp_err_t uart_flush_input(uart_port_t uart_num);
|
||||
|
||||
/**
|
||||
* @brief UART get RX ring buffer cached data length
|
||||
* @param uart_num UART port number.
|
||||
* @param size Pointer of size_t to accept cached data length
|
||||
* @brief UART get RX ring buffer cached data length
|
||||
*
|
||||
* @param uart_num UART port number.
|
||||
* @param size Pointer of size_t to accept cached data length
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
@ -652,9 +664,9 @@ esp_err_t uart_flush_input(uart_port_t uart_num);
|
||||
esp_err_t uart_get_buffered_data_len(uart_port_t uart_num, size_t* size);
|
||||
|
||||
/**
|
||||
* @brief UART disable pattern detect function.
|
||||
* Designed for applications like 'AT commands'.
|
||||
* When the hardware detects a series of one same character, the interrupt will be triggered.
|
||||
* @brief UART disable pattern detect function.
|
||||
* Designed for applications like 'AT commands'.
|
||||
* When the hardware detects a series of one same character, the interrupt will be triggered.
|
||||
*
|
||||
* @param uart_num UART port number.
|
||||
*
|
||||
@ -737,6 +749,96 @@ int uart_pattern_get_pos(uart_port_t uart_num);
|
||||
*/
|
||||
esp_err_t uart_pattern_queue_reset(uart_port_t uart_num, int queue_length);
|
||||
|
||||
/**
|
||||
* @brief UART set communication mode
|
||||
* @note This function must be executed after uart_driver_install(), when the driver object is initialized.
|
||||
* @param uart_num Uart number to configure
|
||||
* @param mode UART UART mode to set
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t uart_set_mode(uart_port_t uart_num, uart_mode_t mode);
|
||||
|
||||
/**
|
||||
* @brief UART set threshold timeout for TOUT feature
|
||||
*
|
||||
* @param uart_num Uart number to configure
|
||||
* @param tout_thresh This parameter defines timeout threshold in uart symbol periods. The maximum value of threshold is 126.
|
||||
* tout_thresh = 1, defines TOUT interrupt timeout equal to transmission time of one symbol (~11 bit) on current baudrate.
|
||||
* If the time is expired the UART_RXFIFO_TOUT_INT interrupt is triggered. If tout_thresh == 0,
|
||||
* the TOUT feature is disabled.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
* - ESP_ERR_INVALID_STATE Driver is not installed
|
||||
*/
|
||||
esp_err_t uart_set_rx_timeout(uart_port_t uart_num, const uint8_t tout_thresh);
|
||||
|
||||
/**
|
||||
* @brief Returns collision detection flag for RS485 mode
|
||||
* Function returns the collision detection flag into variable pointed by collision_flag.
|
||||
* *collision_flag = true, if collision detected else it is equal to false.
|
||||
* This function should be executed when actual transmission is completed (after uart_write_bytes()).
|
||||
*
|
||||
* @param uart_num Uart number to configure
|
||||
* @param collision_flag Pointer to variable of type bool to return collision flag.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t uart_get_collision_flag(uart_port_t uart_num, bool* collision_flag);
|
||||
|
||||
/**
|
||||
* @brief Set the number of RX pin signal edges for light sleep wakeup
|
||||
*
|
||||
* UART can be used to wake up the system from light sleep. This feature works
|
||||
* by counting the number of positive edges on RX pin and comparing the count to
|
||||
* the threshold. When the count exceeds the threshold, system is woken up from
|
||||
* light sleep. This function allows setting the threshold value.
|
||||
*
|
||||
* Stop bit and parity bits (if enabled) also contribute to the number of edges.
|
||||
* For example, letter 'a' with ASCII code 97 is encoded as 010001101 on the wire
|
||||
* (with 8n1 configuration), start and stop bits included. This sequence has 3
|
||||
* positive edges (transitions from 0 to 1). Therefore, to wake up the system
|
||||
* when 'a' is sent, set wakeup_threshold=3.
|
||||
*
|
||||
* The character that triggers wakeup is not received by UART (i.e. it can not
|
||||
* be obtained from UART FIFO). Depending on the baud rate, a few characters
|
||||
* after that will also not be received. Note that when the chip enters and exits
|
||||
* light sleep mode, APB frequency will be changing. To make sure that UART has
|
||||
* correct baud rate all the time, select REF_TICK as UART clock source,
|
||||
* by setting use_ref_tick field in uart_config_t to true.
|
||||
*
|
||||
* @note in ESP32, UART2 does not support light sleep wakeup feature.
|
||||
*
|
||||
* @param uart_num UART number
|
||||
* @param wakeup_threshold number of RX edges for light sleep wakeup, value is 3 .. 0x3ff.
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG if uart_num is incorrect or wakeup_threshold is
|
||||
* outside of [3, 0x3ff] range.
|
||||
*/
|
||||
esp_err_t uart_set_wakeup_threshold(uart_port_t uart_num, int wakeup_threshold);
|
||||
|
||||
/**
|
||||
* @brief Get the number of RX pin signal edges for light sleep wakeup.
|
||||
*
|
||||
* See description of uart_set_wakeup_threshold for the explanation of UART
|
||||
* wakeup feature.
|
||||
*
|
||||
* @param uart_num UART number
|
||||
* @param[out] out_wakeup_threshold output, set to the current value of wakeup
|
||||
* threshold for the given UART.
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - ESP_ERR_INVALID_ARG if out_wakeup_threshold is NULL
|
||||
*/
|
||||
esp_err_t uart_get_wakeup_threshold(uart_port_t uart_num, int* out_wakeup_threshold);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user