Skip to content

Commit

Permalink
Mode support for spidriver2
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbowman committed Mar 31, 2021
1 parent c2189d3 commit 2c537e4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions c/common/spidriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ void spi_getstatus(SPIDriver *sd)
&sd->cs,
&sd->ccitt_crc
);
sd->mode = 0;
}

void spi_sel(SPIDriver *sd)
Expand Down Expand Up @@ -308,6 +309,15 @@ void spi_setb(SPIDriver *sd, char v)
sd->b = v;
}

void spi_setmode(SPIDriver *sd, char m)
{
if (strcmp(sd->model, "spidriver2") == 0) {
char cmd[2] = {'m', m};
writeToSerialPort(sd->port, cmd, 2);
sd->mode = m;
}
}

void spi_write(SPIDriver *sd, const char bytes[], size_t nn)
{
size_t i;
Expand Down Expand Up @@ -416,6 +426,12 @@ int spi_commands(SPIDriver *sd, int argc, char *argv[])
spi_setb(sd, token[0]);
break;

case 'm':
token = argv[++i];
if (token != NULL)
spi_setmode(sd, token[0]);
break;

default:
badcommand:
fprintf(stderr, "Bad command '%s'\n", token);
Expand All @@ -429,6 +445,7 @@ int spi_commands(SPIDriver *sd, int argc, char *argv[])
fprintf(stderr, " r N read N bytes from SPI\n");
fprintf(stderr, " a 0/1 Set A line\n");
fprintf(stderr, " b 0/1 Set B line\n");
fprintf(stderr, " m 0-3 Set SPI mode (spidriver2 only)\n");
fprintf(stderr, "\n");

return 1;
Expand Down
1 change: 1 addition & 0 deletions c/common/spidriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ typedef struct {
current_ma, // device current (mA)
temp_celsius; // temperature (C)
unsigned int a, b, cs; // state of three output lines
unsigned int mode; // SPI mode
unsigned int
ccitt_crc, // Hardware CCITT CRC
e_ccitt_crc; // Host CCITT CRC, should match
Expand Down

0 comments on commit 2c537e4

Please sign in to comment.