Move code from mEBasic ver 6.XX to mEBasic Pro ver 2.50

General discussion on mikroBasic PRO for PIC.
Author
Message
Philtkp
Posts: 307
Joined: 26 Apr 2006 00:58
Location: Tucson Arizona

Move code from mEBasic ver 6.XX to mEBasic Pro ver 2.50

#1 Post by Philtkp » 04 Sep 2009 18:56

Hello,
I'm trying to move some of the code I was using to mEBasic Pro.
This servo code using a PIC18F4550 worked fine before. I created a new Discriptor file but can not get the system to recognize the PIC.
This what I've tried.
-I can load the pic with the old HEX file and it works fine
-I can complie and program the PIC with the example and all works fine.
-If I create a new discriptor file for the example the PIC is not
recognized :(
-Using 18F4550 with 20Mhz resonator
- Device is set correct at 48Mhz
- 96mhz PLL Presacler set to divide by 5
CPU System Clock PostScaller96MHZ PLL /2
I have no clue what I missed. any help would be greatly appriciated

Could someone look at the code below. I only changed a couple of things and have documented them.

This is the code I'm working with.

Code: Select all

program test
include "USBdsc"      ' this module must be included in the same folder as the main program


dim
    wrbuf    as  byte[2]
    wr_adr   as  word
    servo    as byte[8]
    temp     as byte

sub procedure interrupt
If (INTCON.TMR0IE = 1) And (INTCON.TMR0IF = 1) Then
  LATB = 255
  temp = 0
  delay_us(820)
  TMR0L = 0
  asm
     movlw    0
     decfsz   _servo+0, 1,0
     iorlw    1
     decfsz   _servo+1, 1,0
     iorlw    2
     decfsz   _servo+2, 1,0
     iorlw    4
     decfsz   _servo+3, 1,0
     iorlw    8
     decfsz   _servo+4, 1,0
     iorlw    16
     decfsz   _servo+5, 1,0
     iorlw    32
     decfsz   _servo+6, 1,0
     iorlw    64
     decfsz   _servo+7, 1,0
     iorlw    128
     andwf    LATB, 1,0
     movf     TMR0L, 0,0
     xorwf    _temp, 0,0
     bz       $-2
     incfsz   _temp, 1,0
     bra      $-22
  end asm                        ' routine has used ~2180us to this point
  TMR0H = Hi(-3362)              ' load balance of 20ms in Timer0...high byte first
  '//************************************************************************
  '// TMR0L = -3362   error: 43 305 Argument is out of range "-3362" to "byte" test.mbas
  '//************************************************************************
  TMR0L = WORD(-3362)
  INTCON.TMR0IF = 0              ' reset the interrupt flag
Else
    HID_InterruptProc
End If
end sub

sub procedure Init_Main
   INTCON2 = 0xF5
   INTCON3 = 0xC0
   RCON.IPEN = 0                  ' disable Priority Levels on interrupts
   PIE1 = 0                       ' clear all interrupt enables
   PIE2 = 0
   PIR1 = 0
   PIR2 = 0
   ADCON1 = 15                    ' digital IO
   TRISB = 0
   LATB = 0
  T0CON = %00000101              ' prescaler = 64 or 5.3us per increment
  TMR0H = WORD(-1)
  TMR0L = WORD(-1)
  '//******************************************************************
  '//TMR0H = -1                     ' load Timer0 high byte first
  '//TMR0L = -1    65 305 Argument is out of range "-1" to "byte" test.mbas
  '//              65 327 Incompatible types ("complex type" to "simple type") test.mbas
  '//******************************************************************
  INTCON = %10100000             ' Timer0 Interrupt Enabled and Flag Cleared
  T0CON.7 = 1                    ' Timer0 On
end sub

main:
  Init_Main
  HID_Enable(@servo, @wrbuf)     ' @servo is equivalent to the Read_Buffer
  Delay_mS(1000)
  For temp = 0 to 7
     servo[temp] = 255
  Next temp
  while true
      If HID_READ <> 0 Then      ' if USB package has arrived...servo positions are in Read_Buffer
        wrbuf[0] = 255           ' 255 is verification value
        HID_WRITE(@wrbuf, 1)     ' reply to host with verification
     End If
  wend

  HID_Disable
 '//**************************************************************************
 '//  Code below not needed in version Pro version
 '//**************************************************************************
 '// '** This code is necessary in order to make linker load the variables and HID_InterruptProc routine.
 '// '** In real time it will never execute.
 '// if false then
 '//     HID_InterruptProc
 '//     wr_adr = @DeviceDescr
 '//     wr_adr = @ConfigDescr
 '//     wr_adr = @InterfaceDescr
 '//     wr_adr = @HID_Descriptor
 '//     wr_adr = @EP1_RXDescr
 '//     wr_adr = @EP1_TXDescr
 '//     wr_adr = @HID_ReportDesc
 '//     wr_adr = @LangIDDescr
 '//     wr_adr = @ManufacturerDescr
 '//     wr_adr = @ProductDescr
 '//     wr_adr = @StrUnknownDescr
 '// end if
end.

Bytex
Posts: 459
Joined: 23 Jun 2008 00:58
Location: Palmanova (UD), Italy
Contact:

#2 Post by Bytex » 04 Sep 2009 19:59

Hello Phil,
I've a question: Did you use this tool to generate the descriptor file ?

Image

Did you set correctly the VID, PID, Vendor-name, Product-name and the Report-length ?

Second point. Try to modify the @RD & @WR buffer length, both equal in size and fix it to 64 bytes.

Code: Select all

dim 
    wrbuf    as  byte[64] 
    wr_adr   as  word 
    servo    as  byte[64] 
    temp     as  byte 
I'm not sure, could be the right way :wink:

Best regards,
Max

http://www.b-vu.com

Philtkp
Posts: 307
Joined: 26 Apr 2006 00:58
Location: Tucson Arizona

#3 Post by Philtkp » 04 Sep 2009 21:19

Hi,
Thanks for the reply. Yes, Thats the Discription generator I used.
I mainly used the default setting for VID, PID. The rerort length was set to
Input =1, Output = 8, Vendor name = Testing, Product Name = PIC18F4550
Second point. Try to modify the @RD & @WR buffer length, both equal in size and fix it to 64 bytes.

Code:
dim
wrbuf as byte[64]
wr_adr as word
servo as byte[64]
temp as byte

This worked ok before, I'll give it a try thanks

Philtkp
Posts: 307
Joined: 26 Apr 2006 00:58
Location: Tucson Arizona

#4 Post by Philtkp » 05 Sep 2009 21:47

BINGO! :shock: Had to find the right settings for the Configuration Bits under edit project. :D now all my previous failed attemps seem to work. I just mirriored the ones from the example
now to continue with porting the code

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

#5 Post by xor » 06 Sep 2009 20:23

I saw a comment by janni on another thread. Be careful when using negative numbers since they must be typecast properly. INTEGER is a word-size data type that has negative values..

Try casting your negative numbers such by using this form: INTEGER(-3362)

This way the compiler knows how to manage the value before creating the HEX.

I haven't tesed this in mB PRO but if you want to keep a variable as WORD then you might create the same value by simply doing

Code: Select all

 myvar = 65536-3362
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]

Philtkp
Posts: 307
Joined: 26 Apr 2006 00:58
Location: Tucson Arizona

#6 Post by Philtkp » 06 Sep 2009 20:47

XOR,
Nice to see you about. Hope your feeling well. I've been fighting this beast for a bit now. tried WORD(-3362) but not INTEGER i'll give that a try. Thanks

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

#7 Post by xor » 07 Sep 2009 00:38

HI Phil, Doing better today thanks..... until my next treatment in a couple days :cry:

Maybe WORD(65536-3362) is better, keeping a positive value result large or small (0 to 65535).

Integer is 16-bit number with the 16th bit used for determining the sign , - or +., of the next 15 bits.

INTEGER covers a l16-bit range of numbers but imited in the size of its positive and negative values... -32767 ... to ... +32767.

The integer data type is very useful to determine if a math result is less than 0 or for less-than/greater-than value comparisons.,,, including 0.
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]

xor
Posts: 5465
Joined: 18 May 2005 00:59
Location: NYC
Contact:

#8 Post by xor » 07 Sep 2009 00:48

While I have not kept up to date for any changes ifor the latest compiler HID/USB library changes I have skimmed some of DANY's material (in the forums in mikroPascal) on this subject on his website. Very useful and helpful information. He usually has his weblink in his posts.
[color=darkred][b]xor[/b][/color]
[url=http://circuit-ed.com]CircuitED -[/url]

Philtkp
Posts: 307
Joined: 26 Apr 2006 00:58
Location: Tucson Arizona

#9 Post by Philtkp » 07 Sep 2009 16:42

Hi Warren,
Glad to hear your feeling better. :D :D :D
xor wrote:Maybe WORD(65536-3362) is better
Seems that this is better

Dany's website does has alot of good information, it's in Pascal but it still made sense :? Thanks

I have been succesful in getting the code below working under mEBasic Pro 2.50 :shock: :D

Code: Select all

Program servo_16_4550
'******************************************************************************************
'*                    18F2550 PIC USB_HID 50Hz PWM SERVO CONTROLLER                       *
'*                     by W. Schroeder alias "xor" -- July 4, 2006                        *
'*                            Revised on September 25, 2006                               *
'*                                                                                        *
'*   Re-Compiled with mikroBASIC Pro 2.50 and tested on the EasyPIC5 Development Board    *
'*   Uses: HID_constants,USB and USART Libraies                                           *
'*   PIC18F4550 20MHz crystal oscillator                                                  *
'*   16 SERVO's                                                                           *
'******************************************************************************************
'******************************************************************************************

include "SERVOdsc"      ' this module must be included in the same folder as the main program


dim
    wrbuf    as  byte[2]
    wr_adr   as  word
    servo    as byte[17]
    temp     as byte

sub procedure interrupt
If (INTCON.TMR0IE = 1) And (INTCON.TMR0IF = 1) Then
  LATB = 255
  LATD = 255
  temp = 0
  delay_us(330)
  TMR0L = 0
  asm
PWM_Loop:
     movlw    0
     decfsz   _servo+1, 1,0
     iorlw    1
     decfsz   _servo+2, 1,0
     iorlw    2
     decfsz   _servo+3, 1,0
     iorlw    4
     decfsz   _servo+4, 1,0
     iorlw    8
     decfsz   _servo+5, 1,0
     iorlw    16
     decfsz   _servo+6, 1,0
     iorlw    32
     decfsz   _servo+7, 1,0
     iorlw    64
     decfsz   _servo+8, 1,0
     iorlw    128
     andwf    LATB, 1,0
     movlw    0
     decfsz   _servo+9, 1,0
     iorlw    1
     decfsz   _servo+10, 1,0
     iorlw    2
     decfsz   _servo+11, 1,0
     iorlw    4
     decfsz   _servo+12, 1,0
     iorlw    8
     decfsz   _servo+13, 1,0
     iorlw    16
     decfsz   _servo+14, 1,0
     iorlw    32
     decfsz   _servo+15, 1,0
     iorlw    64
     decfsz   _servo+16, 1,0
     iorlw    128
     andwf    LATD, 1,0
end asm
     delay_us(2)
asm
     incfsz   _temp, 1,0
     bra      PWM_Loop
end asm
  TMR0H = Hi(-3362)              ' load balance of 20ms in Timer0...high byte first
  TMR0L = WORD(65536-3362)
  INTCON.TMR0IF = 0              ' reset the interrupt flag
Else
    HID_InterruptProc
End If
end sub

sub procedure Init_Main
   INTCON2 = 0xF5
   INTCON3 = 0xC0
   RCON.IPEN = 0                  ' disable Priority Levels on interrupts
   PIE1 = 0                       ' clear all interrupt enables
   PIE2 = 0
   PIR1 = 0
   PIR2 = 0
   ADCON1 = 15                    ' digital IO
   TRISB = 0
   TRISD = 0
   LATB = 0
   LATD = 0
  T0CON = %00000101              ' prescaler = 64 or 5.3us per increment
  TMR0H = WORD(65536-1)                     ' load Timer0 high byte first
  TMR0L = WORD(65536-1)
  INTCON = %10100000             ' Timer0 Interrupt Enabled and Flag Cleared
  T0CON.7 = 1                    ' Timer0 On
end sub


main:
  Init_Main
  HID_Enable(@servo, @wrbuf)     ' @servo is equivalent to the Read_Buffer
  Delay_mS(1000)
 ' For temp = 0 to 15
  '   servo[temp] = 256
  'Next temp
  while true
      If HID_READ <> 0 Then      ' if USB package has arrived...servo positions are in Read_Buffer
        wrbuf[0] = 255           ' 255 is verification value
        HID_WRITE(@wrbuf, 1)     ' reply to host with verification
     End If
  wend

  HID_Disable
 
end.
Now to add another 8 servo's :wink:

OldSpring
Posts: 134
Joined: 07 Feb 2007 00:01

Re: Move code from mEBasic ver 6.XX to mEBasic Pro ver 2.50

#10 Post by OldSpring » 20 Aug 2010 03:37

hi, Philtkp:

Does this code work for mEBasic Pro ver 3.80? I just tried, but it doesn't work for me.

Philtkp
Posts: 307
Joined: 26 Apr 2006 00:58
Location: Tucson Arizona

Re: Move code from mEBasic ver 6.XX to mEBasic Pro ver 2.50

#11 Post by Philtkp » 20 Aug 2010 16:16

OldSpring,
I haven't tried using HID since ver 3.0. I found that once I was able to get the example
running stable, Then I was able to run my code without any problems. When I get home I'll try and see what happens. Are you using one of the EASYPIC boards or your own?

OldSpring
Posts: 134
Joined: 07 Feb 2007 00:01

Re: Move code from mEBasic ver 6.XX to mEBasic Pro ver 2.50

#12 Post by OldSpring » 20 Aug 2010 19:40

Hi, Philtkp:

I'm using my own board. it works fine for MEBasic Pro 3.80 test code and my project code.

If you can run this code under MEBasic Pro 3.80 , please let me know.

Thank you!

OldSpring
Posts: 134
Joined: 07 Feb 2007 00:01

Re: Move code from mEBasic ver 6.XX to mEBasic Pro ver 2.50

#13 Post by OldSpring » 28 Aug 2010 21:12

Hi, Philtkp:

Any news? Waiting......

Philtkp
Posts: 307
Joined: 26 Apr 2006 00:58
Location: Tucson Arizona

Re: Move code from mEBasic ver 6.XX to mEBasic Pro ver 2.50

#14 Post by Philtkp » 29 Aug 2010 01:48

I wasnt able to get to compile either. under 3.8 or 4.0.

EDIT:
This complied under 3.8 and i had to create a new descriptor file
Try changing
TMR0L = WORD(65536-3362) to

Code: Select all

TMR0L = Lo(65536-3362)
and
TMR0H = WORD(65536-1) ' load Timer0 high byte first
TMR0L = WORD(65536-1)

Code: Select all

TMR0H = Hi(65536-1)                     ' load Timer0 high byte first
TMR0L = Lo(65536-1)
and

HID_InterruptProc to

Code: Select all

USB_Interrupt_Proc

OldSpring
Posts: 134
Joined: 07 Feb 2007 00:01

Re: Move code from mEBasic ver 6.XX to mEBasic Pro ver 2.50

#15 Post by OldSpring » 30 Aug 2010 17:04

Hi, Philtkp:
Thank you for you help.
I tried. The code can be complied under MB Pro 3.8, but it doesn't work. ( this project setting works for MB test code).
Below is my test code and USB descriptor file:

Test code:

Code: Select all

program SERVO8_USB
'******************************************************************************************
'*                    18F2550 PIC USB_HID 50Hz PWM SERVO CONTROLLER                       *
'*                     by W. Schroeder alias "xor" -- July 4, 2006                        *
'*                            Revised on September 25, 2006                               *
'*                                                                                        *
'*     Compiled with mikroBASIC 5.0.0.1 and tested on the EasyPIC3 Development Board      *
'* Uses mikroBASIC USB_HID Library and must include "USBdsc.pbas" and "HIDconstant.pbas"  *
'*                                                                                        *
'*   Also required is the free Visual Basic Servo Controller Demo program included with   *
'*           this file. This program has been tested on Windows XP with USB2.0.           *
'*                                                                                        *                                                                                        *
'*   Configuration settings for the 18F2550 are the same as the mikroBASIC 18F2550 HID    *
'*      example found in the mikroBASIC Examples folder in the mikroBASIC directory.      *
'*   These configurations are set up for an 8MHz crystal oscillator and through internal  *
'*    PLL settings this is increased to 48MHz.  This also produces a very fast 12 MIPS.   *
'*                                                                                        *
'*   The EasyPIC3 board provides an easy connection to the PIC via a USB port.  Please    *
'*        refer to the board schematic for ideas for your own circuit connections.        *
'*                                                                                        *
'*         For the purposes of this demo all output pins of PORTB are utilized.           *
'*         Servo[0] is PORTB.0, Servo[1] is PORTB.1,...., Servo[7] is PORTB.7             *
'*                                                                                        *
'*     The range of PWM on-time is 820us to 2180us analogous with values of  1 to 256     *
'*      A value of 128 is considered 50% of servo rotation with an on-time of 1500us      *
'*    Timer0 in 16-bit mode is used to establish an accurate 20ms (50Hz) PWM interval     *
'*                                                                                        *
'******************************************************************************************
'******************************************************************************************

dim
    wrbuf    as  byte[2]
    wr_adr   as  word
    servo    as byte[8]
    temp     as byte

sub procedure interrupt
If (INTCON.TMR0IE = 1) And (INTCON.TMR0IF = 1) Then
  LATB = 255
  temp = 0
  delay_us(820)
  TMR0L = 0
  asm
     movlw    0
     decfsz   _servo+0, 1,0
     iorlw    1
     decfsz   _servo+1, 1,0
     iorlw    2
     decfsz   _servo+2, 1,0
     iorlw    4
     decfsz   _servo+3, 1,0
     iorlw    8
     decfsz   _servo+4, 1,0
     iorlw    16
     decfsz   _servo+5, 1,0
     iorlw    32
     decfsz   _servo+6, 1,0
     iorlw    64
     decfsz   _servo+7, 1,0
     iorlw    128
     andwf    LATB, 1,0
     movf     TMR0L, 0,0
     xorwf    _temp, 0,0
     bz       $-2
     incfsz   _temp, 1,0
     bra      $-22
  end asm                        ' routine has used ~2180us to this point
  TMR0H = Hi(65536-3362)         ' load balance of 20ms in Timer0...high byte first
  TMR0L = Lo(65536-3362)         ' TMR0L = -3362
  INTCON.TMR0IF = 0              ' reset the interrupt flag
Else
    USB_Interrupt_Proc
End If
end sub

sub procedure Init_Main
   INTCON2 = 0xF5
   INTCON3 = 0xC0
   RCON.IPEN = 0                  ' disable Priority Levels on interrupts
   PIE1 = 0                       ' clear all interrupt enables
   PIE2 = 0
   PIR1 = 0
   PIR2 = 0
   ADCON1 = 15                    ' digital IO
   TRISB = 0
   LATB = 0
  T0CON = %00000101              ' prescaler = 64 or 5.3us per increment
  TMR0H = Hi(65536-1)                     ' load Timer0 high byte first
  TMR0L = Lo(65536-1)
  INTCON = %10100000             ' Timer0 Interrupt Enabled and Flag Cleared
  T0CON.7 = 1                    ' Timer0 On
end sub

main:
  Init_Main
  HID_Enable(@servo, @wrbuf)     ' @servo is equivalent to the Read_Buffer
  Delay_mS(1000)
  For temp = 0 to 7
     servo[temp] = 255
  Next temp
  while true
      If HID_READ <> 0 Then      ' if USB package has arrived...servo positions are in Read_Buffer
        wrbuf[0] = 255           ' 255 is verification value
        HID_WRITE(@wrbuf, 1)     ' reply to host with verification
     End If
  wend
  HID_Disable
end.
USB descriptor file:

Code: Select all

module USBdsc

const USB_VENDOR_ID as word = 0x1234
const USB_PRODUCT_ID as word = 0x0001
const USB_SELF_POWER as char = 0x80            ' Self powered 0xC0,  0x80 bus powered
const USB_MAX_POWER as char = 50               ' Bus power required in units of 2 mA
const HID_INPUT_REPORT_BYTES as char = 1
const HID_OUTPUT_REPORT_BYTES as char = 8
const EP_IN_INTERVAL as char = 1
const EP_OUT_INTERVAL as char = 1

const USB_INTERRUPT as char = 0
const USB_TRANSFER_TYPE as char = 0x03         '0x03 Interrupt
const USB_HID_EP as char = 1
const USB_HID_RPT_SIZE as char = 33

structure device_descriptor
    dim bLength as char               ' bLength         - Descriptor size in bytes (12h)
    dim bDescriptorType as char       ' bDescriptorType - The constant DEVICE (01h)
    dim bcdUSB as word                ' bcdUSB          - USB specification release number (BCD)
    dim bDeviceClass as char          ' bDeviceClass    - Class Code
    dim bDeviceSubClass as char       ' bDeviceSubClass - Subclass code
    dim bDeviceProtocol as char       ' bDeviceProtocol - Protocol code
    dim bMaxPacketSize0 as char       ' bMaxPacketSize0 - Maximum packet size for endpoint 0
    dim idVendor as word              ' idVendor        - Vendor ID
    dim idProduct as word             ' idProduct       - Product ID
    dim bcdDevice as word             ' bcdDevice       - Device release number (BCD)
    dim iManufacturer as char         ' iManufacturer   - Index of string descriptor for the manufacturer
    dim iProduct as char              ' iProduct        - Index of string descriptor for the product.
    dim iSerialNumber as char         ' iSerialNumber   - Index of string descriptor for the serial number.
    dim bNumConfigurations as char    ' bNumConfigurations - Number of possible configurations
end structure

const device_dsc as device_descriptor = (
  0x12,                   ' bLength
  0x01,                   ' bDescriptorType
  0x0200,                 ' bcdUSB
  0x00,                   ' bDeviceClass
  0x00,                   ' bDeviceSubClass
  0x00,                   ' bDeviceProtocol
  8,                      ' bMaxPacketSize0
  USB_VENDOR_ID,          ' idVendor
  USB_PRODUCT_ID,         ' idProduct
  0x0001,                 ' bcdDevice
  0x01,                   ' iManufacturer
  0x02,                   ' iProduct
  0x00,                   ' iSerialNumber
  0x01                    ' bNumConfigurations
)

' Configuration 1 Descriptor
const configDescriptor1 as byte[41] = (
    ' Configuration Descriptor
    0x09,                   ' bLength             - Descriptor size in bytes
    0x02,                   ' bDescriptorType     - The constant CONFIGURATION (02h)
    0x29,0x00,              ' wTotalLength        - The number of bytes in the configuration descriptor and all of its subordinate descriptors
    1,                      ' bNumInterfaces      - Number of interfaces in the configuration
    1,                      ' bConfigurationValue - Identifier for Set Configuration and Get Configuration requests
    0,                      ' iConfiguration      - Index of string descriptor for the configuration
    USB_SELF_POWER,         ' bmAttributes        - Self/bus power and remote wakeup settings
    USB_MAX_POWER,          ' bMaxPower           - Bus power required in units of 2 mA

    ' Interface Descriptor
    0x09,                   ' bLength - Descriptor size in bytes (09h)
    0x04,                   ' bDescriptorType - The constant Interface (04h)
    0,                      ' bInterfaceNumber - Number identifying this interface
    0,                      ' bAlternateSetting - A number that identifies a descriptor with alternate settings for this bInterfaceNumber.
    2,                      ' bNumEndpoint - Number of endpoints supported not counting endpoint zero
    0x03,                   ' bInterfaceClass - Class code
    0,                      ' bInterfaceSubclass - Subclass code
    0,                      ' bInterfaceProtocol - Protocol code
    0,                      ' iInterface - Interface string index

    ' HID Class-Specific Descriptor
    0x09,                   ' bLength         - Descriptor size in bytes.
    0x21,                   ' bDescriptorType - This descriptor's type: 21h to indicate the HID class.
    0x01,0x01,              ' bcdHID          - HID specification release number (BCD).
    0x00,                   ' bCountryCode    - Numeric expression identifying the country for localized hardware (BCD) or 00h.
    1,                      ' bNumDescriptors - Number of subordinate report and physical descriptors.
    0x22,                   ' bDescriptorType - The type of a class-specific descriptor that follows
    USB_HID_RPT_SIZE,0x00,  ' wDescriptorLength - Total length of the descriptor identified above.

    ' Endpoint Descriptor
    0x07,                   ' bLength - Descriptor size in bytes (07h)
    0x05,                   ' bDescriptorType - The constant Endpoint (05h)
    USB_HID_EP or 0x80,     ' bEndpointAddress - Endpoint number and direction
    USB_TRANSFER_TYPE,      ' bmAttributes - Transfer type and supplementary information
    0x40,0x00,              ' wMaxPacketSize - Maximum packet size supported
    EP_IN_INTERVAL,         ' bInterval - Service interval or NAK rate

    ' Endpoint Descriptor
    0x07,                   ' bLength - Descriptor size in bytes (07h)
    0x05,                   ' bDescriptorType - The constant Endpoint (05h)
    USB_HID_EP,             ' bEndpointAddress - Endpoint number and direction
    USB_TRANSFER_TYPE,      ' bmAttributes - Transfer type and supplementary information
    0x40,0x00,              ' wMaxPacketSize - Maximum packet size supported
    EP_OUT_INTERVAL         ' bInterval - Service interval or NAK rate
)

structure hid_report_descriptor
  dim report as char[USB_HID_RPT_SIZE]
end structure

const hid_rpt_desc as hid_report_descriptor = (
  (0x06, 0x00, 0xFF,      ' Usage Page = 0xFF00 (Vendor Defined Page 1)
  0x09, 0x01,             ' Usage (Vendor Usage 1)
  0xA1, 0x01,             ' Collection (Application)
  ' Input report
  0x19, 0x01,             ' Usage Minimum
  0x29, 0x40,             ' Usage Maximum
  0x15, 0x00,             ' Logical Minimum (data bytes in the report may have minimum value = 0x00)
  0x26, 0xFF, 0x00,       ' Logical Maximum (data bytes in the report may have maximum value = 0x00FF = unsigned 255)
  0x75, 0x08,             ' Report Size: 8-bit field size
  0x95, HID_INPUT_REPORT_BYTES,' Report Count
  0x81, 0x02,             ' Input (Data, Array, Abs)
  ' Output report
  0x19, 0x01,             ' Usage Minimum
  0x29, 0x40,             ' Usage Maximum
  0x75, 0x08,             ' Report Size: 8-bit field size
  0x95, HID_OUTPUT_REPORT_BYTES,' Report Count
  0x91, 0x02,             ' Output (Data, Array, Abs)
  0xC0)                   ' End Collection
  )

'Language code string descriptor
structure str1
  dim bLength as char
  dim bDscType as char
  dim wString as word[1]
end structure

const strd1 as str1 = (
  4,
  0x03,
  (0x0409)
)

'Manufacturer string descriptor
structure str2
  dim bLength as char
  dim bDscType as char
  dim wString as word[16]
end structure

const strd2 as str2 = (
  34,           'sizeof this descriptor string
  0x03,
  ("M","i","k","r","o","e","l","e","k","t","r","o","n","i","k","a")
)

'Product string descriptor
structure str3
  dim bLength as char
  dim bDscType as char
  dim wString as word[23]
end structure

const strd3 as str3 = (
  32,           'sizeof this descriptor string
  0x03,
  ("U","S","B"," ","H","I","D"," ","L","i","b","r","a","r","y")
)


dim USB_config_dsc_ptr as ^const char[1]

dim USB_string_dsc_ptr as ^const char[3]

sub procedure USB_Init_desc()

implements
  sub procedure USB_Init_desc()
    USB_config_dsc_ptr[0] = @configDescriptor1
    USB_string_dsc_ptr[0] = ^const char(@strd1)
    USB_string_dsc_ptr[1] = ^const char(@strd2)
    USB_string_dsc_ptr[2] = ^const char(@strd3)
  end sub
end.
Could you give me some suggestion?
Thank you.

Post Reply

Return to “mikroBasic PRO for PIC General”