Stirring from the ashes of the week from hell...* On Mon, Mar 24, 2025 at 11:54:59PM -1000, Anthony Sorace wrote: > Brian Stuart did a port of Inferno to the Sun SPOT hardware, which has some > overlap with the devices in question: > > http://iwp9.org/8e/sunspot.pdf
Yes, that would be an example of one way to do it. In that case, the devices weren't directly available to the ARM over i2c, but had an ATMega88 in between that we talk to. > I did an accelerometer on a pi hat a while ago. I think I ended up with the > same interface you were describing, but without the normalization, which > seems like a good improvement. One of the classes I have just wrapped up this term uses the Pi interfaces to play with various devices. I'll attach a Q&D user space program that reads from the i2c MMA8451 accelerometer. I think if it were me (and we weren't talking about real-time behavior) I'd leave just the i2c driver in the kernel and write a user-space server that reads from it and serves a small tree of device info. This makes a good time to advertise the upcoming IWP9. The paper I'll be giving is related and even touches on the in-kernel vs user-space question. * Grades from our Winter term were due today at noon, and this is probably the farthest behind I've ever been going into the final push. Now I have a week and a half to get ready for the Vintage Computer Festival in NJ, where BTW Brian Kernighan will be appearing. BLS ------------------------------------------ 9fans: 9fans Permalink: https://9fans.topicbox.com/groups/9fans/T4d13b3016d2a2310-M9808b1309f2c605f84ed393d Delivery options: https://9fans.topicbox.com/groups/9fans/subscription
#include <u.h> #include <libc.h> void main() { int fd, cfd, i, n, x, y, z; uchar buf[16]; fd = open("/dev/i2c.1c.data", ORDWR); if(fd < 0) { bind("#J1c", "/dev", MAFTER); fd = open("/dev/i2c.1c.data", ORDWR); if(fd < 0) print("open error: %r\n"); } cfd = open("/dev/i2c.1c.ctl", ORDWR); buf[0] = 0x2a; buf[1] = 0x01; pwrite(fd, buf, 2, 0); fprint(cfd, "subaddress"); n = pread(fd, buf, 1, 0x0d); print("Got ID %d %02x\n", n, buf[0]); n = pread(fd, buf, 16, 0x09); for(i = 0; i < 16; ++i) print("%02x ", buf[i]); print("\n"); pread(fd, buf, 1, 0x2a); print("Ctlreg: %02x\n", buf[0]); while(1) { sleep(1000); n = pread(fd, buf, 7, 0x00); print("Got %d %02x ", n, buf[0]); x = buf[1] << 8 | buf[2]; if(x & 0x8000) x |= ~0x7fff; y = buf[3] << 8 | buf[4]; if(y & 0x8000) y |= ~0x7fff; z = buf[5] << 8 | buf[6]; if(z & 0x8000) z |= ~0x7fff; print("x:%d y:%d z:%d\n", x, y, z); } }