stm32/usb: Change HID report funcs to take HID state, not usbdev state.
This commit is contained in:
parent
91bca340ec
commit
2e565cc0d4
|
@ -628,7 +628,7 @@ STATIC mp_obj_t pyb_usb_hid_send(mp_obj_t self_in, mp_obj_t report_in) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// send the data
|
// send the data
|
||||||
if (USBD_OK == USBD_HID_SendReport(&self->usb_dev->usbd_cdc_msc_hid_state, bufinfo.buf, bufinfo.len)) {
|
if (USBD_OK == USBD_HID_SendReport(&self->usb_dev->usbd_hid_itf.base, bufinfo.buf, bufinfo.len)) {
|
||||||
return mp_obj_new_int(bufinfo.len);
|
return mp_obj_new_int(bufinfo.len);
|
||||||
} else {
|
} else {
|
||||||
return mp_obj_new_int(0);
|
return mp_obj_new_int(0);
|
||||||
|
@ -660,7 +660,7 @@ STATIC mp_uint_t pyb_usb_hid_ioctl(mp_obj_t self_in, mp_uint_t request, mp_uint_
|
||||||
if ((flags & MP_STREAM_POLL_RD) && usbd_hid_rx_num(&self->usb_dev->usbd_hid_itf) > 0) {
|
if ((flags & MP_STREAM_POLL_RD) && usbd_hid_rx_num(&self->usb_dev->usbd_hid_itf) > 0) {
|
||||||
ret |= MP_STREAM_POLL_RD;
|
ret |= MP_STREAM_POLL_RD;
|
||||||
}
|
}
|
||||||
if ((flags & MP_STREAM_POLL_WR) && USBD_HID_CanSendReport(&self->usb_dev->usbd_cdc_msc_hid_state)) {
|
if ((flags & MP_STREAM_POLL_WR) && USBD_HID_CanSendReport(&self->usb_dev->usbd_hid_itf.base)) {
|
||||||
ret |= MP_STREAM_POLL_WR;
|
ret |= MP_STREAM_POLL_WR;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -62,9 +62,9 @@ int8_t usbd_hid_receive(usbd_hid_state_t *hid_in, size_t len) {
|
||||||
hid->current_write_buffer = !hid->current_write_buffer;
|
hid->current_write_buffer = !hid->current_write_buffer;
|
||||||
hid->last_read_len = len;
|
hid->last_read_len = len;
|
||||||
// initiate next USB packet transfer, to append to existing data in buffer
|
// initiate next USB packet transfer, to append to existing data in buffer
|
||||||
USBD_HID_ReceivePacket(hid->base.usbd, hid->buffer[hid->current_write_buffer]);
|
USBD_HID_ReceivePacket(&hid->base, hid->buffer[hid->current_write_buffer]);
|
||||||
// Set NAK to indicate we need to process read buffer
|
// Set NAK to indicate we need to process read buffer
|
||||||
USBD_HID_SetNAK(hid->base.usbd);
|
USBD_HID_SetNAK(&hid->base);
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ int usbd_hid_rx(usbd_hid_itf_t *hid, size_t len, uint8_t *buf, uint32_t timeout)
|
||||||
hid->current_read_buffer = !hid->current_read_buffer;
|
hid->current_read_buffer = !hid->current_read_buffer;
|
||||||
|
|
||||||
// Clear NAK to indicate we are ready to read more data
|
// Clear NAK to indicate we are ready to read more data
|
||||||
USBD_HID_ClearNAK(hid->base.usbd);
|
USBD_HID_ClearNAK(&hid->base);
|
||||||
|
|
||||||
// Success, return number of bytes read
|
// Success, return number of bytes read
|
||||||
return read_len;
|
return read_len;
|
||||||
|
|
|
@ -169,11 +169,11 @@ static inline void USBD_MSC_RegisterStorage(usbd_cdc_msc_hid_state_t *usbd, USBD
|
||||||
usbd->MSC_BOT_ClassData.bdev_ops = fops;
|
usbd->MSC_BOT_ClassData.bdev_ops = fops;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t USBD_HID_ReceivePacket(usbd_cdc_msc_hid_state_t *usbd, uint8_t *buf);
|
uint8_t USBD_HID_ReceivePacket(usbd_hid_state_t *usbd, uint8_t *buf);
|
||||||
int USBD_HID_CanSendReport(usbd_cdc_msc_hid_state_t *usbd);
|
int USBD_HID_CanSendReport(usbd_hid_state_t *usbd);
|
||||||
uint8_t USBD_HID_SendReport(usbd_cdc_msc_hid_state_t *usbd, uint8_t *report, uint16_t len);
|
uint8_t USBD_HID_SendReport(usbd_hid_state_t *usbd, uint8_t *report, uint16_t len);
|
||||||
uint8_t USBD_HID_SetNAK(usbd_cdc_msc_hid_state_t *usbd);
|
uint8_t USBD_HID_SetNAK(usbd_hid_state_t *usbd);
|
||||||
uint8_t USBD_HID_ClearNAK(usbd_cdc_msc_hid_state_t *usbd);
|
uint8_t USBD_HID_ClearNAK(usbd_hid_state_t *usbd);
|
||||||
|
|
||||||
// These are provided externally to implement the CDC interface
|
// These are provided externally to implement the CDC interface
|
||||||
uint8_t *usbd_cdc_init(usbd_cdc_state_t *cdc);
|
uint8_t *usbd_cdc_init(usbd_cdc_state_t *cdc);
|
||||||
|
|
|
@ -1141,51 +1141,51 @@ uint8_t USBD_CDC_ReceivePacket(usbd_cdc_state_t *cdc, uint8_t *buf) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare OUT endpoint for reception
|
// prepare OUT endpoint for reception
|
||||||
uint8_t USBD_HID_ReceivePacket(usbd_cdc_msc_hid_state_t *usbd, uint8_t *buf) {
|
uint8_t USBD_HID_ReceivePacket(usbd_hid_state_t *hid, uint8_t *buf) {
|
||||||
// Suspend or Resume USB Out process
|
// Suspend or Resume USB Out process
|
||||||
|
|
||||||
#if !USBD_SUPPORT_HS_MODE
|
#if !USBD_SUPPORT_HS_MODE
|
||||||
if (usbd->pdev->dev_speed == USBD_SPEED_HIGH) {
|
if (hid->usbd->pdev->dev_speed == USBD_SPEED_HIGH) {
|
||||||
return USBD_FAIL;
|
return USBD_FAIL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Prepare Out endpoint to receive next packet
|
// Prepare Out endpoint to receive next packet
|
||||||
uint16_t mps_out =
|
uint16_t mps_out =
|
||||||
usbd->hid->desc[HID_DESC_OFFSET_MAX_PACKET_OUT_LO]
|
hid->desc[HID_DESC_OFFSET_MAX_PACKET_OUT_LO]
|
||||||
| (usbd->hid->desc[HID_DESC_OFFSET_MAX_PACKET_OUT_HI] << 8);
|
| (hid->desc[HID_DESC_OFFSET_MAX_PACKET_OUT_HI] << 8);
|
||||||
USBD_LL_PrepareReceive(usbd->pdev, usbd->hid->out_ep, buf, mps_out);
|
USBD_LL_PrepareReceive(hid->usbd->pdev, hid->out_ep, buf, mps_out);
|
||||||
|
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int USBD_HID_CanSendReport(usbd_cdc_msc_hid_state_t *usbd) {
|
int USBD_HID_CanSendReport(usbd_hid_state_t *hid) {
|
||||||
return usbd->pdev->dev_state == USBD_STATE_CONFIGURED && usbd->hid->state == HID_IDLE;
|
return hid->usbd->pdev->dev_state == USBD_STATE_CONFIGURED && hid->state == HID_IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t USBD_HID_SendReport(usbd_cdc_msc_hid_state_t *usbd, uint8_t *report, uint16_t len) {
|
uint8_t USBD_HID_SendReport(usbd_hid_state_t *hid, uint8_t *report, uint16_t len) {
|
||||||
if (usbd->pdev->dev_state == USBD_STATE_CONFIGURED) {
|
if (hid->usbd->pdev->dev_state == USBD_STATE_CONFIGURED) {
|
||||||
if (usbd->hid->state == HID_IDLE) {
|
if (hid->state == HID_IDLE) {
|
||||||
usbd->hid->state = HID_BUSY;
|
hid->state = HID_BUSY;
|
||||||
USBD_LL_Transmit(usbd->pdev, usbd->hid->in_ep, report, len);
|
USBD_LL_Transmit(hid->usbd->pdev, hid->in_ep, report, len);
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return USBD_FAIL;
|
return USBD_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t USBD_HID_SetNAK(usbd_cdc_msc_hid_state_t *usbd) {
|
uint8_t USBD_HID_SetNAK(usbd_hid_state_t *hid) {
|
||||||
// get USBx object from pdev (needed for USBx_OUTEP macro below)
|
// get USBx object from pdev (needed for USBx_OUTEP macro below)
|
||||||
PCD_HandleTypeDef *hpcd = usbd->pdev->pData;
|
PCD_HandleTypeDef *hpcd = hid->usbd->pdev->pData;
|
||||||
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
|
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
|
||||||
// set NAK on HID OUT endpoint
|
// set NAK on HID OUT endpoint
|
||||||
USBx_OUTEP(HID_OUT_EP_WITH_CDC)->DOEPCTL |= USB_OTG_DOEPCTL_SNAK;
|
USBx_OUTEP(HID_OUT_EP_WITH_CDC)->DOEPCTL |= USB_OTG_DOEPCTL_SNAK;
|
||||||
return USBD_OK;
|
return USBD_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t USBD_HID_ClearNAK(usbd_cdc_msc_hid_state_t *usbd) {
|
uint8_t USBD_HID_ClearNAK(usbd_hid_state_t *hid) {
|
||||||
// get USBx object from pdev (needed for USBx_OUTEP macro below)
|
// get USBx object from pdev (needed for USBx_OUTEP macro below)
|
||||||
PCD_HandleTypeDef *hpcd = usbd->pdev->pData;
|
PCD_HandleTypeDef *hpcd = hid->usbd->pdev->pData;
|
||||||
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
|
USB_OTG_GlobalTypeDef *USBx = hpcd->Instance;
|
||||||
// clear NAK on HID OUT endpoint
|
// clear NAK on HID OUT endpoint
|
||||||
USBx_OUTEP(HID_OUT_EP_WITH_CDC)->DOEPCTL |= USB_OTG_DOEPCTL_CNAK;
|
USBx_OUTEP(HID_OUT_EP_WITH_CDC)->DOEPCTL |= USB_OTG_DOEPCTL_CNAK;
|
||||||
|
|
Loading…
Reference in New Issue