Add file and functions for simple pin operations.
This commit is contained in:
parent
514cb2020b
commit
41f70bd135
5
src/include/pins.h
Normal file
5
src/include/pins.h
Normal 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
28
src/pins.c
Normal 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");
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user