Merge branch 'feature/hspi_test' into 'master'

feat(spi): fix some bugs and restructure the spi driver and the demo

See merge request sdk/ESP8266_RTOS_SDK!1113
This commit is contained in:
Dong Heng
2019-11-13 10:00:35 +08:00
44 changed files with 1879 additions and 660 deletions

View File

@ -0,0 +1,88 @@
// Copyright 2018-2025 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 "esp_err.h"
#include "driver/gpio.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Receive SPI data
*
* @param data Data buffer to receive
* @param len Data length
* @param xTicksToWait Ticks to wait until receive data; use portMAX_DELAY to
* never time out.
* @return
* - Actual length received
*/
uint32_t hspi_slave_logic_read_data(uint8_t*data, uint32_t len, TickType_t xTicksToWait);
/**
* @brief Send SPI data
*
* @param data Data buffer to send
* @param len Data length
* @param xTicksToWait Ticks to wait until send data; use portMAX_DELAY to
* never time out.
* @return
* - Actual length received
*/
uint32_t hspi_slave_logic_write_data(uint8_t*data, uint32_t len, TickType_t xTicksToWait);
/**
* @brief Create a SPI device to transmit SPI data
*
* @param trigger_pin The pin used for handshake
* @param trigger_level The number of bytes that must be in the stream
* buffer before a task that is blocked on the stream buffer to wait for data is
* moved out of the blocked state. For example, if a task is blocked on a read
* of an empty stream buffer that has a trigger level of 1 then the task will be
* unblocked when a single byte is written to the buffer or the task's block
* time expires. As another example, if a task is blocked on a read of an empty
* stream buffer that has a trigger level of 10 then the task will not be
* unblocked until the stream buffer contains at least 10 bytes or the task's
* block time expires. If a reading task's block time expires before the
* trigger level is reached then the task will still receive however many bytes
* are actually available. Setting a trigger level of 0 will result in a
* trigger level of 1 being used. It is not valid to specify a trigger level
* that is greater than the buffer size.
* @param tx_buffer_size The total number of bytes the send stream buffer will be
* able to hold at any one time.
* @param rx_buffer_size The total number of bytes the receive stream buffer will be
* able to hold at any one time.
*
* @return
* - ESP_OK Success
* - ESP_ERR_NO_MEM No memory
*/
esp_err_t hspi_slave_logic_device_create(gpio_num_t trigger_pin, uint32_t trigger_level,uint32_t tx_buffer_size, uint32_t rx_buffer_size);
/**
* @brief Delete the SPI slave bus
*
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_STATE SPI slave already deleted
*/
esp_err_t hspi_slave_logic_device_delete(void);
#ifdef __cplusplus
}
#endif

View File

@ -36,7 +36,7 @@ extern "C" {
#define SPI_BYTE_ORDER_LSB_FIRST 0
/* SPI default bus interface parameter definition */
#define SPI_DEFAULT_INTERFACE 0x1F0 /* CS_EN:1, MISO_EN:1, MOSI_EN:1, BYTE_TX_ORDER:1, BYTE_TX_ORDER:1, BIT_RX_ORDER:0, BIT_TX_ORDER:0, CPHA:0, CPOL:0 */
#define SPI_DEFAULT_INTERFACE 0x1C0 /* CS_EN:1, MISO_EN:1, MOSI_EN:1, BYTE_TX_ORDER:0, BYTE_TX_ORDER:0, BIT_RX_ORDER:0, BIT_TX_ORDER:0, CPHA:0, CPOL:0 */
/* SPI master default interrupt enable definition */
#define SPI_MASTER_DEFAULT_INTR_ENABLE 0x10 /* TRANS_DONE: true, WRITE_STATUS: false, READ_STATUS: false, WRITE_BUFFER: false, READ_BUFFER: false */
@ -140,8 +140,8 @@ typedef union {
typedef struct {
uint16_t *cmd; /*!< SPI transmission command */
uint32_t *addr; /*!< SPI transmission address */
uint32_t *mosi; /*!< SPI transmission MOSI buffer */
uint32_t *miso; /*!< SPI transmission MISO buffer */
uint32_t *mosi; /*!< SPI transmission MOSI buffer, in order to improve the transmission efficiency, it is recommended that the external incoming data is (uint32_t *) type data, do not use other type data. */
uint32_t *miso; /*!< SPI transmission MISO buffer, in order to improve the transmission efficiency, it is recommended that the external incoming data is (uint32_t *) type data, do not use other type data. */
union {
struct {
uint32_t cmd: 5; /*!< SPI transmission command bits */
@ -403,14 +403,14 @@ esp_err_t spi_slave_set_status(spi_host_t host, uint32_t *status);
* - CSPI_HOST SPI0
* - HSPI_HOST SPI1
*
* @param trans Transmission parameter structure
* @param trans Pointer to transmission parameter structure
*
* @return
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
* - ESP_FAIL spi has not been initialized yet
*/
esp_err_t spi_trans(spi_host_t host, spi_trans_t trans);
esp_err_t spi_trans(spi_host_t host, spi_trans_t *trans);
/**
* @brief Deinit the spi