Skip to content

Commit b928d9b

Browse files
authored
Merge pull request #278 from adafruit/develop
Develop
2 parents e5ed58b + dda9dba commit b928d9b

File tree

71 files changed

+1093
-27492
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1093
-27492
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
*.app
88

99
*.pyc
10-
/tools/nrfutil-0.5.2/build/
11-
/tools/nrfutil-0.5.2/dist/
12-
/tools/nrfutil-0.5.2/nrfutil.egg-info/
1310
/tools/.idea/
1411
/tools/midi_tests/node_modules
1512

changelog.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Adafruit nRF52 Arduino Core Changelog
22

3-
# 0.10.5
3+
# 0.11.0
44

5-
- Fixed Feather nRF52840 Express's qspi driver to work with on-board flash device
65
- Rework USB driver using Adafruit_TinyUSB library
76
- Added Metro nRF52840 Express
87
- Update bootloader binaries to 0.2.11

cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ int Adafruit_USBD_CDC::read(void)
8282
return (int) tud_cdc_read_char();
8383
}
8484

85-
size_t Adafruit_USBD_CDC::readBytes(char *buffer, size_t length)
86-
{
87-
return tud_cdc_read(buffer, length);
88-
}
89-
9085
void Adafruit_USBD_CDC::flush(void)
9186
{
9287
tud_cdc_write_flush();
@@ -106,11 +101,8 @@ size_t Adafruit_USBD_CDC::write(const uint8_t *buffer, size_t size)
106101
remain -= wrcount;
107102
buffer += wrcount;
108103

109-
// Write FIFO is full, flush and re-try
110-
if ( remain )
111-
{
112-
tud_cdc_write_flush();
113-
}
104+
// Write FIFO is full, run usb background to flush
105+
if ( remain ) yield();
114106
}
115107

116108
return size - remain;

cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_CDC.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ class Adafruit_USBD_CDC : public Stream, Adafruit_USBD_Interface
5151
return write((const uint8_t *)buffer, size);
5252
}
5353
operator bool();
54-
55-
size_t readBytes(char *buffer, size_t length);
56-
size_t readBytes(uint8_t *buffer, size_t length) { return readBytes((char *)buffer, length); }
5754
};
5855

5956
extern Adafruit_USBD_CDC Serial;

cores/nRF5/Adafruit_TinyUSB_Core/Adafruit_USBD_Device.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ uint8_t const * tud_descriptor_configuration_cb(uint8_t index)
164164
return USBDevice._desc_cfg;
165165
}
166166

167-
static uint16_t _desc_str[32];
167+
// up to 32 unicode characters (header make it 33)
168+
static uint16_t _desc_str[33];
168169

169170
// Invoked when received GET STRING DESCRIPTOR request
170171
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
@@ -187,7 +188,7 @@ uint16_t const* tud_descriptor_string_cb(uint8_t index)
187188

188189
// cap at max char
189190
chr_count = strlen(str);
190-
if ( chr_count > 31 ) chr_count = 31;
191+
if ( chr_count > 32 ) chr_count = 32;
191192

192193
for(uint8_t i=0; i<chr_count; i++)
193194
{

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/cdc/cdc_device.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,21 @@ typedef struct
7373
//--------------------------------------------------------------------+
7474
CFG_TUSB_MEM_SECTION static cdcd_interface_t _cdcd_itf[CFG_TUD_CDC];
7575

76-
// TODO will be replaced by dcd_edpt_busy()
77-
bool pending_read_from_host;
76+
//bool pending_read_from_host; TODO remove
7877
static void _prep_out_transaction (uint8_t itf)
7978
{
8079
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
8180

8281
// skip if previous transfer not complete
83-
// dcd_edpt_busy() doesn't work, probably transfer is complete but not properly handled by the stack
84-
// if ( dcd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_out) ) return;
85-
if (pending_read_from_host) return;
82+
if ( usbd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_out) ) return;
83+
//if (pending_read_from_host) return;
8684

8785
// Prepare for incoming data but only allow what we can store in the ring buffer.
8886
uint16_t max_read = tu_fifo_remaining(&p_cdc->rx_ff);
8987
if ( max_read >= CFG_TUD_CDC_EPSIZE )
9088
{
91-
dcd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_out, p_cdc->epout_buf, CFG_TUD_CDC_EPSIZE);
92-
pending_read_from_host = true;
89+
usbd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_out, p_cdc->epout_buf, CFG_TUD_CDC_EPSIZE);
90+
// pending_read_from_host = true;
9391
}
9492
}
9593

@@ -183,13 +181,13 @@ uint32_t tud_cdc_n_write(uint8_t itf, void const* buffer, uint32_t bufsize)
183181
bool tud_cdc_n_write_flush (uint8_t itf)
184182
{
185183
cdcd_interface_t* p_cdc = &_cdcd_itf[itf];
186-
TU_VERIFY( !dcd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_in) ); // skip if previous transfer not complete
184+
TU_VERIFY( !usbd_edpt_busy(TUD_OPT_RHPORT, p_cdc->ep_in) ); // skip if previous transfer not complete
187185

188186
uint16_t count = tu_fifo_read_n(&_cdcd_itf[itf].tx_ff, p_cdc->epin_buf, CFG_TUD_CDC_EPSIZE);
189187
if ( count )
190188
{
191189
TU_VERIFY( tud_cdc_n_connected(itf) ); // fifo is empty if not connected
192-
TU_ASSERT( dcd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_in, p_cdc->epin_buf, count) );
190+
TU_ASSERT( usbd_edpt_xfer(TUD_OPT_RHPORT, p_cdc->ep_in, p_cdc->epin_buf, count) );
193191
}
194192

195193
return true;
@@ -298,7 +296,7 @@ bool cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t
298296
}
299297

300298
// Prepare for incoming data
301-
pending_read_from_host = false;
299+
// pending_read_from_host = false;
302300
_prep_out_transaction(cdc_id);
303301

304302
return true;
@@ -394,7 +392,7 @@ bool cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
394392
if (tud_cdc_rx_cb && tu_fifo_count(&p_cdc->rx_ff) ) tud_cdc_rx_cb(itf);
395393

396394
// prepare for OUT transaction
397-
pending_read_from_host = false;
395+
// pending_read_from_host = false;
398396
_prep_out_transaction(itf);
399397
}
400398

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/hid/hid_device.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,28 +73,31 @@ bool tud_hid_ready(void)
7373
{
7474
uint8_t itf = 0;
7575
uint8_t const ep_in = _hidd_itf[itf].ep_in;
76-
return tud_ready() && (ep_in != 0) && !dcd_edpt_busy(TUD_OPT_RHPORT, ep_in);
76+
return tud_ready() && (ep_in != 0) && !usbd_edpt_busy(TUD_OPT_RHPORT, ep_in);
7777
}
7878

7979
bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len)
8080
{
81-
TU_VERIFY( tud_hid_ready() && (len < CFG_TUD_HID_BUFSIZE) );
81+
TU_VERIFY( tud_hid_ready() );
8282

8383
uint8_t itf = 0;
8484
hidd_interface_t * p_hid = &_hidd_itf[itf];
8585

86-
// If report id = 0, skip ID field
8786
if (report_id)
8887
{
88+
len = tu_min8(len, CFG_TUD_HID_BUFSIZE-1);
89+
8990
p_hid->epin_buf[0] = report_id;
9091
memcpy(p_hid->epin_buf+1, report, len);
9192
len++;
9293
}else
9394
{
95+
// If report id = 0, skip ID field
96+
len = tu_min8(len, CFG_TUD_HID_BUFSIZE);
9497
memcpy(p_hid->epin_buf, report, len);
9598
}
9699

97-
return dcd_edpt_xfer(TUD_OPT_RHPORT, p_hid->ep_in, p_hid->epin_buf, len);
100+
return usbd_edpt_xfer(TUD_OPT_RHPORT, p_hid->ep_in, p_hid->epin_buf, len);
98101
}
99102

100103
bool tud_hid_boot_mode(void)
@@ -180,7 +183,7 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t
180183
*p_len = sizeof(tusb_desc_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + desc_itf->bNumEndpoints*sizeof(tusb_desc_endpoint_t);
181184

182185
// Prepare for output endpoint
183-
if (p_hid->ep_out) TU_ASSERT(dcd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)));
186+
if (p_hid->ep_out) TU_ASSERT(usbd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)));
184187

185188
return true;
186189
}
@@ -303,7 +306,7 @@ bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
303306
if (ep_addr == p_hid->ep_out)
304307
{
305308
tud_hid_set_report_cb(0, HID_REPORT_TYPE_INVALID, p_hid->epout_buf, xferred_bytes);
306-
TU_ASSERT(dcd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)));
309+
TU_ASSERT(usbd_edpt_xfer(rhport, p_hid->ep_out, p_hid->epout_buf, sizeof(p_hid->epout_buf)));
307310
}
308311

309312
return true;

cores/nRF5/Adafruit_TinyUSB_Core/tinyusb/src/class/msc/msc_device.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ bool mscd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t
139139
(*p_len) = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t);
140140

141141
// Prepare for Command Block Wrapper
142-
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) );
142+
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) );
143143

144144
return true;
145145
}
@@ -394,7 +394,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
394394
if ( (p_cbw->total_bytes > 0 ) && !tu_bit_test(p_cbw->dir, 7) )
395395
{
396396
// queue transfer
397-
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, p_msc->total_len) );
397+
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, p_msc->total_len) );
398398
}else
399399
{
400400
int32_t resplen;
@@ -428,7 +428,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
428428
if (p_msc->total_len)
429429
{
430430
TU_ASSERT( p_cbw->total_bytes >= p_msc->total_len ); // cannot return more than host expect
431-
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, p_msc->total_len) );
431+
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, p_msc->total_len) );
432432
}else
433433
{
434434
p_msc->stage = MSC_STAGE_STATUS;
@@ -543,7 +543,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
543543
p_msc->stage = MSC_STAGE_CMD;
544544

545545
// Send SCSI Status
546-
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_in , (uint8_t*) &p_msc->csw, sizeof(msc_csw_t)) );
546+
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_in , (uint8_t*) &p_msc->csw, sizeof(msc_csw_t)) );
547547

548548
// Invoke complete callback if defined
549549
if ( SCSI_CMD_READ_10 == p_cbw->command[0])
@@ -560,7 +560,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
560560
}
561561

562562
// Queue for the next CBW
563-
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) );
563+
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, (uint8_t*) &p_msc->cbw, sizeof(msc_cbw_t)) );
564564
}
565565
}
566566

@@ -602,7 +602,7 @@ static void proc_read10_cmd(uint8_t rhport, mscd_interface_t* p_msc)
602602
}
603603
else
604604
{
605-
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, nbytes), );
605+
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_in, _mscd_buf, nbytes), );
606606
}
607607
}
608608

@@ -627,7 +627,7 @@ static void proc_write10_cmd(uint8_t rhport, mscd_interface_t* p_msc)
627627
int32_t nbytes = (int32_t) tu_min32(sizeof(_mscd_buf), p_cbw->total_bytes-p_msc->xferred_len);
628628

629629
// Write10 callback will be called later when usb transfer complete
630-
TU_ASSERT( dcd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, nbytes), );
630+
TU_ASSERT( usbd_edpt_xfer(rhport, p_msc->ep_out, _mscd_buf, nbytes), );
631631
}
632632

633633
#endif

0 commit comments

Comments
 (0)