Skip to content

Commit 8d0e780

Browse files
author
Sean Cross
committed
include: Add GPIO header file
This adds a header file to describe Fernvale's unique GPIO scheme.
1 parent 4658e53 commit 8d0e780

File tree

4 files changed

+772
-0
lines changed

4 files changed

+772
-0
lines changed

cmd-spi.c

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include <string.h>
2+
#include "bionic.h"
3+
#include "serial.h"
4+
#include "printf.h"
5+
#include "spi.h"
6+
7+
#define SPI_CSEL 0
8+
9+
int cmd_spi(int argc, char **argv)
10+
{
11+
uint32_t recv_bytes_count;
12+
uint8_t xmit_bytes[argc - 1];
13+
int i;
14+
15+
if (argc == 1 && !_strcasecmp(argv[0], "loop")) {
16+
printf("Repeatedly sending 0x9f -- id\n");
17+
while(1) {
18+
uint8_t out[1] = {0x9f};
19+
uint8_t in[3];
20+
spi_cmd_txrx(0, sizeof(out), sizeof(in), out, in);
21+
printf("ID: ");
22+
serial_print_hex(in, sizeof(in));
23+
}
24+
}
25+
26+
if (argc < 2) {
27+
printf("Send SPI bytes out and read the response.\n");
28+
printf("Usage: spi [count] [byte 1] [byte 2] ...\n");
29+
printf(" Where \"count\" is the number of bytes to expect"
30+
" in response.\n");
31+
return 1;
32+
}
33+
34+
recv_bytes_count = _strtoul(argv[0], NULL, 0);
35+
uint8_t recv_bytes[recv_bytes_count];
36+
37+
for (i = 1; i < argc; i++)
38+
xmit_bytes[i - 1] = _strtoul(argv[i], NULL, 0);
39+
40+
printf("Transmitting %d bytes and expecting a response with %d bytes:\n",
41+
sizeof(xmit_bytes), sizeof(recv_bytes));
42+
serial_print_hex(xmit_bytes, sizeof(xmit_bytes));
43+
44+
spi_cmd_txrx(SPI_CSEL, sizeof(xmit_bytes), sizeof(recv_bytes),
45+
xmit_bytes, recv_bytes);
46+
47+
printf("Response:\n");
48+
serial_print_hex(recv_bytes, sizeof(recv_bytes));
49+
50+
return 0;
51+
}

0 commit comments

Comments
 (0)