| /********************************************************************************* | 
|  *      Copyright:  (C) 2024 LingYun IoT System Studio | 
|  *                  All rights reserved. | 
|  * | 
|  *       Filename:  led.h | 
|  *    Description:  This file is used to control RGB 3-colors LED | 
|  * | 
|  * | 
|  * Pin connection: | 
|  *               RGB Led Module           IGKBoard-IMX6ULL | 
|  *                   R        <----->      #Pin36 (GPIO1_IO11) | 
|  *                   G        <----->      #Pin38 (GPIO1_IO10) | 
|  *                   B        <----->      #Pin40 (GPIO5_IO09) | 
|  *                  GND       <----->      GND | 
|  * | 
|  ********************************************************************************/ | 
|   | 
| #ifndef  _LED_H_ | 
| #define  _LED_H_ | 
|   | 
| #include "gpiod.h" | 
|   | 
| #define DELAY     300 | 
|   | 
| #define ON        1 | 
| #define OFF       0 | 
|   | 
| /* Three LEDs number */ | 
| enum | 
| { | 
|     LED_R = 0, | 
|     LED_G, | 
|     LED_B, | 
|     LED_CNT, | 
| }; | 
|   | 
| enum | 
| { | 
|     ACTIVE_HIGH, /* High level will turn led on */ | 
|     ACTIVE_LOW,  /* Low level will turn led on */ | 
| }; | 
|   | 
| /* Three LEDs hardware information */ | 
| typedef struct led_s | 
| { | 
|     const char               *name;      /* RGB 3-color LED name  */ | 
|     int                       chip_num;  /* RGB 3-color LED connect chip */ | 
|     int                       gpio_num;  /* RGB 3-color LED connect line */ | 
|     int                       active;    /* RGB 3-color LED active level */ | 
|     int                       status;    /* RGB 3-color LED current status */ | 
|     struct gpiod_line_request *request;  /* libgpiod gpio request handler */ | 
| } led_t; | 
|   | 
| /* Three LEDs structure */ | 
| typedef struct leds_s | 
| { | 
|     led_t               *leds;  /* led pointer to leds_info */ | 
|     int                  count; /* led count */ | 
| } leds_t; | 
|   | 
|   | 
| /* initial leds */ | 
| int init_led(void); | 
|   | 
| /* terminate leds   */ | 
| int term_led(void); | 
|   | 
| /* turn $which led ON/OFF */ | 
| int turn_led(int which, int cmd); | 
|   | 
| /* toggle $which led status */ | 
| int toggle_led(int which); | 
|   | 
| /* blink $which led status with $interval ms */ | 
| void blink_led(int which, int interval); | 
|   | 
| #endif |