Skip to content
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

Add pico-sdk support #625

Merged
merged 3 commits into from
Oct 4, 2024
Merged
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
42 changes: 9 additions & 33 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,38 +1,14 @@
# CMakeLists for ESP-IDF
set (LGFX_ROOT ${CMAKE_CURRENT_LIST_DIR})

set(COMPONENT_ADD_INCLUDEDIRS
src
)
file(GLOB SRCS
src/lgfx/Fonts/efont/*.c
src/lgfx/Fonts/IPA/*.c
src/lgfx/utility/*.c
src/lgfx/v1/*.cpp
src/lgfx/v1/misc/*.cpp
src/lgfx/v1/panel/*.cpp
src/lgfx/v1/platforms/arduino_default/*.cpp
src/lgfx/v1/platforms/esp32/*.cpp
src/lgfx/v1/platforms/esp32c3/*.cpp
src/lgfx/v1/platforms/esp32s2/*.cpp
src/lgfx/v1/platforms/esp32s3/*.cpp
src/lgfx/v1/touch/*.cpp
)
# Espressif ESP* based boards
if (DEFINED ESP_PLATFORM)
include(${LGFX_ROOT}/boards.cmake/esp-idf.cmake)

set(COMPONENT_SRCS ${SRCS})
# Raspberry Pi RP* based boards
elseif ((DEFINED PICO_PLATFORM) OR (DEFINED PICO_BOARD))
include(${LGFX_ROOT}/boards.cmake/pico-sdk.cmake)

if (IDF_VERSION_MAJOR GREATER_EQUAL 5)
set(COMPONENT_REQUIRES nvs_flash efuse esp_lcd driver esp_timer)
elseif ((IDF_VERSION_MAJOR EQUAL 4) AND (IDF_VERSION_MINOR GREATER 3) OR IDF_VERSION_MAJOR GREATER 4)
set(COMPONENT_REQUIRES nvs_flash efuse esp_lcd)
# Cannot determine boards type
else()
set(COMPONENT_REQUIRES nvs_flash efuse)
message("Error: No platform specified")
endif()


### If you use arduino-esp32 components, please activate next comment line.
# list(APPEND COMPONENT_REQUIRES arduino-esp32)


message(STATUS "LovyanGFX use components = ${COMPONENT_REQUIRES}")

register_component()
38 changes: 38 additions & 0 deletions boards.cmake/esp-idf.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# CMakeLists for ESP-IDF

set(COMPONENT_ADD_INCLUDEDIRS
${LGFX_ROOT}/src
)
file(GLOB SRCS
${LGFX_ROOT}/src/lgfx/Fonts/efont/*.c
${LGFX_ROOT}/src/lgfx/Fonts/IPA/*.c
${LGFX_ROOT}/src/lgfx/utility/*.c
${LGFX_ROOT}/src/lgfx/v1/*.cpp
${LGFX_ROOT}/src/lgfx/v1/misc/*.cpp
${LGFX_ROOT}/src/lgfx/v1/panel/*.cpp
${LGFX_ROOT}/src/lgfx/v1/platforms/arduino_default/*.cpp
${LGFX_ROOT}/src/lgfx/v1/platforms/esp32/*.cpp
${LGFX_ROOT}/src/lgfx/v1/platforms/esp32c3/*.cpp
${LGFX_ROOT}/src/lgfx/v1/platforms/esp32s2/*.cpp
${LGFX_ROOT}/src/lgfx/v1/platforms/esp32s3/*.cpp
${LGFX_ROOT}/src/lgfx/v1/touch/*.cpp
)

set(COMPONENT_SRCS ${SRCS})

if (IDF_VERSION_MAJOR GREATER_EQUAL 5)
set(COMPONENT_REQUIRES nvs_flash efuse esp_lcd driver esp_timer)
elseif ((IDF_VERSION_MAJOR EQUAL 4) AND (IDF_VERSION_MINOR GREATER 3) OR IDF_VERSION_MAJOR GREATER 4)
set(COMPONENT_REQUIRES nvs_flash efuse esp_lcd)
else()
set(COMPONENT_REQUIRES nvs_flash efuse)
endif()


### If you use arduino-esp32 components, please activate next comment line.
# list(APPEND COMPONENT_REQUIRES arduino-esp32)


message(STATUS "LovyanGFX use components = ${COMPONENT_REQUIRES}")

register_component()
50 changes: 50 additions & 0 deletions boards.cmake/pico-sdk.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# CMakeLists for PICO SDK

include(${PICO_SDK_PATH}/external/pico_sdk_import.cmake)

pico_sdk_init()

add_compile_definitions(
USE_PICO_SDK=1
)

# pico_add_library()
add_library(LovyanGFX_headers INTERFACE)
add_library(LovyanGFX INTERFACE)

target_include_directories(
LovyanGFX_headers INTERFACE
src
)

#add_compile_definitions
target_compile_definitions(LovyanGFX INTERFACE
USE_PICO_SDK
)

file(GLOB SRCS
src/lgfx/Fonts/efont/*.c
src/lgfx/Fonts/IPA/*.c
src/lgfx/utility/*.c
src/lgfx/v1/*.cpp
src/lgfx/v1/misc/*.cpp
src/lgfx/v1/panel/*.cpp
src/lgfx/v1/platforms/arduino_default/*.cpp
src/lgfx/v1/platforms/rp2040/*.cpp
src/lgfx/v1/touch/*.cpp
)
target_sources(LovyanGFX INTERFACE ${SRCS})
target_link_libraries(LovyanGFX INTERFACE
LovyanGFX_headers
pico_stdlib
pico_float
pico_double
hardware_dma
hardware_gpio
hardware_spi
hardware_i2c
hardware_pwm
)

pico_enable_stdio_usb(LovyanGFX 0)
pico_enable_stdio_uart(LovyanGFX 1)
61 changes: 61 additions & 0 deletions examples_for_picosdk/i2c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#
# Usage:
#
# 1. Copy this directory outside "LovyanGFX" directory
#
# 2. Set variables below (in environment variables or CMakeLists.txt)
# PICO_SDK_PATH
# PICO_PLATFORM (rp2040,rp2350-arm-s)
# PICO_BOARD (optional, "pico", "pico2",...)
#
# 3. Copy "LovyanGFX" directory to this directory)
#
# 4. mkdir and cd build directory
#
# 5. run cmake
#

set (PROJ_NAME i2c_test)

cmake_minimum_required(VERSION 3.13)

if (NOT (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/LovyanGFX))
message(FATAL_ERROR "Please copy \"LovyanGFX\" directory to \"${CMAKE_CURRENT_SOURCE_DIR}\".")
endif()


include(../pico_sdk_import.cmake)
include(../pico_extras_import_optional.cmake)

project(${PROJ_NAME}
C
CXX
ASM
)

set(CMAKE_C_STNDARD 11)
set(CMAKE_CXX_STANDARD 17)

pico_sdk_init()

add_subdirectory(
LovyanGFX
)

add_executable(${PROJ_NAME}
main.cpp
)

target_include_directories(${PROJ_NAME} PRIVATE
.
)

pico_enable_stdio_usb(${PROJ_NAME} 0)
pico_enable_stdio_uart(${PROJ_NAME} 1)

pico_add_extra_outputs(${PROJ_NAME})

target_link_libraries(${PROJ_NAME}
pico_stdlib
LovyanGFX
)
52 changes: 52 additions & 0 deletions examples_for_picosdk/i2c/LGFX_config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <LovyanGFX.hpp>

// SSD1306 (128x64) の接続設定例
#define TFT_SDA 12
#define TFT_SCL 13
#define I2C_PORT 0
#define I2C_ADDR 0x3c

class LGFX : public lgfx::LGFX_Device
{
lgfx::Panel_SSD1306 _panel_instance;
lgfx::Bus_I2C _bus_instance; // I2Cバスのインスタンス
public:
LGFX(void)
{
{ // バス制御の設定を行います。
auto cfg = _bus_instance.config(); // バス設定用の構造体を取得します。

// I2Cバスの設定
cfg.i2c_port = I2C_PORT; // 使用するI2Cポートを選択 (0 or 1)
cfg.freq_write = 400000; // 送信時のクロック
cfg.freq_read = 400000; // 受信時のクロック
cfg.pin_sda = TFT_SDA; // SDAを接続しているピン番号
cfg.pin_scl = TFT_SCL; // SCLを接続しているピン番号
cfg.i2c_addr = I2C_ADDR; // I2Cデバイスのアドレス

_bus_instance.config(cfg); // 設定値をバスに反映します。
_panel_instance.setBus(&_bus_instance); // バスをパネルにセットします。
}

{ // 表示パネル制御の設定を行います。
auto cfg = _panel_instance.config(); // 表示パネル設定用の構造体を取得します。

cfg.pin_cs = -1; // CSが接続されているピン番号 (-1 = disable)
cfg.pin_rst = -1; // RSTが接続されているピン番号 (-1 = disable)
cfg.pin_busy = -1; // BUSYが接続されているピン番号 (-1 = disable)

cfg.panel_width = 128; // 実際に表示可能な幅
cfg.panel_height = 64; // 実際に表示可能な高さ
//cfg.offset_x = 0; // パネルのX方向オフセット量
//cfg.offset_y = 0; // パネルのY方向オフセット量

// cfg.offset_rotation = 4; // 回転方向の値のオフセット 0~7 (4~7は上下反転)
// cfg.invert = true; // パネルの明暗が反転してしまう場合 trueに設定
// cfg.rgb_order = true; // パネルの赤と青が入れ替わってしまう場合 trueに設定

_panel_instance.config(cfg);
}

setPanel(&_panel_instance); // 使用するパネルをセットします。
}
};
Loading
Loading