/*
 * Copyright (c) 2013 - 2016, Freescale Semiconductor, Inc.
 * Copyright 2016-2017 NXP
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * o Redistributions of source code must retain the above copyright notice, this list
 *   of conditions and the following disclaimer.
 *
 * o Redistributions in binary form must reproduce the above copyright notice, this
 *   list of conditions and the following disclaimer in the documentation and/or
 *   other materials provided with the distribution.
 *
 * o Neither the name of the copyright holder nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
#ifndef _NT_MODULE_GPIO_H_
#define _NT_MODULE_GPIO_H_

/**
 * \defgroup gpio GPIO module
 * \ingroup modules
 * GPIO module uses the MCU's General Purpose pins and Timer.
 * \{
 */

#include "nt_modules.h"
#include "nt_types.h"
#include "nt_gpio.h"


/* forward declaration */
struct nt_module;
struct nt_module_interface;
struct nt_module_data;
                                     

/** Gpio user's interface, which is used by the GPIO modules.
 *  All of these functions must be implemented in the application.
 */
struct nt_module_gpio_user_interface {
    void (* set_pin_output)(uint32_t port, uint32_t pin);        /*!< Set pin direction to output */
    void (* set_pin_input)(uint32_t port, uint32_t pin);         /*!< Set pin direction to input */
    void (* set_pin_low)(uint32_t port, uint32_t pin);           /*!< Set pin to logic low */
    void (* set_pin_high)(uint32_t port, uint32_t pin);          /*!< Set pin to logic high */
    uint32_t (* get_pin_value)(uint32_t port, uint32_t pin);     /*!< Get pin value */
    void (* set_pin_default_state)(uint32_t port, uint32_t pin); /*!< Set pin to default state when it's not being measured */
    void (* init_timer)(void);                                   /*!< Init timer */
    void (* start_timer)(void);                                  /*!< Start timer */
    void (* stop_timer)(void);                                   /*!< Stop timer */
    void (* timer_reset_counter)(void);                          /*!< Reset timer counter */
    uint32_t (* timer_get_counter)(void);                        /*!< Get timer counter */
    uint32_t (* timer_get_overrun)(void);                        /*!< Get timer overrun */
    void (* set_pin_pull_up)(uint32_t port, uint32_t pin);       /*!< Set pin to GPIO with pull-up */
    void (* set_pin_pull_down)(uint32_t port, uint32_t pin);     /*!< Set pin to GPIO with pull-down */
    void (* set_pin_tsi_mode)(uint32_t port, uint32_t pin);      /*!< Set pin to TSI mode */
    void (* set_pin_gpio_mode)(uint32_t port, uint32_t pin);     /*!< Set pin to GPIO mode */
};

/** GPIO module, which uses the \b ??interrupts? port to sample a signal from the running timer counter.
 */
struct nt_module_gpio_params {
    const struct nt_module_gpio_user_interface *user_interface;    
};

extern const struct nt_module_interface nt_module_gpio_interface; /*!< Can't be NULL. */

int32_t nt_gpio_data_check(const struct nt_module_data *module);

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif

#endif

/** \} */ /*/ end of gpio group */
