Skip to content

Commit 4e96c83

Browse files
committed
2 parents 51c271f + afae7a8 commit 4e96c83

File tree

138 files changed

+16195
-5950
lines changed

Some content is hidden

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

138 files changed

+16195
-5950
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ Future upgrades may fail since the internal contents were modified by hand. In
2121
order to recover, shut down the IDE, delete the entire `Arduino15` directory,
2222
then restart the IDE.
2323

24+
# Pull Requests
25+
26+
Before submitting a pull request, please see our
27+
[guidelines](https://github.com/01org/corelibs-arduino101/wiki/Writing-a-commit-message)
28+
for writing a considerate commit message.
29+
2430
# Support & Issues
2531

2632
If you have found a bug, or you believe a new feature should be added, please
@@ -47,3 +53,21 @@ them to the [support forum](https://forum.arduino.cc/index.php?board=103).
4753
> "How do I use this library?"
4854
4955
> "I can't get this example sketch to work. What am I doing wrong?"
56+
57+
# Enable debug interface on Serail1
58+
59+
*Default disable the debug interface.
60+
61+
If you want to enable debug trace on Serail1 to debug corelib, follow these instructions.
62+
63+
1. Shut down the IDE
64+
2. Go to Arduino15 directory
65+
* Windows: `C:\Users\<user>\AppData\Roaming\Arduino15`
66+
* OS X: `~/Library/Arduino15`
67+
* Linux: `~/.arduino15`
68+
3. Modify the platform.txt
69+
* Find `compiler.c.flags` and add `-DCONFIGURE_DEBUG_CORELIB_ENABLED` at the end of this line
70+
* Find `compiler.cpp.flags` and add `-DCONFIGURE_DEBUG_CORELIB_ENABLED` at the end of this line
71+
4. Initial Serial1 in your sketch
72+
* Add `Serial1.begin(115200);` in your `setup()`
73+
5. Adjust the output level at log_init function in log.c

cores/arduino/Arduino.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ extern "C"{
4343
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (SYSTEM_CORE_CLOCK / 1000L) )
4444
#define microsecondsToClockCycles(a) ( (a) * (SYSTEM_CORE_CLOCK / 1000000L) )
4545

46-
#define digitalPinToInterrupt(P) ( P )
47-
4846
void yield(void);
4947

5048
/* sketch */

cores/arduino/UARTClass.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include "wiring_constants.h"
2626
#include "wiring_digital.h"
2727

28+
#define SETTLING_TIME 400
29+
2830
extern void UART_Handler(void);
2931
extern void serialEventRun(void) __attribute__((weak));
3032
extern void serialEvent(void) __attribute__((weak));
@@ -112,6 +114,10 @@ void UARTClass::end( void )
112114
opened = false;
113115
// Clear any received data
114116
_rx_buffer->_iHead = _rx_buffer->_iTail;
117+
118+
SET_PIN_MODE(17, GPIO_MUX_MODE); // Rdx SOC PIN (Arduino header pin 0)
119+
SET_PIN_MODE(16, GPIO_MUX_MODE); // Txd SOC PIN (Arduino header pin 1)
120+
delayMicroseconds(SETTLING_TIME); // wait for lines to settle
115121
}
116122

117123
void UARTClass::setInterruptPriority(uint32_t priority)

cores/arduino/i2c.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ static void ss_i2c_err(uint32_t dev_id)
4848
i2c_err_source = dev_id;
4949
}
5050

51-
static int wait_rx_or_err(bool no_stop){
51+
static int wait_rx_or_err()
52+
{
5253
uint64_t timeout = TIMEOUT_MS * 200;
5354
while(timeout--) {
5455
if (i2c_err_detect) {
@@ -65,20 +66,17 @@ static int wait_rx_or_err(bool no_stop){
6566
return I2C_ERROR_OTHER; // other error
6667
}
6768
}
68-
if (!no_stop) {
69-
if (i2c_rx_complete) {
70-
return I2C_OK;
71-
}
69+
if (i2c_rx_complete) {
70+
return I2C_OK;
7271
}
7372
delayMicroseconds(10);
7473
}
75-
if (!no_stop)
76-
return I2C_TIMEOUT;
77-
else
78-
return I2C_OK;
74+
75+
return I2C_TIMEOUT;
7976
}
8077

81-
static int wait_tx_or_err(bool no_stop){
78+
static int wait_tx_or_err()
79+
{
8280
uint64_t timeout = TIMEOUT_MS * 200;
8381
while(timeout--) {
8482
if (i2c_err_detect) {
@@ -95,17 +93,12 @@ static int wait_tx_or_err(bool no_stop){
9593
return I2C_ERROR_OTHER; // other error
9694
}
9795
}
98-
if (!no_stop) {
99-
if (i2c_tx_complete) {
96+
if (i2c_tx_complete) {
10097
return I2C_OK;
101-
}
10298
}
10399
delayMicroseconds(10);
104100
}
105-
if (!no_stop)
106-
return I2C_TIMEOUT;
107-
else
108-
return I2C_OK;
101+
return I2C_TIMEOUT;
109102
}
110103

111104
static int wait_dev_ready(I2C_CONTROLLER controller_id, bool no_stop){
@@ -116,9 +109,13 @@ static int wait_dev_ready(I2C_CONTROLLER controller_id, bool no_stop){
116109
if (ret == I2C_OK) {
117110
return I2C_OK;
118111
}
119-
if (ret == I2C_BUSY) {
112+
else if (ret == I2C_BUSY) {
120113
delayMicroseconds(10);
121114
}
115+
else
116+
{
117+
return I2C_TIMEOUT - ret;
118+
}
122119
}
123120
return I2C_TIMEOUT - ret;
124121
}
@@ -202,7 +199,7 @@ int i2c_writebytes(uint8_t *bytes, uint8_t length, bool no_stop)
202199
i2c_err_detect = 0;
203200
i2c_err_source = 0;
204201
ss_i2c_transfer(I2C_SENSING_0, bytes, length, 0, 0, i2c_slave, no_stop);
205-
ret = wait_tx_or_err(no_stop);
202+
ret = wait_tx_or_err();
206203
if (ret)
207204
return ret;
208205
ret = wait_dev_ready(I2C_SENSING_0, no_stop);
@@ -219,7 +216,7 @@ int i2c_readbytes(uint8_t *buf, int length, bool no_stop)
219216
i2c_err_detect = 0;
220217
i2c_err_source = 0;
221218
ss_i2c_transfer(I2C_SENSING_0, 0, 0, buf, length, i2c_slave, no_stop);
222-
ret = wait_rx_or_err(no_stop);
219+
ret = wait_rx_or_err();
223220
if (ret)
224221
return ret;
225222
ret = wait_dev_ready(I2C_SENSING_0, no_stop);

cores/arduino/printk.cpp

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
/*
2+
* Copyright (c) 2015, Intel Corporation. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are met:
6+
*
7+
* 1. Redistributions of source code must retain the above copyright notice,
8+
* this list of conditions and the following disclaimer.
9+
*
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
*
14+
* 3. Neither the name of the copyright holder nor the names of its contributors
15+
* may be used to endorse or promote products derived from this software without
16+
* specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#include <stdarg.h>
32+
#include "UARTClass.h"
33+
34+
extern "C" void printk(const char *fmt, va_list args);
35+
int __vsnprintf(char *dest, int size, const char *fmt, va_list args)
36+
{
37+
int might_format = 0;
38+
int len = 0;
39+
char lastchar = 0;
40+
bool binary_format = false;
41+
42+
if (!dest || !size)
43+
return 0;
44+
45+
while (*fmt && len < size) {
46+
if (!might_format) {
47+
if (*fmt == '\n' && lastchar != '\r') {
48+
if (len < size) {
49+
lastchar = *dest++ = '\r', len++;
50+
continue;
51+
} else
52+
break;
53+
} else if (*fmt != '%') {
54+
if (len < size)
55+
lastchar = *dest++ = *fmt, len++;
56+
else
57+
break;
58+
} else
59+
might_format = 1;
60+
} else {
61+
if (*fmt == '%') {
62+
if (len < size)
63+
*dest++ = '%', len++;
64+
else
65+
break;
66+
might_format = 0;
67+
} else {
68+
switch (*fmt) {
69+
case '0':
70+
case '1':
71+
might_format |= 2;
72+
goto still_format;
73+
break;
74+
case '2':
75+
might_format |= 4;
76+
goto still_format;
77+
break;
78+
case '4':
79+
might_format |= 8;
80+
goto still_format;
81+
break;
82+
case 'b':
83+
binary_format = true;
84+
goto still_format;
85+
break;
86+
case 'd':
87+
case 'i':
88+
case 'u':
89+
if (!binary_format) {
90+
unsigned long num =
91+
va_arg(args,
92+
unsigned long);
93+
unsigned long pos = 999999999;
94+
unsigned long remainder = num;
95+
int found_largest_digit = 0;
96+
97+
if (*fmt != 'u'
98+
&& (num & (1 << 31))) {
99+
if (len < size)
100+
*dest++ =
101+
'-',
102+
len++;
103+
num = (~num) + 1;
104+
remainder = num;
105+
}
106+
while (pos >= 9) {
107+
if (found_largest_digit
108+
|| remainder >
109+
pos) {
110+
found_largest_digit
111+
= 1;
112+
if (len < size)
113+
*dest++
114+
=
115+
(
116+
char)
117+
((
118+
remainder
119+
/ (
120+
pos
121+
+
122+
1))
123+
+
124+
48),
125+
len++;
126+
else
127+
break;
128+
}
129+
remainder %= (pos + 1);
130+
pos /= 10;
131+
}
132+
if (len < size)
133+
*dest++ =
134+
(char)(
135+
remainder
136+
+
137+
48),
138+
len++;
139+
break;
140+
}
141+
case 'x':
142+
case 'X':
143+
case 'p': {
144+
unsigned long num =
145+
va_arg(args, unsigned long);
146+
int sz = sizeof(num) * 2;
147+
148+
if (might_format & 8) {
149+
sz = 4;
150+
} else if (might_format & 4) {
151+
sz = 2;
152+
} else if (might_format & 2) {
153+
sz = 1;
154+
}
155+
for (; sz; sz--) {
156+
char nibble;
157+
if (!binary_format) {
158+
nibble =
159+
(num >>
160+
((sz -
161+
1) <<
162+
2) & 0xf);
163+
nibble +=
164+
nibble >
165+
9 ? 87 : 48;
166+
} else {
167+
nibble =
168+
(num >>
169+
((sz -
170+
1) <<
171+
3) & 0xff);
172+
}
173+
if (len < size)
174+
*dest++ =
175+
nibble,
176+
len++;
177+
else
178+
break;
179+
}
180+
break;
181+
}
182+
case 's': {
183+
char *s = va_arg(args, char *);
184+
while (*s)
185+
if (len < size)
186+
*dest++ =
187+
*s++, len++;
188+
else
189+
break;
190+
break;
191+
}
192+
case 'c': {
193+
char c = va_arg(args, int);
194+
if (len < size)
195+
*dest++ = c, len++;
196+
break;
197+
}
198+
default:
199+
if (len < size)
200+
*dest++ = '%', len++;
201+
if (len < size)
202+
*dest++ = *fmt, len++;
203+
break;
204+
}
205+
might_format = 0;
206+
still_format:
207+
(void)might_format;
208+
}
209+
}
210+
++fmt;
211+
}
212+
*dest = '\0';
213+
return len;
214+
}
215+
216+
extern UARTClass Serial1;
217+
#define PRINTK_BUFSIZ 256
218+
void printk(const char *fmt, va_list args)
219+
{
220+
#ifdef CONFIGURE_DEBUG_CORELIB_ENABLED
221+
int len = 0;
222+
223+
char tmp[PRINTK_BUFSIZ];
224+
225+
len = __vsnprintf(tmp, PRINTK_BUFSIZ, fmt, args);
226+
227+
tmp[len] = '\0';
228+
Serial1.println(tmp);
229+
#endif
230+
}

libraries/CurieBLE/examples/BatteryMonitor/BatteryMonitor.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void setup() {
4545

4646
void loop() {
4747
// listen for BLE peripherals to connect:
48-
BLECentral central = blePeripheral.central();
48+
BLECentralHelper central = blePeripheral.central();
4949

5050
// if a central is connected to peripheral:
5151
if (central) {

0 commit comments

Comments
 (0)