; Software License Agreement ; ; The software supplied herewith by Microchip Technology Incorporated (the "Company") ; for its PICmicro® Microcontroller is intended and supplied to you, the Company’s ; customer, for use solely and exclusively on Microchip PICmicro Microcontroller ; products. ; ; The software is owned by the Company and/or its supplier, and is protected under ; applicable copyright laws. All rights are reserved. Any use in violation of the ; foregoing restrictions may subject the user to criminal sanctions under applicable ; laws, as well as to civil liability for the breach of the terms and conditions of ; this license. ; ; THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES, WHETHER EXPRESS, ; IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF ; MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE ; COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR ; CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. ; ; ############################################################################### ; filename: USB_DEFS.INC ; Definitions used throughout the Chapter 9 code ; ; ############################################################################### ; ; Author: Dan Butler ; Company: Microchip Technology Inc ; ; Revision: 1.10 ; Date: 07-December-2000 ; Assembled using MPASM 2.30.07 ; ;################################################################################ ; ; include files: ; none ; ;################################################################################ ; Edit these as appropriate for your descriptors #define NUM_CONFIGURATIONS 1 ; Define the states that the USB interface can be in #define POWERED_STATE 0x00 #define DEFAULT_STATE 0x01 #define ADDRESS_STATE 0x02 #define CONFIG_STATE 0x03 ; Define the states for Control EndPoints #define EP_IDLE_STATE 0x00 #define EP_SETUP_STATE 0x01 #define EP_DISABLED_STATE 0xff #define ENDPT_DISABLED 0x00 #define ENDPT_IN_ONLY 0x01 #define ENDPT_OUT_ONLY 0x02 #define ENDPT_CONTROL 0x06 ; enable for in, out and setup #define ENDPT_NON_CONTROL 0x0E ; enable for in, and out #define INT_STAT_MASK_RESET 0x01 #define INT_STAT_MASK_ERROR 0x02 #define INT_STAT_MASK_TOKEN_DONE 0x04 #define INT_STAT_MASK_SLEEP 0x08 #define INT_STAT_MASK_STALL 0x10 #define TOKEN_OUT (0x01<<2) #define TOKEN_ACK (0x02<<2) #define TOKEN_IN (0x09<<2) #define TOKEN_SETUP (0x0D<<2) #define USB_Buffer 0xB8 ; on page 3 so actual address 0x1B8 ; offsets from the beginning of the Buffer Descriptor #define BYTECOUNT 0x01 #define ADDRESS 0x02 ; Descriptor types #define DEVICE 1 #define CONFIGURATION 2 #define STRING 3 #define INTERFACE 4 #define ENDPOINT 5 ; offsets from the beginning of the setup data record #define bmRequestType 0x00 #define bRequest 0x01 #define wValue 0x02 #define wValueHigh 0x03 #define wIndex 0x04 #define wIndexHigh 0x05 #define wLength 0x06 #define wLengthHigh 0x07 #define CLEAR_FEATURE 0x01 #define GET_CONFIGURATION 0x08 #define GET_DESCRIPTOR 0x06 #define GET_STRING_DESCRIPTOR 0x66 #define GET_INTERFACE 0x0A #define GET_STATUS 0x00 #define SET_ADDRESS 0x05 #define SET_CONFIGURATION 0x09 #define SET_FEATURE 0x03 #define SET_INTERFACE 0x0B #define VEND_SET_MEMORY 0x80 #define SVCUSBINT 0x01 << 2 #define SVCTOKENDONE 0x02 << 2 #define SVCRESET 0x03 << 2 #define SVCSLEEP 0x04 << 2 #define SVCSTALL 0x05 << 2 #define SVCERROR 0x06 << 2 #define SVCACTIVITY 0x07 << 2 #define TOKENOUT 0x08 << 2 #define TOKENIN 0x09 << 2 #define TOKENSETUP 0x0A << 2 #define CLEARFEATURE 0x0B << 2 #define GETCONFIG 0x0C << 2 #define GETDESCRIPTOR 0x0D << 2 #define GETINTERFACE 0x0E << 2 #define GETSTATUS 0x0F << 2 #define SETADDRESS 0x10 << 2 #define SETCONFIG 0x11 << 2 #define SETFEATURE 0x12 << 2 #define SETINTERFACE 0x13 << 2 #define FINISHSETADDRESS 0x14 << 2 #define COPYDESC2EP0 0x15 << 2 #define COPYSTRINGDESC2EP0 0x16 << 2 #define ZEROLENPACKET 0x17 << 2 ; assumes we start and end in bank 2 COPYBUFFERDESCRIPTOR macro bsf STATUS,IRP ; indirectly to pages 2/3 bsf STATUS,RP0 ; direct to page 3 movf USTAT,w ; get the status register addlw 0xA0 ; add the offset to the beginning of the BD's movwf FSR ; save in the FSR. movf INDF,w movwf BufferDescriptor ; in shared RAM incf FSR,f movf INDF,w movwf BufferDescriptor+1 incf FSR,f movf INDF,w movwf BufferDescriptor+2 bcf STATUS,RP0 ; back to page 2 endm ; Increments a 16bit counter, stored Lowbyte:Highbyte INCREMENT16 macro index local endinc16 incfsz index,f goto endinc16 incf index+1,f endinc16 endm REQUESTERROR macro bsf STATUS,RP0 ; page 3 movf USTAT,w ; get the status register addlw 0xA0 ; add the offset to the beginning of the BD's movwf FSR bsf INDF,EP_STALL ; set endpoint stall bit bcf STATUS,RP0 ; back to page 2 endm ; ********************************************************************* ; wait here until the enumeration process is complete. ; This is implemented as a macro to avoid chewing up another stack level ; ********************************************************************* ConfiguredUSB macro banksel USWSTAT enumloop clrwdt ; Pet the dog movlw 0x03 andwf USWSTAT,w ; save lower 2 bits of USWSTAT xorlw CONFIG_STATE ; compare with configured state btfss STATUS,Z ; are we configured? goto enumloop ; nope, keep waiting ... clrf STATUS ; back to bank 0, we're configured, let things roll endm