Callbacks for implementing USB HID class. More...
Functions | |
void | usb_handle_class_ctrl_read_callback () |
Callback routine for a class control read. | |
void | usb_handle_class_ctrl_write_callback (uns8 *data, uns16 count) |
Callback routine for a class control write. | |
void | usb_handle_class_request_callback (setup_data_packet sdp) |
Callback routine for a control transfer request that is placed on the class. |
void usb_handle_class_ctrl_read_callback | ( | ) |
When a control transfer is taking place, this routine is called to indicate that a control read for the class has taken place. Since everything in USB land is all about what has just happened, this callback will occur after data has been transferred to the host. If you wish to send more data to the host, use usb_send_data(), or if your control read has sent all the data required, you will need to indicate that the state has changed by setting the control_mode variable to cm_CTRL_READ_AWAITING_STATUS. This will indicate to the stack that it should now wait for the status packet before completing the control transfer.
To allow this callback to trigger, ensure you define USB_CALLBACK_ON_CLASS_CTRL in your config.h
void usb_handle_class_ctrl_write_callback | ( | uns8 * | data, | |
uns16 | count | |||
) |
When a control transfer is taking place, this routine is called to indicate that a control write for the class has taken place. Since everything in USB land is all about what has just happened, this callback will occur after data has been received by the device. If you expect more data from the host, it will arrive in due course since endpoint 0 will be primed for more data automatically. If you have received all the data from the host, you will need to set the control_mode state variable to cm_CTRL_WRITE_SENDING_STATUS and then actually send the status by calling usb_send_status_ack(). Once the status has actually been sent, the control_mode state will automatically change to cm_IDLE to indicate the transfer has completed.
To allow this callback to trigger, ensure you define USB_CALLBACK_ON_CLASS_CTRL in your config.h
void usb_handle_class_request_callback | ( | setup_data_packet | sdp | ) |
After receiving a setup packet, where the request is placed on the class, this routine is called. In usb_handle_class_request_callback, you can set up ready for the data stage of the control transfer. The direction of the data stage can be determined by examining test_bit(sdp.bRequest, DATA_STAGE_DIR) although generally it appears to be obvious from the request. The request is stored in sdp.bRequest.
Typically, if it is a control read transfer (that is, it is a request by the host for data), then you will need to move the control_mode state variable to cm_CTRL_READ_DATA_STAGE_CLASS and send data using usb_send_data(). If you only intend to send one packet, you can immediately move the control_mode state variable to cm_CTRL_READ_AWAITING_STATUS to indicate you are waiting for the status to arrive. You could wait for the usb_handle_class_ctrl_read callback and do it (move to cm_CTROL_READ_AWAITING_STATUS) but the PicPack USB stack can handle the control read event for you if you've already switched states.
If it is a control write transfer (that is, it is a request by the host to send data to the device), then you will need to move the control_mode state variable to cm_CTRL_WRITE_DATA_STAGE_CLASS. Then, the usb_handle_class_ctrl_write will be fired when data is received by the device in the data stage.
To allow this callback to trigger, ensure you define USB_CALLBACK_ON_CLASS_CTRL in your config.h
00060 { 00061 #ifdef USB_DEBUG 00062 serial_print_str("Class request: "); 00063 serial_print_int(sdp.bRequest); 00064 #endif 00065 00066 switch(sdp.bRequest) { 00067 case req_GET_REPORT: 00068 #ifdef USB_DEBUG 00069 serial_print_str(" Set_idle "); 00070 #endif 00071 break; 00072 case req_GET_IDLE: 00073 break; 00074 case req_GET_PROTOCOL: 00075 break; 00076 case req_SET_REPORT: 00077 #ifdef USB_DEBUG 00078 serial_print_str(" Set_report "); 00079 #endif 00080 break; 00081 case req_SET_IDLE: 00082 #ifdef USB_DEBUG 00083 serial_print_str(" Set_idle "); 00084 #endif 00085 // we don't support whatever they want 00086 usb_stall_ep0(); 00087 break; 00088 case req_SET_PROTOCOL: 00089 break; 00090 00091 } 00092 00093 }