diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..487eb96 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "python.linting.enabled": false, + "files.associations": { + "obj.h": "c" + } +} \ No newline at end of file diff --git a/MicroPython_BUILD/components/micropython/esp32/machine_i2s.c b/MicroPython_BUILD/components/micropython/esp32/machine_i2s.c index a09a506..19aae6b 100644 --- a/MicroPython_BUILD/components/micropython/esp32/machine_i2s.c +++ b/MicroPython_BUILD/components/micropython/esp32/machine_i2s.c @@ -25,20 +25,16 @@ */ #include "py/obj.h" +#include "py/objstr.h" #include "driver/i2s.h" // #include "machine_i2s.h" #include "py/runtime.h" #include "py/mperrno.h" -typedef enum { - I2S, I2S_MERUS, DAC_BUILT_IN, PDM -} output_mode_t; - typedef struct { mp_obj_base_t base; i2s_port_t port; - output_mode_t output_mode; i2s_config_t config; i2s_channel_t num_channels; uint8_t volume; @@ -48,57 +44,43 @@ extern const mp_obj_type_t machine_i2s_type; STATIC void machine_i2s_obj_init_helper(machine_i2s_obj_t *self, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_mode, ARG_bclk, ARG_ws, ARG_data_out, ARG_data_in, ARG_samplerate, ARG_bitdepth, ARG_channel, ARG_volume}; + enum { ARG_mode, ARG_rate, ARG_bits, ARG_channel_format, ARG_data_format, ARG_dma_count, ARG_dma_len}; static const mp_arg_t allowed_args[] = { - { MP_QSTR_mode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = DAC_BUILT_IN} }, - { MP_QSTR_bclk, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 2} }, - { MP_QSTR_ws, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 13} }, - { MP_QSTR_data_out, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 5} }, - { MP_QSTR_data_in, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = -1} }, - { MP_QSTR_samplerate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 48000} }, - { MP_QSTR_bitdepth, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 16} }, - { MP_QSTR_channel, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 2} }, - { MP_QSTR_volume, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 80} }, + { MP_QSTR_mode, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = I2S_MODE_MASTER | I2S_MODE_TX | I2S_MODE_DAC_BUILT_IN} }, + { MP_QSTR_rate, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 16000} }, + { MP_QSTR_bits, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 16} }, + { MP_QSTR_channel_format, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = I2S_CHANNEL_FMT_RIGHT_LEFT} }, + { MP_QSTR_data_format, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = I2S_COMM_FORMAT_I2S_MSB} }, + { MP_QSTR_dma_count, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 4} }, + { MP_QSTR_dma_len, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1024} }, }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - output_mode_t mode = args[ARG_mode].u_int; - self->output_mode = mode; - self->config.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_TX | (mode == DAC_BUILT_IN ? I2S_MODE_DAC_BUILT_IN : 0)); - self->config.sample_rate = args[ARG_samplerate].u_int; - self->config.bits_per_sample = args[ARG_bitdepth].u_int; - self->config.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT; - self->config.communication_format = (i2s_comm_format_t)((mode == DAC_BUILT_IN ? 0 : I2S_COMM_FORMAT_I2S) | I2S_COMM_FORMAT_I2S_MSB); + self->config.mode = (i2s_mode_t)(args[ARG_mode].u_int); + self->config.sample_rate = (int)args[ARG_rate].u_int; + self->config.bits_per_sample = (i2s_bits_per_sample_t)args[ARG_bits].u_int; + self->config.channel_format = (i2s_channel_fmt_t)args[ARG_channel_format].u_int; + self->config.communication_format = (i2s_comm_format_t)args[ARG_data_format].u_int; self->config.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1, //Interrupt level 1 - self->config.dma_buf_count = 4; - self->config.dma_buf_len = 1024; + self->config.dma_buf_count = (int)args[ARG_dma_count].u_int; + self->config.dma_buf_len = (int)args[ARG_dma_len].u_int; self->config.use_apll = 0; - self->num_channels = args[ARG_channel].u_int; - self->volume = args[ARG_volume].u_int; + + self->num_channels = 2; + self->volume = 100; if (i2s_driver_install(self->port, &self->config, 0, NULL) != ESP_OK) { mp_raise_ValueError("I2S: failed to enable"); } - if (mode == DAC_BUILT_IN) { + if ((self->config.mode & I2S_MODE_DAC_BUILT_IN) || (self->config.mode & I2S_MODE_PDM)) { i2s_set_pin(self->port, NULL); - i2s_set_dac_mode(I2S_DAC_CHANNEL_RIGHT_EN); - } else { - i2s_pin_config_t pin_config = { - .bck_io_num = args[ARG_bclk].u_int, - .ws_io_num = args[ARG_ws].u_int, - .data_out_num = args[ARG_data_out].u_int, - .data_in_num = args[ARG_data_in].u_int, - }; - if (i2s_set_pin(self->port, &pin_config) != ESP_OK) { - i2s_driver_uninstall(self->port); - mp_raise_ValueError("I2S: failed to set pins in"); - } - } + i2s_set_dac_mode(I2S_DAC_CHANNEL_BOTH_EN); // default + } i2s_set_clk(self->port, self->config.sample_rate, self->config.bits_per_sample, self->num_channels); - // i2s_zero_dma_buffer(self->port); } //---------------------------------------------------------------------- @@ -126,22 +108,38 @@ STATIC mp_obj_t machine_i2s_make_new(const mp_obj_type_t *type, size_t n_args, s } //---------------------------------------------------------------------- -STATIC mp_obj_t machine_i2s_obj_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t machine_i2s_init(size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { machine_i2s_obj_init_helper(args[0], n_args - 1, args + 1, kw_args); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_KW(machine_i2s_init_obj, 1, machine_i2s_obj_init); +MP_DEFINE_CONST_FUN_OBJ_KW(machine_i2s_init_obj, 2, machine_i2s_init); //---------------------------------------------------------------------- -STATIC mp_obj_t machine_i2s_obj_deinit(mp_obj_t self_in) { +STATIC mp_obj_t machine_i2s_deinit(mp_obj_t self_in) { const machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in); i2s_driver_uninstall(self->port); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_1(machine_i2s_deinit_obj, machine_i2s_obj_deinit); +MP_DEFINE_CONST_FUN_OBJ_1(machine_i2s_deinit_obj, machine_i2s_deinit); + +//---------------------------------------------------------------------- +STATIC mp_obj_t machine_i2s_start(mp_obj_t self_in) { + const machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in); + i2s_start(self->port); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(machine_i2s_start_obj, machine_i2s_start); + +//---------------------------------------------------------------------- +STATIC mp_obj_t machine_i2s_stop(mp_obj_t self_in) { + const machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in); + i2s_stop(self->port); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_1(machine_i2s_stop_obj, machine_i2s_stop); //----------------------------------------------------------------------- -STATIC mp_obj_t machine_i2s_obj_sample_rates(mp_obj_t self_in, mp_obj_t rate) { +STATIC mp_obj_t machine_i2s_sample_rates(mp_obj_t self_in, mp_obj_t rate) { machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in); self->config.sample_rate = mp_obj_get_int(rate); @@ -149,10 +147,10 @@ STATIC mp_obj_t machine_i2s_obj_sample_rates(mp_obj_t self_in, mp_obj_t rate) { return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_2(machine_i2s_set_sample_rates_obj, machine_i2s_obj_sample_rates); +MP_DEFINE_CONST_FUN_OBJ_2(machine_i2s_sample_rates_obj, machine_i2s_sample_rates); //----------------------------------------------------------------------- -STATIC mp_obj_t machine_i2s_obj_bits_per_sample(mp_obj_t self_in, mp_obj_t bits) { +STATIC mp_obj_t machine_i2s_bits_per_sample(mp_obj_t self_in, mp_obj_t bits) { machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in); self->config.bits_per_sample = (i2s_bits_per_sample_t)mp_obj_get_int(bits); @@ -160,10 +158,10 @@ STATIC mp_obj_t machine_i2s_obj_bits_per_sample(mp_obj_t self_in, mp_obj_t bits) return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_2(machine_i2s_obj_bits_per_sample_obj, machine_i2s_obj_bits_per_sample); +MP_DEFINE_CONST_FUN_OBJ_2(machine_i2s_bits_per_sample_obj, machine_i2s_bits_per_sample); //----------------------------------------------------------------------- -STATIC mp_obj_t machine_i2s_obj_set_channel(mp_obj_t self_in, mp_obj_t channel) { +STATIC mp_obj_t machine_i2s_set_channel(mp_obj_t self_in, mp_obj_t channel) { machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in); self->num_channels = (i2s_channel_t)mp_obj_get_int(channel); @@ -171,20 +169,121 @@ STATIC mp_obj_t machine_i2s_obj_set_channel(mp_obj_t self_in, mp_obj_t channel) return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_2(machine_i2s_obj_set_channel_obj, machine_i2s_obj_set_channel); +MP_DEFINE_CONST_FUN_OBJ_2(machine_i2s_set_channel_obj, machine_i2s_set_channel); //----------------------------------------------------------------------- -STATIC mp_obj_t machine_i2s_obj_set_volume(mp_obj_t self_in, mp_obj_t volume) { +STATIC mp_obj_t machine_i2s_set_dac_mode(mp_obj_t self_in, mp_obj_t dac_mode) { + machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in); + + uint8_t _dac_mode = mp_obj_get_int(dac_mode); + + if (self->port == I2S_NUM_0) { + i2s_set_dac_mode((i2s_dac_mode_t)_dac_mode); + } else { + mp_raise_ValueError("PDM and built-in DAC functions are only supported on I2S0 for current ESP32 chip."); + } + + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(machine_i2s_set_dac_mode_obj, machine_i2s_set_dac_mode); + +//----------------------------------------------------------------------- +STATIC mp_obj_t machine_i2s_set_adc_mode(mp_obj_t self_in, mp_obj_t pin) { + machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in); + + uint8_t adc_pin = mp_obj_get_int(pin); + uint8_t adc1_channel[] = { + ADC1_CHANNEL_4, /*!< ADC1 channel 4 is GPIO32 */ + ADC1_CHANNEL_5, /*!< ADC1 channel 5 is GPIO33 */ + ADC1_CHANNEL_6, /*!< ADC1 channel 6 is GPIO34 */ + ADC1_CHANNEL_7, /*!< ADC1 channel 7 is GPIO35 */ + ADC1_CHANNEL_0, /*!< ADC1 channel 0 is GPIO36 */ + ADC1_CHANNEL_1, /*!< ADC1 channel 1 is GPIO37 */ + ADC1_CHANNEL_2, /*!< ADC1 channel 2 is GPIO38 */ + ADC1_CHANNEL_3 /*!< ADC1 channel 3 is GPIO39 */ + }; + + if (adc_pin < 32 || adc_pin > 39) { + mp_raise_ValueError("built-in ADC functions are only supported ADC1 channel."); + } + + if (self->port == I2S_NUM_0) { + i2s_set_adc_mode(ADC_UNIT_1, (adc1_channel_t)(adc1_channel[adc_pin - 32])); + } else { + mp_raise_ValueError("built-in ADC functions are only supported on I2S0 for current ESP32 chip."); + } + + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(machine_i2s_set_adc_mode_obj, machine_i2s_set_adc_mode); + +//----------------------------------------------------------------------- +STATIC mp_obj_t machine_i2s_adc_enable(mp_obj_t self_in, mp_obj_t enable) { + machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in); + + uint8_t _enable = mp_obj_get_int(enable); + + if (_enable) { + i2s_adc_enable(self->port); + } else { + i2s_adc_disable(self->port); + } + + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(machine_i2s_adc_enable_obj, machine_i2s_adc_enable); + +//------------------------------------------------------------------------------------------------- +STATIC mp_obj_t machine_i2s_set_pin(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + + const mp_arg_t allowed_args[] = { + { MP_QSTR_bck, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } }, + { MP_QSTR_ws, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } }, + { MP_QSTR_out, MP_ARG_REQUIRED | MP_ARG_INT, { .u_int = 0 } }, + { MP_QSTR_in, MP_ARG_INT, { .u_int = -1 } }, + }; + machine_i2s_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); + + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + mp_int_t bck_io_num = args[0].u_int; + mp_int_t ws_io_num = args[1].u_int; + mp_int_t data_out_num = args[2].u_int; + mp_int_t data_in_num = -1; + + if (args[3].u_int >= 0) { + mp_int_t data_in_num = args[3].u_int; + } + + i2s_pin_config_t pin_config = { + .bck_io_num = bck_io_num, + .ws_io_num = ws_io_num, + .data_out_num = data_out_num, + .data_in_num = data_in_num, + }; + + if (i2s_set_pin(self->port, &pin_config) != ESP_OK) { + i2s_driver_uninstall(self->port); + mp_raise_ValueError("I2S: failed to set pins in"); + } + + return mp_const_none; +} +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_i2s_set_pin_obj, 3, machine_i2s_set_pin); + +//----------------------------------------------------------------------- +STATIC mp_obj_t machine_i2s_set_volume(mp_obj_t self_in, mp_obj_t volume) { machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in); self->volume = mp_obj_get_int(volume); return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_2(machine_i2s_obj_set_volume_obj, machine_i2s_obj_set_volume); +MP_DEFINE_CONST_FUN_OBJ_2(machine_i2s_set_volume_obj, machine_i2s_set_volume); //---------------------------------------------------------------------- -STATIC mp_obj_t machine_i2s_obj_write(const mp_obj_t self_in, mp_obj_t buf_in) { +STATIC mp_obj_t machine_i2s_write(const mp_obj_t self_in, mp_obj_t buf_in) { const machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_buffer_info_t bufinfo; @@ -196,10 +295,31 @@ STATIC mp_obj_t machine_i2s_obj_write(const mp_obj_t self_in, mp_obj_t buf_in) { return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_2(machine_i2s_write_obj, machine_i2s_obj_write); +MP_DEFINE_CONST_FUN_OBJ_2(machine_i2s_write_obj, machine_i2s_write); //---------------------------------------------------------------------- -STATIC mp_obj_t machine_i2s_obj_stream_out(const mp_obj_t self_in, mp_obj_t buf_in) { +STATIC mp_obj_t machine_i2s_read(const mp_obj_t self_in, mp_obj_t buf_len) { + const machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in); + + uint8_t *rdbuf = malloc(buf_len); + + if (i2s_read_bytes(self->port, (char*)rdbuf, buf_len, portMAX_DELAY) == ESP_FAIL) { + mp_raise_OSError(MP_EIO); + return mp_const_none; + } + + mp_obj_t res = mp_const_none; + if (rdbuf) res = mp_obj_new_str_of_type(&mp_type_bytes, (byte*)rdbuf, buf_len); + else res = mp_obj_new_str_of_type(&mp_type_bytes, (byte*)"", 0); + + if (rdbuf) free(rdbuf); + + return res; +} +MP_DEFINE_CONST_FUN_OBJ_2(machine_i2s_read_obj, machine_i2s_read); + +//---------------------------------------------------------------------- +STATIC mp_obj_t machine_i2s_stream_out(const mp_obj_t self_in, mp_obj_t buf_in) { const machine_i2s_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_buffer_info_t bufinfo; @@ -208,6 +328,12 @@ STATIC mp_obj_t machine_i2s_obj_stream_out(const mp_obj_t self_in, mp_obj_t buf_ uint8_t buf_bytes_per_sample = (self->config.bits_per_sample / 8); uint32_t num_samples = bufinfo.len / buf_bytes_per_sample / self->num_channels; + // support only 16 bit buffers for now + if(self->config.bits_per_sample != I2S_BITS_PER_SAMPLE_16BIT) { + mp_raise_ValueError("support only 16 bit buffers for now"); + return mp_const_none; + } + // pointer to left / right sample position char *ptr_l = bufinfo.buf; char *ptr_r = bufinfo.buf + buf_bytes_per_sample; @@ -221,7 +347,7 @@ STATIC mp_obj_t machine_i2s_obj_stream_out(const mp_obj_t self_in, mp_obj_t buf_ TickType_t max_wait = 20 / portTICK_PERIOD_MS; // portMAX_DELAY = bad idea for (int i = 0; i < num_samples; i++) { - if(self->output_mode == DAC_BUILT_IN) { + if (self->config.mode & I2S_MODE_DAC_BUILT_IN) { // assume 16 bit src bit_depth short left = *(short *) ptr_l; short right = *(short *) ptr_r; @@ -236,7 +362,7 @@ STATIC mp_obj_t machine_i2s_obj_stream_out(const mp_obj_t self_in, mp_obj_t buf_ uint32_t sample = (uint16_t) left; sample = (sample << 16 & 0xffff0000) | ((uint16_t) right); - bytes_pushed = i2s_push_sample(self->port, (const char*) &sample, max_wait); + bytes_pushed = i2s_push_sample(self->port, (const char*) &sample, 0); } else { switch (self->config.bits_per_sample) @@ -274,23 +400,57 @@ STATIC mp_obj_t machine_i2s_obj_stream_out(const mp_obj_t self_in, mp_obj_t buf_ return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_2(machine_i2s_obj_stream_out_obj, machine_i2s_obj_stream_out); +MP_DEFINE_CONST_FUN_OBJ_2(machine_i2s_stream_out_obj, machine_i2s_stream_out); //---------------------------------------------------------------------- STATIC const mp_rom_map_elem_t machine_i2s_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_i2s_init_obj)}, - { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_i2s_deinit_obj) }, - { MP_ROM_QSTR(MP_QSTR_sample_rate), MP_ROM_PTR(&machine_i2s_set_sample_rates_obj) }, - { MP_ROM_QSTR(MP_QSTR_bits_per_sample), MP_ROM_PTR(&machine_i2s_obj_bits_per_sample_obj) }, - { MP_ROM_QSTR(MP_QSTR_channel), MP_ROM_PTR(&machine_i2s_obj_set_channel_obj) }, - { MP_ROM_QSTR(MP_QSTR_volume), MP_ROM_PTR(&machine_i2s_obj_set_volume_obj) }, - { MP_ROM_QSTR(MP_QSTR_stream_out), MP_ROM_PTR(&machine_i2s_obj_stream_out_obj) }, - { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&machine_i2s_write_obj) }, - { MP_ROM_QSTR(MP_QSTR_MODE_IN_DAC), MP_ROM_INT(DAC_BUILT_IN) }, - { MP_ROM_QSTR(MP_QSTR_MODE_I2S), MP_ROM_INT(I2S) }, - { MP_ROM_QSTR(MP_QSTR_I2S_NUM_0), MP_ROM_INT(I2S_NUM_0) }, - { MP_ROM_QSTR(MP_QSTR_I2S_NUM_1), MP_ROM_INT(I2S_NUM_1) }, + // Standard methods + { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&machine_i2s_init_obj)}, + { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&machine_i2s_deinit_obj) }, + { MP_ROM_QSTR(MP_QSTR_start), MP_ROM_PTR(&machine_i2s_start_obj) }, + { MP_ROM_QSTR(MP_QSTR_stop), MP_ROM_PTR(&machine_i2s_stop_obj) }, + { MP_ROM_QSTR(MP_QSTR_sample_rate), MP_ROM_PTR(&machine_i2s_sample_rates_obj) }, + { MP_ROM_QSTR(MP_QSTR_bits), MP_ROM_PTR(&machine_i2s_bits_per_sample_obj) }, + { MP_ROM_QSTR(MP_QSTR_nchannels), MP_ROM_PTR(&machine_i2s_set_channel_obj) }, + { MP_ROM_QSTR(MP_QSTR_set_pin), MP_ROM_PTR(&machine_i2s_set_pin_obj) }, + { MP_ROM_QSTR(MP_QSTR_set_dac_mode), MP_ROM_PTR(&machine_i2s_set_dac_mode_obj) }, + { MP_ROM_QSTR(MP_QSTR_set_adc_mode), MP_ROM_PTR(&machine_i2s_set_adc_mode_obj) }, + { MP_ROM_QSTR(MP_QSTR_adc_enable), MP_ROM_PTR(&machine_i2s_adc_enable_obj) }, + { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&machine_i2s_write_obj) }, + { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&machine_i2s_read_obj) }, + { MP_ROM_QSTR(MP_QSTR_volume), MP_ROM_PTR(&machine_i2s_set_volume_obj) }, + { MP_ROM_QSTR(MP_QSTR_stream_out), MP_ROM_PTR(&machine_i2s_stream_out_obj) }, + + // Constants + { MP_ROM_QSTR(MP_QSTR_I2S_NUM_0), MP_ROM_INT(I2S_NUM_0) }, + { MP_ROM_QSTR(MP_QSTR_I2S_NUM_1), MP_ROM_INT(I2S_NUM_1) }, + + { MP_ROM_QSTR(MP_QSTR_MODE_MASTER), MP_ROM_INT(I2S_MODE_MASTER) }, + { MP_ROM_QSTR(MP_QSTR_MODE_SLAVE), MP_ROM_INT(I2S_MODE_SLAVE) }, + { MP_ROM_QSTR(MP_QSTR_MODE_TX), MP_ROM_INT(I2S_MODE_TX) }, + { MP_ROM_QSTR(MP_QSTR_MODE_RX), MP_ROM_INT(I2S_MODE_RX) }, + { MP_ROM_QSTR(MP_QSTR_MODE_DAC_BUILT_IN), MP_ROM_INT(I2S_MODE_DAC_BUILT_IN) }, + { MP_ROM_QSTR(MP_QSTR_MODE_ADC_BUILT_IN), MP_ROM_INT(I2S_MODE_ADC_BUILT_IN) }, + { MP_ROM_QSTR(MP_QSTR_MODE_PDM), MP_ROM_INT(I2S_MODE_PDM) }, + + { MP_ROM_QSTR(MP_QSTR_CHANNEL_RIGHT_LEFT),MP_ROM_INT(I2S_CHANNEL_FMT_RIGHT_LEFT) }, + { MP_ROM_QSTR(MP_QSTR_CHANNEL_ALL_RIGHT), MP_ROM_INT(I2S_CHANNEL_FMT_ALL_RIGHT) }, + { MP_ROM_QSTR(MP_QSTR_CHANNEL_ALL_LEFT), MP_ROM_INT(I2S_CHANNEL_FMT_ALL_LEFT) }, + { MP_ROM_QSTR(MP_QSTR_CHANNEL_ONLY_RIGHT),MP_ROM_INT(I2S_CHANNEL_FMT_ONLY_RIGHT) }, + { MP_ROM_QSTR(MP_QSTR_CHANNEL_ONLY_LEFT), MP_ROM_INT(I2S_CHANNEL_FMT_ONLY_LEFT) }, + + { MP_ROM_QSTR(MP_QSTR_FORMAT_I2S), MP_ROM_INT(I2S_COMM_FORMAT_I2S) }, + { MP_ROM_QSTR(MP_QSTR_FORMAT_I2S_MSB), MP_ROM_INT(I2S_COMM_FORMAT_I2S_MSB) }, + { MP_ROM_QSTR(MP_QSTR_FORMAT_I2S_LSB), MP_ROM_INT(I2S_COMM_FORMAT_I2S_LSB) }, + { MP_ROM_QSTR(MP_QSTR_FORMAT_PCM), MP_ROM_INT(I2S_COMM_FORMAT_PCM) }, + { MP_ROM_QSTR(MP_QSTR_FORMAT_PCM_SHORT), MP_ROM_INT(I2S_COMM_FORMAT_PCM_SHORT) }, + { MP_ROM_QSTR(MP_QSTR_FORMAT_PCM_LONG), MP_ROM_INT(I2S_COMM_FORMAT_PCM_LONG) }, + + { MP_ROM_QSTR(MP_QSTR_DAC_DISABLE), MP_ROM_INT(I2S_DAC_CHANNEL_DISABLE) }, + { MP_ROM_QSTR(MP_QSTR_DAC_RIGHT_EN), MP_ROM_INT(I2S_DAC_CHANNEL_RIGHT_EN) }, + { MP_ROM_QSTR(MP_QSTR_DAC_LEFT_EN), MP_ROM_INT(I2S_DAC_CHANNEL_LEFT_EN) }, + { MP_ROM_QSTR(MP_QSTR_DAC_BOTH_EN), MP_ROM_INT(I2S_DAC_CHANNEL_BOTH_EN) }, }; STATIC MP_DEFINE_CONST_DICT(machine_i2s_locals_dict, machine_i2s_locals_dict_table); @@ -300,4 +460,4 @@ const mp_obj_type_t machine_i2s_type = { .name = MP_QSTR_I2S, .make_new = machine_i2s_make_new, .locals_dict = (mp_obj_dict_t*)&machine_i2s_locals_dict, -}; \ No newline at end of file +}; diff --git a/MicroPython_BUILD/components/micropython/esp32/machine_i2s.h b/MicroPython_BUILD/components/micropython/esp32/machine_i2s.h deleted file mode 100644 index 80e0d21..0000000 --- a/MicroPython_BUILD/components/micropython/esp32/machine_i2s.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Ayke van Laethem - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MICROPY_INCLUDED_ESP32_MACHINE_I2S_H -#define MICROPY_INCLUDED_ESP32_MACHINE_I2S_H - -#include "py/obj.h" -#include "driver/i2s.h" - -typedef struct { - mp_obj_base_t base; - i2s_port_t port; -} machine_i2s_obj_t; - -extern const mp_obj_type_t machine_i2s_type; - -#endif // MICROPY_INCLUDED_ESP32_MACHINE_I2S_H \ No newline at end of file diff --git a/MicroPython_BUILD/components/micropython/esp32/moddisplay.c b/MicroPython_BUILD/components/micropython/esp32/moddisplay.c index d144eaa..3142656 100644 --- a/MicroPython_BUILD/components/micropython/esp32/moddisplay.c +++ b/MicroPython_BUILD/components/micropython/esp32/moddisplay.c @@ -1349,7 +1349,6 @@ STATIC mp_obj_t display_tft_setColor(size_t n_args, const mp_obj_t *pos_args, mp { MP_QSTR_color, MP_ARG_INT, { .u_int = -1 } }, { MP_QSTR_bcolor, MP_ARG_INT, { .u_int = -1 } }, }; - display_tft_obj_t *self = MP_OBJ_TO_PTR(pos_args[0]); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); diff --git a/MicroPython_BUILD/components/micropython/esp32/modmachine.c b/MicroPython_BUILD/components/micropython/esp32/modmachine.c index 9a16110..0dd0dc4 100644 --- a/MicroPython_BUILD/components/micropython/esp32/modmachine.c +++ b/MicroPython_BUILD/components/micropython/esp32/modmachine.c @@ -905,6 +905,7 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_Neopixel), MP_ROM_PTR(&machine_neopixel_type) }, { MP_OBJ_NEW_QSTR(MP_QSTR_DHT), MP_ROM_PTR(&machine_dht_type) }, { MP_OBJ_NEW_QSTR(MP_QSTR_Onewire), MP_ROM_PTR(&machine_onewire_type) }, +<<<<<<< HEAD // Constants { MP_ROM_QSTR(MP_QSTR_LOG_NONE), MP_ROM_INT(ESP_LOG_NONE) }, @@ -916,6 +917,9 @@ STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_EXT1_ANYHIGH), MP_ROM_INT(ESP_EXT1_WAKEUP_ANY_HIGH) }, { MP_ROM_QSTR(MP_QSTR_EXT1_ALLLOW), MP_ROM_INT(ESP_EXT1_WAKEUP_ALL_LOW) }, { MP_ROM_QSTR(MP_QSTR_EXT1_ANYLOW), MP_ROM_INT(EXT1_WAKEUP_ALL_HIGH) }, +======= + { MP_OBJ_NEW_QSTR(MP_QSTR_I2S), MP_ROM_PTR(&machine_i2s_type) }, +>>>>>>> i2s }; STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table); diff --git a/MicroPython_BUILD/components/micropython/esp32/modmachine.h b/MicroPython_BUILD/components/micropython/esp32/modmachine.h index 83159c7..58c0812 100644 --- a/MicroPython_BUILD/components/micropython/esp32/modmachine.h +++ b/MicroPython_BUILD/components/micropython/esp32/modmachine.h @@ -75,6 +75,7 @@ extern const mp_obj_type_t machine_neopixel_type; extern const mp_obj_type_t machine_dht_type; extern const mp_obj_type_t machine_onewire_type; extern const mp_obj_type_t machine_ds18x20_type; +extern const mp_obj_type_t machine_i2s_type; extern nvs_handle mpy_nvs_handle; diff --git a/MicroPython_BUILD/components/micropython/extmod/vfs_native.c b/MicroPython_BUILD/components/micropython/extmod/vfs_native.c index bad0813..40f51ec 100644 --- a/MicroPython_BUILD/components/micropython/extmod/vfs_native.c +++ b/MicroPython_BUILD/components/micropython/extmod/vfs_native.c @@ -655,7 +655,11 @@ STATIC void checkBoot_py() if (fd != NULL) { char buf[128] = {'\0'}; // sprintf(buf, "# This file is executed on every boot (including wake-boot from deepsleep)\nimport sys\nsys.path[1] = '/flash/lib'\n"); +<<<<<<< HEAD sprintf(buf, "import inisetup\n"); +======= + sprintf(buf, "import inisetup\n"); +>>>>>>> i2s int len = strlen(buf); int res = fwrite(buf, 1, len, fd); if (res != len) { diff --git a/MicroPython_BUILD/firmware/esp32/MicroPython.bin b/MicroPython_BUILD/firmware/esp32/MicroPython.bin index 0d5e7bd..480276d 100644 Binary files a/MicroPython_BUILD/firmware/esp32/MicroPython.bin and b/MicroPython_BUILD/firmware/esp32/MicroPython.bin differ diff --git a/MicroPython_BUILD/firmware/esp32/firmware.bin b/MicroPython_BUILD/firmware/esp32/firmware.bin index 8945f19..5cae4c3 100644 Binary files a/MicroPython_BUILD/firmware/esp32/firmware.bin and b/MicroPython_BUILD/firmware/esp32/firmware.bin differ diff --git a/MicroPython_BUILD/firmware/esp32/partitions_mpy.bin b/MicroPython_BUILD/firmware/esp32/partitions_mpy.bin index b6e4482..94e7dda 100644 Binary files a/MicroPython_BUILD/firmware/esp32/partitions_mpy.bin and b/MicroPython_BUILD/firmware/esp32/partitions_mpy.bin differ diff --git a/MicroPython_BUILD/firmware/esp32/partitions_mpy.csv b/MicroPython_BUILD/firmware/esp32/partitions_mpy.csv index 5aa8157..1f782a7 100644 --- a/MicroPython_BUILD/firmware/esp32/partitions_mpy.csv +++ b/MicroPython_BUILD/firmware/esp32/partitions_mpy.csv @@ -5,5 +5,5 @@ # ------------------------------------------------------- nvs, data, nvs, 0x9000, 24K, phy_init, data, phy, 0xf000, 4K, -MicroPython, app, factory, 0x10000, 1600K, -internalfs, data, spiffs, , 2432K, +MicroPython, app, factory, 0x10000, 1664K, +internalfs, data, spiffs, , 2368K, diff --git a/MicroPython_BUILD/firmware/esp32_psram/MicroPython.bin b/MicroPython_BUILD/firmware/esp32_psram/MicroPython.bin index 7043451..ea02d33 100644 Binary files a/MicroPython_BUILD/firmware/esp32_psram/MicroPython.bin and b/MicroPython_BUILD/firmware/esp32_psram/MicroPython.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_psram/firmware.bin b/MicroPython_BUILD/firmware/esp32_psram/firmware.bin index a9606fd..98a2a41 100644 Binary files a/MicroPython_BUILD/firmware/esp32_psram/firmware.bin and b/MicroPython_BUILD/firmware/esp32_psram/firmware.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_psram/partitions_mpy.bin b/MicroPython_BUILD/firmware/esp32_psram/partitions_mpy.bin index 77c62f1..a441257 100644 Binary files a/MicroPython_BUILD/firmware/esp32_psram/partitions_mpy.bin and b/MicroPython_BUILD/firmware/esp32_psram/partitions_mpy.bin differ diff --git a/MicroPython_BUILD/firmware/esp32_psram/partitions_mpy.csv b/MicroPython_BUILD/firmware/esp32_psram/partitions_mpy.csv index 5935343..02fe64b 100644 --- a/MicroPython_BUILD/firmware/esp32_psram/partitions_mpy.csv +++ b/MicroPython_BUILD/firmware/esp32_psram/partitions_mpy.csv @@ -5,5 +5,5 @@ # ------------------------------------------------------- nvs, data, nvs, 0x9000, 24K, phy_init, data, phy, 0xf000, 4K, -MicroPython, app, factory, 0x10000, 1728K, -internalfs, data, spiffs, , 2304K, +MicroPython, app, factory, 0x10000, 1792K, +internalfs, data, spiffs, , 2240K,