Skip to content

Commit 59f5362

Browse files
committed
Merge branch 'develop'
2 parents 864e58d + 9fe45b7 commit 59f5362

30 files changed

Lines changed: 482 additions & 493 deletions

File tree

examples/UnitUnified/NFCA/Detect/Detect.ino

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
This example is shared with M5Unit-RFID
1010
*/
1111
// *************************************************************
12-
// Choose one define symbol to match the unit you are using
12+
// Choose ONE define symbol to match the unit/board you are using
1313
// *************************************************************
14-
#if !defined(USING_UNIT_NFC) && !defined(USING_CAP_CC1101) && !defined(USING_UNIT_RFID2)
15-
// For UnitNFC
14+
#if !defined(USING_UNIT_NFC) && !defined(USING_CAP_CC1101) && !defined(USING_UNIT_RFID2) && \
15+
!defined(USING_M5DIAL_BUILTIN_WS1850S)
16+
// For UnitNFC (ST25R3916, I2C)
1617
// #define USING_UNIT_NFC
17-
// For CapNFC
18+
// For CapCC1101NFC (ST25R3916, SPI)
1819
// #define USING_CAP_CC1101
19-
// For UnitRFID2
20+
// For UnitRFID2 (WS1850S external, I2C GROVE)
2021
// #define USING_UNIT_RFID2
22+
// For M5Dial Builtin WS1850S (internal I2C)
23+
// #define USING_M5DIAL_BUILTIN_WS1850S
2124
#endif
2225
#include "main/Detect.cpp"

examples/UnitUnified/NFCA/Detect/main/Detect.cpp

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,24 @@
1313
#include <M5UnitUnifiedNFC.h>
1414
#include <M5Utility.h>
1515
#include <Wire.h>
16-
#include <M5HAL.hpp> // For NessoN1
1716
#include <vector>
1817

1918
// *************************************************************
20-
// Choose one define symbol to match the unit you are using
19+
// Choose ONE define symbol to match the unit/board you are using
2120
// *************************************************************
22-
#if !defined(USING_UNIT_NFC) && !defined(USING_CAP_CC1101) && !defined(USING_UNIT_RFID2)
23-
// For UnitNFC
21+
#if !defined(USING_UNIT_NFC) && !defined(USING_CAP_CC1101) && !defined(USING_UNIT_RFID2) && \
22+
!defined(USING_M5DIAL_BUILTIN_WS1850S)
23+
// For UnitNFC (ST25R3916, I2C)
2424
// #define USING_UNIT_NFC
25-
// For CapNFC
25+
// For CapCC1101NFC (ST25R3916, SPI)
2626
// #define USING_CAP_CC1101
27-
// For UnitRFID2
27+
// For UnitRFID2 (WS1850S external, I2C GROVE)
2828
// #define USING_UNIT_RFID2
29+
// For M5Dial Builtin WS1850S (internal I2C)
30+
// #define USING_M5DIAL_BUILTIN_WS1850S
2931
#endif
3032

31-
#if defined(USING_UNIT_RFID2)
33+
#if defined(USING_UNIT_RFID2) || defined(USING_M5DIAL_BUILTIN_WS1850S)
3234
#include <M5UnitUnifiedRFID.h>
3335
#endif
3436

@@ -46,9 +48,12 @@ m5::unit::UnitNFC unit{}; // I2C
4648
m5::unit::CapCC1101NFC unit{}; // CapCC1101 (SPI)
4749
#elif defined(USING_UNIT_RFID2)
4850
#pragma message "Choose UnitRFID2"
49-
m5::unit::UnitRFID2 unit{}; // UnitRFID2 (M5Unit-RFID)
51+
m5::unit::UnitRFID2 unit{}; // UnitRFID2 external (M5Unit-RFID, GROVE)
52+
#elif defined(USING_M5DIAL_BUILTIN_WS1850S)
53+
#pragma message "Choose UnitRFID2 (M5Dial Builtin)"
54+
m5::unit::UnitRFID2 unit{}; // M5Dial builtin WS1850S (internal I2C)
5055
#else
51-
#error Choose unit please!
56+
#error Choose ONE: USING_UNIT_NFC / USING_CAP_CC1101 / USING_UNIT_RFID2 / USING_M5DIAL_BUILTIN_WS1850S
5257
#endif
5358
m5::nfc::NFCLayerA nfc_a{unit};
5459
} // namespace
@@ -63,25 +68,26 @@ void setup()
6368
lcd.setRotation(1);
6469
}
6570

66-
#if defined(USING_UNIT_NFC) || defined(USING_UNIT_RFID2)
67-
// NessoN1: Arduino Wire (I2C_NUM_0) cannot be used for GROVE port.
68-
// Wire is used by M5Unified In_I2C for internal devices.
69-
// Reconfiguring Wire to GROVE pins breaks In_I2C.
70-
// Solution: Use SoftwareI2C via M5HAL (bit-banging) for the GROVE port.
71-
// NanoC6: Wire.begin() on GROVE pins conflicts with Ex_I2C on the same I2C_NUM_0.
72-
// Solution: Use M5.Ex_I2C directly instead of Arduino Wire.
73-
auto board = M5.getBoard();
7471
bool unit_ready{};
72+
7573
#if defined(USING_M5DIAL_BUILTIN_WS1850S)
74+
// M5Dial builtin WS1850S: small loop antenna; reduce RxGain to 33dB to mitigate
75+
// reflection interference (default 48dB causes unstable WUPA on Builtin).
76+
{
77+
auto cfg = unit.config();
78+
cfg.receiver_gain = m5::unit::mfrc522::ReceiverGain::dB33;
79+
unit.config(cfg);
80+
}
7681
// M5Dial builtin WS1850S on In_I2C (G12/G11, shared with RTC8563)
7782
M5_LOGI("Using M5.In_I2C for builtin WS1850S");
7883
unit_ready = Units.add(unit, M5.In_I2C) && Units.begin();
79-
#else
80-
// NessoN1: port_b (GROVE) uses SoftwareI2C (M5HAL Bus) which causes I2C register
81-
// polling latency too high for MFRC522/WS1850S RF timing requirements.
82-
// Use QWIIC (port_a) with Wire instead. (Requires QWIIC-GROVE conversion cable)
83-
if (board == m5::board_t::board_M5NanoC6) {
84-
// NanoC6: Use M5.Ex_I2C (m5::I2C_Class, not Arduino Wire)
84+
85+
#elif defined(USING_UNIT_NFC) || defined(USING_UNIT_RFID2)
86+
// External I2C unit (GROVE port).
87+
// NessoN1: Arduino Wire (I2C_NUM_0) cannot be used for GROVE port (used by In_I2C internals).
88+
// Use QWIIC (port_a) with Wire. (Requires QWIIC-GROVE conversion cable)
89+
// NanoC6: Wire.begin() on GROVE pins conflicts with Ex_I2C on I2C_NUM_0; use M5.Ex_I2C directly.
90+
if (M5.getBoard() == m5::board_t::board_M5NanoC6) {
8591
M5_LOGI("Using M5.Ex_I2C");
8692
unit_ready = Units.add(unit, M5.Ex_I2C) && Units.begin();
8793
} else {
@@ -92,14 +98,7 @@ void setup()
9298
Wire.begin(pin_num_sda, pin_num_scl, 400 * 1000U);
9399
unit_ready = Units.add(unit, Wire) && Units.begin();
94100
}
95-
#endif // USING_M5DIAL_BUILTIN_WS1850S
96-
if (!unit_ready) {
97-
M5_LOGE("Failed to begin");
98-
lcd.fillScreen(TFT_RED);
99-
while (true) {
100-
m5::utility::delay(10000);
101-
}
102-
}
101+
103102
#elif defined(USING_CAP_CC1101)
104103
if (!SPI.bus()) {
105104
auto spi_sclk = M5.getPin(m5::pin_name_t::sd_spi_sclk);
@@ -108,16 +107,17 @@ void setup()
108107
M5_LOGI("getPin: %d,%d,%d", spi_sclk, spi_mosi, spi_miso);
109108
SPI.begin(spi_sclk, spi_miso, spi_mosi /* SS is shared SD, CC1101, ST25R3916 */);
110109
}
111-
112110
SPISettings settings = {10000000, MSBFIRST, SPI_MODE1};
113-
if (!Units.add(unit, SPI, settings) || !Units.begin()) {
111+
unit_ready = Units.add(unit, SPI, settings) && Units.begin();
112+
#endif
113+
114+
if (!unit_ready) {
114115
M5_LOGE("Failed to begin");
115116
lcd.fillScreen(TFT_RED);
116117
while (true) {
117118
m5::utility::delay(10000);
118119
}
119120
}
120-
#endif
121121
M5_LOGI("M5UnitUnified initialized");
122122
M5_LOGI("%s", Units.debugInfo().c_str());
123123

examples/UnitUnified/NFCA/Dump/Dump.ino

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
This example is shared with M5Unit-RFID
1010
*/
1111
// *************************************************************
12-
// Choose one define symbol to match the unit you are using
12+
// Choose ONE define symbol to match the unit/board you are using
1313
// *************************************************************
14-
#if !defined(USING_UNIT_NFC) && !defined(USING_CAP_CC1101) && !defined(USING_UNIT_RFID2)
15-
// For UnitNFC
14+
#if !defined(USING_UNIT_NFC) && !defined(USING_CAP_CC1101) && !defined(USING_UNIT_RFID2) && \
15+
!defined(USING_M5DIAL_BUILTIN_WS1850S)
16+
// For UnitNFC (ST25R3916, I2C)
1617
// #define USING_UNIT_NFC
17-
// For CapNFC
18+
// For CapCC1101NFC (ST25R3916, SPI)
1819
// #define USING_CAP_CC1101
19-
// For UnitRFID2
20+
// For UnitRFID2 (WS1850S external, I2C GROVE)
2021
// #define USING_UNIT_RFID2
22+
// For M5Dial Builtin WS1850S (internal I2C)
23+
// #define USING_M5DIAL_BUILTIN_WS1850S
2124
#endif
2225
#include "main/Dump.cpp"

examples/UnitUnified/NFCA/Dump/main/Dump.cpp

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,24 @@
1313
#include <M5UnitUnifiedNFC.h>
1414
#include <M5Utility.h>
1515
#include <Wire.h>
16-
#include <M5HAL.hpp> // For NessoN1
1716
#include <vector>
1817

1918
// *************************************************************
20-
// Choose one define symbol to match the unit you are using
19+
// Choose ONE define symbol to match the unit/board you are using
2120
// *************************************************************
22-
#if !defined(USING_UNIT_NFC) && !defined(USING_CAP_CC1101) && !defined(USING_UNIT_RFID2)
23-
// For UnitNFC
21+
#if !defined(USING_UNIT_NFC) && !defined(USING_CAP_CC1101) && !defined(USING_UNIT_RFID2) && \
22+
!defined(USING_M5DIAL_BUILTIN_WS1850S)
23+
// For UnitNFC (ST25R3916, I2C)
2424
// #define USING_UNIT_NFC
25-
// For CapNFC
25+
// For CapCC1101NFC (ST25R3916, SPI)
2626
// #define USING_CAP_CC1101
27-
// For UnitRFID2
27+
// For UnitRFID2 (WS1850S external, I2C GROVE)
2828
// #define USING_UNIT_RFID2
29+
// For M5Dial Builtin WS1850S (internal I2C)
30+
// #define USING_M5DIAL_BUILTIN_WS1850S
2931
#endif
3032

31-
#if defined(USING_UNIT_RFID2)
33+
#if defined(USING_UNIT_RFID2) || defined(USING_M5DIAL_BUILTIN_WS1850S)
3234
#include <M5UnitUnifiedRFID.h>
3335
#endif
3436

@@ -48,9 +50,12 @@ m5::unit::UnitNFC unit{}; // I2C
4850
m5::unit::CapCC1101NFC unit{}; // CapCC1101 (SPI)
4951
#elif defined(USING_UNIT_RFID2)
5052
#pragma message "Choose UnitRFID2"
51-
m5::unit::UnitRFID2 unit{}; // UnitRFID2 (M5Unit-RFID)
53+
m5::unit::UnitRFID2 unit{}; // UnitRFID2 external (M5Unit-RFID, GROVE)
54+
#elif defined(USING_M5DIAL_BUILTIN_WS1850S)
55+
#pragma message "Choose UnitRFID2 (M5Dial Builtin)"
56+
m5::unit::UnitRFID2 unit{}; // M5Dial builtin WS1850S (internal I2C)
5257
#else
53-
#error Choose unit please!
58+
#error Choose ONE: USING_UNIT_NFC / USING_CAP_CC1101 / USING_UNIT_RFID2 / USING_M5DIAL_BUILTIN_WS1850S
5459
#endif
5560
m5::nfc::NFCLayerA nfc_a{unit};
5661

@@ -69,18 +74,26 @@ void setup()
6974
lcd.setRotation(1);
7075
}
7176

72-
#if defined(USING_UNIT_NFC) || defined(USING_UNIT_RFID2)
73-
auto board = M5.getBoard();
7477
bool unit_ready{};
78+
7579
#if defined(USING_M5DIAL_BUILTIN_WS1850S)
80+
// M5Dial builtin WS1850S: small loop antenna; reduce RxGain to 33dB to mitigate
81+
// reflection interference (default 48dB causes unstable WUPA on Builtin).
82+
{
83+
auto cfg = unit.config();
84+
cfg.receiver_gain = m5::unit::mfrc522::ReceiverGain::dB33;
85+
unit.config(cfg);
86+
}
7687
// M5Dial builtin WS1850S on In_I2C (G12/G11, shared with RTC8563)
7788
M5_LOGI("Using M5.In_I2C for builtin WS1850S");
7889
unit_ready = Units.add(unit, M5.In_I2C) && Units.begin();
79-
#else
80-
// NessoN1: port_b (GROVE) uses SoftwareI2C (M5HAL Bus) which causes I2C register
81-
// polling latency too high for MFRC522/WS1850S RF timing requirements.
82-
// Use QWIIC (port_a) with Wire instead. (Requires QWIIC-GROVE conversion cable)
83-
if (board == m5::board_t::board_M5NanoC6) {
90+
91+
#elif defined(USING_UNIT_NFC) || defined(USING_UNIT_RFID2)
92+
// External I2C unit (GROVE port).
93+
// NessoN1: Arduino Wire (I2C_NUM_0) cannot be used for GROVE port (used by In_I2C internals).
94+
// Use QWIIC (port_a) with Wire. (Requires QWIIC-GROVE conversion cable)
95+
// NanoC6: Wire.begin() on GROVE pins conflicts with Ex_I2C on I2C_NUM_0; use M5.Ex_I2C directly.
96+
if (M5.getBoard() == m5::board_t::board_M5NanoC6) {
8497
M5_LOGI("Using M5.Ex_I2C");
8598
unit_ready = Units.add(unit, M5.Ex_I2C) && Units.begin();
8699
} else {
@@ -91,14 +104,7 @@ void setup()
91104
Wire.begin(pin_num_sda, pin_num_scl, 400 * 1000U);
92105
unit_ready = Units.add(unit, Wire) && Units.begin();
93106
}
94-
#endif // USING_M5DIAL_BUILTIN_WS1850S
95-
if (!unit_ready) {
96-
M5_LOGE("Failed to begin");
97-
lcd.fillScreen(TFT_RED);
98-
while (true) {
99-
m5::utility::delay(10000);
100-
}
101-
}
107+
102108
#elif defined(USING_CAP_CC1101)
103109
if (!SPI.bus()) {
104110
auto spi_sclk = M5.getPin(m5::pin_name_t::sd_spi_sclk);
@@ -107,16 +113,17 @@ void setup()
107113
M5_LOGI("getPin: %d,%d,%d", spi_sclk, spi_mosi, spi_miso);
108114
SPI.begin(spi_sclk, spi_miso, spi_mosi /* SS is shared SD, CC1101, ST25R3916 */);
109115
}
110-
111116
SPISettings settings = {10000000, MSBFIRST, SPI_MODE1};
112-
if (!Units.add(unit, SPI, settings) || !Units.begin()) {
117+
unit_ready = Units.add(unit, SPI, settings) && Units.begin();
118+
#endif
119+
120+
if (!unit_ready) {
113121
M5_LOGE("Failed to begin");
114122
lcd.fillScreen(TFT_RED);
115123
while (true) {
116124
m5::utility::delay(10000);
117125
}
118126
}
119-
#endif
120127
M5_LOGI("M5UnitUnified initialized");
121128
M5_LOGI("%s", Units.debugInfo().c_str());
122129

examples/UnitUnified/NFCA/Emulation/Emulation.ino

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
NFC-A Emulation mode
99
*/
1010
// *************************************************************
11-
// Choose one define symbol to match the unit you are using
11+
// Choose ONE define symbol to match the unit you are using
12+
// NOTE: Emulation is supported ONLY on UnitNFC (ST25R3916) and CapCC1101NFC (ST25R3916).
13+
// UnitRFID2 (WS1850S) and M5Dial Builtin (WS1850S) do NOT support emulation.
1214
// *************************************************************
1315
#if !defined(USING_UNIT_NFC) && !defined(USING_CAP_CC1101)
14-
// For UnitNFC
16+
// For UnitNFC (ST25R3916, I2C)
1517
// #define USING_UNIT_NFC
16-
// For CapNFC
18+
// For CapCC1101NFC (ST25R3916, SPI)
1719
// #define USING_CAP_CC1101
1820
#endif
1921
#include "main/Emulation.cpp"

examples/UnitUnified/NFCA/Emulation/main/Emulation.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,21 @@
1212
#include <M5UnitUnifiedNFC.h>
1313
#include <M5Utility.h>
1414
#include <Wire.h>
15-
#include <M5HAL.hpp> // For NessoN1
1615
#include <vector>
1716

1817
// *************************************************************
19-
// Choose one define symbol to match the unit you are using
18+
// Choose ONE define symbol to match the unit you are using
19+
// NOTE: Emulation is supported ONLY on UnitNFC (ST25R3916) and CapCC1101NFC (ST25R3916).
20+
// UnitRFID2 (WS1850S) and M5Dial Builtin (WS1850S) do NOT support emulation.
2021
// *************************************************************
2122
#if !defined(USING_UNIT_NFC) && !defined(USING_CAP_CC1101)
22-
// For UnitNFC
23+
// For UnitNFC (ST25R3916, I2C)
2324
// #define USING_UNIT_NFC
24-
// For CapNFC
25+
// For CapCC1101NFC (ST25R3916, SPI)
2526
// #define USING_CAP_CC1101
2627
#endif
27-
#if defined(USING_UNIT_RFID2)
28-
#error UnitRFID2 does NOT support emulation
28+
#if defined(USING_UNIT_RFID2) || defined(USING_M5DIAL_BUILTIN_WS1850S)
29+
#error Emulation is NOT supported on UnitRFID2 / M5Dial Builtin (WS1850S). Use UnitNFC or CapCC1101NFC.
2930
#endif
3031

3132
using namespace m5::nfc;
@@ -177,7 +178,7 @@ void setup()
177178
auto board = M5.getBoard();
178179
bool unit_ready{};
179180
// NessoN1: port_b (GROVE) uses SoftwareI2C (M5HAL Bus) which causes I2C register
180-
// polling latency too high for MFRC522/WS1850S RF timing requirements.
181+
// polling latency too high for ST25R3916 RF timing requirements.
181182
// Use QWIIC (port_a) with Wire instead. (Requires QWIIC-GROVE conversion cable)
182183
if (board == m5::board_t::board_M5NanoC6) {
183184
M5_LOGI("Using M5.Ex_I2C");

examples/UnitUnified/NFCA/NDEF/NDEF.ino

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
This example is shared with M5Unit-RFID
1010
*/
1111
// *************************************************************
12-
// Choose one define symbol to match the unit you are using
12+
// Choose ONE define symbol to match the unit/board you are using
1313
// *************************************************************
14-
#if !defined(USING_UNIT_NFC) && !defined(USING_CAP_CC1101) && !defined(USING_UNIT_RFID2)
15-
// For UnitNFC
14+
#if !defined(USING_UNIT_NFC) && !defined(USING_CAP_CC1101) && !defined(USING_UNIT_RFID2) && \
15+
!defined(USING_M5DIAL_BUILTIN_WS1850S)
16+
// For UnitNFC (ST25R3916, I2C)
1617
// #define USING_UNIT_NFC
17-
// For CapNFC
18+
// For CapCC1101NFC (ST25R3916, SPI)
1819
// #define USING_CAP_CC1101
19-
// For UnitRFID2
20+
// For UnitRFID2 (WS1850S external, I2C GROVE)
2021
// #define USING_UNIT_RFID2
22+
// For M5Dial Builtin WS1850S (internal I2C)
23+
// #define USING_M5DIAL_BUILTIN_WS1850S
2124
#endif
2225
#include "main/NDEF.cpp"

0 commit comments

Comments
 (0)