迷你看门狗
(→PIN Macro) |
(→GPIO) |
||
| 第284行: | 第284行: | ||
==== gpio_output_set ==== | ==== gpio_output_set ==== | ||
| + | gpio_output_set(u32 set_mask, u32 clear_mask, u32 enable_mask, u32 disable_mask) | ||
| + | |||
| + | * set_mask: 设置输出为高的位,对应位为 1 输出高,对应位为 0 不改变状态 | ||
| + | * clear_mask: 设置输出为低的位,对应位为 1 输出低,对应位为 0 不改变状态 | ||
| + | * enable_mask: 设置使能输出的位 | ||
| + | * disable_mask: 设置使能输入的位 | ||
<br><br> | <br><br> | ||
2014年12月12日 (五) 15:18的版本
目录 |
1 主控SoC
1.1 概述
- Tensilica Xtensa LX3 32-bit RISC SOC clocked at 80 MHz
- 32-bit ALU
- 16, 32 or 64 GPR
- six special purpose registers
- 80 base instructions
The Xtensa ISA employs 24-bit instructions with 16-bit narrow encodings for the most common instructions.
1.2 管脚定义
1.3 Toolchain
2 基本布局
一个蓝色高亮 LED,接着 UTXD 上
一颗 12V 电池
一个 SPI Flash
一颗 8266
重启拔电池即可
官方参考设计:
3 Web Server API
3.1 client info
$ curl -X GET http://192.168.1.112/client?command=info {
"Version":{
"hardware":"0.3",
"software":"0.9.3"
},
"Device":{
"product":"Humiture",
"manufacturer":"Espressif Systems"
}
}
3.2 client status
$ curl -X GET http://192.168.1.112/client?command=status
{
"Status":{
"status":40
}
}
3.3 client scan
$ curl -X GET http://192.168.1.112/client?command=scan
{
"Response":{
"TotalPage":2
}
}
3.4 config wifi
$ curl -X GET http://192.168.1.112/config?command=wifi
{
"Response":{
"Station":{
"Connect_Station":{
"ssid":"HOME-WIFI",
"password":"xxxxxxxx"
},
"Ipinfo_Station":{
"ip":"192.168.1.112",
"mask":"255.255.255.0",
"gw":"192.168.1.1"
}
},
"Softap":{
"Connect_Softap":{
"authmode":"OPEN",
"channel":11,
"ssid":"ESP_9CCF90",
"password":""
},
"Ipinfo_Softap":{
"ip":"192.168.4.1",
"mask":"255.255.255.0",
"gw":"192.168.4.1"
}
}
}
3.5 config switch
$ curl -X GET http://192.168.1.112/config?command=switch
{
"Response":{
"status":0
}
}
3.6 config light
$ curl -X GET http://192.168.1.112/config?command=light
{
"freq":0,
"rgb":{
"red":0,
"green":0,
"blue":0
}
}
3.7 config reboot
$ curl -X GET http://192.168.1.112/config?command=reboot
3.8 config sleep
$ curl -X POST http://192.168.1.112/config?command=sleep
3.9 设置 station 模式
设备默认为softAP模式,设置 station 模式需先用PC或手机 WiFi 连接到设备,然后从手机或PC端发送下述指令:
$ curl -X POST -H "Content-Type:application/json" -d '{"Request":{"Station":
{"Connect_Station":{"ssid":"comcat","password":"12345678"}}}}' http://192.168.1.112/config?command=wifi
设置完成后设备自动重启,进入station 模式,并自动去连接所设置的路由
注:token 字段和espressif 服务器架构相关,是随机的长度为40 的
3.10 设置 softAP 模式
设备发送如下指令,从 station 模式切回 softAP 模式:
$ curl -X POST -H "Content-Type:application/json" -d ' \
{"Request":{"Softap":{"Connect_Softap":{"authmode":"OPEN","channel":6,"ssid":"mini-CamGo","password":""}}}}' \
http://192.168.10.213/config?command=wifi
注意:
- Authmode 支持OPEN、WPAPSK、WPA2PSK、WPAPSK/WPA2PSK。
- password 长度需不小于8 个字符
3.11 恢复出厂设置
$ curl -X POST -H "Content-Type:application/json" -d '{"factory":1}' http://IP/config?command=param
3.12 系统复位
$ curl -X POST -H "Content-Type:application/json" -d '{"reset":1}' http://IP/config?command=param
3.13 获取模块上电运行时间
$ curl -X GET http://IP/config?command=systime
3.14 串口波特率
$ curl -X POST -H "Content-Type:application/json" -d '{" uartbaud":baudrate}' http://IP/config?command=param
其中baudrate 代表要设置的波特率。 { “response”:{ “systime”:11111 } }
3.15 设置dataserver 端口
$ curl -X POST -H "Content-Type:application/json" -d '{" dataport":port}' http://IP/config?command=param
其中port 代表要设置的端口号
4 SDK API
4.1 GPIO
4.1.1 PIN Macro
PIN_PULLUP_DIS(PERIPHS_IO_MUX_GPIO2_U);
PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO4_U);
PIN_PULLDWN_DIS(PERIPHS_IO_MUX_U0TXD_U);
PIN_PULLDWN_EN(PERIPHS_IO_MUX_GPIO5_U);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12); // 选择 MTDI 脚复用为 GPIO12,大量管脚有多个功能,需用此宏选择具体的管脚功能
参考 SDK_DIR/include/eagle_soc.h
4.1.2 gpio_output_set
gpio_output_set(u32 set_mask, u32 clear_mask, u32 enable_mask, u32 disable_mask)
- set_mask: 设置输出为高的位,对应位为 1 输出高,对应位为 0 不改变状态
- clear_mask: 设置输出为低的位,对应位为 1 输出低,对应位为 0 不改变状态
- enable_mask: 设置使能输出的位
- disable_mask: 设置使能输入的位
#include <gpio.h> // Initialize the GPIO subsystem. gpio_init(); GPIO_REG_READ(GPIO_OUT_ADDRESS) & BIT2 == 1 //Set GPIO2 to output mode PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); //Set GPIO2 low gpio_output_set(0, BIT2, BIT2, 0); //Set GPIO0 to HIGH gpio_output_set(BIT2, 0, BIT2, 0); //Set GPIO12 to HIGH, GPIO13 to LOW gpio_output_set(BIT12, BIT13, BIT12|BIT13, 0);

