Selaa lähdekoodia

gblink: add function to get default pin setting

Signed-off-by: Kris Bahnsen <Kris@KBEmbedded.com>
Kris Bahnsen 1 vuosi sitten
vanhempi
commit
e2922bd0bb
2 muutettua tiedostoa jossa 32 lisäystä ja 0 poistoa
  1. 23 0
      gblink/gblink.c
  2. 9 0
      gblink/include/gblink.h

+ 23 - 0
gblink/gblink.c

@@ -321,6 +321,29 @@ int gblink_pin_set_default(void *handle, gblink_pinouts pinout)
 	return 0;
 }
 
+int gblink_pin_get_default(void *handle)
+{
+	furi_assert(handle);
+	struct gblink *gblink = handle;
+	int i;
+
+	for (i = 0; i < PINOUT_COUNT; i++) {
+		if (gblink->serin != common_pinouts[i].serin)
+			continue;
+		if (gblink->serout != common_pinouts[i].serout)
+			continue;
+		if (gblink->clk != common_pinouts[i].clk)
+			continue;
+		/* XXX: Currently not checked or used! */
+		//if (gblink->sd != common_pinouts[pinout].sd;
+		break;
+	}
+
+	if (i == PINOUT_COUNT)
+		i = -1;
+
+	return i;
+}
 
 const GpioPin *gblink_pin_get(void *handle, gblink_bus_pins pin)
 {

+ 9 - 0
gblink/include/gblink.h

@@ -136,6 +136,15 @@ bool gblink_transfer(void *handle, uint8_t val);
  */
 int gblink_pin_set_default(void *handle, gblink_pinouts pinout);
 
+/**
+ * Check if the pinout set matches a pre-configured one
+ *
+ * @param handle Pointer to gblink handle
+ *
+ * @returns The index of the pre-configured pinout or -1 on error
+ */
+int gblink_pin_get_default(void *handle);
+
 /**
  * Set a gpio pin to a specific pin mode
  *