~aleteoryx/muditaos

ref: 317baa04e949a32ef1e72b2dd2b61c1e7a97ca25 muditaos/module-bsp/board/rt1051/bellpx/hal/key_input/KeyInput.cpp -rw-r--r-- 1.6 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
52
53
54
55
56
57
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "KeyInput.hpp"
#include <bsp/KeyInputCommon.hpp>

#include <hal/GenericFactory.hpp>
#include <bsp/switches/switches.hpp>
#include <bsp/rotary_encoder/rotary_encoder.hpp>
#include <board/BoardDefinitions.hpp>

namespace hal::key_input
{
    std::shared_ptr<AbstractKeyInput> AbstractKeyInput::Factory::create()
    {
        return hal::impl::factory<KeyInput, AbstractKeyInput>();
    }

    void KeyInput::init(xQueueHandle queueHandle)
    {
        bsp::bell_switches::init(queueHandle);
        bsp::rotary_encoder::init(queueHandle);
    }

    void KeyInput::deinit()
    {
        bsp::bell_switches::deinit();
        bsp::rotary_encoder::deinit();
    }

    std::vector<bsp::KeyEvent> KeyInput::getKeyEvents(KeyNotificationSource notification)
    {
        auto keyNotification = static_cast<bsp::NotificationSource>(notification);
        if (keyNotification == bsp::NotificationSource::rotaryEncoder) {
            return bsp::rotary_encoder::getKeyEvents();
        }
        else {
            return bsp::bell_switches::getKeyEvents(keyNotification);
        }
    }

    BaseType_t generalIRQHandler(std::uint32_t irqMask)
    {
        constexpr std::uint32_t encoderMask{99};
        if (irqMask == encoderMask) {
            return bsp::rotary_encoder::IRQHandler(irqMask);
        }
        else {
            return bsp::bell_switches::IRQHandler(irqMask);
        }
    }

    BaseType_t wakeupIRQHandler()
    {
        return bsp::bell_switches::wakeupIRQHandler();
    }
} // namespace hal::key_input