Commit d16bd85799370f9b17c7d0c91da913809518d9fd

Authored by rguillom
2 parents 8ae5cde5 752b62a9

fusion partie3 vers 328P

lufa-master/PolytechLille/PAD/Descriptors.c
@@ -29,7 +29,6 @@ @@ -29,7 +29,6 @@
29 this software. 29 this software.
30 */ 30 */
31 31
32 -  
33 /** \file 32 /** \file
34 * 33 *
35 * USB Device Descriptors, for library use when in USB device mode. Descriptors are special 34 * USB Device Descriptors, for library use when in USB device mode. Descriptors are special
@@ -39,13 +38,10 @@ @@ -39,13 +38,10 @@
39 38
40 #include "Descriptors.h" 39 #include "Descriptors.h"
41 40
42 -//////////////////////////////////////////////////////////////////////////  
43 -  
44 -  
45 -/** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage  
46 - * of the device in one of its supported configurations, including information about any device interfaces  
47 - * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting  
48 - * a configuration so that the host may correctly communicate with the USB device. 41 +/** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
  42 + * device characteristics, including the supported USB version, control endpoint size and the
  43 + * number of device configurations. The descriptor is read out by the USB host when the enumeration
  44 + * process begins.
49 */ 45 */
50 const USB_Descriptor_Device_t PROGMEM RelayBoard_DeviceDescriptor = 46 const USB_Descriptor_Device_t PROGMEM RelayBoard_DeviceDescriptor =
51 { 47 {
@@ -58,8 +54,8 @@ const USB_Descriptor_Device_t PROGMEM RelayBoard_DeviceDescriptor = @@ -58,8 +54,8 @@ const USB_Descriptor_Device_t PROGMEM RelayBoard_DeviceDescriptor =
58 54
59 .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE, 55 .Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
60 56
61 - .VendorID = 0x04B4,  
62 - .ProductID = 0xFD11, 57 + .VendorID = 0x04B4, //A MODIFIER avec VendorID Carte
  58 + .ProductID = 0xFD11, //A MODIFIER
63 .ReleaseNumber = VERSION_BCD(2,0,0), 59 .ReleaseNumber = VERSION_BCD(2,0,0),
64 60
65 .ManufacturerStrIndex = STRING_ID_Manufacturer, 61 .ManufacturerStrIndex = STRING_ID_Manufacturer,
@@ -67,50 +63,60 @@ const USB_Descriptor_Device_t PROGMEM RelayBoard_DeviceDescriptor = @@ -67,50 +63,60 @@ const USB_Descriptor_Device_t PROGMEM RelayBoard_DeviceDescriptor =
67 .SerialNumStrIndex = STRING_ID_Serial, 63 .SerialNumStrIndex = STRING_ID_Serial,
68 64
69 .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS 65 .NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
70 -  
71 -  
72 -////////////////////////////////////////////////////////////////////////////  
73 -  
74 - 66 +};
75 67
76 /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage 68 /** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage
77 * of the device in one of its supported configurations, including information about any device interfaces 69 * of the device in one of its supported configurations, including information about any device interfaces
78 * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting 70 * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
79 * a configuration so that the host may correctly communicate with the USB device. 71 * a configuration so that the host may correctly communicate with the USB device.
80 */ 72 */
81 -const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = 73 +const USB_Descriptor_Configuration_t PROGMEM RelayBoard_ConfigurationDescriptor =
82 { 74 {
83 .Config = 75 .Config =
84 { 76 {
85 .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration}, 77 .Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
86 78
87 .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t), 79 .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
88 - .TotalInterfaces = 2,// MODIF ICI (1 au début) 80 + .TotalInterfaces = 2,
89 81
90 .ConfigurationNumber = 1, 82 .ConfigurationNumber = 1,
91 .ConfigurationStrIndex = NO_DESCRIPTOR, 83 .ConfigurationStrIndex = NO_DESCRIPTOR,
92 84
93 - .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED), 85 + .ConfigAttributes = USB_CONFIG_ATTR_RESERVED,
94 86
95 - .MaxPowerConsumption = USB_CONFIG_POWER_MA(100) 87 + .MaxPowerConsumption = USB_CONFIG_POWER_MA(500)
96 }, 88 },
97 -////////////////////////////////////////////////////////////////////////////// AJOUT  
98 - .InterfaceOUT = 89 +
  90 + /* Description Interface SORTIE (LED)*/
  91 + .InferfaceOUT =
99 { 92 {
100 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, 93 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
101 94
102 - .InterfaceNumber = INTERFACE_ID_InterfaceOUT, //pas sur mais presque  
103 - .AlternateSetting = 0x00, 95 + .InterfaceNumber = INTERFACE_ID_InterfaceOUT,
  96 + .AlternateSetting = 0,
104 97
105 .TotalEndpoints = 1, 98 .TotalEndpoints = 1,
106 99
107 - .Class = HID_CSCP_HIDClass,  
108 - .SubClass = HID_CSCP_BootSubclass,  
109 - .Protocol = HID_CSCP_KeyboardBootProtocol, 100 + .Class = USB_CSCP_VendorSpecificClass,
  101 + .SubClass = 0x00,
  102 + .Protocol = 0x00,
110 103
111 .InterfaceStrIndex = NO_DESCRIPTOR 104 .InterfaceStrIndex = NO_DESCRIPTOR
112 }, 105 },
  106 +
  107 + /*
  108 + .HID_KeyboardHID =
  109 + {
  110 + .Header = {.Size = sizeof(USB_HID_Descriptor_HID_t), .Type = HID_DTYPE_HID},
113 111
  112 + .HIDSpec = VERSION_BCD(1,1,1),
  113 + .CountryCode = 0x00,
  114 + .TotalReportDescriptors = 1,
  115 + .HIDReportType = HID_DTYPE_Report,
  116 + .HIDReportLength = sizeof(KeyboardReport)
  117 + },
  118 + */
  119 +
114 .ReportOUTEndpoint = 120 .ReportOUTEndpoint =
115 { 121 {
116 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, 122 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
@@ -120,7 +126,9 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = @@ -120,7 +126,9 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
120 .EndpointSize = KEYBOARD_EPSIZE, 126 .EndpointSize = KEYBOARD_EPSIZE,
121 .PollingIntervalMS = 0x05 127 .PollingIntervalMS = 0x05
122 }, 128 },
123 -////////////////////////////////////////////////////////////////////////////// FIN AJOUT 129 +
  130 +
  131 + /* Description interface IN (Boutons)*/
124 .InterfaceIN = 132 .InterfaceIN =
125 { 133 {
126 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface}, 134 .Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
@@ -137,57 +145,27 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = @@ -137,57 +145,27 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
137 .InterfaceStrIndex = NO_DESCRIPTOR 145 .InterfaceStrIndex = NO_DESCRIPTOR
138 }, 146 },
139 147
140 - .ReportINEndpoint1 = 148 + .ReportINEndpointBoutons =
141 { 149 {
142 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, 150 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
143 151
144 - .EndpointAddress = KEYBOARD_IN_EPADDR, 152 + .EndpointAddress = KEYBOARD_IN_Bout_EPADDR,
145 .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), 153 .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
146 .EndpointSize = KEYBOARD_EPSIZE, 154 .EndpointSize = KEYBOARD_EPSIZE,
147 .PollingIntervalMS = 0x05 155 .PollingIntervalMS = 0x05
148 }, 156 },
149 157
150 - .ReportINEndpoint2 = 158 + .ReportINEndpointJoystick =
151 { 159 {
152 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint}, 160 .Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
153 161
154 - .EndpointAddress = KEYBOARD_IN_EPADDR, 162 + .EndpointAddress = KEYBOARD_IN_Joy_EPADDR,
155 .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), 163 .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
156 .EndpointSize = KEYBOARD_EPSIZE, 164 .EndpointSize = KEYBOARD_EPSIZE,
157 .PollingIntervalMS = 0x05 165 .PollingIntervalMS = 0x05
158 } 166 }
159 }; 167 };
160 168
161 -////////////////////////////////////////////////////////////////////////////////////////////////////////////  
162 -////////////////////////////////////////////////////////////////////////////////////////////////////////////  
163 -  
164 -/** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests  
165 - * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate  
166 - * via the language ID table available at USB.org what languages the device supports for its string descriptors.  
167 - */  
168 -const USB_Descriptor_String_t PROGMEM LanguageString = USB_STRING_DESCRIPTOR_ARRAY(LANGUAGE_ID_ENG);  
169 -  
170 -/** Manufacturer descriptor string. This is a Unicode string containing the manufacturer's details in human readable  
171 - * form, and is read out upon request by the host when the appropriate string ID is requested, listed in the Device  
172 - * Descriptor.  
173 - */  
174 -const USB_Descriptor_String_t PROGMEM ManufacturerString = USB_STRING_DESCRIPTOR(L"LUFA Library");  
175 -  
176 -/** Product descriptor string. This is a Unicode string containing the product's details in human readable form,  
177 - * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device  
178 - * Descriptor.  
179 - */  
180 -const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(L"LUFA Keyboard Demo");  
181 -  
182 -/** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"  
183 - * documentation) by the application code so that the address and size of a requested descriptor can be given  
184 - * to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function  
185 - * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the  
186 - * USB host.  
187 - */  
188 -  
189 -///////////////////////////////////////////////////////////////////////////////////////////////////////////////  
190 -  
191 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests 169 /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
192 * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate 170 * the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
193 * via the language ID table available at USB.org what languages the device supports for its string descriptors. 171 * via the language ID table available at USB.org what languages the device supports for its string descriptors.
@@ -222,12 +200,6 @@ const USB_Descriptor_String_t PROGMEM RelayBoard_SerialString = USB_STRING_DESCR @@ -222,12 +200,6 @@ const USB_Descriptor_String_t PROGMEM RelayBoard_SerialString = USB_STRING_DESCR
222 * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the 200 * is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
223 * USB host. 201 * USB host.
224 */ 202 */
225 -  
226 -  
227 -  
228 -  
229 -////////////////////////////////////////////////////////////////////////////////////////////////////////////////  
230 -///////////////////////////////////////////////////////////////////////////////////////////////////////////////  
231 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, 203 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
232 const uint16_t wIndex, 204 const uint16_t wIndex,
233 const void** const DescriptorAddress) 205 const void** const DescriptorAddress)
@@ -241,67 +213,6 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, @@ -241,67 +213,6 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
241 switch (DescriptorType) 213 switch (DescriptorType)
242 { 214 {
243 case DTYPE_Device: 215 case DTYPE_Device:
244 - Address = &DeviceDescriptor;  
245 - Size = sizeof(USB_Descriptor_Device_t);  
246 - break;  
247 - case DTYPE_Configuration:  
248 - Address = &ConfigurationDescriptor;  
249 - Size = sizeof(USB_Descriptor_Configuration_t);  
250 - break;  
251 - case DTYPE_String:  
252 - switch (DescriptorNumber)  
253 - {  
254 - case STRING_ID_Language:  
255 - Address = &LanguageString;  
256 - Size = pgm_read_byte(&LanguageString.Header.Size);  
257 - break;  
258 - case STRING_ID_Manufacturer:  
259 - Address = &ManufacturerString;  
260 - Size = pgm_read_byte(&ManufacturerString.Header.Size);  
261 - break;  
262 - case STRING_ID_Product:  
263 - Address = &ProductString;  
264 - Size = pgm_read_byte(&ProductString.Header.Size);  
265 - break;  
266 - }  
267 -  
268 - break;  
269 - case HID_DTYPE_HID:  
270 - Address = &ConfigurationDescriptor.HID_KeyboardHID;  
271 - Size = sizeof(USB_HID_Descriptor_HID_t);  
272 - break;  
273 - case HID_DTYPE_Report:  
274 - Address = &KeyboardReport;  
275 - Size = sizeof(KeyboardReport);  
276 - break;  
277 - }  
278 -  
279 - *DescriptorAddress = Address;  
280 - return Size;  
281 -}  
282 -  
283 -  
284 -/////////////////////////////////////////////////////////////////////////////////  
285 -  
286 -  
287 -uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,  
288 - const uint16_t wIndex,  
289 - const void** const DescriptorAddress)  
290 -{  
291 - cons  
292 -/** Configuration descriptor structure. This descriptor, located in FLASH memory, describes the usage  
293 - * of the device in one of its supported configurations, including information about any device interfaces  
294 - * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting  
295 - * a configuration so that the host may correctly communicate with the USB device.  
296 - */t uint8_t DescriptorType = (wValue >> 8);  
297 - const uint8_t DescriptorNumber = (wValue & 0xFF);  
298 -  
299 - const void* Address = NULL;  
300 - uint16_t Size = NO_DESCRIPTOR;  
301 -  
302 - switch (DescriptorType)  
303 - {  
304 - case DTYPE_Device:  
305 Address = &RelayBoard_DeviceDescriptor; 216 Address = &RelayBoard_DeviceDescriptor;
306 Size = sizeof(USB_Descriptor_Device_t); 217 Size = sizeof(USB_Descriptor_Device_t);
307 break; 218 break;
@@ -336,3 +247,4 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, @@ -336,3 +247,4 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
336 *DescriptorAddress = Address; 247 *DescriptorAddress = Address;
337 return Size; 248 return Size;
338 } 249 }
  250 +
lufa-master/PolytechLille/PAD/Descriptors.h
@@ -51,7 +51,13 @@ @@ -51,7 +51,13 @@
51 USB_Descriptor_Configuration_Header_t Config; 51 USB_Descriptor_Configuration_Header_t Config;
52 52
53 // Relay Board Interface 53 // Relay Board Interface
54 - USB_Descriptor_Interface_t RelayBoardInterface; 54 + USB_Descriptor_Interface_t InterfaceOUT;
  55 + //USB_HID_Descriptor_HID_t HID_KeyboardHID; //UTILE ?
  56 + USB_Descriptor_Endpoint_t HID_ReportOUTEndpoint;
  57 +
  58 + USB_Descriptor_Interface_t InterfaceIN;
  59 + USB_Descriptor_Endpoint_t HID_ReportINEndpointBoutons;
  60 + USB_Descriptor_Endpoint_t HID_ReportOUTEndpointJoystick;
55 } USB_Descriptor_Configuration_t; 61 } USB_Descriptor_Configuration_t;
56 62
57 /** Enum for the device interface descriptor IDs within the device. Each interface descriptor 63 /** Enum for the device interface descriptor IDs within the device. Each interface descriptor
@@ -60,8 +66,8 @@ @@ -60,8 +66,8 @@
60 */ 66 */
61 enum InterfaceDescriptors_t 67 enum InterfaceDescriptors_t
62 { 68 {
63 - INTERFACE_ID_InterfaceOUT = 0,  
64 - INTERFACE_ID_InterfaceIN = 1,/**< Relay board interface descriptor ID */ 69 + INTERFACE_ID_InterfaceOUT = 0, /**< Relay board interface descriptor ID */
  70 + INTERFACE_ID_InterfaceIN = 1,
65 }; 71 };
66 72
67 /** Enum for the device string descriptor IDs within the device. Each string descriptor should 73 /** Enum for the device string descriptor IDs within the device. Each string descriptor should
@@ -76,9 +82,24 @@ @@ -76,9 +82,24 @@
76 STRING_ID_Serial = 3, /**< Serial number string ID */ 82 STRING_ID_Serial = 3, /**< Serial number string ID */
77 }; 83 };
78 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 +
79 /* Function Prototypes: */ 99 /* Function Prototypes: */
80 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, 100 uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
81 const uint16_t wIndex, 101 const uint16_t wIndex,
82 const void** const DescriptorAddress) 102 const void** const DescriptorAddress)
83 ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3); 103 ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
84 #endif 104 #endif
  105 +
lufa-master/PolytechLille/PAD/PAD.c
@@ -53,7 +53,7 @@ int main(void) @@ -53,7 +53,7 @@ int main(void)
53 USB_USBTask(); 53 USB_USBTask();
54 //HID_Task(); 54 //HID_Task();
55 } 55 }
56 - } 56 +}
57 57
58 /** Configures the board hardware and chip peripherals for the project's functionality. */ 58 /** Configures the board hardware and chip peripherals for the project's functionality. */
59 void SetupHardware(void) 59 void SetupHardware(void)
@@ -65,87 +65,121 @@ void SetupHardware(void) @@ -65,87 +65,121 @@ void SetupHardware(void)
65 65
66 /* Disable clock division */ 66 /* Disable clock division */
67 clock_prescale_set(clock_div_1); 67 clock_prescale_set(clock_div_1);
68 -#endif  
69 68
70 69
71 -//TODO INITIALISATIONS 70 +/**INITIALISATIONS*/
72 /* Hardware Initialization */ 71 /* Hardware Initialization */
73 USB_Init(); 72 USB_Init();
  73 + Serial_init(9600,0); //9600 Bauds, configuration
74 74
75 /* Initialize Relays */ 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,20 +45,19 @@
45 45
46 #include "Descriptors.h" 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 #include <LUFA/Drivers/USB/USB.h> 50 #include <LUFA/Drivers/USB/USB.h>
50 #include <LUFA/Platform/Platform.h> 51 #include <LUFA/Platform/Platform.h>
51 52
52 /* Macros: */ 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 /* Function Prototypes: */ 56 /* Function Prototypes: */
60 void SetupHardware(void); 57 void SetupHardware(void);
61 - 58 + void EVENT_USB_Device_ConfigurationChanged(void);
  59 + void SendNextReport(void);
  60 + void ReceiveNextReport(void);
62 void EVENT_USB_Device_ControlRequest(void); 61 void EVENT_USB_Device_ControlRequest(void);
63 62
64 #endif 63 #endif