github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/machine/usb/descriptor/hidreport.go (about)

     1  package descriptor
     2  
     3  const (
     4  	hidUsagePage       = 0x05
     5  	hidUsage           = 0x09
     6  	hidLogicalMinimum  = 0x14
     7  	hidLogicalMaximum  = 0x24
     8  	hidUsageMinimum    = 0x18
     9  	hidUsageMaximum    = 0x28
    10  	hidPhysicalMinimum = 0x34
    11  	hidPhysicalMaximum = 0x44
    12  	hidUnitExponent    = 0x55
    13  	hidUnit            = 0x65
    14  	hidCollection      = 0xa1
    15  	hidInput           = 0x81
    16  	hidOutput          = 0x91
    17  	hidReportSize      = 0x75
    18  	hidReportCount     = 0x95
    19  	hidReportID        = 0x85
    20  )
    21  
    22  const (
    23  	hidSizeValue0 = 0x00
    24  	hidSizeValue1 = 0x01
    25  	hidSizeValue2 = 0x02
    26  	hidSizeValue4 = 0x03
    27  )
    28  
    29  var (
    30  	HIDUsagePageGenericDesktop     = []byte{hidUsagePage, 0x01}
    31  	HIDUsagePageSimulationControls = []byte{hidUsagePage, 0x02}
    32  	HIDUsagePageVRControls         = []byte{hidUsagePage, 0x03}
    33  	HIDUsagePageSportControls      = []byte{hidUsagePage, 0x04}
    34  	HIDUsagePageGameControls       = []byte{hidUsagePage, 0x05}
    35  	HIDUsagePageGenericControls    = []byte{hidUsagePage, 0x06}
    36  	HIDUsagePageKeyboard           = []byte{hidUsagePage, 0x07}
    37  	HIDUsagePageLED                = []byte{hidUsagePage, 0x08}
    38  	HIDUsagePageButton             = []byte{hidUsagePage, 0x09}
    39  	HIDUsagePageOrdinal            = []byte{hidUsagePage, 0x0A}
    40  	HIDUsagePageTelephony          = []byte{hidUsagePage, 0x0B}
    41  	HIDUsagePageConsumer           = []byte{hidUsagePage, 0x0C}
    42  	HIDUsagePageDigitizers         = []byte{hidUsagePage, 0x0D}
    43  	HIDUsagePageHaptics            = []byte{hidUsagePage, 0x0E}
    44  	HIDUsagePagePhysicalInput      = []byte{hidUsagePage, 0x0F}
    45  	HIDUsagePageUnicode            = []byte{hidUsagePage, 0x10}
    46  	HIDUsagePageSoC                = []byte{hidUsagePage, 0x11}
    47  	HIDUsagePageEyeHeadTrackers    = []byte{hidUsagePage, 0x12}
    48  	HIDUsagePageAuxDisplay         = []byte{hidUsagePage, 0x14}
    49  	HIDUsagePageSensors            = []byte{hidUsagePage, 0x20}
    50  	HIDUsagePageMedicalInstrument  = []byte{hidUsagePage, 0x40}
    51  	HIDUsagePageBrailleDisplay     = []byte{hidUsagePage, 0x41}
    52  	HIDUsagePageLighting           = []byte{hidUsagePage, 0x59}
    53  	HIDUsagePageMonitor            = []byte{hidUsagePage, 0x80}
    54  	HIDUsagePageMonitorEnum        = []byte{hidUsagePage, 0x81}
    55  	HIDUsagePageVESA               = []byte{hidUsagePage, 0x82}
    56  	HIDUsagePagePower              = []byte{hidUsagePage, 0x84}
    57  	HIDUsagePageBatterySystem      = []byte{hidUsagePage, 0x85}
    58  	HIDUsagePageBarcodeScanner     = []byte{hidUsagePage, 0x8C}
    59  	HIDUsagePageScales             = []byte{hidUsagePage, 0x8D}
    60  	HIDUsagePageMagneticStripe     = []byte{hidUsagePage, 0x8E}
    61  	HIDUsagePageCameraControl      = []byte{hidUsagePage, 0x90}
    62  	HIDUsagePageArcade             = []byte{hidUsagePage, 0x91}
    63  	HIDUsagePageGaming             = []byte{hidUsagePage, 0x92}
    64  )
    65  
    66  var (
    67  	HIDUsageDesktopPointer         = []byte{hidUsage, 0x01}
    68  	HIDUsageDesktopMouse           = []byte{hidUsage, 0x02}
    69  	HIDUsageDesktopJoystick        = []byte{hidUsage, 0x04}
    70  	HIDUsageDesktopGamepad         = []byte{hidUsage, 0x05}
    71  	HIDUsageDesktopKeyboard        = []byte{hidUsage, 0x06}
    72  	HIDUsageDesktopKeypad          = []byte{hidUsage, 0x07}
    73  	HIDUsageDesktopMultiaxis       = []byte{hidUsage, 0x08}
    74  	HIDUsageDesktopTablet          = []byte{hidUsage, 0x09}
    75  	HIDUsageDesktopWaterCooling    = []byte{hidUsage, 0x0A}
    76  	HIDUsageDesktopChassis         = []byte{hidUsage, 0x0B}
    77  	HIDUsageDesktopWireless        = []byte{hidUsage, 0x0C}
    78  	HIDUsageDesktopPortable        = []byte{hidUsage, 0x0D}
    79  	HIDUsageDesktopSystemMultiaxis = []byte{hidUsage, 0x0E}
    80  	HIDUsageDesktopSpatial         = []byte{hidUsage, 0x0F}
    81  	HIDUsageDesktopAssistive       = []byte{hidUsage, 0x10}
    82  	HIDUsageDesktopDock            = []byte{hidUsage, 0x11}
    83  	HIDUsageDesktopDockable        = []byte{hidUsage, 0x12}
    84  	HIDUsageDesktopCallState       = []byte{hidUsage, 0x13}
    85  	HIDUsageDesktopX               = []byte{hidUsage, 0x30}
    86  	HIDUsageDesktopY               = []byte{hidUsage, 0x31}
    87  	HIDUsageDesktopZ               = []byte{hidUsage, 0x32}
    88  	HIDUsageDesktopRx              = []byte{hidUsage, 0x33}
    89  	HIDUsageDesktopRy              = []byte{hidUsage, 0x34}
    90  	HIDUsageDesktopRz              = []byte{hidUsage, 0x35}
    91  	HIDUsageDesktopSlider          = []byte{hidUsage, 0x36}
    92  	HIDUsageDesktopDial            = []byte{hidUsage, 0x37}
    93  	HIDUsageDesktopWheel           = []byte{hidUsage, 0x38}
    94  	HIDUsageDesktopHatSwitch       = []byte{hidUsage, 0x39}
    95  	HIDUsageDesktopCountedBuffer   = []byte{hidUsage, 0x3A}
    96  )
    97  
    98  var (
    99  	HIDUsageConsumerControl             = []byte{hidUsage, 0x01}
   100  	HIDUsageConsumerNumericKeypad       = []byte{hidUsage, 0x02}
   101  	HIDUsageConsumerProgrammableButtons = []byte{hidUsage, 0x03}
   102  	HIDUsageConsumerMicrophone          = []byte{hidUsage, 0x04}
   103  	HIDUsageConsumerHeadphone           = []byte{hidUsage, 0x05}
   104  	HIDUsageConsumerGraphicEqualizer    = []byte{hidUsage, 0x06}
   105  )
   106  
   107  var (
   108  	HIDCollectionPhysical    = []byte{hidCollection, 0x00}
   109  	HIDCollectionApplication = []byte{hidCollection, 0x01}
   110  	HIDCollectionEnd         = []byte{0xc0}
   111  )
   112  
   113  var (
   114  	// Input (Data,Ary,Abs), Key arrays (6 bytes)
   115  	HIDInputDataAryAbs = []byte{hidInput, 0x00}
   116  
   117  	// Input (Data, Variable, Absolute), Modifier byte
   118  	HIDInputDataVarAbs = []byte{hidInput, 0x02}
   119  
   120  	// Input (Const,Var,Abs), Modifier byte
   121  	HIDInputConstVarAbs = []byte{hidInput, 0x03}
   122  
   123  	// Input (Data, Variable, Relative), 2 position bytes (X & Y)
   124  	HIDInputDataVarRel = []byte{hidInput, 0x06}
   125  
   126  	// Output (Data, Variable, Absolute), Modifier byte
   127  	HIDOutputDataVarAbs = []byte{hidOutput, 0x02}
   128  
   129  	// Output (Const, Variable, Absolute), Modifier byte
   130  	HIDOutputConstVarAbs = []byte{hidOutput, 0x03}
   131  )
   132  
   133  func HIDReportSize(size int) []byte {
   134  	return []byte{hidReportSize, byte(size)}
   135  }
   136  
   137  func HIDReportCount(count int) []byte {
   138  	return []byte{hidReportCount, byte(count)}
   139  }
   140  
   141  func HIDReportID(id int) []byte {
   142  	return []byte{hidReportID, byte(id)}
   143  }
   144  
   145  func HIDLogicalMinimum(min int) []byte {
   146  	switch {
   147  	case min < -32767 || 65535 < min:
   148  		return []byte{hidLogicalMinimum + hidSizeValue4, uint8(min), uint8(min >> 8), uint8(min >> 16), uint8(min >> 24)}
   149  	case min < -127 || 255 < min:
   150  		return []byte{hidLogicalMinimum + hidSizeValue2, uint8(min), uint8(min >> 8)}
   151  	default:
   152  		return []byte{hidLogicalMinimum + hidSizeValue1, byte(min)}
   153  	}
   154  }
   155  
   156  func HIDLogicalMaximum(max int) []byte {
   157  	switch {
   158  	case max < -32767 || 65535 < max:
   159  		return []byte{hidLogicalMaximum + hidSizeValue4, uint8(max), uint8(max >> 8), uint8(max >> 16), uint8(max >> 24)}
   160  	case max < -127 || 255 < max:
   161  		return []byte{hidLogicalMaximum + hidSizeValue2, uint8(max), uint8(max >> 8)}
   162  	default:
   163  		return []byte{hidLogicalMaximum + hidSizeValue1, byte(max)}
   164  	}
   165  }
   166  
   167  func HIDUsageMinimum(min int) []byte {
   168  	switch {
   169  	case min < -32767 || 65535 < min:
   170  		return []byte{hidUsageMinimum + hidSizeValue4, uint8(min), uint8(min >> 8), uint8(min >> 16), uint8(min >> 24)}
   171  	case min < -127 || 255 < min:
   172  		return []byte{hidUsageMinimum + hidSizeValue2, uint8(min), uint8(min >> 8)}
   173  	default:
   174  		return []byte{hidUsageMinimum + hidSizeValue1, byte(min)}
   175  	}
   176  }
   177  
   178  func HIDUsageMaximum(max int) []byte {
   179  	switch {
   180  	case max < -32767 || 65535 < max:
   181  		return []byte{hidUsageMaximum + hidSizeValue4, uint8(max), uint8(max >> 8), uint8(max >> 16), uint8(max >> 24)}
   182  	case max < -127 || 255 < max:
   183  		return []byte{hidUsageMaximum + hidSizeValue2, uint8(max), uint8(max >> 8)}
   184  	default:
   185  		return []byte{hidUsageMaximum + hidSizeValue1, byte(max)}
   186  	}
   187  }
   188  
   189  func HIDPhysicalMinimum(min int) []byte {
   190  	switch {
   191  	case min < -32767 || 65535 < min:
   192  		return []byte{hidPhysicalMinimum + hidSizeValue4, uint8(min), uint8(min >> 8), uint8(min >> 16), uint8(min >> 24)}
   193  	case min < -127 || 255 < min:
   194  		return []byte{hidPhysicalMinimum + hidSizeValue2, uint8(min), uint8(min >> 8)}
   195  	default:
   196  		return []byte{hidPhysicalMinimum + hidSizeValue1, byte(min)}
   197  	}
   198  }
   199  
   200  func HIDPhysicalMaximum(max int) []byte {
   201  	switch {
   202  	case max < -32767 || 65535 < max:
   203  		return []byte{hidPhysicalMaximum + hidSizeValue4, uint8(max), uint8(max >> 8), uint8(max >> 16), uint8(max >> 24)}
   204  	case max < -127 || 255 < max:
   205  		return []byte{hidPhysicalMaximum + hidSizeValue2, uint8(max), uint8(max >> 8)}
   206  	default:
   207  		return []byte{hidPhysicalMaximum + hidSizeValue1, byte(max)}
   208  	}
   209  }
   210  
   211  func HIDUnitExponent(exp int) []byte {
   212  	return []byte{hidUnitExponent, byte(exp)}
   213  }
   214  
   215  func HIDUnit(unit int) []byte {
   216  	return []byte{hidUnit, byte(unit)}
   217  }