Skip to content

Commit

Permalink
Merge pull request #337 from lyusupov/master
Browse files Browse the repository at this point in the history
Add LilyGO T-TWR Plus
  • Loading branch information
hathach authored Jul 20, 2023
2 parents 02c8e3a + 3779a96 commit 196129e
Show file tree
Hide file tree
Showing 6 changed files with 305 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/build_esp32.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ jobs:
- 'espressif_esp32s3_devkitc_1'
- 'espressif_esp32s3_devkitm_1'
- 'espressif_esp32s3_eye'
- 'lilygo_ttgo_t_twr_plus'
- 'lilygo_ttgo_tbeam_s3'
- 'lolin_s3'
- 'm5stack_atoms3'
Expand Down
5 changes: 5 additions & 0 deletions ports/espressif/boards/lilygo_ttgo_t_twr_plus/board.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Apply board specific content here
set(IDF_TARGET "esp32s3")

set(BOARD_SOURCES "${BOARD}/board.cpp")
#set(BOARD_COMPONENTS "ssd1306 XPowersLib")
186 changes: 186 additions & 0 deletions ports/espressif/boards/lilygo_ttgo_t_twr_plus/board.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@

#include <stdbool.h>
#include "board_api.h"


#if CONFIG_SSD1306_128x64
#include "esp_log.h"
#include "sdkconfig.h"
#include "driver/gpio.h"
#include "driver/i2c.h"


#include "ssd1306.h"
#include "font8x8_basic.h"

#define tag "SSD1306"
#endif

#ifdef CONFIG_XPOWERS_CHIP_AXP2102

#define XPOWERS_CHIP_AXP2102
#include "XPowersLib.h"
static const char *TAG = "AXP2101";

static XPowersPMU PMU;

#endif /* CONFIG_XPOWERS_CHIP_AXP2102 */

#define I2C_MASTER_NUM 1
#define I2C_MASTER_FREQ_HZ 100000 /*!< I2C master clock frequency */
#define I2C_MASTER_SDA_IO (gpio_num_t) 8
#define I2C_MASTER_SCL_IO (gpio_num_t) 9


#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define I2C_MASTER_TIMEOUT_MS 1000

#define WRITE_BIT I2C_MASTER_WRITE /*!< I2C master write */
#define READ_BIT I2C_MASTER_READ /*!< I2C master read */
#define ACK_CHECK_EN 0x1 /*!< I2C master will check ack from slave*/
#define ACK_CHECK_DIS 0x0 /*!< I2C master will not check ack from slave */
#define ACK_VAL (i2c_ack_type_t)0x0 /*!< I2C ack value */
#define NACK_VAL (i2c_ack_type_t)0x1 /*!< I2C nack value */

/**
* @brief Read a sequence of bytes from a pmu registers
*/
int pmu_register_read(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint8_t len)
{
if (len == 0) {
return ESP_OK;
}
if (data == NULL) {
return ESP_FAIL;
}
i2c_cmd_handle_t cmd;

cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (devAddr << 1) | WRITE_BIT, ACK_CHECK_EN);
i2c_master_write_byte(cmd, regAddr, ACK_CHECK_EN);
i2c_master_stop(cmd);
esp_err_t ret = i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "PMU i2c_master_cmd_begin FAILED! > ");
return ESP_FAIL;
}
cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (devAddr << 1) | READ_BIT, ACK_CHECK_EN);
if (len > 1) {
i2c_master_read(cmd, data, len - 1, ACK_VAL);
}
i2c_master_read_byte(cmd, &data[len - 1], NACK_VAL);
i2c_master_stop(cmd);
ret = i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "PMU READ FAILED! > ");
}
return ret == ESP_OK ? 0 : -1;
}

/**
* @brief Write a byte to a pmu register
*/
int pmu_register_write_byte(uint8_t devAddr, uint8_t regAddr, uint8_t *data, uint8_t len)
{
if (data == NULL) {
return ESP_FAIL;
}
i2c_cmd_handle_t cmd = i2c_cmd_link_create();
i2c_master_start(cmd);
i2c_master_write_byte(cmd, (devAddr << 1) | I2C_MASTER_WRITE, ACK_CHECK_EN);
i2c_master_write_byte(cmd, regAddr, ACK_CHECK_EN);
i2c_master_write(cmd, data, len, ACK_CHECK_EN);
i2c_master_stop(cmd);
esp_err_t ret = i2c_master_cmd_begin(I2C_MASTER_NUM, cmd, 1000 / portTICK_RATE_MS);
i2c_cmd_link_delete(cmd);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "PMU WRITE FAILED! < ");
}
return ret == ESP_OK ? 0 : -1;
}

extern "C" bool board_init_extension()
{
SSD1306_t dev;

i2c_config_t i2c_conf ;
memset(&i2c_conf, 0, sizeof(i2c_conf));
i2c_conf.mode = I2C_MODE_MASTER;
i2c_conf.sda_io_num = I2C_MASTER_SDA_IO;
i2c_conf.scl_io_num = I2C_MASTER_SCL_IO;
i2c_conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
i2c_conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
i2c_conf.master.clk_speed = I2C_MASTER_FREQ_HZ;
i2c_param_config(I2C_MASTER_NUM, &i2c_conf);
i2c_driver_install(I2C_MASTER_NUM, i2c_conf.mode,
I2C_MASTER_RX_BUF_DISABLE, I2C_MASTER_TX_BUF_DISABLE, 0);

if (PMU.begin(AXP2101_SLAVE_ADDRESS, pmu_register_read, pmu_register_write_byte)) {

ESP_LOGI(TAG, "Init PMU SUCCESS!");

//Turn off not use power channel
PMU.disableDC2();
PMU.disableDC3();
PMU.disableDC4();
PMU.disableDC5();

PMU.disableALDO1();
PMU.disableALDO2();
PMU.disableALDO3();
PMU.disableALDO4();
PMU.disableBLDO1();
PMU.disableBLDO2();

PMU.setDC1Voltage(3300); // WROOM, OLED
PMU.enableDC1();

PMU.setDC3Voltage(3400); // SA868, NeoPixel
PMU.enableDC3();

/* no power for GNSS and/or Mic at this moment */

// uSD
PMU.setALDO2Voltage(3300);
PMU.enableALDO2();

// use X axis offset for SH1106 OLED
dev._offset = CONFIG_OFFSETX;

} else {
ESP_LOGE(TAG, "Init PMU FAILED!");

// use no offset with SSD1306 OLED
dev._offset = 0;
}

#if CONFIG_I2C_INTERFACE
i2c_master_init(&dev, I2C_MASTER_SDA_IO, I2C_MASTER_SCL_IO, -1);
#endif // CONFIG_I2C_INTERFACE

#if CONFIG_FLIP
dev._flip = true;
ESP_LOGW(tag, "Flip upside down");
#endif

ESP_LOGI(tag, "Panel is 128x64");
ssd1306_init(&dev, 128, 64);

ssd1306_clear_screen(&dev, false);
ssd1306_contrast(&dev, 0xff);

ssd1306_display_text(&dev, 1, " T-TWR Plus Boot", 16, true);
ssd1306_display_text(&dev, 4, "Put UF2 firmware", 16, false);
ssd1306_display_text(&dev, 6, "on " UF2_VOLUME_LABEL " Vol", 16, false);

//ssd1306_clear_line(&dev, 5, false);

return true;
}

72 changes: 72 additions & 0 deletions ports/espressif/boards/lilygo_ttgo_t_twr_plus/board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2020 Ha Thach (tinyusb.org) for Adafruit Industries
* Copyright (c) 2023 Linar Yusupov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#pragma once

#define BOARD_INIT_CUSTOM 1

//--------------------------------------------------------------------+
// Button
//--------------------------------------------------------------------+

// Enter UF2 mode if GPIO is pressed while 2nd stage bootloader indicator
// is on e.g RGB = Purple. If it is GPIO0, user should not hold this while
// reset since that will instead run the 1st stage ROM bootloader
#define PIN_BUTTON_UF2 0

// Initial delay in milliseconds to detect user interaction to enter UF2
#define UF2_DETECTION_DELAY_MS 1000

//--------------------------------------------------------------------+
// LED
//--------------------------------------------------------------------+

// GPIO connected to Neopixel data
#define NEOPIXEL_PIN 42

// Brightness percentage from 1 to 255
#define NEOPIXEL_BRIGHTNESS 0x10

// Number of neopixels
#define NEOPIXEL_NUMBER 1

// LED for indicator and writing flash
// If not defined neopixel will be use for flash writing instead
//#define LED_PIN 7
//#define LED_STATE_ON 1

//--------------------------------------------------------------------+
// USB UF2
//--------------------------------------------------------------------+

#define USB_VID 0x303A // Espressif VID
#define USB_PID 0x8191 // Espressif assigned PID
#define USB_MANUFACTURER "LilyGO"
#define USB_PRODUCT "T-TWR Plus"

#define UF2_PRODUCT_NAME USB_MANUFACTURER " " USB_PRODUCT
#define UF2_BOARD_ID "ESP32S3-TWR-v2.0"
#define UF2_VOLUME_LABEL "TWRBOOT"
#define UF2_INDEX_URL "https://www.lilygo.cc/products/t-twr-plus"
40 changes: 40 additions & 0 deletions ports/espressif/boards/lilygo_ttgo_t_twr_plus/sdkconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Board Specific Config

# Partition Table
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions-16MB.csv"

# Serial flasher config
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y

#
# XPowersLib Configuration
#
#CONFIG_XPOWERS_CHIP_AXP2102=y
# CONFIG_XPOWERS_CHIP_AXP192 is not set
#CONFIG_I2C_MASTER_PORT_NUM=1
#CONFIG_I2C_MASTER_FREQUENCY=100000
#CONFIG_PMU_I2C_SCL=9
#CONFIG_PMU_I2C_SDA=8
#CONFIG_PMU_INTERRUPT_PIN=4
# end of XPowersLib Configuration

#
# SSD1306 Configuration
#
#CONFIG_GPIO_RANGE_MAX=48
#CONFIG_I2C_INTERFACE=y
# CONFIG_SPI_INTERFACE is not set
# CONFIG_SSD1306_128x32 is not set
#CONFIG_SSD1306_128x64=y

# SSD1306
#CONFIG_OFFSETX=0

# SH1106
#CONFIG_OFFSETX=2

# CONFIG_FLIP is not set
#CONFIG_SCL_GPIO=9
#CONFIG_SDA_GPIO=8
#CONFIG_RESET_GPIO=-1
# end of SSD1306 Configuration
2 changes: 1 addition & 1 deletion ports/espressif/boards/lilygo_ttgo_tbeam_s3/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@
#define UF2_PRODUCT_NAME USB_MANUFACTURER " " USB_PRODUCT
#define UF2_BOARD_ID "ESP32S3-TBeam-v3.0"
#define UF2_VOLUME_LABEL "TBEAMBOOT"
#define UF2_INDEX_URL "http://www.lilygo.cn/claprod_view.aspx?Id=1163"
#define UF2_INDEX_URL "https://www.lilygo.cc/products/softrf-t-beamsupreme"

0 comments on commit 196129e

Please sign in to comment.