Skip to content
Wiebe van Breukelen edited this page Oct 30, 2018 · 7 revisions

Configuring a GPIO pin

You may configure a GPIO pin to only be input or output driven. Also, it is possible to do both.

Input driven

To set a GPIO pin to input driven mode, please use the hwstl::make_ipin(pin_number) function.

Example: configure pin D7 on an Arduino based board to be input driven.

auto [d7] = hwstl::make_ipin(
    hwstl::target::pin::d7
);

Output driven

To set a GPIO pin to output driven mode, please use the hwstl::make_opin(pin_number) function.

Example: configure pin D13, in most cases the onboard LED, on an Arduino based board to be output driven.

auto [d13] = hwstl::make_opin(
    hwstl::target::pin::d13
);

Input and output driven

To set a GPIO pin to input/output driven, please use the hwstl::make_iopin(pin_number) function.

Example: configure pin D13, in most cases the onboard LED, on an Arduino based board to be output driven.

auto [d5] = hwstl::make_iopin(
    hwstl::target::pin::d5
);

Multiple pin initialization

You may initialize a sequence of pins at once. This will improve the performance of your application slightly. To initialize multiple pins you may use the hwstl::make_ipin, hwstl::make_opin and hwstl::make_iopin as noted in the sections above.

Example:

auto [d5, d13] = hwstl::make_iopin(
    hwstl::target::pin::d5
    hwstl::target::pin::d7
);

Note that pins D5 and D7 are both in input/output mode.

Using GPIO pins

If you've configured some GPIO pins, you may now proceed to do something with them.

Input

You may get the level of a GPIO pin.

Example (D7 is configured to be input driven):

bool pin_val = d7.get();

Output

You may set the level of a GPIO pin to HIGH or LOW.

High:

d5.set(1);

Low:

d5.set(0);