Skip to content

Commit 56045b5

Browse files
committed
trying a change that limits arduino.h to not be included in library discovery, this may help compile times. Add dtostrf implementation from deprecated arduino api, we will likely not need this after we add float printing support
1 parent b54bfcb commit 56045b5

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

Arduino.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55

66
// The "Arduino.h" header file is intended to only be included by C++ sources.
77

8-
#ifndef _ARDUINO_MBED_BRIDGE_ARDUINO_H_
8+
#if ARDUINO_LIBRARY_DISCOVERY_PHASE == 1
9+
#define ARDUINO_LIB_DISCOVERY_PHASE
10+
#endif
11+
#if !defined(_ARDUINO_MBED_BRIDGE_ARDUINO_H_) && !defined(ARDUINO_LIB_DISCOVERY_PHASE)
912
#define _ARDUINO_MBED_BRIDGE_ARDUINO_H_
1013

1114
#include "mbed.h"

core-extend/dtostrf.h

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
dtostrf - Emulation for dtostrf function from avr-libc
3+
Copyright (c) 2015 Arduino LLC. All rights reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#pragma once
21+
22+
23+
24+
#ifdef __cplusplus
25+
extern "C" {
26+
#endif
27+
28+
char *dtostrf(double val, signed char width, unsigned char prec, char *sout);
29+
30+
#ifdef __cplusplus
31+
}
32+
#endif
33+

core-implement/dtostrf.c

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
dtostrf - Emulation for dtostrf function from avr-libc
3+
Copyright (c) 2016 Arduino LLC. All rights reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
// This is a default implementation for dtostrf function.
21+
// This file should be used if the standard lib doesn't provide an
22+
// implementation of dtostrf.
23+
24+
// Create a file called "dtostrf.c" with the following include:
25+
// #include "api/deprecated-avr-comp/avr/dtostrf.c.impl"
26+
27+
#include <stdio.h>
28+
29+
char *dtostrf (double val, signed char width, unsigned char prec, char *sout) {
30+
asm(".global _printf_float");
31+
32+
char fmt[20];
33+
sprintf(fmt, "%%%d.%df", width, prec);
34+
sprintf(sout, fmt, val);
35+
return sout;
36+
}
37+

0 commit comments

Comments
 (0)