nexpaq / SerialInterface

Fork of SerialInterface by Greg Steiert

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SerialInterface.h Source File

SerialInterface.h

00001 /* Pmod Interface Library
00002  *
00003  */
00004 #ifndef SERIALINTERFACE_H
00005 #define SERIALINTERFACE_H
00006 
00007 #include "mbed.h"
00008 #include "SerialInterface.h"
00009 
00010 #define MAX_NUM_ARGS      0x400
00011 #define DBUF_MAX_LENGTH   0x400
00012 
00013 /** Serial Interface Library, Provides utilities for remotely accessing peripherals
00014  *
00015  * Example:
00016  * @code
00017  * // Configure board to pass UART signals to peripheral connector.
00018  *
00019  * #include "SerialInterface.h"
00020  *
00021  * I2C i2c(P3_4, P3_5);
00022  * SPI spi(P5_1, P5_2, P5_0);
00023  * DigitalInOut gpio[] = {P5_3, P5_4, P5_5, P5_6, P3_0, P3_1, P3_2, P3_3};
00024  * AnalogIn ain[] = {AIN_0, AIN_1, AIN_2, AIN_3, AIN_4, AIN_5, AIN_6, AIN_7};
00025  * 
00026  * SerialInterface serInt(i2c, spi, gpio, ain);
00027  *
00028  * int main() {
00029  *    char ibuf[256];
00030  *    char obuf[256];
00031  *    while(1) {
00032  *        scanf("%s", ibuf);
00033  *        serInt.call(ibuf, obuf);
00034  *        printf("%s=", ibuf);
00035  *        printf("%s\n", obuf);
00036  * }
00037  * @endcode
00038  */
00039 class SerialInterface
00040 {
00041 public:
00042 
00043     /** Create a SerialInterface interface
00044      *
00045      */
00046     SerialInterface(I2C *i2c, SPI *spi, DigitalInOut* gpio, AnalogIn* ain);
00047 
00048     ~SerialInterface();
00049 
00050     /** Name the I2C arguments
00051     */
00052     enum PINTi2cArgs {
00053         IA_CNT = 0, /**< Argument Count */
00054         IA_ADD,     /**< Device Address */
00055         IA_DATA,    /**< Data, Read = # bytes to read, Write = first data byte */
00056         IA_RDDA     /**< Read Data, data to write prior to read */
00057     };
00058 
00059     /** Process URI encoded commands
00060      *
00061      *  @param input a pointer to the string containing the command
00062      *  @param output a pointer to the string to write the result
00063      */
00064     void call(char* input, char* output);
00065 
00066 private:
00067 
00068     // Types
00069     typedef union {
00070         struct {
00071             char csPin;
00072             char csPol;
00073             char format;
00074             char freq;
00075         };
00076         int merged;
00077     } spiConfig_t;
00078 
00079     // Internal Functions
00080 
00081     /** Process Analog Input Command
00082      *
00083      *  @param resp a pointer to the string to write the result
00084      */
00085     void fnc_ain(char* resp);
00086 
00087     /** Process Digital I/O Command
00088      *
00089      *  @param resp a pointer to the string to write the result
00090      */
00091     void fnc_dio(char* resp);
00092 
00093     /** Process I2C Command
00094      *
00095      *  @param resp a pointer to the string to write the result
00096      */
00097     void fnc_i2c(char* resp);
00098 
00099     /** Process SPI Command
00100      *
00101      *  @param resp a pointer to the string to write the result
00102      */
00103     void fnc_spi(char* resp);
00104 
00105     // Internal Resources
00106     I2C *_i2c;
00107     SPI *_spi;
00108     DigitalInOut *_gpio;
00109     AnalogIn *_ain;
00110 
00111     // Internal Buffers
00112     int _args[MAX_NUM_ARGS];
00113     char _dbuf[DBUF_MAX_LENGTH];
00114 
00115 };
00116 
00117 #endif