#include "vmdcl.h"
VM_DCL_HANDLE eint_handle; // Declares a VM_DCL_HANDLE variable.
vm_eint_control_config_t eint_config; // Declares a vm_eint_control_config_t variable.
vm_eint_control_sensitivity_t sens_data; // Declares a vm_eint_control_sensitivity_t variable.
vm_eint_control_hw_debounce_t debounce_time; // Declares a vm_eint_control_hw_debounce_t variable.
eint_handle = vm_dcl_open(VM_DCL_EINT, PIN2EINT(VM_PIN_P0)); // Calls vm_dcl_open() to get a handle. Use PIN2EINT to convert from pin name to EINT number.
vm_dcl_control(eint_handle, VM_EINT_COMMAND_MASK, NULL); // Before configuring EINT, we mask it firstly.
vm_dcl_registercallback(eint_handle, EVENT_EINT_TRIGGER, eint_callback, (void*)NULL ); // Registers the callback. Note: the last parameter is NULL.
sens_data.sensitivity = 1; // 1 means the Level Sensitive. 0 means the Edge Sensitive.
vm_dcl_control(eint_handle, VM_EINT_COMMAND_SET_SENSITIVITY, (void *)&sens_data); // Sets EINT sensitivity.
debounce_time.debounce_time = 10; // Debounce time 10ms
vm_dcl_control(eint_handle,VM_EINT_COMMAND_SET_HW_DEBOUNCE,(void *)&debounce_time); // Set debounce time
eint_config.act_polarity = 0; // 1 means positive activated. 0 means negative activated.
eint_config.debounce_en = 1; // 1 means to enable the HW debounce. 0 means to disable the HW debounce.
eint_config.auto_unmask = 1; // 1 means to unmask after callback. 0 means not to unmask and the callers should unmask themselves.
vm_dcl_control(eint_handle, VM_EINT_COMMAND_CONFIG, (void*)&eint_config); // Calls this API prior to unmasking the EINT next.
vm_dcl_control(eint_handle, VM_EINT_COMMAND_UNMASK, NULL); // Calls this function to unmask the EINT.
vm_dcl_close(eint_handle); // Finally, calls vm_dcl_close().