/*
* Copyright (c) 2023-2028, SpaceTouch Inc.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date          Author      Notes
* 2023-07-18    zhixiongl       the first version
*/


#ifndef SPV_HAL_LRADC_H
#define SPV_HAL_LRADC_H

#ifdef __cplusplus
extern "C"
{
#endif

#include "platform.h"


//#define DBG_HAL_LRADC

#if defined(DBG_HAL_LRADC)
#define HAL_LRADC_LOG(fmt, ...)      rt_kprintf(fmt, ##__VA_ARGS__)
#else
#define HAL_LRADC_LOG(fmt, ...)
#endif

typedef enum
{
    LRADC0 = 0,
    LRADC1 = 1,
    LRADC2 = 2,
    LRADC3 = 3,
    LRADC4 = 4,
    LRADC5 = 5,
    LRADC6 = 6,
    LRADC7 = 7,
    LRADC8 = 8,
    LRADC9 = 9,
    LRADC10 = 10,
    LRADC11 = 11,
    LRADC_NUM,
} lradc_port_t;

#define HAL_LRADC_EOK                          0               /**< There is no error */
#define HAL_LRADC_ERROR                        1               /**< A generic error happens */

#define LRADC_ENABLE                            (0x1UL<<0)
#define LRADC_START                             (0x1UL<<0)

void hal_lradc_set_channelphase(uint32_t lradc_num);
void hal_lradc_set_sampleaverage(lradc_port_t lradc_port, uint32_t avg);
void hal_lradc_set_samplerate(lradc_port_t lradc_port, uint32_t sr);
void hal_lradc_set_samplemode(lradc_port_t lradc_port, uint32_t mode);
void hal_lradc_enable(lradc_port_t lradc_port, uint32_t state);
void hal_lradc_start(void);
void hal_lradc_stop(void);
int32_t hal_lradc_getvalue(lradc_port_t lradc_port);
void hal_lradc_it_config(uint32_t lradc_ie, uint32_t state);
uint32_t hal_lradc_get_it_status(uint32_t lradc_pd);
void hal_lradc_clear_it_pending_bit(uint32_t lradc_pd);
void hal_lradc_wakeup_config(uint32_t lradc_wakeup, uint32_t state);

int32_t hal_lradc_init(lradc_port_t lradc_port);

#ifdef __cplusplus
}
#endif

#endif

