wiringPi_Blueberry/README.md
liuls2002 359f5f9b7e doc
2023-08-11 16:58:15 +08:00

298 lines
6.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

### 说明
本仓库是将 wiringOP 移植到 MangoPi(H616) 上。需要使用 Orange Pi Zero2的对应的系统镜像。
### 下载
```bash
apt-get update
apt-get install -y git
git clone https://github.com/liuls2002/wiringOP-for-MangoPi-H616.git
```
#### 编译安装
```bash
cd wiringOP
./build clean
./build
```
### Python版本
```bash
# 下载 orangepi 提供的代码
git clone --recursive https://github.com/orangepi-xunlong/wiringOP-Python.git
cd wiringOP-Python
# 使用本工程中的代码替换 wiringOP-Python 目录下的 wiringOP
cp -r ./wiringOP ./wiringOP-Python
# 安装tools
sudo apt-get install swig python3-dev python3-setuptools
# Build & install with
python3 generate-bindings.py > bindings.i
sudo python3 setup.py install
```
### Mango Pi的官方网站
[Mango Pi official website | Tiny and Elegant SBC | mqquad](https://mangopi.org/mqquad)
---
### 相较于 Orange Pi 提供的代码的改动
Mango Pi(h616) 与 Orange Pi Zero2 使用相同的soc全志H616所以基于 Orange Pi Zero2 进行移植修改比较方便。
Mango Pi(h616) 引脚对应关系如下:
<img src=".\imgs\pins.png" alt="pins" style="zoom:60%;" />
总共有3种编号board引脚编号芯片引脚编号逻辑引脚编号。控制gpio时一般采用逻辑引脚编号。
==我们需要修改这3者的映射关系。为了简便我将逻辑引脚编号与board的引脚编号保持一致使用时需要注意。==
#### 1 修改 gpio/OrangPi.c
将`#ifdef CONFIG_ORANGEPI_ZERO2`包含的代码替换为如下代码:
```c
#ifdef CONFIG_ORANGEPI_ZERO2
int pinToGpioOrangePi [64] =
{
-1, // 0
-1 , -1 ,
264 , -1 ,
263 , -1 ,
256 , 224 ,
-1 , 225 ,
226 , 257 ,
227 , -1 ,
269 , 270 ,
-1 , 228 ,
231 , -1 ,
232 , 262 ,
230 , 229 ,
-1 , 233 ,
266 , 265 ,
267 , -1 ,
268 , 261 ,
271 , -1 ,
258 , 234 ,
272 , 260 ,
-1 , 259 , // 40
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1,-1, // 63
};
int physToWpi[64] =
{
-1, // 0
-1, -1, // 1, 2
3, -1, //3, 4
5, -1, //5, 6
7, 8, //7, 8
-1, 10, //9,10
11, 12, //11,12
13, -1, //13,14
15, 16, //15,16
-1, 18, //17,18
19, -1, //19,20
21, 22, //21,22
23, 24, //23, 24
-1, 26, // 25, 26
27, 28, //27, 28
29, -1, //29, 30
31, 32, //31, 32
33, -1, //33, 34
35, 36, //35, 36
37, 38, //37, 38
-1, 40, //39, 40
// Padding:
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 56
-1, -1, -1, -1, -1, -1, -1, // ... 63
};
char *physNames[64] =
{
NULL,
" 3.3V", "5V ",
" TWI1_SDA", "5V ",
" TWI1_SCL", "GND ",
"I2S0_MCLK", "TX0",
" GND", "RX0",
" TX5", "I2S_CLK",
" RX5", "GND ",
" TX4/PWM3", "RX4/PWM4",
" 3.3V", "PH4",
"SPI1_MOSI", "GND ",
"SPI1_MISO", "RX2",
" SPI1_CLK", "SPI1_CS0 ",
" GND", "SPI1_CS1",
" TWI2_SDA", "TWI2_SCL",
" PI11", "GND ",
" PI12", "LEDC/TX2",
" PI15", "GND ",
"I2S0_LRCK", "PH10",
" PI16", "I2S0_DOUT",
" GND", "I2S0_DIN",
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
};
#endif
```
替换 `void OrangePiReadAll(void)`函数中的部分代码
```c
// 替换前
#elif CONFIG_ORANGEPI_ZERO2
for (pin = 1 ; pin <= 34; pin += 2) // orangepi zero2 引出34pin
// 替换后
#elif CONFIG_ORANGEPI_ZERO2
for (pin = 1 ; pin <= 40; pin += 2) // mangopi 引出40pin
```
#### 2 修改 wiringPi/OrangePi.c
将`#ifdef CONFIG_ORANGEPI_ZERO2`包含的代码替换为如下代码:
```c
#ifdef CONFIG_ORANGEPI_ZERO2
int pinToGpioOrangePi [64] =
{
-1, // 0
-1 , -1 ,
264 , -1 ,
263 , -1 ,
256 , 224 ,
-1 , 225 ,
226 , 257 ,
227 , -1 ,
269 , 270 ,
-1 , 228 ,
231 , -1 ,
232 , 262 ,
230 , 229 ,
-1 , 233 ,
266 , 265 ,
267 , -1 ,
268 , 261 ,
271 , -1 ,
258 , 234 ,
272 , 260 ,
-1 , 259 , // 40
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, // 63
};
int physToGpioOrangePi [64] =
{
-1, // 0
-1 , -1 ,
264 , -1 ,
263 , -1 ,
256 , 224 ,
-1 , 225 ,
226 , 257 ,
227 , -1 ,
269 , 270 ,
-1 , 228 ,
231 , -1 ,
232 , 262 ,
230 , 229 ,
-1 , 233 ,
266 , 265 ,
267 , -1 ,
268 , 261 ,
271 , -1 ,
258 , 234 ,
272 , 260 ,
-1 , 259 , // 40
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, // 63
} ;
int physToPinOrangePi [64] =
{
-1, // 0
-1, -1, // 1, 2
3, -1, //3, 4
5, -1, //5, 6
7, 8, //7, 8
-1, 10, //9,10
11, 12, //11,12
13, -1, //13,14
15, 16, //15,16
-1, 18, //17,18
19, -1, //19,20
21, 22, //21,22
23, 24, //23, 24
-1, 26, // 25, 26
27, 28, //27, 28
29, -1, //29, 30
31, 32, //31, 32
33, -1, //33, 34
35, 36, //35, 36
37, 38, //37, 38
-1, 40, //39, 40
// Padding:
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //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