|
| 1 | +#include "ch32fun.h" |
| 2 | +#include <stdio.h> |
| 3 | +#include <string.h> |
| 4 | +#include "rv003usb.h" |
| 5 | + |
| 6 | +int main() |
| 7 | +{ |
| 8 | + SystemInit(); |
| 9 | + // funGpioInitC(); |
| 10 | + // funPinMode(PC5, GPIO_CFGLR_OUT_10Mhz_PP); |
| 11 | + Delay_Ms(1); // Ensures USB re-enumeration after bootloader or reset; Spec demand >2.5µs ( TDDIS ) |
| 12 | + usb_setup(); |
| 13 | + while(1) |
| 14 | + { |
| 15 | + // funDigitalWrite(PC5, 1); |
| 16 | + // Delay_Ms(1000); |
| 17 | + // funDigitalWrite(PC5, 0); |
| 18 | + // Delay_Ms(1000); |
| 19 | +#if RV003USB_EVENT_DEBUGGING |
| 20 | + uint32_t * ue = GetUEvent(); |
| 21 | + if( ue ) |
| 22 | + { |
| 23 | + printf( "%lu %lx %lx %lx\n", ue[0], ue[1], ue[2], ue[3] ); |
| 24 | + } |
| 25 | +#endif |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +void usb_handle_user_data( struct usb_endpoint * e, int current_endpoint, uint8_t * data, int len, struct rv003usb_internal * ist ) |
| 30 | +{ |
| 31 | + if (len > 0) { |
| 32 | + LogUEvent(1139, data[0], 0, current_endpoint); |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +void usb_handle_user_in_request( struct usb_endpoint * e, uint8_t * scratchpad, int endp, uint32_t sendtok, struct rv003usb_internal * ist ) |
| 37 | +{ |
| 38 | + if( endp == 1 ) |
| 39 | + { |
| 40 | + // Mouse (4 bytes) |
| 41 | + static int i; |
| 42 | + static uint8_t tsajoystick[4] = { 0x00, 0x00, 0x00, 0x00 }; |
| 43 | + i++; |
| 44 | + int mode = i >> 5; |
| 45 | + |
| 46 | + // Move the mouse right, down, left and up in a square. |
| 47 | + switch( mode & 3 ) |
| 48 | + { |
| 49 | + case 0: tsajoystick[1] = 1; tsajoystick[2] = 0; break; |
| 50 | + case 1: tsajoystick[1] = 0; tsajoystick[2] = 1; break; |
| 51 | + case 2: tsajoystick[1] = -1; tsajoystick[2] = 0; break; |
| 52 | + case 3: tsajoystick[1] = 0; tsajoystick[2] =-1; break; |
| 53 | + } |
| 54 | + usb_send_data( tsajoystick, 4, 0, sendtok ); |
| 55 | + } |
| 56 | + else if( endp == 2 ) |
| 57 | + { |
| 58 | + // Keyboard (8 bytes) |
| 59 | + static int i; |
| 60 | + static uint8_t tsajoystick[8] = { 0x00 }; |
| 61 | + usb_send_data( tsajoystick, 8, 0, sendtok ); |
| 62 | + |
| 63 | + i++; |
| 64 | + |
| 65 | + // Press a Key every second or so. |
| 66 | + if( (i & 0x7f) == 0 ) |
| 67 | + { |
| 68 | + tsajoystick[4] = 0x05; // 0x05 = "b"; 0x53 = NUMLOCK; 0x39 = CAPSLOCK; |
| 69 | + } |
| 70 | + else |
| 71 | + { |
| 72 | + tsajoystick[4] = 0; |
| 73 | + } |
| 74 | + } |
| 75 | + else |
| 76 | + { |
| 77 | + // If it's a control transfer, empty it. |
| 78 | + usb_send_empty( sendtok ); |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | + |
0 commit comments