SakuraIO
Fork of SakuraIO by
SakuraIO.h@1:20e1dfe45dab, 2016-11-19 (annotated)
- Committer:
- spiralray
- Date:
- Sat Nov 19 12:32:11 2016 +0000
- Revision:
- 1:20e1dfe45dab
- Parent:
- 0:8d34375d954c
- Child:
- 2:6f8e51a42a7d
Support I2C
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
spiralray | 0:8d34375d954c | 1 | #ifndef _SAKURAIO_H_ |
spiralray | 0:8d34375d954c | 2 | #define _SAKURAIO_H_ |
spiralray | 0:8d34375d954c | 3 | |
spiralray | 1:20e1dfe45dab | 4 | #include "mbed.h" |
spiralray | 0:8d34375d954c | 5 | #include <SakuraIO/commands.h> |
spiralray | 0:8d34375d954c | 6 | |
spiralray | 0:8d34375d954c | 7 | class SakuraIO |
spiralray | 0:8d34375d954c | 8 | { |
spiralray | 0:8d34375d954c | 9 | protected: |
spiralray | 0:8d34375d954c | 10 | virtual void begin(){} |
spiralray | 0:8d34375d954c | 11 | virtual void end(){} |
spiralray | 0:8d34375d954c | 12 | |
spiralray | 0:8d34375d954c | 13 | virtual void sendByte(uint8_t data){} |
spiralray | 0:8d34375d954c | 14 | //virtual void finishSending(){} |
spiralray | 0:8d34375d954c | 15 | |
spiralray | 0:8d34375d954c | 16 | virtual uint8_t startReceive(uint8_t length){return length;}; |
spiralray | 0:8d34375d954c | 17 | virtual uint8_t receiveByte(){return 0x00;} |
spiralray | 0:8d34375d954c | 18 | virtual uint8_t receiveByte(bool stop){return 0x00;} |
spiralray | 0:8d34375d954c | 19 | //virtual void finishReceiving(){} |
spiralray | 0:8d34375d954c | 20 | |
spiralray | 0:8d34375d954c | 21 | uint8_t executeCommand(uint8_t cmd,uint8_t requestLength, uint8_t *request, uint8_t *responseLength, uint8_t *response); |
spiralray | 0:8d34375d954c | 22 | |
spiralray | 0:8d34375d954c | 23 | uint8_t enqueueTxRaw(uint8_t ch, uint8_t type, uint8_t length, uint8_t *data, uint64_t offset); |
spiralray | 0:8d34375d954c | 24 | |
spiralray | 0:8d34375d954c | 25 | public: |
spiralray | 0:8d34375d954c | 26 | uint8_t getConnectionStatus(); |
spiralray | 0:8d34375d954c | 27 | uint8_t getSignalQuarity(); |
spiralray | 0:8d34375d954c | 28 | uint64_t getUnixtime(); |
spiralray | 0:8d34375d954c | 29 | uint8_t echoback(uint8_t length, uint8_t *data, uint8_t *response); |
spiralray | 0:8d34375d954c | 30 | uint16_t getADC(uint8_t channel); |
spiralray | 0:8d34375d954c | 31 | uint8_t enqueueTx(uint8_t ch, int32_t value, uint64_t offset); |
spiralray | 0:8d34375d954c | 32 | uint8_t enqueueTx(uint8_t ch, uint32_t value, uint64_t offset); |
spiralray | 0:8d34375d954c | 33 | uint8_t enqueueTx(uint8_t ch, int64_t value, uint64_t offset); |
spiralray | 0:8d34375d954c | 34 | uint8_t enqueueTx(uint8_t ch, uint64_t value, uint64_t offset); |
spiralray | 0:8d34375d954c | 35 | uint8_t enqueueTx(uint8_t ch, float value, uint64_t offset); |
spiralray | 0:8d34375d954c | 36 | uint8_t enqueueTx(uint8_t ch, double value, uint64_t offset); |
spiralray | 0:8d34375d954c | 37 | uint8_t enqueueTx(uint8_t ch, uint8_t value[8], uint64_t offset); |
spiralray | 0:8d34375d954c | 38 | uint8_t enqueueTx(uint8_t ch, int32_t value); |
spiralray | 0:8d34375d954c | 39 | uint8_t enqueueTx(uint8_t ch, uint32_t value); |
spiralray | 0:8d34375d954c | 40 | uint8_t enqueueTx(uint8_t ch, int64_t value); |
spiralray | 0:8d34375d954c | 41 | uint8_t enqueueTx(uint8_t ch, uint64_t value); |
spiralray | 0:8d34375d954c | 42 | uint8_t enqueueTx(uint8_t ch, float value); |
spiralray | 0:8d34375d954c | 43 | uint8_t enqueueTx(uint8_t ch, double value); |
spiralray | 0:8d34375d954c | 44 | uint8_t enqueueTx(uint8_t ch, uint8_t value[8]); |
spiralray | 0:8d34375d954c | 45 | uint8_t getTxQueueLength(uint8_t *available, uint8_t *queued); |
spiralray | 0:8d34375d954c | 46 | uint8_t clearTx(); |
spiralray | 0:8d34375d954c | 47 | uint8_t getTxStatus(uint8_t *queue, uint8_t *immediate); |
spiralray | 0:8d34375d954c | 48 | uint8_t send(); |
spiralray | 0:8d34375d954c | 49 | uint8_t dequeueRx(uint8_t *ch, uint8_t *type, uint8_t *value, int64_t *offset); |
spiralray | 0:8d34375d954c | 50 | uint8_t peekRx(uint8_t *ch, uint8_t *type, uint8_t *value, int64_t *offset); |
spiralray | 0:8d34375d954c | 51 | uint8_t getRxQueueLength(uint8_t *available, uint8_t *queued); |
spiralray | 0:8d34375d954c | 52 | uint8_t clearRx(); |
spiralray | 0:8d34375d954c | 53 | uint16_t getProductID(); |
spiralray | 0:8d34375d954c | 54 | uint8_t getUniqueID(char *data); |
spiralray | 0:8d34375d954c | 55 | uint8_t getFirmwareVersion(char *data); |
spiralray | 0:8d34375d954c | 56 | uint8_t unlock(); |
spiralray | 0:8d34375d954c | 57 | uint8_t updateFirmware(); |
spiralray | 0:8d34375d954c | 58 | uint8_t getFirmwareUpdateStatus(); |
spiralray | 0:8d34375d954c | 59 | uint8_t reset(); |
spiralray | 0:8d34375d954c | 60 | }; |
spiralray | 0:8d34375d954c | 61 | |
spiralray | 0:8d34375d954c | 62 | class SakuraIO_SPI : public SakuraIO |
spiralray | 0:8d34375d954c | 63 | { |
spiralray | 0:8d34375d954c | 64 | protected: |
spiralray | 0:8d34375d954c | 65 | SPI &spi; |
spiralray | 0:8d34375d954c | 66 | DigitalOut &cs; |
spiralray | 0:8d34375d954c | 67 | void begin(); |
spiralray | 0:8d34375d954c | 68 | void end(); |
spiralray | 0:8d34375d954c | 69 | void sendByte(uint8_t data); |
spiralray | 0:8d34375d954c | 70 | uint8_t receiveByte(bool stop); |
spiralray | 0:8d34375d954c | 71 | uint8_t receiveByte(); |
spiralray | 0:8d34375d954c | 72 | public: |
spiralray | 0:8d34375d954c | 73 | SakuraIO_SPI(SPI &_spi, DigitalOut &_cs); |
spiralray | 0:8d34375d954c | 74 | }; |
spiralray | 0:8d34375d954c | 75 | |
spiralray | 0:8d34375d954c | 76 | class SakuraIO_I2C : public SakuraIO |
spiralray | 0:8d34375d954c | 77 | { |
spiralray | 0:8d34375d954c | 78 | protected: |
spiralray | 1:20e1dfe45dab | 79 | I2C i2c; |
spiralray | 1:20e1dfe45dab | 80 | int _length; |
spiralray | 1:20e1dfe45dab | 81 | |
spiralray | 1:20e1dfe45dab | 82 | virtual void begin(); |
spiralray | 1:20e1dfe45dab | 83 | virtual void end(); |
spiralray | 1:20e1dfe45dab | 84 | virtual void sendByte(uint8_t data); |
spiralray | 1:20e1dfe45dab | 85 | virtual uint8_t startReceive(uint8_t length); |
spiralray | 1:20e1dfe45dab | 86 | virtual uint8_t receiveByte(bool stop); |
spiralray | 1:20e1dfe45dab | 87 | virtual uint8_t receiveByte(); |
spiralray | 0:8d34375d954c | 88 | uint8_t mode; |
spiralray | 0:8d34375d954c | 89 | public: |
spiralray | 1:20e1dfe45dab | 90 | SakuraIO_I2C (I2C &_i2c); |
spiralray | 1:20e1dfe45dab | 91 | SakuraIO_I2C (PinName sda, PinName scl); |
spiralray | 0:8d34375d954c | 92 | }; |
spiralray | 0:8d34375d954c | 93 | |
spiralray | 0:8d34375d954c | 94 | #endif // _SAKURAIO_H_ |