📄 tusb2136kbfw programmer guide.txt
字号:
void GetVidPidSetting(void)
{
s0123 = bVIDSTA;
The above code starts by setting the variable s0123 to the initial value of the VIDSTA port. This is used later in main() to establish the VID/PID mask.
for(fncOffset = 0; fncOffset < 17; fncOffset++ )
if(funcDefs[fncOffset].s0123 == s0123 || funcDefs[fncOffset].s0123 == 0xFF )
break;
The for() loop above traverses through the funcDefs[] structure (explained below) in order to find the configuration that corresponds with the current VID/PID setting, held at this point in s0123. However, if it finds the 0xFF entry in the funcDefs[] table, it uses that entry as the default.
The fncOffset variable is used in the rest of the program to reference the elements in the funcDefs[] structure.
FuncDefs[] Structure: The funcDefs[] structure holds configuration-specific information for all of the possible product VID/PID options supported by the firmware. Since the VIDSTA value is determined by 4 pins (S0-S3) at boot time, there are a maximum of 16 possible configuration options, each of which has an entry in the funcDefs[] structure. However, the funcDefs[] structure is defined as 17 elements so that the final default (0xFF) entry may be included.
The first entry in the table is presented as follows:
struct FUNCDEF_STRUCT code funcDefs[17] = {
// VID/PID Setting 0 *******************************
{0, // S0S1 value
0x0001, 0x0002, // HUB VID/PID */
0x0003, 0x0004, // FNC VID/PID */
0x1234, // FNC revision level
"Texas Instruments",
"Texas Instruments TUSB2136 Keyboard (Ver 0)",
NULL},
Field #1: S0123. The first element of the table, in this case "0", is the VID/PID setting. Once the product configuration is determined in GetVidPidSetting(), the routine searches for an entry in the funcDefs[] table. It looks for a match and, if one isn't found, it looks for an entry with s0123 = 0xFF which is assumed to be the default value.
Field #2: hubVID. This is the 16-bit VID that will be assigned to the HUB when the corresponding product configuration is selected.
Field #3: hubPID. This is the 16-bit PID that will be assigned to the HUB when the corresponding product configuration is selected.
Field #4: fncVID. This is the 16-bit VID that will be assigned to the function (keyboard) when the corresponding product configuration is selected.
Field #5: fncPID. This is the 16-bit PID that will be assigned to the function (keyboard) when the corresponding product configuration is selected.
Field #6: fncRevision. This is the 16-bit Revision level that is assigne to the function and will be reported to the host in the function descriptors.
Field #6: mfgDescription. This is a character string which contains the description of the manufacturer that will be returned to the host in the function descriptors.
Field #7: prodDescription. This is a character string which contains the description of the product that will be returned to the host in the function descriptors.
Field #8: serialNumber. This is a character string which contains the serial number of the device. This string is normally left blank. If it is used, it must be guaranteed to be a unique value such that two of the devices attached to the same host will not use the same serial number.
SOURCE FILE: "DESCRIP.C"
The Descrip.c source file contains the basic definition of the descriptors that are returned to the host when requested.
AbromDeviceDescriptor[]: This is the 18 byte (12h) device descriptor. The specification of the components of the Device Descriptor may be found in the USB specification. This descriptor is copied to the descriptor XRAM buffer when the descriptor is requested, and a number of the component values are modified at run-time with values selected by the VID/PID configuration. The values that are modified at run-time are so noted with comments in descrip.c.
AbromConfigurationDescriptorGroup[]: This contains the configuration descriptor group which includes the configuration, interface, HID, and endpoint #1 descriptor. The values contained in this definition are exactly what will be sent to the host when the configuration group descriptor is requested. No changes are made to these values at run-time.
AbromReportDescriptor[]: This is the HID Report Descriptor. It defines the format of the data that is sent to the host from the HID function as well as the data that is sent from the host to the keyboard. See the HID Specification for more details on Report Descriptors.
SOURCE FILE: "USBINIT.C"
The UsbInit.C source file contains a number of routines used to initialize the USB features of the hardware-specifically it initializes the host and function, along with the necessary interrupts to drive them.
InitializeUsbHub(): This function initializes the USB hub. This causes the hub to connect upstream, to the host or upstream hub. This is called once at boot time by main() in keyboard.c.
UsbReset(): This function resets the USB function. It is called at boot time and whenever a Reset command is received by the function. It resets the device by setting the function address to 00 and initializing the endpoints.
InitializeUsbFunction(): This function initializes the necessary interrupts and calls the UsbReset() function. It is called only at boot time to initialize the functions and the interrupts.
InitializeUsbData(): This function sets a number of function and hub-related values. Called by UsbReset(). Could probably be consolidated into UsbReset().
SOURCE FILE: "USB.C"
The Usb.C source file contains virtually all USB-related functions. These functions are directly related to the USB operations of the firmware. The only USB-related functions that are not contained in this source file are the initialization routines that are contained in UsbInit.C, and routines that are very keyboard-specific, which are contained in Keyboard.c.
usbGetConfiguration (): This function is called when a GetConfiguration request is received. It sends the value contained in the variable bConfigurationNumber.
usbSetConfiguration (): This function is called when a SetConfiguration command is received. It sets the value of the bConfigurationNumber variable to the value specified.
UsbSetReport(): This function is called when a SetReport command is received. At this point, the data that follows is the value that will be assigned to the keyboard LEDs. The function sets the pointer to th bLed variable so that the subsequent data received will be placed in that variable.
UsbGetDeviceDescriptor(): This function is called when a GetDeviceDescriptor command is received. The descriptor template is copied from abromDeviceDescriptor (see descrip.c), and pertinent values are modified on-the-fly. The fully constructed descriptor is then sent back to the host.
UsbGetHIDDescriptor(): This function is called when a GetHIDDescriptor command is received. The HID descriptor portion of the abromConfigurationDescriptorGroup array (see descrip.c) is then sent back to the host.
UsbGetConfigurationDescriptor(): This function is called when a GetConfigurationDescriptor command is received. The entire configuration descriptor group abromConfigurationDescriptorGroup (see descrip.c) is sent back to the host.
UsbGetStringDescriptor(): This function is called when a GetStringDescriptor command is received. It determines the index of the string descriptor that is to be sent to the host. The string descriptor is determined and constructed on-the-fly and send back to the host.
UsbGetReportDescriptor(): This function is called when a GetReportDescriptor command is received. It sends the function's report descriptor back to the host.
UsbSetIdle(), UsbGetIdel(): These two functions, according to the HID specification, are optional. This firmware doesn't support either function, and just stalls the endpoint.
UsbGetInterface(): This function returns the current interface, as specified in the variable bInterfaceNumber.
UsbSetInterface(): This function sets the variable bInterfaceNumber to the specified value.
UsbGetDeviceStatus(): This function returns to the host the current device feature status, as contained in the variable wDeviceFeatures.
UsbSetRemoteWakeup(): This function is called when a SetRemoteWakeup command is received. This allows the keyboard to wake up the USB bus when it is in suspend mode and activity is detected on the keyboard.
UsbClearRemoteWakeup(): This function is called when a ClearRemoteWakeup command is received. This disables the RemoteWakeup feature outlined in the previous command.
UsbGetInterfaceStatus(): This function is called when a GetInterfaceStatus command is received. In this firmware, it always returns 0000h.
UsbSetAddress(): This function allows the host to assign an address to the function. This command is generally received after a USB reset.
UsbSetEndpointHalt(): This function is used to allow the host to disable an endpoint. This is generally used by a host if it determines that a function endpoint is out of control.
UsbClearEndpointHalt(): This function is used to re-enable an endpoint that has been disabled with the previous command.
UsbGetEndpointStatus(): This function sends the host the current status of the specified endpoint. Specifically, it indicates whether the given endpoint is in a Halted state or not.
UsbNonStandardRequest(): This function is called if a request is received by the firmware that is not recognized as a valid request. In this case, the endpoint is stalled to indicate that the given request is not supported.
UsbDecodeAndProcessUsbRequest(): This function is called when a request is received via Endpoint 0. It searches the tUsbRequestList table to find an entry that matches the current request, and calls the corresponding function-or UsbNonStandardRequest(), if no match is found.
UsbStallEndpoint0(): Stalls both Input and Output Endpoint #0.
UsbReceiveDataPacketOnEP0(): This function is called to receive data on endpoint #0. This function assigns the address of the buffer where the incoming data will be stored.
UsbReceiveNextPacketOnOEP0(): This function is called when a data packet has actually been received on Endpoint #0. It will store the incoming data in the address that was previously established when UsbReceiveDataPacketOnEP0() was called.
UsbSendZeroLengthPacketOnIEP(): This function will send a zero-length data packet on Input Endpoint #0. A zero-length packet is a common form of responding to the host.
UsbSendDataPacketOnEP0(): This function initializes a transfer of data from the function to the host via Input Endpoint #0. The address of the buffer is passed to the function.
UsbSendNextPacketOnIEP0(): This function sends the next packet of data from the buffer that was deined in the previous call to UsbSendDataPAcketOnEP0().
SetupPacketInterruptHandler(): This function is called when a Setup packet interrupt is triggered. This happens when a setup packet is received on Endpoint #0. It calls UsbDecodeAndProcessUsbRequest to determine what request or command is being received.
OEP0InterruptHandler(): This function is called when an Output Endpoint #0 interrupt occurs. This occurs after a packet of data has been received on Output Endpoint #0. The routine either resets the endpoint to receive the next packet of data if more data is expected, or stalls the endpoint if no more data is expected.
IEP0InterruptHandler(): This function is called when an Input Endpoint #0 interrupt occurs. This occurs after a packet of data has been sent on Input Endpoint #0 to the host. The routine either prepares to send the next packet of data from the buffer, sets the function address if this is in response to a set address command, or stalls the endpoint if there is no more data to send.
USBInterrupt(): This function is the USB interrupt routine. It is called whenever an interrupt is generated by the USB subsystem. Based on the source of the USB interrupt, the appropriate function is called to handle the interrupt.
P33Interrupt(): This function is called when the keyboard is in suspend mode and keyboard activity causes the function to wakeup.
SOURCE FILE: "SUPPORT.C"
The Support.C source file contains general support routines that are used throughout the project.
Strlen(): This function performs the same function as the normal 'C' strlen function. It is coded in this module since it produces smaller firmware than using the strlen function included in the IAR 'C' library.
Memcpy():This function performs the same function as the normal 'C' memcpy function. It is coded in this module since it produces smaller firmware than using the memcpy function included in the IAR 'C' library.
Memcmp(): This function compares the two memory blocks indicated in the parameters for the length also indicated and determines whether they are the same. A zero return indicates the two areas of memory are the same while a non-zero return indicates the two memory areas are different.
SendUartByte(): This sends the value that it is passed to the serial port. This is a debug routine that is only enabled if the SERIALDEBUG define is enabled.
SendUartString(): This sends the given string to the serial port. This is a debug routine that is only enabled if the SERIALDEBUG define is enabled.
SendUartHex(): This sends the given byte to the serial byte as a 2-digit HEX value. This is a debug routine that is only enabled if the SERIALDEBUG define is enabled.
DelaymSecond(): This routines pauses the specified number of miliseconds. This is a debug routine that is only enabled if the TIMER define is enabled.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -