raiden00pl commented on code in PR #15789:
URL: https://github.com/apache/nuttx/pull/15789#discussion_r1948031125


##########
drivers/sensors/lsm6dso32_uorb.c:
##########
@@ -0,0 +1,1979 @@
+/****************************************************************************
+ * drivers/sensors/lsm6dso32_uorb.c
+ *
+ * Contributed by Carleton University InSpace
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/nuttx.h>
+
+#include <debug.h>
+
+#include <nuttx/fs/fs.h>
+#include <nuttx/i2c/i2c_master.h>
+#include <nuttx/kmalloc.h>
+#include <nuttx/kthread.h>
+#include <nuttx/mutex.h>
+#include <nuttx/random.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/sensors/lsm6dso32.h>
+#include <nuttx/sensors/sensor.h>
+#include <nuttx/signal.h>
+#include <stdio.h>
+#include <sys/types.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* The value that should be in the WHO_AM_I register. */
+
+#define WHO_AM_I_VAL 0x6c
+
+/* Convert milli Gs to m/s^2 */
+
+#define MILLIG_TO_MS2 (0.0098067f)
+
+/* Convert milli-dps to rad/s */
+
+#define MDPS_TO_RADS (3.141592653f / (180.0f * 1000.0f))
+
+#ifndef CONFIG_SENSORS_LSM6DSO32_I2C_FREQUENCY
+#define CONFIG_SENSORS_LSM6DSO32_I2C_FREQUENCY 400000
+#endif /* CONFIG_SENSORS_LSM6DSO32_I2C_FREQUENCY */
+
+/* Number of measurement rounds for gyro self test */
+
+#define GYRO_SELFTEST_ROUNDS 5
+
+/* Minimum and maximum values for self-test at +/-2000dps, converted from
+ * 1dps/LSB to 70mdps/LSB
+ */
+
+#define GYRO_ST_MIN ((150 * 1000) / 70)
+#define GYRO_ST_MAX ((700 * 1000) / 70)
+
+#define XL_SELFTEST_ROUNDS 5
+
+/* Minimum and maximum values for self-test at +/-4g in 1mg/LSB converted to
+ * 0.122mg/LSB
+ */
+
+#define XL_ST_MIN (50 / 0.122f)
+#define XL_ST_MAX (1700 / 0.122f)
+
+/* Min & max representable accel offset in g using 2^{-10}g/LSB */
+
+#define XL_10_W_MAX (127.0f / (1 << 10))
+#define XL_10_W_MIN (-127.0f / (1 << 10))
+
+/* Min & max representable accel offset in g using 2^{-6}g/LSB */
+
+#define XL_6_W_MAX (127.0f / (1 << 6))
+#define XL_6_W_MIN (-127.0f / (1 << 6))
+
+/* Registers */
+
+#define WHO_AM_I 0x0f   /* Hard-coded address on I2C bus. */
+#define TIMESTAMP0 0x40 /* First timestamp register (32 bits) */
+#define STATUS_REG 0x1e /* The status register */
+#define CTRL1_XL 0x10   /* Accel control reg 1 */
+#define CTRL2_G 0x11    /* Gyro control reg 2 */
+#define CTRL3_C 0x12    /* Control reg 3 */
+#define CTRL4_C 0x13    /* Control reg 4 */
+#define CTRL5_C 0x14    /* Control reg 5 */
+#define CTRL6_C 0x15    /* Control reg 6 */
+#define CTRL7_G 0x16    /* Control reg 7 */
+#define CTRL8_XL 0x17   /* Control reg 8 */
+#define CTRL9_XL 0x18   /* Control reg 9 */
+#define CTRL10_C 0x19   /* Control reg 10 */
+#define FIFO_CTRL4 0x0a /* The fourth FIFO control reg  */
+#define INT1_CTRL 0x0d  /* INT1 pin control */
+#define INT2_CTRL 0x0e  /* INT2 pin control */
+#define OUT_TEMP_L 0x20 /* Temp output low byte. */
+#define OUT_TEMP_H 0x21 /* Temp output high byte. */
+#define OUTX_L_G 0x22   /* Gyro pitch axis (X) low byte. */
+#define OUTX_H_G 0x23   /* Gyro pitch axis (X) high byte. */
+#define OUTY_L_G 0x24   /* Gyro roll axis (Y) low byte. */
+#define OUTY_H_G 0x25   /* Gyro roll axis (Y) high byte. */
+#define OUTZ_L_G 0x26   /* Gyro yaw axis (Z) low byte. */
+#define OUTZ_H_G 0x27   /* Gyro yaw axis (Z) high byte. */
+#define OUTX_L_A 0x28   /* Accel (X) low byte. */
+#define OUTX_H_A 0x29   /* Accel (X) high byte. */
+#define OUTY_L_A 0x2a   /* Accel (Y) low byte. */
+#define OUTY_H_A 0x2b   /* Accel (Y) high byte. */
+#define OUTZ_L_A 0x2c   /* Accel (Z) low byte. */
+#define OUTZ_H_A 0x2d   /* Accel (Z) high byte. */
+#define X_OFS_USR 0x73  /* X offset correction accel */
+#define Y_OFS_USR 0x74  /* Y offset correction accel */
+#define Z_OFS_USR 0x75  /* Z offset correction accel */
+
+/* Bits */
+
+#define BIT_STATUS_XLDA (1 << 0)    /* Accel data ready */
+#define BIT_STATUS_GDA (1 << 1)     /* Gyro data ready */
+#define BIT_STATUS_TDA (1 << 2)     /* Temp data ready */
+#define BIT_G_ST_POS (1 << 2)       /* Enable gyro positive self-test */
+#define BIT_XL_ST_POS (1 << 0)      /* Enable accel positive self-test */
+#define BIT_USR_OFF_W (1 << 3)      /* User offset weight */
+#define BIT_USR_OFF_ON_OUT (1 << 1) /* User offset enable */
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* ODRs common to the accelerometer and the gyroscope. NOTE: this driver does
+ * implement the 1.6Hz low power ODR for the accelerometer.
+ */
+
+enum lsm6dso32_odr_e
+{
+  ODR_OFF = 0x0,    /* Sensor Deactivated */
+  ODR_12_5HZ = 0x1, /* 12.5Hz Rate. */
+  ODR_26HZ = 0x2,   /* 26Hz Rate. */
+  ODR_52HZ = 0x3,   /* 52Hz Rate. */
+  ODR_104HZ = 0x4,  /* 104Hz Rate */
+  ODR_208HZ = 0x5,  /* 208Hz Rate */
+  ODR_416HZ = 0x6,  /* 416Hz Rate */
+  ODR_833HZ = 0x7,  /* 833Hz Rate */
+  ODR_1660HZ = 0x8, /* 1.66kHz Rate */
+  ODR_3330HZ = 0x9, /* 3.33kHz Rate */
+  ODR_6660HZ = 0xa, /* 6.66kHz Rate */
+  ODR_1_6HZ = 0xb,  /* 1.6Hz Rate */
+};
+
+/* Represents a lower half sensor driver of the LSM6DSO32 */
+
+struct lsm6dso32_sens_s
+{
+  FAR struct sensor_lowerhalf_s lower; /* Lower-half sensor driver */
+  FAR struct lsm6dso32_dev_s *dev;     /* Reference to parent device */
+  bool enabled;                        /* If this sensor is enabled */
+  enum lsm6dso32_odr_e odr;            /* Measurement interval of this
+                                        * sensor */
+  int fsr;                             /* Full scale range of this sensor.
+                                        * Can be from either gyro or accel
+                                        * FSR enum. */
+  sem_t run;                           /* Polling cycle lock */
+  enum lsm6dso32_int_e intpin;         /* The interrupt pin for this device */
+  bool interrupts;                     /* Whether or not interrupts are
+                                        * enabled. */
+  struct work_s work;                  /* Interrupt work queue
+                                        * structure */
+};
+
+/* Represents the LSM6DSO23 IMU device */
+
+struct lsm6dso32_dev_s
+{
+  struct lsm6dso32_sens_s gyro;  /* Gyroscope */
+  struct lsm6dso32_sens_s accel; /* Accelerometer lower half */
+  FAR struct i2c_master_s *i2c;  /* I2C interface. */
+  uint8_t addr;                  /* I2C address. */
+  float gy_off[3];               /* Offsets for gyroscope measurements */
+  mutex_t devlock;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int lsm6dso32_control(FAR struct sensor_lowerhalf_s *lower,
+                             FAR struct file *filep, int cmd,
+                             unsigned long arg);
+static int lsm6dso32_activate(FAR struct sensor_lowerhalf_s *lower,
+                              FAR struct file *filep, bool enable);
+static int lsm6dso32_set_interval(FAR struct sensor_lowerhalf_s *lower,
+                                  FAR struct file *filep,
+                                  FAR uint32_t *period_us);
+static int lsm6dso32_selftest(FAR struct sensor_lowerhalf_s *lower,
+                              FAR struct file *filep, unsigned long arg);
+static int lsm6dso32_set_calibvalue(FAR struct sensor_lowerhalf_s *lower,
+                                    FAR struct file *filep,
+                                    unsigned long arg);
+static int lsm6dso32_get_info(FAR struct sensor_lowerhalf_s *lower,
+                              FAR struct file *filep,
+                              FAR struct sensor_device_info_s *info);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* ODR frequencies to measurement intervals in microseconds */
+
+static const uint32_t ODR_INTERVAL[] =
+{
+  [ODR_OFF] = 0,      [ODR_12_5HZ] = 80000, [ODR_26HZ] = 38462,

Review Comment:
   You shouldn't use designated initializers in common code. NuttX common code 
should be C89, and this feature is from C99. 
   
   I know that some sensors use this approach but this is against NuttX 
standard and should be fixed some day: 
https://nuttx.apache.org/docs/latest/contributing/coding_style.html#initializers
   



-- 
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.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to