periph 1.3.1 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +18 -0
  2. package/examples/accelerometer/bma180/complete.js +83 -0
  3. package/examples/accelerometer/bma180/demo.js +47 -0
  4. package/examples/accelerometer/bma180/minimal.js +21 -0
  5. package/examples/accelerometer/fxos8700/complete.js +111 -0
  6. package/examples/accelerometer/fxos8700/demo.js +80 -0
  7. package/examples/accelerometer/fxos8700/minimal.js +20 -0
  8. package/examples/accelerometer/lis3dh/complete.js +123 -0
  9. package/examples/accelerometer/lis3dh/demo.js +99 -0
  10. package/examples/accelerometer/lis3dh/minimal.js +19 -0
  11. package/examples/accelerometer/lsm303/complete.js +82 -0
  12. package/examples/accelerometer/lsm303/demo.js +96 -0
  13. package/examples/accelerometer/lsm303/minimal.js +23 -0
  14. package/examples/accelerometer/mma8451q/complete.js +96 -0
  15. package/examples/accelerometer/mma8451q/demo.js +120 -0
  16. package/examples/accelerometer/mma8451q/minimal.js +20 -0
  17. package/examples/adc_dac/ad5243/complete.js +52 -0
  18. package/examples/adc_dac/ad5243/demo.js +50 -0
  19. package/examples/adc_dac/ad5243/minimal.js +23 -0
  20. package/examples/adc_dac/ad5248/complete.js +49 -0
  21. package/examples/adc_dac/ad5248/demo.js +42 -0
  22. package/examples/adc_dac/ad5248/minimal.js +21 -0
  23. package/examples/adc_dac/ads1013/complete.js +51 -0
  24. package/examples/adc_dac/ads1013/demo.js +51 -0
  25. package/examples/adc_dac/ads1013/minimal.js +21 -0
  26. package/examples/adc_dac/ads1014/complete.js +88 -0
  27. package/examples/adc_dac/ads1014/demo.js +52 -0
  28. package/examples/adc_dac/ads1014/minimal.js +21 -0
  29. package/examples/adc_dac/ads1113/complete.js +47 -0
  30. package/examples/adc_dac/ads1113/demo.js +39 -0
  31. package/examples/adc_dac/ads1113/minimal.js +20 -0
  32. package/examples/adc_dac/ads1114/complete.js +77 -0
  33. package/examples/adc_dac/ads1114/demo.js +47 -0
  34. package/examples/adc_dac/ads1114/minimal.js +20 -0
  35. package/examples/adc_dac/ads1115/complete.js +82 -0
  36. package/examples/adc_dac/ads1115/demo.js +55 -0
  37. package/examples/adc_dac/ads1115/minimal.js +20 -0
  38. package/examples/display/pcf8578/complete.js +58 -0
  39. package/examples/display/pcf8578/demo.js +62 -0
  40. package/examples/display/pcf8578/minimal.js +19 -0
  41. package/examples/display/pcf8579/complete.js +58 -0
  42. package/examples/display/pcf8579/demo.js +61 -0
  43. package/examples/display/pcf8579/minimal.js +19 -0
  44. package/examples/imu/icm20948/complete.js +114 -0
  45. package/examples/imu/icm20948/demo.js +79 -0
  46. package/examples/imu/icm20948/minimal.js +22 -0
  47. package/examples/io_expander/mcp23008/complete.js +70 -0
  48. package/examples/io_expander/mcp23008/demo.js +58 -0
  49. package/examples/io_expander/mcp23008/minimal.js +20 -0
  50. package/examples/memory/mb85rc/complete.js +40 -0
  51. package/examples/memory/mb85rc/demo.js +58 -0
  52. package/examples/memory/mb85rc/minimal.js +15 -0
  53. package/examples/motor/drv2605/complete.js +100 -0
  54. package/examples/motor/drv2605/demo.js +55 -0
  55. package/examples/motor/drv2605/minimal.js +24 -0
  56. package/package.json +1 -1
  57. package/src/chips/accelerometer/bma180.js +573 -0
  58. package/src/chips/accelerometer/fxos8700.js +1600 -0
  59. package/src/chips/accelerometer/lis3dh.js +1341 -0
  60. package/src/chips/accelerometer/lsm303.js +1471 -0
  61. package/src/chips/accelerometer/mma8451q.js +1406 -0
  62. package/src/chips/adc_dac/_ads111x_base.js +272 -0
  63. package/src/chips/adc_dac/ad5243.js +231 -0
  64. package/src/chips/adc_dac/ad5248.js +194 -0
  65. package/src/chips/adc_dac/ads1013.js +219 -0
  66. package/src/chips/adc_dac/ads1014.js +509 -0
  67. package/src/chips/adc_dac/ads1113.js +112 -0
  68. package/src/chips/adc_dac/ads1114.js +201 -0
  69. package/src/chips/adc_dac/ads1115.js +232 -0
  70. package/src/chips/display/pcf8578.js +452 -0
  71. package/src/chips/display/pcf8579.js +451 -0
  72. package/src/chips/imu/icm20948.js +849 -0
  73. package/src/chips/io_expander/mcp23008.js +558 -0
  74. package/src/chips/memory/mb85rc.js +166 -0
  75. package/src/chips/motor/drv2605.js +592 -0
  76. package/src/discovery/registry.js +20 -19
@@ -0,0 +1,451 @@
1
+ 'use strict';
2
+
3
+ const _ADDR_SA0_LOW = 0x3C;
4
+ const _ADDR_SA0_HIGH = 0x3D;
5
+
6
+ const _CMD_SET_MODE = 0x40;
7
+ const _CMD_DEVICE_SELECT = 0x60;
8
+ const _CMD_RAM_ACCESS = 0x70;
9
+ const _CMD_SET_START_BANK = 0x7C;
10
+ const _CONT = 0x80;
11
+
12
+ const STATUS_BLANK = 0;
13
+ const STATUS_NORMAL = 1;
14
+ const STATUS_ALL_ON = 2;
15
+ const STATUS_INVERSE = 3;
16
+
17
+ const ACCESS_CHARACTER = 0;
18
+ const ACCESS_HALF_GRAPHIC = 1;
19
+ const ACCESS_FULL_GRAPHIC = 2;
20
+
21
+ const RAM_COLUMNS = 40;
22
+ const RAM_BANKS = 4;
23
+
24
+ // multiplex rate (rows) -> M[1:0]
25
+ const _MUX_CODE = { 8: 1, 16: 2, 24: 3, 32: 0 };
26
+ const _PER_COL = [1, 2, 4];
27
+
28
+ /**
29
+ * PCF8579 LCD column driver — minimal interface.
30
+ *
31
+ * The PCF8579 is the column-driver companion of the PCF8578 and cannot run alone: the clock,
32
+ * frame sync and row waveforms come from a PCF8578 (or an equivalent source). This driver
33
+ * writes the display RAM of one PCF8579 (4 banks x 40 columns, X = n drives output Cn). The
34
+ * chip has no register map; this driver streams command bytes and display data with the plain
35
+ * connection `write` / `writeRead` calls. The I2C address is 0x3C (SA0 = VSS) or 0x3D
36
+ * (SA0 = VDD); the chip supports 100 kHz at most.
37
+ *
38
+ * The constructor starts the initialisation (waits for the internal reset, clears this device's
39
+ * RAM, then switches the display on in normal video with start bank 0); every method waits for
40
+ * it and `ready()` resolves (or rejects) when it is done. If the subaddress pins A3:A0 do not
41
+ * match `subaddress`, the data bytes are not acknowledged and `ready()` rejects. A shadow copy
42
+ * of the 4 x 40 byte RAM is kept so single-pixel updates need only one byte on the bus. One RAM
43
+ * byte is 8 vertical pixels of one column; bit 0 is the top row of the bank.
44
+ *
45
+ * device-select, set-mode and set-start-bank reach every device on the I2C address, so all
46
+ * drivers on one bus must use the same `rows` / `mixed` settings.
47
+ *
48
+ * @param {import('../../connection/connection').Connection} connection - Configured I2C
49
+ * connection pointing at the device (100 kHz maximum).
50
+ * @param {number} [subaddress=0] - Hardware subaddress set on pins A3:A0, 0 .. 15.
51
+ * @param {number} [rows=16] - Number of display rows: 8, 16, 24 or 32.
52
+ * @param {boolean} [mixed=false] - true if the PCF8578 in the system runs in mixed mode (T bit).
53
+ */
54
+ class PCF8579Minimal {
55
+ constructor(connection, subaddress = 0, rows = 16, mixed = false) {
56
+ if (!(rows in _MUX_CODE)) {
57
+ throw new RangeError('rows must be 8, 16, 24 or 32');
58
+ }
59
+ if (subaddress < 0 || subaddress > 15) {
60
+ throw new RangeError('subaddress must be in 0..15');
61
+ }
62
+ this._conn = connection;
63
+ this._subaddress = subaddress;
64
+ this._rows = rows;
65
+ this._mixed = !!mixed;
66
+ this._status = STATUS_NORMAL;
67
+ this._startBank = 0;
68
+ this._shadow = [];
69
+ for (let b = 0; b < RAM_BANKS; b++) this._shadow.push(new Uint8Array(RAM_COLUMNS));
70
+ this._ready = this._init();
71
+ this._ready.catch(() => {}); // surfaced through ready() and the first awaited call
72
+ }
73
+
74
+ /**
75
+ * Resolves when the initialisation sequence is finished (rejects if it failed).
76
+ * @returns {Promise<void>}
77
+ */
78
+ ready() { return this._ready; }
79
+
80
+ _modeByte(status, cont) {
81
+ return (cont ? _CONT : 0) | _CMD_SET_MODE | ((this._mixed ? 1 : 0) << 4)
82
+ | (status << 2) | _MUX_CODE[this._rows];
83
+ }
84
+
85
+ _ramAccessByte(access, bank, cont = true) {
86
+ return (cont ? _CONT : 0) | _CMD_RAM_ACCESS | (access << 2) | bank;
87
+ }
88
+
89
+ _selectByte() {
90
+ return _CONT | _CMD_DEVICE_SELECT | this._subaddress;
91
+ }
92
+
93
+ _zeroShadow() {
94
+ for (const bank of this._shadow) bank.fill(0);
95
+ }
96
+
97
+ async _init() {
98
+ await new Promise((resolve) => setTimeout(resolve, 2)); // >= 1 ms internal power-on reset
99
+ this._startBank = 0;
100
+ const out = [
101
+ this._selectByte(), // device-select
102
+ this._modeByte(STATUS_BLANK, true), // blank
103
+ _CONT | _CMD_SET_START_BANK, // start bank 0
104
+ this._ramAccessByte(ACCESS_FULL_GRAPHIC, 0), // full-graphic, bank 0
105
+ 0x00, // load-X 0 (C = 0)
106
+ ...new Array(RAM_COLUMNS * RAM_BANKS).fill(0),
107
+ ];
108
+ await this._conn.write(Buffer.from(out));
109
+ this._zeroShadow();
110
+ this._status = STATUS_NORMAL;
111
+ await this._conn.write(Buffer.from([this._modeByte(STATUS_NORMAL, false)]));
112
+ }
113
+
114
+ // Write data at RAM column x / bank and mirror it in the shadow.
115
+ async _ramWrite(x, bank, data, access = ACCESS_CHARACTER) {
116
+ const out = [
117
+ this._selectByte(),
118
+ this._ramAccessByte(access, bank),
119
+ x & 0x3F,
120
+ ...data,
121
+ ];
122
+ await this._conn.write(Buffer.from(out));
123
+ const perCol = _PER_COL[access];
124
+ for (let i = 0; i < data.length; i++) {
125
+ const col = x + Math.floor(i / perCol);
126
+ if (col < RAM_COLUMNS) this._shadow[bank + (i % perCol)][col] = data[i];
127
+ }
128
+ }
129
+
130
+ /**
131
+ * Zero this device's whole display RAM (4 banks x 40 columns) and the shadow.
132
+ * @returns {Promise<void>}
133
+ */
134
+ async clear() {
135
+ await this._ready;
136
+ const out = [
137
+ this._selectByte(),
138
+ this._ramAccessByte(ACCESS_FULL_GRAPHIC, 0),
139
+ 0x00,
140
+ ...new Array(RAM_COLUMNS * RAM_BANKS).fill(0),
141
+ ];
142
+ await this._conn.write(Buffer.from(out));
143
+ this._zeroShadow();
144
+ }
145
+
146
+ /**
147
+ * Set or clear one pixel. Out-of-range coordinates are ignored. Writes exactly one RAM byte.
148
+ *
149
+ * @param {number} x - Column, 0 .. 39.
150
+ * @param {number} y - Row, 0 .. rows - 1.
151
+ * @param {boolean} [on=true] - true lights the pixel, false clears it.
152
+ * @returns {Promise<void>}
153
+ */
154
+ async setPixel(x, y, on = true) {
155
+ await this._ready;
156
+ if (x < 0 || x >= RAM_COLUMNS || y < 0 || y >= this._rows) return;
157
+ const bank = y >> 3;
158
+ const bit = 1 << (y & 7);
159
+ const value = on ? (this._shadow[bank][x] | bit) : (this._shadow[bank][x] & ~bit & 0xFF);
160
+ await this._ramWrite(x, bank, [value]);
161
+ }
162
+
163
+ /**
164
+ * Write consecutive column bytes in character access mode.
165
+ *
166
+ * @param {number} x - First column, 0 .. 39.
167
+ * @param {number} bank - Bank (8-row band), 0 .. rows/8 - 1.
168
+ * @param {number[]|Buffer} data - Column bytes; bit 0 is the top row of the bank. The write
169
+ * is truncated at column 39.
170
+ * @returns {Promise<void>}
171
+ */
172
+ async writeColumns(x, bank, data) {
173
+ await this._ready;
174
+ if (bank < 0 || bank >= (this._rows >> 3)) {
175
+ throw new RangeError('bank out of range for the configured rows');
176
+ }
177
+ if (x < 0 || x >= RAM_COLUMNS) return;
178
+ const bytes = Array.from(data).slice(0, RAM_COLUMNS - x);
179
+ if (bytes.length === 0) return;
180
+ await this._ramWrite(x, bank, bytes);
181
+ }
182
+ }
183
+
184
+ /**
185
+ * PCF8579 full interface — extends PCF8579Minimal.
186
+ *
187
+ * Adds pixel read-back from the shadow, fill, line/rectangle/bitmap drawing, display status
188
+ * (blank / normal / all-on / inverse), multiplex rate and PCF8578 mode bit, hardware vertical
189
+ * scrolling via the start bank, and raw RAM write/read in all three access modes including
190
+ * transfers that run on into the following cascaded devices.
191
+ *
192
+ * @param {import('../../connection/connection').Connection} connection - Configured I2C
193
+ * connection pointing at the device (100 kHz maximum).
194
+ * @param {number} [subaddress=0] - Hardware subaddress set on pins A3:A0, 0 .. 15.
195
+ * @param {number} [rows=16] - Number of display rows: 8, 16, 24 or 32.
196
+ * @param {boolean} [mixed=false] - true if the PCF8578 in the system runs in mixed mode.
197
+ */
198
+ class PCF8579Full extends PCF8579Minimal {
199
+ _plot(x, y, on, dirty) {
200
+ if (x < 0 || x >= RAM_COLUMNS || y < 0 || y >= this._rows) return;
201
+ const bank = y >> 3;
202
+ const bit = 1 << (y & 7);
203
+ this._shadow[bank][x] = on ? (this._shadow[bank][x] | bit) : (this._shadow[bank][x] & ~bit & 0xFF);
204
+ dirty.add(bank * RAM_COLUMNS + x);
205
+ }
206
+
207
+ // One transaction per run of consecutive changed columns in a bank.
208
+ async _flush(dirty) {
209
+ const items = Array.from(dirty).sort((a, b) => a - b);
210
+ let i = 0;
211
+ while (i < items.length) {
212
+ const bank = Math.floor(items[i] / RAM_COLUMNS);
213
+ const start = items[i] % RAM_COLUMNS;
214
+ let end = start;
215
+ while (i + 1 < items.length && items[i + 1] === items[i] + 1
216
+ && Math.floor(items[i + 1] / RAM_COLUMNS) === bank) {
217
+ i++;
218
+ end++;
219
+ }
220
+ await this._ramWrite(start, bank, Array.from(this._shadow[bank].slice(start, end + 1)));
221
+ i++;
222
+ }
223
+ }
224
+
225
+ /**
226
+ * Return the state of one pixel from the shadow (no bus traffic).
227
+ *
228
+ * @param {number} x - Display column.
229
+ * @param {number} y - Display row.
230
+ * @returns {Promise<boolean>} true if the pixel is set; false if clear or out of range.
231
+ */
232
+ async getPixel(x, y) {
233
+ await this._ready;
234
+ if (x < 0 || x >= RAM_COLUMNS || y < 0 || y >= this._rows) return false;
235
+ return (this._shadow[y >> 3][x] & (1 << (y & 7))) !== 0;
236
+ }
237
+
238
+ /**
239
+ * Set every displayed pixel (rows x 40) on or off.
240
+ * @param {boolean} [on=true] - true lights all pixels, false clears them.
241
+ * @returns {Promise<void>}
242
+ */
243
+ async fill(on = true) {
244
+ await this._ready;
245
+ for (let bank = 0; bank < (this._rows >> 3); bank++) {
246
+ await this._ramWrite(0, bank, new Array(RAM_COLUMNS).fill(on ? 0xFF : 0x00));
247
+ }
248
+ }
249
+
250
+ /**
251
+ * Draw a Bresenham line, written as one batch of changed bytes.
252
+ *
253
+ * @param {number} x0 - Start column.
254
+ * @param {number} y0 - Start row.
255
+ * @param {number} x1 - End column.
256
+ * @param {number} y1 - End row.
257
+ * @param {boolean} [on=true] - true draws, false erases.
258
+ * @returns {Promise<void>}
259
+ */
260
+ async drawLine(x0, y0, x1, y1, on = true) {
261
+ await this._ready;
262
+ const dirty = new Set();
263
+ const dx = Math.abs(x1 - x0);
264
+ const dy = -Math.abs(y1 - y0);
265
+ const sx = x0 < x1 ? 1 : -1;
266
+ const sy = y0 < y1 ? 1 : -1;
267
+ let err = dx + dy;
268
+ for (;;) {
269
+ this._plot(x0, y0, on, dirty);
270
+ if (x0 === x1 && y0 === y1) break;
271
+ const e2 = 2 * err;
272
+ if (e2 >= dy) { err += dy; x0 += sx; }
273
+ if (e2 <= dx) { err += dx; y0 += sy; }
274
+ }
275
+ await this._flush(dirty);
276
+ }
277
+
278
+ /**
279
+ * Draw a rectangle outline or a filled rectangle.
280
+ *
281
+ * @param {number} x - Left column.
282
+ * @param {number} y - Top row.
283
+ * @param {number} w - Width in pixels.
284
+ * @param {number} h - Height in pixels.
285
+ * @param {boolean} [on=true] - true draws, false erases.
286
+ * @param {boolean} [fill=false] - true fills the interior.
287
+ * @returns {Promise<void>}
288
+ */
289
+ async drawRect(x, y, w, h, on = true, fill = false) {
290
+ await this._ready;
291
+ if (w <= 0 || h <= 0) return;
292
+ const dirty = new Set();
293
+ for (let yy = y; yy < y + h; yy++) {
294
+ for (let xx = x; xx < x + w; xx++) {
295
+ if (fill || yy === y || yy === y + h - 1 || xx === x || xx === x + w - 1) {
296
+ this._plot(xx, yy, on, dirty);
297
+ }
298
+ }
299
+ }
300
+ await this._flush(dirty);
301
+ }
302
+
303
+ /**
304
+ * Blit 8-pixel-high column bytes aligned to a bank boundary.
305
+ *
306
+ * @param {number} x - Left column.
307
+ * @param {number} y - Top row; must be a non-negative multiple of 8.
308
+ * @param {number[]|Buffer} columns - One byte per column (bit 0 = top row); clipped at
309
+ * column 39.
310
+ * @returns {Promise<void>}
311
+ */
312
+ async showBitmap(x, y, columns) {
313
+ if (y % 8 !== 0 || y < 0) {
314
+ throw new RangeError('y must be a non-negative multiple of 8');
315
+ }
316
+ await this.writeColumns(x, y >> 3, columns);
317
+ }
318
+
319
+ /**
320
+ * Set the display status; RAM contents are preserved. Affects all devices on the address.
321
+ * @param {number} status - PCF8579Full.DISPLAY_BLANK / _NORMAL / _ALL_ON / _INVERSE.
322
+ * @returns {Promise<void>}
323
+ */
324
+ async setDisplay(status) {
325
+ await this._ready;
326
+ if (status < 0 || status > 3) throw new RangeError('status must be in 0..3');
327
+ this._status = status;
328
+ await this._conn.write(Buffer.from([this._modeByte(status, false)]));
329
+ }
330
+
331
+ /**
332
+ * Change the multiplex rate and the PCF8578 mode bit T (affects all devices).
333
+ *
334
+ * @param {number} rows - 8, 16, 24 or 32.
335
+ * @param {boolean} [mixed=false] - true if the PCF8578 runs in mixed mode.
336
+ * @returns {Promise<void>}
337
+ */
338
+ async setMode(rows, mixed = false) {
339
+ await this._ready;
340
+ if (!(rows in _MUX_CODE)) throw new RangeError('rows must be 8, 16, 24 or 32');
341
+ this._rows = rows;
342
+ this._mixed = !!mixed;
343
+ await this._conn.write(Buffer.from([this._modeByte(this._status, false)]));
344
+ }
345
+
346
+ /**
347
+ * Select the RAM bank shown at the top of the display (vertical scroll, all devices).
348
+ * @param {number} bank - 0 .. 3.
349
+ * @returns {Promise<void>}
350
+ */
351
+ async setStartBank(bank) {
352
+ await this._ready;
353
+ if (bank < 0 || bank > 3) throw new RangeError('bank must be in 0..3');
354
+ this._startBank = bank;
355
+ await this._conn.write(Buffer.from([_CMD_SET_START_BANK | bank]));
356
+ }
357
+
358
+ /**
359
+ * Add `banks` (may be negative) to the start bank, modulo the banks in use.
360
+ * @param {number} banks - Number of 8-row steps.
361
+ * @returns {Promise<void>}
362
+ */
363
+ async scroll(banks) {
364
+ await this._ready;
365
+ const n = this._rows >> 3;
366
+ await this.setStartBank((((this._startBank + banks) % n) + n) % n);
367
+ }
368
+
369
+ _checkRamArgs(x, bank, count, access, cascade = false) {
370
+ if (access < 0 || access > 2) throw new RangeError('access must be in 0..2');
371
+ if (x < 0 || x > 39 || bank < 0 || bank > 3) throw new RangeError('x must be in 0..39 and bank in 0..3');
372
+ if (access === 1 && bank % 2) throw new RangeError('half-graphic access must start at an even bank');
373
+ if (access === 2 && bank !== 0) throw new RangeError('full-graphic access must start at bank 0');
374
+ if (!cascade && x + Math.ceil(count / _PER_COL[access]) > 40) throw new RangeError('write would pass column 39');
375
+ }
376
+
377
+ /**
378
+ * Raw RAM write of this device in character, half-graphic or full-graphic order.
379
+ *
380
+ * @param {number} x - RAM column, 0 .. 39.
381
+ * @param {number} bank - RAM bank, 0 .. 3 (even for half-graphic, 0 for full-graphic).
382
+ * @param {number[]|Buffer} data - Bytes to write; must not pass column 39.
383
+ * @param {number} [mode=0] - ACCESS_CHARACTER, ACCESS_HALF_GRAPHIC or ACCESS_FULL_GRAPHIC.
384
+ * @returns {Promise<void>}
385
+ */
386
+ async writeRam(x, bank, data, mode = ACCESS_CHARACTER) {
387
+ await this._ready;
388
+ const bytes = Array.from(data);
389
+ this._checkRamArgs(x, bank, bytes.length, mode);
390
+ if (bytes.length === 0) return;
391
+ await this._ramWrite(x, bank, bytes, mode);
392
+ }
393
+
394
+ /**
395
+ * Write from column 0, bank 0 of this device and run on into the following subaddresses (the
396
+ * chip advances its subaddress counter after column 39). The shadow only tracks this
397
+ * device's first 40 columns.
398
+ *
399
+ * @param {number[]|Buffer} data - Bytes to write.
400
+ * @param {number} [mode=2] - ACCESS_CHARACTER, ACCESS_HALF_GRAPHIC or ACCESS_FULL_GRAPHIC.
401
+ * @returns {Promise<void>}
402
+ */
403
+ async writeRamCascade(data, mode = ACCESS_FULL_GRAPHIC) {
404
+ await this._ready;
405
+ const bytes = Array.from(data);
406
+ this._checkRamArgs(0, 0, bytes.length, mode, true);
407
+ if (bytes.length === 0) return;
408
+ await this._ramWrite(0, 0, bytes, mode);
409
+ }
410
+
411
+ /**
412
+ * Raw RAM read: address-set commands, repeated start, then `n` bytes.
413
+ *
414
+ * @param {number} x - RAM column, 0 .. 39.
415
+ * @param {number} bank - RAM bank, 0 .. 3.
416
+ * @param {number} n - Number of bytes to read.
417
+ * @param {number} [mode=0] - Access mode as for writeRam.
418
+ * @returns {Promise<Buffer>} The bytes read.
419
+ */
420
+ async readRam(x, bank, n, mode = ACCESS_CHARACTER) {
421
+ await this._ready;
422
+ this._checkRamArgs(x, bank, n, mode);
423
+ const cmds = Buffer.from([
424
+ this._selectByte(),
425
+ this._ramAccessByte(mode, bank),
426
+ x & 0x3F,
427
+ ]);
428
+ return this._conn.writeRead(cmds, n);
429
+ }
430
+
431
+ /**
432
+ * Re-run initialisation (clears this device's RAM, normal video, start bank 0).
433
+ * @returns {Promise<void>}
434
+ */
435
+ async reset() {
436
+ await this._ready;
437
+ this._ready = this._init();
438
+ this._ready.catch(() => {});
439
+ await this._ready;
440
+ }
441
+ }
442
+
443
+ PCF8579Full.DISPLAY_BLANK = STATUS_BLANK;
444
+ PCF8579Full.DISPLAY_NORMAL = STATUS_NORMAL;
445
+ PCF8579Full.DISPLAY_ALL_ON = STATUS_ALL_ON;
446
+ PCF8579Full.DISPLAY_INVERSE = STATUS_INVERSE;
447
+ PCF8579Full.ACCESS_CHARACTER = ACCESS_CHARACTER;
448
+ PCF8579Full.ACCESS_HALF_GRAPHIC = ACCESS_HALF_GRAPHIC;
449
+ PCF8579Full.ACCESS_FULL_GRAPHIC = ACCESS_FULL_GRAPHIC;
450
+
451
+ module.exports = { PCF8579Minimal, PCF8579Full };