]> git.earman.xyz Git - sensor-watch.git/commitdiff
port GPIO functions to new framework
authorjoeycastillo <joeycastillo@utexas.edu>
Wed, 18 Sep 2024 18:33:07 +0000 (14:33 -0400)
committerjoeycastillo <joeycastillo@utexas.edu>
Wed, 18 Sep 2024 18:33:07 +0000 (14:33 -0400)
Makefile
app.c
watch-library/hardware/watch/watch_gpio.c
watch-library/shared/watch/watch.h

index 2ae61724597bee403081e4cd157d8b7f6d99a7ad..4197d036f0fdb8760b0e9298a4273774a8dc3828 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -29,6 +29,7 @@ INCLUDES += \
 
 # Add your source files here.
 SRCS += \
+  ./watch-library/hardware/watch/watch_gpio.c \
   ./app.c \
 
 # Finally, leave this line at the bottom of the file.
diff --git a/app.c b/app.c
index a8655b1a52d7a7ed4677ee4220ee71d3489d8df9..e3083c01f72ff65b0e404e681633af1b583f4a6b 100644 (file)
--- a/app.c
+++ b/app.c
@@ -6,11 +6,13 @@ void app_init(void) {
 }
 
 void app_setup(void) {
-    HAL_GPIO_GREEN_out();
+    watch_enable_digital_output(HAL_GPIO_GREEN_pin());
 }
 
 bool app_loop(void) {
-    HAL_GPIO_GREEN_toggle();
+    watch_set_pin_level(HAL_GPIO_GREEN_pin(), true);
+    delay_ms(500);
+    watch_set_pin_level(HAL_GPIO_GREEN_pin(), false);
     delay_ms(500);
 
     return false;
index b37d009f17cab40dde9a108a4bedd10bc6df2080..3e1d13dfbc1cdbe6cc3e31898bc767f5b847e084 100644 (file)
 
 #include "watch_gpio.h"
 
- void watch_enable_digital_input(const uint8_t pin) {
-    gpio_set_pin_direction(pin, GPIO_DIRECTION_IN);
-    gpio_set_pin_function(pin, GPIO_PIN_FUNCTION_OFF);
+inline void watch_enable_digital_input(const uint8_t pin) {
+    PORT->Group[pin >> 5].DIRCLR.reg = (1 << (pin & 0x1F));
+    PORT->Group[pin >> 5].PINCFG[pin & 0x1F].reg |= PORT_PINCFG_INEN;
+    PORT->Group[pin >> 5].PINCFG[pin & 0x1F].reg &= ~PORT_PINCFG_PULLEN;
 }
 
 void watch_disable_digital_input(const uint8_t pin) {
-    gpio_set_pin_direction(pin, GPIO_DIRECTION_OFF);
-    gpio_set_pin_pull_mode(pin, GPIO_PULL_OFF);
-    gpio_set_pin_function(pin, GPIO_PIN_FUNCTION_OFF);
+    PORT->Group[pin >> 5].DIRCLR.reg = (1 << (pin & 0x1F));
+    PORT->Group[pin >> 5].PINCFG[pin & 0x1F].reg &= ~(PORT_PINCFG_PULLEN | PORT_PINCFG_INEN);
 }
 
 void watch_enable_pull_up(const uint8_t pin) {
-    gpio_set_pin_pull_mode(pin, GPIO_PULL_UP);
+    PORT->Group[pin >> 5].OUTSET.reg = (1 << (pin & 0x1F));
+    PORT->Group[pin >> 5].PINCFG[pin & 0x1F].reg |= PORT_PINCFG_PULLEN;
 }
 
 void watch_enable_pull_down(const uint8_t pin) {
-    gpio_set_pin_pull_mode(pin, GPIO_PULL_DOWN);
+    PORT->Group[pin >> 5].OUTCLR.reg = (1 << (pin & 0x1F));
+    PORT->Group[pin >> 5].PINCFG[pin & 0x1F].reg |= PORT_PINCFG_PULLEN;
 }
 
 bool watch_get_pin_level(const uint8_t pin) {
-    return gpio_get_pin_level(pin);
+    return (PORT->Group[pin >> 5].IN.reg & (1 << (pin & 0x1F))) != 0;
 }
 
 void watch_enable_digital_output(const uint8_t pin) {
-    gpio_set_pin_direction(pin, GPIO_DIRECTION_OUT);
-    gpio_set_pin_function(pin, GPIO_PIN_FUNCTION_OFF);
+    PORT->Group[pin >> 5].DIRSET.reg = (1 << (pin & 0x1F));
+    PORT->Group[pin >> 5].PINCFG[pin & 0x1F].reg |= PORT_PINCFG_INEN;
 }
 
 void watch_disable_digital_output(const uint8_t pin) {
-    gpio_set_pin_direction(pin, GPIO_DIRECTION_OFF);
+    PORT->Group[pin >> 5].DIRCLR.reg = (1 << (pin & 0x1F));
+    PORT->Group[pin >> 5].PINCFG[pin & 0x1F].reg &= ~(PORT_PINCFG_PULLEN | PORT_PINCFG_INEN);
 }
 
 void watch_set_pin_level(const uint8_t pin, const bool level) {
-    gpio_set_pin_level(pin, level);
+    if (level) {
+        PORT->Group[pin >> 5].OUTSET.reg = (1 << (pin & 0x1F));
+    } else {
+        PORT->Group[pin >> 5].OUTCLR.reg = (1 << (pin & 0x1F));
+    }
 }
index 516f08e604e4641aa6a86874a54d38ecaf1708d7..7f4b7640ff012bf6cedd46c737c56fd17a8cec83 100644 (file)
@@ -63,7 +63,7 @@
 // #include "watch_led.h"
 // #include "watch_buzzer.h"
 // #include "watch_adc.h"
-// #include "watch_gpio.h"
+#include "watch_gpio.h"
 // #include "watch_i2c.h"
 // #include "watch_spi.h"
 // #include "watch_uart.h"