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

Function xs_FT6202

modules/drivers/ft6206/modFt6206.c:111–166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109}
110
111void xs_FT6202(xsMachine *the)
112{
113 ft6206 ft;
114 uint8_t data[2];
115 uint8_t err;
116
117 ft = c_calloc(1, sizeof(ft6206Record));
118 if (!ft) xsUnknownError("out of memory");
119 xsmcSetHostData(xsThis, ft);
120
121 xsmcVars(1);
122
123 modI2CConfig(ft->i2c, MODDEF_FT6206_HZ, MODDEF_FT6206_SDA, MODDEF_FT6206_SCL, MODDEF_FT6206_ADDR, 250);
124 modI2CInit(&ft->i2c);
125
126 data[0] = FT6206_REG_VENDID;
127 err = modI2CWrite(&ft->i2c, data, 1, false);
128 if (err) xsUnknownError("write FT6206_REG_VENDID failed");
129 err = modI2CRead(&ft->i2c, data, 1, true);
130 if (err) xsUnknownError("read FT6206_REG_VENDID failed");
131 if ((0 != data[0]) && (1 != data[0]) && (2 != data[0]) && (17 != data[0]) && (32 != data[0])) xsUnknownError("bad FT6206_REG_VENDID");
132
133 data[0] = FT6206_REG_CHIPID;
134 err = modI2CWrite(&ft->i2c, data, 1, false);
135 if (err) xsUnknownError("write FT6206_REG_CHIPID failed");
136 err = modI2CRead(&ft->i2c, data, 1, true);
137 if (err) xsUnknownError("read FT6206_REG_CHIPID failed");
138 if ((6 != data[0]) && (100 != data[0])) xsUnknownError("bad FT6206_REG_CHIPID");
139
140 data[0] = FT6206_REG_THRESHHOLD;
141 data[1] = MODDEF_FT6206_THRESHOLD;
142 err = modI2CWrite(&ft->i2c, data, 2, true);
143 if (err) xsUnknownError("write failed setting threshold");
144
145 data[0] = FT6206_REG_CTRL;
146 data[1] = 1; // switch to monitor mode when no touch
147 err = modI2CWrite(&ft->i2c, data, 2, true);
148 if (err) xsUnknownError("write failed setting ctrl");
149
150#if MODDEF_FT6206_CALIBRATE
151 ft->min_x = MODDEF_FT6206_RAW_LEFT;
152 ft->max_x = MODDEF_FT6206_RAW_RIGHT;
153 ft->min_y = MODDEF_FT6206_RAW_TOP;
154 ft->max_y = MODDEF_FT6206_RAW_BOTTOM;
155
156 uint8_t prefType;
157 int16_t values[4];
158 uint16_t byteCountOut;
159 if (modPreferenceGet("ft6206", "calibrate", &prefType, (uint8_t *)values, sizeof(values), &byteCountOut)) {
160 ft->min_x = values[0];
161 ft->max_x = values[1];
162 ft->min_y = values[2];
163 ft->max_y = values[3];
164 }
165#endif
166}
167
168void xs_FT6202_read(xsMachine *the)

Callers

nothing calls this directly

Calls 4

modI2CInitFunction · 0.50
modI2CWriteFunction · 0.50
modI2CReadFunction · 0.50
modPreferenceGetFunction · 0.50

Tested by

no test coverage detected