| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- #include "luat_base.h"
- #include "luat_gpio.h"
- #include "luat_audio.h"
- #include "luat_rtos.h"
- #define LUAT_LOG_TAG "tm8211"
- #include "luat_log.h"
- static int tm8211_codec_init(luat_audio_codec_conf_t* conf,uint8_t mode){
- if (conf->power_pin != LUAT_CODEC_PA_NONE){
- luat_gpio_mode(conf->power_pin, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, !conf->power_on_level);
- luat_gpio_set(conf->power_pin, conf->power_on_level);
- }
- if (conf->power_on_delay_ms){
- luat_rtos_task_sleep(conf->power_on_delay_ms);
- }
- return 0;
- }
- static int tm8211_codec_deinit(luat_audio_codec_conf_t* conf){
- if (conf->pa_pin != LUAT_CODEC_PA_NONE){
- luat_gpio_set(conf->pa_pin, !conf->pa_on_level);
- luat_gpio_close(conf->pa_pin);
- }
- if (conf->power_pin != LUAT_CODEC_PA_NONE){
- luat_gpio_set(conf->power_pin, !conf->power_on_level);
- luat_gpio_close(conf->power_pin);
- }
- return 0;
- }
- static void tm8211_codec_pa(luat_audio_codec_conf_t* conf,uint8_t on){
- if (conf->pa_pin == LUAT_CODEC_PA_NONE) return;
- if (on){
- luat_gpio_set(conf->pa_pin, conf->pa_on_level);
- }else{
- luat_gpio_set(conf->pa_pin, !conf->pa_on_level);
- }
- }
- static int tm8211_mode_pwrdown(luat_audio_codec_conf_t* conf){
- if (conf->power_pin != LUAT_CODEC_PA_NONE){
- luat_gpio_set(conf->power_pin, !conf->power_on_level);
- }
- }
- static int tm8211_codec_control(luat_audio_codec_conf_t* conf,luat_audio_codec_ctl_t cmd,uint32_t data){
- switch (cmd){
- case LUAT_CODEC_SET_PA:
- tm8211_codec_pa(conf,(uint8_t)data);
- break;
- case LUAT_CODEC_MODE_PWRDOWN:
- tm8211_mode_pwrdown(conf);
- break;
- default:
- break;
- }
- return 0;
- }
- static int tm8211_codec_start(luat_audio_codec_conf_t* conf){
- tm8211_codec_pa(conf,1);
- if (conf->power_pin != LUAT_CODEC_PA_NONE){
- luat_gpio_set(conf->power_pin, conf->power_on_level);
- }
- return 0;
- }
- static int tm8211_codec_stop(luat_audio_codec_conf_t* conf){
- tm8211_codec_pa(conf,0);
- if (conf->power_pin != LUAT_CODEC_PA_NONE){
- luat_gpio_set(conf->power_pin, !conf->power_on_level);
- }
- return 0;
- }
- const luat_audio_codec_opts_t codec_opts_tm8211 = {
- .name = "tm8211",
- .init = tm8211_codec_init,
- .deinit = tm8211_codec_deinit,
- .control = tm8211_codec_control,
- .start = tm8211_codec_start,
- .stop = tm8211_codec_stop,
- .no_control = 1,
- };
|