stmhal: Fix USB HID receive not receiving the first packet.

This commit is contained in:
Pavol Rusnak 2017-01-16 16:43:09 +01:00 committed by Damien George
parent c5310ee5b5
commit 89f2b62016
4 changed files with 26 additions and 5 deletions

View File

@ -607,7 +607,11 @@ STATIC mp_obj_t pyb_usb_hid_send(mp_obj_t self_in, mp_obj_t report_in) {
}
// send the data
USBD_HID_SendReport(&hUSBDDevice, bufinfo.buf, bufinfo.len);
if (USBD_OK == USBD_HID_SendReport(&hUSBDDevice, bufinfo.buf, bufinfo.len)) {
return mp_obj_new_int(bufinfo.len);
} else {
return mp_obj_new_int(0);
}
#endif
return mp_const_none;

View File

@ -45,21 +45,35 @@
/* Private variables ---------------------------------------------------------*/
static __IO uint8_t dev_is_connected = 0; // indicates if we are connected
static uint8_t buffer[2][HID_DATA_FS_MAX_PACKET_SIZE]; // pair of buffers to read individual packets into
static int8_t current_read_buffer = 0; // which buffer to read from
static uint32_t last_read_len; // length of last read
static uint32_t last_read_len = 0; // length of last read
static int8_t current_write_buffer = 0; // which buffer to write to
/* Private function prototypes -----------------------------------------------*/
static int8_t HID_Itf_Init (void);
static int8_t HID_Itf_Receive (uint8_t* pbuf, uint32_t Len);
const USBD_HID_ItfTypeDef USBD_HID_fops = {
HID_Itf_Init,
HID_Itf_Receive
};
/**
* @brief HID_Itf_Init
* Initializes the HID media low layer
* @param None
* @retval Result of the opeartion: USBD_OK if all operations are OK else USBD_FAIL
*/
static int8_t HID_Itf_Init(void)
{
current_read_buffer = 0;
last_read_len = 0;
current_write_buffer = 0;
USBD_HID_SetRxBuffer(&hUSBDDevice, buffer[current_write_buffer]);
return USBD_OK;
}
/**
* @brief HID_Itf_Receive
* Data received over USB OUT endpoint is processed here.

View File

@ -48,6 +48,7 @@ typedef struct {
} USBD_CDC_HandleTypeDef;
typedef struct _USBD_HID_Itf {
int8_t (* Init) (void);
int8_t (* Receive)(uint8_t *, uint32_t);
} USBD_HID_ItfTypeDef;

View File

@ -724,6 +724,8 @@ static uint8_t USBD_CDC_MSC_HID_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx) {
USBD_EP_TYPE_INTR,
mps_out);
HID_fops->Init();
// Prepare Out endpoint to receive next packet
USBD_LL_PrepareReceive(pdev, hid_out_ep, HID_ClassData.RxBuffer, mps_out);