JOYSTIK 8 AXIS 12 BUTTON + HAT and COMPLETE DOCUMENTATION

General discussion on mikroBasic PRO for PIC.
Post Reply
Author
Message
S59KB
Posts: 46
Joined: 17 Apr 2010 15:48
Location: CELJE
Contact:

JOYSTIK 8 AXIS 12 BUTTON + HAT and COMPLETE DOCUMENTATION

#1 Post by S59KB » 26 Jan 2013 14:46

* Program name: JOYSTIK_BY_BOKI S59KB 8 BIT

* Copyright:
S59KB
Thank microelectronics, 2013

* Revision History:
20130126:

* Description:

This is a simple demonstration of 8 Axis, 12 Buttons and Hat Joystick Controller
Possibility of adjusting OFFSET potentiometer USING REFERENCES VREF+ and VREF-
Due to the angle of the potentiometer.
There are opportunities to expand the matrix of buttons
Program to use USB_HID_desc

* Test configuration:
No drivers needed
Tested on WIN_98 operating systems,
Tested on WIN_XP 32_BIT operating systems,
Tested on WIN_XP 64_BIT operating systems,
Tested on WIN_7 32_BIT operating systems,
Tested on WIN_7 64_BIT operating systems,
Not tested on WIN_8 operating systems.

MCU: P18F2550 or any other USB Pic
Dev.Board: EasyPIC5 or any other.
Oscillator: 4.0000 MHz
SW: mikroBasic Pro v 3.2

You can download it
http://www.libstock.com/projects/view/5 ... button-hat

Image

Image

Image

Testing program JOYSTICK

Image

PROGRAM FOR TILES Sprint Layout50

Image

FRONT PAGE

Image

last page

Image

8 BIT VERSION

Code: Select all

'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
''
'' * Program name: JOYSTIC_BY_BOKI S59KB
''
'' * Copyright:
''     S59KB
''     Thank microelectronics, 2013
''
'' * Revision History:
''     20130126:
''
'' * Description:
''
''     This is a simple demonstration of 8 Axis, 12 Buttons and Hat Joystick Controller
''     Possibility of adjusting OFFSET potentiometer USING REFERENCES VREF+ and VREF-
''     Due to the angle of the potentiometer.
''     There are opportunities to expand the matrix of buttons
''     Program to use USB_HID_desc
''
'' * Test configuration:
''     No drivers needed
''     Tested on WIN_98 operating systems,
''     Tested on WIN_XP 32_BIT operating systems,
''     Tested on WIN_XP 64_BIT operating systems,
''     Tested on WIN_7 32_BIT operating systems,
''     Tested on WIN_7 64_BIT operating systems,
''     Not tested on WIN_8 operating systems.
''
''     MCU:             P18F2550 or any other USB Pic
''     Dev.Board:       EasyPIC5 or any other.
''     Oscillator:      4.0000 MHz
''     SW:              mikroBasic Pro v 3.2
''
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
   program JOYSTIC_BY_BOKI
   include USB_HID_desc
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
'  Tested on 18F2550 @ 4 MHz....8 Axis, 12 Buttons and Hat Joystick Controller
'                      ______   _____
'                     (     (__)     )
'  COLUMN 4     RE3 O (1           28) O RB7
'                     (              )
'  X AXIS   RA0/AN0 O (2           27) O RB6       ROWS 3
'                     (              )
'  Y AXIS   RA1/AN1 O (3           26) O RB5
'                     (              )
'  VREF -   RA2/AN2 O (4           25) O RB4/AN11  SLIDER AXIS
'                     (              )
'  VREF +   RA3/AN3 O (5           24) O RB3/AN9   RY AXIS
'                     (              )
'  ROWS 4       RA4 O (6           23) O RB2/AN8   RX AXIS
'                     (              )
'  Z AXIS   RA5/AN4 O (7           22) O RB1/AN10  RZ AXIS
'                     (              )
'  - 5 V        VSS O (8           21) O RB0/AN12  DIAL AXIS
'                     (              )
'               OSC O (9           20) O VDD       + 5 V
'               4 MHZ (              )
'               OSC O (10          19) O VSS       - 5 V
'                     (              )
'  COLUMN 1     RCO O (11          18) O RC7       ROWS 2
'                     (              )
'  COLUMN 2     RC1 O (12          17) O RC6       ROWS 1
'                     (              )
'  COLUMN 3     RC2 O (13          16) O D++
'                     (              )   USB
'               USB O (14          15) O D--
'                     (______________)
'*******************************************************************************
'                USB Data Map BYTE
'    |----|----|----|----|----|----|----|----|
' 0  |                   X                   |
'    |----|----|----|----|----|----|----|----|
' 1  |                   Y                   |
'    |----|----|----|----|----|----|----|----|
' 2  |                   Z                   |
'    |----|----|----|----|----|----|----|----|
' 3  |                   RX                  |
'    |----|----|----|----|----|----|----|----|
' 4  |                   RY                   |
'    |----|----|----|----|----|----|----|----|
' 5  |                   RZ                  |
'    |----|----|----|----|----|----|----|----|
' 6  |                  DIAL                 |
'    |----|----|----|----|----|----|----|----|
' 7  |                 SLIDER                |
'    |----|----|----|----|----|----|----|----|
' 8  |HATA|HATB|HATC|HATD|SW1 |SW2 |SW3 |SW4 |
'    |----|----|----|----|----|----|----|----|
' 9  |SW5 |SW6 |SW7 |SW8 |SW9 |SW10|SW11|SW12|
'    |----|----|----|----|----|----|----|----|
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
DIM   BR AS BYTE
DIM   BUTT AS BYTE[5]
DIM   NEGACIJA AS BYTE
DIM   BUTTONS as BYTE[4]
DIM   userWR_buffer as BYTE[64]
DIM   userRD_buffer as BYTE[64]
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
sub procedure interrupt   ' Main Interrupt Routine
    HID_InterruptProc
end sub
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
sub procedure Init_Main   ' Initialization Routine
  '--------------------------------------
  ' Disable interrupts
  '--------------------------------------
  INTCON = 0              ' Disable GIE, PEIE, TMR0IE,INT0IE, RBIE
  INTCON2 = 0x75          ' Turn on PORTB pull-ups
  INTCON3 = 0xC0
  RCON.IPEN = 0           ' Disable Priority Levels on interrupts
  PIE1 = 0  PIE2 = 0  PIR1 = 0  PIR2 = 0
  LATA = 0  LATB = 0  LATC = 0
'--------------------------------------
'  ADCON1 = ADCON1 or 0xF3  ' 0xF3 REFERENCA +/-
  ADCON0 = 0x01
  ADCON1 = 0x31      ' RA2, RA3  are joystick axis inputs REFERENCA
  ADCON2 = 0xBE
'--------------------------------------
' Switch Map TRIS bits:  1 = input, 0 = output
  TRISC.0 = 1  ' RC0 input  Columns 1 - with pullup
  TRISC.1 = 1  ' RC1 input  Columns 2 - with pullup
  TRISC.2 = 1  ' RC2 input  Columns 3 - with pullup
'  TRISE.3 = 1  ' RE2 input  Columns 4 - with pullup
  TRISC.6 = 0  ' RC6 output Rows 1
  TRISC.7 = 0  ' RC7 output Rows 2
  TRISA.4 = 0  ' RA4 output Rows 3
  TRISB.6 = 0  ' RB6 output Rows 4
end sub
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
main:                          ' Main Program Routine
  Init_Main()
  FOR BR = 0 TO 11
    userWR_buffer[BR] = 0x00   ' Initialize everything to 0
  NEXT BR
'----------------------------
  FOR BR = 0 TO 4
    BUTT[BR] = 0x00            ' Initialize everything to 0
  NEXT BR
  HID_Enable(@userRD_buffer, @userWR_buffer)
  Delay_ms(1000)
  Delay_ms(1000)
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
  while true
      PORTC.0 = 0 PORTC.1 = 0  PORTC.2 = 0  PORTE.0 = 0
' Scan switch lines
' Read key data into Hat and Buttons
'     Switch Map                  COL
'     ROW            1 - RC0     2 - RC1     3 - RC2     4 - RE4
'     RC6 - 1        0.0 = 1H    0.1 = 2H    0.2 = 3H    0.3 = 4H   HAT     1-4
'     RC7 - 2        0.4 = 1     0.5 = 2     0.6 = 3     0.7 = 4    BUTTONS 1-4
'     RA4 - 3        1.0 = 5     1.1 = 6     1.2 = 7     1.3 = 8    BUTTONS 5-8
'     RB6 - 4        1.4 = 9     1.5 = 10    1.6 = 11    1.7 = 12   BUTTONS 9-12
'-------------------------------------------------------------------------------
'  VARIJANTA 1 SA 4 POZICIJE OD 90°
'  Scan row RC6 = 0   Hat
      PORTA.4 = 1  PORTB.6 = 1 PORTC.6 = 0 PORTC.7 = 1
      BUTT[0] = 1 BUTT[1] = 1 BUTT[2] = 1  BUTT[3] = 1
      IF (PORTC.1 = 0) THEN BUTT[1] = 0 END IF  ' B
      IF (PORTC.2 = 0) THEN BUTT[2] = 0 END IF  ' C
      IF (PORTC.0 = 0) THEN BUTT[1] = 0 BUTT[2] = 0 END IF  ' D
      IF (PORTE.3 = 0) THEN BUTT[3] = 0 END IF  'A
      IF (PORTC.0 = 1) AND (PORTC.1 = 1) AND (PORTC.2 = 1) THEN NEGACIJA = 0 ELSE NEGACIJA = 1 END IF
      IF (BUTT[3] = 0) AND (NEGACIJA = 0) THEN NEGACIJA = 1 END IF
      BUTTONS[0].0 = BUTT[0]
      BUTTONS[0].1 = BUTT[1]
      BUTTONS[0].2 = BUTT[2]
      BUTTONS[0].3 = NEGACIJA
'---------------------------
'  VARIJANTA 2 SA 8 POZICIJA OD 45°
'  Scan row RC6 = 0   Hat
'      PORTA.4 = 1 PORTB.6 = 1 PORTC.6 = 0 PORTC.7 = 1
'      BUTTONS[0].0 = PORTC.0
'      BUTTONS[0].1 = PORTC.1
'      BUTTONS[0].2 = PORTC.2
'      IF (PORTC.0 = 1) AND (PORTC.1 = 1) AND (PORTC.2 = 1) THEN NEGACIJA = 0 ELSE NEGACIJA = 1 END IF
'      IF (PORTE.3 = 0) AND (NEGACIJA = 0) THEN NEGACIJA = 1 END IF
'      BUTTONS[0].3 = NEGACIJA
'---------------------------
' Scan row RC7 = 0   Buttons
      PORTA.4 = 1 PORTB.6 = 1 PORTC.6 = 1 PORTC.7 = 0
      BUTTONS[0].4 = PORTC.0
      BUTTONS[0].5 = PORTC.1
      BUTTONS[0].6 = PORTC.2
      BUTTONS[0].7 = PORTE.3
'---------------------------
' Scan row RA4 = 0   Buttons
      PORTA.4 = 0 PORTB.6 = 1 PORTC.6 = 1 PORTC.7 = 1
      BUTTONS[1].0 = PORTC.0
      BUTTONS[1].1 = PORTC.1
      BUTTONS[1].2 = PORTC.2
      BUTTONS[1].3 = PORTE.3
'---------------------------
' Scan row RB6 = 0   Buttons
      PORTA.4 = 1 PORTB.6 = 0 PORTC.6 = 1 PORTC.7 = 1
      BUTTONS[1].4 = PORTC.0
      BUTTONS[1].5 = PORTC.1
      BUTTONS[1].6 = PORTC.2
      BUTTONS[1].7 = PORTE.3
      PORTA.4 = 1 PORTB.6 = 1 PORTC.6 = 1 PORTC.7 = 1
  '---------------------------------------------------------
  ' SELEKTOVANJE RADNIH I MIRNIH BUTTONA
      FOR BR = 0 TO 2
          buttons[BR]= NOT buttons[BR]
      NEXT BR
  '---------------------------------------------------------
  ' Read axis  inputs and userWR 8 BYTE
         userWR_buffer[0] = adc_read(10)>>2  ' Read RZ
         userWR_buffer[1] = adc_read(0)>>2   ' Read X
         userWR_buffer[2] = adc_read(1)>>2   ' Read Y
         userWR_buffer[3] = adc_read(4)>>2   ' Read Z
         userWR_buffer[4] = adc_read(8)>>2   ' Read RX
         userWR_buffer[5] = adc_read(9)>>2   ' Read RY
         userWR_buffer[6] = adc_read(12)>>2  ' Read DIAL
         userWR_buffer[7] = adc_read(11)>>2  ' Read SLIDER
'-----------------------------------------------------------
' Read BUTTONS  inputs and HAT  2 BYTE
         userWR_buffer[8] = BUTTONS[0]      ' HAT and buttons 1, 2, 3, 4
         userWR_buffer[9] = BUTTONS[1]      ' buttons 5, 6, 7, 8, 9, 10, 11, 12
'-----------------------------------------------------------
         HID_Write(@userWR_buffer, 10)
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
  wend
  HID_Disable()
end.
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
Image

8 BIT VERSION

Code: Select all

module USB_HID_desc
' uses HIDconstant;
'  File Version 2.0
'******************************************************************************
 const Serial_No = "22062005"
'******************************************************************************
' The number of bytes in each report,
' calculated from Report Size and Report Count in the report descriptor
'******************************************************************************
 const HID_INPUT_REPORT_BYTES      = 64
 const HID_OUTPUT_REPORT_BYTES     = 64
 const HID_FEATURE_REPORT_BYTES    = 2
'******************************************************************************
' Byte constants
'******************************************************************************
 const NUM_ENDPOINTS               = 2
 const ConfigDescr_wTotalLength    = USB_CONFIG_DESCRIPTOR_LEN + USB_INTERF_DESCRIPTOR_LEN + USB_HID_DESCRIPTOR_LEN + (NUM_ENDPOINTS * USB_ENDP_DESCRIPTOR_LEN)
 const HID_ReportDesc_len          = 115
 const Low_HID_ReportDesc_len      = HID_ReportDesc_len
 const High_HID_ReportDesc_len     = HID_ReportDesc_len >> 8
 const Low_HID_PACKET_SIZE         = HID_PACKET_SIZE
 const High_HID_PACKET_SIZE        = HID_PACKET_SIZE >> 8
'******************************************************************************
' Descriptor Tables
'******************************************************************************
' const DescTables as byte[USB_DEVICE_DESCRIPTOR_ALL_LEN*2] = (
 const DescTables as byte[(18+9+9+9+7+7+115)*2] = (
' Device Descriptor
    USB_DEVICE_DESCRIPTOR_LEN, 0,           ' bLength               - Length of Device descriptor (always 0x12)
    USB_DEVICE_DESCRIPTOR_TYPE, 0,          ' bDescriptorType       - 1 = DEVICE descriptor
    0x00, 0,                                ' bcdUSB                - USB revision 2.00 (low byte)
    0x02, 0,                                '                                           (high byte)
    0x00, 0,                                ' bDeviceClass          - Zero means each interface operates independently (class code in the interface descriptor)
    0x00, 0,                                ' bDeviceSubClass
    0x00, 0,                                ' bDeviceProtocol
    EP0_PACKET_SIZE, 0,                     ' bMaxPacketSize0       - maximum size of a data packet for a control transfer over EP0
    0x01, 0,                                ' idVendor              - Vendor  ID (low byte)
    0x28, 0,                                '                                    (high byte)
    0x13, 0,                                ' idProduct             - Product ID (low byte)
    0x20, 0,                                '                                    (high byte)
    0x21, 0,                                ' bcdDevice             - (low byte)
    0x01, 0,                                '                         (high byte)
    0x01, 0,                                ' iManufacturer         - String1
    0x02, 0,                                ' iProduct              - String2
    0x03, 0,                                ' iSerialNumber         - String3
    0x01, 0,                                ' bNumConfigurations    - 1
'------------------------------------------------------------------------------
' Configuration Descriptor
    USB_CONFIG_DESCRIPTOR_LEN, 0,           ' bLength               - Length of Configuration descriptor (always 0x09)
    USB_CONFIG_DESCRIPTOR_TYPE, 0,          ' bDescriptorType       - 2 = CONFIGURATION descriptor
    ConfigDescr_wTotalLength, 0,            ' wTotalLength          - Total length of this config. descriptor plus the interface and endpoint descriptors that are part of the configuration.
    0x00, 0,                                '                         (high byte)
    0x01, 0,                                ' bNumInterfaces        - Number of interfaces
    0x01, 0,                                ' bConfigurationValue   - Configuration Value
    0x00, 0,                                ' iConfiguration        - String Index for this configuration ( None )
    0xA0, 0,                                ' bmAttributes          - attributes - "Bus powered" and "Remote wakeup"
    50, 0,                                  ' MaxPower              - bus-powered draws 50*2 mA from the bus.
'------------------------------------------------------------------------------
' Interface Descriptor
    USB_INTERF_DESCRIPTOR_LEN, 0,           ' bLength               - Length of Interface descriptor (always 0x09)
    USB_INTERFACE_DESCRIPTOR_TYPE, 0,       ' bDescriptorType       - 4 = INTERFACE descriptor
    0x00, 0,                                ' bInterfaceNumber      - Number of interface, 0 based array
    0x00, 0,                                ' bAlternateSetting     - Alternate setting
    NUM_ENDPOINTS, 0,                       ' bNumEndPoints         - Number of endpoints used in this interface
    0x03, 0,                                ' bInterfaceClass       - assigned by the USB
    0x00, 0,                                ' bInterfaceSubClass    - Not A boot device
    0x00, 0,                                ' bInterfaceProtocol    - none
    0x00, 0,                                ' iInterface            - Index to string descriptor that describes this interface ( None )
'------------------------------------------------------------------------------
' HID Descriptor
    USB_HID_DESCRIPTOR_LEN, 0,              ' bLength               - Length of HID descriptor (always 0x09)
    USB_HID_DESCRIPTOR_TYPE, 0,             ' bDescriptorType       - 0x21 = HID descriptor
    0x01, 0,                                ' HID class release number (1.01)
    0x01, 0,
    0x00, 0,                                ' Localized country code (none)
    0x01, 0,                                ' # of HID class descriptor to follow (1)
    0x22, 0,                                ' Report descriptor type (HID)
    Low_HID_ReportDesc_len, 0,
    High_HID_ReportDesc_len, 0,
'------------------------------------------------------------------------------
' EP1_RX Descriptor
    USB_ENDP_DESCRIPTOR_LEN, 0,             ' bLength               - length of descriptor (always 0x07)
    USB_ENDPOINT_DESCRIPTOR_TYPE, 0,        ' bDescriptorType       - 5 = ENDPOINT descriptor
    0x81, 0,                                ' bEndpointAddress      - In, EP1
    USB_ENDPOINT_TYPE_INTERRUPT, 0,         ' bmAttributes          - Endpoint Type - Interrupt
    Low_HID_PACKET_SIZE, 0,                 ' wMaxPacketSize        - max packet size - low order byte
    High_HID_PACKET_SIZE, 0,                '                       - max packet size - high order byte
    1, 0,                                   ' bInterval             - polling interval (1 ms)
'------------------------------------------------------------------------------
' EP1_TX Descriptor
    USB_ENDP_DESCRIPTOR_LEN, 0,             ' bLength               - length of descriptor (always 0x07)
    USB_ENDPOINT_DESCRIPTOR_TYPE, 0,        ' bDescriptorType       - 5 = ENDPOINT descriptor
    0x01, 0,                                ' bEndpointAddress      - Out, EP1
    USB_ENDPOINT_TYPE_INTERRUPT, 0,         ' bmAttributes          - Endpoint Type - Interrupt
    Low_HID_PACKET_SIZE, 0,                 ' wMaxPacketSize        - max packet size - low order byte
    High_HID_PACKET_SIZE, 0,                '                       - max packet size - high order byte
    1, 0,                                   ' bInterval             - polling interval (1 ms)
'------------------------------------------------------------------------------
' HID_Report Descriptor
' USB Data Map
'------------------------------------------------------------------------------
0x05, 0, 0x01, 0,    ' USAGE_PAGE (Generic Desktop)
0x15, 0, 0x00, 0,    ' LOGICAL_MINIMUM (0)
0x09, 0, 0x04, 0,    ' USAGE (Joystick)
0xa1, 0, 0x01, 0,    ' COLLECTION (Application)
 '------------------------------------------------------------------------------
' 1 BYTE  DATA ZA RZ OSU
0x05, 0, 0x01, 0,    ' USAGE_PAGE (Generic Desktop)
0x09, 0, 0x35, 0,    ' USAGE (RZ)
0x15, 0, 0x00, 0,    ' LOGICAL_MINIMUM (0)
0x26, 0, 0xff, 0,
0x00, 0,             ' LOGICAL_MAXIMUM (255)
0x75, 0, 0x08, 0,    ' REPORT_SIZE (8)
0x95, 0, 0x01, 0,    ' REPORT_COUNT (1)
0x81, 0, 0x02, 0,    ' INPUT (Data,Var,Abs)
'------------------------------------------------------------------------------
' 2,3,4,5,6 BYTE  DATA ZA X, Y, Z, RX, RY OSU
0x05, 0, 0x01, 0,    ' USAGE_PAGE (Generic Desktop)
0x15, 0, 0x00, 0,    ' LOGICAL_MINIMUM (0)
0x26, 0,
0xff, 0, 0x00, 0,    ' LOGICAL_MAXIMUM (255)
0xa1, 0, 0x00, 0,    ' COLLECTION (Physical)
0x09, 0, 0x30, 0,    ' USAGE (X)
0x09, 0, 0x31, 0,    ' USAGE (Y)
0x09, 0, 0x32, 0,    ' USAGE (Z)
0x09, 0, 0x33, 0,    ' USAGE (RX)
0x09, 0, 0x34, 0,    ' USAGE (RY)
0x95, 0, 0x05, 0,    ' REPORT_COUNT (5)
0x81, 0, 0x02, 0,    ' INPUT (Data,Var,Abs)
 '------------------------------------------------------------------------------
' 7 BYTE  DATA ZA Dial POZICIJU
0x05, 0, 0x01, 0,     ' USAGE_PAGE (Generic Desktop)
0x09, 0, 0x36, 0,     ' USAGE (Dial)
0x15, 0, 0x00, 0,     ' LOGICAL_MINIMUM (0)
0x26, 0, 0xFF, 0,
0x00, 0,              ' LOGICAL_MAXIMUM (255)
0x75, 0, 0x08, 0,     ' REPORT_SIZE (8)
0x95, 0, 0x01, 0,     ' REPORT_COUNT (1)
0x81, 0, 0x02, 0,     ' INPUT (Data,Var,Abs)
'------------------------------------------------------------------------------
' 8 BYTE  DATA ZA Slider POZICIJU
0x05, 0, 0x01, 0,     ' USAGE_PAGE (Generic Desktop)
0x09, 0, 0x37, 0,     ' USAGE (Slider)
0x15, 0, 0x00, 0,     ' LOGICAL_MINIMUM (0)
0x26, 0, 0xFF, 0,
0x00, 0,              ' LOGICAL_MAXIMUM (255)
0x75, 0, 0x08, 0,     ' REPORT_SIZE (8)
0x95, 0, 0x01, 0,     ' REPORT_COUNT (1)
0x81, 0, 0x02, 0,     ' INPUT (Data,Var,Abs)
'------------------------------------------------------------------------------
' 9  1/2  BYTE  DATA ZA HAT POZICIJU i 2/2 BYTE ZA BUTTONS
0x05, 0, 0x01, 0,     ' USAGE_PAGE (Generic Desktop)
0x09, 0, 0x39, 0,     ' USAGE (Hat switch)
0x15, 0, 0x00, 0,     ' LOGICAL_MINIMUM (0)
0x25, 0, 0x07, 0,     ' LOGICAL_MAXIMUM (1)
0x35, 0, 0x00, 0,     ' PHYSICAL_MINIMUM (0)
0x46, 0, 0x68, 0,     '
0x01, 0,              ' PHYSICAL_MAXIMUM (360)
0x55, 0, 0x0F, 0,     ' UNIT (Eng Rot:Angular Pos)
0x75, 0, 0x04, 0,     ' REPORT_SIZE (4)
0x95, 0, 0x01, 0,     ' REPORT_COUNT (1)
0x81, 0, 0x02, 0,     ' INPUT (Data,Var,Abs)
'------------------------------------------------------------------------------
' 10  BYTE  DATA ZA Buttons POZICIJU
0x05, 0, 0x09, 0,     ' USAGE_PAGE (Buttons)
0x19, 0, 0x01, 0,     ' Usage Minimum
0x29, 0, 0x12, 0,     ' Usage Maximum
0x15, 0, 0x00, 0,     ' LOGICAL_MINIMUM (0)
0x25, 0, 0x01, 0,     ' LOGICAL_MAXIMUM (1)
0x75, 0, 0x01, 0,     ' REPORT_SIZE  (1)
0x95, 0, 0x0C, 0,     ' REPORT_COUNT (12)
0x81, 0, 0x02, 0,     ' INPUT (Data,Var,Abs)
'------------------------------------------------------------------------------
0xc0, 0,              ' END_COLLECTION
0xc0, 0               ' END_COLLECTION
)
'******************************************************************************
 const LangIDDescr as byte[8] = (
    0x04, 0,
    USB_STRING_DESCRIPTOR_TYPE, 0,
    0x09, 0,                                ' LangID (0x0409) - Low
    0x04, 0                                 '                 - High
)
'******************************************************************************
 const ManufacturerDescr as byte[28] = (
    14, 0,
    USB_STRING_DESCRIPTOR_TYPE, 0,
    "8", 0, 0, 0,
    "-", 0, 0, 0,
    "B", 0, 0, 0,
    "i", 0, 0, 0,
    "t", 0, 0, 0,
    "a", 0, 0, 0
)
'******************************************************************************
 const ProductDescr as byte[116] = (
    58, 0,
    USB_STRING_DESCRIPTOR_TYPE, 0,
    "U", 0, 0, 0,
    "S", 0, 0, 0,
    "B", 0, 0, 0,
    " ", 0, 0, 0,
    "J", 0, 0, 0,
    "O", 0, 0, 0,
    "Y", 0, 0, 0,
    "S", 0, 0, 0,
    "T", 0, 0, 0,
    "I", 0, 0, 0,
    "C", 0, 0, 0,
    " ", 0, 0, 0,
    "B", 0, 0, 0,
    "Y", 0, 0, 0,
    " ", 0, 0, 0,
    "S", 0, 0, 0,
    "5", 0, 0, 0,
    "9", 0, 0, 0,
    "K", 0, 0, 0,
    "B", 0, 0, 0,
    " ", 0, 0, 0,
    "V", 0, 0, 0,
    "E", 0, 0, 0,
    "R", 0, 0, 0,
    " ", 0, 0, 0,
    "2", 0, 0, 0,
    ".", 0, 0, 0,
    "0", 0, 0, 0
)
'******************************************************************************
 const StrUnknownDescr as byte[36] = (
    18, 0,
    USB_STRING_DESCRIPTOR_TYPE, 0,
    Serial_No[0], 0, 0, 0,
    Serial_No[1], 0, 0, 0,
    Serial_No[2], 0, 0, 0,
    Serial_No[3], 0, 0, 0,
    Serial_No[4], 0, 0, 0,
    Serial_No[5], 0, 0, 0,
    Serial_No[6], 0, 0, 0,
    Serial_No[7], 0, 0, 0
)
'******************************************************************************
implements

end.
10 BIT VERSION

Code: Select all

'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
''
'' * Program name: JOYSTIC_BY_BOKI S59KB  10 BIT AXIS
''
'' * Copyright:
''     S59KB
''     Thank microelectronics, 2013
''
'' * Revision History:
''     20130126:
''
'' * Description:
''
''     This is a simple demonstration of 8 Axis, 12 Buttons and Hat Joystick Controller
''     Possibility of adjusting OFFSET potentiometer USING REFERENCES VREF+ and VREF-
''     Due to the angle of the potentiometer.
''     There are opportunities to expand the matrix of buttons
''     Program to use USB_HID_desc
''
'' * Test configuration:
''     No drivers needed
''     Tested on WIN_98 operating systems,
''     Tested on WIN_XP 32_BIT operating systems,
''     Tested on WIN_XP 64_BIT operating systems,
''     Tested on WIN_7 32_BIT operating systems,
''     Tested on WIN_7 64_BIT operating systems,
''     Not tested on WIN_8 operating systems.
''
''     MCU:             P18F2550 or any other USB Pic
''     Dev.Board:       EasyPIC5 or any other.
''     Oscillator:      4.0000 MHz
''     SW:              mikroBasic Pro v 3.2
''
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
   program JOYSTIC_BY_BOKI
   include USB_HID_desc
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
'  Tested on 18F2550 @ 4 MHz....8 Axis, 12 Buttons and Hat Joystick Controller
'                      ______   _____
'                     (     (__)     )
'  COLUMN 4     RE3 O (1           28) O RB7
'                     (              )
'  X AXIS   RA0/AN0 O (2           27) O RB6       ROWS 3
'                     (              )
'  Y AXIS   RA1/AN1 O (3           26) O RB5
'                     (              )
'  VREF -   RA2/AN2 O (4           25) O RB4/AN11  SLIDER AXIS
'                     (              )
'  VREF +   RA3/AN3 O (5           24) O RB3/AN9   RY AXIS
'                     (              )
'  ROWS 4       RA4 O (6           23) O RB2/AN8   RX AXIS
'                     (              )
'  Z AXIS   RA5/AN4 O (7           22) O RB1/AN10  RZ AXIS
'                     (              )
'  - 5 V        VSS O (8           21) O RB0/AN12  DIAL AXIS
'                     (              )
'               OSC O (9           20) O VDD       + 5 V
'               4 MHZ (              )
'               OSC O (10          19) O VSS       - 5 V
'                     (              )
'  COLUMN 1     RCO O (11          18) O RC7       ROWS 2
'                     (              )
'  COLUMN 2     RC1 O (12          17) O RC6       ROWS 1
'                     (              )
'  COLUMN 3     RC2 O (13          16) O D++
'                     (              )   USB
'               USB O (14          15) O D--
'                     (______________)
'*******************************************************************************
'                USB Data Map BYTE
'       |----|----|----|----|----|----|----|----|
' 0,1   |                   X                   |
'       |----|----|----|----|----|----|----|----|
' 2,3   |                   Y                   |
'       |----|----|----|----|----|----|----|----|
' 4,5   |                   Z                   |
'       |----|----|----|----|----|----|----|----|
' 6,7   |                   RX                  |
'       |----|----|----|----|----|----|----|----|
' 8,9   |                   RY                  |
'       |----|----|----|----|----|----|----|----|
' 10,11 |                   RZ                  |
'       |----|----|----|----|----|----|----|----|
' 12,13 |                  DIAL                 |
'       |----|----|----|----|----|----|----|----|
' 14,15 |                 SLIDER                |
'       |----|----|----|----|----|----|----|----|
' 16    |HATA|HATB|HATC|HATD|SW1 |SW2 |SW3 |SW4 |
'       |----|----|----|----|----|----|----|----|
' 17    |SW5 |SW6 |SW7 |SW8 |SW9 |SW10|SW11|SW12|
'       |----|----|----|----|----|----|----|----|
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
DIM   BR AS BYTE
DIM   POT_BR AS BYTE
DIM   BUTT AS BYTE[5]
DIM   NEGACIJA AS BYTE
DIM   BUTTONS as BYTE[4]
DIM   userWR_buffer as BYTE[64]
DIM   userRD_buffer as BYTE[64]
DIM   POT AS WORD[9]
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
sub procedure interrupt   ' Main Interrupt Routine
    HID_InterruptProc
end sub
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
sub procedure Init_Main   ' Initialization Routine
  '--------------------------------------
  ' Disable interrupts
  '--------------------------------------
  INTCON = 0              ' Disable GIE, PEIE, TMR0IE,INT0IE, RBIE
  INTCON2 = 0x75          ' Turn on PORTB pull-ups
  INTCON3 = 0xC0
  RCON.IPEN = 0           ' Disable Priority Levels on interrupts
  PIE1 = 0  PIE2 = 0  PIR1 = 0  PIR2 = 0
  LATA = 0  LATB = 0  LATC = 0
'--------------------------------------
'  ADCON1 = ADCON1 or 0xF3  ' 0xF3 REFERENCA +/-
  ADCON0 = 0x01
  ADCON1 = 0x31      ' RA2, RA3  are joystick axis inputs REFERENCA
  ADCON2 = 0xBE
'--------------------------------------
' Switch Map TRIS bits:  1 = input, 0 = output
  TRISC.0 = 1  ' RC0 input  Columns 1 - with pullup
  TRISC.1 = 1  ' RC1 input  Columns 2 - with pullup
  TRISC.2 = 1  ' RC2 input  Columns 3 - with pullup
'  TRISE.3 = 1  ' RE2 input  Columns 4 - with pullup
  TRISC.6 = 0  ' RC6 output Rows 1
  TRISC.7 = 0  ' RC7 output Rows 2
  TRISA.4 = 0  ' RA4 output Rows 3
  TRISB.6 = 0  ' RB6 output Rows 4
end sub
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
main:                          ' Main Program Routine
  Init_Main()
  FOR BR = 0 TO 11
    userWR_buffer[BR] = 0x00   ' Initialize everything to 0
  NEXT BR
'----------------------------
  FOR BR = 0 TO 4
    BUTT[BR] = 0x00            ' Initialize everything to 0
  NEXT BR
  HID_Enable(@userRD_buffer, @userWR_buffer)
  Delay_ms(1000)
  Delay_ms(1000)
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
  while true
    '  PORTC.0 = 0 PORTC.1 = 0  PORTC.2 = 0  PORTE.0 = 0
' Scan switch lines
' Read key data into Hat and Buttons
'     Switch Map                  COL
'     ROW            1 - RC0     2 - RC1     3 - RC2     4 - RE4
'     RC6 - 1        0.0 = 1H    0.1 = 2H    0.2 = 3H    0.3 = 4H   HAT     1-4
'     RC7 - 2        0.4 = 1     0.5 = 2     0.6 = 3     0.7 = 4    BUTTONS 1-4
'     RA4 - 3        1.0 = 5     1.1 = 6     1.2 = 7     1.3 = 8    BUTTONS 5-8
'     RB6 - 4        1.4 = 9     1.5 = 10    1.6 = 11    1.7 = 12   BUTTONS 9-12
'-------------------------------------------------------------------------------
'  VARIJANTA 1 SA 4 POZICIJE OD 90°
'  Scan row RC6 = 0   Hat
      PORTA.4 = 1  PORTB.6 = 1 PORTC.6 = 0 PORTC.7 = 1
      BUTT[0] = 1 BUTT[1] = 1 BUTT[2] = 1  BUTT[3] = 1
      IF (PORTC.1 = 0) THEN BUTT[1] = 0 END IF  ' B
      IF (PORTC.2 = 0) THEN BUTT[2] = 0 END IF  ' C
      IF (PORTC.0 = 0) THEN BUTT[1] = 0 BUTT[2] = 0 END IF  ' D
      IF (PORTE.3 = 0) THEN BUTT[3] = 0 END IF  'A
      IF (PORTC.0 = 1) AND (PORTC.1 = 1) AND (PORTC.2 = 1) THEN NEGACIJA = 0 ELSE NEGACIJA = 1 END IF
      IF (BUTT[3] = 0) AND (NEGACIJA = 0) THEN NEGACIJA = 1 END IF
      BUTTONS[0].0 = BUTT[0]
      BUTTONS[0].1 = BUTT[1]
      BUTTONS[0].2 = BUTT[2]
      BUTTONS[0].3 = NEGACIJA
'---------------------------
'  VARIJANTA 2 SA 8 POZICIJA OD 45°
'  Scan row RC6 = 0   Hat
'      PORTA.4 = 1 PORTB.6 = 1 PORTC.6 = 0 PORTC.7 = 1
'      BUTTONS[0].0 = PORTC.0
'      BUTTONS[0].1 = PORTC.1
'      BUTTONS[0].2 = PORTC.2
'      IF (PORTC.0 = 1) AND (PORTC.1 = 1) AND (PORTC.2 = 1) THEN NEGACIJA = 0 ELSE NEGACIJA = 1 END IF
'      IF (PORTE.3 = 0) AND (NEGACIJA = 0) THEN NEGACIJA = 1 END IF
'      BUTTONS[0].3 = NEGACIJA
'---------------------------
' Scan row RC7 = 0   Buttons
      PORTA.4 = 1 PORTB.6 = 1 PORTC.6 = 1 PORTC.7 = 0
      BUTTONS[0].4 = PORTC.0
      BUTTONS[0].5 = PORTC.1
      BUTTONS[0].6 = PORTC.2
      BUTTONS[0].7 = PORTE.3
'---------------------------
' Scan row RA4 = 0   Buttons
      PORTA.4 = 0 PORTB.6 = 1 PORTC.6 = 1 PORTC.7 = 1
      BUTTONS[1].0 = PORTC.0
      BUTTONS[1].1 = PORTC.1
      BUTTONS[1].2 = PORTC.2
      BUTTONS[1].3 = PORTE.3
'---------------------------
' Scan row RB6 = 0   Buttons
      PORTA.4 = 1 PORTB.6 = 0 PORTC.6 = 1 PORTC.7 = 1
      BUTTONS[1].4 = PORTC.0
      BUTTONS[1].5 = PORTC.1
      BUTTONS[1].6 = PORTC.2
      BUTTONS[1].7 = PORTE.3
      PORTA.4 = 1 PORTB.6 = 1 PORTC.6 = 1 PORTC.7 = 1
  '---------------------------------------------------------
  ' SELEKTOVANJE RADNIH I MIRNIH BUTTONA
      FOR BR = 0 TO 2
          buttons[BR]= NOT buttons[BR]
      NEXT BR
  '---------------------------------------------------------
  ' Read axis  inputs and userWR 16 BYTE
         POT[1] = adc_read(10)
            userWR_buffer[0] = LO(POT[1])   ' Read RZ
            userWR_buffer[1] = HI(POT[1])
         POT[2] = adc_read(0)
            userWR_buffer[2] = LO(POT[2])   ' Read X
            userWR_buffer[3] = HI(POT[2])
         POT[3] = adc_read(1)
            userWR_buffer[4] = LO(POT[3])   ' Read Y
            userWR_buffer[5] = HI(POT[3])
         POT[4] = adc_read(4)
            userWR_buffer[6] = LO(POT[4])   ' Read Z
            userWR_buffer[7] = HI(POT[4])
         POT[5] = adc_read(8)
            userWR_buffer[8] = LO(POT[5])   ' Read RX
            userWR_buffer[9] = HI(POT[5])
         POT[6] = adc_read(9)
            userWR_buffer[10] = LO(POT[6])  ' Read RY
            userWR_buffer[11] = HI(POT[6])
         POT[7] = adc_read(12)
            userWR_buffer[12] = LO(POT[7])  ' Read DIAL
            userWR_buffer[13] = HI(POT[7])
         POT[8] = adc_read(11)
            userWR_buffer[14] = LO(POT[8])  ' Read SLIDER
            userWR_buffer[15] = HI(POT[8])
'-----------------------------------------------------------
' Read BUTTONS  inputs and HAT  2 BYTE
         userWR_buffer[16] = BUTTONS[0]      ' HAT and buttons 1, 2, 3, 4
         userWR_buffer[17] = BUTTONS[1]      ' buttons 5, 6, 7, 8, 9, 10, 11, 12
'-----------------------------------------------------------
         HID_Write(@userWR_buffer, 18)
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
  wend
  HID_Disable()
end.
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
10 BIT VERSION

Code: Select all

module USB_HID_desc
' uses HIDconstant;
'  File Version 2.0
'******************************************************************************
 const Serial_No = "22062005"
'******************************************************************************
' The number of bytes in each report,
' calculated from Report Size and Report Count in the report descriptor
'******************************************************************************
 const HID_INPUT_REPORT_BYTES      = 64
 const HID_OUTPUT_REPORT_BYTES     = 64
 const HID_FEATURE_REPORT_BYTES    = 2
'******************************************************************************
' Byte constants
'******************************************************************************
 const NUM_ENDPOINTS               = 2
 const ConfigDescr_wTotalLength    = USB_CONFIG_DESCRIPTOR_LEN + USB_INTERF_DESCRIPTOR_LEN + USB_HID_DESCRIPTOR_LEN + (NUM_ENDPOINTS * USB_ENDP_DESCRIPTOR_LEN)
' const HID_ReportDesc_len          = 115
 const HID_ReportDesc_len          = 78
 const Low_HID_ReportDesc_len      = HID_ReportDesc_len
 const High_HID_ReportDesc_len     = HID_ReportDesc_len >> 8
 const Low_HID_PACKET_SIZE         = HID_PACKET_SIZE
 const High_HID_PACKET_SIZE        = HID_PACKET_SIZE >> 8
'******************************************************************************
' Descriptor Tables
'******************************************************************************
' const DescTables as byte[USB_DEVICE_DESCRIPTOR_ALL_LEN*2] = (
' const DescTables as byte[(18+9+9+9+7+7+115)*2] = (
 const DescTables as byte[(18+9+9+9+7+7+78)*2] = (
' Device Descriptor
    USB_DEVICE_DESCRIPTOR_LEN, 0,           ' bLength               - Length of Device descriptor (always 0x12)
    USB_DEVICE_DESCRIPTOR_TYPE, 0,          ' bDescriptorType       - 1 = DEVICE descriptor
    0x00, 0,                                ' bcdUSB                - USB revision 2.00 (low byte)
    0x02, 0,                                '                                           (high byte)
    0x00, 0,                                ' bDeviceClass          - Zero means each interface operates independently (class code in the interface descriptor)
    0x00, 0,                                ' bDeviceSubClass
    0x00, 0,                                ' bDeviceProtocol
    EP0_PACKET_SIZE, 0,                     ' bMaxPacketSize0       - maximum size of a data packet for a control transfer over EP0
    0x02, 0,                                ' idVendor              - Vendor  ID (low byte)
    0x07, 0,                                '                                    (high byte)
    0x13, 0,                                ' idProduct             - Product ID (low byte)
    0x20, 0,                                '                                    (high byte)
    0x21, 0,                                ' bcdDevice             - (low byte)
    0x01, 0,                                '                         (high byte)
    0x01, 0,                                ' iManufacturer         - String1
    0x02, 0,                                ' iProduct              - String2
    0x03, 0,                                ' iSerialNumber         - String3
    0x01, 0,                                ' bNumConfigurations    - 1
'------------------------------------------------------------------------------
' Configuration Descriptor
    USB_CONFIG_DESCRIPTOR_LEN, 0,           ' bLength               - Length of Configuration descriptor (always 0x09)
    USB_CONFIG_DESCRIPTOR_TYPE, 0,          ' bDescriptorType       - 2 = CONFIGURATION descriptor
    ConfigDescr_wTotalLength, 0,            ' wTotalLength          - Total length of this config. descriptor plus the interface and endpoint descriptors that are part of the configuration.
    0x00, 0,                                '                         (high byte)
    0x01, 0,                                ' bNumInterfaces        - Number of interfaces
    0x01, 0,                                ' bConfigurationValue   - Configuration Value
    0x00, 0,                                ' iConfiguration        - String Index for this configuration ( None )
    0xA0, 0,                                ' bmAttributes          - attributes - "Bus powered" and "Remote wakeup"
    50, 0,                                  ' MaxPower              - bus-powered draws 50*2 mA from the bus.
'------------------------------------------------------------------------------
' Interface Descriptor
    USB_INTERF_DESCRIPTOR_LEN, 0,           ' bLength               - Length of Interface descriptor (always 0x09)
    USB_INTERFACE_DESCRIPTOR_TYPE, 0,       ' bDescriptorType       - 4 = INTERFACE descriptor
    0x00, 0,                                ' bInterfaceNumber      - Number of interface, 0 based array
    0x00, 0,                                ' bAlternateSetting     - Alternate setting
    NUM_ENDPOINTS, 0,                       ' bNumEndPoints         - Number of endpoints used in this interface
    0x03, 0,                                ' bInterfaceClass       - assigned by the USB
    0x00, 0,                                ' bInterfaceSubClass    - Not A boot device
    0x00, 0,                                ' bInterfaceProtocol    - none
    0x00, 0,                                ' iInterface            - Index to string descriptor that describes this interface ( None )
'------------------------------------------------------------------------------
' HID Descriptor
    USB_HID_DESCRIPTOR_LEN, 0,              ' bLength               - Length of HID descriptor (always 0x09)
    USB_HID_DESCRIPTOR_TYPE, 0,             ' bDescriptorType       - 0x21 = HID descriptor
    0x01, 0,                                ' HID class release number (1.01)
    0x01, 0,
    0x00, 0,                                ' Localized country code (none)
    0x01, 0,                                ' # of HID class descriptor to follow (1)
    0x22, 0,                                ' Report descriptor type (HID)
    Low_HID_ReportDesc_len, 0,
    High_HID_ReportDesc_len, 0,
'------------------------------------------------------------------------------
' EP1_RX Descriptor
    USB_ENDP_DESCRIPTOR_LEN, 0,             ' bLength               - length of descriptor (always 0x07)
    USB_ENDPOINT_DESCRIPTOR_TYPE, 0,        ' bDescriptorType       - 5 = ENDPOINT descriptor
    0x81, 0,                                ' bEndpointAddress      - In, EP1
    USB_ENDPOINT_TYPE_INTERRUPT, 0,         ' bmAttributes          - Endpoint Type - Interrupt
    Low_HID_PACKET_SIZE, 0,                 ' wMaxPacketSize        - max packet size - low order byte
    High_HID_PACKET_SIZE, 0,                '                       - max packet size - high order byte
    1, 0,                                   ' bInterval             - polling interval (1 ms)
'------------------------------------------------------------------------------
' EP1_TX Descriptor
    USB_ENDP_DESCRIPTOR_LEN, 0,             ' bLength               - length of descriptor (always 0x07)
    USB_ENDPOINT_DESCRIPTOR_TYPE, 0,        ' bDescriptorType       - 5 = ENDPOINT descriptor
    0x01, 0,                                ' bEndpointAddress      - Out, EP1
    USB_ENDPOINT_TYPE_INTERRUPT, 0,         ' bmAttributes          - Endpoint Type - Interrupt
    Low_HID_PACKET_SIZE, 0,                 ' wMaxPacketSize        - max packet size - low order byte
    High_HID_PACKET_SIZE, 0,                '                       - max packet size - high order byte
    1, 0,                                   ' bInterval             - polling interval (1 ms)
'------------------------------------------------------------------------------
' HID_Report Descriptor
' USB Data Map
'------------------------------------------------------------------------------
0x05, 0, 0x01, 0,    ' USAGE_PAGE (Generic Desktop)
0x15, 0, 0x00, 0,    ' LOGICAL_MINIMUM (0)
0x09, 0, 0x04, 0,    ' USAGE (Joystick)
0xa1, 0, 0x01, 0,    ' COLLECTION (Application)
'------------------------------------------------------------------------------
' 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 BYTE  DATA ZA X, Y, Z, RX, RY, RZ, Dial, Slider OSU
0x05, 0, 0x01, 0,    ' USAGE_PAGE (Generic Desktop)
0x15, 0, 0x00, 0,
0x26, 0,             ' LOGICAL_MINIMUM (0)
0xFF, 0, 0x03, 0,    ' LOGICAL_MAXIMUM (1024)
0x75, 0, 0x10, 0,    ' REPORT_SIZE (16)
0xa1, 0, 0x00, 0,    ' COLLECTION (Physical)
0x09, 0, 0x35, 0,    ' USAGE (RZ)
0x09, 0, 0x30, 0,    ' USAGE (X)
0x09, 0, 0x31, 0,    ' USAGE (Y)
0x09, 0, 0x32, 0,    ' USAGE (Z)
0x09, 0, 0x33, 0,    ' USAGE (RX)
0x09, 0, 0x34, 0,    ' USAGE (RY)
0x09, 0, 0x36, 0,    ' USAGE (Dial)
0x09, 0, 0x37, 0,    ' USAGE (Slider)
0x95, 0, 0x08, 0,    ' REPORT_COUNT (8)
0x81, 0, 0x02, 0,    ' INPUT (Data,Var,Abs)
0xc0, 0,             ' END_COLLECTION
'------------------------------------------------------------------------------
' 17 1/2  BYTE  DATA ZA HAT POZICIJU i 2/2 BYTE ZA BUTTONS
0x05, 0, 0x01, 0,     ' USAGE_PAGE (Generic Desktop)
0x09, 0, 0x39, 0,     ' USAGE (Hat switch)
0x15, 0, 0x00, 0,     ' LOGICAL_MINIMUM (0)
0x25, 0, 0x07, 0,     ' LOGICAL_MAXIMUM (1)
0x35, 0, 0x00, 0,     ' PHYSICAL_MINIMUM (0)
0x46, 0, 0x68, 0,     '
0x01, 0,              ' PHYSICAL_MAXIMUM (360)
0x55, 0, 0x0F, 0,     ' UNIT (Eng Rot:Angular Pos)
0x75, 0, 0x04, 0,     ' REPORT_SIZE (4)
0x95, 0, 0x01, 0,     ' REPORT_COUNT (1)
0x81, 0, 0x02, 0,     ' INPUT (Data,Var,Abs)
'------------------------------------------------------------------------------
' 18 BYTE  DATA ZA Buttons POZICIJU
0x05, 0, 0x09, 0,     ' USAGE_PAGE (Buttons)
0x19, 0, 0x01, 0,     ' Usage Minimum
0x29, 0, 0x12, 0,     ' Usage Maximum
0x15, 0, 0x00, 0,     ' LOGICAL_MINIMUM (0)
0x25, 0, 0x01, 0,     ' LOGICAL_MAXIMUM (1)
0x75, 0, 0x01, 0,     ' REPORT_SIZE  (1)
0x95, 0, 0x0C, 0,     ' REPORT_COUNT (12)
0x81, 0, 0x02, 0,     ' INPUT (Data,Var,Abs)
'------------------------------------------------------------------------------

0xc0, 0               ' END_COLLECTION
)
'******************************************************************************
 const LangIDDescr as byte[8] = (
    0x04, 0,
    USB_STRING_DESCRIPTOR_TYPE, 0,
    0x09, 0,                                ' LangID (0x0409) - Low
    0x04, 0                                 '                 - High
)
'******************************************************************************
 const ManufacturerDescr as byte[28] = (
    14, 0,
    USB_STRING_DESCRIPTOR_TYPE, 0,
    "8", 0, 0, 0,
    "-", 0, 0, 0,
    "B", 0, 0, 0,
    "i", 0, 0, 0,
    "t", 0, 0, 0,
    "a", 0, 0, 0
)
'******************************************************************************
 const ProductDescr as byte[116] = (
    58, 0,
    USB_STRING_DESCRIPTOR_TYPE, 0,
    "U", 0, 0, 0,
    "S", 0, 0, 0,
    "B", 0, 0, 0,
    " ", 0, 0, 0,
    "J", 0, 0, 0,
    "O", 0, 0, 0,
    "Y", 0, 0, 0,
    "S", 0, 0, 0,
    "T", 0, 0, 0,
    "I", 0, 0, 0,
    "C", 0, 0, 0,
    " ", 0, 0, 0,
    "B", 0, 0, 0,
    "Y", 0, 0, 0,
    " ", 0, 0, 0,
    "S", 0, 0, 0,
    "5", 0, 0, 0,
    "9", 0, 0, 0,
    "K", 0, 0, 0,
    "B", 0, 0, 0,
    " ", 0, 0, 0,
    "1", 0, 0, 0,
    "0", 0, 0, 0,
    " ", 0, 0, 0,
    "B", 0, 0, 0,
    "I", 0, 0, 0,
    "T", 0, 0, 0,
    " ", 0, 0, 0
)
'******************************************************************************
 const StrUnknownDescr as byte[36] = (
    18, 0,
    USB_STRING_DESCRIPTOR_TYPE, 0,
    Serial_No[0], 0, 0, 0,
    Serial_No[1], 0, 0, 0,
    Serial_No[2], 0, 0, 0,
    Serial_No[3], 0, 0, 0,
    Serial_No[4], 0, 0, 0,
    Serial_No[5], 0, 0, 0,
    Serial_No[6], 0, 0, 0,
    Serial_No[7], 0, 0, 0
)
'******************************************************************************
implements

end.
Image

Image

Image

And finally

Image

Live long and prosper 73 de S59KB
Last edited by S59KB on 06 Feb 2013 23:03, edited 5 times in total.

User avatar
filip
mikroElektronika team
Posts: 11874
Joined: 25 Jan 2008 09:56

Re: JOYSTIK 8 AXIS 12 BUTTON + HAT and COMPLETE DOCUMENTATIO

#2 Post by filip » 28 Jan 2013 11:15

Hi,

Thank you for sharing this project with the Forum members. :)

Regards,
Filip.

S59KB
Posts: 46
Joined: 17 Apr 2010 15:48
Location: CELJE
Contact:

Re: JOYSTIK 8 AXIS 12 BUTTON + HAT and COMPLETE DOCUMENTATIO

#3 Post by S59KB » 16 Feb 2013 12:19

IMPROVED VERSION
"JOYSTIK 8 AXIS 12 BUTTON + HAT and COMPLETE DOCUMENTATION"
IN
"JOYSTIK 8 AXIS 10 BIT, 12 BUTTON + HAT AND SET JOY"

EQUIPMENT CONNECTION is the same, just add a setting through a program written in Visual Basic 6.

Program written in Visual Basic 6
You can set the reverse and zoom potentiometer, and to see the value.
The documentation is presented in the full open source.

HARDWARE SETUP

Image

ADJUSTABLE SETUP
These data upload the joystic

Do not change the form of the VID & PID

Image

Download

http://www.libstock.com/projects/view/5 ... nd-set-joy

SHOULD ONLY EPROM MUST SET
AND THEN COMPILE

Image

Image

IMPROVED VERSION JOYSTIC_10_BIT_AND_SET

Code: Select all

'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
''
'' * Program name: JOYSTIC_10_BIT_AND_SET
''
'' * Copyright:
''     S59KB
''     Thank microelectronics, 2013
''
'' * Revision History:
''     201300216:
''
'' * Description:
''
''     This is a simple demonstration of 8 Axis 10 Bit, 12 Buttons and Hat Joystick Controller
''     Possibility of adjusting OFFSET potentiometer USING REFERENCES VREF+ and VREF-
''     Due to the angle of the potentiometer.
''     There are opportunities to expand the matrix of buttons
''     Program to use USB_HID_desc
''     IMPROVED VERSION program written in Visual Basic 6
''
'' * Test configuration:
''     No drivers needed
''     Tested on WIN_98 operating systems,
''     Tested on WIN_XP 32_BIT operating systems,
''     Tested on WIN_XP 64_BIT operating systems,
''     Tested on WIN_7 32_BIT operating systems,
''     Tested on WIN_7 64_BIT operating systems,
''     Not tested on WIN_8 operating systems.
''
''     MCU:             P18F2550 or any other USB Pic
''     Dev.Board:       EasyPIC5 or any other.
''     Oscillator:      4.0000 MHz
''     SW:              mikroBasic Pro v 3.2
''
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
program JOYSTIC_10_BIT_AND_SET
include USB_HID_desc
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
'  Tested on 18F2550 @ 4 MHz....8 Axis, 12 Buttons and Hat Joystick Controller
'                      ______   _____
'                     (     (__)     )
'  COLUMN 4     RE3 O (1           28) O RB7
'                     (              )
'  X AXIS   RA0/AN0 O (2           27) O RB6       ROWS 3
'                     (              )
'  Y AXIS   RA1/AN1 O (3           26) O RB5
'                     (              )
'  VREF -   RA2/AN2 O (4           25) O RB4/AN11  SLIDER AXIS
'                     (              )
'  VREF +   RA3/AN3 O (5           24) O RB3/AN9   RY AXIS
'                     (              )
'  ROWS 4       RA4 O (6           23) O RB2/AN8   RX AXIS
'                     (              )
'  Z AXIS   RA5/AN4 O (7           22) O RB1/AN10  RZ AXIS
'                     (              )
'  - 5 V        VSS O (8           21) O RB0/AN12  DIAL AXIS
'                     (              )
'               OSC O (9           20) O VDD       + 5 V
'               4 MHZ (              )
'               OSC O (10          19) O VSS       - 5 V
'                     (              )
'  COLUMN 1     RCO O (11          18) O RC7       ROWS 2
'                     (              )
'  COLUMN 2     RC1 O (12          17) O RC6       ROWS 1
'                     (              )
'  COLUMN 3     RC2 O (13          16) O D++
'                     (              )   USB
'               USB O (14          15) O D--
'                     (______________)
'*******************************************************************************
'                USB Data Map BYTE
'       |----|----|----|----|----|----|----|----|
' 0,1   |                   X                   |
'       |----|----|----|----|----|----|----|----|
' 2,3   |                   Y                   |
'       |----|----|----|----|----|----|----|----|
' 4,5   |                   Z                   |
'       |----|----|----|----|----|----|----|----|
' 6,7   |                   RX                  |
'       |----|----|----|----|----|----|----|----|
' 8,9   |                   RY                  |
'       |----|----|----|----|----|----|----|----|
' 10,11 |                   RZ                  |
'       |----|----|----|----|----|----|----|----|
' 12,13 |                  DIAL                 |
'       |----|----|----|----|----|----|----|----|
' 14,15 |                 SLIDER                |
'       |----|----|----|----|----|----|----|----|
' 16    |HATA|HATB|HATC|HATD|SW1 |SW2 |SW3 |SW4 |
'       |----|----|----|----|----|----|----|----|
' 17    |SW5 |SW6 |SW7 |SW8 |SW9 |SW10|SW11|SW12|
'       |----|----|----|----|----|----|----|----|
'
'            KONTROLNA INFORMACIJA SETOVANJA
'       |----|----|----|----|----|----|----|----|
' 18    |PC  |PC  |PC  |PC  |PC  |PC  |PC  |PC  |
'       |----|----|----|----|----|----|----|----|
' 19    |PC  |PC  |PC  |PC  |PC  |PC  |PC  |PC  |
'       |----|----|----|----|----|----|----|----|
' 20    |PC  |PC  |PC  |PC  |PC  |PC  |PC  |PC  |
'       |----|----|----|----|----|----|----|----|
' 21    |PC  |PC  |PC  |PC  |PC  |PC  |PC  |PC  |
'       |----|----|----|----|----|----|----|----|
' 22    |PC  |PC  |PC  |PC  |PC  |PC  |PC  |PC  |
'       |----|----|----|----|----|----|----|----|
' 23    |PC  |PC  |PC  |PC  |PC  |PC  |PC  |PC  |
'       |----|----|----|----|----|----|----|----|
' 24    |PC  |PC  |PC  |PC  |PC  |PC  |PC  |PC  |
'       |----|----|----|----|----|----|----|----|
' 25    |PC  |PC  |PC  |PC  |PC  |PC  |PC  |PC  |
'       |----|----|----|----|----|----|----|----|

'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
DIM BR AS BYTE
DIM POT_BR AS BYTE
DIM BUTT AS BYTE[5]
DIM NEGACIJA AS BYTE
DIM BUTTONS as BYTE[4]
DIM HAT_BUTTONS as BYTE[4]
DIM userWR_buffer as BYTE[64]
DIM userRD_buffer as BYTE[64]
DIM POT_MIX AS longword[9]
DIM POT AS WORD[9]
DIM REVERS AS BYTE[9]
DIM REVERS_PC AS BYTE
DIM ZOOM AS BYTE[9]
DIM ZOOM_PC AS BYTE[9]
DIM SAVE_AS AS BYTE
DIM S_AS AS WORD
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
sub procedure interrupt   ' Main Interrupt Routine
    HID_InterruptProc
end sub
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
sub function SAVE_HAT( DIM DATA_HAT AS BYTE) AS BYTE
    DIM RESULT_HAT AS BYTE
    select case DATA_HAT
    case 0        RESULT_HAT = 0x0F   '(0)-- Zero value (HID meaning)
    case 1        RESULT_HAT = 0x00   '(1)-- Up
    case 2        RESULT_HAT = 0x02   '(2)-- Right
    case 3        RESULT_HAT = 0x01   '(3)-- * Up-Right
    case 4        RESULT_HAT = 0x04   '(4)-- Down
    case 5        RESULT_HAT = 0x0F   '(5)-- * (Impossible)
    case 6        RESULT_HAT = 0x03   '(6)-- * Right-Down
    case 7        RESULT_HAT = 0x0F   '(7)
    case 8        RESULT_HAT = 0x06   '(8)-- Left
    case 9        RESULT_HAT = 0x07   '(9)-- * Left-Up
    case 10        RESULT_HAT = 0x0F   '(10)-- * (Impossible)
    case 11        RESULT_HAT = 0x0F   '(11)--
    case 12        RESULT_HAT = 0x05   '(13)-- * Down-Left
    case 13        RESULT_HAT = 0x0F   '(14)--
    case 14        RESULT_HAT = 0x0F   '(15)--
    case 15        RESULT_HAT = 0x0F   '(16)--
    end select
   result = RESULT_HAT
end sub
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
sub procedure READ_BUTTONS_AND_HAT ()
   BUTTONS[0] = 0
   BUTTONS[1] = 0
'  PORTC.0 = 0 PORTC.1 = 0  PORTC.2 = 0  PORTE.0 = 0
' Scan switch lines
' Read key data into Hat and Buttons
'     Switch Map                  COL
'     ROW            1 - RC0     2 - RC1     3 - RC2     4 - RE3
'     RC6 - 1        0.0 = 1H    0.1 = 2H    0.2 = 3H    0.3 = 4H   HAT     1-4
'     RC7 - 2        0.4 = 1     0.5 = 2     0.6 = 3     0.7 = 4    BUTTONS 1-4
'     RA4 - 3        1.0 = 5     1.1 = 6     1.2 = 7     1.3 = 8    BUTTONS 5-8
'     RB6 - 4        1.4 = 9     1.5 = 10    1.6 = 11    1.7 = 12   BUTTONS 9-12
'-------------------------------------------------------------------------------
      PORTA.4 = 1  PORTB.6 = 1 PORTC.6 = 0 PORTC.7 = 1
      Delay_ms(1)
      HAT_BUTTONS[0].0 = NOT PORTC.0
      HAT_BUTTONS[0].1 = NOT PORTC.1
      HAT_BUTTONS[0].2 = NOT PORTC.2
      HAT_BUTTONS[0].3 = NOT PORTE.3
      HAT_BUTTONS[0] = SAVE_HAT(HAT_BUTTONS[0])
'---------------------------
' Scan row RC7 = 0   Buttons
      PORTA.4 = 1 PORTB.6 = 1 PORTC.6 = 1 PORTC.7 = 0
      Delay_ms(1)
      BUTTONS[0].4 = NOT PORTC.0
      BUTTONS[0].5 = NOT PORTC.1
      BUTTONS[0].6 = NOT PORTC.2
      BUTTONS[0].7 = NOT PORTE.3
'---------------------------
' Scan row RA4 = 0   Buttons
      PORTA.4 = 0 PORTB.6 = 1 PORTC.6 = 1 PORTC.7 = 1
      Delay_ms(1)
      BUTTONS[1].0 = NOT PORTC.0
      BUTTONS[1].1 = NOT PORTC.1
      BUTTONS[1].2 = NOT PORTC.2
      BUTTONS[1].3 = NOT PORTE.3
'---------------------------
' Scan row RB6 = 0   Buttons
      PORTA.4 = 1 PORTB.6 = 0 PORTC.6 = 1 PORTC.7 = 1
      Delay_ms(1)
      BUTTONS[1].4 = NOT PORTC.0
      BUTTONS[1].5 = NOT PORTC.1
      BUTTONS[1].6 = NOT PORTC.2
      BUTTONS[1].7 = NOT PORTE.3
      PORTA.4 = 1 PORTB.6 = 1 PORTC.6 = 0 PORTC.7 = 1
      Delay_ms(1)
  '---------------------------------------------------------
  ' SELEKTOVANJE RADNIH I MIRNIH BUTTONA
  '    FOR BR = 0 TO 2
  '        buttons[BR]= NOT buttons[BR]
  '    NEXT BR
end sub
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
sub procedure READ_AXIS ()
    POT_MIX[1] = adc_read(10)        ' Read RZ      4 VB6
    POT_MIX[2] = adc_read(0)         ' Read X       0 VB6
    POT_MIX[3] = adc_read(1)         ' Read Y       0 VB6
    POT_MIX[4] = adc_read(4)         ' Read Z       1 VB6
    POT_MIX[5] = adc_read(8)         ' Read RX      2 VB6
    POT_MIX[6] = adc_read(9)         ' Read RY      3 VB6
    POT_MIX[7] = adc_read(12)        ' Read DIAL    5 VB6
    POT_MIX[8] = adc_read(11)        ' Read SLIDER  6 VB6
end sub
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
sub procedure READ_EPP_REVERS_ZOOM ()
     IF userRD_buffer[0] = 1 THEN
        REVERS[1] = userRD_buffer[1] EEPROM_Write(1, REVERS[1])
        REVERS[2] = userRD_buffer[2] EEPROM_Write(2, REVERS[2])
        REVERS[3] = userRD_buffer[3] EEPROM_Write(3, REVERS[3])
        REVERS[4] = userRD_buffer[4] EEPROM_Write(4, REVERS[4])
        REVERS[5] = userRD_buffer[5] EEPROM_Write(5, REVERS[5])
        REVERS[6] = userRD_buffer[6] EEPROM_Write(6, REVERS[6])
        '---------------------------
        ZOOM[1] = userRD_buffer[7]   EEPROM_Write(7, ZOOM[1])
        ZOOM[2] = userRD_buffer[8]   EEPROM_Write(8, ZOOM[2])
        ZOOM[3] = userRD_buffer[9]   EEPROM_Write(9, ZOOM[3])
        ZOOM[4] = userRD_buffer[10]  EEPROM_Write(10, ZOOM[4])
        ZOOM[5] = userRD_buffer[11]  EEPROM_Write(11, ZOOM[5])
        ZOOM[6] = userRD_buffer[12]  EEPROM_Write(12, ZOOM[6])
        userRD_buffer[0] = 0
        SAVE_AS = 1
     END IF
end sub
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
sub procedure Init_Main   ' Initialization Routine
  '--------------------------------------
  ' Disable interrupts
  '--------------------------------------
  INTCON = 0              ' Disable GIE, PEIE, TMR0IE,INT0IE, RBIE
  INTCON2 = 0x75          ' Turn on PORTB pull-ups
  INTCON3 = 0xC0
  RCON.IPEN = 0           ' Disable Priority Levels on interrupts
  PIE1 = 0  PIE2 = 0  PIR1 = 0  PIR2 = 0
  LATA = 0  LATB = 0  LATC = 0
'--------------------------------------
'  ADCON1 = ADCON1 or 0xF3  ' 0xF3 REFERENCA +/-
  ADCON0 = 0x01
  ADCON1 = 0x31      ' RA2, RA3  are joystick axis inputs REFERENCA
  ADCON2 = 0xBE
'--------------------------------------
' Switch Map TRIS bits:  1 = input, 0 = output
  TRISC.0 = 1  ' RC0 input  Columns 1 - with pullup
  TRISC.1 = 1  ' RC1 input  Columns 2 - with pullup
  TRISC.2 = 1  ' RC2 input  Columns 3 - with pullup
'  TRISE.3 = 1  ' RE2 input  Columns 4 - with pullup
  TRISC.6 = 0  ' RC6 output Rows 1
  TRISC.7 = 0  ' RC7 output Rows 2
  TRISA.4 = 0  ' RA4 output Rows 3
  TRISB.6 = 0  ' RB6 output Rows 4
end sub
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
main:                            ' Main Program Routine
  Init_Main()
  FOR BR = 0 TO 11
    userWR_buffer[BR] = 0x00     ' Initialize everything to 0
  NEXT BR
'----------------------------
  FOR BR = 0 TO 4
    BUTT[BR] = 0x00              ' Initialize everything to 0
  NEXT BR
 '----------------------------
 ' Initialize REVERS kanala
    REVERS[1] = EEPROM_Read(1)
    REVERS[2] = EEPROM_Read(2)
    REVERS[3] = EEPROM_Read(3)
    REVERS[4] = EEPROM_Read(4)
    REVERS[5] = EEPROM_Read(5)
    REVERS[6] = EEPROM_Read(6)
 '----------------------------
 ' Initialize ZOOM kanala
    ZOOM[1] = EEPROM_Read(7)
    ZOOM[2] = EEPROM_Read(8)
    ZOOM[3] = EEPROM_Read(9)
    ZOOM[4] = EEPROM_Read(10)
    ZOOM[5] = EEPROM_Read(11)
    ZOOM[6] = EEPROM_Read(12)
 '----------------------------
  HID_Enable(@userRD_buffer, @userWR_buffer)
  Delay_ms(1000)
  Delay_ms(1000)
  SAVE_AS = 0
  S_AS = 0
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
  while true
'---------------------------------------------------------
' Read BUTTONS AND HAT
         READ_BUTTONS_AND_HAT ()
' Read AXIS
         READ_AXIS ()
' Read REVERS AND ZOOM
         READ_EPP_REVERS_ZOOM ()
'---------------------------------------------------------
' ZUMIRANJE POTENCIOMETRA
         POT_MIX[4] = (POT_MIX[4] * 100) / (ZOOM[1]) IF POT_MIX[4] > 1023 THEN POT_MIX[4] = 1023 END IF
         POT_MIX[5] = (POT_MIX[5] * 100) / (ZOOM[2]) IF POT_MIX[5] > 1023 THEN POT_MIX[5] = 1023 END IF
         POT_MIX[6] = (POT_MIX[6] * 100) / (ZOOM[3]) IF POT_MIX[6] > 1023 THEN POT_MIX[6] = 1023 END IF
         POT_MIX[1] = (POT_MIX[1] * 100) / (ZOOM[4]) IF POT_MIX[1] > 1023 THEN POT_MIX[1] = 1023 END IF
         POT_MIX[7] = (POT_MIX[7] * 100) / (ZOOM[5]) IF POT_MIX[7] > 1023 THEN POT_MIX[7] = 1023 END IF
         POT_MIX[8] = (POT_MIX[8] * 100) / (ZOOM[6]) IF POT_MIX[8] > 1023 THEN POT_MIX[8] = 1023 END IF
         FOR BR = 0 TO 8
             POT[BR] = POT_MIX[BR]
         NEXT BR
'---------------------------------------------------------
' REVERSIRANJE POTENCIOMETRA
         IF REVERS[1] = 0 THEN POT[4] = POT[4] ELSE POT[4] = 1023 - POT[4] END IF
         IF REVERS[2] = 0 THEN POT[5] = POT[5] ELSE POT[5] = 1023 - POT[5] END IF
         IF REVERS[3] = 0 THEN POT[6] = POT[6] ELSE POT[6] = 1023 - POT[6] END IF
         IF REVERS[4] = 0 THEN POT[1] = POT[1] ELSE POT[1] = 1023 - POT[1] END IF
         IF REVERS[5] = 0 THEN POT[7] = POT[7] ELSE POT[7] = 1023 - POT[7] END IF
         IF REVERS[6] = 0 THEN POT[8] = POT[8] ELSE POT[8] = 1023 - POT[8] END IF
            REVERS_PC.0 = 0
            REVERS_PC.1 = REVERS[1]
            REVERS_PC.2 = REVERS[2]
            REVERS_PC.3 = REVERS[3]
            REVERS_PC.4 = REVERS[4]
            REVERS_PC.5 = REVERS[5]
            REVERS_PC.6 = REVERS[6]
            REVERS_PC.7 = 0
'-----------------------------------------------------------------------------
' Axis inputs SEND
         userWR_buffer[0] = LO(POT[1])
         userWR_buffer[1] = HI(POT[1])
         userWR_buffer[2] = LO(POT[2])
         userWR_buffer[3] = HI(POT[2])
         userWR_buffer[4] = LO(POT[3])
         userWR_buffer[5] = HI(POT[3])
         userWR_buffer[6] = LO(POT[4])
         userWR_buffer[7] = HI(POT[4])
         userWR_buffer[8] = LO(POT[5])
         userWR_buffer[9] = HI(POT[5])
         userWR_buffer[10] = LO(POT[6])
         userWR_buffer[11] = HI(POT[6])
         userWR_buffer[12] = LO(POT[7])
         userWR_buffer[13] = HI(POT[7])
         userWR_buffer[14] = LO(POT[8])
         userWR_buffer[15] = HI(POT[8])
'--------------------------------------
' HAT and BUTTONS 1, 2, 3, 4  SEND
         'userWR_buffer[16] = HAT_BUTTONS[0]
         userWR_buffer[16] = HAT_BUTTONS[0] + BUTTONS[0]
' BUTTONS 5, 6, 7, 8, 9, 10, 11, 12 SEND
         userWR_buffer[17] = BUTTONS[1]
'--------------------------------------
' KONTROLNA INFORMACIJA SETOVANJA
         userWR_buffer[18] = REVERS_PC
         userWR_buffer[19] = ZOOM[1]
         userWR_buffer[20] = ZOOM[2]
         userWR_buffer[21] = ZOOM[3]
         userWR_buffer[22] = ZOOM[4]
         userWR_buffer[23] = ZOOM[5]
         userWR_buffer[24] = ZOOM[6]
         userWR_buffer[25] = SAVE_AS
         INC(S_AS)
         IF S_AS >= 10000 THEN
            SAVE_AS = 0
            S_AS = 0
         END IF
'--------------------------------------
' Send data report to pc and read data report from pc.
         HID_Write(@userWR_buffer, 26)
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
  wend
  HID_Disable()
end.
'*******************************************************************************
'///////////////////////////////////////////////////////////////////////////////
'*******************************************************************************
module USB_HID_desc

Code: Select all

module USB_HID_desc
' uses HIDconstant;
'  File Version 2.0
'******************************************************************************
 const Serial_No = "22062005"
'******************************************************************************
' The number of bytes in each report,
' calculated from Report Size and Report Count in the report descriptor
'******************************************************************************
 const HID_INPUT_REPORT_BYTES      = 64
 const HID_OUTPUT_REPORT_BYTES     = 64
 const HID_FEATURE_REPORT_BYTES    = 2
'******************************************************************************
' Byte constants
'******************************************************************************
 const NUM_ENDPOINTS               = 2
 const ConfigDescr_wTotalLength    = USB_CONFIG_DESCRIPTOR_LEN + USB_INTERF_DESCRIPTOR_LEN + USB_HID_DESCRIPTOR_LEN + (NUM_ENDPOINTS * USB_ENDP_DESCRIPTOR_LEN)
 const HID_ReportDesc_Fix          = 59
 const HID_ReportDesc_len          = 233
 const Low_HID_ReportDesc_len      = HID_ReportDesc_len
 const High_HID_ReportDesc_len     = HID_ReportDesc_len >> 8
 const Low_HID_PACKET_SIZE         = HID_PACKET_SIZE
 const High_HID_PACKET_SIZE        = HID_PACKET_SIZE >> 8
'******************************************************************************
' Descriptor Tables
'******************************************************************************
' const DescTables as byte[USB_DEVICE_DESCRIPTOR_ALL_LEN*2] = (
 const DescTables as byte[(HID_ReportDesc_Fix + HID_ReportDesc_len)*2] = (
' Device Descriptor
    USB_DEVICE_DESCRIPTOR_LEN, 0,           ' bLength               - Length of Device descriptor (always 0x12)
    USB_DEVICE_DESCRIPTOR_TYPE, 0,          ' bDescriptorType       - 1 = DEVICE descriptor
    0x00, 0,                                ' bcdUSB                - USB revision 2.00 (low byte)
    0x02, 0,                                '                                           (high byte)
    0x00, 0,                                ' bDeviceClass          - Zero means each interface operates independently (class code in the interface descriptor)
    0x00, 0,                                ' bDeviceSubClass
    0x00, 0,                                ' bDeviceProtocol
    EP0_PACKET_SIZE, 0,                     ' bMaxPacketSize0       - maximum size of a data packet for a control transfer over EP0
    0x02, 0,                                ' idVendor              - Vendor  ID (low byte)
    0x07, 0,                                '                                    (high byte)
    0x13, 0,                                ' idProduct             - Product ID (low byte)
    0x20, 0,                                '                                    (high byte)
    0x21, 0,                                ' bcdDevice             - (low byte)
    0x01, 0,                                '                         (high byte)
    0x01, 0,                                ' iManufacturer         - String1
    0x02, 0,                                ' iProduct              - String2
    0x03, 0,                                ' iSerialNumber         - String3
    0x01, 0,                                ' bNumConfigurations    - 1
'------------------------------------------------------------------------------
' Configuration Descriptor
    USB_CONFIG_DESCRIPTOR_LEN, 0,           ' bLength               - Length of Configuration descriptor (always 0x09)
    USB_CONFIG_DESCRIPTOR_TYPE, 0,          ' bDescriptorType       - 2 = CONFIGURATION descriptor
    ConfigDescr_wTotalLength, 0,            ' wTotalLength          - Total length of this config. descriptor plus the interface and endpoint descriptors that are part of the configuration.
    0x00, 0,                                '                         (high byte)
    0x01, 0,                                ' bNumInterfaces        - Number of interfaces
    0x01, 0,                                ' bConfigurationValue   - Configuration Value
    0x00, 0,                                ' iConfiguration        - String Index for this configuration ( None )
    0xA0, 0,                                ' bmAttributes          - attributes - "Bus powered" and "Remote wakeup"
    50, 0,                                  ' MaxPower              - bus-powered draws 50*2 mA from the bus.
'------------------------------------------------------------------------------
' Interface Descriptor
    USB_INTERF_DESCRIPTOR_LEN, 0,           ' bLength               - Length of Interface descriptor (always 0x09)
    USB_INTERFACE_DESCRIPTOR_TYPE, 0,       ' bDescriptorType       - 4 = INTERFACE descriptor
    0x00, 0,                                ' bInterfaceNumber      - Number of interface, 0 based array
    0x00, 0,                                ' bAlternateSetting     - Alternate setting
    NUM_ENDPOINTS, 0,                       ' bNumEndPoints         - Number of endpoints used in this interface
    0x03, 0,                                ' bInterfaceClass       - assigned by the USB
    0x00, 0,                                ' bInterfaceSubClass    - Not A boot device
    0x00, 0,                                ' bInterfaceProtocol    - none
    0x00, 0,                                ' iInterface            - Index to string descriptor that describes this interface ( None )
'------------------------------------------------------------------------------
' HID Descriptor
    USB_HID_DESCRIPTOR_LEN, 0,              ' bLength               - Length of HID descriptor (always 0x09)
    USB_HID_DESCRIPTOR_TYPE, 0,             ' bDescriptorType       - 0x21 = HID descriptor
    0x01, 0,                                ' HID class release number (1.01)
    0x01, 0,
    0x00, 0,                                ' Localized country code (none)
    0x01, 0,                                ' # of HID class descriptor to follow (1)
    0x22, 0,                                ' Report descriptor type (HID)
    Low_HID_ReportDesc_len, 0,
    High_HID_ReportDesc_len, 0,
'------------------------------------------------------------------------------
' EP1_RX Descriptor
    USB_ENDP_DESCRIPTOR_LEN, 0,             ' bLength               - length of descriptor (always 0x07)
    USB_ENDPOINT_DESCRIPTOR_TYPE, 0,        ' bDescriptorType       - 5 = ENDPOINT descriptor
    0x81, 0,                                ' bEndpointAddress      - In, EP1
    USB_ENDPOINT_TYPE_INTERRUPT, 0,         ' bmAttributes          - Endpoint Type - Interrupt
    Low_HID_PACKET_SIZE, 0,                 ' wMaxPacketSize        - max packet size - low order byte
    High_HID_PACKET_SIZE, 0,                '                       - max packet size - high order byte
    1, 0,                                   ' bInterval             - polling interval (1 ms)
'------------------------------------------------------------------------------
' EP1_TX Descriptor
    USB_ENDP_DESCRIPTOR_LEN, 0,             ' bLength               - length of descriptor (always 0x07)
    USB_ENDPOINT_DESCRIPTOR_TYPE, 0,        ' bDescriptorType       - 5 = ENDPOINT descriptor
    0x01, 0,                                ' bEndpointAddress      - Out, EP1
    USB_ENDPOINT_TYPE_INTERRUPT, 0,         ' bmAttributes          - Endpoint Type - Interrupt
    Low_HID_PACKET_SIZE, 0,                 ' wMaxPacketSize        - max packet size - low order byte
    High_HID_PACKET_SIZE, 0,                '                       - max packet size - high order byte
    1, 0,                                   ' bInterval             - polling interval (1 ms)
'------------------------------------------------------------------------------
' HID_Report Descriptor
' USB Data Map
'------------------------------------------------------------------------------
0x05, 0, 0x01, 0,     ' USAGE_PAGE (Generic Desktop)
0x09, 0, 0x04, 0,     ' USAGE (Joystick)
0xa1, 0, 0x01, 0,     ' COLLECTION (Application)
'------------------------------------------------------------------------------
' The Output report 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18 BYTE
0x09, 0, 0x01, 0,     ' USAGE ID - Joystick
0x15, 0, 0x00, 0,     ' LOGICAL_MINIMUM (0)
0x26, 0, 0x00, 0,
0xFF, 0,              ' LOGICAL_MAXIMUM (255)
0x75, 0, 0x08, 0,     ' REPORT_SIZE (8)
0x95, 0, 0x12, 0,     ' REPORT_COUNT (2)
0x91, 0, 0x02, 0,     ' OUTPUT (Data,Var,Abs)
'------------------------------------------------------------------------------
' The Input report 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 BYTE  DATA ZA X, Y, Z, RX, RY, RZ, Dial, Slider OSU
0x05, 0, 0x01, 0,     ' USAGE_PAGE (Generic Desktop)
0x15, 0, 0x00, 0,
0x26, 0,              ' LOGICAL_MINIMUM (0)
0xFF, 0, 0x03, 0,     ' LOGICAL_MAXIMUM (1024)
0x75, 0, 0x10, 0,     ' REPORT_SIZE (16)
0xa1, 0, 0x00, 0,     ' COLLECTION (Physical)
0x09, 0, 0x35, 0,     ' USAGE (RZ)
0x09, 0, 0x30, 0,     ' USAGE (X)
0x09, 0, 0x31, 0,     ' USAGE (Y)
0x09, 0, 0x32, 0,     ' USAGE (Z)
0x09, 0, 0x33, 0,     ' USAGE (RX)
0x09, 0, 0x34, 0,     ' USAGE (RY)
0x09, 0, 0x36, 0,     ' USAGE (Dial)
0x09, 0, 0x37, 0,     ' USAGE (Slider)
0x95, 0, 0x08, 0,     ' REPORT_COUNT (8)
0x81, 0, 0x02, 0,     ' INPUT (Data,Var,Abs)
'------------------------------------------------------------------------------
' The Input report 16 1/2 BYTE DATA ZA HAT POZICIJU i 2/2 BYTE ZA BUTTONS
0x05, 0, 0x01, 0,     ' USAGE_PAGE (Generic Desktop)
0x09, 0, 0x39, 0,     ' USAGE (Hat switch)
0x15, 0, 0x00, 0,     ' LOGICAL_MINIMUM (0)
0x25, 0, 0x07, 0,     ' LOGICAL_MAXIMUM (7)
0x35, 0, 0x00, 0,     ' PHYSICAL_MINIMUM (0)
0x46, 0, 0x3B, 0,     '
0x01, 0,              ' PHYSICAL_MAXIMUM (315)
0x65, 0, 0x14, 0,     ' UNIT (Eng Rot:Angular Pos)
0x75, 0, 0x04, 0,     ' REPORT_SIZE (4)
0x95, 0, 0x01, 0,     ' REPORT_COUNT (1)
0x81, 0, 0x02, 0,     ' INPUT (Data,Var,Abs)
'------------------------------------------------------------------------------
' The Input report 17 BYTE DATA ZA Buttons POZICIJU
0x05, 0, 0x09, 0,     ' USAGE_PAGE (Buttons)
0x19, 0, 0x01, 0,     ' Usage Minimum
0x29, 0, 0x12, 0,     ' Usage Maximum
0x15, 0, 0x00, 0,     ' LOGICAL_MINIMUM (0)
0x25, 0, 0x01, 0,     ' LOGICAL_MAXIMUM (1)
0x75, 0, 0x01, 0,     ' REPORT_SIZE  (1)
0x95, 0, 0x0C, 0,     ' REPORT_COUNT (12)
0x81, 0, 0x02, 0,     ' INPUT (Data,Var,Abs)
'------------------------------------------------------------------------------
' The Input report 18 BYTE DATA ZA KOMANDU SETOVANJA
0x05, 0, 0x01, 0,     ' USAGE_PAGE (Generic Desktop)
0x05, 0, 0x08, 0,     ' USAGE_PAGE (LEDS_1)
0x19, 0, 0x01, 0,     ' Usage Minimum
0x29, 0, 0x12, 0,     ' Usage Maximum
0x15, 0, 0x00, 0,     ' LOGICAL_MINIMUM (0)
0x25, 0, 0x01, 0,     ' LOGICAL_MAXIMUM (1)
0x75, 0, 0x08, 0,     ' REPORT_SIZE  (8)
0x95, 0, 0x01, 0,     ' REPORT_COUNT (1)
0x81, 0, 0x02, 0,     ' INPUT (Data,Var,Abs)
'------------------------------------------------------------------------------
' The Input report 19 BYTE DATA ZA DATA SETOVANJA
0x05, 0, 0x01, 0,     ' USAGE_PAGE (Generic Desktop)
0x05, 0, 0x08, 0,     ' USAGE_PAGE (LEDS_2)
0x19, 0, 0x01, 0,     ' Usage Minimum
0x29, 0, 0x12, 0,     ' Usage Maximum
0x15, 0, 0x00, 0,     ' LOGICAL_MINIMUM (0)
0x25, 0, 0x01, 0,     ' LOGICAL_MAXIMUM (1)
0x75, 0, 0x08, 0,     ' REPORT_SIZE  (8)
0x95, 0, 0x01, 0,     ' REPORT_COUNT (1)
0x81, 0, 0x02, 0,     ' INPUT (Data,Var,Abs)
'------------------------------------------------------------------------------
' The Input report 20 BYTE DATA ZA KOMANDU SETOVANJA
0x05, 0, 0x01, 0,     ' USAGE_PAGE (Generic Desktop)
0x05, 0, 0x08, 0,     ' USAGE_PAGE (LEDS_3)
0x19, 0, 0x01, 0,     ' Usage Minimum
0x29, 0, 0x12, 0,     ' Usage Maximum
0x15, 0, 0x00, 0,     ' LOGICAL_MINIMUM (0)
0x25, 0, 0x01, 0,     ' LOGICAL_MAXIMUM (1)
0x75, 0, 0x08, 0,     ' REPORT_SIZE  (8)
0x95, 0, 0x01, 0,     ' REPORT_COUNT (1)
0x81, 0, 0x02, 0,     ' INPUT (Data,Var,Abs)
'------------------------------------------------------------------------------
' The Input report 21 BYTE DATA ZA DATA SETOVANJA
0x05, 0, 0x01, 0,     ' USAGE_PAGE (Generic Desktop)
0x05, 0, 0x08, 0,     ' USAGE_PAGE (LEDS_4)
0x19, 0, 0x01, 0,     ' Usage Minimum
0x29, 0, 0x12, 0,     ' Usage Maximum
0x15, 0, 0x00, 0,     ' LOGICAL_MINIMUM (0)
0x25, 0, 0x01, 0,     ' LOGICAL_MAXIMUM (1)
0x75, 0, 0x08, 0,     ' REPORT_SIZE  (8)
0x95, 0, 0x01, 0,     ' REPORT_COUNT (1)
0x81, 0, 0x02, 0,     ' INPUT (Data,Var,Abs)
'------------------------------------------------------------------------------
' The Input report 22 BYTE DATA ZA KOMANDU SETOVANJA
0x05, 0, 0x01, 0,     ' USAGE_PAGE (Generic Desktop)
0x05, 0, 0x08, 0,     ' USAGE_PAGE (LEDS_5)
0x19, 0, 0x01, 0,     ' Usage Minimum
0x29, 0, 0x12, 0,     ' Usage Maximum
0x15, 0, 0x00, 0,     ' LOGICAL_MINIMUM (0)
0x25, 0, 0x01, 0,     ' LOGICAL_MAXIMUM (1)
0x75, 0, 0x08, 0,     ' REPORT_SIZE  (8)
0x95, 0, 0x01, 0,     ' REPORT_COUNT (1)
0x81, 0, 0x02, 0,     ' INPUT (Data,Var,Abs)
'------------------------------------------------------------------------------
' The Input report 23 BYTE DATA ZA DATA SETOVANJA
0x05, 0, 0x01, 0,     ' USAGE_PAGE (Generic Desktop)
0x05, 0, 0x08, 0,     ' USAGE_PAGE (LEDS_6)
0x19, 0, 0x01, 0,     ' Usage Minimum
0x29, 0, 0x12, 0,     ' Usage Maximum
0x15, 0, 0x00, 0,     ' LOGICAL_MINIMUM (0)
0x25, 0, 0x01, 0,     ' LOGICAL_MAXIMUM (1)
0x75, 0, 0x08, 0,     ' REPORT_SIZE  (8)
0x95, 0, 0x01, 0,     ' REPORT_COUNT (1)
0x81, 0, 0x02, 0,     ' INPUT (Data,Var,Abs)
'------------------------------------------------------------------------------
' The Input report 24 BYTE DATA ZA KOMANDU SETOVANJA
0x05, 0, 0x01, 0,     ' USAGE_PAGE (Generic Desktop)
0x05, 0, 0x08, 0,     ' USAGE_PAGE (LEDS_7)
0x19, 0, 0x01, 0,     ' Usage Minimum
0x29, 0, 0x12, 0,     ' Usage Maximum
0x15, 0, 0x00, 0,     ' LOGICAL_MINIMUM (0)
0x25, 0, 0x01, 0,     ' LOGICAL_MAXIMUM (1)
0x75, 0, 0x08, 0,     ' REPORT_SIZE  (8)
0x95, 0, 0x01, 0,     ' REPORT_COUNT (1)
0x81, 0, 0x02, 0,     ' INPUT (Data,Var,Abs)
'------------------------------------------------------------------------------
' The Input report 25 BYTE DATA ZA DATA SETOVANJA
0x05, 0, 0x01, 0,     ' USAGE_PAGE (Generic Desktop)
0x05, 0, 0x08, 0,     ' USAGE_PAGE (LEDS_8)
0x19, 0, 0x01, 0,     ' Usage Minimum
0x29, 0, 0x12, 0,     ' Usage Maximum
0x15, 0, 0x00, 0,     ' LOGICAL_MINIMUM (0)
0x25, 0, 0x01, 0,     ' LOGICAL_MAXIMUM (1)
0x75, 0, 0x08, 0,     ' REPORT_SIZE  (8)
0x95, 0, 0x01, 0,     ' REPORT_COUNT (1)
0x81, 0, 0x02, 0,     ' INPUT (Data,Var,Abs)
'------------------------------------------------------------------------------
0xc0, 0,              ' END_COLLECTION
0xc0, 0               ' END_COLLECTION
)
'******************************************************************************
 const LangIDDescr as byte[8] = (
    0x04, 0,
    USB_STRING_DESCRIPTOR_TYPE, 0,
    0x09, 0,                                ' LangID (0x0409) - Low
    0x04, 0                                 '                 - High
)
'******************************************************************************
 const ManufacturerDescr as byte[28] = (
    14, 0,
    USB_STRING_DESCRIPTOR_TYPE, 0,
    "8", 0, 0, 0,
    "-", 0, 0, 0,
    "B", 0, 0, 0,
    "i", 0, 0, 0,
    "t", 0, 0, 0,
    "a", 0, 0, 0
)
'******************************************************************************
 const ProductDescr as byte[116] = (
    58, 0,
    USB_STRING_DESCRIPTOR_TYPE, 0,
    "U", 0, 0, 0,
    "S", 0, 0, 0,
    "B", 0, 0, 0,
    " ", 0, 0, 0,
    "J", 0, 0, 0,
    "O", 0, 0, 0,
    "Y", 0, 0, 0,
    "S", 0, 0, 0,
    "T", 0, 0, 0,
    "I", 0, 0, 0,
    "C", 0, 0, 0,
    " ", 0, 0, 0,
    "B", 0, 0, 0,
    "Y", 0, 0, 0,
    " ", 0, 0, 0,
    "S", 0, 0, 0,
    "5", 0, 0, 0,
    "9", 0, 0, 0,
    "K", 0, 0, 0,
    "B", 0, 0, 0,
    " ", 0, 0, 0,
    "1", 0, 0, 0,
    "0", 0, 0, 0,
    " ", 0, 0, 0,
    "B", 0, 0, 0,
    "I", 0, 0, 0,
    "T", 0, 0, 0,
    " ", 0, 0, 0
)
'******************************************************************************
 const StrUnknownDescr as byte[36] = (
    18, 0,
    USB_STRING_DESCRIPTOR_TYPE, 0,
    Serial_No[0], 0, 0, 0,
    Serial_No[1], 0, 0, 0,
    Serial_No[2], 0, 0, 0,
    Serial_No[3], 0, 0, 0,
    Serial_No[4], 0, 0, 0,
    Serial_No[5], 0, 0, 0,
    Serial_No[6], 0, 0, 0,
    Serial_No[7], 0, 0, 0
)
'******************************************************************************
implements

end.
Coming soon force feedback jojstick in the full open source., Enjoy

Post Reply

Return to “mikroBasic PRO for PIC General”