summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSeon Rozenblum <seon@unexpectedmaker.com>2021-09-04 10:41:25 +1000
committerDamien George <damien@micropython.org>2021-09-10 15:40:32 +1000
commit9a7f77bfbc51f4dda5a9396d8bb4b57dcdfcdb90 (patch)
treec911fcefb0427ccf551d473aac5854b1035628ad
parent60d3a3c3a0746312f4fd46c56d206ffad1c57796 (diff)
esp32/boards: Add new FeatherS2-Neo board definition.
-rw-r--r--ports/esp32/boards/UM_FEATHERS2NEO/manifest.py2
-rw-r--r--ports/esp32/boards/UM_FEATHERS2NEO/modules/feathers2neo.py90
-rw-r--r--ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.cmake8
-rw-r--r--ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.h12
-rw-r--r--ports/esp32/boards/UM_FEATHERS2NEO/sdkconfig.board8
-rwxr-xr-xtools/autobuild/build-esp32-latest.sh1
6 files changed, 121 insertions, 0 deletions
diff --git a/ports/esp32/boards/UM_FEATHERS2NEO/manifest.py b/ports/esp32/boards/UM_FEATHERS2NEO/manifest.py
new file mode 100644
index 000000000..7ae2ed15d
--- /dev/null
+++ b/ports/esp32/boards/UM_FEATHERS2NEO/manifest.py
@@ -0,0 +1,2 @@
+include("$(PORT_DIR)/boards/manifest.py")
+freeze("modules")
diff --git a/ports/esp32/boards/UM_FEATHERS2NEO/modules/feathers2neo.py b/ports/esp32/boards/UM_FEATHERS2NEO/modules/feathers2neo.py
new file mode 100644
index 000000000..857c7559d
--- /dev/null
+++ b/ports/esp32/boards/UM_FEATHERS2NEO/modules/feathers2neo.py
@@ -0,0 +1,90 @@
+# FeatherS2 Neo MicroPython Helper Library
+# 2021 Seon Rozenblum - Unexpected Maker
+#
+# Project home:
+# https://unexpectedmaker.com/feathers2-neo
+#
+# 2021-Sep-04 - v0.1 - Initial implementation
+
+# Import required libraries
+from micropython import const
+from machine import Pin, ADC
+import machine, time
+
+# FeatherS2 Neo Hardware Pin Assignments
+
+# Sense Pins
+VBUS_SENSE = const(34)
+VBAT_SENSE = const(2)
+
+# RGB LED Pins
+RGB_DATA = const(40)
+RGB_PWR = const(39)
+
+# RGB MATRIX LED Pins
+RGB_MATRIX_DATA = const(21)
+RGB_MATRIX_PWR = const(4)
+
+# SPI
+SPI_MOSI = const(35)
+SPI_MISO = const(37)
+SPI_CLK = const(36)
+
+# 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 for deep sleep."""
+ Pin(RGB_PWR, Pin.OUT).value(state)
+
+
+def set_pixel_matrix_power(state):
+ """Enable or Disable power to the onboard NeoPixel RGB Matrix to either show colours, or to reduce power for deep sleep."""
+ Pin(RGB_MATRIX_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
+
+
+# NeoPixel 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 RGB LED 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 NeoPixel."""
+ set_pixel_power(False)
+ set_pixel_matrix_power(False)
+ machine.deepsleep(t)
diff --git a/ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.cmake b/ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.cmake
new file mode 100644
index 000000000..b0b3e3aa9
--- /dev/null
+++ b/ports/esp32/boards/UM_FEATHERS2NEO/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_BOARD_DIR}/manifest.py) \ No newline at end of file
diff --git a/ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.h b/ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.h
new file mode 100644
index 000000000..5ee6874b8
--- /dev/null
+++ b/ports/esp32/boards/UM_FEATHERS2NEO/mpconfigboard.h
@@ -0,0 +1,12 @@
+#define MICROPY_HW_BOARD_NAME "FeatherS2 Neo"
+#define MICROPY_HW_MCU_NAME "ESP32-S2FN4R2"
+
+#define MICROPY_PY_BLUETOOTH (0)
+#define MICROPY_HW_ENABLE_SDCARD (0)
+
+#define MICROPY_HW_I2C0_SCL (9)
+#define MICROPY_HW_I2C0_SDA (8)
+
+#define MICROPY_HW_SPI1_MOSI (35) // SDO
+#define MICROPY_HW_SPI1_MISO (37) // SDI
+#define MICROPY_HW_SPI1_SCK (36)
diff --git a/ports/esp32/boards/UM_FEATHERS2NEO/sdkconfig.board b/ports/esp32/boards/UM_FEATHERS2NEO/sdkconfig.board
new file mode 100644
index 000000000..87a92892d
--- /dev/null
+++ b/ports/esp32/boards/UM_FEATHERS2NEO/sdkconfig.board
@@ -0,0 +1,8 @@
+CONFIG_FLASHMODE_QIO=y
+CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
+CONFIG_USB_AND_UART=y
+CONFIG_ESPTOOLPY_AFTER_NORESET=y
+
+# LWIP
+CONFIG_LWIP_LOCAL_HOSTNAME="UMFeatherS2Neo"
+# end of LWIP
diff --git a/tools/autobuild/build-esp32-latest.sh b/tools/autobuild/build-esp32-latest.sh
index 92a12b2d5..5445927ab 100755
--- a/tools/autobuild/build-esp32-latest.sh
+++ b/tools/autobuild/build-esp32-latest.sh
@@ -49,4 +49,5 @@ else
do_build esp32c3 GENERIC_C3
do_build tinys2 UM_TINYS2
do_build featherS2 UM_FEATHERS2
+ do_build featherS2neo UM_FEATHERS2NEO
fi