Nordic nRF52832-PCA100A0-GPIO设置

1、在#include "nrf_gpio.h"中定义有
// LEDs definitions for PCA10040
#define LEDS_NUMBER 4

#define LED_START 17
#define LED_1 17
#define LED_2 18
#define LED_3 19
#define LED_4 20
#define LED_STOP 20
#define LEDS_LIST { LED_1, LED_2, LED_3, LED_4 }
#define LEDS_ACTIVE_STATE 0

#define BUTTON_START 13
#define BUTTON_1 13
#define BUTTON_2 14
#define BUTTON_3 15
#define BUTTON_4 16
#define BUTTON_STOP 16
#define BUTTON_PULL NRF_GPIO_PIN_PULLUP
#define BUTTONS_LIST { BUTTON_1, BUTTON_2, BUTTON_3, BUTTON_4 }
#define BUTTONS_ACTIVE_STATE 0

2、在"boards.c"中将利用数组进行之间传递
#if LEDS_NUMBER > 0
static const uint8_t m_board_led_list[LEDS_NUMBER] = LEDS_LIST;
#endif

#if BUTTONS_NUMBER > 0
static const uint8_t m_board_btn_list[BUTTONS_NUMBER] = BUTTONS_LIST;
#endif

3、在led_init()函数中进行初始化:
1)nrf_gpio_cfg_output(m_board_led_list[i]);
__STATIC_INLINE void nrf_gpio_cfg_output(uint32_t pin_number)
{
nrf_gpio_cfg(
pin_number,//pin角标志
NRF_GPIO_PIN_DIR_OUTPUT,//方向为输出
NRF_GPIO_PIN_INPUT_DISCONNECT,//是否管理缓存
NRF_GPIO_PIN_NOPULL,//无上拉内阻
NRF_GPIO_PIN_S0S1,//输出驱动模式
NRF_GPIO_PIN_NOSENSE);//作为输入时默认电平
}
2)bsp_board_led_off(uint32_t led_idx)
nrf_gpio_pin_write(m_board_led_list[led_idx], LEDS_ACTIVE_STATE ? 0 : 1);
__STATIC_INLINE void nrf_gpio_pin_write(uint32_t pin_number, uint32_t value)
{
if (value == 0)
{
nrf_gpio_pin_clear(pin_number);
//nrf_gpio_port_out_clear(reg, 1UL << pin_number);
//->p_reg->OUTCLR = clr_mask;
}
else
{
nrf_gpio_pin_set(pin_number);
//nrf_gpio_port_out_set(reg, 1UL << pin_number);
//p_reg->OUTSET = set_mask;
}
}

4、button_lnit();初始化按键
nrf_gpio_cfg_input(m_board_btn_list[i], BUTTON_PULL);

__STATIC_INLINE void nrf_gpio_cfg_input(uint32_t pin_number, nrf_gpio_pin_pull_t pull_config)
{
nrf_gpio_cfg(
pin_number,
NRF_GPIO_PIN_DIR_INPUT,
NRF_GPIO_PIN_INPUT_CONNECT,
pull_config,
NRF_GPIO_PIN_S0S1,
NRF_GPIO_PIN_NOSENSE);
}
5、获取button状态
bool bsp_board_button_state_get(uint32_t button_idx)
{
ASSERT(button_idx < BUTTONS_NUMBER);
bool pin_set = nrf_gpio_pin_read(m_board_btn_list[button_idx]) ? true : false;
return (pin_set == (BUTTONS_ACTIVE_STATE ? true : false));
}
//__STATIC_INLINE uint32_t nrf_gpio_pin_read(uint32_t pin_number)
{
NRF_GPIO_Type * reg = nrf_gpio_pin_port_decode(&pin_number);
return ((nrf_gpio_port_in_read(reg) >> pin_number) & 1UL);
}

你可能感兴趣的:(nordic蓝牙学习)