Permalink
Browse files

Provide a SPIPinForConnector() to do logical to physical pin-mapping.

  • Loading branch information...
hzeller committed Apr 23, 2017
1 parent c881ac1 commit 54c3c68e38cee08c157010b9a24a4501db80383c
Showing with 34 additions and 2 deletions.
  1. +7 −1 include/multi-spi.h
  2. +26 −0 lib/direct-multi-spi.cc
  3. +1 −1 lib/ft-gpio.cc
View
@@ -57,10 +57,16 @@ class MultiSPI {
SPI_P16 = 20,
};
+ // A function that maps the connector number (P1..P16) to the value of
+ // the corresponding SPI Pin SPI_P1..SPI_P16 constant.
+ static int SPIPinForConnector(int connector);
+
virtual ~MultiSPI() {}
// Register a new data stream for the given GPIO. The SPI data is
- // sent with the common clock and this gpio pin.
+ // sent with the common clock and this gpio pin. The gpio must be one
+ // of the above SPI_xx constants or the return value of
+ // SPIPinForConnector().
//
// Note, each channel might receive more bytes because they share the
// same clock with everyone and it depends on what is the longest requested
View
@@ -27,6 +27,32 @@
#include <algorithm>
namespace spixels {
+
+// This should be in a multi-spi.cc, but that would be the only function. So
+// here is good as well.
+int MultiSPI::SPIPinForConnector(int connector) {
+ switch (connector) {
+ case 1: return SPI_P1;
+ case 2: return SPI_P2;
+ case 3: return SPI_P3;
+ case 4: return SPI_P4;
+ case 5: return SPI_P5;
+ case 6: return SPI_P6;
+ case 7: return SPI_P7;
+ case 8: return SPI_P8;
+
+ case 9: return SPI_P9;
+ case 10: return SPI_P10;
+ case 11: return SPI_P11;
+ case 12: return SPI_P12;
+ case 13: return SPI_P13;
+ case 14: return SPI_P14;
+ case 15: return SPI_P15;
+ case 16: return SPI_P16;
+ }
+ return -1;
+}
+
namespace {
class DirectMultiSPI : public MultiSPI {
public:
View
@@ -66,7 +66,7 @@ bool GPIO::AddOutput(int bit) {
}
const uint32_t gpio_mask = 1 << bit;
- if ((gpio_mask & kValidBits) == 0)
+ if (bit < 0 || ((gpio_mask & kValidBits) == 0))
return false;
INP_GPIO(bit); // for writing, we first need to set as input.
OUT_GPIO(bit);

0 comments on commit 54c3c68

Please sign in to comment.