src/eric7/MicroPython/EthernetDialogs/WiznetUtilities.py

branch
mpy_network
changeset 9885
05cbf70e8f10
parent 9878
a82014a9e57b
child 10330
5ea038882dd6
equal deleted inserted replaced
9883:7e073ff57760 9885:05cbf70e8f10
6 """ 6 """
7 Module implementing WIZnet 5x00 related utility functions. 7 Module implementing WIZnet 5x00 related utility functions.
8 """ 8 """
9 9
10 10
11 def wiznetInit(): 11 def mpyWiznetInit():
12 """ 12 """
13 Function to get the WIZnet 5x00 initialization code. 13 Function to get the WIZnet 5x00 initialization code for MicroPython.
14 14
15 @return string containing the code to initialize the WIZnet 5x00 ethernet interface 15 @return string containing the code to initialize the WIZnet 5x00 ethernet interface
16 @rtype str 16 @rtype str
17 """ 17 """
18 return """ 18 return """
29 from machine import Pin, SPI 29 from machine import Pin, SPI
30 30
31 spi = SPI(0, 2_000_000, mosi=Pin(19), miso=Pin(16), sck=Pin(18)) 31 spi = SPI(0, 2_000_000, mosi=Pin(19), miso=Pin(16), sck=Pin(18))
32 nic = network.WIZNET5K(spi, Pin(17), Pin(20)) 32 nic = network.WIZNET5K(spi, Pin(17), Pin(20))
33 """ 33 """
34
35
36 def cpyWiznetInit():
37 """
38 Function to get the WIZnet 5x00 initialization code for CircuitPython.
39
40 @return string containing the code to initialize the WIZnet 5x00 ethernet interface
41 @rtype str
42 """
43 return """
44 def w5x00_init():
45 global nic
46
47 try:
48 nic
49 except NameError:
50 nic = None
51
52 if nic is None:
53 import board
54 import busio
55 import digitalio
56 from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K
57
58 SPI0_RX = board.GP16
59 SPI0_CSn = board.GP17
60 SPI0_SCK = board.GP18
61 SPI0_TX = board.GP19
62 W5x00_RSTn = board.GP20
63
64 ethernetRst = digitalio.DigitalInOut(W5x00_RSTn)
65 ethernetRst.direction = digitalio.Direction.OUTPUT
66
67 cs = digitalio.DigitalInOut(SPI0_CSn)
68 spi = busio.SPI(SPI0_SCK, MOSI=SPI0_TX, MISO=SPI0_RX)
69
70 nic = WIZNET5K(spi, cs, reset=ethernetRst, is_dhcp=False)
71 """

eric ide

mercurial