-
Notifications
You must be signed in to change notification settings - Fork 0
/
Max7312.cpp
100 lines (79 loc) · 2.37 KB
/
Max7312.cpp
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
#include <Max7312.h>
#include "Arduino.h"
#include <Wire.h>
// Comments
//
//...
Max7312::Max7312(){
_chipAddress=MAX7312_ADDRESS;
init(0x00, 0x00);
}
Max7312::Max7312(unsigned char chipAddress){
_chipAddress=chipAddress;
init(0x00, 0x00);
}
Max7312::Max7312(unsigned char chipAddress, unsigned char portDirection1, unsigned char portDirection2)
{
_chipAddress=chipAddress;
init(portDirection1, portDirection2);
}
Max7312::Max7312(unsigned char chipAddress, unsigned char portDirection1, unsigned char portDirection2, unsigned char timeoutFlag)
{
_chipAddress=chipAddress;
init(portDirection1, portDirection2, timeoutFlag);
}
void Max7312::init(unsigned char portDirection1, unsigned char portDirection2)
{
init(portDirection1, portDirection2, 0x01);
}
void Max7312::init(unsigned char portDirection1, unsigned char portDirection2, unsigned char timeoutFlag)
{
initDataBuffers();
Wire.begin();
configPort1(portDirection1);
configPort2(portDirection2);
configTimeout(timeoutFlag);
}
void Max7312::initDataBuffers(){
_port1_data=0;
_port2_data=0;
}
/********** high level commands, for the user! */
unsigned char Max7312::readPort1(){
_port1_data=readChar(INPUT_PORT_1);
return _port1_data;
}
unsigned char Max7312::readPort2(){
_port2_data=readChar(INPUT_PORT_2);
return _port2_data;
}
void Max7312::writePort1(unsigned char portData){
writeChar(OUTPUT_PORT_1, portData);
}
void Max7312::writePort2(unsigned char portData){
writeChar(OUTPUT_PORT_2, portData);
}
void Max7312::polarityInversionPort1(unsigned char portInversion){
writeChar(OUTPUT_PORT_1, portInversion);
}
void Max7312::polarityInversionPort2(unsigned char portInversion){
writeChar(OUTPUT_PORT_2, portInversion);
}
void Max7312::configPort1(unsigned char portDirection){
writeChar(CONFIGURATION_PORT_1, portDirection);
}
void Max7312::configPort2(unsigned char portDirection){
writeChar(CONFIGURATION_PORT_2, portDirection);
}
void Max7312::configTimeout(unsigned char timeoutFlag){
writeChar(TIMEOUT_REGISTER, timeoutFlag);
}
void Max7312::readIntFlag(){}
/*********** mid level commands, for sending data/cmds */
/************ low level writing to i2c **********/
void Max7312::writeChar(unsigned char registerAddress, unsigned char charData){
// todo implement i2c write from Wire library
}
unsigned char Max7312::readChar(unsigned char registerAddress){
// todo implement i2c read from Wire library
}