【板子开箱】小安派Ai-M61-32S 开箱点灯

[复制链接]
查看372 | 回复0 | 2023-11-22 10:00:40 | 显示全部楼层 |阅读模式
本帖最后由 leeyangy 于 2023-11-22 14:39 编辑

简单了拍几张

                               
登录/注册后可看大图



点灯过程 -- 先上图

                               
登录/注册后可看大图



                               
登录/注册后可看大图



                               
登录/注册后可看大图



1. 编译PWM循环呼吸灯
代码过程参考自本论坛:参考教程
2. 环境搭建(参考论坛文档)3. 工程文件创建
# 在 aithinker_Ai-M6X_SDK/examples 新建一个文件夹my_pwm作为自己的工程项目(aithinker_Ai-M6X_SDK/examples/my_pwm)
# 拷贝以下aithinker_Ai-M6X_SDK/examples/peripherals/pwm_v2/pwm_basic全部内容到自己的工程路径下(my_pwm)
  • 修改 CmakeLists.txt

  1. cmake_minimum_required(VERSION 3.15)

  2. include(proj.conf)

  3. find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE})

  4. sdk_set_main_file(main.c)

  5. project(my_pwm)
复制代码
  • 修改 flash_prog_cfg.ini

  1. [cfg]
  2. # 0: no erase, 1:programmed section erase, 2: chip erase
  3. erase = 1
  4. # skip mode set first para is skip addr, second para is skip len, multi-segment region with ; separated
  5. skip_mode = 0x0, 0x0
  6. # 0: not use isp mode, #1: isp mode
  7. boot2_isp_mode = 0

  8. # [FW]
  9. # filedir = ./build/build_out/pwm*_$(CHIPNAME).bin
  10. # address = 0x000000

  11. [boot2]
  12. filedir = ./build/build_out/boot2_*.bin
  13. address = 0x000000

  14. [partition]
  15. filedir = ./build/build_out/partition*.bin
  16. address = 0xE000

  17. [FW]
  18. filedir = ./build/build_out/my_pwm_$(CHIPNAME).bin
  19. address = @partition
复制代码


4. PWM呼吸灯功能实现



  1. #include "bflb_mtimer.h"
  2. #include "bflb_pwm_v2.h"
  3. #include "bflb_clock.h"
  4. #include "bflb_gpio.h"
  5. #include "board.h"

  6. struct bflb_device_s *pwm;
  7. struct bflb_device_s *gpio;

  8. #define PWM_PERIOD_MAX 255

  9. int main(void) {
  10.     int i;
  11.     board_init();

  12.     pwm = bflb_device_get_by_name("pwm_v2_0");
  13.     gpio = bflb_device_get_by_name("gpio");

  14.     /*初始化RGB灯,IO15、12、14,对应蓝灯、红灯、绿灯*/
  15.     bflb_gpio_init(gpio, GPIO_PIN_15, GPIO_FUNC_PWM0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
  16.     bflb_gpio_init(gpio, GPIO_PIN_12, GPIO_FUNC_PWM0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);
  17.     bflb_gpio_init(gpio, GPIO_PIN_14, GPIO_FUNC_PWM0 | GPIO_ALTERNATE | GPIO_PULLUP | GPIO_SMT_EN | GPIO_DRV_1);

  18.     /* period = .XCLK / .clk_div / .period = 40MHz / 40 / 1000 = 1KHz */
  19.     struct bflb_pwm_v2_config_s cfg = {
  20.         .clk_source = BFLB_SYSTEM_XCLK,
  21.         .clk_div = 40,
  22.         .period = PWM_PERIOD_MAX,
  23.     };

  24.     /*初始化PWM输出*/
  25.     bflb_pwm_v2_init(pwm, &cfg);
  26.     bflb_pwm_v2_start(pwm);

  27.     /*功能实现,红、绿、蓝灯依次呼吸循环亮灭*/
  28.     while (1) {
  29.         //红灯呼吸亮灭
  30.         bflb_pwm_v2_channel_positive_start(pwm, PWM_CH0); //使能红灯通道

  31.         for (i = 0; i < PWM_PERIOD_MAX; i++) {
  32.             bflb_pwm_v2_channel_set_threshold(pwm, PWM_CH0, 0, i);

  33.             bflb_mtimer_delay_ms(5);
  34.         }
  35.         for (i = PWM_PERIOD_MAX; i > 0; i--) {
  36.             bflb_pwm_v2_channel_set_threshold(pwm, PWM_CH0, 0, i);

  37.             bflb_mtimer_delay_ms(5);
  38.         }
  39.         bflb_pwm_v2_channel_positive_stop(pwm, PWM_CH0); //失能红灯通道

  40.         //绿灯呼吸亮灭
  41.         bflb_pwm_v2_channel_positive_start(pwm, PWM_CH2); //使能绿灯通道

  42.         for (i = 0; i < PWM_PERIOD_MAX; i++) {
  43.             bflb_pwm_v2_channel_set_threshold(pwm, PWM_CH2, 0, i);

  44.             bflb_mtimer_delay_ms(5);
  45.         }
  46.         for (i = PWM_PERIOD_MAX; i > 0; i--) {
  47.             bflb_pwm_v2_channel_set_threshold(pwm, PWM_CH2, 0, i);

  48.             bflb_mtimer_delay_ms(5);
  49.         }
  50.         bflb_pwm_v2_channel_positive_stop(pwm, PWM_CH2); //失能绿灯通道

  51.         //蓝灯循环亮灭
  52.         bflb_pwm_v2_channel_positive_start(pwm, PWM_CH3); //使能蓝灯通道

  53.         for (i = 0; i < PWM_PERIOD_MAX; i++) {
  54.             bflb_pwm_v2_channel_set_threshold(pwm, PWM_CH3, 0, i);

  55.             bflb_mtimer_delay_ms(5);
  56.         }
  57.         for (i = PWM_PERIOD_MAX; i > 0; i--) {
  58.             bflb_pwm_v2_channel_set_threshold(pwm, PWM_CH3, 0, i);

  59.             bflb_mtimer_delay_ms(5);
  60.         }
  61.         bflb_pwm_v2_channel_positive_stop(pwm, PWM_CH3); //失能蓝灯通道
  62.     }
  63. }
复制代码



5. 编译和烧录
  1. # 编译,打开终端,cd 到当前项目下,执行 make
  2. make
  3. # Linux 烧录命令
  4. # make flash COMX=/dev/ttyUSB0
  5. make flash COMX=COM5
复制代码

6. 实现代码
my_pwm.zip (2.29 KB, 下载次数: 1)
回复

使用道具 举报

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

本版积分规则