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

Function xs_serial_constructor

modules/io/serial/nrf52/serial.c:162–389  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

160
161
162void xs_serial_constructor(xsMachine *the)
163{
164 Serial serial;
165 int baud;
166 uint8_t hasReadable, hasWritable, format;
167 uint8_t receivePullup = 0;
168 xsSlot *onReadable, *onWritable;
169 int transmitPin = kInvalidPin, receivePin = kInvalidPin;
170 int data = 8, parity = 0;
171 uint16_t transmitNotifyThreshold;
172#if MODDEF_SERIAL_TXACTIVE
173 int32_t txActivePin = kInvalidPin;
174 uint8_t txActiveEnable = 1;
175 uint8_t txActiveMode = kDigitalOutput;
176#endif
177
178 xsmcVars(2);
179
180 if (xsmcGet(xsVar(0), xsArg(0), xsID_transmit)) {
181 transmitPin = builtinGetPin(the, &xsVar(0));
182 if (!builtinIsPinFree(transmitPin))
183 xsUnknownError("in use");
184 }
185
186 if (xsmcGet(xsVar(0), xsArg(0), xsID_receive)) {
187 receivePin = builtinGetPin(the, &xsVar(0));
188 if (!builtinIsPinFree(receivePin))
189 xsUnknownError("in use");
190 }
191 else if (kInvalidPin == transmitPin)
192 xsUnknownError("invalid"); // need at least one of tx or rx
193
194 if (xsmcGet(xsVar(0), xsArg(0), xsID_receivePullup))
195 receivePullup = xsmcToInteger(xsVar(0));
196
197 xsmcGet(xsVar(0), xsArg(0), xsID_baud);
198 baud = xsmcToInteger(xsVar(0));
199 transmitNotifyThreshold = (baud >> 3) * 0.0025;
200 switch (baud) {
201 case 1200:
202 baud = NRF_UARTE_BAUDRATE_1200;
203 break;
204 case 2400:
205 baud = NRF_UARTE_BAUDRATE_2400;
206 break;
207 case 4800:
208 baud = NRF_UARTE_BAUDRATE_4800;
209 break;
210 case 9600:
211 baud = NRF_UARTE_BAUDRATE_9600;
212 break;
213 case 14400:
214 baud = NRF_UARTE_BAUDRATE_14400;
215 break;
216 case 19200:
217 baud = NRF_UARTE_BAUDRATE_19200;
218 break;
219 case 28800:

Callers

nothing calls this directly

Calls 4

builtinGetCallbackFunction · 0.85
builtinInitializeTargetFunction · 0.85
builtinInitializeFormatFunction · 0.85
modMessagePostToMachineFunction · 0.50

Tested by

no test coverage detected