From 5ba64844e2a61881ec4d853639a73da5ef7b2b72 Mon Sep 17 00:00:00 2001 From: joeycastillo Date: Wed, 18 Sep 2024 14:33:07 -0400 Subject: [PATCH] port GPIO functions to new framework --- Makefile | 1 + app.c | 6 +++-- watch-library/hardware/watch/watch_gpio.c | 33 ++++++++++++++--------- watch-library/shared/watch/watch.h | 2 +- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 2ae61724..4197d036 100644 --- 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 a8655b1a..e3083c01 100644 --- 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; diff --git a/watch-library/hardware/watch/watch_gpio.c b/watch-library/hardware/watch/watch_gpio.c index b37d009f..3e1d13df 100644 --- a/watch-library/hardware/watch/watch_gpio.c +++ b/watch-library/hardware/watch/watch_gpio.c @@ -24,38 +24,45 @@ #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)); + } } diff --git a/watch-library/shared/watch/watch.h b/watch-library/shared/watch/watch.h index 516f08e6..7f4b7640 100644 --- a/watch-library/shared/watch/watch.h +++ b/watch-library/shared/watch/watch.h @@ -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"