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>
This commit is contained in:
parent
32ec07a350
commit
0e87459e2b
|
@ -0,0 +1,3 @@
|
|||
include("$(PORT_DIR)/boards/manifest.py")
|
||||
freeze("$(PORT_DIR)/boards/UM_TINYPICO/modules", "dotstar.py")
|
||||
freeze("modules")
|
|
@ -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)
|
|
@ -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)
|
|
@ -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)
|
|
@ -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
|
|
@ -0,0 +1,2 @@
|
|||
include("$(PORT_DIR)/boards/manifest.py")
|
||||
freeze("modules")
|
|
@ -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)
|
|
@ -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)
|
|
@ -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)
|
|
@ -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
|
Loading…
Reference in New Issue