periph 1.2.0 → 1.3.0

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 (153) hide show
  1. package/README.md +18 -0
  2. package/examples/accelerometer/bma150/complete.js +62 -0
  3. package/examples/accelerometer/bma150/demo.js +65 -0
  4. package/examples/accelerometer/bma150/minimal.js +18 -0
  5. package/examples/adc_dac/hy3131/complete.js +66 -0
  6. package/examples/adc_dac/hy3131/demo.js +37 -0
  7. package/examples/adc_dac/hy3131/minimal.js +18 -0
  8. package/examples/discovery/complete.js +25 -0
  9. package/examples/discovery/demo.js +30 -0
  10. package/examples/discovery/minimal.js +12 -0
  11. package/examples/display/il0373/complete.js +71 -0
  12. package/examples/display/il0373/demo.js +49 -0
  13. package/examples/display/il0373/minimal.js +26 -0
  14. package/examples/display/ssd1331/complete.js +83 -0
  15. package/examples/display/ssd1331/demo.js +49 -0
  16. package/examples/display/ssd1331/minimal.js +27 -0
  17. package/examples/display/st7036/complete.js +71 -0
  18. package/examples/display/st7036/demo.js +56 -0
  19. package/examples/display/st7036/minimal.js +21 -0
  20. package/examples/display/uc1611s/complete.js +135 -0
  21. package/examples/display/uc1611s/complete_spi.js +128 -0
  22. package/examples/display/uc1611s/demo.js +90 -0
  23. package/examples/display/uc1611s/demo_spi.js +91 -0
  24. package/examples/display/uc1611s/minimal.js +28 -0
  25. package/examples/display/uc1611s/minimal_spi.js +30 -0
  26. package/examples/display/uc8159/complete.js +64 -0
  27. package/examples/display/uc8159/demo.js +41 -0
  28. package/examples/display/uc8159/minimal.js +28 -0
  29. package/examples/display/uc8276c/complete.js +73 -0
  30. package/examples/display/uc8276c/demo.js +49 -0
  31. package/examples/display/uc8276c/minimal.js +26 -0
  32. package/examples/environmental/bme280/complete.js +1 -1
  33. package/examples/environmental/bme280/demo.js +1 -1
  34. package/examples/environmental/bme280/minimal.js +1 -1
  35. package/examples/gyroscope/l3g4200d/complete.js +1 -1
  36. package/examples/gyroscope/l3g4200d/demo.js +1 -1
  37. package/examples/gyroscope/l3g4200d/minimal.js +1 -1
  38. package/examples/memory/23x1024/complete.js +54 -0
  39. package/examples/memory/23x1024/demo.js +51 -0
  40. package/examples/memory/23x1024/minimal.js +22 -0
  41. package/examples/memory/mx25l12845e/complete.js +66 -0
  42. package/examples/memory/mx25l12845e/demo.js +66 -0
  43. package/examples/memory/mx25l12845e/minimal.js +27 -0
  44. package/examples/memory/sd_spi/complete.js +55 -0
  45. package/examples/memory/sd_spi/demo.js +67 -0
  46. package/examples/memory/sd_spi/minimal.js +32 -0
  47. package/examples/motor/drv8830/complete.js +50 -0
  48. package/examples/motor/drv8830/demo.js +57 -0
  49. package/examples/motor/drv8830/minimal.js +23 -0
  50. package/examples/pressure/bmp280/complete.js +1 -1
  51. package/examples/pressure/bmp280/demo.js +1 -1
  52. package/examples/pressure/bmp280/minimal.js +1 -1
  53. package/examples/pressure/bmp581/complete.js +1 -1
  54. package/examples/pressure/bmp581/demo.js +1 -1
  55. package/examples/pressure/bmp581/minimal.js +1 -1
  56. package/examples/pressure/lps22df/complete.js +1 -1
  57. package/examples/pressure/lps22df/demo.js +1 -1
  58. package/examples/pressure/lps22df/minimal.js +1 -1
  59. package/examples/rtc/ds3231/complete.js +77 -0
  60. package/examples/rtc/ds3231/demo.js +60 -0
  61. package/examples/rtc/ds3231/minimal.js +23 -0
  62. package/examples/rtc/pcf8523/complete.js +66 -0
  63. package/examples/rtc/pcf8523/demo.js +65 -0
  64. package/examples/rtc/pcf8523/minimal.js +20 -0
  65. package/examples/temperature/mcp9808/complete.js +89 -0
  66. package/examples/temperature/mcp9808/demo.js +62 -0
  67. package/examples/temperature/mcp9808/minimal.js +21 -0
  68. package/examples/temperature/tmp117/complete.js +90 -0
  69. package/examples/temperature/tmp117/demo.js +73 -0
  70. package/examples/temperature/tmp117/minimal.js +21 -0
  71. package/examples/tof/vl53l0x/complete.js +118 -0
  72. package/examples/tof/vl53l0x/demo.js +83 -0
  73. package/examples/tof/vl53l0x/minimal.js +25 -0
  74. package/examples/tof/vl53l1x/complete.js +151 -0
  75. package/examples/tof/vl53l1x/demo.js +100 -0
  76. package/examples/tof/vl53l1x/minimal.js +25 -0
  77. package/package.json +1 -1
  78. package/src/chips/accelerometer/adxl345.js +10 -31
  79. package/src/chips/accelerometer/adxl362.js +7 -7
  80. package/src/chips/accelerometer/bma150.js +419 -0
  81. package/src/chips/adc_dac/ad7705.js +36 -9
  82. package/src/chips/adc_dac/ad7706.js +39 -9
  83. package/src/chips/adc_dac/hy3131.js +311 -0
  84. package/src/chips/display/il0373.js +607 -0
  85. package/src/chips/display/ssd1331.js +412 -0
  86. package/src/chips/display/st7036.js +401 -0
  87. package/src/chips/display/uc1611s.js +648 -0
  88. package/src/chips/display/uc8159.js +394 -0
  89. package/src/chips/display/uc8276c.js +658 -0
  90. package/src/chips/environmental/bme280.js +31 -46
  91. package/src/chips/environmental/bme680.js +38 -43
  92. package/src/chips/gas/ens160.js +18 -26
  93. package/src/chips/gyroscope/l3g4200d.js +34 -50
  94. package/src/chips/gyroscope/l3gd20h.js +24 -40
  95. package/src/chips/imu/mpu6050.js +29 -41
  96. package/src/chips/imu/mpu9250.js +45 -69
  97. package/src/chips/imu/mpu9255.js +54 -78
  98. package/src/chips/io_expander/mcp23017.js +24 -33
  99. package/src/chips/light/apds-9930.js +52 -60
  100. package/src/chips/light/apds9960.js +69 -77
  101. package/src/chips/magnetometer/as5600.js +13 -27
  102. package/src/chips/magnetometer/hmc5883l.js +32 -29
  103. package/src/chips/memory/_23x1024.js +228 -0
  104. package/src/chips/memory/_24aa02uid.js +8 -11
  105. package/src/chips/memory/mx25l12845e.js +467 -0
  106. package/src/chips/memory/sd_spi.js +486 -0
  107. package/src/chips/motor/drv8830.js +239 -0
  108. package/src/chips/other/mpr121.js +7 -7
  109. package/src/chips/power/ina219.js +5 -8
  110. package/src/chips/power/ina226.js +5 -8
  111. package/src/chips/power/ina3221.js +5 -8
  112. package/src/chips/pressure/bmp085.js +17 -11
  113. package/src/chips/pressure/bmp180.js +7 -7
  114. package/src/chips/pressure/bmp280.js +21 -33
  115. package/src/chips/pressure/bmp384.js +28 -39
  116. package/src/chips/pressure/bmp581.js +59 -70
  117. package/src/chips/pressure/lps22df.js +50 -52
  118. package/src/chips/pressure/lps28dfw.js +15 -13
  119. package/src/chips/pressure/lps33hw.js +7 -5
  120. package/src/chips/rtc/ds3231.js +504 -0
  121. package/src/chips/rtc/pcf8523.js +533 -0
  122. package/src/chips/temperature/mcp9808.js +490 -0
  123. package/src/chips/temperature/tmp117.js +471 -0
  124. package/src/chips/tof/_vl53_base.js +160 -0
  125. package/src/chips/tof/vl53l0x.js +816 -0
  126. package/src/chips/tof/vl53l1x.js +816 -0
  127. package/src/connection/connection.js +6 -4
  128. package/src/connection/dhtxx.js +5 -3
  129. package/src/connection/display.js +278 -0
  130. package/src/connection/display_mock.js +77 -0
  131. package/src/connection/hx711.js +5 -3
  132. package/src/connection/i2c.js +6 -4
  133. package/src/connection/i2c_mock.js +47 -0
  134. package/src/connection/input_pin.js +36 -5
  135. package/src/connection/register.js +14 -0
  136. package/src/connection/register_connection.js +65 -0
  137. package/src/connection/sipo.js +4 -2
  138. package/src/connection/sipo_mock.js +49 -0
  139. package/src/connection/smbus.js +6 -4
  140. package/src/connection/softspi.js +73 -0
  141. package/src/connection/spi.js +110 -23
  142. package/src/connection/spi_mock.js +50 -0
  143. package/src/connection/uart.js +2 -1
  144. package/src/discovery/discovery.js +218 -0
  145. package/src/discovery/registry.js +85 -0
  146. package/src/storage/block_device.js +95 -0
  147. package/src/storage/ram_block_device.js +72 -0
  148. package/examples/motor/.gitkeep +0 -0
  149. package/examples/temperature/.gitkeep +0 -0
  150. package/examples/tof/.gitkeep +0 -0
  151. package/src/chips/motor/.gitkeep +0 -0
  152. package/src/chips/temperature/.gitkeep +0 -0
  153. package/src/chips/tof/.gitkeep +0 -0
@@ -0,0 +1,401 @@
1
+ 'use strict';
2
+
3
+ const COLUMNS = 16;
4
+ const ROWS = 2;
5
+
6
+ const SUPPLY_3V3 = 0;
7
+ const SUPPLY_5V = 1;
8
+
9
+ const _CMD_CLEAR = 0x01;
10
+ const _CMD_HOME = 0x02;
11
+ const _CMD_ENTRY = 0x04;
12
+ const _CMD_DISPLAY = 0x08;
13
+ const _CMD_SHIFT = 0x10;
14
+ const _CMD_FUNCTION = 0x20;
15
+ const _CMD_CGRAM = 0x40;
16
+ const _CMD_DDRAM = 0x80;
17
+ const _CMD_BIAS = 0x14; // table 1: 0x14 | BS << 3 | FX
18
+ const _CMD_ICONADDR = 0x40; // table 1
19
+ const _CMD_POWER = 0x50; // table 1: | Ion << 3 | Bon << 2 | C5 << 1 | C4
20
+ const _CMD_FOLLOWER = 0x60; // table 1: | Fon << 3 | Rab2..0
21
+ const _CMD_CONTRAST = 0x70; // table 1: | C3..C0
22
+ const _CMD_DHPOS = 0x10; // table 2: | UD << 3
23
+
24
+ // [function, bias, power, follower, contrast low] per module (1, 2, 3 lines) and supply, data sheet page 7
25
+ const _PRESETS = [
26
+ [[0x31, 0x14, 0x55, 0x6D, 0x7C], [0x31, 0x1C, 0x51, 0x6A, 0x74]], // DOGM081
27
+ [[0x39, 0x14, 0x55, 0x6D, 0x78], [0x39, 0x1C, 0x52, 0x69, 0x74]], // DOGM162
28
+ [[0x39, 0x15, 0x55, 0x6E, 0x72], [0x39, 0x1D, 0x50, 0x6C, 0x7C]], // DOGM163
29
+ ];
30
+
31
+ /**
32
+ * ST7036 character LCD controller — minimal interface.
33
+ *
34
+ * Drives an EA DOGM162W-A (2 x 16, 3.3 V) over 4-wire serial: SI, SCL, CSB, RS (C/D) and RESET.
35
+ * The HD44780-compatible instruction set has an extension table (selected by Function Set
36
+ * IS[2:1]) for bias, booster, follower and contrast; the DOG presets from the data sheet
37
+ * (page 7) are sent at initialisation.
38
+ *
39
+ * The connection is a DisplayConnection (see specs/transport_display.md) with no BUSY pin: the
40
+ * serial mode is write-only and has no busy flag, so every instruction is followed by a fixed
41
+ * wait (30 us, 2 ms after Clear / Return Home). Every instruction is a single byte sent with RS
42
+ * (D/C#) low; every data byte gets its own CS window, followed by the 30 us gap.
43
+ *
44
+ * The constructor starts the initialisation sequence; every method waits for it, and `ready()`
45
+ * resolves (or rejects) when it is done.
46
+ *
47
+ * @param {object} connection - A DisplayConnection (SIMPLEX wiring, no BUSY pin), SPI mode 0 at
48
+ * about 1 MHz or less (SCL cycle >= 200 ns at <= 4.5 V).
49
+ */
50
+ class ST7036Minimal {
51
+ constructor(connection, preset = null) {
52
+ const p = preset || {
53
+ lines: ROWS, columns: COLUMNS, n: 1, bon: 1, contrast: 0x18, rab: 5, quarter: false, fx: 0,
54
+ seq: [0x39, 0x14, 0x55, 0x6D, 0x78],
55
+ };
56
+ this._conn = connection;
57
+ this._lines = p.lines;
58
+ this._columns = p.columns;
59
+ this._n = p.n; // Function Set N
60
+ this._dh = 0; // Function Set DH
61
+ this._bon = p.bon; // booster on
62
+ this._ion = 0; // ICON display on
63
+ this._contrast = p.contrast; // C5..C0
64
+ this._fon = 1; // follower on
65
+ this._rab = p.rab; // Rab2..0
66
+ this._quarter = p.quarter; // bias 1/4
67
+ this._fx = p.fx; // bias FX bit
68
+ this._display = 0x0C; // Display ON/OFF byte
69
+ this._entry = 0x06; // Entry Mode byte
70
+ this._addr = 0; // cached DDRAM address
71
+ this._ready = this._initSequence(...p.seq);
72
+ this._ready.catch(() => {}); // surfaced through ready() and the first awaited call
73
+ }
74
+
75
+ /** @returns {number} Characters per line. */
76
+ get columns() { return this._columns; }
77
+
78
+ /** @returns {number} Number of lines. */
79
+ get rows() { return this._lines; }
80
+
81
+ /**
82
+ * Resolves when initialisation has finished; rejects if it failed.
83
+ * @returns {Promise<void>}
84
+ */
85
+ ready() { return this._ready; }
86
+
87
+ // ---- internals -------------------------------------------------------------------------
88
+
89
+ /** Send one instruction byte (RS low) and wait `waitUs` microseconds. */
90
+ async _instr(byte, waitUs = 30) {
91
+ await this._conn.sendCommand(byte);
92
+ if (waitUs >= 1000) await this._conn.delayMs(Math.ceil(waitUs / 1000));
93
+ else await this._conn.delayUs(waitUs);
94
+ }
95
+
96
+ /** Send one data byte (RS high) in its own CS window, then wait 30 us. */
97
+ async _data(byte) {
98
+ await this._conn.sendData([byte & 0xFF]);
99
+ await this._conn.delayUs(30);
100
+ }
101
+
102
+ _rowStart(row) { return this._lines === 3 ? row * 0x10 : row * 0x40; }
103
+
104
+ async _setDdram(addr) {
105
+ this._addr = addr & 0x7F;
106
+ await this._instr(_CMD_DDRAM | this._addr);
107
+ }
108
+
109
+ /** Function Set byte for the cached N / DH and instruction table `table` (0..2). */
110
+ _function(table) {
111
+ return _CMD_FUNCTION | 0x10 | (this._n << 3) | (this._dh << 2) | (table & 3);
112
+ }
113
+
114
+ /** Power/ICON/Contrast high byte from the cached Ion, Bon and contrast. */
115
+ _powerByte() {
116
+ return _CMD_POWER | (this._ion << 3) | (this._bon << 2) | ((this._contrast >> 4) & 3);
117
+ }
118
+
119
+ /** Hardware reset, power-up wait and the instruction sequence of a preset. */
120
+ async _initSequence(func, bias, power, follower, contrast) {
121
+ await this._conn.reset();
122
+ await this._conn.delayMs(40);
123
+ await this._instr(func);
124
+ await this._instr(bias);
125
+ await this._instr(contrast);
126
+ await this._instr(power);
127
+ await this._instr(follower);
128
+ await this._conn.delayMs(200); // booster / V0 settle
129
+ await this._instr(func & ~0x01); // back to instruction table 0
130
+ await this._instr(this._display);
131
+ await this._instr(_CMD_CLEAR, 2000);
132
+ await this._instr(this._entry);
133
+ this._addr = 0;
134
+ }
135
+
136
+ // ---- public API ------------------------------------------------------------------------
137
+
138
+ /** Clear the display (Clear Display, 2 ms); the cursor goes to the top left. @returns {Promise<void>} */
139
+ async clear() {
140
+ await this._ready;
141
+ await this._instr(_CMD_CLEAR, 2000);
142
+ this._addr = 0;
143
+ }
144
+
145
+ /** Return the cursor (and a shifted display) to the home position (Return Home, 2 ms). @returns {Promise<void>} */
146
+ async home() {
147
+ await this._ready;
148
+ await this._instr(_CMD_HOME, 2000);
149
+ this._addr = 0;
150
+ }
151
+
152
+ /**
153
+ * Move the cursor to (col, row). Out-of-range positions are ignored.
154
+ * @param {number} col - Column, 0 .. columns - 1.
155
+ * @param {number} row - Row, 0 .. rows - 1.
156
+ * @returns {Promise<void>}
157
+ */
158
+ async setCursor(col, row) {
159
+ await this._ready;
160
+ if (col < 0 || row < 0 || col >= this._columns || row >= this._lines) return;
161
+ await this._setDdram(this._rowStart(row) + col);
162
+ }
163
+
164
+ /**
165
+ * Write text at the cursor, one data byte per transfer with a 30 us gap. ASCII 0x20 .. 0x7D is
166
+ * written as is; any other character becomes '?'. The cursor does not wrap to the next line.
167
+ * @param {string} text - Text to write.
168
+ * @returns {Promise<void>}
169
+ */
170
+ async write(text) {
171
+ await this._ready;
172
+ if (text === null || text === undefined) return;
173
+ for (const ch of String(text)) {
174
+ const c = ch.codePointAt(0);
175
+ await this._writeCode(c >= 0x20 && c <= 0x7D ? c : 0x3F);
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Write one raw character code (including the CGRAM codes 0..7) at the cursor.
181
+ * @param {number} code - Character code 0..255.
182
+ * @returns {Promise<void>}
183
+ */
184
+ async writeChar(code) {
185
+ await this._ready;
186
+ await this._writeCode(code);
187
+ }
188
+
189
+ async _writeCode(code) {
190
+ await this._data(code);
191
+ this._addr = (this._addr + 1) & 0x7F;
192
+ }
193
+
194
+ /**
195
+ * Move the cursor to (col, row) and write text.
196
+ * @param {number} col - Column.
197
+ * @param {number} row - Row.
198
+ * @param {string} text - Text to write.
199
+ * @returns {Promise<void>}
200
+ */
201
+ async printAt(col, row, text) {
202
+ await this.setCursor(col, row);
203
+ await this.write(text);
204
+ }
205
+ }
206
+
207
+ /**
208
+ * ST7036 character LCD controller — full interface.
209
+ *
210
+ * Extends ST7036Minimal with the DOGM081 / DOGM162 / DOGM163 modules at 3.3 V or 5 V, display
211
+ * control (on/off, cursor, blink, entry mode, shift), contrast, booster, follower and bias,
212
+ * custom characters (CGRAM), double height, ICON RAM and raw instructions.
213
+ *
214
+ * @param {object} connection - A DisplayConnection (SIMPLEX wiring, no BUSY pin).
215
+ * @param {number} [lines=2] - 1 (DOGM081, 1 x 8), 2 (DOGM162, 2 x 16) or 3 (DOGM163, 3 x 16).
216
+ * @param {number|null} [columns=null] - Characters per line, or null for the module default (8 or 16).
217
+ * @param {number} [supply=SUPPLY_3V3] - SUPPLY_3V3 (booster on) or SUPPLY_5V (booster off).
218
+ * @param {number|null} [contrast=null] - Contrast C5..C0 0..63, or null for the data sheet preset.
219
+ */
220
+ class ST7036Full extends ST7036Minimal {
221
+ constructor(connection, lines = 2, columns = null, supply = SUPPLY_3V3, contrast = null) {
222
+ if (![1, 2, 3].includes(lines)) throw new RangeError('lines must be 1, 2 or 3');
223
+ let [func, bias, power, follower, low] = _PRESETS[lines - 1][supply];
224
+ let c = ((power & 3) << 4) | (low & 0x0F);
225
+ if (contrast !== null && contrast !== undefined) {
226
+ c = contrast & 0x3F;
227
+ power = (power & ~3) | ((c >> 4) & 3);
228
+ low = _CMD_CONTRAST | (c & 0x0F);
229
+ }
230
+ super(connection, {
231
+ lines, columns: columns !== null && columns !== undefined ? columns : (lines === 1 ? 8 : 16),
232
+ n: (func >> 3) & 1, bon: (power >> 2) & 1, contrast: c, rab: follower & 7,
233
+ quarter: ((bias >> 3) & 1) === 1, fx: bias & 1,
234
+ seq: [func, bias, power, follower, low],
235
+ });
236
+ }
237
+
238
+ // ---- display control -------------------------------------------------------------------
239
+
240
+ async _setDisplayBit(mask, on) {
241
+ this._display = on ? (this._display | mask) : (this._display & ~mask);
242
+ this._display = (this._display & 0x07) | _CMD_DISPLAY;
243
+ await this._instr(this._display);
244
+ }
245
+
246
+ /** Turn the display on or off (the DDRAM content is kept). @param {boolean} on @returns {Promise<void>} */
247
+ async display(on) { await this._ready; await this._setDisplayBit(0x04, on); }
248
+
249
+ /**
250
+ * Show or hide the cursor and its blinking block.
251
+ * @param {boolean} on - Underline cursor.
252
+ * @param {boolean} [blink=false] - Blinking character block.
253
+ * @returns {Promise<void>}
254
+ */
255
+ async cursor(on, blink = false) {
256
+ await this._ready;
257
+ await this._setDisplayBit(0x02, on);
258
+ await this._setDisplayBit(0x01, blink);
259
+ }
260
+
261
+ /**
262
+ * Set the entry mode: cursor direction and display shift on write.
263
+ * @param {boolean} increment - true = cursor moves right (address + 1), false = left.
264
+ * @param {boolean} [shift=false] - true = shift the display on every write.
265
+ * @returns {Promise<void>}
266
+ */
267
+ async setEntryMode(increment, shift = false) {
268
+ await this._ready;
269
+ this._entry = _CMD_ENTRY | (increment ? 2 : 0) | (shift ? 1 : 0);
270
+ await this._instr(this._entry);
271
+ }
272
+
273
+ /** Shift the cursor one position. @param {boolean} right @returns {Promise<void>} */
274
+ async shiftCursor(right) { await this._ready; await this._instr(_CMD_SHIFT | (right ? 0x04 : 0)); }
275
+
276
+ /** Shift the whole display one position (the cursor follows). @param {boolean} right @returns {Promise<void>} */
277
+ async shiftDisplay(right) { await this._ready; await this._instr(_CMD_SHIFT | 0x08 | (right ? 0x04 : 0)); }
278
+
279
+ /** Return the cursor and a shifted display to the home position (2 ms). @returns {Promise<void>} */
280
+ async returnHome() { await this.home(); }
281
+
282
+ /** Set a raw DDRAM address (for use with display shift). @param {number} address 0..0x7F @returns {Promise<void>} */
283
+ async setDdramAddress(address) { await this._ready; await this._setDdram(address); }
284
+
285
+ // ---- contrast and supply ---------------------------------------------------------------
286
+
287
+ async _extBegin() { await this._instr(this._function(1)); }
288
+ async _extEnd() { await this._instr(this._function(0)); }
289
+
290
+ /** Set the contrast C5..C0. @param {number} value - 0..63. @returns {Promise<void>} */
291
+ async setContrast(value) {
292
+ await this._ready;
293
+ this._contrast = value & 0x3F;
294
+ await this._extBegin();
295
+ await this._instr(this._powerByte());
296
+ await this._instr(_CMD_CONTRAST | (this._contrast & 0x0F));
297
+ await this._extEnd();
298
+ }
299
+
300
+ /** Switch the voltage booster on or off (needed at 3.3 V). @param {boolean} on @returns {Promise<void>} */
301
+ async setBooster(on) {
302
+ await this._ready;
303
+ this._bon = on ? 1 : 0;
304
+ await this._extBegin();
305
+ await this._instr(this._powerByte());
306
+ await this._extEnd();
307
+ }
308
+
309
+ /**
310
+ * Set the voltage follower and the V0 amplification.
311
+ * @param {boolean} on - Follower on.
312
+ * @param {number} ratio - Rab2..Rab0 0..7: 1 + Rb/Ra = 1, 1.25, 1.5, 1.8, 2, 2.5, 3, 3.75.
313
+ * @returns {Promise<void>}
314
+ */
315
+ async setFollower(on, ratio) {
316
+ await this._ready;
317
+ this._fon = on ? 1 : 0;
318
+ this._rab = ratio & 7;
319
+ await this._extBegin();
320
+ await this._instr(_CMD_FOLLOWER | (this._fon << 3) | this._rab);
321
+ await this._extEnd();
322
+ }
323
+
324
+ /**
325
+ * Set the LCD bias: 1/5 (default) or 1/4. FX follows the line count.
326
+ * @param {boolean} quarter - true = 1/4 bias, false = 1/5 bias.
327
+ * @returns {Promise<void>}
328
+ */
329
+ async setBias(quarter) {
330
+ await this._ready;
331
+ this._quarter = !!quarter;
332
+ await this._extBegin();
333
+ await this._instr(_CMD_BIAS | (quarter ? 8 : 0) | this._fx);
334
+ await this._extEnd();
335
+ }
336
+
337
+ // ---- custom characters and special modes -----------------------------------------------
338
+
339
+ /**
340
+ * Define a user character (CGRAM) and restore the DDRAM address.
341
+ * @param {number} index - Character code 0..7.
342
+ * @param {number[]} rows - 8 row patterns, 5 bits each (bit 4 = leftmost pixel).
343
+ * @returns {Promise<void>}
344
+ */
345
+ async createChar(index, rows) {
346
+ await this._ready;
347
+ const saved = this._addr;
348
+ await this._instr(_CMD_CGRAM | ((index & 7) << 3));
349
+ for (let i = 0; i < 8; i++) await this._data(rows[i] & 0x1F);
350
+ await this._setDdram(saved);
351
+ }
352
+
353
+ /**
354
+ * Double-height font (1-line module: 5 x 16 font; 3-line module: top or bottom pair of lines).
355
+ * Ignored on the 2-line module (the combination is forbidden by the data sheet).
356
+ * @param {boolean} on - Double height on.
357
+ * @param {boolean} [upper=true] - 3-line module only: true = COM1..16 (UD = 1), false = COM9..24.
358
+ * @returns {Promise<void>}
359
+ */
360
+ async setDoubleHeight(on, upper = true) {
361
+ await this._ready;
362
+ if (this._lines === 2) return;
363
+ this._dh = on ? 1 : 0;
364
+ await this._instr(this._function(this._lines === 1 ? 0 : 2));
365
+ if (this._lines === 3) await this._instr(_CMD_DHPOS | (upper ? 8 : 0));
366
+ await this._instr(this._function(0));
367
+ }
368
+
369
+ /** Turn the ICON display on or off (no icons are wired on the DOG modules). @param {boolean} on @returns {Promise<void>} */
370
+ async icon(on) {
371
+ await this._ready;
372
+ this._ion = on ? 1 : 0;
373
+ await this._extBegin();
374
+ await this._instr(this._powerByte());
375
+ await this._extEnd();
376
+ }
377
+
378
+ /**
379
+ * Write one ICON RAM byte.
380
+ * @param {number} address - ICON RAM address 0..15.
381
+ * @param {number} value - Byte to store.
382
+ * @returns {Promise<void>}
383
+ */
384
+ async writeIcon(address, value) {
385
+ await this._ready;
386
+ const saved = this._addr;
387
+ await this._extBegin();
388
+ await this._instr(_CMD_ICONADDR | (address & 0x0F));
389
+ await this._data(value);
390
+ await this._extEnd();
391
+ await this._setDdram(saved);
392
+ }
393
+
394
+ /** Send any instruction byte (RS low) and wait 30 us. @param {number} instruction @returns {Promise<void>} */
395
+ async sendCommand(instruction) { await this._ready; await this._instr(instruction & 0xFF); }
396
+
397
+ /** Send any data byte (RS high) and wait 30 us. @param {number} value @returns {Promise<void>} */
398
+ async sendData(value) { await this.writeChar(value); }
399
+ }
400
+
401
+ module.exports = { ST7036Minimal, ST7036Full, COLUMNS, ROWS, SUPPLY_3V3, SUPPLY_5V };