Ever since we’ve started writing/porting CircuitPython drivers for sensors and displays and such, we’ve fallen in love with `busio` – our generalized I2C and SPI API which takes out the repetitive parts of writing drivers: i2c address scanning, writing registers, reading chunks of data and concatenating it, dealing with repeated-start chips. After doing a bunch of drivers, we started looking at our Arduino libraries with an itchy nose. Sure they worked, but they’d been building up a decade of cruft and low-level interfacing.
So we’re doing a bit of a scrubbing for our older libraries, to ‘busio-ify’ them. Carter has been taking the lead and it is soooooooooo satisfying to look at the pull requests. For example, this one was approved today: https://github.com/adafruit/Adafruit_TCS34725/pull/47/files
(yes we use a stack single-element array for readability. yes we are well aware we could pass in the local’s address. yes its on purpose)
Because Adafruit_BusIO now does the annoying “we can only read/write 32 bytes at a time but sometimes we have a larger buffer” management, we have lovely diffs like this one from https://github.com/adafruit/Adafruit_AMG88xx/pull/24/files
We’re so happy to see this happen. Adafruit_BusIO handles I2C, hardware and software SPI with fast-io bitbanging. It also can do things like manage ‘registers’ and variable-size/offset bit-fields and will do all the error-prone math for you. There’s more memory used both flash and RAM, but that’s what good reusable-software engineering practice is all about!
Check out the Doxygen docs here https://adafruit.github.io/Adafruit_BusIO/html/annotated.html and our examples here https://adafruit.github.io/Adafruit_BusIO/html/annotated.html
Then, tune in to the Adafruit GitHub repo to see the libraries as they’re updated each week to BusIO.