periph 1.6.0 → 1.6.1

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 (47) hide show
  1. package/README.md +11 -0
  2. package/examples/gas/rrh62000/complete.js +74 -0
  3. package/examples/gas/rrh62000/demo.js +87 -0
  4. package/examples/gas/rrh62000/minimal.js +22 -0
  5. package/examples/gas/scd30/complete.js +73 -0
  6. package/examples/gas/scd30/demo.js +102 -0
  7. package/examples/gas/scd30/minimal.js +20 -0
  8. package/examples/gas/scd40/complete.js +76 -0
  9. package/examples/gas/scd40/demo.js +109 -0
  10. package/examples/gas/scd40/minimal.js +20 -0
  11. package/examples/light/tsl2561/complete.js +74 -0
  12. package/examples/light/tsl2561/demo.js +46 -0
  13. package/examples/light/tsl2561/minimal.js +22 -0
  14. package/examples/light/tsl2591/complete.js +90 -0
  15. package/examples/light/tsl2591/demo.js +119 -0
  16. package/examples/light/tsl2591/minimal.js +22 -0
  17. package/examples/light/vcnl4040/complete.js +102 -0
  18. package/examples/light/vcnl4040/demo.js +125 -0
  19. package/examples/light/vcnl4040/minimal.js +25 -0
  20. package/examples/light/vcnl4200/complete.js +101 -0
  21. package/examples/light/vcnl4200/demo.js +126 -0
  22. package/examples/light/vcnl4200/minimal.js +25 -0
  23. package/examples/rfid/st25dv/complete.js +94 -0
  24. package/examples/rfid/st25dv/demo.js +121 -0
  25. package/examples/rfid/st25dv/minimal.js +21 -0
  26. package/examples/rtc/bq32000/complete.js +53 -0
  27. package/examples/rtc/bq32000/demo.js +77 -0
  28. package/examples/rtc/bq32000/minimal.js +20 -0
  29. package/examples/rtc/ds1307/complete.js +54 -0
  30. package/examples/rtc/ds1307/demo.js +96 -0
  31. package/examples/rtc/ds1307/minimal.js +20 -0
  32. package/examples/rtc/ds1371/complete.js +53 -0
  33. package/examples/rtc/ds1371/demo.js +85 -0
  34. package/examples/rtc/ds1371/minimal.js +25 -0
  35. package/package.json +1 -1
  36. package/src/chips/gas/rrh62000.js +418 -0
  37. package/src/chips/gas/scd30.js +368 -0
  38. package/src/chips/gas/scd40.js +451 -0
  39. package/src/chips/light/tsl2561.js +445 -0
  40. package/src/chips/light/tsl2591.js +561 -0
  41. package/src/chips/light/vcnl4040.js +576 -0
  42. package/src/chips/light/vcnl4200.js +592 -0
  43. package/src/chips/rfid/st25dv.js +628 -0
  44. package/src/chips/rtc/bq32000.js +334 -0
  45. package/src/chips/rtc/ds1307.js +327 -0
  46. package/src/chips/rtc/ds1371.js +453 -0
  47. package/src/discovery/registry.js +11 -11
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ // Minimal example: read proximity and ambient light five times a second
4
+ // (ALS 80 ms, PS 16 bit, duty 1/160, 50 mA IRED).
5
+
6
+ const { I2CConnection } = require('periph/src/connection/i2c');
7
+ const { VCNL4040Minimal } = require('periph/src/chips/light/vcnl4040');
8
+
9
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
10
+
11
+ (async () => {
12
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
13
+ const connection = new I2CConnection(bus, VCNL4040Minimal.I2C_ADDRESS);
14
+ const sensor = new VCNL4040Minimal(connection); // Create VCNL4040 driver, (connection)
15
+ await sensor.init(); // Run initialization sequence, () → void (checks ID, powers on ALS and PS)
16
+
17
+ for (let i = 0; i < 50; i++) {
18
+ const proximity = await sensor.readProximity(); // Read proximity, () → int counts
19
+ const lux = await sensor.readLux(); // Read ambient light, () → float lux
20
+ console.log(`proximity ${proximity} ${lux.toFixed(1)} lx`);
21
+ await sleep(200);
22
+ }
23
+
24
+ await connection.close();
25
+ })();
@@ -0,0 +1,101 @@
1
+ 'use strict';
2
+
3
+ // Complete example: exercise every method of VCNL4200Full — proximity, lux,
4
+ // raw ALS / white channels, ALS and PS configuration, thresholds,
5
+ // cancellation, active force, logic output, ID, status and interrupts.
6
+
7
+ const { I2CConnection } = require('periph/src/connection/i2c');
8
+ const { VCNL4200Full, alsSensitivity, alsMaxRange } = require('periph/src/chips/light/vcnl4200');
9
+
10
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
11
+
12
+ (async () => {
13
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
14
+ const connection = new I2CConnection(bus, VCNL4200Full.I2C_ADDRESS);
15
+ const sensor = new VCNL4200Full(connection); // Create VCNL4200 Full driver, (connection)
16
+ await sensor.init(); // Run initialization sequence, () → void
17
+ // checks ID 0x1058, ALS 50 ms on, PS 16 bit / duty 1/160 / 50 mA on
18
+
19
+ console.log((await sensor.deviceId()).toString(16)); // Read the ID register, () → int
20
+ // 0x1058 for the VCNL4200 (bits 11:8 = version code)
21
+ console.log(await sensor.readProximity()); // Read proximity, () → int counts
22
+ // PS_DATA; larger = closer
23
+ console.log(await sensor.readLux()); // Read ambient light, () → float lux
24
+ // ALS_DATA × sensitivity of the current integration time
25
+ console.log(await sensor.readAls()); // Read raw ALS, () → int counts
26
+ // ALS_DATA, 0–65535
27
+ console.log(await sensor.readWhite()); // Read raw white channel, () → int counts
28
+ // WHITE_DATA, 0–65535
29
+ console.log(alsSensitivity(400), alsMaxRange(400)); // ALS resolution / range, (milliseconds) → float
30
+ // 0.003 lx/count and 197 lx at 400 ms
31
+
32
+ await sensor.setAlsIntegrationTime(100); // ALS integration time, (milliseconds 50/100/200/400) → void
33
+ // 100 ms = 0.012 lx/count, 786 lx range
34
+ console.log(await sensor.getAlsIntegrationTime()); // ALS integration time, () → int ms
35
+ // read back from ALS_CONF
36
+ await sensor.setAlsPersistence(2); // ALS persistence, (count 1/2/4/8) → void
37
+ // consecutive results outside the window
38
+ await sensor.setAlsInterruptChannel(false); // ALS interrupt channel, (white) → void
39
+ // false = ALS channel, true = white channel
40
+ await sensor.setAlsThresholds(1000, 20000); // ALS window, (low, high counts 0–65535) → void
41
+ // counts = lux / sensitivity
42
+ console.log(await sensor.getAlsThresholds()); // ALS window, () → {low, high}
43
+ // ALS_THDL, ALS_THDH
44
+ await sensor.alsDisable(); // ALS off, () → void
45
+ // ALS_SD = 1
46
+ await sensor.alsEnable(); // ALS on, () → void
47
+ // ALS_SD = 0; next result after one integration
48
+
49
+ await sensor.setPsResolution(16); // PS resolution, (bits 12/16) → void
50
+ // set before the thresholds
51
+ await sensor.setPsDuty(160); // IRED duty, (ratio 160/320/640/1280) → void
52
+ // on/off ratio 1/160
53
+ await sensor.setPsIntegrationTime(2); // PS integration time, (t 1/1.5/2/4/8/9) → void
54
+ // in units of T
55
+ await sensor.setPsPersistence(2); // PS persistence, (count 1–4) → void
56
+ // consecutive hits for an interrupt
57
+ await sensor.setPsMultiPulse(2); // Multi-pulse, (count 1/2/4/8) → void
58
+ // IRED pulses per measurement
59
+ await sensor.setLedCurrent(100); // IRED current, (milliamperes 50–200) → void
60
+ // 50, 75, 100, 120, 140, 160, 180 or 200 mA
61
+ await sensor.setPsThresholds(1000, 3000); // PS window, (low away, high close) → void
62
+ // 0–4095 at 12 bit
63
+ console.log(await sensor.getPsThresholds()); // PS window, () → {low, high}
64
+ // PS_THDL, PS_THDH
65
+ await sensor.setPsCancellation(0); // Cancellation, (level 0–65535) → void
66
+ // subtracted from every PS result
67
+ await sensor.setPsSunlight(true); // Sunlight, (cancel, doubleImmunity=false, capability1_5x=false, outputFF=false) → void
68
+ // PS_SC_EN; the flags set PS_SC_ADV, PS_SP and PS_SPO
69
+ await sensor.setPsSmartPersistence(true); // Smart persistence, (on) → void
70
+ // faster response with persistence > 1
71
+ await sensor.psDisable(); // PS off, () → void
72
+ // PS_SD = 1
73
+ await sensor.psEnable(); // PS on, () → void
74
+ // PS_SD = 0
75
+
76
+ await sensor.setPsActiveForce(true); // Active-force mode, (on) → void
77
+ // PS measures only on trigger
78
+ console.log(await sensor.triggerPs()); // One PS measurement, () → int counts
79
+ // writes PS_TRIG, waits, reads PS_DATA
80
+ await sensor.setPsActiveForce(false);
81
+ await sensor.setPsLogicOutput(true); // Logic-output mode, (on) → void
82
+ // INT low while close, high once away
83
+ await sleep(1000);
84
+ await sensor.setPsLogicOutput(false);
85
+
86
+ console.log(await sensor.status()); // Interrupt flags, () → int
87
+ // INT_FLAG high byte; reading clears it
88
+ await sensor.enableInterrupt(VCNL4200Full.SOURCE_ALS_HIGH | VCNL4200Full.SOURCE_PS_CLOSE); // Enable sources, (source) → void
89
+ // ALS_INT_EN covers both ALS sources
90
+ console.log(await sensor.pollInterrupt()); // Pending flags, () → int
91
+ // reads and clears INT_FLAG
92
+ await sensor.onInterrupt((f) => console.log('interrupt', f.toString(16))); // Subscribe, (callback(flags), {intPin}) → void
93
+ // falling edge on INT, or poll every 100 ms
94
+ await sleep(10000);
95
+ await sensor.offInterrupt(); // Unsubscribe, () → void
96
+ await sensor.disableInterrupt(VCNL4200Full.SOURCE_ALS_HIGH | VCNL4200Full.SOURCE_ALS_LOW
97
+ | VCNL4200Full.SOURCE_PS_CLOSE | VCNL4200Full.SOURCE_PS_AWAY); // Disable sources, (source) → void
98
+ // clears ALS_INT_EN and PS_INT
99
+
100
+ await connection.close();
101
+ })();
@@ -0,0 +1,126 @@
1
+ 'use strict';
2
+
3
+ // Demo: presence-activated display light. Prints the ID and settings, reads
4
+ // proximity and lux every 0.2 s for 10 s, calibrates the cancellation with
5
+ // nothing in front of the sensor, reports close/away and room-light events
6
+ // for 15 s, steps through the ALS integration times, the PS resolutions and
7
+ // IRED currents, shows active-force mode and the logic output, then powers
8
+ // both sensors down.
9
+
10
+ const { I2CConnection } = require('periph/src/connection/i2c');
11
+ const { VCNL4200Full, alsSensitivity, alsMaxRange } = require('periph/src/chips/light/vcnl4200');
12
+
13
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
14
+ const S = VCNL4200Full;
15
+ const ALL = S.SOURCE_PS_CLOSE | S.SOURCE_PS_AWAY | S.SOURCE_ALS_HIGH | S.SOURCE_ALS_LOW;
16
+
17
+ (async () => {
18
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
19
+ const connection = new I2CConnection(bus, VCNL4200Full.I2C_ADDRESS);
20
+ const sensor = new VCNL4200Full(connection); // Create VCNL4200 Full driver, (connection)
21
+ await sensor.init(); // Run initialization sequence, () → void
22
+ console.log('ID 0x' + (await sensor.deviceId()).toString(16)); // Read the ID register, () → int
23
+ console.log('ALS integration', await sensor.getAlsIntegrationTime(), 'ms'); // ALS integration time, () → int ms
24
+
25
+ /* Live readings: move a hand towards the sensor. The proximity count
26
+ rises as more IRED light is reflected; the lux value follows the room. */
27
+ for (let i = 0; i < 50; i++) {
28
+ const p = await sensor.readProximity(); // Read proximity, () → int counts
29
+ const lx = await sensor.readLux(); // Read ambient light, () → float lux
30
+ const w = await sensor.readWhite(); // Read raw white channel, () → int counts
31
+ const a = await sensor.readAls(); // Read raw ALS, () → int counts
32
+ console.log(`proximity ${p} ${lx.toFixed(1)} lx white ${w} als ${a}`);
33
+ await sleep(200);
34
+ }
35
+
36
+ /* Calibrate the cancellation: with nothing in front of the sensor the
37
+ count is cross talk from the cover glass; subtracting it makes
38
+ "no target" read close to 0. */
39
+ console.log('remove any object in front of the sensor');
40
+ await sleep(3000);
41
+ let sum = 0;
42
+ for (let i = 0; i < 8; i++) sum += await sensor.readProximity();
43
+ await sensor.setPsCancellation(Math.floor(sum / 8)); // Cancellation, (level 0–65535) → void
44
+ console.log('cancellation level', Math.floor(sum / 8));
45
+
46
+ /* Close/away window: above the high threshold the PS reports "close",
47
+ below the low threshold "away"; persistence 2 ignores single noisy
48
+ samples and smart persistence keeps the response fast. The ALS window
49
+ reports a change of the room light. */
50
+ await sensor.setPsThresholds(300, 1000); // PS window, (low away, high close) → void
51
+ console.log('PS window', await sensor.getPsThresholds()); // PS window, () → {low, high}
52
+ await sensor.setPsPersistence(2); // PS persistence, (count 1–4) → void
53
+ await sensor.setPsSmartPersistence(true); // Smart persistence, (on) → void
54
+ await sensor.setPsSunlight(true, true); // Sunlight, (cancel, doubleImmunity, capability1_5x, outputFF) → void
55
+ const als = await sensor.readAls();
56
+ await sensor.setAlsThresholds(Math.floor(als / 2), Math.min(65535, als * 2)); // ALS window, (low, high counts) → void
57
+ console.log('ALS window', await sensor.getAlsThresholds()); // ALS window, () → {low, high}
58
+ await sensor.setAlsPersistence(4); // ALS persistence, (count 1/2/4/8) → void
59
+ await sensor.setAlsInterruptChannel(false); // ALS interrupt channel, (white) → void
60
+ await sensor.status(); // Interrupt flags, () → int (clears stale flags)
61
+ await sensor.enableInterrupt(ALL); // Enable sources, (source) → void
62
+ await sensor.onInterrupt(async (flags) => { // Subscribe, (callback(flags), {intPin}) → void
63
+ if (flags & S.SOURCE_PS_CLOSE) console.log('close: wake the display');
64
+ if (flags & S.SOURCE_PS_AWAY) console.log('away: dim the display');
65
+ if (flags & (S.SOURCE_ALS_HIGH | S.SOURCE_ALS_LOW)) console.log('room light changed');
66
+ if (flags & S.FLAG_SUNLIGHT_PROTECT) console.log('PS sunlight protection');
67
+ if (flags & S.FLAG_PS_SATURATED) console.log('PS saturated');
68
+ });
69
+ console.log('wave a hand in front of the sensor for 15 s');
70
+ await sleep(15000);
71
+ await sensor.offInterrupt(); // Unsubscribe, () → void
72
+ console.log('pending', await sensor.pollInterrupt()); // Pending flags, () → int
73
+ await sensor.disableInterrupt(ALL); // Disable sources, (source) → void
74
+
75
+ /* ALS integration times: longer integration gives finer resolution but a
76
+ smaller range. */
77
+ for (const ms of [50, 100, 200, 400]) {
78
+ await sensor.setAlsIntegrationTime(ms); // ALS integration time, (milliseconds) → void
79
+ await sleep(ms * 2);
80
+ console.log(`${ms} ms ${alsSensitivity(ms)} lx/count range ${alsMaxRange(ms).toFixed(1)} lx ${(await sensor.readLux()).toFixed(2)} lx`);
81
+ }
82
+ await sensor.setAlsIntegrationTime(50);
83
+
84
+ /* PS resolution and IRED current: 12-bit output saturates at 4095; a
85
+ higher IRED current reaches further but costs current (average = pulse
86
+ current × duty ratio). */
87
+ for (const bits of [12, 16]) {
88
+ await sensor.setPsResolution(bits); // PS resolution, (bits 12/16) → void
89
+ for (const ma of [50, 75, 100, 120, 140, 160, 180, 200]) {
90
+ await sensor.setLedCurrent(ma); // IRED current, (milliamperes) → void
91
+ await sleep(50);
92
+ console.log(`${bits} bit ${ma} mA proximity ${await sensor.readProximity()}`);
93
+ }
94
+ }
95
+ await sensor.setLedCurrent(50);
96
+ await sensor.setPsDuty(320); // IRED duty, (ratio 160/320/640/1280) → void
97
+ await sensor.setPsIntegrationTime(1.5); // PS integration time, (t) → void
98
+ await sensor.setPsMultiPulse(2); // Multi-pulse, (count 1/2/4/8) → void
99
+
100
+ /* Active force: the PS stays in standby and measures only when
101
+ triggered, the lowest-power way to sample proximity. */
102
+ await sensor.setPsActiveForce(true); // Active-force mode, (on) → void
103
+ for (let i = 0; i < 5; i++) {
104
+ console.log('triggered proximity', await sensor.triggerPs()); // One PS measurement, () → int counts
105
+ await sleep(500);
106
+ }
107
+ await sensor.setPsActiveForce(false);
108
+
109
+ /* Logic output: INT follows the close/away state directly, e.g. to gate
110
+ a backlight without the host. */
111
+ await sensor.setPsLogicOutput(true); // Logic-output mode, (on) → void
112
+ console.log('INT is now a close/away output for 5 s');
113
+ await sleep(5000);
114
+ await sensor.setPsLogicOutput(false);
115
+
116
+ /* Shut down: both sensors stop measuring; the IRED is off. */
117
+ await sensor.psDisable(); // PS off, () → void
118
+ await sensor.alsDisable(); // ALS off, () → void
119
+ await sensor.psEnable(); // PS on, () → void
120
+ await sensor.alsEnable(); // ALS on, () → void
121
+ await sensor.psDisable();
122
+ await sensor.alsDisable();
123
+ console.log('both sensors shut down');
124
+
125
+ await connection.close();
126
+ })();
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ // Minimal example: read proximity and ambient light five times a second
4
+ // (ALS 50 ms, PS 16 bit, duty 1/160, 50 mA IRED).
5
+
6
+ const { I2CConnection } = require('periph/src/connection/i2c');
7
+ const { VCNL4200Minimal } = require('periph/src/chips/light/vcnl4200');
8
+
9
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
10
+
11
+ (async () => {
12
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
13
+ const connection = new I2CConnection(bus, VCNL4200Minimal.I2C_ADDRESS);
14
+ const sensor = new VCNL4200Minimal(connection); // Create VCNL4200 driver, (connection)
15
+ await sensor.init(); // Run initialization sequence, () → void (checks ID, powers on ALS and PS)
16
+
17
+ for (let i = 0; i < 50; i++) {
18
+ const proximity = await sensor.readProximity(); // Read proximity, () → int counts
19
+ const lux = await sensor.readLux(); // Read ambient light, () → float lux
20
+ console.log(`proximity ${proximity} ${lux.toFixed(1)} lx`);
21
+ await sleep(200);
22
+ }
23
+
24
+ await connection.close();
25
+ })();
@@ -0,0 +1,94 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { ST25DVFull, ST25DVSource } = require('../../../src/chips/rfid/st25dv');
5
+
6
+ async function main() {
7
+ const user = new I2CConnection(1, 0x53, null, null, 2); // Create user-area connection, (bus=1, addr=0x53, intPin=null, enPin=null, regBytes=2) → Connection
8
+ const system = new I2CConnection(1, 0x57, null, null, 2); // Create system-area connection, (bus=1, addr=0x57, intPin=null, enPin=null, regBytes=2) → Connection
9
+ const tag = new ST25DVFull(user, system); // Create ST25DV driver, (user, system, gpoActiveHigh=false) → void
10
+ await tag.init(); // Read MEM_SIZE, BLK_SIZE, IC_REF, () → void
11
+ // derives the user memory size from the system area
12
+
13
+ console.log('Size:', tag.memorySize(), 'bytes'); // Get user memory size, () → number bytes
14
+ // (MEM_SIZE + 1) × (BLK_SIZE + 1)
15
+ console.log('IC_REF: 0x' + tag.icReference().toString(16)); // Get IC reference, () → number
16
+ // 0x24 = ST25DV04K, 0x26 = ST25DV16K/64K
17
+ console.log('UID:', (await tag.uid()).toString('hex')); // Read unique ID, () → Buffer (8)
18
+ // most significant byte first, starts with E0 02
19
+ console.log('IC_REV:', await tag.icRevision()); // Read IC revision, () → number
20
+ // IC_REV register 0x0020
21
+
22
+ await tag.write(0x0100, Buffer.from(Array.from({ length: 40 }, (_, i) => i))); // Write user memory, (address, data) → void
23
+ // split into 16-byte-aligned writes, ACK-polled each
24
+ console.log('Data:', (await tag.read(0x0100, 40)).toString('hex')); // Read user memory, (address, length) → Buffer
25
+ // 16-byte-aligned reads, retried while an RF reader holds the bus
26
+ await tag.waitWriteComplete(); // Wait for the write cycle, () → void
27
+ // ACK polling on 0x53
28
+
29
+ console.log('IT_TIME:', (await tag.readSystem(0x0001, 1))[0]); // Read system area, (address, length) → Buffer
30
+ // raw access to the static registers at 0x57
31
+ console.log('Session:', await tag.sessionOpen()); // Query I²C security session, () → boolean
32
+ // I2C_SSO_Dyn bit 0
33
+ console.log('Password OK:', await tag.presentPassword(Buffer.alloc(8))); // Present I²C password, (password 8 bytes) → boolean
34
+ // opens the session needed for system-area writes
35
+ await tag.writePassword(Buffer.alloc(8)); // Change I²C password, (password 8 bytes) → void
36
+ // here rewritten with the factory value
37
+ await tag.writeSystem(0x0001, 0x03); // Write system area, (address, data) → void
38
+ // IT_TIME back to its reset value, ACK-polled
39
+
40
+ await tag.setAreaEnd(1, tag.memorySize() / 32 - 1); // Set end of area 1-3, (area 1–3, endBlock 0–255) → void
41
+ // area n ends at byte endBlock × 32 + 31
42
+ await tag.setAreaProtection(1, 0x00, 0x00); // Set area protection, (area 1–4, rf 0–15, i2c 0–3) → void
43
+ // RFAnSS value and the area's I2CSS bits
44
+ console.log('Area 1 protection:', await tag.getAreaProtection(1)); // Get area protection, (area 1–4) → {rf, i2c}
45
+
46
+ await tag.setGpo(ST25DVFull.GPO_FIELD_CHANGE); // Write static GPO register, (sources, enable=true) → void
47
+ // the chip copies it into GPO_CTRL_Dyn
48
+ console.log('GPO: 0x' + (await tag.getGpo()).toString(16)); // Read static GPO register, () → number
49
+ await tag.setGpoRuntime(true); // Switch GPO output at runtime, (enable) → void
50
+ // GPO_CTRL_Dyn.GPO_EN, no session needed
51
+ await tag.setInterruptPulse(3); // Set GPO pulse duration, (value 0–7) → void
52
+ // 301 µs − value × 37.65 µs
53
+
54
+ console.log('Field present:', await tag.fieldPresent()); // Query RF field, () → boolean
55
+ // EH_CTRL_Dyn.FIELD_ON
56
+ await tag.setEnergyHarvesting(false); // Control energy harvesting, (enabled, forced=false) → void
57
+ // EH_EN now, EH_MODE written only when it changes
58
+ await tag.setRfState(); // Set RF interface state, (disable=false, sleep=false) → void
59
+ // runtime RF_MNGT_Dyn
60
+
61
+ await tag.enableMailbox(); // Enable fast transfer mode, () → void
62
+ // sets MB_MODE if needed, then MB_CTRL_Dyn.MB_EN
63
+ await tag.setMailboxWatchdog(0); // Set mailbox watchdog, (value 0–7) → void
64
+ // 2^(value−1) × 30 ms, 0 disables it
65
+ await tag.mailboxWrite(Buffer.from('ping')); // Put mailbox message, (data 1–256 bytes) → void
66
+ // single write starting at 0x2008
67
+ console.log('Mailbox:', await tag.mailboxStatus()); // Decode mailbox status, () → object
68
+ // enabled, hostPut, rfPut, hostMiss, rfMiss, …
69
+ console.log('Message:', (await tag.mailboxRead()).toString()); // Read mailbox message, () → Buffer
70
+ // MB_LEN_Dyn + 1 bytes, empty if no message
71
+ await tag.disableMailbox(); // Disable fast transfer mode, () → void
72
+ // clears MB_EN, which also drops the message
73
+
74
+ await tag.writeNdef([0xD1, 0x01, 0x05, 0x54, 0x02, 0x65, 0x6E, 0x48, 0x69, 0x21]); // Write NDEF message, (message) → void
75
+ // capability container + TLV 03 <len> … FE
76
+ console.log('NDEF:', (await tag.readNdef()).toString('hex')); // Read NDEF message, () → Buffer
77
+ // parses the CC and the first NDEF TLV
78
+ await tag.lockCcfile(false); // Lock CC file blocks, (lock=true) → void
79
+ // false keeps blocks 0/1 RF-writable
80
+
81
+ await tag.enableInterrupt(ST25DVSource.FIELD_RISING | ST25DVSource.RF_WRITE); // Enable interrupt sources, (source) → void
82
+ // static GPO register bits plus GPO_EN
83
+ await tag.onInterrupt((s) => console.log('GPO event: 0x' + s.toString(16))); // Subscribe to GPO events, (callback, intPin=null) → void
84
+ // 10 ms IT_STS_Dyn polling without a GPO pin
85
+ console.log('Pending: 0x' + (await tag.pollInterrupt()).toString(16)); // Read and clear IT_STS_Dyn, () → number
86
+ // ST25DVSource mask, 0 = none
87
+ await tag.offInterrupt(); // Unsubscribe, () → void
88
+ await tag.disableInterrupt(ST25DVSource.RF_WRITE); // Disable interrupt sources, (source) → void
89
+ // clears the matching GPO enable bits
90
+ user.close();
91
+ system.close();
92
+ }
93
+
94
+ main().catch(err => { console.error(err); process.exit(1); });
@@ -0,0 +1,121 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { ST25DVFull, ST25DVSource } = require('../../../src/chips/rfid/st25dv');
5
+
6
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
7
+
8
+ async function main() {
9
+ // --- Two connections, one chip ---
10
+ // The ST25DV answers on 0x53 (user memory, dynamic registers, mailbox) and on
11
+ // 0x57 (system configuration). Both use 16-bit register addresses.
12
+ const user = new I2CConnection(1, 0x53, null, null, 2); // Create user-area connection, (bus=1, addr=0x53, intPin=null, enPin=null, regBytes=2) → Connection
13
+ const system = new I2CConnection(1, 0x57, null, null, 2); // Create system-area connection, (bus=1, addr=0x57, intPin=null, enPin=null, regBytes=2) → Connection
14
+ const tag = new ST25DVFull(user, system); // Create ST25DV driver, (user, system, gpoActiveHigh=false) → void
15
+ await tag.init(); // Read MEM_SIZE, BLK_SIZE, IC_REF, () → void
16
+
17
+ // --- Identify the tag ---
18
+ // IC_REF tells the 04K apart from the 16K/64K; the size comes from MEM_SIZE.
19
+ console.log('IC_REF 0x' + tag.icReference().toString(16), 'revision', await tag.icRevision()); // Get IC reference, () → number ; Read IC revision, () → number
20
+ console.log('UID', (await tag.uid()).toString('hex'), '-', tag.memorySize(), 'bytes'); // Read unique ID, () → Buffer (8) ; Get user memory size, () → number bytes
21
+
22
+ // --- NDEF text record a phone can read ---
23
+ // Record header D1 (MB/ME/SR, well-known), type 'T', status 02 (language "en").
24
+ const text = Buffer.from('Hello from Periph');
25
+ const record = Buffer.concat([Buffer.from([0xD1, 0x01, 3 + text.length, 0x54, 0x02]), Buffer.from('en'), text]);
26
+ await tag.writeNdef(record); // Write NDEF message, (message) → void
27
+ console.log('NDEF read back:', (await tag.readNdef()).equals(record)); // Read NDEF message, () → Buffer
28
+
29
+ // --- Raw bytes across a 256-byte page boundary ---
30
+ // The driver splits the write into 16-byte-aligned pieces and ACK-polls each.
31
+ const saved = await tag.read(0x00F8, 32); // Read user memory, (address, length) → Buffer
32
+ const pattern = Buffer.from(Array.from({ length: 32 }, (_, i) => 0x40 + i));
33
+ await tag.write(0x00F8, pattern); // Write user memory, (address, data) → void
34
+ await tag.waitWriteComplete(); // Wait for the write cycle, () → void
35
+ console.log('Page-crossing write ok:', (await tag.read(0x00F8, 32)).equals(pattern)); // Read user memory, (address, length) → Buffer
36
+ await tag.write(0x00F8, saved); // Write user memory, (address, data) → void
37
+
38
+ // --- Password session and two memory areas ---
39
+ // Area 1 = first 1 KiB (stays open), area 2 = the rest: RF writes need RF
40
+ // password 1, I2C writes need the I2C session. The factory I2C password is 0.
41
+ const pwd = Buffer.alloc(8);
42
+ console.log('Session before:', await tag.sessionOpen()); // Query I²C security session, () → boolean
43
+ console.log('Password accepted:', await tag.presentPassword(pwd)); // Present I²C password, (password 8 bytes) → boolean
44
+ const end1 = Math.min(tag.memorySize(), 1024) / 32 - 1;
45
+ const last = tag.memorySize() / 32 - 1;
46
+ await tag.setAreaEnd(1, end1); // Set end of area 1-3, (area 1–3, endBlock 0–255) → void
47
+ await tag.setAreaEnd(2, last); // Set end of area 1-3, (area 1–3, endBlock 0–255) → void
48
+ await tag.setAreaEnd(3, last); // Set end of area 1-3, (area 1–3, endBlock 0–255) → void
49
+ await tag.setAreaProtection(2, 0x05, 0x01); // Set area protection, (area 1–4, rf 0–15, i2c 0–3) → void
50
+ console.log('Area 2 protection:', await tag.getAreaProtection(2)); // Get area protection, (area 1–4) → {rf, i2c}
51
+
52
+ // --- Change and restore the I2C password ---
53
+ const newPwd = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0]);
54
+ await tag.writePassword(newPwd); // Change I²C password, (password 8 bytes) → void
55
+ console.log('New password accepted:', await tag.presentPassword(newPwd)); // Present I²C password, (password 8 bytes) → boolean
56
+ await tag.writePassword(pwd); // Change I²C password, (password 8 bytes) → void
57
+ console.log('Factory password restored:', await tag.presentPassword(pwd)); // Present I²C password, (password 8 bytes) → boolean
58
+
59
+ // --- GPO events while a phone approaches ---
60
+ // Field change and RF write events pulse GPO; without a GPO pin the driver
61
+ // polls IT_STS_Dyn every 10 ms. Hold a phone to the antenna now.
62
+ await tag.setInterruptPulse(3); // Set GPO pulse duration, (value 0–7) → void
63
+ await tag.setGpo(ST25DVFull.GPO_FIELD_CHANGE); // Write static GPO register, (sources, enable=true) → void
64
+ await tag.enableInterrupt(ST25DVSource.FIELD_RISING | ST25DVSource.RF_WRITE); // Enable interrupt sources, (source) → void
65
+ console.log('GPO register: 0x' + (await tag.getGpo()).toString(16)); // Read static GPO register, () → number
66
+ console.log('Pending before: 0x' + (await tag.pollInterrupt()).toString(16)); // Read and clear IT_STS_Dyn, () → number
67
+ await tag.onInterrupt((status) => { // Subscribe to GPO events, (callback, intPin=null) → void
68
+ const names = [];
69
+ if (status & ST25DVSource.FIELD_RISING) names.push('field on');
70
+ if (status & ST25DVSource.FIELD_FALLING) names.push('field off');
71
+ if (status & ST25DVSource.RF_WRITE) names.push('RF write');
72
+ console.log(' GPO event:', names.join(', ') || '0x' + status.toString(16));
73
+ });
74
+ for (let i = 0; i < 10; i++) {
75
+ console.log(' field present:', await tag.fieldPresent()); // Query RF field, () → boolean
76
+ await sleep(1000);
77
+ }
78
+ await tag.offInterrupt(); // Unsubscribe, () → void
79
+ await tag.disableInterrupt(ST25DVSource.RF_WRITE); // Disable interrupt sources, (source) → void
80
+
81
+ // --- Fast transfer mode: host <-> phone mailbox ---
82
+ // The host puts a message; an RF reader (e.g. the ST25 app) reads it and can
83
+ // answer. The watchdog releases an unread message after 2^(7-1) x 30 ms.
84
+ await tag.enableMailbox(); // Enable fast transfer mode, () → void
85
+ await tag.setMailboxWatchdog(7); // Set mailbox watchdog, (value 0–7) → void
86
+ await tag.mailboxWrite(Buffer.from('hello reader')); // Put mailbox message, (data 1–256 bytes) → void
87
+ for (let i = 0; i < 10; i++) {
88
+ const st = await tag.mailboxStatus(); // Decode mailbox status, () → object
89
+ if (st.rfPut) {
90
+ console.log('Reader says:', (await tag.mailboxRead()).toString()); // Read mailbox message, () → Buffer
91
+ break;
92
+ }
93
+ console.log(' mailbox:', st);
94
+ await sleep(1000);
95
+ }
96
+ await tag.disableMailbox(); // Disable fast transfer mode, () → void
97
+
98
+ // --- Energy harvesting and RF state ---
99
+ await tag.setEnergyHarvesting(true); // Control energy harvesting, (enabled, forced=false) → void
100
+ await sleep(1000);
101
+ await tag.setEnergyHarvesting(false); // Control energy harvesting, (enabled, forced=false) → void
102
+ await tag.setRfState(false, true); // Set RF interface state, (disable=false, sleep=false) → void
103
+ console.log('RF asleep: a phone no longer sees the tag');
104
+ await sleep(2000);
105
+ await tag.setRfState(); // Set RF interface state, (disable=false, sleep=false) → void
106
+
107
+ // --- Restore the delivery defaults ---
108
+ // One area, no protection, field-change GPO only, mailbox off, CC unlocked.
109
+ await tag.setAreaProtection(2, 0x00, 0x00); // Set area protection, (area 1–4, rf 0–15, i2c 0–3) → void
110
+ await tag.setAreaEnd(1, last); // Set end of area 1-3, (area 1–3, endBlock 0–255) → void
111
+ await tag.setGpo(ST25DVFull.GPO_FIELD_CHANGE); // Write static GPO register, (sources, enable=true) → void
112
+ await tag.setGpoRuntime(true); // Switch GPO output at runtime, (enable) → void
113
+ await tag.writeSystem(0x000D, 0x00); // Write system area, (address, data) → void
114
+ console.log('MB_MODE:', (await tag.readSystem(0x000D, 1))[0]); // Read system area, (address, length) → Buffer
115
+ await tag.lockCcfile(false); // Lock CC file blocks, (lock=true) → void
116
+ console.log('Done.');
117
+ user.close();
118
+ system.close();
119
+ }
120
+
121
+ main().catch(err => { console.error(err); process.exit(1); });
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('../../../src/connection/i2c');
4
+ const { ST25DVMinimal } = require('../../../src/chips/rfid/st25dv');
5
+
6
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
7
+
8
+ async function main() {
9
+ const user = new I2CConnection(1, 0x53, null, null, 2); // Create user-area connection, (bus=1, addr=0x53, intPin=null, enPin=null, regBytes=2) → Connection
10
+ const system = new I2CConnection(1, 0x57, null, null, 2); // Create system-area connection, (bus=1, addr=0x57, intPin=null, enPin=null, regBytes=2) → Connection
11
+ const tag = new ST25DVMinimal(user, system); // Create ST25DV driver, (user, system, gpoActiveHigh=false) → void
12
+ await tag.init(); // Read MEM_SIZE, BLK_SIZE, IC_REF, () → void
13
+
14
+ await tag.write(0x0100, Buffer.from('Hello NFC')); // Write user memory, (address, data) → void
15
+ for (;;) {
16
+ console.log('Memory:', (await tag.read(0x0100, 9)).toString()); // Read user memory, (address, length) → Buffer
17
+ await sleep(1000);
18
+ }
19
+ }
20
+
21
+ main().catch(err => { console.error(err); process.exit(1); });
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ const { I2CConnection } = require('periph/src/connection/i2c');
4
+ const { BQ32000Full } = require('periph/src/chips/rtc/bq32000');
5
+
6
+ (async () => {
7
+ const bus = parseInt(process.env.I2C_BUS || '1', 10);
8
+ const connection = new I2CConnection(bus, 0x68);
9
+ const rtc = new BQ32000Full(connection); // Create BQ32000 Full driver, (connection)
10
+ await rtc.init(); // Confirm presence, () → None
11
+ // reads the clock registers once, no writes
12
+
13
+ await rtc.setDatetime(2026, 11, 28, 6, 14, 30, 0); // Set the calendar clock, (year 2000–2099, month, day, weekday 0=Sun, hour, minute, second) → None
14
+ // one 7-byte write; STOP = 0, OF = 0, century off
15
+ const dt = await rtc.getDatetime(); // Read the calendar clock, () → {year, month, day, weekday, hour, minute, second}
16
+ // decodes the seven BCD registers 0x00–0x06
17
+ const failed = await rtc.oscillatorFailed(); // Query oscillator-fail flag, () → bool
18
+ // true after the first power-up or a crystal dropout
19
+ await rtc.clearOscillatorFail(); // Clear oscillator-fail flag, () → None
20
+ // read-modify-write of MINUTES bit 7
21
+ await rtc.stopOscillator(); // Stop the oscillator, () → None
22
+ // STOP = 1, the clock no longer advances
23
+ await rtc.startOscillator(); // Start the oscillator, () → None
24
+ // STOP = 0; 1 then 0 force-starts a fresh chip
25
+
26
+ await rtc.setCentury(true, 0); // Write century bits, (enable, century=0) → None
27
+ // CENT toggles when the year rolls 99 → 00
28
+ const century = await rtc.getCentury(); // Read century bits, () → {enabled, century}
29
+
30
+ await rtc.setCalibration(12.2); // Set calibration, (ppm −126.5…+63.5) → None
31
+ // nearest step: CAL = 6, S = 0 → +12.21 ppm (slows the RTC)
32
+ const ppm = await rtc.getCalibration(); // Read calibration, () → ppm
33
+
34
+ await rtc.setCalibrationOutput(1); // Output test signal on IRQ, (hz 512|1|null) → None
35
+ // 1 Hz includes the ppm adjustment (SF key sequence for FTF)
36
+ await rtc.setCalibrationOutput(null); // Turn the test signal off, (null) → None
37
+ await rtc.setIrq(true); // Drive IRQ as a level, (level) → None
38
+ // FT = 0, OUT = 1: open drain released (pull-up to VCC)
39
+
40
+ await rtc.enableTrickleCharge(false); // Enable trickle charger, (fetBypass=false) → None
41
+ // supercap only — never with a primary coin cell
42
+ await rtc.disableTrickleCharge(); // Disable trickle charger, () → None
43
+ // TCHE = 0xA, TCH2 = 0, TCFE = 0
44
+
45
+ const cfg1 = await rtc.readRegister(0x07); // Read raw register, (reg 0x00–0x09) → int
46
+ await rtc.writeRegister(0x07, cfg1); // Write raw register, (reg 0x00–0x09, value) → None
47
+ // reserved bits of 0x08/0x09 are preserved
48
+
49
+ console.log(dt, `oscillatorFailed=${failed}`);
50
+ console.log('century', century, `calibration ${ppm.toFixed(2)} ppm`, `CAL_CFG1=0x${cfg1.toString(16).padStart(2, '0')}`);
51
+
52
+ await connection.close();
53
+ })();