Browse Source

update

3lead_uart_test_ok_version
zhaohe 1 year ago
parent
commit
6876f7ca11
  1. 6
      .vscode/settings.json
  2. 12
      README.md
  3. 4
      app/main.c
  4. 88
      app/src/board.c
  5. 22
      app/src/board.h

6
.vscode/settings.json

@ -32,6 +32,10 @@
"version.h": "c",
"zble_service.h": "c",
"pca10112.h": "c",
"pca10100.h": "c"
"pca10100.h": "c",
"board.h": "c",
"stdio.h": "c",
"nrf_log_ctrl.h": "c",
"nrf_log_default_backends.h": "c"
}
}

12
README.md

@ -15,14 +15,10 @@ https://iflytop1.feishu.cn/wiki/Fp0fwciUEibtm4kaUeXcraOCneg
#define BSP_LED_2 15
#define BSP_LED_3 16
#define BUTTONS_NUMBER 4
#define BUTTON_1 11
#define BUTTON_2 12
#define BUTTON_3 24
#define BUTTON_4 25
#define BUTTON_PULL NRF_GPIO_PIN_PULLUP
#define BUTTON_1 11 // 上拉低电平有效
#define BUTTON_2 12 // 上拉低电平有效
#define BUTTON_3 24 // 上拉低电平有效
#define BUTTON_4 25 // 上拉低电平有效
sdk\components\boards\pca10100.h

4
app/main.c

@ -15,6 +15,8 @@ int main(void) {
NRF_LOG_INFO("Version :%d", VERSION);
NRF_LOG_INFO("Manufacturer :%s", MANUFACTURER_NAME);
// zble_service_init(&cfg);
uint8_t io_index[] = {11, 12, 24};
zbsp_gpio_state_monitor(1000, (uint8_t*)io_index, ZARRAY_SIZE(io_index));
zsys_loop();
}

88
app/src/board.c

@ -2,24 +2,14 @@
#include "app_timer.h"
#include "nrf_gpio.h"
#include "sys.h"
/*******************************************************************************
* DEBUG_LIGHT *
*******************************************************************************/
APP_TIMER_DEF(m_debug_light_tmr_cb);
APP_TIMER_DEF(m_debug_light_tmr);
static int32_t m_debug_light_io_index;
static void debug_light_tmr_cb_handler(void* p_context) {
static bool inited = false;
if (!inited) {
inited = true;
nrf_gpio_cfg(m_debug_light_io_index, //
NRF_GPIO_PIN_DIR_OUTPUT, //
NRF_GPIO_PIN_INPUT_DISCONNECT, //
NRF_GPIO_PIN_NOPULL, //
NRF_GPIO_PIN_S0S1, //
NRF_GPIO_PIN_NOSENSE);
}
static bool state = false;
if (state) {
nrf_gpio_pin_set(m_debug_light_io_index);
@ -31,11 +21,81 @@ static void debug_light_tmr_cb_handler(void* p_context) {
void debug_light_init(int io_index) {
m_debug_light_io_index = io_index;
nrf_gpio_cfg(m_debug_light_io_index, //
NRF_GPIO_PIN_DIR_OUTPUT, //
NRF_GPIO_PIN_INPUT_DISCONNECT, //
NRF_GPIO_PIN_NOPULL, //
NRF_GPIO_PIN_S0S1, //
NRF_GPIO_PIN_NOSENSE);
ret_code_t err_code;
err_code = app_timer_create(&m_debug_light_tmr_cb, APP_TIMER_MODE_REPEATED, debug_light_tmr_cb_handler);
err_code = app_timer_create(&m_debug_light_tmr, APP_TIMER_MODE_REPEATED, debug_light_tmr_cb_handler);
APP_ERROR_CHECK(err_code);
app_timer_start(m_debug_light_tmr_cb, APP_TIMER_TICKS(100), NULL);
app_timer_start(m_debug_light_tmr, APP_TIMER_TICKS(100), NULL);
}
/*******************************************************************************
* zbsp_enter_sleep *
*******************************************************************************/
APP_TIMER_DEF(enter_sleep_mode_tmr);
static int32_t m_wakeup_io_index;
static bool m_wakeup_io_mirror;
static void enter_sleep_tmr_cb(void* p_context) {
ZLOGI("enter sleep mode, wakeup io index: %d", m_wakeup_io_index);
if (m_wakeup_io_mirror) {
nrf_gpio_cfg_sense_input(m_wakeup_io_index, BUTTON_PULL, NRF_GPIO_PIN_SENSE_LOW);
} else {
nrf_gpio_cfg_sense_input(m_wakeup_io_index, BUTTON_PULL, NRF_GPIO_PIN_SENSE_HIGH);
}
// Go to system-off mode (this function will not return; wakeup will cause a reset).
APP_ERROR_CHECK(sd_power_system_off());
}
void zbsp_enter_sleep(int32_t after_ms, int32_t wakeup_io_index, bool mirror) {
m_wakeup_io_index = wakeup_io_index;
m_wakeup_io_mirror = mirror;
ret_code_t err_code;
APP_ERROR_CHECK(app_timer_create(&enter_sleep_mode_tmr, APP_TIMER_MODE_SINGLE_SHOT, enter_sleep_tmr_cb));
APP_ERROR_CHECK(app_timer_start(enter_sleep_mode_tmr, APP_TIMER_TICKS(after_ms), NULL));
ZLOGI("enter sleep mode after %d ms", after_ms);
}
/*******************************************************************************
* gpio_io_state_monitor *
*******************************************************************************/
APP_TIMER_DEF(gpio_io_state_monitor_tmr);
static uint8_t* m_io_index;
static int32_t m_nio;
static void gpio_io_state_monitor_tmr_cb(void* p_context) {
// ioindex:state ioindex:state ioindex:state
if (m_nio == 1) {
ZLOGI("iostate %d:%d ", m_io_index[0], nrf_gpio_pin_read(m_io_index[0]));
} else if (m_nio == 2) {
ZLOGI("iostate %d:%d %d:%d", m_io_index[0], nrf_gpio_pin_read(m_io_index[0]), //
m_io_index[1], nrf_gpio_pin_read(m_io_index[1]));
} else if (m_nio >= 3) {
ZLOGI("iostate %d:%d %d:%d %d:%d", m_io_index[0], nrf_gpio_pin_read(m_io_index[0]), //
m_io_index[1], nrf_gpio_pin_read(m_io_index[1]), //
m_io_index[2], nrf_gpio_pin_read(m_io_index[2]));
}
}
void zbsp_gpio_state_monitor_without_initio(int dumpstate_period, uint8_t* io_index, int32_t nio) {
m_io_index = io_index;
m_nio = nio;
APP_ERROR_CHECK(app_timer_create(&gpio_io_state_monitor_tmr, APP_TIMER_MODE_REPEATED, gpio_io_state_monitor_tmr_cb));
APP_ERROR_CHECK(app_timer_start(gpio_io_state_monitor_tmr, APP_TIMER_TICKS(dumpstate_period), NULL));
}
void zbsp_gpio_state_monitor(int dumpstate_period, uint8_t* io_index, int32_t nio) {
m_io_index = io_index;
m_nio = nio;
for (int i = 0; i < nio; i++) {
nrf_gpio_cfg_input(io_index[i], NRF_GPIO_PIN_PULLUP);
}
zbsp_gpio_state_monitor_without_initio(dumpstate_period, io_index, nio);
}
void board_init() {}

22
app/src/board.h

@ -1,4 +1,7 @@
#pragma once
#include <stdio.h>
#include "sys.h"
/*******************************************************************************
* DEBUG_LIGHT *
@ -6,6 +9,21 @@
void debug_light_init(int io_index);
/*******************************************************************************
* BOARD *
* zbsp_enter_sleep *
*******************************************************************************/
/**
* @brief
*
* @param after_ms
* @param wakeup_io_index
*/
void zbsp_enter_sleep(int32_t after_ms, int32_t wakeup_io_index, bool mirror);
/*******************************************************************************
* gpio_io_state_monitor *
*******************************************************************************/
void board_init();
void zbsp_gpio_state_monitor(int dumpstate_period, uint8_t* io_index, int32_t nio);
void zbsp_gpio_state_monitor_without_initio(int dumpstate_period, uint8_t* io_index, int32_t nio);
void board_init();
Loading…
Cancel
Save