Easy HID Command -Response application


Results 1 to 26 of 26

Threaded View

  1. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Default

    If there's anyone that knows about USB ... She's the one.
    I've never tried "feature reports" before, I'll have to look into that.

    But this might help with the USB interrupt part.
    It's an include file that services the USB via the USB interrupt.
    It works with programs derived from EasyHID or straight PBP with custom HID descriptors.
    I'm hoping it works with HIDmaker programs too.

    It also gives indications of when the device is connected to the PC, when a report has been received and when it's OK to transmit using the BIT variables ...

    Plugged indicates when the device is fully connected to the PC.
    RX_READY indicates when a report has been received.
    TX_READY indicates when it's OK to Send. The device is Plugged and the SIE is ready to accept data.

    It does everything required to handle the interrupts.
    All you have to do is INCLUDE the file.

    Well, you'll also need to comment out any USBSERVICE and USBINIT statements that may already be in your program, because they will conflict with the interrupt servicing.

    If you want to use other High Priority interrupts in your program, that can be done too. See INT_HOOK below.
    Low priority interrupts are still available.

    Code:
    '***************************************************************************
    '*  Name    : USB_ASM_Service.pbp                                          *
    '*  Author  : Darrel Taylor                                                *
    '*  Date    : 9/10/2009                                                    *
    '*  Version : 1.1                                                          *
    '*  Notes  1. DO NOT place ANY USBSERVICE or USBINIT statements ANYWHERE   *
    '*            in your program. They will conflict with interrupt Servicing *
    '*         2. To use other high priority interrupts you can add the define *
    '*            DEFINE  INT_HOOK  handlers                                   *
    '*            handlers will be called on each high priority interrupt      *
    '*            The handlers must be ASM Interrupt compatible                *
    '***************************************************************************
    DEFINE INTHAND _DoUSBSERVICE
    
    GIE                VAR INTCON.7      ; Global Interrupt Enable
    PEIE               VAR INTCON.6      ; Peripheral Interrupt Enable
    USBIE              VAR PIE2.5        ; USB funnel Interrupt Enable
    USBIF              VAR PIR2.5        ; USB Interrupt Flag
    IDLEIF             VAR UIR.4         ; USB Idle Interrupt Flag
    SOFIF              VAR UIR.6         ; USB Start Of Frame Flag
    SOFIE              VAR UIE.6         ; USB Start Of Frame Interrupt Enable
    USB_Flags          VAR BYTE BANK0
      Plugged          VAR USB_Flags.0   ; indicates Fully connected to PC
      RX_READY         VAR USB_Flags.1   ; indicates Report has been received
      TX_READY         VAR USB_Flags.2   ; indicates it's OK to Send
    CONFIGURED_STATE   CON EXT           ; state when PIC is connected to PC
    BD1STATOUT         VAR BYTE EXT      ; OUT report status byte
    BD1STATIN          VAR BYTE EXT      ; IN report status byte
    USBDeviceState     VAR BYTE EXT      ; USB drivers current State
    RXOWNED            VAR BD1STATOUT.7  ; Out report Owned (OUT is PC to PIC)
    TXOWNED            VAR BD1STATIN.7   ;  IN report Owned (IN is PIC to PC)
    
    ;----[Make it compatible with PBP versions previous to 2.60]----------------
    ASM
      ifndef _USBMEMORYADDRESS           ; only PBP 2.60+ has USBMEMORYADDRESS 
    _USBMEMORYADDRESS = 400h             ; fake it for 2.50-
      endif
    BD1STATOUT = _USBMEMORYADDRESS + 8   ; 408h or 208h
    BD1STATIN  = _USBMEMORYADDRESS + 0Ch ; 40Ch or 20Ch
    
      ifndef USBDeviceState              ; 2.60+ uses USBDeviceState
        ifdef usb_device_state           ; 2.50- uses usb_device_state
    USBDeviceState = usb_device_state
        else
          error "USBDeviceState not found" ; somethings not right if we get here
        endif 
      endif
    ENDASM
    
    ;----[Initialise USB and Interrupts]----------------------------------------
        PAUSE 100                    ; Allow VUSB to stabilize
        USBINIT                      ; initialize the USB driver
        USBSERVICE                   ; service it once
        UIE = $7F                    ; enable USB interrupts
        UEIE = $9F                   ; enable USB Error interrupts
        USBIE = 1                    ; enable USB funnel int
        PEIE = 1                     ; enable peripheral ints
        GIE = 1                      ; enable global ints
        USB_Flags = 0                ; clear the flags
    GOTO OverUSBservice              ; jump over the subroutines
    
    ;----[Interrupt handler -- Service USB]-------------------------------------
    DoUSBSERVICE:
      IF USBIE THEN
        IF USBIF THEN
          BSR = 0                      ; Make sure we're in BANK0
          IF IDLEIF THEN Plugged = 0   ; If the bus is Idle, we can't be Plugged
          IF SOFIF  THEN               ; On Start-Of-Frame
            IF (USBDeviceState = CONFIGURED_STATE) THEN ; Check for CONFIGURED
                Plugged = 1          ; if so, we're Plugged
            ENDIF
          ENDIF
          USBSERVICE                   ; Run the SERVICE routines
          USBIF = 0                    ; clear the USB flag
          IF !Plugged THEN UEIR = 0    ; prevents lock-ups when not terminated
                                         ;  from bit-stuff error
          RX_READY = !RXOWNED          ; indicate if report has been Received
          IF Plugged THEN
            TX_READY = !TXOWNED      ; indicate if ready to Send
          ELSE
            TX_READY = 0             ; don't try to send when not Plugged
          ENDIF
        ENDIF
      ENDIF
      
      ASM
        ifdef INT_HOOK
          L?CALL  INT_HOOK           ; call User Handlers if INT_HOOK is Defined
        endif                        ; User routines must be ASM INT compatible
        retfie 1                     ; Return from interrupt "Fast" with shadows
      ENDASM
    
    OverUSBservice:
    ADDED:
    I've added a define that let's you easliy use more high priority interrupts ...
    Code:
    DEFINE  INT_HOOK  _MyInts
    If defined, the MyInts: routine will be called on each high priority interrupt.
    It should end with a RETURN

    HTH,
    Attached Files Attached Files
    Last edited by Darrel Taylor; - 11th September 2009 at 05:50. Reason: Added some comments to make more sense. Added INT_HOOK define.

Similar Threads

  1. USB hid maker help please.
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd April 2013, 14:49
  2. i cant get 18f2550 work as HID
    By Ahmadabuomar in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 13th October 2009, 16:39
  3. Unusual Interrupts Application Problem
    By Joe Rocci in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 8th May 2009, 11:55
  4. Hid Maker FS Problems
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 24th April 2009, 21:27
  5. Making your own HID descriptor file
    By NL2TTL in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 27th April 2005, 12:35

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts