-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpio.c
79 lines (74 loc) · 2.53 KB
/
gpio.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
78
79
/*
* gpio.c
*
* Created on: 23 jul. 2020
* Author: Matías Lopez - Jesús López
*/
//*****************************************************************************
//
// gpio.c - Driver para manejar los pines de uC.
//
//*****************************************************************************
//*****************************************************************************
#include "gpio.h"
//*****************************************************************************
void GPIO_configPins(uint16_t* selectedPort, uint16_t* selectedPin)
{
uint16_t port = *(selectedPort);
uint8_t pin = *(selectedPin);
switch (port)
{
case 1:
*(selectedPin) = (0x0001 << pin);
*(selectedPort) = 0x0200;
break;
case 2:
*(selectedPin) = (0x0001 << pin);
*(selectedPin) <<= 8;
*(selectedPort) = 0x0200;
break;
case 3:
*(selectedPin) = (0x0001 << pin);
*(selectedPort) = 0x0220;
break;
case 4:
*(selectedPin) = (0x0001 << pin);
*(selectedPin) <<= 8;
*(selectedPort) = 0x0220;
break;
case 5:
*(selectedPin) = (0x0001 << pin);
*(selectedPort) = 0x0240;
break;
case 6:
*(selectedPin) = (0x0001 << pin);
*(selectedPin) <<= 8;
*(selectedPort) = 0x0240;
break;
case 7:
*(selectedPin) = (0x0001 << pin);
*(selectedPort) = 0x0260;
break;
case 8:
*(selectedPin) = (0x0001 << pin);
*(selectedPin) <<= 8;
*(selectedPort) = 0x0260;
break;
}
}
//*****************************************************************************
void GPIO_powerOnSensor(const uint8_t vccPort, const uint8_t vccPin)
{
uint16_t selectedPortVcc = vccPort;
uint16_t selectedPinVcc = vccPin;
GPIO_configPins(&selectedPortVcc, &selectedPinVcc);
GPIO_setHighOnPin(selectedPortVcc, selectedPinVcc);
}
//*****************************************************************************
void GPIO_powerOffSensor(const uint8_t vccPort, const uint8_t vccPin)
{
uint16_t selectedPortVcc = vccPort;
uint16_t selectedPinVcc = vccPin;
GPIO_configPins(&selectedPortVcc, &selectedPinVcc);
GPIO_setLowOnPin(selectedPortVcc, selectedPinVcc);
}