i2s and digital microphones

Discussion and questions about programming with Ultibo.
pik33
Posts: 891
Joined: Fri Sep 30, 2016 6:30 pm
Location: Poland
Contact:

Re: i2s and digital microphones

Postby pik33 » Mon Apr 15, 2019 6:14 am

Can RetAMP Player be configured to use I2S to output the audio?


Not yet. The player uses SimpleAudio for its output, so I have to finish the SimpleAudio i2s related code

As it is now, it only inits the device and transmits data through it.

I have to

(1) add i2s related code to InitAudio procedure
(2) modify the main audio thread to use i2s if needed

Then I have to add a configuration option for RetAMP to allow the user to select an audio output device.

So the answer is: it is doable but not yet done.

I have an i2s DAC HAT so I will do it sooner or later :)
pjde
Posts: 444
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: i2s and digital microphones

Postby pjde » Sat Apr 20, 2019 12:16 am

Apologies if I am missing the obvious but how do we specifiy the DMA channel we want to use in the DMATransferRequestEx function?

Regards

Paul
User avatar
Ultibo
Site Admin
Posts: 2303
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: i2s and digital microphones

Postby Ultibo » Sun Apr 21, 2019 10:14 am

pjde wrote:Apologies if I am missing the obvious but how do we specifiy the DMA channel we want to use in the DMATransferRequestEx function?

By design the DMA driver chooses the next available channel that suits your requirements, the Flags field of the TDMAData allows you to request a bulk channel (DMA_DATA_FLAG_BULK) or a lite channel (DMA_DATA_FLAG_LITE) but ultimately the channel selection is up to the host driver at present.

Of course the ability to reserve a channel (either generically or specifically) is something that could be useful in certain circumstances so we will add it to the feature list for future work.
Ultibo.org | Make something amazing
https://ultibo.org
pjde
Posts: 444
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: i2s and digital microphones

Postby pjde » Mon Apr 22, 2019 10:27 pm

Thanks Garry

The auto assignment should work fine for me.

One further question.

I am trying to use DMA to transfer from memory into the peripheral.

What properties do I need to set to transfer 4 bytes at a time to the same destination peripheral register (4 memory locations). If I set the NOINCREMENT flag, won't that only do the transfer on single bytes to the first memory location?

Regards

Paul
User avatar
Ultibo
Site Admin
Posts: 2303
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: i2s and digital microphones

Postby Ultibo » Tue Apr 23, 2019 12:02 am

pjde wrote:I am trying to use DMA to transfer from memory into the peripheral.

What properties do I need to set to transfer 4 bytes at a time to the same destination peripheral register (4 memory locations). If I set the NOINCREMENT flag, won't that only do the transfer on single bytes to the first memory location?

The DMA engines read and write 32bits at a time by default even when reading or writing to or from a peripheral. The details are shown in the BCM2835 ARM Peripherals document for the Transfer Information (TI) register on pages 50 to 52 which says if DEST_WIDTH = 0 use 32-bit destination write width and if DEST_INC = 0 destination address does not change.

The Ultibo API has its own set of DMA data flags (DMA_DATA_FLAG_*) which can be found in the Platform unit and map to these values, so for a memory to peripheral transfer you would use the following flags:

Code: Select all

DMA_DATA_FLAG_DEST_NOINCREMENT or DMA_DATA_FLAG_DEST_DREQ or DMA_DATA_FLAG_SOURCE_WIDE or DMA_DATA_FLAG_NOINVALIDATE

Which tells the DMA don't increment the destination address, use DREQ (data request) signal from the peripheral to control write timing, use wide (128bit) reads from the source address and don't perform cache invalidation on the destination address (because it isn't cached).

I'm assuming you are only wanting TX at present so one channel is all you need, but if you want to do simultaneous TX/RX as described on page 123 of BCM2835 ARM Peripherals then the SPI driver shows a good example of how to do that using two DMA requests and callbacks.
Ultibo.org | Make something amazing
https://ultibo.org
pjde
Posts: 444
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: i2s and digital microphones

Postby pjde » Tue Apr 23, 2019 4:08 am

Thanks again Garry

I think my DMA requests are correct now. (The transfer only completes if I set the I2S controller to master which is what I would expect).



Code: Select all

const
  PCM_REGS_BASE  = BCM2837_PCM_REGS_BASE;  // make board independent

var
  AudioBuffer : pointer;
  AudioBufferSize : cardinal;
  res : LongWord;
  DMAData : TDMAData; 
....
DMAData.Source := AudioBuffer;
DMAData.Dest := pointer (PCM_REGS_BASE + $04);     // Tx FIFO
DMAData.Flags := DMA_DATA_FLAG_DEST_DREQ or DMA_DATA_FLAG_DEST_NOINCREMENT or DMA_DATA_FLAG_SOURCE_WIDE or DMA_DATA_FLAG_NOINVALIDATE;
DMAData.Size := AudioBufferSize div 4;
DMAData.Next := nil;
res := DMATransferRequestEx (DMAHostGetDefault, @DMAData, @DMARequestCompleted, nil, DMA_DIR_MEM_TO_DEV, DMA_DREQ_ID_PCM_TX, DMA_REQUEST_FLAG_NONE);
 


My lack of audio must lie elsewhere. Onwards ever onwards.

Regards

Paul
User avatar
Ultibo
Site Admin
Posts: 2303
Joined: Sat Dec 19, 2015 3:49 am
Location: Australia

Re: i2s and digital microphones

Postby Ultibo » Tue Apr 23, 2019 11:23 am

pjde wrote:

Code: Select all

DMAData.Size := AudioBufferSize div 4;
 


I'm pretty sure there is no reason to divide the size by 4, even though the DMA transfers in 32bit writes it requires the size supplied to be the total in bytes.
Ultibo.org | Make something amazing
https://ultibo.org
pjde
Posts: 444
Joined: Tue Feb 09, 2016 6:21 am
Location: Sydney, Australia

Re: i2s and digital microphones

Postby pjde » Tue Apr 23, 2019 9:44 pm

Thanks Garry

I shall change it.

Regards

Paul

Return to “General”

Who is online

Users browsing this forum: No registered users and 39 guests