/*********************************************************************************
|
* Copyright: (C) 2024 LingYun IoT System Studio
|
* All rights reserved.
|
*
|
* Filename: relay.h
|
* Description: This file is used to control relay
|
*
|
*
|
* Pin connection:
|
* Relay Module IGKBoard-IMX6ULL
|
* VCC <-----> 5V
|
* I <-----> #Pin22 (GPIO3_IO23)
|
* GND <-----> GND
|
*
|
********************************************************************************/
|
|
#ifndef _RELAY_H_
|
#define _RELAY_H_
|
|
#include "gpiod.h"
|
|
#define DELAY 300
|
|
#define ON 1
|
#define OFF 0
|
|
/* relay number */
|
enum
|
{
|
RELAY1 = 0,
|
RELAY_CNT,
|
};
|
|
enum
|
{
|
ACTIVE_HIGH, /* High level will turn relay on */
|
ACTIVE_LOW, /* Low level will turn relay on */
|
};
|
|
/* relay hardware information */
|
typedef struct relay_s
|
{
|
const char *name; /* relay name */
|
int chip_num; /* relay connect chip */
|
int gpio_num; /* relay connect line */
|
int active; /* relay active level */
|
int status; /* relay current status */
|
struct gpiod_line_request *request; /* libgpiod gpio request handler */
|
} relay_t;
|
|
/* relay structure */
|
typedef struct relays_s
|
{
|
relay_t *relays;/* relay pointer to relays_info */
|
int count; /* relay count */
|
} relays_t;
|
|
/* initial relays */
|
int init_relay(void);
|
|
/* terminate relays */
|
int term_relay(void);
|
|
/* turn $which relay ON/OFF */
|
int turn_relay(int which, int cmd);
|
|
/* toggle $which relay status */
|
int toggle_relay(int which);
|
|
#endif
|