I trying to build this project, before that i try to compile the code to Bascom, but i am getting an error.
Could anyone here help me to solve the problem where is the core.
Below are the code.
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- 'USB Keyboard Emulator Example
- 'ollopa 2009-2012
- '
- 'This project emulates a standard 105 key USB keyboard.
- 'PORTB shows the status of the keyboard LEDs (CAPS lock, NUMLOCK, etc)
- 'PORTA connects to STK500 buttons.
- ' BTN0 = send "hello" message.
- ' BTN1 = send "A"
- 'Note: Buttons and LEDs are inverted due to STK500's inverted logic (0 = pressed / on)
- '
- 'Test setup is on the STK500 with Vtarget set to 3.6V
- 'Using an atmega644 and external 12MHz crystal
- 'Save about 38 bytes of code size
- $noramclear
- $hwstack = 30
- $swstack = 30
- $framesize = 40 '24 bytes reserved
- Rem porta.0 = 1
- Rem
- '$regfile = "attiny85.dat"
- $regfile = "m8def.dat"
- $crystal = 12000000
- '$crystal = 15000000
- 'Include the software USB library
- $lib "swusb.lbx"
- $external _swusb
- $external Crcusb
- '****************************************************************************
- '****************************************************************************
- '*******************************************************************************
- '************************* USB Configuration Constants *************************
- 'Use EEPROM or FLASH to store USB descriptors
- '1 = EEPROM, 0 = FLASH. Storing to EEPROM will reduce code size slightly.
- Const _usb_use_eeprom = 0
- 'Don't wait for sent packets to be ACK'd by the host before marking the
- 'transmission as complete. This option breaks the USB spec but improves
- 'throughput with faster polling speeds.
- 'This may cause reliability issues. Should leave set to 0 to be safe.
- Const _usb_assume_ack = 0
- '***************************** Device Descriptor *******************************
- 'USB Vendor ID and Product ID (Assigned by USB-IF)
- 'Const _usb_vid = &HBBBB
- 'Const _usb_pid = &HEF33
- 'USB Device Release Number (BCD)
- 'Const _usb_devrel = &H0001
- 'USB Release Spec (BCD)
- 'Const _usb_spec = &H0110
- 'USB Device Class, subclass, and protocol (assigned by USB-IF).
- '&h00 = Class defined by interface. (HID is defined in the interface)
- '&hFF = Vendor-defined class (You must write your own PC driver)
- 'See http://www.usb.org/developers/defined_class for more information
- Const _usb_devclass = 0
- Const _usb_devsubclass = 0
- Const _usb_devprot = 0
- 'These are _indexes_ to UNICODE string descriptors for the manufacturer,
- 'product name, and serial number. 0 means there is no descriptor.
- Const _usb_imanufacturer = 1
- Const _usb_iproduct = 2
- Const _usb_iserial = 0
- 'Number of configurations for this device. Don't change this unless
- 'you know what you are doing. Ordinarily it should just be 1.
- Const _usb_numconfigs = 1
- '***************************** Descriptor configuration ************************
- 'The number of interfaces for this device
- 'Const _usb_numifaces = 1
- Const _usb_numifaces = 2 'Now we have 2 interfaces !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 'Configuration Number (do not edit)
- Const _usb_confignum = 1
- 'Index of UNICODE string descriptor that describes this config (0 = None)
- 'Const _usb_iconfig = 2
- Const _usb_iconfig = 0 'Not needed !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- '&H80 = device powered from USB bus.
- '&HC0 = self-powered (has a power supply)
- 'Const _usb_powered = &HC0
- 'Const _usb_powered = &HA0 'Device powered from USB bus and can wakeup it !!!!!!!!!!!!!!!!!
- 'Required current in 2mA increments (500mA max)
- Const _usb_maxpower = 50 '50 * 2mA = 100mA
- '**************************** Interface Descriptor *****************************
- 'Number of interfaces for this device (1 or 2)
- 'Const _usb_ifaces = 1
- Const _usb_ifaces = 2 'Now we have 2 interfaces !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 'Interface numbers
- Const _usb_ifaceaddr = 0
- Const _usb_ifaceaddr1 = 1 'Second Interface number **************************************
- 'Alternate indexes
- Const _usb_alternate = 0
- Const _usb_alternate1 = 0 'Second Interface Alternate index *****************************
- 'Number of endpoints for each interface (excluding endp 0)
- 'Const _usb_ifaceendpoints = 2
- Const _usb_ifaceendpoints = 1 'First Interface Endpoint !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- Const _usb_ifaceendpoints1 = 1 'Second Interface Endpoint *************************************
- 'USB Interface Class, subclass, and protocol (assigned by USB-IF).
- '&h00 = RESERVED
- '&hFF = Vendor-defined class (You must write your own PC driver)
- ' Other values are USB interface device class. (such as HID)
- 'See http://www.usb.org/developers/defined_class for more information
- Const _usb_ifclass = 3 'Interrupt class
- Const _usb_ifclass1 = 3 'Interrupt class **********************************************
- 'Const _usb_ifsubclass = 0
- Const _usb_ifsubclass = 1 'Subclass 1 for keyboard !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- Const _usb_ifsubclass1 = 0 'Subclass 0 for multimedia ************************************
- 'Const _usb_ifprotocol = 0
- Const _usb_ifprotocol = 1 'For first interface !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- Const _usb_ifprotocol1 = 0 'For second interface *****************************************
- 'Index to UNICODE string descriptor for this interface (0 = None)
- Const _usb_iiface = 0
- Const _usb_iiface1 = 0 'The same for second interface *********************************
- '*************************** Optional HID Descriptor ***************************
- 'HID class devices are things like keyboard, mouse, joystick.
- 'See http://www.usb.org/developers/hidpage/ for the specification,
- 'tools, and resources.
- 'Note that for a HID device, the device class, subclass, and protocol
- 'must be 0. The interface class must be 3 (HID).
- 'Interface subclass and protocol must be 0 unless you are making a
- 'keyboard or a mouse that supports the predefined boot protocol.
- 'See pages 8 and 9 of the HID 1.11 specification PDF.
- 'Number of HID descriptors (EXCLUDING report and physical)
- 'If you are not making a HID device, then set this constant to 0
- 'Const _usb_hids = 1
- Const _usb_hids = 2 'Now we have 2 HIDs !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 'BCD HID releasenumber. Current spec is 1.11
- Const _usb_hid_release = &H0111
- 'Country code from page 23 of the HID 1.11 specifications.
- 'Usually the country code is 0 unless you are making a keyboard.
- Const _usb_hid_country = 0
- 'The number of report and physical descriptors for this HID
- 'Must be at least 1! All HID devices have at least 1 report descriptor.
- Const _usb_hid_numdescriptors = 1 'Here we set the number of descriptors for each interface separately, but use it twice
- 'Use a software tool to create the report descriptor and $INCLUDE it.
- '*************************** Endpoint Descriptor(s) ****************************
- 'Endpoint 0 is not included here. These are only for optional
- 'endpoints.
- 'Note: HID devices require 1 interrupt IN endpoint
- 'Address of optional endpoints (Must be > 0. comment-out to not use)
- Const _usb_endp2addr = 1
- Const _usb_endp3addr = 2
- 'Valid types are 0 for control or 3 for interrupt
- Const _usb_endp2type = 3
- Const _usb_endp3type = 3
- 'Directions Are : 0 = Out , 1 = In. Ignored By Control Endpoints
- Const _usb_endp2direction = 1
- 'Const _usb_endp3direction = 0
- Const _usb_endp3direction = 1 'Now this point is IN too !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 'Polling interval (ms) for interrupt endpoints. Ignored by control endpoints
- ' (Must be at least 10)
- Const _usb_endp2interval = 10
- Const _usb_endp3interval = 10
- '*****************************************************************************
- '*****************************************************************************
- $include "multikbd_declarations.inc"
- Declare Sub Typemessage(message As String)
- Declare Sub Typekey(key As Byte)
- Declare Function Ascii2usage(ascii As Byte) As Word
- Declare Function Crcusb(buffer() As Byte , Count As Byte) As Word
- '**************************** USB Interrupt And Init ***************************
- 'Set all the variables, flags, and sync bits to their initial states
- Call Usb_reset()
- Const _usb_intf = Intf0
- Config Int0 = Rising
- On Int0 Usb_isr Nosave
- Enable Int0
- Enable Interrupts
- '*******************************************************************************
- '*************************** End Of USB Configuration **************************
- Config Pinb.1 = Input : Portb.1 = 1
- Config Pinb.2 = Input : Portb.2 = 1
- Dim Resetcounter As Word
- Dim Idlemode As Byte
- Dim Keybd_leds As Byte 'keyboard status LEDs (numlock, capslock, etc.)
- Dim Message As String * 10
- Dim Akey As Byte
- Dim Paus As Byte
- Paus = 70
- Message = "BARTek "
- Do
- Resetcounter = 0
- Call Usb_check_reset
- Akey = Usb_check_rx()
- '############# THIS TYPE "BARTek" if unmarked and switch pressed (I test KB option on Mega8)
- 'BARTek BARTek BARTek BARTek BARTek BARTek BARTek BARTek BARTek BARTek BARTek BARTek BARTek BARTek
- '#######################################################################
- ' If Pinb.1 = 0 Then
- ' Call Typemessage(message)
- ' End If
- '######################################################################
- If Pinb.1 = 0 Then
- If _usb_tx_status._usb_txc = 1 Then ' Volume-
- _usb_tx_buffer3(2) = 1
- _usb_tx_buffer3(3) = 234
- _usb_tx_buffer3(4) = 0
- Call Usb_send(_usb_tx_status3(1) , 3)
- Waitms Paus
- End If
- If _usb_tx_status._usb_txc = 1 Then
- _usb_tx_buffer3(2) = 1
- _usb_tx_buffer3(3) = 0
- _usb_tx_buffer3(4) = 0
- Call Usb_send(_usb_tx_status3(1) , 3)
- Waitms Paus
- End If
- End If
- If Pinb.2 = 0 Then
- If _usb_tx_status._usb_txc = 1 Then ' Volume+
- _usb_tx_buffer3(2) = 1
- _usb_tx_buffer3(3) = 233
- _usb_tx_buffer3(4) = 0
- Call Usb_send(_usb_tx_status3(1) , 3)
- Waitms Paus
- End If
- If _usb_tx_status._usb_txc = 1 Then
- _usb_tx_buffer3(2) = 1
- _usb_tx_buffer3(3) = 0
- _usb_tx_buffer3(4) = 0
- Call Usb_send(_usb_tx_status3(1) , 3)
- Waitms Paus
- End If
- End If
- Loop
- End
- 'BARTek BARTek BARTek BARTek BARTek BARTek BARTek BARTek BARTek BARTek BARTek BARTek BARTek BARTek
- '#######################################################################
- $include "swusb_routines.inc"
- Sub Typemessage(message As String)
- Local Count As Byte
- Local Key As Byte
- Local Char As String * 1
- For Count = 1 To Len(message)
- Char = Mid(message , Count , 1)
- Key = Asc(char)
- Call Typekey(key)
- Next
- End Sub
- Sub Typekey(key As Byte)
- Local Usage As Word
- Usage = Ascii2usage(key)
- Do : Loop Until _usb_tx_status2(1)._usb_txc = 1
- ' Key down
- _usb_tx_buffer2(2) = High(usage) 'Modifier keys (shift, ctl, alt, etc)
- _usb_tx_buffer2(3) = 0 'Reserved. Always 0
- _usb_tx_buffer2(4) = Low(usage) 'key1
- _usb_tx_buffer2(5) = 0 'key2
- _usb_tx_buffer2(6) = 0 'key3
- _usb_tx_buffer2(7) = 0 'key4
- _usb_tx_buffer2(8) = 0 'key5
- _usb_tx_buffer2(9) = 0 'key6
- Call Usb_send(_usb_tx_status2(1) , 8)
- ' Key up
- Do : Loop Until _usb_tx_status2(1)._usb_txc = 1
- _usb_tx_buffer2(2) = 0 'Modifier keys (shift, ctl, alt, etc)
- _usb_tx_buffer2(3) = 0 'Reserved. Always 0
- _usb_tx_buffer2(4) = 0 'key1
- _usb_tx_buffer2(5) = 0 'key2
- _usb_tx_buffer2(6) = 0 'key3
- _usb_tx_buffer2(7) = 0 'key4
- _usb_tx_buffer2(8) = 0 'key5
- _usb_tx_buffer2(9) = 0 'key6
- Call Usb_send(_usb_tx_status2(1) , 8)
- End Sub
- End
- '*******************************************************************************
- '******************** Descriptors stored in EEPROM or FLASH ********************
- ' Do not change the order of the descriptors!
- '
- #if _usb_use_eeprom = 1
- $eeprom
- #else
- $data
- #endif
- 'Device Descriptor
- _usb_devicedescriptor:
- Data 18 , 18 , _usb_desc_device , _usb_specl , _usb_spech , _usb_devclass
- Data _usb_devsubclass , _usb_devprot , 8 , _usb_vidl , _usb_vidh , _usb_pidl
- Data _usb_pidh , _usb_devrell , _usb_devrelh , _usb_imanufacturer
- Data _usb_iproduct , _usb_iserial , _usb_numconfigs
- 'Retrieving the configuration descriptor also gets all the interface and
- 'endpoint descriptors for that configuration. It is not possible to retrieve
- 'only an interface or only an endpoint descriptor. Consequently, this is a
- 'large transaction of variable size.
- _usb_configdescriptor:
- Data _usb_descr_total , 9 , _usb_desc_config , _usb_descr_totall
- Data _usb_descr_totalh , _usb_numifaces , _usb_confignum , _usb_iconfig
- Data _usb_powered , _usb_maxpower
- '_usb_IFaceDescriptor
- Data 9 , _usb_desc_iface , _usb_ifaceaddr , _usb_alternate
- Data _usb_ifaceendpoints , _usb_ifclass , _usb_ifsubclass , _usb_ifprotocol
- Data _usb_iiface
- '#if _usb_hids > 0
- '_usb_HIDDescriptor
- Data _usb_hid_descr_len , _usb_desc_hid , _usb_hid_releasel , _usb_hid_releaseh
- Data _usb_hid_country , _usb_hid_numdescriptors
- 'Next follows a list of bType and wLength bytes/words for each report and
- 'physical descriptor.
- Data _usb_desc_report
- Data 63 , 0
- 'End of report/physical descriptor list
- '#endif
- '#if _usb_endpoints > 1
- '_usb_EndpointDescriptor
- Data 7 , _usb_desc_endpoint , _usb_endp2attr , _usb_endp2type , 8 , 0
- Data _usb_endp2interval
- '#endif
- '_usb_IFaceDescriptor1 *************************************************************************************
- Data 9 , _usb_desc_iface , _usb_ifaceaddr1 , _usb_alternate1 ' ***********
- Data _usb_ifaceendpoints1 , _usb_ifclass1 , _usb_ifsubclass1 , _usb_ifprotocol1 ' ***********
- Data _usb_iiface1 ' ***********
- '_usb_HIDDescriptor1 *************************************************************************************
- Data _usb_hid_descr_len , _usb_desc_hid , _usb_hid_releasel , _usb_hid_releaseh ' ***********
- Data _usb_hid_country , _usb_hid_numdescriptors , _usb_desc_report ' ***********
- Data 50 , 0 ' ***********
- '#if _usb_endpoints > 2
- '_usb_EndpointDescriptor
- 'Data 7 , _usb_desc_endpoint , _usb_endp3attr , _usb_endp3type , 8 , 0
- Data 7 , _usb_desc_endpoint , _usb_endp3attr , _usb_endp3type , 3 , 0 'Multimedia message lenght is 3 bytes !!!!!!!!!!!!!!!!
- Data _usb_endp3interval
- '#endif
- #if _usb_hids > 0
- _usb_hid_reportdescriptor:
- Data 63
- Data &H05 , &H01 ' USAGE_PAGE (Generic Desktop)
- Data &H09 , &H06 ' USAGE (Keyboard)
- Data &HA1 , &H01 ' COLLECTION (Application)
- Data &H05 , &H07 ' USAGE_PAGE (Keyboard)
- Data &H19 , &HE0 ' USAGE_MINIMUM (Keyboard LeftControl)
- Data &H29 , &HE7 ' USAGE_MAXIMUM (Keyboard Right GUI)
- Data &H15 , &H00 ' LOGICAL_MINIMUM (0)
- Data &H25 , &H01 ' LOGICAL_MAXIMUM (1)
- Data &H75 , &H01 ' REPORT_SIZE (1)
- Data &H95 , &H08 ' REPORT_COUNT (8)
- Data &H81 , &H02 ' INPUT (Data,Var,Abs)
- Data &H95 , &H01 ' REPORT_COUNT (1)
- Data &H75 , &H08 ' REPORT_SIZE (8)
- Data &H81 , &H03 ' INPUT (Cnst,Var,Abs)
- Data &H95 , &H05 ' REPORT_COUNT (5)
- Data &H75 , &H01 ' REPORT_SIZE (1)
- Data &H05 , &H08 ' USAGE_PAGE (LEDs)
- Data &H19 , &H01 ' USAGE_MINIMUM (Num Lock)
- Data &H29 , &H05 ' USAGE_MAXIMUM (Kana)
- Data &H91 , &H02 ' OUTPUT (Data,Var,Abs)
- Data &H95 , &H01 ' REPORT_COUNT (1)
- Data &H75 , &H03 ' REPORT_SIZE (3)
- Data &H91 , &H03 ' OUTPUT (Cnst,Var,Abs)
- Data &H95 , &H06 ' REPORT_COUNT (6)
- Data &H75 , &H08 ' REPORT_SIZE (8)
- Data &H15 , &H00 ' LOGICAL_MINIMUM (0)
- Data &H25 , &H65 ' LOGICAL_MAXIMUM (101)
- Data &H05 , &H07 ' USAGE_PAGE (Keyboard)
- Data &H19 , &H00 ' USAGE_MINIMUM (Reserved (no event indicated))
- Data &H29 , &H65 ' USAGE_MAXIMUM (Keyboard Application)
- Data &H81 , &H00 ' INPUT (Data,Ary,Abs)
- Data &HC0 ' END_COLLECTION
- _usb_hid_reportdescriptor1: ' ************
- Data 50 ' ************
- Data &H05 , &H0C 'Usage Page (Consumer Devices) ************
- Data &H09 , &H01 'Usage (Consumer Control) ************
- Data &HA1 , &H01 'Collection (Application) ************
- Data &H85 , &H01 ' Report ID (1) ************
- Data &H19 , &H00 ' Usage Minimum (Undefined) ************
- Data &H2A , &H3C , &H02 ' Usage Maximum (reserved 0x023c) ************
- Data &H15 , &H00 ' Logical Minimum (0) ************
- Data &H26 , &H3C , &H02 ' Logical Maximum (572) ************
- Data &H95 , &H01 ' Report Count (1) ************
- Data &H75 , &H10 ' Report Size (16) ************
- Data &H81 , &H00 ' Input (Data,Ary,Abs) ************
- Data &HC0 'End Collection ************
- Data &H05 , &H01 'Usage Page (Generic Desktop) ************
- Data &H09 , &H80 'Usage (System Control) ************
- Data &HA1 , &H01 'Collection (Application) ************
- Data &H85 , &H02 ' Report ID (2) ************
- Data &H19 , &H81 ' Usage Minimum (System Power Down) ************
- Data &H29 , &H83 ' Usage Maximum (System Wake Up) ************
- Data &H25 , &H01 ' Logical Maximum (1) ************
- Data &H75 , &H01 ' Report Size (1) ************
- Data &H95 , &H03 ' Report Count (3) ************
- Data &H81 , &H02 ' Input (Data,Var,Abs,NWrp,Lin,Pref,NNul,Bit) ************
- Data &H95 , &H05 ' Report Count (5) ************
- Data &H81 , &H01 ' Input (Cnst,Ary,Abs) ************
- Data &HC0 'End Collection ************
- #endif
- '*****************************String descriptors********************************
- 'Yes, they MUST be written like "t","e","s","t". Doing so pads them with
- '0's. If you write it like "test," I promise you it won't work.
- 'Default language descriptor (index 0)
- _usb_langdescriptor:
- Data 4 , 4 , _usb_desc_string , 09 , 04 '&h0409 = English
- 'Manufacturer Descriptor (unicode)
- _usb_mandescriptor:
- Data 14 , 14 , _usb_desc_string
- Data "o" , "l" , "l" , "o" , "p" , "a"
- 'Product Descriptor (unicode)
- _usb_proddescriptor:
- Data 46 , 46 , _usb_desc_string
- Data "o" , "l" , "l" , "o" , "p" , "a" , "'" , "s" , " " , "k" , "e" , "y" , "b" , "o" , "a" , "r" , "d" , " "
- Data "v" , "1" , "." , "0"
- _usb_numdescriptor:
- Data 4 , 4 , _usb_desc_string
- Data "2" , 0 , 0
- '*******************************************************************************
- Function Ascii2usage(ascii As Byte) As Word
- Local Result As Word
- 'Maps common (mostly printable) ASCII characters to USB Keyboard usage codes
- 'Returns two bytes: keyboard modifier flags and key code
- 'Modifier bits:
- '0 LEFT CTRL
- '1 LEFT SHIFT
- '2 LEFT ALT
- '3 LEFT GUI
- '4 RIGHT CTRL
- '5 RIGHT SHIFT
- '6 RIGHT ALT
- '7 RIGHT GUI
- 'USB Keyboard usage codes
- '0 No event (no keys pressed)
- '1 Keyboard ErrorRollOver
- '2 Keyboard POSTFail
- '3 Undefined Keyboard Error
- 'Standard Keyboard keys
- '04-29 (a and A) to (z and Z) Letters
- '30-39 (1 and !) to (0 and )) Numbers
- '40 Enter/Return (^m)
- '41 Escape
- '42 Backspace (^h)
- '43 Tab
- '44 Space
- '45 - and _
- '46 = and +
- '47 [ and {
- '48 ] and }
- '49 \ and |
- '50 Non-US # and ~ or \ and |
- '51 ; and :
- '52 ' and "
- '53 ` and ~
- '54 , and <
- '55 . and >
- '56 / and ?
- '57 CAPS LOCK
- '58-69 F1 - F12
- '70 PRINT SCREEN
- '71 SCROLL LOCK
- '72 Pause
- '73 Insert
- '74 Home
- '75 PageUp
- '76 Delete
- '77 End
- '78 PageDown
- '79 Right Arrow
- '80 Left Arrow
- '81 Down Arrow
- '82 Up Arrow
- 'Standard Keypad keys (ten-key)
- '83 Keypad Numlock
- '84 Keypad /
- '85 Keypad *
- '86 Keypad -
- '87 Keypad +
- '88 Keypad ENTER
- '89-98 Keypad 1-0
- '99 Keypad . and DEL
- Select Case Ascii
- Case "a" To "z":
- Result = Ascii - 93
- Case "A" To "Z":
- Result = Ascii - 61
- Result = Result Or &B00000010_00000000 'left shift modifier
- Case "1" To "9":
- Result = Ascii - 19
- Case "0":
- Result = 39
- Case " ":
- Result = 44
- Case Else:
- Result = 0
- End Select
- Ascii2usage = Result
- End Function
Thank you.
Weako.