pkarashchenko commented on code in PR #10855:
URL: https://github.com/apache/nuttx/pull/10855#discussion_r1346097230


##########
arch/arm/include/samv7/sam_afec.h:
##########
@@ -0,0 +1,69 @@
+/****************************************************************************
+ * arch/arm/include/samv7/sam_afec.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_ARM_INC_SAMV7_SAM_AFEC_H

Review Comment:
   ```suggestion
   #ifndef __ARCH_ARM_INCLUDE_SAMV7_SAM_AFEC_H
   ```
   



##########
arch/arm/src/samv7/sam_afec.c:
##########
@@ -1009,7 +1013,7 @@ static void afec_shutdown(struct adc_dev_s *dev)
 
 static int afec_ioctl(struct adc_dev_s *dev, int cmd, unsigned long arg)
 {
-  struct samv7_dev_s *priv = (struct samv7_dev_s *)dev->ad_priv;
+  struct samv7_dev_s *priv = (struct samv7_dev_s *) dev->ad_priv;

Review Comment:
   ```suggestion
     struct samv7_dev_s *priv = (struct samv7_dev_s *)dev->ad_priv;
   ```
   



##########
arch/arm/src/samv7/sam_afec.c:
##########
@@ -1021,20 +1025,47 @@ static int afec_ioctl(struct adc_dev_s *dev, int cmd, 
unsigned long arg)
         }
         break;
 #endif
-      case ANIOC_GET_NCHANNELS:
-        {
-          /* Return the number of configured channels */
-
-          ret = priv->nchannels;
-        }
-        break;
-
-      default:
-        {
-          aerr("ERROR: Unknown cmd: %d\n", cmd);
-          ret = -ENOTTY;
-        }
-        break;
+    case ANIOC_GET_NCHANNELS:
+      {
+        /* Return the number of configured channels */
+
+        ret = priv->nchannels;
+      }
+      break;
+    case ANIOC_SAMV7_AFEC_IOCTRL_GAIN:
+      {
+        /* Set the requested gain of the associated channel */
+
+        sam_afec_gain_param_tds *chgain = (sam_afec_gain_param_tds *) arg;
+
+        uint32_t afec_cgr = afec_getreg(priv, SAM_AFEC_CGR_OFFSET);
+        afec_cgr &= ~AFEC_CGR_GAIN_MASK(chgain->channel);
+        afec_cgr |= AFEC_CGR_GAIN(chgain->channel, chgain->gain);
+        afec_putreg(priv, SAM_AFEC_CGR_OFFSET, afec_cgr);
+
+        /* new gain is set, now adjust the offset register */
+        
+        uint16_t offset;
+        if (chgain->gain == 0)
+            offset = 0x200;
+        else if (chgain->gain == 1)
+          offset = 0x100;
+        else if (chgain->gain == 2)
+          offset = 0x40;

Review Comment:
   ```suggestion
           if (chgain->gain == 0)
             {
               offset = 0x200;
             }
           else if (chgain->gain == 1)
             {
               offset = 0x100;
             }
           else if (chgain->gain == 2)
             {
               offset = 0x40;
             }
   ```
   



##########
arch/arm/include/samv7/sam_afec.h:
##########
@@ -0,0 +1,69 @@
+/****************************************************************************
+ * arch/arm/include/samv7/sam_afec.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __ARCH_ARM_INC_SAMV7_SAM_AFEC_H
+#define __ARCH_ARM_INC_SAMV7_SAM_AFEC_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/analog/adc.h>
+
+/* IOCTL Commands ***********************************************************
+ *
+ * Cmd: SAMV7_AFEC_IOCTRL_GAIN           Arg: Channel and Gain
+ *
+ */
+
+#define ANIOC_SAMV7_AFEC_IOCTRL_GAIN           _ANIOC(AN_SAMV7_AFEC_FIRST + 0)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+typedef struct sam_afec_gain_param_s
+{
+  uint8_t channel;  /* channel number of aefc instance */
+  uint8_t gain;     /* gain to be set for the channel 0:1, 1:2, 3:4 */
+}sam_afec_gain_param_tds;

Review Comment:
   ```suggestion
   } sam_afec_gain_param_tds;
   ```
   Why `_tds` and not `_t`?



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