# HG changeset patch # User Paul Boddie # Date 1609973671 -3600 # Node ID 84945015fb9c287520e6ba1bdb6c9ce4bf349123 # Parent 99302c954b99fa520e9e944084502406e5c4e584 Added testing of the voltage level and charging status, and of powering down. diff -r 99302c954b99 -r 84945015fb9c pkg/landfall-examples/letux400_i2c/letux400_i2c.cc --- a/pkg/landfall-examples/letux400_i2c/letux400_i2c.cc Wed Jan 06 00:46:11 2021 +0100 +++ b/pkg/landfall-examples/letux400_i2c/letux400_i2c.cc Wed Jan 06 23:54:31 2021 +0100 @@ -210,7 +210,7 @@ printf("Written: %d\n", nwritten); - do + for (int i = 0; i < 3; i++) { /* Issue selection of device register 0. */ @@ -232,6 +232,24 @@ rtc_datetime(buf); + /* Read from the power controller at 0x28. */ + + buf[0] = 0xdb; + nwritten = jz4730_i2c_write(i2c0, 0x28, buf, 1); + printf("Written: %d\n", nwritten); + nread = jz4730_i2c_read(i2c0, 0x28, buf, 1); + printf("Read: %d\n", nread); + + printf("Voltage level: %1.3f\n", buf[0] * 36235 / 1000000.0); + + buf[0] = 0xd9; + nwritten = jz4730_i2c_write(i2c0, 0x28, buf, 1); + printf("Written: %d\n", nwritten); + nread = jz4730_i2c_read(i2c0, 0x28, buf, 1); + printf("Read: %d\n", nread); + + printf("Charger connected: %s\n", buf[0] & 1 ? "yes" : "no"); + /* Scan the bus. */ printf("Scan I2C0...\n"); @@ -239,7 +257,12 @@ sleep(5); } - while(1); + + /* Issue a shutdown request. */ + + buf[0] = 0xd8; buf[1] = 1; + nwritten = jz4730_i2c_write(i2c0, 0x28, buf, 2); + printf("Written: %d\n", nwritten); /* Detach from the interrupt. */