Skip to content

Commit

Permalink
Merge pull request #90 from m5stack/develop
Browse files Browse the repository at this point in the history
0.1.15
  • Loading branch information
lovyan03 authored Mar 31, 2024
2 parents 140d83f + 1bd1c8f commit b490abf
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 40 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "git",
"url": "https://github.com/m5stack/M5GFX.git"
},
"version": "0.1.14",
"version": "0.1.15",
"frameworks": ["arduino", "espidf", "*"],
"platforms": ["espressif32", "native"],
"headers": "M5GFX.h"
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=M5GFX
version=0.1.14
version=0.1.15
author=M5Stack
maintainer=M5Stack
sentence=Library for M5Stack All Display
Expand Down
7 changes: 6 additions & 1 deletion src/M5AtomDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include "lgfx/v1/panel/Panel_M5HDMI.hpp"
#include "M5GFX.h"

#if defined (SDL_h_) || defined (CONFIG_IDF_TARGET_ESP32S3) || defined (CONFIG_IDF_TARGET_ESP32) || !defined (CONFIG_IDF_TARGET)
#define M5ATOMDISPLAY_ENABLED
#endif

#ifndef M5ATOMDISPLAY_LOGICAL_WIDTH
#define M5ATOMDISPLAY_LOGICAL_WIDTH 1280
#endif
Expand Down Expand Up @@ -100,7 +104,8 @@ class M5AtomDisplay : public M5GFX
return true;
}

#if !defined (CONFIG_IDF_TARGET_ESP32C3)
#if defined (M5ATOMDISPLAY_ENABLED)
#undef M5ATOMDISPLAY_ENABLED

#if defined (SDL_h_)
auto p = new lgfx::Panel_sdl();
Expand Down
8 changes: 8 additions & 0 deletions src/M5GFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,8 @@ namespace m5gfx
{ // check panel (ST7789)
board = board_t::board_M5StickCPlus;
ESP_LOGI(LIBRARY_NAME, "[Autodetect] M5StickCPlus");
bus_spi->release();
bus_cfg.spi_host = HSPI_HOST;
bus_cfg.freq_write = 40000000;
bus_cfg.freq_read = 15000000;
bus_spi->config(bus_cfg);
Expand All @@ -661,6 +663,8 @@ namespace m5gfx
{ // check panel (ST7735)
board = board_t::board_M5StickC;
ESP_LOGI(LIBRARY_NAME, "[Autodetect] M5StickC");
bus_spi->release();
bus_cfg.spi_host = HSPI_HOST;
bus_cfg.freq_write = 27000000;
bus_cfg.freq_read = 14000000;
bus_spi->config(bus_cfg);
Expand Down Expand Up @@ -744,6 +748,8 @@ namespace m5gfx
_pin_level(GPIO_NUM_4, true); // POWER_HOLD_PIN 4
board = board_t::board_M5StickCPlus2;
ESP_LOGI(LIBRARY_NAME, "[Autodetect] M5StickCPlus2");
bus_spi->release();
bus_cfg.spi_host = HSPI_HOST;
bus_cfg.freq_write = 40000000;
bus_cfg.freq_read = 15000000;
bus_spi->config(bus_cfg);
Expand Down Expand Up @@ -811,6 +817,8 @@ namespace m5gfx
ESP_LOGI(LIBRARY_NAME, "[Autodetect] M5Station");
board = board_t::board_M5Station;

bus_spi->release();
bus_cfg.spi_host = HSPI_HOST;
bus_cfg.freq_write = 40000000;
bus_cfg.freq_read = 15000000;
bus_spi->config(bus_cfg);
Expand Down
10 changes: 8 additions & 2 deletions src/M5ModuleDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include "lgfx/v1/panel/Panel_M5HDMI.hpp"
#include "M5GFX.h"

#if defined (SDL_h_) || defined (CONFIG_IDF_TARGET_ESP32S3) || defined (CONFIG_IDF_TARGET_ESP32) || !defined (CONFIG_IDF_TARGET)
#define M5MODULEDISPLAY_ENABLED
#endif

#ifndef M5MODULEDISPLAY_LOGICAL_WIDTH
#define M5MODULEDISPLAY_LOGICAL_WIDTH 1280
#endif
Expand Down Expand Up @@ -100,7 +104,8 @@ class M5ModuleDisplay : public M5GFX
return true;
}

#if !defined (CONFIG_IDF_TARGET_ESP32C3)
#if defined (M5MODULEDISPLAY_ENABLED)
#undef M5MODULEDISPLAY_ENABLED

#if defined (SDL_h_)
auto p = new lgfx::Panel_sdl();
Expand Down Expand Up @@ -143,7 +148,8 @@ class M5ModuleDisplay : public M5GFX
int spi_mosi = GPIO_NUM_23;
int spi_sclk = GPIO_NUM_18;

if (0x03 == m5gfx::i2c::readRegister8(1, 0x34, 0x03, 400000))
auto axp_id = m5gfx::i2c::readRegister8(1, 0x34, 0x03, 400000);
if (axp_id == 0x03 || axp_id == 0x4A) // AXP192 & AXP2101
{ // M5Stack Core2 / Tough
#if defined ( ESP_LOGD )
ESP_LOGD("LGFX","ModuleDisplay with Core2/Tough");
Expand Down
1 change: 1 addition & 0 deletions src/lgfx/boards.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace lgfx // This should not be changed to "m5gfx"
, board_M5AtomS3Lite
, board_M5AtomS3U
, board_M5Capsule
, board_M5NanoC6

/// external displays
, board_M5AtomDisplay = 192
Expand Down
2 changes: 1 addition & 1 deletion src/lgfx/v1/gitTagVersion.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define LGFX_VERSION_MAJOR 1
#define LGFX_VERSION_MINOR 1
#define LGFX_VERSION_PATCH 14
#define LGFX_VERSION_PATCH 15
#define LOVYANGFX_VERSION F( LGFX_VERSION_MAJOR "." LGFX_VERSION_MINOR "." LGFX_VERSION_PATCH )
4 changes: 2 additions & 2 deletions src/lgfx/v1/platforms/esp32/Bus_I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ namespace lgfx
auto dev = &I2C0;
#endif

#if defined (CONFIG_IDF_TARGET_ESP32C3) || defined (CONFIG_IDF_TARGET_ESP32S3)
#if defined (CONFIG_IDF_TARGET_ESP32C3) || defined (CONFIG_IDF_TARGET_ESP32C6) || defined (CONFIG_IDF_TARGET_ESP32S3)
while (dev->sr.bus_busy) { taskYIELD(); }
#else
while (dev->status_reg.bus_busy) { taskYIELD(); }
Expand All @@ -119,7 +119,7 @@ namespace lgfx
auto dev = &I2C0;
#endif

#if defined (CONFIG_IDF_TARGET_ESP32C3) || defined (CONFIG_IDF_TARGET_ESP32S3)
#if defined (CONFIG_IDF_TARGET_ESP32C3) || defined (CONFIG_IDF_TARGET_ESP32C6) || defined (CONFIG_IDF_TARGET_ESP32S3)
return dev->sr.bus_busy;
#else
return dev->status_reg.bus_busy;
Expand Down
8 changes: 6 additions & 2 deletions src/lgfx/v1/platforms/esp32/Bus_SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,19 @@ Original Source:
#define SPI_PIN_REG SPI_MISC_REG
#endif

#if defined (SOC_GDMA_SUPPORTED) // for C3/S3
#if defined (SOC_GDMA_SUPPORTED) // for C3/C6/S3
#include <soc/gdma_channel.h>
#include <soc/gdma_reg.h>
#include <soc/gdma_struct.h>
#if !defined DMA_OUT_LINK_CH0_REG
#define DMA_OUT_LINK_CH0_REG GDMA_OUT_LINK_CH0_REG
#define DMA_OUTFIFO_STATUS_CH0_REG GDMA_OUTFIFO_STATUS_CH0_REG
#define DMA_OUTLINK_START_CH0 GDMA_OUTLINK_START_CH0
#define DMA_OUTFIFO_EMPTY_CH0 GDMA_OUTFIFO_EMPTY_L3_CH0
#if defined (GDMA_OUTFIFO_EMPTY_L3_CH0)
#define DMA_OUTFIFO_EMPTY_CH0 GDMA_OUTFIFO_EMPTY_L3_CH0
#else
#define DMA_OUTFIFO_EMPTY_CH0 GDMA_OUTFIFO_EMPTY_CH0
#endif
#endif
#endif

Expand Down
65 changes: 36 additions & 29 deletions src/lgfx/v1/platforms/esp32/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ Original Source:
#if (ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 3, 0))
#include <soc/syscon_reg.h>
#else
#include <soc/apb_ctrl_reg.h>
#if __has_include (<soc/apb_ctrl_reg.h>)
#include <soc/apb_ctrl_reg.h>
#endif
#endif
#include <soc/efuse_reg.h>

Expand Down Expand Up @@ -315,7 +317,12 @@ namespace lgfx
*io_mux_reg = io_mux_val;

GPIO.pin[pin].pad_driver = 0; // 1 = OpenDrain / 0 = normal output

#if defined (CONFIG_IDF_TARGET_ESP32C6)
GPIO.func_out_sel_cfg[pin].out_sel = SIG_GPIO_OUT_IDX;
#else
GPIO.func_out_sel_cfg[pin].func_sel = SIG_GPIO_OUT_IDX;
#endif
}

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -661,48 +668,48 @@ namespace lgfx

static i2c_dev_t* getDev(int num)
{
#if defined ( CONFIG_IDF_TARGET_ESP32C3 )
#if SOC_I2C_NUM == 1
return &I2C0;
#else
return num == 0 ? &I2C0 : &I2C1;
#endif
}

#if defined ( CONFIG_IDF_TARGET_ESP32C3 ) || defined ( CONFIG_IDF_TARGET_ESP32S3 )
#if defined ( CONFIG_IDF_TARGET_ESP32 ) || !defined ( CONFIG_IDF_TARGET )

static void updateDev(i2c_dev_t* dev)
{
dev->ctr.conf_upgate = 1;
}
static volatile uint32_t* getFifoAddr(int num)
{
#if defined ( CONFIG_IDF_TARGET_ESP32S3 )
return &(getDev(num)->data.val);
#else
return &(getDev(num)->fifo_data.val);
#endif
return (volatile uint32_t*)((num == 0) ? 0x6001301c : 0x6002701c);
}

static constexpr int i2c_cmd_start = 6;
static constexpr int i2c_cmd_start = 0;
static constexpr int i2c_cmd_write = 1;
static constexpr int i2c_cmd_read = 3;
static constexpr int i2c_cmd_stop = 2;
static constexpr int i2c_cmd_read = 2;
static constexpr int i2c_cmd_stop = 3;
static constexpr int i2c_cmd_end = 4;

#else

static void updateDev(i2c_dev_t* dev)
{
dev->ctr.conf_upgate = 1;
}
static volatile uint32_t* getFifoAddr(int num)
{
return (volatile uint32_t*)((num == 0) ? 0x6001301c : 0x6002701c);
#if defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
return &(getDev(num)->data.val);
#else
return &(getDev(num)->fifo_data.val);
#endif
}

static constexpr int i2c_cmd_start = 0;
static constexpr int i2c_cmd_start = 6;
static constexpr int i2c_cmd_write = 1;
static constexpr int i2c_cmd_read = 2;
static constexpr int i2c_cmd_stop = 3;
static constexpr int i2c_cmd_read = 3;
static constexpr int i2c_cmd_stop = 2;
static constexpr int i2c_cmd_end = 4;

#endif
Expand Down Expand Up @@ -742,7 +749,7 @@ namespace lgfx
void save_reg(i2c_dev_t* dev)
{
auto reg = (volatile uint32_t*)dev;
#if defined ( CONFIG_IDF_TARGET_ESP32S3 )
#if defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
auto fifo_reg = (volatile uint32_t*)(&dev->data);
#else
auto fifo_reg = (volatile uint32_t*)(&dev->fifo_data);
Expand All @@ -757,7 +764,7 @@ namespace lgfx
void load_reg(i2c_dev_t* dev)
{
auto reg = (volatile uint32_t*)dev;
#if defined ( CONFIG_IDF_TARGET_ESP32S3 )
#if defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
auto fifo_reg = (volatile uint32_t*)(&dev->data);
#else
auto fifo_reg = (volatile uint32_t*)(&dev->fifo_data);
Expand Down Expand Up @@ -801,7 +808,7 @@ namespace lgfx
{
#if defined ( CONFIG_IDF_TARGET_ESP32C3 )
return dev->sr.rx_fifo_cnt;
#elif defined ( CONFIG_IDF_TARGET_ESP32S3 )
#elif defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
return dev->sr.rxfifo_cnt;
#else
return dev->status_reg.rx_fifo_cnt;
Expand Down Expand Up @@ -910,7 +917,7 @@ namespace lgfx
uint32_t us;
#if defined ( CONFIG_IDF_TARGET_ESP32C3 )
uint32_t us_limit = (dev->scl_high_period.period + dev->scl_low_period.period + 16 ) * (1 + dev->sr.tx_fifo_cnt);
#elif defined ( CONFIG_IDF_TARGET_ESP32S3 )
#elif defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
uint32_t us_limit = (dev->scl_high_period.scl_high_period + dev->scl_low_period.scl_low_period + 16 ) * (1 + dev->sr.txfifo_cnt);
#else
uint32_t us_limit = (dev->scl_high_period.period + dev->scl_low_period.period + 16 ) * (1 + dev->status_reg.tx_fifo_cnt);
Expand All @@ -928,7 +935,7 @@ namespace lgfx
dev->int_clr.val = int_raw.val;
#if !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32)
if (!int_raw.end_detect || int_raw.ack_err)
#elif defined ( CONFIG_IDF_TARGET_ESP32S3 )
#elif defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
if (!int_raw.end_detect_int_raw || int_raw.nack_int_raw)
#else
if (!int_raw.end_detect || int_raw.nack)
Expand All @@ -942,7 +949,7 @@ namespace lgfx

if (flg_stop || res.has_error())
{
#if defined ( CONFIG_IDF_TARGET_ESP32S3 )
#if defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
if (i2c_context[i2c_port].state == i2c_context_t::state_read || !int_raw.end_detect_int_raw)
#else
if (i2c_context[i2c_port].state == i2c_context_t::state_read || !int_raw.end_detect)
Expand All @@ -961,7 +968,7 @@ namespace lgfx
while (!(dev->int_raw.val & intmask_) && ((millis() - ms) < 14));
#if !defined (CONFIG_IDF_TARGET) || defined (CONFIG_IDF_TARGET_ESP32)
if (res.has_value() && dev->int_raw.ack_err)
#elif defined ( CONFIG_IDF_TARGET_ESP32S3 )
#elif defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
if (res.has_value() && dev->int_raw.nack_int_raw)
#else
if (res.has_value() && dev->int_raw.nack)
Expand Down Expand Up @@ -1124,7 +1131,7 @@ namespace lgfx
{
i2c_context[i2c_port].freq = freq;
static constexpr uint32_t MIN_I2C_CYCLE = 35;
#if defined (CONFIG_IDF_TARGET_ESP32C3) || defined (CONFIG_IDF_TARGET_ESP32S3)
#if defined (CONFIG_IDF_TARGET_ESP32C3) || defined (CONFIG_IDF_TARGET_ESP32S3) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
uint32_t src_clock = 40 * 1000 * 1000; // XTAL clock
#else
rtc_cpu_freq_config_t cpu_freq_conf;
Expand Down Expand Up @@ -1186,7 +1193,7 @@ namespace lgfx
cycle = (1<<10)-1;
}

#if defined (CONFIG_IDF_TARGET_ESP32S3)
#if defined (CONFIG_IDF_TARGET_ESP32S3) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
auto wait_high = scl_high_period >> 2;
dev->scl_high_period.scl_high_period = scl_high_period - wait_high;
dev->scl_high_period.scl_wait_high_period = wait_high;
Expand Down Expand Up @@ -1236,7 +1243,7 @@ namespace lgfx
auto dev = getDev(i2c_port);
i2c_context[i2c_port].lock();

#if defined ( CONFIG_IDF_TARGET_ESP32C3 ) || defined ( CONFIG_IDF_TARGET_ESP32S3 )
#if defined ( CONFIG_IDF_TARGET_ESP32C3 ) || defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
if (dev->sr.bus_busy)
#else
if (dev->status_reg.bus_busy)
Expand All @@ -1248,7 +1255,7 @@ namespace lgfx
{
taskYIELD();
}
#if defined ( CONFIG_IDF_TARGET_ESP32C3 ) || defined ( CONFIG_IDF_TARGET_ESP32S3 )
#if defined ( CONFIG_IDF_TARGET_ESP32C3 ) || defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
while (dev->sr.bus_busy && micros() - ms < 128);
#else
while (dev->status_reg.bus_busy && micros() - ms < 128);
Expand All @@ -1265,7 +1272,7 @@ namespace lgfx
#if defined ( CONFIG_IDF_TARGET_ESP32C3 )
dev->timeout.time_out_value = 31;
dev->timeout.time_out_en = 1;
#elif defined ( CONFIG_IDF_TARGET_ESP32S3 )
#elif defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
dev->to.time_out_value = 31;
dev->to.time_out_en = 1;
#else
Expand Down Expand Up @@ -1354,7 +1361,7 @@ namespace lgfx
auto dev = getDev(i2c_port);

size_t len = 0;
#if defined ( CONFIG_IDF_TARGET_ESP32S3 )
#if defined ( CONFIG_IDF_TARGET_ESP32S3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
uint32_t us_limit = ((dev->scl_high_period.scl_high_period + dev->scl_high_period.scl_wait_high_period + dev->scl_low_period.scl_low_period) << 1);
#elif defined ( CONFIG_IDF_TARGET_ESP32C3 )
uint32_t us_limit = ((dev->scl_high_period.period + dev->scl_low_period.period) << 1);
Expand Down
2 changes: 1 addition & 1 deletion src/lgfx/v1/platforms/esp32/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ namespace lgfx
pinMode(pin, mode);
}

#if defined ( CONFIG_IDF_TARGET_ESP32C3 )
#if defined ( CONFIG_IDF_TARGET_ESP32C3 ) || defined ( CONFIG_IDF_TARGET_ESP32C6 )
static inline volatile uint32_t* get_gpio_hi_reg(int_fast8_t pin) { return &GPIO.out_w1ts.val; }
static inline volatile uint32_t* get_gpio_lo_reg(int_fast8_t pin) { return &GPIO.out_w1tc.val; }
static inline bool gpio_in(int_fast8_t pin) { return GPIO.in.val & (1 << (pin & 31)); }
Expand Down

0 comments on commit b490abf

Please sign in to comment.