periph 1.3.2 → 1.4.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 +27 -0
- package/examples/accelerometer/bma180/complete.js +83 -0
- package/examples/accelerometer/bma180/demo.js +47 -0
- package/examples/accelerometer/bma180/minimal.js +21 -0
- package/examples/accelerometer/fxos8700/complete.js +111 -0
- package/examples/accelerometer/fxos8700/demo.js +80 -0
- package/examples/accelerometer/fxos8700/minimal.js +20 -0
- package/examples/accelerometer/lis3dh/complete.js +123 -0
- package/examples/accelerometer/lis3dh/demo.js +99 -0
- package/examples/accelerometer/lis3dh/minimal.js +19 -0
- package/examples/accelerometer/lsm303/complete.js +82 -0
- package/examples/accelerometer/lsm303/demo.js +96 -0
- package/examples/accelerometer/lsm303/minimal.js +23 -0
- package/examples/accelerometer/mma8451q/complete.js +96 -0
- package/examples/accelerometer/mma8451q/demo.js +120 -0
- package/examples/accelerometer/mma8451q/minimal.js +20 -0
- package/examples/adc_dac/ad5243/complete.js +52 -0
- package/examples/adc_dac/ad5243/demo.js +50 -0
- package/examples/adc_dac/ad5243/minimal.js +23 -0
- package/examples/adc_dac/ad5248/complete.js +49 -0
- package/examples/adc_dac/ad5248/demo.js +42 -0
- package/examples/adc_dac/ad5248/minimal.js +21 -0
- package/examples/adc_dac/ads1013/complete.js +51 -0
- package/examples/adc_dac/ads1013/demo.js +51 -0
- package/examples/adc_dac/ads1013/minimal.js +21 -0
- package/examples/adc_dac/ads1014/complete.js +88 -0
- package/examples/adc_dac/ads1014/demo.js +52 -0
- package/examples/adc_dac/ads1014/minimal.js +21 -0
- package/examples/adc_dac/ads1113/complete.js +47 -0
- package/examples/adc_dac/ads1113/demo.js +39 -0
- package/examples/adc_dac/ads1113/minimal.js +20 -0
- package/examples/adc_dac/ads1114/complete.js +77 -0
- package/examples/adc_dac/ads1114/demo.js +47 -0
- package/examples/adc_dac/ads1114/minimal.js +20 -0
- package/examples/adc_dac/ads1115/complete.js +82 -0
- package/examples/adc_dac/ads1115/demo.js +55 -0
- package/examples/adc_dac/ads1115/minimal.js +20 -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/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/pcf8578/complete.js +58 -0
- package/examples/display/pcf8578/demo.js +62 -0
- package/examples/display/pcf8578/minimal.js +19 -0
- package/examples/display/pcf8579/complete.js +58 -0
- package/examples/display/pcf8579/demo.js +61 -0
- package/examples/display/pcf8579/minimal.js +19 -0
- package/examples/imu/icm20948/complete.js +114 -0
- package/examples/imu/icm20948/demo.js +79 -0
- package/examples/imu/icm20948/minimal.js +22 -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/mcp23008/complete.js +70 -0
- package/examples/io_expander/mcp23008/demo.js +58 -0
- package/examples/io_expander/mcp23008/minimal.js +20 -0
- package/examples/memory/mb85rc/complete.js +40 -0
- package/examples/memory/mb85rc/demo.js +58 -0
- package/examples/memory/mb85rc/minimal.js +15 -0
- package/examples/motor/drv2605/complete.js +100 -0
- package/examples/motor/drv2605/demo.js +55 -0
- package/examples/motor/drv2605/minimal.js +24 -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/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/package.json +1 -1
- package/src/chips/accelerometer/bma180.js +573 -0
- package/src/chips/accelerometer/fxos8700.js +1600 -0
- package/src/chips/accelerometer/lis3dh.js +1341 -0
- package/src/chips/accelerometer/lsm303.js +1471 -0
- package/src/chips/accelerometer/mma8451q.js +1406 -0
- package/src/chips/adc_dac/_ads111x_base.js +272 -0
- package/src/chips/adc_dac/ad5243.js +231 -0
- package/src/chips/adc_dac/ad5248.js +194 -0
- package/src/chips/adc_dac/ads1013.js +219 -0
- package/src/chips/adc_dac/ads1014.js +509 -0
- package/src/chips/adc_dac/ads1113.js +112 -0
- package/src/chips/adc_dac/ads1114.js +201 -0
- package/src/chips/adc_dac/ads1115.js +232 -0
- package/src/chips/adc_dac/es8311.js +621 -0
- package/src/chips/adc_dac/mcp4xxx.js +982 -0
- package/src/chips/display/pcf8578.js +452 -0
- package/src/chips/display/pcf8579.js +451 -0
- package/src/chips/imu/icm20948.js +849 -0
- package/src/chips/imu/qmi8658a.js +1011 -0
- package/src/chips/io_expander/mcp23008.js +558 -0
- package/src/chips/memory/mb85rc.js +166 -0
- package/src/chips/motor/drv2605.js +592 -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/power/axp2101.js +968 -0
- package/src/chips/rtc/pcf85063a.js +482 -0
- package/src/connection/uart.js +9 -0
- package/src/connection/uart_mock.js +65 -0
- package/src/discovery/registry.js +45 -19
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Complete example for the AXP2101 — exercise every method in the public API.
|
|
4
|
+
// Rail setters are called with the values just read so the board keeps running;
|
|
5
|
+
// destructive commands are guarded by ENABLE_DANGEROUS.
|
|
6
|
+
|
|
7
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
8
|
+
const { AXP2101Full } = require('periph/src/chips/power/axp2101');
|
|
9
|
+
|
|
10
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
11
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x34', 16);
|
|
12
|
+
|
|
13
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
14
|
+
const chip = new AXP2101Full(connection); // Create AXP2101 Full driver, (connection)
|
|
15
|
+
|
|
16
|
+
(async () => {
|
|
17
|
+
await chip.ready; // Wait for init, () → Promise
|
|
18
|
+
// runs the init sequence: bus check, ADC channels on, fuel gauge on
|
|
19
|
+
const onSrc = await chip.powerOnSource(); // Power on source, () → number
|
|
20
|
+
// PWRON_STATUS flags: key, IRQ pin, VBUS, battery
|
|
21
|
+
const offSrc = await chip.powerOffSource(); // Power off source, () → number
|
|
22
|
+
// PWROFF_STATUS flags: why the PMIC last powered off
|
|
23
|
+
const vbus = await chip.vbusVoltage(); // Vbus voltage, () → number V
|
|
24
|
+
// VBUS ADC channel, 1 mV per LSB
|
|
25
|
+
const vsys = await chip.systemVoltage(); // System voltage, () → number V
|
|
26
|
+
// VSYS ADC channel, 1 mV per LSB
|
|
27
|
+
const ts = await chip.tsVoltage(); // Ts voltage, () → number V
|
|
28
|
+
// TS pin ADC channel, 0.5 mV per LSB
|
|
29
|
+
const tdie = await chip.dieTemperature(); // Die temperature, () → number °C
|
|
30
|
+
// die-temperature channel, vendor formula (verify on hardware)
|
|
31
|
+
const snapshot = await chip.readAll(); // Read all, () → object
|
|
32
|
+
// one call returns every measurement plus charge state and VBUS flag
|
|
33
|
+
const flags = await chip.status(); // Status, () → object
|
|
34
|
+
// decodes STATUS1 / STATUS2 into named flags
|
|
35
|
+
await chip.setAdcChannels(true, true, true, true, true, false); // Set adc channels, (vbat=True, ts=True, vbus=True, vsys=True, tdie=True, gpadc=False) →
|
|
36
|
+
// ADC_ENABLE channel mask; GPADC stays off
|
|
37
|
+
await chip.setAdcLowFrequency(false); // Set adc low frequency, (enabled) →
|
|
38
|
+
// TS_H bit 7: slow 64 s sampling only when powered off on battery
|
|
39
|
+
await chip.setCharging(true); // Set charging, (enabled) →
|
|
40
|
+
// MODULE_ENABLE bit 1: main-cell charging
|
|
41
|
+
await chip.setChargeVoltage(4.2); // Set charge voltage, (volts 4.0/4.1/4.2/4.35/4.4) →
|
|
42
|
+
// CV register; 4.35 / 4.4 V are for high-voltage cells only
|
|
43
|
+
await chip.setChargeCurrent(0.5); // Set charge current, (amps 0–1.5) →
|
|
44
|
+
// ICC: 25 mA steps up to 0.2 A, 100 mA steps above; capped by the charge voltage
|
|
45
|
+
await chip.setPrechargeCurrent(0.125); // Set precharge current, (amps 0–0.2) →
|
|
46
|
+
// IPRECHG in 25 mA steps
|
|
47
|
+
await chip.setTermination(0.125, true); // Set termination, (amps 0–0.2, enabled=True) →
|
|
48
|
+
// ITERM current in 25 mA steps plus the enable bit
|
|
49
|
+
await chip.setInputCurrentLimit(1.5); // Set input current limit, (amps 0.1/0.5/0.9/1.0/1.5/2.0) →
|
|
50
|
+
// IINLIM: input current limit
|
|
51
|
+
await chip.setInputVoltageLimit(4.36); // Set input voltage limit, (volts 3.88–5.08) →
|
|
52
|
+
// VINDPM in 80 mV steps
|
|
53
|
+
await chip.setMinSystemVoltage(3.7); // Set min system voltage, (volts 3.2–3.9) →
|
|
54
|
+
// MIN_VSYS in 100 mV steps
|
|
55
|
+
await chip.setChargeTimers(60, 12, true, true, true); // Set charge timers, (precharge_min=60, done_hours=12, precharge_enabled=True, done_enabled=True, slow_in_dpm=True) →
|
|
56
|
+
// CHG_TIMER: pre-charge 40–70 min, charge-done 5–20 h
|
|
57
|
+
await chip.setThermalRegulation(100); // Set thermal regulation, (celsius 60/80/100/120) →
|
|
58
|
+
// THERMAL_REG: charger thermal-regulation threshold
|
|
59
|
+
await chip.setDieProtection(125, true); // Set die protection, (level1_celsius=125, detect=True) →
|
|
60
|
+
// DIE_TEMP_CTRL: die over-temperature level 1 and detection
|
|
61
|
+
await chip.setBatteryDetection(true); // Set battery detection, (enabled) →
|
|
62
|
+
// BAT_DETECT bit 0
|
|
63
|
+
await chip.setBackupCharging(false, 2.9); // Set backup charging, (enabled, volts=2.9 V) →
|
|
64
|
+
// MODULE_ENABLE bit 2 and BTN_BAT_VTERM for the coin cell
|
|
65
|
+
await chip.setChgled('type_a', 'hiz'); // Set chgled, (mode='type_a', output='hiz') →
|
|
66
|
+
// CHGLED_CTRL: charge indicator behaviour
|
|
67
|
+
await chip.configureTs(true, 50, 'when_adc'); // Configure ts, (battery_sensor=True, current_ua=50 µA, source='when_adc') →
|
|
68
|
+
// TS_CTRL: thermistor mode, injected current and source mode
|
|
69
|
+
await chip.setTsLimits(1.312, 0.176, 1.984, 0.152); // Set ts limits, (charge_cold, charge_hot, work_cold, work_hot) → V
|
|
70
|
+
// VLTF/VHTF thresholds as TS voltages (32 mV / 2 mV steps)
|
|
71
|
+
await chip.setTsHysteresis(0.032, 0.004); // Set ts hysteresis, (low_to_normal=0.032 V, high_to_normal=0.004 V) →
|
|
72
|
+
// TS_HYS_L2H (16 mV steps) and TS_HYS_H2L (4 mV steps)
|
|
73
|
+
await chip.configureJeita(false, null, null, true, false, 0, 1); // Configure jeita, (enabled, cool_voltage=None, warm_voltage=None, cool_half_current=True, warm_half_current=False, cool_voltage_drop=0, warm_voltage_drop=1) →
|
|
74
|
+
// JEITA profile; thresholds are left unchanged when None
|
|
75
|
+
const [enabled, volts] = await chip.getRail('aldo1'); // Get rail, (name) → [boolean, number V]
|
|
76
|
+
// enable bit and programmed voltage of one rail
|
|
77
|
+
await chip.setRailVoltage('aldo1', volts); // Set rail voltage, (name, volts) → V
|
|
78
|
+
// rounds to the nearest step inside the rail range; raises outside it
|
|
79
|
+
await chip.setRailEnabled('aldo1', enabled); // Set rail enabled, (name, enabled) →
|
|
80
|
+
// enable bit in DCDC_EN / LDO_EN0 / LDO_EN1
|
|
81
|
+
await chip.configureDcdc('dcdc1', false, null); // Configure dcdc, (name, always_pwm=False, dvm=None) →
|
|
82
|
+
// forced-PWM bit per DCDC; DVM only for DCDC2 / DCDC3
|
|
83
|
+
await chip.configureDcdcGlobal(false, false, false, false, 60); // Configure dcdc global, (force_ccm=False, slow_ramp=False, frequency_spread=False, spread_100khz=False, uvp_debounce_us=60 µs) →
|
|
84
|
+
// DCDC_EN bits 6 / 5 and DCDC_PWM bits 7:6, 1:0
|
|
85
|
+
await chip.setOffDischarge(true); // Set off discharge, (enabled) →
|
|
86
|
+
// COMMON_CONFIG bit 5: discharge outputs when off
|
|
87
|
+
await chip.configureSleep(false, true, false); // Configure sleep, (wake_on_irq=False, pwrok_low=True, restore_voltages=False) →
|
|
88
|
+
// SLEEP_CTRL bits 4, 3, 2
|
|
89
|
+
await chip.configurePowerKey(512, 6, 1.5, true, false, false); // Configure power key, (on_ms=512, off_s=6, irq_s=1.5, long_press_off=True, restart_instead=False, force_off_16s=False) →
|
|
90
|
+
// power-key timing and the actions of a long press
|
|
91
|
+
await chip.configurePowerOff(true, 2.6, true, 0x0F); // Configure power off, (die_over_temp=True, off_voltage=2.6 V, dcdc_ovp=True, dcdc_uvp=0x0F) →
|
|
92
|
+
// power-off sources: die over-temperature, VOFF threshold, DCDC OVP / UVP
|
|
93
|
+
await chip.configurePwrok(true, 8, true, false, false); // Configure pwrok, (check=True, delay_ms=8 ms, off_delay=True, reverse_off_sequence=False, restart_on_low=False) →
|
|
94
|
+
// PWROK_CTRL delay and sequencing
|
|
95
|
+
await chip.setBatfetOffEnable(false); // Set batfet off enable, (enabled) →
|
|
96
|
+
// BATFET_CTRL bit 3: BATFET on when powered off on battery only
|
|
97
|
+
await chip.configureFastPoweron(false, false); // Configure fast poweron, (poweron, wakeup, sequence=None) →
|
|
98
|
+
// FAST_PWRON enables; the per-rail start sequence is left untouched
|
|
99
|
+
await chip.configureWatchdog(false, 64, 'irq'); // Configure watchdog, (enabled, timeout_s=64 s, action='irq') →
|
|
100
|
+
// watchdog disabled here; timeout and action are still programmed
|
|
101
|
+
await chip.feedWatchdog(); // Feed watchdog, () →
|
|
102
|
+
// WATCHDOG_CTRL bit 3: clears the watchdog counter
|
|
103
|
+
await chip.configureBatteryWarning(10, 1); // Configure battery warning, (level2=10 %, level1=1 %) →
|
|
104
|
+
// LOWBAT_WARN: warning levels 2 (5–20 %) and 1 (0–15 %)
|
|
105
|
+
await chip.setGaugeEnabled(true); // Set gauge enabled, (enabled) →
|
|
106
|
+
// MODULE_ENABLE bit 3: fuel gauge
|
|
107
|
+
await chip.resetGauge(false); // Reset gauge, (full=False) →
|
|
108
|
+
// GAUGE_RESET bit 3 (bit 2 for the deeper reset)
|
|
109
|
+
await chip.setGpio1(false); // Set gpio1, (low) →
|
|
110
|
+
// GPIO1 open-drain output: False = Hi-Z
|
|
111
|
+
await chip.writeDataBuffer(0, 0x5A); // Write data buffer, (index 0–3, value 0–255) →
|
|
112
|
+
// stores a byte that survives soft restarts
|
|
113
|
+
const stored = await chip.readDataBuffer(0); // Read data buffer, (index 0–3) → number
|
|
114
|
+
// reads the byte back
|
|
115
|
+
await chip.enableInterrupt(AXP2101Full.SOURCE_VBUS_INSERT); // Enable interrupt, (source) →
|
|
116
|
+
// sets the source bits in IRQ_EN0..2
|
|
117
|
+
await chip.disableInterrupt(AXP2101Full.SOURCE_VBUS_INSERT); // Disable interrupt, (source) →
|
|
118
|
+
// clears the source bits in IRQ_EN0..2
|
|
119
|
+
const irq = await chip.pollInterrupt(); // Poll interrupt, () → number
|
|
120
|
+
// reads IRQ_STATUS0..2, clears the bits seen and returns the 24-bit status
|
|
121
|
+
|
|
122
|
+
// Destructive commands stay disabled; set ENABLE_DANGEROUS only on a bench supply.
|
|
123
|
+
const ENABLE_DANGEROUS = false;
|
|
124
|
+
if (ENABLE_DANGEROUS) {
|
|
125
|
+
await chip.powerOff(); // Power off, () → None
|
|
126
|
+
// COMMON_CONFIG bit 0: soft power-off, cuts every output except RTCLDO
|
|
127
|
+
await chip.restart(); // Restart, () → None
|
|
128
|
+
// COMMON_CONFIG bit 1: restarts the system
|
|
129
|
+
await chip.sleep(); // Sleep, () → None
|
|
130
|
+
// SLEEP_CTRL bit 0: enter sleep
|
|
131
|
+
await chip.wakeup(); // Wakeup, () → None
|
|
132
|
+
// SLEEP_CTRL bit 1: wake up
|
|
133
|
+
}
|
|
134
|
+
await connection.close();
|
|
135
|
+
})();
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Demo for the AXP2101 — battery and power-rail monitor.
|
|
4
|
+
// Prints the power-on source and every rail, programs a 4.2 V / 500 mA charge profile, arms six
|
|
5
|
+
// interrupts and then prints one status line per second (plus an event line per interrupt) for 120 s.
|
|
6
|
+
|
|
7
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
8
|
+
const { AXP2101Full } = require('periph/src/chips/power/axp2101');
|
|
9
|
+
|
|
10
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
11
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x34', 16);
|
|
12
|
+
|
|
13
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
14
|
+
const chip = new AXP2101Full(connection); // Create AXP2101 Full driver, (connection)
|
|
15
|
+
|
|
16
|
+
const EVENTS = [
|
|
17
|
+
[AXP2101Full.SOURCE_VBUS_INSERT, 'VBUS inserted'],
|
|
18
|
+
[AXP2101Full.SOURCE_VBUS_REMOVE, 'VBUS removed'],
|
|
19
|
+
[AXP2101Full.SOURCE_CHARGE_START, 'charging started'],
|
|
20
|
+
[AXP2101Full.SOURCE_CHARGE_DONE, 'charging done'],
|
|
21
|
+
[AXP2101Full.SOURCE_PWRON_SHORT, 'power key short press'],
|
|
22
|
+
[AXP2101Full.SOURCE_SOC_WARN_L2, 'battery warning level 2'],
|
|
23
|
+
];
|
|
24
|
+
const RAILS = ['dcdc1', 'dcdc2', 'dcdc3', 'dcdc4', 'aldo1', 'aldo2', 'aldo3', 'aldo4',
|
|
25
|
+
'bldo1', 'bldo2', 'cpusldo', 'dldo1', 'dldo2'];
|
|
26
|
+
|
|
27
|
+
(async () => {
|
|
28
|
+
// --- Report why the board started and what every rail is doing ---
|
|
29
|
+
// eFuse defaults differ per product, so the rails are read, never assumed.
|
|
30
|
+
const src = await chip.powerOnSource(); // Read power-on flags, () → number
|
|
31
|
+
console.log('power-on source: 0x' + src.toString(16).padStart(2, '0'));
|
|
32
|
+
for (const name of RAILS) {
|
|
33
|
+
const [enabled, volts] = await chip.getRail(name); // Read rail state, (name) → [boolean, number V]
|
|
34
|
+
console.log(`${name.padEnd(8)} ${enabled ? 'on ' : 'off'} ${volts.toFixed(2)} V`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// --- Program a conservative 4.2 V / 500 mA charge profile ---
|
|
38
|
+
// 4.2 V suits a standard Li-ion cell; 500 mA keeps heating low; the 1.5 A input
|
|
39
|
+
// limit lets a USB charger feed both the system and the charger.
|
|
40
|
+
await chip.setChargeVoltage(4.2); // Set charge target, (volts 4.0/4.1/4.2/4.35/4.4) → void
|
|
41
|
+
await chip.setChargeCurrent(0.5); // Set charge current, (amps 0–1.5) → void
|
|
42
|
+
await chip.setInputCurrentLimit(1.5); // Set input current limit, (amps 0.1/0.5/0.9/1.0/1.5/2.0) → void
|
|
43
|
+
await chip.setTermination(0.05); // Set termination current, (amps 0–0.2, enabled=true) → void
|
|
44
|
+
|
|
45
|
+
// --- Arm low-battery warnings and the power events of interest ---
|
|
46
|
+
// The warning levels are 15 % and 5 %; the six sources below raise the IRQ pin.
|
|
47
|
+
await chip.configureBatteryWarning(15, 5); // Set warning levels, (level2=10 %, level1=1 %) → void
|
|
48
|
+
for (const [mask] of EVENTS) {
|
|
49
|
+
await chip.enableInterrupt(mask); // Enable interrupt source, (source) → void
|
|
50
|
+
}
|
|
51
|
+
await chip.pollInterrupt(); // Clear stale status, () → number
|
|
52
|
+
|
|
53
|
+
// --- Monitor for 120 s ---
|
|
54
|
+
// One status line per second; pollInterrupt() returns and clears every pending event.
|
|
55
|
+
for (let i = 0; i < 120; i++) {
|
|
56
|
+
const d = await chip.readAll(); // Read all measurements, () → object
|
|
57
|
+
const direction = (await chip.status()).batteryDirection; // Read status flags, () → object
|
|
58
|
+
console.log(`${d.batteryVoltage.toFixed(3)} V ${String(d.batteryPercent).padStart(3)} % ` +
|
|
59
|
+
`vbus ${d.vbusPresent} ${d.vbusVoltage.toFixed(2)} V sys ${d.systemVoltage.toFixed(2)} V ` +
|
|
60
|
+
`die ${d.dieTemperature.toFixed(1)} C state ${d.chargeState} ${direction}`);
|
|
61
|
+
const events = await chip.pollInterrupt(); // Read and clear events, () → number
|
|
62
|
+
for (const [mask, text] of EVENTS) {
|
|
63
|
+
if (events & mask) console.log('event: ' + text);
|
|
64
|
+
}
|
|
65
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
66
|
+
}
|
|
67
|
+
await connection.close();
|
|
68
|
+
})();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Minimal example for the AXP2101 — battery and power-source monitoring.
|
|
4
|
+
|
|
5
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
6
|
+
const { AXP2101Minimal } = require('periph/src/chips/power/axp2101');
|
|
7
|
+
|
|
8
|
+
const I2C_BUS = parseInt(process.env.I2C_BUS || '1', 10);
|
|
9
|
+
const I2C_ADDR = parseInt(process.env.I2C_ADDR || '0x34', 16);
|
|
10
|
+
|
|
11
|
+
const connection = new I2CConnection(I2C_BUS, I2C_ADDR);
|
|
12
|
+
const chip = new AXP2101Minimal(connection); // Create AXP2101 driver, (connection)
|
|
13
|
+
|
|
14
|
+
(async () => {
|
|
15
|
+
for (let i = 0; i < 10; i++) {
|
|
16
|
+
const v = await chip.batteryVoltage(); // Read battery voltage, () → number V
|
|
17
|
+
const pct = await chip.batteryPercent(); // Read state of charge, () → number %
|
|
18
|
+
const state = await chip.chargeState(); // Read charge state, () → int (0 trickle … 5 none)
|
|
19
|
+
const vbus = await chip.vbusPresent(); // Check input source, () → boolean
|
|
20
|
+
console.log(`${v.toFixed(3)} V ${pct} % state=${state} vbus=${vbus}`);
|
|
21
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
22
|
+
}
|
|
23
|
+
await connection.close();
|
|
24
|
+
})();
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
4
|
+
const { PCF85063AFull } = require('periph/src/chips/rtc/pcf85063a');
|
|
5
|
+
|
|
6
|
+
(async () => {
|
|
7
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
8
|
+
const connection = new I2CConnection(bus, 0x51);
|
|
9
|
+
const rtc = new PCF85063AFull(connection); // Create PCF85063A Full driver, (connection)
|
|
10
|
+
await rtc.init(); // Confirm presence + force 24-hour mode, () → None
|
|
11
|
+
// bus check, STOP = 0, 12_24 = 0
|
|
12
|
+
|
|
13
|
+
await rtc.setDatetime(2026, 9, 23, 3, 14, 30, 0); // Set the calendar clock, (year 2000–2099, month, day, weekday 0=Sun, hour, minute, second) → None
|
|
14
|
+
// STOP-bit precision start; clears OS
|
|
15
|
+
const dt = await rtc.getDatetime(); // Read the calendar clock, () → {year, month, day, weekday, hour, minute, second}
|
|
16
|
+
// decodes the seven BCD clock/calendar registers
|
|
17
|
+
const stopped = await rtc.oscillatorStopped(); // Query oscillator-stop flag, () → bool
|
|
18
|
+
// true means the time may be invalid until setDatetime
|
|
19
|
+
await rtc.clearOscillatorStop(); // Clear oscillator-stop flag, () → None
|
|
20
|
+
// still true afterwards means the crystal is not running
|
|
21
|
+
await rtc.stopClock(); // Freeze the clock, () → None
|
|
22
|
+
// STOP = 1, divider chain held in reset
|
|
23
|
+
await rtc.startClock(); // Release the clock, () → None
|
|
24
|
+
|
|
25
|
+
await rtc.setAlarm({ second: 0, minute: 0, hour: 9 }); // Configure alarm, ({second, minute, hour, day, weekday}) → None
|
|
26
|
+
// fires daily at 09:00:00; omitted fields are ignored in the match
|
|
27
|
+
const alarm = await rtc.getAlarm(); // Read alarm, () → {second, minute, hour, day, weekday}
|
|
28
|
+
// disabled fields decode as null
|
|
29
|
+
|
|
30
|
+
await rtc.configureTimer(10, '1hz'); // Start countdown timer, (value 1–255, sourceClock, pulsed=false) → None
|
|
31
|
+
// counts down 10 s, then sets TF
|
|
32
|
+
const remaining = await rtc.readTimer(); // Read timer counter, () → int
|
|
33
|
+
// live value, not the loaded one
|
|
34
|
+
await rtc.disableTimer(); // Stop timer, () → None
|
|
35
|
+
// TE = 0, TIE = 0, 1/60 Hz clock for power saving
|
|
36
|
+
|
|
37
|
+
await rtc.setMinuteInterrupt('minute'); // Select minute interrupt, (mode "off"|"minute"|"half_minute") → None
|
|
38
|
+
// sets MI; reported as SOURCE_TIMER
|
|
39
|
+
|
|
40
|
+
await rtc.setClockOutput(1); // Drive CLKOUT, (frequencyHz) → None
|
|
41
|
+
// 1 Hz square wave on the CLKOUT pin
|
|
42
|
+
await rtc.disableClockOutput(); // Disable CLKOUT, () → None
|
|
43
|
+
// COF = 111, pin low
|
|
44
|
+
|
|
45
|
+
await rtc.setOffset(-3, 'normal'); // Write offset calibration, (offset −64–63, mode='normal') → None
|
|
46
|
+
// −3 LSB × 4.34 ppm = −13.02 ppm correction
|
|
47
|
+
const offset = await rtc.getOffset(); // Read offset calibration, () → {offset, mode}
|
|
48
|
+
|
|
49
|
+
await rtc.setOscillatorLoad(12.5); // Select crystal load, (picofarads 7|12.5) → None
|
|
50
|
+
// match the crystal's specified load capacitance
|
|
51
|
+
await rtc.writeRam(0xA5); // Write RAM byte, (value 0–255) → None
|
|
52
|
+
const ram = await rtc.readRam(); // Read RAM byte, () → int
|
|
53
|
+
|
|
54
|
+
await rtc.onInterrupt((status) => console.log('interrupt status=0x' + status.toString(16))); // Subscribe to interrupts, (callback) → None
|
|
55
|
+
// falls back to 5 ms polling when no INT pin is wired
|
|
56
|
+
await rtc.enableInterrupt(PCF85063AFull.SOURCE_ALARM | PCF85063AFull.SOURCE_TIMER); // Enable sources, (source) → None
|
|
57
|
+
// sets AIE and TIE
|
|
58
|
+
const status = await rtc.pollInterrupt(); // Poll & clear flags, () → int
|
|
59
|
+
// clears AF/TF, returns the pre-clear mask
|
|
60
|
+
await rtc.disableInterrupt(PCF85063AFull.SOURCE_ALARM | PCF85063AFull.SOURCE_TIMER | PCF85063AFull.SOURCE_MINUTE | PCF85063AFull.SOURCE_HALF_MINUTE | PCF85063AFull.SOURCE_CORRECTION); // Disable sources, (source) → None
|
|
61
|
+
await rtc.offInterrupt(); // Unsubscribe, () → None
|
|
62
|
+
|
|
63
|
+
await rtc.softwareReset(); // Software reset, () → None
|
|
64
|
+
// resets ALL registers including the time
|
|
65
|
+
|
|
66
|
+
console.log(dt, { stopped }, alarm, { remaining, ram }, offset, { status });
|
|
67
|
+
await connection.close();
|
|
68
|
+
})();
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Scheduling core of a battery-powered logger: reseeds the clock after a
|
|
4
|
+
// power loss, counts boots in the free RAM byte, then wakes on an hourly
|
|
5
|
+
// alarm to print a timestamp while a 30-second pulsed countdown timer
|
|
6
|
+
// toggles an LED as a "still running" heartbeat.
|
|
7
|
+
|
|
8
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
9
|
+
const { PCF85063AFull } = require('periph/src/chips/rtc/pcf85063a');
|
|
10
|
+
|
|
11
|
+
(async () => {
|
|
12
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
13
|
+
const connection = new I2CConnection(bus, 0x51);
|
|
14
|
+
const rtc = new PCF85063AFull(connection); // Create PCF85063A Full driver, (connection)
|
|
15
|
+
await rtc.init(); // Confirm presence + force 24-hour mode, () → None
|
|
16
|
+
|
|
17
|
+
// --- Detect a lost time reference and reseed if needed ---
|
|
18
|
+
// A fresh chip, or one whose supply dropped out, reports the OS flag set:
|
|
19
|
+
// its calendar cannot be trusted until reseeded. The crystal needs up to
|
|
20
|
+
// 2 s to start, so wait until the flag stays clear.
|
|
21
|
+
if (await rtc.oscillatorStopped()) { // Query oscillator-stop flag, () → bool
|
|
22
|
+
await rtc.setDatetime(2026, 1, 1, 4, 0, 0, 0); // Set the calendar clock, (year, month, day, weekday 0=Sun, hour, minute, second) → None
|
|
23
|
+
console.log('oscillator was stopped - reseeded from reference timestamp');
|
|
24
|
+
while (await rtc.oscillatorStopped()) { // Query oscillator-stop flag, () → bool
|
|
25
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// --- Count boots in the free RAM byte ---
|
|
30
|
+
// The RAM byte survives as long as VDD is present, so it works as a tiny
|
|
31
|
+
// non-volatile counter next to the clock.
|
|
32
|
+
const boots = ((await rtc.readRam()) + 1) & 0xFF; // Read RAM byte, () → int
|
|
33
|
+
await rtc.writeRam(boots); // Write RAM byte, (value 0–255) → None
|
|
34
|
+
console.log(`boot #${boots}`, await rtc.getDatetime(), await rtc.getOffset()); // Read the calendar clock, () → {year, month, day, weekday, hour, minute, second}
|
|
35
|
+
// Read offset calibration, () → {offset, mode}
|
|
36
|
+
|
|
37
|
+
// --- Tune the board for low power ---
|
|
38
|
+
// Match the crystal's load capacitance and switch the 32.768 kHz CLKOUT
|
|
39
|
+
// off — it is enabled at power-on and costs current on a battery device.
|
|
40
|
+
await rtc.setOscillatorLoad(12.5); // Select crystal load, (picofarads 7|12.5) → None
|
|
41
|
+
await rtc.disableClockOutput(); // Disable CLKOUT, () → None
|
|
42
|
+
|
|
43
|
+
// --- Hourly wake-up plus a 30 s heartbeat ---
|
|
44
|
+
// Only second and minute are enabled, so the alarm matches at hh:00:00
|
|
45
|
+
// every hour. The pulsed timer reloads automatically; minute ticks share
|
|
46
|
+
// the same TF flag and are reported as SOURCE_TIMER.
|
|
47
|
+
await rtc.setAlarm({ second: 0, minute: 0 }); // Configure alarm, ({second, minute, hour, day, weekday}) → None
|
|
48
|
+
await rtc.configureTimer(30, '1hz', true); // Start countdown timer, (value 1–255, sourceClock, pulsed=false) → None
|
|
49
|
+
await rtc.setMinuteInterrupt('minute'); // Select minute interrupt, (mode "off"|"minute"|"half_minute") → None
|
|
50
|
+
|
|
51
|
+
// --- Dispatch by source: log on the alarm, blink on the heartbeat ---
|
|
52
|
+
let alarms = 0;
|
|
53
|
+
let ledOn = false;
|
|
54
|
+
await new Promise((resolve) => {
|
|
55
|
+
const timeout = setTimeout(resolve, 5 * 60 * 1000);
|
|
56
|
+
rtc.onInterrupt(async (status) => { // Subscribe to interrupts, (callback) → None
|
|
57
|
+
if (status & PCF85063AFull.SOURCE_ALARM) {
|
|
58
|
+
const dt = await rtc.getDatetime(); // Read the calendar clock, () → {year, month, day, weekday, hour, minute, second}
|
|
59
|
+
console.log('[hourly]', dt);
|
|
60
|
+
if (++alarms >= 5) { clearTimeout(timeout); resolve(); }
|
|
61
|
+
}
|
|
62
|
+
if (status & PCF85063AFull.SOURCE_TIMER) {
|
|
63
|
+
ledOn = !ledOn;
|
|
64
|
+
console.log(`[heartbeat] LED ${ledOn ? 'on' : 'off'}`);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
rtc.enableInterrupt(PCF85063AFull.SOURCE_ALARM | PCF85063AFull.SOURCE_TIMER); // Enable sources, (source) → None
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// --- Leave the chip quiet on exit ---
|
|
71
|
+
await rtc.disableInterrupt(PCF85063AFull.SOURCE_ALARM | PCF85063AFull.SOURCE_TIMER); // Disable sources, (source) → None
|
|
72
|
+
await rtc.disableTimer(); // Stop timer, () → None
|
|
73
|
+
await rtc.setMinuteInterrupt('off'); // Select minute interrupt, (mode "off"|"minute"|"half_minute") → None
|
|
74
|
+
await rtc.offInterrupt(); // Unsubscribe, () → None
|
|
75
|
+
await connection.close();
|
|
76
|
+
})();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { I2CConnection } = require('periph/src/connection/i2c');
|
|
4
|
+
const { PCF85063AMinimal } = require('periph/src/chips/rtc/pcf85063a');
|
|
5
|
+
|
|
6
|
+
(async () => {
|
|
7
|
+
const bus = parseInt(process.env.I2C_BUS || '1', 10);
|
|
8
|
+
const connection = new I2CConnection(bus, 0x51);
|
|
9
|
+
const rtc = new PCF85063AMinimal(connection); // Create PCF85063A driver, (connection)
|
|
10
|
+
await rtc.init(); // Confirm presence + force 24-hour mode, () → None
|
|
11
|
+
|
|
12
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
13
|
+
for (let i = 0; i < 10; i++) {
|
|
14
|
+
const dt = await rtc.getDatetime(); // Read the calendar clock, () → {year, month, day, weekday, hour, minute, second}
|
|
15
|
+
console.log(`${dt.year}-${pad(dt.month)}-${pad(dt.day)} ${pad(dt.hour)}:${pad(dt.minute)}:${pad(dt.second)}`);
|
|
16
|
+
await new Promise((r) => setTimeout(r, 1000));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
await connection.close();
|
|
20
|
+
})();
|