-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpio.h
97 lines (82 loc) · 3.52 KB
/
gpio.h
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/******************************************************************************
* gpio.h
*
* Created on: Oct 3, 2024
* Author: Malak
*******************************************************************************/
#ifndef GPIO_H_
#define GPIO_H_
#include "std_types.h"
/*******************************************************************************
* Definitions *
*******************************************************************************/
#define NUM_OF_PORTS 4
#define NUM_OF_PINS_PER_PORT 8
#define PORTA_ID 0
#define PORTB_ID 1
#define PORTC_ID 2
#define PORTD_ID 3
#define PIN0_ID 0
#define PIN1_ID 1
#define PIN2_ID 2
#define PIN3_ID 3
#define PIN4_ID 4
#define PIN5_ID 5
#define PIN6_ID 6
#define PIN7_ID 7
/*******************************************************************************
* Types Declaration *
*******************************************************************************/
typedef enum
{
PIN_INPUT,PIN_OUTPUT
}GPIO_PinDirectionType;
typedef enum
{
PORT_INPUT,PORT_OUTPUT=0xFF
}GPIO_PortDirectionType;
/*******************************************************************************
* Functions Prototypes *
*******************************************************************************/
/*
* Description :
* Setup the direction of the required pin input/output.
* If the input port number or pin number are not correct, The function will not handle the request.
*/
void GPIO_setupPinDirection(uint8 port_num, uint8 pin_num, GPIO_PinDirectionType direction);
/*
* Description :
* Write the value Logic High or Logic Low on the required pin.
* If the input port number or pin number are not correct, The function will not handle the request.
* If the pin is input, this function will enable/disable the internal pull-up resistor.
*/
void GPIO_writePin(uint8 port_num, uint8 pin_num, uint8 value);
/*
* Description :
* Read and return the value for the required pin, it should be Logic High or Logic Low.
* If the input port number or pin number are not correct, The function will return Logic Low.
*/
uint8 GPIO_readPin(uint8 port_num, uint8 pin_num);
/*
* Description :
* Setup the direction of the required port all pins input/output.
* If the direction value is PORT_INPUT all pins in this port should be input pins.
* If the direction value is PORT_OUTPUT all pins in this port should be output pins.
* If the input port number is not correct, The function will not handle the request.
*/
void GPIO_setupPortDirection(uint8 port_num, GPIO_PortDirectionType direction);
/*
* Description :
* Write the value on the required port.
* If any pin in the port is output pin the value will be written.
* If any pin in the port is input pin this will activate/deactivate the internal pull-up resistor.
* If the input port number is not correct, The function will not handle the request.
*/
void GPIO_writePort(uint8 port_num, uint8 value);
/*
* Description :
* Read and return the value of the required port.
* If the input port number is not correct, The function will return ZERO value.
*/
uint8 GPIO_readPort(uint8 port_num);
#endif /* GPIO_H_ */