PDA

View Full Version : USB pic18f4550 USB COMPOSITE DEVICE



Saitama
- 3rd April 2023, 17:26
Hello everyone.
I always try to use microde studio for many of my projects because of the speed and ease of reading the code, with its disadvantages such as higher space usage per program and a very small community, I use it because its benefits are greater. among my projects I need to create a composite device, searching the internet I have not found precise information on this topic, not even an example.
I have worked on this and I have achieved something that is close to achieving it,
At this point I think I need to properly address the second device endpoints.
I have analyzed pbppic18.mac USBOUT-->L?CALL PutUSB and the respective usb_dev.asm where I find that I can address correctly without modifying the code because the required Endpoint has been correctly stored in FSR0L. Despite my poor understanding, I have so far modified the usb_mem.asm, usb_dev.inc, and usb_hid.asm files.
The result of this has been that the PC recognizes the composite device correctly and interface 0 communicates (with some easily fixable glitches), but interface 1 is not heard. I think this potential problem is in usb_hid.asm, because invoking endpoint 82 I think it sends to both endpoints 81 and 82, causing me to lose data on device 0 and abort receiving from device 1
https://i.postimg.cc/bvsGSysv/Untitleddf.png
I need some help to find a solution to this problem, if you can help with any contribution I will be very grateful
DES_FirmAC01.bas




' USB descriptors for a HID device
'USBMEMORYADDRESS Con $400 ' USB RAM starts here (set in device header file)
USBMEMORYSIZE Con 256 ' USB RAM size in bytes
USBReservedMemory Var Byte[USBMEMORYSIZE] USBMEMORYADDRESS ' Reserve memory used by USB assembler code


goto hid_desc_end ' Skip over all of the USB assembler code
asm


#define USB_EP0_BUFF_SIZE 8 ; 8, 16, 32, or 64
#define USB_MAX_NUM_INT 2 ; For tracking Alternate Setting
#define USB_MAX_EP_NUMBER 2 ; UEP1
#define NUM_CONFIGURATIONS 1
#define NUM_INTERFACES 2


#define UCFG_VAL USB_PULLUP_ENABLE|USB_INTERNAL_TRANSCEIVER|USB_FUL L_SPEED|USB_PING_PONG__NO_PING_PONG
;#define UCFG_VAL USB_PULLUP_ENABLE|USB_INTERNAL_TRANSCEIVER|USB_LOW _SPEED|USB_PING_PONG__NO_PING_PONG


;#define USE_SELF_POWER_SENSE_IO
;#define USE_USB_BUS_SENSE_IO


#define USB_POLLING


; HID
; Endpoints Allocation
#define HID_INTF_ID 0x00
#define HID_EP 1
#define HID_INT_OUT_EP_SIZE 16
#define HID_INT_IN_EP_SIZE 16


#define HID_DEV_INTF_ID 0x01
#define HID_DEV_EP 2
#define HID_DEV_INT_OUT_EP_SIZE 16
#define HID_DEV_INT_IN_EP_SIZE 16


#define HID_NUM_OF_DSC 1


include "usb_hid.asm" ; Include rest of USB files, starting with HID class code


; ************************************************** ****************
; This table is polled by the host immediately after USB Reset has been released.
; This table defines the maximum packet size EP0 can take.
; See section 9.6.1 of the Rev 1.0 USB specification.
; These fields are application DEPENDENT. Modify these to meet
; your specifications.
; ************************************************** ****************
DeviceDescriptor
retlw (EndDeviceDescriptor-DeviceDescriptor)/2 ; bLength Length of this descriptor
retlw USB_DESCRIPTOR_DEVICE ; bDescType This is a DEVICE descriptor
retlw 0x00 ; bcdUSBUSB Revision 1.10 (low byte)
retlw 0x02 ; high byte
retlw 0x00 ; bDeviceClass zero means each interface operates independently
retlw 0x00 ; bDeviceSubClass
retlw 0x00 ; bDeviceProtocol
retlw USB_EP0_BUFF_SIZE ; bMaxPacketSize for EP0


; idVendor (low byte, high byte)
retlw 0xD9
retlw 0x04


; idProduct (low byte, high byte)
retlw 0x3C
retlw 0x00


retlw 0x00 ; bcdDevice (low byte)
retlw 0x01 ; (high byte)
retlw 0x01 ; iManufacturer (string index)
retlw 0x02 ; iProduct (string index)
retlw 0x03 ; iSerialNumber (string index)
retlw NUM_CONFIGURATIONS ; bNumConfigurations
EndDeviceDescriptor


; ************************************************** ****************
; This table is retrieved by the host after the address has been set.
; This table defines the configurations available for the device.
; See section 9.6.2 of the Rev 1.0 USB specification (page 184).
; These fields are application DEPENDENT.
; Modify these to meet your specifications.
; ************************************************** ****************
; Configuration pointer table
USB_CD_Ptr
Configs
db low Config1, high Config1
db upper Config1, 0


; Configuration Descriptor
Config1
retlw (Interface1-Config1)/2 ; bLength Length of this descriptor
retlw USB_DESCRIPTOR_CONFIGURATION ; bDescType 2=CONFIGURATION
Config1Len
retlw low ((EndConfig1 - Config1)/2) ; Length of this configuration
retlw high ((EndConfig1 - Config1)/2)
retlw NUM_INTERFACES ; bNumInterfaces Number of interfaces
retlw 0x01 ; bConfigValue Configuration Value
retlw 0x00 ; iConfig (string index)
retlw _DEFAULT|_SELF ; bmAttributes attributes - bus powered
retlw 0x32 ; Max power consumption (2X mA)
Interface1
retlw (HIDDescriptor1-Interface1)/2 ; length of descriptor
retlw USB_DESCRIPTOR_INTERFACE
retlw 0x00 ; number of interface, 0 based array
retlw 0x00 ; alternate setting
retlw 0x01 ; number of endpoints used in this interface
retlw 0x03 ; interface class - assigned by the USB
retlw 0x00 ; boot device
retlw 0x00 ; interface protocol
retlw 0x04 ; index to string descriptor that describes this interface
HIDDescriptor1
retlw (Endpoint1In-HIDDescriptor1)/2 ; descriptor size (9 bytes)
retlw DSC_HID ; descriptor type (HID)
retlw 0x11 ; HID class release number (1.11)
retlw 0x01
retlw 0x00 ; Localized country code (none)
retlw 0x01 ; # of HID class descriptor to follow (1)
retlw 0x22 ; Report descriptor type (HID)
ReportDescriptor1Len
retlw low ((EndReportDescriptor1-ReportDescriptor1)/2)
retlw high ((EndReportDescriptor1-ReportDescriptor1)/2)
Endpoint1In
retlw (Interface2-Endpoint1In)/2 ; length of descriptor
retlw USB_DESCRIPTOR_ENDPOINT
retlw HID_EP|_EP_IN ; EP1, In
retlw _INT ; Interrupt
retlw low (HID_INT_IN_EP_SIZE) ; This should be the size of the endpoint buffer
retlw high (HID_INT_IN_EP_SIZE)
retlw 0x01 ; Polling interval
;EndPoint1Out
; retlw (Interface2-EndPoint1Out)/2 ; Length of this Endpoint Descriptor
; retlw USB_DESCRIPTOR_ENDPOINT ; bDescriptorType = 5 for Endpoint Descriptor
; retlw HID_EP|_EP_OUT ; Endpoint number & direction
; retlw _INT ; Transfer type supported by this Endpoint
; retlw low (HID_INT_OUT_EP_SIZE) ; This should be the size of the endpoint buffer
; retlw high (HID_INT_OUT_EP_SIZE)
; retlw 0x01 ; Polling interval
Interface2
retlw (HIDDescriptor2-Interface2)/2 ; length of descriptor
retlw USB_DESCRIPTOR_INTERFACE ; INTERFACE descriptor type
retlw 0x01 ; number of interface, 0 based array
retlw 0x00 ; alternate setting
retlw 0x01 ; number of endpoints used in this interface
retlw 0x03 ; interface class - assigned by the USB
retlw 0x00 ; boot device
retlw 0x00 ; interface protocol
retlw 0x04 ; index to string descriptor that describes this interface
HIDDescriptor2
retlw (Endpoint2In-HIDDescriptor2)/2 ; descriptor size (9 bytes)
retlw DSC_HID ; descriptor type (HID)
retlw 0x11 ; HID class release number (1.11)
retlw 0x01
retlw 0x00 ; Localized country code (none)
retlw 0x01 ; # of HID class descriptor to follow (1)
retlw 0x22 ; Report descriptor type (HID)
ReportDescriptor2Len
retlw low ((EndReportDescriptor2-ReportDescriptor2)/2)
retlw high ((EndReportDescriptor2-ReportDescriptor2)/2)
Endpoint2In
retlw (EndConfig1-Endpoint2In)/2 ; length of descriptor
retlw USB_DESCRIPTOR_ENDPOINT
retlw HID_DEV_EP|_EP_IN ; EP2, In
retlw _INT ; Interrupt
retlw low (HID_DEV_INT_IN_EP_SIZE) ; This should be the size of the endpoint buffer
retlw high (HID_DEV_INT_IN_EP_SIZE)
retlw 0x01 ; Polling interval
;EndPoint2Out
; retlw (EndConfig1-EndPoint2Out)/2 ; Length of this Endpoint Descriptor
; retlw USB_DESCRIPTOR_ENDPOINT ; bDescriptorType = 5 for Endpoint Descriptor
; retlw HID_DEV_EP|_EP_OUT ; Endpoint number & direction
; retlw _INT ; Transfer type supported by this Endpoint
; retlw low (HID_DEV_INT_OUT_EP_SIZE) ; This should be the size of the endpoint buffer
; retlw high (HID_DEV_INT_OUT_EP_SIZE)
; retlw 0x01 ; Polling interval
EndConfig1


ReportDescriptor1
retlw 0x05 ; USAGE_PAGE (generic desktop Choose the usage page "mouse" is on
retlw 0x01 ; LOW

retlw 0x09 ; USAGE Device is a Gamepad
retlw 0x05 ; LOW

retlw 0xA1 ; COLLECTION (APPLICATION)
retlw 0x01 ; LOW

retlw 0x85 ; REPORT_ID (1 Pad1)
retlw 0x01 ; LOW

retlw 0xA1 ; Colection Physycal
retlw 0x00 ; LOW

retlw 0x09 ; usage x
retlw 0x30 ;

retlw 0x09 ; usage y
retlw 0x31 ;

retlw 0x15 ; logical minimun 0
retlw 0x00 ;

retlw 0x26 ; logical maximun 1023
retlw 0xFF ;
retlw 0x03 ;

retlw 0x35 ; Physical Minimum (0)
retlw 0x00 ;

retlw 0x46 ; Physical Maximum (1023)
retlw 0xFF ;
retlw 0x03 ;

retlw 0x95 ; REPORT_COUNT 2
retlw 0x02 ;

retlw 0x75 ; report size 16
retlw 0x10 ;

retlw 0x81 ; data,var,abs
retlw 0x02 ;

retlw 0xC0 ; END_COLLECTION
;******************************************

retlw 0xA1 ; Colection Physycal
retlw 0x00 ; LOW

retlw 0x09 ; usage Rx
retlw 0x33 ;

retlw 0x09 ; usage Ry
retlw 0x34 ;

retlw 0x15 ; logical minimun 0
retlw 0x00 ;

retlw 0x26 ; logical maximun 2047
retlw 0xFF ;
retlw 0x03 ;

retlw 0x35 ; Physical Minimum (0)
retlw 0x00 ;

retlw 0x46 ; Physical Maximum (2047)
retlw 0xFF ;
retlw 0x03 ;

retlw 0x95 ; REPORT_COUNT 2
retlw 0x02 ;

retlw 0x75 ; report size 16
retlw 0x10 ;

retlw 0x81 ; data,var,abs
retlw 0x02 ;

retlw 0xC0 ; END_COLLECTION
;******************************************


retlw 0x05 ; USAGE_PAGE (Button)
retlw 0x09 ; low

retlw 0x19 ; Usage Minimum (Button 1)
retlw 0x01 ;

retlw 0x29 ; Usage Maximum (Button 13)
retlw 0x0D ;

retlw 0x95 ; report count 13
retlw 0x0D ;

retlw 0x75 ; report size 1
retlw 0x01 ;

retlw 0x81 ; input data,var,abs
retlw 0x02 ;

retlw 0x95 ; report count 1
retlw 0x01 ;

retlw 0x75 ; report size 3
retlw 0x03 ;

retlw 0x81 ; input Cnst,var,abs
retlw 0x01 ;

retlw 0xC0 ; END_COLLECTION


;************************************************* **********************
;* GamePAD 2 *
;************************************************* **********************


retlw 0x05 ; USAGE_PAGE (generic desktop Choose the usage page "mouse" is on
retlw 0x01 ; LOW

retlw 0x09 ; USAGE Device is a Gamepad
retlw 0x05 ; LOW

retlw 0xA1 ; COLLECTION (APPLICATION)
retlw 0x01 ; LOW

retlw 0x85 ; REPORT_ID (1 Pad1)
retlw 0x02 ; LOW

retlw 0xA1 ; Colection Physycal
retlw 0x00 ; LOW

retlw 0x09 ; usage x
retlw 0x30 ;

retlw 0x09 ; usage y
retlw 0x31 ;

retlw 0x15 ; logical minimun 0
retlw 0x00 ;

retlw 0x26 ; logical maximun 1023
retlw 0xFF ;
retlw 0x03 ;

retlw 0x35 ; Physical Minimum (0)
retlw 0x00 ;

retlw 0x46 ; Physical Maximum (1023)
retlw 0xFF ;
retlw 0x03 ;

retlw 0x95 ; REPORT_COUNT 2
retlw 0x02 ;

retlw 0x75 ; report size 16
retlw 0x10 ;

retlw 0x81 ; data,var,abs
retlw 0x02 ;

retlw 0xC0 ; END_COLLECTION
;******************************************

retlw 0xA1 ; Colection Physycal
retlw 0x00 ; LOW

retlw 0x09 ; usage Rx
retlw 0x33 ;

retlw 0x09 ; usage Ry
retlw 0x34 ;

retlw 0x15 ; logical minimun 0
retlw 0x00 ;

retlw 0x26 ; logical maximun 2047
retlw 0xFF ;
retlw 0x03 ;

retlw 0x35 ; Physical Minimum (0)
retlw 0x00 ;

retlw 0x46 ; Physical Maximum (2047)
retlw 0xFF ;
retlw 0x03 ;

retlw 0x95 ; REPORT_COUNT 2
retlw 0x02 ;

retlw 0x75 ; report size 16
retlw 0x10 ;

retlw 0x81 ; data,var,abs
retlw 0x02 ;

retlw 0xC0 ; END_COLLECTION
;******************************************


retlw 0x05 ; USAGE_PAGE (Button)
retlw 0x09 ; low

retlw 0x19 ; Usage Minimum (Button 1)
retlw 0x01 ;

retlw 0x29 ; Usage Maximum (Button 13)
retlw 0x0E ;

retlw 0x95 ; report count 13
retlw 0x0E ;

retlw 0x75 ; report size 1
retlw 0x01 ;

retlw 0x81 ; input data,var,abs
retlw 0x02 ;

retlw 0x95 ; report count 1
retlw 0x01 ;

retlw 0x75 ; report size 2
retlw 0x02 ;

retlw 0x81 ; input Cnst,var,abs
retlw 0x01 ;

retlw 0xC0 ; END_COLLECTION


EndReportDescriptor1


ReportDescriptor2
;***************************************
;* Mouse Emu *
;***************************************
retlw 0x05 ; USAGE_PAGE (generic desktop)
retlw 0x01 ; LOW

retlw 0x09 ; USAGE Mouse
retlw 0x02 ; LOW

retlw 0xA1 ; COLLECTION (APPLICATION)
retlw 0x01 ; LOW

retlw 0x85 ; REPORT_ID (1)
retlw 0x01 ; LOW

retlw 0x09 ; USAGE_PAGE (Pointer)
retlw 0x01 ; LOW

retlw 0xA1 ; COLLECTION (Physical)
retlw 0x00 ;

retlw 0x05 ; USAGE_PAGE (Button)
retlw 0x09 ;

retlw 0x19 ; Usage Minimum (Button 1)
retlw 0x01 ;

retlw 0x29 ; Usage Maximum (Button 2)
retlw 0x02 ;

retlw 0x15 ; logical minimun
retlw 0x00 ;

retlw 0x25 ; logical maximun
retlw 0x01 ;

retlw 0x75 ; report size 1
retlw 0x01 ;

retlw 0x95 ; report count 3
retlw 0x02 ;

retlw 0x81 ; input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit)
retlw 0x02 ;

retlw 0x95 ; report count 3
retlw 0x06 ;

retlw 0x81 ; input (Data,Var,Abs)
retlw 0x03 ;

retlw 0x05 ; USAGE_PAGE (Generic Desktop)
retlw 0x01 ; LOW

retlw 0x09 ; Usage(X)
retlw 0x30 ;

retlw 0x09 ; Usage(Y)
retlw 0x31 ;

retlw 0x15 ; logical minimun (-127)
retlw 0x81 ;

retlw 0x25 ; logical maximun (127)
retlw 0x7F ;

retlw 0x75 ; report size 8
retlw 0x08 ;

retlw 0x95 ; report count 2
retlw 0x02 ;

retlw 0x81 ; INPUT (Data,Var,Rel)
retlw 0x06 ;

retlw 0xC0 ; END_COLLECTION
retlw 0xC0 ; END_COLLECTION

;***************************************
;* Keyboard Emu *
;***************************************



;***************************************
;* Volume Control *
;***************************************
retlw 0x05 ; USAGE_PAGE (Consumer Devices)
retlw 0x0C ; LOW

retlw 0x09 ; USAGE (Consumer Control)
retlw 0x01 ; LOW

retlw 0xA1 ; COLLECTION (APPLICATION)
retlw 0x01 ; LOW

retlw 0x85 ; REPORT_ID (2 Media)
retlw 0x02 ; LOW

retlw 0x19 ; Usage Minimum (0x00)
retlw 0x00 ;

retlw 0x2A ; Usage Maximum (0xAC format)
retlw 0x3C ;
retlw 0x02

retlw 0x15 ; logical minimun
retlw 0x00 ;

retlw 0x26 ; logical maximun (572)
retlw 0x3C ;
retlw 0x02 ;


retlw 0x95 ; report count 1
retlw 0x01 ;

retlw 0x75 ; report size 16
retlw 0x10 ;

retlw 0x81 ; input (Data,Var,Abs)
retlw 0x00 ;

retlw 0xC0 ; END_COLLECTION
EndReportDescriptor2


; String pointer table
USB_SD_Ptr
Strings
db low String0, high String0
db upper String0, 0
db low String1, high String1
db upper String1, 0
db low String2, high String2
db upper String2, 0
db low String3, high String3
db upper String3, 0


String0
retlw (String1-String0)/2 ; Length of string
retlw USB_DESCRIPTOR_STRING ; Descriptor type 3
retlw 0x09 ; Language ID (as defined by MS 0x0409)
retlw 0x04


; company name
String1
retlw (String2-String1)/2
retlw USB_DESCRIPTOR_STRING

retlw 'D'
retlw 0x00
retlw 'C'
retlw 0x00
retlw 'L'
retlw 0x00
retlw '.'
retlw 0x00



; product name
String2
retlw (String3-String2)/2
retlw USB_DESCRIPTOR_STRING

retlw 'P'
retlw 0x00
retlw 'B'
retlw 0x00
retlw 'J'
retlw 0x00
retlw 'U'
retlw 0x00
retlw 'I'
retlw 0x00
retlw '3'
retlw 0x00
retlw '2'
retlw 0x00
retlw 'I'
retlw 0x00
retlw 'A'
retlw 0x00
retlw '8'
retlw 0x00
retlw 'O'
retlw 0x00
retlw '2'
retlw 0x00
retlw '4'
retlw 0x00


; serial number
String3
retlw (String4-String3)/2
retlw USB_DESCRIPTOR_STRING

retlw 'D'
retlw 0x00
retlw 'J'
retlw 0x00
retlw 'C'
retlw 0x00
retlw '0'
retlw 0x00
retlw '0'
retlw 0x00
retlw '2'
retlw 0x00
retlw '2'
retlw 0x00


String4
retlw (String5-String4)/2
retlw USB_DESCRIPTOR_STRING

retlw 'A'
retlw 0x00
retlw 'R'
retlw 0x00
retlw 'C'
retlw 0x00
retlw 'A'
retlw 0x00
retlw 'D'
retlw 0x00
retlw 'E'
retlw 0x00
retlw ' '
retlw 0x00
retlw 'J'
retlw 0x00
retlw 'A'
retlw 0x00
retlw 'M'
retlw 0x00
retlw 'M'
retlw 0x00
retlw 'A'
retlw 0x00

String5
endasm
hid_desc_end




usb_hid.asm

; usb_hid.asm




;************************************************* *******************
; File Description:


; Change History:
; Rev Date Description
; 1.0 11/19/2004 Initial release
; 2.1 02/26/2007 Updated for simplicity and to use common
; coding style
;************************************************* ******************/


;/** INCLUDES ************************************************** *****/
;#include "GenericTypeDefs.h"
;#include "Compiler.h"
;#include "usb_config.h"
;#include "./USB/usb_device.h"
;#include "./USB/usb_function_hid.h"


;/** VARIABLES ************************************************** ****/
;#pragma udata
;BYTE idle_rate;
;BYTE active_protocol; // [0] Boot Protocol [1] Report Protocol
;BYTE hid_rpt_rx_len;


;/** PRIVATE PROTOTYPES *********************************************/
;void HIDGetReportHandler(void);
;void HIDSetReportHandler(void);


;/** DECLARATIONS ************************************************** */
;#pragma code


;/** CLASS SPECIFIC REQUESTS ****************************************/
;/************************************************** ******************
; * Function: void USBCheckHIDRequest(void)
; *
; * PreCondition: None
; *
; * Input: None
; *
; * Output: None
; *
; * Side Effects: None
; *
; * Overview: This routine checks the setup data packet to see
; * if it knows how to handle it
; *
; * Note: None
; ************************************************** *****************/
;//void USBCheckHIDRequest(void)
USBCheckHIDRequest
;//{
movlb high _USBMEMORYADDRESS ; Point to proper bank
;// if(SetupPkt.Recipient != RCPT_INTF) return;
movf SetupPkt, W ; Recipient = RCPT_INTF?
andlw 0x1f ; Mask to lower 5 bits
sublw RCPT_INTF
bnz USBCheckHIDRequestExit ; No


;// if((SetupPkt.bIntfID != HID_INTF_ID)&&
movlw HID_INTF_ID ; IntfID = HID_INTF_ID?
cpfseq SetupPkt + bIntfID
;// (SetupPkt.bIntfID != HID_DEV_INTF_ID)) return;
movlw HID_DEV_INTF_ID ; IntfID = HID_DEV_INTF_ID?
cpfseq SetupPkt + bIntfID


USBCheckHIDRequestExit
return ; No

; /*
; * There are two standard requests that hid.c may support.
; * 1. GET_DSC(DSC_HID,DSC_RPT,DSC_PHY);
; * 2. SET_DSC(DSC_HID,DSC_RPT,DSC_PHY);
; */
;// if(SetupPkt.bRequest == GET_DSC)
movlw GET_DSC ; Request = GET_DSC?
cpfseq SetupPkt + bRequest
bra USBCheckHIDRequestClass ; No
;// {
;// switch(SetupPkt.bDescriptorType)
;// {
;// case DSC_HID:
movlw DSC_HID ; DescriptorType = DSC_HID?
cpfseq SetupPkt + bDescriptorType
bra USBCheckHIDRequest1 ; No
;// if(USBActiveConfiguration == 1)
movlw 1 ; USBActiveConfiguration = 1?
cpfseq USBActiveConfiguration
bra USBCheckHIDRequestClass ; No
;// {
;// USBEP0SendROMPtr(
;// (ROM BYTE*)&configDescriptor1 + 18,
;// sizeof(USB_HID_DSC)+3, // RRoj hack
;// USB_EP0_INCLUDE_ZERO);
movlw HID_INTF_ID ; IntfID = HID_INTF_ID?
cpfseq SetupPkt + bIntfID
bra USBHdesc2 ; Use HIDDescriptor2


mSetSourcePointer HIDDescriptor1
mGetRomTableCount ; Set wCount
;// clrf info
bcf info, ctrl_trf_mem ; Indicate ROM
bsf info, includeZero ; Include a trailing zero packet
bsf info, busy
bra USBCheckHIDRequestClass


USBHdesc2
mSetSourcePointer HIDDescriptor2
mGetRomTableCount ; Set wCount
;// clrf info
bcf info, ctrl_trf_mem ; Indicate ROM
bsf info, includeZero ; Include a trailing zero packet
bsf info, busy
bra USBCheckHIDRequestClass


;// }
;// break;
USBCheckHIDRequest1
; case DSC_RPT:
movlw DSC_RPT ; DescriptorType = DSC_RPT?
cpfseq SetupPkt + bDescriptorType
bra USBCheckHIDRequest2 ; No
; if(USBActiveConfiguration == 1)
movlw 1 ; USBActiveConfiguration = 1?
cpfseq USBActiveConfiguration
bra USBCheckHIDRequestClass ; No
; {
; USBEP0SendROMPtr(
; (ROM BYTE*)&hid_rpt01,
; sizeof(hid_rpt01), //See usbcfg.h
; USB_EP0_INCLUDE_ZERO);


movlw HID_INTF_ID ; IntfID = HID_INTF_ID?
cpfseq SetupPkt + bIntfID
bra USBRDasc2 ; Use ReportDescriptor2


mSetSourcePointer ReportDescriptor1
movlw low (ReportDescriptor1Len) ; Set wCount
movwf TBLPTRL
movlw high (ReportDescriptor1Len)
movwf TBLPTRH
movlw upper (ReportDescriptor1Len)
movwf TBLPTRU
tblrd *+ ; Read count low
movff TABLAT, inCount
tblrd *+ ; Skip next
tblrd * ; Read count high
movff TABLAT, inCount + 1
;// clrf info
bcf info, ctrl_trf_mem ; Indicate ROM
bsf info, includeZero ; Include a trailing zero packet
bsf info, busy
bra USBCheckHIDRequestClass
USBRDasc2
mSetSourcePointer ReportDescriptor2
movlw low (ReportDescriptor1Len) ; Set wCount
movwf TBLPTRL
movlw high (ReportDescriptor1Len)
movwf TBLPTRH
movlw upper (ReportDescriptor1Len)
movwf TBLPTRU
tblrd *+ ; Read count low
movff TABLAT, inCount
tblrd *+ ; Skip next
tblrd * ; Read count high
movff TABLAT, inCount + 1
;// clrf info
bcf info, ctrl_trf_mem ; Indicate ROM
bsf info, includeZero ; Include a trailing zero packet
bsf info, busy
bra USBCheckHIDRequestClass
;// }
;// break;






https://drive.google.com/file/d/1J_o76uFFcyrDTBeuz-tusKk6rdubFsge/view?usp=sharing

Saitama
- 6th April 2023, 08:05
solved. composite device works

USBCheckHIDRequest;//{
movlb high _USBMEMORYADDRESS ; Point to proper bank
;// if(SetupPkt.Recipient != RCPT_INTF) return;
movf SetupPkt, W ; Recipient = RCPT_INTF?
andlw 0x1f ; Mask to lower 5 bits
sublw RCPT_INTF
bnz USBCheckHIDRequestExit ; No
;// if(SetupPkt.bIntfID != HID_DEV_INTF_ID) return;
movlw HID_DEV_INTF_ID ; IntfID = HID_DEV_INTF_ID?
subwf SetupPkt + bIntfID, W
bz USBCheckHIDRequest3 ; Yes
;// if(SetupPkt.bIntfID != HID_INTF_ID) return;
movlw HID_INTF_ID ; IntfID = HID_INTF_ID?
cpfseq SetupPkt + bIntfID


USBCheckHIDRequestExit
return ; No

; /*
; * There are two standard requests that hid.c may support.
; * 1. GET_DSC(DSC_HID,DSC_RPT,DSC_PHY);
; * 2. SET_DSC(DSC_HID,DSC_RPT,DSC_PHY);
; */
;// if(SetupPkt.bRequest == GET_DSC)
movlw GET_DSC ; Request = GET_DSC?
cpfseq SetupPkt + bRequest
bra USBCheckHIDRequestClass ; No
;// {
;// switch(SetupPkt.bDescriptorType)
;// {
;// case DSC_HID:
movlw DSC_HID ; DescriptorType = DSC_HID?
cpfseq SetupPkt + bDescriptorType
bra USBCheckHIDRequest1 ; No
;// if(USBActiveConfiguration == 1)
movlw 1 ; USBActiveConfiguration = 1?
cpfseq USBActiveConfiguration
bra USBCheckHIDRequestClass ; No
;// {
;// USBEP0SendROMPtr(
;// (ROM BYTE*)&configDescriptor1 + 18,
;// sizeof(USB_HID_DSC)+3, // RRoj hack
;// USB_EP0_INCLUDE_ZERO);
mSetSourcePointer HIDDescriptor1
mGetRomTableCount ; Set wCount
;// clrf info
bcf info, ctrl_trf_mem ; Indicate ROM
bsf info, includeZero ; Include a trailing zero packet
bsf info, busy
bra USBCheckHIDRequestClass


;// }
;// break;
USBCheckHIDRequest3
; /*
; * There are two standard requests that hid.c may support.
; * 1. GET_DSC(DSC_HID,DSC_RPT,DSC_PHY);
; * 2. SET_DSC(DSC_HID,DSC_RPT,DSC_PHY);
; */
;// if(SetupPkt.bRequest == GET_DSC)
movlw GET_DSC ; Request = GET_DSC?
cpfseq SetupPkt + bRequest
bra USBCheckHIDRequestClass ; No
;// {
;// switch(SetupPkt.bDescriptorType)
;// {
;// case DSC_HID:
movlw DSC_HID ; DescriptorType = DSC_HID?
cpfseq SetupPkt + bDescriptorType
bra USBCheckHIDRequest1 ; No
;// if(USBActiveConfiguration == 1)
movlw 1 ; USBActiveConfiguration = 1?
cpfseq USBActiveConfiguration
bra USBCheckHIDRequestClass ; No
;// {
;// USBEP0SendROMPtr(
;// (ROM BYTE*)&configDescriptor1 + 18,
;// sizeof(USB_HID_DSC)+3, // RRoj hack
;// USB_EP0_INCLUDE_ZERO);


mSetSourcePointer HIDDescriptor2
mGetRomTableCount ; Set wCount
;// clrf info
bcf info, ctrl_trf_mem ; Indicate ROM
bsf info, includeZero ; Include a trailing zero packet
bsf info, busy
bra USBCheckHIDRequestClass


USBCheckHIDRequest1
; case DSC_RPT:


movlw HID_DEV_INTF_ID ; IntfID = HID_DEV_INTF_ID?
subwf SetupPkt + bIntfID, W
bz USBCheckHIDRequest4 ; Yes


movlw DSC_RPT ; DescriptorType = DSC_RPT?
cpfseq SetupPkt + bDescriptorType
bra USBCheckHIDRequest2 ; No
; if(USBActiveConfiguration == 1)
movlw 1 ; USBActiveConfiguration = 1?
cpfseq USBActiveConfiguration
bra USBCheckHIDRequestClass ; No
; {
; USBEP0SendROMPtr(
; (ROM BYTE*)&hid_rpt01,
; sizeof(hid_rpt01), //See usbcfg.h
; USB_EP0_INCLUDE_ZERO);


mSetSourcePointer ReportDescriptor1
movlw low (ReportDescriptor1Len) ; Set wCount
movwf TBLPTRL
movlw high (ReportDescriptor1Len)
movwf TBLPTRH
movlw upper (ReportDescriptor1Len)
movwf TBLPTRU
tblrd *+ ; Read count low
movff TABLAT, inCount
tblrd *+ ; Skip next
tblrd * ; Read count high
movff TABLAT, inCount + 1
;// clrf info
bcf info, ctrl_trf_mem ; Indicate ROM
bsf info, includeZero ; Include a trailing zero packet
bsf info, busy
bra USBCheckHIDRequestClass
;// }
;// break;
USBCheckHIDRequest2
;// case DSC_PHY:
movlw DSC_PHY ; DescriptorType = DSC_PHY?
cpfseq SetupPkt + bDescriptorType
bra USBCheckHIDRequestClass
; USBEP0Transmit(USB_EP0_NO_DATA);
clrf info
bsf info, busy
; break;
; }//end switch(SetupPkt.bDescriptorType)
; }//end if(SetupPkt.bRequest == GET_DSC)

USBCheckHIDRequestClass
; if(SetupPkt.RequestType != CLASS) return;
movf SetupPkt, W ; RequestType = CLASS?
andlw 0x60 ; Mask to proper bits
sublw (CLASS) << 5
bnz USBCheckHIDRequestExit ; No
; switch(SetupPkt.bRequest)
; {
; case GET_REPORT:
movlw GET_REPORT ; Request = GET_REPORT?
subwf SetupPkt + bRequest, W
; HIDGetReportHandler();
bz HIDGetReportHandler ; Yes
; break;
; case SET_REPORT:
movlw SET_REPORT ; Request = SET_REPORT?
subwf SetupPkt + bRequest, W
; HIDSetReportHandler();
bz HIDSetReportHandler ; Yes
; break;
; case GET_IDLE:
movlw GET_IDLE ; Request = GET_IDLE?
cpfseq SetupPkt + bRequest
bra USBCheckHIDRequestClass1 ; No
; USBEP0SendRAMPtr(
; (BYTE*)&idle_rate,
; 1,
; USB_EP0_INCLUDE_ZERO);
mSetSourcePointer idle_rate
movlw 1
movwf inCount
clrf inCount + 1
; clrf info
bsf info, ctrl_trf_mem ; Indicate RAM
bsf info, includeZero ; Include a trailing zero packet
bsf info, busy
return
; break;
USBCheckHIDRequestClass1
; case SET_IDLE:
movlw SET_IDLE ; Request = SET_IDLE?
cpfseq SetupPkt + bRequest
bra USBCheckHIDRequestClass2 ; No
; USBEP0Transmit(USB_EP0_NO_DATA);
clrf info
bsf info, busy
; idle_rate = SetupPkt.W_Value.byte.HB;
movff SetupPkt + wValue + 1, idle_rate
return
; break;
USBCheckHIDRequestClass2
; case GET_PROTOCOL:
movlw GET_PROTOCOL ; Request = GET_PROTOCOL?
cpfseq SetupPkt + bRequest
bra USBCheckHIDRequestClass3 ; No
; USBEP0SendRAMPtr(
; (BYTE*)&active_protocol,
; 1,
; USB_EP0_NO_OPTIONS);
mSetSourcePointer active_protocol
movlw 1
movwf inCount
clrf inCount + 1
clrf info
bsf info, ctrl_trf_mem ; Indicate RAM
bsf info, busy
return
; break;
USBCheckHIDRequestClass3
; case SET_PROTOCOL:
movlw SET_PROTOCOL ; Request = SET_PROTOCOL?
cpfseq SetupPkt + bRequest
return ; No
; USBEP0Transmit(USB_EP0_NO_DATA);
clrf info
bsf info, busy
; active_protocol = SetupPkt.W_Value.byte.LB;
movff SetupPkt + wValue, active_protocol
; break;
; }//end switch(SetupPkt.bRequest)
return
;}//end USBCheckHIDRequest


;void HIDGetReportHandler(void)
HIDGetReportHandler
;{
return
;}//end HIDGetReportHandler


;void HIDSetReportHandler(void)
HIDSetReportHandler
;{
return
;}//end HIDSetReportHandler


USBCheckHIDRequest4
; case DSC_RPT:
movlw DSC_RPT ; DescriptorType = DSC_RPT?
cpfseq SetupPkt + bDescriptorType
bra USBCheckHIDRequest2 ; No
; if(USBActiveConfiguration == 1)
movlw 1 ; USBActiveConfiguration = 1?
cpfseq USBActiveConfiguration
bra USBCheckHIDRequestClass ; No
; {
; USBEP0SendROMPtr(
; (ROM BYTE*)&hid_rpt01,
; sizeof(hid_rpt01), //See usbcfg.h
; USB_EP0_INCLUDE_ZERO);




mSetSourcePointer ReportDescriptor2
movlw low (ReportDescriptor1Len) ; Set wCount
movwf TBLPTRL
movlw high (ReportDescriptor1Len)
movwf TBLPTRH
movlw upper (ReportDescriptor1Len)
movwf TBLPTRU
tblrd *+ ; Read count low
movff TABLAT, inCount
tblrd *+ ; Skip next
tblrd * ; Read count high
movff TABLAT, inCount + 1
;// clrf info
bcf info, ctrl_trf_mem ; Indicate ROM
bsf info, includeZero ; Include a trailing zero packet
bsf info, busy
bra USBCheckHIDRequestClass
;// }
;// break;


;/** USER API ************************************************** *****/


;/************************************************** ******************
; * Function: void HIDInitEP(void)
; *
; * PreCondition: None
; *
; * Input: None
; *
; * Output: None
; *
; * Side Effects: None
; *
; * Overview: HIDInitEP initializes HID endpoints, buffer
; * descriptors, internal state-machine, and
; * variables. It should be called after the USB
; * host has sent out a SET_CONFIGURATION request.
; * See USBStdSetCfgHandler() in usbd.c for examples.
; *
; * Note: None
; ************************************************** *****************/
;#if !defined(USB_DYNAMIC_EP_CONFIG)
;void HIDInitEP(void)
;{
;}//end HIDInitEP
;#endif


;// ************************************************** ************************************************** **
;// ************** USB Callback Functions ************************************************** **************
;// ************************************************** ************************************************** **
;// The USB firmware stack will call the callback functions USBCBxxx() in response to certain USB related
;// events. For example, if the host PC is powering down, it will stop sending out Start of Frame (SOF)
;// packets to your device. In response to this, all USB devices are supposed to decrease their power
;// consumption from the USB Vbus to <2.5mA each. The USB module detects this condition (which according
;// to the USB specifications is 3+ms of no bus activity/SOF packets) and then calls the USBCBSuspend()
;// function. You should modify these callback functions to take appropriate actions for each of these
;// conditions. For example, in the USBCBSuspend(), you may wish to add code that will decrease power
;// consumption from Vbus to <2.5mA (such as by clock switching, turning off LEDs, putting the
;// microcontroller to sleep, etc.). Then, in the USBCBWakeFromSuspend() function, you may then wish to
;// add code that undoes the power saving things done in the USBCBSuspend() function.


;// The USBCBSendResume() function is special, in that the USB stack will not automatically call this
;// function. This function is meant to be called from the application firmware instead. See the
;// additional comments near the function.


;/************************************************** ****************************
; * Function: void USBCBSuspend(void)
; *
; * PreCondition: None
; *
; * Input: None
; *
; * Output: None
; *
; * Side Effects: None
; *
; * Overview: Call back that is invoked when a USB suspend is detected
; *
; * Note: None
; ************************************************** ***************************/
;void USBCBSuspend(void)
USBCBSuspend
;{
; //Example power saving code. Insert appropriate code here for the desired
; //application behavior. If the microcontroller will be put to sleep, a
; //process similar to that shown below may be used:

; //ConfigureIOPinsForLowPower();
; //SaveStateOfAllInterruptEnableBits();
; //DisableAllInterruptEnableBits();
; //EnableOnlyTheInterruptsWhichWillBeUsedToWakeTheMic ro(); //should enable at least USBActivityIF as a wake source
; //Sleep();
; //RestoreStateOfAllPreviouslySavedInterruptEnableBit s(); //Preferrably, this should be done in the USBCBWakeFromSuspend() function instead.
; //RestoreIOPinsToNormal(); //Preferrably, this should be done in the USBCBWakeFromSuspend() function instead.


; //IMPORTANT NOTE: Do not clear the USBActivityIF (ACTVIF) bit here. This bit is
; //cleared inside the usb_device.c file. Clearing USBActivityIF here will cause
; //things to not work as intended.



; #if defined(__C30__)
; #if 0
; U1EIR = 0xFFFF;
; U1IR = 0xFFFF;
; U1OTGIR = 0xFFFF;
; IFS5bits.USB1IF = 0;
; IEC5bits.USB1IE = 1;
; U1OTGIEbits.ACTVIE = 1;
; U1OTGIRbits.ACTVIF = 1;
; TRISA &= 0xFF3F;
; LATAbits.LATA6 = 1;
; Sleep();
; LATAbits.LATA6 = 0;
; #endif
; #endif
return
;}




;/************************************************** ****************************
; * Function: void _USB1Interrupt(void)
; *
; * PreCondition: None
; *
; * Input: None
; *
; * Output: None
; *
; * Side Effects: None
; *
; * Overview: This function is called when the USB interrupt bit is set
; * In this example the interrupt is only used when the device
; * goes to sleep when it receives a USB suspend command
; *
; * Note: None
; ************************************************** ***************************/
;#if 0
;void __attribute__ ((interrupt)) _USB1Interrupt(void)
;{
; #if !defined(self_powered)
; if(U1OTGIRbits.ACTVIF)
; {
; LATAbits.LATA7 = 1;
;
; IEC5bits.USB1IE = 0;
; U1OTGIEbits.ACTVIE = 0;
; IFS5bits.USB1IF = 0;
;
; //USBClearInterruptFlag(USBActivityIFReg,USBActivity IFBitNum);
; USBClearInterruptFlag(USBIdleIFReg,USBIdleIFBitNum );
; //USBSuspendControl = 0;
; LATAbits.LATA7 = 0;
; }
; #endif
;}
;#endif


;/************************************************** ****************************
; * Function: void USBCBWakeFromSuspend(void)
; *
; * PreCondition: None
; *
; * Input: None
; *
; * Output: None
; *
; * Side Effects: None
; *
; * Overview: The host may put USB peripheral devices in low power
; * suspend mode (by "sending" 3+ms of idle). Once in suspend
; * mode, the host may wake the device back up by sending non-
; * idle state signalling.
; *
; * This call back is invoked when a wakeup from USB suspend
; * is detected.
; *
; * Note: None
; ************************************************** ***************************/
;void USBCBWakeFromSuspend(void)
USBCBWakeFromSuspend
;{
; // If clock switching or other power savings measures were taken when
; // executing the USBCBSuspend() function, now would be a good time to
; // switch back to normal full power run mode conditions. The host allows
; // a few milliseconds of wakeup time, after which the device must be
; // fully back to normal, and capable of receiving and processing USB
; // packets. In order to do this, the USB module must receive proper
; // clocking (IE: 48MHz clock must be available to SIE for full speed USB
; // operation).
return
;}


;/************************************************** ******************
; * Function: void USBCB_SOF_Handler(void)
; *
; * PreCondition: None
; *
; * Input: None
; *
; * Output: None
; *
; * Side Effects: None
; *
; * Overview: The USB host sends out a SOF packet to full-speed
; * devices every 1 ms. This interrupt may be useful
; * for isochronous pipes. End designers should
; * implement callback routine as necessary.
; *
; * Note: None
; ************************************************** *****************/
;void USBCB_SOF_Handler(void)
USBCB_SOF_Handler
;{
; // No need to clear UIRbits.SOFIF to 0 here.
; // Callback caller is already doing that.
return
;}


;/************************************************** *****************
; * Function: void USBCBErrorHandler(void)
; *
; * PreCondition: None
; *
; * Input: None
; *
; * Output: None
; *
; * Side Effects: None
; *
; * Overview: The purpose of this callback is mainly for
; * debugging during development. Check UEIR to see
; * which error causes the interrupt.
; *
; * Note: None
; ************************************************** *****************/
;void USBCBErrorHandler(void)
USBCBErrorHandler
;{
; // No need to clear UEIR to 0 here.
; // Callback caller is already doing that.


; // Typically, user firmware does not need to do anything special
; // if a USB error occurs. For example, if the host sends an OUT
; // packet to your device, but the packet gets corrupted (ex:
; // because of a bad connection, or the user unplugs the
; // USB cable during the transmission) this will typically set
; // one or more USB error interrupt flags. Nothing specific
; // needs to be done however, since the SIE will automatically
; // send a "NAK" packet to the host. In response to this, the
; // host will normally retry to send the packet again, and no
; // data loss occurs. The system will typically recover
; // automatically, without the need for application firmware
; // intervention.

; // Nevertheless, this callback function is provided, such as
; // for debugging purposes.
return
;}




;/************************************************** *****************
; * Function: void USBCBCheckOtherReq(void)
; *
; * PreCondition: None
; *
; * Input: None
; *
; * Output: None
; *
; * Side Effects: None
; *
; * Overview: When SETUP packets arrive from the host, some
; * firmware must process the request and respond
; * appropriately to fulfill the request. Some of
; * the SETUP packets will be for standard
; * USB "chapter 9" (as in, fulfilling chapter 9 of
; * the official USB specifications) requests, while
; * others may be specific to the USB device class
; * that is being implemented. For example, a HID
; * class device needs to be able to respond to
; * "GET REPORT" type of requests. This
; * is not a standard USB chapter 9 request, and
; * therefore not handled by usb_device.c. Instead
; * this request should be handled by class specific
; * firmware, such as that contained in usb_function_hid.c.
; *
; * Note: None
; ************************************************** ***************************/
;void USBCBCheckOtherReq(void)
USBCBCheckOtherReq
;{
; USBCheckHIDRequest();
bra USBCheckHIDRequest
;}//end




;/************************************************** *****************
; * Function: void USBCBStdSetDscHandler(void)
; *
; * PreCondition: None
; *
; * Input: None
; *
; * Output: None
; *
; * Side Effects: None
; *
; * Overview: The USBCBStdSetDscHandler() callback function is
; * called when a SETUP, bRequest: SET_DESCRIPTOR request
; * arrives. Typically SET_DESCRIPTOR requests are
; * not used in most applications, and it is
; * optional to support this type of request.
; *
; * Note: None
; ************************************************** ***************************/
;void USBCBStdSetDscHandler(void)
USBCBStdSetDscHandler
;{
; // Must claim session ownership if supporting this request
return
;}//end




;/************************************************** ****************************
; * Function: void USBCBInitEP(void)
; *
; * PreCondition: None
; *
; * Input: None
; *
; * Output: None
; *
; * Side Effects: None
; *
; * Overview: This function is called when the device becomes
; * initialized, which occurs after the host sends a
; * SET_CONFIGURATION (wValue not = 0) request. This
; * callback function should initialize the endpoints
; * for the device's usage according to the current
; * configuration.
; *
; * Note: None
; ************************************************** ***************************/
;void USBCBInitEP(void)
USBCBInitEP
;{
; Enable the HID endpoint
; USBEnableEndpoint(HID_EP,USB_IN_ENABLED|USB_HANDSH AKE_ENABLED|USB_DISALLOW_SETUP);
; Enable and configure OUT endpoint
movlb high _USBMEMORYADDRESS ; Point to proper bank
movlw HID_EP
movwf FSR0L ; Endpoint number
movlw USB_OUT_ENABLED|USB_IN_ENABLED|USB_HANDSHAKE_ENABL ED|USB_DISALLOW_SETUP
movwf usb_temp ; Options
lfsr 1, hid_report_out ; Endpoint buffer
movlw HID_INT_OUT_EP_SIZE ; Endpoint size
rcall USBEnableEndpointOut


; Enable and configure IN endpoint
movlb high _USBMEMORYADDRESS ; Point to proper bank
movlw HID_EP
movwf FSR0L ; Endpoint number
movlw USB_OUT_ENABLED|USB_IN_ENABLED|USB_HANDSHAKE_ENABL ED|USB_DISALLOW_SETUP
movwf usb_temp ; Options
lfsr 1, hid_report_in ; Endpoint buffer
movlw HID_INT_IN_EP_SIZE ; Endpoint size
rcall USBEnableEndpointIn


; USBEnableEndpoint(HID_DEV_EP,USB_IN_ENABLED|USB_HA NDSHAKE_ENABLED|USB_DISALLOW_SETUP);
; Enable and configure OUT endpoint
movlb high _USBMEMORYADDRESS ; Point to proper bank
movlw HID_DEV_EP
movwf FSR0L ; Endpoint number
movlw USB_OUT_ENABLED|USB_IN_ENABLED|USB_HANDSHAKE_ENABL ED|USB_DISALLOW_SETUP
movwf usb_temp ; Options
lfsr 1, hid_dev_report_out ; Endpoint buffer
movlw HID_DEV_INT_OUT_EP_SIZE ; Endpoint size
rcall USBEnableEndpointOut


; Enable and configure IN endpoint
movlb high _USBMEMORYADDRESS ; Point to proper bank
movlw HID_DEV_EP
movwf FSR0L ; Endpoint number
movlw USB_OUT_ENABLED|USB_IN_ENABLED|USB_HANDSHAKE_ENABL ED|USB_DISALLOW_SETUP
movwf usb_temp ; Options
lfsr 1, hid_dev_report_in ; Endpoint buffer
movlw HID_DEV_INT_IN_EP_SIZE ; Endpoint size
bra USBEnableEndpointIn
;}


;/************************************************** ******************
; * Function: void USBCBSendResume(void)
; *
; * PreCondition: None
; *
; * Input: None
; *
; * Output: None
; *
; * Side Effects: None
; *
; * Overview: The USB specifications allow some types of USB
; * peripheral devices to wake up a host PC (such
; * as if it is in a low power suspend to RAM state).
; * This can be a very useful feature in some
; * USB applications, such as an Infrared remote
; * control receiver. If a user presses the "power"
; * button on a remote control, it is nice that the
; * IR receiver can detect this signalling, and then
; * send a USB "command" to the PC to wake up.
; *
; * The USBCBSendResume() "callback" function is used
; * to send this special USB signalling which wakes
; * up the PC. This function may be called by
; * application firmware to wake up the PC. This
; * function should only be called when:
; *
; * 1. The USB driver used on the host PC supports
; * the remote wakeup capability.
; * 2. The USB configuration descriptor indicates
; * the device is remote wakeup capable in the
; * bmAttributes field.
; * 3. The USB host PC is currently sleeping,
; * and has previously sent your device a SET
; * FEATURE setup packet which "armed" the
; * remote wakeup capability.
; *
; * This callback should send a RESUME signal that
; * has the period of 1-15ms.
; *
; * Note: Interrupt vs. Polling
; * -Primary clock
; * -Secondary clock ***** MAKE NOTES ABOUT THIS *******
; * > Can switch to primary first by calling USBCBWakeFromSuspend()

; * The modifiable section in this routine should be changed
; * to meet the application needs. Current implementation
; * temporary blocks other functions from executing for a
; * period of 1-13 ms depending on the core frequency.
; *
; * According to USB 2.0 specification section 7.1.7.7,
; * "The remote wakeup device must hold the resume signaling
; * for at lest 1 ms but for no more than 15 ms."
; * The idea here is to use a delay counter loop, using a
; * common value that would work over a wide range of core
; * frequencies.
; * That value selected is 1800. See table below:
; * ================================================== ========
; * Core Freq(MHz) MIP RESUME Signal Period (ms)
; * ================================================== ========
; * 48 12 1.05
; * 4 1 12.6
; * ================================================== ========
; * * These timing could be incorrect when using code
; * optimization or extended instruction mode,
; * or when having other interrupts enabled.
; * Make sure to verify using the MPLAB SIM's Stopwatch
; * and verify the actual signal on an oscilloscope.
; ************************************************** *****************/
;void USBCBSendResume(void)
USBCBSendResume
;{
movlb high _USBMEMORYADDRESS ; Point to proper bank
; static WORD delay_count;

; USBResumeControl = 1; // Start RESUME signaling
bsf UCON, RESUME ; Start RESUME signaling

; delay_count = 1800U; // Set RESUME line for 1-13 ms
; do
; {
; delay_count--;
; }while(delay_count);
movlw 0x10 ; Set RESUME line for 1-13 ms
movwf FSR2H ; Using FSR2 as temp
clrf FSR2L
USBCBSendResumeLoop
decfsz FSR2L, F
bra USBCBSendResumeLoop
decfsz FSR2H, F
bra USBCBSendResumeLoop
; USBResumeControl = 0;
bcf UCON, RESUME
return
;}


;/** EOF hid.c ************************************************** ****/

Ioannis
- 6th April 2023, 08:31
The last post is in C, right?

How all the above work together with C in MCS and PBP compiler?

I still did not understood what your project does in regards with the interent. I see only a USB connection.
In any case seems you are brave enough!

Ioannis

HenrikOlsson
- 6th April 2023, 08:58
I suspect that the file was originally in C but has been ported to ASM (by MeLabs I guess (?)) and is part of the USB file package that PBP uses. The C code is left in there, but commented out, as reference to what is translated. Saitama has modified it to support composite device which is way cool!

I'd love to see a quick reference/tutorial on how to implement a composite device using this/these modified files.

Great job Saitama, not your typical first post(s) around here :-) :._applause:

Ioannis
- 6th April 2023, 10:06
As I am a real novice on USB things, I can only say wow and a big bravo to Saitama for this achivement.

If not proprietary, I 'd love to see the whole project. it would be a great tutorial case study.

Ioannis

Saitama
- 6th April 2023, 16:57
Thanks for cheering me up. I'm going to share the project so you can study it. Any questions or requirements I am at your service,
As a case of interest I was able to solve it with the analysis of Chat-GPT, this did not give me solutions since they do not exist on the network for microcode studio but I analyzed each piece of code and thus I was able to have a complete understanding of it. https://drive.google.com/drive/folders/1L6mlBUBDwrJXSIsC5iF3DnWQ8wakP1tY?usp=share_link
9352

(https://drive.google.com/drive/folders/1L6mlBUBDwrJXSIsC5iF3DnWQ8wakP1tY?usp=share_link)

Ioannis
- 6th April 2023, 20:30
Very nice board!

Ioannis