periph 1.3.3 → 1.5.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.
- package/README.md +36 -0
- package/examples/adc_dac/ad5251/complete.js +66 -0
- package/examples/adc_dac/ad5251/demo.js +69 -0
- package/examples/adc_dac/ad5251/minimal.js +23 -0
- package/examples/adc_dac/ad5252/complete.js +66 -0
- package/examples/adc_dac/ad5252/demo.js +69 -0
- package/examples/adc_dac/ad5252/minimal.js +23 -0
- package/examples/adc_dac/ads7828/complete.js +46 -0
- package/examples/adc_dac/ads7828/demo.js +45 -0
- package/examples/adc_dac/ads7828/minimal.js +17 -0
- package/examples/adc_dac/cat5171/complete.js +52 -0
- package/examples/adc_dac/cat5171/demo.js +59 -0
- package/examples/adc_dac/cat5171/minimal.js +23 -0
- package/examples/adc_dac/cs43l22/complete.js +88 -0
- package/examples/adc_dac/cs43l22/demo.js +56 -0
- package/examples/adc_dac/cs43l22/minimal.js +20 -0
- package/examples/adc_dac/ds1881/complete.js +62 -0
- package/examples/adc_dac/ds1881/demo.js +61 -0
- package/examples/adc_dac/ds1881/minimal.js +25 -0
- package/examples/adc_dac/ds3502/complete.js +46 -0
- package/examples/adc_dac/ds3502/demo.js +54 -0
- package/examples/adc_dac/ds3502/minimal.js +28 -0
- package/examples/adc_dac/es8311/complete.js +80 -0
- package/examples/adc_dac/es8311/demo.js +59 -0
- package/examples/adc_dac/es8311/minimal.js +18 -0
- package/examples/adc_dac/mcp3422/complete.js +48 -0
- package/examples/adc_dac/mcp3422/demo.js +49 -0
- package/examples/adc_dac/mcp3422/minimal.js +25 -0
- package/examples/adc_dac/mcp4xxx/complete.js +97 -0
- package/examples/adc_dac/mcp4xxx/demo.js +76 -0
- package/examples/adc_dac/mcp4xxx/minimal.js +22 -0
- package/examples/display/sh1106/complete.js +101 -0
- package/examples/display/sh1106/demo.js +68 -0
- package/examples/display/sh1106/minimal.js +25 -0
- package/examples/display/ssd1305/complete.js +129 -0
- package/examples/display/ssd1305/demo.js +71 -0
- package/examples/display/ssd1305/minimal.js +25 -0
- package/examples/display/ssd1306/complete.js +115 -0
- package/examples/display/ssd1306/demo.js +70 -0
- package/examples/display/ssd1306/minimal.js +25 -0
- package/examples/environmental/am2315/complete.js +34 -0
- package/examples/environmental/am2315/demo.js +46 -0
- package/examples/environmental/am2315/minimal.js +21 -0
- package/examples/humidity/htu21df/complete.js +49 -0
- package/examples/humidity/htu21df/demo.js +50 -0
- package/examples/humidity/htu21df/minimal.js +22 -0
- package/examples/humidity/sht31/complete.js +53 -0
- package/examples/humidity/sht31/demo.js +53 -0
- package/examples/humidity/sht31/minimal.js +21 -0
- package/examples/humidity/si7021/complete.js +55 -0
- package/examples/humidity/si7021/demo.js +58 -0
- package/examples/humidity/si7021/minimal.js +21 -0
- package/examples/imu/bno055/complete.js +85 -0
- package/examples/imu/bno055/demo.js +70 -0
- package/examples/imu/bno055/minimal.js +20 -0
- package/examples/imu/qmi8658a/complete.js +134 -0
- package/examples/imu/qmi8658a/demo.js +81 -0
- package/examples/imu/qmi8658a/minimal.js +22 -0
- package/examples/io_expander/pca6408a/complete.js +63 -0
- package/examples/io_expander/pca6408a/demo.js +58 -0
- package/examples/io_expander/pca6408a/minimal.js +20 -0
- package/examples/io_expander/pca6416a/complete.js +68 -0
- package/examples/io_expander/pca6416a/demo.js +60 -0
- package/examples/io_expander/pca6416a/minimal.js +20 -0
- package/examples/io_expander/pca9536/complete.js +63 -0
- package/examples/io_expander/pca9536/demo.js +57 -0
- package/examples/io_expander/pca9536/minimal.js +20 -0
- package/examples/io_expander/pca9539/complete.js +68 -0
- package/examples/io_expander/pca9539/demo.js +60 -0
- package/examples/io_expander/pca9539/minimal.js +20 -0
- package/examples/light/max44009/complete.js +56 -0
- package/examples/light/max44009/demo.js +49 -0
- package/examples/light/max44009/minimal.js +22 -0
- package/examples/memory/at24c02n/complete.js +39 -0
- package/examples/memory/at24c02n/demo.js +39 -0
- package/examples/memory/at24c02n/minimal.js +15 -0
- package/examples/memory/at24c64/complete.js +39 -0
- package/examples/memory/at24c64/demo.js +39 -0
- package/examples/memory/at24c64/minimal.js +15 -0
- package/examples/memory/cat24c512/complete.js +39 -0
- package/examples/memory/cat24c512/demo.js +39 -0
- package/examples/memory/cat24c512/minimal.js +15 -0
- package/examples/motor/tmc2130/complete.js +138 -0
- package/examples/motor/tmc2130/demo.js +96 -0
- package/examples/motor/tmc2130/minimal.js +30 -0
- package/examples/motor/tmc2208/complete.js +92 -0
- package/examples/motor/tmc2208/demo.js +85 -0
- package/examples/motor/tmc2208/minimal.js +25 -0
- package/examples/motor/tmc2209/complete.js +106 -0
- package/examples/motor/tmc2209/demo.js +97 -0
- package/examples/motor/tmc2209/minimal.js +25 -0
- package/examples/motor/tmc5160/complete.js +205 -0
- package/examples/motor/tmc5160/demo.js +104 -0
- package/examples/motor/tmc5160/minimal.js +35 -0
- package/examples/other/pca9541/complete.js +52 -0
- package/examples/other/pca9541/demo.js +61 -0
- package/examples/other/pca9541/minimal.js +23 -0
- package/examples/power/axp2101/complete.js +135 -0
- package/examples/power/axp2101/demo.js +68 -0
- package/examples/power/axp2101/minimal.js +24 -0
- package/examples/rtc/pcf85063a/complete.js +68 -0
- package/examples/rtc/pcf85063a/demo.js +76 -0
- package/examples/rtc/pcf85063a/minimal.js +20 -0
- package/examples/temperature/tmp102/complete.js +74 -0
- package/examples/temperature/tmp102/demo.js +71 -0
- package/examples/temperature/tmp102/minimal.js +20 -0
- package/examples/tof/vl6180x/complete.js +62 -0
- package/examples/tof/vl6180x/demo.js +77 -0
- package/examples/tof/vl6180x/minimal.js +23 -0
- package/package.json +1 -1
- package/src/chips/adc_dac/ad5251.js +345 -0
- package/src/chips/adc_dac/ad5252.js +345 -0
- package/src/chips/adc_dac/ads7828.js +225 -0
- package/src/chips/adc_dac/cat5171.js +213 -0
- package/src/chips/adc_dac/cs43l22.js +645 -0
- package/src/chips/adc_dac/ds1881.js +357 -0
- package/src/chips/adc_dac/ds3502.js +241 -0
- package/src/chips/adc_dac/es8311.js +621 -0
- package/src/chips/adc_dac/mcp3422.js +312 -0
- package/src/chips/adc_dac/mcp4xxx.js +982 -0
- package/src/chips/display/mono_oled.js +182 -0
- package/src/chips/display/sh1106.js +496 -0
- package/src/chips/display/ssd1305.js +655 -0
- package/src/chips/display/ssd1306.js +458 -0
- package/src/chips/environmental/am2315.js +237 -0
- package/src/chips/humidity/htu21df.js +222 -0
- package/src/chips/humidity/sht31.js +284 -0
- package/src/chips/humidity/si7021.js +282 -0
- package/src/chips/imu/bno055.js +496 -0
- package/src/chips/imu/qmi8658a.js +1011 -0
- package/src/chips/io_expander/pca6408a.js +407 -0
- package/src/chips/io_expander/pca6416a.js +455 -0
- package/src/chips/io_expander/pca9536.js +398 -0
- package/src/chips/io_expander/pca9539.js +457 -0
- package/src/chips/light/max44009.js +336 -0
- package/src/chips/memory/at24c02n.js +220 -0
- package/src/chips/memory/at24c64.js +220 -0
- package/src/chips/memory/cat24c512.js +221 -0
- package/src/chips/motor/tmc2130.js +537 -0
- package/src/chips/motor/tmc2208.js +490 -0
- package/src/chips/motor/tmc2209.js +565 -0
- package/src/chips/motor/tmc5160.js +900 -0
- package/src/chips/other/pca9541.js +315 -0
- package/src/chips/power/axp2101.js +968 -0
- package/src/chips/rtc/pcf85063a.js +482 -0
- package/src/chips/temperature/tmp102.js +361 -0
- package/src/chips/tof/vl6180x.js +580 -0
- package/src/connection/uart.js +9 -0
- package/src/connection/uart_mock.js +65 -0
- package/src/discovery/registry.js +85 -8
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shared building blocks of the monochrome page-organised OLED controller drivers (SSD130x style):
|
|
5
|
+
* a page-major 1 bpp framebuffer with drawing primitives, and the two transports (control-byte
|
|
6
|
+
* framed I²C, D/C-pin framed 4-wire SPI).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const I2C_CHUNK = 32; // largest write in bytes including the control byte
|
|
10
|
+
const SPI_CHUNK = 128;
|
|
11
|
+
|
|
12
|
+
/** Page-major monochrome framebuffer (bit 0 of a byte = top pixel of its page) with drawing primitives. */
|
|
13
|
+
class MonoFramebuffer {
|
|
14
|
+
/**
|
|
15
|
+
* @param {number} width - Columns.
|
|
16
|
+
* @param {number} height - Rows, a multiple of 8.
|
|
17
|
+
*/
|
|
18
|
+
constructor(width, height) {
|
|
19
|
+
this.width = width;
|
|
20
|
+
this.height = height;
|
|
21
|
+
this.pages = height / 8;
|
|
22
|
+
this.data = Buffer.alloc(width * this.pages);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Zero the framebuffer. */
|
|
26
|
+
clear() { this.data.fill(0); }
|
|
27
|
+
|
|
28
|
+
/** Set (or clear) every pixel. @param {boolean} [on=true] */
|
|
29
|
+
fill(on = true) { this.data.fill(on ? 0xFF : 0); }
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Set or clear one pixel; out-of-range coordinates are ignored.
|
|
33
|
+
* @param {number} x - Column.
|
|
34
|
+
* @param {number} y - Row.
|
|
35
|
+
* @param {boolean} [on=true]
|
|
36
|
+
*/
|
|
37
|
+
setPixel(x, y, on = true) {
|
|
38
|
+
if (x < 0 || y < 0 || x >= this.width || y >= this.height) return;
|
|
39
|
+
const i = (y >> 3) * this.width + x;
|
|
40
|
+
if (on) this.data[i] |= 1 << (y & 7);
|
|
41
|
+
else this.data[i] &= ~(1 << (y & 7)) & 0xFF;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Return a pixel; out-of-range coordinates read as false.
|
|
46
|
+
* @param {number} x
|
|
47
|
+
* @param {number} y
|
|
48
|
+
* @returns {boolean}
|
|
49
|
+
*/
|
|
50
|
+
getPixel(x, y) {
|
|
51
|
+
if (x < 0 || y < 0 || x >= this.width || y >= this.height) return false;
|
|
52
|
+
return (this.data[(y >> 3) * this.width + x] & (1 << (y & 7))) !== 0;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Bresenham line. @param {number} x0 @param {number} y0 @param {number} x1 @param {number} y1 @param {boolean} [on=true] */
|
|
56
|
+
drawLine(x0, y0, x1, y1, on = true) {
|
|
57
|
+
const dx = Math.abs(x1 - x0);
|
|
58
|
+
const dy = -Math.abs(y1 - y0);
|
|
59
|
+
const sx = x0 < x1 ? 1 : -1;
|
|
60
|
+
const sy = y0 < y1 ? 1 : -1;
|
|
61
|
+
let err = dx + dy;
|
|
62
|
+
for (;;) {
|
|
63
|
+
this.setPixel(x0, y0, on);
|
|
64
|
+
if (x0 === x1 && y0 === y1) break;
|
|
65
|
+
const e2 = 2 * err;
|
|
66
|
+
if (e2 >= dy) { err += dy; x0 += sx; }
|
|
67
|
+
if (e2 <= dx) { err += dx; y0 += sy; }
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Rectangle outline or filled rectangle.
|
|
73
|
+
* @param {number} x
|
|
74
|
+
* @param {number} y
|
|
75
|
+
* @param {number} w
|
|
76
|
+
* @param {number} h
|
|
77
|
+
* @param {boolean} [on=true]
|
|
78
|
+
* @param {boolean} [fill=false]
|
|
79
|
+
*/
|
|
80
|
+
drawRect(x, y, w, h, on = true, fill = false) {
|
|
81
|
+
if (w <= 0 || h <= 0) return;
|
|
82
|
+
if (fill) {
|
|
83
|
+
for (let yy = y; yy < y + h; yy++) for (let xx = x; xx < x + w; xx++) this.setPixel(xx, yy, on);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
this.drawLine(x, y, x + w - 1, y, on);
|
|
87
|
+
this.drawLine(x, y + h - 1, x + w - 1, y + h - 1, on);
|
|
88
|
+
this.drawLine(x, y, x, y + h - 1, on);
|
|
89
|
+
this.drawLine(x + w - 1, y, x + w - 1, y + h - 1, on);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Copy a column-major bitmap (8 pixels per byte, bit 0 = top); clipped. `columns` holds `heightPages`
|
|
94
|
+
* groups of columns, page by page: byte p * n + c is column c of page row p.
|
|
95
|
+
* @param {number} x
|
|
96
|
+
* @param {number} y - Top row, a multiple of 8.
|
|
97
|
+
* @param {Buffer|number[]} columns
|
|
98
|
+
* @param {number} [heightPages=1]
|
|
99
|
+
* @throws {RangeError} If y is not a multiple of 8.
|
|
100
|
+
*/
|
|
101
|
+
blit(x, y, columns, heightPages = 1) {
|
|
102
|
+
if (y % 8 !== 0) throw new RangeError('y must be a multiple of 8');
|
|
103
|
+
const n = Math.floor(columns.length / heightPages);
|
|
104
|
+
for (let p = 0; p < heightPages; p++) {
|
|
105
|
+
const page = y / 8 + p;
|
|
106
|
+
if (page < 0 || page >= this.pages) continue;
|
|
107
|
+
for (let c = 0; c < n; c++) {
|
|
108
|
+
const xx = x + c;
|
|
109
|
+
if (xx >= 0 && xx < this.width) this.data[page * this.width + xx] = columns[p * n + c];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** The bytes of one page. @param {number} page @returns {Buffer} */
|
|
115
|
+
page(page) {
|
|
116
|
+
const start = page * this.width;
|
|
117
|
+
return this.data.subarray(start, start + this.width);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** The framebuffer column-major (for vertical addressing). @returns {Buffer} */
|
|
121
|
+
transposed() {
|
|
122
|
+
const out = Buffer.alloc(this.data.length);
|
|
123
|
+
let n = 0;
|
|
124
|
+
for (let x = 0; x < this.width; x++) {
|
|
125
|
+
for (let p = 0; p < this.pages; p++) out[n++] = this.data[p * this.width + x];
|
|
126
|
+
}
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** I²C transport: every transaction starts with a control byte (0x00 = commands, 0x40 = RAM data). */
|
|
132
|
+
class I2cOledBus {
|
|
133
|
+
/** @param {object} connection - I2CConnection at 0x3C or 0x3D. */
|
|
134
|
+
constructor(connection) {
|
|
135
|
+
this._conn = connection;
|
|
136
|
+
this.canRead = true;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
writeCommands(bytes) { return this._conn.write(Buffer.concat([Buffer.from([0x00]), Buffer.from(bytes)])); }
|
|
140
|
+
|
|
141
|
+
async writeData(data) {
|
|
142
|
+
const step = I2C_CHUNK - 1;
|
|
143
|
+
for (let i = 0; i < data.length; i += step) {
|
|
144
|
+
await this._conn.write(Buffer.concat([Buffer.from([0x40]), data.subarray(i, i + step)]));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async readStatus() {
|
|
149
|
+
await this._conn.write(Buffer.from([0x00]));
|
|
150
|
+
return Buffer.from(await this._conn.read(1))[0];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async readRam(n) {
|
|
154
|
+
await this._conn.write(Buffer.from([0x40]));
|
|
155
|
+
return Buffer.from(await this._conn.read(n + 1)).subarray(1);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
async hardwareReset() {}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** 4-wire SPI transport on a display connection: D/C low for every command byte, high for RAM data. */
|
|
162
|
+
class SpiOledBus {
|
|
163
|
+
/** @param {object} connection - DisplayConnection. */
|
|
164
|
+
constructor(connection) {
|
|
165
|
+
this._conn = connection;
|
|
166
|
+
this.canRead = false;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
async writeCommands(bytes) {
|
|
170
|
+
for (const b of bytes) await this._conn.sendCommand(b);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async writeData(data) {
|
|
174
|
+
for (let i = 0; i < data.length; i += SPI_CHUNK) {
|
|
175
|
+
await this._conn.sendData(data.subarray(i, i + SPI_CHUNK));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
hardwareReset() { return this._conn.reset(); }
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
module.exports = { MonoFramebuffer, I2cOledBus, SpiOledBus, I2C_CHUNK, SPI_CHUNK };
|
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const WIDTH = 132;
|
|
4
|
+
const HEIGHT = 64;
|
|
5
|
+
const I2C_CHUNK = 32; // largest write in bytes including the control byte
|
|
6
|
+
const SPI_CHUNK = 132;
|
|
7
|
+
|
|
8
|
+
const _CMD_COL_LO = 0x00; // | A[3:0]
|
|
9
|
+
const _CMD_COL_HI = 0x10; // | A[7:4]
|
|
10
|
+
const _CMD_PUMP = 0x30; // | A[1:0]
|
|
11
|
+
const _CMD_START_LINE = 0x40; // | A[5:0]
|
|
12
|
+
const _CMD_CONTRAST = 0x81;
|
|
13
|
+
const _CMD_SEG_REMAP = 0xA0; // | ADC
|
|
14
|
+
const _CMD_ALL_ON = 0xA4; // | 1
|
|
15
|
+
const _CMD_INVERT = 0xA6; // | 1
|
|
16
|
+
const _CMD_MULTIPLEX = 0xA8;
|
|
17
|
+
const _CMD_DCDC = 0xAD;
|
|
18
|
+
const _CMD_DISPLAY = 0xAE; // | 1
|
|
19
|
+
const _CMD_PAGE = 0xB0; // | A[2:0]
|
|
20
|
+
const _CMD_SCAN = 0xC0; // | (scan << 3)
|
|
21
|
+
const _CMD_OFFSET = 0xD3;
|
|
22
|
+
const _CMD_CLOCK = 0xD5;
|
|
23
|
+
const _CMD_PRECHARGE = 0xD9;
|
|
24
|
+
const _CMD_COM = 0xDA;
|
|
25
|
+
const _CMD_VCOM = 0xDB;
|
|
26
|
+
|
|
27
|
+
const sleepMs = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
28
|
+
|
|
29
|
+
/** I²C transport: every transaction starts with a control byte (0x00 = commands, 0x40 = RAM data). */
|
|
30
|
+
class I2CBus {
|
|
31
|
+
constructor(connection) {
|
|
32
|
+
this._conn = connection;
|
|
33
|
+
this.canRead = true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
writeCommands(bytes) { return this._conn.write(Buffer.concat([Buffer.from([0x00]), Buffer.from(bytes)])); }
|
|
37
|
+
|
|
38
|
+
async writeData(data) {
|
|
39
|
+
const step = I2C_CHUNK - 1;
|
|
40
|
+
for (let i = 0; i < data.length; i += step) {
|
|
41
|
+
await this._conn.write(Buffer.concat([Buffer.from([0x40]), data.subarray(i, i + step)]));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async readStatus() {
|
|
46
|
+
await this._conn.write(Buffer.from([0x00]));
|
|
47
|
+
return Buffer.from(await this._conn.read(1))[0];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async readRam(n) {
|
|
51
|
+
await this._conn.write(Buffer.from([0x40]));
|
|
52
|
+
return Buffer.from(await this._conn.read(n + 1)).subarray(1);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async hardwareReset() {}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** 4-wire SPI transport on a display connection: D/C low for every command byte, high for RAM data. */
|
|
59
|
+
class SpiBus {
|
|
60
|
+
constructor(connection) {
|
|
61
|
+
this._conn = connection;
|
|
62
|
+
this.canRead = false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async writeCommands(bytes) {
|
|
66
|
+
for (const b of bytes) await this._conn.sendCommand(b);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async writeData(data) {
|
|
70
|
+
for (let i = 0; i < data.length; i += SPI_CHUNK) {
|
|
71
|
+
await this._conn.sendData(data.subarray(i, i + SPI_CHUNK));
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
hardwareReset() { return this._conn.reset(); }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* SH1106 132 x 64 OLED controller-driver — minimal interface (I²C).
|
|
80
|
+
*
|
|
81
|
+
* Drives a monochrome SH1106 OLED panel (typically a 1.3" 128 x 64 module) over I²C at 0x3C
|
|
82
|
+
* (SA0 = VSS) or 0x3D (SA0 = VDD1). The chip has 132 RAM columns; 128-pixel-wide modules show RAM
|
|
83
|
+
* columns 2..129, so `columnOffset` defaults to 2.
|
|
84
|
+
*
|
|
85
|
+
* All drawing goes into a framebuffer of width * height / 8 bytes (page-major, bit 0 = top pixel of
|
|
86
|
+
* the page); `show()` sends it page by page (the chip has page addressing only). The initialization
|
|
87
|
+
* follows the datasheet power-on flow with the internal DC-DC: setup stream with the display off,
|
|
88
|
+
* DC-DC on + 100 ms, RAM cleared, display on + 150 ms. The constructor starts the initialisation;
|
|
89
|
+
* every method that talks to the chip waits for it, and `ready()` resolves (or rejects) when done.
|
|
90
|
+
*
|
|
91
|
+
* @param {object} connection - I2CConnection at 0x3C or 0x3D.
|
|
92
|
+
* @param {number} [width=128] - Visible columns, 1..132.
|
|
93
|
+
* @param {number} [height=64] - Rows, a multiple of 8 and at most 64.
|
|
94
|
+
* @param {number} [columnOffset=2] - First RAM column shown (0 for a true 132-column panel).
|
|
95
|
+
* @param {boolean} [internalDcdc=true] - True for the internal charge pump, false for an external VPP.
|
|
96
|
+
* @param {object} [bus] - Internal: transport override used by the SPI classes.
|
|
97
|
+
*/
|
|
98
|
+
class SH1106Minimal {
|
|
99
|
+
constructor(connection, width = 128, height = 64, columnOffset = 2, internalDcdc = true, bus = null) {
|
|
100
|
+
if (!(width >= 1 && width <= WIDTH)) throw new RangeError('width must be 1..132');
|
|
101
|
+
if (!(height >= 8 && height <= HEIGHT && height % 8 === 0)) throw new RangeError('height must be a multiple of 8, 8..64');
|
|
102
|
+
if (!(columnOffset >= 0 && columnOffset + width <= WIDTH)) throw new RangeError('columnOffset + width must be at most 132');
|
|
103
|
+
this._bus = bus || new I2CBus(connection);
|
|
104
|
+
this.width = width;
|
|
105
|
+
this.height = height;
|
|
106
|
+
this._offset = columnOffset;
|
|
107
|
+
this._dcdc = internalDcdc;
|
|
108
|
+
this._pages = height / 8;
|
|
109
|
+
this._fb = Buffer.alloc(width * this._pages);
|
|
110
|
+
this._adc = 0;
|
|
111
|
+
this._scan = 0;
|
|
112
|
+
this._ready = this._initSequence();
|
|
113
|
+
this._ready.catch(() => {}); // surfaced through ready() and the first awaited call
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Resolves when initialisation has finished; rejects if it failed.
|
|
118
|
+
* @returns {Promise<void>}
|
|
119
|
+
*/
|
|
120
|
+
ready() { return this._ready; }
|
|
121
|
+
|
|
122
|
+
// ---- internals -------------------------------------------------------------------------
|
|
123
|
+
|
|
124
|
+
_command(...values) {
|
|
125
|
+
return this._bus.writeCommands(Buffer.from(values));
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
_addressBytes(page, column) {
|
|
129
|
+
return Buffer.from([_CMD_PAGE | (page & 7), _CMD_COL_LO | (column & 0x0F), _CMD_COL_HI | ((column >> 4) & 0x0F)]);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async _writePage(page, data) {
|
|
133
|
+
await this._bus.writeCommands(this._addressBytes(page, this._offset));
|
|
134
|
+
await this._bus.writeData(data);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Datasheet power-on flow: setup stream, DC-DC, RAM clear, display on. */
|
|
138
|
+
async _initSequence() {
|
|
139
|
+
await this._bus.hardwareReset();
|
|
140
|
+
await sleepMs(1);
|
|
141
|
+
await this._command(_CMD_DISPLAY,
|
|
142
|
+
_CMD_CLOCK, 0x50,
|
|
143
|
+
_CMD_MULTIPLEX, this.height - 1,
|
|
144
|
+
_CMD_OFFSET, 0x00,
|
|
145
|
+
_CMD_START_LINE,
|
|
146
|
+
_CMD_SEG_REMAP | this._adc,
|
|
147
|
+
_CMD_SCAN | (this._scan << 3),
|
|
148
|
+
_CMD_COM, 0x12,
|
|
149
|
+
_CMD_CONTRAST, 0x80,
|
|
150
|
+
_CMD_PRECHARGE, 0x22,
|
|
151
|
+
_CMD_VCOM, 0x35,
|
|
152
|
+
_CMD_PUMP,
|
|
153
|
+
_CMD_ALL_ON,
|
|
154
|
+
_CMD_INVERT);
|
|
155
|
+
if (this._dcdc) {
|
|
156
|
+
await this._command(_CMD_DCDC, 0x8B);
|
|
157
|
+
await sleepMs(100);
|
|
158
|
+
} else {
|
|
159
|
+
await this._command(_CMD_DCDC, 0x8A);
|
|
160
|
+
}
|
|
161
|
+
const blank = Buffer.alloc(WIDTH);
|
|
162
|
+
for (let page = 0; page < 8; page++) {
|
|
163
|
+
await this._bus.writeCommands(this._addressBytes(page, 0));
|
|
164
|
+
await this._bus.writeData(blank);
|
|
165
|
+
}
|
|
166
|
+
await this._command(_CMD_DISPLAY | 1);
|
|
167
|
+
await sleepMs(this._dcdc ? 150 : 50);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
_showPage(page) {
|
|
171
|
+
const start = page * this.width;
|
|
172
|
+
return this._writePage(page, this._fb.subarray(start, start + this.width));
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ---- public API ------------------------------------------------------------------------
|
|
176
|
+
|
|
177
|
+
/** Zero the framebuffer. Call `show()` to update the panel. */
|
|
178
|
+
clear() {
|
|
179
|
+
this._fb.fill(0);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Set or clear one pixel in the framebuffer. Out-of-range coordinates are ignored.
|
|
184
|
+
* @param {number} x - Column, 0 .. width - 1.
|
|
185
|
+
* @param {number} y - Row, 0 .. height - 1.
|
|
186
|
+
* @param {boolean} [on=true] - True to set the pixel, false to clear it.
|
|
187
|
+
*/
|
|
188
|
+
setPixel(x, y, on = true) {
|
|
189
|
+
if (x < 0 || y < 0 || x >= this.width || y >= this.height) return;
|
|
190
|
+
const i = (y >> 3) * this.width + x;
|
|
191
|
+
if (on) this._fb[i] |= 1 << (y & 7);
|
|
192
|
+
else this._fb[i] &= ~(1 << (y & 7)) & 0xFF;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Write the whole framebuffer to the display RAM (page + column command, then width data bytes per page).
|
|
197
|
+
* @returns {Promise<void>}
|
|
198
|
+
*/
|
|
199
|
+
async show() {
|
|
200
|
+
await this._ready;
|
|
201
|
+
for (let page = 0; page < this._pages; page++) await this._showPage(page);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* SH1106 OLED controller-driver — full interface (I²C).
|
|
207
|
+
*
|
|
208
|
+
* Extends SH1106Minimal with drawing primitives, contrast, sleep, invert, all-on test, flip,
|
|
209
|
+
* hardware scroll (display start line), display offset, multiplex ratio, clock / oscillator,
|
|
210
|
+
* pre-charge, COM configuration, VCOM level, pump voltage, DC-DC control, status and RAM reads
|
|
211
|
+
* (I²C only) and raw commands.
|
|
212
|
+
*
|
|
213
|
+
* @param {object} connection - I2CConnection at 0x3C or 0x3D.
|
|
214
|
+
* @param {number} [width=128] - Visible columns, 1..132.
|
|
215
|
+
* @param {number} [height=64] - Rows, a multiple of 8 and at most 64.
|
|
216
|
+
* @param {number} [columnOffset=2] - First RAM column shown.
|
|
217
|
+
* @param {boolean} [internalDcdc=true] - True for the internal charge pump.
|
|
218
|
+
* @param {object} [bus] - Internal: transport override used by the SPI classes.
|
|
219
|
+
*/
|
|
220
|
+
class SH1106Full extends SH1106Minimal {
|
|
221
|
+
// ---- framebuffer -----------------------------------------------------------------------
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Return a framebuffer pixel; out-of-range coordinates read as false.
|
|
225
|
+
* @param {number} x - Column.
|
|
226
|
+
* @param {number} y - Row.
|
|
227
|
+
* @returns {boolean} True if the pixel is set.
|
|
228
|
+
*/
|
|
229
|
+
getPixel(x, y) {
|
|
230
|
+
if (x < 0 || y < 0 || x >= this.width || y >= this.height) return false;
|
|
231
|
+
return (this._fb[(y >> 3) * this.width + x] & (1 << (y & 7))) !== 0;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** Set (or clear) the whole framebuffer. @param {boolean} [on=true] */
|
|
235
|
+
fill(on = true) {
|
|
236
|
+
this._fb.fill(on ? 0xFF : 0);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Draw a Bresenham line into the framebuffer.
|
|
241
|
+
* @param {number} x0 - Start column.
|
|
242
|
+
* @param {number} y0 - Start row.
|
|
243
|
+
* @param {number} x1 - End column.
|
|
244
|
+
* @param {number} y1 - End row.
|
|
245
|
+
* @param {boolean} [on=true] - True to set pixels, false to clear them.
|
|
246
|
+
*/
|
|
247
|
+
drawLine(x0, y0, x1, y1, on = true) {
|
|
248
|
+
const dx = Math.abs(x1 - x0);
|
|
249
|
+
const dy = -Math.abs(y1 - y0);
|
|
250
|
+
const sx = x0 < x1 ? 1 : -1;
|
|
251
|
+
const sy = y0 < y1 ? 1 : -1;
|
|
252
|
+
let err = dx + dy;
|
|
253
|
+
for (;;) {
|
|
254
|
+
this.setPixel(x0, y0, on);
|
|
255
|
+
if (x0 === x1 && y0 === y1) break;
|
|
256
|
+
const e2 = 2 * err;
|
|
257
|
+
if (e2 >= dy) { err += dy; x0 += sx; }
|
|
258
|
+
if (e2 <= dx) { err += dx; y0 += sy; }
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Draw a rectangle outline or a filled rectangle into the framebuffer.
|
|
264
|
+
* @param {number} x - Left column.
|
|
265
|
+
* @param {number} y - Top row.
|
|
266
|
+
* @param {number} w - Width in pixels.
|
|
267
|
+
* @param {number} h - Height in pixels.
|
|
268
|
+
* @param {boolean} [on=true] - True to set pixels, false to clear them.
|
|
269
|
+
* @param {boolean} [fill=false] - True for a filled rectangle.
|
|
270
|
+
*/
|
|
271
|
+
drawRect(x, y, w, h, on = true, fill = false) {
|
|
272
|
+
if (w <= 0 || h <= 0) return;
|
|
273
|
+
if (fill) {
|
|
274
|
+
for (let yy = y; yy < y + h; yy++) for (let xx = x; xx < x + w; xx++) this.setPixel(xx, yy, on);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
this.drawLine(x, y, x + w - 1, y, on);
|
|
278
|
+
this.drawLine(x, y + h - 1, x + w - 1, y + h - 1, on);
|
|
279
|
+
this.drawLine(x, y, x, y + h - 1, on);
|
|
280
|
+
this.drawLine(x + w - 1, y, x + w - 1, y + h - 1, on);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Copy a column-major bitmap (8 pixels per byte, bit 0 = top) into the framebuffer. `columns`
|
|
285
|
+
* holds `heightPages` groups of columns, page by page: byte p * n + c is column c of page row p
|
|
286
|
+
* (n = length / heightPages). The bitmap is clipped to the framebuffer; y must be a multiple of 8.
|
|
287
|
+
* @param {number} x - Left column of the bitmap.
|
|
288
|
+
* @param {number} y - Top row, a multiple of 8.
|
|
289
|
+
* @param {Buffer|number[]} columns - Bitmap bytes.
|
|
290
|
+
* @param {number} [heightPages=1] - Number of 8-pixel-high rows of the bitmap.
|
|
291
|
+
*/
|
|
292
|
+
blit(x, y, columns, heightPages = 1) {
|
|
293
|
+
if (y % 8 !== 0) throw new RangeError('y must be a multiple of 8');
|
|
294
|
+
const n = Math.floor(columns.length / heightPages);
|
|
295
|
+
for (let p = 0; p < heightPages; p++) {
|
|
296
|
+
const page = y / 8 + p;
|
|
297
|
+
if (page < 0 || page >= this._pages) continue;
|
|
298
|
+
for (let c = 0; c < n; c++) {
|
|
299
|
+
const xx = x + c;
|
|
300
|
+
if (xx >= 0 && xx < this.width) this._fb[page * this.width + xx] = columns[p * n + c];
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Write one framebuffer page to the display RAM (cheaper partial update).
|
|
307
|
+
* @param {number} page - Page 0 .. height / 8 - 1.
|
|
308
|
+
* @returns {Promise<void>}
|
|
309
|
+
*/
|
|
310
|
+
async showPage(page) {
|
|
311
|
+
await this._ready;
|
|
312
|
+
if (page >= 0 && page < this._pages) await this._showPage(page);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// ---- display control -------------------------------------------------------------------
|
|
316
|
+
|
|
317
|
+
/** Set the segment output current (contrast). @param {number} value - 0..255 (reset 0x80). @returns {Promise<void>} */
|
|
318
|
+
async setContrast(value) {
|
|
319
|
+
await this._ready;
|
|
320
|
+
await this._command(_CMD_CONTRAST, value & 0xFF);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** Switch the display on or off (RAM and settings are kept). @param {boolean} on @returns {Promise<void>} */
|
|
324
|
+
async setDisplay(on) {
|
|
325
|
+
await this._ready;
|
|
326
|
+
await this._command(_CMD_DISPLAY | (on ? 1 : 0));
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/** Display off; the DC-DC stops, RAM and settings are kept and stay writable. @returns {Promise<void>} */
|
|
330
|
+
sleep() { return this.setDisplay(false); }
|
|
331
|
+
|
|
332
|
+
/** Display on, then wait 100 ms for VPP when the internal DC-DC is used. @returns {Promise<void>} */
|
|
333
|
+
async wake() {
|
|
334
|
+
await this.setDisplay(true);
|
|
335
|
+
await sleepMs(this._dcdc ? 100 : 50);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/** Invert the displayed image without changing RAM. @param {boolean} on @returns {Promise<void>} */
|
|
339
|
+
async setInvert(on) {
|
|
340
|
+
await this._ready;
|
|
341
|
+
await this._command(_CMD_INVERT | (on ? 1 : 0));
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/** Force all pixels on (test mode, RAM unchanged). @param {boolean} on @returns {Promise<void>} */
|
|
345
|
+
async setAllOn(on) {
|
|
346
|
+
await this._ready;
|
|
347
|
+
await this._command(_CMD_ALL_ON | (on ? 1 : 0));
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Mirror columns (segment re-map) and/or rows (COM scan direction); the framebuffer is unchanged.
|
|
352
|
+
* @param {boolean} horizontal - True to reverse the segment mapping (ADC = 1).
|
|
353
|
+
* @param {boolean} vertical - True to reverse the COM scan direction (0xC8).
|
|
354
|
+
* @returns {Promise<void>}
|
|
355
|
+
*/
|
|
356
|
+
async setFlip(horizontal, vertical) {
|
|
357
|
+
await this._ready;
|
|
358
|
+
this._adc = horizontal ? 1 : 0;
|
|
359
|
+
this._scan = vertical ? 1 : 0;
|
|
360
|
+
await this._command(_CMD_SEG_REMAP | this._adc, _CMD_SCAN | (this._scan << 3));
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/** Set the RAM line shown at COM0 (hardware vertical scroll). @param {number} line - 0..63. @returns {Promise<void>} */
|
|
364
|
+
async setStartLine(line) {
|
|
365
|
+
await this._ready;
|
|
366
|
+
await this._command(_CMD_START_LINE | (line & 0x3F));
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
/** Shift the COM mapping. @param {number} offset - 0..63. @returns {Promise<void>} */
|
|
370
|
+
async setDisplayOffset(offset) {
|
|
371
|
+
await this._ready;
|
|
372
|
+
await this._command(_CMD_OFFSET, offset & 0x3F);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/** Set the multiplex ratio. @param {number} ratio - 1..64. @returns {Promise<void>} */
|
|
376
|
+
async setMultiplex(ratio) {
|
|
377
|
+
await this._ready;
|
|
378
|
+
await this._command(_CMD_MULTIPLEX, (ratio - 1) & 0x3F);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Set the clock divide ratio and oscillator frequency.
|
|
383
|
+
* @param {number} divide - Divide ratio, 1..16.
|
|
384
|
+
* @param {number} osc - Oscillator setting, 0..15 (5 = nominal).
|
|
385
|
+
* @returns {Promise<void>}
|
|
386
|
+
*/
|
|
387
|
+
async setClock(divide, osc) {
|
|
388
|
+
await this._ready;
|
|
389
|
+
await this._command(_CMD_CLOCK, ((osc & 0x0F) << 4) | ((divide - 1) & 0x0F));
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Set the pre-charge and discharge periods in display clocks.
|
|
394
|
+
* @param {number} precharge - 1..15.
|
|
395
|
+
* @param {number} discharge - 1..15.
|
|
396
|
+
* @returns {Promise<void>}
|
|
397
|
+
*/
|
|
398
|
+
async setPrecharge(precharge, discharge) {
|
|
399
|
+
await this._ready;
|
|
400
|
+
await this._command(_CMD_PRECHARGE, ((discharge & 0x0F) << 4) | (precharge & 0x0F));
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/** Select the COM pin configuration. @param {boolean} alternative - True 0x12 (reset), false 0x02. @returns {Promise<void>} */
|
|
404
|
+
async setComConfig(alternative) {
|
|
405
|
+
await this._ready;
|
|
406
|
+
await this._command(_CMD_COM, alternative ? 0x12 : 0x02);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/** Set the VCOM deselect level. @param {number} value - 0..255 (reset 0x35). @returns {Promise<void>} */
|
|
410
|
+
async setVcomDeselect(value) {
|
|
411
|
+
await this._ready;
|
|
412
|
+
await this._command(_CMD_VCOM, value & 0xFF);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
/** Set the charge pump voltage. @param {number} level - 0 = 7.4 V, 1 = 8.0 V, 2 = 8.4 V, 3 = 9.0 V. @returns {Promise<void>} */
|
|
416
|
+
async setPumpVoltage(level) {
|
|
417
|
+
await this._ready;
|
|
418
|
+
await this._command(_CMD_PUMP | (level & 3));
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/** Switch the internal DC-DC on (0x8B) or off (0x8A, external VPP); call with the display off. @param {boolean} on @returns {Promise<void>} */
|
|
422
|
+
async setDcdc(on) {
|
|
423
|
+
await this._ready;
|
|
424
|
+
this._dcdc = !!on;
|
|
425
|
+
await this._command(_CMD_DCDC, on ? 0x8B : 0x8A);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// ---- reads and raw access --------------------------------------------------------------
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Read the status byte (I²C only).
|
|
432
|
+
* @returns {Promise<number>} Bit 7 BUSY, bit 6 = 1 when the display is off.
|
|
433
|
+
*/
|
|
434
|
+
async readStatus() {
|
|
435
|
+
await this._ready;
|
|
436
|
+
if (!this._bus.canRead) throw new Error('the SPI interface is write-only');
|
|
437
|
+
return this._bus.readStatus();
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Read `n` bytes of display RAM (I²C only); the dummy byte after an address change is discarded.
|
|
442
|
+
* @param {number} page - RAM page 0..7.
|
|
443
|
+
* @param {number} column - Start RAM column.
|
|
444
|
+
* @param {number} n - Number of bytes.
|
|
445
|
+
* @returns {Promise<Buffer>} The RAM bytes.
|
|
446
|
+
*/
|
|
447
|
+
async readPage(page, column, n) {
|
|
448
|
+
await this._ready;
|
|
449
|
+
if (!this._bus.canRead) throw new Error('the SPI interface is write-only');
|
|
450
|
+
await this._bus.writeCommands(this._addressBytes(page, column));
|
|
451
|
+
return this._bus.readRam(n);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/** Send raw bytes as one command stream. @param {...number} bytes @returns {Promise<void>} */
|
|
455
|
+
async sendCommand(...bytes) {
|
|
456
|
+
await this._ready;
|
|
457
|
+
await this._command(...bytes);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* SH1106 over 4-wire SPI — minimal interface.
|
|
463
|
+
*
|
|
464
|
+
* Same framebuffer, drawing and initialization as SH1106Minimal, driven through a display connection
|
|
465
|
+
* (CS, D/C = A0, RES optional, no BUSY). The chip must be strapped for 4-wire SPI. SPI mode 0, up to
|
|
466
|
+
* 2 MHz. Every command byte is sent with D/C low, RAM data with D/C high. SPI cannot read:
|
|
467
|
+
* `readStatus()` / `readPage()` of the full class reject.
|
|
468
|
+
*
|
|
469
|
+
* @param {object} connection - DisplayConnection.
|
|
470
|
+
* @param {number} [width=128] - Visible columns, 1..132.
|
|
471
|
+
* @param {number} [height=64] - Rows, a multiple of 8 and at most 64.
|
|
472
|
+
* @param {number} [columnOffset=2] - First RAM column shown.
|
|
473
|
+
* @param {boolean} [internalDcdc=true] - True for the internal charge pump.
|
|
474
|
+
*/
|
|
475
|
+
class SH1106SpiMinimal extends SH1106Minimal {
|
|
476
|
+
constructor(connection, width = 128, height = 64, columnOffset = 2, internalDcdc = true) {
|
|
477
|
+
super(null, width, height, columnOffset, internalDcdc, new SpiBus(connection));
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* SH1106 over 4-wire SPI — full interface (see SH1106Full; `readStatus()` and `readPage()` reject).
|
|
483
|
+
*
|
|
484
|
+
* @param {object} connection - DisplayConnection.
|
|
485
|
+
* @param {number} [width=128] - Visible columns, 1..132.
|
|
486
|
+
* @param {number} [height=64] - Rows, a multiple of 8 and at most 64.
|
|
487
|
+
* @param {number} [columnOffset=2] - First RAM column shown.
|
|
488
|
+
* @param {boolean} [internalDcdc=true] - True for the internal charge pump.
|
|
489
|
+
*/
|
|
490
|
+
class SH1106SpiFull extends SH1106Full {
|
|
491
|
+
constructor(connection, width = 128, height = 64, columnOffset = 2, internalDcdc = true) {
|
|
492
|
+
super(null, width, height, columnOffset, internalDcdc, new SpiBus(connection));
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
module.exports = { SH1106Minimal, SH1106Full, SH1106SpiMinimal, SH1106SpiFull, WIDTH, HEIGHT, I2C_CHUNK, SPI_CHUNK };
|