Skip to content

Commit 600e345

Browse files
committed
Preparation for a 1.6.0 release
- Code cleanup and compatibility with Arduino 1.6.* - Proper documentation of code sources and licenses used - Updated library.properties and keywords.txt - "Appropriated" the method used by Paul Stoffregen for determining which architecture is which from the Teensyduino SPI.h file
1 parent 21fac01 commit 600e345

21 files changed

+1345
-1321
lines changed

CAN.cpp

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,59 @@
1-
/* Copyright (C) 2014
1+
/*
2+
Copyright © 2007-2015 Fabian Greif, David Harding, Kyle Crockett,
3+
Nuno Alves, Stevenh, Collin Kidder, Daniel Kasamis, Cory Fowler, teachop,
4+
Pedro Cevallos, Neil McNeight
25
3-
Contributors: Pedro Cevallos & Neil McNeight
6+
This file is part of CAN_Library.
47
5-
This program is free software: you can redistribute it and/or modify
6-
it under the terms of the GNU General Public License as published by
7-
the Free Software Foundation, either version 3 of the License, or
8+
CAN_Library is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU Lesser General Public License as published by
10+
the Free Software Foundation, either version 2.1 of the License, or
811
(at your option) any later version.
912
10-
This program is distributed in the hope that it will be useful,
13+
CAN_Library is distributed in the hope that it will be useful,
1114
but WITHOUT ANY WARRANTY; without even the implied warranty of
1215
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
GNU General Public License for more details.
16+
GNU Lesser General Public License for more details.
1417
15-
You should have received a copy of the GNU General Public License
18+
You should have received a copy of the GNU Lesser General Public License
1619
along with this program. If not, see <http://www.gnu.org/licenses/>.
1720
1821
Acknowledgements:
19-
Fabian Greif for the initial libraries for MCP2515, SJA1000 and AT90CAN
20-
http://www.kreatives-chaos.com/artikel/universelle-can-bibliothek
21-
as well as his updates at https://github.com/dergraaf/avr-can-lib
22-
David Harding for his version of the MCP2515 library
23-
http://forum.arduino.cc/index.php/topic,8730.0.html
24-
Kyle Crockett CANduino library with 16Mhz oscillator
25-
http://code.google.com/p/canduino/
26-
Nuno Alves for the help on Extended ID messaging
27-
Stevenh for his work on library and all of the MCP research/work
28-
http://modelrail.otenko.com/arduino/arduino-controller-area-network-can
29-
Collin Kidder (collin80) for his work on the Arduino Due CAN interface
30-
https://github.com/collin80/due_can
31-
Daniel Kasamis (togglebit) both for his code at
32-
https://github.com/togglebit/ArduinoDUE_OBD_FreeRunningCAN as well as his
33-
DUE CANshield http://togglebit.net/product/arduino-due-can-shield/
34-
Cory Fowler (coryjfowler) for 16 MHz bitrate timing information
35-
https://github.com/coryjfowler/MCP2515_lib
36-
teachop for the FlexCAN library for the Teensy 3.1
37-
https://github.com/teachop/FlexCAN_Library
22+
Fabian Greif for the initial libraries for MCP2515, SJA1000 and AT90CAN
23+
http://www.kreatives-chaos.com/artikel/universelle-can-bibliothek
24+
as well as his updates at https://github.com/dergraaf/avr-can-lib
25+
David Harding for his version of the MCP2515 library
26+
http://forum.arduino.cc/index.php/topic,8730.0.html
27+
Kyle Crockett CANduino library with 16Mhz oscillator
28+
http://code.google.com/p/canduino/
29+
Nuno Alves for the help on Extended ID messaging
30+
Stevenh for his work on library and all of the MCP research/work
31+
http://modelrail.otenko.com/arduino/arduino-controller-area-network-can
32+
Collin Kidder (collin80) for his work on the Arduino Due CAN interface
33+
https://github.com/collin80/due_can
34+
Daniel Kasamis (togglebit) both for his code at
35+
https://github.com/togglebit/ArduinoDUE_OBD_FreeRunningCAN as well as his
36+
DUE CANshield http://togglebit.net/product/arduino-due-can-shield/
37+
Cory Fowler (coryjfowler) for 16 MHz bitrate timing information
38+
https://github.com/coryjfowler/MCP2515_lib
39+
teachop for the FlexCAN library for the Teensy 3.1
40+
https://github.com/teachop/FlexCAN_Library
3841
3942
-------------------------------------------------------------------------------
4043
Change Log
4144
42-
DATE VER WHO WHAT
45+
DATE VER WHO WHAT
4346
07/07/13 0.1 PC Modified and merge all MCP2515 libraries found. Stripped
4447
away most unused functions and corrected MCP2515 defs
4548
09/12/13 0.2 PC Added selectable CS SPI for CAN controller to use 1 IC
4649
to control several mcp2515
47-
02/05/14 0.3 PC Added filter and mask controls
50+
02/05/14 0.3 PC Added filter and mask controls
4851
05/01/14 0.4 PC Cleaned up functions, variables and added message
4952
structures for J1939, CANopen and CAN.
50-
05/07/14 1.0 PC Released Library to the public through GitHub
51-
06/18/14 1.9 NEM Preparing a unified CAN library across three different
53+
05/07/14 1.0 PC Released Library to the public through GitHub
54+
06/18/14 1.5 NEM Preparing a unified CAN library across three different
5255
CAN controllers
56+
06/14/15 1.6.0 NEM Code cleanup and compatibility with Arduino 1.6.*
5357
-------------------------------------------------------------------------------
5458
5559
*/

CAN.h

Lines changed: 73 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,59 @@
1-
/* Copyright (C) 2014
1+
/*
2+
Copyright © 2007-2015 Fabian Greif, David Harding, Kyle Crockett,
3+
Nuno Alves, Stevenh, Collin Kidder, Daniel Kasamis, Cory Fowler, teachop,
4+
Pedro Cevallos, Neil McNeight
25
3-
Contributors: Pedro Cevallos & Neil McNeight
6+
This file is part of CAN_Library.
47
5-
This program is free software: you can redistribute it and/or modify
6-
it under the terms of the GNU General Public License as published by
7-
the Free Software Foundation, either version 3 of the License, or
8+
CAN_Library is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU Lesser General Public License as published by
10+
the Free Software Foundation, either version 2.1 of the License, or
811
(at your option) any later version.
912
10-
This program is distributed in the hope that it will be useful,
13+
CAN_Library is distributed in the hope that it will be useful,
1114
but WITHOUT ANY WARRANTY; without even the implied warranty of
1215
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
GNU General Public License for more details.
16+
GNU Lesser General Public License for more details.
1417
15-
You should have received a copy of the GNU General Public License
18+
You should have received a copy of the GNU Lesser General Public License
1619
along with this program. If not, see <http://www.gnu.org/licenses/>.
1720
1821
Acknowledgements:
19-
Fabian Greif for the initial libraries for MCP2515, SJA1000 and AT90CAN
20-
http://www.kreatives-chaos.com/artikel/universelle-can-bibliothek
21-
as well as his updates at https://github.com/dergraaf/avr-can-lib
22-
David Harding for his version of the MCP2515 library
23-
http://forum.arduino.cc/index.php/topic,8730.0.html
24-
Kyle Crockett CANduino library with 16Mhz oscillator
25-
http://code.google.com/p/canduino/
26-
Nuno Alves for the help on Extended ID messaging
27-
Stevenh for his work on library and all of the MCP research/work
28-
http://modelrail.otenko.com/arduino/arduino-controller-area-network-can
29-
Collin Kidder (collin80) for his work on the Arduino Due CAN interface
30-
https://github.com/collin80/due_can
31-
Daniel Kasamis (togglebit) both for his code at
32-
https://github.com/togglebit/ArduinoDUE_OBD_FreeRunningCAN as well as his
33-
DUE CANshield http://togglebit.net/product/arduino-due-can-shield/
34-
Cory Fowler (coryjfowler) for 16 MHz bitrate timing information
35-
https://github.com/coryjfowler/MCP2515_lib
36-
teachop for the FlexCAN library for the Teensy 3.1
37-
https://github.com/teachop/FlexCAN_Library
22+
Fabian Greif for the initial libraries for MCP2515, SJA1000 and AT90CAN
23+
http://www.kreatives-chaos.com/artikel/universelle-can-bibliothek
24+
as well as his updates at https://github.com/dergraaf/avr-can-lib
25+
David Harding for his version of the MCP2515 library
26+
http://forum.arduino.cc/index.php/topic,8730.0.html
27+
Kyle Crockett CANduino library with 16Mhz oscillator
28+
http://code.google.com/p/canduino/
29+
Nuno Alves for the help on Extended ID messaging
30+
Stevenh for his work on library and all of the MCP research/work
31+
http://modelrail.otenko.com/arduino/arduino-controller-area-network-can
32+
Collin Kidder (collin80) for his work on the Arduino Due CAN interface
33+
https://github.com/collin80/due_can
34+
Daniel Kasamis (togglebit) both for his code at
35+
https://github.com/togglebit/ArduinoDUE_OBD_FreeRunningCAN as well as his
36+
DUE CANshield http://togglebit.net/product/arduino-due-can-shield/
37+
Cory Fowler (coryjfowler) for 16 MHz bitrate timing information
38+
https://github.com/coryjfowler/MCP2515_lib
39+
teachop for the FlexCAN library for the Teensy 3.1
40+
https://github.com/teachop/FlexCAN_Library
3841
3942
-------------------------------------------------------------------------------
4043
Change Log
4144
42-
DATE VER WHO WHAT
45+
DATE VER WHO WHAT
4346
07/07/13 0.1 PC Modified and merge all MCP2515 libraries found. Stripped
4447
away most unused functions and corrected MCP2515 defs
4548
09/12/13 0.2 PC Added selectable CS SPI for CAN controller to use 1 IC
4649
to control several mcp2515
47-
02/05/14 0.3 PC Added filter and mask controls
50+
02/05/14 0.3 PC Added filter and mask controls
4851
05/01/14 0.4 PC Cleaned up functions, variables and added message
4952
structures for J1939, CANopen and CAN.
50-
05/07/14 1.0 PC Released Library to the public through GitHub
51-
06/18/14 1.9 NEM Preparing a unified CAN library across three different
53+
05/07/14 1.0 PC Released Library to the public through GitHub
54+
06/18/14 1.5 NEM Preparing a unified CAN library across three different
5255
CAN controllers
56+
06/14/15 1.6.0 NEM Code cleanup and compatibility with Arduino 1.6.*
5357
-------------------------------------------------------------------------------
5458
5559
*/
@@ -113,17 +117,16 @@ DATE VER WHO WHAT
113117
//
114118
typedef struct __attribute__((__packed__))
115119
{
116-
uint32_t id : 29; // if (ide == CAN_RECESSIVE) { extended ID }
117-
// else { standard ID }
118-
uint8_t valid : 1; // To avoid passing garbage frames around
119-
uint8_t rtr : 1; // Remote Transmission Request Bit (RTR)
120+
uint32_t id : 29; // if (extended == CAN_RECESSIVE) { extended ID } else { standard ID }
121+
uint8_t valid : 1; // To avoid passing garbage frames around
122+
uint8_t rtr : 1; // Remote Transmission Request Bit (RTR)
120123
uint8_t extended : 1; // Identifier Extension Bit (IDE)
121124
uint32_t fid; // family ID
122-
uint8_t priority : 4; // Priority but only important for TX frames and then only for special uses.
123-
uint8_t length : 4; // Data Length
125+
uint8_t priority : 4; // Priority but only important for TX frames and then only for special uses.
126+
uint8_t length : 4; // Data Length
124127
uint16_t timeout; // milliseconds, zero will disable waiting
125-
uint8_t data[8]; // Message data
126-
} CAN_Frame; // suffix of '_t' is reserved by POSIX for future use
128+
uint8_t data[8]; // Message data
129+
} CAN_Frame; // suffix of '_t' is reserved by POSIX for future use
127130

128131

129132
// From http://www.cse.dmu.ac.uk/~eg/tele/CanbusIDandMask.html
@@ -172,22 +175,27 @@ typedef struct __attribute__((__packed__))
172175
// number of different tasks.
173176
typedef struct __attribute__((__packed__))
174177
{
175-
uint32_t id : 29; // if (ide == CAN_RECESSIVE) { extended ID }
176-
// else { standard ID }
177-
uint8_t rtr : 1; // Remote Transmission Request Bit (RTR)
178+
uint32_t id : 29; // if (extended == CAN_RECESSIVE) { extended ID } else { standard ID }
179+
uint8_t rtr : 1; // Remote Transmission Request Bit (RTR)
178180
uint8_t extended : 1; // Identifier Extension Bit (IDE)
179181
uint8_t data[2]; // Filter / Mask for message data
180-
} CAN_Filter; // suffix of '_t' is reserved by POSIX for future use
182+
} CAN_Filter; // suffix of '_t' is reserved by POSIX for future use
181183

182184

183185
class CANClass // Can't inherit from Stream
184186
{
185187
public:
188+
// Initializes CAN communications.
186189
virtual void begin(uint32_t bitrate);
190+
// Finishes CAN communications
187191
virtual void end();
192+
// Check if message has been received on any of the buffers
188193
virtual uint8_t available();
194+
// Receive CAN message and allows use of the message structure for easier message handling
189195
virtual CAN_Frame read();
196+
190197
virtual void flush();
198+
// Load and send CAN message.
191199
virtual uint8_t write(const CAN_Frame&);
192200

193201
//CAN_Frame& operator=(const CAN_Frame&);
@@ -199,8 +207,11 @@ class CANClass // Can't inherit from Stream
199207
// Unable to use extern on a base class
200208

201209
// It's time for #ifdef bingo!
202-
#if defined(ARDUINO_ARCH_AVR) && !defined(__MK20DX256__)
203-
//
210+
/**********************************************************/
211+
/* 8 bit AVR-based boards */
212+
/**********************************************************/
213+
#if defined(__AVR__)
214+
204215
#if defined(__AVR_AT90CAN32__) || \
205216
defined(__AVR_AT90CAN64__) || \
206217
defined(__AVR_AT90CAN128__)
@@ -218,21 +229,34 @@ class CANClass // Can't inherit from Stream
218229
#define CAN_CONTROLLER_MCP2515 // SPI interface to MCP2515 chip
219230
#include <SPI.h>
220231
#include "CAN_MCP2515.h"
221-
//#elif defined(SJA1000) // SPI interface to SJA1000 chip
232+
//#elif defined(SJA1000) // 8-bit parallel interface to SJA1000 chip
222233
//#define CAN_CONTROLLER_SJA1000
223-
//#include <SPI.h>
224234
//#include "CAN_SJA1000.h"
225235
//#else
226236
//#error "Your SPI CAN controller is currently unsupported."
227237
//#endif // MCP2515 / SJA1000
228238
#endif // AT90 / M1 / C1 / SPI
229239

230-
#elif defined(ARDUINO_ARCH_SAM) || defined(__SAM3X8E__) // Arduino Due
240+
/**********************************************************/
241+
/* 32 bit Arduino Due */
242+
/**********************************************************/
243+
#elif defined(__arm__) && defined(__SAM3X8E__)
231244
#define CAN_CONTROLLER_SAM3X
232245
#include "CAN_SAM3X.h"
233-
#elif defined(__MK20DX256__) // Teensy 3.1
246+
/**********************************************************/
247+
/* 32 bit Teensy 3.0 and 3.1 */
248+
/**********************************************************/
249+
#elif defined(__arm__) && defined(TEENSYDUINO) && defined(KINETISK)
234250
#define CAN_CONTROLLER_K2X
235251
#include "CAN_K2X.h"
252+
/**********************************************************/
253+
/* 32 bit Teensy-LC */
254+
/**********************************************************/
255+
#elif defined(__arm__) && defined(TEENSYDUINO) && defined(KINETISL)
256+
// Assume an SPI interface to an MCP2515
257+
#define CAN_CONTROLLER_MCP2515 // SPI interface to MCP2515 chip
258+
#include <SPI.h>
259+
#include "CAN_MCP2515.h"
236260
#else
237261
#error "Your CPU & CAN controller are currently unsupported."
238262
#endif // ARDUINO_ARCH_*

CAN_AT90CAN.cpp

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,48 @@
1-
/* Copyright (C) 2014
1+
/*
2+
Copyright © 2007-2015 Fabian Greif, David Harding, Kyle Crockett,
3+
Nuno Alves, Stevenh, Collin Kidder, Daniel Kasamis, Cory Fowler, teachop,
4+
Pedro Cevallos, Neil McNeight
25
3-
Contributors: Pedro Cevallos & Neil McNeight
6+
This file is part of CAN_Library.
47
5-
This program is free software: you can redistribute it and/or modify
6-
it under the terms of the GNU General Public License as published by
7-
the Free Software Foundation, either version 3 of the License, or
8+
CAN_Library is free software: you can redistribute it and/or modify
9+
it under the terms of the GNU Lesser General Public License as published by
10+
the Free Software Foundation, either version 2.1 of the License, or
811
(at your option) any later version.
912
10-
This program is distributed in the hope that it will be useful,
13+
CAN_Library is distributed in the hope that it will be useful,
1114
but WITHOUT ANY WARRANTY; without even the implied warranty of
1215
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
GNU General Public License for more details.
16+
GNU Lesser General Public License for more details.
1417
15-
You should have received a copy of the GNU General Public License
18+
You should have received a copy of the GNU Lesser General Public License
1619
along with this program. If not, see <http://www.gnu.org/licenses/>.
1720
1821
Acknowledgements:
19-
Fabian Greif for the initial libraries for MCP2515, SJA1000 and AT90CAN
20-
http://www.kreatives-chaos.com/artikel/universelle-can-bibliothek
21-
as well as his updates at https://github.com/dergraaf/avr-can-lib
22-
David Harding for his version of the MCP2515 library
23-
http://forum.arduino.cc/index.php/topic,8730.0.html
24-
Kyle Crockett CANduino library with 16Mhz oscillator
25-
http://code.google.com/p/canduino/
26-
Nuno Alves for the help on Extended ID messaging
27-
Stevenh for his work on library and all of the MCP research/work
28-
http://modelrail.otenko.com/arduino/arduino-controller-area-network-can
29-
Collin Kidder (collin80) for his work on the Arduino Due CAN interface
30-
https://github.com/collin80/due_can
31-
Daniel Kasamis (togglebit) both for his code at
32-
https://github.com/togglebit/ArduinoDUE_OBD_FreeRunningCAN as well as his
33-
DUE CANshield http://togglebit.net/product/arduino-due-can-shield/
34-
Cory Fowler (coryjfowler) for 16 MHz bitrate timing information
35-
https://github.com/coryjfowler/MCP2515_lib
36-
teachop for the FlexCAN library for the Teensy 3.1
37-
https://github.com/teachop/FlexCAN_Library
22+
Fabian Greif for the initial libraries for MCP2515, SJA1000 and AT90CAN
23+
http://www.kreatives-chaos.com/artikel/universelle-can-bibliothek
24+
as well as his updates at https://github.com/dergraaf/avr-can-lib
25+
David Harding for his version of the MCP2515 library
26+
http://forum.arduino.cc/index.php/topic,8730.0.html
27+
Kyle Crockett CANduino library with 16Mhz oscillator
28+
http://code.google.com/p/canduino/
29+
Nuno Alves for the help on Extended ID messaging
30+
Stevenh for his work on library and all of the MCP research/work
31+
http://modelrail.otenko.com/arduino/arduino-controller-area-network-can
32+
Collin Kidder (collin80) for his work on the Arduino Due CAN interface
33+
https://github.com/collin80/due_can
34+
Daniel Kasamis (togglebit) both for his code at
35+
https://github.com/togglebit/ArduinoDUE_OBD_FreeRunningCAN as well as his
36+
DUE CANshield http://togglebit.net/product/arduino-due-can-shield/
37+
Cory Fowler (coryjfowler) for 16 MHz bitrate timing information
38+
https://github.com/coryjfowler/MCP2515_lib
39+
teachop for the FlexCAN library for the Teensy 3.1
40+
https://github.com/teachop/FlexCAN_Library
3841
3942
-------------------------------------------------------------------------------
4043
Change Log
4144
42-
DATE VER WHO WHAT
45+
DATE VER WHO WHAT
4346
07/07/13 0.1 PC Modified and merge all MCP2515 libraries found. Stripped
4447
away most unused functions and corrected MCP2515 defs
4548
09/12/13 0.2 PC Added selectable CS SPI for CAN controller to use 1 IC
@@ -48,8 +51,9 @@ DATE VER WHO WHAT
4851
05/01/14 0.4 PC Cleaned up functions, variables and added message
4952
structures for J1939, CANopen and CAN.
5053
05/07/14 1.0 PC Released Library to the public through GitHub
51-
06/18/14 1.9 NEM Preparing a unified CAN library across three different
54+
06/18/14 1.5 NEM Preparing a unified CAN library across three different
5255
CAN controllers
56+
06/14/15 1.6.0 NEM Code cleanup and compatibility with Arduino 1.6.*
5357
-------------------------------------------------------------------------------
5458
5559
*/

0 commit comments

Comments
 (0)