summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2021-05-06 11:08:00 +1000
committerDamien George <damien@micropython.org>2021-05-10 16:56:53 +1000
commit0e87459e2bfd073a084fe4af00c2f75d4c815639 (patch)
treeac36f7f7e91908ff23de6a7afc4367dc512553c4
parent32ec07a3504d6dcbfc53997197a3c53e8c03497f (diff)
esp32/boards: Add UM_FEATHERS2 and UM_TINYS2 board definitions.
Based on original commit made by Seon Rozenblum aka @UnexpectedMaker. Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r--ports/esp32/boards/UM_FEATHERS2/manifest.py3
-rw-r--r--ports/esp32/boards/UM_FEATHERS2/modules/feathers2.py101
-rw-r--r--ports/esp32/boards/UM_FEATHERS2/mpconfigboard.cmake9
-rw-r--r--ports/esp32/boards/UM_FEATHERS2/mpconfigboard.h5
-rw-r--r--ports/esp32/boards/UM_FEATHERS2/sdkconfig.board16
-rw-r--r--ports/esp32/boards/UM_TINYS2/manifest.py2
-rw-r--r--ports/esp32/boards/UM_TINYS2/modules/tinys2.py82
-rw-r--r--ports/esp32/boards/UM_TINYS2/mpconfigboard.cmake8
-rw-r--r--ports/esp32/boards/UM_TINYS2/mpconfigboard.h9
-rw-r--r--ports/esp32/boards/UM_TINYS2/sdkconfig.board6
10 files changed, 241 insertions, 0 deletions
diff --git a/ports/esp32/boards/UM_FEATHERS2/manifest.py b/ports/esp32/boards/UM_FEATHERS2/manifest.py
new file mode 100644
index 000000000..82ad0c7e4
--- /dev/null
+++ b/ports/esp32/boards/UM_FEATHERS2/manifest.py
@@ -0,0 +1,3 @@
+include("$(PORT_DIR)/boards/manifest.py")
+freeze("$(PORT_DIR)/boards/UM_TINYPICO/modules", "dotstar.py")
+freeze("modules")
diff --git a/ports/esp32/boards/UM_FEATHERS2/modules/feathers2.py b/ports/esp32/boards/UM_FEATHERS2/modules/feathers2.py
new file mode 100644
index 000000000..32126fc9c
--- /dev/null
+++ b/ports/esp32/boards/UM_FEATHERS2/modules/feathers2.py
@@ -0,0 +1,101 @@
+# FeatherS2 MicroPython Helper Library
+# 2021 Seon Rozenblum - Unexpected Maker
+#
+# Project home:
+# https://feathers2.io
+#
+# 2021-Mar-21 - v0.1 - Initial implementation
+
+# Import required libraries
+from micropython import const
+from machine import Pin, SPI, ADC
+import machine, time
+
+# FeatherS2 Hardware Pin Assignments
+
+# LDO
+LDO2 = const(21)
+
+# APA102 Dotstar pins
+DOTSTAR_CLK = const(45)
+DOTSTAR_DATA = const(40)
+
+# SPI
+SPI_MOSI = const(35)
+SPI_MISO = const(36)
+SPI_CLK = const(37)
+
+# I2C
+I2C_SDA = const(38)
+I2C_SCL = const(33)
+
+# DAC
+DAC1 = const(17)
+DAC2 = const(18)
+
+# LED & Ambient Light Sensor
+LED = const(13)
+AMB_LIGHT = const(4)
+
+# Helper functions
+
+# LED & Ambient Light Sensor control
+def set_led(state):
+ l = Pin(LED, Pin.OUT)
+ l.value(state)
+
+
+def toggle_led(state):
+ l = Pin(LED, Pin.OUT)
+ l.value(not l.value())
+
+
+# Create ADC and set attenuation and return teh ambient light value from the onboard sensor
+def get_amb_light():
+ adc = ADC(Pin(AMB_LIGHT))
+ adc.atten(ADC.ATTN_11DB)
+ return adc.read()
+
+
+# LDO2 power control
+# When we manually turn off the second LDO we also set the DotStar DATA and CLK pins to input to
+# prevent parasitic power from lighting the LED even with the LDO off, causing current use.
+# The DotStar is a beautiful LED, but parasitic power makes it a terrible choice for battery use :(
+def set_ldo2_power(state):
+ """Set the power for the on-board Dostar to allow no current draw when not needed."""
+ # Set the power pin to the inverse of state
+ ldo2 = Pin(LDO2, Pin.OUT)
+ ldo2.value(state)
+
+ if state:
+ Pin(DOTSTAR_CLK, Pin.OUT)
+ Pin(DOTSTAR_DATA, Pin.OUT) # If power is on, set CLK to be output, otherwise input
+ else:
+ Pin(DOTSTAR_CLK, Pin.IN)
+ Pin(DOTSTAR_DATA, Pin.IN) # If power is on, set CLK to be output, otherwise input
+
+ # A small delay to let the IO change state
+ time.sleep(0.035)
+
+
+# Dotstar rainbow colour wheel
+def dotstar_color_wheel(wheel_pos):
+ """Color wheel to allow for cycling through the rainbow of RGB colors."""
+ wheel_pos = wheel_pos % 255
+
+ if wheel_pos < 85:
+ return 255 - wheel_pos * 3, 0, wheel_pos * 3
+ elif wheel_pos < 170:
+ wheel_pos -= 85
+ return 0, wheel_pos * 3, 255 - wheel_pos * 3
+ else:
+ wheel_pos -= 170
+ return wheel_pos * 3, 255 - wheel_pos * 3, 0
+
+
+# Go into deep sleep but shut down the APA first to save power
+# Use this if you want lowest deep sleep current
+def go_deepsleep(t):
+ """Deep sleep helper that also powers down the on-board Dotstar."""
+ set_ldo2_power(False)
+ machine.deepsleep(t)
diff --git a/ports/esp32/boards/UM_FEATHERS2/mpconfigboard.cmake b/ports/esp32/boards/UM_FEATHERS2/mpconfigboard.cmake
new file mode 100644
index 000000000..5e570d513
--- /dev/null
+++ b/ports/esp32/boards/UM_FEATHERS2/mpconfigboard.cmake
@@ -0,0 +1,9 @@
+set(IDF_TARGET esp32s2)
+set(SDKCONFIG_DEFAULTS
+ boards/sdkconfig.base
+ boards/sdkconfig.spiram_sx
+ boards/sdkconfig.usb
+ boards/UM_FEATHERS2/sdkconfig.board
+)
+
+set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py) \ No newline at end of file
diff --git a/ports/esp32/boards/UM_FEATHERS2/mpconfigboard.h b/ports/esp32/boards/UM_FEATHERS2/mpconfigboard.h
new file mode 100644
index 000000000..c045adccd
--- /dev/null
+++ b/ports/esp32/boards/UM_FEATHERS2/mpconfigboard.h
@@ -0,0 +1,5 @@
+#define MICROPY_HW_BOARD_NAME "FeatherS2"
+#define MICROPY_HW_MCU_NAME "ESP32-S2"
+
+#define MICROPY_PY_BLUETOOTH (0)
+#define MICROPY_HW_ENABLE_SDCARD (0) \ No newline at end of file
diff --git a/ports/esp32/boards/UM_FEATHERS2/sdkconfig.board b/ports/esp32/boards/UM_FEATHERS2/sdkconfig.board
new file mode 100644
index 000000000..ccda7bff6
--- /dev/null
+++ b/ports/esp32/boards/UM_FEATHERS2/sdkconfig.board
@@ -0,0 +1,16 @@
+CONFIG_FLASHMODE_QIO=y
+CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
+CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y
+CONFIG_ESPTOOLPY_AFTER_NORESET=y
+
+CONFIG_SPIRAM_MEMTEST=
+
+CONFIG_ESPTOOLPY_FLASHSIZE_4MB=
+CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
+CONFIG_PARTITION_TABLE_CUSTOM=y
+CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-16MiB.csv"
+#CONFIG_USB_AND_UART=y
+
+# LWIP
+CONFIG_LWIP_LOCAL_HOSTNAME="UMFeatherS2"
+# end of LWIP
diff --git a/ports/esp32/boards/UM_TINYS2/manifest.py b/ports/esp32/boards/UM_TINYS2/manifest.py
new file mode 100644
index 000000000..7ae2ed15d
--- /dev/null
+++ b/ports/esp32/boards/UM_TINYS2/manifest.py
@@ -0,0 +1,2 @@
+include("$(PORT_DIR)/boards/manifest.py")
+freeze("modules")
diff --git a/ports/esp32/boards/UM_TINYS2/modules/tinys2.py b/ports/esp32/boards/UM_TINYS2/modules/tinys2.py
new file mode 100644
index 000000000..ca59cb123
--- /dev/null
+++ b/ports/esp32/boards/UM_TINYS2/modules/tinys2.py
@@ -0,0 +1,82 @@
+# TinyS2 MicroPython Helper Library
+# 2021 Seon Rozenblum - Unexpected Maker
+#
+# Project home:
+# https://tinys2.io
+#
+# 2021-Apr-10 - v0.1 - Initial implementation
+
+# Import required libraries
+from micropython import const
+from machine import Pin, SPI, ADC
+import machine, time
+
+# TinyS2 Hardware Pin Assignments
+
+# Sense Pins
+VBUS_SENSE = const(21)
+VBAT_SENSE = const(3)
+
+
+# RGB LED Pins
+RGB_DATA = const(1)
+RGB_PWR = const(2)
+
+# SPI
+SPI_MOSI = const(35)
+SPI_MISO = const(36)
+SPI_CLK = const(37)
+
+# I2C
+I2C_SDA = const(8)
+I2C_SCL = const(9)
+
+# DAC
+DAC1 = const(17)
+DAC2 = const(18)
+
+
+# Helper functions
+def set_pixel_power(state):
+ """Enable or Disable power to the onboard NeoPixel to either show colour, or to reduce power fro deep sleep."""
+ Pin(RGB_PWR, Pin.OUT).value(state)
+
+
+def get_battery_voltage():
+ """
+ Returns the current battery voltage. If no battery is connected, returns 4.2V which is the charge voltage
+ This is an approximation only, but useful to detect if the charge state of the battery is getting low.
+ """
+ adc = ADC(Pin(VBAT_SENSE)) # Assign the ADC pin to read
+ measuredvbat = adc.read() # Read the value
+ measuredvbat /= 8192 # divide by 8192 as we are using the default ADC voltage range of 0-1V
+ measuredvbat *= 4.2 # Multiply by 4.2V, our reference voltage
+ return round(measuredvbat, 2)
+
+
+def get_vbus_present():
+ """Detect if VBUS (5V) power source is present"""
+ return Pin(VBUS_SENSE, Pin.IN).value() == 1
+
+
+# Dotstar rainbow colour wheel
+def rgb_color_wheel(wheel_pos):
+ """Color wheel to allow for cycling through the rainbow of RGB colors."""
+ wheel_pos = wheel_pos % 255
+
+ if wheel_pos < 85:
+ return 255 - wheel_pos * 3, 0, wheel_pos * 3
+ elif wheel_pos < 170:
+ wheel_pos -= 85
+ return 0, wheel_pos * 3, 255 - wheel_pos * 3
+ else:
+ wheel_pos -= 170
+ return wheel_pos * 3, 255 - wheel_pos * 3, 0
+
+
+# Go into deep sleep but shut down the APA first to save power
+# Use this if you want lowest deep sleep current
+def go_deepsleep(t):
+ """Deep sleep helper that also powers down the on-board Dotstar."""
+ set_pixel_power(False)
+ machine.deepsleep(t)
diff --git a/ports/esp32/boards/UM_TINYS2/mpconfigboard.cmake b/ports/esp32/boards/UM_TINYS2/mpconfigboard.cmake
new file mode 100644
index 000000000..928f9f8fc
--- /dev/null
+++ b/ports/esp32/boards/UM_TINYS2/mpconfigboard.cmake
@@ -0,0 +1,8 @@
+set(IDF_TARGET esp32s2)
+set(SDKCONFIG_DEFAULTS
+ boards/sdkconfig.base
+ boards/sdkconfig.spiram_sx
+ boards/sdkconfig.usb
+)
+
+set(MICROPY_FROZEN_MANIFEST ${MICROPY_PORT_DIR}/boards/manifest.py)
diff --git a/ports/esp32/boards/UM_TINYS2/mpconfigboard.h b/ports/esp32/boards/UM_TINYS2/mpconfigboard.h
new file mode 100644
index 000000000..87d266e58
--- /dev/null
+++ b/ports/esp32/boards/UM_TINYS2/mpconfigboard.h
@@ -0,0 +1,9 @@
+#define MICROPY_HW_BOARD_NAME "TinyS2"
+#define MICROPY_HW_MCU_NAME "ESP32-S2FN4R2"
+
+#define MICROPY_PY_BLUETOOTH (0)
+#define MICROPY_HW_ENABLE_SDCARD (0)
+
+#define MICROPY_HW_SPI1_MOSI (35)
+#define MICROPY_HW_SPI1_MISO (36)
+#define MICROPY_HW_SPI1_SCK (37)
diff --git a/ports/esp32/boards/UM_TINYS2/sdkconfig.board b/ports/esp32/boards/UM_TINYS2/sdkconfig.board
new file mode 100644
index 000000000..48b6749c7
--- /dev/null
+++ b/ports/esp32/boards/UM_TINYS2/sdkconfig.board
@@ -0,0 +1,6 @@
+CONFIG_FLASHMODE_QIO=y
+CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
+CONFIG_USB_AND_UART=y
+# LWIP
+CONFIG_LWIP_LOCAL_HOSTNAME="UMTinyS2"
+# end of LWIP