Skip to content

Commit 83ed3d5

Browse files
ficetoficeto
ficeto
authored and
ficeto
committed
Importing my changes
1 parent 7e40b9f commit 83ed3d5

32 files changed

+1427
-1224
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,5 @@ avr-toolchain-*.zip
5656
/hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/
5757
/hardware/tools/bossac.exe
5858
/hardware/tools/listComPorts.exe
59+
60+
build/macosx/esptool-*-osx.zip

hardware/esp8266com/esp8266/cores/esp8266/Arduino.h

+48-11
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,27 @@ extern "C" {
3636
#include "stdlib_noniso.h"
3737
#include "binary.h"
3838
#include "pgmspace.h"
39+
#include "esp8266_peri.h"
40+
#include "si2c.h"
3941

4042
void yield(void);
4143

4244
#define HIGH 0x1
4345
#define LOW 0x0
4446

45-
#define INPUT 0x0
46-
#define OUTPUT 0x1
47-
#define INPUT_PULLUP 0x2
48-
#define INPUT_PULLDOWN 0x3
49-
#define OUTPUT_OPEN_DRAIN 0x4
47+
#define PWMRANGE 1023
48+
49+
//GPIO FUNCTIONS
50+
#define INPUT 0x00
51+
#define OUTPUT 0x01
52+
#define INPUT_PULLUP 0x02
53+
#define INPUT_PULLDOWN 0x04
54+
#define SPECIAL 0xF8 //defaults to the usable BUSes uart0rx/tx uart1tx and hspi
55+
#define FUNCTION_0 0x08
56+
#define FUNCTION_1 0x18
57+
#define FUNCTION_2 0x28
58+
#define FUNCTION_3 0x38
59+
#define FUNCTION_4 0x48
5060

5161
#define PI 3.1415926535897932384626433832795
5262
#define HALF_PI 1.5707963267948966192313216916398
@@ -61,13 +71,41 @@ void yield(void);
6171
#define LSBFIRST 0
6272
#define MSBFIRST 1
6373

64-
#define CHANGE 1
65-
#define FALLING 2
66-
#define RISING 3
74+
//Interrupt Modes
75+
#define DISABLED 0x00
76+
#define RISING 0x01
77+
#define FALLING 0x02
78+
#define CHANGE 0x03
79+
#define ONLOW 0x04
80+
#define ONHIGH 0x05
81+
#define ONLOW_WE 0x0C
82+
#define ONHIGH_WE 0x0D
6783

6884
#define DEFAULT 1
6985
#define EXTERNAL 0
7086

87+
//timer dividers
88+
#define TIM_DIV1 0 //80MHz (80 ticks/us - 104857.588 us max)
89+
#define TIM_DIV16 1 //5MHz (5 ticks/us - 1677721.4 us max)
90+
#define TIM_DIV265 3 //312.5Khz (1 tick = 3.2us - 26843542.4 us max)
91+
//timer int_types
92+
#define TIM_EDGE 0
93+
#define TIM_LEVEL 1
94+
//timer reload values
95+
#define TIM_SINGLE 0 //on interrupt routine you need to write a new value to start the timer again
96+
#define TIM_LOOP 1 //on interrupt the counter will start with the same value again
97+
98+
#define timer1_read() (T1V)
99+
#define timer1_enabled() ((T1C & (1 << TCTE)) != 0)
100+
#define timer1_interrupted() ((T1C & (1 << TCIS)) != 0)
101+
102+
void timer1_isr_init(void);
103+
void timer1_enable(uint8_t divider, uint8_t int_type, uint8_t reload);
104+
void timer1_disable(void);
105+
void timer1_attachInterrupt(void (*userFunc)(void));
106+
void timer1_detachInterrupt(void);
107+
void timer1_write(uint32_t ticks); //maximum ticks 8388607
108+
71109
// undefine stdlib's abs if encountered
72110
#ifdef abs
73111
#undef abs
@@ -145,13 +183,12 @@ void loop(void);
145183

146184
uint32_t digitalPinToPort(uint32_t pin);
147185
uint32_t digitalPinToBitMask(uint32_t pin);
148-
#define analogInPinToBit(P) (P)
149186
volatile uint32_t* portOutputRegister(uint32_t port);
150187
volatile uint32_t* portInputRegister(uint32_t port);
151188
volatile uint32_t* portModeRegister(uint32_t port);
152189

153-
#define NOT_A_PIN 0
154-
#define NOT_A_PORT 0
190+
#define NOT_A_PIN -1
191+
#define NOT_A_PORT -1
155192
#define NOT_AN_INTERRUPT -1
156193

157194
#ifdef __cplusplus
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
timer.c - Timer1 library for esp8266
3+
4+
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
5+
This file is part of the esp8266 core for Arduino environment.
6+
7+
This library is free software; you can redistribute it and/or
8+
modify it under the terms of the GNU Lesser General Public
9+
License as published by the Free Software Foundation; either
10+
version 2.1 of the License, or (at your option) any later version.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public
18+
License along with this library; if not, write to the Free Software
19+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20+
*/
21+
#include "wiring_private.h"
22+
#include "pins_arduino.h"
23+
#include "c_types.h"
24+
25+
void (*timer1_user_cb)(void);
26+
27+
void timer1_isr_handler(void *para){
28+
if((T1C & ((1 << TCAR) | (1 << TCIT))) == 0) TEIE &= ~TEIE1;//edge int disable
29+
T1I = 0;
30+
if(timer1_user_cb) timer1_user_cb();
31+
}
32+
33+
void timer1_attachInterrupt(void (*userFunc)(void)) {
34+
timer1_user_cb = userFunc;
35+
ETS_FRC1_INTR_ENABLE();
36+
}
37+
38+
void timer1_detachInterrupt() {
39+
timer1_user_cb = 0;
40+
TEIE &= ~TEIE1;//edge int disable
41+
ETS_FRC1_INTR_DISABLE();
42+
}
43+
44+
void timer1_enable(uint8_t divider, uint8_t int_type, uint8_t reload){
45+
T1C = (1 << TCTE) | ((divider & 3) << TCPD) | ((int_type & 1) << TCIT) | ((reload & 1) << TCAR);
46+
T1I = 0;
47+
}
48+
49+
void timer1_write(uint32_t ticks){
50+
T1L = ((ticks) & 0x7FFFFF);
51+
if((T1C & (1 << TCIT)) == 0) TEIE |= TEIE1;//edge int enable
52+
}
53+
54+
void timer1_disable(){
55+
T1C = 0;
56+
T1I = 0;
57+
}
58+
59+
void timer1_isr_init(){
60+
ETS_FRC_TIMER1_INTR_ATTACH(timer1_isr_handler, NULL);
61+
}
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,56 @@
11
/*
2-
core_esp8266_analog.c - an interface to the esp8266 ADC
2+
analog.c - analogRead implementation for esp8266
33
4-
Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
5-
This file is part of the esp8266 core for Arduino environment.
4+
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
5+
This file is part of the esp8266 core for Arduino environment.
66
7-
This library is free software; you can redistribute it and/or
8-
modify it under the terms of the GNU Lesser General Public
9-
License as published by the Free Software Foundation; either
10-
version 2.1 of the License, or (at your option) any later version.
11-
12-
This library is distributed in the hope that it will be useful,
13-
but WITHOUT ANY WARRANTY; without even the implied warranty of
14-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15-
Lesser General Public License for more details.
16-
17-
You should have received a copy of the GNU Lesser General Public
18-
License along with this library; if not, write to the Free Software
19-
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20-
*/
21-
7+
This library is free software; you can redistribute it and/or
8+
modify it under the terms of the GNU Lesser General Public
9+
License as published by the Free Software Foundation; either
10+
version 2.1 of the License, or (at your option) any later version.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public
18+
License along with this library; if not, write to the Free Software
19+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20+
*/
2221
#include "wiring_private.h"
2322
#include "pins_arduino.h"
2423

25-
void analogReference(uint8_t mode) {
26-
}
24+
void analogReference(uint8_t mode) {}
2725

2826
extern int __analogRead(uint8_t pin) {
29-
if(pin == 0)
30-
return system_adc_read();
31-
32-
return 0;
27+
if(pin == 17){
28+
//return system_adc_read();
29+
uint8_t i;
30+
uint16_t data[8];
31+
32+
rom_i2c_writeReg_Mask(0x6C,2,0,5,5,1);
33+
34+
ESP8266_REG(0xD5C) |= (1 << 21);
35+
while ((ESP8266_REG(0xD50) & (7 << 24)) > 0);
36+
ESP8266_REG(0xD50) &= ~(1 << 1);
37+
ESP8266_REG(0xD50) |= (1 << 1);
38+
delayMicroseconds(2);
39+
while ((ESP8266_REG(0xD50) & (7 << 24)) > 0);
40+
41+
read_sar_dout(data);
42+
rom_i2c_writeReg_Mask(0x6C,2,0,5,5,1);
43+
44+
while ((ESP8266_REG(0xD50) & (7 << 24)) > 0);
45+
ESP8266_REG(0xD5C) &= ~(1 << 21);
46+
ESP8266_REG(0xD60) |= (1 << 0);
47+
ESP8266_REG(0xD60) &= ~(1 << 0);
48+
49+
uint16_t tout = 0;
50+
for (i = 0; i < 8; i++) tout += data[i];
51+
return tout >> 4;//tout is 10 bits fraction
52+
}
53+
return digitalRead(pin) * 1023;
3354
}
3455

3556
extern int analogRead(uint8_t pin) __attribute__ ((weak, alias("__analogRead")));

0 commit comments

Comments
 (0)