Skip to content

Commit 8f66fcc

Browse files
ledneczkirleh
andcommitted
[architecture] I2sMaster created
Co-authored-by: Raphael Lehmann <[email protected]>
1 parent 21ba120 commit 8f66fcc

File tree

2 files changed

+118
-0
lines changed

2 files changed

+118
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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

src/modm/architecture/module.lb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,20 @@ class I2cMultiplexer(Module):
231231
env.copy("interface/i2c_multiplexer.hpp")
232232
# -----------------------------------------------------------------------------
233233

234+
class I2s(Module):
235+
def init(self, module):
236+
module.name = "i2s"
237+
module.description = "Inter-IC Sound (I2S)"
238+
239+
def prepare(self, module, options):
240+
module.depends(":processing:resumable")
241+
return True
242+
243+
def build(self, env):
244+
env.outbasepath = "modm/src/modm/architecture"
245+
env.copy("interface/i2s_master.hpp")
246+
# -----------------------------------------------------------------------------
247+
234248
class Interrupt(Module):
235249
def init(self, module):
236250
module.name = "interrupt"
@@ -367,6 +381,7 @@ def prepare(module, options):
367381
module.add_submodule(I2c())
368382
module.add_submodule(I2cDevice())
369383
module.add_submodule(I2cMultiplexer())
384+
module.add_submodule(I2s())
370385
module.add_submodule(Interrupt())
371386
module.add_submodule(Memory())
372387
module.add_submodule(OneWire())

0 commit comments

Comments
 (0)