Skip to content

Commit 6187c07

Browse files
committed
Merge branch 'zero' of github.com:arduino/ArduinoZero into zero
2 parents 6fc30bb + 5f849ab commit 6187c07

File tree

9 files changed

+161
-77
lines changed

9 files changed

+161
-77
lines changed

cores/arduino/SERCOM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ void SERCOM::initClockNVIC( void )
633633
clockId = GCM_SERCOM4_CORE;
634634
IdNvic = SERCOM4_IRQn;
635635
}
636-
else if(sercom == SERCOM5)
636+
else // if(sercom == SERCOM5)
637637
{
638638
clockId = GCM_SERCOM5_CORE;
639639
IdNvic = SERCOM5_IRQn;

cores/arduino/Server.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
2-
Copyright (c) 2014 Arduino. All right reserved.
2+
Server.h - Base class that provides Server
3+
Copyright (c) 2011 Adrian McEwen. All right reserved.
34
45
This library is free software; you can redistribute it and/or
56
modify it under the terms of the GNU Lesser General Public
@@ -8,8 +9,8 @@
89
910
This library is distributed in the hope that it will be useful,
1011
but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12-
See the GNU Lesser General Public License for more details.
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
1314
1415
You should have received a copy of the GNU Lesser General Public
1516
License along with this library; if not, write to the Free Software
@@ -19,6 +20,8 @@
1920
#ifndef server_h
2021
#define server_h
2122

23+
#include "Print.h"
24+
2225
class Server : public Print {
2326
public:
2427
virtual void begin() =0;

cores/arduino/USB/USBCore.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ uint32_t USBD_Available(uint32_t ep)
105105
// Return number of bytes read
106106
uint32_t USBD_Recv(uint32_t ep, void* d, uint32_t len)
107107
{
108-
if (!_usbConfiguration || len < 0)
108+
if (!_usbConfiguration)
109109
return -1;
110110

111111
uint32_t n = UDD_FifoByteCount(ep);
@@ -200,8 +200,8 @@ uint32_t USBD_RecvControl(void* d, uint32_t len)
200200
if (read > len)
201201
read = len;
202202
UDD_Recv(EP0, &buffer);
203-
while (!udd_is_OUT_transf_cplt(EP0));
204-
for (int i=0; i<read; i++) {
203+
while (!udd_is_OUT_transf_cplt(EP0));
204+
for (uint32_t i=0; i<read; i++) {
205205
data[i] = buffer[i];
206206
}
207207
udd_OUT_transfer_allowed(EP0);

cores/arduino/WString.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
/*
2-
Copyright (c) 2014 Arduino. All right reserved.
2+
WString.cpp - String library for Wiring & Arduino
3+
...mostly rewritten by Paul Stoffregen...
4+
Copyright (c) 2009-10 Hernando Barragan. All rights reserved.
5+
Copyright 2011, Paul Stoffregen, [email protected]
36
47
This library is free software; you can redistribute it and/or
58
modify it under the terms of the GNU Lesser General Public
@@ -8,8 +11,8 @@
811
912
This library is distributed in the hope that it will be useful,
1013
but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12-
See the GNU Lesser General Public License for more details.
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
1316
1417
You should have received a copy of the GNU Lesser General Public
1518
License along with this library; if not, write to the Free Software
@@ -213,10 +216,10 @@ void String::move(String &rhs)
213216
String & String::operator = (const String &rhs)
214217
{
215218
if (this == &rhs) return *this;
216-
219+
217220
if (rhs.buffer) copy(rhs.buffer, rhs.len);
218221
else invalidate();
219-
222+
220223
return *this;
221224
}
222225

@@ -238,7 +241,7 @@ String & String::operator = (const char *cstr)
238241
{
239242
if (cstr) copy(cstr, strlen(cstr));
240243
else invalidate();
241-
244+
242245
return *this;
243246
}
244247

@@ -481,7 +484,7 @@ unsigned char String::equalsIgnoreCase( const String &s2 ) const
481484
const char *p2 = s2.buffer;
482485
while (*p1) {
483486
if (tolower(*p1++) != tolower(*p2++)) return 0;
484-
}
487+
}
485488
return 1;
486489
}
487490

@@ -512,7 +515,7 @@ char String::charAt(unsigned int loc) const
512515
return operator[](loc);
513516
}
514517

515-
void String::setCharAt(unsigned int loc, char c)
518+
void String::setCharAt(unsigned int loc, char c)
516519
{
517520
if (loc < len) buffer[loc] = c;
518521
}
@@ -618,10 +621,10 @@ String String::substring(unsigned int left, unsigned int right) const
618621
left = temp;
619622
}
620623
String out;
621-
if (left > len) return out;
624+
if (left >= len) return out;
622625
if (right > len) right = len;
623626
char temp = buffer[right]; // save the replaced character
624-
buffer[right] = '\0';
627+
buffer[right] = '\0';
625628
out = buffer + left; // pointer arithmetic
626629
buffer[right] = temp; //restore character
627630
return out;
@@ -683,15 +686,16 @@ void String::replace(const String& find, const String& replace)
683686
}
684687

685688
void String::remove(unsigned int index){
686-
if (index >= len) { return; }
687-
int count = len - index;
688-
remove(index, count);
689+
// Pass the biggest integer as the count. The remove method
690+
// below will take care of truncating it at the end of the
691+
// string.
692+
remove(index, (unsigned int)-1);
689693
}
690694

691695
void String::remove(unsigned int index, unsigned int count){
692696
if (index >= len) { return; }
693697
if (count <= 0) { return; }
694-
if (index + count > len) { count = len - index; }
698+
if (count > len - index) { count = len - index; }
695699
char *writeTo = buffer + index;
696700
len = len - count;
697701
strncpy(writeTo, buffer + index + count,len - index);

cores/arduino/wiring.c

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -92,46 +92,39 @@ void init( void )
9292

9393
// Initialize Analog Controller
9494
// Setting clock
95+
while(GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY);
96+
9597
GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID( GCM_ADC ) | // Generic Clock ADC
96-
GCLK_CLKCTRL_GEN_GCLK0 | // Generic Clock Generator 0 is source
98+
GCLK_CLKCTRL_GEN_GCLK0 | // Generic Clock Generator 0 is source
9799
GCLK_CLKCTRL_CLKEN ;
98100

99-
ADC->CTRLB.reg = ADC_CTRLB_PRESCALER_DIV128 | // Divide Clock by 512.
100-
ADC_CTRLB_RESSEL_10BIT; // Result on 10 bits
101+
while( ADC->STATUS.bit.SYNCBUSY == 1 ); // Wait for synchronization of registers between the clock domains
102+
103+
ADC->CTRLB.reg = ADC_CTRLB_PRESCALER_DIV512 | // Divide Clock by 512.
104+
ADC_CTRLB_RESSEL_10BIT; // 10 bits resolution as default
105+
106+
ADC->SAMPCTRL.reg = 0x3f; // Set max Sampling Time Length
107+
108+
while( ADC->STATUS.bit.SYNCBUSY == 1 ); // Wait for synchronization of registers between the clock domains
101109

102110
ADC->INPUTCTRL.reg = ADC_INPUTCTRL_MUXNEG_GND; // No Negative input (Internal Ground)
103111

104112
// Averaging (see table 31-2 p.816 datasheet)
105-
ADC->AVGCTRL.reg = ADC_AVGCTRL_SAMPLENUM_2 | // 2 samples
106-
ADC_AVGCTRL_ADJRES(0x01ul); // Adjusting result by 1
113+
ADC->AVGCTRL.reg = ADC_AVGCTRL_SAMPLENUM_64 | // 64 samples
114+
ADC_AVGCTRL_ADJRES(0x04ul); // Adjusting result by 4
107115

108116
analogReference( AR_DEFAULT ) ; // Analog Reference is AREF pin (3.3v)
109117

110-
ADC->CTRLA.bit.ENABLE = 1; // Enable ADC
111-
while( ADC->STATUS.bit.SYNCBUSY == 1 )
112-
{
113-
// Waiting for synchronization
114-
}
115-
116118
// Initialize DAC
117119
// Setting clock
120+
while ( GCLK->STATUS.reg & GCLK_STATUS_SYNCBUSY );
118121
GCLK->CLKCTRL.reg = GCLK_CLKCTRL_ID( GCM_DAC ) | // Generic Clock ADC
119-
GCLK_CLKCTRL_GEN_GCLK0 | // Generic Clock Generator 0 is source
122+
GCLK_CLKCTRL_GEN_GCLK0 | // Generic Clock Generator 0 is source
120123
GCLK_CLKCTRL_CLKEN ;
121124

122-
/* temporary DAC disable
125+
while ( DAC->STATUS.bit.SYNCBUSY == 1 ); // Wait for synchronization of registers between the clock domains
123126
DAC->CTRLB.reg = DAC_CTRLB_REFSEL_AVCC | // Using the 3.3V reference
124-
DAC_CTRLB_EOEN; // External Output Enable (Vout)
125-
DAC->DATA.reg = 0x3FFul;
126-
127-
// Enable DAC
128-
DAC->CTRLA.bit.ENABLE = 1;
129-
130-
while(DAC->STATUS.bit.SYNCBUSY != 0)
131-
{
132-
// Waiting for synchronization
133-
}
134-
*/
127+
DAC_CTRLB_EOEN ; // External Output Enable (Vout)
135128
}
136129

137130
#ifdef __cplusplus

0 commit comments

Comments
 (0)