Mon, 20 Jan 2025 15:48:41 +0100
MicroPython
- Updated the list of known CircuitPython boards for CPy 9.2.3.
9878 | 1 | # -*- coding: utf-8 -*- |
2 | ||
11090
f5f5f5803935
Updated copyright for 2025.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
3 | # Copyright (c) 2023 - 2025 Detlev Offenbach <detlev@die-offenbachs.de> |
9878 | 4 | # |
5 | ||
6 | """ | |
7 | Module implementing WIZnet 5x00 related utility functions. | |
8 | """ | |
9 | ||
10 | ||
9885 | 11 | def mpyWiznetInit(): |
9878 | 12 | """ |
9885 | 13 | Function to get the WIZnet 5x00 initialization code for MicroPython. |
9878 | 14 | |
15 | @return string containing the code to initialize the WIZnet 5x00 ethernet interface | |
16 | @rtype str | |
17 | """ | |
10330
5ea038882dd6
MicroPython Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9885
diff
changeset
|
18 | return """def w5x00_init(): |
9878 | 19 | global nic |
20 | ||
21 | try: | |
22 | nic | |
23 | except NameError: | |
24 | nic = None | |
25 | ||
26 | if nic is None: | |
27 | import network | |
28 | from machine import Pin, SPI | |
29 | ||
30 | spi = SPI(0, 2_000_000, mosi=Pin(19), miso=Pin(16), sck=Pin(18)) | |
31 | nic = network.WIZNET5K(spi, Pin(17), Pin(20)) | |
32 | """ | |
9885 | 33 | |
34 | ||
35 | def cpyWiznetInit(): | |
36 | """ | |
37 | Function to get the WIZnet 5x00 initialization code for CircuitPython. | |
38 | ||
39 | @return string containing the code to initialize the WIZnet 5x00 ethernet interface | |
40 | @rtype str | |
41 | """ | |
10330
5ea038882dd6
MicroPython Interface
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9885
diff
changeset
|
42 | return """def w5x00_init(): |
9885 | 43 | global nic |
44 | ||
45 | try: | |
46 | nic | |
47 | except NameError: | |
48 | nic = None | |
49 | ||
50 | if nic is None: | |
51 | import board | |
52 | import busio | |
53 | import digitalio | |
54 | from adafruit_wiznet5k.adafruit_wiznet5k import WIZNET5K | |
55 | ||
56 | SPI0_RX = board.GP16 | |
57 | SPI0_CSn = board.GP17 | |
58 | SPI0_SCK = board.GP18 | |
59 | SPI0_TX = board.GP19 | |
60 | W5x00_RSTn = board.GP20 | |
61 | ||
62 | ethernetRst = digitalio.DigitalInOut(W5x00_RSTn) | |
63 | ethernetRst.direction = digitalio.Direction.OUTPUT | |
64 | ||
65 | cs = digitalio.DigitalInOut(SPI0_CSn) | |
66 | spi = busio.SPI(SPI0_SCK, MOSI=SPI0_TX, MISO=SPI0_RX) | |
67 | ||
68 | nic = WIZNET5K(spi, cs, reset=ethernetRst, is_dhcp=False) | |
69 | """ |