~aleteoryx/muditaos

ref: 6b45d3b71dc1e09a16a3bc66cc54ced1c9de8d43 muditaos/module-bsp/board/rt1051/bellpx/hal/key_input/KeyInput.cpp -rw-r--r-- 1.6 KiB
6b45d3b7 — Maciej Gibowicz [BH-2097] Adding and deleting a single custom quote 1 year, 13 days 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-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/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 EncoderIRQHandler()
    {
        return bsp::rotary_encoder::IRQHandler();
    }

    BaseType_t GPIO2SwitchesIRQHandler(std::uint32_t irqMask)
    {
        return bsp::bell_switches::GPIO2SwitchesIRQHandler(irqMask);
    }

    BaseType_t GPIO5SwitchesIRQHandler(std::uint32_t irqMask)
    {
        return bsp::bell_switches::GPIO5SwitchesIRQHandler(irqMask);
    }

} // namespace hal::key_input