/*!
 * @file        main.c
 *
 * @brief       Main program body
 *
 * @version     V1.0.0
 *
 * @date        2025-01-01
 *
 * @attention
 *
 *  Copyright (C) 2025 Geehy Semiconductor
 *
 *  You may not use this file except in compliance with the
 *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
 *
 *  The program is only for reference, which is distributed in the hope
 *  that it will be useful and instructional for customers to develop
 *  their software. Unless required by applicable law or agreed to in
 *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
 *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
 *  and limitations under the License.
 */

/* Includes ***************************************************************/
#include "main.h"
#include <stdio.h>
#include "bmp561_cadc.h"
#include "bmp561_gpio.h"
#include "bmp561_sysctrl.h"

/* Private includes *******************************************************/

/* Private macro **********************************************************/

/* Private typedef ********************************************************/

/* Private variables ******************************************************/
volatile uint32_t current = 0;

/* Private function prototypes ********************************************/
void CADC_Init(void);

/* External variables *****************************************************/

/* External functions *****************************************************/

/*!
 * @brief   Main program
 *
 * @param   None
 *
 * @retval  None
 */
int main(void)
{
    BOARD_Delay_Config();
    GPIO_Reset();
    BOARD_Delay_Ms(3000);

    CADC_Init();

    while (1)
    {
        if (CADC_ReadSampleFlag())
        {
            current =  CADC_GetRawData();
            CADC_ClearSampleFlag();
        }
    }
}

/*!
 * @brief   VADC initialization
 *
 * @param   None
 *
 * @retval  None
 */
void CADC_Init(void)
{
    SYSCTRL_Unlock();
    SYSCTRL_EnableAPBPeriphBCGClock(SYSCTRL_APB_CADC);
    SYSCTRL_EnableAPBPeriphWCGClock(SYSCTRL_APB_CADC);
    SYSCTRL_EnableAFEClock();
    SYSCTRL_EnableAFE();
    SYSCTRL_Lock();

    CADC_Enable();
}
