Skip to content

Commit

Permalink
Initial contents commit
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelJonker authored and MichaelJonker committed Dec 29, 2014
1 parent b5ae07a commit f5492af
Show file tree
Hide file tree
Showing 27 changed files with 4,334 additions and 5 deletions.
22 changes: 22 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Note: because this repository is a 'fine' selection of a much larger file structure in my work directory
# I choose to ignore all
*

# As git does not ignore files specified in .gitignore that are already tracked,
# files can be added to the repository with git add -f. <file>
# However, for completeness, all what should be in the repository is summed up here.
# note: git is case insensitive to the entries in .gitignore

### not ignored (hence included) are ======================

#this file
!.gitignore

#the project readme
!readme.md

# The library folder:
!libraries
#
# The folder with the arduino sketch to test the code :
!morse
172 changes: 167 additions & 5 deletions README.md

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions libraries/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Note: because this repository is a 'fine' selection of a much larger file structure in my work directory
# I choose to ignore all
*

# As git does not ignore files specified in .gitignore that are already tracked,
# files can be added to the repository with git add -f. <file>
# However, for completeness, all what should be in the repository is summed up here.
# note: git is case insensitive to the entries in .gitignore

### not ignored (hence included) are ======================

#this file
!.gitignore

#the libraries readme
!readme.md

# The library folders:
!HardwareSerial_RS485
!MessageFilter
!Morse
40 changes: 40 additions & 0 deletions libraries/HardwareSerial_RS485/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Note: because this repository is a 'fine' selection of a much larger file structure in my work directory
# I choose to ignore all
*

# As git does not ignore files specified in .gitignore that are already tracked,
# files can be added to the repository with git add -f. <file>
# However, for completeness, all what should be in the repository is summed up here.
# note: git is case insensitive to the entries in .gitignore

### not ignored (hence included) are ======================

#this file
!.gitignore
!Figure1.JPG

#the HardwareSerial_RS485 readme
!readme.md

#the HardwareSerial_RS485 header and implementation file
!HardwareSerial_RS485.h
!HardwareSerial_RS485.cpp

#the HardwareSerial_RS485Enabled and HardwareSerial_RS485Helper class
!HardwareSerial_RS485Enabled.h
!HardwareSerial_RS485Helper.h

#the USB specific adaptation of HardwareSerial
!HardwareSerial_USB.cpp
!HardwareSerial_USB.h

#template definitions for generic bit handling
!BitManipulation.h

#enhance Print.h class
!Print.h
!Print.cpp

!USARTdef.h

!USART_analysis.bash
37 changes: 37 additions & 0 deletions libraries/HardwareSerial_RS485/BitManipulation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* BitManipulation.h
templates for bit manipulation
Copyright (c) 2014 Michael Jonker. All right reserved.
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 2.1 of the License, or (at your option)
any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/


#ifndef BitManipulation_h
#define BitManipulation_h
// define templates for easy bit manipulation
template <typename R, typename V> inline void setBits (R &item, const V set) { item = (item | set); }
template <typename R, typename V> inline void clrBits (R &item, const V clr) { item = (item &~clr); }
template <typename R, typename V> inline void modBits (R &item, const V set, V clr) { item = (item &~clr ) | set; }
template <typename R, typename V> inline void setBit (R &item, const V set) { item = (item | (1<<set)); }
template <typename R, typename V> inline void clrBit (R &item, const V clr) { item = (item &~(1<<clr)); }
template <typename R, typename V> inline bool testBit (const R item, const V bit) { return (item & (1<<bit))!=0; }
template <typename R, typename V> inline bool testBitsAny (const R item, const V bits) { return (item & bits)!=0; }
template <typename R, typename V> inline bool testBitsAll (const R item, const V bits) { return (item & bits)==bits; }
template <typename R, typename V> inline bool testBitField(const R item, const V FieldMask, const V FieldValue) { return (item & ~FieldMask)==(FieldValue & FieldMask); }
template <typename R, typename V> inline void setBitField (R &item, const V FieldMask, const V FieldValue) { item = (item & ~FieldMask) |(FieldValue & FieldMask); }
template <typename R, typename V> inline void neukBits (R &item, const V ClrMask, const V SetMask) { item = (item & ~(ClrMask^SetMask)) ^SetMask; }
#endif // ifndef BitManipulation_h
Binary file added libraries/HardwareSerial_RS485/Figure1.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions libraries/HardwareSerial_RS485/HardwareSerial_RS485.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* HardwareSerial_RS485.cpp copyright notice
Replacement of the classical HardwareSerial version for Wiring by Nicholas Zambetti, Mark Sproul, Alarus
Copyright (c) 2014 Michael Jonker. All right reserved.
http://en.wikipedia.org/wiki/Beerware
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* Michael Jonker <EPID: 52.36040, 4.87001, 5m, AD19540508.621> wrote this file.
* As long as you retain this notice you can do whatever you want with this stuff.
* If we meet some day, and you think this stuff is worth it, you can buy me a beer in return.
This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details. You can obtain a copy of this license
from the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#define InHardwareSerial_RS485_CPP
#include "HardwareSerial_RS485.h"
// All static data and code of the HardwareSerial classes are instantiated by compiling and linking this file.
// However, the actual code is located in HardwareSerial_RS485.h and HardwareSerial_RS485Enabled.h
// This is a personal style choice for ease of maintenance (with minor overhead).

#if defined(HardwareSerial_use_classical_version)
// we use the classical version, we include the cpp code from HardwareSerial.cpp
#warning "HardwareSerial_RS485 uses classical version ======================================================"
#include "HardwareSerial.cpp"
#endif



/* testing options:
# options to compile outside Arduino environment (for debugging and code optimisation)
cd $Arduino
arduino-1.0.5/hardware/tools/avr/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -MMD -DARDUINO=105\
-mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 \
-Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/standard \
-ImyProjects/libraries/HardwareSerial_RS485 \
-S myProjects/libraries/HardwareSerial_RS485/HardwareSerial_RS485.cpp
-mmcu=atmega32u4 -DF_CPU=16000000L -DUSB_VID=0x2341 -DUSB_PID=0x8039 -Iarduino-1.0.5/hardware/arduino/cores/arduino/robot -Iarduino-1.0.5/hardware/arduino/variants/standard/robot_motor \
-mmcu=atmega328p -DF_CPU=16000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/standard \
Board:
Mega(ATmega1280) -mmcu=atmega1280 -DF_CPU=16000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/mega
BT w/ ATmega168 -mmcu=atmega168 -DF_CPU=16000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/eightanaloginputs
Mini w/ ATmega168 -mmcu=atmega168 -DF_CPU=16000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/eightanaloginputs
Nano w/ ATmega168 -mmcu=atmega168 -DF_CPU=16000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/eightanaloginputs
Diecimila or Duemilanove w/ ATmega328lanova w/ ATmega168 -mmcu=atmega168 -DF_CPU=16000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/standard
NG or older w/ ATmega168 -mmcu=atmega168 -DF_CPU=16000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/standard
Pro or Pro Mini (5V,16 MHz) w/ ATmega168 -mmcu=atmega168 -DF_CPU=16000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/standard
Lilipad w/ ATmega168 -mmcu=atmega168 -DF_CPU=8000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/standard
Pro or Pro Mini (3.3V,8 MHz) w/ ATmega168 -mmcu=atmega168 -DF_CPU=8000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/standard
Mega 2560 or Mega ADK -mmcu=atmega2560 -DF_CPU=16000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/mega
BT w/ ATmega328 -mmcu=atmega328p -DF_CPU=16000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/eightanaloginputs
Mini w/ ATmega328 -mmcu=atmega328p -DF_CPU=16000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/eightanaloginputs
Nano w/ ATmega328 -mmcu=atmega328p -DF_CPU=16000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/eightanaloginputs
Duemilanove w/ ATmega328 -mmcu=atmega328p -DF_CPU=16000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/standard
Pro or Pro Mini (5V,16 MHz) w/ ATmega328 -mmcu=atmega328p -DF_CPU=16000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/standard
Ethernet -mmcu=atmega328p -DF_CPU=16000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/standard
UNO -mmcu=atmega328p -DF_CPU=16000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/standard
Fio -mmcu=atmega328p -DF_CPU=8000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/eightanaloginputs
Lilipad w/ ATmega328 -mmcu=atmega328p -DF_CPU=8000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/standard
Pro or Pro Mini (3.3V,8 MHz) w/ ATmega328 -mmcu=atmega328p -DF_CPU=8000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/standard
Leonardo -mmcu=atmega32u4 -DF_CPU=16000000L -DUSB_VID=0x2341 -DUSB_PID=0x8036 -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/leonardo
Micro -mmcu=atmega32u4 -DF_CPU=16000000L -DUSB_VID=0x2341 -DUSB_PID=0x8037 -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/micro
Robot Control -mmcu=atmega32u4 -DF_CPU=16000000L -DUSB_VID=0x2341 -DUSB_PID=0x8038 -Iarduino-1.0.5/hardware/arduino/cores/robot -Iarduino-1.0.5/hardware/arduino/variants/robot_control
Robot Motor -mmcu=atmega32u4 -DF_CPU=16000000L -DUSB_VID=0x2341 -DUSB_PID=0x8039 -Iarduino-1.0.5/hardware/arduino/cores/robot -Iarduino-1.0.5/hardware/arduino/variants/robot_motor
Esplora -mmcu=atmega32u4 -DF_CPU=16000000L -DUSB_VID=0x2341 -DUSB_PID=0x803C -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/leonardo
Lilipad USB -mmcu=atmega32u4 -DF_CPU=8000000L -DUSB_VID=0x1B4F -DUSB_PID=0x9208 -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/leonardo
NG or older w/ ATmega8 -mmcu=atmega8 -DF_CPU=16000000L -DUSB_VID=null -DUSB_PID=null -Iarduino-1.0.5/hardware/arduino/cores/arduino -Iarduino-1.0.5/hardware/arduino/variants/standard
# see http://gcc.gnu.org/wiki/avr-gcc
# see http://gcc.gnu.org/onlinedocs/gcc-4.3.6/gcc/Optimize-Options.html#Optimize-Options
arduino-1.0.5/hardware/tools/avr/bin/avr-g++ -v --help
arduino-1.0.5/hardware/tools/avr/bin/avr-gcc -v --help
g++ -E HardwareSerial.cpp > HardwareSerial.p #preprocess only
g++ -S HardwareSerial.cpp #assemble only
g++ -c HardwareSerial.cpp #compile only
g++ -O0 -g HardwareSerial.cpp #compile and link, no optimisation
g++ -mmcu=atmega328p -S HardwareSerial.cpp
g++ -mmcu=atmega328p -c HardwareSerial.cpp
g++ -mmcu=atmega328p HardwareSerial.cpp
*/

141 changes: 141 additions & 0 deletions libraries/HardwareSerial_RS485/HardwareSerial_RS485.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/* HardwareSerial_RS485.h copyright notice
Replacement of the classical HardwareSerial version for Wiring by Nicholas Zambetti, Mark Sproul, Alarus.
Copyright (c) 2014 Michael Jonker. All right reserved.
http://en.wikipedia.org/wiki/Beerware
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* Michael Jonker <EPID: 52.36040, 4.87001, 5m, AD19540508.621> wrote this file.
* As long as you retain this notice you can do whatever you want with this stuff.
* If we meet some day, and you think this stuff is worth it, you can buy me a beer in return.
This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details. You can obtain a copy of this license
from the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#if !defined(HardwareSerial_RS485_h)
#define HardwareSerial_RS485_h


#if !defined(HardwareSerial_use_classical_version)
#if !defined(HardwareSerial_h)
#define HardwareSerial_h /* block loading the classsical version of HardwareSerial */
#else
#error "HardwareSerial.h already loaded. The file HardwareSerial_RS485.h must be included before the #include "Arduino.h" (whether explicit or implicit)."
#endif

#include <HardwareSerial_RS485Helper.h>
#include <HardwareSerial_RS485Enabled.h>

/* define Hardware Serial classes for all objects.
notes:
if defined_SerialClass<n> has been defined externally, this definition will be used. If not, a default will be chosen.
if the externally defined defined_SerialClass<n> is 'empty', then no Serial class will be created.
//todo include a user accessible configuration file, allowing to externalize the definition of the SerialClass(es) an to keep this header file 'clean'.
*/
#if defined(USBCON)
#include "HardwareSerial_USB.h"
extern HardwareSerial_USB Serial_;
#endif
#if defined(UCSR0A)
#if !defined(defined_SerialClass0)
#define defined_SerialClass0 HardwareSerial<USART0, 6, 6, ' ', RS485serial< >, MessageFilterRT >
#endif
//#if defined_SerialClass0 //todo find a way to implement a test like #if defined_SerialClass0 != null
typedef defined_SerialClass0 SerialClass0;
extern SerialClass0 Serial0;
//#endif
#endif
#if defined(UCSR1A)
#if !defined(defined_SerialClass1)
#define defined_SerialClass1 HardwareSerial<USART1>
#endif
//#if defined_SerialClass1
typedef defined_SerialClass1 SerialClass1;
extern SerialClass1 Serial1;
//#endif
#endif
#if defined(UCSR2A)
#if !defined(defined_SerialClass2)
#define defined_SerialClass2 HardwareSerial<USART2>
#endif
//#if defined_SerialClass2
typedef defined_SerialClass2 SerialClass2;
extern SerialClass2 Serial2;
//#endif
#endif
#if defined(UCSR3A)
#if !defined(defined_SerialClass3)
#define defined_SerialClass3 HardwareSerial<USART3>
#endif
//#if defined_SerialClass3
typedef defined_SerialClass3 SerialClass3;
extern SerialClass3 Serial3;
//#endif
#endif
// other examples:
//#define defined_SerialClass HardwareSerial<USART0, 5, 6, ' ', RS485serial<> > // RS485 only, no message filter
//#define defined_SerialClass HardwareSerial<USART0, 5, 6, ' ', RS485serial< TRxControl<'C', 2, 3> >, MessageFilterRT >
//#define defined_SerialClass HardwareSerial<USART0, 5, 6, ' ', RS485_dummy>

#if defined(USBCON)
#define Serial Serial_
#else
#define Serial Serial0
#endif

#if defined(InHardwareSerial_RS485_CPP)
// link the hardware interrupt vectors to the interrupt methods of the HWSerial class
#if defined(defined_SerialClass0)
SerialClass0 Serial0;
link_USART_Vectors(USART0, Serial0);
void serialEvent0() __attribute__((weak));
void serialEvent0() {}
#endif
#if defined(defined_SerialClass1)
SerialClass1 Serial1;
link_USART_Vectors(USART1, Serial1);
void serialEvent1() __attribute__((weak));
void serialEvent1() {}
#endif
#if defined(defined_SerialClass2)
SerialClass2 Serial2;
link_USART_Vectors(USART2, Serial2);
void serialEvent2() __attribute__((weak));
void serialEvent2() {}
#endif
#if defined(defined_SerialClass3)
SerialClass3 Serial3;
link_USART_Vectors(USART3, Serial3);
void serialEvent3() __attribute__((weak));
void serialEvent3() {}
#endif

// define the USART classes
extern void serialEventRun(void) __attribute__((weak));
void serialEventRun(void)
{
#if defined(defined_SerialClass0)
if (Serial0.available()) serialEvent();
#endif
#if defined(defined_SerialClass1)
if (Serial1.available()) serialEvent1();
#endif
#if defined(defined_SerialClass2)
if (Serial2.available()) serialEvent2();
#endif
#if defined(defined_SerialClass3)
if (Serial3.available()) serialEvent3();
#endif
}


#endif // defined(InHardwareSerial_RS485_CPP)

#endif // !defined(HardwareSerial_use_classical_version)

#endif // !defined(HardwareSerial_RS485_h)
Loading

0 comments on commit f5492af

Please sign in to comment.