casaroli commented on code in PR #21516:
URL: https://github.com/apache/nuttx/pull/21516#discussion_r4535178021
##########
boards/arm/imxrt/imxrt1180-evk/src/imxrt_bringup.c:
##########
@@ -93,6 +96,14 @@ int imxrt_bringup(void)
{
int ret = OK;
+#ifdef CONFIG_IMXRT_ADC
+ ret = imxrt_adc_initialize();
Review Comment:
`imxrt_adc_initialize()` still has no prototype in any header at
d1f00a21de3, so this call is an implicit declaration: `imxrt_bringup.c:100:9:
error: implicit declaration of function 'imxrt_adc_initialize'`
(arm-none-eabi-gcc 13.2 with -Werror; GCC 14 fails also without -Werror).
Fix: declare `int imxrt_adc_initialize(void);` in
`boards/arm/imxrt/imxrt1180-evk/src/imxrt1180-evk.h`.
##########
arch/arm/src/imxrt/imxrt_adc_ver3.c:
##########
@@ -0,0 +1,495 @@
+/****************************************************************************
+ * arch/arm/src/imxrt/imxrt_adc_ver3.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 <errno.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <nuttx/analog/adc.h>
+#include <nuttx/analog/ioctl.h>
+#include <nuttx/arch.h>
+#include <nuttx/irq.h>
+
+#include "arm_internal.h"
+#include "chip.h"
+#include "hardware/imxrt_adc.h"
+#include "hardware/imxrt_pinmux.h"
+#include "imxrt_gpio.h"
+#include "imxrt_periphclks.h"
+
+#ifdef CONFIG_IMXRT_ADC
+#if defined(CONFIG_IMXRT_ADC1) || defined(CONFIG_IMXRT_ADC2)
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+#define ADC_MAX_CHANNELS 16
+#define ADC2_MAX_CHANNELS 14
+#define IMXRT_ADC_PIN(n) \
+ IOMUX_PIN(IMXRT_PADCFG(0, 63 + (n), 0, 0, IMXRT_PADCFG_NO_DSYIDX, 0), \
+ IOMUXC_PAD_IBE_OFF, IOMUXC_MUX_SION_OFF)
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct imxrt_adc_ver3_s
+{
+ const struct adc_callback_s *cb;
+ uint8_t intf;
+ uint32_t base;
+ int irq;
+ uint8_t initialized;
+ uint8_t nchannels;
+ uint8_t chanlist[ADC_MAX_CHANNELS];
+ uint8_t current;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int adc_bind(struct adc_dev_s *dev,
+ const struct adc_callback_s *callback);
+static void adc_reset(struct adc_dev_s *dev);
+static int adc_setup(struct adc_dev_s *dev);
+static void adc_shutdown(struct adc_dev_s *dev);
+static void adc_rxint(struct adc_dev_s *dev, bool enable);
+static int adc_ioctl(struct adc_dev_s *dev, int cmd, unsigned long arg);
+static int adc_interrupt(int irq, void *context, void *arg);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct adc_ops_s g_adcops =
+{
+ .ao_bind = adc_bind,
+ .ao_reset = adc_reset,
+ .ao_setup = adc_setup,
+ .ao_shutdown = adc_shutdown,
+ .ao_rxint = adc_rxint,
+ .ao_ioctl = adc_ioctl,
+};
+
+#ifdef CONFIG_IMXRT_ADC1
+static struct imxrt_adc_ver3_s g_adcpriv1 =
+{
+ .intf = 1,
+ .base = IMXRT_ADC1_BASE,
+ .irq = IMXRT_IRQ_ADC1
+};
+static struct adc_dev_s g_adcdev1 =
+{
+ &g_adcops,
+ &g_adcpriv1
+};
+
+static const gpio_pinset_t g_adcpinlist1[ADC_MAX_CHANNELS] =
+{
+ IMXRT_ADC_PIN(16),
+ IMXRT_ADC_PIN(14),
+ IMXRT_ADC_PIN(12),
+ IMXRT_ADC_PIN(10),
+ IMXRT_ADC_PIN(8),
+ IMXRT_ADC_PIN(6),
+ IMXRT_ADC_PIN(4),
+ IMXRT_ADC_PIN(2),
+ IMXRT_ADC_PIN(17),
+ IMXRT_ADC_PIN(15),
+ IMXRT_ADC_PIN(13),
+ IMXRT_ADC_PIN(11),
+ IMXRT_ADC_PIN(9),
+ IMXRT_ADC_PIN(7),
+ IMXRT_ADC_PIN(5),
+ IMXRT_ADC_PIN(3),
+};
+#endif
+
+#ifdef CONFIG_IMXRT_ADC2
+static struct imxrt_adc_ver3_s g_adcpriv2 =
+{
+ .intf = 2,
+ .base = IMXRT_ADC2_BASE,
+ .irq = IMXRT_IRQ_ADC2
+};
+static struct adc_dev_s g_adcdev2 =
+{
+ &g_adcops,
+ &g_adcpriv2
+};
+
+static const gpio_pinset_t g_adcpinlist2[ADC2_MAX_CHANNELS] =
+{
+ IMXRT_ADC_PIN(18),
+ IMXRT_ADC_PIN(20),
+ IMXRT_ADC_PIN(22),
+ IMXRT_ADC_PIN(24),
+ IMXRT_ADC_PIN(26),
+ IMXRT_ADC_PIN(28),
+ IMXRT_ADC_PIN(30),
+ IMXRT_ADC_PIN(19),
+ IMXRT_ADC_PIN(21),
+ IMXRT_ADC_PIN(23),
+ IMXRT_ADC_PIN(25),
+ IMXRT_ADC_PIN(27),
+ IMXRT_ADC_PIN(29),
+ IMXRT_ADC_PIN(31),
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static inline uint32_t adc_getreg(struct imxrt_adc_ver3_s *priv,
+ uint32_t offset)
+{
+ return getreg32(priv->base + offset);
+}
+
+static inline void adc_putreg(struct imxrt_adc_ver3_s *priv,
+ uint32_t offset, uint32_t value)
+{
+ putreg32(value, priv->base + offset);
+}
+
+/****************************************************************************
+ * Name: adc_bind
+ *
+ * Description:
+ * Bind the upper-half driver callbacks to the lower-half implementation.
+ * This must be called early in order to receive ADC event notifications.
+ *
+ ****************************************************************************/
+
+static int adc_bind(struct adc_dev_s *dev,
+ const struct adc_callback_s *callback)
+{
+ ((struct imxrt_adc_ver3_s *)dev->ad_priv)->cb = callback;
+ return OK;
+}
+
+/****************************************************************************
+ * Name: adc_reset
+ *
+ * Description:
+ * Reset the ADC device. Called early to initialize the hardware. This
+ * is called, before adc_setup() and on error conditions.
+ *
+ ****************************************************************************/
+
+static void adc_reset(struct adc_dev_s *dev)
+{
+ struct imxrt_adc_ver3_s *priv = dev->ad_priv;
+
+ if (priv->initialized != 0)
+ {
+ return;
+ }
+
+ if (priv->intf == 1)
+ {
+ imxrt_clockall_adc1();
+ }
+ else
+ {
+ imxrt_clockall_adc2();
+ }
+
+ adc_putreg(priv, IMXRT_ADC_CTRL_OFFSET, IMXRT_ADC_CTRL_RST);
+ adc_putreg(priv, IMXRT_ADC_CTRL_OFFSET, 0);
+ adc_putreg(priv, IMXRT_ADC_CFG_OFFSET, IMXRT_ADC_CFG_PWREN |
+ (0x10u << IMXRT_ADC_CFG_PUDLY_SHIFT));
+ adc_putreg(priv, IMXRT_ADC_FCTRL0_OFFSET, IMXRT_ADC_FCTRL_FWMARK(0));
+ adc_putreg(priv, IMXRT_ADC_IE_OFFSET, 0);
+
+ /* Keep calibration out of the reset path until the gain-result sequence
+ * (GCC/GCR) is implemented. The SDK examples initialize this way too.
+ */
+
+ adc_putreg(priv, IMXRT_ADC_CTRL_OFFSET, IMXRT_ADC_CTRL_ADCEN);
+
+ /* Pad configuration */
+
+ for (int i = 0; i < priv->nchannels; i++)
+ {
+ DEBUGASSERT(priv->chanlist[i] < ADC_MAX_CHANNELS);
+ if (priv->intf == 1)
+ {
+ imxrt_config_gpio(g_adcpinlist1[priv->chanlist[i]]);
+ }
+ else
+ {
+ imxrt_config_gpio(g_adcpinlist2[priv->chanlist[i]]);
Review Comment:
With only `CONFIG_IMXRT_ADC1=y` this file does not compile: `g_adcpinlist2`
exists only under `CONFIG_IMXRT_ADC2`, so `imxrt_adc_ver3.c:249:29: error:
'g_adcpinlist2' undeclared`. With only ADC2, line 245 fails the same way on
`g_adcpinlist1`.
Fix: put each `imxrt_config_gpio()` call under its own `#ifdef
CONFIG_IMXRT_ADC1` / `#ifdef CONFIG_IMXRT_ADC2`.
##########
boards/arm/imxrt/imxrt1180-evk/src/Makefile:
##########
@@ -24,6 +24,10 @@ include $(TOPDIR)/Make.defs
CSRCS = imxrt_boot.c imxrt_bringup.c imxrt_appinit.c
+ifeq ($(CONFIG_IMXRT_ADC),y)
Review Comment:
The CI check job fails only on this file: "Makefile created/modified but no
corresponding CMakeLists.txt exists". This board has no CMake build at all.
Fix: add `[skip-cmake-parity]` to the commit message, as tools/checkpatch.sh
accepts for a Make-only change.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]