USB HID Peripheral
Bootloader » Peripheral Definitions

USB HID peripheral interface. More...

Collaboration diagram for USB HID Peripheral:

## Data Structures

struct | usb_hid_packetizer_info_t
| State information for the USB HID packetizer. More...

## Enumerations

enum | { kAppRequestParam_IdleRate = 0, kAppRequestParam_Protocol, kAppRequestParamCount }
| Request parameters.
enum | { kAppRequestParam_IdleRate = 0, kAppRequestParam_Protocol, kAppRequestParamCount }
| Request parameters.

## Functions

static bool | usb_hid_poll_for_activity (const peripheral_descriptor_t *self)
static status_t | usb_device_full_init (const peripheral_descriptor_t *self, serial_byte_receive_func_t function)
static void | usb_device_full_shutdown (const peripheral_descriptor_t *self)
static void | usb_msc_pump (const peripheral_descriptor_t *self)
| Run the sbloader state machine. More...
static status_t | usb_hid_packet_init (const peripheral_descriptor_t *self)
static status_t | usb_hid_packet_read (const peripheral_descriptor_t *self, uint8_t **packet, uint32_t *packetLength, packet_type_t packetType)
static status_t | usb_hid_packet_write (const peripheral_descriptor_t *self, const uint8_t *packet, uint32_t byteCount, packet_type_t packetType)
static void | usb_hid_packet_abort_data_phase (const peripheral_descriptor_t *self)
static status_t | usb_hid_packet_finalize (const peripheral_descriptor_t *self)
static uint32_t | usb_hid_packet_get_max_packet_size (const peripheral_descriptor_t *self)
usb_status_t | usb_device_callback (usb_device_handle handle, uint32_t event, void *param)
usb_status_t | usb_device_msc_callback (class_handle_t handle, uint32_t event, void *param)
| device msc callback function. More...
void | USBHS_IRQHandler (void)
void | USB0_IRQHandler (void)
static void | usb_hid_app_callback (uint8_t controller_ID, uint8_t event_type, void *val)
| This function handles the callback. More...
static uint8_t | usb_hid_app_param_callback (uint8_t request, uint16_t value, uint16_t wIndex, uint8_t **data, USB_PACKET_SIZE *size)
| This function handles callbacks for USB HID Class request. More...
static status_t | usb_hid_full_init (const peripheral_descriptor_t *self, serial_byte_receive_func_t function)
static void | usb_hid_full_shutdown (const peripheral_descriptor_t *self)
static void | usb_set_clock_gate (uint32_t instance, PeripheralClockSetting set)
static void | usb_hid_app_callback (uint8_t event_type, void *val, void *arg)
| This function handles the callback. More...
static uint8_t | usb_hid_app_param_callback (uint8_t request, uint16_t value, uint8_t **data, USB_PACKET_SIZE *size, void *arg)
uint32_t | usb_get_instance_via_ipsr (void)

## Variables

static bool | s_dHidMscActivity [2] = { false }
const peripheral_control_interface_t | g_usbHidControlInterface
| Control interface for the USB HID peripheral driver. More...
const peripheral_packet_interface_t | g_usbHidPacketInterface
| Packet interface for the USB HID peripheral driver. More...
static usb_device_composite_struct_t | g_device_composite
const peripheral_control_interface_t | g_usbHidControlInterface
| Control interface for the USB HID peripheral driver. More...
const peripheral_packet_interface_t | g_usbHidPacketInterface
| Packet interface for the USB HID peripheral driver. More...
static const IRQn_Type | usb_irq_ids [USB_INSTANCE_COUNT]
static usb_hid_packetizer_info_t | s_hidInfo
| Current state of the USB HID packetizer.
bool | isEnumerated
| Whether the device has enumerated and is configured.
bool | didReceiveFirstReport
| Whether the first report has been received.
bool | didReceiveDataPhaseAbort
| Whether we received a data phase abort request.
bool | isReceiveDataRequestRequired
| Whether an interrupt out pipe receive data request is required.
uint8_t | appRequestParams [kAppRequestParamCount]
| Storage for request parameter values.
sync_object_t | receiveSync
| Sync object used for reading packets.
sync_object_t | sendSync
| Sync object used for sending packets.
uint32_t | reportSize
bl_hid_report_t | report
| the report plus the header, as the host can send up to the max report size bytes. More...
hid_handle_t | app_handle
usb_desc_request_notify_struct_t | g_desc_callback
const peripheral_control_interface_t | g_usbHidControlInterface
| Control interface for the USB HID peripheral driver. More...
const peripheral_packet_interface_t | g_usbHidPacketInterface
| Packet interface for the USB HID peripheral driver. More...
static usb_hid_packetizer_info_t | s_hidInfo [USB_INSTANCE_COUNT+USBHS_INSTANCE_COUNT]
| Current state of the USB HID packetizer.

## USB_Class_Periodic_Task

The function calls for periodic tasks

Parameters

  None |

Returns
  None

Called to check for any pending requests

static void | usb_hid_Periodic_Task (const peripheral_descriptor_t *self)

## Usage Information

USB HID peripheral interface.

## Data Structure Documentation

struct usb_hid_packetizer_info_t

State information for the USB HID packetizer.

Collaboration diagram for usb_hid_packetizer_info_t:
[legend]

Data Fields
hid_handle_t | app_handle |
uint8_t | appRequestParams[kAppRequestParamCount] | Storage for request parameter values.
bool | didReceiveDataPhaseAbort | Whether we received a data phase abort request.
bool | didReceiveFirstReport | Whether the first report has been received.
bool | isEnumerated | Whether the device has enumerated and is configured.
bool | isReceiveDataRequestRequired | Whether an interrupt out pipe receive data request is required.
sync_object_t | receiveSync | Sync object used for reading packets.
bl_hid_report_t | report | the report plus the header, as the host can send up to the max report size bytes. Buffer used to hold HID reports for sending and receiving.
uint32_t | reportSize | The size in bytes of a received report. May be greater than the packet contained within
sync_object_t | sendSync | Sync object used for sending packets.

## Function Documentation

usb_status_t usb_device_msc_callback | ( | class_handle_t | handle,
|  | uint32_t | event,
|  | void * | param
| ) |  |

device msc callback function.

This function handle the disk class specified event.

Parameters

  handle | The USB class handle.
  event | The USB device event type.
  param | The parameter of the class specific event.

Returns
  kStatus_USB_Success or error.

< Send data completed

< Data received

< Host write data

< Host read data

void usb_hid_app_callback | ( | uint8_t | controller_ID,
|  | uint8_t | event_type,
|  | void * | val
| ) |  |

static

This function handles the callback.

This function is called from the class layer whenever reset occurs or enum is complete. after the enum is complete this function sets a variable so that the application can start

Parameters

  controller_ID | Controller ID
  event_type | value of the event
  val | gives the configuration value

void usb_hid_app_callback | ( | uint8_t | event_type,
|  | void * | val,
|  | void * | arg
| ) |  |

static

This function handles the callback.

This function is called from the class layer whenever reset occurs or enum is complete. after the enum is complete this function sets a variable so that the application can start

Parameters

  event_type | value of the event
  val | gives the configuration value
  arg |

uint8_t usb_hid_app_param_callback | ( | uint8_t | request,
|  | uint16_t | value,
|  | uint16_t | wIndex,
|  | uint8_t ** | data,
|  | USB_PACKET_SIZE * | size
| ) |  |

static

This function handles callbacks for USB HID Class request.

This function is called whenever a HID class request is received. This function handles these class requests

Parameters

  request | request type
  value | give report type and id
  data | pointer to the data
  size | size of the transfer

Returns
  status USB_OK : if successful else return error

void usb_msc_pump | ( | const peripheral_descriptor_t * | self | ) |

static

Run the sbloader state machine.

This function is called repeatedly by the main application loop. We use it to run the sbloader state machine from non-interrupt context.

## Variable Documentation

hid_handle_t app_handle

uint8_t appRequestParams

Storage for request parameter values.

bool didReceiveDataPhaseAbort

Whether we received a data phase abort request.

bool didReceiveFirstReport

Whether the first report has been received.

const peripheral_control_interface_t g_usbHidControlInterface

Initial value:
= {.pollForActivity = usb_hid_poll_for_activity,
.init = usb_device_full_init,
.shutdown = usb_device_full_shutdown,
.pump = usb_msc_pump }
usb_msc_pump
static void usb_msc_pump(const peripheral_descriptor_t *self)
Run the sbloader state machine.
Definition: usb_hid_msc_peripheral_interface.c:421

Control interface for the USB HID peripheral driver.

const peripheral_control_interface_t g_usbHidControlInterface

Initial value:
= {.pollForActivity = usb_hid_poll_for_activity,
.init = usb_hid_full_init,
.shutdown = usb_hid_full_shutdown,
.pump = USB_Class_HID_Periodic_Task }

Control interface for the USB HID peripheral driver.

const peripheral_control_interface_t g_usbHidControlInterface

Initial value:
= {.pollForActivity = usb_hid_poll_for_activity,
.init = usb_hid_full_init,
.shutdown = usb_hid_full_shutdown,
.pump = usb_hid_Periodic_Task }

Control interface for the USB HID peripheral driver.

const peripheral_packet_interface_t g_usbHidPacketInterface

Initial value:
= {.init = usb_hid_packet_init,
.readPacket = usb_hid_packet_read,
.writePacket = usb_hid_packet_write,
.abortDataPhase = usb_hid_packet_abort_data_phase,
.finalize = usb_hid_packet_finalize,
.getMaxPacketSize = usb_hid_packet_get_max_packet_size,
.byteReceivedCallback = 0 }

Packet interface for the USB HID peripheral driver.

const peripheral_packet_interface_t g_usbHidPacketInterface

Initial value:
= {.init = usb_hid_packet_init,
.readPacket = usb_hid_packet_read,
.writePacket = usb_hid_packet_write,
.abortDataPhase = usb_hid_packet_abort_data_phase,
.finalize = usb_hid_packet_finalize,
.getMaxPacketSize = usb_hid_packet_get_max_packet_size,
.byteReceivedCallback = 0 }

Packet interface for the USB HID peripheral driver.

const peripheral_packet_interface_t g_usbHidPacketInterface

Initial value:
= {.init = usb_hid_packet_init,
.readPacket = usb_hid_packet_read,
.writePacket = usb_hid_packet_write,
.abortDataPhase = usb_hid_packet_abort_data_phase,
.finalize = usb_hid_packet_finalize,
.getMaxPacketSize = usb_hid_packet_get_max_packet_size,
.byteReceivedCallback = 0 }

Packet interface for the USB HID peripheral driver.

bool isEnumerated

Whether the device has enumerated and is configured.

bool isReceiveDataRequestRequired

Whether an interrupt out pipe receive data request is required.

sync_object_t receiveSync

Sync object used for reading packets.

bl_hid_report_t report

the report plus the header, as the host can send up to the max report size bytes.

Buffer used to hold HID reports for sending and receiving.

uint32_t reportSize

The size in bytes of a received report. May be greater than the packet contained within

sync_object_t sendSync

Sync object used for sending packets.

const IRQn_Type usb_irq_ids[USB_INSTANCE_COUNT]

static

Initial value:
= {
#if BL_HAS_MULTI_CORE
NVIC0_USB0_IRQn,
#else
USB0_IRQn,
#endif
}