Skip to content

Commit

Permalink
posix/pios_sys: support specifying gyro interrupt line
Browse files Browse the repository at this point in the history
  • Loading branch information
mlyle committed May 25, 2017
1 parent e725241 commit b9c7a36
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions flight/PiOS/posix/pios_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ static bool debug_fpe=false;
bool are_realtime = false;

#ifdef PIOS_INCLUDE_SPI
#include <pios_dio.h>

int num_spi = 0;
uintptr_t spi_devs[16];

dio_tag_t gyro_int = NULL;

#include "pios_spi_posix_priv.h"
#include "pios_ms5611_priv.h"
#include "pios_bmm150_priv.h"
Expand All @@ -97,7 +101,7 @@ uintptr_t external_i2c_adapter_id;
#endif

static void Usage(char *cmdName) {
printf( "usage: %s [-f] [-r] [-m orientation] [-s spibase] [-d drvname:bus:id]\n"
printf( "usage: %s [-f] [-r] [-g num] [-m orientation] [-s spibase] [-d drvname:bus:id]\n"
"\t\t[-l logfile] [-I i2cdev] [-i drvname:bus]"
"\n"
"\t-f\tEnables floating point exception trapping mode\n"
Expand All @@ -108,6 +112,7 @@ static void Usage(char *cmdName) {
"\t\t\tAvailable drivers: gps msp lighttelemetry telemetry\n"
#endif
#ifdef PIOS_INCLUDE_SPI
"\t-g gpionum\tSpecifies the gyro interrupt is on gpionum\n"
"\t-s spibase\tConfigures a SPI interface on the base path\n"
"\t-d drvname:bus:id\tStarts driver drvname on bus/id\n"
"\t\t\tAvailable drivers: bmm150 bmx055 flyingpio ms5611\n"
Expand Down Expand Up @@ -316,6 +321,8 @@ static int handle_device(const char *optarg) {
bmx055_cfg = PIOS_malloc(sizeof(*bmx055_cfg));
bzero(bmx055_cfg, sizeof(*bmx055_cfg));

bmx055_cfg->int_pin = gyro_int;

int ret = PIOS_BMX055_SPI_Init(&dev, spi_devs[bus_num], dev_num, dev_num+1, bmx055_cfg);

if (ret) goto fail;
Expand Down Expand Up @@ -429,7 +436,7 @@ void PIOS_SYS_Args(int argc, char *argv[]) {

bool first_arg = true;

while ((opt = getopt(argc, argv, "frl:s:d:S:I:i:")) != -1) {
while ((opt = getopt(argc, argv, "frg:l:s:d:S:I:i:")) != -1) {
switch (opt) {
case 'f':
debug_fpe = true;
Expand Down Expand Up @@ -511,6 +518,29 @@ void PIOS_SYS_Args(int argc, char *argv[]) {
break;
#endif
#ifdef PIOS_INCLUDE_SPI
case 'g':
{
if (!first_arg) {
printf("Gyro int must be before hw\n");
exit(1);
}

char *endptr;

int num;

num = strtol(optarg, &endptr, 10);

if (!endptr || (*endptr != '\0')) {
printf("Invalid gyro int pin\n");
exit(1);
}

gyro_int = DIO_MAKE_TAG(num);

break;
}

case 'd':
if (handle_device(optarg)) {
printf("Couldn't init device\n");
Expand Down

0 comments on commit b9c7a36

Please sign in to comment.