Author | Matthew Schinkel |
Adapted-by | |
Compiler | >=2.5r4 |
This application emulates a mouse USB human interface device (HID), once the USB device has been configured and the USB HID device is recognized by the host operating systems, it will move the computer mouse.
Albert Faber& Joep Suijs jallib usb_keyboard library https://www.silabs.com/documents/public/application-notes/AN249.pdf
const byte USB_EP3_OUT_SIZE = 8
var volatile bit _usb_hid_can_tx = true
const bit USB_EP1 = 1
var byte usb_mouse_report[8]
const byte USB_CONFIGURATION_DESCRIPTOR[ USB_CONFIGURATION_DESCRIPTOR_SIZE ]=
const byte USB_EP0_OUT_SIZE = 8
const byte USB_DEVICE_DESCRIPTOR[USB_DEVICE_DESCRIPTOR_SIZE] = {
const bit USB_EP2 = 0
const word USB_EP0_OUT_ADDR = ( USB_BASE_ADDRESS + 0x0010 )
const bit USB_EP0 = 1
const word USB_EP3_OUT_ADDR = 0x0000
const byte USB_HCR_SET_PROTOCOL = 0x0B
const byte USB_HCR_SET_REPORT = 0x09
const USB_CONFIGURATION_DESCRIPTOR_SIZE = 0x09 + 0x09 + 0x09 + 0x07
const byte USB_HCR_GET_PROTOCOL = 0x03
var volatile byte usb_ep0in_buf[ USB_EP0_IN_SIZE ] at USB_EP0_IN_ADDR
const word USB_EP2_IN_ADDR = 0x0000
const byte USB_HID_REQ_HID = 0x21
var volatile byte usb_ep0out_buf[ USB_EP0_OUT_SIZE ] at USB_EP0_OUT_ADDR
var volatile byte usb_ep1in_buf[ USB_EP1_IN_SIZE ] at USB_EP1_IN_ADDR
const byte USB_HID_REPORT1[]=
const word USB_EP3_IN_ADDR = 0x0000
const byte USB_EP1_OUT_SIZE = 4
const byte USB_HID_ENDPOINT = 0x01
const byte USB_EP3_IN_SIZE = 8
var volatile byte usb_ep1out_buf[ USB_EP1_OUT_SIZE ] at USB_EP1_OUT_ADDR
const USB_MOUSE_RIGHT_BUTTON = 0x02
const byte USB_EP1_IN_SIZE = 4
const bit USB_EP3 = 0
const word USB_EP2_OUT_ADDR = 0x0000
const byte USB_HCR_GET_REPORT = 0x01
const byte USB_HCR_GET_IDLE = 0x02
const USB_MOUSE_LEFT_BUTTON = 0x01
const byte USB_EP0_IN_SIZE = 8
const byte USB_EP2_IN_SIZE = 8
const byte USB_HID_REQ_REPORT = 0x22
const word USB_EP1_OUT_ADDR = ( USB_EP0_IN_ADDR + USB_EP0_IN_SIZE )
const byte USB_HID_REQ_PHYSDISCR = 0x23
const USB_MOUSE_BUTTONS_UP = 0x00
const word USB_EP1_IN_ADDR = ( USB_EP1_OUT_ADDR + USB_EP1_OUT_SIZE )
const byte USB_EP2_OUT_SIZE = 8
const word USB_EP0_IN_ADDR = ( USB_EP0_OUT_ADDR + USB_EP0_OUT_SIZE )
const byte USB_STRING0[] =
const USB_MOUSE_WHEEL_BUTTON = 0x04
const byte USB_HCR_SET_IDLE = 0x0A
usb_handle_class_request_callback()
usb_mouse_send_button(byte in button)
usb_mouse_right_click()
usb_handle_class_ctrl_read_callback()
usb_mouse_left_click()
usb_mouse_wheel_click()
usb_mouse_move(sbyte in move_left_right, sbyte in move_up_down)
usb_mouse_flush()
usb_mouse_init()
usb_handle_class_ctrl_write_callback()
usb_mouse_move_wheel(sbyte in data)
usb_ep_data_in_callback(byte in end_point, word in buffer_addr, byte in byte_count)
const byte USB_EP3_OUT_SIZE = 8
No documentation found
var volatile bit _usb_hid_can_tx = true
No documentation found
const bit USB_EP1 = 1
No documentation found
var byte usb_mouse_report[8]
No documentation found
const byte USB_CONFIGURATION_DESCRIPTOR[ USB_CONFIGURATION_DESCRIPTOR_SIZE ]=
No documentation found
const byte USB_EP0_OUT_SIZE = 8
No documentation found
const byte USB_DEVICE_DESCRIPTOR[USB_DEVICE_DESCRIPTOR_SIZE] = {
USB Descriptors
const bit USB_EP2 = 0
No documentation found
const word USB_EP0_OUT_ADDR = ( USB_BASE_ADDRESS + 0x0010 )
No documentation found
const bit USB_EP0 = 1
No documentation found
const word USB_EP3_OUT_ADDR = 0x0000
No documentation found
const byte USB_HCR_SET_PROTOCOL = 0x0B
No documentation found
const byte USB_HCR_SET_REPORT = 0x09
No documentation found
const USB_CONFIGURATION_DESCRIPTOR_SIZE = 0x09 + 0x09 + 0x09 + 0x07
No documentation found
const byte USB_HCR_GET_PROTOCOL = 0x03
No documentation found
var volatile byte usb_ep0in_buf[ USB_EP0_IN_SIZE ] at USB_EP0_IN_ADDR
No documentation found
const word USB_EP2_IN_ADDR = 0x0000
No documentation found
const byte USB_HID_REQ_HID = 0x21
No documentation found
var volatile byte usb_ep0out_buf[ USB_EP0_OUT_SIZE ] at USB_EP0_OUT_ADDR
No documentation found
var volatile byte usb_ep1in_buf[ USB_EP1_IN_SIZE ] at USB_EP1_IN_ADDR
No documentation found
const byte USB_HID_REPORT1[]=
No documentation found
const word USB_EP3_IN_ADDR = 0x0000
No documentation found
const byte USB_EP1_OUT_SIZE = 4
No documentation found
const byte USB_HID_ENDPOINT = 0x01
No documentation found
const byte USB_EP3_IN_SIZE = 8
No documentation found
var volatile byte usb_ep1out_buf[ USB_EP1_OUT_SIZE ] at USB_EP1_OUT_ADDR
No documentation found
const USB_MOUSE_RIGHT_BUTTON = 0x02
No documentation found
const byte USB_EP1_IN_SIZE = 4
No documentation found
const bit USB_EP3 = 0
No documentation found
const word USB_EP2_OUT_ADDR = 0x0000
No documentation found
const byte USB_HCR_GET_REPORT = 0x01
No documentation found
const byte USB_HCR_GET_IDLE = 0x02
No documentation found
const USB_MOUSE_LEFT_BUTTON = 0x01
No documentation found
const byte USB_EP0_IN_SIZE = 8
No documentation found
const byte USB_EP2_IN_SIZE = 8
No documentation found
const byte USB_HID_REQ_REPORT = 0x22
No documentation found
const word USB_EP1_OUT_ADDR = ( USB_EP0_IN_ADDR + USB_EP0_IN_SIZE )
No documentation found
const byte USB_HID_REQ_PHYSDISCR = 0x23
No documentation found
const USB_MOUSE_BUTTONS_UP = 0x00
Mouse code definitions
const word USB_EP1_IN_ADDR = ( USB_EP1_OUT_ADDR + USB_EP1_OUT_SIZE )
No documentation found
const byte USB_EP2_OUT_SIZE = 8
No documentation found
const word USB_EP0_IN_ADDR = ( USB_EP0_OUT_ADDR + USB_EP0_OUT_SIZE )
No documentation found
const byte USB_STRING0[] =
No documentation found
const USB_MOUSE_WHEEL_BUTTON = 0x04
No documentation found
const byte USB_HCR_SET_IDLE = 0x0A
No documentation found
usb_handle_class_request_callback()
No documentation found
usb_mouse_send_button(byte in button)
send a mouse button command
usb_mouse_right_click()
mouse right click
usb_handle_class_ctrl_read_callback()
No documentation found
usb_mouse_left_click()
mouse left click
usb_mouse_wheel_click()
mouse wheel click
usb_mouse_move(sbyte in move_left_right, sbyte in move_up_down)
Move the mouse
usb_mouse_flush()
usb_mouse_flush shall be called on a regular base (millisecond range) in order to keep the USB communcation alive. Therfore it is adviced to call the usb_mouse _flush procedure in the main loop of your application. Note: Only needed when USB interrupt is not used otherwise this call can be omitted (it does nothing in interrupt mode).
usb_mouse_init()
usb_mouse_init will setup the HID USB communication with the HOST, however, this can be a time consuming process, therefore this call is non blocking. In order to check if communication with the HOST has been established, one can call the usb_is_configured() function, see usb_is_configured() documentation for additional details.
usb_handle_class_ctrl_write_callback()
No documentation found
usb_mouse_move_wheel(sbyte in data)
Move the mouse
usb_ep_data_in_callback(byte in end_point, word in buffer_addr, byte in byte_count)
No documentation found
_usb_hid_tx_report( byte in hid_report_in[], byte in cnt )
_usb_hid_tx_report, internal function to send a HID report
18f67j50 | 18f67j50_usb_mouse.jal |