-
Notifications
You must be signed in to change notification settings - Fork 0
/
OptoGPIOConfig.c
77 lines (71 loc) · 2.08 KB
/
OptoGPIOConfig.c
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* OptoGPIOConfig.c
*
*
* Author: Caroline
*/
#include "avr32\uc3l064.h"
#include "avr32\gpio_211.h"
#include "OptoGPIOConfig.h"
void assign_gpio_module(unsigned int pin_num, unsigned int pin_mod){
volatile avr32_gpio_port_t *gpio_port = &AVR32_GPIO.port[pin_num>>5];
switch(pin_mod){
// pmr - peripheral mux register
// to set peripheral function, we need to write
// to the correct PMRn indices
case 0:
// Function = A
gpio_port->pmr0c = (1<<(pin_num & 0x1F));
gpio_port->pmr1c = (1<<(pin_num & 0x1F));
gpio_port->pmr2c = (1<<(pin_num & 0x1F));
break;
case 1:
// Function = B
gpio_port->pmr0s = (1<<(pin_num & 0x1F));
gpio_port->pmr1c = (1<<(pin_num & 0x1F));
gpio_port->pmr2c = (1<<(pin_num & 0x1F));
break;
case 2:
// Function = C
gpio_port->pmr0c = (1<<(pin_num & 0x1F));
gpio_port->pmr1s = (1<<(pin_num & 0x1F));
gpio_port->pmr2c = (1<<(pin_num & 0x1F));
break;
case 3:
// Function = D
gpio_port->pmr0s = (1<<(pin_num & 0x1F));
gpio_port->pmr1s = (1<<(pin_num & 0x1F));
gpio_port->pmr2c = (1<<(pin_num & 0x1F));
break;
case 4:
// Function = E
gpio_port->pmr0c = (1<<(pin_num & 0x1F));
gpio_port->pmr1c = (1<<(pin_num & 0x1F));
gpio_port->pmr2s = (1<<(pin_num & 0x1F));
case 5:
// Function = F
gpio_port->pmr0s = (1<<(pin_num & 0x1F));
gpio_port->pmr1c = (1<<(pin_num & 0x1F));
gpio_port->pmr2s = (1<<(pin_num & 0x1F));
case 6:
// Function = G
gpio_port->pmr0c = (1<<(pin_num & 0x1F));
gpio_port->pmr1s = (1<<(pin_num & 0x1F));
gpio_port->pmr2s = (1<<(pin_num & 0x1F));
case 7:
// Function = H
gpio_port->pmr0s = (1<<(pin_num & 0x1F));
gpio_port->pmr1s = (1<<(pin_num & 0x1F));
gpio_port->pmr2s = (1<<(pin_num & 0x1F));
default:
// Invalid GPIO
return;
}
// Disable GPIO function for pin to enable peripheral
gpio_port->gperc = (1<<(pin_num & 0x1F));
}
void enable_gpio_pin(unsigned int pin_num){
volatile avr32_gpio_port_t *gpio_port = &AVR32_GPIO.port[pin_num>>5];
gpio_port->oderc = (1 << (pin_num & 0x1F));
gpio_port->gpers = (1 << (pin_num & 0x1F));
}