aboutsummaryrefslogtreecommitdiffstats
path: root/include/gpio.h
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2018-03-01 13:03:40 -0500
committerClyne Sullivan <tullivan99@gmail.com>2018-03-01 13:03:40 -0500
commit51b884c44c858aa56aae6675a2c3a8b2d882768e (patch)
treeaf052ed484d44e6594b18f01a4edceabd99b852c /include/gpio.h
parent4614429f5751e14e37ceedb7130b7a829c89476a (diff)
keypad support, making stuff good
Diffstat (limited to 'include/gpio.h')
-rw-r--r--include/gpio.h96
1 files changed, 83 insertions, 13 deletions
diff --git a/include/gpio.h b/include/gpio.h
index 524b791..46a8e15 100644
--- a/include/gpio.h
+++ b/include/gpio.h
@@ -1,46 +1,116 @@
+/**
+ * @file gpio.h
+ * Abstracts gpio access, makes things easier
+ */
+
#ifndef GPIO_H_
#define GPIO_H_
#include <stm32l476xx.h>
+/**
+ * Helps simplify gpio calls.
+ * @param p port, e.g. GPIOA
+ * @param b pin, e.g. 4
+ */
#define GPIO_PORT(p, b) GPIO##p, b
+/**
+ * Defines possible modes for a gpio pin
+ */
enum GPIO_MODE
{
- INPUT = 0,
- OUTPUT,
- ALTERNATE,
- ANALOG
+ INPUT = 0, /**< digital input */
+ OUTPUT, /**< digital output */
+ ALTERNATE, /**< alternate function */
+ ANALOG /**< analog function */
};
+/**
+ * Defines whether to use push-pull or open drain.
+ */
enum GPIO_TYPE
{
- PUSHPULL = 0,
- OPENDRAIN
+ PUSHPULL = 0, /**< push-pull */
+ OPENDRAIN /**< open drain */
};
+/**
+ * Defines the pin's speed
+ */
enum GPIO_SPEED
{
- LOW = 0,
- MEDIUM,
- HIGH,
- VERYHIGH
+ LOW = 0, /**< low */
+ MEDIUM, /**< medium */
+ HIGH, /**< high */
+ VERYHIGH /**< very high/maximum */
};
+/**
+ * Defines if a pullup or pulldown should be used.
+ */
enum GPIO_PUPD
{
- NOPUPD,
- PULLUP,
- PULLDOWN
+ NOPUPD, /**< no pullup/pulldown */
+ PULLUP, /**< use pullup */
+ PULLDOWN /**< use pulldown */
};
+/**
+ * Initializes the gpio.
+ */
void gpio_init(void);
+/**
+ * Enables or disables pullup/pulldown for the given pin.
+ * @param port the port, e.g. GPIOA
+ * @param pin the pin
+ * @param pupd pullup/pulldown enable
+ * @see GPIO_PUPD
+ */
void gpio_pupd(GPIO_TypeDef *port, uint8_t pin, uint8_t pupd);
+
+/**
+ * Sets whether to use push-pull or open drain for the given pin.
+ * @param port the port
+ * @param pin the pin
+ * @param type what to use
+ * @see GPIO_TYPE
+ */
void gpio_type(GPIO_TypeDef *port, uint8_t pin, uint8_t type);
+
+/**
+ * Sets the pin's speed.
+ * @param port the port
+ * @param pin the pin
+ * @param speed the speed to use
+ * @see GPIO_SPEED
+ */
void gpio_speed(GPIO_TypeDef *port, uint8_t pin, uint8_t speed);
+
+/**
+ * Sets the pin's i/o mode.
+ * @param port the port
+ * @param pin the pin
+ * @param mode the mode to use
+ * @see GPIO_MODE
+ */
void gpio_mode(GPIO_TypeDef *port, uint8_t pin, uint8_t mode);
+
+/**
+ * Sets the state of a digital output pin.
+ * @param port the port
+ * @param pin the pin
+ * @param val non-zero for high, zero for low
+ */
void gpio_dout(GPIO_TypeDef *port, uint8_t pin, uint8_t val);
+
+/**
+ * Reads a digital input pin.
+ * @param port the port
+ * @param pin the pin
+ * @return non-zero for high, zero for low
+ */
uint8_t gpio_din(GPIO_TypeDef *port, uint8_t pin);
#endif // GPIO_H_