Skip to content

Commit f75a184

Browse files
committed
Initial commit
0 parents  commit f75a184

12 files changed

+1582
-0
lines changed

LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2018 Alex Duchesne
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

README.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
ArduinoLite is a lightweight Arduino library for the ESP32. My goal was to provide the minimum needed to be able to use Arduino sensors libraries with little to no change.
2+
3+
Arduino-esp32 is a great project but it is just a port of Arduino-esp8266 and as such it contains custom, incomplete,
4+
and often buggy implementations of the various peripherals (I2C, SD Card, Wifi, SPI, etc). This becomes an issue if
5+
most of your project is written in native esp-idf code as it may cause conflicts or hard to track down bugs. ArduinoLite
6+
is a wrapper around the native esp-idf API.
7+
8+
## Features
9+
10+
Currently implemented:
11+
- The basic functions (pinMode, digitalWrite, millis, etc)
12+
- The Wire library
13+
- The WiFi library
14+
- The String library
15+
16+
To be implemented:
17+
- SPI
18+
19+
Could be added for convenience:
20+
- Stream/Print/Serial (To make display libraries work with no changes)
21+
- SD (to avoid all the boilerplate esp-idf code)
22+
23+
Out of scope:
24+
- The rest
25+
26+
27+
## Credits:
28+
- The WString is taken from Arduino (AVR)

component.mk

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#
2+
# Component Makefile
3+
#
4+
# This Makefile should, at the very least, just include $(SDK_PATH)/make/component.mk. By default,
5+
# this will take the sources in the src/ directory, compile them and link them into
6+
# lib(subdirectory_name).a in the build directory. This behaviour is entirely configurable,
7+
# please read the SDK documents if you need to do this.
8+
#
9+
10+
COMPONENT_SRCDIRS := src
11+
COMPONENT_ADD_INCLUDEDIRS := src

src/Arduino.h

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#ifndef ArduinoLite_h
2+
#define ArduinoLite_h
3+
4+
#include "driver/gpio.h"
5+
#include "esp_timer.h"
6+
#include "esp_log.h"
7+
#include "unistd.h"
8+
#include "WString.h"
9+
10+
#ifdef __cplusplus
11+
#include <algorithm>
12+
#include <cmath>
13+
using std::abs;
14+
using std::cos;
15+
using std::sin;
16+
using std::tan;
17+
using std::max;
18+
using std::min;
19+
#endif
20+
21+
typedef bool boolean;
22+
typedef uint8_t byte;
23+
typedef unsigned int word;
24+
25+
#define F_CPU (CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ * 1000000U)
26+
27+
#define LSBFIRST 0
28+
#define MSBFIRST 1
29+
30+
#define LOW 0x0
31+
#define HIGH 0x1
32+
#define INPUT GPIO_MODE_INPUT|(GPIO_FLOATING << 8)
33+
#define INPUT_PULLUP GPIO_MODE_INPUT|(GPIO_PULLUP_ONLY << 8)
34+
#define INPUT_PULLDOWN GPIO_MODE_INPUT|(GPIO_PULLDOWN_ONLY << 8)
35+
#define OUTPUT GPIO_MODE_OUTPUT|(GPIO_FLOATING << 8)
36+
37+
#define pinMode(pin, mode) gpio_set_direction((gpio_num_t)(pin), (gpio_mode_t)((mode) & 0xFF)); \
38+
gpio_set_pull_mode((gpio_num_t)(pin), (gpio_pull_mode_t)((mode) >> 8))
39+
#define digitalWrite(pin, val) gpio_set_level((gpio_num_t)(pin), (uint32_t)(val))
40+
#define digitalRead(pin) gpio_get_level((gpio_num_t)(pin))
41+
#define digitalPinIsValid(pin) ((pin) < 40)
42+
#define digitalPinCanOutput(pin) ((pin) < 34)
43+
#define digitalPinToInterrupt(pin) (digitalPinIsValid(pin) ? (pin) : -1)
44+
#define digitalPinHasPWM(pin) (digitalPinCanOutput(pin))
45+
46+
#define analogWrite(pin, val)
47+
#define analogRead(pin)
48+
49+
#define attachInterrupt(pin, cb, mode)
50+
#define attachInterruptArg(pin, cb, arg, mode)
51+
#define detachInterrupt(pin)
52+
53+
#define micros() ((unsigned long)esp_timer_get_time())
54+
#define millis() ((unsigned long)(esp_timer_get_time() / 1000ULL))
55+
#define delay(ms) delayMicroseconds((ms) * 1000)
56+
#define delayMicroseconds(us) usleep(us)
57+
#define yield() vPortYield()
58+
#define NOP() asm volatile ("nop")
59+
#define PROGMEM
60+
61+
#define pgm_read_byte(addr) (*(const unsigned char *)(addr))
62+
#define pgm_read_word(addr) ({ typeof(addr) _addr = (addr); *(const unsigned short *)(_addr); })
63+
#define pgm_read_dword(addr) ({ typeof(addr) _addr = (addr); *(const unsigned long *)(_addr); })
64+
#define pgm_read_float(addr) ({ typeof(addr) _addr = (addr); *(const float *)(_addr); })
65+
#define pgm_read_ptr(addr) ({ typeof(addr) _addr = (addr); *(void * const *)(_addr); })
66+
67+
inline long map(long x, long in_min, long in_max, long out_min, long out_max) {
68+
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
69+
}
70+
71+
inline void interrupts() {}
72+
inline void noInterrupts() {}
73+
74+
// To do:
75+
// pulseIn()
76+
// pulseInLong()
77+
// shiftIn()
78+
// shiftOut()
79+
// bit()
80+
// bitClear()
81+
// bitRead()
82+
// bitSet()
83+
// bitWrite()
84+
// highByte()
85+
// lowByte()
86+
87+
#endif

src/SPI.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "SPI.h"

src/SPI.h

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#ifndef _SPI_H_
2+
#define _SPI_H_
3+
4+
#include "inttypes.h"
5+
#include "string.h"
6+
#include "stddef.h"
7+
#include "esp_log.h"
8+
9+
#define SPI_HAS_TRANSACTION 1
10+
#define SPI_HAS_NOTUSINGINTERRUPT 1
11+
#define SPI_ATOMIC_VERSION 1
12+
13+
#define SPI_CLOCK_DIV4 0x00
14+
#define SPI_CLOCK_DIV16 0x01
15+
#define SPI_CLOCK_DIV64 0x02
16+
#define SPI_CLOCK_DIV128 0x03
17+
#define SPI_CLOCK_DIV2 0x04
18+
#define SPI_CLOCK_DIV8 0x05
19+
#define SPI_CLOCK_DIV32 0x06
20+
21+
#define SPI_MODE0 0x00
22+
#define SPI_MODE1 0x04
23+
#define SPI_MODE2 0x08
24+
#define SPI_MODE3 0x0C
25+
26+
#ifndef LSBFIRST
27+
#define LSBFIRST 0
28+
#endif
29+
#ifndef MSBFIRST
30+
#define MSBFIRST 1
31+
#endif
32+
33+
class SPISettings
34+
{
35+
public:
36+
SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) {}
37+
SPISettings() { SPISettings(4000000, MSBFIRST, SPI_MODE0); }
38+
};
39+
40+
class SPIClass
41+
{
42+
public:
43+
static void begin() {}
44+
static void end() {}
45+
static void usingInterrupt(uint8_t interruptNumber) {}
46+
static void notUsingInterrupt(uint8_t interruptNumber) {}
47+
static void beginTransaction(SPISettings settings) {}
48+
static uint8_t transfer(uint8_t data) { return 0;}
49+
static uint16_t transfer16(uint16_t data) { return 0;}
50+
static void transfer(void *buf, size_t count) {}
51+
static void endTransaction(void) {}
52+
static void setBitOrder(uint8_t bitOrder) {}
53+
static void setDataMode(uint8_t dataMode) {}
54+
static void setClockDivider(uint8_t clockDiv) {}
55+
};
56+
57+
extern SPIClass SPI;
58+
59+
#endif

0 commit comments

Comments
 (0)