Compare commits

...

841 Commits

Author SHA1 Message Date
Sergiusz B e8dcb52425 Better steps/mm. 2013-04-28 22:43:29 +02:00
Sergiusz B 3325a1eeae Change the pins around to fit our connection scheme. 2013-04-28 20:10:18 +02:00
Sergiusz B 6330a35209 Add new sketchfile. 2013-04-28 13:20:30 +02:00
Sergiusz B e1919f3d4f Green hackerspace printer. 2013-04-28 13:08:05 +02:00
ErikZalm 4f96ad5621 Merge pull request #456 from Stefanowicz/Marlin_v1
Add (as an option) slower SD transfer mode
2013-04-24 02:01:52 -07:00
Lukasz Stefanowicz d71f1e9bf6 Add (as an option) slower SD transfer mode 2013-04-24 10:50:57 +02:00
ErikZalm db5bb8546d Merge pull request #452 from MStohn/Marlin_v1
128x64 RepRapDiscount Full Graphic Smart Controller support
2013-04-23 09:43:37 -07:00
daid 4b2ece159b Merge pull request #453 from brackendawson/Marlin_v1
Make Gen7 1.4+ heater temp sensort pins match silkscreen.
2013-04-16 10:12:25 -07:00
Bracken Dawson d5ee2a5a62 Make Gen7 1.4 heater pins match silkscreen 2013-04-16 17:37:38 +01:00
MaikStohn 7ac6d7f78e FIX: Speedup - no explicit display clear needed in u8glib 2013-04-16 14:22:24 +02:00
MaikStohn 13596e8722 Added RepRapDiscount FULL GRAPHIC Smart Controller 2013-04-16 14:21:39 +02:00
MaikStohn 3a6abe1d6e Removed STB custom font hack from u8glib library and moved to marlin project 2013-04-16 13:54:39 +02:00
MaikStohn 16afbf9bfa FIX: adopted latest changes from hitachi implementation 2013-04-16 13:51:48 +02:00
MaikStohn c83863d5d6 add U8glib library to Arduino1.x includes 2013-04-16 12:44:54 +02:00
daid303 34bca48b98 Merge branch 'Marlin_v1' of github.com:ErikZalm/Marlin into Marlin_v1 2013-04-15 15:11:38 +02:00
daid303 ac52dcc174 Updated the card menu and watch messages to make it more informative. 2013-04-15 15:11:22 +02:00
daid 84920e9c58 Merge pull request #449 from Stefanowicz/Marlin_v1
Fix: Build error when EEPROM_SETTINGS is defined and PIDTEMP is undefined
2013-04-12 13:45:15 -07:00
Stefanowicz 31bb3fb297 Fix: Build error when EEPROM_SETTINGS is defined and PIDTEMP is undefined 2013-04-12 18:04:32 +02:00
daid303 c80a78bb70 Lower the default max E feedrate a bit. With the stepper fix this is much to high. 2013-04-12 13:54:38 +02:00
Simon Oliver 5d5909fc25 Fix failure to compile with heated bed: remove call to non-existant scaleBedPID(). 2013-04-12 13:32:47 +02:00
Simon Oliver 93f0463b21 Allow Edit menu to call fn after edit; Fix PID Ki and Kd display in menus; Actually use changed PID and Max Accel values
Add new 'callback' edit-menu types that call a function after the edit is done. Use this to display and edit Ki and Kd correctly (removing the scaling first and reapplying it after). Also use it to reset maximum stepwise acceleration rates, after updating mm/s^2 rates via menus. (Previously, changes did nothing to affect planner unless saved back to EEPROM, and the machine reset).

Add calls to updatePID() so that PID loop uses updated values whether set by gcode (it already did this), or by restoring defaults, or loading from EEPROM (it didn't do those last two). Similarly, update the maximum step/s^2 accel rates when the mm/s^2 values are changed - whether by menu edits, restore defaults, or EEPROM read.

Refactor the acceleration rate update logic, and the PID scaling logic, into new functions that can be called from wherever, including the callbacks.

Add menu items to allow the z jerk and e jerk to be viewed/edited in the Control->Motion menu, as per xy jerk.

Conflicts:
	Marlin/language.h
2013-04-12 13:31:30 +02:00
ErikZalm 1f74ef4157 Merge pull request #441 from bkpsu/Marlin_v1
Fixed cardreader.h to resolve issue #440 (Pull Request  #425 missing file)
2013-04-01 01:06:10 -07:00
Bart K 4fa2260a59 Fixed cardreader.h to resolve issue #440 (Pull Request #425 missing file) 2013-03-31 19:59:16 -04:00
Erik van der Zalm 038d405254 Corrected #endif in language.h 2013-03-31 20:28:29 +02:00
ErikZalm 2438b34df9 Merge pull request #439 from STB3/Marlin-language.h-repair
Removed GIT fragments from language.h
2013-03-30 15:44:26 -07:00
Dirk Eichel 443aaa30bf Removed GIT fragments
Seems that there was something wrong while merging
2013-03-30 23:26:42 +01:00
ErikZalm 7f622467fc Merge pull request #425 from kefir-/m928_logging
M928 logging
2013-03-30 08:50:34 -07:00
ErikZalm 86867928ac Merge pull request #434 from DDRBoxman/Marlin_v1
Add support for M300: Play beep sound
2013-03-30 08:49:54 -07:00
ErikZalm 9a38cad6f0 Merge pull request #430 from STB3/GLCD_128x64_dots
Final task of the 128x64dots GLCD implementation
2013-03-30 08:49:14 -07:00
ErikZalm 7a5c474d91 Update Configuration.h 2013-03-28 21:27:50 +01:00
Dirk Eichel 4e448b700a Merged fetched files from Marlin_v1 branch
Pull requests: #414 #433 #432 #428
2013-03-26 21:43:04 +01:00
Dirk Eichel fa58be3cb8 Merge remote-tracking branch 'upstream/Marlin_v1' into Marlin_v1 2013-03-26 21:37:05 +01:00
ErikZalm 9f2862ce48 Merge pull request #414 from whosawhatsis/Marlin_v1
regenerated thermistor table 7
2013-03-25 13:14:49 -07:00
ErikZalm 9fb8bd5685 Merge pull request #433 from whosawhatsis/bang-mode
Separate PID_MAX from BANG_MAX
2013-03-25 13:11:34 -07:00
ErikZalm aa816ee81c Merge pull request #432 from blddk/Marlin_v1
HTML removed, Rumba added
2013-03-25 13:06:25 -07:00
Colin Edwards 0d075378d5 Add LARGE_FLASH define and enable it for some of the beefier boards
The LARGE_FLASH flag allows superfluous features to be excluded
on boards with less memory
2013-03-25 10:42:27 -05:00
Colin Edwards 9a1c90471f Ignore unused beeper pins 2013-03-25 10:28:15 -05:00
Colin Edwards 1a0f889803 Add support for M300: Play beep sound 2013-03-24 23:35:05 -05:00
whosawhatsis fd5b7e0cec Separate PID_MAX from BANG_MAX
This allows PID_FUNCTIONAL_RANGE to use a maximum duty cycle higher
than PID_MAX. This is useful for powerful heaters to heat quickly in
bang-bang mode, but use a lower duty cycle that is easier to stabilize
in PID mode.
2013-03-22 18:16:26 -07:00
blddk e5a853a3d0 Added automated extruder fan function 2013-03-22 18:49:05 +01:00
blddk 72419f69a9 Added rumba 2013-03-22 18:41:54 +01:00
blddk 91bea43332 Added rumba pinout 2013-03-22 18:29:47 +01:00
blddk d2b00fe486 Removed html and added rumba
Found some unwanted html at the bottom of the file which caused it to not be able to compile.
Also added rumba as machine.
2013-03-22 18:28:16 +01:00
Dirk Eichel 6c66cae694 GLCD init screen cosmetics 2013-03-19 21:25:11 +01:00
Dirk Eichel f3e0e5184d Add include selector between char. LCD and GLCD 2013-03-19 20:59:21 +01:00
Dirk Eichel 5d3862f9d1 Modified u8glib logo on welcome screen 2013-03-19 20:32:23 +01:00
Dirk Eichel 0b320f75e9 Removed debug code, add some comments 2013-03-19 20:29:25 +01:00
Dirk Eichel 5f1cd70122 Add code to lcd_update() for GLCD
This code selects between the routines for the GLCD or the char.
display.
2013-03-19 20:19:16 +01:00
Dirk Eichel a49c09a776 Add variable for animated fan, add float conversion w/o sign
A new variable was introduced to allow fan animation on the GLCD.
Add additional float to string conversion routine without sign
character. This is used for the coordinates visualisation on the GLCD.
2013-03-19 20:13:23 +01:00
Dirk Eichel 26d8863111 Add library selection between GLCD and char. LCD 2013-03-19 20:03:47 +01:00
Dirk Eichel 4a141a694f Marlin code for GLCD display
This contains the menues, status screen etc...
2013-03-19 19:59:56 +01:00
Dirk Eichel 83c790a020 Add bitmap graphics for GLCD
1. Marlin welcome screen
2. Status screen symbols 3 Extruders, heated bed, animated fan logo 1
3. Status screen symbols 3 Extruders, heated bed, animated fan logo 2
2013-03-19 19:57:35 +01:00
Dirk Eichel c28e71a1bf Reduced u8glib SPI speed to fosc/8
Makes the lib compatible with most LCDs
2013-03-19 19:50:08 +01:00
Dirk Eichel ee8feb9dee Add Marlin (reprap) specific fonts 6x10, 6x9
Font size 6x10 with feedrate symbol & Font size 6x9.
2013-03-19 19:45:57 +01:00
Dirk Eichel c8e2f44087 Add u8glib library supporting dot matrix displays
https://code.google.com/p/u8glib/
Universal Graphics Library for 8 Bit Embedded Systems
2013-03-19 19:41:23 +01:00
Dirk Eichel 7417423691 Merge remote-tracking branch 'origin/Marlin_language_file_fix' into GLCD_128x64_dots 2013-03-19 19:38:44 +01:00
ErikZalm 590225be25 Merge pull request #428 from ryanturner/Marlin_v1
Adding Maker's Tool Works heated bed thermistor
2013-03-19 11:32:47 -07:00
Dirk Eichel a0e41c0970 Merge remote-tracking branch 'upstream/Marlin_v1' into Marlin_v1 2013-03-19 19:16:00 +01:00
Dirk Eichel 233df9cca0 Add missing LF at the end of the file 2013-03-19 19:12:33 +01:00
Dirk Eichel bb0de75a92 Removed umwanted HTML code ath the end of the file
Sorry for that. This does not lead to compile errors. I removed the
unwanted code to make it clean.
2013-03-19 06:46:05 +01:00
Ryan Turner 7c47e7162d Adding Maker's Tool Works heated bed thermistor 2013-03-18 22:53:37 -05:00
daid af78d0cbfa Merge pull request #1 from illuminarti/Fix_E_Speed
Fix step rate bug (especially for retraction)
2013-03-18 23:36:11 +01:00
Dirk Eichel 9a78f321a4 Add pins for Motherboard variant 64
These definition contain also the definition for the graphics LCD.
2013-03-18 23:36:11 +01:00
Dirk Eichel 5de25ccd20 Add Motherboard variant 64 - STB V1.1
Definition for the graphic LCD are already in it, they will not harm the
configuration as they are only defined constants
2013-03-18 23:36:10 +01:00
daid d6ce63c49c Merge pull request #411 from STB3/Marlin_w_STB_Board_support
Add STB board support to Marlin (next step towards graphic LCD implementation)
2013-03-18 07:57:39 -07:00
Ketil Froyn f036be7c4e Clean up tab/whitespace from last commit 2013-03-16 23:11:58 +01:00
Ketil Froyn 07e11c7cf5 Add command M928 to enable logging to file of received gcode commands 2013-03-16 23:02:57 +01:00
daid 92782f9252 Merge pull request #1 from illuminarti/Fix_E_Speed
Fix step rate bug (especially for retraction)
2013-03-15 09:07:34 +01:00
whosawhatsis 6a61a3c0b4 missing comma in last commit 2013-03-08 16:15:49 -08:00
whosawhatsis f0aee4101a regenerated thermistor table 7
Generated with createTemperatureLookup.py. The old table crapped out at
270C, which was a problem for polycarbonate.
2013-03-08 13:41:49 -08:00
Dirk Eichel 140e095c6e Add pins for Motherboard variant 64
These definition contain also the definition for the graphics LCD.
2013-03-01 17:47:32 +01:00
Dirk Eichel b2c1c64fb1 Add Motherboard variant 64 - STB V1.1
Definition for the graphic LCD are already in it, they will not harm the
configuration as they are only defined constants
2013-03-01 17:39:54 +01:00
Dirk Eichel ceb5ee38af Replaced corrupted language.h file on local PC with current from ErikZalm/Marlin 2013-03-01 17:27:57 +01:00
Dirk Eichel 8efd4cfd73 fixed merge conflict 2013-03-01 16:27:35 +01:00
daid b3ebb71704 Merge pull request #408 from STB3/Marlin_with_ATmega1284p_Sanguino_on_023_support
Marlin with ATmega1284p sanguino support under Arduino 023
2013-03-01 06:08:18 -08:00
Dirk Eichel f991bf23b2 Add bootloader files for ATmega1284/Sanguino
Added the optiboot bootloader, uses only 512kB of FLASH
Includes .hex file is for 20MHz µC Clock and serial speed of 57k6
2013-02-27 22:34:36 +01:00
Dirk Eichel 5bfba7720e Switched to Sanguino 0023r4
This is the actual Sanguino release for Arduino 023.
It has full ATmega1284p support.

Reference:
https://code.google.com/p/sanguino/downloads/detail?name=Sanguino-0023r4.zip&can=2&q=
2013-02-27 22:29:46 +01:00
Dirk Eichel a069d30a4b Add additional Sanguino bard versions to boards.txt
ATmega644P 16MHz, ATmega1284p 8, 16, 20MHz
2013-02-27 22:17:42 +01:00
daid303 4eb81a69e6 Only compile the new extruder offset code if you have multiple extruders. 2013-02-27 12:32:07 +01:00
daid 3e9cd334a4 Merge pull request #383 from dob71/jeff
Hotend offset handling for multi-extruder machines
2013-02-27 03:10:18 -08:00
daid303 de3dec7215 Also show the tune menu when USB printing. 2013-02-20 00:54:44 +01:00
Denis Bakin 73d41c10b9 Merge branch 'Marlin_v1' of github.com:ErikZalm/Marlin into jeff
Conflicts:
	Marlin/language.h
	Marlin/thermistortables.h
2013-02-18 12:10:52 -05:00
daid 63da4dc59a Merge pull request #398 from DanieleSdei/Marlin_v1
Marlin v1, alignment of the Italian language
2013-02-16 15:41:43 -08:00
daid 7eb9811958 Merge pull request #397 from codenamepawel/patch-1
Update Marlin/language.h
2013-02-16 15:41:07 -08:00
Daniele Sdei 82e28851bd Italian language: SD-Card change and SD-Card init 2013-02-16 12:17:29 +01:00
Daniele Sdei aed5965ad8 Italian language: remove space and some fix 2013-02-16 12:14:50 +01:00
codenamepawel d360846dd4 Update Marlin/language.h
Update Polish language 	#define MSG_RESUMING "Wznawiam drukowanie"
2013-02-16 03:42:53 +01:00
daid303 2f60e324dc Fixed #394 2013-02-14 14:04:26 +01:00
daid 5e2abfcdcd Merge pull request #391 from STB3/Marlin_with_SD-Card_Change_Menu
Add SD-Card change and SD-Card init. for electronics equipped with LCD Display
2013-02-13 08:56:00 -08:00
daid fa5c45f515 Merge pull request #392 from mfeherpataky/Marlin_v1
Update Marlin/ultralcd_implementation_hitachi_HD44780.h
2013-02-13 08:54:58 -08:00
Dirk Eichel a0d4e8e78e Add Messages for SD Card init. & change 2013-02-13 10:05:18 +01:00
mfeherpataky bbf0cc1379 Update Marlin/ultralcd_implementation_hitachi_HD44780.h
Fix to a bug that I just introduced - sorry. Forgot about offset of string length.
2013-02-12 20:06:51 +01:00
Dirk Eichel c8f1fbd9d8 Add SD-Card change and SD-Card init.
Add SD-Card change and SD-Card init. for reprap electronics without
SD-Chard change detect pin.
2013-02-12 17:35:46 +01:00
daid be91fb9b47 Merge pull request #389 from mfeherpataky/Marlin_v1
Update Marlin/ultralcd_implementation_hitachi_HD44780.h
2013-02-12 07:56:15 -08:00
mfeherpataky 71ddb8dc60 Update Marlin/ultralcd_implementation_hitachi_HD44780.h
Use all available characters in narrow LCDs < 20 characters.
2013-02-12 00:03:40 +01:00
mfeherpataky d2c547c407 Update Marlin/ultralcd_implementation_hitachi_HD44780.h
Fix to a minor bug with hardcoded LCD_WIDTH that draws edited values outside of the 16 characters width LCDs.
2013-02-11 23:25:24 +01:00
Denis B 70871715e4 Added support for extruder offset handling
The extruder offset can be specified in the configuration
file or adjusted on the fly using the "M218 T# X# Y#" command.
The EEPROM support is not yet merged in.
The "T#" command can take option "F#" that specifies the feedrate
at which the printing head should be re-positioned. If not
specified the re-positioning move is not preformed immediately,
but the coordinates are adjusted for the printer to properly
position the head when the next movement happens.
2013-02-04 23:05:45 -05:00
Denis B 49b2ddc8c1 Cleaned up non-standard characters 2013-02-04 01:41:40 -05:00
Bernhard Kubicek f8876a7958 Merge pull request #376 from kintel/skip_longfilenames
Also skip .files and _files with long filenames. I think its better than before. If somebody dislikes it, or wants additional configuration, it can be done in a future step. Thanks, Marius, and nice to have you helping!
2013-02-03 03:05:31 -08:00
daid 18fcc367d2 Merge pull request #371 from Banjer/Melzi_LED_PIN
Chenged LED_PIN for Melzi boards, added comment about broken versions of...
2013-02-02 03:23:43 -08:00
daid 6b78edf7c5 Merge pull request #374 from kintel/quickstop
compile fix: quickStop() needs stepper.h
2013-02-01 13:54:12 -08:00
Bas Spaans 19ce90fe02 Added comment about M42 usage (clean) 2013-01-31 18:20:23 +01:00
Bas Spaans 00fed0a703 Revert "Extended comment explaining M42 usage"
This reverts commit 01541ee64c.
2013-01-31 18:11:13 +01:00
Marius Kintel e06d820909 Also skip .files and _files with long filenames 2013-01-31 12:07:42 -05:00
Bas Spaans 01541ee64c Extended comment explaining M42 usage 2013-01-31 18:00:25 +01:00
Marius Kintel f24f02e212 compile fix: quickStop() needs stepper.h 2013-01-31 10:43:03 -05:00
Bas Spaans 12c41423ad Fixed typo in comment 2013-01-30 22:54:04 +01:00
Bas Spaans 0995eaa492 Chenged LED_PIN for Melzi boards, added comment about broken versions of the Sanguino libraries 2013-01-30 22:25:01 +01:00
Bernhard 1d06b10962 Added a feature to have filament change by gcode or display trigger.
[default off for now]
syntax: M600  X[pos] Y[pos] Z[relative lift] E[initial retract] L[later retract distance for removal]

if enabled, after a M600, the printer will retract by E, lift by Z, move to XY, retract even more filament.
Oh, and it will display "remove filament" and beep like crazy.

You are then supposed to insert a new filament (other color, e.g.) and click the display to continue.
After having the nozzle cleaned manually, aided by the disabled e-steppers.
After clicking, the printer will then go back the whole shebang, and continue printing with a fancy new color.
2013-01-27 13:21:34 +01:00
daid303 408b349a84 Fixed #368. Commented out the wrong pin definition, but explained why it is there. 2013-01-21 15:46:17 +01:00
daid 236bb2c110 Merge pull request #365 from DanieleSdei/Marlin_v1
Marlin v1, italian MSG_RESUMING and RepRapPro thermistor tables.
2013-01-14 08:29:55 -08:00
Daniele Sdei 9ecb267b63 Merge remote-tracking branch 'upstream/Marlin_v1' into Marlin_v1 2013-01-14 15:47:40 +01:00
Daniele Sdei 3cf59f6f9a add RepRapPro Huxley thermistor tables 2013-01-14 15:36:08 +01:00
daid c1730e2b08 Merge pull request #363 from yuroller/sanguino_panelolu
Panelolu pin assignment for sanguinololu
2013-01-10 07:19:37 -08:00
Yuri Valentini 86358dd6cd Panelolu pin assignment for sanguinololu from http://reprap.org/wiki/Panelolu 2013-01-10 12:23:20 +01:00
daid303 0f3f5d083d Minor cleanup of the new FAN_KICKSTART code. #334 2013-01-10 11:08:45 +01:00
daid 6ec56fa923 Merge pull request #334 from KevinOConnor/FanKick
Add feature to briefly run the cooling fan at full speed when it first starts.
2013-01-09 02:47:59 -08:00
daid 965baf2683 Merge pull request #362 from daid/Marlin_v1
Finnish language
2013-01-09 02:42:09 -08:00
daid 4fde836d83 Merge pull request #8 from randomev/Marlin_v1
+ Finnish translation
2013-01-09 02:39:43 -08:00
Kevin O'Connor 3d91bd486c Add "kick fan" feature - briefly run fan at full speed on start.
Add a feature to run the cooling fan at full speed for a small period
(default 100ms) when first starting the fan.  Some fans wont reliably
start spinning at low power, and many fans have issue with the PWM at
low power.  However, once the fan starts spinning it can reliably be
set to a wide range of PWM values.
2013-01-08 18:50:15 -05:00
Kevin O'Connor 3f2f94ef28 Be consistent in setting of the fan PWM.
Always set the FAN PWM value in check_axes_activity() and always use
the value of the active move if a move is active.
2013-01-08 18:49:18 -05:00
Henry Palonen 7f30039d2a + Finnish translation 2013-01-08 19:21:34 +02:00
daid303 14e1d495ef Merge branch 'Marlin_v1' of github.com:ErikZalm/Marlin into Marlin_v1 2013-01-08 17:10:30 +01:00
daid303 bbe7d3d0fe Fixed #312 2013-01-08 17:09:57 +01:00
daid 7ce509b9a7 Merge pull request #361 from yuroller/MakefileSanguino
Makefile sanguino
2013-01-08 06:22:27 -08:00
Yuri Valentini 9c34c4f05b fixes for ramps compilation using installed arduino ide 2013-01-08 12:54:31 +01:00
daid303 442ade15a6 Move Gen6 stuff into a proper location. 2013-01-08 12:31:28 +01:00
daid 5fd4582cc8 Merge pull request #242 from Drakelive/Marlin_v1
Fixes issues # 216 and # 135 for Gen6 and Gen6 Deluxe board
2013-01-08 03:29:20 -08:00
daid303 8b88e3b386 Fixed #345, Fixed #267. 2013-01-08 12:14:55 +01:00
daid 27843388c6 Merge pull request #360 from njprossi/Marlin_v1
Power signal control definitions for other power supplies
2013-01-08 02:58:02 -08:00
daid303 bfa5bb86e4 Merge branch 'Marlin_v1' of github.com:ErikZalm/Marlin into Marlin_v1 2013-01-08 11:54:13 +01:00
daid303 921273baa0 Added optional feature to stop printing when an endstop is hit. Made the Z display on the LCD in 3.2 format instead of 3.1. Added LCD message when and endstop is hit. 2013-01-08 11:53:18 +01:00
Yuri Valentini 7d20ec706e Added libraries from Arduino 1.0.3 for sanguino build 2013-01-07 17:26:50 +01:00
Nicolas Rossi 437eb3bafc Initialize PS_ON at startup 2013-01-07 14:57:51 +01:00
Nicolas Rossi f3c1fc70a9 Power signal control definitions for ATX and others 2013-01-07 14:33:30 +01:00
Yuri Valentini dad7691df9 makefile for sanguino standalone compilation 2013-01-07 11:08:10 +01:00
daid 3a1cd30ce1 Merge pull request #358 from yuroller/sanguino_spi
Definitions for Sanguino SPI
2013-01-04 11:53:10 -08:00
Yuri Valentini 69582042d7 Definitions for Sanguino SPI 2013-01-04 18:32:08 +01:00
Daniele Sdei 5f82f03ff3 Add italian MSG_RESUMING. 2012-12-28 11:44:35 +01:00
daid303 5e3873c8db Add german MSG_RESUMING. 2012-12-25 20:53:11 +01:00
daid303 01aac2a142 Small changes on the LCD panel, let the speed control work better, line up the parameter edit the same as the menu, remove some unused defines, and remove the Z from the 10mm move menu. 2012-12-21 16:14:47 +01:00
daid303 b69cb9fbd9 Change the end of SD cart print message from minutes/seconds to hours/minutes. 2012-12-19 12:26:40 +01:00
daid 30254e3388 Merge pull request #350 from jcrocholl/Marlin_v1
Automatically set *_MIN_PIN and *_MAX_PIN according to *_HOME_DIR.
2012-12-17 02:16:31 -08:00
daid303 38ee395ac7 Replace the 1ms delay for 2 nops to get a 100ns delay. #259 2012-12-17 11:12:11 +01:00
daid303 5df5e4c4a2 Merge branch 'Marlin_v1' of github.com:ErikZalm/Marlin into Marlin_v1 2012-12-17 11:09:18 +01:00
daid303 a95dcd74e7 Fix some of the duplicated PSTRs, saving 500bytes of flash with LCD on. 2012-12-17 11:09:09 +01:00
daid ab318beaaf Merge pull request #348 from oni303/Marlin_v1
fixed  (#328) pwm generation at pin D12 and D13
2012-12-17 02:08:28 -08:00
Johann Rocholl 8caf5d252d Remove bogus blank line. 2012-12-16 12:50:20 -08:00
Johann Rocholl b39f5d614a For boards with only one endstop per axis, automatically set *_MIN_PIN and *_MAX_PIN according to *_HOME_DIR. 2012-12-16 12:09:53 -08:00
oni303 ab09fa4bbf fixed pwm generation at pin D12 and D13 when one of them is used as FAN_PIN on Sanguino, added soft pwm entry for FAN_PIN in temperature.cpp 2012-12-16 01:36:57 +01:00
daid 83ea7dc5b9 Merge pull request #342 from setar/Marlin_v1
Fix the russian translation.
2012-12-14 05:04:41 -08:00
Sergey Taranenko 5697451c72 fix lcd class 2012-12-14 15:39:47 +04:00
Sergey Taranenko 58e806f3fa Fix the russial translation. 2012-12-14 15:39:26 +04:00
Sergey Taranenko 50a5ce1dc4 deduplicate messages 2012-12-14 15:37:05 +04:00
daid303 6123a00e64 Fix the german translation. 2012-12-14 11:11:02 +01:00
daid303 7c21716886 Fixed #341 2012-12-14 10:53:11 +01:00
daid303 ae1bc83350 Merge branch 'Marlin_v1' of github.com:ErikZalm/Marlin into Marlin_v1 2012-12-13 13:25:22 +01:00
daid303 596a7e1904 Fix compiling for Arduin < 1.0.0 2012-12-13 13:24:55 +01:00
Daid b264317fa0 Reverted the patch by KevinOConnor, as it crashes some versions of avr-gcc and caused linking issues. 2012-12-13 12:19:12 +01:00
Daid 673577a31b Merge branch 'Marlin_v1' of github.com:ErikZalm/Marlin into Marlin_v1 2012-12-13 11:41:34 +01:00
Daid 23022f1a82 Updates to Makefile to compile for Teensy. 2012-12-13 11:41:27 +01:00
daid 96e9db8919 Merge pull request #339 from KevinOConnor/CompilerFlags
Add additional optimization flags to Makefile
2012-12-13 01:30:17 -08:00
daid303 08356361ac Fixing a problem with heated beds not working without PID and BED_LIMIT_SWITCHING 2012-12-13 10:25:29 +01:00
daid303 047d037f8c #ifdef fix for #326 2012-12-13 09:04:41 +01:00
Kevin O'Connor 0908458381 Use gcc "-fwhole-program" optimization.
Use "whole program" and "link time optimization" features of gcc.  The
whole-program optimization enables the compiler to evaluate the entire
firmware for optimization instead of just one code file at a time.
This leads to better overall optimizations.
2012-12-12 23:22:35 -05:00
Kevin O'Connor 16fbb455ef Use linker "--relax" option.
The "relax" option enables the linker to convert certain "call"
instructions to the smaller "rcall" instruction.  This reduces the
size of the resulting binary.
2012-12-12 23:22:31 -05:00
daid303 f30b46b2a8 One more fix for #338, I really should get a heated bed to test with. 2012-12-12 23:06:17 +01:00
daid303 65c3f1ffcd Most likely fixing #338 2012-12-12 21:56:17 +01:00
daid303 7577717b59 Fixed #336 2012-12-12 13:08:26 +01:00
daid303 1a8f54cea1 The big LCD code update. This splits the display and menu implementation. Paving the way for future different displays. It also makes it easier to modify the menu structures while keeping everything consistant. Note that this most likely breaks the translations, which need to be updated. 2012-12-12 11:47:03 +01:00
daid303 6731c094ee Fix compiling with just an 16x2 LCD and no buttons. 2012-12-12 11:32:33 +01:00
daid303 b99a928a80 Fix the M117 (display message on LCD) when used over USB with checksums. 2012-12-12 09:35:32 +01:00
daid303 55ba90ac19 Add PID functional range setting. With high powered heaters the current functional range of 10 degrees causes high overshoots as the PID needs to kick in before the temperature hits 10 degrees below target. 2012-12-12 09:08:37 +01:00
daid303 5ff5cee8ce Fix the sensitive pin definitions, there where analogue numbers in the digital pin list. Also made M42 without a P function on the LED_PIN (which was otherwise a useless pin definition) 2012-12-11 14:53:53 +01:00
daid303 8b58edc70e Merge branch 'Marlin_v1' of github.com:ErikZalm/Marlin into Marlin_v1 2012-12-11 13:38:34 +01:00
daid d0319d45af Merge pull request #335 from jcrocholl/Marlin_v1
Fix endstop pins for Printrboard
2012-12-11 02:59:58 -08:00
Johann Rocholl ca409e5531 Fix X/Y/Z_MIN_PIN for Printrboard. 2012-12-11 01:59:48 -08:00
Johann Rocholl 1f45cb0a51 Fix typo in MANUAL_HOME_POSITION (plural S missing) and improve comments. 2012-12-11 01:54:40 -08:00
daid303 46ec4b648c Added some missing Mxxx comments to M commands. Fixed the unsetting of the timer dividers for the fast PWM fan. 2012-12-11 10:21:44 +01:00
Daid 724f5aa36b Update on makefile for moved Arduino addons. 2012-12-10 12:06:30 +01:00
daid303 6d9dfa96c3 Move the Arduino related stuff out of the Marlin tree, as they are not directly related to Marlin functionality but addons for the Arduino IDE. Also split up the addons for pre 1.0.0 Arduino and post 1.0.0 Arduino. 2012-12-10 12:02:29 +01:00
daid303 3fb07d9b8d Add MINTEMP/MAXTEMP error to LCD, and fix temperature bug with more then 1 extruder. 2012-12-10 10:48:46 +01:00
daid303 82c8724b33 Fix compile with PID_DEBUG 2012-12-09 23:50:12 +01:00
daid303 9b160972a1 Merge branch 'Marlin_v1' of github.com:ErikZalm/Marlin into Marlin_v1 2012-12-09 23:46:42 +01:00
daid303 e036750bdf Use the disable macros on initialization. Which fixes a bug when there is no pin defined for stepper enabled (motherboard 4) 2012-12-09 23:46:25 +01:00
Daid fcd9de72ef Merge branch 'Marlin_v1' of github.com:ErikZalm/Marlin into Marlin_v1 2012-12-09 23:31:07 +01:00
Daid 32d4373e0f Add printrboard and brainwave to Makefile. 2012-12-09 23:30:55 +01:00
daid b3ddbcee2a Merge pull request #329 from jcrocholl/Marlin_v1
Add Printrboard and Brainwave to pins.h and fastio.h
2012-12-09 14:29:26 -08:00
Daid 29435dfb4b Proper avr for Sanguino in Makefile. 2012-12-09 23:02:03 +01:00
daid303 52158dffcc Big temperature code update. No longer converts back and forwards between temperature and raw sample value. Reducing complexity, removing code. Also named some variables better. While keeping the safety intact and functionality the same. 2012-12-09 23:00:06 +01:00
Daid ca7acbe6d9 Allow specification of which arduino hardware subvariant in Makefile. 2012-12-09 19:19:57 +01:00
Johann Rocholl 33247733e0 Teensylu and Printrboard use different analog pins for thermistors. 2012-12-09 02:19:13 -08:00
Johann Rocholl 621c24a10f AT90USB is only defined after pins.h is included. 2012-12-09 01:40:33 -08:00
Johann Rocholl 6cba11f087 Stop redefining MOTHERBOARD and #define AT90USB instead. Also put #ifndef AT90USB around the HardwareSerial_h trick, so now Printrboard / Brainwave support compiles on Arduino 1.0.2 as well. 2012-12-09 01:32:09 -08:00
Johann Rocholl 4d351b4846 Improved formatting and comments for consistency. 2012-12-08 20:15:53 -08:00
Johann Rocholl a30007caa4 If fastio.h is not messed up then Teensylu and Printrboard are actually using the same pins. 2012-12-08 19:46:42 -08:00
Johann Rocholl 6aa87a7b67 Use the same fastio.h definition for AT90USB1286/7 and AT90USB646/7. 2012-12-08 15:16:38 -08:00
Johann Rocholl b1c38d4c82 Avoid compiler warnings (redefined MOTHERBOARD) in Arduino 1.0 and greater. 2012-12-08 11:34:18 -08:00
Johann Rocholl 42e21bb06e Add support for Printrboard (from https://github.com/lincomatic/Marlin) and Brainwave (from https://github.com/metrix/Sprinter). 2012-12-08 10:49:01 -08:00
Johann Rocholl ce4b5bbeaa Add AT90USB646 support from Sprinter to fastio.h. 2012-12-08 10:45:58 -08:00
Daid f413aa33b3 Small makefile change, posibility to add defines on the commandline, and fix compiling with watchdog enabled when using the Makefile. 2012-12-08 11:49:53 +01:00
daid303 587154c01b Fix the WATCHPERIOD implementation. It did not work correctly in a multi extruder setup, it did not work after 32 seconds after startup (int16 used as millies timestamp). And it did not work if you gave an M104 or M109 when the target was already around the target setpoint. So on average, it did not work at all. The new implementation should be robust in detecting a failure to heat up. 2012-12-06 10:36:07 +01:00
daid303 1f27870d41 Fix compiling the watchdog error message when the manual reset watchdog is used. 2012-12-06 10:27:50 +01:00
daid303 c5d4225804 Mistake there, not sure why I did that. My bad. 2012-12-05 20:23:13 +01:00
daid303 529748894c Minor changes in the temperature code for some cleanup. 2012-12-05 19:54:01 +01:00
daid303 4e26ecc940 The Partial release message (which does not really tell you anything) overwrites the final print time on the LCD, which is a real shame. So I removed the message. 2012-12-05 19:32:26 +01:00
daid303 c421774422 The Partial release message (which does not really tell you anything) overwrites the final print time on the LCD, which is a real shame. So I removed the message. 2012-12-05 19:32:02 +01:00
daid303 16078e47d4 Fixed #325 2012-12-04 16:27:21 +01:00
daid303 6a9bee27cc Changed the naming of some LCD functions, so the names match better what the function does. Also moved around some prototypes for general cleanup. 2012-12-03 12:52:00 +01:00
daid303 94ea26ff46 Some minor changes on code style. And a bugfix where the counters for positioning in the stepper where wrong depending on compiler settings. (Caused strange values to reported back with M114 and endstop triggers). Also fixed compiling with FWRETRACT enabled. 2012-12-03 12:13:20 +01:00
daid303 6c51fe5039 Fix the bug where the SD percentage calculation is wrong when the file is larger then 42MB 2012-12-03 11:35:36 +01:00
daid 34b2de4cd8 Merge pull request #320 from brupje/patch-1
Fix for keypad
2012-12-01 01:02:32 -08:00
brupje 57429cb9fe Fix for keypad 2012-11-29 21:42:19 +01:00
daid303 97fa2a9c30 Few simple fixes that save RAM, as static strings are stored in RAM by default. 2012-11-28 10:30:34 +01:00
Daid c94ca24adc Fixed #317 2012-11-24 17:32:30 +01:00
Daid 99e9554edd Some fixes in the Makefile to support Arduino 1.0.0 or higher and added the Rambo. Still needs some more work for the different arduino hardware variants. 2012-11-24 11:46:31 +01:00
Erik vd Zalm dbbf050005 More rambo fixes 2012-11-21 20:53:56 +01:00
Erik vd Zalm f934d0ef5b Merge remote-tracking branch 'tonokip/Marlin_v1' into Marlin_v1
Conflicts:
	Marlin/Configuration.h
2012-11-21 20:36:30 +01:00
Erik vd Zalm e48dfcc2b3 Tmp copy before merge 2012-11-21 20:29:31 +01:00
Erik vd Zalm b98fb17fe9 Small FREQUENCY_LIMIT changes 2012-11-21 20:17:44 +01:00
daid bce67ec2c9 Merge pull request #312 from gege2b/Marlin_v1
Added french translation
2012-11-18 13:43:07 -08:00
Gege 9b1d2483a0 I hope last changes to french translation 2012-11-18 22:34:56 +01:00
Gege b1adc567da Correction to french translation (non-ASCII chars only) 2012-11-18 20:00:41 +01:00
Gege 0807d82af0 Correction to french translation (plain text only) 2012-11-18 19:39:56 +01:00
Erik vd Zalm 5cd7a90b32 Added new temperature lookup table creation tool. This one uses stein hart-hart equations.
You need 3 temperature resistance:combinations. This gives a better result then using beta.
2012-11-16 23:51:05 +01:00
gege2b bb119739b0 Added french translation 2012-11-16 18:38:50 +01:00
daid df8dd5ac21 Merge pull request #306 from nothinman/Marlin_v1
Added automatic build numbering.
2012-11-14 01:59:33 -08:00
daid b7c8e5bbcf Merge pull request #308 from MStohn/Marlin_v1
FIX: Allow marlin internal 0°C represenation
2012-11-13 05:53:58 -08:00
MaikStohn 2b7b1e52b1 allow marlin internal 0°C represenation 2012-11-13 14:37:08 +01:00
Martin Lukasik 2f771b3979 Added automatic build numbering. 2012-11-12 21:06:59 +00:00
daid 9bebe9b631 Merge pull request #302 from nothinman/Marlin_v1
Added Polish translation. Cosmetic changes to English.
2012-11-12 12:13:30 -08:00
daid303 a2032afa3a Fixed #303 2012-11-12 21:04:07 +01:00
Martin Lukasik 6a55ca8370 Added Polish translation. Cosmetic changes to English. 2012-11-12 15:54:07 +00:00
daid303 8f20562f49 Fix some of the crowded code style. And fixed the conditional. #300 2012-11-12 15:49:40 +01:00
daid303 43018a48c4 Fix for a few -Wextra warnings. 2012-11-12 15:35:28 +01:00
daid303 72586eb30a Solved few warnings. 2012-11-12 09:29:12 +01:00
daid303 7a02ba361c Header multiple include protection should match the filename, not just _ARDUINO_H, which is almost bound to go wrong some day. 2012-11-12 09:24:28 +01:00
daid303 f4a89ec776 SDCARDINSERTED is always defined, and thus we do not need the #ifdefs. 2012-11-12 09:16:27 +01:00
daid303 57834776ad Made the 2nd speed lookup table condition more explicit. 2012-11-11 12:02:48 +01:00
Daid caa2b25b40 Fix Gen7 compile if you have avr-libc version 1.7.1 or higher. See http://code.google.com/p/arduino/issues/detail?id=604 2012-11-11 11:17:54 +01:00
daid303 a27fef8750 Store the pre-heat constants outside of the ULTIPANEL define, so we can use them when storing EEPROM in a build without the ULTIPANEL. 2012-11-11 11:06:58 +01:00
daid303 789be03b4f Update on makefile, should make it easier to compile for different boards without changing the makefile. (Still missing Arduino 1.x.x support). 2012-11-11 11:05:52 +01:00
daid303 40ce057a3e Fixing issue #297 2012-11-10 14:37:01 +01:00
daid303 625ac81acc Yes, makes sense, lets NOT use the value directly from the configuration define but modify it before setting it. This will not confuse people (including me) at all! 2012-11-09 22:36:31 +01:00
daid303 ffc69537aa Update on some comments, make the MOTHERBOARD list complete again. 2012-11-09 09:10:51 +01:00
daid303 71efcfc648 Most likely fixing issue #295. 2012-11-08 21:08:05 +01:00
daid303 04be9d6001 God damn. Sorry, my mistake, forgot to add this file. 2012-11-07 23:16:43 +01:00
daid303 c17da4b707 Add ConfigurationStore to the Makefile. 2012-11-07 22:43:01 +01:00
daid ccd9fd0dc3 Merge pull request #292 from jothan/lcdfix
Lcd fixes
2012-11-07 13:10:59 -08:00
Jonathan Bastien-Filiatrault 46b9988e26 Search and replace failure. 2012-11-07 16:09:30 -05:00
Jonathan Bastien-Filiatrault 0f73afb0b0 Avoid defining overriding definitions for the RepRapDiscount Smart
Controller. Remove common definitions. Harmonize declaration order.
2012-11-07 16:04:28 -05:00
Jonathan Bastien-Filiatrault 36b452c7ac Remove abbrs. 2012-11-07 15:42:18 -05:00
daid a394ac9f95 Merge pull request #294 from YanFM/patch-1
Update Marlin/language.h
2012-11-07 06:21:28 -08:00
YanFM 332344bd43 Update Marlin/language.h
Included Portuguese language
2012-11-07 09:43:13 -02:00
daid303 e6c1cadea0 Set the watchdog to a 4 second timeout, as with 1 second it can timeout during SD card init. 2012-11-07 12:32:17 +01:00
daid faea7d72b8 Merge pull request #290 from buildrob/Marlin_v1
Clean up special serial port cases
2012-11-07 02:00:26 -08:00
daid303 12a4d60e18 Fix the EEPROM storage, no longer inline it at multiple locations, and remove the template. 2012-11-07 10:02:45 +01:00
Robert F-C 08337e01f7 Added change to feature list. 2012-11-07 17:28:46 +11:00
Jonathan Bastien-Filiatrault 9606f4d04f Include Marlin_main.cpp in source files. 2012-11-06 20:32:48 -05:00
Jonathan Bastien-Filiatrault 3cbaad9288 RepRapDiscount Smart Controller pin definitions. 2012-11-06 20:32:13 -05:00
Robert F-C 99692dc99e Clean up special serial port cases
Assume SERIAL_PORT 0 if not defined. Collapse un-numbered register
special case. Clarify comments.
2012-11-07 09:00:21 +11:00
daid303 5a998558a9 Update suggested by Robert F-C. #289 2012-11-06 21:04:29 +01:00
daid303 f6ff0ab767 signed/unsigned fixes. 2012-11-06 15:33:49 +01:00
daid303 5d471e0f34 Also reset the PID values to defaults. Fixes #281 2012-11-06 15:21:00 +01:00
daid303 d3ebc34958 Hopefully also support chips with a single UART in MarlinSerial now. 2012-11-06 14:43:36 +01:00
daid303 b6ff45254e Better explain the watchdog "problem" and rename the config define so it explains that the feature belongs to the watchdog. 2012-11-06 13:33:00 +01:00
daid303 7e348fcb5f By mistake enabled the watchdog by default. This should be off by default. 2012-11-06 13:20:08 +01:00
daid303 06b58a9c4f First cleanup. Moved all code to cpp files, so there are no dependencies on pde files. And no more odd requirement to cat files together. (Still need to fix the Makefile). Also cleaned up some defines and made defines upper case as by C coding conventions. 2012-11-06 12:06:41 +01:00
daid 539f3b3fe4 Merge pull request #284 from brackendawson/Marlin_v1
Use the right pins for Gen7 1.4
2012-11-06 01:06:24 -08:00
daid 2f20df3f55 Merge pull request #289 from buildrob/Marlin_v1
Marlin v1 configurable serial port
2012-11-06 01:00:50 -08:00
Robert F-C 65c9a0728f Set default serial port back to 0. 2012-11-05 22:15:07 +11:00
Robert F-C ab9d183024 Make serial port configurable.
This change makes the choice of serial port configurable so that
wireless capability can be easily added by connecting Bluetooth modules
(such as BlueSmirf or JY-MCU) to the expansion port pins.
2012-11-05 21:34:27 +11:00
Bracken Dawson f5631a89e8 Add dummy Emergancy Pin to Gen7 1.4
Change required after pulling from ErikZalm.
2012-10-26 22:28:37 +01:00
Bracken Dawson a4f9e1ebf2 Merge git://github.com/ErikZalm/Marlin into Marlin_v1 2012-10-26 22:20:35 +01:00
Bracken Dawson 2873d67b17 Put bogus temp override back in Gen7 up to 1.3
Took out the ifdef when I split 1.4 out and forgot to permanently
define it for <=1.3.
2012-10-26 22:17:26 +01:00
ErikZalm a7e40b2903 Merge pull request #276 from setar/Marlin_v1
Fix num of digits on LCD for E and Z axis.
2012-10-23 09:48:55 -07:00
ErikZalm 23b0f8ed4b Merge pull request #279 from MaikStohn/Marlin_v1
Fixed wrong code (will not even compile when EXTRUDERS>2)
2012-10-23 09:48:02 -07:00
MaikStohn 6ed02c86be Fixed wrong code (will not even compile when EXTRUDERS>2) 2012-10-23 18:08:43 +02:00
Sergey Taranenko 2a67363e27 Fix ‘prog_uchar’ definition in LiquidCrystalRus.cpp 2012-10-22 11:05:17 +04:00
Sergey Taranenko 205304ddee Merge git://github.com/ErikZalm/Marlin into Marlin_v1 2012-10-22 10:59:27 +04:00
Erik vd Zalm 58bca87c72 fix LCD temp bed artifacts on power up ' B022/0.) -> B022/000 ' 2012-10-21 14:40:06 +02:00
Erik vd Zalm febeb43197 Revert "fix LCD temp bed artifacts on power up ' B022/0.) -> B022/000 '"
This reverts commit cb02c2f9d8.
2012-10-21 14:36:31 +02:00
Sergey Taranenko 8178dec4c3 Fix num of digits on LCD for E and Z axis.
The number of steps per mm often contains 4 digits before the decimal point and does not require precision greater than 0.1
2012-10-18 17:45:40 +04:00
ErikZalm 70f57a6844 Merge pull request #273 from setar/Marlin_v1
fix LCD temp bed artifacts on power up ' B022/0.) -> B022/000 '
2012-10-17 04:10:18 -07:00
ErikZalm ff14199e58 Merge pull request #270 from jothan/Marlin_v1
Create an explicit rule for building applet/Marlin.cpp.
2012-10-17 04:09:36 -07:00
ErikZalm bfdf0932c1 Merge pull request #274 from DanieleSdei/Marlin_v1
Italian language support
2012-10-17 04:09:13 -07:00
Daniele Sdei 695938ba3f Italian language support 2012-10-17 12:48:26 +02:00
Sergey Taranenko cb02c2f9d8 fix LCD temp bed artifacts on power up ' B022/0.) -> B022/000 ' 2012-10-17 10:49:05 +04:00
Jonathan Bastien-Filiatrault e4a5e333ef Generalize. 2012-10-15 21:34:33 -04:00
Jonathan Bastien-Filiatrault e10d3136c8 Create an explicit rule for building applet/Marlin.cpp.
It would seem that the pattern matches do not work when the source
file is created when make is running. The result of this is that it is
necessary to run "make" twice to build the firmware.

This adds an explicit rule without a pattern match for building
applet/Marlin.cpp it corrects the make behaviour at the cost of adding
a little redundancy in the Makefile.
2012-10-15 21:16:25 -04:00
ErikZalm 9f089756b7 Merge pull request #265 from setar/Marlin_v1
Added Russian translation
2012-10-14 14:11:58 -07:00
ErikZalm 654387297f Merge pull request #268 from brupje/Marlin_v1
Marlin v1
2012-10-14 08:55:01 -07:00
brupje 326423719f Add support for Megatronics 2012-10-14 14:05:57 +03:00
brupje d07b6e93d5 Add support for Megatronics 2012-10-14 14:05:12 +03:00
Sergey Taranenko efcc28d347 Fix check for include LiquidCrystalRus.h 2012-10-13 00:29:34 +04:00
Sergey Taranenko cfc193cdac Enables support the Cyrillic alphabet for LCD 2012-10-12 19:06:43 +04:00
Sergey Taranenko 24bcc9647d Added Russian translation 2012-10-12 18:33:05 +04:00
ErikZalm bc27d809fb Merge pull request #262 from markfinn/bedpid-clean3
Remove unwanted artifacts in merge of bed-pid tree
2012-10-09 13:18:58 -07:00
Mark Finn bf7e453d02 Unwanted artifacts from unclean merge of bed-pid tree 2012-10-09 14:47:35 -05:00
ErikZalm 36a746d7d5 Merge pull request #244 from markfinn/pidbed
PID for heated bed
2012-10-08 11:15:16 -07:00
tonokip ca811156a0 Merge pull request #1 from johnnyr/patch-1
fix max endstop pins
2012-10-01 23:55:08 -07:00
ErikZalm 50daf27e5a Merge pull request #255 from elgambitero/Marlin_v1
Spanish language updated
2012-09-26 10:29:03 -07:00
elgambitero df09e2adce Spanish updated 2012-09-26 19:14:07 +02:00
elgambitero ddf6603d81 Spanish language updated. Bug fixes on dialogs. 2012-09-26 19:11:45 +02:00
elgambitero 4bf8b1aeee fesfas 2012-09-26 19:05:31 +02:00
drakelive be1e099f1b Union whit Erick version 2012-09-25 19:17:15 +02:00
elgambitero 7afd202b89 New dialogs translated to spanish. Bug fixes.
Dialogs from M119 translated, and "Set Preheat" dialogs adapted to the
screen size.
2012-09-25 19:16:57 +02:00
elgambitero ebc4601185 Some new dialogs translated to Spanish 2012-09-25 19:08:44 +02:00
drakelive c8ea9b0e58 Merge branch 'Marlin_v1' of https://github.com/Drakelive/Marlin 2012-09-25 18:51:20 +02:00
drakelive ca7ca4572e primo commit 2012-09-25 18:46:38 +02:00
ErikZalm c0aad4c28a Merge pull request #254 from ZetaPhoenix/Marlin_v1_bugfix
Changes to M119 response for easier visual comparison
2012-09-25 00:10:38 -07:00
johnnyr 8016f058bc fix max endstop pins 2012-09-19 13:15:17 -05:00
Mark Finn d197f8504b clean up and changes from testing 2012-09-17 19:18:50 -05:00
Mark Finn eb06a886c4 missed 2012-09-17 14:23:49 -05:00
Mark Finn 04631d2250 cleanup for pull 2012-09-17 14:17:24 -05:00
Mark Finn 0a5ad3ab85 move comment to correct place 2012-09-17 08:42:35 -05:00
ZetaPhoenix 8ac5b29e02 Changes to M119 response for easier visual comparison
Changed to report on individual lines with "TRIGGERED" or "open" instead of "H" or "L" on one line as H&L could be confused with logic levels High and Low which may be wrong if using inverted logic.  Added strings to language.h.

Fixed typo "deu" in English language that was fixed in #134 but got added back in via 9f7f7354f5
2012-09-16 14:51:24 -07:00
ErikZalm 0a31ccb1d1 Merge pull request #251 from ZetaPhoenix/Marlin_v1_bugfix
Limit Switch locations based on MIN/MAX limits and homing direction
2012-09-16 01:47:51 -07:00
ZetaPhoenix c6caa45ae2 Limit Switch locations based on MIN/MAX limits and homing direction
fixes #246
Added statements to set the limit switch positions to the maximum travel if homing in the positive direction as well as bed center at (0,0) if defined.
Relocated code based on feedback.
2012-09-15 15:25:49 -07:00
ZetaPhoenix dc566d654f fixes #246
Added statements to set the limit switch positions to the maximum travel if homing in the positive direction as well as bed center at (0,0) if defined.
2012-09-14 21:48:49 -07:00
ErikZalm ba898faa7d Merge pull request #249 from gwelchc/patch-2
Slight modification for byte savings
2012-09-14 12:13:36 -07:00
ErikZalm 0152ee71a5 Merge pull request #248 from gwelchc/patch-1
Binary representation for characters in ultraldc.pde
2012-09-14 12:10:28 -07:00
ErikZalm 348d543425 Merge pull request #245 from andrey-vasilyev/patch-1
Fix M81 not working reliably on Gen7
2012-09-14 12:04:57 -07:00
G. W. C. 6ccbfeb80c Update Marlin/Marlin.pde
Added function 'setTargetedHotend' that turns into a function an operation repeated 3 times through the M-codes processing.

This modification saves a few bytes that can be used to add support for new commands.
2012-09-14 16:38:54 +03:00
G. W. C. c433142abf Update Marlin/ultralcd.pde
The joris' char drawins are expressed in binary so to show their content's in a more visual fashion.

This is not a code modification as much as a readibility modification.
2012-09-14 16:29:43 +03:00
andrey-vasilyev 1d389ad3a8 Fix M81 not working reliably on Gen7
Some discussion of the issue is here http://forums.reprap.org/read.php?181,118329,page=1
2012-09-13 19:23:48 +04:00
Mark Finn 5bfccab650 readme 2012-09-12 21:52:16 -05:00
Mark Finn 9698f4ea64 bed pid
Conflicts:

	Marlin/Configuration.h
2012-09-12 21:18:59 -05:00
ErikZalm 769796ed4c Merge pull request #240 from ZetaPhoenix/Marlin_v1_bugfix
Missing #else in temperature.cpp prevented reading bed temp when TEMP_BE...
2012-09-11 02:10:39 -07:00
drakelive e5c39b7c2a commit 2012-09-10 14:25:49 +02:00
ZetaPhoenix e8c92e0a95 Missing #else in temperature.cpp prevented reading bed temp when TEMP_BED_PIN <7. Thanks to Leland Wallace for helping me track this down via "Sesame Street" coding (what is not like the other) 2012-09-09 16:06:02 -07:00
drake bf2071871c Merge branch 'Marlin_v1' of https://github.com/Drakelive/Marlin 2012-09-08 23:08:34 +02:00
drake fc32e20881 first commit 2012-09-08 22:26:23 +02:00
Erik vd Zalm abf0693e8e Added KILL_PIN -1 to gen7 boards 2012-09-04 08:20:27 +02:00
Erik vd Zalm 47319cf64e Fixed typo in SF arc fix code. 2012-09-03 21:28:31 +02:00
Erik vd Zalm e358a2d7af Added fix for SF Arc Point fillet procedure 2012-09-02 01:12:49 +02:00
ErikZalm 044a64a1fb Merge pull request #225 from Justblair/Marlin_v1
Added PDF file containing Menu Tree for documentation purposes.
2012-09-01 04:41:49 -07:00
ErikZalm cd91e0e3e1 Merge pull request #228 from Drakelive/patch-1
Update Marlin/pins.h
2012-08-30 13:39:37 -07:00
Drakelive d728e35658 Update Marlin/pins.h 2012-08-30 23:36:49 +03:00
tonokip 1c1fddc7ac Added support for the Rambo reprap electronics board. Added Mcodes to set
motor current and microstepping pins.
2012-08-30 00:16:57 -07:00
Blair Thompson dcd3e8a211 Tidy up 2012-08-29 22:53:41 +01:00
Blair Thompson ddd9d0cfd4 Added PDF file containing Menu Tree for documentation purposes. Source xlsx document included. 2012-08-29 21:08:41 +01:00
Erik vd Zalm 0e58ef6805 Some dialogs are corrected 2012-08-29 21:15:59 +02:00
Erik vd Zalm 0e89022cc3 Correct temptable_55 name. 2012-08-28 19:47:22 +02:00
Bracken Dawson 47d4f55bc0 Fix Gen7 1.4 pinout
Gen7 1.4 uses very different pin assignments, might as well make a new
section and remove some of the conditionals from each. It's easier to change
your pin assingment this way if like me you don't wire it exactly to plan.
2012-08-22 23:15:46 +01:00
elgambitero 6cd150842f Update Marlin/language.h
Some dialogs corrected and Default language set to 1
2012-08-22 21:46:22 +03:00
elgambitero 299c18596f Update Marlin/language.h
Some dialogs are corrected
2012-08-22 21:44:57 +03:00
ErikZalm b86336c3f5 Merge pull request #221 from daid/Marlin_v1
Long filename support for LCD display
2012-08-22 06:30:35 -07:00
daid b69e75c89a Added long filename support. 2012-08-22 14:49:57 +02:00
ErikZalm 825adbd67b Merge pull request #220 from MaikStohn/1d224cc031
Implemented support for KILL_PIN / Fixed compilation errors for incomplete/bad translations
2012-08-22 04:33:28 -07:00
stohn 1d224cc031 merged with upstream and FIXED AGAIN bad translation commit
PLEASE BE MORE CAREFUL WHEN SUBMITTING NEW TRANSLATIONS

When you add new menu items / messages always copy them to ALL
languages (just use english)
2012-08-22 13:05:42 +02:00
stohn 06c03fe2f0 new method for message for making KILLED message visible
The cli(); at the start of the kill() function also stops the internal
arduino timer which stops updating of millis() which prevents the
display of the "KILLED." message.
The new function updates the display directly without checking any
timers.
2012-08-22 12:44:41 +02:00
daid 87ff61a8a6 Fix for #201 2012-08-22 10:54:55 +02:00
ErikZalm 8c94ad0d26 Merge pull request #219 from Justblair/Marlin_v1
Added new function to the LCD menu.  Preheat settings now adjustable and can be stored
2012-08-21 23:21:11 -07:00
Blair Thompson aacbebbebe Added Menu Options to the Main-> Control->Temperature Submenu that allow the user to set new values for the ABS and PLA preheat function. EEPROM updated so that these settings can also be committed to EEPROM memory. 2012-08-21 23:46:10 +01:00
stohn 31873ec707 changed int to long to overcome overflow of number display
- related bug reports: Issue #201, Issue #213
2012-08-21 16:47:39 +02:00
stohn de0448343f added KILL_PIN support / cleaned up manage_inactivity function definition 2012-08-21 14:48:29 +02:00
stohn 69961dbba3 fixed incorrect menu messages from last commit...
- removed several multiple definitions of same message
- fixed definition of missing messages in german and spanish
- tweaked german translation (a lot)
- added note about changing and testing this file
2012-08-21 14:44:20 +02:00
ErikZalm f67feea093 Merge pull request #217 from Justblair/Marlin_v1
Fixed broken Language file and pre-heat ABS and PLA options
2012-08-20 14:34:32 -07:00
Blair Thompson 6c050b8440 Fixes error introduced at commit aee475aa55 which caused the sketch not to comile for language option 1. Several defines were removed but still referenced in ultralcd.pde 2012-08-20 21:54:47 +01:00
Blair Thompson b9f9f8f7d3 The pre-heat ABS and PLA options in the LCD Menu were broken a while back. The pre-heat worked fine, but the cooling fans were not switching on as intended. This is now fixed. 2012-08-20 21:49:37 +01:00
elgambitero d38b96fff1 Update Marlin/language.h 2012-08-12 22:45:11 +03:00
Erik vd Zalm 9f7f7354f5 Set default language 1 2012-08-12 21:29:42 +02:00
ErikZalm d3b8edb6a2 Merge pull request #212 from elgambitero/Marlin_v1
Spanish language included in the language.h file
2012-08-12 12:27:06 -07:00
elgambitero aee475aa55 Update Marlin/language.h
Spanish language included. It features the LCD screen messages and a small part of the Serial messages.
2012-08-12 21:26:17 +03:00
Erik vd Zalm 9083966c22 Do not use feedrate multiiply on Z and E only moves. 2012-08-12 18:13:34 +02:00
Erik vd Zalm 5406c533db Disable FAST_PWM by default. On some systems it does not work ok. 2012-08-11 15:51:04 +02:00
Erik vd Zalm f92dc91c3d Enable M503 also when eeprom is disabled 2012-08-11 15:49:40 +02:00
James Adams 35a1dd081f no message 2012-08-11 15:33:35 +02:00
James Adams 5131ab19ca Fixed Retract in LCD Menu 2012-08-11 15:29:40 +02:00
James Adams 96f4f90cb3 Added pause and retract lcd menu items 2012-08-11 15:29:33 +02:00
James Adams e10355500d Updated Language.h with pause, resume, and retract 2012-08-11 15:29:26 +02:00
ErikZalm a97c006bbf Merge pull request #195 from kobaan/Marlin_v1
Updated german translations in language.h
2012-08-11 01:45:30 -07:00
ErikZalm f062794a0d Merge pull request #208 from Enchiridion/Marlin_v1
Added support for dual Z axis stepper drivers
2012-08-11 01:42:49 -07:00
ErikZalm 57468d3c21 Merge pull request #210 from Dabble63/Marlin_v1
Add Duty Cycling to the Heater Bed
2012-08-11 01:42:02 -07:00
ErikZalm 22aae62ccd Merge pull request #209 from ijackson/for-upstream
M206 fixes, and ancillary improvements
2012-08-11 01:40:50 -07:00
Dabble63 6b45e9f167 Add Duty Cycling to the Heater Bed 2012-08-11 09:17:47 +03:00
Ian Jackson adee81170d M206: save values in eeprom
Really, we should have a way to adjust the XYZ homing of a machine in
the eeprom.  So as the second stage of this, make the M206 home offset
parameters subject to the M500/M501/M502/M503 eeprom commands.

Bump the eeprom version to "V06".

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2012-08-11 01:43:00 +01:00
Ian Jackson 1dba212e18 HOMEAXIS: make into a function
Replace the large macro HOMEAXIS with a function.  This avoids the
compiler generating three copies of largely identical code.  The
saving is 724 bytes of program memory.

We make use of XYZ_CONSTS_FROM_CONFIG to provide convenient
array-shaped access to MAX_LENGTH, HOME_RETRACT_MM and HOME_DIR.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2012-08-11 01:43:00 +01:00
Ian Jackson 7bb326d389 eeprom: provide smaller code for SERIAL_ECHOPAIR
SERIAL_ECHOPAIR implies, eventually, two calls to MYSERIAL.print.  One
of these has FORCE_INLINE for a per-character loop, and both involve
constructing a method call rather than a simple function call.

Produce better and smaller code by providing three specialised
functions serial_echopair.  This saves 672 bytes of program memory
(with EEPROM_SETTINGS and SDSUPPORT enabled).

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2012-08-11 01:42:59 +01:00
Ian Jackson 957e966d2d M206: always use homing ("homeing") offsets
Previously the parameters set in M206 would only be used if a G82
command was sent with specific axis home values.  This limits its
usefulness.

Really, we should have a way to adjust the XYZ homing of a machine in
the eeprom.  So as the first stage of this, make M206 affect every
home command.  The values set using M206 are now added to the
configuration variables [XYZ]_HOME_POS.

This is achieved by replacing all uses of [XYZ]_HOME_POS in the code
by a new home_pos[] which includes the adjustment.  We also have to
adjust the uses of [XYZ]_{MIN,MAX}_POS similarly - see below.


To allow axis_is_at_home to be written as a function taking an axis
index rather than a macro taking an axis letter, we provide
constant arrays in program memory containing the values of
[XYZ]_{MIN,MAX,HOME}_POS from the compiled-in configuration.

This is done with some helper macros to deal with the declaration
(XYZ_CONSTS_FROM_CONFIG) and definition of the inline function which
does the program memory access.

We also introduce the overloaded function read_pgm_any, whose
instances are produced with DEFINE_PGM_READ_ANY, which allows the
access functions to automatically produce the correct type.

The type- and pointer-massaging code in the access function boils
down, when compiled, to a simple program memory access.


A question arises: if the M206 offset is set, should this adjustment
to the home position shift or change the possible range of movement
permitted by the software endstops ?

The documentation in Configuration.h describes these limits as:
    // Travel limits after homing
Since this is a file containing physical limits, and actual suggested
values for these configuration parameters appear to include a certain
amount of slop, I've taken the view that these should be regarded as
nominal physical distances from the limit switches, and that the
permissible travel should be unaffected by M206.

So for example with the (rather unrealistic)
  #define X_HOME_DIR -1
  #define X_MIN_POS -20
  #define X_HOME_POS 0
  #define X_MAX_POS 100
no matter the setting of M206 X, the machine would be permitted
to move from 20mm "beyond" the limit switch trigger point in
the negative X direction and 100mm away from the limit switch in
the positive X direction, for a total travel of 120mm.

With M206 X-10 that would be considered to correspond to X coordinates
-30 to +90.  With M206 X+10 that would be considered to correspond to
X coordinates -10 to +110.


fixes #200 (in ErikZalm/Marlin).

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2012-08-11 01:35:03 +01:00
Ian Jackson faccb35850 software_endstops: use *_MIN_POS and *_MAX_POS for arcs
If [XYZ]_HOME_POS and [XYZ]_MIN_POS aren't 0, these corrections are
wrong.  Use the same logic as in Marlin.pde:prepare_move: ie, clamp to
[XYZ]_{MIN,MAX}_POS.

While we're here, put this cut-and-paste code in a function
clamp_to_software_endstops.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2012-08-10 19:36:30 +01:00
Ian Jackson 3f15b7c7b8 Makefile: Better display of size (device memory usage)
Run avr-size with the --mcu=... -C option as well.  That reports how
much actual device program and data memory is used along with a
percentage fullness.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2012-08-10 19:36:30 +01:00
Ian Jackson 0c35facc94 Makefile: support V=1
Often it can be useful to see the actual commands being run by make.
Other projects (eg, the Linux kernel) support this with a "V=1" make
parameter.  Do the same here.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2012-08-10 19:36:29 +01:00
Ian Jackson 71404eef29 .gitignore: Add *~, *.orig, *.rej, move to root directory
Move the .gitignore out of the Marlin subdirectory so it applies to
the whole tree, and add some missing patterns.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2012-08-10 19:36:29 +01:00
Ian Jackson a873541ef6 Marlin.pde: include comment for emacs mode
Emacs by default doesn't recognise a ".pde" file as C++ source code.
Add the annotation to the top of the file to make it work.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2012-08-10 19:36:29 +01:00
Enchiridion 50cde90324 Added support for dual Z axis stepper drivers 2012-08-04 00:32:26 -06:00
kobaan 603a5e25b3 Updated german translations in language.h and eliminated a few double lines. 2012-07-16 14:26:28 +03:00
Chris Palmer 538189cc19 Fixed soft limits when the origin is in the middle.
HOME_POS is now always where the endstop is and can be outside the limits.
The limits are now defined by MIN_POS and MAX_POS rather than HOME_POS and MAX_LENGTH.
The Z is axis now homed first if direction is away from the bed.

Saguinololu limit pins change from MIN to MAX according to the homing direction.
2012-07-14 22:24:26 +02:00
ErikZalm 686011a548 Fixed typo 2012-07-14 17:25:35 +03:00
Erik van der Zalm cd57bf305b Merge git://github.com/daid/Marlin into Marlin_v1
Added invert step pins to corexy code
2012-07-14 15:07:14 +02:00
Erik van der Zalm ea2c19f978 Added CoreXY support (Thanks Ilan Moyer) 2012-07-14 14:21:53 +02:00
Erik van der Zalm aa65fe22ed decoupled axes sucessfully at least on pure x or y jog 2012-07-14 13:43:19 +02:00
daid 12de8fff81 Support step motor controllers with active low step pins. 2012-06-29 16:27:47 +02:00
Erik van der Zalm b67dacdc8f Fixed AD595 define 2012-06-11 17:33:42 +02:00
Bernhard d3002ef741 corrected retract 2012-06-03 16:56:40 +02:00
Bernhard 0c123950e9 __ header file replace 2012-06-02 20:44:17 +02:00
Bernhard bf077125b9 added firmware retract. disabled by default 2012-06-02 20:32:28 +02:00
Bernhard 88d2a671cc readme corrected 2012-06-02 14:14:36 +02:00
Bernhard 0e5e249ab5 added individual pullup setting option to have finer control in case there is a special z-min sensor, for example 2012-06-02 13:47:50 +02:00
Bernhard e792d62f47 readme 2012-06-02 13:44:38 +02:00
Bernhard Kubicek 6b14f95b3e Merge pull request #170 from linagee/Marlin_v1
Marlin v1
2012-06-02 03:46:56 -07:00
Bernhard Kubicek c7ce99d495 Merge pull request #172 from daid/Marlin_v1
Add M401 - Wait for user to press button on LCD (with optional timeout) minor fix in M115.
2012-06-02 03:44:03 -07:00
Bernhard Kubicek b7fc14bc65 repaired thermistortable_6 by graphcial fitting of the off-slope values. see issue 179. Erik, I know you asked for no changes, but this file probably is not related and hopefully allright. 2012-05-30 14:14:36 +03:00
ErikZalm 9e1021efbe Fixed SL bug. 2012-05-28 22:32:53 +03:00
Daid e9bec9b6fe Fixed E1_ENABLE pin for Ultimaker. This was wrong for the 1.5.4 and 1.5.3 PCB (I cannot check the 1.5.6) 2012-05-24 18:36:55 +02:00
linagee fbd282b3ba Update Marlin/Configuration.h 2012-05-20 13:19:28 -06:00
linagee 2e8c5049c5 Update Marlin/thermistortables.h 2012-05-20 13:18:45 -06:00
linagee 2d0d8e5272 Small correction. 2012-05-20 11:09:07 -06:00
Daid 4d7fe7115f Changed M401 to M0/M1 as suggested, so they match normal CNC stop commands. 2012-05-20 14:37:30 +02:00
linagee 9e9db65c3f Update Marlin/thermistortables.h 2012-05-20 05:51:29 -06:00
linagee bd966ef389 Update Marlin/thermistortables.h 2012-05-20 05:49:01 -06:00
linagee 775da3f103 Added top ratings and extended to ADC=1 for table 3 and 5. 2012-05-20 05:35:57 -06:00
linagee 96a4baa0be Update Marlin/thermistortables.h 2012-05-20 04:55:22 -06:00
linagee 2aa9f7b131 Update Marlin/thermistortables.h 2012-05-20 04:35:28 -06:00
linagee c4490f5f3d Update Marlin/Configuration.h 2012-05-20 04:27:52 -06:00
linagee dd9144994e Tested May 19 - It works! Verified with separate thermocouple TM-902C also. 2012-05-20 04:13:29 -06:00
linagee 4c37d0d9f1 Extended range above 250C. (Operating range states up to 300C) 2012-05-20 04:01:30 -06:00
Daid b59724e42b Add strigification for extruder amount in M115 report. 2012-05-19 19:01:14 +02:00
Daid 16413bb8f2 Last M401 update, refresh the LCD during an M401 wait. 2012-05-19 18:53:56 +02:00
Daid b3941fce5c Update after testing 2012-05-19 18:48:43 +02:00
Daid d494688565 Do not initialize in the header file. 2012-05-19 17:57:52 +02:00
Daid 516ec90242 Add M401 - Wait for user on LCD button press 2012-05-19 17:54:07 +02:00
Daid 7244aa7eb7 Merge branch 'Marlin_v1' of https://github.com/ErikZalm/Marlin into Marlin_v1 2012-05-19 17:38:46 +02:00
linagee de2ca3b2e8 Grammar correction. 2012-05-19 07:40:35 -06:00
linagee c2fc466e1b Update Marlin/Configuration.h 2012-05-19 05:56:17 -06:00
linagee 241f5a4c0e Update Marlin/thermistortables.h 2012-05-19 05:52:12 -06:00
linagee 9f9f498491 Update Marlin/Configuration.h 2012-05-19 05:47:30 -06:00
Erik van der Zalm e31bef31ad Limit PID autotune PWM to PID_MAX 2012-05-16 19:32:23 +02:00
ErikZalm b2a9ccdb97 Merge pull request #159 from MaikStohn/Marlin_v1
Marlin v1 - BUG FIXES / CORRECTIONS
2012-05-16 12:32:35 -07:00
Erik van der Zalm d459fb41b7 Merge branch 'Marlin_v1' of github.com:ErikZalm/Marlin into Marlin_v1 2012-05-16 19:22:08 +02:00
ErikZalm 804e0d6117 Merge pull request #164 from guanix/Marlin_v1
Melzi support
2012-05-16 12:21:48 -07:00
ErikZalm bb499421e9 Merge pull request #166 from zittix/Marlin_v1
Fixes #153 for bad call to abs()
2012-05-16 12:00:22 -07:00
Erik van der Zalm ba96059203 add additional dropsegments test 2012-05-16 19:21:44 +02:00
zittix fbd91ab0b5 Fixes #153 for bad call to abs() 2012-05-16 18:17:34 +02:00
MaikStohn b51c06e2b3 Merge branch 'Marlin_v1' of https://github.com/ErikZalm/Marlin into Marlin_v1 2012-05-11 16:57:08 +02:00
MaikStohn 159ae90874 bug fix for scrolling of main menu when using SMALL_DISPLAY (2 lines only) 2012-05-11 15:23:10 +02:00
MaikStohn e48f5aa6a7 fixed typo 2012-05-11 15:22:06 +02:00
MaikStohn 1efe9ab497 changed encoder pos from int to long to fix problems setting x/y/z/e stepps_per_mm using the lcd menu 2012-05-11 15:19:09 +02:00
Guan Yang 602c8ee02b Melzi support 2012-05-09 18:37:07 -04:00
Daid 279d00da9f Fixed #if for Ultimaker. 2012-05-09 10:50:44 +02:00
daid 830972ce3c Merge pull request #1 from ErikDeBruijn/Marlin_v1_Ultimaker-rc3
Marlin v1 ultimaker rc3
2012-05-09 01:35:59 -07:00
Bernhard Kubicek 451f9cc6d1 Residual in the comments: there are no more mm/minutes but only mm/sec in the planner buffer. 2012-05-09 08:05:13 +03:00
Erik de Bruijn e3fe1f0d00 Made a more granular configuration possible PREVENT_LENGTHY_EXTRUDE. You can now decide to allow/disallow large length of extrusions to be executed.
Turning off the protection might be beneficial to those who want to do fast and long reversals.
2012-05-08 17:44:08 +02:00
Erik de Bruijn d88205d89d Suggestion to improve (TODO), no actual code changed 2012-05-08 17:43:57 +02:00
Erik de Bruijn 5aa80e6c05 Made language.h more flexible. Automatically do the right defines based on MOTHERBOARD == 7 ? "Ultimaker" : "Mendel" 2012-05-08 17:43:02 +02:00
MaikStohn b657a18449 Revert "magic PROGMEM defines to avoid hundreds of wrong GCC warnings"
This reverts commit 3682d9bd5b.
2012-05-04 12:24:07 +02:00
Bernhard Kubicek 108011085b futher docu of M500 2012-05-04 08:37:49 +03:00
MaikStohn d188ae4c9d added missing declaration of buttons_init()
This is required when moving the buttons_init() function to the
lcd_init() function
2012-05-03 15:48:44 +02:00
MaikStohn 3682d9bd5b magic PROGMEM defines to avoid hundreds of wrong GCC warnings 2012-05-03 15:43:23 +02:00
MaikStohn 032df0b2c6 Moved LCD initialization out of constructor
Since the class "MainMenu" was used within a static variable the
initialization of the object (constructor call) was done before Arduino
library startup. It always caused a crash when using AVRStudio with
JTAG debugger (caused from calling the LCD initialization / the lot of
I/O work / the stack used during this calls). By moving the LCD_INIT
out of the constructor and using an explicit call inside of Arduino
setup() implementation immediately fixed all problems and the JTAG
debugger runs fine.
2012-05-03 14:28:17 +02:00
MaikStohn bd1ad7c76a explicit includes to make it compile with AVRStudio/Eclipse 2012-05-03 14:22:43 +02:00
MaikStohn 060b38de5c delete obsolete and wrong code
"i" runs from 0 to 4 but "add_homeing" array size is 3 only. On the
other hand the calculated value gets overwritten by either one of the
if choice.
2012-05-03 14:15:46 +02:00
MaikStohn 789ba02d43 fixed typo in comment 2012-05-03 14:13:53 +02:00
Erik van der Zalm 1874cb71a6 Added option to increase the FAN PWM frequency. 2012-05-02 19:26:14 +02:00
Erik van der Zalm 6a5a34e0ff Small cleanup 2012-04-30 13:37:49 +02:00
Erik van der Zalm e3821bd86f Merge branch 'Marlin_v1' of github.com:ErikZalm/Marlin into Marlin_v1 2012-04-30 13:36:27 +02:00
Erik van der Zalm 02af69911e Added temperature window to M109. This is needed for systems with no overshoot PID. 2012-04-30 13:36:19 +02:00
ErikZalm e203b8c754 Merge pull request #154 from daid/Marlin_v1
Added 2nd extruder temperature LCD readout and setting.
2012-04-28 13:19:55 -07:00
ErikZalm 362ddc4efc Merge pull request #155 from Atntias/patch-1
adding M120 and 121 for turning on and off the endstops only for homing
2012-04-28 13:19:19 -07:00
ErikZalm 58cad83253 Merge pull request #156 from Atntias/patch-2
Fix to allow M120/M121
2012-04-28 13:19:00 -07:00
sefi c27081aa4a Fix to allow M120/M121 2012-04-28 17:35:51 +03:00
sefi e11e072eca adding M120 and 121 for turning on and off the endstops only for homing function 2012-04-28 17:31:22 +03:00
Daid 8e68c6cf89 Show proper temperature for extruder 2 2012-04-27 15:00:01 +02:00
Daid 8503b78876 Added support for 2nd extruder temperature to UltraLCD 2012-04-27 14:51:32 +02:00
Bernhard Kubicek 8446c9dc92 Merge pull request #152 from loganb/Marlin_v1
Fix compile error on boards without a bed heater.

I could not find why this problem was introduced. 
Its quite obvious, so I think its in general interest to merge.
2012-04-25 22:23:31 -07:00
Logan Bowers 3eacb4c16d Wrap the call to turn off the bed heater in a #if to prevent a compile error on boards that do not have a bed heater 2012-04-25 19:22:38 -07:00
Bernhard e4d2138dbd reinitialize the lcd, if the SD card is inserted or removed. It seems that LCDs can confused by electrical discharges from time to time.
Since a removal or insert of the sd card takes a long time in firmware, just reinitializing the lcd does not hurt.
actually, it solves a problem with the UltiControlle
2012-04-22 21:12:17 +02:00
Bernhard 464b755918 added support for the UltiController 2012-04-22 20:55:56 +02:00
Bernhard 44fd8d46d2 fixed quickhome 2012-04-22 20:44:27 +02:00
Bernhard 33bb044d7c fixed catsting to (int)e in serial error messages.
see https://github.com/ErikZalm/Marlin/issues/148
2012-04-22 20:04:39 +02:00
Erik van der Zalm ffea8008ca Update readme file 2012-04-15 22:44:03 +02:00
ErikZalm c2557abc03 Merge pull request #138 from triffid/fix-makefile
make should rebuild if configuration or Makefile is changed
2012-04-15 10:21:46 -07:00
Erik van der Zalm 67cf105bc6 Fixed AUTOTEMP (M109 S215 B260 F1 starts autotemp)
Changed SLOWDOWN. IF this does not work ok OLD_SLOWDOWN is the old algo.
2012-04-15 19:17:33 +02:00
Erik van der Zalm 8aee9d51b6 Disabled disable_heater in PID_autotune. 2012-04-12 21:12:31 +02:00
ErikZalm 939f1fab46 Merge pull request #140 from daid/Marlin_v1
Fix for wrong systax in #ifdef.
2012-04-12 05:29:24 -07:00
Daid 414408b2d0 Fix for wrong systax in #ifdef. 2012-04-12 14:01:30 +02:00
Michael Moon 77d503fa13 Fix Makefile 2012-04-11 11:39:35 +10:00
Erik van der Zalm cf7c8c458f Fixed MAX6675 2012-04-10 21:57:57 +02:00
ErikZalm 325f0651ac Merge pull request #136 from grrf/patch-1
This breaks temperature readout for pronterface!
2012-04-10 09:48:45 -07:00
grrf 03b0850e63 This breaks temperature readout for pronterface! 2012-04-09 23:37:34 +03:00
ErikZalm 2a019a53d2 Merge pull request #134 from tgiphil/Marlin_v1
- Fixed a typo
2012-04-08 05:16:29 -07:00
tgiphil ad8bc71d3e - Fixed a typo 2012-04-07 20:01:31 -07:00
Erik van der Zalm 46feae79c6 Fixed typo in arc 2012-04-02 17:19:20 +02:00
Erik van der Zalm 4ca2f336f0 Changed default MINIMUM_PLANNER_SPEED -> 0.05
Fixed small bug in arcs
M105 prints now actual_temp/target_temp
2012-04-01 16:23:40 +02:00
Erik van der Zalm ae0bf8068b Fixed arc offset. 2012-03-27 19:03:33 +02:00
Erik van der Zalm 0c1b863755 Ignore ":" in comments. 2012-03-25 14:41:26 +02:00
Erik van der Zalm 63aec3c56e Replaced Kill by Stop. If the printer is stopped. Fix the error and use M999 to restart.
Moved the PID_dT in the Ki and Kd calculation from the configuration.h to temperature.cpp
2012-03-25 14:36:51 +02:00
ErikZalm 8b785f75a6 Merge pull request #123 from buserror-uk/for-upstream
For upstream
2012-03-23 11:54:58 -07:00
ErikZalm 5b8758f42b Merge pull request #126 from tommycheng/patch-1
Fix compilation error when PIDTEMP is undefined and ULTIPANEL is defined...
2012-03-23 11:54:37 -07:00
Tommy Cheng 520f1a54a8 Fix compilation error when PIDTEMP is undefined and ULTIPANEL is defined. 2012-03-24 02:26:59 +08:00
Michel Pollet 5550e893d5 New board variant, Open Motion Controller
Open Hardware board currently used by the group build of http://tvrrug.org.uk
The board can be found at http://solderpad.com/folknology/open-motion-controller/

Signed-off-by: Michel Pollet <buserror@gmail.com>
2012-03-22 13:51:21 +00:00
Michel Pollet aa6e6e914e Makefile: Redone
+ Removed most explicit pathnames, use the standard make "VPATH" to let
make find the files for itself.

+ Added a "hardware variant" variable that allows compiging Sanguino and
Gen7 as well as "generic" arduino.

+ Allows overriding the MOTHERBOARD define from the Makefile

+ Removed the 'preprocessor' bit that wasn't needed, now just "include" the
files that are needed, since it allows gcc to show the right file/line
when displaying error/warnings.

+ Uses gcc's own dependency generator to generate the .d files, and
and include these instead of self-patching the makefile

Signed-off-by: Michel Pollet <buserror@gmail.com>
2012-03-22 13:48:10 +00:00
Bernhard 0183e6332a made prepare->autostart independent of current folder. 2012-03-19 20:24:40 +01:00
Bernhard 1532200435 found error in filenames.
One array was too short. This had nothing to do with long filenames, other than if they were 12 characters exactly, which could only happen if the extension and the text before were filled completely
2012-03-19 20:06:58 +01:00
ErikZalm 7f775c142c Update README.md 2012-03-18 15:59:14 +01:00
Erik van der Zalm b985e4a134 Fixed compile errors in ultralcd when no ultra_lcd is selected. 2012-03-15 22:29:31 +01:00
Erik van der Zalm 2e749d60c3 Added DISABLE_MAX_ENDSTOPS 2012-03-12 20:32:14 +01:00
Erik van der Zalm 33f5697888 PPID tune exports more constants. 2012-03-11 22:18:25 +01:00
Erik van der Zalm b44055cc51 Merge branch 'Marlin_v1' of github.com:ErikZalm/Marlin into Marlin_v1 2012-03-11 18:03:00 +01:00
Erik van der Zalm f5eae52098 Added more manage_inactivity checks 2012-03-11 17:59:44 +01:00
ErikZalm 19a47dae4a Merge pull request #99 from Justblair/master
Better pin configuration for rotary encoder in RAMPS boards
2012-03-11 04:34:59 -07:00
Erik van der Zalm 910f4e77a2 Added 20MHz support. 2012-03-11 12:25:04 +01:00
ErikZalm 7cefad3744 Merge pull request #106 from bgamari/Marlin_v1
Make F_CPU dependence of stepper.cpp more explicit
2012-03-11 01:48:30 -08:00
Erik van der Zalm 87ff2f8867 Added CONTROLLERFAN. (Controlling a fan to cool down the steppper drivers) 2012-03-11 10:44:10 +01:00
Erik van der Zalm 387fe51a56 Do not disable steppers when there are moves in the queue. 2012-03-09 20:20:01 +01:00
Erik van der Zalm 421264e58a Fixed typo 2012-03-09 17:49:48 +01:00
Erik van der Zalm 15ad923310 Removed !!!. Stupid arduino bootloader can't handle this. 2012-03-09 17:42:32 +01:00
Erik van der Zalm 61e09e6be2 Added FAN_PIN -1 checks 2012-03-08 22:09:49 +01:00
Erik van der Zalm 87c4e06c24 Corrected active_extruder when autotemp is used. 2012-03-08 22:04:13 +01:00
Erik van der Zalm 7b1e295f34 Merge branch 'Marlin_v1' of github.com:ErikZalm/Marlin into Marlin_v1 2012-03-08 21:48:06 +01:00
Erik van der Zalm c077316b2b Added PID autotune. (experimental)
M303 Starts autotune. Wait till the Kp Ki and Kd constants are printed.
Put these values in Configuration.h
2012-03-08 21:43:21 +01:00
Ben Gamari 49b228c4b3 Add instructions to regenerate speed_lookuptable when changing F_CPU 2012-03-07 18:11:03 -05:00
Ben Gamari 96509494f0 stepper: Clarify comment on timer-counter configuration 2012-03-07 18:11:01 -05:00
Ben Gamari 6d7e6a11fc Add create_speed_lookup 2012-03-07 18:11:01 -05:00
ErikZalm f3095493b0 Merge pull request #100 from tommycheng/patch-1
While Waiting for hotbed to warm up via M190, LCD Display and Click Enco...
2012-03-05 09:56:50 -08:00
Tommy Cheng ce07c9186d While Waiting for hotbed to warm up via M190, LCD Display and Click Encoder input freeze until target temperature is reached. 2012-03-05 23:12:26 +08:00
Erik van der Zalm 116dc86b8a Fixed type in e-jerk 2012-03-04 23:09:13 +01:00
Blair Thompson 02ee9e3d30 Changed Pin Assignment for the RAMPS motherboard so that LCD and Rotary encoder are all wired to AUX-4
This simplifies wiring for those with RAMPS 1.3 and 1.4 boards.
2012-03-04 21:34:20 +00:00
Erik van der Zalm e056bf8081 Added E-Jerk 2012-03-04 16:34:58 +01:00
Erik van der Zalm 4deeffbc88 Added missing defines to the german section.
Translation still needed.
2012-03-04 14:08:20 +01:00
Erik van der Zalm 632528aa95 merging with SCUBA82 2012-03-04 13:41:47 +01:00
Erik van der Zalm aac7aa3bf0 Queued fan control. Issue #90 2012-03-04 13:05:26 +01:00
Christian Thalhammer fde51084f3 set SD file delete to M30; switch printime output to M31 2012-03-03 21:58:12 +01:00
Erik van der Zalm 21e2bae063 Changed (corrected?) SD_card comment handling. 2012-03-03 21:28:33 +01:00
Erik van der Zalm e509bbf636 Merge branch 'Marlin_v1' of github.com:ErikZalm/Marlin into Marlin_v1 2012-03-03 20:41:22 +01:00
Erik van der Zalm 072011a3ef Added current_block = NULL to quickStop() 2012-03-03 20:40:46 +01:00
ErikZalm 2422a857a1 Merge pull request #96 from haxar/Marlin_v1
make analog2tempBed return a precise celsius reading for BED_USES_THERMISTOR, ...
2012-03-03 11:24:58 -08:00
Erik van der Zalm f598077af3 Removed vc files 2012-03-03 20:22:42 +01:00
Erik van der Zalm cb0c84e075 Merge remote-tracking branch 'justblair/master' into Marlin_v1 2012-03-03 20:20:55 +01:00
ErikZalm 1d5809d458 Merge pull request #88 from daid/Marlin_v1
Made plan_buffer_line arguments const...
2012-03-03 11:18:14 -08:00
Erik van der Zalm ed951b1977 Fixed RAMPS 1.2 support (Found and fixed by rrhb) 2012-03-03 20:15:41 +01:00
Blair Thompson 4879de08e8 The percent complete for the SD file statistic sits squint. Changed "lcd.Setcursor (7,2);" to "lcd.Setcursor (10,2);".
The percent complete now lines up with the temperatures and Z-axis position figures, nicer to read and nicer to look at IMHO.
2012-03-03 16:47:27 +00:00
Blair Thompson f278e1c00f This is in my opinion a much better way of dealing with SD cards than my previous fix.
Instead of adding a momentary switch to fake the insertion of the card I have modified the ultralcd menu item:

Card Menu -> Refresh

to reinitialise the card providing that the SDCARDDETECT pin has been set to -1 in the pins.h file.  This requires one less switch on the front panel and the refresh menu item is in the most relevent place for a user who wishes to inert a card and then print from it.

It also means that the "Card inserted" messages do not bother the users of these card readers (they dont make sense for users without SCCARDDETECT)
2012-03-03 16:30:31 +00:00
Blair Thompson 046a8e0039 Added more defines to the language.h file so that nowe most of the text strings are now configured via this file. Still got some hunting down to do to complete this task. 2012-03-03 15:51:47 +00:00
haxar 79a466ca26 make analog2tempBed return a precise celsius reading for BED_USES_THERMISTOR, complementing changes to analog2temp in d15f01e 2012-03-02 17:15:21 -08:00
Christian Thalhammer 5f3a422e68 added M31 - delete file from sd card 2012-03-02 21:49:05 +01:00
Christian Thalhammer fa2e3a40e9 fixed LCD manual z axis move Feedrate to 70 (was 1700) 2012-03-01 14:38:50 +01:00
Christian Thalhammer a92b3afe64 added german translation;Menue should be in english.. sounds better 2012-03-01 14:24:20 +01:00
Christian Thalhammer 9fa586bbed fixed languages; Preheat_PLA and Preheat_ABS was not defined for non
english
2012-03-01 14:05:40 +01:00
Daid 00d33e6b82 Typo fix 2012-02-29 19:01:21 +01:00
Daid 7d124478fa Only protect the heater pins for the defined extruders.
Changed the way the extruder pins are defined so it doesn't create extra -1 entries in the list.
2012-02-29 15:49:02 +01:00
Daid 3d83109028 Fixed general 16x2 LCD build without SD support. 2012-02-29 15:33:23 +01:00
Christian Thalhammer cb02914687 Merge remote-tracking branch 'upstream/Marlin_v1' into Marlin_v1 2012-02-29 14:51:35 +01:00
Christian Thalhammer 10bf2bb8e1 - 2012-02-29 14:51:15 +01:00
Daid d47b666630 Merge branch 'Marlin_v1' of git://github.com/ErikZalm/Marlin into Marlin_v1 2012-02-29 12:19:20 +01:00
Daid 88d289caa1 Made plan_buffer_line arguments const, which optimizes better and fixes the RUNOUT_PREVENTION feature. 2012-02-29 11:38:12 +01:00
Erik van der Zalm b4833d55c2 Fixed HOME_POS in combination with G28 X0 or G28 Y0 2012-02-28 18:20:03 +01:00
Erik van der Zalm c6f2ec3c82 remove stop_heating_wait 2012-02-27 18:45:45 +01:00
Erik van der Zalm b48d67ce10 Fixed homing 2012-02-27 18:31:40 +01:00
ErikZalm 071eec7aa7 Merge pull request #81 from phord/09469add5560ca8a676c42e4bcd499868c33f0dd
Clean up and add some trace info
2012-02-27 08:38:36 -08:00
ErikZalm 1ebe7d1ab6 Merge pull request #83 from phord/tempfix
Add explicit #define for bogus temp override
2012-02-27 08:36:45 -08:00
ErikZalm de37b2264a Merge pull request #82 from phord/fix-gen7-build
pins.h: Define Z_MAX_PIN for Gen7 board
2012-02-27 08:36:06 -08:00
Phil Hord b65ef8d66c Add support for upcoming Gen7 v1.4
V1.4 moves thermistor power to the always-on 5v line.
The BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE is no longer
needed on this board.  Add a new motherboard type to
support this feature.
2012-02-26 20:39:49 -05:00
Phil Hord 740f0c7690 Add explicit #define for bogus temp override
The code to ignore the "bad thermistor reading failsafe"
suicide function depends on the existing of the PS_ON pin
feature.  But in some boards this shouldn't be the case
Fix this by adding an explicit definition to make our
intentions more clear and separable.
2012-02-26 20:26:16 -05:00
Phil Hord ba8500a236 pins.h: Define Z_MAX_PIN for Gen7 board
The Z_MAX_PIN value was defined as no-value, but this causes
the compile to fail.  Fix this by setting the Z_MAX_PIN to the
correct value (which happens to be 0 for pin PB0/DIO0/0).
2012-02-26 20:18:39 -05:00
Phil Hord 09469add55 Add board reset reporting (from Repetier-Firmware) 2012-02-26 18:26:56 -05:00
Phil Hord f3101e96d9 Add suitable .gitignore to avoid build noise 2012-02-26 18:26:56 -05:00
Phil Hord 245dca4bee Makefile: generic pde=>cpp rule
This adds flexibility to the makefile by allowing different pde
targets to be specified for different needs.
2012-02-26 18:26:55 -05:00
Erik van der Zalm 97d42ca2b2 SDSUPPORT default disabled 2012-02-26 22:05:38 +01:00
ErikZalm 2faa0852b9 Merge pull request #79 from changwoo/Marlin_v1
Fix build on Sanguino based boards with ATmega1284P
2012-02-26 13:03:15 -08:00
Changwoo Ryu 7b14953c99 Fix build on Sanguino based boards with ATmega1284P 2012-02-27 04:12:55 +09:00
Daid 286d5003fa Fixed compiler warning for Sanguino compile 2012-02-26 17:35:01 +01:00
ErikZalm 66d50562b6 Merge pull request #76 from iXce/Marlin_v1
Fix Makefile
2012-02-26 07:30:51 -08:00
Erik van der Zalm 27f595a444 Changed version => RC2 2012-02-26 16:26:40 +01:00
Erik van der Zalm 018c567abf Moved SLOWDOWN function. (jetty840)
Included AD595 calibration options. (daid)
2012-02-26 16:23:47 +01:00
Erik van der Zalm 4fbda5c3f5 Merge remote-tracking branch 'daid/Marlin_v1' into Test 2012-02-26 16:10:59 +01:00
Erik van der Zalm ce714fe306 Fixes in pins.h 2012-02-25 22:55:17 +01:00
Erik van der Zalm 35e57bf149 Added gen6 deluxe. 2012-02-25 17:44:45 +01:00
Erik van der Zalm 84ea2d61e8 Moved gen7 boards to motherboard type 10, 11 and 12.
Split ramps1.3 in Sprinter like config and multiextruder config.
2012-02-24 23:34:41 +01:00
Guillaume Seguin adc108d79e Correctly build the produced applet/Marlin.cpp source 2012-02-24 21:21:19 +01:00
Erik van der Zalm 5aa9c41ab1 Changed comment mode for detection.
Added M221 extuder multiply factor.
2012-02-24 20:42:07 +01:00
Erik van der Zalm 00690f7ffd Fix cast warning in Gen7 2012-02-23 18:50:05 +01:00
Erik van der Zalm 01d28c18ab Fixed casting warning in sanguino 2012-02-23 18:45:37 +01:00
Blair Thompson 2fd8c248fe Added Fan control to the pre-heat settings.
I find that the PID routine works better when the cooling fan is switched on
at the beginning of a warm up routine.  Otherwise when you enable the fan
just before a print, you have a delay as the PIDre-adjusts.

This should also be safer as most cooling fans are directed at the hot -ends
thermal barrier!
2012-02-22 23:05:52 +00:00
Blair Thompson d9f2f509d5 Added new menu items under the prepare submenu.
Instead of a single pre-heat, now there is pre-heat ABS and PLA options
Added defines to the configuration file to adjust preheat temperatures for both
2012-02-22 22:51:04 +00:00
Erik van der Zalm ae3e7586c6 Added HOME_POS. This adds the posibility to make the center 0
Updated the Xsteps ... settings via the LCD menu
2012-02-22 18:07:56 +01:00
Erik van der Zalm df1437bd86 Changed display format for some numbers. 2012-02-21 23:05:43 +01:00
Erik van der Zalm 8816ef1c64 Small fixes after merge 2012-02-21 20:36:43 +01:00
Erik van der Zalm d298dd121f merged SBUBA82 and Justblair 2012-02-21 20:26:59 +01:00
Erik van der Zalm 2cc9a89830 Merge remote-tracking branch 'SCUBA82/Marlin_v1' into Marlin_v1 2012-02-21 20:17:35 +01:00
Erik van der Zalm a0a1f81913 various changes 2012-02-21 20:17:28 +01:00
Christian Thalhammer 8a8ea50f33 fixed manual axis movement lcd option 2012-02-21 09:31:28 +01:00
Blair Thompson b976692d0f Removed VS project files for tidyness stakes 2012-02-20 22:39:39 +00:00
Blair Thompson fe940a142d Added a structure that will allow easy translations/modifications to the LCD menu.
Signed-off-by: Blair Thompson <mail@justblair.co.uk>
2012-02-20 22:22:46 +00:00
Christian Thalhammer b3fb09a20c change preheat to ABS values of nozzle 227 and be 105 °C
next try for manual axis movement
2012-02-20 16:07:27 +01:00
Christian Thalhammer 6a3f8cf23f Infos about fuses to use; correct fuses in boards.txt 2012-02-20 10:25:51 +01:00
Blair Thompson a05a261b72 Added a workaround. Ramps SD card does not have sdcarddetect. My temporary solution is to add a momentary swtich
that pulls down the SDCARDDETECT pin and mimicking the pull and reinsert ofa a SD card
2012-02-18 23:56:31 +00:00
Blair Thompson 1b6765ed12 Updated the pin config for RAMPS 1.3 to include ultimaker new style LCD/Rotary Encoder interface 2012-02-18 18:25:04 +00:00
Christian Thalhammer 1ff99ae25f ATMega1284P support for Arduino IDE
replace $ARDUINO_HOME/hardware/tools/avr/etc/arduino.conf with this file
2012-02-17 11:41:47 +01:00
Christian Thalhammer 234fe8ea67 added infos for this fork 2012-02-17 11:07:24 +01:00
Christian Thalhammer e661578c84 support for GEN7 1.1,1.2 and 1.3 2012-02-17 10:46:48 +01:00
Daid 73344e69c1 Added temperature offset/gain settings for AD595. 2012-02-16 11:05:08 +01:00
Christian Thalhammer d309565b56 Merge remote-tracking branch 'upstream/Marlin_v1' into Marlin_v1
Conflicts:
	Marlin/Configuration.h
2012-02-13 13:07:55 +01:00
daid 3f20f37c78 Merge remote branch 'upstream/Marlin_v1' into Marlin_v1 2012-02-13 12:39:00 +01:00
Christian Thalhammer 0e3631ff4b smaller changes 2012-02-13 12:31:53 +01:00
Erik van der Zalm fa2e1be0ca changed default EXTRUDE_MINTEMP to 170. 2012-02-12 17:38:54 +01:00
Erik van der Zalm 7699f250e3 Fixed small merge bug 2012-02-12 14:06:08 +01:00
Erik van der Zalm 11518a987f merged with triffid fork 2012-02-12 13:58:36 +01:00
Erik van der Zalm b447815de5 removed unused HEATING_EARLY_FINISH_DEG_OFFSET
Simplified stepper inactive time
2012-02-12 18:02:12 +08:00
Erik van der Zalm bde30b2b48 Corrected e-length calculation in planner 2012-02-12 18:02:12 +08:00
Erik van der Zalm 13e185d330 removed unused HEATING_EARLY_FINISH_DEG_OFFSET
Simplified stepper inactive time
2012-02-11 23:22:16 +01:00
Erik van der Zalm b58eae7657 Corrected e-length calculation in planner 2012-02-11 18:36:42 +01:00
ErikZalm 3e7fcb813e Merge pull request #61 from daid/Marlin_v1
Updated SERIAL define to MYSERIAL, because Arduino 1.0 defines SERIAL as 0.
2012-02-11 07:36:24 -08:00
daid 2a77c84c8f Updated SERIAL define to MYSERIAL, because Arduino 1.0 defines SERIAL as 0. 2012-02-11 16:02:47 +01:00
Erik van der Zalm d47a3e5950 Changed check i mtion_conrol
if (millimeters_of_travel == 0.0) => if (millimeters_of_travel < 0.001)
(thanks mooselake)
2012-02-09 21:02:01 +01:00
Erik van der Zalm f87c80889f Fixed M109 timer overflow (reported by triffid) 2012-02-09 20:54:49 +01:00
Erik van der Zalm 154de69c02 Print configuration.h version during startup (thanks hairykiwi) 2012-02-09 20:26:17 +01:00
Erik van der Zalm 6ef8459494 Corrected distance calculation. (thanks jv4779) 2012-02-09 19:53:06 +01:00
Erik van der Zalm 598eb1d4f1 Fixed compilation for gcc-4.6.2 with avr-lib-1.8.0 (thanks daid) 2012-02-09 19:38:53 +01:00
Erik van der Zalm 9173a5713b Teensylu support. 2012-02-09 19:27:45 +01:00
Erik van der Zalm da040fd393 Fixed ultimaker heater 1 pins. (Thanks daid) 2012-02-09 17:19:45 +01:00
Erik van der Zalm bdb70c0509 Warning for 10k thermistor 2012-02-08 18:38:45 +01:00
Erik van der Zalm 5113513cb2 RC 1 2012-02-08 18:28:54 +01:00
Erik van der Zalm d8a0c6450f Split the configuration file in two parts.
One for common settings.
One for advanced settings.
2012-02-07 20:23:43 +01:00
Christian Thalhammer 4cc8e37bf1 lcd menue "move_axis" added 2012-02-07 12:58:05 +01:00
Christian Thalhammer b5fae1104b fixed sUICIDE_PIN disable 2012-02-07 08:50:26 +01:00
Erik van der Zalm f9c5333f97 Made "stop heating wait" optional.
Default off.
2012-02-06 20:13:44 +01:00
Erik van der Zalm 292ddd2edb Fix Z_LATE_ENABLE 2012-02-06 17:38:16 +01:00
Christian Thalhammer 25cd8af536 added arduino ide GEN7 support Files 2012-02-06 14:11:25 +01:00
Christian Thalhammer 14702089ee -disable TEMP Min MAX Kill while using PS_ON Pin
ON GEN7 there is no temperature reading when power is off.. so Marlin
would kill itself. There seems to be an update from "Traumflug" on GEN7
using standby VCC for thermistors.
2012-02-06 12:28:33 +01:00
Christian Thalhammer b51e8bf7e5 -disabled CARDDETECT if PIN is set to -1
- redo disable Beeper if PIN is set to -1
2012-02-06 12:22:44 +01:00
Christian Thalhammer 3183a14755 -added Configuration for GEN7 which worked for me 2012-02-06 12:12:18 +01:00
Christian Thalhammer 5edef148fe -disalbe beeper if BEEPER_PIN = -1 2012-02-06 12:10:32 +01:00
Christian Thalhammer 13e2ad2831 - added info for using GEN7 configuration 2012-02-06 11:58:52 +01:00
Christian Thalhammer 59cc5f889e - added support for ATMega1284P 2012-02-06 11:55:56 +01:00
Christian Thalhammer a11f3b2d2f - Pins for modified GEN7 assigned
- Added support for ATMega1284
2012-02-06 11:49:23 +01:00
Christian Thalhammer b0070a244a Merge remote-tracking branch 'upstream/master' into Marlin_v1
Conflicts:
	README
2012-02-06 11:37:07 +01:00
Erik van der Zalm abb7e63906 fixed z-disable bug. 2012-02-05 21:14:55 +01:00
Erik van der Zalm 9f139d6e0e Added MAX6675 support. (Thanks to gregfrost)
Needs some work to remove the blocking in read max6675.
2012-02-05 13:05:07 +01:00
Erik van der Zalm e45e5c68bb Added support for Gen3+ (Pins file only)
Added late z enable. (blddk request)
Only calculate look ahead if >2 moves in buffer.
Removed some FORCE_INLINE to save memory.

Signed-off-by: Erik van der Zalm <erik@vdzalm.eu>
2012-02-05 12:42:15 +01:00
ErikZalm 7c6141ebc4 Merge pull request #54 from haxar/patch-1
M109 EOL fix when TEMP_RESIDENCY_TIME is undefined; printer interface (p...
2012-02-05 02:19:35 -08:00
Michael Moon 9c918a497b more work on Makefile - actually rebuilds if Makefile or Configuration.h are altered, also much cleaner output 2012-01-25 20:46:27 +11:00
Michael Moon ab01658fd2 local configuration stuff- WATCHPERIOD causes breakage, disable. few other misc changes 2012-01-24 17:02:45 +11:00
Michael Moon 42bedb3f60 PROGMEM elements must be const 2012-01-24 15:57:42 +11:00
Michael Moon a991bde523 enable auto-reset before programming, disable afterwards 2012-01-24 14:25:28 +11:00
Michael Moon 3e575533c5 get M81 working 2012-01-24 14:24:41 +11:00
Michael Moon 2ae2ead97b help residency not overflow 2012-01-24 14:24:24 +11:00
Michael Moon 71dc82e0b4 my local configuration 2012-01-24 13:19:37 +11:00
Michael Moon 5aadc2f5ca cardreader needs to include some other files 2012-01-24 13:19:24 +11:00
Michael Moon 8d0916af13 allow Marlin to actually compile with Makefile pulled from Sprinter and a few other modifications 2012-01-24 13:18:54 +11:00
haxar 6cc6029d7a M109 EOL fix when TEMP_RESIDENCY_TIME is undefined; printer interface (pronterface) could not see target extruder heater temperature to continue print 2012-01-22 03:25:56 -08:00
Bernhard 157aa7f2fd m115 eol fix 2012-01-15 20:51:49 +01:00
Bernhard 7aeb45303d small mistake 2012-01-15 18:31:21 +01:00
Bernhard cee5f9020a added suicide pin for a power supply to the arduino that is only active if the arduino is holding high for an output. 2012-01-15 17:06:10 +01:00
Bernhard 3814bbb529 made sd code only compile with SDSUPPORT defined. safes 10k of codespace 2011-12-26 09:28:51 +01:00
Bernhard 729cde4475 fix autostart failure if in wrong directory 2011-12-26 09:20:53 +01:00
Bernhard 396270a0de fix duplicated definition of MOSI MISO pins in case motherboard==33 2011-12-26 09:20:21 +01:00
Bernhard 11f2dafc4e one step closer to a functional makefile.. 2011-12-22 16:43:28 +01:00
Bernhard 8463e39a4a starting with sanguino arduino 1.0 compatibility 2011-12-22 16:11:15 +01:00
Bernhard 2bc160a978 add wiring.h, that can be used to overwrite:
arduino-0023/hardware/arduino/cores/arduino/wiring.h
this is necessary if the avr libraries are recent, but arduino is old. Alternative: newer arduino
2011-12-22 14:57:28 +01:00
Bernhard 57f9359a41 simplified the includes, makefile now works with arduino23 2011-12-22 14:55:45 +01:00
Bernhard 3c1a4aac2b header file simplification 2011-12-22 12:38:50 +01:00
Bernhard 212515148e added m240 photography support. default off 2011-12-22 12:11:39 +01:00
Bernhard 6735025428 cooldown 2011-12-22 12:02:33 +01:00
Bernhard 415aadf704 lcd panel bed support
advance and ultipanel not any more in default config
2011-12-22 11:45:52 +01:00
Bernhard 4bababf5b0 Merge branch 'Marlin_v1' of https://github.com/ErikZalm/Marlin into Marlin_v1 2011-12-22 09:22:39 +01:00
Bernhard f312216e97 Revert "untestest commit, so I don't loose code.. features runout prevention addons"
This reverts commit 651cde8b98.
2011-12-22 09:22:22 +01:00
Bernhard 651cde8b98 untestest commit, so I don't loose code.. features runout prevention addons 2011-12-22 09:20:34 +01:00
Erik van der Zalm 554cc1718d Fiexed E_ENABLE_PIN errors 2011-12-15 11:59:07 +01:00
Erik van der Zalm 617968ab76 G92 fix 2011-12-12 20:43:47 +01:00
Erik van der Zalm 84d9cf7339 merging 2011-12-12 20:35:46 +01:00
Erik van der Zalm e017228569 Merged multiple extruder support.
Soft PWM. (Sanguinololu can also have PID temperature control)
Interrupt save WRITE for addresses > 0x0FF
2011-12-12 19:34:37 +01:00
Bernhard 3320a5b37d make autotemp compatile for use without pid 2011-12-11 22:25:52 +01:00
Bernhard 06411d5c9e ultralcd can now also stop the wait loop for the hot-end m109 heating when stopping sd prints. 2011-12-11 22:18:50 +01:00
Bernhard 82c99625fa instant stop of sd prints from the panel. 2011-12-11 22:10:06 +01:00
Bernhard 01001b89d2 repaired nozzle runout prevention to not collide with automatic stepper disabeling. 2011-12-11 15:42:56 +01:00
Bernhard 88ee053af0 heating up santity, formarly knows as "watchdog", but renamed due to the existance of the real watchdog, works now. 2011-12-09 17:07:44 +01:00
Bernhard b1d84d879b st_synchronize back to normal.. 2011-12-09 16:13:58 +01:00
Bernhard Kubicek f6fe7143e4 Merge pull request #29 from k-eex/Marlin_v1
Fix M201 not saving settings in all places, so the changes did not get written into EEPROM
2011-12-09 06:37:42 -08:00
Bernhard dde4b40fa9 disable steppers in runout prevention 2011-12-09 15:37:24 +01:00
Bernhard 2bc5e7ec9e prevent too long extrudes, or too cold extrudes 2011-12-09 15:09:52 +01:00
Bernhard aa4f9a6474 better values. 2011-12-09 14:09:34 +01:00
Bernhard 87fd249c43 made runout prevention independent of tempeorarily set esteps 2011-12-09 13:56:28 +01:00
Bernhard 1ec0c3b68a extruder runout prevention. 2011-12-09 13:39:00 +01:00
Bernhard 5b4625f79c added a partial release option to "m84" aka "stepper release". If you do tiny layers, you might want to keep the z-axis powered to not loose height positioning after homeing. 2011-12-09 12:51:08 +01:00
Bernhard cc4a9cdb69 added autostart procedure trigger to the ultralcd menu 2011-12-09 12:33:00 +01:00
Bernhard 61c943b4bf fixed the st_synchronize. it would have continued if there is only the last move of the buffer being stepped. 2011-12-09 12:32:31 +01:00
Keegi bae1e422f6 Fix M201 not saving settings in all places, so the changes did not get written into EEPROM 2011-12-08 12:25:32 +02:00
Bernhard 754d2d69b2 z homing sound fix, for now until the actual cause is found.. 2011-12-07 23:08:13 +01:00
Bernhard 986f0ba76c moved <stdio.h> to more dominant location. 2011-12-07 20:56:47 +01:00
Bernhard 460b788d78 repaired homing position setting. 2011-12-07 20:54:34 +01:00
Erik van der Zalm 3664ed6aad Merge branch 'Marlin_v1' of https://github.com/dob71/Marlin into Marlin_v1 2011-12-07 19:57:39 +01:00
Erik van der Zalm 43f5c3e82b Merge branch 'Marlin_v1', remote-tracking branch 'origin/Marlin_v1' into Marlin_v1 2011-12-07 19:55:17 +01:00
Denis B 4fd75dc813 Working version of multiple extruders (up to 3)
- The temperature control is pretty much complete
  (not sure what to do w/ autotemp though)
  Changed the pins assignment to clearly separate bed and extruder heaters
  and temp sensors, changed a bit how termistor tables are handled.
- The steppers control is rudimentary
  (only chanages what pins it uses depending on the active_extruder var,
   but that's enough for switching extruder in the start.gcode in the
   the profiles)
- Tested only w/ RAMPS 1.4
2011-12-06 00:09:16 -05:00
Bernhard 12e8edcac3 Merge branch 'Marlin_v1' of https://github.com/ErikZalm/Marlin into Marlin_v1 2011-12-04 22:27:37 +01:00
Bernhard cf50ba140f added M503 to display eeprom storage, and renamed eeprom routings. This version is compatible with the qtmarlin eeprom-tab. 2011-12-04 22:26:42 +01:00
Erik van der Zalm 89e832c295 Update endstops only for homing. (use less resources when not used) 2011-12-04 21:03:02 +01:00
Erik van der Zalm b99c49ec3b Add option to only check endstop when homing 2011-12-04 20:17:21 +01:00
Erik van der Zalm 95a0b28acb Merge branch 'Marlin_v1', remote-tracking branch 'origin/Marlin_v1' into Marlin_v1 2011-12-04 19:54:43 +01:00
Erik van der Zalm af22e9cd38 Some advance modifications 2011-12-04 19:54:07 +01:00
Bernhard 7714b98da7 solved some compiler warnings that are now visible in arduino 1.0.
Found a couple of unused variables, that I commented.
Tried to solve the program memory warning message, and failed.
2011-12-04 12:40:18 +01:00
Bernhard dfd240b260 overworked autotemp, removed one layer of nesting from the ultralcd. 2011-12-04 09:48:53 +01:00
Bernhard 4f909963e4 make QUICKHOME configureable 2011-12-04 09:02:09 +01:00
Erik van der Zalm 6b86f15686 More 2nd extruder implementation. (Not usable)
Advance (not tested)
2011-12-02 17:45:05 +01:00
Bernhard 0bc9daa4f7 make it compile with arduino 1.0 ; function is still untested. 2011-12-01 16:38:01 +01:00
Bernhard b0c3871750 more fixing of the sanguino math round problem 2011-11-30 09:07:56 +01:00
Bernhard 9c57453168 removed stream.h referenece from marlinserial. 2011-11-30 08:57:30 +01:00
Bernhard 59205ac5fc preliminiary implementation for the early heating finish.
Might be replaced by something more clever, e.g. by erik, and does not yet support the second extruder or the bed.
its kind of not so cool, because you need 6 more ints.
Maybe isheating() should use the degrees directly, as it is not used in time-critical anyways.
Then it would be much easier. to have the offsets without additional variables.
2011-11-30 08:51:46 +01:00
Bernhard 7a4be21b4f made it compile if arduino decides to include files in a differnt order. DEC HEX and stuff now defined in MarlinSerial.h 2011-11-30 08:32:28 +01:00
Bernhard 716e89b87c first homing move diagonal towards home switches. 2011-11-29 22:11:45 +01:00
Bernhard d00b7e5587 repaired compiliation in windows 2011-11-28 22:45:40 +01:00
Bernhard e4ab0e5982 more inlines 2011-11-28 22:11:17 +01:00
Bernhard 8cb29921a0 possible stepper release after sd printing 2011-11-28 22:09:17 +01:00
Bernhard 044886b4a0 Merge branch 'Marlin_v1' of https://github.com/ErikZalm/Marlin into Marlin_v1 2011-11-28 21:52:16 +01:00
Bernhard b19c8b74b9 force inline 2011-11-28 21:51:44 +01:00
Erik van der Zalm 6d95644c0d Moved M88 into M84. (M84 E) 2011-11-28 21:49:54 +01:00
Bernhard 311627141b Merge branch 'smallopt' into Marlin_v1
Conflicts:
	Marlin/temperature.h
2011-11-28 21:36:01 +01:00
Erik van der Zalm 7216a12856 Disabled M88 for boards that don't have seperate enable pins. 2011-11-28 21:17:06 +01:00
Erik van der Zalm 98805c9228 Added M88 command. (Request from Action68) 2011-11-28 20:51:01 +01:00
Bernhard 85da81e673 inlineing of small functions in serial 2011-11-28 19:34:42 +01:00
Bernhard b9ad0bb2ce removed unecessary indirect register adressing in serial. 2011-11-28 19:28:38 +01:00
Bernhard dd5ca68c87 get rid of indirect ringbuffer calls, made some inlines, removed virtual and streaming class requirements. 2011-11-28 19:13:40 +01:00
Erik van der Zalm dd5296ad4d Fixed temperature reading bug.
(When using the lower and upper adc input bank)
2011-11-28 17:42:49 +01:00
Erik van der Zalm f75f426dfa Removed interrupt nesting in the stepper ISR.
Add serial checkRx in stepper ISR.
Copied HardwareSerial to MarlinSerial (Needed for checkRx).
2011-11-27 21:12:55 +01:00
Bernhard 2d9a715655 first naive attempt to have a offset in the homeing procedure. Does not enable to move into regions not allowed by endstops. 2011-11-27 17:27:17 +01:00
Bernhard d2f034ba84 lcd message from gcode, m117 2011-11-27 16:53:11 +01:00
Bernhard 6aecf80278 add autotemp support to the lcd 2011-11-27 16:45:19 +01:00
Bernhard b128d25f27 overlooked some inlines.. 2011-11-27 16:45:00 +01:00
Bernhard 26a1de1e44 force inline 2011-11-27 16:04:58 +01:00
Bernhard f8e170a44b planner optimization by inline functions 2011-11-27 14:57:12 +01:00
Erik van der Zalm aad4b75b94 First parts 2nd extruder 2011-11-26 17:33:25 +01:00
Bernhard a0dc66f7bf Home retract distance configureable per axis. 2011-11-26 12:04:06 +01:00
Bernhard 6d6f323535 make an option if sd-card stop should release the steppers. 2011-11-26 11:51:38 +01:00
Bernhard 4d6a5c29df disable steppers as routine in stepper.cpp 2011-11-26 11:50:23 +01:00
Bernhard 74d0032e25 cooldown blocking selectable by #define. 2011-11-26 09:03:12 +01:00
Bernhard 191f36b493 slowdown 2011-11-25 23:59:30 +01:00
Bernhard c54a807824 overworked ultralcd a bit 2011-11-25 23:37:08 +01:00
Bernhard a6823a84e1 another typo 2011-11-25 22:36:33 +01:00
Bernhard 57e163e989 typo 2011-11-25 22:34:12 +01:00
Bernhard b58787a367 now velocities are also set in mm/sec in gcode. 2011-11-25 22:32:26 +01:00
Bernhard 71ca78982b Merge branch 'Marlin_v1' of https://github.com/ErikZalm/Marlin into Marlin_v1 2011-11-25 22:14:36 +01:00
Bernhard 235051253a overworked lcd+eeprom to have only mm/sec and PID including pid_dt 2011-11-25 22:14:29 +01:00
Erik van der Zalm 27654bfe69 Fixed variable (removed 0x) 2011-11-25 22:10:06 +01:00
Erik van der Zalm cdf0bd4e63 Fixed config bug when EEPROM was disabled 2011-11-25 20:07:30 +01:00
Erik van der Zalm 6ac9b2e761 Fixed residency time bug. (Thanks to Sound :-) ) 2011-11-25 19:34:36 +01:00
Erik van der Zalm ac8adabb2b Small nominal speed improvement. 2011-11-25 15:32:50 +01:00
Erik van der Zalm 0e0e4945d8 Removed ISR overtaken message from ISR routine 2011-11-25 13:59:58 +01:00
Erik van der Zalm c0f8c9fd72 Seperate ENDSTOP_INVERTING for X Y and Z
Added simple endstop filter.
Corrected M114 count display.
2011-11-25 13:43:06 +01:00
ErikZalm 0db97b9c7f Update README.md 2011-11-21 22:40:47 +01:00
Bernhard Kubicek 5535e51bf6 Yes, thats the beta. 2011-11-20 17:04:57 +01:00
Bernhard Kubicek 8b14a8ad34 Merge branch 'Marlin_v1' of https://github.com/ErikZalm/Marlin into Marlin_v1 2011-11-20 16:39:39 +01:00
Bernhard Kubicek 924bab1a03 less lcd flickering 2011-11-20 16:37:01 +01:00
Bernhard Kubicek 379ea642e1 make tuneing sub-menu. 2011-11-20 16:05:42 +01:00
Erik van der Zalm 959d82e81e Small temperature disable bug. 2011-11-20 15:03:35 +01:00
Erik van der Zalm 15bb3f284e Merge branch 'Marlin_v1', remote-tracking branch 'origin/Marlin_v1' into Marlin_v1 2011-11-20 14:51:40 +01:00
Erik van der Zalm 4e5becfc51 Added endstop reporting 2011-11-20 14:50:08 +01:00
Bernhard Kubicek eeb4f029db Merge branch 'Marlin_v1' of https://github.com/ErikZalm/Marlin into Marlin_v1 2011-11-20 14:45:38 +01:00
Bernhard Kubicek b21d5193f2 made ultralcd compatible with folders. 2011-11-20 14:43:47 +01:00
Erik van der Zalm 85c8a87e70 Small changes to README.md 2011-11-20 13:31:07 +01:00
Erik van der Zalm 2e43f9c809 Changed min max temperature code. 2011-11-20 13:14:58 +01:00
Bernhard Kubicek cd2268f10a code cleanup in ultralcd. 2011-11-20 11:55:33 +01:00
Bernhard Kubicek d8e7e2f72e more readme 2011-11-20 11:55:06 +01:00
Bernhard Kubicek 6dba34ab0e even more format. 2011-11-20 09:09:11 +01:00
Bernhard Kubicek 4687c56f53 format 2011-11-20 09:06:05 +01:00
Bernhard Kubicek 4258841241 format 2011-11-20 09:03:42 +01:00
Bernhard Kubicek 827cd72703 format readme. 2011-11-20 09:00:19 +01:00
Bernhard Kubicek d41547a397 Merge branch 'Marlin_v1' of https://github.com/ErikZalm/Marlin into Marlin_v1 2011-11-19 22:04:55 +01:00
Bernhard Kubicek 61e0740bf0 overworked readme 2011-11-19 22:04:37 +01:00
Erik van der Zalm 0e7fee9a9b Merge branch 'Marlin_v1', remote-tracking branch 'origin/Marlin_v1' into Marlin_v1 2011-11-19 21:33:15 +01:00
Erik van der Zalm 915ef2d4a1 Added software endstops 2011-11-19 21:32:47 +01:00
Bernhard Kubicek e87df99e22 update mcode documentation 2011-11-19 21:01:07 +01:00
Bernhard Kubicek 8a1e719a3f overworked config file 2011-11-19 20:52:43 +01:00
Bernhard Kubicek 5ad1d19384 make it compile without sd_support 2011-11-19 20:18:54 +01:00
Bernhard Kubicek 7a2d1f5aeb add M17, so the enable stepper button works in repg. 2011-11-19 18:22:22 +01:00
Erik van der Zalm e02af3e66a Merge remote-tracking branch 'origin/Marlin_v1' into Marlin_v1 2011-11-19 17:23:47 +01:00
Erik van der Zalm 537b5c155d Fixed arc flowrate. 2011-11-19 17:23:28 +01:00
Bernhard Kubicek 953d830bba Merge branch 'Marlin_v1' of https://github.com/ErikZalm/Marlin into Marlin_v1 2011-11-19 17:09:43 +01:00
Bernhard Kubicek 2a6afee832 make it compile without autotemp 2011-11-19 17:09:33 +01:00
Bernhard Kubicek f52e1a9571 autotemp working, default=disabled. 2011-11-19 17:07:44 +01:00
Erik van der Zalm 6e6fdb9a4e Merge remote-tracking branch 'origin/Marlin_v1' into Marlin_v1 2011-11-19 16:18:13 +01:00
Erik van der Zalm 6841a10446 Fixed max/min temperature bug 2011-11-19 16:16:26 +01:00
Bernhard Kubicek 8a08b8e07e trying to get autotemp to work. 2011-11-19 15:37:10 +01:00
Bernhard Kubicek f0154de5b3 found bug that disabled printing from root. 2011-11-19 15:36:49 +01:00
Bernhard Kubicek 70650c331d corrected the ultimaker default values, the previous had a calculation error: see: http://groups.google.com/group/ultimaker/browse_thread/thread/91906788639703cf 2011-11-19 14:50:31 +01:00
Bernhard Kubicek 9d90220537 Merge branch 'Marlin_v1' of https://github.com/ErikZalm/Marlin into Marlin_v1 2011-11-19 14:35:53 +01:00
Bernhard Kubicek 869cee74e6 host-based sd card printing seems now to work with folders 2011-11-19 14:34:27 +01:00
Bernhard Kubicek 70abca195a overworked cardreader for folder support; not finished yet. 2011-11-19 13:13:34 +01:00
Erik van der Zalm ff69e0a772 Changed max/min temp init. Removed second uart from sabguino core 2011-11-19 12:19:53 +01:00
Bernhard Kubicek 1e5e141ac9 Merge branch 'Marlin_v1' of https://github.com/ErikZalm/Marlin into Marlin_v1 2011-11-18 22:22:23 +01:00
Bernhard Kubicek edb5ea7efa the normal config again.. 2011-11-18 22:22:07 +01:00
Bernhard Kubicek 5df5727e93 removed some debugging comments 2011-11-18 22:20:53 +01:00
Bernhard Kubicek 64f2121ab1 updated to sdfatlib2010902 2011-11-18 22:17:37 +01:00
Erik van der Zalm b15902d3b5 Fixed bug in configuration.h 2011-11-18 19:46:16 +01:00
Erik van der Zalm e63e224a33 Merge remote-tracking branch 'origin/Marlin_v1' into Marlin_v1
Conflicts:
	Marlin/Configuration.h
	Marlin/Marlin.pde
2011-11-18 19:04:09 +01:00
Erik van der Zalm e7dca8614b Advance experiments. Not working yet. 2011-11-18 18:59:17 +01:00
Bernhard Kubicek 46f80e82d9 Merge branch 'Marlin_v1' of https://github.com/ErikZalm/Marlin into Marlin_v1
Conflicts:
	Marlin/ultralcd.h
2011-11-15 22:53:04 +01:00
Bernhard Kubicek a9c7da06e3 and changed ultipanel to have the mm/sec and not mm/min
Merge branch 'Marlin_v1' of https://github.com/ErikZalm/Marlin into Marlin_v1

Conflicts:
	Marlin/Marlin.pde
	Marlin/ultralcd.h
2011-11-15 22:50:43 +01:00
Bernhard Kubicek 02b9eceead show sd% 2011-11-15 20:55:00 +01:00
Bernhard Kubicek 7919a40d06 watchdog,percent done, 2011-11-15 20:54:40 +01:00
Erik van der Zalm 805d37f77b Fixed some small planner bugs 2011-11-15 18:14:00 +01:00
Erik van der Zalm 5fd41ae872 Some fixes in planner 2011-11-14 23:57:34 +01:00
Erik van der Zalm 95126c09c0 Added slowdown 2011-11-14 20:04:29 +01:00
Erik van der Zalm 331e82dcd3 Buffer size > 16 2011-11-14 18:53:09 +01:00
Erik van der Zalm 2643ae93d6 Added modified Sanguino files 2011-11-14 18:27:47 +01:00
Erik van der Zalm c00eefb824 Merge remote-tracking branch 'origin/Marlin_v1' into Marlin_v1 2011-11-14 18:26:57 +01:00
Erik van der Zalm 1d0452f10c 250000 baud 2011-11-14 18:24:02 +01:00
Bernhard Kubicek c57906b627 fixed bug with adjusting ki in realtime. 2011-11-13 21:43:26 +01:00
Erik van der Zalm ac82411c73 Merge remote-tracking branch 'origin/Marlin_v1' into Marlin_v1 2011-11-13 20:46:44 +01:00
Erik van der Zalm 65934eee9c A lot of changes in the planner code 2011-11-13 20:42:08 +01:00
Bernhard Kubicek 9980ceb4a3 added a m400, that finished all moves,
and the mechanism so that if an endstop is hit it the ISR, the steps_to_be_taken are stored, and some current_block data that will be deleted in the next move
If the normal loop() then finds such an event, the position is calculated (floats would have taken too long in the ISR) A serial message is generated.
2011-11-13 19:58:09 +01:00
Bernhard Kubicek ff592b056a heater power repair. 2011-11-13 00:48:55 +01:00
Bernhard Kubicek e9adfa27b5 re-enabled heaterpower as storage for the current storage of the heater PWM duty cycle.
the M301 now returns the current PID settings of the machine.
M105 returns heating pwm duty cylce as "@:"
2011-11-12 20:37:28 +01:00
Bernhard Kubicek 36958ee305 minor changes and first not-well working version of autotemp 2011-11-09 22:09:16 +01:00
Bernhard Kubicek ba8a53a40f Streaming.h is gone. It conflicted with PROGMEM. And saving memory is more important than nicer code, imho 2011-11-09 20:30:41 +01:00
Bernhard Kubicek 27361e7cd0 beautified the config. ordered it into thematic sections. 2011-11-09 20:28:40 +01:00
Bernhard Kubicek ab154d5592 project progmem finished: total change with ultipanel: 2456 byte free ram initial. now: 4374 ram. 2011-11-09 20:27:44 +01:00
Bernhard Kubicek 7b70caab7c made progmem mainly, found one bug in cardreader, added a empty class for cardreader in case no sd support. 2011-11-07 22:33:13 +01:00
Bernhard Kubicek 72ace55e6a better visibility of public/private/imported variables 2011-11-06 23:34:40 +01:00
Bernhard Kubicek 977fd2b2c7 Merge branch 'Marlin_v1' of https://github.com/ErikZalm/Marlin into Marlin_v1 2011-11-06 23:21:33 +01:00
Bernhard Kubicek 907daa49af made loop counters uint8_t most were int(16_t) before 2011-11-06 23:21:12 +01:00
Erik van der Zalm e3af73ee0c Thermistor name problem 2011-11-06 23:20:01 +01:00
Bernhard Kubicek 0b43761c3a preprocessor magic to have a single source principle 2011-11-06 23:13:19 +01:00
Bernhard Kubicek 156763d027 Merge branch 'Marlin_v1' of https://github.com/ErikZalm/Marlin into Marlin_v1 2011-11-06 22:48:36 +01:00
Bernhard Kubicek fc0064e525 made cardreader more selfsustained 2011-11-06 22:48:15 +01:00
Erik van der Zalm d3bfffcb6e Corrected thermistor naming 2011-11-06 22:37:43 +01:00
Bernhard Kubicek 01df04e02c first compile with the cardreader class 2011-11-06 21:39:53 +01:00
Bernhard Kubicek 163efdf1c7 Merge branch 'Marlin_v1' of https://github.com/ErikZalm/Marlin into Marlin_v1 2011-11-06 19:49:04 +01:00
Bernhard Kubicek 87aaf0f70a static'ified Marlin.pde. 2011-11-06 19:48:37 +01:00
Erik van der Zalm 5cf349a24a Fixed some arc bugs 2011-11-06 19:37:12 +01:00
Bernhard Kubicek 79d1bfb5c0 made many possible variables static, so they cannot be used extern. 2011-11-06 19:36:29 +01:00
Erik van der Zalm 76b3f805c0 Added teensylu pins 2011-11-06 19:30:04 +01:00
Bernhard Kubicek 1d171e9e52 reformating and some minor bugs/things found on the way. 2011-11-06 19:23:08 +01:00
Bernhard Kubicek 900e0c9bf2 overworked the serial responses. Quite difficult, since many texts are Pronterface protocol. 2011-11-06 17:33:09 +01:00
Bernhard Kubicek 1740a83e11 correcting commit errors. 2011-11-06 15:10:29 +01:00
Bernhard Kubicek 7cc358b56b wrong file location 2011-11-06 14:58:12 +01:00
Bernhard Kubicek e8092898b1 watchdog into dedicated file 2011-11-06 14:22:15 +01:00
Bernhard Kubicek 2afb7bd4cf refactured temperature.cpp so that there are now abstract functions to access temperatures. 2011-11-06 14:03:41 +01:00
Erik van der Zalm 0b82465168 First arcs version. (Arcs not working ok) 2011-11-06 12:39:00 +01:00
Erik van der Zalm 2e8e8878e5 Corrected temp variables. 2011-11-05 20:21:09 +01:00
Erik van der Zalm 04d3b5537f Merge remote-tracking branch 'origin/Marlin_v1' into Marlin_v1
Conflicts:
	Marlin/Configuration.h
	Marlin/EEPROMwrite.h
	Marlin/Marlin.h
	Marlin/Marlin.pde
	Marlin/temperature.cpp
	Marlin/temperature.h
	Marlin/thermistortables.h
2011-11-05 20:03:38 +01:00
Erik van der Zalm d15f01e1b4 Temperature changes 2011-11-05 19:21:36 +01:00
Bernhard Kubicek ea86a5e10f moved the variables in the ISR, thats the most normal use case of static. 2011-11-05 16:53:37 +01:00
Bernhard Kubicek b9ea0651ec Revert "this is not working. Do you maybe know why?"
This reverts commit 8bcdb9f5f0.
2011-11-05 16:49:29 +01:00
Bernhard Kubicek 8bcdb9f5f0 this is not working. Do you maybe know why? 2011-11-05 16:43:44 +01:00
Bernhard Kubicek 40e8081623 changed end of line to windows, which seems to be the majority of developers main platform. 2011-11-05 14:19:57 +01:00
Bernhard Kubicek 00674af3a8 merge from the branch bkubicek/Marlin/zalmmerge 2011-11-05 14:13:20 +01:00
Erik van der Zalm d7c4f0780b Added M42, M80 and M81 2011-11-05 11:18:52 +01:00
Erik van der Zalm 95d3d9847c M109 now equal to sprinter 2011-11-04 23:38:25 +01:00
Erik van der Zalm bf879ceaa9 Added thermistor tables 2011-11-04 22:51:14 +01:00
Erik van der Zalm 094afe7c10 Merged Marlin, Marlin non gen6 and Ultimaker changes 2011-11-04 18:02:56 +01:00
450 changed files with 283901 additions and 7001 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
*.o
applet/
*~
*.orig
*.rej

View File

@ -0,0 +1,35 @@
##############################################################
Generation_Series.name=Gen6 & Gen6 Deluxe
Generation_Series.upload.protocol=stk500
Generation_Series.upload.maximum_size=63488
Generation_Series.upload.speed=38400
Generation_Series.bootloader.low_fuses=0xFF
Generation_Series.bootloader.high_fuses=0xDC
Generation_Series.bootloader.extended_fuses=0xFD
Generation_Series.bootloader.path=atmega644p
Generation_Series.bootloader.file=ATmegaBOOT_644P.hex
Generation_Series.bootloader.unlock_bits=0x3F
Generation_Series.bootloader.lock_bits=0x0F
Generation_Series.build.mcu=atmega644p
Generation_Series.build.f_cpu=16000000L
Generation_Series.build.core=arduino
##############################################################
Sanguinololu.name=Sanguinololu 1.2 and above
Sanguinololu.upload.protocol=stk500
Sanguinololu.upload.maximum_size=63488
Sanguinololu.upload.speed=38400
Sanguinololu.bootloader.low_fuses=0xFF
Sanguinololu.bootloader.high_fuses=0xDC
Sanguinololu.bootloader.extended_fuses=0xFD
Sanguinololu.bootloader.path=atmega644p
Sanguinololu.bootloader.file=ATmegaBOOT_644P.hex
Sanguinololu.bootloader.unlock_bits=0x3F
Sanguinololu.bootloader.lock_bits=0x0F
Sanguinololu.build.mcu=atmega644p
Sanguinololu.build.f_cpu=16000000L
Sanguinololu.build.core=arduino

View File

@ -0,0 +1,713 @@
/**********************************************************/
/* Serial Bootloader for Atmel megaAVR Controllers */
/* */
/* tested with ATmega644 and ATmega644P */
/* should work with other mega's, see code for details */
/* */
/* ATmegaBOOT.c */
/* */
/* 20090131: Added 324P support from Alex Leone */
/* Marius Kintel */
/* 20080915: applied ADABoot mods for Sanguino 644P */
/* Brian Riley */
/* 20080711: hacked for Sanguino by Zach Smith */
/* and Justin Day */
/* 20070626: hacked for Arduino Diecimila (which auto- */
/* resets when a USB connection is made to it) */
/* by D. Mellis */
/* 20060802: hacked for Arduino by D. Cuartielles */
/* based on a previous hack by D. Mellis */
/* and D. Cuartielles */
/* */
/* Monitor and debug functions were added to the original */
/* code by Dr. Erik Lins, chip45.com. (See below) */
/* */
/* Thanks to Karl Pitrich for fixing a bootloader pin */
/* problem and more informative LED blinking! */
/* */
/* For the latest version see: */
/* http://www.chip45.com/ */
/* */
/* ------------------------------------------------------ */
/* */
/* based on stk500boot.c */
/* Copyright (c) 2003, Jason P. Kyle */
/* All rights reserved. */
/* see avr1.org for original file and information */
/* */
/* 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 the Free Software */
/* Foundation; either version 2 of the License, or */
/* (at your option) any later version. */
/* */
/* This program 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 General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU General */
/* Public License along with this program; if not, write */
/* to the Free Software Foundation, Inc., */
/* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* */
/* Licence can be viewed at */
/* http://www.fsf.org/licenses/gpl.txt */
/* */
/* Target = Atmel AVR m128,m64,m32,m16,m8,m162,m163,m169, */
/* m8515,m8535. ATmega161 has a very small boot block so */
/* isn't supported. */
/* */
/* Tested with m168 */
/**********************************************************/
/* $Id$ */
/* some includes */
#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <avr/boot.h>
#ifdef ADABOOT
#define NUM_LED_FLASHES 3
#define ADABOOT_VER 1
#endif
/* 20070707: hacked by David A. Mellis - after this many errors give up and launch application */
#define MAX_ERROR_COUNT 5
/* set the UART baud rate */
/* 20080711: hack by Zach Hoeken */
#define BAUD_RATE 38400
/* SW_MAJOR and MINOR needs to be updated from time to time to avoid warning message from AVR Studio */
/* never allow AVR Studio to do an update !!!! */
#define HW_VER 0x02
#define SW_MAJOR 0x01
#define SW_MINOR 0x10
/* onboard LED is used to indicate, that the bootloader was entered (3x flashing) */
/* if monitor functions are included, LED goes on after monitor was entered */
#define LED_DDR DDRB
#define LED_PORT PORTB
#define LED_PIN PINB
#define LED PINB0
/* define various device id's */
/* manufacturer byte is always the same */
#define SIG1 0x1E // Yep, Atmel is the only manufacturer of AVR micros. Single source :(
#if defined(__AVR_ATmega644P__)
#define SIG2 0x96
#define SIG3 0x0A
#elif defined(__AVR_ATmega644__)
#define SIG2 0x96
#define SIG3 0x09
#elif defined(__AVR_ATmega324P__)
#define SIG2 0x95
#define SIG3 0x08
#endif
#define PAGE_SIZE 0x080U //128 words
#define PAGE_SIZE_BYTES 0x100U //256 bytes
/* function prototypes */
void putch(char);
char getch(void);
void getNch(uint8_t);
void byte_response(uint8_t);
void nothing_response(void);
char gethex(void);
void puthex(char);
void flash_led(uint8_t);
/* some variables */
union address_union
{
uint16_t word;
uint8_t byte[2];
} address;
union length_union
{
uint16_t word;
uint8_t byte[2];
} length;
struct flags_struct
{
unsigned eeprom : 1;
unsigned rampz : 1;
} flags;
uint8_t buff[256];
uint8_t error_count = 0;
uint8_t sreg;
void (*app_start)(void) = 0x0000;
/* main program starts here */
int main(void)
{
uint8_t ch,ch2;
uint16_t w;
uint16_t i;
asm volatile("nop\n\t");
#ifdef ADABOOT // BBR/LF 10/8/2007 & 9/13/2008
ch = MCUSR;
MCUSR = 0;
WDTCSR |= _BV(WDCE) | _BV(WDE);
WDTCSR = 0;
// Check if the WDT was used to reset, in which case we dont bootload and skip straight to the code. woot.
if (! (ch & _BV(EXTRF))) // if its a not an external reset...
app_start(); // skip bootloader
#endif
//initialize our serial port.
UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
UCSR0B = (1<<RXEN0) | (1<<TXEN0);
UCSR0C = (1<<UCSZ00) | (1<<UCSZ01);
/* Enable internal pull-up resistor on pin D0 (RX), in order
to supress line noise that prevents the bootloader from
timing out (DAM: 20070509) */
DDRD &= ~_BV(PIND0);
PORTD |= _BV(PIND0);
/* set LED pin as output */
LED_DDR |= _BV(LED);
/* flash onboard LED to signal entering of bootloader */
/* ADABOOT will do two series of flashes. first 4 - signifying ADABOOT */
/* then a pause and another flash series signifying ADABOOT sub-version */
flash_led(NUM_LED_FLASHES);
#ifdef ADABOOT
flash_led(ADABOOT_VER); // BBR 9/13/2008
#endif
/* forever loop */
for (;;)
{
/* get character from UART */
ch = getch();
/* A bunch of if...else if... gives smaller code than switch...case ! */
/* Hello is anyone home ? */
if(ch=='0')
nothing_response();
/* Request programmer ID */
/* Not using PROGMEM string due to boot block in m128 being beyond 64kB boundry */
/* Would need to selectively manipulate RAMPZ, and it's only 9 characters anyway so who cares. */
else if(ch=='1')
{
if (getch() == ' ')
{
putch(0x14);
putch('A');
putch('V');
putch('R');
putch(' ');
putch('I');
putch('S');
putch('P');
putch(0x10);
}
else
{
if (++error_count == MAX_ERROR_COUNT)
app_start();
}
}
/* AVR ISP/STK500 board commands DON'T CARE so default nothing_response */
else if(ch=='@')
{
ch2 = getch();
if (ch2 > 0x85)
getch();
nothing_response();
}
/* AVR ISP/STK500 board requests */
else if(ch=='A')
{
ch2 = getch();
if(ch2 == 0x80)
byte_response(HW_VER); // Hardware version
else if(ch2==0x81)
byte_response(SW_MAJOR); // Software major version
else if(ch2==0x82)
byte_response(SW_MINOR); // Software minor version
else if(ch2==0x98)
byte_response(0x03); // Unknown but seems to be required by avr studio 3.56
else
byte_response(0x00); // Covers various unnecessary responses we don't care about
}
/* Device Parameters DON'T CARE, DEVICE IS FIXED */
else if(ch=='B')
{
getNch(20);
nothing_response();
}
/* Parallel programming stuff DON'T CARE */
else if(ch=='E')
{
getNch(5);
nothing_response();
}
/* Enter programming mode */
else if(ch=='P')
{
nothing_response();
}
/* Leave programming mode */
else if(ch=='Q')
{
nothing_response();
#ifdef ADABOOT
// autoreset via watchdog (sneaky!) BBR/LF 9/13/2008
WDTCSR = _BV(WDE);
while (1); // 16 ms
#endif
}
/* Erase device, don't care as we will erase one page at a time anyway. */
else if(ch=='R')
{
nothing_response();
}
/* Set address, little endian. EEPROM in bytes, FLASH in words */
/* Perhaps extra address bytes may be added in future to support > 128kB FLASH. */
/* This might explain why little endian was used here, big endian used everywhere else. */
else if(ch=='U')
{
address.byte[0] = getch();
address.byte[1] = getch();
nothing_response();
}
/* Universal SPI programming command, disabled. Would be used for fuses and lock bits. */
else if(ch=='V')
{
getNch(4);
byte_response(0x00);
}
/* Write memory, length is big endian and is in bytes */
else if(ch=='d')
{
length.byte[1] = getch();
length.byte[0] = getch();
flags.eeprom = 0;
if (getch() == 'E')
flags.eeprom = 1;
for (i=0; i<PAGE_SIZE; i++)
buff[i] = 0;
for (w = 0; w < length.word; w++)
{
// Store data in buffer, can't keep up with serial data stream whilst programming pages
buff[w] = getch();
}
if (getch() == ' ')
{
if (flags.eeprom)
{
//Write to EEPROM one byte at a time
for(w=0;w<length.word;w++)
{
while(EECR & (1<<EEPE));
EEAR = (uint16_t)(void *)address.word;
EEDR = buff[w];
EECR |= (1<<EEMPE);
EECR |= (1<<EEPE);
address.word++;
}
}
else
{
//address * 2 -> byte location
address.word = address.word << 1;
//Even up an odd number of bytes
if ((length.byte[0] & 0x01))
length.word++;
// HACKME: EEPE used to be EEWE
//Wait for previous EEPROM writes to complete
//while(bit_is_set(EECR,EEPE));
while(EECR & (1<<EEPE));
asm volatile(
"clr r17 \n\t" //page_word_count
"lds r30,address \n\t" //Address of FLASH location (in bytes)
"lds r31,address+1 \n\t"
"ldi r28,lo8(buff) \n\t" //Start of buffer array in RAM
"ldi r29,hi8(buff) \n\t"
"lds r24,length \n\t" //Length of data to be written (in bytes)
"lds r25,length+1 \n\t"
"length_loop: \n\t" //Main loop, repeat for number of words in block
"cpi r17,0x00 \n\t" //If page_word_count=0 then erase page
"brne no_page_erase \n\t"
"wait_spm1: \n\t"
"lds r16,%0 \n\t" //Wait for previous spm to complete
"andi r16,1 \n\t"
"cpi r16,1 \n\t"
"breq wait_spm1 \n\t"
"ldi r16,0x03 \n\t" //Erase page pointed to by Z
"sts %0,r16 \n\t"
"spm \n\t"
"wait_spm2: \n\t"
"lds r16,%0 \n\t" //Wait for previous spm to complete
"andi r16,1 \n\t"
"cpi r16,1 \n\t"
"breq wait_spm2 \n\t"
"ldi r16,0x11 \n\t" //Re-enable RWW section
"sts %0,r16 \n\t"
"spm \n\t"
"no_page_erase: \n\t"
"ld r0,Y+ \n\t" //Write 2 bytes into page buffer
"ld r1,Y+ \n\t"
"wait_spm3: \n\t"
"lds r16,%0 \n\t" //Wait for previous spm to complete
"andi r16,1 \n\t"
"cpi r16,1 \n\t"
"breq wait_spm3 \n\t"
"ldi r16,0x01 \n\t" //Load r0,r1 into FLASH page buffer
"sts %0,r16 \n\t"
"spm \n\t"
"inc r17 \n\t" //page_word_count++
"cpi r17,%1 \n\t"
"brlo same_page \n\t" //Still same page in FLASH
"write_page: \n\t"
"clr r17 \n\t" //New page, write current one first
"wait_spm4: \n\t"
"lds r16,%0 \n\t" //Wait for previous spm to complete
"andi r16,1 \n\t"
"cpi r16,1 \n\t"
"breq wait_spm4 \n\t"
"ldi r16,0x05 \n\t" //Write page pointed to by Z
"sts %0,r16 \n\t"
"spm \n\t"
"wait_spm5: \n\t"
"lds r16,%0 \n\t" //Wait for previous spm to complete
"andi r16,1 \n\t"
"cpi r16,1 \n\t"
"breq wait_spm5 \n\t"
"ldi r16,0x11 \n\t" //Re-enable RWW section
"sts %0,r16 \n\t"
"spm \n\t"
"same_page: \n\t"
"adiw r30,2 \n\t" //Next word in FLASH
"sbiw r24,2 \n\t" //length-2
"breq final_write \n\t" //Finished
"rjmp length_loop \n\t"
"final_write: \n\t"
"cpi r17,0 \n\t"
"breq block_done \n\t"
"adiw r24,2 \n\t" //length+2, fool above check on length after short page write
"rjmp write_page \n\t"
"block_done: \n\t"
"clr __zero_reg__ \n\t" //restore zero register
: "=m" (SPMCSR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31"
);
}
putch(0x14);
putch(0x10);
}
else
{
if (++error_count == MAX_ERROR_COUNT)
app_start();
}
}
/* Read memory block mode, length is big endian. */
else if(ch=='t')
{
length.byte[1] = getch();
length.byte[0] = getch();
if (getch() == 'E')
flags.eeprom = 1;
else
{
flags.eeprom = 0;
address.word = address.word << 1; // address * 2 -> byte location
}
// Command terminator
if (getch() == ' ')
{
putch(0x14);
for (w=0; w<length.word; w++)
{
// Can handle odd and even lengths okay
if (flags.eeprom)
{
// Byte access EEPROM read
while(EECR & (1<<EEPE));
EEAR = (uint16_t)(void *)address.word;
EECR |= (1<<EERE);
putch(EEDR);
address.word++;
}
else
{
if (!flags.rampz)
putch(pgm_read_byte_near(address.word));
address.word++;
}
}
putch(0x10);
}
}
/* Get device signature bytes */
else if(ch=='u')
{
if (getch() == ' ')
{
putch(0x14);
putch(SIG1);
putch(SIG2);
putch(SIG3);
putch(0x10);
}
else
{
if (++error_count == MAX_ERROR_COUNT)
app_start();
}
}
/* Read oscillator calibration byte */
else if(ch=='v')
byte_response(0x00);
else if (++error_count == MAX_ERROR_COUNT)
app_start();
}
/* end of forever loop */
}
char gethex(void)
{
char ah,al;
ah = getch();
putch(ah);
al = getch();
putch(al);
if(ah >= 'a')
ah = ah - 'a' + 0x0a;
else if(ah >= '0')
ah -= '0';
if(al >= 'a')
al = al - 'a' + 0x0a;
else if(al >= '0')
al -= '0';
return (ah << 4) + al;
}
void puthex(char ch)
{
char ah,al;
ah = (ch & 0xf0) >> 4;
if(ah >= 0x0a)
ah = ah - 0x0a + 'a';
else
ah += '0';
al = (ch & 0x0f);
if(al >= 0x0a)
al = al - 0x0a + 'a';
else
al += '0';
putch(ah);
putch(al);
}
void putch(char ch)
{
while (!(UCSR0A & _BV(UDRE0)));
UDR0 = ch;
}
char getch(void)
{
uint32_t count = 0;
#ifdef ADABOOT
LED_PORT &= ~_BV(LED); // toggle LED to show activity - BBR/LF 10/3/2007 & 9/13/2008
#endif
while(!(UCSR0A & _BV(RXC0)))
{
/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
/* HACKME:: here is a good place to count times*/
count++;
if (count > MAX_TIME_COUNT)
app_start();
}
#ifdef ADABOOT
LED_PORT |= _BV(LED); // toggle LED to show activity - BBR/LF 10/3/2007 & 9/13/2008
#endif
return UDR0;
}
void getNch(uint8_t count)
{
uint8_t i;
for(i=0;i<count;i++)
{
while(!(UCSR0A & _BV(RXC0)));
UDR0;
}
}
void byte_response(uint8_t val)
{
if (getch() == ' ')
{
putch(0x14);
putch(val);
putch(0x10);
}
else
{
if (++error_count == MAX_ERROR_COUNT)
app_start();
}
}
void nothing_response(void)
{
if (getch() == ' ')
{
putch(0x14);
putch(0x10);
}
else
{
if (++error_count == MAX_ERROR_COUNT)
app_start();
}
}
#ifdef ADABOOT
void flash_led(uint8_t count)
{
/* flash onboard LED count times to signal entering of bootloader */
/* l needs to be volatile or the delay loops below might get */
/* optimized away if compiling with optimizations (DAM). */
volatile uint32_t l;
if (count == 0) {
count = ADABOOT;
}
int8_t i;
for (i = 0; i < count; ++i) {
LED_PORT |= _BV(LED); // LED on
for(l = 0; l < (F_CPU / 1000); ++l); // delay NGvalue was 1000 for both loops - BBR
LED_PORT &= ~_BV(LED); // LED off
for(l = 0; l < (F_CPU / 250); ++l); // delay asymmteric for ADA BOOT BBR
}
for(l = 0; l < (F_CPU / 100); ++l); // pause ADA BOOT BBR
}
#else
void flash_led(uint8_t count)
{
/* flash onboard LED three times to signal entering of bootloader */
/* l needs to be volatile or the delay loops below might get
optimized away if compiling with optimizations (DAM). */
volatile uint32_t l;
if (count == 0) {
count = 3;
}
int8_t i;
for (i = 0; i < count; ++i) {
LED_PORT |= _BV(LED);
for(l = 0; l < (F_CPU / 1000); ++l);
LED_PORT &= ~_BV(LED);
for(l = 0; l < (F_CPU / 1000); ++l);
}
}
#endif
/* end of file ATmegaBOOT.c */

View File

@ -0,0 +1,121 @@
:10F800000C943E7C0C945B7C0C945B7C0C945B7C39
:10F810000C945B7C0C945B7C0C945B7C0C945B7C0C
:10F820000C945B7C0C945B7C0C945B7C0C945B7CFC
:10F830000C945B7C0C945B7C0C945B7C0C945B7CEC
:10F840000C945B7C0C945B7C0C945B7C0C945B7CDC
:10F850000C945B7C0C945B7C0C945B7C0C945B7CCC
:10F860000C945B7C0C945B7C0C945B7C0C945B7CBC
:10F870000C945B7C0C945B7C0C945B7C11241FBE11
:10F88000CFEFD8E0DEBFCDBF11E0A0E0B1E0E6E60B
:10F89000FFEF02C005900D92A030B107D9F712E03A
:10F8A000A0E0B1E001C01D92A930B107E1F70E94CC
:10F8B000537D0C94B27F0C94007CCF93DF93CDB733
:10F8C000DEB724970FB6F894DEBF0FBECDBF8823F6
:10F8D00009F481E020E0482F55274115510509F42E
:10F8E0003DC0289A19821A821B821C820BC0898112
:10F8F0009A81AB81BC810196A11DB11D89839A8338
:10F90000AB83BC8389819A81AB81BC8180589E4343
:10F91000A040B04060F3289819821A821B821C8292
:10F920000BC089819A81AB81BC810196A11DB11D5B
:10F9300089839A83AB83BC8389819A81AB81BC81A3
:10F9400080509A4FA040B04060F32F5F822F9927DC
:10F9500087FD9095841795070CF4C3CF19821A82FE
:10F960001B821C8289819A81AB81BC818050914726
:10F97000A240B040A0F489819A81AB81BC810196FC
:10F98000A11DB11D89839A83AB83BC8389819A8130
:10F99000AB81BC8180509147A240B04060F3249677
:10F9A0000FB6F894DEBF0FBECDBFDF91CF910895A3
:10F9B000EF92FF920F931F93EE24FF248701289864
:10F9C0008091C00087FD17C00894E11CF11C011D47
:10F9D000111D81E0E81689E0F8068DE3080780E054
:10F9E000180770F3E0910001F091010109958091F1
:10F9F000C00087FFE9CF289A8091C600992787FD2C
:10FA000090951F910F91FF90EF900895982F8091FE
:10FA1000C00085FFFCCF9093C60008950E94D87C5B
:10FA2000803271F0809102018F5F809302018530F6
:10FA300009F00895E0910001F09101010995089500
:10FA400084E10E94067D80E10E94067D0895CF93A7
:10FA5000C82F0E94D87C803241F0809102018F5FD4
:10FA600080930201853081F40AC084E10E94067D02
:10FA70008C2F0E94067D80E10E94067D05C0E091EA
:10FA80000001F09101010995CF910895282F90E090
:10FA900007C08091C0008823E4F78091C6009F5F73
:10FAA0009217B8F30895CFEFD8E0DEBFCDBF0000C6
:10FAB00094B714BE809160008861809360001092BA
:10FAC000600091FF74C189E18093C4001092C50069
:10FAD00088E18093C10086E08093C2005098589AD4
:10FAE000209A83E00E945D7C81E00E945D7C0E9400
:10FAF000D87C8033B9F18133C1F1803409F456C028
:10FB0000813409F45CC0823409F46EC0853409F490
:10FB100071C0803539F1813509F4F3C0823511F1B6
:10FB2000853509F4D3C0863509F4CBC0843609F491
:10FB300065C0843709F4EBC0853709F4D2C0863735
:10FB400009F44AC0809102018F5F809302018530E1
:10FB500071F6E0910001F091010109950E94D87CB5
:10FB6000803349F60E940E7DC2CF0E94D87CC82FF8
:10FB7000803241F784E10E94067D81E40E94067D87
:10FB800086E50E94067D82E50E94067D8C2F0E94FC
:10FB9000067D89E40E94067D83E50E94067D80E55E
:10FBA0000E94067D80E10E94067DA1CF0E94D87C44
:10FBB0008638C0F20E94D87C0E940E7D98CF0E94A9
:10FBC000D87C803809F407C1813809F400C1823833
:10FBD00009F4F9C0883921F080E00E94277D87CFA1
:10FBE00083E00E94277D83CF84E10E94467D0E94AE
:10FBF0000E7D7DCF85E00E94467DF9CF0E94D87CA6
:10FC0000809306020E94D87C8093050280910802AE
:10FC10008E7F809308020E94D87C853409F44BC003
:10FC2000E5E0F1E0119281E0E438F807D9F3D0F390
:10FC3000C0E0D0E0809105029091060218161906E6
:10FC400078F405E011E00E94D87CF80181938F01DF
:10FC500021968091050290910602C817D90798F362
:10FC60000E94D87C803209F06DCF8091080280FF1D
:10FC7000B6C0C0E0D0E02091050230910602121615
:10FC80001306B8F4E0910301F0910401A5E0B1E09E
:10FC9000F999FECFF2BDE1BD8D9180BDFA9AF99A36
:10FCA00031962196C217D30798F3F0930401E0939D
:10FCB000030184E175CF809108028160809308027E
:10FCC000AFCF84E00E94467D80E087CF0E94D87C41
:10FCD000809303010E94D87C809304010E940E7DD2
:10FCE00006CF0E94D87C803209F02CCF84E10E949C
:10FCF000067D8EE10E94067D85E90E94067D88E0F2
:10FD00004FCF0E940E7D88E080936000FFCF0E945D
:10FD1000D87C809306020E94D87C809305020E94C2
:10FD2000D87C853409F449C0809108028E7F809385
:10FD300008028091030190910401880F991F90930C
:10FD40000401809303010E94D87C803209F0CFCE59
:10FD500084E10E94067DC0E0D0E020910502309150
:10FD600006021216130608F01DCFE0910301F09170
:10FD700004018091080280FF96C0F999FECFF2BD80
:10FD8000E1BDF89A80B50E94067DE0910301F091F3
:10FD900004013196F0930401E093030120910502E0
:10FDA000309106022196C217D30718F3FBCEE091DB
:10FDB0000001F0910101099586CE809108028160D1
:10FDC00080930802C0CF80E10E94277D90CE81E021
:10FDD0000E94277D8CCE82E00E94277D88CE809174
:10FDE000030190910401880F991F9093040180935F
:10FDF00003018091050280FF09C080910502909166
:10FE0000060201969093060280930502F999FECFAF
:10FE10001127E0910301F0910401C5E0D1E0809148
:10FE2000050290910602103091F400915700017084
:10FE30000130D9F303E000935700E8950091570093
:10FE400001700130D9F301E100935700E895099062
:10FE500019900091570001700130D9F301E000932F
:10FE60005700E8951395103898F011270091570026
:10FE700001700130D9F305E000935700E895009137
:10FE8000570001700130D9F301E100935700E89564
:10FE90003296029709F0C7CF103011F00296E5CFE5
:10FEA000112484E17DCE869580FF06C03196F093C3
:10FEB0000401E093030176CF84910E94067D209196
:10FEC000050230910602E0910301F0910401EECFAA
:10FED0001F93CF930E94D87CC82F0E94067D0E945A
:10FEE000D87C182F0E94067DC1362CF0C7551136DC
:10FEF0003CF0175508C0C033D4F3C0531136CCF7CB
:10FF000010330CF01053C295C07FC10F8C2F99276E
:10FF100087FD9095CF911F910895CF93282F992712
:10FF200087FD9095807F907095958795959587959D
:10FF300095958795959587958A303CF0895AC22F7B
:10FF4000CF70CA303CF0C95A06C0805DC22FCF7056
:10FF5000CA30CCF7C05D0E94067D8C2F0E94067DC2
:06FF6000CF910895FFCFD0
:040000030000F80001
:00000001FF

View File

@ -0,0 +1,120 @@
:10F800000C94387C0C94557C0C94557C0C94557C51
:10F810000C94557C0C94557C0C94557C0C94557C24
:10F820000C94557C0C94557C0C94557C0C94557C14
:10F830000C94557C0C94557C0C94557C0C94557C04
:10F840000C94557C0C94557C0C94557C0C94557CF4
:10F850000C94557C0C94557C0C94557C0C94557CE4
:10F860000C94557C0C94557C0C94557C0C94557CD4
:10F8700011241FBECFEFD0E1DEBFCDBF11E0A0E06D
:10F88000B1E0EAE5FFEF02C005900D92A030B107AC
:10F89000D9F712E0A0E0B1E001C01D92A930B10794
:10F8A000E1F70E944D7D0C94AC7F0C94007CCF93CB
:10F8B000DF93CDB7DEB724970FB6F894DEBF0FBE47
:10F8C000CDBF882309F481E020E0482F552741155A
:10F8D000510509F43DC0289A19821A821B821C82A4
:10F8E0000BC089819A81AB81BC810196A11DB11D9C
:10F8F00089839A83AB83BC8389819A81AB81BC81E4
:10F9000080589E43A040B04060F3289819821A8224
:10F910001B821C820BC089819A81AB81BC810196BC
:10F92000A11DB11D89839A83AB83BC8389819A8190
:10F93000AB81BC8180509A4FA040B04060F32F5FF4
:10F94000822F992787FD9095841795070CF4C3CFD4
:10F9500019821A821B821C8289819A81AB81BC81A7
:10F9600080509147A240B040A0F489819A81AB8138
:10F97000BC810196A11DB11D89839A83AB83BC8391
:10F9800089819A81AB81BC8180509147A240B0406F
:10F9900060F324960FB6F894DEBF0FBECDBFDF91A3
:10F9A000CF910895EF92FF920F931F93EE24FF24BF
:10F9B000870128988091C00087FD17C00894E11C3A
:10F9C000F11C011D111D81E0E81689E0F8068DE3A8
:10F9D000080780E0180770F3E0910001F091010141
:10F9E00009958091C00087FFE9CF289A8091C600D1
:10F9F000992787FD90951F910F91FF90EF900895A3
:10FA0000982F8091C00085FFFCCF9093C600089589
:10FA10000E94D27C803271F0809102018F5F8093CE
:10FA20000201853009F00895E0910001F091010193
:10FA30000995089584E10E94007D80E10E94007D87
:10FA40000895CF93C82F0E94D27C803241F08091DC
:10FA500002018F5F80930201853081F40AC084E146
:10FA60000E94007D8C2F0E94007D80E10E94007D1D
:10FA700005C0E0910001F09101010995CF91089531
:10FA8000282F90E007C08091C0008823E4F7809180
:10FA9000C6009F5F9217B8F30895CFEFD0E1DEBFA5
:10FAA000CDBF000094B714BE809160008861809340
:10FAB00060001092600091FF74C189E18093C400DE
:10FAC0001092C50088E18093C10086E08093C20057
:10FAD0005098589A209A83E00E94577C81E00E94B7
:10FAE000577C0E94D27C8033B9F18133C1F18034DC
:10FAF00009F456C0813409F45CC0823409F46EC044
:10FB0000853409F471C0803539F1813509F4F3C0C9
:10FB1000823511F1853509F4D3C0863509F4CBC09F
:10FB2000843609F465C0843709F4EBC0853709F4DD
:10FB3000D2C0863709F44AC0809102018F5F80935A
:10FB40000201853071F6E0910001F0910101099503
:10FB50000E94D27C803349F60E94087DC2CF0E9469
:10FB6000D27CC82F803241F784E10E94007D81E47D
:10FB70000E94007D86E50E94007D82E50E94007D56
:10FB80008C2F0E94007D89E40E94007D83E50E9405
:10FB9000007D80E50E94007D80E10E94007DA1CF74
:10FBA0000E94D27C8638C0F20E94D27C0E94087DDE
:10FBB00098CF0E94D27C803809F407C1813809F4BB
:10FBC00000C1823809F4F9C0883921F080E00E9430
:10FBD000217D87CF83E00E94217D83CF84E10E9435
:10FBE000407D0E94087D7DCF85E00E94407DF9CF59
:10FBF0000E94D27C809306020E94D27C80930502F0
:10FC0000809108028E7F809308020E94D27C853406
:10FC100009F44BC0E5E0F1E0119281E0E438F80727
:10FC2000D9F3D0F3C0E0D0E08091050290910602B4
:10FC30001816190678F405E011E00E94D27CF8014C
:10FC400081938F0121968091050290910602C81739
:10FC5000D90798F30E94D27C803209F06DCF809151
:10FC6000080280FFB6C0C0E0D0E0209105023091CC
:10FC7000060212161306B8F4E0910301F091040194
:10FC8000A5E0B1E0F999FECFF2BDE1BD8D9180BD57
:10FC9000FA9AF99A31962196C217D30798F3F093FE
:10FCA0000401E093030184E175CF80910802816033
:10FCB00080930802AFCF84E00E94407D80E087CF30
:10FCC0000E94D27C809303010E94D27C8093040125
:10FCD0000E94087D06CF0E94D27C803209F02CCF92
:10FCE00084E10E94007D8EE10E94007D86E90E94F1
:10FCF000007D89E04FCF0E94087D88E080936000FE
:10FD0000FFCF0E94D27C809306020E94D27C809317
:10FD100005020E94D27C853409F449C08091080212
:10FD20008E7F809308028091030190910401880FD7
:10FD3000991F90930401809303010E94D27C80322A
:10FD400009F0CFCE84E10E94007DC0E0D0E0209198
:10FD50000502309106021216130608F01DCFE0913D
:10FD60000301F09104018091080280FF96C0F99987
:10FD7000FECFF2BDE1BDF89A80B50E94007DE09112
:10FD80000301F09104013196F0930401E093030123
:10FD900020910502309106022196C217D30718F36D
:10FDA000FBCEE0910001F0910101099586CE809192
:10FDB0000802816080930802C0CF80E10E94217D0B
:10FDC00090CE81E00E94217D8CCE82E00E94217D38
:10FDD00088CE8091030190910401880F991F909320
:10FDE0000401809303018091050280FF09C0809186
:10FDF00005029091060201969093060280930502F7
:10FE0000F999FECF1127E0910301F0910401C5E0BB
:10FE1000D1E08091050290910602103091F400919A
:10FE2000570001700130D9F303E000935700E895C3
:10FE30000091570001700130D9F301E100935700A0
:10FE4000E895099019900091570001700130D9F39D
:10FE500001E000935700E8951395103898F01127AA
:10FE60000091570001700130D9F305E0009357006D
:10FE7000E8950091570001700130D9F301E100933A
:10FE80005700E8953296029709F0C7CF103011F06D
:10FE90000296E5CF112484E17DCE869580FF06C0D1
:10FEA0003196F0930401E093030176CF84910E9490
:10FEB000007D2091050230910602E0910301F0914E
:10FEC0000401EECF1F93CF930E94D27CC82F0E94D3
:10FED000007D0E94D27C182F0E94007DC1362CF03C
:10FEE000C75511363CF0175508C0C033D4F3C05382
:10FEF0001136CCF710330CF01053C295C07FC10FF0
:10FF00008C2F992787FD9095CF911F910895CF93BE
:10FF1000282F992787FD9095807F907095958795DC
:10FF20009595879595958795959587958A303CF019
:10FF3000895AC22FCF70CA303CF0C95A06C0805DC2
:10FF4000C22FCF70CA30CCF7C05D0E94007D8C2FCD
:0AFF50000E94007DCF910895FFCFBD
:040000030000F80001
:00000001FF

View File

@ -0,0 +1,121 @@
:10F800000C943E7C0C945B7C0C945B7C0C945B7C39
:10F810000C945B7C0C945B7C0C945B7C0C945B7C0C
:10F820000C945B7C0C945B7C0C945B7C0C945B7CFC
:10F830000C945B7C0C945B7C0C945B7C0C945B7CEC
:10F840000C945B7C0C945B7C0C945B7C0C945B7CDC
:10F850000C945B7C0C945B7C0C945B7C0C945B7CCC
:10F860000C945B7C0C945B7C0C945B7C0C945B7CBC
:10F870000C945B7C0C945B7C0C945B7C11241FBE11
:10F88000CFEFD0E1DEBFCDBF11E0A0E0B1E0E6E612
:10F89000FFEF02C005900D92A030B107D9F712E03A
:10F8A000A0E0B1E001C01D92A930B107E1F70E94CC
:10F8B000537D0C94B27F0C94007CCF93DF93CDB733
:10F8C000DEB724970FB6F894DEBF0FBECDBF8823F6
:10F8D00009F481E020E0482F55274115510509F42E
:10F8E0003DC0289A19821A821B821C820BC0898112
:10F8F0009A81AB81BC810196A11DB11D89839A8338
:10F90000AB83BC8389819A81AB81BC8180589E4343
:10F91000A040B04060F3289819821A821B821C8292
:10F920000BC089819A81AB81BC810196A11DB11D5B
:10F9300089839A83AB83BC8389819A81AB81BC81A3
:10F9400080509A4FA040B04060F32F5F822F9927DC
:10F9500087FD9095841795070CF4C3CF19821A82FE
:10F960001B821C8289819A81AB81BC818050914726
:10F97000A240B040A0F489819A81AB81BC810196FC
:10F98000A11DB11D89839A83AB83BC8389819A8130
:10F99000AB81BC8180509147A240B04060F3249677
:10F9A0000FB6F894DEBF0FBECDBFDF91CF910895A3
:10F9B000EF92FF920F931F93EE24FF248701289864
:10F9C0008091C00087FD17C00894E11CF11C011D47
:10F9D000111D81E0E81689E0F8068DE3080780E054
:10F9E000180770F3E0910001F091010109958091F1
:10F9F000C00087FFE9CF289A8091C600992787FD2C
:10FA000090951F910F91FF90EF900895982F8091FE
:10FA1000C00085FFFCCF9093C60008950E94D87C5B
:10FA2000803271F0809102018F5F809302018530F6
:10FA300009F00895E0910001F09101010995089500
:10FA400084E10E94067D80E10E94067D0895CF93A7
:10FA5000C82F0E94D87C803241F0809102018F5FD4
:10FA600080930201853081F40AC084E10E94067D02
:10FA70008C2F0E94067D80E10E94067D05C0E091EA
:10FA80000001F09101010995CF910895282F90E090
:10FA900007C08091C0008823E4F78091C6009F5F73
:10FAA0009217B8F30895CFEFD0E1DEBFCDBF0000CD
:10FAB00094B714BE809160008861809360001092BA
:10FAC000600091FF74C189E18093C4001092C50069
:10FAD00088E18093C10086E08093C2005098589AD4
:10FAE000209A83E00E945D7C81E00E945D7C0E9400
:10FAF000D87C8033B9F18133C1F1803409F456C028
:10FB0000813409F45CC0823409F46EC0853409F490
:10FB100071C0803539F1813509F4F3C0823511F1B6
:10FB2000853509F4D3C0863509F4CBC0843609F491
:10FB300065C0843709F4EBC0853709F4D2C0863735
:10FB400009F44AC0809102018F5F809302018530E1
:10FB500071F6E0910001F091010109950E94D87CB5
:10FB6000803349F60E940E7DC2CF0E94D87CC82FF8
:10FB7000803241F784E10E94067D81E40E94067D87
:10FB800086E50E94067D82E50E94067D8C2F0E94FC
:10FB9000067D89E40E94067D83E50E94067D80E55E
:10FBA0000E94067D80E10E94067DA1CF0E94D87C44
:10FBB0008638C0F20E94D87C0E940E7D98CF0E94A9
:10FBC000D87C803809F407C1813809F400C1823833
:10FBD00009F4F9C0883921F080E00E94277D87CFA1
:10FBE00083E00E94277D83CF84E10E94467D0E94AE
:10FBF0000E7D7DCF85E00E94467DF9CF0E94D87CA6
:10FC0000809306020E94D87C8093050280910802AE
:10FC10008E7F809308020E94D87C853409F44BC003
:10FC2000E5E0F1E0119281E0E438F807D9F3D0F390
:10FC3000C0E0D0E0809105029091060218161906E6
:10FC400078F405E011E00E94D87CF80181938F01DF
:10FC500021968091050290910602C817D90798F362
:10FC60000E94D87C803209F06DCF8091080280FF1D
:10FC7000B6C0C0E0D0E02091050230910602121615
:10FC80001306B8F4E0910301F0910401A5E0B1E09E
:10FC9000F999FECFF2BDE1BD8D9180BDFA9AF99A36
:10FCA00031962196C217D30798F3F0930401E0939D
:10FCB000030184E175CF809108028160809308027E
:10FCC000AFCF84E00E94467D80E087CF0E94D87C41
:10FCD000809303010E94D87C809304010E940E7DD2
:10FCE00006CF0E94D87C803209F02CCF84E10E949C
:10FCF000067D8EE10E94067D86E90E94067D8AE0EF
:10FD00004FCF0E940E7D88E080936000FFCF0E945D
:10FD1000D87C809306020E94D87C809305020E94C2
:10FD2000D87C853409F449C0809108028E7F809385
:10FD300008028091030190910401880F991F90930C
:10FD40000401809303010E94D87C803209F0CFCE59
:10FD500084E10E94067DC0E0D0E020910502309150
:10FD600006021216130608F01DCFE0910301F09170
:10FD700004018091080280FF96C0F999FECFF2BD80
:10FD8000E1BDF89A80B50E94067DE0910301F091F3
:10FD900004013196F0930401E093030120910502E0
:10FDA000309106022196C217D30718F3FBCEE091DB
:10FDB0000001F0910101099586CE809108028160D1
:10FDC00080930802C0CF80E10E94277D90CE81E021
:10FDD0000E94277D8CCE82E00E94277D88CE809174
:10FDE000030190910401880F991F9093040180935F
:10FDF00003018091050280FF09C080910502909166
:10FE0000060201969093060280930502F999FECFAF
:10FE10001127E0910301F0910401C5E0D1E0809148
:10FE2000050290910602103091F400915700017084
:10FE30000130D9F303E000935700E8950091570093
:10FE400001700130D9F301E100935700E895099062
:10FE500019900091570001700130D9F301E000932F
:10FE60005700E8951395103898F011270091570026
:10FE700001700130D9F305E000935700E895009137
:10FE8000570001700130D9F301E100935700E89564
:10FE90003296029709F0C7CF103011F00296E5CFE5
:10FEA000112484E17DCE869580FF06C03196F093C3
:10FEB0000401E093030176CF84910E94067D209196
:10FEC000050230910602E0910301F0910401EECFAA
:10FED0001F93CF930E94D87CC82F0E94067D0E945A
:10FEE000D87C182F0E94067DC1362CF0C7551136DC
:10FEF0003CF0175508C0C033D4F3C0531136CCF7CB
:10FF000010330CF01053C295C07FC10F8C2F99276E
:10FF100087FD9095CF911F910895CF93282F992712
:10FF200087FD9095807F907095958795959587959D
:10FF300095958795959587958A303CF0895AC22F7B
:10FF4000CF70CA303CF0C95A06C0805DC22FCF7056
:10FF5000CA30CCF7C05D0E94067D8C2F0E94067DC2
:06FF6000CF910895FFCFD0
:040000030000F80001
:00000001FF

View File

@ -0,0 +1,56 @@
# Makefile for ATmegaBOOT
# E.Lins, 18.7.2005
# $Id$
# program name should not be changed...
PROGRAM = ATmegaBOOT_644P
# enter the target CPU frequency
AVR_FREQ = 16000000L
MCU_TARGET = atmega644p
LDSECTION = --section-start=.text=0xF800
OBJ = $(PROGRAM).o
OPTIMIZE = -O2
DEFS =
LIBS =
CC = avr-gcc
# Override is only needed by avr-lib build system.
override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(AVR_FREQ) $(DEFS)
override LDFLAGS = -Wl,$(LDSECTION)
#override LDFLAGS = -Wl,-Map,$(PROGRAM).map,$(LDSECTION)
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
all: CFLAGS += '-DMAX_TIME_COUNT=8000000L>>1' -DADABOOT
all: $(PROGRAM).hex
$(PROGRAM).hex: $(PROGRAM).elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
$(PROGRAM).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
$(OBJ): ATmegaBOOT.c
avr-gcc $(CFLAGS) $(LDFLAGS) -c -g -O2 -Wall -mmcu=$(MCU_TARGET) ATmegaBOOT.c -o $(PROGRAM).o
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
%.srec: %.elf
$(OBJCOPY) -j .text -j .data -O srec $< $@
%.bin: %.elf
$(OBJCOPY) -j .text -j .data -O binary $< $@
clean:
rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex

View File

@ -0,0 +1,3 @@
Note: This bootloader support ATmega644, ATmega644P and ATmega324P.
To build, set PROGRAM and MCU_TARGET in the Makefile according to your target device.

View File

@ -0,0 +1 @@
#include "WProgram.h"

View File

@ -0,0 +1,202 @@
/*
HardwareSerial.cpp - Hardware serial library for Wiring
Copyright (c) 2006 Nicholas Zambetti. 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
Modified 23 November 2006 by David A. Mellis
Modified 28 September 2010 by Mark Sproul
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "wiring.h"
#include "wiring_private.h"
// this next line disables the entire HardwareSerial.cpp,
// this is so I can support Attiny series and any other chip without a uart
#if defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H)
#include "HardwareSerial.h"
// Define constants and variables for buffering incoming serial data. We're
// using a ring buffer (I think), in which rx_buffer_head is the index of the
// location to which to write the next incoming character and rx_buffer_tail
// is the index of the location from which to read.
#define RX_BUFFER_SIZE 128
struct ring_buffer
{
unsigned char buffer[RX_BUFFER_SIZE];
int head;
int tail;
};
ring_buffer rx_buffer = { { 0 }, 0, 0 };
inline void store_char(unsigned char c, ring_buffer *rx_buffer)
{
int i = (unsigned int)(rx_buffer->head + 1) & (RX_BUFFER_SIZE -1);
// if we should be storing the received character into the location
// just before the tail (meaning that the head would advance to the
// current location of the tail), we're about to overflow the buffer
// and so we don't write the character or advance the head.
if (i != rx_buffer->tail) {
rx_buffer->buffer[rx_buffer->head] = c;
rx_buffer->head = i;
}
}
// fixed by Mark Sproul this is on the 644/644p
//SIGNAL(SIG_USART_RECV)
SIGNAL(USART0_RX_vect)
{
unsigned char c = UDR0;
store_char(c, &rx_buffer);
}
// Constructors ////////////////////////////////////////////////////////////////
HardwareSerial::HardwareSerial(ring_buffer *rx_buffer,
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
volatile uint8_t *udr,
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x)
{
_rx_buffer = rx_buffer;
_ubrrh = ubrrh;
_ubrrl = ubrrl;
_ucsra = ucsra;
_ucsrb = ucsrb;
_udr = udr;
_rxen = rxen;
_txen = txen;
_rxcie = rxcie;
_udre = udre;
_u2x = u2x;
}
// Public Methods //////////////////////////////////////////////////////////////
void HardwareSerial::begin(long baud)
{
uint16_t baud_setting;
bool use_u2x = true;
#if F_CPU == 16000000UL
// hardcoded exception for compatibility with the bootloader shipped
// with the Duemilanove and previous boards and the firmware on the 8U2
// on the Uno and Mega 2560.
if (baud == 57600) {
use_u2x = false;
}
#endif
if (use_u2x) {
*_ucsra = 1 << _u2x;
baud_setting = (F_CPU / 4 / baud - 1) / 2;
} else {
*_ucsra = 0;
baud_setting = (F_CPU / 8 / baud - 1) / 2;
}
// assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
*_ubrrh = baud_setting >> 8;
*_ubrrl = baud_setting;
sbi(*_ucsrb, _rxen);
sbi(*_ucsrb, _txen);
sbi(*_ucsrb, _rxcie);
}
void HardwareSerial::end()
{
cbi(*_ucsrb, _rxen);
cbi(*_ucsrb, _txen);
cbi(*_ucsrb, _rxcie);
}
int HardwareSerial::available(void)
{
return (unsigned int)(RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) & (RX_BUFFER_SIZE-1);
}
int HardwareSerial::peek(void)
{
if (_rx_buffer->head == _rx_buffer->tail) {
return -1;
} else {
return _rx_buffer->buffer[_rx_buffer->tail];
}
}
int HardwareSerial::read(void)
{
// if the head isn't ahead of the tail, we don't have any characters
if (_rx_buffer->head == _rx_buffer->tail) {
return -1;
} else {
unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
_rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) & (RX_BUFFER_SIZE-1);
return c;
}
}
void HardwareSerial::flush()
{
// don't reverse this or there may be problems if the RX interrupt
// occurs after reading the value of rx_buffer_head but before writing
// the value to rx_buffer_tail; the previous value of rx_buffer_head
// may be written to rx_buffer_tail, making it appear as if the buffer
// don't reverse this or there may be problems if the RX interrupt
// occurs after reading the value of rx_buffer_head but before writing
// the value to rx_buffer_tail; the previous value of rx_buffer_head
// may be written to rx_buffer_tail, making it appear as if the buffer
// were full, not empty.
_rx_buffer->head = _rx_buffer->tail;
}
//
// Drakelive 2012-09-04
//
#if ARDUINO >= 100
size_t HardwareSerial::write(uint8_t c)
{
while (!((*_ucsra) & (1 << _udre)))
;
*_udr = c;
}
#else
void HardwareSerial::write(uint8_t c)
{
while (!((*_ucsra) & (1 << _udre)))
;
*_udr = c;
}
#endif
// Drakelive 2012-09-04
// Preinstantiate Objects //////////////////////////////////////////////////////
HardwareSerial Serial(&rx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0);
#endif // whole file

View File

@ -0,0 +1,87 @@
/*
HardwareSerial.h - Hardware serial library for Wiring
Copyright (c) 2006 Nicholas Zambetti. 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
Modified 28 September 2010 by Mark Sproul
*/
#ifndef HardwareSerial_h
#define HardwareSerial_h
#include <inttypes.h>
#include "Stream.h"
struct ring_buffer;
class HardwareSerial : public Stream
{
private:
ring_buffer *_rx_buffer;
volatile uint8_t *_ubrrh;
volatile uint8_t *_ubrrl;
volatile uint8_t *_ucsra;
volatile uint8_t *_ucsrb;
volatile uint8_t *_udr;
uint8_t _rxen;
uint8_t _txen;
uint8_t _rxcie;
uint8_t _udre;
uint8_t _u2x;
public:
HardwareSerial(ring_buffer *rx_buffer,
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
volatile uint8_t *udr,
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x);
void begin(long);
void end();
virtual int available(void);
virtual int peek(void);
virtual int read(void);
virtual void flush(void);
//
// Drakelive 2012-09-04
//
#if ARDUINO >= 100
virtual size_t write(uint8_t);
#else
virtual void write(uint8_t);
#endif
// Drakelive 2012-09-04
using Print::write; // pull in write(str) and write(buf, size) from Print
};
#if defined(UBRRH) || defined(UBRR0H)
extern HardwareSerial Serial;
#elif defined(USBCON)
#include "usb_api.h"
#endif
#if defined(UBRR1H)
extern HardwareSerial Serial1;
#endif
#if defined(UBRR2H)
extern HardwareSerial Serial2;
#endif
#if defined(UBRR3H)
extern HardwareSerial Serial3;
#endif
#endif

View File

@ -0,0 +1,220 @@
/*
Print.cpp - Base class that provides print() and println()
Copyright (c) 2008 David A. Mellis. 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
Modified 23 November 2006 by David A. Mellis
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "wiring.h"
#include "Print.h"
// Public Methods //////////////////////////////////////////////////////////////
/* default implementation: may be overridden */
void Print::write(const char *str)
{
while (*str)
write(*str++);
}
/* default implementation: may be overridden */
void Print::write(const uint8_t *buffer, size_t size)
{
while (size--)
write(*buffer++);
}
void Print::print(const String &s)
{
for (int i = 0; i < s.length(); i++) {
write(s[i]);
}
}
void Print::print(const char str[])
{
write(str);
}
void Print::print(char c, int base)
{
print((long) c, base);
}
void Print::print(unsigned char b, int base)
{
print((unsigned long) b, base);
}
void Print::print(int n, int base)
{
print((long) n, base);
}
void Print::print(unsigned int n, int base)
{
print((unsigned long) n, base);
}
void Print::print(long n, int base)
{
if (base == 0) {
write(n);
} else if (base == 10) {
if (n < 0) {
print('-');
n = -n;
}
printNumber(n, 10);
} else {
printNumber(n, base);
}
}
void Print::print(unsigned long n, int base)
{
if (base == 0) write(n);
else printNumber(n, base);
}
void Print::print(double n, int digits)
{
printFloat(n, digits);
}
void Print::println(void)
{
print('\r');
print('\n');
}
void Print::println(const String &s)
{
print(s);
println();
}
void Print::println(const char c[])
{
print(c);
println();
}
void Print::println(char c, int base)
{
print(c, base);
println();
}
void Print::println(unsigned char b, int base)
{
print(b, base);
println();
}
void Print::println(int n, int base)
{
print(n, base);
println();
}
void Print::println(unsigned int n, int base)
{
print(n, base);
println();
}
void Print::println(long n, int base)
{
print(n, base);
println();
}
void Print::println(unsigned long n, int base)
{
print(n, base);
println();
}
void Print::println(double n, int digits)
{
print(n, digits);
println();
}
// Private Methods /////////////////////////////////////////////////////////////
void Print::printNumber(unsigned long n, uint8_t base)
{
unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars.
unsigned long i = 0;
if (n == 0) {
print('0');
return;
}
while (n > 0) {
buf[i++] = n % base;
n /= base;
}
for (; i > 0; i--)
print((char) (buf[i - 1] < 10 ?
'0' + buf[i - 1] :
'A' + buf[i - 1] - 10));
}
void Print::printFloat(double number, uint8_t digits)
{
// Handle negative numbers
if (number < 0.0)
{
print('-');
number = -number;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i)
rounding /= 10.0;
number += rounding;
// Extract the integer part of the number and print it
unsigned long int_part = (unsigned long)number;
double remainder = number - (double)int_part;
print(int_part);
// Print the decimal point, but only if there are digits beyond
if (digits > 0)
print(".");
// Extract digits from the remainder one at a time
while (digits-- > 0)
{
remainder *= 10.0;
int toPrint = int(remainder);
print(toPrint);
remainder -= toPrint;
}
}

View File

@ -0,0 +1,77 @@
/*
Print.h - Base class that provides print() and println()
Copyright (c) 2008 David A. Mellis. 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 Print_h
#define Print_h
#include <inttypes.h>
#include <stdio.h> // for size_t
#include "WString.h"
#define DEC 10
#define HEX 16
#define OCT 8
#define BIN 2
#define BYTE 0
class Print
{
private:
void printNumber(unsigned long, uint8_t);
void printFloat(double, uint8_t);
public:
//
// Drakelive 2012-09-04
//
#if ARDUINO >= 100
virtual size_t write(uint8_t) = 0;
#else
virtual void write(uint8_t) = 0;
#endif
// Drakelive 2012-09-04
virtual void write(const char *str);
virtual void write(const uint8_t *buffer, size_t size);
void print(const String &);
void print(const char[]);
void print(char, int = BYTE);
void print(unsigned char, int = BYTE);
void print(int, int = DEC);
void print(unsigned int, int = DEC);
void print(long, int = DEC);
void print(unsigned long, int = DEC);
void print(double, int = 2);
void println(const String &s);
void println(const char[]);
void println(char, int = BYTE);
void println(unsigned char, int = BYTE);
void println(int, int = DEC);
void println(unsigned int, int = DEC);
void println(long, int = DEC);
void println(unsigned long, int = DEC);
void println(double, int = 2);
void println(void);
};
#endif

View File

@ -0,0 +1,35 @@
/*
Stream.h - base class for character-based streams.
Copyright (c) 2010 David A. Mellis. 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 Stream_h
#define Stream_h
#include <inttypes.h>
#include "Print.h"
class Stream : public Print
{
public:
virtual int available() = 0;
virtual int read() = 0;
virtual int peek() = 0;
virtual void flush() = 0;
};
#endif

View File

@ -0,0 +1,601 @@
/* Tone.cpp
A Tone Generator Library
Written by Brett Hagman
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
Version Modified By Date Comments
------- ----------- -------- --------
0001 B Hagman 09/08/02 Initial coding
0002 B Hagman 09/08/18 Multiple pins
0003 B Hagman 09/08/18 Moved initialization from constructor to begin()
0004 B Hagman 09/09/26 Fixed problems with ATmega8
0005 B Hagman 09/11/23 Scanned prescalars for best fit on 8 bit timers
09/11/25 Changed pin toggle method to XOR
09/11/25 Fixed timer0 from being excluded
0006 D Mellis 09/12/29 Replaced objects with functions
0007 M Sproul 10/08/29 Changed #ifdefs from cpu to register
*************************************************/
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "wiring.h"
#include "pins_arduino.h"
#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega128__)
#define TCCR2A TCCR2
#define TCCR2B TCCR2
#define COM2A1 COM21
#define COM2A0 COM20
#define OCR2A OCR2
#define TIMSK2 TIMSK
#define OCIE2A OCIE2
#define TIMER2_COMPA_vect TIMER2_COMP_vect
#define TIMSK1 TIMSK
#endif
// timerx_toggle_count:
// > 0 - duration specified
// = 0 - stopped
// < 0 - infinitely (until stop() method called, or new play() called)
#if !defined(__AVR_ATmega8__)
volatile long timer0_toggle_count;
volatile uint8_t *timer0_pin_port;
volatile uint8_t timer0_pin_mask;
#endif
volatile long timer1_toggle_count;
volatile uint8_t *timer1_pin_port;
volatile uint8_t timer1_pin_mask;
volatile long timer2_toggle_count;
volatile uint8_t *timer2_pin_port;
volatile uint8_t timer2_pin_mask;
#if defined(TIMSK3)
volatile long timer3_toggle_count;
volatile uint8_t *timer3_pin_port;
volatile uint8_t timer3_pin_mask;
#endif
#if defined(TIMSK4)
volatile long timer4_toggle_count;
volatile uint8_t *timer4_pin_port;
volatile uint8_t timer4_pin_mask;
#endif
#if defined(TIMSK5)
volatile long timer5_toggle_count;
volatile uint8_t *timer5_pin_port;
volatile uint8_t timer5_pin_mask;
#endif
// MLS: This does not make sense, the 3 options are the same
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define AVAILABLE_TONE_PINS 1
const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 3, 4, 5, 1, 0 */ };
static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255, 255, 255, 255, 255 */ };
#elif defined(__AVR_ATmega8__)
#define AVAILABLE_TONE_PINS 1
const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 1 */ };
static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255 */ };
#else
#define AVAILABLE_TONE_PINS 1
// Leave timer 0 to last.
const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 1, 0 */ };
static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255, 255 */ };
#endif
static int8_t toneBegin(uint8_t _pin)
{
int8_t _timer = -1;
// if we're already using the pin, the timer should be configured.
for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
if (tone_pins[i] == _pin) {
return pgm_read_byte(tone_pin_to_timer_PGM + i);
}
}
// search for an unused timer.
for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
if (tone_pins[i] == 255) {
tone_pins[i] = _pin;
_timer = pgm_read_byte(tone_pin_to_timer_PGM + i);
break;
}
}
if (_timer != -1)
{
// Set timer specific stuff
// All timers in CTC mode
// 8 bit timers will require changing prescalar values,
// whereas 16 bit timers are set to either ck/1 or ck/64 prescalar
switch (_timer)
{
#if defined(TCCR0A) && defined(TCCR0B)
case 0:
// 8 bit timer
TCCR0A = 0;
TCCR0B = 0;
bitWrite(TCCR0A, WGM01, 1);
bitWrite(TCCR0B, CS00, 1);
timer0_pin_port = portOutputRegister(digitalPinToPort(_pin));
timer0_pin_mask = digitalPinToBitMask(_pin);
break;
#endif
#if defined(TCCR1A) && defined(TCCR1B) && defined(WGM12)
case 1:
// 16 bit timer
TCCR1A = 0;
TCCR1B = 0;
bitWrite(TCCR1B, WGM12, 1);
bitWrite(TCCR1B, CS10, 1);
timer1_pin_port = portOutputRegister(digitalPinToPort(_pin));
timer1_pin_mask = digitalPinToBitMask(_pin);
break;
#endif
#if defined(TCCR2A) && defined(TCCR2B)
case 2:
// 8 bit timer
TCCR2A = 0;
TCCR2B = 0;
bitWrite(TCCR2A, WGM21, 1);
bitWrite(TCCR2B, CS20, 1);
timer2_pin_port = portOutputRegister(digitalPinToPort(_pin));
timer2_pin_mask = digitalPinToBitMask(_pin);
break;
#endif
#if defined(TCCR3A) && defined(TCCR3B) && defined(TIMSK3)
case 3:
// 16 bit timer
TCCR3A = 0;
TCCR3B = 0;
bitWrite(TCCR3B, WGM32, 1);
bitWrite(TCCR3B, CS30, 1);
timer3_pin_port = portOutputRegister(digitalPinToPort(_pin));
timer3_pin_mask = digitalPinToBitMask(_pin);
break;
#endif
#if defined(TCCR4A) && defined(TCCR4B) && defined(TIMSK4)
case 4:
// 16 bit timer
TCCR4A = 0;
TCCR4B = 0;
#if defined(WGM42)
bitWrite(TCCR4B, WGM42, 1);
#elif defined(CS43)
#warning this may not be correct
// atmega32u4
bitWrite(TCCR4B, CS43, 1);
#endif
bitWrite(TCCR4B, CS40, 1);
timer4_pin_port = portOutputRegister(digitalPinToPort(_pin));
timer4_pin_mask = digitalPinToBitMask(_pin);
break;
#endif
#if defined(TCCR5A) && defined(TCCR5B) && defined(TIMSK5)
case 5:
// 16 bit timer
TCCR5A = 0;
TCCR5B = 0;
bitWrite(TCCR5B, WGM52, 1);
bitWrite(TCCR5B, CS50, 1);
timer5_pin_port = portOutputRegister(digitalPinToPort(_pin));
timer5_pin_mask = digitalPinToBitMask(_pin);
break;
#endif
}
}
return _timer;
}
// frequency (in hertz) and duration (in milliseconds).
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
{
uint8_t prescalarbits = 0b001;
long toggle_count = 0;
uint32_t ocr = 0;
int8_t _timer;
_timer = toneBegin(_pin);
if (_timer >= 0)
{
// Set the pinMode as OUTPUT
pinMode(_pin, OUTPUT);
// if we are using an 8 bit timer, scan through prescalars to find the best fit
if (_timer == 0 || _timer == 2)
{
ocr = F_CPU / frequency / 2 - 1;
prescalarbits = 0b001; // ck/1: same for both timers
if (ocr > 255)
{
ocr = F_CPU / frequency / 2 / 8 - 1;
prescalarbits = 0b010; // ck/8: same for both timers
if (_timer == 2 && ocr > 255)
{
ocr = F_CPU / frequency / 2 / 32 - 1;
prescalarbits = 0b011;
}
if (ocr > 255)
{
ocr = F_CPU / frequency / 2 / 64 - 1;
prescalarbits = _timer == 0 ? 0b011 : 0b100;
if (_timer == 2 && ocr > 255)
{
ocr = F_CPU / frequency / 2 / 128 - 1;
prescalarbits = 0b101;
}
if (ocr > 255)
{
ocr = F_CPU / frequency / 2 / 256 - 1;
prescalarbits = _timer == 0 ? 0b100 : 0b110;
if (ocr > 255)
{
// can't do any better than /1024
ocr = F_CPU / frequency / 2 / 1024 - 1;
prescalarbits = _timer == 0 ? 0b101 : 0b111;
}
}
}
}
#if defined(TCCR0B)
if (_timer == 0)
{
TCCR0B = prescalarbits;
}
else
#endif
#if defined(TCCR2B)
{
TCCR2B = prescalarbits;
}
#else
{
// dummy place holder to make the above ifdefs work
}
#endif
}
else
{
// two choices for the 16 bit timers: ck/1 or ck/64
ocr = F_CPU / frequency / 2 - 1;
prescalarbits = 0b001;
if (ocr > 0xffff)
{
ocr = F_CPU / frequency / 2 / 64 - 1;
prescalarbits = 0b011;
}
if (_timer == 1)
{
#if defined(TCCR1B)
TCCR1B = (TCCR1B & 0b11111000) | prescalarbits;
#endif
}
#if defined(TCCR3B)
else if (_timer == 3)
TCCR3B = (TCCR3B & 0b11111000) | prescalarbits;
#endif
#if defined(TCCR4B)
else if (_timer == 4)
TCCR4B = (TCCR4B & 0b11111000) | prescalarbits;
#endif
#if defined(TCCR5B)
else if (_timer == 5)
TCCR5B = (TCCR5B & 0b11111000) | prescalarbits;
#endif
}
// Calculate the toggle count
if (duration > 0)
{
toggle_count = 2 * frequency * duration / 1000;
}
else
{
toggle_count = -1;
}
// Set the OCR for the given timer,
// set the toggle count,
// then turn on the interrupts
switch (_timer)
{
#if defined(OCR0A) && defined(TIMSK0) && defined(OCIE0A)
case 0:
OCR0A = ocr;
timer0_toggle_count = toggle_count;
bitWrite(TIMSK0, OCIE0A, 1);
break;
#endif
case 1:
#if defined(OCR1A) && defined(TIMSK1) && defined(OCIE1A)
OCR1A = ocr;
timer1_toggle_count = toggle_count;
bitWrite(TIMSK1, OCIE1A, 1);
#elif defined(OCR1A) && defined(TIMSK) && defined(OCIE1A)
// this combination is for at least the ATmega32
OCR1A = ocr;
timer1_toggle_count = toggle_count;
bitWrite(TIMSK, OCIE1A, 1);
#endif
break;
#if defined(OCR2A) && defined(TIMSK2) && defined(OCIE2A)
case 2:
OCR2A = ocr;
timer2_toggle_count = toggle_count;
bitWrite(TIMSK2, OCIE2A, 1);
break;
#endif
#if defined(TIMSK3)
case 3:
OCR3A = ocr;
timer3_toggle_count = toggle_count;
bitWrite(TIMSK3, OCIE3A, 1);
break;
#endif
#if defined(TIMSK4)
case 4:
OCR4A = ocr;
timer4_toggle_count = toggle_count;
bitWrite(TIMSK4, OCIE4A, 1);
break;
#endif
#if defined(OCR5A) && defined(TIMSK5) && defined(OCIE5A)
case 5:
OCR5A = ocr;
timer5_toggle_count = toggle_count;
bitWrite(TIMSK5, OCIE5A, 1);
break;
#endif
}
}
}
// XXX: this function only works properly for timer 2 (the only one we use
// currently). for the others, it should end the tone, but won't restore
// proper PWM functionality for the timer.
void disableTimer(uint8_t _timer)
{
switch (_timer)
{
case 0:
#if defined(TIMSK0)
TIMSK0 = 0;
#elif defined(TIMSK)
TIMSK = 0; // atmega32
#endif
break;
#if defined(TIMSK1) && defined(OCIE1A)
case 1:
bitWrite(TIMSK1, OCIE1A, 0);
break;
#endif
case 2:
#if defined(TIMSK2) && defined(OCIE2A)
bitWrite(TIMSK2, OCIE2A, 0); // disable interrupt
#endif
#if defined(TCCR2A) && defined(WGM20)
TCCR2A = (1 << WGM20);
#endif
#if defined(TCCR2B) && defined(CS22)
TCCR2B = (TCCR2B & 0b11111000) | (1 << CS22);
#endif
#if defined(OCR2A)
OCR2A = 0;
#endif
break;
#if defined(TIMSK3)
case 3:
TIMSK3 = 0;
break;
#endif
#if defined(TIMSK4)
case 4:
TIMSK4 = 0;
break;
#endif
#if defined(TIMSK5)
case 5:
TIMSK5 = 0;
break;
#endif
}
}
void noTone(uint8_t _pin)
{
int8_t _timer = -1;
for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
if (tone_pins[i] == _pin) {
_timer = pgm_read_byte(tone_pin_to_timer_PGM + i);
tone_pins[i] = 255;
}
}
disableTimer(_timer);
digitalWrite(_pin, 0);
}
#if 0
#if !defined(__AVR_ATmega8__)
ISR(TIMER0_COMPA_vect)
{
if (timer0_toggle_count != 0)
{
// toggle the pin
*timer0_pin_port ^= timer0_pin_mask;
if (timer0_toggle_count > 0)
timer0_toggle_count--;
}
else
{
disableTimer(0);
*timer0_pin_port &= ~(timer0_pin_mask); // keep pin low after stop
}
}
#endif
ISR(TIMER1_COMPA_vect)
{
if (timer1_toggle_count != 0)
{
// toggle the pin
*timer1_pin_port ^= timer1_pin_mask;
if (timer1_toggle_count > 0)
timer1_toggle_count--;
}
else
{
disableTimer(1);
*timer1_pin_port &= ~(timer1_pin_mask); // keep pin low after stop
}
}
#endif
ISR(TIMER2_COMPA_vect)
{
if (timer2_toggle_count != 0)
{
// toggle the pin
*timer2_pin_port ^= timer2_pin_mask;
if (timer2_toggle_count > 0)
timer2_toggle_count--;
}
else
{
// need to call noTone() so that the tone_pins[] entry is reset, so the
// timer gets initialized next time we call tone().
// XXX: this assumes timer 2 is always the first one used.
noTone(tone_pins[0]);
// disableTimer(2);
// *timer2_pin_port &= ~(timer2_pin_mask); // keep pin low after stop
}
}
//#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#if 0
ISR(TIMER3_COMPA_vect)
{
if (timer3_toggle_count != 0)
{
// toggle the pin
*timer3_pin_port ^= timer3_pin_mask;
if (timer3_toggle_count > 0)
timer3_toggle_count--;
}
else
{
disableTimer(3);
*timer3_pin_port &= ~(timer3_pin_mask); // keep pin low after stop
}
}
ISR(TIMER4_COMPA_vect)
{
if (timer4_toggle_count != 0)
{
// toggle the pin
*timer4_pin_port ^= timer4_pin_mask;
if (timer4_toggle_count > 0)
timer4_toggle_count--;
}
else
{
disableTimer(4);
*timer4_pin_port &= ~(timer4_pin_mask); // keep pin low after stop
}
}
ISR(TIMER5_COMPA_vect)
{
if (timer5_toggle_count != 0)
{
// toggle the pin
*timer5_pin_port ^= timer5_pin_mask;
if (timer5_toggle_count > 0)
timer5_toggle_count--;
}
else
{
disableTimer(5);
*timer5_pin_port &= ~(timer5_pin_mask); // keep pin low after stop
}
}
#endif

View File

@ -0,0 +1,168 @@
/*
WCharacter.h - Character utility functions for Wiring & Arduino
Copyright (c) 2010 Hernando Barragan. 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 Character_h
#define Character_h
#include <ctype.h>
// WCharacter.h prototypes
inline boolean isAlphaNumeric(int c) __attribute__((always_inline));
inline boolean isAlpha(int c) __attribute__((always_inline));
inline boolean isAscii(int c) __attribute__((always_inline));
inline boolean isWhitespace(int c) __attribute__((always_inline));
inline boolean isControl(int c) __attribute__((always_inline));
inline boolean isDigit(int c) __attribute__((always_inline));
inline boolean isGraph(int c) __attribute__((always_inline));
inline boolean isLowerCase(int c) __attribute__((always_inline));
inline boolean isPrintable(int c) __attribute__((always_inline));
inline boolean isPunct(int c) __attribute__((always_inline));
inline boolean isSpace(int c) __attribute__((always_inline));
inline boolean isUpperCase(int c) __attribute__((always_inline));
inline boolean isHexadecimalDigit(int c) __attribute__((always_inline));
inline int toAscii(int c) __attribute__((always_inline));
inline int toLowerCase(int c) __attribute__((always_inline));
inline int toUpperCase(int c)__attribute__((always_inline));
// Checks for an alphanumeric character.
// It is equivalent to (isalpha(c) || isdigit(c)).
inline boolean isAlphaNumeric(int c)
{
return ( isalnum(c) == 0 ? false : true);
}
// Checks for an alphabetic character.
// It is equivalent to (isupper(c) || islower(c)).
inline boolean isAlpha(int c)
{
return ( isalpha(c) == 0 ? false : true);
}
// Checks whether c is a 7-bit unsigned char value
// that fits into the ASCII character set.
inline boolean isAscii(int c)
{
return ( isascii (c) == 0 ? false : true);
}
// Checks for a blank character, that is, a space or a tab.
inline boolean isWhitespace(int c)
{
return ( isblank (c) == 0 ? false : true);
}
// Checks for a control character.
inline boolean isControl(int c)
{
return ( iscntrl (c) == 0 ? false : true);
}
// Checks for a digit (0 through 9).
inline boolean isDigit(int c)
{
return ( isdigit (c) == 0 ? false : true);
}
// Checks for any printable character except space.
inline boolean isGraph(int c)
{
return ( isgraph (c) == 0 ? false : true);
}
// Checks for a lower-case character.
inline boolean isLowerCase(int c)
{
return (islower (c) == 0 ? false : true);
}
// Checks for any printable character including space.
inline boolean isPrintable(int c)
{
return ( isprint (c) == 0 ? false : true);
}
// Checks for any printable character which is not a space
// or an alphanumeric character.
inline boolean isPunct(int c)
{
return ( ispunct (c) == 0 ? false : true);
}
// Checks for white-space characters. For the avr-libc library,
// these are: space, formfeed ('\f'), newline ('\n'), carriage
// return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').
inline boolean isSpace(int c)
{
return ( isspace (c) == 0 ? false : true);
}
// Checks for an uppercase letter.
inline boolean isUpperCase(int c)
{
return ( isupper (c) == 0 ? false : true);
}
// Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7
// 8 9 a b c d e f A B C D E F.
inline boolean isHexadecimalDigit(int c)
{
return ( isxdigit (c) == 0 ? false : true);
}
// Converts c to a 7-bit unsigned char value that fits into the
// ASCII character set, by clearing the high-order bits.
inline int toAscii(int c)
{
return toascii (c);
}
// Warning:
// Many people will be unhappy if you use this function.
// This function will convert accented letters into random
// characters.
// Converts the letter c to lower case, if possible.
inline int toLowerCase(int c)
{
return tolower (c);
}
// Converts the letter c to upper case, if possible.
inline int toUpperCase(int c)
{
return toupper (c);
}
#endif

View File

@ -0,0 +1 @@
#include "wiring.h"

View File

@ -0,0 +1,249 @@
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Wiring project - http://wiring.uniandes.edu.co
Copyright (c) 2004-05 Hernando Barragan
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
Modified 24 November 2006 by David A. Mellis
Modified 1 August 2010 by Mark Sproul
*/
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include "WConstants.h"
#include "wiring_private.h"
volatile static voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS];
// volatile static voidFuncPtr twiIntFunc;
void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
intFunc[interruptNum] = userFunc;
// Configure the interrupt mode (trigger on low input, any change, rising
// edge, or falling edge). The mode constants were chosen to correspond
// to the configuration bits in the hardware register, so we simply shift
// the mode into place.
// Enable the interrupt.
switch (interruptNum) {
#if defined(EICRA) && defined(EICRB) && defined(EIMSK)
case 2:
EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
EIMSK |= (1 << INT0);
break;
case 3:
EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
EIMSK |= (1 << INT1);
break;
case 4:
EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
EIMSK |= (1 << INT2);
break;
case 5:
EICRA = (EICRA & ~((1 << ISC30) | (1 << ISC31))) | (mode << ISC30);
EIMSK |= (1 << INT3);
break;
case 0:
EICRB = (EICRB & ~((1 << ISC40) | (1 << ISC41))) | (mode << ISC40);
EIMSK |= (1 << INT4);
break;
case 1:
EICRB = (EICRB & ~((1 << ISC50) | (1 << ISC51))) | (mode << ISC50);
EIMSK |= (1 << INT5);
break;
case 6:
EICRB = (EICRB & ~((1 << ISC60) | (1 << ISC61))) | (mode << ISC60);
EIMSK |= (1 << INT6);
break;
case 7:
EICRB = (EICRB & ~((1 << ISC70) | (1 << ISC71))) | (mode << ISC70);
EIMSK |= (1 << INT7);
break;
#else
case 0:
#if defined(EICRA) && defined(ISC00) && defined(EIMSK)
EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
EIMSK |= (1 << INT0);
#elif defined(MCUCR) && defined(ISC00) && defined(GICR)
MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
GICR |= (1 << INT0);
#elif defined(MCUCR) && defined(ISC00) && defined(GIMSK)
MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
GIMSK |= (1 << INT0);
#else
#error attachInterrupt not finished for this CPU (case 0)
#endif
break;
case 1:
#if defined(EICRA) && defined(ISC10) && defined(ISC11) && defined(EIMSK)
EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
EIMSK |= (1 << INT1);
#elif defined(MCUCR) && defined(ISC10) && defined(ISC11) && defined(GICR)
MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
GICR |= (1 << INT1);
#elif defined(MCUCR) && defined(ISC10) && defined(GIMSK) && defined(GIMSK)
MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
GIMSK |= (1 << INT1);
#else
#warning attachInterrupt may need some more work for this cpu (case 1)
#endif
break;
#endif
}
}
}
void detachInterrupt(uint8_t interruptNum) {
if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
// Disable the interrupt. (We can't assume that interruptNum is equal
// to the number of the EIMSK bit to clear, as this isn't true on the
// ATmega8. There, INT0 is 6 and INT1 is 7.)
switch (interruptNum) {
#if defined(EICRA) && defined(EICRB) && defined(EIMSK)
case 2:
EIMSK &= ~(1 << INT0);
break;
case 3:
EIMSK &= ~(1 << INT1);
break;
case 4:
EIMSK &= ~(1 << INT2);
break;
case 5:
EIMSK &= ~(1 << INT3);
break;
case 0:
EIMSK &= ~(1 << INT4);
break;
case 1:
EIMSK &= ~(1 << INT5);
break;
case 6:
EIMSK &= ~(1 << INT6);
break;
case 7:
EIMSK &= ~(1 << INT7);
break;
#else
case 0:
#if defined(EIMSK) && defined(INT0)
EIMSK &= ~(1 << INT0);
#elif defined(GICR) && defined(ISC00)
GICR &= ~(1 << INT0); // atmega32
#elif defined(GIMSK) && defined(INT0)
GIMSK &= ~(1 << INT0);
#else
#error detachInterrupt not finished for this cpu
#endif
break;
case 1:
#if defined(EIMSK) && defined(INT1)
EIMSK &= ~(1 << INT1);
#elif defined(GICR) && defined(INT1)
GICR &= ~(1 << INT1); // atmega32
#elif defined(GIMSK) && defined(INT1)
GIMSK &= ~(1 << INT1);
#else
#warning detachInterrupt may need some more work for this cpu (case 1)
#endif
break;
#endif
}
intFunc[interruptNum] = 0;
}
}
/*
void attachInterruptTwi(void (*userFunc)(void) ) {
twiIntFunc = userFunc;
}
*/
#if defined(EICRA) && defined(EICRB)
SIGNAL(INT0_vect) {
if(intFunc[EXTERNAL_INT_2])
intFunc[EXTERNAL_INT_2]();
}
SIGNAL(INT1_vect) {
if(intFunc[EXTERNAL_INT_3])
intFunc[EXTERNAL_INT_3]();
}
SIGNAL(INT2_vect) {
if(intFunc[EXTERNAL_INT_4])
intFunc[EXTERNAL_INT_4]();
}
SIGNAL(INT3_vect) {
if(intFunc[EXTERNAL_INT_5])
intFunc[EXTERNAL_INT_5]();
}
SIGNAL(INT4_vect) {
if(intFunc[EXTERNAL_INT_0])
intFunc[EXTERNAL_INT_0]();
}
SIGNAL(INT5_vect) {
if(intFunc[EXTERNAL_INT_1])
intFunc[EXTERNAL_INT_1]();
}
SIGNAL(INT6_vect) {
if(intFunc[EXTERNAL_INT_6])
intFunc[EXTERNAL_INT_6]();
}
SIGNAL(INT7_vect) {
if(intFunc[EXTERNAL_INT_7])
intFunc[EXTERNAL_INT_7]();
}
#else
SIGNAL(INT0_vect) {
if(intFunc[EXTERNAL_INT_0])
intFunc[EXTERNAL_INT_0]();
}
SIGNAL(INT1_vect) {
if(intFunc[EXTERNAL_INT_1])
intFunc[EXTERNAL_INT_1]();
}
#endif
/*
SIGNAL(SIG_2WIRE_SERIAL) {
if(twiIntFunc)
twiIntFunc();
}
*/

View File

@ -0,0 +1,60 @@
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Wiring project - http://wiring.org.co
Copyright (c) 2004-06 Hernando Barragan
Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id$
*/
extern "C" {
#include "stdlib.h"
}
void randomSeed(unsigned int seed)
{
if (seed != 0) {
srandom(seed);
}
}
long random(long howbig)
{
if (howbig == 0) {
return 0;
}
return random() % howbig;
}
long random(long howsmall, long howbig)
{
if (howsmall >= howbig) {
return howsmall;
}
long diff = howbig - howsmall;
return random(diff) + howsmall;
}
long map(long x, long in_min, long in_max, long out_min, long out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
unsigned int makeWord(unsigned int w) { return w; }
unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; }

View File

@ -0,0 +1,63 @@
#ifndef WProgram_h
#define WProgram_h
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <avr/interrupt.h>
#include "wiring.h"
#ifdef __cplusplus
#include "WCharacter.h"
#include "WString.h"
#include "HardwareSerial.h"
uint16_t makeWord(uint16_t w);
uint16_t makeWord(byte h, byte l);
#define word(...) makeWord(__VA_ARGS__)
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
void noTone(uint8_t _pin);
// WMath prototypes
long random(long);
long random(long, long);
void randomSeed(unsigned int);
long map(long, long, long, long, long);
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
const static uint8_t A0 = 54;
const static uint8_t A1 = 55;
const static uint8_t A2 = 56;
const static uint8_t A3 = 57;
const static uint8_t A4 = 58;
const static uint8_t A5 = 59;
const static uint8_t A6 = 60;
const static uint8_t A7 = 61;
const static uint8_t A8 = 62;
const static uint8_t A9 = 63;
const static uint8_t A10 = 64;
const static uint8_t A11 = 65;
const static uint8_t A12 = 66;
const static uint8_t A13 = 67;
const static uint8_t A14 = 68;
const static uint8_t A15 = 69;
#else
const static uint8_t A0 = 14;
const static uint8_t A1 = 15;
const static uint8_t A2 = 16;
const static uint8_t A3 = 17;
const static uint8_t A4 = 18;
const static uint8_t A5 = 19;
const static uint8_t A6 = 20;
const static uint8_t A7 = 21;
#endif
#endif
#endif

View File

@ -0,0 +1,443 @@
/*
WString.cpp - String library for Wiring & Arduino
Copyright (c) 2009-10 Hernando Barragan. All rights 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
*/
#include <stdlib.h>
#include "WProgram.h"
#include "WString.h"
String::String( const char *value )
{
if ( value == NULL )
value = "";
getBuffer( _length = strlen( value ) );
if ( _buffer != NULL )
strcpy( _buffer, value );
}
String::String( const String &value )
{
getBuffer( _length = value._length );
if ( _buffer != NULL )
strcpy( _buffer, value._buffer );
}
String::String( const char value )
{
_length = 1;
getBuffer(1);
if ( _buffer != NULL ) {
_buffer[0] = value;
_buffer[1] = 0;
}
}
String::String( const unsigned char value )
{
_length = 1;
getBuffer(1);
if ( _buffer != NULL) {
_buffer[0] = value;
_buffer[1] = 0;
}
}
String::String( const int value, const int base )
{
char buf[33];
itoa((signed long)value, buf, base);
getBuffer( _length = strlen(buf) );
if ( _buffer != NULL )
strcpy( _buffer, buf );
}
String::String( const unsigned int value, const int base )
{
char buf[33];
ultoa((unsigned long)value, buf, base);
getBuffer( _length = strlen(buf) );
if ( _buffer != NULL )
strcpy( _buffer, buf );
}
String::String( const long value, const int base )
{
char buf[33];
ltoa(value, buf, base);
getBuffer( _length = strlen(buf) );
if ( _buffer != NULL )
strcpy( _buffer, buf );
}
String::String( const unsigned long value, const int base )
{
char buf[33];
ultoa(value, buf, 10);
getBuffer( _length = strlen(buf) );
if ( _buffer != NULL )
strcpy( _buffer, buf );
}
char String::charAt( unsigned int loc ) const
{
return operator[]( loc );
}
void String::setCharAt( unsigned int loc, const char aChar )
{
if(_buffer == NULL) return;
if(_length > loc) {
_buffer[loc] = aChar;
}
}
int String::compareTo( const String &s2 ) const
{
return strcmp( _buffer, s2._buffer );
}
const String & String::concat( const String &s2 )
{
return (*this) += s2;
}
const String & String::operator=( const String &rhs )
{
if ( this == &rhs )
return *this;
if ( rhs._length > _length )
{
free(_buffer);
getBuffer( rhs._length );
}
if ( _buffer != NULL ) {
_length = rhs._length;
strcpy( _buffer, rhs._buffer );
}
return *this;
}
//const String & String::operator+=( const char aChar )
//{
// if ( _length == _capacity )
// doubleBuffer();
//
// _buffer[ _length++ ] = aChar;
// _buffer[ _length ] = '\0';
// return *this;
//}
const String & String::operator+=( const String &other )
{
_length += other._length;
if ( _length > _capacity )
{
char *temp = (char *)realloc(_buffer, _length + 1);
if ( temp != NULL ) {
_buffer = temp;
_capacity = _length;
} else {
_length -= other._length;
return *this;
}
}
strcat( _buffer, other._buffer );
return *this;
}
int String::operator==( const String &rhs ) const
{
return ( _length == rhs._length && strcmp( _buffer, rhs._buffer ) == 0 );
}
int String::operator!=( const String &rhs ) const
{
return ( _length != rhs.length() || strcmp( _buffer, rhs._buffer ) != 0 );
}
int String::operator<( const String &rhs ) const
{
return strcmp( _buffer, rhs._buffer ) < 0;
}
int String::operator>( const String &rhs ) const
{
return strcmp( _buffer, rhs._buffer ) > 0;
}
int String::operator<=( const String &rhs ) const
{
return strcmp( _buffer, rhs._buffer ) <= 0;
}
int String::operator>=( const String & rhs ) const
{
return strcmp( _buffer, rhs._buffer ) >= 0;
}
char & String::operator[]( unsigned int index )
{
static char dummy_writable_char;
if (index >= _length || !_buffer) {
dummy_writable_char = 0;
return dummy_writable_char;
}
return _buffer[ index ];
}
char String::operator[]( unsigned int index ) const
{
// need to check for valid index, to do later
return _buffer[ index ];
}
boolean String::endsWith( const String &s2 ) const
{
if ( _length < s2._length )
return 0;
return strcmp( &_buffer[ _length - s2._length], s2._buffer ) == 0;
}
boolean String::equals( const String &s2 ) const
{
return ( _length == s2._length && strcmp( _buffer,s2._buffer ) == 0 );
}
boolean String::equalsIgnoreCase( const String &s2 ) const
{
if ( this == &s2 )
return true; //1;
else if ( _length != s2._length )
return false; //0;
return strcmp(toLowerCase()._buffer, s2.toLowerCase()._buffer) == 0;
}
String String::replace( char findChar, char replaceChar )
{
if ( _buffer == NULL ) return *this;
String theReturn = _buffer;
char* temp = theReturn._buffer;
while( (temp = strchr( temp, findChar )) != 0 )
*temp = replaceChar;
return theReturn;
}
String String::replace( const String& match, const String& replace )
{
if ( _buffer == NULL ) return *this;
String temp = _buffer, newString;
int loc;
while ( (loc = temp.indexOf( match )) != -1 )
{
newString += temp.substring( 0, loc );
newString += replace;
temp = temp.substring( loc + match._length );
}
newString += temp;
return newString;
}
int String::indexOf( char temp ) const
{
return indexOf( temp, 0 );
}
int String::indexOf( char ch, unsigned int fromIndex ) const
{
if ( fromIndex >= _length )
return -1;
const char* temp = strchr( &_buffer[fromIndex], ch );
if ( temp == NULL )
return -1;
return temp - _buffer;
}
int String::indexOf( const String &s2 ) const
{
return indexOf( s2, 0 );
}
int String::indexOf( const String &s2, unsigned int fromIndex ) const
{
if ( fromIndex >= _length )
return -1;
const char *theFind = strstr( &_buffer[ fromIndex ], s2._buffer );
if ( theFind == NULL )
return -1;
return theFind - _buffer; // pointer subtraction
}
int String::lastIndexOf( char theChar ) const
{
return lastIndexOf( theChar, _length - 1 );
}
int String::lastIndexOf( char ch, unsigned int fromIndex ) const
{
if ( fromIndex >= _length )
return -1;
char tempchar = _buffer[fromIndex + 1];
_buffer[fromIndex + 1] = '\0';
char* temp = strrchr( _buffer, ch );
_buffer[fromIndex + 1] = tempchar;
if ( temp == NULL )
return -1;
return temp - _buffer;
}
int String::lastIndexOf( const String &s2 ) const
{
return lastIndexOf( s2, _length - s2._length );
}
int String::lastIndexOf( const String &s2, unsigned int fromIndex ) const
{
// check for empty strings
if ( s2._length == 0 || s2._length - 1 > fromIndex || fromIndex >= _length )
return -1;
// matching first character
char temp = s2[ 0 ];
for ( int i = fromIndex; i >= 0; i-- )
{
if ( _buffer[ i ] == temp && (*this).substring( i, i + s2._length ).equals( s2 ) )
return i;
}
return -1;
}
boolean String::startsWith( const String &s2 ) const
{
if ( _length < s2._length )
return 0;
return startsWith( s2, 0 );
}
boolean String::startsWith( const String &s2, unsigned int offset ) const
{
if ( offset > _length - s2._length )
return 0;
return strncmp( &_buffer[offset], s2._buffer, s2._length ) == 0;
}
String String::substring( unsigned int left ) const
{
return substring( left, _length );
}
String String::substring( unsigned int left, unsigned int right ) const
{
if ( left > right )
{
int temp = right;
right = left;
left = temp;
}
if ( right > _length )
{
right = _length;
}
char temp = _buffer[ right ]; // save the replaced character
_buffer[ right ] = '\0';
String outPut = ( _buffer + left ); // pointer arithmetic
_buffer[ right ] = temp; //restore character
return outPut;
}
String String::toLowerCase() const
{
String temp = _buffer;
for ( unsigned int i = 0; i < _length; i++ )
temp._buffer[ i ] = (char)tolower( temp._buffer[ i ] );
return temp;
}
String String::toUpperCase() const
{
String temp = _buffer;
for ( unsigned int i = 0; i < _length; i++ )
temp._buffer[ i ] = (char)toupper( temp._buffer[ i ] );
return temp;
}
String String::trim() const
{
if ( _buffer == NULL ) return *this;
String temp = _buffer;
unsigned int i,j;
for ( i = 0; i < _length; i++ )
{
if ( !isspace(_buffer[i]) )
break;
}
for ( j = temp._length - 1; j > i; j-- )
{
if ( !isspace(_buffer[j]) )
break;
}
return temp.substring( i, j + 1);
}
void String::getBytes(unsigned char *buf, unsigned int bufsize)
{
if (!bufsize || !buf) return;
unsigned int len = bufsize - 1;
if (len > _length) len = _length;
strncpy((char *)buf, _buffer, len);
buf[len] = 0;
}
void String::toCharArray(char *buf, unsigned int bufsize)
{
if (!bufsize || !buf) return;
unsigned int len = bufsize - 1;
if (len > _length) len = _length;
strncpy(buf, _buffer, len);
buf[len] = 0;
}
long String::toInt() {
return atol(_buffer);
}

View File

@ -0,0 +1,112 @@
/*
WString.h - String library for Wiring & Arduino
Copyright (c) 2009-10 Hernando Barragan. 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 String_h
#define String_h
//#include "WProgram.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
class String
{
public:
// constructors
String( const char *value = "" );
String( const String &value );
String( const char );
String( const unsigned char );
String( const int, const int base=10);
String( const unsigned int, const int base=10 );
String( const long, const int base=10 );
String( const unsigned long, const int base=10 );
~String() { free(_buffer); _length = _capacity = 0;} //added _length = _capacity = 0;
// operators
const String & operator = ( const String &rhs );
const String & operator +=( const String &rhs );
//const String & operator +=( const char );
int operator ==( const String &rhs ) const;
int operator !=( const String &rhs ) const;
int operator < ( const String &rhs ) const;
int operator > ( const String &rhs ) const;
int operator <=( const String &rhs ) const;
int operator >=( const String &rhs ) const;
char operator []( unsigned int index ) const;
char& operator []( unsigned int index );
//operator const char *() const { return _buffer; }
// general methods
char charAt( unsigned int index ) const;
int compareTo( const String &anotherString ) const;
unsigned char endsWith( const String &suffix ) const;
unsigned char equals( const String &anObject ) const;
unsigned char equalsIgnoreCase( const String &anotherString ) const;
int indexOf( char ch ) const;
int indexOf( char ch, unsigned int fromIndex ) const;
int indexOf( const String &str ) const;
int indexOf( const String &str, unsigned int fromIndex ) const;
int lastIndexOf( char ch ) const;
int lastIndexOf( char ch, unsigned int fromIndex ) const;
int lastIndexOf( const String &str ) const;
int lastIndexOf( const String &str, unsigned int fromIndex ) const;
const unsigned int length( ) const { return _length; }
void setCharAt(unsigned int index, const char ch);
unsigned char startsWith( const String &prefix ) const;
unsigned char startsWith( const String &prefix, unsigned int toffset ) const;
String substring( unsigned int beginIndex ) const;
String substring( unsigned int beginIndex, unsigned int endIndex ) const;
String toLowerCase( ) const;
String toUpperCase( ) const;
String trim( ) const;
void getBytes(unsigned char *buf, unsigned int bufsize);
void toCharArray(char *buf, unsigned int bufsize);
long toInt( );
const String& concat( const String &str );
String replace( char oldChar, char newChar );
String replace( const String& match, const String& replace );
friend String operator + ( String lhs, const String &rhs );
protected:
char *_buffer; // the actual char array
unsigned int _capacity; // the array length minus one (for the '\0')
unsigned int _length; // the String length (not counting the '\0')
void getBuffer(unsigned int maxStrLen);
private:
};
// allocate buffer space
inline void String::getBuffer(unsigned int maxStrLen)
{
_capacity = maxStrLen;
_buffer = (char *) malloc(_capacity + 1);
if (_buffer == NULL) _length = _capacity = 0;
}
inline String operator+( String lhs, const String &rhs )
{
return lhs += rhs;
}
#endif

View File

@ -0,0 +1,515 @@
#ifndef Binary_h
#define Binary_h
#define B0 0
#define B00 0
#define B000 0
#define B0000 0
#define B00000 0
#define B000000 0
#define B0000000 0
#define B00000000 0
#define B1 1
#define B01 1
#define B001 1
#define B0001 1
#define B00001 1
#define B000001 1
#define B0000001 1
#define B00000001 1
#define B10 2
#define B010 2
#define B0010 2
#define B00010 2
#define B000010 2
#define B0000010 2
#define B00000010 2
#define B11 3
#define B011 3
#define B0011 3
#define B00011 3
#define B000011 3
#define B0000011 3
#define B00000011 3
#define B100 4
#define B0100 4
#define B00100 4
#define B000100 4
#define B0000100 4
#define B00000100 4
#define B101 5
#define B0101 5
#define B00101 5
#define B000101 5
#define B0000101 5
#define B00000101 5
#define B110 6
#define B0110 6
#define B00110 6
#define B000110 6
#define B0000110 6
#define B00000110 6
#define B111 7
#define B0111 7
#define B00111 7
#define B000111 7
#define B0000111 7
#define B00000111 7
#define B1000 8
#define B01000 8
#define B001000 8
#define B0001000 8
#define B00001000 8
#define B1001 9
#define B01001 9
#define B001001 9
#define B0001001 9
#define B00001001 9
#define B1010 10
#define B01010 10
#define B001010 10
#define B0001010 10
#define B00001010 10
#define B1011 11
#define B01011 11
#define B001011 11
#define B0001011 11
#define B00001011 11
#define B1100 12
#define B01100 12
#define B001100 12
#define B0001100 12
#define B00001100 12
#define B1101 13
#define B01101 13
#define B001101 13
#define B0001101 13
#define B00001101 13
#define B1110 14
#define B01110 14
#define B001110 14
#define B0001110 14
#define B00001110 14
#define B1111 15
#define B01111 15
#define B001111 15
#define B0001111 15
#define B00001111 15
#define B10000 16
#define B010000 16
#define B0010000 16
#define B00010000 16
#define B10001 17
#define B010001 17
#define B0010001 17
#define B00010001 17
#define B10010 18
#define B010010 18
#define B0010010 18
#define B00010010 18
#define B10011 19
#define B010011 19
#define B0010011 19
#define B00010011 19
#define B10100 20
#define B010100 20
#define B0010100 20
#define B00010100 20
#define B10101 21
#define B010101 21
#define B0010101 21
#define B00010101 21
#define B10110 22
#define B010110 22
#define B0010110 22
#define B00010110 22
#define B10111 23
#define B010111 23
#define B0010111 23
#define B00010111 23
#define B11000 24
#define B011000 24
#define B0011000 24
#define B00011000 24
#define B11001 25
#define B011001 25
#define B0011001 25
#define B00011001 25
#define B11010 26
#define B011010 26
#define B0011010 26
#define B00011010 26
#define B11011 27
#define B011011 27
#define B0011011 27
#define B00011011 27
#define B11100 28
#define B011100 28
#define B0011100 28
#define B00011100 28
#define B11101 29
#define B011101 29
#define B0011101 29
#define B00011101 29
#define B11110 30
#define B011110 30
#define B0011110 30
#define B00011110 30
#define B11111 31
#define B011111 31
#define B0011111 31
#define B00011111 31
#define B100000 32
#define B0100000 32
#define B00100000 32
#define B100001 33
#define B0100001 33
#define B00100001 33
#define B100010 34
#define B0100010 34
#define B00100010 34
#define B100011 35
#define B0100011 35
#define B00100011 35
#define B100100 36
#define B0100100 36
#define B00100100 36
#define B100101 37
#define B0100101 37
#define B00100101 37
#define B100110 38
#define B0100110 38
#define B00100110 38
#define B100111 39
#define B0100111 39
#define B00100111 39
#define B101000 40
#define B0101000 40
#define B00101000 40
#define B101001 41
#define B0101001 41
#define B00101001 41
#define B101010 42
#define B0101010 42
#define B00101010 42
#define B101011 43
#define B0101011 43
#define B00101011 43
#define B101100 44
#define B0101100 44
#define B00101100 44
#define B101101 45
#define B0101101 45
#define B00101101 45
#define B101110 46
#define B0101110 46
#define B00101110 46
#define B101111 47
#define B0101111 47
#define B00101111 47
#define B110000 48
#define B0110000 48
#define B00110000 48
#define B110001 49
#define B0110001 49
#define B00110001 49
#define B110010 50
#define B0110010 50
#define B00110010 50
#define B110011 51
#define B0110011 51
#define B00110011 51
#define B110100 52
#define B0110100 52
#define B00110100 52
#define B110101 53
#define B0110101 53
#define B00110101 53
#define B110110 54
#define B0110110 54
#define B00110110 54
#define B110111 55
#define B0110111 55
#define B00110111 55
#define B111000 56
#define B0111000 56
#define B00111000 56
#define B111001 57
#define B0111001 57
#define B00111001 57
#define B111010 58
#define B0111010 58
#define B00111010 58
#define B111011 59
#define B0111011 59
#define B00111011 59
#define B111100 60
#define B0111100 60
#define B00111100 60
#define B111101 61
#define B0111101 61
#define B00111101 61
#define B111110 62
#define B0111110 62
#define B00111110 62
#define B111111 63
#define B0111111 63
#define B00111111 63
#define B1000000 64
#define B01000000 64
#define B1000001 65
#define B01000001 65
#define B1000010 66
#define B01000010 66
#define B1000011 67
#define B01000011 67
#define B1000100 68
#define B01000100 68
#define B1000101 69
#define B01000101 69
#define B1000110 70
#define B01000110 70
#define B1000111 71
#define B01000111 71
#define B1001000 72
#define B01001000 72
#define B1001001 73
#define B01001001 73
#define B1001010 74
#define B01001010 74
#define B1001011 75
#define B01001011 75
#define B1001100 76
#define B01001100 76
#define B1001101 77
#define B01001101 77
#define B1001110 78
#define B01001110 78
#define B1001111 79
#define B01001111 79
#define B1010000 80
#define B01010000 80
#define B1010001 81
#define B01010001 81
#define B1010010 82
#define B01010010 82
#define B1010011 83
#define B01010011 83
#define B1010100 84
#define B01010100 84
#define B1010101 85
#define B01010101 85
#define B1010110 86
#define B01010110 86
#define B1010111 87
#define B01010111 87
#define B1011000 88
#define B01011000 88
#define B1011001 89
#define B01011001 89
#define B1011010 90
#define B01011010 90
#define B1011011 91
#define B01011011 91
#define B1011100 92
#define B01011100 92
#define B1011101 93
#define B01011101 93
#define B1011110 94
#define B01011110 94
#define B1011111 95
#define B01011111 95
#define B1100000 96
#define B01100000 96
#define B1100001 97
#define B01100001 97
#define B1100010 98
#define B01100010 98
#define B1100011 99
#define B01100011 99
#define B1100100 100
#define B01100100 100
#define B1100101 101
#define B01100101 101
#define B1100110 102
#define B01100110 102
#define B1100111 103
#define B01100111 103
#define B1101000 104
#define B01101000 104
#define B1101001 105
#define B01101001 105
#define B1101010 106
#define B01101010 106
#define B1101011 107
#define B01101011 107
#define B1101100 108
#define B01101100 108
#define B1101101 109
#define B01101101 109
#define B1101110 110
#define B01101110 110
#define B1101111 111
#define B01101111 111
#define B1110000 112
#define B01110000 112
#define B1110001 113
#define B01110001 113
#define B1110010 114
#define B01110010 114
#define B1110011 115
#define B01110011 115
#define B1110100 116
#define B01110100 116
#define B1110101 117
#define B01110101 117
#define B1110110 118
#define B01110110 118
#define B1110111 119
#define B01110111 119
#define B1111000 120
#define B01111000 120
#define B1111001 121
#define B01111001 121
#define B1111010 122
#define B01111010 122
#define B1111011 123
#define B01111011 123
#define B1111100 124
#define B01111100 124
#define B1111101 125
#define B01111101 125
#define B1111110 126
#define B01111110 126
#define B1111111 127
#define B01111111 127
#define B10000000 128
#define B10000001 129
#define B10000010 130
#define B10000011 131
#define B10000100 132
#define B10000101 133
#define B10000110 134
#define B10000111 135
#define B10001000 136
#define B10001001 137
#define B10001010 138
#define B10001011 139
#define B10001100 140
#define B10001101 141
#define B10001110 142
#define B10001111 143
#define B10010000 144
#define B10010001 145
#define B10010010 146
#define B10010011 147
#define B10010100 148
#define B10010101 149
#define B10010110 150
#define B10010111 151
#define B10011000 152
#define B10011001 153
#define B10011010 154
#define B10011011 155
#define B10011100 156
#define B10011101 157
#define B10011110 158
#define B10011111 159
#define B10100000 160
#define B10100001 161
#define B10100010 162
#define B10100011 163
#define B10100100 164
#define B10100101 165
#define B10100110 166
#define B10100111 167
#define B10101000 168
#define B10101001 169
#define B10101010 170
#define B10101011 171
#define B10101100 172
#define B10101101 173
#define B10101110 174
#define B10101111 175
#define B10110000 176
#define B10110001 177
#define B10110010 178
#define B10110011 179
#define B10110100 180
#define B10110101 181
#define B10110110 182
#define B10110111 183
#define B10111000 184
#define B10111001 185
#define B10111010 186
#define B10111011 187
#define B10111100 188
#define B10111101 189
#define B10111110 190
#define B10111111 191
#define B11000000 192
#define B11000001 193
#define B11000010 194
#define B11000011 195
#define B11000100 196
#define B11000101 197
#define B11000110 198
#define B11000111 199
#define B11001000 200
#define B11001001 201
#define B11001010 202
#define B11001011 203
#define B11001100 204
#define B11001101 205
#define B11001110 206
#define B11001111 207
#define B11010000 208
#define B11010001 209
#define B11010010 210
#define B11010011 211
#define B11010100 212
#define B11010101 213
#define B11010110 214
#define B11010111 215
#define B11011000 216
#define B11011001 217
#define B11011010 218
#define B11011011 219
#define B11011100 220
#define B11011101 221
#define B11011110 222
#define B11011111 223
#define B11100000 224
#define B11100001 225
#define B11100010 226
#define B11100011 227
#define B11100100 228
#define B11100101 229
#define B11100110 230
#define B11100111 231
#define B11101000 232
#define B11101001 233
#define B11101010 234
#define B11101011 235
#define B11101100 236
#define B11101101 237
#define B11101110 238
#define B11101111 239
#define B11110000 240
#define B11110001 241
#define B11110010 242
#define B11110011 243
#define B11110100 244
#define B11110101 245
#define B11110110 246
#define B11110111 247
#define B11111000 248
#define B11111001 249
#define B11111010 250
#define B11111011 251
#define B11111100 252
#define B11111101 253
#define B11111110 254
#define B11111111 255
#endif

View File

@ -0,0 +1,14 @@
#include <WProgram.h>
int main(void)
{
init();
setup();
for (;;)
loop();
return 0;
}

View File

@ -0,0 +1,200 @@
/*
pins_arduino.c - pin definitions for the Arduino board
Part of Arduino / Wiring Lite
Copyright (c) 2005 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: pins_arduino.c 254 2007-04-20 23:17:38Z mellis $
*/
#include <avr/io.h>
#include "wiring_private.h"
#include "pins_arduino.h"
// On the Sanguino board, digital pins are also used
// for the analog output (software PWM). Analog input
// pins are a separate set.
// ATMEL ATMEGA644P / SANGUINO
//
// +---\/---+
// INT0 (D 0) PB0 1| |40 PA0 (AI 0 / D31)
// INT1 (D 1) PB1 2| |39 PA1 (AI 1 / D30)
// INT2 (D 2) PB2 3| |38 PA2 (AI 2 / D29)
// PWM (D 3) PB3 4| |37 PA3 (AI 3 / D28)
// PWM (D 4) PB4 5| |36 PA4 (AI 4 / D27)
// MOSI (D 5) PB5 6| |35 PA5 (AI 5 / D26)
// MISO (D 6) PB6 7| |34 PA6 (AI 6 / D25)
// SCK (D 7) PB7 8| |33 PA7 (AI 7 / D24)
// RST 9| |32 AREF
// VCC 10| |31 GND
// GND 11| |30 AVCC
// XTAL2 12| |29 PC7 (D 23)
// XTAL1 13| |28 PC6 (D 22)
// RX0 (D 8) PD0 14| |27 PC5 (D 21) TDI
// TX0 (D 9) PD1 15| |26 PC4 (D 20) TDO
// RX1 (D 10) PD2 16| |25 PC3 (D 19) TMS
// TX1 (D 11) PD3 17| |24 PC2 (D 18) TCK
// PWM (D 12) PD4 18| |23 PC1 (D 17) SDA
// PWM (D 13) PD5 19| |22 PC0 (D 16) SCL
// PWM (D 14) PD6 20| |21 PD7 (D 15) PWM
// +--------+
//
#define PA 1
#define PB 2
#define PC 3
#define PD 4
// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
const uint8_t PROGMEM port_to_mode_PGM[] =
{
NOT_A_PORT,
(uint8_t) (uint16_t) &DDRA,
(uint8_t) (uint16_t) &DDRB,
(uint8_t) (uint16_t) &DDRC,
(uint8_t) (uint16_t) &DDRD,
};
const uint8_t PROGMEM port_to_output_PGM[] =
{
NOT_A_PORT,
(uint8_t) (uint16_t) &PORTA,
(uint8_t) (uint16_t) &PORTB,
(uint8_t) (uint16_t) &PORTC,
(uint8_t) (uint16_t) &PORTD,
};
const uint8_t PROGMEM port_to_input_PGM[] =
{
NOT_A_PORT,
(uint8_t) (uint16_t) &PINA,
(uint8_t) (uint16_t) &PINB,
(uint8_t) (uint16_t) &PINC,
(uint8_t) (uint16_t) &PIND,
};
const uint8_t PROGMEM digital_pin_to_port_PGM[] =
{
PB, /* 0 */
PB,
PB,
PB,
PB,
PB,
PB,
PB,
PD, /* 8 */
PD,
PD,
PD,
PD,
PD,
PD,
PD,
PC, /* 16 */
PC,
PC,
PC,
PC,
PC,
PC,
PC,
PA, /* 24 */
PA,
PA,
PA,
PA,
PA,
PA,
PA /* 31 */
};
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] =
{
_BV(0), /* 0, port B */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
_BV(0), /* 8, port D */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
_BV(0), /* 16, port C */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
_BV(7), /* 24, port A */
_BV(6),
_BV(5),
_BV(4),
_BV(3),
_BV(2),
_BV(1),
_BV(0)
};
const uint8_t PROGMEM digital_pin_to_timer_PGM[] =
{
NOT_ON_TIMER, /* 0 - PB0 */
NOT_ON_TIMER, /* 1 - PB1 */
NOT_ON_TIMER, /* 2 - PB2 */
TIMER0A, /* 3 - PB3 */
TIMER0B, /* 4 - PB4 */
NOT_ON_TIMER, /* 5 - PB5 */
NOT_ON_TIMER, /* 6 - PB6 */
NOT_ON_TIMER, /* 7 - PB7 */
NOT_ON_TIMER, /* 8 - PD0 */
NOT_ON_TIMER, /* 9 - PD1 */
NOT_ON_TIMER, /* 10 - PD2 */
NOT_ON_TIMER, /* 11 - PD3 */
TIMER1B, /* 12 - PD4 */
TIMER1A, /* 13 - PD5 */
TIMER2B, /* 14 - PD6 */
TIMER2A, /* 15 - PD7 */
NOT_ON_TIMER, /* 16 - PC0 */
NOT_ON_TIMER, /* 17 - PC1 */
NOT_ON_TIMER, /* 18 - PC2 */
NOT_ON_TIMER, /* 19 - PC3 */
NOT_ON_TIMER, /* 20 - PC4 */
NOT_ON_TIMER, /* 21 - PC5 */
NOT_ON_TIMER, /* 22 - PC6 */
NOT_ON_TIMER, /* 23 - PC7 */
NOT_ON_TIMER, /* 24 - PA0 */
NOT_ON_TIMER, /* 25 - PA1 */
NOT_ON_TIMER, /* 26 - PA2 */
NOT_ON_TIMER, /* 27 - PA3 */
NOT_ON_TIMER, /* 28 - PA4 */
NOT_ON_TIMER, /* 29 - PA5 */
NOT_ON_TIMER, /* 30 - PA6 */
NOT_ON_TIMER /* 31 - PA7 */
};

View File

@ -0,0 +1,65 @@
/*
pins_arduino.h - Pin definition functions for Arduino
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2007 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
*/
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <avr/pgmspace.h>
#define NOT_A_PIN 0
#define NOT_A_PORT 0
#define NOT_ON_TIMER 0
#define TIMER0A 1
#define TIMER0B 2
#define TIMER1A 3
#define TIMER1B 4
#define TIMER2 5
#define TIMER2A 6
#define TIMER2B 7
extern const uint8_t PROGMEM port_to_mode_PGM[];
extern const uint8_t PROGMEM port_to_input_PGM[];
extern const uint8_t PROGMEM port_to_output_PGM[];
extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
// Get the bit location within the hardware port of the given virtual pin.
// This comes from the pins_*.c file for the active board configuration.
//
// These perform slightly better as macros compared to inline functions
//
#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
#define analogInPinToBit(P) (P)
#define portOutputRegister(P) ( (volatile uint8_t *)( (uint16_t) pgm_read_byte( port_to_output_PGM + (P))) )
#define portInputRegister(P) ( (volatile uint8_t *)( (uint16_t) pgm_read_byte( port_to_input_PGM + (P))) )
#define portModeRegister(P) ( (volatile uint8_t *)( (uint16_t) pgm_read_byte( port_to_mode_PGM + (P))) )
#endif

View File

@ -0,0 +1,289 @@
/*
wiring.c - Partial implementation of the Wiring API for the ATmega8.
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id$
*/
#include "wiring_private.h"
// the prescaler is set so that timer0 ticks every 64 clock cycles, and the
// the overflow handler is called every 256 ticks.
#define MICROSECONDS_PER_TIMER0_OVERFLOW (clockCyclesToMicroseconds(64 * 256))
// the whole number of milliseconds per timer0 overflow
#define MILLIS_INC (MICROSECONDS_PER_TIMER0_OVERFLOW / 1000)
// the fractional number of milliseconds per timer0 overflow. we shift right
// by three to fit these numbers into a byte. (for the clock speeds we care
// about - 8 and 16 MHz - this doesn't lose precision.)
#define FRACT_INC ((MICROSECONDS_PER_TIMER0_OVERFLOW % 1000) >> 3)
#define FRACT_MAX (1000 >> 3)
volatile unsigned long timer0_overflow_count = 0;
volatile unsigned long timer0_millis = 0;
static unsigned char timer0_fract = 0;
SIGNAL(TIMER0_OVF_vect)
{
// copy these to local variables so they can be stored in registers
// (volatile variables must be read from memory on every access)
unsigned long m = timer0_millis;
unsigned char f = timer0_fract;
m += MILLIS_INC;
f += FRACT_INC;
if (f >= FRACT_MAX) {
f -= FRACT_MAX;
m += 1;
}
timer0_fract = f;
timer0_millis = m;
timer0_overflow_count++;
}
unsigned long millis()
{
unsigned long m;
uint8_t oldSREG = SREG;
// disable interrupts while we read timer0_millis or we might get an
// inconsistent value (e.g. in the middle of a write to timer0_millis)
cli();
m = timer0_millis;
SREG = oldSREG;
return m;
}
unsigned long micros() {
unsigned long m;
uint8_t oldSREG = SREG, t;
cli();
m = timer0_overflow_count;
#if defined(TCNT0)
t = TCNT0;
#elif defined(TCNT0L)
t = TCNT0L;
#else
#error TIMER 0 not defined
#endif
#ifdef TIFR0
if ((TIFR0 & _BV(TOV0)) && (t < 255))
m++;
#else
if ((TIFR & _BV(TOV0)) && (t < 255))
m++;
#endif
SREG = oldSREG;
return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond());
}
void delay(unsigned long ms)
{
uint16_t start = (uint16_t)micros();
while (ms > 0) {
if (((uint16_t)micros() - start) >= 1000) {
ms--;
start += 1000;
}
}
}
/* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */
void delayMicroseconds(unsigned int us)
{
// calling avrlib's delay_us() function with low values (e.g. 1 or
// 2 microseconds) gives delays longer than desired.
//delay_us(us);
#if F_CPU >= 16000000L
// for the 16 MHz clock on most Arduino boards
// for a one-microsecond delay, simply return. the overhead
// of the function call yields a delay of approximately 1 1/8 us.
if (--us == 0)
return;
// the following loop takes a quarter of a microsecond (4 cycles)
// per iteration, so execute it four times for each microsecond of
// delay requested.
us <<= 2;
// account for the time taken in the preceeding commands.
us -= 2;
#else
// for the 8 MHz internal clock on the ATmega168
// for a one- or two-microsecond delay, simply return. the overhead of
// the function calls takes more than two microseconds. can't just
// subtract two, since us is unsigned; we'd overflow.
if (--us == 0)
return;
if (--us == 0)
return;
// the following loop takes half of a microsecond (4 cycles)
// per iteration, so execute it twice for each microsecond of
// delay requested.
us <<= 1;
// partially compensate for the time taken by the preceeding commands.
// we can't subtract any more than this or we'd overflow w/ small delays.
us--;
#endif
// busy wait
__asm__ __volatile__ (
"1: sbiw %0,1" "\n\t" // 2 cycles
"brne 1b" : "=w" (us) : "0" (us) // 2 cycles
);
}
void init()
{
// this needs to be called before setup() or some functions won't
// work there
sei();
// on the ATmega168, timer 0 is also used for fast hardware pwm
// (using phase-correct PWM would mean that timer 0 overflowed half as often
// resulting in different millis() behavior on the ATmega8 and ATmega168)
#if defined(TCCR0A) && defined(WGM01)
sbi(TCCR0A, WGM01);
sbi(TCCR0A, WGM00);
#endif
// set timer 0 prescale factor to 64
#if defined(__AVR_ATmega128__)
// CPU specific: different values for the ATmega128
sbi(TCCR0, CS02);
#elif defined(TCCR0) && defined(CS01) && defined(CS00)
// this combination is for the standard atmega8
sbi(TCCR0, CS01);
sbi(TCCR0, CS00);
#elif defined(TCCR0B) && defined(CS01) && defined(CS00)
// this combination is for the standard 168/328/1280/2560
sbi(TCCR0B, CS01);
sbi(TCCR0B, CS00);
#elif defined(TCCR0A) && defined(CS01) && defined(CS00)
// this combination is for the __AVR_ATmega645__ series
sbi(TCCR0A, CS01);
sbi(TCCR0A, CS00);
#else
#error Timer 0 prescale factor 64 not set correctly
#endif
// enable timer 0 overflow interrupt
#if defined(TIMSK) && defined(TOIE0)
sbi(TIMSK, TOIE0);
#elif defined(TIMSK0) && defined(TOIE0)
sbi(TIMSK0, TOIE0);
#else
#error Timer 0 overflow interrupt not set correctly
#endif
// timers 1 and 2 are used for phase-correct hardware pwm
// this is better for motors as it ensures an even waveform
// note, however, that fast pwm mode can achieve a frequency of up
// 8 MHz (with a 16 MHz clock) at 50% duty cycle
TCCR1B = 0;
// set timer 1 prescale factor to 64
#if defined(TCCR1B) && defined(CS11) && defined(CS10)
sbi(TCCR1B, CS11);
sbi(TCCR1B, CS10);
#elif defined(TCCR1) && defined(CS11) && defined(CS10)
sbi(TCCR1, CS11);
sbi(TCCR1, CS10);
#endif
// put timer 1 in 8-bit phase correct pwm mode
#if defined(TCCR1A) && defined(WGM10)
sbi(TCCR1A, WGM10);
#elif defined(TCCR1)
#warning this needs to be finished
#endif
// set timer 2 prescale factor to 64
#if defined(TCCR2) && defined(CS22)
sbi(TCCR2, CS22);
#elif defined(TCCR2B) && defined(CS22)
sbi(TCCR2B, CS22);
#else
#warning Timer 2 not finished (may not be present on this CPU)
#endif
// configure timer 2 for phase correct pwm (8-bit)
#if defined(TCCR2) && defined(WGM20)
sbi(TCCR2, WGM20);
#elif defined(TCCR2A) && defined(WGM20)
sbi(TCCR2A, WGM20);
#else
#warning Timer 2 not finished (may not be present on this CPU)
#endif
#if defined(TCCR3B) && defined(CS31) && defined(WGM30)
sbi(TCCR3B, CS31); // set timer 3 prescale factor to 64
sbi(TCCR3B, CS30);
sbi(TCCR3A, WGM30); // put timer 3 in 8-bit phase correct pwm mode
#endif
#if defined(TCCR4B) && defined(CS41) && defined(WGM40)
sbi(TCCR4B, CS41); // set timer 4 prescale factor to 64
sbi(TCCR4B, CS40);
sbi(TCCR4A, WGM40); // put timer 4 in 8-bit phase correct pwm mode
#endif
#if defined(TCCR5B) && defined(CS51) && defined(WGM50)
sbi(TCCR5B, CS51); // set timer 5 prescale factor to 64
sbi(TCCR5B, CS50);
sbi(TCCR5A, WGM50); // put timer 5 in 8-bit phase correct pwm mode
#endif
#if defined(ADCSRA)
// set a2d prescale factor to 128
// 16 MHz / 128 = 125 KHz, inside the desired 50-200 KHz range.
// XXX: this will not work properly for other clock speeds, and
// this code should use F_CPU to determine the prescale factor.
sbi(ADCSRA, ADPS2);
sbi(ADCSRA, ADPS1);
sbi(ADCSRA, ADPS0);
// enable a2d conversions
sbi(ADCSRA, ADEN);
#endif
// the bootloader connects pins 0 and 1 to the USART; disconnect them
// here so they can be used as normal digital i/o; they will be
// reconnected in Serial.begin()
#if defined(UCSRB)
UCSRB = 0;
#elif defined(UCSR0B)
UCSR0B = 0;
#endif
}

View File

@ -0,0 +1,136 @@
/*
wiring.h - Partial implementation of the Wiring API for the ATmega8.
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id$
*/
#ifndef Wiring_h
#define Wiring_h
#include <math.h>
#include <avr/io.h>
#include <stdlib.h>
#include "binary.h"
#ifdef __cplusplus
extern "C"{
#endif
#define HIGH 0x1
#define LOW 0x0
#define INPUT 0x0
#define OUTPUT 0x1
#define true 0x1
#define false 0x0
#define PI 3.1415926535897932384626433832795
#define HALF_PI 1.5707963267948966192313216916398
#define TWO_PI 6.283185307179586476925286766559
#define DEG_TO_RAD 0.017453292519943295769236907684886
#define RAD_TO_DEG 57.295779513082320876798154814105
#define SERIAL 0x0
#define DISPLAY 0x1
#define LSBFIRST 0
#define MSBFIRST 1
#define CHANGE 1
#define FALLING 2
#define RISING 3
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define INTERNAL1V1 2
#define INTERNAL2V56 3
#else
#define INTERNAL 3
#endif
#define DEFAULT 1
#define EXTERNAL 0
// undefine stdlib's abs if encountered
#ifdef abs
#undef abs
#endif
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(x) ((x)>0?(x):-(x))
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
#define radians(deg) ((deg)*DEG_TO_RAD)
#define degrees(rad) ((rad)*RAD_TO_DEG)
#define sq(x) ((x)*(x))
#define interrupts() sei()
#define noInterrupts() cli()
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
#define microsecondsToClockCycles(a) ( ((a) * (F_CPU / 1000L)) / 1000L )
#define lowByte(w) ((uint8_t) ((w) & 0xff))
#define highByte(w) ((uint8_t) ((w) >> 8))
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
typedef unsigned int word;
#define bit(b) (1UL << (b))
typedef uint8_t boolean;
typedef uint8_t byte;
void init(void);
void pinMode(uint8_t, uint8_t);
void digitalWrite(uint8_t, uint8_t);
int digitalRead(uint8_t);
int analogRead(uint8_t);
void analogReference(uint8_t mode);
void analogWrite(uint8_t, int);
unsigned long millis(void);
unsigned long micros(void);
void delay(unsigned long);
void delayMicroseconds(unsigned int us);
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
void attachInterrupt(uint8_t, void (*)(void), int mode);
void detachInterrupt(uint8_t);
void setup(void);
void loop(void);
#ifdef __cplusplus
} // extern "C"
#endif
#endif

View File

@ -0,0 +1,259 @@
/*
wiring_analog.c - analog input and output
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
Modified 28 September 2010 by Mark Sproul
$Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
*/
#include "wiring_private.h"
#include "pins_arduino.h"
uint8_t analog_reference = DEFAULT;
void analogReference(uint8_t mode)
{
// can't actually set the register here because the default setting
// will connect AVCC and the AREF pin, which would cause a short if
// there's something connected to AREF.
analog_reference = mode;
}
int analogRead(uint8_t pin)
{
uint8_t low, high;
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
if (pin >= 54) pin -= 54; // allow for channel or pin numbers
#else
if (pin >= 14) pin -= 14; // allow for channel or pin numbers
#endif
#if defined(ADCSRB) && defined(MUX5)
// the MUX5 bit of ADCSRB selects whether we're reading from channels
// 0 to 7 (MUX5 low) or 8 to 15 (MUX5 high).
ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5);
#endif
// set the analog reference (high two bits of ADMUX) and select the
// channel (low 4 bits). this also sets ADLAR (left-adjust result)
// to 0 (the default).
#if defined(ADMUX)
ADMUX = (analog_reference << 6) | (pin & 0x07);
#endif
// without a delay, we seem to read from the wrong channel
//delay(1);
#if defined(ADCSRA) && defined(ADCL)
// start the conversion
sbi(ADCSRA, ADSC);
// ADSC is cleared when the conversion finishes
while (bit_is_set(ADCSRA, ADSC));
// we have to read ADCL first; doing so locks both ADCL
// and ADCH until ADCH is read. reading ADCL second would
// cause the results of each conversion to be discarded,
// as ADCL and ADCH would be locked when it completed.
low = ADCL;
high = ADCH;
#else
// we dont have an ADC, return 0
low = 0;
high = 0;
#endif
// combine the two bytes
return (high << 8) | low;
}
// Right now, PWM output only works on the pins with
// hardware support. These are defined in the appropriate
// pins_*.c file. For the rest of the pins, we default
// to digital output.
void analogWrite(uint8_t pin, int val)
{
// We need to make sure the PWM output is enabled for those pins
// that support it, as we turn it off when digitally reading or
// writing with them. Also, make sure the pin is in output mode
// for consistenty with Wiring, which doesn't require a pinMode
// call for the analog output pins.
pinMode(pin, OUTPUT);
if (val == 0)
{
digitalWrite(pin, LOW);
}
else if (val == 255)
{
digitalWrite(pin, HIGH);
}
else
{
switch(digitalPinToTimer(pin))
{
// XXX fix needed for atmega8
#if defined(TCCR0) && defined(COM00) && !defined(__AVR_ATmega8__)
case TIMER0A:
// connect pwm to pin on timer 0
sbi(TCCR0, COM00);
OCR0 = val; // set pwm duty
break;
#endif
#if defined(TCCR0A) && defined(COM0A1)
case TIMER0A:
// connect pwm to pin on timer 0, channel A
sbi(TCCR0A, COM0A1);
OCR0A = val; // set pwm duty
break;
#endif
#if defined(TCCR0A) && defined(COM0B1)
case TIMER0B:
// connect pwm to pin on timer 0, channel B
sbi(TCCR0A, COM0B1);
OCR0B = val; // set pwm duty
break;
#endif
#if defined(TCCR1A) && defined(COM1A1)
case TIMER1A:
// connect pwm to pin on timer 1, channel A
sbi(TCCR1A, COM1A1);
OCR1A = val; // set pwm duty
break;
#endif
#if defined(TCCR1A) && defined(COM1B1)
case TIMER1B:
// connect pwm to pin on timer 1, channel B
sbi(TCCR1A, COM1B1);
OCR1B = val; // set pwm duty
break;
#endif
#if defined(TCCR2) && defined(COM21)
case TIMER2:
// connect pwm to pin on timer 2
sbi(TCCR2, COM21);
OCR2 = val; // set pwm duty
break;
#endif
#if defined(TCCR2A) && defined(COM2A1)
case TIMER2A:
// connect pwm to pin on timer 2, channel A
sbi(TCCR2A, COM2A1);
OCR2A = val; // set pwm duty
break;
#endif
#if defined(TCCR2A) && defined(COM2B1)
case TIMER2B:
// connect pwm to pin on timer 2, channel B
sbi(TCCR2A, COM2B1);
OCR2B = val; // set pwm duty
break;
#endif
#if defined(TCCR3A) && defined(COM3A1)
case TIMER3A:
// connect pwm to pin on timer 3, channel A
sbi(TCCR3A, COM3A1);
OCR3A = val; // set pwm duty
break;
#endif
#if defined(TCCR3A) && defined(COM3B1)
case TIMER3B:
// connect pwm to pin on timer 3, channel B
sbi(TCCR3A, COM3B1);
OCR3B = val; // set pwm duty
break;
#endif
#if defined(TCCR3A) && defined(COM3C1)
case TIMER3C:
// connect pwm to pin on timer 3, channel C
sbi(TCCR3A, COM3C1);
OCR3C = val; // set pwm duty
break;
#endif
#if defined(TCCR4A) && defined(COM4A1)
case TIMER4A:
// connect pwm to pin on timer 4, channel A
sbi(TCCR4A, COM4A1);
OCR4A = val; // set pwm duty
break;
#endif
#if defined(TCCR4A) && defined(COM4B1)
case TIMER4B:
// connect pwm to pin on timer 4, channel B
sbi(TCCR4A, COM4B1);
OCR4B = val; // set pwm duty
break;
#endif
#if defined(TCCR4A) && defined(COM4C1)
case TIMER4C:
// connect pwm to pin on timer 4, channel C
sbi(TCCR4A, COM4C1);
OCR4C = val; // set pwm duty
break;
#endif
#if defined(TCCR5A) && defined(COM5A1)
case TIMER5A:
// connect pwm to pin on timer 5, channel A
sbi(TCCR5A, COM5A1);
OCR5A = val; // set pwm duty
break;
#endif
#if defined(TCCR5A) && defined(COM5B1)
case TIMER5B:
// connect pwm to pin on timer 5, channel B
sbi(TCCR5A, COM5B1);
OCR5B = val; // set pwm duty
break;
#endif
#if defined(TCCR5A) && defined(COM5C1)
case TIMER5C:
// connect pwm to pin on timer 5, channel C
sbi(TCCR5A, COM5C1);
OCR5C = val; // set pwm duty
break;
#endif
case NOT_ON_TIMER:
default:
if (val < 128) {
digitalWrite(pin, LOW);
} else {
digitalWrite(pin, HIGH);
}
}
}
}

View File

@ -0,0 +1,166 @@
/*
wiring_digital.c - digital input and output functions
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
Modified 28 September 2010 by Mark Sproul
$Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
*/
#include "wiring_private.h"
#include "pins_arduino.h"
void pinMode(uint8_t pin, uint8_t mode)
{
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *reg;
if (port == NOT_A_PIN) return;
// JWS: can I let the optimizer do this?
reg = portModeRegister(port);
if (mode == INPUT) {
uint8_t oldSREG = SREG;
cli();
*reg &= ~bit;
SREG = oldSREG;
} else {
uint8_t oldSREG = SREG;
cli();
*reg |= bit;
SREG = oldSREG;
}
}
// Forcing this inline keeps the callers from having to push their own stuff
// on the stack. It is a good performance win and only takes 1 more byte per
// user than calling. (It will take more bytes on the 168.)
//
// But shouldn't this be moved into pinMode? Seems silly to check and do on
// each digitalread or write.
//
// Mark Sproul:
// - Removed inline. Save 170 bytes on atmega1280
// - changed to a switch statment; added 32 bytes but much easier to read and maintain.
// - Added more #ifdefs, now compiles for atmega645
//
//static inline void turnOffPWM(uint8_t timer) __attribute__ ((always_inline));
//static inline void turnOffPWM(uint8_t timer)
static void turnOffPWM(uint8_t timer)
{
switch (timer)
{
#if defined(TCCR1A) && defined(COM1A1)
case TIMER1A: cbi(TCCR1A, COM1A1); break;
#endif
#if defined(TCCR1A) && defined(COM1B1)
case TIMER1B: cbi(TCCR1A, COM1B1); break;
#endif
#if defined(TCCR2) && defined(COM21)
case TIMER2: cbi(TCCR2, COM21); break;
#endif
#if defined(TCCR0A) && defined(COM0A1)
case TIMER0A: cbi(TCCR0A, COM0A1); break;
#endif
#if defined(TIMER0B) && defined(COM0B1)
case TIMER0B: cbi(TCCR0A, COM0B1); break;
#endif
#if defined(TCCR2A) && defined(COM2A1)
case TIMER2A: cbi(TCCR2A, COM2A1); break;
#endif
#if defined(TCCR2A) && defined(COM2B1)
case TIMER2B: cbi(TCCR2A, COM2B1); break;
#endif
#if defined(TCCR3A) && defined(COM3A1)
case TIMER3A: cbi(TCCR3A, COM3A1); break;
#endif
#if defined(TCCR3A) && defined(COM3B1)
case TIMER3B: cbi(TCCR3A, COM3B1); break;
#endif
#if defined(TCCR3A) && defined(COM3C1)
case TIMER3C: cbi(TCCR3A, COM3C1); break;
#endif
#if defined(TCCR4A) && defined(COM4A1)
case TIMER4A: cbi(TCCR4A, COM4A1); break;
#endif
#if defined(TCCR4A) && defined(COM4B1)
case TIMER4B: cbi(TCCR4A, COM4B1); break;
#endif
#if defined(TCCR4A) && defined(COM4C1)
case TIMER4C: cbi(TCCR4A, COM4C1); break;
#endif
#if defined(TCCR5A)
case TIMER5A: cbi(TCCR5A, COM5A1); break;
case TIMER5B: cbi(TCCR5A, COM5B1); break;
case TIMER5C: cbi(TCCR5A, COM5C1); break;
#endif
}
}
void digitalWrite(uint8_t pin, uint8_t val)
{
uint8_t timer = digitalPinToTimer(pin);
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *out;
if (port == NOT_A_PIN) return;
// If the pin that support PWM output, we need to turn it off
// before doing a digital write.
if (timer != NOT_ON_TIMER) turnOffPWM(timer);
out = portOutputRegister(port);
if (val == LOW) {
uint8_t oldSREG = SREG;
cli();
*out &= ~bit;
SREG = oldSREG;
} else {
uint8_t oldSREG = SREG;
cli();
*out |= bit;
SREG = oldSREG;
}
}
int digitalRead(uint8_t pin)
{
uint8_t timer = digitalPinToTimer(pin);
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
if (port == NOT_A_PIN) return LOW;
// If the pin that support PWM output, we need to turn it off
// before getting a digital reading.
if (timer != NOT_ON_TIMER) turnOffPWM(timer);
if (*portInputRegister(port) & bit) return HIGH;
return LOW;
}

View File

@ -0,0 +1,68 @@
/*
wiring_private.h - Internal header file.
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: wiring.h 239 2007-01-12 17:58:39Z mellis $
*/
#ifndef WiringPrivate_h
#define WiringPrivate_h
#include <math.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdio.h>
#include <stdarg.h>
#include "wiring.h"
#ifdef __cplusplus
extern "C"{
#endif
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
#define EXTERNAL_INT_0 0
#define EXTERNAL_INT_1 1
#define EXTERNAL_INT_2 2
#define EXTERNAL_INT_3 3
#define EXTERNAL_INT_4 4
#define EXTERNAL_INT_5 5
#define EXTERNAL_INT_6 6
#define EXTERNAL_INT_7 7
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define EXTERNAL_NUM_INTERRUPTS 8
#else
#define EXTERNAL_NUM_INTERRUPTS 2
#endif
typedef void (*voidFuncPtr)(void);
#ifdef __cplusplus
} // extern "C"
#endif
#endif

View File

@ -0,0 +1,69 @@
/*
wiring_pulse.c - pulseIn() function
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
*/
#include "wiring_private.h"
#include "pins_arduino.h"
/* Measures the length (in microseconds) of a pulse on the pin; state is HIGH
* or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds
* to 3 minutes in length, but must be called at least a few dozen microseconds
* before the start of the pulse. */
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
{
// cache the port and bit of the pin in order to speed up the
// pulse width measuring loop and achieve finer resolution. calling
// digitalRead() instead yields much coarser resolution.
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
uint8_t stateMask = (state ? bit : 0);
unsigned long width = 0; // keep initialization out of time critical area
// convert the timeout from microseconds to a number of times through
// the initial loop; it takes 16 clock cycles per iteration.
unsigned long numloops = 0;
unsigned long maxloops = microsecondsToClockCycles(timeout) / 16;
// wait for any previous pulse to end
while ((*portInputRegister(port) & bit) == stateMask)
if (numloops++ == maxloops)
return 0;
// wait for the pulse to start
while ((*portInputRegister(port) & bit) != stateMask)
if (numloops++ == maxloops)
return 0;
// wait for the pulse to stop
while ((*portInputRegister(port) & bit) == stateMask) {
if (numloops++ == maxloops)
return 0;
width++;
}
// convert the reading to microseconds. The loop has been determined
// to be 20 clock cycles long and have about 16 clocks between the edge
// and the start of the loop. There will be some error introduced by
// the interrupt handlers.
return clockCyclesToMicroseconds(width * 21 + 16);
}

View File

@ -0,0 +1,55 @@
/*
wiring_shift.c - shiftOut() function
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
*/
#include "wiring_private.h"
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) {
uint8_t value = 0;
uint8_t i;
for (i = 0; i < 8; ++i) {
digitalWrite(clockPin, HIGH);
if (bitOrder == LSBFIRST)
value |= digitalRead(dataPin) << i;
else
value |= digitalRead(dataPin) << (7 - i);
digitalWrite(clockPin, LOW);
}
return value;
}
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
{
uint8_t i;
for (i = 0; i < 8; i++) {
if (bitOrder == LSBFIRST)
digitalWrite(dataPin, !!(val & (1 << i)));
else
digitalWrite(dataPin, !!(val & (1 << (7 - i))));
digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
}
}

View File

@ -0,0 +1,101 @@
##############################################################
Gen7-644-16.name=Gen7 with ATmega644 and 16 MHz
Gen7-644-16.upload.protocol=stk500v2
Gen7-644-16.upload.maximum_size=63488
Gen7-644-16.upload.speed=115200
Gen7-644-16.bootloader.low_fuses=0xF7
Gen7-644-16.bootloader.high_fuses=0xD4
Gen7-644-16.bootloader.extended_fuses=0xFD
Gen7-644-16.bootloader.path=Gen7
Gen7-644-16.bootloader.file=bootloader-644-16MHz.hex
Gen7-644-16.bootloader.unlock_bits=0x3F
Gen7-644-16.bootloader.lock_bits=0x0F
Gen7-644-16.build.mcu=atmega644
Gen7-644-16.build.f_cpu=16000000L
Gen7-644-16.build.core=arduino
##############################################################
Gen7-644-20.name=Gen7 with ATmega644 and 20 MHz
Gen7-644-20.upload.protocol=stk500v2
Gen7-644-20.upload.maximum_size=63488
Gen7-644-20.upload.speed=115200
Gen7-644-20.bootloader.low_fuses=0xF7
Gen7-644-20.bootloader.high_fuses=0xD4
Gen7-644-20.bootloader.extended_fuses=0xFD
Gen7-644-20.bootloader.path=Gen7
Gen7-644-20.bootloader.file=bootloader-644-20MHz.hex
Gen7-644-20.bootloader.unlock_bits=0x3F
Gen7-644-20.bootloader.lock_bits=0x0F
Gen7-644-20.build.mcu=atmega644
Gen7-644-20.build.f_cpu=20000000L
Gen7-644-20.build.core=arduino
##############################################################
Gen7-644P-16.name=Gen7 with ATmega644P and 16 MHz
Gen7-644P-16.upload.protocol=stk500v2
Gen7-644P-16.upload.maximum_size=63488
Gen7-644P-16.upload.speed=115200
Gen7-644P-16.bootloader.low_fuses=0xF7
Gen7-644P-16.bootloader.high_fuses=0xD4
Gen7-644P-16.bootloader.extended_fuses=0xFD
Gen7-644P-16.bootloader.path=Gen7
Gen7-644P-16.bootloader.file=bootloader-644P-16MHz.hex
Gen7-644P-16.bootloader.unlock_bits=0x3F
Gen7-644P-16.bootloader.lock_bits=0x0F
Gen7-644P-16.build.mcu=atmega644p
Gen7-644P-16.build.f_cpu=16000000L
Gen7-644P-16.build.core=arduino
##############################################################
Gen7-644P-20.name=Gen7 with ATmega644P and 20 MHz
Gen7-644P-20.upload.protocol=stk500v2
Gen7-644P-20.upload.maximum_size=63488
Gen7-644P-20.upload.speed=115200
Gen7-644P-20.bootloader.low_fuses=0xF7
Gen7-644P-20.bootloader.high_fuses=0xD4
Gen7-644P-20.bootloader.extended_fuses=0xFD
Gen7-644P-20.bootloader.path=Gen7
Gen7-644P-20.bootloader.file=bootloader-644P-20MHz.hex
Gen7-644P-20.bootloader.unlock_bits=0x3F
Gen7-644P-20.bootloader.lock_bits=0x0F
Gen7-644P-20.build.mcu=atmega644p
Gen7-644P-20.build.f_cpu=20000000L
Gen7-644P-20.build.core=arduino
##############################################################
Gen7-1284p-16.name=Gen7 with ATmega1284 and 16 MHz
Gen7-1284p-16.upload.protocol=stk500v2
Gen7-1284p-16.upload.maximum_size=129024
Gen7-1284p-16.upload.speed=115200
Gen7-1284p-16.bootloader.low_fuses=0xF7
Gen7-1284p-16.bootloader.high_fuses=0xD4
Gen7-1284p-16.bootloader.extended_fuses=0xFD
Gen7-1284p-16.bootloader.path=Gen7
Gen7-1284p-16.bootloader.file=bootloader-1284P-16MHz.hex
Gen7-1284p-16.bootloader.unlock_bits=0x3F
Gen7-1284p-16.bootloader.lock_bits=0x2F
Gen7-1284p-16.build.mcu=atmega1284p
Gen7-1284p-16.build.f_cpu=16000000L
Gen7-1284p-16.build.core=arduino
##############################################################
Gen7-1284p-20.name=Gen7 with ATmega1284 and 20 MHz
Gen7-1284p-20.upload.protocol=stk500v2
Gen7-1284p-20.upload.maximum_size=129024
Gen7-1284p-20.upload.speed=115200
Gen7-1284p-20.bootloader.low_fuses=0xF7
Gen7-1284p-20.bootloader.high_fuses=0xD4
Gen7-1284p-20.bootloader.extended_fuses=0xFD
Gen7-1284p-20.bootloader.path=Gen7
Gen7-1284p-20.bootloader.file=bootloader-1284P-16MHz.hex
Gen7-1284p-20.bootloader.unlock_bits=0x3F
Gen7-1284p-20.bootloader.lock_bits=0x2F
Gen7-1284p-20.build.mcu=atmega1284p
Gen7-1284p-20.build.f_cpu=20000000L
Gen7-1284p-20.build.core=arduino

View File

@ -0,0 +1,113 @@
:020000021000EC
:10F8000011241FBE8FEF90E49EBF8DBF01C32F92C6
:10F810003F924F925F926F927F928F929F92AF92A0
:10F82000BF92CF92DF92EF92FF920F931F93DF93DD
:10F83000CF93CDB7DEB7C252D1400FB6F894DEBF3A
:10F840000FBECDBF44245524DD24C25EDE4F188296
:10F85000CE51D1408824992454013AC20E9428FFF5
:10F86000282F133059F1143028F4113081F0123060
:10F8700000F507C0153081F1153030F1163071F701
:10F880003DC08B3159F711E05BE1D52EE7CF8130D8
:10F8900041F0C25EDE4F3881CE51D140831709F06E
:10F8A00019C2D226C25EDE4F2883CE51D14012E06B
:10F8B000D5CFF82EEE24D82613E0D0CF90E0E82A5A
:10F8C000F92AD22614E0CACF8E3009F003C2D82616
:10F8D00015E044245524C2CFE1E0F0E0EC0FFD1F19
:10F8E000E40DF51D80830894411C511CD8264E144C
:10F8F0005F0409F0B3CF720116E0B0CF8D1509F0A7
:10F90000E9C1EAC1CC2447C08D81803311F090E079
:10F910000AC08F81882311F49EE105C0813011F067
:10F9200095E001C097E91A821B828D818C838E81BC
:10F930008D839E831F8247E0E42EF12C88C11A82BA
:10F9400068E06B8383E58C8394E59D83EBE4EE8331
:10F9500085E38F8380E3888789878FE58A8782E3C1
:10F960008B873BE0E32EF12C72C18A81813941F013
:10F97000823941F0803911F48FE005C080E003C086
:10F9800082E001C08AE01A828B8323E0E22EF12C10
:10F990005EC1CC24C3941A8292E0E92EF12C58C1A6
:10F9A0008D81882311F48EE128C0813011F085E02B
:10F9B00024C087E922C01A8229E0E1E0F0E0209328
:10F9C000570084911BC08B81803589F48C818830ED
:10F9D00039F439E0E2E0F0E03093570084910DC053
:10F9E00069E0E0E0F0E060935700849106C099E0A0
:10F9F000E3E0F0E09093570084911A828B831C829D
:10FA000084E0E82EF12C23C18A8190E0A0E0B0E0F0
:10FA1000B82EAA24992488248B8190E0A0E0B0E03D
:10FA2000DC0199278827882A992AAA2ABB2A8D814E
:10FA300090E0A0E0B0E0882A992AAA2ABB2A8C810B
:10FA400090E0A0E0B0E0BA2FA92F982F8827882A4D
:10FA5000992AAA2ABB2A88C0EA81C05EDE4FE883C1
:10FA6000C052D140C15EDE4F1882CF51D1408B8150
:10FA7000A82FB0E0C15EDE4F28813981CF51D1403F
:10FA8000A22BB32B933109F042C075016401CC0C59
:10FA9000DD1CEE1CFF1C33E0F601E0925B003093AE
:10FAA0005700E89507B600FCFDCF8E01055F1F4F9C
:10FAB000F801808161810E5F1F4FA5019401220F23
:10FAC000331F441F551F362E222490E0822993298C
:10FAD00061E00C01F90140935B0060935700E895E9
:10FAE00011240894811C911CA11CB11C129701F7D0
:10FAF00085E0F601E0925B0080935700E89507B639
:10FB000000FCFDCF81E180935700E8952DC0FE01F8
:10FB10003B9620E030E040E050E011977D0100E0AE
:10FB200010E00894E11CF11C011D111D6081F99980
:10FB3000FECF1FBAC901880D991D92BD81BD60BD60
:10FB40000FB6F894FA9AF99A0FBE2F5F3F4F4F4FB6
:10FB50005F4F2E153F054007510711F03196E6CF54
:10FB6000820E931EA41EB51E1A826EC09A81CE5DAF
:10FB7000DE4F9883C252D140CF5DDE4F1882C15212
:10FB8000D1408B81C82EDD24CF5DDE4FE881F98125
:10FB9000C152D140CE2ADF2A1A8289818431E1F410
:10FBA0009601BE016D5F7F4FD501C401880F991F7B
:10FBB000AA1FBB1FABBFFC0187919691FB018083FD
:10FBC00091836E5F7F4F0894811C911CA11CB11C16
:10FBD0002250304049F72EC0BE016D5F7F4F20E0BC
:10FBE00030E040E050E00894C108D108760100E020
:10FBF00010E00894C11CD11C0894E11CF11C011DEB
:10FC0000111DF999FECFC901880D991D92BD81BDC5
:10FC1000F89A80B5FB018193BF012F5F3F4F4F4F93
:10FC20005F4F2E153F054007510759F7820E931E6F
:10FC3000A41EB51E23E0E22EF12CEC0CFD1CFB01F2
:10FC4000108205C080EC8A8392E0E92EF12CCC244E
:10FC50008BE10E94C7FEC25EDE4F8881CE51D1404B
:10FC60000E94C7FE8F2D0E94C7FE8E2D0E94C7FEE8
:10FC70008EE00E94C7FE85E1D82EC25EDE4FF8817D
:10FC8000CE51D140DF26DE24DF243E010894611CE2
:10FC9000711C0AC0F30111913F01812F0E94C7FE20
:10FCA000D1260894E108F108E114F10499F78D2DAB
:10FCB0000E94C7FECC2009F044C0C25EDE4FF8812E
:10FCC000CE51D140FF5FC25EDE4FF883CE51D140AE
:10FCD000EE24FF2410E0C2CD9981933109F4BCCE0B
:10FCE0009431B0F4933009F440CE943038F491302C
:10FCF00009F425CE923009F0A5CF04CE903109F455
:10FD000001CE913109F445CE963009F09BCF7CCEDF
:10FD1000983109F458CE993150F4953109F49CCEBC
:10FD2000953108F423CF963109F08CCF1FCF9B314A
:10FD300009F436CE9D3109F4E7CD9A3109F082CF2E
:10FD40003ACECE5DDE4F0FB6F894DEBF0FBECDBF0C
:10FD5000CF91DF911F910F91FF90EF90DF90CF90A7
:10FD6000BF90AF909F908F907F906F905F904F90DB
:10FD70003F902F9008958091C00087FFFCCF089599
:10FD80008091C00087FFFCCF8091C6000895982F16
:10FD90008091C00085FFFCCF9093C60008959B0121
:10FDA000AC0197FF11C08091C00082608093C000B9
:10FDB00050954095309521953F4F4F4F5F4F60E0F4
:10FDC00074E284EF90E009C08091C0008D7F809341
:10FDD000C00060E072E18AE790E00E9447FF2C5F7C
:10FDE0003F4F4F4F5F4F83E0569547953795279587
:10FDF0008A95D1F7215030403093C5002093C4003C
:10FE0000089518B817B81F921F921F920895FFCF38
:10FE100084B714BE90E083709070892B39F418B8C1
:10FE200017B81F921F921F920895FFCF88E1809309
:10FE3000C10060E07EE38EEF9FEF0E94CFFE0E9444
:10FE400007FC18B817B81F921F921F920895FFCF92
:10FE500020E030E040E050E013C02F5F3F4F4F4FB5
:10FE60005F4F21308AE6380788E1480780E058076D
:10FE700039F418B817B81F921F921F920895FFCF38
:10FE80008091C00087FFE9CF0E94C0FE0895A1E2E3
:10FE90001A2EAA1BBB1BFD010DC0AA1FBB1FEE1F04
:10FEA000FF1FA217B307E407F50720F0A21BB30B4F
:10FEB000E40BF50B661F771F881F991F1A9469F7CB
:10FEC00060957095809590959B01AC01BD01CF0127
:02FED000089593
:040000031000F800F1
:00000001FF

View File

@ -0,0 +1,75 @@
:10F800008FEF90E19EBF8DBF11241FBE5A9A00C09A
:10F81000CDB7DEB7CD51D140DEBFCDBF1092C50010
:10F8200088E08093C40088E18093C100EE24FF2427
:10F8300020E0552400E010E039E0432E9BE0292E23
:10F84000312C2C0E3D1ECFC14150504060407040C5
:10F8500011F43FE206C08091C00087FFF5CF3091E0
:10F86000C600933021F1943028F4913099F0923011
:10F87000C8F407C0953049F1953000F19630D1F5C4
:10F8800035C03B3119F491E02BE134C03F3291F5A2
:10F890003983BBC1313011F0351559F52327532E6B
:10F8A00092E028C0B32FA0E0232793E023C0832F4A
:10F8B00090E0A82BB92B232794E01CC03E30C9F45C
:10F8C000232795E0EE24FF2415C0E1E0F0E0EC0FE3
:10F8D000FD1FEE0DFF1D30830894E11CF11C232752
:10F8E000EA16FB0639F4D70196E004C0321709F492
:10F8F0008CC190E044E755E962E470E0ACCF90E061
:10F9000044C08D81803311F090E00AC08F8188233C
:10F9100011F49EE105C0813011F099E001C096E933
:10F920001A821B828D818C838E818D839E831F82A0
:10F9300047E050E0F4C01A8288E08B8381E48C8336
:10F9400086E58D8382E58E8389E48F8383E58887CE
:10F9500080E589878FE58A8782E38B874BE050E0DB
:10F96000DEC08A81813941F0823941F0803911F459
:10F970008FE005C080E003C082E001C08AE01A8207
:10F980008B8343E050E0CBC091E01A8242E050E02C
:10F99000C7C08D81882311F48EE124C0813011F01D
:10F9A00089E020C086E91EC01A82E1E0F0E04092C2
:10F9B0005700849118C08B81803579F48C81883010
:10F9C00031F4E2E0F0E04092570084910BC0E0E0B7
:10F9D000F0E040925700849105C0E3E0F0E04092EF
:10F9E000570084911A828B831C8244E050E097C0B8
:10F9F000BC80AA248D81082F10E00A291B29000F42
:10FA0000111F1A828AC09A8088248B81682F70E027
:10FA100068297929933109F033C0F7EF0F3F1F07A9
:10FA200010F0A8013FC023E0F80120935700E895AB
:10FA300007B600FCFDCFA801D1018C9111962C9145
:10FA400011971296D22ECC2490E08C299D2921E08A
:10FA5000FA010C0120935700E89511244E5F5F4F87
:10FA60006250704051F725E0F80120935700E89567
:10FA700007B600FCFDCF81E180935700E89512C0E6
:10FA8000A801FB01D10141BD52BD4F5F5F4F8D9178
:10FA900080BDFA9AF99AF999FECF3197A1F7A8019A
:10FAA000460F571F1A828A0138C07A8066248B81DC
:10FAB000A82FB0E0A629B7291A828981843191F450
:10FAC000BD019E012D5F3F4FF80185919491F90191
:10FAD000808391832E5F3F4F0E5F1F4F62507040B7
:10FAE00099F713C0A801BD019E012D5F3F4F41BD95
:10FAF00052BD4F5F5F4FF89A80B5F90181939F0126
:10FB000061507040A1F70A0F1B1FAD014D5F5F4FA1
:10FB1000F901108204C080EC8A8342E050E090E05A
:10FB2000FBE1F093C6008091C00086FFFCCF80917E
:10FB3000C00080648093C0005092C6008091C000D5
:10FB400086FFFCCF8091C00080648093C000652F49
:10FB50005093C6008091C00086FFFCCF8091C0000A
:10FB600080648093C000342F4093C6008091C00011
:10FB700086FFFCCF8091C00080648093C0008EE03F
:10FB80008093C6008091C00086FFFCCF8091C000AA
:10FB900080648093C00025E1252523272627FE01C8
:10FBA000319610C030813093C6008091C00086FF2E
:10FBB000FCCF31968091C00080648093C0002327E1
:10FBC000415050404115510569F72093C60080917E
:10FBD000C00086FFFCCF8091C00080648093C0008D
:10FBE000992349F4539444E755E962E470E090E0C6
:10FBF000A0E0B0E030CE5A9881E180935700E895BC
:10FC000011241F921F920895FFCF9981933109F417
:10FC1000FACE9431C8F4963009F4EACE973050F415
:10FC2000923009F46CCE933009F49BCE913009F0F8
:10FC300072CF81CE913109F4A7CE923108F0E1CE96
:10FC4000903109F068CF5BCE983109F4B4CE993188
:10FC500050F4953109F4D7CE953108F426CF96317A
:10FC600009F059CF22CF9B3109F493CE9C3120F477
:10FC70009A3109F050CF98CE9D3109F442CE9F328F
:06FC800009F049CFB8CFE6
:040000030000F80001
:00000001FF

View File

@ -0,0 +1,75 @@
:10F800008FEF90E19EBF8DBF11241FBE5A9A00C09A
:10F81000CDB7DEB7CD51D140DEBFCDBF1092C50010
:10F820008AE08093C40088E18093C100EE24FF2425
:10F8300020E0552400E010E039E0432E9BE0292E23
:10F84000312C2C0E3D1ECFC14150504060407040C5
:10F8500011F43FE206C08091C00087FFF5CF3091E0
:10F86000C600933021F1943028F4913099F0923011
:10F87000C8F407C0953049F1953000F19630D1F5C4
:10F8800035C03B3119F491E02BE134C03F3291F5A2
:10F890003983BBC1313011F0351559F52327532E6B
:10F8A00092E028C0B32FA0E0232793E023C0832F4A
:10F8B00090E0A82BB92B232794E01CC03E30C9F45C
:10F8C000232795E0EE24FF2415C0E1E0F0E0EC0FE3
:10F8D000FD1FEE0DFF1D30830894E11CF11C232752
:10F8E000EA16FB0639F4D70196E004C0321709F492
:10F8F0008CC190E041ED5AE363E570E0ACCF90E05D
:10F9000044C08D81803311F090E00AC08F8188233C
:10F9100011F49EE105C0813011F099E001C096E933
:10F920001A821B828D818C838E818D839E831F82A0
:10F9300047E050E0F4C01A8288E08B8381E48C8336
:10F9400086E58D8382E58E8389E48F8383E58887CE
:10F9500080E589878FE58A8782E38B874BE050E0DB
:10F96000DEC08A81813941F0823941F0803911F459
:10F970008FE005C080E003C082E001C08AE01A8207
:10F980008B8343E050E0CBC091E01A8242E050E02C
:10F99000C7C08D81882311F48EE124C0813011F01D
:10F9A00089E020C086E91EC01A82E1E0F0E04092C2
:10F9B0005700849118C08B81803579F48C81883010
:10F9C00031F4E2E0F0E04092570084910BC0E0E0B7
:10F9D000F0E040925700849105C0E3E0F0E04092EF
:10F9E000570084911A828B831C8244E050E097C0B8
:10F9F000BC80AA248D81082F10E00A291B29000F42
:10FA0000111F1A828AC09A8088248B81682F70E027
:10FA100068297929933109F033C0F7EF0F3F1F07A9
:10FA200010F0A8013FC023E0F80120935700E895AB
:10FA300007B600FCFDCFA801D1018C9111962C9145
:10FA400011971296D22ECC2490E08C299D2921E08A
:10FA5000FA010C0120935700E89511244E5F5F4F87
:10FA60006250704051F725E0F80120935700E89567
:10FA700007B600FCFDCF81E180935700E89512C0E6
:10FA8000A801FB01D10141BD52BD4F5F5F4F8D9178
:10FA900080BDFA9AF99AF999FECF3197A1F7A8019A
:10FAA000460F571F1A828A0138C07A8066248B81DC
:10FAB000A82FB0E0A629B7291A828981843191F450
:10FAC000BD019E012D5F3F4FF80185919491F90191
:10FAD000808391832E5F3F4F0E5F1F4F62507040B7
:10FAE00099F713C0A801BD019E012D5F3F4F41BD95
:10FAF00052BD4F5F5F4FF89A80B5F90181939F0126
:10FB000061507040A1F70A0F1B1FAD014D5F5F4FA1
:10FB1000F901108204C080EC8A8342E050E090E05A
:10FB2000FBE1F093C6008091C00086FFFCCF80917E
:10FB3000C00080648093C0005092C6008091C000D5
:10FB400086FFFCCF8091C00080648093C000652F49
:10FB50005093C6008091C00086FFFCCF8091C0000A
:10FB600080648093C000342F4093C6008091C00011
:10FB700086FFFCCF8091C00080648093C0008EE03F
:10FB80008093C6008091C00086FFFCCF8091C000AA
:10FB900080648093C00025E1252523272627FE01C8
:10FBA000319610C030813093C6008091C00086FF2E
:10FBB000FCCF31968091C00080648093C0002327E1
:10FBC000415050404115510569F72093C60080917E
:10FBD000C00086FFFCCF8091C00080648093C0008D
:10FBE000992349F4539441ED5AE363E570E090E0C2
:10FBF000A0E0B0E030CE5A9881E180935700E895BC
:10FC000011241F921F920895FFCF9981933109F417
:10FC1000FACE9431C8F4963009F4EACE973050F415
:10FC2000923009F46CCE933009F49BCE913009F0F8
:10FC300072CF81CE913109F4A7CE923108F0E1CE96
:10FC4000903109F068CF5BCE983109F4B4CE993188
:10FC500050F4953109F4D7CE953108F426CF96317A
:10FC600009F059CF22CF9B3109F493CE9C3120F477
:10FC70009A3109F050CF98CE9D3109F442CE9F328F
:06FC800009F049CFB8CFE6
:040000030000F80001
:00000001FF

View File

@ -0,0 +1,75 @@
:10F800008FEF90E19EBF8DBF11241FBE5A9A00C09A
:10F81000CDB7DEB7CD51D140DEBFCDBF1092C50010
:10F8200088E08093C40088E18093C100EE24FF2427
:10F8300020E0552400E010E039E0432E93E0292E2B
:10F84000312C2C0E3D1ECDC14150504060407040C7
:10F8500011F43FE206C08091C00087FFF5CF3091E0
:10F86000C600933021F1943028F4913099F0923011
:10F87000C8F407C0953049F1953000F19630D1F5C4
:10F8800035C03B3119F491E02BE134C03F3291F5A2
:10F890003983B9C1313011F0351559F52327532E6D
:10F8A00092E028C0B32FA0E0232793E023C0832F4A
:10F8B00090E0A82BB92B232794E01CC03E30C9F45C
:10F8C000232795E0EE24FF2415C0E1E0F0E0EC0FE3
:10F8D000FD1FEE0DFF1D30830894E11CF11C232752
:10F8E000EA16FB0639F4D70196E004C0321709F492
:10F8F0008AC190E044E755E962E470E0ACCF90E063
:10F9000044C08D81803311F090E00AC08F8188233C
:10F9100011F49EE105C0813011F09AE001C096E932
:10F920001A821B828D818C838E818D839E831F82A0
:10F9300047E050E0F2C01A8288E08B8381E48C8338
:10F9400086E58D8382E58E8389E48F8383E58887CE
:10F9500080E589878FE58A8782E38B874BE050E0DB
:10F96000DCC08A81813941F0823941F0803911F45B
:10F970008FE005C080E003C082E001C08AE01A8207
:10F980008B8343E050E0C9C091E01A8242E050E02E
:10F99000C5C08D81882311F48EE124C0813011F01F
:10F9A0008AE020C086E91EC01A82E1E0F0E04092C1
:10F9B0005700849118C08B81803579F48C81883010
:10F9C00031F4E2E0F0E04092570084910BC0E0E0B7
:10F9D000F0E040925700849105C0E3E0F0E04092EF
:10F9E000570084911A828B831C8244E050E095C0BA
:10F9F000BC80AA248D81082F10E00A291B29000F42
:10FA0000111F1A8288C09A8088248B81682F70E029
:10FA100068297929933109F034C0F7EF0F3F1F07A8
:10FA200010F0A80141C023E0F80120935700E895A9
:10FA300007B600FCFDCFA801DE011B968C91119644
:10FA40002C9111971296D22ECC2490E08C299D29CE
:10FA500021E0FA010C0120935700E89511244E5F34
:10FA60005F4F6250704051F725E0F8012093570036
:10FA7000E89507B600FCFDCF81E180935700E8953B
:10FA800013C0A801FB01DE011B9641BD52BD4F5FB3
:10FA90005F4F8D9180BDFA9AF99AF999FECF31970F
:10FAA000A1F7A801460F571F1A828A0134C07A8035
:10FAB00066248B81A82FB0E0A629B7291A828981F4
:10FAC000843181F4BD019101F80185919491F9018E
:10FAD000808391832E5F3F4F0E5F1F4F62507040B7
:10FAE00099F711C0A801BD01910141BD52BD4F5F01
:10FAF0005F4FF89A80B5F90181939F016150704082
:10FB0000A1F70A0F1B1FAD014D5F5F4FF901108276
:10FB100004C080EC8A8342E050E090E0FBE1F09387
:10FB2000C6008091C00086FFFCCF8091C000806439
:10FB30008093C0005092C6008091C00086FFFCCF29
:10FB40008091C00080648093C000652F5093C600F0
:10FB50008091C00086FFFCCF8091C00080648093BC
:10FB6000C000342F4093C6008091C00086FFFCCFB8
:10FB70008091C00080648093C0008EE08093C600B6
:10FB80008091C00086FFFCCF8091C000806480938C
:10FB9000C00025E1252523272627FE01319610C028
:10FBA00030813093C6008091C00086FFFCCF319633
:10FBB0008091C00080648093C00023274150504052
:10FBC0004115510569F72093C6008091C00086FF5A
:10FBD000FCCF8091C00080648093C000992349F4D9
:10FBE000539444E755E962E470E090E0A0E0B0E0AF
:10FBF00032CE5A9881E180935700E89511241F92E4
:10FC00001F920895FFCF9981933109F4FCCE94316E
:10FC1000C8F4963009F4ECCE973050F4923009F4E1
:10FC20006ECE933009F49DCE913009F072CF83CE21
:10FC3000913109F4A9CE923108F0E3CE903109F068
:10FC400068CF5DCE983109F4B6CE993150F4953134
:10FC500009F4D9CE953108F42ACF963109F059CF5D
:10FC600026CF9B3109F495CE9C3120F49A3109F0CE
:10FC700050CF9ACE9D3109F444CE9F3209F049CF3E
:02FC8000B8CFFB
:040000030000F80001
:00000001FF

View File

@ -0,0 +1,75 @@
:10F800008FEF90E19EBF8DBF11241FBE5A9A00C09A
:10F81000CDB7DEB7CD51D140DEBFCDBF1092C50010
:10F820008AE08093C40088E18093C100EE24FF2425
:10F8300020E0552400E010E039E0432E93E0292E2B
:10F84000312C2C0E3D1ECDC14150504060407040C7
:10F8500011F43FE206C08091C00087FFF5CF3091E0
:10F86000C600933021F1943028F4913099F0923011
:10F87000C8F407C0953049F1953000F19630D1F5C4
:10F8800035C03B3119F491E02BE134C03F3291F5A2
:10F890003983B9C1313011F0351559F52327532E6D
:10F8A00092E028C0B32FA0E0232793E023C0832F4A
:10F8B00090E0A82BB92B232794E01CC03E30C9F45C
:10F8C000232795E0EE24FF2415C0E1E0F0E0EC0FE3
:10F8D000FD1FEE0DFF1D30830894E11CF11C232752
:10F8E000EA16FB0639F4D70196E004C0321709F492
:10F8F0008AC190E041ED5AE363E570E0ACCF90E05F
:10F9000044C08D81803311F090E00AC08F8188233C
:10F9100011F49EE105C0813011F09AE001C096E932
:10F920001A821B828D818C838E818D839E831F82A0
:10F9300047E050E0F2C01A8288E08B8381E48C8338
:10F9400086E58D8382E58E8389E48F8383E58887CE
:10F9500080E589878FE58A8782E38B874BE050E0DB
:10F96000DCC08A81813941F0823941F0803911F45B
:10F970008FE005C080E003C082E001C08AE01A8207
:10F980008B8343E050E0C9C091E01A8242E050E02E
:10F99000C5C08D81882311F48EE124C0813011F01F
:10F9A0008AE020C086E91EC01A82E1E0F0E04092C1
:10F9B0005700849118C08B81803579F48C81883010
:10F9C00031F4E2E0F0E04092570084910BC0E0E0B7
:10F9D000F0E040925700849105C0E3E0F0E04092EF
:10F9E000570084911A828B831C8244E050E095C0BA
:10F9F000BC80AA248D81082F10E00A291B29000F42
:10FA0000111F1A8288C09A8088248B81682F70E029
:10FA100068297929933109F034C0F7EF0F3F1F07A8
:10FA200010F0A80141C023E0F80120935700E895A9
:10FA300007B600FCFDCFA801DE011B968C91119644
:10FA40002C9111971296D22ECC2490E08C299D29CE
:10FA500021E0FA010C0120935700E89511244E5F34
:10FA60005F4F6250704051F725E0F8012093570036
:10FA7000E89507B600FCFDCF81E180935700E8953B
:10FA800013C0A801FB01DE011B9641BD52BD4F5FB3
:10FA90005F4F8D9180BDFA9AF99AF999FECF31970F
:10FAA000A1F7A801460F571F1A828A0134C07A8035
:10FAB00066248B81A82FB0E0A629B7291A828981F4
:10FAC000843181F4BD019101F80185919491F9018E
:10FAD000808391832E5F3F4F0E5F1F4F62507040B7
:10FAE00099F711C0A801BD01910141BD52BD4F5F01
:10FAF0005F4FF89A80B5F90181939F016150704082
:10FB0000A1F70A0F1B1FAD014D5F5F4FF901108276
:10FB100004C080EC8A8342E050E090E0FBE1F09387
:10FB2000C6008091C00086FFFCCF8091C000806439
:10FB30008093C0005092C6008091C00086FFFCCF29
:10FB40008091C00080648093C000652F5093C600F0
:10FB50008091C00086FFFCCF8091C00080648093BC
:10FB6000C000342F4093C6008091C00086FFFCCFB8
:10FB70008091C00080648093C0008EE08093C600B6
:10FB80008091C00086FFFCCF8091C000806480938C
:10FB9000C00025E1252523272627FE01319610C028
:10FBA00030813093C6008091C00086FFFCCF319633
:10FBB0008091C00080648093C00023274150504052
:10FBC0004115510569F72093C6008091C00086FF5A
:10FBD000FCCF8091C00080648093C000992349F4D9
:10FBE000539441ED5AE363E570E090E0A0E0B0E0AB
:10FBF00032CE5A9881E180935700E89511241F92E4
:10FC00001F920895FFCF9981933109F4FCCE94316E
:10FC1000C8F4963009F4ECCE973050F4923009F4E1
:10FC20006ECE933009F49DCE913009F072CF83CE21
:10FC3000913109F4A9CE923108F0E3CE903109F068
:10FC400068CF5DCE983109F4B6CE993150F4953134
:10FC500009F4D9CE953108F42ACF963109F059CF5D
:10FC600026CF9B3109F495CE9C3120F49A3109F0CE
:10FC700050CF9ACE9D3109F444CE9F3209F049CF3E
:02FC8000B8CFFB
:040000030000F80001
:00000001FF

View File

@ -0,0 +1,239 @@
/*
HardwareSerial.cpp - Hardware serial library for Wiring
Copyright (c) 2006 Nicholas Zambetti. 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
Modified 23 November 2006 by David A. Mellis
*/
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "wiring.h"
#include "wiring_private.h"
#include "HardwareSerial.h"
// Define constants and variables for buffering incoming serial data. We're
// using a ring buffer (I think), in which rx_buffer_head is the index of the
// location to which to write the next incoming character and rx_buffer_tail
// is the index of the location from which to read.
#define RX_BUFFER_SIZE 128
struct ring_buffer {
unsigned char buffer[RX_BUFFER_SIZE];
int head;
int tail;
};
ring_buffer rx_buffer = { { 0 }, 0, 0 };
#ifdef UDR1
ring_buffer rx_buffer1 = { { 0 }, 0, 0 };
#endif
#ifdef UDR2
ring_buffer rx_buffer2 = { { 0 }, 0, 0 };
#endif
#ifdef UDR3
ring_buffer rx_buffer3 = { { 0 }, 0, 0 };
#endif
inline void store_char(unsigned char c, ring_buffer *rx_buffer)
{
int i = (rx_buffer->head + 1) % RX_BUFFER_SIZE;
// if we should be storing the received character into the location
// just before the tail (meaning that the head would advance to the
// current location of the tail), we're about to overflow the buffer
// and so we don't write the character or advance the head.
if (i != rx_buffer->tail) {
rx_buffer->buffer[rx_buffer->head] = c;
rx_buffer->head = i;
}
}
ISR(USART0_RX_vect)
{
unsigned char c = UDR0;
store_char(c, &rx_buffer);
}
#ifdef UDR1
ISR(USART1_RX_vect)
{
unsigned char c = UDR1;
store_char(c, &rx_buffer1);
}
#ifdef UDR2
ISR(USART2_RX_vect)
{
unsigned char c = UDR2;
store_char(c, &rx_buffer2);
}
#ifdef UDR2
ISR(USART3_RX_vect)
{
unsigned char c = UDR3;
store_char(c, &rx_buffer3);
}
#endif
#endif
#else
#if defined(__AVR_ATmega8__)
SIGNAL(SIG_UART_RECV)
#else
SIGNAL(USART_RX_vect)
#endif
{
#if defined(__AVR_ATmega8__)
unsigned char c = UDR;
#else
unsigned char c = UDR0;
#endif
store_char(c, &rx_buffer);
}
#endif
// Constructors ////////////////////////////////////////////////////////////////
HardwareSerial::HardwareSerial(ring_buffer *rx_buffer,
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
volatile uint8_t *udr,
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x)
{
_rx_buffer = rx_buffer;
_ubrrh = ubrrh;
_ubrrl = ubrrl;
_ucsra = ucsra;
_ucsrb = ucsrb;
_udr = udr;
_rxen = rxen;
_txen = txen;
_rxcie = rxcie;
_udre = udre;
_u2x = u2x;
}
// Public Methods //////////////////////////////////////////////////////////////
void HardwareSerial::begin(long baud)
{
uint16_t baud_setting;
bool use_u2x;
// U2X mode is needed for baud rates higher than (CPU Hz / 16)
if (baud > F_CPU / 16) {
use_u2x = true;
} else {
// figure out if U2X mode would allow for a better connection
// calculate the percent difference between the baud-rate specified and
// the real baud rate for both U2X and non-U2X mode (0-255 error percent)
uint8_t nonu2x_baud_error = abs((int)(255-((F_CPU/(16*(((F_CPU/8/baud-1)/2)+1))*255)/baud)));
uint8_t u2x_baud_error = abs((int)(255-((F_CPU/(8*(((F_CPU/4/baud-1)/2)+1))*255)/baud)));
// prefer non-U2X mode because it handles clock skew better
use_u2x = (nonu2x_baud_error > u2x_baud_error);
}
if (use_u2x) {
*_ucsra = 1 << _u2x;
baud_setting = (F_CPU / 4 / baud - 1) / 2;
} else {
*_ucsra = 0;
baud_setting = (F_CPU / 8 / baud - 1) / 2;
}
// assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
*_ubrrh = baud_setting >> 8;
*_ubrrl = baud_setting;
sbi(*_ucsrb, _rxen);
sbi(*_ucsrb, _txen);
sbi(*_ucsrb, _rxcie);
}
void HardwareSerial::end()
{
cbi(*_ucsrb, _rxen);
cbi(*_ucsrb, _txen);
cbi(*_ucsrb, _rxcie);
}
uint8_t HardwareSerial::available(void)
{
return (RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % RX_BUFFER_SIZE;
}
int HardwareSerial::read(void)
{
// if the head isn't ahead of the tail, we don't have any characters
if (_rx_buffer->head == _rx_buffer->tail) {
return -1;
} else {
unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
_rx_buffer->tail = (_rx_buffer->tail + 1) % RX_BUFFER_SIZE;
return c;
}
}
void HardwareSerial::flush()
{
// don't reverse this or there may be problems if the RX interrupt
// occurs after reading the value of rx_buffer_head but before writing
// the value to rx_buffer_tail; the previous value of rx_buffer_head
// may be written to rx_buffer_tail, making it appear as if the buffer
// don't reverse this or there may be problems if the RX interrupt
// occurs after reading the value of rx_buffer_head but before writing
// the value to rx_buffer_tail; the previous value of rx_buffer_head
// may be written to rx_buffer_tail, making it appear as if the buffer
// were full, not empty.
_rx_buffer->head = _rx_buffer->tail;
}
void HardwareSerial::write(uint8_t c)
{
while (!((*_ucsra) & (1 << _udre)))
;
*_udr = c;
}
// Preinstantiate Objects //////////////////////////////////////////////////////
#if defined(__AVR_ATmega8__)
HardwareSerial Serial(&rx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UDR, RXEN, TXEN, RXCIE, UDRE, U2X);
#else
HardwareSerial Serial(&rx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0);
#endif
#ifdef UDR1
HardwareSerial Serial1(&rx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRE1, U2X1);
#endif
#ifdef UDR2
HardwareSerial Serial2(&rx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UDR2, RXEN2, TXEN2, RXCIE2, UDRE2, U2X2);
#endif
#ifdef UDR3
HardwareSerial Serial3(&rx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UDR3, RXEN3, TXEN3, RXCIE3, UDRE3, U2X3);
#endif

View File

@ -0,0 +1,69 @@
/*
HardwareSerial.h - Hardware serial library for Wiring
Copyright (c) 2006 Nicholas Zambetti. 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 HardwareSerial_h
#define HardwareSerial_h
#include <inttypes.h>
#include "Print.h"
struct ring_buffer;
class HardwareSerial : public Print
{
private:
ring_buffer *_rx_buffer;
volatile uint8_t *_ubrrh;
volatile uint8_t *_ubrrl;
volatile uint8_t *_ucsra;
volatile uint8_t *_ucsrb;
volatile uint8_t *_udr;
uint8_t _rxen;
uint8_t _txen;
uint8_t _rxcie;
uint8_t _udre;
uint8_t _u2x;
public:
HardwareSerial(ring_buffer *rx_buffer,
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
volatile uint8_t *udr,
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x);
void begin(long);
void end();
uint8_t available(void);
int read(void);
void flush(void);
virtual void write(uint8_t);
using Print::write; // pull in write(str) and write(buf, size) from Print
};
extern HardwareSerial Serial;
#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1280__)
extern HardwareSerial Serial1;
#endif
#if defined(__AVR_ATmega1280__)
extern HardwareSerial Serial2;
extern HardwareSerial Serial3;
#endif
#endif

View File

@ -0,0 +1,243 @@
# Arduino 0011 Makefile
# Arduino adaptation by mellis, eighthave, oli.keller
#
# This makefile allows you to build sketches from the command line
# without the Arduino environment (or Java).
#
# Detailed instructions for using the makefile:
#
# 1. Copy this file into the folder with your sketch. There should be a
# file with the same name as the folder and with the extension .pde
# (e.g. foo.pde in the foo/ folder).
#
# 2. Modify the line containg "INSTALL_DIR" to point to the directory that
# contains the Arduino installation (for example, under Mac OS X, this
# might be /Applications/arduino-0012).
#
# 3. Modify the line containing "PORT" to refer to the filename
# representing the USB or serial connection to your Arduino board
# (e.g. PORT = /dev/tty.USB0). If the exact name of this file
# changes, you can use * as a wildcard (e.g. PORT = /dev/tty.usb*).
#
# 4. Set the line containing "MCU" to match your board's processor.
# Older one's are atmega8 based, newer ones like Arduino Mini, Bluetooth
# or Diecimila have the atmega168. If you're using a LilyPad Arduino,
# change F_CPU to 8000000.
#
# 5. At the command line, change to the directory containing your
# program's file and the makefile.
#
# 6. Type "make" and press enter to compile/verify your program.
#
# 7. Type "make upload", reset your Arduino board, and press enter to
# upload your program to the Arduino board.
#
# $Id$
TARGET = $(notdir $(CURDIR))
INSTALL_DIR = /Users/dmellis/Source/arduino/trunk/build/macosx/build/work
PORT = /dev/tty.usb*
UPLOAD_RATE = 19200
AVRDUDE_PROGRAMMER = stk500v1
MCU = atmega168
F_CPU = 16000000
############################################################################
# Below here nothing should be changed...
ARDUINO = $(INSTALL_DIR)/hardware/cores/arduino
AVR_TOOLS_PATH = $(INSTALL_DIR)/hardware/tools/avr/bin
SRC = $(ARDUINO)/pins_arduino.c $(ARDUINO)/wiring.c \
$(ARDUINO)/wiring_analog.c $(ARDUINO)/wiring_digital.c \
$(ARDUINO)/wiring_pulse.c $(ARDUINO)/wiring_serial.c \
$(ARDUINO)/wiring_shift.c $(ARDUINO)/WInterrupts.c
CXXSRC = $(ARDUINO)/HardwareSerial.cpp $(ARDUINO)/WMath.cpp
FORMAT = ihex
# Name of this Makefile (used for "make depend").
MAKEFILE = Makefile
# Debugging format.
# Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
# AVR (extended) COFF requires stabs, plus an avr-objcopy run.
DEBUG = stabs
OPT = s
# Place -D or -U options here
CDEFS = -DF_CPU=$(F_CPU)
CXXDEFS = -DF_CPU=$(F_CPU)
# Place -I options here
CINCS = -I$(ARDUINO)
CXXINCS = -I$(ARDUINO)
# Compiler flag to set the C Standard level.
# c89 - "ANSI" C
# gnu89 - c89 plus GCC extensions
# c99 - ISO C99 standard (not yet fully implemented)
# gnu99 - c99 plus GCC extensions
CSTANDARD = -std=gnu99
CDEBUG = -g$(DEBUG)
CWARN = -Wall -Wstrict-prototypes
CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
#CEXTRA = -Wa,-adhlns=$(<:.c=.lst)
CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA)
CXXFLAGS = $(CDEFS) $(CINCS) -O$(OPT)
#ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
LDFLAGS = -lm
# Programming support using avrdude. Settings and variables.
AVRDUDE_PORT = $(PORT)
AVRDUDE_WRITE_FLASH = -U flash:w:applet/$(TARGET).hex
AVRDUDE_FLAGS = -V -F -C $(INSTALL_DIR)/hardware/tools/avr/etc/avrdude.conf \
-p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
-b $(UPLOAD_RATE)
# Program settings
CC = $(AVR_TOOLS_PATH)/avr-gcc
CXX = $(AVR_TOOLS_PATH)/avr-g++
OBJCOPY = $(AVR_TOOLS_PATH)/avr-objcopy
OBJDUMP = $(AVR_TOOLS_PATH)/avr-objdump
AR = $(AVR_TOOLS_PATH)/avr-ar
SIZE = $(AVR_TOOLS_PATH)/avr-size
NM = $(AVR_TOOLS_PATH)/avr-nm
AVRDUDE = $(AVR_TOOLS_PATH)/avrdude
REMOVE = rm -f
MV = mv -f
# Define all object files.
OBJ = $(SRC:.c=.o) $(CXXSRC:.cpp=.o) $(ASRC:.S=.o)
# Define all listing files.
LST = $(ASRC:.S=.lst) $(CXXSRC:.cpp=.lst) $(SRC:.c=.lst)
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
ALL_CXXFLAGS = -mmcu=$(MCU) -I. $(CXXFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
# Default target.
all: applet_files build sizeafter
build: elf hex
applet_files: $(TARGET).pde
# Here is the "preprocessing".
# It creates a .cpp file based with the same name as the .pde file.
# On top of the new .cpp file comes the WProgram.h header.
# At the end there is a generic main() function attached.
# Then the .cpp file will be compiled. Errors during compile will
# refer to this new, automatically generated, file.
# Not the original .pde file you actually edit...
test -d applet || mkdir applet
echo '#include "WProgram.h"' > applet/$(TARGET).cpp
cat $(TARGET).pde >> applet/$(TARGET).cpp
cat $(ARDUINO)/main.cxx >> applet/$(TARGET).cpp
elf: applet/$(TARGET).elf
hex: applet/$(TARGET).hex
eep: applet/$(TARGET).eep
lss: applet/$(TARGET).lss
sym: applet/$(TARGET).sym
# Program the device.
upload: applet/$(TARGET).hex
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) applet/$(TARGET).hex
ELFSIZE = $(SIZE) applet/$(TARGET).elf
sizebefore:
@if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(HEXSIZE); echo; fi
sizeafter:
@if [ -f applet/$(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(HEXSIZE); echo; fi
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT=$(OBJCOPY) --debugging \
--change-section-address .data-0x800000 \
--change-section-address .bss-0x800000 \
--change-section-address .noinit-0x800000 \
--change-section-address .eeprom-0x810000
coff: applet/$(TARGET).elf
$(COFFCONVERT) -O coff-avr applet/$(TARGET).elf $(TARGET).cof
extcoff: $(TARGET).elf
$(COFFCONVERT) -O coff-ext-avr applet/$(TARGET).elf $(TARGET).cof
.SUFFIXES: .elf .hex .eep .lss .sym
.elf.hex:
$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
.elf.eep:
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
# Create extended listing file from ELF output file.
.elf.lss:
$(OBJDUMP) -h -S $< > $@
# Create a symbol table from ELF output file.
.elf.sym:
$(NM) -n $< > $@
# Link: create ELF output file from library.
applet/$(TARGET).elf: $(TARGET).pde applet/core.a
$(CC) $(ALL_CFLAGS) -o $@ applet/$(TARGET).cpp -L. applet/core.a $(LDFLAGS)
applet/core.a: $(OBJ)
@for i in $(OBJ); do echo $(AR) rcs applet/core.a $$i; $(AR) rcs applet/core.a $$i; done
# Compile: create object files from C++ source files.
.cpp.o:
$(CXX) -c $(ALL_CXXFLAGS) $< -o $@
# Compile: create object files from C source files.
.c.o:
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C source files.
.c.s:
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
.S.o:
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Target: clean project.
clean:
$(REMOVE) applet/$(TARGET).hex applet/$(TARGET).eep applet/$(TARGET).cof applet/$(TARGET).elf \
applet/$(TARGET).map applet/$(TARGET).sym applet/$(TARGET).lss applet/core.a \
$(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) $(CXXSRC:.cpp=.s) $(CXXSRC:.cpp=.d)
depend:
if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
then \
sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
$(MAKEFILE).$$$$ && \
$(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
fi
echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
>> $(MAKEFILE); \
$(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)
.PHONY: all build elf hex eep lss sym program coff extcoff clean depend applet_files sizebefore sizeafter

View File

@ -0,0 +1,203 @@
/*
Print.cpp - Base class that provides print() and println()
Copyright (c) 2008 David A. Mellis. 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
Modified 23 November 2006 by David A. Mellis
*/
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <math.h>
#include "wiring.h"
#include "Print.h"
// Public Methods //////////////////////////////////////////////////////////////
void Print::print(uint8_t b)
{
this->write(b);
}
void Print::print(char c)
{
print((byte) c);
}
void Print::print(const char c[])
{
while (*c)
print(*c++);
}
void Print::print(int n)
{
print((long) n);
}
void Print::print(unsigned int n)
{
print((unsigned long) n);
}
void Print::print(long n)
{
if (n < 0) {
print('-');
n = -n;
}
printNumber(n, 10);
}
void Print::print(unsigned long n)
{
printNumber(n, 10);
}
void Print::print(long n, int base)
{
if (base == 0)
print((char) n);
else if (base == 10)
print(n);
else
printNumber(n, base);
}
void Print::print(double n)
{
printFloat(n, 2);
}
void Print::println(void)
{
print('\r');
print('\n');
}
void Print::println(char c)
{
print(c);
println();
}
void Print::println(const char c[])
{
print(c);
println();
}
void Print::println(uint8_t b)
{
print(b);
println();
}
void Print::println(int n)
{
print(n);
println();
}
void Print::println(unsigned int n)
{
print(n);
println();
}
void Print::println(long n)
{
print(n);
println();
}
void Print::println(unsigned long n)
{
print(n);
println();
}
void Print::println(long n, int base)
{
print(n, base);
println();
}
void Print::println(double n)
{
print(n);
println();
}
// Private Methods /////////////////////////////////////////////////////////////
void Print::printNumber(unsigned long n, uint8_t base)
{
unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars.
unsigned long i = 0;
if (n == 0) {
print('0');
return;
}
while (n > 0) {
buf[i++] = n % base;
n /= base;
}
for (; i > 0; i--)
print((char) (buf[i - 1] < 10 ?
'0' + buf[i - 1] :
'A' + buf[i - 1] - 10));
}
void Print::printFloat(double number, uint8_t digits)
{
// Handle negative numbers
if (number < 0.0)
{
print('-');
number = -number;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i)
rounding /= 10.0;
number += rounding;
// Extract the integer part of the number and print it
unsigned long int_part = (unsigned long)number;
double remainder = number - (double)int_part;
print(int_part);
// Print the decimal point, but only if there are digits beyond
if (digits > 0)
print(".");
// Extract digits from the remainder one at a time
while (digits-- > 0)
{
remainder *= 10.0;
int toPrint = int(remainder);
print(toPrint);
remainder -= toPrint;
}
}

View File

@ -0,0 +1,59 @@
/*
Print.h - Base class that provides print() and println()
Copyright (c) 2008 David A. Mellis. 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 Print_h
#define Print_h
#include <inttypes.h>
#define DEC 10
#define HEX 16
#define OCT 8
#define BIN 2
#define BYTE 0
class Print
{
private:
void printNumber(unsigned long, uint8_t);
void printFloat(double, uint8_t);
public:
virtual void write(uint8_t);
void print(char);
void print(const char[]);
void print(uint8_t);
void print(int);
void print(unsigned int);
void print(long);
void print(unsigned long);
void print(long, int);
void print(double);
void println(void);
void println(char);
void println(const char[]);
void println(uint8_t);
void println(int);
void println(unsigned int);
void println(long);
void println(unsigned long);
void println(long, int);
void println(double);
};
#endif

View File

@ -0,0 +1,515 @@
/* Tone.cpp
A Tone Generator Library
Written by Brett Hagman
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
Version Modified By Date Comments
------- ----------- -------- --------
0001 B Hagman 09/08/02 Initial coding
0002 B Hagman 09/08/18 Multiple pins
0003 B Hagman 09/08/18 Moved initialization from constructor to begin()
0004 B Hagman 09/09/26 Fixed problems with ATmega8
0005 B Hagman 09/11/23 Scanned prescalars for best fit on 8 bit timers
09/11/25 Changed pin toggle method to XOR
09/11/25 Fixed timer0 from being excluded
0006 D Mellis 09/12/29 Replaced objects with functions
*************************************************/
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <wiring.h>
#include <pins_arduino.h>
#if defined(__AVR_ATmega8__)
#define TCCR2A TCCR2
#define TCCR2B TCCR2
#define COM2A1 COM21
#define COM2A0 COM20
#define OCR2A OCR2
#define TIMSK2 TIMSK
#define OCIE2A OCIE2
#define TIMER2_COMPA_vect TIMER2_COMP_vect
#define TIMSK1 TIMSK
#endif
// timerx_toggle_count:
// > 0 - duration specified
// = 0 - stopped
// < 0 - infinitely (until stop() method called, or new play() called)
#if !defined(__AVR_ATmega8__)
volatile long timer0_toggle_count;
volatile uint8_t *timer0_pin_port;
volatile uint8_t timer0_pin_mask;
#endif
volatile long timer1_toggle_count;
volatile uint8_t *timer1_pin_port;
volatile uint8_t timer1_pin_mask;
volatile long timer2_toggle_count;
volatile uint8_t *timer2_pin_port;
volatile uint8_t timer2_pin_mask;
#if defined(__AVR_ATmega1280__)
volatile long timer3_toggle_count;
volatile uint8_t *timer3_pin_port;
volatile uint8_t timer3_pin_mask;
volatile long timer4_toggle_count;
volatile uint8_t *timer4_pin_port;
volatile uint8_t timer4_pin_mask;
volatile long timer5_toggle_count;
volatile uint8_t *timer5_pin_port;
volatile uint8_t timer5_pin_mask;
#endif
#if defined(__AVR_ATmega1280__)
#define AVAILABLE_TONE_PINS 1
const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 3, 4, 5, 1, 0 */ };
static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255, 255, 255, 255, 255 */ };
#elif defined(__AVR_ATmega8__)
#define AVAILABLE_TONE_PINS 1
const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 1 */ };
static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255 */ };
#else
#define AVAILABLE_TONE_PINS 1
// Leave timer 0 to last.
const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 1, 0 */ };
static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255, 255 */ };
#endif
static int8_t toneBegin(uint8_t _pin)
{
int8_t _timer = -1;
// if we're already using the pin, the timer should be configured.
for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
if (tone_pins[i] == _pin) {
return pgm_read_byte(tone_pin_to_timer_PGM + i);
}
}
// search for an unused timer.
for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
if (tone_pins[i] == 255) {
tone_pins[i] = _pin;
_timer = pgm_read_byte(tone_pin_to_timer_PGM + i);
break;
}
}
if (_timer != -1)
{
// Set timer specific stuff
// All timers in CTC mode
// 8 bit timers will require changing prescalar values,
// whereas 16 bit timers are set to either ck/1 or ck/64 prescalar
switch (_timer)
{
#if !defined(__AVR_ATmega8__)
case 0:
// 8 bit timer
TCCR0A = 0;
TCCR0B = 0;
bitWrite(TCCR0A, WGM01, 1);
bitWrite(TCCR0B, CS00, 1);
timer0_pin_port = portOutputRegister(digitalPinToPort(_pin));
timer0_pin_mask = digitalPinToBitMask(_pin);
break;
#endif
case 1:
// 16 bit timer
TCCR1A = 0;
TCCR1B = 0;
bitWrite(TCCR1B, WGM12, 1);
bitWrite(TCCR1B, CS10, 1);
timer1_pin_port = portOutputRegister(digitalPinToPort(_pin));
timer1_pin_mask = digitalPinToBitMask(_pin);
break;
case 2:
// 8 bit timer
TCCR2A = 0;
TCCR2B = 0;
bitWrite(TCCR2A, WGM21, 1);
bitWrite(TCCR2B, CS20, 1);
timer2_pin_port = portOutputRegister(digitalPinToPort(_pin));
timer2_pin_mask = digitalPinToBitMask(_pin);
break;
#if defined(__AVR_ATmega1280__)
case 3:
// 16 bit timer
TCCR3A = 0;
TCCR3B = 0;
bitWrite(TCCR3B, WGM32, 1);
bitWrite(TCCR3B, CS30, 1);
timer3_pin_port = portOutputRegister(digitalPinToPort(_pin));
timer3_pin_mask = digitalPinToBitMask(_pin);
break;
case 4:
// 16 bit timer
TCCR4A = 0;
TCCR4B = 0;
bitWrite(TCCR4B, WGM42, 1);
bitWrite(TCCR4B, CS40, 1);
timer4_pin_port = portOutputRegister(digitalPinToPort(_pin));
timer4_pin_mask = digitalPinToBitMask(_pin);
break;
case 5:
// 16 bit timer
TCCR5A = 0;
TCCR5B = 0;
bitWrite(TCCR5B, WGM52, 1);
bitWrite(TCCR5B, CS50, 1);
timer5_pin_port = portOutputRegister(digitalPinToPort(_pin));
timer5_pin_mask = digitalPinToBitMask(_pin);
break;
#endif
}
}
return _timer;
}
// frequency (in hertz) and duration (in milliseconds).
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
{
uint8_t prescalarbits = 0b001;
long toggle_count = 0;
uint32_t ocr = 0;
int8_t _timer;
_timer = toneBegin(_pin);
if (_timer >= 0)
{
// Set the pinMode as OUTPUT
pinMode(_pin, OUTPUT);
// if we are using an 8 bit timer, scan through prescalars to find the best fit
if (_timer == 0 || _timer == 2)
{
ocr = F_CPU / frequency / 2 - 1;
prescalarbits = 0b001; // ck/1: same for both timers
if (ocr > 255)
{
ocr = F_CPU / frequency / 2 / 8 - 1;
prescalarbits = 0b010; // ck/8: same for both timers
if (_timer == 2 && ocr > 255)
{
ocr = F_CPU / frequency / 2 / 32 - 1;
prescalarbits = 0b011;
}
if (ocr > 255)
{
ocr = F_CPU / frequency / 2 / 64 - 1;
prescalarbits = _timer == 0 ? 0b011 : 0b100;
if (_timer == 2 && ocr > 255)
{
ocr = F_CPU / frequency / 2 / 128 - 1;
prescalarbits = 0b101;
}
if (ocr > 255)
{
ocr = F_CPU / frequency / 2 / 256 - 1;
prescalarbits = _timer == 0 ? 0b100 : 0b110;
if (ocr > 255)
{
// can't do any better than /1024
ocr = F_CPU / frequency / 2 / 1024 - 1;
prescalarbits = _timer == 0 ? 0b101 : 0b111;
}
}
}
}
#if !defined(__AVR_ATmega8__)
if (_timer == 0)
TCCR0B = prescalarbits;
else
#endif
TCCR2B = prescalarbits;
}
else
{
// two choices for the 16 bit timers: ck/1 or ck/64
ocr = F_CPU / frequency / 2 - 1;
prescalarbits = 0b001;
if (ocr > 0xffff)
{
ocr = F_CPU / frequency / 2 / 64 - 1;
prescalarbits = 0b011;
}
if (_timer == 1)
TCCR1B = (TCCR1B & 0b11111000) | prescalarbits;
#if defined(__AVR_ATmega1280__)
else if (_timer == 3)
TCCR3B = (TCCR3B & 0b11111000) | prescalarbits;
else if (_timer == 4)
TCCR4B = (TCCR4B & 0b11111000) | prescalarbits;
else if (_timer == 5)
TCCR5B = (TCCR5B & 0b11111000) | prescalarbits;
#endif
}
// Calculate the toggle count
if (duration > 0)
{
toggle_count = 2 * frequency * duration / 1000;
}
else
{
toggle_count = -1;
}
// Set the OCR for the given timer,
// set the toggle count,
// then turn on the interrupts
switch (_timer)
{
#if !defined(__AVR_ATmega8__)
case 0:
OCR0A = ocr;
timer0_toggle_count = toggle_count;
bitWrite(TIMSK0, OCIE0A, 1);
break;
#endif
case 1:
OCR1A = ocr;
timer1_toggle_count = toggle_count;
bitWrite(TIMSK1, OCIE1A, 1);
break;
case 2:
OCR2A = ocr;
timer2_toggle_count = toggle_count;
bitWrite(TIMSK2, OCIE2A, 1);
break;
#if defined(__AVR_ATmega1280__)
case 3:
OCR3A = ocr;
timer3_toggle_count = toggle_count;
bitWrite(TIMSK3, OCIE3A, 1);
break;
case 4:
OCR4A = ocr;
timer4_toggle_count = toggle_count;
bitWrite(TIMSK4, OCIE4A, 1);
break;
case 5:
OCR5A = ocr;
timer5_toggle_count = toggle_count;
bitWrite(TIMSK5, OCIE5A, 1);
break;
#endif
}
}
}
void noTone(uint8_t _pin)
{
int8_t _timer = -1;
for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
if (tone_pins[i] == _pin) {
_timer = pgm_read_byte(tone_pin_to_timer_PGM + i);
tone_pins[i] = 255;
}
}
switch (_timer)
{
#if defined(__AVR_ATmega8__)
case 1:
bitWrite(TIMSK1, OCIE1A, 0);
break;
case 2:
bitWrite(TIMSK2, OCIE2A, 0);
break;
#else
case 0:
TIMSK0 = 0;
break;
case 1:
TIMSK1 = 0;
break;
case 2:
TIMSK2 = 0;
break;
#endif
#if defined(__AVR_ATmega1280__)
case 3:
TIMSK3 = 0;
break;
case 4:
TIMSK4 = 0;
break;
case 5:
TIMSK5 = 0;
break;
#endif
}
digitalWrite(_pin, 0);
}
#if 0
#if !defined(__AVR_ATmega8__)
ISR(TIMER0_COMPA_vect)
{
if (timer0_toggle_count != 0)
{
// toggle the pin
*timer0_pin_port ^= timer0_pin_mask;
if (timer0_toggle_count > 0)
timer0_toggle_count--;
}
else
{
TIMSK0 = 0; // disable the interrupt
*timer0_pin_port &= ~(timer0_pin_mask); // keep pin low after stop
}
}
#endif
ISR(TIMER1_COMPA_vect)
{
if (timer1_toggle_count != 0)
{
// toggle the pin
*timer1_pin_port ^= timer1_pin_mask;
if (timer1_toggle_count > 0)
timer1_toggle_count--;
}
else
{
TIMSK1 = 0; // disable the interrupt
*timer1_pin_port &= ~(timer1_pin_mask); // keep pin low after stop
}
}
#endif
ISR(TIMER2_COMPA_vect)
{
if (timer2_toggle_count != 0)
{
// toggle the pin
*timer2_pin_port ^= timer2_pin_mask;
if (timer2_toggle_count > 0)
timer2_toggle_count--;
}
else
{
TIMSK2 = 0; // disable the interrupt
*timer2_pin_port &= ~(timer2_pin_mask); // keep pin low after stop
}
}
//#if defined(__AVR_ATmega1280__)
#if 0
ISR(TIMER3_COMPA_vect)
{
if (timer3_toggle_count != 0)
{
// toggle the pin
*timer3_pin_port ^= timer3_pin_mask;
if (timer3_toggle_count > 0)
timer3_toggle_count--;
}
else
{
TIMSK3 = 0; // disable the interrupt
*timer3_pin_port &= ~(timer3_pin_mask); // keep pin low after stop
}
}
ISR(TIMER4_COMPA_vect)
{
if (timer4_toggle_count != 0)
{
// toggle the pin
*timer4_pin_port ^= timer4_pin_mask;
if (timer4_toggle_count > 0)
timer4_toggle_count--;
}
else
{
TIMSK4 = 0; // disable the interrupt
*timer4_pin_port &= ~(timer4_pin_mask); // keep pin low after stop
}
}
ISR(TIMER5_COMPA_vect)
{
if (timer5_toggle_count != 0)
{
// toggle the pin
*timer5_pin_port ^= timer5_pin_mask;
if (timer5_toggle_count > 0)
timer5_toggle_count--;
}
else
{
TIMSK5 = 0; // disable the interrupt
*timer5_pin_port &= ~(timer5_pin_mask); // keep pin low after stop
}
}
#endif

View File

@ -0,0 +1,168 @@
/*
WCharacter.h - Character utility functions for Wiring & Arduino
Copyright (c) 2010 Hernando Barragan. 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 Character_h
#define Character_h
#include <ctype.h>
// WCharacter.h prototypes
inline boolean isAlphaNumeric(int c) __attribute__((always_inline));
inline boolean isAlpha(int c) __attribute__((always_inline));
inline boolean isAscii(int c) __attribute__((always_inline));
inline boolean isWhitespace(int c) __attribute__((always_inline));
inline boolean isControl(int c) __attribute__((always_inline));
inline boolean isDigit(int c) __attribute__((always_inline));
inline boolean isGraph(int c) __attribute__((always_inline));
inline boolean isLowerCase(int c) __attribute__((always_inline));
inline boolean isPrintable(int c) __attribute__((always_inline));
inline boolean isPunct(int c) __attribute__((always_inline));
inline boolean isSpace(int c) __attribute__((always_inline));
inline boolean isUpperCase(int c) __attribute__((always_inline));
inline boolean isHexadecimalDigit(int c) __attribute__((always_inline));
inline int toAscii(int c) __attribute__((always_inline));
inline int toLowerCase(int c) __attribute__((always_inline));
inline int toUpperCase(int c)__attribute__((always_inline));
// Checks for an alphanumeric character.
// It is equivalent to (isalpha(c) || isdigit(c)).
inline boolean isAlphaNumeric(int c)
{
return ( isalnum(c) == 0 ? false : true);
}
// Checks for an alphabetic character.
// It is equivalent to (isupper(c) || islower(c)).
inline boolean isAlpha(int c)
{
return ( isalpha(c) == 0 ? false : true);
}
// Checks whether c is a 7-bit unsigned char value
// that fits into the ASCII character set.
inline boolean isAscii(int c)
{
return ( isascii (c) == 0 ? false : true);
}
// Checks for a blank character, that is, a space or a tab.
inline boolean isWhitespace(int c)
{
return ( isblank (c) == 0 ? false : true);
}
// Checks for a control character.
inline boolean isControl(int c)
{
return ( iscntrl (c) == 0 ? false : true);
}
// Checks for a digit (0 through 9).
inline boolean isDigit(int c)
{
return ( isdigit (c) == 0 ? false : true);
}
// Checks for any printable character except space.
inline boolean isGraph(int c)
{
return ( isgraph (c) == 0 ? false : true);
}
// Checks for a lower-case character.
inline boolean isLowerCase(int c)
{
return (islower (c) == 0 ? false : true);
}
// Checks for any printable character including space.
inline boolean isPrintable(int c)
{
return ( isprint (c) == 0 ? false : true);
}
// Checks for any printable character which is not a space
// or an alphanumeric character.
inline boolean isPunct(int c)
{
return ( ispunct (c) == 0 ? false : true);
}
// Checks for white-space characters. For the avr-libc library,
// these are: space, formfeed ('\f'), newline ('\n'), carriage
// return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').
inline boolean isSpace(int c)
{
return ( isspace (c) == 0 ? false : true);
}
// Checks for an uppercase letter.
inline boolean isUpperCase(int c)
{
return ( isupper (c) == 0 ? false : true);
}
// Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7
// 8 9 a b c d e f A B C D E F.
inline boolean isHexadecimalDigit(int c)
{
return ( isxdigit (c) == 0 ? false : true);
}
// Converts c to a 7-bit unsigned char value that fits into the
// ASCII character set, by clearing the high-order bits.
inline int toAscii(int c)
{
return toascii (c);
}
// Warning:
// Many people will be unhappy if you use this function.
// This function will convert accented letters into random
// characters.
// Converts the letter c to lower case, if possible.
inline int toLowerCase(int c)
{
return tolower (c);
}
// Converts the letter c to upper case, if possible.
inline int toUpperCase(int c)
{
return toupper (c);
}
#endif

View File

@ -0,0 +1 @@
#include "wiring.h"

View File

@ -0,0 +1,87 @@
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Wiring project - http://wiring.uniandes.edu.co
Copyright (c) 2004-05 Hernando Barragan
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
Modified 24 November 2006 by David A. Mellis
*/
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include "WConstants.h"
#include "wiring_private.h"
volatile static voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS];
// volatile static voidFuncPtr twiIntFunc;
void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode)
{
if(interruptNum < EXTERNAL_NUM_INTERRUPTS)
{
intFunc[interruptNum] = userFunc;
//clear the config for the change settings
EICRA &= ~(B00000011 << (interruptNum * 2));
//set our mode.
EICRA |= (mode << (interruptNum * 2));
// Enable the interrupt.
EIMSK |= (1 << interruptNum);
}
}
void detachInterrupt(uint8_t interruptNum)
{
if(interruptNum < EXTERNAL_NUM_INTERRUPTS)
{
// Disable the interrupt.
EIMSK &= ~(1 << interruptNum);
intFunc[interruptNum] = 0;
}
}
ISR(INT0_vect) {
if(intFunc[EXTERNAL_INT_0])
intFunc[EXTERNAL_INT_0]();
}
ISR(INT1_vect) {
if(intFunc[EXTERNAL_INT_1])
intFunc[EXTERNAL_INT_1]();
}
ISR(INT2_vect) {
if(intFunc[EXTERNAL_INT_2])
intFunc[EXTERNAL_INT_2]();
}
/*
SIGNAL(SIG_2WIRE_SERIAL) {
if(twiIntFunc)
twiIntFunc();
}
*/

View File

@ -0,0 +1,60 @@
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Wiring project - http://wiring.org.co
Copyright (c) 2004-06 Hernando Barragan
Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id$
*/
extern "C" {
#include "stdlib.h"
}
void randomSeed(unsigned int seed)
{
if (seed != 0){
srandom(seed);
}
}
long random(long howbig)
{
if (howbig == 0) {
return 0;
}
return random() % howbig;
}
long random(long howsmall, long howbig)
{
if (howsmall >= howbig) {
return howsmall;
}
long diff = howbig - howsmall;
return random(diff) + howsmall;
}
long map(long x, long in_min, long in_max, long out_min, long out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
unsigned int makeWord(unsigned int w) { return w; }
unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; }

View File

@ -0,0 +1,34 @@
#ifndef WProgram_h
#define WProgram_h
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <avr/interrupt.h>
#include "wiring.h"
#ifdef __cplusplus
#include "WCharacter.h"
#include "WString.h"
#include "HardwareSerial.h"
uint16_t makeWord(uint16_t w);
uint16_t makeWord(byte h, byte l);
#define word(...) makeWord(__VA_ARGS__)
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
void noTone(uint8_t _pin);
// WMath prototypes
long random(long);
long random(long, long);
void randomSeed(unsigned int);
long map(long, long, long, long, long);
#endif
#endif

View File

@ -0,0 +1,443 @@
/*
WString.cpp - String library for Wiring & Arduino
Copyright (c) 2009-10 Hernando Barragan. All rights 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
*/
#include <stdlib.h>
#include "WProgram.h"
#include "WString.h"
String::String( const char *value )
{
if ( value == NULL )
value = "";
getBuffer( _length = strlen( value ) );
if ( _buffer != NULL )
strcpy( _buffer, value );
}
String::String( const String &value )
{
getBuffer( _length = value._length );
if ( _buffer != NULL )
strcpy( _buffer, value._buffer );
}
String::String( const char value )
{
_length = 1;
getBuffer(1);
if ( _buffer != NULL ) {
_buffer[0] = value;
_buffer[1] = 0;
}
}
String::String( const unsigned char value )
{
_length = 1;
getBuffer(1);
if ( _buffer != NULL) {
_buffer[0] = value;
_buffer[1] = 0;
}
}
String::String( const int value, const int base )
{
char buf[33];
itoa((signed long)value, buf, base);
getBuffer( _length = strlen(buf) );
if ( _buffer != NULL )
strcpy( _buffer, buf );
}
String::String( const unsigned int value, const int base )
{
char buf[33];
ultoa((unsigned long)value, buf, base);
getBuffer( _length = strlen(buf) );
if ( _buffer != NULL )
strcpy( _buffer, buf );
}
String::String( const long value, const int base )
{
char buf[33];
ltoa(value, buf, base);
getBuffer( _length = strlen(buf) );
if ( _buffer != NULL )
strcpy( _buffer, buf );
}
String::String( const unsigned long value, const int base )
{
char buf[33];
ultoa(value, buf, 10);
getBuffer( _length = strlen(buf) );
if ( _buffer != NULL )
strcpy( _buffer, buf );
}
char String::charAt( unsigned int loc ) const
{
return operator[]( loc );
}
void String::setCharAt( unsigned int loc, const char aChar )
{
if(_buffer == NULL) return;
if(_length > loc) {
_buffer[loc] = aChar;
}
}
int String::compareTo( const String &s2 ) const
{
return strcmp( _buffer, s2._buffer );
}
const String & String::concat( const String &s2 )
{
return (*this) += s2;
}
const String & String::operator=( const String &rhs )
{
if ( this == &rhs )
return *this;
if ( rhs._length > _length )
{
free(_buffer);
getBuffer( rhs._length );
}
if ( _buffer != NULL ) {
_length = rhs._length;
strcpy( _buffer, rhs._buffer );
}
return *this;
}
//const String & String::operator+=( const char aChar )
//{
// if ( _length == _capacity )
// doubleBuffer();
//
// _buffer[ _length++ ] = aChar;
// _buffer[ _length ] = '\0';
// return *this;
//}
const String & String::operator+=( const String &other )
{
_length += other._length;
if ( _length > _capacity )
{
char *temp = (char *)realloc(_buffer, _length + 1);
if ( temp != NULL ) {
_buffer = temp;
_capacity = _length;
} else {
_length -= other._length;
return *this;
}
}
strcat( _buffer, other._buffer );
return *this;
}
int String::operator==( const String &rhs ) const
{
return ( _length == rhs._length && strcmp( _buffer, rhs._buffer ) == 0 );
}
int String::operator!=( const String &rhs ) const
{
return ( _length != rhs.length() || strcmp( _buffer, rhs._buffer ) != 0 );
}
int String::operator<( const String &rhs ) const
{
return strcmp( _buffer, rhs._buffer ) < 0;
}
int String::operator>( const String &rhs ) const
{
return strcmp( _buffer, rhs._buffer ) > 0;
}
int String::operator<=( const String &rhs ) const
{
return strcmp( _buffer, rhs._buffer ) <= 0;
}
int String::operator>=( const String & rhs ) const
{
return strcmp( _buffer, rhs._buffer ) >= 0;
}
char & String::operator[]( unsigned int index )
{
static char dummy_writable_char;
if (index >= _length || !_buffer) {
dummy_writable_char = 0;
return dummy_writable_char;
}
return _buffer[ index ];
}
char String::operator[]( unsigned int index ) const
{
// need to check for valid index, to do later
return _buffer[ index ];
}
boolean String::endsWith( const String &s2 ) const
{
if ( _length < s2._length )
return 0;
return strcmp( &_buffer[ _length - s2._length], s2._buffer ) == 0;
}
boolean String::equals( const String &s2 ) const
{
return ( _length == s2._length && strcmp( _buffer,s2._buffer ) == 0 );
}
boolean String::equalsIgnoreCase( const String &s2 ) const
{
if ( this == &s2 )
return true; //1;
else if ( _length != s2._length )
return false; //0;
return strcmp(toLowerCase()._buffer, s2.toLowerCase()._buffer) == 0;
}
String String::replace( char findChar, char replaceChar )
{
if ( _buffer == NULL ) return *this;
String theReturn = _buffer;
char* temp = theReturn._buffer;
while( (temp = strchr( temp, findChar )) != 0 )
*temp = replaceChar;
return theReturn;
}
String String::replace( const String& match, const String& replace )
{
if ( _buffer == NULL ) return *this;
String temp = _buffer, newString;
int loc;
while ( (loc = temp.indexOf( match )) != -1 )
{
newString += temp.substring( 0, loc );
newString += replace;
temp = temp.substring( loc + match._length );
}
newString += temp;
return newString;
}
int String::indexOf( char temp ) const
{
return indexOf( temp, 0 );
}
int String::indexOf( char ch, unsigned int fromIndex ) const
{
if ( fromIndex >= _length )
return -1;
const char* temp = strchr( &_buffer[fromIndex], ch );
if ( temp == NULL )
return -1;
return temp - _buffer;
}
int String::indexOf( const String &s2 ) const
{
return indexOf( s2, 0 );
}
int String::indexOf( const String &s2, unsigned int fromIndex ) const
{
if ( fromIndex >= _length )
return -1;
const char *theFind = strstr( &_buffer[ fromIndex ], s2._buffer );
if ( theFind == NULL )
return -1;
return theFind - _buffer; // pointer subtraction
}
int String::lastIndexOf( char theChar ) const
{
return lastIndexOf( theChar, _length - 1 );
}
int String::lastIndexOf( char ch, unsigned int fromIndex ) const
{
if ( fromIndex >= _length )
return -1;
char tempchar = _buffer[fromIndex + 1];
_buffer[fromIndex + 1] = '\0';
char* temp = strrchr( _buffer, ch );
_buffer[fromIndex + 1] = tempchar;
if ( temp == NULL )
return -1;
return temp - _buffer;
}
int String::lastIndexOf( const String &s2 ) const
{
return lastIndexOf( s2, _length - s2._length );
}
int String::lastIndexOf( const String &s2, unsigned int fromIndex ) const
{
// check for empty strings
if ( s2._length == 0 || s2._length - 1 > fromIndex || fromIndex >= _length )
return -1;
// matching first character
char temp = s2[ 0 ];
for ( int i = fromIndex; i >= 0; i-- )
{
if ( _buffer[ i ] == temp && (*this).substring( i, i + s2._length ).equals( s2 ) )
return i;
}
return -1;
}
boolean String::startsWith( const String &s2 ) const
{
if ( _length < s2._length )
return 0;
return startsWith( s2, 0 );
}
boolean String::startsWith( const String &s2, unsigned int offset ) const
{
if ( offset > _length - s2._length )
return 0;
return strncmp( &_buffer[offset], s2._buffer, s2._length ) == 0;
}
String String::substring( unsigned int left ) const
{
return substring( left, _length );
}
String String::substring( unsigned int left, unsigned int right ) const
{
if ( left > right )
{
int temp = right;
right = left;
left = temp;
}
if ( right > _length )
{
right = _length;
}
char temp = _buffer[ right ]; // save the replaced character
_buffer[ right ] = '\0';
String outPut = ( _buffer + left ); // pointer arithmetic
_buffer[ right ] = temp; //restore character
return outPut;
}
String String::toLowerCase() const
{
String temp = _buffer;
for ( unsigned int i = 0; i < _length; i++ )
temp._buffer[ i ] = (char)tolower( temp._buffer[ i ] );
return temp;
}
String String::toUpperCase() const
{
String temp = _buffer;
for ( unsigned int i = 0; i < _length; i++ )
temp._buffer[ i ] = (char)toupper( temp._buffer[ i ] );
return temp;
}
String String::trim() const
{
if ( _buffer == NULL ) return *this;
String temp = _buffer;
unsigned int i,j;
for ( i = 0; i < _length; i++ )
{
if ( !isspace(_buffer[i]) )
break;
}
for ( j = temp._length - 1; j > i; j-- )
{
if ( !isspace(_buffer[j]) )
break;
}
return temp.substring( i, j + 1);
}
void String::getBytes(unsigned char *buf, unsigned int bufsize)
{
if (!bufsize || !buf) return;
unsigned int len = bufsize - 1;
if (len > _length) len = _length;
strncpy((char *)buf, _buffer, len);
buf[len] = 0;
}
void String::toCharArray(char *buf, unsigned int bufsize)
{
if (!bufsize || !buf) return;
unsigned int len = bufsize - 1;
if (len > _length) len = _length;
strncpy(buf, _buffer, len);
buf[len] = 0;
}
long String::toInt() {
return atol(_buffer);
}

View File

@ -0,0 +1,112 @@
/*
WString.h - String library for Wiring & Arduino
Copyright (c) 2009-10 Hernando Barragan. 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 String_h
#define String_h
//#include "WProgram.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
class String
{
public:
// constructors
String( const char *value = "" );
String( const String &value );
String( const char );
String( const unsigned char );
String( const int, const int base=10);
String( const unsigned int, const int base=10 );
String( const long, const int base=10 );
String( const unsigned long, const int base=10 );
~String() { free(_buffer); _length = _capacity = 0;} //added _length = _capacity = 0;
// operators
const String & operator = ( const String &rhs );
const String & operator +=( const String &rhs );
//const String & operator +=( const char );
int operator ==( const String &rhs ) const;
int operator !=( const String &rhs ) const;
int operator < ( const String &rhs ) const;
int operator > ( const String &rhs ) const;
int operator <=( const String &rhs ) const;
int operator >=( const String &rhs ) const;
char operator []( unsigned int index ) const;
char& operator []( unsigned int index );
//operator const char *() const { return _buffer; }
// general methods
char charAt( unsigned int index ) const;
int compareTo( const String &anotherString ) const;
unsigned char endsWith( const String &suffix ) const;
unsigned char equals( const String &anObject ) const;
unsigned char equalsIgnoreCase( const String &anotherString ) const;
int indexOf( char ch ) const;
int indexOf( char ch, unsigned int fromIndex ) const;
int indexOf( const String &str ) const;
int indexOf( const String &str, unsigned int fromIndex ) const;
int lastIndexOf( char ch ) const;
int lastIndexOf( char ch, unsigned int fromIndex ) const;
int lastIndexOf( const String &str ) const;
int lastIndexOf( const String &str, unsigned int fromIndex ) const;
const unsigned int length( ) const { return _length; }
void setCharAt(unsigned int index, const char ch);
unsigned char startsWith( const String &prefix ) const;
unsigned char startsWith( const String &prefix, unsigned int toffset ) const;
String substring( unsigned int beginIndex ) const;
String substring( unsigned int beginIndex, unsigned int endIndex ) const;
String toLowerCase( ) const;
String toUpperCase( ) const;
String trim( ) const;
void getBytes(unsigned char *buf, unsigned int bufsize);
void toCharArray(char *buf, unsigned int bufsize);
long toInt( );
const String& concat( const String &str );
String replace( char oldChar, char newChar );
String replace( const String& match, const String& replace );
friend String operator + ( String lhs, const String &rhs );
protected:
char *_buffer; // the actual char array
unsigned int _capacity; // the array length minus one (for the '\0')
unsigned int _length; // the String length (not counting the '\0')
void getBuffer(unsigned int maxStrLen);
private:
};
// allocate buffer space
inline void String::getBuffer(unsigned int maxStrLen)
{
_capacity = maxStrLen;
_buffer = (char *) malloc(_capacity + 1);
if (_buffer == NULL) _length = _capacity = 0;
}
inline String operator+( String lhs, const String &rhs )
{
return lhs += rhs;
}
#endif

View File

@ -0,0 +1,515 @@
#ifndef Binary_h
#define Binary_h
#define B0 0
#define B00 0
#define B000 0
#define B0000 0
#define B00000 0
#define B000000 0
#define B0000000 0
#define B00000000 0
#define B1 1
#define B01 1
#define B001 1
#define B0001 1
#define B00001 1
#define B000001 1
#define B0000001 1
#define B00000001 1
#define B10 2
#define B010 2
#define B0010 2
#define B00010 2
#define B000010 2
#define B0000010 2
#define B00000010 2
#define B11 3
#define B011 3
#define B0011 3
#define B00011 3
#define B000011 3
#define B0000011 3
#define B00000011 3
#define B100 4
#define B0100 4
#define B00100 4
#define B000100 4
#define B0000100 4
#define B00000100 4
#define B101 5
#define B0101 5
#define B00101 5
#define B000101 5
#define B0000101 5
#define B00000101 5
#define B110 6
#define B0110 6
#define B00110 6
#define B000110 6
#define B0000110 6
#define B00000110 6
#define B111 7
#define B0111 7
#define B00111 7
#define B000111 7
#define B0000111 7
#define B00000111 7
#define B1000 8
#define B01000 8
#define B001000 8
#define B0001000 8
#define B00001000 8
#define B1001 9
#define B01001 9
#define B001001 9
#define B0001001 9
#define B00001001 9
#define B1010 10
#define B01010 10
#define B001010 10
#define B0001010 10
#define B00001010 10
#define B1011 11
#define B01011 11
#define B001011 11
#define B0001011 11
#define B00001011 11
#define B1100 12
#define B01100 12
#define B001100 12
#define B0001100 12
#define B00001100 12
#define B1101 13
#define B01101 13
#define B001101 13
#define B0001101 13
#define B00001101 13
#define B1110 14
#define B01110 14
#define B001110 14
#define B0001110 14
#define B00001110 14
#define B1111 15
#define B01111 15
#define B001111 15
#define B0001111 15
#define B00001111 15
#define B10000 16
#define B010000 16
#define B0010000 16
#define B00010000 16
#define B10001 17
#define B010001 17
#define B0010001 17
#define B00010001 17
#define B10010 18
#define B010010 18
#define B0010010 18
#define B00010010 18
#define B10011 19
#define B010011 19
#define B0010011 19
#define B00010011 19
#define B10100 20
#define B010100 20
#define B0010100 20
#define B00010100 20
#define B10101 21
#define B010101 21
#define B0010101 21
#define B00010101 21
#define B10110 22
#define B010110 22
#define B0010110 22
#define B00010110 22
#define B10111 23
#define B010111 23
#define B0010111 23
#define B00010111 23
#define B11000 24
#define B011000 24
#define B0011000 24
#define B00011000 24
#define B11001 25
#define B011001 25
#define B0011001 25
#define B00011001 25
#define B11010 26
#define B011010 26
#define B0011010 26
#define B00011010 26
#define B11011 27
#define B011011 27
#define B0011011 27
#define B00011011 27
#define B11100 28
#define B011100 28
#define B0011100 28
#define B00011100 28
#define B11101 29
#define B011101 29
#define B0011101 29
#define B00011101 29
#define B11110 30
#define B011110 30
#define B0011110 30
#define B00011110 30
#define B11111 31
#define B011111 31
#define B0011111 31
#define B00011111 31
#define B100000 32
#define B0100000 32
#define B00100000 32
#define B100001 33
#define B0100001 33
#define B00100001 33
#define B100010 34
#define B0100010 34
#define B00100010 34
#define B100011 35
#define B0100011 35
#define B00100011 35
#define B100100 36
#define B0100100 36
#define B00100100 36
#define B100101 37
#define B0100101 37
#define B00100101 37
#define B100110 38
#define B0100110 38
#define B00100110 38
#define B100111 39
#define B0100111 39
#define B00100111 39
#define B101000 40
#define B0101000 40
#define B00101000 40
#define B101001 41
#define B0101001 41
#define B00101001 41
#define B101010 42
#define B0101010 42
#define B00101010 42
#define B101011 43
#define B0101011 43
#define B00101011 43
#define B101100 44
#define B0101100 44
#define B00101100 44
#define B101101 45
#define B0101101 45
#define B00101101 45
#define B101110 46
#define B0101110 46
#define B00101110 46
#define B101111 47
#define B0101111 47
#define B00101111 47
#define B110000 48
#define B0110000 48
#define B00110000 48
#define B110001 49
#define B0110001 49
#define B00110001 49
#define B110010 50
#define B0110010 50
#define B00110010 50
#define B110011 51
#define B0110011 51
#define B00110011 51
#define B110100 52
#define B0110100 52
#define B00110100 52
#define B110101 53
#define B0110101 53
#define B00110101 53
#define B110110 54
#define B0110110 54
#define B00110110 54
#define B110111 55
#define B0110111 55
#define B00110111 55
#define B111000 56
#define B0111000 56
#define B00111000 56
#define B111001 57
#define B0111001 57
#define B00111001 57
#define B111010 58
#define B0111010 58
#define B00111010 58
#define B111011 59
#define B0111011 59
#define B00111011 59
#define B111100 60
#define B0111100 60
#define B00111100 60
#define B111101 61
#define B0111101 61
#define B00111101 61
#define B111110 62
#define B0111110 62
#define B00111110 62
#define B111111 63
#define B0111111 63
#define B00111111 63
#define B1000000 64
#define B01000000 64
#define B1000001 65
#define B01000001 65
#define B1000010 66
#define B01000010 66
#define B1000011 67
#define B01000011 67
#define B1000100 68
#define B01000100 68
#define B1000101 69
#define B01000101 69
#define B1000110 70
#define B01000110 70
#define B1000111 71
#define B01000111 71
#define B1001000 72
#define B01001000 72
#define B1001001 73
#define B01001001 73
#define B1001010 74
#define B01001010 74
#define B1001011 75
#define B01001011 75
#define B1001100 76
#define B01001100 76
#define B1001101 77
#define B01001101 77
#define B1001110 78
#define B01001110 78
#define B1001111 79
#define B01001111 79
#define B1010000 80
#define B01010000 80
#define B1010001 81
#define B01010001 81
#define B1010010 82
#define B01010010 82
#define B1010011 83
#define B01010011 83
#define B1010100 84
#define B01010100 84
#define B1010101 85
#define B01010101 85
#define B1010110 86
#define B01010110 86
#define B1010111 87
#define B01010111 87
#define B1011000 88
#define B01011000 88
#define B1011001 89
#define B01011001 89
#define B1011010 90
#define B01011010 90
#define B1011011 91
#define B01011011 91
#define B1011100 92
#define B01011100 92
#define B1011101 93
#define B01011101 93
#define B1011110 94
#define B01011110 94
#define B1011111 95
#define B01011111 95
#define B1100000 96
#define B01100000 96
#define B1100001 97
#define B01100001 97
#define B1100010 98
#define B01100010 98
#define B1100011 99
#define B01100011 99
#define B1100100 100
#define B01100100 100
#define B1100101 101
#define B01100101 101
#define B1100110 102
#define B01100110 102
#define B1100111 103
#define B01100111 103
#define B1101000 104
#define B01101000 104
#define B1101001 105
#define B01101001 105
#define B1101010 106
#define B01101010 106
#define B1101011 107
#define B01101011 107
#define B1101100 108
#define B01101100 108
#define B1101101 109
#define B01101101 109
#define B1101110 110
#define B01101110 110
#define B1101111 111
#define B01101111 111
#define B1110000 112
#define B01110000 112
#define B1110001 113
#define B01110001 113
#define B1110010 114
#define B01110010 114
#define B1110011 115
#define B01110011 115
#define B1110100 116
#define B01110100 116
#define B1110101 117
#define B01110101 117
#define B1110110 118
#define B01110110 118
#define B1110111 119
#define B01110111 119
#define B1111000 120
#define B01111000 120
#define B1111001 121
#define B01111001 121
#define B1111010 122
#define B01111010 122
#define B1111011 123
#define B01111011 123
#define B1111100 124
#define B01111100 124
#define B1111101 125
#define B01111101 125
#define B1111110 126
#define B01111110 126
#define B1111111 127
#define B01111111 127
#define B10000000 128
#define B10000001 129
#define B10000010 130
#define B10000011 131
#define B10000100 132
#define B10000101 133
#define B10000110 134
#define B10000111 135
#define B10001000 136
#define B10001001 137
#define B10001010 138
#define B10001011 139
#define B10001100 140
#define B10001101 141
#define B10001110 142
#define B10001111 143
#define B10010000 144
#define B10010001 145
#define B10010010 146
#define B10010011 147
#define B10010100 148
#define B10010101 149
#define B10010110 150
#define B10010111 151
#define B10011000 152
#define B10011001 153
#define B10011010 154
#define B10011011 155
#define B10011100 156
#define B10011101 157
#define B10011110 158
#define B10011111 159
#define B10100000 160
#define B10100001 161
#define B10100010 162
#define B10100011 163
#define B10100100 164
#define B10100101 165
#define B10100110 166
#define B10100111 167
#define B10101000 168
#define B10101001 169
#define B10101010 170
#define B10101011 171
#define B10101100 172
#define B10101101 173
#define B10101110 174
#define B10101111 175
#define B10110000 176
#define B10110001 177
#define B10110010 178
#define B10110011 179
#define B10110100 180
#define B10110101 181
#define B10110110 182
#define B10110111 183
#define B10111000 184
#define B10111001 185
#define B10111010 186
#define B10111011 187
#define B10111100 188
#define B10111101 189
#define B10111110 190
#define B10111111 191
#define B11000000 192
#define B11000001 193
#define B11000010 194
#define B11000011 195
#define B11000100 196
#define B11000101 197
#define B11000110 198
#define B11000111 199
#define B11001000 200
#define B11001001 201
#define B11001010 202
#define B11001011 203
#define B11001100 204
#define B11001101 205
#define B11001110 206
#define B11001111 207
#define B11010000 208
#define B11010001 209
#define B11010010 210
#define B11010011 211
#define B11010100 212
#define B11010101 213
#define B11010110 214
#define B11010111 215
#define B11011000 216
#define B11011001 217
#define B11011010 218
#define B11011011 219
#define B11011100 220
#define B11011101 221
#define B11011110 222
#define B11011111 223
#define B11100000 224
#define B11100001 225
#define B11100010 226
#define B11100011 227
#define B11100100 228
#define B11100101 229
#define B11100110 230
#define B11100111 231
#define B11101000 232
#define B11101001 233
#define B11101010 234
#define B11101011 235
#define B11101100 236
#define B11101101 237
#define B11101110 238
#define B11101111 239
#define B11110000 240
#define B11110001 241
#define B11110010 242
#define B11110011 243
#define B11110100 244
#define B11110101 245
#define B11110110 246
#define B11110111 247
#define B11111000 248
#define B11111001 249
#define B11111010 250
#define B11111011 251
#define B11111100 252
#define B11111101 253
#define B11111110 254
#define B11111111 255
#endif

View File

@ -0,0 +1,14 @@
#include <WProgram.h>
int main(void)
{
init();
setup();
for (;;)
loop();
return 0;
}

View File

@ -0,0 +1,12 @@
int main(void)
{
init();
setup();
for (;;)
loop();
return 0;
}

View File

@ -0,0 +1,200 @@
/*
pins_arduino.c - pin definitions for the Arduino board
Part of Arduino / Wiring Lite
Copyright (c) 2005 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: pins_arduino.c 254 2007-04-20 23:17:38Z mellis $
*/
#include <avr/io.h>
#include "wiring_private.h"
#include "pins_arduino.h"
// On the Sanguino board, digital pins are also used
// for the analog output (software PWM). Analog input
// pins are a separate set.
// ATMEL ATMEGA644P / SANGUINO
//
// +---\/---+
// INT0 (D 0) PB0 1| |40 PA0 (AI 0 / D31)
// INT1 (D 1) PB1 2| |39 PA1 (AI 1 / D30)
// INT2 (D 2) PB2 3| |38 PA2 (AI 2 / D29)
// PWM (D 3) PB3 4| |37 PA3 (AI 3 / D28)
// PWM (D 4) PB4 5| |36 PA4 (AI 4 / D27)
// MOSI (D 5) PB5 6| |35 PA5 (AI 5 / D26)
// MISO (D 6) PB6 7| |34 PA6 (AI 6 / D25)
// SCK (D 7) PB7 8| |33 PA7 (AI 7 / D24)
// RST 9| |32 AREF
// VCC 10| |31 GND
// GND 11| |30 AVCC
// XTAL2 12| |29 PC7 (D 23)
// XTAL1 13| |28 PC6 (D 22)
// RX0 (D 8) PD0 14| |27 PC5 (D 21) TDI
// TX0 (D 9) PD1 15| |26 PC4 (D 20) TDO
// RX1 (D 10) PD2 16| |25 PC3 (D 19) TMS
// TX1 (D 11) PD3 17| |24 PC2 (D 18) TCK
// PWM (D 12) PD4 18| |23 PC1 (D 17) SDA
// PWM (D 13) PD5 19| |22 PC0 (D 16) SCL
// PWM (D 14) PD6 20| |21 PD7 (D 15) PWM
// +--------+
//
#define PA 1
#define PB 2
#define PC 3
#define PD 4
// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
const uint8_t PROGMEM port_to_mode_PGM[] =
{
NOT_A_PORT,
(uint8_t) &DDRA,
(uint8_t) &DDRB,
(uint8_t) &DDRC,
(uint8_t) &DDRD,
};
const uint8_t PROGMEM port_to_output_PGM[] =
{
NOT_A_PORT,
(uint8_t) &PORTA,
(uint8_t) &PORTB,
(uint8_t) &PORTC,
(uint8_t) &PORTD,
};
const uint8_t PROGMEM port_to_input_PGM[] =
{
NOT_A_PORT,
(uint8_t) &PINA,
(uint8_t) &PINB,
(uint8_t) &PINC,
(uint8_t) &PIND,
};
const uint8_t PROGMEM digital_pin_to_port_PGM[] =
{
PB, /* 0 */
PB,
PB,
PB,
PB,
PB,
PB,
PB,
PD, /* 8 */
PD,
PD,
PD,
PD,
PD,
PD,
PD,
PC, /* 16 */
PC,
PC,
PC,
PC,
PC,
PC,
PC,
PA, /* 24 */
PA,
PA,
PA,
PA,
PA,
PA,
PA /* 31 */
};
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] =
{
_BV(0), /* 0, port B */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
_BV(0), /* 8, port D */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
_BV(0), /* 16, port C */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
_BV(7), /* 24, port A */
_BV(6),
_BV(5),
_BV(4),
_BV(3),
_BV(2),
_BV(1),
_BV(0)
};
const uint8_t PROGMEM digital_pin_to_timer_PGM[] =
{
NOT_ON_TIMER, /* 0 - PB0 */
NOT_ON_TIMER, /* 1 - PB1 */
NOT_ON_TIMER, /* 2 - PB2 */
TIMER0A, /* 3 - PB3 */
TIMER0B, /* 4 - PB4 */
NOT_ON_TIMER, /* 5 - PB5 */
NOT_ON_TIMER, /* 6 - PB6 */
NOT_ON_TIMER, /* 7 - PB7 */
NOT_ON_TIMER, /* 8 - PD0 */
NOT_ON_TIMER, /* 9 - PD1 */
NOT_ON_TIMER, /* 10 - PD2 */
NOT_ON_TIMER, /* 11 - PD3 */
TIMER1B, /* 12 - PD4 */
TIMER1A, /* 13 - PD5 */
TIMER2B, /* 14 - PD6 */
TIMER2A, /* 15 - PD7 */
NOT_ON_TIMER, /* 16 - PC0 */
NOT_ON_TIMER, /* 17 - PC1 */
NOT_ON_TIMER, /* 18 - PC2 */
NOT_ON_TIMER, /* 19 - PC3 */
NOT_ON_TIMER, /* 20 - PC4 */
NOT_ON_TIMER, /* 21 - PC5 */
NOT_ON_TIMER, /* 22 - PC6 */
NOT_ON_TIMER, /* 23 - PC7 */
NOT_ON_TIMER, /* 24 - PA0 */
NOT_ON_TIMER, /* 25 - PA1 */
NOT_ON_TIMER, /* 26 - PA2 */
NOT_ON_TIMER, /* 27 - PA3 */
NOT_ON_TIMER, /* 28 - PA4 */
NOT_ON_TIMER, /* 29 - PA5 */
NOT_ON_TIMER, /* 30 - PA6 */
NOT_ON_TIMER /* 31 - PA7 */
};

View File

@ -0,0 +1,65 @@
/*
pins_arduino.h - Pin definition functions for Arduino
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2007 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
*/
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <avr/pgmspace.h>
#define NOT_A_PIN 0
#define NOT_A_PORT 0
#define NOT_ON_TIMER 0
#define TIMER0A 1
#define TIMER0B 2
#define TIMER1A 3
#define TIMER1B 4
#define TIMER2 5
#define TIMER2A 6
#define TIMER2B 7
extern const uint8_t PROGMEM port_to_mode_PGM[];
extern const uint8_t PROGMEM port_to_input_PGM[];
extern const uint8_t PROGMEM port_to_output_PGM[];
extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
// Get the bit location within the hardware port of the given virtual pin.
// This comes from the pins_*.c file for the active board configuration.
//
// These perform slightly better as macros compared to inline functions
//
#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
#define analogInPinToBit(P) (P)
#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_byte( port_to_output_PGM + (P))) )
#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_byte( port_to_input_PGM + (P))) )
#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_byte( port_to_mode_PGM + (P))) )
#endif

View File

@ -24,12 +24,19 @@
#include "wiring_private.h"
volatile unsigned long timer0_overflow_count = 0;
volatile unsigned long timer0_clock_cycles = 0;
volatile unsigned long timer0_millis = 0;
SIGNAL(TIMER0_OVF_vect)
{
timer0_overflow_count++;
// timer 0 prescale factor is 64 and the timer overflows at 256
timer0_millis++;
timer0_clock_cycles += 64UL * 256UL;
while (timer0_clock_cycles > clockCyclesPerMicrosecond() * 1000UL) {
timer0_clock_cycles -= clockCyclesPerMicrosecond() * 1000UL;
timer0_millis++;
}
}
unsigned long millis()
@ -46,6 +53,27 @@ unsigned long millis()
return m;
}
unsigned long micros() {
unsigned long m, t;
uint8_t oldSREG = SREG;
cli();
t = TCNT0;
#ifdef TIFR0
if ((TIFR0 & _BV(TOV0)) && (t == 0))
t = 256;
#else
if ((TIFR & _BV(TOV0)) && (t == 0))
t = 256;
#endif
m = timer0_overflow_count;
SREG = oldSREG;
return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond());
}
void delay(unsigned long ms)
{
unsigned long start = millis();
@ -139,7 +167,7 @@ void init()
// this is better for motors as it ensures an even waveform
// note, however, that fast pwm mode can achieve a frequency of up
// 8 MHz (with a 16 MHz clock) at 50% duty cycle
#if 0
// set timer 1 prescale factor to 64
sbi(TCCR1B, CS11);
sbi(TCCR1B, CS10);
@ -172,5 +200,4 @@ void init()
//TODO: test to see if disabling this helps?
//UCSR1B = 0;
#endif
#endif
}

View File

@ -0,0 +1,135 @@
/*
wiring.h - Partial implementation of the Wiring API for the ATmega8.
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: wiring.h 387 2008-03-08 21:30:00Z mellis $
*/
#ifndef Wiring_h
#define Wiring_h
#include <avr/io.h>
#include "binary.h"
#ifdef __cplusplus
extern "C"{
#endif
#define HIGH 0x1
#define LOW 0x0
#define INPUT 0x0
#define OUTPUT 0x1
#define true 0x1
#define false 0x0
#define PI 3.14159265
#define HALF_PI 1.57079
#define TWO_PI 6.283185
#define DEG_TO_RAD 0.01745329
#define RAD_TO_DEG 57.2957786
#define SERIAL 0x0
#define DISPLAY 0x1
#define LSBFIRST 0
#define MSBFIRST 1
#define CHANGE 1
#define FALLING 2
#define RISING 3
#define INTERNAL 3
#define DEFAULT 1
#define EXTERNAL 0
// undefine stdlib's abs if encountered
#ifdef abs
#undef abs
#endif
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(x) ((x)>0?(x):-(x))
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
#if __AVR_LIBC_VERSION__ < 10701UL
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
#endif
#define radians(deg) ((deg)*DEG_TO_RAD)
#define degrees(rad) ((rad)*RAD_TO_DEG)
#define sq(x) ((x)*(x))
#define interrupts() sei()
#define noInterrupts() cli()
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
#define lowByte(w) ((w) & 0xff)
#define highByte(w) ((w) >> 8)
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
typedef unsigned int word;
#define bit(b) (1 << (b))
typedef uint8_t boolean;
typedef uint8_t byte;
void init(void);
void pinMode(uint8_t, uint8_t);
void digitalWrite(uint8_t, uint8_t);
int digitalRead(uint8_t);
int analogRead(uint8_t);
void analogReference(uint8_t mode);
void analogWrite(uint8_t, int);
void beginSerial(uint8_t, long);
void serialWrite(uint8_t, unsigned char);
int serialAvailable(uint8_t);
int serialRead(uint8_t);
void serialFlush(uint8_t);
unsigned long millis(void);
unsigned long micros(void);
void delay(unsigned long);
void delayMicroseconds(unsigned int us);
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val);
void attachInterrupt(uint8_t, void (*)(void), int mode);
void detachInterrupt(uint8_t);
void setup(void);
void loop(void);
#ifdef __cplusplus
} // extern "C"
#endif
#endif

View File

@ -0,0 +1,116 @@
/*
wiring_analog.c - analog input and output
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
*/
#include "wiring_private.h"
#include "pins_arduino.h"
uint8_t analog_reference = DEFAULT;
void analogReference(uint8_t mode)
{
// can't actually set the register here because the default setting
// will connect AVCC and the AREF pin, which would cause a short if
// there's something connected to AREF.
analog_reference = mode;
}
int analogRead(uint8_t pin)
{
uint8_t low, high, ch = analogInPinToBit(pin);
// set the analog reference (high two bits of ADMUX) and select the
// channel (low 4 bits). this also sets ADLAR (left-adjust result)
// to 0 (the default).
// the final AND is to clear the pos/neg reference bits
ADMUX = ((analog_reference << 6) | (pin & 0x0f)) & B11000111;
// without a delay, we seem to read from the wrong channel
//delay(1);
// start the conversion
sbi(ADCSRA, ADSC);
// ADSC is cleared when the conversion finishes
while (bit_is_set(ADCSRA, ADSC));
// we have to read ADCL first; doing so locks both ADCL
// and ADCH until ADCH is read. reading ADCL second would
// cause the results of each conversion to be discarded,
// as ADCL and ADCH would be locked when it completed.
low = ADCL;
high = ADCH;
// combine the two bytes
return (high << 8) | low;
}
// Right now, PWM output only works on the pins with
// hardware support. These are defined in the appropriate
// pins_*.c file. For the rest of the pins, we default
// to digital output.
void analogWrite(uint8_t pin, int val)
{
// We need to make sure the PWM output is enabled for those pins
// that support it, as we turn it off when digitally reading or
// writing with them. Also, make sure the pin is in output mode
// for consistenty with Wiring, which doesn't require a pinMode
// call for the analog output pins.
pinMode(pin, OUTPUT);
if (digitalPinToTimer(pin) == TIMER1A) {
// connect pwm to pin on timer 1, channel A
sbi(TCCR1A, COM1A1);
// set pwm duty
OCR1A = val;
} else if (digitalPinToTimer(pin) == TIMER1B) {
// connect pwm to pin on timer 1, channel B
sbi(TCCR1A, COM1B1);
// set pwm duty
OCR1B = val;
} else if (digitalPinToTimer(pin) == TIMER0A) {
// connect pwm to pin on timer 0, channel A
sbi(TCCR0A, COM0A1);
// set pwm duty
OCR0A = val;
} else if (digitalPinToTimer(pin) == TIMER0B) {
// connect pwm to pin on timer 0, channel B
sbi(TCCR0A, COM0B1);
// set pwm duty
OCR0B = val;
} else if (digitalPinToTimer(pin) == TIMER2A) {
// connect pwm to pin on timer 2, channel A
sbi(TCCR2A, COM2A1);
// set pwm duty
OCR2A = val;
} else if (digitalPinToTimer(pin) == TIMER2B) {
// connect pwm to pin on timer 2, channel B
sbi(TCCR2A, COM2B1);
// set pwm duty
OCR2B = val;
} else if (val < 128)
//fail semi-intelligently
digitalWrite(pin, LOW);
else
digitalWrite(pin, HIGH);
}

View File

@ -0,0 +1,95 @@
/*
wiring_digital.c - digital input and output functions
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
*/
#include "wiring_private.h"
#include "pins_arduino.h"
void pinMode(uint8_t pin, uint8_t mode)
{
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *reg;
if (port == NOT_A_PIN) return;
// JWS: can I let the optimizer do this?
reg = portModeRegister(port);
if (mode == INPUT) *reg &= ~bit;
else *reg |= bit;
}
// Forcing this inline keeps the callers from having to push their own stuff
// on the stack. It is a good performance win and only takes 1 more byte per
// user than calling. (It will take more bytes on the 168.)
//
// But shouldn't this be moved into pinMode? Seems silly to check and do on
// each digitalread or write.
//
static inline void turnOffPWM(uint8_t timer) __attribute__ ((always_inline));
static inline void turnOffPWM(uint8_t timer)
{
if (timer == TIMER0A) cbi(TCCR0A, COM0A1);
if (timer == TIMER0B) cbi(TCCR0A, COM0B1);
if (timer == TIMER1A) cbi(TCCR1A, COM1A1);
if (timer == TIMER1B) cbi(TCCR1A, COM1B1);
if (timer == TIMER2A) cbi(TCCR2A, COM2A1);
if (timer == TIMER2B) cbi(TCCR2A, COM2B1);
}
void digitalWrite(uint8_t pin, uint8_t val)
{
uint8_t timer = digitalPinToTimer(pin);
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *out;
if (port == NOT_A_PIN) return;
// If the pin that support PWM output, we need to turn it off
// before doing a digital write.
if (timer != NOT_ON_TIMER) turnOffPWM(timer);
out = portOutputRegister(port);
if (val == LOW) *out &= ~bit;
else *out |= bit;
}
int digitalRead(uint8_t pin)
{
uint8_t timer = digitalPinToTimer(pin);
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
if (port == NOT_A_PIN) return LOW;
// If the pin that support PWM output, we need to turn it off
// before getting a digital reading.
if (timer != NOT_ON_TIMER) turnOffPWM(timer);
if (*portInputRegister(port) & bit) return HIGH;
return LOW;
}

View File

@ -0,0 +1,60 @@
/*
wiring_private.h - Internal header file.
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: wiring.h 239 2007-01-12 17:58:39Z mellis $
*/
#ifndef WiringPrivate_h
#define WiringPrivate_h
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <avr/delay.h>
#include <stdio.h>
#include <stdarg.h>
#include "wiring.h"
#ifdef __cplusplus
extern "C"{
#endif
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
#define EXTERNAL_INT_0 0
#define EXTERNAL_INT_1 1
#define EXTERNAL_INT_2 2
#define EXTERNAL_NUM_INTERRUPTS 3
typedef void (*voidFuncPtr)(void);
#ifdef __cplusplus
} // extern "C"
#endif
#endif

View File

@ -0,0 +1,66 @@
/*
wiring_pulse.c - pulseIn() function
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
*/
#include "wiring_private.h"
#include "pins_arduino.h"
/* Measures the length (in microseconds) of a pulse on the pin; state is HIGH
* or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds
* to 3 minutes in length, but must be called at least a few dozen microseconds
* before the start of the pulse. */
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
{
// cache the port and bit of the pin in order to speed up the
// pulse width measuring loop and achieve finer resolution. calling
// digitalRead() instead yields much coarser resolution.
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
uint8_t stateMask = (state ? bit : 0);
unsigned long width = 0; // keep initialization out of time critical area
// convert the timeout from microseconds to a number of times through
// the initial loop; it takes 16 clock cycles per iteration.
unsigned long numloops = 0;
unsigned long maxloops = microsecondsToClockCycles(timeout) / 16;
// wait for any previous pulse to end
while ((*portInputRegister(port) & bit) == stateMask)
if (numloops++ == maxloops)
return 0;
// wait for the pulse to start
while ((*portInputRegister(port) & bit) != stateMask)
if (numloops++ == maxloops)
return 0;
// wait for the pulse to stop
while ((*portInputRegister(port) & bit) == stateMask)
width++;
// convert the reading to microseconds. The loop has been determined
// to be 10 clock cycles long and have about 16 clocks between the edge
// and the start of the loop. There will be some error introduced by
// the interrupt handlers.
return clockCyclesToMicroseconds(width * 10 + 16);
}

View File

@ -31,7 +31,6 @@
// location to which to write the next incoming character and rx_buffer_tail
// is the index of the location from which to read.
#define RX_BUFFER_SIZE 128
#define RX_BUFFER_MASK 0x7f
#if defined(__AVR_ATmega644P__)
unsigned char rx_buffer[2][RX_BUFFER_SIZE];
@ -91,7 +90,7 @@ void serialWrite(uint8_t uart, unsigned char c)
int serialAvailable(uint8_t uart)
{
return (RX_BUFFER_SIZE + rx_buffer_head[uart] - rx_buffer_tail[uart]) & RX_BUFFER_MASK;
return (RX_BUFFER_SIZE + rx_buffer_head[uart] - rx_buffer_tail[uart]) % RX_BUFFER_SIZE;
}
int serialRead(uint8_t uart)
@ -101,7 +100,7 @@ int serialRead(uint8_t uart)
return -1;
} else {
unsigned char c = rx_buffer[uart][rx_buffer_tail[uart]];
rx_buffer_tail[uart] = (rx_buffer_tail[uart] + 1) & RX_BUFFER_MASK;
rx_buffer_tail[uart] = (rx_buffer_tail[uart] + 1) % RX_BUFFER_SIZE;
return c;
}
}
@ -121,7 +120,7 @@ ISR(USART##uart_##_RX_vect) \
{ \
unsigned char c = UDR##uart_; \
\
int i = (rx_buffer_head[uart_] + 1) & RX_BUFFER_MASK; \
int i = (rx_buffer_head[uart_] + 1) % RX_BUFFER_SIZE; \
\
/* if we should be storing the received character into the location \
just before the tail (meaning that the head would advance to the \

View File

@ -0,0 +1,40 @@
/*
wiring_shift.c - shiftOut() function
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
*/
#include "wiring_private.h"
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val)
{
int i;
for (i = 0; i < 8; i++) {
if (bitOrder == LSBFIRST)
digitalWrite(dataPin, !!(val & (1 << i)));
else
digitalWrite(dataPin, !!(val & (1 << (7 - i))));
digitalWrite(clockPin, HIGH);
digitalWrite(clockPin, LOW);
}
}

View File

@ -0,0 +1,99 @@
##############################################################
sanguino.name=Sanguino
sanguino.upload.protocol=stk500
sanguino.upload.maximum_size=63488
sanguino.upload.speed=38400
sanguino.bootloader.low_fuses=0xFF
sanguino.bootloader.high_fuses=0xDC
sanguino.bootloader.extended_fuses=0xFD
sanguino.bootloader.path=atmega644p
sanguino.bootloader.file=ATmegaBOOT_644P.hex
sanguino.bootloader.unlock_bits=0x3F
sanguino.bootloader.lock_bits=0x0F
sanguino.build.mcu=atmega644p
sanguino.build.f_cpu=16000000L
sanguino.build.core=arduino
##############################################################
atmega644.name=Sanguino W/ ATmega644P
atmega644.upload.protocol=stk500
atmega644.upload.maximum_size=63488
atmega644.upload.speed=57600
atmega644.bootloader.low_fuses=0xFF
atmega644.bootloader.high_fuses=0x9A
atmega644.bootloader.extended_fuses=0xFF
atmega644.bootloader.path=atmega
atmega644.bootloader.file=ATmegaBOOT_168_atmega644p.hex
#atmega644.bootloader.file=ATmegaBOOT_644P.hex
atmega644.bootloader.unlock_bits=0x3F
atmega644.bootloader.lock_bits=0x0F
atmega644.build.mcu=atmega644p
atmega644.build.f_cpu=16000000L
atmega644.build.core=arduino
##############################################################
atmega12848m.name=Sanguino W/ ATmega1284p 8mhz
atmega12848m.upload.protocol=stk500
atmega12848m.upload.maximum_size=131072
atmega12848m.upload.speed=19200
atmega12848m.bootloader.low_fuses=0xFD
atmega12848m.bootloader.high_fuses=0x9A
atmega12848m.bootloader.extended_fuses=0xFF
atmega12848m.bootloader.path=atmega
atmega12848m.bootloader.file=ATmegaBOOT_168_atmega1284p_8m.hex
atmega12848m.bootloader.unlock_bits=0x3F
atmega12848m.bootloader.lock_bits=0x0F
atmega12848m.build.mcu=atmega1284p
atmega12848m.build.f_cpu=8000000L
atmega12848m.build.core=arduino
##############################################################
atmega1284.name=Sanguino W/ ATmega1284p 16mhz
atmega1284.upload.protocol=stk500
atmega1284.upload.maximum_size=131072
atmega1284.upload.speed=57600
atmega1284.bootloader.low_fuses=0xFF
atmega1284.bootloader.high_fuses=0x9A
atmega1284.bootloader.extended_fuses=0xFF
atmega1284.bootloader.path=atmega
atmega1284.bootloader.file=ATmegaBOOT_168_atmega1284p.hex
atmega1284.bootloader.unlock_bits=0x3F
atmega1284.bootloader.lock_bits=0x0F
atmega1284.build.mcu=atmega1284p
atmega1284.build.f_cpu=16000000L
atmega1284.build.core=arduino
##############################################################
atmega1284s.name=Sanguino W/ ATmega1284p 20mhz
atmega1284s.upload.protocol=stk500
atmega1284s.upload.maximum_size=131072
atmega1284s.upload.speed=57600
atmega1284s.bootloader.low_fuses=0xFF
atmega1284s.bootloader.high_fuses=0x9A
atmega1284s.bootloader.extended_fuses=0xFF
atmega1284s.bootloader.path=atmega
atmega1284s.bootloader.file=ATmegaBOOT_168_atmega1284p.hex
atmega1284s.bootloader.unlock_bits=0x3F
atmega1284s.bootloader.lock_bits=0x0F
atmega1284s.build.mcu=atmega1284p
atmega1284s.build.f_cpu=20000000L
atmega1284s.build.core=arduino
#

View File

@ -0,0 +1,470 @@
# Makefile for ATmegaBOOT
# E.Lins, 18.7.2005
# $Id$
#
# Instructions
#
# To make bootloader .hex file:
# make diecimila
# make lilypad
# make ng
# etc...
#
# To burn bootloader .hex file:
# make diecimila_isp
# make lilypad_isp
# make ng_isp
# etc...
# program name should not be changed...
PROGRAM = optiboot
# The default behavior is to build using tools that are in the users
# current path variables, but we can also build using an installed
# Arduino user IDE setup, or the Arduino source tree.
# Uncomment this next lines to build within the arduino environment,
# using the arduino-included avrgcc toolset (mac and pc)
# ENV ?= arduino
# ENV ?= arduinodev
# OS ?= macosx
# OS ?= windows
# enter the parameters for the avrdude isp tool
ISPTOOL = stk500v2
ISPPORT = usb
ISPSPEED = -b 115200
MCU_TARGET = atmega168
LDSECTIONS = -Wl,--section-start=.text=0x3e00 -Wl,--section-start=.version=0x3ffe
# Build environments
# Start of some ugly makefile-isms to allow optiboot to be built
# in several different environments. See the README.TXT file for
# details.
# default
fixpath = $(1)
ifeq ($(ENV), arduino)
# For Arduino, we assume that we're connected to the optiboot directory
# included with the arduino distribution, which means that the full set
# of avr-tools are "right up there" in standard places.
TOOLROOT = ../../../tools
GCCROOT = $(TOOLROOT)/avr/bin/
AVRDUDE_CONF = -C$(TOOLROOT)/avr/etc/avrdude.conf
ifeq ($(OS), windows)
# On windows, SOME of the tool paths will need to have backslashes instead
# of forward slashes (because they use windows cmd.exe for execution instead
# of a unix/mingw shell?) We also have to ensure that a consistent shell
# is used even if a unix shell is installed (ie as part of WINAVR)
fixpath = $(subst /,\,$1)
SHELL = cmd.exe
endif
else ifeq ($(ENV), arduinodev)
# Arduino IDE source code environment. Use the unpacked compilers created
# by the build (you'll need to do "ant build" first.)
ifeq ($(OS), macosx)
TOOLROOT = ../../../../build/macosx/work/Arduino.app/Contents/Resources/Java/hardware/tools
endif
ifeq ($(OS), windows)
TOOLROOT = ../../../../build/windows/work/hardware/tools
endif
GCCROOT = $(TOOLROOT)/avr/bin/
AVRDUDE_CONF = -C$(TOOLROOT)/avr/etc/avrdude.conf
else
GCCROOT =
AVRDUDE_CONF =
endif
#
# End of build environment code.
# the efuse should really be 0xf8; since, however, only the lower
# three bits of that byte are used on the atmega168, avrdude gets
# confused if you specify 1's for the higher bits, see:
# http://tinker.it/now/2007/02/24/the-tale-of-avrdude-atmega168-and-extended-bits-fuses/
#
# similarly, the lock bits should be 0xff instead of 0x3f (to
# unlock the bootloader section) and 0xcf instead of 0x2f (to
# lock it), but since the high two bits of the lock byte are
# unused, avrdude would get confused.
ISPFUSES = $(GCCROOT)avrdude $(AVRDUDE_CONF) -c $(ISPTOOL) \
-p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \
-e -u -U lock:w:0x3f:m -U efuse:w:0x$(EFUSE):m \
-U hfuse:w:0x$(HFUSE):m -U lfuse:w:0x$(LFUSE):m
ISPFLASH = $(GCCROOT)avrdude $(AVRDUDE_CONF) -c $(ISPTOOL) \
-p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \
-U flash:w:$(PROGRAM)_$(TARGET).hex -U lock:w:0x2f:m
STK500 = "C:\Program Files\Atmel\AVR Tools\STK500\Stk500.exe"
STK500-1 = $(STK500) -e -d$(MCU_TARGET) -pf -vf -if$(PROGRAM)_$(TARGET).hex \
-lFF -LFF -f$(HFUSE)$(LFUSE) -EF8 -ms -q -cUSB -I200kHz -s -wt
STK500-2 = $(STK500) -d$(MCU_TARGET) -ms -q -lCF -LCF -cUSB -I200kHz -s -wt
OBJ = $(PROGRAM).o
OPTIMIZE = -Os -fno-inline-small-functions -fno-split-wide-types -mshort-calls
DEFS =
LIBS =
CC = $(GCCROOT)avr-gcc
# Override is only needed by avr-lib build system.
override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(AVR_FREQ) $(DEFS)
override LDFLAGS = $(LDSECTIONS) -Wl,--relax -Wl,--gc-sections -nostartfiles -nostdlib
OBJCOPY = $(GCCROOT)avr-objcopy
OBJDUMP = $(call fixpath,$(GCCROOT)avr-objdump)
SIZE = $(GCCROOT)avr-size
# Test platforms
# Virtual boot block test
virboot328: TARGET = atmega328
virboot328: MCU_TARGET = atmega328p
virboot328: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' '-DVIRTUAL_BOOT'
virboot328: AVR_FREQ = 16000000L
virboot328: LDSECTIONS = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
virboot328: $(PROGRAM)_atmega328.hex
virboot328: $(PROGRAM)_atmega328.lst
# 20MHz clocked platforms
#
# These are capable of 230400 baud, or 115200 baud on PC (Arduino Avrdude issue)
#
pro20: TARGET = pro_20mhz
pro20: MCU_TARGET = atmega168
pro20: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
pro20: AVR_FREQ = 20000000L
pro20: $(PROGRAM)_pro_20mhz.hex
pro20: $(PROGRAM)_pro_20mhz.lst
pro20_isp: pro20
pro20_isp: TARGET = pro_20mhz
# 2.7V brownout
pro20_isp: HFUSE = DD
# Full swing xtal (20MHz) 258CK/14CK+4.1ms
pro20_isp: LFUSE = C6
# 512 byte boot
pro20_isp: EFUSE = 04
pro20_isp: isp
# 16MHz clocked platforms
#
# These are capable of 230400 baud, or 115200 baud on PC (Arduino Avrdude issue)
#
pro16: TARGET = pro_16MHz
pro16: MCU_TARGET = atmega168
pro16: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
pro16: AVR_FREQ = 16000000L
pro16: $(PROGRAM)_pro_16MHz.hex
pro16: $(PROGRAM)_pro_16MHz.lst
pro16_isp: pro16
pro16_isp: TARGET = pro_16MHz
# 2.7V brownout
pro16_isp: HFUSE = DD
# Full swing xtal (20MHz) 258CK/14CK+4.1ms
pro16_isp: LFUSE = C6
# 512 byte boot
pro16_isp: EFUSE = 04
pro16_isp: isp
# Diecimila, Duemilanove with m168, and NG use identical bootloaders
# Call it "atmega168" for generality and clarity, keep "diecimila" for
# backward compatibility of makefile
#
atmega168: TARGET = atmega168
atmega168: MCU_TARGET = atmega168
atmega168: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
atmega168: AVR_FREQ = 16000000L
atmega168: $(PROGRAM)_atmega168.hex
atmega168: $(PROGRAM)_atmega168.lst
atmega168_isp: atmega168
atmega168_isp: TARGET = atmega168
# 2.7V brownout
atmega168_isp: HFUSE = DD
# Low power xtal (16MHz) 16KCK/14CK+65ms
atmega168_isp: LFUSE = FF
# 512 byte boot
atmega168_isp: EFUSE = 04
atmega168_isp: isp
diecimila: TARGET = diecimila
diecimila: MCU_TARGET = atmega168
diecimila: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
diecimila: AVR_FREQ = 16000000L
diecimila: $(PROGRAM)_diecimila.hex
diecimila: $(PROGRAM)_diecimila.lst
diecimila_isp: diecimila
diecimila_isp: TARGET = diecimila
# 2.7V brownout
diecimila_isp: HFUSE = DD
# Low power xtal (16MHz) 16KCK/14CK+65ms
diecimila_isp: LFUSE = FF
# 512 byte boot
diecimila_isp: EFUSE = 04
diecimila_isp: isp
atmega328: TARGET = atmega328
atmega328: MCU_TARGET = atmega328p
atmega328: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
atmega328: AVR_FREQ = 16000000L
atmega328: LDSECTIONS = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
atmega328: $(PROGRAM)_atmega328.hex
atmega328: $(PROGRAM)_atmega328.lst
atmega328_isp: atmega328
atmega328_isp: TARGET = atmega328
atmega328_isp: MCU_TARGET = atmega328p
# 512 byte boot, SPIEN
atmega328_isp: HFUSE = DE
# Low power xtal (16MHz) 16KCK/14CK+65ms
atmega328_isp: LFUSE = FF
# 2.7V brownout
atmega328_isp: EFUSE = 05
atmega328_isp: isp
atmega1284: TARGET = atmega1284p
atmega1284: MCU_TARGET = atmega1284p
atmega1284: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' '-DBIGBOOT'
atmega1284: AVR_FREQ = 16000000L
atmega1284: LDSECTIONS = -Wl,--section-start=.text=0x1fc00
atmega1284: $(PROGRAM)_atmega1284p.hex
atmega1284: $(PROGRAM)_atmega1284p.lst
atmega1284_isp: atmega1284
atmega1284_isp: TARGET = atmega1284p
atmega1284_isp: MCU_TARGET = atmega1284p
# 1024 byte boot
atmega1284_isp: HFUSE = DE
# Low power xtal (16MHz) 16KCK/14CK+65ms
atmega1284_isp: LFUSE = FF
# 2.7V brownout
atmega1284_isp: EFUSE = FD
atmega1284_isp: isp
# Sanguino has a minimum boot size of 1024 bytes, so enable extra functions
#
sanguino: TARGET = atmega644p
sanguino: MCU_TARGET = atmega644p
sanguino: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' '-DBIGBOOT'
sanguino: AVR_FREQ = 16000000L
sanguino: LDSECTIONS = -Wl,--section-start=.text=0xfc00
sanguino: $(PROGRAM)_atmega644p.hex
sanguino: $(PROGRAM)_atmega644p.lst
sanguino_isp: sanguino
sanguino_isp: TARGET = atmega644p
sanguino_isp: MCU_TARGET = atmega644p
# 1024 byte boot
sanguino_isp: HFUSE = DE
# Low power xtal (16MHz) 16KCK/14CK+65ms
sanguino_isp: LFUSE = FF
# 2.7V brownout
sanguino_isp: EFUSE = 05
sanguino_isp: isp
# Mega has a minimum boot size of 1024 bytes, so enable extra functions
#mega: TARGET = atmega1280
mega: MCU_TARGET = atmega1280
mega: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200' '-DBIGBOOT'
mega: AVR_FREQ = 16000000L
mega: LDSECTIONS = -Wl,--section-start=.text=0x1fc00
mega: $(PROGRAM)_atmega1280.hex
mega: $(PROGRAM)_atmega1280.lst
mega_isp: mega
mega_isp: TARGET = atmega1280
mega_isp: MCU_TARGET = atmega1280
# 1024 byte boot
mega_isp: HFUSE = DE
# Low power xtal (16MHz) 16KCK/14CK+65ms
mega_isp: LFUSE = FF
# 2.7V brownout
mega_isp: EFUSE = 05
mega_isp: isp
# ATmega8
#
atmega8: TARGET = atmega8
atmega8: MCU_TARGET = atmega8
atmega8: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
atmega8: AVR_FREQ = 16000000L
atmega8: LDSECTIONS = -Wl,--section-start=.text=0x1e00 -Wl,--section-start=.version=0x1ffe
atmega8: $(PROGRAM)_atmega8.hex
atmega8: $(PROGRAM)_atmega8.lst
atmega8_isp: atmega8
atmega8_isp: TARGET = atmega8
atmega8_isp: MCU_TARGET = atmega8
# SPIEN, CKOPT, Bootsize=512B
atmega8_isp: HFUSE = CC
# 2.7V brownout, Low power xtal (16MHz) 16KCK/14CK+65ms
atmega8_isp: LFUSE = BF
atmega8_isp: isp
# ATmega88
#
atmega88: TARGET = atmega88
atmega88: MCU_TARGET = atmega88
atmega88: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
atmega88: AVR_FREQ = 16000000L
atmega88: LDSECTIONS = -Wl,--section-start=.text=0x1e00 -Wl,--section-start=.version=0x1ffe
atmega88: $(PROGRAM)_atmega88.hex
atmega88: $(PROGRAM)_atmega88.lst
atmega88_isp: atmega88
atmega88_isp: TARGET = atmega88
atmega88_isp: MCU_TARGET = atmega88
# 2.7V brownout
atmega88_isp: HFUSE = DD
# Low power xtal (16MHz) 16KCK/14CK+65ms
atemga88_isp: LFUSE = FF
# 512 byte boot
atmega88_isp: EFUSE = 04
atmega88_isp: isp
# 8MHz clocked platforms
#
# These are capable of 115200 baud
#
lilypad: TARGET = lilypad
lilypad: MCU_TARGET = atmega168
lilypad: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
lilypad: AVR_FREQ = 8000000L
lilypad: $(PROGRAM)_lilypad.hex
lilypad: $(PROGRAM)_lilypad.lst
lilypad_isp: lilypad
lilypad_isp: TARGET = lilypad
# 2.7V brownout
lilypad_isp: HFUSE = DD
# Internal 8MHz osc (8MHz) Slow rising power
lilypad_isp: LFUSE = E2
# 512 byte boot
lilypad_isp: EFUSE = 04
lilypad_isp: isp
lilypad_resonator: TARGET = lilypad_resonator
lilypad_resonator: MCU_TARGET = atmega168
lilypad_resonator: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
lilypad_resonator: AVR_FREQ = 8000000L
lilypad_resonator: $(PROGRAM)_lilypad_resonator.hex
lilypad_resonator: $(PROGRAM)_lilypad_resonator.lst
lilypad_resonator_isp: lilypad_resonator
lilypad_resonator_isp: TARGET = lilypad_resonator
# 2.7V brownout
lilypad_resonator_isp: HFUSE = DD
# Full swing xtal (20MHz) 258CK/14CK+4.1ms
lilypad_resonator_isp: LFUSE = C6
# 512 byte boot
lilypad_resonator_isp: EFUSE = 04
lilypad_resonator_isp: isp
pro8: TARGET = pro_8MHz
pro8: MCU_TARGET = atmega168
pro8: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
pro8: AVR_FREQ = 8000000L
pro8: $(PROGRAM)_pro_8MHz.hex
pro8: $(PROGRAM)_pro_8MHz.lst
pro8_isp: pro8
pro8_isp: TARGET = pro_8MHz
# 2.7V brownout
pro8_isp: HFUSE = DD
# Full swing xtal (20MHz) 258CK/14CK+4.1ms
pro8_isp: LFUSE = C6
# 512 byte boot
pro8_isp: EFUSE = 04
pro8_isp: isp
atmega328_pro8: TARGET = atmega328_pro_8MHz
atmega328_pro8: MCU_TARGET = atmega328p
atmega328_pro8: CFLAGS += '-DLED_START_FLASHES=3' '-DBAUD_RATE=115200'
atmega328_pro8: AVR_FREQ = 8000000L
atmega328_pro8: LDSECTIONS = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
atmega328_pro8: $(PROGRAM)_atmega328_pro_8MHz.hex
atmega328_pro8: $(PROGRAM)_atmega328_pro_8MHz.lst
atmega328_pro8_isp: atmega328_pro8
atmega328_pro8_isp: TARGET = atmega328_pro_8MHz
atmega328_pro8_isp: MCU_TARGET = atmega328p
# 512 byte boot, SPIEN
atmega328_pro8_isp: HFUSE = DE
# Low power xtal (16MHz) 16KCK/14CK+65ms
atmega328_pro8_isp: LFUSE = FF
# 2.7V brownout
atmega328_pro8_isp: EFUSE = 05
atmega328_pro8_isp: isp
# 1MHz clocked platforms
#
# These are capable of 9600 baud
#
luminet: TARGET = luminet
luminet: MCU_TARGET = attiny84
luminet: CFLAGS += '-DLED_START_FLASHES=3' '-DSOFT_UART' '-DBAUD_RATE=9600'
luminet: CFLAGS += '-DVIRTUAL_BOOT_PARTITION'
luminet: AVR_FREQ = 1000000L
luminet: LDSECTIONS = -Wl,--section-start=.text=0x1d00 -Wl,--section-start=.version=0x1efe
luminet: $(PROGRAM)_luminet.hex
luminet: $(PROGRAM)_luminet.lst
luminet_isp: luminet
luminet_isp: TARGET = luminet
luminet_isp: MCU_TARGET = attiny84
# Brownout disabled
luminet_isp: HFUSE = DF
# 1MHz internal oscillator, slowly rising power
luminet_isp: LFUSE = 62
# Self-programming enable
luminet_isp: EFUSE = FE
luminet_isp: isp
#
# Generic build instructions
#
#
isp: $(TARGET)
$(ISPFUSES)
$(ISPFLASH)
isp-stk500: $(PROGRAM)_$(TARGET).hex
$(STK500-1)
$(STK500-2)
%.elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
$(SIZE) $@
clean:
rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -j .version --set-section-flags .version=alloc,load -O ihex $< $@
%.srec: %.elf
$(OBJCOPY) -j .text -j .data -j .version --set-section-flags .version=alloc,load -O srec $< $@
%.bin: %.elf
$(OBJCOPY) -j .text -j .data -j .version --set-section-flags .version=alloc,load -O binary $< $@

View File

@ -0,0 +1,848 @@
/* Modified to use out for SPM access
** Peter Knight, Optiboot project http://optiboot.googlecode.com
**
** Todo: Tidy up
**
** "_short" routines execute 1 cycle faster and use 1 less word of flash
** by using "out" instruction instead of "sts".
**
** Additional elpm variants that trust the value of RAMPZ
*/
/* Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007 Eric B. Weddington
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* Neither the name of the copyright holders nor the names of
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. */
/* $Id: boot.h,v 1.27.2.3 2008/09/30 13:58:48 arcanum Exp $ */
#ifndef _AVR_BOOT_H_
#define _AVR_BOOT_H_ 1
/** \file */
/** \defgroup avr_boot <avr/boot.h>: Bootloader Support Utilities
\code
#include <avr/io.h>
#include <avr/boot.h>
\endcode
The macros in this module provide a C language interface to the
bootloader support functionality of certain AVR processors. These
macros are designed to work with all sizes of flash memory.
Global interrupts are not automatically disabled for these macros. It
is left up to the programmer to do this. See the code example below.
Also see the processor datasheet for caveats on having global interrupts
enabled during writing of the Flash.
\note Not all AVR processors provide bootloader support. See your
processor datasheet to see if it provides bootloader support.
\todo From email with Marek: On smaller devices (all except ATmega64/128),
__SPM_REG is in the I/O space, accessible with the shorter "in" and "out"
instructions - since the boot loader has a limited size, this could be an
important optimization.
\par API Usage Example
The following code shows typical usage of the boot API.
\code
#include <inttypes.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
void boot_program_page (uint32_t page, uint8_t *buf)
{
uint16_t i;
uint8_t sreg;
// Disable interrupts.
sreg = SREG;
cli();
eeprom_busy_wait ();
boot_page_erase (page);
boot_spm_busy_wait (); // Wait until the memory is erased.
for (i=0; i<SPM_PAGESIZE; i+=2)
{
// Set up little-endian word.
uint16_t w = *buf++;
w += (*buf++) << 8;
boot_page_fill (page + i, w);
}
boot_page_write (page); // Store buffer in flash page.
boot_spm_busy_wait(); // Wait until the memory is written.
// Reenable RWW-section again. We need this if we want to jump back
// to the application after bootloading.
boot_rww_enable ();
// Re-enable interrupts (if they were ever enabled).
SREG = sreg;
}\endcode */
#include <avr/eeprom.h>
#include <avr/io.h>
#include <inttypes.h>
#include <limits.h>
/* Check for SPM Control Register in processor. */
#if defined (SPMCSR)
# define __SPM_REG SPMCSR
#elif defined (SPMCR)
# define __SPM_REG SPMCR
#else
# error AVR processor does not provide bootloader support!
#endif
/* Check for SPM Enable bit. */
#if defined(SPMEN)
# define __SPM_ENABLE SPMEN
#elif defined(SELFPRGEN)
# define __SPM_ENABLE SELFPRGEN
#else
# error Cannot find SPM Enable bit definition!
#endif
/** \ingroup avr_boot
\def BOOTLOADER_SECTION
Used to declare a function or variable to be placed into a
new section called .bootloader. This section and its contents
can then be relocated to any address (such as the bootloader
NRWW area) at link-time. */
#define BOOTLOADER_SECTION __attribute__ ((section (".bootloader")))
/* Create common bit definitions. */
#ifdef ASB
#define __COMMON_ASB ASB
#else
#define __COMMON_ASB RWWSB
#endif
#ifdef ASRE
#define __COMMON_ASRE ASRE
#else
#define __COMMON_ASRE RWWSRE
#endif
/* Define the bit positions of the Boot Lock Bits. */
#define BLB12 5
#define BLB11 4
#define BLB02 3
#define BLB01 2
/** \ingroup avr_boot
\def boot_spm_interrupt_enable()
Enable the SPM interrupt. */
#define boot_spm_interrupt_enable() (__SPM_REG |= (uint8_t)_BV(SPMIE))
/** \ingroup avr_boot
\def boot_spm_interrupt_disable()
Disable the SPM interrupt. */
#define boot_spm_interrupt_disable() (__SPM_REG &= (uint8_t)~_BV(SPMIE))
/** \ingroup avr_boot
\def boot_is_spm_interrupt()
Check if the SPM interrupt is enabled. */
#define boot_is_spm_interrupt() (__SPM_REG & (uint8_t)_BV(SPMIE))
/** \ingroup avr_boot
\def boot_rww_busy()
Check if the RWW section is busy. */
#define boot_rww_busy() (__SPM_REG & (uint8_t)_BV(__COMMON_ASB))
/** \ingroup avr_boot
\def boot_spm_busy()
Check if the SPM instruction is busy. */
#define boot_spm_busy() (__SPM_REG & (uint8_t)_BV(__SPM_ENABLE))
/** \ingroup avr_boot
\def boot_spm_busy_wait()
Wait while the SPM instruction is busy. */
#define boot_spm_busy_wait() do{}while(boot_spm_busy())
#define __BOOT_PAGE_ERASE (_BV(__SPM_ENABLE) | _BV(PGERS))
#define __BOOT_PAGE_WRITE (_BV(__SPM_ENABLE) | _BV(PGWRT))
#define __BOOT_PAGE_FILL _BV(__SPM_ENABLE)
#define __BOOT_RWW_ENABLE (_BV(__SPM_ENABLE) | _BV(__COMMON_ASRE))
#define __BOOT_LOCK_BITS_SET (_BV(__SPM_ENABLE) | _BV(BLBSET))
#define __boot_page_fill_short(address, data) \
(__extension__({ \
__asm__ __volatile__ \
( \
"movw r0, %3\n\t" \
"out %0, %1\n\t" \
"spm\n\t" \
"clr r1\n\t" \
: \
: "i" (_SFR_IO_ADDR(__SPM_REG)), \
"r" ((uint8_t)__BOOT_PAGE_FILL), \
"z" ((uint16_t)address), \
"r" ((uint16_t)data) \
: "r0" \
); \
}))
#define __boot_page_fill_normal(address, data) \
(__extension__({ \
__asm__ __volatile__ \
( \
"movw r0, %3\n\t" \
"sts %0, %1\n\t" \
"spm\n\t" \
"clr r1\n\t" \
: \
: "i" (_SFR_MEM_ADDR(__SPM_REG)), \
"r" ((uint8_t)__BOOT_PAGE_FILL), \
"z" ((uint16_t)address), \
"r" ((uint16_t)data) \
: "r0" \
); \
}))
#define __boot_page_fill_alternate(address, data)\
(__extension__({ \
__asm__ __volatile__ \
( \
"movw r0, %3\n\t" \
"sts %0, %1\n\t" \
"spm\n\t" \
".word 0xffff\n\t" \
"nop\n\t" \
"clr r1\n\t" \
: \
: "i" (_SFR_MEM_ADDR(__SPM_REG)), \
"r" ((uint8_t)__BOOT_PAGE_FILL), \
"z" ((uint16_t)address), \
"r" ((uint16_t)data) \
: "r0" \
); \
}))
#define __boot_page_fill_extended(address, data) \
(__extension__({ \
__asm__ __volatile__ \
( \
"movw r0, %4\n\t" \
"movw r30, %A3\n\t" \
"sts %1, %C3\n\t" \
"sts %0, %2\n\t" \
"spm\n\t" \
"clr r1\n\t" \
: \
: "i" (_SFR_MEM_ADDR(__SPM_REG)), \
"i" (_SFR_MEM_ADDR(RAMPZ)), \
"r" ((uint8_t)__BOOT_PAGE_FILL), \
"r" ((uint32_t)address), \
"r" ((uint16_t)data) \
: "r0", "r30", "r31" \
); \
}))
#define __boot_page_fill_extended_short(address, data) \
(__extension__({ \
__asm__ __volatile__ \
( \
"movw r0, %4\n\t" \
"movw r30, %A3\n\t" \
"out %1, %C3\n\t" \
"out %0, %2\n\t" \
"spm\n\t" \
"clr r1\n\t" \
: \
: "i" (_SFR_IO_ADDR(__SPM_REG)), \
"i" (_SFR_IO_ADDR(RAMPZ)), \
"r" ((uint8_t)__BOOT_PAGE_FILL), \
"r" ((uint32_t)address), \
"r" ((uint16_t)data) \
: "r0", "r30", "r31" \
); \
}))
#define __boot_page_erase_short(address) \
(__extension__({ \
__asm__ __volatile__ \
( \
"out %0, %1\n\t" \
"spm\n\t" \
: \
: "i" (_SFR_IO_ADDR(__SPM_REG)), \
"r" ((uint8_t)__BOOT_PAGE_ERASE), \
"z" ((uint16_t)address) \
); \
}))
#define __boot_page_erase_normal(address) \
(__extension__({ \
__asm__ __volatile__ \
( \
"sts %0, %1\n\t" \
"spm\n\t" \
: \
: "i" (_SFR_MEM_ADDR(__SPM_REG)), \
"r" ((uint8_t)__BOOT_PAGE_ERASE), \
"z" ((uint16_t)address) \
); \
}))
#define __boot_page_erase_alternate(address) \
(__extension__({ \
__asm__ __volatile__ \
( \
"sts %0, %1\n\t" \
"spm\n\t" \
".word 0xffff\n\t" \
"nop\n\t" \
: \
: "i" (_SFR_MEM_ADDR(__SPM_REG)), \
"r" ((uint8_t)__BOOT_PAGE_ERASE), \
"z" ((uint16_t)address) \
); \
}))
#define __boot_page_erase_extended(address) \
(__extension__({ \
__asm__ __volatile__ \
( \
"movw r30, %A3\n\t" \
"sts %1, %C3\n\t" \
"sts %0, %2\n\t" \
"spm\n\t" \
: \
: "i" (_SFR_MEM_ADDR(__SPM_REG)), \
"i" (_SFR_MEM_ADDR(RAMPZ)), \
"r" ((uint8_t)__BOOT_PAGE_ERASE), \
"r" ((uint32_t)address) \
: "r30", "r31" \
); \
}))
#define __boot_page_erase_extended_short(address) \
(__extension__({ \
__asm__ __volatile__ \
( \
"movw r30, %A3\n\t" \
"out %1, %C3\n\t" \
"out %0, %2\n\t" \
"spm\n\t" \
: \
: "i" (_SFR_IO_ADDR(__SPM_REG)), \
"i" (_SFR_IO_ADDR(RAMPZ)), \
"r" ((uint8_t)__BOOT_PAGE_ERASE), \
"r" ((uint32_t)address) \
: "r30", "r31" \
); \
}))
#define __boot_page_write_short(address) \
(__extension__({ \
__asm__ __volatile__ \
( \
"out %0, %1\n\t" \
"spm\n\t" \
: \
: "i" (_SFR_IO_ADDR(__SPM_REG)), \
"r" ((uint8_t)__BOOT_PAGE_WRITE), \
"z" ((uint16_t)address) \
); \
}))
#define __boot_page_write_normal(address) \
(__extension__({ \
__asm__ __volatile__ \
( \
"sts %0, %1\n\t" \
"spm\n\t" \
: \
: "i" (_SFR_MEM_ADDR(__SPM_REG)), \
"r" ((uint8_t)__BOOT_PAGE_WRITE), \
"z" ((uint16_t)address) \
); \
}))
#define __boot_page_write_alternate(address) \
(__extension__({ \
__asm__ __volatile__ \
( \
"sts %0, %1\n\t" \
"spm\n\t" \
".word 0xffff\n\t" \
"nop\n\t" \
: \
: "i" (_SFR_MEM_ADDR(__SPM_REG)), \
"r" ((uint8_t)__BOOT_PAGE_WRITE), \
"z" ((uint16_t)address) \
); \
}))
#define __boot_page_write_extended(address) \
(__extension__({ \
__asm__ __volatile__ \
( \
"movw r30, %A3\n\t" \
"sts %1, %C3\n\t" \
"sts %0, %2\n\t" \
"spm\n\t" \
: \
: "i" (_SFR_MEM_ADDR(__SPM_REG)), \
"i" (_SFR_MEM_ADDR(RAMPZ)), \
"r" ((uint8_t)__BOOT_PAGE_WRITE), \
"r" ((uint32_t)address) \
: "r30", "r31" \
); \
}))
#define __boot_page_write_extended_short(address) \
(__extension__({ \
__asm__ __volatile__ \
( \
"movw r30, %A3\n\t" \
"out %1, %C3\n\t" \
"out %0, %2\n\t" \
"spm\n\t" \
: \
: "i" (_SFR_IO_ADDR(__SPM_REG)), \
"i" (_SFR_IO_ADDR(RAMPZ)), \
"r" ((uint8_t)__BOOT_PAGE_WRITE), \
"r" ((uint32_t)address) \
: "r30", "r31" \
); \
}))
#define __boot_rww_enable_short() \
(__extension__({ \
__asm__ __volatile__ \
( \
"out %0, %1\n\t" \
"spm\n\t" \
: \
: "i" (_SFR_IO_ADDR(__SPM_REG)), \
"r" ((uint8_t)__BOOT_RWW_ENABLE) \
); \
}))
#define __boot_rww_enable() \
(__extension__({ \
__asm__ __volatile__ \
( \
"sts %0, %1\n\t" \
"spm\n\t" \
: \
: "i" (_SFR_MEM_ADDR(__SPM_REG)), \
"r" ((uint8_t)__BOOT_RWW_ENABLE) \
); \
}))
#define __boot_rww_enable_alternate() \
(__extension__({ \
__asm__ __volatile__ \
( \
"sts %0, %1\n\t" \
"spm\n\t" \
".word 0xffff\n\t" \
"nop\n\t" \
: \
: "i" (_SFR_MEM_ADDR(__SPM_REG)), \
"r" ((uint8_t)__BOOT_RWW_ENABLE) \
); \
}))
/* From the mega16/mega128 data sheets (maybe others):
Bits by SPM To set the Boot Loader Lock bits, write the desired data to
R0, write "X0001001" to SPMCR and execute SPM within four clock cycles
after writing SPMCR. The only accessible Lock bits are the Boot Lock bits
that may prevent the Application and Boot Loader section from any
software update by the MCU.
If bits 5..2 in R0 are cleared (zero), the corresponding Boot Lock bit
will be programmed if an SPM instruction is executed within four cycles
after BLBSET and SPMEN (or SELFPRGEN) are set in SPMCR. The Z-pointer is
don't care during this operation, but for future compatibility it is
recommended to load the Z-pointer with $0001 (same as used for reading the
Lock bits). For future compatibility It is also recommended to set bits 7,
6, 1, and 0 in R0 to 1 when writing the Lock bits. When programming the
Lock bits the entire Flash can be read during the operation. */
#define __boot_lock_bits_set_short(lock_bits) \
(__extension__({ \
uint8_t value = (uint8_t)(~(lock_bits)); \
__asm__ __volatile__ \
( \
"ldi r30, 1\n\t" \
"ldi r31, 0\n\t" \
"mov r0, %2\n\t" \
"out %0, %1\n\t" \
"spm\n\t" \
: \
: "i" (_SFR_IO_ADDR(__SPM_REG)), \
"r" ((uint8_t)__BOOT_LOCK_BITS_SET), \
"r" (value) \
: "r0", "r30", "r31" \
); \
}))
#define __boot_lock_bits_set(lock_bits) \
(__extension__({ \
uint8_t value = (uint8_t)(~(lock_bits)); \
__asm__ __volatile__ \
( \
"ldi r30, 1\n\t" \
"ldi r31, 0\n\t" \
"mov r0, %2\n\t" \
"sts %0, %1\n\t" \
"spm\n\t" \
: \
: "i" (_SFR_MEM_ADDR(__SPM_REG)), \
"r" ((uint8_t)__BOOT_LOCK_BITS_SET), \
"r" (value) \
: "r0", "r30", "r31" \
); \
}))
#define __boot_lock_bits_set_alternate(lock_bits) \
(__extension__({ \
uint8_t value = (uint8_t)(~(lock_bits)); \
__asm__ __volatile__ \
( \
"ldi r30, 1\n\t" \
"ldi r31, 0\n\t" \
"mov r0, %2\n\t" \
"sts %0, %1\n\t" \
"spm\n\t" \
".word 0xffff\n\t" \
"nop\n\t" \
: \
: "i" (_SFR_MEM_ADDR(__SPM_REG)), \
"r" ((uint8_t)__BOOT_LOCK_BITS_SET), \
"r" (value) \
: "r0", "r30", "r31" \
); \
}))
/*
Reading lock and fuse bits:
Similarly to writing the lock bits above, set BLBSET and SPMEN (or
SELFPRGEN) bits in __SPMREG, and then (within four clock cycles) issue an
LPM instruction.
Z address: contents:
0x0000 low fuse bits
0x0001 lock bits
0x0002 extended fuse bits
0x0003 high fuse bits
Sounds confusing, doesn't it?
Unlike the macros in pgmspace.h, no need to care for non-enhanced
cores here as these old cores do not provide SPM support anyway.
*/
/** \ingroup avr_boot
\def GET_LOW_FUSE_BITS
address to read the low fuse bits, using boot_lock_fuse_bits_get
*/
#define GET_LOW_FUSE_BITS (0x0000)
/** \ingroup avr_boot
\def GET_LOCK_BITS
address to read the lock bits, using boot_lock_fuse_bits_get
*/
#define GET_LOCK_BITS (0x0001)
/** \ingroup avr_boot
\def GET_EXTENDED_FUSE_BITS
address to read the extended fuse bits, using boot_lock_fuse_bits_get
*/
#define GET_EXTENDED_FUSE_BITS (0x0002)
/** \ingroup avr_boot
\def GET_HIGH_FUSE_BITS
address to read the high fuse bits, using boot_lock_fuse_bits_get
*/
#define GET_HIGH_FUSE_BITS (0x0003)
/** \ingroup avr_boot
\def boot_lock_fuse_bits_get(address)
Read the lock or fuse bits at \c address.
Parameter \c address can be any of GET_LOW_FUSE_BITS,
GET_LOCK_BITS, GET_EXTENDED_FUSE_BITS, or GET_HIGH_FUSE_BITS.
\note The lock and fuse bits returned are the physical values,
i.e. a bit returned as 0 means the corresponding fuse or lock bit
is programmed.
*/
#define boot_lock_fuse_bits_get_short(address) \
(__extension__({ \
uint8_t __result; \
__asm__ __volatile__ \
( \
"ldi r30, %3\n\t" \
"ldi r31, 0\n\t" \
"out %1, %2\n\t" \
"lpm %0, Z\n\t" \
: "=r" (__result) \
: "i" (_SFR_IO_ADDR(__SPM_REG)), \
"r" ((uint8_t)__BOOT_LOCK_BITS_SET), \
"M" (address) \
: "r0", "r30", "r31" \
); \
__result; \
}))
#define boot_lock_fuse_bits_get(address) \
(__extension__({ \
uint8_t __result; \
__asm__ __volatile__ \
( \
"ldi r30, %3\n\t" \
"ldi r31, 0\n\t" \
"sts %1, %2\n\t" \
"lpm %0, Z\n\t" \
: "=r" (__result) \
: "i" (_SFR_MEM_ADDR(__SPM_REG)), \
"r" ((uint8_t)__BOOT_LOCK_BITS_SET), \
"M" (address) \
: "r0", "r30", "r31" \
); \
__result; \
}))
/** \ingroup avr_boot
\def boot_signature_byte_get(address)
Read the Signature Row byte at \c address. For some MCU types,
this function can also retrieve the factory-stored oscillator
calibration bytes.
Parameter \c address can be 0-0x1f as documented by the datasheet.
\note The values are MCU type dependent.
*/
#define __BOOT_SIGROW_READ (_BV(__SPM_ENABLE) | _BV(SIGRD))
#define boot_signature_byte_get_short(addr) \
(__extension__({ \
uint16_t __addr16 = (uint16_t)(addr); \
uint8_t __result; \
__asm__ __volatile__ \
( \
"out %1, %2\n\t" \
"lpm %0, Z" "\n\t" \
: "=r" (__result) \
: "i" (_SFR_IO_ADDR(__SPM_REG)), \
"r" ((uint8_t) __BOOT_SIGROW_READ), \
"z" (__addr16) \
); \
__result; \
}))
#define boot_signature_byte_get(addr) \
(__extension__({ \
uint16_t __addr16 = (uint16_t)(addr); \
uint8_t __result; \
__asm__ __volatile__ \
( \
"sts %1, %2\n\t" \
"lpm %0, Z" "\n\t" \
: "=r" (__result) \
: "i" (_SFR_MEM_ADDR(__SPM_REG)), \
"r" ((uint8_t) __BOOT_SIGROW_READ), \
"z" (__addr16) \
); \
__result; \
}))
/** \ingroup avr_boot
\def boot_page_fill(address, data)
Fill the bootloader temporary page buffer for flash
address with data word.
\note The address is a byte address. The data is a word. The AVR
writes data to the buffer a word at a time, but addresses the buffer
per byte! So, increment your address by 2 between calls, and send 2
data bytes in a word format! The LSB of the data is written to the lower
address; the MSB of the data is written to the higher address.*/
/** \ingroup avr_boot
\def boot_page_erase(address)
Erase the flash page that contains address.
\note address is a byte address in flash, not a word address. */
/** \ingroup avr_boot
\def boot_page_write(address)
Write the bootloader temporary page buffer
to flash page that contains address.
\note address is a byte address in flash, not a word address. */
/** \ingroup avr_boot
\def boot_rww_enable()
Enable the Read-While-Write memory section. */
/** \ingroup avr_boot
\def boot_lock_bits_set(lock_bits)
Set the bootloader lock bits.
\param lock_bits A mask of which Boot Loader Lock Bits to set.
\note In this context, a 'set bit' will be written to a zero value.
Note also that only BLBxx bits can be programmed by this command.
For example, to disallow the SPM instruction from writing to the Boot
Loader memory section of flash, you would use this macro as such:
\code
boot_lock_bits_set (_BV (BLB11));
\endcode
\note Like any lock bits, the Boot Loader Lock Bits, once set,
cannot be cleared again except by a chip erase which will in turn
also erase the boot loader itself. */
/* Normal versions of the macros use 16-bit addresses.
Extended versions of the macros use 32-bit addresses.
Alternate versions of the macros use 16-bit addresses and require special
instruction sequences after LPM.
FLASHEND is defined in the ioXXXX.h file.
USHRT_MAX is defined in <limits.h>. */
#if defined(__AVR_ATmega161__) || defined(__AVR_ATmega163__) \
|| defined(__AVR_ATmega323__)
/* Alternate: ATmega161/163/323 and 16 bit address */
#define boot_page_fill(address, data) __boot_page_fill_alternate(address, data)
#define boot_page_erase(address) __boot_page_erase_alternate(address)
#define boot_page_write(address) __boot_page_write_alternate(address)
#define boot_rww_enable() __boot_rww_enable_alternate()
#define boot_lock_bits_set(lock_bits) __boot_lock_bits_set_alternate(lock_bits)
#elif (FLASHEND > USHRT_MAX)
/* Extended: >16 bit address */
#define boot_page_fill(address, data) __boot_page_fill_extended_short(address, data)
#define boot_page_erase(address) __boot_page_erase_extended_short(address)
#define boot_page_write(address) __boot_page_write_extended_short(address)
#define boot_rww_enable() __boot_rww_enable_short()
#define boot_lock_bits_set(lock_bits) __boot_lock_bits_set_short(lock_bits)
#else
/* Normal: 16 bit address */
#define boot_page_fill(address, data) __boot_page_fill_short(address, data)
#define boot_page_erase(address) __boot_page_erase_short(address)
#define boot_page_write(address) __boot_page_write_short(address)
#define boot_rww_enable() __boot_rww_enable_short()
#define boot_lock_bits_set(lock_bits) __boot_lock_bits_set_short(lock_bits)
#endif
/** \ingroup avr_boot
Same as boot_page_fill() except it waits for eeprom and spm operations to
complete before filling the page. */
#define boot_page_fill_safe(address, data) \
do { \
boot_spm_busy_wait(); \
eeprom_busy_wait(); \
boot_page_fill(address, data); \
} while (0)
/** \ingroup avr_boot
Same as boot_page_erase() except it waits for eeprom and spm operations to
complete before erasing the page. */
#define boot_page_erase_safe(address) \
do { \
boot_spm_busy_wait(); \
eeprom_busy_wait(); \
boot_page_erase (address); \
} while (0)
/** \ingroup avr_boot
Same as boot_page_write() except it waits for eeprom and spm operations to
complete before writing the page. */
#define boot_page_write_safe(address) \
do { \
boot_spm_busy_wait(); \
eeprom_busy_wait(); \
boot_page_write (address); \
} while (0)
/** \ingroup avr_boot
Same as boot_rww_enable() except waits for eeprom and spm operations to
complete before enabling the RWW mameory. */
#define boot_rww_enable_safe() \
do { \
boot_spm_busy_wait(); \
eeprom_busy_wait(); \
boot_rww_enable(); \
} while (0)
/** \ingroup avr_boot
Same as boot_lock_bits_set() except waits for eeprom and spm operations to
complete before setting the lock bits. */
#define boot_lock_bits_set_safe(lock_bits) \
do { \
boot_spm_busy_wait(); \
eeprom_busy_wait(); \
boot_lock_bits_set (lock_bits); \
} while (0)
#endif /* _AVR_BOOT_H_ */

View File

@ -0,0 +1,724 @@
/**********************************************************/
/* -Wl,-section-start=bootloader=0x1fc00 */
/* Optiboot bootloader for Arduino */
/* */
/* http://optiboot.googlecode.com */
/* */
/* Arduino-maintained version : See README.TXT */
/* http://code.google.com/p/arduino/ */
/* */
/* Heavily optimised bootloader that is faster and */
/* smaller than the Arduino standard bootloader */
/* */
/* Enhancements: */
/* Fits in 512 bytes, saving 1.5K of code space */
/* Background page erasing speeds up programming */
/* Higher baud rate speeds up programming */
/* Written almost entirely in C */
/* Customisable timeout with accurate timeconstant */
/* Optional virtual UART. No hardware UART required. */
/* Optional virtual boot partition for devices without. */
/* */
/* What you lose: */
/* Implements a skeleton STK500 protocol which is */
/* missing several features including EEPROM */
/* programming and non-page-aligned writes */
/* High baud rate breaks compatibility with standard */
/* Arduino flash settings */
/* */
/* Fully supported: */
/* ATmega168 based devices (Diecimila etc) */
/* ATmega328P based devices (Duemilanove etc) */
/* */
/* Alpha test */
/* ATmega1280 based devices (Arduino Mega) */
/* */
/* Work in progress: */
/* ATmega644P based devices (Sanguino) */
/* ATtiny84 based devices (Luminet) */
/* */
/* Does not support: */
/* USB based devices (eg. Teensy) */
/* */
/* Assumptions: */
/* The code makes several assumptions that reduce the */
/* code size. They are all true after a hardware reset, */
/* but may not be true if the bootloader is called by */
/* other means or on other hardware. */
/* No interrupts can occur */
/* UART and Timer 1 are set to their reset state */
/* SP points to RAMEND */
/* */
/* Code builds on code, libraries and optimisations from: */
/* stk500boot.c by Jason P. Kyle */
/* Arduino bootloader http://arduino.cc */
/* Spiff's 1K bootloader http://spiffie.org/know/arduino_1k_bootloader/bootloader.shtml */
/* avr-libc project http://nongnu.org/avr-libc */
/* Adaboot http://www.ladyada.net/library/arduino/bootloader.html */
/* AVR305 Atmel Application Note */
/* */
/* 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 the Free Software */
/* Foundation; either version 2 of the License, or */
/* (at your option) any later version. */
/* */
/* This program 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 General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU General */
/* Public License along with this program; if not, write */
/* to the Free Software Foundation, Inc., */
/* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* */
/* Licence can be viewed at */
/* http://www.fsf.org/licenses/gpl.txt */
/* */
/**********************************************************/
/**********************************************************/
/* */
/* Optional defines: */
/* */
/**********************************************************/
/* */
/* BIG_BOOT: */
/* Build a 1k bootloader, not 512 bytes. This turns on */
/* extra functionality. */
/* */
/* BAUD_RATE: */
/* Set bootloader baud rate. */
/* */
/* LUDICROUS_SPEED: */
/* 230400 baud :-) */
/* */
/* SOFT_UART: */
/* Use AVR305 soft-UART instead of hardware UART. */
/* */
/* LED_START_FLASHES: */
/* Number of LED flashes on bootup. */
/* */
/* LED_DATA_FLASH: */
/* Flash LED when transferring data. For boards without */
/* TX or RX LEDs, or for people who like blinky lights. */
/* */
/* SUPPORT_EEPROM: */
/* Support reading and writing from EEPROM. This is not */
/* used by Arduino, so off by default. */
/* */
/* TIMEOUT_MS: */
/* Bootloader timeout period, in milliseconds. */
/* 500,1000,2000,4000,8000 supported. */
/* */
/**********************************************************/
/**********************************************************/
/* Version Numbers! */
/* */
/* Arduino Optiboot now includes this Version number in */
/* the source and object code. */
/* */
/* Version 3 was released as zip from the optiboot */
/* repository and was distributed with Arduino 0022. */
/* Version 4 starts with the arduino repository commit */
/* that brought the arduino repository up-to-date with */
/* the optiboot source tree changes since v3. */
/* */
/**********************************************************/
/**********************************************************/
/* Edit History: */
/* */
/* Jan 2012: */
/* 4.5 WestfW: fix NRWW value for m1284. */
/* 4.4 WestfW: use attribute OS_main instead of naked for */
/* main(). This allows optimizations that we */
/* count on, which are prohibited in naked */
/* functions due to PR42240. (keeps us less */
/* than 512 bytes when compiler is gcc4.5 */
/* (code from 4.3.2 remains the same.) */
/* 4.4 WestfW and Maniacbug: Add m1284 support. This */
/* does not change the 328 binary, so the */
/* version number didn't change either. (?) */
/* June 2011: */
/* 4.4 WestfW: remove automatic soft_uart detect (didn't */
/* know what it was doing or why.) Added a */
/* check of the calculated BRG value instead. */
/* Version stays 4.4; existing binaries are */
/* not changed. */
/* 4.4 WestfW: add initialization of address to keep */
/* the compiler happy. Change SC'ed targets. */
/* Return the SW version via READ PARAM */
/* 4.3 WestfW: catch framing errors in getch(), so that */
/* AVRISP works without HW kludges. */
/* http://code.google.com/p/arduino/issues/detail?id=368n*/
/* 4.2 WestfW: reduce code size, fix timeouts, change */
/* verifySpace to use WDT instead of appstart */
/* 4.1 WestfW: put version number in binary. */
/**********************************************************/
#define OPTIBOOT_MAJVER 4
#define OPTIBOOT_MINVER 5
#define MAKESTR(a) #a
#define MAKEVER(a, b) MAKESTR(a*256+b)
asm(" .section .version\n"
"optiboot_version: .word " MAKEVER(OPTIBOOT_MAJVER, OPTIBOOT_MINVER) "\n"
" .section .text\n");
#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
// <avr/boot.h> uses sts instructions, but this version uses out instructions
// This saves cycles and program memory.
#include "boot.h"
// We don't use <avr/wdt.h> as those routines have interrupt overhead we don't need.
#include "pin_defs.h"
#include "stk500.h"
#ifndef LED_START_FLASHES
#define LED_START_FLASHES 0
#endif
#ifdef LUDICROUS_SPEED
#define BAUD_RATE 230400L
#endif
/* set the UART baud rate defaults */
#ifndef BAUD_RATE
#if F_CPU >= 8000000L
#define BAUD_RATE 115200L // Highest rate Avrdude win32 will support
#elsif F_CPU >= 1000000L
#define BAUD_RATE 9600L // 19200 also supported, but with significant error
#elsif F_CPU >= 128000L
#define BAUD_RATE 4800L // Good for 128kHz internal RC
#else
#define BAUD_RATE 1200L // Good even at 32768Hz
#endif
#endif
#if 0
/* Switch in soft UART for hard baud rates */
/*
* I don't understand what this was supposed to accomplish, where the
* constant "280" came from, or why automatically (and perhaps unexpectedly)
* switching to a soft uart is a good thing, so I'm undoing this in favor
* of a range check using the same calc used to config the BRG...
*/
#if (F_CPU/BAUD_RATE) > 280 // > 57600 for 16MHz
#ifndef SOFT_UART
#define SOFT_UART
#endif
#endif
#else // 0
#if (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 > 250
#error Unachievable baud rate (too slow) BAUD_RATE
#endif // baud rate slow check
#if (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 < 3
#error Unachievable baud rate (too fast) BAUD_RATE
#endif // baud rate fastn check
#endif
/* Watchdog settings */
#define WATCHDOG_OFF (0)
#define WATCHDOG_16MS (_BV(WDE))
#define WATCHDOG_32MS (_BV(WDP0) | _BV(WDE))
#define WATCHDOG_64MS (_BV(WDP1) | _BV(WDE))
#define WATCHDOG_125MS (_BV(WDP1) | _BV(WDP0) | _BV(WDE))
#define WATCHDOG_250MS (_BV(WDP2) | _BV(WDE))
#define WATCHDOG_500MS (_BV(WDP2) | _BV(WDP0) | _BV(WDE))
#define WATCHDOG_1S (_BV(WDP2) | _BV(WDP1) | _BV(WDE))
#define WATCHDOG_2S (_BV(WDP2) | _BV(WDP1) | _BV(WDP0) | _BV(WDE))
#ifndef __AVR_ATmega8__
#define WATCHDOG_4S (_BV(WDP3) | _BV(WDE))
#define WATCHDOG_8S (_BV(WDP3) | _BV(WDP0) | _BV(WDE))
#endif
/* Function Prototypes */
/* The main function is in init9, which removes the interrupt vector table */
/* we don't need. It is also 'naked', which means the compiler does not */
/* generate any entry or exit code itself. */
int main(void) __attribute__ ((OS_main)) __attribute__ ((section (".init9")));
void putch(char);
uint8_t getch(void);
static inline void getNch(uint8_t); /* "static inline" is a compiler hint to reduce code size */
void verifySpace();
static inline void flash_led(uint8_t);
uint8_t getLen();
static inline void watchdogReset();
void watchdogConfig(uint8_t x);
#ifdef SOFT_UART
void uartDelay() __attribute__ ((naked));
#endif
void appStart() __attribute__ ((naked));
/*
* NRWW memory
* Addresses below NRWW (Non-Read-While-Write) can be programmed while
* continuing to run code from flash, slightly speeding up programming
* time. Beware that Atmel data sheets specify this as a WORD address,
* while optiboot will be comparing against a 16-bit byte address. This
* means that on a part with 128kB of memory, the upper part of the lower
* 64k will get NRWW processing as well, even though it doesn't need it.
* That's OK. In fact, you can disable the overlapping processing for
* a part entirely by setting NRWWSTART to zero. This reduces code
* space a bit, at the expense of being slightly slower, overall.
*
* RAMSTART should be self-explanatory. It's bigger on parts with a
* lot of peripheral registers.
*/
#if defined(__AVR_ATmega168__)
#define RAMSTART (0x100)
#define NRWWSTART (0x3800)
#elif defined(__AVR_ATmega328P__)
#define RAMSTART (0x100)
#define NRWWSTART (0x7000)
#elif defined (__AVR_ATmega644P__)
#define RAMSTART (0x100)
#define NRWWSTART (0xE000)
#elif defined (__AVR_ATmega1284P__)
#define RAMSTART (0x100)
#define NRWWSTART (0xE000)
#elif defined(__AVR_ATtiny84__)
#define RAMSTART (0x100)
#define NRWWSTART (0x0000)
#elif defined(__AVR_ATmega1280__)
#define RAMSTART (0x200)
#define NRWWSTART (0xE000)
#elif defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)
#define RAMSTART (0x100)
#define NRWWSTART (0x1800)
#endif
/* C zero initialises all global variables. However, that requires */
/* These definitions are NOT zero initialised, but that doesn't matter */
/* This allows us to drop the zero init code, saving us memory */
#define buff ((uint8_t*)(RAMSTART))
#ifdef VIRTUAL_BOOT_PARTITION
#define rstVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+4))
#define wdtVect (*(uint16_t*)(RAMSTART+SPM_PAGESIZE*2+6))
#endif
/* main program starts here */
int main(void) {
uint8_t ch;
/*
* Making these local and in registers prevents the need for initializing
* them, and also saves space because code no longer stores to memory.
* (initializing address keeps the compiler happy, but isn't really
* necessary, and uses 4 bytes of flash.)
*/
register uint16_t address = 0;
register uint8_t length;
// After the zero init loop, this is the first code to run.
//
// This code makes the following assumptions:
// No interrupts will execute
// SP points to RAMEND
// r1 contains zero
//
// If not, uncomment the following instructions:
// cli();
asm volatile ("clr __zero_reg__");
#ifdef __AVR_ATmega8__
SP=RAMEND; // This is done by hardware reset
#endif
// Adaboot no-wait mod
ch = MCUSR;
MCUSR = 0;
if (!(ch & _BV(EXTRF))) appStart();
#if LED_START_FLASHES > 0
// Set up Timer 1 for timeout counter
TCCR1B = _BV(CS12) | _BV(CS10); // div 1024
#endif
#ifndef SOFT_UART
#ifdef __AVR_ATmega8__
UCSRA = _BV(U2X); //Double speed mode USART
UCSRB = _BV(RXEN) | _BV(TXEN); // enable Rx & Tx
UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0); // config USART; 8N1
UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
#else
UCSR0A = _BV(U2X0); //Double speed mode USART0
UCSR0B = _BV(RXEN0) | _BV(TXEN0);
UCSR0C = _BV(UCSZ00) | _BV(UCSZ01);
UBRR0L = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
#endif
#endif
// Set up watchdog to trigger after 500ms
watchdogConfig(WATCHDOG_1S);
/* Set LED pin as output */
LED_DDR |= _BV(LED);
#ifdef SOFT_UART
/* Set TX pin as output */
UART_DDR |= _BV(UART_TX_BIT);
#endif
#if LED_START_FLASHES > 0
/* Flash onboard LED to signal entering of bootloader */
flash_led(LED_START_FLASHES * 2);
#endif
/* Forever loop */
for (;;) {
/* get character from UART */
ch = getch();
if(ch == STK_GET_PARAMETER) {
unsigned char which = getch();
verifySpace();
if (which == 0x82) {
/*
* Send optiboot version as "minor SW version"
*/
putch(OPTIBOOT_MINVER);
} else if (which == 0x81) {
putch(OPTIBOOT_MAJVER);
} else {
/*
* GET PARAMETER returns a generic 0x03 reply for
* other parameters - enough to keep Avrdude happy
*/
putch(0x03);
}
}
else if(ch == STK_SET_DEVICE) {
// SET DEVICE is ignored
getNch(20);
}
else if(ch == STK_SET_DEVICE_EXT) {
// SET DEVICE EXT is ignored
getNch(5);
}
else if(ch == STK_LOAD_ADDRESS) {
// LOAD ADDRESS
uint16_t newAddress;
newAddress = getch();
newAddress = (newAddress & 0xff) | (getch() << 8);
#ifdef RAMPZ
// Transfer top bit to RAMPZ
RAMPZ = (newAddress & 0x8000) ? 1 : 0;
#endif
newAddress += newAddress; // Convert from word address to byte address
address = newAddress;
verifySpace();
}
else if(ch == STK_UNIVERSAL) {
// UNIVERSAL command is ignored
getNch(4);
putch(0x00);
}
/* Write memory, length is big endian and is in bytes */
else if(ch == STK_PROG_PAGE) {
// PROGRAM PAGE - we support flash programming only, not EEPROM
uint8_t *bufPtr;
uint16_t addrPtr;
getch(); /* getlen() */
length = getch();
getch();
// If we are in RWW section, immediately start page erase
if (address < NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);
// While that is going on, read in page contents
bufPtr = buff;
do *bufPtr++ = getch();
while (--length);
// If we are in NRWW section, page erase has to be delayed until now.
// Todo: Take RAMPZ into account
if (address >= NRWWSTART) __boot_page_erase_short((uint16_t)(void*)address);
// Read command terminator, start reply
verifySpace();
// If only a partial page is to be programmed, the erase might not be complete.
// So check that here
boot_spm_busy_wait();
#ifdef VIRTUAL_BOOT_PARTITION
if ((uint16_t)(void*)address == 0) {
// This is the reset vector page. We need to live-patch the code so the
// bootloader runs.
//
// Move RESET vector to WDT vector
uint16_t vect = buff[0] | (buff[1]<<8);
rstVect = vect;
wdtVect = buff[8] | (buff[9]<<8);
vect -= 4; // Instruction is a relative jump (rjmp), so recalculate.
buff[8] = vect & 0xff;
buff[9] = vect >> 8;
// Add jump to bootloader at RESET vector
buff[0] = 0x7f;
buff[1] = 0xce; // rjmp 0x1d00 instruction
}
#endif
// Copy buffer into programming buffer
bufPtr = buff;
addrPtr = (uint16_t)(void*)address;
ch = SPM_PAGESIZE / 2;
do {
uint16_t a;
a = *bufPtr++;
a |= (*bufPtr++) << 8;
__boot_page_fill_short((uint16_t)(void*)addrPtr,a);
addrPtr += 2;
} while (--ch);
// Write from programming buffer
__boot_page_write_short((uint16_t)(void*)address);
boot_spm_busy_wait();
#if defined(RWWSRE)
// Reenable read access to flash
boot_rww_enable();
#endif
}
/* Read memory block mode, length is big endian. */
else if(ch == STK_READ_PAGE) {
// READ PAGE - we only read flash
getch(); /* getlen() */
length = getch();
getch();
verifySpace();
#ifdef VIRTUAL_BOOT_PARTITION
do {
// Undo vector patch in bottom page so verify passes
if (address == 0) ch=rstVect & 0xff;
else if (address == 1) ch=rstVect >> 8;
else if (address == 8) ch=wdtVect & 0xff;
else if (address == 9) ch=wdtVect >> 8;
else ch = pgm_read_byte_near(address);
address++;
putch(ch);
} while (--length);
#else
#ifdef RAMPZ
// Since RAMPZ should already be set, we need to use EPLM directly.
// do putch(pgm_read_byte_near(address++));
// while (--length);
do {
uint8_t result;
__asm__ ("elpm %0,Z\n":"=r"(result):"z"(address));
putch(result);
address++;
}
while (--length);
#else
do putch(pgm_read_byte_near(address++));
while (--length);
#endif
#endif
}
/* Get device signature bytes */
else if(ch == STK_READ_SIGN) {
// READ SIGN - return what Avrdude wants to hear
verifySpace();
putch(SIGNATURE_0);
putch(SIGNATURE_1);
putch(SIGNATURE_2);
}
else if (ch == STK_LEAVE_PROGMODE) { /* 'Q' */
// Adaboot no-wait mod
watchdogConfig(WATCHDOG_16MS);
verifySpace();
}
else {
// This covers the response to commands like STK_ENTER_PROGMODE
verifySpace();
}
putch(STK_OK);
}
}
void putch(char ch) {
#ifndef SOFT_UART
while (!(UCSR0A & _BV(UDRE0)));
UDR0 = ch;
#else
__asm__ __volatile__ (
" com %[ch]\n" // ones complement, carry set
" sec\n"
"1: brcc 2f\n"
" cbi %[uartPort],%[uartBit]\n"
" rjmp 3f\n"
"2: sbi %[uartPort],%[uartBit]\n"
" nop\n"
"3: rcall uartDelay\n"
" rcall uartDelay\n"
" lsr %[ch]\n"
" dec %[bitcnt]\n"
" brne 1b\n"
:
:
[bitcnt] "d" (10),
[ch] "r" (ch),
[uartPort] "I" (_SFR_IO_ADDR(UART_PORT)),
[uartBit] "I" (UART_TX_BIT)
:
"r25"
);
#endif
}
uint8_t getch(void) {
uint8_t ch;
#ifdef LED_DATA_FLASH
#ifdef __AVR_ATmega8__
LED_PORT ^= _BV(LED);
#else
LED_PIN |= _BV(LED);
#endif
#endif
#ifdef SOFT_UART
__asm__ __volatile__ (
"1: sbic %[uartPin],%[uartBit]\n" // Wait for start edge
" rjmp 1b\n"
" rcall uartDelay\n" // Get to middle of start bit
"2: rcall uartDelay\n" // Wait 1 bit period
" rcall uartDelay\n" // Wait 1 bit period
" clc\n"
" sbic %[uartPin],%[uartBit]\n"
" sec\n"
" dec %[bitCnt]\n"
" breq 3f\n"
" ror %[ch]\n"
" rjmp 2b\n"
"3:\n"
:
[ch] "=r" (ch)
:
[bitCnt] "d" (9),
[uartPin] "I" (_SFR_IO_ADDR(UART_PIN)),
[uartBit] "I" (UART_RX_BIT)
:
"r25"
);
#else
while(!(UCSR0A & _BV(RXC0)))
;
if (!(UCSR0A & _BV(FE0))) {
/*
* A Framing Error indicates (probably) that something is talking
* to us at the wrong bit rate. Assume that this is because it
* expects to be talking to the application, and DON'T reset the
* watchdog. This should cause the bootloader to abort and run
* the application "soon", if it keeps happening. (Note that we
* don't care that an invalid char is returned...)
*/
watchdogReset();
}
ch = UDR0;
#endif
#ifdef LED_DATA_FLASH
#ifdef __AVR_ATmega8__
LED_PORT ^= _BV(LED);
#else
LED_PIN |= _BV(LED);
#endif
#endif
return ch;
}
#ifdef SOFT_UART
// AVR305 equation: #define UART_B_VALUE (((F_CPU/BAUD_RATE)-23)/6)
// Adding 3 to numerator simulates nearest rounding for more accurate baud rates
#define UART_B_VALUE (((F_CPU/BAUD_RATE)-20)/6)
#if UART_B_VALUE > 255
#error Baud rate too slow for soft UART
#endif
void uartDelay() {
__asm__ __volatile__ (
"ldi r25,%[count]\n"
"1:dec r25\n"
"brne 1b\n"
"ret\n"
::[count] "M" (UART_B_VALUE)
);
}
#endif
void getNch(uint8_t count) {
do getch(); while (--count);
verifySpace();
}
void verifySpace() {
if (getch() != CRC_EOP) {
watchdogConfig(WATCHDOG_16MS); // shorten WD timeout
while (1) // and busy-loop so that WD causes
; // a reset and app start.
}
putch(STK_INSYNC);
}
#if LED_START_FLASHES > 0
void flash_led(uint8_t count) {
do {
TCNT1 = -(F_CPU/(1024*16));
TIFR1 = _BV(TOV1);
while(!(TIFR1 & _BV(TOV1)));
#ifdef __AVR_ATmega8__
LED_PORT ^= _BV(LED);
#else
LED_PIN |= _BV(LED);
#endif
watchdogReset();
} while (--count);
}
#endif
// Watchdog functions. These are only safe with interrupts turned off.
void watchdogReset() {
__asm__ __volatile__ (
"wdr\n"
);
}
void watchdogConfig(uint8_t x) {
WDTCSR = _BV(WDCE) | _BV(WDE);
WDTCSR = x;
}
void appStart() {
watchdogConfig(WATCHDOG_OFF);
__asm__ __volatile__ (
#ifdef VIRTUAL_BOOT_PARTITION
// Jump to WDT vector
"ldi r30,4\n"
"clr r31\n"
#else
// Jump to RST vector
"clr r30\n"
"clr r31\n"
#endif
"ijmp\n"
);
}

View File

@ -0,0 +1,33 @@
:020000021000EC
:10FE00000F92CDB7DEB7112484B714BE81FFDFD0C7
:10FE100082E08093C00088E18093C10086E08093F7
:10FE2000C2008AE28093C4008EE0BBD0209A00E03A
:10FE300010E0EE24E394E1E1DE2EF3E0FF2EA5D006
:10FE4000813471F4A2D08983B2D08981823809F4D7
:10FE50008BC0813811F484E001C083E08FD08BC067
:10FE6000823411F484E103C0853419F485E0A7D00D
:10FE700082C0853591F489D0A82EBB2486D0082F66
:10FE800010E0102F00270A291B29812F881F88279F
:10FE9000881F8BBF000F111F6DC0863521F484E0D1
:10FEA0008ED080E0DBCF843609F040C06ED06DD0BC
:10FEB000C82E6BD080EE0030180718F4F801F7BE9A
:10FEC000E895A12C51E0B52E60D0F50181935F013A
:10FED000CE16D1F7F0EE00301F0718F0F801F7BE8C
:10FEE000E89565D007B600FCFDCFF801A0E0B1E0D1
:10FEF0002C9130E011968C91119790E0982F8827E3
:10FF0000822B932B12960C01E7BEE89511243296B2
:10FF100082E0A030B80761F785E0F80187BFE89577
:10FF200007B600FCFDCFD7BEE89525C08437A9F4FD
:10FF30002CD02BD0B82E29D03AD0CB2C4801F401AC
:10FF400086911CD00894811C911CCA94C1F70F5F44
:10FF50001F4FBA940B0D111D0EC0853739F427D0F1
:10FF60008EE10CD087E90AD085E078CF813511F495
:10FF700088E017D01CD080E101D061CF9091C00003
:10FF800095FFFCCF8093C60008958091C00087FF45
:10FF9000FCCF8091C00084FD01C0A8958091C6006F
:10FFA0000895E0E6F0E098E1908380830895EDDF26
:10FFB000803219F088E0F5DFFFCF84E1DFCFCF9307
:10FFC000C82FE3DFC150E9F7F2DFCF91089580E059
:08FFD000E8DFEE27FF2709948A
:040000031000FE00EB
:00000001FF

View File

@ -0,0 +1,81 @@
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) || defined(__AVR_ATmega88) || defined(__AVR_ATmega8__) || defined(__AVR_ATmega88__)
/* Onboard LED is connected to pin PB5 in Arduino NG, Diecimila, and Duemilanove */
#define LED_DDR DDRB
#define LED_PORT PORTB
#define LED_PIN PINB
#define LED PINB5
/* Ports for soft UART */
#ifdef SOFT_UART
#define UART_PORT PORTD
#define UART_PIN PIND
#define UART_DDR DDRD
#define UART_TX_BIT 1
#define UART_RX_BIT 0
#endif
#endif
#if defined(__AVR_ATmega8__)
//Name conversion R.Wiersma
#define UCSR0A UCSRA
#define UDR0 UDR
#define UDRE0 UDRE
#define RXC0 RXC
#define FE0 FE
#define TIFR1 TIFR
#define WDTCSR WDTCR
#endif
/* Luminet support */
#if defined(__AVR_ATtiny84__)
/* Red LED is connected to pin PA4 */
#define LED_DDR DDRA
#define LED_PORT PORTA
#define LED_PIN PINA
#define LED PINA4
/* Ports for soft UART - left port only for now. TX/RX on PA2/PA3 */
#ifdef SOFT_UART
#define UART_PORT PORTA
#define UART_PIN PINA
#define UART_DDR DDRA
#define UART_TX_BIT 2
#define UART_RX_BIT 3
#endif
#endif
/* Sanguino support */
#if defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
/* Onboard LED is connected to pin PB0 on Sanguino */
#define LED_DDR DDRB
#define LED_PORT PORTB
#define LED_PIN PINB
#define LED PINB0
/* Ports for soft UART */
#ifdef SOFT_UART
#define UART_PORT PORTD
#define UART_PIN PIND
#define UART_DDR DDRD
#define UART_TX_BIT 1
#define UART_RX_BIT 0
#endif
#endif
/* Mega support */
#if defined(__AVR_ATmega1280__)
/* Onboard LED is connected to pin PB7 on Arduino Mega */
#define LED_DDR DDRB
#define LED_PORT PORTB
#define LED_PIN PINB
#define LED PINB7
/* Ports for soft UART */
#ifdef SOFT_UART
#define UART_PORT PORTE
#define UART_PIN PINE
#define UART_DDR DDRE
#define UART_TX_BIT 1
#define UART_RX_BIT 0
#endif
#endif

View File

@ -0,0 +1,39 @@
/* STK500 constants list, from AVRDUDE */
#define STK_OK 0x10
#define STK_FAILED 0x11 // Not used
#define STK_UNKNOWN 0x12 // Not used
#define STK_NODEVICE 0x13 // Not used
#define STK_INSYNC 0x14 // ' '
#define STK_NOSYNC 0x15 // Not used
#define ADC_CHANNEL_ERROR 0x16 // Not used
#define ADC_MEASURE_OK 0x17 // Not used
#define PWM_CHANNEL_ERROR 0x18 // Not used
#define PWM_ADJUST_OK 0x19 // Not used
#define CRC_EOP 0x20 // 'SPACE'
#define STK_GET_SYNC 0x30 // '0'
#define STK_GET_SIGN_ON 0x31 // '1'
#define STK_SET_PARAMETER 0x40 // '@'
#define STK_GET_PARAMETER 0x41 // 'A'
#define STK_SET_DEVICE 0x42 // 'B'
#define STK_SET_DEVICE_EXT 0x45 // 'E'
#define STK_ENTER_PROGMODE 0x50 // 'P'
#define STK_LEAVE_PROGMODE 0x51 // 'Q'
#define STK_CHIP_ERASE 0x52 // 'R'
#define STK_CHECK_AUTOINC 0x53 // 'S'
#define STK_LOAD_ADDRESS 0x55 // 'U'
#define STK_UNIVERSAL 0x56 // 'V'
#define STK_PROG_FLASH 0x60 // '`'
#define STK_PROG_DATA 0x61 // 'a'
#define STK_PROG_FUSE 0x62 // 'b'
#define STK_PROG_LOCK 0x63 // 'c'
#define STK_PROG_PAGE 0x64 // 'd'
#define STK_PROG_FUSE_EXT 0x65 // 'e'
#define STK_READ_FLASH 0x70 // 'p'
#define STK_READ_DATA 0x71 // 'q'
#define STK_READ_FUSE 0x72 // 'r'
#define STK_READ_LOCK 0x73 // 's'
#define STK_READ_PAGE 0x74 // 't'
#define STK_READ_SIGN 0x75 // 'u'
#define STK_READ_OSCCAL 0x76 // 'v'
#define STK_READ_FUSE_EXT 0x77 // 'w'
#define STK_READ_OSCCAL_EXT 0x78 // 'x'

View File

@ -0,0 +1,713 @@
/**********************************************************/
/* Serial Bootloader for Atmel megaAVR Controllers */
/* */
/* tested with ATmega644 and ATmega644P */
/* should work with other mega's, see code for details */
/* */
/* ATmegaBOOT.c */
/* */
/* 20090131: Added 324P support from Alex Leone */
/* Marius Kintel */
/* 20080915: applied ADABoot mods for Sanguino 644P */
/* Brian Riley */
/* 20080711: hacked for Sanguino by Zach Smith */
/* and Justin Day */
/* 20070626: hacked for Arduino Diecimila (which auto- */
/* resets when a USB connection is made to it) */
/* by D. Mellis */
/* 20060802: hacked for Arduino by D. Cuartielles */
/* based on a previous hack by D. Mellis */
/* and D. Cuartielles */
/* */
/* Monitor and debug functions were added to the original */
/* code by Dr. Erik Lins, chip45.com. (See below) */
/* */
/* Thanks to Karl Pitrich for fixing a bootloader pin */
/* problem and more informative LED blinking! */
/* */
/* For the latest version see: */
/* http://www.chip45.com/ */
/* */
/* ------------------------------------------------------ */
/* */
/* based on stk500boot.c */
/* Copyright (c) 2003, Jason P. Kyle */
/* All rights reserved. */
/* see avr1.org for original file and information */
/* */
/* 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 the Free Software */
/* Foundation; either version 2 of the License, or */
/* (at your option) any later version. */
/* */
/* This program 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 General Public */
/* License for more details. */
/* */
/* You should have received a copy of the GNU General */
/* Public License along with this program; if not, write */
/* to the Free Software Foundation, Inc., */
/* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* */
/* Licence can be viewed at */
/* http://www.fsf.org/licenses/gpl.txt */
/* */
/* Target = Atmel AVR m128,m64,m32,m16,m8,m162,m163,m169, */
/* m8515,m8535. ATmega161 has a very small boot block so */
/* isn't supported. */
/* */
/* Tested with m168 */
/**********************************************************/
/* $Id$ */
/* some includes */
#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#include <avr/boot.h>
#ifdef ADABOOT
#define NUM_LED_FLASHES 3
#define ADABOOT_VER 1
#endif
/* 20070707: hacked by David A. Mellis - after this many errors give up and launch application */
#define MAX_ERROR_COUNT 5
/* set the UART baud rate */
/* 20080711: hack by Zach Hoeken */
#define BAUD_RATE 38400
/* SW_MAJOR and MINOR needs to be updated from time to time to avoid warning message from AVR Studio */
/* never allow AVR Studio to do an update !!!! */
#define HW_VER 0x02
#define SW_MAJOR 0x01
#define SW_MINOR 0x10
/* onboard LED is used to indicate, that the bootloader was entered (3x flashing) */
/* if monitor functions are included, LED goes on after monitor was entered */
#define LED_DDR DDRB
#define LED_PORT PORTB
#define LED_PIN PINB
#define LED PINB0
/* define various device id's */
/* manufacturer byte is always the same */
#define SIG1 0x1E // Yep, Atmel is the only manufacturer of AVR micros. Single source :(
#if defined(__AVR_ATmega644P__)
#define SIG2 0x96
#define SIG3 0x0A
#elif defined(__AVR_ATmega644__)
#define SIG2 0x96
#define SIG3 0x09
#elif defined(__AVR_ATmega324P__)
#define SIG2 0x95
#define SIG3 0x08
#endif
#define PAGE_SIZE 0x080U //128 words
#define PAGE_SIZE_BYTES 0x100U //256 bytes
/* function prototypes */
void putch(char);
char getch(void);
void getNch(uint8_t);
void byte_response(uint8_t);
void nothing_response(void);
char gethex(void);
void puthex(char);
void flash_led(uint8_t);
/* some variables */
union address_union
{
uint16_t word;
uint8_t byte[2];
} address;
union length_union
{
uint16_t word;
uint8_t byte[2];
} length;
struct flags_struct
{
unsigned eeprom : 1;
unsigned rampz : 1;
} flags;
uint8_t buff[256];
uint8_t error_count = 0;
uint8_t sreg;
void (*app_start)(void) = 0x0000;
/* main program starts here */
int main(void)
{
uint8_t ch,ch2;
uint16_t w;
uint16_t i;
asm volatile("nop\n\t");
#ifdef ADABOOT // BBR/LF 10/8/2007 & 9/13/2008
ch = MCUSR;
MCUSR = 0;
WDTCSR |= _BV(WDCE) | _BV(WDE);
WDTCSR = 0;
// Check if the WDT was used to reset, in which case we dont bootload and skip straight to the code. woot.
if (! (ch & _BV(EXTRF))) // if its a not an external reset...
app_start(); // skip bootloader
#endif
//initialize our serial port.
UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
UCSR0B = (1<<RXEN0) | (1<<TXEN0);
UCSR0C = (1<<UCSZ00) | (1<<UCSZ01);
/* Enable internal pull-up resistor on pin D0 (RX), in order
to supress line noise that prevents the bootloader from
timing out (DAM: 20070509) */
DDRD &= ~_BV(PIND0);
PORTD |= _BV(PIND0);
/* set LED pin as output */
LED_DDR |= _BV(LED);
/* flash onboard LED to signal entering of bootloader */
/* ADABOOT will do two series of flashes. first 4 - signifying ADABOOT */
/* then a pause and another flash series signifying ADABOOT sub-version */
flash_led(NUM_LED_FLASHES);
#ifdef ADABOOT
flash_led(ADABOOT_VER); // BBR 9/13/2008
#endif
/* forever loop */
for (;;)
{
/* get character from UART */
ch = getch();
/* A bunch of if...else if... gives smaller code than switch...case ! */
/* Hello is anyone home ? */
if(ch=='0')
nothing_response();
/* Request programmer ID */
/* Not using PROGMEM string due to boot block in m128 being beyond 64kB boundry */
/* Would need to selectively manipulate RAMPZ, and it's only 9 characters anyway so who cares. */
else if(ch=='1')
{
if (getch() == ' ')
{
putch(0x14);
putch('A');
putch('V');
putch('R');
putch(' ');
putch('I');
putch('S');
putch('P');
putch(0x10);
}
else
{
if (++error_count == MAX_ERROR_COUNT)
app_start();
}
}
/* AVR ISP/STK500 board commands DON'T CARE so default nothing_response */
else if(ch=='@')
{
ch2 = getch();
if (ch2 > 0x85)
getch();
nothing_response();
}
/* AVR ISP/STK500 board requests */
else if(ch=='A')
{
ch2 = getch();
if(ch2 == 0x80)
byte_response(HW_VER); // Hardware version
else if(ch2==0x81)
byte_response(SW_MAJOR); // Software major version
else if(ch2==0x82)
byte_response(SW_MINOR); // Software minor version
else if(ch2==0x98)
byte_response(0x03); // Unknown but seems to be required by avr studio 3.56
else
byte_response(0x00); // Covers various unnecessary responses we don't care about
}
/* Device Parameters DON'T CARE, DEVICE IS FIXED */
else if(ch=='B')
{
getNch(20);
nothing_response();
}
/* Parallel programming stuff DON'T CARE */
else if(ch=='E')
{
getNch(5);
nothing_response();
}
/* Enter programming mode */
else if(ch=='P')
{
nothing_response();
}
/* Leave programming mode */
else if(ch=='Q')
{
nothing_response();
#ifdef ADABOOT
// autoreset via watchdog (sneaky!) BBR/LF 9/13/2008
WDTCSR = _BV(WDE);
while (1); // 16 ms
#endif
}
/* Erase device, don't care as we will erase one page at a time anyway. */
else if(ch=='R')
{
nothing_response();
}
/* Set address, little endian. EEPROM in bytes, FLASH in words */
/* Perhaps extra address bytes may be added in future to support > 128kB FLASH. */
/* This might explain why little endian was used here, big endian used everywhere else. */
else if(ch=='U')
{
address.byte[0] = getch();
address.byte[1] = getch();
nothing_response();
}
/* Universal SPI programming command, disabled. Would be used for fuses and lock bits. */
else if(ch=='V')
{
getNch(4);
byte_response(0x00);
}
/* Write memory, length is big endian and is in bytes */
else if(ch=='d')
{
length.byte[1] = getch();
length.byte[0] = getch();
flags.eeprom = 0;
if (getch() == 'E')
flags.eeprom = 1;
for (i=0; i<PAGE_SIZE; i++)
buff[i] = 0;
for (w = 0; w < length.word; w++)
{
// Store data in buffer, can't keep up with serial data stream whilst programming pages
buff[w] = getch();
}
if (getch() == ' ')
{
if (flags.eeprom)
{
//Write to EEPROM one byte at a time
for(w=0;w<length.word;w++)
{
while(EECR & (1<<EEPE));
EEAR = (uint16_t)(void *)address.word;
EEDR = buff[w];
EECR |= (1<<EEMPE);
EECR |= (1<<EEPE);
address.word++;
}
}
else
{
//address * 2 -> byte location
address.word = address.word << 1;
//Even up an odd number of bytes
if ((length.byte[0] & 0x01))
length.word++;
// HACKME: EEPE used to be EEWE
//Wait for previous EEPROM writes to complete
//while(bit_is_set(EECR,EEPE));
while(EECR & (1<<EEPE));
asm volatile(
"clr r17 \n\t" //page_word_count
"lds r30,address \n\t" //Address of FLASH location (in bytes)
"lds r31,address+1 \n\t"
"ldi r28,lo8(buff) \n\t" //Start of buffer array in RAM
"ldi r29,hi8(buff) \n\t"
"lds r24,length \n\t" //Length of data to be written (in bytes)
"lds r25,length+1 \n\t"
"length_loop: \n\t" //Main loop, repeat for number of words in block
"cpi r17,0x00 \n\t" //If page_word_count=0 then erase page
"brne no_page_erase \n\t"
"wait_spm1: \n\t"
"lds r16,%0 \n\t" //Wait for previous spm to complete
"andi r16,1 \n\t"
"cpi r16,1 \n\t"
"breq wait_spm1 \n\t"
"ldi r16,0x03 \n\t" //Erase page pointed to by Z
"sts %0,r16 \n\t"
"spm \n\t"
"wait_spm2: \n\t"
"lds r16,%0 \n\t" //Wait for previous spm to complete
"andi r16,1 \n\t"
"cpi r16,1 \n\t"
"breq wait_spm2 \n\t"
"ldi r16,0x11 \n\t" //Re-enable RWW section
"sts %0,r16 \n\t"
"spm \n\t"
"no_page_erase: \n\t"
"ld r0,Y+ \n\t" //Write 2 bytes into page buffer
"ld r1,Y+ \n\t"
"wait_spm3: \n\t"
"lds r16,%0 \n\t" //Wait for previous spm to complete
"andi r16,1 \n\t"
"cpi r16,1 \n\t"
"breq wait_spm3 \n\t"
"ldi r16,0x01 \n\t" //Load r0,r1 into FLASH page buffer
"sts %0,r16 \n\t"
"spm \n\t"
"inc r17 \n\t" //page_word_count++
"cpi r17,%1 \n\t"
"brlo same_page \n\t" //Still same page in FLASH
"write_page: \n\t"
"clr r17 \n\t" //New page, write current one first
"wait_spm4: \n\t"
"lds r16,%0 \n\t" //Wait for previous spm to complete
"andi r16,1 \n\t"
"cpi r16,1 \n\t"
"breq wait_spm4 \n\t"
"ldi r16,0x05 \n\t" //Write page pointed to by Z
"sts %0,r16 \n\t"
"spm \n\t"
"wait_spm5: \n\t"
"lds r16,%0 \n\t" //Wait for previous spm to complete
"andi r16,1 \n\t"
"cpi r16,1 \n\t"
"breq wait_spm5 \n\t"
"ldi r16,0x11 \n\t" //Re-enable RWW section
"sts %0,r16 \n\t"
"spm \n\t"
"same_page: \n\t"
"adiw r30,2 \n\t" //Next word in FLASH
"sbiw r24,2 \n\t" //length-2
"breq final_write \n\t" //Finished
"rjmp length_loop \n\t"
"final_write: \n\t"
"cpi r17,0 \n\t"
"breq block_done \n\t"
"adiw r24,2 \n\t" //length+2, fool above check on length after short page write
"rjmp write_page \n\t"
"block_done: \n\t"
"clr __zero_reg__ \n\t" //restore zero register
: "=m" (SPMCSR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31"
);
}
putch(0x14);
putch(0x10);
}
else
{
if (++error_count == MAX_ERROR_COUNT)
app_start();
}
}
/* Read memory block mode, length is big endian. */
else if(ch=='t')
{
length.byte[1] = getch();
length.byte[0] = getch();
if (getch() == 'E')
flags.eeprom = 1;
else
{
flags.eeprom = 0;
address.word = address.word << 1; // address * 2 -> byte location
}
// Command terminator
if (getch() == ' ')
{
putch(0x14);
for (w=0; w<length.word; w++)
{
// Can handle odd and even lengths okay
if (flags.eeprom)
{
// Byte access EEPROM read
while(EECR & (1<<EEPE));
EEAR = (uint16_t)(void *)address.word;
EECR |= (1<<EERE);
putch(EEDR);
address.word++;
}
else
{
if (!flags.rampz)
putch(pgm_read_byte_near(address.word));
address.word++;
}
}
putch(0x10);
}
}
/* Get device signature bytes */
else if(ch=='u')
{
if (getch() == ' ')
{
putch(0x14);
putch(SIG1);
putch(SIG2);
putch(SIG3);
putch(0x10);
}
else
{
if (++error_count == MAX_ERROR_COUNT)
app_start();
}
}
/* Read oscillator calibration byte */
else if(ch=='v')
byte_response(0x00);
else if (++error_count == MAX_ERROR_COUNT)
app_start();
}
/* end of forever loop */
}
char gethex(void)
{
char ah,al;
ah = getch();
putch(ah);
al = getch();
putch(al);
if(ah >= 'a')
ah = ah - 'a' + 0x0a;
else if(ah >= '0')
ah -= '0';
if(al >= 'a')
al = al - 'a' + 0x0a;
else if(al >= '0')
al -= '0';
return (ah << 4) + al;
}
void puthex(char ch)
{
char ah,al;
ah = (ch & 0xf0) >> 4;
if(ah >= 0x0a)
ah = ah - 0x0a + 'a';
else
ah += '0';
al = (ch & 0x0f);
if(al >= 0x0a)
al = al - 0x0a + 'a';
else
al += '0';
putch(ah);
putch(al);
}
void putch(char ch)
{
while (!(UCSR0A & _BV(UDRE0)));
UDR0 = ch;
}
char getch(void)
{
uint32_t count = 0;
#ifdef ADABOOT
LED_PORT &= ~_BV(LED); // toggle LED to show activity - BBR/LF 10/3/2007 & 9/13/2008
#endif
while(!(UCSR0A & _BV(RXC0)))
{
/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
/* HACKME:: here is a good place to count times*/
count++;
if (count > MAX_TIME_COUNT)
app_start();
}
#ifdef ADABOOT
LED_PORT |= _BV(LED); // toggle LED to show activity - BBR/LF 10/3/2007 & 9/13/2008
#endif
return UDR0;
}
void getNch(uint8_t count)
{
uint8_t i;
for(i=0;i<count;i++)
{
while(!(UCSR0A & _BV(RXC0)));
UDR0;
}
}
void byte_response(uint8_t val)
{
if (getch() == ' ')
{
putch(0x14);
putch(val);
putch(0x10);
}
else
{
if (++error_count == MAX_ERROR_COUNT)
app_start();
}
}
void nothing_response(void)
{
if (getch() == ' ')
{
putch(0x14);
putch(0x10);
}
else
{
if (++error_count == MAX_ERROR_COUNT)
app_start();
}
}
#ifdef ADABOOT
void flash_led(uint8_t count)
{
/* flash onboard LED count times to signal entering of bootloader */
/* l needs to be volatile or the delay loops below might get */
/* optimized away if compiling with optimizations (DAM). */
volatile uint32_t l;
if (count == 0) {
count = ADABOOT;
}
int8_t i;
for (i = 0; i < count; ++i) {
LED_PORT |= _BV(LED); // LED on
for(l = 0; l < (F_CPU / 1000); ++l); // delay NGvalue was 1000 for both loops - BBR
LED_PORT &= ~_BV(LED); // LED off
for(l = 0; l < (F_CPU / 250); ++l); // delay asymmteric for ADA BOOT BBR
}
for(l = 0; l < (F_CPU / 100); ++l); // pause ADA BOOT BBR
}
#else
void flash_led(uint8_t count)
{
/* flash onboard LED three times to signal entering of bootloader */
/* l needs to be volatile or the delay loops below might get
optimized away if compiling with optimizations (DAM). */
volatile uint32_t l;
if (count == 0) {
count = 3;
}
int8_t i;
for (i = 0; i < count; ++i) {
LED_PORT |= _BV(LED);
for(l = 0; l < (F_CPU / 1000); ++l);
LED_PORT &= ~_BV(LED);
for(l = 0; l < (F_CPU / 1000); ++l);
}
}
#endif
/* end of file ATmegaBOOT.c */

View File

@ -0,0 +1,121 @@
:10F800000C943E7C0C945B7C0C945B7C0C945B7C39
:10F810000C945B7C0C945B7C0C945B7C0C945B7C0C
:10F820000C945B7C0C945B7C0C945B7C0C945B7CFC
:10F830000C945B7C0C945B7C0C945B7C0C945B7CEC
:10F840000C945B7C0C945B7C0C945B7C0C945B7CDC
:10F850000C945B7C0C945B7C0C945B7C0C945B7CCC
:10F860000C945B7C0C945B7C0C945B7C0C945B7CBC
:10F870000C945B7C0C945B7C0C945B7C11241FBE11
:10F88000CFEFD8E0DEBFCDBF11E0A0E0B1E0E6E60B
:10F89000FFEF02C005900D92A030B107D9F712E03A
:10F8A000A0E0B1E001C01D92A930B107E1F70E94CC
:10F8B000537D0C94B27F0C94007CCF93DF93CDB733
:10F8C000DEB724970FB6F894DEBF0FBECDBF8823F6
:10F8D00009F481E020E0482F55274115510509F42E
:10F8E0003DC0289A19821A821B821C820BC0898112
:10F8F0009A81AB81BC810196A11DB11D89839A8338
:10F90000AB83BC8389819A81AB81BC8180589E4343
:10F91000A040B04060F3289819821A821B821C8292
:10F920000BC089819A81AB81BC810196A11DB11D5B
:10F9300089839A83AB83BC8389819A81AB81BC81A3
:10F9400080509A4FA040B04060F32F5F822F9927DC
:10F9500087FD9095841795070CF4C3CF19821A82FE
:10F960001B821C8289819A81AB81BC818050914726
:10F97000A240B040A0F489819A81AB81BC810196FC
:10F98000A11DB11D89839A83AB83BC8389819A8130
:10F99000AB81BC8180509147A240B04060F3249677
:10F9A0000FB6F894DEBF0FBECDBFDF91CF910895A3
:10F9B000EF92FF920F931F93EE24FF248701289864
:10F9C0008091C00087FD17C00894E11CF11C011D47
:10F9D000111D81E0E81689E0F8068DE3080780E054
:10F9E000180770F3E0910001F091010109958091F1
:10F9F000C00087FFE9CF289A8091C600992787FD2C
:10FA000090951F910F91FF90EF900895982F8091FE
:10FA1000C00085FFFCCF9093C60008950E94D87C5B
:10FA2000803271F0809102018F5F809302018530F6
:10FA300009F00895E0910001F09101010995089500
:10FA400084E10E94067D80E10E94067D0895CF93A7
:10FA5000C82F0E94D87C803241F0809102018F5FD4
:10FA600080930201853081F40AC084E10E94067D02
:10FA70008C2F0E94067D80E10E94067D05C0E091EA
:10FA80000001F09101010995CF910895282F90E090
:10FA900007C08091C0008823E4F78091C6009F5F73
:10FAA0009217B8F30895CFEFD8E0DEBFCDBF0000C6
:10FAB00094B714BE809160008861809360001092BA
:10FAC000600091FF74C189E18093C4001092C50069
:10FAD00088E18093C10086E08093C2005098589AD4
:10FAE000209A83E00E945D7C81E00E945D7C0E9400
:10FAF000D87C8033B9F18133C1F1803409F456C028
:10FB0000813409F45CC0823409F46EC0853409F490
:10FB100071C0803539F1813509F4F3C0823511F1B6
:10FB2000853509F4D3C0863509F4CBC0843609F491
:10FB300065C0843709F4EBC0853709F4D2C0863735
:10FB400009F44AC0809102018F5F809302018530E1
:10FB500071F6E0910001F091010109950E94D87CB5
:10FB6000803349F60E940E7DC2CF0E94D87CC82FF8
:10FB7000803241F784E10E94067D81E40E94067D87
:10FB800086E50E94067D82E50E94067D8C2F0E94FC
:10FB9000067D89E40E94067D83E50E94067D80E55E
:10FBA0000E94067D80E10E94067DA1CF0E94D87C44
:10FBB0008638C0F20E94D87C0E940E7D98CF0E94A9
:10FBC000D87C803809F407C1813809F400C1823833
:10FBD00009F4F9C0883921F080E00E94277D87CFA1
:10FBE00083E00E94277D83CF84E10E94467D0E94AE
:10FBF0000E7D7DCF85E00E94467DF9CF0E94D87CA6
:10FC0000809306020E94D87C8093050280910802AE
:10FC10008E7F809308020E94D87C853409F44BC003
:10FC2000E5E0F1E0119281E0E438F807D9F3D0F390
:10FC3000C0E0D0E0809105029091060218161906E6
:10FC400078F405E011E00E94D87CF80181938F01DF
:10FC500021968091050290910602C817D90798F362
:10FC60000E94D87C803209F06DCF8091080280FF1D
:10FC7000B6C0C0E0D0E02091050230910602121615
:10FC80001306B8F4E0910301F0910401A5E0B1E09E
:10FC9000F999FECFF2BDE1BD8D9180BDFA9AF99A36
:10FCA00031962196C217D30798F3F0930401E0939D
:10FCB000030184E175CF809108028160809308027E
:10FCC000AFCF84E00E94467D80E087CF0E94D87C41
:10FCD000809303010E94D87C809304010E940E7DD2
:10FCE00006CF0E94D87C803209F02CCF84E10E949C
:10FCF000067D8EE10E94067D85E90E94067D88E0F2
:10FD00004FCF0E940E7D88E080936000FFCF0E945D
:10FD1000D87C809306020E94D87C809305020E94C2
:10FD2000D87C853409F449C0809108028E7F809385
:10FD300008028091030190910401880F991F90930C
:10FD40000401809303010E94D87C803209F0CFCE59
:10FD500084E10E94067DC0E0D0E020910502309150
:10FD600006021216130608F01DCFE0910301F09170
:10FD700004018091080280FF96C0F999FECFF2BD80
:10FD8000E1BDF89A80B50E94067DE0910301F091F3
:10FD900004013196F0930401E093030120910502E0
:10FDA000309106022196C217D30718F3FBCEE091DB
:10FDB0000001F0910101099586CE809108028160D1
:10FDC00080930802C0CF80E10E94277D90CE81E021
:10FDD0000E94277D8CCE82E00E94277D88CE809174
:10FDE000030190910401880F991F9093040180935F
:10FDF00003018091050280FF09C080910502909166
:10FE0000060201969093060280930502F999FECFAF
:10FE10001127E0910301F0910401C5E0D1E0809148
:10FE2000050290910602103091F400915700017084
:10FE30000130D9F303E000935700E8950091570093
:10FE400001700130D9F301E100935700E895099062
:10FE500019900091570001700130D9F301E000932F
:10FE60005700E8951395103898F011270091570026
:10FE700001700130D9F305E000935700E895009137
:10FE8000570001700130D9F301E100935700E89564
:10FE90003296029709F0C7CF103011F00296E5CFE5
:10FEA000112484E17DCE869580FF06C03196F093C3
:10FEB0000401E093030176CF84910E94067D209196
:10FEC000050230910602E0910301F0910401EECFAA
:10FED0001F93CF930E94D87CC82F0E94067D0E945A
:10FEE000D87C182F0E94067DC1362CF0C7551136DC
:10FEF0003CF0175508C0C033D4F3C0531136CCF7CB
:10FF000010330CF01053C295C07FC10F8C2F99276E
:10FF100087FD9095CF911F910895CF93282F992712
:10FF200087FD9095807F907095958795959587959D
:10FF300095958795959587958A303CF0895AC22F7B
:10FF4000CF70CA303CF0C95A06C0805DC22FCF7056
:10FF5000CA30CCF7C05D0E94067D8C2F0E94067DC2
:06FF6000CF910895FFCFD0
:040000030000F80001
:00000001FF

View File

@ -0,0 +1,120 @@
:10F800000C94387C0C94557C0C94557C0C94557C51
:10F810000C94557C0C94557C0C94557C0C94557C24
:10F820000C94557C0C94557C0C94557C0C94557C14
:10F830000C94557C0C94557C0C94557C0C94557C04
:10F840000C94557C0C94557C0C94557C0C94557CF4
:10F850000C94557C0C94557C0C94557C0C94557CE4
:10F860000C94557C0C94557C0C94557C0C94557CD4
:10F8700011241FBECFEFD0E1DEBFCDBF11E0A0E06D
:10F88000B1E0EAE5FFEF02C005900D92A030B107AC
:10F89000D9F712E0A0E0B1E001C01D92A930B10794
:10F8A000E1F70E944D7D0C94AC7F0C94007CCF93CB
:10F8B000DF93CDB7DEB724970FB6F894DEBF0FBE47
:10F8C000CDBF882309F481E020E0482F552741155A
:10F8D000510509F43DC0289A19821A821B821C82A4
:10F8E0000BC089819A81AB81BC810196A11DB11D9C
:10F8F00089839A83AB83BC8389819A81AB81BC81E4
:10F9000080589E43A040B04060F3289819821A8224
:10F910001B821C820BC089819A81AB81BC810196BC
:10F92000A11DB11D89839A83AB83BC8389819A8190
:10F93000AB81BC8180509A4FA040B04060F32F5FF4
:10F94000822F992787FD9095841795070CF4C3CFD4
:10F9500019821A821B821C8289819A81AB81BC81A7
:10F9600080509147A240B040A0F489819A81AB8138
:10F97000BC810196A11DB11D89839A83AB83BC8391
:10F9800089819A81AB81BC8180509147A240B0406F
:10F9900060F324960FB6F894DEBF0FBECDBFDF91A3
:10F9A000CF910895EF92FF920F931F93EE24FF24BF
:10F9B000870128988091C00087FD17C00894E11C3A
:10F9C000F11C011D111D81E0E81689E0F8068DE3A8
:10F9D000080780E0180770F3E0910001F091010141
:10F9E00009958091C00087FFE9CF289A8091C600D1
:10F9F000992787FD90951F910F91FF90EF900895A3
:10FA0000982F8091C00085FFFCCF9093C600089589
:10FA10000E94D27C803271F0809102018F5F8093CE
:10FA20000201853009F00895E0910001F091010193
:10FA30000995089584E10E94007D80E10E94007D87
:10FA40000895CF93C82F0E94D27C803241F08091DC
:10FA500002018F5F80930201853081F40AC084E146
:10FA60000E94007D8C2F0E94007D80E10E94007D1D
:10FA700005C0E0910001F09101010995CF91089531
:10FA8000282F90E007C08091C0008823E4F7809180
:10FA9000C6009F5F9217B8F30895CFEFD0E1DEBFA5
:10FAA000CDBF000094B714BE809160008861809340
:10FAB00060001092600091FF74C189E18093C400DE
:10FAC0001092C50088E18093C10086E08093C20057
:10FAD0005098589A209A83E00E94577C81E00E94B7
:10FAE000577C0E94D27C8033B9F18133C1F18034DC
:10FAF00009F456C0813409F45CC0823409F46EC044
:10FB0000853409F471C0803539F1813509F4F3C0C9
:10FB1000823511F1853509F4D3C0863509F4CBC09F
:10FB2000843609F465C0843709F4EBC0853709F4DD
:10FB3000D2C0863709F44AC0809102018F5F80935A
:10FB40000201853071F6E0910001F0910101099503
:10FB50000E94D27C803349F60E94087DC2CF0E9469
:10FB6000D27CC82F803241F784E10E94007D81E47D
:10FB70000E94007D86E50E94007D82E50E94007D56
:10FB80008C2F0E94007D89E40E94007D83E50E9405
:10FB9000007D80E50E94007D80E10E94007DA1CF74
:10FBA0000E94D27C8638C0F20E94D27C0E94087DDE
:10FBB00098CF0E94D27C803809F407C1813809F4BB
:10FBC00000C1823809F4F9C0883921F080E00E9430
:10FBD000217D87CF83E00E94217D83CF84E10E9435
:10FBE000407D0E94087D7DCF85E00E94407DF9CF59
:10FBF0000E94D27C809306020E94D27C80930502F0
:10FC0000809108028E7F809308020E94D27C853406
:10FC100009F44BC0E5E0F1E0119281E0E438F80727
:10FC2000D9F3D0F3C0E0D0E08091050290910602B4
:10FC30001816190678F405E011E00E94D27CF8014C
:10FC400081938F0121968091050290910602C81739
:10FC5000D90798F30E94D27C803209F06DCF809151
:10FC6000080280FFB6C0C0E0D0E0209105023091CC
:10FC7000060212161306B8F4E0910301F091040194
:10FC8000A5E0B1E0F999FECFF2BDE1BD8D9180BD57
:10FC9000FA9AF99A31962196C217D30798F3F093FE
:10FCA0000401E093030184E175CF80910802816033
:10FCB00080930802AFCF84E00E94407D80E087CF30
:10FCC0000E94D27C809303010E94D27C8093040125
:10FCD0000E94087D06CF0E94D27C803209F02CCF92
:10FCE00084E10E94007D8EE10E94007D86E90E94F1
:10FCF000007D89E04FCF0E94087D88E080936000FE
:10FD0000FFCF0E94D27C809306020E94D27C809317
:10FD100005020E94D27C853409F449C08091080212
:10FD20008E7F809308028091030190910401880FD7
:10FD3000991F90930401809303010E94D27C80322A
:10FD400009F0CFCE84E10E94007DC0E0D0E0209198
:10FD50000502309106021216130608F01DCFE0913D
:10FD60000301F09104018091080280FF96C0F99987
:10FD7000FECFF2BDE1BDF89A80B50E94007DE09112
:10FD80000301F09104013196F0930401E093030123
:10FD900020910502309106022196C217D30718F36D
:10FDA000FBCEE0910001F0910101099586CE809192
:10FDB0000802816080930802C0CF80E10E94217D0B
:10FDC00090CE81E00E94217D8CCE82E00E94217D38
:10FDD00088CE8091030190910401880F991F909320
:10FDE0000401809303018091050280FF09C0809186
:10FDF00005029091060201969093060280930502F7
:10FE0000F999FECF1127E0910301F0910401C5E0BB
:10FE1000D1E08091050290910602103091F400919A
:10FE2000570001700130D9F303E000935700E895C3
:10FE30000091570001700130D9F301E100935700A0
:10FE4000E895099019900091570001700130D9F39D
:10FE500001E000935700E8951395103898F01127AA
:10FE60000091570001700130D9F305E0009357006D
:10FE7000E8950091570001700130D9F301E100933A
:10FE80005700E8953296029709F0C7CF103011F06D
:10FE90000296E5CF112484E17DCE869580FF06C0D1
:10FEA0003196F0930401E093030176CF84910E9490
:10FEB000007D2091050230910602E0910301F0914E
:10FEC0000401EECF1F93CF930E94D27CC82F0E94D3
:10FED000007D0E94D27C182F0E94007DC1362CF03C
:10FEE000C75511363CF0175508C0C033D4F3C05382
:10FEF0001136CCF710330CF01053C295C07FC10FF0
:10FF00008C2F992787FD9095CF911F910895CF93BE
:10FF1000282F992787FD9095807F907095958795DC
:10FF20009595879595958795959587958A303CF019
:10FF3000895AC22FCF70CA303CF0C95A06C0805DC2
:10FF4000C22FCF70CA30CCF7C05D0E94007D8C2FCD
:0AFF50000E94007DCF910895FFCFBD
:040000030000F80001
:00000001FF

View File

@ -0,0 +1,121 @@
:10F800000C943E7C0C945B7C0C945B7C0C945B7C39
:10F810000C945B7C0C945B7C0C945B7C0C945B7C0C
:10F820000C945B7C0C945B7C0C945B7C0C945B7CFC
:10F830000C945B7C0C945B7C0C945B7C0C945B7CEC
:10F840000C945B7C0C945B7C0C945B7C0C945B7CDC
:10F850000C945B7C0C945B7C0C945B7C0C945B7CCC
:10F860000C945B7C0C945B7C0C945B7C0C945B7CBC
:10F870000C945B7C0C945B7C0C945B7C11241FBE11
:10F88000CFEFD0E1DEBFCDBF11E0A0E0B1E0E6E612
:10F89000FFEF02C005900D92A030B107D9F712E03A
:10F8A000A0E0B1E001C01D92A930B107E1F70E94CC
:10F8B000537D0C94B27F0C94007CCF93DF93CDB733
:10F8C000DEB724970FB6F894DEBF0FBECDBF8823F6
:10F8D00009F481E020E0482F55274115510509F42E
:10F8E0003DC0289A19821A821B821C820BC0898112
:10F8F0009A81AB81BC810196A11DB11D89839A8338
:10F90000AB83BC8389819A81AB81BC8180589E4343
:10F91000A040B04060F3289819821A821B821C8292
:10F920000BC089819A81AB81BC810196A11DB11D5B
:10F9300089839A83AB83BC8389819A81AB81BC81A3
:10F9400080509A4FA040B04060F32F5F822F9927DC
:10F9500087FD9095841795070CF4C3CF19821A82FE
:10F960001B821C8289819A81AB81BC818050914726
:10F97000A240B040A0F489819A81AB81BC810196FC
:10F98000A11DB11D89839A83AB83BC8389819A8130
:10F99000AB81BC8180509147A240B04060F3249677
:10F9A0000FB6F894DEBF0FBECDBFDF91CF910895A3
:10F9B000EF92FF920F931F93EE24FF248701289864
:10F9C0008091C00087FD17C00894E11CF11C011D47
:10F9D000111D81E0E81689E0F8068DE3080780E054
:10F9E000180770F3E0910001F091010109958091F1
:10F9F000C00087FFE9CF289A8091C600992787FD2C
:10FA000090951F910F91FF90EF900895982F8091FE
:10FA1000C00085FFFCCF9093C60008950E94D87C5B
:10FA2000803271F0809102018F5F809302018530F6
:10FA300009F00895E0910001F09101010995089500
:10FA400084E10E94067D80E10E94067D0895CF93A7
:10FA5000C82F0E94D87C803241F0809102018F5FD4
:10FA600080930201853081F40AC084E10E94067D02
:10FA70008C2F0E94067D80E10E94067D05C0E091EA
:10FA80000001F09101010995CF910895282F90E090
:10FA900007C08091C0008823E4F78091C6009F5F73
:10FAA0009217B8F30895CFEFD0E1DEBFCDBF0000CD
:10FAB00094B714BE809160008861809360001092BA
:10FAC000600091FF74C189E18093C4001092C50069
:10FAD00088E18093C10086E08093C2005098589AD4
:10FAE000209A83E00E945D7C81E00E945D7C0E9400
:10FAF000D87C8033B9F18133C1F1803409F456C028
:10FB0000813409F45CC0823409F46EC0853409F490
:10FB100071C0803539F1813509F4F3C0823511F1B6
:10FB2000853509F4D3C0863509F4CBC0843609F491
:10FB300065C0843709F4EBC0853709F4D2C0863735
:10FB400009F44AC0809102018F5F809302018530E1
:10FB500071F6E0910001F091010109950E94D87CB5
:10FB6000803349F60E940E7DC2CF0E94D87CC82FF8
:10FB7000803241F784E10E94067D81E40E94067D87
:10FB800086E50E94067D82E50E94067D8C2F0E94FC
:10FB9000067D89E40E94067D83E50E94067D80E55E
:10FBA0000E94067D80E10E94067DA1CF0E94D87C44
:10FBB0008638C0F20E94D87C0E940E7D98CF0E94A9
:10FBC000D87C803809F407C1813809F400C1823833
:10FBD00009F4F9C0883921F080E00E94277D87CFA1
:10FBE00083E00E94277D83CF84E10E94467D0E94AE
:10FBF0000E7D7DCF85E00E94467DF9CF0E94D87CA6
:10FC0000809306020E94D87C8093050280910802AE
:10FC10008E7F809308020E94D87C853409F44BC003
:10FC2000E5E0F1E0119281E0E438F807D9F3D0F390
:10FC3000C0E0D0E0809105029091060218161906E6
:10FC400078F405E011E00E94D87CF80181938F01DF
:10FC500021968091050290910602C817D90798F362
:10FC60000E94D87C803209F06DCF8091080280FF1D
:10FC7000B6C0C0E0D0E02091050230910602121615
:10FC80001306B8F4E0910301F0910401A5E0B1E09E
:10FC9000F999FECFF2BDE1BD8D9180BDFA9AF99A36
:10FCA00031962196C217D30798F3F0930401E0939D
:10FCB000030184E175CF809108028160809308027E
:10FCC000AFCF84E00E94467D80E087CF0E94D87C41
:10FCD000809303010E94D87C809304010E940E7DD2
:10FCE00006CF0E94D87C803209F02CCF84E10E949C
:10FCF000067D8EE10E94067D86E90E94067D8AE0EF
:10FD00004FCF0E940E7D88E080936000FFCF0E945D
:10FD1000D87C809306020E94D87C809305020E94C2
:10FD2000D87C853409F449C0809108028E7F809385
:10FD300008028091030190910401880F991F90930C
:10FD40000401809303010E94D87C803209F0CFCE59
:10FD500084E10E94067DC0E0D0E020910502309150
:10FD600006021216130608F01DCFE0910301F09170
:10FD700004018091080280FF96C0F999FECFF2BD80
:10FD8000E1BDF89A80B50E94067DE0910301F091F3
:10FD900004013196F0930401E093030120910502E0
:10FDA000309106022196C217D30718F3FBCEE091DB
:10FDB0000001F0910101099586CE809108028160D1
:10FDC00080930802C0CF80E10E94277D90CE81E021
:10FDD0000E94277D8CCE82E00E94277D88CE809174
:10FDE000030190910401880F991F9093040180935F
:10FDF00003018091050280FF09C080910502909166
:10FE0000060201969093060280930502F999FECFAF
:10FE10001127E0910301F0910401C5E0D1E0809148
:10FE2000050290910602103091F400915700017084
:10FE30000130D9F303E000935700E8950091570093
:10FE400001700130D9F301E100935700E895099062
:10FE500019900091570001700130D9F301E000932F
:10FE60005700E8951395103898F011270091570026
:10FE700001700130D9F305E000935700E895009137
:10FE8000570001700130D9F301E100935700E89564
:10FE90003296029709F0C7CF103011F00296E5CFE5
:10FEA000112484E17DCE869580FF06C03196F093C3
:10FEB0000401E093030176CF84910E94067D209196
:10FEC000050230910602E0910301F0910401EECFAA
:10FED0001F93CF930E94D87CC82F0E94067D0E945A
:10FEE000D87C182F0E94067DC1362CF0C7551136DC
:10FEF0003CF0175508C0C033D4F3C0531136CCF7CB
:10FF000010330CF01053C295C07FC10F8C2F99276E
:10FF100087FD9095CF911F910895CF93282F992712
:10FF200087FD9095807F907095958795959587959D
:10FF300095958795959587958A303CF0895AC22F7B
:10FF4000CF70CA303CF0C95A06C0805DC22FCF7056
:10FF5000CA30CCF7C05D0E94067D8C2F0E94067DC2
:06FF6000CF910895FFCFD0
:040000030000F80001
:00000001FF

View File

@ -0,0 +1,56 @@
# Makefile for ATmegaBOOT
# E.Lins, 18.7.2005
# $Id$
# program name should not be changed...
PROGRAM = ATmegaBOOT_644P
# enter the target CPU frequency
AVR_FREQ = 16000000L
MCU_TARGET = atmega644p
LDSECTION = --section-start=.text=0xF800
OBJ = $(PROGRAM).o
OPTIMIZE = -O2
DEFS =
LIBS =
CC = avr-gcc
# Override is only needed by avr-lib build system.
override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -DF_CPU=$(AVR_FREQ) $(DEFS)
override LDFLAGS = -Wl,$(LDSECTION)
#override LDFLAGS = -Wl,-Map,$(PROGRAM).map,$(LDSECTION)
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
all: CFLAGS += '-DMAX_TIME_COUNT=8000000L>>1' -DADABOOT
all: $(PROGRAM).hex
$(PROGRAM).hex: $(PROGRAM).elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
$(PROGRAM).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
$(OBJ): ATmegaBOOT.c
avr-gcc $(CFLAGS) $(LDFLAGS) -c -g -O2 -Wall -mmcu=$(MCU_TARGET) ATmegaBOOT.c -o $(PROGRAM).o
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
%.srec: %.elf
$(OBJCOPY) -j .text -j .data -O srec $< $@
%.bin: %.elf
$(OBJCOPY) -j .text -j .data -O binary $< $@
clean:
rm -rf *.o *.elf *.lst *.map *.sym *.lss *.eep *.srec *.bin *.hex

View File

@ -0,0 +1,3 @@
Note: This bootloader support ATmega644, ATmega644P and ATmega324P.
To build, set PROGRAM and MCU_TARGET in the Makefile according to your target device.

View File

@ -0,0 +1,303 @@
/*
HardwareSerial.cpp - Hardware serial library for Wiring
Copyright (c) 2006 Nicholas Zambetti. 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
Modified 23 November 2006 by David A. Mellis
Modified 28 September 2010 by Mark Sproul
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include "wiring.h"
#include "wiring_private.h"
// this next line disables the entire HardwareSerial.cpp,
// this is so I can support Attiny series and any other chip without a uart
#if defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H)
#include "HardwareSerial.h"
// Define constants and variables for buffering incoming serial data. We're
// using a ring buffer (I think), in which rx_buffer_head is the index of the
// location to which to write the next incoming character and rx_buffer_tail
// is the index of the location from which to read.
#if (RAMEND < 1000)
#define RX_BUFFER_SIZE 32
#else
#define RX_BUFFER_SIZE 128
#endif
struct ring_buffer
{
unsigned char buffer[RX_BUFFER_SIZE];
int head;
int tail;
};
#if defined(UBRRH) || defined(UBRR0H)
ring_buffer rx_buffer = { { 0 }, 0, 0 };
#endif
#if defined(UBRR1H)
ring_buffer rx_buffer1 = { { 0 }, 0, 0 };
#endif
#if defined(UBRR2H)
ring_buffer rx_buffer2 = { { 0 }, 0, 0 };
#endif
#if defined(UBRR3H)
ring_buffer rx_buffer3 = { { 0 }, 0, 0 };
#endif
inline void store_char(unsigned char c, ring_buffer *rx_buffer)
{
int i = (unsigned int)(rx_buffer->head + 1) % RX_BUFFER_SIZE;
// if we should be storing the received character into the location
// just before the tail (meaning that the head would advance to the
// current location of the tail), we're about to overflow the buffer
// and so we don't write the character or advance the head.
if (i != rx_buffer->tail) {
rx_buffer->buffer[rx_buffer->head] = c;
rx_buffer->head = i;
}
}
#if defined(USART_RX_vect)
SIGNAL(USART_RX_vect)
{
#if defined(UDR0)
unsigned char c = UDR0;
#elif defined(UDR)
unsigned char c = UDR; // atmega8535
#else
#error UDR not defined
#endif
store_char(c, &rx_buffer);
}
#elif defined(SIG_USART0_RECV) && defined(UDR0)
SIGNAL(SIG_USART0_RECV)
{
unsigned char c = UDR0;
store_char(c, &rx_buffer);
}
#elif defined(SIG_UART0_RECV) && defined(UDR0)
SIGNAL(SIG_UART0_RECV)
{
unsigned char c = UDR0;
store_char(c, &rx_buffer);
}
//#elif defined(SIG_USART_RECV)
#elif defined(USART0_RX_vect)
// fixed by Mark Sproul this is on the 644/644p
//SIGNAL(SIG_USART_RECV)
SIGNAL(USART0_RX_vect)
{
#if defined(UDR0)
unsigned char c = UDR0;
#elif defined(UDR)
unsigned char c = UDR; // atmega8, atmega32
#else
#error UDR not defined
#endif
store_char(c, &rx_buffer);
}
#elif defined(SIG_UART_RECV)
// this is for atmega8
SIGNAL(SIG_UART_RECV)
{
#if defined(UDR0)
unsigned char c = UDR0; // atmega645
#elif defined(UDR)
unsigned char c = UDR; // atmega8
#endif
store_char(c, &rx_buffer);
}
#elif defined(USBCON)
#warning No interrupt handler for usart 0
#warning Serial(0) is on USB interface
#else
#error No interrupt handler for usart 0
#endif
//#if defined(SIG_USART1_RECV)
#if defined(USART1_RX_vect)
//SIGNAL(SIG_USART1_RECV)
SIGNAL(USART1_RX_vect)
{
unsigned char c = UDR1;
store_char(c, &rx_buffer1);
}
#elif defined(SIG_USART1_RECV)
#error SIG_USART1_RECV
#endif
#if defined(USART2_RX_vect) && defined(UDR2)
SIGNAL(USART2_RX_vect)
{
unsigned char c = UDR2;
store_char(c, &rx_buffer2);
}
#elif defined(SIG_USART2_RECV)
#error SIG_USART2_RECV
#endif
#if defined(USART3_RX_vect) && defined(UDR3)
SIGNAL(USART3_RX_vect)
{
unsigned char c = UDR3;
store_char(c, &rx_buffer3);
}
#elif defined(SIG_USART3_RECV)
#error SIG_USART3_RECV
#endif
// Constructors ////////////////////////////////////////////////////////////////
HardwareSerial::HardwareSerial(ring_buffer *rx_buffer,
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
volatile uint8_t *udr,
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x)
{
_rx_buffer = rx_buffer;
_ubrrh = ubrrh;
_ubrrl = ubrrl;
_ucsra = ucsra;
_ucsrb = ucsrb;
_udr = udr;
_rxen = rxen;
_txen = txen;
_rxcie = rxcie;
_udre = udre;
_u2x = u2x;
}
// Public Methods //////////////////////////////////////////////////////////////
void HardwareSerial::begin(long baud)
{
uint16_t baud_setting;
bool use_u2x = true;
#if F_CPU == 16000000UL
// hardcoded exception for compatibility with the bootloader shipped
// with the Duemilanove and previous boards and the firmware on the 8U2
// on the Uno and Mega 2560.
if (baud == 57600) {
use_u2x = false;
}
#endif
if (use_u2x) {
*_ucsra = 1 << _u2x;
baud_setting = (F_CPU / 4 / baud - 1) / 2;
} else {
*_ucsra = 0;
baud_setting = (F_CPU / 8 / baud - 1) / 2;
}
// assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
*_ubrrh = baud_setting >> 8;
*_ubrrl = baud_setting;
sbi(*_ucsrb, _rxen);
sbi(*_ucsrb, _txen);
sbi(*_ucsrb, _rxcie);
}
void HardwareSerial::end()
{
cbi(*_ucsrb, _rxen);
cbi(*_ucsrb, _txen);
cbi(*_ucsrb, _rxcie);
}
int HardwareSerial::available(void)
{
return (unsigned int)(RX_BUFFER_SIZE + _rx_buffer->head - _rx_buffer->tail) % RX_BUFFER_SIZE;
}
int HardwareSerial::peek(void)
{
if (_rx_buffer->head == _rx_buffer->tail) {
return -1;
} else {
return _rx_buffer->buffer[_rx_buffer->tail];
}
}
int HardwareSerial::read(void)
{
// if the head isn't ahead of the tail, we don't have any characters
if (_rx_buffer->head == _rx_buffer->tail) {
return -1;
} else {
unsigned char c = _rx_buffer->buffer[_rx_buffer->tail];
_rx_buffer->tail = (unsigned int)(_rx_buffer->tail + 1) % RX_BUFFER_SIZE;
return c;
}
}
void HardwareSerial::flush()
{
// don't reverse this or there may be problems if the RX interrupt
// occurs after reading the value of rx_buffer_head but before writing
// the value to rx_buffer_tail; the previous value of rx_buffer_head
// may be written to rx_buffer_tail, making it appear as if the buffer
// don't reverse this or there may be problems if the RX interrupt
// occurs after reading the value of rx_buffer_head but before writing
// the value to rx_buffer_tail; the previous value of rx_buffer_head
// may be written to rx_buffer_tail, making it appear as if the buffer
// were full, not empty.
_rx_buffer->head = _rx_buffer->tail;
}
void HardwareSerial::write(uint8_t c)
{
while (!((*_ucsra) & (1 << _udre)))
;
*_udr = c;
}
// Preinstantiate Objects //////////////////////////////////////////////////////
#if defined(UBRRH) && defined(UBRRL)
HardwareSerial Serial(&rx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UDR, RXEN, TXEN, RXCIE, UDRE, U2X);
#elif defined(UBRR0H) && defined(UBRR0L)
HardwareSerial Serial(&rx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRE0, U2X0);
#elif defined(USBCON)
#warning no serial port defined (port 0)
#else
#error no serial port defined (port 0)
#endif
#if defined(UBRR1H)
HardwareSerial Serial1(&rx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRE1, U2X1);
#endif
#if defined(UBRR2H)
HardwareSerial Serial2(&rx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UDR2, RXEN2, TXEN2, RXCIE2, UDRE2, U2X2);
#endif
#if defined(UBRR3H)
HardwareSerial Serial3(&rx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UDR3, RXEN3, TXEN3, RXCIE3, UDRE3, U2X3);
#endif
#endif // whole file

View File

@ -0,0 +1,76 @@
/*
HardwareSerial.h - Hardware serial library for Wiring
Copyright (c) 2006 Nicholas Zambetti. 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
Modified 28 September 2010 by Mark Sproul
*/
#ifndef HardwareSerial_h
#define HardwareSerial_h
#include <inttypes.h>
#include "Stream.h"
struct ring_buffer;
class HardwareSerial : public Stream
{
private:
ring_buffer *_rx_buffer;
volatile uint8_t *_ubrrh;
volatile uint8_t *_ubrrl;
volatile uint8_t *_ucsra;
volatile uint8_t *_ucsrb;
volatile uint8_t *_udr;
uint8_t _rxen;
uint8_t _txen;
uint8_t _rxcie;
uint8_t _udre;
uint8_t _u2x;
public:
HardwareSerial(ring_buffer *rx_buffer,
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
volatile uint8_t *udr,
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udre, uint8_t u2x);
void begin(long);
void end();
virtual int available(void);
virtual int peek(void);
virtual int read(void);
virtual void flush(void);
virtual void write(uint8_t);
using Print::write; // pull in write(str) and write(buf, size) from Print
};
#if defined(UBRRH) || defined(UBRR0H)
extern HardwareSerial Serial;
#elif defined(USBCON)
#include "usb_api.h"
#endif
#if defined(UBRR1H)
extern HardwareSerial Serial1;
#endif
#if defined(UBRR2H)
extern HardwareSerial Serial2;
#endif
#if defined(UBRR3H)
extern HardwareSerial Serial3;
#endif
#endif

View File

@ -0,0 +1,220 @@
/*
Print.cpp - Base class that provides print() and println()
Copyright (c) 2008 David A. Mellis. 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
Modified 23 November 2006 by David A. Mellis
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "wiring.h"
#include "Print.h"
// Public Methods //////////////////////////////////////////////////////////////
/* default implementation: may be overridden */
void Print::write(const char *str)
{
while (*str)
write(*str++);
}
/* default implementation: may be overridden */
void Print::write(const uint8_t *buffer, size_t size)
{
while (size--)
write(*buffer++);
}
void Print::print(const String &s)
{
for (int i = 0; i < s.length(); i++) {
write(s[i]);
}
}
void Print::print(const char str[])
{
write(str);
}
void Print::print(char c, int base)
{
print((long) c, base);
}
void Print::print(unsigned char b, int base)
{
print((unsigned long) b, base);
}
void Print::print(int n, int base)
{
print((long) n, base);
}
void Print::print(unsigned int n, int base)
{
print((unsigned long) n, base);
}
void Print::print(long n, int base)
{
if (base == 0) {
write(n);
} else if (base == 10) {
if (n < 0) {
print('-');
n = -n;
}
printNumber(n, 10);
} else {
printNumber(n, base);
}
}
void Print::print(unsigned long n, int base)
{
if (base == 0) write(n);
else printNumber(n, base);
}
void Print::print(double n, int digits)
{
printFloat(n, digits);
}
void Print::println(void)
{
print('\r');
print('\n');
}
void Print::println(const String &s)
{
print(s);
println();
}
void Print::println(const char c[])
{
print(c);
println();
}
void Print::println(char c, int base)
{
print(c, base);
println();
}
void Print::println(unsigned char b, int base)
{
print(b, base);
println();
}
void Print::println(int n, int base)
{
print(n, base);
println();
}
void Print::println(unsigned int n, int base)
{
print(n, base);
println();
}
void Print::println(long n, int base)
{
print(n, base);
println();
}
void Print::println(unsigned long n, int base)
{
print(n, base);
println();
}
void Print::println(double n, int digits)
{
print(n, digits);
println();
}
// Private Methods /////////////////////////////////////////////////////////////
void Print::printNumber(unsigned long n, uint8_t base)
{
unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars.
unsigned long i = 0;
if (n == 0) {
print('0');
return;
}
while (n > 0) {
buf[i++] = n % base;
n /= base;
}
for (; i > 0; i--)
print((char) (buf[i - 1] < 10 ?
'0' + buf[i - 1] :
'A' + buf[i - 1] - 10));
}
void Print::printFloat(double number, uint8_t digits)
{
// Handle negative numbers
if (number < 0.0)
{
print('-');
number = -number;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i)
rounding /= 10.0;
number += rounding;
// Extract the integer part of the number and print it
unsigned long int_part = (unsigned long)number;
double remainder = number - (double)int_part;
print(int_part);
// Print the decimal point, but only if there are digits beyond
if (digits > 0)
print(".");
// Extract digits from the remainder one at a time
while (digits-- > 0)
{
remainder *= 10.0;
int toPrint = int(remainder);
print(toPrint);
remainder -= toPrint;
}
}

View File

@ -0,0 +1,66 @@
/*
Print.h - Base class that provides print() and println()
Copyright (c) 2008 David A. Mellis. 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 Print_h
#define Print_h
#include <inttypes.h>
#include <stdio.h> // for size_t
#include "WString.h"
#define DEC 10
#define HEX 16
#define OCT 8
#define BIN 2
#define BYTE 0
class Print
{
private:
void printNumber(unsigned long, uint8_t);
void printFloat(double, uint8_t);
public:
virtual void write(uint8_t) = 0;
virtual void write(const char *str);
virtual void write(const uint8_t *buffer, size_t size);
void print(const String &);
void print(const char[]);
void print(char, int = BYTE);
void print(unsigned char, int = BYTE);
void print(int, int = DEC);
void print(unsigned int, int = DEC);
void print(long, int = DEC);
void print(unsigned long, int = DEC);
void print(double, int = 2);
void println(const String &s);
void println(const char[]);
void println(char, int = BYTE);
void println(unsigned char, int = BYTE);
void println(int, int = DEC);
void println(unsigned int, int = DEC);
void println(long, int = DEC);
void println(unsigned long, int = DEC);
void println(double, int = 2);
void println(void);
};
#endif

View File

@ -0,0 +1,35 @@
/*
Stream.h - base class for character-based streams.
Copyright (c) 2010 David A. Mellis. 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 Stream_h
#define Stream_h
#include <inttypes.h>
#include "Print.h"
class Stream : public Print
{
public:
virtual int available() = 0;
virtual int read() = 0;
virtual int peek() = 0;
virtual void flush() = 0;
};
#endif

View File

@ -0,0 +1,601 @@
/* Tone.cpp
A Tone Generator Library
Written by Brett Hagman
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
Version Modified By Date Comments
------- ----------- -------- --------
0001 B Hagman 09/08/02 Initial coding
0002 B Hagman 09/08/18 Multiple pins
0003 B Hagman 09/08/18 Moved initialization from constructor to begin()
0004 B Hagman 09/09/26 Fixed problems with ATmega8
0005 B Hagman 09/11/23 Scanned prescalars for best fit on 8 bit timers
09/11/25 Changed pin toggle method to XOR
09/11/25 Fixed timer0 from being excluded
0006 D Mellis 09/12/29 Replaced objects with functions
0007 M Sproul 10/08/29 Changed #ifdefs from cpu to register
*************************************************/
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include "wiring.h"
#include "pins_arduino.h"
#if defined(__AVR_ATmega8__) || defined(__AVR_ATmega128__)
#define TCCR2A TCCR2
#define TCCR2B TCCR2
#define COM2A1 COM21
#define COM2A0 COM20
#define OCR2A OCR2
#define TIMSK2 TIMSK
#define OCIE2A OCIE2
#define TIMER2_COMPA_vect TIMER2_COMP_vect
#define TIMSK1 TIMSK
#endif
// timerx_toggle_count:
// > 0 - duration specified
// = 0 - stopped
// < 0 - infinitely (until stop() method called, or new play() called)
#if !defined(__AVR_ATmega8__)
volatile long timer0_toggle_count;
volatile uint8_t *timer0_pin_port;
volatile uint8_t timer0_pin_mask;
#endif
volatile long timer1_toggle_count;
volatile uint8_t *timer1_pin_port;
volatile uint8_t timer1_pin_mask;
volatile long timer2_toggle_count;
volatile uint8_t *timer2_pin_port;
volatile uint8_t timer2_pin_mask;
#if defined(TIMSK3)
volatile long timer3_toggle_count;
volatile uint8_t *timer3_pin_port;
volatile uint8_t timer3_pin_mask;
#endif
#if defined(TIMSK4)
volatile long timer4_toggle_count;
volatile uint8_t *timer4_pin_port;
volatile uint8_t timer4_pin_mask;
#endif
#if defined(TIMSK5)
volatile long timer5_toggle_count;
volatile uint8_t *timer5_pin_port;
volatile uint8_t timer5_pin_mask;
#endif
// MLS: This does not make sense, the 3 options are the same
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define AVAILABLE_TONE_PINS 1
const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 3, 4, 5, 1, 0 */ };
static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255, 255, 255, 255, 255 */ };
#elif defined(__AVR_ATmega8__)
#define AVAILABLE_TONE_PINS 1
const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 1 */ };
static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255 */ };
#else
#define AVAILABLE_TONE_PINS 1
// Leave timer 0 to last.
const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 1, 0 */ };
static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255, 255 */ };
#endif
static int8_t toneBegin(uint8_t _pin)
{
int8_t _timer = -1;
// if we're already using the pin, the timer should be configured.
for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
if (tone_pins[i] == _pin) {
return pgm_read_byte(tone_pin_to_timer_PGM + i);
}
}
// search for an unused timer.
for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
if (tone_pins[i] == 255) {
tone_pins[i] = _pin;
_timer = pgm_read_byte(tone_pin_to_timer_PGM + i);
break;
}
}
if (_timer != -1)
{
// Set timer specific stuff
// All timers in CTC mode
// 8 bit timers will require changing prescalar values,
// whereas 16 bit timers are set to either ck/1 or ck/64 prescalar
switch (_timer)
{
#if defined(TCCR0A) && defined(TCCR0B)
case 0:
// 8 bit timer
TCCR0A = 0;
TCCR0B = 0;
bitWrite(TCCR0A, WGM01, 1);
bitWrite(TCCR0B, CS00, 1);
timer0_pin_port = portOutputRegister(digitalPinToPort(_pin));
timer0_pin_mask = digitalPinToBitMask(_pin);
break;
#endif
#if defined(TCCR1A) && defined(TCCR1B) && defined(WGM12)
case 1:
// 16 bit timer
TCCR1A = 0;
TCCR1B = 0;
bitWrite(TCCR1B, WGM12, 1);
bitWrite(TCCR1B, CS10, 1);
timer1_pin_port = portOutputRegister(digitalPinToPort(_pin));
timer1_pin_mask = digitalPinToBitMask(_pin);
break;
#endif
#if defined(TCCR2A) && defined(TCCR2B)
case 2:
// 8 bit timer
TCCR2A = 0;
TCCR2B = 0;
bitWrite(TCCR2A, WGM21, 1);
bitWrite(TCCR2B, CS20, 1);
timer2_pin_port = portOutputRegister(digitalPinToPort(_pin));
timer2_pin_mask = digitalPinToBitMask(_pin);
break;
#endif
#if defined(TCCR3A) && defined(TCCR3B) && defined(TIMSK3)
case 3:
// 16 bit timer
TCCR3A = 0;
TCCR3B = 0;
bitWrite(TCCR3B, WGM32, 1);
bitWrite(TCCR3B, CS30, 1);
timer3_pin_port = portOutputRegister(digitalPinToPort(_pin));
timer3_pin_mask = digitalPinToBitMask(_pin);
break;
#endif
#if defined(TCCR4A) && defined(TCCR4B) && defined(TIMSK4)
case 4:
// 16 bit timer
TCCR4A = 0;
TCCR4B = 0;
#if defined(WGM42)
bitWrite(TCCR4B, WGM42, 1);
#elif defined(CS43)
#warning this may not be correct
// atmega32u4
bitWrite(TCCR4B, CS43, 1);
#endif
bitWrite(TCCR4B, CS40, 1);
timer4_pin_port = portOutputRegister(digitalPinToPort(_pin));
timer4_pin_mask = digitalPinToBitMask(_pin);
break;
#endif
#if defined(TCCR5A) && defined(TCCR5B) && defined(TIMSK5)
case 5:
// 16 bit timer
TCCR5A = 0;
TCCR5B = 0;
bitWrite(TCCR5B, WGM52, 1);
bitWrite(TCCR5B, CS50, 1);
timer5_pin_port = portOutputRegister(digitalPinToPort(_pin));
timer5_pin_mask = digitalPinToBitMask(_pin);
break;
#endif
}
}
return _timer;
}
// frequency (in hertz) and duration (in milliseconds).
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration)
{
uint8_t prescalarbits = 0b001;
long toggle_count = 0;
uint32_t ocr = 0;
int8_t _timer;
_timer = toneBegin(_pin);
if (_timer >= 0)
{
// Set the pinMode as OUTPUT
pinMode(_pin, OUTPUT);
// if we are using an 8 bit timer, scan through prescalars to find the best fit
if (_timer == 0 || _timer == 2)
{
ocr = F_CPU / frequency / 2 - 1;
prescalarbits = 0b001; // ck/1: same for both timers
if (ocr > 255)
{
ocr = F_CPU / frequency / 2 / 8 - 1;
prescalarbits = 0b010; // ck/8: same for both timers
if (_timer == 2 && ocr > 255)
{
ocr = F_CPU / frequency / 2 / 32 - 1;
prescalarbits = 0b011;
}
if (ocr > 255)
{
ocr = F_CPU / frequency / 2 / 64 - 1;
prescalarbits = _timer == 0 ? 0b011 : 0b100;
if (_timer == 2 && ocr > 255)
{
ocr = F_CPU / frequency / 2 / 128 - 1;
prescalarbits = 0b101;
}
if (ocr > 255)
{
ocr = F_CPU / frequency / 2 / 256 - 1;
prescalarbits = _timer == 0 ? 0b100 : 0b110;
if (ocr > 255)
{
// can't do any better than /1024
ocr = F_CPU / frequency / 2 / 1024 - 1;
prescalarbits = _timer == 0 ? 0b101 : 0b111;
}
}
}
}
#if defined(TCCR0B)
if (_timer == 0)
{
TCCR0B = prescalarbits;
}
else
#endif
#if defined(TCCR2B)
{
TCCR2B = prescalarbits;
}
#else
{
// dummy place holder to make the above ifdefs work
}
#endif
}
else
{
// two choices for the 16 bit timers: ck/1 or ck/64
ocr = F_CPU / frequency / 2 - 1;
prescalarbits = 0b001;
if (ocr > 0xffff)
{
ocr = F_CPU / frequency / 2 / 64 - 1;
prescalarbits = 0b011;
}
if (_timer == 1)
{
#if defined(TCCR1B)
TCCR1B = (TCCR1B & 0b11111000) | prescalarbits;
#endif
}
#if defined(TCCR3B)
else if (_timer == 3)
TCCR3B = (TCCR3B & 0b11111000) | prescalarbits;
#endif
#if defined(TCCR4B)
else if (_timer == 4)
TCCR4B = (TCCR4B & 0b11111000) | prescalarbits;
#endif
#if defined(TCCR5B)
else if (_timer == 5)
TCCR5B = (TCCR5B & 0b11111000) | prescalarbits;
#endif
}
// Calculate the toggle count
if (duration > 0)
{
toggle_count = 2 * frequency * duration / 1000;
}
else
{
toggle_count = -1;
}
// Set the OCR for the given timer,
// set the toggle count,
// then turn on the interrupts
switch (_timer)
{
#if defined(OCR0A) && defined(TIMSK0) && defined(OCIE0A)
case 0:
OCR0A = ocr;
timer0_toggle_count = toggle_count;
bitWrite(TIMSK0, OCIE0A, 1);
break;
#endif
case 1:
#if defined(OCR1A) && defined(TIMSK1) && defined(OCIE1A)
OCR1A = ocr;
timer1_toggle_count = toggle_count;
bitWrite(TIMSK1, OCIE1A, 1);
#elif defined(OCR1A) && defined(TIMSK) && defined(OCIE1A)
// this combination is for at least the ATmega32
OCR1A = ocr;
timer1_toggle_count = toggle_count;
bitWrite(TIMSK, OCIE1A, 1);
#endif
break;
#if defined(OCR2A) && defined(TIMSK2) && defined(OCIE2A)
case 2:
OCR2A = ocr;
timer2_toggle_count = toggle_count;
bitWrite(TIMSK2, OCIE2A, 1);
break;
#endif
#if defined(TIMSK3)
case 3:
OCR3A = ocr;
timer3_toggle_count = toggle_count;
bitWrite(TIMSK3, OCIE3A, 1);
break;
#endif
#if defined(TIMSK4)
case 4:
OCR4A = ocr;
timer4_toggle_count = toggle_count;
bitWrite(TIMSK4, OCIE4A, 1);
break;
#endif
#if defined(OCR5A) && defined(TIMSK5) && defined(OCIE5A)
case 5:
OCR5A = ocr;
timer5_toggle_count = toggle_count;
bitWrite(TIMSK5, OCIE5A, 1);
break;
#endif
}
}
}
// XXX: this function only works properly for timer 2 (the only one we use
// currently). for the others, it should end the tone, but won't restore
// proper PWM functionality for the timer.
void disableTimer(uint8_t _timer)
{
switch (_timer)
{
case 0:
#if defined(TIMSK0)
TIMSK0 = 0;
#elif defined(TIMSK)
TIMSK = 0; // atmega32
#endif
break;
#if defined(TIMSK1) && defined(OCIE1A)
case 1:
bitWrite(TIMSK1, OCIE1A, 0);
break;
#endif
case 2:
#if defined(TIMSK2) && defined(OCIE2A)
bitWrite(TIMSK2, OCIE2A, 0); // disable interrupt
#endif
#if defined(TCCR2A) && defined(WGM20)
TCCR2A = (1 << WGM20);
#endif
#if defined(TCCR2B) && defined(CS22)
TCCR2B = (TCCR2B & 0b11111000) | (1 << CS22);
#endif
#if defined(OCR2A)
OCR2A = 0;
#endif
break;
#if defined(TIMSK3)
case 3:
TIMSK3 = 0;
break;
#endif
#if defined(TIMSK4)
case 4:
TIMSK4 = 0;
break;
#endif
#if defined(TIMSK5)
case 5:
TIMSK5 = 0;
break;
#endif
}
}
void noTone(uint8_t _pin)
{
int8_t _timer = -1;
for (int i = 0; i < AVAILABLE_TONE_PINS; i++) {
if (tone_pins[i] == _pin) {
_timer = pgm_read_byte(tone_pin_to_timer_PGM + i);
tone_pins[i] = 255;
}
}
disableTimer(_timer);
digitalWrite(_pin, 0);
}
#if 0
#if !defined(__AVR_ATmega8__)
ISR(TIMER0_COMPA_vect)
{
if (timer0_toggle_count != 0)
{
// toggle the pin
*timer0_pin_port ^= timer0_pin_mask;
if (timer0_toggle_count > 0)
timer0_toggle_count--;
}
else
{
disableTimer(0);
*timer0_pin_port &= ~(timer0_pin_mask); // keep pin low after stop
}
}
#endif
ISR(TIMER1_COMPA_vect)
{
if (timer1_toggle_count != 0)
{
// toggle the pin
*timer1_pin_port ^= timer1_pin_mask;
if (timer1_toggle_count > 0)
timer1_toggle_count--;
}
else
{
disableTimer(1);
*timer1_pin_port &= ~(timer1_pin_mask); // keep pin low after stop
}
}
#endif
ISR(TIMER2_COMPA_vect)
{
if (timer2_toggle_count != 0)
{
// toggle the pin
*timer2_pin_port ^= timer2_pin_mask;
if (timer2_toggle_count > 0)
timer2_toggle_count--;
}
else
{
// need to call noTone() so that the tone_pins[] entry is reset, so the
// timer gets initialized next time we call tone().
// XXX: this assumes timer 2 is always the first one used.
noTone(tone_pins[0]);
// disableTimer(2);
// *timer2_pin_port &= ~(timer2_pin_mask); // keep pin low after stop
}
}
//#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#if 0
ISR(TIMER3_COMPA_vect)
{
if (timer3_toggle_count != 0)
{
// toggle the pin
*timer3_pin_port ^= timer3_pin_mask;
if (timer3_toggle_count > 0)
timer3_toggle_count--;
}
else
{
disableTimer(3);
*timer3_pin_port &= ~(timer3_pin_mask); // keep pin low after stop
}
}
ISR(TIMER4_COMPA_vect)
{
if (timer4_toggle_count != 0)
{
// toggle the pin
*timer4_pin_port ^= timer4_pin_mask;
if (timer4_toggle_count > 0)
timer4_toggle_count--;
}
else
{
disableTimer(4);
*timer4_pin_port &= ~(timer4_pin_mask); // keep pin low after stop
}
}
ISR(TIMER5_COMPA_vect)
{
if (timer5_toggle_count != 0)
{
// toggle the pin
*timer5_pin_port ^= timer5_pin_mask;
if (timer5_toggle_count > 0)
timer5_toggle_count--;
}
else
{
disableTimer(5);
*timer5_pin_port &= ~(timer5_pin_mask); // keep pin low after stop
}
}
#endif

View File

@ -0,0 +1,168 @@
/*
WCharacter.h - Character utility functions for Wiring & Arduino
Copyright (c) 2010 Hernando Barragan. 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 Character_h
#define Character_h
#include <ctype.h>
// WCharacter.h prototypes
inline boolean isAlphaNumeric(int c) __attribute__((always_inline));
inline boolean isAlpha(int c) __attribute__((always_inline));
inline boolean isAscii(int c) __attribute__((always_inline));
inline boolean isWhitespace(int c) __attribute__((always_inline));
inline boolean isControl(int c) __attribute__((always_inline));
inline boolean isDigit(int c) __attribute__((always_inline));
inline boolean isGraph(int c) __attribute__((always_inline));
inline boolean isLowerCase(int c) __attribute__((always_inline));
inline boolean isPrintable(int c) __attribute__((always_inline));
inline boolean isPunct(int c) __attribute__((always_inline));
inline boolean isSpace(int c) __attribute__((always_inline));
inline boolean isUpperCase(int c) __attribute__((always_inline));
inline boolean isHexadecimalDigit(int c) __attribute__((always_inline));
inline int toAscii(int c) __attribute__((always_inline));
inline int toLowerCase(int c) __attribute__((always_inline));
inline int toUpperCase(int c)__attribute__((always_inline));
// Checks for an alphanumeric character.
// It is equivalent to (isalpha(c) || isdigit(c)).
inline boolean isAlphaNumeric(int c)
{
return ( isalnum(c) == 0 ? false : true);
}
// Checks for an alphabetic character.
// It is equivalent to (isupper(c) || islower(c)).
inline boolean isAlpha(int c)
{
return ( isalpha(c) == 0 ? false : true);
}
// Checks whether c is a 7-bit unsigned char value
// that fits into the ASCII character set.
inline boolean isAscii(int c)
{
return ( isascii (c) == 0 ? false : true);
}
// Checks for a blank character, that is, a space or a tab.
inline boolean isWhitespace(int c)
{
return ( isblank (c) == 0 ? false : true);
}
// Checks for a control character.
inline boolean isControl(int c)
{
return ( iscntrl (c) == 0 ? false : true);
}
// Checks for a digit (0 through 9).
inline boolean isDigit(int c)
{
return ( isdigit (c) == 0 ? false : true);
}
// Checks for any printable character except space.
inline boolean isGraph(int c)
{
return ( isgraph (c) == 0 ? false : true);
}
// Checks for a lower-case character.
inline boolean isLowerCase(int c)
{
return (islower (c) == 0 ? false : true);
}
// Checks for any printable character including space.
inline boolean isPrintable(int c)
{
return ( isprint (c) == 0 ? false : true);
}
// Checks for any printable character which is not a space
// or an alphanumeric character.
inline boolean isPunct(int c)
{
return ( ispunct (c) == 0 ? false : true);
}
// Checks for white-space characters. For the avr-libc library,
// these are: space, formfeed ('\f'), newline ('\n'), carriage
// return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').
inline boolean isSpace(int c)
{
return ( isspace (c) == 0 ? false : true);
}
// Checks for an uppercase letter.
inline boolean isUpperCase(int c)
{
return ( isupper (c) == 0 ? false : true);
}
// Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7
// 8 9 a b c d e f A B C D E F.
inline boolean isHexadecimalDigit(int c)
{
return ( isxdigit (c) == 0 ? false : true);
}
// Converts c to a 7-bit unsigned char value that fits into the
// ASCII character set, by clearing the high-order bits.
inline int toAscii(int c)
{
return toascii (c);
}
// Warning:
// Many people will be unhappy if you use this function.
// This function will convert accented letters into random
// characters.
// Converts the letter c to lower case, if possible.
inline int toLowerCase(int c)
{
return tolower (c);
}
// Converts the letter c to upper case, if possible.
inline int toUpperCase(int c)
{
return toupper (c);
}
#endif

View File

@ -0,0 +1 @@
#include "wiring.h"

View File

@ -0,0 +1,280 @@
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Wiring project - http://wiring.uniandes.edu.co
Copyright (c) 2004-05 Hernando Barragan
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
Modified 24 November 2006 by David A. Mellis
Modified 1 August 2010 by Mark Sproul
*/
#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include "WConstants.h"
#include "wiring_private.h"
volatile static voidFuncPtr intFunc[EXTERNAL_NUM_INTERRUPTS];
// volatile static voidFuncPtr twiIntFunc;
void attachInterrupt(uint8_t interruptNum, void (*userFunc)(void), int mode) {
if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
intFunc[interruptNum] = userFunc;
// Configure the interrupt mode (trigger on low input, any change, rising
// edge, or falling edge). The mode constants were chosen to correspond
// to the configuration bits in the hardware register, so we simply shift
// the mode into place.
// Enable the interrupt.
switch (interruptNum) {
#if defined(EICRA) && defined(EICRB) && defined(EIMSK)
case 2:
EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
EIMSK |= (1 << INT0);
break;
case 3:
EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
EIMSK |= (1 << INT1);
break;
case 4:
EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
EIMSK |= (1 << INT2);
break;
case 5:
EICRA = (EICRA & ~((1 << ISC30) | (1 << ISC31))) | (mode << ISC30);
EIMSK |= (1 << INT3);
break;
case 0:
EICRB = (EICRB & ~((1 << ISC40) | (1 << ISC41))) | (mode << ISC40);
EIMSK |= (1 << INT4);
break;
case 1:
EICRB = (EICRB & ~((1 << ISC50) | (1 << ISC51))) | (mode << ISC50);
EIMSK |= (1 << INT5);
break;
case 6:
EICRB = (EICRB & ~((1 << ISC60) | (1 << ISC61))) | (mode << ISC60);
EIMSK |= (1 << INT6);
break;
case 7:
EICRB = (EICRB & ~((1 << ISC70) | (1 << ISC71))) | (mode << ISC70);
EIMSK |= (1 << INT7);
break;
#elif defined(EICRA) && defined(EIMSK)
case 0:
EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
EIMSK |= (1 << INT0);
break;
case 1:
EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
EIMSK |= (1 << INT1);
break;
case 2:
EICRA = (EICRA & ~((1 << ISC20) | (1 << ISC21))) | (mode << ISC20);
EIMSK |= (1 << INT2);
break;
#else
case 0:
#if defined(EICRA) && defined(ISC00) && defined(EIMSK)
EICRA = (EICRA & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
EIMSK |= (1 << INT0);
#elif defined(MCUCR) && defined(ISC00) && defined(GICR)
MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
GICR |= (1 << INT0);
#elif defined(MCUCR) && defined(ISC00) && defined(GIMSK)
MCUCR = (MCUCR & ~((1 << ISC00) | (1 << ISC01))) | (mode << ISC00);
GIMSK |= (1 << INT0);
#else
#error attachInterrupt not finished for this CPU (case 0)
#endif
break;
case 1:
#if defined(EICRA) && defined(ISC10) && defined(ISC11) && defined(EIMSK)
EICRA = (EICRA & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
EIMSK |= (1 << INT1);
#elif defined(MCUCR) && defined(ISC10) && defined(ISC11) && defined(GICR)
MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
GICR |= (1 << INT1);
#elif defined(MCUCR) && defined(ISC10) && defined(GIMSK) && defined(GIMSK)
MCUCR = (MCUCR & ~((1 << ISC10) | (1 << ISC11))) | (mode << ISC10);
GIMSK |= (1 << INT1);
#else
#warning attachInterrupt may need some more work for this cpu (case 1)
#endif
break;
#endif
}
}
}
void detachInterrupt(uint8_t interruptNum) {
if(interruptNum < EXTERNAL_NUM_INTERRUPTS) {
// Disable the interrupt. (We can't assume that interruptNum is equal
// to the number of the EIMSK bit to clear, as this isn't true on the
// ATmega8. There, INT0 is 6 and INT1 is 7.)
switch (interruptNum) {
#if defined(EICRA) && defined(EICRB) && defined(EIMSK)
case 5:
EIMSK &= ~(1 << INT3);
break;
case 0:
EIMSK &= ~(1 << INT4);
break;
case 1:
EIMSK &= ~(1 << INT5);
break;
case 6:
EIMSK &= ~(1 << INT6);
break;
case 7:
EIMSK &= ~(1 << INT7);
break;
#elif defined(EICRA) && defined(EIMSK)
case 0:
EIMSK &= ~(1 << INT0);
break;
case 1:
EIMSK &= ~(1 << INT1);
break;
case 2:
EIMSK &= ~(1 << INT2);
break;
#else
case 0:
#if defined(EIMSK) && defined(INT0)
EIMSK &= ~(1 << INT0);
#elif defined(GICR) && defined(ISC00)
GICR &= ~(1 << INT0); // atmega32
#elif defined(GIMSK) && defined(INT0)
GIMSK &= ~(1 << INT0);
#else
#error detachInterrupt not finished for this cpu
#endif
break;
case 1:
#if defined(EIMSK) && defined(INT1)
EIMSK &= ~(1 << INT1);
#elif defined(GICR) && defined(INT1)
GICR &= ~(1 << INT1); // atmega32
#elif defined(GIMSK) && defined(INT1)
GIMSK &= ~(1 << INT1);
#else
#warning detachInterrupt may need some more work for this cpu (case 1)
#endif
break;
#endif
}
intFunc[interruptNum] = 0;
}
}
/*
void attachInterruptTwi(void (*userFunc)(void) ) {
twiIntFunc = userFunc;
}
*/
#if defined(EICRA) && defined(EICRB)
SIGNAL(INT0_vect) {
if(intFunc[EXTERNAL_INT_2])
intFunc[EXTERNAL_INT_2]();
}
SIGNAL(INT1_vect) {
if(intFunc[EXTERNAL_INT_3])
intFunc[EXTERNAL_INT_3]();
}
SIGNAL(INT2_vect) {
if(intFunc[EXTERNAL_INT_4])
intFunc[EXTERNAL_INT_4]();
}
SIGNAL(INT3_vect) {
if(intFunc[EXTERNAL_INT_5])
intFunc[EXTERNAL_INT_5]();
}
SIGNAL(INT4_vect) {
if(intFunc[EXTERNAL_INT_0])
intFunc[EXTERNAL_INT_0]();
}
SIGNAL(INT5_vect) {
if(intFunc[EXTERNAL_INT_1])
intFunc[EXTERNAL_INT_1]();
}
SIGNAL(INT6_vect) {
if(intFunc[EXTERNAL_INT_6])
intFunc[EXTERNAL_INT_6]();
}
SIGNAL(INT7_vect) {
if(intFunc[EXTERNAL_INT_7])
intFunc[EXTERNAL_INT_7]();
}
#elif defined(EICRA)
SIGNAL(INT0_vect) {
if(intFunc[EXTERNAL_INT_0])
intFunc[EXTERNAL_INT_0]();
}
SIGNAL(INT1_vect) {
if(intFunc[EXTERNAL_INT_1])
intFunc[EXTERNAL_INT_1]();
}
SIGNAL(INT2_vect) {
if(intFunc[EXTERNAL_INT_2])
intFunc[EXTERNAL_INT_2]();
}
#else
SIGNAL(INT0_vect) {
if(intFunc[EXTERNAL_INT_0])
intFunc[EXTERNAL_INT_0]();
}
SIGNAL(INT1_vect) {
if(intFunc[EXTERNAL_INT_1])
intFunc[EXTERNAL_INT_1]();
}
#endif
/*
SIGNAL(SIG_2WIRE_SERIAL) {
if(twiIntFunc)
twiIntFunc();
}
*/

View File

@ -0,0 +1,60 @@
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Wiring project - http://wiring.org.co
Copyright (c) 2004-06 Hernando Barragan
Modified 13 August 2006, David A. Mellis for Arduino - http://www.arduino.cc/
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id$
*/
extern "C" {
#include "stdlib.h"
}
void randomSeed(unsigned int seed)
{
if (seed != 0) {
srandom(seed);
}
}
long random(long howbig)
{
if (howbig == 0) {
return 0;
}
return random() % howbig;
}
long random(long howsmall, long howbig)
{
if (howsmall >= howbig) {
return howsmall;
}
long diff = howbig - howsmall;
return random(diff) + howsmall;
}
long map(long x, long in_min, long in_max, long out_min, long out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
unsigned int makeWord(unsigned int w) { return w; }
unsigned int makeWord(unsigned char h, unsigned char l) { return (h << 8) | l; }

View File

@ -0,0 +1,63 @@
#ifndef WProgram_h
#define WProgram_h
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <avr/interrupt.h>
#include "wiring.h"
#ifdef __cplusplus
#include "WCharacter.h"
#include "WString.h"
#include "HardwareSerial.h"
uint16_t makeWord(uint16_t w);
uint16_t makeWord(byte h, byte l);
#define word(...) makeWord(__VA_ARGS__)
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L);
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0);
void noTone(uint8_t _pin);
// WMath prototypes
long random(long);
long random(long, long);
void randomSeed(unsigned int);
long map(long, long, long, long, long);
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
const static uint8_t A0 = 54;
const static uint8_t A1 = 55;
const static uint8_t A2 = 56;
const static uint8_t A3 = 57;
const static uint8_t A4 = 58;
const static uint8_t A5 = 59;
const static uint8_t A6 = 60;
const static uint8_t A7 = 61;
const static uint8_t A8 = 62;
const static uint8_t A9 = 63;
const static uint8_t A10 = 64;
const static uint8_t A11 = 65;
const static uint8_t A12 = 66;
const static uint8_t A13 = 67;
const static uint8_t A14 = 68;
const static uint8_t A15 = 69;
#else
const static uint8_t A0 = 14;
const static uint8_t A1 = 15;
const static uint8_t A2 = 16;
const static uint8_t A3 = 17;
const static uint8_t A4 = 18;
const static uint8_t A5 = 19;
const static uint8_t A6 = 20;
const static uint8_t A7 = 21;
#endif
#endif
#endif

View File

@ -0,0 +1,443 @@
/*
WString.cpp - String library for Wiring & Arduino
Copyright (c) 2009-10 Hernando Barragan. All rights 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
*/
#include <stdlib.h>
#include "WProgram.h"
#include "WString.h"
String::String( const char *value )
{
if ( value == NULL )
value = "";
getBuffer( _length = strlen( value ) );
if ( _buffer != NULL )
strcpy( _buffer, value );
}
String::String( const String &value )
{
getBuffer( _length = value._length );
if ( _buffer != NULL )
strcpy( _buffer, value._buffer );
}
String::String( const char value )
{
_length = 1;
getBuffer(1);
if ( _buffer != NULL ) {
_buffer[0] = value;
_buffer[1] = 0;
}
}
String::String( const unsigned char value )
{
_length = 1;
getBuffer(1);
if ( _buffer != NULL) {
_buffer[0] = value;
_buffer[1] = 0;
}
}
String::String( const int value, const int base )
{
char buf[33];
itoa((signed long)value, buf, base);
getBuffer( _length = strlen(buf) );
if ( _buffer != NULL )
strcpy( _buffer, buf );
}
String::String( const unsigned int value, const int base )
{
char buf[33];
ultoa((unsigned long)value, buf, base);
getBuffer( _length = strlen(buf) );
if ( _buffer != NULL )
strcpy( _buffer, buf );
}
String::String( const long value, const int base )
{
char buf[33];
ltoa(value, buf, base);
getBuffer( _length = strlen(buf) );
if ( _buffer != NULL )
strcpy( _buffer, buf );
}
String::String( const unsigned long value, const int base )
{
char buf[33];
ultoa(value, buf, 10);
getBuffer( _length = strlen(buf) );
if ( _buffer != NULL )
strcpy( _buffer, buf );
}
char String::charAt( unsigned int loc ) const
{
return operator[]( loc );
}
void String::setCharAt( unsigned int loc, const char aChar )
{
if(_buffer == NULL) return;
if(_length > loc) {
_buffer[loc] = aChar;
}
}
int String::compareTo( const String &s2 ) const
{
return strcmp( _buffer, s2._buffer );
}
const String & String::concat( const String &s2 )
{
return (*this) += s2;
}
const String & String::operator=( const String &rhs )
{
if ( this == &rhs )
return *this;
if ( rhs._length > _length )
{
free(_buffer);
getBuffer( rhs._length );
}
if ( _buffer != NULL ) {
_length = rhs._length;
strcpy( _buffer, rhs._buffer );
}
return *this;
}
//const String & String::operator+=( const char aChar )
//{
// if ( _length == _capacity )
// doubleBuffer();
//
// _buffer[ _length++ ] = aChar;
// _buffer[ _length ] = '\0';
// return *this;
//}
const String & String::operator+=( const String &other )
{
_length += other._length;
if ( _length > _capacity )
{
char *temp = (char *)realloc(_buffer, _length + 1);
if ( temp != NULL ) {
_buffer = temp;
_capacity = _length;
} else {
_length -= other._length;
return *this;
}
}
strcat( _buffer, other._buffer );
return *this;
}
int String::operator==( const String &rhs ) const
{
return ( _length == rhs._length && strcmp( _buffer, rhs._buffer ) == 0 );
}
int String::operator!=( const String &rhs ) const
{
return ( _length != rhs.length() || strcmp( _buffer, rhs._buffer ) != 0 );
}
int String::operator<( const String &rhs ) const
{
return strcmp( _buffer, rhs._buffer ) < 0;
}
int String::operator>( const String &rhs ) const
{
return strcmp( _buffer, rhs._buffer ) > 0;
}
int String::operator<=( const String &rhs ) const
{
return strcmp( _buffer, rhs._buffer ) <= 0;
}
int String::operator>=( const String & rhs ) const
{
return strcmp( _buffer, rhs._buffer ) >= 0;
}
char & String::operator[]( unsigned int index )
{
static char dummy_writable_char;
if (index >= _length || !_buffer) {
dummy_writable_char = 0;
return dummy_writable_char;
}
return _buffer[ index ];
}
char String::operator[]( unsigned int index ) const
{
// need to check for valid index, to do later
return _buffer[ index ];
}
boolean String::endsWith( const String &s2 ) const
{
if ( _length < s2._length )
return 0;
return strcmp( &_buffer[ _length - s2._length], s2._buffer ) == 0;
}
boolean String::equals( const String &s2 ) const
{
return ( _length == s2._length && strcmp( _buffer,s2._buffer ) == 0 );
}
boolean String::equalsIgnoreCase( const String &s2 ) const
{
if ( this == &s2 )
return true; //1;
else if ( _length != s2._length )
return false; //0;
return strcmp(toLowerCase()._buffer, s2.toLowerCase()._buffer) == 0;
}
String String::replace( char findChar, char replaceChar )
{
if ( _buffer == NULL ) return *this;
String theReturn = _buffer;
char* temp = theReturn._buffer;
while( (temp = strchr( temp, findChar )) != 0 )
*temp = replaceChar;
return theReturn;
}
String String::replace( const String& match, const String& replace )
{
if ( _buffer == NULL ) return *this;
String temp = _buffer, newString;
int loc;
while ( (loc = temp.indexOf( match )) != -1 )
{
newString += temp.substring( 0, loc );
newString += replace;
temp = temp.substring( loc + match._length );
}
newString += temp;
return newString;
}
int String::indexOf( char temp ) const
{
return indexOf( temp, 0 );
}
int String::indexOf( char ch, unsigned int fromIndex ) const
{
if ( fromIndex >= _length )
return -1;
const char* temp = strchr( &_buffer[fromIndex], ch );
if ( temp == NULL )
return -1;
return temp - _buffer;
}
int String::indexOf( const String &s2 ) const
{
return indexOf( s2, 0 );
}
int String::indexOf( const String &s2, unsigned int fromIndex ) const
{
if ( fromIndex >= _length )
return -1;
const char *theFind = strstr( &_buffer[ fromIndex ], s2._buffer );
if ( theFind == NULL )
return -1;
return theFind - _buffer; // pointer subtraction
}
int String::lastIndexOf( char theChar ) const
{
return lastIndexOf( theChar, _length - 1 );
}
int String::lastIndexOf( char ch, unsigned int fromIndex ) const
{
if ( fromIndex >= _length )
return -1;
char tempchar = _buffer[fromIndex + 1];
_buffer[fromIndex + 1] = '\0';
char* temp = strrchr( _buffer, ch );
_buffer[fromIndex + 1] = tempchar;
if ( temp == NULL )
return -1;
return temp - _buffer;
}
int String::lastIndexOf( const String &s2 ) const
{
return lastIndexOf( s2, _length - s2._length );
}
int String::lastIndexOf( const String &s2, unsigned int fromIndex ) const
{
// check for empty strings
if ( s2._length == 0 || s2._length - 1 > fromIndex || fromIndex >= _length )
return -1;
// matching first character
char temp = s2[ 0 ];
for ( int i = fromIndex; i >= 0; i-- )
{
if ( _buffer[ i ] == temp && (*this).substring( i, i + s2._length ).equals( s2 ) )
return i;
}
return -1;
}
boolean String::startsWith( const String &s2 ) const
{
if ( _length < s2._length )
return 0;
return startsWith( s2, 0 );
}
boolean String::startsWith( const String &s2, unsigned int offset ) const
{
if ( offset > _length - s2._length )
return 0;
return strncmp( &_buffer[offset], s2._buffer, s2._length ) == 0;
}
String String::substring( unsigned int left ) const
{
return substring( left, _length );
}
String String::substring( unsigned int left, unsigned int right ) const
{
if ( left > right )
{
int temp = right;
right = left;
left = temp;
}
if ( right > _length )
{
right = _length;
}
char temp = _buffer[ right ]; // save the replaced character
_buffer[ right ] = '\0';
String outPut = ( _buffer + left ); // pointer arithmetic
_buffer[ right ] = temp; //restore character
return outPut;
}
String String::toLowerCase() const
{
String temp = _buffer;
for ( unsigned int i = 0; i < _length; i++ )
temp._buffer[ i ] = (char)tolower( temp._buffer[ i ] );
return temp;
}
String String::toUpperCase() const
{
String temp = _buffer;
for ( unsigned int i = 0; i < _length; i++ )
temp._buffer[ i ] = (char)toupper( temp._buffer[ i ] );
return temp;
}
String String::trim() const
{
if ( _buffer == NULL ) return *this;
String temp = _buffer;
unsigned int i,j;
for ( i = 0; i < _length; i++ )
{
if ( !isspace(_buffer[i]) )
break;
}
for ( j = temp._length - 1; j > i; j-- )
{
if ( !isspace(_buffer[j]) )
break;
}
return temp.substring( i, j + 1);
}
void String::getBytes(unsigned char *buf, unsigned int bufsize)
{
if (!bufsize || !buf) return;
unsigned int len = bufsize - 1;
if (len > _length) len = _length;
strncpy((char *)buf, _buffer, len);
buf[len] = 0;
}
void String::toCharArray(char *buf, unsigned int bufsize)
{
if (!bufsize || !buf) return;
unsigned int len = bufsize - 1;
if (len > _length) len = _length;
strncpy(buf, _buffer, len);
buf[len] = 0;
}
long String::toInt() {
return atol(_buffer);
}

View File

@ -0,0 +1,112 @@
/*
WString.h - String library for Wiring & Arduino
Copyright (c) 2009-10 Hernando Barragan. 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 String_h
#define String_h
//#include "WProgram.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
class String
{
public:
// constructors
String( const char *value = "" );
String( const String &value );
String( const char );
String( const unsigned char );
String( const int, const int base=10);
String( const unsigned int, const int base=10 );
String( const long, const int base=10 );
String( const unsigned long, const int base=10 );
~String() { free(_buffer); _length = _capacity = 0;} //added _length = _capacity = 0;
// operators
const String & operator = ( const String &rhs );
const String & operator +=( const String &rhs );
//const String & operator +=( const char );
int operator ==( const String &rhs ) const;
int operator !=( const String &rhs ) const;
int operator < ( const String &rhs ) const;
int operator > ( const String &rhs ) const;
int operator <=( const String &rhs ) const;
int operator >=( const String &rhs ) const;
char operator []( unsigned int index ) const;
char& operator []( unsigned int index );
//operator const char *() const { return _buffer; }
// general methods
char charAt( unsigned int index ) const;
int compareTo( const String &anotherString ) const;
unsigned char endsWith( const String &suffix ) const;
unsigned char equals( const String &anObject ) const;
unsigned char equalsIgnoreCase( const String &anotherString ) const;
int indexOf( char ch ) const;
int indexOf( char ch, unsigned int fromIndex ) const;
int indexOf( const String &str ) const;
int indexOf( const String &str, unsigned int fromIndex ) const;
int lastIndexOf( char ch ) const;
int lastIndexOf( char ch, unsigned int fromIndex ) const;
int lastIndexOf( const String &str ) const;
int lastIndexOf( const String &str, unsigned int fromIndex ) const;
const unsigned int length( ) const { return _length; }
void setCharAt(unsigned int index, const char ch);
unsigned char startsWith( const String &prefix ) const;
unsigned char startsWith( const String &prefix, unsigned int toffset ) const;
String substring( unsigned int beginIndex ) const;
String substring( unsigned int beginIndex, unsigned int endIndex ) const;
String toLowerCase( ) const;
String toUpperCase( ) const;
String trim( ) const;
void getBytes(unsigned char *buf, unsigned int bufsize);
void toCharArray(char *buf, unsigned int bufsize);
long toInt( );
const String& concat( const String &str );
String replace( char oldChar, char newChar );
String replace( const String& match, const String& replace );
friend String operator + ( String lhs, const String &rhs );
protected:
char *_buffer; // the actual char array
unsigned int _capacity; // the array length minus one (for the '\0')
unsigned int _length; // the String length (not counting the '\0')
void getBuffer(unsigned int maxStrLen);
private:
};
// allocate buffer space
inline void String::getBuffer(unsigned int maxStrLen)
{
_capacity = maxStrLen;
_buffer = (char *) malloc(_capacity + 1);
if (_buffer == NULL) _length = _capacity = 0;
}
inline String operator+( String lhs, const String &rhs )
{
return lhs += rhs;
}
#endif

View File

@ -0,0 +1,515 @@
#ifndef Binary_h
#define Binary_h
#define B0 0
#define B00 0
#define B000 0
#define B0000 0
#define B00000 0
#define B000000 0
#define B0000000 0
#define B00000000 0
#define B1 1
#define B01 1
#define B001 1
#define B0001 1
#define B00001 1
#define B000001 1
#define B0000001 1
#define B00000001 1
#define B10 2
#define B010 2
#define B0010 2
#define B00010 2
#define B000010 2
#define B0000010 2
#define B00000010 2
#define B11 3
#define B011 3
#define B0011 3
#define B00011 3
#define B000011 3
#define B0000011 3
#define B00000011 3
#define B100 4
#define B0100 4
#define B00100 4
#define B000100 4
#define B0000100 4
#define B00000100 4
#define B101 5
#define B0101 5
#define B00101 5
#define B000101 5
#define B0000101 5
#define B00000101 5
#define B110 6
#define B0110 6
#define B00110 6
#define B000110 6
#define B0000110 6
#define B00000110 6
#define B111 7
#define B0111 7
#define B00111 7
#define B000111 7
#define B0000111 7
#define B00000111 7
#define B1000 8
#define B01000 8
#define B001000 8
#define B0001000 8
#define B00001000 8
#define B1001 9
#define B01001 9
#define B001001 9
#define B0001001 9
#define B00001001 9
#define B1010 10
#define B01010 10
#define B001010 10
#define B0001010 10
#define B00001010 10
#define B1011 11
#define B01011 11
#define B001011 11
#define B0001011 11
#define B00001011 11
#define B1100 12
#define B01100 12
#define B001100 12
#define B0001100 12
#define B00001100 12
#define B1101 13
#define B01101 13
#define B001101 13
#define B0001101 13
#define B00001101 13
#define B1110 14
#define B01110 14
#define B001110 14
#define B0001110 14
#define B00001110 14
#define B1111 15
#define B01111 15
#define B001111 15
#define B0001111 15
#define B00001111 15
#define B10000 16
#define B010000 16
#define B0010000 16
#define B00010000 16
#define B10001 17
#define B010001 17
#define B0010001 17
#define B00010001 17
#define B10010 18
#define B010010 18
#define B0010010 18
#define B00010010 18
#define B10011 19
#define B010011 19
#define B0010011 19
#define B00010011 19
#define B10100 20
#define B010100 20
#define B0010100 20
#define B00010100 20
#define B10101 21
#define B010101 21
#define B0010101 21
#define B00010101 21
#define B10110 22
#define B010110 22
#define B0010110 22
#define B00010110 22
#define B10111 23
#define B010111 23
#define B0010111 23
#define B00010111 23
#define B11000 24
#define B011000 24
#define B0011000 24
#define B00011000 24
#define B11001 25
#define B011001 25
#define B0011001 25
#define B00011001 25
#define B11010 26
#define B011010 26
#define B0011010 26
#define B00011010 26
#define B11011 27
#define B011011 27
#define B0011011 27
#define B00011011 27
#define B11100 28
#define B011100 28
#define B0011100 28
#define B00011100 28
#define B11101 29
#define B011101 29
#define B0011101 29
#define B00011101 29
#define B11110 30
#define B011110 30
#define B0011110 30
#define B00011110 30
#define B11111 31
#define B011111 31
#define B0011111 31
#define B00011111 31
#define B100000 32
#define B0100000 32
#define B00100000 32
#define B100001 33
#define B0100001 33
#define B00100001 33
#define B100010 34
#define B0100010 34
#define B00100010 34
#define B100011 35
#define B0100011 35
#define B00100011 35
#define B100100 36
#define B0100100 36
#define B00100100 36
#define B100101 37
#define B0100101 37
#define B00100101 37
#define B100110 38
#define B0100110 38
#define B00100110 38
#define B100111 39
#define B0100111 39
#define B00100111 39
#define B101000 40
#define B0101000 40
#define B00101000 40
#define B101001 41
#define B0101001 41
#define B00101001 41
#define B101010 42
#define B0101010 42
#define B00101010 42
#define B101011 43
#define B0101011 43
#define B00101011 43
#define B101100 44
#define B0101100 44
#define B00101100 44
#define B101101 45
#define B0101101 45
#define B00101101 45
#define B101110 46
#define B0101110 46
#define B00101110 46
#define B101111 47
#define B0101111 47
#define B00101111 47
#define B110000 48
#define B0110000 48
#define B00110000 48
#define B110001 49
#define B0110001 49
#define B00110001 49
#define B110010 50
#define B0110010 50
#define B00110010 50
#define B110011 51
#define B0110011 51
#define B00110011 51
#define B110100 52
#define B0110100 52
#define B00110100 52
#define B110101 53
#define B0110101 53
#define B00110101 53
#define B110110 54
#define B0110110 54
#define B00110110 54
#define B110111 55
#define B0110111 55
#define B00110111 55
#define B111000 56
#define B0111000 56
#define B00111000 56
#define B111001 57
#define B0111001 57
#define B00111001 57
#define B111010 58
#define B0111010 58
#define B00111010 58
#define B111011 59
#define B0111011 59
#define B00111011 59
#define B111100 60
#define B0111100 60
#define B00111100 60
#define B111101 61
#define B0111101 61
#define B00111101 61
#define B111110 62
#define B0111110 62
#define B00111110 62
#define B111111 63
#define B0111111 63
#define B00111111 63
#define B1000000 64
#define B01000000 64
#define B1000001 65
#define B01000001 65
#define B1000010 66
#define B01000010 66
#define B1000011 67
#define B01000011 67
#define B1000100 68
#define B01000100 68
#define B1000101 69
#define B01000101 69
#define B1000110 70
#define B01000110 70
#define B1000111 71
#define B01000111 71
#define B1001000 72
#define B01001000 72
#define B1001001 73
#define B01001001 73
#define B1001010 74
#define B01001010 74
#define B1001011 75
#define B01001011 75
#define B1001100 76
#define B01001100 76
#define B1001101 77
#define B01001101 77
#define B1001110 78
#define B01001110 78
#define B1001111 79
#define B01001111 79
#define B1010000 80
#define B01010000 80
#define B1010001 81
#define B01010001 81
#define B1010010 82
#define B01010010 82
#define B1010011 83
#define B01010011 83
#define B1010100 84
#define B01010100 84
#define B1010101 85
#define B01010101 85
#define B1010110 86
#define B01010110 86
#define B1010111 87
#define B01010111 87
#define B1011000 88
#define B01011000 88
#define B1011001 89
#define B01011001 89
#define B1011010 90
#define B01011010 90
#define B1011011 91
#define B01011011 91
#define B1011100 92
#define B01011100 92
#define B1011101 93
#define B01011101 93
#define B1011110 94
#define B01011110 94
#define B1011111 95
#define B01011111 95
#define B1100000 96
#define B01100000 96
#define B1100001 97
#define B01100001 97
#define B1100010 98
#define B01100010 98
#define B1100011 99
#define B01100011 99
#define B1100100 100
#define B01100100 100
#define B1100101 101
#define B01100101 101
#define B1100110 102
#define B01100110 102
#define B1100111 103
#define B01100111 103
#define B1101000 104
#define B01101000 104
#define B1101001 105
#define B01101001 105
#define B1101010 106
#define B01101010 106
#define B1101011 107
#define B01101011 107
#define B1101100 108
#define B01101100 108
#define B1101101 109
#define B01101101 109
#define B1101110 110
#define B01101110 110
#define B1101111 111
#define B01101111 111
#define B1110000 112
#define B01110000 112
#define B1110001 113
#define B01110001 113
#define B1110010 114
#define B01110010 114
#define B1110011 115
#define B01110011 115
#define B1110100 116
#define B01110100 116
#define B1110101 117
#define B01110101 117
#define B1110110 118
#define B01110110 118
#define B1110111 119
#define B01110111 119
#define B1111000 120
#define B01111000 120
#define B1111001 121
#define B01111001 121
#define B1111010 122
#define B01111010 122
#define B1111011 123
#define B01111011 123
#define B1111100 124
#define B01111100 124
#define B1111101 125
#define B01111101 125
#define B1111110 126
#define B01111110 126
#define B1111111 127
#define B01111111 127
#define B10000000 128
#define B10000001 129
#define B10000010 130
#define B10000011 131
#define B10000100 132
#define B10000101 133
#define B10000110 134
#define B10000111 135
#define B10001000 136
#define B10001001 137
#define B10001010 138
#define B10001011 139
#define B10001100 140
#define B10001101 141
#define B10001110 142
#define B10001111 143
#define B10010000 144
#define B10010001 145
#define B10010010 146
#define B10010011 147
#define B10010100 148
#define B10010101 149
#define B10010110 150
#define B10010111 151
#define B10011000 152
#define B10011001 153
#define B10011010 154
#define B10011011 155
#define B10011100 156
#define B10011101 157
#define B10011110 158
#define B10011111 159
#define B10100000 160
#define B10100001 161
#define B10100010 162
#define B10100011 163
#define B10100100 164
#define B10100101 165
#define B10100110 166
#define B10100111 167
#define B10101000 168
#define B10101001 169
#define B10101010 170
#define B10101011 171
#define B10101100 172
#define B10101101 173
#define B10101110 174
#define B10101111 175
#define B10110000 176
#define B10110001 177
#define B10110010 178
#define B10110011 179
#define B10110100 180
#define B10110101 181
#define B10110110 182
#define B10110111 183
#define B10111000 184
#define B10111001 185
#define B10111010 186
#define B10111011 187
#define B10111100 188
#define B10111101 189
#define B10111110 190
#define B10111111 191
#define B11000000 192
#define B11000001 193
#define B11000010 194
#define B11000011 195
#define B11000100 196
#define B11000101 197
#define B11000110 198
#define B11000111 199
#define B11001000 200
#define B11001001 201
#define B11001010 202
#define B11001011 203
#define B11001100 204
#define B11001101 205
#define B11001110 206
#define B11001111 207
#define B11010000 208
#define B11010001 209
#define B11010010 210
#define B11010011 211
#define B11010100 212
#define B11010101 213
#define B11010110 214
#define B11010111 215
#define B11011000 216
#define B11011001 217
#define B11011010 218
#define B11011011 219
#define B11011100 220
#define B11011101 221
#define B11011110 222
#define B11011111 223
#define B11100000 224
#define B11100001 225
#define B11100010 226
#define B11100011 227
#define B11100100 228
#define B11100101 229
#define B11100110 230
#define B11100111 231
#define B11101000 232
#define B11101001 233
#define B11101010 234
#define B11101011 235
#define B11101100 236
#define B11101101 237
#define B11101110 238
#define B11101111 239
#define B11110000 240
#define B11110001 241
#define B11110010 242
#define B11110011 243
#define B11110100 244
#define B11110101 245
#define B11110110 246
#define B11110111 247
#define B11111000 248
#define B11111001 249
#define B11111010 250
#define B11111011 251
#define B11111100 252
#define B11111101 253
#define B11111110 254
#define B11111111 255
#endif

View File

@ -0,0 +1,14 @@
#include <WProgram.h>
int main(void)
{
init();
setup();
for (;;)
loop();
return 0;
}

View File

@ -0,0 +1,627 @@
/*
pins_arduino.c - pin definitions for the Arduino board
Part of Arduino / Wiring Lite
Copyright (c) 2005 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
Changelog
-----------
11/25/11 - ryan@ryanmsutton.com - Add pins for Sanguino 644P and 1284P
$Id$
*/
#include <avr/io.h>
#include "wiring_private.h"
#include "pins_arduino.h"
// On the Arduino board, digital pins are also used
// for the analog output (software PWM). Analog input
// pins are a separate set.
// ATMEL ATMEGA8 & 168 / ARDUINO
//
// +-\/-+
// PC6 1| |28 PC5 (AI 5)
// (D 0) PD0 2| |27 PC4 (AI 4)
// (D 1) PD1 3| |26 PC3 (AI 3)
// (D 2) PD2 4| |25 PC2 (AI 2)
// PWM+ (D 3) PD3 5| |24 PC1 (AI 1)
// (D 4) PD4 6| |23 PC0 (AI 0)
// VCC 7| |22 GND
// GND 8| |21 AREF
// PB6 9| |20 AVCC
// PB7 10| |19 PB5 (D 13)
// PWM+ (D 5) PD5 11| |18 PB4 (D 12)
// PWM+ (D 6) PD6 12| |17 PB3 (D 11) PWM
// (D 7) PD7 13| |16 PB2 (D 10) PWM
// (D 8) PB0 14| |15 PB1 (D 9) PWM
// +----+
//
// (PWM+ indicates the additional PWM pins on the ATmega168.)
// ATMEL ATMEGA1280 / ARDUINO
//
// 0-7 PE0-PE7 works
// 8-13 PB0-PB5 works
// 14-21 PA0-PA7 works
// 22-29 PH0-PH7 works
// 30-35 PG5-PG0 works
// 36-43 PC7-PC0 works
// 44-51 PJ7-PJ0 works
// 52-59 PL7-PL0 works
// 60-67 PD7-PD0 works
// A0-A7 PF0-PF7
// A8-A15 PK0-PK7
// ATMEL ATMEGA644P / SANGUINO
//
// +---\/---+
// INT0 (D 0) PB0 1| |40 PA0 (AI 0 / D31)
// INT1 (D 1) PB1 2| |39 PA1 (AI 1 / D30)
// INT2 (D 2) PB2 3| |38 PA2 (AI 2 / D29)
// PWM (D 3) PB3 4| |37 PA3 (AI 3 / D28)
// PWM (D 4) PB4 5| |36 PA4 (AI 4 / D27)
// MOSI (D 5) PB5 6| |35 PA5 (AI 5 / D26)
// MISO (D 6) PB6 7| |34 PA6 (AI 6 / D25)
// SCK (D 7) PB7 8| |33 PA7 (AI 7 / D24)
// RST 9| |32 AREF
// VCC 10| |31 GND
// GND 11| |30 AVCC
// XTAL2 12| |29 PC7 (D 23)
// XTAL1 13| |28 PC6 (D 22)
// RX0 (D 8) PD0 14| |27 PC5 (D 21) TDI
// TX0 (D 9) PD1 15| |26 PC4 (D 20) TDO
// RX1 (D 10) PD2 16| |25 PC3 (D 19) TMS
// TX1 (D 11) PD3 17| |24 PC2 (D 18) TCK
// PWM (D 12) PD4 18| |23 PC1 (D 17) SDA
// PWM (D 13) PD5 19| |22 PC0 (D 16) SCL
// PWM (D 14) PD6 20| |21 PD7 (D 15) PWM
// +--------+
//
#define PA 1
#define PB 2
#define PC 3
#define PD 4
#define PE 5
#define PF 6
#define PG 7
#define PH 8
#define PJ 10
#define PK 11
#define PL 12
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
const uint16_t PROGMEM port_to_mode_PGM[] = {
NOT_A_PORT,
&DDRA,
&DDRB,
&DDRC,
&DDRD,
&DDRE,
&DDRF,
&DDRG,
&DDRH,
NOT_A_PORT,
&DDRJ,
&DDRK,
&DDRL,
};
const uint16_t PROGMEM port_to_output_PGM[] = {
NOT_A_PORT,
&PORTA,
&PORTB,
&PORTC,
&PORTD,
&PORTE,
&PORTF,
&PORTG,
&PORTH,
NOT_A_PORT,
&PORTJ,
&PORTK,
&PORTL,
};
const uint16_t PROGMEM port_to_input_PGM[] = {
NOT_A_PIN,
&PINA,
&PINB,
&PINC,
&PIND,
&PINE,
&PINF,
&PING,
&PINH,
NOT_A_PIN,
&PINJ,
&PINK,
&PINL,
};
const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
// PORTLIST
// -------------------------------------------
PE , // PE 0 ** 0 ** USART0_RX
PE , // PE 1 ** 1 ** USART0_TX
PE , // PE 4 ** 2 ** PWM2
PE , // PE 5 ** 3 ** PWM3
PG , // PG 5 ** 4 ** PWM4
PE , // PE 3 ** 5 ** PWM5
PH , // PH 3 ** 6 ** PWM6
PH , // PH 4 ** 7 ** PWM7
PH , // PH 5 ** 8 ** PWM8
PH , // PH 6 ** 9 ** PWM9
PB , // PB 4 ** 10 ** PWM10
PB , // PB 5 ** 11 ** PWM11
PB , // PB 6 ** 12 ** PWM12
PB , // PB 7 ** 13 ** PWM13
PJ , // PJ 1 ** 14 ** USART3_TX
PJ , // PJ 0 ** 15 ** USART3_RX
PH , // PH 1 ** 16 ** USART2_TX
PH , // PH 0 ** 17 ** USART2_RX
PD , // PD 3 ** 18 ** USART1_TX
PD , // PD 2 ** 19 ** USART1_RX
PD , // PD 1 ** 20 ** I2C_SDA
PD , // PD 0 ** 21 ** I2C_SCL
PA , // PA 0 ** 22 ** D22
PA , // PA 1 ** 23 ** D23
PA , // PA 2 ** 24 ** D24
PA , // PA 3 ** 25 ** D25
PA , // PA 4 ** 26 ** D26
PA , // PA 5 ** 27 ** D27
PA , // PA 6 ** 28 ** D28
PA , // PA 7 ** 29 ** D29
PC , // PC 7 ** 30 ** D30
PC , // PC 6 ** 31 ** D31
PC , // PC 5 ** 32 ** D32
PC , // PC 4 ** 33 ** D33
PC , // PC 3 ** 34 ** D34
PC , // PC 2 ** 35 ** D35
PC , // PC 1 ** 36 ** D36
PC , // PC 0 ** 37 ** D37
PD , // PD 7 ** 38 ** D38
PG , // PG 2 ** 39 ** D39
PG , // PG 1 ** 40 ** D40
PG , // PG 0 ** 41 ** D41
PL , // PL 7 ** 42 ** D42
PL , // PL 6 ** 43 ** D43
PL , // PL 5 ** 44 ** D44
PL , // PL 4 ** 45 ** D45
PL , // PL 3 ** 46 ** D46
PL , // PL 2 ** 47 ** D47
PL , // PL 1 ** 48 ** D48
PL , // PL 0 ** 49 ** D49
PB , // PB 3 ** 50 ** SPI_MISO
PB , // PB 2 ** 51 ** SPI_MOSI
PB , // PB 1 ** 52 ** SPI_SCK
PB , // PB 0 ** 53 ** SPI_SS
PF , // PF 0 ** 54 ** A0
PF , // PF 1 ** 55 ** A1
PF , // PF 2 ** 56 ** A2
PF , // PF 3 ** 57 ** A3
PF , // PF 4 ** 58 ** A4
PF , // PF 5 ** 59 ** A5
PF , // PF 6 ** 60 ** A6
PF , // PF 7 ** 61 ** A7
PK , // PK 0 ** 62 ** A8
PK , // PK 1 ** 63 ** A9
PK , // PK 2 ** 64 ** A10
PK , // PK 3 ** 65 ** A11
PK , // PK 4 ** 66 ** A12
PK , // PK 5 ** 67 ** A13
PK , // PK 6 ** 68 ** A14
PK , // PK 7 ** 69 ** A15
};
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
// PIN IN PORT
// -------------------------------------------
_BV( 0 ) , // PE 0 ** 0 ** USART0_RX
_BV( 1 ) , // PE 1 ** 1 ** USART0_TX
_BV( 4 ) , // PE 4 ** 2 ** PWM2
_BV( 5 ) , // PE 5 ** 3 ** PWM3
_BV( 5 ) , // PG 5 ** 4 ** PWM4
_BV( 3 ) , // PE 3 ** 5 ** PWM5
_BV( 3 ) , // PH 3 ** 6 ** PWM6
_BV( 4 ) , // PH 4 ** 7 ** PWM7
_BV( 5 ) , // PH 5 ** 8 ** PWM8
_BV( 6 ) , // PH 6 ** 9 ** PWM9
_BV( 4 ) , // PB 4 ** 10 ** PWM10
_BV( 5 ) , // PB 5 ** 11 ** PWM11
_BV( 6 ) , // PB 6 ** 12 ** PWM12
_BV( 7 ) , // PB 7 ** 13 ** PWM13
_BV( 1 ) , // PJ 1 ** 14 ** USART3_TX
_BV( 0 ) , // PJ 0 ** 15 ** USART3_RX
_BV( 1 ) , // PH 1 ** 16 ** USART2_TX
_BV( 0 ) , // PH 0 ** 17 ** USART2_RX
_BV( 3 ) , // PD 3 ** 18 ** USART1_TX
_BV( 2 ) , // PD 2 ** 19 ** USART1_RX
_BV( 1 ) , // PD 1 ** 20 ** I2C_SDA
_BV( 0 ) , // PD 0 ** 21 ** I2C_SCL
_BV( 0 ) , // PA 0 ** 22 ** D22
_BV( 1 ) , // PA 1 ** 23 ** D23
_BV( 2 ) , // PA 2 ** 24 ** D24
_BV( 3 ) , // PA 3 ** 25 ** D25
_BV( 4 ) , // PA 4 ** 26 ** D26
_BV( 5 ) , // PA 5 ** 27 ** D27
_BV( 6 ) , // PA 6 ** 28 ** D28
_BV( 7 ) , // PA 7 ** 29 ** D29
_BV( 7 ) , // PC 7 ** 30 ** D30
_BV( 6 ) , // PC 6 ** 31 ** D31
_BV( 5 ) , // PC 5 ** 32 ** D32
_BV( 4 ) , // PC 4 ** 33 ** D33
_BV( 3 ) , // PC 3 ** 34 ** D34
_BV( 2 ) , // PC 2 ** 35 ** D35
_BV( 1 ) , // PC 1 ** 36 ** D36
_BV( 0 ) , // PC 0 ** 37 ** D37
_BV( 7 ) , // PD 7 ** 38 ** D38
_BV( 2 ) , // PG 2 ** 39 ** D39
_BV( 1 ) , // PG 1 ** 40 ** D40
_BV( 0 ) , // PG 0 ** 41 ** D41
_BV( 7 ) , // PL 7 ** 42 ** D42
_BV( 6 ) , // PL 6 ** 43 ** D43
_BV( 5 ) , // PL 5 ** 44 ** D44
_BV( 4 ) , // PL 4 ** 45 ** D45
_BV( 3 ) , // PL 3 ** 46 ** D46
_BV( 2 ) , // PL 2 ** 47 ** D47
_BV( 1 ) , // PL 1 ** 48 ** D48
_BV( 0 ) , // PL 0 ** 49 ** D49
_BV( 3 ) , // PB 3 ** 50 ** SPI_MISO
_BV( 2 ) , // PB 2 ** 51 ** SPI_MOSI
_BV( 1 ) , // PB 1 ** 52 ** SPI_SCK
_BV( 0 ) , // PB 0 ** 53 ** SPI_SS
_BV( 0 ) , // PF 0 ** 54 ** A0
_BV( 1 ) , // PF 1 ** 55 ** A1
_BV( 2 ) , // PF 2 ** 56 ** A2
_BV( 3 ) , // PF 3 ** 57 ** A3
_BV( 4 ) , // PF 4 ** 58 ** A4
_BV( 5 ) , // PF 5 ** 59 ** A5
_BV( 6 ) , // PF 6 ** 60 ** A6
_BV( 7 ) , // PF 7 ** 61 ** A7
_BV( 0 ) , // PK 0 ** 62 ** A8
_BV( 1 ) , // PK 1 ** 63 ** A9
_BV( 2 ) , // PK 2 ** 64 ** A10
_BV( 3 ) , // PK 3 ** 65 ** A11
_BV( 4 ) , // PK 4 ** 66 ** A12
_BV( 5 ) , // PK 5 ** 67 ** A13
_BV( 6 ) , // PK 6 ** 68 ** A14
_BV( 7 ) , // PK 7 ** 69 ** A15
};
const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
// TIMERS
// -------------------------------------------
NOT_ON_TIMER , // PE 0 ** 0 ** USART0_RX
NOT_ON_TIMER , // PE 1 ** 1 ** USART0_TX
TIMER3B , // PE 4 ** 2 ** PWM2
TIMER3C , // PE 5 ** 3 ** PWM3
TIMER0B , // PG 5 ** 4 ** PWM4
TIMER3A , // PE 3 ** 5 ** PWM5
TIMER4A , // PH 3 ** 6 ** PWM6
TIMER4B , // PH 4 ** 7 ** PWM7
TIMER4C , // PH 5 ** 8 ** PWM8
TIMER2B , // PH 6 ** 9 ** PWM9
TIMER2A , // PB 4 ** 10 ** PWM10
TIMER1A , // PB 5 ** 11 ** PWM11
TIMER1B , // PB 6 ** 12 ** PWM12
TIMER0A , // PB 7 ** 13 ** PWM13
NOT_ON_TIMER , // PJ 1 ** 14 ** USART3_TX
NOT_ON_TIMER , // PJ 0 ** 15 ** USART3_RX
NOT_ON_TIMER , // PH 1 ** 16 ** USART2_TX
NOT_ON_TIMER , // PH 0 ** 17 ** USART2_RX
NOT_ON_TIMER , // PD 3 ** 18 ** USART1_TX
NOT_ON_TIMER , // PD 2 ** 19 ** USART1_RX
NOT_ON_TIMER , // PD 1 ** 20 ** I2C_SDA
NOT_ON_TIMER , // PD 0 ** 21 ** I2C_SCL
NOT_ON_TIMER , // PA 0 ** 22 ** D22
NOT_ON_TIMER , // PA 1 ** 23 ** D23
NOT_ON_TIMER , // PA 2 ** 24 ** D24
NOT_ON_TIMER , // PA 3 ** 25 ** D25
NOT_ON_TIMER , // PA 4 ** 26 ** D26
NOT_ON_TIMER , // PA 5 ** 27 ** D27
NOT_ON_TIMER , // PA 6 ** 28 ** D28
NOT_ON_TIMER , // PA 7 ** 29 ** D29
NOT_ON_TIMER , // PC 7 ** 30 ** D30
NOT_ON_TIMER , // PC 6 ** 31 ** D31
NOT_ON_TIMER , // PC 5 ** 32 ** D32
NOT_ON_TIMER , // PC 4 ** 33 ** D33
NOT_ON_TIMER , // PC 3 ** 34 ** D34
NOT_ON_TIMER , // PC 2 ** 35 ** D35
NOT_ON_TIMER , // PC 1 ** 36 ** D36
NOT_ON_TIMER , // PC 0 ** 37 ** D37
NOT_ON_TIMER , // PD 7 ** 38 ** D38
NOT_ON_TIMER , // PG 2 ** 39 ** D39
NOT_ON_TIMER , // PG 1 ** 40 ** D40
NOT_ON_TIMER , // PG 0 ** 41 ** D41
NOT_ON_TIMER , // PL 7 ** 42 ** D42
NOT_ON_TIMER , // PL 6 ** 43 ** D43
TIMER5C , // PL 5 ** 44 ** D44
TIMER5B , // PL 4 ** 45 ** D45
TIMER5A , // PL 3 ** 46 ** D46
NOT_ON_TIMER , // PL 2 ** 47 ** D47
NOT_ON_TIMER , // PL 1 ** 48 ** D48
NOT_ON_TIMER , // PL 0 ** 49 ** D49
NOT_ON_TIMER , // PB 3 ** 50 ** SPI_MISO
NOT_ON_TIMER , // PB 2 ** 51 ** SPI_MOSI
NOT_ON_TIMER , // PB 1 ** 52 ** SPI_SCK
NOT_ON_TIMER , // PB 0 ** 53 ** SPI_SS
NOT_ON_TIMER , // PF 0 ** 54 ** A0
NOT_ON_TIMER , // PF 1 ** 55 ** A1
NOT_ON_TIMER , // PF 2 ** 56 ** A2
NOT_ON_TIMER , // PF 3 ** 57 ** A3
NOT_ON_TIMER , // PF 4 ** 58 ** A4
NOT_ON_TIMER , // PF 5 ** 59 ** A5
NOT_ON_TIMER , // PF 6 ** 60 ** A6
NOT_ON_TIMER , // PF 7 ** 61 ** A7
NOT_ON_TIMER , // PK 0 ** 62 ** A8
NOT_ON_TIMER , // PK 1 ** 63 ** A9
NOT_ON_TIMER , // PK 2 ** 64 ** A10
NOT_ON_TIMER , // PK 3 ** 65 ** A11
NOT_ON_TIMER , // PK 4 ** 66 ** A12
NOT_ON_TIMER , // PK 5 ** 67 ** A13
NOT_ON_TIMER , // PK 6 ** 68 ** A14
NOT_ON_TIMER , // PK 7 ** 69 ** A15
};
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
const uint16_t PROGMEM port_to_mode_PGM[] =
{
NOT_A_PORT,
&DDRA,
&DDRB,
&DDRC,
&DDRD,
};
const uint16_t PROGMEM port_to_output_PGM[] =
{
NOT_A_PORT,
&PORTA,
&PORTB,
&PORTC,
&PORTD,
};
const uint16_t PROGMEM port_to_input_PGM[] =
{
NOT_A_PORT,
&PINA,
&PINB,
&PINC,
&PIND,
};
const uint8_t PROGMEM digital_pin_to_port_PGM[] =
{
PB, /* 0 */
PB,
PB,
PB,
PB,
PB,
PB,
PB,
PD, /* 8 */
PD,
PD,
PD,
PD,
PD,
PD,
PD,
PC, /* 16 */
PC,
PC,
PC,
PC,
PC,
PC,
PC,
PA, /* 24 */
PA,
PA,
PA,
PA,
PA,
PA,
PA /* 31 */
};
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] =
{
_BV(0), /* 0, port B */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
_BV(0), /* 8, port D */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
_BV(0), /* 16, port C */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
_BV(7), /* 24, port A */
_BV(6),
_BV(5),
_BV(4),
_BV(3),
_BV(2),
_BV(1),
_BV(0)
};
const uint8_t PROGMEM digital_pin_to_timer_PGM[] =
{
NOT_ON_TIMER, /* 0 - PB0 */
NOT_ON_TIMER, /* 1 - PB1 */
NOT_ON_TIMER, /* 2 - PB2 */
TIMER0A, /* 3 - PB3 */
TIMER0B, /* 4 - PB4 */
NOT_ON_TIMER, /* 5 - PB5 */
NOT_ON_TIMER, /* 6 - PB6 */
NOT_ON_TIMER, /* 7 - PB7 */
NOT_ON_TIMER, /* 8 - PD0 */
NOT_ON_TIMER, /* 9 - PD1 */
NOT_ON_TIMER, /* 10 - PD2 */
NOT_ON_TIMER, /* 11 - PD3 */
TIMER1B, /* 12 - PD4 */
TIMER1A, /* 13 - PD5 */
TIMER2B, /* 14 - PD6 */
TIMER2A, /* 15 - PD7 */
NOT_ON_TIMER, /* 16 - PC0 */
NOT_ON_TIMER, /* 17 - PC1 */
NOT_ON_TIMER, /* 18 - PC2 */
NOT_ON_TIMER, /* 19 - PC3 */
NOT_ON_TIMER, /* 20 - PC4 */
NOT_ON_TIMER, /* 21 - PC5 */
NOT_ON_TIMER, /* 22 - PC6 */
NOT_ON_TIMER, /* 23 - PC7 */
NOT_ON_TIMER, /* 24 - PA0 */
NOT_ON_TIMER, /* 25 - PA1 */
NOT_ON_TIMER, /* 26 - PA2 */
NOT_ON_TIMER, /* 27 - PA3 */
NOT_ON_TIMER, /* 28 - PA4 */
NOT_ON_TIMER, /* 29 - PA5 */
NOT_ON_TIMER, /* 30 - PA6 */
NOT_ON_TIMER /* 31 - PA7 */
};
#else
// these arrays map port names (e.g. port B) to the
// appropriate addresses for various functions (e.g. reading
// and writing)
const uint16_t PROGMEM port_to_mode_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
&DDRB,
&DDRC,
&DDRD,
};
const uint16_t PROGMEM port_to_output_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
&PORTB,
&PORTC,
&PORTD,
};
const uint16_t PROGMEM port_to_input_PGM[] = {
NOT_A_PORT,
NOT_A_PORT,
&PINB,
&PINC,
&PIND,
};
const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
PD, /* 0 */
PD,
PD,
PD,
PD,
PD,
PD,
PD,
PB, /* 8 */
PB,
PB,
PB,
PB,
PB,
PC, /* 14 */
PC,
PC,
PC,
PC,
PC,
};
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
_BV(0), /* 0, port D */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(6),
_BV(7),
_BV(0), /* 8, port B */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
_BV(0), /* 14, port C */
_BV(1),
_BV(2),
_BV(3),
_BV(4),
_BV(5),
};
const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
NOT_ON_TIMER, /* 0 - port D */
NOT_ON_TIMER,
NOT_ON_TIMER,
// on the ATmega168, digital pin 3 has hardware pwm
#if defined(__AVR_ATmega8__)
NOT_ON_TIMER,
#else
TIMER2B,
#endif
NOT_ON_TIMER,
// on the ATmega168, digital pins 5 and 6 have hardware pwm
#if defined(__AVR_ATmega8__)
NOT_ON_TIMER,
NOT_ON_TIMER,
#else
TIMER0B,
TIMER0A,
#endif
NOT_ON_TIMER,
NOT_ON_TIMER, /* 8 - port B */
TIMER1A,
TIMER1B,
#if defined(__AVR_ATmega8__)
TIMER2,
#else
TIMER2A,
#endif
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER, /* 14 - port C */
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
NOT_ON_TIMER,
};
#endif

View File

@ -0,0 +1,94 @@
/*
pins_arduino.h - Pin definition functions for Arduino
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2007 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: wiring.h 249 2007-02-03 16:52:51Z mellis $
*/
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <avr/pgmspace.h>
#define NOT_A_PIN 0
#define NOT_A_PORT 0
#define NOT_ON_TIMER 0
#define TIMER0A 1
#define TIMER0B 2
#define TIMER1A 3
#define TIMER1B 4
#define TIMER2 5
#define TIMER2A 6
#define TIMER2B 7
#define TIMER3A 8
#define TIMER3B 9
#define TIMER3C 10
#define TIMER4A 11
#define TIMER4B 12
#define TIMER4C 13
#define TIMER5A 14
#define TIMER5B 15
#define TIMER5C 16
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
const static uint8_t SS = 53;
const static uint8_t MOSI = 51;
const static uint8_t MISO = 50;
const static uint8_t SCK = 52;
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
const static uint8_t SS = 4;
const static uint8_t MOSI = 5;
const static uint8_t MISO = 6;
const static uint8_t SCK = 7;
#else
const static uint8_t SS = 10;
const static uint8_t MOSI = 11;
const static uint8_t MISO = 12;
const static uint8_t SCK = 13;
#endif
// On the ATmega1280, the addresses of some of the port registers are
// greater than 255, so we can't store them in uint8_t's.
extern const uint16_t PROGMEM port_to_mode_PGM[];
extern const uint16_t PROGMEM port_to_input_PGM[];
extern const uint16_t PROGMEM port_to_output_PGM[];
extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
// extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
// Get the bit location within the hardware port of the given virtual pin.
// This comes from the pins_*.c file for the active board configuration.
//
// These perform slightly better as macros compared to inline functions
//
#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
#define digitalPinToBitMask(P) ( pgm_read_byte( digital_pin_to_bit_mask_PGM + (P) ) )
#define digitalPinToTimer(P) ( pgm_read_byte( digital_pin_to_timer_PGM + (P) ) )
#define analogInPinToBit(P) (P)
#define portOutputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_output_PGM + (P))) )
#define portInputRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_input_PGM + (P))) )
#define portModeRegister(P) ( (volatile uint8_t *)( pgm_read_word( port_to_mode_PGM + (P))) )
#endif

View File

@ -0,0 +1,289 @@
/*
wiring.c - Partial implementation of the Wiring API for the ATmega8.
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id$
*/
#include "wiring_private.h"
// the prescaler is set so that timer0 ticks every 64 clock cycles, and the
// the overflow handler is called every 256 ticks.
#define MICROSECONDS_PER_TIMER0_OVERFLOW (clockCyclesToMicroseconds(64 * 256))
// the whole number of milliseconds per timer0 overflow
#define MILLIS_INC (MICROSECONDS_PER_TIMER0_OVERFLOW / 1000)
// the fractional number of milliseconds per timer0 overflow. we shift right
// by three to fit these numbers into a byte. (for the clock speeds we care
// about - 8 and 16 MHz - this doesn't lose precision.)
#define FRACT_INC ((MICROSECONDS_PER_TIMER0_OVERFLOW % 1000) >> 3)
#define FRACT_MAX (1000 >> 3)
volatile unsigned long timer0_overflow_count = 0;
volatile unsigned long timer0_millis = 0;
static unsigned char timer0_fract = 0;
SIGNAL(TIMER0_OVF_vect)
{
// copy these to local variables so they can be stored in registers
// (volatile variables must be read from memory on every access)
unsigned long m = timer0_millis;
unsigned char f = timer0_fract;
m += MILLIS_INC;
f += FRACT_INC;
if (f >= FRACT_MAX) {
f -= FRACT_MAX;
m += 1;
}
timer0_fract = f;
timer0_millis = m;
timer0_overflow_count++;
}
unsigned long millis()
{
unsigned long m;
uint8_t oldSREG = SREG;
// disable interrupts while we read timer0_millis or we might get an
// inconsistent value (e.g. in the middle of a write to timer0_millis)
cli();
m = timer0_millis;
SREG = oldSREG;
return m;
}
unsigned long micros() {
unsigned long m;
uint8_t oldSREG = SREG, t;
cli();
m = timer0_overflow_count;
#if defined(TCNT0)
t = TCNT0;
#elif defined(TCNT0L)
t = TCNT0L;
#else
#error TIMER 0 not defined
#endif
#ifdef TIFR0
if ((TIFR0 & _BV(TOV0)) && (t < 255))
m++;
#else
if ((TIFR & _BV(TOV0)) && (t < 255))
m++;
#endif
SREG = oldSREG;
return ((m << 8) + t) * (64 / clockCyclesPerMicrosecond());
}
void delay(unsigned long ms)
{
uint16_t start = (uint16_t)micros();
while (ms > 0) {
if (((uint16_t)micros() - start) >= 1000) {
ms--;
start += 1000;
}
}
}
/* Delay for the given number of microseconds. Assumes a 8 or 16 MHz clock. */
void delayMicroseconds(unsigned int us)
{
// calling avrlib's delay_us() function with low values (e.g. 1 or
// 2 microseconds) gives delays longer than desired.
//delay_us(us);
#if F_CPU >= 16000000L
// for the 16 MHz clock on most Arduino boards
// for a one-microsecond delay, simply return. the overhead
// of the function call yields a delay of approximately 1 1/8 us.
if (--us == 0)
return;
// the following loop takes a quarter of a microsecond (4 cycles)
// per iteration, so execute it four times for each microsecond of
// delay requested.
us <<= 2;
// account for the time taken in the preceeding commands.
us -= 2;
#else
// for the 8 MHz internal clock on the ATmega168
// for a one- or two-microsecond delay, simply return. the overhead of
// the function calls takes more than two microseconds. can't just
// subtract two, since us is unsigned; we'd overflow.
if (--us == 0)
return;
if (--us == 0)
return;
// the following loop takes half of a microsecond (4 cycles)
// per iteration, so execute it twice for each microsecond of
// delay requested.
us <<= 1;
// partially compensate for the time taken by the preceeding commands.
// we can't subtract any more than this or we'd overflow w/ small delays.
us--;
#endif
// busy wait
__asm__ __volatile__ (
"1: sbiw %0,1" "\n\t" // 2 cycles
"brne 1b" : "=w" (us) : "0" (us) // 2 cycles
);
}
void init()
{
// this needs to be called before setup() or some functions won't
// work there
sei();
// on the ATmega168, timer 0 is also used for fast hardware pwm
// (using phase-correct PWM would mean that timer 0 overflowed half as often
// resulting in different millis() behavior on the ATmega8 and ATmega168)
#if defined(TCCR0A) && defined(WGM01)
sbi(TCCR0A, WGM01);
sbi(TCCR0A, WGM00);
#endif
// set timer 0 prescale factor to 64
#if defined(__AVR_ATmega128__)
// CPU specific: different values for the ATmega128
sbi(TCCR0, CS02);
#elif defined(TCCR0) && defined(CS01) && defined(CS00)
// this combination is for the standard atmega8
sbi(TCCR0, CS01);
sbi(TCCR0, CS00);
#elif defined(TCCR0B) && defined(CS01) && defined(CS00)
// this combination is for the standard 168/328/1280/2560
sbi(TCCR0B, CS01);
sbi(TCCR0B, CS00);
#elif defined(TCCR0A) && defined(CS01) && defined(CS00)
// this combination is for the __AVR_ATmega645__ series
sbi(TCCR0A, CS01);
sbi(TCCR0A, CS00);
#else
#error Timer 0 prescale factor 64 not set correctly
#endif
// enable timer 0 overflow interrupt
#if defined(TIMSK) && defined(TOIE0)
sbi(TIMSK, TOIE0);
#elif defined(TIMSK0) && defined(TOIE0)
sbi(TIMSK0, TOIE0);
#else
#error Timer 0 overflow interrupt not set correctly
#endif
// timers 1 and 2 are used for phase-correct hardware pwm
// this is better for motors as it ensures an even waveform
// note, however, that fast pwm mode can achieve a frequency of up
// 8 MHz (with a 16 MHz clock) at 50% duty cycle
TCCR1B = 0;
// set timer 1 prescale factor to 64
#if defined(TCCR1B) && defined(CS11) && defined(CS10)
sbi(TCCR1B, CS11);
sbi(TCCR1B, CS10);
#elif defined(TCCR1) && defined(CS11) && defined(CS10)
sbi(TCCR1, CS11);
sbi(TCCR1, CS10);
#endif
// put timer 1 in 8-bit phase correct pwm mode
#if defined(TCCR1A) && defined(WGM10)
sbi(TCCR1A, WGM10);
#elif defined(TCCR1)
#warning this needs to be finished
#endif
// set timer 2 prescale factor to 64
#if defined(TCCR2) && defined(CS22)
sbi(TCCR2, CS22);
#elif defined(TCCR2B) && defined(CS22)
sbi(TCCR2B, CS22);
#else
#warning Timer 2 not finished (may not be present on this CPU)
#endif
// configure timer 2 for phase correct pwm (8-bit)
#if defined(TCCR2) && defined(WGM20)
sbi(TCCR2, WGM20);
#elif defined(TCCR2A) && defined(WGM20)
sbi(TCCR2A, WGM20);
#else
#warning Timer 2 not finished (may not be present on this CPU)
#endif
#if defined(TCCR3B) && defined(CS31) && defined(WGM30)
sbi(TCCR3B, CS31); // set timer 3 prescale factor to 64
sbi(TCCR3B, CS30);
sbi(TCCR3A, WGM30); // put timer 3 in 8-bit phase correct pwm mode
#endif
#if defined(TCCR4B) && defined(CS41) && defined(WGM40)
sbi(TCCR4B, CS41); // set timer 4 prescale factor to 64
sbi(TCCR4B, CS40);
sbi(TCCR4A, WGM40); // put timer 4 in 8-bit phase correct pwm mode
#endif
#if defined(TCCR5B) && defined(CS51) && defined(WGM50)
sbi(TCCR5B, CS51); // set timer 5 prescale factor to 64
sbi(TCCR5B, CS50);
sbi(TCCR5A, WGM50); // put timer 5 in 8-bit phase correct pwm mode
#endif
#if defined(ADCSRA)
// set a2d prescale factor to 128
// 16 MHz / 128 = 125 KHz, inside the desired 50-200 KHz range.
// XXX: this will not work properly for other clock speeds, and
// this code should use F_CPU to determine the prescale factor.
sbi(ADCSRA, ADPS2);
sbi(ADCSRA, ADPS1);
sbi(ADCSRA, ADPS0);
// enable a2d conversions
sbi(ADCSRA, ADEN);
#endif
// the bootloader connects pins 0 and 1 to the USART; disconnect them
// here so they can be used as normal digital i/o; they will be
// reconnected in Serial.begin()
#if defined(UCSRB)
UCSRB = 0;
#elif defined(UCSR0B)
UCSR0B = 0;
#endif
}

View File

@ -0,0 +1,138 @@
/*
wiring.h - Partial implementation of the Wiring API for the ATmega8.
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id$
*/
#ifndef Wiring_h
#define Wiring_h
#include <avr/io.h>
#include <stdlib.h>
#include "binary.h"
#ifdef __cplusplus
extern "C"{
#endif
#define HIGH 0x1
#define LOW 0x0
#define INPUT 0x0
#define OUTPUT 0x1
#define true 0x1
#define false 0x0
#define PI 3.1415926535897932384626433832795
#define HALF_PI 1.5707963267948966192313216916398
#define TWO_PI 6.283185307179586476925286766559
#define DEG_TO_RAD 0.017453292519943295769236907684886
#define RAD_TO_DEG 57.295779513082320876798154814105
#define SERIAL 0x0
#define DISPLAY 0x1
#define LSBFIRST 0
#define MSBFIRST 1
#define CHANGE 1
#define FALLING 2
#define RISING 3
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define INTERNAL1V1 2
#define INTERNAL2V56 3
#else
#define INTERNAL 3
#endif
#define DEFAULT 1
#define EXTERNAL 0
// undefine stdlib's abs if encountered
#ifdef abs
#undef abs
#endif
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(x) ((x)>0?(x):-(x))
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
// Removed to work with newer AVRLIBC
//#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
#define radians(deg) ((deg)*DEG_TO_RAD)
#define degrees(rad) ((rad)*RAD_TO_DEG)
#define sq(x) ((x)*(x))
#define interrupts() sei()
#define noInterrupts() cli()
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
#define microsecondsToClockCycles(a) ( ((a) * (F_CPU / 1000L)) / 1000L )
#define lowByte(w) ((uint8_t) ((w) & 0xff))
#define highByte(w) ((uint8_t) ((w) >> 8))
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
typedef unsigned int word;
#define bit(b) (1UL << (b))
typedef uint8_t boolean;
typedef uint8_t byte;
void init(void);
void pinMode(uint8_t, uint8_t);
void digitalWrite(uint8_t, uint8_t);
int digitalRead(uint8_t);
int analogRead(uint8_t);
void analogReference(uint8_t mode);
void analogWrite(uint8_t, int);
unsigned long millis(void);
unsigned long micros(void);
void delay(unsigned long);
void delayMicroseconds(unsigned int us);
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
void attachInterrupt(uint8_t, void (*)(void), int mode);
void detachInterrupt(uint8_t);
void setup(void);
void loop(void);
#ifdef __cplusplus
} // extern "C"
#endif
#endif

View File

@ -0,0 +1,259 @@
/*
wiring_analog.c - analog input and output
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
Modified 28 September 2010 by Mark Sproul
$Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
*/
#include "wiring_private.h"
#include "pins_arduino.h"
uint8_t analog_reference = DEFAULT;
void analogReference(uint8_t mode)
{
// can't actually set the register here because the default setting
// will connect AVCC and the AREF pin, which would cause a short if
// there's something connected to AREF.
analog_reference = mode;
}
int analogRead(uint8_t pin)
{
uint8_t low, high;
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
if (pin >= 54) pin -= 54; // allow for channel or pin numbers
#else
if (pin >= 14) pin -= 14; // allow for channel or pin numbers
#endif
#if defined(ADCSRB) && defined(MUX5)
// the MUX5 bit of ADCSRB selects whether we're reading from channels
// 0 to 7 (MUX5 low) or 8 to 15 (MUX5 high).
ADCSRB = (ADCSRB & ~(1 << MUX5)) | (((pin >> 3) & 0x01) << MUX5);
#endif
// set the analog reference (high two bits of ADMUX) and select the
// channel (low 4 bits). this also sets ADLAR (left-adjust result)
// to 0 (the default).
#if defined(ADMUX)
ADMUX = (analog_reference << 6) | (pin & 0x07);
#endif
// without a delay, we seem to read from the wrong channel
//delay(1);
#if defined(ADCSRA) && defined(ADCL)
// start the conversion
sbi(ADCSRA, ADSC);
// ADSC is cleared when the conversion finishes
while (bit_is_set(ADCSRA, ADSC));
// we have to read ADCL first; doing so locks both ADCL
// and ADCH until ADCH is read. reading ADCL second would
// cause the results of each conversion to be discarded,
// as ADCL and ADCH would be locked when it completed.
low = ADCL;
high = ADCH;
#else
// we dont have an ADC, return 0
low = 0;
high = 0;
#endif
// combine the two bytes
return (high << 8) | low;
}
// Right now, PWM output only works on the pins with
// hardware support. These are defined in the appropriate
// pins_*.c file. For the rest of the pins, we default
// to digital output.
void analogWrite(uint8_t pin, int val)
{
// We need to make sure the PWM output is enabled for those pins
// that support it, as we turn it off when digitally reading or
// writing with them. Also, make sure the pin is in output mode
// for consistenty with Wiring, which doesn't require a pinMode
// call for the analog output pins.
pinMode(pin, OUTPUT);
if (val == 0)
{
digitalWrite(pin, LOW);
}
else if (val == 255)
{
digitalWrite(pin, HIGH);
}
else
{
switch(digitalPinToTimer(pin))
{
// XXX fix needed for atmega8
#if defined(TCCR0) && defined(COM00) && !defined(__AVR_ATmega8__)
case TIMER0A:
// connect pwm to pin on timer 0
sbi(TCCR0, COM00);
OCR0 = val; // set pwm duty
break;
#endif
#if defined(TCCR0A) && defined(COM0A1)
case TIMER0A:
// connect pwm to pin on timer 0, channel A
sbi(TCCR0A, COM0A1);
OCR0A = val; // set pwm duty
break;
#endif
#if defined(TCCR0A) && defined(COM0B1)
case TIMER0B:
// connect pwm to pin on timer 0, channel B
sbi(TCCR0A, COM0B1);
OCR0B = val; // set pwm duty
break;
#endif
#if defined(TCCR1A) && defined(COM1A1)
case TIMER1A:
// connect pwm to pin on timer 1, channel A
sbi(TCCR1A, COM1A1);
OCR1A = val; // set pwm duty
break;
#endif
#if defined(TCCR1A) && defined(COM1B1)
case TIMER1B:
// connect pwm to pin on timer 1, channel B
sbi(TCCR1A, COM1B1);
OCR1B = val; // set pwm duty
break;
#endif
#if defined(TCCR2) && defined(COM21)
case TIMER2:
// connect pwm to pin on timer 2
sbi(TCCR2, COM21);
OCR2 = val; // set pwm duty
break;
#endif
#if defined(TCCR2A) && defined(COM2A1)
case TIMER2A:
// connect pwm to pin on timer 2, channel A
sbi(TCCR2A, COM2A1);
OCR2A = val; // set pwm duty
break;
#endif
#if defined(TCCR2A) && defined(COM2B1)
case TIMER2B:
// connect pwm to pin on timer 2, channel B
sbi(TCCR2A, COM2B1);
OCR2B = val; // set pwm duty
break;
#endif
#if defined(TCCR3A) && defined(COM3A1)
case TIMER3A:
// connect pwm to pin on timer 3, channel A
sbi(TCCR3A, COM3A1);
OCR3A = val; // set pwm duty
break;
#endif
#if defined(TCCR3A) && defined(COM3B1)
case TIMER3B:
// connect pwm to pin on timer 3, channel B
sbi(TCCR3A, COM3B1);
OCR3B = val; // set pwm duty
break;
#endif
#if defined(TCCR3A) && defined(COM3C1)
case TIMER3C:
// connect pwm to pin on timer 3, channel C
sbi(TCCR3A, COM3C1);
OCR3C = val; // set pwm duty
break;
#endif
#if defined(TCCR4A) && defined(COM4A1)
case TIMER4A:
// connect pwm to pin on timer 4, channel A
sbi(TCCR4A, COM4A1);
OCR4A = val; // set pwm duty
break;
#endif
#if defined(TCCR4A) && defined(COM4B1)
case TIMER4B:
// connect pwm to pin on timer 4, channel B
sbi(TCCR4A, COM4B1);
OCR4B = val; // set pwm duty
break;
#endif
#if defined(TCCR4A) && defined(COM4C1)
case TIMER4C:
// connect pwm to pin on timer 4, channel C
sbi(TCCR4A, COM4C1);
OCR4C = val; // set pwm duty
break;
#endif
#if defined(TCCR5A) && defined(COM5A1)
case TIMER5A:
// connect pwm to pin on timer 5, channel A
sbi(TCCR5A, COM5A1);
OCR5A = val; // set pwm duty
break;
#endif
#if defined(TCCR5A) && defined(COM5B1)
case TIMER5B:
// connect pwm to pin on timer 5, channel B
sbi(TCCR5A, COM5B1);
OCR5B = val; // set pwm duty
break;
#endif
#if defined(TCCR5A) && defined(COM5C1)
case TIMER5C:
// connect pwm to pin on timer 5, channel C
sbi(TCCR5A, COM5C1);
OCR5C = val; // set pwm duty
break;
#endif
case NOT_ON_TIMER:
default:
if (val < 128) {
digitalWrite(pin, LOW);
} else {
digitalWrite(pin, HIGH);
}
}
}
}

View File

@ -0,0 +1,166 @@
/*
wiring_digital.c - digital input and output functions
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
Modified 28 September 2010 by Mark Sproul
$Id: wiring.c 248 2007-02-03 15:36:30Z mellis $
*/
#include "wiring_private.h"
#include "pins_arduino.h"
void pinMode(uint8_t pin, uint8_t mode)
{
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *reg;
if (port == NOT_A_PIN) return;
// JWS: can I let the optimizer do this?
reg = portModeRegister(port);
if (mode == INPUT) {
uint8_t oldSREG = SREG;
cli();
*reg &= ~bit;
SREG = oldSREG;
} else {
uint8_t oldSREG = SREG;
cli();
*reg |= bit;
SREG = oldSREG;
}
}
// Forcing this inline keeps the callers from having to push their own stuff
// on the stack. It is a good performance win and only takes 1 more byte per
// user than calling. (It will take more bytes on the 168.)
//
// But shouldn't this be moved into pinMode? Seems silly to check and do on
// each digitalread or write.
//
// Mark Sproul:
// - Removed inline. Save 170 bytes on atmega1280
// - changed to a switch statment; added 32 bytes but much easier to read and maintain.
// - Added more #ifdefs, now compiles for atmega645
//
//static inline void turnOffPWM(uint8_t timer) __attribute__ ((always_inline));
//static inline void turnOffPWM(uint8_t timer)
static void turnOffPWM(uint8_t timer)
{
switch (timer)
{
#if defined(TCCR1A) && defined(COM1A1)
case TIMER1A: cbi(TCCR1A, COM1A1); break;
#endif
#if defined(TCCR1A) && defined(COM1B1)
case TIMER1B: cbi(TCCR1A, COM1B1); break;
#endif
#if defined(TCCR2) && defined(COM21)
case TIMER2: cbi(TCCR2, COM21); break;
#endif
#if defined(TCCR0A) && defined(COM0A1)
case TIMER0A: cbi(TCCR0A, COM0A1); break;
#endif
#if defined(TIMER0B) && defined(COM0B1)
case TIMER0B: cbi(TCCR0A, COM0B1); break;
#endif
#if defined(TCCR2A) && defined(COM2A1)
case TIMER2A: cbi(TCCR2A, COM2A1); break;
#endif
#if defined(TCCR2A) && defined(COM2B1)
case TIMER2B: cbi(TCCR2A, COM2B1); break;
#endif
#if defined(TCCR3A) && defined(COM3A1)
case TIMER3A: cbi(TCCR3A, COM3A1); break;
#endif
#if defined(TCCR3A) && defined(COM3B1)
case TIMER3B: cbi(TCCR3A, COM3B1); break;
#endif
#if defined(TCCR3A) && defined(COM3C1)
case TIMER3C: cbi(TCCR3A, COM3C1); break;
#endif
#if defined(TCCR4A) && defined(COM4A1)
case TIMER4A: cbi(TCCR4A, COM4A1); break;
#endif
#if defined(TCCR4A) && defined(COM4B1)
case TIMER4B: cbi(TCCR4A, COM4B1); break;
#endif
#if defined(TCCR4A) && defined(COM4C1)
case TIMER4C: cbi(TCCR4A, COM4C1); break;
#endif
#if defined(TCCR5A)
case TIMER5A: cbi(TCCR5A, COM5A1); break;
case TIMER5B: cbi(TCCR5A, COM5B1); break;
case TIMER5C: cbi(TCCR5A, COM5C1); break;
#endif
}
}
void digitalWrite(uint8_t pin, uint8_t val)
{
uint8_t timer = digitalPinToTimer(pin);
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
volatile uint8_t *out;
if (port == NOT_A_PIN) return;
// If the pin that support PWM output, we need to turn it off
// before doing a digital write.
if (timer != NOT_ON_TIMER) turnOffPWM(timer);
out = portOutputRegister(port);
if (val == LOW) {
uint8_t oldSREG = SREG;
cli();
*out &= ~bit;
SREG = oldSREG;
} else {
uint8_t oldSREG = SREG;
cli();
*out |= bit;
SREG = oldSREG;
}
}
int digitalRead(uint8_t pin)
{
uint8_t timer = digitalPinToTimer(pin);
uint8_t bit = digitalPinToBitMask(pin);
uint8_t port = digitalPinToPort(pin);
if (port == NOT_A_PIN) return LOW;
// If the pin that support PWM output, we need to turn it off
// before getting a digital reading.
if (timer != NOT_ON_TIMER) turnOffPWM(timer);
if (*portInputRegister(port) & bit) return HIGH;
return LOW;
}

View File

@ -0,0 +1,70 @@
/*
wiring_private.h - Internal header file.
Part of Arduino - http://www.arduino.cc/
Copyright (c) 2005-2006 David A. Mellis
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., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
$Id: wiring.h 239 2007-01-12 17:58:39Z mellis $
*/
#ifndef WiringPrivate_h
#define WiringPrivate_h
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/delay.h>
#include <stdio.h>
#include <stdarg.h>
#include "wiring.h"
#ifdef __cplusplus
extern "C"{
#endif
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
#define EXTERNAL_INT_0 0
#define EXTERNAL_INT_1 1
#define EXTERNAL_INT_2 2
#define EXTERNAL_INT_3 3
#define EXTERNAL_INT_4 4
#define EXTERNAL_INT_5 5
#define EXTERNAL_INT_6 6
#define EXTERNAL_INT_7 7
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define EXTERNAL_NUM_INTERRUPTS 8
#elif defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)
#define EXTERNAL_NUM_INTERRUPTS 3
#else
#define EXTERNAL_NUM_INTERRUPTS 2
#endif
typedef void (*voidFuncPtr)(void);
#ifdef __cplusplus
} // extern "C"
#endif
#endif

Some files were not shown because too many files have changed in this diff Show More