Navigation

    全志在线开发者论坛

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • 在线文档
    • 社区主页
    1. Home
    2. yanmingjian
    Y
    • Profile
    • Following 0
    • Followers 2
    • my integral 2334
    • Topics 26
    • Posts 42
    • Best 5
    • Groups 0

    giaoLV 5

    @yanmingjian

    2334
    integral
    6
    Reputation
    45
    Profile views
    42
    Posts
    2
    Followers
    0
    Following
    Joined Last Online
    Location 直布罗陀

    yanmingjian Unfollow Follow

    Best posts made by yanmingjian

    • 【全志T113-S3_100ask】Linux蓝牙通信实战

      (一)初始化蓝牙

      # 复位蓝牙
      echo 0 > /sys/class/rfkill/rfkill0/state
      sleep 1
      echo 1 > /sys/class/rfkill/rfkill0/state
      sleep 1
      
      # 绑定蓝牙设备
      hciattach -n ttyS1 xradio > /dev/null 2>&1 &
      sleep 8
      
      # 启用蓝牙设备
      hciconfig hci0 up
      hciconfig hci0 piscan
      

      (二)Linux下蓝牙工具(bluez 工具集)

      • hcitool、bluetoothctl等工具,可以进行BLE设备的扫描、连接、配对、广播等操作
      • hcitool 可以发送HCI command,设置BLE的广播数据
      • bluetoothctl 可以新增蓝牙服务,返回回调等操作
      • sdptool 查看蓝牙信息和提供的服务
      • hciconfig 查看蓝牙信息
      • l2ping 测试蓝牙的连通性
      • gatttool :可以在GATT层面,完成GATT profile的连接、service
      • attribute的读写等操作

      (三)蓝牙扫描

      hcitool scan 	#扫描经典蓝牙
      
      hcitool lescan	 #扫描BL低功耗蓝牙
      

      (四)使用Bluetoothctl创建蓝牙服务

      1、先启动蓝牙,进入可搜索状态

      # 复位蓝牙
      echo 0 > /sys/class/rfkill/rfkill0/state
      sleep 1
      echo 1 > /sys/class/rfkill/rfkill0/state
      sleep 1
      
      # 绑定设备
      hciattach -n ttyS1 xradio > /dev/null 2>&1 &
      sleep 8
      
      # 启用蓝牙设备
      hciconfig hci0 up
      hciconfig hci0 piscan
      
      # 免认证
      hciconfig hci0 auth
      # 广播
      hciconfig hci0 leadv
      

      2、进入 bluetoothctl 交互界面

      # bluetoothctl
      Agent registered
      [CHG] Controller 22:92:C9:8C:04:EA Pairable: yes
      [bluetooth]#
      

      3、手机使用BLE调试助手连接蓝牙,如下图所示

      d0b7a80a50f54b4b97d83d16901c7a69.jpeg

      4、连接后,bluetoothctl会发生变化,此时已经进入交互界面

      60c7807b5b42449cb17eb4e0e8d8b178.png

      4、但是我们没有其他服务,只能做一些简单的操作,比如读取,因为现有的服务是 bluetoothctl 提供的

      4d528dd7f4f743b997a69f9eeb76f4f5.jpeg

      5、下面我们添加自己的服务

      5.1 进入菜单

      [6B-3C-BF-AD-2A-A8]# menu gatt
      Menu gatt:
      Available commands:
      -------------------
      list-attributes [dev/local]                       List attributes
      select-attribute <attribute/UUID>                 Select attribute
      attribute-info [attribute/UUID]                   Select attribute
      read [offset]                                     Read attribute value
      write <data=xx xx ...> [offset] [type]            Write attribute value
      acquire-write                                     Acquire Write file descriptor
      release-write                                     Release Write file descriptor
      ....
      

      5.2 添加自己的service和characteristic

      [bluetoothctl] register-service 0xFFFF # (Choose yes when asked if primary service)
      [bluetoothctl] register-characteristic 0xAAAA read       # (Select a value of 1 when prompted)# 输入的值是初始值,每次读取,会加一
      [bluetoothctl] register-characteristic 0xBBBB read,write # (Select a value of 0 when prompted)
      [bluetoothctl] register-characteristic 0xCCCC read       # (Select a value of 2 when prompted)
      [bluetoothctl] register-application # (This commits the services/characteristics and registers the profile)
      [bluetoothctl] back
      [bluetoothctl] advertise on
      

      通过 show 操作可以看到刚才添加的0xffff 服务

      5.3 手机重新连接蓝牙
      服务从 3 项变为 4 项,第 4 项即为我们刚才添加的服务。

      be8fe95d320e42ccb5be219f087fee32.png

      5.4 读写操作
      在有上传按钮的服务上传数据

      92d75d26a94440e5aa84a19d9298ed2f.png

      此时收到:

      75c9a34123c246318a871e302ba74cd4.png

      读操作的话,直接读取就好了,值为刚才我们设置的值。
      至此测试完毕

      (五)其他操作

      1、启动/关闭/重启蓝牙

      hciconfig hci0 up  		#启动蓝牙设备
      hciconfig hci0 off 		#关闭蓝牙设备
      hciconfig hci0 reset 	#重启蓝牙设备
      

      2、测试蓝牙是否可达 l2ping

      l2ping -i hci0 -c 4 21:12:A3:C4:50:66
      

      3、查看功能与服务

      sdptool browse local    # local可以改成其它蓝牙的mac地址
      

      4、查看蓝牙的状态和信息

      hciconfig -a
      

      5、查看蓝牙设备

      hcitool dev
      Devices:
              hci0    22:22:2A:B0:9C:3C
      

      6、开启/关闭蓝牙广播

      hciconfig hci0 leadv / noleadv
      

      7、查看已经连接的BLE设备
      (此时调试助手已经连接)

      hcitool -i hci0 con
      Connections:
              > LE 60:AB:D1:B5:A6:FB handle 0 state 1 lm PERIPHERAL
      

      8、 蓝牙认证打开/关闭
      直接体现在进行蓝牙连接时,是否输入连接PIN密码,用于PIN配对

      hciconfig hci0 auth/noauth
      

      9、 查看/改变蓝牙主从状态

      hciconfig hci0 lm master、hciconfig hci0 lm slave
      

      10、查看/设置蓝牙名称

      hciconfig hci0 name 、hciconfig hci0 name BLXX
      

      11、 查看支持的链路层状态

      hciconfig hci0 lestates
      

      12、列出低功耗蓝牙的服务

      bluetoothctl --monitor gatt.list-attributes
      

      其他操作自己慢慢摸索哈,我一个人只能啃成这样了,如有写得不对的地方大佬指正。

      原文链接:https://blog.csdn.net/qq_46079439/article/details/126244998

      posted in D1系列-RISC-V
      Y
      giao
    • 【全志T113-S3_100ask】4-编写按键驱动(atomic + poll)

      前言

      本来想写一下点灯的驱动的,结果发现板子上没有用户的led灯?????那就试着写一下按键的驱动吧。

      (一)查看原理图

      在原理图里,找到了用户按键USER KEY的内容

      9615353f06ef4042b70e91e77e520006.png

      并且是连接在核心板的PB 4 引脚上

      f908d56c63824ae79d531898b7db6ff1.png

      看起来没有用作其他功能。

      (二)修改设备树

      设备树在以下目录里
      /disk/buildroot-100ask_t113-pro/buildroot/output/build/linux-d96275805a67d54998123d36e59108cb1ed52ad5/arch/arm/boot/dts

      添加一级子节点

      key { 
      	#address-cells = <1>; 
      	#size-cells = <1>;
      	reg = <0x0 0x0 0x0 0x0>;
        	compatible = "allwinner,sunxi-pinctrl-test"; 
        	pinctrl-names = "default"; 
       	pinctrl-0 = <&key_pins_a>; 
        	key-gpio = <&pio PB 4 GPIO_ACTIVE_LOW>; /* KEY0 */ 
        	status = "okay"; 
      };
      

      添加 pio

      key_pins_a: userkey { 
      	allwinner,pins = "PB4" ; 
      };
      

      添加后如下:
      6fe9c7a2005e4587951203a03e00a11b.png

      (三)编写驱动 key_drv.c

      #include <linux/types.h>
      #include <linux/kernel.h>
      #include <linux/delay.h>
      #include <linux/ide.h>
      #include <linux/init.h>
      #include <linux/module.h>
      #include <linux/errno.h>
      #include <linux/gpio.h>
      #include <linux/cdev.h>
      #include <linux/device.h>
      #include <linux/of.h>
      #include <linux/of_address.h>
      #include <linux/of_gpio.h>
      #include <linux/semaphore.h>
      #include <asm/mach/map.h>
      #include <asm/uaccess.h>
      #include <asm/io.h>
      
      #define KEY_CNT			1		/* 设备号个数 	*/
      #define KEY_NAME		"key"	/* 名字 		*/
      
      /* 定义按键值 */
      #define KEY0VALUE		0XF0	/* 按键值 		*/
      #define INVAKEY			0X00	/* 无效的按键值  */
      
      /* key设备结构体 */
      struct key_dev{
      	dev_t devid;			/* 设备号 	 */
      	struct cdev cdev;		/* cdev 	*/
      	struct class *class;	/* 类 		*/
      	struct device *device;	/* 设备 	 */
      	int major;				/* 主设备号	  */
      	int minor;				/* 次设备号   */
      	struct device_node	*nd; /* 设备节点 */
      	int key_gpio;			/* key所使用的GPIO编号		*/
      	atomic_t keyvalue;		/* 按键值 		*/	
      };
      
      struct key_dev keydev;		/* key设备 */
      
      /*
       * @description	: 初始化按键IO,open函数打开驱动的时候
       * 				  初始化按键所使用的GPIO引脚。
       * @param 		: 无
       * @return 		: 无
       */
      static int keyio_init(void)
      {
      	keydev.nd = of_find_node_by_path("/key");
      	if (keydev.nd== NULL) {
      		return -EINVAL;
      	}
      
      	keydev.key_gpio = of_get_named_gpio(keydev.nd ,"key-gpio", 0);
      	if (keydev.key_gpio < 0) {
      		printk("can't get key0\r\n");
      		return -EINVAL;
      	}
      	printk("key_gpio=%d\r\n", keydev.key_gpio);
      	
      	/* 初始化key所使用的IO */
      	gpio_request(keydev.key_gpio, "key0");	/* 请求IO */
      	gpio_direction_input(keydev.key_gpio);	/* 设置为输入 */
      	return 0;
      }
      
      /*
       * @description		: 打开设备
       * @param - inode 	: 传递给驱动的inode
       * @param - filp 	: 设备文件,file结构体有个叫做private_data的成员变量
       * 					  一般在open的时候将private_data指向设备结构体。
       * @return 			: 0 成功;其他 失败
       */
      static int key_open(struct inode *inode, struct file *filp)
      {
      	int ret = 0;
      	filp->private_data = &keydev; 	/* 设置私有数据 */
      
      	ret = keyio_init();				/* 初始化按键IO */
      	if (ret < 0) {
      		return ret;
      	}
      
      	return 0;
      }
      
      /*
       * @description		: 从设备读取数据 
       * @param - filp 	: 要打开的设备文件(文件描述符)
       * @param - buf 	: 返回给用户空间的数据缓冲区
       * @param - cnt 	: 要读取的数据长度
       * @param - offt 	: 相对于文件首地址的偏移
       * @return 			: 读取的字节数,如果为负值,表示读取失败
       */
      static ssize_t key_read(struct file *filp, char __user *buf, size_t cnt, loff_t *offt)
      {
      	int ret = 0;
      	int value;
      	struct key_dev *dev = filp->private_data;
      
      	if (gpio_get_value(dev->key_gpio) == 0) { 		/* key0按下 */
      		while(!gpio_get_value(dev->key_gpio));		/* 等待按键释放 */
      		atomic_set(&dev->keyvalue, KEY0VALUE);	
      	} else {	
      		atomic_set(&dev->keyvalue, INVAKEY);		/* 无效的按键值 */
      	}
      
      	value = atomic_read(&dev->keyvalue);
      	ret = copy_to_user(buf, &value, sizeof(value));
      	return ret;
      }
      
      /*
       * @description		: 向设备写数据 
       * @param - filp 	: 设备文件,表示打开的文件描述符
       * @param - buf 	: 要写给设备写入的数据
       * @param - cnt 	: 要写入的数据长度
       * @param - offt 	: 相对于文件首地址的偏移
       * @return 			: 写入的字节数,如果为负值,表示写入失败
       */
      static ssize_t key_write(struct file *filp, const char __user *buf, size_t cnt, loff_t *offt)
      {
      	return 0;
      }
      
      /*
       * @description		: 关闭/释放设备
       * @param - filp 	: 要关闭的设备文件(文件描述符)
       * @return 			: 0 成功;其他 失败
       */
      static int key_release(struct inode *inode, struct file *filp)
      {
      	return 0;
      }
      
      /* 设备操作函数 */
      static struct file_operations key_fops = {
      	.owner = THIS_MODULE,
      	.open = key_open,
      	.read = key_read,
      	.write = key_write,
      	.release = 	key_release,
      };
      
      /*
       * @description	: 驱动入口函数
       * @param 		: 无
       * @return 		: 无
       */
      static int __init mykey_init(void)
      {
      	/* 初始化原子变量 */
      	atomic_set(&keydev.keyvalue, INVAKEY);
      
      	/* 注册字符设备驱动 */
      	/* 1、创建设备号 */
      	if (keydev.major) {		/*  定义了设备号 */
      		keydev.devid = MKDEV(keydev.major, 0);
      		register_chrdev_region(keydev.devid, KEY_CNT, KEY_NAME);
      	} else {						/* 没有定义设备号 */
      		alloc_chrdev_region(&keydev.devid, 0, KEY_CNT, KEY_NAME);	/* 申请设备号 */
      		keydev.major = MAJOR(keydev.devid);	/* 获取分配号的主设备号 */
      		keydev.minor = MINOR(keydev.devid);	/* 获取分配号的次设备号 */
      	}
      	
      	/* 2、初始化cdev */
      	keydev.cdev.owner = THIS_MODULE;
      	cdev_init(&keydev.cdev, &key_fops);
      	
      	/* 3、添加一个cdev */
      	cdev_add(&keydev.cdev, keydev.devid, KEY_CNT);
      
      	/* 4、创建类 */
      	keydev.class = class_create(THIS_MODULE, KEY_NAME);
      	if (IS_ERR(keydev.class)) {
      		return PTR_ERR(keydev.class);
      	}
      
      	/* 5、创建设备 */
      	keydev.device = device_create(keydev.class, NULL, keydev.devid, NULL, KEY_NAME);
      	if (IS_ERR(keydev.device)) {
      		return PTR_ERR(keydev.device);
      	}
      	
      	return 0;
      }
      
      /*
       * @description	: 驱动出口函数
       * @param 		: 无
       * @return 		: 无
       */
      static void __exit mykey_exit(void)
      {
      	/* 注销字符设备驱动 */
      	gpio_free(keydev.key_gpio);
      	cdev_del(&keydev.cdev);/*  删除cdev */
      	unregister_chrdev_region(keydev.devid, KEY_CNT); /* 注销设备号 */
      
      	device_destroy(keydev.class, keydev.devid);
      	class_destroy(keydev.class);
      }
      
      module_init(mykey_init);
      module_exit(mykey_exit);
      MODULE_LICENSE("GPL");
      MODULE_AUTHOR("z");
      

      参考了正点原子的按键驱动:

      (四)编写测试应用 key_drv_test.c

      #include "stdio.h"
      #include "unistd.h"
      #include "sys/types.h"
      #include "sys/stat.h"
      #include "fcntl.h"
      #include "stdlib.h"
      #include "string.h"
      
      /* 定义按键值 */
      #define KEY0VALUE	0XF0
      #define INVAKEY		0X00
      
      /*
       * @description		: main主程序
       * @param - argc 	: argv数组元素个数
       * @param - argv 	: 具体参数
       * @return 			: 0 成功;其他 失败
       */
      int main(int argc, char *argv[])
      {
      	int fd, ret;
      	char *filename;
      	int keyvalue;
      	
      	if(argc != 2){
      		printf("Error Usage!\r\n");
      		return -1;
      	}
      
      	filename = argv[1];
      
      	/* 打开key驱动 */
      	fd = open(filename, O_RDWR);
      	if(fd < 0){
      		printf("file %s open failed!\r\n", argv[1]);
      		return -1;
      	}
      
      	/* 循环读取按键值数据! */
      	while(1) {
      		read(fd, &keyvalue, sizeof(keyvalue));
      		if (keyvalue == KEY0VALUE) {	/* KEY0 */
      			printf("KEY0 Press, value = %#X\r\n", keyvalue);	/* 按下 */
      		}
      	}
      
      	ret= close(fd); /* 关闭文件 */
      	if(ret < 0){
      		printf("file %s close failed!\r\n", argv[1]);
      		return -1;
      	}
      	return 0;
      }
      

      (五)编写Makefile

      KERN_DIR = /disk/buildroot-100ask_t113-pro/buildroot/output/build/linux-d96275805a67d54998123d36e59108cb1ed52ad5
      
      
      all:
      	make -C $(KERN_DIR) M=`pwd` modules 
      	$(CROSS_COMPILE)gcc -o key_drv_test key_drv_test.c 
      
      clean:
      	make -C $(KERN_DIR) M=`pwd` modules clean
      	rm -rf modules.order
      	rm -f key_drv_test
      
      obj-m	+= key_drv.o
      

      (六)测试

      编译驱动

      root@znh-ubuntu:/disk/vsCode/04_key# ls
      key_drv.c  key_drv_test.c  Makefile
      
      root@znh-ubuntu:/disk/vsCode/04_key# make
      make -C /disk/buildroot-100ask_t113-pro/buildroot/output/build/linux-d96275805a67d54998123d36e59108cb1ed52ad5 M=`pwd` modules
      make[1]: 进入目录“/disk/buildroot-100ask_t113-pro/buildroot/output/build/linux-d96275805a67d54998123d36e59108cb1ed52ad5”
        CC [M]  /disk/vsCode/04_key/key_drv.o
        Building modules, stage 2.
        MODPOST 1 modules
        CC [M]  /disk/vsCode/04_key/key_drv.mod.o
        LD [M]  /disk/vsCode/04_key/key_drv.ko
      make[1]: 离开目录“/disk/buildroot-100ask_t113-pro/buildroot/output/build/linux-d96275805a67d54998123d36e59108cb1ed52ad5”
      arm-linux-gnueabi-gcc -o key_drv_test key_drv_test.c
      
      root@znh-ubuntu:/disk/vsCode/04_key# ls
      key_drv.c   key_drv.mod    key_drv.mod.o  key_drv_test    Makefile       Module.symvers
      key_drv.ko  key_drv.mod.c  key_drv.o      key_drv_test.c  modules.order
      root@znh-ubuntu:/disk/vsCode/04_key#
      

      编译kernel、buildroot、烧卡、tftp:略

      测试驱动

      # chmod 777 key_drv_test
      # ls
      key_drv.ko    key_drv_test
      
      # insmod key_drv.ko
      [  162.979954] key_drv: loading out-of-tree module taints kernel.
      
      # ./key_drv_test /dev/key
      [  166.293872] key_gpio=36
      KEY0 Press, value = 0XF0
      KEY0 Press, value = 0XF0
      KEY0 Press, value = 0XF0
      ^C
      
      # ls /proc/device-tree
      #address-cells                memory@40000000
      #size-cells                   model
      aliases                       name
      chosen                        pio-18
      compatible                    pio-33
      cpu-opp-table                 pmu
      cpus                          power-management@ff000000
      dcxo24M_clk                   psci
      dram                          rc16m_clk
      dump_reg@20000                share_space@0x42100000
      ext32k_clk                    soc@3000000
      firmware                      thermal-zones
      interrupt-controller@3020000  timer_arch
      interrupt-parent              usb1-vbus
      iommu@2010000                 vdd-cpu
      key
      

      至此,按键驱动完成,但是还有很多需要修改的地方吧,或者很多冗余的东西,以后再修改了。

      原文链接:https://blog.csdn.net/qq_46079439/article/details/125899592

      posted in 其它全志芯片讨论区
      Y
      giao
    • 2022年7月版——在“哪吒”上跑AI 全志D1 ncnn框架移植笔记

      ncnn框架是当前边缘计算的主流框架,关于全志D1运行ncnn框架的笔记,nihui大佬曾经于2021年发表了相关的帖子。但是目前工具链和ncnn版本有所变化,因此在大佬的基础上将,完整过程记录如下。

      相关链接:
      1.https://bbs.aw-ol.com/topic/705/
      2.https://zhuanlan.zhihu.com/p/386312071?utm_source=qq&utm_medium=social&utm_oi=872955404320141312

      1 准备交叉编译工具链

      目前使用的交叉工具链是v2.2.6版本,具体下载链接见:https://occ.t-head.cn/community/download?id=4046947553902661632

      下载这个文件:Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.2.6-20220516.tar.gz

      tar -xf Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.2.6-20220516.tar.gz
      export RISCV_ROOT_PATH=/home/{你的用户名}/Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.2.6
      

      2 下载和编译ncnn

      这边的toolchain file选用c906-v226.toolchain.cmake,其余的不用修改,在toolchain file里面都已经改好了。其中可能有路径问题,根据ncnn文件夹,实际所在的路径修改即可。

      git clone https://github.com/Tencent/ncnn.git
      cd ncnn
      mkdir build-c906
      cd build-c906
      cmake -DCMAKE_TOOLCHAIN_FILE=../toolchains/c906-v226.toolchain.cmake -DCMAKE_BUILD_TYPE=release -DNCNN_OPENMP=OFF -DNCNN_THREADS=OFF -DNCNN_RUNTIME_CPU=OFF -DNCNN_RVV=ON -DNCNN_SIMPLEOCV=ON -DNCNN_BUILD_EXAMPLES=ON ..
      make -j4
      

      3 测试benchncnn

      目前2.0版本的TinaLinux 执行 ncnn 程序已经不会有问题

      将 ncnn/build-c906/benchmark/benchncnn 和 ncnn/benchmark/*.param 拷贝到 d1开发板上,路径结构如下:

      80abd156fc86ba2c318912d87e220577.png

      chmod 0777 benchncnn 
      ./benchncnn 4 1 0 -1 0
      
      oot@TinaLinux:~/ncnn# ./benchncnn 4 1 0 -1 0
      syscall error -1
      loop_count = 4
      num_threads = 1
      powersave = 0
      gpu_device = -1
      cooling_down = 0
      fopen squeezenet.param failed
      network graph not ready
      Segmentation fault
      root@TinaLinux:~/ncnn# ./benchncnn 4 1 0 -1 0
      syscall error -1
      loop_count = 4
      num_threads = 1
      powersave = 0
      gpu_device = -1
      cooling_down = 0
                squeezenet  min =  382.77  max =  385.92  avg =  384.66
           squeezenet_int8  min = 8975.18  max = 8979.84  avg = 8977.72
                 mobilenet  min =  702.76  max =  704.76  avg =  703.74
            mobilenet_int8  min = 29501.19  max = 29546.07  avg = 29514.59
              mobilenet_v2  min =  451.34  max =  452.27  avg =  451.78
              mobilenet_v3  min =  358.12  max =  359.24  avg =  358.42
                shufflenet  min =  527.04  max =  528.48  avg =  527.69
             shufflenet_v2  min =  310.96  max =  312.30  avg =  311.59
                   mnasnet  min =  435.13  max =  437.02  avg =  435.94
           proxylessnasnet  min =  473.05  max =  476.37  avg =  475.19
           efficientnet_b0  min =  601.75  max =  610.41  avg =  606.18
         efficientnetv2_b0  min =  859.37  max =  861.75  avg =  860.67
              regnety_400m  min =  653.71  max =  654.24  avg =  653.88
                 blazeface  min =  154.08  max =  154.67  avg =  154.38
                 googlenet  min = 1404.80  max = 1409.50  avg = 1407.33
            googlenet_int8  min = 42586.56  max = 42608.04  avg = 42597.36
                  resnet18  min = 1047.81  max = 1050.59  avg = 1049.40
             resnet18_int8  min = 45011.41  max = 45185.10  avg = 45098.12
                   alexnet  min =  955.34  max =  956.98  avg =  956.06
                     vgg16  min = 5355.40  max = 5356.05  avg = 5355.75
      

      如果一切运行正常,则会出现上述信息。

      4 测试example

      将 ncnn/build-c906/examples/nanodet 和测试图片拷贝到 d1开发板上

      从这里下载 nanodet 模型文件并拷贝到 d1开发板上

      nihui/ncnn-assets​github.com/nihui/ncnn-assets/tree/master/models

      目录结构如下:

      35b2dd1eb5e8a25b37f92325da1c0b16.png

      注意,进过测试,jpg格式的图像读取时会报错,png格式没有问题

      ./nanodet test.png
      

      bd0e8ab3ee50032c1a82e873a5aa8576.png
      177b58a5b1e4b24788974154c648b8b8.png

      posted in D1系列-RISC-V
      Y
      giao
    • 使用 D1s (RDC2022 纪念版) 连接 thingspeak

      D1s 连接网络

      硬件

      • D1s 开发板
      • RW007 模块

      D1s 开发板 RW007 模块 连接图
      1be560f99717c71203eaa6dcb15d4446.png.webp

      配置 RW007 软件包

      e5113c656db614ac2dfa5121542b6a93.png

      D1s 开发板 通过 SPI0 连接到 RW007 WiFi 模块
      c850f902f35d0cf99afaff939a8f991a.png

      使用 pkgs —update 更新软件包

      更新软件包之后 将 rw007 软件包中的 struct rw007_spi 结构体定义中的 ALIGN 改为 rt_align

      即可使用 wifi 指令连接 wifi 了

      d9b338ead18dc751decf8baff8e1bde8.png

      注: D1s 开发板 和 RW007 模块 之间同时使用将会有一些小问题

      • 在上电情况下插 RW007 模块 串口终端将会断掉,重新打开串口终端软件即可
      • 插着 RW007 模块 上电、复位 都将进入 FEL 模式,需要通过 xfel.exe reset 命令退出

      配置 thingspeak

      • 第一次使用时需要注册用户

      • 新建频道

      这里只使用最基本的功能,创建了一个数据接口 field1 后续需要通过 field1 来上传数据

      50b82be02283298b8bf698c28a235c50.png.webp

      查看创建好频道的相关 http 的 api

      1ff02f0469f34cd290e57e76904105b1.png

      如下图所示 Write a Channel Feed API 中最后的 field1=0 就是上传的数据(这里 0 不局限于数字,经验证字符串也是可以的)

      bc0fa0047f77d062dc8cd666379359ed.png.webp

      由于 thingspeak 使用了 GET 协议 我们这里使用了 webclient 软件包来进行数据的上传

      添加 webclient 软件包

      7cd0921c801e5e1cd69308bf762f7adc.png

      添加 rt-thread/bsp/allwinner/d1s/applications/thingspeak.c 文件

      将 GET_LOCAL_URI 宏定义的值换为你自己的 Write a Channel Feed API

      #include <stdio.h>
      #include <webclient.h>
      #define GET_LOCAL_URI "http://api.thingspeak.com/update?api_key=XXXXXXXXXXXX&field1="
      static int webclient_get_smpl(const char *uri)
      {
          char *response = RT_NULL;
          size_t resp_len = 0;
          int index;
          if (webclient_request(uri, RT_NULL, RT_NULL, 0, (void **)&response, &resp_len) < 0)
          {
              rt_kprintf("webclient send get request failed.");
              return -RT_ERROR;
          }
          rt_kprintf("webclient send get request by simplify request interface.\n");
          rt_kprintf("webclient get response data: \n");
          for (index = 0; index < rt_strlen(response); index++)
          {
              rt_kprintf("%c", response[index]);
          }
          rt_kprintf("\n");
          if (response)
          {
              web_free(response);
          }
          return 0;
      }
      static int thingspeak(void)
      {
          char uri[80];
          srand();
          int number;
          while(1)
          {
              number = rand() % 100;
              sprintf(uri, "%s%d", GET_LOCAL_URI, number);
              webclient_get_smpl(uri);
              rt_kprintf("random number is %d\r\n",number);
              rt_thread_mdelay(20000);
          }
      }
      MSH_CMD_EXPORT(thingspeak, thingspeak);
      
      

      上述文件为 每隔 20 秒,将开发板随机出来的 0~100 值上传到 thingspeak

      编译,下载,运行之后,连接 WIFI 后 使用 thingspeak 命令运行程序,如果出现下面这种情况则表明成功
      thread.org/ask/article/a5b655730a865335.html

      0adcb59be2a03db460356a4d1a4cbf37.png

      也可以通过 API Keys 中的其他 API 查询到开发板上传的数据

      20d48684d3cadde52e1bd71660cd0e3a.png

      另外这里还有可视化的图标供我们观看

      42a83f4369a07a302ab9ec81f5541972.png

      原文链接:https://club.rt-thread.org/ask/article/a5b655730a865335.html

      posted in D1系列-RISC-V
      Y
      giao
    • 【全志T113-S3_100ask】使用内核驱动点灯(控制继电器)

      背景

      开发板上没有led灯,且没用其他引出的GPIO,所以就借rgb屏幕的引脚来点个灯(不过分吧@狗头),实现控制继电器。

      (一)寻找合适的GPIO

      看了好久的原理图,怕与其他功能冲突,所以就使用了 PD13 作为本次实验的引脚。

      该引脚除了作为rgb屏幕的功能外,好像没其他作用了,好,就它了。

      4f64437d6891425bbdf72cd15c831ea1.png

      (二)跳线

      焊接飞线接到继电器上。

      88d1fc81a8da470eb4dab00da065c4d0.png

      (三)修改设备树

      参考开发文档

      Documentation/devicetree/bindings/leds/leds-gpio.txt

      LEDs connected to GPIO lines
      
      Required properties:
      - compatible : should be "gpio-leds".
      
      Each LED is represented as a sub-node of the gpio-leds device.  Each
      node's name represents the name of the corresponding LED.
      
      LED sub-node properties:
      - gpios :  Should specify the LED's GPIO, see "gpios property" in
        Documentation/devicetree/bindings/gpio/gpio.txt.  Active low LEDs should be
        indicated using flags in the GPIO specifier.
      - function :  (optional)
        see Documentation/devicetree/bindings/leds/common.txt
      - color :  (optional)
        see Documentation/devicetree/bindings/leds/common.txt
      - label :  (optional)
        see Documentation/devicetree/bindings/leds/common.txt (deprecated)
      - linux,default-trigger :  (optional)
        see Documentation/devicetree/bindings/leds/common.txt
      - default-state:  (optional) The initial state of the LED.
        see Documentation/devicetree/bindings/leds/common.txt
      - retain-state-suspended: (optional) The suspend state can be retained.Such
        as charge-led gpio.
      - retain-state-shutdown: (optional) Retain the state of the LED on shutdown.
        Useful in BMC systems, for example when the BMC is rebooted while the host
        remains up.
      - panic-indicator : (optional)
        see Documentation/devicetree/bindings/leds/common.txt
      
      Examples:
      
      #include <dt-bindings/gpio/gpio.h>
      #include <dt-bindings/leds/common.h>
      
      leds {
              compatible = "gpio-leds";
              led0 {
                      gpios = <&mcu_pio 0 GPIO_ACTIVE_LOW>;
                      linux,default-trigger = "disk-activity";
                      function = LED_FUNCTION_DISK;
              };
      
              led1 {
                      gpios = <&mcu_pio 1 GPIO_ACTIVE_HIGH>;
                      /* Keep LED on if BIOS detected hardware fault */
                      default-state = "keep";
                      function = LED_FUNCTION_FAULT;
              };
      };
      
      run-control {
              compatible = "gpio-leds";
              led0 {
                      gpios = <&mpc8572 6 GPIO_ACTIVE_HIGH>;
                      color = <LED_COLOR_ID_RED>;
                      default-state = "off";
              };
              led1 {
                      gpios = <&mpc8572 7 GPIO_ACTIVE_HIGH>;
                      color = <LED_COLOR_ID_GREEN>;
                      default-state = "on";
              };
      };
      
      leds {
              compatible = "gpio-leds";
      
              led0 {
                      gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>;
                      linux,default-trigger = "max8903-charger-charging";
                      retain-state-suspended;
                      function = LED_FUNCTION_CHARGE;
              };
      };
      

      简单来说就是指定 compatible = “gpio-leds” 就好了

      在根节点下添加:

      dtsleds { 
       	compatible = "gpio-leds";
       	led0 { 
      	 	label = "red";
      	  	gpios = <&pio PD 13 GPIO_ACTIVE_HIGH>; 
      	  	default-state = "off"; 
      	}; 
      };
      

      实例:

      ccc98029b00242ca904ebe910195495c.png

      (四)使能内核的LED驱动

      cbb51d2bde1b437a81d953fc17574778.png

      路径参考:

      Symbol: LEDS_GPIO [=y]                                                                                       │
       │ Type  : tristate                                                                                             │
       │ Prompt: LED Support for GPIO connected LEDs                                                                  │
       │   Location:                                                                                                  │
       │     -> Device Drivers                                                                                        │
       │       -> LED Support (NEW_LEDS [=y])                                                                         │
       │   Defined at drivers/leds/Kconfig:307                                                                        │
       │   Depends on: NEW_LEDS [=y] && LEDS_CLASS [=y] && (GPIOLIB [=y] || COMPILE_TEST [=n])                        │
       │   Selected by [n]:                                                                                           │
       │   - PCENGINES_APU2 [=n] && X86 && X86_PLATFORM_DEVICES [=n] && INPUT [=y] && INPUT_KEYBOARD [=y] && \        │
       │ GPIOLIB [=y] && LEDS_CLASS [=y]
      

      然后编译烧写系统。

      (五)测试验证

      1、寻找设备树,在 /proc/device-tree 下

      9ffd69cded23467d85204c0a6efdeb78.png

      2、点亮

      在 /sys/class/leds/red 下可以找到相关的属性

      下面使 brightness 属性为 1 .即可点亮

      echo 1 > /sys/class/leds/red/brightness
      

      继电器接通!!

      关闭的话,使用以下命令即可

      echo 0 > /sys/class/leds/red/brightness
      

      至此测试完毕

      原文链接:https://blog.csdn.net/qq_46079439/article/details/126131219
      作者@第四维度

      posted in D1系列-RISC-V
      Y
      giao

    Latest posts made by yanmingjian

    • Reply: 【FAQ】全志R128芯片 在FreeRTOS下如何查看并更改各CPU核的默认运行频率?

      @zhenxin 应该快出了吧,之前看到的消息
      https://www.cnx-software.com/2023/03/06/allwinner-r128-wireless-soc-features-64-bit-risc-v-core-arm-cortex-m33-core-and-hifi-5-audio-dsp/

      posted in R128系列-智能硬件
      Y
      giao
    • Reply: 使用 D1s (RDC2022 纪念版) 连接 thingspeak

      @xiaowenge 好,板子不错挺容易上手的,已经私聊你了😁 谢谢老板

      posted in D1系列-RISC-V
      Y
      giao
    • 使用 D1s (RDC2022 纪念版) 连接 thingspeak

      D1s 连接网络

      硬件

      • D1s 开发板
      • RW007 模块

      D1s 开发板 RW007 模块 连接图
      1be560f99717c71203eaa6dcb15d4446.png.webp

      配置 RW007 软件包

      e5113c656db614ac2dfa5121542b6a93.png

      D1s 开发板 通过 SPI0 连接到 RW007 WiFi 模块
      c850f902f35d0cf99afaff939a8f991a.png

      使用 pkgs —update 更新软件包

      更新软件包之后 将 rw007 软件包中的 struct rw007_spi 结构体定义中的 ALIGN 改为 rt_align

      即可使用 wifi 指令连接 wifi 了

      d9b338ead18dc751decf8baff8e1bde8.png

      注: D1s 开发板 和 RW007 模块 之间同时使用将会有一些小问题

      • 在上电情况下插 RW007 模块 串口终端将会断掉,重新打开串口终端软件即可
      • 插着 RW007 模块 上电、复位 都将进入 FEL 模式,需要通过 xfel.exe reset 命令退出

      配置 thingspeak

      • 第一次使用时需要注册用户

      • 新建频道

      这里只使用最基本的功能,创建了一个数据接口 field1 后续需要通过 field1 来上传数据

      50b82be02283298b8bf698c28a235c50.png.webp

      查看创建好频道的相关 http 的 api

      1ff02f0469f34cd290e57e76904105b1.png

      如下图所示 Write a Channel Feed API 中最后的 field1=0 就是上传的数据(这里 0 不局限于数字,经验证字符串也是可以的)

      bc0fa0047f77d062dc8cd666379359ed.png.webp

      由于 thingspeak 使用了 GET 协议 我们这里使用了 webclient 软件包来进行数据的上传

      添加 webclient 软件包

      7cd0921c801e5e1cd69308bf762f7adc.png

      添加 rt-thread/bsp/allwinner/d1s/applications/thingspeak.c 文件

      将 GET_LOCAL_URI 宏定义的值换为你自己的 Write a Channel Feed API

      #include <stdio.h>
      #include <webclient.h>
      #define GET_LOCAL_URI "http://api.thingspeak.com/update?api_key=XXXXXXXXXXXX&field1="
      static int webclient_get_smpl(const char *uri)
      {
          char *response = RT_NULL;
          size_t resp_len = 0;
          int index;
          if (webclient_request(uri, RT_NULL, RT_NULL, 0, (void **)&response, &resp_len) < 0)
          {
              rt_kprintf("webclient send get request failed.");
              return -RT_ERROR;
          }
          rt_kprintf("webclient send get request by simplify request interface.\n");
          rt_kprintf("webclient get response data: \n");
          for (index = 0; index < rt_strlen(response); index++)
          {
              rt_kprintf("%c", response[index]);
          }
          rt_kprintf("\n");
          if (response)
          {
              web_free(response);
          }
          return 0;
      }
      static int thingspeak(void)
      {
          char uri[80];
          srand();
          int number;
          while(1)
          {
              number = rand() % 100;
              sprintf(uri, "%s%d", GET_LOCAL_URI, number);
              webclient_get_smpl(uri);
              rt_kprintf("random number is %d\r\n",number);
              rt_thread_mdelay(20000);
          }
      }
      MSH_CMD_EXPORT(thingspeak, thingspeak);
      
      

      上述文件为 每隔 20 秒,将开发板随机出来的 0~100 值上传到 thingspeak

      编译,下载,运行之后,连接 WIFI 后 使用 thingspeak 命令运行程序,如果出现下面这种情况则表明成功
      thread.org/ask/article/a5b655730a865335.html

      0adcb59be2a03db460356a4d1a4cbf37.png

      也可以通过 API Keys 中的其他 API 查询到开发板上传的数据

      20d48684d3cadde52e1bd71660cd0e3a.png

      另外这里还有可视化的图标供我们观看

      42a83f4369a07a302ab9ec81f5541972.png

      原文链接:https://club.rt-thread.org/ask/article/a5b655730a865335.html

      posted in D1系列-RISC-V
      Y
      giao
    • 【全志T113-S3_100ask】Linux蓝牙通信实战

      (一)初始化蓝牙

      # 复位蓝牙
      echo 0 > /sys/class/rfkill/rfkill0/state
      sleep 1
      echo 1 > /sys/class/rfkill/rfkill0/state
      sleep 1
      
      # 绑定蓝牙设备
      hciattach -n ttyS1 xradio > /dev/null 2>&1 &
      sleep 8
      
      # 启用蓝牙设备
      hciconfig hci0 up
      hciconfig hci0 piscan
      

      (二)Linux下蓝牙工具(bluez 工具集)

      • hcitool、bluetoothctl等工具,可以进行BLE设备的扫描、连接、配对、广播等操作
      • hcitool 可以发送HCI command,设置BLE的广播数据
      • bluetoothctl 可以新增蓝牙服务,返回回调等操作
      • sdptool 查看蓝牙信息和提供的服务
      • hciconfig 查看蓝牙信息
      • l2ping 测试蓝牙的连通性
      • gatttool :可以在GATT层面,完成GATT profile的连接、service
      • attribute的读写等操作

      (三)蓝牙扫描

      hcitool scan 	#扫描经典蓝牙
      
      hcitool lescan	 #扫描BL低功耗蓝牙
      

      (四)使用Bluetoothctl创建蓝牙服务

      1、先启动蓝牙,进入可搜索状态

      # 复位蓝牙
      echo 0 > /sys/class/rfkill/rfkill0/state
      sleep 1
      echo 1 > /sys/class/rfkill/rfkill0/state
      sleep 1
      
      # 绑定设备
      hciattach -n ttyS1 xradio > /dev/null 2>&1 &
      sleep 8
      
      # 启用蓝牙设备
      hciconfig hci0 up
      hciconfig hci0 piscan
      
      # 免认证
      hciconfig hci0 auth
      # 广播
      hciconfig hci0 leadv
      

      2、进入 bluetoothctl 交互界面

      # bluetoothctl
      Agent registered
      [CHG] Controller 22:92:C9:8C:04:EA Pairable: yes
      [bluetooth]#
      

      3、手机使用BLE调试助手连接蓝牙,如下图所示

      d0b7a80a50f54b4b97d83d16901c7a69.jpeg

      4、连接后,bluetoothctl会发生变化,此时已经进入交互界面

      60c7807b5b42449cb17eb4e0e8d8b178.png

      4、但是我们没有其他服务,只能做一些简单的操作,比如读取,因为现有的服务是 bluetoothctl 提供的

      4d528dd7f4f743b997a69f9eeb76f4f5.jpeg

      5、下面我们添加自己的服务

      5.1 进入菜单

      [6B-3C-BF-AD-2A-A8]# menu gatt
      Menu gatt:
      Available commands:
      -------------------
      list-attributes [dev/local]                       List attributes
      select-attribute <attribute/UUID>                 Select attribute
      attribute-info [attribute/UUID]                   Select attribute
      read [offset]                                     Read attribute value
      write <data=xx xx ...> [offset] [type]            Write attribute value
      acquire-write                                     Acquire Write file descriptor
      release-write                                     Release Write file descriptor
      ....
      

      5.2 添加自己的service和characteristic

      [bluetoothctl] register-service 0xFFFF # (Choose yes when asked if primary service)
      [bluetoothctl] register-characteristic 0xAAAA read       # (Select a value of 1 when prompted)# 输入的值是初始值,每次读取,会加一
      [bluetoothctl] register-characteristic 0xBBBB read,write # (Select a value of 0 when prompted)
      [bluetoothctl] register-characteristic 0xCCCC read       # (Select a value of 2 when prompted)
      [bluetoothctl] register-application # (This commits the services/characteristics and registers the profile)
      [bluetoothctl] back
      [bluetoothctl] advertise on
      

      通过 show 操作可以看到刚才添加的0xffff 服务

      5.3 手机重新连接蓝牙
      服务从 3 项变为 4 项,第 4 项即为我们刚才添加的服务。

      be8fe95d320e42ccb5be219f087fee32.png

      5.4 读写操作
      在有上传按钮的服务上传数据

      92d75d26a94440e5aa84a19d9298ed2f.png

      此时收到:

      75c9a34123c246318a871e302ba74cd4.png

      读操作的话,直接读取就好了,值为刚才我们设置的值。
      至此测试完毕

      (五)其他操作

      1、启动/关闭/重启蓝牙

      hciconfig hci0 up  		#启动蓝牙设备
      hciconfig hci0 off 		#关闭蓝牙设备
      hciconfig hci0 reset 	#重启蓝牙设备
      

      2、测试蓝牙是否可达 l2ping

      l2ping -i hci0 -c 4 21:12:A3:C4:50:66
      

      3、查看功能与服务

      sdptool browse local    # local可以改成其它蓝牙的mac地址
      

      4、查看蓝牙的状态和信息

      hciconfig -a
      

      5、查看蓝牙设备

      hcitool dev
      Devices:
              hci0    22:22:2A:B0:9C:3C
      

      6、开启/关闭蓝牙广播

      hciconfig hci0 leadv / noleadv
      

      7、查看已经连接的BLE设备
      (此时调试助手已经连接)

      hcitool -i hci0 con
      Connections:
              > LE 60:AB:D1:B5:A6:FB handle 0 state 1 lm PERIPHERAL
      

      8、 蓝牙认证打开/关闭
      直接体现在进行蓝牙连接时,是否输入连接PIN密码,用于PIN配对

      hciconfig hci0 auth/noauth
      

      9、 查看/改变蓝牙主从状态

      hciconfig hci0 lm master、hciconfig hci0 lm slave
      

      10、查看/设置蓝牙名称

      hciconfig hci0 name 、hciconfig hci0 name BLXX
      

      11、 查看支持的链路层状态

      hciconfig hci0 lestates
      

      12、列出低功耗蓝牙的服务

      bluetoothctl --monitor gatt.list-attributes
      

      其他操作自己慢慢摸索哈,我一个人只能啃成这样了,如有写得不对的地方大佬指正。

      原文链接:https://blog.csdn.net/qq_46079439/article/details/126244998

      posted in D1系列-RISC-V
      Y
      giao
    • 【全志T113-S3_100ask】使用内核驱动点灯(控制继电器)

      背景

      开发板上没有led灯,且没用其他引出的GPIO,所以就借rgb屏幕的引脚来点个灯(不过分吧@狗头),实现控制继电器。

      (一)寻找合适的GPIO

      看了好久的原理图,怕与其他功能冲突,所以就使用了 PD13 作为本次实验的引脚。

      该引脚除了作为rgb屏幕的功能外,好像没其他作用了,好,就它了。

      4f64437d6891425bbdf72cd15c831ea1.png

      (二)跳线

      焊接飞线接到继电器上。

      88d1fc81a8da470eb4dab00da065c4d0.png

      (三)修改设备树

      参考开发文档

      Documentation/devicetree/bindings/leds/leds-gpio.txt

      LEDs connected to GPIO lines
      
      Required properties:
      - compatible : should be "gpio-leds".
      
      Each LED is represented as a sub-node of the gpio-leds device.  Each
      node's name represents the name of the corresponding LED.
      
      LED sub-node properties:
      - gpios :  Should specify the LED's GPIO, see "gpios property" in
        Documentation/devicetree/bindings/gpio/gpio.txt.  Active low LEDs should be
        indicated using flags in the GPIO specifier.
      - function :  (optional)
        see Documentation/devicetree/bindings/leds/common.txt
      - color :  (optional)
        see Documentation/devicetree/bindings/leds/common.txt
      - label :  (optional)
        see Documentation/devicetree/bindings/leds/common.txt (deprecated)
      - linux,default-trigger :  (optional)
        see Documentation/devicetree/bindings/leds/common.txt
      - default-state:  (optional) The initial state of the LED.
        see Documentation/devicetree/bindings/leds/common.txt
      - retain-state-suspended: (optional) The suspend state can be retained.Such
        as charge-led gpio.
      - retain-state-shutdown: (optional) Retain the state of the LED on shutdown.
        Useful in BMC systems, for example when the BMC is rebooted while the host
        remains up.
      - panic-indicator : (optional)
        see Documentation/devicetree/bindings/leds/common.txt
      
      Examples:
      
      #include <dt-bindings/gpio/gpio.h>
      #include <dt-bindings/leds/common.h>
      
      leds {
              compatible = "gpio-leds";
              led0 {
                      gpios = <&mcu_pio 0 GPIO_ACTIVE_LOW>;
                      linux,default-trigger = "disk-activity";
                      function = LED_FUNCTION_DISK;
              };
      
              led1 {
                      gpios = <&mcu_pio 1 GPIO_ACTIVE_HIGH>;
                      /* Keep LED on if BIOS detected hardware fault */
                      default-state = "keep";
                      function = LED_FUNCTION_FAULT;
              };
      };
      
      run-control {
              compatible = "gpio-leds";
              led0 {
                      gpios = <&mpc8572 6 GPIO_ACTIVE_HIGH>;
                      color = <LED_COLOR_ID_RED>;
                      default-state = "off";
              };
              led1 {
                      gpios = <&mpc8572 7 GPIO_ACTIVE_HIGH>;
                      color = <LED_COLOR_ID_GREEN>;
                      default-state = "on";
              };
      };
      
      leds {
              compatible = "gpio-leds";
      
              led0 {
                      gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>;
                      linux,default-trigger = "max8903-charger-charging";
                      retain-state-suspended;
                      function = LED_FUNCTION_CHARGE;
              };
      };
      

      简单来说就是指定 compatible = “gpio-leds” 就好了

      在根节点下添加:

      dtsleds { 
       	compatible = "gpio-leds";
       	led0 { 
      	 	label = "red";
      	  	gpios = <&pio PD 13 GPIO_ACTIVE_HIGH>; 
      	  	default-state = "off"; 
      	}; 
      };
      

      实例:

      ccc98029b00242ca904ebe910195495c.png

      (四)使能内核的LED驱动

      cbb51d2bde1b437a81d953fc17574778.png

      路径参考:

      Symbol: LEDS_GPIO [=y]                                                                                       │
       │ Type  : tristate                                                                                             │
       │ Prompt: LED Support for GPIO connected LEDs                                                                  │
       │   Location:                                                                                                  │
       │     -> Device Drivers                                                                                        │
       │       -> LED Support (NEW_LEDS [=y])                                                                         │
       │   Defined at drivers/leds/Kconfig:307                                                                        │
       │   Depends on: NEW_LEDS [=y] && LEDS_CLASS [=y] && (GPIOLIB [=y] || COMPILE_TEST [=n])                        │
       │   Selected by [n]:                                                                                           │
       │   - PCENGINES_APU2 [=n] && X86 && X86_PLATFORM_DEVICES [=n] && INPUT [=y] && INPUT_KEYBOARD [=y] && \        │
       │ GPIOLIB [=y] && LEDS_CLASS [=y]
      

      然后编译烧写系统。

      (五)测试验证

      1、寻找设备树,在 /proc/device-tree 下

      9ffd69cded23467d85204c0a6efdeb78.png

      2、点亮

      在 /sys/class/leds/red 下可以找到相关的属性

      下面使 brightness 属性为 1 .即可点亮

      echo 1 > /sys/class/leds/red/brightness
      

      继电器接通!!

      关闭的话,使用以下命令即可

      echo 0 > /sys/class/leds/red/brightness
      

      至此测试完毕

      原文链接:https://blog.csdn.net/qq_46079439/article/details/126131219
      作者@第四维度

      posted in D1系列-RISC-V
      Y
      giao
    • 【全志T113-S3_100ask】音频输入与输出

      背景

      之前查看系统命令,发现有个aplay命令,然后尝试使用 aplay -Dhw:audiocodec -vvv gz.wav 播放音频,然后报错 aplay: pcm_write:2127: write error: Input/output error

      # aplay -Dhw:audiocodec  gz.wav
      Playing WAVE 'gz.wav' : [   46.786665] [SNDCODEC][sunxi_card_hw_params][620]:stream_flag: 0
      Signed 16 bit Little Endian, Rate 16000 Hz, Mono
      aplay: pcm_write:2127: write error: Input/output error
      

      然后就不会了。

      8月2日100ask出了简单的教程,是需要先使用tinymix 设置参数的,但是。-bash: tinymix: command not found

      我又不想再去编译安装 tinymix ,发现有个 amixer 命令,查阅资料成功配置,播放了音乐。

      (一)amixer 的使用

      1、查看用法

      # amixer -h
      Usage: amixer <options> [command]
      
      Available options:
        -h,--help       this help
        -c,--card N     select the card
        -D,--device N   select the device, default 'default'
        -d,--debug      debug mode
        -n,--nocheck    do not perform range checking
        -v,--version    print version of this program
        -q,--quiet      be quiet
        -i,--inactive   show also inactive controls
        -a,--abstract L select abstraction level (none or basic)
        -s,--stdin      Read and execute commands from stdin sequentially
        -R,--raw-volume Use the raw value (default)
        -M,--mapped-volume Use the mapped volume
      
      Available commands:
        scontrols       show all mixer simple controls
        scontents       show contents of all mixer simple controls (default command)
        sset sID P      set contents for one mixer simple control
        sget sID        get contents for one mixer simple control
        controls        show all controls for given card
        contents        show contents of all controls for given card
        cset cID P      set control contents for one control
        cget cID        get control contents for one control
      
      Available advanced commands:
        sevents         show the mixer events for simple controls
        events          show the mixer events for simple controls
      

      有点复杂看不懂。。。查阅资料。

      2、常用命令

      本节参考 https://blog.csdn.net/meirixuexi/article/details/71513007

      amixer controls 用于查看音频系统提供的操作接口
      amixer contents 用于查看接口配置参数
      amixer cget + 接口函数
      amixer cset + 接口函数 + 设置值
      

      解释:比如想要设置主音量,第一次使用的话先得查询一下接口函数的配置参数,但是又不知道接口叫什么,先查询所有接口

      # amixer controls
      numid=17,iface=MIXER,name='Headphone volume'
      numid=30,iface=MIXER,name='Headphone Switch'
      numid=12,iface=MIXER,name='FMINL gain volume'
      numid=13,iface=MIXER,name='FMINR gain volume'
      numid=2,iface=MIXER,name='ADC1 ADC2 swap'
      numid=24,iface=MIXER,name='ADC1 Input FMINL Switch'
      numid=25,iface=MIXER,name='ADC1 Input LINEINL Switch'
      numid=23,iface=MIXER,name='ADC1 Input MIC1 Boost Switch'
      numid=6,iface=MIXER,name='ADC1 volume'
      ...省略...
      

      找到了Headphone volume,意思是耳机音量,因为我们是使用3.5mm接口的,所以这一项和我们想要的很像。

      使用 amixer cget + 接口函数查询现在的参数,如:

      # amixer cget numid=17,iface=MIXER,name='Headphone volume'
      
      numid=17,iface=MIXER,name='Headphone volume'
        ; type=INTEGER,access=rw---R--,values=1,min=0,max=7,step=0
        : values=4
        | dBscale-min=-42.00dB,step=6.00dB,mute=0
      

      value = 4,最大值为7

      修改音量值为6:

      # amixer cset numid=17,iface=MIXER,name='Headphone volume' 6
      
      numid=17,iface=MIXER,name='Headphone volume'
        ; type=INTEGER,access=rw---R--,values=1,min=0,max=7,step=0
        : values=6
        | dBscale-min=-42.00dB,step=6.00dB,mute=0
      

      (二)amixer 设置音频输出参数

      经过查询,之所以出现 aplay: pcm_write:2127: write error: Input/output error 错误是因为没有输出设备。

      # amixer cget numid=30,iface=MIXER,name='Headphone Switch'
      
      numid=30,iface=MIXER,name='Headphone Switch'
        ; type=BOOLEAN,access=rw------,values=1
        : values=off
      

      耳机开关的输出是 off !!!

      将其开启:

      # amixer cset numid=30,iface=MIXER,name='Headphone Switch' on
      
      numid=30,iface=MIXER,name='Headphone Switch'
        ; type=BOOLEAN,access=rw------,values=1
        : values=on
      

      使用 aplay 可以从耳机输出音乐了!!

      (三)使用 aplay 播放音乐

      1、配置音频输出渠道:

      # amixer cset numid=30,iface=MIXER,name='Headphone Switch' on
      
      numid=30,iface=MIXER,name='Headphone Switch'
        ; type=BOOLEAN,access=rw------,values=1
        : values=on
      

      2、设置音量1:

      # amixer cset numid=17,iface=MIXER,name='Headphone volume' 6
      
      numid=17,iface=MIXER,name='Headphone volume'
        ; type=INTEGER,access=rw---R--,values=1,min=0,max=7,step=0
        : values=6
        | dBscale-min=-42.00dB,step=6.00dB,mute=0
      

      设置音量2:

      # amixer cset numid=5,iface=MIXER,name="PCM Volume" 170
      
      numid=5,iface=MIXER,name='DAC volume'
        ; type=INTEGER,access=rw---R--,values=2,min=0,max=255,step=0
        : values=170,170
        | dBscale-min=-119.25dB,step=0.75dB,mute=0
      

      3、播放音乐:

      # aplay -Dhw:audiocodec -vvv piao.wav
      
      Playing WAVE 'piao.wav' : [  228.205229] [SNDCODEC][sunxi_card_hw_params][620]:stream_flag: 0
      Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
      Hardware PCM card 0 'audiocodec' device 0 subdevice 0
      Its setup is:
        stream       : PLAYBACK
        access       : RW_INTERLEAVED
        format       : S16_LE
        subformat    : STD
      ...省略...
      

      实测:

      3bd5a2f03b5b4b3cb835dd8a7af85391.png

      (四)使用 arecord 录音

      配置音频输入渠道:

      amixer cset numid=29,iface=MIXER,name='ADC3 Input MIC3 Boost Switch' on
      amixer cset numid=31,iface=MIXER,name='HpSpeaker Switch' on
      

      录音

      arecord -Dhw:audiocodec -f S24_LE -r 16000 -c 1 -d 10 -vv ./in.wav
      

      解释:使用 设备audiocodec
      录制 格式为S24_LE
      输入比特率为16000
      通道1
      时间为10s
      保存在 ./in.wav
      更多内容\查看帮助 arecord -h

      实测:

      8b880533322f40d7a396b588da537fd6.png

      原文链接:https://blog.csdn.net/qq_46079439/article/details/126127325

      posted in D1系列-RISC-V
      Y
      giao
    • Reply: uboot正确启动了,RGB屏点不亮

      @zznzzn

      运气不错~竟然没烧哈哈

      Licheepi这个支持电阻屏,想要测试触摸功能要重新买块电阻屏哦

      也是通用的

      QQ图片20220922163413.jpg

      posted in 其它全志芯片讨论区
      Y
      giao
    • Reply: uboot正确启动了,RGB屏点不亮

      屏是标准的rgb接口屏,可是正点原子转接过啦

      应该是用这个,插Licheepi,这个是通用的RGB 40pin接口

      QQ图片20220922160245.jpg

      不确定接口顺序就直接插上去,不怕冒烟嘛?

      posted in 其它全志芯片讨论区
      Y
      giao
    • 【全志T113-S3_100ask】USB串口获取GPS数据

      背景

      板子上有两个串口,但是串口1被xr829模块占用了,串口3主要用于调试,为简单实现串口功能,本讲将实现usb转串口(ch340)来采集gps的数据,并解析。

      (一)USB串口驱动

      @本讲不使用Tina系统,使用 百问Buildroot 。

      Tips:CH340是CH341的阉割版,CH340不支持并口、打印口、IIC,专为串口应用设计

      在buildroot已经集成了ch341的驱动,我们将其 使能 即可使用,非常简单。

      Symbol: USB_SERIAL_CH341 [=y]                                                                                
         Type  : tristate                                                                                             
         Prompt: USB Winchiphead CH341 Single Port Serial Driver                                                      
           Location:                                                                                                  
             -> Device Drivers                                                                                        
               -> USB support (USB_SUPPORT [=y])                                                                      
         (1)     -> USB Serial Converter support (USB_SERIAL [=y])                                                    
           Defined at drivers/usb/serial/Kconfig:105                                                                  
           Depends on: USB_SUPPORT [=y] && USB [=y] && USB_SERIAL [=y]
      

      (二)驱动加载

      驱动是编译进内核的,不用手动加载,把USB转TTL插到USB口就自动匹配识别,生成ttyUSB0设备。
      以下是开机显示信息:

      [   11.529946] usbcore: registered new interface driver ch341
      [   11.537840] usbserial: USB Serial support registered for ch341-uart
      [   11.545934] ch341 1-1.2:1.0: ch341-uart converter detected
      [   11.578483] usb 1-1.2: ch341-uart converter now attached to ttyUSB0
      
      ls /dev
      

      e70eb4435354446080861b476af87b14.png

      (三)简单读取串口数据

      此时已经将ch340和gps模块连接上开发板了
      5de7d28df1c44082a5227e0c256a338e.jpeg

      使用 cat 命令即可简单读取串口返回的信息。

      # cat /dev/ttyUSB0
      
      A*7B
      
      $GPVTG,,T,,M,1.070,N,1.982,K,A*27
      
      $GPGGA,072008.00,2306.6$GPTXT,01,01,01,NMEA unknown msg*58
      
      $GPRMC,072232.00,A,2306.62360,N,11316.59966,E,0.311,,020822,,,A*78
      
      $GPVTG,,T,,M,0.311,N,0.577,K,A*25
      
      $GPGGA,072232.00,2306.62360,N,11316.59966,E,1,08,1.62,21.7,M,-5.6,M,,*7A
      
      $GPGSA,A,3,13,02,05,11,20,18,24,23,,,,,3.06,1.62,2.59*05
      
      $GPGSV,3,1,11,02,49,126,20,05,43,034,37,11,28,123,12,13,58,033,35*72
      
      $GPGSV,3,2,11,15,73,291,21,18,27,324,37,20,24,071,29,23,10,286,32*78
      
      $GPGSV,3,3,11,24,26,175,20,29,48,259,10,30,06,046,*45
      
      $GPGLL,2306.62360,N,11316.59966,E,072232.00,A,A*68
      

      (四)数据解析

      本解析参考: https://blog.csdn.net/qq_30665009/article/details/121434507

      我们在编写正式的应用程序之前,先了解这一堆数据里面我们想要的部分 --> $GPRMC

      $GPRMC格式:

      $GPRMC,<1>,<2>,<3>,<4>,<5>,<6>,<7>,<8>,<9>,<10>,<11>,<12>*hh<CR><LF>
      
      $GPRMC,072232.00,A,2306.62360,N,11316.59966,E,0.311,,020822,,,A*78
      

      其中:

      99299559-7F78-4cb0-9987-DC72A0B68F3F.png

      (五)编写应用程序

      参考 https://www.likecs.com/show-205110023.html

      1、定义结构体

      typedef struct __gprmc__
      {
          UINT time;         /* gps定位时间 */
          char pos_state;    /*gps状态位*/
          float latitude;    /*纬度 */
          float longitude;   /* 经度 */
          float speed;       /* 速度 */
          float direction;   /*航向 */
          UINT date;         /*日期  */
          float declination; /* 磁偏角 */
          char dd;
          char mode; /* GPS模式位 */
      } GPRMC;
      

      2、使用 open 和 read 函数读取串口数据

      3、获取想要的部分

      /* 如果buff字符串中包含字符"$GPRMC"则将$GPRMC的地址赋值给ptr */
      if (NULL == (ptr = strstr(buff, "$GPRMC")))
      {
          return -1;
      }
      

      4、使用 sscanf 进行格式化处理,存进结构体

      5、计算、回显处理

      (六)测试

      编译后放到开发板,测试程序

      # ls
      gps_test
      
      # ./gps_test
      buff:1,13,36,033,33*7F
      $GPGSV,3,2,10,15,62,356,30,18,48,324,20,20,14,092,19,23,21,306,23*7A
      $GPGSV,3,3,10,24,48,164,20,29,35,229,25*70
      $GPGLL,2306.62377,N,11316.59930,E,081227.00,A,A*65
      $GPRMC,081228.00,A,2306.62398,N,11316.59935,E,0.294,,020822,,,A*72
      $GPVTG,,T,,M,0.294,N,0.545,K,A*28
      $GPGGA,081228.00,2306.62398,N,11316.59935,E,1,08,1.04,-0.4,M,-5.6,M,,*61
      $GPGSA,A,3,15,18,24,13,05,02,23,20,,,,,2.10,1.04,1.82*02
      $GPGSV,3,1,10,02,29,144,21,05,36,062,35,11,10,138,,13,36,033,32*7E
      $GPGSV,3,2,10,15,62,356,30,18,48,324,17,20,14,092,20,23,21,306,22*75
      $GPGSV,3,3,10,24,48,164,20,29,35,229,26*73
      $GPGLL,2306.62398,N,11316.59935,E,081228.00,A,A*6E
      $GPRMC,081229.00,A,2306.62396,N,11316.59928,E,0.427,,020822,,,A*7F
      $GPVTG,,T,,M,0.427,N,0.791,K,A*2D
      $GPGGA,081229.00,2306.62396,N,11316.59928,E,1,09,1.04,-0.8,M,-5.6,M,,*6F
      $GPGSA,A,3,15,18,24,13,05,02,23,20,11,,,,2.10,1.04,1.82*02
      $GPGSV,3,1,10,02,29,144,21,05,36,062,35,11,10,138,1,1144,15,05,36,062,36,11,10,138,12)▒▒
      ===========================================================
      ==
      ==   GPS state bit : A  [A:有效状态 V:无效状态]
      ==   GPS mode  bit : A  [A:自主定位 D:差分定位]
      ==   Date : 2022-08-02
      ==   Time : 16:12:28
      ==   纬度 : 北纬:23度6分37秒
      ==   经度 : 东经:113度16分35秒
      ==   速度 : 0.294  m/s
      ==
      ============================================================
      

      但是要留意,某些gps模块获取不到该字段的数据,需要将其对应修改匹配。

      至此,测试完毕。

      源码地址:
      https://download.csdn.net/download/qq_46079439/86272180
      原文链接:https://blog.csdn.net/qq_46079439/article/details/126122756

      posted in D1系列-RISC-V
      Y
      giao
    • Reply: 全志V853编译出现问题

      缺少一个命令,需要安装uboot-tools包

      posted in V853系列-AI视觉
      Y
      giao