Commit 752b62a91c77eefced7c5d89ab5bbfc45d17c0f0
1 parent
4dcf8810
Descriptors + PAD en cours
Showing
4 changed files
with
134 additions
and
84 deletions
Show diff stats
lufa-master/PolytechLille/PAD/Descriptors.c
... | ... | @@ -104,6 +104,7 @@ const USB_Descriptor_Configuration_t PROGMEM RelayBoard_ConfigurationDescriptor |
104 | 104 | .InterfaceStrIndex = NO_DESCRIPTOR |
105 | 105 | }, |
106 | 106 | |
107 | + /* | |
107 | 108 | .HID_KeyboardHID = |
108 | 109 | { |
109 | 110 | .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID}, |
... | ... | @@ -114,6 +115,7 @@ const USB_Descriptor_Configuration_t PROGMEM RelayBoard_ConfigurationDescriptor |
114 | 115 | .HIDReportType = HID_DTYPE_Report, |
115 | 116 | .HIDReportLength = sizeof(KeyboardReport) |
116 | 117 | }, |
118 | + */ | |
117 | 119 | |
118 | 120 | .ReportOUTEndpoint = |
119 | 121 | { |
... | ... | @@ -147,17 +149,17 @@ const USB_Descriptor_Configuration_t PROGMEM RelayBoard_ConfigurationDescriptor |
147 | 149 | { |
148 | 150 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, |
149 | 151 | |
150 | - .EndpointAddress = KEYBOARD_IN_EPADDR, | |
152 | + .EndpointAddress = KEYBOARD_IN_Bout_EPADDR, | |
151 | 153 | .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), |
152 | 154 | .EndpointSize = KEYBOARD_EPSIZE, |
153 | 155 | .PollingIntervalMS = 0x05 |
154 | 156 | }, |
155 | 157 | |
156 | - .ReportINEndpointJoysticks = | |
158 | + .ReportINEndpointJoystick = | |
157 | 159 | { |
158 | 160 | .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, |
159 | 161 | |
160 | - .EndpointAddress = KEYBOARD_IN_EPADDR, | |
162 | + .EndpointAddress = KEYBOARD_IN_Joy_EPADDR, | |
161 | 163 | .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), |
162 | 164 | .EndpointSize = KEYBOARD_EPSIZE, |
163 | 165 | .PollingIntervalMS = 0x05 | ... | ... |
lufa-master/PolytechLille/PAD/Descriptors.h
... | ... | @@ -52,12 +52,12 @@ |
52 | 52 | |
53 | 53 | // Relay Board Interface |
54 | 54 | USB_Descriptor_Interface_t InterfaceOUT; |
55 | - USB_HID_Descriptor_HID_t HID_KeyboardHID; //UTILE ? | |
55 | + //USB_HID_Descriptor_HID_t HID_KeyboardHID; //UTILE ? | |
56 | 56 | USB_Descriptor_Endpoint_t HID_ReportOUTEndpoint; |
57 | 57 | |
58 | 58 | USB_Descriptor_Interface_t InterfaceIN; |
59 | 59 | USB_Descriptor_Endpoint_t HID_ReportINEndpointBoutons; |
60 | - USB_Descriptor_Endpoint_t HID_ReportOUTEndpointJoysticks; | |
60 | + USB_Descriptor_Endpoint_t HID_ReportOUTEndpointJoystick; | |
61 | 61 | } USB_Descriptor_Configuration_t; |
62 | 62 | |
63 | 63 | /** Enum for the device interface descriptor IDs within the device. Each interface descriptor |
... | ... | @@ -66,7 +66,8 @@ |
66 | 66 | */ |
67 | 67 | enum InterfaceDescriptors_t |
68 | 68 | { |
69 | - INTERFACE_ID_RelayBoard = 0, /**< Relay board interface descriptor ID */ | |
69 | + INTERFACE_ID_InterfaceOUT = 0, /**< Relay board interface descriptor ID */ | |
70 | + INTERFACE_ID_InterfaceIN = 1, | |
70 | 71 | }; |
71 | 72 | |
72 | 73 | /** Enum for the device string descriptor IDs within the device. Each string descriptor should |
... | ... | @@ -81,6 +82,20 @@ |
81 | 82 | STRING_ID_Serial = 3, /**< Serial number string ID */ |
82 | 83 | }; |
83 | 84 | |
85 | + /* Macros: */ | |
86 | + | |
87 | + | |
88 | + /** Endpoint address of the Keyboard HID reporting IN endpoint. */ | |
89 | + #define KEYBOARD_IN_Bout_EPADDR (ENDPOINT_DIR_IN | 1) //Adr. EP Boutons | |
90 | + #define KEYBOARD_IN_Joy_EPADDR (ENDPOINT_DIR_IN | 1) //Adr. EP Joystick | |
91 | + | |
92 | + /** Endpoint address of the Keyboard HID reporting OUT endpoint. */ | |
93 | + #define KEYBOARD_OUT_EPADDR (ENDPOINT_DIR_OUT | 2) | |
94 | + | |
95 | + /** Size in bytes of the Keyboard HID reporting IN and OUT endpoints. */ | |
96 | + #define KEYBOARD_EPSIZE 8 | |
97 | + | |
98 | + | |
84 | 99 | /* Function Prototypes: */ |
85 | 100 | uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, |
86 | 101 | const uint16_t wIndex, | ... | ... |
lufa-master/PolytechLille/PAD/PAD.c
... | ... | @@ -53,7 +53,7 @@ int main(void) |
53 | 53 | USB_USBTask(); |
54 | 54 | //HID_Task(); |
55 | 55 | } |
56 | - } | |
56 | +} | |
57 | 57 | |
58 | 58 | /** Configures the board hardware and chip peripherals for the project's functionality. */ |
59 | 59 | void SetupHardware(void) |
... | ... | @@ -65,87 +65,121 @@ void SetupHardware(void) |
65 | 65 | |
66 | 66 | /* Disable clock division */ |
67 | 67 | clock_prescale_set(clock_div_1); |
68 | -#endif | |
69 | 68 | |
70 | 69 | |
71 | -//TODO INITIALISATIONS | |
70 | +/**INITIALISATIONS*/ | |
72 | 71 | /* Hardware Initialization */ |
73 | 72 | USB_Init(); |
73 | + Serial_init(9600,0); //9600 Bauds, configuration | |
74 | 74 | |
75 | 75 | /* Initialize Relays */ |
76 | - DDRC |= ALL_RELAYS; | |
77 | - PORTC &= ~ALL_RELAYS; | |
76 | + DDRD |= ALL_RELAYS; // Port pour la liaison série | |
77 | + PORTD &= ~ALL_RELAYS; | |
78 | 78 | } |
79 | 79 | |
80 | -/** Event handler for the library USB Control Request reception event. */ | |
81 | -void EVENT_USB_Device_ControlRequest(void) | |
80 | + | |
81 | +/** Event handler for the USB_ConfigurationChanged event. This is fired when the host sets the current configuration | |
82 | + * of the USB device after enumeration, and configures the keyboard device endpoints. | |
83 | + */ | |
84 | +void EVENT_USB_Device_ConfigurationChanged(void) | |
82 | 85 | { |
83 | - const uint8_t SerialNumber[5] = { 0, 0, 0, 0, 1 }; | |
84 | - uint8_t ControlData[2] = { 0, 0 }; | |
86 | + bool ConfigSuccess = true; | |
87 | + | |
88 | + /* Setup HID Report Endpoints */ //MODIFS ICI | |
89 | + ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_IN_Bout_EPADDR, EP_TYPE_INTERRUPT, KEYBOARD_EPSIZE, 1); | |
90 | + ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_IN_Joy_EPADDR, EP_TYPE_INTERRUPT, KEYBOARD_EPSIZE, 1); | |
91 | + ConfigSuccess &= Endpoint_ConfigureEndpoint(KEYBOARD_OUT_EPADDR, EP_TYPE_INTERRUPT, KEYBOARD_EPSIZE, 1); | |
92 | + | |
93 | + /* Turn on Start-of-Frame events for tracking HID report period expiry */ | |
94 | + USB_Device_EnableSOFEvents(); | |
95 | + | |
96 | + /* Indicate endpoint configuration success or failure */ | |
97 | + //LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR); | |
98 | +} | |
99 | + | |
100 | + | |
101 | +/** Sends the next HID report to the host, via the keyboard data endpoint. */ | |
102 | +void SendNextReport(void) //Envoi liaison Série | |
103 | +{ | |
104 | + static USB_KeyboardReport_Data_t PrevKeyboardReportData; | |
105 | + USB_KeyboardReport_Data_t KeyboardReportData; | |
106 | + bool SendReport = false; | |
107 | + | |
108 | + /* Create the next keyboard report for transmission to the host */ | |
109 | + CreateKeyboardReport(&KeyboardReportData); | |
110 | + | |
111 | + /* Check if the idle period is set and has elapsed */ | |
112 | + if (IdleCount && (!(IdleMSRemaining))) | |
113 | + { | |
114 | + /* Reset the idle time remaining counter */ | |
115 | + IdleMSRemaining = IdleCount; | |
116 | + | |
117 | + /* Idle period is set and has elapsed, must send a report to the host */ | |
118 | + SendReport = true; | |
119 | + } | |
120 | + else | |
121 | + { | |
122 | + /* Check to see if the report data has changed - if so a report MUST be sent */ | |
123 | + SendReport = (memcmp(&PrevKeyboardReportData, &KeyboardReportData, sizeof(USB_KeyboardReport_Data_t)) != 0); | |
124 | + } | |
125 | + | |
126 | + | |
127 | + /** Envoi sur INTERFACE BOUTONS**/ | |
128 | + /* Select the Keyboard Report Endpoint */ | |
129 | + Endpoint_SelectEndpoint(KEYBOARD_IN_Bout_EPADDR); | |
130 | + | |
131 | + /* Check if Keyboard Endpoint Ready for Read/Write and if we should send a new report */ | |
132 | + if (Endpoint_IsReadWriteAllowed() && SendReport) | |
133 | + { | |
134 | + /* Save the current report data for later comparison to check for changes */ | |
135 | + PrevKeyboardReportData = KeyboardReportData; | |
85 | 136 | |
86 | - switch (USB_ControlRequest.bRequest) | |
137 | + /* Write Keyboard Report Data */ | |
138 | + Endpoint_Write_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData), NULL); | |
139 | + | |
140 | + /* Finalize the stream transfer to send the last packet */ | |
141 | + Endpoint_ClearIN(); | |
142 | + } | |
143 | + | |
144 | + /** Envoi sur INTERFACE Joystick**/ | |
145 | + /* Select the Keyboard Report Endpoint */ | |
146 | + Endpoint_SelectEndpoint(KEYBOARD_IN_Joy_EPADDR); | |
147 | + | |
148 | + /* Check if Keyboard Endpoint Ready for Read/Write and if we should send a new report */ | |
149 | + if (Endpoint_IsReadWriteAllowed() && SendReport) | |
87 | 150 | { |
88 | - case 0x09: | |
89 | - if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) | |
90 | - { | |
91 | - LEDs_ToggleLEDs(LEDS_LED1); | |
92 | - | |
93 | - Endpoint_ClearSETUP(); | |
94 | - | |
95 | - Endpoint_Read_Control_Stream_LE(ControlData, sizeof(ControlData)); | |
96 | - Endpoint_ClearIN(); | |
97 | - | |
98 | - switch (USB_ControlRequest.wValue) | |
99 | - { | |
100 | - case 0x303: | |
101 | - if (ControlData[1]) PORTC &= ~RELAY1; else PORTC |= RELAY1; | |
102 | - break; | |
103 | - case 0x306: | |
104 | - if (ControlData[1]) PORTC &= ~RELAY2; else PORTC |= RELAY2; | |
105 | - break; | |
106 | - case 0x309: | |
107 | - if (ControlData[1]) PORTC &= ~RELAY3; else PORTC |= RELAY3; | |
108 | - break; | |
109 | - case 0x30c: | |
110 | - if (ControlData[1]) PORTC &= ~RELAY4; else PORTC |= RELAY4; | |
111 | - break; | |
112 | - } | |
113 | - } | |
114 | - | |
115 | - break; | |
116 | - case 0x01: | |
117 | - if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) | |
118 | - { | |
119 | - LEDs_ToggleLEDs(LEDS_LED1); | |
120 | - | |
121 | - Endpoint_ClearSETUP(); | |
122 | - | |
123 | - switch (USB_ControlRequest.wValue) | |
124 | - { | |
125 | - case 0x301: | |
126 | - Endpoint_Write_Control_Stream_LE(SerialNumber, sizeof(SerialNumber)); | |
127 | - break; | |
128 | - case 0x303: | |
129 | - ControlData[1] = (PORTC & RELAY1) ? 2 : 3; | |
130 | - break; | |
131 | - case 0x306: | |
132 | - ControlData[1] = (PORTC & RELAY2) ? 2 : 3; | |
133 | - break; | |
134 | - case 0x309: | |
135 | - ControlData[1] = (PORTC & RELAY3) ? 2 : 3; | |
136 | - break; | |
137 | - case 0x30c: | |
138 | - ControlData[1] = (PORTC & RELAY4) ? 2 : 3; | |
139 | - break; | |
140 | - } | |
141 | - | |
142 | - if (ControlData[1]) | |
143 | - Endpoint_Write_Control_Stream_LE(ControlData, sizeof(ControlData)); | |
144 | - | |
145 | - Endpoint_ClearOUT(); | |
146 | - } | |
147 | - | |
148 | - break; | |
151 | + /* Save the current report data for later comparison to check for changes */ | |
152 | + PrevKeyboardReportData = KeyboardReportData; | |
153 | + | |
154 | + /* Write Keyboard Report Data */ | |
155 | + Endpoint_Write_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData), NULL); | |
156 | + | |
157 | + /* Finalize the stream transfer to send the last packet */ | |
158 | + Endpoint_ClearIN(); | |
149 | 159 | } |
150 | 160 | } |
151 | 161 | |
162 | + | |
163 | +/** Reads the next LED status report from the host from the LED data endpoint, if one has been sent. */ | |
164 | +void ReceiveNextReport(void) //Réception Liaison Série | |
165 | +{ | |
166 | + /* Select the Keyboard LED Report Endpoint */ | |
167 | + Endpoint_SelectEndpoint(KEYBOARD_OUT_EPADDR); | |
168 | + | |
169 | + /* Check if Keyboard LED Endpoint contains a packet */ | |
170 | + if (Endpoint_IsOUTReceived()) | |
171 | + { | |
172 | + /* Check to see if the packet contains data */ | |
173 | + if (Endpoint_IsReadWriteAllowed()) | |
174 | + { | |
175 | + /* Read in the LED report from the host */ | |
176 | + uint8_t LEDReport = Endpoint_Read_8(); | |
177 | + | |
178 | + /* Process the read LED report from the host */ | |
179 | + ProcessLEDReport(LEDReport); | |
180 | + } | |
181 | + | |
182 | + /* Handshake the OUT Endpoint - clear endpoint and ready for next report */ | |
183 | + Endpoint_ClearOUT(); | |
184 | + } | |
185 | +} | ... | ... |
lufa-master/PolytechLille/PAD/PAD.h
... | ... | @@ -45,20 +45,19 @@ |
45 | 45 | |
46 | 46 | #include "Descriptors.h" |
47 | 47 | |
48 | - #include <LUFA/Drivers/Board/LEDs.h> | |
48 | + //#include <LUFA/Drivers/Board/LEDs.h> | |
49 | + #include "LUFA/Drivers/PeripheralSerial.h" | |
49 | 50 | #include <LUFA/Drivers/USB/USB.h> |
50 | 51 | #include <LUFA/Platform/Platform.h> |
51 | 52 | |
52 | 53 | /* Macros: */ |
53 | - #define RELAY1 (1 << 7) | |
54 | - #define RELAY2 (1 << 6) | |
55 | - #define RELAY3 (1 << 5) | |
56 | - #define RELAY4 (1 << 4) | |
57 | - #define ALL_RELAYS (RELAY1 | RELAY2 | RELAY3 | RELAY4) | |
54 | + | |
58 | 55 | |
59 | 56 | /* Function Prototypes: */ |
60 | 57 | void SetupHardware(void); |
61 | - | |
58 | + void EVENT_USB_Device_ConfigurationChanged(void); | |
59 | + void SendNextReport(void); | |
60 | + void ReceiveNextReport(void); | |
62 | 61 | void EVENT_USB_Device_ControlRequest(void); |
63 | 62 | |
64 | 63 | #endif | ... | ... |