pin.c 810 Bytes
Newer Older
Jake Read's avatar
Jake Read committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
/*
 * pin.c
 *
 * Created: 6/18/2018 12:22:50 PM
 *  Author: Jake
 */ 

#include "pin.h"

void pin_init(pin_t *pin, PORT_t *port, uint8_t pin_bm, uint8_t pin_pos, uint8_t inout){
	pin->port = port;
	pin->pin_bm = pin_bm;
	pin->pin_pos = pin_pos;
	if(inout){
		pin_output(pin);
	} else {
		pin_input(pin);
	}
}

void pin_output(pin_t *pin){
	pin->port->DIRSET = pin->pin_bm;
}

void pin_set(pin_t *pin){
	pin->port->OUTSET = pin->pin_bm;
}
void pin_clear(pin_t *pin){
	pin->port->OUTCLR = pin->pin_bm;
}

void pin_toggle(pin_t *pin){
	pin->port->OUTTGL = pin->pin_bm;
}

void pin_input(pin_t *pin){
	pin->port->DIRCLR = pin->pin_bm;
}

void pin_pullup(pin_t *pin){
	// ? how to access PIN0CTRL, etc?
}
void pin_pulldown(pin_t *pin){
	// 
}

uint8_t pin_read(pin_t *pin){
	return (pin->port->IN & pin->pin_bm);
}