1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 
5 #include "py/builtin.h"
6 #include "py/obj.h"
7 #include "py/runtime.h"
8 #include "ulog/ulog.h"
9 
10 #define LOG_TAG "uvoice_snd"
11 
12 static bool is_uvoice_inited = false;
13 
get_uvoice_state()14 bool get_uvoice_state()
15 {
16     return is_uvoice_inited;
17 }
18 
set_uvoice_state(bool state)19 void set_uvoice_state(bool state)
20 {
21     is_uvoice_inited = state;
22 }
23 
uvoice_snd_print(const mp_print_t * print,mp_obj_t self_in,mp_print_kind_t kind)24 void uvoice_snd_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind)
25 {
26 }
27 
uvoice_snd_new(const mp_obj_type_t * type,size_t n_args,size_t n_kw,const mp_obj_t * args)28 STATIC mp_obj_t uvoice_snd_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args)
29 {
30     return mp_const_none;
31 }
32 
a2sa_uvoice_snd_init(void)33 STATIC mp_obj_t a2sa_uvoice_snd_init(void)
34 {
35     extern int audio_install_codec_driver();
36     mp_int_t ret = audio_install_codec_driver();
37     if (ret != 0) {
38         LOGE(LOG_TAG, "Failed to install codec driver, ret=%d", ret);
39         return MP_OBJ_NEW_SMALL_INT(ret);
40     }
41 
42     ret = uvoice_init();
43     if (ret != 0) {
44         LOGE(LOG_TAG, "Failed to init uvoice, ret=%d", ret);
45     } else {
46         set_uvoice_state(true);
47     }
48 
49     return MP_OBJ_NEW_SMALL_INT(ret);
50 }
51 MP_DEFINE_CONST_FUN_OBJ_0(a2sa_uvoice_snd_init_obj, a2sa_uvoice_snd_init);
52 
audio_uninstall_codec_driver()53 static mp_int_t audio_uninstall_codec_driver()
54 {
55     return 0;
56 }
57 
a2sa_uvoice_snd_deinit(void)58 STATIC mp_obj_t a2sa_uvoice_snd_deinit(void)
59 {
60     mp_int_t ret = audio_uninstall_codec_driver();
61     if (ret != 0) {
62         LOGE(LOG_TAG, "Failed to deinit uvoice, ret=%d", ret);
63         return MP_OBJ_NEW_SMALL_INT(ret);
64     }
65 
66     ret = uvoice_free();
67     if (ret != 0) {
68         LOGE(LOG_TAG, "Failed to deinit uvoice, ret=%d", ret);
69     } else {
70         set_uvoice_state(false);
71     }
72     return MP_OBJ_NEW_SMALL_INT(ret);
73 }
74 MP_DEFINE_CONST_FUN_OBJ_0(a2sa_uvoice_snd_deinit_obj, a2sa_uvoice_snd_deinit);
75 
76 STATIC const mp_rom_map_elem_t uvoice_module_snd_globals_table[] = {
77     { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&a2sa_uvoice_snd_init_obj) },
78     { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&a2sa_uvoice_snd_deinit_obj) },
79 };
80 STATIC MP_DEFINE_CONST_DICT(uvoice_module_snd_globals, uvoice_module_snd_globals_table);
81 
82 const mp_obj_type_t uvoice_snd_type = {
83     .base = { &mp_type_type },
84     .name = MP_QSTR_Snd,
85     .print = uvoice_snd_print,
86     .make_new = uvoice_snd_new,
87     .locals_dict = (mp_obj_dict_t *)&uvoice_module_snd_globals,
88 };
89