~aleteoryx/muditaos

ref: 317baa04e949a32ef1e72b2dd2b61c1e7a97ca25 muditaos/module-bsp/board/rt1051/drivers/RT1051DriverLPSPI.cpp -rw-r--r-- 1.4 KiB
317baa04 — Wojtek Rzepecki [BH-872] Fix encoder hadnling 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "RT1051DriverLPSPI.hpp"
#include "critical.hpp"
#include "board/rt1051/bsp/lpm/ClockState.hpp"

namespace drivers
{

    RT1051DriverLPSPI::RT1051DriverLPSPI(std::string name, LPSPIInstances inst) : DriverLPSPI(std::move(name), inst)
    {
        switch (instance) {
        case LPSPIInstances::LPSPI_1:
            lpspiClock = kCLOCK_Lpspi1;
            break;
        case LPSPIInstances::LPSPI_2:
            lpspiClock = kCLOCK_Lpspi2;
            break;
        case LPSPIInstances::LPSPI_3:
            lpspiClock = kCLOCK_Lpspi3;
            break;
        case LPSPIInstances::LPSPI_4:
            lpspiClock = kCLOCK_Lpspi4;
            break;
        }
    }

    void RT1051DriverLPSPI::Enable()
    {
        cpp_freertos::CriticalSection::Enter();
        if (!pll2Driver) {
            pll2Driver = std::make_shared<RT1051DriverPLL2>();
        }
        if (!bsp::IsClockEnabled(lpspiClock)) {
            CLOCK_EnableClock(lpspiClock);
        }
        cpp_freertos::CriticalSection::Exit();
    }

    void RT1051DriverLPSPI::Disable()
    {
        cpp_freertos::CriticalSection::Enter();
        if (bsp::IsClockEnabled(lpspiClock)) {
            CLOCK_DisableClock(lpspiClock);
        }
        pll2Driver.reset();
        cpp_freertos::CriticalSection::Exit();
    }

} // namespace drivers