2015-07-02 19:17:16 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Intel Corporation
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-07-02 19:17:16 +08:00
|
|
|
*/
|
|
|
|
|
2016-02-08 04:29:17 +08:00
|
|
|
/**
|
|
|
|
* @file
|
2017-04-21 19:24:07 +08:00
|
|
|
* @brief Public API for SPI drivers and applications
|
2016-02-08 04:29:17 +08:00
|
|
|
*/
|
|
|
|
|
2015-07-02 19:17:16 +08:00
|
|
|
#ifndef __SPI_H__
|
|
|
|
#define __SPI_H__
|
|
|
|
|
2015-10-26 18:18:44 +08:00
|
|
|
/**
|
|
|
|
* @brief SPI Interface
|
|
|
|
* @defgroup spi_interface SPI Interface
|
|
|
|
* @ingroup io_interfaces
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 23:32:08 +08:00
|
|
|
#include <zephyr/types.h>
|
2015-07-13 21:36:31 +08:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <device.h>
|
|
|
|
|
2015-07-02 19:17:16 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-07-18 23:27:11 +08:00
|
|
|
/**
|
2017-04-21 19:24:07 +08:00
|
|
|
* @brief SPI operational mode
|
|
|
|
*/
|
|
|
|
#define SPI_OP_MODE_MASTER 0
|
2017-07-18 23:27:29 +08:00
|
|
|
#define SPI_OP_MODE_SLAVE BIT(0)
|
|
|
|
#define SPI_OP_MODE_MASK 0x1
|
|
|
|
#define SPI_OP_MODE_GET(_operation_) ((_operation_) & SPI_OP_MODE_MASK)
|
2017-04-21 19:24:07 +08:00
|
|
|
|
2016-02-08 04:29:17 +08:00
|
|
|
/**
|
|
|
|
* @brief SPI Polarity & Phase Modes
|
|
|
|
*/
|
2015-07-02 19:17:16 +08:00
|
|
|
|
2017-04-21 19:24:07 +08:00
|
|
|
/**
|
|
|
|
* Clock Polarity: if set, clock idle state will be 1
|
|
|
|
* and active state will be 0. If untouched, the inverse will be true
|
|
|
|
* which is the default.
|
|
|
|
*/
|
|
|
|
#define SPI_MODE_CPOL BIT(1)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clock Phase: this dictates when is the data captured, and depends
|
|
|
|
* clock's polarity. When SPI_MODE_CPOL is set and this bit as well,
|
2017-08-10 23:21:28 +08:00
|
|
|
* capture will occur on low to high transition and high to low if
|
2017-04-21 19:24:07 +08:00
|
|
|
* this bit is not set (default). This is fully reversed if CPOL is
|
|
|
|
* not set.
|
|
|
|
*/
|
|
|
|
#define SPI_MODE_CPHA BIT(2)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whatever data is transmitted is looped-back to the receiving buffer of
|
|
|
|
* the controller. This is fully controller dependent as some may not
|
|
|
|
* support this, and can be used for testing purposes only.
|
|
|
|
*/
|
|
|
|
#define SPI_MODE_LOOP BIT(3)
|
|
|
|
|
|
|
|
#define SPI_MODE_MASK (0xE)
|
|
|
|
#define SPI_MODE_GET(_mode_) \
|
|
|
|
((_mode_) & SPI_MODE_MASK)
|
2015-07-02 19:17:16 +08:00
|
|
|
|
2016-02-08 04:29:17 +08:00
|
|
|
/**
|
|
|
|
* @brief SPI Transfer modes (host controller dependent)
|
|
|
|
*/
|
2017-04-21 19:24:07 +08:00
|
|
|
#define SPI_TRANSFER_MSB (0)
|
|
|
|
#define SPI_TRANSFER_LSB BIT(4)
|
2015-07-02 19:17:16 +08:00
|
|
|
|
2017-04-21 19:24:07 +08:00
|
|
|
/**
|
|
|
|
* @brief SPI word size
|
|
|
|
*/
|
|
|
|
#define SPI_WORD_SIZE_SHIFT (5)
|
|
|
|
#define SPI_WORD_SIZE_MASK (0x3F << SPI_WORD_SIZE_SHIFT)
|
|
|
|
#define SPI_WORD_SIZE_GET(_operation_) \
|
|
|
|
(((_operation_) & SPI_WORD_SIZE_MASK) >> SPI_WORD_SIZE_SHIFT)
|
2015-07-02 19:17:16 +08:00
|
|
|
|
2017-04-21 19:24:07 +08:00
|
|
|
#define SPI_WORD_SET(_word_size_) \
|
|
|
|
((_word_size_) << SPI_WORD_SIZE_SHIFT)
|
2015-07-02 19:17:16 +08:00
|
|
|
|
2016-02-08 04:29:17 +08:00
|
|
|
/**
|
2017-04-21 19:24:07 +08:00
|
|
|
* @brief SPI MISO lines
|
2015-07-02 19:17:16 +08:00
|
|
|
*
|
2018-02-05 21:23:51 +08:00
|
|
|
* Some controllers support dual, quad or octal MISO lines connected to slaves.
|
2017-04-21 19:24:07 +08:00
|
|
|
* Default is single, which is the case most of the time.
|
2015-07-02 19:17:16 +08:00
|
|
|
*/
|
2018-02-05 21:23:51 +08:00
|
|
|
#define SPI_LINES_SINGLE (0 << 11)
|
|
|
|
#define SPI_LINES_DUAL (1 << 11)
|
|
|
|
#define SPI_LINES_QUAD (2 << 11)
|
|
|
|
#define SPI_LINES_OCTAL (3 << 11)
|
2015-07-02 19:17:16 +08:00
|
|
|
|
2017-04-21 19:24:07 +08:00
|
|
|
#define SPI_LINES_MASK (0x3 << 11)
|
2017-04-24 22:29:37 +08:00
|
|
|
|
2017-05-10 14:40:00 +08:00
|
|
|
/**
|
|
|
|
* @brief Specific SPI devices control bits
|
|
|
|
*/
|
|
|
|
/* Requests - if possible - to keep CS asserted after the transaction */
|
|
|
|
#define SPI_HOLD_ON_CS BIT(13)
|
|
|
|
/* Keep the device locked after the transaction for the current config.
|
|
|
|
* Use this with extreme caution (see spi_release() below) as it will
|
|
|
|
* prevent other callers to access the SPI device until spi_release() is
|
|
|
|
* properly called.
|
|
|
|
*/
|
|
|
|
#define SPI_LOCK_ON BIT(14)
|
|
|
|
|
2018-02-06 20:23:54 +08:00
|
|
|
/* Active high logic on CS - Usually, and by default, CS logic is active
|
|
|
|
* low. However, some devices may require the reverse logic: active high.
|
|
|
|
* This bit will request the controller to use that logic. Note that not
|
|
|
|
* all controllers are able to handle that natively. In this case deferring
|
|
|
|
* the CS control to a gpio line through struct spi_cs_control would be
|
|
|
|
* the solution.
|
|
|
|
*/
|
|
|
|
#define SPI_CS_ACTIVE_HIGH BIT(15)
|
|
|
|
|
2017-04-21 19:24:07 +08:00
|
|
|
/**
|
|
|
|
* @brief SPI Chip Select control structure
|
|
|
|
*
|
|
|
|
* This can be used to control a CS line via a GPIO line, instead of
|
|
|
|
* using the controller inner CS logic.
|
|
|
|
*
|
2017-10-03 16:50:39 +08:00
|
|
|
* @param gpio_dev is a valid pointer to an actual GPIO device. A NULL pointer
|
|
|
|
* can be provided to full inhibit CS control if necessary.
|
2017-09-09 06:32:16 +08:00
|
|
|
* @param gpio_pin is a number representing the gpio PIN that will be used
|
2017-04-21 19:24:07 +08:00
|
|
|
* to act as a CS line
|
2017-09-09 06:32:16 +08:00
|
|
|
* @param delay is a delay in microseconds to wait before starting the
|
2017-04-21 19:24:07 +08:00
|
|
|
* transmission and before releasing the CS line
|
|
|
|
*/
|
|
|
|
struct spi_cs_control {
|
|
|
|
struct device *gpio_dev;
|
|
|
|
u32_t gpio_pin;
|
|
|
|
u32_t delay;
|
2017-04-24 22:29:37 +08:00
|
|
|
};
|
|
|
|
|
2016-06-16 05:18:38 +08:00
|
|
|
/**
|
2017-04-21 19:24:07 +08:00
|
|
|
* @brief SPI controller configuration structure
|
|
|
|
*
|
2017-09-09 06:32:16 +08:00
|
|
|
* @param dev is a valid pointer to an actual SPI device
|
|
|
|
* @param frequency is the bus frequency in Hertz
|
|
|
|
* @param operation is a bit field with the following parts:
|
2017-04-21 19:24:07 +08:00
|
|
|
*
|
2017-09-09 06:32:16 +08:00
|
|
|
* operational mode [ 0 ] - master or slave.
|
|
|
|
* mode [ 1 : 3 ] - Polarity, phase and loop mode.
|
|
|
|
* transfer [ 4 ] - LSB or MSB first.
|
|
|
|
* word_size [ 5 : 10 ] - Size of a data frame in bits.
|
2018-02-05 21:23:51 +08:00
|
|
|
* lines [ 11 : 12 ] - MISO lines: Single/Dual/Quad/Octal.
|
2017-09-09 06:32:16 +08:00
|
|
|
* cs_hold [ 13 ] - Hold on the CS line if possible.
|
|
|
|
* lock_on [ 14 ] - Keep resource locked for the caller.
|
2018-02-06 20:23:54 +08:00
|
|
|
* cs_active_high [ 15 ] - Active high CS logic.
|
2017-09-09 06:32:16 +08:00
|
|
|
* @param slave is the slave number from 0 to host controller slave limit.
|
|
|
|
* @param cs is a valid pointer on a struct spi_cs_control is CS line is
|
2017-04-21 19:24:07 +08:00
|
|
|
* emulated through a gpio line, or NULL otherwise.
|
2017-05-10 14:40:00 +08:00
|
|
|
*
|
2018-02-15 16:50:40 +08:00
|
|
|
* @note Only cs_hold and lock_on can be changed between consecutive
|
|
|
|
* transceive call. Rest of the attributes are not meant to be tweaked.
|
2016-06-16 05:18:38 +08:00
|
|
|
*/
|
2017-04-21 19:24:07 +08:00
|
|
|
struct spi_config {
|
|
|
|
u32_t frequency;
|
|
|
|
u16_t operation;
|
|
|
|
u16_t slave;
|
2017-05-05 17:58:38 +08:00
|
|
|
|
2018-02-05 21:25:09 +08:00
|
|
|
const struct spi_cs_control *cs;
|
2017-04-21 19:24:07 +08:00
|
|
|
};
|
|
|
|
|
2016-06-16 05:18:38 +08:00
|
|
|
/**
|
2017-04-21 19:24:07 +08:00
|
|
|
* @brief SPI buffer structure
|
|
|
|
*
|
2017-09-09 06:32:16 +08:00
|
|
|
* @param buf is a valid pointer on a data buffer, or NULL otherwise.
|
|
|
|
* @param len is the length of the buffer or, if buf is NULL, will be the
|
|
|
|
* length which as to be sent as dummy bytes (as TX buffer) or
|
|
|
|
* the length of bytes that should be skipped (as RX buffer).
|
2016-06-16 05:18:38 +08:00
|
|
|
*/
|
2017-04-21 19:24:07 +08:00
|
|
|
struct spi_buf {
|
|
|
|
void *buf;
|
|
|
|
size_t len;
|
|
|
|
};
|
|
|
|
|
2018-01-30 20:49:01 +08:00
|
|
|
/**
|
|
|
|
* @brief SPI buffer array structure
|
|
|
|
*
|
|
|
|
* @param buffers is a valid pointer on an array of spi_buf, or NULL.
|
|
|
|
* @param count is the length of the array pointed by buffers.
|
|
|
|
*/
|
|
|
|
struct spi_buf_set {
|
|
|
|
const struct spi_buf *buffers;
|
|
|
|
size_t count;
|
|
|
|
};
|
|
|
|
|
2016-06-16 05:18:38 +08:00
|
|
|
/**
|
|
|
|
* @typedef spi_api_io
|
|
|
|
* @brief Callback API for I/O
|
2017-04-21 19:24:07 +08:00
|
|
|
* See spi_transceive() for argument descriptions
|
2016-06-16 05:18:38 +08:00
|
|
|
*/
|
2018-01-30 20:49:01 +08:00
|
|
|
typedef int (*spi_api_io)(struct device *dev,
|
|
|
|
const struct spi_config *config,
|
|
|
|
const struct spi_buf_set *tx_bufs,
|
|
|
|
const struct spi_buf_set *rx_bufs);
|
2015-07-02 19:17:16 +08:00
|
|
|
|
2017-05-05 17:58:38 +08:00
|
|
|
/**
|
|
|
|
* @typedef spi_api_io
|
|
|
|
* @brief Callback API for asynchronous I/O
|
|
|
|
* See spi_transceive_async() for argument descriptions
|
|
|
|
*/
|
2018-01-30 20:49:01 +08:00
|
|
|
typedef int (*spi_api_io_async)(struct device *dev,
|
|
|
|
const struct spi_config *config,
|
|
|
|
const struct spi_buf_set *tx_bufs,
|
|
|
|
const struct spi_buf_set *rx_bufs,
|
2017-05-05 17:58:38 +08:00
|
|
|
struct k_poll_signal *async);
|
|
|
|
|
2017-05-10 14:40:00 +08:00
|
|
|
/**
|
|
|
|
* @typedef spi_api_release
|
|
|
|
* @brief Callback API for unlocking SPI device.
|
|
|
|
* See spi_release() for argument descriptions
|
|
|
|
*/
|
2018-01-30 20:49:01 +08:00
|
|
|
typedef int (*spi_api_release)(struct device *dev,
|
|
|
|
const struct spi_config *config);
|
2017-05-10 14:40:00 +08:00
|
|
|
|
|
|
|
|
2017-04-21 19:24:07 +08:00
|
|
|
/**
|
|
|
|
* @brief SPI driver API
|
|
|
|
* This is the mandatory API any SPI driver needs to expose.
|
|
|
|
*/
|
2015-07-02 19:17:16 +08:00
|
|
|
struct spi_driver_api {
|
2015-08-21 17:48:54 +08:00
|
|
|
spi_api_io transceive;
|
2018-01-30 05:12:50 +08:00
|
|
|
#ifdef CONFIG_SPI_ASYNC
|
2017-05-05 17:58:38 +08:00
|
|
|
spi_api_io_async transceive_async;
|
2018-01-30 05:12:50 +08:00
|
|
|
#endif /* CONFIG_SPI_ASYNC */
|
2017-05-10 14:40:00 +08:00
|
|
|
spi_api_release release;
|
2015-07-02 19:17:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-04-21 19:24:07 +08:00
|
|
|
* @brief Read/write the specified amount of data from the SPI driver.
|
2015-08-21 17:48:54 +08:00
|
|
|
*
|
2017-04-21 19:24:07 +08:00
|
|
|
* Note: This function is synchronous.
|
2015-08-21 17:48:54 +08:00
|
|
|
*
|
2018-01-30 20:49:01 +08:00
|
|
|
* @param dev Pointer to the device structure for the driver instance
|
2017-04-21 19:24:07 +08:00
|
|
|
* @param config Pointer to a valid spi_config structure instance.
|
2017-05-30 20:28:07 +08:00
|
|
|
* @param tx_bufs Buffer array where data to be sent originates from,
|
|
|
|
* or NULL if none.
|
|
|
|
* @param rx_bufs Buffer array where data to be read will be written to,
|
|
|
|
* or NULL if none.
|
2015-08-21 17:48:54 +08:00
|
|
|
*
|
2018-04-04 22:48:29 +08:00
|
|
|
* @retval 0 If successful, negative errno code otherwise. In case of slave
|
|
|
|
* transaction: if successful it will return the amount of frames
|
|
|
|
* received, negative errno code otherwise.
|
2015-08-21 17:48:54 +08:00
|
|
|
*/
|
2018-01-30 20:49:01 +08:00
|
|
|
__syscall int spi_transceive(struct device *dev,
|
|
|
|
const struct spi_config *config,
|
|
|
|
const struct spi_buf_set *tx_bufs,
|
|
|
|
const struct spi_buf_set *rx_bufs);
|
|
|
|
|
|
|
|
static inline int _impl_spi_transceive(struct device *dev,
|
|
|
|
const struct spi_config *config,
|
|
|
|
const struct spi_buf_set *tx_bufs,
|
|
|
|
const struct spi_buf_set *rx_bufs)
|
2015-08-21 17:48:54 +08:00
|
|
|
{
|
2018-03-17 19:44:40 +08:00
|
|
|
const struct spi_driver_api *api =
|
|
|
|
(const struct spi_driver_api *)dev->driver_api;
|
2015-08-21 17:48:54 +08:00
|
|
|
|
2018-01-30 20:49:01 +08:00
|
|
|
return api->transceive(dev, config, tx_bufs, rx_bufs);
|
2015-08-21 17:48:54 +08:00
|
|
|
}
|
|
|
|
|
2015-07-02 19:17:16 +08:00
|
|
|
/**
|
2016-02-08 04:29:17 +08:00
|
|
|
* @brief Read the specified amount of data from the SPI driver.
|
2015-08-21 17:48:54 +08:00
|
|
|
*
|
2017-04-21 19:24:07 +08:00
|
|
|
* Note: This function is synchronous.
|
|
|
|
*
|
2018-01-30 20:49:01 +08:00
|
|
|
* @param dev Pointer to the device structure for the driver instance
|
2017-04-21 19:24:07 +08:00
|
|
|
* @param config Pointer to a valid spi_config structure instance.
|
2017-05-30 20:28:07 +08:00
|
|
|
* @param rx_bufs Buffer array where data to be read will be written to.
|
2015-08-21 17:48:54 +08:00
|
|
|
*
|
2017-04-21 19:24:07 +08:00
|
|
|
* @retval 0 If successful, negative errno code otherwise.
|
2018-02-15 16:50:40 +08:00
|
|
|
*
|
|
|
|
* @note This function is an helper function calling spi_transceive.
|
2015-07-02 19:17:16 +08:00
|
|
|
*/
|
2018-01-30 20:49:01 +08:00
|
|
|
static inline int spi_read(struct device *dev,
|
|
|
|
const struct spi_config *config,
|
|
|
|
const struct spi_buf_set *rx_bufs)
|
2015-07-02 19:17:16 +08:00
|
|
|
{
|
2018-01-30 20:49:01 +08:00
|
|
|
return spi_transceive(dev, config, NULL, rx_bufs);
|
2015-08-21 17:48:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-04-21 19:24:07 +08:00
|
|
|
* @brief Write the specified amount of data from the SPI driver.
|
2015-08-21 17:48:54 +08:00
|
|
|
*
|
2017-04-21 19:24:07 +08:00
|
|
|
* Note: This function is synchronous.
|
2015-08-21 17:48:54 +08:00
|
|
|
*
|
2018-01-30 20:49:01 +08:00
|
|
|
* @param dev Pointer to the device structure for the driver instance
|
2017-04-21 19:24:07 +08:00
|
|
|
* @param config Pointer to a valid spi_config structure instance.
|
2017-05-30 20:28:07 +08:00
|
|
|
* @param tx_bufs Buffer array where data to be sent originates from.
|
2015-08-21 17:48:54 +08:00
|
|
|
*
|
2017-04-21 19:24:07 +08:00
|
|
|
* @retval 0 If successful, negative errno code otherwise.
|
2018-02-15 16:50:40 +08:00
|
|
|
*
|
|
|
|
* @note This function is an helper function calling spi_transceive.
|
2015-08-21 17:48:54 +08:00
|
|
|
*/
|
2018-01-30 20:49:01 +08:00
|
|
|
static inline int spi_write(struct device *dev,
|
|
|
|
const struct spi_config *config,
|
|
|
|
const struct spi_buf_set *tx_bufs)
|
2015-08-21 17:48:54 +08:00
|
|
|
{
|
2018-01-30 20:49:01 +08:00
|
|
|
return spi_transceive(dev, config, tx_bufs, NULL);
|
2017-05-05 17:58:38 +08:00
|
|
|
}
|
|
|
|
|
2018-01-30 05:12:50 +08:00
|
|
|
#ifdef CONFIG_SPI_ASYNC
|
2017-05-05 17:58:38 +08:00
|
|
|
/**
|
|
|
|
* @brief Read/write the specified amount of data from the SPI driver.
|
|
|
|
*
|
|
|
|
* Note: This function is asynchronous.
|
|
|
|
*
|
2018-01-30 20:49:01 +08:00
|
|
|
* @param dev Pointer to the device structure for the driver instance
|
2017-05-05 17:58:38 +08:00
|
|
|
* @param config Pointer to a valid spi_config structure instance.
|
2017-05-30 20:28:07 +08:00
|
|
|
* @param tx_bufs Buffer array where data to be sent originates from,
|
|
|
|
* or NULL if none.
|
|
|
|
* @param rx_bufs Buffer array where data to be read will be written to,
|
|
|
|
* or NULL if none.
|
2017-05-05 17:58:38 +08:00
|
|
|
* @param async A pointer to a valid and ready to be signaled
|
|
|
|
* struct k_poll_signal. (Note: if NULL this function will not
|
|
|
|
* notify the end of the transaction, and whether it went
|
|
|
|
* successfully or not).
|
|
|
|
*
|
2018-04-04 22:48:29 +08:00
|
|
|
* @retval 0 If successful, negative errno code otherwise. In case of slave
|
|
|
|
* transaction: if successful it will return the amount of frames
|
|
|
|
* received, negative errno code otherwise.
|
2017-05-05 17:58:38 +08:00
|
|
|
*/
|
2018-01-30 20:49:01 +08:00
|
|
|
static inline int spi_transceive_async(struct device *dev,
|
|
|
|
const struct spi_config *config,
|
|
|
|
const struct spi_buf_set *tx_bufs,
|
|
|
|
const struct spi_buf_set *rx_bufs,
|
2017-05-05 17:58:38 +08:00
|
|
|
struct k_poll_signal *async)
|
|
|
|
{
|
2018-03-17 19:44:40 +08:00
|
|
|
const struct spi_driver_api *api =
|
|
|
|
(const struct spi_driver_api *)dev->driver_api;
|
2017-05-05 17:58:38 +08:00
|
|
|
|
2018-01-30 20:49:01 +08:00
|
|
|
return api->transceive_async(dev, config, tx_bufs, rx_bufs, async);
|
2017-05-05 17:58:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Read the specified amount of data from the SPI driver.
|
|
|
|
*
|
|
|
|
* Note: This function is asynchronous.
|
|
|
|
*
|
2018-01-30 20:49:01 +08:00
|
|
|
* @param dev Pointer to the device structure for the driver instance
|
2017-05-05 17:58:38 +08:00
|
|
|
* @param config Pointer to a valid spi_config structure instance.
|
2017-05-30 20:28:07 +08:00
|
|
|
* @param rx_bufs Buffer array where data to be read will be written to.
|
2017-05-05 17:58:38 +08:00
|
|
|
* @param async A pointer to a valid and ready to be signaled
|
|
|
|
* struct k_poll_signal. (Note: if NULL this function will not
|
|
|
|
* notify the end of the transaction, and whether it went
|
|
|
|
* successfully or not).
|
|
|
|
*
|
|
|
|
* @retval 0 If successful, negative errno code otherwise.
|
2018-02-15 16:50:40 +08:00
|
|
|
*
|
|
|
|
* @note This function is an helper function calling spi_transceive_async.
|
2017-05-05 17:58:38 +08:00
|
|
|
*/
|
2018-01-30 20:49:01 +08:00
|
|
|
static inline int spi_read_async(struct device *dev,
|
|
|
|
const struct spi_config *config,
|
|
|
|
const struct spi_buf_set *rx_bufs,
|
2017-05-05 17:58:38 +08:00
|
|
|
struct k_poll_signal *async)
|
|
|
|
{
|
2018-01-30 20:49:01 +08:00
|
|
|
return spi_transceive_async(dev, config, NULL, rx_bufs, async);
|
2017-05-05 17:58:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Write the specified amount of data from the SPI driver.
|
|
|
|
*
|
|
|
|
* Note: This function is asynchronous.
|
|
|
|
*
|
2018-01-30 20:49:01 +08:00
|
|
|
* @param dev Pointer to the device structure for the driver instance
|
2017-05-05 17:58:38 +08:00
|
|
|
* @param config Pointer to a valid spi_config structure instance.
|
2017-05-30 20:28:07 +08:00
|
|
|
* @param tx_bufs Buffer array where data to be sent originates from.
|
2017-05-05 17:58:38 +08:00
|
|
|
* @param async A pointer to a valid and ready to be signaled
|
|
|
|
* struct k_poll_signal. (Note: if NULL this function will not
|
|
|
|
* notify the end of the transaction, and whether it went
|
|
|
|
* successfully or not).
|
|
|
|
*
|
|
|
|
* @retval 0 If successful, negative errno code otherwise.
|
2018-02-15 16:50:40 +08:00
|
|
|
*
|
|
|
|
* @note This function is an helper function calling spi_transceive_async.
|
2017-05-05 17:58:38 +08:00
|
|
|
*/
|
2018-01-30 20:49:01 +08:00
|
|
|
static inline int spi_write_async(struct device *dev,
|
|
|
|
const struct spi_config *config,
|
|
|
|
const struct spi_buf_set *tx_bufs,
|
2017-05-05 17:58:38 +08:00
|
|
|
struct k_poll_signal *async)
|
|
|
|
{
|
2018-01-30 20:49:01 +08:00
|
|
|
return spi_transceive_async(dev, config, tx_bufs, NULL, async);
|
2015-07-02 19:17:16 +08:00
|
|
|
}
|
2018-01-30 05:12:50 +08:00
|
|
|
#endif /* CONFIG_SPI_ASYNC */
|
2015-07-02 19:17:16 +08:00
|
|
|
|
2017-05-10 14:40:00 +08:00
|
|
|
/**
|
|
|
|
* @brief Release the SPI device locked on by the current config
|
|
|
|
*
|
|
|
|
* Note: This synchronous function is used to release the lock on the SPI
|
|
|
|
* device that was kept if, and if only, given config parameter was
|
|
|
|
* the last one to be used (in any of the above functions) and if
|
|
|
|
* it has the SPI_LOCK_ON bit set into its operation bits field.
|
|
|
|
* This can be used if the caller needs to keep its hand on the SPI
|
|
|
|
* device for consecutive transactions.
|
|
|
|
*
|
2018-01-30 20:49:01 +08:00
|
|
|
* @param dev Pointer to the device structure for the driver instance
|
2017-05-10 14:40:00 +08:00
|
|
|
* @param config Pointer to a valid spi_config structure instance.
|
|
|
|
*/
|
2018-01-30 20:49:01 +08:00
|
|
|
__syscall int spi_release(struct device *dev,
|
|
|
|
const struct spi_config *config);
|
2017-10-27 05:21:35 +08:00
|
|
|
|
2018-01-30 20:49:01 +08:00
|
|
|
static inline int _impl_spi_release(struct device *dev,
|
|
|
|
const struct spi_config *config)
|
2017-05-10 14:40:00 +08:00
|
|
|
{
|
2018-03-17 19:44:40 +08:00
|
|
|
const struct spi_driver_api *api =
|
|
|
|
(const struct spi_driver_api *)dev->driver_api;
|
2017-05-10 14:40:00 +08:00
|
|
|
|
2018-01-30 20:49:01 +08:00
|
|
|
return api->release(dev, config);
|
2017-05-10 14:40:00 +08:00
|
|
|
}
|
|
|
|
|
2015-07-02 19:17:16 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-10-26 18:18:44 +08:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2017-10-27 05:21:35 +08:00
|
|
|
#include <syscalls/spi.h>
|
2017-04-21 19:24:07 +08:00
|
|
|
|
2017-10-27 05:21:35 +08:00
|
|
|
#endif /* __SPI_H__ */
|