MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / xs_arducam_read

Function xs_arducam_read

modules/drivers/arducam/modArducam.c:263–335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

261}
262
263void xs_arducam_read(xsMachine *the)
264{
265 ArduCAM ac = xsmcGetHostData(xsThis);
266 int argc = xsmcArgc;
267 int i;
268 uint8_t data[4];
269 uint8_t *buffer;
270 int bufferSize = xsmcGetArrayBufferLength(xsArg(0));
271 int readSize;
272
273 if (1 == argc)
274 readSize = bufferSize;
275 else {
276 readSize = xsmcToInteger(xsArg(1));
277 if (readSize > bufferSize)
278 readSize = bufferSize;
279 }
280
281 if (readSize > ac->bytesAvailable)
282 readSize = ac->bytesAvailable;
283
284 buffer = xsmcToArrayBuffer(xsArg(0));
285
286#if 0
287 if (ac->skipFirst) {
288 readRegisterSPI_FIFO(ac);
289 ac->skipFirst = 0;
290 }
291
292 for (i = 0; i < readSize; i += 1)
293 *buffer++ = readRegisterSPI_FIFO(ac);
294#else
295 if (ac->startBurst) {
296 data[0] = BURST_FIFO_READ;
297 modSPITx(&ac->spiConfig, data, 1);
298 ac->startBurst = 0;
299 }
300
301 if (ac->skipFirst) {
302 uint8_t dummy = 0xff;
303 modSPITxRx(&ac->spiConfig, &dummy, 1);
304 ac->skipFirst = 0;
305 }
306
307 for (i = 0; i < readSize; ) {
308 uint32_t temp32[64 / 4];
309 uint8_t *temp8 = (uint8_t *)temp32;
310 int use = readSize - i;
311 if (use > 64) use = 64;
312
313 modSPITxRx(&ac->spiConfig, temp8, use);
314
315 if (ac->swap16) {
316 uint8_t j;
317 for (j = 0; j < use; j+= 2) {
318 uint8_t temp = temp8[j];
319 temp8[j] = temp8[j + 1];
320 temp8[j + 1] = temp;

Callers

nothing calls this directly

Calls 3

readRegisterSPI_FIFOFunction · 0.85
modSPITxFunction · 0.50
modSPITxRxFunction · 0.50

Tested by

no test coverage detected