From aa47b81abb2b04f3ec48643ae97a15d5f089b9d6 Mon Sep 17 00:00:00 2001 From: Bartosz Meglicki Date: Mon, 24 Nov 2014 02:11:46 +0100 Subject: [PATCH 1/8] I2C driver for Microinfinity CruizCore XG1300L gyroscope and accelerometer. This sensor doesn't follow LEGO guidelines and the driver has to be loaded manually. --- drivers/legoev3/nxt_i2c_sensor.h | 2 + drivers/legoev3/nxt_i2c_sensor_defs.c | 224 ++++++++++++++++++++++++++ 2 files changed, 226 insertions(+) diff --git a/drivers/legoev3/nxt_i2c_sensor.h b/drivers/legoev3/nxt_i2c_sensor.h index 71f19983ffe8a..4b27a1aa5b636 100644 --- a/drivers/legoev3/nxt_i2c_sensor.h +++ b/drivers/legoev3/nxt_i2c_sensor.h @@ -129,6 +129,7 @@ enum nxt_i2c_sensor_type { MS_ABSOLUTE_IMU, MS_ANGLE_SENSOR, MS_LIGHT_SENSOR_ARRAY, + MI_CRUIZCORE_XG1300L, NUM_NXT_I2C_SENSORS }; @@ -155,6 +156,7 @@ enum nxt_i2c_sensor_type { { "ms-absolute-imu", MS_ABSOLUTE_IMU }, \ { "ms-angle-sensor", MS_ANGLE_SENSOR }, \ { "ms-light-array", MS_LIGHT_SENSOR_ARRAY }, \ +{ "mi-cruizcore-xg1300", MI_CRUIZCORE_XG1300L }, \ { } extern const struct nxt_i2c_sensor_info nxt_i2c_sensor_defs[]; diff --git a/drivers/legoev3/nxt_i2c_sensor_defs.c b/drivers/legoev3/nxt_i2c_sensor_defs.c index ce33b70d70d4d..7a55e67070560 100644 --- a/drivers/legoev3/nxt_i2c_sensor_defs.c +++ b/drivers/legoev3/nxt_i2c_sensor_defs.c @@ -301,6 +301,76 @@ static void ms_imu_poll_cb(struct nxt_i2c_sensor_data *sensor) } } + +/* + * BEGINNING OF + * Microinfinity CruizCore XG1300L gyroscope and accelerometer related functions + * BEGINNING OF + */ +static void mi_cruizcore_xg1300l_poll_cb(struct nxt_i2c_sensor_data *sensor) +{ + u8 *scaling_factor = sensor->info.callback_data; + + struct nxt_i2c_sensor_mode_info *i2c_mode_info = + &sensor->info.i2c_mode_info[sensor->mode]; + struct msensor_mode_info *ms_mode_info = + &sensor->info.ms_mode_info[sensor->mode]; + + s16 *raw_as_s16=(s16*) ms_mode_info->raw_data; + + /* + * Perform normal i2c read (just like nxt_i2c_sensor_poll_work). + */ + i2c_smbus_read_i2c_block_data(sensor->client, + i2c_mode_info->read_data_reg, ms_mode_info->data_sets + * msensor_data_size[ms_mode_info->data_type], + ms_mode_info->raw_data); + + /* scale values for acceleration */ + + if(sensor->mode < 2 || sensor->mode==6) // "ANG-ACC", "ANG-SPEED", "RESET", no acceleration info + return; + + if(sensor->mode == 3) // "ALL", accelerometer data starting from fourth byte + raw_as_s16 += 2; + + raw_as_s16[0] *= *scaling_factor; + raw_as_s16[1] *= *scaling_factor; + raw_as_s16[2] *= *scaling_factor; +} + +// Remember the last set scaling factor for the accelerometer so +// that the values are scaled correctly also in ALL mode +static void mi_cruizcore_xg1300l_set_mode_post_cb(struct nxt_i2c_sensor_data *data, u8 mode) +{ + u8 *scaling_factor = data->info.callback_data; + if (mode == 0 && !scaling_factor) + { + scaling_factor = kzalloc(sizeof(u8), GFP_KERNEL); + *scaling_factor = 1; + data->info.callback_data = scaling_factor; + } + else if (mode==2 || mode==6) *scaling_factor=1; //"ACCEL-2G", "RESET" + else if (mode==4) *scaling_factor=2; //"ACCEL-4G" + else if (mode==5) *scaling_factor=4; //"ACCEL-8G" +} +// Free calback data on remove +static void mi_cruizcore_xg1300l_remove_cb(struct nxt_i2c_sensor_data *data) +{ + u8 *scaling_factor = data->info.callback_data; + + if(scaling_factor) + { + data->info.callback_data = NULL; + kfree(scaling_factor); + } +} +/* END OF + * Microinfinity CruizCore XG1300L gyroscope and accelerometer related functions + * END OF + */ + + /** * nxt_i2c_sensor_defs - Sensor definitions * @@ -2130,6 +2200,160 @@ const struct nxt_i2c_sensor_info nxt_i2c_sensor_defs[] = { }, }, }, + [MI_CRUIZCORE_XG1300L] = { + /** + * [^usage]: Sample usage: + * + * CruizCore XG1300L doesn't follow LEGO guidelines and it can't be autodected. + * Until we find other way to identify the sensor the driver has to be loaded manually. + * + * Register I2C device: + * + *
echo mi-cruizcore-xg1300 0x01 > /sys/bus/i2c/devices/i2c-/new_device
+		 * 
+ * + * Finding device class node: + * + * + * @vendor_name: Microinfinity + * @vendor_part_number: CruizCore XG 1300L + * @vendor_part_name: CruizCore XG 1300L digital gyroscope and accelerometer + * @vendor_website: http://www.minfinity.com/eng/page.php?Main=1&sub=1&tab=5 + * @default_address: 0x1 + */ + .name = "mi-cruizcore-xg1300", + .vendor_id = "mnfinity", //not implemented on CruizCore side I2C! + .product_id = "XG1300L", //not implemented on CruizCore side I2C! + .num_modes = 7, + .num_read_only_modes = 4, + .ops.poll_cb = mi_cruizcore_xg1300l_poll_cb, + .ops.set_mode_post_cb = mi_cruizcore_xg1300l_set_mode_post_cb, + .ops.remove_cb = mi_cruizcore_xg1300l_remove_cb, + + .ms_mode_info = { + [0] = { + /** + * @description: Accumulated angle + * @value0: Z-axis accumulated angle (-180 to 180) + * @units_description: degrees + */ + .name = "ANG-ACC", + .data_sets = 1, + .data_type = MSENSOR_DATA_S16, + .units = "deg", + .decimals = 2, + }, + [1] = { + /** + * + * @description: Rate of turn + * @value0: Z-axis rate of turn + * @units_description: degrees per second + */ + .name = "ANG-SPEED", + .data_sets = 1, + .data_type = MSENSOR_DATA_S16, + .decimals = 2, + .units = "d/s", + }, + + + [2] = { + /** + * + * @description: Acceleration in X, Y, Z axis, scale +-2G + * @value0: Acceleration in X axis + * @value1: Acceleration in Y axis + * @value2: Acceleration in Z axis + * @units_description: g + */ + .name = "ACCEL-2G", + .data_sets = 3, + .units = "g", + .data_type = MSENSOR_DATA_S16, + .decimals = 3, + }, + [3] = { + /** + * @description: All values: accumulated angle, rate of turn, acceleration in X, Y, Z with last set scale + * @value0: Z-axis accumulated angle (-180 to 180), 2 decimal places + * @value1: Z-axis rate of turn, 2 decimal places + * @value2: Acceleration in X axis , 3 decimal places, range as was set last time + * @value3: Acceleration in Y axis , 3 decimal places, range as was set last time + * @value4: Acceleration in Z axis , 3 decimal places, range as was set last time + * + */ + .name = "ALL", + .data_sets = 5, + .data_type = MSENSOR_DATA_S16, + }, + [4] = { + /** + * + * @description: Acceleration in X, Y, Z axis, scale +-4G + * @value0: Acceleration in X axis + * @value1: Acceleration in Y axis + * @value2: Acceleration in Z axis + * @units_description: g + */ + .name = "ACCEL-4G", + .data_sets = 3, + .units = "g", + .data_type = MSENSOR_DATA_S16, + .decimals = 3, + }, + [5] = { + /** + * + * @description: Acceleration in X, Y, Z axis, scale +-8G + * @value0: Acceleration in X axis + * @value1: Acceleration in Y axis + * @value2: Acceleration in Z axis + * @units_description: g + */ + .name = "ACCEL-8G", + .data_sets = 3, + .units = "g", + .data_type = MSENSOR_DATA_S16, + .decimals = 3, + }, + [6] = { + /** + * + * @description: Reset device: recalculate bias drift, reset accumulated angle, set accelerometer scaling factor to 2G, this *has* to be done with sensor not moving and is strongly recommended to be called manually before work + */ + .name = "RESET", + .data_sets = 0, + }, + + }, + .i2c_mode_info = { + [0] = { + .read_data_reg = 0x42, + }, + [1] = { + .read_data_reg = 0x44, + }, + [2] = { + .read_data_reg = 0x46, + .set_mode_reg = 0x61, + }, + [3] = { + .read_data_reg = 0x42, + }, + [4] = { + .read_data_reg = 0x46, + .set_mode_reg = 0x62, + }, + [5] = { + .read_data_reg = 0x46, + .set_mode_reg = 0x63, + }, + [6] = { + .set_mode_reg = 0x60, + }, + }, + } }; EXPORT_SYMBOL_GPL(nxt_i2c_sensor_defs); From 8fe851ea361bcf3044c885d488fadf7da4315783 Mon Sep 17 00:00:00 2001 From: Bartosz Meglicki Date: Mon, 24 Nov 2014 02:21:32 +0100 Subject: [PATCH 2/8] Removed unecessary line from documentation --- drivers/legoev3/nxt_i2c_sensor_defs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/legoev3/nxt_i2c_sensor_defs.c b/drivers/legoev3/nxt_i2c_sensor_defs.c index 7a55e67070560..2aba97b617044 100644 --- a/drivers/legoev3/nxt_i2c_sensor_defs.c +++ b/drivers/legoev3/nxt_i2c_sensor_defs.c @@ -2211,8 +2211,7 @@ const struct nxt_i2c_sensor_info nxt_i2c_sensor_defs[] = { * *
echo mi-cruizcore-xg1300 0x01 > /sys/bus/i2c/devices/i2c-/new_device
 		 * 
- * - * Finding device class node: + * * * * @vendor_name: Microinfinity From 99ad6ad268ba008b322722890e6b4341f19cdc90 Mon Sep 17 00:00:00 2001 From: Bartosz Meglicki Date: Mon, 24 Nov 2014 12:55:21 +0100 Subject: [PATCH 3/8] Added super-awesome command callbacks ;-) Reimplemented driver for Microinfinity CruizCore XG1300L using commands and modes Masacred trailing whitespaces Added footnotes instead of overgrown descriptions --- drivers/legoev3/nxt_i2c_sensor.h | 6 +- drivers/legoev3/nxt_i2c_sensor_core.c | 8 +- drivers/legoev3/nxt_i2c_sensor_defs.c | 208 +++++++++++++------------- 3 files changed, 111 insertions(+), 111 deletions(-) diff --git a/drivers/legoev3/nxt_i2c_sensor.h b/drivers/legoev3/nxt_i2c_sensor.h index 4b27a1aa5b636..90d7f50c538a7 100644 --- a/drivers/legoev3/nxt_i2c_sensor.h +++ b/drivers/legoev3/nxt_i2c_sensor.h @@ -22,7 +22,7 @@ #define NXT_I2C_ID_STR_LEN 8 #define NXT_I2C_FW_VER_REG 0x00 -#define NXT_I2C_VEND_ID_REG 0x08 +#define NXT_I2C_VEND_ID_REG 0x08 #define NXT_I2C_PROD_ID_REG 0x10 struct nxt_i2c_sensor_data; @@ -35,6 +35,7 @@ struct nxt_i2c_sensor_data; * @set_mode_pre_cb: Called before the mode is set. Returning a negative error * value will prevent the mode from being changed. * @set_mode_post_cb: Called after the mode has been changed. + * @send_command_post_cb: Called after the command has been sent * @poll_cb: Called after the sensor has been polled. * @probe_cb: Called at the end of the driver probe function. * @remove_cb: Called at the beginning of the driver remove function. @@ -42,6 +43,7 @@ struct nxt_i2c_sensor_data; struct nxt_i2c_sensor_ops { int (*set_mode_pre_cb)(struct nxt_i2c_sensor_data *data, u8 mode); void (*set_mode_post_cb)(struct nxt_i2c_sensor_data *data, u8 mode); + void (*send_command_post_cb)(struct nxt_i2c_sensor_data *data, u8 command); void (*poll_cb)(struct nxt_i2c_sensor_data *data); void (*probe_cb)(struct nxt_i2c_sensor_data *data); void (*remove_cb)(struct nxt_i2c_sensor_data *data); @@ -156,7 +158,7 @@ enum nxt_i2c_sensor_type { { "ms-absolute-imu", MS_ABSOLUTE_IMU }, \ { "ms-angle-sensor", MS_ANGLE_SENSOR }, \ { "ms-light-array", MS_LIGHT_SENSOR_ARRAY }, \ -{ "mi-cruizcore-xg1300", MI_CRUIZCORE_XG1300L }, \ +{ "mi-xg1300l", MI_CRUIZCORE_XG1300L }, \ { } extern const struct nxt_i2c_sensor_info nxt_i2c_sensor_defs[]; diff --git a/drivers/legoev3/nxt_i2c_sensor_core.c b/drivers/legoev3/nxt_i2c_sensor_core.c index 62be4af11b2ce..adab910e6e2ee 100644 --- a/drivers/legoev3/nxt_i2c_sensor_core.c +++ b/drivers/legoev3/nxt_i2c_sensor_core.c @@ -129,10 +129,16 @@ static int nxt_i2c_sensor_set_mode(void *context, u8 mode) static int nxt_i2c_sensor_send_command(void *context, u8 command) { struct nxt_i2c_sensor_data *sensor = context; + int err; - return i2c_smbus_write_byte_data(sensor->client, + err=i2c_smbus_write_byte_data(sensor->client, sensor->info.i2c_cmd_info[command].cmd_reg, sensor->info.i2c_cmd_info[command].cmd_data); + + if (sensor->info.ops.send_command_post_cb) + sensor->info.ops.send_command_post_cb(sensor, command); + + return err; } static ssize_t nxt_i2c_sensor_write_data(void *context, char *data, loff_t off, diff --git a/drivers/legoev3/nxt_i2c_sensor_defs.c b/drivers/legoev3/nxt_i2c_sensor_defs.c index 2aba97b617044..d607380680465 100644 --- a/drivers/legoev3/nxt_i2c_sensor_defs.c +++ b/drivers/legoev3/nxt_i2c_sensor_defs.c @@ -2,6 +2,7 @@ * NXT I2C sensor device driver for LEGO MINDSTORMS EV3 * * Copyright (C) 2013-2014 David Lechner + * Copyright (C) 2014 Bartosz Meglicki * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as @@ -301,15 +302,12 @@ static void ms_imu_poll_cb(struct nxt_i2c_sensor_data *sensor) } } - /* - * BEGINNING OF - * Microinfinity CruizCore XG1300L gyroscope and accelerometer related functions - * BEGINNING OF + * Microinfinity CruizCore XG1300L gyroscope and accelerometer related functions */ static void mi_cruizcore_xg1300l_poll_cb(struct nxt_i2c_sensor_data *sensor) { - u8 *scaling_factor = sensor->info.callback_data; + u8 *scaling_factor = sensor->info.callback_data; struct nxt_i2c_sensor_mode_info *i2c_mode_info = &sensor->info.i2c_mode_info[sensor->mode]; @@ -328,10 +326,10 @@ static void mi_cruizcore_xg1300l_poll_cb(struct nxt_i2c_sensor_data *sensor) /* scale values for acceleration */ - if(sensor->mode < 2 || sensor->mode==6) // "ANG-ACC", "ANG-SPEED", "RESET", no acceleration info + if(sensor->mode < 2) /* "ANG-ACC", "ANG-SPEED" - no acceleration info */ return; - if(sensor->mode == 3) // "ALL", accelerometer data starting from fourth byte + if(sensor->mode == 3) /* "ALL", accelerometer data starting from fourth byte */ raw_as_s16 += 2; raw_as_s16[0] *= *scaling_factor; @@ -339,25 +337,25 @@ static void mi_cruizcore_xg1300l_poll_cb(struct nxt_i2c_sensor_data *sensor) raw_as_s16[2] *= *scaling_factor; } -// Remember the last set scaling factor for the accelerometer so -// that the values are scaled correctly also in ALL mode -static void mi_cruizcore_xg1300l_set_mode_post_cb(struct nxt_i2c_sensor_data *data, u8 mode) +static void mi_cruizcore_xg1300l_send_command_post_cb(struct nxt_i2c_sensor_data *data, u8 command) { u8 *scaling_factor = data->info.callback_data; - if (mode == 0 && !scaling_factor) - { - scaling_factor = kzalloc(sizeof(u8), GFP_KERNEL); - *scaling_factor = 1; - data->info.callback_data = scaling_factor; - } - else if (mode==2 || mode==6) *scaling_factor=1; //"ACCEL-2G", "RESET" - else if (mode==4) *scaling_factor=2; //"ACCEL-4G" - else if (mode==5) *scaling_factor=4; //"ACCEL-8G" + + if (command==0 || command==1) *scaling_factor=1; /* "RESET", "ACCEL-2G" */ + else if (command==2) *scaling_factor=2; /* "ACCEL-4G" */ + else if (command==3) *scaling_factor=4; /* "ACCEL-8G" */ +} + +static void mi_cruizcore_xg1300l_probe_cb(struct nxt_i2c_sensor_data *data) +{ + u8 *scaling_factor = kzalloc(sizeof(u8), GFP_KERNEL); + *scaling_factor = 1; + data->info.callback_data = scaling_factor; } -// Free calback data on remove + static void mi_cruizcore_xg1300l_remove_cb(struct nxt_i2c_sensor_data *data) { - u8 *scaling_factor = data->info.callback_data; + u8 *scaling_factor = data->info.callback_data; if(scaling_factor) { @@ -365,11 +363,6 @@ static void mi_cruizcore_xg1300l_remove_cb(struct nxt_i2c_sensor_data *data) kfree(scaling_factor); } } -/* END OF - * Microinfinity CruizCore XG1300L gyroscope and accelerometer related functions - * END OF - */ - /** * nxt_i2c_sensor_defs - Sensor definitions @@ -386,6 +379,7 @@ static void mi_cruizcore_xg1300l_remove_cb(struct nxt_i2c_sensor_data *data) * - num_read_only_modes (default num_modes) * - ops.set_mode_pre_cb * - ops.set_mode_post_cb + * - ops.send_command_post_cb * - ops.poll_cb * - ops.probe_cb * - ops.remove_cb @@ -2201,7 +2195,7 @@ const struct nxt_i2c_sensor_info nxt_i2c_sensor_defs[] = { }, }, [MI_CRUIZCORE_XG1300L] = { - /** + /** * [^usage]: Sample usage: * * CruizCore XG1300L doesn't follow LEGO guidelines and it can't be autodected. @@ -2211,24 +2205,22 @@ const struct nxt_i2c_sensor_info nxt_i2c_sensor_defs[] = { * *
echo mi-cruizcore-xg1300 0x01 > /sys/bus/i2c/devices/i2c-/new_device
 		 * 
- * - * - * + * * @vendor_name: Microinfinity - * @vendor_part_number: CruizCore XG 1300L - * @vendor_part_name: CruizCore XG 1300L digital gyroscope and accelerometer + * @vendor_part_name: CruizCore XG 1300L Digital Gyroscope And Accelerometer * @vendor_website: http://www.minfinity.com/eng/page.php?Main=1&sub=1&tab=5 - * @default_address: 0x1 + * @default_address: 0x01 + * @default_address_footnote [^usage] */ - .name = "mi-cruizcore-xg1300", - .vendor_id = "mnfinity", //not implemented on CruizCore side I2C! - .product_id = "XG1300L", //not implemented on CruizCore side I2C! - .num_modes = 7, - .num_read_only_modes = 4, - .ops.poll_cb = mi_cruizcore_xg1300l_poll_cb, - .ops.set_mode_post_cb = mi_cruizcore_xg1300l_set_mode_post_cb, - .ops.remove_cb = mi_cruizcore_xg1300l_remove_cb, - + .name = "mi-xg1300l", + .vendor_id = "mnfinity", /* The sensor doesn't return vendor_id, it can't be autodetected this way */ + .product_id = "XG1300L", /* The sensor doesn't return product_id, it can't be autodetected this way */ + .num_modes = 4, + .num_read_only_modes = 4, + .ops.poll_cb = mi_cruizcore_xg1300l_poll_cb, + .ops.send_command_post_cb = mi_cruizcore_xg1300l_send_command_post_cb, + .ops.probe_cb = mi_cruizcore_xg1300l_probe_cb, + .ops.remove_cb = mi_cruizcore_xg1300l_remove_cb, .ms_mode_info = { [0] = { /** @@ -2244,9 +2236,9 @@ const struct nxt_i2c_sensor_info nxt_i2c_sensor_defs[] = { }, [1] = { /** - * - * @description: Rate of turn - * @value0: Z-axis rate of turn + * + * @description: Rotational speed + * @value0: Z-axis rotational speed * @units_description: degrees per second */ .name = "ANG-SPEED", @@ -2255,104 +2247,104 @@ const struct nxt_i2c_sensor_info nxt_i2c_sensor_defs[] = { .decimals = 2, .units = "d/s", }, - - [2] = { /** * - * @description: Acceleration in X, Y, Z axis, scale +-2G - * @value0: Acceleration in X axis - * @value1: Acceleration in Y axis - * @value2: Acceleration in Z axis - * @units_description: g + * @description: Acceleration in X, Y, Z axis + * @value0: Acceleration in X axis + * @value1: Acceleration in Y axis + * @value2: Acceleration in Z axis + * @units_description: g (1g ~ 9.81 m/s2) */ - .name = "ACCEL-2G", - .data_sets = 3, + .name = "ACCEL-XYZ", + .data_sets = 3, .units = "g", .data_type = MSENSOR_DATA_S16, .decimals = 3, }, [3] = { /** - * @description: All values: accumulated angle, rate of turn, acceleration in X, Y, Z with last set scale - * @value0: Z-axis accumulated angle (-180 to 180), 2 decimal places - * @value1: Z-axis rate of turn, 2 decimal places - * @value2: Acceleration in X axis , 3 decimal places, range as was set last time - * @value3: Acceleration in Y axis , 3 decimal places, range as was set last time - * @value4: Acceleration in Z axis , 3 decimal places, range as was set last time - * + * [^acceleration-description]: 3 decimal places, range as was set by last command + * [^accumulated-angle-description]: 2 decimal places, (-180 to 180) + * [^rotational-speed-description]: 2 decimal places + * + * @description: All values + * @value0: Z-axis accumulated angle + * @value0_footnote: [^accumulated-angle-description] + * @value1: Z-axis rotational speed + * @value1_footnote: [^rotational-speed-description] + * @value2: X-axis acceleration + * @value2_footnote: [^acceleration-description] + * @value3: Y-axis acceleration + * @value3_footnote: [^acceleration-description] + * @value4: Z-axis acceleration + * @value4_footnote: [^acceleration-description] + * */ .name = "ALL", .data_sets = 5, .data_type = MSENSOR_DATA_S16, }, - [4] = { + }, + .i2c_mode_info = { + [0] = { + .read_data_reg = 0x42, + }, + [1] = { + .read_data_reg = 0x44, + }, + [2] = { + .read_data_reg = 0x46, + }, + [3] = { + .read_data_reg = 0x42, + }, + }, + .num_commands = 4, + .ms_cmd_info = { + [0] = { /** + * [^reset-description]: recalculate bias drift, reset accumulated angle, set accelerometer scaling factor to 2G, this *has* to be done with sensor not moving and is strongly recommended to be called manually before work * - * @description: Acceleration in X, Y, Z axis, scale +-4G - * @value0: Acceleration in X axis - * @value1: Acceleration in Y axis - * @value2: Acceleration in Z axis - * @units_description: g + * @description: Reset device + * @description_footnote: [^reset-description] */ - .name = "ACCEL-4G", - .data_sets = 3, - .units = "g", - .data_type = MSENSOR_DATA_S16, - .decimals = 3, + .name = "RESET", }, - [5] = { + [1] = { /** - * - * @description: Acceleration in X, Y, Z axis, scale +-8G - * @value0: Acceleration in X axis - * @value1: Acceleration in Y axis - * @value2: Acceleration in Z axis - * @units_description: g + * @description: Acceleration scaling 2G */ - .name = "ACCEL-8G", - .data_sets = 3, - .units = "g", - .data_type = MSENSOR_DATA_S16, - .decimals = 3, + .name = "ACCEL-2G", }, - [6] = { + [2] = { /** - * - * @description: Reset device: recalculate bias drift, reset accumulated angle, set accelerometer scaling factor to 2G, this *has* to be done with sensor not moving and is strongly recommended to be called manually before work + * @description: Acceleration scaling 4G */ - .name = "RESET", - .data_sets = 0, + .name = "ACCEL-4G", + }, + [3] = { + /** + * @description: Acceleration scaling 8G + */ + .name = "ACCEL-8G", }, - }, - .i2c_mode_info = { + .i2c_cmd_info = { [0] = { - .read_data_reg = 0x42, + .cmd_reg = 0x60, }, [1] = { - .read_data_reg = 0x44, + .cmd_reg = 0x61, }, [2] = { - .read_data_reg = 0x46, - .set_mode_reg = 0x61, + .cmd_reg = 0x62, }, [3] = { - .read_data_reg = 0x42, - }, - [4] = { - .read_data_reg = 0x46, - .set_mode_reg = 0x62, - }, - [5] = { - .read_data_reg = 0x46, - .set_mode_reg = 0x63, - }, - [6] = { - .set_mode_reg = 0x60, + .cmd_reg = 0x63, }, }, - } + }, }; EXPORT_SYMBOL_GPL(nxt_i2c_sensor_defs); From 87f5424a48d71c279d8148a65f2bc5c30088d51b Mon Sep 17 00:00:00 2001 From: Bartosz Meglicki Date: Mon, 24 Nov 2014 17:58:22 +0100 Subject: [PATCH 4/8] Command callback not called if error occurs during command execution Wrapped some lines --- drivers/legoev3/nxt_i2c_sensor_core.c | 5 ++++- drivers/legoev3/nxt_i2c_sensor_defs.c | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/legoev3/nxt_i2c_sensor_core.c b/drivers/legoev3/nxt_i2c_sensor_core.c index adab910e6e2ee..2158d6c81cacb 100644 --- a/drivers/legoev3/nxt_i2c_sensor_core.c +++ b/drivers/legoev3/nxt_i2c_sensor_core.c @@ -131,10 +131,13 @@ static int nxt_i2c_sensor_send_command(void *context, u8 command) struct nxt_i2c_sensor_data *sensor = context; int err; - err=i2c_smbus_write_byte_data(sensor->client, + err = i2c_smbus_write_byte_data(sensor->client, sensor->info.i2c_cmd_info[command].cmd_reg, sensor->info.i2c_cmd_info[command].cmd_data); + if (err) + return err; + if (sensor->info.ops.send_command_post_cb) sensor->info.ops.send_command_post_cb(sensor, command); diff --git a/drivers/legoev3/nxt_i2c_sensor_defs.c b/drivers/legoev3/nxt_i2c_sensor_defs.c index d607380680465..fde3069d04a46 100644 --- a/drivers/legoev3/nxt_i2c_sensor_defs.c +++ b/drivers/legoev3/nxt_i2c_sensor_defs.c @@ -2213,7 +2213,7 @@ const struct nxt_i2c_sensor_info nxt_i2c_sensor_defs[] = { * @default_address_footnote [^usage] */ .name = "mi-xg1300l", - .vendor_id = "mnfinity", /* The sensor doesn't return vendor_id, it can't be autodetected this way */ + .vendor_id = "mnfinity", /* The sensor doesn't return vendor_id, it can't be autodetected this way */ .product_id = "XG1300L", /* The sensor doesn't return product_id, it can't be autodetected this way */ .num_modes = 4, .num_read_only_modes = 4, @@ -2304,7 +2304,10 @@ const struct nxt_i2c_sensor_info nxt_i2c_sensor_defs[] = { .ms_cmd_info = { [0] = { /** - * [^reset-description]: recalculate bias drift, reset accumulated angle, set accelerometer scaling factor to 2G, this *has* to be done with sensor not moving and is strongly recommended to be called manually before work + * [^reset-description]: recalculate bias drift, reset accumulated angle, + * set accelerometer scaling factor to 2G, + * this has to be done with sensor not moving + * and is strongly recommended to be called manually before work * * @description: Reset device * @description_footnote: [^reset-description] From c4eff90d771cb7df1a594f226f09f0b1e429e7b3 Mon Sep 17 00:00:00 2001 From: Bartosz Meglicki Date: Mon, 24 Nov 2014 18:02:00 +0100 Subject: [PATCH 5/8] Added some spaces around some '=' ;-) --- drivers/legoev3/nxt_i2c_sensor_defs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/legoev3/nxt_i2c_sensor_defs.c b/drivers/legoev3/nxt_i2c_sensor_defs.c index fde3069d04a46..3ae140e3f7836 100644 --- a/drivers/legoev3/nxt_i2c_sensor_defs.c +++ b/drivers/legoev3/nxt_i2c_sensor_defs.c @@ -314,7 +314,7 @@ static void mi_cruizcore_xg1300l_poll_cb(struct nxt_i2c_sensor_data *sensor) struct msensor_mode_info *ms_mode_info = &sensor->info.ms_mode_info[sensor->mode]; - s16 *raw_as_s16=(s16*) ms_mode_info->raw_data; + s16 *raw_as_s16 = (s16*) ms_mode_info->raw_data; /* * Perform normal i2c read (just like nxt_i2c_sensor_poll_work). From 7448be9c6a43e59a2d7681c667c2db20c7492eb1 Mon Sep 17 00:00:00 2001 From: Bartosz Meglicki Date: Mon, 24 Nov 2014 18:06:47 +0100 Subject: [PATCH 6/8] vendor_part_number back vendor_part_name reshaped --- drivers/legoev3/nxt_i2c_sensor_defs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/legoev3/nxt_i2c_sensor_defs.c b/drivers/legoev3/nxt_i2c_sensor_defs.c index 3ae140e3f7836..da29692a75dad 100644 --- a/drivers/legoev3/nxt_i2c_sensor_defs.c +++ b/drivers/legoev3/nxt_i2c_sensor_defs.c @@ -2207,7 +2207,8 @@ const struct nxt_i2c_sensor_info nxt_i2c_sensor_defs[] = { * * * @vendor_name: Microinfinity - * @vendor_part_name: CruizCore XG 1300L Digital Gyroscope And Accelerometer + * @vendor_part_number: CruizCore XG 1300L + * @vendor_part_name: Digital Gyroscope And Accelerometer * @vendor_website: http://www.minfinity.com/eng/page.php?Main=1&sub=1&tab=5 * @default_address: 0x01 * @default_address_footnote [^usage] From 3489663d082d4f9355a7e3597a3f24acc4285558 Mon Sep 17 00:00:00 2001 From: Bartosz Meglicki Date: Mon, 24 Nov 2014 18:16:38 +0100 Subject: [PATCH 7/8] Numbers at the beginning of footnotes spelled (e.g. two instead of 2) --- drivers/legoev3/nxt_i2c_sensor_defs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/legoev3/nxt_i2c_sensor_defs.c b/drivers/legoev3/nxt_i2c_sensor_defs.c index da29692a75dad..8ffa4f8d5f4ca 100644 --- a/drivers/legoev3/nxt_i2c_sensor_defs.c +++ b/drivers/legoev3/nxt_i2c_sensor_defs.c @@ -2265,9 +2265,9 @@ const struct nxt_i2c_sensor_info nxt_i2c_sensor_defs[] = { }, [3] = { /** - * [^acceleration-description]: 3 decimal places, range as was set by last command - * [^accumulated-angle-description]: 2 decimal places, (-180 to 180) - * [^rotational-speed-description]: 2 decimal places + * [^acceleration-description]: three decimal places, range as was set by last command + * [^accumulated-angle-description]: two decimal places, (-180 to 180) + * [^rotational-speed-description]: two decimal places * * @description: All values * @value0: Z-axis accumulated angle From 7757fea8b5530afbe91e53d3bd2a7bcc9da56bc9 Mon Sep 17 00:00:00 2001 From: Bartosz Meglicki Date: Mon, 24 Nov 2014 18:20:05 +0100 Subject: [PATCH 8/8] Missing : --- drivers/legoev3/nxt_i2c_sensor_defs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/legoev3/nxt_i2c_sensor_defs.c b/drivers/legoev3/nxt_i2c_sensor_defs.c index 8ffa4f8d5f4ca..1dd0a8ea2be33 100644 --- a/drivers/legoev3/nxt_i2c_sensor_defs.c +++ b/drivers/legoev3/nxt_i2c_sensor_defs.c @@ -2211,7 +2211,7 @@ const struct nxt_i2c_sensor_info nxt_i2c_sensor_defs[] = { * @vendor_part_name: Digital Gyroscope And Accelerometer * @vendor_website: http://www.minfinity.com/eng/page.php?Main=1&sub=1&tab=5 * @default_address: 0x01 - * @default_address_footnote [^usage] + * @default_address_footnote: [^usage] */ .name = "mi-xg1300l", .vendor_id = "mnfinity", /* The sensor doesn't return vendor_id, it can't be autodetected this way */