123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- /*
- * Copyright (c) 2021 HPMicro
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
- #ifndef HPM_DAO_DRV_H
- #define HPM_DAO_DRV_H
- #include "hpm_common.h"
- #include "hpm_dao_regs.h"
- #include "hpm_i2s_common.h"
- #include "hpm_soc_feature.h"
- /**
- * @brief DAO driver APIs
- * @defgroup dao_interface DAO driver APIs
- * @ingroup io_interfaces
- * @{
- */
- /**
- * @brief DAO channel selection
- */
- #define DAO_CHANNEL_LEFT_ONLY DAO_CTRL_LEFT_EN_MASK
- #define DAO_CHANNEL_RIGHT_ONLY DAO_CTRL_RIGHT_EN_MASK
- #define DAO_CHANNEL_BOTH \
- (DAO_CTRL_RIGHT_EN_MASK | DAO_CTRL_LEFT_EN_MASK)
- /**
- * @brief DAO default output
- */
- #define DAO_DEFAULT_OUTPUT_ALL_LOW (0U)
- #define DAO_DEFAULT_OUTPUT_ALL_HIGH (1U)
- #define DAO_DEFAULT_OUTPUT_P_HIGH_N_LOW (2U)
- #define DAO_DEFAULT_OUTPUT_DISABLED (3U)
- /**
- * @brief DAO config
- */
- typedef struct dao_config {
- bool enable_mono_output;
- uint8_t default_output_level;
- uint8_t channel_count;
- #if defined(HPM_IP_FEATURE_DAO_DATA_FORMAT_CONFIG) && (HPM_IP_FEATURE_DAO_DATA_FORMAT_CONFIG == 1)
- bool enable_tdm_mode;
- bool frame_start_at_rising_edge;
- uint8_t protocol;
- uint8_t channel_length;
- uint8_t audio_depth;
- #endif
- uint8_t channel_slot_mask;
- } dao_config_t;
- typedef enum {
- dao_right_channel = DAO_CTRL_RIGHT_EN_MASK,
- dao_left_channel = DAO_CTRL_LEFT_EN_MASK,
- } dao_channel_t;
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * @brief config high pass filter
- *
- * @param [in] ptr DAO base address
- * @param [in] hpf_coef_ma high pass filter a coefficient's complement
- * @param [in] hpf_coef_b high pass filter b coefficient
- * @param [in] enable
- * @arg true: enable
- * @arg false: disable
- */
- static inline void dao_config_hpf(DAO_Type *ptr,
- uint32_t hpf_coef_ma,
- uint32_t hpf_coef_b,
- bool enable)
- {
- ptr->HPF_MA = DAO_HPF_MA_COEF_SET(hpf_coef_ma);
- ptr->HPF_B = DAO_HPF_B_COEF_SET(hpf_coef_b);
- ptr->CTRL = (ptr->CTRL & ~DAO_CTRL_HPF_EN_MASK)
- | (enable ? DAO_CTRL_HPF_EN_MASK : 0);
- }
- /**
- * @brief enable high pass filter
- *
- * @param [in] ptr DAO base address
- */
- static inline void dao_enable_hpf(DAO_Type *ptr)
- {
- ptr->CTRL |= DAO_CTRL_HPF_EN_MASK;
- }
- /**
- * @brief disable high pass filter
- *
- * @param [in] ptr DAO base address
- */
- static inline void dao_disable_hpf(DAO_Type *ptr)
- {
- ptr->CTRL &= ~DAO_CTRL_HPF_EN_MASK;
- }
- /**
- * @brief enable channel
- *
- * @param [in] ptr DAO base address
- * @param [in] ch channel defined in dao_channel_t
- */
- static inline void dao_enable_channel(DAO_Type *ptr, uint32_t ch)
- {
- ptr->CTRL |= ch;
- }
- /**
- * @brief disable channel
- *
- * @param [in] ptr DAO base address
- * @param [in] ch channel defined in dao_channel_t
- */
- static inline void dao_disable_channel(DAO_Type *ptr, uint32_t ch)
- {
- ptr->CTRL &= ~ch;
- }
- /**
- * @brief enable mono output
- *
- * @param [in] ptr DAO base address
- */
- static inline void dao_enable_mono_output(DAO_Type *ptr)
- {
- ptr->CTRL |= DAO_CTRL_MONO_MASK;
- }
- /**
- * @brief disable mono output
- *
- * @param [in] ptr DAO base address
- */
- static inline void dao_disable_mono_output(DAO_Type *ptr)
- {
- ptr->CTRL &= ~DAO_CTRL_MONO_MASK;
- }
- /**
- * @brief enable remap
- *
- * @param [in] ptr DAO base address
- */
- static inline void dao_enable_remap(DAO_Type *ptr)
- {
- ptr->CTRL |= DAO_CTRL_REMAP_MASK;
- }
- /**
- * @brief disable remap
- *
- * @param [in] ptr DAO base address
- */
- static inline void dao_disable_remap(DAO_Type *ptr)
- {
- ptr->CTRL &= ~DAO_CTRL_REMAP_MASK;
- }
- /**
- * @brief invert output
- *
- * @param [in] ptr DAO base address
- * @param [in] invert
- * @arg true: invert output
- * @arg false: not invert output
- */
- static inline void dao_invert_output(DAO_Type *ptr, bool invert)
- {
- ptr->CTRL = (ptr->CTRL & DAO_CTRL_INVERT_MASK)
- | DAO_CTRL_INVERT_SET(invert);
- }
- /**
- * @brief force pads output with certain level
- *
- * @param [in] ptr DAO base address
- * @param [in] output output level
- */
- static inline void dao_force_output(DAO_Type *ptr, uint8_t output)
- {
- ptr->CTRL = (ptr->CTRL & DAO_CTRL_FALSE_LEVEL_MASK)
- | DAO_CTRL_FALSE_LEVEL_SET(output);
- }
- /**
- * @brief enable false run
- * when false run mode is enabled, the module continues to consume data, no actual output on pads.
- * @param [in] ptr DAO base address
- * @param [in] enable
- * @arg true: enable
- * @arg false: disable
- */
- static inline void dao_enable_false_run(DAO_Type *ptr, bool enable)
- {
- ptr->CTRL = (ptr->CTRL & DAO_CTRL_FALSE_RUN_MASK)
- | DAO_CTRL_FALSE_RUN_SET(enable);
- }
- /**
- * @brief software reset
- *
- * @param [in] ptr DAO base address
- */
- static inline void dao_software_reset(DAO_Type *ptr)
- {
- ptr->CMD |= DAO_CMD_SFTRST_MASK;
- ptr->CMD &= ~DAO_CMD_SFTRST_MASK;
- }
- /**
- * @brief check whether DAO is running
- *
- * @param [in] ptr DAO base address
- * @retval true if dao is running
- */
- static inline bool dao_is_running(DAO_Type *ptr)
- {
- return ptr->CMD & DAO_CMD_RUN_MASK;
- }
- /**
- * @brief start
- *
- * @param [in] ptr DAO base address
- */
- static inline void dao_start(DAO_Type *ptr)
- {
- ptr->CMD |= DAO_CMD_RUN_MASK;
- }
- /**
- * @brief stop
- *
- * @param [in] ptr DAO base address
- */
- static inline void dao_stop(DAO_Type *ptr)
- {
- ptr->CMD &= ~DAO_CMD_RUN_MASK;
- }
- /**
- * @brief initlization
- *
- * @param [in] ptr DAO base address
- * @param [in] config dao_config_t
- * @retval hpm_stat_t status_invalid_argument or status_success
- */
- hpm_stat_t dao_init(DAO_Type *ptr, dao_config_t *config);
- /**
- * @brief get default config
- *
- * @param [in] ptr DAO base address
- * @param [out] config dao_config_t
- */
- void dao_get_default_config(DAO_Type *ptr, dao_config_t *config);
- /**
- * @}
- */
- #ifdef __cplusplus
- }
- #endif
- #endif /* HPM_DAO_DRV_H */
|