node-red-contrib-periph-memory 1.4.0 → 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 +6 -0
- package/examples/at24c02n/demo.json +78 -0
- package/examples/at24c64/demo.json +78 -0
- package/examples/cat24c512/demo.json +78 -0
- package/nodes/at24c02n/at24c02n.html +89 -0
- package/nodes/at24c02n/at24c02n.js +62 -0
- package/nodes/at24c64/at24c64.html +89 -0
- package/nodes/at24c64/at24c64.js +62 -0
- package/nodes/cat24c512/cat24c512.html +89 -0
- package/nodes/cat24c512/cat24c512.js +62 -0
- package/package.json +6 -3
package/README.md
CHANGED
|
@@ -20,6 +20,12 @@ npm install node-red-contrib-periph-memory
|
|
|
20
20
|
| `23x1024` | input | Reads, writes and fills a 23LC1024 / 23A1024 1-Mbit (128 KiB) SPI serial SRAM, and selects its operating mode. |
|
|
21
21
|
| `24aa02uid-device` | config | I²C bus and address for a 24AA02UID |
|
|
22
22
|
| `24aa02uid` | input | Reads the factory-programmed 32-bit unique serial number from a 24AA02UID EEPROM, or reads / writes user EEPROM bytes, over I²C. |
|
|
23
|
+
| `at24c02n-device` | config | I²C bus and address for an AT24C02N |
|
|
24
|
+
| `periph-at24c02n` | input | Reads, writes and fills the 256 B EEPROM of an AT24C02N over I²C. Writes are split at 8-byte page boundaries and ACK-polled until each write cycle (5 ms max) has finished. |
|
|
25
|
+
| `at24c64-device` | config | I²C bus and address for an AT24C64 |
|
|
26
|
+
| `periph-at24c64` | input | Reads, writes and fills the 8 KiB EEPROM of an AT24C64 over I²C. Writes are split at 32-byte page boundaries and ACK-polled until each write cycle (10 ms max (20 ms at 1.8 V)) has finished. |
|
|
27
|
+
| `cat24c512-device` | config | I²C bus and address for a CAT24C512 |
|
|
28
|
+
| `periph-cat24c512` | input | Reads, writes and fills the 64 KiB EEPROM of a CAT24C512 over I²C. Writes are split at 128-byte page boundaries and ACK-polled until each write cycle (5 ms max) has finished. |
|
|
23
29
|
| `mb85rc-device` | config | I²C bus and address for a MB85RC |
|
|
24
30
|
| `periph-mb85rc` | input | Reads, writes and fills the 32 KiB non-volatile FRAM of an MB85RC256V over I²C. FRAM writes complete at bus speed — no write delay, no page limit. |
|
|
25
31
|
| `mx25l12845e-device` | config | Bus configuration for a MX25L12845E |
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "tab-at24c02n-demo",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "AT24C02N Boot Counter",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "Demonstrates non-volatile EEPROM state. Every 5 seconds a function node reads a 4-byte big-endian counter at address 0x0000 through periph-at24c02n, increments it and writes it back (page-split and ACK-polled by the driver). The Debug node shows the counter, which survives a Node-RED restart or power loss."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "cfg-at24c02n",
|
|
11
|
+
"type": "at24c02n-device",
|
|
12
|
+
"name": "AT24C02N",
|
|
13
|
+
"bus": "1",
|
|
14
|
+
"address": "50"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"id": "inj-tick",
|
|
18
|
+
"type": "inject",
|
|
19
|
+
"name": "every 5 s",
|
|
20
|
+
"repeat": "5",
|
|
21
|
+
"crontab": "",
|
|
22
|
+
"once": true,
|
|
23
|
+
"onceDelay": 0.1,
|
|
24
|
+
"topic": "",
|
|
25
|
+
"payload": "",
|
|
26
|
+
"payloadType": "date",
|
|
27
|
+
"z": "tab-at24c02n-demo",
|
|
28
|
+
"x": 130,
|
|
29
|
+
"y": 120,
|
|
30
|
+
"wires": [["rd"]]
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"id": "rd",
|
|
34
|
+
"type": "periph-at24c02n",
|
|
35
|
+
"name": "Read counter",
|
|
36
|
+
"device": "cfg-at24c02n",
|
|
37
|
+
"z": "tab-at24c02n-demo",
|
|
38
|
+
"x": 310,
|
|
39
|
+
"y": 120,
|
|
40
|
+
"wires": [["inc"]]
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"id": "inc",
|
|
44
|
+
"type": "function",
|
|
45
|
+
"name": "increment",
|
|
46
|
+
"func": "const d = msg.payload.data || [0, 0, 0, 0];\nconst n = (((d[0] << 24) >>> 0) + (d[1] << 16) + (d[2] << 8) + d[3] + 1) >>> 0;\nmsg.count = n;\nmsg.payload = { op: 'write', address: 0, data: [(n >>> 24) & 255, (n >>> 16) & 255, (n >>> 8) & 255, n & 255] };\nreturn msg;",
|
|
47
|
+
"outputs": 1,
|
|
48
|
+
"z": "tab-at24c02n-demo",
|
|
49
|
+
"x": 490,
|
|
50
|
+
"y": 120,
|
|
51
|
+
"wires": [["wr"]]
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"id": "wr",
|
|
55
|
+
"type": "periph-at24c02n",
|
|
56
|
+
"name": "Write counter",
|
|
57
|
+
"device": "cfg-at24c02n",
|
|
58
|
+
"z": "tab-at24c02n-demo",
|
|
59
|
+
"x": 670,
|
|
60
|
+
"y": 120,
|
|
61
|
+
"wires": [["dbg"]]
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"id": "dbg",
|
|
65
|
+
"type": "debug",
|
|
66
|
+
"name": "Counter",
|
|
67
|
+
"active": true,
|
|
68
|
+
"tosidebar": true,
|
|
69
|
+
"console": false,
|
|
70
|
+
"tostatus": false,
|
|
71
|
+
"complete": "count",
|
|
72
|
+
"targetType": "msg",
|
|
73
|
+
"z": "tab-at24c02n-demo",
|
|
74
|
+
"x": 850,
|
|
75
|
+
"y": 120,
|
|
76
|
+
"wires": []
|
|
77
|
+
}
|
|
78
|
+
]
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "tab-at24c64-demo",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "AT24C64 Boot Counter",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "Demonstrates non-volatile EEPROM state. Every 5 seconds a function node reads a 4-byte big-endian counter at address 0x0000 through periph-at24c64, increments it and writes it back (page-split and ACK-polled by the driver). The Debug node shows the counter, which survives a Node-RED restart or power loss."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "cfg-at24c64",
|
|
11
|
+
"type": "at24c64-device",
|
|
12
|
+
"name": "AT24C64",
|
|
13
|
+
"bus": "1",
|
|
14
|
+
"address": "50"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"id": "inj-tick",
|
|
18
|
+
"type": "inject",
|
|
19
|
+
"name": "every 5 s",
|
|
20
|
+
"repeat": "5",
|
|
21
|
+
"crontab": "",
|
|
22
|
+
"once": true,
|
|
23
|
+
"onceDelay": 0.1,
|
|
24
|
+
"topic": "",
|
|
25
|
+
"payload": "",
|
|
26
|
+
"payloadType": "date",
|
|
27
|
+
"z": "tab-at24c64-demo",
|
|
28
|
+
"x": 130,
|
|
29
|
+
"y": 120,
|
|
30
|
+
"wires": [["rd"]]
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"id": "rd",
|
|
34
|
+
"type": "periph-at24c64",
|
|
35
|
+
"name": "Read counter",
|
|
36
|
+
"device": "cfg-at24c64",
|
|
37
|
+
"z": "tab-at24c64-demo",
|
|
38
|
+
"x": 310,
|
|
39
|
+
"y": 120,
|
|
40
|
+
"wires": [["inc"]]
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"id": "inc",
|
|
44
|
+
"type": "function",
|
|
45
|
+
"name": "increment",
|
|
46
|
+
"func": "const d = msg.payload.data || [0, 0, 0, 0];\nconst n = (((d[0] << 24) >>> 0) + (d[1] << 16) + (d[2] << 8) + d[3] + 1) >>> 0;\nmsg.count = n;\nmsg.payload = { op: 'write', address: 0, data: [(n >>> 24) & 255, (n >>> 16) & 255, (n >>> 8) & 255, n & 255] };\nreturn msg;",
|
|
47
|
+
"outputs": 1,
|
|
48
|
+
"z": "tab-at24c64-demo",
|
|
49
|
+
"x": 490,
|
|
50
|
+
"y": 120,
|
|
51
|
+
"wires": [["wr"]]
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"id": "wr",
|
|
55
|
+
"type": "periph-at24c64",
|
|
56
|
+
"name": "Write counter",
|
|
57
|
+
"device": "cfg-at24c64",
|
|
58
|
+
"z": "tab-at24c64-demo",
|
|
59
|
+
"x": 670,
|
|
60
|
+
"y": 120,
|
|
61
|
+
"wires": [["dbg"]]
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"id": "dbg",
|
|
65
|
+
"type": "debug",
|
|
66
|
+
"name": "Counter",
|
|
67
|
+
"active": true,
|
|
68
|
+
"tosidebar": true,
|
|
69
|
+
"console": false,
|
|
70
|
+
"tostatus": false,
|
|
71
|
+
"complete": "count",
|
|
72
|
+
"targetType": "msg",
|
|
73
|
+
"z": "tab-at24c64-demo",
|
|
74
|
+
"x": 850,
|
|
75
|
+
"y": 120,
|
|
76
|
+
"wires": []
|
|
77
|
+
}
|
|
78
|
+
]
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"id": "tab-cat24c512-demo",
|
|
4
|
+
"type": "tab",
|
|
5
|
+
"label": "CAT24C512 Boot Counter",
|
|
6
|
+
"disabled": false,
|
|
7
|
+
"info": "Demonstrates non-volatile EEPROM state. Every 5 seconds a function node reads a 4-byte big-endian counter at address 0x0000 through periph-cat24c512, increments it and writes it back (page-split and ACK-polled by the driver). The Debug node shows the counter, which survives a Node-RED restart or power loss."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"id": "cfg-cat24c512",
|
|
11
|
+
"type": "cat24c512-device",
|
|
12
|
+
"name": "CAT24C512",
|
|
13
|
+
"bus": "1",
|
|
14
|
+
"address": "50"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"id": "inj-tick",
|
|
18
|
+
"type": "inject",
|
|
19
|
+
"name": "every 5 s",
|
|
20
|
+
"repeat": "5",
|
|
21
|
+
"crontab": "",
|
|
22
|
+
"once": true,
|
|
23
|
+
"onceDelay": 0.1,
|
|
24
|
+
"topic": "",
|
|
25
|
+
"payload": "",
|
|
26
|
+
"payloadType": "date",
|
|
27
|
+
"z": "tab-cat24c512-demo",
|
|
28
|
+
"x": 130,
|
|
29
|
+
"y": 120,
|
|
30
|
+
"wires": [["rd"]]
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"id": "rd",
|
|
34
|
+
"type": "periph-cat24c512",
|
|
35
|
+
"name": "Read counter",
|
|
36
|
+
"device": "cfg-cat24c512",
|
|
37
|
+
"z": "tab-cat24c512-demo",
|
|
38
|
+
"x": 310,
|
|
39
|
+
"y": 120,
|
|
40
|
+
"wires": [["inc"]]
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
"id": "inc",
|
|
44
|
+
"type": "function",
|
|
45
|
+
"name": "increment",
|
|
46
|
+
"func": "const d = msg.payload.data || [0, 0, 0, 0];\nconst n = (((d[0] << 24) >>> 0) + (d[1] << 16) + (d[2] << 8) + d[3] + 1) >>> 0;\nmsg.count = n;\nmsg.payload = { op: 'write', address: 0, data: [(n >>> 24) & 255, (n >>> 16) & 255, (n >>> 8) & 255, n & 255] };\nreturn msg;",
|
|
47
|
+
"outputs": 1,
|
|
48
|
+
"z": "tab-cat24c512-demo",
|
|
49
|
+
"x": 490,
|
|
50
|
+
"y": 120,
|
|
51
|
+
"wires": [["wr"]]
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"id": "wr",
|
|
55
|
+
"type": "periph-cat24c512",
|
|
56
|
+
"name": "Write counter",
|
|
57
|
+
"device": "cfg-cat24c512",
|
|
58
|
+
"z": "tab-cat24c512-demo",
|
|
59
|
+
"x": 670,
|
|
60
|
+
"y": 120,
|
|
61
|
+
"wires": [["dbg"]]
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"id": "dbg",
|
|
65
|
+
"type": "debug",
|
|
66
|
+
"name": "Counter",
|
|
67
|
+
"active": true,
|
|
68
|
+
"tosidebar": true,
|
|
69
|
+
"console": false,
|
|
70
|
+
"tostatus": false,
|
|
71
|
+
"complete": "count",
|
|
72
|
+
"targetType": "msg",
|
|
73
|
+
"z": "tab-cat24c512-demo",
|
|
74
|
+
"x": 850,
|
|
75
|
+
"y": 120,
|
|
76
|
+
"wires": []
|
|
77
|
+
}
|
|
78
|
+
]
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('at24c02n-device', {
|
|
4
|
+
category: 'config',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '50', required: true }
|
|
9
|
+
},
|
|
10
|
+
label: function() {
|
|
11
|
+
return this.name || ('AT24C02N @ 0x' + this.address + ' (bus ' + this.bus + ')');
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<script type="text/html" data-template-name="at24c02n-device">
|
|
17
|
+
<div class="form-row">
|
|
18
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
19
|
+
<input type="text" id="node-config-input-name" placeholder="AT24C02N">
|
|
20
|
+
</div>
|
|
21
|
+
<div class="form-row">
|
|
22
|
+
<label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
23
|
+
<input type="number" id="node-config-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
24
|
+
</div>
|
|
25
|
+
<div class="form-row">
|
|
26
|
+
<label for="node-config-input-address">Address (hex)</label>
|
|
27
|
+
<input type="text" id="node-config-input-address" placeholder="50" style="width:80px"> 50–57 (A2:A0 pins), default 50
|
|
28
|
+
</div>
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<!-- EEPROM node: trigger → read / write / fill -->
|
|
32
|
+
<script type="text/javascript">
|
|
33
|
+
RED.nodes.registerType('periph-at24c02n', {
|
|
34
|
+
category: 'Peripheral',
|
|
35
|
+
color: '#C084FC',
|
|
36
|
+
defaults: {
|
|
37
|
+
name: { value: '' },
|
|
38
|
+
device: { value: '', type: 'at24c02n-device', required: true }
|
|
39
|
+
},
|
|
40
|
+
inputs: 1,
|
|
41
|
+
outputs: 1,
|
|
42
|
+
icon: 'font-awesome/fa-database',
|
|
43
|
+
label: function() { return this.name || 'AT24C02N'; },
|
|
44
|
+
paletteLabel: 'AT24C02N'
|
|
45
|
+
});
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<script type="text/html" data-template-name="periph-at24c02n">
|
|
49
|
+
<div class="form-row">
|
|
50
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
51
|
+
<input type="text" id="node-input-device">
|
|
52
|
+
</div>
|
|
53
|
+
<div class="form-row">
|
|
54
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
55
|
+
<input type="text" id="node-input-name" placeholder="AT24C02N">
|
|
56
|
+
</div>
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<script type="text/html" data-help-name="periph-at24c02n">
|
|
60
|
+
<p>Reads, writes and fills the 256 B EEPROM of an AT24C02N over I²C. Writes are split at
|
|
61
|
+
8-byte page boundaries and ACK-polled until each write cycle (5 ms max) has finished.</p>
|
|
62
|
+
<p>The device is configured via an <b>at24c02n-device</b> config node.</p>
|
|
63
|
+
|
|
64
|
+
<h3>Inputs</h3>
|
|
65
|
+
<dl class="message-properties">
|
|
66
|
+
<dt>payload.op <span class="property-type">string</span></dt>
|
|
67
|
+
<dd><code>read</code> (default), <code>write</code>, or <code>fill</code>.</dd>
|
|
68
|
+
<dt>payload.address <span class="property-type">number</span></dt>
|
|
69
|
+
<dd>Start address 0–255. Ranges that would pass 0x00FF are rejected.</dd>
|
|
70
|
+
<dt>payload.length <span class="property-type">number</span></dt>
|
|
71
|
+
<dd>Number of bytes (<code>read</code>, <code>fill</code>).</dd>
|
|
72
|
+
<dt>payload.data <span class="property-type">array of numbers</span></dt>
|
|
73
|
+
<dd>Bytes to write (<code>write</code>).</dd>
|
|
74
|
+
<dt>payload.value <span class="property-type">number</span></dt>
|
|
75
|
+
<dd>Fill byte, default 0 (<code>fill</code>).</dd>
|
|
76
|
+
</dl>
|
|
77
|
+
|
|
78
|
+
<h3>Outputs</h3>
|
|
79
|
+
<dl class="message-properties">
|
|
80
|
+
<dt>payload.data <span class="property-type">array of numbers</span></dt>
|
|
81
|
+
<dd>Bytes read. <code>read</code> only.</dd>
|
|
82
|
+
<dt>payload.ok <span class="property-type">boolean</span></dt>
|
|
83
|
+
<dd>True on success. <code>write</code> and <code>fill</code> only.</dd>
|
|
84
|
+
</dl>
|
|
85
|
+
|
|
86
|
+
<h3>Configuration</h3>
|
|
87
|
+
<p>Set the I²C bus number and the chip address (<code>0x50</code>–<code>0x57</code>,
|
|
88
|
+
selected by pins A2:A0; default <code>0x50</code>) in the device config node.</p>
|
|
89
|
+
</script>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { AT24C02NFull } = require('periph/src/chips/memory/at24c02n');
|
|
6
|
+
|
|
7
|
+
function AT24C02NDeviceNode(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
const connection = new I2CConnection(parseInt(config.bus), parseInt(config.address, 16));
|
|
12
|
+
node.driver = new AT24C02NFull(connection);
|
|
13
|
+
node.connection = connection;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
node.error('AT24C02N init failed: ' + e.message);
|
|
16
|
+
}
|
|
17
|
+
node.on('close', function() {
|
|
18
|
+
if (node.connection) node.connection.close();
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
RED.nodes.registerType('at24c02n-device', AT24C02NDeviceNode);
|
|
22
|
+
|
|
23
|
+
function AT24C02NNode(config) {
|
|
24
|
+
RED.nodes.createNode(this, config);
|
|
25
|
+
const node = this;
|
|
26
|
+
node.device = RED.nodes.getNode(config.device);
|
|
27
|
+
|
|
28
|
+
node.on('input', async function(msg, send, done) {
|
|
29
|
+
if (!node.device || !node.device.driver) {
|
|
30
|
+
node.error('No AT24C02N device configured', msg);
|
|
31
|
+
done();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const d = node.device.driver;
|
|
36
|
+
const p = (msg.payload && typeof msg.payload === 'object' && !Array.isArray(msg.payload)) ? msg.payload : {};
|
|
37
|
+
const pick = (k, dflt) => (p[k] != null) ? p[k] : (msg[k] != null ? msg[k] : dflt);
|
|
38
|
+
const op = pick('op', 'read');
|
|
39
|
+
const address = pick('address', 0);
|
|
40
|
+
if (op === 'read') {
|
|
41
|
+
const data = await d.read(address, pick('length', 1));
|
|
42
|
+
msg.payload = { data: Array.from(data) };
|
|
43
|
+
} else if (op === 'write') {
|
|
44
|
+
await d.write(address, Buffer.from(pick('data', [])));
|
|
45
|
+
msg.payload = { ok: true };
|
|
46
|
+
} else if (op === 'fill') {
|
|
47
|
+
await d.fill(address, pick('length', 0), pick('value', 0));
|
|
48
|
+
msg.payload = { ok: true };
|
|
49
|
+
} else {
|
|
50
|
+
node.error('Unknown op: ' + op, msg);
|
|
51
|
+
done();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
send(msg);
|
|
55
|
+
done();
|
|
56
|
+
} catch (e) {
|
|
57
|
+
done(e);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
RED.nodes.registerType('periph-at24c02n', AT24C02NNode);
|
|
62
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('at24c64-device', {
|
|
4
|
+
category: 'config',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '50', required: true }
|
|
9
|
+
},
|
|
10
|
+
label: function() {
|
|
11
|
+
return this.name || ('AT24C64 @ 0x' + this.address + ' (bus ' + this.bus + ')');
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<script type="text/html" data-template-name="at24c64-device">
|
|
17
|
+
<div class="form-row">
|
|
18
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
19
|
+
<input type="text" id="node-config-input-name" placeholder="AT24C64">
|
|
20
|
+
</div>
|
|
21
|
+
<div class="form-row">
|
|
22
|
+
<label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
23
|
+
<input type="number" id="node-config-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
24
|
+
</div>
|
|
25
|
+
<div class="form-row">
|
|
26
|
+
<label for="node-config-input-address">Address (hex)</label>
|
|
27
|
+
<input type="text" id="node-config-input-address" placeholder="50" style="width:80px"> 50–57 (A2:A0 pins), default 50
|
|
28
|
+
</div>
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<!-- EEPROM node: trigger → read / write / fill -->
|
|
32
|
+
<script type="text/javascript">
|
|
33
|
+
RED.nodes.registerType('periph-at24c64', {
|
|
34
|
+
category: 'Peripheral',
|
|
35
|
+
color: '#C084FC',
|
|
36
|
+
defaults: {
|
|
37
|
+
name: { value: '' },
|
|
38
|
+
device: { value: '', type: 'at24c64-device', required: true }
|
|
39
|
+
},
|
|
40
|
+
inputs: 1,
|
|
41
|
+
outputs: 1,
|
|
42
|
+
icon: 'font-awesome/fa-database',
|
|
43
|
+
label: function() { return this.name || 'AT24C64'; },
|
|
44
|
+
paletteLabel: 'AT24C64'
|
|
45
|
+
});
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<script type="text/html" data-template-name="periph-at24c64">
|
|
49
|
+
<div class="form-row">
|
|
50
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
51
|
+
<input type="text" id="node-input-device">
|
|
52
|
+
</div>
|
|
53
|
+
<div class="form-row">
|
|
54
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
55
|
+
<input type="text" id="node-input-name" placeholder="AT24C64">
|
|
56
|
+
</div>
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<script type="text/html" data-help-name="periph-at24c64">
|
|
60
|
+
<p>Reads, writes and fills the 8 KiB EEPROM of an AT24C64 over I²C. Writes are split at
|
|
61
|
+
32-byte page boundaries and ACK-polled until each write cycle (10 ms max (20 ms at 1.8 V)) has finished.</p>
|
|
62
|
+
<p>The device is configured via an <b>at24c64-device</b> config node.</p>
|
|
63
|
+
|
|
64
|
+
<h3>Inputs</h3>
|
|
65
|
+
<dl class="message-properties">
|
|
66
|
+
<dt>payload.op <span class="property-type">string</span></dt>
|
|
67
|
+
<dd><code>read</code> (default), <code>write</code>, or <code>fill</code>.</dd>
|
|
68
|
+
<dt>payload.address <span class="property-type">number</span></dt>
|
|
69
|
+
<dd>Start address 0–8191. Ranges that would pass 0x1FFF are rejected.</dd>
|
|
70
|
+
<dt>payload.length <span class="property-type">number</span></dt>
|
|
71
|
+
<dd>Number of bytes (<code>read</code>, <code>fill</code>).</dd>
|
|
72
|
+
<dt>payload.data <span class="property-type">array of numbers</span></dt>
|
|
73
|
+
<dd>Bytes to write (<code>write</code>).</dd>
|
|
74
|
+
<dt>payload.value <span class="property-type">number</span></dt>
|
|
75
|
+
<dd>Fill byte, default 0 (<code>fill</code>).</dd>
|
|
76
|
+
</dl>
|
|
77
|
+
|
|
78
|
+
<h3>Outputs</h3>
|
|
79
|
+
<dl class="message-properties">
|
|
80
|
+
<dt>payload.data <span class="property-type">array of numbers</span></dt>
|
|
81
|
+
<dd>Bytes read. <code>read</code> only.</dd>
|
|
82
|
+
<dt>payload.ok <span class="property-type">boolean</span></dt>
|
|
83
|
+
<dd>True on success. <code>write</code> and <code>fill</code> only.</dd>
|
|
84
|
+
</dl>
|
|
85
|
+
|
|
86
|
+
<h3>Configuration</h3>
|
|
87
|
+
<p>Set the I²C bus number and the chip address (<code>0x50</code>–<code>0x57</code>,
|
|
88
|
+
selected by pins A2:A0; default <code>0x50</code>) in the device config node.</p>
|
|
89
|
+
</script>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { AT24C64Full } = require('periph/src/chips/memory/at24c64');
|
|
6
|
+
|
|
7
|
+
function AT24C64DeviceNode(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
const connection = new I2CConnection(parseInt(config.bus), parseInt(config.address, 16), null, null, 2);
|
|
12
|
+
node.driver = new AT24C64Full(connection);
|
|
13
|
+
node.connection = connection;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
node.error('AT24C64 init failed: ' + e.message);
|
|
16
|
+
}
|
|
17
|
+
node.on('close', function() {
|
|
18
|
+
if (node.connection) node.connection.close();
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
RED.nodes.registerType('at24c64-device', AT24C64DeviceNode);
|
|
22
|
+
|
|
23
|
+
function AT24C64Node(config) {
|
|
24
|
+
RED.nodes.createNode(this, config);
|
|
25
|
+
const node = this;
|
|
26
|
+
node.device = RED.nodes.getNode(config.device);
|
|
27
|
+
|
|
28
|
+
node.on('input', async function(msg, send, done) {
|
|
29
|
+
if (!node.device || !node.device.driver) {
|
|
30
|
+
node.error('No AT24C64 device configured', msg);
|
|
31
|
+
done();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const d = node.device.driver;
|
|
36
|
+
const p = (msg.payload && typeof msg.payload === 'object' && !Array.isArray(msg.payload)) ? msg.payload : {};
|
|
37
|
+
const pick = (k, dflt) => (p[k] != null) ? p[k] : (msg[k] != null ? msg[k] : dflt);
|
|
38
|
+
const op = pick('op', 'read');
|
|
39
|
+
const address = pick('address', 0);
|
|
40
|
+
if (op === 'read') {
|
|
41
|
+
const data = await d.read(address, pick('length', 1));
|
|
42
|
+
msg.payload = { data: Array.from(data) };
|
|
43
|
+
} else if (op === 'write') {
|
|
44
|
+
await d.write(address, Buffer.from(pick('data', [])));
|
|
45
|
+
msg.payload = { ok: true };
|
|
46
|
+
} else if (op === 'fill') {
|
|
47
|
+
await d.fill(address, pick('length', 0), pick('value', 0));
|
|
48
|
+
msg.payload = { ok: true };
|
|
49
|
+
} else {
|
|
50
|
+
node.error('Unknown op: ' + op, msg);
|
|
51
|
+
done();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
send(msg);
|
|
55
|
+
done();
|
|
56
|
+
} catch (e) {
|
|
57
|
+
done(e);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
RED.nodes.registerType('periph-at24c64', AT24C64Node);
|
|
62
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<!-- Config node: one instance per physical device -->
|
|
2
|
+
<script type="text/javascript">
|
|
3
|
+
RED.nodes.registerType('cat24c512-device', {
|
|
4
|
+
category: 'config',
|
|
5
|
+
defaults: {
|
|
6
|
+
name: { value: '' },
|
|
7
|
+
bus: { value: '1', required: true, validate: RED.validators.number() },
|
|
8
|
+
address: { value: '50', required: true }
|
|
9
|
+
},
|
|
10
|
+
label: function() {
|
|
11
|
+
return this.name || ('CAT24C512 @ 0x' + this.address + ' (bus ' + this.bus + ')');
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<script type="text/html" data-template-name="cat24c512-device">
|
|
17
|
+
<div class="form-row">
|
|
18
|
+
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
19
|
+
<input type="text" id="node-config-input-name" placeholder="CAT24C512">
|
|
20
|
+
</div>
|
|
21
|
+
<div class="form-row">
|
|
22
|
+
<label for="node-config-input-bus"><i class="fa fa-microchip"></i> I²C bus</label>
|
|
23
|
+
<input type="number" id="node-config-input-bus" min="0" style="width:80px"> (Linux /dev/i2c-N)
|
|
24
|
+
</div>
|
|
25
|
+
<div class="form-row">
|
|
26
|
+
<label for="node-config-input-address">Address (hex)</label>
|
|
27
|
+
<input type="text" id="node-config-input-address" placeholder="50" style="width:80px"> 50–57 (A2:A0 pins), default 50
|
|
28
|
+
</div>
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<!-- EEPROM node: trigger → read / write / fill -->
|
|
32
|
+
<script type="text/javascript">
|
|
33
|
+
RED.nodes.registerType('periph-cat24c512', {
|
|
34
|
+
category: 'Peripheral',
|
|
35
|
+
color: '#C084FC',
|
|
36
|
+
defaults: {
|
|
37
|
+
name: { value: '' },
|
|
38
|
+
device: { value: '', type: 'cat24c512-device', required: true }
|
|
39
|
+
},
|
|
40
|
+
inputs: 1,
|
|
41
|
+
outputs: 1,
|
|
42
|
+
icon: 'font-awesome/fa-database',
|
|
43
|
+
label: function() { return this.name || 'CAT24C512'; },
|
|
44
|
+
paletteLabel: 'CAT24C512'
|
|
45
|
+
});
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<script type="text/html" data-template-name="periph-cat24c512">
|
|
49
|
+
<div class="form-row">
|
|
50
|
+
<label for="node-input-device"><i class="fa fa-microchip"></i> Device</label>
|
|
51
|
+
<input type="text" id="node-input-device">
|
|
52
|
+
</div>
|
|
53
|
+
<div class="form-row">
|
|
54
|
+
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
|
55
|
+
<input type="text" id="node-input-name" placeholder="CAT24C512">
|
|
56
|
+
</div>
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<script type="text/html" data-help-name="periph-cat24c512">
|
|
60
|
+
<p>Reads, writes and fills the 64 KiB EEPROM of a CAT24C512 over I²C. Writes are split at
|
|
61
|
+
128-byte page boundaries and ACK-polled until each write cycle (5 ms max) has finished.</p>
|
|
62
|
+
<p>The device is configured via an <b>cat24c512-device</b> config node.</p>
|
|
63
|
+
|
|
64
|
+
<h3>Inputs</h3>
|
|
65
|
+
<dl class="message-properties">
|
|
66
|
+
<dt>payload.op <span class="property-type">string</span></dt>
|
|
67
|
+
<dd><code>read</code> (default), <code>write</code>, or <code>fill</code>.</dd>
|
|
68
|
+
<dt>payload.address <span class="property-type">number</span></dt>
|
|
69
|
+
<dd>Start address 0–65535. Ranges that would pass 0xFFFF are rejected.</dd>
|
|
70
|
+
<dt>payload.length <span class="property-type">number</span></dt>
|
|
71
|
+
<dd>Number of bytes (<code>read</code>, <code>fill</code>).</dd>
|
|
72
|
+
<dt>payload.data <span class="property-type">array of numbers</span></dt>
|
|
73
|
+
<dd>Bytes to write (<code>write</code>).</dd>
|
|
74
|
+
<dt>payload.value <span class="property-type">number</span></dt>
|
|
75
|
+
<dd>Fill byte, default 0 (<code>fill</code>).</dd>
|
|
76
|
+
</dl>
|
|
77
|
+
|
|
78
|
+
<h3>Outputs</h3>
|
|
79
|
+
<dl class="message-properties">
|
|
80
|
+
<dt>payload.data <span class="property-type">array of numbers</span></dt>
|
|
81
|
+
<dd>Bytes read. <code>read</code> only.</dd>
|
|
82
|
+
<dt>payload.ok <span class="property-type">boolean</span></dt>
|
|
83
|
+
<dd>True on success. <code>write</code> and <code>fill</code> only.</dd>
|
|
84
|
+
</dl>
|
|
85
|
+
|
|
86
|
+
<h3>Configuration</h3>
|
|
87
|
+
<p>Set the I²C bus number and the chip address (<code>0x50</code>–<code>0x57</code>,
|
|
88
|
+
selected by pins A2:A0; default <code>0x50</code>) in the device config node.</p>
|
|
89
|
+
</script>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function(RED) {
|
|
4
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
5
|
+
const { CAT24C512Full } = require('periph/src/chips/memory/cat24c512');
|
|
6
|
+
|
|
7
|
+
function CAT24C512DeviceNode(config) {
|
|
8
|
+
RED.nodes.createNode(this, config);
|
|
9
|
+
const node = this;
|
|
10
|
+
try {
|
|
11
|
+
const connection = new I2CConnection(parseInt(config.bus), parseInt(config.address, 16), null, null, 2);
|
|
12
|
+
node.driver = new CAT24C512Full(connection);
|
|
13
|
+
node.connection = connection;
|
|
14
|
+
} catch (e) {
|
|
15
|
+
node.error('CAT24C512 init failed: ' + e.message);
|
|
16
|
+
}
|
|
17
|
+
node.on('close', function() {
|
|
18
|
+
if (node.connection) node.connection.close();
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
RED.nodes.registerType('cat24c512-device', CAT24C512DeviceNode);
|
|
22
|
+
|
|
23
|
+
function CAT24C512Node(config) {
|
|
24
|
+
RED.nodes.createNode(this, config);
|
|
25
|
+
const node = this;
|
|
26
|
+
node.device = RED.nodes.getNode(config.device);
|
|
27
|
+
|
|
28
|
+
node.on('input', async function(msg, send, done) {
|
|
29
|
+
if (!node.device || !node.device.driver) {
|
|
30
|
+
node.error('No CAT24C512 device configured', msg);
|
|
31
|
+
done();
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const d = node.device.driver;
|
|
36
|
+
const p = (msg.payload && typeof msg.payload === 'object' && !Array.isArray(msg.payload)) ? msg.payload : {};
|
|
37
|
+
const pick = (k, dflt) => (p[k] != null) ? p[k] : (msg[k] != null ? msg[k] : dflt);
|
|
38
|
+
const op = pick('op', 'read');
|
|
39
|
+
const address = pick('address', 0);
|
|
40
|
+
if (op === 'read') {
|
|
41
|
+
const data = await d.read(address, pick('length', 1));
|
|
42
|
+
msg.payload = { data: Array.from(data) };
|
|
43
|
+
} else if (op === 'write') {
|
|
44
|
+
await d.write(address, Buffer.from(pick('data', [])));
|
|
45
|
+
msg.payload = { ok: true };
|
|
46
|
+
} else if (op === 'fill') {
|
|
47
|
+
await d.fill(address, pick('length', 0), pick('value', 0));
|
|
48
|
+
msg.payload = { ok: true };
|
|
49
|
+
} else {
|
|
50
|
+
node.error('Unknown op: ' + op, msg);
|
|
51
|
+
done();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
send(msg);
|
|
55
|
+
done();
|
|
56
|
+
} catch (e) {
|
|
57
|
+
done(e);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
RED.nodes.registerType('periph-cat24c512', CAT24C512Node);
|
|
62
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-periph-memory",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "Node-RED nodes for memory chips",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node-red",
|
|
@@ -17,9 +17,12 @@
|
|
|
17
17
|
"nodes": {
|
|
18
18
|
"23x1024": "nodes/23x1024/23x1024.js",
|
|
19
19
|
"24aa02uid": "nodes/24aa02uid/24aa02uid.js",
|
|
20
|
-
"
|
|
20
|
+
"at24c02n": "nodes/at24c02n/at24c02n.js",
|
|
21
|
+
"at24c64": "nodes/at24c64/at24c64.js",
|
|
22
|
+
"cat24c512": "nodes/cat24c512/cat24c512.js",
|
|
23
|
+
"mb85rc": "nodes/mb85rc/mb85rc.js",
|
|
21
24
|
"mx25l12845e": "nodes/mx25l12845e/mx25l12845e.js",
|
|
22
|
-
"
|
|
25
|
+
"sd_spi": "nodes/sd_spi/sd_spi.js"
|
|
23
26
|
}
|
|
24
27
|
},
|
|
25
28
|
"dependencies": {
|