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

Function xs_SSD1306

modules/drivers/ssd1306/modSsd1306.c:196–341  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194}
195
196void xs_SSD1306(xsMachine *the)
197{
198 int width, height, pixelFormat;
199 int address;
200 ssd1606 ssd;
201
202 xsmcVars(1);
203#if MODDEF_SSD1306_WIDTH
204 width = MODDEF_SSD1306_WIDTH;
205#else
206 xsmcGet(xsVar(0), xsArg(0), xsID_width);
207 width = xsmcToInteger(xsVar(0));
208#endif
209
210#if MODDEF_SSD1306_HEIGHT
211 height = MODDEF_SSD1306_HEIGHT;
212#else
213 xsmcGet(xsVar(0), xsArg(0), xsID_height);
214 height = xsmcToInteger(xsVar(0));
215#endif
216
217 if (xsmcHas(xsArg(0), xsID_pixelFormat)) {
218 xsmcGet(xsVar(0), xsArg(0), xsID_pixelFormat);
219 pixelFormat = xsmcToInteger(xsVar(0));
220 }
221 else
222 pixelFormat = kCommodettoBitmapFormat;
223 if (kCommodettoBitmapGray256 != pixelFormat)
224 xsUnknownError("gray256 pixels required");
225
226 ssd = c_calloc(1, sizeof(ssd1606Record));
227 if (!ssd)
228 xsUnknownError("out of memory");
229
230 xsmcSetHostData(xsThis, ssd);
231
232 ssd->dispatch = (PixelsOutDispatch)&gPixelsOutDispatch;
233 ssd->the = the;
234
235 ssd->width = (uint8_t)width;
236 ssd->height = (uint8_t)height;
237
238#ifdef MODDEF_SSD1306_RST_PIN
239 SCREEN_RST_INIT;
240 // modDelayMilliseconds(10);
241 SCREEN_RST_DEACTIVE;
242 modDelayMilliseconds(1);
243 SCREEN_RST_ACTIVE;
244 modDelayMilliseconds(10);
245 SCREEN_RST_DEACTIVE;
246#endif
247
248#if MODDEF_SSD1306_SPI
249 SCREEN_CS_INIT;
250 SCREEN_DC_INIT;
251
252 ssd->config.spi.hz = MODDEF_SSD1306_HZ;
253 ssd->config.spi.doChipSelect = ssd1306ChipSelect;

Callers

nothing calls this directly

Calls 3

doCmdFunction · 0.70
modSPIInitFunction · 0.50
modI2CInitFunction · 0.50

Tested by

no test coverage detected