Skip to content

Commit f91d16b

Browse files
committed
implement more commands
1 parent f552aef commit f91d16b

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

main.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ static void command_loop(void)
167167
(1 << S_CMD_S_PIN_STATE)|
168168
(1 << S_CMD_R_BYTE)|
169169
(1 << S_CMD_O_WRITEB)|
170-
(1 << S_CMD_O_INIT)
170+
(1 << S_CMD_O_INIT)|
171+
(1 << S_CMD_O_EXEC)
171172
};
172173

173174
sendbyte_blocking(S_ACK);
@@ -347,6 +348,43 @@ static void command_loop(void)
347348
sendbyte_blocking(S_ACK);
348349
break;
349350
}
351+
case S_CMD_O_EXEC:
352+
{
353+
if (opbuf_pos == 0) {
354+
sendbyte_blocking(S_NAK);
355+
break;
356+
}
357+
358+
// Send ACK before handling the operation buffer
359+
sendbyte_blocking(S_ACK);
360+
361+
// Handle the operation buffer
362+
uint32_t i = 0;
363+
while (i < opbuf_pos) {
364+
uint8_t cmd = opbuf[i++];
365+
uint32_t addr;
366+
uint8_t byte;
367+
368+
switch (cmd) {
369+
case S_CMD_O_WRITEB:
370+
memcpy(&addr, &opbuf[i], 3);
371+
i += 3;
372+
byte = opbuf[i++];
373+
cs_select(SPI_CS);
374+
spi_write_blocking(SPI_IF, (uint8_t*)&addr, 3); // Send address
375+
spi_write_blocking(SPI_IF, &byte, 1); // Send data
376+
cs_deselect(SPI_CS);
377+
break;
378+
default:
379+
sendbyte_blocking(S_NAK);
380+
break;
381+
}
382+
}
383+
384+
// Send ACK after handling the operation buffer
385+
sendbyte_blocking(S_ACK);
386+
break;
387+
}
350388
default:
351389
sendbyte_blocking(S_NAK);
352390
break;

0 commit comments

Comments
 (0)