From 41f70bd135d57f94f777d54c384e5ac8fa7ddffc Mon Sep 17 00:00:00 2001 From: Marco Date: Mon, 23 May 2022 21:26:15 +0200 Subject: [PATCH] Add file and functions for simple pin operations. --- src/include/pins.h | 5 +++++ src/pins.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/include/pins.h create mode 100644 src/pins.c diff --git a/src/include/pins.h b/src/include/pins.h new file mode 100644 index 0000000..5194449 --- /dev/null +++ b/src/include/pins.h @@ -0,0 +1,5 @@ +#include + +void togglePin(volatile uint8_t *port, unsigned int pin); +void unsetPin(volatile uint8_t *port, unsigned int pin); +void setPin(volatile uint8_t *port, unsigned int pin); \ No newline at end of file diff --git a/src/pins.c b/src/pins.c new file mode 100644 index 0000000..69cae33 --- /dev/null +++ b/src/pins.c @@ -0,0 +1,28 @@ +#include + +#include "pins.h" + +void setPin(volatile uint8_t *port, unsigned int pin) +{ + *port |= (1 << pin); + printf("Port %d, Pin %d set\n\r", port, pin); +} + +void unsetPin(volatile uint8_t *port, unsigned int pin) +{ + *port &= ~(1 << pin); + printf("Port %d, Pin %d unset\n\r", port, pin); +} + +void togglePin(volatile uint8_t *port, unsigned int pin) +{ + *port ^= (1 << pin); + printf("Port %d, Pin %d toggled to ", port, pin); + + if ((*port & (1 << pin)) > 0) + printf("on"); + else + printf("off"); + + printf("\n\r"); +} \ No newline at end of file