1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
RIOT/drivers/ina3221/alerts.c
2021-07-07 08:40:02 +02:00

58 lines
1.4 KiB
C

/*
* Copyright (C) 2019 Otto-von-Guericke-Universität Magdeburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup drivers_ina3221
* @{
*
* @file
* @brief Functions to enable/disable GPIO alerts
* for INA3221
*
* @author Fabian Hüßler <fabian.huessler@ovgu.de>
*
* @}
*/
#include <errno.h>
#include "periph/gpio.h"
#include "ina3221.h"
int ina3221_enable_alert(ina3221_t *dev, ina3221_alert_t alert,
ina3221_alert_cb_t cb, void *arg)
{
if (alert >= INA3221_NUM_ALERTS) {
return -ERANGE;
}
if (!gpio_is_valid(dev->params.upins.apins.alert_pins[alert])) {
return -ENOTSUP;
}
dev->alert_callbacks[alert] = cb;
dev->alert_callback_arguments[alert] = arg;
int check = gpio_init_int(
dev->params.upins.apins.alert_pins[alert],
(dev->params.gpio_config & (1U << alert)) ? GPIO_IN_PU : GPIO_IN,
GPIO_FALLING,
cb,
arg
);
return check ? check : 0;
}
int ina3221_disable_alert(ina3221_t *dev, ina3221_alert_t alert)
{
if (alert >= INA3221_NUM_ALERTS) {
return -ERANGE;
}
if (!gpio_is_valid(dev->params.upins.apins.alert_pins[alert])) {
return -ENOTSUP;
}
gpio_irq_disable(dev->params.upins.apins.alert_pins[alert]);
return 0;
}