Command processor to access I2C and SPI Takes URI coded commands and returns JSON array
Fork of SerialInterface by
SerialInterface.h@10:94a98d095b2a, 2018-01-26 (annotated)
- Committer:
- switches
- Date:
- Fri Jan 26 00:10:32 2018 +0000
- Revision:
- 10:94a98d095b2a
- Parent:
- 9:f52181496512
- Child:
- 11:bc8d6816839f
Increased argument array size and data buffer size to 0x4000
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gsteiert | 0:828bfd94972b | 1 | /* Pmod Interface Library |
gsteiert | 0:828bfd94972b | 2 | * |
gsteiert | 0:828bfd94972b | 3 | */ |
switches | 2:3f6a8ac111a9 | 4 | #ifndef SERIALINTERFACE_H |
switches | 2:3f6a8ac111a9 | 5 | #define SERIALINTERFACE_H |
gsteiert | 0:828bfd94972b | 6 | |
gsteiert | 0:828bfd94972b | 7 | #include "mbed.h" |
switches | 2:3f6a8ac111a9 | 8 | #include "SerialInterface.h" |
gsteiert | 0:828bfd94972b | 9 | |
switches | 10:94a98d095b2a | 10 | #define MAX_NUM_ARGS 0x4000 |
switches | 10:94a98d095b2a | 11 | #define DBUF_MAX_LENGTH 0x4000 |
switches | 10:94a98d095b2a | 12 | |
switches | 8:a0937dc92631 | 13 | /** Serial Interface Library, Provides utilities for remotely accessing peripherals |
gsteiert | 0:828bfd94972b | 14 | * |
gsteiert | 0:828bfd94972b | 15 | * Example: |
gsteiert | 0:828bfd94972b | 16 | * @code |
gsteiert | 0:828bfd94972b | 17 | * // Configure board to pass UART signals to peripheral connector. |
gsteiert | 0:828bfd94972b | 18 | * |
switches | 2:3f6a8ac111a9 | 19 | * #include "SerialInterface.h" |
gsteiert | 0:828bfd94972b | 20 | * |
switches | 3:601b78524967 | 21 | * I2C i2c(P3_4, P3_5); |
switches | 4:0bd9ec504040 | 22 | * SPI spi(P5_1, P5_2, P5_0); |
switches | 8:a0937dc92631 | 23 | * DigitalInOut gpio[] = {P5_3, P5_4, P5_5, P5_6, P3_0, P3_1, P3_2, P3_3}; |
switches | 8:a0937dc92631 | 24 | * AnalogIn ain[] = {AIN_0, AIN_1, AIN_2, AIN_3, AIN_4, AIN_5, AIN_6, AIN_7}; |
switches | 8:a0937dc92631 | 25 | * |
switches | 8:a0937dc92631 | 26 | * SerialInterface serInt(i2c, spi, gpio, ain); |
gsteiert | 0:828bfd94972b | 27 | * |
gsteiert | 0:828bfd94972b | 28 | * int main() { |
gsteiert | 0:828bfd94972b | 29 | * char ibuf[256]; |
gsteiert | 0:828bfd94972b | 30 | * char obuf[256]; |
gsteiert | 0:828bfd94972b | 31 | * while(1) { |
gsteiert | 0:828bfd94972b | 32 | * scanf("%s", ibuf); |
switches | 3:601b78524967 | 33 | * serInt.call(ibuf, obuf); |
gsteiert | 0:828bfd94972b | 34 | * printf("%s=", ibuf); |
gsteiert | 0:828bfd94972b | 35 | * printf("%s\n", obuf); |
gsteiert | 0:828bfd94972b | 36 | * } |
gsteiert | 0:828bfd94972b | 37 | * @endcode |
gsteiert | 0:828bfd94972b | 38 | */ |
switches | 2:3f6a8ac111a9 | 39 | class SerialInterface |
gsteiert | 0:828bfd94972b | 40 | { |
gsteiert | 0:828bfd94972b | 41 | public: |
gsteiert | 0:828bfd94972b | 42 | |
switches | 2:3f6a8ac111a9 | 43 | /** Create a SerialInterface interface |
gsteiert | 0:828bfd94972b | 44 | * |
gsteiert | 0:828bfd94972b | 45 | */ |
switches | 9:f52181496512 | 46 | SerialInterface(I2C *i2c, SPI *spi, DigitalInOut* gpio, AnalogIn* ain); |
gsteiert | 0:828bfd94972b | 47 | |
switches | 2:3f6a8ac111a9 | 48 | ~SerialInterface(); |
gsteiert | 0:828bfd94972b | 49 | |
gsteiert | 0:828bfd94972b | 50 | /** Name the I2C arguments |
gsteiert | 0:828bfd94972b | 51 | */ |
gsteiert | 0:828bfd94972b | 52 | enum PINTi2cArgs { |
gsteiert | 0:828bfd94972b | 53 | IA_CNT = 0, /**< Argument Count */ |
gsteiert | 0:828bfd94972b | 54 | IA_ADD, /**< Device Address */ |
gsteiert | 0:828bfd94972b | 55 | IA_DATA, /**< Data, Read = # bytes to read, Write = first data byte */ |
gsteiert | 0:828bfd94972b | 56 | IA_RDDA /**< Read Data, data to write prior to read */ |
gsteiert | 0:828bfd94972b | 57 | }; |
gsteiert | 0:828bfd94972b | 58 | |
switches | 7:06a2eb2483f6 | 59 | /** Process URI encoded commands |
gsteiert | 0:828bfd94972b | 60 | * |
gsteiert | 0:828bfd94972b | 61 | * @param input a pointer to the string containing the command |
gsteiert | 0:828bfd94972b | 62 | * @param output a pointer to the string to write the result |
gsteiert | 0:828bfd94972b | 63 | */ |
gsteiert | 0:828bfd94972b | 64 | void call(char* input, char* output); |
gsteiert | 0:828bfd94972b | 65 | |
gsteiert | 0:828bfd94972b | 66 | private: |
gsteiert | 0:828bfd94972b | 67 | |
switches | 5:9e27e2a46fa6 | 68 | // Types |
switches | 5:9e27e2a46fa6 | 69 | typedef union { |
switches | 5:9e27e2a46fa6 | 70 | struct { |
switches | 5:9e27e2a46fa6 | 71 | char csPin; |
switches | 5:9e27e2a46fa6 | 72 | char csPol; |
switches | 5:9e27e2a46fa6 | 73 | char format; |
switches | 5:9e27e2a46fa6 | 74 | char freq; |
switches | 5:9e27e2a46fa6 | 75 | }; |
switches | 5:9e27e2a46fa6 | 76 | int merged; |
switches | 5:9e27e2a46fa6 | 77 | } spiConfig_t; |
switches | 5:9e27e2a46fa6 | 78 | |
gsteiert | 0:828bfd94972b | 79 | // Internal Functions |
gsteiert | 0:828bfd94972b | 80 | |
switches | 6:c9b7256c8261 | 81 | /** Process Analog Input Command |
switches | 6:c9b7256c8261 | 82 | * |
switches | 6:c9b7256c8261 | 83 | * @param resp a pointer to the string to write the result |
switches | 6:c9b7256c8261 | 84 | */ |
switches | 6:c9b7256c8261 | 85 | void fnc_ain(char* resp); |
switches | 6:c9b7256c8261 | 86 | |
switches | 5:9e27e2a46fa6 | 87 | /** Process Digital I/O Command |
switches | 5:9e27e2a46fa6 | 88 | * |
switches | 5:9e27e2a46fa6 | 89 | * @param resp a pointer to the string to write the result |
switches | 5:9e27e2a46fa6 | 90 | */ |
switches | 5:9e27e2a46fa6 | 91 | void fnc_dio(char* resp); |
switches | 5:9e27e2a46fa6 | 92 | |
gsteiert | 0:828bfd94972b | 93 | /** Process I2C Command |
switches | 5:9e27e2a46fa6 | 94 | * |
gsteiert | 0:828bfd94972b | 95 | * @param resp a pointer to the string to write the result |
gsteiert | 0:828bfd94972b | 96 | */ |
gsteiert | 0:828bfd94972b | 97 | void fnc_i2c(char* resp); |
gsteiert | 0:828bfd94972b | 98 | |
gsteiert | 0:828bfd94972b | 99 | /** Process SPI Command |
switches | 5:9e27e2a46fa6 | 100 | * |
gsteiert | 0:828bfd94972b | 101 | * @param resp a pointer to the string to write the result |
gsteiert | 0:828bfd94972b | 102 | */ |
gsteiert | 0:828bfd94972b | 103 | void fnc_spi(char* resp); |
gsteiert | 0:828bfd94972b | 104 | |
gsteiert | 0:828bfd94972b | 105 | // Internal Resources |
switches | 9:f52181496512 | 106 | I2C *_i2c; |
switches | 9:f52181496512 | 107 | SPI *_spi; |
switches | 5:9e27e2a46fa6 | 108 | DigitalInOut *_gpio; |
switches | 6:c9b7256c8261 | 109 | AnalogIn *_ain; |
gsteiert | 0:828bfd94972b | 110 | |
gsteiert | 0:828bfd94972b | 111 | // Internal Buffers |
switches | 10:94a98d095b2a | 112 | int _args[MAX_NUM_ARGS]; |
switches | 10:94a98d095b2a | 113 | char _dbuf[DBUF_MAX_LENGTH]; |
gsteiert | 0:828bfd94972b | 114 | |
gsteiert | 0:828bfd94972b | 115 | }; |
gsteiert | 0:828bfd94972b | 116 | |
gsteiert | 0:828bfd94972b | 117 | #endif |