-
Notifications
You must be signed in to change notification settings - Fork 154
I2S driver for STM32F4 #621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
ledneczki
wants to merge
6
commits into
modm-io:develop
Choose a base branch
from
ledneczki:feature/i2s-stm32f407
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4826ca8
[I2S] Setup PLL for the I2S peripheral
ledneczki 6f8fc64
[I2S] Setup basic I2S driver template package
ledneczki 4162b24
[I2S] Add pin configuration for I2S DAC
ledneczki bed748a
[I2S] Add first draft of I2S master configuration
ledneczki 96db91a
[I2S] Add audio DAC driver and interrupt driven I2S
ledneczki dab81d6
[I2S] Fix audio DAC driver
ledneczki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) 2009-2012, Fabian Greif | ||
* Copyright (c) 2010, Martin Rosekeit | ||
* Copyright (c) 2012-2015, Niklas Hauser | ||
* Copyright (c) 2013, Sascha Schade | ||
* Copyright (c) 2021, Marton Ledneczki | ||
* | ||
* 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/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#ifndef MODM_INTERFACE_I2S_HPP | ||
#define MODM_INTERFACE_I2S_HPP | ||
|
||
#include <modm/architecture/interface/peripheral.hpp> | ||
|
||
namespace modm | ||
{ | ||
|
||
/// @ingroup modm_architecture_i2s | ||
struct I2s | ||
{ | ||
/// The signature of the configuration function. | ||
using ConfigurationHandler = void(*)(); | ||
}; | ||
|
||
} // namespace modm | ||
|
||
#endif // MODM_INTERFACE_I2S_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
/* | ||
* Copyright (c) 2009-2012, Fabian Greif | ||
* Copyright (c) 2010, Martin Rosekeit | ||
* Copyright (c) 2012-2017, Niklas Hauser | ||
* Copyright (c) 2013, Sascha Schade | ||
* Copyright (c) 2021, Marton Lednczki | ||
* | ||
* 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/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#ifndef MODM_INTERFACE_I2S_MASTER_HPP | ||
#define MODM_INTERFACE_I2S_MASTER_HPP | ||
|
||
#include <modm/processing/resumable.hpp> | ||
#include "i2s.hpp" | ||
|
||
namespace modm | ||
{ | ||
|
||
/** | ||
* Interface for a I2S Master | ||
* | ||
* @author Marton Ledneczki | ||
* @ingroup modm_architecture_i2s | ||
*/ | ||
class I2sMaster : public ::modm::PeripheralDriver, public I2s | ||
{ | ||
#ifdef __DOXYGEN__ | ||
public: | ||
/** | ||
* Connect GPIOs to the peripheral and configure them. | ||
* | ||
* This configures the CK (serial clock), MCK (master clock), | ||
* SD (serial data) and WS (word select) signals and connects them. | ||
* | ||
* @tparam Signals | ||
* One CK, SD and WS signal are required | ||
* and can be passed out-of-order. | ||
*/ | ||
template< class... Signals > | ||
static void | ||
connect(); | ||
|
||
/** | ||
* Initializes the hardware and sets the baudrate. | ||
* | ||
* @tparam SystemClock | ||
* the currently active system clock | ||
* @tparam baudrate | ||
* the desired baudrate in Hz | ||
* @tparam tolerance | ||
* the allowed relative tolerance for the resulting baudrate | ||
*/ | ||
template< class SystemClock, baudrate_t baudrate, percent_t tolerance=5_pct > | ||
static void | ||
initialize(); | ||
|
||
/// Sets a new data mode. | ||
static void | ||
setDataMode(DataMode mode); | ||
|
||
/// Sets a new data order. | ||
static void | ||
setDataOrder(DataOrder order); | ||
|
||
/** | ||
* Request access to the spi master within a context. | ||
* You may acquire the spi master multiple times within the same context. | ||
* | ||
* The configuration handler will only be called when aquiring the spi | ||
* master for the first time (if it is not a `nullptr`). | ||
* | ||
* @warning Aquires must be balanced with releases of the **same** context! | ||
* @warning Aquires are persistent even after calling `initialize()`! | ||
* | ||
* @return `0` if another context is using the spi master, otherwise | ||
* `>0` as the number of times this context acquired the master. | ||
*/ | ||
static uint8_t | ||
acquire(void *ctx, ConfigurationHandler handler = nullptr); | ||
|
||
/** | ||
* Release access to the spi master within a context. | ||
* | ||
* @warning Releases must be balanced with acquires of the **same** context! | ||
* @warning Releases are persistent even after calling `initialize()`! | ||
* | ||
* @return `0` if nothing can be released anymore (for any context) | ||
* `>0` as the number of times this context can still release the master. | ||
*/ | ||
static uint8_t | ||
release(void *ctx); | ||
|
||
/** | ||
* Swap a single byte and wait for completion. | ||
* | ||
* @param data | ||
* data to be sent | ||
* @return received data | ||
*/ | ||
static uint8_t | ||
transferBlocking(uint8_t data); | ||
|
||
/** | ||
* Set the data buffers and length with options and starts a transfer. | ||
* This may be hardware accelerated (DMA or Interrupt), but not guaranteed. | ||
* | ||
* @param[in] tx | ||
* pointer to transmit buffer, set to `nullptr` to send dummy bytes | ||
* @param[out] rx | ||
* pointer to receive buffer, set to `nullptr` to discard received bytes | ||
* @param length | ||
* number of bytes to be shifted out | ||
*/ | ||
static void | ||
transferBlocking(const uint8_t *tx, uint8_t *rx, std::size_t length); | ||
|
||
/** | ||
* Swap a single byte and wait for completion non-blocking!. | ||
* | ||
* You must call this inside a Protothread or Resumable | ||
* using `PT_CALL` or `RF_CALL` respectively. | ||
* @warning These methods differ from Resumables by lacking context protection! | ||
* You must ensure that only one driver is accessing this resumable function | ||
* by using `acquire(ctx)` and `release(ctx)`. | ||
* | ||
* @param data | ||
* data to be sent | ||
* @return received data | ||
*/ | ||
static modm::ResumableResult<uint8_t> | ||
transfer(uint8_t data); | ||
|
||
/** | ||
* Set the data buffers and length with options and | ||
* starts a non-blocking transfer. | ||
* This may be hardware accelerated (DMA or Interrupt), but not guaranteed. | ||
* | ||
* You must call this inside a Protothread or Resumable | ||
* using `PT_CALL` or `RF_CALL` respectively. | ||
* @warning These methods differ from Resumables by lacking context protection! | ||
* You must ensure that only one driver is accessing this resumable function | ||
* by using `acquire(ctx)` and `release(ctx)`. | ||
* | ||
* @param[in] tx | ||
* pointer to transmit buffer, set to `nullptr` to send dummy bytes | ||
* @param[out] rx | ||
* pointer to receive buffer, set to `nullptr` to discard received bytes | ||
* @param length | ||
* number of bytes to be shifted out | ||
*/ | ||
static modm::ResumableResult<void> | ||
transfer(const uint8_t *tx, uint8_t *rx, std::size_t length); | ||
#endif | ||
}; | ||
|
||
} // namespace modm | ||
|
||
#endif // MODM_INTERFACE_SPI_MASTER_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (c) 2009-2011, Fabian Greif | ||
* Copyright (c) 2010, Martin Rosekeit | ||
* Copyright (c) 2011-2017, Niklas Hauser | ||
* Copyright (c) 2012, Georgi Grinshpun | ||
* Copyright (c) 2013, Kevin Läufer | ||
* Copyright (c) 2014, Sascha Schade | ||
* Copyright (C) 2021, Marton Ledneczki | ||
* | ||
* 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/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#ifndef MODM_STM32_I2S_MASTER{{ id }}_HPP | ||
#define MODM_STM32_I2S_MASTER{{ id }}_HPP | ||
|
||
#include <modm/architecture/interface/i2s_master.hpp> | ||
#include <modm/platform/gpio/connector.hpp> | ||
#include <modm/math/algorithm/prescaler.hpp> | ||
//#include "i2s_hal_{{ id }}.hpp" TODO | ||
|
||
namespace modm | ||
{ | ||
|
||
namespace platform | ||
{ | ||
|
||
/** | ||
* Inter-IC Sound (I2C{{ id }}). | ||
* | ||
* TODO: say something about the nature of implementation | ||
* | ||
* @author Marton Ledneczki | ||
* @ingroup modm_platform_i2s modm_platform_i2s_{{id}} | ||
*/ | ||
class I2sMaster{{ id }} : public modm::I2sMaster | ||
{ | ||
public: | ||
//using Hal = I2sHal{{ id }}; TODO | ||
|
||
//using DataSize = Hal::DataSize; TODO | ||
|
||
public: | ||
template< template<Peripheral _> class... Signals > | ||
static void | ||
connect() | ||
{ | ||
using Connector = GpioConnector<Peripheral::I2s{{ id }}, Signals...>; | ||
using Ck = typename Connector::template GetSignal<Gpio::Signal::Ck>; | ||
using Mck = typename Connector::template GetSignal<Gpio::Signal::Mck>; | ||
using Sd = typename Connector::template GetSignal<Gpio::Signal::Sd>; | ||
using Ws = typename Connector::template GetSignal<Gpio::Signal::Ws>; | ||
|
||
// Connector::disconnect(); | ||
Ck::setOutput(Gpio::OutputType::PushPull); | ||
Mck::setOutput(Gpio::OutputType::PushPull); | ||
Sd::setOutput(Gpio::OutputType::PushPull); | ||
Ws::setOutput(Gpio::OutputType::PushPull); | ||
Connector::connect(); | ||
} | ||
|
||
|
||
// end documentation inherited | ||
}; | ||
|
||
} // namespace platform | ||
|
||
} // namespace modm | ||
|
||
#endif // MODM_STM32_I2S_MASTER{{ id }}_HPP |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.