Skip to content
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

merge v1.0.0 into master #39

Merged
merged 14 commits into from
Sep 30, 2021
Merged
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
6 changes: 6 additions & 0 deletions .github/workflows/aunit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@ jobs:

- name: Verify tests
run: |
# tests/IPAddressTest requires EPOXY_CORE_ESP8266, which requires clean
make -C tests clean
make -C tests tests
make -C tests runtests
# clean after tests/IPAddressTest to revert to EPOXY_CORE_AVR
make -C libraries clean
make -C libraries tests
make -C libraries runtests
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Changelog

* Unreleased
* 1.0 (2021-09-30)
* Add `epoxy_argc` and `epoxy_argv` as extern global variables which
are set to the `argc` and `argv` parameters passed into the global
`main()`.
* Allows command line arguments to be passed into an Arduino
application, to facilitate debugging on a Unix desktop machine.
* Add `examples/CommandLine` which provides a basic command line parser
that can be copied and modified for other applications.
* Add `toString()` to `IPAddress` class, activated with `EPOXY_CORE_ESP8266`
for compatibility with ESP8266 Core.
* Add `strstr_P()` to `pgmspace.h`.
* Finally fix [Issue #2](https://github.com/bxparks/EpoxyDuino/issues/2) and
[Issue #25](https://github.com/bxparks/EpoxyDuino/issues/25).
* 0.8 (2021-08-08)
* Add `EpoxyMockTimerOne` mock library for `TimerOne`
(https://github.com/PaulStoffregen/TimerOne).
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
# Users of this library will use 'EpoxyDuino.mk' instead.

all:
$(MAKE) -C tests
$(MAKE) -C libraries
$(MAKE) -C examples

runtests:
$(MAKE) -C tests runtests
$(MAKE) -C libraries runtests

clean:
$(MAKE) -C tests clean
$(MAKE) -C libraries clean
$(MAKE) -C examples clean
99 changes: 63 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

[![AUnit Tests](https://github.com/bxparks/EpoxyDuino/actions/workflows/aunit_tests.yml/badge.svg)](https://github.com/bxparks/EpoxyDuino/actions/workflows/aunit_tests.yml)

**New**: [GitHub Discussions](https://github.com/bxparks/EpoxyDuino/discussions)
for this project is now active! Let's use that for general support questions,
and reserve the [GitHub Issues](https://github.com/bxparks/EpoxyDuino/issues)
section for bugs and feature requests.

This project contains a small (but often effective) implementation of the
Arduino programming framework for Linux, MacOS, FreeBSD (experimental) and
potentially other POSIX-like systems. Originally, it was created to allow
Expand Down Expand Up @@ -60,16 +55,10 @@ The disadvantages are:
environments (e.g. 16-bit `int` versus 32-bit `int`, or 32-bit `long` versus
64-bit `long`).

**Version**: 0.8 (2021-08-08)
**Version**: 1.0 (2021-09-30)

**Changelog**: See [CHANGELOG.md](CHANGELOG.md)

**Breaking Change**: Prior to v0.5, this project was known as "UnixHostDuino".
The old `UNIX_HOST_DUINO` macro and `UnixHostDuino.mk` include file still exist
for backwards compatibility. See
[Issue #15](https://github.com/bxparks/EpoxyDuino/issues/15)
for more details.

## Table of Contents

* [Installation](#Installation)
Expand All @@ -87,6 +76,7 @@ for more details.
* [Additional Clean Up](#AdditionalCleanUp)
* [Alternate Arduino Core](#AlternateArduinoCore)
* [PlatformIO](#PlatformIO)
* [Command Line Flags and Arguments](#CommandLineFlagsAndArguments)
* [Supported Arduino Features](#SupportedArduinoFeatures)
* [Arduino Functions](#ArduinoFunctions)
* [Serial Port Emulation](#SerialPortEmulation)
Expand Down Expand Up @@ -320,9 +310,9 @@ FooLibrary
|-- library.properties
|-- src
| |-- FooLibrary.h
| |-- foolib
| | |-- file.h
| | `-- file.cpp
| `-- foolib
| |-- file.h
| `-- file.cpp
`-- tests
|-- AxxTest
| |-- AxxTest.ino
Expand Down Expand Up @@ -513,8 +503,12 @@ Core. EpoxyDuino provides the ability substitute a different Arduino API Core
through 2 Makefile variables:

* `EPOXY_CORE`
* This Makefile variable defines the C-preprocessor macro which will be
defined through the `-D` flag through `-D $(EPOXY_CORE)`.
* `EPOXY_CORE_PATH`

#### `EPOXY_CORE`

The `EPOXY_CORE` Makefile variable defines the C-preprocessor macro which will
be defined through the `-D` flag through `-D $(EPOXY_CORE)`.

There are currently 2 valid options for this Makefile variable:

Expand All @@ -538,12 +532,12 @@ compiler, which will activate any code that is guarded by:
#endif
```

#### `EPOXY_CORE_PATH`

If the `EPOXY_CORE` make variable is insufficient (e.g. because the appropriate
changes have not been incorporated into `$(EPOXY_DUINO_DIR)/cores/epoxy/`), then
there is an even bigger hammer with the following make variable:

* `EPOXY_CORE_PATH`
* Defines the full-path to the Arduino Core API files.
the `EPOXY_CORE_PATH` provides an even bigger hammer. It defines the the
full-path to the Arduino Core API files.

By default, this is set to `$(EPOXY_DUINO_DIR)/cores/epoxy`. You can create your
own set of Arduino API files in a directory of your choosing, and set this
Expand All @@ -562,6 +556,50 @@ in [Issue #31](https://github.com/bxparks/EpoxyDuino/pull/31) (thanks
https://github.com/lopsided98). However, this functionality is *unsupported*. If
it becomes broken in the future, please send me a PR to fix it.

<a name="CommandLineFlagsAndArguments"></a>
### Command Line Flags and Arguments

The standard Arduino environment does not provide command line arguments, since
a microcontroller does not normally provide a command line environment.
When an Arduino application is compiled Using EpoxyDuino, the Unix command line
parameters (`argc` and `argv`) become available through 2 global variables:

* `extern int epoxy_argc`
* `extern const char* const* epoxy_argv`

The [examples/CommandLine](examples/CommandLine) program contains a basic
command line parser which can be copied and customized for different
applications:

```
$ ./CommandLine.out --help
Usage: ./CommandLine.out [--help|-h] [-s] [--include word] [--] [words ...]

$ ./CommandLine.out one two
arg: one
arg: two

$ ./CommandLine.out -s
flag: -s

$ ./CommandLine.out --include inc one two
flag: --include inc
arg: one
arg: two

$ ./CommandLine.out --include inc -- -one two
flag: --include inc
arg: -one
arg: two

$ ./CommandLine.out -a
Unknonwn flag '-a'
Usage: ./CommandLine.out [--help|-h] [-s] [--include word] [--] [words ...]
```

A more advanced example can be seen in
[AUnit/TestRunner.cpp](https://github.com/bxparks/AUnit/blob/develop/src/aunit/TestRunner.cpp).

<a name="SupportedArduinoFeatures"></a>
## Supported Arduino Features

Expand Down Expand Up @@ -595,7 +633,7 @@ The following functions and features of the Arduino framework are implemented:
* `pgm_read_byte()`, `pgm_read_word()`, `pgm_read_dword()`,
`pgm_read_float()`, `pgm_read_ptr()`
* `strlen_P()`, `strcat_P()`, `strcpy_P()`, `strncpy_P()`, `strcmp_P()`,
`strncmp_P()`, `strcasecmp_P()`, `strchr_P()`, `strrchr_P()`
`strncmp_P()`, `strcasecmp_P()`, `strchr_P()`, `strrchr_P()`, `strstr_P()`
* `memcpy_P()`, `vsnprintf_P()`
* `PROGMEM`, `PGM_P`, `PGM_VOID_P`, `PSTR()`
* `IPAddress.h`
Expand All @@ -606,7 +644,8 @@ The following functions and features of the Arduino framework are implemented:
* `Wire.h` (stub implementation)
* `SPI.h` (stub implementation)

See [Arduino.h](https://github.com/bxparks/EpoxyDuino/blob/develop/Arduino.h)
See
[Arduino.h](https://github.com/bxparks/EpoxyDuino/blob/develop/cores/epoxy/Arduino.h)
for the latest list. Most of the header files included by this `Arduino.h`
file were copied and modified from the [arduino:avr
core](https://github.com/arduino/ArduinoCore-avr/tree/master/cores/arduino),
Expand Down Expand Up @@ -809,19 +848,7 @@ This library has been tested on:
<a name="Bugs"></a>
## Bugs and Limitations

If the executable (e.g. `SampleTest.out`) is piped to the `less(1)` or `more(1)`
command, sometimes (not all the time) the executable hangs and displays nothing
on the pager program. I don't know why, it probably has to do with the way that
the `less` or `more` programs manipulate the `stdin`. The solution is to
explicitly redirect the `stdin`:

```
$ ./SampleTest.out | grep failed # works

$ ./SampleTest.out | less # hangs

$ ./SampleTest.out < /dev/null | less # works
```
None that I am aware of.

<a name="FeedbackAndSupport"></a>
## Feedback and Support
Expand Down
13 changes: 11 additions & 2 deletions cores/epoxy/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#define EPOXY_DUINO_EPOXY_ARDUINO_H

// xx.yy.zz => xxyyzz (without leading 0)
#define EPOXY_DUINO_VERSION 800
#define EPOXY_DUINO_VERSION_STRING "0.8.0"
#define EPOXY_DUINO_VERSION 10000
#define EPOXY_DUINO_VERSION_STRING "1.0.0"

#include <stdlib.h>
#include <stdint.h>
Expand All @@ -28,6 +28,9 @@
#include "WCharacter.h"
#include "Print.h"
#include "StdioSerial.h"
#if defined(EPOXY_CORE_ESP8266)
#include "Esp.h"
#endif

// Used by digitalRead() and digitalWrite()
#define HIGH 0x1
Expand Down Expand Up @@ -213,6 +216,12 @@ int unixhostduino_main(int argc, char** argv);
/** Calls unixhostduino_main() unless overriden by user */
int main(int argc, char** argv);

/** Copy of the argc parameter of main() as a global variable. */
extern int epoxy_argc;

/** Copy of the argv parameter of main() as a global variable. */
extern const char* const* epoxy_argv;

}

// WMath prototypes
Expand Down
10 changes: 1 addition & 9 deletions cores/epoxy/Esp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,8 @@

#if defined(EPOXY_CORE_ESP8266)

#include <Arduino.h>
#include <Stream.h>
#include <sys/time.h>

class _FLOAT
{
public:
int digits;
float val;
};
#include "Stream.h"

class EspClass
{
Expand Down
20 changes: 20 additions & 0 deletions cores/epoxy/IPAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,23 @@ size_t IPAddress::printTo(Print& p) const
n += p.print(_address.bytes[3], DEC);
return n;
}

#if defined(EPOXY_CORE_ESP8266)
String IPAddress::toString() const
{
String s;
s.reserve(16);

s.concat(_address.bytes[0]);
s.concat('.');
s.concat(_address.bytes[1]);
s.concat('.');
s.concat(_address.bytes[2]);
s.concat('.');
s.concat(_address.bytes[3]);

return s;
}
#endif

const IPAddress INADDR_NONE(0,0,0,0);
12 changes: 9 additions & 3 deletions cores/epoxy/IPAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Copied from Arduino AVR core 1.8.3 by Erik Tideman. Removed
unnecessary 'friend' declarations.

Merged selected features from ESP8266 Core 2.7.4 by Brian T. Park.

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
Expand Down Expand Up @@ -32,8 +34,8 @@
class IPAddress : public Printable {
private:
union {
uint8_t bytes[4]; // IPv4 address
uint32_t dword;
uint8_t bytes[4]; // IPv4 address
uint32_t dword;
} _address;

// Access the raw byte array containing the address. Because this returns a pointer
Expand Down Expand Up @@ -67,8 +69,12 @@ class IPAddress : public Printable {
IPAddress& operator=(uint32_t address);

virtual size_t printTo(Print& p) const;

#if defined(EPOXY_CORE_ESP8266)
String toString() const;
#endif
};

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

#endif
Loading