Skip to content

Commit 541aa4e

Browse files
committed
1-wire timings (STD, OD modes) moved to defines
1 parent 070a794 commit 541aa4e

1 file changed

Lines changed: 77 additions & 33 deletions

File tree

src/OneWireNg_BitBang.cpp

Lines changed: 77 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,48 @@
2929
# error "Unsupported platform"
3030
#endif
3131

32+
/* Standard mode timings
33+
*/
34+
/* min. 480 us */
35+
#define STD_RESET_LOW 480
36+
/* reset high; presence-detect sampling: 68-75 us */
37+
#define STD_RESET_SMPL 70
38+
/* reset trailing high */
39+
#define STD_RESET_END 410
40+
41+
/* write-0 low: 60-120 us */
42+
#define STD_WRITE0_LOW 60
43+
/* write-0 trailing high: 5-15 us */
44+
#define STD_WRITE0_END 10
45+
46+
/* write-1 low */
47+
#define STD_WRITE1_LOW 5
48+
/* write-1 high; sampling max 15 us (low + high) */
49+
#define STD_WRITE1_SMPL 8
50+
/* write-1 trailing high */
51+
#define STD_WRITE1_END 56
52+
53+
/* Overdrive mode timings
54+
*/
55+
/* reset low: 53-80 us */
56+
#define OD_RESET_LOW 68
57+
/* reset high; presence-detect sampling: 8-9 us */
58+
#define OD_RESET_SMPL 8
59+
/* reset high; trailing part */
60+
#define OD_RESET_END 40
61+
62+
/* write-0 low: 8-13 us */
63+
#define OD_WRITE0_LOW 8
64+
/* write-0 trailing high: 1-2 us */
65+
#define OD_WRITE0_END 1
66+
67+
/* write-1 low */
68+
#define OD_WRITE1_LOW 1
69+
/* write-1 high; sampling max 2 us (low + high) */
70+
#define OD_WRITE1_SMPL 1
71+
/* write-1 trailing high */
72+
#define OD_WRITE1_END 7
73+
3274
OneWireNg::ErrorCode OneWireNg_BitBang::reset()
3375
{
3476
int presPulse;
@@ -39,27 +81,29 @@ OneWireNg::ErrorCode OneWireNg_BitBang::reset()
3981
#ifdef CONFIG_OVERDRIVE_ENABLED
4082
if (_overdrive)
4183
{
42-
/* overdrive mode */
84+
/* Overdrive mode
85+
*/
4386
setBus(0);
44-
delayUs(68); /* 53-80 us */
87+
delayUs(OD_RESET_LOW);
4588
setBus(1);
46-
delayUs(8); /* presence-detect sample at 8-9 us */
89+
delayUs(OD_RESET_SMPL);
4790
presPulse = readGpioIn(GPIO_DTA);
4891
timeCriticalExit();
49-
delayUs(40);
92+
delayUs(OD_RESET_END);
5093
} else
5194
#endif
5295
{
53-
/* standard mode */
96+
/* Standard mode
97+
*/
5498
setBus(0);
5599
timeCriticalExit();
56-
delayUs(480); /* min 480 us */
100+
delayUs(STD_RESET_LOW);
57101
timeCriticalEnter();
58102
setBus(1);
59-
delayUs(70); /* presence-detect sample at 68-75 us */
103+
delayUs(STD_RESET_SMPL);
60104
presPulse = readGpioIn(GPIO_DTA);
61105
timeCriticalExit();
62-
delayUs(410);
106+
delayUs(STD_RESET_END);
63107
}
64108
return (presPulse ? EC_NO_DEVS : EC_SUCCESS);
65109
}
@@ -74,50 +118,62 @@ int OneWireNg_BitBang::touchBit(int bit)
74118
#ifdef CONFIG_OVERDRIVE_ENABLED
75119
if (_overdrive)
76120
{
77-
/* overdrive mode */
121+
/* Overdrive mode
122+
*/
78123
if (bit != 0)
79124
{
80-
/* write-1 w/ sampling alias read */
125+
/* write-1 with sampling (alias read) */
81126
smpl = touch1Overdrive();
82127
timeCriticalExit();
83-
delayUs(7);
128+
delayUs(OD_WRITE1_END);
84129
} else
85130
{
86131
/* write-0 */
87132
setBus(0);
88-
delayUs(8); /* 8-13 us */
133+
delayUs(OD_WRITE0_LOW);
89134
setBus(1);
90135
timeCriticalExit();
91-
delayUs(1); /* 1-2 us */
136+
delayUs(OD_WRITE0_END);
92137
}
93138
} else
94139
#endif
95140
{
96-
/* standard mode */
141+
/* Standard mode
142+
*/
97143
if (bit != 0)
98144
{
99-
/* write-1 w/ sampling alias read */
145+
/* write-1 with sampling (alias read) */
100146
setBus(0);
101-
delayUs(5);
147+
delayUs(STD_WRITE1_LOW);
102148
setBus(1);
103-
delayUs(8);
104-
/* start sampling at 13us; max at 15 us */
149+
delayUs(STD_WRITE1_SMPL);
105150
smpl = readGpioIn(GPIO_DTA);
106151
timeCriticalExit();
107-
delayUs(56);
152+
delayUs(STD_WRITE1_END);
108153
} else
109154
{
110155
/* write-0 */
111156
setBus(0);
112-
delayUs(60); /* 60-120 us */
157+
delayUs(STD_WRITE0_LOW);
113158
setBus(1);
114159
timeCriticalExit();
115-
delayUs(10); /* 5-15 us */
160+
delayUs(STD_WRITE0_END);
116161
}
117162
}
118163
return smpl;
119164
}
120165

166+
#ifdef CONFIG_OVERDRIVE_ENABLED
167+
int OneWireNg_BitBang::touch1Overdrive()
168+
{
169+
setBus(0);
170+
delayUs(OD_WRITE1_LOW);
171+
setBus(1);
172+
delayUs(OD_WRITE1_SMPL);
173+
return readGpioIn(GPIO_DTA);
174+
}
175+
#endif
176+
121177
OneWireNg::ErrorCode OneWireNg_BitBang::powerBus(bool on)
122178
{
123179
if (!_flgs.od) {
@@ -135,15 +191,3 @@ OneWireNg::ErrorCode OneWireNg_BitBang::powerBus(bool on)
135191
_flgs.pwre = (on != 0);
136192
return EC_SUCCESS;
137193
}
138-
139-
#ifdef CONFIG_OVERDRIVE_ENABLED
140-
int OneWireNg_BitBang::touch1Overdrive()
141-
{
142-
setBus(0);
143-
delayUs(1);
144-
setBus(1);
145-
delayUs(1);
146-
/* start sampling at 2 us */
147-
return readGpioIn(GPIO_DTA);
148-
}
149-
#endif

0 commit comments

Comments
 (0)