ARM Linux DIY(八)USB 调试

news2024/10/7 10:25:51

前言

V3s 带有一个 USB 接口,将其设置为 HOST 或 OTG 模式,这样可以用来接入键盘、鼠标等 USB 外设。

USB 简介

USB 有两种设备:HOST 和 USB 功能设备。
在 USB2.0 中又引入了一个新的概念 OTG,即设备角色可以动态切换。
切换方式一:硬件
使用 USB_ID 引脚,默认上拉,处于 device 状态。
如果需要 OTG 控制器进入 HOST 状态,需要外接的 USB 口将 USB_ID 短接到地。
切换方式二:设备树
设备树直接配置

&usb_otg {
        dr_mode = "otg"; /* 三个可选项: otg / host / peripheral */
        status = "okay";
};

切换方式三:手动修改 /sys
进入 Linux 系统,执行,usb 将会被设置成为 host 模式

echo host > /sys/devices/platform/soc/1c13000.usb/musb-hdrc.1.auto/mode

我们使用硬件方式切换

硬件

USB 电路简单,只有两根线 D+、D-,器件也简单,就一个 USB 母座,甚至连电阻电容都不需要,其它外设如果也能像 USB 这样就好了。😊😊😊
焊接就很简单了,就一个 USB 母座,我使用的是 Type C 母座
请添加图片描述

设备树

arch/arm/boot/dts/sun8i-v3s-licheepi-zero.dts


/ {
    soc {
        // 增加 ehci0 (usb2.0)、ohci0 (usb1.1) 这两个节点
        ehci0: usb@01c1a000 {
            compatible = "allwinner,sun8i-v3s-ehci", "generic-ehci";
            reg = <0x01c1a000 0x100>;
            interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
            clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>;
            resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
            status = "okay";
        };

        ohci0: usb@01c1a400 {
            compatible = "allwinner,sun8i-v3s-ohci", "generic-ohci";
            reg = <0x01c1a400 0x100>;
            interrupts = <GIC_SPI 73 IRQ_TYPE_LEVEL_HIGH>;
            clocks = <&ccu CLK_BUS_EHCI0>, <&ccu CLK_BUS_OHCI0>,
            <&ccu CLK_USB_OHCI0>;
            resets = <&ccu RST_BUS_EHCI0>, <&ccu RST_BUS_OHCI0>;
            status = "okay";
        };
    };
};

&usb_otg {
	dr_mode = "otg";
	status = "okay";
};

&usbphy {
	usb0_id_det-gpios = <&pio 5 6 GPIO_ACTIVE_HIGH>;
	status = "okay";
};

调试

# lsusb 
Bus 003 Device 001: ID 1d6b:0002
Bus 001 Device 001: ID 1d6b:0002
Bus 002 Device 001: ID 1d6b:0001

插入键盘

# 
[   64.047789] usb 2-1: USB disconnect, device number 2
[   69.109743] usb 2-1: new full-speed USB device number 3 using ohci-platform
[   69.410757] usbhid 2-1:1.0: can't add hid device: -71
[   69.417442] usbhid: probe of 2-1:1.0 failed with error -71
[   69.438942] input: Gaming KB  System Control as /devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.1/0003:258A:1006.0001/input/input1
[   69.520323] input: Gaming KB  Consumer Control as /devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.1/0003:258A:1006.0001/input/input2
[   69.536532] input: Gaming KB  Keyboard as /devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.1/0003:258A:1006.0001/input/input3
[   69.558009] hid-generic 0003:258A:1006.0001: input: USB HID v1.11 Keyboard [Gaming KB ] on usb-1c1a400.usb-1/input1
[   71.259791] usb 2-1: reset full-speed USB device number 3 using ohci-platform
[   73.019839] usb 2-1: reset full-speed USB device number 3 using ohci-platform
[   74.999799] usb 2-1: reset full-speed USB device number 3 using ohci-platform
[   76.809912] usb 2-1: reset full-speed USB device number 3 using ohci-platform
[   77.469746] usb 2-1: device not accepting address 3, error -62
[   77.679753] usb 2-1: reset full-speed USB device number 3 using ohci-platform
[   79.639774] usb 2-1: reset full-speed USB device number 3 using ohci-platform
[   81.230445] usb 2-1: reset full-speed USB device number 3 using ohci-platform
[   83.079769] usb 2-1: reset full-speed USB device number 3 using ohci-platform
[   85.079781] usb 2-1: reset full-speed USB device number 3 using ohci-platform
[   85.354764] usb 2-1: device descriptor read/all, error -71
[   85.569730] usb 2-1: reset full-speed USB device number 3 using ohci-platform

报错 usb 2-1: device descriptor read/all, error -71
拔插一次

# 
[  207.536060] usb 2-1: USB disconnect, device number 3
[  210.899724] usb 2-1: new full-speed USB device number 4 using ohci-platform
[  211.196755] usbhid 2-1:1.0: can't add hid device: -62
[  211.203540] usbhid: probe of 2-1:1.0 failed with error -62
[  211.231919] input: Gaming KB  Gaming KB  System Control as /devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.1/0003:258A:1006.0002/input/input4
[  211.310302] input: Gaming KB  Gaming KB  Consumer Control as /devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.1/0003:258A:1006.0002/input/input5
[  211.327496] input: Gaming KB  Gaming KB  Keyboard as /devices/platform/soc/1c1a400.usb/usb2/2-1/2-1:1.1/0003:258A:1006.0002/input/input6
[  211.359852] hid-generic 0003:258A:1006.0002: input: USB HID v1.11 Keyboard [Gaming KB  Gaming KB ] on usb-1c1a400.usb-1/input1

还是报错 usbhid: probe of 2-1:1.0 failed with error -62

# ls /dev/input/ -lh
total 0      
crw-------    1 root     root       13,  64 Jan  1 00:00 event0
crw-------    1 root     root       13,  65 Jan  1 00:03 event1 // 键盘
crw-------    1 root     root       13,  66 Jan  1 00:03 event2 // 键盘
crw-------    1 root     root       13,  67 Jan  1 00:03 event3 // 键盘

/dev/input 目录下虽然产生了键盘对应的 event 设备,但是监听这些设备,按下键盘,没有任何反应

# hexdump /dev/input/event1

# hexdump /dev/input/event2

# hexdump /dev/input/event3

起初怀疑是供电不足,于是使用一个电源适配器专门给 HUB 供电,还是报错。
又怀疑是 1 拖 4 的 USB HUB 质量不好,或者耗电太大,于是又买了个 1 拖 1 的 USB HUB(其实不能算是 HUB,应该只能算是 Type C 转 Type A 转换器),结果还是报错。
还怀疑是 USB_ID 引脚没有下拉,于是飞线到 GND 进行下拉,还是报错。
就这样调试了两天未果,最终从《USB 为什么一般选择48MHz》 这篇文章中找到了线索,

USB 的系统时钟需要时 bitrate 的 4 倍, 如低速 USB,传输速率是 1.5Mbps, 系统时钟需要选择为1.5*4 == 6Mhz,全速 usb 12MHz * 4 == 48Mhz

想到我使用的晶振是 26MHz,不是 4 的整数倍,难道是这个原因?
将晶振从 26MHz 换成了 24MHz,相应地,uboot 和 kernel dts 也修改成 24MHz,上电测试竟然还真的正常了。

测试

插入 USB HUB
请添加图片描述

# 
[  290.679671] usb 1-1: new high-speed USB device number 2 using ehci-platform
[  290.881127] hub 1-1:1.0: USB hub found
[  290.886219] hub 1-1:1.0: 4 ports detected

# lsusb 
Bus 003 Device 001: ID 1d6b:0002
Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 002: ID 1a40:0101 // USB HUB
Bus 002 Device 001: ID 1d6b:0001

插入键盘

# 
[  587.679662] usb 1-1.1: new full-speed USB device number 3 using ehci-platform
[  587.936322] input: Gaming KB  Gaming KB  as /devices/platform/soc/1c1a000.usb/usb1/1-1/1-1.1/1-1.1:1.0/0003:258A:1006.0001/input/input1
[  588.020368] hid-generic 0003:258A:1006.0001: input: USB HID v1.11 Keyboard [Gaming KB  Gaming KB ] on usb-1c1a000.usb-1.1/input0
[  588.049607] input: Gaming KB  Gaming KB  System Control as /devices/platform/soc/1c1a000.usb/usb1/1-1/1-1.1/1-1.1:1.1/0003:258A:1006.0002/input/input2
[  588.130279] input: Gaming KB  Gaming KB  Consumer Control as /devices/platform/soc/1c1a000.usb/usb1/1-1/1-1.1/1-1.1:1.1/0003:258A:1006.0002/input/input3
[  588.147663] input: Gaming KB  Gaming KB  Keyboard as /devices/platform/soc/1c1a000.usb/usb1/1-1/1-1.1/1-1.1:1.1/0003:258A:1006.0002/input/input4
[  588.170084] hid-generic 0003:258A:1006.0002: input: USB HID v1.11 Keyboard [Gaming KB  Gaming KB ] on usb-1c1a000.usb-1.1/input1

# lsusb 
Bus 003 Device 001: ID 1d6b:0002
Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 003: ID 258a:1006 // 键盘
Bus 001 Device 002: ID 1a40:0101
Bus 002 Device 001: ID 1d6b:0001

# ls /dev/input/ -lh
total 0      
crw-------    1 root     root       13,  64 Jan  1 00:00 event0
crw-------    1 root     root       13,  65 Jan  1 02:04 event1 // 键盘
crw-------    1 root     root       13,  66 Jan  1 02:04 event2 // 键盘
crw-------    1 root     root       13,  67 Jan  1 02:04 event3 // 键盘
crw-------    1 root     root       13,  68 Jan  1 02:04 event4 // 键盘

监听键盘按键

# hexdump /dev/input/event1
0000000 1dbd 0000 9338 0007 0004 0004 000b 0007
0000010 1dbd 0000 9338 0007 0001 0023 0001 0000
0000020 1dbd 0000 9338 0007 0000 0000 0000 0000
0000030 1dbd 0000 eaec 0008 0004 0004 000b 0007
0000040 1dbd 0000 eaec 0008 0001 0023 0000 0000
0000050 1dbd 0000 eaec 0008 0000 0000 0000 0000
0000060 1dbe 0000 01b8 0000 0004 0004 0009 0007
0000070 1dbe 0000 01b8 0000 0001 0021 0001 0000
0000080 1dbe 0000 01b8 0000 0000 0000 0000 0000
0000090 1dbe 0000 1ae3 0001 0004 0004 0009 0007
00000a0 1dbe 0000 1ae3 0001 0001 0021 0000 0000
00000b0 1dbe 0000 1ae3 0001 0000 0000 0000 0000
00000c0 1dbe 0000 d8e5 000b 0004 0004 0015 0007
00000d0 1dbe 0000 d8e5 000b 0001 0013 0001 0000
00000e0 1dbe 0000 d8e5 000b 0000 0000 0000 0000
00000f0 1dbe 0000 8e63 000d 0004 0004 0015 0007
0000100 1dbe 0000 8e63 000d 0001 0013 0000 0000
0000110 1dbe 0000 8e63 000d 0000 0000 0000 0000

插入鼠标

# 
[  806.739667] usb 1-1.4: new full-speed USB device number 4 using ehci-platform
[  806.996984] input: Logitech G102 Prodigy Gaming Mouse as /devices/platform/soc/1c1a000.usb/usb1/1-1/1-1.4/1-1.4:1.0/0003:046D:C084.0003/input/input5
[  807.022588] hid-generic 0003:046D:C084.0003: input: USB HID v1.11 Mouse [Logitech G102 Prodigy Gaming Mouse] on usb-1c1a000.usb-1.4/input0
[  807.067548] input: Logitech G102 Prodigy Gaming Mouse Keyboard as /devices/platform/soc/1c1a000.usb/usb1/1-1/1-1.4/1-1.4:1.1/0003:046D:C084.0004/input/input6
[  807.150288] input: Logitech G102 Prodigy Gaming Mouse Consumer Control as /devices/platform/soc/1c1a000.usb/usb1/1-1/1-1.4/1-1.4:1.1/0003:046D:C084.0004/input/input7
[  807.168723] input: Logitech G102 Prodigy Gaming Mouse System Control as /devices/platform/soc/1c1a000.usb/usb1/1-1/1-1.4/1-1.4:1.1/0003:046D:C084.0004/input/input8
[  807.193232] hid-generic 0003:046D:C084.0004: input: USB HID v1.11 Keyboard [Logitech G102 Prodigy Gaming Mouse] on usb-1c1a000.usb-1.4/input1

# lsusb 
Bus 003 Device 001: ID 1d6b:0002
Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 003: ID 258a:1006
Bus 001 Device 002: ID 1a40:0101
Bus 002 Device 001: ID 1d6b:0001
Bus 001 Device 004: ID 046d:c084 // 鼠标

# ls /dev/input/ -lh
total 0      
crw-------    1 root     root       13,  64 Jan  1 00:00 event0
crw-------    1 root     root       13,  65 Jan  1 02:04 event1
crw-------    1 root     root       13,  66 Jan  1 02:04 event2
crw-------    1 root     root       13,  67 Jan  1 02:04 event3
crw-------    1 root     root       13,  68 Jan  1 02:04 event4
crw-------    1 root     root       13,  69 Jan  1 02:08 event5 // 鼠标
crw-------    1 root     root       13,  70 Jan  1 02:08 event6 // 鼠标
crw-------    1 root     root       13,  71 Jan  1 02:08 event7 // 鼠标
crw-------    1 root     root       13,  72 Jan  1 02:08 event8 // 鼠标

监听鼠标移动、点击

# hexdump /dev/input/event5
0000000 1e91 0000 9be6 000e 0002 0000 0001 0000
0000010 1e91 0000 9be6 000e 0000 0000 0000 0000
0000020 1e91 0000 befd 000e 0002 0000 0001 0000
0000030 1e91 0000 befd 000e 0000 0000 0000 0000
0000040 1e91 0000 caa5 000e 0002 0001 0001 0000
0000050 1e91 0000 caa5 000e 0000 0000 0000 0000
0000060 1e92 0000 3dfc 0001 0002 0000 0001 0000
0000070 1e92 0000 3dfc 0001 0000 0000 0000 0000
0000080 1e93 0000 cb9d 0008 0002 0000 0001 0000
0000090 1e93 0000 cb9d 0008 0000 0000 0000 0000
00000a0 1e93 0000 15c0 0009 0002 0000 0001 0000
00000b0 1e93 0000 15c0 0009 0000 0000 0000 0000
00000c0 1e93 0000 f24a 000a 0002 0000 0001 0000
00000d0 1e93 0000 f24a 000a 0000 0000 0000 0000
00000e0 1e93 0000 1950 000b 0002 0000 0001 0000
00000f0 1e93 0000 1950 000b 0000 0000 0000 0000
0000100 1e93 0000 3c95 000b 0002 0000 0001 0000
0000110 1e93 0000 3c95 000b 0000 0000 0000 0000
0000120 1e93 0000 5bc9 000b 0002 0000 0001 0000
0000130 1e93 0000 5bc9 000b 0000 0000 0000 0000
0000140 1e93 0000 7afe 000b 0002 0000 0001 0000
0000150 1e93 0000 7afe 000b 0000 0000 0000 0000
0000160 1e96 0000 5793 0000 0004 0004 0001 0009
0000170 1e96 0000 5793 0000 0001 0110 0001 0000
0000180 1e96 0000 5793 0000 0000 0000 0000 0000
0000190 1e96 0000 3fd6 0002 0004 0004 0001 0009
00001a0 1e96 0000 3fd6 0002 0001 0110 0000 0000
00001b0 1e96 0000 3fd6 0002 0000 0000 0000 0000
00001c0 1e96 0000 e13b 0007 0004 0004 0002 0009
00001d0 1e96 0000 e13b 0007 0001 0111 0001 0000
00001e0 1e96 0000 e13b 0007 0000 0000 0000 0000
00001f0 1e96 0000 d35f 0008 0004 0004 0002 0009
0000200 1e96 0000 d35f 0008 0001 0111 0000 0000
0000210 1e96 0000 d35f 0008 0000 0000 0000 0000
0000220 1e96 0000 3cce 0009 0004 0004 0002 0009
0000230 1e96 0000 3cce 0009 0001 0111 0001 0000
0000240 1e96 0000 3cce 0009 0000 0000 0000 0000
0000250 1e96 0000 ae11 0009 0004 0004 0002 0009
0000260 1e96 0000 ae11 0009 0001 0111 0000 0000
0000270 1e96 0000 ae11 0009 0000 0000 0000 0000

至此,USB 调试 OK

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1004886.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

关系的定义及表示

关系的定义及表示 1、若集合R是AA的子集&#xff0c;则称R是集合A上的二元关系&#xff0c;简称关系 例&#xff1a;A{1,2}&#xff0c; AA{<1,1>,<1,2>,<2,1>,<2,2>}&#xff0c;AA的任何一个子集都是A上的关系 如&#xff1a; R{<1,1>, &…

B+Tree 索引结构

文章目录 1. 数据库索引2. BTree 索引结构 1. 数据库索引 索引是为了提高数据的查询速度&#xff0c;相当于给数据进行编号&#xff0c;在查找数据的时候就可以通过编号快速找到对应的数据。索引用的是 B Tree 数据结构。 乱序插入数据&#xff0c;会自动按照 id 进行升序排…

做题(1)

1.fileinclude 打开 发现提示flag在flag.php里边 查看页面源代码 $lan $_COOKIE[language]; 这句话是关键 变量lan是用cookie传参的 include("english.php"); 这句话表明了文件包含 include函数用php伪协议 filer绕过 include($lan.".php"); 这句话…

AI项目六:WEB端部署YOLOv5

若该文为原创文章&#xff0c;转载请注明原文出处。 一、介绍 最近接触网页大屏&#xff0c;所以就想把YOLOV5部署到WEB端&#xff0c;通过了解&#xff0c;知道了两个方法&#xff1a; 1、基于Flask部署YOLOv5目标检测模型。 2、基于Streamlit部署YOLOv5目标检测。 代码在…

Trinitycore学习之在vscode查看远端服务器上源码配置

1&#xff1a;安装vscode&#xff0c;去官网下载&#xff0c;这里下载windows版本安装包 .zip https://code.visualstudio.com/Download 2&#xff1a;安装后&#xff0c;安装扩展chinese&#xff0c;使用中文设置&#xff0c;需要重启vscode。 3&#xff1a;安装ssh相关插件…

C++设计模式_05_Observer 观察者模式

接上篇&#xff0c;本篇将会介绍C设计模式中的Observer 观察者模式&#xff0c;和前2篇模板方法Template Method及Strategy 策略模式一样&#xff0c;仍属于“组件协作”模式。Observer 在某些领域也叫做 Event 。 文章目录 1. 动机&#xff08; Motivation&#xff09;2. 代码…

Thonny安装教程

软件简介 Thonny —— 一个面向初学者的 Python IDE Thonny 由爱沙尼亚的 Tartu 大学开发&#xff0c;它采用了不同的方法&#xff0c;因为它的调试器是专为学习和教学编程而设计的。 下载&安装Thonny 下载地址 打开安装包&#xff0c;进入安装界面&#xff0c;一路Ne…

【每日一题】445. 两数相加 II

给你两个 非空 链表来代表两个非负整数。数字最高位位于链表开始位置。它们的每个节点只存储一位数字。将这两数相加会返回一个新的链表。 你可以假设除了数字 0 之外&#xff0c;这两个数字都不会以零开头。 示例1&#xff1a; 输入&#xff1a;l1 [7,2,4,3], l2 [5,6,4] 输…

电池电动汽车的健康状态 SOH 和充电状态 SOC 估计

完整程序请查看博主主页置顶博客&#xff08;专享优惠&#xff09; 主要内容&#xff1a; 健康状态 SOH采用平均加权最小二乘法&#xff08;AWTLS&#xff09;进行估计&#xff0c;并对比了加权最小二乘 &#xff08;WLS&#xff09;、总最小二乘法&#xff08;TLS&#xff0…

SQL7 查找年龄大于24岁的用户信息

描述 题目&#xff1a;现在运营想要针对24岁以上的用户开展分析&#xff0c;请你取出满足条件的设备ID、性别、年龄、学校。 用户信息表&#xff1a;user_profile iddevice_idgenderageuniversityprovince12138male21北京大学Beijing23214male复旦大学Shanghai36543female20…

GE IS215UCVGM06A IS215UCVGH1A VMIVME-7666-111000燃机模块

数据采集和监测&#xff1a;燃机模块通常具有广泛的数据采集功能&#xff0c;用于监测燃机的性能参数&#xff0c;如温度、压力、振动等。这些数据有助于运营人员实时监测燃机状态。 控制功能&#xff1a;这些模块通常包括控制逻辑和算法&#xff0c;用于管理燃机的启停、负荷…

山东大学图书馆《乡村振兴战略下传统村落文化旅游设计》许少辉八一新著

山东大学图书馆《乡村振兴战略下传统村落文化旅游设计》许少辉八一新著

2023年中国光伏行业研究报告

第一章 行业概况 1.1 定义 光伏行业&#xff0c;也称为太阳能光伏行业&#xff0c;是一个专注于利用光伏技术将太阳能转化为电能的领域。该行业涵盖了太阳能电池的制造、光伏系统的设计、安装和维护&#xff0c;以及电能的销售和供应。光伏技术的核心是光伏效应&#xff0c;通…

这家酒店,管理方式太out了!换个风格后绝了!

在酒店业&#xff0c;我们追求的不仅仅是舒适和奢华&#xff0c;还包括客人的安全与健康。然而&#xff0c;火灾风险是无论在何处都不可忽视的潜在威胁。每年&#xff0c;全球范围内数以千计的火灾事件发生&#xff0c;不仅造成了巨大的财产损失&#xff0c;还可能威胁到人们的…

mysql查所有下级

//向下递归包含本级 WITH RECURSIVE cte AS (SELECT * FROM live_usr_config WHERE supid"lNy5ZNI3WZ3QXSopb0mdr"UNION ALLSELECT d.* FROM live_usr_config d INNER JOIN cte ON d.supid cte.subid ) SELECT * FROM cte;//向下递归包含本级并限制次数为下两层 W…

Mathpix替代者|科研人必备公式识别插件|latexocr安装教程

首先是安装好python、然后直接用命令调用 文章目录 1、安装步骤2、使用步骤 1、安装步骤 也可以安装精简版的python 准备 Python 环境&#xff0c;安装python的步骤可以查看我的上一篇博文&#xff1a; Anaconda最新版2023安装教程Spyder安装教程 确保你的计算机已经安装了 P…

大数据课程L7——网站流量项目的操作步骤

文章作者邮箱:yugongshiye@sina.cn 地址:广东惠州 ▲ 本章节目的 ⚪ 了解网站流量项目的Spark与HBase整合; ⚪ 掌握网站流量项目的实时流业务处理; 一、 Spark 与 HBase 整合基础 1. 实现步骤: 1. 启动 IDEA。 2. 创建 Maven 工程,骨架选择 quickstar…

2023/09/12 qtc++

实现一个图形类(Shape) &#xff0c;包含受保护成员属性:周长、面积&#xff0c; 公共成员函数:特殊成员函数书写 定义一个圆形类(Circle) &#xff0c;继承自图形类&#xff0c;包含私有属性:半径 公共成员函数:特殊成员函数…

使用Langchain+GPT+向量数据库chromadb 来创建文档对话机器人

使用LangchainGPT向量数据库chromadb 来创建文档对话机器人 一.效果图如下&#xff1a; 二.安装包 pip install langchainpip install chromadbpip install unstructuredpip install jieba三.代码如下 #!/usr/bin/python # -*- coding: UTF-8 -*-import os # 导入os模块&…

59-代码随想录--数组--螺旋矩阵

力扣&#xff08;LeetCode&#xff09;官网 - 全球极客挚爱的技术成长平台 给定一个正整数 n&#xff0c;生成一个包含 1 到 n^2 所有元素&#xff0c;且元素按顺时针顺序螺旋排列的正方形矩阵。 示例: 输入: 3 输出: [ [ 1, 2, 3 ], [ 8, 9, 4 ], [ 7, 6, 5 ] ] 模拟顺时针…