ok
Dependents: pixy2 pixy2_10_0042 0000Non_stop_code_v1 0000Non_stop_code_v3 ... more
Fork of pixy by
PixyLinkSPI.h@0:ed8dc4531ac1, 2014-11-16 (annotated)
- Committer:
- acracan
- Date:
- Sun Nov 16 11:52:55 2014 +0000
- Revision:
- 0:ed8dc4531ac1
Initial commit of ported version of the Arduino Pixy Cmucam5 library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
acracan | 0:ed8dc4531ac1 | 1 | #ifndef TUIASI_PIXYLINKSPI_H |
acracan | 0:ed8dc4531ac1 | 2 | #define TUIASI_PIXYLINKSPI_H |
acracan | 0:ed8dc4531ac1 | 3 | |
acracan | 0:ed8dc4531ac1 | 4 | #include "SPI.h" |
acracan | 0:ed8dc4531ac1 | 5 | #include "PixyLink.h" |
acracan | 0:ed8dc4531ac1 | 6 | |
acracan | 0:ed8dc4531ac1 | 7 | class PixyLinkSPI : public PixyLink, private SPI |
acracan | 0:ed8dc4531ac1 | 8 | { |
acracan | 0:ed8dc4531ac1 | 9 | public: |
acracan | 0:ed8dc4531ac1 | 10 | PixyLinkSPI(PinName mosi, PinName miso, PinName sclk) : |
acracan | 0:ed8dc4531ac1 | 11 | SPI(mosi, miso, sclk), outLen(0), outIndex(0) { |
acracan | 0:ed8dc4531ac1 | 12 | }; |
acracan | 0:ed8dc4531ac1 | 13 | |
acracan | 0:ed8dc4531ac1 | 14 | virtual uint16_t getWord() { |
acracan | 0:ed8dc4531ac1 | 15 | uint16_t w = ((uint16_t)getByte()) << 8; |
acracan | 0:ed8dc4531ac1 | 16 | return w | getByte(); |
acracan | 0:ed8dc4531ac1 | 17 | }; |
acracan | 0:ed8dc4531ac1 | 18 | |
acracan | 0:ed8dc4531ac1 | 19 | virtual uint8_t getByte() { |
acracan | 0:ed8dc4531ac1 | 20 | uint8_t c = 0x00; |
acracan | 0:ed8dc4531ac1 | 21 | if (outIndex < outLen) { |
acracan | 0:ed8dc4531ac1 | 22 | c = outBuf[outIndex++]; |
acracan | 0:ed8dc4531ac1 | 23 | } |
acracan | 0:ed8dc4531ac1 | 24 | return write(c); |
acracan | 0:ed8dc4531ac1 | 25 | }; |
acracan | 0:ed8dc4531ac1 | 26 | |
acracan | 0:ed8dc4531ac1 | 27 | virtual int8_t send(uint8_t *data, uint8_t len) { |
acracan | 0:ed8dc4531ac1 | 28 | if (len > PIXY_OUTBUF_SIZE || outLen != 0) |
acracan | 0:ed8dc4531ac1 | 29 | return -1; |
acracan | 0:ed8dc4531ac1 | 30 | memcpy(outBuf, data, len); |
acracan | 0:ed8dc4531ac1 | 31 | outLen = len; |
acracan | 0:ed8dc4531ac1 | 32 | outIndex = 0; |
acracan | 0:ed8dc4531ac1 | 33 | return len; |
acracan | 0:ed8dc4531ac1 | 34 | }; |
acracan | 0:ed8dc4531ac1 | 35 | |
acracan | 0:ed8dc4531ac1 | 36 | private: |
acracan | 0:ed8dc4531ac1 | 37 | static const uint8_t PIXY_OUTBUF_SIZE = 6; |
acracan | 0:ed8dc4531ac1 | 38 | static const uint8_t PIXY_SYNC_BYTE = 0x5a; |
acracan | 0:ed8dc4531ac1 | 39 | static const uint8_t PIXY_SYNC_BYTE_DATA = 0x5b; |
acracan | 0:ed8dc4531ac1 | 40 | |
acracan | 0:ed8dc4531ac1 | 41 | uint8_t outBuf[PIXY_OUTBUF_SIZE]; |
acracan | 0:ed8dc4531ac1 | 42 | uint8_t outLen; |
acracan | 0:ed8dc4531ac1 | 43 | uint8_t outIndex; |
acracan | 0:ed8dc4531ac1 | 44 | |
acracan | 0:ed8dc4531ac1 | 45 | }; |
acracan | 0:ed8dc4531ac1 | 46 | #endif //TUIASI_PIXYLINKSPI_H |