Exemplo n.º 1
0
/**
 * @brief   Default data received callback.
 * @details The application must use this function as callback for the OUT
 *          data endpoint.
 *
 * @param[in] usbp      pointer to the @p USBDriver object
 * @param[in] ep        OUT endpoint number
 */
void sduDataReceived(USBDriver *usbp, usbep_t ep) {
  uint8_t *buf;
  SerialUSBDriver *sdup = usbp->out_params[ep - 1U];

  if (sdup == NULL) {
    return;
  }

  osalSysLockFromISR();

  /* Signaling that data is available in the input queue.*/
  chnAddFlagsI(sdup, CHN_INPUT_AVAILABLE);

  /* Posting the filled buffer in the queue.*/
  ibqPostFullBufferI(&sdup->ibqueue,
                     usbGetReceiveTransactionSizeX(sdup->config->usbp,
                                                   sdup->config->bulk_out));

  /* The endpoint cannot be busy, we are in the context of the callback,
     so a packet is in the buffer for sure. Trying to get a free buffer
     for the next transaction.*/
  buf = ibqGetEmptyBufferI(&sdup->ibqueue);
  if (buf != NULL) {
    /* Buffer found, starting a new transaction.*/
    usbStartReceiveI(sdup->config->usbp, sdup->config->bulk_out,
                     buf, SERIAL_USB_BUFFERS_SIZE);
  }
  osalSysUnlockFromISR();
}
Exemplo n.º 2
0
/**
 * @brief   USB device configured handler.
 *
 * @param[in] sdup      pointer to a @p SerialUSBDriver object
 *
 * @iclass
 */
void sduConfigureHookI(SerialUSBDriver *sdup) {
  uint8_t *buf;

  ibqResetI(&sdup->ibqueue);
  obqResetI(&sdup->obqueue);
  chnAddFlagsI(sdup, CHN_CONNECTED);

  /* Starts the first OUT transaction immediately.*/
  buf = ibqGetEmptyBufferI(&sdup->ibqueue);

  osalDbgAssert(buf != NULL, "no free buffer");

  usbStartReceiveI(sdup->config->usbp, sdup->config->bulk_out,
                   buf, SERIAL_USB_BUFFERS_SIZE);
}
Exemplo n.º 3
0
/**
 * @brief   USB device configured handler.
 *
 * @param[in] uhdp      pointer to a @p USBHIDDriver object
 *
 * @iclass
 */
void hidConfigureHookI(USBHIDDriver *uhdp) {
  uint8_t *buf;

  ibqResetI(&uhdp->ibqueue);
  obqResetI(&uhdp->obqueue);
  chnAddFlagsI(uhdp, CHN_CONNECTED);

  /* Starts the first OUT transaction immediately.*/
  buf = ibqGetEmptyBufferI(&uhdp->ibqueue);

  osalDbgAssert(buf != NULL, "no free buffer");

  usbStartReceiveI(uhdp->config->usbp, uhdp->config->int_out,
                   buf, USB_HID_BUFFERS_SIZE);
}
Exemplo n.º 4
0
/**
 * @brief   Notification of empty buffer released into the input buffers queue.
 *
 * @param[in] bqp       the buffers queue pointer.
 */
static void ibnotify(io_buffers_queue_t *bqp) {
  SerialUSBDriver *sdup = bqGetLinkX(bqp);

  /* If the USB driver is not in the appropriate state then transactions
     must not be started.*/
  if ((usbGetDriverStateI(sdup->config->usbp) != USB_ACTIVE) ||
      (sdup->state != SDU_READY)) {
    return;
  }

  /* Checking if there is already a transaction ongoing on the endpoint.*/
  if (!usbGetReceiveStatusI(sdup->config->usbp, sdup->config->bulk_out)) {
    /* Trying to get a free buffer.*/
    uint8_t *buf = ibqGetEmptyBufferI(&sdup->ibqueue);
    if (buf != NULL) {
      /* Buffer found, starting a new transaction.*/
      usbStartReceiveI(sdup->config->usbp, sdup->config->bulk_out,
                       buf, SERIAL_USB_BUFFERS_SIZE);
    }
  }
}