Command processor to access I2C and SPI Takes URI coded commands and returns JSON array
Fork of SerialInterface by
SerialInterface.h
- Committer:
- switches
- Date:
- 2016-12-15
- Revision:
- 6:c9b7256c8261
- Parent:
- 5:9e27e2a46fa6
- Child:
- 7:06a2eb2483f6
File content as of revision 6:c9b7256c8261:
/* Pmod Interface Library * */ #ifndef SERIALINTERFACE_H #define SERIALINTERFACE_H #include "mbed.h" #include "SerialInterface.h" /** RAPC Library, Provides utilities for remotely accessing peripherals * * Example: * @code * // Configure board to pass UART signals to peripheral connector. * * #include "SerialInterface.h" * * SerialInterface serInt; * I2C i2c(P3_4, P3_5); * SPI spi(P5_1, P5_2, P5_0); * DigitalOut ssel(P5_3); * * int main() { * char ibuf[256]; * char obuf[256]; * serInt.init(&i2c, &spi, &ssel); * while(1) { * scanf("%s", ibuf); * serInt.call(ibuf, obuf); * printf("%s=", ibuf); * printf("%s\n", obuf); * } * @endcode */ class SerialInterface { public: /** Create a SerialInterface interface * */ SerialInterface(I2C &i2c, SPI &spi); ~SerialInterface(); /** Name the I2C arguments */ enum PINTi2cArgs { IA_CNT = 0, /**< Argument Count */ IA_ADD, /**< Device Address */ IA_DATA, /**< Data, Read = # bytes to read, Write = first data byte */ IA_RDDA /**< Read Data, data to write prior to read */ }; /** Initialize the digital pins and PWM * */ void init(DigitalInOut* gpio, AnalogIn* ain); /** Process Remote Arduino Peripheral Module Command * * @param input a pointer to the string containing the command * @param output a pointer to the string to write the result */ void call(char* input, char* output); private: // Types typedef union { struct { char csPin; char csPol; char format; char freq; }; int merged; } spiConfig_t; // Internal Functions /** Process Analog Input Command * * @param resp a pointer to the string to write the result */ void fnc_ain(char* resp); /** Process Digital I/O Command * * @param resp a pointer to the string to write the result */ void fnc_dio(char* resp); /** Process I2C Command * * @param resp a pointer to the string to write the result */ void fnc_i2c(char* resp); /** Process SPI Command * * @param resp a pointer to the string to write the result */ void fnc_spi(char* resp); // Internal Resources I2C _i2c; SPI _spi; DigitalInOut *_gpio; AnalogIn *_ain; // Internal Buffers int _args[64]; char _dbuf[256]; }; #endif