/*********************************************************************************
|
* Copyright: (C) 2021 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 Raspberry Pi Board
|
* R <-----> #Pin33(BCM GPIO13)
|
* G <-----> #Pin35(BCM GPIO19)
|
* B <-----> #Pin37(BCM GPIO26)
|
* GND <-----> GND
|
*
|
* System install:
|
* sudo apt install -y libgpiod-dev gpiod
|
*
|
*
|
********************************************************************************/
|
|
#ifndef _LEDS_H_
|
#define _LEDS_H_
|
|
#define ON 1
|
#define OFF 0
|
|
/* Three LEDs code */
|
enum
|
{
|
LED_R = 0,
|
LED_G,
|
LED_B,
|
LED_CNT,
|
};
|
|
/* Three LEDs hardware information */
|
typedef struct led_info_s
|
{
|
const char *name; /* RGB 3-color LED name */
|
int gpio; /* RGB 3-color LED BCM pin number */
|
int active;/* RGB 3-color LED active GPIO level: 0->low 1->high */
|
struct gpiod_line *line; /* libgpiod line */
|
} led_info_t;
|
|
/* Three LEDs API context */
|
typedef struct led_ctx_s
|
{
|
struct gpiod_chip *chip;
|
led_info_t *leds;
|
int count;
|
} led_ctx_t;
|
|
extern int init_led(led_ctx_t *ctx, int which);
|
extern int term_led(led_ctx_t *ctx, int which);
|
extern int turn_led(int which, int cmd);
|
|
#endif /* ----- #ifndef _LEDS_H_ ----- */
|