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

Function xs_i2c_read

modules/pins/i2c/i2c.c:92–120  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92void xs_i2c_read(xsMachine *the)
93{
94 modI2C i2c;
95 int argc = xsmcArgc;
96 unsigned int len = xsmcToInteger(xsArg(0)), i;
97 unsigned char err;
98 unsigned char buffer[40];
99
100 if (len > sizeof(buffer))
101 xsUnknownError("40 byte read limit");
102
103 i2c = xsmcGetHostChunk(xsThis);
104 err = modI2CRead(&i2c->state, buffer, len, true);
105 if (err)
106 return; // undefined returned on read failure
107
108 if (argc >= 2) {
109 int bufferByteLength;
110 xsResult = xsArg(1);
111 bufferByteLength = xsmcGetArrayBufferLength(xsResult);
112 if (bufferByteLength < len)
113 xsUnknownError("buffer too small");
114 c_memmove(xsmcToArrayBuffer(xsResult), buffer, len);
115 }
116 else {
117 xsmcSetArrayBuffer(xsResult, buffer, len);
118 xsResult = xsNew1(xsGlobal, xsID_Uint8Array, xsResult);
119 }
120}
121
122void xs_i2c_write(xsMachine *the)
123{

Callers

nothing calls this directly

Calls 1

modI2CReadFunction · 0.50

Tested by

no test coverage detected