Comments (9)
I propose to add this to the official distribution: it is backward compatible and it means people can have a 'one-stop-shop-experience' by just reading the gpio.h file.
//example based on ESP8266_RTOS_SDK version 1.5.0
#include "esp_common.h"
#include "gpio.h"
#define GPIO_INPUT(gpio_bits) ((gpio_input_get()&gpio_bits)?1:0)
#define GPIO_INTERRUPT_ENABLE _xt_isr_unmask(1 << ETS_GPIO_INUM)
void gpio_config(GPIO_ConfigTypeDef *pGPIOConfig);
/******************************************************************************
* FunctionName : gpio_intr_handler - generic handling of GPIO interrupts
*******************************************************************************/
void (*gpio_intr_callbacks[16])(void);
void gpio_intr_handler() {
int i;
uint32 gpio_mask = _xt_read_ints();
uint32_t gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
os_printf("interrupt@%dus: mask=0x%02x, status=0x%02x\n",system_get_time(),gpio_mask,gpio_status);
for (i=0 ; i<16 ; i++)
if ( (0x1<<i) & gpio_status & gpio_intr_callbacks[i]!= NULL )
(*gpio_intr_callbacks[i])();
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status ); //clear interrupt status
}
//****** THE ITEMS ABOVE SHOULD BE ADDED TO THE GPIO driver files ************//
/******************************************************************************
* FunctionName : Pin0 specific interrupt handler
*******************************************************************************/
LOCAL void callback0() {
static uint32 oldtime;
// os_printf("oldtime: %d\n",oldtime);
if ( (oldtime+200)<(oldtime=(system_get_time()/1000) ) ) { //200ms debounce guard
GPIO_OUTPUT(GPIO_Pin_2,GPIO_INPUT(GPIO_Pin_2)^1); //toggle
os_printf("Pin2-toggle\n");
}
// os_printf("newtime: %d\n",oldtime);
}
/******************************************************************************
* FunctionName : user_init
*******************************************************************************/
void user_init(void)
{
GPIO_ConfigTypeDef gpio0_in_cfg; //Define GPIO Init Structures
GPIO_ConfigTypeDef gpio2_in_cfg;
gpio0_in_cfg.GPIO_IntrType = GPIO_PIN_INTR_NEGEDGE; //Falling edge trigger
gpio0_in_cfg.GPIO_Mode = GPIO_Mode_Input; //Input mode
gpio0_in_cfg.GPIO_Pin = GPIO_Pin_0; //Enable GPIO
gpio_config(&gpio0_in_cfg); //Initialization function
gpio_intr_handler_register(gpio_intr_handler,NULL); //Register the interrupt function
GPIO_INTERRUPT_ENABLE;
gpio_intr_callbacks[0]=callback0; //define the Pin0 callback
gpio2_in_cfg.GPIO_IntrType = GPIO_PIN_INTR_DISABLE; //no interrupt
gpio2_in_cfg.GPIO_Mode = GPIO_Mode_Output; //Output mode
gpio2_in_cfg.GPIO_Pullup = GPIO_PullUp_EN; //improves transitions
gpio2_in_cfg.GPIO_Pin = GPIO_Pin_2; //Enable GPIO
gpio_config(&gpio2_in_cfg); //Initialization function
}
/***********************************************************************************
* FunctionName : user_rf_cal_sector_set forced upon us by espressif since RTOS1.4.2
***********************************************************************************/
uint32 user_rf_cal_sector_set(void) {
extern char flashchip;
SpiFlashChip *flash = (SpiFlashChip*)(&flashchip + 4);
//sec_num = chip_size / flash->sector_size; but sector size is 4096 = 2^12
uint32_t sec_num = flash->chip_size >> 12;
return sec_num - 5;
}
from esp8266_rtos_sdk.
@ly0 have you found any info on this ? I am looking for the same info.
from esp8266_rtos_sdk.
@donnib refered to http://g-lab.ca/esp8266ex-gpio-registers/, maybe we need to handle the related registers directly. search 'INT' for more info on that page. But I haven't tried.
from esp8266_rtos_sdk.
gpio driver has been upload, you can have a test.
from esp8266_rtos_sdk.
@espressif which driver are you reffering to ? 0.9.4 has GPIO interrupt supported ? If so any documentation about that ?
from esp8266_rtos_sdk.
@donnib see this https://github.com/espressif/esp_iot_rtos_sdk/tree/master/examples/dirver_lib
from esp8266_rtos_sdk.
In the exemple you talked about a gpio_intr_ack function (https://github.com/espressif/esp_iot_rtos_sdk/blob/master/examples/driver_lib/driver/gpio.c#L101). But I can't find it anywhere. Even if I add the signature : void gpio_intr_ack(uint32 mask); the linker can't find it.
EDIT: I managed to compile by providing the address to the linker (PROVIDE ( gpio_intr_ack = 0x40004dcc );) But now I'm getting this exception when I trigger my interrupt :
Fatal exception (20): (EXCCAUSE_INSTR_PROHIBITED)
epc1=0x00000004
epc2=0x00000000
epc3=0x4024306f
epcvaddr=0x00000004
depc=0x00000000
Here is my code :
LOCAL void (*callbacks[16])(void);
LOCAL void interruptHandler(int gpio_mask) {
for (int i=0 ; i<16 ; i++) {
if ((0x1<<i) & gpio_mask) {
if (callbacks[i] != NULL) {
(*callbacks[i])();
}
}
}
gpio_intr_ack(gpio_mask);
}
And this is how i register the handler :
for (int i=0 ; i<16 ; i++) {
callbacks[i] = NULL;
}
_xt_isr_attach(ETS_GPIO_INUM, (_xt_isr)interruptHandler);
_xt_isr_unmask(1<<ETS_GPIO_INUM);
EDIT2: It seems that the interrupt is given no arguments (gpio_mask is always 16, whatever the pin are). I tried to use gpio_intr_pending(); but it always return 0 and throw a 29 (EXCCAUSE_STORE_PROHIBITED) exception. It also seems that the interrupt is triggered a lot before crashing, shouldn't it be triggered once ?
EDIT3: I tried to use _xt_clear_ints(uint32 mask); and _xt_read_ints(); but I have the same issue, with _xt_read_ints(); returning a lot of 20 and some 84.
from esp8266_rtos_sdk.
Any idea ? This issue seems to be linked with the pwm one.
Edit: an answer has been found by hreintke on esp8266.com : http://www.esp8266.com/viewtopic.php?f=8&t=241&p=7246#p7246
from esp8266_rtos_sdk.
Now, 2 years later, is there an answer to this?
For now I cannot see any clear instructions in the SDK itself and the driver code seems incomplete.
For example, gpio.c contains the function gpio_config() but there is no prototype in gpio.h
The example given on espressif site depends on this function...
Is there a conclusive example how to do this??
from esp8266_rtos_sdk.
Related Issues (20)
- Missing DER certificate support in esp_http_client component (GIT8266O-834)
- How do I.. SD card using example please (GIT8266O-835)
- Linking fails on hello_world example with disabled assertions (GIT8266O-836) HOT 1
- Bootloader compilation fails when "UART for console output" is set to "none" (GIT8266O-837)
- Application doesn't work with assertion level set to "disabled" (GIT8266O-839) HOT 1
- master分支下,使用ADC例程读出来的数据过高 (GIT8266O-840)
- Do not get IP address after call esp_wifi_connect() (GIT8266O-841) HOT 1
- can't find vApplicationGetTimerTaskMemory function. (GIT8266O-843) HOT 1
- CONFIG_DISABLE_ROM_UART_PRINT leads to boot loop (GIT8266O-844)
- Error: invalid register 'intclear' for 'wsr' instruction (GIT8266O-845) HOT 1
- esp-netif interface (GIT8266O-846) HOT 1
- Compiled size (GIT8266O-847) HOT 1
- Proble Install Python Package by Using mingw32 on Windows (GIT8266O-848) HOT 4
- export.sh cannot run correctly on zsh (GIT8266O-849)
- [Bug/suggestion] Diverging baud rates in hello_world example (GIT8266O-850)
- Error in configuring ESP8266 RTOS SDK development environment on Linux??? (GIT8266O-851) HOT 7
- Segment loaded at 0x*** lands in same 64KB flash mapping as segment loaded at 0x*** (GIT8266O-852) HOT 2
- cmake error at cmakelists.txt & menuconfig errors (GIT8266O-853)
- menuconfig script fails for ncurses in Arch-Linux (GIT8266O-855) HOT 5
- 烧录protocols/mqtt/tcp的demo后报错 (GIT8266O-858)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esp8266_rtos_sdk.