pin.c 925 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
/*
 * pin.c
 *
 * Created: 2/5/2018 11:21:37 PM
 *  Author: Jake
 */ 

#include "pin.h"
#include "sam.h"

pin_t pin_new(PortGroup *port, uint32_t pin_number){
	pin_t pin;
	pin.port = port;
14
	pin.pin = pin_number;
15
16
17
18
19
20
21
22
23
24
25
26
	pin.bm = (uint32_t)(1 << pin_number);
	return pin;
}


void pin_output(pin_t *pin){
	pin->port->DIRSET.reg = pin->bm;
	pin->port->OUTCLR.reg = pin->bm;
}

void pin_input(pin_t *pin){
	pin->port->DIRCLR.reg = pin->bm;
27
28
29
30
31
32
33
34
35
36
	pin->port->PINCFG[pin->pin].bit.INEN = 1;
}

void pin_pullup(pin_t *pin){
	pin->port->PINCFG[pin->pin].bit.PULLEN = 1;
	pin->port->OUTSET.reg |= pin->bm;
}

void pin_pulldown(pin_t *pin){
	pin->port->PINCFG[pin->pin].bit.PULLEN = 1;
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
}

void pin_set(pin_t *pin){
	pin->port->OUTSET.reg = pin->bm;
}

void pin_clear(pin_t *pin){
	pin->port->OUTCLR.reg = pin->bm;
}

void pin_toggle(pin_t *pin){
	pin->port->OUTTGL.reg = pin->bm;
}

int pin_read(pin_t *pin){
	return pin->port->IN.reg & pin->bm;
}