Microchip® Advanced Software Framework

Quick Start Guide for USB Device Mouse Module (UDI Mouse)

This is the quick start guide for the USB Device Mouse Module (UDI Mouse) with step-by-step instructions on how to configure and use the modules in a selection of use cases.

The use cases contain several code fragments. The code fragments in the steps for setup can be copied into a custom initialization function, while the steps for usage can be copied into, e.g., the main application function.

Basic Use Case

In this basic use case, the "USB HID Mouse (Single Interface Device)" module is used. The "USB HID Mouse (Composite Device)" module usage is described in Advanced Use Cases.

Setup Steps

As a USB device, it follows common USB device setup steps. Refer to USB Device Basic Setup.

Usage Steps

Example Code

Content of conf_usb.h:

#define UDI_HID_MOUSE_ENABLE_EXT() my_callback_mouse_enable()
extern bool my_callback_mouse_enable(void);
#define UDI_HID_MOUSE_DISABLE_EXT() my_callback_mouse_disable()
extern void my_callback_mouse_disable(void);
#include "udi_hid_mouse_conf.h" // At the end of conf_usb.h file

Add to application C-file:

static bool my_flag_autorize_mouse_events = false;
bool my_callback_mouse_enable(void)
{
my_flag_autorize_mouse_events = true;
return true;
}
void my_callback_mouse_disable(void)
{
my_flag_autorize_mouse_events = false;
}
void my_button_press_event(void)
{
if (!my_flag_autorize_mouse_events) {
return;
}
}

Workflow

  1. Ensure that conf_usb.h is available and contains the following configuration which is the USB device mouse configuration:
    #define UDI_HID_MOUSE_ENABLE_EXT() my_callback_mouse_enable()
    extern bool my_callback_mouse_enable(void);
    Note
    After the device enumeration (detecting and identifying USB devices), the USB host starts the device configuration. When the USB mouse interface from the device is accepted by the host, the USB host enables this interface and the UDI_HID_MOUSE_ENABLE_EXT() callback function is called and return true. Thus, it is recommended to enable sensors used by the mouse in this function.
    #define UDI_HID_MOUSE_DISABLE_EXT() my_callback_mouse_disable()
    extern void my_callback_mouse_disable(void);
    Note
    When the USB device is unplugged or is reset by the USB host, the USB interface is disabled and the UDI_HID_MOUSE_DISABLE_EXT() callback function is called. Thus, it is recommended to disable sensors used by the mouse in this function.
  2. Send mouse events:
    // Sends a value at scroll wheel
    // Sends an Y axis value at mouse pointer
    udi_hid_mouse_moveY(int8_t pos_y);
    // Sends an X axis value at mouse pointer
    udi_hid_mouse_moveX(int8_t pos_x);
    // Sends a middle click event
    // Sends a right click event
    udi_hid_mouse_btnright(bool b_state);
    // Sends a left click event
    udi_hid_mouse_btnleft(bool b_state);

Advanced Use Cases

For more advanced use of the UHI HID mouse module, see the following use cases: