/* Copyright (C) 2024 Moxa Inc. All rights reserved. */
/* SPDX-License-Identifier: Apache-2.0 */
/*!
    \file vm1220_io.h
    \copyright Moxa Inc.
    \brief <b>\a Moxa \a vm1220 Library</b>
    \date 2024-08-22
    \author David CL Tsai
    \version V1.0
*/

#ifndef __VM1220_IO_H__
#define __VM1220_IO_H__

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

/*!
    \addtogroup Library
    @{
*/

/*!
    \addtogroup VM1220_IO
    @{
*/
/*!
    \addtogroup VM1220_IO_ERR
    @{
*/
typedef int32_t VM1220_IO_ERR;
#define VM1220_IO_ERR_OK        0
#define VM1220_IO_ERR_INIT      1
#define VM1220_IO_ERR_CHANNEL   2
#define VM1220_IO_ERR_MODE      3
#define VM1220_IO_ERR_ARGUMENT  4
#define VM1220_IO_ERR_CMD_FAIL  5
//! @}

/*!
    \return     \link VM1220_IO_ERR_OK VM1220_IO_ERR_OK\endlink if everything is ok.
                Otherwise, refer to the \link VM1220_IO_ERR VM1220_IO_ERR\endlink.
    \note       This function \b MUST be called before using VM1220 library.
*/
VM1220_IO_ERR VM1220_IO_Client_Init(void);


//! @}

/*!
    \addtogroup DI
    @{
    \details
    \b Sample \b Code: \n
    \link di.c di.c\endlink \n
*/

/*!
    \param[in]  start Specifies the start channel.
    \param[in]  count The number of channels to be get.
    \param[out] p_values A pointer that stores DI values of the contiguous channels;
                    each bit holds one channel's value.
                    The bit 0 represents digital input status of the start channel and so on
    \return     \link VM1220_IO_ERR_OK VM1220_IO_ERR_OK\endlink if everything is ok.
                Otherwise, refer to the \link VM1220_IO_ERR VM1220_IO_ERR\endlink.
*/
VM1220_IO_ERR VM1220_DI_GetValues(uint8_t start, uint8_t count, uint32_t *p_values);

//! @}

// ----------------------------------------------------------------------------
/*!
    \addtogroup DO
    @{
    \details
    \b Sample \b Code: \n
    \link do.c do.c\endlink \n
*/

/*!
    \param[in]  start Specifies the start channel.
    \param[in]  count The number of channels to be get.
    \param[out] p_values A pointer that stores DO values of the contiguous channels;
                    each bit holds one channel's value.
                    The bit 0 represents digital input status of the start channel and so on
    \return     \link VM1220_IO_ERR_OK VM1220_IO_ERR_OK\endlink if everything is ok.
                Otherwise, refer to the \link VM1220_IO_ERR VM1220_IO_ERR\endlink.
*/
VM1220_IO_ERR VM1220_DO_GetValues(uint8_t start, uint8_t count, uint32_t *p_values);

/*!
    \param[in] start Specifies the start channel.
    \param[in] count The number of channels to be set.
    \param[in] values DO values of the contiguous channels;
                    each bit holds one channel's value.
                    The bit 0 represents digital output status of the start channel and so on.
    \return     \link VM1220_IO_ERR_OK VM1220_IO_ERR_OK\endlink if everything is ok.
                Otherwise, refer to the \link VM1220_IO_ERR VM1220_IO_ERR\endlink.
*/
VM1220_IO_ERR VM1220_DO_SetValues(uint8_t start, uint8_t count, uint32_t values);

//! @}

// ----------------------------------------------------------------------------
/*!
    \addtogroup DIO
    @{
    \details
    \b Sample \b Code: \n
    \link dio.c dio.c\endlink \n
*/

/*!
    \addtogroup DIO_MODE
    @{
*/
//DIO MODE
#define DIO_MODE_DI  0
#define DIO_MODE_DO  1
//! @}

/*!
    \param[in]  start Specifies the start channel.
    \param[in]  count The number of channels to be get.
    \param[out] p_values A pointer that stores DI values of the contiguous channels;
                    each bit holds one channel's value.
                    The bit 0 represents digital input or output status of the start channel and so on
    \return     \link VM1220_IO_ERR_OK VM1220_IO_ERR_OK\endlink if everything is ok.
                Otherwise, refer to the \link VM1220_IO_ERR VM1220_IO_ERR\endlink.
*/
VM1220_IO_ERR VM1220_DIO_GetValues(uint8_t start, uint8_t count, uint32_t *p_values);

/*!
    \param[in] start Specifies the start channel.
    \param[in] count The number of channels to be set.
    \param[in] values DO values of the contiguous channels;
                    each bit holds one channel's value.
                    The bit 0 represents digital output status of the start channel and so on.
    \return     \link VM1220_IO_ERR_OK VM1220_IO_ERR_OK\endlink if everything is ok.
                Otherwise, refer to the \link VM1220_IO_ERR VM1220_IO_ERR\endlink.
*/
VM1220_IO_ERR VM1220_DIO_SetValues(uint8_t start, uint8_t count, uint32_t values);

/*!
    \param[in]  start Specifies the start channel.
    \param[in]  count The number of channels to be get.
    \param[out] p_values A pointer that stores mode values of the contiguous channels;
                    each bit holds one channel's value.
                    The bit 0 represents direction status of the start channel and so on
    \return     \link VM1220_IO_ERR_OK VM1220_IO_ERR_OK\endlink if everything is ok.
                Otherwise, refer to the \link VM1220_IO_ERR VM1220_IO_ERR\endlink.
*/
VM1220_IO_ERR VM1220_DIO_GetModes(uint8_t start, uint8_t count, uint32_t *p_values);

/*!
    \param[in] start Specifies the start channel.
    \param[in] count The number of channels to be set.
    \param[in] values Mode values of the contiguous channels;
                    each bit holds one channel's value.
                    The bit 0 represents input/output status of the start channel and so on.
    \return     \link VM1220_IO_ERR_OK VM1220_IO_ERR_OK\endlink if everything is ok.
                Otherwise, refer to the \link VM1220_IO_ERR VM1220_IO_ERR\endlink.
*/
VM1220_IO_ERR VM1220_DIO_SetModes(uint8_t start, uint8_t count, uint32_t values);

//! @}

// ----------------------------------------------------------------------------
/*!
    \addtogroup Misc
    @{
    \details
    \b Sample \b Code: \n
    \link misc.c misc.c\endlink
*/

/*!
    \addtogroup LED_state
    @{
*/
#define LED_STATE_DARK              0
#define LED_STATE_GREEN             1
#define LED_STATE_GREEN_HEARTBEAT   2
//! @}
/*!
    \addtogroup User_LED_Channel
    @{
*/
#define LED_CHANNEL_USR1      1
#define LED_CHANNEL_USR2      2
#define LED_CHANNEL_USR3      3
#define LED_CHANNEL_USR4      4
//! @}

/*!
    \param[in]  channel Specifies the \link User_LED_Channel user led channel\endlink.
    \param[out] state Stores the \link LED_state led state\endlink.
    \return     \link VM1220_IO_ERR_OK VM1220_IO_ERR_OK\endlink if everything is ok.
                Otherwise, refer to the \link VM1220_IO_ERR VM1220_IO_ERR\endlink.
*/
VM1220_IO_ERR VM1220_Misc_GetUserLedState(uint8_t channel, uint8_t *state);

/*!
    \param[in] channel Specifies the \link User_LED_Channel user led channel\endlink.
    \param[in] state Stores the \link LED_state led state\endlink.
    \return     \link VM1220_IO_ERR_OK VM1220_IO_ERR_OK\endlink if everything is ok.
                Otherwise, refer to the \link VM1220_IO_ERR VM1220_IO_ERR\endlink.
*/
VM1220_IO_ERR VM1220_Misc_SetUserLedState(uint8_t channel, uint8_t state);

//! @}


#ifdef __cplusplus
} // extern "C"
#endif

#endif // __VM1220_IO_H__
