drivers: spi_bitbang: Increase supported word size to 32 bits
This change introduces support for words up to 32 bits size to the spi_bitbang driver Signed-off-by: Michal Morsisko <morsisko@gmail.com>
This commit is contained in:
parent
c8c0c294b1
commit
e87e0542b8
1 changed files with 18 additions and 4 deletions
|
@ -44,13 +44,19 @@ static int spi_bitbang_configure(const struct spi_bitbang_config *info,
|
||||||
|
|
||||||
const int bits = SPI_WORD_SIZE_GET(config->operation);
|
const int bits = SPI_WORD_SIZE_GET(config->operation);
|
||||||
|
|
||||||
if (bits > 16) {
|
if (bits > 32) {
|
||||||
LOG_ERR("Word sizes > 16 bits not supported");
|
LOG_ERR("Word sizes > 32 bits not supported");
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
data->bits = bits;
|
data->bits = bits;
|
||||||
data->dfs = ((data->bits - 1) / 8) + 1;
|
data->dfs = ((data->bits - 1) / 8) + 1;
|
||||||
|
|
||||||
|
/* As there is no uint24_t, it is assumed uint32_t will be used as the buffer base type. */
|
||||||
|
if (data->dfs == 3) {
|
||||||
|
data->dfs = 4;
|
||||||
|
}
|
||||||
|
|
||||||
if (config->frequency > 0) {
|
if (config->frequency > 0) {
|
||||||
/* convert freq to period, the extra /2 is due to waiting
|
/* convert freq to period, the extra /2 is due to waiting
|
||||||
* twice in each clock cycle. The '2000' is an upscale factor.
|
* twice in each clock cycle. The '2000' is an upscale factor.
|
||||||
|
@ -147,10 +153,14 @@ static int spi_bitbang_transceive(const struct device *dev,
|
||||||
const uint32_t wait_us = data->wait_us;
|
const uint32_t wait_us = data->wait_us;
|
||||||
|
|
||||||
while (spi_context_tx_buf_on(ctx) || spi_context_rx_buf_on(ctx)) {
|
while (spi_context_tx_buf_on(ctx) || spi_context_rx_buf_on(ctx)) {
|
||||||
uint16_t w = 0;
|
uint32_t w = 0;
|
||||||
|
|
||||||
if (ctx->tx_len) {
|
if (ctx->tx_len) {
|
||||||
switch (data->dfs) {
|
switch (data->dfs) {
|
||||||
|
case 4:
|
||||||
|
case 3:
|
||||||
|
w = *(uint32_t *)(ctx->tx_buf);
|
||||||
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
w = *(uint16_t *)(ctx->tx_buf);
|
w = *(uint16_t *)(ctx->tx_buf);
|
||||||
break;
|
break;
|
||||||
|
@ -160,7 +170,7 @@ static int spi_bitbang_transceive(const struct device *dev,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t r = 0;
|
uint32_t r = 0;
|
||||||
uint8_t i = 0;
|
uint8_t i = 0;
|
||||||
int b = 0;
|
int b = 0;
|
||||||
bool do_read = false;
|
bool do_read = false;
|
||||||
|
@ -209,6 +219,10 @@ static int spi_bitbang_transceive(const struct device *dev,
|
||||||
|
|
||||||
if (spi_context_rx_buf_on(ctx)) {
|
if (spi_context_rx_buf_on(ctx)) {
|
||||||
switch (data->dfs) {
|
switch (data->dfs) {
|
||||||
|
case 4:
|
||||||
|
case 3:
|
||||||
|
*(uint32_t *)(ctx->rx_buf) = r;
|
||||||
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
*(uint16_t *)(ctx->rx_buf) = r;
|
*(uint16_t *)(ctx->rx_buf) = r;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue