Skip to content

Commit 2fd422e

Browse files
committed
Rearrange code to use just two anonymous namespace blocks for compilation-unit local linkage.
1 parent 0c8556b commit 2fd422e

File tree

1 file changed

+47
-50
lines changed

1 file changed

+47
-50
lines changed

cores/esp8266/core_esp8266_wiring_digital.cpp

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -115,38 +115,56 @@ namespace
115115
voidFuncPtr fn;
116116
std::function<void()> functional;
117117
};
118-
}
119118

120-
static interrupt_handler_t interrupt_handlers[16] = { {0, nullptr, nullptr}, };
121-
static uint32_t interrupt_reg = 0;
119+
static interrupt_handler_t interrupt_handlers[16] = { {0, nullptr, nullptr}, };
120+
static uint32_t interrupt_reg = 0;
122121

123-
void ICACHE_RAM_ATTR interrupt_handler(void *arg, void *frame)
124-
{
125-
(void) arg;
126-
(void) frame;
127-
uint32_t status = GPIE;
128-
GPIEC = status;//clear them interrupts
129-
uint32_t levels = GPI;
130-
if(status == 0 || interrupt_reg == 0) return;
131-
ETS_GPIO_INTR_DISABLE();
132-
int i = 0;
133-
uint32_t changedbits = status & interrupt_reg;
134-
while(changedbits){
135-
while(!(changedbits & (1 << i))) i++;
136-
changedbits &= ~(1 << i);
137-
interrupt_handler_t *handler = &interrupt_handlers[i];
138-
if (handler->mode == CHANGE ||
139-
(handler->mode & 1) == !!(levels & (1 << i))) {
140-
// to make ISR compatible to Arduino AVR model where interrupts are disabled
141-
// we disable them before we call the client ISR
142-
esp8266::InterruptLock irqLock; // stop other interrupts
143-
if (handler->fn)
144-
handler->fn();
145-
else
146-
handler->functional();
122+
void ICACHE_RAM_ATTR set_interrupt_handlers(uint8_t pin, voidFuncPtr userFunc, uint8_t mode)
123+
{
124+
interrupt_handler_t* handler = &interrupt_handlers[pin];
125+
handler->fn = userFunc;
126+
handler->functional = nullptr;
127+
if (userFunc)
128+
handler->mode = mode;
129+
}
130+
131+
void ICACHE_RAM_ATTR interrupt_handler(void *arg, void *frame)
132+
{
133+
(void) arg;
134+
(void) frame;
135+
uint32_t status = GPIE;
136+
GPIEC = status;//clear them interrupts
137+
uint32_t levels = GPI;
138+
if (status == 0 || interrupt_reg == 0) return;
139+
ETS_GPIO_INTR_DISABLE();
140+
int i = 0;
141+
uint32_t changedbits = status & interrupt_reg;
142+
while (changedbits) {
143+
while (!(changedbits & (1 << i))) i++;
144+
changedbits &= ~(1 << i);
145+
interrupt_handler_t* handler = &interrupt_handlers[i];
146+
if (handler->mode == CHANGE ||
147+
(handler->mode & 1) == !!(levels & (1 << i))) {
148+
// to make ISR compatible to Arduino AVR model where interrupts are disabled
149+
// we disable them before we call the client ISR
150+
esp8266::InterruptLock irqLock; // stop other interrupts
151+
if (handler->fn)
152+
handler->fn();
153+
else
154+
handler->functional();
155+
}
156+
}
157+
ETS_GPIO_INTR_ENABLE();
158+
}
159+
160+
void set_interrupt_reg(uint8_t pin, int mode)
161+
{
162+
interrupt_reg |= (1 << pin);
163+
GPC(pin) &= ~(0xF << GPCI);//INT mode disabled
164+
GPIEC = (1 << pin); //Clear Interrupt for this pin
165+
GPC(pin) |= ((mode & 0xF) << GPCI);//INT mode "mode"
166+
ETS_GPIO_INTR_ATTACH(interrupt_handler, &interrupt_reg);
147167
}
148-
}
149-
ETS_GPIO_INTR_ENABLE();
150168
}
151169

152170
extern void __attachInterruptArg(uint8_t pin, voidFuncPtrArg userFunc, void* arg, int mode)
@@ -163,27 +181,6 @@ extern void __attachInterruptArg(uint8_t pin, voidFuncPtrArg userFunc, void* arg
163181
attachInterrupt(pin, std::bind(userFunc, arg), mode);
164182
}
165183

166-
namespace
167-
{
168-
void set_interrupt_reg(uint8_t pin, int mode)
169-
{
170-
interrupt_reg |= (1 << pin);
171-
GPC(pin) &= ~(0xF << GPCI);//INT mode disabled
172-
GPIEC = (1 << pin); //Clear Interrupt for this pin
173-
GPC(pin) |= ((mode & 0xF) << GPCI);//INT mode "mode"
174-
ETS_GPIO_INTR_ATTACH(interrupt_handler, &interrupt_reg);
175-
}
176-
177-
void set_interrupt_handlers(uint8_t pin, voidFuncPtr userFunc, uint8_t mode)
178-
{
179-
interrupt_handler_t* handler = &interrupt_handlers[pin];
180-
handler->fn = userFunc;
181-
handler->functional = nullptr;
182-
if (userFunc)
183-
handler->mode = mode;
184-
}
185-
}
186-
187184
extern void __attachInterrupt(uint8_t pin, voidFuncPtr userFunc, int mode)
188185
{
189186
// #5780

0 commit comments

Comments
 (0)