Merge pull request #3706 from guohp1128/guohp

提交nrf5x的gpio驱动
This commit is contained in:
Bernard Xiong authored and GitHub committed 2020-07-06 22:21:04 +08:00
commit 02ac2b7a56
6 files changed
+444 -12

No files matched your search

File diff suppressed because it is too large. Load diff
+53
View File
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2006-2018, 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 <nrf52840.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__ */
+8 -10
View File
@@ -25,25 +25,23 @@
#include <shell.h>
#endif
#include <nrf_gpio.h>
#include <drv_gpio.h>
#define DK_BOARD_LED_1 13
int main(void)
{
int count = 1;
nrf_gpio_cfg_output(DK_BOARD_LED_1);
int count = 1;
rt_pin_mode(DK_BOARD_LED_1, PIN_MODE_OUTPUT);
while (count++)
{
nrf_gpio_pin_set(DK_BOARD_LED_1);
{
rt_pin_write(DK_BOARD_LED_1, PIN_HIGH);
rt_thread_mdelay(500);
nrf_gpio_pin_clear(DK_BOARD_LED_1);
rt_thread_mdelay(500);
rt_pin_write(DK_BOARD_LED_1, PIN_LOW);
rt_thread_mdelay(500);
}
return RT_EOK;
}
/*@}*/
+6
View File
@@ -3,6 +3,7 @@
#include <nrfx_systick.h>
#include "board.h"
#include "drv_gpio.h"
#include "drv_uart.h"
void SysTick_Configuration(void)
@@ -47,6 +48,11 @@ void rt_hw_board_init(void)
rt_system_heap_init((void *)HEAP_BEGIN, (void *)HEAP_END);
#endif
/* Pin driver initialization is open by default */
#ifdef RT_USING_PIN
rt_hw_pin_init();
#endif
#ifdef RT_USING_SERIAL
rt_hw_uart_init();
#endif
+1 -1
View File
@@ -2,7 +2,7 @@
#define _BOARD_H_
#include <rtthread.h>
#include <rthw.h>
#include "nrf.h"
#define MCU_FLASH_SIZE MCU_FLASH_SIZE_KB*1024
+1 -1
View File
@@ -1898,7 +1898,7 @@
// <e> NRFX_GPIOTE_ENABLED - nrfx_gpiote - GPIOTE peripheral driver
//==========================================================
#ifndef NRFX_GPIOTE_ENABLED
#define NRFX_GPIOTE_ENABLED 0
#define NRFX_GPIOTE_ENABLED 1
#endif
// <o> NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS - Number of lower power input pins
#ifndef NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS