-
Notifications
You must be signed in to change notification settings - Fork 6
/
HDQ.h
103 lines (85 loc) · 2.58 KB
/
HDQ.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
//.H CODE
#include "inttypes.h"
/** * Texas Instruments HDQ implementation for the Arduino API
* (cleft) Matthieu Lalonde 2008 ([email protected])
* Creative Commons BY-SA-NC
* * http://trac.mlalonde.net/cral/browser/HDQ/ * * Revision 1 *
**/
#ifndef HDQ_H
#define HDQ_H
/**
* Default pin to use if none is specified to the constructor
**/
#define HDQ_DEFAULT_PIN 7 /* Arduino pin 7 */
/**
* Read/write command mask
**/
#define HDQ_ADDR_MASK_READ 0x00
#define HDQ_ADDR_MASK_WRITE 0x80 /* B10000000 */
/**
* This is the number of times the slave wait loop
* will run before we time out.
* As far as I can tell the loop uses ~6 instructions
* thus giving about 200uS delay which is a full bit write
**/
#define HDQ_DELAY_FAIL_TRIES 300
/**
* HDQ Default NEW timings
**/
#define HDQ_DELAY_THW1 45 // 32 - 66uS
#define HDQ_DELAY_THW0 120 // 70 - 145uS
#define HDQ_DELAY_TDW1 48 // 0.5 - 50us
#define HDQ_DELAY_TDW0 110 // 86 - 145uS
#define HDQ_DELAY_TCYCD 205 // 190 min
#define HDQ_DELAY_TB 250 /* Min: 190uS */
#define HDQ_DELAY_TBR 70 /* Min: 40uS */
#define HDQ_DELAY_TCYCH 250 /* Min: 190uS Max: 250uS*/
#define HDQ_DELAY_TRSPS_MAX 320 /* Max: 320uS */
#define HDQ_DELAY_BIT_TOTAL 200
class HDQ {
public:
/**
* Constructor
* @param pinArg: pin number to attach to
**/
//HDQ(uint8_t pinArg = HDQ_DEFAULT_PIN);
HDQ( uint8_t pinArg);
/**
* sendBreak: writes a break to the HDQ line
**/
void doBreak(void);
/**
* write: send a payload to the device
* @param reg: the address of the register to write to
* @param payload: data to be sent
* @return: false, unless if verif is set, then
* it will read back the register and
* return true if it matches the payload
**/
bool write(uint8_t reg, uint8_t payload, bool verif);
bool write(uint8_t reg, uint8_t payload);
/**
* read: read from the device
* @param register: address of the register to read
* @return a uint8_t integer
**/
uint8_t read(uint8_t reg);
private:
/**
* Port variables definition
**/
uint8_t pin;
uint8_t port;
uint8_t bitmask;
volatile uint8_t *outputReg;
volatile uint8_t *inputReg;
volatile uint8_t *modeReg;
/**
* writeByte: write a raw byte of data to the bus
* @param payload: the byte to send
*
**/
void writeByte(uint8_t payload);
//uint8_t _HDQ_readPin();
};
#endif