cleanup: include/: move spi.h to drivers/spi.h

move spi.h to drivers/spi.h and
create a shim for backward-compatibility.

No functional changes to the headers.
A warning in the shim can be controlled with CONFIG_COMPAT_INCLUDES.

Related to #16539

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
This commit is contained in:
Anas Nashif 2019-06-25 15:54:01 -04:00
commit bd70f6f1ed
54 changed files with 481 additions and 466 deletions

View file

@ -8,7 +8,7 @@
#include <drivers/gpio.h> #include <drivers/gpio.h>
#include <init.h> #include <init.h>
#include <spi.h> #include <drivers/spi.h>
#include <misc/byteorder.h> #include <misc/byteorder.h>
#include <misc/util.h> #include <misc/util.h>

View file

@ -6,7 +6,7 @@
#include <kernel.h> #include <kernel.h>
#include <device.h> #include <device.h>
#include <spi.h> #include <drivers/spi.h>
#include <drivers/gpio.h> #include <drivers/gpio.h>
#define LOG_LEVEL CONFIG_CAN_LOG_LEVEL #define LOG_LEVEL CONFIG_CAN_LOG_LEVEL

View file

@ -14,7 +14,7 @@ LOG_MODULE_REGISTER(display_ili9340);
#include <drivers/gpio.h> #include <drivers/gpio.h>
#include <misc/byteorder.h> #include <misc/byteorder.h>
#include <spi.h> #include <drivers/spi.h>
#include <string.h> #include <string.h>
struct ili9340_data { struct ili9340_data {

View file

@ -13,7 +13,7 @@ LOG_MODULE_REGISTER(ssd1673);
#include <display.h> #include <display.h>
#include <init.h> #include <init.h>
#include <drivers/gpio.h> #include <drivers/gpio.h>
#include <spi.h> #include <drivers/spi.h>
#include <misc/byteorder.h> #include <misc/byteorder.h>
#include "ssd1673_regs.h" #include "ssd1673_regs.h"

View file

@ -16,7 +16,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <drivers/gpio.h> #include <drivers/gpio.h>
#include <spi.h> #include <drivers/spi.h>
#include <net/net_pkt.h> #include <net/net_pkt.h>
#include <net/net_if.h> #include <net/net_if.h>
#include <net/ethernet.h> #include <net/ethernet.h>

View file

@ -7,7 +7,7 @@
#include <errno.h> #include <errno.h>
#include <drivers/flash.h> #include <drivers/flash.h>
#include <spi.h> #include <drivers/spi.h>
#include <init.h> #include <init.h>
#include <string.h> #include <string.h>
#include "spi_flash_w25qxxdv_defs.h" #include "spi_flash_w25qxxdv_defs.h"

View file

@ -8,7 +8,7 @@
#include <errno.h> #include <errno.h>
#include <drivers/flash.h> #include <drivers/flash.h>
#include <spi.h> #include <drivers/spi.h>
#include <init.h> #include <init.h>
#include <string.h> #include <string.h>
#include "spi_nor.h" #include "spi_nor.h"

View file

@ -26,7 +26,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
#include <string.h> #include <string.h>
#include <random/rand32.h> #include <random/rand32.h>
#include <spi.h> #include <drivers/spi.h>
#include <drivers/gpio.h> #include <drivers/gpio.h>
#include <net/ieee802154_radio.h> #include <net/ieee802154_radio.h>

View file

@ -11,7 +11,7 @@
#include <linker/sections.h> #include <linker/sections.h>
#include <sys/atomic.h> #include <sys/atomic.h>
#include <spi.h> #include <drivers/spi.h>
#include <ieee802154/cc1200.h> #include <ieee802154/cc1200.h>

View file

@ -11,7 +11,7 @@
#include <linker/sections.h> #include <linker/sections.h>
#include <sys/atomic.h> #include <sys/atomic.h>
#include <spi.h> #include <drivers/spi.h>
#include <ieee802154/cc2520.h> #include <ieee802154/cc2520.h>

View file

@ -12,7 +12,7 @@
#include <linker/sections.h> #include <linker/sections.h>
#include <sys/atomic.h> #include <sys/atomic.h>
#include <spi.h> #include <drivers/spi.h>
/* Runtime context structure /* Runtime context structure
*************************** ***************************

View file

@ -6,7 +6,7 @@
#include <errno.h> #include <errno.h>
#include <drivers/led_strip.h> #include <drivers/led_strip.h>
#include <spi.h> #include <drivers/spi.h>
struct apa102_data { struct apa102_data {
struct device *spi; struct device *spi;

View file

@ -29,7 +29,7 @@ LOG_MODULE_REGISTER(lpd880x);
#include <zephyr.h> #include <zephyr.h>
#include <device.h> #include <device.h>
#include <spi.h> #include <drivers/spi.h>
#include <misc/util.h> #include <misc/util.h>
/* /*

View file

@ -14,7 +14,7 @@ LOG_MODULE_REGISTER(ws2812);
#include <zephyr.h> #include <zephyr.h>
#include <device.h> #include <device.h>
#include <spi.h> #include <drivers/spi.h>
#include <misc/util.h> #include <misc/util.h>
/* /*

View file

@ -12,7 +12,7 @@
#include <drivers/gpio.h> #include <drivers/gpio.h>
#include <misc/byteorder.h> #include <misc/byteorder.h>
#include <misc/__assert.h> #include <misc/__assert.h>
#include <spi.h> #include <drivers/spi.h>
#include <logging/log.h> #include <logging/log.h>
#include "adxl362.h" #include "adxl362.h"

View file

@ -10,7 +10,7 @@
#include <zephyr/types.h> #include <zephyr/types.h>
#include <device.h> #include <device.h>
#include <drivers/gpio.h> #include <drivers/gpio.h>
#include <spi.h> #include <drivers/spi.h>
#define ADXL362_SLAVE_ID 1 #define ADXL362_SLAVE_ID 1

View file

@ -12,7 +12,7 @@
#include <misc/printk.h> #include <misc/printk.h>
#include <misc/__assert.h> #include <misc/__assert.h>
#include <stdlib.h> #include <stdlib.h>
#include <spi.h> #include <drivers/spi.h>
#include <drivers/i2c.h> #include <drivers/i2c.h>
#include <logging/log.h> #include <logging/log.h>

View file

@ -10,7 +10,7 @@
#include <zephyr/types.h> #include <zephyr/types.h>
#include <device.h> #include <device.h>
#include <drivers/gpio.h> #include <drivers/gpio.h>
#include <spi.h> #include <drivers/spi.h>
#include <drivers/i2c.h> #include <drivers/i2c.h>
#include <misc/util.h> #include <misc/util.h>

View file

@ -17,7 +17,7 @@
#ifdef DT_BOSCH_BME280_BUS_I2C #ifdef DT_BOSCH_BME280_BUS_I2C
#include <drivers/i2c.h> #include <drivers/i2c.h>
#elif defined DT_BOSCH_BME280_BUS_SPI #elif defined DT_BOSCH_BME280_BUS_SPI
#include <spi.h> #include <drivers/spi.h>
#endif #endif
#include <logging/log.h> #include <logging/log.h>

View file

@ -9,7 +9,7 @@
#define ZEPHYR_DRIVERS_SENSOR_BMI160_BMI160_H_ #define ZEPHYR_DRIVERS_SENSOR_BMI160_BMI160_H_
#include <drivers/gpio.h> #include <drivers/gpio.h>
#include <spi.h> #include <drivers/spi.h>
#include <misc/util.h> #include <misc/util.h>
/* registers */ /* registers */

View file

@ -19,7 +19,7 @@
#define LIS2DH_BUS_DEV_NAME DT_INST_0_ST_LIS2DH_BUS_NAME #define LIS2DH_BUS_DEV_NAME DT_INST_0_ST_LIS2DH_BUS_NAME
#if defined(DT_ST_LIS2DH_BUS_SPI) #if defined(DT_ST_LIS2DH_BUS_SPI)
#include <spi.h> #include <drivers/spi.h>
#define LIS2DH_SPI_READ_BIT BIT(7) #define LIS2DH_SPI_READ_BIT BIT(7)
#define LIS2DH_SPI_AUTOINC_ADDR BIT(6) #define LIS2DH_SPI_AUTOINC_ADDR BIT(6)

View file

@ -10,7 +10,7 @@
#include <string.h> #include <string.h>
#include <spi.h> #include <drivers/spi.h>
#include "lis2ds12.h" #include "lis2ds12.h"
#include <logging/log.h> #include <logging/log.h>

View file

@ -15,7 +15,7 @@
#include <drivers/sensor.h> #include <drivers/sensor.h>
#if defined(DT_ST_LIS2DW12_BUS_SPI) #if defined(DT_ST_LIS2DW12_BUS_SPI)
#include <spi.h> #include <drivers/spi.h>
#elif defined(DT_ST_LIS2DW12_BUS_I2C) #elif defined(DT_ST_LIS2DW12_BUS_I2C)
#include <drivers/i2c.h> #include <drivers/i2c.h>
#endif #endif

View file

@ -11,7 +11,7 @@
#ifndef ZEPHYR_DRIVERS_SENSOR_LIS2DW12_LIS2DW12_H_ #ifndef ZEPHYR_DRIVERS_SENSOR_LIS2DW12_LIS2DW12_H_
#define ZEPHYR_DRIVERS_SENSOR_LIS2DW12_LIS2DW12_H_ #define ZEPHYR_DRIVERS_SENSOR_LIS2DW12_LIS2DW12_H_
#include <spi.h> #include <drivers/spi.h>
#include <drivers/gpio.h> #include <drivers/gpio.h>
#include <misc/util.h> #include <misc/util.h>
#include <drivers/sensor.h> #include <drivers/sensor.h>

View file

@ -8,7 +8,7 @@
*/ */
#include <string.h> #include <string.h>
#include <spi.h> #include <drivers/spi.h>
#include "lsm6dsl.h" #include "lsm6dsl.h"
#include <logging/log.h> #include <logging/log.h>

View file

@ -8,7 +8,7 @@
#include <logging/log.h> #include <logging/log.h>
LOG_MODULE_REGISTER(spi_cc13xx_cc26xx); LOG_MODULE_REGISTER(spi_cc13xx_cc26xx);
#include <spi.h> #include <drivers/spi.h>
#include <sys_clock.h> #include <sys_clock.h>
#include <driverlib/prcm.h> #include <driverlib/prcm.h>

View file

@ -13,7 +13,7 @@
#define ZEPHYR_DRIVERS_SPI_SPI_CONTEXT_H_ #define ZEPHYR_DRIVERS_SPI_SPI_CONTEXT_H_
#include <drivers/gpio.h> #include <drivers/gpio.h>
#include <spi.h> #include <drivers/spi.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View file

@ -40,7 +40,7 @@ LOG_MODULE_REGISTER(spi_dw);
#include <drivers/interrupt_controller/ioapic.h> #include <drivers/interrupt_controller/ioapic.h>
#endif #endif
#include <spi.h> #include <drivers/spi.h>
#include "spi_dw.h" #include "spi_dw.h"
#include "spi_context.h" #include "spi_context.h"

View file

@ -9,7 +9,7 @@
#ifndef ZEPHYR_DRIVERS_SPI_SPI_DW_H_ #ifndef ZEPHYR_DRIVERS_SPI_SPI_DW_H_
#define ZEPHYR_DRIVERS_SPI_SPI_DW_H_ #define ZEPHYR_DRIVERS_SPI_SPI_DW_H_
#include <spi.h> #include <drivers/spi.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include <spi.h> #include <drivers/spi.h>
#include <syscall_handler.h> #include <syscall_handler.h>
#include <string.h> #include <string.h>

View file

@ -23,7 +23,7 @@ LOG_MODULE_REGISTER(spi_intel);
#include <sys/sys_io.h> #include <sys/sys_io.h>
#include <power/power.h> #include <power/power.h>
#include <spi.h> #include <drivers/spi.h>
#include "spi_intel.h" #include "spi_intel.h"
#ifdef CONFIG_IOAPIC #ifdef CONFIG_IOAPIC

View file

@ -12,7 +12,7 @@ LOG_MODULE_REGISTER(spi_ll_stm32);
#include <kernel.h> #include <kernel.h>
#include <soc.h> #include <soc.h>
#include <errno.h> #include <errno.h>
#include <spi.h> #include <drivers/spi.h>
#include <toolchain.h> #include <toolchain.h>
#include <clock_control/stm32_clock_control.h> #include <clock_control/stm32_clock_control.h>

View file

@ -6,7 +6,7 @@
*/ */
#include <errno.h> #include <errno.h>
#include <spi.h> #include <drivers/spi.h>
#include <drivers/clock_control.h> #include <drivers/clock_control.h>
#include <fsl_dspi.h> #include <fsl_dspi.h>

View file

@ -5,7 +5,7 @@
*/ */
#include <errno.h> #include <errno.h>
#include <spi.h> #include <drivers/spi.h>
#include <drivers/clock_control.h> #include <drivers/clock_control.h>
#include <fsl_lpspi.h> #include <fsl_lpspi.h>

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include <spi.h> #include <drivers/spi.h>
#include <nrfx_spi.h> #include <nrfx_spi.h>
#define LOG_DOMAIN "spi_nrfx_spi" #define LOG_DOMAIN "spi_nrfx_spi"

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include <spi.h> #include <drivers/spi.h>
#include <nrfx_spim.h> #include <nrfx_spim.h>
#include <string.h> #include <string.h>

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include <spi.h> #include <drivers/spi.h>
#include <nrfx_spis.h> #include <nrfx_spis.h>
#define LOG_DOMAIN "spi_nrfx_spis" #define LOG_DOMAIN "spi_nrfx_spis"

View file

@ -12,7 +12,7 @@ LOG_MODULE_REGISTER(spi_sam);
#include "spi_context.h" #include "spi_context.h"
#include <errno.h> #include <errno.h>
#include <device.h> #include <device.h>
#include <spi.h> #include <drivers/spi.h>
#include <soc.h> #include <soc.h>
#define SAM_SPI_CHIP_SELECT_COUNT 4 #define SAM_SPI_CHIP_SELECT_COUNT 4

View file

@ -11,7 +11,7 @@ LOG_MODULE_REGISTER(spi_sam0);
#include "spi_context.h" #include "spi_context.h"
#include <errno.h> #include <errno.h>
#include <device.h> #include <device.h>
#include <spi.h> #include <drivers/spi.h>
#include <soc.h> #include <soc.h>
#include <drivers/dma.h> #include <drivers/dma.h>

View file

@ -11,7 +11,7 @@
#include <sys/sys_io.h> #include <sys/sys_io.h>
#include <device.h> #include <device.h>
#include <spi.h> #include <drivers/spi.h>
#define SPI_CFG(dev) ((struct spi_sifive_cfg *) ((dev)->config->config_info)) #define SPI_CFG(dev) ((struct spi_sifive_cfg *) ((dev)->config->config_info))
#define SPI_DATA(dev) ((struct spi_sifive_data *) ((dev)->driver_data)) #define SPI_DATA(dev) ((struct spi_sifive_data *) ((dev)->driver_data))

View file

@ -13,7 +13,7 @@ LOG_MODULE_REGISTER(wifi_eswifi_bus_spi);
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <drivers/gpio.h> #include <drivers/gpio.h>
#include <spi.h> #include <drivers/spi.h>
#include "eswifi.h" #include "eswifi.h"

View file

@ -9,7 +9,7 @@
#include <device.h> #include <device.h>
#include <drivers/gpio.h> #include <drivers/gpio.h>
#include <spi.h> #include <drivers/spi.h>
#include <wifi/winc1500.h> #include <wifi/winc1500.h>

View file

@ -12,7 +12,7 @@ LOG_MODULE_REGISTER(winc1500);
#include <stdint.h> #include <stdint.h>
#include <device.h> #include <device.h>
#include <spi.h> #include <drivers/spi.h>
#include "wifi_winc1500_nm_bsp_internal.h" #include "wifi_winc1500_nm_bsp_internal.h"

425
include/drivers/spi.h Normal file
View file

@ -0,0 +1,425 @@
/*
* Copyright (c) 2015 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
/**
* @file
* @brief Public API for SPI drivers and applications
*/
#ifndef ZEPHYR_INCLUDE_DRIVERS_SPI_H_
#define ZEPHYR_INCLUDE_DRIVERS_SPI_H_
/**
* @brief SPI Interface
* @defgroup spi_interface SPI Interface
* @ingroup io_interfaces
* @{
*/
#include <zephyr/types.h>
#include <stddef.h>
#include <device.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief SPI operational mode
*/
#define SPI_OP_MODE_MASTER 0
#define SPI_OP_MODE_SLAVE BIT(0)
#define SPI_OP_MODE_MASK 0x1
#define SPI_OP_MODE_GET(_operation_) ((_operation_) & SPI_OP_MODE_MASK)
/**
* @brief SPI Polarity & Phase Modes
*/
/**
* 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,
* capture will occur on low to high transition and high to low if
* 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)
/**
* @brief SPI Transfer modes (host controller dependent)
*/
#define SPI_TRANSFER_MSB (0)
#define SPI_TRANSFER_LSB BIT(4)
/**
* @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)
#define SPI_WORD_SET(_word_size_) \
((_word_size_) << SPI_WORD_SIZE_SHIFT)
/**
* @brief SPI MISO lines
*
* Some controllers support dual, quad or octal MISO lines connected to slaves.
* Default is single, which is the case most of the time.
*/
#define SPI_LINES_SINGLE (0 << 11)
#define SPI_LINES_DUAL (1 << 11)
#define SPI_LINES_QUAD (2 << 11)
#define SPI_LINES_OCTAL (3 << 11)
#define SPI_LINES_MASK (0x3 << 11)
/**
* @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)
/* 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)
/**
* @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.
*
* @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.
* @param gpio_pin is a number representing the gpio PIN that will be used
* to act as a CS line
* @param delay is a delay in microseconds to wait before starting the
* transmission and before releasing the CS line
*/
struct spi_cs_control {
struct device *gpio_dev;
u32_t gpio_pin;
u32_t delay;
};
/**
* @brief SPI controller configuration structure
*
* @param frequency is the bus frequency in Hertz
* @param operation is a bit field with the following parts:
*
* 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.
* lines [ 11 : 12 ] - MISO lines: Single/Dual/Quad/Octal.
* cs_hold [ 13 ] - Hold on the CS line if possible.
* lock_on [ 14 ] - Keep resource locked for the caller.
* cs_active_high [ 15 ] - Active high CS logic.
* @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
* emulated through a gpio line, or NULL otherwise.
*
* @note Only cs_hold and lock_on can be changed between consecutive
* transceive call. Rest of the attributes are not meant to be tweaked.
*/
struct spi_config {
u32_t frequency;
u16_t operation;
u16_t slave;
const struct spi_cs_control *cs;
};
/**
* @brief SPI buffer structure
*
* @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).
*/
struct spi_buf {
void *buf;
size_t len;
};
/**
* @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;
};
/**
* @typedef spi_api_io
* @brief Callback API for I/O
* See spi_transceive() for argument descriptions
*/
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);
/**
* @typedef spi_api_io
* @brief Callback API for asynchronous I/O
* See spi_transceive_async() for argument descriptions
*/
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,
struct k_poll_signal *async);
/**
* @typedef spi_api_release
* @brief Callback API for unlocking SPI device.
* See spi_release() for argument descriptions
*/
typedef int (*spi_api_release)(struct device *dev,
const struct spi_config *config);
/**
* @brief SPI driver API
* This is the mandatory API any SPI driver needs to expose.
*/
struct spi_driver_api {
spi_api_io transceive;
#ifdef CONFIG_SPI_ASYNC
spi_api_io_async transceive_async;
#endif /* CONFIG_SPI_ASYNC */
spi_api_release release;
};
/**
* @brief Read/write the specified amount of data from the SPI driver.
*
* Note: This function is synchronous.
*
* @param dev Pointer to the device structure for the driver instance
* @param config Pointer to a valid spi_config structure instance.
* @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.
*
* @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.
*/
__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 z_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)
{
const struct spi_driver_api *api =
(const struct spi_driver_api *)dev->driver_api;
return api->transceive(dev, config, tx_bufs, rx_bufs);
}
/**
* @brief Read the specified amount of data from the SPI driver.
*
* Note: This function is synchronous.
*
* @param dev Pointer to the device structure for the driver instance
* @param config Pointer to a valid spi_config structure instance.
* @param rx_bufs Buffer array where data to be read will be written to.
*
* @retval 0 If successful, negative errno code otherwise.
*
* @note This function is an helper function calling spi_transceive.
*/
static inline int spi_read(struct device *dev,
const struct spi_config *config,
const struct spi_buf_set *rx_bufs)
{
return spi_transceive(dev, config, NULL, rx_bufs);
}
/**
* @brief Write the specified amount of data from the SPI driver.
*
* Note: This function is synchronous.
*
* @param dev Pointer to the device structure for the driver instance
* @param config Pointer to a valid spi_config structure instance.
* @param tx_bufs Buffer array where data to be sent originates from.
*
* @retval 0 If successful, negative errno code otherwise.
*
* @note This function is an helper function calling spi_transceive.
*/
static inline int spi_write(struct device *dev,
const struct spi_config *config,
const struct spi_buf_set *tx_bufs)
{
return spi_transceive(dev, config, tx_bufs, NULL);
}
#ifdef CONFIG_SPI_ASYNC
/**
* @brief Read/write the specified amount of data from the SPI driver.
*
* Note: This function is asynchronous.
*
* @param dev Pointer to the device structure for the driver instance
* @param config Pointer to a valid spi_config structure instance.
* @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.
* @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. In case of slave
* transaction: if successful it will return the amount of frames
* received, negative errno code otherwise.
*/
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,
struct k_poll_signal *async)
{
const struct spi_driver_api *api =
(const struct spi_driver_api *)dev->driver_api;
return api->transceive_async(dev, config, tx_bufs, rx_bufs, async);
}
/**
* @brief Read the specified amount of data from the SPI driver.
*
* Note: This function is asynchronous.
*
* @param dev Pointer to the device structure for the driver instance
* @param config Pointer to a valid spi_config structure instance.
* @param rx_bufs Buffer array where data to be read will be written to.
* @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.
*
* @note This function is an helper function calling spi_transceive_async.
*/
static inline int spi_read_async(struct device *dev,
const struct spi_config *config,
const struct spi_buf_set *rx_bufs,
struct k_poll_signal *async)
{
return spi_transceive_async(dev, config, NULL, rx_bufs, async);
}
/**
* @brief Write the specified amount of data from the SPI driver.
*
* Note: This function is asynchronous.
*
* @param dev Pointer to the device structure for the driver instance
* @param config Pointer to a valid spi_config structure instance.
* @param tx_bufs Buffer array where data to be sent originates from.
* @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.
*
* @note This function is an helper function calling spi_transceive_async.
*/
static inline int spi_write_async(struct device *dev,
const struct spi_config *config,
const struct spi_buf_set *tx_bufs,
struct k_poll_signal *async)
{
return spi_transceive_async(dev, config, tx_bufs, NULL, async);
}
#endif /* CONFIG_SPI_ASYNC */
/**
* @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.
*
* @param dev Pointer to the device structure for the driver instance
* @param config Pointer to a valid spi_config structure instance.
*/
__syscall int spi_release(struct device *dev,
const struct spi_config *config);
static inline int z_impl_spi_release(struct device *dev,
const struct spi_config *config)
{
const struct spi_driver_api *api =
(const struct spi_driver_api *)dev->driver_api;
return api->release(dev, config);
}
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#include <syscalls/spi.h>
#endif /* ZEPHYR_INCLUDE_DRIVERS_SPI_H_ */

View file

@ -1,425 +1,15 @@
/* /*
* Copyright (c) 2015 Intel Corporation * Copyright (c) 2019 Intel Corporation
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
/**
* @file
* @brief Public API for SPI drivers and applications
*/
#ifndef ZEPHYR_INCLUDE_SPI_H_ #ifndef ZEPHYR_INCLUDE_SPI_H_
#define ZEPHYR_INCLUDE_SPI_H_ #define ZEPHYR_INCLUDE_SPI_H_
/** #ifndef CONFIG_COMPAT_INCLUDES
* @brief SPI Interface #warning "This header file has moved, include <drivers/spi.h> instead."
* @defgroup spi_interface SPI Interface
* @ingroup io_interfaces
* @{
*/
#include <zephyr/types.h>
#include <stddef.h>
#include <device.h>
#ifdef __cplusplus
extern "C" {
#endif #endif
/** #include <drivers/spi.h>
* @brief SPI operational mode
*/
#define SPI_OP_MODE_MASTER 0
#define SPI_OP_MODE_SLAVE BIT(0)
#define SPI_OP_MODE_MASK 0x1
#define SPI_OP_MODE_GET(_operation_) ((_operation_) & SPI_OP_MODE_MASK)
/**
* @brief SPI Polarity & Phase Modes
*/
/**
* 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,
* capture will occur on low to high transition and high to low if
* 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)
/**
* @brief SPI Transfer modes (host controller dependent)
*/
#define SPI_TRANSFER_MSB (0)
#define SPI_TRANSFER_LSB BIT(4)
/**
* @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)
#define SPI_WORD_SET(_word_size_) \
((_word_size_) << SPI_WORD_SIZE_SHIFT)
/**
* @brief SPI MISO lines
*
* Some controllers support dual, quad or octal MISO lines connected to slaves.
* Default is single, which is the case most of the time.
*/
#define SPI_LINES_SINGLE (0 << 11)
#define SPI_LINES_DUAL (1 << 11)
#define SPI_LINES_QUAD (2 << 11)
#define SPI_LINES_OCTAL (3 << 11)
#define SPI_LINES_MASK (0x3 << 11)
/**
* @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)
/* 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)
/**
* @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.
*
* @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.
* @param gpio_pin is a number representing the gpio PIN that will be used
* to act as a CS line
* @param delay is a delay in microseconds to wait before starting the
* transmission and before releasing the CS line
*/
struct spi_cs_control {
struct device *gpio_dev;
u32_t gpio_pin;
u32_t delay;
};
/**
* @brief SPI controller configuration structure
*
* @param frequency is the bus frequency in Hertz
* @param operation is a bit field with the following parts:
*
* 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.
* lines [ 11 : 12 ] - MISO lines: Single/Dual/Quad/Octal.
* cs_hold [ 13 ] - Hold on the CS line if possible.
* lock_on [ 14 ] - Keep resource locked for the caller.
* cs_active_high [ 15 ] - Active high CS logic.
* @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
* emulated through a gpio line, or NULL otherwise.
*
* @note Only cs_hold and lock_on can be changed between consecutive
* transceive call. Rest of the attributes are not meant to be tweaked.
*/
struct spi_config {
u32_t frequency;
u16_t operation;
u16_t slave;
const struct spi_cs_control *cs;
};
/**
* @brief SPI buffer structure
*
* @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).
*/
struct spi_buf {
void *buf;
size_t len;
};
/**
* @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;
};
/**
* @typedef spi_api_io
* @brief Callback API for I/O
* See spi_transceive() for argument descriptions
*/
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);
/**
* @typedef spi_api_io
* @brief Callback API for asynchronous I/O
* See spi_transceive_async() for argument descriptions
*/
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,
struct k_poll_signal *async);
/**
* @typedef spi_api_release
* @brief Callback API for unlocking SPI device.
* See spi_release() for argument descriptions
*/
typedef int (*spi_api_release)(struct device *dev,
const struct spi_config *config);
/**
* @brief SPI driver API
* This is the mandatory API any SPI driver needs to expose.
*/
struct spi_driver_api {
spi_api_io transceive;
#ifdef CONFIG_SPI_ASYNC
spi_api_io_async transceive_async;
#endif /* CONFIG_SPI_ASYNC */
spi_api_release release;
};
/**
* @brief Read/write the specified amount of data from the SPI driver.
*
* Note: This function is synchronous.
*
* @param dev Pointer to the device structure for the driver instance
* @param config Pointer to a valid spi_config structure instance.
* @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.
*
* @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.
*/
__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 z_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)
{
const struct spi_driver_api *api =
(const struct spi_driver_api *)dev->driver_api;
return api->transceive(dev, config, tx_bufs, rx_bufs);
}
/**
* @brief Read the specified amount of data from the SPI driver.
*
* Note: This function is synchronous.
*
* @param dev Pointer to the device structure for the driver instance
* @param config Pointer to a valid spi_config structure instance.
* @param rx_bufs Buffer array where data to be read will be written to.
*
* @retval 0 If successful, negative errno code otherwise.
*
* @note This function is an helper function calling spi_transceive.
*/
static inline int spi_read(struct device *dev,
const struct spi_config *config,
const struct spi_buf_set *rx_bufs)
{
return spi_transceive(dev, config, NULL, rx_bufs);
}
/**
* @brief Write the specified amount of data from the SPI driver.
*
* Note: This function is synchronous.
*
* @param dev Pointer to the device structure for the driver instance
* @param config Pointer to a valid spi_config structure instance.
* @param tx_bufs Buffer array where data to be sent originates from.
*
* @retval 0 If successful, negative errno code otherwise.
*
* @note This function is an helper function calling spi_transceive.
*/
static inline int spi_write(struct device *dev,
const struct spi_config *config,
const struct spi_buf_set *tx_bufs)
{
return spi_transceive(dev, config, tx_bufs, NULL);
}
#ifdef CONFIG_SPI_ASYNC
/**
* @brief Read/write the specified amount of data from the SPI driver.
*
* Note: This function is asynchronous.
*
* @param dev Pointer to the device structure for the driver instance
* @param config Pointer to a valid spi_config structure instance.
* @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.
* @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. In case of slave
* transaction: if successful it will return the amount of frames
* received, negative errno code otherwise.
*/
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,
struct k_poll_signal *async)
{
const struct spi_driver_api *api =
(const struct spi_driver_api *)dev->driver_api;
return api->transceive_async(dev, config, tx_bufs, rx_bufs, async);
}
/**
* @brief Read the specified amount of data from the SPI driver.
*
* Note: This function is asynchronous.
*
* @param dev Pointer to the device structure for the driver instance
* @param config Pointer to a valid spi_config structure instance.
* @param rx_bufs Buffer array where data to be read will be written to.
* @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.
*
* @note This function is an helper function calling spi_transceive_async.
*/
static inline int spi_read_async(struct device *dev,
const struct spi_config *config,
const struct spi_buf_set *rx_bufs,
struct k_poll_signal *async)
{
return spi_transceive_async(dev, config, NULL, rx_bufs, async);
}
/**
* @brief Write the specified amount of data from the SPI driver.
*
* Note: This function is asynchronous.
*
* @param dev Pointer to the device structure for the driver instance
* @param config Pointer to a valid spi_config structure instance.
* @param tx_bufs Buffer array where data to be sent originates from.
* @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.
*
* @note This function is an helper function calling spi_transceive_async.
*/
static inline int spi_write_async(struct device *dev,
const struct spi_config *config,
const struct spi_buf_set *tx_bufs,
struct k_poll_signal *async)
{
return spi_transceive_async(dev, config, tx_bufs, NULL, async);
}
#endif /* CONFIG_SPI_ASYNC */
/**
* @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.
*
* @param dev Pointer to the device structure for the driver instance
* @param config Pointer to a valid spi_config structure instance.
*/
__syscall int spi_release(struct device *dev,
const struct spi_config *config);
static inline int z_impl_spi_release(struct device *dev,
const struct spi_config *config)
{
const struct spi_driver_api *api =
(const struct spi_driver_api *)dev->driver_api;
return api->release(dev, config);
}
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#include <syscalls/spi.h>
#endif /* ZEPHYR_INCLUDE_SPI_H_ */ #endif /* ZEPHYR_INCLUDE_SPI_H_ */

View file

@ -18,7 +18,7 @@
#include <device.h> #include <device.h>
#include <init.h> #include <init.h>
#include <drivers/gpio.h> #include <drivers/gpio.h>
#include <spi.h> #include <drivers/spi.h>
#include <net/buf.h> #include <net/buf.h>
#include <bluetooth/bluetooth.h> #include <bluetooth/bluetooth.h>

View file

@ -10,7 +10,7 @@
#include <drivers/gpio.h> #include <drivers/gpio.h>
#include <drivers/led.h> #include <drivers/led.h>
#include <drivers/i2c.h> #include <drivers/i2c.h>
#include <spi.h> #include <drivers/spi.h>
#include <drivers/sensor.h> #include <drivers/sensor.h>
#include <stdio.h> #include <stdio.h>

View file

@ -15,7 +15,7 @@ LOG_MODULE_REGISTER(main);
#include <zephyr.h> #include <zephyr.h>
#include <drivers/led_strip.h> #include <drivers/led_strip.h>
#include <device.h> #include <device.h>
#include <spi.h> #include <drivers/spi.h>
#include <misc/util.h> #include <misc/util.h>
/* /*

View file

@ -14,7 +14,7 @@ LOG_MODULE_REGISTER(main);
#include <zephyr.h> #include <zephyr.h>
#include <drivers/led_strip.h> #include <drivers/led_strip.h>
#include <device.h> #include <device.h>
#include <spi.h> #include <drivers/spi.h>
#include <misc/util.h> #include <misc/util.h>
/* /*

View file

@ -15,7 +15,7 @@ LOG_MODULE_REGISTER(main);
#include <zephyr.h> #include <zephyr.h>
#include <drivers/led_strip.h> #include <drivers/led_strip.h>
#include <device.h> #include <device.h>
#include <spi.h> #include <drivers/spi.h>
#include <misc/util.h> #include <misc/util.h>
/* /*

View file

@ -8,7 +8,7 @@
#include <zephyr.h> #include <zephyr.h>
#include <misc/printk.h> #include <misc/printk.h>
#include <device.h> #include <device.h>
#include <spi.h> #include <drivers/spi.h>
/** /**
* @file Sample app using the Fujitsu MB85RS64V FRAM through SPI. * @file Sample app using the Fujitsu MB85RS64V FRAM through SPI.

View file

@ -11,7 +11,7 @@ LOG_MODULE_REGISTER(sdhc, CONFIG_DISK_LOG_LEVEL);
#include <disk/disk_access.h> #include <disk/disk_access.h>
#include <drivers/gpio.h> #include <drivers/gpio.h>
#include <misc/byteorder.h> #include <misc/byteorder.h>
#include <spi.h> #include <drivers/spi.h>
#include <sys/crc.h> #include <sys/crc.h>
#define SDHC_SECTOR_SIZE 512 #define SDHC_SECTOR_SIZE 512

View file

@ -23,7 +23,7 @@
#include <drivers/gpio.h> #include <drivers/gpio.h>
#include <drivers/led_strip.h> #include <drivers/led_strip.h>
#include <spi.h> #include <drivers/spi.h>
#include <uart.h> #include <uart.h>
#include <usb/usb_device.h> #include <usb/usb_device.h>
#include <usb/class/usb_hid.h> #include <usb/class/usb_hid.h>

View file

@ -14,7 +14,7 @@ LOG_MODULE_REGISTER(main);
#include <stdio.h> #include <stdio.h>
#include <ztest.h> #include <ztest.h>
#include <spi.h> #include <drivers/spi.h>
#define SPI_DRV_NAME CONFIG_SPI_LOOPBACK_DRV_NAME #define SPI_DRV_NAME CONFIG_SPI_LOOPBACK_DRV_NAME
#define SPI_SLAVE CONFIG_SPI_LOOPBACK_SLAVE_NUMBER #define SPI_SLAVE CONFIG_SPI_LOOPBACK_SLAVE_NUMBER