Skip to content

Commit

Permalink
spi: read
Browse files Browse the repository at this point in the history
  • Loading branch information
lws-team committed Nov 3, 2024
1 parent e04a3cf commit 0fbe31e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/libwebsockets/lws-spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,8 @@ typedef struct lws_spi_ops {
LWS_VISIBLE LWS_EXTERN int
lws_spi_table_issue(const lws_spi_ops_t *spi_ops, uint32_t flags, const uint8_t *p, size_t len);

LWS_VISIBLE LWS_EXTERN int
lws_spi_readback(const lws_spi_ops_t *spi_ops, uint32_t flags,
const uint8_t *p, size_t len, uint8_t *rb, size_t rb_len);

#endif
36 changes: 36 additions & 0 deletions lib/drivers/spi/lws-spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,39 @@ lws_spi_table_issue(const lws_spi_ops_t *spi_ops, uint32_t flags,

return 0;
}

int
lws_spi_readback(const lws_spi_ops_t *spi_ops, uint32_t flags,
const uint8_t *p, size_t len, uint8_t *rb, size_t rb_len)
{
lws_spi_desc_t desc;
size_t pos = 0;

memset(&desc, 0, sizeof(desc));
desc.count_cmd = 1;
desc.flags = flags;

while (pos < len) {

desc.count_write = p[pos++];

desc.src = (uint8_t *)&p[pos++];
if (desc.count_write)
desc.data = (uint8_t *)&p[pos];
else
desc.data = NULL;

desc.dest = rb;
desc.count_read = rb_len;

if (spi_ops->queue(spi_ops, &desc) != ESP_OK) {
lwsl_err("%s: unable to queue\n", __func__);
return 1;
}

pos += desc.count_write;
}

return 0;
}

0 comments on commit 0fbe31e

Please sign in to comment.