Răsfoiți Sursa

add:w5500增加获取mac的API

alienwalker 3 ani în urmă
părinte
comite
c2deaa3852

+ 16 - 0
components/ethernet/w5500/luat_lib_w5500.c

@@ -25,6 +25,7 @@
 @int irq pin
 @int reset pin
 @int link 状态 pin,可以留空不使用,默认不使用
+@return string 当前的mac
 @usage
 w5500.init(spi.SPI_0, 24000000, pin.PB13, pin.PC08, pin.PC09)
 */
@@ -113,6 +114,20 @@ static int l_w5500_network_register(lua_State *L){
 	return 0;
 }
 
+/*
+获取w5500当前的MAC,必须在init之后用,如果config中设置了自己的MAC,需要延迟一点时间再读
+@api w5500.getMAC()
+@return string 当前的MAC
+@usage
+local mac = w5500.getMAC()
+log.info("w5500 mac", mac:toHex())
+*/
+static int l_w5500_get_mac(lua_State *L){
+	uint8_t mac[6];
+	w5500_get_mac(mac);
+	lua_pushlstring(L, mac, 6);
+	return 1;
+}
 
 #include "rotable2.h"
 static const rotable_Reg_t reg_w5500[] =
@@ -122,6 +137,7 @@ static const rotable_Reg_t reg_w5500[] =
 	{ "config",           ROREG_FUNC(l_w5500_config)},
 #endif
 	{ "bind",           ROREG_FUNC(l_w5500_network_register)},
+	{ "getMac",           ROREG_FUNC(l_w5500_get_mac)},
 	{ NULL,            ROREG_INT(0)}
 };
 

+ 12 - 0
components/ethernet/w5500/w5500.c

@@ -1810,6 +1810,18 @@ void w5500_set_mac(uint8_t mac[6])
 	}
 }
 
+void w5500_get_mac(uint8_t mac[6])
+{
+	if (prv_w5500_ctrl)
+	{
+		memcpy(mac, prv_w5500_ctrl->mac, 6);
+	}
+	else
+	{
+		memset(mac, 0xff, 6);
+	}
+}
+
 void w5500_set_param(uint16_t timeout, uint8_t retry, uint8_t auto_speed, uint8_t force_arp)
 {
 	if (prv_w5500_ctrl)

+ 1 - 0
components/ethernet/w5500/w5500_def.h

@@ -28,6 +28,7 @@
 
 void w5500_set_static_ip(uint32_t ipv4, uint32_t submask, uint32_t gateway);
 void w5500_set_mac(uint8_t mac[6]);
+void w5500_get_mac(uint8_t mac[6]);
 void w5500_set_param(uint16_t timeout, uint8_t retry, uint8_t auto_speed, uint8_t force_arp);
 int w5500_reset(void);
 void w5500_init(luat_spi_t* spi, uint8_t irq_pin, uint8_t rst_pin, uint8_t link_pin);

+ 1 - 0
demo/ftp/main.lua

@@ -33,6 +33,7 @@ sys.taskInit(function()
     elseif rtos.bsp() == "AIR105" then
         -- w5500 以太网, 当前仅Air105支持
         w5500.init(spi.HSPI_0, 24000000, pin.PC14, pin.PC01, pin.PC00)
+        log.info("auto mac", w5500.getMac():toHex())
         w5500.config() --默认是DHCP模式
         w5500.bind(socket.ETH0)
         LED = gpio.setup(62, 0, gpio.PULLUP)