Ejemplo n.º 1
0
/**
 * @brief Internal SETUP standard IN request handler.
 *
 * @param[in] p_inst        Generic class instance.
 * @param[in] p_setup_ev    Setup event.
 *
 * @return Standard error code.
 * @retval NRF_SUCCESS              Request handled correctly.
 * @retval NRF_ERROR_NOT_SUPPORTED  Request is not supported.
 */
static ret_code_t setup_req_std_in(app_usbd_class_inst_t const * p_inst,
                                   app_usbd_setup_evt_t const  * p_setup_ev)
{
    /* Only Get Descriptor standard IN request is supported by Audio class */
    if ((app_usbd_setup_req_rec(p_setup_ev->setup.bmRequestType) == APP_USBD_SETUP_REQREC_INTERFACE)
        &&
        (p_setup_ev->setup.bRequest == APP_USBD_SETUP_STDREQ_GET_DESCRIPTOR))
    {
        size_t dsc_len = 0;
        size_t max_size;

        uint8_t * p_trans_buff = app_usbd_core_setup_transfer_buff_get(&max_size);

        /* Try to find descriptor in class internals*/
        ret_code_t ret = app_usbd_class_descriptor_find(
            p_inst,
            p_setup_ev->setup.wValue.hb,
            p_setup_ev->setup.wValue.lb,
            p_trans_buff,
            &dsc_len);

        if (ret != NRF_ERROR_NOT_FOUND)
        {
            ASSERT(dsc_len < NRF_DRV_USBD_EPSIZE);
            return app_usbd_core_setup_rsp(&(p_setup_ev->setup), p_trans_buff, dsc_len);
        }
    }

    return NRF_ERROR_NOT_SUPPORTED;
}
Ejemplo n.º 2
0
/**
 * @brief Internal SETUP standard IN request handler.
 *
 * @param[in] p_inst        Generic class instance.
 * @param[in] p_setup_ev    Setup event.
 *
 * @return Standard error code.
 */
static ret_code_t setup_req_std_in(app_usbd_class_inst_t const * p_inst,
                                   app_usbd_setup_evt_t const *  p_setup_ev)
{
    switch (p_setup_ev->setup.bmRequest)
    {
        case APP_USBD_SETUP_STDREQ_GET_DESCRIPTOR:
        {
            size_t dsc_len = 0;

            /* Try to find descriptor in class internals*/
            void const * p_dsc = app_usbd_class_descriptor_find(p_inst,
                                                                p_setup_ev->setup.wValue.hb,
                                                                p_setup_ev->setup.wValue.lb,
                                                                &dsc_len);
            if (p_dsc != NULL)
            {
                return app_usbd_core_setup_rsp(&(p_setup_ev->setup), p_dsc, dsc_len);
            }

            break;
        }
        default:
            break;
    }

    return NRF_ERROR_NOT_SUPPORTED;
}
Ejemplo n.º 3
0
/**
 * @brief Internal SETUP standard IN request handler.
 *
 * @param[in] p_inst        Generic class instance.
 * @param[in] p_setup_ev    Setup event.
 *
 * @return Standard error code.
 */
static ret_code_t setup_req_std_in(app_usbd_class_inst_t const * p_inst,
                                   app_usbd_setup_evt_t const *  p_setup_ev)
{
    switch (p_setup_ev->setup.bmRequest)
    {
        case APP_USBD_SETUP_STDREQ_GET_DESCRIPTOR:
        {
            size_t dsc_len = 0;

            /* Try to find descriptor in class internals*/
            void const * p_dsc = app_usbd_class_descriptor_find(p_inst,
                                                                p_setup_ev->setup.wValue.hb,
                                                                p_setup_ev->setup.wValue.lb,
                                                                &dsc_len);
            if (p_dsc != NULL)
            {
                return app_usbd_core_setup_rsp(&(p_setup_ev->setup), p_dsc, dsc_len);
            }

            break;
        }
        case APP_USBD_SETUP_STDREQ_GET_INTERFACE:
        {

            size_t tx_maxsize;
            uint8_t * p_tx_buff = app_usbd_core_setup_transfer_buff_get(&tx_maxsize);

            p_tx_buff[0] = 0;
            return app_usbd_core_setup_rsp(&p_setup_ev->setup,
                                           p_tx_buff,
                                           sizeof(uint8_t));
        }
        default:
            break;
    }

    return NRF_ERROR_NOT_SUPPORTED;
}