-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMCP23017.h
129 lines (95 loc) · 3.57 KB
/
MCP23017.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
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
#ifndef _EXPANDER_I2C_H
#define _EXPANDER_I2C_H
/**
* @file expander-i2c.h
* @author Hamza RAHAL
* @brief
* @version 0.2
* @date 2022-05-19
*
* @copyright Saemload (c) 2022
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <linux/ioctl.h>
#include <linux/types.h>
#include <linux/i2c-dev.h>
#include <stdarg.h>
#include <wiringPi.h>
#include <wiringPiI2C.h>
// pour les printf colorés
#define RESET "\033[0m"
#define GREEN "\033[32m"
#define RED "\033[31m"
#define I2C_DEVICE "/dev/i2c-1"
#define VERSION_EXPANDER_I2C "1.0"
#define MAX_STRING 255
//l'expander 0x26
#define RCD_RESET 6 // Pin pour controler le mode de calcul de l'ADE
#define RCD_TST 5 // Pin pour controler le mode de calcul de l'ADE
#define RCD_DIS 4 // Pin pour controler le cs de l'ADE
#define LOCK_D 3 // Pin pour controler l'adc Temperature
#define TYPE_E_F_ON 2
#define TYPE_2_L2L3_ON 1
#define TYPE_2_NL1_ON 0
//l'expander 0x27
#define PM0 7 // Pin pour controler le mode de calcul de l'ADE
#define PM1 6 // Pin pour controler le mode de calcul de l'ADE
#define PM_CS 5 // Pin pour controler le cs de l'ADE
#define T_CS 4 // Pin pour controler l'adc Temperature
#define CP_CS 3
#define PP_CS 2
#define CP_DIS 1
#define LED_DIS 0
// registers
#define MCP23008_IODIR 0x00 //!< I/O direction register
#define MCP23008_IPOL 0x01 //!< Input polarity register
#define MCP23008_GPINTEN 0x02 //!< Interrupt-on-change control register
#define MCP23008_DEFVAL 0x03 //!< Default compare register for interrupt-on-change
#define REG_INTCON 0x04 //!< Interrupt control register
#define REG_IOCON 0x05 //!< Configuration register
#define REG_GPPU 0x06 //!< Pull-up resistor configuration register
#define REG_INTF 0x07 //!< Interrupt flag register
#define REG_INTCAP 0x08 //!< Interrupt capture register
#define REG_GPIO 0x09 //!< Port register
#define REG_OLAT 0x0A //!< Output latch register
/*
LES LABELS SONT A CHANGER DANS LA FONCTION expanderlabelize()
*/
typedef struct expander
{
/* data */
int fd; // descripeur du fichier /dev/i2c-dev
uint8_t buff[4]; // buffer contenant la derniere valeur ecrite ou lue
char label[8][MAX_STRING]; // label des port GPIO pour l'affichage dans console
uint8_t addr;
int8_t erreur; // TODO :mettre en place un systeme d'erreur pour le debug
}expander_t;
expander_t* expander_init(uint8_t);
void expander_labelize(expander_t*);
void expander_openI2C(expander_t*);
void expander_closeI2C(expander_t*);
void expander_setI2C(expander_t*);
void expander_setPullup(expander_t * exp, uint8_t val);
uint8_t expander_getAllPinsGPIO(expander_t*);
uint8_t expander_getPinGPIO(expander_t*, uint8_t);
void expander_setPinGPIO(expander_t*, uint8_t);
void expander_resetPinGPIO(expander_t*, uint8_t);
void expander_setOnlyPinResetOthersGPIO(expander_t*, uint8_t);
void expander_resetOnlyPinSetOthersGPIO(expander_t*, uint8_t);
void expander_togglePinGPIO(expander_t*, uint8_t);
void expander_setAllPinsGPIO(expander_t*);
void expander_resetAllPinsGPIO(expander_t*);
void expander_setAndResetSomePinsGPIO(expander_t*, uint8_t);
void expander_polGPIO(expander_t *exp, uint8_t val);
void expander_printGPIO(expander_t*);
void expander_closeAndFree(expander_t*);
#endif