mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-20 21:01:25 +03:00
Merge branch 'ide-1.5.x' into can
This commit is contained in:
380
hardware/arduino/avr/cores/arduino/malloc.c
Normal file
380
hardware/arduino/avr/cores/arduino/malloc.c
Normal file
@ -0,0 +1,380 @@
|
||||
/* Copyright (c) 2002, 2004, 2010 Joerg Wunsch
|
||||
Copyright (c) 2010 Gerben van den Broeke
|
||||
All rights reserved.
|
||||
|
||||
malloc, free, realloc from avr-libc 1.7.0
|
||||
with minor modifications, by Paul Stoffregen
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
* Neither the name of the copyright holders nor the names of
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <avr/io.h>
|
||||
|
||||
|
||||
#define __MALLOC_MARGIN__ 120
|
||||
|
||||
|
||||
struct __freelist {
|
||||
size_t sz;
|
||||
struct __freelist *nx;
|
||||
};
|
||||
|
||||
/*
|
||||
* Exported interface:
|
||||
*
|
||||
* When extending the data segment, the allocator will not try to go
|
||||
* beyond the current stack limit, decreased by __malloc_margin bytes.
|
||||
* Thus, all possible stack frames of interrupt routines that could
|
||||
* interrupt the current function, plus all further nested function
|
||||
* calls must not require more stack space, or they'll risk to collide
|
||||
* with the data segment.
|
||||
*/
|
||||
|
||||
|
||||
#define STACK_POINTER() ((char *)AVR_STACK_POINTER_REG)
|
||||
extern char __heap_start;
|
||||
char *__brkval = &__heap_start; // first location not yet allocated
|
||||
struct __freelist *__flp; // freelist pointer (head of freelist)
|
||||
char *__brkval_maximum = 100;
|
||||
|
||||
void *
|
||||
malloc(size_t len)
|
||||
{
|
||||
struct __freelist *fp1, *fp2, *sfp1, *sfp2;
|
||||
char *cp;
|
||||
size_t s, avail;
|
||||
|
||||
/*
|
||||
* Our minimum chunk size is the size of a pointer (plus the
|
||||
* size of the "sz" field, but we don't need to account for
|
||||
* this), otherwise we could not possibly fit a freelist entry
|
||||
* into the chunk later.
|
||||
*/
|
||||
if (len < sizeof(struct __freelist) - sizeof(size_t))
|
||||
len = sizeof(struct __freelist) - sizeof(size_t);
|
||||
|
||||
/*
|
||||
* First, walk the free list and try finding a chunk that
|
||||
* would match exactly. If we found one, we are done. While
|
||||
* walking, note down the smallest chunk we found that would
|
||||
* still fit the request -- we need it for step 2.
|
||||
*
|
||||
*/
|
||||
for (s = 0, fp1 = __flp, fp2 = 0;
|
||||
fp1;
|
||||
fp2 = fp1, fp1 = fp1->nx) {
|
||||
if (fp1->sz < len)
|
||||
continue;
|
||||
if (fp1->sz == len) {
|
||||
/*
|
||||
* Found it. Disconnect the chunk from the
|
||||
* freelist, and return it.
|
||||
*/
|
||||
if (fp2)
|
||||
fp2->nx = fp1->nx;
|
||||
else
|
||||
__flp = fp1->nx;
|
||||
return &(fp1->nx);
|
||||
}
|
||||
else {
|
||||
if (s == 0 || fp1->sz < s) {
|
||||
/* this is the smallest chunk found so far */
|
||||
s = fp1->sz;
|
||||
sfp1 = fp1;
|
||||
sfp2 = fp2;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Step 2: If we found a chunk on the freelist that would fit
|
||||
* (but was too large), look it up again and use it, since it
|
||||
* is our closest match now. Since the freelist entry needs
|
||||
* to be split into two entries then, watch out that the
|
||||
* difference between the requested size and the size of the
|
||||
* chunk found is large enough for another freelist entry; if
|
||||
* not, just enlarge the request size to what we have found,
|
||||
* and use the entire chunk.
|
||||
*/
|
||||
if (s) {
|
||||
if (s - len < sizeof(struct __freelist)) {
|
||||
/* Disconnect it from freelist and return it. */
|
||||
if (sfp2)
|
||||
sfp2->nx = sfp1->nx;
|
||||
else
|
||||
__flp = sfp1->nx;
|
||||
return &(sfp1->nx);
|
||||
}
|
||||
/*
|
||||
* Split them up. Note that we leave the first part
|
||||
* as the new (smaller) freelist entry, and return the
|
||||
* upper portion to the caller. This saves us the
|
||||
* work to fix up the freelist chain; we just need to
|
||||
* fixup the size of the current entry, and note down
|
||||
* the size of the new chunk before returning it to
|
||||
* the caller.
|
||||
*/
|
||||
cp = (char *)sfp1;
|
||||
s -= len;
|
||||
cp += s;
|
||||
sfp2 = (struct __freelist *)cp;
|
||||
sfp2->sz = len;
|
||||
sfp1->sz = s - sizeof(size_t);
|
||||
return &(sfp2->nx);
|
||||
}
|
||||
/*
|
||||
* Step 3: If the request could not be satisfied from a
|
||||
* freelist entry, just prepare a new chunk. This means we
|
||||
* need to obtain more memory first. The largest address just
|
||||
* not allocated so far is remembered in the brkval variable.
|
||||
* Under Unix, the "break value" was the end of the data
|
||||
* segment as dynamically requested from the operating system.
|
||||
* Since we don't have an operating system, just make sure
|
||||
* that we don't collide with the stack.
|
||||
*/
|
||||
cp = STACK_POINTER() - __MALLOC_MARGIN__;
|
||||
if (cp <= __brkval)
|
||||
/*
|
||||
* Memory exhausted.
|
||||
*/
|
||||
return 0;
|
||||
avail = cp - __brkval;
|
||||
/*
|
||||
* Both tests below are needed to catch the case len >= 0xfffe.
|
||||
*/
|
||||
if (avail >= len && avail >= len + sizeof(size_t)) {
|
||||
fp1 = (struct __freelist *)__brkval;
|
||||
__brkval += len + sizeof(size_t);
|
||||
__brkval_maximum = __brkval;
|
||||
fp1->sz = len;
|
||||
return &(fp1->nx);
|
||||
}
|
||||
/*
|
||||
* Step 4: There's no help, just fail. :-/
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
free(void *p)
|
||||
{
|
||||
struct __freelist *fp1, *fp2, *fpnew;
|
||||
char *cp1, *cp2, *cpnew;
|
||||
|
||||
/* ISO C says free(NULL) must be a no-op */
|
||||
if (p == 0)
|
||||
return;
|
||||
|
||||
cpnew = p;
|
||||
cpnew -= sizeof(size_t);
|
||||
fpnew = (struct __freelist *)cpnew;
|
||||
fpnew->nx = 0;
|
||||
|
||||
/*
|
||||
* Trivial case first: if there's no freelist yet, our entry
|
||||
* will be the only one on it. If this is the last entry, we
|
||||
* can reduce __brkval instead.
|
||||
*/
|
||||
if (__flp == 0) {
|
||||
if ((char *)p + fpnew->sz == __brkval)
|
||||
__brkval = cpnew;
|
||||
else
|
||||
__flp = fpnew;
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Now, find the position where our new entry belongs onto the
|
||||
* freelist. Try to aggregate the chunk with adjacent chunks
|
||||
* if possible.
|
||||
*/
|
||||
for (fp1 = __flp, fp2 = 0;
|
||||
fp1;
|
||||
fp2 = fp1, fp1 = fp1->nx) {
|
||||
if (fp1 < fpnew)
|
||||
continue;
|
||||
cp1 = (char *)fp1;
|
||||
fpnew->nx = fp1;
|
||||
if ((char *)&(fpnew->nx) + fpnew->sz == cp1) {
|
||||
/* upper chunk adjacent, assimilate it */
|
||||
fpnew->sz += fp1->sz + sizeof(size_t);
|
||||
fpnew->nx = fp1->nx;
|
||||
}
|
||||
if (fp2 == 0) {
|
||||
/* new head of freelist */
|
||||
__flp = fpnew;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Note that we get here either if we hit the "break" above,
|
||||
* or if we fell off the end of the loop. The latter means
|
||||
* we've got a new topmost chunk. Either way, try aggregating
|
||||
* with the lower chunk if possible.
|
||||
*/
|
||||
fp2->nx = fpnew;
|
||||
cp2 = (char *)&(fp2->nx);
|
||||
if (cp2 + fp2->sz == cpnew) {
|
||||
/* lower junk adjacent, merge */
|
||||
fp2->sz += fpnew->sz + sizeof(size_t);
|
||||
fp2->nx = fpnew->nx;
|
||||
}
|
||||
/*
|
||||
* If there's a new topmost chunk, lower __brkval instead.
|
||||
*/
|
||||
for (fp1 = __flp, fp2 = 0;
|
||||
fp1->nx != 0;
|
||||
fp2 = fp1, fp1 = fp1->nx)
|
||||
/* advance to entry just before end of list */;
|
||||
cp2 = (char *)&(fp1->nx);
|
||||
if (cp2 + fp1->sz == __brkval) {
|
||||
if (fp2 == NULL)
|
||||
/* Freelist is empty now. */
|
||||
__flp = NULL;
|
||||
else
|
||||
fp2->nx = NULL;
|
||||
__brkval = cp2 - sizeof(size_t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void *
|
||||
realloc(void *ptr, size_t len)
|
||||
{
|
||||
struct __freelist *fp1, *fp2, *fp3, *ofp3;
|
||||
char *cp, *cp1;
|
||||
void *memp;
|
||||
size_t s, incr;
|
||||
|
||||
/* Trivial case, required by C standard. */
|
||||
if (ptr == 0)
|
||||
return malloc(len);
|
||||
|
||||
cp1 = (char *)ptr;
|
||||
cp1 -= sizeof(size_t);
|
||||
fp1 = (struct __freelist *)cp1;
|
||||
|
||||
cp = (char *)ptr + len; /* new next pointer */
|
||||
if (cp < cp1)
|
||||
/* Pointer wrapped across top of RAM, fail. */
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* See whether we are growing or shrinking. When shrinking,
|
||||
* we split off a chunk for the released portion, and call
|
||||
* free() on it. Therefore, we can only shrink if the new
|
||||
* size is at least sizeof(struct __freelist) smaller than the
|
||||
* previous size.
|
||||
*/
|
||||
if (len <= fp1->sz) {
|
||||
/* The first test catches a possible unsigned int
|
||||
* rollover condition. */
|
||||
if (fp1->sz <= sizeof(struct __freelist) ||
|
||||
len > fp1->sz - sizeof(struct __freelist))
|
||||
return ptr;
|
||||
fp2 = (struct __freelist *)cp;
|
||||
fp2->sz = fp1->sz - len - sizeof(size_t);
|
||||
fp1->sz = len;
|
||||
free(&(fp2->nx));
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we get here, we are growing. First, see whether there
|
||||
* is space in the free list on top of our current chunk.
|
||||
*/
|
||||
incr = len - fp1->sz;
|
||||
cp = (char *)ptr + fp1->sz;
|
||||
fp2 = (struct __freelist *)cp;
|
||||
for (s = 0, ofp3 = 0, fp3 = __flp;
|
||||
fp3;
|
||||
ofp3 = fp3, fp3 = fp3->nx) {
|
||||
if (fp3 == fp2 && fp3->sz + sizeof(size_t) >= incr) {
|
||||
/* found something that fits */
|
||||
if (fp3->sz + sizeof(size_t) - incr > sizeof(struct __freelist)) {
|
||||
/* split off a new freelist entry */
|
||||
cp = (char *)ptr + len;
|
||||
fp2 = (struct __freelist *)cp;
|
||||
fp2->nx = fp3->nx;
|
||||
fp2->sz = fp3->sz - incr;
|
||||
fp1->sz = len;
|
||||
} else {
|
||||
/* it just fits, so use it entirely */
|
||||
fp1->sz += fp3->sz + sizeof(size_t);
|
||||
fp2 = fp3->nx;
|
||||
}
|
||||
if (ofp3)
|
||||
ofp3->nx = fp2;
|
||||
else
|
||||
__flp = fp2;
|
||||
return ptr;
|
||||
}
|
||||
/*
|
||||
* Find the largest chunk on the freelist while
|
||||
* walking it.
|
||||
*/
|
||||
if (fp3->sz > s)
|
||||
s = fp3->sz;
|
||||
}
|
||||
/*
|
||||
* If we are the topmost chunk in memory, and there was no
|
||||
* large enough chunk on the freelist that could be re-used
|
||||
* (by a call to malloc() below), quickly extend the
|
||||
* allocation area if possible, without need to copy the old
|
||||
* data.
|
||||
*/
|
||||
if (__brkval == (char *)ptr + fp1->sz && len > s) {
|
||||
cp = (char *)ptr + len;
|
||||
cp1 = STACK_POINTER() - __MALLOC_MARGIN__;
|
||||
if (cp < cp1) {
|
||||
__brkval = cp;
|
||||
__brkval_maximum = cp;
|
||||
fp1->sz = len;
|
||||
return ptr;
|
||||
}
|
||||
/* If that failed, we are out of luck. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Call malloc() for a new chunk, then copy over the data, and
|
||||
* release the old region.
|
||||
*/
|
||||
if ((memp = malloc(len)) == 0)
|
||||
return 0;
|
||||
memcpy(memp, ptr, fp1->sz);
|
||||
free(ptr);
|
||||
return memp;
|
||||
}
|
||||
|
@ -5,10 +5,20 @@ void * operator new(size_t size)
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void * operator new[](size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void operator delete(void * ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
void operator delete[](void * ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
int __cxa_guard_acquire(__guard *g) {return !*(char *)(g);};
|
||||
void __cxa_guard_release (__guard *g) {*(char *)g = 1;};
|
||||
|
@ -8,7 +8,9 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
void * operator new(size_t size);
|
||||
void operator delete(void * ptr);
|
||||
void * operator new[](size_t size);
|
||||
void operator delete(void * ptr);
|
||||
void operator delete[](void * ptr);
|
||||
|
||||
__extension__ typedef int __guard __attribute__((mode (__DI__)));
|
||||
|
||||
|
@ -0,0 +1,38 @@
|
||||
/*
|
||||
Esplora Accelerometer
|
||||
|
||||
This sketch shows you how to read the values from the accelerometer.
|
||||
To see it in action, open the serial monitor and tilt the board. You'll see
|
||||
the accelerometer values for each axis change when you tilt the board
|
||||
on that axis.
|
||||
|
||||
Created on 22 Dec 2012
|
||||
by Tom Igoe
|
||||
|
||||
This example is in the public domain.
|
||||
*/
|
||||
|
||||
#include <Esplora.h>
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600); // initialize serial communications with your computer
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int xAxis = Esplora.readAccelerometer(X_AXIS); // read the X axis
|
||||
int yAxis = Esplora.readAccelerometer(Y_AXIS); // read the Y axis
|
||||
int zAxis = Esplora.readAccelerometer(Z_AXIS); // read the Z axis
|
||||
|
||||
Serial.print("x: "); // print the label for X
|
||||
Serial.print(xAxis); // print the value for the X axis
|
||||
Serial.print("\ty: "); // print a tab character, then the label for Y
|
||||
Serial.print(yAxis); // print the value for the Y axis
|
||||
Serial.print("\tz: "); // print a tab character, then the label for Z
|
||||
Serial.println(zAxis); // print the value for the Z axis
|
||||
|
||||
delay(500); // wait half a second (500 milliseconds)
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,42 @@
|
||||
|
||||
/*
|
||||
Esplora Blink
|
||||
|
||||
This sketch blinks the Esplora's RGB LED. It goes through
|
||||
all three primary colors (red, green, blue), then it
|
||||
combines them for secondary colors(yellow, cyan, magenta), then
|
||||
it turns on all the colors for white.
|
||||
For best results cover the LED with a piece of white paper to see the colors.
|
||||
|
||||
Created on 22 Dec 2012
|
||||
by Tom Igoe
|
||||
|
||||
This example is in the public domain.
|
||||
*/
|
||||
|
||||
#include <Esplora.h>
|
||||
|
||||
|
||||
void setup() {
|
||||
// There's nothing to set up for this sketch
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Esplora.writeRGB(255,0,0); // make the LED red
|
||||
delay(1000); // wait 1 second
|
||||
Esplora.writeRGB(0,255,0); // make the LED green
|
||||
delay(1000); // wait 1 second
|
||||
Esplora.writeRGB(0,0,255); // make the LED blue
|
||||
delay(1000); // wait 1 second
|
||||
Esplora.writeRGB(255,255,0); // make the LED yellow
|
||||
delay(1000); // wait 1 second
|
||||
Esplora.writeRGB(0,255,255); // make the LED cyan
|
||||
delay(1000); // wait 1 second
|
||||
Esplora.writeRGB(255,0,255); // make the LED magenta
|
||||
delay(1000); // wait 1 second
|
||||
Esplora.writeRGB(255,255,255);// make the LED white
|
||||
delay(1000); // wait 1 second
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,50 @@
|
||||
/*
|
||||
Esplora Joystick Mouse
|
||||
|
||||
This sketch shows you how to read the joystick and use it to control the movement
|
||||
of the cursor on your computer. You're making your Esplora into a mouse!
|
||||
|
||||
WARNING: this sketch will take over your mouse movement. If you lose control
|
||||
of your mouse do the following:
|
||||
1) unplug the Esplora.
|
||||
2) open the EsploraBlink sketch
|
||||
3) hold the reset button down while plugging your Esplora back in
|
||||
4) while holding reset, click "Upload"
|
||||
5) when you see the message "Done compiling", release the reset button.
|
||||
|
||||
This will stop your Esplora from controlling your mouse while you upload a sketch
|
||||
that doesn't take control of the mouse.
|
||||
|
||||
Created on 22 Dec 2012
|
||||
by Tom Igoe
|
||||
|
||||
This example is in the public domain.
|
||||
*/
|
||||
|
||||
#include <Esplora.h>
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600); // initialize serial communication with your computer
|
||||
Mouse.begin(); // take control of the mouse
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int xValue = Esplora.readJoystickX(); // read the joystick's X position
|
||||
int yValue = Esplora.readJoystickY(); // read the joystick's Y position
|
||||
int button = Esplora.readJoystickSwitch(); // read the joystick pushbutton
|
||||
Serial.print("Joystick X: "); // print a label for the X value
|
||||
Serial.print(xValue); // print the X value
|
||||
Serial.print("\tY: "); // print a tab character and a label for the Y value
|
||||
Serial.print(yValue); // print the Y value
|
||||
Serial.print("\tButton: "); // print a tab character and a label for the button
|
||||
Serial.print(button); // print the button value
|
||||
|
||||
int mouseX = map( xValue,-512, 512, 10, -10); // map the X value to a range of movement for the mouse X
|
||||
int mouseY = map( yValue,-512, 512, -10, 10); // map the Y value to a range of movement for the mouse Y
|
||||
Mouse.move(mouseX, mouseY, 0); // move the mouse
|
||||
|
||||
delay(10); // a short delay before moving again
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
Created on 22 november 2012
|
||||
By Enrico Gueli <enrico.gueli@gmail.com>
|
||||
Modified 24 Nov 2012
|
||||
Modified 22 Dec 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
#include <Esplora.h>
|
||||
@ -24,7 +24,7 @@ void loop() {
|
||||
|
||||
// convert the sensor readings to light levels:
|
||||
byte red = map(xAxis, -512, 512, 0, 255);
|
||||
byte green = map(xAxis, -512, 512, 0, 255);
|
||||
byte green = map(yAxis, -512, 512, 0, 255);
|
||||
byte blue = slider/4;
|
||||
|
||||
// print the light levels:
|
@ -0,0 +1,91 @@
|
||||
/*
|
||||
Esplora Led calibration
|
||||
|
||||
This sketch shows you how to read and calibrate the light sensor.
|
||||
Because light levels vary from one location to another, you need to calibrate the
|
||||
sensor for each location. To do this, you read the sensor for a few seconds,
|
||||
and save the highest and lowest readings as maximum and minimum.
|
||||
Then, when you're using the sensor's reading (for example, to set the brightness
|
||||
of the LED), you map the sensor's reading to a range between the minimum
|
||||
and the maximum.
|
||||
|
||||
Created on 22 Dec 2012
|
||||
by Tom Igoe
|
||||
|
||||
This example is in the public domain.
|
||||
*/
|
||||
|
||||
#include <Esplora.h>
|
||||
|
||||
// variables:
|
||||
int lightMin = 1023; // minimum sensor value
|
||||
int lightMax = 0; // maximum sensor value
|
||||
boolean calibrated = false; // whether the sensor's been calibrated yet
|
||||
|
||||
void setup() {
|
||||
// initialize the serial communication:
|
||||
Serial.begin(9600);
|
||||
|
||||
// print an intial message
|
||||
Serial.println("To calibrate the light sensor, press and hold Switch 1");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// if switch 1 is pressed, go to the calibration function again:
|
||||
if (Esplora.readButton(1) == LOW) {
|
||||
calibrate();
|
||||
}
|
||||
// read the sensor into a variable:
|
||||
int light = Esplora.readLightSensor();
|
||||
|
||||
// map the light level to a brightness level for the LED
|
||||
// using the calibration min and max:
|
||||
int brightness = map(light, lightMin, lightMax, 0, 255);
|
||||
// limit the brightness to a range from 0 to 255:
|
||||
brightness = constrain(brightness, 0, 255);
|
||||
// write the brightness to the blue LED.
|
||||
Esplora.writeBlue(brightness);
|
||||
|
||||
// if the calibration's been done, show the sensor and brightness
|
||||
// levels in the serial monitor:
|
||||
if (calibrated == true) {
|
||||
// print the light sensor levels and the LED levels (to see what's going on):
|
||||
Serial.print("light sensor level: ");
|
||||
Serial.print(light);
|
||||
Serial.print(" blue brightness: ");
|
||||
Serial.println(brightness);
|
||||
}
|
||||
// add a delay to keep the LED from flickering:
|
||||
delay(10);
|
||||
}
|
||||
|
||||
void calibrate() {
|
||||
// tell the user what do to using the serial monitor:
|
||||
Serial.println("While holding switch 1, shine a light on the light sensor, then cover it.");
|
||||
|
||||
// calibrate while switch 1 is pressed:
|
||||
while(Esplora.readButton(1) == LOW) {
|
||||
// read the sensor value:
|
||||
int light = Esplora.readLightSensor();
|
||||
|
||||
// record the maximum sensor value:
|
||||
if (light > lightMax) {
|
||||
lightMax = light;
|
||||
}
|
||||
|
||||
// record the minimum sensor value:
|
||||
if (light < lightMin) {
|
||||
lightMin = light;
|
||||
}
|
||||
// note that you're calibrated, for future reference:
|
||||
calibrated = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -6,14 +6,15 @@
|
||||
|
||||
Created on 22 november 2012
|
||||
By Enrico Gueli <enrico.gueli@gmail.com>
|
||||
modified 24 Nov 2012
|
||||
modified 22 Dec 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
|
||||
|
||||
#include <Esplora.h>
|
||||
|
||||
|
||||
// these are the frequencies for the notes from middle C
|
||||
// to one octave above middle C:
|
||||
const int note[] = {
|
||||
262, // C
|
||||
277, // C#
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
Esplora Sound Sensor
|
||||
|
||||
This sketch shows you how to read the microphone sensor. The microphone
|
||||
will range from 0 (total silence) to 1023 (really loud).
|
||||
When you're using the sensor's reading (for example, to set the brightness
|
||||
of the LED), you map the sensor's reading to a range between the minimum
|
||||
and the maximum.
|
||||
|
||||
Created on 22 Dec 2012
|
||||
by Tom Igoe
|
||||
|
||||
This example is in the public domain.
|
||||
*/
|
||||
|
||||
#include <Esplora.h>
|
||||
|
||||
void setup() {
|
||||
// initialize the serial communication:
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the sensor into a variable:
|
||||
int loudness = Esplora.readMicrophone();
|
||||
|
||||
// map the sound level to a brightness level for the LED:
|
||||
int brightness = map(loudness, 0, 1023, 0, 255);
|
||||
// write the brightness to the green LED:
|
||||
Esplora.writeGreen(brightness);
|
||||
|
||||
|
||||
// print the microphone levels and the LED levels (to see what's going on):
|
||||
Serial.print("sound level: ");
|
||||
Serial.print(loudness);
|
||||
Serial.print(" Green brightness: ");
|
||||
Serial.println(brightness);
|
||||
// add a delay to keep the LED from flickering:
|
||||
delay(10);
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
Esplora Temperature Sensor
|
||||
|
||||
This sketch shows you how to read the Esplora's temperature sensor
|
||||
You can read the temperature sensor in Farhenheit or Celsius.
|
||||
|
||||
Created on 22 Dec 2012
|
||||
by Tom Igoe
|
||||
|
||||
This example is in the public domain.
|
||||
*/
|
||||
#include <Esplora.h>
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(9600); // initialize serial communications with your computer
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// read the temperature sensor in Celsius, then Fahrenheit:
|
||||
int celsius = Esplora.readTemperature(DEGREES_C);
|
||||
int fahrenheit = Esplora.readTemperature(DEGREES_F);
|
||||
|
||||
// print the results:
|
||||
Serial.print("Temperature is: ");
|
||||
Serial.print(celsius);
|
||||
Serial.print(" degrees Celsius, or ");
|
||||
Serial.print(fahrenheit);
|
||||
Serial.println(" degrees Fahrenheit.");
|
||||
Serial.println(" Fahrenheit = (9/5 * Celsius) + 32");
|
||||
|
||||
// wait a second before reading again:
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
@ -111,6 +111,15 @@ boolean _Esplora::readButton(byte ch) {
|
||||
return (val > 512) ? HIGH : LOW;
|
||||
}
|
||||
|
||||
boolean _Esplora::readJoystickButton() {
|
||||
if (readChannel(CH_JOYSTICK_SW) == 1023) {
|
||||
return HIGH;
|
||||
} else if (readChannel(CH_JOYSTICK_SW) == 0) {
|
||||
return LOW;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void _Esplora::writeRGB(byte r, byte g, byte b) {
|
||||
writeRed(r);
|
||||
writeGreen(g);
|
||||
|
@ -21,7 +21,7 @@
|
||||
#ifndef ESPLORA_H_
|
||||
#define ESPLORA_H_
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
/*
|
||||
* The following constants are used internally by the Esplora
|
||||
@ -141,6 +141,8 @@ public:
|
||||
* LOW if the button is pressed, and HIGH otherwise.
|
||||
*/
|
||||
boolean readButton(byte channel);
|
||||
|
||||
boolean readJoystickButton();
|
||||
|
||||
void writeRGB(byte red, byte green, byte blue);
|
||||
void writeRed(byte red);
|
||||
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
Esplora Pong
|
||||
|
||||
This sketch connects serially to a Processing sketch to control a Pong game.
|
||||
It sends the position of the slider and the states of three pushbuttons to the
|
||||
Processing sketch serially, separated by commas. The Processing sketch uses that
|
||||
data to control the graphics in the sketch.
|
||||
|
||||
The slider sets a paddle's height
|
||||
Switch 1 is resets the game
|
||||
Switch 2 resets the ball to the center
|
||||
Switch 3 reverses the players
|
||||
|
||||
You can play this game with one or two Esploras.
|
||||
|
||||
Created on 22 Dec 2012
|
||||
by Tom Igoe
|
||||
|
||||
This example is in the public domain.
|
||||
*/
|
||||
|
||||
#include <Esplora.h>
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600); // initialize serial communication
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the slider and three of the buttons
|
||||
int slider = Esplora.readSlider();
|
||||
int resetButton = Esplora.readButton(SWITCH_1);
|
||||
int serveButton = Esplora.readButton(SWITCH_3);
|
||||
int switchPlayerButton = Esplora.readButton(SWITCH_4);
|
||||
|
||||
Serial.print(slider); // print the slider value
|
||||
Serial.print(","); // add a comma
|
||||
Serial.print(resetButton); // print the reset button value
|
||||
Serial.print(","); // add another comma
|
||||
Serial.print(serveButton); // print the serve button value
|
||||
Serial.print(","); // add another comma
|
||||
Serial.println(switchPlayerButton); // print the last button with a newline
|
||||
delay(10); // delay before sending the next set
|
||||
}
|
||||
|
@ -0,0 +1,116 @@
|
||||
/*
|
||||
Esplora Remote
|
||||
|
||||
This sketch allows to test all the Esplora's peripherals.
|
||||
It is also used with the ProcessingStart sketch (for Processing).
|
||||
|
||||
When uploaded, you can open the Serial monitor and write one of
|
||||
the following commands (without quotes) to get an answer:
|
||||
|
||||
"D": prints the current value of all sensors, separated by a comma.
|
||||
See the dumpInputs() function below to get the meaning of
|
||||
each value.
|
||||
|
||||
"Rxxx"
|
||||
"Gxxx"
|
||||
"Bxxx": set the color of the RGB led. For example, write "R255"
|
||||
to turn on the red to full brightness, "G128" to turn
|
||||
the green to half brightness, or "G0" to turn off
|
||||
the green channel.
|
||||
|
||||
"Txxxx": play a tone with the buzzer. The number is the
|
||||
frequency, e.g. "T440" plays the central A note.
|
||||
Write "T0" to turn off the buzzer.
|
||||
|
||||
|
||||
Created on 22 november 2012
|
||||
By Enrico Gueli <enrico.gueli@gmail.com>
|
||||
Modified 23 Dec 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
|
||||
#include <Esplora.h>
|
||||
|
||||
void setup() {
|
||||
while(!Serial); // needed for Leonardo-based board like Esplora
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (Serial.available())
|
||||
parseCommand();
|
||||
}
|
||||
|
||||
/*
|
||||
* This function reads a character from the serial line and
|
||||
* decide what to do next. The "what to do" part is given by
|
||||
* function it calls (e.g. dumpInputs(), setRed() and so on).
|
||||
*/
|
||||
void parseCommand() {
|
||||
char cmd = Serial.read();
|
||||
switch(cmd) {
|
||||
case 'D':
|
||||
dumpInputs();
|
||||
break;
|
||||
case 'R':
|
||||
setRed();
|
||||
break;
|
||||
case 'G':
|
||||
setGreen();
|
||||
break;
|
||||
case 'B':
|
||||
setBlue();
|
||||
break;
|
||||
case 'T':
|
||||
setTone();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void dumpInputs() {
|
||||
Serial.print(Esplora.readButton(SWITCH_1));
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readButton(SWITCH_2));
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readButton(SWITCH_3));
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readButton(SWITCH_4));
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readSlider());
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readLightSensor());
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readTemperature(DEGREES_C));
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readMicrophone());
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readJoystickSwitch());
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readJoystickX());
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readJoystickY());
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readAccelerometer(X_AXIS));
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readAccelerometer(Y_AXIS));
|
||||
Serial.print(',');
|
||||
Serial.print(Esplora.readAccelerometer(Z_AXIS));
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void setRed() {
|
||||
Esplora.writeRed(Serial.parseInt());
|
||||
}
|
||||
|
||||
void setGreen() {
|
||||
Esplora.writeGreen(Serial.parseInt());
|
||||
}
|
||||
|
||||
void setBlue() {
|
||||
Esplora.writeBlue(Serial.parseInt());
|
||||
}
|
||||
|
||||
void setTone() {
|
||||
Esplora.tone(Serial.parseInt());
|
||||
}
|
||||
|
@ -1,17 +1,16 @@
|
||||
/*
|
||||
Esplora Table
|
||||
|
||||
Acts like a keyboard that prints some of its sensors'
|
||||
Acts like a keyboard that prints sensor
|
||||
data in a table-like text, row by row.
|
||||
It is a sort of "data-logger".
|
||||
|
||||
At startup, it does nothing. It just waits for you to open a
|
||||
spreadsheet (e.g. Google Drive spreadsheet) so it can put its
|
||||
data. Then, by pressing Switch 1, it starts printing the table
|
||||
At startup, it does nothing. It waits for you to open a
|
||||
spreadsheet (e.g. Google Drive spreadsheet) so it can write
|
||||
data. By pressing Switch 1, it starts printing the table
|
||||
headers and the first row of data. It waits a bit, then it
|
||||
will print another row, and so on.
|
||||
|
||||
The amount of time between each row is given by the slider.
|
||||
The amount of time between each row is determined by the slider.
|
||||
If put to full left, the sketch will wait 10 seconds; at
|
||||
full right position, it will wait 5 minutes. An intermediate
|
||||
position will make the sketch wait for some time in-between.
|
||||
@ -175,17 +174,12 @@ void logAndPrint() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to delay(), but allows to do something else
|
||||
* in the meanwhile. In particular, it calls waitLoop().
|
||||
* Similar to delay(), but allows the program to do something else
|
||||
* in the meanwhile. In particular, it calls checkSwitchPress().
|
||||
* Note 1: it may wait longer than the specified amount, not less;
|
||||
* Note 2: beware of data synchronization issues, e.g. if the
|
||||
* whileWaiting() function alters some variables used by the
|
||||
* activeDelay() function alters some variables used by the
|
||||
* caller of this function.
|
||||
*
|
||||
* I discovered by chance that there's an ongoing discussion about
|
||||
* adding yield() in the Arduino API:
|
||||
* http://comments.gmane.org/gmane.comp.hardware.arduino.devel/1381
|
||||
* The purpose is the same, but for now I'm using this implementation.
|
||||
*/
|
||||
void activeDelay(unsigned long amount) {
|
||||
unsigned long at = millis() + amount;
|
@ -1,94 +0,0 @@
|
||||
/*
|
||||
Esplora Slave
|
||||
|
||||
This sketch allows to test all the Esplora's peripherals.
|
||||
It is also used with the ProcessingStart sketch (for Processing).
|
||||
|
||||
When uploaded, you can open the Serial monitor and write one of
|
||||
the following commands (without quotes) to get an answer:
|
||||
|
||||
"D": prints the current value of all sensors, separated by a comma.
|
||||
See the dumpInputs() function below to get the meaning of
|
||||
each value.
|
||||
|
||||
"Rxxx"
|
||||
"Gxxx"
|
||||
"Bxxx": set the color of the RGB led. For example, write "R255"
|
||||
to turn on the red to full brightness, "G128" to turn
|
||||
the green to half brightness, or "G0" to turn off
|
||||
the green channel.
|
||||
|
||||
"Txxxx": play a tone with the buzzer. The number is the
|
||||
frequency, e.g. "T440" plays the central A note.
|
||||
Write "T0" to turn off the buzzer.
|
||||
|
||||
|
||||
Created on 22 november 2012
|
||||
By Enrico Gueli <enrico.gueli@gmail.com>
|
||||
*/
|
||||
|
||||
#include <Esplora.h>
|
||||
|
||||
void setup() {
|
||||
while(!Serial); // needed for Leonardo-based board like Esplora
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (Serial.available())
|
||||
parseCommand();
|
||||
}
|
||||
|
||||
/*
|
||||
* This function reads a character from the serial line and
|
||||
* decide what to do next. The "what to do" part is given by
|
||||
* function it calls (e.g. dumpInputs(), setRed() and so on).
|
||||
*/
|
||||
void parseCommand() {
|
||||
char cmd = Serial.read();
|
||||
switch(cmd) {
|
||||
case 'D': dumpInputs(); break;
|
||||
case 'R': setRed(); break;
|
||||
case 'G': setGreen(); break;
|
||||
case 'B': setBlue(); break;
|
||||
case 'T': setTone(); break;
|
||||
}
|
||||
}
|
||||
|
||||
void dumpInputs() {
|
||||
/*
|
||||
* please note: a single row contains two instructions.
|
||||
* one is to print the sensor value, the other to print the
|
||||
* comma symbol.
|
||||
*/
|
||||
Serial.print(Esplora.readButton(SWITCH_1)); Serial.print(',');
|
||||
Serial.print(Esplora.readButton(SWITCH_2)); Serial.print(',');
|
||||
Serial.print(Esplora.readButton(SWITCH_3)); Serial.print(',');
|
||||
Serial.print(Esplora.readButton(SWITCH_4)); Serial.print(',');
|
||||
Serial.print(Esplora.readSlider()); Serial.print(',');
|
||||
Serial.print(Esplora.readLightSensor()); Serial.print(',');
|
||||
Serial.print(Esplora.readTemperature(DEGREES_C)); Serial.print(',');
|
||||
Serial.print(Esplora.readMicrophone()); Serial.print(',');
|
||||
Serial.print(Esplora.readJoystickSwitch()); Serial.print(',');
|
||||
Serial.print(Esplora.readJoystickX()); Serial.print(',');
|
||||
Serial.print(Esplora.readJoystickY()); Serial.print(',');
|
||||
Serial.print(Esplora.readAccelerometer(X_AXIS)); Serial.print(',');
|
||||
Serial.print(Esplora.readAccelerometer(Y_AXIS)); Serial.print(',');
|
||||
Serial.print(Esplora.readAccelerometer(Z_AXIS)); Serial.println();
|
||||
}
|
||||
|
||||
void setRed() {
|
||||
Esplora.writeRed(Serial.parseInt());
|
||||
}
|
||||
|
||||
void setGreen() {
|
||||
Esplora.writeGreen(Serial.parseInt());
|
||||
}
|
||||
|
||||
void setBlue() {
|
||||
Esplora.writeBlue(Serial.parseInt());
|
||||
}
|
||||
|
||||
void setTone() {
|
||||
Esplora.tone(Serial.parseInt());
|
||||
}
|
@ -16,6 +16,7 @@ readLightSensor KEYWORD2
|
||||
readTemperature KEYWORD2
|
||||
readMicrophone KEYWORD2
|
||||
readJoystickSwitch KEYWORD2
|
||||
readJoystickButton KEYWORD2
|
||||
readJoystickX KEYWORD2
|
||||
readJoystickY KEYWORD2
|
||||
readAccelerometer KEYWORD2
|
||||
|
@ -43,6 +43,7 @@ int DhcpClass::request_DHCP_lease(){
|
||||
_dhcpTransactionId = random(1UL, 2000UL);
|
||||
_dhcpInitialTransactionId = _dhcpTransactionId;
|
||||
|
||||
_dhcpUdpSocket.stop();
|
||||
if (_dhcpUdpSocket.begin(DHCP_CLIENT_PORT) == 0)
|
||||
{
|
||||
// Couldn't get a socket
|
||||
|
@ -10,7 +10,8 @@ uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = {
|
||||
|
||||
int EthernetClass::begin(uint8_t *mac_address)
|
||||
{
|
||||
_dhcp = new DhcpClass();
|
||||
static DhcpClass s_dhcp;
|
||||
_dhcp = &s_dhcp;
|
||||
|
||||
|
||||
// Initialise the basic info
|
||||
|
@ -63,7 +63,7 @@ void loop() {
|
||||
// send a standard http response header
|
||||
client.println("HTTP/1.1 200 OK");
|
||||
client.println("Content-Type: text/html");
|
||||
client.println("Connnection: close");
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
client.println("<!DOCTYPE HTML>");
|
||||
client.println("<html>");
|
||||
|
@ -245,7 +245,7 @@ void FirmataClass::processInput(void)
|
||||
break;
|
||||
case REPORT_ANALOG:
|
||||
case REPORT_DIGITAL:
|
||||
waitForData = 1; // two data bytes needed
|
||||
waitForData = 1; // one data byte needed
|
||||
executeMultiByteCommand = command;
|
||||
break;
|
||||
case START_SYSEX:
|
||||
|
@ -76,7 +76,7 @@ void loop() {
|
||||
// send a standard http response header
|
||||
client.println("HTTP/1.1 200 OK");
|
||||
client.println("Content-Type: text/html");
|
||||
client.println("Connnection: close");
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
client.println("<!DOCTYPE HTML>");
|
||||
client.println("<html>");
|
||||
|
@ -1,140 +0,0 @@
|
||||
/* ----------------------------------------------------------------------------
|
||||
* ATMEL Microcontroller Software Support
|
||||
* ----------------------------------------------------------------------------
|
||||
* 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:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the disclaimer below.
|
||||
*
|
||||
* Atmel's name may not be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* DISCLAIMER: 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
|
||||
* 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.
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Linker script for running in internal FLASH on the ATSAM3S4
|
||||
*----------------------------------------------------------------------------*/
|
||||
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
SEARCH_DIR(.)
|
||||
|
||||
/* Memory Spaces Definitions */
|
||||
MEMORY
|
||||
{
|
||||
rom (rx) : ORIGIN = 0x00400000, LENGTH = 0x00040000 /* flash, 256K */
|
||||
ram (rwx) : ORIGIN = 0x20000000, LENGTH = 0x0000c000 /* sram, 48K */
|
||||
}
|
||||
|
||||
/* Section Definitions */
|
||||
SECTIONS
|
||||
{
|
||||
.text :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sfixed = .;
|
||||
KEEP(*(.vectors .vectors.*))
|
||||
*(.text .text.* .gnu.linkonce.t.*)
|
||||
*(.glue_7t) *(.glue_7)
|
||||
*(.rodata .rodata* .gnu.linkonce.r.*)
|
||||
*(.ARM.extab* .gnu.linkonce.armextab.*)
|
||||
|
||||
/* Support C constructors, and C destructors in both user code
|
||||
and the C library. This also provides support for C++ code. */
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.init))
|
||||
. = ALIGN(4);
|
||||
__preinit_array_start = .;
|
||||
KEEP (*(.preinit_array))
|
||||
__preinit_array_end = .;
|
||||
|
||||
. = ALIGN(4);
|
||||
__init_array_start = .;
|
||||
KEEP (*(SORT(.init_array.*)))
|
||||
KEEP (*(.init_array))
|
||||
__init_array_end = .;
|
||||
|
||||
. = ALIGN(0x4);
|
||||
KEEP (*crtbegin.o(.ctors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
|
||||
KEEP (*(SORT(.ctors.*)))
|
||||
KEEP (*crtend.o(.ctors))
|
||||
|
||||
. = ALIGN(4);
|
||||
KEEP(*(.fini))
|
||||
|
||||
. = ALIGN(4);
|
||||
__fini_array_start = .;
|
||||
KEEP (*(.fini_array))
|
||||
KEEP (*(SORT(.fini_array.*)))
|
||||
__fini_array_end = .;
|
||||
|
||||
KEEP (*crtbegin.o(.dtors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
|
||||
KEEP (*(SORT(.dtors.*)))
|
||||
KEEP (*crtend.o(.dtors))
|
||||
|
||||
. = ALIGN(4);
|
||||
_efixed = .; /* End of text section */
|
||||
} > rom
|
||||
|
||||
/* .ARM.exidx is sorted, so has to go in its own output section. */
|
||||
PROVIDE_HIDDEN (__exidx_start = .);
|
||||
.ARM.exidx :
|
||||
{
|
||||
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
|
||||
} > rom
|
||||
PROVIDE_HIDDEN (__exidx_end = .);
|
||||
|
||||
. = ALIGN(4);
|
||||
_etext = .;
|
||||
|
||||
.relocate : AT (_etext)
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_srelocate = .;
|
||||
*(.ramfunc .ramfunc.*);
|
||||
*(.data .data.*);
|
||||
. = ALIGN(4);
|
||||
_erelocate = .;
|
||||
} > ram
|
||||
|
||||
/* .bss section which is used for uninitialized data */
|
||||
.bss (NOLOAD) :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
_sbss = . ;
|
||||
_szero = .;
|
||||
*(.bss .bss.*)
|
||||
*(COMMON)
|
||||
. = ALIGN(4);
|
||||
_ebss = . ;
|
||||
_ezero = .;
|
||||
} > ram
|
||||
|
||||
/* stack section */
|
||||
.stack (NOLOAD):
|
||||
{
|
||||
. = ALIGN(8);
|
||||
*(.stack .stack.*)
|
||||
} > ram
|
||||
|
||||
. = ALIGN(4);
|
||||
_end = . ;
|
||||
}
|
@ -157,7 +157,7 @@ void Serial_::accept(void)
|
||||
{
|
||||
ring_buffer *buffer = &cdc_rx_buffer;
|
||||
uint32_t c = USBD_Recv(CDC_RX);
|
||||
uint32_t i = (uint32_t)(buffer->head+1) % SERIAL_BUFFER_SIZE;
|
||||
uint32_t i = (uint32_t)(buffer->head+1) % CDC_SERIAL_BUFFER_SIZE;
|
||||
|
||||
// if we should be storing the received character into the location
|
||||
// just before the tail (meaning that the head would advance to the
|
||||
@ -172,7 +172,7 @@ void Serial_::accept(void)
|
||||
int Serial_::available(void)
|
||||
{
|
||||
ring_buffer *buffer = &cdc_rx_buffer;
|
||||
return (unsigned int)(SERIAL_BUFFER_SIZE + buffer->head - buffer->tail) % SERIAL_BUFFER_SIZE;
|
||||
return (unsigned int)(CDC_SERIAL_BUFFER_SIZE + buffer->head - buffer->tail) % CDC_SERIAL_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
int Serial_::peek(void)
|
||||
@ -201,7 +201,7 @@ int Serial_::read(void)
|
||||
else
|
||||
{
|
||||
unsigned char c = buffer->buffer[buffer->tail];
|
||||
buffer->tail = (unsigned int)(buffer->tail + 1) % SERIAL_BUFFER_SIZE;
|
||||
buffer->tail = (unsigned int)(buffer->tail + 1) % CDC_SERIAL_BUFFER_SIZE;
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
@ -199,6 +199,7 @@ uint32_t USBD_Send(uint32_t ep, const void* d, uint32_t len)
|
||||
len -= n;
|
||||
|
||||
UDD_Send(ep & 0xF, data, n);
|
||||
data += n;
|
||||
}
|
||||
//TXLED1; // light the TX LED
|
||||
//TxLEDPulse = TX_RX_LED_PULSE_MS;
|
||||
|
@ -243,8 +243,8 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue) {
|
||||
|
||||
// Write user value
|
||||
ulValue = mapResolution(ulValue, _writeResolution, DACC_RESOLUTION);
|
||||
while ((dacc_get_interrupt_status(DACC_INTERFACE) & DACC_ISR_TXRDY) == 0);
|
||||
dacc_write_conversion_data(DACC_INTERFACE, ulValue);
|
||||
while ((dacc_get_interrupt_status(DACC_INTERFACE) & DACC_ISR_EOC) == 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ int DhcpClass::request_DHCP_lease(){
|
||||
_dhcpTransactionId = random(1UL, 2000UL);
|
||||
_dhcpInitialTransactionId = _dhcpTransactionId;
|
||||
|
||||
_dhcpUdpSocket.stop();
|
||||
if (_dhcpUdpSocket.begin(DHCP_CLIENT_PORT) == 0)
|
||||
{
|
||||
// Couldn't get a socket
|
||||
|
@ -10,7 +10,9 @@ uint16_t EthernetClass::_server_port[MAX_SOCK_NUM] = {
|
||||
|
||||
int EthernetClass::begin(uint8_t *mac_address)
|
||||
{
|
||||
_dhcp = new DhcpClass();
|
||||
static DhcpClass s_dhcp;
|
||||
_dhcp = &s_dhcp;
|
||||
|
||||
|
||||
// Initialise the basic info
|
||||
W5100.init();
|
||||
@ -59,7 +61,6 @@ void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dn
|
||||
void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)
|
||||
{
|
||||
W5100.init();
|
||||
|
||||
W5100.setMACAddress(mac);
|
||||
W5100.setIPAddress(local_ip._address);
|
||||
W5100.setGatewayIp(gateway._address);
|
||||
|
@ -63,7 +63,7 @@ void loop() {
|
||||
// send a standard http response header
|
||||
client.println("HTTP/1.1 200 OK");
|
||||
client.println("Content-Type: text/html");
|
||||
client.println("Connnection: close");
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
client.println("<!DOCTYPE HTML>");
|
||||
client.println("<html>");
|
||||
|
@ -63,15 +63,15 @@ void mousePressed() {
|
||||
// This function intercepts mouse button release
|
||||
void mouseReleased() {
|
||||
Serial.print("Released: ");
|
||||
if (!mouse.getButton(LEFT_BUTTON) && left==true) {
|
||||
if (!mouse.getButton(LEFT_BUTTON) && leftButton == true) {
|
||||
Serial.print("L");
|
||||
leftButton = false;
|
||||
}
|
||||
if (!mouse.getButton(MIDDLE_BUTTON) && middle==true) {
|
||||
if (!mouse.getButton(MIDDLE_BUTTON) && middleButton == true) {
|
||||
Serial.print("M");
|
||||
middleButton = false;
|
||||
}
|
||||
if (!mouse.getButton(RIGHT_BUTTON) && right==true) {
|
||||
if (!mouse.getButton(RIGHT_BUTTON) && rightButton == true) {
|
||||
Serial.print("R");
|
||||
rightButton = false;
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ void loop() {
|
||||
// send a standard http response header
|
||||
client.println("HTTP/1.1 200 OK");
|
||||
client.println("Content-Type: text/html");
|
||||
client.println("Connnection: close");
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
client.println("<!DOCTYPE HTML>");
|
||||
client.println("<html>");
|
||||
|
@ -15,16 +15,11 @@ extern "C" {
|
||||
#define SLAVEREADY 7 // handshake pin
|
||||
#define WIFILED 9 // led on wifi shield
|
||||
|
||||
#define DELAY_100NS do { asm volatile("nop"); }while(0);
|
||||
#define DELAY_SPI(X) { int ii=0; do { asm volatile("nop"); }while(++ii<X);}
|
||||
#define DELAY_SPI(X) { int ii=0; do { asm volatile("nop"); } while (++ii < X*6); }
|
||||
#define DELAY_TRANSFER() DELAY_SPI(10)
|
||||
|
||||
void SpiDrv::begin()
|
||||
{
|
||||
// pinMode(SCK, OUTPUT);
|
||||
// pinMode(MOSI, OUTPUT);
|
||||
// pinMode(SS, OUTPUT);
|
||||
|
||||
SPI.begin();
|
||||
pinMode(SLAVESELECT, OUTPUT);
|
||||
pinMode(SLAVEREADY, INPUT);
|
||||
@ -69,11 +64,6 @@ void SpiDrv::spiSlaveDeselect()
|
||||
char SpiDrv::spiTransfer(volatile char data)
|
||||
{
|
||||
char result = SPI.transfer(data);
|
||||
// SPDR = data; // Start the transmission
|
||||
// while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
|
||||
// {
|
||||
// };
|
||||
// char result = SPDR;
|
||||
DELAY_TRANSFER();
|
||||
|
||||
return result; // return the received byte
|
||||
|
Reference in New Issue
Block a user