import usb_hid import storage import board import digitalio import time # left fn key is board.GP0 x board.GP15 # key check -- if left fn key is pressed, do not disable_usb_drive() # initialize pins try: storage.disable_usb_drive() col_pin = digitalio.DigitalInOut(board.GP0) row_pin = digitalio.DigitalInOut(board.GP15) row_pin.direction = digitalio.Direction.INPUT row_pin.pull = digitalio.Pull.UP col_pin.direction = digitalio.Direction.OUTPUT col_pin.value = False time.sleep(0.05) # scan left fn key col_pin.direction = digitalio.Direction.OUTPUT col_pin.value = True row_pin.direction = digitalio.Direction.INPUT row_pin.pull = digitalio.Pull.DOWN # check if left fn is not pressed if row_pin.value: time.sleep(0.05) if row_pin.value: storage.enable_usb_drive() except Exception as e: print(f"An error occurred: {e}") # This is only one example of a gamepad report descriptor, # and may not suit your needs. GAMEPAD_REPORT_DESCRIPTOR = bytes(( 0x05, 0x01, # Usage Page (Generic Desktop Ctrls) 0x09, 0x05, # Usage (Game Pad) 0xA1, 0x01, # Collection (Application) 0x85, 0x04, # Report ID (4) 0x05, 0x09, # Usage Page (Button) 0x19, 0x01, # Usage Minimum (Button 1) 0x29, 0x0F, # Usage Maximum (Button 15) 0x15, 0x00, # Logical Minimum (0) 0x25, 0x01, # Logical Maximum (1) 0x75, 0x01, # Report Size (1) 0x95, 0x10, # Report Count (16) 0x81, 0x02, # Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) 0x05, 0x01, # Usage Page (Generic Desktop Ctrls) 0x15, 0x81, # Logical Minimum (-127) 0x25, 0x7F, # Logical Maximum (127) 0x09, 0x30, # Usage (X) 0x09, 0x31, # Usage (Y) 0x09, 0x32, # Usage (Z) 0x09, 0x35, # Usage (Rz) 0x75, 0x08, # Report Size (8) 0x95, 0x04, # Report Count (4) 0x81, 0x02, # Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position) 0xC0, # End Collection )) gamepad = usb_hid.Device( report_descriptor=GAMEPAD_REPORT_DESCRIPTOR, usage_page=0x01, # Generic Desktop Control usage=0x05, # Gamepad report_ids=(4,), # Descriptor uses report ID 4. in_report_lengths=(6,), # This gamepad sends 6 bytes in its report. out_report_lengths=(0,), # It does not receive any reports. ) usb_hid.enable( (usb_hid.Device.KEYBOARD, usb_hid.Device.MOUSE, usb_hid.Device.CONSUMER_CONTROL, gamepad) )