;USB hub-related routines include "ti83plus.inc" include "equates.inc" PUBLIC DirectUSB_HandleHubConnected,DirectUSB_ClearHubPortFeature,DirectUSB_SetHubPortFeature PUBLIC DirectUSB_GetHubPortStatus EXTERN DirectUSB_GetDescriptor,DirectUSB_GetCurrentDevice,DirectUSB_SetupEndpoint,DirectUSB_RequestData EXTERN DirectUSB_ConfigureDevice,DirectUSB_SendControlData,DirectUSB_ClearFeature EXTERN DispHexA,DispHexHL,IPutC DirectUSB_HandleHubConnected: LOG Custom,1 in a,(80h) call DispHexA ld a,02h ld de,inputBuffer ld bc,8 call DirectUSB_GetDescriptor ; ret c LOG Custom,0FFh ld hl,(inputBuffer+2) call DispHexHL ld bc,64 or a sbc hl,bc jr nc,$F add hl,bc ld b,h ld c,l $$: ld a,(bMaxPacketSize0) call DispHexA ld a,02h ld de,inputBuffer call DirectUSB_GetDescriptor ret c LOG Custom,2 ;Keep going until we get to an endpoint descriptor ld ix,inputBuffer findEndpointLoop: xor a cp (ix+1) scf ret z ld a,05h cp (ix+1) jr z,$F findAnotherEndpoint: ld c,(ix+0) ld b,0 add ix,bc jr findEndpointLoop $$: ld a,(ix+2) call DispHexA bit 7,a jr z,findAnotherEndpoint ld a,(ix+3) call DispHexA and 00000011b cp 000000011b jr nz,findAnotherEndpoint LOG Custom,3 ld b,(ix+2) ld e,(ix+4) ld d,(ix+5) ld c,(ix+6) ld h,(ix+3) call DirectUSB_GetCurrentDevice ret c push bc call DirectUSB_SetupEndpoint LOG Custom,4 ;Configure device ld b,1 call DirectUSB_ConfigureDevice pop bc ret c LOG Custom,5 res 7,b ld c,b push bc ld de,inputBuffer ld bc,7 call DirectUSB_GetHubDescriptor pop bc ret c ;Enable power to all the ports ld a,(inputBuffer+2) ld b,a ld de,1 $$: push bc ld hl,0008h push de call DirectUSB_SetHubPortFeature pop de pop bc ret c inc de djnz $B ;Request data on hub interrupt pipe call DirectUSB_GetCurrentDevice call DirectUSB_RequestData ld a,5 call IPutC xor a ret bGetDescriptor: DB 80h,06h,00h,02h,00h,00h,0FFh,00h DirectUSB_GetHubDescriptor: ;BC: number of bytes expected to receive in response (7 bytes is safe): ; 0 bDescLength 1 Number of bytes in this descriptor, including this byte ; 1 bDescriptorType 1 Descriptor Type, value: 29H for hub descriptor ; 2 bNbrPorts 1 Number of downstream facing ports that this hub supports ; 3 wHubCharacteristics 2 ; 5 bPwrOn2PwrGood 1 Time (in 2ms intervals) from the time the power-on sequence ; begins on a port until power is good on that port. The ; USB System Software uses this value to determine how long ; to wait before accessing a powered-on port. ; 6 bHubContrCurrent 1 Maximum current requirements of the Hub Controller electronics ; in mA. ; 7 DeviceRemovable Variable ; PortPwrCtrlMask Variable ;DE => buffer for response ;Returns carry flag set if problems push de push bc ld hl,bGetHubDescriptor rst 20h pop bc pop de ld (OP1+6),bc ld hl,OP1 jr DirectUSB_SendControlData bGetHubDescriptor: DB 10100000b,06h,00h,29h,00h,00h,08h,00h DirectUSB_SetHubPortFeature: ;IX => device information structure ;HL: feature type ;DE: port number ;Returns carry flag set if problems in a,(80h) push af push de push hl ld a,(ix+0) out (80h),a ld hl,sSetFeature rst 20h pop hl ld (OP1+2),hl pop hl ld (OP1+4),hl ld hl,OP1 ld bc,0 call DirectUSB_SendControlData pop bc ld a,b out (80h),a ret sSetFeature: DB 23h,03h,08h,00h,01h,00h,00h,00h DirectUSB_ClearHubPortFeature: ;IX => device information structure ;HL: feature selector ;DE: port number ld b,00100011b jr DirectUSB_ClearFeature DirectUSB_GetHubPortStatus: ;IX => device information structure ;HL: port ;Outputs: ; DEHL: port status in a,(80h) push af ld a,(ix+0) out (80h),a push hl ld hl,sGetHubPortStatus rst 20h pop hl ld (OP1+4),hl jr $F sGetHubPortStatus: DB 10100011b,0,0,0,0,0,4,0 DirectUSB_GetHubStatus: ;IX => device information structure ;Outputs: ; DEHL: hub status in a,(80h) push af ld a,(ix+0) out (80h),a ld hl,sGetHubStatus rst 20h $$: ld hl,OP1 ld de,inputBuffer ld bc,4 call DirectUSB_SendControlData ld ix,inputBuffer ld d,(ix+0) ld e,(ix+1) ld h,(ix+2) ld l,(ix+3) pop bc ld a,b out (80h),a ret sGetHubStatus: DB 10100000b,0,0,0,0,0,4,0