Merge pull request #1 from Xinyuan-LilyGO/master

merge from upstream
This commit is contained in:
dervomsee
2021-04-21 13:19:41 +02:00
committed by GitHub
65 changed files with 219509 additions and 2028 deletions

View File

@@ -86,4 +86,21 @@
- Update pin definition document
## (23/2/2021)
- <BasicUnit/AXP20x_ADC> example compatible with T-Block
- <BasicUnit/AXP20x_ADC> example compatible with T-Block
## (27/3/2021)
- [Merged#119](https://github.com/Xinyuan-LilyGO/TTGO_TWatch_Library/pull/119)
- Update `library.properties`,up to `1.4.2` version
- Added <examples/Shield/S7xG_Debug> examples
## (4/1/2021)
- Update TWATCH-N touch to IO33
- Added <examples/UnitTest/HardwareTest> examples
## (4/6/2021)
- Add S7XG sample code <examples/Shield/S7xG/*>
## (4/13/2021)
- Add PN532 NFC examples, The example comes from <https://github.com/adafruit/Adafruit-PN532>

View File

@@ -81,7 +81,7 @@
<td align="center">Product</td>
<td align="center"><a href="https://www.aliexpress.com/item/33038999162.html">T-Watch-2019</a></td>
<td align="center"><a href="https://www.aliexpress.com/item/4000971508364.html">T-Watch-2020-V1</a></td>
<td align="center">T-Watch-2020-V2</a></td>
<td align="center"><a href="https://www.aliexpress.com/item/1005002264354524.html">T-Watch-2020-V2</a></td>
<td align="center"><a href="https://www.aliexpress.com/item/1005002053650442.html">T-Watch-2020-V3</a></td>
<td align="center"><a href="https://www.aliexpress.com/item/1005001824993604.html">T-Block/T-Block-V1</a></td>
<td align="center"><a href="https://www.aliexpress.com/item/1005001447548347.html">LilyPi</a></td>
@@ -270,7 +270,7 @@
<!-- 2020 V1 -->
<td align="center">❌</a></td>
<!-- 2020 V2 -->
<td align="center"><a href="https://github.com/Xinyuan-LilyGO/LilyGo-HAL/tree/master/L67K"> Quectel L67K</a></td>
<td align="center"><a href="https://github.com/Xinyuan-LilyGO/LilyGo-HAL/tree/master/L76K"> Quectel L76K</a></td>
<!-- 2020 V3 -->
<td align="center">❌</a></td>
<!-- TBLOCK -->

View File

@@ -38,7 +38,7 @@
│   └── WakeupFormTouchScreen #从触摸屏唤醒ESP32
├── ClientProject #客户的示例目录
│   └── SimpleFramework #使用TFT_eSPI构成的框架
├── ExternTFTLibrary #使用PlatfromIO,外部TFT_eSPI与TTGO_TWatch_Library搭配使用示例
├── ExternTFTLibrary #使用PlatformIO,外部TFT_eSPI与TTGO_TWatch_Library搭配使用示例
│   └── src
├── LVGL #LVGL图形框架演示目录
│   ├── AnalogRead #获取模拟数据在显示屏中绘制曲线
@@ -125,4 +125,4 @@
│   └── Unicode
├── UnitTest #硬件单元测试目录
│   └── ScreenRotation #屏幕选择与触摸
```
```

View File

@@ -48,7 +48,7 @@
## 3.datasheet
- [Esp32](https://www.espressif.com/sites/default/files/documentation/esp32_technical_reference_manual_en.pdf)
- [L67K](https://github.com/Xinyuan-LilyGO/LilyGo-HAL/tree/master/L67K)
- [L76K](https://github.com/Xinyuan-LilyGO/LilyGo-HAL/tree/master/L76K)
- [AXP202](https://github.com/Xinyuan-LilyGO/LilyGo-HAL/tree/master/AXP202)
- [BMA423](https://github.com/Xinyuan-LilyGO/LilyGo-HAL/tree/master/BMA423)
- [ST7789](https://github.com/Xinyuan-LilyGO/LilyGo-HAL/blob/master/DISPLAY/ST7789V.pdf)

View File

@@ -36,9 +36,17 @@ void setup()
ttgo->button->setPressedHandler(pressed);
ttgo->button->setReleasedHandler(released);
#ifdef LILYGO_WATCH_2019_NO_TOUCH
pinMode(TOUCH_INT, INPUT);
#endif
}
void loop()
{
#ifdef LILYGO_WATCH_2019_NO_TOUCH
if (digitalRead(TOUCH_INT)) {
Serial.println("TWatchN touch pressed");
}
#endif
ttgo->button->loop();
}

View File

@@ -23,6 +23,8 @@ void setup()
//!Clear IRQ unprocessed first
ttgo->power->enableIRQ(AXP202_PEK_SHORTPRESS_IRQ, true);
ttgo->power->clearIRQ();
pinMode(TOUCH_INT, INPUT);
}
void loop()

View File

@@ -1,4 +1,11 @@
/*
Use Arduino ESP32 Sketch data Upload files,
if you not install
[download ESP32FS-vX.zip](https://github.com/me-no-dev/arduino-esp32fs-plugin/releases),
Extract to <C:\Users\Your User Name\Documents\Arduino\tools>
* */
#include "config.h"
TTGOClass *ttgo;

View File

@@ -0,0 +1,17 @@
// => Hardware select
#define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line
// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line
// #define LILYGO_WATCH_BLOCK // To use T-Watch Block , please uncomment this line
//NOT SUPPORT ...
// //#define LILYGO_WATCH_2020_V1
//NOT SUPPORT ...
// => Function select
#define LILYGO_WATCH_HAS_NFC
#include <LilyGoWatch.h>

View File

@@ -0,0 +1,102 @@
/**************************************************************************/
/*!
@file iso14443a_uid.ino
@author Adafruit Industries
@license BSD (see license.txt)
This example will attempt to connect to an ISO14443A
card or tag and retrieve some basic information about it
that can be used to determine what type of card it is.
Note that you need the baud rate to be 115200 because we need to print
out the data and read from the card at the same time!
This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
This library works with the Adafruit NFC breakout
----> https://www.adafruit.com/products/364
Check out the links above for our tutorials and wiring diagrams
These chips use SPI or I2C to communicate.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
*/
/**************************************************************************/
#include "config.h"
TTGOClass *ttgo;
Adafruit_PN532 *nfc;
void setup(void)
{
Serial.begin(115200);
while (!Serial) delay(10); // for Leonardo/Micro/Zero
Serial.println("Looking for PN532...");
ttgo = TTGOClass::getWatch();
ttgo->begin();
#ifdef LILYGO_WATCH_2019_WITH_TOUCH
ttgo->openBL();
ttgo->tft->println("iso14443a_uid example!");
ttgo->tft->println("All messages will be output to the serial port, please open the terminal to view ");
#endif
ttgo->enableLDO3();
ttgo->nfc_begin();
nfc = ttgo->nfc;
uint32_t versiondata = nfc->getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
// Got ok data, print it out!
Serial.print("Found chip PN5"); Serial.println((versiondata >> 24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata >> 16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata >> 8) & 0xFF, DEC);
// configure board to read RFID tags
nfc->SAMConfig();
}
void loop(void)
{
boolean success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
// Wait for an ISO14443A type cards (Mifare, etc.). When one is found
// 'uid' will be populated with the UID, and uidLength will indicate
// if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
success = nfc->readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
if (success) {
Serial.println("Found a card!");
Serial.print("UID Length: "); Serial.print(uidLength, DEC); Serial.println(" bytes");
Serial.print("UID Value: ");
for (uint8_t i = 0; i < uidLength; i++) {
Serial.print(" 0x"); Serial.print(uid[i], HEX);
}
Serial.println("");
// Wait 1 second before continuing
delay(1000);
} else {
// PN532 probably timed out waiting for a card
Serial.println("Timed out waiting for a card");
}
}

View File

@@ -0,0 +1,17 @@
// => Hardware select
#define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line
// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line
// #define LILYGO_WATCH_BLOCK // To use T-Watch Block , please uncomment this line
//NOT SUPPORT ...
// //#define LILYGO_WATCH_2020_V1
//NOT SUPPORT ...
// => Function select
#define LILYGO_WATCH_HAS_NFC
#include <LilyGoWatch.h>

View File

@@ -0,0 +1,99 @@
/**************************************************************************/
/*!
@file iso14443as_target.ino
@original Adafruit Industries
@modified Salvador Mendoza(@Netxing)
@license BSD (see license.txt)
This example will attempt to mimic an ISO14443A smart card
and retrieve some basic information from a PoS or terminal,
this can be used to establish a communication process.
Note that you need the baud rate to be 115200 because we need to print
out the data and read from the card at the same time!
This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
This library works with the Adafruit NFC breakout
----> https://www.adafruit.com/products/364
Check out the links above for our tutorials and wiring diagrams
These chips use SPI or I2C to communicate.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
*/
/**************************************************************************/
#include "config.h"
TTGOClass *ttgo;
Adafruit_PN532 *nfc;
void setup(void)
{
Serial.begin(115200);
while (!Serial) delay(10); // for Leonardo/Micro/Zero
Serial.println("Looking for PN532...");
ttgo = TTGOClass::getWatch();
ttgo->begin();
#ifdef LILYGO_WATCH_2019_WITH_TOUCH
ttgo->openBL();
ttgo->tft->println("iso14443as_target example!");
ttgo->tft->println("All messages will be output to the serial port, please open the terminal to view ");
#endif
ttgo->enableLDO3();
ttgo->nfc_begin();
nfc = ttgo->nfc;
uint32_t versiondata = nfc->getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
// Got ok data, print it out!
Serial.print("Found chip PN5"); Serial.println((versiondata >> 24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata >> 16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata >> 8) & 0xFF, DEC);
// configure board to read RFID tags
nfc->SAMConfig();
}
void loop(void)
{
boolean success;
uint8_t apdubuffer[255] = {}, apdulen;
uint8_t ppse[] = {0x8E, 0x6F, 0x23, 0x84, 0x0E, 0x32, 0x50, 0x41, 0x59, 0x2E, 0x53, 0x59, 0x53, 0x2E, 0x44, 0x44, 0x46, 0x30, 0x31, 0xA5, 0x11, 0xBF, 0x0C, 0x0E, 0x61, 0x0C, 0x4F, 0x07, 0xA0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10, 0x87, 0x01, 0x01, 0x90, 0x00};
nfc->AsTarget();
success = nfc->getDataTarget(apdubuffer, &apdulen); //Read initial APDU
if (apdulen > 0) {
for (uint8_t i = 0; i < apdulen; i++) {
Serial.print(" 0x"); Serial.print(apdubuffer[i], HEX);
}
Serial.println("");
}
nfc->setDataTarget(ppse, sizeof(ppse)); //Mimic a smart card response with a PPSE APDU
nfc->getDataTarget(apdubuffer, &apdulen); //Read respond from the PoS or Terminal
if (apdulen > 0) {
for (uint8_t i = 0; i < apdulen; i++) {
Serial.print(" 0x"); Serial.print(apdubuffer[i], HEX);
}
Serial.println("");
}
delay(1000);
}

View File

@@ -0,0 +1,17 @@
// => Hardware select
#define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line
// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line
// #define LILYGO_WATCH_BLOCK // To use T-Watch Block , please uncomment this line
//NOT SUPPORT ...
// //#define LILYGO_WATCH_2020_V1
//NOT SUPPORT ...
// => Function select
#define LILYGO_WATCH_HAS_NFC
#include <LilyGoWatch.h>

View File

@@ -0,0 +1,187 @@
/**************************************************************************/
/*!
@file mifareclassic_formatndef.ino
@author Adafruit Industries
@license BSD (see license.txt)
This example attempts to format a clean Mifare Classic 1K card as
an NFC Forum tag (to store NDEF messages that can be read by any
NFC enabled Android phone, etc.)
Note that you need the baud rate to be 115200 because we need to print
out the data and read from the card at the same time!
This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
This library works with the Adafruit NFC Shield
----> https://www.adafruit.com/products/789
Check out the links above for our tutorials and wiring diagrams
These chips use SPI or I2C to communicate
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
*/
/**************************************************************************/
#include "config.h"
TTGOClass *ttgo;
Adafruit_PN532 *nfc;
/*
We can encode many different kinds of pointers to the card,
from a URL, to an Email address, to a phone number, and many more
check the library header .h file to see the large # of supported
prefixes!
*/
// For a http://www. url:
const char *url = "adafruit.com";
uint8_t ndefprefix = NDEF_URIPREFIX_HTTP_WWWDOT;
// for an email address
//const char * url = "mail@example.com";
//uint8_t ndefprefix = NDEF_URIPREFIX_MAILTO;
// for a phone number
//const char * url = "+1 212 555 1212";
//uint8_t ndefprefix = NDEF_URIPREFIX_TEL;
void setup(void)
{
Serial.begin(115200);
while (!Serial) delay(10); // for Leonardo/Micro/Zero
Serial.println("Looking for PN532...");
ttgo = TTGOClass::getWatch();
ttgo->begin();
#ifdef LILYGO_WATCH_2019_WITH_TOUCH
ttgo->openBL();
ttgo->tft->println("mifareclassic_formatndef example!");
ttgo->tft->println("All messages will be output to the serial port, please open the terminal to view ");
#endif
ttgo->enableLDO3();
ttgo->nfc_begin();
nfc = ttgo->nfc;
uint32_t versiondata = nfc->getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
// Got ok data, print it out!
Serial.print("Found chip PN5"); Serial.println((versiondata >> 24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata >> 16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata >> 8) & 0xFF, DEC);
// configure board to read RFID tags
nfc->SAMConfig();
}
void loop(void)
{
uint8_t success; // Flag to check if there was an error with the PN532
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
// Use the default key
uint8_t keya[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
Serial.println("");
Serial.println("PLEASE NOTE: Formatting your card for NDEF records will change the");
Serial.println("authentication keys. To reformat your NDEF tag as a clean Mifare");
Serial.println("Classic tag, use the mifareclassic_ndeftoclassic example!");
Serial.println("");
Serial.println("Place your Mifare Classic card on the reader to format with NDEF");
Serial.println("and press any key to continue ...");
// Wait for user input before proceeding
while (!Serial.available());
// a key was pressed1
while (Serial.available()) Serial.read();
// Wait for an ISO14443A type card (Mifare, etc.). When one is found
// 'uid' will be populated with the UID, and uidLength will indicate
// if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
success = nfc->readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
if (success) {
// Display some basic information about the card
Serial.println("Found an ISO14443A card");
Serial.print(" UID Length: "); Serial.print(uidLength, DEC); Serial.println(" bytes");
Serial.print(" UID Value: ");
nfc->PrintHex(uid, uidLength);
Serial.println("");
// Make sure this is a Mifare Classic card
if (uidLength != 4) {
Serial.println("Ooops ... this doesn't seem to be a Mifare Classic card!");
return;
}
// We probably have a Mifare Classic card ...
Serial.println("Seems to be a Mifare Classic card (4 byte UID)");
// Try to format the card for NDEF data
success = nfc->mifareclassic_AuthenticateBlock (uid, uidLength, 0, 0, keya);
if (!success) {
Serial.println("Unable to authenticate block 0 to enable card formatting!");
return;
}
success = nfc->mifareclassic_FormatNDEF();
if (!success) {
Serial.println("Unable to format the card for NDEF");
return;
}
Serial.println("Card has been formatted for NDEF data using MAD1");
// Try to authenticate block 4 (first block of sector 1) using our key
success = nfc->mifareclassic_AuthenticateBlock (uid, uidLength, 4, 0, keya);
// Make sure the authentification process didn't fail
if (!success) {
Serial.println("Authentication failed.");
return;
}
// Try to write a URL
Serial.println("Writing URI to sector 1 as an NDEF Message");
// Authenticated seems to have worked
// Try to write an NDEF record to sector 1
// Use 0x01 for the URI Identifier Code to prepend "http://www."
// to the url (and save some space). For information on URI ID Codes
// see http://www.ladyada.net/wiki/private/articlestaging/nfc/ndef
if (strlen(url) > 38) {
// The length is also checked in the WriteNDEFURI function, but lets
// warn users here just in case they change the value and it's bigger
// than it should be
Serial.println("URI is too long ... must be less than 38 characters long");
return;
}
// URI is within size limits ... write it to the card and report success/failure
success = nfc->mifareclassic_WriteNDEFURI(1, ndefprefix, url);
if (success) {
Serial.println("NDEF URI Record written to sector 1");
} else {
Serial.println("NDEF Record creation failed! :(");
}
}
// Wait a bit before trying again
Serial.println("\n\nDone!");
delay(1000);
Serial.flush();
while (Serial.available()) Serial.read();
}

View File

@@ -0,0 +1,17 @@
// => Hardware select
#define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line
// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line
// #define LILYGO_WATCH_BLOCK // To use T-Watch Block , please uncomment this line
//NOT SUPPORT ...
// //#define LILYGO_WATCH_2020_V1
//NOT SUPPORT ...
// => Function select
#define LILYGO_WATCH_HAS_NFC
#include <LilyGoWatch.h>

View File

@@ -0,0 +1,164 @@
/**************************************************************************/
/*!
@file mifareclassic_memdump.ino
@author Adafruit Industries
@license BSD (see license.txt)
This example attempts to dump the contents of a Mifare Classic 1K card
Note that you need the baud rate to be 115200 because we need to print
out the data and read from the card at the same time!
This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
This library works with the Adafruit NFC breakout
----> https://www.adafruit.com/products/364
Check out the links above for our tutorials and wiring diagrams
These chips use SPI or I2C to communicate
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
*/
/**************************************************************************/
#include "config.h"
TTGOClass *ttgo;
Adafruit_PN532 *nfc;
void setup(void)
{
Serial.begin(115200);
while (!Serial) delay(10); // for Leonardo/Micro/Zero
Serial.println("Looking for PN532...");
ttgo = TTGOClass::getWatch();
ttgo->begin();
#ifdef LILYGO_WATCH_2019_WITH_TOUCH
ttgo->openBL();
ttgo->tft->println("mifareclassic_memdump example!");
ttgo->tft->println("All messages will be output to the serial port, please open the terminal to view ");
#endif
ttgo->enableLDO3();
ttgo->nfc_begin();
nfc = ttgo->nfc;
uint32_t versiondata = nfc->getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
// Got ok data, print it out!
Serial.print("Found chip PN5"); Serial.println((versiondata >> 24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata >> 16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata >> 8) & 0xFF, DEC);
// configure board to read RFID tags
nfc->SAMConfig();
Serial.println("Waiting for an ISO14443A Card ...");
}
void loop(void)
{
uint8_t success; // Flag to check if there was an error with the PN532
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
uint8_t currentblock; // Counter to keep track of which block we're on
bool authenticated = false; // Flag to indicate if the sector is authenticated
uint8_t data[16]; // Array to store block data during reads
// Keyb on NDEF and Mifare Classic should be the same
uint8_t keyuniversal[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
// Wait for an ISO14443A type cards (Mifare, etc.). When one is found
// 'uid' will be populated with the UID, and uidLength will indicate
// if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
success = nfc->readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
if (success) {
// Display some basic information about the card
Serial.println("Found an ISO14443A card");
Serial.print(" UID Length: "); Serial.print(uidLength, DEC); Serial.println(" bytes");
Serial.print(" UID Value: ");
nfc->PrintHex(uid, uidLength);
Serial.println("");
if (uidLength == 4) {
// We probably have a Mifare Classic card ...
Serial.println("Seems to be a Mifare Classic card (4 byte UID)");
// Now we try to go through all 16 sectors (each having 4 blocks)
// authenticating each sector, and then dumping the blocks
for (currentblock = 0; currentblock < 64; currentblock++) {
// Check if this is a new block so that we can reauthenticate
if (nfc->mifareclassic_IsFirstBlock(currentblock)) authenticated = false;
// If the sector hasn't been authenticated, do so first
if (!authenticated) {
// Starting of a new sector ... try to to authenticate
Serial.print("------------------------Sector "); Serial.print(currentblock / 4, DEC); Serial.println("-------------------------");
if (currentblock == 0) {
// This will be 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF for Mifare Classic (non-NDEF!)
// or 0xA0 0xA1 0xA2 0xA3 0xA4 0xA5 for NDEF formatted cards using key a,
// but keyb should be the same for both (0xFF 0xFF 0xFF 0xFF 0xFF 0xFF)
success = nfc->mifareclassic_AuthenticateBlock (uid, uidLength, currentblock, 1, keyuniversal);
} else {
// This will be 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF for Mifare Classic (non-NDEF!)
// or 0xD3 0xF7 0xD3 0xF7 0xD3 0xF7 for NDEF formatted cards using key a,
// but keyb should be the same for both (0xFF 0xFF 0xFF 0xFF 0xFF 0xFF)
success = nfc->mifareclassic_AuthenticateBlock (uid, uidLength, currentblock, 1, keyuniversal);
}
if (success) {
authenticated = true;
} else {
Serial.println("Authentication error");
}
}
// If we're still not authenticated just skip the block
if (!authenticated) {
Serial.print("Block "); Serial.print(currentblock, DEC); Serial.println(" unable to authenticate");
} else {
// Authenticated ... we should be able to read the block now
// Dump the data into the 'data' array
success = nfc->mifareclassic_ReadDataBlock(currentblock, data);
if (success) {
// Read successful
Serial.print("Block "); Serial.print(currentblock, DEC);
if (currentblock < 10) {
Serial.print(" ");
} else {
Serial.print(" ");
}
// Dump the raw data
nfc->PrintHexChar(data, 16);
} else {
// Oops ... something happened
Serial.print("Block "); Serial.print(currentblock, DEC);
Serial.println(" unable to read this block");
}
}
}
} else {
Serial.println("Ooops ... this doesn't seem to be a Mifare Classic card!");
}
}
// Wait a bit before trying again
Serial.println("\n\nSend a character to run the mem dumper again!");
Serial.flush();
while (!Serial.available());
while (Serial.available()) {
Serial.read();
}
Serial.flush();
}

View File

@@ -0,0 +1,17 @@
// => Hardware select
#define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line
// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line
// #define LILYGO_WATCH_BLOCK // To use T-Watch Block , please uncomment this line
//NOT SUPPORT ...
// //#define LILYGO_WATCH_2020_V1
//NOT SUPPORT ...
// => Function select
#define LILYGO_WATCH_HAS_NFC
#include <LilyGoWatch.h>

View File

@@ -0,0 +1,192 @@
/**************************************************************************/
/*!
@file mifareclassic_ndeftoclassic.ino
@author KTOWN (Adafruit Industries)
@license BSD (see license.txt)
This examples attempts to take a Mifare Classic 1K card that has been
formatted for NDEF messages using mifareclassic_formatndef, and resets
the authentication keys back to the Mifare Classic defaults
This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
This library works with the Adafruit NFC Shield
----> https://www.adafruit.com/products/789
Check out the links above for our tutorials and wiring diagrams
These chips use SPI or I2C to communicate
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
*/
/**************************************************************************/
#include "config.h"
TTGOClass *ttgo;
Adafruit_PN532 *nfc;
#define NR_SHORTSECTOR (32) // Number of short sectors on Mifare 1K/4K
#define NR_LONGSECTOR (8) // Number of long sectors on Mifare 4K
#define NR_BLOCK_OF_SHORTSECTOR (4) // Number of blocks in a short sector
#define NR_BLOCK_OF_LONGSECTOR (16) // Number of blocks in a long sector
// Determine the sector trailer block based on sector number
#define BLOCK_NUMBER_OF_SECTOR_TRAILER(sector) (((sector)<NR_SHORTSECTOR)? \
((sector)*NR_BLOCK_OF_SHORTSECTOR + NR_BLOCK_OF_SHORTSECTOR-1):\
(NR_SHORTSECTOR*NR_BLOCK_OF_SHORTSECTOR + (sector-NR_SHORTSECTOR)*NR_BLOCK_OF_LONGSECTOR + NR_BLOCK_OF_LONGSECTOR-1))
// Determine the sector's first block based on the sector number
#define BLOCK_NUMBER_OF_SECTOR_1ST_BLOCK(sector) (((sector)<NR_SHORTSECTOR)? \
((sector)*NR_BLOCK_OF_SHORTSECTOR):\
(NR_SHORTSECTOR*NR_BLOCK_OF_SHORTSECTOR + (sector-NR_SHORTSECTOR)*NR_BLOCK_OF_LONGSECTOR))
// The default Mifare Classic key
static const uint8_t KEY_DEFAULT_KEYAB[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
void setup(void)
{
Serial.begin(115200);
while (!Serial) delay(10); // for Leonardo/Micro/Zero
Serial.println("Looking for PN532...");
ttgo = TTGOClass::getWatch();
ttgo->begin();
#ifdef LILYGO_WATCH_2019_WITH_TOUCH
ttgo->openBL();
ttgo->tft->println("mifareclassic_ndeftoclassic example!");
ttgo->tft->println("All messages will be output to the serial port, please open the terminal to view ");
#endif
ttgo->enableLDO3();
ttgo->nfc_begin();
nfc = ttgo->nfc;
uint32_t versiondata = nfc->getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
// Got ok data, print it out!
Serial.print("Found chip PN5"); Serial.println((versiondata >> 24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata >> 16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata >> 8) & 0xFF, DEC);
// configure board to read RFID tags
nfc->SAMConfig();
}
void loop(void)
{
uint8_t success; // Flag to check if there was an error with the PN532
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
bool authenticated = false; // Flag to indicate if the sector is authenticated
uint8_t blockBuffer[16]; // Buffer to store block contents
uint8_t blankAccessBits[3] = { 0xff, 0x07, 0x80 };
uint8_t idx = 0;
uint8_t numOfSector = 16; // Assume Mifare Classic 1K for now (16 4-block sectors)
Serial.println("Place your NDEF formatted Mifare Classic 1K card on the reader");
Serial.println("and press any key to continue ...");
// Wait for user input before proceeding
while (!Serial.available());
while (Serial.available()) Serial.read();
// Wait for an ISO14443A type card (Mifare, etc.). When one is found
// 'uid' will be populated with the UID, and uidLength will indicate
// if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
success = nfc->readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
if (success) {
// We seem to have a tag ...
// Display some basic information about it
Serial.println("Found an ISO14443A card/tag");
Serial.print(" UID Length: "); Serial.print(uidLength, DEC); Serial.println(" bytes");
Serial.print(" UID Value: ");
nfc->PrintHex(uid, uidLength);
Serial.println("");
// Make sure this is a Mifare Classic card
if (uidLength != 4) {
Serial.println("Ooops ... this doesn't seem to be a Mifare Classic card!");
return;
}
Serial.println("Seems to be a Mifare Classic card (4 byte UID)");
Serial.println("");
Serial.println("Reformatting card for Mifare Classic (please don't touch it!) ... ");
// Now run through the card sector by sector
for (idx = 0; idx < numOfSector; idx++) {
// Step 1: Authenticate the current sector using key B 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
success = nfc->mifareclassic_AuthenticateBlock (uid, uidLength, BLOCK_NUMBER_OF_SECTOR_TRAILER(idx), 1, (uint8_t *)KEY_DEFAULT_KEYAB);
if (!success) {
Serial.print("Authentication failed for sector "); Serial.println(numOfSector);
return;
}
// Step 2: Write to the other blocks
if (idx == 16) {
memset(blockBuffer, 0, sizeof(blockBuffer));
if (!(nfc->mifareclassic_WriteDataBlock((BLOCK_NUMBER_OF_SECTOR_TRAILER(idx)) - 3, blockBuffer))) {
Serial.print("Unable to write to sector "); Serial.println(numOfSector);
return;
}
}
if ((idx == 0) || (idx == 16)) {
memset(blockBuffer, 0, sizeof(blockBuffer));
if (!(nfc->mifareclassic_WriteDataBlock((BLOCK_NUMBER_OF_SECTOR_TRAILER(idx)) - 2, blockBuffer))) {
Serial.print("Unable to write to sector "); Serial.println(numOfSector);
return;
}
} else {
memset(blockBuffer, 0, sizeof(blockBuffer));
if (!(nfc->mifareclassic_WriteDataBlock((BLOCK_NUMBER_OF_SECTOR_TRAILER(idx)) - 3, blockBuffer))) {
Serial.print("Unable to write to sector "); Serial.println(numOfSector);
return;
}
if (!(nfc->mifareclassic_WriteDataBlock((BLOCK_NUMBER_OF_SECTOR_TRAILER(idx)) - 2, blockBuffer))) {
Serial.print("Unable to write to sector "); Serial.println(numOfSector);
return;
}
}
memset(blockBuffer, 0, sizeof(blockBuffer));
if (!(nfc->mifareclassic_WriteDataBlock((BLOCK_NUMBER_OF_SECTOR_TRAILER(idx)) - 1, blockBuffer))) {
Serial.print("Unable to write to sector "); Serial.println(numOfSector);
return;
}
// Step 3: Reset both keys to 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
memcpy(blockBuffer, KEY_DEFAULT_KEYAB, sizeof(KEY_DEFAULT_KEYAB));
memcpy(blockBuffer + 6, blankAccessBits, sizeof(blankAccessBits));
blockBuffer[9] = 0x69;
memcpy(blockBuffer + 10, KEY_DEFAULT_KEYAB, sizeof(KEY_DEFAULT_KEYAB));
// Step 4: Write the trailer block
if (!(nfc->mifareclassic_WriteDataBlock((BLOCK_NUMBER_OF_SECTOR_TRAILER(idx)), blockBuffer))) {
Serial.print("Unable to write trailer block of sector "); Serial.println(numOfSector);
return;
}
}
}
// Wait a bit before trying again
Serial.println("\n\nDone!");
delay(1000);
Serial.flush();
while (Serial.available()) Serial.read();
}

View File

@@ -0,0 +1,17 @@
// => Hardware select
#define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line
// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line
// #define LILYGO_WATCH_BLOCK // To use T-Watch Block , please uncomment this line
//NOT SUPPORT ...
// //#define LILYGO_WATCH_2020_V1
//NOT SUPPORT ...
// => Function select
#define LILYGO_WATCH_HAS_NFC
#include <LilyGoWatch.h>

View File

@@ -0,0 +1,172 @@
/**************************************************************************/
/*!
@file mifareclassic_updatendef.ino
@author Adafruit Industries
@license BSD (see license.txt)
Updates a sector that is already formatted for NDEF (using
mifareclassic_formatndef.pde for example), inserting a new url
This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
This library works with the Adafruit NFC Shield
----> https://www.adafruit.com/products/789
Check out the links above for our tutorials and wiring diagrams
These chips use SPI or I2C to communicate
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
*/
/**************************************************************************/
#include "config.h"
TTGOClass *ttgo;
Adafruit_PN532 *nfc;
// Or use this line for a breakout or shield with an I2C connection:
//Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);
/*
We can encode many different kinds of pointers to the card,
from a URL, to an Email address, to a phone number, and many more
check the library header .h file to see the large # of supported
prefixes!
*/
// For a http://www. url:
const char *url = "adafruit.com/blog/";
uint8_t ndefprefix = NDEF_URIPREFIX_HTTP_WWWDOT;
// for an email address
//const char * url = "mail@example.com";
//uint8_t ndefprefix = NDEF_URIPREFIX_MAILTO;
// for a phone number
//const char * url = "+1 212 555 1212";
//uint8_t ndefprefix = NDEF_URIPREFIX_TEL;
void setup(void)
{
Serial.begin(115200);
while (!Serial) delay(10); // for Leonardo/Micro/Zero
Serial.println("Looking for PN532...");
ttgo = TTGOClass::getWatch();
ttgo->begin();
#ifdef LILYGO_WATCH_2019_WITH_TOUCH
ttgo->openBL();
ttgo->tft->println("mifareclassic_updatendef example!");
ttgo->tft->println("All messages will be output to the serial port, please open the terminal to view ");
#endif
ttgo->enableLDO3();
ttgo->nfc_begin();
nfc = ttgo->nfc;
uint32_t versiondata = nfc->getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
// Got ok data, print it out!
Serial.print("Found chip PN5"); Serial.println((versiondata >> 24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata >> 16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata >> 8) & 0xFF, DEC);
// configure board to read RFID tags
nfc->SAMConfig();
}
void loop(void)
{
uint8_t success; // Flag to check if there was an error with the PN532
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
bool authenticated = false; // Flag to indicate if the sector is authenticated
// Use the default NDEF keys (these would have have set by mifareclassic_formatndef.pde!)
uint8_t keya[6] = { 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5 };
uint8_t keyb[6] = { 0xD3, 0xF7, 0xD3, 0xF7, 0xD3, 0xF7 };
Serial.println("Place your NDEF formatted Mifare Classic card on the reader to update the");
Serial.println("NDEF record and press any key to continue ...");
// Wait for user input before proceeding
while (!Serial.available());
// a key was pressed1
while (Serial.available()) Serial.read();
// Wait for an ISO14443A type card (Mifare, etc.). When one is found
// 'uid' will be populated with the UID, and uidLength will indicate
// if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
success = nfc->readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
if (success) {
// Display some basic information about the card
Serial.println("Found an ISO14443A card");
Serial.print(" UID Length: "); Serial.print(uidLength, DEC); Serial.println(" bytes");
Serial.print(" UID Value: ");
nfc->PrintHex(uid, uidLength);
Serial.println("");
// Make sure this is a Mifare Classic card
if (uidLength != 4) {
Serial.println("Ooops ... this doesn't seem to be a Mifare Classic card!");
return;
}
// We probably have a Mifare Classic card ...
Serial.println("Seems to be a Mifare Classic card (4 byte UID)");
// Check if this is an NDEF card (using first block of sector 1 from mifareclassic_formatndef.pde)
// Must authenticate on the first key using 0xD3 0xF7 0xD3 0xF7 0xD3 0xF7
success = nfc->mifareclassic_AuthenticateBlock (uid, uidLength, 4, 0, keyb);
if (!success) {
Serial.println("Unable to authenticate block 4 ... is this card NDEF formatted?");
return;
}
Serial.println("Authentication succeeded (seems to be an NDEF/NFC Forum tag) ...");
// Authenticated seems to have worked
// Try to write an NDEF record to sector 1
// Use 0x01 for the URI Identifier Code to prepend "http://www."
// to the url (and save some space). For information on URI ID Codes
// see http://www.ladyada.net/wiki/private/articlestaging/nfc/ndef
if (strlen(url) > 38) {
// The length is also checked in the WriteNDEFURI function, but lets
// warn users here just in case they change the value and it's bigger
// than it should be
Serial.println("URI is too long ... must be less than 38 characters!");
return;
}
Serial.println("Updating sector 1 with URI as NDEF Message");
// URI is within size limits ... write it to the card and report success/failure
success = nfc->mifareclassic_WriteNDEFURI(1, ndefprefix, url);
if (success) {
Serial.println("NDEF URI Record written to sector 1");
Serial.println("");
} else {
Serial.println("NDEF Record creation failed! :(");
}
}
// Wait a bit before trying again
Serial.println("\n\nDone!");
delay(1000);
Serial.flush();
while (Serial.available()) Serial.read();
}

View File

@@ -0,0 +1,17 @@
// => Hardware select
#define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line
// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line
// #define LILYGO_WATCH_BLOCK // To use T-Watch Block , please uncomment this line
//NOT SUPPORT ...
// //#define LILYGO_WATCH_2020_V1
//NOT SUPPORT ...
// => Function select
#define LILYGO_WATCH_HAS_NFC
#include <LilyGoWatch.h>

View File

@@ -0,0 +1,147 @@
/**************************************************************************/
/*!
@file ntag2xx_erase.ino
@author KTOWN (Adafruit Industries)
@license BSD (see license.txt)
This example will wait for any NTAG203 or NTAG213 card or tag,
and will attempt to erase the user data section of the card (setting
all user bytes to 0x00)
This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
This library works with the Adafruit NFC breakout
----> https://www.adafruit.com/products/364
Check out the links above for our tutorials and wiring diagrams
These chips use SPI or I2C to communicate.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
*/
/**************************************************************************/
#include "config.h"
TTGOClass *ttgo;
Adafruit_PN532 *nfc;
void setup(void)
{
Serial.begin(115200);
while (!Serial) delay(10); // for Leonardo/Micro/Zero
Serial.println("Looking for PN532...");
ttgo = TTGOClass::getWatch();
ttgo->begin();
#ifdef LILYGO_WATCH_2019_WITH_TOUCH
ttgo->openBL();
ttgo->tft->println("ntag2xx_erase example!");
ttgo->tft->println("All messages will be output to the serial port, please open the terminal to view ");
#endif
ttgo->enableLDO3();
ttgo->nfc_begin();
nfc = ttgo->nfc;
uint32_t versiondata = nfc->getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
// Got ok data, print it out!
Serial.print("Found chip PN5"); Serial.println((versiondata >> 24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata >> 16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata >> 8) & 0xFF, DEC);
// configure board to read RFID tags
nfc->SAMConfig();
}
void loop(void)
{
uint8_t success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
// Wait for an NTAG203 card. When one is found 'uid' will be populated with
// the UID, and uidLength will indicate the size of the UUID (normally 7)
success = nfc->readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
if (success) {
// Display some basic information about the card
Serial.println("Found an ISO14443A card");
Serial.print(" UID Length: "); Serial.print(uidLength, DEC); Serial.println(" bytes");
Serial.print(" UID Value: ");
nfc->PrintHex(uid, uidLength);
Serial.println("");
if (uidLength == 7) {
uint8_t data[32];
// We probably have an NTAG2xx card (though it could be Ultralight as well)
Serial.println("Seems to be an NTAG2xx tag (7 byte UID)");
// NTAG2x3 cards have 39*4 bytes of user pages (156 user bytes),
// starting at page 4 ... larger cards just add pages to the end of
// this range:
// See: http://www.nxp.com/documents/short_data_sheet/NTAG203_SDS.pdf
// TAG Type PAGES USER START USER STOP
// -------- ----- ---------- ---------
// NTAG 203 42 4 39
// NTAG 213 45 4 39
// NTAG 215 135 4 129
// NTAG 216 231 4 225
Serial.println("");
Serial.println("Writing 0x00 0x00 0x00 0x00 to pages 4..39");
Serial.println("");
for (uint8_t i = 4; i < 39; i++) {
memset(data, 0, 4);
success = nfc->ntag2xx_WritePage(i, data);
// Display the current page number
Serial.print("Page ");
if (i < 10) {
Serial.print("0");
Serial.print(i);
} else {
Serial.print(i);
}
Serial.print(": ");
// Display the results, depending on 'success'
if (success) {
Serial.println("Erased");
} else {
Serial.println("Unable to write to the requested page!");
}
}
} else {
Serial.println("This doesn't seem to be an NTAG203 tag (UUID length != 7 bytes)!");
}
// Wait a bit before trying again
Serial.println("\n\nSend a character to scan another tag!");
Serial.flush();
while (!Serial.available());
while (Serial.available()) {
Serial.read();
}
Serial.flush();
}
}

View File

@@ -0,0 +1,17 @@
// => Hardware select
#define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line
// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line
// #define LILYGO_WATCH_BLOCK // To use T-Watch Block , please uncomment this line
//NOT SUPPORT ...
// //#define LILYGO_WATCH_2020_V1
//NOT SUPPORT ...
// => Function select
#define LILYGO_WATCH_HAS_NFC
#include <LilyGoWatch.h>

View File

@@ -0,0 +1,141 @@
/**************************************************************************/
/*!
@file ntag2xx_read.ino
@author KTOWN (Adafruit Industries)
@license BSD (see license.txt)
This example will wait for any NTAG203 or NTAG213 card or tag,
and will attempt to read from it.
This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
This library works with the Adafruit NFC breakout
----> https://www.adafruit.com/products/364
Check out the links above for our tutorials and wiring diagrams
These chips use SPI or I2C to communicate.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
*/
/**************************************************************************/
#include "config.h"
TTGOClass *ttgo;
Adafruit_PN532 *nfc;
void setup(void)
{
Serial.begin(115200);
while (!Serial) delay(10); // for Leonardo/Micro/Zero
Serial.println("Looking for PN532...");
ttgo = TTGOClass::getWatch();
ttgo->begin();
#ifdef LILYGO_WATCH_2019_WITH_TOUCH
ttgo->openBL();
ttgo->tft->println("ntag2xx_read example!");
ttgo->tft->println("All messages will be output to the serial port, please open the terminal to view ");
#endif
ttgo->enableLDO3();
ttgo->nfc_begin();
nfc = ttgo->nfc;
uint32_t versiondata = nfc->getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
// Got ok data, print it out!
Serial.print("Found chip PN5"); Serial.println((versiondata >> 24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata >> 16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata >> 8) & 0xFF, DEC);
// configure board to read RFID tags
nfc->SAMConfig();
}
void loop(void)
{
uint8_t success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
// Wait for an NTAG203 card. When one is found 'uid' will be populated with
// the UID, and uidLength will indicate the size of the UUID (normally 7)
success = nfc->readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
if (success) {
// Display some basic information about the card
Serial.println("Found an ISO14443A card");
Serial.print(" UID Length: "); Serial.print(uidLength, DEC); Serial.println(" bytes");
Serial.print(" UID Value: ");
nfc->PrintHex(uid, uidLength);
Serial.println("");
if (uidLength == 7) {
uint8_t data[32];
// We probably have an NTAG2xx card (though it could be Ultralight as well)
Serial.println("Seems to be an NTAG2xx tag (7 byte UID)");
// NTAG2x3 cards have 39*4 bytes of user pages (156 user bytes),
// starting at page 4 ... larger cards just add pages to the end of
// this range:
// See: http://www.nxp.com/documents/short_data_sheet/NTAG203_SDS.pdf
// TAG Type PAGES USER START USER STOP
// -------- ----- ---------- ---------
// NTAG 203 42 4 39
// NTAG 213 45 4 39
// NTAG 215 135 4 129
// NTAG 216 231 4 225
for (uint8_t i = 0; i < 42; i++) {
success = nfc->ntag2xx_ReadPage(i, data);
// Display the current page number
Serial.print("PAGE ");
if (i < 10) {
Serial.print("0");
Serial.print(i);
} else {
Serial.print(i);
}
Serial.print(": ");
// Display the results, depending on 'success'
if (success) {
// Dump the page data
nfc->PrintHexChar(data, 4);
} else {
Serial.println("Unable to read the requested page!");
}
}
} else {
Serial.println("This doesn't seem to be an NTAG203 tag (UUID length != 7 bytes)!");
}
// Wait a bit before trying again
Serial.println("\n\nSend a character to scan another tag!");
Serial.flush();
while (!Serial.available());
while (Serial.available()) {
Serial.read();
}
Serial.flush();
}
}

View File

@@ -0,0 +1,17 @@
// => Hardware select
#define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line
// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line
// #define LILYGO_WATCH_BLOCK // To use T-Watch Block , please uncomment this line
//NOT SUPPORT ...
// //#define LILYGO_WATCH_2020_V1
//NOT SUPPORT ...
// => Function select
#define LILYGO_WATCH_HAS_NFC
#include <LilyGoWatch.h>

View File

@@ -0,0 +1,197 @@
/**************************************************************************/
/*!
@file ntag2xx_updatendef.ino
@author KTOWN (Adafruit Industries)
@license BSD (see license.txt)
This example will wait for any NTAG203 or NTAG213 card or tag,
and will attempt to add or update an NDEF URI at the start of the
tag's memory.
This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
This library works with the Adafruit NFC breakout
----> https://www.adafruit.com/products/364
Check out the links above for our tutorials and wiring diagrams
These chips use SPI or I2C to communicate.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
*/
/**************************************************************************/
#include "config.h"
TTGOClass *ttgo;
Adafruit_PN532 *nfc;
/*
We can encode many different kinds of pointers to the card,
from a URL, to an Email address, to a phone number, and many more
check the library header .h file to see the large # of supported
prefixes!
*/
// For a http://www. url:
char *url = "adafruit.com/blog/";
uint8_t ndefprefix = NDEF_URIPREFIX_HTTP_WWWDOT;
// for an email address
//char * url = "mail@example.com";
//uint8_t ndefprefix = NDEF_URIPREFIX_MAILTO;
// for a phone number
//char * url = "+1 212 555 1212";
//uint8_t ndefprefix = NDEF_URIPREFIX_TEL;
void setup(void)
{
Serial.begin(115200);
while (!Serial) delay(10); // for Leonardo/Micro/Zero
Serial.println("Looking for PN532...");
ttgo = TTGOClass::getWatch();
ttgo->begin();
#ifdef LILYGO_WATCH_2019_WITH_TOUCH
ttgo->openBL();
ttgo->tft->println("ntag2xx_updatendef example!");
ttgo->tft->println("All messages will be output to the serial port, please open the terminal to view ");
#endif
ttgo->enableLDO3();
ttgo->nfc_begin();
nfc = ttgo->nfc;
uint32_t versiondata = nfc->getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
// Got ok data, print it out!
Serial.print("Found chip PN5"); Serial.println((versiondata >> 24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata >> 16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata >> 8) & 0xFF, DEC);
// configure board to read RFID tags
nfc->SAMConfig();
}
void loop(void)
{
uint8_t success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
uint8_t dataLength;
// Require some user feedback before running this example!
Serial.println("\r\nPlace your NDEF formatted NTAG2xx tag on the reader to update the");
Serial.println("NDEF record and press any key to continue ...\r\n");
// Wait for user input before proceeding
while (!Serial.available());
// a key was pressed1
while (Serial.available()) Serial.read();
// 1.) Wait for an NTAG203 card. When one is found 'uid' will be populated with
// the UID, and uidLength will indicate the size of the UID (normally 7)
success = nfc->readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
// It seems we found a valid ISO14443A Tag!
if (success) {
// 2.) Display some basic information about the card
Serial.println("Found an ISO14443A card");
Serial.print(" UID Length: "); Serial.print(uidLength, DEC); Serial.println(" bytes");
Serial.print(" UID Value: ");
nfc->PrintHex(uid, uidLength);
Serial.println("");
if (uidLength != 7) {
Serial.println("This doesn't seem to be an NTAG203 tag (UUID length != 7 bytes)!");
} else {
uint8_t data[32];
// We probably have an NTAG2xx card (though it could be Ultralight as well)
Serial.println("Seems to be an NTAG2xx tag (7 byte UID)");
// NTAG2x3 cards have 39*4 bytes of user pages (156 user bytes),
// starting at page 4 ... larger cards just add pages to the end of
// this range:
// See: http://www.nxp.com/documents/short_data_sheet/NTAG203_SDS.pdf
// TAG Type PAGES USER START USER STOP
// -------- ----- ---------- ---------
// NTAG 203 42 4 39
// NTAG 213 45 4 39
// NTAG 215 135 4 129
// NTAG 216 231 4 225
// 3.) Check if the NDEF Capability Container (CC) bits are already set
// in OTP memory (page 3)
memset(data, 0, 4);
success = nfc->ntag2xx_ReadPage(3, data);
if (!success) {
Serial.println("Unable to read the Capability Container (page 3)");
return;
} else {
// If the tag has already been formatted as NDEF, byte 0 should be:
// Byte 0 = Magic Number (0xE1)
// Byte 1 = NDEF Version (Should be 0x10)
// Byte 2 = Data Area Size (value * 8 bytes)
// Byte 3 = Read/Write Access (0x00 for full read and write)
if (!((data[0] == 0xE1) && (data[1] == 0x10))) {
Serial.println("This doesn't seem to be an NDEF formatted tag.");
Serial.println("Page 3 should start with 0xE1 0x10.");
} else {
// 4.) Determine and display the data area size
dataLength = data[2] * 8;
Serial.print("Tag is NDEF formatted. Data area size = ");
Serial.print(dataLength);
Serial.println(" bytes");
// 5.) Erase the old data area
Serial.print("Erasing previous data area ");
for (uint8_t i = 4; i < (dataLength / 4) + 4; i++) {
memset(data, 0, 4);
success = nfc->ntag2xx_WritePage(i, data);
Serial.print(".");
if (!success) {
Serial.println(" ERROR!");
return;
}
}
Serial.println(" DONE!");
// 6.) Try to add a new NDEF URI record
Serial.print("Writing URI as NDEF Record ... ");
success = nfc->ntag2xx_WriteNDEFURI(ndefprefix, url, dataLength);
if (success) {
Serial.println("DONE!");
} else {
Serial.println("ERROR! (URI length?)");
}
} // CC contents NDEF record check
} // CC page read check
} // UUID length check
// Wait a bit before trying again
Serial.flush();
while (!Serial.available());
while (Serial.available()) {
Serial.read();
}
Serial.flush();
} // Start waiting for a new ISO14443A tag
}

View File

@@ -0,0 +1,17 @@
// => Hardware select
#define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line
// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line
// #define LILYGO_WATCH_BLOCK // To use T-Watch Block , please uncomment this line
//NOT SUPPORT ...
// //#define LILYGO_WATCH_2020_V1
//NOT SUPPORT ...
// => Function select
#define LILYGO_WATCH_HAS_NFC
#include <LilyGoWatch.h>

View File

@@ -0,0 +1,167 @@
/**************************************************************************/
/*!
@file readMifare.ino
@author Adafruit Industries
@license BSD (see license.txt)
This example will wait for any ISO14443A card or tag, and
depending on the size of the UID will attempt to read from it.
If the card has a 4-byte UID it is probably a Mifare
Classic card, and the following steps are taken:
- Authenticate block 4 (the first block of Sector 1) using
the default KEYA of 0XFF 0XFF 0XFF 0XFF 0XFF 0XFF
- If authentication succeeds, we can then read any of the
4 blocks in that sector (though only block 4 is read here)
If the card has a 7-byte UID it is probably a Mifare
Ultralight card, and the 4 byte pages can be read directly.
Page 4 is read by default since this is the first 'general-
purpose' page on the tags.
This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
This library works with the Adafruit NFC breakout
----> https://www.adafruit.com/products/364
Check out the links above for our tutorials and wiring diagrams
These chips use SPI or I2C to communicate.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
*/
/**************************************************************************/
#include "config.h"
TTGOClass *ttgo;
Adafruit_PN532 *nfc;
void setup(void)
{
Serial.begin(115200);
while (!Serial) delay(10); // for Leonardo/Micro/Zero
Serial.println("Looking for PN532...");
ttgo = TTGOClass::getWatch();
ttgo->begin();
#ifdef LILYGO_WATCH_2019_WITH_TOUCH
ttgo->openBL();
ttgo->tft->println("readMifare example!");
ttgo->tft->println("All messages will be output to the serial port, please open the terminal to view ");
#endif
ttgo->enableLDO3();
ttgo->nfc_begin();
nfc = ttgo->nfc;
uint32_t versiondata = nfc->getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
// Got ok data, print it out!
Serial.print("Found chip PN5"); Serial.println((versiondata >> 24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata >> 16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata >> 8) & 0xFF, DEC);
// configure board to read RFID tags
nfc->SAMConfig();
}
void loop(void)
{
uint8_t success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
// Wait for an ISO14443A type cards (Mifare, etc.). When one is found
// 'uid' will be populated with the UID, and uidLength will indicate
// if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
success = nfc->readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
if (success) {
// Display some basic information about the card
Serial.println("Found an ISO14443A card");
Serial.print(" UID Length: "); Serial.print(uidLength, DEC); Serial.println(" bytes");
Serial.print(" UID Value: ");
nfc->PrintHex(uid, uidLength);
Serial.println("");
if (uidLength == 4) {
// We probably have a Mifare Classic card ...
Serial.println("Seems to be a Mifare Classic card (4 byte UID)");
// Now we need to try to authenticate it for read/write access
// Try with the factory default KeyA: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
Serial.println("Trying to authenticate block 4 with default KEYA value");
uint8_t keya[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
// Start with block 4 (the first block of sector 1) since sector 0
// contains the manufacturer data and it's probably better just
// to leave it alone unless you know what you're doing
success = nfc->mifareclassic_AuthenticateBlock(uid, uidLength, 4, 0, keya);
if (success) {
Serial.println("Sector 1 (Blocks 4..7) has been authenticated");
uint8_t data[16];
// If you want to write something to block 4 to test with, uncomment
// the following line and this text should be read back in a minute
//memcpy(data, (const uint8_t[]){ 'a', 'd', 'a', 'f', 'r', 'u', 'i', 't', '.', 'c', 'o', 'm', 0, 0, 0, 0 }, sizeof data);
// success = nfc->mifareclassic_WriteDataBlock (4, data);
// Try to read the contents of block 4
success = nfc->mifareclassic_ReadDataBlock(4, data);
if (success) {
// Data seems to have been read ... spit it out
Serial.println("Reading Block 4:");
nfc->PrintHexChar(data, 16);
Serial.println("");
// Wait a bit before reading the card again
delay(1000);
} else {
Serial.println("Ooops ... unable to read the requested block. Try another key?");
}
} else {
Serial.println("Ooops ... authentication failed: Try another key?");
}
}
if (uidLength == 7) {
// We probably have a Mifare Ultralight card ...
Serial.println("Seems to be a Mifare Ultralight tag (7 byte UID)");
// Try to read the first general-purpose user page (#4)
Serial.println("Reading page 4");
uint8_t data[32];
success = nfc->mifareultralight_ReadPage (4, data);
if (success) {
// Data seems to have been read ... spit it out
nfc->PrintHexChar(data, 4);
Serial.println("");
// Wait a bit before reading the card again
delay(1000);
} else {
Serial.println("Ooops ... unable to read the requested page!?");
}
}
}
}

View File

@@ -0,0 +1,17 @@
// => Hardware select
#define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line
// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line
// #define LILYGO_WATCH_BLOCK // To use T-Watch Block , please uncomment this line
//NOT SUPPORT ...
// //#define LILYGO_WATCH_2020_V1
//NOT SUPPORT ...
// => Function select
#define LILYGO_WATCH_HAS_NFC
#include <LilyGoWatch.h>

View File

@@ -0,0 +1,114 @@
/**************************************************************************/
/*!
@file readMifareClassic.ino
@author Adafruit Industries
@license BSD (see license.txt)
This example will wait for any ISO14443A card or tag, and
depending on the size of the UID will attempt to read from it.
If the card has a 4-byte UID it is probably a Mifare
Classic card, and the following steps are taken:
Reads the 4 byte (32 bit) ID of a MiFare Classic card.
Since the classic cards have only 32 bit identifiers you can stick
them in a single variable and use that to compare card ID's as a
number. This doesn't work for ultralight cards that have longer 7
byte IDs!
Note that you need the baud rate to be 115200 because we need to
print out the data and read from the card at the same time!
This is an example sketch for the Adafruit PN532 NFC/RFID breakout boards
This library works with the Adafruit NFC breakout
----> https://www.adafruit.com/products/364
Check out the links above for our tutorials and wiring diagrams
These chips use SPI to communicate, 4 required to interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
*/
/**************************************************************************/
#include "config.h"
TTGOClass *ttgo;
Adafruit_PN532 *nfc;
void setup(void)
{
Serial.begin(115200);
while (!Serial) delay(10); // for Leonardo/Micro/Zero
Serial.println("Looking for PN532...");
ttgo = TTGOClass::getWatch();
ttgo->begin();
#ifdef LILYGO_WATCH_2019_WITH_TOUCH
ttgo->openBL();
ttgo->tft->println("readMifareClassic example!");
ttgo->tft->println("All messages will be output to the serial port, please open the terminal to view ");
#endif
ttgo->enableLDO3();
ttgo->nfc_begin();
nfc = ttgo->nfc;
uint32_t versiondata = nfc->getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");
while (1); // halt
}
// Got ok data, print it out!
Serial.print("Found chip PN5"); Serial.println((versiondata >> 24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata >> 16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata >> 8) & 0xFF, DEC);
// configure board to read RFID tags
nfc->SAMConfig();
}
void loop(void)
{
uint8_t success;
uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
// Wait for an ISO14443A type cards (Mifare, etc.). When one is found
// 'uid' will be populated with the UID, and uidLength will indicate
// if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
success = nfc->readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
if (success) {
// Display some basic information about the card
Serial.println("Found an ISO14443A card");
Serial.print(" UID Length: "); Serial.print(uidLength, DEC); Serial.println(" bytes");
Serial.print(" UID Value: ");
nfc->PrintHex(uid, uidLength);
if (uidLength == 4) {
// We probably have a Mifare Classic card ...
uint32_t cardid = uid[0];
cardid <<= 8;
cardid |= uid[1];
cardid <<= 8;
cardid |= uid[2];
cardid <<= 8;
cardid |= uid[3];
Serial.print("Seems to be a Mifare Classic card #");
Serial.println(cardid);
}
Serial.println("");
}
}

View File

@@ -0,0 +1,40 @@
#include "config.h"
TTGOClass *ttgo;
TFT_eSPI *tft ;
#define S7XGPort Serial1
void setup(void)
{
Serial.begin(115200);
ttgo = TTGOClass::getWatch();
ttgo->begin();
ttgo->openBL();
//! Create a new pointer to save the display object
tft = ttgo->tft;
tft->setTextFont(2);
tft->println(" S7XG Debug Test");
ttgo->enableLDO4(); //S7XG GPS VDD
ttgo->enableLDO3(); //S7XG VDD
S7XGPort.begin(115200, SERIAL_8N1, GPS_RX, GPS_TX);
}
// Command datasheet: https://github.com/Xinyuan-LilyGO/LilyGo-HAL/tree/master/ACSIP_S7678G
void loop(void)
{
while (S7XGPort.available()) {
Serial.write(S7XGPort.read());
}
while (Serial.available()) {
S7XGPort.write(Serial.read());
}
}

View File

@@ -0,0 +1,17 @@
// => Hardware select
#define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line
// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line
// #define LILYGO_WATCH_BLOCK // To use T-Watch Block , please uncomment this line
//NOT SUPPORT ...
// //#define LILYGO_WATCH_2020_V1
//NOT SUPPORT ...
// => Function select
#define LILYGO_WATCH_HAS_S76_S78G
#include <LilyGoWatch.h>

View File

@@ -1,3 +1,4 @@
// Old time example, not recommended
#include "config.h"
TTGOClass *ttgo;

View File

@@ -1,3 +1,4 @@
// Old time example, not recommended
#include "config.h"
TTGOClass *ttgo;

View File

@@ -0,0 +1,17 @@
// => Hardware select
#define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line
// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line
// #define LILYGO_WATCH_BLOCK // To use T-Watch Block , please uncomment this line
//NOT SUPPORT ...
// //#define LILYGO_WATCH_2020_V1
//NOT SUPPORT ...
// => Function select
#define LILYGO_WATCH_HAS_S76_S78G
#include <LilyGoWatch.h>

View File

@@ -0,0 +1,315 @@
#pragma mark - Depend Acsip-S7xG-Library
/*
cd ~/Arduino/libraries
git clone https://github.com/lewisxhe/Acsip-S7xG-Library.git
*/
// Example source: https://github.com/lewisxhe/Acsip-S7xG-Library
#include "config.h"
#include <acsip.h>
#include "acsiplogo.h"
TTGOClass *watch = nullptr;
TFT_eSPI *tft;
HardwareSerial *hwSerial = nullptr;
Acsip s76g;
struct GPSDataStruct data;
uint32_t utimerStart = 0;
#define CHECK_ERROR(ret) do{ \
if(ret != S7XG_OK){ \
Serial.printf("%d failed\n", __LINE__); \
while (1); \
} \
}while(0)
int ret = 0;
void showResult(bool r)
{
tft->print(" [");
tft->setTextColor(r ? TFT_GREEN : TFT_RED);
tft->print(r ? "OK" : "FAIL");
tft->setTextColor(TFT_WHITE);
tft->println("]");
}
void setupWatch()
{
Serial.begin(115200);
watch = TTGOClass::getWatch();
watch->begin();
tft = watch->tft;
tft->fillScreen(TFT_BLACK);
tft->setTextFont(2);
watch->openBL();
tft->setAddrWindow(30, 25, 168, 77);
tft->pushColors((uint16_t *)acsiplogo, 0x3288);
watch->enableLDO4();
watch->enableLDO3();
hwSerial = new HardwareSerial(1);
hwSerial->begin(115200, SERIAL_8N1, GPS_RX, GPS_TX);
if (!s76g.begin(*hwSerial)) {
tft->setTextColor(TFT_RED);
tft->println("Initialization 'S76/78G' failed");
while (1);
}
tft->setCursor(0, 100);
tft->print("FW version:");
tft->println(s76g.getVersion());
tft->print("Hardware:");
tft->println(s76g.getHardWareVer());
tft->print("UUID:");
tft->println(s76g.getUUID());
uint32_t r1, r2;
tft->print("ADC resistor: ");
ret = s76g.getBatteryResistor(r1, r2);
tft->print("R1:");
tft->print(r1);
tft->print(" ");
tft->print("R2:");
tft->print(r2);
showResult(ret == S7XG_OK);
uint16_t volt;
tft->print("ADC Volt: ");
ret = s76g.getBatteryVoltage(volt);
tft->print(volt);
tft->print(" mV");
showResult(ret == S7XG_OK);
tft->print("Set gpio [PB6] OUTPUT");
ret = s76g.setGPIOMode(S7XG_GPIO_GROUP_B, 6, OUTPUT);
if (ret == S7XG_OK) {
showResult(true);
tft->print("Set gpio [PB6] to HIGH");
ret = s76g.setGPIOValue(S7XG_GPIO_GROUP_B, 6, HIGH);
showResult(ret == S7XG_OK);
tft->print("Get gpio [PB6] :");
int val = s76g.getGPIOValue(S7XG_GPIO_GROUP_B, 6);
tft->print(val ? "HIGH" : "LOW");
showResult(ret == S7XG_OK);
}
delay(3000);
}
void gpsBegin()
{
// To reset GPS
ret = s76g.gpsReset();
CHECK_ERROR(ret);
// Representing whether S76G enables the internal level shift IC
ret = s76g.setLevelShift(true);
CHECK_ERROR(ret);
// Representing the way of how S76G/S78G starts to get position
// S7XG_GPS_START_HOT
// S7XG_GPS_START_WARM
// S7XG_GPS_START_COLD
ret = s76g.setStart(S7XG_GPS_START_HOT);
CHECK_ERROR(ret);
//representing S76G/S78G GPS satellite system is set to either
// S7XG_SATELLITE_GPS
// S7XG_SATELLITE_GPS_GLONASS
ret = s76g.setSatelliteSystem(S7XG_SATELLITE_GPS);
CHECK_ERROR(ret);
//Representing the SONY CXD5603GF GPS positioning cycle time,
//it can be 1000 to 600000 milliseconds.
ret = s76g.setPositioningCycle(1000);
CHECK_ERROR(ret);
// Representing S76G/S78G GPS mode is set to either
// S7XG_GPS_MODE_AUTO,
// S7XG_GPS_MODE_MANUAL,
// S7XG_GPS_MODE_IDLE,
ret = s76g.setMode(S7XG_GPS_MODE_MANUAL);
CHECK_ERROR(ret);
GPSModeStruct mode;
ret = s76g.getMode(mode);
CHECK_ERROR(ret);
//To show the TTFF (Time To First Fix) value of the last GPS positioning.
float sec = 0;
ret = s76g.getTtff(sec);
CHECK_ERROR(ret);
Serial.printf("TTFF is %f\n", sec);
}
void setup()
{
setupWatch();
gpsBegin();
}
void loop()
{
if (millis() - utimerStart > 1000) {
//GPS data type, which can be S7XG_GPS_DATA_DMS , S7XG_GPS_DATA_RAW , S7XG_GPS_DATA_DD
GPSDataType type = S7XG_GPS_DATA_RAW;
ret = s76g.getData(data, type);
if (data.isValid) {
tft->fillScreen(TFT_BLACK);
tft->setCursor(0, 0);
switch (type) {
case S7XG_GPS_DATA_DMS:
tft->print("date:");
tft->print(data.dms.datetime.year);
tft->print("/");
tft->print(data.dms.datetime.month);
tft->print("/");
tft->print(data.dms.datetime.day);
tft->print(" ");
tft->print("time:");
tft->print(data.dms.datetime.hour);
tft->print(":");
tft->print(data.dms.datetime.minute);
tft->print(":");
tft->print(data.dms.datetime.second);
tft->println();
tft->print("lat:");
tft->print(data.dms.lat.dd);
tft->print("/");
tft->print(data.dms.lat.mm);
tft->print("/");
tft->print(data.dms.lat.ss);
tft->println();
tft->print("lng:");
tft->print(data.dms.lng.dd);
tft->print("/");
tft->print(data.dms.lng.mm);
tft->print("/");
tft->print(data.dms.lng.ss);
tft->println();
Serial.printf("ret:%d %hu/%hhu/%hhu %hhu:%hhu:%hhu dd:%d mm:%d ss:%lf dd:%d mm:%d ss:%lf [%f]\n",
ret,
data.dms.datetime.year,
data.dms.datetime.month,
data.dms.datetime.day,
data.dms.datetime.hour,
data.dms.datetime.minute,
data.dms.datetime.second,
data.dms.lat.dd, data.dms.lat.mm, data.dms.lat.ss,
data.dms.lng.dd, data.dms.lng.mm, data.dms.lng.ss,
data.second);
break;
case S7XG_GPS_DATA_RAW:
tft->print("date:");
tft->print(data.raw.datetime.year);
tft->print("/");
tft->print(data.raw.datetime.month);
tft->print("/");
tft->print(data.raw.datetime.day);
tft->print(" ");
tft->print("time:");
tft->print(data.raw.datetime.hour);
tft->print(":");
tft->print(data.raw.datetime.minute);
tft->print(":");
tft->print(data.raw.datetime.second);
tft->println();
tft->print("lat:");
tft->print(data.raw.lat);
tft->print("lng:");
tft->print(data.raw.lng);
Serial.printf("ret:%d %u/%hhu/%hhu %hhu:%hhu:%hhu lat:%f lng:%f [%f]\n",
ret,
data.raw.datetime.year,
data.raw.datetime.month,
data.raw.datetime.day,
data.raw.datetime.hour,
data.raw.datetime.minute,
data.raw.datetime.second,
data.raw.lat,
data.raw.lng,
data.second);
break;
case S7XG_GPS_DATA_DD:
tft->print("date:");
tft->print(data.dd.datetime.year);
tft->print("/");
tft->print(data.dd.datetime.month);
tft->print("/");
tft->print(data.dd.datetime.day);
tft->print(" ");
tft->print("time:");
tft->print(data.dd.datetime.hour);
tft->print(":");
tft->print(data.dd.datetime.minute);
tft->print(":");
tft->print(data.dd.datetime.second);
tft->println();
tft->print("lat:");
tft->print(data.dd.lat);
tft->print("lng:");
tft->print(data.dd.lng);
Serial.printf("ret:%d %hu/%hhu/%hhu %hhu:%hhu:%hhu lat:%f lng:%f [%f]\n",
ret,
data.dd.datetime.year,
data.dd.datetime.month,
data.dd.datetime.day,
data.dd.datetime.hour,
data.dd.datetime.minute,
data.dd.datetime.second,
data.dd.lat,
data.dd.lng,
data.second);
break;
default:
break;
}
} else
Serial.println(millis());
utimerStart = millis();
}
}

View File

@@ -0,0 +1,17 @@
// => Hardware select
#define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line
// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line
// #define LILYGO_WATCH_BLOCK // To use T-Watch Block , please uncomment this line
//NOT SUPPORT ...
// //#define LILYGO_WATCH_2020_V1
//NOT SUPPORT ...
// => Function select
#define LILYGO_WATCH_HAS_S76_S78G
#include <LilyGoWatch.h>

View File

@@ -0,0 +1,217 @@
#pragma mark - Depend CayenneLPP and ArduinoJson libraries , Acsip-S7xG-Library
/*
cd ~/Arduino/libraries
git clone https://github.com/ElectronicCats/CayenneLPP.git
git clone https://github.com/bblanchon/ArduinoJson.git
git clone https://github.com/lewisxhe/Acsip-S7xG-Library.git
*/
// Example source: https://github.com/lewisxhe/Acsip-S7xG-Library
#include "config.h"
#include <acsip.h>
#include "acsiplogo.h"
#include <CayenneLPP.h>
#include <ArduinoJson.h>
TTGOClass *watch = nullptr;
TFT_eSPI *tft;
HardwareSerial *hwSerial = nullptr;
Acsip s76g;
CayenneLPP lpp(160);
struct GPSDataStruct data;
uint32_t utimerStart = 0;
#define CHECK_ERROR(ret) do{ \
if(ret != S7XG_OK){ \
Serial.printf("%d failed\n", __LINE__); \
while (1); \
} \
}while(0)
const char *deveui = "your ttn deveui";
const char *appeui = "your ttn appeui";
const char *devadr = "your ttn devaddr";
const char *nwskey = "your ttn network session key";
const char *appskey = "your ttn app session key";
int ret = 0;
void showResult(bool r)
{
tft->print(" [");
tft->setTextColor(r ? TFT_GREEN : TFT_RED);
tft->print(r ? "OK" : "FAIL");
tft->setTextColor(TFT_WHITE);
tft->println("]");
}
void setupWatch()
{
Serial.begin(115200);
watch = TTGOClass::getWatch();
watch->begin();
tft = watch->tft;
tft->fillScreen(TFT_BLACK);
tft->setTextFont(2);
watch->openBL();
tft->setAddrWindow(30, 25, 168, 77);
tft->pushColors((uint16_t *)acsiplogo, 0x3288);
watch->enableLDO4();
watch->enableLDO3();
hwSerial = new HardwareSerial(1);
hwSerial->begin(115200, SERIAL_8N1, GPS_RX, GPS_TX);
if (!s76g.begin(*hwSerial)) {
tft->setTextColor(TFT_RED);
tft->println("Initialization 'S76/78G' failed");
while (1);
}
tft->setCursor(0, 100);
tft->print("FW version:");
tft->println(s76g.getVersion());
tft->print("Hardware:");
tft->println(s76g.getHardWareVer());
tft->print("UUID:");
tft->println(s76g.getUUID());
uint32_t r1, r2;
tft->print("ADC resistor: ");
ret = s76g.getBatteryResistor(r1, r2);
tft->print("R1:");
tft->print(r1);
tft->print(" ");
tft->print("R2:");
tft->print(r2);
showResult(ret == S7XG_OK);
uint16_t volt;
tft->print("ADC Volt: ");
ret = s76g.getBatteryVoltage(volt);
tft->print(volt);
tft->print(" mV");
showResult(ret == S7XG_OK);
tft->print("Set gpio [PB6] OUTPUT");
ret = s76g.setGPIOMode(S7XG_GPIO_GROUP_B, 6, OUTPUT);
if (ret == S7XG_OK) {
showResult(true);
tft->print("Set gpio [PB6] to HIGH");
ret = s76g.setGPIOValue(S7XG_GPIO_GROUP_B, 6, HIGH);
showResult(ret == S7XG_OK);
tft->print("Get gpio [PB6] :");
int val = s76g.getGPIOValue(S7XG_GPIO_GROUP_B, 6);
tft->print(val ? "HIGH" : "LOW");
showResult(ret == S7XG_OK);
}
delay(3000);
}
void lorawanBegin()
{
char cla = s76g.getClass();
Serial.printf("getClass -> %c\n", cla);
//Set Class A
ret = s76g.setClass('A');
CHECK_ERROR(ret);
bool isJoin = s76g.isJoin();
Serial.printf("S76G is %s\n", isJoin ? "joined" : "unjoined");
int pwr = 0;
ret = s76g.getPower(pwr);
CHECK_ERROR(ret);
Serial.printf("S76G power level is %d\n", pwr);
//Set Device Address
ret = s76g.setDevAddr(devadr);
CHECK_ERROR(ret);
//Set Network Session Key
ret = s76g.setNetworkSessionKey(nwskey);
CHECK_ERROR(ret);
//Set App Session Key
ret = s76g.setAppSessionKey(appskey);
CHECK_ERROR(ret);
//Set the corresponding channel frequency
s76g.setChannelFreq(0, 868100000);
s76g.setChannelFreq(1, 868300000);
s76g.setChannelFreq(2, 868500000);
s76g.setChannelFreq(3, 867100000);
s76g.setChannelFreq(4, 867300000);
s76g.setChannelFreq(5, 867500000);
s76g.setChannelFreq(6, 867700000);
s76g.setChannelFreq(7, 867900000);
s76g.setChannelFreq(8, 868800000);
//Connection method using ABP
s76g.joinABP();
//Waiting to connect to TTN
while (1) {
if (s76g.isJoin()) {
break;
}
Serial.println("Wait for join to TTN");
delay(1500);
}
Serial.println();
Serial.println();
Serial.println("Join to TTN");
}
void setup()
{
setupWatch();
lorawanBegin();
}
void loop()
{
if (millis() - utimerStart > 20000) {
//Upload random data
lpp.reset();
lpp.addTemperature(1, rand() % 30);
lpp.addBarometricPressure(2, rand() % 3000);
lpp.addAnalogOutput(3, rand() % 100 + 10);
int uplinkPort = 1;
ret = s76g.send(uplinkPort, lpp.getBuffer(), lpp.getSize());
Serial.printf("Send [%u] Byte\n", lpp.getSize());
if (ret != S7XG_OK) {
hwSerial->flush();
}
utimerStart = millis();
}
}

View File

@@ -0,0 +1,17 @@
// => Hardware select
#define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line
// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line
// #define LILYGO_WATCH_BLOCK // To use T-Watch Block , please uncomment this line
//NOT SUPPORT ...
// //#define LILYGO_WATCH_2020_V1
//NOT SUPPORT ...
// => Function select
#define LILYGO_WATCH_HAS_S76_S78G
#include <LilyGoWatch.h>

View File

@@ -0,0 +1,212 @@
#pragma mark - Depend CayenneLPP and ArduinoJson libraries , Acsip-S7xG-Library
/*
cd ~/Arduino/libraries
git clone https://github.com/ElectronicCats/CayenneLPP.git
git clone https://github.com/bblanchon/ArduinoJson.git
git clone https://github.com/lewisxhe/Acsip-S7xG-Library.git
*/
// Example source: https://github.com/lewisxhe/Acsip-S7xG-Library
#include "config.h"
#include <acsip.h>
#include "acsiplogo.h"
#include <CayenneLPP.h>
#include <ArduinoJson.h>
TTGOClass *watch = nullptr;
TFT_eSPI *tft;
HardwareSerial *hwSerial = nullptr;
Acsip s76g;
CayenneLPP lpp(160);
struct GPSDataStruct data;
uint32_t utimerStart = 0;
#define CHECK_ERROR(ret) do{ \
if(ret != S7XG_OK){ \
Serial.printf("%d failed\n", __LINE__); \
while (1); \
} \
}while(0)
const char *appeui = "your ttn appeui";
const char *deveui = "your ttn deveui";
const char *appkey = "your ttn app key";
int ret = 0;
void showResult(bool r)
{
tft->print(" [");
tft->setTextColor(r ? TFT_GREEN : TFT_RED);
tft->print(r ? "OK" : "FAIL");
tft->setTextColor(TFT_WHITE);
tft->println("]");
}
void setupWatch()
{
Serial.begin(115200);
watch = TTGOClass::getWatch();
watch->begin();
tft = watch->tft;
tft->fillScreen(TFT_BLACK);
tft->setTextFont(2);
watch->openBL();
tft->setAddrWindow(30, 25, 168, 77);
tft->pushColors((uint16_t *)acsiplogo, 0x3288);
watch->enableLDO4();
watch->enableLDO3();
hwSerial = new HardwareSerial(1);
hwSerial->begin(115200, SERIAL_8N1, GPS_RX, GPS_TX);
if (!s76g.begin(*hwSerial)) {
tft->setTextColor(TFT_RED);
tft->println("Initialization 'S76/78G' failed");
while (1);
}
tft->setCursor(0, 100);
tft->print("FW version:");
tft->println(s76g.getVersion());
tft->print("Hardware:");
tft->println(s76g.getHardWareVer());
tft->print("UUID:");
tft->println(s76g.getUUID());
uint32_t r1, r2;
tft->print("ADC resistor: ");
ret = s76g.getBatteryResistor(r1, r2);
tft->print("R1:");
tft->print(r1);
tft->print(" ");
tft->print("R2:");
tft->print(r2);
showResult(ret == S7XG_OK);
uint16_t volt;
tft->print("ADC Volt: ");
ret = s76g.getBatteryVoltage(volt);
tft->print(volt);
tft->print(" mV");
showResult(ret == S7XG_OK);
tft->print("Set gpio [PB6] OUTPUT");
ret = s76g.setGPIOMode(S7XG_GPIO_GROUP_B, 6, OUTPUT);
if (ret == S7XG_OK) {
showResult(true);
tft->print("Set gpio [PB6] to HIGH");
ret = s76g.setGPIOValue(S7XG_GPIO_GROUP_B, 6, HIGH);
showResult(ret == S7XG_OK);
tft->print("Get gpio [PB6] :");
int val = s76g.getGPIOValue(S7XG_GPIO_GROUP_B, 6);
tft->print(val ? "HIGH" : "LOW");
showResult(ret == S7XG_OK);
}
delay(3000);
}
void lorawanBegin()
{
char cla = s76g.getClass();
Serial.printf("getClass -> %c\n", cla);
//Set Class A
ret = s76g.setClass('A');
CHECK_ERROR(ret);
bool isJoin = s76g.isJoin();
Serial.printf("S76G is %s\n", isJoin ? "joined" : "unjoined");
int pwr = 0;
ret = s76g.getPower(pwr);
CHECK_ERROR(ret);
Serial.printf("S76G power level is %d\n", pwr);
//Set AppEUI
ret = s76g.setAppEui(appeui);
CHECK_ERROR(ret);
//Set DevEUI
ret = s76g.setDevEui(deveui);
CHECK_ERROR(ret);
//Set App Key
ret = s76g.setAppKey(appkey);
CHECK_ERROR(ret);
//Set the corresponding channel frequency
s76g.setChannelFreq(0, 868100000);
s76g.setChannelFreq(1, 868300000);
s76g.setChannelFreq(2, 868500000);
s76g.setChannelFreq(3, 867100000);
s76g.setChannelFreq(4, 867300000);
s76g.setChannelFreq(5, 867500000);
s76g.setChannelFreq(6, 867700000);
s76g.setChannelFreq(7, 867900000);
s76g.setChannelFreq(8, 868800000);
//Connection method using OTAA
s76g.joinOTAA();
//Waiting to connect to TTN
while (1) {
if (s76g.isJoin()) {
break;
}
Serial.println("Wait for join to TTN");
delay(1500);
}
Serial.println();
Serial.println();
Serial.println("Join to TTN");
}
void setup()
{
setupWatch();
lorawanBegin();
}
void loop()
{
if (millis() - utimerStart > 20000) {
//Upload random data
lpp.reset();
lpp.addTemperature(1, rand() % 30);
lpp.addBarometricPressure(2, rand() % 3000);
lpp.addAnalogOutput(3, rand() % 100 + 10);
int uplinkPort = 1;
ret = s76g.send(uplinkPort, lpp.getBuffer(), lpp.getSize());
Serial.printf("Send [%u] Byte\n", lpp.getSize());
if (ret != S7XG_OK) {
hwSerial->flush();
}
utimerStart = millis();
}
}

View File

@@ -0,0 +1,17 @@
// => Hardware select
#define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line
// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line
// #define LILYGO_WATCH_BLOCK // To use T-Watch Block , please uncomment this line
//NOT SUPPORT ...
// //#define LILYGO_WATCH_2020_V1
//NOT SUPPORT ...
// => Function select
#define LILYGO_WATCH_HAS_S76_S78G
#include <LilyGoWatch.h>

View File

@@ -0,0 +1,181 @@
#pragma mark - Depend Acsip-S7xG-Library
/*
cd ~/Arduino/libraries
git clone https://github.com/lewisxhe/Acsip-S7xG-Library.git
*/
// Example source: https://github.com/lewisxhe/Acsip-S7xG-Library
#include "config.h"
#include <acsip.h>
#include "acsiplogo.h"
TTGOClass *watch = nullptr;
TFT_eSPI *tft;
HardwareSerial *hwSerial = nullptr;
Acsip s76g;
#define CHECK_ERROR(ret) do{ \
if(ret != S7XG_OK){ \
Serial.printf("%d failed\n", __LINE__); \
while (1); \
} \
}while(0)
int ret = 0;
void showResult(bool r)
{
tft->print(" [");
tft->setTextColor(r ? TFT_GREEN : TFT_RED);
tft->print(r ? "OK" : "FAIL");
tft->setTextColor(TFT_WHITE);
tft->println("]");
}
void setupWatch()
{
Serial.begin(115200);
watch = TTGOClass::getWatch();
watch->begin();
tft = watch->tft;
tft->fillScreen(TFT_BLACK);
tft->setTextFont(2);
watch->openBL();
tft->setAddrWindow(30, 25, 168, 77);
tft->pushColors((uint16_t *)acsiplogo, 0x3288);
watch->enableLDO4();
watch->enableLDO3();
hwSerial = new HardwareSerial(1);
hwSerial->begin(115200, SERIAL_8N1, GPS_RX, GPS_TX);
if (!s76g.begin(*hwSerial)) {
tft->setTextColor(TFT_RED);
tft->println("Initialization 'S76/78G' failed");
while (1);
}
tft->setCursor(0, 100);
tft->print("FW version:");
tft->println(s76g.getVersion());
tft->print("Hardware:");
tft->println(s76g.getHardWareVer());
tft->print("UUID:");
tft->println(s76g.getUUID());
uint32_t r1, r2;
tft->print("ADC resistor: ");
ret = s76g.getBatteryResistor(r1, r2);
tft->print("R1:");
tft->print(r1);
tft->print(" ");
tft->print("R2:");
tft->print(r2);
showResult(ret == S7XG_OK);
uint16_t volt;
tft->print("ADC Volt: ");
ret = s76g.getBatteryVoltage(volt);
tft->print(volt);
tft->print(" mV");
showResult(ret == S7XG_OK);
tft->print("Set gpio [PB6] OUTPUT");
ret = s76g.setGPIOMode(S7XG_GPIO_GROUP_B, 6, OUTPUT);
if (ret == S7XG_OK) {
showResult(true);
tft->print("Set gpio [PB6] to HIGH");
ret = s76g.setGPIOValue(S7XG_GPIO_GROUP_B, 6, HIGH);
showResult(ret == S7XG_OK);
tft->print("Get gpio [PB6] :");
int val = s76g.getGPIOValue(S7XG_GPIO_GROUP_B, 6);
tft->print(val ? "HIGH" : "LOW");
showResult(ret == S7XG_OK);
}
delay(3000);
}
void rfReceiveCallback(const char *data, int rssi, int snr)
{
Serial.print("receive:");
Serial.print(data);
Serial.print(" ");
Serial.print("rssi:");
Serial.print(rssi);
Serial.print(" ");
Serial.print("snr:");
Serial.print(snr);
Serial.println();
}
void rfBegin()
{
uint32_t freq = 0;
ret = s76g.getRfFreq(freq);
CHECK_ERROR(ret);
//Representing communication frequency in Hz, it can be values from 862000000 to 932000000 (S76S); 137000000 to 525000000 (S78S).
freq = 915000000;
ret = s76g.setRfFreq(freq);
CHECK_ERROR(ret);
ret = s76g.getRfFreq(freq);
CHECK_ERROR(ret);
Serial.printf("freq = %u\n", freq);
//Representing transmitting power in dBm, it can be from 2 to 20.
uint8_t dBm = 20;
ret = s76g.setRfPower(dBm);
CHECK_ERROR(ret);
ret = s76g.getRfPower(dBm);
CHECK_ERROR(ret);
Serial.printf("dBm = %u\n", dBm);
uint8_t sf = 0;
s76g.getRfSpreadingFactor(sf);
CHECK_ERROR(ret);
Serial.printf("SpreadingFactor = %u\n", sf);
//Representing signal bandwidth in kHz, it can be: 125, 250, 500.
uint16_t bw = 125;
s76g.setRfBandWitdth(bw);
//Set the receive callback function
s76g.setRFCallback(rfReceiveCallback);
//Turn on continuous reception mode
ret = s76g.setReceiveContinuous(true);
CHECK_ERROR(ret);
}
void setup()
{
setupWatch();
rfBegin();
}
void loop()
{
// rf service function
s76g.service();
}

View File

@@ -0,0 +1,17 @@
// => Hardware select
#define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line
// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line
// #define LILYGO_WATCH_BLOCK // To use T-Watch Block , please uncomment this line
//NOT SUPPORT ...
// //#define LILYGO_WATCH_2020_V1
//NOT SUPPORT ...
// => Function select
#define LILYGO_WATCH_HAS_S76_S78G
#include <LilyGoWatch.h>

View File

@@ -0,0 +1,180 @@
#pragma mark - Depend Acsip-S7xG-Library
/*
cd ~/Arduino/libraries
git clone https://github.com/lewisxhe/Acsip-S7xG-Library.git
*/
// Example source: https://github.com/lewisxhe/Acsip-S7xG-Library
#include "config.h"
#include <acsip.h>
#include "acsiplogo.h"
TTGOClass *watch = nullptr;
TFT_eSPI *tft;
HardwareSerial *hwSerial = nullptr;
Acsip s76g;
#define CHECK_ERROR(ret) do{ \
if(ret != S7XG_OK){ \
Serial.printf("%d failed\n", __LINE__); \
while (1); \
} \
}while(0)
int ret = 0;
void showResult(bool r)
{
tft->print(" [");
tft->setTextColor(r ? TFT_GREEN : TFT_RED);
tft->print(r ? "OK" : "FAIL");
tft->setTextColor(TFT_WHITE);
tft->println("]");
}
void setupWatch()
{
Serial.begin(115200);
watch = TTGOClass::getWatch();
watch->begin();
tft = watch->tft;
tft->fillScreen(TFT_BLACK);
tft->setTextFont(2);
watch->openBL();
tft->setAddrWindow(30, 25, 168, 77);
tft->pushColors((uint16_t *)acsiplogo, 0x3288);
watch->enableLDO4();
watch->enableLDO3();
hwSerial = new HardwareSerial(1);
hwSerial->begin(115200, SERIAL_8N1, GPS_RX, GPS_TX);
if (!s76g.begin(*hwSerial)) {
tft->setTextColor(TFT_RED);
tft->println("Initialization 'S76/78G' failed");
while (1);
}
tft->setCursor(0, 100);
tft->print("FW version:");
tft->println(s76g.getVersion());
tft->print("Hardware:");
tft->println(s76g.getHardWareVer());
tft->print("UUID:");
tft->println(s76g.getUUID());
uint32_t r1, r2;
tft->print("ADC resistor: ");
ret = s76g.getBatteryResistor(r1, r2);
tft->print("R1:");
tft->print(r1);
tft->print(" ");
tft->print("R2:");
tft->print(r2);
showResult(ret == S7XG_OK);
uint16_t volt;
tft->print("ADC Volt: ");
ret = s76g.getBatteryVoltage(volt);
tft->print(volt);
tft->print(" mV");
showResult(ret == S7XG_OK);
tft->print("Set gpio [PB6] OUTPUT");
ret = s76g.setGPIOMode(S7XG_GPIO_GROUP_B, 6, OUTPUT);
if (ret == S7XG_OK) {
showResult(true);
tft->print("Set gpio [PB6] to HIGH");
ret = s76g.setGPIOValue(S7XG_GPIO_GROUP_B, 6, HIGH);
showResult(ret == S7XG_OK);
tft->print("Get gpio [PB6] :");
int val = s76g.getGPIOValue(S7XG_GPIO_GROUP_B, 6);
tft->print(val ? "HIGH" : "LOW");
showResult(ret == S7XG_OK);
}
delay(3000);
}
void rfReceiveCallback(const char *data, int rssi, int snr)
{
Serial.print("receive:");
Serial.print(data);
Serial.print(" ");
Serial.print("rssi:");
Serial.print(rssi);
Serial.print(" ");
Serial.print("snr:");
Serial.print(snr);
Serial.println();
}
void rfBegin()
{
uint32_t freq = 0;
ret = s76g.getRfFreq(freq);
CHECK_ERROR(ret);
//Representing communication frequency in Hz, it can be values from 862000000 to 932000000 (S76S); 137000000 to 525000000 (S78S).
freq = 915000000;
ret = s76g.setRfFreq(freq);
CHECK_ERROR(ret);
ret = s76g.getRfFreq(freq);
CHECK_ERROR(ret);
Serial.printf("freq = %u\n", freq);
//Representing transmitting power in dBm, it can be from 2 to 20.
uint8_t dBm = 20;
ret = s76g.setRfPower(dBm);
CHECK_ERROR(ret);
ret = s76g.getRfPower(dBm);
CHECK_ERROR(ret);
Serial.printf("dBm = %u\n", dBm);
uint8_t sf = 0;
s76g.getRfSpreadingFactor(sf);
CHECK_ERROR(ret);
Serial.printf("SpreadingFactor = %u\n", sf);
//Representing signal bandwidth in kHz, it can be: 125, 250, 500.
uint16_t bw = 125;
s76g.setRfBandWitdth(bw);
//Turn off continuous reception mode
ret = s76g.setReceiveContinuous(false);
CHECK_ERROR(ret);
}
void setup()
{
setupWatch();
rfBegin();
}
void loop()
{
ret = s76g.RfSendString("hello world");
CHECK_ERROR(ret);
delay(10000);
}

View File

@@ -0,0 +1,707 @@
/**
* @file lilygo main.cpp
*
*/
/*********************
* INCLUDES
*********************/
#include "config.h"
#include <WiFi.h>
#if defined(LILYGO_WATCH_2020_V1)||defined(LILYGO_WATCH_2020_V3)
#include <driver/i2s.h>
#include "HTTPClient.h"
#include "AudioFileSourcePROGMEM.h"
#include "AudioFileSourceID3.h"
#include "AudioGeneratorMP3.h"
#include "AudioOutputI2S.h"
#include "image.h"
#include "image1.h"
#endif
/**********************
* MACROS
**********************/
#define SerialMon Serial
#define MAX30105_ADDRESS 0x57
#define PCF8563_ADDRESS 0x51
#define BMA423_ADDRESS 0x19
#define AXP202_ADDRESS 0x35
#define FT6206_ADDRESS 0X38
#define MPU6050_ADDRESS 0x68
#define MPR121_ADDRESS 0x5A
#define DRV2605_ADDRESS 0x5A
/**********************
* STATIC VARIABLES
**********************/
static TTGOClass *ttgo = nullptr;
static TFT_eSPI *tft = nullptr;
static BMA *bma = nullptr;
static PCF8563_Class *rtc = nullptr;
static CapacitiveTouch *tp = nullptr;
static AXP20X_Class *pmu = nullptr;
static Buzzer *buzzer = nullptr ;
#ifdef LILYGO_WATCH_2020_V2
static Adafruit_DRV2605 *drv;
static TinyGPSPlus *gps;
#endif
static bool find_pwr, find_bma, find_pcf, find_mpu, find_max, find_tp, find_mpr, find_drv;
static bool ret, bma_irq, pmu_irq;
static uint32_t last = 0;
static char buf[256];
static uint32_t montiorMillis = 0;
static uint16_t x;
static uint16_t y;
#define BUFFER_SIZE (2 * TFT_WIDTH)
uint8_t buffer[BUFFER_SIZE] = {0};
uint16_t *ptr = nullptr;
uint16_t prevX[TFT_WIDTH];
uint16_t prevY[TFT_WIDTH];
/**********************
* STATIC FUNCTIONS
**********************/
static void display_info(void);
static void devScan(TwoWire &w);
static void resultOutput(String str, bool ret);
static void wifiScan(void);
#ifdef LILYGO_WATCH_2020_V3
//! PDM MIC BOARD
#define MIC_DATA 2
#define MIC_CLOCK 0
void setupMic()
{
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX | I2S_MODE_PDM),
.sample_rate = 44100,
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
.channel_format = I2S_CHANNEL_FMT_RIGHT_LEFT,
.communication_format = (i2s_comm_format_t)(I2S_COMM_FORMAT_I2S | I2S_COMM_FORMAT_I2S_MSB),//I2S_COMM_FORMAT_I2S,
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = 2,
.dma_buf_len = 128,
};
i2s_pin_config_t i2s_cfg;
i2s_cfg.bck_io_num = I2S_PIN_NO_CHANGE;
i2s_cfg.ws_io_num = MIC_CLOCK;
i2s_cfg.data_out_num = I2S_PIN_NO_CHANGE;
i2s_cfg.data_in_num = MIC_DATA;
i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
i2s_set_pin(I2S_NUM_0, &i2s_cfg);
i2s_set_clk(I2S_NUM_0, 44100, I2S_BITS_PER_SAMPLE_16BIT, I2S_CHANNEL_MONO);
}
void showSignal()
{
int x = 0, y = 0;
for (int i = 0; i < 240; i++) {
x = i;
y = map(ptr[i], 0, 65535, 0, 240);
tft->drawPixel(prevX[i], prevY[i], TFT_WHITE);
tft->drawPixel(x, y, TFT_BLACK);
prevX[i] = x;
prevY[i] = y;
}
}
#endif
bool pmuIRQ()
{
bool rlst = false;
if (pmu_irq) {
pmu_irq = false;
pmu->readIRQ();
if (pmu->isPEKShortPressIRQ()) {
rlst = true;
}
pmu->clearIRQ();
}
return rlst;
}
/**********************
* GLOBAL FUNCTIONS
**********************/
void setup()
{
SerialMon.begin(115200);
setCpuFrequencyMhz(240);
ttgo = TTGOClass::getWatch();
ttgo->begin();
ttgo->openBL();
tft = ttgo->tft;
tp = ttgo->touch;
#ifdef LILYGO_WATCH_2020_V2
gps = ttgo->gps;
drv = ttgo->drv;
#endif
bma = ttgo->bma;
rtc = ttgo->rtc;
pmu = ttgo->power;
//! i2c device scan
devScan(Wire);
devScan(Wire1);
if (find_pwr) {
Serial.println("OK");
pinMode(AXP202_INT, INPUT);
attachInterrupt(AXP202_INT, [] {
pmu_irq = true;
}, FALLING);
ttgo->power->adc1Enable(AXP202_BATT_CUR_ADC1 | AXP202_BATT_VOL_ADC1 |
AXP202_VBUS_VOL_ADC1 | AXP202_VBUS_CUR_ADC1,
true);
ttgo->power->enableIRQ(AXP202_VBUS_REMOVED_IRQ | AXP202_VBUS_CONNECT_IRQ |
AXP202_BATT_REMOVED_IRQ | AXP202_BATT_CONNECT_IRQ |
AXP202_PEK_LONGPRESS_IRQ | AXP202_PEK_SHORTPRESS_IRQ,
true);
ttgo->power->clearIRQ();
}
tft->fillScreen(TFT_BLACK);
#ifdef LILYGO_WATCH_2020_V3
setupMic();
size_t read_len = 0;
while (1) {
if (pmuIRQ()) {
Serial.println("PMU IRQ");
break;
}
i2s_read(I2S_NUM_0, (char *) buffer, BUFFER_SIZE, &read_len, 100 / portTICK_RATE_MS);
ptr = (uint16_t *)buffer;
showSignal();
delay(20);
}
i2s_driver_uninstall(I2S_NUM_0);
#endif
#if defined(LILYGO_WATCH_2020_V1)||defined(LILYGO_WATCH_2020_V3)
tft->fillScreen(TFT_BLACK);
tft->setCursor(0, 0);
tft->println("Play Audio!");
ttgo->enableAudio();
ttgo->motor_begin();
int i = 3;
do {
ttgo->motor->onec();
delay(500);
} while (i--);
AudioGeneratorMP3 *mp3;
AudioFileSourcePROGMEM *file;
AudioOutputI2S *out;
AudioFileSourceID3 *id3;
// file = new AudioFileSourcePROGMEM(image, sizeof(image));
file = new AudioFileSourcePROGMEM(image1, sizeof(image1));
id3 = new AudioFileSourceID3(file);
out = new AudioOutputI2S();
out->SetPinout(TWATCH_DAC_IIS_BCK, TWATCH_DAC_IIS_WS, TWATCH_DAC_IIS_DOUT);
mp3 = new AudioGeneratorMP3();
mp3->begin(id3, out);
while (1) {
if (mp3->isRunning()) {
if (!mp3->loop()) {
mp3->stop();
}
} else {
Serial.printf("MP3 done\n");
break;
}
}
delete file;
delete id3;
delete out;
delete mp3;
ttgo->disableAudio();
#endif
//! Screen test
tft->fillScreen(TFT_BLACK);
delay(500);
tft->fillScreen(TFT_RED);
delay(500);
tft->fillScreen(TFT_GREEN);
delay(500);
tft->fillScreen(TFT_BLUE);
delay(500);
tft->fillScreen(TFT_BLACK);
delay(500);
wifiScan();
delay(5000);
tft->fillScreen(TFT_BLACK);
tft->setTextFont(2);
tft->setCursor(0, 0);
tft->println("Touch test, click the button to skip");
while (1) {
if (pmuIRQ()) {
break;
}
if (tp->getPoint(x, y)) {
tft->fillCircle(x, y, 2, TFT_GREEN);
}
}
tft->fillScreen(TFT_BLACK);
tft->setTextColor(TFT_WHITE);
tft->setCursor(0, 0);
resultOutput("Find AXP202 Chip", find_pwr);
resultOutput("Find BMA423 Chip", find_bma);
resultOutput("Find PCF8563 Chip", find_pcf);
resultOutput("Find TP62XX Chip", find_tp);
if (find_bma) {
ret = ttgo->bma->begin();
resultOutput("Setup BMA423", ret);
bma->attachInterrupt();
pinMode(BMA423_INT1, INPUT);
attachInterrupt(BMA423_INT1, [] {
bma_irq = true;
}, RISING);
}
if (find_pcf) {
int yy = 2020, mm = 3, dd = 15, h = 2, m = 10, s = 0;
rtc->setDateTime(yy, mm, dd, h, m, s);
RTC_Date dt = rtc->getDateTime();
ret = dt.year != yy || dt.month != mm || dt.day != dd || dt.hour != h || dt.minute != m;
resultOutput("Setup PCF8563 ", !ret);
}
#ifdef LILYGO_WATCH_2020_V2
if (!ttgo->sdcard_begin()) {
resultOutput("Setup SDCard ", false);
} else {
resultOutput("Setup SDCard ", true);
}
#endif
tft->setTextColor(TFT_GREEN);
tft->drawString("Step Count:", 0, tft->height() - 20);
#if defined(LILYGO_WATCH_2020_V2)
ttgo->trunOnGPS();
ttgo->gps_begin();
gps = ttgo->gps;
if (find_drv) {
ttgo->enableDrv2650(true);
drv->selectLibrary(1);
drv->setMode(DRV2605_MODE_INTTRIG);
}
#elif defined(LILYGO_WATCH_2019_WITH_TOUCH)
ttgo->enableLDO3();
ttgo->motor_begin();
buzzer = new Buzzer(25);
buzzer->begin();
#endif
}
void loop()
{
#ifdef LILYGO_WATCH_2020_V2
while (ttgo->hwSerial->available()) {
int r = ttgo->hwSerial->read();
Serial.write(r);
ttgo->gps->encode(r);
}
display_info();
#endif
if (millis() - montiorMillis > 1000 && find_pwr) {
if (ttgo->power->isBatteryConnect()) {
snprintf(buf, sizeof(buf), "B:%.2fV/%.2fmA",
ttgo->power->getBattVoltage() / 1000.0,
ttgo->power->isChargeing() ? ttgo->power->getBattChargeCurrent() : ttgo->power->getBattDischargeCurrent());
} else {
snprintf(buf, sizeof(buf), "V:%.2fV/%.2fmA",
ttgo->power->getVbusVoltage() / 1000.0,
ttgo->power->getVbusCurrent());
}
tft->setTextDatum(MC_DATUM);
x = tft->width() / 2;
y = tft->height() - 20;
tft->fillRect(60, y - 50, x, 16, TFT_BLACK);
tft->drawString(buf, x, y - 40, tft->textfont);
montiorMillis = millis();
tft->setTextDatum(TL_DATUM);
}
if (pmu_irq) {
pmu_irq = false;
ttgo->power->readIRQ();
if (ttgo->power->isChargingIRQ()) {
ttgo->setBrightness(255);
} else {
}
if (ttgo->power->isVbusRemoveIRQ()) {
ttgo->setBrightness(80);
}
if (ttgo->power->isPEKLongtPressIRQ()) {
SerialMon.println("isPEKLongtPressIRQ");
}
if (ttgo->power->isPEKShortPressIRQ()) {
#if defined(LILYGO_WATCH_2020_V2)
if (find_drv) {
// set the effect to play
drv->setWaveform(0, 75); // play effect
drv->setWaveform(1, 0); // end waveform
// play the effect!
drv->go();
}
#elif defined(LILYGO_WATCH_2019_WITH_TOUCH)
ttgo->motor->onec();
buzzer->onec();
#endif
if (ttgo->bl->isOn()) {
ttgo->closeBL();
} else {
ttgo->openBL();
}
}
ttgo->power->clearIRQ();
}
if (tp->getPoint(x, y)) {
snprintf(buf, sizeof(buf), "x:%d y:%d", x, y);
tft->fillRect(tft->width() / 2, tft->height() - 20, tft->width() / 2, tft->height() - 20, TFT_BLACK);
tft->drawRightString(buf, tft->width() - 5, tft->height() - 20, tft->textfont);
}
if (bma_irq) {
bma_irq = false;
do {
ret = bma->readInterrupt();
} while (!ret);
if (bma->isStepCounter()) {
static uint32_t prevSetp = 0;
uint32_t c = bma->getCounter();
if (prevSetp == c)
return;
prevSetp = c;
String str = "Step Count:" + String(c);
uint16_t twidth = tft->textWidth(str);
y = tft->height() - 20;
tft->fillRect(0,
y - 20,
twidth + 10,
40,
TFT_BLACK);
tft->drawString(str, 0, y);
}
}
}
/**********************
* STATIC FUNCTIONS
**********************/
#ifdef LILYGO_WATCH_2020_V2
static void display_info(void)
{
static uint32_t updatePeriod;
if (millis() - updatePeriod < 1000) {
return;
}
updatePeriod = millis();
if (gps->date.isUpdated() && gps->time.isUpdated()) {
tft->fillRect(0, 115, 240, 35, TFT_BLACK);
tft->setCursor(0, 116);
tft->print("DATE Year:");
tft->print(gps->date.year());
tft->print(" Month:");
tft->print(gps->date.month());
tft->print(" Day:");
tft->println(gps->date.day());
tft->print(F("TIME Hour:"));
tft->print(gps->time.hour());
tft->print(F(" Minute:"));
tft->print(gps->time.minute());
tft->print(F(" Second:"));
tft->print(gps->time.second());
// SerialMon.print(F("DATE Fix Age="));
// SerialMon.print(gps->date.age());
// SerialMon.print(F("ms Raw="));
// SerialMon.print(gps->date.value());
// SerialMon.print(F(" Year="));
// SerialMon.print(gps->date.year());
// SerialMon.print(F(" Month="));
// SerialMon.print(gps->date.month());
// SerialMon.print(F(" Day="));
// SerialMon.println(gps->date.day());
// SerialMon.print(F("TIME Fix Age="));
// SerialMon.print(gps->time.age());
// SerialMon.print(F("ms Raw="));
// SerialMon.print(gps->time.value());
// SerialMon.print(F(" Hour="));
// SerialMon.print(gps->time.hour());
// SerialMon.print(F(" Minute="));
// SerialMon.print(gps->time.minute());
// SerialMon.print(F(" Second="));
// SerialMon.print(gps->time.second());
// SerialMon.print(F(" Hundredths="));
// SerialMon.println(gps->time.centisecond());
}
if (gps->location.isUpdated()) {
tft->fillRect(0, 150, 240, 20, TFT_BLACK);
tft->setCursor(0, 150);
tft->print(F("LOCATION Lat:"));
tft->print(gps->location.lat(), 3);
tft->print(F(" Long="));
tft->println(gps->location.lng(), 3);
// SerialMon.print(F("LOCATION Fix Age="));
// SerialMon.print(gps->location.age());
// SerialMon.print(F("ms Raw Lat="));
// SerialMon.print(gps->location.rawLat().negative ? "-" : "+");
// SerialMon.print(gps->location.rawLat().deg);
// SerialMon.print("[+");
// SerialMon.print(gps->location.rawLat().billionths);
// SerialMon.print(F(" billionths], Raw Long="));
// SerialMon.print(gps->location.rawLng().negative ? "-" : "+");
// SerialMon.print(gps->location.rawLng().deg);
// SerialMon.print("[+");
// SerialMon.print(gps->location.rawLng().billionths);
// SerialMon.print(F(" billionths], Lat="));
// SerialMon.print(gps->location.lat(), 6);
// SerialMon.print(F(" Long="));
// SerialMon.println(gps->location.lng(), 6);
}
if (gps->speed.isUpdated()) {
// SerialMon.print(F("SPEED Fix Age="));
// SerialMon.print(gps->speed.age());
// SerialMon.print(F("ms Raw="));
// SerialMon.print(gps->speed.value());
// SerialMon.print(F(" Knots="));
// SerialMon.print(gps->speed.knots());
// SerialMon.print(F(" MPH="));
// SerialMon.print(gps->speed.mph());
// SerialMon.print(F(" m/s="));
// SerialMon.print(gps->speed.mps());
// SerialMon.print(F(" km/h="));
// SerialMon.println(gps->speed.kmph());
}
if (gps->course.isUpdated()) {
// SerialMon.print(F("COURSE Fix Age="));
// SerialMon.print(gps->course.age());
// SerialMon.print(F("ms Raw="));
// SerialMon.print(gps->course.value());
// SerialMon.print(F(" Deg="));
// SerialMon.println(gps->course.deg());
}
if (gps->altitude.isUpdated()) {
// SerialMon.print(F("ALTITUDE Fix Age="));
// SerialMon.print(gps->altitude.age());
// SerialMon.print(F("ms Raw="));
// SerialMon.print(gps->altitude.value());
// SerialMon.print(F(" Meters="));
// SerialMon.print(gps->altitude.meters());
// SerialMon.print(F(" Miles="));
// SerialMon.print(gps->altitude.miles());
// SerialMon.print(F(" KM="));
// SerialMon.print(gps->altitude.kilometers());
// SerialMon.print(F(" Feet="));
// SerialMon.println(gps->altitude.feet());
}
if (gps->satellites.isUpdated()) {
// SerialMon.print(F("SATELLITES Fix Age="));
// SerialMon.print(gps->satellites.age());
// SerialMon.print(F("ms Value="));
// SerialMon.println(gps->satellites.value());
}
if (gps->hdop.isUpdated()) {
// SerialMon.print(F("HDOP Fix Age="));
// SerialMon.print(gps->hdop.age());
// SerialMon.print(F("ms Value="));
// SerialMon.println(gps->hdop.value());
}
// if (millis() - last > 5000) {
// SerialMon.println();
// if (gps->charsProcessed() < 10) {
// SerialMon.println(F("WARNING: No GPS data. Check wiring."));
// }
// last = millis();
// SerialMon.println();
// }
delay(20);
}
#endif
static void devScan(TwoWire &w)
{
uint8_t err, addr;
int nDevices = 0;
for (addr = 1; addr < 127; addr++) {
w.beginTransmission(addr);
err = w.endTransmission();
if (err == 0) {
SerialMon.print("I2C device found at address 0x");
if (addr < 16)
SerialMon.print("0");
SerialMon.print(addr, HEX);
SerialMon.println(" !");
switch (addr) {
case MAX30105_ADDRESS:
find_max = true;
break;
case PCF8563_ADDRESS:
find_pcf = true;
break;
case BMA423_ADDRESS:
find_bma = true;
break;
case AXP202_ADDRESS:
find_pwr = true;
break;
case FT6206_ADDRESS:
find_tp = true;
break;
case MPU6050_ADDRESS:
find_mpu = true;
break;
// case MPR121_ADDRESS:
// find_mpr = true;
// break;
case DRV2605_ADDRESS:
find_drv = true;
default:
break;
}
nDevices++;
} else if (err == 4) {
SerialMon.print("Unknow error at address 0x");
if (addr < 16)
SerialMon.print("0");
SerialMon.println(addr, HEX);
}
}
}
static void resultOutput(String str, bool ret)
{
tft->setTextColor(TFT_WHITE);
tft->drawString(str, 0, tft->getCursorY());
tft->setTextColor(ret ? TFT_GREEN : TFT_RED);
tft->drawRightString(ret ? "[OK]" : "[FAIL]", tft->width() - 5, tft->getCursorY(), tft->textfont);
tft->println();
}
static void wifiScan(void)
{
char buff[128];
tft->setCursor(0, 0);
tft->setTextColor(TFT_GREEN, TFT_BLACK);
tft->fillScreen(TFT_BLACK);
tft->setTextDatum(MC_DATUM);
tft->setTextSize(1);
tft->drawString("Scan Network", tft->width() / 2, tft->height() / 2);
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
int16_t n = WiFi.scanNetworks();
tft->fillScreen(TFT_BLACK);
if (n == 0) {
SerialMon.println("No Search WiFi Signal");
tft->drawString("No Search WiFi Signal", tft->width() / 2, tft->height() / 2);
} else {
tft->setTextDatum(TL_DATUM);
tft->setCursor(0, 0);
bool utf8 = false;
SerialMon.printf("Search [%d] WiFi Signal\n", n);
uint16_t count = 0;
for (int i = 0; i < n; ++i) {
SerialMon.println(WiFi.SSID(i));
char *ssid = (char *)WiFi.SSID(i).c_str();
for (int j = 0; j < strlen(ssid); j++) {
if (ssid[j] > 0x7F) {
utf8 = true;
break;
};
}
if (!utf8) {
sprintf(buff,
"\t[%d]:%s(%d)",
count++,
WiFi.SSID(i).c_str(),
WiFi.RSSI(i));
tft->println(buff);
}
utf8 = false;
}
}
WiFi.mode(WIFI_OFF);
}

View File

@@ -0,0 +1,17 @@
// => Hardware select
// #define LILYGO_WATCH_2019_WITH_TOUCH // To use T-Watch2019 with touchscreen, please uncomment this line
// #define LILYGO_WATCH_2019_NO_TOUCH // To use T-Watch2019 Not touchscreen , please uncomment this line
// #define LILYGO_WATCH_BLOCK // To use T-Watch Block , please uncomment this line
// #define LILYGO_WATCH_2020_V1
#define LILYGO_WATCH_2020_V2
// #define LILYGO_WATCH_2020_V3
#ifdef LILYGO_WATCH_2019_WITH_TOUCH
#define LILYGO_WATCH_HAS_MOTOR
#endif
#include <LilyGoWatch.h>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
{
"name": "TTGO TWatch Library",
"keywords": "Device Conterl,TWatch,Watch,TTGO",
"description": "Arduino Library for TTGO T-Watch development kit",
"description": "Arduino Library for LilyGo T-Watch & LilyPi & T-Block development kit",
"repository": {
"type": "git",
"url": "https://github.com/Xinyuan-LilyGO/TTGO_TWatch_Library.git"
@@ -12,14 +12,9 @@
"email": "lily@lilygo.cc",
"url": "https://github.com/Xinyuan-LilyGO",
"maintainer": true
},
{
"name": "lewishe",
"email": "lewishe@outlook.com",
"url": "https://github.com/lewisxhe"
}
],
"version": "1.4.1",
"version": "1.4.2",
"frameworks": "arduino",
"platforms": "esp32"
}

View File

@@ -1,8 +1,8 @@
name=TTGO TWatch Library
version=1.4.1
version=1.4.2
author=TTGO
maintainer=lewis he <lewishe@outlook.com>
sentence=Library for TTGO T-Watch development kit
maintainer=Xinyuan Electronics <lily@lilygo.cc>
sentence=Library for LilyGo development kit
paragraph=twatch library
category=Device Control
url=https://github.com/Xinyuan-LilyGO/TTGO_TWatch_Library

View File

@@ -139,6 +139,14 @@ typedef FocalTech_Class CapacitiveTouch ;
#define TOUCH_IRQ_BIT (_BV(1))
/* Selectively disable some initialisation */
#define NO_HARDWARE (_BV(0))
#define NO_POWER (_BV(1))
#define NO_TFT (_BV(2))
#define NO_TOUCH (_BV(3))
#define NO_SENSOR (_BV(4))
#define NO_BACKLIGHT (_BV(5))
class TTGOClass
{
public:
@@ -158,9 +166,8 @@ public:
}
#endif
void begin()
void begin( uint8_t disable = 0 )
{
i2c = new I2CBus();
#ifdef LILYGO_WATCH_HAS_PCF8563
@@ -192,12 +199,23 @@ public:
drv = new Adafruit_DRV2605();
#endif /*LILYGO_WATCH_DRV2605*/
initHardware();
initPower();
initTFT();
initTouch();
initSensor();
initBlacklight();
if(!(disable & NO_HARDWARE))
initHardware();
if(!(disable & NO_HARDWARE))
initPower();
if(!(disable & NO_HARDWARE))
initTFT();
if(!(disable & NO_HARDWARE))
initTouch();
if(!(disable & NO_HARDWARE))
initSensor();
if(!(disable & NO_HARDWARE))
initBlacklight();
}
#ifdef LILYGO_WATCH_HAS_BMA423

View File

@@ -25,8 +25,8 @@
#define USER_BUTTON 36
#define TOUCH_INT 38
#define RTC_INT_PIN 37
#define TOUCH_INT 33
#define RTC_INT_PIN 37
#define AXP202_INT 35
#define BMA423_INT1 39
#define BMA423_INT2 0

View File

@@ -634,18 +634,24 @@ int AXP20X_Class::readIRQ()
{
if (!_init)
return AXP_NOT_INIT;
AXP_DEBUG("readIRQ() : ");
switch (_chip_id) {
case AXP192_CHIP_ID:
for (int i = 0; i < 4; ++i) {
_readByte(AXP192_INTSTS1 + i, 1, &_irq[i]);
AXP_DEBUG("%02x:%02x ", AXP202_INTSTS1 + i, _irq[i]);
}
_readByte(AXP192_INTSTS5, 1, &_irq[4]);
AXP_DEBUG("%02x:%02x\n", AXP192_INTSTS5, _irq[4]);
return AXP_PASS;
case AXP202_CHIP_ID:
for (int i = 0; i < 5; ++i) {
_readByte(AXP202_INTSTS1 + i, 1, &_irq[i]);
AXP_DEBUG("%02x:%02x ", AXP202_INTSTS1 + i, _irq[i]);
}
AXP_DEBUG("\n");
return AXP_PASS;
default:
return AXP_FAIL;
@@ -655,6 +661,7 @@ int AXP20X_Class::readIRQ()
void AXP20X_Class::clearIRQ()
{
uint8_t val = 0xFF;
AXP_DEBUG("clearIRQ()\n");
switch (_chip_id) {
case AXP192_CHIP_ID:
for (int i = 0; i < 3; i++) {
@@ -1019,6 +1026,19 @@ int AXP20X_Class::setStartupTime(uint8_t param)
return AXP_PASS;
}
int AXP20X_Class::getStartupTime(){
uint8_t val;
_readByte(AXP202_POK_SET, 1, &val);
static const int trans[]={
13, 30, 10, 20
};
val &= 0b11000000;
AXP_DEBUG("%x -> %x\n", val, val>>6);
return trans[ val>>6 ];
}
int AXP20X_Class::setlongPressTime(uint8_t param)
{
uint8_t val;
@@ -1033,6 +1053,21 @@ int AXP20X_Class::setlongPressTime(uint8_t param)
return AXP_PASS;
}
int AXP20X_Class::getlongPressTime(){
uint8_t val;
_readByte(AXP202_POK_SET, 1, &val);
static const int trans[]={
10, 15, 20, 25
};
val &= 0b00110000;
AXP_DEBUG("%x -> %x\n", val, val>>4);
return trans[ val>>4 ];
}
int AXP20X_Class::setShutdownTime(uint8_t param)
{
uint8_t val;
@@ -1047,6 +1082,19 @@ int AXP20X_Class::setShutdownTime(uint8_t param)
return AXP_PASS;
}
int AXP20X_Class::getShutdownTime(){
uint8_t val;
_readByte(AXP202_POK_SET, 1, &val);
static const int trans[]={
40, 60, 80, 100
};
val &= 0b00000011;
AXP_DEBUG("%x\n", val);
return trans[ val ];
}
int AXP20X_Class::setTimeOutShutdown(bool en)
{
uint8_t val;

View File

@@ -643,21 +643,37 @@ public:
int setTimer(uint8_t minutes);
int offTimer();
int clearTimerStatus();
/**
* param: axp202_startup_time_t or axp192_startup_time_t
*/
int setStartupTime(uint8_t param);
/**
* Return : LongPress threshold x10 (so 15 = 1.5s)
*/
int getStartupTime();
/**
* param: axp_loonPress_time_t
*/
int setlongPressTime(uint8_t param);
/**
* Return : LongPress threshold x10 (so 15 = 1.5s)
*/
int getlongPressTime();
/**
* @param param: axp_poweroff_time_t
*/
int setShutdownTime(uint8_t param);
/**
* Return : shutdown Press threshold x10 (so 15 = 1.5s)
*/
int getShutdownTime();
int setTimeOutShutdown(bool en);
int shutdown();
@@ -747,6 +763,13 @@ public:
int getChargeControlCur();
int setChargeControlCur(uint16_t mA);
// Read register value at reg address
uint8_t readRegister( uint8_t reg ){
uint8_t dt;
_readByte( reg, 1, &dt );
return dt;
}
private:
uint16_t _getRegistH8L5(uint8_t regh8, uint8_t regl5)
{

View File

@@ -1,230 +0,0 @@
/**************************************************************************/
/*!
@file Adafruit_PN532.h
@author Adafruit Industries
@license BSD (see license.txt)
This is a library for the Adafruit PN532 NFC/RFID breakout boards
This library works with the Adafruit NFC breakout
----> https://www.adafruit.com/products/364
Check out the links above for our tutorials and wiring diagrams
These chips use SPI or I2C to communicate.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
@section HISTORY
v2.0 - Refactored to add I2C support from Adafruit_NFCShield_I2C library.
v1.1 - Added full command list
- Added 'verbose' mode flag to constructor to toggle debug output
- Changed readPassiveTargetID() to return variable length values
*/
/**************************************************************************/
#ifndef ADAFRUIT_PN532_H
#define ADAFRUIT_PN532_H
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#define PN532_PREAMBLE (0x00)
#define PN532_STARTCODE1 (0x00)
#define PN532_STARTCODE2 (0xFF)
#define PN532_POSTAMBLE (0x00)
#define PN532_HOSTTOPN532 (0xD4)
#define PN532_PN532TOHOST (0xD5)
// PN532 Commands
#define PN532_COMMAND_DIAGNOSE (0x00)
#define PN532_COMMAND_GETFIRMWAREVERSION (0x02)
#define PN532_COMMAND_GETGENERALSTATUS (0x04)
#define PN532_COMMAND_READREGISTER (0x06)
#define PN532_COMMAND_WRITEREGISTER (0x08)
#define PN532_COMMAND_READGPIO (0x0C)
#define PN532_COMMAND_WRITEGPIO (0x0E)
#define PN532_COMMAND_SETSERIALBAUDRATE (0x10)
#define PN532_COMMAND_SETPARAMETERS (0x12)
#define PN532_COMMAND_SAMCONFIGURATION (0x14)
#define PN532_COMMAND_POWERDOWN (0x16)
#define PN532_COMMAND_RFCONFIGURATION (0x32)
#define PN532_COMMAND_RFREGULATIONTEST (0x58)
#define PN532_COMMAND_INJUMPFORDEP (0x56)
#define PN532_COMMAND_INJUMPFORPSL (0x46)
#define PN532_COMMAND_INLISTPASSIVETARGET (0x4A)
#define PN532_COMMAND_INATR (0x50)
#define PN532_COMMAND_INPSL (0x4E)
#define PN532_COMMAND_INDATAEXCHANGE (0x40)
#define PN532_COMMAND_INCOMMUNICATETHRU (0x42)
#define PN532_COMMAND_INDESELECT (0x44)
#define PN532_COMMAND_INRELEASE (0x52)
#define PN532_COMMAND_INSELECT (0x54)
#define PN532_COMMAND_INAUTOPOLL (0x60)
#define PN532_COMMAND_TGINITASTARGET (0x8C)
#define PN532_COMMAND_TGSETGENERALBYTES (0x92)
#define PN532_COMMAND_TGGETDATA (0x86)
#define PN532_COMMAND_TGSETDATA (0x8E)
#define PN532_COMMAND_TGSETMETADATA (0x94)
#define PN532_COMMAND_TGGETINITIATORCOMMAND (0x88)
#define PN532_COMMAND_TGRESPONSETOINITIATOR (0x90)
#define PN532_COMMAND_TGGETTARGETSTATUS (0x8A)
#define PN532_RESPONSE_INDATAEXCHANGE (0x41)
#define PN532_RESPONSE_INLISTPASSIVETARGET (0x4B)
#define PN532_WAKEUP (0x55)
#define PN532_SPI_STATREAD (0x02)
#define PN532_SPI_DATAWRITE (0x01)
#define PN532_SPI_DATAREAD (0x03)
#define PN532_SPI_READY (0x01)
#define PN532_I2C_ADDRESS (0x48 >> 1)
#define PN532_I2C_READBIT (0x01)
#define PN532_I2C_BUSY (0x00)
#define PN532_I2C_READY (0x01)
#define PN532_I2C_READYTIMEOUT (20)
#define PN532_MIFARE_ISO14443A (0x00)
// Mifare Commands
#define MIFARE_CMD_AUTH_A (0x60)
#define MIFARE_CMD_AUTH_B (0x61)
#define MIFARE_CMD_READ (0x30)
#define MIFARE_CMD_WRITE (0xA0)
#define MIFARE_CMD_TRANSFER (0xB0)
#define MIFARE_CMD_DECREMENT (0xC0)
#define MIFARE_CMD_INCREMENT (0xC1)
#define MIFARE_CMD_STORE (0xC2)
#define MIFARE_ULTRALIGHT_CMD_WRITE (0xA2)
// Prefixes for NDEF Records (to identify record type)
#define NDEF_URIPREFIX_NONE (0x00)
#define NDEF_URIPREFIX_HTTP_WWWDOT (0x01)
#define NDEF_URIPREFIX_HTTPS_WWWDOT (0x02)
#define NDEF_URIPREFIX_HTTP (0x03)
#define NDEF_URIPREFIX_HTTPS (0x04)
#define NDEF_URIPREFIX_TEL (0x05)
#define NDEF_URIPREFIX_MAILTO (0x06)
#define NDEF_URIPREFIX_FTP_ANONAT (0x07)
#define NDEF_URIPREFIX_FTP_FTPDOT (0x08)
#define NDEF_URIPREFIX_FTPS (0x09)
#define NDEF_URIPREFIX_SFTP (0x0A)
#define NDEF_URIPREFIX_SMB (0x0B)
#define NDEF_URIPREFIX_NFS (0x0C)
#define NDEF_URIPREFIX_FTP (0x0D)
#define NDEF_URIPREFIX_DAV (0x0E)
#define NDEF_URIPREFIX_NEWS (0x0F)
#define NDEF_URIPREFIX_TELNET (0x10)
#define NDEF_URIPREFIX_IMAP (0x11)
#define NDEF_URIPREFIX_RTSP (0x12)
#define NDEF_URIPREFIX_URN (0x13)
#define NDEF_URIPREFIX_POP (0x14)
#define NDEF_URIPREFIX_SIP (0x15)
#define NDEF_URIPREFIX_SIPS (0x16)
#define NDEF_URIPREFIX_TFTP (0x17)
#define NDEF_URIPREFIX_BTSPP (0x18)
#define NDEF_URIPREFIX_BTL2CAP (0x19)
#define NDEF_URIPREFIX_BTGOEP (0x1A)
#define NDEF_URIPREFIX_TCPOBEX (0x1B)
#define NDEF_URIPREFIX_IRDAOBEX (0x1C)
#define NDEF_URIPREFIX_FILE (0x1D)
#define NDEF_URIPREFIX_URN_EPC_ID (0x1E)
#define NDEF_URIPREFIX_URN_EPC_TAG (0x1F)
#define NDEF_URIPREFIX_URN_EPC_PAT (0x20)
#define NDEF_URIPREFIX_URN_EPC_RAW (0x21)
#define NDEF_URIPREFIX_URN_EPC (0x22)
#define NDEF_URIPREFIX_URN_NFC (0x23)
#define PN532_GPIO_VALIDATIONBIT (0x80)
#define PN532_GPIO_P30 (0)
#define PN532_GPIO_P31 (1)
#define PN532_GPIO_P32 (2)
#define PN532_GPIO_P33 (3)
#define PN532_GPIO_P34 (4)
#define PN532_GPIO_P35 (5)
class Adafruit_PN532
{
public:
Adafruit_PN532(uint8_t clk, uint8_t miso, uint8_t mosi, uint8_t ss); // Software SPI
Adafruit_PN532(uint8_t irq, uint8_t reset); // Hardware I2C
Adafruit_PN532(uint8_t ss); // Hardware SPI
void begin(void);
// Generic PN532 functions
bool SAMConfig(void);
uint32_t getFirmwareVersion(void);
bool sendCommandCheckAck(uint8_t *cmd, uint8_t cmdlen, uint16_t timeout = 1000);
bool writeGPIO(uint8_t pinstate);
uint8_t readGPIO(void);
bool setPassiveActivationRetries(uint8_t maxRetries);
// ISO14443A functions
bool readPassiveTargetID(uint8_t cardbaudrate, uint8_t *uid, uint8_t *uidLength, uint16_t timeout = 0); //timeout 0 means no timeout - will block forever.
bool inDataExchange(uint8_t *send, uint8_t sendLength, uint8_t *response, uint8_t *responseLength);
bool inListPassiveTarget();
// Mifare Classic functions
bool mifareclassic_IsFirstBlock (uint32_t uiBlock);
bool mifareclassic_IsTrailerBlock (uint32_t uiBlock);
uint8_t mifareclassic_AuthenticateBlock (uint8_t *uid, uint8_t uidLen, uint32_t blockNumber, uint8_t keyNumber, uint8_t *keyData);
uint8_t mifareclassic_ReadDataBlock (uint8_t blockNumber, uint8_t *data);
uint8_t mifareclassic_WriteDataBlock (uint8_t blockNumber, uint8_t *data);
uint8_t mifareclassic_FormatNDEF (void);
uint8_t mifareclassic_WriteNDEFURI (uint8_t sectorNumber, uint8_t uriIdentifier, const char *url);
// Mifare Ultralight functions
uint8_t mifareultralight_ReadPage (uint8_t page, uint8_t *buffer);
uint8_t mifareultralight_WritePage (uint8_t page, uint8_t *data);
// NTAG2xx functions
uint8_t ntag2xx_ReadPage (uint8_t page, uint8_t *buffer);
uint8_t ntag2xx_WritePage (uint8_t page, uint8_t *data);
uint8_t ntag2xx_WriteNDEFURI (uint8_t uriIdentifier, char *url, uint8_t dataLen);
// Help functions to display formatted text
static void PrintHex(const byte *data, const uint32_t numBytes);
static void PrintHexChar(const byte *pbtData, const uint32_t numBytes);
typedef void (*readBytesCall_t)(uint8_t devAddress, uint8_t *data, uint16_t len) ;
typedef void (*writeBytesCall_t)(uint8_t devAddress, uint8_t regAddress, uint8_t *data, uint16_t len) ;
void setI2CRead(readBytesCall_t cb);
void setI2CWrite(writeBytesCall_t cb);
private:
uint8_t _ss, _clk, _mosi, _miso;
uint8_t _irq, _reset;
uint8_t _uid[7]; // ISO14443A uid
uint8_t _uidLen; // uid len
uint8_t _key[6]; // Mifare Classic key
uint8_t _inListedTag; // Tg number of inlisted tag.
bool _usingSPI; // True if using SPI, false if using I2C.
bool _hardwareSPI; // True is using hardware SPI, false if using software SPI.
// Low level communication functions that handle both SPI and I2C.
void readdata(uint8_t *buff, uint8_t n);
void writecommand(uint8_t *cmd, uint8_t cmdlen);
bool isready();
bool waitready(uint16_t timeout);
bool readack();
// SPI-specific functions.
void spi_write(uint8_t c);
uint8_t spi_read(void);
readBytesCall_t _readCallBack;
writeBytesCall_t _writeCallBack;
// Note there are i2c_read and i2c_write inline functions defined in the .cpp file.
};
#endif

View File

@@ -102,7 +102,7 @@ bool PCF8563_Class::isValid()
RTC_Date PCF8563_Class::getDateTime()
{
uint16_t year;
uint8_t cetury = 0;
uint8_t century = 0;
_readByte(PCF8563_SEC_REG, 7, _data);
_voltageLow = (_data[0] & PCF8563_VOL_LOW_MASK);
_data[0] = _bcd_to_dec(_data[0] & (~PCF8563_VOL_LOW_MASK));
@@ -110,10 +110,10 @@ RTC_Date PCF8563_Class::getDateTime()
_data[2] = _bcd_to_dec(_data[2] & PCF8563_HOUR_MASK);
_data[3] = _bcd_to_dec(_data[3] & PCF8563_DAY_MASK);
_data[4] = _bcd_to_dec(_data[4] & PCF8563_WEEKDAY_MASK);
cetury = _data[5] & PCF8563_CENTURY_MASK;
century = _data[5] & PCF8563_CENTURY_MASK;
_data[5] = _bcd_to_dec(_data[5] & PCF8563_MONTH_MASK);
year = _bcd_to_dec(_data[6]);
year = cetury ? 1900 + year : 2000 + year;
year = century ? 1900 + year : 2000 + year;
return RTC_Date(
year,
_data[5],
@@ -252,11 +252,11 @@ void PCF8563_Class::disableTimer()
_writeByte(PCF8563_STAT2_REG, 1, _data);
}
void PCF8563_Class::setTimer(uint8_t val, uint8_t freq, bool enIntrrupt)
void PCF8563_Class::setTimer(uint8_t val, uint8_t freq, bool enInterrupt)
{
_readByte(PCF8563_STAT2_REG, 1, &_data[0]);
_readByte(PCF8563_TIMER1_REG, 1, &_data[1]);
if (enIntrrupt) {
if (enInterrupt) {
_data[0] |= 1 << 4;
} else {
_data[0] &= ~(1 << 4);
@@ -278,8 +278,6 @@ void PCF8563_Class::clearTimer()
_writeByte(PCF8563_TIMER1_REG, 1, &_data[1]);
}
bool PCF8563_Class::enableCLK(uint8_t freq)
{
if (freq >= PCF8563_CLK_MAX) return false;
@@ -294,16 +292,13 @@ void PCF8563_Class::disableCLK()
_writeByte(PCF8563_SQW_REG, 1, _data);
}
const char *PCF8563_Class::formatDateTime(uint8_t sytle)
const char *PCF8563_Class::formatDateTime(uint8_t style)
{
RTC_Date t = getDateTime();
switch (sytle) {
switch (style) {
case PCF_TIMEFORMAT_HM:
snprintf(format, sizeof(format), "%02d:%02d", t.hour, t.minute);
break;
case PCF_TIMEFORMAT_HMS:
snprintf(format, sizeof(format), "%02d:%02d:%02d", t.hour, t.minute, t.second);
break;
case PCF_TIMEFORMAT_YYYY_MM_DD:
snprintf(format, sizeof(format), "%02d-%02d-%02d", t.year, t.month, t.day);
break;
@@ -316,8 +311,9 @@ const char *PCF8563_Class::formatDateTime(uint8_t sytle)
case PCF_TIMEFORMAT_YYYY_MM_DD_H_M_S:
snprintf(format, sizeof(format), "%02d-%02d-%02d/%02d:%02d:%02d", t.year, t.month, t.day, t.hour, t.minute, t.second);
break;
case PCF_TIMEFORMAT_HMS:
default:
snprintf(format, sizeof(format), "%02d:%02d", t.hour, t.minute);
snprintf(format, sizeof(format), "%02d:%02d:%02d", t.hour, t.minute, t.second);
break;
}
return format;
@@ -371,8 +367,6 @@ RTC_Date::RTC_Date(uint16_t y,
}
uint8_t RTC_Date::StringToUint8(const char *pString)
{
uint8_t value = 0;

View File

@@ -162,7 +162,7 @@ public:
bool isTimerActive();
void enableTimer();
void disableTimer();
void setTimer(uint8_t val, uint8_t freq, bool enIntrrupt);
void setTimer(uint8_t val, uint8_t freq, bool enInterrupt);
void clearTimer();
bool enableCLK(uint8_t freq);
@@ -171,7 +171,7 @@ public:
void syncToSystem();
void syncToRtc();
const char *formatDateTime(uint8_t sytle = PCF_TIMEFORMAT_HMS);
const char *formatDateTime(uint8_t style = PCF_TIMEFORMAT_HMS);
uint32_t getDayOfWeek(uint32_t day, uint32_t month, uint32_t year);
uint8_t status2();

View File

@@ -0,0 +1,229 @@
/**************************************************************************/
/*!
@file Adafruit_PN532.h
@author Adafruit Industries
@license BSD (see license.txt)
This is a library for the Adafruit PN532 NFC/RFID breakout boards
This library works with the Adafruit NFC breakout
----> https://www.adafruit.com/products/364
Check out the links above for our tutorials and wiring diagrams
These chips use SPI or I2C to communicate.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
@section HISTORY
v2.0 - Refactored to add I2C support from Adafruit_NFCShield_I2C library.
v1.1 - Added full command list
- Added 'verbose' mode flag to constructor to toggle debug output
- Changed readPassiveTargetID() to return variable length values
*/
/**************************************************************************/
#ifndef ADAFRUIT_PN532_H
#define ADAFRUIT_PN532_H
#include "Arduino.h"
#define PN532_PREAMBLE (0x00)
#define PN532_STARTCODE1 (0x00)
#define PN532_STARTCODE2 (0xFF)
#define PN532_POSTAMBLE (0x00)
#define PN532_HOSTTOPN532 (0xD4)
#define PN532_PN532TOHOST (0xD5)
// PN532 Commands
#define PN532_COMMAND_DIAGNOSE (0x00)
#define PN532_COMMAND_GETFIRMWAREVERSION (0x02)
#define PN532_COMMAND_GETGENERALSTATUS (0x04)
#define PN532_COMMAND_READREGISTER (0x06)
#define PN532_COMMAND_WRITEREGISTER (0x08)
#define PN532_COMMAND_READGPIO (0x0C)
#define PN532_COMMAND_WRITEGPIO (0x0E)
#define PN532_COMMAND_SETSERIALBAUDRATE (0x10)
#define PN532_COMMAND_SETPARAMETERS (0x12)
#define PN532_COMMAND_SAMCONFIGURATION (0x14)
#define PN532_COMMAND_POWERDOWN (0x16)
#define PN532_COMMAND_RFCONFIGURATION (0x32)
#define PN532_COMMAND_RFREGULATIONTEST (0x58)
#define PN532_COMMAND_INJUMPFORDEP (0x56)
#define PN532_COMMAND_INJUMPFORPSL (0x46)
#define PN532_COMMAND_INLISTPASSIVETARGET (0x4A)
#define PN532_COMMAND_INATR (0x50)
#define PN532_COMMAND_INPSL (0x4E)
#define PN532_COMMAND_INDATAEXCHANGE (0x40)
#define PN532_COMMAND_INCOMMUNICATETHRU (0x42)
#define PN532_COMMAND_INDESELECT (0x44)
#define PN532_COMMAND_INRELEASE (0x52)
#define PN532_COMMAND_INSELECT (0x54)
#define PN532_COMMAND_INAUTOPOLL (0x60)
#define PN532_COMMAND_TGINITASTARGET (0x8C)
#define PN532_COMMAND_TGSETGENERALBYTES (0x92)
#define PN532_COMMAND_TGGETDATA (0x86)
#define PN532_COMMAND_TGSETDATA (0x8E)
#define PN532_COMMAND_TGSETMETADATA (0x94)
#define PN532_COMMAND_TGGETINITIATORCOMMAND (0x88)
#define PN532_COMMAND_TGRESPONSETOINITIATOR (0x90)
#define PN532_COMMAND_TGGETTARGETSTATUS (0x8A)
#define PN532_RESPONSE_INDATAEXCHANGE (0x41)
#define PN532_RESPONSE_INLISTPASSIVETARGET (0x4B)
#define PN532_WAKEUP (0x55)
#define PN532_SPI_STATREAD (0x02)
#define PN532_SPI_DATAWRITE (0x01)
#define PN532_SPI_DATAREAD (0x03)
#define PN532_SPI_READY (0x01)
#define PN532_I2C_ADDRESS (0x48 >> 1)
#define PN532_I2C_READBIT (0x01)
#define PN532_I2C_BUSY (0x00)
#define PN532_I2C_READY (0x01)
#define PN532_I2C_READYTIMEOUT (20)
#define PN532_MIFARE_ISO14443A (0x00)
// Mifare Commands
#define MIFARE_CMD_AUTH_A (0x60)
#define MIFARE_CMD_AUTH_B (0x61)
#define MIFARE_CMD_READ (0x30)
#define MIFARE_CMD_WRITE (0xA0)
#define MIFARE_CMD_TRANSFER (0xB0)
#define MIFARE_CMD_DECREMENT (0xC0)
#define MIFARE_CMD_INCREMENT (0xC1)
#define MIFARE_CMD_STORE (0xC2)
#define MIFARE_ULTRALIGHT_CMD_WRITE (0xA2)
// Prefixes for NDEF Records (to identify record type)
#define NDEF_URIPREFIX_NONE (0x00)
#define NDEF_URIPREFIX_HTTP_WWWDOT (0x01)
#define NDEF_URIPREFIX_HTTPS_WWWDOT (0x02)
#define NDEF_URIPREFIX_HTTP (0x03)
#define NDEF_URIPREFIX_HTTPS (0x04)
#define NDEF_URIPREFIX_TEL (0x05)
#define NDEF_URIPREFIX_MAILTO (0x06)
#define NDEF_URIPREFIX_FTP_ANONAT (0x07)
#define NDEF_URIPREFIX_FTP_FTPDOT (0x08)
#define NDEF_URIPREFIX_FTPS (0x09)
#define NDEF_URIPREFIX_SFTP (0x0A)
#define NDEF_URIPREFIX_SMB (0x0B)
#define NDEF_URIPREFIX_NFS (0x0C)
#define NDEF_URIPREFIX_FTP (0x0D)
#define NDEF_URIPREFIX_DAV (0x0E)
#define NDEF_URIPREFIX_NEWS (0x0F)
#define NDEF_URIPREFIX_TELNET (0x10)
#define NDEF_URIPREFIX_IMAP (0x11)
#define NDEF_URIPREFIX_RTSP (0x12)
#define NDEF_URIPREFIX_URN (0x13)
#define NDEF_URIPREFIX_POP (0x14)
#define NDEF_URIPREFIX_SIP (0x15)
#define NDEF_URIPREFIX_SIPS (0x16)
#define NDEF_URIPREFIX_TFTP (0x17)
#define NDEF_URIPREFIX_BTSPP (0x18)
#define NDEF_URIPREFIX_BTL2CAP (0x19)
#define NDEF_URIPREFIX_BTGOEP (0x1A)
#define NDEF_URIPREFIX_TCPOBEX (0x1B)
#define NDEF_URIPREFIX_IRDAOBEX (0x1C)
#define NDEF_URIPREFIX_FILE (0x1D)
#define NDEF_URIPREFIX_URN_EPC_ID (0x1E)
#define NDEF_URIPREFIX_URN_EPC_TAG (0x1F)
#define NDEF_URIPREFIX_URN_EPC_PAT (0x20)
#define NDEF_URIPREFIX_URN_EPC_RAW (0x21)
#define NDEF_URIPREFIX_URN_EPC (0x22)
#define NDEF_URIPREFIX_URN_NFC (0x23)
#define PN532_GPIO_VALIDATIONBIT (0x80)
#define PN532_GPIO_P30 (0)
#define PN532_GPIO_P31 (1)
#define PN532_GPIO_P32 (2)
#define PN532_GPIO_P33 (3)
#define PN532_GPIO_P34 (4)
#define PN532_GPIO_P35 (5)
class Adafruit_PN532
{
public:
Adafruit_PN532(uint8_t irq, uint8_t reset); // Hardware I2C
void begin(void);
// Generic PN532 functions
bool SAMConfig(void);
uint32_t getFirmwareVersion(void);
bool sendCommandCheckAck(uint8_t *cmd, uint8_t cmdlen,
uint16_t timeout = 100);
bool writeGPIO(uint8_t pinstate);
uint8_t readGPIO(void);
bool setPassiveActivationRetries(uint8_t maxRetries);
// ISO14443A functions
bool readPassiveTargetID(
uint8_t cardbaudrate, uint8_t *uid, uint8_t *uidLength,
uint16_t timeout = 0); // timeout 0 means no timeout - will block forever.
bool startPassiveTargetIDDetection(uint8_t cardbaudrate);
bool readDetectedPassiveTargetID(uint8_t *uid, uint8_t *uidLength);
bool inDataExchange(uint8_t *send, uint8_t sendLength, uint8_t *response,
uint8_t *responseLength);
bool inListPassiveTarget();
uint8_t AsTarget();
uint8_t getDataTarget(uint8_t *cmd, uint8_t *cmdlen);
uint8_t setDataTarget(uint8_t *cmd, uint8_t cmdlen);
// Mifare Classic functions
bool mifareclassic_IsFirstBlock(uint32_t uiBlock);
bool mifareclassic_IsTrailerBlock(uint32_t uiBlock);
uint8_t mifareclassic_AuthenticateBlock(uint8_t *uid, uint8_t uidLen,
uint32_t blockNumber,
uint8_t keyNumber, uint8_t *keyData);
uint8_t mifareclassic_ReadDataBlock(uint8_t blockNumber, uint8_t *data);
uint8_t mifareclassic_WriteDataBlock(uint8_t blockNumber, uint8_t *data);
uint8_t mifareclassic_FormatNDEF(void);
uint8_t mifareclassic_WriteNDEFURI(uint8_t sectorNumber,
uint8_t uriIdentifier, const char *url);
// Mifare Ultralight functions
uint8_t mifareultralight_ReadPage(uint8_t page, uint8_t *buffer);
uint8_t mifareultralight_WritePage(uint8_t page, uint8_t *data);
// NTAG2xx functions
uint8_t ntag2xx_ReadPage(uint8_t page, uint8_t *buffer);
uint8_t ntag2xx_WritePage(uint8_t page, uint8_t *data);
uint8_t ntag2xx_WriteNDEFURI(uint8_t uriIdentifier, char *url,
uint8_t dataLen);
// Help functions to display formatted text
static void PrintHex(const byte *data, const uint32_t numBytes);
static void PrintHexChar(const byte *pbtData, const uint32_t numBytes);
typedef void (*readBytesCall_t)(uint8_t devAddress, uint8_t *data, uint16_t len) ;
typedef void (*writeBytesCall_t)(uint8_t devAddress, uint8_t regAddress, uint8_t *data, uint16_t len) ;
void setI2CRead(readBytesCall_t cb);
void setI2CWrite(writeBytesCall_t cb);
private:
int8_t _irq = -1, _reset = -1;
int8_t _uid[7]; // ISO14443A uid
int8_t _uidLen; // uid len
int8_t _key[6]; // Mifare Classic key
int8_t _inListedTag; // Tg number of inlisted tag.
// Low level communication functions that handle both SPI and I2C.
void readdata(uint8_t *buff, uint8_t n);
void writecommand(uint8_t *cmd, uint8_t cmdlen);
bool isready();
bool waitready(uint16_t timeout);
bool readack();
readBytesCall_t _readCallBack;
writeBytesCall_t _writeCallBack;
};
#endif

View File

@@ -0,0 +1,87 @@
# Adafruit-PN532 [![Build Status](https://github.com/adafruit/Adafruit-PN532/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit-PN532/actions)
This is a library for the Adafruit PN532 NFC/RFID breakout boards
This library works with the Adafruit NFC breakout
* https://www.adafruit.com/products/364
Check out the links above for our tutorials and wiring diagrams
These chips use I2C or SPI to communicate.
<!-- START COMPATIBILITY TABLE -->
## Compatibility
MCU | Tested Works | Doesn't Work | Not Tested | Notes
------------------ | :----------: | :----------: | :---------: | -----
Atmega328 @ 16MHz | X | | | SPI &amp; I2C Works
Atmega328 @ 12MHz | X | | | SPI &amp; I2C Works
Atmega32u4 @ 16MHz | X | | | Follow instructions at https://learn.adafruit.com/adafruit-pn532-rfid-nfc/shield-wiring#using-with-the-arduino-leonardo-and-yun to move pin 2.
Atmega32u4 @ 8MHz | X | | | SPI &amp; I2C Works
ESP8266 | | X | | SPI only, I2C clock stretching not supported
ESP32 | X | | | SPI works; I2C works using IRQ and without sharing the I2C bus.
Atmega2560 @ 16MHz | X | | | SPI &amp; I2C Works
ATSAM3X8E | X | | | SPI &amp; I2C Works
ATSAM21D | | X | | SPI only, I2C clock stretching not supported. Use programming port.
ATtiny85 @ 16MHz | | | X |
ATtiny85 @ 8MHz | | | X |
Intel Curie @ 32MHz | | | X |
STM32F2 | | | X |
* ATmega328 @ 16MHz : Arduino UNO, Adafruit Pro Trinket 5V, Adafruit Metro 328, Adafruit Metro Mini
* ATmega328 @ 12MHz : Adafruit Pro Trinket 3V
* ATmega32u4 @ 16MHz : Arduino Leonardo, Arduino Micro, Arduino Yun, Teensy 2.0
* ATmega32u4 @ 8MHz : Adafruit Flora, Bluefruit Micro
* ESP8266 : Adafruit Huzzah
* ESP32 : WROOM
* ATmega2560 @ 16MHz : Arduino Mega
* ATSAM3X8E : Arduino Due
* ATSAM21D : Arduino Zero, M0 Pro
* ATtiny85 @ 16MHz : Adafruit Trinket 5V
* ATtiny85 @ 8MHz : Adafruit Gemma, Arduino Gemma, Adafruit Trinket 3V
<!-- END COMPATIBILITY TABLE -->
# Dependencies
* [Adafruit_BusIO](https://github.com/adafruit/Adafruit_BusIO)
# Contributing
Contributions are welcome! Please read our [Code of Conduct](https://github.com/adafruit/Adafruit-PN532/blob/master/CODE_OF_CONDUCT.md>)
before contributing to help this project stay welcoming.
## Documentation and doxygen
Documentation is produced by doxygen. Contributions should include documentation for any new code added.
Some examples of how to use doxygen can be found in these guide pages:
https://learn.adafruit.com/the-well-automated-arduino-library/doxygen
https://learn.adafruit.com/the-well-automated-arduino-library/doxygen-tips
## Formatting and clang-format
This library uses [`clang-format`](https://releases.llvm.org/download.html) to standardize the formatting of `.cpp` and `.h` files.
Contributions should be formatted using `clang-format`:
The `-i` flag will make the changes to the file.
```bash
clang-format -i *.cpp *.h
```
If you prefer to make the changes yourself, running `clang-format` without the `-i` flag will print out a formatted version of the file. You can save this to a file and diff it against the original to see the changes.
Note that the formatting output by `clang-format` is what the automated formatting checker will expect. Any diffs from this formatting will result in a failed build until they are addressed. Using the `-i` flag is highly recommended.
### clang-format resources
* [Binary builds and source available on the LLVM downloads page](https://releases.llvm.org/download.html)
* [Documentation and IDE integration](https://clang.llvm.org/docs/ClangFormat.html)
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada & Kevin Townsend for Adafruit Industries.
BSD license, check license.txt for more information
All text above must be included in any redistribution
To install, use the Arduino Library Manager and search for "Adafruit PN532" and install the library. Adafruit BusIO library is also required

View File

@@ -0,0 +1,10 @@
name=Adafruit PN532
version=1.2.2
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=Arduino library for SPI and I2C access to the PN532 RFID/Near Field Communication chip
paragraph=Arduino library for SPI and I2C access to the PN532 RFID/Near Field Communication chip
category=Communication
url=https://github.com/adafruit/Adafruit-PN532
architectures=*
depends=Adafruit BusIO

View File

@@ -0,0 +1,26 @@
Software License Agreement (BSD License)
Copyright (c) 2012, Adafruit Industries
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holders nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.