Lines Matching +full:half +full:- +full:duplex

2  * Copyright (c) 2021 Marc Reilly - Creative Product Design
4 * SPDX-License-Identifier: Apache-2.0
34 if (config->operation & SPI_OP_MODE_SLAVE) { in spi_bitbang_configure()
36 return -ENOTSUP; in spi_bitbang_configure()
39 if (config->operation & (SPI_TRANSFER_LSB | SPI_LINES_DUAL in spi_bitbang_configure()
42 return -ENOTSUP; in spi_bitbang_configure()
45 const int bits = SPI_WORD_SIZE_GET(config->operation); in spi_bitbang_configure()
49 return -ENOTSUP; in spi_bitbang_configure()
52 data->bits = bits; in spi_bitbang_configure()
53 data->dfs = ((data->bits - 1) / 8) + 1; in spi_bitbang_configure()
54 if (config->frequency > 0) { in spi_bitbang_configure()
58 data->wait_us = (1000000ul * 2000ul / config->frequency) / 2000ul; in spi_bitbang_configure()
59 data->wait_us /= 2; in spi_bitbang_configure()
61 data->wait_us = 8 / 2; /* 125 kHz */ in spi_bitbang_configure()
64 data->ctx.config = config; in spi_bitbang_configure()
74 const struct spi_bitbang_config *info = dev->config; in spi_bitbang_transceive()
75 struct spi_bitbang_data *data = dev->data; in spi_bitbang_transceive()
76 struct spi_context *ctx = &data->ctx; in spi_bitbang_transceive()
87 if (spi_cfg->operation & SPI_HALF_DUPLEX) { in spi_bitbang_transceive()
88 if (!info->mosi_gpio.port) { in spi_bitbang_transceive()
89 LOG_ERR("No MOSI pin specified in half duplex mode"); in spi_bitbang_transceive()
90 return -EINVAL; in spi_bitbang_transceive()
94 LOG_ERR("Both RX and TX specified in half duplex mode"); in spi_bitbang_transceive()
95 return -EINVAL; in spi_bitbang_transceive()
98 mosi = &info->mosi_gpio; in spi_bitbang_transceive()
102 miso = &info->mosi_gpio; in spi_bitbang_transceive()
105 if (info->mosi_gpio.port) { in spi_bitbang_transceive()
106 mosi = &info->mosi_gpio; in spi_bitbang_transceive()
109 if (info->miso_gpio.port) { in spi_bitbang_transceive()
110 miso = &info->miso_gpio; in spi_bitbang_transceive()
114 if (info->mosi_gpio.port) { in spi_bitbang_transceive()
115 rc = gpio_pin_configure_dt(&info->mosi_gpio, mosi_flags); in spi_bitbang_transceive()
122 spi_context_buffers_setup(ctx, tx_bufs, rx_bufs, data->dfs); in spi_bitbang_transceive()
128 if (SPI_MODE_GET(spi_cfg->operation) & SPI_MODE_CPOL) { in spi_bitbang_transceive()
131 if (SPI_MODE_GET(spi_cfg->operation) & SPI_MODE_CPHA) { in spi_bitbang_transceive()
134 if (SPI_MODE_GET(spi_cfg->operation) & SPI_MODE_LOOP) { in spi_bitbang_transceive()
139 gpio_pin_set_dt(&info->clk_gpio, clock_state); in spi_bitbang_transceive()
143 const uint32_t wait_us = data->wait_us; in spi_bitbang_transceive()
148 if (ctx->tx_len) { in spi_bitbang_transceive()
149 switch (data->dfs) { in spi_bitbang_transceive()
151 w = *(uint16_t *)(ctx->tx_buf); in spi_bitbang_transceive()
154 w = *(uint8_t *)(ctx->tx_buf); in spi_bitbang_transceive()
159 int shift = data->bits - 1; in spi_bitbang_transceive()
181 gpio_pin_set_dt(&info->clk_gpio, !clock_state); in spi_bitbang_transceive()
190 gpio_pin_set_dt(&info->clk_gpio, clock_state); in spi_bitbang_transceive()
202 --shift; in spi_bitbang_transceive()
206 switch (data->dfs) { in spi_bitbang_transceive()
208 *(uint16_t *)(ctx->rx_buf) = r; in spi_bitbang_transceive()
211 *(uint8_t *)(ctx->rx_buf) = r; in spi_bitbang_transceive()
218 spi_context_update_tx(ctx, data->dfs, 1); in spi_bitbang_transceive()
219 spi_context_update_rx(ctx, data->dfs, 1); in spi_bitbang_transceive()
236 return -ENOTSUP; in spi_bitbang_transceive_async()
243 struct spi_bitbang_data *data = dev->data; in spi_bitbang_release()
244 struct spi_context *ctx = &data->ctx; in spi_bitbang_release()
260 const struct spi_bitbang_config *config = dev->config; in spi_bitbang_init()
261 struct spi_bitbang_data *data = dev->data; in spi_bitbang_init()
264 if (!gpio_is_ready_dt(&config->clk_gpio)) { in spi_bitbang_init()
266 return -ENODEV; in spi_bitbang_init()
268 rc = gpio_pin_configure_dt(&config->clk_gpio, GPIO_OUTPUT_INACTIVE); in spi_bitbang_init()
274 if (config->mosi_gpio.port != NULL) { in spi_bitbang_init()
275 if (!gpio_is_ready_dt(&config->mosi_gpio)) { in spi_bitbang_init()
277 return -ENODEV; in spi_bitbang_init()
279 rc = gpio_pin_configure_dt(&config->mosi_gpio, in spi_bitbang_init()
287 if (config->miso_gpio.port != NULL) { in spi_bitbang_init()
288 if (!gpio_is_ready_dt(&config->miso_gpio)) { in spi_bitbang_init()
290 return -ENODEV; in spi_bitbang_init()
294 rc = gpio_pin_configure_dt(&config->miso_gpio, GPIO_INPUT); in spi_bitbang_init()
301 rc = spi_context_cs_configure_all(&data->ctx); in spi_bitbang_init()