mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-17 22:23:10 +03:00
Merged upstream arduino branch
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@ -14,4 +14,5 @@ hardware/arduino/bootloaders/caterina_LUFA/Caterina.elf
|
|||||||
hardware/arduino/bootloaders/caterina_LUFA/Caterina.eep
|
hardware/arduino/bootloaders/caterina_LUFA/Caterina.eep
|
||||||
hardware/arduino/bootloaders/caterina_LUFA/.dep/
|
hardware/arduino/bootloaders/caterina_LUFA/.dep/
|
||||||
.gitignore
|
.gitignore
|
||||||
build/windows/work/
|
build/windows/work/
|
||||||
|
build/linux/work/
|
||||||
|
@ -1095,9 +1095,10 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
item = newJMenuItemShift(_("Find in Reference"), 'F');
|
item = newJMenuItemShift(_("Find in Reference"), 'F');
|
||||||
item.addActionListener(new ActionListener() {
|
item.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (textarea.isSelectionActive()) {
|
// if (textarea.isSelectionActive()) {
|
||||||
handleFindReference();
|
// handleFindReference();
|
||||||
}
|
// }
|
||||||
|
handleFindReference();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
menu.add(item);
|
menu.add(item);
|
||||||
@ -1830,25 +1831,58 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
stopCompoundEdit();
|
stopCompoundEdit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String getCurrentKeyword() {
|
||||||
|
String text = "";
|
||||||
|
if (textarea.getSelectedText() != null)
|
||||||
|
text = textarea.getSelectedText().trim();
|
||||||
|
|
||||||
protected void handleFindReference() {
|
try {
|
||||||
String text = textarea.getSelectedText().trim();
|
int current = textarea.getCaretPosition();
|
||||||
|
int startOffset = 0;
|
||||||
|
int endIndex = current;
|
||||||
|
String tmp = textarea.getDocument().getText(current, 1);
|
||||||
|
// TODO probably a regexp that matches Arduino lang special chars
|
||||||
|
// already exists.
|
||||||
|
String regexp = "[\\s\\n();\\\\.!='\\[\\]{}]";
|
||||||
|
|
||||||
if (text.length() == 0) {
|
while (!tmp.matches(regexp)) {
|
||||||
statusNotice(_("First select a word to find in the reference."));
|
endIndex++;
|
||||||
|
tmp = textarea.getDocument().getText(endIndex, 1);
|
||||||
|
}
|
||||||
|
// For some reason document index start at 2.
|
||||||
|
// if( current - start < 2 ) return;
|
||||||
|
|
||||||
} else {
|
tmp = "";
|
||||||
String referenceFile = PdeKeywords.getReference(text);
|
while (!tmp.matches(regexp)) {
|
||||||
//System.out.println("reference file is " + referenceFile);
|
startOffset++;
|
||||||
if (referenceFile == null) {
|
if (current - startOffset < 0) {
|
||||||
statusNotice(
|
tmp = textarea.getDocument().getText(0, 1);
|
||||||
I18n.format(_("No reference available for \"{0}\""), text)
|
break;
|
||||||
);
|
} else
|
||||||
} else {
|
tmp = textarea.getDocument().getText(current - startOffset, 1);
|
||||||
Base.showReference(I18n.format(_("{0}.html"), referenceFile));
|
}
|
||||||
}
|
startOffset--;
|
||||||
}
|
|
||||||
}
|
int length = endIndex - current + startOffset;
|
||||||
|
text = textarea.getDocument().getText(current - startOffset, length);
|
||||||
|
|
||||||
|
} catch (BadLocationException bl) {
|
||||||
|
bl.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void handleFindReference() {
|
||||||
|
String text = getCurrentKeyword();
|
||||||
|
|
||||||
|
String referenceFile = PdeKeywords.getReference(text);
|
||||||
|
if (referenceFile == null) {
|
||||||
|
statusNotice(I18n.format(_("No reference available for \"{0}\""), text));
|
||||||
|
} else {
|
||||||
|
Base.showReference(I18n.format(_("{0}.html"), referenceFile));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||||
@ -2775,16 +2809,15 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
copyItem.setEnabled(true);
|
copyItem.setEnabled(true);
|
||||||
discourseItem.setEnabled(true);
|
discourseItem.setEnabled(true);
|
||||||
|
|
||||||
String sel = textarea.getSelectedText().trim();
|
|
||||||
referenceFile = PdeKeywords.getReference(sel);
|
|
||||||
referenceItem.setEnabled(referenceFile != null);
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
cutItem.setEnabled(false);
|
cutItem.setEnabled(false);
|
||||||
copyItem.setEnabled(false);
|
copyItem.setEnabled(false);
|
||||||
discourseItem.setEnabled(false);
|
discourseItem.setEnabled(false);
|
||||||
referenceItem.setEnabled(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
referenceFile = PdeKeywords.getReference(getCurrentKeyword());
|
||||||
|
referenceItem.setEnabled(referenceFile != null);
|
||||||
|
|
||||||
super.show(component, x, y);
|
super.show(component, x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,9 +178,6 @@
|
|||||||
#: Editor.java:1255
|
#: Editor.java:1255
|
||||||
!Use\ Selection\ For\ Find=
|
!Use\ Selection\ For\ Find=
|
||||||
|
|
||||||
#: Editor.java:1816
|
|
||||||
!First\ select\ a\ word\ to\ find\ in\ the\ reference.=
|
|
||||||
|
|
||||||
#: Editor.java:1823
|
#: Editor.java:1823
|
||||||
#, java-format
|
#, java-format
|
||||||
!No\ reference\ available\ for\ "{0}"=
|
!No\ reference\ available\ for\ "{0}"=
|
||||||
|
@ -110,7 +110,7 @@ public class PdePreprocessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//String importRegexp = "(?:^|\\s|;)(import\\s+)(\\S+)(\\s*;)";
|
//String importRegexp = "(?:^|\\s|;)(import\\s+)(\\S+)(\\s*;)";
|
||||||
String importRegexp = "^\\s*#include\\s+[<\"](\\S+)[\">]";
|
String importRegexp = "^\\s*#include\\s*[<\"](\\S+)[\">]";
|
||||||
programImports = new ArrayList<String>();
|
programImports = new ArrayList<String>();
|
||||||
|
|
||||||
String[][] pieces = PApplet.matchAll(program, importRegexp);
|
String[][] pieces = PApplet.matchAll(program, importRegexp);
|
||||||
@ -205,7 +205,8 @@ public class PdePreprocessor {
|
|||||||
for (int i = 0; i < prototypes.size(); i++) {
|
for (int i = 0; i < prototypes.size(); i++) {
|
||||||
out.print(prototypes.get(i) + "\n");
|
out.print(prototypes.get(i) + "\n");
|
||||||
}
|
}
|
||||||
out.println("#line 1");
|
String[] lines = program.substring(0, prototypeInsertionPoint).split("\n", -1);
|
||||||
|
out.println("#line " + (lines.length - 1));
|
||||||
out.print(program.substring(prototypeInsertionPoint));
|
out.print(program.substring(prototypeInsertionPoint));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,13 +317,31 @@ public class PdePreprocessor {
|
|||||||
|
|
||||||
// XXX: doesn't handle ... varargs
|
// XXX: doesn't handle ... varargs
|
||||||
// XXX: doesn't handle function pointers
|
// XXX: doesn't handle function pointers
|
||||||
Pattern pattern = Pattern.compile("[\\w\\[\\]\\*]+\\s+[&\\[\\]\\*\\w\\s]+\\([&,\\[\\]\\*\\w\\s]*\\)(?=\\s*\\{)");
|
Pattern prototypePattern = Pattern.compile("[\\w\\[\\]\\*]+\\s+[&\\[\\]\\*\\w\\s]+\\([&,\\[\\]\\*\\w\\s]*\\)(?=\\s*;)");
|
||||||
|
Pattern functionPattern = Pattern.compile("[\\w\\[\\]\\*]+\\s+[&\\[\\]\\*\\w\\s]+\\([&,\\[\\]\\*\\w\\s]*\\)(?=\\s*\\{)");
|
||||||
|
|
||||||
ArrayList<String> matches = new ArrayList<String>();
|
// Find already declared prototypes
|
||||||
Matcher matcher = pattern.matcher(in);
|
ArrayList<String> prototypeMatches = new ArrayList<String>();
|
||||||
while (matcher.find())
|
Matcher prototypeMatcher = prototypePattern.matcher(in);
|
||||||
matches.add(matcher.group(0) + ";");
|
while (prototypeMatcher.find())
|
||||||
|
prototypeMatches.add(prototypeMatcher.group(0) + ";");
|
||||||
|
|
||||||
return matches;
|
// Find all functions and generate prototypes for them
|
||||||
|
ArrayList<String> functionMatches = new ArrayList<String>();
|
||||||
|
Matcher functionMatcher = functionPattern.matcher(in);
|
||||||
|
while (functionMatcher.find())
|
||||||
|
functionMatches.add(functionMatcher.group(0) + ";");
|
||||||
|
|
||||||
|
// Remove generated prototypes that exactly match ones found in the source file
|
||||||
|
for (int functionIndex=functionMatches.size() - 1; functionIndex >= 0; functionIndex--) {
|
||||||
|
for (int prototypeIndex=0; prototypeIndex < prototypeMatches.size(); prototypeIndex++) {
|
||||||
|
if ((functionMatches.get(functionIndex)).equals(prototypeMatches.get(prototypeIndex))) {
|
||||||
|
functionMatches.remove(functionIndex);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return functionMatches;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ public class AutoFormat implements Tool {
|
|||||||
c = string[j++] = getchr(); // extra char
|
c = string[j++] = getchr(); // extra char
|
||||||
while (done == 0) {
|
while (done == 0) {
|
||||||
c = string[j++] = getchr();
|
c = string[j++] = getchr();
|
||||||
while ((c != '/') && (j < string.length)) {
|
while ((c != '/') && (j < string.length) && EOF == 0) {
|
||||||
if(c == '\n' || c == '\r') {
|
if(c == '\n' || c == '\r') {
|
||||||
lineNumber++;
|
lineNumber++;
|
||||||
putcoms();
|
putcoms();
|
||||||
@ -111,7 +111,9 @@ public class AutoFormat implements Tool {
|
|||||||
if (j>1 && string[j-2] == '*') {
|
if (j>1 && string[j-2] == '*') {
|
||||||
done = 1;
|
done = 1;
|
||||||
jdoc = 0;
|
jdoc = 0;
|
||||||
}
|
} else if (EOF != 0) {
|
||||||
|
done = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
putcoms();
|
putcoms();
|
||||||
@ -134,7 +136,7 @@ public class AutoFormat implements Tool {
|
|||||||
}
|
}
|
||||||
if (ch == '\'' || ch == '"') {
|
if (ch == '\'' || ch == '"') {
|
||||||
cc = string[j++] = getchr();
|
cc = string[j++] = getchr();
|
||||||
while (cc != ch) {
|
while (cc != ch && EOF == 0) {
|
||||||
if (cc == '\\') string[j++] = getchr();
|
if (cc == '\\') string[j++] = getchr();
|
||||||
cc = string[j++] = getchr();
|
cc = string[j++] = getchr();
|
||||||
}
|
}
|
||||||
@ -207,7 +209,7 @@ public class AutoFormat implements Tool {
|
|||||||
}
|
}
|
||||||
string[j] = '\0';
|
string[j] = '\0';
|
||||||
i = 0;
|
i = 0;
|
||||||
while (string[i] == ' ') i++;
|
while (string[i] == ' ' && EOF == 0) i++;
|
||||||
if (lookup_com(w_jdoc) == 1) jdoc = 1;
|
if (lookup_com(w_jdoc) == 1) jdoc = 1;
|
||||||
String strBuffer = new String(string,0,j);
|
String strBuffer = new String(string,0,j);
|
||||||
if (string[i] == '/' && string[i+1]=='*')
|
if (string[i] == '/' && string[i+1]=='*')
|
||||||
@ -241,7 +243,7 @@ public class AutoFormat implements Tool {
|
|||||||
public void cpp_comment() throws IOException
|
public void cpp_comment() throws IOException
|
||||||
{
|
{
|
||||||
c = getchr();
|
c = getchr();
|
||||||
while(c != '\n' && c != '\r' && j<133)
|
while(c != '\n' && c != '\r' && EOF == 0)
|
||||||
{
|
{
|
||||||
string[j++] = c;
|
string[j++] = c;
|
||||||
c = getchr();
|
c = getchr();
|
||||||
@ -337,7 +339,7 @@ public class AutoFormat implements Tool {
|
|||||||
peekc = getchr();
|
peekc = getchr();
|
||||||
//while ((peekc == '\t' || peekc == ' ') &&
|
//while ((peekc == '\t' || peekc == ' ') &&
|
||||||
// (j < string.length)) {
|
// (j < string.length)) {
|
||||||
while (peekc == '\t' || peekc == ' ') {
|
while ((peekc == '\t' || peekc == ' ') && EOF == 0) {
|
||||||
string[j++] = peekc;
|
string[j++] = peekc;
|
||||||
peek = -1;
|
peek = -1;
|
||||||
peekc = '`';
|
peekc = '`';
|
||||||
@ -398,7 +400,7 @@ public class AutoFormat implements Tool {
|
|||||||
|
|
||||||
if (j<1) return (0);
|
if (j<1) return (0);
|
||||||
kk=0;
|
kk=0;
|
||||||
while(string[kk] == ' ')kk++;
|
while(string[kk] == ' ' && EOF == 0)kk++;
|
||||||
l=0;
|
l=0;
|
||||||
l = j_string.indexOf(keyword);
|
l = j_string.indexOf(keyword);
|
||||||
if (l<0 || l!=kk)
|
if (l<0 || l!=kk)
|
||||||
@ -421,7 +423,7 @@ public class AutoFormat implements Tool {
|
|||||||
|
|
||||||
if (j<1) return (0);
|
if (j<1) return (0);
|
||||||
kk=0;
|
kk=0;
|
||||||
while(string[kk] == ' ')kk++;
|
while(string[kk] == ' ' && EOF == 0) kk++;
|
||||||
l=0;
|
l=0;
|
||||||
l = j_string.indexOf(keyword);
|
l = j_string.indexOf(keyword);
|
||||||
if (l<0 || l!=kk)
|
if (l<0 || l!=kk)
|
||||||
@ -637,7 +639,8 @@ public class AutoFormat implements Tool {
|
|||||||
case '\'':
|
case '\'':
|
||||||
string[j++] = c;
|
string[j++] = c;
|
||||||
cc = getchr();
|
cc = getchr();
|
||||||
while(cc != c)
|
int count = 0;
|
||||||
|
while(cc != c && EOF == 0)
|
||||||
{
|
{
|
||||||
// max. length of line should be 256
|
// max. length of line should be 256
|
||||||
string[j++] = cc;
|
string[j++] = cc;
|
||||||
@ -784,7 +787,7 @@ public class AutoFormat implements Tool {
|
|||||||
case '#':
|
case '#':
|
||||||
string[j++] = c;
|
string[j++] = c;
|
||||||
cc = getchr();
|
cc = getchr();
|
||||||
while(cc != '\n')
|
while(cc != '\n' && EOF == 0)
|
||||||
{
|
{
|
||||||
string[j++] = cc;
|
string[j++] = cc;
|
||||||
cc = getchr();
|
cc = getchr();
|
||||||
@ -827,13 +830,13 @@ public class AutoFormat implements Tool {
|
|||||||
if ((lookup(w_for) == 1))
|
if ((lookup(w_for) == 1))
|
||||||
{
|
{
|
||||||
c = get_string();
|
c = get_string();
|
||||||
while(c != ';') c = get_string();
|
while(c != ';' && EOF == 0) c = get_string();
|
||||||
ct=0;
|
ct=0;
|
||||||
int for_done = 0;
|
int for_done = 0;
|
||||||
while (for_done==0)
|
while (for_done == 0 && EOF == 0)
|
||||||
{
|
{
|
||||||
c = get_string();
|
c = get_string();
|
||||||
while(c != ')')
|
while(c != ')' && EOF == 0)
|
||||||
{
|
{
|
||||||
if(c == '(') ct++;
|
if(c == '(') ct++;
|
||||||
c = get_string();
|
c = get_string();
|
||||||
|
@ -723,8 +723,8 @@
|
|||||||
prefix="arduino-${version}"
|
prefix="arduino-${version}"
|
||||||
excludes="**/*.tgz,
|
excludes="**/*.tgz,
|
||||||
**/*.bz2,
|
**/*.bz2,
|
||||||
**/macosx/,
|
**/build/macosx/,
|
||||||
**/windows/,
|
**/build/windows/,
|
||||||
**/work/,
|
**/work/,
|
||||||
**/.git/,
|
**/.git/,
|
||||||
**/*.class"
|
**/*.class"
|
||||||
|
@ -26,7 +26,7 @@ my $faq = create_page('FAQ.html', "$ARDUINO/Main/FAQ");
|
|||||||
my $env = create_page('environment.html', "$ARDUINO/Main/Environment");
|
my $env = create_page('environment.html', "$ARDUINO/Main/Environment");
|
||||||
my $css = create_page('arduinoUno.css', "$ARDUINO/pub/skins/arduinoUno/arduinoUno.css");
|
my $css = create_page('arduinoUno.css', "$ARDUINO/pub/skins/arduinoUno/arduinoUno.css");
|
||||||
my $css2 = create_page('arduinoWide.css', "$ARDUINO/pub/skins/arduinoWide/arduinoWide.css");
|
my $css2 = create_page('arduinoWide.css', "$ARDUINO/pub/skins/arduinoWide/arduinoWide.css");
|
||||||
my $css2 = create_page('arduinoWideRender.css', "$ARDUINO/pub/skins/arduinoWideRender/arduinoWideRender.css");
|
my $css3 = create_page('arduinoWideRender.css', "$ARDUINO/pub/skins/arduinoWideRender/arduinoWideRender.css");
|
||||||
my $eeprom = create_page('EEPROM.html', "$ARDUINO/Reference/EEPROM");
|
my $eeprom = create_page('EEPROM.html', "$ARDUINO/Reference/EEPROM");
|
||||||
my $stepper = create_page('Stepper.html', "$ARDUINO/Reference/Stepper");
|
my $stepper = create_page('Stepper.html', "$ARDUINO/Reference/Stepper");
|
||||||
my $softser = create_page('SoftwareSerial.html', "$ARDUINO/Reference/SoftwareSerial");
|
my $softser = create_page('SoftwareSerial.html', "$ARDUINO/Reference/SoftwareSerial");
|
||||||
@ -38,7 +38,8 @@ my $mousekeyboard = create_page('MouseKeyboard.html', "$ARDUINO/Reference/MouseK
|
|||||||
my $lcd = create_page('LiquidCrystal.html', "$ARDUINO/Reference/LiquidCrystal");
|
my $lcd = create_page('LiquidCrystal.html', "$ARDUINO/Reference/LiquidCrystal");
|
||||||
my $ethernet = create_page('Ethernet.html', "$ARDUINO/Reference/Ethernet");
|
my $ethernet = create_page('Ethernet.html', "$ARDUINO/Reference/Ethernet");
|
||||||
my $serial = create_page('Serial.html', "$ARDUINO/Reference/Serial");
|
my $serial = create_page('Serial.html', "$ARDUINO/Reference/Serial");
|
||||||
my $string = create_page('StringClass.html', "$ARDUINO/Reference/StringClass");
|
my $stream = create_page('Stream.html', "$ARDUINO/Reference/Stream");
|
||||||
|
my $string = create_page('StringObject.html', "$ARDUINO/Reference/StringObject");
|
||||||
|
|
||||||
create_linked_pages($guide, qr!$ARDUINO/Guide/(\w+)!, 'Guide_%%.html');
|
create_linked_pages($guide, qr!$ARDUINO/Guide/(\w+)!, 'Guide_%%.html');
|
||||||
create_linked_pages($softser, qr!$ARDUINO/Reference/(SoftwareSerial\w+)!, '%%.html');
|
create_linked_pages($softser, qr!$ARDUINO/Reference/(SoftwareSerial\w+)!, '%%.html');
|
||||||
@ -57,6 +58,8 @@ create_linked_pages($ethernet, qr!$ARDUINO/Reference/(Server\w+)!, '%%.ht
|
|||||||
create_linked_pages($ethernet, qr!$ARDUINO/Reference/(Client\w+)!, '%%.html');
|
create_linked_pages($ethernet, qr!$ARDUINO/Reference/(Client\w+)!, '%%.html');
|
||||||
create_linked_pages($serial, qr!$ARDUINO/Serial/(\w+)!, 'Serial_%%.html');
|
create_linked_pages($serial, qr!$ARDUINO/Serial/(\w+)!, 'Serial_%%.html');
|
||||||
create_linked_pages($string, qr!$ARDUINO/Reference/(String\w+)!, '%%.html');
|
create_linked_pages($string, qr!$ARDUINO/Reference/(String\w+)!, '%%.html');
|
||||||
|
create_linked_pages($stream, qr!$ARDUINO/Reference/(Stream\w+)!, '%%.html');
|
||||||
|
create_linked_pages($string, qr!$ARDUINO/Reference/(String\w+)!, '%%.html');
|
||||||
|
|
||||||
my $index = create_page('index.html', "$ARDUINO/Reference/HomePage");
|
my $index = create_page('index.html', "$ARDUINO/Reference/HomePage");
|
||||||
|
|
||||||
|
@ -14,6 +14,8 @@
|
|||||||
<string>VERSION</string>
|
<string>VERSION</string>
|
||||||
<!-- now stop changing things and get outta here -->
|
<!-- now stop changing things and get outta here -->
|
||||||
|
|
||||||
|
<key>NSHighResolutionCapable</key>
|
||||||
|
<true/>
|
||||||
<key>CFBundleAllowMixedLocalizations</key>
|
<key>CFBundleAllowMixedLocalizations</key>
|
||||||
<string>true</string>
|
<string>true</string>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
|
@ -13,12 +13,12 @@
|
|||||||
Attach a MIDI cable to the jack, then to a MIDI synth, and play music.
|
Attach a MIDI cable to the jack, then to a MIDI synth, and play music.
|
||||||
|
|
||||||
created 13 Jun 2006
|
created 13 Jun 2006
|
||||||
modified 30 Aug 2011
|
modified 13 Aug 2012
|
||||||
by Tom Igoe
|
by Tom Igoe
|
||||||
|
|
||||||
This example code is in the public domain.
|
This example code is in the public domain.
|
||||||
|
|
||||||
http://www.arduino.cc/en/Tutorial/MIDI
|
http://www.arduino.cc/en/Tutorial/Midi
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
Arduino Starter Kit example
|
||||||
|
Project 2 - Spaceship Interface
|
||||||
|
|
||||||
|
This sketch is written to accompany Project 2 in the
|
||||||
|
Arduino Starter Kit
|
||||||
|
|
||||||
|
Parts required:
|
||||||
|
1 green LED
|
||||||
|
2 red LEDs
|
||||||
|
pushbutton
|
||||||
|
10 kilohm resistor
|
||||||
|
3 220 ohm resistors
|
||||||
|
|
||||||
|
Created 13 September 2012
|
||||||
|
by Scott Fitzgerald
|
||||||
|
|
||||||
|
http://arduino.cc/starterKit
|
||||||
|
|
||||||
|
This example code is part of the public domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Create a global variable to hold the
|
||||||
|
// state of the switch. This variable is persistent
|
||||||
|
// throughout the program. Whenever you refer to
|
||||||
|
// switchState, you’re talking about the number it holds
|
||||||
|
int switchstate = 0;
|
||||||
|
|
||||||
|
void setup(){
|
||||||
|
// declare the LED pins as outputs
|
||||||
|
pinMode(3,OUTPUT);
|
||||||
|
pinMode(4,OUTPUT);
|
||||||
|
pinMode(5,OUTPUT);
|
||||||
|
|
||||||
|
// declare the switch pin as an input
|
||||||
|
pinMode(2,INPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(){
|
||||||
|
|
||||||
|
// read the value of the switch
|
||||||
|
// digitalRead() checks to see if there is voltage
|
||||||
|
// on the pin or not
|
||||||
|
switchstate = digitalRead(2);
|
||||||
|
|
||||||
|
// if the button is not pressed
|
||||||
|
// blink the red LEDs
|
||||||
|
if (switchstate == LOW) {
|
||||||
|
digitalWrite(3, HIGH); // turn the green LED on pin 3 on
|
||||||
|
digitalWrite(4, LOW); // turn the red LED on pin 4 off
|
||||||
|
digitalWrite(5, LOW); // turn the red LED on pin 5 off
|
||||||
|
}
|
||||||
|
// this else is part of the above if() statement.
|
||||||
|
// if the switch is not LOW (the button is pressed)
|
||||||
|
// the code below will run
|
||||||
|
else {
|
||||||
|
digitalWrite(3, LOW); // turn the green LED on pin 3 off
|
||||||
|
digitalWrite(4, LOW); // turn the red LED on pin 4 off
|
||||||
|
digitalWrite(5, HIGH); // turn the red LED on pin 5 on
|
||||||
|
// wait for a quarter second before changing the light
|
||||||
|
delay(250);
|
||||||
|
digitalWrite(4, HIGH); // turn the red LED on pin 4 on
|
||||||
|
digitalWrite(5, LOW); // turn the red LED on pin 5 off
|
||||||
|
// wait for a quarter second before changing the light
|
||||||
|
delay(250);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
Arduino Starter Kit example
|
||||||
|
Project 3 - Love-O-Meter
|
||||||
|
|
||||||
|
This sketch is written to accompany Project 3 in the
|
||||||
|
Arduino Starter Kit
|
||||||
|
|
||||||
|
Parts required:
|
||||||
|
1 TMP36 temperature sensor
|
||||||
|
3 red LEDs
|
||||||
|
3 220 ohm resistors
|
||||||
|
|
||||||
|
Created 13 September 2012
|
||||||
|
by Scott Fitzgerald
|
||||||
|
|
||||||
|
http://arduino.cc/starterKit
|
||||||
|
|
||||||
|
This example code is part of the public domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
// named constant for the pin the sensor is connected to
|
||||||
|
const int sensorPin = A0;
|
||||||
|
// room temperature in Celcius
|
||||||
|
const float baselineTemp = 20.0;
|
||||||
|
|
||||||
|
void setup(){
|
||||||
|
// open a serial connection to display values
|
||||||
|
Serial.begin(9600);
|
||||||
|
// set the LED pins as outputs
|
||||||
|
// the for() loop saves some extra coding
|
||||||
|
for(int pinNumber = 2; pinNumber<5; pinNumber++){
|
||||||
|
pinMode(pinNumber,OUTPUT);
|
||||||
|
digitalWrite(pinNumber, LOW);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(){
|
||||||
|
// read the value on AnalogIn pin 0
|
||||||
|
// and store it in a variable
|
||||||
|
int sensorVal = analogRead(sensorPin);
|
||||||
|
|
||||||
|
// send the 10-bit sensor value out the serial port
|
||||||
|
Serial.print("sensor Value: ");
|
||||||
|
Serial.print(sensorVal);
|
||||||
|
|
||||||
|
// convert the ADC reading to voltage
|
||||||
|
float voltage = (sensorVal/1024.0) * 5.0;
|
||||||
|
|
||||||
|
// Send the voltage level out the Serial port
|
||||||
|
Serial.print(", Volts: ");
|
||||||
|
Serial.print(voltage);
|
||||||
|
|
||||||
|
// convert the voltage to temperature in degrees C
|
||||||
|
// the sensor changes 10 mV per degree
|
||||||
|
// the datasheet says there's a 500 mV offset
|
||||||
|
// ((volatge - 500mV) times 100)
|
||||||
|
Serial.print(", degrees C: ");
|
||||||
|
float temperature = (voltage - .5) * 100;
|
||||||
|
Serial.println(temperature);
|
||||||
|
|
||||||
|
// if the current temperature is lower than the baseline
|
||||||
|
// turn off all LEDs
|
||||||
|
if(temperature < baselineTemp){
|
||||||
|
digitalWrite(2, LOW);
|
||||||
|
digitalWrite(3, LOW);
|
||||||
|
digitalWrite(4, LOW);
|
||||||
|
} // if the temperature rises 2-4 degrees, turn an LED on
|
||||||
|
else if(temperature >= baselineTemp+2 && temperature < baselineTemp+4){
|
||||||
|
digitalWrite(2, HIGH);
|
||||||
|
digitalWrite(3, LOW);
|
||||||
|
digitalWrite(4, LOW);
|
||||||
|
} // if the temperature rises 4-6 degrees, turn a second LED on
|
||||||
|
else if(temperature >= baselineTemp+4 && temperature < baselineTemp+6){
|
||||||
|
digitalWrite(2, HIGH);
|
||||||
|
digitalWrite(3, HIGH);
|
||||||
|
digitalWrite(4, LOW);
|
||||||
|
} // if the temperature rises more than 6 degrees, turn all LEDs on
|
||||||
|
else if(temperature >= baselineTemp+6){
|
||||||
|
digitalWrite(2, HIGH);
|
||||||
|
digitalWrite(3, HIGH);
|
||||||
|
digitalWrite(4, HIGH);
|
||||||
|
}
|
||||||
|
delay(1);
|
||||||
|
}
|
@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
Arduino Starter Kit example
|
||||||
|
Project 4 - Color Mixing Lamp
|
||||||
|
|
||||||
|
This sketch is written to accompany Project 3 in the
|
||||||
|
Arduino Starter Kit
|
||||||
|
|
||||||
|
Parts required:
|
||||||
|
1 RGB LED
|
||||||
|
three 10 kilohm resistors
|
||||||
|
3 220 ohm resistors
|
||||||
|
3 photoresistors
|
||||||
|
red green aand blue colored gels
|
||||||
|
|
||||||
|
Created 13 September 2012
|
||||||
|
by Scott Fitzgerald
|
||||||
|
Thanks to Federico Vanzati for improvements
|
||||||
|
|
||||||
|
http://arduino.cc/starterKit
|
||||||
|
|
||||||
|
This example code is part of the public domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
const int greenLEDPin = 9; // LED connected to digital pin 9
|
||||||
|
const int redLEDPin = 10; // LED connected to digital pin 10
|
||||||
|
const int blueLEDPin = 11; // LED connected to digital pin 11
|
||||||
|
|
||||||
|
const int redSensorPin = A0; // pin with the photoresistor with the red gel
|
||||||
|
const int greenSensorPin = A1; // pin with the photoresistor with the green gel
|
||||||
|
const int blueSensorPin = A2; // pin with the photoresistor with the blue gel
|
||||||
|
|
||||||
|
int redValue = 0; // value to write to the red LED
|
||||||
|
int greenValue = 0; // value to write to the green LED
|
||||||
|
int blueValue = 0; // value to write to the blue LED
|
||||||
|
|
||||||
|
int redSensorValue = 0; // variable to hold the value from the red sensor
|
||||||
|
int greenSensorValue = 0; // variable to hold the value from the green sensor
|
||||||
|
int blueSensorValue = 0; // variable to hold the value from the blue sensor
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// initialize serial communications at 9600 bps:
|
||||||
|
Serial.begin(9600);
|
||||||
|
|
||||||
|
// set the digital pins as outputs
|
||||||
|
pinMode(greenLedPin,OUTPUT);
|
||||||
|
pinMode(redLedPin,OUTPUT);
|
||||||
|
pinMode(blueLedPin,OUTPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Read the sensors first:
|
||||||
|
|
||||||
|
// read the value from the red-filtered photoresistor:
|
||||||
|
redsensorValue = analogRead(redsensorPin);
|
||||||
|
// give the ADC a moment to settle
|
||||||
|
delay(5);
|
||||||
|
// read the value from the green-filtered photoresistor:
|
||||||
|
greensensorValue = analogRead(greensensorPin);
|
||||||
|
// give the ADC a moment to settle
|
||||||
|
delay(5);
|
||||||
|
// read the value from the blue-filtered photoresistor:
|
||||||
|
bluesensorValue = analogRead(bluesensorPin);
|
||||||
|
|
||||||
|
// print out the values to the serial monitor
|
||||||
|
Serial.print("raw sensor Values \t red: ");
|
||||||
|
Serial.print(redsensorValue);
|
||||||
|
Serial.print("\t green: ");
|
||||||
|
Serial.print(greensensorValue);
|
||||||
|
Serial.print("\t Blue: ");
|
||||||
|
Serial.println(bluesensorValue);
|
||||||
|
|
||||||
|
/*
|
||||||
|
In order to use the values from the sensor for the LED,
|
||||||
|
you need to do some math. The ADC provides a 10-bit number,
|
||||||
|
but analogWrite() uses 8 bits. You'll want to divide your
|
||||||
|
sensor readings by 4 to keep them in range of the output.
|
||||||
|
*/
|
||||||
|
redValue = redsensorValue/4;
|
||||||
|
greenValue = greensensorValue/4;
|
||||||
|
blueValue = bluesensorValue/4;
|
||||||
|
|
||||||
|
// print out the mapped values
|
||||||
|
Serial.print("Mapped sensor Values \t red: ");
|
||||||
|
Serial.print(redValue);
|
||||||
|
Serial.print("\t green: ");
|
||||||
|
Serial.print(greenValue);
|
||||||
|
Serial.print("\t Blue: ");
|
||||||
|
Serial.println(blueValue);
|
||||||
|
|
||||||
|
/*
|
||||||
|
Now that you have a usable value, it's time to PWM the LED.
|
||||||
|
*/
|
||||||
|
analogWrite(redLedPin, redValue);
|
||||||
|
analogWrite(greenLedPin, greenValue);
|
||||||
|
analogWrite(blueLedPin, blueValue);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
Arduino Starter Kit example
|
||||||
|
Project 5 - Servo Mood Indicator
|
||||||
|
|
||||||
|
This sketch is written to accompany Project 5 in the
|
||||||
|
Arduino Starter Kit
|
||||||
|
|
||||||
|
Parts required:
|
||||||
|
servo motor
|
||||||
|
10 kilohm potentiometer
|
||||||
|
2 100 uF electrolytic capacitors
|
||||||
|
|
||||||
|
Created 13 September 2012
|
||||||
|
by Scott Fitzgerald
|
||||||
|
|
||||||
|
http://arduino.cc/starterKit
|
||||||
|
|
||||||
|
This example code is part of the public domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
// include the servo library
|
||||||
|
#include <Servo.h>
|
||||||
|
|
||||||
|
Servo myServo; // create a servo object
|
||||||
|
|
||||||
|
int const potPin = A0; // analog pin used to connect the potentiometer
|
||||||
|
int potVal; // variable to read the value from the analog pin
|
||||||
|
int angle; // variable to hold the angle for the servo motor
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
myServo.attach(9); // attaches the servo on pin 9 to the servo object
|
||||||
|
Serial.begin(9600); // open a serial connection to your computer
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
potVal = analogRead(potPin); // read the value of the potentiometer
|
||||||
|
// print out the value to the serial monitor
|
||||||
|
Serial.print("potVal: ");
|
||||||
|
Serial.print(potVal);
|
||||||
|
|
||||||
|
// scale the numbers from the pot
|
||||||
|
angle = map(potVal, 0, 1023, 0, 179);
|
||||||
|
|
||||||
|
// print out the angle for the servo motor
|
||||||
|
Serial.print(", angle: ");
|
||||||
|
Serial.println(angle);
|
||||||
|
|
||||||
|
// set the servo position
|
||||||
|
myServo.write(angle);
|
||||||
|
|
||||||
|
// wait for the servo to get there
|
||||||
|
delay(15);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
Arduino Starter Kit example
|
||||||
|
Project 6 - Light Theremin
|
||||||
|
|
||||||
|
This sketch is written to accompany Project 6 in the
|
||||||
|
Arduino Starter Kit
|
||||||
|
|
||||||
|
Parts required:
|
||||||
|
photoresistor
|
||||||
|
10 kilohm resistor
|
||||||
|
piezo
|
||||||
|
|
||||||
|
Created 13 September 2012
|
||||||
|
by Scott Fitzgerald
|
||||||
|
|
||||||
|
http://arduino.cc/starterKit
|
||||||
|
|
||||||
|
This example code is part of the public domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
// variable to hold sensor value
|
||||||
|
int sensorValue;
|
||||||
|
// variable to calibrate low value
|
||||||
|
int sensorLow = 1023;
|
||||||
|
// variable to calibrate high value
|
||||||
|
int sensorHigh = 0;
|
||||||
|
// LED pin
|
||||||
|
const int ledPin = 13;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// Make the LED pin an output and turn it on
|
||||||
|
pinMode(ledPin, OUTPUT);
|
||||||
|
digitalWrite(ledPin, HIGH);
|
||||||
|
|
||||||
|
// calibrate for the first five seconds after program runs
|
||||||
|
while (millis() < 5000) {
|
||||||
|
// record the maximum sensor value
|
||||||
|
sensorValue = analogRead(A0);
|
||||||
|
if (sensorValue > sensorHigh) {
|
||||||
|
sensorHigh = sensorValue;
|
||||||
|
}
|
||||||
|
// record the minimum sensor value
|
||||||
|
if (sensorValue < sensorLow) {
|
||||||
|
sensorLow = sensorValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// turn the LED off, signaling the end of the calibration period
|
||||||
|
digitalWrite(ledPin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
//read the input from A0 and store it in a variable
|
||||||
|
sensorValue = analogRead(A0);
|
||||||
|
|
||||||
|
// map the sensor values to a wide range of pitches
|
||||||
|
int pitch = map(sensorValue, sensorLow, sensorHigh, 50, 4000);
|
||||||
|
|
||||||
|
// play the tone for 20 ms on pin 8
|
||||||
|
tone(8, pitch, 20);
|
||||||
|
|
||||||
|
// wait for a moment
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
Arduino Starter Kit example
|
||||||
|
Project 7 - Keyboard
|
||||||
|
|
||||||
|
This sketch is written to accompany Project 7 in the
|
||||||
|
Arduino Starter Kit
|
||||||
|
|
||||||
|
Parts required:
|
||||||
|
two 10 kilohm resistors
|
||||||
|
1 Megohm resistor
|
||||||
|
220 ohm resistor
|
||||||
|
4 pushbuttons
|
||||||
|
piezo
|
||||||
|
|
||||||
|
Created 13 September 2012
|
||||||
|
by Scott Fitzgerald
|
||||||
|
|
||||||
|
http://arduino.cc/starterKit
|
||||||
|
|
||||||
|
This example code is part of the public domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
// create an array of notes
|
||||||
|
// the numbers below correspond to
|
||||||
|
// the frequencies of middle C, D, E, and F
|
||||||
|
int notes[] = {262, 294, 330, 349};
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
//start serial communication
|
||||||
|
Serial.begin(9600);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// create a local variable to hold the input on pin A0
|
||||||
|
int keyVal = analogRead(A0);
|
||||||
|
// send the value from A0 to the Serial Monitor
|
||||||
|
Serial.println(keyVal);
|
||||||
|
|
||||||
|
// play the note corresponding to each value on A0
|
||||||
|
if(keyVal == 1023){
|
||||||
|
// play the first frequency in the array on pin 8
|
||||||
|
tone(8, notes[0]);
|
||||||
|
}
|
||||||
|
else if(keyVal >= 990 && keyVal <= 1010){
|
||||||
|
// play the second frequency in the array on pin 8
|
||||||
|
tone(8, notes[1]);
|
||||||
|
}
|
||||||
|
else if(keyVal >= 505 && keyVal <= 515){
|
||||||
|
// play the third frequency in the array on pin 8
|
||||||
|
tone(8, notes[2]);
|
||||||
|
}
|
||||||
|
else if(keyVal >= 5 && keyVal <= 10){
|
||||||
|
// play the fourth frequency in the array on pin 8
|
||||||
|
tone(8, notes[3]);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// if the value is out of range, play no tone
|
||||||
|
noTone(8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
Arduino Starter Kit example
|
||||||
|
Project 8 - Digital Hourglass
|
||||||
|
|
||||||
|
This sketch is written to accompany Project 8 in the
|
||||||
|
Arduino Starter Kit
|
||||||
|
|
||||||
|
Parts required:
|
||||||
|
10 kilohm resistor
|
||||||
|
six 220 ohm resistors
|
||||||
|
six LEDs
|
||||||
|
tilt switch
|
||||||
|
|
||||||
|
Created 13 September 2012
|
||||||
|
by Scott Fitzgerald
|
||||||
|
|
||||||
|
http://arduino.cc/starterKit
|
||||||
|
|
||||||
|
This example code is part of the public domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
// named constant for the switch pin
|
||||||
|
const int switchPin = 8;
|
||||||
|
|
||||||
|
unsigned long previousTime = 0; // store the last time an LED was updated
|
||||||
|
int switchState = 0; // the current switch state
|
||||||
|
int prevSwitchState = 0; // the previous switch state
|
||||||
|
int led = 2; // a variable to refer to the LEDs
|
||||||
|
|
||||||
|
// 600000 = 10 minutes in milliseconds
|
||||||
|
long interval = 600000; // interval at which to light the next LED
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// set the LED pins as outputs
|
||||||
|
for(int x = 2;x<8;x++){
|
||||||
|
pinMode(x, OUTPUT);
|
||||||
|
}
|
||||||
|
// set the tilt switch pin as input
|
||||||
|
pinMode(switchPin, INPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(){
|
||||||
|
// store the time since the Arduino started running in a variable
|
||||||
|
unsigned long currentTime = millis();
|
||||||
|
|
||||||
|
// compare the current time to the previous time an LED turned on
|
||||||
|
// if it is greater than your interval, run the if statement
|
||||||
|
if(currentTime - previousTime > interval) {
|
||||||
|
// save the current time as the last time you changed an LED
|
||||||
|
previousTime = currentTime;
|
||||||
|
// Turn the LED on
|
||||||
|
digitalWrite(led, HIGH);
|
||||||
|
// increment the led variable
|
||||||
|
// in 10 minutes the next LED will light up
|
||||||
|
led++;
|
||||||
|
|
||||||
|
if(led == 7){
|
||||||
|
// the hour is up
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// read the switch value
|
||||||
|
switchState = digitalRead(switchPin);
|
||||||
|
|
||||||
|
// if the switch has changed
|
||||||
|
if(switchState != prevSwitchState){
|
||||||
|
// turn all the LEDs low
|
||||||
|
for(int x = 2;x<8;x++){
|
||||||
|
digitalWrite(x, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
// reset the LED variable to the first one
|
||||||
|
led = 2;
|
||||||
|
|
||||||
|
//reset the timer
|
||||||
|
previousTime = currentTime;
|
||||||
|
}
|
||||||
|
// set the previous switch state to the current state
|
||||||
|
prevSwitchState = switchState;
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
Arduino Starter Kit example
|
||||||
|
Project 9 - Motorized Pinwheel
|
||||||
|
|
||||||
|
This sketch is written to accompany Project 9 in the
|
||||||
|
Arduino Starter Kit
|
||||||
|
|
||||||
|
Parts required:
|
||||||
|
10 kilohm resistor
|
||||||
|
pushbutton
|
||||||
|
motor
|
||||||
|
9V battery
|
||||||
|
IRF520 MOSFET
|
||||||
|
1N4007 diode
|
||||||
|
|
||||||
|
Created 13 September 2012
|
||||||
|
by Scott Fitzgerald
|
||||||
|
|
||||||
|
http://arduino.cc/starterKit
|
||||||
|
|
||||||
|
This example code is part of the public domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
// named constants for the switch and motor pins
|
||||||
|
const int switchPin = 2; // the number of the switch pin
|
||||||
|
const int motorPin = 9; // the number of the motor pin
|
||||||
|
|
||||||
|
int switchState = 0; // variable for reading the switch's status
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// initialize the motor pin as an output:
|
||||||
|
pinMode(motorPin, OUTPUT);
|
||||||
|
// initialize the switch pin as an input:
|
||||||
|
pinMode(switchPin, INPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(){
|
||||||
|
// read the state of the switch value:
|
||||||
|
switchState = digitalRead(switchPin);
|
||||||
|
|
||||||
|
// check if the switch is pressed.
|
||||||
|
if (switchState == HIGH) {
|
||||||
|
// turn motor on:
|
||||||
|
digitalWrite(motorPin, HIGH);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// turn motor off:
|
||||||
|
digitalWrite(motorPin, LOW);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
Arduino Starter Kit example
|
||||||
|
Project 10 - Zoetrope
|
||||||
|
|
||||||
|
This sketch is written to accompany Project 10 in the
|
||||||
|
Arduino Starter Kit
|
||||||
|
|
||||||
|
Parts required:
|
||||||
|
two 10 kilohm resistors
|
||||||
|
2 momentary pushbuttons
|
||||||
|
one 10 kilohm potentiometer
|
||||||
|
motor
|
||||||
|
9V battery
|
||||||
|
H-Bridge
|
||||||
|
|
||||||
|
Created 13 September 2012
|
||||||
|
by Scott Fitzgerald
|
||||||
|
Thanks to Federico Vanzati for improvements
|
||||||
|
|
||||||
|
http://arduino.cc/starterKit
|
||||||
|
|
||||||
|
This example code is part of the public domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
const int controlPin1 = 2; // connected to pin 7 on the H-bridge
|
||||||
|
const int controlPin2 = 3; // connected to pin 2 on the H-bridge
|
||||||
|
const int enablePin = 9; // connected to pin 1 on the H-bridge
|
||||||
|
const int directionSwitchPin = 4; // connected to the switch for direction
|
||||||
|
const int onOffSwitchStateSwitchPin = 5; // connected to the switch for turning the motor on and off
|
||||||
|
const int potPin = A0; // connected to the potentiometer's output
|
||||||
|
|
||||||
|
// create some variables to hold values from your inputs
|
||||||
|
int onOffSwitchState = 0; // current state of the On/Off switch
|
||||||
|
int previousOnOffSwitchState = 0; // previous position of the on/off switch
|
||||||
|
int directionSwitchState = 0; // current state of the direction switch
|
||||||
|
int previousDirectionSwitchState = 0; // previous state of the direction switch
|
||||||
|
|
||||||
|
int motorEnabled = 0; // Turns the motor on/off
|
||||||
|
int motorSpeed = 0; // speed of the motor
|
||||||
|
int motorDirection = 1; // current direction of the motor
|
||||||
|
|
||||||
|
void setup(){
|
||||||
|
// intialize the inputs and outputs
|
||||||
|
pinMode(directionSwitchPin, INPUT);
|
||||||
|
pinMode(onOffSwitchStateSwitchPin, INPUT);
|
||||||
|
pinMode(controlPin1, OUTPUT);
|
||||||
|
pinMode(controlPin2, OUTPUT);
|
||||||
|
pinMode(enablePin, OUTPUT);
|
||||||
|
|
||||||
|
// pull the enable pin LOW to start
|
||||||
|
digitalWrite(enablePin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(){
|
||||||
|
// read the value of the on/off switch
|
||||||
|
onOffSwitchState = digitalRead(onOffSwitchStateSwitchPin);
|
||||||
|
delay(1);
|
||||||
|
|
||||||
|
// read the value of the direction switch
|
||||||
|
directionSwitchState = digitalRead(directionSwitchPin);
|
||||||
|
|
||||||
|
// read the value of the pot and divide by 4 to get
|
||||||
|
// a value that can be used for PWM
|
||||||
|
motorSpeed = analogRead(potPin)/4;
|
||||||
|
|
||||||
|
// if the on/off button changed state since the last loop()
|
||||||
|
if(onOffSwitchState != previousOnOffSwitchState){
|
||||||
|
// change the value of motorEnabled if pressed
|
||||||
|
if(onOffSwitchState == HIGH){
|
||||||
|
motorEnabled = !motorEnabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the direction button changed state since the last loop()
|
||||||
|
if (directionSwitchState != previousDirectionSwitchState) {
|
||||||
|
// change the value of motorDirection if pressed
|
||||||
|
if (directionSwitchState == HIGH) {
|
||||||
|
motorDirection = !motorDirection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// change the direction the motor spins by talking
|
||||||
|
// to the control pins on the H-Bridge
|
||||||
|
if (motorDirection == 1) {
|
||||||
|
digitalWrite(controlPin1, HIGH);
|
||||||
|
digitalWrite(controlPin2, LOW);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
digitalWrite(controlPin1, LOW);
|
||||||
|
digitalWrite(controlPin2, HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the motor is supposed to be on
|
||||||
|
if (motorEnabled == 1) {
|
||||||
|
// PWM the enable pin to vary the speed
|
||||||
|
analogWrite(enablePin, motorSpeed);
|
||||||
|
}
|
||||||
|
else { // if the motor is not supposed to be on
|
||||||
|
//turn the motor off
|
||||||
|
analogWrite(enablePin, 0);
|
||||||
|
}
|
||||||
|
// save the current On/Offswitch state as the previous
|
||||||
|
previousDirectionSwitchState = directionSwitchState;
|
||||||
|
// save the current switch state as the previous
|
||||||
|
previousOnOffSwitchState = onOffSwitchState;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
Arduino Starter Kit example
|
||||||
|
Project 11 - Crystal Ball
|
||||||
|
|
||||||
|
This sketch is written to accompany Project 11 in the
|
||||||
|
Arduino Starter Kit
|
||||||
|
|
||||||
|
Parts required:
|
||||||
|
220 ohm resistor
|
||||||
|
10 kilohm resistor
|
||||||
|
10 kilohm potentiometer
|
||||||
|
16x2 LCD screen
|
||||||
|
tilt switch
|
||||||
|
|
||||||
|
|
||||||
|
Created 13 September 2012
|
||||||
|
by Scott Fitzgerald
|
||||||
|
|
||||||
|
http://arduino.cc/starterKit
|
||||||
|
|
||||||
|
This example code is part of the public domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
// include the library code:
|
||||||
|
#include <LiquidCrystal.h>
|
||||||
|
|
||||||
|
// initialize the library with the numbers of the interface pins
|
||||||
|
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
|
||||||
|
|
||||||
|
// set up a constant for the tilt switchPin
|
||||||
|
const int switchPin = 6;
|
||||||
|
|
||||||
|
// variable to hold the value of the switchPin
|
||||||
|
int switchState = 0;
|
||||||
|
|
||||||
|
// variable to hold previous value of the switchpin
|
||||||
|
int prevSwitchState = 0;
|
||||||
|
|
||||||
|
// a variable to choose which reply from the crystal ball
|
||||||
|
int reply;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// set up the number of columns and rows on the LCD
|
||||||
|
lcd.begin(16, 2);
|
||||||
|
|
||||||
|
// set up the switch pin as an input
|
||||||
|
pinMode(switchPin,INPUT);
|
||||||
|
|
||||||
|
// Print a message to the LCD.
|
||||||
|
lcd.print("Ask the");
|
||||||
|
// set the cursor to column 0, line 1
|
||||||
|
// line 1 is the second row, since counting begins with 0
|
||||||
|
lcd.setCursor(0, 1);
|
||||||
|
// print to the second line
|
||||||
|
lcd.print("Crystal Ball!");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// check the status of the switch
|
||||||
|
switchState = digitalRead(switchPin);
|
||||||
|
|
||||||
|
// compare the switchState to its previous state
|
||||||
|
if (switchState != prevSwitchState) {
|
||||||
|
// if the state has changed from HIGH to LOW
|
||||||
|
// you know that the ball has been tilted from
|
||||||
|
// one direction to the other
|
||||||
|
if (switchState == LOW) {
|
||||||
|
// randomly chose a reply
|
||||||
|
reply = random(8);
|
||||||
|
// clean up the screen before printing a new reply
|
||||||
|
lcd.clear();
|
||||||
|
// set the cursor to column 0, line 0
|
||||||
|
lcd.setCursor(0, 0);
|
||||||
|
// print some text
|
||||||
|
lcd.print("the ball says:");
|
||||||
|
// move the cursor to the second line
|
||||||
|
lcd.setCursor(0, 1);
|
||||||
|
|
||||||
|
// choose a saying to print baed on the value in reply
|
||||||
|
switch(reply){
|
||||||
|
case 0:
|
||||||
|
lcd.print("Yes");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
lcd.print("Most likely");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
lcd.print("Certainly");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
lcd.print("Outlook good");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
lcd.print("Unsure");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 5:
|
||||||
|
lcd.print("Ask again");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 6:
|
||||||
|
lcd.print("Doubtful");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 7:
|
||||||
|
lcd.print("No");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// save the current switch state as the last state
|
||||||
|
prevSwitchState = switchState;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,172 @@
|
|||||||
|
/*
|
||||||
|
Arduino Starter Kit example
|
||||||
|
Project 12 - Knock Lock
|
||||||
|
|
||||||
|
This sketch is written to accompany Project 12 in the
|
||||||
|
Arduino Starter Kit
|
||||||
|
|
||||||
|
Parts required:
|
||||||
|
1 Megohm resistor
|
||||||
|
10 kilohm resistor
|
||||||
|
three 220 ohm resistors
|
||||||
|
piezo
|
||||||
|
servo motor
|
||||||
|
push button
|
||||||
|
one red LED
|
||||||
|
one yellow LED
|
||||||
|
one green LED
|
||||||
|
100 uF capacitor
|
||||||
|
|
||||||
|
Created 18 September 2012
|
||||||
|
by Scott Fitzgerald
|
||||||
|
Thanks to Federico Vanzati for improvements
|
||||||
|
|
||||||
|
http://arduino.cc/starterKit
|
||||||
|
|
||||||
|
This example code is part of the public domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
// import the library
|
||||||
|
#include <Servo.h>
|
||||||
|
// create an instance of the servo library
|
||||||
|
Servo myServo;
|
||||||
|
|
||||||
|
const int piezo = A0; // pin the piezo is attached to
|
||||||
|
const int switchPin = 2; // pin the switch is attached to
|
||||||
|
const int yellowLed = 3; // pin the yellow LED is attached to
|
||||||
|
const int greenLed = 4; // pin the green LED is attached to
|
||||||
|
const int redLed = 5; // pin the red LED is attached to
|
||||||
|
|
||||||
|
// variable for the piezo value
|
||||||
|
int knockVal;
|
||||||
|
// variable for the switch value
|
||||||
|
int switchVal;
|
||||||
|
|
||||||
|
// variables for the high and low limits of the knock value
|
||||||
|
const int quietKnock = 10;
|
||||||
|
const int loudKnock = 100;
|
||||||
|
|
||||||
|
// variable to indicate if locked or not
|
||||||
|
boolean locked = false;
|
||||||
|
// how many valid knocks you've received
|
||||||
|
int numberOfKnocks = 0;
|
||||||
|
|
||||||
|
void setup(){
|
||||||
|
// attach the servo to pin 9
|
||||||
|
myServo.attach(9);
|
||||||
|
|
||||||
|
// make the LED pins outputs
|
||||||
|
pinMode(yellowLed, OUTPUT);
|
||||||
|
pinMode(redLed, OUTPUT);
|
||||||
|
pinMode(greenLed, OUTPUT);
|
||||||
|
|
||||||
|
// set the switch pin as an input
|
||||||
|
pinMode(switchPin, INPUT);
|
||||||
|
|
||||||
|
// start serial communication for debugging
|
||||||
|
Serial.begin(9600);
|
||||||
|
|
||||||
|
// turn the green LED on
|
||||||
|
digitalWrite(greenLed, HIGH);
|
||||||
|
|
||||||
|
// move the servo to the unlocked position
|
||||||
|
myServo.write(0);
|
||||||
|
|
||||||
|
// print status to the serial monitor
|
||||||
|
Serial.println("the box is unlocked!");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(){
|
||||||
|
|
||||||
|
// if the box is unlocked
|
||||||
|
if(locked == false){
|
||||||
|
|
||||||
|
// read the value of the switch pin
|
||||||
|
switchVal = digitalRead(switchPin);
|
||||||
|
|
||||||
|
// if the button is pressed, lock the box
|
||||||
|
if(switchVal == HIGH){
|
||||||
|
// set the locked variable to "true"
|
||||||
|
locked = true;
|
||||||
|
|
||||||
|
// change the status LEDs
|
||||||
|
digitalWrite(greenLed,LOW);
|
||||||
|
digitalWrite(redLed,HIGH);
|
||||||
|
|
||||||
|
// move the servo to the locked position
|
||||||
|
myServo.write(90);
|
||||||
|
|
||||||
|
// print out status
|
||||||
|
Serial.println("the box is locked!");
|
||||||
|
|
||||||
|
// wait for the servo to move into position
|
||||||
|
delay (1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the box is locked
|
||||||
|
if(locked == true){
|
||||||
|
|
||||||
|
// check the value of the piezo
|
||||||
|
knockVal = analogRead(piezo);
|
||||||
|
|
||||||
|
// if there are not enough valid knocks
|
||||||
|
if(numberOfKnocks < 3 && knockVal > 0){
|
||||||
|
|
||||||
|
// check to see if the knock is in range
|
||||||
|
if(checkForKnock(knockVal) == true){
|
||||||
|
|
||||||
|
// increment the number of valid knocks
|
||||||
|
numberOfKnocks++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// print status of knocks
|
||||||
|
Serial.print(3 - numberOfKnocks);
|
||||||
|
Serial.println(" more knocks to go");
|
||||||
|
}
|
||||||
|
|
||||||
|
// if there are three knocks
|
||||||
|
if(numberOfKnocks >= 3){
|
||||||
|
// unlock the box
|
||||||
|
locked = false;
|
||||||
|
|
||||||
|
// move the servo to the unlocked position
|
||||||
|
myServo.write(0);
|
||||||
|
|
||||||
|
// wait for it to move
|
||||||
|
delay(20);
|
||||||
|
|
||||||
|
// change status LEDs
|
||||||
|
digitalWrite(greenLed,HIGH);
|
||||||
|
digitalWrite(redLed,LOW);
|
||||||
|
Serial.println("the box is unlocked!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// this function checks to see if a
|
||||||
|
// detected knock is within max and min range
|
||||||
|
boolean checkForKnock(int value){
|
||||||
|
// if the value of the knock is greater than
|
||||||
|
// the minimum, and larger than the maximum
|
||||||
|
if(value > quietKnock && value < loudKnock){
|
||||||
|
// turn the status LED on
|
||||||
|
digitalWrite(yellowLed, HIGH);
|
||||||
|
delay(50);
|
||||||
|
digitalWrite(yellowLed, LOW);
|
||||||
|
// print out the status
|
||||||
|
Serial.print("Valid knock of value ");
|
||||||
|
Serial.println(value);
|
||||||
|
// return true
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// if the knock is not within range
|
||||||
|
else {
|
||||||
|
// print status
|
||||||
|
Serial.print("Bad knock value ");
|
||||||
|
Serial.println(value);
|
||||||
|
// return false
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,71 @@
|
|||||||
|
/*
|
||||||
|
Arduino Starter Kit example
|
||||||
|
Project 13 - Touch Sensor Lamp
|
||||||
|
|
||||||
|
This sketch is written to accompany Project 13 in the
|
||||||
|
Arduino Starter Kit
|
||||||
|
|
||||||
|
Parts required:
|
||||||
|
1 Megohm resistor
|
||||||
|
metal foil or copper mesh
|
||||||
|
220 ohm resistor
|
||||||
|
LED
|
||||||
|
|
||||||
|
Software required :
|
||||||
|
CapacitiveSensor library by Paul Badger
|
||||||
|
http://arduino.cc/playground/Main/CapacitiveSensor
|
||||||
|
|
||||||
|
Created 18 September 2012
|
||||||
|
by Scott Fitzgerald
|
||||||
|
|
||||||
|
http://arduino.cc/starterKit
|
||||||
|
|
||||||
|
This example code is part of the public domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
// import the library (must be located in the
|
||||||
|
// Arduino/libraries directory)
|
||||||
|
#include <CapacitiveSensor.h>
|
||||||
|
|
||||||
|
// create an instance of the library
|
||||||
|
// pin 4 sends electrical energy
|
||||||
|
// pin 2 senses senses a change
|
||||||
|
CapacitiveSensor capSensor = CapacitiveSensor(4,2);
|
||||||
|
|
||||||
|
// threshold for turning the lamp on
|
||||||
|
int threshold = 1000;
|
||||||
|
|
||||||
|
// pin the LED is connected to
|
||||||
|
const int ledPin = 12;
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// open a serial connection
|
||||||
|
Serial.begin(9600);
|
||||||
|
// set the LED pin as an output
|
||||||
|
pinMode(ledPin, OUTPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// store the value reported by the sensor in a variable
|
||||||
|
long sensorValue = capSensor.capacitiveSensor(30);
|
||||||
|
|
||||||
|
// print out the sensor value
|
||||||
|
Serial.println(sensorValue);
|
||||||
|
|
||||||
|
// if the value is greater than the threshold
|
||||||
|
if(sensorValue > threshold) {
|
||||||
|
// turn the LED on
|
||||||
|
digitalWrite(ledPin, HIGH);
|
||||||
|
}
|
||||||
|
// if it's lower than the threshold
|
||||||
|
else {
|
||||||
|
// turn the LED off
|
||||||
|
digitalWrite(ledPin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,104 @@
|
|||||||
|
/*
|
||||||
|
Arduino Starter Kit example
|
||||||
|
Project 14 - Tweak the Arduino Logo
|
||||||
|
|
||||||
|
This sketch is written to accompany Project 14 in the
|
||||||
|
Arduino Starter Kit
|
||||||
|
|
||||||
|
Parts required:
|
||||||
|
10 kilohm potentiometer
|
||||||
|
|
||||||
|
Software required :
|
||||||
|
Processing http://processing.org
|
||||||
|
Active internet connection
|
||||||
|
|
||||||
|
Created 18 September 2012
|
||||||
|
by Scott Fitzgerald
|
||||||
|
|
||||||
|
http://arduino.cc/starterKit
|
||||||
|
|
||||||
|
This example code is part of the public domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// initialize serial communication
|
||||||
|
Serial.begin(9600);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// read the value of A0, divide by 4 and
|
||||||
|
// send it as a byte over the serial connection
|
||||||
|
Serial.write(analogRead(A0)/4);
|
||||||
|
delay(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Processing code for this example
|
||||||
|
// Tweak the Arduno Logo
|
||||||
|
// by Scott Fitzgerald
|
||||||
|
// This example code is in the public domain
|
||||||
|
|
||||||
|
// import the serial library
|
||||||
|
import processing.serial.*;
|
||||||
|
|
||||||
|
// create an instance of the serial library
|
||||||
|
Serial myPort;
|
||||||
|
|
||||||
|
// create an instance of PImage
|
||||||
|
PImage logo;
|
||||||
|
|
||||||
|
// a variable to hold the background color
|
||||||
|
int bgcolor = 0;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// set the color mode to Hue/Saturation/Brightness
|
||||||
|
colorMode(HSB, 255);
|
||||||
|
|
||||||
|
// load the Arduino logo into the PImage instance
|
||||||
|
logo = loadImage("http://arduino.cc/en/pub/skins/arduinoWide/img/logo.png");
|
||||||
|
|
||||||
|
// make the window the same size as the image
|
||||||
|
size(logo.width, logo.height);
|
||||||
|
|
||||||
|
// print a list of available serial ports to the
|
||||||
|
// Processing staus window
|
||||||
|
println("Available serial ports:");
|
||||||
|
println(Serial.list());
|
||||||
|
|
||||||
|
// Tell the serial object the information it needs to communicate
|
||||||
|
// with the Arduno. Change Serial.list()[0] to the correct
|
||||||
|
// 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.
|
||||||
|
myPort = 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() {
|
||||||
|
|
||||||
|
// if there is information in the serial port
|
||||||
|
if ( myPort.available() > 0) {
|
||||||
|
// read the value and store it in a variable
|
||||||
|
bgcolor = myPort.read();
|
||||||
|
|
||||||
|
// print the value to the status window
|
||||||
|
println(bgcolor);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw the background. the variable bgcolor
|
||||||
|
// contains the Hue, determined by the value
|
||||||
|
// from the serial port
|
||||||
|
background(bgcolor, 255, 255);
|
||||||
|
|
||||||
|
// draw the Arduino logo
|
||||||
|
image(logo, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
Arduino Starter Kit example
|
||||||
|
Project 15 - Hacking Buttons
|
||||||
|
|
||||||
|
This sketch is written to accompany Project 15 in the
|
||||||
|
Arduino Starter Kit
|
||||||
|
|
||||||
|
Parts required:
|
||||||
|
batery powered component
|
||||||
|
220 ohm resistor
|
||||||
|
4N35 optocoupler
|
||||||
|
|
||||||
|
Created 18 September 2012
|
||||||
|
by Scott Fitzgerald
|
||||||
|
|
||||||
|
http://arduino.cc/starterKit
|
||||||
|
|
||||||
|
This example code is part of the public domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
const int optoPin = 2; // the pin the optocoupler is connected to
|
||||||
|
|
||||||
|
void setup(){
|
||||||
|
// make the pin with the optocoupler an output
|
||||||
|
pinMode(optoPin, OUTPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(){
|
||||||
|
digitalWrite(optoPin, HIGH); // pull pin 2 HIGH, activating the optocoupler
|
||||||
|
|
||||||
|
delay(15); // give the optocoupler a moment to activate
|
||||||
|
|
||||||
|
digitalWrite(optoPin, LOW); // pull pin 2 low until you're ready to activate again
|
||||||
|
delay(21000); // wait for 21 seconds
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
@ -120,7 +120,7 @@ mega2560.cpu=2560 or ADK
|
|||||||
mega2560.container=Arduino Mega
|
mega2560.container=Arduino Mega
|
||||||
|
|
||||||
mega2560.upload.tool=avrdude
|
mega2560.upload.tool=avrdude
|
||||||
mega2560.upload.protocol=stk500v2
|
mega2560.upload.protocol=wiring
|
||||||
mega2560.upload.maximum_size=258048
|
mega2560.upload.maximum_size=258048
|
||||||
mega2560.upload.speed=115200
|
mega2560.upload.speed=115200
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ extern "C"{
|
|||||||
#define EXTERNAL 1
|
#define EXTERNAL 1
|
||||||
#define INTERNAL 2
|
#define INTERNAL 2
|
||||||
#else
|
#else
|
||||||
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284P__)
|
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__)
|
||||||
#define INTERNAL1V1 2
|
#define INTERNAL1V1 2
|
||||||
#define INTERNAL2V56 3
|
#define INTERNAL2V56 3
|
||||||
#else
|
#else
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
Modified 23 November 2006 by David A. Mellis
|
Modified 23 November 2006 by David A. Mellis
|
||||||
Modified 28 September 2010 by Mark Sproul
|
Modified 28 September 2010 by Mark Sproul
|
||||||
|
Modified 14 August 2012 by Alarus
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -109,13 +110,22 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#if defined(UDR0)
|
#if defined(UDR0)
|
||||||
unsigned char c = UDR0;
|
if (bit_is_clear(UCSR0A, UPE0)) {
|
||||||
|
unsigned char c = UDR0;
|
||||||
|
store_char(c, &rx_buffer);
|
||||||
|
} else {
|
||||||
|
unsigned char c = UDR0;
|
||||||
|
};
|
||||||
#elif defined(UDR)
|
#elif defined(UDR)
|
||||||
unsigned char c = UDR;
|
if (bit_is_clear(UCSRA, PE)) {
|
||||||
|
unsigned char c = UDR;
|
||||||
|
store_char(c, &rx_buffer);
|
||||||
|
} else {
|
||||||
|
unsigned char c = UDR;
|
||||||
|
};
|
||||||
#else
|
#else
|
||||||
#error UDR not defined
|
#error UDR not defined
|
||||||
#endif
|
#endif
|
||||||
store_char(c, &rx_buffer);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@ -126,8 +136,12 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
|
|||||||
#define serialEvent1_implemented
|
#define serialEvent1_implemented
|
||||||
SIGNAL(USART1_RX_vect)
|
SIGNAL(USART1_RX_vect)
|
||||||
{
|
{
|
||||||
unsigned char c = UDR1;
|
if (bit_is_clear(UCSR1A, UPE1)) {
|
||||||
store_char(c, &rx_buffer1);
|
unsigned char c = UDR1;
|
||||||
|
store_char(c, &rx_buffer1);
|
||||||
|
} else {
|
||||||
|
unsigned char c = UDR1;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
#elif defined(SIG_USART1_RECV)
|
#elif defined(SIG_USART1_RECV)
|
||||||
#error SIG_USART1_RECV
|
#error SIG_USART1_RECV
|
||||||
@ -139,8 +153,12 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
|
|||||||
#define serialEvent2_implemented
|
#define serialEvent2_implemented
|
||||||
SIGNAL(USART2_RX_vect)
|
SIGNAL(USART2_RX_vect)
|
||||||
{
|
{
|
||||||
unsigned char c = UDR2;
|
if (bit_is_clear(UCSR2A, UPE2)) {
|
||||||
store_char(c, &rx_buffer2);
|
unsigned char c = UDR2;
|
||||||
|
store_char(c, &rx_buffer2);
|
||||||
|
} else {
|
||||||
|
unsigned char c = UDR2;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
#elif defined(SIG_USART2_RECV)
|
#elif defined(SIG_USART2_RECV)
|
||||||
#error SIG_USART2_RECV
|
#error SIG_USART2_RECV
|
||||||
@ -152,8 +170,12 @@ inline void store_char(unsigned char c, ring_buffer *buffer)
|
|||||||
#define serialEvent3_implemented
|
#define serialEvent3_implemented
|
||||||
SIGNAL(USART3_RX_vect)
|
SIGNAL(USART3_RX_vect)
|
||||||
{
|
{
|
||||||
unsigned char c = UDR3;
|
if (bit_is_clear(UCSR3A, UPE3)) {
|
||||||
store_char(c, &rx_buffer3);
|
unsigned char c = UDR3;
|
||||||
|
store_char(c, &rx_buffer3);
|
||||||
|
} else {
|
||||||
|
unsigned char c = UDR3;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
#elif defined(SIG_USART3_RECV)
|
#elif defined(SIG_USART3_RECV)
|
||||||
#error SIG_USART3_RECV
|
#error SIG_USART3_RECV
|
||||||
@ -274,7 +296,7 @@ ISR(USART3_UDRE_vect)
|
|||||||
HardwareSerial::HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer,
|
HardwareSerial::HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer,
|
||||||
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
|
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
|
||||||
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
|
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
|
||||||
volatile uint8_t *udr,
|
volatile uint8_t *ucsrc, volatile uint8_t *udr,
|
||||||
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x)
|
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x)
|
||||||
{
|
{
|
||||||
_rx_buffer = rx_buffer;
|
_rx_buffer = rx_buffer;
|
||||||
@ -283,6 +305,7 @@ HardwareSerial::HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer,
|
|||||||
_ubrrl = ubrrl;
|
_ubrrl = ubrrl;
|
||||||
_ucsra = ucsra;
|
_ucsra = ucsra;
|
||||||
_ucsrb = ucsrb;
|
_ucsrb = ucsrb;
|
||||||
|
_ucsrc = ucsrc;
|
||||||
_udr = udr;
|
_udr = udr;
|
||||||
_rxen = rxen;
|
_rxen = rxen;
|
||||||
_txen = txen;
|
_txen = txen;
|
||||||
@ -327,6 +350,55 @@ try_again:
|
|||||||
*_ubrrh = baud_setting >> 8;
|
*_ubrrh = baud_setting >> 8;
|
||||||
*_ubrrl = baud_setting;
|
*_ubrrl = baud_setting;
|
||||||
|
|
||||||
|
transmitting = false;
|
||||||
|
|
||||||
|
sbi(*_ucsrb, _rxen);
|
||||||
|
sbi(*_ucsrb, _txen);
|
||||||
|
sbi(*_ucsrb, _rxcie);
|
||||||
|
cbi(*_ucsrb, _udrie);
|
||||||
|
}
|
||||||
|
|
||||||
|
void HardwareSerial::begin(unsigned long baud, byte config)
|
||||||
|
{
|
||||||
|
uint16_t baud_setting;
|
||||||
|
uint8_t current_config;
|
||||||
|
bool use_u2x = true;
|
||||||
|
|
||||||
|
#if F_CPU == 16000000UL
|
||||||
|
// hardcoded exception for compatibility with the bootloader shipped
|
||||||
|
// with the Duemilanove and previous boards and the firmware on the 8U2
|
||||||
|
// on the Uno and Mega 2560.
|
||||||
|
if (baud == 57600) {
|
||||||
|
use_u2x = false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
try_again:
|
||||||
|
|
||||||
|
if (use_u2x) {
|
||||||
|
*_ucsra = 1 << _u2x;
|
||||||
|
baud_setting = (F_CPU / 4 / baud - 1) / 2;
|
||||||
|
} else {
|
||||||
|
*_ucsra = 0;
|
||||||
|
baud_setting = (F_CPU / 8 / baud - 1) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((baud_setting > 4095) && use_u2x)
|
||||||
|
{
|
||||||
|
use_u2x = false;
|
||||||
|
goto try_again;
|
||||||
|
}
|
||||||
|
|
||||||
|
// assign the baud_setting, a.k.a. ubbr (USART Baud Rate Register)
|
||||||
|
*_ubrrh = baud_setting >> 8;
|
||||||
|
*_ubrrl = baud_setting;
|
||||||
|
|
||||||
|
//set the data bits, parity, and stop bits
|
||||||
|
#if defined(__AVR_ATmega8__)
|
||||||
|
config |= 0x80; // select UCSRC register (shared with UBRRH)
|
||||||
|
#endif
|
||||||
|
*_ucsrc = config;
|
||||||
|
|
||||||
sbi(*_ucsrb, _rxen);
|
sbi(*_ucsrb, _rxen);
|
||||||
sbi(*_ucsrb, _txen);
|
sbi(*_ucsrb, _txen);
|
||||||
sbi(*_ucsrb, _rxcie);
|
sbi(*_ucsrb, _rxcie);
|
||||||
@ -376,8 +448,9 @@ int HardwareSerial::read(void)
|
|||||||
|
|
||||||
void HardwareSerial::flush()
|
void HardwareSerial::flush()
|
||||||
{
|
{
|
||||||
while (_tx_buffer->head != _tx_buffer->tail)
|
// UDR is kept full while the buffer is not empty, so TXC triggers when EMPTY && SENT
|
||||||
;
|
while (transmitting && ! (*_ucsra & _BV(TXC0)));
|
||||||
|
transmitting = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t HardwareSerial::write(uint8_t c)
|
size_t HardwareSerial::write(uint8_t c)
|
||||||
@ -394,6 +467,9 @@ size_t HardwareSerial::write(uint8_t c)
|
|||||||
_tx_buffer->head = i;
|
_tx_buffer->head = i;
|
||||||
|
|
||||||
sbi(*_ucsrb, _udrie);
|
sbi(*_ucsrb, _udrie);
|
||||||
|
// clear the TXC bit -- "can be cleared by writing a one to its bit location"
|
||||||
|
transmitting = true;
|
||||||
|
sbi(*_ucsra, TXC0);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -405,9 +481,9 @@ HardwareSerial::operator bool() {
|
|||||||
// Preinstantiate Objects //////////////////////////////////////////////////////
|
// Preinstantiate Objects //////////////////////////////////////////////////////
|
||||||
|
|
||||||
#if defined(UBRRH) && defined(UBRRL)
|
#if defined(UBRRH) && defined(UBRRL)
|
||||||
HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UDR, RXEN, TXEN, RXCIE, UDRIE, U2X);
|
HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRRH, &UBRRL, &UCSRA, &UCSRB, &UCSRC, &UDR, RXEN, TXEN, RXCIE, UDRIE, U2X);
|
||||||
#elif defined(UBRR0H) && defined(UBRR0L)
|
#elif defined(UBRR0H) && defined(UBRR0L)
|
||||||
HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UDR0, RXEN0, TXEN0, RXCIE0, UDRIE0, U2X0);
|
HardwareSerial Serial(&rx_buffer, &tx_buffer, &UBRR0H, &UBRR0L, &UCSR0A, &UCSR0B, &UCSR0C, &UDR0, RXEN0, TXEN0, RXCIE0, UDRIE0, U2X0);
|
||||||
#elif defined(USBCON)
|
#elif defined(USBCON)
|
||||||
// do nothing - Serial object and buffers are initialized in CDC code
|
// do nothing - Serial object and buffers are initialized in CDC code
|
||||||
#else
|
#else
|
||||||
@ -415,13 +491,13 @@ HardwareSerial::operator bool() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(UBRR1H)
|
#if defined(UBRR1H)
|
||||||
HardwareSerial Serial1(&rx_buffer1, &tx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRIE1, U2X1);
|
HardwareSerial Serial1(&rx_buffer1, &tx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UCSR1C, &UDR1, RXEN1, TXEN1, RXCIE1, UDRIE1, U2X1);
|
||||||
#endif
|
#endif
|
||||||
#if defined(UBRR2H)
|
#if defined(UBRR2H)
|
||||||
HardwareSerial Serial2(&rx_buffer2, &tx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UDR2, RXEN2, TXEN2, RXCIE2, UDRIE2, U2X2);
|
HardwareSerial Serial2(&rx_buffer2, &tx_buffer2, &UBRR2H, &UBRR2L, &UCSR2A, &UCSR2B, &UCSR2C, &UDR2, RXEN2, TXEN2, RXCIE2, UDRIE2, U2X2);
|
||||||
#endif
|
#endif
|
||||||
#if defined(UBRR3H)
|
#if defined(UBRR3H)
|
||||||
HardwareSerial Serial3(&rx_buffer3, &tx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UDR3, RXEN3, TXEN3, RXCIE3, UDRIE3, U2X3);
|
HardwareSerial Serial3(&rx_buffer3, &tx_buffer3, &UBRR3H, &UBRR3L, &UCSR3A, &UCSR3B, &UCSR3C, &UDR3, RXEN3, TXEN3, RXCIE3, UDRIE3, U2X3);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // whole file
|
#endif // whole file
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
Modified 28 September 2010 by Mark Sproul
|
Modified 28 September 2010 by Mark Sproul
|
||||||
|
Modified 14 August 2012 by Alarus
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef HardwareSerial_h
|
#ifndef HardwareSerial_h
|
||||||
@ -37,29 +38,62 @@ class HardwareSerial : public Stream
|
|||||||
volatile uint8_t *_ubrrl;
|
volatile uint8_t *_ubrrl;
|
||||||
volatile uint8_t *_ucsra;
|
volatile uint8_t *_ucsra;
|
||||||
volatile uint8_t *_ucsrb;
|
volatile uint8_t *_ucsrb;
|
||||||
|
volatile uint8_t *_ucsrc;
|
||||||
volatile uint8_t *_udr;
|
volatile uint8_t *_udr;
|
||||||
uint8_t _rxen;
|
uint8_t _rxen;
|
||||||
uint8_t _txen;
|
uint8_t _txen;
|
||||||
uint8_t _rxcie;
|
uint8_t _rxcie;
|
||||||
uint8_t _udrie;
|
uint8_t _udrie;
|
||||||
uint8_t _u2x;
|
uint8_t _u2x;
|
||||||
|
bool transmitting;
|
||||||
public:
|
public:
|
||||||
HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer,
|
HardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer,
|
||||||
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
|
volatile uint8_t *ubrrh, volatile uint8_t *ubrrl,
|
||||||
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
|
volatile uint8_t *ucsra, volatile uint8_t *ucsrb,
|
||||||
volatile uint8_t *udr,
|
volatile uint8_t *ucsrc, volatile uint8_t *udr,
|
||||||
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x);
|
uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x);
|
||||||
void begin(unsigned long);
|
void begin(unsigned long);
|
||||||
|
void begin(unsigned long, byte);
|
||||||
void end();
|
void end();
|
||||||
virtual int available(void);
|
virtual int available(void);
|
||||||
virtual int peek(void);
|
virtual int peek(void);
|
||||||
virtual int read(void);
|
virtual int read(void);
|
||||||
virtual void flush(void);
|
virtual void flush(void);
|
||||||
virtual size_t write(uint8_t);
|
virtual size_t write(uint8_t);
|
||||||
|
inline size_t write(unsigned long n) { return write((uint8_t)n); }
|
||||||
|
inline size_t write(long n) { return write((uint8_t)n); }
|
||||||
|
inline size_t write(unsigned int n) { return write((uint8_t)n); }
|
||||||
|
inline size_t write(int n) { return write((uint8_t)n); }
|
||||||
using Print::write; // pull in write(str) and write(buf, size) from Print
|
using Print::write; // pull in write(str) and write(buf, size) from Print
|
||||||
operator bool();
|
operator bool();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Define config for Serial.begin(baud, config);
|
||||||
|
#define SERIAL_5N1 0x00
|
||||||
|
#define SERIAL_6N1 0x02
|
||||||
|
#define SERIAL_7N1 0x04
|
||||||
|
#define SERIAL_8N1 0x06
|
||||||
|
#define SERIAL_5N2 0x08
|
||||||
|
#define SERIAL_6N2 0x0A
|
||||||
|
#define SERIAL_7N2 0x0C
|
||||||
|
#define SERIAL_8N2 0x0E
|
||||||
|
#define SERIAL_5E1 0x20
|
||||||
|
#define SERIAL_6E1 0x22
|
||||||
|
#define SERIAL_7E1 0x24
|
||||||
|
#define SERIAL_8E1 0x26
|
||||||
|
#define SERIAL_5E2 0x28
|
||||||
|
#define SERIAL_6E2 0x2A
|
||||||
|
#define SERIAL_7E2 0x2C
|
||||||
|
#define SERIAL_8E2 0x2E
|
||||||
|
#define SERIAL_5O1 0x30
|
||||||
|
#define SERIAL_6O1 0x32
|
||||||
|
#define SERIAL_7O1 0x34
|
||||||
|
#define SERIAL_8O1 0x36
|
||||||
|
#define SERIAL_5O2 0x38
|
||||||
|
#define SERIAL_6O2 0x3A
|
||||||
|
#define SERIAL_7O2 0x3C
|
||||||
|
#define SERIAL_8O2 0x3E
|
||||||
|
|
||||||
#if defined(UBRRH) || defined(UBRR0H)
|
#if defined(UBRRH) || defined(UBRR0H)
|
||||||
extern HardwareSerial Serial;
|
extern HardwareSerial Serial;
|
||||||
#elif defined(USBCON)
|
#elif defined(USBCON)
|
||||||
@ -76,6 +110,22 @@ class HardwareSerial : public Stream
|
|||||||
extern HardwareSerial Serial3;
|
extern HardwareSerial Serial3;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* on ATmega8, the uart and its bits are not numbered, so there is no "TXC0"
|
||||||
|
* definition. It is slightly cleaner to define this here instead of having
|
||||||
|
* conditional code in the cpp module.
|
||||||
|
*/
|
||||||
|
#if !defined(TXC0)
|
||||||
|
#if defined(TXC)
|
||||||
|
#define TXC0 TXC
|
||||||
|
#elif defined(TXC1)
|
||||||
|
// Some devices have uart1 but no uart0
|
||||||
|
#define TXC0 TXC1
|
||||||
|
#else
|
||||||
|
#error TXC0 not definable in HardwareSerial.h
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
extern void serialEventRun(void) __attribute__((weak));
|
extern void serialEventRun(void) __attribute__((weak));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -603,7 +603,7 @@ ISR(USB_GEN_vect)
|
|||||||
{
|
{
|
||||||
#ifdef CDC_ENABLED
|
#ifdef CDC_ENABLED
|
||||||
USB_Flush(CDC_TX); // Send a tx frame if found
|
USB_Flush(CDC_TX); // Send a tx frame if found
|
||||||
while (USB_Available(CDC_RX)) // Handle received bytes (if any)
|
if (USB_Available(CDC_RX)) // Handle received bytes (if any)
|
||||||
Serial.accept();
|
Serial.accept();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ int analogRead(uint8_t pin)
|
|||||||
if (pin >= 54) pin -= 54; // allow for channel or pin numbers
|
if (pin >= 54) pin -= 54; // allow for channel or pin numbers
|
||||||
#elif defined(__AVR_ATmega32U4__)
|
#elif defined(__AVR_ATmega32U4__)
|
||||||
if (pin >= 18) pin -= 18; // allow for channel or pin numbers
|
if (pin >= 18) pin -= 18; // allow for channel or pin numbers
|
||||||
#elif defined(__AVR_ATmega1284__)
|
#elif defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__)
|
||||||
if (pin >= 24) pin -= 24; // allow for channel or pin numbers
|
if (pin >= 24) pin -= 24; // allow for channel or pin numbers
|
||||||
#else
|
#else
|
||||||
if (pin >= 14) pin -= 14; // allow for channel or pin numbers
|
if (pin >= 14) pin -= 14; // allow for channel or pin numbers
|
||||||
|
@ -54,7 +54,7 @@ extern "C"{
|
|||||||
|
|
||||||
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
||||||
#define EXTERNAL_NUM_INTERRUPTS 8
|
#define EXTERNAL_NUM_INTERRUPTS 8
|
||||||
#elif defined(__AVR_ATmega1284P__)
|
#elif defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644P__)
|
||||||
#define EXTERNAL_NUM_INTERRUPTS 3
|
#define EXTERNAL_NUM_INTERRUPTS 3
|
||||||
#elif defined(__AVR_ATmega32U4__)
|
#elif defined(__AVR_ATmega32U4__)
|
||||||
#define EXTERNAL_NUM_INTERRUPTS 4
|
#define EXTERNAL_NUM_INTERRUPTS 4
|
||||||
|
@ -65,9 +65,8 @@
|
|||||||
typedef enum { _timer5, _timer1, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t ;
|
typedef enum { _timer5, _timer1, _timer3, _timer4, _Nbr_16timers } timer16_Sequence_t ;
|
||||||
|
|
||||||
#elif defined(__AVR_ATmega32U4__)
|
#elif defined(__AVR_ATmega32U4__)
|
||||||
#define _useTimer3
|
|
||||||
#define _useTimer1
|
#define _useTimer1
|
||||||
typedef enum { _timer3, _timer1, _Nbr_16timers } timer16_Sequence_t ;
|
typedef enum { _timer1, _Nbr_16timers } timer16_Sequence_t ;
|
||||||
|
|
||||||
#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
|
#elif defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
|
||||||
#define _useTimer3
|
#define _useTimer3
|
||||||
@ -124,4 +123,4 @@ private:
|
|||||||
int8_t max; // maximum is this value times 4 added to MAX_PULSE_WIDTH
|
int8_t max; // maximum is this value times 4 added to MAX_PULSE_WIDTH
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -27,6 +27,69 @@
|
|||||||
|
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
|
// Workaround for wrong definitions in "iom32u4.h".
|
||||||
|
// This should be fixed in the AVR toolchain.
|
||||||
|
#undef UHCON
|
||||||
|
#undef UHINT
|
||||||
|
#undef UHIEN
|
||||||
|
#undef UHADDR
|
||||||
|
#undef UHFNUM
|
||||||
|
#undef UHFNUML
|
||||||
|
#undef UHFNUMH
|
||||||
|
#undef UHFLEN
|
||||||
|
#undef UPINRQX
|
||||||
|
#undef UPINTX
|
||||||
|
#undef UPNUM
|
||||||
|
#undef UPRST
|
||||||
|
#undef UPCONX
|
||||||
|
#undef UPCFG0X
|
||||||
|
#undef UPCFG1X
|
||||||
|
#undef UPSTAX
|
||||||
|
#undef UPCFG2X
|
||||||
|
#undef UPIENX
|
||||||
|
#undef UPDATX
|
||||||
|
#undef TCCR2A
|
||||||
|
#undef WGM20
|
||||||
|
#undef WGM21
|
||||||
|
#undef COM2B0
|
||||||
|
#undef COM2B1
|
||||||
|
#undef COM2A0
|
||||||
|
#undef COM2A1
|
||||||
|
#undef TCCR2B
|
||||||
|
#undef CS20
|
||||||
|
#undef CS21
|
||||||
|
#undef CS22
|
||||||
|
#undef WGM22
|
||||||
|
#undef FOC2B
|
||||||
|
#undef FOC2A
|
||||||
|
#undef TCNT2
|
||||||
|
#undef TCNT2_0
|
||||||
|
#undef TCNT2_1
|
||||||
|
#undef TCNT2_2
|
||||||
|
#undef TCNT2_3
|
||||||
|
#undef TCNT2_4
|
||||||
|
#undef TCNT2_5
|
||||||
|
#undef TCNT2_6
|
||||||
|
#undef TCNT2_7
|
||||||
|
#undef OCR2A
|
||||||
|
#undef OCR2_0
|
||||||
|
#undef OCR2_1
|
||||||
|
#undef OCR2_2
|
||||||
|
#undef OCR2_3
|
||||||
|
#undef OCR2_4
|
||||||
|
#undef OCR2_5
|
||||||
|
#undef OCR2_6
|
||||||
|
#undef OCR2_7
|
||||||
|
#undef OCR2B
|
||||||
|
#undef OCR2_0
|
||||||
|
#undef OCR2_1
|
||||||
|
#undef OCR2_2
|
||||||
|
#undef OCR2_3
|
||||||
|
#undef OCR2_4
|
||||||
|
#undef OCR2_5
|
||||||
|
#undef OCR2_6
|
||||||
|
#undef OCR2_7
|
||||||
|
|
||||||
#define TX_RX_LED_INIT DDRD |= (1<<5), DDRB |= (1<<0)
|
#define TX_RX_LED_INIT DDRD |= (1<<5), DDRB |= (1<<0)
|
||||||
#define TXLED0 PORTD |= (1<<5)
|
#define TXLED0 PORTD |= (1<<5)
|
||||||
#define TXLED1 PORTD &= ~(1<<5)
|
#define TXLED1 PORTD &= ~(1<<5)
|
||||||
|
BIN
hardware/arduino/firmwares/wifishield/binary/wifiHD.elf
Normal file
BIN
hardware/arduino/firmwares/wifishield/binary/wifiHD.elf
Normal file
Binary file not shown.
15921
hardware/arduino/firmwares/wifishield/binary/wifiHD.hex
Normal file
15921
hardware/arduino/firmwares/wifishield/binary/wifiHD.hex
Normal file
File diff suppressed because it is too large
Load Diff
BIN
hardware/arduino/firmwares/wifishield/binary/wifiHD_2_1.elf
Normal file
BIN
hardware/arduino/firmwares/wifishield/binary/wifiHD_2_1.elf
Normal file
Binary file not shown.
BIN
hardware/arduino/firmwares/wifishield/binary/wifi_dnld.elf
Normal file
BIN
hardware/arduino/firmwares/wifishield/binary/wifi_dnld.elf
Normal file
Binary file not shown.
10470
hardware/arduino/firmwares/wifishield/binary/wifi_dnld.hex
Normal file
10470
hardware/arduino/firmwares/wifishield/binary/wifi_dnld.hex
Normal file
File diff suppressed because it is too large
Load Diff
BIN
hardware/arduino/firmwares/wifishield/binary/wifi_dnld_2_1.elf
Normal file
BIN
hardware/arduino/firmwares/wifishield/binary/wifi_dnld_2_1.elf
Normal file
Binary file not shown.
@ -0,0 +1,96 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
WIFI_FW_PATH="/hardware/arduino/firmwares/wifi-shield"
|
||||||
|
AVR_TOOLS_PATH="/hardware/tools/avr/bin"
|
||||||
|
|
||||||
|
progname=$0
|
||||||
|
|
||||||
|
usage () {
|
||||||
|
cat <<EOF
|
||||||
|
Usage: $progname [-a Arduino_path] [-f which_firmware] [-h]
|
||||||
|
-a set the path where the Arduino IDE is installed
|
||||||
|
-f the firmware you want to upload, valid parameters are:
|
||||||
|
shield - to upgrade the WiFi shield firmware
|
||||||
|
all - to upgrade both firmwares
|
||||||
|
-h help
|
||||||
|
EOF
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
upgradeHDmodule () {
|
||||||
|
sleep 1 # Give time to the shield to end the boot
|
||||||
|
echo "****Upgrade HD WiFi module firmware****\n"
|
||||||
|
dfu-programmer at32uc3a1256 erase
|
||||||
|
dfu-programmer at32uc3a1256 flash --suppress-bootloader-mem $WIFI_FW_PATH/wifi_dnld.hex
|
||||||
|
dfu-programmer at32uc3a1256 start
|
||||||
|
echo -n "\nRemove the J3 jumper then press the RESET button on the shield then type [ENTER] to upgrade the firmware of the shield..\n"
|
||||||
|
read readEnter
|
||||||
|
}
|
||||||
|
|
||||||
|
upgradeShield () {
|
||||||
|
sleep 1 # Give time to the shield to end the boot
|
||||||
|
echo "****Upgrade WiFi Shield firmware****\n"
|
||||||
|
dfu-programmer at32uc3a1256 erase
|
||||||
|
dfu-programmer at32uc3a1256 flash --suppress-bootloader-mem $WIFI_FW_PATH/wifiHD.hex
|
||||||
|
dfu-programmer at32uc3a1256 start
|
||||||
|
echo "\nDone. Remove the J3 jumper and press the RESET button on the shield."
|
||||||
|
echo "Thank you!\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
|
||||||
|
Arduino WiFi Shield upgrade
|
||||||
|
=========================================
|
||||||
|
Disclaimer: to access to the USB devices correctly, the dfu-programmer needs to be used as root. Run this script as root.
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
if [ $USER = 'root' ] ; then #check if the current user is root
|
||||||
|
while getopts ":a:f:h" opt; do
|
||||||
|
case $opt in
|
||||||
|
a)
|
||||||
|
ARDUINO_PATH=$OPTARG
|
||||||
|
WIFI_FW_PATH=$ARDUINO_PATH$WIFI_FW_PATH
|
||||||
|
AVR_TOOLS_PATH=$ARDUINO_PATH$AVR_TOOLS_PATH
|
||||||
|
cd $AVR_TOOLS_PATH
|
||||||
|
./avr-objcopy --output-target=ihex $WIFI_FW_PATH/wifi_dnld.elf $WIFI_FW_PATH/wifi_dnld.hex
|
||||||
|
./avr-objcopy --output-target=ihex $WIFI_FW_PATH/wifiHD.elf $WIFI_FW_PATH/wifiHD.hex
|
||||||
|
;;
|
||||||
|
f)
|
||||||
|
if [ "$ARDUINO_PATH" != "" ] ; then
|
||||||
|
if [ "$OPTARG" = "all" ] ; then
|
||||||
|
upgradeHDmodule
|
||||||
|
upgradeShield
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
if [ "$OPTARG" = "shield" ] ; then
|
||||||
|
upgradeShield
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "invalid parameter for the -f [firmware] option, please retry."
|
||||||
|
echo "Type -h for help\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Arduino Path not setted. Retry...\n"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
h)
|
||||||
|
usage ;;
|
||||||
|
\?)
|
||||||
|
echo "Invalid option: $OPTARG" >&2
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
:)
|
||||||
|
echo "Option -$OPTARG requires an argument." >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echo "You are not root!\n"
|
||||||
|
fi
|
||||||
|
|
||||||
|
shift $(($OPTIND - 1))
|
@ -0,0 +1,96 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
WIFI_FW_PATH="/hardware/arduino/firmwares/wifi-shield"
|
||||||
|
AVR_TOOLS_PATH="/hardware/tools/avr/bin"
|
||||||
|
|
||||||
|
progname=$0
|
||||||
|
|
||||||
|
usage () {
|
||||||
|
cat <<EOF
|
||||||
|
Usage: $progname [-a Arduino_path] [-f which_firmware] [-h]
|
||||||
|
-a set the path where the Arduino IDE is installed
|
||||||
|
-f the firmware you want to upload, valid parameters are:
|
||||||
|
shield - to upgrade the WiFi shield firmware
|
||||||
|
all - to upgrade both firmwares
|
||||||
|
-h help
|
||||||
|
EOF
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
upgradeHDmodule () {
|
||||||
|
sleep 1 # Give time to the shield to end the boot
|
||||||
|
echo "****Upgrade HD WiFi module firmware****\n"
|
||||||
|
dfu-programmer at32uc3a1256 erase
|
||||||
|
dfu-programmer at32uc3a1256 flash --suppress-bootloader-mem $WIFI_FW_PATH/wifi_dnld.hex
|
||||||
|
dfu-programmer at32uc3a1256 start
|
||||||
|
echo -n "\nRemove the J3 jumper then press the RESET button on the shield then type [ENTER] to upgrade the firmware of the shield..\n"
|
||||||
|
read readEnter
|
||||||
|
}
|
||||||
|
|
||||||
|
upgradeShield () {
|
||||||
|
sleep 1 # Give time to the shield to end the boot
|
||||||
|
echo "****Upgrade WiFi Shield firmware****\n"
|
||||||
|
dfu-programmer at32uc3a1256 erase
|
||||||
|
dfu-programmer at32uc3a1256 flash --suppress-bootloader-mem $WIFI_FW_PATH/wifiHD.hex
|
||||||
|
dfu-programmer at32uc3a1256 start
|
||||||
|
echo "\nDone. Remove the J3 jumper and press the RESET button on the shield."
|
||||||
|
echo "Thank you!\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
|
|
||||||
|
Arduino WiFi Shield upgrade
|
||||||
|
=========================================
|
||||||
|
Disclaimer: to access to the USB devices correctly, the dfu-programmer needs to be used as root. Run this script as root.
|
||||||
|
|
||||||
|
EOF
|
||||||
|
|
||||||
|
if [ $USER = 'root' ] ; then #check if the current user is root
|
||||||
|
while getopts ":a:f:h" opt; do
|
||||||
|
case $opt in
|
||||||
|
a)
|
||||||
|
ARDUINO_PATH=$OPTARG
|
||||||
|
WIFI_FW_PATH=$ARDUINO_PATH$WIFI_FW_PATH
|
||||||
|
AVR_TOOLS_PATH=$ARDUINO_PATH$AVR_TOOLS_PATH
|
||||||
|
cd $AVR_TOOLS_PATH
|
||||||
|
./avr-objcopy --output-target=ihex $WIFI_FW_PATH/wifi_dnld.elf $WIFI_FW_PATH/wifi_dnld.hex
|
||||||
|
./avr-objcopy --output-target=ihex $WIFI_FW_PATH/wifiHD.elf $WIFI_FW_PATH/wifiHD.hex
|
||||||
|
;;
|
||||||
|
f)
|
||||||
|
if [ "$ARDUINO_PATH" != "" ] ; then
|
||||||
|
if [ "$OPTARG" = "all" ] ; then
|
||||||
|
upgradeHDmodule
|
||||||
|
upgradeShield
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
if [ "$OPTARG" = "shield" ] ; then
|
||||||
|
upgradeShield
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "invalid parameter for the -f [firmware] option, please retry."
|
||||||
|
echo "Type -h for help\n"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Arduino Path not setted. Retry...\n"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
h)
|
||||||
|
usage ;;
|
||||||
|
\?)
|
||||||
|
echo "Invalid option: $OPTARG" >&2
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
:)
|
||||||
|
echo "Option -$OPTARG requires an argument." >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echo "You are not root!\n"
|
||||||
|
fi
|
||||||
|
|
||||||
|
shift $(($OPTIND - 1))
|
4045
hardware/arduino/firmwares/wifishield/wifiHD/.cproject
Normal file
4045
hardware/arduino/firmwares/wifishield/wifiHD/.cproject
Normal file
File diff suppressed because it is too large
Load Diff
77
hardware/arduino/firmwares/wifishield/wifiHD/.project
Normal file
77
hardware/arduino/firmwares/wifishield/wifiHD/.project
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>wifiHD</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||||
|
<triggers>clean,full,incremental,</triggers>
|
||||||
|
<arguments>
|
||||||
|
<dictionary>
|
||||||
|
<key>?name?</key>
|
||||||
|
<value></value>
|
||||||
|
</dictionary>
|
||||||
|
<dictionary>
|
||||||
|
<key>org.eclipse.cdt.make.core.append_environment</key>
|
||||||
|
<value>true</value>
|
||||||
|
</dictionary>
|
||||||
|
<dictionary>
|
||||||
|
<key>org.eclipse.cdt.make.core.buildArguments</key>
|
||||||
|
<value></value>
|
||||||
|
</dictionary>
|
||||||
|
<dictionary>
|
||||||
|
<key>org.eclipse.cdt.make.core.buildCommand</key>
|
||||||
|
<value>make</value>
|
||||||
|
</dictionary>
|
||||||
|
<dictionary>
|
||||||
|
<key>org.eclipse.cdt.make.core.buildLocation</key>
|
||||||
|
<value>${workspace_loc:/wifiHD/Debug}</value>
|
||||||
|
</dictionary>
|
||||||
|
<dictionary>
|
||||||
|
<key>org.eclipse.cdt.make.core.contents</key>
|
||||||
|
<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
|
||||||
|
</dictionary>
|
||||||
|
<dictionary>
|
||||||
|
<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
|
||||||
|
<value>false</value>
|
||||||
|
</dictionary>
|
||||||
|
<dictionary>
|
||||||
|
<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
|
||||||
|
<value>true</value>
|
||||||
|
</dictionary>
|
||||||
|
<dictionary>
|
||||||
|
<key>org.eclipse.cdt.make.core.enableFullBuild</key>
|
||||||
|
<value>true</value>
|
||||||
|
</dictionary>
|
||||||
|
<dictionary>
|
||||||
|
<key>org.eclipse.cdt.make.core.stopOnError</key>
|
||||||
|
<value>true</value>
|
||||||
|
</dictionary>
|
||||||
|
<dictionary>
|
||||||
|
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
|
||||||
|
<value>true</value>
|
||||||
|
</dictionary>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>com.atmel.avr32.core.nature</nature>
|
||||||
|
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||||
|
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
|
||||||
|
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||||
|
</natures>
|
||||||
|
<linkedResources>
|
||||||
|
<link>
|
||||||
|
<name>UC3 Software Framework</name>
|
||||||
|
<type>2</type>
|
||||||
|
<locationURI>framework:/com.atmel.avr32.sf.uc3</locationURI>
|
||||||
|
</link>
|
||||||
|
</linkedResources>
|
||||||
|
</projectDescription>
|
BIN
hardware/arduino/firmwares/wifishield/wifiHD/Release/wifiHD.elf
Normal file
BIN
hardware/arduino/firmwares/wifishield/wifiHD/Release/wifiHD.elf
Normal file
Binary file not shown.
@ -0,0 +1,170 @@
|
|||||||
|
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||||
|
|
||||||
|
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||||
|
/*! \file *********************************************************************
|
||||||
|
*
|
||||||
|
* \brief Memory access control configuration file.
|
||||||
|
*
|
||||||
|
* This file contains the possible external configuration of the memory access
|
||||||
|
* control.
|
||||||
|
*
|
||||||
|
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||||
|
* - Supported devices: All AVR32 devices can be used.
|
||||||
|
* - AppNote:
|
||||||
|
*
|
||||||
|
* \author Atmel Corporation: http://www.atmel.com \n
|
||||||
|
* Support and FAQ: http://support.atmel.no/
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. 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.
|
||||||
|
*
|
||||||
|
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||||
|
* AVR product.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||||
|
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _CONF_ACCESS_H_
|
||||||
|
#define _CONF_ACCESS_H_
|
||||||
|
|
||||||
|
#include "compiler.h"
|
||||||
|
#include "board.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*! \name Activation of Logical Unit Numbers
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define LUN_0 DISABLE //!< On-Chip Virtual Memory.
|
||||||
|
#define LUN_1 ENABLE //!< AT45DBX Data Flash.
|
||||||
|
#define LUN_2 DISABLE //!< SD/MMC Card over SPI.
|
||||||
|
#define LUN_3 DISABLE
|
||||||
|
#define LUN_4 DISABLE
|
||||||
|
#define LUN_5 DISABLE
|
||||||
|
#define LUN_6 DISABLE
|
||||||
|
#define LUN_7 DISABLE
|
||||||
|
#define LUN_USB DISABLE //!< Host Mass-Storage Memory.
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name LUN 0 Definitions
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define VIRTUAL_MEM LUN_0
|
||||||
|
#define LUN_ID_VIRTUAL_MEM LUN_ID_0
|
||||||
|
#define LUN_0_INCLUDE "virtual_mem.h"
|
||||||
|
#define Lun_0_test_unit_ready virtual_test_unit_ready
|
||||||
|
#define Lun_0_read_capacity virtual_read_capacity
|
||||||
|
#define Lun_0_wr_protect virtual_wr_protect
|
||||||
|
#define Lun_0_removal virtual_removal
|
||||||
|
#define Lun_0_usb_read_10 virtual_usb_read_10
|
||||||
|
#define Lun_0_usb_write_10 virtual_usb_write_10
|
||||||
|
#define Lun_0_mem_2_ram virtual_mem_2_ram
|
||||||
|
#define Lun_0_ram_2_mem virtual_ram_2_mem
|
||||||
|
#define LUN_0_NAME "\"On-Chip Virtual Memory\""
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name LUN 1 Definitions
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define AT45DBX_MEM LUN_1
|
||||||
|
#define LUN_ID_AT45DBX_MEM LUN_ID_1
|
||||||
|
#define LUN_1_INCLUDE "at45dbx_mem.h"
|
||||||
|
#define Lun_1_test_unit_ready at45dbx_test_unit_ready
|
||||||
|
#define Lun_1_read_capacity at45dbx_read_capacity
|
||||||
|
#define Lun_1_wr_protect at45dbx_wr_protect
|
||||||
|
#define Lun_1_removal at45dbx_removal
|
||||||
|
#define Lun_1_usb_read_10 at45dbx_usb_read_10
|
||||||
|
#define Lun_1_usb_write_10 at45dbx_usb_write_10
|
||||||
|
#define Lun_1_mem_2_ram at45dbx_df_2_ram
|
||||||
|
#define Lun_1_ram_2_mem at45dbx_ram_2_df
|
||||||
|
#define LUN_1_NAME "\"AT45DBX Data Flash\""
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name LUN 2 Definitions
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define SD_MMC_SPI_MEM LUN_2
|
||||||
|
#define LUN_ID_SD_MMC_SPI_MEM LUN_ID_2
|
||||||
|
#define LUN_2_INCLUDE "sd_mmc_spi_mem.h"
|
||||||
|
#define Lun_2_test_unit_ready sd_mmc_spi_test_unit_ready
|
||||||
|
#define Lun_2_read_capacity sd_mmc_spi_read_capacity
|
||||||
|
#define Lun_2_wr_protect sd_mmc_spi_wr_protect
|
||||||
|
#define Lun_2_removal sd_mmc_spi_removal
|
||||||
|
#define Lun_2_usb_read_10 sd_mmc_spi_usb_read_10
|
||||||
|
#define Lun_2_usb_write_10 sd_mmc_spi_usb_write_10
|
||||||
|
#define Lun_2_mem_2_ram sd_mmc_spi_mem_2_ram
|
||||||
|
#define Lun_2_ram_2_mem sd_mmc_spi_ram_2_mem
|
||||||
|
#define LUN_2_NAME "\"SD/MMC Card over SPI\""
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name USB LUNs Definitions
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define MEM_USB LUN_USB
|
||||||
|
#define LUN_ID_MEM_USB LUN_ID_USB
|
||||||
|
#define LUN_USB_INCLUDE "host_mem.h"
|
||||||
|
#define Lun_usb_test_unit_ready(lun) host_test_unit_ready(lun)
|
||||||
|
#define Lun_usb_read_capacity(lun, nb_sect) host_read_capacity(lun, nb_sect)
|
||||||
|
#define Lun_usb_read_sector_size(lun) host_read_sector_size(lun)
|
||||||
|
#define Lun_usb_wr_protect(lun) host_wr_protect(lun)
|
||||||
|
#define Lun_usb_removal() host_removal()
|
||||||
|
#define Lun_usb_mem_2_ram(addr, ram) host_read_10_ram(addr, ram)
|
||||||
|
#define Lun_usb_ram_2_mem(addr, ram) host_write_10_ram(addr, ram)
|
||||||
|
#define LUN_USB_NAME "\"Host Mass-Storage Memory\""
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name Actions Associated with Memory Accesses
|
||||||
|
*
|
||||||
|
* Write here the action to associate with each memory access.
|
||||||
|
*
|
||||||
|
* \warning Be careful not to waste time in order not to disturb the functions.
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define memory_start_read_action(nb_sectors)
|
||||||
|
#define memory_stop_read_action()
|
||||||
|
#define memory_start_write_action(nb_sectors)
|
||||||
|
#define memory_stop_write_action()
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name Activation of Interface Features
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define ACCESS_USB DISABLED //!< MEM <-> USB interface.
|
||||||
|
#define ACCESS_MEM_TO_RAM ENABLED //!< MEM <-> RAM interface.
|
||||||
|
#define ACCESS_STREAM ENABLED //!< Streaming MEM <-> MEM interface. //mlf
|
||||||
|
#define ACCESS_STREAM_RECORD DISABLED //!< Streaming MEM <-> MEM interface in record mode.
|
||||||
|
#define ACCESS_MEM_TO_MEM DISABLED //!< MEM <-> MEM interface.
|
||||||
|
#define ACCESS_CODEC DISABLED //!< Codec interface.
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name Specific Options for Access Control
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define GLOBAL_WR_PROTECT DISABLED //!< Management of a global write protection.
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _CONF_ACCESS_H_
|
@ -0,0 +1,83 @@
|
|||||||
|
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||||
|
|
||||||
|
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||||
|
/*! \file *********************************************************************
|
||||||
|
*
|
||||||
|
* \brief AT45DBX configuration file.
|
||||||
|
*
|
||||||
|
* This file contains the possible external configuration of the AT45DBX.
|
||||||
|
*
|
||||||
|
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||||
|
* - Supported devices: All AVR32 devices with an SPI module can be used.
|
||||||
|
* - AppNote:
|
||||||
|
*
|
||||||
|
* \author Atmel Corporation: http://www.atmel.com \n
|
||||||
|
* Support and FAQ: http://support.atmel.no/
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. 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.
|
||||||
|
*
|
||||||
|
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||||
|
* AVR product.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||||
|
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _CONF_AT45DBX_H_
|
||||||
|
#define _CONF_AT45DBX_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include "conf_access.h"
|
||||||
|
|
||||||
|
#if AT45DBX_MEM == DISABLE
|
||||||
|
#error conf_at45dbx.h is #included although AT45DBX_MEM is disabled
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include "at45dbx.h"
|
||||||
|
|
||||||
|
|
||||||
|
//_____ D E F I N I T I O N S ______________________________________________
|
||||||
|
|
||||||
|
//! Size of AT45DBX data flash memories to manage.
|
||||||
|
#define AT45DBX_MEM_SIZE AT45DBX_1MB
|
||||||
|
|
||||||
|
//! Number of AT45DBX components to manage.
|
||||||
|
#define AT45DBX_MEM_CNT 1
|
||||||
|
|
||||||
|
//! First chip select used by AT45DBX components on the SPI module instance.
|
||||||
|
//! AT45DBX_SPI_NPCS0_PIN always corresponds to this first NPCS, whatever it is.
|
||||||
|
#define AT45DBX_SPI_FIRST_NPCS AT45DBX_SPI_NPCS
|
||||||
|
|
||||||
|
//! SPI master speed in Hz.
|
||||||
|
#define AT45DBX_SPI_MASTER_SPEED 12000000
|
||||||
|
|
||||||
|
//! Number of bits in each SPI transfer.
|
||||||
|
#define AT45DBX_SPI_BITS 8
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _CONF_AT45DBX_H_
|
@ -0,0 +1,108 @@
|
|||||||
|
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||||
|
|
||||||
|
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||||
|
/*! \file *********************************************************************
|
||||||
|
*
|
||||||
|
* \brief CONF_EBI EBI/SMC driver for AVR32 UC3.
|
||||||
|
*
|
||||||
|
* \note The values defined in this file are device-specific. See the device
|
||||||
|
* datasheet for further information.
|
||||||
|
*
|
||||||
|
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||||
|
* - Supported devices: All AVR32 devices with an SMC module can be used.
|
||||||
|
* - AppNote:
|
||||||
|
*
|
||||||
|
* \author Atmel Corporation: http://www.atmel.com \n
|
||||||
|
* Support and FAQ: http://support.atmel.no/
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. 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.
|
||||||
|
*
|
||||||
|
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||||
|
* AVR product.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||||
|
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _CONF_EBI_H_
|
||||||
|
#define _CONF_EBI_H_
|
||||||
|
|
||||||
|
#include "compiler.h"
|
||||||
|
#include "board.h"
|
||||||
|
|
||||||
|
#if (ET024006DHU_SMC_USE_NCS == 0)
|
||||||
|
#define SMC_USE_NCS0
|
||||||
|
#define SMC_COMPONENT_CS0 ET024006DHU_SMC_COMPONENT_CS
|
||||||
|
#else
|
||||||
|
|
||||||
|
#if (ET024006DHU_SMC_USE_NCS == 2)
|
||||||
|
#define SMC_USE_NCS2
|
||||||
|
#define SMC_COMPONENT_CS2 ET024006DHU_SMC_COMPONENT_CS
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error This board is not supported
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define EBI_DATA_0 ET024006DHU_EBI_DATA_0
|
||||||
|
#define EBI_DATA_1 ET024006DHU_EBI_DATA_1
|
||||||
|
#define EBI_DATA_2 ET024006DHU_EBI_DATA_2
|
||||||
|
#define EBI_DATA_3 ET024006DHU_EBI_DATA_3
|
||||||
|
#define EBI_DATA_4 ET024006DHU_EBI_DATA_4
|
||||||
|
#define EBI_DATA_5 ET024006DHU_EBI_DATA_5
|
||||||
|
#define EBI_DATA_6 ET024006DHU_EBI_DATA_6
|
||||||
|
#define EBI_DATA_7 ET024006DHU_EBI_DATA_7
|
||||||
|
#define EBI_DATA_8 ET024006DHU_EBI_DATA_8
|
||||||
|
#define EBI_DATA_9 ET024006DHU_EBI_DATA_9
|
||||||
|
#define EBI_DATA_10 ET024006DHU_EBI_DATA_10
|
||||||
|
#define EBI_DATA_11 ET024006DHU_EBI_DATA_11
|
||||||
|
#define EBI_DATA_12 ET024006DHU_EBI_DATA_12
|
||||||
|
#define EBI_DATA_13 ET024006DHU_EBI_DATA_13
|
||||||
|
#define EBI_DATA_14 ET024006DHU_EBI_DATA_14
|
||||||
|
#define EBI_DATA_15 ET024006DHU_EBI_DATA_15
|
||||||
|
|
||||||
|
#if BOARD==EVK1105
|
||||||
|
#ifdef EVK1105_REV3
|
||||||
|
#define EBI_ADDR_19 AVR32_EBI_ADDR_19
|
||||||
|
#define EBI_NCS_2 ET024006DHU_EBI_NCS
|
||||||
|
#else
|
||||||
|
#define EBI_ADDR_21 ET024006DHU_EBI_ADDR_21
|
||||||
|
#define EBI_NCS_0 ET024006DHU_EBI_NCS
|
||||||
|
#endif
|
||||||
|
#elif BOARD == UC3C_EK
|
||||||
|
#define EBI_ADDR_22 AVR32_EBI_ADDR_22
|
||||||
|
#define EBI_NCS_0 ET024006DHU_EBI_NCS
|
||||||
|
#elif BOARD == EVK1104
|
||||||
|
#define EBI_ADDR_21 ET024006DHU_EBI_ADDR_21
|
||||||
|
#define EBI_NCS_0 ET024006DHU_EBI_NCS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define EBI_NWE0 ET024006DHU_EBI_NWE
|
||||||
|
#define EBI_NRD ET024006DHU_EBI_NRD
|
||||||
|
|
||||||
|
#endif // _CONF_EBI_H_
|
@ -0,0 +1,73 @@
|
|||||||
|
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||||
|
|
||||||
|
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||||
|
/*! \file *********************************************************************
|
||||||
|
*
|
||||||
|
* \brief SD/MMC configuration file.
|
||||||
|
*
|
||||||
|
* This file contains the possible external configuration of the SD/MMC.
|
||||||
|
*
|
||||||
|
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||||
|
* - Supported devices: All AVR32 devices with an SPI module can be used.
|
||||||
|
* - AppNote:
|
||||||
|
*
|
||||||
|
* \author Atmel Corporation: http://www.atmel.com \n
|
||||||
|
* Support and FAQ: http://support.atmel.no/
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. 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.
|
||||||
|
*
|
||||||
|
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||||
|
* AVR product.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||||
|
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _CONF_SD_MMC_SPI_H_
|
||||||
|
#define _CONF_SD_MMC_SPI_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include "conf_access.h"
|
||||||
|
|
||||||
|
#if SD_MMC_SPI_MEM == DISABLE
|
||||||
|
#error conf_sd_mmc_spi.h is #included although SD_MMC_SPI_MEM is disabled
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include "sd_mmc_spi.h"
|
||||||
|
|
||||||
|
|
||||||
|
//_____ D E F I N I T I O N S ______________________________________________
|
||||||
|
|
||||||
|
//! SPI master speed in Hz.
|
||||||
|
#define SD_MMC_SPI_MASTER_SPEED 12000000
|
||||||
|
|
||||||
|
//! Number of bits in each SPI transfer.
|
||||||
|
#define SD_MMC_SPI_BITS 8
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _CONF_SD_MMC_SPI_H_
|
@ -0,0 +1,74 @@
|
|||||||
|
/* This file is part of the ATMEL AVR32-SoftwareFramework-AT32UC3A-1.4.0 Release */
|
||||||
|
|
||||||
|
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||||
|
/*! \file *********************************************************************
|
||||||
|
*
|
||||||
|
* \brief AVR32 UC3 ISP trampoline.
|
||||||
|
*
|
||||||
|
* In order to be able to program a project with both BatchISP and JTAGICE mkII
|
||||||
|
* without having to take the general-purpose fuses into consideration, add this
|
||||||
|
* file to the project and change the program entry point to _trampoline.
|
||||||
|
*
|
||||||
|
* The pre-programmed ISP will be erased if JTAGICE mkII is used.
|
||||||
|
*
|
||||||
|
* - Compiler: GNU GCC for AVR32
|
||||||
|
* - Supported devices: All AVR32UC devices can be used.
|
||||||
|
*
|
||||||
|
* \author Atmel Corporation: http://www.atmel.com \n
|
||||||
|
* Support and FAQ: http://support.atmel.no/
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/* Copyright (C) 2006-2008, Atmel Corporation All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. 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.
|
||||||
|
*
|
||||||
|
* 3. The name of ATMEL may not be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ATMEL ``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 EXPRESSLY AND
|
||||||
|
* SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "conf_isp.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! @{
|
||||||
|
//! \verbatim
|
||||||
|
|
||||||
|
|
||||||
|
// This must be linked @ 0x80000000 if it is to be run upon reset.
|
||||||
|
.section .reset, "ax", @progbits
|
||||||
|
|
||||||
|
|
||||||
|
.global _trampoline
|
||||||
|
.type _trampoline, @function
|
||||||
|
_trampoline:
|
||||||
|
// Jump to program start.
|
||||||
|
rjmp program_start
|
||||||
|
|
||||||
|
.org PROGRAM_START_OFFSET
|
||||||
|
program_start:
|
||||||
|
// Jump to the C runtime startup routine.
|
||||||
|
lda.w pc, _stext
|
||||||
|
|
||||||
|
|
||||||
|
//! \endverbatim
|
||||||
|
//! @}
|
@ -0,0 +1,236 @@
|
|||||||
|
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||||
|
|
||||||
|
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||||
|
/*! \file *********************************************************************
|
||||||
|
*
|
||||||
|
* \brief AT32UC3A EVK1100 board header file.
|
||||||
|
*
|
||||||
|
* This file contains definitions and services related to the features of the
|
||||||
|
* EVK1100 board rev. B and C.
|
||||||
|
*
|
||||||
|
* To use this board, define BOARD=EVK1100.
|
||||||
|
*
|
||||||
|
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||||
|
* - Supported devices: All AVR32 AT32UC3A devices can be used.
|
||||||
|
* - AppNote:
|
||||||
|
*
|
||||||
|
* \author Atmel Corporation: http://www.atmel.com \n
|
||||||
|
* Support and FAQ: http://support.atmel.no/
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. 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.
|
||||||
|
*
|
||||||
|
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||||
|
* AVR product.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||||
|
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _ARDUINO_H_
|
||||||
|
#define _ARDUINO_H_
|
||||||
|
|
||||||
|
#include "compiler.h"
|
||||||
|
|
||||||
|
#ifdef __AVR32_ABI_COMPILER__ // Automatically defined when compiling for AVR32, not when assembling.
|
||||||
|
# include "led.h"
|
||||||
|
#endif // __AVR32_ABI_COMPILER__
|
||||||
|
|
||||||
|
|
||||||
|
/*! \name Oscillator Definitions
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
// RCOsc has no custom calibration by default. Set the following definition to
|
||||||
|
// the appropriate value if a custom RCOsc calibration has been applied to your
|
||||||
|
// part.
|
||||||
|
//#define FRCOSC AVR32_PM_RCOSC_FREQUENCY //!< RCOsc frequency: Hz.
|
||||||
|
|
||||||
|
#define FOSC32 32768 //!< Osc32 frequency: Hz.
|
||||||
|
#define OSC32_STARTUP AVR32_PM_OSCCTRL32_STARTUP_8192_RCOSC //!< Osc32 startup time: RCOsc periods.
|
||||||
|
|
||||||
|
#define FOSC0 12000000 //!< Osc0 frequency: Hz.
|
||||||
|
#define OSC0_STARTUP AVR32_PM_OSCCTRL0_STARTUP_2048_RCOSC //!< Osc0 startup time: RCOsc periods.
|
||||||
|
|
||||||
|
// Osc1 crystal is not mounted by default. Set the following definitions to the
|
||||||
|
// appropriate values if a custom Osc1 crystal is mounted on your board.
|
||||||
|
//#define FOSC1 12000000 //!< Osc1 frequency: Hz.
|
||||||
|
//#define OSC1_STARTUP AVR32_PM_OSCCTRL1_STARTUP_2048_RCOSC //!< Osc1 startup time: RCOsc periods.
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
//! Number of LEDs.
|
||||||
|
#define LED_COUNT 0
|
||||||
|
|
||||||
|
/*! \name GPIO Connections of LEDs
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define LED0_GPIO AVR32_PIN_PB19
|
||||||
|
#define LED1_GPIO AVR32_PIN_PB20
|
||||||
|
#define LED2_GPIO AVR32_PIN_PB21
|
||||||
|
#define DEB_PIN_GPIO AVR32_PIN_PA20
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name PWM Channels of LEDs
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define LED0_PWM 0
|
||||||
|
#define LED1_PWM 1
|
||||||
|
#define LED2_PWM 2
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name PWM Functions of LEDs
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define LED0_PWM_FUNCTION AVR32_PWM_0_FUNCTION
|
||||||
|
#define LED1_PWM_FUNCTION AVR32_PWM_1_FUNCTION
|
||||||
|
#define LED2_PWM_FUNCTION AVR32_PWM_2_FUNCTION
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name Color Identifiers of LEDs to Use with LED Functions
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define LED_MONO0_GREEN LED0
|
||||||
|
#define LED_MONO1_RED LED1
|
||||||
|
#define LED_MONO2_BLU LED2
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/*! \name SPI Connections of the DIP204 LCD
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define DIP204_SPI (&AVR32_SPI1)
|
||||||
|
#define DIP204_SPI_NPCS 2
|
||||||
|
#define DIP204_SPI_SCK_PIN AVR32_SPI1_SCK_0_0_PIN
|
||||||
|
#define DIP204_SPI_SCK_FUNCTION AVR32_SPI1_SCK_0_0_FUNCTION
|
||||||
|
#define DIP204_SPI_MISO_PIN AVR32_SPI1_MISO_0_0_PIN
|
||||||
|
#define DIP204_SPI_MISO_FUNCTION AVR32_SPI1_MISO_0_0_FUNCTION
|
||||||
|
#define DIP204_SPI_MOSI_PIN AVR32_SPI1_MOSI_0_0_PIN
|
||||||
|
#define DIP204_SPI_MOSI_FUNCTION AVR32_SPI1_MOSI_0_0_FUNCTION
|
||||||
|
#define DIP204_SPI_NPCS_PIN AVR32_SPI1_NPCS_2_0_PIN
|
||||||
|
#define DIP204_SPI_NPCS_FUNCTION AVR32_SPI1_NPCS_2_0_FUNCTION
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name GPIO and PWM Connections of the DIP204 LCD Backlight
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define DIP204_BACKLIGHT_PIN AVR32_PIN_PB18
|
||||||
|
#define DIP204_PWM_CHANNEL 6
|
||||||
|
#define DIP204_PWM_PIN AVR32_PWM_6_PIN
|
||||||
|
#define DIP204_PWM_FUNCTION AVR32_PWM_6_FUNCTION
|
||||||
|
//! @}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*! \name SPI Connections of the AT45DBX Data Flash Memory
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define AT45DBX_SPI (&AVR32_SPI1)
|
||||||
|
#define AT45DBX_SPI_NPCS 2
|
||||||
|
#define AT45DBX_SPI_SCK_PIN AVR32_SPI1_SCK_0_0_PIN
|
||||||
|
#define AT45DBX_SPI_SCK_FUNCTION AVR32_SPI1_SCK_0_0_FUNCTION
|
||||||
|
#define AT45DBX_SPI_MISO_PIN AVR32_SPI1_MISO_0_0_PIN
|
||||||
|
#define AT45DBX_SPI_MISO_FUNCTION AVR32_SPI1_MISO_0_0_FUNCTION
|
||||||
|
#define AT45DBX_SPI_MOSI_PIN AVR32_SPI1_MOSI_0_0_PIN
|
||||||
|
#define AT45DBX_SPI_MOSI_FUNCTION AVR32_SPI1_MOSI_0_0_FUNCTION
|
||||||
|
#define AT45DBX_SPI_NPCS2_PIN AVR32_SPI1_NPCS_2_0_PIN
|
||||||
|
#define AT45DBX_SPI_NPCS2_FUNCTION AVR32_SPI1_NPCS_2_0_FUNCTION
|
||||||
|
#define AT45DBX_CHIP_RESET AVR32_PIN_PA02
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
/*! \name GPIO and SPI Connections of the SD/MMC Connector
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
//#define SD_MMC_CARD_DETECT_PIN AVR32_PIN_PA02
|
||||||
|
//#define SD_MMC_WRITE_PROTECT_PIN AVR32_PIN_PA07
|
||||||
|
#define SD_MMC_SPI (&AVR32_SPI1)
|
||||||
|
#define SD_MMC_SPI_NPCS 1
|
||||||
|
#define SD_MMC_SPI_SCK_PIN AVR32_SPI1_SCK_0_0_PIN
|
||||||
|
#define SD_MMC_SPI_SCK_FUNCTION AVR32_SPI1_SCK_0_0_FUNCTION
|
||||||
|
#define SD_MMC_SPI_MISO_PIN AVR32_SPI1_MISO_0_0_PIN
|
||||||
|
#define SD_MMC_SPI_MISO_FUNCTION AVR32_SPI1_MISO_0_0_FUNCTION
|
||||||
|
#define SD_MMC_SPI_MOSI_PIN AVR32_SPI1_MOSI_0_0_PIN
|
||||||
|
#define SD_MMC_SPI_MOSI_FUNCTION AVR32_SPI1_MOSI_0_0_FUNCTION
|
||||||
|
#define SD_MMC_SPI_NPCS_PIN AVR32_SPI1_NPCS_1_0_PIN
|
||||||
|
#define SD_MMC_SPI_NPCS_FUNCTION AVR32_SPI1_NPCS_1_0_FUNCTION
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/* Timer Counter to generate clock for WiFi chip*/
|
||||||
|
# define WIFI_TC (&AVR32_TC)
|
||||||
|
# define WIFI_TC_CHANNEL_ID 0
|
||||||
|
# define WIFI_TC_CHANNEL_PIN AVR32_TC_A0_0_0_PIN
|
||||||
|
# define WIFI_TC_CHANNEL_FUNCTION AVR32_TC_A0_0_0_FUNCTION
|
||||||
|
// Note that TC_A0_0_0 pin is pin 6 (PB23) on AT32UC3A1512 QFP100.
|
||||||
|
|
||||||
|
/* Pin related to WiFi chip communication */
|
||||||
|
#ifndef USE_POLL
|
||||||
|
#define USE_POLL
|
||||||
|
#endif
|
||||||
|
#define SPI_CS 0
|
||||||
|
#define AVR32_SPI AVR32_SPI1
|
||||||
|
#define GPIO_IRQ_PIN AVR32_PIN_PA03
|
||||||
|
#define GPIO_IRQ AVR32_GPIO_IRQ_7
|
||||||
|
#define GPIO_W_RESET_PIN AVR32_PIN_PA07
|
||||||
|
#define GPIO_W_SHUTDOWN_PIN AVR32_PIN_PA09
|
||||||
|
|
||||||
|
/* Pin related to shield communication */
|
||||||
|
#define ARDUINO_HANDSHAKE_PIN AVR32_PIN_PA25
|
||||||
|
#define ARDUINO_EXTINT_PIN AVR32_PIN_PA04 //not used
|
||||||
|
|
||||||
|
#define AVR32_PDCA_PID_TX AVR32_PDCA_PID_SPI1_TX
|
||||||
|
#define AVR32_PDCA_PID_RX AVR32_PDCA_PID_SPI1_RX
|
||||||
|
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/*! \name TWI Connections of the Spare TWI Connector
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define SPARE_TWI (&AVR32_TWI)
|
||||||
|
#define SPARE_TWI_SCL_PIN AVR32_TWI_SCL_0_0_PIN
|
||||||
|
#define SPARE_TWI_SCL_FUNCTION AVR32_TWI_SCL_0_0_FUNCTION
|
||||||
|
#define SPARE_TWI_SDA_PIN AVR32_TWI_SDA_0_0_PIN
|
||||||
|
#define SPARE_TWI_SDA_FUNCTION AVR32_TWI_SDA_0_0_FUNCTION
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
/*! \name SPI Connections of the Spare SPI Connector
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define SPARE_SPI (&AVR32_SPI0)
|
||||||
|
#define SPARE_SPI_NPCS 0
|
||||||
|
#define SPARE_SPI_SCK_PIN AVR32_SPI0_SCK_0_0_PIN
|
||||||
|
#define SPARE_SPI_SCK_FUNCTION AVR32_SPI0_SCK_0_0_FUNCTION
|
||||||
|
#define SPARE_SPI_MISO_PIN AVR32_SPI0_MISO_0_0_PIN
|
||||||
|
#define SPARE_SPI_MISO_FUNCTION AVR32_SPI0_MISO_0_0_FUNCTION
|
||||||
|
#define SPARE_SPI_MOSI_PIN AVR32_SPI0_MOSI_0_0_PIN
|
||||||
|
#define SPARE_SPI_MOSI_FUNCTION AVR32_SPI0_MOSI_0_0_FUNCTION
|
||||||
|
#define SPARE_SPI_NPCS_PIN AVR32_SPI0_NPCS_0_0_PIN
|
||||||
|
#define SPARE_SPI_NPCS_FUNCTION AVR32_SPI0_NPCS_0_0_FUNCTION
|
||||||
|
//! @}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // _ARDUINO_H_
|
@ -0,0 +1,346 @@
|
|||||||
|
/* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||||
|
|
||||||
|
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||||
|
/*! \file *********************************************************************
|
||||||
|
*
|
||||||
|
* \brief AT32UC3A EVK1100 board LEDs support package.
|
||||||
|
*
|
||||||
|
* This file contains definitions and services related to the LED features of
|
||||||
|
* the EVK1100 board.
|
||||||
|
*
|
||||||
|
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||||
|
* - Supported devices: All AVR32 AT32UC3A devices can be used.
|
||||||
|
* - AppNote:
|
||||||
|
*
|
||||||
|
* \author Atmel Corporation: http://www.atmel.com \n
|
||||||
|
* Support and FAQ: http://support.atmel.no/
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. 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.
|
||||||
|
*
|
||||||
|
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||||
|
* AVR product.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||||
|
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <avr32/io.h>
|
||||||
|
#include "preprocessor.h"
|
||||||
|
#include "compiler.h"
|
||||||
|
#include "arduino.h"
|
||||||
|
#include "led.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! Structure describing LED hardware connections.
|
||||||
|
typedef const struct
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
U32 PORT; //!< LED GPIO port.
|
||||||
|
U32 PIN_MASK; //!< Bit-mask of LED pin in GPIO port.
|
||||||
|
} GPIO; //!< LED GPIO descriptor.
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
S32 CHANNEL; //!< LED PWM channel (< 0 if N/A).
|
||||||
|
S32 FUNCTION; //!< LED pin PWM function (< 0 if N/A).
|
||||||
|
} PWM; //!< LED PWM descriptor.
|
||||||
|
} tLED_DESCRIPTOR;
|
||||||
|
|
||||||
|
|
||||||
|
//! Hardware descriptors of all LEDs.
|
||||||
|
static tLED_DESCRIPTOR LED_DESCRIPTOR[LED_COUNT] =
|
||||||
|
{
|
||||||
|
#define INSERT_LED_DESCRIPTOR(LED_NO, unused) \
|
||||||
|
{ \
|
||||||
|
{LED##LED_NO##_GPIO / 32, 1 << (LED##LED_NO##_GPIO % 32)},\
|
||||||
|
{LED##LED_NO##_PWM, LED##LED_NO##_PWM_FUNCTION } \
|
||||||
|
},
|
||||||
|
MREPEAT(LED_COUNT, INSERT_LED_DESCRIPTOR, ~)
|
||||||
|
#undef INSERT_LED_DESCRIPTOR
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//! Saved state of all LEDs.
|
||||||
|
static volatile U32 LED_State = (1 << LED_COUNT) - 1;
|
||||||
|
|
||||||
|
|
||||||
|
U32 LED_Read_Display(void)
|
||||||
|
{
|
||||||
|
return LED_State;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LED_Display(U32 leds)
|
||||||
|
{
|
||||||
|
// Use the LED descriptors to get the connections of a given LED to the MCU.
|
||||||
|
tLED_DESCRIPTOR *led_descriptor;
|
||||||
|
volatile avr32_gpio_port_t *led_gpio_port;
|
||||||
|
|
||||||
|
// Make sure only existing LEDs are specified.
|
||||||
|
leds &= (1 << LED_COUNT) - 1;
|
||||||
|
|
||||||
|
// Update the saved state of all LEDs with the requested changes.
|
||||||
|
LED_State = leds;
|
||||||
|
|
||||||
|
// For all LEDs...
|
||||||
|
for (led_descriptor = &LED_DESCRIPTOR[0];
|
||||||
|
led_descriptor < LED_DESCRIPTOR + LED_COUNT;
|
||||||
|
led_descriptor++)
|
||||||
|
{
|
||||||
|
// Set the LED to the requested state.
|
||||||
|
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||||
|
if (leds & 1)
|
||||||
|
{
|
||||||
|
led_gpio_port->ovrc = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
led_gpio_port->ovrs = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
}
|
||||||
|
led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
leds >>= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
U32 LED_Read_Display_Mask(U32 mask)
|
||||||
|
{
|
||||||
|
return Rd_bits(LED_State, mask);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LED_Display_Mask(U32 mask, U32 leds)
|
||||||
|
{
|
||||||
|
// Use the LED descriptors to get the connections of a given LED to the MCU.
|
||||||
|
tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
|
||||||
|
volatile avr32_gpio_port_t *led_gpio_port;
|
||||||
|
U8 led_shift;
|
||||||
|
|
||||||
|
// Make sure only existing LEDs are specified.
|
||||||
|
mask &= (1 << LED_COUNT) - 1;
|
||||||
|
|
||||||
|
// Update the saved state of all LEDs with the requested changes.
|
||||||
|
Wr_bits(LED_State, mask, leds);
|
||||||
|
|
||||||
|
// While there are specified LEDs left to manage...
|
||||||
|
while (mask)
|
||||||
|
{
|
||||||
|
// Select the next specified LED and set it to the requested state.
|
||||||
|
led_shift = 1 + ctz(mask);
|
||||||
|
led_descriptor += led_shift;
|
||||||
|
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||||
|
leds >>= led_shift - 1;
|
||||||
|
if (leds & 1)
|
||||||
|
{
|
||||||
|
led_gpio_port->ovrc = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
led_gpio_port->ovrs = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
}
|
||||||
|
led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
leds >>= 1;
|
||||||
|
mask >>= led_shift;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Bool LED_Test(U32 leds)
|
||||||
|
{
|
||||||
|
return Tst_bits(LED_State, leds);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LED_Off(U32 leds)
|
||||||
|
{
|
||||||
|
// Use the LED descriptors to get the connections of a given LED to the MCU.
|
||||||
|
tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
|
||||||
|
volatile avr32_gpio_port_t *led_gpio_port;
|
||||||
|
U8 led_shift;
|
||||||
|
|
||||||
|
// Make sure only existing LEDs are specified.
|
||||||
|
leds &= (1 << LED_COUNT) - 1;
|
||||||
|
|
||||||
|
// Update the saved state of all LEDs with the requested changes.
|
||||||
|
Clr_bits(LED_State, leds);
|
||||||
|
|
||||||
|
// While there are specified LEDs left to manage...
|
||||||
|
while (leds)
|
||||||
|
{
|
||||||
|
// Select the next specified LED and turn it off.
|
||||||
|
led_shift = 1 + ctz(leds);
|
||||||
|
led_descriptor += led_shift;
|
||||||
|
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||||
|
led_gpio_port->ovrs = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
leds >>= led_shift;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LED_On(U32 leds)
|
||||||
|
{
|
||||||
|
// Use the LED descriptors to get the connections of a given LED to the MCU.
|
||||||
|
tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
|
||||||
|
volatile avr32_gpio_port_t *led_gpio_port;
|
||||||
|
U8 led_shift;
|
||||||
|
|
||||||
|
// Make sure only existing LEDs are specified.
|
||||||
|
leds &= (1 << LED_COUNT) - 1;
|
||||||
|
|
||||||
|
// Update the saved state of all LEDs with the requested changes.
|
||||||
|
Set_bits(LED_State, leds);
|
||||||
|
|
||||||
|
// While there are specified LEDs left to manage...
|
||||||
|
while (leds)
|
||||||
|
{
|
||||||
|
// Select the next specified LED and turn it on.
|
||||||
|
led_shift = 1 + ctz(leds);
|
||||||
|
led_descriptor += led_shift;
|
||||||
|
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||||
|
led_gpio_port->ovrc = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
leds >>= led_shift;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LED_Toggle(U32 leds)
|
||||||
|
{
|
||||||
|
// Use the LED descriptors to get the connections of a given LED to the MCU.
|
||||||
|
tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
|
||||||
|
volatile avr32_gpio_port_t *led_gpio_port;
|
||||||
|
U8 led_shift;
|
||||||
|
|
||||||
|
// Make sure only existing LEDs are specified.
|
||||||
|
leds &= (1 << LED_COUNT) - 1;
|
||||||
|
|
||||||
|
// Update the saved state of all LEDs with the requested changes.
|
||||||
|
Tgl_bits(LED_State, leds);
|
||||||
|
|
||||||
|
// While there are specified LEDs left to manage...
|
||||||
|
while (leds)
|
||||||
|
{
|
||||||
|
// Select the next specified LED and toggle it.
|
||||||
|
led_shift = 1 + ctz(leds);
|
||||||
|
led_descriptor += led_shift;
|
||||||
|
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||||
|
led_gpio_port->ovrt = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
leds >>= led_shift;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
U32 LED_Read_Display_Field(U32 field)
|
||||||
|
{
|
||||||
|
return Rd_bitfield(LED_State, field);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LED_Display_Field(U32 field, U32 leds)
|
||||||
|
{
|
||||||
|
// Move the bit-field to the appropriate position for the bit-mask.
|
||||||
|
LED_Display_Mask(field, leds << ctz(field));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
U8 LED_Get_Intensity(U32 led)
|
||||||
|
{
|
||||||
|
tLED_DESCRIPTOR *led_descriptor;
|
||||||
|
|
||||||
|
// Check that the argument value is valid.
|
||||||
|
led = ctz(led);
|
||||||
|
led_descriptor = &LED_DESCRIPTOR[led];
|
||||||
|
if (led >= LED_COUNT || led_descriptor->PWM.CHANNEL < 0) return 0;
|
||||||
|
|
||||||
|
// Return the duty cycle value if the LED PWM channel is enabled, else 0.
|
||||||
|
return (AVR32_PWM.sr & (1 << led_descriptor->PWM.CHANNEL)) ?
|
||||||
|
AVR32_PWM.channel[led_descriptor->PWM.CHANNEL].cdty : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LED_Set_Intensity(U32 leds, U8 intensity)
|
||||||
|
{
|
||||||
|
tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
|
||||||
|
volatile avr32_pwm_channel_t *led_pwm_channel;
|
||||||
|
volatile avr32_gpio_port_t *led_gpio_port;
|
||||||
|
U8 led_shift;
|
||||||
|
|
||||||
|
// For each specified LED...
|
||||||
|
for (leds &= (1 << LED_COUNT) - 1; leds; leds >>= led_shift)
|
||||||
|
{
|
||||||
|
// Select the next specified LED and check that it has a PWM channel.
|
||||||
|
led_shift = 1 + ctz(leds);
|
||||||
|
led_descriptor += led_shift;
|
||||||
|
if (led_descriptor->PWM.CHANNEL < 0) continue;
|
||||||
|
|
||||||
|
// Initialize or update the LED PWM channel.
|
||||||
|
led_pwm_channel = &AVR32_PWM.channel[led_descriptor->PWM.CHANNEL];
|
||||||
|
if (!(AVR32_PWM.sr & (1 << led_descriptor->PWM.CHANNEL)))
|
||||||
|
{
|
||||||
|
led_pwm_channel->cmr = (AVR32_PWM_CPRE_MCK << AVR32_PWM_CPRE_OFFSET) &
|
||||||
|
~(AVR32_PWM_CALG_MASK |
|
||||||
|
AVR32_PWM_CPOL_MASK |
|
||||||
|
AVR32_PWM_CPD_MASK);
|
||||||
|
led_pwm_channel->cprd = 0x000000FF;
|
||||||
|
led_pwm_channel->cdty = intensity;
|
||||||
|
AVR32_PWM.ena = 1 << led_descriptor->PWM.CHANNEL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AVR32_PWM.isr;
|
||||||
|
while (!(AVR32_PWM.isr & (1 << led_descriptor->PWM.CHANNEL)));
|
||||||
|
led_pwm_channel->cupd = intensity;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Switch the LED pin to its PWM function.
|
||||||
|
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||||
|
if (led_descriptor->PWM.FUNCTION & 0x1)
|
||||||
|
{
|
||||||
|
led_gpio_port->pmr0s = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
led_gpio_port->pmr0c = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
}
|
||||||
|
if (led_descriptor->PWM.FUNCTION & 0x2)
|
||||||
|
{
|
||||||
|
led_gpio_port->pmr1s = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
led_gpio_port->pmr1c = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
}
|
||||||
|
led_gpio_port->gperc = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,191 @@
|
|||||||
|
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||||
|
|
||||||
|
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||||
|
/*! \file *********************************************************************
|
||||||
|
*
|
||||||
|
* \brief AT32UC3A EVK1100 board LEDs support package.
|
||||||
|
*
|
||||||
|
* This file contains definitions and services related to the LED features of
|
||||||
|
* the EVK1100 board.
|
||||||
|
*
|
||||||
|
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||||
|
* - Supported devices: All AVR32 AT32UC3A devices can be used.
|
||||||
|
* - AppNote:
|
||||||
|
*
|
||||||
|
* \author Atmel Corporation: http://www.atmel.com \n
|
||||||
|
* Support and FAQ: http://support.atmel.no/
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. 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.
|
||||||
|
*
|
||||||
|
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||||
|
* AVR product.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||||
|
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _LED_H_
|
||||||
|
#define _LED_H_
|
||||||
|
|
||||||
|
#include "compiler.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*! \name Identifiers of LEDs to Use with LED Functions
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define LED0 0x01
|
||||||
|
#define LED1 0x02
|
||||||
|
#define LED2 0x04
|
||||||
|
#define LED3 0x08
|
||||||
|
#define LED4 0x10
|
||||||
|
#define LED5 0x20
|
||||||
|
#define LED6 0x40
|
||||||
|
#define LED7 0x80
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
/*! \brief Gets the last state of all LEDs set through the LED API.
|
||||||
|
*
|
||||||
|
* \return State of all LEDs (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \note The GPIO pin configuration of all LEDs is left unchanged.
|
||||||
|
*/
|
||||||
|
extern U32 LED_Read_Display(void);
|
||||||
|
|
||||||
|
/*! \brief Sets the state of all LEDs.
|
||||||
|
*
|
||||||
|
* \param leds New state of all LEDs (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \note The pins of all LEDs are set to GPIO output mode.
|
||||||
|
*/
|
||||||
|
extern void LED_Display(U32 leds);
|
||||||
|
|
||||||
|
/*! \brief Gets the last state of the specified LEDs set through the LED API.
|
||||||
|
*
|
||||||
|
* \param mask LEDs of which to get the state (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \return State of the specified LEDs (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \note The GPIO pin configuration of all LEDs is left unchanged.
|
||||||
|
*/
|
||||||
|
extern U32 LED_Read_Display_Mask(U32 mask);
|
||||||
|
|
||||||
|
/*! \brief Sets the state of the specified LEDs.
|
||||||
|
*
|
||||||
|
* \param mask LEDs of which to set the state (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \param leds New state of the specified LEDs (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \note The pins of the specified LEDs are set to GPIO output mode.
|
||||||
|
*/
|
||||||
|
extern void LED_Display_Mask(U32 mask, U32 leds);
|
||||||
|
|
||||||
|
/*! \brief Tests the last state of the specified LEDs set through the LED API.
|
||||||
|
*
|
||||||
|
* \param leds LEDs of which to test the state (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \return \c TRUE if at least one of the specified LEDs has a state on, else
|
||||||
|
* \c FALSE.
|
||||||
|
*
|
||||||
|
* \note The GPIO pin configuration of all LEDs is left unchanged.
|
||||||
|
*/
|
||||||
|
extern Bool LED_Test(U32 leds);
|
||||||
|
|
||||||
|
/*! \brief Turns off the specified LEDs.
|
||||||
|
*
|
||||||
|
* \param leds LEDs to turn off (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \note The pins of the specified LEDs are set to GPIO output mode.
|
||||||
|
*/
|
||||||
|
extern void LED_Off(U32 leds);
|
||||||
|
|
||||||
|
/*! \brief Turns on the specified LEDs.
|
||||||
|
*
|
||||||
|
* \param leds LEDs to turn on (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \note The pins of the specified LEDs are set to GPIO output mode.
|
||||||
|
*/
|
||||||
|
extern void LED_On(U32 leds);
|
||||||
|
|
||||||
|
/*! \brief Toggles the specified LEDs.
|
||||||
|
*
|
||||||
|
* \param leds LEDs to toggle (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \note The pins of the specified LEDs are set to GPIO output mode.
|
||||||
|
*/
|
||||||
|
extern void LED_Toggle(U32 leds);
|
||||||
|
|
||||||
|
/*! \brief Gets as a bit-field the last state of the specified LEDs set through
|
||||||
|
* the LED API.
|
||||||
|
*
|
||||||
|
* \param field LEDs of which to get the state (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \return State of the specified LEDs (1 bit per LED, beginning with the first
|
||||||
|
* specified LED).
|
||||||
|
*
|
||||||
|
* \note The GPIO pin configuration of all LEDs is left unchanged.
|
||||||
|
*/
|
||||||
|
extern U32 LED_Read_Display_Field(U32 field);
|
||||||
|
|
||||||
|
/*! \brief Sets as a bit-field the state of the specified LEDs.
|
||||||
|
*
|
||||||
|
* \param field LEDs of which to set the state (1 bit per LED).
|
||||||
|
* \param leds New state of the specified LEDs (1 bit per LED, beginning with
|
||||||
|
* the first specified LED).
|
||||||
|
*
|
||||||
|
* \note The pins of the specified LEDs are set to GPIO output mode.
|
||||||
|
*/
|
||||||
|
extern void LED_Display_Field(U32 field, U32 leds);
|
||||||
|
|
||||||
|
/*! \brief Gets the intensity of the specified LED.
|
||||||
|
*
|
||||||
|
* \param led LED of which to get the intensity (1 bit per LED; only the least
|
||||||
|
* significant set bit is used).
|
||||||
|
*
|
||||||
|
* \return Intensity of the specified LED (0x00 to 0xFF).
|
||||||
|
*
|
||||||
|
* \warning The PWM channel of the specified LED is supposed to be used only by
|
||||||
|
* this module.
|
||||||
|
*
|
||||||
|
* \note The GPIO pin configuration of all LEDs is left unchanged.
|
||||||
|
*/
|
||||||
|
extern U8 LED_Get_Intensity(U32 led);
|
||||||
|
|
||||||
|
/*! \brief Sets the intensity of the specified LEDs.
|
||||||
|
*
|
||||||
|
* \param leds LEDs of which to set the intensity (1 bit per LED).
|
||||||
|
* \param intensity New intensity of the specified LEDs (0x00 to 0xFF).
|
||||||
|
*
|
||||||
|
* \warning The PWM channels of the specified LEDs are supposed to be used only
|
||||||
|
* by this module.
|
||||||
|
*
|
||||||
|
* \note The pins of the specified LEDs are set to PWM output mode.
|
||||||
|
*/
|
||||||
|
extern void LED_Set_Intensity(U32 leds, U8 intensity);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _LED_H_
|
@ -0,0 +1,433 @@
|
|||||||
|
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||||
|
|
||||||
|
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||||
|
/*! \file *********************************************************************
|
||||||
|
*
|
||||||
|
* \brief AT32UC3A EVK1105 board header file.
|
||||||
|
*
|
||||||
|
* This file contains definitions and services related to the features of the
|
||||||
|
* EVK1105 board rev. B.
|
||||||
|
*
|
||||||
|
* To use this board, define BOARD=EVK1105.
|
||||||
|
*
|
||||||
|
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||||
|
* - Supported devices: All AVR32 AT32UC3A devices can be used.
|
||||||
|
* - AppNote:
|
||||||
|
*
|
||||||
|
* \author Atmel Corporation: http://www.atmel.com \n
|
||||||
|
* Support and FAQ: http://support.atmel.no/
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. 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.
|
||||||
|
*
|
||||||
|
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||||
|
* AVR product.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||||
|
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _EVK1105_H_
|
||||||
|
#define _EVK1105_H_
|
||||||
|
|
||||||
|
#ifdef EVK1105_REV3
|
||||||
|
# include "evk1105_rev3.h"
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include "compiler.h"
|
||||||
|
|
||||||
|
#ifdef __AVR32_ABI_COMPILER__ // Automatically defined when compiling for AVR32, not when assembling.
|
||||||
|
# include "led.h"
|
||||||
|
#endif // __AVR32_ABI_COMPILER__
|
||||||
|
|
||||||
|
|
||||||
|
/*! \name Oscillator Definitions
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
// RCOsc has no custom calibration by default. Set the following definition to
|
||||||
|
// the appropriate value if a custom RCOsc calibration has been applied to your
|
||||||
|
// part.
|
||||||
|
//#define FRCOSC AVR32_PM_RCOSC_FREQUENCY //!< RCOsc frequency: Hz.
|
||||||
|
|
||||||
|
#define FOSC32 32768 //!< Osc32 frequency: Hz.
|
||||||
|
#define OSC32_STARTUP AVR32_PM_OSCCTRL32_STARTUP_8192_RCOSC //!< Osc32 startup time: RCOsc periods.
|
||||||
|
|
||||||
|
#define FOSC0 12000000 //!< Osc0 frequency: Hz.
|
||||||
|
#define OSC0_STARTUP AVR32_PM_OSCCTRL0_STARTUP_2048_RCOSC //!< Osc0 startup time: RCOsc periods.
|
||||||
|
|
||||||
|
#define FOSC1 11289600 //!< Osc1 frequency: Hz
|
||||||
|
#define OSC1_STARTUP AVR32_PM_OSCCTRL1_STARTUP_2048_RCOSC //!< Osc1 startup time: RCOsc periods.
|
||||||
|
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
/*! \name SDRAM Definitions
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
//! Part header file of used SDRAM(s).
|
||||||
|
#define SDRAM_PART_HDR "MT48LC16M16A2TG7E/mt48lc16m16a2tg7e.h"
|
||||||
|
|
||||||
|
//! Data bus width to use the SDRAM(s) with (16 or 32 bits; always 16 bits on
|
||||||
|
//! UC3).
|
||||||
|
#define SDRAM_DBW 16
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
/*! \name USB Definitions
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
//! Multiplexed pin used for USB_ID: AVR32_USBB_USB_ID_x_x.
|
||||||
|
//! To be selected according to the AVR32_USBB_USB_ID_x_x_PIN and
|
||||||
|
//! AVR32_USBB_USB_ID_x_x_FUNCTION definitions from <avr32/uc3axxxx.h>.
|
||||||
|
#define AVR32_USBB_USB_ID_0_2_PIN 21
|
||||||
|
#define AVR32_USBB_USB_ID_0_2_FUNCTION 2
|
||||||
|
#define USB_ID AVR32_USBB_USB_ID_0_2
|
||||||
|
|
||||||
|
//! Multiplexed pin used for USB_VBOF: AVR32_USBB_USB_VBOF_x_x.
|
||||||
|
//! To be selected according to the AVR32_USBB_USB_VBOF_x_x_PIN and
|
||||||
|
//! AVR32_USBB_USB_VBOF_x_x_FUNCTION definitions from <avr32/uc3axxxx.h>.
|
||||||
|
# define USB_VBOF AVR32_USBB_USB_VBOF_0_1
|
||||||
|
|
||||||
|
|
||||||
|
//! Active level of the USB_VBOF output pin.
|
||||||
|
# define USB_VBOF_ACTIVE_LEVEL LOW
|
||||||
|
|
||||||
|
//! USB overcurrent detection pin.
|
||||||
|
# define USB_OVERCURRENT_DETECT_PIN AVR32_PIN_PX15
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
//! GPIO connection of the MAC PHY PWR_DOWN/INT signal.
|
||||||
|
# define MACB_INTERRUPT_PIN AVR32_PIN_PA26
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//! Number of LEDs.
|
||||||
|
#define LED_COUNT 4
|
||||||
|
|
||||||
|
/*! \name GPIO Connections of LEDs
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
# define LED0_GPIO AVR32_PIN_PB27
|
||||||
|
# define LED1_GPIO AVR32_PIN_PB28
|
||||||
|
# define LED2_GPIO AVR32_PIN_PA05
|
||||||
|
# define LED3_GPIO AVR32_PIN_PA06
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name Color Identifiers of LEDs to Use with LED Functions
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define LED_MONO0_GREEN LED0
|
||||||
|
#define LED_MONO1_GREEN LED1
|
||||||
|
#define LED_MONO2_GREEN LED2
|
||||||
|
#define LED_MONO3_GREEN LED3
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name PWM Channels of LEDs
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define LED0_PWM 4
|
||||||
|
#define LED1_PWM 5
|
||||||
|
#define LED2_PWM (-1)
|
||||||
|
#define LED3_PWM (-1)
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name PWM Functions of LEDs
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
/* TODO: Implement PWM functionality */
|
||||||
|
#define LED0_PWM_FUNCTION (-1)//AVR32_PWM_0_FUNCTION
|
||||||
|
#define LED1_PWM_FUNCTION (-1)//AVR32_PWM_1_FUNCTION
|
||||||
|
#define LED2_PWM_FUNCTION (-1)
|
||||||
|
#define LED3_PWM_FUNCTION (-1)
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
//! External interrupt connection of touch sensor.
|
||||||
|
#define QT1081_EIC_EXTINT_PIN AVR32_EIC_EXTINT_1_PIN
|
||||||
|
#define QT1081_EIC_EXTINT_FUNCTION AVR32_EIC_EXTINT_1_FUNCTION
|
||||||
|
#define QT1081_EIC_EXTINT_IRQ AVR32_EIC_IRQ_1
|
||||||
|
#define QT1081_EIC_EXTINT_INT AVR32_EIC_INT1
|
||||||
|
/*! \name Touch sensor low power mode select
|
||||||
|
*/
|
||||||
|
#define QT1081_LP_MODE AVR32_PIN_PB29
|
||||||
|
|
||||||
|
/*! \name GPIO Connections of touch buttons
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define QT1081_TOUCH_SENSOR_0 AVR32_PIN_PB22
|
||||||
|
#define QT1081_TOUCH_SENSOR_0_PRESSED 1
|
||||||
|
#define QT1081_TOUCH_SENSOR_1 AVR32_PIN_PB23
|
||||||
|
#define QT1081_TOUCH_SENSOR_1_PRESSED 1
|
||||||
|
#define QT1081_TOUCH_SENSOR_2 AVR32_PIN_PB24
|
||||||
|
#define QT1081_TOUCH_SENSOR_2_PRESSED 1
|
||||||
|
#define QT1081_TOUCH_SENSOR_3 AVR32_PIN_PB25
|
||||||
|
#define QT1081_TOUCH_SENSOR_3_PRESSED 1
|
||||||
|
#define QT1081_TOUCH_SENSOR_4 AVR32_PIN_PB26
|
||||||
|
#define QT1081_TOUCH_SENSOR_4_PRESSED 1
|
||||||
|
|
||||||
|
#define QT1081_TOUCH_SENSOR_ENTER QT1081_TOUCH_SENSOR_4
|
||||||
|
#define QT1081_TOUCH_SENSOR_ENTER_PRESSED QT1081_TOUCH_SENSOR_4_PRESSED
|
||||||
|
#define QT1081_TOUCH_SENSOR_LEFT QT1081_TOUCH_SENSOR_3
|
||||||
|
#define QT1081_TOUCH_SENSOR_LEFT_PRESSED QT1081_TOUCH_SENSOR_3_PRESSED
|
||||||
|
#define QT1081_TOUCH_SENSOR_RIGHT QT1081_TOUCH_SENSOR_2
|
||||||
|
#define QT1081_TOUCH_SENSOR_RIGHT_PRESSED QT1081_TOUCH_SENSOR_2_PRESSED
|
||||||
|
#define QT1081_TOUCH_SENSOR_UP QT1081_TOUCH_SENSOR_0
|
||||||
|
#define QT1081_TOUCH_SENSOR_UP_PRESSED QT1081_TOUCH_SENSOR_0_PRESSED
|
||||||
|
#define QT1081_TOUCH_SENSOR_DOWN QT1081_TOUCH_SENSOR_1
|
||||||
|
#define QT1081_TOUCH_SENSOR_DOWN_PRESSED QT1081_TOUCH_SENSOR_1_PRESSED
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name SPI Connections of the AT45DBX Data Flash Memory
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define AT45DBX_SPI (&AVR32_SPI0)
|
||||||
|
#define AT45DBX_SPI_NPCS 0
|
||||||
|
#define AT45DBX_SPI_SCK_PIN AVR32_SPI0_SCK_0_0_PIN
|
||||||
|
#define AT45DBX_SPI_SCK_FUNCTION AVR32_SPI0_SCK_0_0_FUNCTION
|
||||||
|
#define AT45DBX_SPI_MISO_PIN AVR32_SPI0_MISO_0_0_PIN
|
||||||
|
#define AT45DBX_SPI_MISO_FUNCTION AVR32_SPI0_MISO_0_0_FUNCTION
|
||||||
|
#define AT45DBX_SPI_MOSI_PIN AVR32_SPI0_MOSI_0_0_PIN
|
||||||
|
#define AT45DBX_SPI_MOSI_FUNCTION AVR32_SPI0_MOSI_0_0_FUNCTION
|
||||||
|
#define AT45DBX_SPI_NPCS0_PIN AVR32_SPI0_NPCS_0_0_PIN
|
||||||
|
#define AT45DBX_SPI_NPCS0_FUNCTION AVR32_SPI0_NPCS_0_0_FUNCTION
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name GPIO and SPI Connections of the SD/MMC Connector
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define SD_MMC_CARD_DETECT_PIN AVR32_PIN_PA02
|
||||||
|
#define SD_MMC_WRITE_PROTECT_PIN AVR32_PIN_PA18
|
||||||
|
#define SD_MMC_SPI (&AVR32_SPI0)
|
||||||
|
#define SD_MMC_SPI_NPCS 1
|
||||||
|
#define SD_MMC_SPI_SCK_PIN AVR32_SPI0_SCK_0_0_PIN
|
||||||
|
#define SD_MMC_SPI_SCK_FUNCTION AVR32_SPI0_SCK_0_0_FUNCTION
|
||||||
|
#define SD_MMC_SPI_MISO_PIN AVR32_SPI0_MISO_0_0_PIN
|
||||||
|
#define SD_MMC_SPI_MISO_FUNCTION AVR32_SPI0_MISO_0_0_FUNCTION
|
||||||
|
#define SD_MMC_SPI_MOSI_PIN AVR32_SPI0_MOSI_0_0_PIN
|
||||||
|
#define SD_MMC_SPI_MOSI_FUNCTION AVR32_SPI0_MOSI_0_0_FUNCTION
|
||||||
|
#define SD_MMC_SPI_NPCS_PIN AVR32_SPI0_NPCS_1_0_PIN
|
||||||
|
#define SD_MMC_SPI_NPCS_FUNCTION AVR32_SPI0_NPCS_1_0_FUNCTION
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
/*! \name TWI expansion
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define EXPANSION_TWI (&AVR32_TWI)
|
||||||
|
#define EXPANSION_RESET AVR32_PIN_PX16
|
||||||
|
#define EXPANSION_TWI_SCL_PIN AVR32_TWI_SCL_0_0_PIN
|
||||||
|
#define EXPANSION_TWI_SCL_FUNCTION AVR32_TWI_SCL_0_0_FUNCTION
|
||||||
|
#define EXPANSION_TWI_SDA_PIN AVR32_TWI_SDA_0_0_PIN
|
||||||
|
#define EXPANSION_TWI_SDA_FUNCTION AVR32_TWI_SDA_0_0_FUNCTION
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name Wireless expansion
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define WEXPANSION_EXTINT_PIN AVR32_EIC_EXTINT_8_PIN
|
||||||
|
#define WEXPANSION_EXTINT_FUNCTION AVR32_EIC_EXTINT_8_FUNCTION
|
||||||
|
#define WEXPANSION_GPIO1 AVR32_PIN_PB30
|
||||||
|
#define WEXPANSION_GPIO2 AVR32_PIN_PB31
|
||||||
|
|
||||||
|
#define WEXPANSION_SPI (&AVR32_SPI0)
|
||||||
|
#define WEXPANSION_SPI_NPCS 2
|
||||||
|
#define WEXPANSION_SPI_SCK_PIN AVR32_SPI0_SCK_0_0_PIN
|
||||||
|
#define WEXPANSION_SPI_SCK_FUNCTION AVR32_SPI0_SCK_0_0_FUNCTION
|
||||||
|
#define WEXPANSION_SPI_MISO_PIN AVR32_SPI0_MISO_0_0_PIN
|
||||||
|
#define WEXPANSION_SPI_MISO_FUNCTION AVR32_SPI0_MISO_0_0_FUNCTION
|
||||||
|
#define WEXPANSION_SPI_MOSI_PIN AVR32_SPI0_MOSI_0_0_PIN
|
||||||
|
#define WEXPANSION_SPI_MOSI_FUNCTION AVR32_SPI0_MOSI_0_0_FUNCTION
|
||||||
|
#define WEXPANSION_SPI_NPCS_PIN AVR32_SPI0_NPCS_2_0_PIN
|
||||||
|
#define WEXPANSION_SPI_NPCS_FUNCTION AVR32_SPI0_NPCS_2_0_FUNCTION
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name ET024006DHU TFT display
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
#define ET024006DHU_TE_PIN AVR32_PIN_PX19
|
||||||
|
#define ET024006DHU_RESET_PIN AVR32_PIN_PX22
|
||||||
|
#define ET024006DHU_BL_PIN AVR32_PWM_6_PIN
|
||||||
|
#define ET024006DHU_BL_FUNCTION AVR32_PWM_6_FUNCTION
|
||||||
|
#define ET024006DHU_DNC_PIN AVR32_EBI_ADDR_21_1_PIN
|
||||||
|
#define ET024006DHU_DNC_FUNCTION AVR32_EBI_ADDR_21_1_FUNCTION
|
||||||
|
#define ET024006DHU_EBI_NCS_PIN AVR32_EBI_NCS_0_1_PIN
|
||||||
|
#define ET024006DHU_EBI_NCS_FUNCTION AVR32_EBI_NCS_0_1_FUNCTION
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
/*! \name Optional SPI connection to the TFT
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
#define ET024006DHU_SPI (&AVR32_SPI0)
|
||||||
|
#define ET024006DHU_SPI_NPCS 3
|
||||||
|
#define ET024006DHU_SPI_SCK_PIN AVR32_SPI0_SCK_0_0_PIN
|
||||||
|
#define ET024006DHU_SPI_SCK_FUNCTION AVR32_SPI0_SCK_0_0_FUNCTION
|
||||||
|
#define ET024006DHU_SPI_MISO_PIN AVR32_SPI0_MISO_0_0_PIN
|
||||||
|
#define ET024006DHU_SPI_MISO_FUNCTION AVR32_SPI0_MISO_0_0_FUNCTION
|
||||||
|
#define ET024006DHU_SPI_MOSI_PIN AVR32_SPI0_MOSI_0_0_PIN
|
||||||
|
#define ET024006DHU_SPI_MOSI_FUNCTION AVR32_SPI0_MOSI_0_0_FUNCTION
|
||||||
|
#define ET024006DHU_SPI_NPCS_PIN AVR32_SPI1_NPCS_3_0_PIN
|
||||||
|
#define ET024006DHU_SPI_NPCS_FUNCTION AVR32_SPI1_NPCS_3_0_FUNCTION
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
/*! \name Audio amplifier connection to the DAC
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
#define TPA6130_ABDAC (&AVR32_ABDAC)
|
||||||
|
|
||||||
|
#define TPA6130_DATA0_PIN AVR32_ABDAC_DATA_0_1_PIN
|
||||||
|
#define TPA6130_DATA0_FUNCTION AVR32_ABDAC_DATA_0_1_FUNCTION
|
||||||
|
#define TPA6130_DATAN0_PIN AVR32_ABDAC_DATAN_0_1_PIN
|
||||||
|
#define TPA6130_DATAN0_FUNCTION AVR32_ABDAC_DATAN_0_1_FUNCTION
|
||||||
|
#define TPA6130_DATA1_PIN AVR32_ABDAC_DATA_1_1_PIN
|
||||||
|
#define TPA6130_DATA1_FUNCTION AVR32_ABDAC_DATA_1_1_FUNCTION
|
||||||
|
#define TPA6130_DATAN1_PIN AVR32_ABDAC_DATAN_1_1_PIN
|
||||||
|
#define TPA6130_DATAN1_FUNCTION AVR32_ABDAC_DATAN_1_1_FUNCTION
|
||||||
|
|
||||||
|
#define TPA6130_ABDAC_PDCA_PID AVR32_PDCA_PID_ABDAC_TX
|
||||||
|
#define TPA6130_ABDAC_PDCA_CHANNEL 0
|
||||||
|
#define TPA6130_ABDAC_PDCA_IRQ AVR32_PDCA_IRQ_0
|
||||||
|
#define TPA6130_ABDAC_PDCA_INT_LEVEL AVR32_INTC_INT3
|
||||||
|
|
||||||
|
#define TPA6130_TWI (&AVR32_TWI)
|
||||||
|
#define TPA6130_TWI_SCL_PIN AVR32_TWI_SCL_0_0_PIN
|
||||||
|
#define TPA6130_TWI_SCL_FUNCTION AVR32_TWI_SCL_0_0_FUNCTION
|
||||||
|
#define TPA6130_TWI_SDA_PIN AVR32_TWI_SDA_0_0_PIN
|
||||||
|
#define TPA6130_TWI_SDA_FUNCTION AVR32_TWI_SDA_0_0_FUNCTION
|
||||||
|
|
||||||
|
//! }@
|
||||||
|
/*! \name TI TLV320AIC23B sound chip
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define TLV320_SSC (&AVR32_SSC)
|
||||||
|
#define TLV320_SSC_TX_CLOCK_PIN AVR32_SSC_TX_CLOCK_0_PIN
|
||||||
|
#define TLV320_SSC_TX_CLOCK_FUNCTION AVR32_SSC_TX_CLOCK_0_FUNCTION
|
||||||
|
#define TLV320_SSC_TX_DATA_PIN AVR32_SSC_TX_DATA_0_PIN
|
||||||
|
#define TLV320_SSC_TX_DATA_FUNCTION AVR32_SSC_TX_DATA_0_FUNCTION
|
||||||
|
#define TLV320_SSC_TX_FRAME_SYNC_PIN AVR32_SSC_TX_FRAME_SYNC_0_PIN
|
||||||
|
#define TLV320_SSC_TX_FRAME_SYNC_FUNCTION AVR32_SSC_TX_FRAME_SYNC_0_FUNCTION
|
||||||
|
|
||||||
|
#define TLV320_TWI (&AVR32_TWI)
|
||||||
|
#define TLV320_TWI_SCL_PIN AVR32_TWI_SCL_0_0_PIN
|
||||||
|
#define TLV320_TWI_SCL_FUNCTION AVR32_TWI_SCL_0_0_FUNCTION
|
||||||
|
#define TLV320_TWI_SDA_PIN AVR32_TWI_SDA_0_0_PIN
|
||||||
|
#define TLV320_TWI_SDA_FUNCTION AVR32_TWI_SDA_0_0_FUNCTION
|
||||||
|
|
||||||
|
#define TLV320_PM_GCLK_PIN AVR32_PM_GCLK_0_0_PIN
|
||||||
|
#define TLV320_PM_GCLK_FUNCTION AVR32_PM_GCLK_0_0_FUNCTION
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
////! \name SPI: Apple Authentication Chip Hardware Connections
|
||||||
|
////! @{
|
||||||
|
#define IPOD_AUTH_CHIP_SPI (&AVR32_SPI0)
|
||||||
|
#define IPOD_AUTH_CHIP_SPI_IRQ AVR32_SPI0_IRQ
|
||||||
|
#define IPOD_AUTH_CHIP_SPI_NPCS 2
|
||||||
|
#define IPOD_AUTH_CHIP_SPI_SCK_PIN AVR32_SPI0_SCK_0_0_PIN
|
||||||
|
#define IPOD_AUTH_CHIP_SPI_SCK_FUNCTION AVR32_SPI0_SCK_0_0_FUNCTION
|
||||||
|
#define IPOD_AUTH_CHIP_SPI_MISO_PIN AVR32_SPI0_MISO_0_0_PIN
|
||||||
|
#define IPOD_AUTH_CHIP_SPI_MISO_FUNCTION AVR32_SPI0_MISO_0_0_FUNCTION
|
||||||
|
#define IPOD_AUTH_CHIP_SPI_MOSI_PIN AVR32_SPI0_MOSI_0_0_PIN
|
||||||
|
#define IPOD_AUTH_CHIP_SPI_MOSI_FUNCTION AVR32_SPI0_MOSI_0_0_FUNCTION
|
||||||
|
#define IPOD_AUTH_CHIP_SPI_NPCS_PIN AVR32_SPI0_NPCS_2_0_PIN
|
||||||
|
#define IPOD_AUTH_CHIP_SPI_NPCS_FUNCTION AVR32_SPI0_NPCS_2_0_FUNCTION
|
||||||
|
#define IPOD_AUTH_CHIP_SPI_N_RESET_PIN AVR32_PIN_PB30
|
||||||
|
#define IPOD_AUTH_CHIP_SPI_CP_READY_PIN AVR32_PIN_PB31
|
||||||
|
//! }@
|
||||||
|
|
||||||
|
/*! \name Connections of the iPOD Authentication Coprocessor
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
#define IPOD_AUTH_CHIP_TWI (&AVR32_TWI)
|
||||||
|
#define IPOD_AUTH_CHIP_TWI_SCL_PIN AVR32_TWI_SCL_0_0_PIN
|
||||||
|
#define IPOD_AUTH_CHIP_TWI_SCL_FUNCTION AVR32_TWI_SCL_0_0_FUNCTION
|
||||||
|
#define IPOD_AUTH_CHIP_TWI_SDA_PIN AVR32_TWI_SDA_0_0_PIN
|
||||||
|
#define IPOD_AUTH_CHIP_TWI_SDA_FUNCTION AVR32_TWI_SDA_0_0_FUNCTION
|
||||||
|
#define IPOD_AUTH_CHIP_TWI_N_RESET_PIN AVR32_PIN_PX16
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name USART connection to the UC3B board controller
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
#define USART0_RXD_PIN AVR32_USART0_RXD_0_0_PIN
|
||||||
|
#define USART0_RXD_FUNCTION AVR32_USART0_RXD_0_0_FUNCTION
|
||||||
|
#define USART0_TXD_PIN AVR32_USART0_TXD_0_0_PIN
|
||||||
|
#define USART0_TXD_FUNCTION AVR32_USART0_TXD_0_0_FUNCTION
|
||||||
|
#define USART0_RTS_PIN AVR32_USART0_RTS_0_0_PIN
|
||||||
|
#define USART0_RTS_FUNCTION AVR32_USART0_RTS_0_0_FUNCTION
|
||||||
|
#define USART0_CTS_PIN AVR32_USART0_CTS_0_0_PIN
|
||||||
|
#define USART0_CTS_FUNCTION AVR32_USART0_CTS_0_0_FUNCTION
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
#define ADC_VEXT_PIN AVR32_ADC_AD_7_PIN
|
||||||
|
#define ADC_VEXT_FUNCTION AVR32_ADC_AD_7_FUNCTION
|
||||||
|
|
||||||
|
/*! \name LCD Connections of the ET024006DHU display
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define ET024006DHU_SMC_USE_NCS 0
|
||||||
|
#define ET024006DHU_SMC_COMPONENT_CS "smc_et024006dhu.h"
|
||||||
|
|
||||||
|
#define ET024006DHU_EBI_DATA_0 AVR32_EBI_DATA_0
|
||||||
|
#define ET024006DHU_EBI_DATA_1 AVR32_EBI_DATA_1
|
||||||
|
#define ET024006DHU_EBI_DATA_2 AVR32_EBI_DATA_2
|
||||||
|
#define ET024006DHU_EBI_DATA_3 AVR32_EBI_DATA_3
|
||||||
|
#define ET024006DHU_EBI_DATA_4 AVR32_EBI_DATA_4
|
||||||
|
#define ET024006DHU_EBI_DATA_5 AVR32_EBI_DATA_5
|
||||||
|
#define ET024006DHU_EBI_DATA_6 AVR32_EBI_DATA_6
|
||||||
|
#define ET024006DHU_EBI_DATA_7 AVR32_EBI_DATA_7
|
||||||
|
#define ET024006DHU_EBI_DATA_8 AVR32_EBI_DATA_8
|
||||||
|
#define ET024006DHU_EBI_DATA_9 AVR32_EBI_DATA_9
|
||||||
|
#define ET024006DHU_EBI_DATA_10 AVR32_EBI_DATA_10
|
||||||
|
#define ET024006DHU_EBI_DATA_11 AVR32_EBI_DATA_11
|
||||||
|
#define ET024006DHU_EBI_DATA_12 AVR32_EBI_DATA_12
|
||||||
|
#define ET024006DHU_EBI_DATA_13 AVR32_EBI_DATA_13
|
||||||
|
#define ET024006DHU_EBI_DATA_14 AVR32_EBI_DATA_14
|
||||||
|
#define ET024006DHU_EBI_DATA_15 AVR32_EBI_DATA_15
|
||||||
|
|
||||||
|
#define ET024006DHU_EBI_ADDR_21 AVR32_EBI_ADDR_21_1
|
||||||
|
|
||||||
|
#define ET024006DHU_EBI_NWE AVR32_EBI_NWE0_0
|
||||||
|
#define ET024006DHU_EBI_NRD AVR32_EBI_NRD_0
|
||||||
|
#define ET024006DHU_EBI_NCS AVR32_EBI_NCS_0_1
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // !EVK1105_REVA
|
||||||
|
|
||||||
|
#endif // _EVK1105_H_
|
@ -0,0 +1,346 @@
|
|||||||
|
/* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||||
|
|
||||||
|
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||||
|
/*! \file *********************************************************************
|
||||||
|
*
|
||||||
|
* \brief AT32UC3A EVK1105 board LEDs support package.
|
||||||
|
*
|
||||||
|
* This file contains definitions and services related to the LED features of
|
||||||
|
* the EVK1105 board.
|
||||||
|
*
|
||||||
|
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||||
|
* - Supported devices: All AVR32 AT32UC3A devices can be used.
|
||||||
|
* - AppNote:
|
||||||
|
*
|
||||||
|
* \author Atmel Corporation: http://www.atmel.com \n
|
||||||
|
* Support and FAQ: http://support.atmel.no/
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. 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.
|
||||||
|
*
|
||||||
|
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||||
|
* AVR product.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||||
|
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <avr32/io.h>
|
||||||
|
#include "preprocessor.h"
|
||||||
|
#include "compiler.h"
|
||||||
|
#include "evk1105.h"
|
||||||
|
#include "led.h"
|
||||||
|
|
||||||
|
|
||||||
|
//! Structure describing LED hardware connections.
|
||||||
|
typedef const struct
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
U32 PORT; //!< LED GPIO port.
|
||||||
|
U32 PIN_MASK; //!< Bit-mask of LED pin in GPIO port.
|
||||||
|
} GPIO; //!< LED GPIO descriptor.
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
S32 CHANNEL; //!< LED PWM channel (< 0 if N/A).
|
||||||
|
S32 FUNCTION; //!< LED pin PWM function (< 0 if N/A).
|
||||||
|
} PWM; //!< LED PWM descriptor.
|
||||||
|
} tLED_DESCRIPTOR;
|
||||||
|
|
||||||
|
|
||||||
|
//! Hardware descriptors of all LEDs.
|
||||||
|
static tLED_DESCRIPTOR LED_DESCRIPTOR[LED_COUNT] =
|
||||||
|
{
|
||||||
|
#define INSERT_LED_DESCRIPTOR(LED_NO, unused) \
|
||||||
|
{ \
|
||||||
|
{LED##LED_NO##_GPIO / 32, 1 << (LED##LED_NO##_GPIO % 32)},\
|
||||||
|
{LED##LED_NO##_PWM, LED##LED_NO##_PWM_FUNCTION } \
|
||||||
|
},
|
||||||
|
MREPEAT(LED_COUNT, INSERT_LED_DESCRIPTOR, ~)
|
||||||
|
#undef INSERT_LED_DESCRIPTOR
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//! Saved state of all LEDs.
|
||||||
|
static volatile U32 LED_State = (1 << LED_COUNT) - 1;
|
||||||
|
|
||||||
|
|
||||||
|
U32 LED_Read_Display(void)
|
||||||
|
{
|
||||||
|
return LED_State;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LED_Display(U32 leds)
|
||||||
|
{
|
||||||
|
// Use the LED descriptors to get the connections of a given LED to the MCU.
|
||||||
|
tLED_DESCRIPTOR *led_descriptor;
|
||||||
|
volatile avr32_gpio_port_t *led_gpio_port;
|
||||||
|
|
||||||
|
// Make sure only existing LEDs are specified.
|
||||||
|
leds &= (1 << LED_COUNT) - 1;
|
||||||
|
|
||||||
|
// Update the saved state of all LEDs with the requested changes.
|
||||||
|
LED_State = leds;
|
||||||
|
|
||||||
|
// For all LEDs...
|
||||||
|
for (led_descriptor = &LED_DESCRIPTOR[0];
|
||||||
|
led_descriptor < LED_DESCRIPTOR + LED_COUNT;
|
||||||
|
led_descriptor++)
|
||||||
|
{
|
||||||
|
// Set the LED to the requested state.
|
||||||
|
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||||
|
if (leds & 1)
|
||||||
|
{
|
||||||
|
led_gpio_port->ovrc = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
led_gpio_port->ovrs = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
}
|
||||||
|
led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
leds >>= 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
U32 LED_Read_Display_Mask(U32 mask)
|
||||||
|
{
|
||||||
|
return Rd_bits(LED_State, mask);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LED_Display_Mask(U32 mask, U32 leds)
|
||||||
|
{
|
||||||
|
// Use the LED descriptors to get the connections of a given LED to the MCU.
|
||||||
|
tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
|
||||||
|
volatile avr32_gpio_port_t *led_gpio_port;
|
||||||
|
U8 led_shift;
|
||||||
|
|
||||||
|
// Make sure only existing LEDs are specified.
|
||||||
|
mask &= (1 << LED_COUNT) - 1;
|
||||||
|
|
||||||
|
// Update the saved state of all LEDs with the requested changes.
|
||||||
|
Wr_bits(LED_State, mask, leds);
|
||||||
|
|
||||||
|
// While there are specified LEDs left to manage...
|
||||||
|
while (mask)
|
||||||
|
{
|
||||||
|
// Select the next specified LED and set it to the requested state.
|
||||||
|
led_shift = 1 + ctz(mask);
|
||||||
|
led_descriptor += led_shift;
|
||||||
|
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||||
|
leds >>= led_shift - 1;
|
||||||
|
if (leds & 1)
|
||||||
|
{
|
||||||
|
led_gpio_port->ovrc = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
led_gpio_port->ovrs = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
}
|
||||||
|
led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
leds >>= 1;
|
||||||
|
mask >>= led_shift;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Bool LED_Test(U32 leds)
|
||||||
|
{
|
||||||
|
return Tst_bits(LED_State, leds);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LED_Off(U32 leds)
|
||||||
|
{
|
||||||
|
// Use the LED descriptors to get the connections of a given LED to the MCU.
|
||||||
|
tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
|
||||||
|
volatile avr32_gpio_port_t *led_gpio_port;
|
||||||
|
U8 led_shift;
|
||||||
|
|
||||||
|
// Make sure only existing LEDs are specified.
|
||||||
|
leds &= (1 << LED_COUNT) - 1;
|
||||||
|
|
||||||
|
// Update the saved state of all LEDs with the requested changes.
|
||||||
|
Clr_bits(LED_State, leds);
|
||||||
|
|
||||||
|
// While there are specified LEDs left to manage...
|
||||||
|
while (leds)
|
||||||
|
{
|
||||||
|
// Select the next specified LED and turn it off.
|
||||||
|
led_shift = 1 + ctz(leds);
|
||||||
|
led_descriptor += led_shift;
|
||||||
|
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||||
|
led_gpio_port->ovrs = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
leds >>= led_shift;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LED_On(U32 leds)
|
||||||
|
{
|
||||||
|
// Use the LED descriptors to get the connections of a given LED to the MCU.
|
||||||
|
tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
|
||||||
|
volatile avr32_gpio_port_t *led_gpio_port;
|
||||||
|
U8 led_shift;
|
||||||
|
|
||||||
|
// Make sure only existing LEDs are specified.
|
||||||
|
leds &= (1 << LED_COUNT) - 1;
|
||||||
|
|
||||||
|
// Update the saved state of all LEDs with the requested changes.
|
||||||
|
Set_bits(LED_State, leds);
|
||||||
|
|
||||||
|
// While there are specified LEDs left to manage...
|
||||||
|
while (leds)
|
||||||
|
{
|
||||||
|
// Select the next specified LED and turn it on.
|
||||||
|
led_shift = 1 + ctz(leds);
|
||||||
|
led_descriptor += led_shift;
|
||||||
|
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||||
|
led_gpio_port->ovrc = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
leds >>= led_shift;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LED_Toggle(U32 leds)
|
||||||
|
{
|
||||||
|
// Use the LED descriptors to get the connections of a given LED to the MCU.
|
||||||
|
tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
|
||||||
|
volatile avr32_gpio_port_t *led_gpio_port;
|
||||||
|
U8 led_shift;
|
||||||
|
|
||||||
|
// Make sure only existing LEDs are specified.
|
||||||
|
leds &= (1 << LED_COUNT) - 1;
|
||||||
|
|
||||||
|
// Update the saved state of all LEDs with the requested changes.
|
||||||
|
Tgl_bits(LED_State, leds);
|
||||||
|
|
||||||
|
// While there are specified LEDs left to manage...
|
||||||
|
while (leds)
|
||||||
|
{
|
||||||
|
// Select the next specified LED and toggle it.
|
||||||
|
led_shift = 1 + ctz(leds);
|
||||||
|
led_descriptor += led_shift;
|
||||||
|
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||||
|
led_gpio_port->ovrt = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
leds >>= led_shift;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
U32 LED_Read_Display_Field(U32 field)
|
||||||
|
{
|
||||||
|
return Rd_bitfield(LED_State, field);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LED_Display_Field(U32 field, U32 leds)
|
||||||
|
{
|
||||||
|
// Move the bit-field to the appropriate position for the bit-mask.
|
||||||
|
LED_Display_Mask(field, leds << ctz(field));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
U8 LED_Get_Intensity(U32 led)
|
||||||
|
{
|
||||||
|
tLED_DESCRIPTOR *led_descriptor;
|
||||||
|
|
||||||
|
// Check that the argument value is valid.
|
||||||
|
led = ctz(led);
|
||||||
|
led_descriptor = &LED_DESCRIPTOR[led];
|
||||||
|
if (led >= LED_COUNT || led_descriptor->PWM.CHANNEL < 0) return 0;
|
||||||
|
|
||||||
|
// Return the duty cycle value if the LED PWM channel is enabled, else 0.
|
||||||
|
return (AVR32_PWM.sr & (1 << led_descriptor->PWM.CHANNEL)) ?
|
||||||
|
AVR32_PWM.channel[led_descriptor->PWM.CHANNEL].cdty : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void LED_Set_Intensity(U32 leds, U8 intensity)
|
||||||
|
{
|
||||||
|
tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
|
||||||
|
volatile avr32_pwm_channel_t *led_pwm_channel;
|
||||||
|
volatile avr32_gpio_port_t *led_gpio_port;
|
||||||
|
U8 led_shift;
|
||||||
|
|
||||||
|
// For each specified LED...
|
||||||
|
for (leds &= (1 << LED_COUNT) - 1; leds; leds >>= led_shift)
|
||||||
|
{
|
||||||
|
// Select the next specified LED and check that it has a PWM channel.
|
||||||
|
led_shift = 1 + ctz(leds);
|
||||||
|
led_descriptor += led_shift;
|
||||||
|
if (led_descriptor->PWM.CHANNEL < 0) continue;
|
||||||
|
|
||||||
|
// Initialize or update the LED PWM channel.
|
||||||
|
led_pwm_channel = &AVR32_PWM.channel[led_descriptor->PWM.CHANNEL];
|
||||||
|
if (!(AVR32_PWM.sr & (1 << led_descriptor->PWM.CHANNEL)))
|
||||||
|
{
|
||||||
|
led_pwm_channel->cmr = (AVR32_PWM_CPRE_MCK << AVR32_PWM_CPRE_OFFSET) &
|
||||||
|
~(AVR32_PWM_CALG_MASK |
|
||||||
|
AVR32_PWM_CPOL_MASK |
|
||||||
|
AVR32_PWM_CPD_MASK);
|
||||||
|
led_pwm_channel->cprd = 0x000000FF;
|
||||||
|
led_pwm_channel->cdty = intensity;
|
||||||
|
AVR32_PWM.ena = 1 << led_descriptor->PWM.CHANNEL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AVR32_PWM.isr;
|
||||||
|
while (!(AVR32_PWM.isr & (1 << led_descriptor->PWM.CHANNEL)));
|
||||||
|
led_pwm_channel->cupd = intensity;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Switch the LED pin to its PWM function.
|
||||||
|
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||||
|
if (led_descriptor->PWM.FUNCTION & 0x1)
|
||||||
|
{
|
||||||
|
led_gpio_port->pmr0s = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
led_gpio_port->pmr0c = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
}
|
||||||
|
if (led_descriptor->PWM.FUNCTION & 0x2)
|
||||||
|
{
|
||||||
|
led_gpio_port->pmr1s = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
led_gpio_port->pmr1c = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
}
|
||||||
|
led_gpio_port->gperc = led_descriptor->GPIO.PIN_MASK;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,187 @@
|
|||||||
|
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||||
|
|
||||||
|
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||||
|
/*! \file *********************************************************************
|
||||||
|
*
|
||||||
|
* \brief AT32UC3A EVK1105 board LEDs support package.
|
||||||
|
*
|
||||||
|
* This file contains definitions and services related to the LED features of
|
||||||
|
* the EVK1105 board.
|
||||||
|
*
|
||||||
|
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||||
|
* - Supported devices: All AVR32 AT32UC3A devices can be used.
|
||||||
|
* - AppNote:
|
||||||
|
*
|
||||||
|
* \author Atmel Corporation: http://www.atmel.com \n
|
||||||
|
* Support and FAQ: http://support.atmel.no/
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. 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.
|
||||||
|
*
|
||||||
|
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||||
|
* AVR product.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||||
|
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _LED_H_
|
||||||
|
#define _LED_H_
|
||||||
|
|
||||||
|
#include "compiler.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*! \name Identifiers of LEDs to Use with LED Functions
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define LED0 0x01
|
||||||
|
#define LED1 0x02
|
||||||
|
#define LED2 0x04
|
||||||
|
#define LED3 0x08
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
/*! \brief Gets the last state of all LEDs set through the LED API.
|
||||||
|
*
|
||||||
|
* \return State of all LEDs (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \note The GPIO pin configuration of all LEDs is left unchanged.
|
||||||
|
*/
|
||||||
|
extern U32 LED_Read_Display(void);
|
||||||
|
|
||||||
|
/*! \brief Sets the state of all LEDs.
|
||||||
|
*
|
||||||
|
* \param leds New state of all LEDs (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \note The pins of all LEDs are set to GPIO output mode.
|
||||||
|
*/
|
||||||
|
extern void LED_Display(U32 leds);
|
||||||
|
|
||||||
|
/*! \brief Gets the last state of the specified LEDs set through the LED API.
|
||||||
|
*
|
||||||
|
* \param mask LEDs of which to get the state (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \return State of the specified LEDs (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \note The GPIO pin configuration of all LEDs is left unchanged.
|
||||||
|
*/
|
||||||
|
extern U32 LED_Read_Display_Mask(U32 mask);
|
||||||
|
|
||||||
|
/*! \brief Sets the state of the specified LEDs.
|
||||||
|
*
|
||||||
|
* \param mask LEDs of which to set the state (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \param leds New state of the specified LEDs (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \note The pins of the specified LEDs are set to GPIO output mode.
|
||||||
|
*/
|
||||||
|
extern void LED_Display_Mask(U32 mask, U32 leds);
|
||||||
|
|
||||||
|
/*! \brief Tests the last state of the specified LEDs set through the LED API.
|
||||||
|
*
|
||||||
|
* \param leds LEDs of which to test the state (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \return \c TRUE if at least one of the specified LEDs has a state on, else
|
||||||
|
* \c FALSE.
|
||||||
|
*
|
||||||
|
* \note The GPIO pin configuration of all LEDs is left unchanged.
|
||||||
|
*/
|
||||||
|
extern Bool LED_Test(U32 leds);
|
||||||
|
|
||||||
|
/*! \brief Turns off the specified LEDs.
|
||||||
|
*
|
||||||
|
* \param leds LEDs to turn off (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \note The pins of the specified LEDs are set to GPIO output mode.
|
||||||
|
*/
|
||||||
|
extern void LED_Off(U32 leds);
|
||||||
|
|
||||||
|
/*! \brief Turns on the specified LEDs.
|
||||||
|
*
|
||||||
|
* \param leds LEDs to turn on (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \note The pins of the specified LEDs are set to GPIO output mode.
|
||||||
|
*/
|
||||||
|
extern void LED_On(U32 leds);
|
||||||
|
|
||||||
|
/*! \brief Toggles the specified LEDs.
|
||||||
|
*
|
||||||
|
* \param leds LEDs to toggle (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \note The pins of the specified LEDs are set to GPIO output mode.
|
||||||
|
*/
|
||||||
|
extern void LED_Toggle(U32 leds);
|
||||||
|
|
||||||
|
/*! \brief Gets as a bit-field the last state of the specified LEDs set through
|
||||||
|
* the LED API.
|
||||||
|
*
|
||||||
|
* \param field LEDs of which to get the state (1 bit per LED).
|
||||||
|
*
|
||||||
|
* \return State of the specified LEDs (1 bit per LED, beginning with the first
|
||||||
|
* specified LED).
|
||||||
|
*
|
||||||
|
* \note The GPIO pin configuration of all LEDs is left unchanged.
|
||||||
|
*/
|
||||||
|
extern U32 LED_Read_Display_Field(U32 field);
|
||||||
|
|
||||||
|
/*! \brief Sets as a bit-field the state of the specified LEDs.
|
||||||
|
*
|
||||||
|
* \param field LEDs of which to set the state (1 bit per LED).
|
||||||
|
* \param leds New state of the specified LEDs (1 bit per LED, beginning with
|
||||||
|
* the first specified LED).
|
||||||
|
*
|
||||||
|
* \note The pins of the specified LEDs are set to GPIO output mode.
|
||||||
|
*/
|
||||||
|
extern void LED_Display_Field(U32 field, U32 leds);
|
||||||
|
|
||||||
|
/*! \brief Gets the intensity of the specified LED.
|
||||||
|
*
|
||||||
|
* \param led LED of which to get the intensity (1 bit per LED; only the least
|
||||||
|
* significant set bit is used).
|
||||||
|
*
|
||||||
|
* \return Intensity of the specified LED (0x00 to 0xFF).
|
||||||
|
*
|
||||||
|
* \warning The PWM channel of the specified LED is supposed to be used only by
|
||||||
|
* this module.
|
||||||
|
*
|
||||||
|
* \note The GPIO pin configuration of all LEDs is left unchanged.
|
||||||
|
*/
|
||||||
|
extern U8 LED_Get_Intensity(U32 led);
|
||||||
|
|
||||||
|
/*! \brief Sets the intensity of the specified LEDs.
|
||||||
|
*
|
||||||
|
* \param leds LEDs of which to set the intensity (1 bit per LED).
|
||||||
|
* \param intensity New intensity of the specified LEDs (0x00 to 0xFF).
|
||||||
|
*
|
||||||
|
* \warning The PWM channels of the specified LEDs are supposed to be used only
|
||||||
|
* by this module.
|
||||||
|
*
|
||||||
|
* \note The pins of the specified LEDs are set to PWM output mode.
|
||||||
|
*/
|
||||||
|
extern void LED_Set_Intensity(U32 leds, U8 intensity);
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _LED_H_
|
@ -0,0 +1,120 @@
|
|||||||
|
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||||
|
|
||||||
|
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||||
|
/*! \file *********************************************************************
|
||||||
|
*
|
||||||
|
* \brief Standard board header file.
|
||||||
|
*
|
||||||
|
* This file includes the appropriate board header file according to the
|
||||||
|
* defined board.
|
||||||
|
*
|
||||||
|
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||||
|
* - Supported devices: All AVR32 devices can be used.
|
||||||
|
* - AppNote:
|
||||||
|
*
|
||||||
|
* \author Atmel Corporation: http://www.atmel.com \n
|
||||||
|
* Support and FAQ: http://support.atmel.no/
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. 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.
|
||||||
|
*
|
||||||
|
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||||
|
* AVR product.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||||
|
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _BOARD_H_
|
||||||
|
#define _BOARD_H_
|
||||||
|
|
||||||
|
#include <avr32/io.h>
|
||||||
|
|
||||||
|
/*! \name Base Boards
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define EVK1100 1 //!< AT32UC3A EVK1100 board.
|
||||||
|
#define EVK1101 2 //!< AT32UC3B EVK1101 board.
|
||||||
|
#define UC3C_EK 3 //!< AT32UC3C UC3C_EK board.
|
||||||
|
#define EVK1104 4 //!< AT32UC3A3 EVK1104 board.
|
||||||
|
#define EVK1105 5 //!< AT32UC3A EVK1105 board.
|
||||||
|
#define STK1000 6 //!< AT32AP7000 STK1000 board.
|
||||||
|
#define NGW100 7 //!< AT32AP7000 NGW100 board.
|
||||||
|
#define STK600_RCUC3L0 8 //!< STK600 RCUC3L0 board.
|
||||||
|
#define UC3L_EK 9 //!< AT32UC3L-EK board.
|
||||||
|
#define USER_BOARD 99 //!< User-reserved board (if any).
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name Extension Boards
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define EXT1102 1 //!< AT32UC3B EXT1102 board.
|
||||||
|
#define MC300 2 //!< AT32UC3 MC300 board.
|
||||||
|
#define USER_EXT_BOARD 99 //!< User-reserved extension board (if any).
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
#if BOARD == EVK1100
|
||||||
|
#include "EVK1100/evk1100.h"
|
||||||
|
#elif BOARD == EVK1101
|
||||||
|
#include "EVK1101/evk1101.h"
|
||||||
|
#elif BOARD == UC3C_EK
|
||||||
|
#include "UC3C_EK/uc3c_ek.h"
|
||||||
|
#elif BOARD == EVK1104
|
||||||
|
#include "EVK1104/evk1104.h"
|
||||||
|
#elif BOARD == EVK1105
|
||||||
|
#include "EVK1105/evk1105.h"
|
||||||
|
#elif BOARD == STK1000
|
||||||
|
#include "STK1000/stk1000.h"
|
||||||
|
#elif BOARD == NGW100
|
||||||
|
#include "NGW100/ngw100.h"
|
||||||
|
#elif BOARD == STK600_RCUC3L0
|
||||||
|
#include "STK600/RCUC3L0/stk600_rcuc3l0.h"
|
||||||
|
#elif BOARD == UC3L_EK
|
||||||
|
#include "UC3L_EK/uc3l_ek.h"
|
||||||
|
#elif BOARD == ARDUINO
|
||||||
|
#include "ARDUINO/arduino.h"
|
||||||
|
#else
|
||||||
|
#error No known AVR32 board defined
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (defined EXT_BOARD)
|
||||||
|
#if EXT_BOARD == EXT1102
|
||||||
|
#include "EXT1102/ext1102.h"
|
||||||
|
#elif EXT_BOARD == MC300
|
||||||
|
#include "MC300/mc300.h"
|
||||||
|
#elif EXT_BOARD == USER_EXT_BOARD
|
||||||
|
// User-reserved area: #include the header file of your extension board here
|
||||||
|
// (if any).
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef FRCOSC
|
||||||
|
#define FRCOSC AVR32_PM_RCOSC_FREQUENCY //!< Default RCOsc frequency.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _BOARD_H_
|
@ -0,0 +1,120 @@
|
|||||||
|
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||||
|
|
||||||
|
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||||
|
/*! \file *********************************************************************
|
||||||
|
*
|
||||||
|
* \brief Standard board header file.
|
||||||
|
*
|
||||||
|
* This file includes the appropriate board header file according to the
|
||||||
|
* defined board.
|
||||||
|
*
|
||||||
|
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||||
|
* - Supported devices: All AVR32 devices can be used.
|
||||||
|
* - AppNote:
|
||||||
|
*
|
||||||
|
* \author Atmel Corporation: http://www.atmel.com \n
|
||||||
|
* Support and FAQ: http://support.atmel.no/
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. 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.
|
||||||
|
*
|
||||||
|
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||||
|
* AVR product.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||||
|
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _BOARD_H_
|
||||||
|
#define _BOARD_H_
|
||||||
|
|
||||||
|
#include <avr32/io.h>
|
||||||
|
|
||||||
|
/*! \name Base Boards
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define EVK1100 1 //!< AT32UC3A EVK1100 board.
|
||||||
|
#define EVK1101 2 //!< AT32UC3B EVK1101 board.
|
||||||
|
#define UC3C_EK 3 //!< AT32UC3C UC3C_EK board.
|
||||||
|
#define EVK1104 4 //!< AT32UC3A3 EVK1104 board.
|
||||||
|
#define EVK1105 5 //!< AT32UC3A EVK1105 board.
|
||||||
|
#define STK1000 6 //!< AT32AP7000 STK1000 board.
|
||||||
|
#define NGW100 7 //!< AT32AP7000 NGW100 board.
|
||||||
|
#define STK600_RCUC3L0 8 //!< STK600 RCUC3L0 board.
|
||||||
|
#define UC3L_EK 9 //!< AT32UC3L-EK board.
|
||||||
|
#define USER_BOARD 99 //!< User-reserved board (if any).
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name Extension Boards
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define EXT1102 1 //!< AT32UC3B EXT1102 board.
|
||||||
|
#define MC300 2 //!< AT32UC3 MC300 board.
|
||||||
|
#define USER_EXT_BOARD 99 //!< User-reserved extension board (if any).
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
#if BOARD == EVK1100
|
||||||
|
#include "EVK1100/evk1100.h"
|
||||||
|
#elif BOARD == EVK1101
|
||||||
|
#include "EVK1101/evk1101.h"
|
||||||
|
#elif BOARD == UC3C_EK
|
||||||
|
#include "UC3C_EK/uc3c_ek.h"
|
||||||
|
#elif BOARD == EVK1104
|
||||||
|
#include "EVK1104/evk1104.h"
|
||||||
|
#elif BOARD == EVK1105
|
||||||
|
#include "EVK1105/evk1105.h"
|
||||||
|
#elif BOARD == STK1000
|
||||||
|
#include "STK1000/stk1000.h"
|
||||||
|
#elif BOARD == NGW100
|
||||||
|
#include "NGW100/ngw100.h"
|
||||||
|
#elif BOARD == STK600_RCUC3L0
|
||||||
|
#include "STK600/RCUC3L0/stk600_rcuc3l0.h"
|
||||||
|
#elif BOARD == UC3L_EK
|
||||||
|
#include "UC3L_EK/uc3l_ek.h"
|
||||||
|
#elif BOARD == ARDUINO
|
||||||
|
#include "ARDUINO/arduino.h"
|
||||||
|
#else
|
||||||
|
#error No known AVR32 board defined
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (defined EXT_BOARD)
|
||||||
|
#if EXT_BOARD == EXT1102
|
||||||
|
#include "EXT1102/ext1102.h"
|
||||||
|
#elif EXT_BOARD == MC300
|
||||||
|
#include "MC300/mc300.h"
|
||||||
|
#elif EXT_BOARD == USER_EXT_BOARD
|
||||||
|
// User-reserved area: #include the header file of your extension board here
|
||||||
|
// (if any).
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef FRCOSC
|
||||||
|
#define FRCOSC AVR32_PM_RCOSC_FREQUENCY //!< Default RCOsc frequency.
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _BOARD_H_
|
@ -0,0 +1,653 @@
|
|||||||
|
/* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||||
|
|
||||||
|
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||||
|
/*! \file *********************************************************************
|
||||||
|
*
|
||||||
|
* \brief Management of the AT45DBX data flash controller through SPI.
|
||||||
|
*
|
||||||
|
* This file manages the accesses to the AT45DBX data flash components.
|
||||||
|
*
|
||||||
|
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||||
|
* - Supported devices: All AVR32 devices with an SPI module can be used.
|
||||||
|
* - AppNote:
|
||||||
|
*
|
||||||
|
* \author Atmel Corporation: http://www.atmel.com \n
|
||||||
|
* Support and FAQ: http://support.atmel.no/
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. 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.
|
||||||
|
*
|
||||||
|
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||||
|
* AVR product.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||||
|
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
//_____ I N C L U D E S ___________________________________________________
|
||||||
|
|
||||||
|
#include "conf_access.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if AT45DBX_MEM == ENABLE
|
||||||
|
|
||||||
|
#include "compiler.h"
|
||||||
|
#include "board.h"
|
||||||
|
#include "gpio.h"
|
||||||
|
#include "spi.h"
|
||||||
|
#include "conf_at45dbx.h"
|
||||||
|
#include "at45dbx.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if AT45DBX_MEM_CNT > 4
|
||||||
|
#error AT45DBX_MEM_CNT must not exceed 4
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
//_____ D E F I N I T I O N S ______________________________________________
|
||||||
|
|
||||||
|
/*! \name AT45DBX Group A Commands
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define AT45DBX_CMDA_RD_PAGE 0xD2 //!< Main Memory Page Read (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDA_RD_ARRAY_LEG 0xE8 //!< Continuous Array Read, Legacy Command (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDA_RD_ARRAY_LF_SM 0x03 //!< Continuous Array Read, Low-Frequency Mode (Serial Mode).
|
||||||
|
#define AT45DBX_CMDA_RD_ARRAY_AF_SM 0x0B //!< Continuous Array Read, Any-Frequency Mode (Serial Mode).
|
||||||
|
#define AT45DBX_CMDA_RD_SECTOR_PROT_REG 0x32 //!< Read Sector Protection Register (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDA_RD_SECTOR_LKDN_REG 0x35 //!< Read Sector Lockdown Register (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDA_RD_SECURITY_REG 0x77 //!< Read Security Register (Serial/8-bit Mode).
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name AT45DBX Group B Commands
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define AT45DBX_CMDB_ER_PAGE 0x81 //!< Page Erase (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDB_ER_BLOCK 0x50 //!< Block Erase (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDB_ER_SECTOR 0x7C //!< Sector Erase (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDB_ER_CHIP 0xC794809A //!< Chip Erase (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDB_XFR_PAGE_TO_BUF1 0x53 //!< Main Memory Page to Buffer 1 Transfer (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDB_XFR_PAGE_TO_BUF2 0x55 //!< Main Memory Page to Buffer 2 Transfer (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDB_CMP_PAGE_TO_BUF1 0x60 //!< Main Memory Page to Buffer 1 Compare (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDB_CMP_PAGE_TO_BUF2 0x61 //!< Main Memory Page to Buffer 2 Compare (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDB_PR_BUF1_TO_PAGE_ER 0x83 //!< Buffer 1 to Main Memory Page Program with Built-in Erase (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDB_PR_BUF2_TO_PAGE_ER 0x86 //!< Buffer 2 to Main Memory Page Program with Built-in Erase (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDB_PR_BUF1_TO_PAGE 0x88 //!< Buffer 1 to Main Memory Page Program without Built-in Erase (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDB_PR_BUF2_TO_PAGE 0x89 //!< Buffer 2 to Main Memory Page Program without Built-in Erase (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDB_PR_PAGE_TH_BUF1 0x82 //!< Main Memory Page Program through Buffer 1 (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDB_PR_PAGE_TH_BUF2 0x85 //!< Main Memory Page Program through Buffer 2 (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDB_RWR_PAGE_TH_BUF1 0x58 //!< Auto Page Rewrite through Buffer 1 (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDB_RWR_PAGE_TH_BUF2 0x59 //!< Auto Page Rewrite through Buffer 2 (Serial/8-bit Mode).
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name AT45DBX Group C Commands
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define AT45DBX_CMDC_RD_BUF1_LF_SM 0xD1 //!< Buffer 1 Read, Low-Frequency Mode (Serial Mode).
|
||||||
|
#define AT45DBX_CMDC_RD_BUF2_LF_SM 0xD3 //!< Buffer 2 Read, Low-Frequency Mode (Serial Mode).
|
||||||
|
#define AT45DBX_CMDC_RD_BUF1_AF_SM 0xD4 //!< Buffer 1 Read, Any-Frequency Mode (Serial Mode).
|
||||||
|
#define AT45DBX_CMDC_RD_BUF2_AF_SM 0xD6 //!< Buffer 2 Read, Any-Frequency Mode (Serial Mode).
|
||||||
|
#define AT45DBX_CMDC_RD_BUF1_AF_8M 0x54 //!< Buffer 1 Read, Any-Frequency Mode (8-bit Mode).
|
||||||
|
#define AT45DBX_CMDC_RD_BUF2_AF_8M 0x56 //!< Buffer 2 Read, Any-Frequency Mode (8-bit Mode).
|
||||||
|
#define AT45DBX_CMDC_WR_BUF1 0x84 //!< Buffer 1 Write (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDC_WR_BUF2 0x87 //!< Buffer 2 Write (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDC_RD_STATUS_REG 0xD7 //!< Status Register Read (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDC_RD_MNFCT_DEV_ID_SM 0x9F //!< Manufacturer and Device ID Read (Serial Mode).
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
/*! \name AT45DBX Group D Commands
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define AT45DBX_CMDD_EN_SECTOR_PROT 0x3D2A7FA9 //!< Enable Sector Protection (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDD_DIS_SECTOR_PROT 0x3D2A7F9A //!< Disable Sector Protection (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDD_ER_SECTOR_PROT_REG 0x3D2A7FCF //!< Erase Sector Protection Register (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDD_PR_SECTOR_PROT_REG 0x3D2A7FFC //!< Program Sector Protection Register (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDD_LKDN_SECTOR 0x3D2A7F30 //!< Sector Lockdown (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDD_PR_SECURITY_REG 0x9B000000 //!< Program Security Register (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDD_PR_CONF_REG 0x3D2A80A6 //!< Program Configuration Register (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDD_DEEP_PWR_DN 0xB9 //!< Deep Power-down (Serial/8-bit Mode).
|
||||||
|
#define AT45DBX_CMDD_RSM_DEEP_PWR_DN 0xAB //!< Resume from Deep Power-down (Serial/8-bit Mode).
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
/*! \name Bit-Masks and Values for the Status Register
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define AT45DBX_MSK_BUSY 0x80 //!< Busy status bit-mask.
|
||||||
|
#define AT45DBX_BUSY 0x00 //!< Busy status value (0x00 when busy, 0x80 when ready).
|
||||||
|
#define AT45DBX_MSK_DENSITY 0x3C //!< Device density bit-mask.
|
||||||
|
//! @}
|
||||||
|
#if AT45DBX_MEM_SIZE == AT45DBX_1MB
|
||||||
|
|
||||||
|
/*! \name AT45DB081 Memories
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define AT45DBX_DENSITY 0x24 //!< Device density value.
|
||||||
|
#define AT45DBX_BYTE_ADDR_BITS 9 //!< Address bits for byte position within buffer.
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
#elif AT45DBX_MEM_SIZE == AT45DBX_2MB
|
||||||
|
|
||||||
|
/*! \name AT45DB161 Memories
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define AT45DBX_DENSITY 0x2C //!< Device density value.
|
||||||
|
#define AT45DBX_BYTE_ADDR_BITS 10 //!< Address bits for byte position within buffer.
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
#elif AT45DBX_MEM_SIZE == AT45DBX_4MB
|
||||||
|
|
||||||
|
/*! \name AT45DB321 Memories
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define AT45DBX_DENSITY 0x34 //!< Device density value.
|
||||||
|
#define AT45DBX_BYTE_ADDR_BITS 10 //!< Address bits for byte position within buffer.
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
#elif AT45DBX_MEM_SIZE == AT45DBX_8MB
|
||||||
|
|
||||||
|
/*! \name AT45DB642 Memories
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define AT45DBX_DENSITY 0x3C //!< Device density value.
|
||||||
|
#define AT45DBX_BYTE_ADDR_BITS 11 //!< Address bits for byte position within buffer.
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error AT45DBX_MEM_SIZE is not defined to a supported value
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//! Address bits for page selection.
|
||||||
|
#define AT45DBX_PAGE_ADDR_BITS (AT45DBX_MEM_SIZE - AT45DBX_PAGE_BITS)
|
||||||
|
|
||||||
|
//! Number of bits for addresses within pages.
|
||||||
|
#define AT45DBX_PAGE_BITS (AT45DBX_BYTE_ADDR_BITS - 1)
|
||||||
|
|
||||||
|
//! Page size in bytes.
|
||||||
|
#define AT45DBX_PAGE_SIZE (1 << AT45DBX_PAGE_BITS)
|
||||||
|
|
||||||
|
//! Bit-mask for byte position within buffer in \ref gl_ptr_mem.
|
||||||
|
#define AT45DBX_MSK_PTR_BYTE ((1 << AT45DBX_PAGE_BITS) - 1)
|
||||||
|
|
||||||
|
//! Bit-mask for page selection in \ref gl_ptr_mem.
|
||||||
|
#define AT45DBX_MSK_PTR_PAGE (((1 << AT45DBX_PAGE_ADDR_BITS) - 1) << AT45DBX_PAGE_BITS)
|
||||||
|
|
||||||
|
//! Bit-mask for byte position within sector in \ref gl_ptr_mem.
|
||||||
|
#define AT45DBX_MSK_PTR_SECTOR ((1 << AT45DBX_SECTOR_BITS) - 1)
|
||||||
|
|
||||||
|
|
||||||
|
/*! \brief Sends a dummy byte through SPI.
|
||||||
|
*/
|
||||||
|
#define spi_write_dummy() spi_write(AT45DBX_SPI, 0xFF)
|
||||||
|
|
||||||
|
|
||||||
|
//! Boolean indicating whether memory is in busy state.
|
||||||
|
static Bool at45dbx_busy;
|
||||||
|
|
||||||
|
//! Memory data pointer.
|
||||||
|
static U32 gl_ptr_mem;
|
||||||
|
|
||||||
|
//! Sector buffer.
|
||||||
|
static U8 sector_buf[AT45DBX_SECTOR_SIZE];
|
||||||
|
|
||||||
|
|
||||||
|
/*! \name Control Functions
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
|
||||||
|
Bool at45dbx_init(spi_options_t spiOptions, unsigned int pba_hz)
|
||||||
|
{
|
||||||
|
// Setup SPI registers according to spiOptions.
|
||||||
|
for (spiOptions.reg = AT45DBX_SPI_FIRST_NPCS;
|
||||||
|
spiOptions.reg < AT45DBX_SPI_FIRST_NPCS + AT45DBX_MEM_CNT;
|
||||||
|
spiOptions.reg++)
|
||||||
|
{
|
||||||
|
if (spi_setupChipReg(AT45DBX_SPI, &spiOptions, pba_hz) != SPI_OK) return KO;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Memory ready.
|
||||||
|
at45dbx_busy = FALSE;
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! \brief Selects or unselects a DF memory.
|
||||||
|
*
|
||||||
|
* \param memidx Memory ID of DF to select or unselect.
|
||||||
|
* \param bSelect Boolean indicating whether the DF memory has to be selected.
|
||||||
|
*/
|
||||||
|
static void at45dbx_chipselect_df(U8 memidx, Bool bSelect)
|
||||||
|
{
|
||||||
|
if (bSelect)
|
||||||
|
{
|
||||||
|
// Select SPI chip.
|
||||||
|
spi_selectChip(AT45DBX_SPI, AT45DBX_SPI_FIRST_NPCS + memidx);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Unselect SPI chip.
|
||||||
|
spi_unselectChip(AT45DBX_SPI, AT45DBX_SPI_FIRST_NPCS + memidx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Bool at45dbx_mem_check(void)
|
||||||
|
{
|
||||||
|
U8 df;
|
||||||
|
U16 status = 0;
|
||||||
|
|
||||||
|
// DF memory check.
|
||||||
|
for (df = 0; df < AT45DBX_MEM_CNT; df++)
|
||||||
|
{
|
||||||
|
// Select the DF memory to check.
|
||||||
|
at45dbx_chipselect_df(df, TRUE);
|
||||||
|
|
||||||
|
// Send the Status Register Read command.
|
||||||
|
spi_write(AT45DBX_SPI, AT45DBX_CMDC_RD_STATUS_REG);
|
||||||
|
|
||||||
|
// Send a dummy byte to read the status register.
|
||||||
|
spi_write_dummy();
|
||||||
|
spi_read(AT45DBX_SPI, &status);
|
||||||
|
|
||||||
|
// Unselect the checked DF memory.
|
||||||
|
at45dbx_chipselect_df(df, FALSE);
|
||||||
|
|
||||||
|
// Unexpected device density value.
|
||||||
|
if ((status & AT45DBX_MSK_DENSITY) < AT45DBX_DENSITY) return KO;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! \brief Waits until the DF is ready.
|
||||||
|
*/
|
||||||
|
static void at45dbx_wait_ready(void)
|
||||||
|
{
|
||||||
|
U16 status;
|
||||||
|
|
||||||
|
// Select the DF memory gl_ptr_mem points to.
|
||||||
|
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, TRUE);
|
||||||
|
|
||||||
|
// Send the Status Register Read command.
|
||||||
|
spi_write(AT45DBX_SPI, AT45DBX_CMDC_RD_STATUS_REG);
|
||||||
|
|
||||||
|
// Read the status register until the DF is ready.
|
||||||
|
do
|
||||||
|
{
|
||||||
|
// Send a dummy byte to read the status register.
|
||||||
|
spi_write_dummy();
|
||||||
|
spi_read(AT45DBX_SPI, &status);
|
||||||
|
} while ((status & AT45DBX_MSK_BUSY) == AT45DBX_BUSY);
|
||||||
|
|
||||||
|
// Unselect the DF memory gl_ptr_mem points to.
|
||||||
|
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Bool at45dbx_read_open(U32 sector)
|
||||||
|
{
|
||||||
|
U32 addr;
|
||||||
|
|
||||||
|
// Set the global memory pointer to a byte address.
|
||||||
|
gl_ptr_mem = sector << AT45DBX_SECTOR_BITS; // gl_ptr_mem = sector * AT45DBX_SECTOR_SIZE.
|
||||||
|
|
||||||
|
// If the DF memory is busy, wait until it's ready.
|
||||||
|
if (at45dbx_busy) at45dbx_wait_ready();
|
||||||
|
at45dbx_busy = FALSE;
|
||||||
|
|
||||||
|
// Select the DF memory gl_ptr_mem points to.
|
||||||
|
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, TRUE);
|
||||||
|
|
||||||
|
// Initiate a page read at a given sector.
|
||||||
|
|
||||||
|
// Send the Main Memory Page Read command.
|
||||||
|
spi_write(AT45DBX_SPI, AT45DBX_CMDA_RD_PAGE);
|
||||||
|
|
||||||
|
// Send the three address bytes, which comprise:
|
||||||
|
// - (24 - (AT45DBX_PAGE_ADDR_BITS + AT45DBX_BYTE_ADDR_BITS)) reserved bits;
|
||||||
|
// - then AT45DBX_PAGE_ADDR_BITS bits specifying the page in main memory to be read;
|
||||||
|
// - then AT45DBX_BYTE_ADDR_BITS bits specifying the starting byte address within that page.
|
||||||
|
// NOTE: The bits of gl_ptr_mem above the AT45DBX_MEM_SIZE bits are useless for the local
|
||||||
|
// DF addressing. They are used for DF discrimination when there are several DFs.
|
||||||
|
addr = (Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_PAGE) << AT45DBX_BYTE_ADDR_BITS) |
|
||||||
|
Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_BYTE);
|
||||||
|
spi_write(AT45DBX_SPI, LSB2W(addr));
|
||||||
|
spi_write(AT45DBX_SPI, LSB1W(addr));
|
||||||
|
spi_write(AT45DBX_SPI, LSB0W(addr));
|
||||||
|
|
||||||
|
// Send 32 don't care clock cycles to initialize the read operation.
|
||||||
|
spi_write_dummy();
|
||||||
|
spi_write_dummy();
|
||||||
|
spi_write_dummy();
|
||||||
|
spi_write_dummy();
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void at45dbx_read_close(void)
|
||||||
|
{
|
||||||
|
// Unselect the DF memory gl_ptr_mem points to.
|
||||||
|
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
|
||||||
|
|
||||||
|
// Memory ready.
|
||||||
|
at45dbx_busy = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Bool at45dbx_write_open(U32 sector)
|
||||||
|
{
|
||||||
|
U32 addr;
|
||||||
|
|
||||||
|
// Set the global memory pointer to a byte address.
|
||||||
|
gl_ptr_mem = sector << AT45DBX_SECTOR_BITS; // gl_ptr_mem = sector * AT45DBX_SECTOR_SIZE.
|
||||||
|
|
||||||
|
// If the DF memory is busy, wait until it's ready.
|
||||||
|
if (at45dbx_busy) at45dbx_wait_ready();
|
||||||
|
at45dbx_busy = FALSE;
|
||||||
|
|
||||||
|
#if AT45DBX_PAGE_SIZE > AT45DBX_SECTOR_SIZE
|
||||||
|
// Select the DF memory gl_ptr_mem points to.
|
||||||
|
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, TRUE);
|
||||||
|
|
||||||
|
// Transfer the content of the current page to buffer 1.
|
||||||
|
|
||||||
|
// Send the Main Memory Page to Buffer 1 Transfer command.
|
||||||
|
spi_write(AT45DBX_SPI, AT45DBX_CMDB_XFR_PAGE_TO_BUF1);
|
||||||
|
|
||||||
|
// Send the three address bytes, which comprise:
|
||||||
|
// - (24 - (AT45DBX_PAGE_ADDR_BITS + AT45DBX_BYTE_ADDR_BITS)) reserved bits;
|
||||||
|
// - then AT45DBX_PAGE_ADDR_BITS bits specifying the page in main memory to be read;
|
||||||
|
// - then AT45DBX_BYTE_ADDR_BITS don't care bits.
|
||||||
|
// NOTE: The bits of gl_ptr_mem above the AT45DBX_MEM_SIZE bits are useless for the local
|
||||||
|
// DF addressing. They are used for DF discrimination when there are several DFs.
|
||||||
|
addr = Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_PAGE) << AT45DBX_BYTE_ADDR_BITS;
|
||||||
|
spi_write(AT45DBX_SPI, LSB2W(addr));
|
||||||
|
spi_write(AT45DBX_SPI, LSB1W(addr));
|
||||||
|
spi_write(AT45DBX_SPI, LSB0W(addr));
|
||||||
|
|
||||||
|
// Unselect the DF memory gl_ptr_mem points to.
|
||||||
|
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
|
||||||
|
|
||||||
|
// Wait for end of page transfer.
|
||||||
|
at45dbx_wait_ready();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Select the DF memory gl_ptr_mem points to.
|
||||||
|
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, TRUE);
|
||||||
|
|
||||||
|
// Initiate a page write at a given sector.
|
||||||
|
|
||||||
|
// Send the Main Memory Page Program through Buffer 1 command.
|
||||||
|
spi_write(AT45DBX_SPI, AT45DBX_CMDB_PR_PAGE_TH_BUF1);
|
||||||
|
|
||||||
|
// Send the three address bytes, which comprise:
|
||||||
|
// - (24 - (AT45DBX_PAGE_ADDR_BITS + AT45DBX_BYTE_ADDR_BITS)) reserved bits;
|
||||||
|
// - then AT45DBX_PAGE_ADDR_BITS bits specifying the page in main memory to be written;
|
||||||
|
// - then AT45DBX_BYTE_ADDR_BITS bits specifying the starting byte address within that page.
|
||||||
|
// NOTE: The bits of gl_ptr_mem above the AT45DBX_MEM_SIZE bits are useless for the local
|
||||||
|
// DF addressing. They are used for DF discrimination when there are several DFs.
|
||||||
|
addr = (Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_PAGE) << AT45DBX_BYTE_ADDR_BITS) |
|
||||||
|
Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_BYTE);
|
||||||
|
spi_write(AT45DBX_SPI, LSB2W(addr));
|
||||||
|
spi_write(AT45DBX_SPI, LSB1W(addr));
|
||||||
|
spi_write(AT45DBX_SPI, LSB0W(addr));
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void at45dbx_write_close(void)
|
||||||
|
{
|
||||||
|
// While end of logical sector not reached, zero-fill remaining memory bytes.
|
||||||
|
while (Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_SECTOR))
|
||||||
|
{
|
||||||
|
spi_write(AT45DBX_SPI, 0x00);
|
||||||
|
gl_ptr_mem++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unselect the DF memory gl_ptr_mem points to.
|
||||||
|
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
|
||||||
|
|
||||||
|
// Memory busy.
|
||||||
|
at45dbx_busy = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
/*! \name Single-Byte Access Functions
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
|
||||||
|
U8 at45dbx_read_byte(void)
|
||||||
|
{
|
||||||
|
U16 data;
|
||||||
|
|
||||||
|
// Memory busy.
|
||||||
|
if (at45dbx_busy)
|
||||||
|
{
|
||||||
|
// Being here, we know that we previously finished a page read.
|
||||||
|
// => We have to access the next page.
|
||||||
|
|
||||||
|
// Memory ready.
|
||||||
|
at45dbx_busy = FALSE;
|
||||||
|
|
||||||
|
// Eventually select the next DF and open the next page.
|
||||||
|
// NOTE: at45dbx_read_open input parameter is a sector.
|
||||||
|
at45dbx_read_open(gl_ptr_mem >> AT45DBX_SECTOR_BITS); // gl_ptr_mem / AT45DBX_SECTOR_SIZE.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send a dummy byte to read the next data byte.
|
||||||
|
spi_write_dummy();
|
||||||
|
spi_read(AT45DBX_SPI, &data);
|
||||||
|
gl_ptr_mem++;
|
||||||
|
|
||||||
|
// If end of page reached,
|
||||||
|
if (!Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_BYTE))
|
||||||
|
{
|
||||||
|
// unselect the DF memory gl_ptr_mem points to.
|
||||||
|
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
|
||||||
|
|
||||||
|
// Memory busy.
|
||||||
|
at45dbx_busy = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Bool at45dbx_write_byte(U8 b)
|
||||||
|
{
|
||||||
|
// Memory busy.
|
||||||
|
if (at45dbx_busy)
|
||||||
|
{
|
||||||
|
// Being here, we know that we previously launched a page programming.
|
||||||
|
// => We have to access the next page.
|
||||||
|
|
||||||
|
// Eventually select the next DF and open the next page.
|
||||||
|
// NOTE: at45dbx_write_open input parameter is a sector.
|
||||||
|
at45dbx_write_open(gl_ptr_mem >> AT45DBX_SECTOR_BITS); // gl_ptr_mem / AT45DBX_SECTOR_SIZE.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write the next data byte.
|
||||||
|
spi_write(AT45DBX_SPI, b);
|
||||||
|
gl_ptr_mem++;
|
||||||
|
|
||||||
|
// If end of page reached,
|
||||||
|
if (!Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_BYTE))
|
||||||
|
{
|
||||||
|
// unselect the DF memory gl_ptr_mem points to in order to program the page.
|
||||||
|
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
|
||||||
|
|
||||||
|
// Memory busy.
|
||||||
|
at45dbx_busy = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
/*! \name Multiple-Sector Access Functions
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
|
||||||
|
Bool at45dbx_read_multiple_sector(U16 nb_sector)
|
||||||
|
{
|
||||||
|
while (nb_sector--)
|
||||||
|
{
|
||||||
|
// Read the next sector.
|
||||||
|
at45dbx_read_sector_2_ram(sector_buf);
|
||||||
|
at45dbx_read_multiple_sector_callback(sector_buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Bool at45dbx_write_multiple_sector(U16 nb_sector)
|
||||||
|
{
|
||||||
|
while (nb_sector--)
|
||||||
|
{
|
||||||
|
// Write the next sector.
|
||||||
|
at45dbx_write_multiple_sector_callback(sector_buf);
|
||||||
|
at45dbx_write_sector_from_ram(sector_buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
/*! \name Single-Sector Access Functions
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
|
||||||
|
Bool at45dbx_read_sector_2_ram(void *ram)
|
||||||
|
{
|
||||||
|
U8 *_ram = ram;
|
||||||
|
U16 i;
|
||||||
|
U16 data;
|
||||||
|
|
||||||
|
// Memory busy.
|
||||||
|
if (at45dbx_busy)
|
||||||
|
{
|
||||||
|
// Being here, we know that we previously finished a page read.
|
||||||
|
// => We have to access the next page.
|
||||||
|
|
||||||
|
// Memory ready.
|
||||||
|
at45dbx_busy = FALSE;
|
||||||
|
|
||||||
|
// Eventually select the next DF and open the next page.
|
||||||
|
// NOTE: at45dbx_read_open input parameter is a sector.
|
||||||
|
at45dbx_read_open(gl_ptr_mem >> AT45DBX_SECTOR_BITS); // gl_ptr_mem / AT45DBX_SECTOR_SIZE.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read the next sector.
|
||||||
|
for (i = AT45DBX_SECTOR_SIZE; i; i--)
|
||||||
|
{
|
||||||
|
// Send a dummy byte to read the next data byte.
|
||||||
|
spi_write_dummy();
|
||||||
|
spi_read(AT45DBX_SPI, &data);
|
||||||
|
*_ram++ = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the memory pointer.
|
||||||
|
gl_ptr_mem += AT45DBX_SECTOR_SIZE;
|
||||||
|
|
||||||
|
#if AT45DBX_PAGE_SIZE > AT45DBX_SECTOR_SIZE
|
||||||
|
// If end of page reached,
|
||||||
|
if (!Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_BYTE))
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
// unselect the DF memory gl_ptr_mem points to.
|
||||||
|
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
|
||||||
|
|
||||||
|
// Memory busy.
|
||||||
|
at45dbx_busy = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Bool at45dbx_write_sector_from_ram(const void *ram)
|
||||||
|
{
|
||||||
|
const U8 *_ram = ram;
|
||||||
|
U16 i;
|
||||||
|
|
||||||
|
// Memory busy.
|
||||||
|
if (at45dbx_busy)
|
||||||
|
{
|
||||||
|
// Being here, we know that we previously launched a page programming.
|
||||||
|
// => We have to access the next page.
|
||||||
|
|
||||||
|
// Eventually select the next DF and open the next page.
|
||||||
|
// NOTE: at45dbx_write_open input parameter is a sector.
|
||||||
|
at45dbx_write_open(gl_ptr_mem >> AT45DBX_SECTOR_BITS); // gl_ptr_mem / AT45DBX_SECTOR_SIZE.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write the next sector.
|
||||||
|
for (i = AT45DBX_SECTOR_SIZE; i; i--)
|
||||||
|
{
|
||||||
|
// Write the next data byte.
|
||||||
|
spi_write(AT45DBX_SPI, *_ram++);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the memory pointer.
|
||||||
|
gl_ptr_mem += AT45DBX_SECTOR_SIZE;
|
||||||
|
|
||||||
|
#if AT45DBX_PAGE_SIZE > AT45DBX_SECTOR_SIZE
|
||||||
|
// If end of page reached,
|
||||||
|
if (!Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_BYTE))
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
// unselect the DF memory gl_ptr_mem points to in order to program the page.
|
||||||
|
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
|
||||||
|
|
||||||
|
// Memory busy.
|
||||||
|
at45dbx_busy = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // AT45DBX_MEM == ENABLE
|
@ -0,0 +1,270 @@
|
|||||||
|
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||||
|
|
||||||
|
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||||
|
/*! \file *********************************************************************
|
||||||
|
*
|
||||||
|
* \brief Management of the AT45DBX data flash controller through SPI.
|
||||||
|
*
|
||||||
|
* This file manages the accesses to the AT45DBX data flash components.
|
||||||
|
*
|
||||||
|
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||||
|
* - Supported devices: All AVR32 devices with an SPI module can be used.
|
||||||
|
* - AppNote:
|
||||||
|
*
|
||||||
|
* \author Atmel Corporation: http://www.atmel.com \n
|
||||||
|
* Support and FAQ: http://support.atmel.no/
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. 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.
|
||||||
|
*
|
||||||
|
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||||
|
* AVR product.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||||
|
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _AT45DBX_H_
|
||||||
|
#define _AT45DBX_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include "conf_access.h"
|
||||||
|
|
||||||
|
#if AT45DBX_MEM == DISABLE
|
||||||
|
#error at45dbx.h is #included although AT45DBX_MEM is disabled
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include "spi.h"
|
||||||
|
|
||||||
|
|
||||||
|
//_____ D E F I N I T I O N S ______________________________________________
|
||||||
|
|
||||||
|
/*! \name Available AT45DBX Sizes
|
||||||
|
*
|
||||||
|
* Number of address bits of available AT45DBX data flash memories.
|
||||||
|
*
|
||||||
|
* \note Only memories with page sizes of at least 512 bytes (sector size) are
|
||||||
|
* supported.
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
#define AT45DBX_1MB 20
|
||||||
|
#define AT45DBX_2MB 21
|
||||||
|
#define AT45DBX_4MB 22
|
||||||
|
#define AT45DBX_8MB 23
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
// AT45DBX_1MB
|
||||||
|
#define AT45DBX_SECTOR_BITS 8 //! Number of bits for addresses within sectors.
|
||||||
|
// AT45DBX_2MB AT45DBX_4MB AT45DBX_8MB
|
||||||
|
//#define AT45DBX_SECTOR_BITS 9 //! Number of bits for addresses within sectors.
|
||||||
|
|
||||||
|
//! Sector size in bytes.
|
||||||
|
#define AT45DBX_SECTOR_SIZE (1 << AT45DBX_SECTOR_BITS)
|
||||||
|
|
||||||
|
|
||||||
|
//_____ D E C L A R A T I O N S ____________________________________________
|
||||||
|
|
||||||
|
/*! \name Control Functions
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
/*! \brief Initializes the data flash controller and the SPI channel by which
|
||||||
|
* the DF is controlled.
|
||||||
|
*
|
||||||
|
* \param spiOptions Initialization options of the DF SPI channel.
|
||||||
|
* \param pba_hz SPI module input clock frequency (PBA clock, Hz).
|
||||||
|
*
|
||||||
|
* \retval OK Success.
|
||||||
|
* \retval KO Failure.
|
||||||
|
*/
|
||||||
|
extern Bool at45dbx_init(spi_options_t spiOptions, unsigned int pba_hz);
|
||||||
|
|
||||||
|
/*! \brief Performs a memory check on all DFs.
|
||||||
|
*
|
||||||
|
* \retval OK Success.
|
||||||
|
* \retval KO Failure.
|
||||||
|
*/
|
||||||
|
extern Bool at45dbx_mem_check(void);
|
||||||
|
|
||||||
|
/*! \brief Opens a DF memory in read mode at a given sector.
|
||||||
|
*
|
||||||
|
* \param sector Start sector.
|
||||||
|
*
|
||||||
|
* \retval OK Success.
|
||||||
|
* \retval KO Failure.
|
||||||
|
*
|
||||||
|
* \note Sector may be page-unaligned (depending on the DF page size).
|
||||||
|
*/
|
||||||
|
extern Bool at45dbx_read_open(U32 sector);
|
||||||
|
|
||||||
|
/*! \brief Unselects the current DF memory.
|
||||||
|
*/
|
||||||
|
extern void at45dbx_read_close(void);
|
||||||
|
|
||||||
|
/*! \brief This function opens a DF memory in write mode at a given sector.
|
||||||
|
*
|
||||||
|
* \param sector Start sector.
|
||||||
|
*
|
||||||
|
* \retval OK Success.
|
||||||
|
* \retval KO Failure.
|
||||||
|
*
|
||||||
|
* \note Sector may be page-unaligned (depending on the DF page size).
|
||||||
|
*
|
||||||
|
* \note If \ref AT45DBX_PAGE_SIZE > \ref AT45DBX_SECTOR_SIZE, page content is
|
||||||
|
* first loaded in buffer to then be partially updated by write byte or
|
||||||
|
* write sector functions.
|
||||||
|
*/
|
||||||
|
extern Bool at45dbx_write_open(U32 sector);
|
||||||
|
|
||||||
|
/*! \brief Fills the end of the current logical sector and launches page programming.
|
||||||
|
*/
|
||||||
|
extern void at45dbx_write_close(void);
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
/*! \name Single-Byte Access Functions
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
/*! \brief Performs a single byte read from DF memory.
|
||||||
|
*
|
||||||
|
* \return The read byte.
|
||||||
|
*
|
||||||
|
* \note First call must be preceded by a call to the \ref at45dbx_read_open
|
||||||
|
* function.
|
||||||
|
*/
|
||||||
|
extern U8 at45dbx_read_byte(void);
|
||||||
|
|
||||||
|
/*! \brief Performs a single byte write to DF memory.
|
||||||
|
*
|
||||||
|
* \param b The byte to write.
|
||||||
|
*
|
||||||
|
* \retval OK Success.
|
||||||
|
* \retval KO Failure.
|
||||||
|
*
|
||||||
|
* \note First call must be preceded by a call to the \ref at45dbx_write_open
|
||||||
|
* function.
|
||||||
|
*/
|
||||||
|
extern Bool at45dbx_write_byte(U8 b);
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
/*! \name Multiple-Sector Access Functions
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
/*! \brief Reads \a nb_sector sectors from DF memory.
|
||||||
|
*
|
||||||
|
* Data flow is: DF -> callback.
|
||||||
|
*
|
||||||
|
* \param nb_sector Number of contiguous sectors to read.
|
||||||
|
*
|
||||||
|
* \retval OK Success.
|
||||||
|
* \retval KO Failure.
|
||||||
|
*
|
||||||
|
* \note First call must be preceded by a call to the \ref at45dbx_read_open
|
||||||
|
* function.
|
||||||
|
*
|
||||||
|
* \note As \ref AT45DBX_PAGE_SIZE is always a multiple of
|
||||||
|
* \ref AT45DBX_SECTOR_SIZE, there is no need to check page end for each
|
||||||
|
* byte.
|
||||||
|
*/
|
||||||
|
extern Bool at45dbx_read_multiple_sector(U16 nb_sector);
|
||||||
|
|
||||||
|
/*! \brief Callback function invoked after each sector read during
|
||||||
|
* \ref at45dbx_read_multiple_sector.
|
||||||
|
*
|
||||||
|
* \param psector Pointer to read sector.
|
||||||
|
*/
|
||||||
|
extern void at45dbx_read_multiple_sector_callback(const void *psector);
|
||||||
|
|
||||||
|
/*! \brief Writes \a nb_sector sectors to DF memory.
|
||||||
|
*
|
||||||
|
* Data flow is: callback -> DF.
|
||||||
|
*
|
||||||
|
* \param nb_sector Number of contiguous sectors to write.
|
||||||
|
*
|
||||||
|
* \retval OK Success.
|
||||||
|
* \retval KO Failure.
|
||||||
|
*
|
||||||
|
* \note First call must be preceded by a call to the \ref at45dbx_write_open
|
||||||
|
* function.
|
||||||
|
*
|
||||||
|
* \note As \ref AT45DBX_PAGE_SIZE is always a multiple of
|
||||||
|
* \ref AT45DBX_SECTOR_SIZE, there is no need to check page end for each
|
||||||
|
* byte.
|
||||||
|
*/
|
||||||
|
extern Bool at45dbx_write_multiple_sector(U16 nb_sector);
|
||||||
|
|
||||||
|
/*! \brief Callback function invoked before each sector write during
|
||||||
|
* \ref at45dbx_write_multiple_sector.
|
||||||
|
*
|
||||||
|
* \param psector Pointer to sector to write.
|
||||||
|
*/
|
||||||
|
extern void at45dbx_write_multiple_sector_callback(void *psector);
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
/*! \name Single-Sector Access Functions
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
/*! \brief Reads 1 DF sector to a RAM buffer.
|
||||||
|
*
|
||||||
|
* Data flow is: DF -> RAM.
|
||||||
|
*
|
||||||
|
* \param ram Pointer to RAM buffer.
|
||||||
|
*
|
||||||
|
* \retval OK Success.
|
||||||
|
* \retval KO Failure.
|
||||||
|
*
|
||||||
|
* \note First call must be preceded by a call to the \ref at45dbx_read_open
|
||||||
|
* function.
|
||||||
|
*/
|
||||||
|
extern Bool at45dbx_read_sector_2_ram(void *ram);
|
||||||
|
|
||||||
|
/*! \brief Writes 1 DF sector from a RAM buffer.
|
||||||
|
*
|
||||||
|
* Data flow is: RAM -> DF.
|
||||||
|
*
|
||||||
|
* \param ram Pointer to RAM buffer.
|
||||||
|
*
|
||||||
|
* \retval OK Success.
|
||||||
|
* \retval KO Failure.
|
||||||
|
*
|
||||||
|
* \note First call must be preceded by a call to the \ref at45dbx_write_open
|
||||||
|
* function.
|
||||||
|
*/
|
||||||
|
extern Bool at45dbx_write_sector_from_ram(const void *ram);
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _AT45DBX_H_
|
@ -0,0 +1,234 @@
|
|||||||
|
/* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||||
|
|
||||||
|
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||||
|
/*! \file *********************************************************************
|
||||||
|
*
|
||||||
|
* \brief CTRL_ACCESS interface for the AT45DBX data flash controller.
|
||||||
|
*
|
||||||
|
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||||
|
* - Supported devices: All AVR32 devices with an SPI module can be used.
|
||||||
|
* - AppNote:
|
||||||
|
*
|
||||||
|
* \author Atmel Corporation: http://www.atmel.com \n
|
||||||
|
* Support and FAQ: http://support.atmel.no/
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. 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.
|
||||||
|
*
|
||||||
|
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||||
|
* AVR product.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||||
|
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
//_____ I N C L U D E S ___________________________________________________
|
||||||
|
|
||||||
|
#include "conf_access.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if AT45DBX_MEM == ENABLE
|
||||||
|
|
||||||
|
#include "conf_at45dbx.h"
|
||||||
|
#include "at45dbx.h"
|
||||||
|
#include "at45dbx_mem.h"
|
||||||
|
|
||||||
|
|
||||||
|
//_____ D E F I N I T I O N S ______________________________________________
|
||||||
|
|
||||||
|
//! Whether to detect write accesses to the memory.
|
||||||
|
#define AT45DBX_MEM_TEST_CHANGE_STATE ENABLED
|
||||||
|
|
||||||
|
|
||||||
|
#if (ACCESS_USB == ENABLED || ACCESS_MEM_TO_RAM == ENABLED) && AT45DBX_MEM_TEST_CHANGE_STATE == ENABLED
|
||||||
|
|
||||||
|
//! Memory data modified flag.
|
||||||
|
static volatile Bool s_b_data_modify = FALSE;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*! \name Control Interface
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
|
||||||
|
Ctrl_status at45dbx_test_unit_ready(void)
|
||||||
|
{
|
||||||
|
return (at45dbx_mem_check() == OK) ? CTRL_GOOD : CTRL_NO_PRESENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Ctrl_status at45dbx_read_capacity(U32 *u32_nb_sector)
|
||||||
|
{
|
||||||
|
*u32_nb_sector = (AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)) - 1;
|
||||||
|
|
||||||
|
return CTRL_GOOD;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Bool at45dbx_wr_protect(void)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Bool at45dbx_removal(void)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
#if ACCESS_USB == ENABLED
|
||||||
|
|
||||||
|
#include "usb_drv.h"
|
||||||
|
#include "scsi_decoder.h"
|
||||||
|
|
||||||
|
|
||||||
|
/*! \name MEM <-> USB Interface
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
|
||||||
|
Ctrl_status at45dbx_usb_read_10(U32 addr, U16 nb_sector)
|
||||||
|
{
|
||||||
|
if (addr + nb_sector > AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)) return CTRL_FAIL;
|
||||||
|
|
||||||
|
at45dbx_read_open(addr);
|
||||||
|
at45dbx_read_multiple_sector(nb_sector);
|
||||||
|
at45dbx_read_close();
|
||||||
|
|
||||||
|
return CTRL_GOOD;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void at45dbx_read_multiple_sector_callback(const void *psector)
|
||||||
|
{
|
||||||
|
U16 data_to_transfer = AT45DBX_SECTOR_SIZE;
|
||||||
|
|
||||||
|
// Transfer read sector to the USB interface.
|
||||||
|
while (data_to_transfer)
|
||||||
|
{
|
||||||
|
while (!Is_usb_in_ready(g_scsi_ep_ms_in))
|
||||||
|
{
|
||||||
|
if(!Is_usb_endpoint_enabled(g_scsi_ep_ms_in))
|
||||||
|
return; // USB Reset
|
||||||
|
}
|
||||||
|
|
||||||
|
Usb_reset_endpoint_fifo_access(g_scsi_ep_ms_in);
|
||||||
|
data_to_transfer = usb_write_ep_txpacket(g_scsi_ep_ms_in, psector,
|
||||||
|
data_to_transfer, &psector);
|
||||||
|
Usb_ack_in_ready_send(g_scsi_ep_ms_in);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Ctrl_status at45dbx_usb_write_10(U32 addr, U16 nb_sector)
|
||||||
|
{
|
||||||
|
if (addr + nb_sector > AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)) return CTRL_FAIL;
|
||||||
|
|
||||||
|
#if AT45DBX_MEM_TEST_CHANGE_STATE == ENABLED
|
||||||
|
if (nb_sector) s_b_data_modify = TRUE;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
at45dbx_write_open(addr);
|
||||||
|
at45dbx_write_multiple_sector(nb_sector);
|
||||||
|
at45dbx_write_close();
|
||||||
|
|
||||||
|
return CTRL_GOOD;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void at45dbx_write_multiple_sector_callback(void *psector)
|
||||||
|
{
|
||||||
|
U16 data_to_transfer = AT45DBX_SECTOR_SIZE;
|
||||||
|
|
||||||
|
// Transfer sector to write from the USB interface.
|
||||||
|
while (data_to_transfer)
|
||||||
|
{
|
||||||
|
while (!Is_usb_out_received(g_scsi_ep_ms_out))
|
||||||
|
{
|
||||||
|
if(!Is_usb_endpoint_enabled(g_scsi_ep_ms_out))
|
||||||
|
return; // USB Reset
|
||||||
|
}
|
||||||
|
|
||||||
|
Usb_reset_endpoint_fifo_access(g_scsi_ep_ms_out);
|
||||||
|
data_to_transfer = usb_read_ep_rxpacket(g_scsi_ep_ms_out, psector,
|
||||||
|
data_to_transfer, &psector);
|
||||||
|
Usb_ack_out_received_free(g_scsi_ep_ms_out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
#endif // ACCESS_USB == ENABLED
|
||||||
|
|
||||||
|
|
||||||
|
#if ACCESS_MEM_TO_RAM == ENABLED
|
||||||
|
|
||||||
|
/*! \name MEM <-> RAM Interface
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
|
||||||
|
Ctrl_status at45dbx_df_2_ram(U32 addr, void *ram)
|
||||||
|
{
|
||||||
|
if (addr + 1 > AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)) return CTRL_FAIL;
|
||||||
|
|
||||||
|
at45dbx_read_open(addr);
|
||||||
|
at45dbx_read_sector_2_ram(ram);
|
||||||
|
at45dbx_read_close();
|
||||||
|
|
||||||
|
return CTRL_GOOD;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Ctrl_status at45dbx_ram_2_df(U32 addr, const void *ram)
|
||||||
|
{
|
||||||
|
if (addr + 1 > AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)) return CTRL_FAIL;
|
||||||
|
|
||||||
|
#if AT45DBX_MEM_TEST_CHANGE_STATE == ENABLED
|
||||||
|
s_b_data_modify = TRUE;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
at45dbx_write_open(addr);
|
||||||
|
at45dbx_write_sector_from_ram(ram);
|
||||||
|
at45dbx_write_close();
|
||||||
|
|
||||||
|
return CTRL_GOOD;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
#endif // ACCESS_MEM_TO_RAM == ENABLED
|
||||||
|
|
||||||
|
|
||||||
|
#endif // AT45DBX_MEM == ENABLE
|
@ -0,0 +1,164 @@
|
|||||||
|
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||||
|
|
||||||
|
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||||
|
/*! \file *********************************************************************
|
||||||
|
*
|
||||||
|
* \brief CTRL_ACCESS interface for the AT45DBX data flash controller.
|
||||||
|
*
|
||||||
|
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||||
|
* - Supported devices: All AVR32 devices with an SPI module can be used.
|
||||||
|
* - AppNote:
|
||||||
|
*
|
||||||
|
* \author Atmel Corporation: http://www.atmel.com \n
|
||||||
|
* Support and FAQ: http://support.atmel.no/
|
||||||
|
*
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. 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.
|
||||||
|
*
|
||||||
|
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||||
|
* AVR product.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||||
|
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _AT45DBX_MEM_H_
|
||||||
|
#define _AT45DBX_MEM_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include "conf_access.h"
|
||||||
|
|
||||||
|
#if AT45DBX_MEM == DISABLE
|
||||||
|
#error at45dbx_mem.h is #included although AT45DBX_MEM is disabled
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include "ctrl_access.h"
|
||||||
|
|
||||||
|
|
||||||
|
//_____ D E C L A R A T I O N S ____________________________________________
|
||||||
|
|
||||||
|
/*! \name Control Interface
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
/*! \brief Tests the memory state and initializes the memory if required.
|
||||||
|
*
|
||||||
|
* The TEST UNIT READY SCSI primary command allows an application client to poll
|
||||||
|
* a LUN until it is ready without having to allocate memory for returned data.
|
||||||
|
*
|
||||||
|
* This command may be used to check the media status of LUNs with removable
|
||||||
|
* media.
|
||||||
|
*
|
||||||
|
* \return Status.
|
||||||
|
*/
|
||||||
|
extern Ctrl_status at45dbx_test_unit_ready(void);
|
||||||
|
|
||||||
|
/*! \brief Returns the address of the last valid sector in the memory.
|
||||||
|
*
|
||||||
|
* \param u32_nb_sector Pointer to the address of the last valid sector.
|
||||||
|
*
|
||||||
|
* \return Status.
|
||||||
|
*/
|
||||||
|
extern Ctrl_status at45dbx_read_capacity(U32 *u32_nb_sector);
|
||||||
|
|
||||||
|
/*! \brief Returns the write-protection state of the memory.
|
||||||
|
*
|
||||||
|
* \return \c TRUE if the memory is write-protected, else \c FALSE.
|
||||||
|
*
|
||||||
|
* \note Only used by removable memories with hardware-specific write
|
||||||
|
* protection.
|
||||||
|
*/
|
||||||
|
extern Bool at45dbx_wr_protect(void);
|
||||||
|
|
||||||
|
/*! \brief Tells whether the memory is removable.
|
||||||
|
*
|
||||||
|
* \return \c TRUE if the memory is removable, else \c FALSE.
|
||||||
|
*/
|
||||||
|
extern Bool at45dbx_removal(void);
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
|
||||||
|
#if ACCESS_USB == ENABLED
|
||||||
|
|
||||||
|
/*! \name MEM <-> USB Interface
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
/*! \brief Tranfers data from the memory to USB.
|
||||||
|
*
|
||||||
|
* \param addr Address of first memory sector to read.
|
||||||
|
* \param nb_sector Number of sectors to transfer.
|
||||||
|
*
|
||||||
|
* \return Status.
|
||||||
|
*/
|
||||||
|
extern Ctrl_status at45dbx_usb_read_10(U32 addr, U16 nb_sector);
|
||||||
|
|
||||||
|
/*! \brief Tranfers data from USB to the memory.
|
||||||
|
*
|
||||||
|
* \param addr Address of first memory sector to write.
|
||||||
|
* \param nb_sector Number of sectors to transfer.
|
||||||
|
*
|
||||||
|
* \return Status.
|
||||||
|
*/
|
||||||
|
extern Ctrl_status at45dbx_usb_write_10(U32 addr, U16 nb_sector);
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if ACCESS_MEM_TO_RAM == ENABLED
|
||||||
|
|
||||||
|
/*! \name MEM <-> RAM Interface
|
||||||
|
*/
|
||||||
|
//! @{
|
||||||
|
|
||||||
|
/*! \brief Copies 1 data sector from the memory to RAM.
|
||||||
|
*
|
||||||
|
* \param addr Address of first memory sector to read.
|
||||||
|
* \param ram Pointer to RAM buffer to write.
|
||||||
|
*
|
||||||
|
* \return Status.
|
||||||
|
*/
|
||||||
|
extern Ctrl_status at45dbx_df_2_ram(U32 addr, void *ram);
|
||||||
|
|
||||||
|
/*! \brief Copies 1 data sector from RAM to the memory.
|
||||||
|
*
|
||||||
|
* \param addr Address of first memory sector to write.
|
||||||
|
* \param ram Pointer to RAM buffer to read.
|
||||||
|
*
|
||||||
|
* \return Status.
|
||||||
|
*/
|
||||||
|
extern Ctrl_status at45dbx_ram_2_df(U32 addr, const void *ram);
|
||||||
|
|
||||||
|
//! @}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _AT45DBX_MEM_H_
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
|||||||
|
Revision: 2491
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef WL_OS_H
|
||||||
|
#define WL_OS_H
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
void *owl_os_alloc(size_t size);
|
||||||
|
void *owl_os_realloc(void *ptr, size_t size);
|
||||||
|
void owl_os_free(void *p);
|
||||||
|
void *owl_os_memcpy(void *dst, const void *src, size_t n);
|
||||||
|
void *owl_os_memset(void *s, int c, size_t n);
|
||||||
|
void *owl_os_memmove(void *dst, const void *src, size_t n);
|
||||||
|
size_t owl_os_strlen(char *s);
|
||||||
|
char *owl_os_strncpy(char *dst, const char *src, size_t n);
|
||||||
|
int owl_os_strncmp(const char *s1, const char *s2, size_t n);
|
||||||
|
int owl_os_strcmp(const char *s1, const char *s2);
|
||||||
|
char *owl_os_strcpy(char *dst, const char *src);
|
||||||
|
char *owl_os_strdup(const char *s);
|
||||||
|
char *owl_os_strndup(const char *s, size_t n);
|
||||||
|
int owl_os_memcmp(const void *s1, const void *s2, size_t n);
|
||||||
|
long int owl_os_strtol(const char *nptr, char **endptr, int base);
|
||||||
|
char *owl_os_strchr(const char *s, int c);
|
||||||
|
char *owl_os_strrchr(const char *s, int c);
|
||||||
|
int owl_os_strcasecmp(const char *s1, const char *s2);
|
||||||
|
char *owl_os_strstr(const char *haystack, const char *needle);
|
||||||
|
|
||||||
|
int owl_os_snprintf(char *str, size_t size, const char *format, ...)
|
||||||
|
__attribute__((format(printf, 3, 4)));
|
||||||
|
|
||||||
|
int owl_os_vprintf(const char *format, va_list arg); /* debug only */
|
||||||
|
int owl_os_printf(const char *format, ...) /* debug only */
|
||||||
|
__attribute__((format(printf, 1, 2)));
|
||||||
|
|
||||||
|
#endif /* WL_OS_H */
|
||||||
|
|
@ -0,0 +1,172 @@
|
|||||||
|
/*!
|
||||||
|
* \file wl_sdio.h
|
||||||
|
* \brief SDIO interface for wl_api.
|
||||||
|
* Copyright (C) 2010 HD Wireless AB
|
||||||
|
*
|
||||||
|
* You should have received a copy of the license along with this library.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WL_SDIO_H
|
||||||
|
#define WL_SDIO_H
|
||||||
|
|
||||||
|
/** \defgroup wl_sdio SDIO Interface
|
||||||
|
*
|
||||||
|
* These functions implement the interface that the wl_api library
|
||||||
|
* needs to work with a SDIO transport layer.
|
||||||
|
*
|
||||||
|
* The functions prototyped here must be implemented when porting the
|
||||||
|
* wl_api library to a new platform with a different SDIO configuration
|
||||||
|
*
|
||||||
|
* On platforms supported by H&D Wireless these functions are
|
||||||
|
* implemented in the file avr32_sdio.c
|
||||||
|
*
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum transfer size. This will set an upper limit on the len parameter
|
||||||
|
* passed to owl_sdio_tx() and owl_sdio_rx().
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define MAX_BLOCK_LEN 512
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This flag might be set when owl_sdio_cmd() is called in case the cmd will
|
||||||
|
* be followed by a data transfer. If the flag is set, the transfer direction is
|
||||||
|
* from the device to the host (read). Otherwise, the transfer direction is
|
||||||
|
* from the host to the device (write).
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define CMD_FLAG_TO_HOST (1 << 0)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that the sdio driver needs to be polled in order to make
|
||||||
|
* forward progress, i.e. it does not support interrupts
|
||||||
|
*
|
||||||
|
* The actual polling will result in owl_sdio_cmd() being called to
|
||||||
|
* request status information from the device.
|
||||||
|
*
|
||||||
|
* To activate polling, this flag should be set in owl_sdio_init().
|
||||||
|
*/
|
||||||
|
#define SDIO_FLAG_POLL (1 << 0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that the sdio driver only supports 1-bit mode.
|
||||||
|
*
|
||||||
|
* To set 1-bit mode, this flag should be set in owl_sdio_init().
|
||||||
|
*/
|
||||||
|
#define SDIO_FLAG_1BIT_MODE (1 << 1)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function will be invoked when wlan initialization should be performed,
|
||||||
|
* this happens when the wl_fw_download() function in the transport group of
|
||||||
|
* wl_api is invoked.
|
||||||
|
*
|
||||||
|
* The wifi device supports sdio high speed mode and clock frequencies up to
|
||||||
|
* 50 MHz.
|
||||||
|
*
|
||||||
|
* The function is responsible for doing any necessary sdio initialization such
|
||||||
|
* as allocating gpio's, setting up the mci master, one time allocations of
|
||||||
|
* dma buffers etc.
|
||||||
|
*
|
||||||
|
* @param flags is an out parameter that should hold any sdio flags upon return.
|
||||||
|
* The avaible flags are prefixed with SDIO_FLAG_
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void owl_sdio_init(uint8_t *flags);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function will be invoked when an sdio cmd should be sent to the
|
||||||
|
* device.
|
||||||
|
*
|
||||||
|
* @param idx is the sdio command number
|
||||||
|
* @param arg is the sdio command argument
|
||||||
|
* @param flags specifies other options, such as any transfer direction.
|
||||||
|
* @param rsp should hold the command response upon return. If null, the
|
||||||
|
* response can be ignored.
|
||||||
|
* @param data holds a pointer to any data that might follow the command. This
|
||||||
|
* allows the sdio driver to setup dma transfers while waiting for the
|
||||||
|
* command response. NULL if no data transfer will follow. Note that
|
||||||
|
* the same data pointer will be passed to owl_sdio_tx(), which should
|
||||||
|
* start the actual transfer.
|
||||||
|
* @param len is the length of the data buffer.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void owl_sdio_cmd(uint8_t idx, uint32_t arg, uint8_t flags, uint32_t *rsp,
|
||||||
|
const uint8_t *data, uint16_t len);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function will be invoked when data should be transmitted to the device.
|
||||||
|
*
|
||||||
|
* If wl_fw_downlad() was called with the size_align parameter set to non-zero,
|
||||||
|
* the pad parameter should be used. If the pad parameter is not 0, additional
|
||||||
|
* data must be transmitted after the data buffer has be sent. Depending on
|
||||||
|
* how the data buffer was first allocated (probably by an TCP/IP stack), it
|
||||||
|
* might be safe or unsafe to continue reading beyond the data buffer to
|
||||||
|
* transmit the additional padding bytes.
|
||||||
|
*
|
||||||
|
* @param data holds a pointer to the data to transmit, the pointer is the
|
||||||
|
* same as the one passed to wl_tx().
|
||||||
|
* @param len is the number of bytes that should be transmitted, including
|
||||||
|
* padding.
|
||||||
|
* @param pad is the number of padding bytes to send.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void owl_sdio_tx(const uint8_t *data, uint16_t len, uint8_t pad);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function will be invoked when data should be received from the device.
|
||||||
|
*
|
||||||
|
* @param data should hold the read data upon return.
|
||||||
|
* @param len is the number of bytes to read.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void owl_sdio_rx(uint8_t *data, uint16_t len);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoked when sdio rx interrupts from the device should be enabled or
|
||||||
|
* disabled.
|
||||||
|
*
|
||||||
|
* If SDIO_FLAG_POLL was set in wl_spi_init(), then this function can be
|
||||||
|
* left empty.
|
||||||
|
*
|
||||||
|
* @param enable specifies if interrupts should be enabled or disabled.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void owl_sdio_irq(uint8_t enable);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delay executiom for the specified number of ms. This function will be called
|
||||||
|
* with delays in the 10-20 ms range during fw download and startup of the
|
||||||
|
* Wi-Fi device. This function can be implemented with a simple for-loop if
|
||||||
|
* desired (beware of optimization). The timing does not have to be accurate as
|
||||||
|
* long as the actual delay becomes at least the specified number of ms.
|
||||||
|
*
|
||||||
|
* @param ms is the minimal amount of time to wait [ms].
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void owl_sdio_mdelay(uint32_t ms);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function should be called whenever an interrupt is detected. It can
|
||||||
|
* be called from an interrupt context.
|
||||||
|
*
|
||||||
|
* If SDIO_FLAG_POLL was set in owl_sdio_init(), then wl_sdio_irq()
|
||||||
|
* should never be called.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
extern void wl_sdio_irq(void);
|
||||||
|
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,185 @@
|
|||||||
|
/*!
|
||||||
|
* \file wl_spi.h
|
||||||
|
* \brief SPI interface for wl_api.
|
||||||
|
* Copyright (C) 2010 HD Wireless AB
|
||||||
|
*
|
||||||
|
* You should have received a copy of the license along with this library.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WL_SPI_H
|
||||||
|
#define WL_SPI_H
|
||||||
|
|
||||||
|
#ifndef WITHOUT_STDINT
|
||||||
|
#include <stdint.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** \defgroup wl_spi SPI Interface
|
||||||
|
*
|
||||||
|
* These functions implement the interface that the wl_api library
|
||||||
|
* needs to work with a SPI transport layer.
|
||||||
|
*
|
||||||
|
* The functions prototyped here must be implemented when porting the
|
||||||
|
* wl_api library to a new platform with a different SPI configuration
|
||||||
|
*
|
||||||
|
* On platforms supported by H&D Wireless these functions are
|
||||||
|
* implemented in the file avr32_spi.c
|
||||||
|
*
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum transfer size. This will set an upper limit on the len parameter
|
||||||
|
* passed to owl_spi_txrx().
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define MAX_BLOCK_LEN 512
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates that the spi driver needs to be polled in order to make
|
||||||
|
* forward progress, i.e. it does not support interrupts through SD pin 8.
|
||||||
|
*
|
||||||
|
* The actual polling will result in owl_spi_txrx() being call to
|
||||||
|
* request status information from the device.
|
||||||
|
*
|
||||||
|
* To activate polling, this flag should be set in owl_spi_init().
|
||||||
|
*
|
||||||
|
* See wl_poll() and wl_register_rx_isr() for more information regarding
|
||||||
|
* polled and interrupt modes.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define SPI_FLAG_POLL (1 << 0)
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function will be invoked when wlan device initialization should be
|
||||||
|
* performed, this happens when the wl_fw_download() function in the transport
|
||||||
|
* group of wl_api is invoked.
|
||||||
|
*
|
||||||
|
* The wifi device requires spi mode 3, i.e. clock polarity high and sample
|
||||||
|
* on second phase. This corresponds to CPOL=1, CPHA=1. Maximum frequency on
|
||||||
|
* spi clock is 30 MHz.
|
||||||
|
*
|
||||||
|
* The function is also responsible for doing any necessary spi initialization
|
||||||
|
* such as allocating gpio's, setting up the SPI master, one time allocations of
|
||||||
|
* dma buffers etc.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* If the SPB105 device is used, two signals; POWER (pin 10 on SPB105) and
|
||||||
|
* SHUTDOWN (pin 4 on SPB105) might be connected to gpio's on the host.
|
||||||
|
* The GPIO_POWER_PIN is the main power supply to the device. The
|
||||||
|
* GPIO_SHUTDOWN_PIN (active low) should be defined as an input.
|
||||||
|
*
|
||||||
|
* After GPIO_POWER_PIN is pulled high by the host, the device will pull the
|
||||||
|
* GPIO_SHUTDOWN_PIN high once the device is properly powered.
|
||||||
|
*
|
||||||
|
* However, if pin 4 (GPIO_SHUTDOWN_PIN) is not connected to the host, a delay
|
||||||
|
* of up to 250 ms must be added after GPIO_POWER_PIN is pulled high to ensure
|
||||||
|
* that startup is completed. The actual time is usually much shorter, therefore
|
||||||
|
* one might try to reduce the delay for a particualar hardware design.
|
||||||
|
*
|
||||||
|
* On SPB104, the GPIO_POWER_PIN will be connected to VCC and GPIO_SHUTDOWN_PIN
|
||||||
|
* will be unconnected; hence we have to make sure that we have enough delay
|
||||||
|
* after powering on the host. Since the device power-on usually happens at the
|
||||||
|
* same time as the host power-on, the startup time of the host can be
|
||||||
|
* subtracted from any delay put into owl_spi_init().
|
||||||
|
*
|
||||||
|
* @param flags is an out parameter that should hold any spi flags upon return.
|
||||||
|
* The avaible flags are prefixed with SPI_FLAG_
|
||||||
|
*
|
||||||
|
* @return 0 on success
|
||||||
|
* -1 if any error occurs
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int owl_spi_init(uint8_t *flags);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoked when a spi transfer should be performed.
|
||||||
|
*
|
||||||
|
* All buffers that are allocated by the wl library will have a size that is
|
||||||
|
* aligned to 4. If size-unaligned data is passed to this function, it is
|
||||||
|
* always allocated by the ip stack. If 4-byte size alignment (e.g. for DMA)
|
||||||
|
* is required, 1-3 extra padding bytes can be transmitted after the in buffer.
|
||||||
|
* These bytes must be 0xff.
|
||||||
|
*
|
||||||
|
* Since size-unaligned data always comes from the ip stack, the out ptr is
|
||||||
|
* always NULL for such data.
|
||||||
|
*
|
||||||
|
* @param in points a buffer which holds the data to be transmitted. If NULL,
|
||||||
|
* then \a len bytes with the value 0xff should be transmitted on the
|
||||||
|
* bus.
|
||||||
|
* @param out points a buffer should hold the data received from the device. If
|
||||||
|
* NULL, any received data can be discarded.
|
||||||
|
* @param len is the length of the in and out buffers.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void owl_spi_txrx(const uint8_t *in, uint8_t* out, uint16_t len);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoked when spi rx interrupts from the device should be enabled or disabled.
|
||||||
|
* Note that the spi interrupts are obtained from pin 8 on SPB104 or pin 3 from
|
||||||
|
* SPB105. This pin can be be connected to a gpio on the host. The irq line
|
||||||
|
* will signal an interrupt on both edges.
|
||||||
|
*
|
||||||
|
* In general, the wifi device will not issue a new interrupt unless the
|
||||||
|
* last interrupt has been handled. Also, during normal operation (i.e after
|
||||||
|
* the complete callback registered in wl_init() has been invoked),
|
||||||
|
* owl_spi_irq() will never be invoked so interrupts will be enabled all
|
||||||
|
* the time. For the SPI-mode, the purpose of owl_spi_irq() is basically to
|
||||||
|
* make sure that the first interrupt (coming after the reset performed in
|
||||||
|
* owl_spi_init()) is ignored.
|
||||||
|
*
|
||||||
|
* If SPI_FLAG_POLL was set in owl_spi_init(), then this function can be
|
||||||
|
* left empty and the wifi device will be used in polled mode. In polled mode,
|
||||||
|
* the interrupt line is not used. Regardless of polled or interrupt-mode,
|
||||||
|
* wl_poll() must be called to ensure progress of the driver.
|
||||||
|
*
|
||||||
|
* @param enable specifies if interrupts should be enabled or disabled.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void owl_spi_irq(uint8_t enable);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoked when the spi cs for the wifi device should be enabled. Note that
|
||||||
|
* multiple calls to owl_spi_txrx() might be done during a 'single' chip
|
||||||
|
* select.
|
||||||
|
*
|
||||||
|
* @param enable specifies whether chip select should be asserted or deasserted,
|
||||||
|
* The chip select signal is active low, so if enable is '1' then the
|
||||||
|
* chip select connected to the wifi device should be set to '0'.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void owl_spi_cs(uint8_t enable);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delay executiom for the specified number of ms. This function will be called
|
||||||
|
* with delays in the 10-20 ms range during fw download and startup of the
|
||||||
|
* Wi-Fi device. This function can be implemented with a simple for-loop if
|
||||||
|
* desired (beware of optimization). The timing does not have to be accurate as
|
||||||
|
* long as the actual delay becomes at least the specified number of ms.
|
||||||
|
*
|
||||||
|
* @param ms is the minimal amount of time to wait [ms].
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void owl_spi_mdelay(uint32_t ms);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function should be called whenever an interrupt is detected. It can
|
||||||
|
* be called from an interrupt context.
|
||||||
|
*
|
||||||
|
* If SPI_FLAG_POLL was set in owl_spi_init(), then wl_spi_irq()
|
||||||
|
* should never be called.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
extern void wl_spi_irq(void);
|
||||||
|
|
||||||
|
|
||||||
|
/*! @} */
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,154 @@
|
|||||||
|
/*
|
||||||
|
* Programming interface for wlap_api.
|
||||||
|
* Copyright (C) 2011 HD Wireless AB
|
||||||
|
*
|
||||||
|
* You should have received a copy of the license along with this library.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*! \file wlap_api.h *************************************************************
|
||||||
|
*
|
||||||
|
* \brief WiFi AP API
|
||||||
|
*
|
||||||
|
* This file provides the wlap_api interface.
|
||||||
|
*
|
||||||
|
* - Compiler: GNU GCC for AVR32
|
||||||
|
* - Supported devices:
|
||||||
|
* \li SPB104 + EVK1100
|
||||||
|
* \li SPB104 + EVK1101
|
||||||
|
* \li SPB104 + EVK1104
|
||||||
|
* \li SPB104 + EVK1105 (SPI)
|
||||||
|
* \li SPB104 + EVK1105 (SPI + irq)
|
||||||
|
* \li SPB105 + EVK1105 (SPI)
|
||||||
|
* - AppNote:
|
||||||
|
*
|
||||||
|
* \author H&D Wireless AB: \n
|
||||||
|
*
|
||||||
|
*****************************************************************************
|
||||||
|
*
|
||||||
|
* \section intro Introduction
|
||||||
|
* This is the documentation for the WiFi AP Driver API \a wlap_api.
|
||||||
|
*
|
||||||
|
* \section files Main Files
|
||||||
|
* - wlap_api.h : WiFi driver interface.
|
||||||
|
* - libwlap_api_*.*.a - Driver library.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef WLAP_API_H
|
||||||
|
#define WLAP_API_H
|
||||||
|
|
||||||
|
#define WLAP_API_RELEASE_NAME "unknown"
|
||||||
|
|
||||||
|
#include <wl_api.h>
|
||||||
|
|
||||||
|
/** \defgroup wl_softap Access Point Mode
|
||||||
|
*
|
||||||
|
* \brief Support the WiFi Access Point mode.
|
||||||
|
*
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Station representation
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
struct wl_sta_t
|
||||||
|
{
|
||||||
|
struct wl_mac_addr_t bssid; /**< The BSSID of the network. */
|
||||||
|
uint8_t queued_pkt_cnt; /**< Number of queueud packets for
|
||||||
|
this STA. */
|
||||||
|
uint8_t in_ps; /**< Is the STA in power save mode. */
|
||||||
|
uint8_t aid; /**< STA AID */
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Station list representation. Array of pointers to wl_sta_t entries. */
|
||||||
|
struct wl_sta_list_t
|
||||||
|
{
|
||||||
|
struct wl_sta_t **sta; /**< The list of pointers to stations */
|
||||||
|
size_t cnt; /**< Number of stations */
|
||||||
|
};
|
||||||
|
|
||||||
|
/*! \brief Get the list of currently associated stations (SoftAP).
|
||||||
|
*
|
||||||
|
* Retrieves the list of current stations from
|
||||||
|
* the driver.
|
||||||
|
*
|
||||||
|
* This function is not thread safe. It must be called in the
|
||||||
|
* same execution context as wl_poll().
|
||||||
|
*
|
||||||
|
* @param network_list Output buffer. The API call returns
|
||||||
|
* a pointer to allocated memory containing the network list.
|
||||||
|
* @return
|
||||||
|
* - WL_SUCCESS
|
||||||
|
* - WL_FAILURE.
|
||||||
|
*/
|
||||||
|
wl_err_t wlap_get_sta_list(struct wl_sta_list_t **network_list);
|
||||||
|
|
||||||
|
|
||||||
|
/*! Callback used to read data from a TX packet.
|
||||||
|
* This function is supplied by the user of the API.
|
||||||
|
*
|
||||||
|
* @param dst Destination buffer. The data should be copied
|
||||||
|
* to this buffer.
|
||||||
|
* @param src_handle Handle to the source packet from where
|
||||||
|
* the data should be copied. This handle is the same one that
|
||||||
|
* is passed in parameter \a pkt_handle to \a wl_process_tx().
|
||||||
|
* @param read_len Number of bytes to copy from \a src_handle
|
||||||
|
* to \a dst.
|
||||||
|
* @param offset The offset in bytes, counting from the
|
||||||
|
* beginning of the Ethernet header, from where to copy data.
|
||||||
|
* @return
|
||||||
|
* - The number of bytes copied. This number may be smaller
|
||||||
|
* than the length requested in \a read_len but it may not
|
||||||
|
* be shorter than the length of the packet counting from
|
||||||
|
* \a offset. In other words, if the caller of this function
|
||||||
|
* receives a return count that is shorter than \a read_len
|
||||||
|
* he will assume that all packet data has been read.
|
||||||
|
* - < 0 on error.
|
||||||
|
*/
|
||||||
|
typedef ssize_t (*wl_pkt_read_cb_t)(char *dst,
|
||||||
|
void *src_handle,
|
||||||
|
size_t read_len,
|
||||||
|
int offset);
|
||||||
|
|
||||||
|
/*! \brief Register a data access function for TX packets (SoftAP).
|
||||||
|
*
|
||||||
|
* When a TX data packet has a different representation than a single
|
||||||
|
* contiguous buffer in memory then a packet read function must be
|
||||||
|
* implemented and registered with this call. Whenever the library
|
||||||
|
* needs to read packet data it will call this function to do it.
|
||||||
|
*
|
||||||
|
* This function can be ignored if the TX packet representation is
|
||||||
|
* a single contiguous buffer. This function is only needed in SoftAP
|
||||||
|
* mode.
|
||||||
|
*
|
||||||
|
* @param pkt_read_cb Read callback.
|
||||||
|
* @param ctx Context
|
||||||
|
*/
|
||||||
|
void wl_register_pkt_read_cb(wl_pkt_read_cb_t pkt_read_cb);
|
||||||
|
|
||||||
|
/*! \brief Start a network using the SoftAP mode.
|
||||||
|
*
|
||||||
|
* This call will cause the WiFi chip to start sending beacons
|
||||||
|
* and accept associations from WiFi stations.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
wl_err_t wlap_start_ap(const char *ssid,
|
||||||
|
const size_t ssid_len,
|
||||||
|
const uint8_t channel,
|
||||||
|
const enum wl_auth_mode auth_mode,
|
||||||
|
const enum wl_enc_type enc_type);
|
||||||
|
|
||||||
|
/*! \brief Disconnect a STA (SoftAP)
|
||||||
|
*
|
||||||
|
* @param bssid The BSSID of the station to disconnect.
|
||||||
|
* @return
|
||||||
|
* - WL_SUCCESS
|
||||||
|
* - WL_FAILURE.
|
||||||
|
*/
|
||||||
|
wl_err_t wlap_disconnect_sta(const struct wl_mac_addr_t bssid);
|
||||||
|
|
||||||
|
|
||||||
|
/*! @} */ /* End wl_softap group */
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user