xiaoxiang781216 commented on code in PR #16836:
URL: https://github.com/apache/nuttx/pull/16836#discussion_r2270719682


##########
drivers/analog/ads7046.c:
##########
@@ -0,0 +1,284 @@
+/****************************************************************************
+ * drivers/analog/ads7046.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <sys/types.h>
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <assert.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/analog/adc.h>
+#include <nuttx/analog/ioctl.h>
+#include <nuttx/analog/ads7046.h>
+
+#if defined(CONFIG_SPI) && defined(CONFIG_ADC_ADS7046)
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Device uses SPI Mode 1: CKPOL = 0, CKPHA = 1 */
+
+#define ADS7046_SPI_MODE  (SPIDEV_MODE1)
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct ads7046_dev_s
+{
+  FAR struct spi_dev_s *spi;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* SPI Helpers */
+
+static void ads7046_lock(FAR struct spi_dev_s *spi);
+
+static void ads7046_unlock(FAR struct spi_dev_s *spi);
+
+/* Character driver methods */
+
+static int ads7046_open(FAR struct file *filep);
+
+static int ads7046_close(FAR struct file *filep);
+
+static int ads7046_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations adc7046_fops =
+{
+  ads7046_open,     /* open */
+  ads7046_close,    /* close */
+  NULL,             /* read */
+  NULL,             /* write */
+  NULL,             /* seek */
+  ads7046_ioctl,    /* ioctl */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static void ads7046_lock(FAR struct spi_dev_s *spi)
+{
+  SPI_LOCK(spi, true);
+}
+
+static void ads7046_unlock(FAR struct spi_dev_s *spi)
+{
+  SPI_LOCK(spi, false);
+}
+
+static void ads7046_config_spi(FAR struct spi_dev_s *spi)
+{
+  SPI_SETMODE(spi, ADS7046_SPI_MODE);
+  SPI_SETBITS(spi, 16);
+  SPI_HWFEATURES(spi, 0);
+  SPI_SETFREQUENCY(spi, CONFIG_ADS7046_FREQUENCY);
+}
+
+static int ads7046_open(FAR struct file *filep)
+{
+  FAR struct inode          *inode  = filep->f_inode;
+  FAR struct ads7046_dev_s  *priv   = inode->i_private;
+
+  ads7046_config_spi(priv->spi);
+  up_mdelay(100);
+
+  return OK;
+}
+
+static int ads7046_close(FAR struct file *filep)
+{
+  UNUSED(filep);
+  return OK;
+}
+
+static void ads7046_read_conversion_result(
+  FAR const struct ads7046_dev_s *dev, FAR uint16_t *conversion_result,
+  bool fast_unsafe)
+{
+  *conversion_result = 0;
+
+  if (!fast_unsafe)
+    {
+      ads7046_lock(dev->spi);
+      ads7046_config_spi(dev->spi);
+    }
+
+  SPI_SELECT(dev->spi, 0, true);
+
+  SPI_RECVBLOCK(dev->spi, conversion_result, 1);
+
+  SPI_SELECT(dev->spi, 0, false);
+  if (!fast_unsafe)
+    {
+      ads7046_unlock(dev->spi);
+    }
+
+  *conversion_result = (*conversion_result & 0b0111111111111000) >> 3;
+
+  /* ainfo("conversion_result = %x\n", *conversion_result); */
+}
+
+static void ads7046_offset_calibration(FAR const struct ads7046_dev_s *dev)
+{
+  ads7046_lock(dev->spi);
+  ads7046_config_spi(dev->spi);
+  SPI_SELECT(dev->spi, 0, true);
+
+  SPI_SNDBLOCK(dev->spi, 0, 4);
+
+  SPI_SELECT(dev->spi, 0, false);
+  ads7046_unlock(dev->spi);
+
+  ainfo("requested offset calibration\n");
+}
+
+static int ads7046_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode          *inode  = filep->f_inode;
+  FAR struct ads7046_dev_s  *priv   = inode->i_private;
+
+  int                       ret = OK;
+
+  switch (cmd)
+    {
+        /* Read the result of an analog conversion */
+
+        case ANIOC_ADS7046_READ:
+        {
+        FAR uint16_t *data = (FAR uint16_t *)((uintptr_t)arg);
+        ads7046_read_conversion_result(priv, data, false);
+        }
+        break;
+
+        /* Read the result of an analog conversion (skip SPI locking &
+         * reconfiguring - HIC SUNT DRACONES!)
+         */
+
+        case ANIOC_ADS7046_READ_FASTUNSAFE:
+        {
+        FAR uint16_t *data = (FAR uint16_t *)((uintptr_t)arg);
+        ads7046_read_conversion_result(priv, data, true);
+        }
+        break;
+
+        /* Start an offset calibration */
+
+        case ANIOC_ADS7046_OFFCAL:
+        {
+        ads7046_offset_calibration(priv);
+        }
+        break;
+
+        /* Command was not recognized */
+
+        default:
+        {
+        _err("ERROR: Unrecognized cmd: %d\n", cmd);
+        ret = -ENOTTY;
+        break;
+        }
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: ads7046_register
+ *
+ * Description:
+ *   Register the ADS7046 character device as 'devpath'
+ *
+ * Input Parameters:
+ *   devpath  - The full path to the driver to register. E.g., "/dev/adc0"
+ *   spi      - An instance of the SPI interface to use.
+ *   devno    - SPI device number
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int ads7046_register(FAR const char *devpath, FAR struct spi_dev_s *spi,
+                     unsigned int devno)
+{
+  UNUSED(devno);
+
+  /* Sanity check */
+
+  DEBUGASSERT(spi != NULL);
+
+  /* Initialize the ADS7046 device structure */
+
+  struct ads7046_dev_s *priv = kmm_malloc(sizeof(struct ads7046_dev_s));
+  if (priv == NULL)
+    {
+      _err("ERROR: Failed to allocate instance %s (%d)\n", strerror(errno),
+           errno);
+      return -ENOMEM;
+    }
+
+  priv->spi = spi;
+
+  /* Register the character driver */
+
+  int ret = register_driver(devpath, &adc7046_fops, 0666, priv);
+  if (ret < 0)
+    {
+      _err("ERROR: Failed to register driver: %s (%d)\n", strerror(-ret),

Review Comment:
   a
   ```suggestion
         aerr("ERROR: Failed to register driver: %s (%d)\n", strerror(-ret),
   ```



##########
drivers/analog/ads7046.c:
##########
@@ -0,0 +1,284 @@
+/****************************************************************************
+ * drivers/analog/ads7046.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <sys/types.h>
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <assert.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/analog/adc.h>
+#include <nuttx/analog/ioctl.h>
+#include <nuttx/analog/ads7046.h>
+
+#if defined(CONFIG_SPI) && defined(CONFIG_ADC_ADS7046)
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Device uses SPI Mode 1: CKPOL = 0, CKPHA = 1 */
+
+#define ADS7046_SPI_MODE  (SPIDEV_MODE1)
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct ads7046_dev_s
+{
+  FAR struct spi_dev_s *spi;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* SPI Helpers */
+
+static void ads7046_lock(FAR struct spi_dev_s *spi);
+
+static void ads7046_unlock(FAR struct spi_dev_s *spi);
+
+/* Character driver methods */
+
+static int ads7046_open(FAR struct file *filep);
+
+static int ads7046_close(FAR struct file *filep);
+
+static int ads7046_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations adc7046_fops =
+{
+  ads7046_open,     /* open */
+  ads7046_close,    /* close */
+  NULL,             /* read */
+  NULL,             /* write */
+  NULL,             /* seek */
+  ads7046_ioctl,    /* ioctl */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static void ads7046_lock(FAR struct spi_dev_s *spi)
+{
+  SPI_LOCK(spi, true);
+}
+
+static void ads7046_unlock(FAR struct spi_dev_s *spi)
+{
+  SPI_LOCK(spi, false);
+}
+
+static void ads7046_config_spi(FAR struct spi_dev_s *spi)
+{
+  SPI_SETMODE(spi, ADS7046_SPI_MODE);
+  SPI_SETBITS(spi, 16);
+  SPI_HWFEATURES(spi, 0);
+  SPI_SETFREQUENCY(spi, CONFIG_ADS7046_FREQUENCY);
+}
+
+static int ads7046_open(FAR struct file *filep)
+{
+  FAR struct inode          *inode  = filep->f_inode;
+  FAR struct ads7046_dev_s  *priv   = inode->i_private;
+
+  ads7046_config_spi(priv->spi);
+  up_mdelay(100);
+
+  return OK;
+}
+
+static int ads7046_close(FAR struct file *filep)
+{
+  UNUSED(filep);
+  return OK;
+}
+
+static void ads7046_read_conversion_result(
+  FAR const struct ads7046_dev_s *dev, FAR uint16_t *conversion_result,
+  bool fast_unsafe)
+{
+  *conversion_result = 0;
+
+  if (!fast_unsafe)
+    {
+      ads7046_lock(dev->spi);
+      ads7046_config_spi(dev->spi);
+    }
+
+  SPI_SELECT(dev->spi, 0, true);
+
+  SPI_RECVBLOCK(dev->spi, conversion_result, 1);
+
+  SPI_SELECT(dev->spi, 0, false);
+  if (!fast_unsafe)
+    {
+      ads7046_unlock(dev->spi);
+    }
+
+  *conversion_result = (*conversion_result & 0b0111111111111000) >> 3;
+
+  /* ainfo("conversion_result = %x\n", *conversion_result); */
+}
+
+static void ads7046_offset_calibration(FAR const struct ads7046_dev_s *dev)
+{
+  ads7046_lock(dev->spi);
+  ads7046_config_spi(dev->spi);
+  SPI_SELECT(dev->spi, 0, true);
+
+  SPI_SNDBLOCK(dev->spi, 0, 4);
+
+  SPI_SELECT(dev->spi, 0, false);
+  ads7046_unlock(dev->spi);
+
+  ainfo("requested offset calibration\n");
+}
+
+static int ads7046_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode          *inode  = filep->f_inode;
+  FAR struct ads7046_dev_s  *priv   = inode->i_private;
+
+  int                       ret = OK;
+
+  switch (cmd)
+    {
+        /* Read the result of an analog conversion */
+
+        case ANIOC_ADS7046_READ:
+        {
+        FAR uint16_t *data = (FAR uint16_t *)((uintptr_t)arg);

Review Comment:
   ```suggestion
             FAR uint16_t *data = (FAR uint16_t *)((uintptr_t)arg);
   ```
   and other places



##########
drivers/analog/ads7046.c:
##########
@@ -0,0 +1,284 @@
+/****************************************************************************
+ * drivers/analog/ads7046.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <sys/types.h>
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <assert.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/analog/adc.h>
+#include <nuttx/analog/ioctl.h>
+#include <nuttx/analog/ads7046.h>
+
+#if defined(CONFIG_SPI) && defined(CONFIG_ADC_ADS7046)
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Device uses SPI Mode 1: CKPOL = 0, CKPHA = 1 */
+
+#define ADS7046_SPI_MODE  (SPIDEV_MODE1)
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct ads7046_dev_s
+{
+  FAR struct spi_dev_s *spi;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* SPI Helpers */
+
+static void ads7046_lock(FAR struct spi_dev_s *spi);
+
+static void ads7046_unlock(FAR struct spi_dev_s *spi);
+
+/* Character driver methods */
+
+static int ads7046_open(FAR struct file *filep);
+
+static int ads7046_close(FAR struct file *filep);
+
+static int ads7046_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations adc7046_fops =
+{
+  ads7046_open,     /* open */
+  ads7046_close,    /* close */
+  NULL,             /* read */
+  NULL,             /* write */
+  NULL,             /* seek */
+  ads7046_ioctl,    /* ioctl */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static void ads7046_lock(FAR struct spi_dev_s *spi)
+{
+  SPI_LOCK(spi, true);
+}
+
+static void ads7046_unlock(FAR struct spi_dev_s *spi)
+{
+  SPI_LOCK(spi, false);
+}
+
+static void ads7046_config_spi(FAR struct spi_dev_s *spi)
+{
+  SPI_SETMODE(spi, ADS7046_SPI_MODE);
+  SPI_SETBITS(spi, 16);
+  SPI_HWFEATURES(spi, 0);
+  SPI_SETFREQUENCY(spi, CONFIG_ADS7046_FREQUENCY);
+}
+
+static int ads7046_open(FAR struct file *filep)
+{
+  FAR struct inode          *inode  = filep->f_inode;
+  FAR struct ads7046_dev_s  *priv   = inode->i_private;
+
+  ads7046_config_spi(priv->spi);
+  up_mdelay(100);
+
+  return OK;
+}
+
+static int ads7046_close(FAR struct file *filep)
+{
+  UNUSED(filep);
+  return OK;
+}
+
+static void ads7046_read_conversion_result(
+  FAR const struct ads7046_dev_s *dev, FAR uint16_t *conversion_result,
+  bool fast_unsafe)
+{
+  *conversion_result = 0;
+
+  if (!fast_unsafe)
+    {
+      ads7046_lock(dev->spi);
+      ads7046_config_spi(dev->spi);
+    }
+
+  SPI_SELECT(dev->spi, 0, true);
+
+  SPI_RECVBLOCK(dev->spi, conversion_result, 1);
+
+  SPI_SELECT(dev->spi, 0, false);
+  if (!fast_unsafe)
+    {
+      ads7046_unlock(dev->spi);
+    }
+
+  *conversion_result = (*conversion_result & 0b0111111111111000) >> 3;
+
+  /* ainfo("conversion_result = %x\n", *conversion_result); */
+}
+
+static void ads7046_offset_calibration(FAR const struct ads7046_dev_s *dev)
+{
+  ads7046_lock(dev->spi);
+  ads7046_config_spi(dev->spi);
+  SPI_SELECT(dev->spi, 0, true);
+
+  SPI_SNDBLOCK(dev->spi, 0, 4);
+
+  SPI_SELECT(dev->spi, 0, false);
+  ads7046_unlock(dev->spi);
+
+  ainfo("requested offset calibration\n");
+}
+
+static int ads7046_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode          *inode  = filep->f_inode;
+  FAR struct ads7046_dev_s  *priv   = inode->i_private;
+
+  int                       ret = OK;
+
+  switch (cmd)
+    {
+        /* Read the result of an analog conversion */
+
+        case ANIOC_ADS7046_READ:

Review Comment:
   ```suggestion
         case ANIOC_ADS7046_READ:
   ```



##########
drivers/analog/ads7046.c:
##########
@@ -0,0 +1,284 @@
+/****************************************************************************
+ * drivers/analog/ads7046.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <sys/types.h>
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <assert.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/analog/adc.h>
+#include <nuttx/analog/ioctl.h>
+#include <nuttx/analog/ads7046.h>
+
+#if defined(CONFIG_SPI) && defined(CONFIG_ADC_ADS7046)

Review Comment:
   remove, don't need



##########
drivers/analog/ads7046.c:
##########
@@ -0,0 +1,284 @@
+/****************************************************************************
+ * drivers/analog/ads7046.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * 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 <sys/types.h>
+#include <sys/ioctl.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <assert.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/analog/adc.h>
+#include <nuttx/analog/ioctl.h>
+#include <nuttx/analog/ads7046.h>
+
+#if defined(CONFIG_SPI) && defined(CONFIG_ADC_ADS7046)
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Device uses SPI Mode 1: CKPOL = 0, CKPHA = 1 */
+
+#define ADS7046_SPI_MODE  (SPIDEV_MODE1)
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct ads7046_dev_s
+{
+  FAR struct spi_dev_s *spi;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* SPI Helpers */
+
+static void ads7046_lock(FAR struct spi_dev_s *spi);
+
+static void ads7046_unlock(FAR struct spi_dev_s *spi);
+
+/* Character driver methods */
+
+static int ads7046_open(FAR struct file *filep);
+
+static int ads7046_close(FAR struct file *filep);
+
+static int ads7046_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct file_operations adc7046_fops =
+{
+  ads7046_open,     /* open */
+  ads7046_close,    /* close */
+  NULL,             /* read */
+  NULL,             /* write */
+  NULL,             /* seek */
+  ads7046_ioctl,    /* ioctl */
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static void ads7046_lock(FAR struct spi_dev_s *spi)
+{
+  SPI_LOCK(spi, true);
+}
+
+static void ads7046_unlock(FAR struct spi_dev_s *spi)
+{
+  SPI_LOCK(spi, false);
+}
+
+static void ads7046_config_spi(FAR struct spi_dev_s *spi)
+{
+  SPI_SETMODE(spi, ADS7046_SPI_MODE);
+  SPI_SETBITS(spi, 16);
+  SPI_HWFEATURES(spi, 0);
+  SPI_SETFREQUENCY(spi, CONFIG_ADS7046_FREQUENCY);
+}
+
+static int ads7046_open(FAR struct file *filep)
+{
+  FAR struct inode          *inode  = filep->f_inode;
+  FAR struct ads7046_dev_s  *priv   = inode->i_private;
+
+  ads7046_config_spi(priv->spi);
+  up_mdelay(100);
+
+  return OK;
+}
+
+static int ads7046_close(FAR struct file *filep)
+{
+  UNUSED(filep);
+  return OK;
+}
+
+static void ads7046_read_conversion_result(
+  FAR const struct ads7046_dev_s *dev, FAR uint16_t *conversion_result,
+  bool fast_unsafe)
+{
+  *conversion_result = 0;
+
+  if (!fast_unsafe)
+    {
+      ads7046_lock(dev->spi);
+      ads7046_config_spi(dev->spi);
+    }
+
+  SPI_SELECT(dev->spi, 0, true);
+
+  SPI_RECVBLOCK(dev->spi, conversion_result, 1);
+
+  SPI_SELECT(dev->spi, 0, false);
+  if (!fast_unsafe)
+    {
+      ads7046_unlock(dev->spi);
+    }
+
+  *conversion_result = (*conversion_result & 0b0111111111111000) >> 3;
+
+  /* ainfo("conversion_result = %x\n", *conversion_result); */
+}
+
+static void ads7046_offset_calibration(FAR const struct ads7046_dev_s *dev)
+{
+  ads7046_lock(dev->spi);
+  ads7046_config_spi(dev->spi);
+  SPI_SELECT(dev->spi, 0, true);
+
+  SPI_SNDBLOCK(dev->spi, 0, 4);
+
+  SPI_SELECT(dev->spi, 0, false);
+  ads7046_unlock(dev->spi);
+
+  ainfo("requested offset calibration\n");
+}
+
+static int ads7046_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode          *inode  = filep->f_inode;
+  FAR struct ads7046_dev_s  *priv   = inode->i_private;
+
+  int                       ret = OK;
+
+  switch (cmd)
+    {
+        /* Read the result of an analog conversion */

Review Comment:
   ```suggestion
         /* Read the result of an analog conversion */
   ```



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