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

_ioa objects are groups of one or more consecutive pins inside the same GPIO 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 0x0400 bytes away 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

Actions



hw( configure, ... ) configures one set of consecutive pins in the same port assuming the gpio function:

hw( 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, 2MHz | lowest
| 10MHz // Default
| 50MHz | highest ]
);



hwa( configure, ... ) configures one set of consecutive pins in the same port, can set alternate function (remapping):

hwa( configure, (porta,0),
[ function, gpio // Default
| (controller,...), ] // Alternate function
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, 2MHz | lowest
| 10MHz // Default
| 50MHz | highest ]
);
Note
You can not map one signal to multiple pins.


read:

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


write:

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.

toggle: 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
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