1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-30 11:24:12 +01:00

Merge branch 'master' of github.com:arduino/32U4 into LUFA_bootloader

This commit is contained in:
Zach Eveland 2012-04-07 16:00:42 -04:00
commit 79ffd4fa1b
1094 changed files with 0 additions and 244188 deletions

View File

@ -1,22 +0,0 @@
#!/bin/sh
APPDIR="$(dirname -- $(readlink -f -- "${0}") )"
cd $APPDIR
for LIB in \
java/lib/rt.jar \
java/lib/tools.jar \
lib/*.jar \
;
do
CLASSPATH="${CLASSPATH}:${LIB}"
done
export CLASSPATH
LD_LIBRARY_PATH=`pwd`/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
export LD_LIBRARY_PATH
export PATH="${APPDIR}/java/bin:${PATH}"
java -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel processing.app.Base

View File

@ -1,15 +0,0 @@
/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor
This example code is in the public domain.
*/
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
}

View File

@ -1,9 +0,0 @@
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}

View File

@ -1,19 +0,0 @@
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
}

View File

@ -1,19 +0,0 @@
/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the serial monitor
This example code is in the public domain.
*/
void setup() {
Serial.begin(9600);
pinMode(2, INPUT);
}
void loop() {
int sensorValue = digitalRead(2);
Serial.println(sensorValue);
}

View File

@ -1,31 +0,0 @@
/*
Fade
This example shows how to fade an LED on pin 9
using the analogWrite() function.
This example code is in the public domain.
*/
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
void setup() {
// declare pin 9 to be an output:
pinMode(9, OUTPUT);
}
void loop() {
// set the brightness of pin 9:
analogWrite(9, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
// wait for 30 milliseconds to see the dimming effect
delay(30);
}

View File

@ -1,65 +0,0 @@
/* Blink without Delay
Turns on and off a light emitting diode(LED) connected to a digital
pin, without using the delay() function. This means that other code
can run at the same time without being interrupted by the LED code.
The circuit:
* LED attached from pin 13 to ground.
* Note: on most Arduinos, there is already an LED on the board
that's attached to pin 13, so no hardware is needed for this example.
created 2005
by David A. Mellis
modified 8 Feb 2010
by Paul Stoffregen
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
*/
// constants won't change. Used here to
// set pin numbers:
const int ledPin = 13; // the number of the LED pin
// Variables will change:
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
// the follow variables is a long because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long interval = 1000; // interval at which to blink (milliseconds)
void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
}
void loop()
{
// here is where you'd put code that needs to be running all the time.
// check to see if it's time to blink the LED; that is, if the
// difference between the current time and last time you blinked
// the LED is bigger than the interval at which you want to
// blink the LED.
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
}

View File

@ -1,56 +0,0 @@
/*
Button
Turns on and off a light emitting diode(LED) connected to digital
pin 13, when pressing a pushbutton attached to pin 2.
The circuit:
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground
* Note: on most Arduinos there is already an LED on the board
attached to pin 13.
created 2005
by DojoDave <http://www.0j0.org>
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Button
*/
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}

View File

@ -1,75 +0,0 @@
/*
Debounce
Each time the input pin goes from LOW to HIGH (e.g. because of a push-button
press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's
a minimum delay between toggles to debounce the circuit (i.e. to ignore
noise).
The circuit:
* LED attached from pin 13 to ground
* pushbutton attached from pin 2 to +5V
* 10K resistor attached from pin 2 to ground
* Note: On most Arduino boards, there is already an LED on the board
connected to pin 13, so you don't need any extra components for this example.
created 21 November 2006
by David A. Mellis
modified 30 Aug 2011
by Limor Fried
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Debounce
*/
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// Variables will change:
int ledState = HIGH; // the current state of the output pin
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
}
void loop() {
// read the state of the switch into a local variable:
int reading = digitalRead(buttonPin);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited
// long enough since the last press to ignore any noise:
// If the switch changed, due to noise or pressing:
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:
buttonState = reading;
}
// set the LED using the state of the button:
digitalWrite(ledPin, buttonState);
// save the reading. Next time through the loop,
// it'll be the lastButtonState:
lastButtonState = reading;
}

View File

@ -1,52 +0,0 @@
/*
Input Pullup Serial
This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a
digital input on pin 2 and prints the results to the serial monitor.
The circuit:
* Momentary switch attached from pin 2 to ground
* Built-in LED on pin 13
Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal
20K-ohm resistor is pulled to 5V. This configuration causes the input to
read HIGH when the switch is open, and LOW when it is closed.
created 14 March 2012
by Scott Fitzgerald
http://www.arduino.cc/en/Tutorial/InputPullupSerial
This example code is in the public domain
*/
void setup(){
//start serial connection
Serial.begin(9600);
//configure pin2 as an input and enable the internal pull-up resistor
pinMode(2, INPUT_PULLUP);
pinMode(13, OUTPUT);
}
void loop(){
//read the pushbutton value into a variable
int sensorVal = digitalRead(2);
//print out the value of the pushbutton
Serial.println(sensorVal);
// Keep in mind the pullup means the pushbutton's
// logic is inverted. It goes HIGH when it's open,
// and LOW when it's pressed. Turn on pin 13 when the
// button's pressed, and off when it's not:
if (sensorVal == HIGH) {
digitalWrite(13, LOW);
}
else {
digitalWrite(13, HIGH);
}
}

View File

@ -1,92 +0,0 @@
/*
State change detection (edge detection)
Often, you don't need to know the state of a digital input all the time,
but you just need to know when the input changes from one state to another.
For example, you want to know when a button goes from OFF to ON. This is called
state change detection, or edge detection.
This example shows how to detect when a button or button changes from off to on
and on to off.
The circuit:
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground
* LED attached from pin 13 to ground (or use the built-in LED on
most Arduino boards)
created 27 Sep 2005
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://arduino.cc/en/Tutorial/ButtonStateChange
*/
// this constant won't change:
const int buttonPin = 2; // the pin that the pushbutton is attached to
const int ledPin = 13; // the pin that the LED is attached to
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
void setup() {
// initialize the button pin as a input:
pinMode(buttonPin, INPUT);
// initialize the LED as an output:
pinMode(ledPin, OUTPUT);
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
buttonPushCounter++;
Serial.println("on");
Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
}
else {
// if the current state is LOW then the button
// wend from on to off:
Serial.println("off");
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
// turns on the LED every four button pushes by
// checking the modulo of the button push counter.
// the modulo function gives you the remainder of
// the division of two numbers:
if (buttonPushCounter % 4 == 0) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}

View File

@ -1,95 +0,0 @@
/*************************************************
* Public Constants
*************************************************/
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978

View File

@ -1,45 +0,0 @@
/*
keyboard
Plays a pitch that changes based on a changing analog input
circuit:
* 3 force-sensing resistors from +5V to analog in 0 through 5
* 3 10K resistors from analog in 0 through 5 to ground
* 8-ohm speaker on digital pin 8
created 21 Jan 2010
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://arduino.cc/en/Tutorial/Tone3
*/
#include "pitches.h"
const int threshold = 10; // minimum reading of the sensors that generates a note
// notes to play, corresponding to the 3 sensors:
int notes[] = {
NOTE_A4, NOTE_B4,NOTE_C3 };
void setup() {
}
void loop() {
for (int thisSensor = 0; thisSensor < 3; thisSensor++) {
// get a sensor reading:
int sensorReading = analogRead(thisSensor);
// if the sensor is pressed hard enough:
if (sensorReading > threshold) {
// play the note corresponding to this sensor:
tone(8, notes[thisSensor], 20);
}
}
Serial.println();
}

View File

@ -1,95 +0,0 @@
/*************************************************
* Public Constants
*************************************************/
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978

View File

@ -1,49 +0,0 @@
/*
Melody
Plays a melody
circuit:
* 8-ohm speaker on digital pin 8
created 21 Jan 2010
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://arduino.cc/en/Tutorial/Tone
*/
#include "pitches.h"
// notes in the melody:
int melody[] = {
NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4, 8, 8, 4,4,4,4,4 };
void setup() {
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 8; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/noteDurations[thisNote];
tone(8, melody[thisNote],noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);
}
}
void loop() {
// no need to repeat the melody.
}

View File

@ -1,95 +0,0 @@
/*************************************************
* Public Constants
*************************************************/
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978

View File

@ -1,42 +0,0 @@
/*
Multiple tone player
Plays multiple tones on multiple pins in sequence
circuit:
* 3 8-ohm speaker on digital pins 6, 7, and 11
created 8 March 2010
by Tom Igoe
based on a snippet from Greg Borenstein
This example code is in the public domain.
http://arduino.cc/en/Tutorial/Tone4
*/
void setup() {
}
void loop() {
// turn off tone function for pin 11:
noTone(11);
// play a note on pin 6 for 200 ms:
tone(6, 440, 200);
delay(200);
// turn off tone function for pin 6:
noTone(6);
// play a note on pin 7 for 500 ms:
tone(7, 494, 500);
delay(500);
// turn off tone function for pin 7:
noTone(7);
// play a note on pin 11 for 500 ms:
tone(11, 523, 300);
delay(300);
}

View File

@ -1,46 +0,0 @@
/*
Pitch follower
Plays a pitch that changes based on a changing analog input
circuit:
* 8-ohm speaker on digital pin 8
* photoresistor on analog 0 to 5V
* 4.7K resistor on analog 0 to ground
created 21 Jan 2010
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://arduino.cc/en/Tutorial/Tone2
*/
void setup() {
// initialize serial communications (for debugging only):
Serial.begin(9600);
}
void loop() {
// read the sensor:
int sensorReading = analogRead(A0);
// print the sensor reading so you know its range
Serial.println(sensorReading);
// map the pitch to the range of the analog input.
// change the minimum and maximum input numbers below
// depending on the range your sensor's giving:
int thisPitch = map(sensorReading, 400, 1000, 100, 1000);
// play the pitch:
tone(9, thisPitch, 10);
}

View File

@ -1,53 +0,0 @@
/*
Analog input, analog output, serial output
Reads an analog input pin, maps the result to a range from 0 to 255
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
Also prints the results to the serial monitor.
The circuit:
* potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
* LED connected from digital pin 9 to ground
created 29 Dec. 2008
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
*/
// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);
// print the results to the serial monitor:
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);
// wait 10 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(10);
}

View File

@ -1,50 +0,0 @@
/*
Analog Input
Demonstrates analog input by reading an analog sensor on analog pin 0 and
turning on and off a light emitting diode(LED) connected to digital pin 13.
The amount of time the LED will be on and off depends on
the value obtained by analogRead().
The circuit:
* Potentiometer attached to analog input 0
* center pin of the potentiometer to the analog pin
* one side pin (either one) to ground
* the other side pin to +5V
* LED anode (long leg) attached to digital output 13
* LED cathode (short leg) attached to ground
* Note: because most Arduinos have a built-in LED attached
to pin 13 on the board, the LED is optional.
Created by David Cuartielles
modified 30 Aug 2011
By Tom Igoe
This example code is in the public domain.
http://arduino.cc/en/Tutorial/AnalogInput
*/
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}

View File

@ -1,45 +0,0 @@
/*
Mega analogWrite() test
This sketch fades LEDs up and down one at a time on digital pins 2 through 13.
This sketch was written for the Arduino Mega, and will not work on previous boards.
The circuit:
* LEDs attached from pins 2 through 13 to ground.
created 8 Feb 2009
by Tom Igoe
This example code is in the public domain.
*/
// These constants won't change. They're used to give names
// to the pins used:
const int lowestPin = 2;
const int highestPin = 13;
void setup() {
// set pins 2 through 13 as outputs:
for (int thisPin =lowestPin; thisPin <= highestPin; thisPin++) {
pinMode(thisPin, OUTPUT);
}
}
void loop() {
// iterate over the pins:
for (int thisPin =lowestPin; thisPin <= highestPin; thisPin++) {
// fade the LED on thisPin from off to brightest:
for (int brightness = 0; brightness < 255; brightness++) {
analogWrite(thisPin, brightness);
delay(2);
}
// fade the LED on thisPin from brithstest to off:
for (int brightness = 255; brightness >= 0; brightness--) {
analogWrite(thisPin, brightness);
delay(2);
}
// pause between LEDs:
delay(100);
}
}

View File

@ -1,75 +0,0 @@
/*
Calibration
Demonstrates one technique for calibrating sensor input. The
sensor readings during the first five seconds of the sketch
execution define the minimum and maximum of expected values
attached to the sensor pin.
The sensor minimum and maximum initial values may seem backwards.
Initially, you set the minimum high and listen for anything
lower, saving it as the new minimum. Likewise, you set the
maximum low and listen for anything higher as the new maximum.
The circuit:
* Analog sensor (potentiometer will do) attached to analog input 0
* LED attached from digital pin 9 to ground
created 29 Oct 2008
By David A Mellis
modified 30 Aug 2011
By Tom Igoe
http://arduino.cc/en/Tutorial/Calibration
This example code is in the public domain.
*/
// These constants won't change:
const int sensorPin = A0; // pin that the sensor is attached to
const int ledPin = 9; // pin that the LED is attached to
// variables:
int sensorValue = 0; // the sensor value
int sensorMin = 1023; // minimum sensor value
int sensorMax = 0; // maximum sensor value
void setup() {
// turn on LED to signal the start of the calibration period:
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
// calibrate during the first five seconds
while (millis() < 5000) {
sensorValue = analogRead(sensorPin);
// record the maximum sensor value
if (sensorValue > sensorMax) {
sensorMax = sensorValue;
}
// record the minimum sensor value
if (sensorValue < sensorMin) {
sensorMin = sensorValue;
}
}
// signal the end of the calibration period
digitalWrite(13, LOW);
}
void loop() {
// read the sensor:
sensorValue = analogRead(sensorPin);
// apply the calibration to the sensor reading
sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);
// in case the sensor value is outside the range seen during calibration
sensorValue = constrain(sensorValue, 0, 255);
// fade the LED using the calibrated value:
analogWrite(ledPin, sensorValue);
}

View File

@ -1,45 +0,0 @@
/*
Fading
This example shows how to fade an LED using the analogWrite() function.
The circuit:
* LED attached from digital pin 9 to ground.
Created 1 Nov 2008
By David A. Mellis
modified 30 Aug 2011
By Tom Igoe
http://arduino.cc/en/Tutorial/Fading
This example code is in the public domain.
*/
int ledPin = 9; // LED connected to digital pin 9
void setup() {
// nothing happens in setup
}
void loop() {
// fade in from min to max in increments of 5 points:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
}

View File

@ -1,67 +0,0 @@
/*
Smoothing
Reads repeatedly from an analog input, calculating a running average
and printing it to the computer. Keeps ten readings in an array and
continually averages them.
The circuit:
* Analog sensor (potentiometer will do) attached to analog input 0
Created 22 April 2007
modified 30 Aug 2011
By David A. Mellis <dam@mellis.org>
http://www.arduino.cc/en/Tutorial/Smoothing
This example code is in the public domain.
*/
// Define the number of samples to keep track of. The higher the number,
// the more the readings will be smoothed, but the slower the output will
// respond to the input. Using a constant rather than a normal variable lets
// use this value to determine the size of the readings array.
const int numReadings = 10;
int readings[numReadings]; // the readings from the analog input
int index = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average
int inputPin = A0;
void setup()
{
// initialize serial communication with computer:
Serial.begin(9600);
// initialize all the readings to 0:
for (int thisReading = 0; thisReading < numReadings; thisReading++)
readings[thisReading] = 0;
}
void loop() {
// subtract the last reading:
total= total - readings[index];
// read from the sensor:
readings[index] = analogRead(inputPin);
// add the reading to the total:
total= total + readings[index];
// advance to the next position in the array:
index = index + 1;
// if we're at the end of the array...
if (index >= numReadings)
// ...wrap around to the beginning:
index = 0;
// calculate the average:
average = total / numReadings;
// send it to the computer as ASCII digits
Serial.println(average);
}

View File

@ -1,77 +0,0 @@
/*
ASCII table
Prints out byte values in all possible formats:
* as raw binary values
* as ASCII-encoded decimal, hex, octal, and binary values
For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII
The circuit: No external hardware needed.
created 2006
by Nicholas Zambetti
modified 2 Apr 2012
by Tom Igoe
This example code is in the public domain.
<http://www.zambetti.com>
*/
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) ;
// prints title with ending line break
Serial.println("ASCII Table ~ Character Map");
}
// first visible ASCIIcharacter '!' is number 33:
int thisByte = 33;
// you can also write ASCII characters in single quotes.
// for example. '!' is the same as 33, so you could also use this:
//int thisByte = '!';
void loop() {
// prints value unaltered, i.e. the raw binary version of the
// byte. The serial monitor interprets all bytes as
// ASCII, so 33, the first number, will show up as '!'
Serial.write(thisByte);
Serial.print(", dec: ");
// prints value as string as an ASCII-encoded decimal (base 10).
// Decimal is the default format for Serial.print() and Serial.println(),
// so no modifier is needed:
Serial.print(thisByte);
// But you can declare the modifier for decimal if you want to.
//this also works if you uncomment it:
// Serial.print(thisByte, DEC);
Serial.print(", hex: ");
// prints value as string in hexadecimal (base 16):
Serial.print(thisByte, HEX);
Serial.print(", oct: ");
// prints value as string in octal (base 8);
Serial.print(thisByte, OCT);
Serial.print(", bin: ");
// prints value as string in binary (base 2)
// also prints ending line break:
Serial.println(thisByte, BIN);
// if printed last visible character '~' or 126, stop:
if(thisByte == 126) { // you could also use if (thisByte == '~') {
// This loop loops forever and does nothing
while(true) {
continue;
}
}
// go on to the next character
thisByte++;
}

View File

@ -1,112 +0,0 @@
/*
Dimmer
Demonstrates the sending data from the computer to the Arduino board,
in this case to control the brightness of an LED. The data is sent
in individual bytes, each of which ranges from 0 to 255. Arduino
reads these bytes and uses them to set the brightness of the LED.
The circuit:
LED attached from digital pin 9 to ground.
Serial connection to Processing, Max/MSP, or another serial application
created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe and Scott Fitzgerald
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Dimmer
*/
const int ledPin = 9; // the pin that the LED is attached to
void setup()
{
// initialize the serial communication:
Serial.begin(9600);
// initialize the ledPin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
byte brightness;
// check if data has been sent from the computer:
if (Serial.available()) {
// read the most recent byte (which will be from 0 to 255):
brightness = Serial.read();
// set the brightness of the LED:
analogWrite(ledPin, brightness);
}
}
/* Processing code for this example
// Dimmer - sends bytes over a serial port
// by David A. Mellis
//This example code is in the public domain.
import processing.serial.*;
Serial port;
void setup() {
size(256, 150);
println("Available serial ports:");
println(Serial.list());
// Uses the first port in this list (number 0). Change this to
// select the port corresponding to your Arduino board. The last
// parameter (e.g. 9600) is the speed of the communication. It
// has to correspond to the value passed to Serial.begin() in your
// Arduino sketch.
port = new Serial(this, Serial.list()[0], 9600);
// If you know the name of the port used by the Arduino board, you
// can specify it directly like this.
//port = new Serial(this, "COM1", 9600);
}
void draw() {
// draw a gradient from black to white
for (int i = 0; i < 256; i++) {
stroke(i);
line(i, 0, i, 150);
}
// write the current X-position of the mouse to the serial port as
// a single byte
port.write(mouseX);
}
*/
/* Max/MSP v5 patch for this example
----------begin_max5_patcher----------
1008.3ocuXszaiaCD9r8uhA5rqAeHIa0aAMaAVf1S6hdoYQAsDiL6JQZHQ2M
YWr+2KeX4vjnjXKKkKhhiGQ9MeyCNz+X9rnMp63sQvuB+MLa1OlOalSjUvrC
ymEUytKuh05TKJWUWyk5nE9eSyuS6jesvHu4F4MxOuUzB6X57sPKWVzBLXiP
xZtGj6q2vafaaT0.BzJfjj.p8ZPukazsQvpfcpFs8mXR3plh8BoBxURIOWyK
rxspZ0YI.eTCEh5Vqp+wGtFXZMKe6CZc3yWZwTdCmYW.BBkdiby8v0r+ST.W
sD9SdUkn8FYspPbqvnBNFtZWiUyLmleJWo0vuKzeuj2vpJLaWA7YiE7wREui
FpDFDp1KcbAFcP5sJoVxp4NB5Jq40ougIDxJt1wo3GDZHiNocKhiIExx+owv
AdOEAksDs.RRrOoww1Arc.9RvN2J9tamwjkcqknvAE0l+8WnjHqreNet8whK
z6mukIK4d+Xknv3jstvJs8EirMMhxsZIusET25jXbX8xczIl5xPVxhPcTGFu
xNDu9rXtUCg37g9Q8Yc+EuofIYmg8QdkPCrOnXsaHwYs3rWx9PGsO+pqueG2
uNQBqWFh1X7qQG+3.VHcHrfO1nyR2TlqpTM9MDsLKNCQVz6KO.+Sfc5j1Ykj
jzkn2jwNDRP7LVb3d9LtoWBAOnvB92Le6yRmZ4UF7YpQhiFi7A5Ka8zXhKdA
4r9TRGG7V4COiSbAJKdXrWNhhF0hNUh7uBa4Mba0l7JUK+omjDMwkSn95Izr
TOwkdp7W.oPRmNRQsiKeu4j3CkfVgt.NYPEYqMGvvJ48vIlPiyzrIuZskWIS
xGJPcmPiWOfLodybH3wjPbMYwlbFIMNHPHFOtLBNaLSa9sGk1TxMzCX5KTa6
WIH2ocxSdngM0QPqFRxyPHFsprrhGc9Gy9xoBjz0NWdR2yW9DUa2F85jG2v9
FgTO4Q8qiC7fzzQNpmNpsY3BrYPVJBMJQ1uVmoItRhw9NrVGO3NMNzYZ+zS7
3WTvTOnUydG5kHMKLqAOjTe7fN2bGSxOZDkMrBrGQ9J1gONBEy0k4gVo8qHc
cxmfxVihWz6a3yqY9NazzUYkua9UnynadOtogW.JfsVGRVNEbWF8I+eHtcwJ
+wLXqZeSdWLo+FQF6731Tva0BISKTx.cLwmgJsUTTvkg1YsnXmxDge.CDR7x
D6YmX6fMznaF7kdczmJXwm.XSOOrdoHhNA7GMiZYLZZR.+4lconMaJP6JOZ8
ftCs1YWHZI3o.sIXezX5ihMSuXzZtk3ai1mXRSczoCS32hAydeyXNEu5SHyS
xqZqbd3ZLdera1iPqYxOm++v7SUSz
-----------end_max5_patcher-----------
*/

View File

@ -1,149 +0,0 @@
/*
Graph
A simple example of communication from the Arduino board to the computer:
the value of analog input 0 is sent out the serial port. We call this "serial"
communication because the connection appears to both the Arduino and the
computer as a serial port, even though it may actually use
a USB cable. Bytes are sent one after another (serially) from the Arduino
to the computer.
You can use the Arduino serial monitor to view the sent data, or it can
be read by Processing, PD, Max/MSP, or any other program capable of reading
data from a serial port. The Processing code below graphs the data received
so you can see the value of the analog input changing over time.
The circuit:
Any analog input sensor is attached to analog in pin 0.
created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe and Scott Fitzgerald
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Graph
*/
void setup() {
// initialize the serial communication:
Serial.begin(9600);
}
void loop() {
// send the value of analog input 0:
Serial.println(analogRead(A0));
// wait a bit for the analog-to-digital converter
// to stabilize after the last reading:
delay(10);
}
/* Processing code for this example
// Graphing sketch
// This program takes ASCII-encoded strings
// from the serial port at 9600 baud and graphs them. It expects values in the
// range 0 to 1023, followed by a newline, or newline and carriage return
// Created 20 Apr 2005
// Updated 18 Jan 2008
// by Tom Igoe
// This example code is in the public domain.
import processing.serial.*;
Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph
void setup () {
// set the window size:
size(400, 300);
// List all the available serial ports
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 9600);
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
// set inital background:
background(0);
}
void draw () {
// everything happens in the serialEvent()
}
void serialEvent (Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// convert to an int and map to the screen height:
float inByte = float(inString);
inByte = map(inByte, 0, 1023, 0, height);
// draw the line:
stroke(127,34,255);
line(xPos, height, xPos, height - inByte);
// at the edge of the screen, go back to the beginning:
if (xPos >= width) {
xPos = 0;
background(0);
}
else {
// increment the horizontal position:
xPos++;
}
}
}
*/
/* Max/MSP v5 patch for this example
----------begin_max5_patcher----------
1591.3oc0YszbaaCD9r7uBL5RalQUAO3CvdyS5zVenWZxs5NcfHgjPCIfJIT
RTxj+6AOHkoTDooroUs0AQPR73a+1cwtK3WtZxzEpOwqlB9YveAlL4KWMYh6
Q1GLo99ISKXeJMmU451zTUQAWpmNy+NM+SZ2y+sR1l02JuU9t0hJvFlNcMPy
dOuBv.U5Rgb0LPpRpYBooM3529latArTUVvzZdFPtsXAuDrrTU.f.sBffXxL
vGE50lIHkUVJXq3fRtdaoDvjYfbgjujaFJSCzq4.tLaN.bi1tJefWpqbO0uz
1IjIABoluxrJ1guxh2JfPO2B5zRNyBCLDFcqbwNvuv9fHCb8bvevyyEU2JKT
YhkBSWPAfq2TZ6YhqmuMUo0feUn+rYpY4YtY+cFw3lUJdCMYAapZqzwUHX8S
crjAd+SIOU6UBAwIygy.Q1+HAA1KH6EveWOFQlitUK92ehfal9kFhUxJ3tWc
sgpxadigWExbt1o7Ps5dk3yttivyg20W0VcSmg1G90qtx92rAZbH4ez.ruy1
nhmaDPidE07J+5n2sg6E6oKXxUSmc20o6E3SPRDbrkXnPGUYE.i5nCNB9TxQ
jG.G0kCTZtH88f07Rt0ZMMWUw8VvbKVAaTk6GyoraPdZff7rQTejBN54lgyv
HE0Ft7AvIvvgvIwO23jBdUkYOuSvIFSiNcjFhiSsUBwsUCh1AgfNSBAeNDBZ
DIDqY.f8.YjfjV1HAn9XDTxyNFYatVTkKx3kcK9GraZpI5jv7GOx+Z37Xh82
LSKHIDmDXaESoXRngIZQDKVkpxUkMCyXCQhcCK1z.G457gi3TzMz4RFD515F
G3bIQQwcP3SOF0zlkGhiCBQ1kOHHFFlXaEBQIQnCwv9QF1LxPZ.A4jR5cyQs
vbvHMJsLll01We+rE2LazX6zYmCraRrsPFwKg1ANBZFY.IAihr8Ox.aH0oAL
hB8nQVw0FSJiZeunOykbT6t3r.NP8.iL+bnwNiXuVMNJH9H9YCm89CFXPBER
bz422p8.O4dg6kRxdyjDqRwMIHTbT3QFLskxJ8tbmQK4tm0XGeZWF7wKKtYY
aTAF.XPNFaaQBinQMJ4QLF0aNHF0JtYuHSxoUZfZY6.UU2ejJTb8lQw8Fo5k
Rv6e2PI+fOM71o2ecY1VgTYdCSxxUqLokuYq9jYJi6lxPgD2NIPePLB0mwbG
YA9Rgxdiu1k5xiLlSU6JVnx6wzg3sYHwTesB8Z5D7RiGZpXyvDNJY.DQX3.H
hvmcUN4bP1yCkhpTle2P37jtBsKrLWcMScEmltOPv22ZfAqQAdKr9HzATQwZ
q18PrUGt6Tst2XMCRUfGuhXs6ccn23YloomMqcTiC5iMGPsHsHRWhWFlaenV
XcqwgCQiGGJzptyS2ZMODBz6fGza0bzmXBj7+DA94bvpR01MffAlueO7HwcI
pWCwmzJdvi9ILgflLAFmyXB6O7ML0YbD26lenmcGxjVsZUN+A6pUK7AtTrPg
M+eRYG0qD9j4I7eEbco8Xh6WcO.or9XDC6UCiewbXHkh6xm5LiPEkzpJDRTu
mEB44Fgz4NCtJvX.SM1vo2SlTCZGAe7GZu6ahdRyzFOhYZ+mbVVSYptBw.K1
tboIkatIA7c1cTKD1u.honLYV04VkluHsXe0szv9pQCE9Ro3jaVB1o15pz2X
zYoBvO5KXCAe0LCYJybE8ZODf4fV8t9qW0zYxq.YJfTosj1bv0xc.SaC0+AV
9V9L.KKyV3SyTcRtmzi6rO.O16USvts4B5xe9EymDvebK0eMfW6+NIsNlE2m
eqRyJ0utRq13+RjmqYKN1e.4d61jjdsauXe3.2p6jgi9hsNIv97CoyJ01xzl
c3ZhUCtSHx3UZgjoEJYqNY+hYs5zZQVFW19L3JDYaTlMLqAAt1G2yXlnFg9a
53L1FJVcv.cOX0dh7mCVGCLce7GFcQwDdH5Ta3nyAS0pQbHxegr+tGIZORgM
RnMj5vGl1Fs16drnk7Tf1XOLgv1n0d2iEsCxR.eQsNOZ4FGF7whofgfI3kES
1kCeOX5L2rifbdu0A9ae2X.V33B1Z+.Bj1FrP5iFrCYCG5EUWSG.hhunHJd.
HJ5hhnng3h9HPj4lud02.1bxGw.
-----------end_max5_patcher-----------
*/

View File

@ -1,49 +0,0 @@
/*
MIDI note player
This sketch shows how to use the serial transmit pin (pin 1) to send MIDI note data.
If this circuit is connected to a MIDI synth, it will play
the notes F#-0 (0x1E) to F#-5 (0x5A) in sequence.
The circuit:
* digital in 1 connected to MIDI jack pin 5
* MIDI jack pin 2 connected to ground
* MIDI jack pin 4 connected to +5V through 220-ohm resistor
Attach a MIDI cable to the jack, then to a MIDI synth, and play music.
created 13 Jun 2006
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/MIDI
*/
void setup() {
// Set MIDI baud rate:
Serial.begin(31250);
}
void loop() {
// play notes from F#-0 (0x1E) to F#-5 (0x5A):
for (int note = 0x1E; note < 0x5A; note ++) {
//Note on channel 1 (0x90), some note value (note), middle velocity (0x45):
noteOn(0x90, note, 0x45);
delay(100);
//Note on channel 1 (0x90), some note value (note), silent velocity (0x00):
noteOn(0x90, note, 0x00);
delay(100);
}
}
// plays a MIDI note. Doesn't check to see that
// cmd is greater than 127, or that data values are less than 127:
void noteOn(int cmd, int pitch, int velocity) {
Serial.write(cmd);
Serial.write(pitch);
Serial.write(velocity);
}

View File

@ -1,33 +0,0 @@
/*
Mega multple serial test
Receives from the main serial port, sends to the others.
Receives from serial port 1, sends to the main serial (Serial 0).
This example works only on the Arduino Mega
The circuit:
* Any serial device attached to Serial port 1
* Serial monitor open on Serial port 0:
created 30 Dec. 2008
by Tom Igoe
This example code is in the public domain.
*/
void setup() {
// initialize both serial ports:
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
// read from port 1, send to port 0:
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
}
}

View File

@ -1,170 +0,0 @@
/*
Physical Pixel
An example of using the Arduino board to receive data from the
computer. In this case, the Arduino boards turns on an LED when
it receives the character 'H', and turns off the LED when it
receives the character 'L'.
The data can be sent from the Arduino serial monitor, or another
program like Processing (see code below), Flash (via a serial-net
proxy), PD, or Max/MSP.
The circuit:
* LED connected from digital pin 13 to ground
created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe and Scott Fitzgerald
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/PhysicalPixel
*/
const int ledPin = 13; // the pin that the LED is attached to
int incomingByte; // a variable to read incoming serial data into
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
}
void loop() {
// see if there's incoming serial data:
if (Serial.available() > 0) {
// read the oldest byte in the serial buffer:
incomingByte = Serial.read();
// if it's a capital H (ASCII 72), turn on the LED:
if (incomingByte == 'H') {
digitalWrite(ledPin, HIGH);
}
// if it's an L (ASCII 76) turn off the LED:
if (incomingByte == 'L') {
digitalWrite(ledPin, LOW);
}
}
}
/* Processing code for this example
// mouseover serial
// Demonstrates how to send data to the Arduino I/O board, in order to
// turn ON a light if the mouse is over a square and turn it off
// if the mouse is not.
// created 2003-4
// based on examples by Casey Reas and Hernando Barragan
// modified 30 Aug 2011
// by Tom Igoe
// This example code is in the public domain.
import processing.serial.*;
float boxX;
float boxY;
int boxSize = 20;
boolean mouseOverBox = false;
Serial port;
void setup() {
size(200, 200);
boxX = width/2.0;
boxY = height/2.0;
rectMode(RADIUS);
// List all the available serial ports in the output pane.
// You will need to choose the port that the Arduino board is
// connected to from this list. The first port in the list is
// port #0 and the third port in the list is port #2.
println(Serial.list());
// Open the port that the Arduino board is connected to (in this case #0)
// Make sure to open the port at the same speed Arduino is using (9600bps)
port = new Serial(this, Serial.list()[0], 9600);
}
void draw()
{
background(0);
// Test if the cursor is over the box
if (mouseX > boxX-boxSize && mouseX < boxX+boxSize &&
mouseY > boxY-boxSize && mouseY < boxY+boxSize) {
mouseOverBox = true;
// draw a line around the box and change its color:
stroke(255);
fill(153);
// send an 'H' to indicate mouse is over square:
port.write('H');
}
else {
// return the box to it's inactive state:
stroke(153);
fill(153);
// send an 'L' to turn the LED off:
port.write('L');
mouseOverBox = false;
}
// Draw the box
rect(boxX, boxY, boxSize, boxSize);
}
*/
/*
Max/MSP version 5 patch to run with this example:
----------begin_max5_patcher----------
1672.3oc2ZszaaiCD9ryuBBebQVCQRYao8xhf1cQCPVfBzh8RRQ.sDsM2HSZ
HQmlzh9eu7gjsjsEk7y0oWjiHoHm4aluYHGlueUmtiDuPy5B9Cv8fNc99Uc5
XZR2Pm726zcF4knDRlYXciDylQ4xtWa6SReQZZ+iSeMiEQR.ej8BM4A9C7OO
kkAlSjQSAYTdbFfvA27o2c6sfO.Doqd6NfXgDHmRUCKkolg4hT06BfbQJGH3
5Qd2e8d.QJIQSow5tzebZ7BFW.FIHow8.2JAQpVIIYByxo9KIMkSjL9D0BRT
sbGHZJIkDoZOSMuQT.8YZ5qpgGI3locF4IpQRzq2nDF+odZMIJkRjpEF44M3
A9nWAum7LKFbSOv+PSRXYOvmIhYiYpg.8A2LOUOxPyH+TjPJA+MS9sIzTRRr
QP9rXF31IBZAHpVHkHrfaPRHLuUCzoj9GSoQRqIB52y6Z.tu8o4EX+fddfuj
+MrXiwPL5+9cXwrOVvkbxLpomazHbQO7EyX7DpzXYgkFdF6algCQpkX4XUlo
hA6oa7GWck9w0Gnmy6RXQOoQeCfWwlzsdnHLTq8n9PCHLv7Cxa6PAN3RCKjh
ISRVZ+sSl704Tqt0kocE9R8J+P+RJOZ4ysp6gN0vppBbOTEN8qp0YCq5bq47
PUwfA5e766z7NbGMuncw7VgNRSyQhbnPMGrDsGaFSvKM5NcWoIVdZn44.eOi
9DTRUT.7jDQzSTiF4UzXLc7tLGh4T9pwaFQkGUGIiOOkpBSJUwGsBd40krHQ
9XEvwq2V6eLIhV6GuzP7uzzXBmzsXPSRYwBtVLp7s5lKVv6UN2VW7xRtYDbx
7s7wRgHYDI8YVFaTBshkP49R3rYpH3RlUhTQmK5jMadJyF3cYaTNQMGSyhRE
IIUlJaOOukdhoOyhnekEKmZlqU3UkLrk7bpPrpztKBVUR1uorLddk6xIOqNt
lBOroRrNVFJGLrDxudpET4kzkstNp2lzuUHVMgk5TDZx9GWumnoQTbhXsEtF
tzCcM+z0QKXsngCUtTOEIN0SX2iHTTIIz968.Kf.uhfzUCUuAd3UKd.OKt.N
HTynxTQyjpQD9jlwEXeKQxfHCBahUge6RprSa2V4m3aYOMyaP6gah2Yf1zbD
jVwZVGFZHHxINFxpjr5CiTS9JiZn6e6nTlXQZTAFj6QCppQwzL0AxVtoi6WE
QXsANkEGWMEuwNvhmKTnat7A9RqLq6pXuEwY6xM5xRraoTiurj51J1vKLzFs
CvM7HI14Mpje6YRxHOSieTsJpvJORjxT1nERK6s7YTN7sr6rylNwf5zMiHI4
meZ4rTYt2PpVettZERbjJ6PjfqN2loPSrUcusH01CegsGEE5467rnCdqT1ES
QxtCvFq.cvGz+BaAHXKzRSfP+2Jf.KCvj5ZLJRAhwi+SWHvPyN3vXiaPn6JR
3eoA.0TkFhTvpsDMIrL20nAkCI4EoYfSHAuiPBdmJRyd.IynYYjIzMvjOTKf
3DLvnvRLDLpWeEOYXMfAZqfQ0.qsnlUdmA33t8CNJ7MZEb.u7fiZHLYzDkJp
R7CqEVLGN75U+1JXxFUY.xEEBcRCqhOEkz2bENEWnh4pbh0wY25EefbD6EmW
UA6Ip8wFLyuFXx+Wrp8m6iff1B86W7bqJO9+mx8er4E3.abCLrYdA16sBuHx
vKT6BlpIGQIhL55W7oicf3ayv3ixQCm4aQuY1HZUPQWY+cASx2WZ3f1fICuz
vj5R5ZbM1y8gXYN4dIXaYGq4NhQvS5MmcDADy+S.j8CQ78vk7Q7gtPDX3kFh
3NGaAsYBUAO.8N1U4WKycxbQdrWxJdXd10gNIO+hkUMmm.CZwknu7JbNUYUq
0sOsTsI1QudDtjw0t+xZ85wWZd80tMCiiMADNX4UzrcSeK23su87IANqmA7j
tiRzoXi2YRh67ldAk79gPmTe3YKuoY0qdEDV3X8xylCJMTN45JIakB7uY8XW
uVr3PO8wWwEoTW8lsfraX7ZqzZDDXCRqNkztHsGCYpIDDAOqxDpMVUMKcOrp
942acPvx2NPocMC1wQZ8glRn3myTykVaEUNLoEeJjVaAevA4EAZnsNgkeyO+
3rEZB7f0DTazDcQTNmdt8aACGi1QOWnMmd+.6YjMHH19OB5gKsMF877x8wsJ
hN97JSnSfLUXGUoj6ujWXd6Pk1SAC+Pkogm.tZ.1lX1qL.pe6PE11DPeMMZ2
.P0K+3peBt3NskC
-----------end_max5_patcher-----------
*/

View File

@ -1,211 +0,0 @@
/*
Serial Call and Response
Language: Wiring/Arduino
This program sends an ASCII A (byte of value 65) on startup
and repeats that until it gets some data in.
Then it waits for a byte in the serial port, and
sends three sensor values whenever it gets a byte in.
Thanks to Greg Shakar and Scott Fitzgerald for the improvements
The circuit:
* potentiometers attached to analog inputs 0 and 1
* pushbutton attached to digital I/O 2
Created 26 Sept. 2005
by Tom Igoe
modified 30 Aug 2011
by Tom Igoe and Scott Fitzgerald
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/SerialCallResponse
*/
int firstSensor = 0; // first analog sensor
int secondSensor = 0; // second analog sensor
int thirdSensor = 0; // digital sensor
int inByte = 0; // incoming serial byte
void setup()
{
// start serial port at 9600 bps:
Serial.begin(9600);
pinMode(2, INPUT); // digital sensor is on digital pin 2
establishContact(); // send a byte to establish contact until receiver responds
}
void loop()
{
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
// read first analog input, divide by 4 to make the range 0-255:
firstSensor = analogRead(A0)/4;
// delay 10ms to let the ADC recover:
delay(10);
// read second analog input, divide by 4 to make the range 0-255:
secondSensor = analogRead(1)/4;
// read switch, map it to 0 or 255L
thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
// send sensor values:
Serial.write(firstSensor);
Serial.write(secondSensor);
Serial.write(thirdSensor);
}
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.print('A'); // send a capital A
delay(300);
}
}
/*
Processing sketch to run with this example:
// This example code is in the public domain.
import processing.serial.*;
int bgcolor; // Background color
int fgcolor; // Fill color
Serial myPort; // The serial port
int[] serialInArray = new int[3]; // Where we'll put what we receive
int serialCount = 0; // A count of how many bytes we receive
int xpos, ypos; // Starting position of the ball
boolean firstContact = false; // Whether we've heard from the microcontroller
void setup() {
size(256, 256); // Stage size
noStroke(); // No border on the next thing drawn
// Set the starting position of the ball (middle of the stage)
xpos = width/2;
ypos = height/2;
// Print a list of the serial ports, for debugging purposes:
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}
void draw() {
background(bgcolor);
fill(fgcolor);
// Draw the shape
ellipse(xpos, ypos, 20, 20);
}
void serialEvent(Serial myPort) {
// read a byte from the serial port:
int inByte = myPort.read();
// if this is the first byte received, and it's an A,
// clear the serial buffer and note that you've
// had first contact from the microcontroller.
// Otherwise, add the incoming byte to the array:
if (firstContact == false) {
if (inByte == 'A') {
myPort.clear(); // clear the serial port buffer
firstContact = true; // you've had first contact from the microcontroller
myPort.write('A'); // ask for more
}
}
else {
// Add the latest byte from the serial port to array:
serialInArray[serialCount] = inByte;
serialCount++;
// If we have 3 bytes:
if (serialCount > 2 ) {
xpos = serialInArray[0];
ypos = serialInArray[1];
fgcolor = serialInArray[2];
// print the values (for debugging purposes only):
println(xpos + "\t" + ypos + "\t" + fgcolor);
// Send a capital A to request new sensor readings:
myPort.write('A');
// Reset serialCount:
serialCount = 0;
}
}
}
*/
/*
Max/MSP version 5 patch to run with this example:
----------begin_max5_patcher----------
2569.3oc2as0jiZqD9YO+Jzw09PRc75BIAX671TaUop8gy4gLoNmG1YqsjAY
rxhAGPLW1T4+dZIAd.aCFeiEuYqXFABQqu9qa0Rp0ec2fgyiegmND8KnOgFL
3utav.8sT2XPd4ACWwdwKjkpq1vU7zTV.e3Hyyj7Wj5665Tbq3LYHWJecM2z
tCGh9b9iVyjdKEQAeIg6IMOkRmM1ZDx10UcgRF6LBgmN1Zy6H70se77+38yJ
9DKhijQrU5Ovv6SDrvhmDksRDAedsvRJU8Tw2zUGSfuyl5ZjUckwpa922cm5
mQsDLh3OCx0NXQJODgqENlyhBFNpkvBchFVzfCwZ+vh60DVHm.r3EuZEORtC
t7.WISnOvBCe+uwSWGGkxQnGidL5AdjeJhgl+pjifuNRtjiRMUecbhbDhE4i
R3LnVTcsRQhnwHzCfXhVDmvChyfZ3EGFmLB8x53Tyq7J7Wn3EPS6IR7B4nrT
.n0M+SrvLnYR3xrjHtOZQR7ps+tiMh2+MVx+EzuuTjhz5JDzSy.KAn5Lir5y
eR3AhdjtTL7SBB5SpO8VMIBZjfXsPDC2GpCCojIP1L89EFIC45f9o6e3Ce7i
n6+YUCmJYIxr0iA4.ZvuxUxwyLgo+ajDUCLR8AizsLfnQn7l.8LbW9SfXIjv
qAZdzJ.1P9LIartS5AvqDvArM590I.ayZ1iQyeE8fWrTh9Ug7aA7DVnuFW+c
.q9XP7F+.ghHtGnBzJZLtdhsskshK6PLV85BXmZL3cNRlM9XX1VWPlsLQD.n
C5m.Mwmje9mUpDOE4RDrT99P9BIPMidBdUAP5AV08ggFdSB6YEWPgoqShg2Q
yOeV.OeIa8ZPSNmq32n+C6Efq9m.kETcfimb96Xz+WotkJtYgTrPjvA9Onn2
gE.bNV5WQ2m3mIhh0LmRs0d0lz5UlDiWJGKGs1jXtTixz8lQalvEQBIHVvGM
UqlBXJONOqQZi2BvfjosuWrWPiTOngmXo8oatfoZPiZWCnYeq.ZdK4desvWD
GXYdBQtmLvk1iCu+wgJ12bdfHBLF.QNyioLGTVCKjJGSFPW8vUYQBySUtKWw
70t0f+bdXr2WQoKy.i.+3miNZJqsqA8czvNgRajxR6aneMQbrF.XkqDMzaFo
6wgmV.YDrNjCWaC.4psvwypAfH6Ef9e7DeVDauPDcePjUcAkUVN4I4.SNx.s
gHTMjVJvSJU6ACeq23nGfYlsoKYYT1khiBv6.Ekhq6SVE2zmu3XZiXvO8a0W
WiJ+Tslhn0f+YvFRSv296xxBkeY+fS0muf4wq8kqQULXXPhvONRIFUdW0sK9
f.Gvn6cJK45ZDwVumWVFGGNmk7jHULOjWQS.rYVjXE39TJLRDDWQwCEqVmHL
VratGOhAswxTuj3vvJMk4IOsmmXB95YgubotsdCupL8lRLmJ1YUteiS2opQ2
hjf4.H4T7+kqT81b0Fw+DGSrPZRyro5Bk7Kssom8jxeuZ8OUa3+6ZDhG6LyA
OcR0Wb6oHMnvok4OFcs.VK0+NOHkjCoF5ryrCBot2zPZkwF1cFoJVZy.ZwLS
2YFp0xYsLwvXtXlBOA2..6TK.ukep5FYsgQW2C5R6FzcMChIw5RvXMF+4DV7
TqCBnzSFPsOE.sinq+afR0HPpG03PV+UHm1GFKImLVR9QGKycj1ZnDe6BkMM
vDDVMKYDZMCvrXXtMn2gQuifdGE8N6KhgewExAGpx5ldnJs7b1rRmIpUKNmN
taHqauXRSqETZfYU5IEy7U0fC6cfAlT137vnwrenQCp0QgFtV8Tzv74FdfQ5
HSGSg+y1dj9uaWWF2pXs1ZIKNht7aScTs1L0LKLcuQ878iEowYIdE58h.dPU
6S97ToHZybo+zaNH2phKE99Um4pFtE9qiAJUt.h9bqzdGsb6zV41s+I231H2
S5WxMts3shPQ5OxM4XjaZuQtUCt1d415FTtw8K4d1wf23aP4lzqvaWq1J2N8
K+fsUtc6W768LL3sgbO46gbmeSnCX1tjT1Sb+u.eFHDwuvjxDw7LoIDrxaex
4uaBM9vCsYFAgwyYg4asylVoRauiTscac2aHwkYmzrpcWyJOsi8NkCb995N8
sLYptT1wYxMRpL8udeCYxzAQjolDBf51BDw4FAQToB.LfJ9DS2MCjju8ylcV
rVHwtuAIx3ffP9YyGLoKhY8JpsySabC1u1pWqSS8hM6RrcqTuV2PoyXCo2Y6
xmwbduYKMroMAL1S6aIzXnmesc+PQpT08KtpLBF0xbrXV9pz3t4x9vC5rivT
v9xo2kpTPLrQq8Qsydvwjze1js23fJcSmiNWRveuxj0mXga7OsuEl1jTWtlt
sIGdqqaiut85SJIixVMmmbHEu1tuIkus6jRnfiaiJ+aJcOoAcusILPWyfbGP
2Os+o7anaianaSlRZc2lX8CKmmZWFFZlySH8OR+EBFJFfKGFbZDF5g190LhX
Vzao5wgvnRWZAR4XxF37zsrVnZ10EpnWNn5agnfj3r0HZ8QR2xnGrMAMNA23
.HG+3njuSrHHdZnKBbnCeFgZWr0XSbU4YgEooXqoVWyLZldIym7PAXpsjmvU
oMtWXbJe6iRSCCGQMo4MYlgzX03Anh3dyjj8U.EUh3dLXxz7T51oMXxj9FlT
2IOTSMNwUiI2xwvRn6jfnU.Dbea550AH5SYF6TONl1k3H13lPDbu67XVmYyG
pX1DvA3Aolut5joTx1Isov5yWzJCIgXMoQim9lsyYtvcDhwzHOPNRwu6kUf+
9rvc+4JtLI9sjcrlAUaQ2rXfTmlTwXxMi6.8Yr3z7FjuBlFRuYY7q0a.8lY4
L0F7LzLWKqyZ0sx4KTrloLswU6EeUOHeWx02323L+Buhhn0YRz7rEKTmm4m3
IuBFXnUhPv6I2KNxO8nO8iTy4IKeo.sZ5vOhuYNwnlAXTGna0gztokIwrj.X
WCLfabXDbmECl9qWMO8Lvw16+cNnry9dWIsNpYKuUl.kpzNa2892p6czPsUj
bnsPlbONQhByHUkxwTr5B0d5lRmov51BYcVmBeTbKDIpS2JSUxFwZjIxrtWl
tzTehEUwrbLqlH1rP5UKkmgyDplCpKctFLSZQOYKqpCawfmYRR+7oXYuoz4h
6VsQZmzstbZCWvw9z74XN+h1NlSrdkRTmxnqtTW37zoas9IsxgNoakIRakIb
24QpshDoyDI21.Szt0w8V1g0jNmS6TYBa2VGHGAcpXHByvG1jYaJ0INIrNM2
cj7kmjtozYJsaoJuLCuctHXaFDaqHw5GbPqN0klNltCF3WG65uMy4gP6dYhb
H9T2RmZ07HNRmD4tzv4KbOAuozkHpxCQzvc7LLZiSBR25jffuBy5IWORw5KE
CagO+YWiuFKOA0VOzDY5zRRqtz4Jszqgz5ZjVWqxRqpTWXei6VWyXx0d4nfB
+8c+C81VE7B
-----------end_max5_patcher-----------
*/

View File

@ -1,228 +0,0 @@
/*
Serial Call and Response in ASCII
Language: Wiring/Arduino
This program sends an ASCII A (byte of value 65) on startup
and repeats that until it gets some data in.
Then it waits for a byte in the serial port, and
sends three ASCII-encoded, comma-separated sensor values,
truncated by a linefeed and carriage return,
whenever it gets a byte in.
Thanks to Greg Shakar and Scott Fitzgerald for the improvements
The circuit:
* potentiometers attached to analog inputs 0 and 1
* pushbutton attached to digital I/O 2
Created 26 Sept. 2005
by Tom Igoe
modified 2 Apr 2012
by Tom Igoe and Scott Fitzgerald
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/SerialCallResponseASCII
*/
int firstSensor = 0; // first analog sensor
int secondSensor = 0; // second analog sensor
int thirdSensor = 0; // digital sensor
int inByte = 0; // incoming serial byte
void setup()
{
// start serial port at 9600 bps and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) ;
;
pinMode(2, INPUT); // digital sensor is on digital pin 2
establishContact(); // send a byte to establish contact until receiver responds
}
void loop()
{
// if we get a valid byte, read analog ins:
if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
// read first analog input:
firstSensor = analogRead(A0);
// read second analog input:
secondSensor = analogRead(A1);
// read switch, map it to 0 or 255L
thirdSensor = map(digitalRead(2), 0, 1, 0, 255);
// send sensor values:
Serial.print(firstSensor);
Serial.print(",");
Serial.print(secondSensor);
Serial.print(",");
Serial.println(thirdSensor);
}
}
void establishContact() {
while (Serial.available() <= 0) {
Serial.println("0,0,0"); // send an initial string
delay(300);
}
}
/*
Processing code to run with this example:
// This example code is in the public domain.
import processing.serial.*; // import the Processing serial library
Serial myPort; // The serial port
float bgcolor; // Background color
float fgcolor; // Fill color
float xpos, ypos; // Starting position of the ball
void setup() {
size(640,480);
// List all the available serial ports
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Arduino module, so I open Serial.list()[0].
// Change the 0 to the appropriate number of the serial port
// that your microcontroller is attached to.
myPort = new Serial(this, Serial.list()[0], 9600);
// read bytes into a buffer until you get a linefeed (ASCII 10):
myPort.bufferUntil('\n');
// draw with smooth edges:
smooth();
}
void draw() {
background(bgcolor);
fill(fgcolor);
// Draw the shape
ellipse(xpos, ypos, 20, 20);
}
// serialEvent method is run automatically by the Processing applet
// whenever the buffer reaches the byte value set in the bufferUntil()
// method in the setup():
void serialEvent(Serial myPort) {
// read the serial buffer:
String myString = myPort.readStringUntil('\n');
// if you got any bytes other than the linefeed:
myString = trim(myString);
// split the string at the commas
// and convert the sections into integers:
int sensors[] = int(split(myString, ','));
// print out the values you got:
for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) {
print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t");
}
// add a linefeed after all the sensor values are printed:
println();
if (sensors.length > 1) {
xpos = map(sensors[0], 0,1023,0,width);
ypos = map(sensors[1], 0,1023,0,height);
fgcolor = sensors[2];
}
// send a byte to ask for more data:
myPort.write("A");
}
*/
/*
Max/MSP version 5 patch to run with this example:
----------begin_max5_patcher----------
3365.3oc4bk0iiaiD9Y2+J3JLOrAq6Fhj5LOscRP.lGxtCxDr6CYBFHaQaqL
xRNRzcOcBx+8s3grkZac31Vr8jMASKScPU7qNXUTUw+3lIVyx+LqzB80neFM
YxebyjIxSINwDc6IVqi977znR4sYMOe8ZVF2Zp5Zb1m4pyuJOujghPkrhjnT
zl7BNZQQ9ZDeURIBdlsUOyh7LdYxuyDOGlbms9zYaWmjkx3x2Cd+Iy2xqNa0
stIhOeUR1xOVvlyUTuuqOzSHRfs7fspEz.8K5GJIVRn4y90ao90okrn0RZw5
dAkaItvedyMh+LcffRF6QnaO.SzPQnmsM5eFskmmugkgrOebfzNNPbbDibJU
hCXG2tvArSEsn5b9SaXptwJQviQVV6drKCRslUVFsjcn3SJH8bJ.C4n.Ctcf
gRjhDTaO4gPI7DbbbgfaEWtz.RKhNR7XVT1xSASrOYLITJrfUG75VVwqULQR
mlAWRyihOUXAepvhiGsNrX2ErPbtFfkMELvzRrzp6nBM9Dk5CUJq3G1IzDXL
snsuz4WR3r054+rduzb86jPHxZp3OyxyWK92seS5VFX+lu5128c2e6s3c2w9
K7C4wr0G47hG38OkMe2k99jB12m9zsgem+2b66e261CFMYCz1YCdJ7WaLiX2
oHJE2qU9FV5EWWiIlU5MZi3vnJ+pANhxagvfNwMxq8r.bz7TVTw3pQqkgHRa
dNzNQDZqHhhPMCr.JsEFQJQgIjt8kz40VJo.dwrKjoeRufBNTZrwizInztyB
igWks.LhvOJeBLfmd4jVlmmlWnFJXABXeWPnMNzS7Ka8uv0.ki4htxQK2.0b
nNcAj9u1BWI77nSA8nlB8TBfNdcgdAcNwmY.veOEsDzP2b9A2P5GTTg031oQ
bmqAUyRVJP7HrMBSOekyN7ThXqfDao7le2g3X2su7S2ezTwE64NtAE6Js93D
HQGJ4N21CJN701TDHyfvipZTEb3JssP6z1hWuxJWZXoskdSE2B5aiRSu8GYk
axyJYn6e+2912h9P1GxdO3ScIJBM6IvKAfXQ7Ur5qR2TTD36cAKBtKp94XYP
vLwSQhWoXI81DUDwYwHTR1TDuXa1bYyYOA8aZRFaAiEeG5sx9NCtedIZQdAa
Y9VnqkF8mh97l7R065I3Wn7EvyNOo.bbDssD3CR55gHHtoRfZ3aKxf2fdEDa
Pv2gjiq+UNm80neRr5hRVIBvIHNvR31iTCxX1CIygwblrEDKFq.Ihy.d0OqK
QPmrLWRD4v4EwhfDzDPaJXaghxPdtn+tBht+qDcbIOpfucyc.c.c3mXB53wn
D03WQIhNXZEvHYEYZT9dzivYYO.jUBGdLPhFsFfMTbDO5N4fbNvWDHM1Ac+l
BQjdgeHCf82OOmyQeeB+2WxJhRik35OAX0aWly9P11MwxGihQ+6477YLwih2
o7HXYyAdiT9ASGy0k0QY3UpP45nVTx.uiqR4ZYD8EdQxR.0P+cfC8y7e4qDr
p4Bgtjkq32lxV.gckm8.7nIfpDHsceZpRdpH5QgLh.q2TjCOiTt8wD35qjAu
hlwDx8neH5yfL7uAhx.KELmokquC8eEhAxUDuhJVjTv.8BP.3.oCPVLp7Sn6
Kh2ljkKknp0WGkYNp7Rhx7nGQNKpi9PKSW3YHtYAKIKgCcJLZKkrokfneoT0
Bosh.JpQR89EGEzHiIngUt4SUGv5EtwoEPywLf17Ur4epxFECjxlmjnsvAl5
.gLA9Hj+lwVljImFXaVBXzGzHDJDK3BaVJbu4UEVRWGEKs3A+bVZ97OgJWsE
zChyeL6UPp0wWEo.VYHpximVX.Ti7kg1f9fkvZhD8USB9Aqi5Zi8KILqio6R
knfudQ98Te+ivVPgSdku9Orh3nrcQJJI.VgFXzHC7HIohY6JA4jZj6DKv1Ys
SOo1iHfyeUExn6zcmBrFVTuCl.VAdHo54CUmDXR2TcwJTPw70qquZ1HmfZN3
ArykBIVVbMgpIVwrEmReH9Le6ueaUft09Sy6LIaCLC.nkJ0ed96MZaJ+iGWh
n40WDMm05C2BeZh0xhj37LAYz3YEmt5EJr6qzbpS4x6HKZyQdXddd5rnBACY
VJqAiFTVhxRVCFn4IJJB7no5hIq2TjnLHr6brrHnOVUNuHOMsQWotxCG4JJ2
9dLIluR1W6wqFes65RY0Uiab9NCS64q1zxY.H4V8u52TCFH9N2PWbfesqerv
VZW+t0vWTg2hcs2u310il6fUBvuNM1tpdW1CmTYSTqxMV.qs3+MOjRzPpREv
MrWH06pARaL0ygQRKjRaGP2M4aqS.29xvzp3o5yTgUG7TQWi6.Kc6DKacIYZ
e1Iyftah.Wdr6QhsC.14kJrpz60xpXclvzE.SeoBqlEP+GH7KBHe4Z8MjTc5
GHIcBj0Wr4+uCK0FPGLThutfxtlXR9MOmh1DATUND8D5MXzaHn2PQuww7SUo
09qNP5cpJ6qlopjidq1PD6WLh3KVOasL2g9v97UeJ3zj7phsV77eA.FXRcMv
9Qiv+RiFT6SBM7ruNPC0a15zcMytmI7HA2Qg+ywYp72CCTZXptug79PGEK8S
KQgIIMw0ONVTlusXdEnWEACpIAFyJ4IY6hk9m2SqO6FWkDG2LxU0ZKDuIG3m
6R.pAw8NY516KT519KS51anzsHliqH5VXEdXzM4KT5FBAAgudn6fgR2WWx2C
mtoWW1SHmBcSudna7oP2jqG518.0sVna+qK4D2gh2dWWzMcnzs8Ejt0mr5Cf
XUF8.K9ivqA726iQbdQxrsbkKXM95LG6qHLde5gNuXee4iko4yhR0eloc8h0
M6QhKyGpydjqII0WCNjtO8qZKeib8uBRlw+1sWhLvpqRuQGWlKd.Hh6U.hHR
1.vhpQPEpusJMZ5JuzbMW9nyyWtLcWNKdl0bklwS1UJKcLDo8v3u3r2w0LfN
GUcFD609pHMLsG07vrRdOb.0jhSfwSDyz4wmfPuSuIkQ.VuVKd6Nbzhpn8Lv
MMoTVHWUG2W8tWxhQxyEkNtEurRQvinxQGxy+XAMPC2WXsKW+iDbgRmpGhRo
iZ0s6pRoees+B9cALXqK7nFnxYWhBtpKE9.RswmqWmL9936cT2siCumLp7dc
dVNLdefk4F13QcXSB8G7vlX+EnLO00evx7DxqiPuAfgpDSTCCtcBCuR59sLi
31r5o5wkXi8vsWbxSU9k5D3rUfJrOfp0ClB7zU.lMBOp0+kda+fnbwpmpV80
q9uZMQsSS.IrUrBY1XK2UPddsqLpVg0oT3tMZfNKIJhm0q.nH2TcLIlniNY2
VMT2XxEdqFpsBETlEti5ZU4DVaTqlOtsREDatZErMYjusgLxRFWVoZkbQ8MT
SPobbkTv57KXHaJUDqq1EmQuoRgUKPAgT82ix6wFawY9s0LdQ9EYwH5evWMC
R2UPLwn6FPsYLPkG8ip0.s+GpEqRUorsZMf9paM3GYQwUp8IYa1xQy1tXgnb
PefU7jnLzWmjBlGXyyyhKMeQhoS4FsABkUi1pQLrgJrNkETQ8vJpw0wMVOer
x9RP+6pT3K7Dphw6rsbd9toOWkTkFS0dQUeiK7wvA5NbXVdQrptm1clkGtoW
3GDPnthe43a6FD7rM8hZkCzgEmNVAOOuVhNNGXGybmcoYPDKh8ihr39cmV7z
4fBRsAf8cjo09Se6UG9pMRMW+9WTeha26KES6+q5T0oKyxAZPH9VeLpXMMFK
MJLq5iEI.oJBLu8Ufm.OZ77fOQ1Rn34+P1W+kPXrawJ7qhXkOUMireP+hUgz
+BKVI63l4SoRJ644ofVV6f7SPrNA6SOkVxMARijz4v7R334jvAR9mDM4zCMQ
MJIQaj1LsASglGlr6ilLKN4ZO.ZBaaTZxe.jD08zHIhuiHwD7v5HCB105LI1
fAPr9FE9bF.EEXTJBODgLmSjgpXgtjPYBmnXuxVWBhkbgIVM4o+9n0ZctDKd
Hpulc1.5P31Dr4oo9lN.a1oCFDuidhldItTUBXo2ze8105bmnfN.p08DoVGa
o1qiCtlUYYqyjZ8HCAaMK+dH.njtIlyiDxPoIr4noAiSFzKoAI76ZVZxcHzj
yKSgTsEm53Enxxs5snpsA.8cJaYhILbMqSTtCwIT2SzWcJUNwuCtNBJactl6
F.wFd8ow38BmsvSI4Q205b8XNXDX1mK.ND23cLqe7CI9Uri4iy+RSSUgG5p+
HIpz3nQKZUBfJEBksNW2AcFp8b7I6NnNwkbbb10xHTqsY8b.OBxBZWnopDbs
BOIm+BGfGCsIpqTxkZqhBPSshVmK0RGCp0OPE7taMpU15boVxUnkJ7PVQRyZ
PmNnvjLbn5zqPZZHV6nFdYVFhSeT5UHMYV8Nr2HrbTNZCrNXoAV8xrHZctyg
MDIM7IxUE6mpR5SM8u1pqn0kvKf9roQ8N0YETQVpJnPOhptBazRteTK1KOcT
a+8meDTjfQXFCepaMuunggpQRiV5jcsxuB+C9dg27m27+.7QBpFG
-----------end_max5_patcher-----------
*/

View File

@ -1,60 +0,0 @@
/*
Serial Event example
When new serial data arrives, this sketch adds it to a String.
When a newline is received, the loop prints the string and
clears it.
A good test for this is to try it with a GPS receiver
that sends out NMEA 0183 sentences.
Created 9 May 2011
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/SerialEvent
*/
String inputString = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
void setup() {
// initialize serial:
Serial.begin(9600);
// reserve 200 bytes for the inputString:
inputString.reserve(200);
}
void loop() {
// print the string when a newline arrives:
if (stringComplete) {
Serial.println(inputString);
// clear the string:
inputString = "";
stringComplete = false;
}
}
/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
*/
void serialEvent() {
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}

View File

@ -1,130 +0,0 @@
/*
This example reads three analog sensors (potentiometers are easiest)
and sends their values serially. The Processing and Max/MSP programs at the bottom
take those three values and use them to change the background color of the screen.
The circuit:
* potentiometers attached to analog inputs 0, 1, and 2
http://www.arduino.cc/en/Tutorial/VirtualColorMixer
created 2 Dec 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe and Scott Fitzgerald
This example code is in the public domain.
*/
const int redPin = A0; // sensor to control red color
const int greenPin = A1; // sensor to control green color
const int bluePin = A2; // sensor to control blue color
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.print(analogRead(redPin));
Serial.print(",");
Serial.print(analogRead(greenPin));
Serial.print(",");
Serial.println(analogRead(bluePin));
}
/* Processing code for this example
// This example code is in the public domain.
import processing.serial.*;
float redValue = 0; // red value
float greenValue = 0; // green value
float blueValue = 0; // blue value
Serial myPort;
void setup() {
size(200, 200);
// List all the available serial ports
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 9600);
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
}
void draw() {
// set the background color with the color values:
background(redValue, greenValue, blueValue);
}
void serialEvent(Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// split the string on the commas and convert the
// resulting substrings into an integer array:
float[] colors = float(split(inString, ","));
// if the array has at least three elements, you know
// you got the whole thing. Put the numbers in the
// color variables:
if (colors.length >=3) {
// map them to the range 0-255:
redValue = map(colors[0], 0, 1023, 0, 255);
greenValue = map(colors[1], 0, 1023, 0, 255);
blueValue = map(colors[2], 0, 1023, 0, 255);
}
}
}
*/
/* Max/MSP patch for this example
----------begin_max5_patcher----------
1512.3oc4Z00aaaCE8YmeED9ktB35xOjrj1aAsXX4g8xZQeYoXfVh1gqRjdT
TsIsn+2K+PJUovVVJ1VMdCAvxThV7bO7b48dIyWtXxzkxaYkSA+J3u.Sl7kK
lLwcK6MlT2dxzB5so4zRW2lJXeRt7elNy+HM6Vs61uDDzbOYkNmo02sg4euS
4BSede8S2P0o2vEq+aEKU66PPP7b3LPHDauPvyCmAvv4v6+M7L2XXF2WfCaF
lURgVPKbCxzKUbZdySDUEbgABN.ia08R9mccGYGn66qGutNir27qWbg8iY+7
HDRx.Hjf+OPHCQgPdpQHoxhBlwB+QF4cbkthlCRk4REnfeKScs3ZwaugWBbj
.PS+.qDPAkZkgPlY5oPS4By2A5aTLFv9pounjsgpnZVF3x27pqtBrRpJnZaa
C3WxTkfUJYA.BzR.BhIy.ehquw7dSoJCsrlATLckR.nhLPNWvVwL+Vp1LHL.
SjMG.tRaG7OxT5R2c8Hx9B8.wLCxVaGI6qnpj45Ug84kL+6YIM8CqUxJyycF
7bqsBRULGvwfWyRMyovElat7NvqoejaLm4f+fkmyKuVTHy3q3ldhB.WtQY6Z
x0BSOeSpTqA+FW+Yy3SyybH3sFy8p0RVCmaMpTyX6HdDZ2JsPbfSogbBMueH
JLd6RMBdfRMzPjZvimuWIK2XgFA.ZmtfKoh0Sm88qc6OF4bDQ3P6kEtF6xej
.OkjD4H5OllyS+.3FlhY0so4xRlWqyrXErQpt+2rsnXgQNZHZgmMVzEofW7T
S4zORQtgIdDbRHrObRzSMNofUVZVcbKbhQZrSOo934TqRHIN2ncr7BF8TKR1
tHDqL.PejLRRPKMR.pKFAkbtDa+UOvsYsIFH0DYsTCjqZ66T1CmGeDILLpSm
myk0SdkOKh5LUr4GbWwRYdW7fm.BvDmzHnSdH3biGpSbxxDNJoGDAD1ChH7L
I0DaloOTBLvkO7zPs5HJnKNoGAXbol5eytUhfyiSfnjE1uAq+Fp0a+wygGwR
q3ZI8.psJpkpJnyPzwmXBj7Sh.+bNvVZxlcKAm0OYHIxcIjzEKdRChgO5UMf
LkMPNN0MfiS7Ev6TYQct.F5IWcCZ4504rGsiVswGWWSYyma01QcZgmL+f+sf
oU18Hn6o6dXkMkFF14TL9rIAWE+6wvGV.p.TPqz3HK5L+VxYxl4UmBKEjr.B
6zinuKI3C+D2Y7azIM6N7QL6t+jQyZxymK1ToAKqVsxjlGyjz2c1kTK3180h
kJEYkacWpv6lyp2VJTjWK47wHA6fyBOWxH9pUf6jUtZkLpNKW.9EeUBH3ymY
XSQlaqGrkQMGzp20adYSmIOGjIABo1xZyAWJtCX9tg6+HMuhMCPyx76ao+Us
UxmzUE79H8d2ZB1m1ztbnOa1mGeAq0awyK8a9UqBUc6pZolpzurTK232e5gp
aInVw8QIIcpaiNSJfY4Z+92Cs+Mc+mgg2cEsvGlLY6V+1kMuioxnB5VM+fsY
9vSu4WI1PMBGXye6KXvNuzmZTh7U9h5j6vvASdngPdgOFxycNL6ia1axUMmT
JIzebXcQCn3SKMf+4QCMmOZung+6xBCPLfwO8ngcEI52YJ1y7mx3CN9xKUYU
bg7Y1yXjlKW6SrZnguQdsSfOSSDItqv2jwJFjavc1vO7OigyBr2+gDYorRk1
HXZpVFfu2FxXkZtfp4RQqNkX5y2sya3YYL2iavWAOaizH+pw.Ibg8f1I9h3Z
2B79sNeOHvBOtfEalWsvyu0KMf015.AaROvZ7vv5AhnndfHLbTgjcCK1KlHv
gOk5B26OqrXjcJ005.QqCHn8fVTxnxfj93SfQiJlv8YV0VT9fVUwOOhSV3uD
eeqCUClbBPa.j3vWDoMZssNTzRNEnE6gYPXazZaMF921syaLWyAeBXvCESA8
ASi6Zyw8.RQi65J8ZsNx3ho93OhGWENtWpowepae4YhCFeLErOLENtXJrOSc
iadi39rf4hwc8xdhHz3gn3dBI7iDRlFe8huAfIZhq
-----------end_max5_patcher-----------
*/

View File

@ -1,57 +0,0 @@
/*
Arrays
Demonstrates the use of an array to hold pin numbers
in order to iterate over the pins in a sequence.
Lights multiple LEDs in sequence, then in reverse.
Unlike the For Loop tutorial, where the pins have to be
contiguous, here the pins can be in any random order.
The circuit:
* LEDs from pins 2 through 7 to ground
created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Array
*/
int timer = 100; // The higher the number, the slower the timing.
int ledPins[] = {
2, 7, 4, 6, 5, 3 }; // an array of pin numbers to which LEDs are attached
int pinCount = 6; // the number of pins (i.e. the length of the array)
void setup() {
int thisPin;
// the array elements are numbered from 0 to (pinCount - 1).
// use a for loop to initialize each pin as an output:
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
}
void loop() {
// loop from the lowest pin to the highest:
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
}
// loop from the highest pin to the lowest:
for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {
// turn the pin on:
digitalWrite(ledPins[thisPin], HIGH);
delay(timer);
// turn the pin off:
digitalWrite(ledPins[thisPin], LOW);
}
}

View File

@ -1,47 +0,0 @@
/*
For Loop Iteration
Demonstrates the use of a for() loop.
Lights multiple LEDs in sequence, then in reverse.
The circuit:
* LEDs from pins 2 through 7 to ground
created 2006
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/ForLoop
*/
int timer = 100; // The higher the number, the slower the timing.
void setup() {
// use a for loop to initialize each pin as an output:
for (int thisPin = 2; thisPin < 8; thisPin++) {
pinMode(thisPin, OUTPUT);
}
}
void loop() {
// loop from the lowest pin to the highest:
for (int thisPin = 2; thisPin < 8; thisPin++) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}
// loop from the highest pin to the lowest:
for (int thisPin = 7; thisPin >= 2; thisPin--) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}
}

View File

@ -1,56 +0,0 @@
/*
Conditionals - If statement
This example demonstrates the use of if() statements.
It reads the state of a potentiometer (an analog input) and turns on an LED
only if the LED goes above a certain threshold level. It prints the analog value
regardless of the level.
The circuit:
* potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
* LED connected from digital pin 13 to ground
* Note: On most Arduino boards, there is already an LED on the board
connected to pin 13, so you don't need any extra components for this example.
created 17 Jan 2009
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://arduino.cc/en/Tutorial/IfStatement
*/
// These constants won't change:
const int analogPin = A0; // pin that the sensor is attached to
const int ledPin = 13; // pin that the LED is attached to
const int threshold = 400; // an arbitrary threshold level that's in the range of the analog input
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize serial communications:
Serial.begin(9600);
}
void loop() {
// read the value of the potentiometer:
int analogValue = analogRead(analogPin);
// if the analog value is high enough, turn on the LED:
if (analogValue > threshold) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin,LOW);
}
// print the analog value:
Serial.println(analogValue);
}

View File

@ -1,88 +0,0 @@
/*
Conditionals - while statement
This example demonstrates the use of while() statements.
While the pushbutton is pressed, the sketch runs the calibration routine.
The sensor readings during the while loop define the minimum and maximum
of expected values from the photo resistor.
This is a variation on the calibrate example.
The circuit:
* photo resistor connected from +5V to analog in pin 0
* 10K resistor connected from ground to analog in pin 0
* LED connected from digital pin 9 to ground through 220 ohm resistor
* pushbutton attached from pin 2 to +5V
* 10K resistor attached from pin 2 to ground
created 17 Jan 2009
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://arduino.cc/en/Tutorial/WhileLoop
*/
// These constants won't change:
const int sensorPin = A2; // pin that the sensor is attached to
const int ledPin = 9; // pin that the LED is attached to
const int indicatorLedPin = 13; // pin that the built-in LED is attached to
const int buttonPin = 2; // pin that the button is attached to
// These variables will change:
int sensorMin = 1023; // minimum sensor value
int sensorMax = 0; // maximum sensor value
int sensorValue = 0; // the sensor value
void setup() {
// set the LED pins as outputs and the switch pin as input:
pinMode(indicatorLedPin, OUTPUT);
pinMode (ledPin, OUTPUT);
pinMode (buttonPin, INPUT);
}
void loop() {
// while the button is pressed, take calibration readings:
while (digitalRead(buttonPin) == HIGH) {
calibrate();
}
// signal the end of the calibration period
digitalWrite(indicatorLedPin, LOW);
// read the sensor:
sensorValue = analogRead(sensorPin);
// apply the calibration to the sensor reading
sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);
// in case the sensor value is outside the range seen during calibration
sensorValue = constrain(sensorValue, 0, 255);
// fade the LED using the calibrated value:
analogWrite(ledPin, sensorValue);
}
void calibrate() {
// turn on the indicator LED to indicate that calibration is happening:
digitalWrite(indicatorLedPin, HIGH);
// read the sensor:
sensorValue = analogRead(sensorPin);
// record the maximum sensor value
if (sensorValue > sensorMax) {
sensorMax = sensorValue;
}
// record the minimum sensor value
if (sensorValue < sensorMin) {
sensorMin = sensorValue;
}
}

View File

@ -1,62 +0,0 @@
/*
Switch statement
Demonstrates the use of a switch statement. The switch
statement allows you to choose from among a set of discrete values
of a variable. It's like a series of if statements.
To see this sketch in action, but the board and sensor in a well-lit
room, open the serial monitor, and and move your hand gradually
down over the sensor.
The circuit:
* photoresistor from analog in 0 to +5V
* 10K resistor from analog in 0 to ground
created 1 Jul 2009
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/SwitchCase
*/
// these constants won't change:
const int sensorMin = 0; // sensor minimum, discovered through experiment
const int sensorMax = 600; // sensor maximum, discovered through experiment
void setup() {
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// read the sensor:
int sensorReading = analogRead(A0);
// map the sensor range to a range of four options:
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
// do something different depending on the
// range value:
switch (range) {
case 0: // your hand is on the sensor
Serial.println("dark");
break;
case 1: // your hand is close to the sensor
Serial.println("dim");
break;
case 2: // your hand is a few inches from the sensor
Serial.println("medium");
break;
case 3: // your hand is nowhere near the sensor
Serial.println("bright");
break;
}
}

View File

@ -1,66 +0,0 @@
/*
Switch statement with serial input
Demonstrates the use of a switch statement. The switch
statement allows you to choose from among a set of discrete values
of a variable. It's like a series of if statements.
To see this sketch in action, open the Serial monitor and send any character.
The characters a, b, c, d, and e, will turn on LEDs. Any other character will turn
the LEDs off.
The circuit:
* 5 LEDs attached to digital pins 2 through 6 through 220-ohm resistors
created 1 Jul 2009
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/SwitchCase2
*/
void setup() {
// initialize serial communication:
Serial.begin(9600);
// initialize the LED pins:
for (int thisPin = 2; thisPin < 7; thisPin++) {
pinMode(thisPin, OUTPUT);
}
}
void loop() {
// read the sensor:
if (Serial.available() > 0) {
int inByte = Serial.read();
// do something different depending on the character received.
// The switch statement expects single number values for each case;
// in this exmaple, though, you're using single quotes to tell
// the controller to get the ASCII value for the character. For
// example 'a' = 97, 'b' = 98, and so forth:
switch (inByte) {
case 'a':
digitalWrite(2, HIGH);
break;
case 'b':
digitalWrite(3, HIGH);
break;
case 'c':
digitalWrite(4, HIGH);
break;
case 'd':
digitalWrite(5, HIGH);
break;
case 'e':
digitalWrite(6, HIGH);
break;
default:
// turn all the LEDs off:
for (int thisPin = 2; thisPin < 7; thisPin++) {
digitalWrite(thisPin, LOW);
}
}
}
}

View File

@ -1,64 +0,0 @@
/*
ADXL3xx
Reads an Analog Devices ADXL3xx accelerometer and communicates the
acceleration to the computer. The pins used are designed to be easily
compatible with the breakout boards from Sparkfun, available from:
http://www.sparkfun.com/commerce/categories.php?c=80
http://www.arduino.cc/en/Tutorial/ADXL3xx
The circuit:
analog 0: accelerometer self test
analog 1: z-axis
analog 2: y-axis
analog 3: x-axis
analog 4: ground
analog 5: vcc
created 2 Jul 2008
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
*/
// these constants describe the pins. They won't change:
const int groundpin = 18; // analog input pin 4 -- ground
const int powerpin = 19; // analog input pin 5 -- voltage
const int xpin = A3; // x-axis of the accelerometer
const int ypin = A2; // y-axis
const int zpin = A1; // z-axis (only on 3-axis models)
void setup()
{
// initialize the serial communications:
Serial.begin(9600);
// Provide ground and power by using the analog inputs as normal
// digital pins. This makes it possible to directly connect the
// breakout board to the Arduino. If you use the normal 5V and
// GND pins on the Arduino, you can remove these lines.
pinMode(groundpin, OUTPUT);
pinMode(powerpin, OUTPUT);
digitalWrite(groundpin, LOW);
digitalWrite(powerpin, HIGH);
}
void loop()
{
// print the sensor values:
Serial.print(analogRead(xpin));
// print a tab between values:
Serial.print("\t");
Serial.print(analogRead(ypin));
// print a tab between values:
Serial.print("\t");
Serial.print(analogRead(zpin));
Serial.println();
// delay before next reading:
delay(100);
}

View File

@ -1,55 +0,0 @@
/* Knock Sensor
This sketch reads a piezo element to detect a knocking sound.
It reads an analog pin and compares the result to a set threshold.
If the result is greater than the threshold, it writes
"knock" to the serial port, and toggles the LED on pin 13.
The circuit:
* + connection of the piezo attached to analog in 0
* - connection of the piezo attached to ground
* 1-megohm resistor attached from analog in 0 to ground
http://www.arduino.cc/en/Tutorial/Knock
created 25 Mar 2007
by David Cuartielles <http://www.0j0.org>
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
*/
// these constants won't change:
const int ledPin = 13; // led connected to digital pin 13
const int knockSensor = A0; // the piezo is connected to analog pin 0
const int threshold = 100; // threshold value to decide when the detected sound is a knock or not
// these variables will change:
int sensorReading = 0; // variable to store the value read from the sensor pin
int ledState = LOW; // variable used to store the last LED status, to toggle the light
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT
Serial.begin(9600); // use the serial port
}
void loop() {
// read the sensor and store it in the variable sensorReading:
sensorReading = analogRead(knockSensor);
// if the sensor reading is greater than the threshold:
if (sensorReading >= threshold) {
// toggle the status of the ledPin:
ledState = !ledState;
// update the LED pin itself:
digitalWrite(ledPin, ledState);
// send the string "Knock!" back to the computer, followed by newline
Serial.println("Knock!");
}
delay(100); // delay to avoid overloading the serial port buffer
}

View File

@ -1,63 +0,0 @@
/*
Memsic2125
Read the Memsic 2125 two-axis accelerometer. Converts the
pulses output by the 2125 into milli-g's (1/1000 of earth's
gravity) and prints them over the serial connection to the
computer.
The circuit:
* X output of accelerometer to digital pin 2
* Y output of accelerometer to digital pin 3
* +V of accelerometer to +5V
* GND of accelerometer to ground
http://www.arduino.cc/en/Tutorial/Memsic2125
created 6 Nov 2008
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
*/
// these constants won't change:
const int xPin = 2; // X output of the accelerometer
const int yPin = 3; // Y output of the accelerometer
void setup() {
// initialize serial communications:
Serial.begin(9600);
// initialize the pins connected to the accelerometer
// as inputs:
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
}
void loop() {
// variables to read the pulse widths:
int pulseX, pulseY;
// variables to contain the resulting accelerations
int accelerationX, accelerationY;
// read pulse from x- and y-axes:
pulseX = pulseIn(xPin,HIGH);
pulseY = pulseIn(yPin,HIGH);
// convert the pulse width into acceleration
// accelerationX and accelerationY are in milli-g's:
// earth's gravity is 1000 milli-g's, or 1g.
accelerationX = ((pulseX / 10) - 500) * 8;
accelerationY = ((pulseY / 10) - 500) * 8;
// print the acceleration
Serial.print(accelerationX);
// print a tab character:
Serial.print("\t");
Serial.print(accelerationY);
Serial.println();
delay(100);
}

View File

@ -1,84 +0,0 @@
/* Ping))) Sensor
This sketch reads a PING))) ultrasonic rangefinder and returns the
distance to the closest object in range. To do this, it sends a pulse
to the sensor to initiate a reading, then listens for a pulse
to return. The length of the returning pulse is proportional to
the distance of the object from the sensor.
The circuit:
* +V connection of the PING))) attached to +5V
* GND connection of the PING))) attached to ground
* SIG connection of the PING))) attached to digital pin 7
http://www.arduino.cc/en/Tutorial/Ping
created 3 Nov 2008
by David A. Mellis
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
*/
// this constant won't change. It's the pin number
// of the sensor's output:
const int pingPin = 7;
void setup() {
// initialize serial communication:
Serial.begin(9600);
}
void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
delay(100);
}
long microsecondsToInches(long microseconds)
{
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}

View File

@ -1,114 +0,0 @@
/*
Row-Column Scanning an 8x8 LED matrix with X-Y input
This example controls an 8x8 LED matrix using two analog inputs
created 27 May 2009
modified 30 Aug 2011
by Tom Igoe
This example works for the Lumex LDM-24488NI Matrix. See
http://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf
for the pin connections
For other LED cathode column matrixes, you should only need to change
the pin numbers in the row[] and column[] arrays
rows are the anodes
cols are the cathodes
---------
Pin numbers:
Matrix:
* Digital pins 2 through 13,
* analog pins 2 through 5 used as digital 16 through 19
Potentiometers:
* center pins are attached to analog pins 0 and 1, respectively
* side pins attached to +5V and ground, respectively.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/RowColumnScanning
see also http://www.tigoe.net/pcomp/code/category/arduinowiring/514 for more
*/
// 2-dimensional array of row pin numbers:
const int row[8] = {
2,7,19,5,13,18,12,16 };
// 2-dimensional array of column pin numbers:
const int col[8] = {
6,11,10,3,17,4,8,9 };
// 2-dimensional array of pixels:
int pixels[8][8];
// cursor position:
int x = 5;
int y = 5;
void setup() {
Serial.begin(9600);
// initialize the I/O pins as outputs:
// iterate over the pins:
for (int thisPin = 0; thisPin < 8; thisPin++) {
// initialize the output pins:
pinMode(col[thisPin], OUTPUT);
pinMode(row[thisPin], OUTPUT);
// take the col pins (i.e. the cathodes) high to ensure that
// the LEDS are off:
digitalWrite(col[thisPin], HIGH);
}
// initialize the pixel matrix:
for (int x = 0; x < 8; x++) {
for (int y = 0; y < 8; y++) {
pixels[x][y] = HIGH;
}
}
}
void loop() {
// read input:
readSensors();
// draw the screen:
refreshScreen();
}
void readSensors() {
// turn off the last position:
pixels[x][y] = HIGH;
// read the sensors for X and Y values:
x = 7 - map(analogRead(A0), 0, 1023, 0, 7);
y = map(analogRead(A1), 0, 1023, 0, 7);
// set the new pixel position low so that the LED will turn on
// in the next screen refresh:
pixels[x][y] = LOW;
}
void refreshScreen() {
// iterate over the rows (anodes):
for (int thisRow = 0; thisRow < 8; thisRow++) {
// take the row pin (anode) high:
digitalWrite(row[thisRow], HIGH);
// iterate over the cols (cathodes):
for (int thisCol = 0; thisCol < 8; thisCol++) {
// get the state of the current pixel;
int thisPixel = pixels[thisRow][thisCol];
// when the row is HIGH and the col is LOW,
// the LED where they meet turns on:
digitalWrite(col[thisCol], thisPixel);
// turn the pixel off:
if (thisPixel == LOW) {
digitalWrite(col[thisCol], HIGH);
}
}
// take the row pin low to turn off the whole row:
digitalWrite(row[thisRow], LOW);
}
}

View File

@ -1,60 +0,0 @@
/*
LED bar graph
Turns on a series of LEDs based on the value of an analog sensor.
This is a simple way to make a bar graph display. Though this graph
uses 10 LEDs, you can use any number by changing the LED count
and the pins in the array.
This method can be used to control any series of digital outputs that
depends on an analog input.
The circuit:
* LEDs from pins 2 through 11 to ground
created 4 Sep 2010
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/BarGraph
*/
// these constants won't change:
const int analogPin = A0; // the pin that the potentiometer is attached to
const int ledCount = 10; // the number of LEDs in the bar graph
int ledPins[] = {
2, 3, 4, 5, 6, 7,8,9,10,11 }; // an array of pin numbers to which LEDs are attached
void setup() {
// loop over the pin array and set them all to output:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
}
}
void loop() {
// read the potentiometer:
int sensorReading = analogRead(analogPin);
// map the result to a range from 0 to the number of LEDs:
int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);
// loop over the LED array:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
// if the array element's index is less than ledLevel,
// turn the pin for this element on:
if (thisLed < ledLevel) {
digitalWrite(ledPins[thisLed], HIGH);
}
// turn off all pins higher than the ledLevel:
else {
digitalWrite(ledPins[thisLed], LOW);
}
}
}

View File

@ -1,84 +0,0 @@
/*
Character analysis operators
Examples using the character analysis operators.
Send any byte and the sketch will tell you about it.
created 29 Nov 2010
modified 2 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) {
; // wait for serial port to connect. Needed fo Leonardo only
}
// send an intro:
Serial.println("send any byte and I'll tell you everything I can about it");
Serial.println();
}
void loop() {
// get any incoming bytes:
if (Serial.available() > 0) {
int thisChar = Serial.read();
// say what was sent:
Serial.print("You sent me: \'");
Serial.write(thisChar);
Serial.print("\' ASCII Value: ");
Serial.println(thisChar);
// analyze what was sent:
if(isAlphaNumeric(thisChar)) {
Serial.println("it's alphanumeric");
}
if(isAlpha(thisChar)) {
Serial.println("it's alphabetic");
}
if(isAscii(thisChar)) {
Serial.println("it's ASCII");
}
if(isWhitespace(thisChar)) {
Serial.println("it's whitespace");
}
if(isControl(thisChar)) {
Serial.println("it's a control character");
}
if(isDigit(thisChar)) {
Serial.println("it's a numeric digit");
}
if(isGraph(thisChar)) {
Serial.println("it's a printable character that's not whitespace");
}
if(isLowerCase(thisChar)) {
Serial.println("it's lower case");
}
if(isPrintable(thisChar)) {
Serial.println("it's printable");
}
if(isPunct(thisChar)) {
Serial.println("it's punctuation");
}
if(isSpace(thisChar)) {
Serial.println("it's a space character");
}
if(isUpperCase(thisChar)) {
Serial.println("it's upper case");
}
if (isHexadecimalDigit(thisChar)) {
Serial.println("it's a valid hexadecimaldigit (i.e. 0 - 9, a - F, or A - F)");
}
// add some space and ask for another byte:
Serial.println();
Serial.println("Give me another byte:");
Serial.println();
}
}

View File

@ -1,68 +0,0 @@
/*
Adding Strings together
Examples of how to add strings together
You can also add several different data types to string, as shown here:
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://arduino.cc/en/Tutorial/StringAdditionOperator
This example code is in the public domain.
*/
// declare three strings:
String stringOne, stringTwo, stringThree;
void setup() {
// initialize serial and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) {
; // wait for serial port to connect. Needed fo Leonardo only
}
stringOne = String("stringThree = ");
stringTwo = String("this string");
stringThree = String ();
Serial.println("\n\nAdding strings together (concatenation):");
Serial.println();
}
void loop() {
// adding a constant integer to a string:
stringThree = stringOne + 123;
Serial.println(stringThree); // prints "stringThree = 123"
// adding a constant long interger to a string:
stringThree = stringOne + 123456789;
Serial.println(stringThree); // prints " You added 123456789"
// adding a constant character to a string:
stringThree = stringOne + 'A';
Serial.println(stringThree); // prints "You added A"
// adding a constant string to a string:
stringThree = stringOne + "abc";
Serial.println(stringThree); // prints "You added abc"
stringThree = stringOne + stringTwo;
Serial.println(stringThree); // prints "You added this string"
// adding a variable integer to a string:
int sensorValue = analogRead(A0);
stringOne = "Sensor value: ";
stringThree = stringOne + sensorValue;
Serial.println(stringThree); // prints "Sensor Value: 401" or whatever value analogRead(A0) has
// adding a variable long integer to a string:
long currentTime = millis();
stringOne="millis() value: ";
stringThree = stringOne + millis();
Serial.println(stringThree); // prints "The millis: 345345" or whatever value currentTime has
// do nothing while true:
while(true);
}

View File

@ -1,70 +0,0 @@
/*
Appending to Strings using the += operator and concat()
Examples of how to append different data types to strings
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://arduino.cc/en/Tutorial/StringAppendOperator
This example code is in the public domain.
*/
String stringOne, stringTwo;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) ;
;
stringOne = String("Sensor ");
stringTwo = String("value");
Serial.println("\n\nAppending to a string:");
}
void loop() {
Serial.println(stringOne); // prints "Sensor "
// adding a string to a string:
stringOne += stringTwo;
Serial.println(stringOne); // prints "Sensor value"
// adding a constant string to a string:
stringOne += " for input ";
Serial.println(stringOne); // prints "Sensor value for input"
// adding a constant character to a string:
stringOne += 'A';
Serial.println(stringOne); // prints "Sensor value for input A"
// adding a constant integer to a string:
stringOne += 0;
Serial.println(stringOne); // prints "Sensor value for input A0"
// adding a constant string to a string:
stringOne += ": ";
Serial.println(stringOne); // prints "Sensor value for input"
// adding a variable integer to a string:
stringOne += analogRead(A0);
Serial.println(stringOne); // prints "Sensor value for input A0: 456" or whatever analogRead(A0) is
Serial.println("\n\nchanging the Strings' values");
stringOne = "A long integer: ";
stringTwo = "The millis(): ";
// adding a constant long integer to a string:
stringOne += 123456789;
Serial.println(stringOne); // prints "A long integer: 123456789"
// using concat() to add a long variable to a string:
stringTwo.concat(millis());
Serial.println(stringTwo); // prints "The millis(): 43534" or whatever the value of the millis() is
// do nothing while true:
while(true);
}

View File

@ -1,41 +0,0 @@
/*
String Case changes
Examples of how to change the case of a string
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://arduino.cc/en/Tutorial/StringCaseChanges
This example code is in the public domain.
*/
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) ;
;
Serial.println("\n\nString case changes:");
}
void loop() {
// toUpperCase() changes all letters to upper case:
String stringOne = "<html><head><body>";
Serial.println(stringOne);
stringOne.toUpperCase();
Serial.println(stringOne);
// toLowerCase() changes all letters to lower case:
String stringTwo = "</BODY></HTML>";
Serial.println(stringTwo);
stringTwo.toLowerCase();
Serial.println(stringTwo);
// do nothing while true:
while(true);
}

View File

@ -1,44 +0,0 @@
/*
String charAt() and setCharAt()
Examples of how to get and set characters of a String
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://arduino.cc/en/Tutorial/StringCharacters
This example code is in the public domain.
*/
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) ;
;
Serial.println("\n\nString charAt() and setCharAt():");
}
void loop() {
// make a string to report a sensor reading:
String reportString = "SensorReading: 456";
Serial.println(reportString);
// the reading's most significant digit is at position 15 in the reportString:
char mostSignificantDigit = reportString.charAt(15);
Serial.println("Most significant digit of the sensor reading is: " + mostSignificantDigit);
// add blank space:
Serial.println();
// you can alo set the character of a string. Change the : to a = character
reportString.setCharAt(13, '=');
Serial.println(reportString);
// do nothing while true:
while(true);
}

View File

@ -1,129 +0,0 @@
/*
Comparing Strings
Examples of how to compare strings using the comparison operators
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://arduino.cc/en/Tutorial/StringComparisonOperators
This example code is in the public domain.
*/
String stringOne, stringTwo;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) ;
;
stringOne = String("this");
stringTwo = String("that");
Serial.println("\n\nComparing Strings:");
}
void loop() {
// two strings equal:
if (stringOne == "this") {
Serial.println("StringOne == \"this\"");
}
// two strings not equal:
if (stringOne != stringTwo) {
Serial.println(stringOne + " =! " + stringTwo);
}
// two strings not equal (case sensitivity matters):
stringOne = "This";
stringTwo = "this";
if (stringOne != stringTwo) {
Serial.println(stringOne + " =! " + stringTwo);
}
// you can also use equals() to see if two strings are the same:
if (stringOne.equals(stringTwo)) {
Serial.println(stringOne + " equals " + stringTwo);
}
else {
Serial.println(stringOne + " does not equal " + stringTwo);
}
// or perhaps you want to ignore case:
if (stringOne.equalsIgnoreCase(stringTwo)) {
Serial.println(stringOne + " equals (ignoring case) " + stringTwo);
}
else {
Serial.println(stringOne + " does not equal (ignoring case) " + stringTwo);
}
// a numeric string compared to the number it represents:
stringOne = "1";
int numberOne = 1;
if (stringOne.toInt() == numberOne) {
Serial.println(stringOne + " = " + numberOne);
}
// two numeric strings compared:
stringOne = "2";
stringTwo = "1";
if (stringOne >= stringTwo) {
Serial.println(stringOne + " >= " + stringTwo);
}
// comparison operators can be used to compare strings for alphabetic sorting too:
stringOne = String("Brown");
if (stringOne < "Charles") {
Serial.println(stringOne + " < Charles");
}
if (stringOne > "Adams") {
Serial.println(stringOne + " > Adams");
}
if (stringOne <= "Browne") {
Serial.println(stringOne + " <= Browne");
}
if (stringOne >= "Brow") {
Serial.println(stringOne + " >= Brow");
}
// the compareTo() operator also allows you to compare strings
// it evaluates on the first character that's different.
// if the first character of the string you're comparing to
// comes first in alphanumeric order, then compareTo() is greater than 0:
stringOne = "Cucumber";
stringTwo = "Cucuracha";
if (stringOne.compareTo(stringTwo) < 0 ) {
Serial.println(stringOne + " comes before " + stringTwo);
}
else {
Serial.println(stringOne + " comes after " + stringTwo);
}
delay(10000); // because the next part is a loop:
// compareTo() is handy when you've got strings with numbers in them too:
while (true) {
stringOne = "Sensor: ";
stringTwo= "Sensor: ";
stringOne += analogRead(A0);
stringTwo += analogRead(A5);
if (stringOne.compareTo(stringTwo) < 0 ) {
Serial.println(stringOne + " comes before " + stringTwo);
}
else {
Serial.println(stringOne + " comes after " + stringTwo);
}
}
}

View File

@ -1,70 +0,0 @@
/*
String constructors
Examples of how to create strings from other data types
created 27 July 2010
modified 30 Aug 2011
by Tom Igoe
http://arduino.cc/en/Tutorial/StringConstructors
This example code is in the public domain.
*/
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) ;
;
Serial.println("\n\nString Constructors:");
}
void loop() {
// using a constant String:
String stringOne = "Hello String";
Serial.println(stringOne); // prints "Hello String"
// converting a constant char into a String:
stringOne = String('a');
Serial.println(stringOne); // prints "a"
// converting a constant string into a String object:
String stringTwo = String("This is a string");
Serial.println(stringTwo); // prints "This is a string"
// concatenating two strings:
stringOne = String(stringTwo + " with more");
// prints "This is a string with more":
Serial.println(stringOne);
// using a constant integer:
stringOne = String(13);
Serial.println(stringOne); // prints "13"
// using an int and a base:
stringOne = String(analogRead(A0), DEC);
// prints "453" or whatever the value of analogRead(A0) is
Serial.println(stringOne);
// using an int and a base (hexadecimal):
stringOne = String(45, HEX);
// prints "2d", which is the hexadecimal version of decimal 45:
Serial.println(stringOne);
// using an int and a base (binary)
stringOne = String(255, BIN);
// prints "11111111" which is the binary value of 255
Serial.println(stringOne);
// using a long and a base:
stringOne = String(millis(), DEC);
// prints "123456" or whatever the value of millis() is:
Serial.println(stringOne);
// do nothing while true:
while(true);
}

View File

@ -1,65 +0,0 @@
/*
String indexOf() and lastIndexOf() functions
Examples of how to evaluate, look for, and replace characters in a String
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://arduino.cc/en/Tutorial/StringIndexOf
This example code is in the public domain.
*/
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) ;
;
Serial.println("\n\nString indexOf() and lastIndexOf() functions:");
}
void loop() {
// indexOf() returns the position (i.e. index) of a particular character
// in a string. For example, if you were parsing HTML tags, you could use it:
String stringOne = "<HTML><HEAD><BODY>";
int firstClosingBracket = stringOne.indexOf('>');
Serial.println("The index of > in the string " + stringOne + " is " + firstClosingBracket);
stringOne = "<HTML><HEAD><BODY>";
int secondOpeningBracket = firstClosingBracket + 1;
int secondClosingBracket = stringOne.indexOf('>', secondOpeningBracket );
Serial.println("The index of the second > in the string " + stringOne + " is " + secondClosingBracket);
// you can also use indexOf() to search for Strings:
stringOne = "<HTML><HEAD><BODY>";
int bodyTag = stringOne.indexOf("<BODY>");
Serial.println("The index of the body tag in the string " + stringOne + " is " + bodyTag);
stringOne = "<UL><LI>item<LI>item<LI>item</UL>";
int firstListItem = stringOne.indexOf("<LI>");
int secondListItem = stringOne.indexOf("item", firstListItem + 1 );
Serial.println("The index of the second list item in the string " + stringOne + " is " + secondClosingBracket);
// lastIndexOf() gives you the last occurrence of a character or string:
int lastOpeningBracket = stringOne.lastIndexOf('<');
Serial.println("The index of the last < in the string " + stringOne + " is " + lastOpeningBracket);
int lastListItem = stringOne.lastIndexOf("<LI>");
Serial.println("The index of the last list item in the string " + stringOne + " is " + lastListItem);
// lastIndexOf() can also search for a string:
stringOne = "<p>Lorem ipsum dolor sit amet</p><p>Ipsem</p><p>Quod</p>";
int lastParagraph = stringOne.lastIndexOf("<p");
int secondLastGraf = stringOne.lastIndexOf("<p", lastParagraph - 1);
Serial.println("The index of the second last paragraph tag " + stringOne + " is " + secondLastGraf);
// do nothing while true:
while(true);
}

View File

@ -1,48 +0,0 @@
/*
String length()
Examples of how to use length() in a String.
Open the Serial Monitor and start sending characters to see the results.
created 1 Aug 2010
by Tom Igoe
http://arduino.cc/en/Tutorial/StringLengthTrim
This example code is in the public domain.
*/
String txtMsg = ""; // a string for incoming text
int lastStringLength = txtMsg.length(); // previous length of the String
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) ;
;
Serial.println("\n\nString length():");
}
void loop() {
// add any incoming characters to the String:
while (Serial.available() > 0) {
char inChar = Serial.read();
txtMsg += inChar;
}
// print the message and a notice if it's changed:
if (txtMsg.length() != lastStringLength) {
Serial.println(txtMsg);
Serial.println(txtMsg.length());
// if the String's longer than 140 characters, complain:
if (txtMsg.length() < 140) {
Serial.println("That's a perfectly acceptable text message");
}
else {
Serial.println("That's too long for a text message.");
}
// note the length for next time through the loop:
lastStringLength = txtMsg.length();
}
}

View File

@ -1,40 +0,0 @@
/*
String length() and trim()
Examples of how to use length() and trim() in a String
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://arduino.cc/en/Tutorial/StringLengthTrim
This example code is in the public domain.
*/
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) ;
;
Serial.println("\n\nString length() and trim():");
}
void loop() {
// here's a String with empty spaces at the end (called white space):
String stringOne = "Hello! ";
Serial.print(stringOne);
Serial.print("<--- end of string. Length: ");
Serial.println(stringOne.length());
// trim the white space off the string:
stringOne.trim();
Serial.print(stringOne);
Serial.print("<--- end of trimmed string. Length: ");
Serial.println(stringOne.length());
// do nothing while true:
while(true);
}

View File

@ -1,48 +0,0 @@
/*
String replace()
Examples of how to replace characters or substrings of a string
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://arduino.cc/en/Tutorial/StringReplace
This example code is in the public domain.
*/
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) ;
;
Serial.println("\n\nString replace:\n");
}
void loop() {
String stringOne = "<html><head><body>";
Serial.println(stringOne);
// replace() changes all instances of one substring with another:
// first, make a copy of th original string:
String stringTwo = stringOne;
// then perform the replacements:
stringTwo.replace("<", "</");
// print the original:
Serial.println("Original string: " + stringOne);
// and print the modified string:
Serial.println("Modified string: " + stringTwo);
// you can also use replace() on single characters:
String normalString = "bookkeeper";
Serial.println("normal: " + normalString);
String leetString = normalString;
leetString.replace('o', '0');
leetString.replace('e', '3');
Serial.println("l33tspeak: " + leetString);
// do nothing while true:
while(true);
}

View File

@ -1,54 +0,0 @@
/*
String startWith() and endsWith()
Examples of how to use startsWith() and endsWith() in a String
created 27 July 2010
modified 2 Apr 2012
by Tom Igoe
http://arduino.cc/en/Tutorial/StringStartsWithEndsWith
This example code is in the public domain.
*/
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) ;
;
Serial.println("\n\nString startsWith() and endsWith():");
}
void loop() {
// startsWith() checks to see if a String starts with a particular substring:
String stringOne = "HTTP/1.1 200 OK";
Serial.println(stringOne);
if (stringOne.startsWith("HTTP/1.1")) {
Serial.println("Server's using http version 1.1");
}
// you can also look for startsWith() at an offset position in the string:
stringOne = "HTTP/1.1 200 OK";
if (stringOne.startsWith("200 OK", 9)) {
Serial.println("Got an OK from the server");
}
// endsWith() checks to see if a String ends with a particular character:
String sensorReading = "sensor = ";
sensorReading += analogRead(A0);
Serial.print (sensorReading);
if (sensorReading.endsWith(0)) {
Serial.println(". This reading is divisible by ten");
}
else {
Serial.println(". This reading is not divisible by ten");
}
// do nothing while true:
while(true);
}

View File

@ -1,41 +0,0 @@
/*
String substring()
Examples of how to use substring in a String
created 27 July 2010,
modified 2 Apr 2012
by Zach Eveland
http://arduino.cc/en/Tutorial/StringSubstring
This example code is in the public domain.
*/
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) ;
;
Serial.println("\n\nString substring():");
}
void loop() {
// Set up a String:
String stringOne = "Content-Type: text/html";
Serial.println(stringOne);
// substring(index) looks for the substring from the index position to the end:
if (stringOne.substring(19) == "html") {
Serial.println("It's an html file");
}
// you can also look for a substring in the middle of a string:
if (stringOne.substring(14,18) == "text") {
Serial.println("It's a text-based file");
}
// do nothing while true:
while(true);
}

View File

@ -1,49 +0,0 @@
/*
String to Integer conversion
Reads a serial input string until it sees a newline, then converts
the string to a number if the characters are digits.
The circuit:
No external components needed.
created 29 Nov 2010
by Tom Igoe
This example code is in the public domain.
*/
String inString = ""; // string to hold input
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) ;
;
Serial.println("\n\nString toInt():");
}
void loop() {
// Read serial input:
while (Serial.available() > 0) {
int inChar = Serial.read();
if (isDigit(inChar)) {
// convert the incoming byte to a char
// and add it to the string:
inString += (char)inChar;
}
// if you get a newline, print the string,
// then the string's value:
if (inChar == '\n') {
Serial.print("Value:");
Serial.println(inString.toInt());
Serial.print("String: ");
Serial.println(inString);
// clear the string for new input:
inString = "";
}
}
}

View File

@ -1,235 +0,0 @@
/*
Serial RGB controller
Reads a serial input string looking for three comma-separated
integers with a newline at the end. Values should be between
0 and 255. The sketch uses those values to set the color
of an RGB LED attached to pins 9 - 11.
The circuit:
* Common-anode RGB LED cathodes attached to pins 9 - 11
* LED anode connected to pin 13
To turn on any given channel, set the pin LOW.
To turn off, set the pin HIGH. The higher the analogWrite level,
the lower the brightness.
created 29 Nov 2010
by Tom Igoe
This example code is in the public domain.
*/
String inString = ""; // string to hold input
int currentColor = 0;
int red, green, blue = 0;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
// this check is only needed on the Leonardo:
while (!Serial) ;
;
Serial.println("\n\nString toInt() RGB:");
// set LED cathode pins as outputs:
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
// turn on pin 13 to power the LEDs:
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
}
void loop() {
int inChar;
// Read serial input:
if (Serial.available() > 0) {
inChar = Serial.read();
}
if (isDigit(inChar)) {
// convert the incoming byte to a char
// and add it to the string:
inString += (char)inChar;
}
// if you get a comma, convert to a number,
// set the appropriate color, and increment
// the color counter:
if (inChar == ',') {
// do something different for each value of currentColor:
switch (currentColor) {
case 0: // 0 = red
red = inString.toInt();
// clear the string for new input:
inString = "";
break;
case 1: // 1 = green:
green = inString.toInt();
// clear the string for new input:
inString = "";
break;
}
currentColor++;
}
// if you get a newline, you know you've got
// the last color, i.e. blue:
if (inChar == '\n') {
blue = inString.toInt();
// set the levels of the LED.
// subtract value from 255 because a higher
// analogWrite level means a dimmer LED, since
// you're raising the level on the anode:
analogWrite(11, 255 - red);
analogWrite(9, 255 - green);
analogWrite(10, 255 - blue);
// print the colors:
Serial.print("Red: ");
Serial.print(red);
Serial.print(", Green: ");
Serial.print(green);
Serial.print(", Blue: ");
Serial.println(blue);
// clear the string for new input:
inString = "";
// reset the color counter:
currentColor = 0;
}
}
/*
Here's a Processing sketch that will draw a color wheel and send a serial
string with the color you click on:
// Subtractive Color Wheel with Serial
// Based on a Processing example by Ira Greenberg.
// Serial output added by Tom Igoe
//
// The primaries are red, yellow, and blue. The secondaries are green,
// purple, and orange. The tertiaries are yellow-orange, red-orange,
// red-purple, blue-purple, blue-green, and yellow-green.
//
// Create a shade or tint of the subtractive color wheel using
// SHADE or TINT parameters.
// Updated 29 November 2010.
import processing.serial.*;
int segs = 12;
int steps = 6;
float rotAdjust = TWO_PI / segs / 2;
float radius;
float segWidth;
float interval = TWO_PI / segs;
Serial myPort;
void setup() {
size(200, 200);
background(127);
smooth();
ellipseMode(RADIUS);
noStroke();
// make the diameter 90% of the sketch area
radius = min(width, height) * 0.45;
segWidth = radius / steps;
// swap which line is commented out to draw the other version
// drawTintWheel();
drawShadeWheel();
// open the first serial port in your computer's list
myPort = new Serial(this, Serial.list()[0], 9600);
}
void drawShadeWheel() {
for (int j = 0; j < steps; j++) {
color[] cols = {
color(255-(255/steps)*j, 255-(255/steps)*j, 0),
color(255-(255/steps)*j, (255/1.5)-((255/1.5)/steps)*j, 0),
color(255-(255/steps)*j, (255/2)-((255/2)/steps)*j, 0),
color(255-(255/steps)*j, (255/2.5)-((255/2.5)/steps)*j, 0),
color(255-(255/steps)*j, 0, 0),
color(255-(255/steps)*j, 0, (255/2)-((255/2)/steps)*j),
color(255-(255/steps)*j, 0, 255-(255/steps)*j),
color((255/2)-((255/2)/steps)*j, 0, 255-(255/steps)*j),
color(0, 0, 255-(255/steps)*j),
color(0, 255-(255/steps)*j, (255/2.5)-((255/2.5)/steps)*j),
color(0, 255-(255/steps)*j, 0),
color((255/2)-((255/2)/steps)*j, 255-(255/steps)*j, 0)
};
for (int i = 0; i < segs; i++) {
fill(cols[i]);
arc(width/2, height/2, radius, radius,
interval*i+rotAdjust, interval*(i+1)+rotAdjust);
}
radius -= segWidth;
}
}
void drawTintWheel() {
for (int j = 0; j < steps; j++) {
color[] cols = {
color((255/steps)*j, (255/steps)*j, 0),
color((255/steps)*j, ((255/1.5)/steps)*j, 0),
color((255/steps)*j, ((255/2)/steps)*j, 0),
color((255/steps)*j, ((255/2.5)/steps)*j, 0),
color((255/steps)*j, 0, 0),
color((255/steps)*j, 0, ((255/2)/steps)*j),
color((255/steps)*j, 0, (255/steps)*j),
color(((255/2)/steps)*j, 0, (255/steps)*j),
color(0, 0, (255/steps)*j),
color(0, (255/steps)*j, ((255/2.5)/steps)*j),
color(0, (255/steps)*j, 0),
color(((255/2)/steps)*j, (255/steps)*j, 0)
};
for (int i = 0; i < segs; i++) {
fill(cols[i]);
arc(width/2, height/2, radius, radius,
interval*i+rotAdjust, interval*(i+1)+rotAdjust);
}
radius -= segWidth;
}
}
void draw() {
// nothing happens here
}
void mouseReleased() {
// get the color of the mouse position's pixel:
color targetColor = get(mouseX, mouseY);
// get the component values:
int r = int(red(targetColor));
int g = int(green(targetColor));
int b = int(blue(targetColor));
// make a comma-separated string:
String colorString = r + "," + g + "," + b + "\n";
// send it out the serial port:
myPort.write(colorString );
}
*/

View File

@ -1,95 +0,0 @@
/*
Keyboard logout
This sketch demonstrates the Keyboard library.
When you connect pin 2 to ground, it performs a logout.
It uses keyboard combinations to do this, as follows:
On Windows, CTRL-ALT-DEL followed by ALT-l
On Ubuntu, CTRL-ALT-DEL, and ENTER
On OSX, CMD-SHIFT-q
To wake: Spacebar.
Circuit:
* Arduino Leonardo
* wire to connect D2 to ground.
created 6 Mar 2012
modified 27 Mar 2012
by Tom Igoe
This example is in the public domain
http://www.arduino.cc/en/Tutorial/KeyboardLogout
*/
#define OSX 0
#define WINDOWS 1
#define UBUNTU 2
// change this to match your platform:
int platform = OSX;
void setup() {
// make pin 2 an input and turn on the
// pullup resistor so it goes high unless
// connected to ground:
pinMode(2, INPUT_PULLUP);
Keyboard.begin();
}
void loop() {
while (digitalRead(2) == HIGH) {
// do nothing until pin 2 goes low
delay(500);
}
delay(1000);
switch (platform) {
case OSX:
Keyboard.press(KEY_LEFT_GUI);
// Shift-Q logs out:
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.press('Q');
delay(100);
Keyboard.releaseAll();
// enter:
Keyboard.write(KEY_RETURN);
break;
case WINDOWS:
// CTRL-ALT-DEL:
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(KEY_DELETE);
delay(100);
Keyboard.releaseAll();
//ALT-s:
delay(2000);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press('l');
Keyboard.releaseAll();
break;
case UBUNTU:
// CTRL-ALT-DEL:
Keyboard.press(KEY_LEFT_CTRL);
Keyboard.press(KEY_LEFT_ALT);
Keyboard.press(KEY_DELETE);
delay(1000);
Keyboard.releaseAll();
// Enter to confirm logout:
Keyboard.write(KEY_RETURN);
break;
}
// do nothing:
while(true);
}

View File

@ -1,47 +0,0 @@
/*
Keyboard Button test
Sends a text string when a button is pressed.
The circuit:
* pushbutton attached from pin 2 to +5V
* 10-kilohm resistor attached from pin 4 to ground
created 24 Oct 2011
modified 27 Mar 2012
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/KeyboardButton
*/
const int buttonPin = 2; // input pin for pushbutton
int previousButtonState = HIGH; // for checking the state of a pushButton
int counter = 0; // button push counter
void setup() {
// make the pushButton pin an input:
pinMode(buttonPin, INPUT);
// initialize control over the keyboard:
Keyboard.begin();
}
void loop() {
// read the pushbutton:
int buttonState = digitalRead(buttonPin);
// if the button state has changed,
if ((buttonState != previousButtonState)
// and it's currently pressed:
&& (buttonState == HIGH)) {
// increment the button counter
counter++;
// type out a message
Keyboard.print("You pressed the button ");
Keyboard.print(counter);
Keyboard.println(" times.");
}
// save the current button state for comparison next time:
previousButtonState = buttonState;
}

View File

@ -1,95 +0,0 @@
/*
Arduino Programs Blink
This sketch demonstrates the Keyboard library.
When you connect pin 2 to ground, it creates a new
window with a key combination (CTRL-N),
then types in the Blink sketch, then auto-formats the text
using another key combination (CTRL-T), then
uploads the sketch to the currently selected Arduino using
a final key combination (CTRL-U).
Circuit:
* Arduino Leonardo
* wire to connect D2 to ground.
created 5 Mar 2012
modified 29 Mar 2012
by Tom Igoe
This example is in the public domain
http://www.arduino.cc/en/Tutorial/KeyboardReprogram
*/
// use this option for OSX.
// Comment it out if using Windows or Linux:
char ctrlKey = KEY_LEFT_GUI;
// use this option for Windows and Linux.
// leave commented out if using OSX:
// char ctrlKey = KEY_LEFT_CTRL;
void setup() {
// make pin 2 an input and turn on the
// pullup resistor so it goes high unless
// connected to ground:
pinMode(2, INPUT_PULLUP);
// initialize control over the keyboard:
Keyboard.begin();
}
void loop() {
while (digitalRead(2) == HIGH) {
// do nothing until pin 2 goes low
delay(500);
}
delay(1000);
// new document:
Keyboard.press(ctrlKey);
Keyboard.press('n');
delay(100);
Keyboard.releaseAll();
// wait for new window to open:
delay(1000);
// Type out "blink":
Keyboard.println("void setup() {");
Keyboard.println("pinMode(13, OUTPUT);");
Keyboard.println("}");
Keyboard.println();
Keyboard.println("void loop() {");
Keyboard.println("digitalWrite(13, HIGH);");
Keyboard.print("delay(3000);");
// 3000 ms is too long. Delete it:
for (int keystrokes=0; keystrokes < 6; keystrokes++) {
delay(500);
Keyboard.write(KEY_BACKSPACE);
}
// make it 1000 instead:
Keyboard.println("1000);");
Keyboard.println("digitalWrite(13, LOW);");
Keyboard.println("delay(1000);");
Keyboard.println("}");
// tidy up:
Keyboard.press(ctrlKey);
Keyboard.press('t');
delay(100);
Keyboard.releaseAll();
delay(3000);
// upload code:
Keyboard.press(ctrlKey);
Keyboard.press('u');
delay(100);
Keyboard.releaseAll();
// wait for the sweet oblivion of reprogramming:
while(true);
}

View File

@ -1,36 +0,0 @@
/*
Keyboard test
Reads a byte from the serial port, sends a keystroke back.
The sent keystroke is one higher than what's received, e.g.
if you send a, you get b, send A you get B, and so forth.
The circuit:
* none
created 21 Oct 2011
modified 27 Mar 2012
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/KeyboardSerial
*/
void setup() {
// open the serial port:
Serial.begin(9600);
// initialize control over the keyboard:
Keyboard.begin();
}
void loop() {
// check for incoming serial data:
if (Serial.available() > 0) {
// read incoming serial data:
char inChar = Serial.read();
// Type the next ASCII value from what you received:
Keyboard.write(inChar+1);
}
}

View File

@ -1,94 +0,0 @@
/*
KeyboardAndMouseControl
Controls the mouse from five pushbuttons on an Arduino Leonardo.
Hardware:
* 5 pushbuttons attached to D2, D3, D4, D5, D6
The mouse movement is always relative. This sketch reads
four pushbuttons, and uses them to set the movement of the mouse.
WARNING: When you use the Mouse.move() command, the Arduino takes
over your mouse! Make sure you have control before you use the mouse commands.
created 15 Mar 2012
modified 27 Mar 2012
by Tom Igoe
this code is in the public domain
*/
// set pin numbers for the five buttons:
// set pin numbers for the five buttons:
const int upButton = 2;
const int downButton = 3;
const int leftButton = 4;
const int rightButton = 5;
const int mouseButton = 6;
void setup() { // initialize the buttons' inputs:
pinMode(upButton, INPUT);
pinMode(downButton, INPUT);
pinMode(leftButton, INPUT);
pinMode(rightButton, INPUT);
pinMode(mouseButton, INPUT);
Serial.begin(9600);
// initialize mouse control:
Mouse.begin();
Keyboard.begin();
}
void loop() {
// use serial input to control the mouse:
if (Serial.available() > 0) {
char inChar = Serial.read();
switch (inChar) {
case 'u':
// move mouse up
Mouse.move(0, -40);
break;
case 'd':
// move mouse down
Mouse.move(0, 40);
break;
case 'l':
// move mouse left
Mouse.move(-40, 0);
break;
case 'r':
// move mouse right
Mouse.move(40, 0);
break;
case 'm':
// move mouse right
Mouse.click(MOUSE_LEFT);
break;
}
}
// use the pushbuttons to control the keyboard:
if (digitalRead(upButton) == HIGH) {
Keyboard.write('u');
}
if (digitalRead(downButton) == HIGH) {
Keyboard.write('d');
}
if (digitalRead(leftButton) == HIGH) {
Keyboard.write('l');
}
if (digitalRead(rightButton) == HIGH) {
Keyboard.write('r');
}
if (digitalRead(mouseButton) == HIGH) {
Keyboard.write('m');
}
}

View File

@ -1,81 +0,0 @@
/*
ButtonMouseControl
Controls the mouse from five pushbuttons on an Arduino Leonardo.
Hardware:
* 5 pushbuttons attached to D2, D3, D4, D5, D6
The mouse movement is always relative. This sketch reads
four pushbuttons, and uses them to set the movement of the mouse.
WARNING: When you use the Mouse.move() command, the Arduino takes
over your mouse! Make sure you have control before you use the mouse commands.
created 15 Mar 2012
modified 27 Mar 2012
by Tom Igoe
this code is in the public domain
*/
// set pin numbers for the five buttons:
const int upButton = 2;
const int downButton = 3;
const int leftButton = 4;
const int rightButton = 5;
const int mouseButton = 6;
int range = 5; // output range of X or Y movement; affects movement speed
int responseDelay = 10; // response delay of the mouse, in ms
void setup() {
// initialize the buttons' inputs:
pinMode(upButton, INPUT);
pinMode(downButton, INPUT);
pinMode(leftButton, INPUT);
pinMode(rightButton, INPUT);
pinMode(mouseButton, INPUT);
// initialize mouse control:
Mouse.begin();
}
void loop() {
// read the buttons:
int upState = digitalRead(upButton);
int downState = digitalRead(downButton);
int rightState = digitalRead(rightButton);
int leftState = digitalRead(leftButton);
int clickState = digitalRead(mouseButton);
// calculate the movement distance based on the button states:
int xDistance = (leftState - rightState)*range;
int yDistance = (upState - downState)*range;
// if X or Y is non-zero, move:
if ((xDistance != 0) || (yDistance != 0)) {
Mouse.move(xDistance, yDistance, 0);
}
// if the mouse button is pressed:
if (clickState == HIGH) {
// if the mouse is not pressed, press it:
if (!Mouse.isPressed(MOUSE_LEFT)) {
Mouse.press(MOUSE_LEFT);
}
}
// else the mouse button is not pressed:
else {
// if the mouse is pressed, release it:
if (Mouse.isPressed(MOUSE_LEFT)) {
Mouse.release(MOUSE_LEFT);
}
}
// a delay so the mouse doesn't move too fast:
delay(responseDelay);
}

View File

@ -1,121 +0,0 @@
/*
JoystickMouseControl
Controls the mouse from a joystick on an Arduino Leonardo.
Uses a pushbutton to turn on and off mouse control, and
a second pushbutton to click the left mouse button
Hardware:
* 2-axis joystick connected to pins A0 and A1
* pushbuttons connected to pin D2 and D3
The mouse movement is always relative. This sketch reads
two analog inputs that range from 0 to 1023 (or less on either end)
and translates them into ranges of -6 to 6.
The sketch assumes that the joystick resting values are around the
middle of the range, but that they vary within a threshold.
WARNING: When you use the Mouse.move() command, the Arduino takes
over your mouse! Make sure you have control before you use the command.
This sketch includes a pushbutton to toggle the mouse control state, so
you can turn on and off mouse control.
created 15 Sept 2011
updated 28 Mar 2012
by Tom Igoe
this code is in the public domain
*/
// set pin numbers for switch, joystick axes, and LED:
const int switchPin = 2; // switch to turn on and off mouse control
const int mouseButton = 3; // input pin for the mouse pushButton
const int xAxis = A0; // joystick X axis
const int yAxis = A1; // joystick Y axis
const int ledPin = 5; // Mouse control LED
// parameters for reading the joystick:
int range = 12; // output range of X or Y movement
int responseDelay = 5; // response delay of the mouse, in ms
int threshold = range/4; // resting threshold
int center = range/2; // resting position value
boolean mouseIsActive = false; // whether or not to control the mouse
int lastSwitchState = LOW; // previous switch state
void setup() {
pinMode(switchPin, INPUT); // the switch pin
pinMode(ledPin, OUTPUT); // the LED pin
// take control of the mouse:
Mouse.begin();
}
void loop() {
// read the switch:
int switchState = digitalRead(switchPin);
// if it's changed and it's high, toggle the mouse state:
if (switchState != lastSwitchState) {
if (switchState == HIGH) {
mouseIsActive = !mouseIsActive;
// turn on LED to indicate mouse state:
digitalWrite(ledPin, mouseIsActive);
}
}
// save switch state for next comparison:
lastSwitchState = switchState;
// read and scale the two axes:
int xReading = readAxis(A0);
int yReading = readAxis(A1);
// if the mouse control state is active, move the mouse:
if (mouseIsActive) {
Mouse.move(xReading, yReading, 0);
}
// read the mouse button and click or not click:
// if the mouse button is pressed:
if (digitalRead(mouseButton) == HIGH) {
// if the mouse is not pressed, press it:
if (!Mouse.isPressed(MOUSE_LEFT)) {
Mouse.press(MOUSE_LEFT);
}
}
// else the mouse button is not pressed:
else {
// if the mouse is pressed, release it:
if (Mouse.isPressed(MOUSE_LEFT)) {
Mouse.release(MOUSE_LEFT);
}
}
delay(responseDelay);
}
/*
reads an axis (0 or 1 for x or y) and scales the
analog input range to a range from 0 to <range>
*/
int readAxis(int thisAxis) {
// read the analog input:
int reading = analogRead(thisAxis);
// map the reading from the analog input range to the output range:
reading = map(reading, 0, 1023, 0, range);
// if the output reading is outside from the
// rest position threshold, use it:
int distance = reading - center;
if (abs(distance) < threshold) {
distance = 0;
}
// return the distance for this axis:
return distance;
}

View File

@ -1,554 +0,0 @@
// ArduinoISP version 04m3
// Copyright (c) 2008-2011 Randall Bohn
// If you require a license, see
// http://www.opensource.org/licenses/bsd-license.php
//
// This sketch turns the Arduino into a AVRISP
// using the following arduino pins:
//
// pin name: not-mega: mega(1280 and 2560)
// slave reset: 10: 53
// MOSI: 11: 51
// MISO: 12: 50
// SCK: 13: 52
//
// Put an LED (with resistor) on the following pins:
// 9: Heartbeat - shows the programmer is running
// 8: Error - Lights up if something goes wrong (use red if that makes sense)
// 7: Programming - In communication with the slave
//
// 23 July 2011 Randall Bohn
// -Address Arduino issue 509 :: Portability of ArduinoISP
// http://code.google.com/p/arduino/issues/detail?id=509
//
// October 2010 by Randall Bohn
// - Write to EEPROM > 256 bytes
// - Better use of LEDs:
// -- Flash LED_PMODE on each flash commit
// -- Flash LED_PMODE while writing EEPROM (both give visual feedback of writing progress)
// - Light LED_ERR whenever we hit a STK_NOSYNC. Turn it off when back in sync.
// - Use pins_arduino.h (should also work on Arduino Mega)
//
// October 2009 by David A. Mellis
// - Added support for the read signature command
//
// February 2009 by Randall Bohn
// - Added support for writing to EEPROM (what took so long?)
// Windows users should consider WinAVR's avrdude instead of the
// avrdude included with Arduino software.
//
// January 2008 by Randall Bohn
// - Thanks to Amplificar for helping me with the STK500 protocol
// - The AVRISP/STK500 (mk I) protocol is used in the arduino bootloader
// - The SPI functions herein were developed for the AVR910_ARD programmer
// - More information at http://code.google.com/p/mega-isp
#include "pins_arduino.h"
#define RESET SS
#define LED_HB 9
#define LED_ERR 8
#define LED_PMODE 7
#define PROG_FLICKER true
#define HWVER 2
#define SWMAJ 1
#define SWMIN 18
// STK Definitions
#define STK_OK 0x10
#define STK_FAILED 0x11
#define STK_UNKNOWN 0x12
#define STK_INSYNC 0x14
#define STK_NOSYNC 0x15
#define CRC_EOP 0x20 //ok it is a space...
void pulse(int pin, int times);
void setup() {
Serial.begin(19200);
pinMode(LED_PMODE, OUTPUT);
pulse(LED_PMODE, 2);
pinMode(LED_ERR, OUTPUT);
pulse(LED_ERR, 2);
pinMode(LED_HB, OUTPUT);
pulse(LED_HB, 2);
}
int error=0;
int pmode=0;
// address for reading and writing, set by 'U' command
int here;
uint8_t buff[256]; // global block storage
#define beget16(addr) (*addr * 256 + *(addr+1) )
typedef struct param {
uint8_t devicecode;
uint8_t revision;
uint8_t progtype;
uint8_t parmode;
uint8_t polling;
uint8_t selftimed;
uint8_t lockbytes;
uint8_t fusebytes;
int flashpoll;
int eeprompoll;
int pagesize;
int eepromsize;
int flashsize;
}
parameter;
parameter param;
// this provides a heartbeat on pin 9, so you can tell the software is running.
uint8_t hbval=128;
int8_t hbdelta=8;
void heartbeat() {
if (hbval > 192) hbdelta = -hbdelta;
if (hbval < 32) hbdelta = -hbdelta;
hbval += hbdelta;
analogWrite(LED_HB, hbval);
delay(20);
}
void loop(void) {
// is pmode active?
if (pmode) digitalWrite(LED_PMODE, HIGH);
else digitalWrite(LED_PMODE, LOW);
// is there an error?
if (error) digitalWrite(LED_ERR, HIGH);
else digitalWrite(LED_ERR, LOW);
// light the heartbeat LED
heartbeat();
if (Serial.available()) {
avrisp();
}
}
uint8_t getch() {
while(!Serial.available());
return Serial.read();
}
void fill(int n) {
for (int x = 0; x < n; x++) {
buff[x] = getch();
}
}
#define PTIME 30
void pulse(int pin, int times) {
do {
digitalWrite(pin, HIGH);
delay(PTIME);
digitalWrite(pin, LOW);
delay(PTIME);
}
while (times--);
}
void prog_lamp(int state) {
if (PROG_FLICKER)
digitalWrite(LED_PMODE, state);
}
void spi_init() {
uint8_t x;
SPCR = 0x53;
x=SPSR;
x=SPDR;
}
void spi_wait() {
do {
}
while (!(SPSR & (1 << SPIF)));
}
uint8_t spi_send(uint8_t b) {
uint8_t reply;
SPDR=b;
spi_wait();
reply = SPDR;
return reply;
}
uint8_t spi_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
uint8_t n;
spi_send(a);
n=spi_send(b);
//if (n != a) error = -1;
n=spi_send(c);
return spi_send(d);
}
void empty_reply() {
if (CRC_EOP == getch()) {
Serial.print((char)STK_INSYNC);
Serial.print((char)STK_OK);
}
else {
error++;
Serial.print((char)STK_NOSYNC);
}
}
void breply(uint8_t b) {
if (CRC_EOP == getch()) {
Serial.print((char)STK_INSYNC);
Serial.print((char)b);
Serial.print((char)STK_OK);
}
else {
error++;
Serial.print((char)STK_NOSYNC);
}
}
void get_version(uint8_t c) {
switch(c) {
case 0x80:
breply(HWVER);
break;
case 0x81:
breply(SWMAJ);
break;
case 0x82:
breply(SWMIN);
break;
case 0x93:
breply('S'); // serial programmer
break;
default:
breply(0);
}
}
void set_parameters() {
// call this after reading paramter packet into buff[]
param.devicecode = buff[0];
param.revision = buff[1];
param.progtype = buff[2];
param.parmode = buff[3];
param.polling = buff[4];
param.selftimed = buff[5];
param.lockbytes = buff[6];
param.fusebytes = buff[7];
param.flashpoll = buff[8];
// ignore buff[9] (= buff[8])
// following are 16 bits (big endian)
param.eeprompoll = beget16(&buff[10]);
param.pagesize = beget16(&buff[12]);
param.eepromsize = beget16(&buff[14]);
// 32 bits flashsize (big endian)
param.flashsize = buff[16] * 0x01000000
+ buff[17] * 0x00010000
+ buff[18] * 0x00000100
+ buff[19];
}
void start_pmode() {
spi_init();
// following delays may not work on all targets...
pinMode(RESET, OUTPUT);
digitalWrite(RESET, HIGH);
pinMode(SCK, OUTPUT);
digitalWrite(SCK, LOW);
delay(50);
digitalWrite(RESET, LOW);
delay(50);
pinMode(MISO, INPUT);
pinMode(MOSI, OUTPUT);
spi_transaction(0xAC, 0x53, 0x00, 0x00);
pmode = 1;
}
void end_pmode() {
pinMode(MISO, INPUT);
pinMode(MOSI, INPUT);
pinMode(SCK, INPUT);
pinMode(RESET, INPUT);
pmode = 0;
}
void universal() {
int w;
uint8_t ch;
fill(4);
ch = spi_transaction(buff[0], buff[1], buff[2], buff[3]);
breply(ch);
}
void flash(uint8_t hilo, int addr, uint8_t data) {
spi_transaction(0x40+8*hilo,
addr>>8 & 0xFF,
addr & 0xFF,
data);
}
void commit(int addr) {
if (PROG_FLICKER) prog_lamp(LOW);
spi_transaction(0x4C, (addr >> 8) & 0xFF, addr & 0xFF, 0);
if (PROG_FLICKER) {
delay(PTIME);
prog_lamp(HIGH);
}
}
//#define _current_page(x) (here & 0xFFFFE0)
int current_page(int addr) {
if (param.pagesize == 32) return here & 0xFFFFFFF0;
if (param.pagesize == 64) return here & 0xFFFFFFE0;
if (param.pagesize == 128) return here & 0xFFFFFFC0;
if (param.pagesize == 256) return here & 0xFFFFFF80;
return here;
}
void write_flash(int length) {
fill(length);
if (CRC_EOP == getch()) {
Serial.print((char) STK_INSYNC);
Serial.print((char) write_flash_pages(length));
}
else {
error++;
Serial.print((char) STK_NOSYNC);
}
}
uint8_t write_flash_pages(int length) {
int x = 0;
int page = current_page(here);
while (x < length) {
if (page != current_page(here)) {
commit(page);
page = current_page(here);
}
flash(LOW, here, buff[x++]);
flash(HIGH, here, buff[x++]);
here++;
}
commit(page);
return STK_OK;
}
#define EECHUNK (32)
uint8_t write_eeprom(int length) {
// here is a word address, get the byte address
int start = here * 2;
int remaining = length;
if (length > param.eepromsize) {
error++;
return STK_FAILED;
}
while (remaining > EECHUNK) {
write_eeprom_chunk(start, EECHUNK);
start += EECHUNK;
remaining -= EECHUNK;
}
write_eeprom_chunk(start, remaining);
return STK_OK;
}
// write (length) bytes, (start) is a byte address
uint8_t write_eeprom_chunk(int start, int length) {
// this writes byte-by-byte,
// page writing may be faster (4 bytes at a time)
fill(length);
prog_lamp(LOW);
for (int x = 0; x < length; x++) {
int addr = start+x;
spi_transaction(0xC0, (addr>>8) & 0xFF, addr & 0xFF, buff[x]);
delay(45);
}
prog_lamp(HIGH);
return STK_OK;
}
void program_page() {
char result = (char) STK_FAILED;
int length = 256 * getch();
length += getch();
char memtype = getch();
// flash memory @here, (length) bytes
if (memtype == 'F') {
write_flash(length);
return;
}
if (memtype == 'E') {
result = (char)write_eeprom(length);
if (CRC_EOP == getch()) {
Serial.print((char) STK_INSYNC);
Serial.print(result);
}
else {
error++;
Serial.print((char) STK_NOSYNC);
}
return;
}
Serial.print((char)STK_FAILED);
return;
}
uint8_t flash_read(uint8_t hilo, int addr) {
return spi_transaction(0x20 + hilo * 8,
(addr >> 8) & 0xFF,
addr & 0xFF,
0);
}
char flash_read_page(int length) {
for (int x = 0; x < length; x+=2) {
uint8_t low = flash_read(LOW, here);
Serial.print((char) low);
uint8_t high = flash_read(HIGH, here);
Serial.print((char) high);
here++;
}
return STK_OK;
}
char eeprom_read_page(int length) {
// here again we have a word address
int start = here * 2;
for (int x = 0; x < length; x++) {
int addr = start + x;
uint8_t ee = spi_transaction(0xA0, (addr >> 8) & 0xFF, addr & 0xFF, 0xFF);
Serial.print((char) ee);
}
return STK_OK;
}
void read_page() {
char result = (char)STK_FAILED;
int length = 256 * getch();
length += getch();
char memtype = getch();
if (CRC_EOP != getch()) {
error++;
Serial.print((char) STK_NOSYNC);
return;
}
Serial.print((char) STK_INSYNC);
if (memtype == 'F') result = flash_read_page(length);
if (memtype == 'E') result = eeprom_read_page(length);
Serial.print(result);
return;
}
void read_signature() {
if (CRC_EOP != getch()) {
error++;
Serial.print((char) STK_NOSYNC);
return;
}
Serial.print((char) STK_INSYNC);
uint8_t high = spi_transaction(0x30, 0x00, 0x00, 0x00);
Serial.print((char) high);
uint8_t middle = spi_transaction(0x30, 0x00, 0x01, 0x00);
Serial.print((char) middle);
uint8_t low = spi_transaction(0x30, 0x00, 0x02, 0x00);
Serial.print((char) low);
Serial.print((char) STK_OK);
}
//////////////////////////////////////////
//////////////////////////////////////////
////////////////////////////////////
////////////////////////////////////
int avrisp() {
uint8_t data, low, high;
uint8_t ch = getch();
switch (ch) {
case '0': // signon
error = 0;
empty_reply();
break;
case '1':
if (getch() == CRC_EOP) {
Serial.print((char) STK_INSYNC);
Serial.print("AVR ISP");
Serial.print((char) STK_OK);
}
break;
case 'A':
get_version(getch());
break;
case 'B':
fill(20);
set_parameters();
empty_reply();
break;
case 'E': // extended parameters - ignore for now
fill(5);
empty_reply();
break;
case 'P':
start_pmode();
empty_reply();
break;
case 'U': // set address (word)
here = getch();
here += 256 * getch();
empty_reply();
break;
case 0x60: //STK_PROG_FLASH
low = getch();
high = getch();
empty_reply();
break;
case 0x61: //STK_PROG_DATA
data = getch();
empty_reply();
break;
case 0x64: //STK_PROG_PAGE
program_page();
break;
case 0x74: //STK_READ_PAGE 't'
read_page();
break;
case 'V': //0x56
universal();
break;
case 'Q': //0x51
error=0;
end_pmode();
empty_reply();
break;
case 0x75: //STK_READ_SIGN 'u'
read_signature();
break;
// expecting a command, not CRC_EOP
// this is how we can get back in sync
case CRC_EOP:
error++;
Serial.print((char) STK_NOSYNC);
break;
// anything else we will return STK_UNKNOWN
default:
error++;
if (CRC_EOP == getch())
Serial.print((char)STK_UNKNOWN);
else
Serial.print((char)STK_NOSYNC);
}
}

View File

@ -1,477 +0,0 @@
# See: http://code.google.com/p/arduino/wiki/Platforms
##############################################################
uno.name=Arduino Uno
uno.upload.protocol=arduino
uno.upload.maximum_size=32256
uno.upload.speed=115200
uno.bootloader.low_fuses=0xff
uno.bootloader.high_fuses=0xde
uno.bootloader.extended_fuses=0x05
uno.bootloader.path=optiboot
uno.bootloader.file=optiboot_atmega328.hex
uno.bootloader.unlock_bits=0x3F
uno.bootloader.lock_bits=0x0F
uno.build.mcu=atmega328p
uno.build.f_cpu=16000000L
uno.build.core=arduino
uno.build.variant=standard
##############################################################
atmega328.name=Arduino Duemilanove w/ ATmega328
atmega328.upload.protocol=arduino
atmega328.upload.maximum_size=30720
atmega328.upload.speed=57600
atmega328.bootloader.low_fuses=0xFF
atmega328.bootloader.high_fuses=0xDA
atmega328.bootloader.extended_fuses=0x05
atmega328.bootloader.path=atmega
atmega328.bootloader.file=ATmegaBOOT_168_atmega328.hex
atmega328.bootloader.unlock_bits=0x3F
atmega328.bootloader.lock_bits=0x0F
atmega328.build.mcu=atmega328p
atmega328.build.f_cpu=16000000L
atmega328.build.core=arduino
atmega328.build.variant=standard
##############################################################
diecimila.name=Arduino Diecimila or Duemilanove w/ ATmega168
diecimila.upload.protocol=arduino
diecimila.upload.maximum_size=14336
diecimila.upload.speed=19200
diecimila.bootloader.low_fuses=0xff
diecimila.bootloader.high_fuses=0xdd
diecimila.bootloader.extended_fuses=0x00
diecimila.bootloader.path=atmega
diecimila.bootloader.file=ATmegaBOOT_168_diecimila.hex
diecimila.bootloader.unlock_bits=0x3F
diecimila.bootloader.lock_bits=0x0F
diecimila.build.mcu=atmega168
diecimila.build.f_cpu=16000000L
diecimila.build.core=arduino
diecimila.build.variant=standard
##############################################################
nano328.name=Arduino Nano w/ ATmega328
nano328.upload.protocol=arduino
nano328.upload.maximum_size=30720
nano328.upload.speed=57600
nano328.bootloader.low_fuses=0xFF
nano328.bootloader.high_fuses=0xDA
nano328.bootloader.extended_fuses=0x05
nano328.bootloader.path=atmega
nano328.bootloader.file=ATmegaBOOT_168_atmega328.hex
nano328.bootloader.unlock_bits=0x3F
nano328.bootloader.lock_bits=0x0F
nano328.build.mcu=atmega328p
nano328.build.f_cpu=16000000L
nano328.build.core=arduino
nano328.build.variant=eightanaloginputs
##############################################################
nano.name=Arduino Nano w/ ATmega168
nano.upload.protocol=arduino
nano.upload.maximum_size=14336
nano.upload.speed=19200
nano.bootloader.low_fuses=0xff
nano.bootloader.high_fuses=0xdd
nano.bootloader.extended_fuses=0x00
nano.bootloader.path=atmega
nano.bootloader.file=ATmegaBOOT_168_diecimila.hex
nano.bootloader.unlock_bits=0x3F
nano.bootloader.lock_bits=0x0F
nano.build.mcu=atmega168
nano.build.f_cpu=16000000L
nano.build.core=arduino
nano.build.variant=eightanaloginputs
##############################################################
mega2560.name=Arduino Mega 2560 or Mega ADK
mega2560.upload.protocol=stk500v2
mega2560.upload.maximum_size=258048
mega2560.upload.speed=115200
mega2560.bootloader.low_fuses=0xFF
mega2560.bootloader.high_fuses=0xD8
mega2560.bootloader.extended_fuses=0xFD
mega2560.bootloader.path=stk500v2
mega2560.bootloader.file=stk500boot_v2_mega2560.hex
mega2560.bootloader.unlock_bits=0x3F
mega2560.bootloader.lock_bits=0x0F
mega2560.build.mcu=atmega2560
mega2560.build.f_cpu=16000000L
mega2560.build.core=arduino
mega2560.build.variant=mega
##############################################################
mega.name=Arduino Mega (ATmega1280)
mega.upload.protocol=arduino
mega.upload.maximum_size=126976
mega.upload.speed=57600
mega.bootloader.low_fuses=0xFF
mega.bootloader.high_fuses=0xDA
mega.bootloader.extended_fuses=0xF5
mega.bootloader.path=atmega
mega.bootloader.file=ATmegaBOOT_168_atmega1280.hex
mega.bootloader.unlock_bits=0x3F
mega.bootloader.lock_bits=0x0F
mega.build.mcu=atmega1280
mega.build.f_cpu=16000000L
mega.build.core=arduino
mega.build.variant=mega
##############################################################
leonardo.name=Arduino Leonardo
leonardo.upload.protocol=avr109
leonardo.upload.maximum_size=28672
leonardo.upload.speed=57600
leonardo.upload.disable_flushing=true
leonardo.bootloader.low_fuses=0xff
leonardo.bootloader.high_fuses=0xd8
leonardo.bootloader.extended_fuses=0xcb
leonardo.bootloader.path=caterina
leonardo.bootloader.file=Caterina.hex
leonardo.bootloader.unlock_bits=0x3F
leonardo.bootloader.lock_bits=0x2F
leonardo.build.mcu=atmega32u4
leonardo.build.f_cpu=16000000L
leonardo.build.core=arduino
leonardo.build.variant=leonardo
##############################################################
#micro.name=Arduino Micro
#micro.upload.protocol=arduino
#micro.upload.maximum_size=30720
#micro.upload.speed=1200
#micro.bootloader.low_fuses=0xde
#micro.bootloader.high_fuses=0xda
#micro.bootloader.extended_fuses=0xcb
#micro.bootloader.path=caterina
#micro.bootloader.file=Caterina-Micro.hex
#micro.bootloader.unlock_bits=0x3F
#micro.bootloader.lock_bits=0x2F
#micro.build.mcu=atmega32u4
#micro.build.f_cpu=16000000L
#micro.build.core=arduino
#micro.build.variant=micro
##############################################################
mini328.name=Arduino Mini w/ ATmega328
mini328.upload.protocol=arduino
mini328.upload.maximum_size=28672
mini328.upload.speed=115200
mini328.bootloader.low_fuses=0xff
mini328.bootloader.high_fuses=0xd8
mini328.bootloader.extended_fuses=0x05
mini328.bootloader.path=optiboot
mini328.bootloader.file=optiboot_atmega328-Mini.hex
mini328.bootloader.unlock_bits=0x3F
mini328.bootloader.lock_bits=0x0F
mini328.build.mcu=atmega328p
mini328.build.f_cpu=16000000L
mini328.build.core=arduino
mini328.build.variant=eightanaloginputs
##############################################################
mini.name=Arduino Mini w/ ATmega168
mini.upload.protocol=arduino
mini.upload.maximum_size=14336
mini.upload.speed=19200
mini.bootloader.low_fuses=0xff
mini.bootloader.high_fuses=0xdd
mini.bootloader.extended_fuses=0x00
mini.bootloader.path=atmega
mini.bootloader.file=ATmegaBOOT_168_ng.hex
mini.bootloader.unlock_bits=0x3F
mini.bootloader.lock_bits=0x0F
mini.build.mcu=atmega168
mini.build.f_cpu=16000000L
mini.build.core=arduino
mini.build.variant=eightanaloginputs
##############################################################
ethernet.name=Arduino Ethernet
ethernet.upload.protocol=arduino
ethernet.upload.maximum_size=32256
ethernet.upload.speed=115200
ethernet.bootloader.low_fuses=0xff
ethernet.bootloader.high_fuses=0xde
ethernet.bootloader.extended_fuses=0x05
ethernet.bootloader.path=optiboot
ethernet.bootloader.file=optiboot_atmega328.hex
ethernet.bootloader.unlock_bits=0x3F
ethernet.bootloader.lock_bits=0x0F
ethernet.build.variant=standard
ethernet.build.mcu=atmega328p
ethernet.build.f_cpu=16000000L
ethernet.build.core=arduino
##############################################################
fio.name=Arduino Fio
fio.upload.protocol=arduino
fio.upload.maximum_size=30720
fio.upload.speed=57600
fio.bootloader.low_fuses=0xFF
fio.bootloader.high_fuses=0xDA
fio.bootloader.extended_fuses=0x05
fio.bootloader.path=arduino:atmega
fio.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex
fio.bootloader.unlock_bits=0x3F
fio.bootloader.lock_bits=0x0F
fio.build.mcu=atmega328p
fio.build.f_cpu=8000000L
fio.build.core=arduino
fio.build.variant=eightanaloginputs
##############################################################
bt328.name=Arduino BT w/ ATmega328
bt328.upload.protocol=arduino
bt328.upload.maximum_size=28672
bt328.upload.speed=19200
bt328.upload.disable_flushing=true
bt328.bootloader.low_fuses=0xff
bt328.bootloader.high_fuses=0xd8
bt328.bootloader.extended_fuses=0x05
bt328.bootloader.path=bt
bt328.bootloader.file=ATmegaBOOT_168_atmega328_bt.hex
bt328.bootloader.unlock_bits=0x3F
bt328.bootloader.lock_bits=0x0F
bt328.build.mcu=atmega328p
bt328.build.f_cpu=16000000L
bt328.build.core=arduino
bt328.build.variant=eightanaloginputs
##############################################################
bt.name=Arduino BT w/ ATmega168
bt.upload.protocol=arduino
bt.upload.maximum_size=14336
bt.upload.speed=19200
bt.upload.disable_flushing=true
bt.bootloader.low_fuses=0xff
bt.bootloader.high_fuses=0xdd
bt.bootloader.extended_fuses=0x00
bt.bootloader.path=bt
bt.bootloader.file=ATmegaBOOT_168.hex
bt.bootloader.unlock_bits=0x3F
bt.bootloader.lock_bits=0x0F
bt.build.mcu=atmega168
bt.build.f_cpu=16000000L
bt.build.core=arduino
bt.build.variant=eightanaloginputs
##############################################################
lilypad328.name=LilyPad Arduino w/ ATmega328
lilypad328.upload.protocol=arduino
lilypad328.upload.maximum_size=30720
lilypad328.upload.speed=57600
lilypad328.bootloader.low_fuses=0xFF
lilypad328.bootloader.high_fuses=0xDA
lilypad328.bootloader.extended_fuses=0x05
lilypad328.bootloader.path=atmega
lilypad328.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex
lilypad328.bootloader.unlock_bits=0x3F
lilypad328.bootloader.lock_bits=0x0F
lilypad328.build.mcu=atmega328p
lilypad328.build.f_cpu=8000000L
lilypad328.build.core=arduino
lilypad328.build.variant=standard
##############################################################
lilypad.name=LilyPad Arduino w/ ATmega168
lilypad.upload.protocol=arduino
lilypad.upload.maximum_size=14336
lilypad.upload.speed=19200
lilypad.bootloader.low_fuses=0xe2
lilypad.bootloader.high_fuses=0xdd
lilypad.bootloader.extended_fuses=0x00
lilypad.bootloader.path=lilypad
lilypad.bootloader.file=LilyPadBOOT_168.hex
lilypad.bootloader.unlock_bits=0x3F
lilypad.bootloader.lock_bits=0x0F
lilypad.build.mcu=atmega168
lilypad.build.f_cpu=8000000L
lilypad.build.core=arduino
lilypad.build.variant=standard
##############################################################
pro5v328.name=Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328
pro5v328.upload.protocol=arduino
pro5v328.upload.maximum_size=30720
pro5v328.upload.speed=57600
pro5v328.bootloader.low_fuses=0xFF
pro5v328.bootloader.high_fuses=0xDA
pro5v328.bootloader.extended_fuses=0x05
pro5v328.bootloader.path=atmega
pro5v328.bootloader.file=ATmegaBOOT_168_atmega328.hex
pro5v328.bootloader.unlock_bits=0x3F
pro5v328.bootloader.lock_bits=0x0F
pro5v328.build.mcu=atmega328p
pro5v328.build.f_cpu=16000000L
pro5v328.build.core=arduino
pro5v328.build.variant=standard
##############################################################
pro5v.name=Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega168
pro5v.upload.protocol=arduino
pro5v.upload.maximum_size=14336
pro5v.upload.speed=19200
pro5v.bootloader.low_fuses=0xff
pro5v.bootloader.high_fuses=0xdd
pro5v.bootloader.extended_fuses=0x00
pro5v.bootloader.path=atmega
pro5v.bootloader.file=ATmegaBOOT_168_diecimila.hex
pro5v.bootloader.unlock_bits=0x3F
pro5v.bootloader.lock_bits=0x0F
pro5v.build.mcu=atmega168
pro5v.build.f_cpu=16000000L
pro5v.build.core=arduino
pro5v.build.variant=standard
##############################################################
pro328.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega328
pro328.upload.protocol=arduino
pro328.upload.maximum_size=30720
pro328.upload.speed=57600
pro328.bootloader.low_fuses=0xFF
pro328.bootloader.high_fuses=0xDA
pro328.bootloader.extended_fuses=0x05
pro328.bootloader.path=atmega
pro328.bootloader.file=ATmegaBOOT_168_atmega328_pro_8MHz.hex
pro328.bootloader.unlock_bits=0x3F
pro328.bootloader.lock_bits=0x0F
pro328.build.mcu=atmega328p
pro328.build.f_cpu=8000000L
pro328.build.core=arduino
pro328.build.variant=standard
##############################################################
pro.name=Arduino Pro or Pro Mini (3.3V, 8 MHz) w/ ATmega168
pro.upload.protocol=arduino
pro.upload.maximum_size=14336
pro.upload.speed=19200
pro.bootloader.low_fuses=0xc6
pro.bootloader.high_fuses=0xdd
pro.bootloader.extended_fuses=0x00
pro.bootloader.path=atmega
pro.bootloader.file=ATmegaBOOT_168_pro_8MHz.hex
pro.bootloader.unlock_bits=0x3F
pro.bootloader.lock_bits=0x0F
pro.build.mcu=atmega168
pro.build.f_cpu=8000000L
pro.build.core=arduino
pro.build.variant=standard
##############################################################
atmega168.name=Arduino NG or older w/ ATmega168
atmega168.upload.protocol=arduino
atmega168.upload.maximum_size=14336
atmega168.upload.speed=19200
atmega168.bootloader.low_fuses=0xff
atmega168.bootloader.high_fuses=0xdd
atmega168.bootloader.extended_fuses=0x00
atmega168.bootloader.path=atmega
atmega168.bootloader.file=ATmegaBOOT_168_ng.hex
atmega168.bootloader.unlock_bits=0x3F
atmega168.bootloader.lock_bits=0x0F
atmega168.build.mcu=atmega168
atmega168.build.f_cpu=16000000L
atmega168.build.core=arduino
atmega168.build.variant=standard
##############################################################
atmega8.name=Arduino NG or older w/ ATmega8
atmega8.upload.protocol=arduino
atmega8.upload.maximum_size=7168
atmega8.upload.speed=19200
atmega8.bootloader.low_fuses=0xdf
atmega8.bootloader.high_fuses=0xca
atmega8.bootloader.path=atmega8
atmega8.bootloader.file=ATmegaBOOT.hex
atmega8.bootloader.unlock_bits=0x3F
atmega8.bootloader.lock_bits=0x0F
atmega8.build.mcu=atmega8
atmega8.build.f_cpu=16000000L
atmega8.build.core=arduino
atmega8.build.variant=standard

View File

@ -1,1054 +0,0 @@
/**********************************************************/
/* Serial Bootloader for Atmel megaAVR Controllers */
/* */
/* tested with ATmega8, ATmega128 and ATmega168 */
/* should work with other mega's, see code for details */
/* */
/* ATmegaBOOT.c */
/* */
/* */
/* 20090308: integrated Mega changes into main bootloader */
/* source by D. Mellis */
/* 20080930: hacked for Arduino Mega (with the 1280 */
/* processor, backwards compatible) */
/* by D. Cuartielles */
/* 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 <util/delay.h>
/* the current avr-libc eeprom functions do not support the ATmega168 */
/* own eeprom write/read functions are used instead */
#if !defined(__AVR_ATmega168__) || !defined(__AVR_ATmega328P__)
#include <avr/eeprom.h>
#endif
/* Use the F_CPU defined in Makefile */
/* 20060803: hacked by DojoCorp */
/* 20070626: hacked by David A. Mellis to decrease waiting time for auto-reset */
/* set the waiting time for the bootloader */
/* get this from the Makefile instead */
/* #define MAX_TIME_COUNT (F_CPU>>4) */
/* 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 */
/* 20060803: hacked by DojoCorp */
//#define BAUD_RATE 115200
#ifndef BAUD_RATE
#define BAUD_RATE 19200
#endif
/* 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
/* Adjust to suit whatever pin your hardware uses to enter the bootloader */
/* ATmega128 has two UARTS so two pins are used to enter bootloader and select UART */
/* ATmega1280 has four UARTS, but for Arduino Mega, we will only use RXD0 to get code */
/* BL0... means UART0, BL1... means UART1 */
#ifdef __AVR_ATmega128__
#define BL_DDR DDRF
#define BL_PORT PORTF
#define BL_PIN PINF
#define BL0 PINF7
#define BL1 PINF6
#elif defined __AVR_ATmega1280__
/* we just don't do anything for the MEGA and enter bootloader on reset anyway*/
#else
/* other ATmegas have only one UART, so only one pin is defined to enter bootloader */
#define BL_DDR DDRD
#define BL_PORT PORTD
#define BL_PIN PIND
#define BL PIND6
#endif
/* 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 */
#if defined __AVR_ATmega128__ || defined __AVR_ATmega1280__
/* Onboard LED is connected to pin PB7 (e.g. Crumb128, PROBOmega128, Savvy128, Arduino Mega) */
#define LED_DDR DDRB
#define LED_PORT PORTB
#define LED_PIN PINB
#define LED PINB7
#else
/* Onboard LED is connected to pin PB5 in Arduino NG, Diecimila, and Duomilanuove */
/* other boards like e.g. Crumb8, Crumb168 are using PB2 */
#define LED_DDR DDRB
#define LED_PORT PORTB
#define LED_PIN PINB
#define LED PINB5
#endif
/* monitor functions will only be compiled when using ATmega128, due to bootblock size constraints */
#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__)
#define MONITOR 1
#endif
/* 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_ATmega1280__
#define SIG2 0x97
#define SIG3 0x03
#define PAGE_SIZE 0x80U //128 words
#elif defined __AVR_ATmega1281__
#define SIG2 0x97
#define SIG3 0x04
#define PAGE_SIZE 0x80U //128 words
#elif defined __AVR_ATmega128__
#define SIG2 0x97
#define SIG3 0x02
#define PAGE_SIZE 0x80U //128 words
#elif defined __AVR_ATmega64__
#define SIG2 0x96
#define SIG3 0x02
#define PAGE_SIZE 0x80U //128 words
#elif defined __AVR_ATmega32__
#define SIG2 0x95
#define SIG3 0x02
#define PAGE_SIZE 0x40U //64 words
#elif defined __AVR_ATmega16__
#define SIG2 0x94
#define SIG3 0x03
#define PAGE_SIZE 0x40U //64 words
#elif defined __AVR_ATmega8__
#define SIG2 0x93
#define SIG3 0x07
#define PAGE_SIZE 0x20U //32 words
#elif defined __AVR_ATmega88__
#define SIG2 0x93
#define SIG3 0x0a
#define PAGE_SIZE 0x20U //32 words
#elif defined __AVR_ATmega168__
#define SIG2 0x94
#define SIG3 0x06
#define PAGE_SIZE 0x40U //64 words
#elif defined __AVR_ATmega328P__
#define SIG2 0x95
#define SIG3 0x0F
#define PAGE_SIZE 0x40U //64 words
#elif defined __AVR_ATmega162__
#define SIG2 0x94
#define SIG3 0x04
#define PAGE_SIZE 0x40U //64 words
#elif defined __AVR_ATmega163__
#define SIG2 0x94
#define SIG3 0x02
#define PAGE_SIZE 0x40U //64 words
#elif defined __AVR_ATmega169__
#define SIG2 0x94
#define SIG3 0x05
#define PAGE_SIZE 0x40U //64 words
#elif defined __AVR_ATmega8515__
#define SIG2 0x93
#define SIG3 0x06
#define PAGE_SIZE 0x20U //32 words
#elif defined __AVR_ATmega8535__
#define SIG2 0x93
#define SIG3 0x08
#define PAGE_SIZE 0x20U //32 words
#endif
/* 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 address_high;
uint8_t pagesz=0x80;
uint8_t i;
uint8_t bootuart = 0;
uint8_t error_count = 0;
void (*app_start)(void) = 0x0000;
/* main program starts here */
int main(void)
{
uint8_t ch,ch2;
uint16_t w;
#ifdef WATCHDOG_MODS
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
#else
asm volatile("nop\n\t");
#endif
/* set pin direction for bootloader pin and enable pullup */
/* for ATmega128, two pins need to be initialized */
#ifdef __AVR_ATmega128__
BL_DDR &= ~_BV(BL0);
BL_DDR &= ~_BV(BL1);
BL_PORT |= _BV(BL0);
BL_PORT |= _BV(BL1);
#else
/* We run the bootloader regardless of the state of this pin. Thus, don't
put it in a different state than the other pins. --DAM, 070709
This also applies to Arduino Mega -- DC, 080930
BL_DDR &= ~_BV(BL);
BL_PORT |= _BV(BL);
*/
#endif
#ifdef __AVR_ATmega128__
/* check which UART should be used for booting */
if(bit_is_clear(BL_PIN, BL0)) {
bootuart = 1;
}
else if(bit_is_clear(BL_PIN, BL1)) {
bootuart = 2;
}
#endif
#if defined __AVR_ATmega1280__
/* the mega1280 chip has four serial ports ... we could eventually use any of them, or not? */
/* however, we don't wanna confuse people, to avoid making a mess, we will stick to RXD0, TXD0 */
bootuart = 1;
#endif
/* check if flash is programmed already, if not start bootloader anyway */
if(pgm_read_byte_near(0x0000) != 0xFF) {
#ifdef __AVR_ATmega128__
/* no UART was selected, start application */
if(!bootuart) {
app_start();
}
#else
/* check if bootloader pin is set low */
/* we don't start this part neither for the m8, nor m168 */
//if(bit_is_set(BL_PIN, BL)) {
// app_start();
// }
#endif
}
#ifdef __AVR_ATmega128__
/* no bootuart was selected, default to uart 0 */
if(!bootuart) {
bootuart = 1;
}
#endif
/* initialize UART(s) depending on CPU defined */
#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__)
if(bootuart == 1) {
UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
UCSR0A = 0x00;
UCSR0C = 0x06;
UCSR0B = _BV(TXEN0)|_BV(RXEN0);
}
if(bootuart == 2) {
UBRR1L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
UBRR1H = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
UCSR1A = 0x00;
UCSR1C = 0x06;
UCSR1B = _BV(TXEN1)|_BV(RXEN1);
}
#elif defined __AVR_ATmega163__
UBRR = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
UBRRHI = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
UCSRA = 0x00;
UCSRB = _BV(TXEN)|_BV(RXEN);
#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
#ifdef DOUBLE_SPEED
UCSR0A = (1<<U2X0); //Double speed mode USART0
UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*8L)-1);
UBRR0H = (F_CPU/(BAUD_RATE*8L)-1) >> 8;
#else
UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
#endif
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);
#elif defined __AVR_ATmega8__
/* m8 */
UBRRH = (((F_CPU/BAUD_RATE)/16)-1)>>8; // set baud rate
UBRRL = (((F_CPU/BAUD_RATE)/16)-1);
UCSRB = (1<<RXEN)|(1<<TXEN); // enable Rx & Tx
UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0); // config USART; 8N1
#else
/* m16,m32,m169,m8515,m8535 */
UBRRL = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
UBRRH = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
UCSRA = 0x00;
UCSRC = 0x06;
UCSRB = _BV(TXEN)|_BV(RXEN);
#endif
#if defined __AVR_ATmega1280__
/* Enable internal pull-up resistor on pin D0 (RX), in order
to supress line noise that prevents the bootloader from
timing out (DAM: 20070509) */
/* feature added to the Arduino Mega --DC: 080930 */
DDRE &= ~_BV(PINE0);
PORTE |= _BV(PINE0);
#endif
/* set LED pin as output */
LED_DDR |= _BV(LED);
/* flash onboard LED to signal entering of bootloader */
#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__)
// 4x for UART0, 5x for UART1
flash_led(NUM_LED_FLASHES + bootuart);
#else
flash_led(NUM_LED_FLASHES);
#endif
/* 20050803: by DojoCorp, this is one of the parts provoking the
system to stop listening, cancelled from the original */
//putch('\0');
/* 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();
}
/* P: Enter programming mode */
/* R: Erase device, don't care as we will erase one page at a time anyway. */
else if(ch=='P' || ch=='R') {
nothing_response();
}
/* Leave programming mode */
else if(ch=='Q') {
nothing_response();
#ifdef WATCHDOG_MODS
// autoreset via watchdog (sneaky!)
WDTCSR = _BV(WDE);
while (1); // 16 ms
#endif
}
/* 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') {
if (getch() == 0x30) {
getch();
ch = getch();
getch();
if (ch == 0) {
byte_response(SIG1);
} else if (ch == 1) {
byte_response(SIG2);
} else {
byte_response(SIG3);
}
} else {
getNch(3);
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 (w=0;w<length.word;w++) {
buff[w] = getch(); // Store data in buffer, can't keep up with serial data stream whilst programming pages
}
if (getch() == ' ') {
if (flags.eeprom) { //Write to EEPROM one byte at a time
address.word <<= 1;
for(w=0;w<length.word;w++) {
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
while(EECR & (1<<EEPE));
EEAR = (uint16_t)(void *)address.word;
EEDR = buff[w];
EECR |= (1<<EEMPE);
EECR |= (1<<EEPE);
#else
eeprom_write_byte((void *)address.word,buff[w]);
#endif
address.word++;
}
}
else { //Write to FLASH one page at a time
if (address.byte[1]>127) address_high = 0x01; //Only possible with m128, m256 will need 3rd address byte. FIXME
else address_high = 0x00;
#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__)
RAMPZ = address_high;
#endif
address.word = address.word << 1; //address * 2 -> byte location
/* if ((length.byte[0] & 0x01) == 0x01) length.word++; //Even up an odd number of bytes */
if ((length.byte[0] & 0x01)) length.word++; //Even up an odd number of bytes
cli(); //Disable interrupts, just to be sure
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega1281__)
while(bit_is_set(EECR,EEPE)); //Wait for previous EEPROM writes to complete
#else
while(bit_is_set(EECR,EEWE)); //Wait for previous EEPROM writes to complete
#endif
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"
#ifdef __AVR_ATmega163__
".word 0xFFFF \n\t"
"nop \n\t"
#endif
"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"
#ifdef __AVR_ATmega163__
".word 0xFFFF \n\t"
"nop \n\t"
#endif
"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"
#ifdef __AVR_ATmega163__
"andi r30,0x80 \n\t" // m163 requires Z6:Z1 to be zero during page write
#endif
"ldi r16,0x05 \n\t" //Write page pointed to by Z
"sts %0,r16 \n\t"
"spm \n\t"
#ifdef __AVR_ATmega163__
".word 0xFFFF \n\t"
"nop \n\t"
"ori r30,0x7E \n\t" // recover Z6:Z1 state after page write (had to be zero during write)
#endif
"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"
#ifdef __AVR_ATmega163__
".word 0xFFFF \n\t"
"nop \n\t"
#endif
"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
#if defined __AVR_ATmega168__ || __AVR_ATmega328P__ || __AVR_ATmega128__ || __AVR_ATmega1280__ || __AVR_ATmega1281__
: "=m" (SPMCSR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31"
#else
: "=m" (SPMCR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31"
#endif
);
/* Should really add a wait for RWW section to be enabled, don't actually need it since we never */
/* exit the bootloader without a power cycle anyhow */
}
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 defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__)
if (address.word>0x7FFF) flags.rampz = 1; // No go with m256, FIXME
else flags.rampz = 0;
#endif
address.word = address.word << 1; // address * 2 -> byte location
if (getch() == 'E') flags.eeprom = 1;
else flags.eeprom = 0;
if (getch() == ' ') { // Command terminator
putch(0x14);
for (w=0;w < length.word;w++) { // Can handle odd and even lengths okay
if (flags.eeprom) { // Byte access EEPROM read
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
while(EECR & (1<<EEPE));
EEAR = (uint16_t)(void *)address.word;
EECR |= (1<<EERE);
putch(EEDR);
#else
putch(eeprom_read_byte((void *)address.word));
#endif
address.word++;
}
else {
if (!flags.rampz) putch(pgm_read_byte_near(address.word));
#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__)
else putch(pgm_read_byte_far(address.word + 0x10000));
// Hmmmm, yuck FIXME when m256 arrvies
#endif
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);
}
#if defined MONITOR
/* here come the extended monitor commands by Erik Lins */
/* check for three times exclamation mark pressed */
else if(ch=='!') {
ch = getch();
if(ch=='!') {
ch = getch();
if(ch=='!') {
PGM_P welcome = "";
#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__)
uint16_t extaddr;
#endif
uint8_t addrl, addrh;
#ifdef CRUMB128
welcome = "ATmegaBOOT / Crumb128 - (C) J.P.Kyle, E.Lins - 050815\n\r";
#elif defined PROBOMEGA128
welcome = "ATmegaBOOT / PROBOmega128 - (C) J.P.Kyle, E.Lins - 050815\n\r";
#elif defined SAVVY128
welcome = "ATmegaBOOT / Savvy128 - (C) J.P.Kyle, E.Lins - 050815\n\r";
#elif defined __AVR_ATmega1280__
welcome = "ATmegaBOOT / Arduino Mega - (C) Arduino LLC - 090930\n\r";
#endif
/* turn on LED */
LED_DDR |= _BV(LED);
LED_PORT &= ~_BV(LED);
/* print a welcome message and command overview */
for(i=0; welcome[i] != '\0'; ++i) {
putch(welcome[i]);
}
/* test for valid commands */
for(;;) {
putch('\n');
putch('\r');
putch(':');
putch(' ');
ch = getch();
putch(ch);
/* toggle LED */
if(ch == 't') {
if(bit_is_set(LED_PIN,LED)) {
LED_PORT &= ~_BV(LED);
putch('1');
} else {
LED_PORT |= _BV(LED);
putch('0');
}
}
/* read byte from address */
else if(ch == 'r') {
ch = getch(); putch(ch);
addrh = gethex();
addrl = gethex();
putch('=');
ch = *(uint8_t *)((addrh << 8) + addrl);
puthex(ch);
}
/* write a byte to address */
else if(ch == 'w') {
ch = getch(); putch(ch);
addrh = gethex();
addrl = gethex();
ch = getch(); putch(ch);
ch = gethex();
*(uint8_t *)((addrh << 8) + addrl) = ch;
}
/* read from uart and echo back */
else if(ch == 'u') {
for(;;) {
putch(getch());
}
}
#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__)
/* external bus loop */
else if(ch == 'b') {
putch('b');
putch('u');
putch('s');
MCUCR = 0x80;
XMCRA = 0;
XMCRB = 0;
extaddr = 0x1100;
for(;;) {
ch = *(volatile uint8_t *)extaddr;
if(++extaddr == 0) {
extaddr = 0x1100;
}
}
}
#endif
else if(ch == 'j') {
app_start();
}
} /* end of monitor functions */
}
}
}
/* end of monitor */
#endif
else if (++error_count == MAX_ERROR_COUNT) {
app_start();
}
} /* end of forever loop */
}
char gethexnib(void) {
char a;
a = getch(); putch(a);
if(a >= 'a') {
return (a - 'a' + 0x0a);
} else if(a >= '0') {
return(a - '0');
}
return a;
}
char gethex(void) {
return (gethexnib() << 4) + gethexnib();
}
void puthex(char ch) {
char ah;
ah = ch >> 4;
if(ah >= 0x0a) {
ah = ah - 0x0a + 'a';
} else {
ah += '0';
}
ch &= 0x0f;
if(ch >= 0x0a) {
ch = ch - 0x0a + 'a';
} else {
ch += '0';
}
putch(ah);
putch(ch);
}
void putch(char ch)
{
#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__)
if(bootuart == 1) {
while (!(UCSR0A & _BV(UDRE0)));
UDR0 = ch;
}
else if (bootuart == 2) {
while (!(UCSR1A & _BV(UDRE1)));
UDR1 = ch;
}
#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
while (!(UCSR0A & _BV(UDRE0)));
UDR0 = ch;
#else
/* m8,16,32,169,8515,8535,163 */
while (!(UCSRA & _BV(UDRE)));
UDR = ch;
#endif
}
char getch(void)
{
#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__)
uint32_t count = 0;
if(bootuart == 1) {
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();
}
return UDR0;
}
else if(bootuart == 2) {
while(!(UCSR1A & _BV(RXC1))) {
/* 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();
}
return UDR1;
}
return 0;
#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
uint32_t count = 0;
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();
}
return UDR0;
#else
/* m8,16,32,169,8515,8535,163 */
uint32_t count = 0;
while(!(UCSRA & _BV(RXC))){
/* 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();
}
return UDR;
#endif
}
void getNch(uint8_t count)
{
while(count--) {
#if defined(__AVR_ATmega128__) || defined(__AVR_ATmega1280__)
if(bootuart == 1) {
while(!(UCSR0A & _BV(RXC0)));
UDR0;
}
else if(bootuart == 2) {
while(!(UCSR1A & _BV(RXC1)));
UDR1;
}
#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
getch();
#else
/* m8,16,32,169,8515,8535,163 */
/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
//while(!(UCSRA & _BV(RXC)));
//UDR;
getch(); // need to handle time out
#endif
}
}
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();
}
}
void flash_led(uint8_t count)
{
while (count--) {
LED_PORT |= _BV(LED);
_delay_ms(100);
LED_PORT &= ~_BV(LED);
_delay_ms(100);
}
}
/* end of file ATmegaBOOT.c */

View File

@ -1,245 +0,0 @@
:020000021000EC
:10F000000C9472F80C9492F80C9492F80C9492F878
:10F010000C9492F80C9492F80C9492F80C9492F848
:10F020000C9492F80C9492F80C9492F80C9492F838
:10F030000C9492F80C9492F80C9492F80C9492F828
:10F040000C9492F80C9492F80C9492F80C9492F818
:10F050000C9492F80C9492F80C9492F80C9492F808
:10F060000C9492F80C9492F80C9492F80C9492F8F8
:10F070000C9492F80C9492F80C9492F80C9492F8E8
:10F080000C9492F80C9492F80C9492F80C9492F8D8
:10F090000C9492F80C9492F80C9492F80C9492F8C8
:10F0A0000C9492F80C9492F80C9492F80C9492F8B8
:10F0B0000C9492F80C9492F80C9492F80C9492F8A8
:10F0C0000C9492F80C9492F80C9492F80C9492F898
:10F0D0000C9492F80C9492F80C9492F80C9492F888
:10F0E0000C9492F811241FBECFEFD1E2DEBFCDBF4A
:10F0F00012E0A0E0B2E0EEEDFEEF01E00BBF02C0D7
:10F1000007900D92A833B107D9F71BBE13E0A8E30F
:10F11000B2E001C01D92A334B107E1F70E9412FAD8
:10F120000C946DFF0C9400F8982F959595959595F6
:10F130009595905D8F708A301CF1282F295A809107
:10F140003802813019F0823071F008958091C0004A
:10F1500085FFFCCF9093C6008091C00085FFFCCF57
:10F160002093C60008958091C80085FFFCCF90933E
:10F17000CE008091C80085FFFCCF2093CE0008957B
:10F18000282F205DDCCF982F80913802813019F034
:10F19000823041F008958091C00085FFFCCF9093AC
:10F1A000C60008958091C80085FFFCCF9093CE00E3
:10F1B0000895EF92FF920F931F9380913802813050
:10F1C00069F1823031F080E01F910F91FF90EF9054
:10F1D0000895EE24FF2487018091C80087FD17C0A1
:10F1E0000894E11CF11C011D111D81E4E81682E464
:10F1F000F8068FE0080780E0180770F3E0913A0204
:10F20000F0913B0209958091C80087FFE9CF80917A
:10F21000CE001F910F91FF90EF900895EE24FF24F0
:10F2200087018091C00087FD17C00894E11CF11C84
:10F23000011D111D81E4E81682E4F8068FE008073D
:10F2400080E0180770F3E0913A02F0913B020995D3
:10F250008091C00087FFE9CF8091C6001F910F9178
:10F26000FF90EF9008950E94D9F8982F809138026E
:10F27000813049F0823091F091366CF490330CF08B
:10F280009053892F08958091C00085FFFCCF909303
:10F29000C60091369CF39755892F08958091C80038
:10F2A00085FFFCCF9093CE00E7CF1F930E9433F9E8
:10F2B000182F0E9433F91295107F810F1F91089526
:10F2C000982F20913802992339F0213031F02230E3
:10F2D00061F091509923C9F708958091C00087FF8C
:10F2E000FCCF8091C6009150F5CF8091C80087FF78
:10F2F000FCCF8091CE009150EDCF1F93182F0E942C
:10F30000D9F8803249F0809139028F5F80933902B9
:10F31000853091F11F910895809138028130B9F0C4
:10F320008230C1F78091C80085FFFCCF84E18093D3
:10F33000CE008091C80085FFFCCF1093CE00809155
:10F34000C80085FFFCCF80E18093CE00E3CF8091A1
:10F35000C00085FFFCCF84E18093C6008091C0008F
:10F3600085FFFCCF1093C6008091C00085FFFCCFC5
:10F3700080E18093C600CECFE0913A02F0913B024B
:10F3800009951F9108950E94D9F8803241F080912B
:10F3900039028F5F80933902853029F10895809179
:10F3A0003802813089F08230C9F78091C80085FF2A
:10F3B000FCCF84E18093CE008091C80085FFFCCF14
:10F3C00080E18093CE0008958091C00085FFFCCF3E
:10F3D00084E18093C6008091C00085FFFCCF80E16E
:10F3E0008093C6000895E0913A02F0913B0209959E
:10F3F000089540E951E08823A1F02F9A28EE33E0E8
:10F40000FA013197F1F721503040D1F72F9828EECB
:10F4100033E0FA013197F1F721503040D1F78150B4
:10F4200061F708952F923F924F925F926F927F9271
:10F430008F929F92AF92BF92CF92DF92EF92FF9204
:10F440000F931F93CF93DF93000081E080933802E6
:10F4500080E18093C4001092C5001092C00086E045
:10F460008093C20088E18093C1006898709A279ABF
:10F4700081E00E94F9F9E4E1EE2E7EE1D72E67E902
:10F48000C62E53E0B52E40E1A42E9924939431E486
:10F49000832E26E5722E92E5692E80E2582E09E42D
:10F4A000402E13E5312EB0E52B2E0E94D9F8803383
:10F4B000C9F1813309F452C0803409F4C8C08134E1
:10F4C00009F4EAC0823489F1853409F4CAC0803570
:10F4D00049F1823539F1813529F1853509F4ECC0DE
:10F4E000863509F409C1843609F428C1843709F442
:10F4F000ABC1853709F473C2863709F4D9C08132AC
:10F5000009F4B7C2809139028F5F80933902853048
:10F5100061F6E0913A02F0913B0209950E94D9F818
:10F52000803339F60E94C3F9C0CF2091380293E1AD
:10F5300005C0223061F09923A9F391502130C9F719
:10F540008091C00087FFFCCF8091C600F4CF8091EE
:10F55000C80087FFFCCF8091CE00EDCF0E94D9F884
:10F56000803281F6809138028130D1F1823009F009
:10F570009CCF8091C80085FFFCCFE092CE008091A7
:10F58000C80085FFFCCF8092CE008091C80085FF27
:10F59000FCCF7092CE008091C80085FFFCCF6092B6
:10F5A000CE008091C80085FFFCCF5092CE008091A4
:10F5B000C80085FFFCCF4092CE008091C80085FF37
:10F5C000FCCF3092CE008091C80085FFFCCF209206
:10F5D000CE008091C80085FFFCCFA092CE0065CF01
:10F5E0008091C00085FFFCCFE092C6008091C000F2
:10F5F00085FFFCCF8092C6008091C00085FFFCCFC4
:10F600007092C6008091C00085FFFCCF6092C6005A
:10F610008091C00085FFFCCF5092C6008091C00051
:10F6200085FFFCCF4092C6008091C00085FFFCCFD3
:10F630003092C6008091C00085FFFCCF2092C600AA
:10F640008091C00085FFFCCFA092C6002ECF0E9403
:10F65000D9F8863808F466CF0E94D9F80E94C3F919
:10F6600024CF2091380294E0213041F0223069F01B
:10F67000992309F457CF91502130C1F78091C000F0
:10F6800087FFFCCF8091C600F3CF8091C80087FF31
:10F69000FCCF8091CE00ECCF0E94D9F8803841F1A8
:10F6A000813809F447C0823809F4CAC08839E1F0CA
:10F6B00080E00E947DF9F9CE0E94D9F880933C0247
:10F6C0000E94D9F880933D020E94C3F9EECE0E94B9
:10F6D000D9F80E94D9F8182F0E94D9F8112309F4FB
:10F6E0007EC2113009F40AC283E00E947DF9DDCEAA
:10F6F00082E00E947DF9D9CE0E94D9F8803339F397
:10F700002091380292E0213039F0223061F09923C3
:10F7100079F291502130C9F78091C00087FFFCCF6A
:10F720008091C600F4CF8091C80087FFFCCF809104
:10F73000CE00EDCF81E00E947DF9B7CE0E94D9F8CE
:10F7400080933F030E94D9F880933E038091420347
:10F750008E7F809342030E94D9F8853409F4B3C1A7
:10F7600080913E0390913F03892B89F000E010E0E7
:10F770000E94D9F8F801E25CFD4F80830F5F1F4FB4
:10F7800080913E0390913F030817190788F30E9468
:10F79000D9F8803209F0B6CE8091420380FFB2C121
:10F7A00040913C0250913D02440F551F50933D0241
:10F7B00040933C0260913E0370913F0361157105D7
:10F7C000F1F080E090E09A01280F391FFC01E25C23
:10F7D000FD4FE081F999FECF1FBA32BD21BDE0BDDA
:10F7E0000FB6F894FA9AF99A0FBE01968617970702
:10F7F00050F3460F571F50933D0240933C028091B7
:10F800003802813081F0823009F04FCE8091C800FB
:10F8100085FFFCCFE092CE008091C80085FFFCCF31
:10F82000A092CE0042CE8091C00085FFFCCFE09236
:10F83000C6008091C00085FFFCCFA092C60035CEE7
:10F8400080E10E947DF931CE0E94D9F880933F0378
:10F850000E94D9F880933E0320913C0230913D02F2
:10F8600037FD46C1809142038D7F80934203220F72
:10F87000331F30933D0220933C020E94D9F8853417
:10F8800009F430C1809142038E7F809342030E942D
:10F89000D9F8803209F009CE60913802613009F45C
:10F8A0006FC0623009F473C000913E0310913F03B2
:10F8B0000115110509F440C080914203782F717041
:10F8C000F82EF69481E0F82240913C0250913D02DE
:10F8D00020E030E013C0FF2009F060C0FA019491ED
:10F8E000613009F43BC0623009F441C0CA0101969D
:10F8F0002F5F3F4FAC0120173107D0F4772359F326
:10F90000F999FECF52BD41BDF89A90B56130F9F03A
:10F91000623061F78091C80085FFFCCF9093CE00E4
:10F92000CA0101962F5F3F4FAC012017310730F31A
:10F9300090933D0280933C02613009F4CAC062306A
:10F9400009F0B3CD8091C80085FFFCCF46CE8091F1
:10F95000C00085FFFCCF9093C600C8CF8091C00047
:10F9600085FDF9CF8091C00085FFF8CFF4CF80915D
:10F97000C80085FDD3CF8091C80085FFF8CFCECFDA
:10F980008091C00085FFFCCFE092C6008DCF8091B2
:10F99000C80085FFFCCFE092CE0086CFCA01A0E070
:10F9A000B0E080509040AF4FBF4FABBFFC0197918C
:10F9B000613061F0623009F099CF8091C80085FD17
:10F9C000ADCF8091C80085FFF8CFA8CF8091C0004F
:10F9D00085FDC1CF8091C00085FFF8CFBCCF0E94CC
:10F9E000D9F8803209F08ECD80913802813011F142
:10F9F000823009F05ACD8091C80085FFFCCFE0929B
:10FA0000CE008091C80085FFFCCFD092CE008091BF
:10FA1000C80085FFFCCFC092CE008091C80085FF52
:10FA2000FCCFB092CE008091C80085FFFCCFA092A1
:10FA3000CE003BCD8091C00085FFFCCFE092C60098
:10FA40008091C00085FFFCCFD092C6008091C0009D
:10FA500085FFFCCFC092C6008091C00085FFFCCF1F
:10FA6000B092C6008091C00085FFFCCFA092C60076
:10FA70001CCD0E94D9F8813209F017CD0E94D9F827
:10FA8000813209F012CD279A2F98109240032091CD
:10FA90003802E1E491E00EC0223009F4A4C0909352
:10FAA0004003E92FF0E0E050FE4FE0819F5FEE233E
:10FAB00009F4A0C0213081F78091C00085FFFCCF00
:10FAC000E093C600ECCF80914203816080934203B3
:10FAD00047CE8091C00085FDB7CD8091C00085FFE5
:10FAE000F8CFB2CD80914203816080934203CFCEA4
:10FAF00080914203826080934203B9CE87E90E94DD
:10FB00007DF9D3CC80913D028823880F880B892111
:10FB1000809341038BBF80913C0290913D02880FFE
:10FB2000991F90933D0280933C0280913E0380FF99
:10FB300009C080913E0390913F03019690933F034B
:10FB400080933E03F894F999FECF1127E0913C028F
:10FB5000F0913D02CEE3D2E080913E0390913F03CD
:10FB6000103091F40091570001700130D9F303E097
:10FB700000935700E8950091570001700130D9F3C8
:10FB800001E100935700E895099019900091570002
:10FB900001700130D9F301E000935700E895139507
:10FBA000103898F011270091570001700130D9F3F7
:10FBB00005E000935700E89500915700017001306F
:10FBC000D9F301E100935700E8953296029709F0C6
:10FBD000C7CF103011F00296E5CF112410CE8EE180
:10FBE0000E947DF962CC8091C80085FFFCCFE09334
:10FBF000CE0055CF7AE0B72E6DE0A62E5AE3952EB3
:10FC000040E2842E3DE3732E90E3692E81E3582E6B
:10FC1000213009F442C0223009F45FC00E94D9F8B3
:10FC2000982F20913802213089F1223009F44EC0FA
:10FC3000943709F46BC0923709F405C1973709F47A
:10FC40007BC0953799F0923609F4BDC09A3601F71A
:10FC5000E0913A02F0913B02099520913802D8CF09
:10FC60008091C00085FFFCCF9093C6000E94D9F818
:10FC7000982F80913802813099F38230B9F78091C2
:10FC8000C80085FFFCCF9093CE00F0CF8091C000DC
:10FC900085FFFCCF9093C600CBCF8091C00085FF3D
:10FCA000FCCFB092C6008091C00085FFFCCFA0922F
:10FCB000C6008091C00085FFFCCF9092C600809165
:10FCC000C00085FFFCCF8092C600A8CF8091C800FD
:10FCD00085FFFCCF9093CE00ABCF8091C80085FF0D
:10FCE000FCCFB092CE008091C80085FFFCCFA092DF
:10FCF000CE008091C80085FFFCCF9092CE0080910D
:10FD0000C80085FFFCCF8092CE0088CF1F9947C0E6
:10FD10002F9A213051F0223009F07ACF8091C8001B
:10FD200085FFFCCF6092CE0073CF8091C00085FF2D
:10FD3000FCCF6092C6006CCF0E94D9F8982F8091BA
:10FD400038028130F1F0823009F4ABC00E9455F9DD
:10FD5000082F0E9455F9182F0E94D9F8982F8091EA
:10FD600038028130A9F0823009F4A2C00E9455F90E
:10FD7000D02ECC24F601E10FF11D808320913802B2
:10FD800047CF8091C00085FFFCCF9093C600DECFA7
:10FD90008091C00085FFFCCF9093C600E7CF2F98DD
:10FDA000213051F0223009F033CF8091C80085FF17
:10FDB000FCCF5092CE002CCF8091C00085FFFCCFAD
:10FDC0005092C60025CF213041F1223081F080E8E9
:10FDD00085BF109274001092750080E091E1FC01E3
:10FDE000819180E091E13097D1F3CF01F8CF8091FC
:10FDF000C80085FFFCCF82E68093CE008091C800CA
:10FE000085FFFCCF85E78093CE008091C80085FFF9
:10FE1000FCCF83E78093CE00DACF8091C00085FFCE
:10FE2000FCCF82E68093C6008091C00085FFFCCFA6
:10FE300085E78093C6008091C00085FFFCCF83E7F3
:10FE40008093C600C4CF0E94D9F8982F80913802C1
:10FE50008130C9F08230D1F10E9455F9182F0E94EB
:10FE600055F9982F809138028130A1F0823039F114
:10FE7000F12EEE24F701E90FF11D80810E9494F824
:10FE800020913802C5CE8091C00085FFFCCF9093B1
:10FE9000C600E2CF8091C00085FFFCCF7092C60003
:10FEA000E7CF8091C80085FFFCCF9093CE004ECF66
:10FEB0008091C80085FFFCCF9093CE0057CF8091F2
:10FEC000C80085FFFCCF7092CE00D2CF8091C800D1
:0EFED00085FFFCCF9093CE00BFCFF894FFCFFC
:10FEDE0041546D656761424F4F54202F204172642B
:10FEEE0075696E6F204D656761202D20284329208E
:10FEFE0041726475696E6F204C4C43202D20303951
:08FF0E00303933300A0D008088
:040000031000F000F9
:00000001FF

View File

@ -1,125 +0,0 @@
:107800000C94343C0C94513C0C94513C0C94513CE1
:107810000C94513C0C94513C0C94513C0C94513CB4
:107820000C94513C0C94513C0C94513C0C94513CA4
:107830000C94513C0C94513C0C94513C0C94513C94
:107840000C94513C0C94513C0C94513C0C94513C84
:107850000C94513C0C94513C0C94513C0C94513C74
:107860000C94513C0C94513C11241FBECFEFD8E036
:10787000DEBFCDBF11E0A0E0B1E0ECE9FFE702C060
:1078800005900D92A230B107D9F712E0A2E0B1E065
:1078900001C01D92AD30B107E1F70E942D3D0C945F
:1078A000CC3F0C94003C982F959595959595959582
:1078B000905D8F708A307CF0282F295A8091C0000B
:1078C00085FFFCCF9093C6008091C00085FFFCCF60
:1078D0002093C6000895282F205DF0CF982F809127
:1078E000C00085FFFCCF9093C6000895EF92FF92F1
:1078F0000F931F93EE24FF2487018091C00087FD22
:1079000017C00894E11CF11C011D111D81E4E8164B
:1079100082E4F8068FE0080780E0180770F3E09132
:107920000401F091050109958091C00087FFE9CF1E
:107930008091C6001F910F91FF90EF9008950E94D3
:10794000763C982F8091C00085FFFCCF9093C600B5
:1079500091362CF490330CF09053892F089597555D
:10796000892F08951F930E949F3C182F0E949F3CCF
:107970001295107F810F1F9108951F93182F882350
:1079800021F00E94763C1150E1F71F9108951F935A
:10799000182F0E94763C803249F0809103018F5F5E
:1079A000809303018530C1F01F9108958091C0003C
:1079B00085FFFCCF84E18093C6008091C00085FFE5
:1079C000FCCF1093C6008091C00085FFFCCF80E102
:1079D0008093C6001F910895E0910401F091050184
:1079E00009951F9108950E94763C803241F0809164
:1079F00003018F5F80930301853081F008958091AA
:107A0000C00085FFFCCF84E18093C6008091C00058
:107A100085FFFCCF80E18093C6000895E0910401CA
:107A2000F09105010995089540E951E08823A1F0FE
:107A30002D9A28EE33E0FA013197F1F721503040CA
:107A4000D1F72D9828EE33E0FA013197F1F7215064
:107A50003040D1F7815061F708953F924F925F9285
:107A60006F927F928F929F92AF92BF92CF92DF924E
:107A7000EF92FF920F931F93CF93DF93000080E16B
:107A80008093C4001092C50088E18093C10086E015
:107A90008093C2005098589A259A81E00E94143D24
:107AA00024E1F22E9EE1E92E85E9D82E0FE0C02ECA
:107AB00010E1B12EAA24A394B1E49B2EA6E58A2E50
:107AC000F2E57F2EE0E26E2E79E4572E63E5462E36
:107AD00050E5352E0E94763C8033B1F18133B9F107
:107AE000803409F46FC0813409F476C0823409F41B
:107AF00085C0853409F488C0803531F1823521F1A3
:107B0000813511F1853509F485C0863509F48DC0BC
:107B1000843609F496C0843709F403C1853709F423
:107B200072C1863709F466C0809103018F5F80932C
:107B30000301853079F6E0910401F0910501099582
:107B40000E94763C803351F60E94F33CC3CF0E94E2
:107B5000763C803249F78091C00085FFFCCFF092DF
:107B6000C6008091C00085FFFCCF9092C600809136
:107B7000C00085FFFCCF8092C6008091C00085FFC9
:107B8000FCCF7092C6008091C00085FFFCCF609250
:107B9000C6008091C00085FFFCCF5092C600809146
:107BA000C00085FFFCCF4092C6008091C00085FFD9
:107BB000FCCF3092C6008091C00085FFFCCFB09210
:107BC000C60088CF0E94763C863808F4BDCF0E945C
:107BD000763C0E94F33C7ECF0E94763C803809F4CC
:107BE0009CC0813809F40BC1823809F43CC1883942
:107BF00009F48FC080E00E94C73C6CCF84E10E94F2
:107C0000BD3C0E94F33C66CF85E00E94BD3C0E94D3
:107C1000F33C60CF0E94763C809306010E94763C44
:107C2000809307010E94F33C55CF0E94763C80333D
:107C300009F41DC183E00E94BD3C80E00E94C73C66
:107C400049CF0E94763C809309020E94763C809343
:107C5000080280910C028E7F80930C020E94763C79
:107C6000853409F415C18091080290910902892B8D
:107C700089F000E010E00E94763CF801E85FFE4FDA
:107C800080830F5F1F4F80910802909109020817AF
:107C9000190788F30E94763C803209F045CF809125
:107CA0000C0280FF01C16091060170910701660F0F
:107CB000771F7093070160930601A0910802B091AD
:107CC00009021097C9F0E8E0F1E09B01AD014E0F09
:107CD0005F1FF999FECF32BD21BD819180BDFA9A17
:107CE000F99A2F5F3F4FE417F50799F76A0F7B1F4B
:107CF00070930701609306018091C00085FFFCCF5F
:107D0000F092C6008091C00085FFFCCFB092C60003
:107D1000E1CE83E00E94C73CDDCE82E00E94C73CFA
:107D2000D9CE0E94763C809309020E94763C8093D3
:107D300008028091060190910701880F991F909386
:107D40000701809306010E94763C853409F4A6C0A1
:107D500080910C028E7F80930C020E94763C8032D0
:107D600009F0B8CE8091C00085FFFCCFF092C6002C
:107D7000609108027091090261157105B9F140E046
:107D800050E080910C02A82FA170B82FB27011C0E2
:107D9000BB2309F45CC0E0910601F0910701319624
:107DA000F0930701E09306014F5F5F4F46175707B7
:107DB000E8F4AA2369F3F999FECF209106013091E6
:107DC000070132BD21BDF89A90B58091C00085FFB2
:107DD000FCCF9093C6002F5F3F4F30930701209355
:107DE00006014F5F5F4F4617570718F38091C00099
:107DF00085FDE5CE8091C00085FFF8CFE0CE81E023
:107E00000E94C73C67CE0E94763C803209F08CCE3F
:107E10008091C00085FFFCCFF092C6008091C00029
:107E200085FFFCCFE092C6008091C00085FFFCCFAB
:107E3000D092C6008091C00085FFFCCFC092C600E2
:107E40008091C00085FFFCCFB092C60043CEE09188
:107E50000601F091070194918091C00085FFFCCF4D
:107E60009093C6009CCF80E10E94C73C33CE0E9415
:107E7000763C0E94763C182F0E94763C112309F430
:107E800083C0113009F484C08FE00E94C73C22CE29
:107E900080910C02816080930C02E5CE80910C02EF
:107EA000816080930C0259CF809107018823880F4D
:107EB000880B8A2180930B02809106019091070123
:107EC000880F991F90930701809306018091080203
:107ED00080FF09C080910802909109020196909359
:107EE000090280930802F894F999FECF1127E091D6
:107EF0000601F0910701C8E0D1E08091080290915D
:107F00000902103091F40091570001700130D9F34B
:107F100003E000935700E89500915700017001308D
:107F2000D9F301E100935700E89509901990009169
:107F3000570001700130D9F301E000935700E89534
:107F40001395103498F011270091570001700130FB
:107F5000D9F305E000935700E895009157000170B0
:107F60000130D9F301E100935700E895329602976A
:107F700009F0C7CF103011F00296E5CF112480919F
:107F8000C00085FFB9CEBCCE8EE10E94C73CA2CD19
:0C7F900085E90E94C73C9ECDF894FFCF0D
:027F9C00800063
:040000030000780081
:00000001FF

View File

@ -1,124 +0,0 @@
:107800000C94343C0C94513C0C94513C0C94513CE1
:107810000C94513C0C94513C0C94513C0C94513CB4
:107820000C94513C0C94513C0C94513C0C94513CA4
:107830000C94513C0C94513C0C94513C0C94513C94
:107840000C94513C0C94513C0C94513C0C94513C84
:107850000C94513C0C94513C0C94513C0C94513C74
:107860000C94513C0C94513C11241FBECFEFD8E036
:10787000DEBFCDBF11E0A0E0B1E0EAE8FFE702C063
:1078800005900D92A230B107D9F712E0A2E0B1E065
:1078900001C01D92AD30B107E1F70E942D3D0C945F
:1078A000C33F0C94003C982F95959595959595958B
:1078B000905D8F708A307CF0282F295A8091C0000B
:1078C00085FFFCCF9093C6008091C00085FFFCCF60
:1078D0002093C6000895282F205DF0CF982F809127
:1078E000C00085FFFCCF9093C6000895EF92FF92F1
:1078F0000F931F93EE24FF2487018091C00087FD22
:1079000017C00894E11CF11C011D111D81E2E8164D
:1079100081EAF80687E0080780E0180770F3E09135
:107920000401F091050109958091C00087FFE9CF1E
:107930008091C6001F910F91FF90EF9008950E94D3
:10794000763C982F8091C00085FFFCCF9093C600B5
:1079500091362CF490330CF09053892F089597555D
:10796000892F08951F930E949F3C182F0E949F3CCF
:107970001295107F810F1F9108951F93182F882350
:1079800021F00E94763C1150E1F71F9108951F935A
:10799000182F0E94763C803249F0809103018F5F5E
:1079A000809303018530C1F01F9108958091C0003C
:1079B00085FFFCCF84E18093C6008091C00085FFE5
:1079C000FCCF1093C6008091C00085FFFCCF80E102
:1079D0008093C6001F910895E0910401F091050184
:1079E00009951F9108950E94763C803241F0809164
:1079F00003018F5F80930301853081F008958091AA
:107A0000C00085FFFCCF84E18093C6008091C00058
:107A100085FFFCCF80E18093C6000895E0910401CA
:107A2000F09105010995089548EC50E08823A1F0F4
:107A30002D9A28EE33E0FA013197F1F721503040CA
:107A4000D1F72D9828EE33E0FA013197F1F7215064
:107A50003040D1F7815061F708953F924F925F9285
:107A60006F927F928F929F92AF92BF92CF92DF924E
:107A7000EF92FF920F931F93CF93DF93000082E06A
:107A80008093C00080E18093C4001092C50088E11B
:107A90008093C10086E08093C2005098589A259A3E
:107AA00081E00E94143D24E1F22E9EE1E92E85E959
:107AB000D82E0FE0C02E10E1B12EAA24A394B1E479
:107AC0009B2EA6E58A2EF2E57F2EE0E26E2E79E46B
:107AD000572E63E5462E50E5352E0E94763C8033C6
:107AE000B1F18133B9F1803409F46FC0813409F404
:107AF00076C0823409F485C0853409F488C08035A5
:107B000031F1823521F1813511F1853509F485C0D6
:107B1000863509F48DC0843609F496C0843709F49B
:107B200003C1853709F472C1863709F466C08091B4
:107B300003018F5F80930301853079F6E0910401A2
:107B4000F091050109950E94763C803351F60E9420
:107B5000F33CC3CF0E94763C803249F78091C0004D
:107B600085FFFCCFF092C6008091C00085FFFCCF5E
:107B70009092C6008091C00085FFFCCF8092C60025
:107B80008091C00085FFFCCF7092C6008091C0003C
:107B900085FFFCCF6092C6008091C00085FFFCCFBE
:107BA0005092C6008091C00085FFFCCF4092C60075
:107BB0008091C00085FFFCCF3092C6008091C0004C
:107BC00085FFFCCFB092C60088CF0E94763C8638F5
:107BD00008F4BDCF0E94763C0E94F33C7ECF0E9409
:107BE000763C803809F49CC0813809F40BC1823896
:107BF00009F430C1883909F48FC080E00E94C73C85
:107C00006CCF84E10E94BD3C0E94F33C66CF85E0CE
:107C10000E94BD3C0E94F33C60CF0E94763C809362
:107C200006010E94763C809307010E94F33C55CFE9
:107C30000E94763C803309F411C183E00E94BD3C70
:107C400080E00E94C73C49CF0E94763C80930902A5
:107C50000E94763C8093080280910C028E7F809374
:107C60000C020E94763C853409F409C18091080217
:107C700090910902892B89F000E010E00E94763C87
:107C8000F801E85FFE4F80830F5F1F4F809108026D
:107C9000909109020817190788F30E94763C8032F8
:107CA00009F045CF80910C0280FFF5C0609106017C
:107CB00070910701660F771F7093070160930601AB
:107CC000A0910802B09109021097C9F0E8E0F1E034
:107CD0009B01AD014E0F5F1FF999FECF32BD21BD53
:107CE000819180BDFA9AF99A2F5F3F4FE417F5070B
:107CF00099F76A0F7B1F70930701609306018091CB
:107D0000C00085FFFCCFF092C6008091C00085FFC7
:107D1000FCCFB092C600E1CE83E00E94C73CDDCE2E
:107D200082E00E94C73CD9CE0E94763C8093090233
:107D30000E94763C80930802809106019091070191
:107D4000880F991F90930701809306010E94763C4B
:107D5000853409F49AC080910C028E7F80930C02C6
:107D60000E94763C803209F0B8CE8091C00085FF39
:107D7000FCCFF092C600A0910802B09109021097C2
:107D8000C1F180910C02082F0170182F1695117007
:107D9000E0910601F0910701AF014F5F5F4FBA011B
:107DA00020E030E00023B1F4112339F49491809164
:107DB000C00085FFFCCF9093C6002F5F3F4FCB01E3
:107DC0000196FA012A173B0780F4BC014F5F5F4F11
:107DD000002351F3F999FECFF2BDE1BDF89A90B5B9
:107DE0008091C00085FFFCCFE6CF709307016093C0
:107DF00006018091C00085FDE5CE8091C00085FF21
:107E0000F8CFE0CE81E00E94C73C67CE0E94763C6E
:107E1000803209F08CCE8091C00085FFFCCFF092BB
:107E2000C6008091C00085FFFCCFE092C600809123
:107E3000C00085FFFCCFD092C6008091C00085FFB6
:107E4000FCCFC092C6008091C00085FFFCCFB092ED
:107E5000C60043CE80E10E94C73C3FCE0E94763CE4
:107E60000E94763C182F0E94763C112309F483C0AF
:107E7000113009F484C08FE00E94C73C2ECE80915F
:107E80000C02816080930C02F1CE80910C02816023
:107E900080930C0265CF809107018823880F880B9F
:107EA0008A2180930B028091060190910701880F2F
:107EB000991F90930701809306018091080280FF2B
:107EC00009C08091080290910902019690930902DD
:107ED00080930802F894F999FECF1127E0910601EA
:107EE000F0910701C8E0D1E0809108029091090269
:107EF000103091F40091570001700130D9F303E084
:107F000000935700E8950091570001700130D9F3B4
:107F100001E100935700E8950990199000915700EE
:107F200001700130D9F301E000935700E8951395F3
:107F3000103498F011270091570001700130D9F3E7
:107F400005E000935700E89500915700017001305B
:107F5000D9F301E100935700E8953296029709F0B2
:107F6000C7CF103011F00296E5CF11248091C000E8
:107F700085FFC5CEC8CE8EE10E94C73CAECD85E957
:0A7F80000E94C73CAACDF894FFCF81
:027F8A00800075
:040000030000780081
:00000001FF

View File

@ -1,126 +0,0 @@
:103800000C94341C0C94511C0C94511C0C94511CA1
:103810000C94511C0C94511C0C94511C0C94511C74
:103820000C94511C0C94511C0C94511C0C94511C64
:103830000C94511C0C94511C0C94511C0C94511C54
:103840000C94511C0C94511C0C94511C0C94511C44
:103850000C94511C0C94511C0C94511C0C94511C34
:103860000C94511C0C94511C11241FBECFEFD4E0BA
:10387000DEBFCDBF11E0A0E0B1E0E4EAFFE302C0AB
:1038800005900D92A230B107D9F712E0A2E0B1E0A5
:1038900001C01D92AD30B107E1F70E94361D0C94B6
:1038A000D01F0C94001C982F9595959595959595FE
:1038B000905D8F708A307CF0282F295A8091C0004B
:1038C00085FFFCCF9093C6008091C00085FFFCCFA0
:1038D0002093C6000895282F205DF0CF982F809167
:1038E000C00085FFFCCF9093C6000895EF92FF9231
:1038F0000F931F93EE24FF2487018091C00087FD62
:1039000017C00894E11CF11C011D111D81E4E8168B
:1039100082E4F8068FE0080780E0180770F3E09172
:103920000401F091050109958091C00087FFE9CF5E
:103930008091C6001F910F91FF90EF9008950E9413
:10394000761C982F8091C00085FFFCCF9093C60015
:1039500091362CF490330CF09053892F089597559D
:10396000892F08951F930E949F1C182F0E949F1C4F
:103970001295107F810F1F910895882351F0982F81
:1039800091508091C00087FFFCCF8091C6009923A1
:10399000B9F708951F93182F0E94761C803249F0C2
:1039A000809103018F5F809303018530C1F01F91E7
:1039B00008958091C00085FFFCCF84E18093C6000C
:1039C0008091C00085FFFCCF1093C6008091C0009D
:1039D00085FFFCCF80E18093C6001F910895E091A0
:1039E0000401F091050109951F9108950E94761C2C
:1039F000803241F0809103018F5F80930301853015
:103A000081F008958091C00085FFFCCF84E1809310
:103A1000C6008091C00085FFFCCF80E18093C60086
:103A20000895E0910401F09105010995089510921F
:103A30000A028823D1F090E040E951E02D9A28EE67
:103A400033E0FA013197F1F721503040D1F72D984A
:103A500028EE33E0FA013197F1F721503040D1F7E9
:103A60009F5F981758F380930A0208953F924F92F0
:103A70005F926F927F928F929F92AF92BF92CF92FE
:103A8000DF92EF92FF920F931F93CF93DF9300008B
:103A900083E38093C4001092C50088E18093C10045
:103AA00086E08093C2005098589A259A81E00E943F
:103AB000171D44E1F42E3EE1E32E24E9D22E96E0D8
:103AC000C92E80E1B82EAA24A39401E4902E16E515
:103AD000812EB2E57B2EA0E26A2EF9E45F2EE3E5AB
:103AE0004E2E70E5372E0E94761C8033B1F1813363
:103AF00009F441C0803409F479C0813409F48CC0E0
:103B0000823471F1853409F47BC0803531F182351E
:103B100021F1813511F1853509F48DC0863509F41F
:103B20009DC0843609F4AEC0843709F41BC18537C3
:103B300009F485C1863709F47AC0809103018F5F4B
:103B400080930301853079F6E0910401F09105013D
:103B500009950E94761C803351F60E94F61CC3CF53
:103B600093E18091C00087FFFCCF8091C60099232C
:103B7000A1F39150F6CF0E94761C8032F1F680912D
:103B8000C00085FFFCCFF092C6008091C00085FF89
:103B9000FCCF9092C6008091C00085FFFCCF809240
:103BA000C6008091C00085FFFCCF7092C600809156
:103BB000C00085FFFCCF6092C6008091C00085FFE9
:103BC000FCCF5092C6008091C00085FFFCCF409290
:103BD000C6008091C00085FFFCCF3092C600809166
:103BE000C00085FFFCCFB092C6007DCF0E94761C3E
:103BF000863808F4B2CF0E94761C0E94F61C73CF60
:103C000094E08091C00087FFFCCF8091C60099238B
:103C100009F4A3CF9150F5CF0E94761C8038D1F0E3
:103C2000813861F1823809F499C0883979F080E0EF
:103C30000E94CA1C58CF0E94761C809306010E94E5
:103C4000761C809307010E94F61C4DCF83E00E94F2
:103C5000CA1C49CF82E00E94CA1C45CF0E94761C34
:103C6000803309F486C192E08091C00087FFFCCFC9
:103C70008091C6009923D9F29150F6CF81E00E943D
:103C8000CA1C31CF0E94761C809309020E94761CC8
:103C90008093080280910C028E7F80930C020E9418
:103CA000761C853429F480910C02816080930C028B
:103CB0008091080290910902892B89F000E010E0C0
:103CC0000E94761CF801E85FFE4F80830F5F1F4F54
:103CD00080910802909109020817190788F30E9441
:103CE000761C803209F029CF80910C0280FFD1C070
:103CF0004091060150910701440F551F5093070151
:103D000040930601A0910802B09109021097C9F0F2
:103D1000E8E0F1E09A01BD016E0F7F1FF999FECF37
:103D200032BD21BD819180BDFA9AF99A2F5F3F4F34
:103D3000E617F70799F74A0F5B1F50930701409367
:103D400006018091C00085FFFCCFF092C6008091F3
:103D5000C00085FFFCCFB092C600C5CE80E10E94B6
:103D6000CA1CC1CE0E94761C809309020E94761C58
:103D7000809308028091060190910701880F991F96
:103D800090930701809306010E94761C853409F404
:103D90007AC080910C028E7F80930C020E94761C68
:103DA000803209F0A0CE8091C00085FFFCCFF09258
:103DB000C600A0910802B09109021097B9F1809154
:103DC0000C02182F1170082F0270E0910601F0917B
:103DD00007019F012F5F3F4FB90140E050E01123E1
:103DE000B1F4002339F494918091C00085FFFCCF99
:103DF0009093C6004F5F5F4FCB010196F9014A17C0
:103E00005B0780F4BC012F5F3F4F112351F3F999F9
:103E1000FECFF2BDE1BDF89A90B58091C00085FF5C
:103E2000FCCFE6CF70930701609306018091C0003C
:103E300085FDD9CE8091C00085FFF8CFD4CE0E94F9
:103E4000761C803209F079CE8091C00085FFFCCFCE
:103E5000F092C6008091C00085FFFCCFE092C600C2
:103E60008091C00085FFFCCFD092C6008091C00039
:103E700085FFFCCFC092C6008091C00085FFFCCFBB
:103E8000B092C60030CE80910C02816080930C020B
:103E900085CF809107018823880F880B8A21809322
:103EA0000B028091060190910701880F991F909352
:103EB0000701809306018091080280FF09C080916C
:103EC00008029091090201969093090280930802DA
:103ED000F894F999FECF1127E0910601F0910701BE
:103EE000C8E0D1E08091080290910902103091F46D
:103EF0000091570001700130D9F303E0009357009F
:103F0000E8950091570001700130D9F301E1009369
:103F10005700E89509901990009157000170013001
:103F2000D9F301E000935700E8951395103498F009
:103F300011270091570001700130D9F305E000937B
:103F40005700E8950091570001700130D9F301E165
:103F500000935700E8953296029709F0C7CF1030CA
:103F600011F00296E5CF11248091C00085FFE9CEC3
:103F7000ECCE0E94761C0E94761C182F0E94761CA4
:103F8000112351F0113021F086E00E94CA1CABCD04
:103F900084E90E94CA1CA7CD8EE10E94CA1CA3CD51
:043FA000F894FFCFC3
:023FA40080009B
:0400000300003800C1
:00000001FF

View File

@ -1,110 +0,0 @@
:103800000C94341C0C94511C0C94511C0C94511CA1
:103810000C94511C0C94511C0C94511C0C94511C74
:103820000C94511C0C94511C0C94511C0C94511C64
:103830000C94511C0C94511C0C94511C0C94511C54
:103840000C94511C0C94511C0C94511C0C94511C44
:103850000C94511C0C94511C0C94511C0C94511C34
:103860000C94511C0C94511C11241FBECFEFD4E0BA
:10387000DEBFCDBF11E0A0E0B1E0E4EAFEE302C0AC
:1038800005900D92A230B107D9F712E0A2E0B1E0A5
:1038900001C01D92AD30B107E1F70E94ED1C0C9400
:1038A000511F0C94001C482F10920A0280E08417CC
:1038B000E0F4582F2D9A28EE33E080E991E001974B
:1038C000F1F721503040C9F72D9828EE33E080E918
:1038D00091E00197F1F721503040C9F7852F8F5FB4
:1038E000582F841738F380930A020895EF92FF92BD
:1038F0000F931F93EE24FF2487018091C00087FD62
:1039000017C00894E11CF11C011D111D81E0E8168F
:1039100082E1F8068AE7080780E0180770F3E09173
:103920000201F091030109958091C00087FFE9CF62
:103930008091C600992787FD90951F910F91FF9068
:10394000EF900895982F8091C00085FFFCCF909351
:10395000C60008950E94761C803271F080910401A7
:103960008F5F80930401853009F00895E091020192
:10397000F09103010995089584E10E94A21C80E161
:103980000E94A21C0895CF93C82F0E94761C8032FB
:1039900041F0809104018F5F80930401853081F4B0
:1039A0000AC084E10E94A21C8C2F0E94A21C80E10C
:1039B0000E94A21C05C0E0910201F091030109954B
:1039C000CF910895CF93C82FC150CF3F21F00E94CF
:1039D000761CC150E0F7CF910895CFEFD4E0DEBF61
:1039E000CDBF000083E38093C4001092C50088E13E
:1039F0008093C10086E08093C2005098589A259A1F
:103A000083E00E94531C0E94761C8033B1F1813305
:103A1000B9F1803409F455C0813409F45BC08234B3
:103A200009F46DC0853409F470C0803531F18235F8
:103A300021F1813511F1853509F46BC0863509F422
:103A400073C0843609F47AC0843709F4CEC0853750
:103A500009F429C1863709F44AC0809104018F5FB7
:103A600080930401853079F6E0910201F091030121
:103A700009950E94761C803351F60E94AA1CC3CF80
:103A80000E94761CC82F803241F784E10E94A21C5C
:103A900081E40E94A21C86E50E94A21C82E50E948D
:103AA000A21C8C2F0E94A21C89E40E94A21C83E508
:103AB0000E94A21C80E50E94A21C80E10E94A21C20
:103AC000A2CF0E94761C8638C0F20E94761C0E940B
:103AD000AA1C99CF0E94761C803809F486C18138CF
:103AE00009F487C1823809F488C1883921F080E05F
:103AF0000E94C31C88CF83E00E94C31C84CF84E152
:103B00000E94E21C0E94AA1C7ECF85E00E94E21C5B
:103B1000F9CF0E94761C809306010E94761C809348
:103B200007010E94AA1C6FCF0E94761C803309F403
:103B3000CAC083E00E94E21C80E0DACF0E94761CBB
:103B4000809309020E94761C8093080280910C02E7
:103B50008E7F80930C020E94761C853409F4C4C0C9
:103B600000E010E0809108029091090218161906F1
:103B700070F4C8E0D1E00E94761C89930F5F1F4F5C
:103B8000809108029091090208171907A0F30E947A
:103B9000761C803209F061CF80910C0280FFAEC0AC
:103BA000E0910601F0910701EE0FFF1F00E010E029
:103BB00020910802309109021216130680F4A8E041
:103BC000B1E0F999FECFF2BDE1BD8D9180BDFA9AC9
:103BD000F99A31960F5F1F4F0217130790F3F09376
:103BE0000701E093060184E166CF0E94761C809372
:103BF00009020E94761C8093080280910601909130
:103C00000701880F991F90930701809306010E9476
:103C1000761C853409F46EC080910C028E7F8093EF
:103C20000C020E94761C803209F0EDCE84E10E94E5
:103C3000A21C00E010E02091080230910902121647
:103C4000130608F03ACFE0910601F0910701809148
:103C50000C0280FF1FC0F999FECFF2BDE1BDF89ABA
:103C600080B50E94A21CE0910601F09107013196F7
:103C7000F0930701E09306012091080230910902B8
:103C80000F5F1F4F0217130708F017CF80910C0228
:103C900080FDE1CF869580FFB4C03196F093070197
:103CA000E0930601EDCF0E94761C803209F0D5CE5C
:103CB00084E10E94A21C8EE10E94A21C84E90E9461
:103CC000A21C86E0F8CE0E94761C0E94761CC82FAB
:103CD0000E94761CCC2309F47CC0C13009F47DC05D
:103CE00086E00E94C31C8FCE80910C02816080937D
:103CF0000C0236CF80910C02816091CF8091070138
:103D000087FD6FC010920B02809106019091070110
:103D1000880F991F909307018093060180910802F4
:103D200080FF09C08091080290910902019690934A
:103D3000090280930802F894F999FECF1127E091C7
:103D40000601F0910701C8E0D1E08091080290914E
:103D50000902103091F40091570001700130D9F33D
:103D600003E000935700E89500915700017001307F
:103D7000D9F301E100935700E8950990199000915B
:103D8000570001700130D9F301E000935700E89526
:103D90001395103498F011270091570001700130ED
:103DA000D9F305E000935700E895009157000170A2
:103DB0000130D9F301E100935700E895329602975C
:103DC00009F0C7CF103011F00296E5CF112484E13D
:103DD00072CE8EE10E94C31C16CE84E90E94C31CE1
:103DE00012CE81E080930B028FCF82E00E94C31C31
:103DF0000ACE81E00E94C31C06CE80E10E94C31C53
:103E000002CE84910E94A21C2091080230910902E6
:103E1000E0910601F091070140CFCF930E94761CFC
:103E2000C82F0E94A21CC13614F0C75503C0C0336E
:103E30000CF0C0538C2F992787FD9095CF91089552
:103E40000F931F930E940D1F082F112707FD109538
:103E500002951295107F1027007F10270E940D1FDA
:103E6000800F992787FD90951F910F910895CF930B
:103E7000C82F85958595859585958A3034F0895A22
:103E8000CF70CA3034F0C95A05C0805DCF70CA30D7
:103E9000D4F7C05D0E94A21C8C2F0E94A21CCF915F
:043EA0000895FFCFB3
:023EA40080009C
:0400000300003800C1
:00000001FF

View File

@ -1,126 +0,0 @@
:103800000C94341C0C94511C0C94511C0C94511CA1
:103810000C94511C0C94511C0C94511C0C94511C74
:103820000C94511C0C94511C0C94511C0C94511C64
:103830000C94511C0C94511C0C94511C0C94511C54
:103840000C94511C0C94511C0C94511C0C94511C44
:103850000C94511C0C94511C0C94511C0C94511C34
:103860000C94511C0C94511C11241FBECFEFD4E0BA
:10387000DEBFCDBF11E0A0E0B1E0EEEAFFE302C0A1
:1038800005900D92A230B107D9F712E0A2E0B1E0A5
:1038900001C01D92AD30B107E1F70E94331D0C94B9
:1038A000D51F0C94001C982F9595959595959595F9
:1038B000905D8F708A307CF0282F295A8091C0004B
:1038C00085FFFCCF9093C6008091C00085FFFCCFA0
:1038D0002093C6000895282F205DF0CF982F809167
:1038E000C00085FFFCCF9093C6000895EF92FF9231
:1038F0000F931F93EE24FF2487018091C00087FD62
:1039000017C00894E11CF11C011D111D81E2E8168D
:1039100081EAF80687E0080780E0180770F3E09175
:103920000401F091050109958091C00087FFE9CF5E
:103930008091C6001F910F91FF90EF9008950E9413
:10394000761C982F8091C00085FFFCCF9093C60015
:1039500091362CF490330CF09053892F089597559D
:10396000892F08951F930E949F1C182F0E949F1C4F
:103970001295107F810F1F9108951F93182F882390
:1039800021F00E94761C1150E1F71F9108951F93BA
:10399000182F0E94761C803249F0809103018F5FBE
:1039A000809303018530C1F01F9108958091C0007C
:1039B00085FFFCCF84E18093C6008091C00085FF25
:1039C000FCCF1093C6008091C00085FFFCCF80E142
:1039D0008093C6001F910895E0910401F0910501C4
:1039E00009951F9108950E94761C803241F08091C4
:1039F00003018F5F80930301853081F008958091EA
:103A0000C00085FFFCCF84E18093C6008091C00098
:103A100085FFFCCF80E18093C6000895E09104010A
:103A2000F09105010995089510920A028823D1F0BA
:103A300090E048EC50E02D9A28EE33E0FA013197FF
:103A4000F1F721503040D1F72D9828EE33E0FA01FC
:103A50003197F1F721503040D1F79F5F981758F315
:103A600080930A0208953F924F925F926F927F92E5
:103A70008F929F92AF92BF92CF92DF92EF92FF927E
:103A80000F931F93CF93DF9394B714BE8091600080
:103A90008861809360001092600091FF0CC289E100
:103AA0008093C4001092C50088E18093C10086E035
:103AB0008093C2005098589A259A81E00E94141D64
:103AC00044E1F42E3EE1E32E24E9D22E96E0C92E05
:103AD00080E1B82EAA24A39401E4902E16E5812E4D
:103AE000B2E57B2EA0E26A2EF9E45F2EE3E54E2ECE
:103AF00070E5372E0E94761C8033B9F18133C1F115
:103B0000803409F470C0813409F477C0823409F438
:103B100086C0853409F489C0803539F1823529F1B0
:103B2000813509F4AFC1853509F485C0863509F4BE
:103B30008DC0843609F435C1843709F4C1C0853796
:103B400009F490C0863709F466C0809103018F5F45
:103B500080930301853071F6E0910401F091050135
:103B600009950E94761C803349F60E94F31CC2CF4F
:103B70000E94761C803249F78091C00085FFFCCFFF
:103B8000F092C6008091C00085FFFCCF9092C600E5
:103B90008091C00085FFFCCF8092C6008091C0005C
:103BA00085FFFCCF7092C6008091C00085FFFCCFDE
:103BB0006092C6008091C00085FFFCCF5092C60085
:103BC0008091C00085FFFCCF4092C6008091C0006C
:103BD00085FFFCCF3092C6008091C00085FFFCCFEE
:103BE000B092C60087CF0E94761C863808F4BDCFFD
:103BF0000E94761C0E94F31C7DCF0E94761C8038A8
:103C000009F45AC0813809F453C0823809F440C11C
:103C1000883909F449C080E00E94C71C6BCF84E159
:103C20000E94BD1C0E94F31C65CF85E00E94BD1C54
:103C30000E94F31C5FCF0E94761C809306010E94B5
:103C4000761C809307010E94F31C54CF0E94761CBF
:103C5000803309F421C183E00E94BD1C80E00E94F2
:103C6000C71C48CF0E94761C803209F06ECF80912D
:103C7000C00085FFFCCFF092C6008091C00085FF98
:103C8000FCCFE092C6008091C00085FFFCCFD092AF
:103C9000C6008091C00085FFFCCFC092C600809115
:103CA000C00085FFFCCF9CCF83E00E94C71C22CFC1
:103CB00081E00E94C71C1ECF82E00E94C71C1ACF61
:103CC0000E94761C809309020E94761C8093080251
:103CD0008091060190910701880F991F9093070129
:103CE000809306010E94761C853409F4C5C080913A
:103CF0000C028E7F80930C020E94761C803209F0A9
:103D0000F9CE8091C00085FFFCCFF092C600609193
:103D10000802709109026115710591F140E050E0CF
:103D200080910C02A82FA170B82FB27010C0BB23D5
:103D300061F1E0910601F09107013196F0930701DE
:103D4000E09306014F5F5F4F46175707C8F4AA2359
:103D500071F3F999FECF209106013091070132BD30
:103D600021BDF89A90B58091C00085FFFCCF90935B
:103D7000C6002F5F3F4F3093070120930601E2CF2B
:103D80008091C00085FFFCCF2BCFE0910601F09120
:103D9000070194918091C00085FFFCCF9093C600ED
:103DA000CCCF0E94761C809309020E94761C8093DF
:103DB000080280910C028E7F80930C020E94761C78
:103DC000853429F480910C02816080930C028091EB
:103DD000080290910902892B89F000E010E00E940E
:103DE000761CF801E85FFE4F80830F5F1F4F8091C4
:103DF0000802909109020817190788F30E94761C9F
:103E0000803209F0A2CE80910C0280FF62C0409106
:103E1000060150910701440F551F5093070140932D
:103E20000601609108027091090261157105C9F0DF
:103E3000E8E0F1E09A01DB01AE0FBF1FF999FECF78
:103E400032BD21BD819180BDFA9AF99A2F5F3F4F13
:103E5000EA17FB0799F7460F571F50930701409346
:103E600006018091C00085FFFCCFF092C6008091D2
:103E7000C00085FFFCCFB4CE80910C02816080939E
:103E80000C023ACF0E94F31C88E080936000FFCFC1
:103E900080E10E94C71C2ECE0E94761C0E94761CD8
:103EA000182F0E94761C112381F0113051F086E00A
:103EB0000E94C71C1FCEE0910401F09105010995F5
:103EC000EECD84E90E94C71C15CE8EE10E94C71C6E
:103ED00011CE809107018823880F880B8A21809357
:103EE0000B028091060190910701880F991F909312
:103EF0000701809306018091080280FF09C080912C
:103F00000802909109020196909309028093080299
:103F1000F894F999FECF1127E0910601F09107017D
:103F2000C8E0D1E08091080290910902103091F42C
:103F30000091570001700130D9F303E0009357005E
:103F4000E8950091570001700130D9F301E1009329
:103F50005700E895099019900091570001700130C1
:103F6000D9F301E000935700E8951395103498F0C9
:103F700011270091570001700130D9F305E000933B
:103F80005700E8950091570001700130D9F301E125
:103F900000935700E8953296029709F0C7CF10308A
:0E3FA00011F00296E5CF11245CCFF894FFCF0C
:023FAE00800091
:0400000300003800C1
:00000001FF

View File

@ -1,224 +0,0 @@
# 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 = ATmegaBOOT_168
# enter the parameters for the avrdude isp tool
ISPTOOL = stk500v2
ISPPORT = usb
ISPSPEED = -b 115200
MCU_TARGET = atmega168
LDSECTION = --section-start=.text=0x3800
# 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 0x0f (to
# lock it), but since the high two bits of the lock byte are
# unused, avrdude would get confused.
ISPFUSES = avrdude -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 = avrdude -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \
-U flash:w:$(PROGRAM)_$(TARGET).hex -U lock:w:0x0f: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 = -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:
lilypad: TARGET = lilypad
lilypad: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>1' '-DNUM_LED_FLASHES=3'
lilypad: AVR_FREQ = 8000000L
lilypad: $(PROGRAM)_lilypad.hex
lilypad_isp: lilypad
lilypad_isp: TARGET = lilypad
lilypad_isp: HFUSE = DD
lilypad_isp: LFUSE = E2
lilypad_isp: EFUSE = 00
lilypad_isp: isp
lilypad_resonator: TARGET = lilypad_resonator
lilypad_resonator: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=3'
lilypad_resonator: AVR_FREQ = 8000000L
lilypad_resonator: $(PROGRAM)_lilypad_resonator.hex
lilypad_resonator_isp: lilypad_resonator
lilypad_resonator_isp: TARGET = lilypad_resonator
lilypad_resonator_isp: HFUSE = DD
lilypad_resonator_isp: LFUSE = C6
lilypad_resonator_isp: EFUSE = 00
lilypad_resonator_isp: isp
pro8: TARGET = pro_8MHz
pro8: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' '-DWATCHDOG_MODS'
pro8: AVR_FREQ = 8000000L
pro8: $(PROGRAM)_pro_8MHz.hex
pro8_isp: pro8
pro8_isp: TARGET = pro_8MHz
pro8_isp: HFUSE = DD
pro8_isp: LFUSE = C6
pro8_isp: EFUSE = 00
pro8_isp: isp
pro16: TARGET = pro_16MHz
pro16: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' '-DWATCHDOG_MODS'
pro16: AVR_FREQ = 16000000L
pro16: $(PROGRAM)_pro_16MHz.hex
pro16_isp: pro16
pro16_isp: TARGET = pro_16MHz
pro16_isp: HFUSE = DD
pro16_isp: LFUSE = C6
pro16_isp: EFUSE = 00
pro16_isp: isp
pro20: TARGET = pro_20mhz
pro20: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' '-DWATCHDOG_MODS'
pro20: AVR_FREQ = 20000000L
pro20: $(PROGRAM)_pro_20mhz.hex
pro20_isp: pro20
pro20_isp: TARGET = pro_20mhz
pro20_isp: HFUSE = DD
pro20_isp: LFUSE = C6
pro20_isp: EFUSE = 00
pro20_isp: isp
diecimila: TARGET = diecimila
diecimila: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1'
diecimila: AVR_FREQ = 16000000L
diecimila: $(PROGRAM)_diecimila.hex
diecimila_isp: diecimila
diecimila_isp: TARGET = diecimila
diecimila_isp: HFUSE = DD
diecimila_isp: LFUSE = FF
diecimila_isp: EFUSE = 00
diecimila_isp: isp
ng: TARGET = ng
ng: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>1' '-DNUM_LED_FLASHES=3'
ng: AVR_FREQ = 16000000L
ng: $(PROGRAM)_ng.hex
ng_isp: ng
ng_isp: TARGET = ng
ng_isp: HFUSE = DD
ng_isp: LFUSE = FF
ng_isp: EFUSE = 00
ng_isp: isp
atmega328: TARGET = atmega328
atmega328: MCU_TARGET = atmega328p
atmega328: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' -DBAUD_RATE=57600
atmega328: AVR_FREQ = 16000000L
atmega328: LDSECTION = --section-start=.text=0x7800
atmega328: $(PROGRAM)_atmega328.hex
atmega328_isp: atmega328
atmega328_isp: TARGET = atmega328
atmega328_isp: MCU_TARGET = atmega328p
atmega328_isp: HFUSE = DA
atmega328_isp: LFUSE = FF
atmega328_isp: EFUSE = 05
atmega328_isp: isp
atmega328_pro8: TARGET = atmega328_pro_8MHz
atmega328_pro8: MCU_TARGET = atmega328p
atmega328_pro8: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=1' -DBAUD_RATE=57600 -DDOUBLE_SPEED
atmega328_pro8: AVR_FREQ = 8000000L
atmega328_pro8: LDSECTION = --section-start=.text=0x7800
atmega328_pro8: $(PROGRAM)_atmega328_pro_8MHz.hex
atmega328_pro8_isp: atmega328_pro8
atmega328_pro8_isp: TARGET = atmega328_pro_8MHz
atmega328_pro8_isp: MCU_TARGET = atmega328p
atmega328_pro8_isp: HFUSE = DA
atmega328_pro8_isp: LFUSE = FF
atmega328_pro8_isp: EFUSE = 05
atmega328_pro8_isp: isp
mega: TARGET = atmega1280
mega: MCU_TARGET = atmega1280
mega: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>4' '-DNUM_LED_FLASHES=0' -DBAUD_RATE=57600
mega: AVR_FREQ = 16000000L
mega: LDSECTION = --section-start=.text=0x1F000
mega: $(PROGRAM)_atmega1280.hex
mega_isp: mega
mega_isp: TARGET = atmega1280
mega_isp: MCU_TARGET = atmega1280
mega_isp: HFUSE = DA
mega_isp: LFUSE = FF
mega_isp: EFUSE = F5
mega_isp: isp
isp: $(TARGET)
$(ISPFUSES)
$(ISPFLASH)
isp-stk500: $(PROGRAM)_$(TARGET).hex
$(STK500-1)
$(STK500-2)
%.elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
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 -O ihex $< $@
%.srec: %.elf
$(OBJCOPY) -j .text -j .data -O srec $< $@
%.bin: %.elf
$(OBJCOPY) -j .text -j .data -O binary $< $@

View File

@ -1,507 +0,0 @@
/**********************************************************/
/* Serial Bootloader for Atmel mega8 AVR Controller */
/* */
/* ATmegaBOOT.c */
/* */
/* Copyright (c) 2003, Jason P. Kyle */
/* */
/* Hacked by DojoCorp - ZGZ - MMX - IVR */
/* Hacked by David A. Mellis */
/* */
/* 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 m8 */
/**********************************************************/
#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include <avr/delay.h>
//#define F_CPU 16000000
/* We, Malmoitians, like slow interaction
* therefore the slow baud rate ;-)
*/
//#define BAUD_RATE 9600
/* 6.000.000 is more or less 8 seconds at the
* speed configured here
*/
//#define MAX_TIME_COUNT 6000000
#define MAX_TIME_COUNT (F_CPU>>1)
///#define MAX_TIME_COUNT_MORATORY 1600000
/* SW_MAJOR and MINOR needs to be updated from time to time to avoid warning message from AVR Studio */
#define HW_VER 0x02
#define SW_MAJOR 0x01
#define SW_MINOR 0x12
// AVR-GCC compiler compatibility
// avr-gcc compiler v3.1.x and older doesn't support outb() and inb()
// if necessary, convert outb and inb to outp and inp
#ifndef outb
#define outb(sfr,val) (_SFR_BYTE(sfr) = (val))
#endif
#ifndef inb
#define inb(sfr) _SFR_BYTE(sfr)
#endif
/* defines for future compatibility */
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
/* Adjust to suit whatever pin your hardware uses to enter the bootloader */
#define eeprom_rb(addr) eeprom_read_byte ((uint8_t *)(addr))
#define eeprom_rw(addr) eeprom_read_word ((uint16_t *)(addr))
#define eeprom_wb(addr, val) eeprom_write_byte ((uint8_t *)(addr), (uint8_t)(val))
/* Onboard LED is connected to pin PB5 */
#define LED_DDR DDRB
#define LED_PORT PORTB
#define LED_PIN PINB
#define LED PINB5
#define SIG1 0x1E // Yep, Atmel is the only manufacturer of AVR micros. Single source :(
#define SIG2 0x93
#define SIG3 0x07
#define PAGE_SIZE 0x20U //32 words
void putch(char);
char getch(void);
void getNch(uint8_t);
void byte_response(uint8_t);
void nothing_response(void);
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 address_high;
uint8_t pagesz=0x80;
uint8_t i;
//uint8_t bootuart0=0,bootuart1=0;
void (*app_start)(void) = 0x0000;
int main(void)
{
uint8_t ch,ch2;
uint16_t w;
//cbi(BL_DDR,BL);
//sbi(BL_PORT,BL);
asm volatile("nop\n\t");
/* check if flash is programmed already, if not start bootloader anyway */
//if(pgm_read_byte_near(0x0000) != 0xFF) {
/* check if bootloader pin is set low */
//if(bit_is_set(BL_PIN,BL)) app_start();
//}
/* initialize UART(s) depending on CPU defined */
/* m8 */
UBRRH = (((F_CPU/BAUD_RATE)/16)-1)>>8; // set baud rate
UBRRL = (((F_CPU/BAUD_RATE)/16)-1);
UCSRB = (1<<RXEN)|(1<<TXEN); // enable Rx & Tx
UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0); // config USART; 8N1
//UBRRL = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
//UBRRH = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
//UCSRA = 0x00;
//UCSRC = 0x86;
//UCSRB = _BV(TXEN)|_BV(RXEN);
/* this was giving uisp problems, so I removed it; without it, the boot
works on with uisp and avrdude on the mac (at least). */
//putch('\0');
//uint32_t l;
//uint32_t time_count;
//time_count=0;
/* set LED pin as output */
sbi(LED_DDR,LED);
for (i = 0; i < 16; i++) {
outb(LED_PORT, inb(LED_PORT) ^ _BV(LED));
_delay_loop_2(0);
}
//for (l=0; l<40000000; l++)
//outb(LED_PORT, inb(LED_PORT) ^= _BV(LED));
/* flash onboard LED three times to signal entering of bootloader */
//for(i=0; i<3; ++i) {
//for(l=0; l<40000000; ++l);
//sbi(LED_PORT,LED);
//for(l=0; l<40000000; ++l);
//cbi(LED_PORT,LED);
//}
/* see comment at previous call to putch() */
//putch('\0'); // this line is needed for the synchronization of the programmer
/* forever */
for (;;) {
//if((inb(UCSRA) & _BV(RXC))){
/* 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);
}
}
/* 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();
// FIXME: modified only here by DojoCorp, Mumbai, India, 20050626
//time_count=0; // exted the delay once entered prog.mode
}
/* Leave programming mode */
else if(ch=='Q') {
nothing_response();
//time_count=MAX_TIME_COUNT_MORATORY; // once the programming is done,
// we should start the application
// but uisp has problems with this,
// therefore we just change the times
// and give the programmer 1 sec to react
}
/* 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 (w=0;w<length.word;w++) {
buff[w] = getch(); // Store data in buffer, can't keep up with serial data stream whilst programming pages
}
if (getch() == ' ') {
if (flags.eeprom) { //Write to EEPROM one byte at a time
for(w=0;w<length.word;w++) {
eeprom_wb(address.word,buff[w]);
address.word++;
}
} else { //Write to FLASH one page at a time
//if (address.byte[1]>127) address_high = 0x01; //Only possible with m128, m256 will need 3rd address byte. FIXME
//else address_high = 0x00;
//address.word = address.word << 1; //address * 2 -> byte location
//if ((length.byte[0] & 0x01)) length.word++; //Even up an odd number of bytes
cli(); //Disable interrupts, just to be sure
while(bit_is_set(EECR,EEWE)); //Wait for previous EEPROM writes to complete
asm volatile(
"clr r17 \n\t" //page_word_count
"lds r30,address \n\t" //Address of FLASH location (in words)
"lds r31,address+1 \n\t"
"lsl r30 \n\t" //address * 2 -> byte location
"rol r31 \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"
"sbrs r24,0 \n\t" //Even up an odd number of bytes
"rjmp length_loop \n\t"
"adiw r24,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"
"rcall wait_spm \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"
"rcall wait_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"
"rcall wait_spm \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
"rcall wait_spm \n\t"
// "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"
"rcall wait_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"
"wait_spm: \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_spm \n\t"
"ret \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" (SPMCR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31");
/* Should really add a wait for RWW section to be enabled, don't actually need it since we never */
/* exit the bootloader without a power cycle anyhow */
}
putch(0x14);
putch(0x10);
}
}
/* 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
}
if (getch() == ' ') { // Command terminator
putch(0x14);
for (w=0;w < length.word;w++) { // Can handle odd and even lengths okay
if (flags.eeprom) { // Byte access EEPROM read
putch(eeprom_rb(address.word));
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);
}
}
/* Read oscillator calibration byte */
else if(ch=='v') {
byte_response(0x00);
}
// } else {
// time_count++;
// if (time_count>=MAX_TIME_COUNT) {
// app_start();
// }
// }
} /* end of forever loop */
}
void putch(char ch)
{
/* m8 */
while (!(inb(UCSRA) & _BV(UDRE)));
outb(UDR,ch);
}
char getch(void)
{
/* m8 */
uint32_t count = 0;
while(!(inb(UCSRA) & _BV(RXC))) {
/* HACKME:: here is a good place to count times*/
count++;
if (count > MAX_TIME_COUNT)
app_start();
}
return (inb(UDR));
}
void getNch(uint8_t count)
{
uint8_t i;
for(i=0;i<count;i++) {
/* m8 */
//while(!(inb(UCSRA) & _BV(RXC)));
//inb(UDR);
getch(); // need to handle time out
}
}
void byte_response(uint8_t val)
{
if (getch() == ' ') {
putch(0x14);
putch(val);
putch(0x10);
}
}
void nothing_response(void)
{
if (getch() == ' ') {
putch(0x14);
putch(0x10);
}
}
/* end of file ATmegaBOOT.c */

View File

@ -1,66 +0,0 @@
:101C000012C02BC02AC029C028C027C026C025C0AA
:101C100024C023C022C021C020C01FC01EC01DC0C0
:101C20001CC01BC01AC011241FBECFE5D4E0DEBF0C
:101C3000CDBF10E0A0E6B0E0E8EEFFE102C0059005
:101C40000D92A236B107D9F711E0A2E6B0E001C0CB
:101C50001D92AA36B107E1F74FC0D2CFEF92FF92A3
:101C60000F931F93EE24FF24870113C00894E11CF7
:101C7000F11C011D111D81E0E81682E1F8068AE7DA
:101C8000080780E0180728F0E0916200F0916300F7
:101C900009955F9BEBCF8CB1992787FD90951F919C
:101CA0000F91FF90EF9008955D9BFECF8CB9089542
:101CB000D5DF803221F484E1F7DF80E1F5DF08959C
:101CC0001F93182FCBDF803231F484E1EDDF812FB9
:101CD000EBDF80E1E9DF1F9108951F93CF93DF933E
:101CE000182FC0E0D0E002C0B9DF2196C117E0F3A1
:101CF000DF91CF911F910895CFE5D4E0DEBFCDBF36
:101D0000000010BC83E389B988E18AB986E880BD08
:101D1000BD9A1092680130E2E0E0F0E02FE088B375
:101D2000832788BBCF010197F1F7215027FFF7CF19
:101D300020E12093680192DF803381F1813399F4AF
:101D40008DDF8032C1F784E1AFDF81E4ADDF86E56E
:101D5000ABDF82E5A9DF80E2A7DF89E4A5DF83E5C9
:101D6000A3DF80E5C7C0803429F478DF8638B0F07F
:101D700075DF14C0813471F471DF803811F482E0B2
:101D80001DC1813811F481E019C1823809F015C1F3
:101D900082E114C1823421F484E19FDF89DFCBCF5B
:101DA000853411F485E0F9CF8035C1F38135B1F385
:101DB0008235A1F3853539F451DF809364004EDF1D
:101DC00080936500EBCF863519F484E086DFF5C09B
:101DD000843609F093C042DF809367013FDF809330
:101DE0006601809169018E7F8093690137DF8534B8
:101DF00029F480916901816080936901C0E0D0E09D
:101E000006E610E005C02ADFF80181938F012196D4
:101E10008091660190916701C817D907A0F31EDF72
:101E2000803209F088CF8091690180FF1FC020E0D7
:101E300030E0E6E6F0E012C0A0916400B0916500E9
:101E40008191082EC5D08091640090916500019623
:101E500090936500809364002F5F3F4F80916601EF
:101E6000909167012817390738F343C0F894E19936
:101E7000FECF1127E0916400F0916500EE0FFF1F87
:101E8000C6E6D0E0809166019091670180FF01C0B5
:101E90000196103051F422D003E000935700E895EA
:101EA0001DD001E100935700E8950990199016D0D4
:101EB00001E000935700E8951395103258F0112770
:101EC0000DD005E000935700E89508D001E100939C
:101ED0005700E8953296029739F0DBCF0091570012
:101EE00001700130D9F30895103011F00296E7CF58
:101EF000112484E1D9DE80E1D7DE1DCF843709F0DB
:101F00004BC0ACDE80936701A9DE80936601A6DE3C
:101F100090916901853421F49160909369010DC01D
:101F20009E7F909369018091640090916500880F75
:101F3000991F909365008093640090DE803209F0D1
:101F4000FACE84E1B1DEC0E0D0E01EC0809169012C
:101F500080FF07C0A0916400B091650031D0802D52
:101F600008C081FD07C0E0916400F0916500E49134
:101F70008E2F9ADE80916400909165000196909377
:101F800065008093640021968091660190916701BD
:101F9000C817D907D8F2AFCF853761F45FDE80323A
:101FA00009F0C9CE84E180DE8EE17EDE83E97CDE4D
:101FB00087E0A0CF863709F0BECE80E081DEBBCEC1
:101FC000E199FECFBFBBAEBBE09A11960DB208956A
:101FD000E199FECFBFBBAEBB0DBA11960FB6F89418
:081FE000E29AE19A0FBE089598
:021FE800800077
:0400000300001C00DD
:00000001FF

View File

@ -1,88 +0,0 @@
# Makefile for ATmegaBOOT
# E.Lins, 2004-10-14
# program name should not be changed...
PROGRAM = ATmegaBOOT
PRODUCT=atmega8
# enter the parameters for the UISP isp tool
ISPPARAMS = -dprog=stk500 -dserial=$(SERIAL) -dspeed=115200
#DIRAVR = /usr/local/avr
DIRAVRBIN = $(DIRAVR)/bin
DIRAVRUTILS = $(DIRAVR)/utils/bin
DIRINC = $(DIRAVR)/include
DIRLIB = $(DIRAVR)/avr/lib
MCU_TARGET = atmega8
LDSECTION = --section-start=.text=0x1c00
FUSE_L = 0xdf
FUSE_H = 0xca
ISPFUSES = $(DIRAVRBIN)/uisp -dpart=ATmega8 $(ISPPARAMS) --wr_fuse_l=$(FUSE_L) --wr_fuse_h=$(FUSE_H)
ISPFLASH = $(DIRAVRBIN)/uisp -dpart=ATmega8 $(ISPPARAMS) --erase --upload if=$(PROGRAM).hex -v
OBJ = $(PROGRAM).o
OPTIMIZE = -Os
DEFS = -DF_CPU=16000000 -DBAUD_RATE=19200
LIBS =
CC = $(DIRAVRBIN)/avr-gcc
# Override is only needed by avr-lib build system.
override CFLAGS = -g -Wall $(OPTIMIZE) -mmcu=$(MCU_TARGET) -D$(PRODUCT) $(DEFS) -I$(DIRINC)
override LDFLAGS = -Wl,-Map,$(PROGRAM).map,$(LDSECTION)
OBJCOPY = $(DIRAVRBIN)/avr-objcopy
OBJDUMP = $(DIRAVRBIN)/avr-objdump
SIZE = $(DIRAVRBIN)/avr-size
all: $(PROGRAM).elf lst text asm size
isp: $(PROGRAM).hex
$(ISPFUSES)
$(ISPFLASH)
$(PROGRAM).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
clean:
rm -rf *.s
rm -rf *.o *.elf
rm -rf *.lst *.map
asm: $(PROGRAM).s
%.s: %.c
$(CC) -S $(CFLAGS) -g1 $^
lst: $(PROGRAM).lst
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
size: $(PROGRAM).hex
$(SIZE) $^
# Rules for building the .text rom images
text: hex bin srec
hex: $(PROGRAM).hex
bin: $(PROGRAM).bin
srec: $(PROGRAM).srec
%.hex: %.elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
%.srec: %.elf
$(OBJCOPY) -j .text -j .data -O srec $< $@
%.bin: %.elf
$(OBJCOPY) -j .text -j .data -O binary $< $@

View File

@ -1,1038 +0,0 @@
/**********************************************************/
/* Serial Bootloader for Atmel megaAVR Controllers */
/* */
/* tested with ATmega8, ATmega128 and ATmega168 */
/* should work with other mega's, see code for details */
/* */
/* ATmegaBOOT.c */
/* */
/* build: 050815 */
/* date : 15.08.2005 */
/* */
/* 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 m128,m8,m163 - feel free to let me know */
/* how/if it works for you. */
/* */
/**********************************************************/
/* some includes */
#include <inttypes.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
#define set_output(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#define set_input(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#define high(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#define low(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
/* the current avr-libc eeprom functions do not support the ATmega168 */
/* own eeprom write/read functions are used instead */
#if !defined(__AVR_ATmega168__) || !defined(__AVR_ATmega328P__)
#include <avr/eeprom.h>
#endif
/* define F_CPU according to AVR_FREQ set in Makefile */
/* Is there a better way to pass such a parameter from Makefile to source code ? */
#define F_CPU 16000000L
#include <util/delay.h>
/* 20060803: hacked by DojoCorp */
/* set the waiting time for the bootloader */
#define MAX_TIME_COUNT (F_CPU>>1)
/* set the UART baud rate */
/* 20060803: hacked by DojoCorp */
#define BAUD_RATE 115200
/* 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 0x0f
/* Adjust to suit whatever pin your hardware uses to enter the bootloader */
/* ATmega128 has two UARTS so two pins are used to enter bootloader and select UART */
/* BL0... means UART0, BL1... means UART1 */
#ifdef __AVR_ATmega128__
#define BL_DDR DDRF
#define BL_PORT PORTF
#define BL_PIN PINF
#define BL0 PINF7
#define BL1 PINF6
#else
/* other ATmegas have only one UART, so only one pin is defined to enter bootloader */
#define BL_DDR DDRD
#define BL_PORT PORTD
#define BL_PIN PIND
#define BL PIND6
#endif
/* 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 */
#ifdef __AVR_ATmega128__
/* Onboard LED is connected to pin PB7 (e.g. Crumb128, PROBOmega128, Savvy128) */
#define LED_DDR DDRB
#define LED_PORT PORTB
#define LED_PIN PINB
#define LED PINB7
#else
/* Onboard LED is connected to pin PB2 (e.g. Crumb8, Crumb168) */
#define LED_DDR DDRB
#define LED_PORT PORTB
#define LED_PIN PINB
/* 20060803: hacked by DojoCorp, LED pin is B5 in Arduino */
/* #define LED PINB2 */
#define LED PINB5
#endif
/* monitor functions will only be compiled when using ATmega128, due to bootblock size constraints */
#ifdef __AVR_ATmega128__
#define MONITOR
#endif
/* 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_ATmega128__
#define SIG2 0x97
#define SIG3 0x02
#define PAGE_SIZE 0x80U //128 words
#elif defined __AVR_ATmega64__
#define SIG2 0x96
#define SIG3 0x02
#define PAGE_SIZE 0x80U //128 words
#elif defined __AVR_ATmega32__
#define SIG2 0x95
#define SIG3 0x02
#define PAGE_SIZE 0x40U //64 words
#elif defined __AVR_ATmega16__
#define SIG2 0x94
#define SIG3 0x03
#define PAGE_SIZE 0x40U //64 words
#elif defined __AVR_ATmega8__
#define SIG2 0x93
#define SIG3 0x07
#define PAGE_SIZE 0x20U //32 words
#elif defined __AVR_ATmega88__
#define SIG2 0x93
#define SIG3 0x0a
#define PAGE_SIZE 0x20U //32 words
#elif defined __AVR_ATmega168__
#define SIG2 0x94
#define SIG3 0x06
#define PAGE_SIZE 0x40U //64 words
#elif defined __AVR_ATmega328P__
#define SIG2 0x95
#define SIG3 0x0F
#define PAGE_SIZE 0x40U //64 words
#elif defined __AVR_ATmega162__
#define SIG2 0x94
#define SIG3 0x04
#define PAGE_SIZE 0x40U //64 words
#elif defined __AVR_ATmega163__
#define SIG2 0x94
#define SIG3 0x02
#define PAGE_SIZE 0x40U //64 words
#elif defined __AVR_ATmega169__
#define SIG2 0x94
#define SIG3 0x05
#define PAGE_SIZE 0x40U //64 words
#elif defined __AVR_ATmega8515__
#define SIG2 0x93
#define SIG3 0x06
#define PAGE_SIZE 0x20U //32 words
#elif defined __AVR_ATmega8535__
#define SIG2 0x93
#define SIG3 0x08
#define PAGE_SIZE 0x20U //32 words
#endif
/* 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 address_high;
uint8_t pagesz=0x80;
uint8_t i;
uint8_t bootuart = 0;
void (*app_start)(void) = 0x0000;
/* main program starts here */
int main(void)
{
uint8_t ch,ch2;
uint16_t w;
asm volatile("nop\n\t");
/* set pin direction for bootloader pin and enable pullup */
/* for ATmega128, two pins need to be initialized */
#ifdef __AVR_ATmega128__
BL_DDR &= ~_BV(BL0);
BL_DDR &= ~_BV(BL1);
BL_PORT |= _BV(BL0);
BL_PORT |= _BV(BL1);
#else
BL_DDR &= ~_BV(BL);
BL_PORT |= _BV(BL);
#endif
#ifdef __AVR_ATmega128__
/* check which UART should be used for booting */
if(bit_is_clear(BL_PIN, BL0)) {
bootuart = 1;
}
else if(bit_is_clear(BL_PIN, BL1)) {
bootuart = 2;
}
#endif
/* check if flash is programmed already, if not start bootloader anyway */
if(pgm_read_byte_near(0x0000) != 0xFF) {
#ifdef __AVR_ATmega128__
/* no UART was selected, start application */
if(!bootuart) {
app_start();
}
#else
/* check if bootloader pin is set low */
/* we don't start this part neither for the m8, nor m168 */
//if(bit_is_set(BL_PIN, BL)) {
// app_start();
// }
#endif
}
#ifdef __AVR_ATmega128__
/* no bootuart was selected, default to uart 0 */
if(!bootuart) {
bootuart = 1;
}
#endif
/* initialize UART(s) depending on CPU defined */
#ifdef __AVR_ATmega128__
if(bootuart == 1) {
UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
UCSR0A = 0x00;
UCSR0C = 0x06;
UCSR0B = _BV(TXEN0)|_BV(RXEN0);
}
if(bootuart == 2) {
UBRR1L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
UBRR1H = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
UCSR1A = 0x00;
UCSR1C = 0x06;
UCSR1B = _BV(TXEN1)|_BV(RXEN1);
}
#elif defined __AVR_ATmega163__
UBRR = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
UBRRHI = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
UCSRA = 0x00;
UCSRB = _BV(TXEN)|_BV(RXEN);
#elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
UBRR0H = ((F_CPU / 16 + BAUD_RATE / 2) / BAUD_RATE - 1) >> 8;
UBRR0L = ((F_CPU / 16 + BAUD_RATE / 2) / BAUD_RATE - 1);
//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);
#elif defined __AVR_ATmega8__
/* m8 */
UBRRH = (((F_CPU/BAUD_RATE)/16)-1)>>8; // set baud rate
UBRRL = (((F_CPU/BAUD_RATE)/16)-1);
UCSRB = (1<<RXEN)|(1<<TXEN); // enable Rx & Tx
UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0); // config USART; 8N1
#else
/* m16,m32,m169,m8515,m8535 */
UBRRL = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
UBRRH = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
UCSRA = 0x00;
UCSRC = 0x06;
UCSRB = _BV(TXEN)|_BV(RXEN);
#endif
/* set LED pin as output */
LED_DDR |= _BV(LED);
set_output(DDRD,PIND7);
high(PORTD,PD7);
for (i = 0; i < 16; i++) {
_delay_loop_2(0);
}
low(PORTD,PD7);
/* flash onboard LED to signal entering of bootloader */
#ifdef __AVR_ATmega128__
// 4x for UART0, 5x for UART1
flash_led(3 + bootuart);
#else
flash_led(3);
#endif
/* 20050803: by DojoCorp, this is one of the parts provoking the
system to stop listening, cancelled from the original */
//putch('\0');
//message("SET BT PAGEMODE 3 2000 1");
putch('S');
putch('E');
putch('T');
putch(' ');
putch('B');
putch('T');
putch(' ');
putch('P');
putch('A');
putch('G');
putch('E');
putch('M');
putch('O');
putch('D');
putch('E');
putch(' ');
putch('3');
putch(' ');
putch('2');
putch('0');
putch('0');
putch('0');
putch(' ');
putch('1');
putch(0x0D);
//put_s("SET BT ROLE 0 f 7d00");
putch('S');
putch('E');
putch('T');
putch(' ');
putch('B');
putch('T');
putch(' ');
putch('R');
putch('O');
putch('L');
putch('E');
putch(' ');
putch('0');
putch(' ');
putch('f');
putch(' ');
putch('7');
putch('d');
putch('0');
putch('0');
putch(0x0D);
/* 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);
}
}
/* 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();
}
/* 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 (w=0;w<length.word;w++) {
buff[w] = getch(); // Store data in buffer, can't keep up with serial data stream whilst programming pages
}
if (getch() == ' ') {
if (flags.eeprom) { //Write to EEPROM one byte at a time
for(w=0;w<length.word;w++) {
#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
while(EECR & (1<<EEPE));
EEAR = (uint16_t)(void *)address.word;
EEDR = buff[w];
EECR |= (1<<EEMPE);
EECR |= (1<<EEPE);
#else
eeprom_write_byte((void *)address.word,buff[w]);
#endif
address.word++;
}
}
else { //Write to FLASH one page at a time
if (address.byte[1]>127) address_high = 0x01; //Only possible with m128, m256 will need 3rd address byte. FIXME
else address_high = 0x00;
#ifdef __AVR_ATmega128__
RAMPZ = address_high;
#endif
address.word = address.word << 1; //address * 2 -> byte location
/* if ((length.byte[0] & 0x01) == 0x01) length.word++; //Even up an odd number of bytes */
if ((length.byte[0] & 0x01)) length.word++; //Even up an odd number of bytes
cli(); //Disable interrupts, just to be sure
// HACKME: EEPE used to be EEWE
while(bit_is_set(EECR,EEPE)); //Wait for previous EEPROM writes to complete
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"
#ifdef __AVR_ATmega163__
".word 0xFFFF \n\t"
"nop \n\t"
#endif
"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"
#ifdef __AVR_ATmega163__
".word 0xFFFF \n\t"
"nop \n\t"
#endif
"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"
#ifdef __AVR_ATmega163__
"andi r30,0x80 \n\t" // m163 requires Z6:Z1 to be zero during page write
#endif
"ldi r16,0x05 \n\t" //Write page pointed to by Z
"sts %0,r16 \n\t"
"spm \n\t"
#ifdef __AVR_ATmega163__
".word 0xFFFF \n\t"
"nop \n\t"
"ori r30,0x7E \n\t" // recover Z6:Z1 state after page write (had to be zero during write)
#endif
"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"
#ifdef __AVR_ATmega163__
".word 0xFFFF \n\t"
"nop \n\t"
#endif
"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
#if defined __AVR_ATmega168__ || __AVR_ATmega328P__
: "=m" (SPMCSR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31"
#else
: "=m" (SPMCR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31"
#endif
);
/* Should really add a wait for RWW section to be enabled, don't actually need it since we never */
/* exit the bootloader without a power cycle anyhow */
}
putch(0x14);
putch(0x10);
}
}
/* Read memory block mode, length is big endian. */
else if(ch=='t') {
length.byte[1] = getch();
length.byte[0] = getch();
#if defined __AVR_ATmega128__
if (address.word>0x7FFF) flags.rampz = 1; // No go with m256, FIXME
else flags.rampz = 0;
#endif
if (getch() == 'E') flags.eeprom = 1;
else {
flags.eeprom = 0;
address.word = address.word << 1; // address * 2 -> byte location
}
if (getch() == ' ') { // Command terminator
putch(0x14);
for (w=0;w < length.word;w++) { // Can handle odd and even lengths okay
if (flags.eeprom) { // Byte access EEPROM read
#if defined __AVR_ATmega168__ || __AVR_ATmega328P__
while(EECR & (1<<EEPE));
EEAR = (uint16_t)(void *)address.word;
EECR |= (1<<EERE);
putch(EEDR);
#else
putch(eeprom_read_byte((void *)address.word));
#endif
address.word++;
}
else {
if (!flags.rampz) putch(pgm_read_byte_near(address.word));
#if defined __AVR_ATmega128__
else putch(pgm_read_byte_far(address.word + 0x10000));
// Hmmmm, yuck FIXME when m256 arrvies
#endif
address.word++;
}
}
putch(0x10);
}
}
/* Get device signature bytes */
else if(ch=='u') {
if (getch() == ' ') {
putch(0x14);
putch(SIG1);
putch(SIG2);
putch(SIG3);
putch(0x10);
}
}
/* Read oscillator calibration byte */
else if(ch=='v') {
byte_response(0x00);
}
#ifdef MONITOR
/* here come the extended monitor commands by Erik Lins */
/* check for three times exclamation mark pressed */
else if(ch=='!') {
ch = getch();
if(ch=='!') {
ch = getch();
if(ch=='!') {
#ifdef __AVR_ATmega128__
uint16_t extaddr;
#endif
uint8_t addrl, addrh;
#ifdef CRUMB128
PGM_P welcome = {"ATmegaBOOT / Crumb128 - (C) J.P.Kyle, E.Lins - 050815\n\r"};
#elif defined PROBOMEGA128
PGM_P welcome = {"ATmegaBOOT / PROBOmega128 - (C) J.P.Kyle, E.Lins - 050815\n\r"};
#elif defined SAVVY128
PGM_P welcome = {"ATmegaBOOT / Savvy128 - (C) J.P.Kyle, E.Lins - 050815\n\r"};
#endif
/* turn on LED */
LED_DDR |= _BV(LED);
LED_PORT &= ~_BV(LED);
/* print a welcome message and command overview */
for(i=0; welcome[i] != '\0'; ++i) {
putch(welcome[i]);
}
/* test for valid commands */
for(;;) {
putch('\n');
putch('\r');
putch(':');
putch(' ');
ch = getch();
putch(ch);
/* toggle LED */
if(ch == 't') {
if(bit_is_set(LED_PIN,LED)) {
LED_PORT &= ~_BV(LED);
putch('1');
} else {
LED_PORT |= _BV(LED);
putch('0');
}
}
/* read byte from address */
else if(ch == 'r') {
ch = getch(); putch(ch);
addrh = gethex();
addrl = gethex();
putch('=');
ch = *(uint8_t *)((addrh << 8) + addrl);
puthex(ch);
}
/* write a byte to address */
else if(ch == 'w') {
ch = getch(); putch(ch);
addrh = gethex();
addrl = gethex();
ch = getch(); putch(ch);
ch = gethex();
*(uint8_t *)((addrh << 8) + addrl) = ch;
}
/* read from uart and echo back */
else if(ch == 'u') {
for(;;) {
putch(getch());
}
}
#ifdef __AVR_ATmega128__
/* external bus loop */
else if(ch == 'b') {
putch('b');
putch('u');
putch('s');
MCUCR = 0x80;
XMCRA = 0;
XMCRB = 0;
extaddr = 0x1100;
for(;;) {
ch = *(volatile uint8_t *)extaddr;
if(++extaddr == 0) {
extaddr = 0x1100;
}
}
}
#endif
else if(ch == 'j') {
app_start();
}
}
/* end of monitor functions */
}
}
}
/* end of monitor */
#endif
}
/* 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)
{
#ifdef __AVR_ATmega128__
if(bootuart == 1) {
while (!(UCSR0A & _BV(UDRE0)));
UDR0 = ch;
}
else if (bootuart == 2) {
while (!(UCSR1A & _BV(UDRE1)));
UDR1 = ch;
}
#elif defined (__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
while (!(UCSR0A & _BV(UDRE0)));
UDR0 = ch;
#else
/* m8,16,32,169,8515,8535,163 */
while (!(UCSRA & _BV(UDRE)));
UDR = ch;
#endif
}
char getch(void)
{
#ifdef __AVR_ATmega128__
if(bootuart == 1) {
while(!(UCSR0A & _BV(RXC0)));
return UDR0;
}
else if(bootuart == 2) {
while(!(UCSR1A & _BV(RXC1)));
return UDR1;
}
return 0;
#elif defined (__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
uint32_t count = 0;
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();
}
return UDR0;
#else
/* m8,16,32,169,8515,8535,163 */
uint32_t count = 0;
while(!(UCSRA & _BV(RXC))){
/* 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();
}
return UDR;
#endif
}
void getNch(uint8_t count)
{
uint8_t i;
for(i=0;i<count;i++) {
#ifdef __AVR_ATmega128__
if(bootuart == 1) {
while(!(UCSR0A & _BV(RXC0)));
UDR0;
}
else if(bootuart == 2) {
while(!(UCSR1A & _BV(RXC1)));
UDR1;
}
#elif (defined __AVR_ATmega168__) || defined(__AVR_ATmega328P__)
while(!(UCSR0A & _BV(RXC0)));
UDR0;
#else
/* m8,16,32,169,8515,8535,163 */
/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
//while(!(UCSRA & _BV(RXC)));
//UDR;
uint8_t i;
for(i=0;i<count;i++) {
getch(); // need to handle time out
}
#endif
}
}
void byte_response(uint8_t val)
{
if (getch() == ' ') {
putch(0x14);
putch(val);
putch(0x10);
}
}
void nothing_response(void)
{
if (getch() == ' ') {
putch(0x14);
putch(0x10);
}
}
void flash_led(uint8_t count)
{
/* flash onboard LED three times to signal entering of bootloader */
uint32_t l;
if (count == 0) {
count = 3;
}
for (i = 0; i < count; ++i) {
LED_PORT |= _BV(LED);
for(l = 0; l < (2 * F_CPU); ++l);
LED_PORT &= ~_BV(LED);
for(l = 0; l < (F_CPU / 5); ++l);
}
}
/* end of file ATmegaBOOT.c */

View File

@ -1,121 +0,0 @@
:103800000C94341C0C944F1C0C944F1C0C944F1CA7
:103810000C944F1C0C944F1C0C944F1C0C944F1C7C
:103820000C944F1C0C944F1C0C944F1C0C944F1C6C
:103830000C944F1C0C944F1C0C944F1C0C944F1C5C
:103840000C944F1C0C944F1C0C944F1C0C944F1C4C
:103850000C944F1C0C944F1C0C944F1C0C944F1C3C
:103860000C944F1C0C944F1C11241FBECFEFD4E0BE
:10387000DEBFCDBF11E0A0E0B1E0E0E6FFE302C0B3
:1038800005900D92A230B107D9F712E0A2E0B1E0A5
:1038900001C01D92AC30B107E1F70C94D61C0C941A
:1038A000001C882309F483E01092090290E0981725
:1038B000F0F4692F2D9A2FEF37E448EE51E02253B0
:1038C00030404040504057FFFACF2D982FEF33ED56
:1038D00040E350E0225330404040504057FFFACF81
:1038E000962F9F5F692F981728F3909309020895E8
:1038F000982F8091C00085FFFCCF9093C60008955B
:10390000EF92FF920F931F93EE24FF248701809183
:10391000C00087FD17C00894E11CF11C011D111D9A
:1039200081E0E81682E1F8068AE7080780E01807D8
:1039300070F3E0910201F091030109958091C000BC
:1039400087FFE9CF8091C600992787FD90951F9149
:103950000F91FF90EF9008950E94801C803209F033
:10396000089584E10E94781C80E10E94781C0895EB
:10397000CF93C82F0E94801C803249F484E10E94BA
:10398000781C8C2F0E94781C80E10E94781CCF91BB
:103990000895282F90E007C08091C0008823E4F7A5
:1039A0008091C6009F5F9217B8F30895CFEFD4E0DF
:1039B000DEBFCDBF000056985E9A1092C50088E029
:1039C0008093C40088E18093C10086E08093C200A8
:1039D000259A579A5F9A109209022FE080E090E0B2
:1039E0000197F1F7215027FFF9CF20E12093090239
:1039F0005F9883E00E94511C83E50E94781C85E457
:103A00000E94781C84E50E94781C80E20E94781C49
:103A100082E40E94781C84E50E94781C80E20E9467
:103A2000781C80E50E94781C81E40E94781C87E461
:103A30000E94781C85E40E94781C8DE40E94781C0A
:103A40008FE40E94781C84E40E94781C85E40E9424
:103A5000781C80E20E94781C83E30E94781C80E23C
:103A60000E94781C82E30E94781C80E30E94781CEC
:103A700080E30E94781C80E30E94781C80E20E9410
:103A8000781C81E30E94781C8DE00E94781C83E5FD
:103A90000E94781C85E40E94781C84E50E94781CB2
:103AA00080E20E94781C82E40E94781C84E50E94D7
:103AB000781C80E20E94781C82E50E94781C8FE4CA
:103AC0000E94781C8CE40E94781C85E40E94781C7B
:103AD00080E20E94781C80E30E94781C80E20E94B1
:103AE000781C86E60E94781C80E20E94781C87E39E
:103AF0000E94781C84E60E94781C80E30E94781C57
:103B000080E30E94781C8DE00E94781C0E94801C3B
:103B1000803361F1813369F1803409F449C0813423
:103B200009F44FC0823409F45DC0853409F460C0E3
:103B30008035E1F08135D1F08235C1F0853509F469
:103B40005BC0863509F463C0843609F465C08437E8
:103B500009F4B9C0853709F414C18637B9F680E095
:103B60000E94B81C0E94801C8033A1F60E94AC1CED
:103B7000CDCF0E94801CC82F803241F684E10E9484
:103B8000781C81E40E94781C86E50E94781C82E5FE
:103B90000E94781C8C2F0E94781C89E40E94781C5B
:103BA00083E50E94781C80E50E94781C80E1ACCF00
:103BB0000E94801C8638D0F20E94801C0E94AC1C9F
:103BC000A5CF0E94801C803809F4EDC0813809F42B
:103BD000EEC0823809F4EFC0883909F683E00E940C
:103BE000B81CC0CF84E10E94C91C0E94AC1C8ECFBF
:103BF00085E00E94C91CF9CF0E94801C80930501BA
:103C00000E94801C809306010E94AC1C7FCF84E040
:103C10000E94C91C80E0A4CF0E94801C80930802EF
:103C20000E94801C8093070280910B028E7F8093FC
:103C30000B020E94801C853409F4C1C000E010E032
:103C400080910702909108021816190670F4C7E0D7
:103C5000D1E00E94801C89930F5F1F4F8091070263
:103C60009091080208171907A0F30E94801C803267
:103C700009F04CCF80910B0280FFADC000E010E056
:103C8000209107023091080212161306C0F4E09149
:103C90000501F0910601A7E0B1E0F999FECFF2BD70
:103CA000E1BD8D9180BDFA9AF99A31960F5F1F4F51
:103CB0000217130790F3F0930601E093050184E1E6
:103CC0000E94781C73CF0E94801C809308020E947F
:103CD000801C809307020E94801C853409F475C003
:103CE00080910B028E7F80930B0280910501909151
:103CF0000601880F991F90930601809305010E9489
:103D0000801C803209F002CF84E10E94781C00E020
:103D100010E020910702309108021216130608F0F5
:103D200045CFE0910501F091060180910B0280FFE3
:103D30001FC0F999FECFF2BDE1BDF89A80B50E948F
:103D4000781CE0910501F09106013196F09306018F
:103D5000E093050120910702309108020F5F1F4F89
:103D60000217130708F022CF80910B0280FDE1CFEC
:103D7000869580FF9BC03196F0930601E093050184
:103D8000EDCF0E94801C803209F0C0CE84E10E94F9
:103D9000781C8EE10E94781C84E90E94781C86E0E1
:103DA0000E94781C03CF82E00E94B81CDBCE81E029
:103DB0000E94B81CD7CE8FE00E94B81CD3CE809151
:103DC0000B02816080930B0239CF80910B028160DE
:103DD00080930B0294CF8091060187FD73C01092EF
:103DE0000A028091050190910601880F991F909316
:103DF0000601809305018091070280FF09C0809130
:103E0000070290910802019690930802809307029E
:103E1000F894F999FECF1127E0910501F091060180
:103E2000C7E0D1E08091070290910802103091F430
:103E30000091570001700130D9F303E0009357005F
:103E4000E8950091570001700130D9F301E100932A
:103E50005700E895099019900091570001700130C2
:103E6000D9F301E000935700E8951395103498F0CA
:103E700011270091570001700130D9F305E000933C
:103E80005700E8950091570001700130D9F301E126
:103E900000935700E8953296029709F0C7CF10308B
:103EA00011F00296E5CF112484E10ACF84910E949B
:103EB000781C2091070230910802E0910501F091F1
:103EC000060159CF81E080930A028BCF1F93CF93D5
:103ED0000E94801CC82F0E94781C0E94801C182FF2
:103EE0000E94781CC1362CF0C75511363CF017558E
:103EF00008C0C033D4F3C0531136CCF710330CF0E4
:103F00001053C295C07FC10F8C2F992787FD9095C4
:103F1000CF911F910895CF93282F992787FD9095D2
:103F2000807F9070959587959595879595958795C0
:103F3000959587958A303CF0895AC22FCF70CA3048
:103F40003CF0C95A06C0805DC22FCF70CA30CCF792
:103F5000C05D0E94781C8C2F0E94781CCF91089520
:023F60008000DF
:0400000300003800C1
:00000001FF

View File

@ -1,162 +0,0 @@
:107000000C9434380C9451380C9451380C945138F9
:107010000C9451380C9451380C9451380C945138CC
:107020000C9451380C9451380C9451380C945138BC
:107030000C9451380C9451380C9451380C945138AC
:107040000C9451380C9451380C9451380C9451389C
:107050000C9451380C9451380C9451380C9451388C
:107060000C9451380C94513811241FBECFEFD8E046
:10707000DEBFCDBF11E0A0E0B1E0E4EEF9E702C071
:1070800005900D92A230B107D9F712E0A2E0B1E06D
:1070900001C01D92AC30B107E1F70E942D390C946C
:1070A000F03C0C940038282F992787FD9095807F1D
:1070B00090709595879595958795959587959595D4
:1070C00087958A30C4F0382F395A822F8F708A30D2
:1070D0007CF0982F995A8091C00085FFFCCF3093A7
:1070E000C6008091C00085FFFCCF9093C600089534
:1070F000982F905DF0CF382F305DE7CF982F80919B
:10710000C00085FFFCCF9093C6000895EF92FF92D8
:107110000F931F93EE24FF2487018091C00087FD09
:1071200017C00894E11CF11C011D111D81E0E81637
:1071300082E1F8068AE7080780E0180770F3E0911B
:107140000301F091040109958091C00087FFE9CF08
:107150008091C6001F910F91FF90EF9008951F93AB
:107160000E948638182F8091C00085FFFCCF1093B5
:10717000C6000E948638982F8091C00085FFFCCF02
:107180009093C600113664F01755913674F490331D
:107190000CF090531295107F892F810F1F91089545
:1071A00010339CF31053913694F397551295107F3A
:1071B000892F810F1F910895282F882351F090E087
:1071C0008091C00087FFFCCF8091C6009F5F92171F
:1071D000B8F308951F93182F0E948638803211F05B
:1071E0001F9108958091C00085FFFCCF84E18093BA
:1071F000C6008091C00085FFFCCF1093C60080912F
:10720000C00085FFFCCF80E18093C6001F910895E8
:107210000E948638803209F008958091C00085FF71
:10722000FCCF84E18093C6008091C00085FFFCCF35
:1072300080E18093C6000895882359F010920902D6
:1072400090E02D9A2D989F5F9817D8F3909309029C
:1072500008951092090283E0F3CF3F924F925F921C
:107260006F927F928F929F92AF92BF92CF92DF9256
:10727000EF92FF920F931F93CF93DF9300005698E6
:107280005E9A1092C50088E08093C40088E18093E4
:10729000C10086E08093C200259A579A5F9A21E048
:1072A00040E050E0CA010197F1F72F5F2131D1F79B
:1072B00080E1809309025F9883E00E941C398091ED
:1072C000C00085FFFCCF83E58093C6008091C0009D
:1072D00085FFFCCF85E48093C6008091C00085FFC8
:1072E000FCCF84E58093C6008091C00085FFFCCF71
:1072F00080E28093C6008091C00085FFFCCF82E4CD
:107300008093C6008091C00085FFFCCF84E5809308
:10731000C6008091C00085FFFCCF80E28093C6004C
:107320008091C00085FFFCCF80E58093C6008091EE
:10733000C00085FFFCCF81E48093C6008091C0002F
:1073400085FFFCCF87E48093C6008091C00085FF55
:10735000FCCF85E48093C6008091C00085FFFCCF00
:107360008DE48093C6008091C00085FFFCCF8FE440
:107370008093C6008091C00085FFFCCF84E4809399
:10738000C6008091C00085FFFCCF85E48093C600D5
:107390008091C00085FFFCCF80E28093C600809181
:1073A000C00085FFFCCF83E38093C6008091C000BE
:1073B00085FFFCCF80E28093C6008091C00085FFEE
:1073C000FCCF82E38093C6008091C00085FFFCCF94
:1073D00080E38093C6008091C00085FFFCCF80E3EE
:1073E0008093C6008091C00085FFFCCF80E380932E
:1073F000C6008091C00085FFFCCF80E28093C6006C
:107400008091C00085FFFCCF81E38093C60080910E
:10741000C00085FFFCCF8DE08093C6008091C00046
:1074200085FFFCCF83E58093C6008091C00085FF77
:10743000FCCF85E48093C6008091C00085FFFCCF1F
:1074400084E58093C6008091C00085FFFCCF80E278
:107450008093C6008091C00085FFFCCF82E48093BA
:10746000C6008091C00085FFFCCF84E58093C600F4
:107470008091C00085FFFCCF80E28093C6008091A0
:10748000C00085FFFCCF82E58093C6008091C000DC
:1074900085FFFCCF8FE48093C6008091C00085FFFC
:1074A000FCCF8CE48093C6008091C00085FFFCCFA8
:1074B00085E48093C6008091C00085FFFCCF80E208
:1074C0008093C6008091C00085FFFCCF80E380934D
:1074D000C6008091C00085FFFCCF80E28093C6008B
:1074E0008091C00085FFFCCF86E68093C600809126
:1074F000C00085FFFCCF80E28093C6008091C00071
:1075000085FFFCCF87E38093C6008091C00085FF94
:10751000FCCF84E68093C6008091C00085FFFCCF3D
:1075200080E38093C6008091C00085FFFCCF80E39C
:107530008093C6008091C00085FFFCCF8DE08093D2
:10754000C60034E1F32E2EE1E22E95E9D92E8FE02C
:10755000C82E00E1B02EAA24A39411E4912EB6E522
:107560008B2EA2E57A2EF0E26F2EE9E45E2E73E513
:10757000472E60E5362E0E948638803359F18133DC
:10758000C9F1803409F472C0813409F486C08234B0
:1075900021F1853409F474C08035E1F08135D1F0F2
:1075A0008235C1F0853509F497C0863509F486C067
:1075B000843609F4A0C0843709F40BC1853709F477
:1075C00075C18637C1F680E00E94EA380E9486388D
:1075D0008033A9F60E940839CECF90E08091C00098
:1075E00087FFFCCF8091C6009F5F9431B9F70E945E
:1075F0000839C1CF0E948638803209F0BCCF809113
:10760000C00085FFFCCFF092C6008091C00085FFCE
:10761000FCCF9092C6008091C00085FFFCCF809285
:10762000C6008091C00085FFFCCF7092C60080919B
:10763000C00085FFFCCF6092C6008091C00085FF2E
:10764000FCCF5092C6008091C00085FFFCCF4092D5
:10765000C6008091C00085FFFCCF3092C6008091AB
:10766000C00085FFFCCFB092C60085CF0E9486384F
:10767000863808F4AFCF0E9486380E9408397BCF45
:1076800090E08091C00087FFFCCF8091C6009F5F93
:107690009530B9F70E9408396ECF0E94863880383D
:1076A00031F1813809F48DC0823809F48EC08839EF
:1076B00009F089CF83E00E94EA385DCF90E08091A5
:1076C000C00087FFFCCF8091C6009F5F9430B9F760
:1076D00080E00E94EA387ACF0E94863880930501C4
:1076E0000E948638809306010E94083944CF82E0C8
:1076F0000E94EA3840CF0E948638809308020E9498
:1077000086388093070280910B028E7F80930B0254
:107710000E948638853429F480910B028160809321
:107720000B028091070290910802892B89F000E0FA
:1077300010E00E948638F801E95FFE4F80830F5FFA
:107740001F4F80910702909108020817190788F3CC
:107750000E948638803209F00ECF80910B0280FFA4
:10776000CFC0A0910702B09108021097E9F0609194
:10777000050170910601E7E0F1E09B01AD014E0FBC
:107780005F1FF999FECF32BD21BD819180BDFA9A6C
:10779000F99A2F5F3F4FE417F50799F76A0F7B1FA0
:1077A00070930601609305018091C00085FFFCCFB6
:1077B000F092C6008091C00085FFFCCFB092C60059
:1077C000DACE81E00E94EA38D6CE8FE00E94EA3815
:1077D000D2CE0E948638809308020E948638809319
:1077E00007020E948638853409F484C080910B0218
:1077F0008E7F80930B028091050190910601880F86
:10780000991F90930601809305010E94863880326B
:1078100009F0B1CE8091C00085FFFCCFF092C60088
:10782000A0910702B09108021097B9F180910B0264
:10783000182F1170082F0270E0910501F0910601D8
:107840009F012F5F3F4FB90140E050E01123B1F499
:10785000002339F494918091C00085FFFCCF909370
:10786000C6004F5F5F4FCB010196F9014A175B07D6
:1078700080F4BC012F5F3F4F112351F3F999FECFE4
:10788000F2BDE1BDF89A90B58091C00085FFFCCFB4
:10789000E6CF70930601609305018091C00085FDDD
:1078A000E2CE8091C00085FFF8CFDDCE0E94863801
:1078B000803209F060CE8091C00085FFFCCFF0924D
:1078C000C6008091C00085FFFCCFE092C600809189
:1078D000C00085FFFCCFD092C6008091C00085FF1C
:1078E000FCCFC092C6008091C00085FFFCCFB09253
:1078F000C60041CE80910B02816080930B0285CF40
:10790000809106018823880F880B8A2180930A02C0
:107910008091050190910601880F991F90930601AF
:10792000809305018091070280FF09C080910702C2
:107930009091080201969093080280930702F894B0
:10794000F999FECF1127E0910501F0910601C7E0FA
:10795000D1E08091070290910802103091F40091DB
:10796000570001700130D9F303E000935700E89508
:107970000091570001700130D9F301E100935700E5
:10798000E895099019900091570001700130D9F3E2
:1079900001E000935700E8951395103498F01127F3
:1079A0000091570001700130D9F305E000935700B2
:1079B000E8950091570001700130D9F301E100937F
:1079C0005700E8953296029709F0C7CF103011F0B2
:1079D0000296E5CF11248091C00085FFE5CEE8CE68
:0479E000F894FFCF49
:0279E400800021
:040000030000700089
:00000001FF

View File

@ -1,109 +0,0 @@
# 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 = ATmegaBOOT_168
# enter the parameters for the avrdude isp tool
ISPTOOL = stk500v2
ISPPORT = usb
ISPSPEED = -b 115200
MCU_TARGET = atmega168
LDSECTION = --section-start=.text=0x3800
# 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 0x0f (to
# lock it), but since the high two bits of the lock byte are
# unused, avrdude would get confused.
ISPFUSES = avrdude -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 = avrdude -c $(ISPTOOL) -p $(MCU_TARGET) -P $(ISPPORT) $(ISPSPEED) \
-U flash:w:$(PROGRAM)_$(TARGET).hex -U lock:w:0x0f: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 = -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:
atmega328_bt: TARGET = atmega328_bt
atmega328_bt: MCU_TARGET = atmega328p
atmega328_bt: AVR_FREQ = 16000000L
atmega328_bt: LDSECTION = --section-start=.text=0x7000
atmega328_bt: $(PROGRAM)_atmega328_bt.hex
atmega328_bt_isp: atmega328_bt
atmega328_bt_isp: TARGET = atmega328_bt
atmega328_bt_isp: MCU_TARGET = atmega328p
atmega328_bt_isp: HFUSE = D8
atmega328_bt_isp: LFUSE = FF
atmega328_bt_isp: EFUSE = 05
atmega328_bt_isp: isp
isp: $(TARGET)
$(ISPFUSES)
$(ISPFLASH)
isp-stk500: $(PROGRAM)_$(TARGET).hex
$(STK500-1)
$(STK500-2)
%.elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
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 -O ihex $< $@
%.srec: %.elf
$(OBJCOPY) -j .text -j .data -O srec $< $@
%.bin: %.elf
$(OBJCOPY) -j .text -j .data -O binary $< $@

View File

@ -1,710 +0,0 @@
/*
LUFA Library
Copyright (C) Dean Camera, 2011.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* Main source file for the CDC class bootloader. This file contains the complete bootloader logic.
*/
#define INCLUDE_FROM_CATERINA_C
#include "Caterina.h"
/** Contains the current baud rate and other settings of the first virtual serial port. This must be retained as some
* operating systems will not open the port unless the settings can be set successfully.
*/
static CDC_LineEncoding_t LineEncoding = { .BaudRateBPS = 0,
.CharFormat = CDC_LINEENCODING_OneStopBit,
.ParityType = CDC_PARITY_None,
.DataBits = 8 };
/** Current address counter. This stores the current address of the FLASH or EEPROM as set by the host,
* and is used when reading or writing to the AVRs memory (either FLASH or EEPROM depending on the issued
* command.)
*/
static uint32_t CurrAddress;
/** Flag to indicate if the bootloader should be running, or should exit and allow the application code to run
* via a watchdog reset. When cleared the bootloader will exit, starting the watchdog and entering an infinite
* loop until the AVR restarts and the application runs.
*/
static bool RunBootloader = true;
/* Pulse generation counters to keep track of the time remaining for each pulse type */
#define TX_RX_LED_PULSE_PERIOD 100
uint16_t TxLEDPulse = 0; // time remaining for Tx LED pulse
uint16_t RxLEDPulse = 0; // time remaining for Rx LED pulse
/* Bootloader timeout timer */
#define TIMEOUT_PERIOD 8000
uint16_t Timeout = 0;
uint16_t bootKey = 0x7777;
volatile uint16_t *const bootKeyPtr = (volatile uint16_t *)0x0A00;
void StartSketch(void)
{
cli();
/* Undo TIMER1 setup and clear the count before running the sketch */
TIMSK1 = 0;
TCCR1B = 0;
TCNT1H = 0; // 16-bit write to TCNT1 requires high byte be written first
TCNT1L = 0;
/* Relocate the interrupt vector table to the application section */
MCUCR = (1 << IVCE);
MCUCR = 0;
L_LED_OFF();
TX_LED_OFF();
RX_LED_OFF();
/* jump to beginning of application space */
__asm__ volatile("jmp 0x0000");
}
/* Breathing animation on L LED indicates bootloader is running */
uint16_t LLEDPulse;
void LEDPulse(void)
{
LLEDPulse++;
uint8_t p = LLEDPulse >> 8;
if (p > 127)
p = 254-p;
p += p;
if (((uint8_t)LLEDPulse) > p)
L_LED_OFF();
else
L_LED_ON();
}
/** Main program entry point. This routine configures the hardware required by the bootloader, then continuously
* runs the bootloader processing routine until instructed to soft-exit, or hard-reset via the watchdog to start
* the loaded application code.
*/
int main(void)
{
/* Watchdog may be configured with a 15 ms period so must disable it before doing anything else */
wdt_disable();
/* Check the reason for the reset and act accordingly */
uint8_t mcusr_state = MCUSR; // store the initial state of the Status register
MCUSR = 0; // clear all reset flags
// After a power-on reset skip the bootloader and jump straight to sketch
// if one exists.
if (mcusr_state & (1<<PORF) && pgm_read_word(0) != 0xFFFF) {
StartSketch();
}
uint16_t bootKeyPtrVal = *bootKeyPtr;
*bootKeyPtr = 0;
if ((mcusr_state & (1<<WDRF)) && (bootKeyPtrVal != bootKey) && (pgm_read_word(0) != 0xFFFF)) {
StartSketch();
}
/* Setup hardware required for the bootloader */
SetupHardware();
/* Enable global interrupts so that the USB stack can function */
sei();
Timeout = 0;
while (RunBootloader)
{
CDC_Task();
USB_USBTask();
/* Time out and start the sketch if one is present */
if (Timeout > TIMEOUT_PERIOD)
RunBootloader = false;
LEDPulse();
}
/* Disconnect from the host - USB interface will be reset later along with the AVR */
USB_Detach();
/* Jump to beginning of application space to run the sketch - do not reset */
StartSketch();
}
/** Configures all hardware required for the bootloader. */
void SetupHardware(void)
{
/* Disable watchdog if enabled by bootloader/fuses */
MCUSR &= ~(1 << WDRF);
wdt_disable();
/* Disable clock division */
clock_prescale_set(clock_div_1);
/* Relocate the interrupt vector table to the bootloader section */
MCUCR = (1 << IVCE);
MCUCR = (1 << IVSEL);
LED_SETUP();
CPU_PRESCALE(0);
L_LED_OFF();
TX_LED_OFF();
RX_LED_OFF();
/* Initialize TIMER1 to handle bootloader timeout and LED tasks.
* With 16 MHz clock and 1/64 prescaler, timer 1 is clocked at 250 kHz
* Our chosen compare match generates an interrupt every 1 ms.
* This interrupt is disabled selectively when doing memory reading, erasing,
* or writing since SPM has tight timing requirements.
*/
OCR1AH = 0;
OCR1AL = 250;
TIMSK1 = (1 << OCIE1A); // enable timer 1 output compare A match interrupt
TCCR1B = ((1 << CS11) | (1 << CS10)); // 1/64 prescaler on timer 1 input
/* Initialize USB Subsystem */
USB_Init();
}
//uint16_t ctr = 0;
ISR(TIMER1_COMPA_vect, ISR_BLOCK)
{
/* Reset counter */
TCNT1H = 0;
TCNT1L = 0;
/* Check whether the TX or RX LED one-shot period has elapsed. if so, turn off the LED */
if (TxLEDPulse && !(--TxLEDPulse))
TX_LED_OFF();
if (RxLEDPulse && !(--RxLEDPulse))
RX_LED_OFF();
if (pgm_read_word(0) != 0xFFFF)
Timeout++;
}
/** Event handler for the USB_ConfigurationChanged event. This configures the device's endpoints ready
* to relay data to and from the attached USB host.
*/
void EVENT_USB_Device_ConfigurationChanged(void)
{
/* Setup CDC Notification, Rx and Tx Endpoints */
Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT,
ENDPOINT_DIR_IN, CDC_NOTIFICATION_EPSIZE,
ENDPOINT_BANK_SINGLE);
Endpoint_ConfigureEndpoint(CDC_TX_EPNUM, EP_TYPE_BULK,
ENDPOINT_DIR_IN, CDC_TXRX_EPSIZE,
ENDPOINT_BANK_SINGLE);
Endpoint_ConfigureEndpoint(CDC_RX_EPNUM, EP_TYPE_BULK,
ENDPOINT_DIR_OUT, CDC_TXRX_EPSIZE,
ENDPOINT_BANK_SINGLE);
}
/** Event handler for the USB_ControlRequest event. This is used to catch and process control requests sent to
* the device from the USB host before passing along unhandled control requests to the library for processing
* internally.
*/
void EVENT_USB_Device_ControlRequest(void)
{
/* Ignore any requests that aren't directed to the CDC interface */
if ((USB_ControlRequest.bmRequestType & (CONTROL_REQTYPE_TYPE | CONTROL_REQTYPE_RECIPIENT)) !=
(REQTYPE_CLASS | REQREC_INTERFACE))
{
return;
}
/* Process CDC specific control requests */
switch (USB_ControlRequest.bRequest)
{
case CDC_REQ_GetLineEncoding:
if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
{
Endpoint_ClearSETUP();
/* Write the line coding data to the control endpoint */
Endpoint_Write_Control_Stream_LE(&LineEncoding, sizeof(CDC_LineEncoding_t));
Endpoint_ClearOUT();
}
break;
case CDC_REQ_SetLineEncoding:
if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
{
Endpoint_ClearSETUP();
/* Read the line coding data in from the host into the global struct */
Endpoint_Read_Control_Stream_LE(&LineEncoding, sizeof(CDC_LineEncoding_t));
Endpoint_ClearIN();
}
break;
}
}
#if !defined(NO_BLOCK_SUPPORT)
/** Reads or writes a block of EEPROM or FLASH memory to or from the appropriate CDC data endpoint, depending
* on the AVR910 protocol command issued.
*
* \param[in] Command Single character AVR910 protocol command indicating what memory operation to perform
*/
static void ReadWriteMemoryBlock(const uint8_t Command)
{
uint16_t BlockSize;
char MemoryType;
bool HighByte = false;
uint8_t LowByte = 0;
BlockSize = (FetchNextCommandByte() << 8);
BlockSize |= FetchNextCommandByte();
MemoryType = FetchNextCommandByte();
if ((MemoryType != 'E') && (MemoryType != 'F'))
{
/* Send error byte back to the host */
WriteNextResponseByte('?');
return;
}
/* Disable timer 1 interrupt - can't afford to process nonessential interrupts
* while doing SPM tasks */
TIMSK1 = 0;
/* Check if command is to read memory */
if (Command == 'g')
{
/* Re-enable RWW section */
boot_rww_enable();
while (BlockSize--)
{
if (MemoryType == 'F')
{
/* Read the next FLASH byte from the current FLASH page */
#if (FLASHEND > 0xFFFF)
WriteNextResponseByte(pgm_read_byte_far(CurrAddress | HighByte));
#else
WriteNextResponseByte(pgm_read_byte(CurrAddress | HighByte));
#endif
/* If both bytes in current word have been read, increment the address counter */
if (HighByte)
CurrAddress += 2;
HighByte = !HighByte;
}
else
{
/* Read the next EEPROM byte into the endpoint */
WriteNextResponseByte(eeprom_read_byte((uint8_t*)(intptr_t)(CurrAddress >> 1)));
/* Increment the address counter after use */
CurrAddress += 2;
}
}
}
else
{
uint32_t PageStartAddress = CurrAddress;
if (MemoryType == 'F')
{
boot_page_erase(PageStartAddress);
boot_spm_busy_wait();
}
while (BlockSize--)
{
if (MemoryType == 'F')
{
/* If both bytes in current word have been written, increment the address counter */
if (HighByte)
{
/* Write the next FLASH word to the current FLASH page */
boot_page_fill(CurrAddress, ((FetchNextCommandByte() << 8) | LowByte));
/* Increment the address counter after use */
CurrAddress += 2;
}
else
{
LowByte = FetchNextCommandByte();
}
HighByte = !HighByte;
}
else
{
/* Write the next EEPROM byte from the endpoint */
eeprom_write_byte((uint8_t*)((intptr_t)(CurrAddress >> 1)), FetchNextCommandByte());
/* Increment the address counter after use */
CurrAddress += 2;
}
}
/* If in FLASH programming mode, commit the page after writing */
if (MemoryType == 'F')
{
/* Commit the flash page to memory */
boot_page_write(PageStartAddress);
/* Wait until write operation has completed */
boot_spm_busy_wait();
}
/* Send response byte back to the host */
WriteNextResponseByte('\r');
}
/* Re-enable timer 1 interrupt disabled earlier in this routine */
TIMSK1 = (1 << OCIE1A);
}
#endif
/** Retrieves the next byte from the host in the CDC data OUT endpoint, and clears the endpoint bank if needed
* to allow reception of the next data packet from the host.
*
* \return Next received byte from the host in the CDC data OUT endpoint
*/
static uint8_t FetchNextCommandByte(void)
{
/* Select the OUT endpoint so that the next data byte can be read */
Endpoint_SelectEndpoint(CDC_RX_EPNUM);
/* If OUT endpoint empty, clear it and wait for the next packet from the host */
while (!(Endpoint_IsReadWriteAllowed()))
{
Endpoint_ClearOUT();
while (!(Endpoint_IsOUTReceived()))
{
if (USB_DeviceState == DEVICE_STATE_Unattached)
return 0;
}
}
/* Fetch the next byte from the OUT endpoint */
return Endpoint_Read_8();
}
/** Writes the next response byte to the CDC data IN endpoint, and sends the endpoint back if needed to free up the
* bank when full ready for the next byte in the packet to the host.
*
* \param[in] Response Next response byte to send to the host
*/
static void WriteNextResponseByte(const uint8_t Response)
{
/* Select the IN endpoint so that the next data byte can be written */
Endpoint_SelectEndpoint(CDC_TX_EPNUM);
/* If IN endpoint full, clear it and wait until ready for the next packet to the host */
if (!(Endpoint_IsReadWriteAllowed()))
{
Endpoint_ClearIN();
while (!(Endpoint_IsINReady()))
{
if (USB_DeviceState == DEVICE_STATE_Unattached)
return;
}
}
/* Write the next byte to the IN endpoint */
Endpoint_Write_8(Response);
TX_LED_ON();
TxLEDPulse = TX_RX_LED_PULSE_PERIOD;
}
#define STK_OK 0x10
#define STK_INSYNC 0x14 // ' '
#define CRC_EOP 0x20 // 'SPACE'
#define STK_GET_SYNC 0x30 // '0'
#define STK_GET_PARAMETER 0x41 // 'A'
#define STK_SET_DEVICE 0x42 // 'B'
#define STK_SET_DEVICE_EXT 0x45 // 'E'
#define STK_LOAD_ADDRESS 0x55 // 'U'
#define STK_UNIVERSAL 0x56 // 'V'
#define STK_PROG_PAGE 0x64 // 'd'
#define STK_READ_PAGE 0x74 // 't'
#define STK_READ_SIGN 0x75 // 'u'
/** Task to read in AVR910 commands from the CDC data OUT endpoint, process them, perform the required actions
* and send the appropriate response back to the host.
*/
void CDC_Task(void)
{
/* Select the OUT endpoint */
Endpoint_SelectEndpoint(CDC_RX_EPNUM);
/* Check if endpoint has a command in it sent from the host */
if (!(Endpoint_IsOUTReceived()))
return;
RX_LED_ON();
RxLEDPulse = TX_RX_LED_PULSE_PERIOD;
/* Read in the bootloader command (first byte sent from host) */
uint8_t Command = FetchNextCommandByte();
if (Command == 'E')
{
/* We nearly run out the bootloader timeout clock,
* leaving just a few hundred milliseconds so the
* bootloder has time to respond and service any
* subsequent requests */
Timeout = TIMEOUT_PERIOD - 500;
/* Re-enable RWW section - must be done here in case
* user has disabled verification on upload. */
boot_rww_enable_safe();
// Send confirmation byte back to the host
WriteNextResponseByte('\r');
}
else if (Command == 'T')
{
FetchNextCommandByte();
// Send confirmation byte back to the host
WriteNextResponseByte('\r');
}
else if ((Command == 'L') || (Command == 'P'))
{
// Send confirmation byte back to the host
WriteNextResponseByte('\r');
}
else if (Command == 't')
{
// Return ATMEGA128 part code - this is only to allow AVRProg to use the bootloader
WriteNextResponseByte(0x44);
WriteNextResponseByte(0x00);
}
else if (Command == 'a')
{
// Indicate auto-address increment is supported
WriteNextResponseByte('Y');
}
else if (Command == 'A')
{
// Set the current address to that given by the host
CurrAddress = (FetchNextCommandByte() << 9);
CurrAddress |= (FetchNextCommandByte() << 1);
// Send confirmation byte back to the host
WriteNextResponseByte('\r');
}
else if (Command == 'p')
{
// Indicate serial programmer back to the host
WriteNextResponseByte('S');
}
else if (Command == 'S')
{
// Write the 7-byte software identifier to the endpoint
for (uint8_t CurrByte = 0; CurrByte < 7; CurrByte++)
WriteNextResponseByte(SOFTWARE_IDENTIFIER[CurrByte]);
}
else if (Command == 'V')
{
WriteNextResponseByte('0' + BOOTLOADER_VERSION_MAJOR);
WriteNextResponseByte('0' + BOOTLOADER_VERSION_MINOR);
}
else if (Command == 's')
{
WriteNextResponseByte(AVR_SIGNATURE_3);
WriteNextResponseByte(AVR_SIGNATURE_2);
WriteNextResponseByte(AVR_SIGNATURE_1);
}
else if (Command == 'e')
{
// Clear the application section of flash
for (uint32_t CurrFlashAddress = 0; CurrFlashAddress < BOOT_START_ADDR; CurrFlashAddress += SPM_PAGESIZE)
{
boot_page_erase(CurrFlashAddress);
boot_spm_busy_wait();
boot_page_write(CurrFlashAddress);
boot_spm_busy_wait();
}
// Send confirmation byte back to the host
WriteNextResponseByte('\r');
}
#if !defined(NO_LOCK_BYTE_WRITE_SUPPORT)
else if (Command == 'l')
{
// Set the lock bits to those given by the host
boot_lock_bits_set(FetchNextCommandByte());
// Send confirmation byte back to the host
WriteNextResponseByte('\r');
}
#endif
else if (Command == 'r')
{
WriteNextResponseByte(boot_lock_fuse_bits_get(GET_LOCK_BITS));
}
else if (Command == 'F')
{
WriteNextResponseByte(boot_lock_fuse_bits_get(GET_LOW_FUSE_BITS));
}
else if (Command == 'N')
{
WriteNextResponseByte(boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS));
}
else if (Command == 'Q')
{
WriteNextResponseByte(boot_lock_fuse_bits_get(GET_EXTENDED_FUSE_BITS));
}
#if !defined(NO_BLOCK_SUPPORT)
else if (Command == 'b')
{
WriteNextResponseByte('Y');
// Send block size to the host
WriteNextResponseByte(SPM_PAGESIZE >> 8);
WriteNextResponseByte(SPM_PAGESIZE & 0xFF);
}
else if ((Command == 'B') || (Command == 'g'))
{
// Keep resetting the timeout counter if we're receiving self-programming instructions
Timeout = 0;
// Delegate the block write/read to a separate function for clarity
ReadWriteMemoryBlock(Command);
}
#endif
#if !defined(NO_FLASH_BYTE_SUPPORT)
else if (Command == 'C')
{
// Write the high byte to the current flash page
boot_page_fill(CurrAddress, FetchNextCommandByte());
// Send confirmation byte back to the host
WriteNextResponseByte('\r');
}
else if (Command == 'c')
{
// Write the low byte to the current flash page
boot_page_fill(CurrAddress | 0x01, FetchNextCommandByte());
// Increment the address
CurrAddress += 2;
// Send confirmation byte back to the host
WriteNextResponseByte('\r');
}
else if (Command == 'm')
{
// Commit the flash page to memory
boot_page_write(CurrAddress);
// Wait until write operation has completed
boot_spm_busy_wait();
// Send confirmation byte back to the host
WriteNextResponseByte('\r');
}
else if (Command == 'R')
{
#if (FLASHEND > 0xFFFF)
uint16_t ProgramWord = pgm_read_word_far(CurrAddress);
#else
uint16_t ProgramWord = pgm_read_word(CurrAddress);
#endif
WriteNextResponseByte(ProgramWord >> 8);
WriteNextResponseByte(ProgramWord & 0xFF);
}
#endif
#if !defined(NO_EEPROM_BYTE_SUPPORT)
else if (Command == 'D')
{
// Read the byte from the endpoint and write it to the EEPROM
eeprom_write_byte((uint8_t*)((intptr_t)(CurrAddress >> 1)), FetchNextCommandByte());
// Increment the address after use
CurrAddress += 2;
// Send confirmation byte back to the host
WriteNextResponseByte('\r');
}
else if (Command == 'd')
{
// Read the EEPROM byte and write it to the endpoint
WriteNextResponseByte(eeprom_read_byte((uint8_t*)((intptr_t)(CurrAddress >> 1))));
// Increment the address after use
CurrAddress += 2;
}
#endif
else if (Command != 27)
{
// Unknown (non-sync) command, return fail code
WriteNextResponseByte('?');
}
/* Select the IN endpoint */
Endpoint_SelectEndpoint(CDC_TX_EPNUM);
/* Remember if the endpoint is completely full before clearing it */
bool IsEndpointFull = !(Endpoint_IsReadWriteAllowed());
/* Send the endpoint data to the host */
Endpoint_ClearIN();
/* If a full endpoint's worth of data was sent, we need to send an empty packet afterwards to signal end of transfer */
if (IsEndpointFull)
{
while (!(Endpoint_IsINReady()))
{
if (USB_DeviceState == DEVICE_STATE_Unattached)
return;
}
Endpoint_ClearIN();
}
/* Wait until the data has been sent to the host */
while (!(Endpoint_IsINReady()))
{
if (USB_DeviceState == DEVICE_STATE_Unattached)
return;
}
/* Select the OUT endpoint */
Endpoint_SelectEndpoint(CDC_RX_EPNUM);
/* Acknowledge the command from the host */
Endpoint_ClearOUT();
}

View File

@ -1,99 +0,0 @@
/*
LUFA Library
Copyright (C) Dean Camera, 2011.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* Header file for BootloaderCDC.c.
*/
#ifndef _CDC_H_
#define _CDC_H_
/* Includes: */
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/boot.h>
#include <avr/eeprom.h>
#include <avr/power.h>
#include <avr/interrupt.h>
#include <stdbool.h>
#include "Descriptors.h"
#include <LUFA/Drivers/USB/USB.h>
/* Macros: */
/** Version major of the CDC bootloader. */
#define BOOTLOADER_VERSION_MAJOR 0x01
/** Version minor of the CDC bootloader. */
#define BOOTLOADER_VERSION_MINOR 0x00
/** Hardware version major of the CDC bootloader. */
#define BOOTLOADER_HWVERSION_MAJOR 0x01
/** Hardware version minor of the CDC bootloader. */
#define BOOTLOADER_HWVERSION_MINOR 0x00
/** Eight character bootloader firmware identifier reported to the host when requested */
#define SOFTWARE_IDENTIFIER "CATERINA"
#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
#define LED_SETUP() DDRC |= (1<<7); DDRB |= (1<<0); DDRD |= (1<<5);
#define L_LED_OFF() PORTC &= ~(1<<7)
#define L_LED_ON() PORTC |= (1<<7)
#define L_LED_TOGGLE() PORTC ^= (1<<7)
#define TX_LED_OFF() PORTD |= (1<<5)
#define TX_LED_ON() PORTD &= ~(1<<5)
#define RX_LED_OFF() PORTB |= (1<<0)
#define RX_LED_ON() PORTB &= ~(1<<0)
/* Type Defines: */
/** Type define for a non-returning pointer to the start of the loaded application in flash memory. */
typedef void (*AppPtr_t)(void) ATTR_NO_RETURN;
/* Function Prototypes: */
void StartSketch(void);
void LEDPulse(void);
void CDC_Task(void);
void SetupHardware(void);
void EVENT_USB_Device_ConfigurationChanged(void);
#if defined(INCLUDE_FROM_CATERINA_C) || defined(__DOXYGEN__)
#if !defined(NO_BLOCK_SUPPORT)
static void ReadWriteMemoryBlock(const uint8_t Command);
#endif
static uint8_t FetchNextCommandByte(void);
static void WriteNextResponseByte(const uint8_t Response);
#endif
#endif

View File

@ -1,256 +0,0 @@
:1070000055C000006EC000006CC000006AC00000E7
:1070100068C0000066C0000064C0000062C00000DC
:1070200060C000005EC00000F1C400005AC0000053
:1070300058C0000056C0000054C0000052C00000FC
:1070400050C0000078C000004CC000004AC00000E2
:1070500048C0000046C0000044C0000042C000001C
:1070600040C000003EC000003CC000003AC000002C
:1070700038C0000036C0000034C0000032C000003C
:1070800030C000002EC000002CC000002AC000004C
:1070900028C0000026C0000024C0000022C000005C
:1070A00020C000001EC000001CC0000011241FBE34
:1070B000CFEFDAE0DEBFCDBF11E0A0E0B1E0E0E36A
:1070C000FFE702C005900D92A83AB107D9F711E089
:1070D000A8EAB1E001C01D92AE3BB107E1F78FD342
:1070E00025C78ECFF89410926F00109281001092F5
:1070F00085001092840081E085BF15BE47985D9A97
:10710000289A0C94000008952091B2013091B301A7
:107110002F5F3F4F3093B3012093B201932F37FF7E
:1071200003C08EEF831B982F990F921710F4479886
:107130000895479A08951F920F920FB60F92112447
:107140002F938F939F93EF93FF931092850010924C
:1071500084008091A8019091A901009741F00197C6
:107160009093A9018093A801892B09F45D9A8091DD
:10717000AA019091AB01009741F001979093AB0168
:107180008093AA01892B09F4289AE0E0F0E0859128
:1071900094918F5F9F4F49F08091AC019091AD0128
:1071A00001969093AD018093AC01FF91EF919F9177
:1071B0008F912F910F900FBE0F901F90189584E024
:1071C0008093E9000DC08091E8008B778093E80000
:1071D00003C08EB3882351F08091E80082FFF9CF7D
:1071E0008091E80085FFEFCF8091F1000895982FFE
:1071F00083E08093E9008091E80085FD0DC08091D7
:10720000E8008E778093E80003C08EB3882369F08E
:107210008091E80080FFF9CF9093F1005D9884E6BB
:1072200090E09093A9018093A80108954F925F92F6
:107230006F927F928F929F92AF92BF92CF92DF9286
:10724000EF92FF920F931F93CF93DF9384E080938D
:10725000E9008091E80082FF57C2289884E690E018
:107260009093AB018093AA01AADF182F853481F493
:107270008CE49DE19093AD018093AC0107B600FCD6
:10728000FDCFF999FECF81E180935700E89503C0C7
:10729000843519F494DF8DE00DC28C34E1F3803530
:1072A000D1F3843721F484E4A2DF80E003C2813685
:1072B00011F489E5FFC18134B1F481DF182F7FDF3C
:1072C00090E0880F991FAA2797FDA095BA2F312F1C
:1072D000330F20E0442737FD4095542F822B932B0A
:1072E000A42BB52BB8C1803711F483E5E3C18335F6
:1072F00049F4C0E0D1E089917ADF21E0C730D207BC
:10730000D1F7D9C1863521F481E371DF80E3D2C1A1
:10731000833731F487E86BDF85E969DF8EE1CAC125
:107320008536B9F4E0E0F0E093E085E09093570013
:10733000E89507B600FCFDCF80935700E89507B6A7
:1073400000FCFDCFE058FF4FA0E7E030FA0771F7EF
:10735000A2CF823739F4E1E0F0E089E08093570072
:107360008491A8C1863439F4E0E0F0E089E08093AC
:10737000570084919FC18E3439F4E3E0F0E089E056
:1073800080935700849196C1813539F4E2E0F0E0B2
:1073900089E08093570084918DC1823631F489E56C
:1073A00026DF80E024DF80E885C1823419F087364B
:1073B00009F0E5C01092AD011092AC0100DF082F7A
:1073C000FEDEF82EFCDE682E8554823008F071C196
:1073D000902F80E0CF2DD0E0C82BD92B10926F00DA
:1073E000173609F04BC081E180935700E895DD2402
:1073F000CC24C3943FC0E090AE01F090AF01009167
:10740000B0011091B101B6E46B16D9F4ED2DF0E0A6
:10741000EE29FF29E4918E2FEADEDD2081F082E063
:1074200090E0A0E0B0E0E80EF91E0A1F1B1FE092FA
:10743000AE01F092AF010093B0011093B101DC24D2
:1074400018C0D801C701B695A7959795879558D5C7
:10745000CEDE82E090E0A0E0B0E0E80EF91E0A1F68
:107460001B1FE092AE01F092AF010093B0011093A8
:10747000B1012197209709F0BECF7DC08090AE0169
:107480009090AF01A090B001B090B10196E4691660
:1074900009F05DC083E0F40180935700E89507B6DA
:1074A00000FCFDCF54C0F6E46F1661F5772031F192
:1074B000E090AE01F090AF010091B0011091B101E8
:1074C0007EDED82ECC24852D90E08C299D29F701D5
:1074D0000C0140925700E895112482E090E0A0E072
:1074E000B0E0E80EF91E0A1F1B1FE092AE01F092F9
:1074F000AF010093B0011093B10102C060DE582EBD
:10750000742423C0E090AE01F090AF010091B0016F
:107510001091B10116950795F794E79450DE682F06
:10752000C701F6D48091AE019091AF01A091B00156
:10753000B091B1010296A11DB11D8093AE0190934F
:10754000AF01A093B001B093B101219704C05524BD
:10755000772444244394209709F0A5CF96E4691634
:1075600041F485E0F40180935700E89507B600FCEC
:10757000FDCF8DE03CDE82E080936F009CC08334C1
:1075800071F40091AE011091AF0119DE90E021E09D
:10759000F8010C0120935700E89511247CCE833626
:1075A00019F5E090AE01F090AF010091B00110919B
:1075B000B10105DEF701E16090E021E00C012093CC
:1075C0005700E895112482E090E0A0E0B0E0E80EDA
:1075D000F91E0A1F1B1FE092AE01F092AF0100934B
:1075E000B0011093B10157CE8D3661F4E091AE0138
:1075F000F091AF0185E080935700E89507B600FC55
:10760000FDCF49CE823551F4E091AE01F091AF014A
:1076100005911491812FEBDD802F4CC0843421F52E
:10762000E090AE01F090AF010091B0011091B10176
:1076300016950795F794E794C2DD682FC70168D4C3
:107640008091AE019091AF01A091B001B091B101D4
:107650000296A11DB11D8093AE019093AF01A0933E
:10766000B001B093B10117CE843609F5E090AE01B8
:10767000F090AF010091B0011091B101D801C701A4
:10768000B695A795979587953BD4B1DD82E090E0BC
:10769000A0E0B0E0E80EF91E0A1F1B1FE092AE0149
:1076A000F092AF010093B0011093B10104C08B318F
:1076B00011F08FE39CDD83E08093E9009091E80076
:1076C0008091E8008E778093E80095FF04C010C099
:1076D0008EB38823C9F08091E80080FFF9CF8091B4
:1076E000E8008E778093E80003C08EB3882361F0B2
:1076F0008091E80080FFF9CF84E08093E9008091D9
:10770000E8008B778093E800DF91CF911F910F9174
:10771000FF90EF90DF90CF90BF90AF909F908F90B1
:107720007F906F905F904F9008959091B601892F50
:107730008F77813249F58091B7018032A1F0813293
:1077400019F5913A09F58091E800877F8093E80068
:107750008DE091E067E070E00AD28091E8008B77DD
:107760008093E8000895913279F48091E800877F52
:107770008093E8008DE091E067E070E05CD280915A
:10778000E8008E778093E800089582E061EC42E0A3
:10779000B4D083E061E842E1B0D084E060E842E147
:1077A000ACC084B7877F84BF88E10FB6F89480931C
:1077B0006000109260000FBE20E880E090E00FB6FD
:1077C000F89420936100809361000FBE81E085BF33
:1077D00092E095BF3F9A209A559AE1E6F0E0208327
:1077E000108247985D9A289A109289008AEF8093B8
:1077F000880090936F0083E080938100EFC01F9317
:1078000088E10FB6F89480936000109260000FBE7C
:1078100084B714BE182F10FF08C0E0E0F0E0859197
:1078200094918F5F9F4F09F05DDC2091000A3091A9
:10783000010A1092010A1092000A13FF0FC08091F2
:10784000090190910A012817390741F0E0E0F0E0C2
:10785000859194918F5F9F4F09F044DCA2DF78946B
:107860001092AD011092AC010CC0E0DC37D38091D6
:10787000AC019091AD0181549F4110F01092140120
:1078800043DC80911401882381F78091E0008160BE
:107890008093E00027DC80E090E01F910895FA01DA
:1078A000923049F0933061F09130F9F485E191E044
:1078B00022E130E01EC087E291E02EE330E019C003
:1078C000882329F485E691E024E030E012C081307D
:1078D00029F489E691E022E230E00BC0823029F4FD
:1078E0008DE891E028E130E004C080E090E020E005
:1078F00030E091838083C90108958093E9008091ED
:10790000EB0081608093EB001092ED006093EC003F
:107910004093ED008091EE00881F8827881F08950E
:107920008091B60188238CF403C08EB38823B1F014
:107930008091E80082FFF9CF8091E8008B778093F7
:10794000E80008958EB3882349F08091E80080FF15
:10795000F9CF8091E8008E778093E8000895EF9248
:10796000FF920F931F9345D04CD008ED10E0F80123
:1079700080818F77808380818068808380818F7D04
:10798000808319BC1EBA1092B40180EEE82EF12C4F
:10799000F70180818B7F8083F80180818160808303
:1079A00080E060E042E0A9DFE1EEF0E080818E7FE0
:1079B0008083E2EEF0E08081816080838081886056
:1079C0008083F70180818E7F8083F80180818061D0
:1079D00080831F910F91FF90EF900895E7EDF0E005
:1079E0008081816080838AE482BF81E08093B501D9
:1079F000B6CFE8EDF0E080818E7F80831092E200C8
:107A000008951092DA001092E10008951F920F92EB
:107A10000FB60F9211242F933F934F935F936F9361
:107A20007F938F939F93AF93BF93EF93FF93809137
:107A3000DA0080FF1BC08091D80080FF17C08091C2
:107A4000DA008E7F8093DA008091D90080FF0BC02E
:107A500080E189BD82E189BD09B400FEFDCF81E0EE
:107A60008EBB3BD203C019BC1EBA37D28091E10055
:107A700080FF17C08091E20080FF13C08091E20078
:107A80008E7F8093E2008091E20080618093E2002B
:107A90008091D80080628093D80019BC85E08EBBAD
:107AA0001CD28091E10084FF2CC08091E20084FF11
:107AB00028C080E189BD82E189BD09B400FEFDCF07
:107AC0008091D8008F7D8093D8008091E1008F7ED7
:107AD0008093E1008091E2008F7E8093E2008091AC
:107AE000E20081608093E2008091B401882331F448
:107AF0008091E30087FD02C081E001C084E08EBB7D
:107B0000ECD18091E10083FF21C08091E20083FFEE
:107B10001DC08091E100877F8093E10082E08EBBF1
:107B20001092B4018091E1008E7F8093E1008091FA
:107B3000E2008E7F8093E2008091E200806180937A
:107B4000E20080E060E042E0D8DEC7D1FF91EF9133
:107B5000BF91AF919F918F917F916F915F914F9165
:107B60003F912F910F900FBE0F901F9018959C0181
:107B70004091BC015091BD014617570718F4F90117
:107B800090E044C06115710511F0AB01F8CF809110
:107B9000E8008E778093E80040E050E0F0CF8EB3AD
:107BA000882309F444C0853009F443C08091E8007B
:107BB00083FF02C081E008958091E80082FD31C01A
:107BC0008091E80080FF22C08091F3009091F20044
:107BD000782F60E0292F30E0262B372B07C08191CA
:107BE0008093F100415050402F5F3F4F41155105A8
:107BF00019F02830310598F390E02830310509F468
:107C000091E08091E8008E778093E800411551055E
:107C100031F6992321F605C08EB3882341F08530D3
:107C200041F08091E80082FFF7CF80E0089582E084
:107C3000089583E008959C016115710529F48091F0
:107C4000E8008B778093E800F90126C08EB3882383
:107C500091F1853091F18091E80083FF02C081E0CD
:107C600008958091E80082FFF1CF06C08091F10075
:107C700081936150704059F02091F3008091F2009F
:107C8000322F20E090E0822B932B892B79F7809183
:107C9000E8008B778093E80061157105B9F605C09F
:107CA0008EB3882341F0853041F08091E80080FF59
:107CB000F7CF80E0089582E0089583E008950F9360
:107CC0001F93DF93CF9300D0CDB7DEB7E6EBF1E0A3
:107CD0008091F100819381E0EE3BF807C9F725DD43
:107CE0008091E80083FFE4C08091B6019091B701D4
:107CF000953009F46DC0963040F4913081F19130A7
:107D000070F0933009F0D4C02AC0983009F4A3C0B1
:107D1000993009F4B2C0963009F0CAC07CC08038EE
:107D200009F4C6C0823809F0C3C08091BA018770D7
:107D30008093E9008091EB001092E9002091E80027
:107D4000277F2093E80090E025E0969587952A9577
:107D5000E1F781708093F1001092F10087C08823D1
:107D600019F0823009F0A4C08F71823009F0A0C0F0
:107D70008091B801882331F52091BA01277009F468
:107D800097C02093E9008091EB0080FF1BC09330E7
:107D900021F48091EB00806213C08091EB00806140
:107DA0008093EB0081E090E002C0880F991F2A9534
:107DB000E2F78093EA001092EA008091EB0088607D
:107DC0008093EB001092E9008091E800877F51C01A
:107DD000882309F06DC01091B8011F770FB7F89490
:107DE0008091E800877F8093E8009ADD8091E80029
:107DF00080FFFCCF8091E3008078812B8093E300AB
:107E000080688093E300112311F482E001C083E0D5
:107E10008EBB0FBF4DC08058823008F049C08091A2
:107E2000B8019091B9016091BA01AE014F5F5F4F07
:107E300036DDBC01009709F43BC08091E800877FE4
:107E40008093E80089819A8192DE8091E8008B77A7
:107E50008093E8002DC0803859F58091E800877F35
:107E60008093E8008091B4018093F1008091E80054
:107E70008E778093E80054DD1BC08823C9F490916D
:107E8000B8019230A8F48091E800877F8093E800E1
:107E90009093B40145DD8091B401882331F4809141
:107EA000E30087FD02C081E001C084E08EBB6DDC91
:107EB0008091E80083FF0AC08091EB00806280938C
:107EC000EB008091E800877F8093E8000F900F908F
:107ED000CF91DF911F910F91089508951F938EB355
:107EE000882361F01091E9001092E9008091E80088
:107EF00083FF01C0E4DE17701093E9001F9108951D
:107F0000F999FECF92BD81BDF89A992780B5089561
:107F1000262FF999FECF1FBA92BD81BD20BD0FB6A5
:107F2000F894FA9AF99A0FBE01960895F894FFCF43
:107F30004341544552494E41007777000A00000002
:107F40000000000801120110010200000841230195
:107F50000701000201000109023E00020100803217
:107F6000090400000102020100052400100104249C
:107F700002040524060001070582030800FF090426
:107F80000100020A000000070504021000010705B5
:107F900083021000010403090422034100720064FB
:107FA00000750069006E006F0020004C0065006FD6
:107FB000006E006100720064006F00000018034151
:107FC0000072006400750069006E006F0020004CB4
:087FD000004C0043000000001A
:040000030000700089
:00000001FF

View File

@ -1,265 +0,0 @@
/*
LUFA Library
Copyright (C) Dean Camera, 2011.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* USB Device Descriptors, for library use when in USB device mode. Descriptors are special
* computer-readable structures which the host requests upon device enumeration, to determine
* the device's capabilities and functions.
*/
#include "Descriptors.h"
/** Device descriptor structure. This descriptor, located in SRAM memory, describes the overall
* device characteristics, including the supported USB version, control endpoint size and the
* number of device configurations. The descriptor is read out by the USB host when the enumeration
* process begins.
*/
const USB_Descriptor_Device_t DeviceDescriptor =
{
.Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
.USBSpecification = VERSION_BCD(01.10),
.Class = CDC_CSCP_CDCClass,
.SubClass = CDC_CSCP_NoSpecificSubclass,
.Protocol = CDC_CSCP_NoSpecificProtocol,
.Endpoint0Size = FIXED_CONTROL_ENDPOINT_SIZE,
.VendorID = 0x2341,
.ProductID = 0x0701,
.ReleaseNumber = VERSION_BCD(00.01),
.ManufacturerStrIndex = 0x02,
.ProductStrIndex = 0x01,
.SerialNumStrIndex = NO_DESCRIPTOR,
.NumberOfConfigurations = FIXED_NUM_CONFIGURATIONS
};
/** Configuration descriptor structure. This descriptor, located in SRAM memory, describes the usage
* of the device in one of its supported configurations, including information about any device interfaces
* and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
* a configuration so that the host may correctly communicate with the USB device.
*/
const USB_Descriptor_Configuration_t ConfigurationDescriptor =
{
.Config =
{
.Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
.TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
.TotalInterfaces = 2,
.ConfigurationNumber = 1,
.ConfigurationStrIndex = NO_DESCRIPTOR,
.ConfigAttributes = USB_CONFIG_ATTR_BUSPOWERED,
.MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
},
.CDC_CCI_Interface =
{
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
.InterfaceNumber = 0,
.AlternateSetting = 0,
.TotalEndpoints = 1,
.Class = CDC_CSCP_CDCClass,
.SubClass = CDC_CSCP_ACMSubclass,
.Protocol = CDC_CSCP_ATCommandProtocol,
.InterfaceStrIndex = NO_DESCRIPTOR
},
.CDC_Functional_Header =
{
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = DTYPE_CSInterface},
.Subtype = 0x00,
.CDCSpecification = VERSION_BCD(01.10),
},
.CDC_Functional_ACM =
{
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = DTYPE_CSInterface},
.Subtype = 0x02,
.Capabilities = 0x04,
},
.CDC_Functional_Union =
{
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = DTYPE_CSInterface},
.Subtype = 0x06,
.MasterInterfaceNumber = 0,
.SlaveInterfaceNumber = 1,
},
.CDC_NotificationEndpoint =
{
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
.EndpointAddress = (ENDPOINT_DIR_IN | CDC_NOTIFICATION_EPNUM),
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = CDC_NOTIFICATION_EPSIZE,
.PollingIntervalMS = 0xFF
},
.CDC_DCI_Interface =
{
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
.InterfaceNumber = 1,
.AlternateSetting = 0,
.TotalEndpoints = 2,
.Class = CDC_CSCP_CDCDataClass,
.SubClass = CDC_CSCP_NoDataSubclass,
.Protocol = CDC_CSCP_NoDataProtocol,
.InterfaceStrIndex = NO_DESCRIPTOR
},
.CDC_DataOutEndpoint =
{
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
.EndpointAddress = (ENDPOINT_DIR_OUT | CDC_RX_EPNUM),
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = CDC_TXRX_EPSIZE,
.PollingIntervalMS = 0x01
},
.CDC_DataInEndpoint =
{
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
.EndpointAddress = (ENDPOINT_DIR_IN | CDC_TX_EPNUM),
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = CDC_TXRX_EPSIZE,
.PollingIntervalMS = 0x01
}
};
/** Language descriptor structure. This descriptor, located in SRAM memory, is returned when the host requests
* the string descriptor with index 0 (the first index). It is actually an array of 16-bit integers, which indicate
* via the language ID table available at USB.org what languages the device supports for its string descriptors.
*/
const USB_Descriptor_String_t LanguageString =
{
.Header = {.Size = USB_STRING_LEN(1), .Type = DTYPE_String},
.UnicodeString = {LANGUAGE_ID_ENG}
};
/** Product descriptor string. This is a Unicode string containing the product's details in human readable form,
* and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
* Descriptor.
*/
const USB_Descriptor_String_t ProductString =
{
.Header = {.Size = USB_STRING_LEN(16), .Type = DTYPE_String},
.UnicodeString = L"Arduino Leonardo"
};
/*
const USB_Descriptor_String_t SerialNumString =
{
.Header = {.Size = USB_STRING_LEN(12), .Type = DTYPE_String},
.UnicodeString = L"000000001452"
};
*/
const USB_Descriptor_String_t ManufNameString =
{
.Header = {.Size = USB_STRING_LEN(11), .Type = DTYPE_String},
.UnicodeString = L"Arduino LLC"
};
/** This function is called by the library when in device mode, and must be overridden (see LUFA library "USB Descriptors"
* documentation) by the application code so that the address and size of a requested descriptor can be given
* to the USB library. When the device receives a Get Descriptor request on the control endpoint, this function
* is called so that the descriptor details can be passed back and the appropriate descriptor sent back to the
* USB host.
*/
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t wIndex,
const void** const DescriptorAddress)
{
const uint8_t DescriptorType = (wValue >> 8);
const uint8_t DescriptorNumber = (wValue & 0xFF);
const void* Address = NULL;
uint16_t Size = NO_DESCRIPTOR;
switch (DescriptorType)
{
case DTYPE_Device:
Address = &DeviceDescriptor;
Size = sizeof(USB_Descriptor_Device_t);
break;
case DTYPE_Configuration:
Address = &ConfigurationDescriptor;
Size = sizeof(USB_Descriptor_Configuration_t);
break;
case DTYPE_String:
if (!(DescriptorNumber))
{
Address = &LanguageString;
Size = LanguageString.Header.Size;
}
else if (DescriptorNumber == DeviceDescriptor.ProductStrIndex)
{
Address = &ProductString;
Size = ProductString.Header.Size;
// } else if (DescriptorNumber == DeviceDescriptor.SerialNumStrIndex)
// {
// Address = &SerialNumString;
// Size = SerialNumString.Header.Size;
} else if (DescriptorNumber == DeviceDescriptor.ManufacturerStrIndex)
{
Address = &ManufNameString;
Size = ManufNameString.Header.Size;
}
break;
}
*DescriptorAddress = Address;
return Size;
}

View File

@ -1,139 +0,0 @@
/*
LUFA Library
Copyright (C) Dean Camera, 2011.
dean [at] fourwalledcubicle [dot] com
www.lufa-lib.org
*/
/*
Copyright 2011 Dean Camera (dean [at] fourwalledcubicle [dot] com)
Permission to use, copy, modify, distribute, and sell this
software and its documentation for any purpose is hereby granted
without fee, provided that the above copyright notice appear in
all copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the name of the author not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
The author disclaim all warranties with regard to this
software, including all implied warranties of merchantability
and fitness. In no event shall the author be liable for any
special, indirect or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether
in an action of contract, negligence or other tortious action,
arising out of or in connection with the use or performance of
this software.
*/
/** \file
*
* Header file for Descriptors.c.
*/
#ifndef _DESCRIPTORS_H_
#define _DESCRIPTORS_H_
/* Includes: */
#include <LUFA/Drivers/USB/USB.h>
/* Macros: */
#if defined(__AVR_AT90USB1287__)
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x97
#define AVR_SIGNATURE_3 0x82
#elif defined(__AVR_AT90USB647__)
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x96
#define AVR_SIGNATURE_3 0x82
#elif defined(__AVR_AT90USB1286__)
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x97
#define AVR_SIGNATURE_3 0x82
#elif defined(__AVR_AT90USB646__)
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x96
#define AVR_SIGNATURE_3 0x82
#elif defined(__AVR_ATmega32U6__)
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x95
#define AVR_SIGNATURE_3 0x88
#elif defined(__AVR_ATmega32U4__)
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x95
#define AVR_SIGNATURE_3 0x87
#elif defined(__AVR_ATmega16U4__)
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x94
#define AVR_SIGNATURE_3 0x88
#elif defined(__AVR_ATmega32U2__)
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x95
#define AVR_SIGNATURE_3 0x8A
#elif defined(__AVR_ATmega16U2__)
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x94
#define AVR_SIGNATURE_3 0x89
#elif defined(__AVR_AT90USB162__)
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x94
#define AVR_SIGNATURE_3 0x82
#elif defined(__AVR_ATmega8U2__)
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x93
#define AVR_SIGNATURE_3 0x89
#elif defined(__AVR_AT90USB82__)
#define AVR_SIGNATURE_1 0x1E
#define AVR_SIGNATURE_2 0x94
#define AVR_SIGNATURE_3 0x82
#else
#error The selected AVR part is not currently supported by this bootloader.
#endif
/** Endpoint number for the CDC control interface event notification endpoint. */
#define CDC_NOTIFICATION_EPNUM 2
/** Endpoint number for the CDC data interface TX (data IN) endpoint. */
#define CDC_TX_EPNUM 3
/** Endpoint number for the CDC data interface RX (data OUT) endpoint. */
#define CDC_RX_EPNUM 4
/** Size of the CDC data interface TX and RX data endpoint banks, in bytes. */
#define CDC_TXRX_EPSIZE 16
/** Size of the CDC control interface notification endpoint bank, in bytes. */
#define CDC_NOTIFICATION_EPSIZE 8
/* Type Defines: */
/** Type define for the device configuration descriptor structure. This must be defined in the
* application code, as the configuration descriptor contains several sub-descriptors which
* vary between devices, and which describe the device's usage to the host.
*/
typedef struct
{
USB_Descriptor_Configuration_Header_t Config;
// CDC Control Interface
USB_Descriptor_Interface_t CDC_CCI_Interface;
USB_CDC_Descriptor_FunctionalHeader_t CDC_Functional_Header;
USB_CDC_Descriptor_FunctionalACM_t CDC_Functional_ACM;
USB_CDC_Descriptor_FunctionalUnion_t CDC_Functional_Union;
USB_Descriptor_Endpoint_t CDC_NotificationEndpoint;
// CDC Data Interface
USB_Descriptor_Interface_t CDC_DCI_Interface;
USB_Descriptor_Endpoint_t CDC_DataOutEndpoint;
USB_Descriptor_Endpoint_t CDC_DataInEndpoint;
} USB_Descriptor_Configuration_t;
/* Function Prototypes: */
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint8_t wIndex,
const void** const DescriptorAddress)
ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(3);
#endif

View File

@ -1,717 +0,0 @@
# Hey Emacs, this is a -*- makefile -*-
#----------------------------------------------------------------------------
# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al.
# >> Modified for use with the LUFA project. <<
#
# Released to the Public Domain
#
# Additional material for this makefile was written by:
# Peter Fleury
# Tim Henigan
# Colin O'Flynn
# Reiner Patommel
# Markus Pfaff
# Sander Pool
# Frederik Rouleau
# Carlos Lamas
# Dean Camera
# Opendous Inc.
# Denver Gingerich
#
#----------------------------------------------------------------------------
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make coff = Convert ELF to AVR COFF.
#
# make extcoff = Convert ELF to AVR Extended COFF.
#
# make program = Download the hex file to the device, using avrdude.
# Please customize the avrdude settings below first!
#
# make doxygen = Generate DoxyGen documentation for the project (must have
# DoxyGen installed)
#
# make debug = Start either simulavr or avarice as specified for debugging,
# with avr-gdb or avr-insight as the front end for debugging.
#
# make filename.s = Just compile filename.c into the assembler code only.
#
# make filename.i = Create a preprocessed source file for use in submitting
# bug reports to the GCC project.
#
# To rebuild project do "make clean" then "make all".
#----------------------------------------------------------------------------
# MCU name
MCU = atmega32u4
# Target architecture (see library "Board Types" documentation).
ARCH = AVR8
# Target board (see library "Board Types" documentation, NONE for projects not requiring
# LUFA board drivers). If USER is selected, put custom board drivers in a directory called
# "Board" inside the application directory.
BOARD = USER
# Processor frequency.
# This will define a symbol, F_CPU, in all source code files equal to the
# processor frequency in Hz. You can then use this symbol in your source code to
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
# automatically to create a 32-bit value in your source code.
#
# This will be an integer division of F_USB below, as it is sourced by
# F_USB after it has run through any CPU prescalers. Note that this value
# does not *change* the processor frequency - it should merely be updated to
# reflect the processor speed set externally so that the code can use accurate
# software delays.
F_CPU = 16000000
# Input clock frequency.
# This will define a symbol, F_USB, in all source code files equal to the
# input clock frequency (before any prescaling is performed) in Hz. This value may
# differ from F_CPU if prescaling is used on the latter, and is required as the
# raw input clock is fed directly to the PLL sections of the AVR for high speed
# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
# at the end, this will be done automatically to create a 32-bit value in your
# source code.
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_USB = $(F_CPU)
# Starting byte address of the bootloader, as a byte address - computed via the formula
# BOOT_START = ((FLASH_SIZE_KB - BOOT_SECTION_SIZE_KB) * 1024)
#
# Note that the bootloader size and start address given in AVRStudio is in words and not
# bytes, and so will need to be doubled to obtain the byte address needed by AVR-GCC.
FLASH_SIZE_KB = 32
BOOT_SECTION_SIZE_KB = 4
BOOT_START = 0x$(shell echo "obase=16; ($(FLASH_SIZE_KB) - $(BOOT_SECTION_SIZE_KB)) * 1024" | bc)
# Output format. (can be srec, ihex, binary)
FORMAT = ihex
# Target file name (without extension).
TARGET = Caterina
# Object files directory
# To put object files in current directory, use a dot (.), do NOT make
# this an empty or blank macro!
OBJDIR = .
# Path to the LUFA library
LUFA_PATH = ../../../../../LUFA-111009
# LUFA library compile-time options and predefined tokens
LUFA_OPTS = -D USB_DEVICE_ONLY
LUFA_OPTS += -D DEVICE_STATE_AS_GPIOR=0
LUFA_OPTS += -D ORDERED_EP_CONFIG
LUFA_OPTS += -D FIXED_CONTROL_ENDPOINT_SIZE=8
LUFA_OPTS += -D FIXED_NUM_CONFIGURATIONS=1
LUFA_OPTS += -D USE_RAM_DESCRIPTORS
LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_DEVICE_OPT_FULLSPEED | USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"
LUFA_OPTS += -D NO_INTERNAL_SERIAL
LUFA_OPTS += -D NO_DEVICE_SELF_POWER
LUFA_OPTS += -D NO_DEVICE_REMOTE_WAKEUP
LUFA_OPTS += -D NO_SOF_EVENTS
#LUFA_OPTS += -D NO_BLOCK_SUPPORT
#LUFA_OPTS += -D NO_EEPROM_BYTE_SUPPORT
#LUFA_OPTS += -D NO_FLASH_BYTE_SUPPORT
LUFA_OPTS += -D NO_LOCK_BYTE_WRITE_SUPPORT
# Create the LUFA source path variables by including the LUFA root makefile
include $(LUFA_PATH)/LUFA/makefile
# List C source files here. (C dependencies are automatically generated.)
SRC = $(TARGET).c \
Descriptors.c \
$(LUFA_SRC_USB) \
# List C++ source files here. (C dependencies are automatically generated.)
CPPSRC =
# List Assembler source files here.
# Make them always end in a capital .S. Files ending in a lowercase .s
# will not be considered source files but generated files (assembler
# output from the compiler), and will be deleted upon "make clean"!
# Even though the DOS/Win* filesystem matches both .s and .S the same,
# it will preserve the spelling of the filenames, and gcc itself does
# care about how the name is spelled on its command-line.
ASRC =
# Optimization level, can be [0, 1, 2, 3, s].
# 0 = turn off optimization. s = optimize for size.
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
OPT = s
# Debugging format.
# Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
# AVR Studio 4.10 requires dwarf-2.
# AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
DEBUG = dwarf-2
# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.
EXTRAINCDIRS = $(LUFA_PATH)/
# 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=c99
# Place -D or -U options here for C sources
CDEFS = -DF_CPU=$(F_CPU)UL
CDEFS += -DF_USB=$(F_USB)UL
CDEFS += -DBOARD=BOARD_$(BOARD) -DARCH=ARCH_$(ARCH)
CDEFS += -DBOOT_START_ADDR=$(BOOT_START)UL
CDEFS += $(LUFA_OPTS)
# Place -D or -U options here for ASM sources
ADEFS = -DF_CPU=$(F_CPU)
ADEFS += -DF_USB=$(F_USB)UL
ADEFS += -DBOARD=BOARD_$(BOARD)
ADEFS += -DBOOT_START_ADDR=$(BOOT_START)UL
ADEFS += $(LUFA_OPTS)
# Place -D or -U options here for C++ sources
CPPDEFS = -DF_CPU=$(F_CPU)UL
CPPDEFS += -DF_USB=$(F_USB)UL
CPPDEFS += -DBOARD=BOARD_$(BOARD)
CPPDEFS += -DBOOT_START_ADDR=$(BOOT_START)UL
CPPDEFS += $(LUFA_OPTS)
#CPPDEFS += -D__STDC_LIMIT_MACROS
#CPPDEFS += -D__STDC_CONSTANT_MACROS
#---------------- Compiler Options C ----------------
# -g*: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
CFLAGS = -g$(DEBUG)
CFLAGS += $(CDEFS)
CFLAGS += -O$(OPT)
CFLAGS += -funsigned-char
CFLAGS += -funsigned-bitfields
CFLAGS += -ffunction-sections
CFLAGS += -fno-inline-small-functions
CFLAGS += -fpack-struct
CFLAGS += -fshort-enums
CFLAGS += -fno-strict-aliasing
CFLAGS += -Wall
CFLAGS += -Wstrict-prototypes
#CFLAGS += -mshort-calls
#CFLAGS += -fno-unit-at-a-time
#CFLAGS += -Wundef
#CFLAGS += -Wunreachable-code
#CFLAGS += -Wsign-compare
CFLAGS += -Wa,-adhlns=$(<:%.c=$(OBJDIR)/%.lst)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
CFLAGS += $(CSTANDARD)
#---------------- Compiler Options C++ ----------------
# -g*: generate debugging information
# -O*: optimization level
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns...: create assembler listing
CPPFLAGS = -g$(DEBUG)
CPPFLAGS += $(CPPDEFS)
CPPFLAGS += -O$(OPT)
CPPFLAGS += -funsigned-char
CPPFLAGS += -funsigned-bitfields
CPPFLAGS += -fpack-struct
CPPFLAGS += -fshort-enums
CPPFLAGS += -fno-exceptions
CPPFLAGS += -Wall
CPPFLAGS += -Wundef
#CPPFLAGS += -mshort-calls
#CPPFLAGS += -fno-unit-at-a-time
#CPPFLAGS += -Wstrict-prototypes
#CPPFLAGS += -Wunreachable-code
#CPPFLAGS += -Wsign-compare
CPPFLAGS += -Wa,-adhlns=$(<:%.cpp=$(OBJDIR)/%.lst)
CPPFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
#CPPFLAGS += $(CSTANDARD)
#---------------- Assembler Options ----------------
# -Wa,...: tell GCC to pass this to the assembler.
# -adhlns: create listing
# -gstabs: have the assembler create line number information; note that
# for use in COFF files, additional information about filenames
# and function names needs to be present in the assembler source
# files -- see avr-libc docs [FIXME: not yet described there]
# -listing-cont-lines: Sets the maximum number of continuation lines of hex
# dump that will be displayed for a given single line of source input.
ASFLAGS = $(ADEFS) -Wa,-adhlns=$(<:%.S=$(OBJDIR)/%.lst),-gstabs,--listing-cont-lines=100
#---------------- Library Options ----------------
# Minimalistic printf version
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
# Floating point printf version (requires MATH_LIB = -lm below)
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
# If this is left blank, then it will use the Standard printf version.
PRINTF_LIB =
#PRINTF_LIB = $(PRINTF_LIB_MIN)
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
# Minimalistic scanf version
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
# If this is left blank, then it will use the Standard scanf version.
SCANF_LIB =
#SCANF_LIB = $(SCANF_LIB_MIN)
#SCANF_LIB = $(SCANF_LIB_FLOAT)
MATH_LIB = -lm
# List any extra directories to look for libraries here.
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.
EXTRALIBDIRS =
#---------------- External Memory Options ----------------
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# used for variables (.data/.bss) and heap (malloc()).
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
# only used for heap (malloc()).
#EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
EXTMEMOPTS =
#---------------- Linker Options ----------------
# -Wl,...: tell GCC to pass this to linker.
# -Map: create map file
# --cref: add cross reference to map file
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
LDFLAGS += -Wl,--section-start=.text=$(BOOT_START)
LDFLAGS += -Wl,--relax
LDFLAGS += -Wl,--gc-sections
LDFLAGS += $(EXTMEMOPTS)
LDFLAGS += $(patsubst %,-L%,$(EXTRALIBDIRS))
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
#LDFLAGS += -T linker_script.x
#---------------- Programming Options (avrdude) ----------------
# Programming hardware
# Type: avrdude -c ?
# to get a full listing.
#
AVRDUDE_PROGRAMMER = avrispmkII
# com1 = serial port. Use lpt1 to connect to parallel port.
AVRDUDE_PORT = usb
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
# Uncomment the following if you want avrdude's erase cycle counter.
# Note that this counter needs to be initialized first using -Yn,
# see avrdude manual.
#AVRDUDE_ERASE_COUNTER = -y
# Uncomment the following if you do /not/ wish a verification to be
# performed after programming the device.
#AVRDUDE_NO_VERIFY = -V
# Increase verbosity level. Please use this when submitting bug
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
# to submit bug reports.
#AVRDUDE_VERBOSE = -v -v
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
#---------------- Debugging Options ----------------
# For simulavr only - target MCU frequency.
DEBUG_MFREQ = $(F_CPU)
# Set the DEBUG_UI to either gdb or insight.
# DEBUG_UI = gdb
DEBUG_UI = insight
# Set the debugging back-end to either avarice, simulavr.
DEBUG_BACKEND = avarice
#DEBUG_BACKEND = simulavr
# GDB Init Filename.
GDBINIT_FILE = __avr_gdbinit
# When using avarice settings for the JTAG
JTAG_DEV = /dev/com1
# Debugging port used to communicate between GDB / avarice / simulavr.
DEBUG_PORT = 4242
# Debugging host used to communicate between GDB / avarice / simulavr, normally
# just set to localhost unless doing some sort of crazy debugging when
# avarice is running on a different computer.
DEBUG_HOST = localhost
#============================================================================
# Define programs and commands.
SHELL = sh
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
AR = avr-ar rcs
NM = avr-nm
AVRDUDE = /Applications/avrdude -C /Applications/avrdude.conf -B 1
REMOVE = rm -f
REMOVEDIR = rm -rf
COPY = cp
WINSHELL = cmd
# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = -------- end --------
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
MSG_COFF = Converting to AVR COFF:
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
MSG_FLASH = Creating load file for Flash:
MSG_EEPROM = Creating load file for EEPROM:
MSG_EXTENDED_LISTING = Creating Extended Listing:
MSG_SYMBOL_TABLE = Creating Symbol Table:
MSG_LINKING = Linking:
MSG_COMPILING = Compiling C:
MSG_COMPILING_CPP = Compiling C++:
MSG_ASSEMBLING = Assembling:
MSG_CLEANING = Cleaning project:
MSG_CREATING_LIBRARY = Creating library:
# Define all object files.
OBJ = $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
# Define all listing files.
LST = $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
# Compiler flags to generate dependency files.
GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d
# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
ALL_CPPFLAGS = -mmcu=$(MCU) -I. -x c++ $(CPPFLAGS) $(GENDEPFLAGS)
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
# Default target.
all: begin gccversion sizebefore build sizeafter end
# Change the build target to build a HEX file or a library.
build: elf hex eep lss sym
#build: lib
elf: $(TARGET).elf
hex: $(TARGET).hex
eep: $(TARGET).eep
lss: $(TARGET).lss
sym: $(TARGET).sym
LIBNAME=lib$(TARGET).a
lib: $(LIBNAME)
# Eye candy.
# AVR Studio 3.x does not check make's exit code but relies on
# the following magic strings to be generated by the compile job.
begin:
@echo
@echo $(MSG_BEGIN)
end:
@echo $(MSG_END)
@echo
# Display size of file.
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
ELFSIZE = $(SIZE) $(MCU_FLAG) $(FORMAT_FLAG) $(TARGET).elf
MCU_FLAG = $(shell $(SIZE) --help | grep -- --mcu > /dev/null && echo --mcu=$(MCU) )
FORMAT_FLAG = $(shell $(SIZE) --help | grep -- --format=.*avr > /dev/null && echo --format=avr )
sizebefore:
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
2>/dev/null; echo; fi
sizeafter:
@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
2>/dev/null; echo; fi
# Display compiler version information.
gccversion :
@$(CC) --version
# Program the device.
program: $(TARGET).hex $(TARGET).eep
$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
# Generate avr-gdb config/init file which does the following:
# define the reset signal, load the target file, connect to target, and set
# a breakpoint at main().
gdb-config:
@$(REMOVE) $(GDBINIT_FILE)
@echo define reset >> $(GDBINIT_FILE)
@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
@echo end >> $(GDBINIT_FILE)
@echo file $(TARGET).elf >> $(GDBINIT_FILE)
@echo target remote $(DEBUG_HOST):$(DEBUG_PORT) >> $(GDBINIT_FILE)
ifeq ($(DEBUG_BACKEND),simulavr)
@echo load >> $(GDBINIT_FILE)
endif
@echo break main >> $(GDBINIT_FILE)
debug: gdb-config $(TARGET).elf
ifeq ($(DEBUG_BACKEND), avarice)
@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
@$(WINSHELL) /c pause
else
@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
$(DEBUG_MFREQ) --port $(DEBUG_PORT)
endif
@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
COFFCONVERT = $(OBJCOPY) --debugging
COFFCONVERT += --change-section-address .data-0x800000
COFFCONVERT += --change-section-address .bss-0x800000
COFFCONVERT += --change-section-address .noinit-0x800000
COFFCONVERT += --change-section-address .eeprom-0x810000
coff: $(TARGET).elf
@echo
@echo $(MSG_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
extcoff: $(TARGET).elf
@echo
@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
# Create final output files (.hex, .eep) from ELF output file.
%.hex: %.elf
@echo
@echo $(MSG_FLASH) $@
$(OBJCOPY) -O $(FORMAT) -R .eeprom -R .fuse -R .lock $< $@
%.eep: %.elf
@echo
@echo $(MSG_EEPROM) $@
-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 --no-change-warnings -O $(FORMAT) $< $@ || exit 0
# Create extended listing file from ELF output file.
%.lss: %.elf
@echo
@echo $(MSG_EXTENDED_LISTING) $@
$(OBJDUMP) -h -S -z $< > $@
# Create a symbol table from ELF output file.
%.sym: %.elf
@echo
@echo $(MSG_SYMBOL_TABLE) $@
$(NM) -n $< > $@
# Create library from object files.
.SECONDARY : $(TARGET).a
.PRECIOUS : $(OBJ)
%.a: $(OBJ)
@echo
@echo $(MSG_CREATING_LIBRARY) $@
$(AR) $@ $(OBJ)
# Link: create ELF output file from object files.
.SECONDARY : $(TARGET).elf
.PRECIOUS : $(OBJ)
%.elf: $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
# Compile: create object files from C source files.
$(OBJDIR)/%.o : %.c
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@
# Compile: create object files from C++ source files.
$(OBJDIR)/%.o : %.cpp
@echo
@echo $(MSG_COMPILING_CPP) $<
$(CC) -c $(ALL_CPPFLAGS) $< -o $@
# Compile: create assembler files from C source files.
%.s : %.c
$(CC) -S $(ALL_CFLAGS) $< -o $@
# Compile: create assembler files from C++ source files.
%.s : %.cpp
$(CC) -S $(ALL_CPPFLAGS) $< -o $@
# Assemble: create object files from assembler source files.
$(OBJDIR)/%.o : %.S
@echo
@echo $(MSG_ASSEMBLING) $<
$(CC) -c $(ALL_ASFLAGS) $< -o $@
# Create preprocessed source for use in sending a bug report.
%.i : %.c
$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@
# Target: clean project.
clean: begin clean_list end
clean_list :
@echo
@echo $(MSG_CLEANING)
$(REMOVE) $(TARGET).hex
$(REMOVE) $(TARGET).eep
$(REMOVE) $(TARGET).cof
$(REMOVE) $(TARGET).elf
$(REMOVE) $(TARGET).map
$(REMOVE) $(TARGET).sym
$(REMOVE) $(TARGET).lss
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.o) $(CPPSRC:%.cpp=$(OBJDIR)/%.o) $(ASRC:%.S=$(OBJDIR)/%.o)
$(REMOVE) $(SRC:%.c=$(OBJDIR)/%.lst) $(CPPSRC:%.cpp=$(OBJDIR)/%.lst) $(ASRC:%.S=$(OBJDIR)/%.lst)
$(REMOVE) $(SRC:.c=.s)
$(REMOVE) $(SRC:.c=.d)
$(REMOVE) $(SRC:.c=.i)
$(REMOVEDIR) .dep
doxygen:
@echo Generating Project Documentation \($(TARGET)\)...
@doxygen Doxygen.conf
@echo Documentation Generation Complete.
clean_doxygen:
rm -rf Documentation
checksource:
@for f in $(SRC) $(CPPSRC) $(ASRC); do \
if [ -f $$f ]; then \
echo "Found Source File: $$f" ; \
else \
echo "Source File Not Found: $$f" ; \
fi; done
# Create object files directory
$(shell mkdir $(OBJDIR) 2>/dev/null)
# Include the dependency files.
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
# Listing of phony targets.
.PHONY : all begin finish end sizebefore sizeafter gccversion \
build elf hex eep lss sym coff extcoff doxygen clean \
clean_list clean_doxygen program debug gdb-config checksource

View File

@ -1,117 +0,0 @@
:103800000C94341C0C944F1C0C944F1C0C944F1CA7
:103810000C944F1C0C944F1C0C944F1C0C944F1C7C
:103820000C944F1C0C944F1C0C944F1C0C944F1C6C
:103830000C944F1C0C944F1C0C944F1C0C944F1C5C
:103840000C944F1C0C944F1C0C944F1C0C944F1C4C
:103850000C944F1C0C944F1C0C944F1C0C944F1C3C
:103860000C944F1C0C944F1C11241FBECFEFD4E0BE
:10387000DEBFCDBF11E0A0E0B1E0E8E1FFE302C0B0
:1038800005900D92A230B107D9F712E0A2E0B1E0A5
:1038900001C01D92AD30B107E1F70C94311D0C94BD
:1038A000001CCF93DF93CDB7DEB724970FB6F89403
:1038B000DEBF0FBECDBF382F882309F433E010924E
:1038C0000A02332309F44BC020E02D9A19821A8290
:1038D0001B821C8289819A81AB81BC8180549F416B
:1038E000A040B040A0F489819A81AB81BC8101964F
:1038F000A11DB11D89839A83AB83BC8389819A8181
:10390000AB81BC8180549F41A040B04060F32D98B2
:1039100019821A821B821C8289819A81AB81BC81A7
:1039200080549F41A040B040A0F489819A81AB812E
:10393000BC810196A11DB11D89839A83AB83BC8391
:1039400089819A81AB81BC8180549F41A040B04065
:1039500060F32F5F231708F4B8CF20930A02249650
:103960000FB6F894DEBF0FBECDBFDF91CF910895A3
:10397000EF92FF920F931F93EE24FF248701809113
:10398000C00087FD17C00894E11CF11C011D111D2A
:1039900081E0E81689E0F8068DE3080780E0180763
:1039A00070F3E0910201F091030109958091C0004C
:1039B00087FFE9CF8091C600992787FD90951F91D9
:1039C0000F91FF90EF900895982F8091C00085FF90
:1039D000FCCF9093C60008950E94B81C803271F00D
:1039E000809104018F5F80930401853009F0089570
:1039F000E0910201F09103010995089584E10E948C
:103A0000E41C80E10E94E41C08951F93182F0E947B
:103A1000B81C803269F0809104018F5F80930401AB
:103A2000853079F4E0910201F0910301099509C014
:103A300084E10E94E41C812F0E94E41C80E10E942A
:103A4000E41C1F910895282F882351F090E0809165
:103A5000C00087FFFCCF8091C6009F5F2917B9F790
:103A60000895CFEFD4E0DEBFCDBF000089E18093A1
:103A7000C4001092C50088E18093C10086E0809365
:103A8000C2005098589A259A83E00E94511C0E94C7
:103A9000B81C8033B1F18133B9F1803409F454C0DA
:103AA000813409F45AC0823409F469C0853409F4B8
:103AB0006CC0803531F1813521F1823511F18535C8
:103AC00009F4B2C0863509F4BAC0843609F463C07B
:103AD000843709F4BBC0853709F40EC1863709F471
:103AE0004AC0809104018F5F80930401853079F68C
:103AF000E0910201F091030109950E94B81C803306
:103B000051F60E94EC1CC3CF0E94B81C803249F7CA
:103B100084E10E94E41C81E40E94E41C86E50E948A
:103B2000E41C82E50E94E41C80E20E94E41C89E41B
:103B30000E94E41C83E50E94E41C80E50E94E41CD2
:103B400080E10E94E41CA3CF0E94B81C8638C8F212
:103B50000E94B81C0E94EC1C9ACF0E94B81C8038AE
:103B600009F4F7C0813809F4F8C0823809F4F9C0C3
:103B7000883909F4BDC080E00E94051D88CF84E12A
:103B80000E94231D0E94EC1C82CF85E00E94231D11
:103B90000E94EC1C7CCF0E94B81C809309020E94FA
:103BA000B81C8093080280910C028E7F80930C02D7
:103BB0000E94B81C853409F4C6C080910802909117
:103BC0000902892B09F0ADC00E94B81C803209F0AF
:103BD00088CF80910C0280FFC8C08091080290912C
:103BE00009020097D1F02091060130910701E8E029
:103BF000F1E0AC014E0F5F1FF999FECF32BD21BD40
:103C0000819180BDFA9AF99A2F5F3F4F4E175F0757
:103C100099F7309307012093060184E10E94E41C88
:103C200080E10E94E41C33CF0E94B81C80930601FF
:103C30000E94B81C809307010E94EC1C28CF84E0EE
:103C40000E94231D80E00E94051D21CF0E94B81C08
:103C5000809309020E94B81C809308020E94B81C3D
:103C6000853409F4F4C080910C028E7F80930C029D
:103C70008091060190910701880F991F9093070189
:103C8000809306010E94B81C803209F000CF84E1C5
:103C90000E94E41C2091080230910902211531058F
:103CA00019F1C0E0D0E0E0910601F09107018091A8
:103CB0000C0280FFC4C0F999FECFF2BDE1BDF89AB5
:103CC00080B50E94E41CE0910601F0910701319655
:103CD000F0930701E0930601209108023091090258
:103CE0002196C217D30718F380E10E94E41CCFCEBF
:103CF00083E00E94051DCBCE0E94B81C803209F0E3
:103D0000F0CE84E10E94E41C8EE10E94E41C84E970
:103D10000E94E41C86E00E94E41C80E10E94E41CF6
:103D2000B6CEC0E0D0E008E011E00E94B81CF80177
:103D300081938F0121968091080290910902C81702
:103D4000D90798F341CF80910C02816080930C02D7
:103D500034CF82E00E94051D9ACE81E00E94051DAD
:103D600096CE80E10E94051D92CE8091070187FDCD
:103D700080C010920B028091060190910701880F7C
:103D8000991F90930701809306018091080280FF9C
:103D900009C080910802909109020196909309024E
:103DA00080930802F894F999FECF1127E09106015B
:103DB000F0910701C8E0D1E08091080290910902DA
:103DC000103091F40091570001700130D9F303E0F5
:103DD00000935700E8950091570001700130D9F326
:103DE00001E100935700E895099019900091570060
:103DF00001700130D9F301E000935700E895139565
:103E0000103498F011270091570001700130D9F358
:103E100005E000935700E8950091570001700130CC
:103E2000D9F301E100935700E8953296029709F023
:103E3000C7CF103011F00296E5CF1124EECE81FFEE
:103E40000CC03196F0930701E093060149CF8091B1
:103E50000C02816080930C0215CF84910E94E41CB7
:103E60002091080230910902E0910601F0910701CA
:103E7000E8CF81E080930B027ECF0F931F930E94C7
:103E8000B81C182F0E94E41C0E94B81C082F0E9426
:103E9000E41C11362CF0175501363CF0075508C0CC
:103EA0001033D4F310530136CCF700330CF0005329
:103EB0001295107F100F812F992787FD90951F91E4
:103EC0000F9108951F93282F992787FD9095807F44
:103ED00090709595879595958795959587959595E6
:103EE00087958A304CF0982F995A822F8F708A309C
:103EF0004CF0182F195A08C0982F905D822F8F70A0
:103F00008A30BCF7182F105D892F0E94E41C812F86
:083F10000E94E41C1F910895BA
:023F1800800027
:0400000300003800C1
:00000001FF

View File

@ -1,979 +0,0 @@
/**********************************************************/
/* Serial Bootloader for Atmel megaAVR Controllers */
/* */
/* tested with ATmega8, ATmega128 and ATmega168 */
/* should work with other mega's, see code for details */
/* */
/* ATmegaBOOT.c */
/* */
/* 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>
/* the current avr-libc eeprom functions do not support the ATmega168 */
/* own eeprom write/read functions are used instead */
#ifndef __AVR_ATmega168__
#include <avr/eeprom.h>
#endif
/* Use the F_CPU defined in Makefile */
/* 20060803: hacked by DojoCorp */
/* 20070626: hacked by David A. Mellis to decrease waiting time for auto-reset */
/* set the waiting time for the bootloader */
/* get this from the Makefile instead */
/* #define MAX_TIME_COUNT (F_CPU>>4) */
/* 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 */
/* 20060803: hacked by DojoCorp */
//#define BAUD_RATE 115200
#define BAUD_RATE 19200
/* 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
/* Adjust to suit whatever pin your hardware uses to enter the bootloader */
/* ATmega128 has two UARTS so two pins are used to enter bootloader and select UART */
/* BL0... means UART0, BL1... means UART1 */
#ifdef __AVR_ATmega128__
#define BL_DDR DDRF
#define BL_PORT PORTF
#define BL_PIN PINF
#define BL0 PINF7
#define BL1 PINF6
#else
/* other ATmegas have only one UART, so only one pin is defined to enter bootloader */
#define BL_DDR DDRD
#define BL_PORT PORTD
#define BL_PIN PIND
#define BL PIND6
#endif
/* 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 */
#ifdef __AVR_ATmega128__
/* Onboard LED is connected to pin PB7 (e.g. Crumb128, PROBOmega128, Savvy128) */
#define LED_DDR DDRB
#define LED_PORT PORTB
#define LED_PIN PINB
#define LED PINB7
#else
/* Onboard LED is connected to pin PB2 (e.g. Crumb8, Crumb168) */
#define LED_DDR DDRB
#define LED_PORT PORTB
#define LED_PIN PINB
/* 20060803: hacked by DojoCorp, LED pin is B5 in Arduino */
/* #define LED PINB2 */
#define LED PINB5
#endif
/* monitor functions will only be compiled when using ATmega128, due to bootblock size constraints */
#ifdef __AVR_ATmega128__
#define MONITOR
#endif
/* 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_ATmega128__
#define SIG2 0x97
#define SIG3 0x02
#define PAGE_SIZE 0x80U //128 words
#elif defined __AVR_ATmega64__
#define SIG2 0x96
#define SIG3 0x02
#define PAGE_SIZE 0x80U //128 words
#elif defined __AVR_ATmega32__
#define SIG2 0x95
#define SIG3 0x02
#define PAGE_SIZE 0x40U //64 words
#elif defined __AVR_ATmega16__
#define SIG2 0x94
#define SIG3 0x03
#define PAGE_SIZE 0x40U //64 words
#elif defined __AVR_ATmega8__
#define SIG2 0x93
#define SIG3 0x07
#define PAGE_SIZE 0x20U //32 words
#elif defined __AVR_ATmega88__
#define SIG2 0x93
#define SIG3 0x0a
#define PAGE_SIZE 0x20U //32 words
#elif defined __AVR_ATmega168__
#define SIG2 0x94
#define SIG3 0x06
#define PAGE_SIZE 0x40U //64 words
#elif defined __AVR_ATmega162__
#define SIG2 0x94
#define SIG3 0x04
#define PAGE_SIZE 0x40U //64 words
#elif defined __AVR_ATmega163__
#define SIG2 0x94
#define SIG3 0x02
#define PAGE_SIZE 0x40U //64 words
#elif defined __AVR_ATmega169__
#define SIG2 0x94
#define SIG3 0x05
#define PAGE_SIZE 0x40U //64 words
#elif defined __AVR_ATmega8515__
#define SIG2 0x93
#define SIG3 0x06
#define PAGE_SIZE 0x20U //32 words
#elif defined __AVR_ATmega8535__
#define SIG2 0x93
#define SIG3 0x08
#define PAGE_SIZE 0x20U //32 words
#endif
/* 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 address_high;
uint8_t pagesz=0x80;
uint8_t i;
uint8_t bootuart = 0;
uint8_t error_count = 0;
void (*app_start)(void) = 0x0000;
/* main program starts here */
int main(void)
{
uint8_t ch,ch2;
uint16_t w;
asm volatile("nop\n\t");
/* set pin direction for bootloader pin and enable pullup */
/* for ATmega128, two pins need to be initialized */
#ifdef __AVR_ATmega128__
BL_DDR &= ~_BV(BL0);
BL_DDR &= ~_BV(BL1);
BL_PORT |= _BV(BL0);
BL_PORT |= _BV(BL1);
#else
/* We run the bootloader regardless of the state of this pin. Thus, don't
put it in a different state than the other pins. --DAM, 070709
BL_DDR &= ~_BV(BL);
BL_PORT |= _BV(BL);
*/
#endif
#ifdef __AVR_ATmega128__
/* check which UART should be used for booting */
if(bit_is_clear(BL_PIN, BL0)) {
bootuart = 1;
}
else if(bit_is_clear(BL_PIN, BL1)) {
bootuart = 2;
}
#endif
/* check if flash is programmed already, if not start bootloader anyway */
if(pgm_read_byte_near(0x0000) != 0xFF) {
#ifdef __AVR_ATmega128__
/* no UART was selected, start application */
if(!bootuart) {
app_start();
}
#else
/* check if bootloader pin is set low */
/* we don't start this part neither for the m8, nor m168 */
//if(bit_is_set(BL_PIN, BL)) {
// app_start();
// }
#endif
}
#ifdef __AVR_ATmega128__
/* no bootuart was selected, default to uart 0 */
if(!bootuart) {
bootuart = 1;
}
#endif
/* initialize UART(s) depending on CPU defined */
#ifdef __AVR_ATmega128__
if(bootuart == 1) {
UBRR0L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
UBRR0H = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
UCSR0A = 0x00;
UCSR0C = 0x06;
UCSR0B = _BV(TXEN0)|_BV(RXEN0);
}
if(bootuart == 2) {
UBRR1L = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
UBRR1H = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
UCSR1A = 0x00;
UCSR1C = 0x06;
UCSR1B = _BV(TXEN1)|_BV(RXEN1);
}
#elif defined __AVR_ATmega163__
UBRR = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
UBRRHI = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
UCSRA = 0x00;
UCSRB = _BV(TXEN)|_BV(RXEN);
#elif defined __AVR_ATmega168__
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);
#elif defined __AVR_ATmega8__
/* m8 */
UBRRH = (((F_CPU/BAUD_RATE)/16)-1)>>8; // set baud rate
UBRRL = (((F_CPU/BAUD_RATE)/16)-1);
UCSRB = (1<<RXEN)|(1<<TXEN); // enable Rx & Tx
UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0); // config USART; 8N1
#else
/* m16,m32,m169,m8515,m8535 */
UBRRL = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
UBRRH = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
UCSRA = 0x00;
UCSRC = 0x06;
UCSRB = _BV(TXEN)|_BV(RXEN);
#endif
/* set LED pin as output */
LED_DDR |= _BV(LED);
/* flash onboard LED to signal entering of bootloader */
#ifdef __AVR_ATmega128__
// 4x for UART0, 5x for UART1
flash_led(NUM_LED_FLASHES + bootuart);
#else
flash_led(NUM_LED_FLASHES);
#endif
/* 20050803: by DojoCorp, this is one of the parts provoking the
system to stop listening, cancelled from the original */
//putch('\0');
/* 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();
}
/* 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 (w=0;w<length.word;w++) {
buff[w] = getch(); // Store data in buffer, can't keep up with serial data stream whilst programming pages
}
if (getch() == ' ') {
if (flags.eeprom) { //Write to EEPROM one byte at a time
for(w=0;w<length.word;w++) {
#ifdef __AVR_ATmega168__
while(EECR & (1<<EEPE));
EEAR = (uint16_t)(void *)address.word;
EEDR = buff[w];
EECR |= (1<<EEMPE);
EECR |= (1<<EEPE);
#else
eeprom_write_byte((void *)address.word,buff[w]);
#endif
address.word++;
}
}
else { //Write to FLASH one page at a time
if (address.byte[1]>127) address_high = 0x01; //Only possible with m128, m256 will need 3rd address byte. FIXME
else address_high = 0x00;
#ifdef __AVR_ATmega128__
RAMPZ = address_high;
#endif
address.word = address.word << 1; //address * 2 -> byte location
/* if ((length.byte[0] & 0x01) == 0x01) length.word++; //Even up an odd number of bytes */
if ((length.byte[0] & 0x01)) length.word++; //Even up an odd number of bytes
cli(); //Disable interrupts, just to be sure
// HACKME: EEPE used to be EEWE
while(bit_is_set(EECR,EEPE)); //Wait for previous EEPROM writes to complete
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"
#ifdef __AVR_ATmega163__
".word 0xFFFF \n\t"
"nop \n\t"
#endif
"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"
#ifdef __AVR_ATmega163__
".word 0xFFFF \n\t"
"nop \n\t"
#endif
"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"
#ifdef __AVR_ATmega163__
"andi r30,0x80 \n\t" // m163 requires Z6:Z1 to be zero during page write
#endif
"ldi r16,0x05 \n\t" //Write page pointed to by Z
"sts %0,r16 \n\t"
"spm \n\t"
#ifdef __AVR_ATmega163__
".word 0xFFFF \n\t"
"nop \n\t"
"ori r30,0x7E \n\t" // recover Z6:Z1 state after page write (had to be zero during write)
#endif
"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"
#ifdef __AVR_ATmega163__
".word 0xFFFF \n\t"
"nop \n\t"
#endif
"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
#if defined __AVR_ATmega168__
: "=m" (SPMCSR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31"
#else
: "=m" (SPMCR) : "M" (PAGE_SIZE) : "r0","r16","r17","r24","r25","r28","r29","r30","r31"
#endif
);
/* Should really add a wait for RWW section to be enabled, don't actually need it since we never */
/* exit the bootloader without a power cycle anyhow */
}
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 defined __AVR_ATmega128__
if (address.word>0x7FFF) flags.rampz = 1; // No go with m256, FIXME
else flags.rampz = 0;
#endif
if (getch() == 'E') flags.eeprom = 1;
else {
flags.eeprom = 0;
address.word = address.word << 1; // address * 2 -> byte location
}
if (getch() == ' ') { // Command terminator
putch(0x14);
for (w=0;w < length.word;w++) { // Can handle odd and even lengths okay
if (flags.eeprom) { // Byte access EEPROM read
#ifdef __AVR_ATmega168__
while(EECR & (1<<EEPE));
EEAR = (uint16_t)(void *)address.word;
EECR |= (1<<EERE);
putch(EEDR);
#else
putch(eeprom_read_byte((void *)address.word));
#endif
address.word++;
}
else {
if (!flags.rampz) putch(pgm_read_byte_near(address.word));
#if defined __AVR_ATmega128__
else putch(pgm_read_byte_far(address.word + 0x10000));
// Hmmmm, yuck FIXME when m256 arrvies
#endif
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);
}
#ifdef MONITOR
/* here come the extended monitor commands by Erik Lins */
/* check for three times exclamation mark pressed */
else if(ch=='!') {
ch = getch();
if(ch=='!') {
ch = getch();
if(ch=='!') {
#ifdef __AVR_ATmega128__
uint16_t extaddr;
#endif
uint8_t addrl, addrh;
#ifdef CRUMB128
PGM_P welcome = {"ATmegaBOOT / Crumb128 - (C) J.P.Kyle, E.Lins - 050815\n\r"};
#elif defined PROBOMEGA128
PGM_P welcome = {"ATmegaBOOT / PROBOmega128 - (C) J.P.Kyle, E.Lins - 050815\n\r"};
#elif defined SAVVY128
PGM_P welcome = {"ATmegaBOOT / Savvy128 - (C) J.P.Kyle, E.Lins - 050815\n\r"};
#endif
/* turn on LED */
LED_DDR |= _BV(LED);
LED_PORT &= ~_BV(LED);
/* print a welcome message and command overview */
for(i=0; welcome[i] != '\0'; ++i) {
putch(welcome[i]);
}
/* test for valid commands */
for(;;) {
putch('\n');
putch('\r');
putch(':');
putch(' ');
ch = getch();
putch(ch);
/* toggle LED */
if(ch == 't') {
if(bit_is_set(LED_PIN,LED)) {
LED_PORT &= ~_BV(LED);
putch('1');
} else {
LED_PORT |= _BV(LED);
putch('0');
}
}
/* read byte from address */
else if(ch == 'r') {
ch = getch(); putch(ch);
addrh = gethex();
addrl = gethex();
putch('=');
ch = *(uint8_t *)((addrh << 8) + addrl);
puthex(ch);
}
/* write a byte to address */
else if(ch == 'w') {
ch = getch(); putch(ch);
addrh = gethex();
addrl = gethex();
ch = getch(); putch(ch);
ch = gethex();
*(uint8_t *)((addrh << 8) + addrl) = ch;
}
/* read from uart and echo back */
else if(ch == 'u') {
for(;;) {
putch(getch());
}
}
#ifdef __AVR_ATmega128__
/* external bus loop */
else if(ch == 'b') {
putch('b');
putch('u');
putch('s');
MCUCR = 0x80;
XMCRA = 0;
XMCRB = 0;
extaddr = 0x1100;
for(;;) {
ch = *(volatile uint8_t *)extaddr;
if(++extaddr == 0) {
extaddr = 0x1100;
}
}
}
#endif
else if(ch == 'j') {
app_start();
}
}
/* end of monitor functions */
}
}
}
/* end of monitor */
#endif
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)
{
#ifdef __AVR_ATmega128__
if(bootuart == 1) {
while (!(UCSR0A & _BV(UDRE0)));
UDR0 = ch;
}
else if (bootuart == 2) {
while (!(UCSR1A & _BV(UDRE1)));
UDR1 = ch;
}
#elif defined __AVR_ATmega168__
while (!(UCSR0A & _BV(UDRE0)));
UDR0 = ch;
#else
/* m8,16,32,169,8515,8535,163 */
while (!(UCSRA & _BV(UDRE)));
UDR = ch;
#endif
}
char getch(void)
{
#ifdef __AVR_ATmega128__
if(bootuart == 1) {
while(!(UCSR0A & _BV(RXC0)));
return UDR0;
}
else if(bootuart == 2) {
while(!(UCSR1A & _BV(RXC1)));
return UDR1;
}
return 0;
#elif defined __AVR_ATmega168__
uint32_t count = 0;
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();
}
return UDR0;
#else
/* m8,16,32,169,8515,8535,163 */
uint32_t count = 0;
while(!(UCSRA & _BV(RXC))){
/* 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();
}
return UDR;
#endif
}
void getNch(uint8_t count)
{
uint8_t i;
for(i=0;i<count;i++) {
#ifdef __AVR_ATmega128__
if(bootuart == 1) {
while(!(UCSR0A & _BV(RXC0)));
UDR0;
}
else if(bootuart == 2) {
while(!(UCSR1A & _BV(RXC1)));
UDR1;
}
#elif defined __AVR_ATmega168__
while(!(UCSR0A & _BV(RXC0)));
UDR0;
#else
/* m8,16,32,169,8515,8535,163 */
/* 20060803 DojoCorp:: Addon coming from the previous Bootloader*/
//while(!(UCSRA & _BV(RXC)));
//UDR;
uint8_t i;
for(i=0;i<count;i++) {
getch(); // need to handle time out
}
#endif
}
}
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();
}
}
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;
}
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);
}
}
/* end of file ATmegaBOOT.c */

View File

@ -1,84 +0,0 @@
# Makefile for ATmegaBOOT
# E.Lins, 18.7.2005
# $Id$
# Instructions
#
# To build the bootloader for the LilyPad:
# make lily
# program name should not be changed...
PROGRAM = ATmegaBOOT_168
# enter the target CPU frequency
AVR_FREQ = 8000000L
# enter the parameters for the avrdude isp tool
ISPTOOL = stk500v2
ISPPORT = usb
ISPSPEED = -b 115200
MCU_TARGET = atmega168
LDSECTION = --section-start=.text=0x3800
# 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 0x0f (to
# lock it), but since the high two bits of the lock byte are
# unused, avrdude would get confused.
ISPFUSES = avrdude -c $(ISPTOOL) -p m168 -P $(ISPPORT) $(ISPSPEED) -e -u -U lock:w:0x3f:m -U efuse:w:0x00:m -U hfuse:w:0xdd:m -U lfuse:w:0xff:m
ISPFLASH = avrdude -c $(ISPTOOL) -p m168 -P $(ISPPORT) $(ISPSPEED) -U flash:w:$(PROGRAM)_$(TARGET).hex -U lock:w:0x0f:m
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:
lily: CFLAGS += '-DMAX_TIME_COUNT=F_CPU>>1' '-DNUM_LED_FLASHES=3'
lily: $(PROGRAM).hex
$(PROGRAM).hex: $(PROGRAM).elf
$(OBJCOPY) -j .text -j .data -O ihex $< $@
$(PROGRAM).elf: $(OBJ)
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
$(OBJ):
avr-gcc $(CFLAGS) $(LDFLAGS) -c -g -O2 -Wall -mmcu=atmega168 ATmegaBOOT.c -o ATmegaBOOT_168.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
install:
avrdude -p m168 -c stk500v2 -P /dev/cu.USA19H1b1P1.1 -e -u -U lock:w:0x3f:m -U efuse:w:0x00:m -U hfuse:w:0xdd:m -U lfuse:w:0xe2:m
avrdude -p m168 -c stk500v2 -P /dev/cu.USA19H1b1P1.1 -e -u -U flash:w:ATmegaBOOT_168.hex -U lock:w:0x0f:m

View File

@ -1,451 +0,0 @@
# 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
# 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

@ -1,81 +0,0 @@
This directory contains the Optiboot small bootloader for AVR
microcontrollers, somewhat modified specifically for the Arduino
environment.
Optiboot is more fully described here: http://code.google.com/p/optiboot/
and is the work of Peter Knight (aka Cathedrow), building on work of Jason P
Kyle, Spiff, and Ladyada. Arduino-specific modification are by Bill
Westfield (aka WestfW)
Arduino-specific issues are tracked as part of the Arduino project
at http://code.google.com/p/arduino
------------------------------------------------------------
Building optiboot for Arduino.
Production builds of optiboot for Arduino are done on a Mac in "unix mode"
using CrossPack-AVR-20100115. CrossPack tracks WINAVR (for windows), which
is just a package of avr-gcc and related utilities, so similar builds should
work on Windows or Linux systems.
One of the Arduino-specific changes is modifications to the makefile to
allow building optiboot using only the tools installed as part of the
Arduino environment, or the Arduino source development tree. All three
build procedures should yield identical binaries (.hex files) (although
this may change if compiler versions drift apart between CrossPack and
the Arduino IDE.)
Building Optiboot in the Arduino IDE Install.
Work in the .../hardware/arduino/bootloaders/optiboot/ and use the
"omake <targets>" command, which just generates a command that uses
the arduino-included "make" utility with a command like:
make OS=windows ENV=arduino <targets>
or make OS=macosx ENV=arduino <targets>
On windows, this assumes you're using the windows command shell. If
you're using a cygwin or mingw shell, or have one of those in your
path, the build will probably break due to slash vs backslash issues.
On a Mac, if you have the developer tools installed, you can use the
Apple-supplied version of make.
The makefile uses relative paths ("../../../tools/" and such) to find
the programs it needs, so you need to work in the existing optiboot
directory (or something created at the same "level") for it to work.
Building Optiboot in the Arduino Source Development Install.
In this case, there is no special shell script, and you're assumed to
have "make" installed somewhere in your path.
Build the Arduino source ("ant build") to unpack the tools into the
expected directory.
Work in Arduino/hardware/arduino/bootloaders/optiboot and use
make OS=windows ENV=arduinodev <targets>
or make OS=macosx ENV=arduinodev <targets>
Programming Chips Using the _isp Targets
The CPU targets have corresponding ISP targets that will actuall
program the bootloader into a chip. "atmega328_isp" for the atmega328,
for example. These will set the fuses and lock bits as appropriate as
well as uploading the bootloader code.
The makefiles default to using a USB programmer, but you can use
a serial programmer like ArduinoISP by changing the appropriate
variables when you invoke make:
make ISPTOOL=stk500v1 ISPPORT=/dev/tty.usbserial-A20e1eAN \
ISPSPEED=-b19200 atmega328_isp
The "atmega8_isp" target does not currently work, because the mega8
doesn't have the "extended" fuse that the generic ISP target wants to
pass on to avrdude. You'll need to run avrdude manually.
Standard Targets
I've reduced the pre-built and source-version-controlled targets
(.hex and .lst files included in the git repository) to just the
three basic 16MHz targets: atmega8, atmega16, atmega328.

View File

@ -1,848 +0,0 @@
/* 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

@ -1,20 +0,0 @@
#!/bin/bash
make clean
#
# The "big three" standard bootloaders.
make atmega8
make atmega168
make atmega328
#
# additional buildable platforms of
# somewhat questionable support level
make lilypad
make lilypad_resonator
make pro8
make pro16
make pro20
make atmega328_pro8
make sanguino
make mega
make atmega88
make luminet

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