Skip to content

Commit

Permalink
tweak for PlatformIO platform=native
Browse files Browse the repository at this point in the history
  • Loading branch information
lovyan03 committed Jul 9, 2023
1 parent 445b603 commit efd95a8
Show file tree
Hide file tree
Showing 14 changed files with 470 additions and 159 deletions.
4 changes: 2 additions & 2 deletions examples/Sprite/ClockSample/ClockSample.ino
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ void loop(void)
{
static uint32_t p_milli = 0;
uint32_t milli = lgfx::millis() % 1000;
if (p_milli < milli) count += (milli - p_milli);
else count += 1000 + (milli - p_milli);
if (p_milli > milli) count += 1000 + (milli - p_milli);
else count += (milli - p_milli);
p_milli = milli;

int32_t tmp = (count % 1000) >> 3;
Expand Down
2 changes: 0 additions & 2 deletions examples/Sprite/MeterSample/MeterSample.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ static float zoom; // 表示倍率

void setup(void)
{
Serial.begin(115200);

lcd.init();
int lw = std::min(lcd.width(), lcd.height());

Expand Down
53 changes: 53 additions & 0 deletions examples_for_PC/PlatformIO_SDL/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

## Visual Studio Code + PlatformIO + SDL2 環境で LovyanGFXを使用する手順

まず最初にVisual Studio Code をインストールし、PlatformIO を使用できる状態にする。
この手順に関しては説明を省略。

---

次に、PlatformIOにて、 `platform = native` のビルドができる状態にする。

手順は下記 URL から `Installation` の項目を読んで実施する。
https://docs.platformio.org/en/latest/platforms/native.html#installation

---

### PlatformIOにて、 SDL2 が使用できる状態にする。

手順は下記 URL から `Install SDL2` の項目を読んで実施する。
https://docs.lvgl.io/latest/en/html/get-started/pc-simulator.html#install-sdl-2


#### Linuxの場合

apt-getでlibsdl2をインストールする。

```
sudo apt-get install libsdl2 libsdl2-dev
```

#### MacOS OSXの場合

Homebrewを使ってsdl2をインストールする。
```
brew install sdl2
```

#### Windowsの場合

`platform = native` のビルドを可能にする手順において、 msys2をインストール済みのはずなので、
githubの SDLのリポジトリにアクセスし、SDL2-devel-x.xx.x-mingw のリリースパッケージを入手する。
https://github.com/libsdl-org/SDL/releases

本記事作成時点のファイル名は `SDL2-devel-2.28.1-mingw.zip`
これを解凍し、出てきたフォルダの中にある `x86_64-w64-mingw32` フォルダを開き、中に以下の 4つのフォルダがあることを確認。
- share
- bin
- include
- lib

C:\msys64\mingw64\ を開き、上記の4つのフォルダと同名のフォルダが存在することを確認したら、C:\msys64\mingw64\ 内に上記フォルダの内容を追加する。(上書きコピー)



27 changes: 27 additions & 0 deletions examples_for_PC/PlatformIO_SDL/platformio.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env:native]
platform = native
build_type = debug
build_flags = -lSDL2

[esp32_base]
build_type = debug
platform = espressif32
board = esp32dev

[env:esp32_arduino]
extends = esp32_base
framework = arduino

[env:esp32_idf]
extends = esp32_base
framework = espidf
37 changes: 37 additions & 0 deletions examples_for_PC/PlatformIO_SDL/src/LGFX_SDL.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

#include <lgfx/v1/platforms/sdl/Panel_sdl.hpp>
#if defined ( SDL_h_ )
#include <thread>

void setup(void);
void loop(void);

static void loopThread(void)
{
setup();
SDL_Delay(5);
for (;;)
{
std::this_thread::yield();
loop();
}
}

#if __has_include(<windows.h>)
#include <windows.h>
#include <tchar.h>
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
#else
int main(int, char**)
#endif
{
std::thread sub_thread(loopThread);
for (;;)
{
std::this_thread::yield();
lgfx::Panel_sdl::sdl_event_handler();
SDL_Delay(5);
}
return 1;
}
#endif
98 changes: 98 additions & 0 deletions examples_for_PC/PlatformIO_SDL/src/user_code.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#define LGFX_AUTODETECT
#include <LGFX_AUTODETECT.hpp>

#if defined ( SDL_h_ )
static LGFX lcd ( 320, 240, 3 );
#else
static LGFX lcd;
#endif


static LGFX_Sprite sprite(&lcd);

struct meter_t
{
int32_t pivot_x;
int32_t pivot_y;

float angle = 0;
float add = 0;

void advance(void)
{
if ((angle >= 256 && add > 0.0)
|| (angle <= 0 && add < 0.0))
{
add = -add;
}
angle += add;
}

void drawGauge(uint32_t color)
{
lcd.setPivot(pivot_x, pivot_y);
sprite.setPaletteColor(1, color);
sprite.pushRotated(angle - 127);
advance();
}
};

struct meter_t meter1, meter2, meter3;

void setup(void)
{
lcd.init();

if (lcd.width() < lcd.height()) {
lcd.setRotation(lcd.getRotation() ^ 1);
}

sprite.setColorDepth(2);

sprite.createSprite(3,lcd.height() / 8);
sprite.setPivot(1, lcd.height() / 4);

sprite.drawFastVLine(1, 0, sprite.height() , 3);
sprite.drawFastVLine(0, 2, sprite.height() - 4, 1);

meter1.pivot_x = lcd.width() >> 1;
meter1.pivot_y = (lcd.height() >> 2) + 2;
meter1.add = 0.01;

meter2.pivot_x = lcd.width() >> 2;
meter2.pivot_y = (lcd.height() * 3) >>2;
meter2.add = 0.11;

meter3.pivot_x = (lcd.width() * 3) >> 2;
meter3.pivot_y = (lcd.height() * 3) >> 2;
meter3.add = 0.57;

lcd.fillScreen(lcd.color565(0,0,127));

for (int i = 0; i < 20; i++) {
lcd.drawFastHLine(0, (i*2+1) * lcd.height() / 40, lcd.width(), 0xFFFF);
lcd.drawFastVLine((i*2+1) * lcd.width() / 40, 0, lcd.height() , 0xFFFF);
}
}

void loop(void)
{
meter1.drawGauge(sprite.color888(255, meter1.angle, 127));
meter2.drawGauge(sprite.color888(255 - meter2.angle, meter2.angle, 127));
meter3.drawGauge(sprite.color888(0, 127, meter3.angle));
}



#if defined ( ESP_PLATFORM ) && !defined ( ARDUINO )
extern "C" {
int app_main(int, char**)
{
setup();
for (;;) {
loop();
}
return 0;
}
}
#endif
2 changes: 1 addition & 1 deletion src/lgfx/utility/lgfx_qoi.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ size_t lgfx_qoi_encode(const void *lineBuffer, const qoi_desc_t *desc, int flip,
writeBuffer = (uint8_t*)malloc(writeBufferSize);
if (!writeBuffer)
{
debug_printf( "Can't malloc %d bytes", writeBufferSize);
debug_printf( "Can't malloc %d bytes", (int)writeBufferSize);
return 0;
}

Expand Down
9 changes: 5 additions & 4 deletions src/lgfx/v1/LGFX_Sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,18 @@ namespace lgfx
uint8_t* dst = &_img[(x + y * bw) * bytes];
uint8_t* src = dst;
uint_fast16_t add_dst = bw * bytes;
uint_fast16_t len = w * bytes;
uint_fast32_t len = w * bytes;
uint_fast32_t w32 = w;

if (_img.use_memcpy())
{
if (w != bw)
if (w32 != bw)
{
dst += add_dst;
}
else
{
w *= h;
w32 *= h;
h = 1;
}
}
Expand All @@ -198,7 +199,7 @@ namespace lgfx
src = (uint8_t*)alloca(len);
++h;
}
memset_multi(src, rawcolor, bytes, w);
memset_multi(src, rawcolor, bytes, w32);
while (--h)
{
memcpy(dst, src, len);
Expand Down
Loading

0 comments on commit efd95a8

Please sign in to comment.