summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/esp32/boards/SIL_MANT1S/board.json27
-rw-r--r--ports/esp32/boards/SIL_MANT1S/manifest.py2
-rw-r--r--ports/esp32/boards/SIL_MANT1S/modules/ping.py114
-rw-r--r--ports/esp32/boards/SIL_MANT1S/mpconfigboard.cmake9
-rw-r--r--ports/esp32/boards/SIL_MANT1S/mpconfigboard.h6
-rw-r--r--ports/esp32/boards/SIL_MANT1S/partitions-8MiB-ota.csv9
-rw-r--r--ports/esp32/boards/SIL_MANT1S/pins.csv3
-rw-r--r--ports/esp32/boards/SIL_MANT1S/sdkconfig.board20
8 files changed, 190 insertions, 0 deletions
diff --git a/ports/esp32/boards/SIL_MANT1S/board.json b/ports/esp32/boards/SIL_MANT1S/board.json
new file mode 100644
index 000000000..06fd7f38b
--- /dev/null
+++ b/ports/esp32/boards/SIL_MANT1S/board.json
@@ -0,0 +1,27 @@
+{
+ "deploy": [
+ "../deploy.md"
+ ],
+ "deploy_options": {
+ "flash_offset": "0x1000"
+ },
+ "docs": "",
+ "features": [
+ "BLE",
+ "External Flash",
+ "External RAM",
+ "WiFi"
+ ],
+ "features_non_filterable": [
+ "T1S",
+ "10BASE-T1S"
+ ],
+ "images": [
+ "mant1s-board-top.jpg"
+ ],
+ "mcu": "esp32",
+ "product": "ManT1S",
+ "thumbnail": "",
+ "url": "https://mant1s.net/",
+ "vendor": "Silicognition LLC"
+}
diff --git a/ports/esp32/boards/SIL_MANT1S/manifest.py b/ports/esp32/boards/SIL_MANT1S/manifest.py
new file mode 100644
index 000000000..7ae2ed15d
--- /dev/null
+++ b/ports/esp32/boards/SIL_MANT1S/manifest.py
@@ -0,0 +1,2 @@
+include("$(PORT_DIR)/boards/manifest.py")
+freeze("modules")
diff --git a/ports/esp32/boards/SIL_MANT1S/modules/ping.py b/ports/esp32/boards/SIL_MANT1S/modules/ping.py
new file mode 100644
index 000000000..ec202f6f9
--- /dev/null
+++ b/ports/esp32/boards/SIL_MANT1S/modules/ping.py
@@ -0,0 +1,114 @@
+# µPing (MicroPing) for MicroPython
+# copyright (c) 2018 Shawwwn <shawwwn1@gmail.com>
+# License: MIT
+
+# Internet Checksum Algorithm
+# Author: Olav Morken
+# https://github.com/olavmrk/python-ping/blob/master/ping.py
+# Adjusted for ruff formatting to include in ManT1S MicroPython
+
+import utime
+import uselect
+import uctypes
+import usocket
+import ustruct
+import urandom
+
+
+# @data: bytes
+def checksum(data):
+ if len(data) & 0x1: # Odd number of bytes
+ data += b"\0"
+ cs = 0
+ for pos in range(0, len(data), 2):
+ b1 = data[pos]
+ b2 = data[pos + 1]
+ cs += (b1 << 8) + b2
+ while cs >= 0x10000:
+ cs = (cs & 0xFFFF) + (cs >> 16)
+ cs = ~cs & 0xFFFF
+ return cs
+
+
+def ping(host, count=4, timeout=5000, interval=10, quiet=False, size=64):
+ # prepare packet
+ assert size >= 16, "pkt size too small"
+ pkt = b"Q" * size
+ pkt_desc = {
+ "type": uctypes.UINT8 | 0,
+ "code": uctypes.UINT8 | 1,
+ "checksum": uctypes.UINT16 | 2,
+ "id": uctypes.UINT16 | 4,
+ "seq": uctypes.INT16 | 6,
+ "timestamp": uctypes.UINT64 | 8,
+ } # packet header descriptor
+ h = uctypes.struct(uctypes.addressof(pkt), pkt_desc, uctypes.BIG_ENDIAN)
+ h.type = 8 # ICMP_ECHO_REQUEST
+ h.code = 0
+ h.checksum = 0
+ h.id = urandom.getrandbits(16)
+ h.seq = 1
+
+ # init socket
+ sock = usocket.socket(usocket.AF_INET, usocket.SOCK_RAW, 1)
+ sock.setblocking(0)
+ sock.settimeout(timeout / 1000)
+ addr = usocket.getaddrinfo(host, 1)[0][-1][0] # ip address
+ sock.connect((addr, 1))
+ not quiet and print("PING %s (%s): %u data bytes" % (host, addr, len(pkt)))
+
+ seqs = list(range(1, count + 1)) # [1,2,...,count]
+ c = 1
+ t = 0
+ n_trans = 0
+ n_recv = 0
+ finish = False
+ while t < timeout:
+ if t == interval and c <= count:
+ # send packet
+ h.checksum = 0
+ h.seq = c
+ h.timestamp = utime.ticks_us()
+ h.checksum = checksum(pkt)
+ if sock.send(pkt) == size:
+ n_trans += 1
+ t = 0 # reset timeout
+ else:
+ seqs.remove(c)
+ c += 1
+
+ # recv packet
+ while 1:
+ socks, _, _ = uselect.select([sock], [], [], 0)
+ if socks:
+ resp = socks[0].recv(4096)
+ resp_mv = memoryview(resp)
+ h2 = uctypes.struct(uctypes.addressof(resp_mv[20:]), pkt_desc, uctypes.BIG_ENDIAN)
+ # TODO: validate checksum (optional)
+ seq = h2.seq
+ if h2.type == 0 and h2.id == h.id and (seq in seqs): # 0: ICMP_ECHO_REPLY
+ t_elasped = (utime.ticks_us() - h2.timestamp) / 1000
+ ttl = ustruct.unpack("!B", resp_mv[8:9])[0] # time-to-live
+ n_recv += 1
+ not quiet and print(
+ "%u bytes from %s: icmp_seq=%u, ttl=%u, time=%f ms"
+ % (len(resp), addr, seq, ttl, t_elasped)
+ )
+ seqs.remove(seq)
+ if len(seqs) == 0:
+ finish = True
+ break
+ else:
+ break
+
+ if finish:
+ break
+
+ utime.sleep_ms(1)
+ t += 1
+
+ # close
+ sock.close()
+ ret = (n_trans, n_recv)
+ not quiet and print("%u packets transmitted, %u packets received" % ret)
+ return ret
diff --git a/ports/esp32/boards/SIL_MANT1S/mpconfigboard.cmake b/ports/esp32/boards/SIL_MANT1S/mpconfigboard.cmake
new file mode 100644
index 000000000..3d17a2896
--- /dev/null
+++ b/ports/esp32/boards/SIL_MANT1S/mpconfigboard.cmake
@@ -0,0 +1,9 @@
+set(SDKCONFIG_DEFAULTS
+ boards/sdkconfig.base
+ boards/sdkconfig.spiram
+ boards/sdkconfig.ble
+ boards/sdkconfig.240mhz
+ boards/SIL_MANT1S/sdkconfig.board
+)
+
+set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py)
diff --git a/ports/esp32/boards/SIL_MANT1S/mpconfigboard.h b/ports/esp32/boards/SIL_MANT1S/mpconfigboard.h
new file mode 100644
index 000000000..342636c8a
--- /dev/null
+++ b/ports/esp32/boards/SIL_MANT1S/mpconfigboard.h
@@ -0,0 +1,6 @@
+#define MICROPY_HW_BOARD_NAME "Silicognition ManT1S"
+#define MICROPY_HW_MCU_NAME "ESP32-PICO-V3-02"
+#define MICROPY_PY_NETWORK_HOSTNAME_DEFAULT "mant1s"
+
+#define MICROPY_HW_I2C0_SCL (32)
+#define MICROPY_HW_I2C0_SDA (33)
diff --git a/ports/esp32/boards/SIL_MANT1S/partitions-8MiB-ota.csv b/ports/esp32/boards/SIL_MANT1S/partitions-8MiB-ota.csv
new file mode 100644
index 000000000..6229f4f75
--- /dev/null
+++ b/ports/esp32/boards/SIL_MANT1S/partitions-8MiB-ota.csv
@@ -0,0 +1,9 @@
+# Partition table for MicroPython with OTA support using 8MB flash
+# Notes: the offset of the partition table itself is set in
+# $IDF_PATH/components/partition_table/Kconfig.projbuild.
+# Name, Type, SubType, Offset, Size, Flags
+nvs, data, nvs, 0x9000, 0x4000,
+otadata, data, ota, 0xd000, 0x2000,
+phy_init, data, phy, 0xf000, 0x1000,
+ota_0, app, ota_0, 0x10000, 0x200000,
+ota_1, app, ota_1, 0x210000, 0x200000,
diff --git a/ports/esp32/boards/SIL_MANT1S/pins.csv b/ports/esp32/boards/SIL_MANT1S/pins.csv
new file mode 100644
index 000000000..a3f037781
--- /dev/null
+++ b/ports/esp32/boards/SIL_MANT1S/pins.csv
@@ -0,0 +1,3 @@
+I2C_SCL,GPIO32
+I2C_SDA,GPIO33
+
diff --git a/ports/esp32/boards/SIL_MANT1S/sdkconfig.board b/ports/esp32/boards/SIL_MANT1S/sdkconfig.board
new file mode 100644
index 000000000..53a605e2c
--- /dev/null
+++ b/ports/esp32/boards/SIL_MANT1S/sdkconfig.board
@@ -0,0 +1,20 @@
+# 8 MB flash
+
+CONFIG_ESPTOOLPY_FLASHSIZE_4MB=
+CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y
+CONFIG_ESPTOOLPY_FLASHSIZE_16MB=
+CONFIG_ESPTOOLPY_FLASHSIZE="8MB"
+
+# Fast flash
+
+CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
+CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
+
+# Partition table
+
+CONFIG_PARTITION_TABLE_CUSTOM=y
+CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="boards/SIL_MANT1S/partitions-8MiB-ota.csv"
+
+# Network name
+
+CONFIG_LWIP_LOCAL_HOSTNAME="ManT1S"