]> git.droids-corp.org - fpv.git/commitdiff
mainboard: do not start i2c polling by default
authorOlivier Matz <zer0@droids-corp.org>
Thu, 18 Sep 2014 17:54:27 +0000 (19:54 +0200)
committerOlivier Matz <zer0@droids-corp.org>
Thu, 18 Sep 2014 17:54:27 +0000 (19:54 +0200)
mainboard/commands.c
mainboard/i2c_protocol.c
mainboard/i2c_protocol.h

index 558e0b653541453ca3cb76e35a687fb17cba68e3..96f719a42c6d03c99052e47ce2a3aea7c5647a78 100644 (file)
@@ -2327,6 +2327,37 @@ const parse_inst_t PROGMEM cmd_dump_i2c = {
 };
 
 
+/* ************* */
+
+struct cmd_i2c_enable_result {
+       fixed_string_t cmd;
+};
+
+static void cmd_i2c_enable_parsed(void *parsed_result, void *data)
+{
+       (void)parsed_result;
+       (void)data;
+
+       i2c_protocol_enable(1);
+}
+
+const char PROGMEM str_i2c_enable[] = "i2c_enable";
+const parse_token_string_t PROGMEM cmd_i2c_enable_cmd =
+       TOKEN_STRING_INITIALIZER(struct cmd_i2c_enable_result, cmd,
+                                str_i2c_enable);
+
+const char PROGMEM help_i2c_enable[] = "i2c_enable";
+const parse_inst_t PROGMEM cmd_i2c_enable = {
+       .f = cmd_i2c_enable_parsed,  /* function to call */
+       .data = NULL,      /* 2nd arg of func */
+       .help_str = help_i2c_enable,
+       .tokens = {        /* token list, NULL terminated */
+               (PGM_P)&cmd_i2c_enable_cmd,
+               NULL,
+       },
+};
+
+
 /* ************* */
 
 /* in progmem */
@@ -2385,5 +2416,6 @@ const parse_ctx_t PROGMEM main_ctx[] = {
        &cmd_eeprom_add2,
        &cmd_eeprom_list,
        &cmd_dump_i2c,
+       &cmd_i2c_enable,
        NULL,
 };
index fe58b7cc952af074ff4d6d5242e1c272d1cc02e0..ceff4c9f2e20887389e414e9f66a4393c8a5d088 100644 (file)
@@ -70,6 +70,8 @@ uint8_t command_buf[I2C_SEND_BUFFER_SIZE];
 volatile int8_t command_dest=-1;
 volatile uint8_t command_size=0;
 
+static uint8_t i2c_enabled = 0;
+
 #define I2C_ERROR(args...) do {                                                \
                if (error_log < I2C_MAX_LOG) {                          \
                        ERROR(E_USER_I2C_PROTO, args);                  \
@@ -119,6 +121,9 @@ static void imuboard_beep_cb(struct callout_mgr *cm, struct callout *tim, void *
        (void)tim;
        (void)arg;
 
+       if (i2c_enabled == 0)
+               goto reschedule;
+
        if ((imuboard_status.flags & I2C_IMUBOARD_STATUS_SDCARD_OK) == 0) {
                beep(0, 1, 1);
                goto reschedule;
@@ -161,6 +166,9 @@ static void i2c_poll_slaves(struct callout_mgr *cm, struct callout *tim, void *a
                LED2_TOGGLE();
 #endif
 
+       if (i2c_enabled == 0)
+               goto reschedule;
+
        /* already running */
        IRQ_LOCK(flags);
        if (running_op != OP_READY) {
@@ -357,6 +365,11 @@ int8_t i2c_led_control(uint8_t addr, uint8_t led, uint8_t state)
        return i2c_send_command(addr, (uint8_t*)&buf, sizeof(buf));
 }
 
+void i2c_protocol_enable(uint8_t enable)
+{
+       i2c_enabled = enable;
+}
+
 void i2c_protocol_init(void)
 {
        callout_init(&i2c_timer, i2c_poll_slaves, NULL, I2C_PRIO);
index 66d5831c7f733f3644cbb9728244cb9e17cedd6d..964f306c678003788a17c4900fbb8277c27eeb98 100644 (file)
@@ -42,4 +42,7 @@ int8_t i2c_led_control(uint8_t addr, uint8_t led, uint8_t state);
  * the i2c timer. */
 struct i2c_ans_imuboard_status imuboard_status;
 
+/* enable polling of slaves */
+void i2c_protocol_enable(uint8_t enable);
+
 #endif