1# Component: Button
2
3* This component defines a button as a well encapsulated object.
4* A button device is defined by:
5	* GPIO number on which the button is attached.
6	* Active level which decided by peripheral hardware.
7    * Trigger mode which decides whether to call serial trigger callback during pressing
8    * Serial threshold seconds which decides that serial trigger callback will be called after how many seconds' pressing
9* A button device can provide:
10    * One push event callback
11    * One release event callback
12    * One short-time tap event callback
13    * One serial trigger event callback
14    * Several long-time press event callback
15    We can set different jitter filters for all the events.
16    Once any of the long press callback is triggered, the short tap event will not be triggered.
17    This components are based on GPIO provided by idf and soft timer provided by FreeRTOS.
18
19* To use the button device, you need to :
20	* create a button object returned by iot_button_create().
21	* Then hook different event callbacks to the button object.
22	* To free the object, you can call iot_button_delete to delete the button object and free the memory that used.
23
24* Todo:
25    * Add hardware timer mode(because sometimes soft-timer callback function is limited)
26
27### NOTE:
28> All the event callback function are realized by FreeRTOS soft timer APIs, the callback must follow the rule:
29
30
31
32```
33  Button callback functions execute in the context of the timer service task.
34  It is therefore essential that button callback functions never attempt to block.
35  For example, a button callback function must not call vTaskDelay(), vTaskDelayUntil(), or specify a non zero block time when accessing a queue or a semaphore.
36```
37
38> In addition:
39> You can adjust the following macros within FreeRTOS to adjust the stack depth/queue length/task priority of the timer service.
40
41
42```
43#define configUSE_TIMERS //enable soft-timer
44#define configTIMER_TASK_PRIORITY // priority of the timers service task
45#define configQueue_LENGTH // length of timer command queue
46#define configTIMER_TASK_STACK_DEPTH // stack depth of the soft-timer
47```