src/eric7/MicroPython/EthernetDialogs/WiznetUtilities.py

Wed, 15 Mar 2023 16:13:35 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 15 Mar 2023 16:13:35 +0100
branch
eric7
changeset 9902
a3136eb28587
parent 9885
05cbf70e8f10
child 10330
5ea038882dd6
permissions
-rw-r--r--

MicroPython
- added a menu entry to set a CircuitPython device into 'UF2 Boot' mode

# -*- coding: utf-8 -*-

# Copyright (c) 2023 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing WIZnet 5x00 related utility functions.
"""


def mpyWiznetInit():
    """
    Function to get the WIZnet 5x00 initialization code for MicroPython.

    @return string containing the code to initialize the WIZnet 5x00 ethernet interface
    @rtype str
    """
    return """
def w5x00_init():
    global nic

    try:
        nic
    except NameError:
        nic = None

    if nic is None:
        import network
        from machine import Pin, SPI

        spi = SPI(0, 2_000_000, mosi=Pin(19), miso=Pin(16), sck=Pin(18))
        nic = network.WIZNET5K(spi, Pin(17), Pin(20))
"""


def cpyWiznetInit():
    """
    Function to get the WIZnet 5x00 initialization code for CircuitPython.

    @return string containing the code to initialize the WIZnet 5x00 ethernet interface
    @rtype str
    """
    return """
def w5x00_init():
    global nic

    try:
        nic
    except NameError:
        nic = None

    if nic is None:
        import board
        import busio
        import digitalio
        from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K

        SPI0_RX = board.GP16
        SPI0_CSn = board.GP17
        SPI0_SCK = board.GP18
        SPI0_TX = board.GP19
        W5x00_RSTn = board.GP20

        ethernetRst = digitalio.DigitalInOut(W5x00_RSTn)
        ethernetRst.direction = digitalio.Direction.OUTPUT

        cs = digitalio.DigitalInOut(SPI0_CSn)
        spi = busio.SPI(SPI0_SCK, MOSI=SPI0_TX, MISO=SPI0_RX)

        nic = WIZNET5K(spi, cs, reset=ethernetRst, is_dhcp=False)
"""

eric ide

mercurial