Skip to content

Commit

Permalink
Merge pull request #14 from m5stack/develop
Browse files Browse the repository at this point in the history
0.0.6
  • Loading branch information
lovyan03 authored Sep 3, 2021
2 parents 8881a42 + 18b5564 commit 67f0fe2
Show file tree
Hide file tree
Showing 117 changed files with 9,379 additions and 5,993 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.0.5",
"version": "0.0.6",
"framework": "arduino",
"platforms": "espressif32"
}
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.0.5
version=0.0.6
author=M5Stack
maintainer=M5Stack
sentence=Library for M5Stack All Display
Expand Down
13 changes: 5 additions & 8 deletions src/M5GFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ namespace m5gfx
nvs_board = board_t::board_M5Tough;

#elif defined ( ARDUINO_M5Stack_ATOM )
#elif defined ( ARDUINO_M5Stack_Timer_CAM )
//#elif defined ( ARDUINO_M5Stack_Timer_CAM )
#endif
}

Expand Down Expand Up @@ -473,8 +473,8 @@ namespace m5gfx
{ // check panel (ST7789)
board = board_t::board_M5StickCPlus;
ESP_LOGW(LIBRARY_NAME, "[Autodetect] M5StickCPlus");
bus_cfg.freq_write = 80000000;
bus_cfg.freq_read = 16000000;
bus_cfg.freq_write = 40000000;
bus_cfg.freq_read = 15000000;
_bus_spi.config(bus_cfg);
auto p = new Panel_M5StickCPlus();
p->bus(&_bus_spi);
Expand Down Expand Up @@ -730,10 +730,9 @@ namespace m5gfx
cfg.i2c_port = I2C_NUM_1;// I2C port number
cfg.freq = 400000; // I2C freq
cfg.x_min = 0;
cfg.x_max = 239;
cfg.x_max = 319;
cfg.y_min = 0;
cfg.y_max = 319;
cfg.offset_rotation = 2;
cfg.y_max = 239;
t->config(cfg);
p->touch(t);
lgfx::i2c::writeRegister8(axp_i2c_port, axp_i2c_addr, 0x94, 0x02, ~0, axp_i2c_freq); // GPIO1 HIGH (TOUCH RST)
Expand Down Expand Up @@ -772,7 +771,6 @@ ESP_LOGI("nvs_board","_board:%d", board);
s.metrics = _font_metrics;
s.cursor_x = _cursor_x;
s.cursor_y = _cursor_y;
s.padX = _padding_x;
_displayStateStack.push_back(s);
}

Expand All @@ -784,7 +782,6 @@ ESP_LOGI("nvs_board","_board:%d", board);
_font = s.gfxFont;
_text_style = s.style;
_font_metrics = s.metrics;
_padding_x = s.padX;
_cursor_x = s.cursor_x;
_cursor_y = s.cursor_y;
}
Expand Down
15 changes: 14 additions & 1 deletion src/M5GFX.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ namespace m5gfx
, board_M5StackCoreInk
, board_M5Paper
, board_M5Tough
, board_M5ATOM
};
}
using board_t = boards::board_t;
Expand All @@ -156,7 +157,7 @@ namespace m5gfx
const lgfx::IFont *gfxFont;
lgfx::TextStyle style;
lgfx::FontMetrics metrics;
int32_t cursor_x, cursor_y, padX;
int32_t cursor_x, cursor_y;
};

lgfx::Bus_SPI _bus_spi;
Expand All @@ -182,6 +183,18 @@ namespace m5gfx
void progressBar(int x, int y, int w, int h, uint8_t val);
void pushState(void);
void popState(void);

/// draw RGB565 format image.
void drawBitmap(int16_t x, int16_t y, int16_t w, int16_t h, const void *data)
{
pushImage(x, y, w, h, (const rgb565_t*)data);
}

/// draw RGB565 format image, with transparent color.
void drawBitmap(int16_t x, int16_t y, int16_t w, int16_t h, const void *data, uint16_t transparent)
{
pushImage(x, y, w, h, (const rgb565_t*)data, transparent);
}
};


Expand Down
34 changes: 34 additions & 0 deletions src/lgfx/internal/algorithm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#if defined ( CONFIG_ARCH_BOARD_SPRESENSE )
#include <Arduino.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef atof
#undef atof
#endif
#ifdef atoi
#undef atoi
#endif
#ifdef atol
#undef atol
#endif
__attribute__((weak)) float atof(const char* nptr) { return strtod((nptr), NULL); }
__attribute__((weak)) int atoi(const char* nptr) { return (int)strtol((nptr), NULL, 10); }
__attribute__((weak)) long atol(const char* nptr) { return strtol((nptr), NULL, 10); }
__attribute__((weak)) int mblen(const char*, size_t) { return 0; }
__attribute__((weak)) size_t mbstowcs(wchar_t*, const char*, size_t) { return 0; }
__attribute__((weak)) int mbtowc(wchar_t*, const char*, size_t) { return 0; }
__attribute__((weak)) size_t wcstombs(char*, const wchar_t*, size_t) { return 0; }
__attribute__((weak)) int wctomb(char*, wchar_t) { return 0; }

#ifdef max
#undef max
#endif

#ifdef min
#undef min
#endif

#endif
#include <algorithm>
13 changes: 13 additions & 0 deletions src/lgfx/internal/limits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#if defined ( CONFIG_ARCH_BOARD_SPRESENSE )
#ifdef max
#undef max
#endif

#ifdef min
#undef min
#endif

#endif
#include <limits>
13 changes: 13 additions & 0 deletions src/lgfx/internal/memory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#if defined ( CONFIG_ARCH_BOARD_SPRESENSE )
#include <stdint.h>
#include <stdio.h>
#include <wchar.h>
__attribute__((weak)) int vfwscanf(void*, const wchar_t *, ...) { return 0; }
__attribute__((weak)) int vswscanf(const wchar_t*, const wchar_t *, ...) { return 0; }
__attribute__((weak)) int vwscanf(const wchar_t*, ...) { return 0; }

#define _GLIBCXX_CSTDINT 1
#endif
#include <memory>
76 changes: 76 additions & 0 deletions src/lgfx/utility/pgmspace.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*----------------------------------------------------------------------------/
Lovyan GFX - Graphics library for embedded devices.
Original Source:
https://github.com/lovyan03/LovyanGFX/
Licence:
[BSD](https://github.com/lovyan03/LovyanGFX/blob/master/license.txt)
Author:
[lovyan03](https://twitter.com/lovyan03)
Contributors:
[ciniml](https://github.com/ciniml)
[mongonta0716](https://github.com/mongonta0716)
[tobozo](https://github.com/tobozo)
/----------------------------------------------------------------------------*/
#ifndef __LGFX_PGMSPACE_H__
#define __LGFX_PGMSPACE_H__

#if defined ( ARDUINO ) && !defined ( pgm_read_byte )
#if __has_include(<pgmspace.h>)
#include <pgmspace.h>
#elif __has_include(<avr/pgmspace.h>) || defined(__AVR__)
#include <avr/pgmspace.h>
#else
#include <Arduino.h>
#endif
#endif
#if !defined ( pgm_read_byte )
#define pgm_read_byte(addr) (*(const uint8_t *)((uintptr_t)addr))
#define pgm_read_word(addr) (*(const uint16_t *)((uintptr_t)addr))
#define pgm_read_dword(addr) (*(const uint32_t *)((uintptr_t)addr))
#endif

/// for not ESP8266
#if !defined ( pgm_read_dword_with_offset )
#if defined (__SAMD21__)
#define pgm_read_word_unaligned(addr) (uint16_t) \
( *(const uint8_t *)((uintptr_t)addr) \
| *(const uint8_t *)((uintptr_t)addr+1) << 8 )
#define pgm_read_3byte_unaligned(addr) (uint32_t) \
( *(const uint8_t *)((uintptr_t)addr) \
| *(const uint8_t *)((uintptr_t)addr+1) << 8 \
| *(const uint8_t *)((uintptr_t)addr+2) << 16 )
#define pgm_read_dword_unaligned(addr) (uint32_t) \
( *(const uint8_t *)((uintptr_t)addr) \
| *(const uint8_t *)((uintptr_t)addr+1) << 8 \
| *(const uint8_t *)((uintptr_t)addr+2) << 16 \
| *(const uint8_t *)((uintptr_t)addr+3) << 24 )
#else
#define pgm_read_word_unaligned(addr) (*(const uint16_t *)((uintptr_t)addr))
#define pgm_read_dword_unaligned(addr) (*(const uint32_t *)((uintptr_t)addr))
#endif
#endif

#if !defined ( pgm_read_3byte_unaligned )
#define pgm_read_3byte_unaligned(addr) (pgm_read_dword_unaligned(addr) & 0xFFFFFFu)
#endif

#if defined (__SAMD21__) || defined ( ESP8266 )
static inline void write_3byte_unaligned(void* addr, uint32_t value)
{
reinterpret_cast<uint8_t*>(addr)[0] = value;
reinterpret_cast<uint8_t*>(addr)[1] = value >> 8;
reinterpret_cast<uint8_t*>(addr)[2] = value >> 16;
}
#else
static inline void write_3byte_unaligned(void* addr, uint32_t value)
{
reinterpret_cast<uint16_t*>(addr)[0] = value;
reinterpret_cast<uint8_t*>(addr)[2] = value >> 16;
}
#endif

#endif
42 changes: 21 additions & 21 deletions src/lgfx/v1/Bus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Original Source:
/----------------------------------------------------------------------------*/
#pragma once

#include <cstdint>
#include <stdint.h>

namespace lgfx
{
Expand Down Expand Up @@ -64,38 +64,38 @@ namespace lgfx
virtual void initDMA(void) = 0;

/// DMA転送キューを追加する。
virtual void addDMAQueue(const std::uint8_t* data, std::uint32_t length) = 0; // { writeBytes(data, length, true); }
virtual void addDMAQueue(const uint8_t* data, uint32_t length) = 0; // { writeBytes(data, length, true); }

/// 蓄積したDMA転送キューの送信を実行する。
virtual void execDMAQueue(void) = 0;

/// DMA用のバッファを取得する。バスの実装によっては内部的には2個のバッファを交互に使用する。
/// 繰返し実行した場合は前回と異なるポインタを得るが、前々回と同じになる場合がある点に注意すること。
virtual std::uint8_t* getDMABuffer(std::uint32_t length) = 0;
virtual uint8_t* getDMABuffer(uint32_t length) = 0;

/// 未送信のデータがあれば送信を開始する。
virtual void flush(void) = 0;

/// D/Cピンをlowにしてデータを送信する。
virtual bool writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) = 0;
virtual bool writeCommand(uint32_t data, uint_fast8_t bit_length) = 0;

/// D/Cピンをhighにしてデータを送信する。
virtual void writeData(std::uint32_t data, std::uint_fast8_t bit_length) = 0;
virtual void writeData(uint32_t data, uint_fast8_t bit_length) = 0;

/// D/Cピンをhighにして指定回数繰り返しデータを送信する。
virtual void writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t count) = 0;
virtual void writeDataRepeat(uint32_t data, uint_fast8_t bit_length, uint32_t count) = 0;

/// pixelcopy構造体を利用してピクセルデータを送信する。
virtual void writePixels(pixelcopy_t* pc, std::uint32_t length) = 0;
virtual void writePixels(pixelcopy_t* pc, uint32_t length) = 0;

/// 引数のバイト列を送信する。
virtual void writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) = 0;
virtual void writeBytes(const uint8_t* data, uint32_t length, bool dc, bool use_dma) = 0;

virtual void beginRead(void) = 0;
virtual void endRead(void) = 0;
virtual std::uint32_t readData(std::uint_fast8_t bit_length) = 0;
virtual bool readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma = false) = 0;
virtual void readPixels(void* dst, pixelcopy_t* pc, std::uint32_t length) = 0;
virtual uint32_t readData(uint_fast8_t bit_length) = 0;
virtual bool readBytes(uint8_t* dst, uint32_t length, bool use_dma = false) = 0;
virtual void readPixels(void* dst, pixelcopy_t* pc, uint32_t length) = 0;
};

struct Bus_NULL : public IBus
Expand All @@ -109,22 +109,22 @@ namespace lgfx
bool busy(void) const override { return false; }

void initDMA(void) override {}
void addDMAQueue(const std::uint8_t* data, std::uint32_t length) override {}
void addDMAQueue(const uint8_t*, uint32_t) override {}
void execDMAQueue(void) override {}
std::uint8_t* getDMABuffer(std::uint32_t length) override { return nullptr; }
uint8_t* getDMABuffer(uint32_t) override { return nullptr; }

void flush(void) override {}
bool writeCommand(std::uint32_t data, std::uint_fast8_t bit_length) override { return false; }
void writeData(std::uint32_t data, std::uint_fast8_t bit_length) override {}
void writeDataRepeat(std::uint32_t data, std::uint_fast8_t bit_length, std::uint32_t count) override {}
void writePixels(pixelcopy_t* pc, std::uint32_t length) override {}
void writeBytes(const std::uint8_t* data, std::uint32_t length, bool dc, bool use_dma) override {}
bool writeCommand(uint32_t, uint_fast8_t) override { return false; }
void writeData(uint32_t, uint_fast8_t) override {}
void writeDataRepeat(uint32_t, uint_fast8_t, uint32_t) override {}
void writePixels(pixelcopy_t*, uint32_t) override {}
void writeBytes(const uint8_t*, uint32_t, bool, bool) override {}

void beginRead(void) override {}
void endRead(void) override {}
std::uint32_t readData(std::uint_fast8_t bit_length) override { return 0; }
bool readBytes(std::uint8_t* dst, std::uint32_t length, bool use_dma = false) override { return false; }
void readPixels(void* dst, pixelcopy_t* pc, std::uint32_t length) override {}
uint32_t readData(uint_fast8_t) override { return 0; }
bool readBytes(uint8_t*, uint32_t, bool) override { return false; }
void readPixels(void*, pixelcopy_t*, uint32_t) override {}
};

//----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 67f0fe2

Please sign in to comment.