summaryrefslogtreecommitdiff
path: root/FreeRTOS/Demo/RISC-V_RV32_SiFive_HiFive1_GCC/freedom-metal/src/drivers/sifive_gpio-buttons.c
blob: fbb6c92a7071e5bd43ace2eeb38201955216cad9 (plain)
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
/* Copyright 2018 SiFive, Inc */
/* SPDX-License-Identifier: Apache-2.0 */

#include <metal/machine/platform.h>

#ifdef METAL_SIFIVE_GPIO_BUTTONS

#include <string.h>
#include <metal/drivers/riscv_cpu.h>
#include <metal/drivers/sifive_gpio-buttons.h>
#include <metal/machine.h>

int  __metal_driver_button_exist (struct metal_button *button, char *label)
{
    if (strcmp(__metal_driver_sifive_gpio_button_label(button), label) == 0) {
        return 1;
    }
    return 0;
}

struct metal_interrupt *
__metal_driver_button_interrupt_controller(struct metal_button *button)
{
    return __metal_driver_sifive_gpio_button_interrupt_controller(button);
}

int __metal_driver_button_get_interrupt_id(struct metal_button *button)
{
    int irq, max_irq;
    struct metal_interrupt *irc;

    irq = __metal_driver_sifive_gpio_button_interrupt_line(button);
    irc =  __metal_driver_sifive_gpio_button_interrupt_controller(button);

    if (irc != NULL) {
        max_irq = _metal_interrupt_command_request(irc,
                                                   METAL_MAX_INTERRUPT_GET,
                                                   NULL);

        if (irq < max_irq) {
            return _metal_interrupt_command_request(irc,
                                                 METAL_INDEX_INTERRUPT_GET,
                                                 (void *)&irq);
        }
    }
    return METAL_INTERRUPT_ID_LCMX;
}

__METAL_DEFINE_VTABLE(__metal_driver_vtable_sifive_button) = {
    .button_vtable.button_exist   = __metal_driver_button_exist,
    .button_vtable.interrupt_controller = __metal_driver_button_interrupt_controller,
    .button_vtable.get_interrupt_id = __metal_driver_button_get_interrupt_id,
};

#endif