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

Function xs_arducam

modules/drivers/arducam/modArducam.c:125–232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123}
124
125void xs_arducam(xsMachine *the)
126{
127 ArduCAM ac;
128 int width, height;
129 char *format;
130 uint8_t value;
131
132 ac = calloc(1, sizeof(ArduCAMRecord));
133 if (!ac)
134 xsUnknownError("no memory");
135 xsmcSetHostData(xsThis, ac);
136
137 ac->spiConfig.hz = MODDEF_ARDUCAM_HZ;
138 ac->spiConfig.doChipSelect = arducamChipSelect;
139
140 /*
141 I2C set-up first
142 */
143
144 ac->i2cConfig.sda = MODDEF_ARDUCAM_I2C_SDA;
145 ac->i2cConfig.scl = MODDEF_ARDUCAM_I2C_SCL;
146 ac->i2cConfig.address = 0x30; // OV2640 (ArcuCAM sources use 0x60 and then shift down by 1)
147 modI2CInit(&ac->i2cConfig);
148
149 writeRegisterI2C_8(ac, 0xff, 0x01);
150
151 value = 0x0A;
152 modI2CWrite(&ac->i2cConfig, &value, 1, true);
153 modI2CRead(&ac->i2cConfig, &value, 1, true);
154 if (0x26 != value)
155 xsUnknownError("bad id high");
156
157 value = 0x0B;
158 modI2CWrite(&ac->i2cConfig, &value, 1, true);
159 modI2CRead(&ac->i2cConfig, &value, 1, true);
160 if ((0x41 != value ) && (0x42 != value))
161 xsUnknownError("bad id low");
162
163 writeRegisterI2C_8(ac, 0x12, 0x80);
164 modDelayMilliseconds(100);
165
166 xsmcVars(1);
167 xsmcGet(xsVar(0), xsArg(0), xsID_width);
168 width = xsmcToInteger(xsVar(0));
169 xsmcGet(xsVar(0), xsArg(0), xsID_height);
170 height = xsmcToInteger(xsVar(0));
171 xsmcGet(xsVar(0), xsArg(0), xsID_format);
172 format = xsmcToString(xsVar(0));
173
174 if (0 == c_strcmp(format, "rgb565be")) {
175 if ((320 != width) || (240 != height))
176 xsUnknownError("unsupported dimensions");
177
178 writeRegistersI2C_8(ac, OV2640_QVGA);
179 }
180 else if (0 == c_strcmp(format, "rgb565le")) {
181 if ((320 != width) || (240 != height))
182 xsUnknownError("unsupported dimensions");

Callers

nothing calls this directly

Calls 10

writeRegisterI2C_8Function · 0.85
writeRegistersI2C_8Function · 0.85
arducamChipSelectFunction · 0.85
writeRegisterSPI_8Function · 0.85
readRegisterSPI_8Function · 0.85
modI2CInitFunction · 0.50
modI2CWriteFunction · 0.50
modI2CReadFunction · 0.50
modGPIOInitFunction · 0.50
modSPIInitFunction · 0.50

Tested by

no test coverage detected