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

Function xs_digital

modules/pins/digital/digital.c:47–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45}
46
47void xs_digital(xsMachine *the)
48{
49 int pin, mode, argc = xsmcArgc;
50 char *port = NULL;
51 modGPIOConfigurationRecord gpio;
52 int woke;
53
54 if (1 == argc) { //@@ eventually only dictionary case should be here
55 xsmcVars(1);
56
57 if (!xsmcHas(xsArg(0), xsID_pin))
58 xsUnknownError("pin missing");
59
60 if (!xsmcHas(xsArg(0), xsID_mode))
61 xsUnknownError("mode missing");
62
63 xsmcGet(xsVar(0), xsArg(0), xsID_pin);
64 pin = xsmcToInteger(xsVar(0));
65
66 xsmcGet(xsVar(0), xsArg(0), xsID_mode);
67 mode = xsmcToInteger(xsVar(0));
68
69 if (xsmcHas(xsArg(0), xsID_port)) {
70 xsmcGet(xsVar(0), xsArg(0), xsID_port);
71 port = xsmcToString(xsVar(0));
72 }
73
74 if (xsmcHas(xsArg(0), xsID_wakeEdge)) {
75 xsmcGet(xsVar(0), xsArg(0), xsID_wakeEdge);
76 mode |= xsmcToInteger(xsVar(0));
77 }
78 }
79 else if (2 == argc) {
80 pin = xsmcToInteger(xsArg(0));
81 mode = xsmcToInteger(xsArg(1));
82 }
83 else if (3 == argc) {
84 pin = xsmcToInteger(xsArg(1));
85 mode = xsmcToInteger(xsArg(2));
86 if (xsmcTest(xsArg(0)))
87 port = xsmcToString(xsArg(0));
88 }
89
90 woke = modGPIODidWake(NULL, pin);
91
92 if (modGPIOInit(&gpio, port, (uint8_t)pin, mode))
93 xsUnknownError("can't init pin");
94
95 xsmcSetHostChunk(xsThis, &gpio, sizeof(gpio));
96
97 if (xsmcHas(xsArg(0), xsID_onWake)) {
98 if (woke) {
99 modDigitalWakeConfigurationRecord wake;
100 wake.obj = xsThis;
101 if (xsmcHas(xsArg(0), xsID_target)) {
102 xsmcGet(xsVar(0), xsArg(0), xsID_target);
103 xsmcSet(xsThis, xsID_target, xsVar(0));
104 }

Callers

nothing calls this directly

Calls 3

modGPIODidWakeFunction · 0.85
modGPIOInitFunction · 0.50
modMessagePostToMachineFunction · 0.50

Tested by

no test coverage detected