apache-mynewt-bot removed a comment on pull request #2499: URL: https://github.com/apache/mynewt-core/pull/2499#issuecomment-786554438
<!-- style-bot --> ## Style check summary ### Our coding style is [here!](https://github.com/apache/mynewt-core/blob/master/CODING_STANDARDS.md) #### hw/drivers/sensors/bma253/src/bma253.c <details> ```diff @@ -577,586 +573,16 @@ sensor_itf_unlock(itf); #endif - if (0 == rc) { - if (bma253->bus_rw_mon) { - BMA253_LOG_DEBUG("bus_write@0x%02X:%02X\n", addr, data); - } - } else { - BMA253_LOG_ERROR("bus_write@0x%02X:%02X rc:%d\n", addr, data, rc); - } + if (0 == rc) { + if (bma253->bus_rw_mon) { + BMA253_LOG_DEBUG("bus_write@0x%02X:%02X\n", addr, data); + } + } else { + BMA253_LOG_ERROR("bus_write@0x%02X:%02X rc:%d\n", addr, data, rc); + } if (!rc) { switch (bma253->power) { - case BMA253_POWER_MODE_SUSPEND: - case BMA253_POWER_MODE_DEEP_SUSPEND: - case BMA253_POWER_MODE_LPM_1: - /* 450us is enough */ - delay_msec(1); - break; - default: - /* this is a blocking delay */ - os_cputime_delay_usecs(2); - break; - } - } else { - /* 450us is enough */ - delay_msec(1); - } - - return rc; -} - - int -bma253_get_chip_id(const struct bma253 * bma253, - uint8_t * chip_id) -{ - return get_register((struct bma253 *)bma253, REG_ADDR_BGW_CHIPID, chip_id); -} - -static void -compute_accel_data( - const struct bma253 *bma253, - struct accel_data *accel_data, - uint8_t data_len, - const uint8_t *raw_data, - float accel_scale) -{ - int16_t raw_accel; - uint8_t model_shift = BMA253_ACCEL_BIT_SHIFT; - uint8_t i; - - BMA253_UNUSED_VAR(bma253); - - for (i = 0; i < data_len; i++) { - raw_accel = (int16_t)(raw_data[(i<<1)] & BMA253_DATA_LSB_MASK) | - (int16_t)(raw_data[(i<<1) + 1] << 8); - raw_accel >>= model_shift; - - accel_data[i].accel_g = (float)raw_accel * accel_scale; - accel_data[i].new_data = raw_data[(i<<1)] & 0x01; - } -} - - - static int -get_accel_scale( - const struct bma253 *bma253, - enum bma253_g_range g_range, - float *accel_scale) -{ - BMA253_UNUSED_VAR(bma253); - - switch (g_range) { - case BMA253_G_RANGE_2: - *accel_scale = BMA253_G_SCALE_2; - break; - case BMA253_G_RANGE_4: - *accel_scale = BMA253_G_SCALE_4; - break; - case BMA253_G_RANGE_8: - *accel_scale = BMA253_G_SCALE_8; - break; - case BMA253_G_RANGE_16: - *accel_scale = BMA253_G_SCALE_16; - break; - default: - return SYS_EINVAL; - } - - return 0; -} - - -int -bma253_get_accel(const struct bma253 * bma253, - enum bma253_g_range g_range, - enum axis axis, - struct accel_data * accel_data) -{ - float accel_scale; - uint8_t base_addr; - uint8_t data[6] = ""; - uint8_t len = 2; - int rc; - - rc = get_accel_scale(bma253, g_range, &accel_scale); - if (0 != rc) { - return rc; - } - - switch (axis) { - case AXIS_ALL: - base_addr = REG_ADDR_ACCD_X_LSB; - len = 6; - break; - case AXIS_X: - base_addr = REG_ADDR_ACCD_X_LSB; - break; - case AXIS_Y: - base_addr = REG_ADDR_ACCD_Y_LSB; - break; - case AXIS_Z: - base_addr = REG_ADDR_ACCD_Z_LSB; - break; - default: - return SYS_EINVAL; - } - - rc = get_registers((struct bma253 *)bma253, base_addr, - data, len); - if (rc != 0) { - return rc; - } - - compute_accel_data(bma253, accel_data, (len >> 1), data, accel_scale); - - return 0; -} - - -/* - * @return the time (in usec) between two samples - **/ -static -int bma253_get_sample_interval_us( - const struct bma253 * bma253) -{ - int sample_interval; - sample_interval = 500 << (BMA253_FILTER_BANDWIDTH_1000_HZ - bma253->bandwidth_curr); - - return sample_interval; -} - -int -bma253_get_temp(const struct bma253 * bma253, - float * temp_c) -{ - uint8_t data; - int rc; - - rc = get_register((struct bma253 *)bma253, REG_ADDR_ACCD_TEMP, &data); - if (rc != 0) { - return rc; - } - - *temp_c = (float)(int8_t)data * 0.5 + 23.0; - - return 0; -} - - - void -quad_to_axis_trigger(struct axis_trigger * axis_trigger, - uint8_t quad_bits, - const char * name_bits) -{ - axis_trigger->sign = (quad_bits >> 3) & 0x01; - switch (quad_bits & 0x07) { - case 0x01: - axis_trigger->axis = AXIS_X; - axis_trigger->axis_known = true; - BMA253_LOG_INFO("tap from %c X axis\n", axis_trigger->sign ? '+' : '-'); - break; - case (1 << 1): - axis_trigger->axis = AXIS_Y; - axis_trigger->axis_known = true; - BMA253_LOG_INFO("tap from %c Y axis\n", axis_trigger->sign ? '+' : '-'); - break; - case (1 << 2): - axis_trigger->axis = AXIS_Z; - axis_trigger->axis_known = true; - BMA253_LOG_INFO("tap from %c Z axis\n", axis_trigger->sign ? '+' : '-'); - break; - default: - BMA253_LOG_INFO("unknown %s quad bits 0x%02X\n", - name_bits, quad_bits); - axis_trigger->axis = -1; - axis_trigger->axis_known = false; - break; - } -} - -int -bma253_get_high_g_int_status(const struct bma253 * bma253, - uint8_t * int_status) -{ - int rc = 0; - - rc = get_registers((struct bma253 *)bma253, REG_ADDR_INT_STATUS_3, - int_status, 4); - - return rc; -} - - -int -bma253_get_int_status(const struct bma253 * bma253, - bma253_int_stat_t * int_status) -{ - int rc; - - rc = get_registers((struct bma253 *)bma253, REG_ADDR_INT_STATUS_0, - (uint8_t*)int_status, 4); - - if (rc != 0) { - return rc; - } - - return 0; -} - -int -bma253_get_fifo_status(const struct bma253 * bma253, - bool * overrun, - uint8_t * frame_counter) -{ - uint8_t data; - int rc; - - ((struct bma253 *)bma253)->bus_rw_mon = 0; - rc = get_register((struct bma253 *)bma253, REG_ADDR_FIFO_STATUS, &data); - ((struct bma253 *)bma253)->bus_rw_mon = 1; - if (rc != 0) { - return rc; - } - - *overrun = data & 0x80; - *frame_counter = data & 0x7F; - - return 0; -} - - -int -bma253_get_g_range(const struct bma253 * bma253, - enum bma253_g_range * g_range) -{ - uint8_t data; - int rc; - - rc = get_register((struct bma253 *)bma253, REG_ADDR_PMU_RANGE, &data); - if (rc != 0) { - return rc; - } - - switch (data & 0x0F) { - default: - BMA253_LOG_ERROR("unknown PMU_RANGE reg value 0x%02X\n", data); - *g_range = BMA253_G_RANGE_16; - break; - case 0x03: - *g_range = BMA253_G_RANGE_2; - break; - case 0x05: - *g_range = BMA253_G_RANGE_4; - break; - case 0x08: - *g_range = BMA253_G_RANGE_8; - break; - case 0x0C: - *g_range = BMA253_G_RANGE_16; - break; - } - - return 0; -} - -int -bma253_set_g_range(const struct bma253 * bma253, - enum bma253_g_range g_range) -{ - uint8_t data; - - switch (g_range) { - case BMA253_G_RANGE_2: - data = 0x03; - break; - case BMA253_G_RANGE_4: - data = 0x05; - break; - case BMA253_G_RANGE_8: - data = 0x08; - break; - case BMA253_G_RANGE_16: - data = 0x0C; - break; - default: - return SYS_EINVAL; - } - - return set_register((struct bma253 *)bma253, REG_ADDR_PMU_RANGE, data); -} - -int -bma253_get_filter_bandwidth(const struct bma253 * bma253, - enum bma253_filter_bandwidth * filter_bandwidth) -{ - uint8_t data; - int rc; - - rc = get_register((struct bma253 *)bma253, REG_ADDR_PMU_BW, &data); - if (rc != 0) { - return rc; - } - - switch (data & 0x1F) { - case 0x00 ... 0x08: - *filter_bandwidth = BMA253_FILTER_BANDWIDTH_7_81_HZ; - break; - case 0x09: - *filter_bandwidth = BMA253_FILTER_BANDWIDTH_15_63_HZ; - break; - case 0x0A: - *filter_bandwidth = BMA253_FILTER_BANDWIDTH_31_25_HZ; - break; - case 0x0B: - *filter_bandwidth = BMA253_FILTER_BANDWIDTH_62_5_HZ; - break; - case 0x0C: - *filter_bandwidth = BMA253_FILTER_BANDWIDTH_125_HZ; - break; - case 0x0D: - *filter_bandwidth = BMA253_FILTER_BANDWIDTH_250_HZ; - break; - case 0x0E: - *filter_bandwidth = BMA253_FILTER_BANDWIDTH_500_HZ; - break; - case 0x0F ... 0x1F: - *filter_bandwidth = BMA253_FILTER_BANDWIDTH_1000_HZ; - break; - } - - return 0; -} - -int -bma253_set_filter_bandwidth(const struct bma253 * bma253, - enum bma253_filter_bandwidth filter_bandwidth) -{ - uint8_t data; - - switch (filter_bandwidth) { - case BMA253_FILTER_BANDWIDTH_7_81_HZ: - data = 0x08; - break; - case BMA253_FILTER_BANDWIDTH_15_63_HZ: - data = 0x09; - break; - case BMA253_FILTER_BANDWIDTH_31_25_HZ: - data = 0x0A; - break; - case BMA253_FILTER_BANDWIDTH_62_5_HZ: - data = 0x0B; - break; - case BMA253_FILTER_BANDWIDTH_125_HZ: - data = 0x0C; - break; - case BMA253_FILTER_BANDWIDTH_250_HZ: - data = 0x0D; - break; - case BMA253_FILTER_BANDWIDTH_500_HZ: - data = 0x0E; - break; - case BMA253_FILTER_BANDWIDTH_1000_HZ: - data = 0x0F; - break; - default: - return SYS_EINVAL; - } - - return set_register((struct bma253 *)bma253, REG_ADDR_PMU_BW, data); -} - -int -bma253_get_power_settings(const struct bma253 * bma253, - struct power_settings * power_settings) -{ - uint8_t data[2]; - int rc; - - rc = get_registers((struct bma253 *)bma253, REG_ADDR_PMU_LPW, - data, sizeof(data) / sizeof(*data)); - if (rc != 0) { - return rc; - } - - switch ((data[0] >> 5) & 0x07) { - default: - BMA253_LOG_ERROR("unknown PMU_LPW reg value 0x%02X\n", data[0]); - power_settings->power_mode = BMA253_POWER_MODE_NORMAL; - break; - case 0x00: - power_settings->power_mode = BMA253_POWER_MODE_NORMAL; - break; - case 0x01: - power_settings->power_mode = BMA253_POWER_MODE_DEEP_SUSPEND; - break; - case 0x02: - if ((data[1] & 0x40) == 0) { - power_settings->power_mode = BMA253_POWER_MODE_LPM_1; - } else { - power_settings->power_mode = BMA253_POWER_MODE_LPM_2; - } - break; - case 0x04: - if ((data[1] & 0x40) == 0) { - power_settings->power_mode = BMA253_POWER_MODE_SUSPEND; - } else { - power_settings->power_mode = BMA253_POWER_MODE_STANDBY; - } - break; - } - - switch ((data[0] >> 1) & 0x0F) { - case 0x00 ... 0x05: - power_settings->sleep_duration = BMA253_SLEEP_DURATION_0_5_MS; - break; - case 0x06: - power_settings->sleep_duration = BMA253_SLEEP_DURATION_1_MS; - break; - case 0x07: - power_settings->sleep_duration = BMA253_SLEEP_DURATION_2_MS; - break; - case 0x08: - power_settings->sleep_duration = BMA253_SLEEP_DURATION_4_MS; - break; - case 0x09: - power_settings->sleep_duration = BMA253_SLEEP_DURATION_6_MS; - break; - case 0x0A: - power_settings->sleep_duration = BMA253_SLEEP_DURATION_10_MS; - break; - case 0x0B: - power_settings->sleep_duration = BMA253_SLEEP_DURATION_25_MS; - break; - case 0x0C: - power_settings->sleep_duration = BMA253_SLEEP_DURATION_50_MS; - break; - case 0x0D: - power_settings->sleep_duration = BMA253_SLEEP_DURATION_100_MS; - break; - case 0x0E: - power_settings->sleep_duration = BMA253_SLEEP_DURATION_500_MS; - break; - case 0x0F: - power_settings->sleep_duration = BMA253_SLEEP_DURATION_1_S; - break; - } - - if ((data[1] & 0x20) != 0) { - power_settings->sleep_timer = SLEEP_TIMER_EQUIDISTANT_SAMPLING; - } else { - power_settings->sleep_timer = SLEEP_TIMER_EVENT_DRIVEN; - } - - return 0; -} - -int -bma253_set_power_settings(const struct bma253 * bma253, - const struct power_settings * power_settings) -{ - uint8_t data[2]; - int rc; - - data[0] = 0; - data[1] = 0; - - switch (power_settings->power_mode) { - case BMA253_POWER_MODE_NORMAL: - data[0] |= 0x00 << 5; - break; - case BMA253_POWER_MODE_DEEP_SUSPEND: - data[0] |= 0x01 << 5; - break; - case BMA253_POWER_MODE_SUSPEND: - data[0] |= 0x04 << 5; - data[1] |= 0x00 << 6; - break; - case BMA253_POWER_MODE_STANDBY: - data[0] |= 0x04 << 5; - data[1] |= 0x01 << 6; - break; - case BMA253_POWER_MODE_LPM_1: - data[0] |= 0x02 << 5; - data[1] |= 0x00 << 6; - break; - case BMA253_POWER_MODE_LPM_2: - data[0] |= 0x02 << 5; - data[1] |= 0x01 << 6; - break; - default: - return SYS_EINVAL; - } - - switch (power_settings->sleep_duration) { - case BMA253_SLEEP_DURATION_0_5_MS: - data[0] |= 0x05 << 1; - break; - case BMA253_SLEEP_DURATION_1_MS: - data[0] |= 0x06 << 1; - break; - case BMA253_SLEEP_DURATION_2_MS: - data[0] |= 0x07 << 1; - break; - case BMA253_SLEEP_DURATION_4_MS: - data[0] |= 0x08 << 1; - break; - case BMA253_SLEEP_DURATION_6_MS: - data[0] |= 0x09 << 1; - break; - case BMA253_SLEEP_DURATION_10_MS: - data[0] |= 0x0A << 1; - break; - case BMA253_SLEEP_DURATION_25_MS: - data[0] |= 0x0B << 1; - break; - case BMA253_SLEEP_DURATION_50_MS: - data[0] |= 0x0C << 1; - break; - case BMA253_SLEEP_DURATION_100_MS: - data[0] |= 0x0D << 1; - break; - case BMA253_SLEEP_DURATION_500_MS: - data[0] |= 0x0E << 1; - break; - case BMA253_SLEEP_DURATION_1_S: - data[0] |= 0x0F << 1; - break; - default: - return SYS_EINVAL; - } - - switch (power_settings->sleep_timer) { - case SLEEP_TIMER_EVENT_DRIVEN: - data[1] |= 0x00 << 5; - break; - case SLEEP_TIMER_EQUIDISTANT_SAMPLING: - data[1] |= 0x01 << 5; - break; - default: - return SYS_EINVAL; - } - - rc = set_register((struct bma253 *)bma253, REG_ADDR_PMU_LOW_POWER, data[1]); - if (rc != 0) { - return rc; - } - - - if (BMA253_POWER_MODE_NORMAL == power_settings->power_mode) { - rc = bma253_clear_fifo(bma253); - BMA253_DRV_CHECK_RC(rc); - } - - rc = set_register((struct bma253 *)bma253, REG_ADDR_PMU_LPW, data[0]); - if (rc != 0) { - return rc; - } - ((struct bma253 *)bma253)->power = power_settings->power_mode; - - /* immediately after changing power mode, a delay is needed */ - switch (power_settings->power_mode) { case BMA253_POWER_MODE_SUSPEND: case BMA253_POWER_MODE_DEEP_SUSPEND: case BMA253_POWER_MODE_LPM_1: @@ -4563,54 +4553,54 @@ sdsi.user_arg = read_arg; #if MYNEWT_VAL(BMA253_INT_ENABLE) - wait_interrupt(&bma253->intr, pdd->int_num); - BMA253_UNUSED_VAR(cfg); + wait_interrupt(&bma253->intr, pdd->int_num); + BMA253_UNUSED_VAR(cfg); #else - switch (cfg->filter_bandwidth) { - case BMA253_FILTER_BANDWIDTH_7_81_HZ: - delay_msec(128); - break; - case BMA253_FILTER_BANDWIDTH_15_63_HZ: - delay_msec(64); - break; - case BMA253_FILTER_BANDWIDTH_31_25_HZ: - delay_msec(32); - break; - case BMA253_FILTER_BANDWIDTH_62_5_HZ: - delay_msec(16); - break; - case BMA253_FILTER_BANDWIDTH_125_HZ: - delay_msec(8); - break; - case BMA253_FILTER_BANDWIDTH_250_HZ: - delay_msec(4); - break; - case BMA253_FILTER_BANDWIDTH_500_HZ: - delay_msec(2); - break; - case BMA253_FILTER_BANDWIDTH_1000_HZ: - delay_msec(1); - break; - default: - delay_msec(1000); - break; - } + switch (cfg->filter_bandwidth) { + case BMA253_FILTER_BANDWIDTH_7_81_HZ: + delay_msec(128); + break; + case BMA253_FILTER_BANDWIDTH_15_63_HZ: + delay_msec(64); + break; + case BMA253_FILTER_BANDWIDTH_31_25_HZ: + delay_msec(32); + break; + case BMA253_FILTER_BANDWIDTH_62_5_HZ: + delay_msec(16); + break; + case BMA253_FILTER_BANDWIDTH_125_HZ: + delay_msec(8); + break; + case BMA253_FILTER_BANDWIDTH_250_HZ: + delay_msec(4); + break; + case BMA253_FILTER_BANDWIDTH_500_HZ: + delay_msec(2); + break; + case BMA253_FILTER_BANDWIDTH_1000_HZ: + delay_msec(1); + break; + default: + delay_msec(1000); + break; + } #endif - rc = bma253_read_and_handle_fifo_data(bma253, + rc = bma253_read_and_handle_fifo_data(bma253, FIFO_DATA_X_AND_Y_AND_Z, &sdsi, stop_ticks, time_ms); - if (rc != 0) { - goto done; - } - - if (bma253->hw_cfg_pending) { - rc = bma253_exec_pending_hw_cfg(bma253); - BMA253_LOG_ERROR("error bma253_exec_pending_hw_cfg: %d\n", rc); - } - - if (bma253->ev_enabled) { - sensor_driver_handle_interrupt(&bma253->sensor); - } + if (rc != 0) { + goto done; + } + + if (bma253->hw_cfg_pending) { + rc = bma253_exec_pending_hw_cfg(bma253); + BMA253_LOG_ERROR("error bma253_exec_pending_hw_cfg: %d\n", rc); + } + + if (bma253->ev_enabled) { + sensor_driver_handle_interrupt(&bma253->sensor); + } rc = bma253_set_int_enable(bma253, &int_enable_org); @@ -5015,8 +5005,8 @@ goto done; } - int_enable.s_tap_int_enable = tap_type == BMA253_TAP_TYPE_SINGLE; - int_enable.d_tap_int_enable = tap_type == BMA253_TAP_TYPE_DOUBLE; + int_enable.s_tap_int_enable = tap_type == BMA253_TAP_TYPE_SINGLE; + int_enable.d_tap_int_enable = tap_type == BMA253_TAP_TYPE_DOUBLE; rc = bma253_set_int_enable(bma253, &int_enable); if (rc != 0) { ``` </details> #### hw/drivers/sensors/bme680/src/bme680.c <details> ```diff @@ -1685,7 +1687,7 @@ hal_gpio_write(interface->si_cs_pin, 0); (void)hal_spi_tx_val(interface->si_num, reg_addr | 0x80); /* Use reg_data for the txbuf as well. - The contents don't matter since we're reading */ + The contents don't matter since we're reading */ hal_spi_txrx(interface->si_num, reg_data, reg_data, len); hal_gpio_write(interface->si_cs_pin, 1); ``` </details> #### hw/drivers/sensors/bno055/src/bno055_shell.c <details> ```diff @@ -152,15 +152,15 @@ tok = strtok(0, ":"); } while(++i < 11 && tok); - bso.bso_acc_off_x = offsetdata[0]; - bso.bso_acc_off_y = offsetdata[1]; - bso.bso_acc_off_z = offsetdata[2]; + bso.bso_acc_off_x = offsetdata[0]; + bso.bso_acc_off_y = offsetdata[1]; + bso.bso_acc_off_z = offsetdata[2]; bso.bso_gyro_off_x = offsetdata[3]; bso.bso_gyro_off_y = offsetdata[4]; bso.bso_gyro_off_z = offsetdata[5]; - bso.bso_mag_off_x = offsetdata[6]; - bso.bso_mag_off_y = offsetdata[7]; - bso.bso_mag_off_z = offsetdata[8]; + bso.bso_mag_off_x = offsetdata[6]; + bso.bso_mag_off_y = offsetdata[7]; + bso.bso_mag_off_z = offsetdata[8]; bso.bso_acc_radius = offsetdata[9]; bso.bso_mag_radius = offsetdata[10]; @@ -260,7 +260,7 @@ console_printf("\tr [n_samples] [ 0-acc | 1 -mag | 2 -gyro | 4 -temp |\n" "\t 9-quat | 26-linearacc | 27-gravity | 28-euler ]\n\n"); } - while(samples--) { + while (samples--) { if (type == SENSOR_TYPE_ROTATION_VECTOR) { rc = bno055_get_quat_data(g_sensor_itf, &data.sqd); ``` </details> #### hw/drivers/sensors/tcs34725/src/tcs34725.c <details> ```diff @@ -673,26 +673,26 @@ *b = payload[7] << 8 | payload[6]; switch (tcs34725->cfg.integration_time) { - case TCS34725_INTEGRATIONTIME_2_4MS: - STATS_INC(g_tcs34725stats, samples_2_4ms); - break; - case TCS34725_INTEGRATIONTIME_24MS: - STATS_INC(g_tcs34725stats, samples_24ms); - break; - case TCS34725_INTEGRATIONTIME_50MS: - STATS_INC(g_tcs34725stats, samples_50ms); - break; - case TCS34725_INTEGRATIONTIME_101MS: - STATS_INC(g_tcs34725stats, samples_101ms); - break; - case TCS34725_INTEGRATIONTIME_154MS: - STATS_INC(g_tcs34725stats, samples_154ms); - break; - case TCS34725_INTEGRATIONTIME_700MS: - STATS_INC(g_tcs34725stats, samples_700ms); - break; - default: - STATS_INC(g_tcs34725stats, samples_userdef); + case TCS34725_INTEGRATIONTIME_2_4MS: + STATS_INC(g_tcs34725stats, samples_2_4ms); + break; + case TCS34725_INTEGRATIONTIME_24MS: + STATS_INC(g_tcs34725stats, samples_24ms); + break; + case TCS34725_INTEGRATIONTIME_50MS: + STATS_INC(g_tcs34725stats, samples_50ms); + break; + case TCS34725_INTEGRATIONTIME_101MS: + STATS_INC(g_tcs34725stats, samples_101ms); + break; + case TCS34725_INTEGRATIONTIME_154MS: + STATS_INC(g_tcs34725stats, samples_154ms); + break; + case TCS34725_INTEGRATIONTIME_700MS: + STATS_INC(g_tcs34725stats, samples_700ms); + break; + default: + STATS_INC(g_tcs34725stats, samples_userdef); break; } ``` </details> ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org