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

_iob objects are groups of one or more consecutive pins inside the same port.

Relatives

Interface

HW_ADDRESS() returns an address for an I/O definition, computed as:

 address_of_port + (number_of_bits-1)*16 + position_of_lsb

Ports are mapped every 0x0400 bytes in memory.

#if HW_ADDRESS(LED) == HW_ADDRESS((porta,9))
// LED is connected on pa9, or LED and pa9 do not exist.
#else
// LED is not connected on pa9, or pa9 or LED does not exist.
#endif

HW_BITS() returns the number of bits of an I/O definition:

#if (HW_ADDRESS((porta,3)) != -1) && (HW_BITS((porta,3)) != 1)
# error HWA is damaged!
#endif

HW_POSITION() returns the position of the least significant bit:

#if (HW_ADDRESS((porta,3)) != -1) && (HW_POSITION((porta,3)) != 3)
# HWA is damaged!
#endif
hw|hwa( configure, (porta,0),
[ function, gpio, ] // Default
mode, digital_input | digital_input_floating // Default
| digital_input_pullup
| digital_input_pulldown
| analog_input
| digital_output | digital_output_pushpull
| digital_output_opendrain,
// Only for output modes
//
[ frequency, low | lowest
| medium
| fast
| high | highest ] );
uint8_t value = hw( read, (porta,0) );

Toggles one or several consecutive pins at once.

Note
toggle is not atomic: it reads the ODR, then sets/resets the relevant bits through the BSRR. The ODR is not written directly.
hw( toggle, (porta,0) );
hwa( toggle, (porta,0) ); // Register PA0 for toggling
hwa( toggle, (porta,4) ); // Register PA4 for toggling
hwa( commit ); // Toggle PA0 and PA4 at once
hw|hwa( write, (porta,0), 0 );
Note
HWA does not write the ODR of the port. It writes the BSRR so that atomicity is guaranted and concurrent tasks can write different pins of the port without conflict.
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