1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

spi: read

This commit is contained in:
Andy Green 2024-10-31 15:26:27 +00:00
parent e04a3cf132
commit 0fbe31e00b
2 changed files with 40 additions and 0 deletions

View file

@ -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

View file

@ -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;
}