Compare commits
No commits in common. "072498d59d6c5bdbb998e6113e31e7da614a269b" and "f9e3b65d3a9794ee2233aa88172346f887b48d04" have entirely different histories.
072498d59d
...
f9e3b65d3a
1 changed files with 25 additions and 35 deletions
|
@ -14,25 +14,17 @@ LOG_MODULE_REGISTER(spi_bitbang);
|
||||||
#include <zephyr/drivers/spi.h>
|
#include <zephyr/drivers/spi.h>
|
||||||
#include "spi_context.h"
|
#include "spi_context.h"
|
||||||
|
|
||||||
/* Expands to 1 if the node has no MISO GPIOs */
|
|
||||||
#define _MISO_PRESENT(n) (DT_INST_PROP_LEN_OR(n, miso_gpios, 0) != 0) |
|
|
||||||
#define SPI_BITBANG_MISO_REQUIRED DT_INST_FOREACH_STATUS_OKAY(_MISO_PRESENT) 0
|
|
||||||
|
|
||||||
struct spi_bitbang_data {
|
struct spi_bitbang_data {
|
||||||
struct spi_context ctx;
|
struct spi_context ctx;
|
||||||
int16_t wait_us;
|
int bits;
|
||||||
/* Number of bits per word. Maximum is 16. */
|
int wait_us;
|
||||||
int8_t bits;
|
int dfs;
|
||||||
/* Number of bytes per word. Maximum is 2. */
|
|
||||||
int8_t dfs;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct spi_bitbang_config {
|
struct spi_bitbang_config {
|
||||||
struct gpio_dt_spec clk_gpio;
|
struct gpio_dt_spec clk_gpio;
|
||||||
struct gpio_dt_spec mosi_gpio;
|
struct gpio_dt_spec mosi_gpio;
|
||||||
#if SPI_BITBANG_MISO_REQUIRED
|
|
||||||
struct gpio_dt_spec miso_gpio;
|
struct gpio_dt_spec miso_gpio;
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static int spi_bitbang_configure(const struct spi_bitbang_config *info,
|
static int spi_bitbang_configure(const struct spi_bitbang_config *info,
|
||||||
|
@ -113,11 +105,10 @@ static int spi_bitbang_transceive(const struct device *dev,
|
||||||
if (info->mosi_gpio.port) {
|
if (info->mosi_gpio.port) {
|
||||||
mosi = &info->mosi_gpio;
|
mosi = &info->mosi_gpio;
|
||||||
}
|
}
|
||||||
#if SPI_BITBANG_MISO_REQUIRED
|
|
||||||
if (info->miso_gpio.port) {
|
if (info->miso_gpio.port) {
|
||||||
miso = &info->miso_gpio;
|
miso = &info->miso_gpio;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (info->mosi_gpio.port) {
|
if (info->mosi_gpio.port) {
|
||||||
|
@ -293,7 +284,6 @@ int spi_bitbang_init(const struct device *dev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SPI_BITBANG_MISO_REQUIRED
|
|
||||||
if (config->miso_gpio.port != NULL) {
|
if (config->miso_gpio.port != NULL) {
|
||||||
if (!gpio_is_ready_dt(&config->miso_gpio)) {
|
if (!gpio_is_ready_dt(&config->miso_gpio)) {
|
||||||
LOG_ERR("GPIO port for miso pin is not ready");
|
LOG_ERR("GPIO port for miso pin is not ready");
|
||||||
|
@ -307,7 +297,6 @@ int spi_bitbang_init(const struct device *dev)
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
rc = spi_context_cs_configure_all(&data->ctx);
|
rc = spi_context_cs_configure_all(&data->ctx);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
|
@ -318,25 +307,26 @@ int spi_bitbang_init(const struct device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SPI_BITBANG_MISO_REQUIRED
|
#define SPI_BITBANG_INIT(inst) \
|
||||||
#define SPI_BITBANG_INIT_MISO(inst) .miso_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, miso_gpios, {0}),
|
static struct spi_bitbang_config spi_bitbang_config_##inst = { \
|
||||||
#else
|
.clk_gpio = GPIO_DT_SPEC_INST_GET(inst, clk_gpios), \
|
||||||
#define SPI_BITBANG_INIT_MISO(inst)
|
.mosi_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, mosi_gpios, {0}), \
|
||||||
#endif
|
.miso_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, miso_gpios, {0}), \
|
||||||
|
}; \
|
||||||
#define SPI_BITBANG_INIT(inst) \
|
\
|
||||||
static const struct spi_bitbang_config spi_bitbang_config_##inst = { \
|
static struct spi_bitbang_data spi_bitbang_data_##inst = { \
|
||||||
.clk_gpio = GPIO_DT_SPEC_INST_GET(inst, clk_gpios), \
|
SPI_CONTEXT_INIT_LOCK(spi_bitbang_data_##inst, ctx), \
|
||||||
.mosi_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, mosi_gpios, {0}), \
|
SPI_CONTEXT_INIT_SYNC(spi_bitbang_data_##inst, ctx), \
|
||||||
SPI_BITBANG_INIT_MISO(inst)}; \
|
SPI_CONTEXT_CS_GPIOS_INITIALIZE(DT_DRV_INST(inst), ctx) \
|
||||||
\
|
}; \
|
||||||
static struct spi_bitbang_data spi_bitbang_data_##inst = { \
|
\
|
||||||
SPI_CONTEXT_INIT_LOCK(spi_bitbang_data_##inst, ctx), \
|
DEVICE_DT_INST_DEFINE(inst, \
|
||||||
SPI_CONTEXT_INIT_SYNC(spi_bitbang_data_##inst, ctx), \
|
spi_bitbang_init, \
|
||||||
SPI_CONTEXT_CS_GPIOS_INITIALIZE(DT_DRV_INST(inst), ctx)}; \
|
NULL, \
|
||||||
\
|
&spi_bitbang_data_##inst, \
|
||||||
DEVICE_DT_INST_DEFINE(inst, spi_bitbang_init, NULL, &spi_bitbang_data_##inst, \
|
&spi_bitbang_config_##inst, \
|
||||||
&spi_bitbang_config_##inst, POST_KERNEL, CONFIG_SPI_INIT_PRIORITY, \
|
POST_KERNEL, \
|
||||||
&spi_bitbang_api);
|
CONFIG_SPI_INIT_PRIORITY, \
|
||||||
|
&spi_bitbang_api);
|
||||||
|
|
||||||
DT_INST_FOREACH_STATUS_OKAY(SPI_BITBANG_INIT)
|
DT_INST_FOREACH_STATUS_OKAY(SPI_BITBANG_INIT)
|
||||||
|
|
Loading…
Reference in a new issue