extmod/modnetwork: Add network.hostname() and network.country().

This provides a standard interface to setting the global networking config
for all interfaces and interface types.

For ports that already use either a static hostname (mimxrt, rp2) they will
now use the configured value. The default is configured by the port
(or optionally the board).

For interfaces that previously supported .config(hostname), this is still
supported but now implemented using the global network.hostname.

Similarly, pyb.country and rp2.country are now deprecated, but the methods
still exist (and forward to network.hostname).

Because ESP32/ESP8266 do not use extmod/modnetwork.c they are not affected
by this commit.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
Jim Mussared
2023-02-01 14:19:45 +11:00
committed by Damien George
parent fc4c47f7bc
commit a377302623
26 changed files with 138 additions and 79 deletions

View File

@@ -1,6 +1,8 @@
#define MICROPY_HW_BOARD_NAME "i.MX RT1020 EVK"
#define MICROPY_HW_MCU_NAME "MIMXRT1021DAG5A"
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-1020evk"
// i.MX RT1020 EVK has 1 board LED
// Todo: think about replacing the define with searching in the generated pins?
#define MICROPY_HW_LED1_PIN (pin_GPIO_AD_B0_05)

View File

@@ -1,6 +1,8 @@
#define MICROPY_HW_BOARD_NAME "i.MX RT1050 EVKB-A1"
#define MICROPY_HW_MCU_NAME "MIMXRT1052DVL6B"
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-1050evk"
// MIMXRT1050_EVKB has 1 user LED
#define MICROPY_HW_LED1_PIN (pin_GPIO_AD_B0_09)
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_low(pin))

View File

@@ -1,6 +1,8 @@
#define MICROPY_HW_BOARD_NAME "i.MX RT1060 EVK"
#define MICROPY_HW_MCU_NAME "MIMXRT1062DVJ6A"
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-1060evk"
// MIMXRT1060_EVK has 1 user LED
#define MICROPY_HW_LED1_PIN (pin_GPIO_AD_B0_09)
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_low(pin))

View File

@@ -1,6 +1,8 @@
#define MICROPY_HW_BOARD_NAME "i.MX RT1064 EVK"
#define MICROPY_HW_MCU_NAME "MIMXRT1064DVL6A"
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-1064evk"
// MIMXRT1064_EVK has 1 user LED
#define MICROPY_HW_LED1_PIN (pin_GPIO_AD_B0_09)
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_low(pin))

View File

@@ -1,5 +1,8 @@
#define MICROPY_HW_BOARD_NAME "i.MX RT1170 EVK"
#define MICROPY_HW_MCU_NAME "MIMXRT1176DVMAA"
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-1070evk"
#define MICROPY_EVENT_POLL_HOOK \
do { \
extern void mp_handle_pending(bool); \

View File

@@ -1,6 +1,8 @@
#define MICROPY_HW_BOARD_NAME "Seeed ARCH MIX"
#define MICROPY_HW_MCU_NAME "MIMXRT1052DVL5B"
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-arch-mix"
// MIMXRT1050_EVKB has 1 user LED
#define MICROPY_HW_LED1_PIN (pin_GPIO_AD_B0_09)
#define MICROPY_HW_LED2_PIN (pin_GPIO_AD_B0_10)

View File

@@ -1,6 +1,8 @@
#define MICROPY_HW_BOARD_NAME "Teensy 4.1"
#define MICROPY_HW_MCU_NAME "MIMXRT1062DVJ6A"
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-teensy41"
// Teensy 4.1 has 1 board LED
#define MICROPY_HW_LED1_PIN (pin_GPIO_B0_03)
#define MICROPY_HW_LED_ON(pin) (mp_hal_pin_high(pin))

View File

@@ -559,7 +559,7 @@ STATIC void eth_lwip_init(eth_t *self) {
n->name[0] = 'e';
n->name[1] = (self == &eth_instance0 ? '0' : '1');
netif_add(n, &ipconfig[0], &ipconfig[1], &ipconfig[2], self, eth_netif_init, ethernet_input);
netif_set_hostname(n, "MPY");
netif_set_hostname(n, mod_network_hostname);
netif_set_default(n);
netif_set_up(n);

View File

@@ -118,6 +118,10 @@ uint32_t trng_random_u32(void);
#define MICROPY_PY_LWIP_REENTER MICROPY_PY_PENDSV_REENTER
#define MICROPY_PY_LWIP_EXIT MICROPY_PY_PENDSV_EXIT
#ifndef MICROPY_PY_NETWORK_HOSTNAME_DEFAULT
#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mpy-mimxrt"
#endif
#endif
// For regular code that wants to prevent "background tasks" from running.