summaryrefslogtreecommitdiff
path: root/bsp/nrf5x/libraries/drivers/drv_gpio.h
blob: 0985c079c8904365be1169eff7e75c3a0aacb120 (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
/*
 * Copyright (c) 2006-2022, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author            Notes
 * 2020-06-16     guohp1128         first version
 */

#ifndef __DRV_GPIO_H__
#define __DRV_GPIO_H__

#include <board.h>
#include <rtdevice.h>
#include <hal/nrf_gpio.h>
#include <drivers/include/nrfx_gpiote.h>

#define __NRF5X_PORT(port)  NRF_P##port##_BASE

#define GET_PIN(PORTx,PIN) (rt_base_t)((32 * ( ((rt_base_t)__NRF5X_PORT(PORTx) - (rt_base_t)NRF_P0_BASE)/(0x0300UL) )) + PIN)

#define __NRF5X_PIN(index, gpio, gpio_index)                                \
    {                                                                       \
        index, NRF_P##gpio, gpio_index                                      \
    }

#define __NRF5X_PIN_RESERVE                                                 \
    {                                                                       \
        -1, 0, 0                                                            \
    }

/* nrf5x GPIO driver */
struct pin_index
{
    int index;
    NRF_GPIO_Type *gpio;//NRF_P0 or NRF_P1
    uint32_t pin;
};

static void nrf5x_pin_write(rt_device_t dev, rt_base_t pin, rt_base_t value);
static int nrf5x_pin_read(rt_device_t dev, rt_base_t pin);
static void nrf5x_pin_mode(rt_device_t dev, rt_base_t pin, rt_base_t mode);
static rt_err_t nrf5x_pin_attach_irq(struct rt_device *device, rt_int32_t pin,
                                     rt_uint32_t mode, void (*hdr)(void *args), void *args);
static rt_err_t nrf5x_pin_dettach_irq(struct rt_device *device, rt_int32_t pin);
static rt_err_t nrf5x_pin_irq_enable(struct rt_device *device, rt_base_t pin,
                                     rt_uint32_t enabled);
int rt_hw_pin_init(void);

#endif /* __DRV_GPIO_H__ */