|
| 1 | +/* |
| 2 | + * Copyright (c) 2013, Kevin Läufer |
| 3 | + * Copyright (c) 2013-2017, Niklas Hauser |
| 4 | + * Copyright (c) 2014, Daniel Krebs |
| 5 | + * Copyright (c) 2020, Mike Wolfram, |
| 6 | + * Copyright (c) 2021, Marton Ledneczki |
| 7 | + * |
| 8 | + * This file is part of the modm project. |
| 9 | + * |
| 10 | + * This Source Code Form is subject to the terms of the Mozilla Public |
| 11 | + * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 12 | + * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 13 | + */ |
| 14 | +// ---------------------------------------------------------------------------- |
| 15 | + |
| 16 | +#ifndef MODM_STM32_I2S_BASE_HPP |
| 17 | +#define MODM_STM32_I2S_BASE_HPP |
| 18 | + |
| 19 | +#include <stdint.h> |
| 20 | +#include "../device.hpp" |
| 21 | +#include <modm/architecture/interface/register.hpp> |
| 22 | + |
| 23 | +namespace modm |
| 24 | +{ |
| 25 | + |
| 26 | +namespace platform |
| 27 | +{ |
| 28 | + |
| 29 | +/** |
| 30 | + * Base class for the I2S classes |
| 31 | + * |
| 32 | + * Provides some common enum that do not depend on the specific I2S. |
| 33 | + * |
| 34 | + * @author Marton Ledneczki |
| 35 | + * @ingroup modm_platform_i2s |
| 36 | + */ |
| 37 | +class I2sBase |
| 38 | +{ |
| 39 | +public: |
| 40 | + enum class |
| 41 | + Interrupt : uint32_t |
| 42 | + { |
| 43 | + RxBufferNotEmpty = SPI_CR2_RXNEIE, |
| 44 | + TxBufferEmpty = SPI_CR2_TXEIE, |
| 45 | + Error = SPI_CR2_ERRIE, |
| 46 | + RxDmaEnable = SPI_CR2_RXDMAEN, |
| 47 | + TxDmaEnable = SPI_CR2_TXDMAEN, |
| 48 | + }; |
| 49 | + MODM_FLAGS32(Interrupt); |
| 50 | + |
| 51 | + enum class |
| 52 | + InterruptFlag : uint32_t |
| 53 | + { |
| 54 | + TxBufferEmpty = SPI_SR_TXE, |
| 55 | + RxBufferNotEmpty = SPI_SR_RXNE, |
| 56 | + CrcError = SPI_SR_CRCERR, |
| 57 | + ModeFaultError = SPI_SR_MODF, |
| 58 | + OverrunError = SPI_SR_OVR, |
| 59 | + Busy = SPI_SR_BSY, |
| 60 | + }; |
| 61 | + MODM_FLAGS32(InterruptFlag); |
| 62 | + |
| 63 | + enum class |
| 64 | + MasterSelection : uint32_t |
| 65 | + { |
| 66 | + Slave = 0b0, ///< Configure I2S as Slave |
| 67 | + Master = SPI_I2SCFGR_I2SCFG_1, ///< Configure I2S as Master |
| 68 | + All = Master, |
| 69 | + }; |
| 70 | + |
| 71 | + enum class |
| 72 | + DirectionSelection : uint32_t |
| 73 | + { |
| 74 | + Transmitter = 0b0, ///< Configure I2S as Transmitter |
| 75 | + Receiver = SPI_I2SCFGR_I2SCFG_0, ///< COnfigure I2S as Receiver |
| 76 | + All = Receiver, |
| 77 | + }; |
| 78 | + |
| 79 | + enum class |
| 80 | + BitDepth : uint32_t |
| 81 | + { |
| 82 | + Sixteen = 0b0, |
| 83 | + Twentyfour = SPI_I2SCFGR_DATLEN_0, |
| 84 | + Thirtytwo = SPI_I2SCFGR_DATLEN_1, |
| 85 | + All = Thirtytwo, |
| 86 | + }; |
| 87 | + |
| 88 | + enum class |
| 89 | + MasterClockOutput : uint32_t |
| 90 | + { |
| 91 | + Disabled = 0b0, |
| 92 | + Enabled = SPI_I2SPR_MCKOE, |
| 93 | + All = Enabled, |
| 94 | + }; |
| 95 | + |
| 96 | + enum class |
| 97 | + OddFactor : uint32_t |
| 98 | + { |
| 99 | + Disabled = 0, |
| 100 | + Enabled = SPI_I2SPR_ODD, |
| 101 | + All = Enabled, |
| 102 | + }; |
| 103 | +}; |
| 104 | + |
| 105 | +} // namespace platform |
| 106 | + |
| 107 | +} // namespace modm |
| 108 | + |
| 109 | +#endif // MODM_STM32_I2S_BASE_HPP |
0 commit comments