1
- /*
1
+ /*
2
2
digital.c - wiring digital implementation for esp8266
3
3
4
4
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
5
5
This file is part of the esp8266 core for Arduino environment.
6
-
6
+
7
7
This library is free software; you can redistribute it and/or
8
8
modify it under the terms of the GNU Lesser General Public
9
9
License as published by the Free Software Foundation; either
25
25
#include "eagle_soc.h"
26
26
#include "ets_sys.h"
27
27
28
+ extern void pwm_stop_pin (uint8_t pin );
29
+
28
30
uint8_t esp8266_gpioToFn [16 ] = {0x34 , 0x18 , 0x38 , 0x14 , 0x3C , 0x40 , 0x1C , 0x20 , 0x24 , 0x28 , 0x2C , 0x30 , 0x04 , 0x08 , 0x0C , 0x10 };
29
31
30
32
extern void __pinMode (uint8_t pin , uint8_t mode ) {
33
+ pwm_stop_pin (pin );
31
34
if (pin < 16 ){
32
35
if (mode == SPECIAL ){
33
36
GPC (pin ) = (GPC (pin ) & (0xF << GPCI )); //SOURCE(GPIO) | DRIVER(NORMAL) | INT_TYPE(UNCHANGED) | WAKEUP_ENABLE(DISABLED)
@@ -77,6 +80,7 @@ extern void __pinMode(uint8_t pin, uint8_t mode) {
77
80
}
78
81
79
82
extern void ICACHE_RAM_ATTR __digitalWrite (uint8_t pin , uint8_t val ) {
83
+ pwm_stop_pin (pin );
80
84
if (pin < 16 ){
81
85
if (val ) GPOS = (1 << pin );
82
86
else GPOC = (1 << pin );
@@ -87,6 +91,7 @@ extern void ICACHE_RAM_ATTR __digitalWrite(uint8_t pin, uint8_t val) {
87
91
}
88
92
89
93
extern int ICACHE_RAM_ATTR __digitalRead (uint8_t pin ) {
94
+ pwm_stop_pin (pin );
90
95
if (pin < 16 ){
91
96
return GPIP (pin );
92
97
} else if (pin == 16 ){
@@ -121,12 +126,12 @@ void ICACHE_RAM_ATTR interrupt_handler(void *arg) {
121
126
while (!(changedbits & (1 << i ))) i ++ ;
122
127
changedbits &= ~(1 << i );
123
128
interrupt_handler_t * handler = & interrupt_handlers [i ];
124
- if (handler -> fn &&
125
- (handler -> mode == CHANGE ||
129
+ if (handler -> fn &&
130
+ (handler -> mode == CHANGE ||
126
131
(handler -> mode & 1 ) == !!(levels & (1 << i )))) {
127
132
// to make ISR compatible to Arduino AVR model where interrupts are disabled
128
133
// we disable them before we call the client ISR
129
- uint32_t savedPS = xt_rsil (15 ); // stop other interrupts
134
+ uint32_t savedPS = xt_rsil (15 ); // stop other interrupts
130
135
handler -> fn ();
131
136
xt_wsr_ps (savedPS );
132
137
}
@@ -170,7 +175,7 @@ void initPins() {
170
175
for (int i = 12 ; i <= 16 ; ++ i ) {
171
176
pinMode (i , INPUT );
172
177
}
173
-
178
+
174
179
ETS_GPIO_INTR_ATTACH (interrupt_handler , & interrupt_reg );
175
180
ETS_GPIO_INTR_ENABLE ();
176
181
}
@@ -180,4 +185,3 @@ extern void digitalWrite(uint8_t pin, uint8_t val) __attribute__ ((weak, alias("
180
185
extern int digitalRead (uint8_t pin ) __attribute__ ((weak , alias ("__digitalRead" )));
181
186
extern void attachInterrupt (uint8_t pin , voidFuncPtr handler , int mode ) __attribute__ ((weak , alias ("__attachInterrupt" )));
182
187
extern void detachInterrupt (uint8_t pin ) __attribute__ ((weak , alias ("__detachInterrupt" )));
183
-
0 commit comments