Skip to content

Commit 42ab124

Browse files
committed
posix/pios_sys: support specifying gyro interrupt line
1 parent 55f51b8 commit 42ab124

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

flight/PiOS/posix/pios_sys.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,13 @@ static bool debug_fpe=false;
7171
bool are_realtime = false;
7272

7373
#ifdef PIOS_INCLUDE_SPI
74+
#include <pios_dio.h>
75+
7476
int num_spi = 0;
7577
uintptr_t spi_devs[16];
7678

79+
dio_tag_t gyro_int = NULL;
80+
7781
#include "pios_spi_posix_priv.h"
7882
#include "pios_ms5611_priv.h"
7983
#include "pios_bmm150_priv.h"
@@ -94,7 +98,7 @@ uintptr_t external_i2c_adapter_id;
9498
#endif
9599

96100
static void Usage(char *cmdName) {
97-
printf( "usage: %s [-f] [-r] [-m orientation] [-s spibase] [-d drvname:bus:id]\n"
101+
printf( "usage: %s [-f] [-r] [-g num] [-m orientation] [-s spibase] [-d drvname:bus:id]\n"
98102
"\t\t[-l logfile] [-I i2cdev] [-i drvname:bus]"
99103
"\n"
100104
"\t-f\tEnables floating point exception trapping mode\n"
@@ -105,6 +109,7 @@ static void Usage(char *cmdName) {
105109
"\t\t\tAvailable drivers: gps msp lighttelemetry telemetry\n"
106110
#endif
107111
#ifdef PIOS_INCLUDE_SPI
112+
"\t-g gpionum\tSpecifies the gyro interrupt is on gpionum\n"
108113
"\t-s spibase\tConfigures a SPI interface on the base path\n"
109114
"\t-d drvname:bus:id\tStarts driver drvname on bus/id\n"
110115
"\t\t\tAvailable drivers: bmm150 bmx055 flyingpio ms5611\n"
@@ -309,6 +314,8 @@ static int handle_device(const char *optarg) {
309314
bmx055_cfg = PIOS_malloc(sizeof(*bmx055_cfg));
310315
bzero(bmx055_cfg, sizeof(*bmx055_cfg));
311316

317+
bmx055_cfg->int_pin = gyro_int;
318+
312319
int ret = PIOS_BMX055_SPI_Init(&dev, spi_devs[bus_num], dev_num, dev_num+1, bmx055_cfg);
313320

314321
if (ret) goto fail;
@@ -422,7 +429,7 @@ void PIOS_SYS_Args(int argc, char *argv[]) {
422429

423430
bool first_arg = true;
424431

425-
while ((opt = getopt(argc, argv, "frl:s:d:S:I:i:")) != -1) {
432+
while ((opt = getopt(argc, argv, "frg:l:s:d:S:I:i:")) != -1) {
426433
switch (opt) {
427434
case 'f':
428435
debug_fpe = true;
@@ -504,6 +511,29 @@ void PIOS_SYS_Args(int argc, char *argv[]) {
504511
break;
505512
#endif
506513
#ifdef PIOS_INCLUDE_SPI
514+
case 'g':
515+
{
516+
if (!first_arg) {
517+
printf("Gyro int must be before hw\n");
518+
exit(1);
519+
}
520+
521+
char *endptr;
522+
523+
int num;
524+
525+
num = strtol(optarg, &endptr, 10);
526+
527+
if (!endptr || (*endptr != '\0')) {
528+
printf("Invalid gyro int pin\n");
529+
exit(1);
530+
}
531+
532+
gyro_int = DIO_MAKE_TAG(num);
533+
534+
break;
535+
}
536+
507537
case 'd':
508538
if (handle_device(optarg)) {
509539
printf("Couldn't init device\n");

0 commit comments

Comments
 (0)