Skip to content

Commit 8e02ca5

Browse files
committed
Merge branch 'esp8266' of https://github.com/ficeto/Arduino into esp8266
Conflicts: hardware/esp8266com/esp8266/libraries/ESP8266WebServer/examples/SDWebServer/SDWebServer.ino
2 parents a1967b9 + 9436222 commit 8e02ca5

Some content is hidden

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

53 files changed

+3605
-3536
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ else they default to pins 4(SDA) and 5(SCL).
132132

133133
#### SPI ####
134134

135-
SPI library supports the entire Arduino SPI API including transactions, including setting phase and polarity.
135+
SPI library supports the entire Arduino SPI API including transactions, including setting phase (CPHA).
136+
Setting the Clock polarity (CPOL) is not supported, yet (SPI_MODE2 and SPI_MODE3 not working).
136137

137138
#### ESP-specific APIs ####
138139

docs/esp8266_tcp_active_close.png

130 KB
Loading

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

+12-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,17 @@ void timer1_write(uint32_t ticks); //maximum ticks 8388607
124124
void ets_intr_lock();
125125
void ets_intr_unlock();
126126

127-
#define interrupts() ets_intr_unlock();
128-
#define noInterrupts() ets_intr_lock();
127+
// level (0-15),
128+
// level 15 will disable ALL interrupts,
129+
// level 0 will disable most software interrupts
130+
//
131+
#define xt_disable_interrupts(state, level) __asm__ __volatile__("rsil %0," __STRINGIFY(level) "; esync; isync; dsync" : "=a" (state))
132+
#define xt_enable_interrupts(state) __asm__ __volatile__("wsr %0,ps; esync" :: "a" (state) : "memory")
133+
134+
extern uint32_t interruptsState;
135+
136+
#define interrupts() xt_enable_interrupts(interruptsState)
137+
#define noInterrupts() xt_disable_interrupts(interruptsState, 15)
129138

130139
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
131140
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
@@ -163,6 +172,7 @@ int digitalRead(uint8_t);
163172
int analogRead(uint8_t);
164173
void analogReference(uint8_t mode);
165174
void analogWrite(uint8_t, int);
175+
void analogWriteFreq(uint32_t freq);
166176

167177
unsigned long millis(void);
168178
unsigned long micros(void);

hardware/esp8266com/esp8266/cores/esp8266/Esp.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,13 @@ FlashMode_t EspClass::getFlashChipMode(void)
227227
*/
228228
uint32_t EspClass::getFlashChipSizeByChipId(void) {
229229
uint32_t chipId = getFlashChipId();
230+
/**
231+
* Chip ID
232+
* 00 - always 00 (Chip ID use only 3 byte)
233+
* 17 - ? looks like 2^xx is size in Byte ? //todo: find docu to this
234+
* 40 - ? may be Speed ? //todo: find docu to this
235+
* C8 - manufacturer ID
236+
*/
230237
switch(chipId) {
231238

232239
// GigaDevice

hardware/esp8266com/esp8266/cores/esp8266/Esp.h

+8
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,16 @@ class EspClass {
9595
FlashMode_t getFlashChipMode(void);
9696
uint32_t getFlashChipSizeByChipId(void);
9797

98+
inline uint32_t getCycleCount(void);
9899
};
99100

101+
uint32_t EspClass::getCycleCount(void)
102+
{
103+
uint32_t ccount;
104+
__asm__ __volatile__("rsr %0,ccount":"=a" (ccount));
105+
return ccount;
106+
}
107+
100108
extern EspClass ESP;
101109

102110
#endif //ESP_H

hardware/esp8266com/esp8266/cores/esp8266/HardwareSerial.cpp

+6-27
Original file line numberDiff line numberDiff line change
@@ -118,50 +118,29 @@ int uart_get_debug();
118118
void ICACHE_RAM_ATTR uart_interrupt_handler(uart_t* uart) {
119119

120120
// -------------- UART 0 --------------
121-
uint32_t status = U0IS;
122121
if(Serial.isRxEnabled()) {
123-
if(status & (1 << UIFF)) {
124-
while(true) {
125-
int rx_count = (U0S >> USTXC) & 0xff;
126-
if(!rx_count)
127-
break;
128-
129-
while(rx_count--) {
130-
char c = U0F & 0xff;
131-
Serial._rx_complete_irq(c);
132-
}
133-
}
122+
while(U0IS & (1 << UIFF)) {
123+
Serial._rx_complete_irq((char)(U0F & 0xff));
134124
U0IC = (1 << UIFF);
135125
}
136126
}
137127
if(Serial.isTxEnabled()) {
138-
if(status & (1 << UIFE)) {
128+
if(U0IS & (1 << UIFE)) {
139129
U0IC = (1 << UIFE);
140130
Serial._tx_empty_irq();
141131
}
142132
}
143133

144134
// -------------- UART 1 --------------
145135

146-
status = U1IS;
147136
if(Serial1.isRxEnabled()) {
148-
if(status & (1 << UIFF)) {
149-
while(true) {
150-
int rx_count = (U1S >> USTXC) & 0xff;
151-
if(!rx_count)
152-
break;
153-
154-
while(rx_count--) {
155-
char c = U1F & 0xff;
156-
Serial1._rx_complete_irq(c);
157-
}
158-
}
137+
while(U1IS & (1 << UIFF)) {
138+
Serial1._rx_complete_irq((char)(U1F & 0xff));
159139
U1IC = (1 << UIFF);
160140
}
161141
}
162142
if(Serial1.isTxEnabled()) {
163-
status = U1IS;
164-
if(status & (1 << UIFE)) {
143+
if(U1IS & (1 << UIFE)) {
165144
U1IC = (1 << UIFE);
166145
Serial1._tx_empty_irq();
167146
}

hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_timer.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ void timer1_isr_handler(void *para){
3030
if(timer1_user_cb) timer1_user_cb();
3131
}
3232

33+
void timer1_isr_init(){
34+
ETS_FRC_TIMER1_INTR_ATTACH(timer1_isr_handler, NULL);
35+
}
36+
3337
void timer1_attachInterrupt(void (*userFunc)(void)) {
3438
timer1_user_cb = userFunc;
3539
ETS_FRC1_INTR_ENABLE();
@@ -55,7 +59,3 @@ void timer1_disable(){
5559
T1C = 0;
5660
T1I = 0;
5761
}
58-
59-
void timer1_isr_init(){
60-
ETS_FRC_TIMER1_INTR_ATTACH(timer1_isr_handler, NULL);
61-
}

hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring.c

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ void delayMicroseconds(unsigned int us) {
7575

7676
void init() {
7777
initPins();
78+
timer1_isr_init();
7879
os_timer_setfn(&micros_overflow_timer, (os_timer_func_t*) &micros_overflow_tick, 0);
7980
os_timer_arm(&micros_overflow_timer, 60000, REPEAT);
8081
}

hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring_digital.c

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ extern void __detachInterrupt(uint8_t pin) {
139139
}
140140
}
141141

142+
// stored state for the noInterrupts/interrupts methods
143+
uint32_t interruptsState = 0;
144+
142145
void initPins() {
143146
//Disable UART interrupts
144147
system_set_os_print(0);

hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_wiring_pwm.c

+6
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,10 @@ extern void __analogWrite(uint8_t pin, int value) {
139139
}
140140
}
141141

142+
extern void __analogWriteFreq(uint32_t freq){
143+
pwm_freq = freq;
144+
prep_pwm_steps();
145+
}
146+
142147
extern void analogWrite(uint8_t pin, int val) __attribute__ ((weak, alias("__analogWrite")));
148+
extern void analogWriteFreq(uint32_t freq) __attribute__ ((weak, alias("__analogWriteFreq")));

0 commit comments

Comments
 (0)