pxt-common-packages 10.1.5 → 10.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/libs/core/hf2.cpp
CHANGED
|
@@ -101,21 +101,54 @@ int HF2::stdRequest(UsbEndpointIn &ctrl, USBSetup &setup) {
|
|
|
101
101
|
return DEVICE_NOT_SUPPORTED;
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
|
|
105
|
-
#define CTRL_GET_REPORT 0x01
|
|
106
|
-
#define CTRL_SET_REPORT 0x09
|
|
107
|
-
#define CTRL_OUT_REPORT_H 0x2
|
|
108
|
-
#define CTRL_IN_REPORT_H 0x1
|
|
104
|
+
#define HF2_FLAG_EVENT 0x01
|
|
109
105
|
|
|
106
|
+
REAL_TIME_FUNC
|
|
110
107
|
void HF2::sendBuffer(uint8_t flag, const void *data, unsigned size, uint32_t prepend) {
|
|
111
108
|
if (!CodalUSB::usbInstance->isInitialised())
|
|
112
109
|
return;
|
|
113
110
|
|
|
114
|
-
|
|
111
|
+
#ifdef USB_EP_FLAG_ASYNC
|
|
112
|
+
// drop non-responses if too much stuff queued up
|
|
113
|
+
if (flag != HF2_FLAG_CMDPKT_LAST && pendingWriteSize > 1000)
|
|
114
|
+
return;
|
|
115
|
+
#endif
|
|
116
|
+
|
|
117
|
+
if (flag == HF2_FLAG_EVENT)
|
|
118
|
+
flag = HF2_FLAG_CMDPKT_LAST;
|
|
115
119
|
|
|
116
120
|
if (prepend + 1)
|
|
117
121
|
size += 4;
|
|
118
122
|
|
|
123
|
+
#ifdef USB_EP_FLAG_ASYNC
|
|
124
|
+
HF2_PendingWrite *e = (HF2_PendingWrite *)malloc(sizeof(HF2_PendingWrite) + size);
|
|
125
|
+
e->size = size;
|
|
126
|
+
e->flag = flag;
|
|
127
|
+
e->next = NULL;
|
|
128
|
+
uint8_t *dst = e->data;
|
|
129
|
+
if (prepend + 1) {
|
|
130
|
+
memcpy(dst, &prepend, 4);
|
|
131
|
+
dst += 4;
|
|
132
|
+
size -= 4;
|
|
133
|
+
}
|
|
134
|
+
memcpy(dst, data, size);
|
|
135
|
+
|
|
136
|
+
target_disable_irq();
|
|
137
|
+
auto p = this->pendingWrite;
|
|
138
|
+
if (!p)
|
|
139
|
+
this->pendingWrite = e;
|
|
140
|
+
else {
|
|
141
|
+
while (p->next)
|
|
142
|
+
p = p->next;
|
|
143
|
+
p->next = e;
|
|
144
|
+
}
|
|
145
|
+
this->pendingWriteSize += 16 + e->size;
|
|
146
|
+
target_enable_irq();
|
|
147
|
+
|
|
148
|
+
pokeSend();
|
|
149
|
+
#else
|
|
150
|
+
uint32_t buf[64 / 4]; // aligned
|
|
151
|
+
|
|
119
152
|
target_disable_irq();
|
|
120
153
|
while (size > 0) {
|
|
121
154
|
memset(buf + 1, 0, 60);
|
|
@@ -143,6 +176,7 @@ void HF2::sendBuffer(uint8_t flag, const void *data, unsigned size, uint32_t pre
|
|
|
143
176
|
in->write(buf, sizeof(buf));
|
|
144
177
|
}
|
|
145
178
|
target_enable_irq();
|
|
179
|
+
#endif
|
|
146
180
|
}
|
|
147
181
|
|
|
148
182
|
const InterfaceInfo *HF2::getInterfaceInfo() {
|
|
@@ -154,7 +188,7 @@ const InterfaceInfo *HF2::getInterfaceInfo() {
|
|
|
154
188
|
}
|
|
155
189
|
|
|
156
190
|
int HF2::sendEvent(uint32_t evId, const void *data, int size) {
|
|
157
|
-
sendBuffer(
|
|
191
|
+
sendBuffer(HF2_FLAG_EVENT, data, size, evId);
|
|
158
192
|
return 0;
|
|
159
193
|
}
|
|
160
194
|
|
|
@@ -231,7 +265,7 @@ static void copy_words(void *dst0, const void *src0, uint32_t n_words) {
|
|
|
231
265
|
#define DBL_TAP_PTR ((volatile uint32_t *)(HSRAM_ADDR + HSRAM_SIZE - 4))
|
|
232
266
|
#endif
|
|
233
267
|
#if defined(NRF52840) || defined(NRF52833)
|
|
234
|
-
#define DBL_TAP_PTR ((volatile uint32_t*)0x20007F7C)
|
|
268
|
+
#define DBL_TAP_PTR ((volatile uint32_t *)0x20007F7C)
|
|
235
269
|
#endif
|
|
236
270
|
#define DBL_TAP_MAGIC_QUICK_BOOT 0xf02669ef
|
|
237
271
|
#define QUICK_BOOT(v) *DBL_TAP_PTR = v ? DBL_TAP_MAGIC_QUICK_BOOT : 0
|
|
@@ -242,7 +276,50 @@ static void jdLog(const uint8_t *frame) {
|
|
|
242
276
|
jdLogger->sendEvent(HF2_EV_JDS_PACKET, frame, frame[2] + 12);
|
|
243
277
|
}
|
|
244
278
|
|
|
279
|
+
void HF2::pokeSend() {
|
|
280
|
+
#ifdef USB_EP_FLAG_ASYNC
|
|
281
|
+
target_disable_irq();
|
|
282
|
+
if (pendingWrite && in->canWrite()) {
|
|
283
|
+
in->flags |= USB_EP_FLAG_ASYNC;
|
|
284
|
+
|
|
285
|
+
int size = pendingWrite->size - pendingWritePtr;
|
|
286
|
+
usb_assert(size > 0);
|
|
287
|
+
uint32_t buf[64 / 4] = {0};
|
|
288
|
+
|
|
289
|
+
int s = 63;
|
|
290
|
+
if (size <= 63) {
|
|
291
|
+
s = size;
|
|
292
|
+
buf[0] = pendingWrite->flag;
|
|
293
|
+
} else {
|
|
294
|
+
buf[0] = pendingWrite->flag == HF2_FLAG_CMDPKT_LAST ? HF2_FLAG_CMDPKT_BODY : pendingWrite->flag;
|
|
295
|
+
}
|
|
296
|
+
buf[0] |= s;
|
|
297
|
+
uint8_t *dst = (uint8_t *)buf;
|
|
298
|
+
dst++;
|
|
299
|
+
memcpy(dst, pendingWrite->data + pendingWritePtr, s);
|
|
300
|
+
|
|
301
|
+
int r = in->write(buf, sizeof(buf));
|
|
302
|
+
if (r == 0) {
|
|
303
|
+
if (s == size) {
|
|
304
|
+
pendingWritePtr = 0;
|
|
305
|
+
pendingWriteSize -= 16 + pendingWrite->size;
|
|
306
|
+
HF2_PendingWrite *n = pendingWrite->next;
|
|
307
|
+
free(pendingWrite);
|
|
308
|
+
pendingWrite = n;
|
|
309
|
+
} else {
|
|
310
|
+
pendingWritePtr += s;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
target_enable_irq();
|
|
315
|
+
#endif
|
|
316
|
+
}
|
|
317
|
+
|
|
245
318
|
int HF2::endpointRequest() {
|
|
319
|
+
#ifdef USB_EP_FLAG_ASYNC
|
|
320
|
+
pokeSend();
|
|
321
|
+
#endif
|
|
322
|
+
|
|
246
323
|
int sz = recv();
|
|
247
324
|
|
|
248
325
|
if (!sz)
|
|
@@ -369,6 +446,11 @@ int HF2::endpointRequest() {
|
|
|
369
446
|
|
|
370
447
|
HF2::HF2(HF2_Buffer &p) : gotSomePacket(false), ctrlWaiting(false), pkt(p), useHID(false) {
|
|
371
448
|
lastExchange = 0;
|
|
449
|
+
#ifdef USB_EP_FLAG_ASYNC
|
|
450
|
+
pendingWrite = NULL;
|
|
451
|
+
pendingWriteSize = 0;
|
|
452
|
+
pendingWritePtr = 0;
|
|
453
|
+
#endif
|
|
372
454
|
}
|
|
373
455
|
|
|
374
456
|
static const InterfaceInfo dummyIfaceInfo = {
|
package/libs/core/hf2.h
CHANGED
|
@@ -21,11 +21,25 @@ typedef struct {
|
|
|
21
21
|
};
|
|
22
22
|
} HF2_Buffer;
|
|
23
23
|
|
|
24
|
+
struct HF2_PendingWrite {
|
|
25
|
+
HF2_PendingWrite *next;
|
|
26
|
+
uint16_t size;
|
|
27
|
+
uint8_t flag;
|
|
28
|
+
uint8_t _reserved;
|
|
29
|
+
uint8_t data[0];
|
|
30
|
+
};
|
|
31
|
+
|
|
24
32
|
class HF2 : public CodalUSBInterface {
|
|
25
33
|
bool gotSomePacket;
|
|
26
34
|
bool ctrlWaiting;
|
|
27
35
|
uint32_t lastExchange;
|
|
28
36
|
|
|
37
|
+
#ifdef USB_EP_FLAG_ASYNC
|
|
38
|
+
HF2_PendingWrite *pendingWrite;
|
|
39
|
+
int pendingWriteSize;
|
|
40
|
+
int pendingWritePtr;
|
|
41
|
+
#endif
|
|
42
|
+
|
|
29
43
|
public:
|
|
30
44
|
HF2_Buffer &pkt;
|
|
31
45
|
|
|
@@ -36,6 +50,7 @@ class HF2 : public CodalUSBInterface {
|
|
|
36
50
|
int sendResponseWithData(const void *data, int size);
|
|
37
51
|
int sendEvent(uint32_t evId, const void *data, int size);
|
|
38
52
|
void sendBuffer(uint8_t flag, const void *data, unsigned size, uint32_t prepend = -1);
|
|
53
|
+
void pokeSend();
|
|
39
54
|
|
|
40
55
|
HF2(HF2_Buffer &pkt);
|
|
41
56
|
virtual int endpointRequest();
|
package/libs/core/pxt.h
CHANGED
|
@@ -4,26 +4,54 @@
|
|
|
4
4
|
|
|
5
5
|
#include "hardware/pll.h"
|
|
6
6
|
#include "hardware/clocks.h"
|
|
7
|
+
#include "hardware/structs/rosc.h"
|
|
7
8
|
|
|
8
9
|
namespace pxt {
|
|
9
10
|
|
|
10
11
|
LowLevelTimer *allocateTimer() {
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
// TODO: add config to low level timer
|
|
13
|
+
return new RP2040LowLevelTimer();
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
static
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
static uint32_t hw_random(void) {
|
|
17
|
+
uint8_t buf[16];
|
|
18
|
+
for (unsigned i = 0; i < sizeof(buf); ++i) {
|
|
19
|
+
buf[i] = 0;
|
|
20
|
+
for (int j = 0; j < 8; ++j) {
|
|
21
|
+
buf[i] <<= 1;
|
|
22
|
+
if (rosc_hw->randombit)
|
|
23
|
+
buf[i] |= 1;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return hash_fnv1(buf, sizeof(buf));
|
|
18
27
|
}
|
|
19
28
|
|
|
20
|
-
void
|
|
21
|
-
|
|
29
|
+
static void initRandomSeed() {
|
|
30
|
+
seedRandom(hw_random());
|
|
22
31
|
}
|
|
23
32
|
|
|
33
|
+
void deepSleep() {}
|
|
34
|
+
|
|
24
35
|
void platform_init() {
|
|
25
|
-
|
|
36
|
+
initRandomSeed();
|
|
37
|
+
}
|
|
26
38
|
|
|
39
|
+
int *getBootloaderConfigData() {
|
|
40
|
+
static bool inited;
|
|
41
|
+
static int *cached;
|
|
42
|
+
|
|
43
|
+
if (!inited) {
|
|
44
|
+
inited = 1;
|
|
45
|
+
for (int i = 1; i <= 64; i *= 2) {
|
|
46
|
+
uint32_t *p = (uint32_t *)(XIP_BASE + i * 1024 * 1024 - 4096);
|
|
47
|
+
if (p[0] == CFG_MAGIC0 && p[1] == CFG_MAGIC1) {
|
|
48
|
+
cached = (int *)p;
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return cached;
|
|
27
55
|
}
|
|
28
56
|
|
|
29
57
|
} // namespace pxt
|
|
@@ -37,7 +37,7 @@ class WStorage {
|
|
|
37
37
|
SETTINGS_SIZE),
|
|
38
38
|
#elif defined(PICO_BOARD)
|
|
39
39
|
// XIP bias 0x10000000
|
|
40
|
-
fs(flash, 0x10000000 + flash.totalSize() - SETTINGS_SIZE, SETTINGS_SIZE),
|
|
40
|
+
fs(flash, 0x10000000 + flash.totalSize() - SETTINGS_SIZE - 4096, SETTINGS_SIZE),
|
|
41
41
|
#else
|
|
42
42
|
fs(flash),
|
|
43
43
|
#endif
|