diff --git a/docs/en/api/m5paper/epd_canvas.md b/docs/en/api/m5paper/epd_canvas.md new file mode 100644 index 00000000..855f808b --- /dev/null +++ b/docs/en/api/m5paper/epd_canvas.md @@ -0,0 +1,416 @@ +## EPD Driver + +>The M5PAPER is equipped with an e-ink screen with a resolution of 540*960 @ 4.7" and supports 16 levels of grayscale display. In the `M5.begin()` initialization, the instance `M5EPD_Driver EPD = M5EPD_Driver();` has been created and initialized. With the following screen driver, you can push the content-drawn data to the screen. + +- `m5epd_err_t begin(int8_t sck, int8_t mosi, int8_t miso, int8_t cs, int8_t busy, int8_t rst = -1);` + +- **Function: Clear screen content/true initializes screen with UPDATE_MODE_INIT mode/false Clear 8951 buffer** +- `m5epd_err_t Clear(bool init = false);` + +- **Functions: Write full frame data / 4 bit per pixel**. +- `m5epd_err_t WriteFullGram4bpp(const uint8_t *gram);` + +- **Function: Write local data in specified area / 4 bit per pixel**. +- `m5epd_err_t WritePartGram4bpp(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint8_t *gram);` + +- **Function: Fill specified data in specified area**. +- `m5epd_err_t FillPartGram4bpp(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t data);` + +- **Functions: Set screen rotation angle/usually set to 90°**. +- `m5epd_err_t SetRotation(uint16_t rotate = IT8951_ROTATE_0);` + +- **Function: flushes the data in the buffer to full screen in the specified mode**. +- `m5epd_err_t UpdateFull(m5epd_update_mode_t mode);` + +- **Function: flushes the data in the buffer to the specified area of the screen in the specified mode**. +- `m5epd_err_t UpdateArea(uint16_t x, uint16_t y, uint16_t w, uint16_t h, m5epd_update_mode_t mode);` + +- **Functions: get refresh times** +- `uint16_t UpdateCount(void);` + +- **Function: Read the screen rotation angle**. +- `uint8_t GetRotate(void) {return _rotate;};` + +- **Function: Read screen orientation** +- `uint8_t GetDirection(void) {return _direction;};` + +- **Functions: reset refresh times** +- `void ResetUpdateCount(void);` + +- **Function: detects if 8951 is busy**. +- `m5epd_err_t CheckAFSR(void);` + +- **Function: set color inverse color** +- `void SetColorReverse(bool is_reverse);` + +## Canvas + +>The library uses the `Canvas` class for drawing patterns, which provides a variety of drawing APIs (including drawing strings, rectangles, triangles, circles, image data, etc.). To use it, you need to create a canvas instance and pass it to the screen driver, as shown in the following code. + +``` +#include + +M5EPD_Canvas canvas(&M5.EPD); +``` + +### Create/delete Canvas + +>Before we can start drawing, we need to create a drawing area using the Canvas instance. + +- **Function: Create Canvas** +- `void *createCanvas(int16_t width, int16_t height, uint8_t frames = 1) { return TFT_eSprite::createSprite(width, height, frames); };` + +- **Function: Delete Canvas** +- `void deleteCanvas(void) { TFT_eSprite::deleteSprite(); }` + +``` +#include + +M5EPD_Canvas canvas(&M5.EPD); + +M5.begin(); +M5.EPD.SetRotation(90); +canvas.createCanvas(400, 300); + +``` + +### Push Canvas + +>After drawing the content using the Draw API, we need to use the `push` API to push the drawn area to the screen. + +// Re-implement functions + +- **Function: Get pointer to the Canvas buffer**. +- `void *frameBuffer(int8_t f = 1);` + +- **Function: Push the Canvas to the specified area of the screen, and specify the refresh mode**. +- `void pushCanvas(int32_t x, int32_t y, m5epd_update_mode_t mode);` + +- **Functions: Push Canvas to screen position 0, 0, assign refresh mode**. +- `void pushCanvas(m5epd_update_mode_t mode);` + +- **Function: Draw to the specified Canvas**. +- `void pushToCanvas(int32_t x, int32_t y, M5EPD_Canvas* canvas);` + +**Example:** + +``` +#include + +M5EPD_Canvas canvas(&M5.EPD); + +void setup() +{ + M5.begin(); + M5.EPD.SetRotation(90); + M5.EPD.Clear(true); + canvas.createCanvas(540, 960); + canvas.setTextSize(3); + canvas.drawString("Hello World!", 50, 350); + canvas.drawString("Hello M5Stack!", 45, 450); + canvas.pushCanvas(0,0,UPDATE_MODE_DU4); +} + +void loop() +{ + +} + +``` + +### Update Mode + +>To use `pushCanvas`, we need to pass a refresh mode parameter. The library `m5epd_update_mode_t` already enumerates several different update modes. + +``` +typedef enum // Typical +{ // Ghosting Update Time Usage + UPDATE_MODE_INIT = 0, // * N/A 2000ms Display initialization, + UPDATE_MODE_DU = 1, // Low 260ms Monochrome menu, text input, and touch screen input 1bit Gray level + UPDATE_MODE_GC16 = 2, // * Very Low 450ms High quality images + UPDATE_MODE_GL16 = 3, // * Medium 450ms Text with white background + UPDATE_MODE_GLR16 = 4, // Low 450ms Text with white background + UPDATE_MODE_GLD16 = 5, // Low 450ms Text and graphics with white background + UPDATE_MODE_DU4 = 6, // * Medium 120ms Fast page flipping at reduced contrast 1bit Gray level Slightly faster than DU, larger afterimage relative to DU + UPDATE_MODE_A2 = 7, // Medium 290ms Anti-aliased text in menus / touch and screen input 2bit Gray level + UPDATE_MODE_NONE = 8 Uploading to the 8951 cache without refreshing allows you to accumulate multiple uploads and then refresh all content at once. +} m5epd_update_mode_t; // The ones marked with * are more commonly used + +``` + +>The refresh quality is relatively good for `UPDATE_MODE_GC16`, `UPDATE_MODE_GL16` , `UPDATE_MODE_GLR16` , `UPDATE_MODE_GLD16`. + +## Canvas API + +- **Function: Fill Draw Area** +- `void fillCanvas(uint32_t color);` + +- **Function: Push Buffer Data** +- `void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint8_t *data);` +- `void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t transp, const uint8_t *data);` + +- **Function: Read pixel color** +- `uint16_t readPixel(int32_t x, int32_t y);` + +- **Function: Draw pixels** +- `void drawPixel(int32_t x, int32_t y, uint32_t color);` + +- **Function: Draw QR code** +- `void qrcode(const char *string, uint16_t x = 50, uint16_t y = 10, uint16_t width = 220, uint8_t version = 6);` +- `void qrcode(const String &string, uint16_t x = 50, uint16_t y = 10, uint16_t width = 220, uint8_t version = 6);` + +- **Functions: draw squares with center points** +- `void fillCenterSquare(int32_t cx, int32_t cy, uint16_t w, uint8_t color);` + +- **Function: Read the buffer size of the current Canvas image**. +- `uint32_t getBufferSize(void) {return _buffer_size;}` + +- **Functions: set inverse color** +- `void ReverseColor(void);` + +- **Function: set local inverse color** +- `void ReversePartColor(int32_t x, int32_t y, int32_t w, int32_t h);` + +- **Function: Canvas Copy** +- `void operator=(const M5EPD_Canvas &src);` + +- **Function: Set screen driver** +- `void setDriver(M5EPD_Driver *driver);` + +## JPG/BMP/PNG + +- **Function: Drawing images with Bmp file data** +- `bool drawBmpFile(fs::FS &fs, const char *path, uint16_t x, uint16_t y); +- `bool drawBmpFile(fs::FS &fs, String path, uint16_t x, uint16_t y);` + + +- **Function: Draw images using Jpg file data**. +- `bool drawJpgFile(fs::FS &fs, const char *path, uint16_t x = 0, + uint16_t y = 0, uint16_t maxWidth = 0, uint16_t maxHeight = 0, + uint16_t offX = 0, uint16_t offY = 0, + jpeg_div_t scale = JPEG_DIV_NONE);` + +- `bool drawJpgFile(fs::FS &fs, String path, uint16_t x = 0, + uint16_t y = 0, uint16_t maxWidth = 0, uint16_t maxHeight = 0, + uint16_t offX = 0, uint16_t offY = 0, + jpeg_div_t scale = JPEG_DIV_NONE);` + +- **Function: Draw images using Png file data**. +- `bool drawPngFile(fs::FS &fs, const char *path, uint16_t x = 0, uint16_t y = 0, + uint16_t maxWidth = 0, uint16_t maxHeight = 0, + uint16_t offX = 0, uint16_t offY = 0, + double scale = 1.0, uint8_t alphaThreshold = 127);` + +- `bool drawPngFile(fs::FS &fs, String path, uint16_t x = 0, uint16_t y = 0, + uint16_t maxWidth = 0, uint16_t maxHeight = 0, + uint16_t offX = 0, uint16_t offY = 0, + double scale = 1.0, uint8_t alphaThreshold = 127);` + +- **Function: Draw images using memory Jpg data**. +- `bool drawJpg(const uint8_t *jpg_data, size_t jpg_len, uint16_t x = 0, + uint16_t y = 0, uint16_t maxWidth = 0, uint16_t maxHeight = 0, + uint16_t offX = 0, uint16_t offY = 0, + jpeg_div_t scale = JPEG_DIV_NONE);` + +- **Function: Draw images using Jpg's Url/Network resource data**. +- `bool drawJpgUrl(String url, uint16_t x = 0, + uint16_t y = 0, uint16_t maxWidth = 0, uint16_t maxHeight = 0, + uint16_t offX = 0, uint16_t offY = 0, jpeg_div_t scale = JPEG_DIV_NONE);` + + +- **Functions: Draw images using Png's Url/Network resource data**. +- `bool drawPngUrl(const char *url, uint16_t x = 0, uint16_t y = 0, + uint16_t maxWidth = 0, uint16_t maxHeight = 0, + uint16_t offX = 0, uint16_t offY = 0, + double scale = 1.0, uint8_t alphaThreshold = 127);` + + +**Example:** + +``` +#include +#include + +M5EPD_Canvas canvas(&M5.EPD); + +void setup() +{ + M5.begin(); + M5.EPD.SetRotation(90); + M5.EPD.Clear(true); + WiFi.begin("WIFI-SSID", "WIFI-PASSWORD"); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + + canvas.createCanvas(540, 960); + canvas.setTextSize(3); + canvas.drawJpgUrl("https://m5stack.oss-cn-shenzhen.aliyuncs.com/image/example_pic/flower.jpg"); + canvas.pushCanvas(0,0,UPDATE_MODE_GC16); +} + +void loop() +{ + +} + + +``` + +## Text + +>Here are some common text drawing APIs. + +- **Function: set font color** +- `void setTextColor(uint16_t color) { TFT_eSPI::setTextColor(color); }` +- `void setTextColor(uint16_t fgcolor, uint16_t bgcolor) { TFT_eSPI::setTextColor(fgcolor, bgcolor); }` + +- **Function: set font size** +- `void setTextSize(uint8_t size) { TFT_eSPI::setTextSize(size); }` + +- **Function: set text line wrap** +- `void setTextWrap(boolean wrapX, boolean wrapY = false) { TFT_eSPI::setTextWrap(wrapX, wrapY); }` + +- **Functions: Setting Text Baseline** +- `void setTextDatum(uint8_t datum) { TFT_eSPI::setTextDatum(datum); }` + +- **Functions: set text Padding** +- `void setTextPadding(uint16_t x_width) { TFT_eSPI::setTextPadding(x_width); }` + +- **Functions: plotting integers** +- `int16_t drawNumber(long long_num, int32_t poX, int32_t poY, uint8_t font) { return TFT_eSPI::drawNumber(long_num, poX, poY, font); }` +- `int16_t drawNumber(long long_num, int32_t poX, int32_t poY) { return TFT_eSPI::drawNumber(long_num, poX, poY); }` + +- **Functions: plot floating point number** +- `int16_t drawFloat(float floatNumber, uint8_t decimal, int32_t poX, int32_t poY, uint8_t font) { return TFT_eSPI::drawFloat(floatNumber, decimal, poX, poY, font); }` +- `int16_t drawFloat(float floatNumber, uint8_t decimal, int32_t poX, int32_t poY) { return TFT_eSPI::drawFloat(floatNumber, decimal, poX, poY); }` + +- **Function: Draw string** +- `int16_t drawString(const char *string, int32_t poX, int32_t poY, uint8_t font) { return TFT_eSPI::drawString(string, poX, poY, font); }` +- `int16_t drawString(const char *string, int32_t poX, int32_t poY) { return TFT_eSPI::drawString(string, poX, poY); }` +- `int16_t drawString(const String &string, int32_t poX, int32_t poY, uint8_t font) { return TFT_eSPI::drawString(string, poX, poY, font); }` +- `int16_t drawString(const String &string, int32_t poX, int32_t poY) { return TFT_eSPI::drawString(string, poX, poY); }` + +- **Functions: decode UTF8 string/return Unicode value**. +- `uint16_t decodeUTF8(uint8_t *buf, uint16_t *index, uint16_t remaining) { return TFT_eSPI::decodeUTF8(buf, index, remaining); };` +- `uint16_t decodeUTF8(uint8_t *buf, uint16_t *index, uint16_t remaining, uint8_t *length) { return TFT_eSPI::decodeUTF8(buf, index, remaining, length); };` + +- **Functions: draw characters** +- `int16_t drawChar(uint16_t uniCode, int32_t x, int32_t y) { return TFT_eSprite::drawChar(uniCode, x, y); }` +- `int16_t drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font) { return TFT_eSprite::drawChar(uniCode, x, y, font); }` +- `void drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32_t bg, uint8_t size) { TFT_eSprite::drawChar(x, y, c, color, bg, size); }` + +- **Function: get text width** +- `int16_t textWidth(const char *string, uint8_t font) {return TFT_eSPI::textWidth(string, font);}` +- `int16_t textWidth(const char *string) {return TFT_eSPI::textWidth(string);}` +- `int16_t textWidth(const String& string, uint8_t font) {return TFT_eSPI::textWidth(string, font);}` +- `int16_t textWidth(const String& string) {return TFT_eSPI::textWidth(string);}` + +## Drawing + +>Here are some common drawing APIs. + +// Parent functions - drawing + +- **Function: Draw circles** +- `void drawCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color) { TFT_eSPI::drawCircle(x0, y0, r, color); }` + +- **Function: Draw circles helper** +- `void drawCircleHelper(int32_t x0, int32_t y0, int32_t r, uint8_t cornername, uint32_t color) { TFT_eSPI::drawCircleHelper(x0, y0, r, cornername, color); }` + +- **Function:draw filled circles** +- `void fillCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color) { TFT_eSPI::fillCircle(x0, y0, r, color); }` + +- **Function:draw filled circles helper** +- `void fillCircleHelper(int32_t x0, int32_t y0, int32_t r, uint8_t cornername, int32_t delta, uint32_t color) { TFT_eSPI::fillCircleHelper(x0, y0, r, cornername, delta, color); }` + +- **Function: Draw a line** +- `void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t color) { TFT_eSprite::drawLine(x0, y0, x1, y1, color); }` +- `void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint8_t thickness, uint8_t color);` + +- **Function: Quickly draw vertical lines**. +- `void drawFastVLine(int32_t x, int32_t y, int32_t h, uint32_t color) { TFT_eSprite::drawFastVLine(x, y, h, color); }` +- `void drawFastVLine(int32_t x, int32_t y, int32_t h, uint8_t thickness, uint8_t color);` + +- **Function: Draw ellipse** +- `void drawEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color) { TFT_eSPI::drawEllipse(x0, y0, rx, ry, color); }` + +- **Function: Draw filled ellipse**. +- `void fillEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color) { TFT_eSPI::fillEllipse(x0, y0, rx, ry, color); }` + +- **Function: Draw rect** +- `void drawRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color) { TFT_eSPI::drawRect(x, y, w, h, color); }` + +- **Function: Draw filled rect** +- `void fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);` + +- **Functions: draw rounded rectangles** +- `void drawRoundRect(int32_t x0, int32_t y0, int32_t w, int32_t h, int32_t radius, uint32_t color) { TFT_eSPI::drawRoundRect(x0, y0, w, h, radius, color); }` + +- **Function: Draw filled rounded rectangles**. +- `void fillRoundRect(int32_t x0, int32_t y0, int32_t w, int32_t h, int32_t radius, uint32_t color) { TFT_eSPI::fillRoundRect(x0, y0, w, h, radius, color); }` + +- **Functions: Drawing triangles** +- `void drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color) { TFT_eSPI::drawTriangle(x0, y0, x1, y1, x2, y2, color); }` + +- **Functions: Draw filled triangles** +- `void fillTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color) { TFT_eSPI::fillTriangle(x0, y0, x1, y1, x2, y2, color); }` + +## print + +>Here are some function overrides for print formatted output. + +// Parent functions - Print +- `size_t printf(const char * format, ...) __attribute__ ((format (printf, 2, 3)));` + +- `size_t print(const __FlashStringHelper *x){return Print::print(x);}` + +- `size_t print(const String &x){return Print::print(x);}` + +- `size_t print(const char x[]){return Print::print(x);}` + +- `size_t print(char x){return Print::print(x);}` + +- `size_t print(unsigned char x, int y = DEC){return Print::print(x, y);}` + +- `size_t print(int x, int y = DEC){return Print::print(x, y);}` + +- `size_t print(unsigned int x, int y = DEC){return Print::print(x, y);}` + +- `size_t print(long x, int y = DEC){return Print::print(x, y);}` + +- `size_t print(unsigned long x, int y = DEC){return Print::print(x, y);}` + +- `size_t print(double x, int y = 2){return Print::print(x, y);}` + +- `size_t print(const Printable& x){return Print::print(x);}` + +- `size_t print(struct tm * timeinfo, const char * format = NULL){return Print::print(timeinfo, format);}` + +- `size_t println(const __FlashStringHelper *x){return Print::println(x);}` + +- `size_t println(const String &x){return Print::println(x);}` + +- `size_t println(const char x[]){return Print::println(x);}` + +- `size_t println(char x){return Print::println(x);}` + +- `size_t println(unsigned char x, int y = DEC){return Print::println(x, y);}` + +- `size_t println(int x, int y = DEC){return Print::println(x, y);}` + +- `size_t println(unsigned int x, int y = DEC){return Print::println(x, y);}` + +- `size_t println(long x, int y = DEC){return Print::println(x, y);}` + +- `size_t println(unsigned long x, int y = DEC){return Print::println(x, y);}` + +- `size_t println(double x, int y = 2){return Print::println(x, y);}` + +- `size_t println(const Printable& x){return Print::println(x);}` + +- `size_t println(struct tm * timeinfo, const char * format = NULL){return Print::println(timeinfo, format);}` + +- `size_t println(void){return Print::println();}` \ No newline at end of file diff --git a/docs/en/api/m5paper/system_api.md b/docs/en/api/m5paper/system_api.md new file mode 100644 index 00000000..46d50be8 --- /dev/null +++ b/docs/en/api/m5paper/system_api.md @@ -0,0 +1,349 @@ +# System & Button & SHT30 & POWER & RTC + +## begin() + +**Syntax:** + +`void begin(bool touchEnable = true, bool SDEnable = true, bool SerialEnable = true, bool BatteryADCEnable = true, bool I2CEnable = false);` + +**Functions: touch screen initialization , TF Card , UART , battery ADC reading , I2C** + +**Example:** + +```arduino +#include + +void setup() { + M5.begin(true,true,true,true,true); +} +``` + +## Button + +**Function: detects device key status** + +``` + Button(uint8_t pin, uint8_t invert, uint32_t dbTime); + uint8_t read(); + uint8_t isPressed(); + uint8_t isReleased(); + uint8_t wasPressed(); + uint8_t wasReleased(); + uint8_t pressedFor(uint32_t ms); + uint8_t releasedFor(uint32_t ms); + uint8_t wasReleasefor(uint32_t ms); + uint32_t lastChange(); + +``` + +## update() + +**Syntax:** + +`void update();` + +**Functions: refresh device key status** + + +**Example:** + +```arduino + +if( M5.BtnL.wasPressed()) +{ + Serial.printf("BtnL wasPressed!"); +} +M5.update(); + +``` + +## SHT30 + +**Function: Read the temperature and humidity detected by the SHT30**. + +``` + float GetTemperature(TemperatureScale Degree = Cel); + float GetRelHumidity(); + float GetAbsHumidity(AbsHumidityScale Scale = Torr); +``` + +**Refresh detection data (need to call the API to get new detection values)** + +`void UpdateData();` + +**Example:** + +```arduino +#include + +char temStr[10]; +char humStr[10]; + +float tem; +float hum; + +M5EPD_Canvas canvas(&M5.EPD); +void setup() +{ + M5.begin(); + M5.SHT30.Begin(); + M5.EPD.SetRotation(90); + M5.EPD.Clear(true); + canvas.createCanvas(400, 300); + canvas.setTextSize(2); +} + +void loop() +{ + + M5.SHT30.UpdateData(); + tem = M5.SHT30.GetTemperature(); + hum = M5.SHT30.GetRelHumidity(); + Serial.printf("Temperatura: %2.2f*C Humedad: %0.2f%%\r\n", tem, hum); + dtostrf(tem, 2, 2 , temStr); + dtostrf(hum, 2, 2 , humStr); + canvas.drawString("Temperatura:" + String(temStr) + "*C", 100, 100); + canvas.drawString("Humedad:" + String(humStr) , 100, 200); + canvas.pushCanvas(0,300,UPDATE_MODE_A2); + delay(1000); +} + +``` + +## Related pin definitions + +``` +#define M5EPD_MAIN_PWR_PIN 2 +#define M5EPD_CS_PIN 15 +#define M5EPD_SCK_PIN 14 +#define M5EPD_MOSI_PIN 12 +#define M5EPD_BUSY_PIN 27 +#define M5EPD_MISO_PIN 13 +#define M5EPD_EXT_PWR_EN_PIN 5 +#define M5EPD_EPD_PWR_EN_PIN 23 +#define M5EPD_KEY_RIGHT_PIN 39 +#define M5EPD_KEY_PUSH_PIN 38 +#define M5EPD_KEY_LEFT_PIN 37 +#define M5EPD_BAT_VOL_PIN 35 +#define M5EPD_PORTC_W_PIN 19 +#define M5EPD_PORTC_Y_PIN 18 +#define M5EPD_PORTB_W_PIN 33 +#define M5EPD_PORTB_Y_PIN 26 +#define M5EPD_PORTA_W_PIN 32 +#define M5EPD_PORTA_Y_PIN 25 +``` + +## Power + +- **Function: Enable Expansion Port Power** +- `void enableEXTPower() { digitalWrite(M5EPD_EXT_PWR_EN_PIN, 1); }` + +- **Functions: power off expansion port**. +- `void disableEXTPower() { digitalWrite(M5EPD_EXT_PWR_EN_PIN, 0); }` + +- **Function: Enable Ink Screen Power** +- `void enableEPDPower() { digitalWrite(M5EPD_EPD_PWR_EN_PIN, 1); }` + +- **Function: Turn off the power of the ink screen**. +- `void disableEPDPower() { digitalWrite(M5EPD_EPD_PWR_EN_PIN, 0); }` + +- **Function: Enable Main Power** +- `void enableMainPower() { digitalWrite(M5EPD_MAIN_PWR_PIN, 1); }` + +- **Function: Turn off main power** +- `void disableMainPower() { digitalWrite(M5EPD_MAIN_PWR_PIN, 0); }` + +- **Functions: initialize battery ADC detection** +- `void BatteryADCBegin();` + +- **Functions: Read battery voltage native ADC value** +- `uint32_t getBatteryRaw();` + +- **Function: Read battery voltage** +- `uint32_t getBatteryVoltage();` + +## RTC + +?>Please use `M5.RTC.begin();` to initialize RTC related functions before using + +``` +typedef struct RTC_Time +{ + int8_t hour; + int8_t min; + int8_t sec; + RTC_Time() : hour(), min(), sec() {} + RTC_Time(int8_t h, int8_t m, int8_t s) : hour(h), min(m), sec(s) {} +} rtc_time_t; + +typedef struct RTC_Date +{ + int8_t week; + int8_t mon; + int8_t day; + int16_t year; + RTC_Date() : week(), mon(), day(), year() {} + RTC_Date(int8_t w, int8_t m, int8_t d, int16_t y) : week(w), mon(m), day(d), year(y) {} +} rtc_date_t; + +``` + +## setTime() + +**Syntax:** + +`void setTime(rtc_time_t *time);` + +**Description:** + +Set RTC Time Struct + +## getTime() + +**Syntax:** + +`void getTime(rtc_time_t *time);` + +**Description:** + +Get RTC Time Struct + +## setDate() + +**Syntax:** + +`void setDate(rtc_date_t *date);` + +**Description:** + +Set RTC Date Struct + +## getDate() + +**Syntax:** + +`void getDate(rtc_date_t *date);` + +**Description:** + +Get RTC Date Struct + +**Example:** + + +``` +#include + +M5EPD_Canvas canvas(&M5.EPD); + +rtc_time_t RTCtime; +rtc_date_t RTCDate; + +char timeStrbuff[64]; + +void flushTime(){ + M5.RTC.getTime(&RTCtime); + M5.RTC.getDate(&RTCDate); + + sprintf(timeStrbuff,"%d/%02d/%02d %02d:%02d:%02d", + RTCDate.year,RTCDate.mon,RTCDate.day, + RTCtime.hour,RTCtime.min,RTCtime.sec); + + canvas.drawString(timeStrbuff, 0, 0); + canvas.pushCanvas(100,200,UPDATE_MODE_DU4); +} + +void setupTime(){ + + RTCtime.hour = 23; + RTCtime.min = 33; + RTCtime.sec = 33; + M5.RTC.setTime(&RTCtime); + + RTCDate.year = 2020; + RTCDate.mon = 11; + RTCDate.day = 27; + M5.RTC.setDate(&RTCDate); +} + +void setup() { + + M5.begin(); + M5.EPD.SetRotation(90); + M5.EPD.Clear(true); + M5.RTC.begin(); + canvas.createCanvas(400, 300); + canvas.setTextSize(3); + setupTime(); +} + +void loop() { + flushTime(); + delay(1000); +} +``` + + +## shutdown() + +### function overload-1: + +Power off and wake up again via PWR button + +`void shutdown();` + +### function overload-2: + +Turn off the power and wake up the device via RTC at the end of the delay based on the number of seconds of incoming delay. + +`int shutdown( int seconds );` + +### function overload-3: + +Turn off the power, pass in the RTC time structure that specifies a certain point in time, and wake up the device via RTC when the `hours`, `minutes`, and `seconds` of that time are met. + +`int shutdown( const rtc_time_t &RTC_TimeStruct);` + +### function overload-4: + +Turn off the power, pass in the RTC time structure specified for a certain point in time, and wake up the device by RTC when the `week number`, `day number`, and `time` of that point in time match at the same time. + +`int shutdown( const rtc_date_t &RTC_DateStruct, const rtc_time_t &RTC_TimeStruct);` + + +**Example:** + +``` +#include + +M5EPD_Canvas canvas(&M5.EPD); + +void setup() +{ + M5.begin(); + M5.EPD.SetRotation(90); + M5.TP.SetRotation(90); + M5.EPD.Clear(true); + M5.RTC.begin(); + canvas.createCanvas(540, 960); + canvas.setTextSize(3); + canvas.drawString("Press PWR Btn for sleep!", 45, 350); + canvas.drawString("after 5 sec wakeup!", 70, 450); + canvas.pushCanvas(0,0,UPDATE_MODE_DU4); + + +} + +void loop() +{ + if(M5.BtnP.wasPressed()){ + + canvas.drawString("I'm going to sleep.zzzZZZ~", 45, 550); + canvas.pushCanvas(0,0,UPDATE_MODE_DU4); + delay(1000); + M5.shutdown(5); + } + M5.update(); + delay(100); +} +``` \ No newline at end of file diff --git a/docs/en/api/m5paper/touch.md b/docs/en/api/m5paper/touch.md new file mode 100644 index 00000000..985f382b --- /dev/null +++ b/docs/en/api/m5paper/touch.md @@ -0,0 +1,103 @@ +# TOUCH-GT911 + +>This is the M5Stack Paper touchscreen library. + +## GT911 + +>In the `M5.begin()` initialization, the instance `GT911 TP = GT911();` has been created and initialized. You can use the API in this instance to get the touch interaction information. + +- **Functions: Initialize I2C bus**. +- `esp_err_t begin(uint8_t pin_sda, uint8_t pin_scl, uint8_t pin_int);` + +- **Functions: if there is new screen touch data to be read**. +- `bool avaliable();` + +- **Functions: screen refresh detection** +- `void update();` + +- **Functions: Set screen rotation angle/usually set to 90°**. +- `void SetRotation(uint16_t rotate);` + +- **Function: Read the X-coordinate of the touch finger**. +- `uint16_t readFingerX(uint8_t num);` + +- **Function: read touch finger Y coordinate** +- `uint16_t readFingerY(uint8_t num);` + +- **Function: Read the touch finger ID coordinates**. +- `uint16_t readFingerID(uint8_t num);` + +- **Function: read the size of the rectangle in the area where the touch finger acts**. +- `uint16_t readFingerSize(uint8_t num);` + +- **Functions: last read number of fingers touched** +- `uint8_t getFingerNum(void);` + +- **Function: detect if the finger is raised**. +- `bool isFingerUp(void);` + +- **Function: Clear the current touch state** +- `void flush(void);` + +- **Function: Read touch finger information, return to structure instance** +- `tp_finger_t readFinger(uint8_t num);` + +``` +typedef struct +{ + uint16_t x; + uint16_t y; + uint16_t id; + uint16_t size; +}tp_finger_t; + +``` + +**Example:** + +```arduino +#include + +M5EPD_Canvas canvas(&M5.EPD); + +int point[2][2]; + +void setup() +{ + M5.begin(); + M5.EPD.SetRotation(90); + M5.TP.SetRotation(90); + M5.EPD.Clear(true); + canvas.createCanvas(540, 960); + canvas.setTextSize(5); + canvas.drawString("Touch The Screen!", 20, 400); + canvas.pushCanvas(0,0,UPDATE_MODE_DU4); +} + +void loop() +{ + + if(M5.TP.avaliable()){ + if(!M5.TP.isFingerUp()){ + M5.TP.update(); + canvas.fillCanvas(0); + bool is_upadte = false; + for(int i=0;i<2; i++){ + tp_finger_t FingerItem = M5.TP.readFinger(i); + if((point[i][0]!=FingerItem.x)||(point[i][1]!=FingerItem.y)){ + is_upadte = true; + point[i][0] = FingerItem.x; + point[i][1] = FingerItem.y; + canvas.fillRect(FingerItem.x-50, FingerItem.y-50, 100, 100, 15); + Serial.printf("Finger ID:%d-->X: %d*C Y: %d Size: %d\r\n", FingerItem.id, FingerItem.x, FingerItem.y , FingerItem.size); + } + } + if(is_upadte) + { + canvas.pushCanvas(0,0,UPDATE_MODE_DU4); + } + } + } +} + +``` diff --git a/docs/en/arduino/arduino_home_page.md b/docs/en/arduino/arduino_home_page.md index 6d602919..e285826a 100644 --- a/docs/en/arduino/arduino_home_page.md +++ b/docs/en/arduino/arduino_home_page.md @@ -92,6 +92,15 @@ const coreink_api = { "id":"coreink_api" }; +const m5paper_api = { + 'title':"M5Paper API", + 'item':{ + 'System & Button & SHT30 & POWER & RTC':'#/en/api/m5paper/system_api', + 'EPD Canvas':'#/en/api/m5paper/epd_canvas', + 'TOUCH':'#/en/api/m5paper/touch' + }, + "id":"m5paper_api" +}; var arduino_home_page = new Vue({ el:'#arduino_home_page', @@ -102,7 +111,8 @@ var arduino_home_page = new Vue({ m5core_api: m5core_api, m5stickc_api: m5stickc_api, m5core2_api: m5core2_api, - coreink_api: coreink_api + coreink_api: coreink_api, + m5paper_api: m5paper_api } }; } diff --git a/docs/en/core/coreink.md b/docs/en/core/coreink.md index 754b3c8c..a757c0de 100644 --- a/docs/en/core/coreink.md +++ b/docs/en/core/coreink.md @@ -16,7 +16,7 @@ view the corresponding tutorial&quick-Start. -?>Warning: Please avoid using high refresh rates,reccommended refresh rate is(15s/per refresh), Do not expose to ultraviolet rays for a long time, otherwise it may cause irreversible damage to the ink screen. +?>Warning: Please avoid using high refresh rates,recommended refresh rate is(15s/per refresh), Do not expose to ultraviolet rays for a long time, otherwise it may cause irreversible damage to the ink screen. diff --git a/docs/en/core/m5paper.md b/docs/en/core/m5paper.md index a35cc4fe..80e09e28 100644 --- a/docs/en/core/m5paper.md +++ b/docs/en/core/m5paper.md @@ -210,7 +210,7 @@ For more info on specific pin functions refer to the official ESP32 Docs[ESP32 d - **API** - - [Arduino API](en/arduino/arduino_home_page) + - [Arduino API](zh_CN/arduino/arduino_home_page?id=m5paper) ## Schematic diff --git a/docs/en/hat/hat-roverc.md b/docs/en/hat/hat-roverc.md index 1fdef0dd..2a721f7a 100644 --- a/docs/en/hat/hat-roverc.md +++ b/docs/en/hat/hat-roverc.md @@ -76,7 +76,7 @@ Before use, please make sure that the roverc is fully charged. Charging method: Burn the easyloader firmware of Joyc and roverc with two M5StickC respectively. Insert Joyc and roverc respectively after burning. After power on, roverc will display the MAC address name and battery power. At the same time, Joyc will scan the MAC address name of roverc. Long press the a key of M5StickC on Joyc, and the work will be matched. Left rocker up and down control front and back, left and right control translation, right rocker left and right control steering. ## Usage -Two M5StickCs will be burned into the EasyLoader firmware of JoyC and RoverC respectively. After burning, they will be inserted into JoyC and RoverC respectively. After booting, RoverC will display the hotspot name of "M5AP+2 bytes mac address", and JoyC will scan the mac address name of RoverC. Press and hold the A5 button of the M5StickC on the JoyC for 3 seconds to start scanning the hotspot of the car, and the pairing is successful. After successful pairing, the link icon is highlighted in the upper left corner of the screen, and the joystick value is displayed on the screen. The left and right joysticks are controlled up and down, the left and right controls pan, and the right rocker controls the steering. +Two M5StickCs will be burned into the EasyLoader firmware of JoyC and RoverC respectively. After burning, they will be inserted into JoyC and RoverC respectively. After booting, RoverC will display the hotspot name of "M5AP+2 bytes mac address", and JoyC will scan the mac address name of RoverC. Press and hold the Home button of the M5StickC on the JoyC for 3 seconds to start scanning the hotspot of the car, and the pairing is successful. After successful pairing, the link icon is highlighted in the upper left corner of the screen, and the joystick value is displayed on the screen. The left and right joysticks are controlled up and down, the left and right controls pan, and the right rocker controls the steering. MotorControl: diff --git a/docs/en/hat/hat_roverc_pro.md b/docs/en/hat/hat_roverc_pro.md index bf23b41f..723511bc 100644 --- a/docs/en/hat/hat_roverc_pro.md +++ b/docs/en/hat/hat_roverc_pro.md @@ -133,7 +133,7 @@ MotorControl: ### 1. Arduino IDE Use with JoyC HAT(without servo gripper), please click [here](https://github.com/m5stack/M5-ProductExampleCodes/tree/master/Hat/RoverC) -Before use, please make sure that the RoverC is fully charged. Charging method: insert M5StickC/M5StickC Plus into the RoverC, and connect the USB cable for charging.Burn the easyloader firmware of JoyC and RoverC with two M5StickC respectively. Insert JoyC and RoverC respectively after burning. After power on, RoverC will display the MAC address name and battery level. At the same time, JoyC will scan for the MAC address of RoverC. Long press the A key of M5StickC on Joyc, and the two will be paired. Left thumbstick controlls forward and back motion, left and right control translation, right thumbstick controls left and right steering. +Before use, please make sure that the RoverC is fully charged. Charging method: insert M5StickC/M5StickC Plus into the RoverC, and connect the USB cable for charging.Burn the easyloader firmware of JoyC and RoverC with two M5StickC respectively. Insert JoyC and RoverC respectively after burning. After power on, RoverC will display the MAC address name and battery level. At the same time, JoyC will scan for the MAC address of RoverC. Long press the Home button of M5StickC on Joyc, and the two will be paired. Left thumbstick controlls forward and back motion, left and right control translation, right thumbstick controls left and right steering. Independent(with servo gripper) usage [here](https://github.com/m5stack/M5-ProductExampleCodes/tree/master/Application/RoverC_PRO_Arduino_Alone) diff --git a/docs/zh_CN/accessory/cable/24awg_cable.md b/docs/zh_CN/accessory/cable/24awg_cable.md new file mode 100644 index 00000000..26ad047b --- /dev/null +++ b/docs/zh_CN/accessory/cable/24awg_cable.md @@ -0,0 +1,42 @@ +# 24AWG 4-CORE Shielded Cable + +SKU:A034 + +
+ +## 描述 + +**24AWG 4-CORE Shielded Cable**M5Stack的一款双绞线屏蔽线缆,4部 + +开发体系中常用的硬件连接导线,所有的控制器Core、功能Unit都能够兼容GROVE接口.GROVE线由4条导线组成,其中两条用作数据信号,其余两条用作"VCC"与"GND",我们提供了不同的长度选择,以满足不同的应用需求. + + + + + + + +## 特性 + +- 5 种规格: 10cm, 20cm, 0.5m, 1m, 2m + +## 重量尺寸 +- 10cm (5/pcs) + - 重量:21g +- 20cm (5/pcs) + - 重量:22g +- 50cm (2/pcs) + - 重量:21g +- 100cm (1/pcs) + - 重量:20g +- 200cm (1/pcs) + - 重量:36g + + \ No newline at end of file diff --git a/docs/zh_CN/api/m5paper/epd_canvas.md b/docs/zh_CN/api/m5paper/epd_canvas.md index 0efd4309..bcbf1689 100644 --- a/docs/zh_CN/api/m5paper/epd_canvas.md +++ b/docs/zh_CN/api/m5paper/epd_canvas.md @@ -2,37 +2,45 @@ >M5PAPER搭载了一块分辨率为540*960 @4.7"的电子墨水屏,支持16级灰度显示. 在`M5.begin()`初始化中,已经创建了实例`M5EPD_Driver EPD = M5EPD_Driver();`并进行了初始化.通过下面的屏幕驱动,你能够将内容绘制的数据推送至屏幕. - - `m5epd_err_t begin(int8_t sck, int8_t mosi, int8_t miso, int8_t cs, int8_t busy, int8_t rst = -1);` +- **功能:清除屏幕内容/true则使用UPDATE_MODE_INIT模式初始化屏幕/false清除8951缓存区** - `m5epd_err_t Clear(bool init = false);` +- **功能:写入完整一帧数据/ 每像素4bit** - `m5epd_err_t WriteFullGram4bpp(const uint8_t *gram);` +- **功能:在指定区域写入局部数据/ 每像素4bit** - `m5epd_err_t WritePartGram4bpp(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint8_t *gram);` +- **功能:在指定区域填充指定数据** - `m5epd_err_t FillPartGram4bpp(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t data);` +- **功能:设置屏幕旋转角度/通常设置为90°** - `m5epd_err_t SetRotation(uint16_t rotate = IT8951_ROTATE_0);` -- `m5epd_err_t SetArea(uint16_t x, uint16_t y, uint16_t w, uint16_t h);` - +- **功能:以指定模式将缓存区中的数据刷新至全屏幕** - `m5epd_err_t UpdateFull(m5epd_update_mode_t mode);` +- **功能:以指定模式将缓存区中的数据刷新至屏幕指定区域** - `m5epd_err_t UpdateArea(uint16_t x, uint16_t y, uint16_t w, uint16_t h, m5epd_update_mode_t mode);` +- **功能:获取刷新次数** - `uint16_t UpdateCount(void);` +- **功能:读取屏幕旋转角度** - `uint8_t GetRotate(void) {return _rotate;};` +- **功能:读取屏幕方向** - `uint8_t GetDirection(void) {return _direction;};` +- **功能:重置刷新次数** - `void ResetUpdateCount(void);` +- **功能:检测8951是否忙碌** - `m5epd_err_t CheckAFSR(void);` -- `SPIClass* GetSPI(void) {return _epd_spi;}` - +- **功能:设置颜色反色** - `void SetColorReverse(bool is_reverse);` ## Canvas @@ -45,7 +53,7 @@ M5EPD_Canvas canvas(&M5.EPD); ``` -## 创建/删除Canvas +### 创建/删除Canvas >在开始绘图前,我们需要使用Canvas实例创建一个绘制区域 @@ -66,18 +74,22 @@ canvas.createCanvas(400, 300); ``` -## 推送Canvas +### 推送Canvas >在使用绘图API完成内容绘制后,我们需要使用`push`API将绘制区域推送到屏幕。 // Re-implement functions +- **功能:获取Canvas缓存区指针** - `void *frameBuffer(int8_t f = 1);` +- **功能:推送Canvas到屏幕指定区域,并指定刷新模式** - `void pushCanvas(int32_t x, int32_t y, m5epd_update_mode_t mode);` +- **功能:推送Canvas到屏幕0,0位置,指定刷新模式** - `void pushCanvas(m5epd_update_mode_t mode);` +- **功能:绘制到指定的Canvas** - `void pushToCanvas(int32_t x, int32_t y, M5EPD_Canvas* canvas);` **例程:** @@ -106,97 +118,65 @@ void loop() ``` -## 刷新模式 +### 刷新模式 >在使用`pushCanvas`时,我们需要传入一个刷新模式参数,在该库中的`m5epd_update_mode_t`已经枚举了几种不同的刷新模式,下面为你说明它们分别有什么样的特点。 ``` + typedef enum // Typical { // Ghosting Update Time Usage UPDATE_MODE_INIT = 0, // * N/A 2000ms Display initialization, - UPDATE_MODE_DU = 1, // Low 260ms Monochrome menu, text input, and touch screen input 1bit黑白,存在残影 - UPDATE_MODE_GC16 = 2, // * Very Low 450ms High quality images - UPDATE_MODE_GL16 = 3, // * Medium 450ms Text with white background - UPDATE_MODE_GLR16 = 4, // Low 450ms Text with white background - UPDATE_MODE_GLD16 = 5, // Low 450ms Text and graphics with white background - UPDATE_MODE_DU4 = 6, // * Medium 120ms Fast page flipping at reduced contrast 1bit黑白 稍微比DU快一点,残影相对DU较大 - UPDATE_MODE_A2 = 7, // Medium 290ms Anti-aliased text in menus / touch and screen input 2bit灰度,残影 - UPDATE_MODE_NONE = 8 上传至8951缓存区 不刷新。 -} m5epd_update_mode_t; // The ones marked with * are more commonly used - - - - UPDATE_MODE_GC16 = 2, // * Very Low 450ms High quality images 先黑闪后刷新 - UPDATE_MODE_GL16 = 3, // * Medium 450ms Text with white background 不黑闪 - UPDATE_MODE_GLR16 = 4, // Low 450ms Text with white background 不黑闪 - UPDATE_MODE_GLD16 = 5, // Low 450ms Text and graphics with white background 不黑闪 - - 刷新质量较好 + UPDATE_MODE_DU = 1, // Low 260ms 适合单色菜单,文本输入, 触摸反馈 1bit黑白,存在残影。 + UPDATE_MODE_GC16 = 2, // * Very Low 450ms 适合高质量图像显示 先黑闪后刷新 + UPDATE_MODE_GL16 = 3, // * Medium 450ms 适合白色背景的文本显示 不黑闪 + UPDATE_MODE_GLR16 = 4, // Low 450ms 适合白色背景的文本显示 不黑闪 + UPDATE_MODE_GLD16 = 5, // Low 450ms 适合白色背景的文本和图形显示 不黑闪 + UPDATE_MODE_DU4 = 6, // * Medium 120ms 降低对比度,适合需要快速翻页切换的情况 1bit黑白 稍微比DU快一点,残影相对DU较大 + UPDATE_MODE_A2 = 7, // Medium 290ms 适合菜单,触摸反馈,抗锯齿文字 2bit灰度,存在残影 + UPDATE_MODE_NONE = 8 上传至8951缓存区 不刷新,可以积累上传多次,然后一次刷新所有内容。 +} m5epd_update_mode_t; // 以上标注了`*`符号的为较为常用的刷新模式 ``` +>刷新质量较为好的几种分别为`UPDATE_MODE_GC16`,`UPDATE_MODE_GL16` , `UPDATE_MODE_GLR16` , `UPDATE_MODE_GLD16` +## 常用API - - -- `uint16_t readPixel(int32_t x, int32_t y);` - -- `void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint8_t *data);` - -- `void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t transp, const uint8_t *data);` - - - +- **功能:填充绘制区域** - `void fillCanvas(uint32_t color);` +- **功能:推送Buffer数据** +- `void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint8_t *data);` +- `void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t transp, const uint8_t *data);` +- **功能:读取像素点颜色** +- `uint16_t readPixel(int32_t x, int32_t y);` + +- **功能:绘制像素点** - `void drawPixel(int32_t x, int32_t y, uint32_t color);` - -- `uint16_t alphaBlend16(uint8_t alpha, uint8_t fgc, uint8_t bgc);` - - -- `void drawFreetypeBitmap(int32_t cx, int32_t cy, uint16_t bw, uint16_t bh, uint8_t *bitmap);` - - - -**例程:** - - - - - - - - - - -- `void setDriver(M5EPD_Driver *driver);` - +- **功能:绘制二维码** - `void qrcode(const char *string, uint16_t x = 50, uint16_t y = 10, uint16_t width = 220, uint8_t version = 6);` - - `void qrcode(const String &string, uint16_t x = 50, uint16_t y = 10, uint16_t width = 220, uint8_t version = 6);` +- **功能:以中心点绘制方块** - `void fillCenterSquare(int32_t cx, int32_t cy, uint16_t w, uint8_t color);` -- `void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint8_t thickness, uint8_t color);` - -- `void drawFastVLine(int32_t x, int32_t y, int32_t h, uint8_t thickness, uint8_t color);` - -- `void drawFastHLine(int32_t x, int32_t y, int32_t w, uint8_t thickness, uint8_t color);` - -- `void fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);` - +- **功能:读取当前Canvas图像的Buffer大小** - `uint32_t getBufferSize(void) {return _buffer_size;}` +- **功能:设置反色** - `void ReverseColor(void);` +- **功能:设置局部反色** - `void ReversePartColor(int32_t x, int32_t y, int32_t w, int32_t h);` +- **功能:Canvas复制** - `void operator=(const M5EPD_Canvas &src);` - - +- **功能:设置屏幕驱动** +- `void setDriver(M5EPD_Driver *driver);` ## JPG/BMP/PNG @@ -246,203 +226,143 @@ typedef enum // Typical double scale = 1.0, uint8_t alphaThreshold = 127);` +**例程:** + +``` +#include +#include + +M5EPD_Canvas canvas(&M5.EPD); + +void setup() +{ + M5.begin(); + M5.EPD.SetRotation(90); + M5.EPD.Clear(true); + WiFi.begin("WIFI-SSID", "WIFI-PASSWORD"); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + + canvas.createCanvas(540, 960); + canvas.setTextSize(3); + canvas.drawJpgUrl("https://m5stack.oss-cn-shenzhen.aliyuncs.com/image/example_pic/flower.jpg"); + canvas.pushCanvas(0,0,UPDATE_MODE_GC16); +} + +void loop() +{ + +} +``` +## Text +>下面是一些常用的文本绘制API。 -- `uint32_t getExceedOffset(void) {return TFT_eSPI::getExceedOffset();}` +- **功能:设置字体颜色** +- `void setTextColor(uint16_t color) { TFT_eSPI::setTextColor(color); }` +- `void setTextColor(uint16_t fgcolor, uint16_t bgcolor) { TFT_eSPI::setTextColor(fgcolor, bgcolor); }` -- `void setTextArea(uint16_t x, uint16_t y, uint16_t w, uint16_t h) {TFT_eSprite::setTextArea(x,y,w,h);}` - -- `size_t write(uint8_t utf8){return TFT_eSprite::write(utf8);}` - -- `void *createCanvas(int16_t width, int16_t height, uint8_t frames = 1) { return TFT_eSprite::createSprite(width, height, frames); };` - -- `void deleteCanvas(void) { TFT_eSprite::deleteSprite(); }` - - - - -- `void setPivot(int16_t x, int16_t y) { TFT_eSprite::setPivot(x, y); }` - -- `int16_t getPivotX(void) { return _xpivot; }` - -- `int16_t getPivotY(void) { return _ypivot; }` - -- `int16_t width(void) { return _dwidth; }` - -- `int16_t height(void) { return _dheight; }` - -- `void setCursor(int16_t x, int16_t y) { TFT_eSPI::setCursor(x, y); }` - -- `void setCursor(int16_t x, int16_t y, uint8_t font) { TFT_eSPI::setCursor(x, y, font); }` - -- `int16_t getCursorX(void) { return TFT_eSPI::getCursorX(); }` - -- `int16_t getCursorY(void) { return TFT_eSPI::getCursorY(); }` - -- `uint16_t fontsLoaded(void) { return TFT_eSPI::fontsLoaded(); }` +- **功能:设置字体大小** +- `void setTextSize(uint8_t size) { TFT_eSPI::setTextSize(size); }` +- **功能:设置文本换行** +- `void setTextWrap(boolean wrapX, boolean wrapY = false) { TFT_eSPI::setTextWrap(wrapX, wrapY); }` +- **功能:设置文本基准** +- `void setTextDatum(uint8_t datum) { TFT_eSPI::setTextDatum(datum); }` +- **功能:设置文本边距** +- `void setTextPadding(uint16_t x_width) { TFT_eSPI::setTextPadding(x_width); }` +- **功能:绘制整数** +- `int16_t drawNumber(long long_num, int32_t poX, int32_t poY, uint8_t font) { return TFT_eSPI::drawNumber(long_num, poX, poY, font); }` +- `int16_t drawNumber(long long_num, int32_t poX, int32_t poY) { return TFT_eSPI::drawNumber(long_num, poX, poY); }` +- **功能:绘制浮点数** +- `int16_t drawFloat(float floatNumber, uint8_t decimal, int32_t poX, int32_t poY, uint8_t font) { return TFT_eSPI::drawFloat(floatNumber, decimal, poX, poY, font); }` +- `int16_t drawFloat(float floatNumber, uint8_t decimal, int32_t poX, int32_t poY) { return TFT_eSPI::drawFloat(floatNumber, decimal, poX, poY); }` +- **功能:绘制字符串** +- `int16_t drawString(const char *string, int32_t poX, int32_t poY, uint8_t font) { return TFT_eSPI::drawString(string, poX, poY, font); }` +- `int16_t drawString(const char *string, int32_t poX, int32_t poY) { return TFT_eSPI::drawString(string, poX, poY); }` +- `int16_t drawString(const String &string, int32_t poX, int32_t poY, uint8_t font) { return TFT_eSPI::drawString(string, poX, poY, font); }` +- `int16_t drawString(const String &string, int32_t poX, int32_t poY) { return TFT_eSPI::drawString(string, poX, poY); }` +- **功能:解码UTF8字符串/返回Unicode值** +- `uint16_t decodeUTF8(uint8_t *buf, uint16_t *index, uint16_t remaining) { return TFT_eSPI::decodeUTF8(buf, index, remaining); };` +- `uint16_t decodeUTF8(uint8_t *buf, uint16_t *index, uint16_t remaining, uint8_t *length) { return TFT_eSPI::decodeUTF8(buf, index, remaining, length); };` +- **功能:绘制字符** +- `int16_t drawChar(uint16_t uniCode, int32_t x, int32_t y) { return TFT_eSprite::drawChar(uniCode, x, y); }` +- `int16_t drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font) { return TFT_eSprite::drawChar(uniCode, x, y, font); }` +- `void drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32_t bg, uint8_t size) { TFT_eSprite::drawChar(x, y, c, color, bg, size); }` +- **功能:获取文本宽度** - `int16_t textWidth(const char *string, uint8_t font) {return TFT_eSPI::textWidth(string, font);}` - - `int16_t textWidth(const char *string) {return TFT_eSPI::textWidth(string);}` - - `int16_t textWidth(const String& string, uint8_t font) {return TFT_eSPI::textWidth(string, font);}` - - `int16_t textWidth(const String& string) {return TFT_eSPI::textWidth(string);}` - - - ## Drawing - // Parent functions - drawing +>下面是一些常用的绘图API。 -- **功能:使用Png的Url/网络资源数据绘制图像** +// Parent functions - drawing + +- **功能:绘制圆形** - `void drawCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color) { TFT_eSPI::drawCircle(x0, y0, r, color); }` -- **功能:使用Png的Url/网络资源数据绘制图像** +- **功能:绘制圆形助手** - `void drawCircleHelper(int32_t x0, int32_t y0, int32_t r, uint8_t cornername, uint32_t color) { TFT_eSPI::drawCircleHelper(x0, y0, r, cornername, color); }` -- **功能:使用Png的Url/网络资源数据绘制图像** +- **功能:绘制填充圆形** - `void fillCircle(int32_t x0, int32_t y0, int32_t r, uint32_t color) { TFT_eSPI::fillCircle(x0, y0, r, color); }` -- **功能:使用Png的Url/网络资源数据绘制图像** +- **功能:绘制填充圆形助手** - `void fillCircleHelper(int32_t x0, int32_t y0, int32_t r, uint8_t cornername, int32_t delta, uint32_t color) { TFT_eSPI::fillCircleHelper(x0, y0, r, cornername, delta, color); }` -- **功能:使用Png的Url/网络资源数据绘制图像** -- `void setWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1) { TFT_eSprite::setWindow(x0, y0, x1, y1); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `void pushColor(uint32_t color) { TFT_eSprite::pushColor(color); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `void pushColor(uint32_t color, uint16_t len) { TFT_eSprite::pushColor(color, len); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `void writeColor(uint16_t color) { TFT_eSprite::writeColor(color); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** +- **功能:绘制直线** - `void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t color) { TFT_eSprite::drawLine(x0, y0, x1, y1, color); }` +- `void drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint8_t thickness, uint8_t color);` -- **功能:使用Png的Url/网络资源数据绘制图像** +- **功能:快速绘制垂直直线** - `void drawFastVLine(int32_t x, int32_t y, int32_t h, uint32_t color) { TFT_eSprite::drawFastVLine(x, y, h, color); }` +- `void drawFastVLine(int32_t x, int32_t y, int32_t h, uint8_t thickness, uint8_t color);` -- **功能:使用Png的Url/网络资源数据绘制图像** -- `void drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color) { TFT_eSprite::drawFastHLine(x, y, w, color); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `void drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32_t bg, uint8_t size) { TFT_eSprite::drawChar(x, y, c, color, bg, size); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `int16_t drawChar(uint16_t uniCode, int32_t x, int32_t y) { return TFT_eSprite::drawChar(uniCode, x, y); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `int16_t drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font) { return TFT_eSprite::drawChar(uniCode, x, y, font); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `void drawGlyph(uint16_t code) { TFT_eSprite::drawGlyph(code); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `void printToSprite(String string) { TFT_eSprite::printToSprite(string); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `void printToSprite(char *cbuffer, uint16_t len) { TFT_eSprite::printToSprite(cbuffer, len); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `int16_t printToSprite(int16_t x, int16_t y, uint16_t index) { return TFT_eSprite::printToSprite(x, y, index); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** +- **功能:绘制椭圆** - `void drawEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color) { TFT_eSPI::drawEllipse(x0, y0, rx, ry, color); }` -- **功能:使用Png的Url/网络资源数据绘制图像** +- **功能:绘制填充椭圆** - `void fillEllipse(int16_t x0, int16_t y0, int32_t rx, int32_t ry, uint16_t color) { TFT_eSPI::fillEllipse(x0, y0, rx, ry, color); }` -- **功能:使用Png的Url/网络资源数据绘制图像** +- **功能:绘制矩形** - `void drawRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color) { TFT_eSPI::drawRect(x, y, w, h, color); }` -- **功能:使用Png的Url/网络资源数据绘制图像** +- **功能:绘制填充矩形** +- `void fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);` + +- **功能:绘制圆角矩形** - `void drawRoundRect(int32_t x0, int32_t y0, int32_t w, int32_t h, int32_t radius, uint32_t color) { TFT_eSPI::drawRoundRect(x0, y0, w, h, radius, color); }` -- **功能:使用Png的Url/网络资源数据绘制图像** +- **功能:绘制填充圆角矩形** - `void fillRoundRect(int32_t x0, int32_t y0, int32_t w, int32_t h, int32_t radius, uint32_t color) { TFT_eSPI::fillRoundRect(x0, y0, w, h, radius, color); }` -- **功能:使用Png的Url/网络资源数据绘制图像** +- **功能:绘制三角形** - `void drawTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color) { TFT_eSPI::drawTriangle(x0, y0, x1, y1, x2, y2, color); }` -- **功能:使用Png的Url/网络资源数据绘制图像** +- **功能:绘制填充三角形** - `void fillTriangle(int32_t x0, int32_t y0, int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint32_t color) { TFT_eSPI::fillTriangle(x0, y0, x1, y1, x2, y2, color); }` -- **功能:使用Png的Url/网络资源数据绘制图像** -- `void setTextColor(uint16_t color) { TFT_eSPI::setTextColor(color); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `void setTextColor(uint16_t fgcolor, uint16_t bgcolor) { TFT_eSPI::setTextColor(fgcolor, bgcolor); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `void setTextSize(uint8_t size) { TFT_eSPI::setTextSize(size); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `void setTextWrap(boolean wrapX, boolean wrapY = false) { TFT_eSPI::setTextWrap(wrapX, wrapY); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `void setTextDatum(uint8_t datum) { TFT_eSPI::setTextDatum(datum); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `void setTextPadding(uint16_t x_width) { TFT_eSPI::setTextPadding(x_width); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `int16_t drawNumber(long long_num, int32_t poX, int32_t poY, uint8_t font) { return TFT_eSPI::drawNumber(long_num, poX, poY, font); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `int16_t drawNumber(long long_num, int32_t poX, int32_t poY) { return TFT_eSPI::drawNumber(long_num, poX, poY); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `int16_t drawFloat(float floatNumber, uint8_t decimal, int32_t poX, int32_t poY, uint8_t font) { return TFT_eSPI::drawFloat(floatNumber, decimal, poX, poY, font); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `int16_t drawFloat(float floatNumber, uint8_t decimal, int32_t poX, int32_t poY) { return TFT_eSPI::drawFloat(floatNumber, decimal, poX, poY); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `int16_t drawString(const char *string, int32_t poX, int32_t poY, uint8_t font) { return TFT_eSPI::drawString(string, poX, poY, font); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `int16_t drawString(const char *string, int32_t poX, int32_t poY) { return TFT_eSPI::drawString(string, poX, poY); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `int16_t drawCentreString(const char *string, int32_t dX, int32_t poY, uint8_t font) { return TFT_eSPI::drawCentreString(string, dX, poY, font); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `int16_t drawRightString(const char *string, int32_t dX, int32_t poY, uint8_t font) { return TFT_eSPI::drawRightString(string, dX, poY, font); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `int16_t drawString(const String &string, int32_t poX, int32_t poY, uint8_t font) { return TFT_eSPI::drawString(string, poX, poY, font); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `int16_t drawString(const String &string, int32_t poX, int32_t poY) { return TFT_eSPI::drawString(string, poX, poY); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `int16_t drawCentreString(const String &string, int32_t dX, int32_t poY, uint8_t font) { return TFT_eSPI::drawCentreString(string, dX, poY, font); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `int16_t drawRightString(const String &string, int32_t dX, int32_t poY, uint8_t font) { return TFT_eSPI::drawRightString(string, dX, poY, font); }` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `uint16_t decodeUTF8(uint8_t *buf, uint16_t *index, uint16_t remaining) { return TFT_eSPI::decodeUTF8(buf, index, remaining); };` - -- **功能:使用Png的Url/网络资源数据绘制图像** -- `uint16_t decodeUTF8(uint8_t *buf, uint16_t *index, uint16_t remaining, uint8_t *length) { return TFT_eSPI::decodeUTF8(buf, index, remaining, length); };` +## print +>下面是一些关于print格式化输出的一些函数重载。 // Parent functions - Print - `size_t printf(const char * format, ...) __attribute__ ((format (printf, 2, 3)));` @@ -471,7 +391,6 @@ typedef enum // Typical - `size_t print(struct tm * timeinfo, const char * format = NULL){return Print::print(timeinfo, format);}` - - `size_t println(const __FlashStringHelper *x){return Print::println(x);}` - `size_t println(const String &x){return Print::println(x);}` @@ -496,17 +415,4 @@ typedef enum // Typical - `size_t println(struct tm * timeinfo, const char * format = NULL){return Print::println(timeinfo, format);}` -- `size_t println(void){return Print::println();}` - - - - - - - - - - - - - +- `size_t println(void){return Print::println();}` \ No newline at end of file diff --git a/docs/zh_CN/api/m5paper/touch.md b/docs/zh_CN/api/m5paper/touch.md index 9ba91831..1e9a6ce9 100644 --- a/docs/zh_CN/api/m5paper/touch.md +++ b/docs/zh_CN/api/m5paper/touch.md @@ -6,40 +6,40 @@ >在`M5.begin()`初始化中,已经创建了实例`GT911 TP = GT911();`并进行了初始化. 你可以用该实例中的API获取触摸交互信息。 -- 初始化I2C总线 +- **功能:初始化I2C总线** - `esp_err_t begin(uint8_t pin_sda, uint8_t pin_scl, uint8_t pin_int);` -- 是否有新的屏幕触摸数据待读取 +- **功能:是否有新的屏幕触摸数据待读取** - `bool avaliable();` -- 刷新屏幕检测 +- **功能:刷新屏幕检测** - `void update();` -- 设置屏幕旋转角度 +- **功能:设置屏幕旋转角度/通常设置为90°** - `void SetRotation(uint16_t rotate);` -- 读取触摸手指X坐标 +- **功能:读取触摸手指X坐标** - `uint16_t readFingerX(uint8_t num);` -- 读取触摸手指Y坐标 +- **功能:读取触摸手指Y坐标** - `uint16_t readFingerY(uint8_t num);` -- 读取触摸手指ID坐标 +- **功能:读取触摸手指ID坐标** - `uint16_t readFingerID(uint8_t num);` -- 读取触摸手指作用区域矩形大小 +- **功能:读取触摸手指作用区域矩形大小** - `uint16_t readFingerSize(uint8_t num);` -- 最后一次读取触摸手指数量 +- **功能:最后一次读取触摸手指数量** - `uint8_t getFingerNum(void);` -- 检测手指是否抬起 +- **功能:检测手指是否抬起** - `bool isFingerUp(void);` -- 将当前触摸状态清空 +- **功能:将当前触摸状态清空** - `void flush(void);` -- 读取触摸手指信息,返回结构体实例 +- **功能:读取触摸手指信息,返回结构体实例** - `tp_finger_t readFinger(uint8_t num);` ``` diff --git a/docs/zh_CN/arduino/arduino_home_page.md b/docs/zh_CN/arduino/arduino_home_page.md index e11bef54..21d367ec 100644 --- a/docs/zh_CN/arduino/arduino_home_page.md +++ b/docs/zh_CN/arduino/arduino_home_page.md @@ -91,6 +91,16 @@ const coreink_api = { "id":"coreink_api" }; +const m5paper_api = { + 'title':"M5Paper API", + 'item':{ + 'System & Button & SHT30 & POWER & RTC':'#/zh_CN/api/m5paper/system_api', + 'EPD Canvas':'#/zh_CN/api/m5paper/epd_canvas', + 'TOUCH':'#/zh_CN/api/m5paper/touch' + }, + "id":"m5paper_api" +}; + var arduino_home_page = new Vue({ el:'#arduino_home_page', @@ -101,7 +111,8 @@ var arduino_home_page = new Vue({ m5core_api: m5core_api, m5stickc_api: m5stickc_api, m5core2_api: m5core2_api, - coreink_api: coreink_api + coreink_api: coreink_api, + m5paper_api: m5paper_api } }; } diff --git a/docs/zh_CN/core/m5paper.md b/docs/zh_CN/core/m5paper.md index 7e48913e..e08b61a1 100644 --- a/docs/zh_CN/core/m5paper.md +++ b/docs/zh_CN/core/m5paper.md @@ -207,7 +207,7 @@ - **API** - - [Arduino API](zh_CN/arduino/arduino_home_page) + - [Arduino API](zh_CN/arduino/arduino_home_page?id=m5paper) ## 原理图 diff --git a/docs/zh_CN/hat/hat-roverc.md b/docs/zh_CN/hat/hat-roverc.md index f85922f7..2f58878c 100644 --- a/docs/zh_CN/hat/hat-roverc.md +++ b/docs/zh_CN/hat/hat-roverc.md @@ -71,7 +71,7 @@ ## 使用说明 使用前请确保RoverC已经充满电,充电方式:将M5StickC插入RoverC,并连接USB线缆进行充电. -分别将两台M5StickC烧录JoyC与RoverC的EasyLoader固件,烧录后分别插入JoyC与RoverC,开机后RoverC会显示"M5AP+2字节mac地址"热点名称,同时JoyC会扫描到RoverC的mac地址名,长按3秒JoyC上的M5StickC的A键,开始扫描小车的热点,即可配对成功。成功配对后屏幕左上角会高亮显示链接图标,同时屏幕显示摇杆数值。左摇杆上下控制前后,左右控制平移,右摇杆左右控制转向。 +分别将两台M5StickC烧录JoyC与RoverC的EasyLoader固件,烧录后分别插入JoyC与RoverC,开机后RoverC会显示"M5AP+2字节mac地址"热点名称,同时JoyC会扫描到RoverC的mac地址名,长按3秒JoyC上的M5StickC的Home键,开始扫描小车的热点,即可配对成功。成功配对后屏幕左上角会高亮显示链接图标,同时屏幕显示摇杆数值。左摇杆上下控制前后,左右控制平移,右摇杆左右控制转向。 电机控制: diff --git a/docs/zh_CN/hat/hat_roverc_pro.md b/docs/zh_CN/hat/hat_roverc_pro.md index e19bfad7..f5579da4 100644 --- a/docs/zh_CN/hat/hat_roverc_pro.md +++ b/docs/zh_CN/hat/hat_roverc_pro.md @@ -137,7 +137,7 @@ MotorControl: ### 1. Arduino IDE 配合摇杆使用(无夹持) [点击此处](https://github.com/m5stack/M5-ProductExampleCodes/tree/master/Hat/RoverC) -使用前,请确保RoverC充满电。充电方式:将M5StickC/M5StickC Plus插入RoverC,连接USB线充电。分别用两个M5StickC/M5StickC PLUS烧录JoyC和RoverC的EasyLoader固件。然后分别插入JoyC和RoverC。开机后,RoverC将显示MAC地址名称和电池电量。同时,JoyC将扫描RoverC的MAC地址。长按Joyc上M5StickC的A键,两者将配对。左摇杆控制前进和后退运动,左右控制平移,右摇杆控制左右转向。 +使用前,请确保RoverC充满电。充电方式:将M5StickC/M5StickC Plus插入RoverC,连接USB线充电。分别用两个M5StickC/M5StickC PLUS烧录JoyC和RoverC的EasyLoader固件。然后分别插入JoyC和RoverC。开机后,RoverC将显示MAC地址名称和电池电量。同时,JoyC将扫描RoverC的MAC地址。长按Joyc上M5StickC的Home键,两者将配对。左摇杆控制前进和后退运动,左右控制平移,右摇杆控制左右转向。 单独使用参考(含夹持) [点击此处](https://github.com/m5stack/M5-ProductExampleCodes/tree/master/Application/RoverC_PRO_Arduino_Alone)