mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
spi: read
This commit is contained in:
parent
e04a3cf132
commit
0fbe31e00b
2 changed files with 40 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue