Browse Source

sys/arduino: make arduino sketch works on avr based boards

pr/spi.typo
Alexandre Abadie 6 years ago
parent
commit
3b1d67badd
  1. 1
      boards/arduino-common/Makefile.features
  2. 14
      examples/arduino_hello-world/hello-world.sketch
  3. 2
      sys/arduino/Makefile.include
  4. 2
      sys/arduino/base.cpp
  5. 2
      sys/arduino/include/arduino.hpp
  6. 2
      sys/arduino/include/serialport.hpp
  7. 1
      sys/arduino/pre.snip
  8. 4
      sys/arduino/serialport.cpp

1
boards/arduino-common/Makefile.features

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

14
examples/arduino_hello-world/hello-world.sketch

@ -13,6 +13,15 @@
#define ARDUINO_LED (0)
#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
int ledPin = ARDUINO_LED;
@ -26,8 +35,9 @@ void setup(void)
{
// configure the LED pin to be output
pinMode(ledPin, OUTPUT);
// configure the first serial port to run with a baudrate of 115200
Serial.begin(115200);
// configure the first serial port to run with the previously defined
// baudrate
Serial.begin(SERIAL_BAUDRATE);
// say hello
Serial.println("Hello Arduino!");
}

2
sys/arduino/Makefile.include

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

2
sys/arduino/base.cpp

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

2
sys/arduino/include/arduino.hpp

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

2
sys/arduino/include/serialport.hpp

@ -84,7 +84,7 @@ public:
*
* @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

1
sys/arduino/pre.snip

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

4
sys/arduino/serialport.cpp

@ -43,7 +43,7 @@ int SerialPort::available(void)
return (int)rx_buf.avail;
}
void SerialPort::begin(int baudrate)
void SerialPort::begin(long baudrate)
{
/* this clears the contents of the ringbuffer... */
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)
{
char buf[64];
size_t len = sprintf(buf, "%.*f", format, val);
size_t len = sprintf(buf, "%.*f", format, (double)val);
write(buf, len);
return len;
}

Loading…
Cancel
Save