ESPHome  2024.11.1
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 12M
212  */
213 
214 static const uint8_t MCP_12MHZ_1000KBPS_CFG1 = 0x00;
215 static const uint8_t MCP_12MHZ_1000KBPS_CFG2 = 0x88;
216 static const uint8_t MCP_12MHZ_1000KBPS_CFG3 = 0x81;
217 
218 static const uint8_t MCP_12MHZ_500KBPS_CFG1 = 0x00;
219 static const uint8_t MCP_12MHZ_500KBPS_CFG2 = 0x9B;
220 static const uint8_t MCP_12MHZ_500KBPS_CFG3 = 0x82;
221 
222 static const uint8_t MCP_12MHZ_250KBPS_CFG1 = 0x01;
223 static const uint8_t MCP_12MHZ_250KBPS_CFG2 = 0x9B;
224 static const uint8_t MCP_12MHZ_250KBPS_CFG3 = 0x82;
225 
226 static const uint8_t MCP_12MHZ_200KBPS_CFG1 = 0x01;
227 static const uint8_t MCP_12MHZ_200KBPS_CFG2 = 0xA4;
228 static const uint8_t MCP_12MHZ_200KBPS_CFG3 = 0x83;
229 
230 static const uint8_t MCP_12MHZ_125KBPS_CFG1 = 0x03;
231 static const uint8_t MCP_12MHZ_125KBPS_CFG2 = 0x9B;
232 static const uint8_t MCP_12MHZ_125KBPS_CFG3 = 0x82;
233 
234 static const uint8_t MCP_12MHZ_100KBPS_CFG1 = 0x03;
235 static const uint8_t MCP_12MHZ_100KBPS_CFG2 = 0xA4;
236 static const uint8_t MCP_12MHZ_100KBPS_CFG3 = 0x83;
237 
238 static const uint8_t MCP_12MHZ_80KBPS_CFG1 = 0x04;
239 static const uint8_t MCP_12MHZ_80KBPS_CFG2 = 0xA4;
240 static const uint8_t MCP_12MHZ_80KBPS_CFG3 = 0x83;
241 
242 static const uint8_t MCP_12MHZ_50KBPS_CFG1 = 0x07;
243 static const uint8_t MCP_12MHZ_50KBPS_CFG2 = 0xA4;
244 static const uint8_t MCP_12MHZ_50KBPS_CFG3 = 0x83;
245 
246 static const uint8_t MCP_12MHZ_40KBPS_CFG1 = 0x09;
247 static const uint8_t MCP_12MHZ_40KBPS_CFG2 = 0xA4;
248 static const uint8_t MCP_12MHZ_40KBPS_CFG3 = 0x83;
249 
250 static const uint8_t MCP_12MHZ_33K3BPS_CFG1 = 0x08;
251 static const uint8_t MCP_12MHZ_33K3BPS_CFG2 = 0xB6;
252 static const uint8_t MCP_12MHZ_33K3BPS_CFG3 = 0x84;
253 
254 static const uint8_t MCP_12MHZ_20KBPS_CFG1 = 0x0E;
255 static const uint8_t MCP_12MHZ_20KBPS_CFG2 = 0xB6;
256 static const uint8_t MCP_12MHZ_20KBPS_CFG3 = 0x84;
257 
258 static const uint8_t MCP_12MHZ_10KBPS_CFG1 = 0x31;
259 static const uint8_t MCP_12MHZ_10KBPS_CFG2 = 0x9B;
260 static const uint8_t MCP_12MHZ_10KBPS_CFG3 = 0x82;
261 
262 static const uint8_t MCP_12MHZ_5KBPS_CFG1 = 0x3B;
263 static const uint8_t MCP_12MHZ_5KBPS_CFG2 = 0xB6;
264 static const uint8_t MCP_12MHZ_5KBPS_CFG3 = 0x84;
265 
266 /*
267  * speed 16M
268  */
269 static const uint8_t MCP_16MHZ_1000KBPS_CFG1 = 0x00;
270 static const uint8_t MCP_16MHZ_1000KBPS_CFG2 = 0xD0;
271 static const uint8_t MCP_16MHZ_1000KBPS_CFG3 = 0x82;
272 
273 static const uint8_t MCP_16MHZ_500KBPS_CFG1 = 0x00;
274 static const uint8_t MCP_16MHZ_500KBPS_CFG2 = 0xF0;
275 static const uint8_t MCP_16MHZ_500KBPS_CFG3 = 0x86;
276 
277 static const uint8_t MCP_16MHZ_250KBPS_CFG1 = 0x41;
278 static const uint8_t MCP_16MHZ_250KBPS_CFG2 = 0xF1;
279 static const uint8_t MCP_16MHZ_250KBPS_CFG3 = 0x85;
280 
281 static const uint8_t MCP_16MHZ_200KBPS_CFG1 = 0x01;
282 static const uint8_t MCP_16MHZ_200KBPS_CFG2 = 0xFA;
283 static const uint8_t MCP_16MHZ_200KBPS_CFG3 = 0x87;
284 
285 static const uint8_t MCP_16MHZ_125KBPS_CFG1 = 0x03;
286 static const uint8_t MCP_16MHZ_125KBPS_CFG2 = 0xF0;
287 static const uint8_t MCP_16MHZ_125KBPS_CFG3 = 0x86;
288 
289 static const uint8_t MCP_16MHZ_100KBPS_CFG1 = 0x03;
290 static const uint8_t MCP_16MHZ_100KBPS_CFG2 = 0xFA;
291 static const uint8_t MCP_16MHZ_100KBPS_CFG3 = 0x87;
292 
293 static const uint8_t MCP_16MHZ_80KBPS_CFG1 = 0x03;
294 static const uint8_t MCP_16MHZ_80KBPS_CFG2 = 0xFF;
295 static const uint8_t MCP_16MHZ_80KBPS_CFG3 = 0x87;
296 
297 static const uint8_t MCP_16MHZ_83K3BPS_CFG1 = 0x03;
298 static const uint8_t MCP_16MHZ_83K3BPS_CFG2 = 0xBE;
299 static const uint8_t MCP_16MHZ_83K3BPS_CFG3 = 0x07;
300 
301 static const uint8_t MCP_16MHZ_50KBPS_CFG1 = 0x07;
302 static const uint8_t MCP_16MHZ_50KBPS_CFG2 = 0xFA;
303 static const uint8_t MCP_16MHZ_50KBPS_CFG3 = 0x87;
304 
305 static const uint8_t MCP_16MHZ_40KBPS_CFG1 = 0x07;
306 static const uint8_t MCP_16MHZ_40KBPS_CFG2 = 0xFF;
307 static const uint8_t MCP_16MHZ_40KBPS_CFG3 = 0x87;
308 
309 static const uint8_t MCP_16MHZ_33K3BPS_CFG1 = 0x4E;
310 static const uint8_t MCP_16MHZ_33K3BPS_CFG2 = 0xF1;
311 static const uint8_t MCP_16MHZ_33K3BPS_CFG3 = 0x85;
312 
313 static const uint8_t MCP_16MHZ_20KBPS_CFG1 = 0x0F;
314 static const uint8_t MCP_16MHZ_20KBPS_CFG2 = 0xFF;
315 static const uint8_t MCP_16MHZ_20KBPS_CFG3 = 0x87;
316 
317 static const uint8_t MCP_16MHZ_10KBPS_CFG1 = 0x1F;
318 static const uint8_t MCP_16MHZ_10KBPS_CFG2 = 0xFF;
319 static const uint8_t MCP_16MHZ_10KBPS_CFG3 = 0x87;
320 
321 static const uint8_t MCP_16MHZ_5KBPS_CFG1 = 0x3F;
322 static const uint8_t MCP_16MHZ_5KBPS_CFG2 = 0xFF;
323 static const uint8_t MCP_16MHZ_5KBPS_CFG3 = 0x87;
324 
325 /*
326  * speed 20M
327  */
328 static const uint8_t MCP_20MHZ_1000KBPS_CFG1 = 0x00;
329 static const uint8_t MCP_20MHZ_1000KBPS_CFG2 = 0xD9;
330 static const uint8_t MCP_20MHZ_1000KBPS_CFG3 = 0x82;
331 
332 static const uint8_t MCP_20MHZ_500KBPS_CFG1 = 0x00;
333 static const uint8_t MCP_20MHZ_500KBPS_CFG2 = 0xFA;
334 static const uint8_t MCP_20MHZ_500KBPS_CFG3 = 0x87;
335 
336 static const uint8_t MCP_20MHZ_250KBPS_CFG1 = 0x41;
337 static const uint8_t MCP_20MHZ_250KBPS_CFG2 = 0xFB;
338 static const uint8_t MCP_20MHZ_250KBPS_CFG3 = 0x86;
339 
340 static const uint8_t MCP_20MHZ_200KBPS_CFG1 = 0x01;
341 static const uint8_t MCP_20MHZ_200KBPS_CFG2 = 0xFF;
342 static const uint8_t MCP_20MHZ_200KBPS_CFG3 = 0x87;
343 
344 static const uint8_t MCP_20MHZ_125KBPS_CFG1 = 0x03;
345 static const uint8_t MCP_20MHZ_125KBPS_CFG2 = 0xFA;
346 static const uint8_t MCP_20MHZ_125KBPS_CFG3 = 0x87;
347 
348 static const uint8_t MCP_20MHZ_100KBPS_CFG1 = 0x04;
349 static const uint8_t MCP_20MHZ_100KBPS_CFG2 = 0xFA;
350 static const uint8_t MCP_20MHZ_100KBPS_CFG3 = 0x87;
351 
352 static const uint8_t MCP_20MHZ_83K3BPS_CFG1 = 0x04;
353 static const uint8_t MCP_20MHZ_83K3BPS_CFG2 = 0xFE;
354 static const uint8_t MCP_20MHZ_83K3BPS_CFG3 = 0x87;
355 
356 static const uint8_t MCP_20MHZ_80KBPS_CFG1 = 0x04;
357 static const uint8_t MCP_20MHZ_80KBPS_CFG2 = 0xFF;
358 static const uint8_t MCP_20MHZ_80KBPS_CFG3 = 0x87;
359 
360 static const uint8_t MCP_20MHZ_50KBPS_CFG1 = 0x09;
361 static const uint8_t MCP_20MHZ_50KBPS_CFG2 = 0xFA;
362 static const uint8_t MCP_20MHZ_50KBPS_CFG3 = 0x87;
363 
364 static const uint8_t MCP_20MHZ_40KBPS_CFG1 = 0x09;
365 static const uint8_t MCP_20MHZ_40KBPS_CFG2 = 0xFF;
366 static const uint8_t MCP_20MHZ_40KBPS_CFG3 = 0x87;
367 
368 static const uint8_t MCP_20MHZ_33K3BPS_CFG1 = 0x0B;
369 static const uint8_t MCP_20MHZ_33K3BPS_CFG2 = 0xFF;
370 static const uint8_t MCP_20MHZ_33K3BPS_CFG3 = 0x87;
371 
372 } // namespace mcp2515
373 } // namespace esphome
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7