Skip to content

Commit 5338899

Browse files
committed
Correct use of online.gpioExpanderButtons
1 parent 67cab0e commit 5338899

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

Firmware/RTK_Everywhere/SD.ino

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,21 @@ void sdUpdate()
7777
#define SD_READ_OCR (0x40 + 58) // read OCR
7878
#define SD_ADV_INIT (0xc0 + 41) // ACMD41, for SDHC cards - advanced start initialization
7979

80-
// Begin initialization by sending CMD0 and waiting until SD card
81-
// responds with In Idle Mode (0x01). If the response is not 0x01
82-
// within a reasonable amount of time, there is no SD card on the bus.
83-
// Returns false if not card is detected
84-
// Returns true if a card responds
85-
// This test takes approximately 13ms to complete
80+
// How this works:
81+
// Some variants have the SD socket card detect pin connected directly to GPIO
82+
// Of those, some are low when the card is present, some are high
83+
// On some variants the card detection is performed via a GPIO expander
84+
// On Postcard: on the Portability Shield, SD DET (SD_CD) is connected to
85+
// IO5 of a PCA9554 I2C GPIO expander (address 0x20)
86+
// IO5 is high when the card is present
87+
// On Facet Flex: SD_#CD is connected to ESP32 GPIO39
88+
// Torch: has no SD card
89+
// On Facet mosaic: the SD card is connected directly to the X5 but
90+
// SD_!DET is connected to ESP32 GPIO15
91+
//
92+
// More generally:
93+
// The GPIO expander on Postcard is known as gpioExpanderButtons (0x20)
94+
// Facet Flex also has a GPIO expander, known as gpioExpanderSwitches (0x21)
8695
bool sdCardPresent(void)
8796
{
8897
if (present.microSdCardDetectLow == true)
@@ -98,9 +107,9 @@ bool sdCardPresent(void)
98107
return (false); // Card detect low = No SD
99108
}
100109
// TODO: check this. Do we have a conflict with online.gpioExpanderButtons vs online.gpioExpander?
101-
else if (present.microSdCardDetectGpioExpanderHigh == true && online.gpioExpanderButtons == true)
110+
else if (present.microSdCardDetectGpioExpanderHigh == true)
102111
{
103-
if (online.gpioExpander == true)
112+
if (online.gpioExpanderButtons == true)
104113
{
105114
if (io.digitalRead(gpioExpander_cardDetect) == GPIO_EXPANDER_CARD_INSERTED)
106115
return (true); // Card detect high = SD in place
@@ -115,6 +124,13 @@ bool sdCardPresent(void)
115124

116125
// else - no card detect pin. Use software detect
117126

127+
// Begin initialization by sending CMD0 and waiting until SD card
128+
// responds with In Idle Mode (0x01). If the response is not 0x01
129+
// within a reasonable amount of time, there is no SD card on the bus.
130+
// Returns false if not card is detected
131+
// Returns true if a card responds
132+
// This test takes approximately 13ms to complete
133+
118134
// Note: even though this is protected by the semaphore,
119135
// this will probably cause issues / corruption if
120136
// a SdFile is open for writing...?

0 commit comments

Comments
 (0)