aboutsummaryrefslogtreecommitdiffstats
path: root/src/gpio.c
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2018-01-04 11:47:43 -0500
committerClyne Sullivan <tullivan99@gmail.com>2018-01-04 11:47:43 -0500
commite5ae7f10f3e144f4a08ee7a66b4105a5aa86e6e7 (patch)
treeae084444f0ea8c91f9b29683f26e09699f11d3f3 /src/gpio.c
parent058c283919424ef8b4425cdf74739535dd1d8072 (diff)
initrd, lcd, file cleanup
Diffstat (limited to 'src/gpio.c')
-rw-r--r--src/gpio.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/gpio.c b/src/gpio.c
new file mode 100644
index 0000000..c2617ee
--- /dev/null
+++ b/src/gpio.c
@@ -0,0 +1,44 @@
+#include <gpio.h>
+
+void gpio_init(void)
+{
+ // enable clocks
+ RCC->AHB2ENR |= 0xFF;
+}
+
+void gpio_pupd(GPIO_TypeDef *port, uint8_t pin, uint8_t pupd)
+{
+ port->PUPDR &= ~(0x03 << (2 * pin));
+ port->PUPDR |= pupd << (2 * pin);
+}
+
+void gpio_speed(GPIO_TypeDef *port, uint8_t pin, uint8_t speed)
+{
+ port->OSPEEDR &= ~(0x03 << (2 * pin));
+ port->OSPEEDR |= speed << (2 * pin);
+}
+
+void gpio_type(GPIO_TypeDef *port, uint8_t pin, uint8_t type)
+{
+ port->OTYPER &= ~(1 << pin);
+ port->OTYPER |= type << pin;
+}
+
+void gpio_mode(GPIO_TypeDef *port, uint8_t pin, uint8_t mode)
+{
+ port->MODER &= ~(0x03 << (2 * pin));
+ port->MODER |= mode << (2 * pin);
+}
+
+void gpio_dout(GPIO_TypeDef *port, uint8_t pin, uint8_t val)
+{
+ if (val)
+ port->BSRR |= (1 << pin);
+ else
+ port->BRR |= (1 << pin);
+}
+
+uint8_t gpio_din(GPIO_TypeDef *port, uint8_t pin)
+{
+ return port->IDR & (1 << pin);
+}