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

Function xs_spi_constructor

modules/io/spi/pico/spi.c:79–178  ·  view source on GitHub ↗

@@ pin values for in, out, and clock not being used or verified

Source from the content-addressed store, hash-verified

77
78//@@ pin values for in, out, and clock not being used or verified
79void xs_spi_constructor(xsMachine *the)
80{
81 SPI spi;
82 uint8_t mosi = kInvalidPin, miso = kInvalidPin, clock, select = kInvalidPin, active = 1, mode = 0;
83 int hz, tmp;
84 uint8_t spiPort;
85
86 xsmcVars(1);
87
88 xsmcGet(xsVar(0), xsArg(0), xsID_clock);
89 clock = builtinGetPin(the, &xsVar(0));
90 if (!builtinIsPinFree(clock))
91 xsUnknownError("in use");
92
93 xsmcGet(xsVar(0), xsArg(0), xsID_hz);
94 hz = xsmcToInteger(xsVar(0));
95 if ((hz < 1) || (hz > 50000000))
96 xsRangeError("invalid hz");
97
98 if (xsmcGet(xsVar(0), xsArg(0), xsID_out)) {
99 mosi = builtinGetPin(the, &xsVar(0));
100 if (!builtinIsPinFree(mosi))
101 xsUnknownError("in use");
102 }
103
104 if (xsmcGet(xsVar(0), xsArg(0), xsID_in)) {
105 miso = builtinGetPin(the, &xsVar(0));
106 if (!builtinIsPinFree(miso))
107 xsUnknownError("in use");
108 }
109
110 if (xsmcGet(xsVar(0), xsArg(0), xsID_select)) {
111 select = builtinGetPin(the, &xsVar(0));
112 if (!builtinIsPinFree(select))
113 xsUnknownError("in use");
114 }
115
116 if (xsmcGet(xsVar(0), xsArg(0), xsID_active)) {
117 active = xsmcToInteger(xsVar(0));
118 if ((0 != active) && (1 != active))
119 xsRangeError("invalid active");
120 }
121
122 if (xsmcGet(xsVar(0), xsArg(0), xsID_mode)) {
123 tmp = xsmcToInteger(xsVar(0));
124 if (tmp & ~3)
125 xsRangeError("invalid mode");
126 mode = (uint8_t)tmp;
127 }
128
129 if ((kInvalidPin == mosi) && (kInvalidPin == miso))
130 xsUnknownError("mosi or miso required");
131
132// xsmcGet(xsVar(0), xsArg(0), xsID_port);
133// tmp = xsmcToInteger(xsVar(0));
134 tmp = spiPortForPin(mosi, miso);
135 if (tmp < 0 || tmp > 2)
136 xsRangeError("invalid port");

Callers

nothing calls this directly

Calls 5

spiPortForPinFunction · 0.85
builtinInitializeTargetFunction · 0.85
builtinInitializeFormatFunction · 0.85
modSPIInitFunction · 0.50
modGPIOInitFunction · 0.50

Tested by

no test coverage detected