Skip to content

Commit 9c5b292

Browse files
Remove last static fcns, optimize flash/RAM
Blink.ino +328 flash, +28 RAM
1 parent 0f47197 commit 9c5b292

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

cores/rp2040/USB.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ uint8_t USBClass::addEntry(Entry **head, int interfaces, const uint8_t *descript
9595
static uint8_t id = 1;
9696

9797
Entry *n = (Entry *)malloc(sizeof(Entry));
98-
assert(n);
9998
n->descriptor = descriptor;
10099
n->len = len;
101100
n->interfaces = interfaces;
@@ -151,7 +150,6 @@ unsigned int USBClass::findID(Entry *head, unsigned int localid) {
151150
head = head->next;
152151
x++;
153152
}
154-
assert(head);
155153
return x;
156154
}
157155

@@ -285,7 +283,6 @@ void USBClass::setupDescHIDReport() {
285283

286284
// Allocate the "real" HID report descriptor
287285
_hid_report = (uint8_t *)malloc(_hid_report_len);
288-
assert(_hid_report);
289286

290287
// Now copy the descriptors
291288
uint8_t *p = _hid_report;
@@ -362,7 +359,6 @@ void USBClass::setupUSBDescriptor() {
362359

363360
// Allocate the "real" HID report descriptor
364361
usbd_desc_cfg = (uint8_t *)malloc(usbd_desc_cfg_len);
365-
assert(usbd_desc_cfg);
366362
bzero(usbd_desc_cfg, usbd_desc_cfg_len);
367363

368364
// Now copy the descriptors
@@ -409,7 +405,7 @@ const uint16_t *USBClass::tud_descriptor_string_cb(uint8_t index, uint16_t langi
409405
}
410406

411407
#ifdef __FREERTOS
412-
void __freertos_usb_task(void *param) {
408+
void USBClass::freertosUSBTask(void *param) {
413409
(void) param;
414410

415411
Serial.begin(115200);
@@ -429,7 +425,7 @@ void __freertos_usb_task(void *param) {
429425
}
430426
}
431427
#else
432-
static void usb_irq() {
428+
void USBClass::usbIRQ() {
433429
// if the mutex is already owned, then we are in user code
434430
// in this file which will do a tud_task itself, so we'll just do nothing
435431
// until the next tick; we won't starve
@@ -439,7 +435,7 @@ static void usb_irq() {
439435
}
440436
}
441437

442-
static int64_t timer_task(__unused alarm_id_t id, __unused void *user_data) {
438+
int64_t USBClass::timerTask(__unused alarm_id_t id, __unused void *user_data) {
443439
irq_set_pending(USB.usbTaskIRQ);
444440
return USB_TASK_INTERVAL;
445441
}
@@ -508,13 +504,13 @@ void USBClass::begin() {
508504
#ifdef __FREERTOS
509505
// Make high prio and locked to core 0
510506
TaskHandle_t usbTask;
511-
xTaskCreate(__freertos_usb_task, "USB", 256, 0, configMAX_PRIORITIES - 2, &usbTask);
507+
xTaskCreate(freertosUSBTask, "USB", 256, 0, configMAX_PRIORITIES - 2, &usbTask);
512508
vTaskCoreAffinitySet(usbTask, 1 << 0);
513509
#else
514510
usbTaskIRQ = user_irq_claim_unused(true);
515-
irq_set_exclusive_handler(usbTaskIRQ, usb_irq);
511+
irq_set_exclusive_handler(usbTaskIRQ, usbIRQ);
516512
irq_set_enabled(usbTaskIRQ, true);
517-
add_alarm_in_us(USB_TASK_INTERVAL, timer_task, nullptr, true);
513+
add_alarm_in_us(USB_TASK_INTERVAL, timerTask, nullptr, true);
518514
#endif
519515
}
520516

cores/rp2040/USB.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class USBClass {
9191
volatile bool initted = false;
9292
#else
9393
// The user IRQ for the USB "task"
94-
int usbTaskIRQ;
94+
uint8_t usbTaskIRQ;
9595
#endif
9696

9797
private:
@@ -134,18 +134,18 @@ class USBClass {
134134
uint8_t usbd_desc_str_alloc = 0;
135135

136136
// HID report
137-
unsigned int _hid_interface = (unsigned int) -1;
137+
uint8_t _hid_interface = (unsigned uint8_t) -1;
138138
uint8_t _hid_endpoint = 0;
139-
int _hid_report_len = 0;
139+
uint16_t _hid_report_len = 0;
140140
uint8_t *_hid_report = nullptr;
141141

142142
// Global USB descriptor
143143
uint8_t *usbd_desc_cfg = nullptr;
144-
int usbd_desc_cfg_len = 0;
144+
uint16_t usbd_desc_cfg_len = 0;
145145

146146
// Available bitmask for endpoints, can never be EP 0
147-
uint32_t _endpointIn = 0xfffffffe;
148-
uint32_t _endpointOut = 0xfffffffe;
147+
uint16_t _endpointIn = 0xfffe;
148+
uint16_t _endpointOut = 0xfffe;
149149

150150
// Overrides for the USB ID/etc.
151151
uint16_t _forceVID = 0;
@@ -156,6 +156,15 @@ class USBClass {
156156

157157
// USB device descriptor
158158
tusb_desc_device_t usbd_desc_device;
159+
160+
// Periodic task
161+
#ifdef __FREERTOS
162+
static void freertosUSBTask(void *param);
163+
#else
164+
static void usbIRQ();
165+
static int64_t timerTask(__unused alarm_id_t id, __unused void *user_data);
166+
#endif
167+
159168
};
160169

161170
extern USBClass USB;

0 commit comments

Comments
 (0)