You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/06/21 20:13:47 UTC

[incubator-nuttx] 04/04: drivers/spi/spi_bitbang.c: Fix typos and nxstyle complaints.

This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 530cad304f5d457300d4a594866821d7d78f6006
Author: Ouss4 <ab...@gmail.com>
AuthorDate: Sat Jun 13 19:05:01 2020 +0100

    drivers/spi/spi_bitbang.c: Fix typos and nxstyle complaints.
---
 boards/arm/sam34/arduino-due/src/sam_mmcsd.c       |  5 +-
 boards/arm/sam34/arduino-due/src/sam_touchscreen.c |  2 +-
 drivers/spi/spi_bitbang.c                          | 14 ++---
 include/nuttx/spi/spi_bitbang.c                    | 63 +++++++++++++---------
 4 files changed, 48 insertions(+), 36 deletions(-)

diff --git a/boards/arm/sam34/arduino-due/src/sam_mmcsd.c b/boards/arm/sam34/arduino-due/src/sam_mmcsd.c
index 9f5954c..843ce2a 100644
--- a/boards/arm/sam34/arduino-due/src/sam_mmcsd.c
+++ b/boards/arm/sam34/arduino-due/src/sam_mmcsd.c
@@ -93,7 +93,7 @@
 
 /* Calibration value for timing loop */
 
-#define SPI_BITBAND_LOOPSPERMSEC CONFIG_BOARD_LOOPSPERMSEC
+#define SPI_BITBANG_LOOPSPERMSEC CONFIG_BOARD_LOOPSPERMSEC
 
 /* SPI_PERBIT_NSEC is the minimum time to transfer one bit.  This determines
  * the maximum frequency and is also used to calculate delays to achieve
@@ -275,7 +275,8 @@ int sam_sdinitialize(int minor)
   ret = mmcsd_spislotinitialize(minor, SAM34_MMCSDSLOTNO, spi);
   if (ret < 0)
     {
-      ferr("ERROR: Failed to bind  bit bang SPI device to MMC/SD slot %d: %d\n",
+      ferr("ERROR: Failed to bind bit bang SPI device"
+            " to MMC/SD slot %d: %d\n",
             SAM34_MMCSDSLOTNO, ret);
       return ret;
     }
diff --git a/boards/arm/sam34/arduino-due/src/sam_touchscreen.c b/boards/arm/sam34/arduino-due/src/sam_touchscreen.c
index 8a86eaa..2eb5e96 100644
--- a/boards/arm/sam34/arduino-due/src/sam_touchscreen.c
+++ b/boards/arm/sam34/arduino-due/src/sam_touchscreen.c
@@ -108,7 +108,7 @@
 
 /* Calibration value for timing loop */
 
-#define SPI_BITBAND_LOOPSPERMSEC CONFIG_BOARD_LOOPSPERMSEC
+#define SPI_BITBANG_LOOPSPERMSEC CONFIG_BOARD_LOOPSPERMSEC
 
 /* SPI_PERBIT_NSEC is the minimum time to transfer one bit.  This determines
  * the maximum frequency and is also used to calculate delays to achieve
diff --git a/drivers/spi/spi_bitbang.c b/drivers/spi/spi_bitbang.c
index 91822cf..263e3c8 100644
--- a/drivers/spi/spi_bitbang.c
+++ b/drivers/spi/spi_bitbang.c
@@ -55,8 +55,8 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-/* This file holds the static, device-independ portion of the generica SPI-
- * bit-bang driver.  The full driver consists of 5 files:
+/* This file holds the static, device-independent portion of the generic
+ * SPI-bit-bang driver.  The full driver consists of 5 files:
  *
  * 1. drivers/spi/spi_bitbang.c:  This file.  This file holds the basic
  *    SPI driver framework and not perform any direct bit-bang operations.
@@ -68,17 +68,17 @@
  * 3. boards/<arch>/<chip>/<board>/src/<file>:  The implementation of the
  *    low-level bit-bang logic resides in some file in the board source
  *    directory.  This board-specific logic includes the bit-bang skeleton
- *    logic provided in include/nuttx/spi/spi_bitband.c.
- * 4. include/nuttx/spi/spi_bitband.c.  Despite the .c extension, this
+ *    logic provided in include/nuttx/spi/spi_bitbang.c.
+ * 4. include/nuttx/spi/spi_bitbang.c.  Despite the .c extension, this is
  *    really an included file.  It is used in this way:  1) The board-
  *    specific logic in boards/<arch>/<chip>/<board>/src/<file> provides
- *    some definitions then 2) includes include/nuttx/spi/spi_bitband.c.
+ *    some definitions then 2) includes include/nuttx/spi/spi_bitbang.c.
  *    That file will then use those definitions to implement the low-level
- *    bit-bang logic.  the board-specific logic then calls
+ *    bit-bang logic.  The board-specific logic then calls
  *    spi_create_bitbang() in this file to instantiate the complete SPI
  *    driver.
  *
- *    See include/nuttx/spi/spi_bitband.c for more detailed usage
+ *    See include/nuttx/spi/spi_bitbang.c for more detailed usage
  *    information.
  */
 
diff --git a/include/nuttx/spi/spi_bitbang.c b/include/nuttx/spi/spi_bitbang.c
index 6d483ee..9cc56cb 100644
--- a/include/nuttx/spi/spi_bitbang.c
+++ b/include/nuttx/spi/spi_bitbang.c
@@ -44,7 +44,9 @@
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
+
 /* Usage ********************************************************************/
+
 /* To use this logic, you should provide a C file that does the following:
  *
  * - Defines SPI_SETSCK and SPI_CLRSCK to set and clear the SCK signal
@@ -53,12 +55,12 @@
  * - Defines SPI_PERBIT_NSEC which is the minimum time to transfer one bit.
  *   This determines the maximum frequency.
  * - Other configuration options:
- *   SPI_BITBAND_LOOPSPERMSEC - Delay loop calibration
+ *   SPI_BITBANG_LOOPSPERMSEC - Delay loop calibration
  *   SPI_BITBANG_DISABLEMODE0 - Define to disable Mode 0 support
  *   SPI_BITBANG_DISABLEMODE1 - Define to disable Mode 1 support
  *   SPI_BITBANG_DISABLEMODE2 - Define to disable Mode 2 support
  *   SPI_BITBANG_DISABLEMODE3 - Define to disable Mode 3 support
- * - Provide implementations of spi_select(), spi_status(), and spi_cmddata().
+ * - Provide implementations of spi_select(), spi_status() and spi_cmddata().
  * - Then include this file
  * - Provide an initialization function that initializes the GPIO pins used
  *   in the bit bang interface and calls spi_create_bitbang().
@@ -115,6 +117,7 @@ static const struct spi_bitbang_ops_s g_spiops =
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
+
 /****************************************************************************
  * Name: spi_delay
  *
@@ -122,10 +125,10 @@ static const struct spi_bitbang_ops_s g_spiops =
  *   Delay for a specified number of loops
  *
  * Input Parameters:
- *   count - The number of loops
+ *   holdtime - The number of loops
  *
  * Returned Value:
- *   Returns the actual frequency selected
+ *   None.
  *
  ****************************************************************************/
 
@@ -143,7 +146,7 @@ static void spi_delay(uint32_t holdtime)
  *   Set the SPI frequency.
  *
  * Input Parameters:
- *   dev -       Device-specific state data
+ *   priv -      Device-specific state data
  *   frequency - The SPI frequency requested
  *
  * Returned Value:
@@ -151,7 +154,8 @@ static void spi_delay(uint32_t holdtime)
  *
  ****************************************************************************/
 
-static uint32_t spi_setfrequency(FAR struct spi_bitbang_s *priv, uint32_t frequency)
+static uint32_t spi_setfrequency(FAR struct spi_bitbang_s *priv,
+                                 uint32_t frequency)
 {
   uint32_t pnsec;
 
@@ -160,11 +164,14 @@ static uint32_t spi_setfrequency(FAR struct spi_bitbang_s *priv, uint32_t freque
    * wait, set low, wait, set high, wait, etc.
    *
    * Here we calcalute the half period of the frequency in nanoseconds (i.e.,
-   * the amount of time that the clock should remain in the high or low state).
+   * the amount of time that the clock should remain in the high or low
+   * state).
    *
-   *   frequency = psec / 1 sec                       psec = full period in seconds
+   *   frequency = psec / 1 sec
+   *      psec = full period in seconds
    *   psec      = 1 sec / frequency
-   *   pnsec     = 1000000000 nsec / (2 * frequency)  pnsec = full period in nsec
+   *   pnsec     = 1000000000 nsec / (2 * frequency)
+   *      pnsec = full period in nsec
    *
    * As examples:
    * 1) frequency = 400KHz; SPI_PERBIT_NSEC = 100
@@ -190,41 +197,43 @@ static uint32_t spi_setfrequency(FAR struct spi_bitbang_s *priv, uint32_t freque
 
   pnsec = (pnsec + 1) >> 1;
 
-  /* But what we really want is the hold time in loop counts. We know that
-   * SPI_BITBAND_LOOPSPERMSEC is the number of times through a delay loop
+  /* But what we really want is the hold time in loop counts.  We know that
+   * SPI_BITBANG_LOOPSPERMSEC is the number of times through a delay loop
    * to get 1 millisecond.
    *
-   * SPI_BITBAND_LOOPSPERMSEC / 1000000 is then the number of counts
+   * SPI_BITBANG_LOOPSPERMSEC / 1000000 is then the number of counts
    * to get 1 nanosecond.  In reality, this is a number less than zero.  But
    * then we can use this to calculate:
    *
-   * holdtime loops/hold = pnsec nsec/hold * (SPI_BITBAND_LOOPSPERMSEC / 1000000) loops/nsec
+   * holdtime loops/hold = pnsec nsec/hold * (SPI_BITBANG_LOOPSPERMSEC /
+   *                                          1000000) loops/nsec
    *
    * As examples:
    * 1) frequency = 400KHz; SPI_PERBIT_NSEC = 100; pnsec = 1200;
-   *    SPI_BITBAND_LOOPSPERMSEC = 5000
+   *    SPI_BITBANG_LOOPSPERMSEC = 5000
    *    holdtime  = (1200 * 5000 + 500000) / 1000000 = 6
    * 2) frequency = 20MHz;  SPI_PERBIT_NSEC = 100; pnsec = 0;
-   *    SPI_BITBAND_LOOPSPERMSEC = 5000
+   *    SPI_BITBANG_LOOPSPERMSEC = 5000
    *    holdtime  = (0 * 5000 + 500000) / 1000000 = 0
    */
 
-  priv->holdtime = (pnsec * SPI_BITBAND_LOOPSPERMSEC + 500000) / 1000000;
+  priv->holdtime = (pnsec * SPI_BITBANG_LOOPSPERMSEC + 500000) / 1000000;
 
   /* Let's do our best to calculate the actual frequency
    *
    * As examples:
    * 1) frequency = 400KHz; SPI_PERBIT_NSEC = 100;
-   *    SPI_BITBAND_LOOPSPERMSEC = 5000; holdtime = 6
+   *    SPI_BITBANG_LOOPSPERMSEC = 5000; holdtime = 6
    *    pnsec     = 2 * 1000000 * 6 / 5000 + 100 = 2500 nsec
    *    frequency = 400KHz
    * 2) frequency = 20MHz;  SPI_PERBIT_NSEC = 100; holdtime = 0
-   *    SPI_BITBAND_LOOPSPERMSEC = 5000; holdtime = 0
+   *    SPI_BITBANG_LOOPSPERMSEC = 5000; holdtime = 0
    *    pnsec     = 2 * 0 * 6 / 5000 + 100 = 100 nsec
    *    frequency = 10MHz
    */
 
-  pnsec = 2 * 1000000 * priv->holdtime / SPI_BITBAND_LOOPSPERMSEC + SPI_PERBIT_NSEC;
+  pnsec = 2 * 1000000 * priv->holdtime / SPI_BITBANG_LOOPSPERMSEC +
+          SPI_PERBIT_NSEC;
   frequency = 1000000000ul / pnsec;
   return frequency;
 }
@@ -236,8 +245,8 @@ static uint32_t spi_setfrequency(FAR struct spi_bitbang_s *priv, uint32_t freque
  *   Select the current SPI mode
  *
  * Input Parameters:
- *   dev  - Device-specific state data
- *   mode - the new SPI mode
+ *   priv - Device-specific state data
+ *   mode - The new SPI mode
  *
  * Returned Value:
  *   None
@@ -466,8 +475,8 @@ static uint16_t spi_bitexchange2(uint16_t dataout, uint32_t holdtime)
 {
   uint16_t datain;
 
-  /* Here the clock is is in the resting set (high).  Set MOSI output and wait
-   * for the hold time
+  /* Here the clock is is in the resting set (high).  Set MOSI output and
+   * wait for the hold time
    */
 
   if (dataout != 0)
@@ -568,7 +577,7 @@ static uint16_t spi_bitexchange3(uint16_t dataout, uint32_t holdtime)
  * Name: spi_exchange
  *
  * Description:
- *   Exahange on word of data on SPI
+ *   Exahange one word of data on SPI
  *
  * Input Parameters:
  *   priv     - Device-specific state data
@@ -580,7 +589,8 @@ static uint16_t spi_bitexchange3(uint16_t dataout, uint32_t holdtime)
  ****************************************************************************/
 
 #ifdef CONFIG_SPI_BITBANG_VARWIDTH
-static uint16_t spi_exchange(FAR struct spi_bitbang_s *priv, uint16_t dataout)
+static uint16_t spi_exchange(FAR struct spi_bitbang_s *priv,
+                             uint16_t dataout)
 {
   bitexchange_t exchange = priv->exchange;
   uint32_t holdtime = priv->holdtime;
@@ -609,7 +619,8 @@ static uint16_t spi_exchange(FAR struct spi_bitbang_s *priv, uint16_t dataout)
 }
 
 #else
-static uint16_t spi_exchange(FAR struct spi_bitbang_s *priv, uint16_t dataout)
+static uint16_t spi_exchange(FAR struct spi_bitbang_s *priv,
+                             uint16_t dataout)
 {
   bitexchange_t exchange = priv->exchange;
   uint32_t holdtime = priv->holdtime;