CHENGQI YANG / MGC3130

Dependencies:   BufferedArray

Dependents:   NucleoMGC3130 i2c_master

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MGC3130.h Source File

MGC3130.h

00001 #ifndef UK_AC_HERTS_SMARTLAB_MGC3130
00002 #define UK_AC_HERTS_SMARTLAB_MGC3130
00003 
00004 #include "mbed.h"
00005 #include "GestICMsg.h"
00006 #include "SensorData.h"
00007 #include "Parameter.h"
00008 #include "TouchDetection.h"
00009 #include "AirWheelDetection.h"
00010 #include "ApproachDetection.h"
00011 #include "TouchInfo.h"
00012 #include "OutputEnable.h"
00013 #include "Trigger.h"
00014 #include "MakePersistent.h"
00015 #include "CalibrationMode.h"
00016 #include "GestureProcessing.h"
00017 
00018 /**
00019 * Outlines the function of the Library’s I2C message interface, and contains the complete message reference to control and operate the MGC3X30 system.
00020  *
00021  * Example:
00022  * @code
00023 *#include "mbed.h"
00024 *#include "MGC3130.h"
00025 *
00026 *SensorData * msg = NULL;
00027 *
00028 *void init()
00029 *{
00030 *    AirWheelDetection air(true);
00031 *    device.setRuntimeParameter(&air);
00032 *
00033 *    TouchDetection touch(true);
00034 *    device.setRuntimeParameter(&touch);
00035 *
00036 *    OutputEnable setting;
00037 *    setting.enableGestureData(true)->enableTouchInfo(true)->enableAirWheelInfo(true)->enableNoisePower(false)
00038 *    ->enablexyzPosition(false)->enableDSPStatus(false)->enableUncalibratedSignal(false)->enableSignalDeviation(false);
00039 *    device.setRuntimeParameter(&setting);
00040 *}
00041 *
00042 *void touch()
00043 *{
00044 *    TouchInfo * info = msg->getTouchInfo();
00045 *
00046 *    if (info == NULL)
00047 *        return;
00048 *
00049 *    if (info->isTapCenterElectrode() == false)
00050 *        return;
00051 *}
00052 *
00053 *void airWheel()
00054 *{
00055 *    int * wheel = msg->getAirWheelInfo();
00056 *    if (wheel == NULL)
00057 *        return;
00058 *}
00059 *
00060 *void gesture()
00061 *{
00062 *    GestureInfo * info = msg->getGestureInfo();
00063 *
00064 *    if (info == NULL)
00065 *        return;
00066 *
00067 *    switch (info->getRecognizedGesture()) {
00068 *            //Garbage Model
00069 *        case 1 :
00070 *            break;
00071 *            //Flick West To East
00072 *        case 2 :
00073 *            break;
00074 *            //Flick East To West
00075 *        case 3 :
00076 *            break;
00077 *            //Flick South To North
00078 *        case 4 :
00079 *            break;
00080 *            //Flick North To South
00081 *        case 5 :
00082 *            break;
00083 *    }
00084 *}
00085 *
00086 *int main()
00087 *{
00088 *    init();
00089 *
00090 *    while(1) {
00091 *        msg = device.readSensorData();
00092 *
00093 *        if (msg == NULL)
00094 *            continue;
00095 *
00096 *        touch();
00097 *
00098 *        gesture();
00099 *
00100 *        airWheel();
00101 *    }
00102 *}
00103  * @endcode
00104  *
00105 */
00106 class MGC3130
00107 {
00108 private:
00109     static const int FREQUENCY_STANDARD = 100000;
00110     static const int FREQUENCY_FULL = 400000;
00111     static const int FREQUENCY_FAST = 1000000;
00112     static const int FREQUENCY_HIGH = 3200000;
00113 
00114     /// EI0 Pin:  The TS line is used to check whether the I2C data is valid and can be sent from MGC3X30 to the host controller.
00115     DigitalInOut TS_Line;
00116 
00117     I2C _i2c_bus;
00118     int _speed;
00119     int _addr;
00120     GestICMsg msg;
00121     SensorData sensor;
00122 
00123 protected:
00124     GestICMsg * readMsg();
00125 
00126 public:
00127     /** Construct a message with existing @GestICMsg as its base.
00128     * IS2 is available for address selection and enables the user to connect up to two MGC3X30 devices on the same bus without address conflict.
00129     * The MGC3X30 I2C addresses are 0x42 and 0x43. They are given as device addresses without the R/W bit.
00130     * In addition, MGC3X30 requires a dedicated transfer status line (TS), which features a
00131     * data transfer status function. The TS is used by both I2C Master and Slave to control
00132     * the data flow. I2C SCL, I2C SDA and TS lines require an open-drain connection on
00133     * MGC3X30 and the connected host controller. To function properly, I2C SCL and I2C
00134     * SDA need to be pulled up to VCC with 1.8 kΩ resistors and the TS line needs to be
00135     * pulled up to VCC with a 10 kΩ resistor.
00136     *
00137     * @param sda I2C sda signal
00138     * @param scl I2C scl signal
00139     * @param EI0 transfer status line
00140     * @param IS2 High->true, Low->false
00141     *
00142     */
00143     MGC3130(PinName sda, PinName scl, PinName EI0, bool IS2);
00144 
00145     /** Get a sensor data payload from the device.
00146     *
00147     * @returns @SensorData NULL means data not avaliable
00148     *
00149     */
00150     SensorData * readSensorData();
00151 
00152     /** Set the system runtime parameters.
00153     *
00154     * @param para @Parameter and any RuntimeParameter classes
00155     *
00156     * @returns
00157     *0x0000 NoError OK
00158     *0x0001 UnknownCommand Message ID is unknown
00159     *0x0002 InvalidSessionId Session ID is invalid or does not match (0x0 is not allowed) (message Fw_Update_Start, Fw_Update_Completed)
00160     *0x0003 InvalidCrc CRC is invalid thrown by messages: Fw_Update_Block, Fw_Update_Start, Fw_Update_Completed
00161     *0x0004 InvalidLength Length is invalid (message Fw_Update_Block)
00162     *0x0005 InvalidAddress Address is invalid (message Fw_Update_Block)
00163     *0x0006 InvalidFunction Function-Id is invalid (message Fw_Update_Start, Fw_Update_Block, Fw_Update_Completed)
00164     *0x0008 ContentMismatch The VerifyOnly function found a mismatch between content and Flash memory (message: Fw_Update_Block)
00165     *0x000B WrongParameterAddr Parameter Start address, contained in the new Library FW to be loaded, does not match Library Loader assumption. The Library Update is therefore aborted. (message: Fw_Update_Start)
00166     *0x0014 WrongParameterValue The value of the Argument/Parameter of a RuntimeParameter command is out of the valid range (message: Request_Message and Set_Runtime_Parameter)
00167     *0x0015 UnknownParameterID The MessageID or RuntimeParameterID is unknown or out of the valid range (message: Request_Message and Set_Runtime_Parameter)
00168     *0x001A WakeupHappend A wake-up by Host was detected
00169     *0x0080 LoaderUpdateStarted The Library Loader update started
00170     *0x0081 LoaderUpdateFinished The Library Loader update finished
00171     */
00172     int setRuntimeParameter(Parameter * para);
00173 };
00174 
00175 #endif