Callbacks for implementing USB HID class. More...
#include "config.h"
#include "pic_usb.h"
#include "pic_usb_buffer_mgt.h"
#include "pic_serial.h"
#include "usb_hid_class.h"
#include "memory.h"
Go to the source code of this file.
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. |
Definition in file usb_hid_class.c.
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
Definition at line 54 of file usb_hid_class.c.
Referenced by usb_handle_transaction().
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
Definition at line 57 of file usb_hid_class.c.
Referenced by usb_handle_transaction().
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
Definition at line 60 of file usb_hid_class.c.
References setup_data_packet::bRequest, req_GET_IDLE, req_GET_PROTOCOL, req_GET_REPORT, req_SET_IDLE, req_SET_PROTOCOL, req_SET_REPORT, serial_print_int(), serial_print_str(), and usb_stall_ep0().
Referenced by usb_handle_transaction().