~aleteoryx/muditaos

ref: 1c668fa7a0ab9680916080be02c743dd7c0363f9 muditaos/module-audio/board/rt1051/puretx/RT1051CellularAudio.hpp -rw-r--r-- 2.6 KiB
1c668fa7 — Pawel Olejniczak [EGD-8034] Switch elements order on date and time screen 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#ifndef PUREPHONE_RT1051CELLULARAUDIO_HPP
#define PUREPHONE_RT1051CELLULARAUDIO_HPP

#include "SAIAudioDevice.hpp"
#include "fsl_sai_edma.h"

#include "FreeRTOS.h"
#include "task.h"
#include "macros.h"

#include "drivers/pll/DriverPLL.hpp"
#include "drivers/dmamux/DriverDMAMux.hpp"
#include "drivers/dma/DriverDMA.hpp"

#include <vector>

namespace audio
{

    void txCellularCallback(I2S_Type *base, sai_edma_handle_t *handle, status_t status, void *userData);
    void rxCellularCallback(I2S_Type *base, sai_edma_handle_t *handle, status_t status, void *userData);

    class RT1051CellularAudio : public SAIAudioDevice
    {

      public:
        friend void txCellularCallback(I2S_Type *base, sai_edma_handle_t *handle, status_t status, void *userData);
        friend void rxCellularCallback(I2S_Type *base, sai_edma_handle_t *handle, status_t status, void *userData);

        RT1051CellularAudio();
        virtual ~RT1051CellularAudio();

        AudioDevice::RetCode Start() override final;
        AudioDevice::RetCode Stop() override final;

        AudioDevice::RetCode setOutputVolume(float vol) override final;
        AudioDevice::RetCode setInputGain(float gain) override final;
        auto getSupportedFormats() -> std::vector<AudioFormat> override final;
        auto getTraits() const -> Traits override final;
        auto getSourceFormat() -> AudioFormat override final;

      private:
        static constexpr auto supportedSampleRate = 16000U;
        static constexpr auto supportedBitWidth   = 16U;
        static constexpr auto supportedChannels   = 1U;

        enum class State
        {
            Running,
            Stopped
        };

        State state                = State::Stopped;
        uint32_t mclkSourceClockHz = 0;
        sai_config_t config;

        // M.P: It is important to destroy these drivers in specific order
        std::shared_ptr<drivers::DriverPLL> pll;
        std::shared_ptr<drivers::DriverDMAMux> dmamux;
        std::shared_ptr<drivers::DriverDMA> dma;
        std::unique_ptr<drivers::DriverDMAHandle> rxDMAHandle;
        std::unique_ptr<drivers::DriverDMAHandle> txDMAHandle;

        static AT_NONCACHEABLE_SECTION_INIT(sai_edma_handle_t txHandle);
        static AT_NONCACHEABLE_SECTION_INIT(sai_edma_handle_t rxHandle);

        void Init();
        void Deinit();
        void OutStart();
        void InStart();
        void OutStop();
        void InStop();
    };
} // namespace audio

#endif // PUREPHONE_RT1051CELLULARAUDIO_HPP