/*
 * Copyright 2021 MindMotion Microelectronics Co., Ltd.
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <stdint.h>
#include <stdio.h>

#include "board_init.h"

/*
 * Definitions.
 */

/*
 * Variables.
 */

/* the CLU 4 input source for one CLU output as source, max length if 4. default logic 0. */
uint32_t trigger_in[4] = {TRIGGER_IN_0, TRIGGER_IN_1, TRIGGER_IN_2, TRIGGER_IN_3};

/*
 * Declerations.
 */
void app_mds_init(void);

/*
 * Functions.
 */

int main(void)
{
    BOARD_Init();

    printf("\r\nmds_trigger_clu example.\r\n");
    printf("press any key to start.\r\n");
    app_mds_init();
    while (1)
    {
        /* type any key into the terminal to trigger the conversion. */
        getchar();

        /* wait for trigger target. */
        BOARD_WaitTrigger();
        printf("mds_trigger_clu done.\r\n");

    }
}
/* setup the mds module, and prepare peripheral control signal interaction. */
void app_mds_init(void)
{

	/* configure, when using clu output as the trigger in. */
    MDS_CluConf_Type conf;
    for(uint32_t i =0; i<4; i++)
	{
    conf.CluInSource[i] = trigger_in[i];
    }
    conf.CluInSourceInvertMask = CLU_IN_INVERT_MASK;
    conf.CluInSourceTriggerEdgeMask = CLU_IN_TRIGGER_EDGE_MASK;
    conf.CluLogic = MDS_CluLogic_OR_OR;
    MDS_EnableTriggerClu(BOARD_MDS_PORT, TRIGGER_OUT, TRIGGER_CLU_IN, &conf);
}

/* EOF. */
