You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2020/07/18 22:31:28 UTC

[GitHub] [incubator-nuttx] acassis opened a new pull request #1422: ESP32: Add driver support to SPI Master and Slave

acassis opened a new pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422


   ## Summary
   This driver was implemented by Dong Heng <do...@espressif.com>
   and modified to fix coding style by Alan Carvalho de Assis.
   ## Impact
   New feature to ESP32
   ## Testing
   ESP-WROVER-KIT
   


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

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



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#discussion_r456842218



##########
File path: arch/xtensa/src/esp32/esp32_spi.c
##########
@@ -0,0 +1,1076 @@
+/****************************************************************************
+ * arch/xtensa/src/esp32/esp32_spi.c
+ *
+ * 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>
+
+#ifdef CONFIG_ESP32_SPI
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <debug.h>
+#include <time.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/irq.h>
+#include <nuttx/clock.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/spi/spi.h>
+
+#include <arch/board/board.h>
+
+#include "esp32_spi.h"
+#include "esp32_gpio.h"
+#include "esp32_cpuint.h"
+
+#include "xtensa.h"
+#include "hardware/esp32_gpio_sigmap.h"
+#include "hardware/esp32_dport.h"
+#include "hardware/esp32_spi.h"
+#include "hardware/esp32_soc.h"
+#include "rom/esp32_gpio.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* SPI Default speed (limited by clock divider) */
+
+#define SPI_FREQ_DEFAULT  400000
+
+/* SPI Device hardware configuration */
+
+struct esp32_spi_config_s
+{
+  uint32_t reg_base;          /* SPI register base address */
+
+  uint32_t clk_freq;          /* SPI clock frequency */
+  enum spi_mode_e mode;       /* SPI default mode */
+
+  uint8_t cs_pin;             /* GPIO configuration for CS */
+  uint8_t mosi_pin;           /* GPIO configuration for MOSI */
+  uint8_t miso_pin;           /* GPIO configuration for MISO */
+  uint8_t clk_pin;            /* GPIO configuration for CLK */
+
+  uint8_t cpu;                /* CPU ID */
+  uint8_t periph;             /* peripher ID */
+  uint8_t irq;                /* Interrupt ID */
+
+  uint32_t clk_bit;           /* Clock enable bit */
+  uint32_t rst_bit;           /* SPI reset bit */
+
+  uint32_t cs_insig;          /* SPI CS input signal index */
+  uint32_t cs_outsig;         /* SPI CS output signal index */
+  uint32_t mosi_insig;        /* SPI MOSI input signal index */
+  uint32_t mosi_outsig;       /* SPI MOSI output signal index */
+  uint32_t miso_insig;        /* SPI MISO input signal index */
+  uint32_t miso_outsig;       /* SPI MISO output signal index */
+  uint32_t clk_insig;         /* SPI CLK input signal index */
+  uint32_t clk_outsig;        /* SPI CLK output signal index */
+};
+
+struct esp32_spi_priv_s
+{
+  /* Externally visible part of the SPI interface */
+
+  struct spi_dev_s spi_dev;
+
+  /* Port configuration */
+
+  const struct esp32_spi_config_s *config;
+
+  int refs;                    /* Referernce count */
+
+  /* Held while chip is selected for mutual exclusion */
+
+  sem_t            exclsem;
+
+  uint32_t         frequency;   /* Requested clock frequency */
+  uint32_t         actual;      /* Actual clock frequency */
+
+  enum spi_mode_e  mode;        /* Actual SPI hardware mode */
+
+  /* Actual SPI send/receive bits once transmission */
+
+  uint8_t          nbits;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int esp32_spi_lock(FAR struct spi_dev_s *dev, bool lock);
+static void esp32_spi_select(FAR struct spi_dev_s *dev,
+                             uint32_t devid,
+                             bool selected);
+static uint32_t esp32_spi_setfrequency(FAR struct spi_dev_s *dev,
+                                       uint32_t frequency);
+static void esp32_spi_setmode(FAR struct spi_dev_s *dev,
+                              enum spi_mode_e mode);
+static void esp32_spi_setbits(FAR struct spi_dev_s *dev, int nbits);
+#ifdef CONFIG_SPI_HWFEATURES
+static int esp32_spi_hwfeatures(FAR struct spi_dev_s *dev,
+                                spi_hwfeatures_t features);
+#endif
+#ifdef CONFIG_SPI_CMDDATA
+static int esp32_spi_cmddata(FAR struct spi_dev_s *dev,
+                             uint32_t devid,
+                             bool cmd);
+#endif
+static uint32_t esp32_spi_send(FAR struct spi_dev_s *dev, uint32_t wd);
+static void esp32_spi_exchange(FAR struct spi_dev_s *dev,
+                               FAR const void *txbuffer,
+                               FAR void *rxbuffer, size_t nwords);
+#ifndef CONFIG_SPI_EXCHANGE
+static void esp32_spi_sndblock(FAR struct spi_dev_s *dev,
+                               FAR const void *txbuffer,
+                               size_t nwords);
+static void esp32_spi_recvblock(FAR struct spi_dev_s *dev,
+                                FAR void *rxbuffer,
+                                size_t nwords);
+#endif
+#ifdef CONFIG_SPI_TRIGGER
+static int esp32_spi_trigger(FAR struct spi_dev_s *dev);
+#endif
+static void esp32_spi_init(FAR struct spi_dev_s *dev);
+static void esp32_spi_deinit(FAR struct spi_dev_s *dev);
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+extern uint8_t esp32_spi2_status(FAR struct spi_dev_s *dev, uint32_t devid);
+extern uint8_t esp32_spi3_status(FAR struct spi_dev_s *dev, uint32_t devid);

Review comment:
       Yes, I'm moving it to the header




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

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



[GitHub] [incubator-nuttx] Ouss4 commented on a change in pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
Ouss4 commented on a change in pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#discussion_r456906160



##########
File path: arch/xtensa/src/esp32/esp32_spi.c
##########
@@ -0,0 +1,1010 @@
+/****************************************************************************
+ * arch/xtensa/src/esp32/esp32_spi.c
+ *
+ * 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>
+
+#ifdef CONFIG_ESP32_SPI
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <debug.h>
+#include <time.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/irq.h>
+#include <nuttx/clock.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/spi/spi.h>
+
+#include <arch/board/board.h>
+
+#include "esp32_spi.h"
+#include "esp32_gpio.h"
+#include "esp32_cpuint.h"
+
+#include "xtensa.h"
+#include "hardware/esp32_gpio_sigmap.h"
+#include "hardware/esp32_dport.h"
+#include "hardware/esp32_spi.h"
+#include "hardware/esp32_soc.h"
+#include "rom/esp32_gpio.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* SPI Default speed (limited by clock divider) */
+
+#define SPI_FREQ_DEFAULT  400000
+
+/* SPI Device hardware configuration */
+
+struct esp32_spi_config_s
+{
+  uint32_t reg_base;          /* SPI register base address */
+
+  uint32_t clk_freq;          /* SPI clock frequency */
+  enum spi_mode_e mode;       /* SPI default mode */
+
+  uint8_t cs_pin;             /* GPIO configuration for CS */
+  uint8_t mosi_pin;           /* GPIO configuration for MOSI */
+  uint8_t miso_pin;           /* GPIO configuration for MISO */
+  uint8_t clk_pin;            /* GPIO configuration for CLK */
+
+  uint8_t cpu;                /* CPU ID */
+  uint8_t periph;             /* peripher ID */
+  uint8_t irq;                /* Interrupt ID */
+
+  uint32_t clk_bit;           /* Clock enable bit */
+  uint32_t rst_bit;           /* SPI reset bit */
+
+  uint32_t cs_insig;          /* SPI CS input signal index */
+  uint32_t cs_outsig;         /* SPI CS output signal index */
+  uint32_t mosi_insig;        /* SPI MOSI input signal index */
+  uint32_t mosi_outsig;       /* SPI MOSI output signal index */
+  uint32_t miso_insig;        /* SPI MISO input signal index */
+  uint32_t miso_outsig;       /* SPI MISO output signal index */
+  uint32_t clk_insig;         /* SPI CLK input signal index */
+  uint32_t clk_outsig;        /* SPI CLK output signal index */
+};
+
+struct esp32_spi_priv_s
+{
+  /* Externally visible part of the SPI interface */
+
+  struct spi_dev_s spi_dev;
+
+  /* Port configuration */
+
+  const struct esp32_spi_config_s *config;
+
+  int refs;                    /* Referernce count */
+
+  /* Held while chip is selected for mutual exclusion */
+
+  sem_t            exclsem;
+
+  uint32_t         frequency;   /* Requested clock frequency */
+  uint32_t         actual;      /* Actual clock frequency */
+
+  enum spi_mode_e  mode;        /* Actual SPI hardware mode */
+
+  /* Actual SPI send/receive bits once transmission */
+
+  uint8_t          nbits;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int esp32_spi_lock(FAR struct spi_dev_s *dev, bool lock);
+static void esp32_spi_select(FAR struct spi_dev_s *dev,
+                             uint32_t devid,
+                             bool selected);
+static uint32_t esp32_spi_setfrequency(FAR struct spi_dev_s *dev,
+                                       uint32_t frequency);
+static void esp32_spi_setmode(FAR struct spi_dev_s *dev,
+                              enum spi_mode_e mode);
+static void esp32_spi_setbits(FAR struct spi_dev_s *dev, int nbits);
+#ifdef CONFIG_SPI_HWFEATURES
+static int esp32_spi_hwfeatures(FAR struct spi_dev_s *dev,
+                                spi_hwfeatures_t features);
+#endif
+static uint32_t esp32_spi_send(FAR struct spi_dev_s *dev, uint32_t wd);
+static void esp32_spi_exchange(FAR struct spi_dev_s *dev,
+                               FAR const void *txbuffer,
+                               FAR void *rxbuffer, size_t nwords);
+#ifndef CONFIG_SPI_EXCHANGE
+static void esp32_spi_sndblock(FAR struct spi_dev_s *dev,
+                               FAR const void *txbuffer,
+                               size_t nwords);
+static void esp32_spi_recvblock(FAR struct spi_dev_s *dev,
+                                FAR void *rxbuffer,
+                                size_t nwords);
+#endif
+#ifdef CONFIG_SPI_TRIGGER
+static int esp32_spi_trigger(FAR struct spi_dev_s *dev);
+#endif
+static void esp32_spi_init(FAR struct spi_dev_s *dev);
+static void esp32_spi_deinit(FAR struct spi_dev_s *dev);
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+#ifdef CONFIG_ESP32_SPI2
+static const struct esp32_spi_config_s esp32_spi2_config =
+{
+  .reg_base     = REG_SPI_BASE(2),
+  .clk_freq     = SPI_FREQ_DEFAULT,
+  .mode         = SPIDEV_MODE0,
+  .cs_pin       = CONFIG_ESP32_SPI2_CSPIN,
+  .mosi_pin     = CONFIG_ESP32_SPI2_MOSIPIN,
+  .miso_pin     = CONFIG_ESP32_SPI2_MISOPIN,
+  .clk_pin      = CONFIG_ESP32_SPI2_CLKPIN,
+  .cpu          = 0,
+  .periph       = ESP32_PERIPH_SPI2,
+  .irq          = ESP32_IRQ_SPI2,
+  .clk_bit      = DPORT_SPI_CLK_EN_2,
+  .rst_bit      = DPORT_SPI_RST_2,
+  .cs_insig     = HSPICS0_IN_IDX,
+  .cs_outsig    = HSPICS0_OUT_IDX,
+  .mosi_insig   = HSPID_IN_IDX,
+  .mosi_outsig  = HSPID_OUT_IDX,
+  .miso_insig   = HSPIQ_IN_IDX,
+  .miso_outsig  = HSPIQ_OUT_IDX,
+  .clk_insig    = HSPICLK_IN_IDX,
+  .clk_outsig   = HSPICLK_OUT_IDX
+};
+
+static const struct spi_ops_s esp32_spi2_ops =
+{
+  .lock              = esp32_spi_lock,
+  .select            = esp32_spi2_select,
+  .setfrequency      = esp32_spi_setfrequency,
+  .setmode           = esp32_spi_setmode,
+  .setbits           = esp32_spi_setbits,
+#ifdef CONFIG_SPI_HWFEATURES
+  .hwfeatures        = esp32_spi_hwfeatures,
+#endif
+  .status            = esp32_spi2_status,
+#ifdef CONFIG_SPI_CMDDATA
+  .cmddata           = esp32_spi2_cmddata,
+#endif
+  .send              = esp32_spi_send,
+#ifdef CONFIG_SPI_EXCHANGE
+  .exchange          = esp32_spi_exchange,
+#else
+  .sndblock          = esp32_spi_sndblock,
+  .recvblock         = esp32_spi_recvblock,
+#endif
+#ifdef CONFIG_SPI_TRIGGER
+  .trigger           = esp32_spi_trigger,
+#endif
+  .registercallback  = NULL,
+};
+
+static struct esp32_spi_priv_s esp32_spi2_priv =
+{
+  .spi_dev =
+              {
+                .ops = &esp32_spi2_ops
+              },
+  .config = &esp32_spi2_config
+};
+#endif /* CONFIG_ESP32_SPI2 */
+
+#ifdef CONFIG_ESP32_SPI3
+static const struct esp32_spi_config_s esp32_spi3_config =
+{
+  .reg_base     = REG_SPI_BASE(3),
+  .clk_freq     = SPI_FREQ_DEFAULT,
+  .mode         = SPIDEV_MODE0,
+  .cs_pin       = CONFIG_ESP32_SPI3_CSPIN,
+  .mosi_pin     = CONFIG_ESP32_SPI3_MOSIPIN,
+  .miso_pin     = CONFIG_ESP32_SPI3_MISOPIN,
+  .clk_pin      = CONFIG_ESP32_SPI3_CLKPIN,
+  .cpu          = 0,
+  .periph       = ESP32_PERIPH_SPI3,
+  .irq          = ESP32_IRQ_SPI3,
+  .clk_bit      = DPORT_SPI_CLK_EN,
+  .rst_bit      = DPORT_SPI_RST,
+  .cs_insig     = VSPICS0_IN_IDX,
+  .cs_outsig    = VSPICS0_OUT_IDX,
+  .mosi_insig   = VSPID_IN_IDX,
+  .mosi_outsig  = VSPID_OUT_IDX,
+  .miso_insig   = VSPIQ_IN_IDX,
+  .miso_outsig  = VSPIQ_OUT_IDX,
+  .clk_insig    = VSPICLK_IN_IDX,
+  .clk_outsig   = VSPICLK_OUT_MUX_IDX
+};
+
+static const struct spi_ops_s esp32_spi3_ops =
+{
+  .lock              = esp32_spi_lock,
+  .select            = esp32_spi3_select,
+  .setfrequency      = esp32_spi_setfrequency,
+  .setmode           = esp32_spi_setmode,
+  .setbits           = esp32_spi_setbits,
+#ifdef CONFIG_SPI_HWFEATURES
+  .hwfeatures        = esp32_spi_hwfeatures,
+#endif
+  .status            = esp32_spi3_status,
+#ifdef CONFIG_SPI_CMDDATA
+  .cmddata           = esp32_spi3_cmddata,
+#endif
+  .send              = esp32_spi_send,
+#ifdef CONFIG_SPI_EXCHANGE
+  .exchange          = esp32_spi_exchange,
+#else
+  .sndblock          = esp32_spi_sndblock,
+  .recvblock         = esp32_spi_recvblock,
+#endif
+#ifdef CONFIG_SPI_TRIGGER
+  .trigger           = esp32_spi_trigger,
+#endif
+  .registercallback  = NULL,
+};
+
+static struct esp32_spi_priv_s esp32_spi3_priv =
+{
+  .spi_dev =
+              {
+                .ops = &esp32_spi3_ops
+              },
+  .config = &esp32_spi3_config
+};
+#endif /* CONFIG_ESP32_SPI3 */
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32_spi_set_reg
+ *
+ * Description:
+ *   Set the contents of the SPI register at offset
+ *
+ * Input Parameters:
+ *   priv   - Private SPI device structure
+ *   offset - Offset to the register of interest
+ *   value  - Value to be written
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+static inline void esp32_spi_set_reg(struct esp32_spi_priv_s *priv,
+                                     int offset,
+                                     uint32_t value)
+{
+  putreg32(value, priv->config->reg_base + offset);
+}
+
+/****************************************************************************
+ * Name: esp32_spi_get_reg
+ *
+ * Description:
+ *   Get the contents of the SPI register at offset
+ *
+ * Input Parameters:
+ *   priv   - Private SPI device structure
+ *   offset - Offset to the register of interest
+ *
+ * Returned Value:
+ *   The contents of the register
+ *
+ ****************************************************************************/
+
+static inline uint32_t esp32_spi_get_reg(struct esp32_spi_priv_s *priv,
+                                         int offset)
+{
+  return getreg32(priv->config->reg_base + offset);
+}
+
+/****************************************************************************
+ * Name: esp32_spi_set_regbits
+ *
+ * Description:
+ *   Set the bits of the SPI register at offset
+ *
+ * Input Parameters:
+ *   priv   - Private SPI device structure
+ *   offset - Offset to the register of interest
+ *   bits   - Bits to be set
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+static inline void esp32_spi_set_regbits(struct esp32_spi_priv_s *priv,
+                                         int offset,
+                                         uint32_t bits)
+{
+  uint32_t tmp = getreg32(priv->config->reg_base + offset);
+
+  putreg32(tmp | bits, priv->config->reg_base + offset);
+}
+
+/****************************************************************************
+ * Name: esp32_spi_reset_regbits
+ *
+ * Description:
+ *   Clear the bits of the SPI register at offset
+ *
+ * Input Parameters:
+ *   priv   - Private SPI device structure
+ *   offset - Offset to the register of interest
+ *   bits   - Bits to be cleared
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+static inline void esp32_spi_reset_regbits(struct esp32_spi_priv_s *priv,
+                                           int offset,
+                                           uint32_t bits)
+{
+  uint32_t tmp = getreg32(priv->config->reg_base + offset);
+
+  putreg32(tmp & (~bits), priv->config->reg_base + offset);
+}
+
+/****************************************************************************
+ * Name: esp32_spi_lock
+ *
+ * Description:
+ *   Lock or unlock the SPI device
+ *
+ * Input Parameters:
+ *   priv   - Private SPI device structure
+ *   lock   - true: Lock spi bus, false: unlock SPI bus
+ *
+ * Returned Value:
+ *   The result of lock or unlock the SPI device
+ *
+ ****************************************************************************/
+
+static int esp32_spi_lock(FAR struct spi_dev_s *dev, bool lock)
+{
+  int ret;
+  FAR struct esp32_spi_priv_s *priv = (FAR struct esp32_spi_priv_s *)dev;
+
+  if (lock)
+    {
+      ret = nxsem_wait_uninterruptible(&priv->exclsem);
+    }
+  else
+    {
+      ret = nxsem_post(&priv->exclsem);
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: esp32_spi_setfrequency
+ *
+ * Description:
+ *   Set the SPI frequency.
+ *
+ * Input Parameters:
+ *   dev -       Device-specific state data
+ *   frequency - The SPI frequency requested
+ *
+ * Returned Value:
+ *   Returns the actual frequency selected
+ *
+ ****************************************************************************/
+
+static uint32_t esp32_spi_setfrequency(FAR struct spi_dev_s *dev,
+                                       uint32_t frequency)
+{
+  uint32_t reg_val;
+  FAR struct esp32_spi_priv_s *priv = (FAR struct esp32_spi_priv_s *)dev;
+  const uint32_t duty_cycle = 128;
+
+  if (frequency > ((APB_CLK_FREQ / 4) * 3))

Review comment:
       Higher level drivers use setfrequency/setmode/setbits before every SPI transaction to make sure that the bus is in the state that the driver wants it to be.  To avoid having to do all of what follows, usually we test if the frequency hasn't changed, if so we just return.  Something like:
   ``` C
   if (priv->frequency == frequency)
     {
       /* We are already at this frequency.  Return the actual. */
   
       return priv->actual;
     }
   ```
   
   
   




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

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



[GitHub] [incubator-nuttx] xiaoxiang781216 edited a comment on pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 edited a comment on pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#issuecomment-660652496


   @acassis @Ouss4 I just rebase https://github.com/apache/incubator-nuttx/pull/1423, we need fix the error in the new avr build first.


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

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



[GitHub] [incubator-nuttx] acassis commented on pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
acassis commented on pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#issuecomment-660649343


   > > @xiaoxiang781216 I think these recent modifications on CI broke the xtensa build, it appears that ${{matrix.boards}}.dat wasn't updated:
   > 
   > That's because the config matrix was only updated in testing/. It's trivial, I can provide a fix for that.
   > 
   > #1424 and its sister in apps/ should do.
   > But both need #1423. Furthermore there are some warnings in the AVR builds, that would also break the build.
   
   It didn't fix/update the issue:
   
   cd sources/testing
   ./cibuild.sh -x testlist/mips-riscv-x86-xtensa.dat
   "
   ERROR: No readable file exists at testlist/mips-riscv-x86-xtensa.dat
   
   USAGE: /github/workspace/sources/nuttx/tools/testbuild.sh [-l|m|c|u|g|n] [-d] [-e <extraflags>] [-x] [-j <ncpus>] [-a <appsdir>] [-t <topdir>] [-p] [-G] <testlist-file>
          /github/workspace/sources/nuttx/tools/testbuild.sh -h
   
   Where:
     -l|m|c|u|g|n selects Linux (l), macOS (m), Cygwin (c),
        Ubuntu under Windows 10 (u), MSYS/MSYS2 (g) or Windows native (n).  Default Linux
     -d enables script debug output
     -e pass extra c/c++ flags such as -Wno-cpp via make command line
     -x exit on build failures
     -j <ncpus> passed on to make.  Default:  No -j make option.
     -a <appsdir> provides the relative path to the apps/ directory.  Default ../apps
     -t <topdir> provides the absolute path to top nuttx/ directory.  Default /github/workspace/sources/testing/../nuttx


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

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



[GitHub] [incubator-nuttx] Ouss4 edited a comment on pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
Ouss4 edited a comment on pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#issuecomment-660644607






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

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



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#discussion_r456842289



##########
File path: arch/xtensa/src/esp32/esp32_spi.c
##########
@@ -0,0 +1,1076 @@
+/****************************************************************************
+ * arch/xtensa/src/esp32/esp32_spi.c
+ *
+ * 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>
+
+#ifdef CONFIG_ESP32_SPI
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <debug.h>
+#include <time.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/irq.h>
+#include <nuttx/clock.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/spi/spi.h>
+
+#include <arch/board/board.h>
+
+#include "esp32_spi.h"
+#include "esp32_gpio.h"
+#include "esp32_cpuint.h"
+
+#include "xtensa.h"
+#include "hardware/esp32_gpio_sigmap.h"
+#include "hardware/esp32_dport.h"
+#include "hardware/esp32_spi.h"
+#include "hardware/esp32_soc.h"
+#include "rom/esp32_gpio.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* SPI Default speed (limited by clock divider) */
+
+#define SPI_FREQ_DEFAULT  400000
+
+/* SPI Device hardware configuration */
+
+struct esp32_spi_config_s
+{
+  uint32_t reg_base;          /* SPI register base address */
+
+  uint32_t clk_freq;          /* SPI clock frequency */
+  enum spi_mode_e mode;       /* SPI default mode */
+
+  uint8_t cs_pin;             /* GPIO configuration for CS */
+  uint8_t mosi_pin;           /* GPIO configuration for MOSI */
+  uint8_t miso_pin;           /* GPIO configuration for MISO */
+  uint8_t clk_pin;            /* GPIO configuration for CLK */
+
+  uint8_t cpu;                /* CPU ID */
+  uint8_t periph;             /* peripher ID */
+  uint8_t irq;                /* Interrupt ID */
+
+  uint32_t clk_bit;           /* Clock enable bit */
+  uint32_t rst_bit;           /* SPI reset bit */
+
+  uint32_t cs_insig;          /* SPI CS input signal index */
+  uint32_t cs_outsig;         /* SPI CS output signal index */
+  uint32_t mosi_insig;        /* SPI MOSI input signal index */
+  uint32_t mosi_outsig;       /* SPI MOSI output signal index */
+  uint32_t miso_insig;        /* SPI MISO input signal index */
+  uint32_t miso_outsig;       /* SPI MISO output signal index */
+  uint32_t clk_insig;         /* SPI CLK input signal index */
+  uint32_t clk_outsig;        /* SPI CLK output signal index */
+};
+
+struct esp32_spi_priv_s
+{
+  /* Externally visible part of the SPI interface */
+
+  struct spi_dev_s spi_dev;
+
+  /* Port configuration */
+
+  const struct esp32_spi_config_s *config;
+
+  int refs;                    /* Referernce count */
+
+  /* Held while chip is selected for mutual exclusion */
+
+  sem_t            exclsem;
+
+  uint32_t         frequency;   /* Requested clock frequency */
+  uint32_t         actual;      /* Actual clock frequency */
+
+  enum spi_mode_e  mode;        /* Actual SPI hardware mode */
+
+  /* Actual SPI send/receive bits once transmission */
+
+  uint8_t          nbits;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int esp32_spi_lock(FAR struct spi_dev_s *dev, bool lock);
+static void esp32_spi_select(FAR struct spi_dev_s *dev,

Review comment:
       I think only spi_select should be in the header, at least on stm32 and nrf52 I only found _select, not _lock.




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

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



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#discussion_r456908827



##########
File path: arch/xtensa/src/esp32/esp32_spi.c
##########
@@ -0,0 +1,1010 @@
+/****************************************************************************
+ * arch/xtensa/src/esp32/esp32_spi.c
+ *
+ * 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>
+
+#ifdef CONFIG_ESP32_SPI
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <debug.h>
+#include <time.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/irq.h>
+#include <nuttx/clock.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/spi/spi.h>
+
+#include <arch/board/board.h>
+
+#include "esp32_spi.h"
+#include "esp32_gpio.h"
+#include "esp32_cpuint.h"
+
+#include "xtensa.h"
+#include "hardware/esp32_gpio_sigmap.h"
+#include "hardware/esp32_dport.h"
+#include "hardware/esp32_spi.h"
+#include "hardware/esp32_soc.h"
+#include "rom/esp32_gpio.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* SPI Default speed (limited by clock divider) */
+
+#define SPI_FREQ_DEFAULT  400000
+
+/* SPI Device hardware configuration */
+
+struct esp32_spi_config_s
+{
+  uint32_t reg_base;          /* SPI register base address */
+
+  uint32_t clk_freq;          /* SPI clock frequency */
+  enum spi_mode_e mode;       /* SPI default mode */
+
+  uint8_t cs_pin;             /* GPIO configuration for CS */
+  uint8_t mosi_pin;           /* GPIO configuration for MOSI */
+  uint8_t miso_pin;           /* GPIO configuration for MISO */
+  uint8_t clk_pin;            /* GPIO configuration for CLK */
+
+  uint8_t cpu;                /* CPU ID */
+  uint8_t periph;             /* peripher ID */
+  uint8_t irq;                /* Interrupt ID */
+
+  uint32_t clk_bit;           /* Clock enable bit */
+  uint32_t rst_bit;           /* SPI reset bit */
+
+  uint32_t cs_insig;          /* SPI CS input signal index */
+  uint32_t cs_outsig;         /* SPI CS output signal index */
+  uint32_t mosi_insig;        /* SPI MOSI input signal index */
+  uint32_t mosi_outsig;       /* SPI MOSI output signal index */
+  uint32_t miso_insig;        /* SPI MISO input signal index */
+  uint32_t miso_outsig;       /* SPI MISO output signal index */
+  uint32_t clk_insig;         /* SPI CLK input signal index */
+  uint32_t clk_outsig;        /* SPI CLK output signal index */
+};
+
+struct esp32_spi_priv_s
+{
+  /* Externally visible part of the SPI interface */
+
+  struct spi_dev_s spi_dev;
+
+  /* Port configuration */
+
+  const struct esp32_spi_config_s *config;
+
+  int refs;                    /* Referernce count */
+
+  /* Held while chip is selected for mutual exclusion */
+
+  sem_t            exclsem;
+
+  uint32_t         frequency;   /* Requested clock frequency */
+  uint32_t         actual;      /* Actual clock frequency */
+
+  enum spi_mode_e  mode;        /* Actual SPI hardware mode */
+
+  /* Actual SPI send/receive bits once transmission */
+
+  uint8_t          nbits;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int esp32_spi_lock(FAR struct spi_dev_s *dev, bool lock);
+static void esp32_spi_select(FAR struct spi_dev_s *dev,
+                             uint32_t devid,
+                             bool selected);
+static uint32_t esp32_spi_setfrequency(FAR struct spi_dev_s *dev,
+                                       uint32_t frequency);
+static void esp32_spi_setmode(FAR struct spi_dev_s *dev,
+                              enum spi_mode_e mode);
+static void esp32_spi_setbits(FAR struct spi_dev_s *dev, int nbits);
+#ifdef CONFIG_SPI_HWFEATURES
+static int esp32_spi_hwfeatures(FAR struct spi_dev_s *dev,
+                                spi_hwfeatures_t features);
+#endif
+static uint32_t esp32_spi_send(FAR struct spi_dev_s *dev, uint32_t wd);
+static void esp32_spi_exchange(FAR struct spi_dev_s *dev,
+                               FAR const void *txbuffer,
+                               FAR void *rxbuffer, size_t nwords);
+#ifndef CONFIG_SPI_EXCHANGE
+static void esp32_spi_sndblock(FAR struct spi_dev_s *dev,
+                               FAR const void *txbuffer,
+                               size_t nwords);
+static void esp32_spi_recvblock(FAR struct spi_dev_s *dev,
+                                FAR void *rxbuffer,
+                                size_t nwords);
+#endif
+#ifdef CONFIG_SPI_TRIGGER
+static int esp32_spi_trigger(FAR struct spi_dev_s *dev);
+#endif
+static void esp32_spi_init(FAR struct spi_dev_s *dev);
+static void esp32_spi_deinit(FAR struct spi_dev_s *dev);
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+#ifdef CONFIG_ESP32_SPI2
+static const struct esp32_spi_config_s esp32_spi2_config =
+{
+  .reg_base     = REG_SPI_BASE(2),
+  .clk_freq     = SPI_FREQ_DEFAULT,
+  .mode         = SPIDEV_MODE0,
+  .cs_pin       = CONFIG_ESP32_SPI2_CSPIN,
+  .mosi_pin     = CONFIG_ESP32_SPI2_MOSIPIN,
+  .miso_pin     = CONFIG_ESP32_SPI2_MISOPIN,
+  .clk_pin      = CONFIG_ESP32_SPI2_CLKPIN,
+  .cpu          = 0,
+  .periph       = ESP32_PERIPH_SPI2,
+  .irq          = ESP32_IRQ_SPI2,
+  .clk_bit      = DPORT_SPI_CLK_EN_2,
+  .rst_bit      = DPORT_SPI_RST_2,
+  .cs_insig     = HSPICS0_IN_IDX,
+  .cs_outsig    = HSPICS0_OUT_IDX,
+  .mosi_insig   = HSPID_IN_IDX,
+  .mosi_outsig  = HSPID_OUT_IDX,
+  .miso_insig   = HSPIQ_IN_IDX,
+  .miso_outsig  = HSPIQ_OUT_IDX,
+  .clk_insig    = HSPICLK_IN_IDX,
+  .clk_outsig   = HSPICLK_OUT_IDX
+};
+
+static const struct spi_ops_s esp32_spi2_ops =
+{
+  .lock              = esp32_spi_lock,
+  .select            = esp32_spi2_select,
+  .setfrequency      = esp32_spi_setfrequency,
+  .setmode           = esp32_spi_setmode,
+  .setbits           = esp32_spi_setbits,
+#ifdef CONFIG_SPI_HWFEATURES
+  .hwfeatures        = esp32_spi_hwfeatures,
+#endif
+  .status            = esp32_spi2_status,
+#ifdef CONFIG_SPI_CMDDATA
+  .cmddata           = esp32_spi2_cmddata,
+#endif
+  .send              = esp32_spi_send,
+#ifdef CONFIG_SPI_EXCHANGE
+  .exchange          = esp32_spi_exchange,
+#else
+  .sndblock          = esp32_spi_sndblock,
+  .recvblock         = esp32_spi_recvblock,
+#endif
+#ifdef CONFIG_SPI_TRIGGER
+  .trigger           = esp32_spi_trigger,
+#endif
+  .registercallback  = NULL,
+};
+
+static struct esp32_spi_priv_s esp32_spi2_priv =
+{
+  .spi_dev =
+              {
+                .ops = &esp32_spi2_ops
+              },
+  .config = &esp32_spi2_config
+};
+#endif /* CONFIG_ESP32_SPI2 */
+
+#ifdef CONFIG_ESP32_SPI3
+static const struct esp32_spi_config_s esp32_spi3_config =
+{
+  .reg_base     = REG_SPI_BASE(3),
+  .clk_freq     = SPI_FREQ_DEFAULT,
+  .mode         = SPIDEV_MODE0,
+  .cs_pin       = CONFIG_ESP32_SPI3_CSPIN,
+  .mosi_pin     = CONFIG_ESP32_SPI3_MOSIPIN,
+  .miso_pin     = CONFIG_ESP32_SPI3_MISOPIN,
+  .clk_pin      = CONFIG_ESP32_SPI3_CLKPIN,
+  .cpu          = 0,
+  .periph       = ESP32_PERIPH_SPI3,
+  .irq          = ESP32_IRQ_SPI3,
+  .clk_bit      = DPORT_SPI_CLK_EN,
+  .rst_bit      = DPORT_SPI_RST,
+  .cs_insig     = VSPICS0_IN_IDX,
+  .cs_outsig    = VSPICS0_OUT_IDX,
+  .mosi_insig   = VSPID_IN_IDX,
+  .mosi_outsig  = VSPID_OUT_IDX,
+  .miso_insig   = VSPIQ_IN_IDX,
+  .miso_outsig  = VSPIQ_OUT_IDX,
+  .clk_insig    = VSPICLK_IN_IDX,
+  .clk_outsig   = VSPICLK_OUT_MUX_IDX
+};
+
+static const struct spi_ops_s esp32_spi3_ops =
+{
+  .lock              = esp32_spi_lock,
+  .select            = esp32_spi3_select,
+  .setfrequency      = esp32_spi_setfrequency,
+  .setmode           = esp32_spi_setmode,
+  .setbits           = esp32_spi_setbits,
+#ifdef CONFIG_SPI_HWFEATURES
+  .hwfeatures        = esp32_spi_hwfeatures,
+#endif
+  .status            = esp32_spi3_status,
+#ifdef CONFIG_SPI_CMDDATA
+  .cmddata           = esp32_spi3_cmddata,
+#endif
+  .send              = esp32_spi_send,
+#ifdef CONFIG_SPI_EXCHANGE
+  .exchange          = esp32_spi_exchange,
+#else
+  .sndblock          = esp32_spi_sndblock,
+  .recvblock         = esp32_spi_recvblock,
+#endif
+#ifdef CONFIG_SPI_TRIGGER
+  .trigger           = esp32_spi_trigger,
+#endif
+  .registercallback  = NULL,
+};
+
+static struct esp32_spi_priv_s esp32_spi3_priv =
+{
+  .spi_dev =
+              {
+                .ops = &esp32_spi3_ops
+              },
+  .config = &esp32_spi3_config
+};
+#endif /* CONFIG_ESP32_SPI3 */
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: esp32_spi_set_reg
+ *
+ * Description:
+ *   Set the contents of the SPI register at offset
+ *
+ * Input Parameters:
+ *   priv   - Private SPI device structure
+ *   offset - Offset to the register of interest
+ *   value  - Value to be written
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+static inline void esp32_spi_set_reg(struct esp32_spi_priv_s *priv,
+                                     int offset,
+                                     uint32_t value)
+{
+  putreg32(value, priv->config->reg_base + offset);
+}
+
+/****************************************************************************
+ * Name: esp32_spi_get_reg
+ *
+ * Description:
+ *   Get the contents of the SPI register at offset
+ *
+ * Input Parameters:
+ *   priv   - Private SPI device structure
+ *   offset - Offset to the register of interest
+ *
+ * Returned Value:
+ *   The contents of the register
+ *
+ ****************************************************************************/
+
+static inline uint32_t esp32_spi_get_reg(struct esp32_spi_priv_s *priv,
+                                         int offset)
+{
+  return getreg32(priv->config->reg_base + offset);
+}
+
+/****************************************************************************
+ * Name: esp32_spi_set_regbits
+ *
+ * Description:
+ *   Set the bits of the SPI register at offset
+ *
+ * Input Parameters:
+ *   priv   - Private SPI device structure
+ *   offset - Offset to the register of interest
+ *   bits   - Bits to be set
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+static inline void esp32_spi_set_regbits(struct esp32_spi_priv_s *priv,
+                                         int offset,
+                                         uint32_t bits)
+{
+  uint32_t tmp = getreg32(priv->config->reg_base + offset);
+
+  putreg32(tmp | bits, priv->config->reg_base + offset);
+}
+
+/****************************************************************************
+ * Name: esp32_spi_reset_regbits
+ *
+ * Description:
+ *   Clear the bits of the SPI register at offset
+ *
+ * Input Parameters:
+ *   priv   - Private SPI device structure
+ *   offset - Offset to the register of interest
+ *   bits   - Bits to be cleared
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+static inline void esp32_spi_reset_regbits(struct esp32_spi_priv_s *priv,
+                                           int offset,
+                                           uint32_t bits)
+{
+  uint32_t tmp = getreg32(priv->config->reg_base + offset);
+
+  putreg32(tmp & (~bits), priv->config->reg_base + offset);
+}
+
+/****************************************************************************
+ * Name: esp32_spi_lock
+ *
+ * Description:
+ *   Lock or unlock the SPI device
+ *
+ * Input Parameters:
+ *   priv   - Private SPI device structure
+ *   lock   - true: Lock spi bus, false: unlock SPI bus
+ *
+ * Returned Value:
+ *   The result of lock or unlock the SPI device
+ *
+ ****************************************************************************/
+
+static int esp32_spi_lock(FAR struct spi_dev_s *dev, bool lock)
+{
+  int ret;
+  FAR struct esp32_spi_priv_s *priv = (FAR struct esp32_spi_priv_s *)dev;
+
+  if (lock)
+    {
+      ret = nxsem_wait_uninterruptible(&priv->exclsem);
+    }
+  else
+    {
+      ret = nxsem_post(&priv->exclsem);
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: esp32_spi_setfrequency
+ *
+ * Description:
+ *   Set the SPI frequency.
+ *
+ * Input Parameters:
+ *   dev -       Device-specific state data
+ *   frequency - The SPI frequency requested
+ *
+ * Returned Value:
+ *   Returns the actual frequency selected
+ *
+ ****************************************************************************/
+
+static uint32_t esp32_spi_setfrequency(FAR struct spi_dev_s *dev,
+                                       uint32_t frequency)
+{
+  uint32_t reg_val;
+  FAR struct esp32_spi_priv_s *priv = (FAR struct esp32_spi_priv_s *)dev;
+  const uint32_t duty_cycle = 128;
+
+  if (frequency > ((APB_CLK_FREQ / 4) * 3))

Review comment:
       Good point Abdelatif! Thank you!




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

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



[GitHub] [incubator-nuttx] Ouss4 commented on pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
Ouss4 commented on pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#issuecomment-660649483


   You'll need to rebase.  I doubt that the checks would pass however.  As I said there is another PR that selects the right toolchain, and then there are some warnings in the AVR build.


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

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



[GitHub] [incubator-nuttx] Ouss4 edited a comment on pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
Ouss4 edited a comment on pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#issuecomment-660644607


   > @xiaoxiang781216 I think these recent modifications on CI broke the xtensa build, it appears that ${{matrix.boards}}.dat wasn't updated:
   
   That's because the config matrix was only updated in testing/.  It's trivial, I can provide a fix for that.
   
   #1424 and its sister in apps/ should do.


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

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



[GitHub] [incubator-nuttx] acassis edited a comment on pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
acassis edited a comment on pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#issuecomment-660638935


   @xiaoxiang781216 I think these recent modifications on CI broke the xtensa build, it appears that ${{matrix.boards}}.dat wasn't updated:
   
   "cd sources/testing
   ./cibuild.sh -x testlist/mips-riscv-x86-xtensa.dat
   "
   ERROR: No readable file exists at testlist/mips-riscv-x86-xtensa.dat
   
   USAGE: /github/workspace/sources/nuttx/tools/testbuild.sh [-l|m|c|u|g|n] [-d] [-e <extraflags>] [-x] [-j <ncpus>] [-a <appsdir>] [-t <topdir>] [-p] [-G] <testlist-file>
          /github/workspace/sources/nuttx/tools/testbuild.sh -h"


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

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



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#discussion_r456843852



##########
File path: arch/xtensa/src/esp32/Kconfig
##########
@@ -309,4 +307,58 @@ endif # SERIAL_IFLOWCONTROL || SERIAL_OFLOWCONTROL
 endif # ESP32_UART2
 
 endmenu # UART configuration
+
+menu "SPI configuration"
+	depends on ESP32_SPI
+
+if ESP32_SPI2
+
+config ESP32_SPI2_CSPIN
+	int "SPI2 CS Pin"

Review comment:
       Since the pins definition for ESP32 UART and other are already in the Kconfig, I think it is better to keep it this way.




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

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



[GitHub] [incubator-nuttx] Ouss4 commented on pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
Ouss4 commented on pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#issuecomment-660644607


   > @xiaoxiang781216 I think these recent modifications on CI broke the xtensa build, it appears that ${{matrix.boards}}.dat wasn't updated:
   
   That's because the config matrix was only updated in testing/.  It's trivial, I can provide a fix for that.


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

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



[GitHub] [incubator-nuttx] Ouss4 edited a comment on pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
Ouss4 edited a comment on pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#issuecomment-660644607


   > @xiaoxiang781216 I think these recent modifications on CI broke the xtensa build, it appears that ${{matrix.boards}}.dat wasn't updated:
   
   That's because the config matrix was only updated in testing/.  It's trivial, I can provide a fix for that.
   
   #1424 and its sister in apps/ should do.
   But both need #1423


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

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



[GitHub] [incubator-nuttx] Ouss4 merged pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
Ouss4 merged pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422


   


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

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



[GitHub] [incubator-nuttx] Ouss4 commented on a change in pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
Ouss4 commented on a change in pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#discussion_r456839614



##########
File path: arch/xtensa/src/esp32/Kconfig
##########
@@ -81,25 +81,23 @@ config ESP32_SDMMC
 	---help---
 		No yet implemented
 
-config ESP32_SPI0

Review comment:
       Shouldn't then only the slave source code be dependent on `CONFIG_ESP32_SPI2 || CONFIG_ESP32_ESP3`?  The master code is similar, right?




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

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



[GitHub] [incubator-nuttx] xiaoxiang781216 commented on pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
xiaoxiang781216 commented on pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#issuecomment-660652496


   @acassis @Ouss4 I just rebase https://github.com/apache/incubator-nuttx/pull/1423, we need fix the error in the new avr build.


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

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



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#discussion_r456839505



##########
File path: arch/xtensa/src/esp32/Kconfig
##########
@@ -81,25 +81,23 @@ config ESP32_SDMMC
 	---help---
 		No yet implemented
 
-config ESP32_SPI0

Review comment:
       Yes, that was the idea, it only support SPI2 and SPI3 because these ports can be master or slave. The code should be modified in the future to support SPI0 and SPI1




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

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



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#discussion_r456839333



##########
File path: arch/xtensa/src/esp32/Make.defs
##########
@@ -99,6 +99,7 @@ CHIP_CSRCS  = esp32_allocateheap.c esp32_clockconfig.c esp32_cpuint.c
 CHIP_CSRCS += esp32_gpio.c esp32_intdecode.c esp32_irq.c esp32_region.c
 CHIP_CSRCS += esp32_timerisr.c
 CHIP_CSRCS += esp32_user.c
+CHIP_CSRCS += esp32_spi.c esp32_spi_slave.c

Review comment:
       Thank you, I just committed it




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

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



[GitHub] [incubator-nuttx] acassis commented on a change in pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
acassis commented on a change in pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#discussion_r456843886



##########
File path: arch/xtensa/src/esp32/Kconfig
##########
@@ -81,25 +81,23 @@ config ESP32_SDMMC
 	---help---
 		No yet implemented
 
-config ESP32_SPI0

Review comment:
       Good point! I agree! You are right, thank you very much Abde!




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

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



[GitHub] [incubator-nuttx] Ouss4 commented on a change in pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
Ouss4 commented on a change in pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#discussion_r456843198



##########
File path: arch/xtensa/src/esp32/esp32_spi.c
##########
@@ -0,0 +1,1076 @@
+/****************************************************************************
+ * arch/xtensa/src/esp32/esp32_spi.c
+ *
+ * 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>
+
+#ifdef CONFIG_ESP32_SPI
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <debug.h>
+#include <time.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/irq.h>
+#include <nuttx/clock.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/spi/spi.h>
+
+#include <arch/board/board.h>
+
+#include "esp32_spi.h"
+#include "esp32_gpio.h"
+#include "esp32_cpuint.h"
+
+#include "xtensa.h"
+#include "hardware/esp32_gpio_sigmap.h"
+#include "hardware/esp32_dport.h"
+#include "hardware/esp32_spi.h"
+#include "hardware/esp32_soc.h"
+#include "rom/esp32_gpio.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* SPI Default speed (limited by clock divider) */
+
+#define SPI_FREQ_DEFAULT  400000
+
+/* SPI Device hardware configuration */
+
+struct esp32_spi_config_s
+{
+  uint32_t reg_base;          /* SPI register base address */
+
+  uint32_t clk_freq;          /* SPI clock frequency */
+  enum spi_mode_e mode;       /* SPI default mode */
+
+  uint8_t cs_pin;             /* GPIO configuration for CS */
+  uint8_t mosi_pin;           /* GPIO configuration for MOSI */
+  uint8_t miso_pin;           /* GPIO configuration for MISO */
+  uint8_t clk_pin;            /* GPIO configuration for CLK */
+
+  uint8_t cpu;                /* CPU ID */
+  uint8_t periph;             /* peripher ID */
+  uint8_t irq;                /* Interrupt ID */
+
+  uint32_t clk_bit;           /* Clock enable bit */
+  uint32_t rst_bit;           /* SPI reset bit */
+
+  uint32_t cs_insig;          /* SPI CS input signal index */
+  uint32_t cs_outsig;         /* SPI CS output signal index */
+  uint32_t mosi_insig;        /* SPI MOSI input signal index */
+  uint32_t mosi_outsig;       /* SPI MOSI output signal index */
+  uint32_t miso_insig;        /* SPI MISO input signal index */
+  uint32_t miso_outsig;       /* SPI MISO output signal index */
+  uint32_t clk_insig;         /* SPI CLK input signal index */
+  uint32_t clk_outsig;        /* SPI CLK output signal index */
+};
+
+struct esp32_spi_priv_s
+{
+  /* Externally visible part of the SPI interface */
+
+  struct spi_dev_s spi_dev;
+
+  /* Port configuration */
+
+  const struct esp32_spi_config_s *config;
+
+  int refs;                    /* Referernce count */
+
+  /* Held while chip is selected for mutual exclusion */
+
+  sem_t            exclsem;
+
+  uint32_t         frequency;   /* Requested clock frequency */
+  uint32_t         actual;      /* Actual clock frequency */
+
+  enum spi_mode_e  mode;        /* Actual SPI hardware mode */
+
+  /* Actual SPI send/receive bits once transmission */
+
+  uint8_t          nbits;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int esp32_spi_lock(FAR struct spi_dev_s *dev, bool lock);
+static void esp32_spi_select(FAR struct spi_dev_s *dev,

Review comment:
       Yes, I was referring to spi_select not _lock.




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

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



[GitHub] [incubator-nuttx] Ouss4 commented on a change in pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
Ouss4 commented on a change in pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#discussion_r456837563



##########
File path: arch/xtensa/src/esp32/Make.defs
##########
@@ -99,6 +99,7 @@ CHIP_CSRCS  = esp32_allocateheap.c esp32_clockconfig.c esp32_cpuint.c
 CHIP_CSRCS += esp32_gpio.c esp32_intdecode.c esp32_irq.c esp32_region.c
 CHIP_CSRCS += esp32_timerisr.c
 CHIP_CSRCS += esp32_user.c
+CHIP_CSRCS += esp32_spi.c esp32_spi_slave.c

Review comment:
       ```suggestion
   ifeq ($(CONFIG_ESP32_SPI),y)
   CHIP_CSRCS += esp32_spi.c esp32_spi_slave.c
   endif
   ```

##########
File path: arch/xtensa/src/esp32/Kconfig
##########
@@ -81,25 +81,23 @@ config ESP32_SDMMC
 	---help---
 		No yet implemented
 
-config ESP32_SPI0

Review comment:
       What's the reason to remove SPI0 and SPI1?  SPI0 is somewhat special, but the difference with SPI1 is that SPI2 and 3 can be configured as slaves.

##########
File path: arch/xtensa/src/esp32/Kconfig
##########
@@ -309,4 +307,58 @@ endif # SERIAL_IFLOWCONTROL || SERIAL_OFLOWCONTROL
 endif # ESP32_UART2
 
 endmenu # UART configuration
+
+menu "SPI configuration"
+	depends on ESP32_SPI
+
+if ESP32_SPI2
+
+config ESP32_SPI2_CSPIN
+	int "SPI2 CS Pin"

Review comment:
       Shouldn't these SPI pins be configured by board logic?  Similar to other boards.




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

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



[GitHub] [incubator-nuttx] acassis commented on pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
acassis commented on pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#issuecomment-660638935


   @xiaoxiang781216 I think these recent modifications on CI broke the xtensa build:
   
   "cd sources/testing
   ./cibuild.sh -x testlist/mips-riscv-x86-xtensa.dat
   "
   ERROR: No readable file exists at testlist/mips-riscv-x86-xtensa.dat
   
   USAGE: /github/workspace/sources/nuttx/tools/testbuild.sh [-l|m|c|u|g|n] [-d] [-e <extraflags>] [-x] [-j <ncpus>] [-a <appsdir>] [-t <topdir>] [-p] [-G] <testlist-file>
          /github/workspace/sources/nuttx/tools/testbuild.sh -h"


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

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



[GitHub] [incubator-nuttx] Ouss4 commented on a change in pull request #1422: ESP32: Add driver support to SPI Master and Slave

Posted by GitBox <gi...@apache.org>.
Ouss4 commented on a change in pull request #1422:
URL: https://github.com/apache/incubator-nuttx/pull/1422#discussion_r456839270



##########
File path: arch/xtensa/src/esp32/esp32_spi.c
##########
@@ -0,0 +1,1076 @@
+/****************************************************************************
+ * arch/xtensa/src/esp32/esp32_spi.c
+ *
+ * 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>
+
+#ifdef CONFIG_ESP32_SPI
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <debug.h>
+#include <time.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/irq.h>
+#include <nuttx/clock.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/spi/spi.h>
+
+#include <arch/board/board.h>
+
+#include "esp32_spi.h"
+#include "esp32_gpio.h"
+#include "esp32_cpuint.h"
+
+#include "xtensa.h"
+#include "hardware/esp32_gpio_sigmap.h"
+#include "hardware/esp32_dport.h"
+#include "hardware/esp32_spi.h"
+#include "hardware/esp32_soc.h"
+#include "rom/esp32_gpio.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* SPI Default speed (limited by clock divider) */
+
+#define SPI_FREQ_DEFAULT  400000
+
+/* SPI Device hardware configuration */
+
+struct esp32_spi_config_s
+{
+  uint32_t reg_base;          /* SPI register base address */
+
+  uint32_t clk_freq;          /* SPI clock frequency */
+  enum spi_mode_e mode;       /* SPI default mode */
+
+  uint8_t cs_pin;             /* GPIO configuration for CS */
+  uint8_t mosi_pin;           /* GPIO configuration for MOSI */
+  uint8_t miso_pin;           /* GPIO configuration for MISO */
+  uint8_t clk_pin;            /* GPIO configuration for CLK */
+
+  uint8_t cpu;                /* CPU ID */
+  uint8_t periph;             /* peripher ID */
+  uint8_t irq;                /* Interrupt ID */
+
+  uint32_t clk_bit;           /* Clock enable bit */
+  uint32_t rst_bit;           /* SPI reset bit */
+
+  uint32_t cs_insig;          /* SPI CS input signal index */
+  uint32_t cs_outsig;         /* SPI CS output signal index */
+  uint32_t mosi_insig;        /* SPI MOSI input signal index */
+  uint32_t mosi_outsig;       /* SPI MOSI output signal index */
+  uint32_t miso_insig;        /* SPI MISO input signal index */
+  uint32_t miso_outsig;       /* SPI MISO output signal index */
+  uint32_t clk_insig;         /* SPI CLK input signal index */
+  uint32_t clk_outsig;        /* SPI CLK output signal index */
+};
+
+struct esp32_spi_priv_s
+{
+  /* Externally visible part of the SPI interface */
+
+  struct spi_dev_s spi_dev;
+
+  /* Port configuration */
+
+  const struct esp32_spi_config_s *config;
+
+  int refs;                    /* Referernce count */
+
+  /* Held while chip is selected for mutual exclusion */
+
+  sem_t            exclsem;
+
+  uint32_t         frequency;   /* Requested clock frequency */
+  uint32_t         actual;      /* Actual clock frequency */
+
+  enum spi_mode_e  mode;        /* Actual SPI hardware mode */
+
+  /* Actual SPI send/receive bits once transmission */
+
+  uint8_t          nbits;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int esp32_spi_lock(FAR struct spi_dev_s *dev, bool lock);
+static void esp32_spi_select(FAR struct spi_dev_s *dev,
+                             uint32_t devid,
+                             bool selected);
+static uint32_t esp32_spi_setfrequency(FAR struct spi_dev_s *dev,
+                                       uint32_t frequency);
+static void esp32_spi_setmode(FAR struct spi_dev_s *dev,
+                              enum spi_mode_e mode);
+static void esp32_spi_setbits(FAR struct spi_dev_s *dev, int nbits);
+#ifdef CONFIG_SPI_HWFEATURES
+static int esp32_spi_hwfeatures(FAR struct spi_dev_s *dev,
+                                spi_hwfeatures_t features);
+#endif
+#ifdef CONFIG_SPI_CMDDATA
+static int esp32_spi_cmddata(FAR struct spi_dev_s *dev,
+                             uint32_t devid,
+                             bool cmd);
+#endif
+static uint32_t esp32_spi_send(FAR struct spi_dev_s *dev, uint32_t wd);
+static void esp32_spi_exchange(FAR struct spi_dev_s *dev,
+                               FAR const void *txbuffer,
+                               FAR void *rxbuffer, size_t nwords);
+#ifndef CONFIG_SPI_EXCHANGE
+static void esp32_spi_sndblock(FAR struct spi_dev_s *dev,
+                               FAR const void *txbuffer,
+                               size_t nwords);
+static void esp32_spi_recvblock(FAR struct spi_dev_s *dev,
+                                FAR void *rxbuffer,
+                                size_t nwords);
+#endif
+#ifdef CONFIG_SPI_TRIGGER
+static int esp32_spi_trigger(FAR struct spi_dev_s *dev);
+#endif
+static void esp32_spi_init(FAR struct spi_dev_s *dev);
+static void esp32_spi_deinit(FAR struct spi_dev_s *dev);
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+extern uint8_t esp32_spi2_status(FAR struct spi_dev_s *dev, uint32_t devid);
+extern uint8_t esp32_spi3_status(FAR struct spi_dev_s *dev, uint32_t devid);

Review comment:
       For other architectures, these are prototyped in the header file (arch/xtensa/src/esp32/esp32_spi.h in this case) and implemented in the board logic.

##########
File path: arch/xtensa/src/esp32/esp32_spi.c
##########
@@ -0,0 +1,1076 @@
+/****************************************************************************
+ * arch/xtensa/src/esp32/esp32_spi.c
+ *
+ * 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>
+
+#ifdef CONFIG_ESP32_SPI
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <debug.h>
+#include <time.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/irq.h>
+#include <nuttx/clock.h>
+#include <nuttx/semaphore.h>
+#include <nuttx/spi/spi.h>
+
+#include <arch/board/board.h>
+
+#include "esp32_spi.h"
+#include "esp32_gpio.h"
+#include "esp32_cpuint.h"
+
+#include "xtensa.h"
+#include "hardware/esp32_gpio_sigmap.h"
+#include "hardware/esp32_dport.h"
+#include "hardware/esp32_spi.h"
+#include "hardware/esp32_soc.h"
+#include "rom/esp32_gpio.h"
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/* SPI Default speed (limited by clock divider) */
+
+#define SPI_FREQ_DEFAULT  400000
+
+/* SPI Device hardware configuration */
+
+struct esp32_spi_config_s
+{
+  uint32_t reg_base;          /* SPI register base address */
+
+  uint32_t clk_freq;          /* SPI clock frequency */
+  enum spi_mode_e mode;       /* SPI default mode */
+
+  uint8_t cs_pin;             /* GPIO configuration for CS */
+  uint8_t mosi_pin;           /* GPIO configuration for MOSI */
+  uint8_t miso_pin;           /* GPIO configuration for MISO */
+  uint8_t clk_pin;            /* GPIO configuration for CLK */
+
+  uint8_t cpu;                /* CPU ID */
+  uint8_t periph;             /* peripher ID */
+  uint8_t irq;                /* Interrupt ID */
+
+  uint32_t clk_bit;           /* Clock enable bit */
+  uint32_t rst_bit;           /* SPI reset bit */
+
+  uint32_t cs_insig;          /* SPI CS input signal index */
+  uint32_t cs_outsig;         /* SPI CS output signal index */
+  uint32_t mosi_insig;        /* SPI MOSI input signal index */
+  uint32_t mosi_outsig;       /* SPI MOSI output signal index */
+  uint32_t miso_insig;        /* SPI MISO input signal index */
+  uint32_t miso_outsig;       /* SPI MISO output signal index */
+  uint32_t clk_insig;         /* SPI CLK input signal index */
+  uint32_t clk_outsig;        /* SPI CLK output signal index */
+};
+
+struct esp32_spi_priv_s
+{
+  /* Externally visible part of the SPI interface */
+
+  struct spi_dev_s spi_dev;
+
+  /* Port configuration */
+
+  const struct esp32_spi_config_s *config;
+
+  int refs;                    /* Referernce count */
+
+  /* Held while chip is selected for mutual exclusion */
+
+  sem_t            exclsem;
+
+  uint32_t         frequency;   /* Requested clock frequency */
+  uint32_t         actual;      /* Actual clock frequency */
+
+  enum spi_mode_e  mode;        /* Actual SPI hardware mode */
+
+  /* Actual SPI send/receive bits once transmission */
+
+  uint8_t          nbits;
+};
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int esp32_spi_lock(FAR struct spi_dev_s *dev, bool lock);
+static void esp32_spi_select(FAR struct spi_dev_s *dev,

Review comment:
       This is also prototyped in the header file and implemented in board logic.




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

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