Skip to content

Arduino libs #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions v4.0/contributed libraries/Arduino.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import Arduino
69 changes: 69 additions & 0 deletions v4.0/contributed libraries/catalogNew.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# This file lists all libraries and documentation the S4A IDE should automatically download
# standard libraries
MPL31155A2.swift
rotaryEncoder.swift
servo.swift
stepper-28BYJ-48.swift
iLEDHelpers.swift
DHT11.swift
Grove2DigitAlnum.swift
fade.swift
pulseIn.swift
unitTests.swift

# standard library documentation
MPL31155A2.txt
rotaryEncoder.txt
servo.txt
stepper-28BYJ-48.txt
iLEDHelpers.txt
DHT11.txt
Grove2DigitAlnum.txt
fade.txt
pulseIn.txt
unitTests.txt

# unsafe libraries and documentation
unsafeSeeed_RGB_LED_Matrix.swift
unsafeSeeed_RGB_LED_Matrix.txt
unsafe_modules/Seeed_RGB_LED_Matrix/libSeeed_RGB_LED_Matrix.a
unsafe_modules/Seeed_RGB_LED_Matrix/module.modulemap
unsafe_modules/Seeed_RGB_LED_Matrix/Seeed_RGB_LED_Matrix.h

unsafeAdafruit_Bluefruit_LE.swift
unsafeAdafruit_Bluefruit_LE.txt
unsafe_modules/Adafruit_Bluefruit_LE/Adafruit_Bluefruit_LE.h
unsafe_modules/Adafruit_Bluefruit_LE/module.modulemap
unsafe_modules/Adafruit_Bluefruit_LE/libAdafruit_Bluefruit_LE.a

unsafeMAX30105.swift
unsafeMAX30105.txt
unsafe_modules/MAX30105/MAX30105_.h
unsafe_modules/MAX30105/module.modulemap
unsafe_modules/MAX30105/libMAX30105.a

unsafeTimerInterrupts.swift
unsafeTimerInterrupts.txt
unsafe_modules/TimerInterrupts/module.modulemap
unsafe_modules/TimerInterrupts/libTimerInterrupts.a
unsafe_modules/TimerInterrupts/TimerInterrupts.h

unsafe_modules/Arduino/libArduino.a
unsafe_modules/Arduino/module.modulemap
unsafe_modules/Arduino/Arduino.h
Arduino.swift
unsafe_modules/Arduino/ArduinoSwift.h
unsafe_modules/Arduino/SimpleDebugPrinter.h
unsafe_modules/Arduino/DebugPrinter.h
unsafe_modules/Arduino/Print.h
unsafe_modules/Arduino/Stream.h
unsafe_modules/Arduino/shims.h
unsafe_modules/Arduino/avrTypes.h
unsafe_modules/Arduino/AdapterSerial.h
unsafe_modules/Arduino/IPAddress.h
unsafe_modules/Arduino/Printable.h
unsafe_modules/Arduino/Udp.h
unsafe_modules/Arduino/Client.h
unsafe_modules/Arduino/Server.h
unsafe_modules/Arduino/Wire.h
unsafe_modules/Arduino/binary.h
64 changes: 64 additions & 0 deletions v4.0/contributed libraries/unsafe_modules/Arduino/AdapterSerial.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*

ORIGINAL FILE AND COPYRIGHT:
HardwareSerial.h - Hardware serial library for Wiring
Copyright (c) 2006 Nicholas Zambetti. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

Modified 28 September 2010 by Mark Sproul
Modified 14 August 2012 by Alarus
Modified 3 December 2013 by Matthijs Kooijman



NEW FILE: AdapterSerial.h
Changes are copyright (c) 2022 Carl Peto.

Rewritten to work as stubs with the AVR library native to the Swift for Arduino platform.

*/

#ifndef Serial_h
#define Serial_h

#include <inttypes.h>

#include "Stream.h"

class AdapterSerial : public Stream
{
public:
inline AdapterSerial();
void begin(unsigned long baud) { } // noop
void begin(unsigned long, uint8_t);
void end();
virtual int available(void);
virtual int peek(void);
virtual int read(void);
virtual int availableForWrite(void);
virtual void flush(void);
virtual size_t write(uint8_t);
inline size_t write(unsigned long n) { return write((uint8_t)n); }
inline size_t write(long n) { return write((uint8_t)n); }
inline size_t write(unsigned int n) { return write((uint8_t)n); }
inline size_t write(int n) { return write((uint8_t)n); }
using Print::write; // pull in write(str) and write(buf, size) from Print
operator bool() { return true; }
};

extern AdapterSerial Serial;

#endif
22 changes: 22 additions & 0 deletions v4.0/contributed libraries/unsafe_modules/Arduino/Arduino.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#define ARDUINO_SHIM_DEFINED (unsigned char)1

#define ARDUINO 100

#ifdef __cplusplus

#include "DebugPrinter.h"
#include "Print.h"
#include "SimpleDebugPrinter.h"
#include "Stream.h"
#include "AdapterSerial.h"
#include "Wire.h"
#include "binary.h"

// these seem to cause program crashes
// #include "IPAddress.h"
// #include "Printable.h"
// #include "Udp.h"
// #include "Client.h"
// #include "Server.h"

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define ARDUINO_SHIM_DEFINED (unsigned char)1
45 changes: 45 additions & 0 deletions v4.0/contributed libraries/unsafe_modules/Arduino/Client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Client.h - Base class that provides Client
Copyright (c) 2011 Adrian McEwen. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef client_h
#define client_h
#include "Print.h"
#include "Stream.h"
#include "IPAddress.h"

class Client : public Stream {

public:
virtual int connect(IPAddress ip, uint16_t port) =0;
virtual int connect(const char *host, uint16_t port) =0;
virtual size_t write(uint8_t) =0;
virtual size_t write(const uint8_t *buf, size_t size) =0;
virtual int available() = 0;
virtual int read() = 0;
virtual int read(uint8_t *buf, size_t size) = 0;
virtual int peek() = 0;
virtual void flush() = 0;
virtual void stop() = 0;
virtual uint8_t connected() = 0;
virtual operator bool() = 0;
protected:
uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); };
};

#endif
12 changes: 12 additions & 0 deletions v4.0/contributed libraries/unsafe_modules/Arduino/DebugPrinter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <inttypes.h>
#include <stddef.h>
#include "Print.h"

class DebugPrinter : public Print
{
protected:
size_t(*_printCallback)(const uint8_t *buf, size_t size) = 0;
public:
DebugPrinter(size_t(*callback)(const uint8_t *buf, size_t size)) { _printCallback = callback; }
virtual size_t write(const uint8_t *buffer, size_t size);
};
78 changes: 78 additions & 0 deletions v4.0/contributed libraries/unsafe_modules/Arduino/IPAddress.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
IPAddress.h - Base class that provides IPAddress
Copyright (c) 2011 Adrian McEwen. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef IPAddress_h
#define IPAddress_h

#include <stdint.h>
#include "Printable.h"
// #include "WString.h"

// A class to make it easier to handle and pass around IP addresses

class IPAddress : public Printable {
private:
union {
uint8_t bytes[4]; // IPv4 address
uint32_t dword;
} _address;

// Access the raw byte array containing the address. Because this returns a pointer
// to the internal structure rather than a copy of the address this function should only
// be used when you know that the usage of the returned uint8_t* will be transient and not
// stored.
uint8_t* raw_address() { return _address.bytes; };

public:
// Constructors
IPAddress();
IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet);
IPAddress(uint32_t address);
IPAddress(const uint8_t *address);

bool fromString(const char *address);
// bool fromString(const String &address) { return fromString(address.c_str()); }

// Overloaded cast operator to allow IPAddress objects to be used where a pointer
// to a four-byte uint8_t array is expected
operator uint32_t() const { return _address.dword; };
bool operator==(const IPAddress& addr) const { return _address.dword == addr._address.dword; };
bool operator==(const uint8_t* addr) const;

// Overloaded index operator to allow getting and setting individual octets of the address
uint8_t operator[](int index) const { return _address.bytes[index]; };
uint8_t& operator[](int index) { return _address.bytes[index]; };

// Overloaded copy operators to allow initialisation of IPAddress objects from other types
IPAddress& operator=(const uint8_t *address);
IPAddress& operator=(uint32_t address);

virtual size_t printTo(Print& p) const;

friend class EthernetClass;
friend class UDP;
friend class Client;
friend class Server;
friend class DhcpClass;
friend class DNSClient;
};

const IPAddress INADDR_NONE(0,0,0,0);

#endif
97 changes: 97 additions & 0 deletions v4.0/contributed libraries/unsafe_modules/Arduino/Print.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
Print.h - Base class that provides print() and println()
Copyright (c) 2008 David A. Mellis. All right reserved.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#ifndef Print_h
#define Print_h

#include <inttypes.h>
#include <stdio.h> // for size_t
#include <string.h>
#include <avr/pgmspace.h>

class __FlashStringHelper;

// #include "WString.h"
// #include "Printable.h"

#define DEC 10
#define HEX 16
#define OCT 8
#ifdef BIN // Prevent warnings if BIN is previously defined in "iotnx4.h" or similar
#undef BIN
#endif
#define BIN 2

class Print
{
private:
int write_error;
size_t printNumber(unsigned long, uint8_t);
size_t printFloat(double, uint8_t);
protected:
void setWriteError(int err = 1) { write_error = err; }
public:
Print() : write_error(0) {}

int getWriteError() { return write_error; }
void clearWriteError() { setWriteError(0); }

virtual size_t write(uint8_t) = 0;
size_t write(const char *str) {
if (str == NULL) return 0;
return write((const uint8_t *)str, strlen(str));
}
virtual size_t write(const uint8_t *buffer, size_t size);
size_t write(const char *buffer, size_t size) {
return write((const uint8_t *)buffer, size);
}

// default to zero, meaning "a single write may block"
// should be overriden by subclasses with buffering
virtual int availableForWrite() { return 0; }

size_t print(const __FlashStringHelper *);
// size_t print(const String &);
size_t print(const char[]);
size_t print(char);
size_t print(unsigned char, int = DEC);
size_t print(int, int = DEC);
size_t print(unsigned int, int = DEC);
size_t print(long, int = DEC);
size_t print(unsigned long, int = DEC);
size_t print(double, int = 2);
// size_t print(const Printable&);

size_t println(const __FlashStringHelper *);
// size_t println(const String &s);
size_t println(const char[]);
size_t println(char);
size_t println(unsigned char, int = DEC);
size_t println(int, int = DEC);
size_t println(unsigned int, int = DEC);
size_t println(long, int = DEC);
size_t println(unsigned long, int = DEC);
size_t println(double, int = 2);
// size_t println(const Printable&);
size_t println(void);

virtual void flush() { /* Empty implementation for backward compatibility */ }
};

#endif
Loading