px-fwlib 0.10.0
Cross-platform embedded library and documentation for 8/16/32-bit microcontrollers generated with Doxygen 1.9.2
px_gpio.c
1/* =============================================================================
2 ____ ___ ____ ___ _ _ ___ __ __ ___ __ __ TM
3 | _ \ |_ _| / ___| / _ \ | \ | | / _ \ | \/ | |_ _| \ \/ /
4 | |_) | | | | | | | | | | \| | | | | | | |\/| | | | \ /
5 | __/ | | | |___ | |_| | | |\ | | |_| | | | | | | | / \
6 |_| |___| \____| \___/ |_| \_| \___/ |_| |_| |___| /_/\_\
7
8 Copyright (c) 2012-2016 Pieter Conradie <https://piconomix.com>
9
10 License: MIT
11 https://github.com/piconomix/px-fwlib/blob/master/LICENSE.md
12
13 Title: px_gpio.h : Microchip AVR GPIO driver
14 Author(s): Pieter Conradie
15 Creation Date: 2014-12-01
16
17============================================================================= */
18
19/* _____STANDARD INCLUDES____________________________________________________ */
20
21/* _____PROJECT INCLUDES_____________________________________________________ */
22#include "px_gpio.h"
23#include "px_log.h"
24
25/* _____LOCAL DEFINITIONS____________________________________________________ */
26PX_LOG_NAME("gpio");
27
28/* _____MACROS_______________________________________________________________ */
29
30/* _____GLOBAL VARIABLES_____________________________________________________ */
31
32/* _____LOCAL VARIABLES______________________________________________________ */
33
34/* _____LOCAL FUNCTION DECLARATIONS__________________________________________ */
35
36/* _____LOCAL FUNCTIONS______________________________________________________ */
37
38/* _____GLOBAL FUNCTIONS_____________________________________________________ */
39/*
40 * Declare "extern inline" functions so that if the compiler decides not to
41 * place the functions inline, normal versions of the functions will be created
42 * that can be called.
43 */
44extern inline void px_gpio_open (px_gpio_handle_t * gpio,
45 px_gpio_reg_t port,
46 px_gpio_reg_t ddr,
47 px_gpio_reg_t pin,
48 uint8_t bit,
49 uint8_t dir,
50 uint8_t init);
51
52extern inline void px_gpio_init (const px_gpio_handle_t * gpio);
53extern inline uint8_t px_gpio_init_ddr (const px_gpio_handle_t * gpio);
54extern inline uint8_t px_gpio_init_port (const px_gpio_handle_t * gpio);
55
56extern inline void px_gpio_out_set_hi (const px_gpio_handle_t * gpio);
57extern inline void px_gpio_out_set_lo (const px_gpio_handle_t * gpio);
58extern inline void px_gpio_out_toggle (const px_gpio_handle_t * gpio);
59
60extern inline bool px_gpio_out_is_hi (const px_gpio_handle_t * gpio);
61extern inline bool px_gpio_out_is_lo (const px_gpio_handle_t * gpio);
62
63extern inline bool px_gpio_in_is_hi (const px_gpio_handle_t * gpio);
64extern inline bool px_gpio_in_is_lo (const px_gpio_handle_t * gpio);
65
66extern inline void px_gpio_dir_set_out (const px_gpio_handle_t * gpio);
67extern inline void px_gpio_dir_set_in (const px_gpio_handle_t * gpio);
68
69extern inline bool px_gpio_dir_is_out (const px_gpio_handle_t * gpio);
70extern inline bool px_gpio_dir_is_in (const px_gpio_handle_t * gpio);
71
72extern inline void px_gpio_pull_up_enable (const px_gpio_handle_t * gpio);
73extern inline void px_gpio_pull_up_disable(const px_gpio_handle_t * gpio);
void px_gpio_open(px_gpio_handle_t *gpio, px_gpio_reg_t port, px_gpio_reg_t ddr, px_gpio_reg_t pin, uint8_t bit, uint8_t dir, uint8_t init)
Initialise a GPIO structure.
Definition: px_gpio.h:358
bool px_gpio_out_is_lo(const px_gpio_handle_t *gpio)
Test if GPIO pin output is set low.
Definition: px_gpio.h:432
bool px_gpio_dir_is_in(const px_gpio_handle_t *gpio)
Test if GPIO pin is configured to be an input.
Definition: px_gpio.h:468
void px_gpio_out_set_lo(const px_gpio_handle_t *gpio)
Set GPIO pin output low.
Definition: px_gpio.h:414
bool px_gpio_in_is_lo(const px_gpio_handle_t *gpio)
Test if GPIO pin input is low.
Definition: px_gpio.h:444
bool px_gpio_dir_is_out(const px_gpio_handle_t *gpio)
Test if GPIO pin is configured to be an output.
Definition: px_gpio.h:462
uint8_t px_gpio_init_ddr(const px_gpio_handle_t *gpio)
Calculate bit mask used to initialise DDR register.
Definition: px_gpio.h:396
uint8_t px_gpio_init_port(const px_gpio_handle_t *gpio)
Calculate bit mask used to initialise PORT register.
Definition: px_gpio.h:402
void px_gpio_dir_set_out(const px_gpio_handle_t *gpio)
Set GPIO pin direction to output.
Definition: px_gpio.h:450
void px_gpio_pull_up_disable(const px_gpio_handle_t *gpio)
Disable pull-up on GPIO pin.
Definition: px_gpio.h:480
void px_gpio_out_set_hi(const px_gpio_handle_t *gpio)
Set GPIO pin output high.
Definition: px_gpio.h:408
void px_gpio_dir_set_in(const px_gpio_handle_t *gpio)
Set GPIO pin direction to input.
Definition: px_gpio.h:456
bool px_gpio_out_is_hi(const px_gpio_handle_t *gpio)
Test if GPIO pin output is set high.
Definition: px_gpio.h:426
void px_gpio_pull_up_enable(const px_gpio_handle_t *gpio)
Enable pull-up on GPIO pin.
Definition: px_gpio.h:474
void px_gpio_out_toggle(const px_gpio_handle_t *gpio)
Toggle GPIO pin output.
Definition: px_gpio.h:420
bool px_gpio_in_is_hi(const px_gpio_handle_t *gpio)
Test if GPIO pin input is high.
Definition: px_gpio.h:438
volatile uint8_t * px_gpio_reg_t
GPIO peripheral register address definition.
Definition: px_gpio.h:215
#define PX_LOG_NAME(name)
Macro to declare a log name string once for each file to reduce code size.
Definition: px_log.h:349
void px_gpio_init(const px_gpio_handle_t *gpio)
Initialise a GPIO pin using supplied handle.
Definition: px_gpio.c:69
GPIO pin handle definition.
Definition: px_gpio.h:114