Skip to content

Commit 142c36f

Browse files
authored
Merge pull request #40 from BB-301/fix/cp2102N-tool-gpio-qfn20-support
Added QFN20 package check for status LEDs GPIO configs in `ext/badge/cp2102.c`
2 parents b35e8c3 + 7e1aac2 commit 142c36f

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

‎ext/badge/cp2102.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,17 @@ main (int argc, char * argv[])
444444
if (gpio != NULL) {
445445
p = (uint8_t *)&config;
446446
if (strcmp (gpio, "on") == 0) {
447-
p[CP2102N_MODE_RESET_P1] |= CP2102N_MODE_GPIO0 |
448-
CP2102N_MODE_GPIO1;
447+
// [CP210N Datasheet](https://www.silabs.com/documents/public/data-sheets/cp2102n-datasheet.pdf)
448+
// NOTE: As visible from Figure 5.3 and Table 5.3 (in the datasheet), the QFN20 package uses
449+
// GPIO.2/TXT and GPIO.3/RXT, as opposed to GPIO.0/TXT and GPIO.1/RXT, respectively, for the other
450+
// two packages (i.e., QFN28 and QFN24). So here we need to check whether we are dealing with QFN20, and,
451+
// if so, adjust the target bits accordingly.
452+
p[CP2102N_MODE_RESET_P1] |= ((part != CP210X_PROD_CP2102N_QFN20) ? (CP2102N_MODE_GPIO0 | CP2102N_MODE_GPIO1) : (CP2102N_MODE_GPIO2 | CP2102N_MODE_GPIO3));
449453
p[CP2102N_PORTSET] |= CP2102N_PORTSET_TXLED |
450454
CP2102N_PORTSET_RXLED;
451455
} else if (strcmp (gpio, "off") == 0) {
452-
p[CP2102N_MODE_RESET_P1] &= ~(CP2102N_MODE_GPIO0 |
453-
CP2102N_MODE_GPIO1);
456+
// NOTE: same note as above "if" block regarding QFN20 package and TX/RX GPIOs.
457+
p[CP2102N_MODE_RESET_P1] &= ~((part != CP210X_PROD_CP2102N_QFN20) ? (CP2102N_MODE_GPIO0 | CP2102N_MODE_GPIO1) : (CP2102N_MODE_GPIO2 | CP2102N_MODE_GPIO3));
454458
p[CP2102N_PORTSET] &= ~(CP2102N_PORTSET_TXLED |
455459
CP2102N_PORTSET_RXLED);
456460
} else {

0 commit comments

Comments
 (0)