File tree Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Expand file tree Collapse file tree 1 file changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -202,17 +202,28 @@ static void command_loop(void)
202
202
uint8_t tx_buffer [MAX_BUFFER_SIZE ]; // Buffer for transmit data
203
203
uint8_t rx_buffer [MAX_BUFFER_SIZE ]; // Buffer for receive data
204
204
205
- // Handle send operation in chunks
206
- while (slen > 0 ) {
207
- uint32_t chunk_size = ( slen < MAX_BUFFER_SIZE ) ? slen : MAX_BUFFER_SIZE ;
208
- readbytes_blocking ( tx_buffer , chunk_size );
205
+ // Read data to be sent (if slen > 0)
206
+ if (slen > 0 ) {
207
+ readbytes_blocking ( tx_buffer , slen ) ;
208
+ }
209
209
210
- cs_select (SPI_CS );
211
- spi_write_blocking (SPI_IF , tx_buffer , chunk_size );
212
- cs_deselect (SPI_CS );
210
+ // Perform SPI operation
211
+ cs_select (SPI_CS );
212
+ if (slen > 0 ) {
213
+ spi_write_blocking (SPI_IF , tx_buffer , slen );
214
+ }
215
+ if (rlen > 0 && rlen < MAX_BUFFER_SIZE ) {
216
+ spi_read_blocking (SPI_IF , 0 , rx_buffer , rlen );
217
+ // Send ACK followed by received data
218
+ sendbyte_blocking (S_ACK );
219
+ if (rlen > 0 ) {
220
+ sendbytes_blocking (rx_buffer , rlen );
221
+ }
213
222
214
- slen -= chunk_size ;
223
+ cs_deselect (SPI_CS );
224
+ break ;
215
225
}
226
+ cs_deselect (SPI_CS );
216
227
217
228
// Send ACK after handling slen (before reading)
218
229
sendbyte_blocking (S_ACK );
You can’t perform that action at this time.
0 commit comments