2021-02-02 20:14:39 -05:00
|
|
|
/*
|
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2021 Scott Shawcroft for Adafruit Industries
|
|
|
|
*
|
|
|
|
* 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_RASPBERRYPI_AUDIO_DMA_OUT_H
|
|
|
|
#define MICROPY_INCLUDED_RASPBERRYPI_AUDIO_DMA_OUT_H
|
|
|
|
|
|
|
|
#include "py/obj.h"
|
|
|
|
#include "supervisor/background_callback.h"
|
|
|
|
|
|
|
|
#include "src/rp2_common/hardware_dma/include/hardware/dma.h"
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
mp_obj_t sample;
|
2021-08-20 20:30:13 -04:00
|
|
|
uint8_t *buffer[2];
|
|
|
|
size_t buffer_length[2];
|
|
|
|
uint32_t channels_to_load_mask;
|
|
|
|
uint32_t output_register_address;
|
|
|
|
background_callback_t callback;
|
2021-02-02 20:14:39 -05:00
|
|
|
uint8_t channel[2];
|
|
|
|
uint8_t audio_channel;
|
|
|
|
uint8_t output_size;
|
|
|
|
uint8_t sample_spacing;
|
2021-08-20 20:30:13 -04:00
|
|
|
uint8_t output_resolution; // in bits
|
|
|
|
uint8_t sample_resolution; // in bits
|
2021-02-02 20:14:39 -05:00
|
|
|
bool loop;
|
2021-06-30 13:11:54 -04:00
|
|
|
bool single_channel_output;
|
2021-02-02 20:14:39 -05:00
|
|
|
bool signed_to_unsigned;
|
|
|
|
bool unsigned_to_signed;
|
|
|
|
bool output_signed;
|
2021-08-03 19:12:14 -04:00
|
|
|
bool playing_in_progress;
|
2021-02-02 20:14:39 -05:00
|
|
|
} audio_dma_t;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
AUDIO_DMA_OK,
|
|
|
|
AUDIO_DMA_DMA_BUSY,
|
|
|
|
AUDIO_DMA_MEMORY_ERROR,
|
|
|
|
} audio_dma_result;
|
|
|
|
|
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
void audio_dma_init(audio_dma_t *dma);
|
|
|
|
void audio_dma_deinit(audio_dma_t *dma);
|
2021-02-02 20:14:39 -05:00
|
|
|
void audio_dma_reset(void);
|
|
|
|
|
|
|
|
// This sets everything up but doesn't start the timer.
|
|
|
|
// Sample is the python object for the sample to play.
|
|
|
|
// loop is true if we should loop the sample.
|
2021-06-30 13:11:54 -04:00
|
|
|
// single_channel_output is true if we only output a single channel. When false, all channels will be
|
2021-02-02 20:14:39 -05:00
|
|
|
// output.
|
2021-06-30 13:11:54 -04:00
|
|
|
// audio_channel is the index of the channel to dma. single_channel_output must be false in this case.
|
2021-02-02 20:14:39 -05:00
|
|
|
// output_signed is true if the dma'd data should be signed. False and it will be unsigned.
|
|
|
|
// output_register_address is the address to copy data to.
|
|
|
|
// dma_trigger_source is the DMA trigger source which cause another copy
|
2021-03-15 09:57:36 -04:00
|
|
|
audio_dma_result audio_dma_setup_playback(audio_dma_t *dma,
|
|
|
|
mp_obj_t sample,
|
|
|
|
bool loop,
|
2021-06-30 13:11:54 -04:00
|
|
|
bool single_channel_output,
|
2021-03-15 09:57:36 -04:00
|
|
|
uint8_t audio_channel,
|
|
|
|
bool output_signed,
|
|
|
|
uint8_t output_resolution,
|
|
|
|
uint32_t output_register_address,
|
|
|
|
uint8_t dma_trigger_source);
|
2021-02-02 20:14:39 -05:00
|
|
|
|
2021-03-15 09:57:36 -04:00
|
|
|
void audio_dma_stop(audio_dma_t *dma);
|
|
|
|
bool audio_dma_get_playing(audio_dma_t *dma);
|
|
|
|
void audio_dma_pause(audio_dma_t *dma);
|
|
|
|
void audio_dma_resume(audio_dma_t *dma);
|
|
|
|
bool audio_dma_get_paused(audio_dma_t *dma);
|
2021-02-02 20:14:39 -05:00
|
|
|
|
2023-06-26 11:33:41 -04:00
|
|
|
uint32_t audio_dma_pause_all(void);
|
2023-06-27 10:59:02 -04:00
|
|
|
void audio_dma_unpause_mask(uint32_t channel_mask);
|
2023-06-26 11:33:41 -04:00
|
|
|
|
2021-02-02 20:14:39 -05:00
|
|
|
#endif // MICROPY_INCLUDED_RASPBERRYPI_AUDIO_DMA_OUT_H
|