The M2M_hwEvents.c file contains the following callback functions:
Callback |
Event starting the callback: |
M2M_onWakeup(…) |
expiration of the alarm time |
M2M_onInterrupt(…) |
interrupt created by a GPIO |
M2M_onHWTimer(…) |
expiration of the hardware timer |
M2M_onUSbCableEvent(...) |
plugging in/unplugging USB cable |
M2M_onI2CEvent(…) |
for future use |
M2M_onKeyEvent(…) |
actions on the “ON” key |
M2M_onWakeup(…) example:
• Use the m2m_rtc_set_date(…) and m2m_rtc_set_time(…) APIs to set the date and time of the module. Use the m2m_rtc_set_alarm(…) API to set the date and time of the alarm;
• When the date/time alarm is reached the M2M_onWakeup(…) callback is executed.
M2M_onInterrupt(…) example:
• Connect GPIO X with GPIO Y using a wire;
• Use the m2m_hw_gpio_write(…) API to force to 0 the GPIO X. Use the m2m_hw_gpio _int_enable(…) to configure the GPIO Y as a source of interrupt. Force to 1 the GPIO X via the m2m_hw_gpio_write(…) API;
• When the transition on the GPIO Y is detected, the M2M_onInterrupt(…) callback is executed.
M2M_onHWTimer(…) example:
When one or more hardware timers are expired, the control calls the M2M_onHWTimer(…) callback. The developer writes in the callback the code that will be executed in accordance with the identifier of the expired timer.
• Use the m2m_hw_timer_start(…) API to start one or more hardware timers;
• When an hardware timer expires the M2M_onHWTimer(…) callback is activated;
• M2M_onHWTimer(…) callback executes the code written by the developer in accordance with the identifier of the expired timer.
M2M_onUSbCableEvent(UINT32 usb_cable_event) example:
The function checks the plugging in/unplugging of the USB cable.
• When the USB cable is plugged in, the control calls the callback with the "usb_cable_event" parameter equal to 1.
• When the USB cable is unplugged, the control calls the callback with the "usb_cable_event" parameter equal to 0.
M2M_onKeyEvent(INT32 val1, INT32 val2) example:
The function checks the “ON” key that turns on/off the module.
• When the “ON” key is pushed, the control calls the callback with the "val1" parameter equal to 1 (key is pressed) and the "val2" parameter equal to 12 (key code of the "ON" key).
• When the “ON” key is released, the control calls the callback with the "val1" parameter equal to 0 (key is released) and the "val2" parameter equal to 12 (key code of the "ON" key).
• If the “ON” key is pushed down for a long time the control calls the callback with the "val1" parameter equal to 2 (key is held down) and the "val2" parameter equal to 12 (key code of the "ON" key). The callback is continuously called. Use the UART API to print out key status and code.