树莓派支持鼠标和LCD(TODO)

这个工作量比较大,估计要晚一些搞了。。。

安装树莓派 Pico 的 C/C++ SDK

git clone https://github.com/hathach/tinyusb.git

CMakeList.txt

复制代码

cmake_minimum_required(VERSION 3.13)

include(pico_sdk_import.cmake)

project(usb_host_mouse_example)

pico_sdk_init()

add_executable(usb_host_mouse_example

main.c

)

# 添加对 TinyUSB 的支持

add_subdirectory(tinyusb)

target_link_libraries(usb_host_mouse_example pico_stdlib tinyusb_host)

pico_add_extra_outputs(usb_host_mouse_example)

main.c

#include "pico/stdlib.h"

#include "bsp/board.h"

#include "tusb.h"

// USB HID 鼠标回调函数

void tuh_hid_mouse_mounted_cb(uint8_t dev_addr) {

printf("A USB mouse is mounted.\n");

}

void tuh_hid_mouse_unmounted_cb(uint8_t dev_addr) {

printf("A USB mouse is unmounted.\n");

}

void tuh_hid_mouse_isr(uint8_t dev_addr, uint8_t instance, const uint8_t* report, uint16_t len) {

// 解析鼠标报告

int8_t x = report[1];

int8_t y = report[2];

int8_t wheel = report[3];

printf("Mouse movement: x=%d, y=%d, wheel=%d\n", x, y, wheel);

}

int main() {

// 初始化板子和 USB 主机

board_init();

tusb_init();

while (true) {

// 处理 USB 事件

tuh_task();

}

return 0;

}

复制代码

mkdir build

cd build

cmake ..

make

生成的 usb_host_mouse_example.uf2 文件拖放到树莓派 Pico 的 USB 驱动器中,完成固件上传。

相关推荐
ACP广源盛139246256731 小时前
GSV2712@ACP#2 进 1 出 HDMI 2.0/Type-C DisplayPort 1.4 混合切换器 + 嵌入式 MCU
单片机·嵌入式硬件·计算机外设·音视频
Terasic友晶科技4 小时前
DE10-Nano的HDMI方块移动案例——显示器时序(DMT)标准介绍
fpga开发·计算机外设·hdmi·显示器时序·dmt
多情刀客无情刀6 小时前
键盘上怎么打箭头符号
计算机外设
AomanHao1 天前
【随笔】CIY68-DIY机械键盘维修小记
计算机外设·随笔·机械键盘
Morgana_Mo1 天前
iOS_输入框键盘跟随最佳实践
ios·计算机外设·cocoa
PhoenixAI83 天前
显示器共享多主机切换的软件解决方案
计算机外设·显示器
Z***G4794 天前
网络爬虫学习:借助DeepSeek完善爬虫软件,实现模拟鼠标右键点击,将链接另存为本地文件
爬虫·学习·计算机外设
啃火龙果的兔子5 天前
客户端频繁调用webview方法导致前端react副作用执行异常
计算机外设·交互
4***72135 天前
网络爬虫学习:借助DeepSeek完善爬虫软件,实现模拟鼠标右键点击,将链接另存为本地文件
爬虫·学习·计算机外设
S9037845976 天前
为什么取模在除数等于2^n的时候可以用按位与替代?
java·tomcat·计算机外设·hibernate