Skip to content
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8f66fcc
[architecture] I2sMaster created
ledneczki Apr 28, 2021
e158b11
[dma] Support double buffer (only stm32-stream-channel)
rleh Oct 29, 2021
294b380
[rcc] Add support for I2S pll on STM32F4
ledneczki Apr 18, 2021
e8b8e36
[board] Disco-F469: MicroSD card connector
rleh Feb 28, 2022
5a040e0
[stm32] I2S master implementation with DMA
ledneczki Apr 29, 2021
d51569b
[driver] Add CS43L22 audio DAC (I2S + I²C)
ledneczki May 9, 2021
3bb021d
[board] Adapt STM32F4-Disco BSP for I2S DAC CS43L22
ledneczki May 4, 2021
ef6baee
[example] STM32F4-Disco: CS43L22 I2S DAC example
rleh Oct 30, 2021
9d7cae5
[driver] Add MA12070P audio DAC (I2S + I²C)
rleh Feb 28, 2022
d31ea26
WIP [example] STM32F469-Disco: MA12070P I2S DAC example
rleh Feb 28, 2022
1a8494b
fixup_example_cs43l22
rleh Mar 2, 2022
9f243a2
fixup_platform_i2s
rleh Mar 2, 2022
5251e28
fixup_architecture_i2s
rleh Mar 2, 2022
cb87fe0
fixup_rcc
rleh Mar 2, 2022
db6e309
fixup_ma12070p
rleh Mar 7, 2022
7b42b83
fixup_cs43l22
rleh Mar 7, 2022
cc6cb20
fixup_disco_f407vg
rleh Mar 7, 2022
9d38a46
fixup_example_ma12070p
rleh Mar 7, 2022
eacad10
fixup platform i2s: disable stm32h7
rleh Mar 8, 2022
001c09a
fixup platform i2s: stm32f410 has no PllI2s
rleh Mar 8, 2022
9b7d3e8
fixup driver ma12070p
rleh Mar 18, 2022
a4cffe6
fixup example stm32f469_discovery/audio_ma12070p
rleh Mar 18, 2022
7406d7d
fixup audio_ma12070p: move to nucleo-f429 dev board
rleh Mar 22, 2022
a816af3
fixup example ma12070p: adapt changed I2sMaster API
rleh Mar 22, 2022
3ead27e
fixup platform/i2s: fix prescaler calculation, i2s config is now temp…
rleh Mar 22, 2022
2c85e4f
fixup dma: enable double buffer also for 'stm32-mux-stream' IP
rleh Mar 22, 2022
4859b64
fixup driver ma12070p
rleh Mar 22, 2022
812d354
fixup driver cs43l22
rleh Mar 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,28 @@ Please [discover modm's peripheral drivers for your specific device][discover].
<td align="center">✅</td>
<td align="center">✅</td>
</tr><tr>
<td align="left">I2S</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✅</td>
<td align="center">✕</td>
<td align="center">✕</td>
<td align="center">○</td>
<td align="center">✕</td>
<td align="center">✕</td>
<td align="center">✕</td>
<td align="center">✕</td>
<td align="center">✕</td>
<td align="center">✕</td>
</tr><tr>
<td align="left">I<sup>2</sup>C</td>
<td align="center">✅</td>
<td align="center">✅</td>
Expand Down Expand Up @@ -647,82 +669,84 @@ you specific needs.
<td align="center"><a href="https://modm.io/reference/module/modm-driver-bno055">BNO055</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-cat24aa">CAT24AA</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-cs43l22">CS43L22</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-drv832x_spi">DRV832X</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ds1302">DS1302</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ds1631">DS1631</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ds18b20">DS18B20</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ea_dog">EA-DOG</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ea_dog">EA-DOG</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_input">Encoder Input</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_input-bitbang">Encoder Input BitBang</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-encoder_output-bitbang">Encoder Output BitBang</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ft245">FT245</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ft6x06">FT6x06</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-gpio_sampler">Gpio Sampler</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-gpio_sampler">Gpio Sampler</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hclax">HCLAx</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hd44780">HD44780</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hmc58x">HMC58x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hmc6343">HMC6343</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-hx711">HX711</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-i2c-eeprom">I2C-EEPROM</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-i2c-eeprom">I2C-EEPROM</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ili9341">ILI9341</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-is31fl3733">IS31FL3733</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-itg3200">ITG3200</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-l3gd20">L3GD20</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lan8720a">LAN8720A</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lawicel">LAWICEL</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lawicel">LAWICEL</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis302dl">LIS302DL</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis3dsh">LIS3DSH</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lis3mdl">LIS3MDL</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lm75">LM75</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lp503x">LP503x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lsm303a">LSM303A</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lsm303a">LSM303A</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-lsm6ds33">LSM6DS33</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ltc2984">LTC2984</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ma12070p">MA12070P</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max6966">MAX6966</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-max7219">MAX7219</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp23x17">MCP23x17</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp2515">MCP2515</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mcp7941x">MCP7941x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-mmc5603">MMC5603</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-nokia5110">NOKIA5110</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-nrf24">NRF24</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-parallel_tft_display">TFT-DISPLAY</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pat9125el">PAT9125EL</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca8574">PCA8574</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9535">PCA9535</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9548a">PCA9548A</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-pca9685">PCA9685</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sh1106">SH1106</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s65">SIEMENS-S65</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-siemens_s75">SIEMENS-S75</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk6812">SK6812</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sk9822">SK9822</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ssd1306">SSD1306</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-st7586s">ST7586S</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stts22h">STTS22H</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-stusb4500">STUSB4500</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-sx1276">SX1276</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3414">TCS3414</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tcs3472">TCS3472</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tlc594x">TLC594x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp102">TMP102</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp12x">TMP12x</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-tmp175">TMP175</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-touch2046">TOUCH2046</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl53l0">VL53L0</a></td>
</tr><tr>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-vl6180">VL6180</a></td>
<td align="center"><a href="https://modm.io/reference/module/modm-driver-ws2812">WS2812</a></td>
</tr><tr>
</tr>
</table>
<!--/drivertable-->
Expand Down
166 changes: 166 additions & 0 deletions examples/stm32f469_discovery/audio_ma12070p/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/*
* Copyright (c) 2022, Raphael Lehmann
* Copyright (c) 2021, Christopher Durand
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------

#include <arm_math.h>
#include <modm/board.hpp>
#include <modm/processing.hpp>
#include <modm/driver/dac/ma12070p.hpp>
#include <modm/platform/i2c/i2c_master_1.hpp>
#include <modm/platform/i2s/i2s_master_2.hpp>
#include <numbers>
#include <optional>

using namespace Board;
using namespace modm::literals;

// I²C pins shared with touchscreen:
using Scl = GpioB8;
using Sda = GpioB9;
using I2cMaster = modm::platform::I2cMaster1;
using Ma12070p = modm::Ma12070p<I2cMaster>;

using I2sWs = GpioOutputB12;
using I2sMck = GpioOutputC6;
using I2sCk = GpioOutputB13;
using I2sData = GpioOutputC1;
using DmaTx = Dma1::Channel4;
using I2sMaster = modm::platform::I2sMaster2<DmaTx>;


struct I2sSystemClock
{
static constexpr uint32_t I2sPll = 86_MHz;

static void
enable()
{
const Rcc::PllI2sFactors pllI2sFactors{
.pllN = 258, // 1 MHz * N=258 -> 258 MHz
.pllR = 3 // 258 MHz / R=3 -> 86 MHz
};
Rcc::enablePllI2s(pllI2sFactors);
}
};

constexpr uint8_t ma12070pAddressI2c = 0x20;
Ma12070p ma12070p{ma12070pAddressI2c};

template<typename T, std::size_t length>
constexpr auto computeSinTable(uint8_t cycles=1)
{
std::array<T, length> data{};
constexpr auto HalfOutput = std::numeric_limits<T>::max() / 2; // 16 bit full scale
for (size_t i = 0; i < data.size(); ++i) {
constexpr auto pi = std::numbers::pi_v<float>;
data[i] = HalfOutput * (1 + arm_sin_f32(i * (2*pi / data.size() * cycles)));
}
return data;
}

constexpr std::size_t bufferSize = 960;
auto bufferA = computeSinTable<uint16_t, bufferSize>(1);
auto bufferB = computeSinTable<uint16_t, bufferSize>(2);
volatile bool bufferA_ready{true};
volatile bool bufferB_ready{true};

void
transferCompleteIrqHandler()
{
LedGreen::reset();

if (bufferA_ready) {
I2sMaster::setTxBuffer(uintptr_t(bufferA.data()), bufferSize);
bufferA_ready = false;
}
else if (bufferB_ready) {
I2sMaster::setTxBuffer(uintptr_t(bufferB.data()), bufferSize);
bufferB_ready = false;
}
else {
LedRed::toggle();
//MODM_LOG_ERROR << "No buffer ready for DMA :(" << modm::endl;
}
I2sMaster::startDma();

LedGreen::set();
}

int
main()
{
Board::initialize();
I2sSystemClock::enable();
Board::initializeTouchscreen(); // for I2c
Dma1::enable();
Dma2::enable();

MODM_LOG_INFO << "Audio MA12070P demo on ST Discovery F469NI" << modm::endl;

while (!RF_CALL_BLOCKING(ma12070p.initialize())) {
MODM_LOG_ERROR << "Unable to initialize MA12070P" << modm::endl;
}


modm::ma12070p::I2sAndVlpConfig config {
.pcmWordFormat = modm::ma12070p::PcmWordFormat::RightJustifed16b,
.clockPolarity = modm::ma12070p::ClockPolarity::FallingEdge,
.frameSize = modm::ma12070p::FrameSize::Bits32,
.wordSelectPolarity = modm::ma12070p::WordSelectPolarity::High,
.rightLeftOrder = modm::ma12070p::RightLeftOrder::LeftFirst,
.useVlp = true,
.useLimiter = true,
};
while (!RF_CALL_BLOCKING(ma12070p.configureI2sAndVlp(config))) {
MODM_LOG_ERROR << "Unable to configure I2S ansd VLP settings of MA12070P" << modm::endl;
}

while (!RF_CALL_BLOCKING(ma12070p.setMasterVolume(-20_q_db))) {
MODM_LOG_ERROR << "Unable to set master volume of MA12070P" << modm::endl;
}

std::optional<modm::ma12070p::VlpMonitor_t> vlpMonitor;
std::optional<modm::ma12070p::ErrorRegister_t> errorRegister;

I2sMaster::connect<I2sMck::Mck, I2sCk::Ck, I2sWs::Ws, I2sData::Sd>();
I2sMaster::initialize<I2sSystemClock, 48_kHz, 1_pct>(
I2sMaster::BitDepth::SixteenWithChannel16,
I2sMaster::MasterClockOutput::Enabled,
I2sMaster::I2sStandard::Philips);

I2sMaster::setTransferCompleteIrqHandler(transferCompleteIrqHandler);
I2sMaster::setTxBuffer(uintptr_t(bufferA.data()), bufferSize);
I2sMaster::start();

while (true)
{
vlpMonitor = RF_CALL_BLOCKING(ma12070p.readVlpMonitor());
if(!vlpMonitor) {
MODM_LOG_ERROR << "Unable to read VLP monitor register" << modm::endl;
}
else {
MODM_LOG_ERROR << *vlpMonitor << modm::endl;
}
errorRegister = RF_CALL_BLOCKING(ma12070p.readAccumulatedErrors());
if(!errorRegister) {
MODM_LOG_ERROR << "Unable to read accumulated error register" << modm::endl;
}
else {
MODM_LOG_ERROR << *errorRegister << modm::endl;
}

if (I2sMaster::hasDmaError()) {
MODM_LOG_ERROR << "I2S DMA Error :(" << modm::endl;
}
}

return 0;
}
14 changes: 14 additions & 0 deletions examples/stm32f469_discovery/audio_ma12070p/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<library>
<extends>modm:disco-f469ni</extends>
<options>
<option name="modm:build:build.path">../../../build/stm32f469_discovery/audio_ma12070p</option>
</options>
<modules>
<module>modm:build:scons</module>
<module>modm:cmsis:dsp:fast_math</module>
<module>modm:driver:ma12070p</module>
<module>modm:platform:i2c:1</module>
<module>modm:platform:i2s:2</module>
<module>modm:processing:timer</module>
</modules>
</library>
Loading