/**********************************************************************
|
* Copyright: (C)2024 LingYun IoT System Studio
|
* Author: GuoWenxue<guowenxue@gmail.com>
|
* Description: ISKBoard Hardware Abstract Layer driver
|
*
|
* ChangeLog:
|
* Version Date Author Description
|
* V1.0.0 2024.08.29 GuoWenxue Release initial version
|
***********************************************************************/
|
|
#include "miscdev.h"
|
|
/*
|
*+----------------------+
|
*| GPIO Relay API |
|
*+----------------------+
|
*/
|
|
gpio_t relays[RelayMax] =
|
{
|
{ "Relay1", GPIOD, GPIO_PIN_2, OFF },
|
};
|
|
int init_relay(void)
|
{
|
int which;
|
|
/* Turn all relays off */
|
for(which=0; which<RelayMax; which++)
|
{
|
HAL_GPIO_WritePin(relays[which].group, relays[which].pin, GPIO_PIN_RESET);
|
}
|
|
return 0;
|
}
|
|
/* Turn $which relay to ON/OFF */
|
void turn_relay(int which, int status)
|
{
|
GPIO_PinState level;
|
|
if( which >= RelayMax )
|
return ;
|
|
level = status==OFF ? GPIO_PIN_RESET : GPIO_PIN_SET;
|
|
HAL_GPIO_WritePin(relays[which].group, relays[which].pin, level);
|
|
relays[which].status = status;
|
}
|
|
/* Get $which relay current status */
|
int status_relay(int which)
|
{
|
if( which >= RelayMax )
|
return 0;
|
|
return relays[which].status;
|
}
|
|
/*
|
*+----------------------+
|
*| GPIO Led API |
|
*+----------------------+
|
*/
|
|
gpio_t leds[LedMax] =
|
{
|
{ "RedLed", GPIOC, GPIO_PIN_9, OFF },
|
{ "GreenLed", GPIOC, GPIO_PIN_6, OFF },
|
{ "BlueLed", GPIOB, GPIO_PIN_2, OFF },
|
};
|
|
|
int init_led(void)
|
{
|
int which;
|
|
/* Turn all Leds off */
|
for(which=0; which<LedMax; which++)
|
{
|
HAL_GPIO_WritePin(leds[which].group, leds[which].pin, GPIO_PIN_SET);
|
}
|
|
return 0;
|
}
|
|
/* Turn $which led to ON/OFF */
|
void turn_led(int which, int status)
|
{
|
GPIO_PinState level;
|
|
if( which >= LedMax )
|
return ;
|
|
level = status==OFF ? GPIO_PIN_SET : GPIO_PIN_RESET;
|
|
HAL_GPIO_WritePin(leds[which].group, leds[which].pin, level);
|
|
leds[which].status = status;
|
}
|
|
/* Toggle $which led status */
|
void toggle_led(int which)
|
{
|
|
if( which >= LedMax )
|
return ;
|
|
HAL_GPIO_TogglePin(leds[which].group, leds[which].pin);
|
|
leds[which].status = !leds[which].status;
|
}
|
|
/* Blink $which led */
|
void blink_led(int which, uint32_t interval)
|
{
|
turn_led(which, ON);
|
HAL_Delay(interval);
|
|
turn_led(which, OFF);
|
HAL_Delay(interval);
|
}
|
|
/* Get $which led current status */
|
int status_led(int which)
|
{
|
if( which >= LedMax )
|
return 0;
|
|
return leds[which].status;
|
}
|