|
| 1 | +/* |
| 2 | + * Copyright (c) 2021, Marton Lednczki |
| 3 | + * Copyright (c) 2022, Raphael Lehmann |
| 4 | + * |
| 5 | + * This file is part of the modm project. |
| 6 | + * |
| 7 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 8 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 9 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 10 | + */ |
| 11 | +// ---------------------------------------------------------------------------- |
| 12 | + |
| 13 | +#ifndef MODM_INTERFACE_I2S_MASTER_HPP |
| 14 | +#define MODM_INTERFACE_I2S_MASTER_HPP |
| 15 | + |
| 16 | +#include <modm/processing/resumable.hpp> |
| 17 | +#include "i2s.hpp" |
| 18 | + |
| 19 | +namespace modm |
| 20 | +{ |
| 21 | + |
| 22 | +/** |
| 23 | + * Interface for a I2S Master |
| 24 | + * |
| 25 | + * @author Marton Ledneczki |
| 26 | + * @ingroup modm_architecture_i2s |
| 27 | + */ |
| 28 | +class I2sMaster : public ::modm::PeripheralDriver |
| 29 | +{ |
| 30 | +#ifdef __DOXYGEN__ |
| 31 | +public: |
| 32 | + /** |
| 33 | + * @brief Connect GPIOs to the peripheral and configure them. |
| 34 | + * |
| 35 | + * This configures the CK (serial clock), MCK (master clock), |
| 36 | + * SD (serial data) and WS (word select) signals and connects them. |
| 37 | + * |
| 38 | + * @tparam Signals One CK, SD, WS, MCK signal are required and can be |
| 39 | + * passed out-of-order. |
| 40 | + */ |
| 41 | + template< class... Signals > |
| 42 | + static void |
| 43 | + connect(); |
| 44 | + |
| 45 | + /** |
| 46 | + * @brief Initializes the hardware and sets the samplerate. |
| 47 | + * |
| 48 | + * @tparam SystemClock the currently active system clock |
| 49 | + * @tparam samplerate the desired sample rate in Hz |
| 50 | + * @tparam tolerance the allowed relative tolerance for the resulting samplerate |
| 51 | + */ |
| 52 | + template< class SystemClock, frequency_t samplerate, percent_t tolerance=pct(0.019) > |
| 53 | + static void |
| 54 | + initialize(); |
| 55 | + |
| 56 | + |
| 57 | + /** |
| 58 | + * @brief Set the buffer |
| 59 | + * |
| 60 | + * @param address Pointer to the buffer. The user has to ensure the buffer is in DMA-able memory. |
| 61 | + * @param length Size of the buffer |
| 62 | + */ |
| 63 | + static void |
| 64 | + setTxBuffer(uintptr_t address, std::size_t length); |
| 65 | + |
| 66 | + /** |
| 67 | + * @brief Set transfer complete handler function |
| 68 | + * |
| 69 | + * The transfer complete handler should set the next tx buffer using |
| 70 | + * `setTxBuffer()` and then restart the DMA transfer using `startDma()`. |
| 71 | + */ |
| 72 | + static void |
| 73 | + setTransferCompleteIrqHandler(DmaBase::IrqHandler handleDmaTransferComplete); |
| 74 | + |
| 75 | + /** |
| 76 | + * @brief Starts the I2S peripheral |
| 77 | + */ |
| 78 | + static void |
| 79 | + start(); |
| 80 | + |
| 81 | + /** |
| 82 | + * @brief (Re-)Starts a DMA transfer |
| 83 | + * |
| 84 | + * This will be usually called inside the transfer complete handler after |
| 85 | + * a (new) tx buffer address was set. |
| 86 | + * |
| 87 | + * @see setTransferCompleteIrqHandler() |
| 88 | + */ |
| 89 | + static void |
| 90 | + startDma(); |
| 91 | + |
| 92 | + /** |
| 93 | + * @brief Stops I2S |
| 94 | + */ |
| 95 | + static void |
| 96 | + stop(); |
| 97 | + |
| 98 | +#endif |
| 99 | +}; |
| 100 | + |
| 101 | +} // namespace modm |
| 102 | + |
| 103 | +#endif // MODM_INTERFACE_SPI_MASTER_HPP |
0 commit comments