8 Replies Latest reply on Sep 30, 2020 2:26 PM by JoBr_1593366

    Should I use custom code or callback in USBFS?

    JoBr_1593366

      For example, in USBFS_DispatchAUDIOClassRqst there's a custom code section:

      /* `#START AUDIO_READ_REQUESTS` Place other request handler here */
      
      /* `#END` */
      
      
      

       

      and then an optional callback:

       

      #ifdef USBFS_DISPATCH_AUDIO_CLASS_AUDIO_READ_REQUESTS_CALLBACK    
          USBFS_DispatchAUDIOClass_AUDIO_READ_REQUESTS_Callback();
      #endif /* (USBFS_DISPATCH_AUDIO_CLASS_AUDIO_READ_REQUESTS_CALLBACK) */
      

       

      These are both for implementing custom audio class request handlers, right?  Why choose one solution over the other? 

       

      Also, why are there no options to modify the code for USBFS_GET_MIN, USBFS_GET_MAX, USBFS_GET_RES, etc?  To make custom code for these we either need to edit the USB component (which makes it harder to upgrade) or replace the entire class handler using USBFS_EXTERN_CLS?  It would be good if every request handler in the component could be replaced/modified in user code.

        • 1. Re: Should I use custom code or callback in USBFS?
          EktaN_26

          Hello JoBr_1593366

           

          Yes, both the callback functions as well as the custom code section can be used for adding custom code in case of USB. This depends upon the application that you want to create. In case you want to process something before entering the ISR for the interrupt triggered you can use Entry callback, in case you want to do some processing after the ISR is executed use the exit callback function and if you want to execute some task within the ISR use the custom code section.

           

          It is also possible to use both the options at the same time.

           

          Regarding the USBFS_GET_MIN, USBFS_GET_MAX, USBFS_GET_RES macros can you please let me know where are these macros used in your project?

           

          Best Regards

          Ekta

          • 2. Re: Should I use custom code or callback in USBFS?
            JoBr_1593366

            Regarding the USBFS_GET_MIN, USBFS_GET_MAX, USBFS_GET_RES macros can you please let me know where are these macros used in your project?

            They are located in USBFS_audio.c but are not customizable.

             

            Do you mean what do we use them for?  They need to be customized if you want to handle multiple Feature Units, such as having different ranges for input and output controls, implementing Mixer Units, etc.

            • 3. Re: Should I use custom code or callback in USBFS?
              LePo_1062026

              JoBr,

              My personal preferences is to use the callbacks over the direct insertion in the component code.  If the callback can be used in your case, it is easier to maintain especially if the component up-revs or you chose to back-rev.

               

              Len

              • 4. Re: Should I use custom code or callback in USBFS?
                EktaN_26

                Hello JoBr_1593366,

                 

                By default the values of the macros USBFS_GET_MIN, USBFS_GET_MAX, USBFS_GET_RES are Audio Class-Specific Request Codes mentioned in the Universal Serial Bus Device Class Definition for Audio Devices (see page 101): https://usb.org/sites/default/files/audio10.pdf

                Can you please let me know if you have added the Mixer Unit Item in the Audio descriptor and made proper configuration for it?

                 

                 

                 

                Please refer to the page 41 of the USB Audio class devices document mentioned above which contains details regarding the Mixer Unit Descriptor.

                 

                Best Regards

                Ekta

                • 5. Re: Should I use custom code or callback in USBFS?
                  JoBr_1593366

                  Yes, my point is that you need to catch requests intended for different Units, each of which has their own bUnitID.  The existing code just has one request handler for all units and features, which isn't useful.

                   

                  After catching USB_RQST_DIR_D2H → USB_RQST_RCPT_IFC → USB_GET_MIN you also have to direct it to the Unit it was meant for:

                   

                  CY_GET_REG8(USB_wIndexHi) == INPUT_VOLUME_FEATURE_UNIT or OUTPUT_VOLUME_FEATURE_UNIT or SOME_MIXER_UNIT, etc.

                   

                  and which feature within that unit:

                   

                  wValueHi == USB_VOLUME_CONTROL or USB_MUTE_CONTROL or USB_TREBLE_CONTROL, etc.

                   

                  and currently the only way to do this is to modify the USB component source code, which is frustrating because it gets changed with each build or with each component upgrade.  There should be custom code sections in each of these request handlers so we can customize the behavior, just like the USB_GET_CUR has custom code sections.

                  • 6. Re: Should I use custom code or callback in USBFS?
                    RodolfoG_11

                    One way to solve this is to import the USBFS component to PSoC Creator and modify its API files to add these custom sections. See this video:

                    https://www.cypress.com/video-library/PSoC-Software/psoc-creator-tutorial-importing-components/107756

                    • 7. Re: Should I use custom code or callback in USBFS?
                      JoBr_1593366

                      Yes, that's what I've been doing, but it makes it difficult to upgrade the USBFS component to include later bug fixes, etc. These custom code  sections should be included in the USBFS component by default, so that we can customize its function.

                      • 8. Re: Should I use custom code or callback in USBFS?
                        JoBr_1593366

                        Do you have instructions on how to update a component after making changes to it, without destroying those custom changes?  I want to incorporate all the bug fixes that were made to the USBFS component.

                         

                        (These custom code sections should really be built into the USBFS component directly, so that we can make customized USB devices without having to deal with modifying the component itself.  It would be easy for Cypress to add them, and then we wouldn't have to modify the component itself to add them.)