node-red-contrib-periph-memory 1.3.1 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,6 +20,8 @@ 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
+ | `mb85rc-device` | config | I²C bus and address for a MB85RC |
24
+ | `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. |
23
25
  | `mx25l12845e-device` | config | Bus configuration for a MX25L12845E |
24
26
  | `mx25l12845e` | input | Reads, writes and erases the 16 MiB Macronix MX25L12845E SPI NOR flash by byte address. Writes are erase-aware: the node erases a 4 KiB sector itself when bits must go from 0 to 1, and keeps the other bytes of that sector. There is no filesystem. |
25
27
  | `sd-spi-device` | config | Bus configuration for a SD-SPI |
@@ -0,0 +1,78 @@
1
+ [
2
+ {
3
+ "id": "tab-mb85rc-demo",
4
+ "type": "tab",
5
+ "label": "MB85RC Boot Counter",
6
+ "disabled": false,
7
+ "info": "Demonstrates non-volatile FRAM state. Every 5 seconds a function node reads a 4-byte big-endian counter at address 0x0000 through periph-mb85rc, increments it and writes it back (no write delay needed). The Debug node shows the counter, which survives a Node-RED restart or power loss."
8
+ },
9
+ {
10
+ "id": "cfg-mb85rc",
11
+ "type": "mb85rc-device",
12
+ "name": "MB85RC",
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-mb85rc-demo",
28
+ "x": 130,
29
+ "y": 120,
30
+ "wires": [["rd"]]
31
+ },
32
+ {
33
+ "id": "rd",
34
+ "type": "periph-mb85rc",
35
+ "name": "Read counter",
36
+ "device": "cfg-mb85rc",
37
+ "z": "tab-mb85rc-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-mb85rc-demo",
49
+ "x": 490,
50
+ "y": 120,
51
+ "wires": [["wr"]]
52
+ },
53
+ {
54
+ "id": "wr",
55
+ "type": "periph-mb85rc",
56
+ "name": "Write counter",
57
+ "device": "cfg-mb85rc",
58
+ "z": "tab-mb85rc-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-mb85rc-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('mb85rc-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 || ('MB85RC @ 0x' + this.address + ' (bus ' + this.bus + ')');
12
+ }
13
+ });
14
+ </script>
15
+
16
+ <script type="text/html" data-template-name="mb85rc-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="MB85RC">
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"> &nbsp;(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"> &nbsp;50–57 (A2:A0 pins), default 50
28
+ </div>
29
+ </script>
30
+
31
+ <!-- FRAM node: trigger → read / write / fill -->
32
+ <script type="text/javascript">
33
+ RED.nodes.registerType('periph-mb85rc', {
34
+ category: 'Peripheral',
35
+ color: '#C084FC',
36
+ defaults: {
37
+ name: { value: '' },
38
+ device: { value: '', type: 'mb85rc-device', required: true }
39
+ },
40
+ inputs: 1,
41
+ outputs: 1,
42
+ icon: 'font-awesome/fa-database',
43
+ label: function() { return this.name || 'MB85RC'; },
44
+ paletteLabel: 'MB85RC'
45
+ });
46
+ </script>
47
+
48
+ <script type="text/html" data-template-name="periph-mb85rc">
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="MB85RC">
56
+ </div>
57
+ </script>
58
+
59
+ <script type="text/html" data-help-name="periph-mb85rc">
60
+ <p>Reads, writes and fills the 32 KiB non-volatile FRAM of an MB85RC256V over I²C.
61
+ FRAM writes complete at bus speed — no write delay, no page limit.</p>
62
+ <p>The device is configured via an <b>mb85rc-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–32767. Ranges that would pass 0x7FFF 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 { MB85RCFull } = require('periph/src/chips/memory/mb85rc');
6
+
7
+ function MB85RCDeviceNode(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 MB85RCFull(connection);
13
+ node.connection = connection;
14
+ } catch (e) {
15
+ node.error('MB85RC init failed: ' + e.message);
16
+ }
17
+ node.on('close', function() {
18
+ if (node.connection) node.connection.close();
19
+ });
20
+ }
21
+ RED.nodes.registerType('mb85rc-device', MB85RCDeviceNode);
22
+
23
+ function MB85RCNode(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 MB85RC 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-mb85rc', MB85RCNode);
62
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-periph-memory",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "Node-RED nodes for memory chips",
5
5
  "keywords": [
6
6
  "node-red",
@@ -18,7 +18,8 @@
18
18
  "23x1024": "nodes/23x1024/23x1024.js",
19
19
  "24aa02uid": "nodes/24aa02uid/24aa02uid.js",
20
20
  "sd_spi": "nodes/sd_spi/sd_spi.js",
21
- "mx25l12845e": "nodes/mx25l12845e/mx25l12845e.js"
21
+ "mx25l12845e": "nodes/mx25l12845e/mx25l12845e.js",
22
+ "mb85rc": "nodes/mb85rc/mb85rc.js"
22
23
  }
23
24
  },
24
25
  "dependencies": {