ESPHome  2022.12.8
mcp2515_defs.h
Go to the documentation of this file.
1 #pragma once
2 
3 namespace esphome {
4 namespace mcp2515 {
5 
6 static const uint8_t CANCTRL_REQOP = 0xE0;
7 static const uint8_t CANCTRL_ABAT = 0x10;
8 static const uint8_t CANCTRL_OSM = 0x08;
9 static const uint8_t CANCTRL_CLKEN = 0x04;
10 static const uint8_t CANCTRL_CLKPRE = 0x03;
11 
12 enum CanctrlReqopMode : uint8_t {
19 };
20 
21 enum TxbNCtrl : uint8_t {
22  TXB_ABTF = 0x40,
23  TXB_MLOA = 0x20,
24  TXB_TXERR = 0x10,
25  TXB_TXREQ = 0x08,
26  TXB_TXIE = 0x04,
27  TXB_TXP = 0x03
28 };
29 
30 enum INSTRUCTION : uint8_t {
46 };
47 
48 enum REGISTER : uint8_t {
49  MCP_RXF0SIDH = 0x00,
50  MCP_RXF0SIDL = 0x01,
51  MCP_RXF0EID8 = 0x02,
52  MCP_RXF0EID0 = 0x03,
53  MCP_RXF1SIDH = 0x04,
54  MCP_RXF1SIDL = 0x05,
55  MCP_RXF1EID8 = 0x06,
56  MCP_RXF1EID0 = 0x07,
57  MCP_RXF2SIDH = 0x08,
58  MCP_RXF2SIDL = 0x09,
59  MCP_RXF2EID8 = 0x0A,
60  MCP_RXF2EID0 = 0x0B,
61  MCP_CANSTAT = 0x0E,
62  MCP_CANCTRL = 0x0F,
63  MCP_RXF3SIDH = 0x10,
64  MCP_RXF3SIDL = 0x11,
65  MCP_RXF3EID8 = 0x12,
66  MCP_RXF3EID0 = 0x13,
67  MCP_RXF4SIDH = 0x14,
68  MCP_RXF4SIDL = 0x15,
69  MCP_RXF4EID8 = 0x16,
70  MCP_RXF4EID0 = 0x17,
71  MCP_RXF5SIDH = 0x18,
72  MCP_RXF5SIDL = 0x19,
73  MCP_RXF5EID8 = 0x1A,
74  MCP_RXF5EID0 = 0x1B,
75  MCP_TEC = 0x1C,
76  MCP_REC = 0x1D,
77  MCP_RXM0SIDH = 0x20,
78  MCP_RXM0SIDL = 0x21,
79  MCP_RXM0EID8 = 0x22,
80  MCP_RXM0EID0 = 0x23,
81  MCP_RXM1SIDH = 0x24,
82  MCP_RXM1SIDL = 0x25,
83  MCP_RXM1EID8 = 0x26,
84  MCP_RXM1EID0 = 0x27,
85  MCP_CNF3 = 0x28,
86  MCP_CNF2 = 0x29,
87  MCP_CNF1 = 0x2A,
88  MCP_CANINTE = 0x2B,
89  MCP_CANINTF = 0x2C,
90  MCP_EFLG = 0x2D,
91  MCP_TXB0CTRL = 0x30,
92  MCP_TXB0SIDH = 0x31,
93  MCP_TXB0SIDL = 0x32,
94  MCP_TXB0EID8 = 0x33,
95  MCP_TXB0EID0 = 0x34,
96  MCP_TXB0DLC = 0x35,
97  MCP_TXB0DATA = 0x36,
98  MCP_TXB1CTRL = 0x40,
99  MCP_TXB1SIDH = 0x41,
100  MCP_TXB1SIDL = 0x42,
101  MCP_TXB1EID8 = 0x43,
102  MCP_TXB1EID0 = 0x44,
103  MCP_TXB1DLC = 0x45,
104  MCP_TXB1DATA = 0x46,
105  MCP_TXB2CTRL = 0x50,
106  MCP_TXB2SIDH = 0x51,
107  MCP_TXB2SIDL = 0x52,
108  MCP_TXB2EID8 = 0x53,
109  MCP_TXB2EID0 = 0x54,
110  MCP_TXB2DLC = 0x55,
111  MCP_TXB2DATA = 0x56,
112  MCP_RXB0CTRL = 0x60,
113  MCP_RXB0SIDH = 0x61,
114  MCP_RXB0SIDL = 0x62,
115  MCP_RXB0EID8 = 0x63,
116  MCP_RXB0EID0 = 0x64,
117  MCP_RXB0DLC = 0x65,
118  MCP_RXB0DATA = 0x66,
119  MCP_RXB1CTRL = 0x70,
120  MCP_RXB1SIDH = 0x71,
121  MCP_RXB1SIDL = 0x72,
122  MCP_RXB1EID8 = 0x73,
123  MCP_RXB1EID0 = 0x74,
124  MCP_RXB1DLC = 0x75,
126 };
127 
128 static const uint8_t CANSTAT_OPMOD = 0xE0;
129 static const uint8_t CANSTAT_ICOD = 0x0E;
130 
131 static const uint8_t CNF3_SOF = 0x80;
132 
133 static const uint8_t TXB_EXIDE_MASK = 0x08;
134 static const uint8_t DLC_MASK = 0x0F;
135 static const uint8_t RTR_MASK = 0x40;
136 
137 static const uint8_t RXB_CTRL_RXM_STD = 0x20;
138 static const uint8_t RXB_CTRL_RXM_EXT = 0x40;
139 static const uint8_t RXB_CTRL_RXM_STDEXT = 0x00;
140 static const uint8_t RXB_CTRL_RXM_MASK = 0x60;
141 static const uint8_t RXB_CTRL_RTR = 0x08;
142 static const uint8_t RXB_0_CTRL_BUKT = 0x04;
143 
144 static const uint8_t MCP_SIDH = 0;
145 static const uint8_t MCP_SIDL = 1;
146 static const uint8_t MCP_EID8 = 2;
147 static const uint8_t MCP_EID0 = 3;
148 static const uint8_t MCP_DLC = 4;
149 static const uint8_t MCP_DATA = 5;
150 
151 /*
152  * Speed 8M
153  */
154 static const uint8_t MCP_8MHZ_1000KBPS_CFG1 = 0x00;
155 static const uint8_t MCP_8MHZ_1000KBPS_CFG2 = 0x80;
156 static const uint8_t MCP_8MHZ_1000KBPS_CFG3 = 0x80;
157 
158 static const uint8_t MCP_8MHZ_500KBPS_CFG1 = 0x00;
159 static const uint8_t MCP_8MHZ_500KBPS_CFG2 = 0x90;
160 static const uint8_t MCP_8MHZ_500KBPS_CFG3 = 0x82;
161 
162 static const uint8_t MCP_8MHZ_250KBPS_CFG1 = 0x00;
163 static const uint8_t MCP_8MHZ_250KBPS_CFG2 = 0xB1;
164 static const uint8_t MCP_8MHZ_250KBPS_CFG3 = 0x85;
165 
166 static const uint8_t MCP_8MHZ_200KBPS_CFG1 = 0x00;
167 static const uint8_t MCP_8MHZ_200KBPS_CFG2 = 0xB4;
168 static const uint8_t MCP_8MHZ_200KBPS_CFG3 = 0x86;
169 
170 static const uint8_t MCP_8MHZ_125KBPS_CFG1 = 0x01;
171 static const uint8_t MCP_8MHZ_125KBPS_CFG2 = 0xB1;
172 static const uint8_t MCP_8MHZ_125KBPS_CFG3 = 0x85;
173 
174 static const uint8_t MCP_8MHZ_100KBPS_CFG1 = 0x01;
175 static const uint8_t MCP_8MHZ_100KBPS_CFG2 = 0xB4;
176 static const uint8_t MCP_8MHZ_100KBPS_CFG3 = 0x86;
177 
178 static const uint8_t MCP_8MHZ_80KBPS_CFG1 = 0x01;
179 static const uint8_t MCP_8MHZ_80KBPS_CFG2 = 0xBF;
180 static const uint8_t MCP_8MHZ_80KBPS_CFG3 = 0x87;
181 
182 static const uint8_t MCP_8MHZ_50KBPS_CFG1 = 0x03;
183 static const uint8_t MCP_8MHZ_50KBPS_CFG2 = 0xB4;
184 static const uint8_t MCP_8MHZ_50KBPS_CFG3 = 0x86;
185 
186 static const uint8_t MCP_8MHZ_40KBPS_CFG1 = 0x03;
187 static const uint8_t MCP_8MHZ_40KBPS_CFG2 = 0xBF;
188 static const uint8_t MCP_8MHZ_40KBPS_CFG3 = 0x87;
189 
190 static const uint8_t MCP_8MHZ_33K3BPS_CFG1 = 0x47;
191 static const uint8_t MCP_8MHZ_33K3BPS_CFG2 = 0xE2;
192 static const uint8_t MCP_8MHZ_33K3BPS_CFG3 = 0x85;
193 
194 static const uint8_t MCP_8MHZ_31K25BPS_CFG1 = 0x07;
195 static const uint8_t MCP_8MHZ_31K25BPS_CFG2 = 0xA4;
196 static const uint8_t MCP_8MHZ_31K25BPS_CFG3 = 0x84;
197 
198 static const uint8_t MCP_8MHZ_20KBPS_CFG1 = 0x07;
199 static const uint8_t MCP_8MHZ_20KBPS_CFG2 = 0xBF;
200 static const uint8_t MCP_8MHZ_20KBPS_CFG3 = 0x87;
201 
202 static const uint8_t MCP_8MHZ_10KBPS_CFG1 = 0x0F;
203 static const uint8_t MCP_8MHZ_10KBPS_CFG2 = 0xBF;
204 static const uint8_t MCP_8MHZ_10KBPS_CFG3 = 0x87;
205 
206 static const uint8_t MCP_8MHZ_5KBPS_CFG1 = 0x1F;
207 static const uint8_t MCP_8MHZ_5KBPS_CFG2 = 0xBF;
208 static const uint8_t MCP_8MHZ_5KBPS_CFG3 = 0x87;
209 
210 /*
211  * speed 16M
212  */
213 static const uint8_t MCP_16MHZ_1000KBPS_CFG1 = 0x00;
214 static const uint8_t MCP_16MHZ_1000KBPS_CFG2 = 0xD0;
215 static const uint8_t MCP_16MHZ_1000KBPS_CFG3 = 0x82;
216 
217 static const uint8_t MCP_16MHZ_500KBPS_CFG1 = 0x00;
218 static const uint8_t MCP_16MHZ_500KBPS_CFG2 = 0xF0;
219 static const uint8_t MCP_16MHZ_500KBPS_CFG3 = 0x86;
220 
221 static const uint8_t MCP_16MHZ_250KBPS_CFG1 = 0x41;
222 static const uint8_t MCP_16MHZ_250KBPS_CFG2 = 0xF1;
223 static const uint8_t MCP_16MHZ_250KBPS_CFG3 = 0x85;
224 
225 static const uint8_t MCP_16MHZ_200KBPS_CFG1 = 0x01;
226 static const uint8_t MCP_16MHZ_200KBPS_CFG2 = 0xFA;
227 static const uint8_t MCP_16MHZ_200KBPS_CFG3 = 0x87;
228 
229 static const uint8_t MCP_16MHZ_125KBPS_CFG1 = 0x03;
230 static const uint8_t MCP_16MHZ_125KBPS_CFG2 = 0xF0;
231 static const uint8_t MCP_16MHZ_125KBPS_CFG3 = 0x86;
232 
233 static const uint8_t MCP_16MHZ_100KBPS_CFG1 = 0x03;
234 static const uint8_t MCP_16MHZ_100KBPS_CFG2 = 0xFA;
235 static const uint8_t MCP_16MHZ_100KBPS_CFG3 = 0x87;
236 
237 static const uint8_t MCP_16MHZ_80KBPS_CFG1 = 0x03;
238 static const uint8_t MCP_16MHZ_80KBPS_CFG2 = 0xFF;
239 static const uint8_t MCP_16MHZ_80KBPS_CFG3 = 0x87;
240 
241 static const uint8_t MCP_16MHZ_83K3BPS_CFG1 = 0x03;
242 static const uint8_t MCP_16MHZ_83K3BPS_CFG2 = 0xBE;
243 static const uint8_t MCP_16MHZ_83K3BPS_CFG3 = 0x07;
244 
245 static const uint8_t MCP_16MHZ_50KBPS_CFG1 = 0x07;
246 static const uint8_t MCP_16MHZ_50KBPS_CFG2 = 0xFA;
247 static const uint8_t MCP_16MHZ_50KBPS_CFG3 = 0x87;
248 
249 static const uint8_t MCP_16MHZ_40KBPS_CFG1 = 0x07;
250 static const uint8_t MCP_16MHZ_40KBPS_CFG2 = 0xFF;
251 static const uint8_t MCP_16MHZ_40KBPS_CFG3 = 0x87;
252 
253 static const uint8_t MCP_16MHZ_33K3BPS_CFG1 = 0x4E;
254 static const uint8_t MCP_16MHZ_33K3BPS_CFG2 = 0xF1;
255 static const uint8_t MCP_16MHZ_33K3BPS_CFG3 = 0x85;
256 
257 static const uint8_t MCP_16MHZ_20KBPS_CFG1 = 0x0F;
258 static const uint8_t MCP_16MHZ_20KBPS_CFG2 = 0xFF;
259 static const uint8_t MCP_16MHZ_20KBPS_CFG3 = 0x87;
260 
261 static const uint8_t MCP_16MHZ_10KBPS_CFG1 = 0x1F;
262 static const uint8_t MCP_16MHZ_10KBPS_CFG2 = 0xFF;
263 static const uint8_t MCP_16MHZ_10KBPS_CFG3 = 0x87;
264 
265 static const uint8_t MCP_16MHZ_5KBPS_CFG1 = 0x3F;
266 static const uint8_t MCP_16MHZ_5KBPS_CFG2 = 0xFF;
267 static const uint8_t MCP_16MHZ_5KBPS_CFG3 = 0x87;
268 
269 /*
270  * speed 20M
271  */
272 static const uint8_t MCP_20MHZ_1000KBPS_CFG1 = 0x00;
273 static const uint8_t MCP_20MHZ_1000KBPS_CFG2 = 0xD9;
274 static const uint8_t MCP_20MHZ_1000KBPS_CFG3 = 0x82;
275 
276 static const uint8_t MCP_20MHZ_500KBPS_CFG1 = 0x00;
277 static const uint8_t MCP_20MHZ_500KBPS_CFG2 = 0xFA;
278 static const uint8_t MCP_20MHZ_500KBPS_CFG3 = 0x87;
279 
280 static const uint8_t MCP_20MHZ_250KBPS_CFG1 = 0x41;
281 static const uint8_t MCP_20MHZ_250KBPS_CFG2 = 0xFB;
282 static const uint8_t MCP_20MHZ_250KBPS_CFG3 = 0x86;
283 
284 static const uint8_t MCP_20MHZ_200KBPS_CFG1 = 0x01;
285 static const uint8_t MCP_20MHZ_200KBPS_CFG2 = 0xFF;
286 static const uint8_t MCP_20MHZ_200KBPS_CFG3 = 0x87;
287 
288 static const uint8_t MCP_20MHZ_125KBPS_CFG1 = 0x03;
289 static const uint8_t MCP_20MHZ_125KBPS_CFG2 = 0xFA;
290 static const uint8_t MCP_20MHZ_125KBPS_CFG3 = 0x87;
291 
292 static const uint8_t MCP_20MHZ_100KBPS_CFG1 = 0x04;
293 static const uint8_t MCP_20MHZ_100KBPS_CFG2 = 0xFA;
294 static const uint8_t MCP_20MHZ_100KBPS_CFG3 = 0x87;
295 
296 static const uint8_t MCP_20MHZ_83K3BPS_CFG1 = 0x04;
297 static const uint8_t MCP_20MHZ_83K3BPS_CFG2 = 0xFE;
298 static const uint8_t MCP_20MHZ_83K3BPS_CFG3 = 0x87;
299 
300 static const uint8_t MCP_20MHZ_80KBPS_CFG1 = 0x04;
301 static const uint8_t MCP_20MHZ_80KBPS_CFG2 = 0xFF;
302 static const uint8_t MCP_20MHZ_80KBPS_CFG3 = 0x87;
303 
304 static const uint8_t MCP_20MHZ_50KBPS_CFG1 = 0x09;
305 static const uint8_t MCP_20MHZ_50KBPS_CFG2 = 0xFA;
306 static const uint8_t MCP_20MHZ_50KBPS_CFG3 = 0x87;
307 
308 static const uint8_t MCP_20MHZ_40KBPS_CFG1 = 0x09;
309 static const uint8_t MCP_20MHZ_40KBPS_CFG2 = 0xFF;
310 static const uint8_t MCP_20MHZ_40KBPS_CFG3 = 0x87;
311 
312 static const uint8_t MCP_20MHZ_33K3BPS_CFG1 = 0x0B;
313 static const uint8_t MCP_20MHZ_33K3BPS_CFG2 = 0xFF;
314 static const uint8_t MCP_20MHZ_33K3BPS_CFG3 = 0x87;
315 
316 } // namespace mcp2515
317 } // namespace esphome
Definition: a4988.cpp:4