diff --git a/ports/esp32/boards/LILYGO_TTGO_LORA32/board.json b/ports/esp32/boards/LILYGO_TTGO_LORA32/board.json new file mode 100644 index 0000000000..7f4b227abf --- /dev/null +++ b/ports/esp32/boards/LILYGO_TTGO_LORA32/board.json @@ -0,0 +1,23 @@ +{ + "deploy": [ + "../deploy.md" + ], + "docs": "", + "features": [ + "BLE", + "LoRa", + "OLED", + "SDCard", + "USB-MICRO", + "WiFi" + ], + "id": "esp32", + "images": [ + "lilygo-ttgo-lora-32-v1-6.jpg" + ], + "mcu": "esp32", + "product": "LILYGO TTGO LoRa32", + "thumbnail": "", + "url": "http://www.lilygo.cn/prod_view.aspx?TypeId=50060&Id=1270&FId=t3:50060:3", + "vendor": "LILYGO" +} diff --git a/ports/esp32/boards/LILYGO_TTGO_LORA32/board.md b/ports/esp32/boards/LILYGO_TTGO_LORA32/board.md new file mode 100644 index 0000000000..b7f5c21fec --- /dev/null +++ b/ports/esp32/boards/LILYGO_TTGO_LORA32/board.md @@ -0,0 +1,3 @@ +The following files are daily firmware for the LILYGO TTGO LoRa32. + +Support for hardware versions v1.0, v1.2, v1.6 and v2.0. diff --git a/ports/esp32/boards/LILYGO_TTGO_LORA32/manifest.py b/ports/esp32/boards/LILYGO_TTGO_LORA32/manifest.py new file mode 100644 index 0000000000..0709f8597c --- /dev/null +++ b/ports/esp32/boards/LILYGO_TTGO_LORA32/manifest.py @@ -0,0 +1,4 @@ +include("$(PORT_DIR)/boards/manifest.py") +freeze("modules") + +freeze("$(MPY_DIR)/drivers/display", "ssd1306.py") diff --git a/ports/esp32/boards/LILYGO_TTGO_LORA32/modules/lilygo_oled.py b/ports/esp32/boards/LILYGO_TTGO_LORA32/modules/lilygo_oled.py new file mode 100644 index 0000000000..58072ee1b5 --- /dev/null +++ b/ports/esp32/boards/LILYGO_TTGO_LORA32/modules/lilygo_oled.py @@ -0,0 +1,36 @@ +from time import sleep_ms +from ssd1306 import SSD1306_I2C +import network + + +class OLED(SSD1306_I2C): + def __init__(self, i2c): + super().__init__(128, 32, i2c) + + 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): + 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() diff --git a/ports/esp32/boards/LILYGO_TTGO_LORA32/modules/lora32.py b/ports/esp32/boards/LILYGO_TTGO_LORA32/modules/lora32.py new file mode 100644 index 0000000000..067982a228 --- /dev/null +++ b/ports/esp32/boards/LILYGO_TTGO_LORA32/modules/lora32.py @@ -0,0 +1,79 @@ +"""LILYGO TTGO LoRa32 MicroPython Helper Library.""" + +from machine import Pin, SoftI2C, Signal + +from lilygo_oled import OLED + +from micropython import const + + +class Lora32Base: + """Base class defining common pins.""" + + def __init__(self, define_helpers=True): + # LORA + self.LORA_MOSI = const(27) + self.LORA_MISO = const(19) + self.LORA_SCLK = const(5) + self.LORA_CS = const(18) + self.LORA_DIO = const(26) + self.LORA_RST = const(23) + + # DAC + self.DAC1 = const(26) + + # LED + self.LED = const(25) + + # OLED + self.OLED_SDA = const(21) + self.OLED_SCL = const(22) + + if define_helpers: + self.create_helpers() + + def create_helpers(self): + self.led = Pin(self.LED, Pin.OUT) + self.i2c = SoftI2C(scl=Pin(self.OLED_SCL), sda=Pin(self.OLED_SDA)) + self.oled = OLED(self.i2c) + + +class Lora32v1_0(Lora32Base): + """Device Support for LILYGO TTGO LoRa32 v1.0.""" + + def __init__(self): + super().__init__(define_helpers=False) + + # v1.0 has different pins for the following + self.LORA_RST = const(14) + self.OLED_SDA = const(4) + self.OLED_SCL = const(15) + + # Also has a reset for the OLED that the others don't have + self.OLED_RST = const(16) + + super().create_helpers() + + +class Lora32v1_2(Lora32Base): + """Device Support for LILYGO TTGO LoRa32 v1.2 (T-Fox).""" + + def __init__(self): + super().__init__() + + # v1.2 Has a DS3231 RTC + self.DS3231_SDA = const(21) + self.DS3231_SCL = const(22) + + +class Lora32(Lora32Base): + """Device Support for LILYGO TTGO LoRa32 v1.6 and v2.0.""" + + def __init__(self): + super().__init__() + + # v1.6 and v2.0 support an SDCard + self.SD_CS = const(13) + self.SD_MOSI = const(15) + self.SD_MISO = const(2) + self.SD_SCLK = const(14) diff --git a/ports/esp32/boards/LILYGO_TTGO_LORA32/mpconfigboard.cmake b/ports/esp32/boards/LILYGO_TTGO_LORA32/mpconfigboard.cmake new file mode 100644 index 0000000000..c35e4e0743 --- /dev/null +++ b/ports/esp32/boards/LILYGO_TTGO_LORA32/mpconfigboard.cmake @@ -0,0 +1,7 @@ +set(SDKCONFIG_DEFAULTS + boards/sdkconfig.base + boards/sdkconfig.ble +) +if(NOT MICROPY_FROZEN_MANIFEST) + set(MICROPY_FROZEN_MANIFEST ${MICROPY_BOARD_DIR}/manifest.py) +endif() diff --git a/ports/esp32/boards/LILYGO_TTGO_LORA32/mpconfigboard.h b/ports/esp32/boards/LILYGO_TTGO_LORA32/mpconfigboard.h new file mode 100644 index 0000000000..1c7b6fd557 --- /dev/null +++ b/ports/esp32/boards/LILYGO_TTGO_LORA32/mpconfigboard.h @@ -0,0 +1,2 @@ +#define MICROPY_HW_BOARD_NAME "LILYGO TTGO LoRa32" +#define MICROPY_HW_MCU_NAME "ESP32"