Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
108 changes: 6 additions & 102 deletions src/modm/architecture/interface/i2s_master.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,123 +39,27 @@ class I2sMaster : public ::modm::PeripheralDriver, public I2s
* SD (serial data) and WS (word select) signals and connects them.
*
* @tparam Signals
* One CK, SD and WS signal are required
* One CK, SD, WS, MCK signal are required
* and can be passed out-of-order.
*/
template< class... Signals >
static void
connect();

/**
* Initializes the hardware and sets the baudrate.
* Initializes the hardware and sets the samplerate.
*
* @tparam SystemClock
* the currently active system clock
* @tparam baudrate
* the desired baudrate in Hz
* @tparam samplerate
* the desired sample rate in Hz
* @tparam tolerance
* the allowed relative tolerance for the resulting baudrate
* the allowed relative tolerance for the resulting samplerate
*/
template< class SystemClock, baudrate_t baudrate, percent_t tolerance=5_pct >
template< class SystemClock, frequency_t samplerate, percent_t tolerance=pct(0.019) >
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
};

Expand Down
5 changes: 5 additions & 0 deletions src/modm/board/disco_f407vg/board.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ initializeCs43()

cs43::I2cMaster::connect<cs43::Scl::Scl, cs43::Sda::Sda>();
cs43::I2cMaster::initialize<SystemClock, 100_kHz>();

cs43::Reset::setOutput(modm::Gpio::Low);
modm::delay_ms(2);
cs43::Reset::setOutput(modm::Gpio::High);

}

/// not supported yet, due to missing I2S driver
Expand Down
Loading