Skip to content

Commit c47857f

Browse files
authored
Merge pull request #40 from sparkfun/samd_update_1.5.0
Samd update 1.5.0
2 parents c123ec4 + 005865b commit c47857f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+9301
-287
lines changed

IDE_Board_Manager/package_sparkfun_index.json

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,35 @@
542542
"version": "1.4.0"
543543
}
544544
]
545+
},
546+
{
547+
"name": "SparkFun SAMD Boards",
548+
"architecture": "samd",
549+
"version": "1.5.0",
550+
"category": "Contributed",
551+
"url": "https://github.com/sparkfun/Arduino_Boards/raw/master/IDE_Board_Manager/sparkfun-samd-1.5.0.tar.bz2",
552+
"archiveFileName": "sparkfun-samd-1.5.0.tar.bz2",
553+
"checksum": "SHA-256:0EC1574A319C1D561322C9E6FF1515B594956BC6B2CF6C92266F4D36684CBBF8",
554+
"size": "322453",
555+
"help": {
556+
"online": "https://learn.sparkfun.com/tutorials/installing-arduino-ide/board-add-ons-with-arduino-board-manager"
557+
},
558+
"boards": [
559+
{
560+
"name": "SparkFun SAMD21 Mini Breakout"
561+
},
562+
{
563+
"name": "SparkFun SAMD21 Dev Breakout"
564+
},
565+
{
566+
"name": "SparkFun 9DoF Razor IMU M0"
567+
},
568+
{
569+
"name": "LilyPad LilyMini"
570+
}
571+
],
572+
"toolsDependencies": [
573+
]
545574
}
546575
],
547576
"tools": [
@@ -575,7 +604,7 @@
575604
]
576605
},
577606
{
578-
"maintainer": "SparkFun Electronics",
607+
"maintainer": "SparkFun Electronics (dependency: Arduino SAMD Boards 1.6.19)",
579608
"help": {
580609
"online": "http://SparkFun.com"
581610
},
315 KB
Binary file not shown.

sparkfun/samd/boards.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ samd21_dev.build.core=arduino
3434
samd21_dev.build.extra_flags=-D__SAMD21G18A__ {build.usb_flags}
3535
samd21_dev.build.ldscript=linker_scripts/gcc/flash_with_bootloader.ld
3636
samd21_dev.build.openocdscript=openocd_scripts/arduino_zero.cfg
37-
samd21_dev.build.variant=arduino_zero
37+
samd21_dev.build.variant=SparkFun_SAMD21_Dev
3838
samd21_dev.build.variant_system_lib=
3939
samd21_dev.build.extra_combine_flags=
4040
samd21_dev.build.vid=0x1B4F

sparkfun/samd/cores/arduino/Print.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@ size_t Print::printFloat(double number, uint8_t digits)
238238

239239
// Print the decimal point, but only if there are digits beyond
240240
if (digits > 0) {
241-
n += print(".");
241+
n += print('.');
242242
}
243243

244244
// Extract digits from the remainder one at a time
245245
while (digits-- > 0)
246246
{
247247
remainder *= 10.0;
248-
unsigned int toPrint = (unsigned int)remainder;
248+
unsigned int toPrint = (unsigned int)(remainder);
249249
n += print(toPrint);
250250
remainder -= toPrint;
251251
}

sparkfun/samd/cores/arduino/Print.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
#define DEC 10
2929
#define HEX 16
3030
#define OCT 8
31+
#ifdef BIN // Prevent warnings if BIN is previously defined in "iotnx4.h" or similar
32+
#undef BIN
33+
#endif
3134
#define BIN 2
3235

3336
class Print
@@ -54,6 +57,10 @@ class Print
5457
return write((const uint8_t *)buffer, size);
5558
}
5659

60+
// default to zero, meaning "a single write may block"
61+
// should be overriden by subclasses with buffering
62+
virtual int availableForWrite() { return 0; }
63+
5764
size_t print(const __FlashStringHelper *);
5865
size_t print(const String &);
5966
size_t print(const char[]);
@@ -78,6 +85,8 @@ class Print
7885
size_t println(double, int = 2);
7986
size_t println(const Printable&);
8087
size_t println(void);
88+
89+
virtual void flush() { /* Empty implementation for backward compatibility */ }
8190
};
8291

8392
#endif

sparkfun/samd/cores/arduino/RingBuffer.cpp

Lines changed: 0 additions & 86 deletions
This file was deleted.

sparkfun/samd/cores/arduino/RingBuffer.h

Lines changed: 104 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1717
*/
1818

19+
#ifdef __cplusplus
20+
1921
#ifndef _RING_BUFFER_
2022
#define _RING_BUFFER_
2123

@@ -27,24 +29,114 @@
2729
// location from which to read.
2830
#define SERIAL_BUFFER_SIZE 64
2931

30-
class RingBuffer
32+
template <int N>
33+
class RingBufferN
3134
{
3235
public:
33-
uint8_t _aucBuffer[SERIAL_BUFFER_SIZE] ;
34-
int _iHead ;
35-
int _iTail ;
36+
uint8_t _aucBuffer[N] ;
37+
volatile int _iHead ;
38+
volatile int _iTail ;
3639

3740
public:
38-
RingBuffer( void ) ;
41+
RingBufferN( void ) ;
3942
void store_char( uint8_t c ) ;
40-
void clear();
41-
int read_char();
42-
int available();
43-
int peek();
44-
bool isFull();
43+
void clear();
44+
int read_char();
45+
int available();
46+
int availableForStore();
47+
int peek();
48+
bool isFull();
4549

4650
private:
47-
int nextIndex(int index);
48-
} ;
51+
int nextIndex(int index);
52+
};
53+
54+
typedef RingBufferN<SERIAL_BUFFER_SIZE> RingBuffer;
55+
56+
57+
template <int N>
58+
RingBufferN<N>::RingBufferN( void )
59+
{
60+
memset( _aucBuffer, 0, N ) ;
61+
clear();
62+
}
63+
64+
template <int N>
65+
void RingBufferN<N>::store_char( uint8_t c )
66+
{
67+
int i = nextIndex(_iHead);
68+
69+
// if we should be storing the received character into the location
70+
// just before the tail (meaning that the head would advance to the
71+
// current location of the tail), we're about to overflow the buffer
72+
// and so we don't write the character or advance the head.
73+
if ( i != _iTail )
74+
{
75+
_aucBuffer[_iHead] = c ;
76+
_iHead = i ;
77+
}
78+
}
79+
80+
template <int N>
81+
void RingBufferN<N>::clear()
82+
{
83+
_iHead = 0;
84+
_iTail = 0;
85+
}
86+
87+
template <int N>
88+
int RingBufferN<N>::read_char()
89+
{
90+
if(_iTail == _iHead)
91+
return -1;
92+
93+
uint8_t value = _aucBuffer[_iTail];
94+
_iTail = nextIndex(_iTail);
95+
96+
return value;
97+
}
98+
99+
template <int N>
100+
int RingBufferN<N>::available()
101+
{
102+
int delta = _iHead - _iTail;
103+
104+
if(delta < 0)
105+
return N + delta;
106+
else
107+
return delta;
108+
}
109+
110+
template <int N>
111+
int RingBufferN<N>::availableForStore()
112+
{
113+
if (_iHead >= _iTail)
114+
return N - 1 - _iHead + _iTail;
115+
else
116+
return _iTail - _iHead - 1;
117+
}
118+
119+
template <int N>
120+
int RingBufferN<N>::peek()
121+
{
122+
if(_iTail == _iHead)
123+
return -1;
124+
125+
return _aucBuffer[_iTail];
126+
}
127+
128+
template <int N>
129+
int RingBufferN<N>::nextIndex(int index)
130+
{
131+
return (uint32_t)(index + 1) % N;
132+
}
133+
134+
template <int N>
135+
bool RingBufferN<N>::isFull()
136+
{
137+
return (nextIndex(_iHead) == _iTail);
138+
}
49139

50140
#endif /* _RING_BUFFER_ */
141+
142+
#endif /* __cplusplus */

0 commit comments

Comments
 (0)