@@ -77,12 +77,21 @@ void sdUpdate()
77
77
#define SD_READ_OCR (0x40 + 58 ) // read OCR
78
78
#define SD_ADV_INIT (0xc0 + 41 ) // ACMD41, for SDHC cards - advanced start initialization
79
79
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)
86
95
bool sdCardPresent (void )
87
96
{
88
97
if (present.microSdCardDetectLow == true )
@@ -98,9 +107,9 @@ bool sdCardPresent(void)
98
107
return (false ); // Card detect low = No SD
99
108
}
100
109
// 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 )
102
111
{
103
- if (online.gpioExpander == true )
112
+ if (online.gpioExpanderButtons == true )
104
113
{
105
114
if (io.digitalRead (gpioExpander_cardDetect) == GPIO_EXPANDER_CARD_INSERTED)
106
115
return (true ); // Card detect high = SD in place
@@ -115,6 +124,13 @@ bool sdCardPresent(void)
115
124
116
125
// else - no card detect pin. Use software detect
117
126
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
+
118
134
// Note: even though this is protected by the semaphore,
119
135
// this will probably cause issues / corruption if
120
136
// a SdFile is open for writing...?
0 commit comments