Skip to content

Commit

Permalink
Merge pull request #23 from soburi/samdupdate
Browse files Browse the repository at this point in the history
Cache up base source updating until SAMD-1.6.9
  • Loading branch information
soburi authored Oct 22, 2016
2 parents 3817a9b + ec615a4 commit 61e44ef
Show file tree
Hide file tree
Showing 12 changed files with 149 additions and 18 deletions.
6 changes: 6 additions & 0 deletions cores/arduino/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ typedef uint16_t word;
//
#include "avr/pgmspace.h"
#include "avr/interrupt.h"
#include "avr/io.h"

#include "binary.h"
#include "itoa.h"
Expand Down Expand Up @@ -114,6 +115,11 @@ void loop( void ) ;

#define bit(b) (1UL << (b))

#if (ARDUINO_SAMD_VARIANT_COMPLIANCE >= 10606)
// Interrupts
#define digitalPinToInterrupt(P) ( P )
#endif

// USB Device
#include "USB/USBDesc.h"
#include "USB/USBCore.h"
Expand Down
2 changes: 1 addition & 1 deletion cores/arduino/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ size_t Print::printFloat(double number, uint8_t digits)
while (digits-- > 0)
{
remainder *= 10.0;
int toPrint = int(remainder);
unsigned int toPrint = (unsigned int)remainder;
n += print(toPrint);
remainder -= toPrint;
}
Expand Down
3 changes: 2 additions & 1 deletion cores/arduino/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class Stream : public Print
// parsing methods

void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second

unsigned long getTimeout(void) { return _timeout; }

bool find(char *target); // reads data from the stream until the target string is found
bool find(uint8_t *target) { return find ((char *)target); }
// returns true if target string is found, false if timed out (see setTimeout)
Expand Down
5 changes: 5 additions & 0 deletions cores/arduino/Uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ int Uart::available()
return (uint32_t)(SERIAL_BUFFER_SIZE + rxBuffer._iHead - rxBuffer._iTail) % SERIAL_BUFFER_SIZE;
}

int Uart::availableForWrite()
{
return 0; //TODO
}

int Uart::peek()
{
return rxBuffer.peek();
Expand Down
1 change: 1 addition & 0 deletions cores/arduino/Uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Uart : public HardwareSerial
void begin(unsigned long baudrate, uint32_t config);
void end();
int available();
int availableForWrite();
int peek();
int read();
void flush();
Expand Down
9 changes: 7 additions & 2 deletions cores/arduino/WString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ String & String::copy(const __FlashStringHelper *pstr, unsigned int length)
void String::move(String &rhs)
{
if (buffer) {
if (capacity >= rhs.len) {
if (rhs && capacity >= rhs.len) {
strcpy(buffer, rhs.buffer);
len = rhs.len;
rhs.len = 0;
Expand Down Expand Up @@ -742,6 +742,11 @@ long String::toInt(void) const

float String::toFloat(void) const
{
if (buffer) return float(atof(buffer));
return float(toDouble());
}

double String::toDouble(void) const
{
if (buffer) return atof(buffer);
return 0;
}
19 changes: 12 additions & 7 deletions cores/arduino/WString.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class String
inline unsigned int length(void) const {return len;}

// creates a copy of the assigned value. if the value is null or
// invalid, or if the memory allocation fails, the string will be
// invalid, or if the memory allocation fails, the string will be
// marked as invalid ("if (s)" will be false).
String & operator = (const String &rhs);
String & operator = (const char *cstr);
Expand All @@ -92,10 +92,10 @@ class String
#endif

// concatenate (works w/ built-in types)

// returns true on success, false on failure (in which case, the string
// is left unchanged). if the argument is null or invalid, the
// concatenation is considered unsucessful.
// is left unchanged). if the argument is null or invalid, the
// concatenation is considered unsucessful.
unsigned char concat(const String &str);
unsigned char concat(const char *cstr);
unsigned char concat(char c);
Expand All @@ -107,7 +107,7 @@ class String
unsigned char concat(float num);
unsigned char concat(double num);
unsigned char concat(const __FlashStringHelper * str);

// if there's not enough memory for the concatenated value, the string
// will be left unchanged (but this isn't signalled in any way)
String & operator += (const String &rhs) {concat(rhs); return (*this);}
Expand Down Expand Up @@ -159,8 +159,12 @@ class String
char& operator [] (unsigned int index);
void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const;
void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const
{getBytes((unsigned char *)buf, bufsize, index);}
const char * c_str() const { return buffer; }
{ getBytes((unsigned char *)buf, bufsize, index); }
const char* c_str() const { return buffer; }
char* begin() { return buffer; }
char* end() { return buffer + length(); }
const char* begin() const { return c_str(); }
const char* end() const { return c_str() + length(); }

// search
int indexOf( char ch ) const;
Expand All @@ -186,6 +190,7 @@ class String
// parsing/conversion
long toInt(void) const;
float toFloat(void) const;
double toDouble(void) const;

protected:
char *buffer; // the actual char array
Expand Down
7 changes: 4 additions & 3 deletions cores/arduino/avr/dtostrf.h
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
dtostrf - Emulation for dtostrf function from avr-libc
Copyright (c) 2013 Arduino. All rights reserved.
Written by Cristian Maglie <[email protected]>
Copyright (c) 2015 Arduino LLC. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand All @@ -18,11 +17,13 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

char *dtostrf (double val, signed char width, unsigned char prec, char *sout);
char *dtostrf(double val, signed char width, unsigned char prec, char *sout);

#ifdef __cplusplus
}
Expand Down
23 changes: 23 additions & 0 deletions cores/arduino/avr/interrupt.h
100644 → 100755
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
Copyright (c) 2015 Arduino LCC. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

/*
Empty file.
This file is here to allow compatibility with sketches (made for AVR)
that includes <AVR/interrupt.h>
*/
32 changes: 32 additions & 0 deletions cores/arduino/avr/io.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
io.h - Definitions for compatibility with AVR io macros
Copyright (c) 2016 Arduino LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE
*/

#ifndef _IO_H_
#define _IO_H_

#define RAMSTART (HMCRAMC0_ADDR)
#define RAMSIZE (HMCRAMC0_SIZE)
#define RAMEND (RAMSTART + RAMSIZE - 1)

#endif
58 changes: 55 additions & 3 deletions cores/arduino/avr/pgmspace.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,79 @@ typedef int16_t prog_int16_t;
typedef uint16_t prog_uint16_t;
typedef int32_t prog_int32_t;
typedef uint32_t prog_uint32_t;
typedef int64_t prog_int64_t;
typedef uint64_t prog_uint64_t;

#define memcpy_P(dest, src, num) memcpy((dest), (src), (num))
#define strcpy_P(dest, src) strcpy((dest), (src))
typedef const void* int_farptr_t;
typedef const void* uint_farptr_t;

#define memchr_P(s, c, n) memchr((s), (c), (n))
#define memcmp_P(s1, s2, n) memcmp((s1), (s2), (n))
#define memccpy_P(dest, src, c, n) memccpy((dest), (src), (c), (n))
#define memcpy_P(dest, src, n) memcpy((dest), (src), (n))
#define memmem_P(haystack, haystacklen, needle, needlelen) memmem((haystack), (haystacklen), (needle), (needlelen))
#define memrchr_P(s, c, n) memrchr((s), (c), (n))
#define strcat_P(dest, src) strcat((dest), (src))
#define strchr_P(s, c) strchr((s), (c))
#define strchrnul_P(s, c) strchrnul((s), (c))
#define strcmp_P(a, b) strcmp((a), (b))
#define strstr_P(a, b) strstr((a), (b))
#define strcpy_P(dest, src) strcpy((dest), (src))
#define strcasecmp_P(s1, s2) strcasecmp((s1), (s2))
#define strcasestr_P(haystack, needle) strcasestr((haystack), (needle))
#define strcspn_P(s, accept) strcspn((s), (accept))
#define strlcat_P(s1, s2, n) strlcat((s1), (s2), (n))
#define strlcpy_P(s1, s2, n) strlcpy((s1), (s2), (n))
#define strlen_P(a) strlen((a))
#define strnlen_P(s, n) strnlen((s), (n))
#define strncmp_P(s1, s2, n) strncmp((s1), (s2), (n))
#define strncasecmp_P(s1, s2, n) strncasecmp((s1), (s2), (n))
#define strncat_P(s1, s2, n) strncat((s1), (s2), (n))
#define strncpy_P(s1, s2, n) strncpy((s1), (s2), (n))
#define strpbrk_P(s, accept) strpbrk((s), (accept))
#define strrchr_P(s, c) strrchr((s), (c))
#define strsep_P(sp, delim) strsep((sp), (delim))
#define strspn_P(s, accept) strspn((s), (accept))
#define strstr_P(a, b) strstr((a), (b))
#define strtok_P(s, delim) strtok((s), (delim))
#define strtok_rP(s, delim, last) strtok((s), (delim), (last))

#define strlen_PF(a) strlen((a))
#define strnlen_PF(src, len) strnlen((src), (len))
#define memcpy_PF(dest, src, len) memcpy((dest), (src), (len))
#define strcpy_PF(dest, src) strcpy((dest), (src))
#define strncpy_PF(dest, src, len) strncpy((dest), (src), (len))
#define strcat_PF(dest, src) strcat((dest), (src))
#define strlcat_PF(dest, src, len) strlcat((dest), (src), (len))
#define strncat_PF(dest, src, len) strncat((dest), (src), (len))
#define strcmp_PF(s1, s2) strcmp((s1), (s2))
#define strncmp_PF(s1, s2, n) strncmp((s1), (s2), (n))
#define strcasecmp_PF(s1, s2) strcasecmp((s1), (s2))
#define strncasecmp_PF(s1, s2, n) strncasecmp((s1), (s2), (n))
#define strstr_PF(s1, s2) strstr((s1), (s2))
#define strlcpy_PF(dest, src, n) strlcpy((dest), (src), (n))
#define memcmp_PF(s1, s2, n) memcmp((s1), (s2), (n))

#define sprintf_P(s, f, ...) sprintf((s), (f), __VA_ARGS__)
#define snprintf_P(s, f, ...) snprintf((s), (f), __VA_ARGS__)

#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
#define pgm_read_word(addr) (*(const unsigned short *)(addr))
#define pgm_read_dword(addr) (*(const unsigned long *)(addr))
#define pgm_read_float(addr) (*(const float *)(addr))
#define pgm_read_ptr(addr) (*(const void *)(addr))

#define pgm_read_byte_near(addr) pgm_read_byte(addr)
#define pgm_read_word_near(addr) pgm_read_word(addr)
#define pgm_read_dword_near(addr) pgm_read_dword(addr)
#define pgm_read_float_near(addr) pgm_read_float(addr)
#define pgm_read_ptr_near(addr) pgm_read_ptr(addr)

#define pgm_read_byte_far(addr) pgm_read_byte(addr)
#define pgm_read_word_far(addr) pgm_read_word(addr)
#define pgm_read_dword_far(addr) pgm_read_dword(addr)
#define pgm_read_float_far(addr) pgm_read_float(addr)
#define pgm_read_ptr_far(addr) pgm_read_ptr(addr)

#define pgm_get_far_address(addr) (&(addr))

#endif
2 changes: 1 addition & 1 deletion cores/arduino/delay.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ extern uint32_t micros( void ) ;
*/
extern void delay( uint32_t dwMs ) ;

#ifndef OVERLOAD_DELAYMICROSECONDS
/**
* \brief Pauses the program for the amount of time (in microseconds) specified as parameter.
*
* \param dwUs the number of microseconds to pause (uint32_t)
*/
#ifndef OVERLOAD_DELAYMICROSECONDS
extern void delayMicroseconds( uint32_t usec );
#endif

Expand Down

0 comments on commit 61e44ef

Please sign in to comment.