Skip to content

Commit 01ead17

Browse files
ledneczkirleh
authored andcommitted
[I2S] Add audio DAC driver and interrupt driven I2S
I2S master driver can be used with the TXE (transmit buffer empty) to transmit audio samples. The DAC driver is not that flexible at this moment. It just provides enough config that it can output audio on the headphone output. Register field definition is also not complete. I just added that much that is currently enough to make it work.
1 parent b5a2c3a commit 01ead17

File tree

8 files changed

+544
-102
lines changed

8 files changed

+544
-102
lines changed

src/modm/architecture/interface/i2s_master.hpp

Lines changed: 6 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -39,123 +39,27 @@ class I2sMaster : public ::modm::PeripheralDriver, public I2s
3939
* SD (serial data) and WS (word select) signals and connects them.
4040
*
4141
* @tparam Signals
42-
* One CK, SD and WS signal are required
42+
* One CK, SD, WS, MCK signal are required
4343
* and can be passed out-of-order.
4444
*/
4545
template< class... Signals >
4646
static void
4747
connect();
4848

4949
/**
50-
* Initializes the hardware and sets the baudrate.
50+
* Initializes the hardware and sets the samplerate.
5151
*
5252
* @tparam SystemClock
5353
* the currently active system clock
54-
* @tparam baudrate
55-
* the desired baudrate in Hz
54+
* @tparam samplerate
55+
* the desired sample rate in Hz
5656
* @tparam tolerance
57-
* the allowed relative tolerance for the resulting baudrate
57+
* the allowed relative tolerance for the resulting samplerate
5858
*/
59-
template< class SystemClock, baudrate_t baudrate, percent_t tolerance=5_pct >
59+
template< class SystemClock, frequency_t samplerate, percent_t tolerance=pct(0.019) >
6060
static void
6161
initialize();
6262

63-
/// Sets a new data mode.
64-
static void
65-
setDataMode(DataMode mode);
66-
67-
/// Sets a new data order.
68-
static void
69-
setDataOrder(DataOrder order);
70-
71-
/**
72-
* Request access to the spi master within a context.
73-
* You may acquire the spi master multiple times within the same context.
74-
*
75-
* The configuration handler will only be called when aquiring the spi
76-
* master for the first time (if it is not a `nullptr`).
77-
*
78-
* @warning Aquires must be balanced with releases of the **same** context!
79-
* @warning Aquires are persistent even after calling `initialize()`!
80-
*
81-
* @return `0` if another context is using the spi master, otherwise
82-
* `>0` as the number of times this context acquired the master.
83-
*/
84-
static uint8_t
85-
acquire(void *ctx, ConfigurationHandler handler = nullptr);
86-
87-
/**
88-
* Release access to the spi master within a context.
89-
*
90-
* @warning Releases must be balanced with acquires of the **same** context!
91-
* @warning Releases are persistent even after calling `initialize()`!
92-
*
93-
* @return `0` if nothing can be released anymore (for any context)
94-
* `>0` as the number of times this context can still release the master.
95-
*/
96-
static uint8_t
97-
release(void *ctx);
98-
99-
/**
100-
* Swap a single byte and wait for completion.
101-
*
102-
* @param data
103-
* data to be sent
104-
* @return received data
105-
*/
106-
static uint8_t
107-
transferBlocking(uint8_t data);
108-
109-
/**
110-
* Set the data buffers and length with options and starts a transfer.
111-
* This may be hardware accelerated (DMA or Interrupt), but not guaranteed.
112-
*
113-
* @param[in] tx
114-
* pointer to transmit buffer, set to `nullptr` to send dummy bytes
115-
* @param[out] rx
116-
* pointer to receive buffer, set to `nullptr` to discard received bytes
117-
* @param length
118-
* number of bytes to be shifted out
119-
*/
120-
static void
121-
transferBlocking(const uint8_t *tx, uint8_t *rx, std::size_t length);
122-
123-
/**
124-
* Swap a single byte and wait for completion non-blocking!.
125-
*
126-
* You must call this inside a Protothread or Resumable
127-
* using `PT_CALL` or `RF_CALL` respectively.
128-
* @warning These methods differ from Resumables by lacking context protection!
129-
* You must ensure that only one driver is accessing this resumable function
130-
* by using `acquire(ctx)` and `release(ctx)`.
131-
*
132-
* @param data
133-
* data to be sent
134-
* @return received data
135-
*/
136-
static modm::ResumableResult<uint8_t>
137-
transfer(uint8_t data);
138-
139-
/**
140-
* Set the data buffers and length with options and
141-
* starts a non-blocking transfer.
142-
* This may be hardware accelerated (DMA or Interrupt), but not guaranteed.
143-
*
144-
* You must call this inside a Protothread or Resumable
145-
* using `PT_CALL` or `RF_CALL` respectively.
146-
* @warning These methods differ from Resumables by lacking context protection!
147-
* You must ensure that only one driver is accessing this resumable function
148-
* by using `acquire(ctx)` and `release(ctx)`.
149-
*
150-
* @param[in] tx
151-
* pointer to transmit buffer, set to `nullptr` to send dummy bytes
152-
* @param[out] rx
153-
* pointer to receive buffer, set to `nullptr` to discard received bytes
154-
* @param length
155-
* number of bytes to be shifted out
156-
*/
157-
static modm::ResumableResult<void>
158-
transfer(const uint8_t *tx, uint8_t *rx, std::size_t length);
15963
#endif
16064
};
16165

src/modm/board/disco_f407vg/board.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,11 @@ initializeCs43()
226226

227227
cs43::I2cMaster::connect<cs43::Scl::Scl, cs43::Sda::Sda>();
228228
cs43::I2cMaster::initialize<SystemClock, 100_kHz>();
229+
230+
cs43::Reset::setOutput(modm::Gpio::Low);
231+
modm::delay_ms(2);
232+
cs43::Reset::setOutput(modm::Gpio::High);
233+
229234
}
230235

231236
/// not supported yet, due to missing I2S driver

0 commit comments

Comments
 (0)