spi: Get basic SPI commands working

This commit is contained in:
Sean Cross 2014-09-12 16:46:11 +08:00
parent 8d0e780508
commit 43a1517aec
8 changed files with 118 additions and 77 deletions

View file

@ -4,30 +4,30 @@
#include "printf.h"
#include "spi.h"
#define SPI_CSEL 0
int cmd_spi(int argc, char **argv)
{
uint32_t recv_bytes_count;
uint8_t xmit_bytes[argc - 1];
int i;
if (argc == 1 && !_strcasecmp(argv[0], "loop")) {
printf("Repeatedly sending 0x9f -- id\n");
while(1) {
uint8_t out[1] = {0x9f};
uint8_t in[3];
spi_cmd_txrx(0, sizeof(out), sizeof(in), out, in);
printf("ID: ");
serial_print_hex(in, sizeof(in));
}
if (argc > 0 && !_strcasecmp(argv[0], "id")) {
uint8_t out[1] = {0x9f};
uint8_t in[3];
spi_cmd_txrx(sizeof(out), sizeof(in), out, in);
printf("ID: %02x %02x %02x\n", in[0], in[1], in[2]);
return 0;
}
if (argc < 2) {
printf("Send SPI bytes out and read the response.\n");
printf("Usage: spi [count] [byte 1] [byte 2] ...\n");
printf(" Where \"count\" is the number of bytes to expect"
" in response.\n");
printf("Usage:\n");
printf(" spi [count] [byte 1] [byte 2] ...\n");
printf(" Where \"count\" is the number of bytes to expect"
" in response.\n");
printf(" spi id -- get device id\n");
return 1;
}
@ -41,7 +41,7 @@ int cmd_spi(int argc, char **argv)
sizeof(xmit_bytes), sizeof(recv_bytes));
serial_print_hex(xmit_bytes, sizeof(xmit_bytes));
spi_cmd_txrx(SPI_CSEL, sizeof(xmit_bytes), sizeof(recv_bytes),
spi_cmd_txrx(sizeof(xmit_bytes), sizeof(recv_bytes),
xmit_bytes, recv_bytes);
printf("Response:\n");