Command processor to access I2C and SPI Takes URI coded commands and returns JSON array
Fork of SerialInterface by
SerialInterface.h@6:c9b7256c8261, 2016-12-15 (annotated)
- Committer:
- switches
- Date:
- Thu Dec 15 03:56:56 2016 +0000
- Revision:
- 6:c9b7256c8261
- Parent:
- 5:9e27e2a46fa6
- Child:
- 7:06a2eb2483f6
Added analog function
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 | |
gsteiert | 0:828bfd94972b | 10 | /** RAPC Library, Provides utilities for remotely accessing peripherals |
gsteiert | 0:828bfd94972b | 11 | * |
gsteiert | 0:828bfd94972b | 12 | * Example: |
gsteiert | 0:828bfd94972b | 13 | * @code |
gsteiert | 0:828bfd94972b | 14 | * // Configure board to pass UART signals to peripheral connector. |
gsteiert | 0:828bfd94972b | 15 | * |
switches | 2:3f6a8ac111a9 | 16 | * #include "SerialInterface.h" |
gsteiert | 0:828bfd94972b | 17 | * |
switches | 2:3f6a8ac111a9 | 18 | * SerialInterface serInt; |
switches | 3:601b78524967 | 19 | * I2C i2c(P3_4, P3_5); |
switches | 4:0bd9ec504040 | 20 | * SPI spi(P5_1, P5_2, P5_0); |
switches | 4:0bd9ec504040 | 21 | * DigitalOut ssel(P5_3); |
gsteiert | 0:828bfd94972b | 22 | * |
gsteiert | 0:828bfd94972b | 23 | * int main() { |
gsteiert | 0:828bfd94972b | 24 | * char ibuf[256]; |
gsteiert | 0:828bfd94972b | 25 | * char obuf[256]; |
switches | 4:0bd9ec504040 | 26 | * serInt.init(&i2c, &spi, &ssel); |
gsteiert | 0:828bfd94972b | 27 | * while(1) { |
gsteiert | 0:828bfd94972b | 28 | * scanf("%s", ibuf); |
switches | 3:601b78524967 | 29 | * serInt.call(ibuf, obuf); |
gsteiert | 0:828bfd94972b | 30 | * printf("%s=", ibuf); |
gsteiert | 0:828bfd94972b | 31 | * printf("%s\n", obuf); |
gsteiert | 0:828bfd94972b | 32 | * } |
gsteiert | 0:828bfd94972b | 33 | * @endcode |
gsteiert | 0:828bfd94972b | 34 | */ |
switches | 2:3f6a8ac111a9 | 35 | class SerialInterface |
gsteiert | 0:828bfd94972b | 36 | { |
gsteiert | 0:828bfd94972b | 37 | public: |
gsteiert | 0:828bfd94972b | 38 | |
switches | 2:3f6a8ac111a9 | 39 | /** Create a SerialInterface interface |
gsteiert | 0:828bfd94972b | 40 | * |
gsteiert | 0:828bfd94972b | 41 | */ |
switches | 6:c9b7256c8261 | 42 | SerialInterface(I2C &i2c, SPI &spi); |
gsteiert | 0:828bfd94972b | 43 | |
switches | 2:3f6a8ac111a9 | 44 | ~SerialInterface(); |
gsteiert | 0:828bfd94972b | 45 | |
gsteiert | 0:828bfd94972b | 46 | /** Name the I2C arguments |
gsteiert | 0:828bfd94972b | 47 | */ |
gsteiert | 0:828bfd94972b | 48 | enum PINTi2cArgs { |
gsteiert | 0:828bfd94972b | 49 | IA_CNT = 0, /**< Argument Count */ |
gsteiert | 0:828bfd94972b | 50 | IA_ADD, /**< Device Address */ |
gsteiert | 0:828bfd94972b | 51 | IA_DATA, /**< Data, Read = # bytes to read, Write = first data byte */ |
gsteiert | 0:828bfd94972b | 52 | IA_RDDA /**< Read Data, data to write prior to read */ |
gsteiert | 0:828bfd94972b | 53 | }; |
gsteiert | 0:828bfd94972b | 54 | |
gsteiert | 0:828bfd94972b | 55 | /** Initialize the digital pins and PWM |
gsteiert | 0:828bfd94972b | 56 | * |
gsteiert | 0:828bfd94972b | 57 | */ |
switches | 6:c9b7256c8261 | 58 | void init(DigitalInOut* gpio, AnalogIn* ain); |
gsteiert | 0:828bfd94972b | 59 | |
gsteiert | 0:828bfd94972b | 60 | /** Process Remote Arduino Peripheral Module Command |
gsteiert | 0:828bfd94972b | 61 | * |
gsteiert | 0:828bfd94972b | 62 | * @param input a pointer to the string containing the command |
gsteiert | 0:828bfd94972b | 63 | * @param output a pointer to the string to write the result |
gsteiert | 0:828bfd94972b | 64 | */ |
gsteiert | 0:828bfd94972b | 65 | void call(char* input, char* output); |
gsteiert | 0:828bfd94972b | 66 | |
gsteiert | 0:828bfd94972b | 67 | private: |
gsteiert | 0:828bfd94972b | 68 | |
switches | 5:9e27e2a46fa6 | 69 | // Types |
switches | 5:9e27e2a46fa6 | 70 | typedef union { |
switches | 5:9e27e2a46fa6 | 71 | struct { |
switches | 5:9e27e2a46fa6 | 72 | char csPin; |
switches | 5:9e27e2a46fa6 | 73 | char csPol; |
switches | 5:9e27e2a46fa6 | 74 | char format; |
switches | 5:9e27e2a46fa6 | 75 | char freq; |
switches | 5:9e27e2a46fa6 | 76 | }; |
switches | 5:9e27e2a46fa6 | 77 | int merged; |
switches | 5:9e27e2a46fa6 | 78 | } spiConfig_t; |
switches | 5:9e27e2a46fa6 | 79 | |
gsteiert | 0:828bfd94972b | 80 | // Internal Functions |
gsteiert | 0:828bfd94972b | 81 | |
switches | 6:c9b7256c8261 | 82 | /** Process Analog Input Command |
switches | 6:c9b7256c8261 | 83 | * |
switches | 6:c9b7256c8261 | 84 | * @param resp a pointer to the string to write the result |
switches | 6:c9b7256c8261 | 85 | */ |
switches | 6:c9b7256c8261 | 86 | void fnc_ain(char* resp); |
switches | 6:c9b7256c8261 | 87 | |
switches | 5:9e27e2a46fa6 | 88 | /** Process Digital I/O Command |
switches | 5:9e27e2a46fa6 | 89 | * |
switches | 5:9e27e2a46fa6 | 90 | * @param resp a pointer to the string to write the result |
switches | 5:9e27e2a46fa6 | 91 | */ |
switches | 5:9e27e2a46fa6 | 92 | void fnc_dio(char* resp); |
switches | 5:9e27e2a46fa6 | 93 | |
gsteiert | 0:828bfd94972b | 94 | /** Process I2C Command |
switches | 5:9e27e2a46fa6 | 95 | * |
gsteiert | 0:828bfd94972b | 96 | * @param resp a pointer to the string to write the result |
gsteiert | 0:828bfd94972b | 97 | */ |
gsteiert | 0:828bfd94972b | 98 | void fnc_i2c(char* resp); |
gsteiert | 0:828bfd94972b | 99 | |
gsteiert | 0:828bfd94972b | 100 | /** Process SPI Command |
switches | 5:9e27e2a46fa6 | 101 | * |
gsteiert | 0:828bfd94972b | 102 | * @param resp a pointer to the string to write the result |
gsteiert | 0:828bfd94972b | 103 | */ |
gsteiert | 0:828bfd94972b | 104 | void fnc_spi(char* resp); |
gsteiert | 0:828bfd94972b | 105 | |
gsteiert | 0:828bfd94972b | 106 | // Internal Resources |
switches | 6:c9b7256c8261 | 107 | I2C _i2c; |
switches | 6:c9b7256c8261 | 108 | SPI _spi; |
switches | 5:9e27e2a46fa6 | 109 | DigitalInOut *_gpio; |
switches | 6:c9b7256c8261 | 110 | AnalogIn *_ain; |
gsteiert | 0:828bfd94972b | 111 | |
gsteiert | 0:828bfd94972b | 112 | // Internal Buffers |
switches | 2:3f6a8ac111a9 | 113 | int _args[64]; |
switches | 5:9e27e2a46fa6 | 114 | char _dbuf[256]; |
gsteiert | 0:828bfd94972b | 115 | |
gsteiert | 0:828bfd94972b | 116 | }; |
gsteiert | 0:828bfd94972b | 117 | |
gsteiert | 0:828bfd94972b | 118 | #endif |