Add file and functions for simple pin operations.

This commit is contained in:
Marco 2022-05-23 21:26:15 +02:00
parent 514cb2020b
commit 41f70bd135
2 changed files with 33 additions and 0 deletions

5
src/include/pins.h Normal file
View File

@ -0,0 +1,5 @@
#include <inttypes.h>
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);

28
src/pins.c Normal file
View File

@ -0,0 +1,28 @@
#include <inttypes.h>
#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");
}