port GPIO functions to new framework
This commit is contained in:
parent
c02132a68f
commit
5ba64844e2
1
Makefile
1
Makefile
@ -29,6 +29,7 @@ INCLUDES += \
|
|||||||
|
|
||||||
# Add your source files here.
|
# Add your source files here.
|
||||||
SRCS += \
|
SRCS += \
|
||||||
|
./watch-library/hardware/watch/watch_gpio.c \
|
||||||
./app.c \
|
./app.c \
|
||||||
|
|
||||||
# Finally, leave this line at the bottom of the file.
|
# Finally, leave this line at the bottom of the file.
|
||||||
|
|||||||
6
app.c
6
app.c
@ -6,11 +6,13 @@ void app_init(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void app_setup(void) {
|
void app_setup(void) {
|
||||||
HAL_GPIO_GREEN_out();
|
watch_enable_digital_output(HAL_GPIO_GREEN_pin());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool app_loop(void) {
|
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);
|
delay_ms(500);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -24,38 +24,45 @@
|
|||||||
|
|
||||||
#include "watch_gpio.h"
|
#include "watch_gpio.h"
|
||||||
|
|
||||||
void watch_enable_digital_input(const uint8_t pin) {
|
inline void watch_enable_digital_input(const uint8_t pin) {
|
||||||
gpio_set_pin_direction(pin, GPIO_DIRECTION_IN);
|
PORT->Group[pin >> 5].DIRCLR.reg = (1 << (pin & 0x1F));
|
||||||
gpio_set_pin_function(pin, GPIO_PIN_FUNCTION_OFF);
|
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) {
|
void watch_disable_digital_input(const uint8_t pin) {
|
||||||
gpio_set_pin_direction(pin, GPIO_DIRECTION_OFF);
|
PORT->Group[pin >> 5].DIRCLR.reg = (1 << (pin & 0x1F));
|
||||||
gpio_set_pin_pull_mode(pin, GPIO_PULL_OFF);
|
PORT->Group[pin >> 5].PINCFG[pin & 0x1F].reg &= ~(PORT_PINCFG_PULLEN | PORT_PINCFG_INEN);
|
||||||
gpio_set_pin_function(pin, GPIO_PIN_FUNCTION_OFF);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void watch_enable_pull_up(const uint8_t pin) {
|
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) {
|
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) {
|
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) {
|
void watch_enable_digital_output(const uint8_t pin) {
|
||||||
gpio_set_pin_direction(pin, GPIO_DIRECTION_OUT);
|
PORT->Group[pin >> 5].DIRSET.reg = (1 << (pin & 0x1F));
|
||||||
gpio_set_pin_function(pin, GPIO_PIN_FUNCTION_OFF);
|
PORT->Group[pin >> 5].PINCFG[pin & 0x1F].reg |= PORT_PINCFG_INEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
void watch_disable_digital_output(const uint8_t pin) {
|
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) {
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,7 +63,7 @@
|
|||||||
// #include "watch_led.h"
|
// #include "watch_led.h"
|
||||||
// #include "watch_buzzer.h"
|
// #include "watch_buzzer.h"
|
||||||
// #include "watch_adc.h"
|
// #include "watch_adc.h"
|
||||||
// #include "watch_gpio.h"
|
#include "watch_gpio.h"
|
||||||
// #include "watch_i2c.h"
|
// #include "watch_i2c.h"
|
||||||
// #include "watch_spi.h"
|
// #include "watch_spi.h"
|
||||||
// #include "watch_uart.h"
|
// #include "watch_uart.h"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user