mirror of https://github.com/jeelabs/esp-link.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.6 KiB
80 lines
1.6 KiB
10 years ago
|
#include <esp8266.h>
|
||
|
#include <serled.h>
|
||
|
|
||
|
static ETSTimer serledTimer;
|
||
|
static uint8_t serledPin;
|
||
|
|
||
|
static void ICACHE_FLASH_ATTR setSerled(int on) {
|
||
|
// LED is active-low
|
||
|
if (on) {
|
||
|
gpio_output_set(0, (1<<serledPin), (1<<serledPin), 0);
|
||
|
} else {
|
||
|
gpio_output_set((1<<serledPin), 0, (1<<serledPin), 0);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
static void ICACHE_FLASH_ATTR serledTimerCb(void *v) {
|
||
|
setSerled(0);
|
||
|
}
|
||
|
|
||
|
void ICACHE_FLASH_ATTR serledFlash(int duration) {
|
||
|
setSerled(1);
|
||
|
os_timer_disarm(&serledTimer);
|
||
|
os_timer_setfn(&serledTimer, serledTimerCb, NULL);
|
||
|
os_timer_arm(&serledTimer, duration, 0);
|
||
|
}
|
||
|
|
||
|
void ICACHE_FLASH_ATTR serledInit(uint8_t pin) {
|
||
|
serledPin = pin;
|
||
|
makeGpio(pin);
|
||
|
gpio_output_set(0, 0, (1<<pin), 0);
|
||
|
serledFlash(1000); // turn it on for 1 second
|
||
|
}
|
||
|
|
||
|
// Make a pin be GPIO, i.e. set the mux so the pin has the gpio function
|
||
|
void ICACHE_FLASH_ATTR makeGpio(uint8_t pin) {
|
||
|
uint32_t addr;
|
||
|
uint8_t func = 3;
|
||
|
switch (pin) {
|
||
|
case 0:
|
||
|
addr = PERIPHS_IO_MUX_GPIO0_U;
|
||
|
func = 0;
|
||
|
break;
|
||
|
case 1:
|
||
|
addr = PERIPHS_IO_MUX_U0TXD_U;
|
||
|
break;
|
||
|
case 2:
|
||
|
addr = PERIPHS_IO_MUX_GPIO2_U;
|
||
|
func = 0;
|
||
|
break;
|
||
|
case 3:
|
||
|
addr = PERIPHS_IO_MUX_U0RXD_U;
|
||
|
break;
|
||
|
case 4:
|
||
|
addr = PERIPHS_IO_MUX_GPIO4_U;
|
||
|
func = 0;
|
||
|
break;
|
||
|
case 5:
|
||
|
addr = PERIPHS_IO_MUX_GPIO5_U;
|
||
|
func = 0;
|
||
|
break;
|
||
|
case 6:
|
||
|
case 7:
|
||
|
case 8:
|
||
|
case 9:
|
||
|
case 10:
|
||
|
case 11:
|
||
|
addr = PERIPHS_IO_MUX_SD_CMD_U - 4 * (11-pin);
|
||
|
break;
|
||
|
case 12:
|
||
|
case 13:
|
||
|
case 14:
|
||
|
case 15:
|
||
|
addr = PERIPHS_IO_MUX_MTDO_U - 4 * (15-pin);
|
||
|
break;
|
||
|
default:
|
||
|
return;
|
||
|
}
|
||
|
PIN_FUNC_SELECT(addr, func);
|
||
|
}
|