Skip to content

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ports/esp32/boards/LOLIN_S2_MINI/manifest.py
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")
52 changes: 52 additions & 0 deletions ports/esp32/boards/LOLIN_S2_MINI/modules/s2mini.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:
Copy link
Member

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:

led = Pin(LED, Pin.OUT, value=0)

Then the user can just do s2mini.led.on().

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:
Copy link
Member

Choose a reason for hiding this comment

The 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)
10 changes: 10 additions & 0 deletions ports/esp32/boards/LOLIN_S2_MINI/mpconfigboard.cmake
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()
12 changes: 12 additions & 0 deletions ports/esp32/boards/LOLIN_S2_MINI/mpconfigboard.h
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)
6 changes: 6 additions & 0 deletions ports/esp32/boards/LOLIN_S2_MINI/sdkconfig.board
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
4 changes: 4 additions & 0 deletions ports/esp32/boards/LOLIN_S2_PICO/manifest.py
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")
104 changes: 104 additions & 0 deletions ports/esp32/boards/LOLIN_S2_PICO/modules/s2pico.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:
Copy link
Member

Choose a reason for hiding this comment

The 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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as for the other board, use button = Pin(BUTTON, Pin.IN, Pin.PULL_UP)

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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use OLED upper camel case.

def __init__(self):
self.reset()

# super().__init__(128,32,I2C(0))
Copy link
Member

Choose a reason for hiding this comment

The 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))
Copy link
Member

Choose a reason for hiding this comment

The 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):
Copy link
Member

Choose a reason for hiding this comment

The 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()
10 changes: 10 additions & 0 deletions ports/esp32/boards/LOLIN_S2_PICO/mpconfigboard.cmake
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()
12 changes: 12 additions & 0 deletions ports/esp32/boards/LOLIN_S2_PICO/mpconfigboard.h
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)
6 changes: 6 additions & 0 deletions ports/esp32/boards/LOLIN_S2_PICO/sdkconfig.board
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