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

Function xs_onewire

modules/drivers/onewire/esp/modonewire.c:75–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73}
74
75void xs_onewire(xsMachine *the)
76{
77 modOneWire onewire;
78 int pin;
79
80 xsmcVars(1);
81
82 if (!xsmcHas(xsArg(0), xsID_pin))
83 xsUnknownError("pin missing");
84
85 onewire = c_malloc(sizeof(modOneWireRecord));
86 if (!onewire)
87 xsUnknownError("no memory");
88
89 xsmcGet(xsVar(0), xsArg(0), xsID_pin);
90 pin = xsmcToInteger(xsVar(0));
91
92 onewire->obj = xsThis;
93 onewire->pin = pin;
94
95 xsRemember(onewire->obj);
96
97#ifdef MODDEF_ONEWIRE_DRIVER_GPIO
98 onewire->owb = owb_gpio_initialize(&onewire->driver_info, onewire->pin);
99#endif
100#ifdef MODDEF_ONEWIRE_DRIVER_RMT
101 onewire->owb = owb_rmt_initialize(&onewire->driver_info, onewire->pin, MODDEF_ONEWIRE_RMT_TX_CHANNEL, MODDEF_ONEWIRE_RMT_RX_CHANNEL);
102#endif
103 if (onewire->owb == NULL)
104 {
105 xsUnknownError("can't init pin");
106 }
107 owb_use_crc(onewire->owb, true); // enable CRC check for ROM code
108
109 xsmcSetHostData(xsThis, onewire);
110}
111
112void xs_onewire_close(xsMachine *the)
113{

Callers

nothing calls this directly

Calls 3

owb_gpio_initializeFunction · 0.85
owb_rmt_initializeFunction · 0.85
owb_use_crcFunction · 0.85

Tested by

no test coverage detected