Skip to content

Commit 0e87459

Browse files
committed
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 <[email protected]>
1 parent 32ec07a commit 0e87459

File tree

10 files changed

+241
-0
lines changed

10 files changed

+241
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include("$(PORT_DIR)/boards/manifest.py")
2+
freeze("$(PORT_DIR)/boards/UM_TINYPICO/modules", "dotstar.py")
3+
freeze("modules")
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# FeatherS2 MicroPython Helper Library
2+
# 2021 Seon Rozenblum - Unexpected Maker
3+
#
4+
# Project home:
5+
# https://feathers2.io
6+
#
7+
# 2021-Mar-21 - v0.1 - Initial implementation
8+
9+
# Import required libraries
10+
from micropython import const
11+
from machine import Pin, SPI, ADC
12+
import machine, time
13+
14+
# FeatherS2 Hardware Pin Assignments
15+
16+
# LDO
17+
LDO2 = const(21)
18+
19+
# APA102 Dotstar pins
20+
DOTSTAR_CLK = const(45)
21+
DOTSTAR_DATA = const(40)
22+
23+
# SPI
24+
SPI_MOSI = const(35)
25+
SPI_MISO = const(36)
26+
SPI_CLK = const(37)
27+
28+
# I2C
29+
I2C_SDA = const(38)
30+
I2C_SCL = const(33)
31+
32+
# DAC
33+
DAC1 = const(17)
34+
DAC2 = const(18)
35+
36+
# LED & Ambient Light Sensor
37+
LED = const(13)
38+
AMB_LIGHT = const(4)
39+
40+
# Helper functions
41+
42+
# LED & Ambient Light Sensor control
43+
def set_led(state):
44+
l = Pin(LED, Pin.OUT)
45+
l.value(state)
46+
47+
48+
def toggle_led(state):
49+
l = Pin(LED, Pin.OUT)
50+
l.value(not l.value())
51+
52+
53+
# Create ADC and set attenuation and return teh ambient light value from the onboard sensor
54+
def get_amb_light():
55+
adc = ADC(Pin(AMB_LIGHT))
56+
adc.atten(ADC.ATTN_11DB)
57+
return adc.read()
58+
59+
60+
# LDO2 power control
61+
# When we manually turn off the second LDO we also set the DotStar DATA and CLK pins to input to
62+
# prevent parasitic power from lighting the LED even with the LDO off, causing current use.
63+
# The DotStar is a beautiful LED, but parasitic power makes it a terrible choice for battery use :(
64+
def set_ldo2_power(state):
65+
"""Set the power for the on-board Dostar to allow no current draw when not needed."""
66+
# Set the power pin to the inverse of state
67+
ldo2 = Pin(LDO2, Pin.OUT)
68+
ldo2.value(state)
69+
70+
if state:
71+
Pin(DOTSTAR_CLK, Pin.OUT)
72+
Pin(DOTSTAR_DATA, Pin.OUT) # If power is on, set CLK to be output, otherwise input
73+
else:
74+
Pin(DOTSTAR_CLK, Pin.IN)
75+
Pin(DOTSTAR_DATA, Pin.IN) # If power is on, set CLK to be output, otherwise input
76+
77+
# A small delay to let the IO change state
78+
time.sleep(0.035)
79+
80+
81+
# Dotstar rainbow colour wheel
82+
def dotstar_color_wheel(wheel_pos):
83+
"""Color wheel to allow for cycling through the rainbow of RGB colors."""
84+
wheel_pos = wheel_pos % 255
85+
86+
if wheel_pos < 85:
87+
return 255 - wheel_pos * 3, 0, wheel_pos * 3
88+
elif wheel_pos < 170:
89+
wheel_pos -= 85
90+
return 0, wheel_pos * 3, 255 - wheel_pos * 3
91+
else:
92+
wheel_pos -= 170
93+
return wheel_pos * 3, 255 - wheel_pos * 3, 0
94+
95+
96+
# Go into deep sleep but shut down the APA first to save power
97+
# Use this if you want lowest deep sleep current
98+
def go_deepsleep(t):
99+
"""Deep sleep helper that also powers down the on-board Dotstar."""
100+
set_ldo2_power(False)
101+
machine.deepsleep(t)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
set(IDF_TARGET esp32s2)
2+
set(SDKCONFIG_DEFAULTS
3+
boards/sdkconfig.base
4+
boards/sdkconfig.spiram_sx
5+
boards/sdkconfig.usb
6+
boards/UM_FEATHERS2/sdkconfig.board
7+
)
8+
9+
set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#define MICROPY_HW_BOARD_NAME "FeatherS2"
2+
#define MICROPY_HW_MCU_NAME "ESP32-S2"
3+
4+
#define MICROPY_PY_BLUETOOTH (0)
5+
#define MICROPY_HW_ENABLE_SDCARD (0)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CONFIG_FLASHMODE_QIO=y
2+
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
3+
CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y
4+
CONFIG_ESPTOOLPY_AFTER_NORESET=y
5+
6+
CONFIG_SPIRAM_MEMTEST=
7+
8+
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=
9+
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
10+
CONFIG_PARTITION_TABLE_CUSTOM=y
11+
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-16MiB.csv"
12+
#CONFIG_USB_AND_UART=y
13+
14+
# LWIP
15+
CONFIG_LWIP_LOCAL_HOSTNAME="UMFeatherS2"
16+
# end of LWIP
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include("$(PORT_DIR)/boards/manifest.py")
2+
freeze("modules")
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# TinyS2 MicroPython Helper Library
2+
# 2021 Seon Rozenblum - Unexpected Maker
3+
#
4+
# Project home:
5+
# https://tinys2.io
6+
#
7+
# 2021-Apr-10 - v0.1 - Initial implementation
8+
9+
# Import required libraries
10+
from micropython import const
11+
from machine import Pin, SPI, ADC
12+
import machine, time
13+
14+
# TinyS2 Hardware Pin Assignments
15+
16+
# Sense Pins
17+
VBUS_SENSE = const(21)
18+
VBAT_SENSE = const(3)
19+
20+
21+
# RGB LED Pins
22+
RGB_DATA = const(1)
23+
RGB_PWR = const(2)
24+
25+
# SPI
26+
SPI_MOSI = const(35)
27+
SPI_MISO = const(36)
28+
SPI_CLK = const(37)
29+
30+
# I2C
31+
I2C_SDA = const(8)
32+
I2C_SCL = const(9)
33+
34+
# DAC
35+
DAC1 = const(17)
36+
DAC2 = const(18)
37+
38+
39+
# Helper functions
40+
def set_pixel_power(state):
41+
"""Enable or Disable power to the onboard NeoPixel to either show colour, or to reduce power fro deep sleep."""
42+
Pin(RGB_PWR, Pin.OUT).value(state)
43+
44+
45+
def get_battery_voltage():
46+
"""
47+
Returns the current battery voltage. If no battery is connected, returns 4.2V which is the charge voltage
48+
This is an approximation only, but useful to detect if the charge state of the battery is getting low.
49+
"""
50+
adc = ADC(Pin(VBAT_SENSE)) # Assign the ADC pin to read
51+
measuredvbat = adc.read() # Read the value
52+
measuredvbat /= 8192 # divide by 8192 as we are using the default ADC voltage range of 0-1V
53+
measuredvbat *= 4.2 # Multiply by 4.2V, our reference voltage
54+
return round(measuredvbat, 2)
55+
56+
57+
def get_vbus_present():
58+
"""Detect if VBUS (5V) power source is present"""
59+
return Pin(VBUS_SENSE, Pin.IN).value() == 1
60+
61+
62+
# Dotstar rainbow colour wheel
63+
def rgb_color_wheel(wheel_pos):
64+
"""Color wheel to allow for cycling through the rainbow of RGB colors."""
65+
wheel_pos = wheel_pos % 255
66+
67+
if wheel_pos < 85:
68+
return 255 - wheel_pos * 3, 0, wheel_pos * 3
69+
elif wheel_pos < 170:
70+
wheel_pos -= 85
71+
return 0, wheel_pos * 3, 255 - wheel_pos * 3
72+
else:
73+
wheel_pos -= 170
74+
return wheel_pos * 3, 255 - wheel_pos * 3, 0
75+
76+
77+
# Go into deep sleep but shut down the APA first to save power
78+
# Use this if you want lowest deep sleep current
79+
def go_deepsleep(t):
80+
"""Deep sleep helper that also powers down the on-board Dotstar."""
81+
set_pixel_power(False)
82+
machine.deepsleep(t)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set(IDF_TARGET esp32s2)
2+
set(SDKCONFIG_DEFAULTS
3+
boards/sdkconfig.base
4+
boards/sdkconfig.spiram_sx
5+
boards/sdkconfig.usb
6+
)
7+
8+
set(MICROPY_FROZEN_MANIFEST ${MICROPY_PORT_DIR}/boards/manifest.py)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#define MICROPY_HW_BOARD_NAME "TinyS2"
2+
#define MICROPY_HW_MCU_NAME "ESP32-S2FN4R2"
3+
4+
#define MICROPY_PY_BLUETOOTH (0)
5+
#define MICROPY_HW_ENABLE_SDCARD (0)
6+
7+
#define MICROPY_HW_SPI1_MOSI (35)
8+
#define MICROPY_HW_SPI1_MISO (36)
9+
#define MICROPY_HW_SPI1_SCK (37)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CONFIG_FLASHMODE_QIO=y
2+
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
3+
CONFIG_USB_AND_UART=y
4+
# LWIP
5+
CONFIG_LWIP_LOCAL_HOSTNAME="UMTinyS2"
6+
# end of LWIP

0 commit comments

Comments
 (0)