Skip to content

Commit 5f3a205

Browse files
me-no-devigrr
authored andcommitted
initial import
1 parent 668acc2 commit 5f3a205

File tree

657 files changed

+170176
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

657 files changed

+170176
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
tools/xtensa-esp32-elf

boards.txt

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
menu.UploadSpeed=Upload Speed
2+
menu.FlashFreq=Flash Frequency
3+
4+
##############################################################
5+
esp32.name=ESP32 Dev Module
6+
7+
esp32.upload.tool=esptool
8+
esp32.upload.maximum_size=1044464
9+
esp32.upload.maximum_data_size=114688
10+
esp32.upload.wait_for_upload_port=true
11+
12+
esp32.serial.disableDTR=true
13+
esp32.serial.disableRTS=true
14+
15+
esp32.build.mcu=esp32
16+
esp32.build.core=esp32
17+
esp32.build.variant=esp32
18+
esp32.build.board=ESP32_DEV
19+
20+
esp32.build.f_cpu=160000000L
21+
esp32.build.flash_mode=dio
22+
esp32.build.flash_size=4MB
23+
24+
esp32.menu.FlashFreq.80=80MHz
25+
esp32.menu.FlashFreq.80.build.flash_freq=80m
26+
esp32.menu.FlashFreq.40=40MHz
27+
esp32.menu.FlashFreq.40.build.flash_freq=40m
28+
29+
esp32.menu.UploadSpeed.921600=921600
30+
esp32.menu.UploadSpeed.921600.upload.speed=921600
31+
esp32.menu.UploadSpeed.115200=115200
32+
esp32.menu.UploadSpeed.115200.upload.speed=115200
33+
esp32.menu.UploadSpeed.256000.windows=256000
34+
esp32.menu.UploadSpeed.256000.upload.speed=256000
35+
esp32.menu.UploadSpeed.230400.windows.upload.speed=256000
36+
esp32.menu.UploadSpeed.230400=230400
37+
esp32.menu.UploadSpeed.230400.upload.speed=230400
38+
esp32.menu.UploadSpeed.460800.linux=460800
39+
esp32.menu.UploadSpeed.460800.macosx=460800
40+
esp32.menu.UploadSpeed.460800.upload.speed=460800
41+
esp32.menu.UploadSpeed.512000.windows=512000
42+
esp32.menu.UploadSpeed.512000.upload.speed=512000

cores/esp32/Arduino.h

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
Arduino.h - Main include file for the Arduino SDK
3+
Copyright (c) 2005-2013 Arduino Team. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#ifndef Arduino_h
21+
#define Arduino_h
22+
23+
#ifdef __cplusplus
24+
extern "C" {
25+
#endif
26+
27+
#include "freertos/FreeRTOS.h"
28+
#include "freertos/task.h"
29+
#include "freertos/semphr.h"
30+
#include "esp32-hal.h"
31+
#include "pins_arduino.h"
32+
33+
#include <stdbool.h>
34+
#include <stdint.h>
35+
#include <stdarg.h>
36+
#include <stddef.h>
37+
#include <stdio.h>
38+
#include <stdlib.h>
39+
#include <string.h>
40+
#include <inttypes.h>
41+
42+
typedef bool boolean;
43+
typedef uint8_t byte;
44+
45+
#include "binary.h"
46+
47+
#ifdef __cplusplus
48+
}
49+
#endif
50+
51+
#include "WCharacter.h"
52+
#include "WString.h"
53+
#include "Stream.h"
54+
#include "Printable.h"
55+
#include "Print.h"
56+
#include "IPAddress.h"
57+
#include "Client.h"
58+
#include "Server.h"
59+
#include "Udp.h"
60+
#include "HardwareSerial.h"
61+
#include "Esp.h"
62+
63+
#endif /* _ESP32_CORE_ARDUINO_H_ */

cores/esp32/Client.h

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
Client.h - Base class that provides Client
3+
Copyright (c) 2011 Adrian McEwen. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#ifndef client_h
21+
#define client_h
22+
#include "Print.h"
23+
#include "Stream.h"
24+
#include "IPAddress.h"
25+
26+
class Client: public Stream
27+
{
28+
public:
29+
virtual int connect(IPAddress ip, uint16_t port) =0;
30+
virtual int connect(const char *host, uint16_t port) =0;
31+
virtual size_t write(uint8_t) =0;
32+
virtual size_t write(const uint8_t *buf, size_t size) =0;
33+
virtual int available() = 0;
34+
virtual int read() = 0;
35+
virtual int read(uint8_t *buf, size_t size) = 0;
36+
virtual int peek() = 0;
37+
virtual void flush() = 0;
38+
virtual void stop() = 0;
39+
virtual uint8_t connected() = 0;
40+
virtual operator bool() = 0;
41+
protected:
42+
uint8_t* rawIPAddress(IPAddress& addr)
43+
{
44+
return addr.raw_address();
45+
}
46+
};
47+
48+
#endif

cores/esp32/Esp.cpp

+223
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
/*
2+
Esp.cpp - ESP31B-specific APIs
3+
Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#include "Arduino.h"
21+
#include "Esp.h"
22+
#include "rom/spi_flash.h"
23+
#include <memory>
24+
25+
//#define DEBUG_SERIAL Serial
26+
27+
28+
/**
29+
* User-defined Literals
30+
* usage:
31+
*
32+
* uint32_t = test = 10_MHz; // --> 10000000
33+
*/
34+
35+
unsigned long long operator"" _kHz(unsigned long long x)
36+
{
37+
return x * 1000;
38+
}
39+
40+
unsigned long long operator"" _MHz(unsigned long long x)
41+
{
42+
return x * 1000 * 1000;
43+
}
44+
45+
unsigned long long operator"" _GHz(unsigned long long x)
46+
{
47+
return x * 1000 * 1000 * 1000;
48+
}
49+
50+
unsigned long long operator"" _kBit(unsigned long long x)
51+
{
52+
return x * 1024;
53+
}
54+
55+
unsigned long long operator"" _MBit(unsigned long long x)
56+
{
57+
return x * 1024 * 1024;
58+
}
59+
60+
unsigned long long operator"" _GBit(unsigned long long x)
61+
{
62+
return x * 1024 * 1024 * 1024;
63+
}
64+
65+
unsigned long long operator"" _kB(unsigned long long x)
66+
{
67+
return x * 1024;
68+
}
69+
70+
unsigned long long operator"" _MB(unsigned long long x)
71+
{
72+
return x * 1024 * 1024;
73+
}
74+
75+
unsigned long long operator"" _GB(unsigned long long x)
76+
{
77+
return x * 1024 * 1024 * 1024;
78+
}
79+
80+
81+
EspClass ESP;
82+
83+
uint32_t EspClass::getCycleCount()
84+
{
85+
uint32_t ccount;
86+
__asm__ __volatile__("esync; rsr %0,ccount":"=a" (ccount));
87+
return ccount;
88+
}
89+
90+
void EspClass::restart(void)
91+
{
92+
system_restart();
93+
}
94+
95+
uint32_t EspClass::getFreeHeap(void)
96+
{
97+
return system_get_free_heap_size();
98+
}
99+
100+
const char * EspClass::getSdkVersion(void)
101+
{
102+
return system_get_sdk_version();
103+
}
104+
105+
uint32_t EspClass::getFlashChipSize(void)
106+
{
107+
uint32_t data;
108+
uint8_t * bytes = (uint8_t *) &data;
109+
// read first 4 byte (magic byte + flash config)
110+
if(SPIRead(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) {
111+
return magicFlashChipSize((bytes[3] & 0xf0) >> 4);
112+
}
113+
return 0;
114+
}
115+
116+
uint32_t EspClass::getFlashChipSpeed(void)
117+
{
118+
uint32_t data;
119+
uint8_t * bytes = (uint8_t *) &data;
120+
// read first 4 byte (magic byte + flash config)
121+
if(SPIRead(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) {
122+
return magicFlashChipSpeed(bytes[3] & 0x0F);
123+
}
124+
return 0;
125+
}
126+
127+
FlashMode_t EspClass::getFlashChipMode(void)
128+
{
129+
FlashMode_t mode = FM_UNKNOWN;
130+
uint32_t data;
131+
uint8_t * bytes = (uint8_t *) &data;
132+
// read first 4 byte (magic byte + flash config)
133+
if(SPIRead(0x0000, &data, 4) == SPI_FLASH_RESULT_OK) {
134+
mode = magicFlashChipMode(bytes[2]);
135+
}
136+
return mode;
137+
}
138+
139+
uint32_t EspClass::magicFlashChipSize(uint8_t byte)
140+
{
141+
switch(byte & 0x0F) {
142+
case 0x0: // 4 Mbit (512KB)
143+
return (512_kB);
144+
case 0x1: // 2 MBit (256KB)
145+
return (256_kB);
146+
case 0x2: // 8 MBit (1MB)
147+
return (1_MB);
148+
case 0x3: // 16 MBit (2MB)
149+
return (2_MB);
150+
case 0x4: // 32 MBit (4MB)
151+
return (4_MB);
152+
case 0x5: // 64 MBit (8MB)
153+
return (8_MB);
154+
case 0x6: // 128 MBit (16MB)
155+
return (16_MB);
156+
case 0x7: // 256 MBit (32MB)
157+
return (32_MB);
158+
default: // fail?
159+
return 0;
160+
}
161+
}
162+
163+
uint32_t EspClass::magicFlashChipSpeed(uint8_t byte)
164+
{
165+
switch(byte & 0x0F) {
166+
case 0x0: // 40 MHz
167+
return (40_MHz);
168+
case 0x1: // 26 MHz
169+
return (26_MHz);
170+
case 0x2: // 20 MHz
171+
return (20_MHz);
172+
case 0xf: // 80 MHz
173+
return (80_MHz);
174+
default: // fail?
175+
return 0;
176+
}
177+
}
178+
179+
FlashMode_t EspClass::magicFlashChipMode(uint8_t byte)
180+
{
181+
FlashMode_t mode = (FlashMode_t) byte;
182+
if(mode > FM_DOUT) {
183+
mode = FM_UNKNOWN;
184+
}
185+
return mode;
186+
}
187+
188+
bool EspClass::eraseConfig(void)
189+
{
190+
bool ret = true;
191+
size_t cfgAddr = (getFlashChipSize() - 0x4000);
192+
size_t cfgSize = (8*1024);
193+
194+
while(cfgSize) {
195+
196+
if(SPIEraseSector((cfgAddr / 4096)) != SPI_FLASH_RESULT_OK) {
197+
ret = false;
198+
}
199+
200+
cfgSize -= 4096;
201+
cfgAddr += 4096;
202+
}
203+
204+
return ret;
205+
}
206+
207+
bool EspClass::flashEraseSector(uint32_t sector)
208+
{
209+
int rc = SPIEraseSector(sector);
210+
return rc == 0;
211+
}
212+
213+
bool EspClass::flashWrite(uint32_t offset, uint32_t *data, size_t size)
214+
{
215+
int rc = SPIWrite(offset, (uint32_t*) data, size);
216+
return rc == 0;
217+
}
218+
219+
bool EspClass::flashRead(uint32_t offset, uint32_t *data, size_t size)
220+
{
221+
int rc = SPIRead(offset, (uint32_t*) data, size);
222+
return rc == 0;
223+
}

0 commit comments

Comments
 (0)