1- /*
1+ /*
22 digital.c - wiring digital implementation for esp8266
33
44 Copyright (c) 2015 Hristo Gochkov. All rights reserved.
55 This file is part of the esp8266 core for Arduino environment.
6-
6+
77 This library is free software; you can redistribute it and/or
88 modify it under the terms of the GNU Lesser General Public
99 License as published by the Free Software Foundation; either
2525#include "eagle_soc.h"
2626#include "ets_sys.h"
2727
28+ extern void pwm_stop_pin (uint8_t pin );
29+
2830uint8_t esp8266_gpioToFn [16 ] = {0x34 , 0x18 , 0x38 , 0x14 , 0x3C , 0x40 , 0x1C , 0x20 , 0x24 , 0x28 , 0x2C , 0x30 , 0x04 , 0x08 , 0x0C , 0x10 };
2931
3032extern void __pinMode (uint8_t pin , uint8_t mode ) {
33+ pwm_stop_pin (pin );
3134 if (pin < 16 ){
3235 if (mode == SPECIAL ){
3336 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) {
7780}
7881
7982extern void ICACHE_RAM_ATTR __digitalWrite (uint8_t pin , uint8_t val ) {
83+ pwm_stop_pin (pin );
8084 if (pin < 16 ){
8185 if (val ) GPOS = (1 << pin );
8286 else GPOC = (1 << pin );
@@ -87,6 +91,7 @@ extern void ICACHE_RAM_ATTR __digitalWrite(uint8_t pin, uint8_t val) {
8791}
8892
8993extern int ICACHE_RAM_ATTR __digitalRead (uint8_t pin ) {
94+ pwm_stop_pin (pin );
9095 if (pin < 16 ){
9196 return GPIP (pin );
9297 } else if (pin == 16 ){
@@ -121,12 +126,12 @@ void ICACHE_RAM_ATTR interrupt_handler(void *arg) {
121126 while (!(changedbits & (1 << i ))) i ++ ;
122127 changedbits &= ~(1 << i );
123128 interrupt_handler_t * handler = & interrupt_handlers [i ];
124- if (handler -> fn &&
125- (handler -> mode == CHANGE ||
129+ if (handler -> fn &&
130+ (handler -> mode == CHANGE ||
126131 (handler -> mode & 1 ) == !!(levels & (1 << i )))) {
127132 // to make ISR compatible to Arduino AVR model where interrupts are disabled
128133 // 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
130135 handler -> fn ();
131136 xt_wsr_ps (savedPS );
132137 }
@@ -170,7 +175,7 @@ void initPins() {
170175 for (int i = 12 ; i <= 16 ; ++ i ) {
171176 pinMode (i , INPUT );
172177 }
173-
178+
174179 ETS_GPIO_INTR_ATTACH (interrupt_handler , & interrupt_reg );
175180 ETS_GPIO_INTR_ENABLE ();
176181}
@@ -180,4 +185,3 @@ extern void digitalWrite(uint8_t pin, uint8_t val) __attribute__ ((weak, alias("
180185extern int digitalRead (uint8_t pin ) __attribute__ ((weak , alias ("__digitalRead" )));
181186extern void attachInterrupt (uint8_t pin , voidFuncPtr handler , int mode ) __attribute__ ((weak , alias ("__attachInterrupt" )));
182187extern void detachInterrupt (uint8_t pin ) __attribute__ ((weak , alias ("__detachInterrupt" )));
183-
0 commit comments