unify SPI helper APIs

This commit is contained in:
Sergio R. Caprile committed 2026-04-01 14:11:35 -03:00
1 parent b1c2ffe1a0
commit d4212ab282
18 files changed
+75 -104

No files matched your search

+3 -7
View File
@@ -4,16 +4,12 @@
static void w5100_txn(struct mg_tcpip_spi *s, uint16_t addr, bool wr, void *buf,
size_t len) {
size_t i;
uint8_t *p = (uint8_t *) buf;
uint8_t control = wr ? 0xF0 : 0x0F;
uint8_t cmd[] = {control, (uint8_t) (addr >> 8), (uint8_t) (addr & 255)};
s->begin(s->spi);
for (i = 0; i < sizeof(cmd); i++) s->txn(s->spi, cmd[i]);
for (i = 0; i < len; i++) {
uint8_t r = s->txn(s->spi, p[i]);
if (!wr) p[i] = r;
}
s->txn(s->spi, cmd, NULL, sizeof(cmd));
if (wr) s->txn(s->spi, (uint8_t *) buf, NULL, len);
if (!wr) s->txn(s->spi, NULL, (uint8_t *) buf, len);
s->end(s->spi);
}