Table of Contents

Pins

Pins library provides an easy way for operating with AVR digital input-output pins. The user can create a pin related variable and do all the pin operations with that variable. This way there is no need to deal with the register names and bit indexes like it is done while programming in direct register access method. The pin's port and index must be specified only once, so the changes are easy to implement.

Data Types

Constants

Functions

Configures pin as an output. Parameters:

Configures pin as an input without pull-up resistor. Parameters:

Configures pin as an input with pull-up resistor. Parameters:

Sets output pin high. Parameters:

Sets output pin low. Parameters:

Inverts output pin state. Parameters:

Sets output pin to desired state. Parameters:

Gets pin value. Parameters:

Reads pin value through the switch debounce filter. Filtering takes at least 8 ms and may last up to 100 ms, depending on when the bouncing ends. If the bouncing does not end, false is returned. Function uses software delay. Parameters:

Example

Example of getting and setting a pin's value. Pin PC0 value is inverted and attached to pin PC3.

#include <homelab/pin.h>
 
pin output_pin = PIN(C, 3);
pin input_pin = PIN(C, 0);
 
int main(void)
{
	bool value;
 
	// Configuring pin as an output pin
	pin_setup_output(output_pin);
 
	// Configuring pin as an input pin with pull-up
	pin_setup_input_with_pullup(input_pin);
 
	// Endless loop
	while (true)
	{
		// Getting an input pin value
		value = pin_get_value(input_pin);
 
		// Setting an output pin value
		pin_set_to(output_pin, !value);
	}
}

led_on, led_off, button_read commands example

#include <homelab/pin.h>
 
// Homelab buttons and LEDs are predefined in the library
 
int main(void)
{
	// Set LED pin as output
	pin_setup_output(led_green);
 
	// Set Button S1 pin as input
	pin_setup_input(S1);
 
	// Endless loop
	while (true)
	{
		// If button is pressed, turn on LED, if not pressed, turn LED off.
		if(button_read(S1) == true)
			led_on(led_green);
		else
			led_off(led_green);
	}
}