-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDRV_PCF8574.h
More file actions
154 lines (133 loc) · 3.82 KB
/
DRV_PCF8574.h
File metadata and controls
154 lines (133 loc) · 3.82 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*********************************.FILE_HEADER.*******************************
<Copyright Notice>
.File :drv_PCF8574.h
.Summary :header file of PCF8574 driver
.Note :
Author Date Description
------------------------------------------------------------------------------
<Author name> <DDMMMYYYY> <changes made>
AFIL 26-04-2025 Created driver
******************************************************************************/
#ifndef DRV_PCF8574_H_
#define DRV_PCF8574_H_
/************************** defines ******************************************/
/********************** typedef enums *****************************************/
#define ADDRESS_I2C_PCF8574 (0x20)
#define PCF8574_MAX_CHANNEL (8U)
#define PCF8574_GPIO_RESET_STATE (0xFF)
/* I2c transfer types */
typedef enum
{
I2C_NORMAL = 0U,
I2C_INTERUPT,
I2C_DMA
}I2C_TRANSFER_TYPE;
typedef enum
{
GPX_PIN_MODE_OUTPUT = 0U,
GPX_PIN_MODE_INPUT = 1U,
}PCF8547_PIN_MODE;
/* Current operation */
typedef enum
{
IO_IDLE = 0U,
IO_READ,
IO_WRITE,
IO_TOGGLE,
IO_INTERRUPT
} PCF8574_Operation;
/* function return types */
typedef enum
{
RETURN_ERROR = 0U,
RETURN_SUCCESS
}ReturnType;
typedef enum
{
PIN0 = 0U,
PIN1,
PIN2,
PIN3,
PIN4,
PIN5,
PIN6,
PIN7,
ALL_PINS
} PCF8574_PinType;
/**************************** typedef structures ********************************/
/* Flag status structure */
typedef struct
{
uint8_t ReadStatus_Flag : 1;
uint8_t WriteStatus_Flag : 1;
uint8_t ToggleStatus_Flag : 1;
uint8_t InterruptStatus_Flag : 1;
uint8_t reserved_flags : 4;
}PCF8574_FlagStatus_st;
/* Pin state structure */
typedef union
{
struct
{
uint8_t P0 : 1; // Pin 0
uint8_t P1 : 1; // Pin 1
uint8_t P2 : 1; // Pin 2
uint8_t P3 : 1; // Pin 3
uint8_t P4 : 1; // Pin 4
uint8_t P5 : 1; // Pin 5
uint8_t P6 : 1; // Pin 6
uint8_t P7 : 1; // Pin 7
} bit;
uint8_t all; // Access all 8 bits directly
} PCF8574_PinState_st;
/* Pin mode structure */
typedef union
{
struct
{
uint8_t P0 : 1; // Pin 0
uint8_t P1 : 1; // Pin 1
uint8_t P2 : 1; // Pin 2
uint8_t P3 : 1; // Pin 3
uint8_t P4 : 1; // Pin 4
uint8_t P5 : 1; // Pin 5
uint8_t P6 : 1; // Pin 6
uint8_t P7 : 1; // Pin 7
} bit;
uint8_t all; // Access all 8 bits directly
} PCF8574_PinMode_st;
typedef struct
{
PCF8574_FlagStatus_st flags;
PCF8574_PinState_st pinState; /* Output register (with bits and full byte access)*/
PCF8574_PinMode_st pinMode;
PCF8574_Operation currOperation;
uint8_t dev_address; /* I2c Address */
} PCF8574_HandleType;
/**************************** functions ***************************************/
/* PCF8574 related functions */
ReturnType PCF8574_Init(PCF8574_HandleType *hpcf,uint8_t device_address);
ReturnType PCF8574_Read(PCF8574_HandleType *hpcf,
PCF8574_PinType pin,
I2C_TRANSFER_TYPE mode);
ReturnType PCF8574_Write(PCF8574_HandleType *hpcf,
PCF8574_PinType pin,
uint8_t* data,
I2C_TRANSFER_TYPE mode);
ReturnType PCF8574_Toggle(PCF8574_HandleType *hpcf,
PCF8574_PinType pin,
I2C_TRANSFER_TYPE mode);
PCF8574_Operation PCF8574_GetOpStatus(PCF8574_HandleType *hpcf);
ReturnType PCF8574_GetPinState(PCF8574_HandleType *hpcf, uint8_t* state);
ReturnType PCF8574_GetFlagStatus(PCF8574_HandleType *hpcf,
PCF8574_Operation op,
uint8_t* status);
ReturnType PCF8574_ClearFlagStatus(PCF8574_HandleType *hpcf,
PCF8574_Operation op);
ReturnType PCF8574_SetPinMode(PCF8574_HandleType *hpcf,
PCF8574_PinType pin,
PCF8547_PIN_MODE mode);
void Callback_IRQ_INT_Pin(void);
void Callback_PCF8574TxComplete(void);
void Callback_PCF8574RxComplete(void);
#endif /* DRV_PCF8574_H_ */