You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mynewt.apache.org by Doug Cooper <te...@gmail.com> on 2021/02/21 18:05:29 UTC

MyNewt api definition

I am trying to use the i2s driver in the latest master and it refers to a
driver definition.  I see that adding PWM0 ( in the syscfg.yml VALS)
enables the PWM api but I don't understand that process well enough to
determine the equivalent for the i2s code.  Can you point me to an example
or a description in the docs?

Appreciate it

Doug

Re: MyNewt api definition

Posted by Jerzy Kasenberg <je...@codecoup.pl>.
Hi Doug,

No MCU/BSP so far has I2S device configuration as easy as PWM (or
other devices) and maybe that
needs to be changed.

But to start using I2S your BSP needs to create I2S device with
i2s_create() function.
Keep in mind that parameter 3 cfg is hardware dependent so far and
needs to be different for different MCUs.

Now there is I2S support for STMF4/F1, nordic  and (partial DA1469x).
Let's assume that you base your design NRF52.

First add dependency to i2s_driver that corresponds to your MCU to
your app or bsp or target:

pkg.deps:
    - "@apache-mynewt-core/hw/drivers/i2s/i2s_nrf52"

In your BPS (or app) add variable

struct i2s i2s_dev;

Now  add buffer pool consisting of at least two buffers that will be
used to transfer samples.
This adds two buffers of 256 bytes that are suitable for 128 16bits samples.

I2S_BUFFER_POOL_DEF(i2s_pool, 2, 256);

and configuration with some hardware specific settings that match
specification of what is connected to i2s interface:

struct i2s_cfg i2s_fg = {
    .nrfx_i2s_cfg = {
        .alignment = I2S_CONFIG_ALIGN_ALIGN_LEFT,
        .channels = I2S_CONFIG_CHANNELS_CHANNELS_STEREO,
        .format = I2S_CONFIG_FORMAT_FORMAT_I2S,
        .irq_priority = 1,
        .sck_pin = ARDUINO_PIN_D0, /* Any pin of your choice */
        .lrck_pin = ARDUINO_PIN_D1,
        .mck_pin = NRFX_I2S_PIN_NOT_USED,
        .sdin_pin = NRFX_I2S_PIN_NOT_USED,
        .sdout_pin = ARDUINO_PIN_D2,
        .sample_width = NRF_I2S_SWIDTH_16BIT,
        .mode = I2S_CONFIG_MODE_MODE_MASTER
    },
    .pool = I2S_BUFFER_POOL(i2s_pool),
    .sample_rate = 32000, /* initial sample rate */
};

find function hal_bsp_init(void) and add i2s_create:

void
hal_bsp_init(void)
{
    /* Make sure system clocks have started */
    hal_system_clock_start();

    nrf52_periph_create();

    /* Create I2S device */
    i2s_create(&i2s_dev, "i2s", &i2s_cfg);
}

How to use it once device is created can be seen in
repos/apache-mynewt-core/hw/drivers/i2s/README.md

I recommend setting syscfg value I2S_BUFFER_GUARD to 4 when you start
working with I2S, since it
is very easy to fill buffers with more data that buffers can handle
and that may result in hard to
understand crashes.

good luck with you design and don't hesitate to ask for help.
Example that is above was not copied over as such from existing
project so it may not compile but
general idea should be correct.

best regards
Jerzy

niedz., 21 lut 2021 o 19:43 Doug Cooper <te...@gmail.com> napisaƂ(a):
>
> I am trying to use the i2s driver in the latest master and it refers to a
> driver definition.  I see that adding PWM0 ( in the syscfg.yml VALS)
> enables the PWM api but I don't understand that process well enough to
> determine the equivalent for the i2s code.  Can you point me to an example
> or a description in the docs?
>
> Appreciate it
>
> Doug