Bit addressable memory/

I programmed 8051 chips alot and these came with bit addressable SFR. I had sbit definations for IO ports and with #defines I'd link a name to an sbit

And to set or clear an output I would do:

outputX = 1;
outputY = 0;
// and to read
if(inputZ) { 
...

I know that with macros you can OR or AND any bit of any byte. Whether it is an char or PORTB. And that we have bitset and bitclear functions (or macros).. Though it is faster than digitalWrite() it is not more 'user friendly'. But what'd like to have.

bit addressable bytes.

I am currently developing a 'better' library to control an I2C MCP23017 IO extender. For this I thought of using a struct with bit fields and macros. My idea is to let a python script read a simple txt file which has the IO definitions in a certain format and generate IO files for me.

I'd like to build structs which would look as follows

struct ioPort {
    unsigned char pin1:1;
    unsigned char pin2:1;
    unsigned char pin3:1;
    unsigned char pin4:1;
    unsigned char pin5:1;
    unsigned char pin6:1;
    unsigned char pin7:1; };

#define ioPort.pin1 outputX
#define ioPort.pin1 outputY
#define ioPort.pin1 inputZ

And then in the program I want to do the same as in my first code snippet.

outputX = 1;

The general idea is that a roundRobinTask continously monitor any IO changes and refreshes the outputs and inputs. I could ofcourse do the same for the native arduino IO. The IO would be slower with reading and writing but you get to type less text. I am such a lazy programmer :)

The MCP extenders would only need 1 init functions and 1 update function. The init function can determen the ammount of connected I2C devices by finding the highest IO pin.

I thought this would be a neat library which would win the 'most user friendly price' . No user has to remember on which slave or pin is attached. You simple type outputX = 1; and the library makes sure it happens

I use this BitArray class for my IO library.

I also recently ported std::bitset, which is the C++ standard library bit-addressable data structure.
Using the Arduino Helpers library, you can just #include <Arduino_Helpers.h> and #include <AH/STL/bitset> to use it, it should be supported on all hardware (AVR, ARM, ESP32 etc.).

Pieter

Small and clean "library" that's much faster than digitalWrite and much easier to understand than direct port manipulation:

https://godbolt.org/z/wp96Ab

The following is "Blink" on an Arduino UNO, all IO operations are just one instruction. (Digital pin 13 is PB5.)

[color=#00979c]void[/color] [color=#5e6d03]setup[/color][color=#000000]([/color][color=#000000])[/color] [color=#000000]{[/color]
  [color=#000000]IOB[/color][color=#000000][[/color][color=#000000]5[/color][color=#000000]][/color] [color=#434f54]=[/color] [color=#000000]PinMode[/color][color=#434f54]:[/color][color=#434f54]:[/color][color=#000000]Output[/color][color=#000000];[/color]  
[color=#000000]}[/color]

[color=#00979c]void[/color] [color=#5e6d03]loop[/color][color=#000000]([/color][color=#000000])[/color] [color=#000000]{[/color]
  [color=#000000]IOB[/color][color=#000000][[/color][color=#000000]5[/color][color=#000000]][/color] [color=#434f54]=[/color] [color=#00979c]HIGH[/color][color=#000000];[/color]
  [color=#d35400]delay[/color][color=#000000]([/color][color=#000000]500[/color][color=#000000])[/color][color=#000000];[/color]
  [color=#000000]IOB[/color][color=#000000][[/color][color=#000000]5[/color][color=#000000]][/color] [color=#434f54]=[/color] [color=#00979c]LOW[/color][color=#000000];[/color]
  [color=#d35400]delay[/color][color=#000000]([/color][color=#000000]500[/color][color=#000000])[/color][color=#000000];[/color]
[color=#000000]}[/color]