From: Olivier Matz Date: Thu, 18 Sep 2014 17:54:27 +0000 (+0200) Subject: mainboard: do not start i2c polling by default X-Git-Url: http://git.droids-corp.org/?p=fpv.git;a=commitdiff_plain;h=d55f19670341d1362595b0ae1ff24d4615050153 mainboard: do not start i2c polling by default --- diff --git a/mainboard/commands.c b/mainboard/commands.c index 558e0b6..96f719a 100644 --- a/mainboard/commands.c +++ b/mainboard/commands.c @@ -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, }; diff --git a/mainboard/i2c_protocol.c b/mainboard/i2c_protocol.c index fe58b7c..ceff4c9 100644 --- a/mainboard/i2c_protocol.c +++ b/mainboard/i2c_protocol.c @@ -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); diff --git a/mainboard/i2c_protocol.h b/mainboard/i2c_protocol.h index 66d5831..964f306 100644 --- a/mainboard/i2c_protocol.h +++ b/mainboard/i2c_protocol.h @@ -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