@@ -172,13 +172,22 @@ uint32_t USB_Write(Usb *pUsb, const char *pData, uint32_t length, uint8_t ep_num
172
172
/* Set the multi packet size as zero for multi-packet transfers where length > ep size */
173
173
usb_endpoint_table [ep_num ].DeviceDescBank [1 ].PCKSIZE .bit .MULTI_PACKET_SIZE = 0 ;
174
174
/* Clear the transfer complete flag */
175
- //pUsb->DEVICE.DeviceEndpoint[ep_num].EPINTFLAG.bit.TRCPT1 = true;
175
+
176
+ #ifdef __SAMR21G18A__
177
+ pUsb -> DEVICE .DeviceEndpoint [ep_num ].EPINTFLAG .bit .TRCPT1 = true;
178
+ #else
176
179
pUsb -> DEVICE .DeviceEndpoint [ep_num ].EPINTFLAG .bit .TRCPT |= (1 <<1 );
180
+ #endif
181
+
177
182
/* Set the bank as ready */
178
183
pUsb -> DEVICE .DeviceEndpoint [ep_num ].EPSTATUSSET .bit .BK1RDY = true;
179
184
180
185
/* Wait for transfer to complete */
186
+ #ifdef __SAMR21G18A__
187
+ while ( (pUsb -> DEVICE .DeviceEndpoint [ep_num ].EPINTFLAG .bit .TRCPT1 ) == 0 );
188
+ #else
181
189
while ( (pUsb -> DEVICE .DeviceEndpoint [ep_num ].EPINTFLAG .bit .TRCPT & (1 <<1 )) == 0 );
190
+ #endif
182
191
183
192
return length ;
184
193
}
@@ -205,15 +214,22 @@ uint32_t USB_Read(Usb *pUsb, char *pData, uint32_t length)
205
214
}
206
215
207
216
/* Check for Transfer Complete 0 flag */
217
+ #ifdef __SAMR21G18A__
218
+ if ( pUsb -> DEVICE .DeviceEndpoint [USB_EP_OUT ].EPINTFLAG .bit .TRCPT0 )
219
+ #else
208
220
if ( pUsb -> DEVICE .DeviceEndpoint [USB_EP_OUT ].EPINTFLAG .bit .TRCPT & (1 <<0 ) )
221
+ #endif
209
222
{
210
223
/* Set packet size */
211
224
packetSize = SAM_BA_MIN (usb_endpoint_table [USB_EP_OUT ].DeviceDescBank [0 ].PCKSIZE .bit .BYTE_COUNT , length );
212
225
/* Copy read data to user buffer */
213
226
memcpy (pData , udd_ep_out_cache_buffer [USB_EP_OUT - 1 ], packetSize );
214
227
/* Clear the Transfer Complete 0 flag */
215
- //pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0 = true;
228
+ #ifdef __SAMR21G18A__
229
+ pUsb -> DEVICE .DeviceEndpoint [USB_EP_OUT ].EPINTFLAG .bit .TRCPT0 = true;
230
+ #else
216
231
pUsb -> DEVICE .DeviceEndpoint [USB_EP_OUT ].EPINTFLAG .bit .TRCPT |= (1 << 0 );
232
+ #endif
217
233
/* Clear the user flag */
218
234
read_job = false;
219
235
}
@@ -240,10 +256,16 @@ uint32_t USB_Read_blocking(Usb *pUsb, char *pData, uint32_t length)
240
256
/* Clear the bank 0 ready flag */
241
257
pUsb -> DEVICE .DeviceEndpoint [USB_EP_OUT ].EPSTATUSCLR .bit .BK0RDY = true;
242
258
/* Wait for transfer to complete */
259
+
260
+ #ifdef __SAMR21G18A__
261
+ while (!( pUsb -> DEVICE .DeviceEndpoint [USB_EP_OUT ].EPINTFLAG .bit .TRCPT0 ));
262
+ /* Clear Transfer complete 0 flag */
263
+ pUsb -> DEVICE .DeviceEndpoint [USB_EP_OUT ].EPINTFLAG .bit .TRCPT0 = true;
264
+ #else
243
265
while (!( pUsb -> DEVICE .DeviceEndpoint [USB_EP_OUT ].EPINTFLAG .bit .TRCPT & (1 <<0 ) ));
244
266
/* Clear Transfer complete 0 flag */
245
- //pUsb->DEVICE.DeviceEndpoint[USB_EP_OUT].EPINTFLAG.bit.TRCPT0 = true;
246
267
pUsb -> DEVICE .DeviceEndpoint [USB_EP_OUT ].EPINTFLAG .bit .TRCPT |= (1 << 0 );
268
+ #endif
247
269
248
270
return length ;
249
271
}
@@ -303,14 +325,20 @@ void USB_SendStall(Usb *pUsb, bool direction_in)
303
325
if (direction_in )
304
326
{
305
327
/* Set STALL request on IN direction */
306
- //pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ1;
328
+ #ifdef __SAMR21G18A__
329
+ pUsb -> DEVICE .DeviceEndpoint [0 ].EPSTATUSSET .reg = USB_DEVICE_EPSTATUSSET_STALLRQ1 ;
330
+ #else
307
331
pUsb -> DEVICE .DeviceEndpoint [0 ].EPSTATUSSET .bit .STALLRQ = (1 <<1 );
332
+ #endif
308
333
}
309
334
else
310
335
{
311
336
/* Set STALL request on OUT direction */
312
- //pUsb->DEVICE.DeviceEndpoint[0].EPSTATUSSET.reg = USB_DEVICE_EPSTATUSSET_STALLRQ0;
337
+ #ifdef __SAMR21G18A__
338
+ pUsb -> DEVICE .DeviceEndpoint [0 ].EPSTATUSSET .reg = USB_DEVICE_EPSTATUSSET_STALLRQ0 ;
339
+ #else
313
340
pUsb -> DEVICE .DeviceEndpoint [0 ].EPSTATUSSET .bit .STALLRQ = (1 <<0 );
341
+ #endif
314
342
}
315
343
}
316
344
@@ -322,12 +350,19 @@ void USB_SendZlp(Usb *pUsb)
322
350
/* Set the byte count as zero */
323
351
usb_endpoint_table [0 ].DeviceDescBank [1 ].PCKSIZE .bit .BYTE_COUNT = 0 ;
324
352
/* Clear the transfer complete flag */
325
- //pUsb->DEVICE.DeviceEndpoint[0].EPINTFLAG.bit.TRCPT1 = true;
353
+ #ifdef __SAMR21G18A__
354
+ pUsb -> DEVICE .DeviceEndpoint [0 ].EPINTFLAG .bit .TRCPT1 = true;
355
+ #else
326
356
pUsb -> DEVICE .DeviceEndpoint [0 ].EPINTFLAG .bit .TRCPT |= (1 << 1 );
357
+ #endif
327
358
/* Set the bank as ready */
328
359
pUsb -> DEVICE .DeviceEndpoint [0 ].EPSTATUSSET .bit .BK1RDY = true;
329
360
/* Wait for transfer to complete */
361
+ #ifdef __SAMR21G18A__
362
+ while (!( pUsb -> DEVICE .DeviceEndpoint [0 ].EPINTFLAG .bit .TRCPT1 ));
363
+ #else
330
364
while (!( pUsb -> DEVICE .DeviceEndpoint [0 ].EPINTFLAG .bit .TRCPT & (1 <<1 ) ));
365
+ #endif
331
366
}
332
367
333
368
/*----------------------------------------------------------------------------
0 commit comments