This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

device_req _cb callback of NRF24LU1+

Codes:

hal_usb_dev_req_resp_t device_req_cb(hal_usb_device_req* req, uint8_t** data_ptr, uint8_t* size) large reentrant
{
  hal_usb_dev_req_resp_t retval;

  if( hal_usb_hid_device_req_proc(req, data_ptr, size, &retval) == true ) 
  {
    // The request was processed with the result stored in the retval variable
    return retval;
  }
  else
  {
     The request was *not* processed by the HID subsystem
    return STALL;   
  }
}
uint8_t ep_1_in_cb(uint8_t *adr_ptr, uint8_t* size) large reentrant
{  
  app_pending_usb_write = false;
  return 0x60; // NAK
  adr_ptr = adr_ptr;
  size = size;
}

I just cannot uderstand the codes corretly.I cannot find where he parameters of the callback fucntions have been initialized. And that ,is there any difference between the "adr_ptr" and the "adr_ptr".Could you give me some help?

  • This is one of the function pointers provided in the hal_usb_init function:

    hal_usb_init(true, device_req_cb, reset_cb, resume_cb, suspend_cb);
    

    This gets stored, and handled and set by the hal_usb library:

    g_hal_usb.device_req = device_req;
    

    And then called from function hal_usb.c::usb_process_dev_req_cb_response in various situations, as to comply with the USB protocol specification.

    The input parameters to function pointer device_req_cb are the USB req, with lower level USB PHY parameters, the data, and size of the data.

    The endpoint callback is handled similarly, via this:

     hal_usb_endpoint_config(0x81, 32, ep_1_in_cb);
    

    The callback is stored in hal_usb.c::i_endpoint_in_isr[0] (for this case, array index 1 for 0x82 ep_2_in_cb etc), then called when data/commands are available on this specific endpoint.

    This line is purely to avoid the compiler giving an unused variable warning:

    adr_ptr = adr_ptr;
    size = size;
    

    Cheers, Håkon

Related