HWA
Bare metal programming with style
Class _ioa: General Purpose Input/Output

This class implements a group of consecutive I/O pins inside the same _gpa GPIO port. It handles not-connected pins and triggers an error if such a pin is addressed (but no error is triggered if you access the registers directly).

It supports HW_ADDRESS(), HW_BITS(), and HW_POSITION().

Relatives

IOs are relatives of their port:

and have their port as relative:

Single IO pins can be designated as relatives of the virtual pin object:

Analog input pins have a did register that disables the digital input stage:

Interface




hw( configure, IO, ... ) and hwa( configure, IO, ... ) configure an IO:

hw | hwa( configure, (porta,0),
[ function, gpio, ] // Default, no other choice
mode, digital_input
| digital_input_floating // Reset value
| digital_input_pullup
| digital_output | digital_output_pushpull
| analog_input
| analog_input_floating
| analog_input_pullup
);
Note
Atmel AVR peripheral controllers take care of their I/O configuration, so there is no need for a 'function' parameter for IOs as it is always 'gpio'.
A digital output in high state enables its pull-up when switched to an input.




hw( read, IO, ... ) returns the state of the IO:

uint8_t value = hw( read, (porta,0) );




hw( write, IO, value ) and hwa( write, IO, value ) set the state of an IO:

hw | hwa( write, (porta,0), 1 ); // PA0 = 1
hw | hwa( write, (portb,2,4), 2 ); // PB5,PB4 = 1,0




hw( set, IO ) and hwa( set, IO ) set all the bits of the IO to 1:

hw | hwa( set, (porta,0) ); // PA0 = 1
hw | hwa( set, (portb,2,4) ); // PB5,PB4 = 1,1




hw( clear, IO ) and hwa( clear, IO ) clear all the bits of the IO:

hw | hwa( clear, (porta,0) ); // PA0 = 0
hw | hwa( clear, (portb,2,4) ); // PB5,PB4 = 0,0




hw( toggle, IO ) and hwa( toggle, IO ) toggle all the bits of the IO:

hw( toggle, (porta,0) ); // Toggle pin PA0
hwa( toggle, (porta,0) ); // Register PA0 for toggling
hwa( toggle, (porta,2,3) ); // Register PA4 and PA3 for toggling
hwa( commit ); // Toggle PA0, PA4 and PA3 at once
hwa
#define hwa(...)
hwa( action, object [,...] ) stores an action for an object into a HWA context.
Definition: hwa_macros.h:552
hw
#define hw(...)
hw( action, object [,...] ) executes an action immediately on an object.
Definition: hwa_macros.h:523