Below is one example that I used last day for testing the system_get_time() api.
But After I provided the bin files and testing on the IoT Ref Compatible Board,
I can not seen any system time information and timediff information.
Where I miss or wrong when employ this api ?
#include <user_buttons.h>
#define PIN_IN 2
#define GPIO_OUT_PIN 13
#define value 1
#define CHECK_BIT(var,pos) ((var) & (1 << (pos)))
//LOCAL void button_init();
//LOCAL uint32_t PIN_IN;
LOCAL uint8 button_last_state = 0;
LOCAL os_timer_t rotary_debounce_timer;
LOCAL os_timer_t button_timer;
void ICACHE_FLASH_ATTR button_push(uint8 debounce){
uint32 Starttime = system_get_time();
if(debounce == 1 ){
os_printf("start debouncing !\n");
os_timer_disarm(&button_timer);
os_timer_setfn(&button_timer,(os_timer_func_t *)button_push,0);
os_timer_arm(&button_timer, 100, 1);
}
if(CHECK_BIT(PIN_IN,0) == 0 && button_last_state == 0)
{
os_printf("Button press\n");
os_timer_disarm(&button_timer);
os_timer_setfn(&button_timer,(os_timer_func_t *)button_push,1);
os_timer_arm(&button_timer,1000,0);
button_last_state = 1;
}
if(CHECK_BIT(PIN_IN,0)== 1 && button_last_state == 1 )
{
os_printf("stop debouncing !\n");
uint32 Timediff = system_get_time()-Starttime ;
button_last_state = 0;
os_printf("time diff: %d\n",Timediff);
}
}
LOCAL void ICACHE_FLASH_ATTR rotary_debounce(uint8 direction)
{
gpio_pin_intr_state_set(GPIO_ID_PIN(13), GPIO_PIN_INTR_ANYEDGE);
if (direction ==1)
os_printf("Up\n");
else
os_printf("Down\n");
}
LOCAL void ICACHE_FLASH_ATTR rotary_intr_handler(int8_t key)
{
uint8 direction = 0;
uint32 inputs;
inputs = PIN_IN; // read datas from PIN_IN to inputs
if (CHECK_BIT(inputs,13) == CHECK_BIT(inputs,12)) // check bit 12 and bit 13 is equal ?
direction = 1;
os_printf("check bit 12 13 equal ?\n");
uint32 gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
gpio_pin_intr_state_set(GPIO_ID_PIN(13), GPIO_PIN_INTR_DISABLE);
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status & BIT(13));
os_timer_disarm(&rotary_debounce_timer);
os_timer_setfn(&rotary_debounce_timer,rotary_debounce,direction);
os_timer_arm(&rotary_debounce_timer, 350, 0);
}
LOCAL void ICACHE_FLASH_ATTR buttons_init()
{
os_printf("button_init start !\n");
// Register an interrupt handler
ETS_GPIO_INTR_ATTACH(rotary_intr_handler,GPIO_OUT_PIN);
// Disable interrupts
ETS_GPIO_INTR_DISABLE();
// set which chip io maps to which pad io
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U,FUNC_GPIO13);
// set the gpio to input
gpio_out_set(GPIO_OUT_PIN,value);
// set gpio registers
gpio_register_set(GPIO_PIN_ADDR(GPIO_OUT_PIN), GPIO_PIN_INT_TYPE_SET(GPIO_PIN_INTR_DISABLE)| GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_DISABLE)| GPIO_PIN_SOURCE_SET(GPIO_AS_PIN_SOURCE));
// clear gpio status
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS,BIT(GPIO_OUT_PIN));
// re-enable gpio interrupt
gpio_pin_intr_state_set(GPIO_ID_PIN(GPIO_OUT_PIN),GPIO_PIN_INTR_ANYEDGE);
// global re- enable interrupts
ETS_GPIO_INTR_ENABLE();
os_printf("gpio_interrupt_enable completed !\n");
// set timer when button_push events call backs , the timer scale is 50ms , restarts when timer to be 0
os_timer_disarm(&button_timer);
os_timer_setfn(&button_timer,(os_timer_func_t *)button_push,1);
os_timer_arm(&button_timer,50,1);
}
void user_init(void)
{
os_printf("SDK Version: %s\n",system_get_sdk_version());
buttons_init();
}Statistics: Posted by PaulTsai111 — Thu Jun 02, 2016 3:30 pm
]]>