【蓝牙5.2 PB-03F教程】GPIO中断

[复制链接]
查看514 | 回复7 | 7 天前 | 显示全部楼层 |阅读模式
本文简单介绍PB-03F模组GPIO中断二次开发;
一、函数介绍

下图是引脚对应的宏定义:
1.png
1. hal_gpioin_register

2.png
2. hal_gpio_init

3.png
3. hal_gpio_pin_init

4.png
4. hal_gpio_fast_write

5.png
5. hal_gpio_read

6.png
6. hal_gpioin_enable

7.png
7. hal_gpioin_disable

8.png
二、工具

1. 硬件
PB-03F开发板
USB-安卓数据线
2. 软件
二次开发环境keil(安装链接
SDK下载链接
三、GPIO demo示例

1. main.c
  1. #include "bus_dev.h"
  2. #include "gpio.h"
  3. #include "clock.h"
  4. #include "timer.h"
  5. #include "jump_function.h"
  6. #include "pwrmgr.h"
  7. #include "mcu.h"
  8. #include "gpio.h"
  9. #include "log.h"
  10. #include "rf_phy_driver.h"
  11. #include "flash.h"
  12. #include "version.h"

  13. //宏定义ms级延时宏
  14. #define STANDBY_WAIT_MS(a)  WaitRTCCount((a)<<5)

  15. //定义一个4字节对齐的无符号8位整数
  16. #define     LARGE_HEAP_SIZE  (4*1024)
  17. ALIGN4_U8       g_largeHeap[LARGE_HEAP_SIZE];

  18. volatile uint8 g_clk32K_config;
  19. volatile sysclk_t g_spif_clk_config;

  20. void posedge_int_wakeup_cb(GPIO_Pin_e pin,IO_Wakeup_Pol_e type)
  21. {
  22.         if(type == POSEDGE)
  23.         {
  24.                 LOG("int or wakeup(pos):gpio:%d type:%d\n",pin,type);
  25.                 hal_gpio_fast_write(P7, 1);
  26.         }
  27.         else
  28.         {
  29.                 LOG("error\n");
  30.         }
  31. }

  32. void negedge_int_wakeup_cb(GPIO_Pin_e pin,IO_Wakeup_Pol_e type)
  33. {
  34.         if(type == NEGEDGE)
  35.         {
  36.                 LOG("int or wakeup(neg):gpio:%d type:%d\n",pin,type);
  37.                 hal_gpio_fast_write(P7, 0);
  38.         }
  39.         else
  40.         {
  41.                 LOG("error\n");
  42.         }
  43. }

  44. static void hal_init(void)
  45. {
  46.         //系统时钟初始化,使用串口需要先初始化系统时钟
  47.         clk_init(g_system_clk); //system init
  48.         
  49.         //LOG串口初始化
  50.         LOG_INIT();
  51.         
  52.         //GPIO初始化
  53.         hal_gpio_init();
  54. }

  55. static void simple_code(void)
  56. {
  57.         gpio_pin_e pin0 = P0;
  58.         
  59.         gpio_pin_e pin7 = P7;
  60.         //设置P7引脚为输出模式(红灯)
  61.         hal_gpio_pin_init(pin7, GPIO_OUTPUT);
  62.         
  63.         //使P7引脚输出高电平
  64.         hal_gpio_fast_write(P7, 1);
  65.         hal_init();
  66.         //设置GPIO中断,并设置回调函数
  67.         hal_gpioin_register(pin0,posedge_int_wakeup_cb,negedge_int_wakeup_cb);
  68. }

  69. int main(void)
  70. {
  71.         simple_code();
  72.         while(1)
  73.         {
  74.                
  75.         }
  76. }        
复制代码
2. 项目框架
9.png
3. 注意
为避免不必要的麻烦,建议在SDK框架demo示例同目录下复制demo粘贴项目进行二次开发。
四、烧录
【蓝牙5.2 PB-03F教程】烧录流程

在上面的链接基础下,烧录文件修改为如下图所示的编译出来的文件选择:
10.png

用心做好保姆工作
回复

使用道具 举报

lazy | 7 天前 | 显示全部楼层
园长现在教程一发就是全套
回复 支持 反对

使用道具 举报

园长厉害
选择去发光,而不是被照亮
回复

使用道具 举报

iiv | 7 天前 | 显示全部楼层

园长不厉害谁厉害,玛丽哥吗
回复 支持 反对

使用道具 举报

lovzx | 6 天前 | 显示全部楼层
学习
回复

使用道具 举报

园长厉害
回复

使用道具 举报

iiv 发表于 2024-10-18 20:10
园长不厉害谁厉害,玛丽哥吗

七哥也厉害
选择去发光,而不是被照亮
回复 支持 反对

使用道具 举报

iiv | 6 天前 | 显示全部楼层

在我心里,园长是最厉害的!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则