2020-05-25 12:04:04 +08:00
|
|
|
/*
|
2023-01-28 17:38:36 +08:00
|
|
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
2020-05-25 12:04:04 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2020-05-19 Sherman first version
|
2023-01-28 17:38:36 +08:00
|
|
|
* 2023-01-28 Andrew add Nrf5340 support
|
2020-05-25 12:04:04 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
|
|
|
#include <rtdevice.h>
|
|
|
|
#include <rthw.h>
|
|
|
|
|
|
|
|
#ifndef __DRV_SPI_H_
|
|
|
|
#define __DRV_SPI_H_
|
|
|
|
|
|
|
|
#ifdef BSP_USING_SPI
|
2023-01-28 17:38:36 +08:00
|
|
|
#if defined(SOC_NRF5340)
|
|
|
|
#include "nrfx_spim.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Attach the spi device to SPI bus, this function must be used after initialization.
|
|
|
|
* @param bus_name spi bus name "spi0"/"spi1"/"spi2"
|
|
|
|
* @param device_name spi device name "spi0x"/"spi1x"/"spi2x"
|
|
|
|
* @param ss_pin spi ss pin number
|
2023-03-17 12:12:16 +08:00
|
|
|
* @retval -RT_ERROR / RT_EOK
|
2023-01-28 17:38:36 +08:00
|
|
|
*/
|
|
|
|
rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_uint32_t ss_pin);
|
|
|
|
|
|
|
|
//SPI bus config
|
|
|
|
#ifdef BSP_USING_SPI0
|
|
|
|
#define NRFX_SPI0_CONFIG \
|
|
|
|
{ \
|
|
|
|
.bus_name = "spi0", \
|
|
|
|
.spi = NRFX_SPIM_INSTANCE(0) \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef BSP_USING_SPI1
|
|
|
|
#define NRFX_SPI1_CONFIG \
|
|
|
|
{ \
|
|
|
|
.bus_name = "spi1", \
|
|
|
|
.spi = NRFX_SPIM_INSTANCE(1) \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef BSP_USING_SPI2
|
|
|
|
#define NRFX_SPI2_CONFIG \
|
|
|
|
{ \
|
|
|
|
.bus_name = "spi2", \
|
|
|
|
.spi = NRFX_SPIM_INSTANCE(2) \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef BSP_USING_SPI3
|
|
|
|
#define NRFX_SPI3_CONFIG \
|
|
|
|
{ \
|
|
|
|
.bus_name = "spi3", \
|
|
|
|
.spi = NRFX_SPIM_INSTANCE(3) \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef BSP_USING_SPI4
|
|
|
|
#define NRFX_SPI4_CONFIG \
|
|
|
|
{ \
|
|
|
|
.bus_name = "spi4", \
|
|
|
|
.spi = NRFX_SPIM_INSTANCE(4) \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct nrfx_drv_spi_config
|
|
|
|
{
|
|
|
|
char *bus_name;
|
|
|
|
nrfx_spim_t spi;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nrfx_drv_spi
|
|
|
|
{
|
|
|
|
nrfx_spim_t spi; /* nrfx spi driver instance. */
|
|
|
|
nrfx_spim_config_t spi_config; /* nrfx spi config Configuration */
|
|
|
|
struct rt_spi_configuration *cfg;
|
|
|
|
struct rt_spi_bus spi_bus;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nrfx_drv_spi_pin_config
|
|
|
|
{
|
|
|
|
rt_uint8_t sck_pin;
|
|
|
|
rt_uint8_t mosi_pin;
|
|
|
|
rt_uint8_t miso_pin;
|
|
|
|
rt_uint8_t ss_pin;
|
|
|
|
};
|
|
|
|
#else
|
2020-05-25 12:04:04 +08:00
|
|
|
#include "nrfx_spi.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Attach the spi device to SPI bus, this function must be used after initialization.
|
|
|
|
* @param bus_name spi bus name "spi0"/"spi1"/"spi2"
|
|
|
|
* @param device_name spi device name "spi0x"/"spi1x"/"spi2x"
|
|
|
|
* @param ss_pin spi ss pin number
|
2023-03-17 12:12:16 +08:00
|
|
|
* @retval -RT_ERROR / RT_EOK
|
2020-05-25 12:04:04 +08:00
|
|
|
*/
|
|
|
|
rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_uint32_t ss_pin);
|
|
|
|
|
|
|
|
//SPI bus config
|
|
|
|
#ifdef BSP_USING_SPI0
|
|
|
|
#define NRFX_SPI0_CONFIG \
|
|
|
|
{ \
|
|
|
|
.bus_name = "spi0", \
|
|
|
|
.spi = NRFX_SPI_INSTANCE(0) \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef BSP_USING_SPI1
|
|
|
|
#define NRFX_SPI1_CONFIG \
|
|
|
|
{ \
|
|
|
|
.bus_name = "spi1", \
|
|
|
|
.spi = NRFX_SPI_INSTANCE(1) \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef BSP_USING_SPI2
|
|
|
|
#define NRFX_SPI2_CONFIG \
|
|
|
|
{ \
|
|
|
|
.bus_name = "spi2", \
|
|
|
|
.spi = NRFX_SPI_INSTANCE(2) \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct nrfx_drv_spi_config
|
|
|
|
{
|
|
|
|
char *bus_name;
|
|
|
|
nrfx_spi_t spi;
|
|
|
|
};
|
|
|
|
|
2021-03-14 15:18:33 +08:00
|
|
|
struct nrfx_drv_spi
|
2020-05-25 12:04:04 +08:00
|
|
|
{
|
|
|
|
nrfx_spi_t spi; /* nrfx spi driver instance. */
|
|
|
|
nrfx_spi_config_t spi_config; /* nrfx spi config Configuration */
|
|
|
|
struct rt_spi_configuration *cfg;
|
|
|
|
struct rt_spi_bus spi_bus;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nrfx_drv_spi_pin_config
|
|
|
|
{
|
|
|
|
rt_uint8_t sck_pin;
|
|
|
|
rt_uint8_t mosi_pin;
|
|
|
|
rt_uint8_t miso_pin;
|
|
|
|
rt_uint8_t ss_pin;
|
|
|
|
};
|
2023-01-28 17:38:36 +08:00
|
|
|
#endif
|
2020-05-25 12:04:04 +08:00
|
|
|
#endif /* BSP_USING_SPI */
|
|
|
|
#endif /*__DRV_SPI_H_*/
|