Skip to content

Commit

Permalink
Documentation content and formatting changes
Browse files Browse the repository at this point in the history
- Standardized header comments across all files
- Restricted text to 80 columns
- Added printing of millis() to ReceiveCANMessages.ino
- Revised the #ifdef BINGO!
- - Now, should only need to #include <CAN.h> and all platform detection
will happen automatically
  • Loading branch information
McNeight committed Jun 14, 2015
1 parent 1be10b3 commit a237c07
Show file tree
Hide file tree
Showing 13 changed files with 298 additions and 196 deletions.
18 changes: 11 additions & 7 deletions CAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
Acknowledgements:
Fabian Greif for the initial MCP2515 library
Fabian Greif for the initial libraries for MCP2515, SJA1000 and AT90CAN
http://www.kreatives-chaos.com/artikel/universelle-can-bibliothek
as well as his updates at https://github.com/dergraaf/avr-can-lib
David Harding for his version of the MCP2515 library
Expand All @@ -36,17 +36,21 @@ Cory Fowler (coryjfowler) for 16 MHz bitrate timing information
teachop for the FlexCAN library for the Teensy 3.1
https://github.com/teachop/FlexCAN_Library
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Change Log
DATE VER WHO WHAT
07/07/13 0.1 PC Modified and merge all MCP2515 libraries found. Stripped away most unused functions and corrected MCP2515 defs
09/12/13 0.2 PC Added selectable CS SPI for CAN controller to use 1 IC to control several mcp2515
07/07/13 0.1 PC Modified and merge all MCP2515 libraries found. Stripped
away most unused functions and corrected MCP2515 defs
09/12/13 0.2 PC Added selectable CS SPI for CAN controller to use 1 IC
to control several mcp2515
02/05/14 0.3 PC Added filter and mask controls
05/01/14 0.4 PC Cleaned up functions, variables and added message structures for J1939, CANopen and CAN.
05/01/14 0.4 PC Cleaned up functions, variables and added message
structures for J1939, CANopen and CAN.
05/07/14 1.0 PC Released Library to the public through GitHub
06/18/14 1.9 NEM Preparing a unified CAN library across three different CAN controllers
-------------------------------------------------------------------------------------------------------------
06/18/14 1.9 NEM Preparing a unified CAN library across three different
CAN controllers
-------------------------------------------------------------------------------
*/

Expand Down
78 changes: 50 additions & 28 deletions CAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
Acknowledgements:
Fabian Greif for the initial MCP2515 library
Fabian Greif for the initial libraries for MCP2515, SJA1000 and AT90CAN
http://www.kreatives-chaos.com/artikel/universelle-can-bibliothek
as well as his updates at https://github.com/dergraaf/avr-can-lib
David Harding for his version of the MCP2515 library
Expand All @@ -36,17 +36,21 @@ Cory Fowler (coryjfowler) for 16 MHz bitrate timing information
teachop for the FlexCAN library for the Teensy 3.1
https://github.com/teachop/FlexCAN_Library
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Change Log
DATE VER WHO WHAT
07/07/13 0.1 PC Modified and merge all MCP2515 libraries found. Stripped away most unused functions and corrected MCP2515 defs
09/12/13 0.2 PC Added selectable CS SPI for CAN controller to use 1 IC to control several mcp2515
07/07/13 0.1 PC Modified and merge all MCP2515 libraries found. Stripped
away most unused functions and corrected MCP2515 defs
09/12/13 0.2 PC Added selectable CS SPI for CAN controller to use 1 IC
to control several mcp2515
02/05/14 0.3 PC Added filter and mask controls
05/01/14 0.4 PC Cleaned up functions, variables and added message structures for J1939, CANopen and CAN.
05/01/14 0.4 PC Cleaned up functions, variables and added message
structures for J1939, CANopen and CAN.
05/07/14 1.0 PC Released Library to the public through GitHub
06/18/14 1.9 NEM Preparing a unified CAN library across three different CAN controllers
-------------------------------------------------------------------------------------------------------------
06/18/14 1.9 NEM Preparing a unified CAN library across three different
CAN controllers
-------------------------------------------------------------------------------
*/

Expand Down Expand Up @@ -105,27 +109,6 @@ DATE VER WHO WHAT
#define CAN_TIMEOUT_T3 1250
#define CAN_TIMEOUT_T4 1050

// It's time for #ifdef bingo!
#if defined(ARDUINO_ARCH_AVR)
#if defined(__AVR_AT90CAN32__) || \
defined(__AVR_AT90CAN64__) || \
defined(__AVR_AT90CAN128__)
#define CAN_CONTROLLER_AT90CAN
// Not sure if code will be different for these CPUs
//#elif defined(__AVR_ATmega32C1__) || defined(__AVR_ATmega64C1__) || \
// defined(__AVR_ATmega16M1__) || defined(__AVR_ATmega32M1__) || \
// defined(__AVR_ATmega64M1__)
#else
#define CAN_CONTROLLER_MCP2515
#endif // defined(ARDUINO_ARCH_AVR)
#elif defined(ARDUINO_ARCH_SAM) // Arduino Due
#define CAN_CONTROLLER_SAM3X
#elif defined(__MK20DX256__) // Teensy 3.1
#define CAN_CONTROLLER_K2X
#else
#error “Your CAN controller is currently unsupported.”
#endif

//
//
typedef struct __attribute__((__packed__))
Expand Down Expand Up @@ -215,4 +198,43 @@ class CANClass // Can't inherit from Stream
//extern CANClass CANbus;
// Unable to use extern on a base class

// It's time for #ifdef bingo!
#if defined(ARDUINO_ARCH_AVR)
//
#if defined(__AVR_AT90CAN32__) || \
defined(__AVR_AT90CAN64__) || \
defined(__AVR_AT90CAN128__)
#define CAN_CONTROLLER_AT90CAN
#include "CAN_AT90CAN.h"
// Not sure if code will be different for these CPUs
#elif defined(__AVR_ATmega32C1__) || \
defined(__AVR_ATmega64C1__) || \
defined(__AVR_ATmega16M1__) || \
defined(__AVR_ATmega32M1__) || \
defined(__AVR_ATmega64M1__)
#error Are you sure these are supported?
#else // Assume it's an AVR with SPI interface
//#if defined(MCP2515)
#define CAN_CONTROLLER_MCP2515 // SPI interface to MCP2515 chip
#include <SPI.h>
#include "CAN_MCP2515.h"
//#elif defined(SJA1000) // SPI interface to SJA1000 chip
//#define CAN_CONTROLLER_SJA1000
//#include <SPI.h>
//#include "CAN_SJA1000.h"
//#else
//#error "Your SPI CAN controller is currently unsupported."
//#endif // MCP2515 / SJA1000
#endif // AT90 / M1 / C1 / SPI

#elif defined(ARDUINO_ARCH_SAM) || defined(__SAM3X8E__) // Arduino Due
#define CAN_CONTROLLER_SAM3X
#include "CAN_SAM3X.h"
#elif defined(__MK20DX256__) // Teensy 3.1
#define CAN_CONTROLLER_K2X
#include "CAN_K2X.h"
#else
#error "Your CPU & CAN controller are currently unsupported."
#endif // ARDUINO_ARCH_*

#endif // _CAN_H_
58 changes: 40 additions & 18 deletions CAN_AT90CAN.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Copyright (C) 2014
Contributor: Pedro Cevallos
Contributors: Pedro Cevallos & Neil McNeight
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -16,28 +16,48 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
Acknowledgements:
Fabian Greif for the initial AT90CAN library from https://github.com/dergraaf/avr-can-lib
-------------------------------------------------------------------------------------------------------------
Fabian Greif for the initial libraries for MCP2515, SJA1000 and AT90CAN
http://www.kreatives-chaos.com/artikel/universelle-can-bibliothek
as well as his updates at https://github.com/dergraaf/avr-can-lib
David Harding for his version of the MCP2515 library
http://forum.arduino.cc/index.php/topic,8730.0.html
Kyle Crockett CANduino library with 16Mhz oscillator
http://code.google.com/p/canduino/
Nuno Alves for the help on Extended ID messaging
Stevenh for his work on library and all of the MCP research/work
http://modelrail.otenko.com/arduino/arduino-controller-area-network-can
Collin Kidder (collin80) for his work on the Arduino Due CAN interface
https://github.com/collin80/due_can
Daniel Kasamis (togglebit) both for his code at
https://github.com/togglebit/ArduinoDUE_OBD_FreeRunningCAN as well as his
DUE CANshield http://togglebit.net/product/arduino-due-can-shield/
Cory Fowler (coryjfowler) for 16 MHz bitrate timing information
https://github.com/coryjfowler/MCP2515_lib
teachop for the FlexCAN library for the Teensy 3.1
https://github.com/teachop/FlexCAN_Library
-------------------------------------------------------------------------------
Change Log
DATE VER WHO WHAT
-------------------------------------------------------------------------------------------------------------
Features:
CAN V2.0B
8 byte length in the data field
Standard and extended data frames
Two receive buffers
Three Transmit Buffers
Supported bitrates:
10 kbps; 20 kbps; 50 kbps; 100 kbps; 125 kbps; 250 kbps; 500 kbps; 1000 kbps
07/07/13 0.1 PC Modified and merge all MCP2515 libraries found. Stripped
away most unused functions and corrected MCP2515 defs
09/12/13 0.2 PC Added selectable CS SPI for CAN controller to use 1 IC
to control several mcp2515
02/05/14 0.3 PC Added filter and mask controls
05/01/14 0.4 PC Cleaned up functions, variables and added message
structures for J1939, CANopen and CAN.
05/07/14 1.0 PC Released Library to the public through GitHub
06/18/14 1.9 NEM Preparing a unified CAN library across three different
CAN controllers
-------------------------------------------------------------------------------
*/

#if defined(ARDUINO_ARCH_AVR)

#if defined(__AVR_AT90CAN32__) || \
defined(__AVR_AT90CAN64__) || \
defined(__AVR_AT90CAN128__)

#include <Arduino.h>
#include "CAN.h"
Expand All @@ -54,4 +74,6 @@ CAN_AT90CAN::CAN_AT90CAN()
{
}

#endif // defined(ARDUINO_ARCH_AVR)
#endif // defined(__AVR_AT90CAN32__) || \
// defined(__AVR_AT90CAN64__) || \
// defined(__AVR_AT90CAN128__)
63 changes: 40 additions & 23 deletions CAN_AT90CAN.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Copyright (C) 2014
Contributor: Pedro Cevallos
Contributors: Pedro Cevallos & Neil McNeight
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -16,40 +16,55 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
Acknowledgements:
Fabian Greif for the initial AT90CAN library from https://github.com/dergraaf/avr-can-lib
-------------------------------------------------------------------------------------------------------------
Fabian Greif for the initial libraries for MCP2515, SJA1000 and AT90CAN
http://www.kreatives-chaos.com/artikel/universelle-can-bibliothek
as well as his updates at https://github.com/dergraaf/avr-can-lib
David Harding for his version of the MCP2515 library
http://forum.arduino.cc/index.php/topic,8730.0.html
Kyle Crockett CANduino library with 16Mhz oscillator
http://code.google.com/p/canduino/
Nuno Alves for the help on Extended ID messaging
Stevenh for his work on library and all of the MCP research/work
http://modelrail.otenko.com/arduino/arduino-controller-area-network-can
Collin Kidder (collin80) for his work on the Arduino Due CAN interface
https://github.com/collin80/due_can
Daniel Kasamis (togglebit) both for his code at
https://github.com/togglebit/ArduinoDUE_OBD_FreeRunningCAN as well as his
DUE CANshield http://togglebit.net/product/arduino-due-can-shield/
Cory Fowler (coryjfowler) for 16 MHz bitrate timing information
https://github.com/coryjfowler/MCP2515_lib
teachop for the FlexCAN library for the Teensy 3.1
https://github.com/teachop/FlexCAN_Library
-------------------------------------------------------------------------------
Change Log
DATE VER WHO WHAT
-------------------------------------------------------------------------------------------------------------
Features:
CAN V2.0B
8 byte length in the data field
Standard and extended data frames
Two receive buffers
Three Transmit Buffers
Supported bitrates:
10 kbps; 20 kbps; 50 kbps; 100 kbps; 125 kbps; 250 kbps; 500 kbps; 1000 kbps
07/07/13 0.1 PC Modified and merge all MCP2515 libraries found. Stripped
away most unused functions and corrected MCP2515 defs
09/12/13 0.2 PC Added selectable CS SPI for CAN controller to use 1 IC
to control several mcp2515
02/05/14 0.3 PC Added filter and mask controls
05/01/14 0.4 PC Cleaned up functions, variables and added message
structures for J1939, CANopen and CAN.
05/07/14 1.0 PC Released Library to the public through GitHub
06/18/14 1.9 NEM Preparing a unified CAN library across three different
CAN controllers
-------------------------------------------------------------------------------
*/

#if defined(ARDUINO_ARCH_AVR)

#if defined(__AVR_AT90CAN32__) || \
defined(__AVR_AT90CAN64__) || \
defined(__AVR_AT90CAN128__)

#ifndef _CAN_AT90CAN_H_
#define _CAN_AT90CAN_H_

#include <Arduino.h>
#include "CAN.h"

#if (defined (__AVR_AT90CAN32__) || \
defined (__AVR_AT90CAN64__) || \
defined (__AVR_AT90CAN128__)) && \
BUILD_FOR_AT90CAN == 1

#if F_CPU != 16000000UL
#error only 16 MHz for F_CPU supported!
#endif
Expand Down Expand Up @@ -182,4 +197,6 @@ class CAN_AT90CAN : public CANClass

#endif // _CAN_AT90CAN_H_

#endif // defined(ARDUINO_ARCH_AVR)
#endif // defined(__AVR_AT90CAN32__) || \
// defined(__AVR_AT90CAN64__) || \
// defined(__AVR_AT90CAN128__)
18 changes: 11 additions & 7 deletions CAN_K2X.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
Acknowledgements:
Fabian Greif for the initial MCP2515 library
Fabian Greif for the initial libraries for MCP2515, SJA1000 and AT90CAN
http://www.kreatives-chaos.com/artikel/universelle-can-bibliothek
as well as his updates at https://github.com/dergraaf/avr-can-lib
David Harding for his version of the MCP2515 library
Expand All @@ -36,17 +36,21 @@ Cory Fowler (coryjfowler) for 16 MHz bitrate timing information
teachop for the FlexCAN library for the Teensy 3.1
https://github.com/teachop/FlexCAN_Library
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Change Log
DATE VER WHO WHAT
07/07/13 0.1 PC Modified and merge all MCP2515 libraries found. Stripped away most unused functions and corrected MCP2515 defs
09/12/13 0.2 PC Added selectable CS SPI for CAN controller to use 1 IC to control several mcp2515
07/07/13 0.1 PC Modified and merge all MCP2515 libraries found. Stripped
away most unused functions and corrected MCP2515 defs
09/12/13 0.2 PC Added selectable CS SPI for CAN controller to use 1 IC
to control several mcp2515
02/05/14 0.3 PC Added filter and mask controls
05/01/14 0.4 PC Cleaned up functions, variables and added message structures for J1939, CANopen and CAN.
05/01/14 0.4 PC Cleaned up functions, variables and added message
structures for J1939, CANopen and CAN.
05/07/14 1.0 PC Released Library to the public through GitHub
06/18/14 1.9 NEM Preparing a unified CAN library across three different CAN controllers
-------------------------------------------------------------------------------------------------------------
06/18/14 1.9 NEM Preparing a unified CAN library across three different
CAN controllers
-------------------------------------------------------------------------------
*/

Expand Down
Loading

0 comments on commit a237c07

Please sign in to comment.