一、简介
WCH的多款USB转单路/多路异步串口芯片,除串口接口以外,还提供独立的GPIO接口,各GPIO引脚支持独立的输出输入,GPIO功能的使用需要与计算机端厂商驱动程序和应用软件配合使用。各芯片的默认GPIO引脚状态有所区别,可查阅芯片技术手册或参考此方案链接附表。
型号 | CH344Q | CH344L | CH347T | CH348L | CH348Q | CH9101U/H |
USB | 480M高速 | 全速 | 480M高速 | 480M高速 | 480M高速 | 全速 |
GPIO数量 | 16 | 12 | 8 | 48 | 12 | 6 |
封装 | LQFP48 | LQFP48 | TSSOP20 | LQFP100 | LQFP48 | SSOP28/ QFN32 |
IO电压 | 3.3V | 3.3V | 3.3V | 3.3V/2.5V/1.8V | 3.3V | 5V/3.3V/ 2.5V/1.8V |
型号 | CH9101R/Y | CH9102F | CH9102X | CH9103M | CH9104L | CH9326G |
USB | 全速 | 全速 | 全速 | 全速 | 全速 | 全速 |
GPIO数量 | 4 | 5 | 6 | 12 | 24 | 4 |
封装 | QSOP16/QFN16 | QFN24 | QFN28 | QFN40 | LQFP48 | SOP16 |
IO电压 | 5V/3.3V/ 2.5V/1.8V | 5V/3.3V/ 2.5V/1.8V | 3.3V | 5V/3.3V/ 2.5V/1.8V | 3.3V | 5V/3.3V |
二、GPIO软件资源和支持型号
1、CH343SER Linux软件包
GitHub - WCHSoftGroup/ch343ser_linux: USB driver for USB to serial chip ch342, ch343, ch344, ch9101, ch9102, ch9103, etcUSB driver for USB to serial chip ch342, ch343, ch344, ch9101, ch9102, ch9103, etc - GitHub - WCHSoftGroup/ch343ser_linux: USB driver for USB to serial chip ch342, ch343, ch344, ch9101, ch9102, ch9103, etchttps://github.com/WCHSoftGroup/ch343ser_linux支持以下芯片型号的GPIO功能:
CH344Q/L、CH9101U/H/R/Y、CH9102F/X、CH9103M、CH9104L。
2、CH9344SER Linux软件包
GitHub - WCHSoftGroup/ch9344ser_linuxContribute to WCHSoftGroup/ch9344ser_linux development by creating an account on GitHub.https://github.com/WCHSoftGroup/ch9344ser_linux支持以下芯片型号的GPIO功能:
CH348L/Q、CH9344L
3、CH9326 Linux软件包
支持以下芯片型号的GPIO功能:
CH9326G
三、CH343SER Linux软件包使用说明
ch343ser_linux软件包包含如下3个部分:
driver:驱动软件
lib:应用库
demo:演示程序
1、编译安装驱动软件,可参考以下博客:
CH342/CH343/CH344/CH347/CH9101/CH9102/CH9103/CH9104 Linux串口驱动使用教程_PC技术小能手的博客-CSDN博客CH343 Linux串口驱动 ch343ser_linux 支持USB转串口芯片 ch342/ch343/ch344/ch347/ch9101/ch9102/ch9103/ch9104等 ,同时该驱动配合ch343_lib库还提供了芯片GPIO接口的读写功能,内部EEPROM的信息配置和读取功能等。CH344Q:16CH344L:12CH9102F:5CH9102X:6可以使用git clone下载该驱动,也可以点击网页下载压缩包文件。https://blog.csdn.net/WCH_TechGroup/article/details/132173723 该驱动软件会自动为GPIO硬件资源创建专用的字符设备节点:/dev/ch343_iodev*,这样应用软件可独立访问该节点以使用GPIO资源,而不占用串口tty设备节点。
2、编译gpio应用软件,可直接编译lib源文件和demo测试文件直接生成目标可执行文件,也可以将lib文件编译成动态库然后demo程序使用时链接此动态库。
1、拷贝lib目录下文件至demo文件夹内cp lib/ch343_lib* demo/2、cd进入demo文件夹,然后编译应用程序cd demogcc ch343_demo_gpio.c ch343_lib.c -o iotest
3、GPIO程序运行演示
程序默认操作USB设备的字符设备节点:/dev/ch343_iodev0,需要操作其他节点或设备可直接修改。演示程序打开设备后自动获取芯片型号和GPIO数量。
- 选项“g”:获取当前芯片的GPIO使能状态、方向设置、引脚电平状态
- 选项“o”:GPIO输出功能演示,按编号依次操作GPIO输出200ms的低电平,模拟跑马灯
- 选项“i”:获取当前芯片的GPIO引脚电平状态
4、编程接口说明
/*** libch343_open - open ch343 device* @devname: the device name to open** In this demo device is opened blocked, you could modify it at will.*/
extern int libch343_open(const char *devname);/*** libch343_close - close ch343 device* @fd: the device handle** The function return 0 if success, others if fail.*/
extern int libch343_close(int fd);/*** libch343_gpioinfo - get gpio status* @fd: file descriptor of ch343 device* @enablebits: pointer to gpio function enable bits, bits0-31 on gpio0-31, 1 on enable* @gpiodirbits: pointer to gpio direction bits, bits0-31 on gpio0-31, 1 on ouput, 0 on input* @gpioval: pointer to gpio input value, bits0-31 on gpio0-31, 1 on high, 0 on low** The function return 0 if success, others if fail.*/
extern int libch343_gpioinfo(int fd, uint32_t *enablebits, uint32_t *gpiodirbits, uint32_t *gpioval);/*** libch343_gpioenable - gpio enable* @fd: file descriptor of ch343 device* @enablebits: gpio function enable bits, 1 on enable* @gpiodirbits: gpio direction bits, 1 on ouput, 0 on input** The function return 0 if success, others if fail.*/
extern int libch343_gpioenable(int fd, uint32_t enablebits, uint32_t gpiodirbits);/*** libch343_gpioset - gpio output* @fd: file descriptor of ch343 device* @gpiobits: gpio valid bits, bits0-31 on gpio0-31, 1 on care, 0 on not* @gpiolevelbits: gpio output bits, bits0-31 on gpio0-31, 1 on high, 0 on low** The function return 0 if success, others if fail.*/
extern int libch343_gpioset(int fd, uint32_t gpiobits, uint32_t gpiolevelbits);/*** libch343_gpioget - get gpio input* @fd: file descriptor of ch343 device* @gpioval: pointer to gpio input value, bits0-31 on gpio0-31, 1 on high, 0 on low** The function return 0 if success, others if fail.*/
extern int libch343_gpioget(int fd, uint32_t *gpioval);/*** libch343_get_chiptype - get chip model* @fd: file descriptor of ch343 device* @type: pointer to chip model** The function return 0 if success, others if fail.*/
extern int libch343_get_chiptype(int fd, CHIPTYPE *type);/*** libch343_get_gpio_count - get gpio amounts of specific chip model* @chiptype: chip model** The function return value larger then 0 if success, -1 if fail.*/
extern int libch343_get_gpio_count(CHIPTYPE chiptype);
API接口函数说明
libch343_open:打开GPIO字符设备
libch343_close:关闭GPIO字符设备
libch343_gpioinfo:获取设备的GPIO状态信息
包括GPIO使能状态、GPIO方向位设定、GPIO电平状态
libch343_gpioenable:GPIO使能以及方向设置
libch343_gpioset:设置GPIO电平,输出高/低电平
参数gpiobits的BIT0~31对应GPIO0~GPIO31,1表示设置该GPIO,0表示不设置该GPIO;
参数gpiolevelbits的BIT0~31对应GPIO0~GPIO31,1表示控制该GPIO输出高电平,0表示控制该GPIO输出低电平;
libch343_gpioget:获取GPIO电平状态
参数gpioval的BIT0~31对应GPIO0~GPIO31,1表示该GPIO为高电平,0表示该GPIO为低电平;
API操作流程
四、默认GPIO引脚状态表
CH344Q | 编号 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
方向 | I | O | I | O | I | O | I | O | |
电平 | H | H | H | H | H | H | H | H | |
编号 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | |
方向 | O | O | O | O | I | I | I | I | |
电平 | H/L | H/L | H/L | H/L | H | H | H | H |
CH344L | 编号 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
方向 | I | O | I | O | I | O | I | O | |
电平 | H | H | H | H | H | H | H | H | |
编号 | 8 | 9 | 10 | 11 | |||||
方向 | O | O | O | O | |||||
电平 | H/L | H/L | H/L | H/L |
CH347T | 编号 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
方向 | I | O | I | I | I | O | I | O | |
电平 | H | H | H | H | H | H/L | H | H |
CH348L | 编号 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
方向 | I | O | I | O | I | O | I | O | |
电平 | H | H | H | H | H | H | H | H | |
编号 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | |
方向 | O | O | O | O | I | O | I | O | |
电平 | H | H/L | H | H/L | H | H | H | H | |
编号 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | |
方向 | I | O | I | O | O | O | O | O | |
电平 | H | H | H | H | H | H | H | H | |
编号 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | |
方向 | I | I | I | I | I | I | I | I | |
电平 | H | H | H | H | H | H | H | H | |
编号 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | |
方向 | I | I | I | I | I | I | I | I | |
电平 | H | H | H | H | H | H | H | H | |
编号 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | |
方向 | I | I | I | I | I | I | I | I | |
电平 | H | H | H | H | H | H | H | H |
CH348Q | 编号 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
方向 | I | O | I | O | I | O | I | O | |
电平 | H | H | H | H | H | H | H | H | |
编号 | 8 | 9 | 10 | 11 | |||||
方向 | O | O | O | O | |||||
电平 | H/L | H/L | H/L | H/L |
CH9101U/H | 编号 | 0 | 1 | 2 | 3 | 4 | 6 |
方向 | O | O | O | O | O | I | |
电平 | H | H | L | H/L | H/L | H |
CH9101R/Y | 编号 | 0 | 1 | 2 | 3 |
方向 | O | O | O | I | |
电平 | H | H | L | H |
CH9102F | 编号 | 0 | 1 | 2 | 3 | 4 |
方向 | O | O | O | I | I | |
电平 | H | H | L | H | H |
CH9102X | 编号 | 0 | 1 | 2 | 3 | 5 | 6 |
方向 | O | O | O | I | I | I | |
电平 | H | H | L | H | H | H |
CH9103M | 编号 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
方向 | I | I | I | I | I | O | I | O | |
电平 | H | H | H | H | H | H | H | H | |
编号 | 8 | 9 | 10 | 11 | |||||
方向 | O | O | O | O | |||||
电平 | H | H | L | L |
CH9104L | 编号 | 00 | 01 | 02 | 03 | 04 | 05 |
方向 | I | I | I | O | I | O | |
电平 | H | H | H | H | H | H/L | |
编号 | 10 | 11 | 12 | 13 | 14 | 15 | |
方向 | I | I | I | O | I | O | |
电平 | H | H | H | H | H | H/L | |
编号 | 20 | 21 | 22 | 23 | 24 | 25 | |
方向 | I | I | I | O | I | O | |
电平 | H | H | H | H | H | H/L | |
编号 | 30 | 31 | 32 | 33 | 34 | 35 | |
方向 | I | I | I | O | I | O | |
电平 | H | H | H | H | H | H/L |
CH9326G | 编号 | 0 | 1 | 2 | 3 |
方向 | I | I | I | I | |
电平 | H | H | H | H |