aboutsummaryrefslogtreecommitdiff
path: root/src/gpio.h
diff options
context:
space:
mode:
authorVictor Mignot <victor@vmignot.fr>2025-07-30 21:22:47 +0200
committerVictor Mignot <victor@vmignot.fr>2025-08-11 14:07:27 +0200
commit31eb5b5de15908fecf3a615910b3273de62baeeb (patch)
tree9ea253c9a695a85257caa36df26299424ccc21fe /src/gpio.h
parentc4314b35efe14fd0c1c57c8c3577431b380e323e (diff)
downloadnanji-31eb5b5de15908fecf3a615910b3273de62baeeb.tar.gz
nrf52832: add GPIO drivers
Diffstat (limited to 'src/gpio.h')
-rw-r--r--src/gpio.h101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/gpio.h b/src/gpio.h
new file mode 100644
index 0000000..adcf76a
--- /dev/null
+++ b/src/gpio.h
@@ -0,0 +1,101 @@
+#ifndef GPIO_H
+#define GPIO_H
+
+#include "types.h"
+
+/* GPIO pins used for the LCD display */
+#define PIN_DISPLAY_SPI_CLOCK PIN_2
+#define PIN_DISPLAY_SPI_MOSI PIN_3
+#define PIN_DISPLAY_COMMAND_DATA PIN_18
+#define PIN_DISPLAY_CHIP_SELECT PIN_25
+#define PIN_DISPLAY_RESET PIN_26
+
+/* GPIO pins used for the touch panel */
+#define PIN_TOUCH_PANEL_RESET PIN_10
+#define PIN_TOUCH_PANEL_IRQ PIN_28
+#define PIN_TOUCH_PANEL_I2C_SDA PIN_06
+#define PIN_TOUCH_PANEL_I2C_SCL PIN_07
+
+/* GPIO pins used for the battery management */
+#define PIN_BATTERY_CHARGE_INDICATOR PIN_12
+#define PIN_BATTERY_VOLTAGE PIN_31
+
+/* GPIO pins used for the button */
+#define PIN_BUTTON_ENABLE PIN_15
+#define PIN_BUTTON_PRESS PIN_13
+
+/* GPIO pins used for the accelerometer */
+#define PIN_ACCEL_I2C_SDA PIN_06
+#define PIN_ACCEL_I2C_SCL PIN_07
+#define PIN_ACCEL_IRQ PIN_08
+
+/**
+ * The signal level of a GPIO line.
+ */
+enum gpio_level {
+ LOW = 0,
+ HIGH = 1,
+};
+
+/**
+ * The availables GPIO pins on the NRF82832.
+ */
+enum gpio_pin {
+ PIN_0 = 0,
+ PIN_1 = 1,
+ PIN_2 = 2,
+ PIN_3 = 3,
+ PIN_4 = 4,
+ PIN_5 = 5,
+ PIN_6 = 6,
+ PIN_7 = 7,
+ PIN_8 = 8,
+ PIN_9 = 9,
+ PIN_10 = 10,
+ PIN_11 = 11,
+ PIN_12 = 12,
+ PIN_13 = 13,
+ PIN_14 = 14,
+ PIN_15 = 15,
+ PIN_16 = 16,
+ PIN_17 = 17,
+ PIN_18 = 18,
+ PIN_19 = 19,
+ PIN_20 = 20,
+ PIN_21 = 21,
+ PIN_22 = 22,
+ PIN_23 = 23,
+ PIN_24 = 24,
+ PIN_25 = 25,
+ PIN_26 = 26,
+ PIN_27 = 27,
+ PIN_28 = 28,
+ PIN_29 = 29,
+ PIN_30 = 30,
+ PIN_31 = 31,
+};
+
+/**
+ * Init the given pin.
+ * Note that each pin configuration is hardcoded to fit the peripheral it is connected to.
+ */
+void gpio_init_pin(enum gpio_pin pin);
+
+/**
+ * Disable a GPIO pin.
+ */
+u8 gpio_disable_pin(enum gpio_pin pin);
+
+/**
+ * Read the current signal level of the given GPIO pin.
+ */
+enum gpio_level gpio_read_pin(enum gpio_pin pin);
+
+/**
+ * Set the given GPIO pin to the given level.
+ * Returns 0 if the given pin is not an output pin.
+ * Returns 1 if written successfully
+ */
+u8 gpio_write_pin(enum gpio_pin pin, enum gpio_level level);
+
+#endif