aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-12-08 14:22:05 -0700
committerJosh Rahm <joshuarahm@gmail.com>2024-12-08 14:22:05 -0700
commitf89f75b5616de99865448f41b068a2783cd3648e (patch)
tree1e7599b8915d3fbb9a1a10892ba58fd44bea3f5d /include
parent546a5ccdba66dd8d8c19ce6d8486f46c84637cf2 (diff)
downloadch573-f89f75b5616de99865448f41b068a2783cd3648e.tar.gz
ch573-f89f75b5616de99865448f41b068a2783cd3648e.tar.bz2
ch573-f89f75b5616de99865448f41b068a2783cd3648e.zip
Cleaned up GPIO code quite a bit.
Diffstat (limited to 'include')
-rw-r--r--include/gpio.h88
1 files changed, 88 insertions, 0 deletions
diff --git a/include/gpio.h b/include/gpio.h
new file mode 100644
index 0000000..ab793f1
--- /dev/null
+++ b/include/gpio.h
@@ -0,0 +1,88 @@
+#pragma once
+
+#include "ch573/gpio.h"
+
+#define GPIO_PORT_A ch573_gpio__gpio_port_a
+#define GPIO_PORT_B ch573_gpio__gpio_port_b
+#define GPIO_PORT CH573_GPIO__GPIO_PORT_T_INTF
+#define GPIO_I CH573_GPIO__GPIO_T_INTF
+#define GPIO ch573_gpio__gpio
+
+#define IS_PORT_B 0x80
+
+typedef enum {
+ PIN_PA4 = 4,
+ PIN_PA5 = 5,
+
+ PIN_PA8 = 8,
+ PIN_PA9 = 9,
+ PIN_PA10 = 10,
+ PIN_PA11 = 11,
+ PIN_PA12 = 12,
+ PIN_PA13 = 13,
+ PIN_PA14 = 14,
+ PIN_PA15 = 15,
+
+ PIN_PB0 = IS_PORT_B | 0,
+ PIN_PB4 = IS_PORT_B | 4,
+ PIN_PB6 = IS_PORT_B | 6,
+ PIN_PB7 = IS_PORT_B | 7,
+
+ PIN_PB10 = IS_PORT_B | 10,
+ PIN_PB11 = IS_PORT_B | 11,
+ PIN_PB12 = IS_PORT_B | 12,
+ PIN_PB13 = IS_PORT_B | 13,
+ PIN_PB14 = IS_PORT_B | 14,
+ PIN_PB15 = IS_PORT_B | 15,
+
+ PIN_PB22 = IS_PORT_B | 8,
+ PIN_PB23 = IS_PORT_B | 9,
+} gpio_pin_t;
+
+typedef enum {
+ PIN_CFG_INPUT_FLOATING,
+ PIN_CFG_INPUT_PULL_UP,
+ PIN_CFG_INPUT_PULL_DOWN,
+ PIN_CFG_OUTPUT_5mA,
+ PIN_CFG_OUTPUT_20mA,
+} gpio_config_t;
+
+typedef enum {
+ AF_SPI = 8,
+ AF_UART1 = 5,
+ AF_UART0 = 4,
+ AF_TMR2 = 2,
+ AF_TMR1 = 1,
+ AF_TMR0 = 0,
+} alternate_function_t;
+
+typedef enum {
+ INT_MODE_FALLING_EDGE,
+ INT_MODE_RISING_EDGE,
+ INT_MODE_LEVEL_HIGH,
+ INT_MODE_LEVEL_LOW
+} interrupt_mode_t;
+
+typedef void (*gpio_callback_t)(gpio_pin_t pin);
+
+#define On_Gpio(arg) \
+ static void __local_on_gpio__(gpio_pin_t pin); \
+ __attribute__((__section__( \
+ ".gpio_callbacks"))) static volatile gpio_callback_t __gpio__position = \
+ __local_on_gpio__; \
+ static void __local_on_gpio__(arg)
+
+/** Configure the given gpio pin for .*/
+void configure_gpio(gpio_pin_t pin, gpio_config_t);
+
+/** Read the input value of the gpio. */
+int read_gpio(gpio_pin_t pin);
+
+/** Sets the gpio pin. */
+void set_gpio(gpio_pin_t pin, int high);
+
+/** Set or unset the peripheral to the alternate set of pins. */
+void enable_alternate_funciton(alternate_function_t af, int enable);
+
+/** Enables the interrupt for a with the provided interrupt mode. */
+void enable_gpio_interrupt(gpio_pin_t pin, interrupt_mode_t int_mode);