-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
add LOLIN_S2_MINI and LOLIN_S2_PICO boards support. #7660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include("$(PORT_DIR)/boards/manifest.py") | ||
freeze("./modules") | ||
|
||
freeze("$(MPY_DIR)/drivers/display", "ssd1306.py") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# LOLIN S2 MINI MicroPython Helper Library | ||
|
||
|
||
from micropython import const | ||
from machine import Pin, SPI, ADC | ||
import machine, time | ||
|
||
import network | ||
|
||
# Pin Assignments | ||
|
||
|
||
# SPI | ||
SPI_MOSI = const(11) | ||
SPI_MISO = const(9) | ||
SPI_CLK = const(7) | ||
|
||
# I2C | ||
I2C_SDA = const(33) | ||
I2C_SCL = const(35) | ||
|
||
# DAC | ||
DAC1 = const(17) | ||
DAC2 = const(18) | ||
|
||
# LED | ||
LED = const(15) | ||
|
||
# BUTTON | ||
BUTTON = const(0) | ||
|
||
|
||
class led: | ||
def __init__(self): | ||
self._led = Pin(LED, Pin.OUT, value=0) | ||
|
||
def on(self): | ||
self._led.value(1) | ||
|
||
def off(self): | ||
self._led.value(0) | ||
|
||
|
||
class button: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As with the LED class I think it's much simpler to just do: button = Pin(BUTTON, Pin.IN, Pin.PULL_UP) and not have this class at all. |
||
def __init__(self): | ||
self._btn = Pin(BUTTON, Pin.IN, Pin.PULL_UP) | ||
|
||
def get_button_status(self): | ||
return self._btn.value() | ||
|
||
def set_button_callback(self, cb): | ||
self._btn.irq(trigger=Pin.IRQ_FALLING, handler=cb) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
set(IDF_TARGET esp32s2) | ||
set(SDKCONFIG_DEFAULTS | ||
boards/sdkconfig.base | ||
boards/sdkconfig.spiram_sx | ||
boards/sdkconfig.usb | ||
) | ||
|
||
if(NOT MICROPY_FROZEN_MANIFEST) | ||
set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py) | ||
endif() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#define MICROPY_HW_BOARD_NAME "LOLIN_S2_MINI" | ||
#define MICROPY_HW_MCU_NAME "ESP32-S2FN4R2" | ||
|
||
#define MICROPY_PY_BLUETOOTH (0) | ||
#define MICROPY_HW_ENABLE_SDCARD (0) | ||
|
||
#define MICROPY_HW_I2C0_SCL (35) | ||
#define MICROPY_HW_I2C0_SDA (33) | ||
|
||
#define MICROPY_HW_SPI1_MOSI (11) | ||
#define MICROPY_HW_SPI1_MISO (9) | ||
#define MICROPY_HW_SPI1_SCK (7) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CONFIG_FLASHMODE_QIO=y | ||
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y | ||
CONFIG_USB_AND_UART=y | ||
# LWIP | ||
CONFIG_LWIP_LOCAL_HOSTNAME="LOLIN_S2_MINI" | ||
# end of LWIP |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
include("$(PORT_DIR)/boards/manifest.py") | ||
freeze("./modules") | ||
|
||
freeze("$(MPY_DIR)/drivers/display", "ssd1306.py") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# LOLIN S2 PICO MicroPython Helper Library | ||
|
||
|
||
from micropython import const | ||
from machine import Pin, SPI, ADC, I2C | ||
import machine, time | ||
import ssd1306 | ||
|
||
import network | ||
|
||
|
||
# Pin Assignments | ||
|
||
# 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) | ||
|
||
# LED | ||
LED = const(10) | ||
|
||
# OLED | ||
OLED_RST = const(18) | ||
|
||
# BUTTON | ||
BUTTON = const(0) | ||
|
||
|
||
class led: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as for the other board, simpler to use machine.Signal: led = Signal(LED, Pin.OUT, value=0, invert=True) |
||
def __init__(self): | ||
self._led = Pin(LED, Pin.OUT, value=1) | ||
|
||
def on(self): | ||
self._led.value(0) | ||
|
||
def off(self): | ||
self._led.value(1) | ||
|
||
|
||
class button: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as for the other board, use |
||
def __init__(self): | ||
self._btn = Pin(BUTTON, Pin.IN, Pin.PULL_UP) | ||
|
||
def get_button_status(self): | ||
return self._btn.value() | ||
|
||
def set_button_callback(self, cb): | ||
self._btn.irq(trigger=Pin.IRQ_FALLING, handler=cb) | ||
|
||
|
||
class oled(ssd1306.SSD1306_I2C): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
def __init__(self): | ||
self.reset() | ||
|
||
# super().__init__(128,32,I2C(0)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line should probably be uncommented (init should usually only be called from within init). |
||
|
||
def reset(self): | ||
|
||
Pin(OLED_RST, Pin.OUT).value(1) | ||
time.sleep_ms(1) | ||
Pin(OLED_RST, Pin.OUT).value(0) | ||
time.sleep_ms(10) | ||
Pin(OLED_RST, Pin.OUT).value(1) | ||
|
||
super().__init__(128, 32, I2C(0)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line should probably be removed. |
||
|
||
def test(self): | ||
|
||
self.fill(0) | ||
self.fill_rect(0, 0, 32, 32, 1) | ||
self.fill_rect(2, 2, 28, 28, 0) | ||
self.vline(9, 8, 22, 1) | ||
self.vline(16, 2, 22, 1) | ||
self.vline(23, 8, 22, 1) | ||
self.fill_rect(26, 24, 2, 4, 1) | ||
self.text("MicroPython", 40, 0, 1) | ||
self.text("SSD1306", 40, 12, 1) | ||
self.text("OLED 128x32", 40, 24, 1) | ||
self.show() | ||
|
||
def display_wifi(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function looks useful to debug WiFi but is it good to include it here? I think it would be better as a separate helper module that can be installed from a .py file to the filesystem. |
||
|
||
self.fill(0) | ||
self.text("Scan...", 0, 0, 1) | ||
self.show() | ||
|
||
sta_if = network.WLAN(network.STA_IF) | ||
sta_if.active(True) | ||
_wifi = sta_if.scan() | ||
|
||
self.fill(0) | ||
self.text(str(len(_wifi)) + " Networks", 0, 0, 1) | ||
self.text(str(_wifi[0][3]) + " - " + (_wifi[0][0]).decode("utf-8"), 0, 12, 1) | ||
self.text(str(_wifi[1][3]) + " - " + (_wifi[1][0]).decode("utf-8"), 0, 24, 1) | ||
|
||
self.show() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
set(IDF_TARGET esp32s2) | ||
set(SDKCONFIG_DEFAULTS | ||
boards/sdkconfig.base | ||
boards/sdkconfig.spiram_sx | ||
boards/sdkconfig.usb | ||
) | ||
|
||
if(NOT MICROPY_FROZEN_MANIFEST) | ||
set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py) | ||
endif() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#define MICROPY_HW_BOARD_NAME "LOLIN_S2_PICO" | ||
#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) | ||
#define MICROPY_HW_SPI1_MISO (36) | ||
#define MICROPY_HW_SPI1_SCK (37) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CONFIG_FLASHMODE_QIO=y | ||
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y | ||
CONFIG_USB_AND_UART=y | ||
# LWIP | ||
CONFIG_LWIP_LOCAL_HOSTNAME="LOLIN_S2_PICO" | ||
# end of LWIP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to make this class name lowercase? Usually classes are upper camel case, which in this situation would be
LED
.Also, this is a very simple class and
machine.Pin
already provides the on/off methods. In my opinion it would be simpler to pre-create the LED object like this:Then the user can just do
s2mini.led.on()
.