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

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


The following commit(s) were added to refs/heads/master by this push:
     new 74790c8033 boards/samv7/hsmci: add option to invert card detection pin
74790c8033 is described below

commit 74790c8033ea77c5ec24a969555449d03209fcb3
Author: Karel Kočí <cyn...@email.cz>
AuthorDate: Sat Feb 18 21:21:10 2023 +0100

    boards/samv7/hsmci: add option to invert card detection pin
    
    The original code hard-coded card detection to the low when card is
    inserted and high when not. This might not be true on every board
    because it depends on the slot and wiring used. The second reason is
    because it is also possible to detect card with D3 pin pull-up when the
    slot does not provide dedicated card detection switch.
    
    This introduces new argument to the sam_hsmci_initialize to allow
    invert of card detection pin. It also applies this invert to existing
    boards as that was the state up to this point.
---
 boards/arm/samv7/common/include/board_hsmci.h      |  2 +-
 boards/arm/samv7/common/src/sam_hsmci.c            | 10 ++++++----
 boards/arm/samv7/same70-qmtech/src/sam_bringup.c   |  2 +-
 boards/arm/samv7/same70-xplained/src/sam_bringup.c |  2 +-
 boards/arm/samv7/samv71-xult/src/sam_bringup.c     |  2 +-
 5 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/boards/arm/samv7/common/include/board_hsmci.h 
b/boards/arm/samv7/common/include/board_hsmci.h
index 94dc1dced5..db256f016c 100644
--- a/boards/arm/samv7/common/include/board_hsmci.h
+++ b/boards/arm/samv7/common/include/board_hsmci.h
@@ -59,7 +59,7 @@ extern "C"
  ****************************************************************************/
 
 int sam_hsmci_initialize(int slotno, int minor, gpio_pinset_t cdcfg,
-                         int cdirq);
+                         int cdirq, bool cdinvert);
 
 /****************************************************************************
  * Name: sam_cardinserted
diff --git a/boards/arm/samv7/common/src/sam_hsmci.c 
b/boards/arm/samv7/common/src/sam_hsmci.c
index e0a2bd8e09..576bce0894 100644
--- a/boards/arm/samv7/common/src/sam_hsmci.c
+++ b/boards/arm/samv7/common/src/sam_hsmci.c
@@ -56,6 +56,7 @@ struct sam_hsmci_state_s
   int cdirq;                  /* Interrupt number (same as pid) */
   uint8_t slotno;             /* Slot number */
   bool cd;                    /* TRUE: card is inserted */
+  bool cdinvert;              /* Invert card detection to 0 signaling card */
 };
 
 /****************************************************************************
@@ -89,9 +90,9 @@ static bool sam_cardinserted_internal(struct 
sam_hsmci_state_s *state)
 
   /* Get the state of the PIO pin */
 
-  inserted = sam_gpioread(state->cdcfg);
-  finfo("Slot %d inserted: %s\n", state->slotno, inserted ? "NO" : "YES");
-  return !inserted;
+  inserted = sam_gpioread(state->cdcfg) != state->cdinvert;
+  finfo("Slot %d inserted: %s\n", state->slotno, inserted ? "YES" : "NO");
+  return inserted;
 }
 
 /****************************************************************************
@@ -181,7 +182,7 @@ static inline struct sam_hsmci_state_s *sam_hsmci_state(int 
slotno)
  ****************************************************************************/
 
 int sam_hsmci_initialize(int slotno, int minor, gpio_pinset_t cdcfg,
-                         int cdirq)
+                         int cdirq, bool cdinvert)
 {
   struct sam_hsmci_state_s *state;
   int ret;
@@ -197,6 +198,7 @@ int sam_hsmci_initialize(int slotno, int minor, 
gpio_pinset_t cdcfg,
 
   state->cdcfg = cdcfg;
   state->cdirq = cdirq;
+  state->cdinvert = cdinvert;
 
   /* Initialize card-detect, write-protect, and power enable PIOs */
 
diff --git a/boards/arm/samv7/same70-qmtech/src/sam_bringup.c 
b/boards/arm/samv7/same70-qmtech/src/sam_bringup.c
index 3039d11486..53835364df 100644
--- a/boards/arm/samv7/same70-qmtech/src/sam_bringup.c
+++ b/boards/arm/samv7/same70-qmtech/src/sam_bringup.c
@@ -160,7 +160,7 @@ int sam_bringup(void)
   /* Initialize the HSMCI0 driver */
 
   ret = sam_hsmci_initialize(HSMCI0_SLOTNO, HSMCI0_MINOR, GPIO_HSMCI0_CD,
-                             IRQ_HSMCI0_CD);
+                             IRQ_HSMCI0_CD, true);
   if (ret < 0)
     {
       syslog(LOG_ERR, "ERROR: sam_hsmci_initialize(%d,%d) failed: %d\n",
diff --git a/boards/arm/samv7/same70-xplained/src/sam_bringup.c 
b/boards/arm/samv7/same70-xplained/src/sam_bringup.c
index 688ae3064d..082da6c93c 100644
--- a/boards/arm/samv7/same70-xplained/src/sam_bringup.c
+++ b/boards/arm/samv7/same70-xplained/src/sam_bringup.c
@@ -221,7 +221,7 @@ int sam_bringup(void)
   /* Initialize the HSMCI0 driver */
 
   ret = sam_hsmci_initialize(HSMCI0_SLOTNO, HSMCI0_MINOR, GPIO_HSMCI0_CD,
-                             IRQ_HSMCI0_CD);
+                             IRQ_HSMCI0_CD, true);
   if (ret < 0)
     {
       syslog(LOG_ERR, "ERROR: sam_hsmci_initialize(%d,%d) failed: %d\n",
diff --git a/boards/arm/samv7/samv71-xult/src/sam_bringup.c 
b/boards/arm/samv7/samv71-xult/src/sam_bringup.c
index 38d816ed2a..0a93b62257 100644
--- a/boards/arm/samv7/samv71-xult/src/sam_bringup.c
+++ b/boards/arm/samv7/samv71-xult/src/sam_bringup.c
@@ -337,7 +337,7 @@ int sam_bringup(void)
   /* Initialize the HSMCI0 driver */
 
   ret = sam_hsmci_initialize(HSMCI0_SLOTNO, HSMCI0_MINOR, GPIO_HSMCI0_CD,
-                             IRQ_HSMCI0_CD);
+                             IRQ_HSMCI0_CD, true);
   if (ret < 0)
     {
       syslog(LOG_ERR, "ERROR: sam_hsmci_initialize(%d,%d) failed: %d\n",

Reply via email to