4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

LovyanGFXからM5Unifiedに置き換えた

Last updated at Posted at 2023-05-21

以下を公開していましたが、LovyanGFXからM5Unifiedを使うように変更しました。

変更前:QuickJS_ESP32_IoT_Device

変更後:QuickJS_ESP32_IoT_Device_M5Unified

platformio.ini

(LovyanGFXの場合)

platformio.ini
	lovyan03/LovyanGFX@^0.5.0
	m5stack/M5StickC@^0.2.5 などなど

(M5Unifiedの場合)

platformio.ini
	m5stack/M5Unified@^0.1.6

include

(LovyanGFXの場合)

#include <M5Atom.h> など

(M5Unifiedの場合)

#include <M5Unified.h>

SDを使う場合
#include <SD.h>
#include <M5Unified.h>

初期化処理

(LovyanGFXの場合)

#if defined(ARDUINO_M5Stick_C)
  M5.begin(true, true, true);
#elif defined(ARDUINO_M5Stack_ATOM)
  M5.begin(true, true, false);
#elif defined(ARDUINO_M5STACK_FIRE)
  M5.begin(true, true, true, true);
#elif defined(ARDUINO_M5STACK_Core2)
  M5.begin(true, true, true, true);
#elif defined(ARDUINO_ESP32C3_DEV)
  Serial.begin(115200);
#elif defined(ARDUINO_ESP32C3U_DEV)
  Serial.begin(115200);
#elif defined(ARDUINO_ESP32S3_DEV)
  Serial.begin(115200);
#endif

(M5Unifiedの場合)

  auto cfg = M5.config();
  M5.begin(cfg);

SD

(LovyanGFXの場合)

対象外

(M5Unifiedの場合)

以下が必要

  bool ret = SD.begin(ssPin, SPI, SD_DEFAULT_FREQ);

RTC

(LovyanGFXの場合)

  M5.Rtc.begin();

(M5Unifiedの場合)

M5.Rtc.begin() は呼ばなくても大丈夫そう。

(LovyanGFXの場合)

  RTC_TimeTypeDef def;
  M5.Rtc.SetTime(&def);

  RTC_DateTypeDef def;
#if defined(ARDUINO_M5Stick_C)
  M5.Rtc.SetData(&def);
#elif defined(ARDUINO_M5STACK_Core2)
  M5.Rtc.SetDate(&def);
#endif

  RTC_TimeTypeDef def;
  M5.Rtc.GetTime(&def);

  RTC_DateTypeDef def;
#if defined(ARDUINO_M5Stick_C)
  M5.Rtc.GetData(&def);
#elif defined(ARDUINO_M5STACK_Core2)
  M5.Rtc.GetDate(&def);
#endif

(M5Unifiedの場合)

  m5::rtc_time_t def;
  M5.Rtc.setTime(&def);

  m5::rtc_date_t def;
  M5.Rtc.setDate(&def);

  m5::rtc_time_t def;
  M5.Rtc.getTime(&def);

  m5::rtc_date_t def;
  M5.Rtc.getDate(&def);

Lcd

(LovyanGFXの場合)

#define LGFX_USE_V1
#define LGFX_AUTODETECT
#include <LovyanGFX.hpp>
#include <LGFX_AUTODETECT.hpp>

LGFX lcd;

  lcd.init();

(M5Unifiedの場合)

不要

(LovyanGFXの場合)

lcd.***

(M5Unifiedの場合)

M5.Display.***;

電源ボタン

(LovyanGFXの場合)

M5.Axp.***

(M5Unifiedの場合)

M5.BtnPWR.***

タッチパネル

(LovyanGFXの場合)

  if( M5.Touch.ispressed() ){
    TouchPoint_t pos = M5.Touch.getPressPoint();

(M5Unifiedの場合)

  if( M5.Touch.getCount() > 0 ){
    m5::touch_detail_t pos = M5.Touch.getDetail();

IMU

(LovyanGFXの場合)

  float ax, ay, az;
#if defined(ARDUINO_ESP32S3_DEV)
  M5.IMU.getAccel(&ax, &ay, &az);
#else
  M5.IMU.getAccelData(&ax, &ay, &az);
#endif

  float gx, gy, gz;
#if defined(ARDUINO_ESP32S3_DEV)
  M5.IMU.getGyro(&gx, &gy, &gz);
#else
  M5.IMU.getGyroData(&gx, &gy, &gz);
#endif

#if defined(ARDUINO_ESP32S3_DEV)
  M5.IMU.getTemp(&t);
#else
  M5.IMU.getTempData(&t);
#endif

(M5Unifiedの場合)

  float ax, ay, az;
  M5.Imu.getAccel(&ax, &ay, &az);

  float gx, gy, gz;
  M5.Imu.getGyro(&gx, &gy, &gz);

  float t;
  M5.Imu.getTemp(&t);

スピーカー

(LovyanGFXの場合)

  M5.Axp.SetSpkEnable(true);

(M5Unifiedの場合)

  if( M5.Speaker.isEnabled() )
    M5.Speaker.begin();

以上

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?