2017-12-14 01:48:58 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 UC Berkeley
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2018-04-28 15:37:41 +02:00
|
|
|
* @defgroup drivers_pulse_counter Pulse counter
|
2017-12-14 01:48:58 +01:00
|
|
|
* @ingroup drivers_sensors
|
2018-06-12 10:35:56 +02:00
|
|
|
* @ingroup drivers_saul
|
2017-12-14 01:48:58 +01:00
|
|
|
*
|
2018-04-28 15:37:41 +02:00
|
|
|
* @brief GPIO based pulse counting driver
|
2017-12-14 01:48:58 +01:00
|
|
|
*
|
2018-06-12 10:35:56 +02:00
|
|
|
* This driver provides @ref drivers_saul capabilities.
|
2017-12-14 01:48:58 +01:00
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
2018-04-28 15:37:41 +02:00
|
|
|
* @brief Driver for the pulse counter
|
2017-12-14 01:48:58 +01:00
|
|
|
*
|
|
|
|
* @author Hyung-Sin Kim <hs.kim@cs.berkeley.edu>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PULSE_COUNTER_H
|
|
|
|
#define PULSE_COUNTER_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2019-04-23 14:14:28 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
#include "c11_atomics_compat.hpp"
|
|
|
|
#else
|
|
|
|
#include <stdatomic.h>
|
|
|
|
#endif
|
2017-12-14 01:48:58 +01:00
|
|
|
#include "periph/gpio.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Parameters needed for device initialization
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
gpio_t gpio; /**< GPIO pin that sensor is connected to */
|
|
|
|
gpio_flank_t gpio_flank; /**< GPIO flank option */
|
|
|
|
} pulse_counter_params_t;
|
|
|
|
|
|
|
|
/**
|
2018-04-28 15:37:41 +02:00
|
|
|
* @brief Device descriptor for a pulse counter device
|
2017-12-14 01:48:58 +01:00
|
|
|
*/
|
|
|
|
typedef struct {
|
2019-04-23 14:14:28 +02:00
|
|
|
atomic_uint_least16_t pulse_count; /**< pulse counter */
|
2017-12-14 01:48:58 +01:00
|
|
|
} pulse_counter_t;
|
|
|
|
|
|
|
|
/**
|
2018-04-28 15:37:41 +02:00
|
|
|
* @brief Initialize a pulse counter device
|
2017-12-14 01:48:58 +01:00
|
|
|
*
|
|
|
|
* @param[out] dev device descriptor
|
|
|
|
* @param[in] params configuration parameters
|
|
|
|
*
|
|
|
|
* @return 0 on success
|
|
|
|
* @return -1 on error
|
|
|
|
*/
|
|
|
|
int pulse_counter_init(pulse_counter_t *dev, const pulse_counter_params_t *params);
|
|
|
|
|
|
|
|
/**
|
2018-04-28 15:37:41 +02:00
|
|
|
* @brief Read and reset pulse counter value
|
2017-12-14 01:48:58 +01:00
|
|
|
*
|
2019-01-06 19:43:40 +01:00
|
|
|
* @param[out] dev device descriptor of sensor
|
2017-12-14 01:48:58 +01:00
|
|
|
*
|
|
|
|
* @return Accumulated pulse counts
|
|
|
|
*/
|
2019-01-06 19:43:40 +01:00
|
|
|
int16_t pulse_counter_read_with_reset(pulse_counter_t *dev);
|
2017-12-14 01:48:58 +01:00
|
|
|
|
|
|
|
/**
|
2018-04-28 15:37:41 +02:00
|
|
|
* @brief Read pulse counter value
|
2017-12-14 01:48:58 +01:00
|
|
|
*
|
|
|
|
* @param[in] dev device descriptor of sensor
|
|
|
|
*
|
|
|
|
* @return Accumulated pulse counts
|
|
|
|
*/
|
2019-04-23 14:14:28 +02:00
|
|
|
int16_t pulse_counter_read_without_reset(pulse_counter_t *dev);
|
2017-12-14 01:48:58 +01:00
|
|
|
|
|
|
|
/**
|
2018-04-28 15:37:41 +02:00
|
|
|
* @brief Reset pulse counter value
|
2017-12-14 01:48:58 +01:00
|
|
|
*
|
2019-01-06 19:43:40 +01:00
|
|
|
* @param[out] dev device descriptor of sensor
|
2017-12-14 01:48:58 +01:00
|
|
|
*/
|
2019-01-06 19:43:40 +01:00
|
|
|
void pulse_counter_reset(pulse_counter_t *dev);
|
2017-12-14 01:48:58 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* PULSE_COUNTER_H */
|
|
|
|
/** @} */
|