1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-17 18:43:50 +01:00

Merge pull request #5987 from aabadie/arduino_sketch_on_arduino

sys/arduino: make arduino sketch works on avr based boards
This commit is contained in:
Hauke Petersen 2017-01-24 14:10:18 +01:00 committed by GitHub
commit 10c46866d2
8 changed files with 20 additions and 8 deletions

View File

@ -5,6 +5,7 @@ FEATURES_PROVIDED += periph_timer
FEATURES_PROVIDED += periph_uart FEATURES_PROVIDED += periph_uart
# Various other features (if any) # Various other features (if any)
FEATURES_PROVIDED += arduino
# The board MPU family (used for grouping by the CI system) # The board MPU family (used for grouping by the CI system)
FEATURES_MCU_GROUP = avr8 FEATURES_MCU_GROUP = avr8

View File

@ -13,6 +13,15 @@
#define ARDUINO_LED (0) #define ARDUINO_LED (0)
#endif #endif
// For some boards RIOT defines a macro assigning the required baudrate of the
// serial link. If this macro is not set, the default baudrate is set to
// 115200.
#ifdef UART_STDIO_BAUDRATE
#define SERIAL_BAUDRATE UART_STDIO_BAUDRATE
#else
#define SERIAL_BAUDRATE 115200
#endif
// Assign the default LED pin // Assign the default LED pin
int ledPin = ARDUINO_LED; int ledPin = ARDUINO_LED;
@ -26,8 +35,9 @@ void setup(void)
{ {
// configure the LED pin to be output // configure the LED pin to be output
pinMode(ledPin, OUTPUT); pinMode(ledPin, OUTPUT);
// configure the first serial port to run with a baudrate of 115200 // configure the first serial port to run with the previously defined
Serial.begin(115200); // baudrate
Serial.begin(SERIAL_BAUDRATE);
// say hello // say hello
Serial.println("Hello Arduino!"); Serial.println("Hello Arduino!");
} }

View File

@ -6,4 +6,4 @@ SRCDIR = $(RIOTBASE)/sys/arduino
$(shell $(RIOTBASE)/dist/tools/arduino/pre_build.sh $(SRCDIR) $(APPDIR) $(SKETCHES)) $(shell $(RIOTBASE)/dist/tools/arduino/pre_build.sh $(SRCDIR) $(APPDIR) $(SKETCHES))
# include the Arduino headers # include the Arduino headers
export INCLUDES += -I$(RIOTBASE)/sys/arduino/include INCLUDES += -I$(RIOTBASE)/sys/arduino/include

View File

@ -54,7 +54,7 @@ int digitalRead(int pin)
} }
} }
void delay(int msec) void delay(unsigned long msec)
{ {
xtimer_usleep(1000 * msec); xtimer_usleep(1000 * msec);
} }

View File

@ -80,7 +80,7 @@ int digitalRead(int pin);
* *
* @param[in] msec number of milliseconds to sleep * @param[in] msec number of milliseconds to sleep
*/ */
void delay(int msec); void delay(unsigned long msec);
#endif /* ARDUINO_H */ #endif /* ARDUINO_H */
/** @} */ /** @} */

View File

@ -84,7 +84,7 @@ public:
* *
* @param[in] speed speed in bits per second (baud) * @param[in] speed speed in bits per second (baud)
*/ */
void begin(int speed); void begin(long speed);
/** /**
* @brief Disables serial communication, allowing the RX and TX pins to be * @brief Disables serial communication, allowing the RX and TX pins to be

View File

@ -1 +1,2 @@
#include "arduino.hpp" #include "arduino.hpp"
#include "board.h"

View File

@ -43,7 +43,7 @@ int SerialPort::available(void)
return (int)rx_buf.avail; return (int)rx_buf.avail;
} }
void SerialPort::begin(int baudrate) void SerialPort::begin(long baudrate)
{ {
/* this clears the contents of the ringbuffer... */ /* this clears the contents of the ringbuffer... */
ringbuffer_init(&rx_buf, rx_mem, SERIAL_RX_BUFSIZE); ringbuffer_init(&rx_buf, rx_mem, SERIAL_RX_BUFSIZE);
@ -92,7 +92,7 @@ size_t SerialPort::print(float val)
size_t SerialPort::print(float val, int format) size_t SerialPort::print(float val, int format)
{ {
char buf[64]; char buf[64];
size_t len = sprintf(buf, "%.*f", format, val); size_t len = sprintf(buf, "%.*f", format, (double)val);
write(buf, len); write(buf, len);
return len; return len;
} }