From f30d70cdaf7ccf1dd875d118fb3f3f6e31457bbf Mon Sep 17 00:00:00 2001 From: Aruna Tennakoon Date: Wed, 27 Jul 2022 08:44:06 +0700 Subject: [PATCH] initial commit --- ReadMe.md | 52 ++++++++++++++++++++ arduino-helloworld-lib/library.properties | 10 ++++ arduino-helloworld-lib/src/esp32/libhello.a | Bin 0 -> 1074 bytes arduino-helloworld-lib/src/hello.h | 6 +++ example/example.ino | 15 ++++++ lib/hello.cpp | 9 ++++ lib/hello.h | 6 +++ 7 files changed, 98 insertions(+) create mode 100644 ReadMe.md create mode 100644 arduino-helloworld-lib/library.properties create mode 100644 arduino-helloworld-lib/src/esp32/libhello.a create mode 100644 arduino-helloworld-lib/src/hello.h create mode 100644 example/example.ino create mode 100644 lib/hello.cpp create mode 100644 lib/hello.h diff --git a/ReadMe.md b/ReadMe.md new file mode 100644 index 0000000..5987870 --- /dev/null +++ b/ReadMe.md @@ -0,0 +1,52 @@ +Step 1: + +Create hello.cpp and hello.h and add the implementation. + +Example files are in lib folder. + +Step 2: + +Make the archive file (.a) using xtensa-esp32-elf-gcc.exe for ESP32 and use xtensa-lx106-elf-gcc for ESP8266 + +xtensa-esp32-elf-gcc.exe -c hello.cpp -o libhello.o +xtensa-esp32-elf-ar.exe crf libhello.a libhello.o + +Note: xtensa-esp32-elf-gcc.exe is located here if you have installed ESP32 in your arduino IDE. +You may want to add this path to system env for easy access. +C:\Users\\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32s2-elf-gcc\gcc8_4_0-esp-2021r2-patch3\bin\ + +Now you should have a libhello.a in the path. + +Step 3: +1. Make the library for Ardunio (arduino-helloworld-lib) and copy the header files (lib\hello.h) to library src folder (arduino-helloworld-lib\src). +2. Copy the libhello.a to arduino-helloworld-lib\src\esp32 or arduino-helloworld-lib\src\esp8266 depending on which gcc you use to create the archive file. + +Step 4: + +Invoke the function from Ardunio sketch. example.ino + +#include // hello.h header from our library (arduino-helloworld-lib) + +#define BAUD_RATE 9600 + +void setup() { + Serial.begin(BAUD_RATE); + +} + +void loop() { + // put your main code here, to run repeatedly: + int result = add(1, 1); // Invokes the add function in libhello.a + Serial.println(result); + delay(1000); +} + + + + + + + + + + diff --git a/arduino-helloworld-lib/library.properties b/arduino-helloworld-lib/library.properties new file mode 100644 index 0000000..8598f3b --- /dev/null +++ b/arduino-helloworld-lib/library.properties @@ -0,0 +1,10 @@ +name=hello +version=1.0.0 +author=aruna +maintainer=aruna +sentence=A simple library +architectures=esp32 +includes=hello.h +paragraph= +precompiled=true +url=https://www.sinric.com diff --git a/arduino-helloworld-lib/src/esp32/libhello.a b/arduino-helloworld-lib/src/esp32/libhello.a new file mode 100644 index 0000000000000000000000000000000000000000..2374301f2da90c29d4307bba411f0a0c0f2d0cd0 GIT binary patch literal 1074 zcma)4-D(p-82#3*jjmp(2o*%wqR>>#xJ}cN7F$fpHUxr-X+^v+nQpcukYtzLxu_S# zSMbtj=+pQZUe+hj@9gZDsUUjb`#(9e^G#M?$SfM~d(Zu=2&_`)w)g#wrXdVHB68T? z4L)qj(P%Ou8pqRVB9h;te^c9TGzyuWx{(`tpTpjv<3Lcup^t^UslQ|75;clOm2Qzo z+mgr70~QjAu@H z6t-dV2UboZ|1?wbgrmxI9GgtVXNtr~DoNrb&q+kdY!=VCcUJ6EOt4Rp#Z$>0k!DHC z%KwLlOvBEWOFG`&Y#1%GfmP1IGaCvqw163~#)g;q7w;K!@SA`QfL^W0w8IRx#a7X+ z!e{K8R&CDhaL?ozU$8wvQo_vIT;onJ%f8|Pc=%@Q0JGwaINJY?Z(M(2yU7MFcz4R$ b+?7ijvfh0pCCs_lsm=S!gExl6(eQo&CKY5f literal 0 HcmV?d00001 diff --git a/arduino-helloworld-lib/src/hello.h b/arduino-helloworld-lib/src/hello.h new file mode 100644 index 0000000..617ff74 --- /dev/null +++ b/arduino-helloworld-lib/src/hello.h @@ -0,0 +1,6 @@ +#ifndef HELLO_H +#define HELLO_H + +int add(int x, int y); + +#endif \ No newline at end of file diff --git a/example/example.ino b/example/example.ino new file mode 100644 index 0000000..d839a1e --- /dev/null +++ b/example/example.ino @@ -0,0 +1,15 @@ +#include + +#define BAUD_RATE 9600 + +void setup() { + Serial.begin(BAUD_RATE); + +} + +void loop() { + // put your main code here, to run repeatedly: + int result = add(1, 1); + Serial.println(result); + delay(1000); +} diff --git a/lib/hello.cpp b/lib/hello.cpp new file mode 100644 index 0000000..169468b --- /dev/null +++ b/lib/hello.cpp @@ -0,0 +1,9 @@ +#include "hello.h" + +int add(int x, int y) { + return x + y; +} + +// C:\Users\user\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\bin +// xtensa-esp32-elf-gcc.exe -c hello.cpp -o hello.o +// xtensa-esp32-elf-ar.exe crf hello.a hello.o diff --git a/lib/hello.h b/lib/hello.h new file mode 100644 index 0000000..617ff74 --- /dev/null +++ b/lib/hello.h @@ -0,0 +1,6 @@ +#ifndef HELLO_H +#define HELLO_H + +int add(int x, int y); + +#endif \ No newline at end of file