variant.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #ifndef _SEEED_XIAO_NRF52840_H_
  2. #define _SEEED_XIAO_NRF52840_H_
  3. /** Master clock frequency */
  4. #define VARIANT_MCK (64000000ul)
  5. #define USE_LFXO // Board uses 32khz crystal for LF
  6. //#define USE_LFRC // Board uses RC for LF
  7. /*----------------------------------------------------------------------------
  8. * Headers
  9. *----------------------------------------------------------------------------*/
  10. #include "WVariant.h"
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif // __cplusplus
  15. #define PINS_COUNT (33)
  16. #define NUM_DIGITAL_PINS (33)
  17. #define NUM_ANALOG_INPUTS (8)
  18. #define NUM_ANALOG_OUTPUTS (0)
  19. // LEDs
  20. #define PIN_LED (LED_RED)
  21. #define LED_PWR (PINS_COUNT)
  22. #define PIN_NEOPIXEL (PINS_COUNT)
  23. #define NEOPIXEL_NUM (0)
  24. #define LED_BUILTIN (PIN_LED)
  25. #define LED_RED (11)
  26. #define LED_GREEN (13)
  27. #define LED_BLUE (12)
  28. #define PIN_STATUS_LED (LED_BLUE)
  29. #define LED_STATE_ON (0) // State when LED is on
  30. // Buttons
  31. #define PIN_BUTTON1 (0)
  32. // Digital PINs
  33. static const uint8_t D0 = 0 ;
  34. static const uint8_t D1 = 1 ;
  35. static const uint8_t D2 = 2 ;
  36. static const uint8_t D3 = 3 ;
  37. static const uint8_t D4 = 4 ;
  38. static const uint8_t D5 = 5 ;
  39. static const uint8_t D6 = 6 ;
  40. static const uint8_t D7 = 7 ;
  41. static const uint8_t D8 = 8 ;
  42. static const uint8_t D9 = 9 ;
  43. static const uint8_t D10 = 10;
  44. #define VBAT_ENABLE (14) // Output LOW to enable reading of the BAT voltage.
  45. // https://wiki.seeedstudio.com/XIAO_BLE#q3-what-are-the-considerations-when-using-xiao-nrf52840-sense-for-battery-charging
  46. #define PIN_CHARGING_CURRENT (22) // Battery Charging current
  47. // https://wiki.seeedstudio.com/XIAO_BLE#battery-charging-current
  48. // Analog pins
  49. #define PIN_A0 (0)
  50. #define PIN_A1 (1)
  51. #define PIN_A2 (2)
  52. #define PIN_A3 (3)
  53. #define PIN_A4 (4)
  54. #define PIN_A5 (5)
  55. #define PIN_VBAT (32) // Read the BAT voltage.
  56. // https://wiki.seeedstudio.com/XIAO_BLE#q3-what-are-the-considerations-when-using-xiao-nrf52840-sense-for-battery-charging
  57. #define BAT_NOT_CHARGING (23) // LOW when charging
  58. #define AREF_VOLTAGE (3.0)
  59. #define ADC_MULTIPLIER (3.0F) // 1M, 512k divider bridge
  60. // Power management boot protection threshold (millivolts)
  61. // Set to 0 to disable boot protection
  62. #define PWRMGT_VOLTAGE_BOOTLOCK 3300 // Won't boot below this voltage
  63. // LPCOMP wake configuration (voltage recovery from SYSTEMOFF)
  64. #define PWRMGT_LPCOMP_AIN 7 // AIN7 = P0.31 = PIN_VBAT
  65. // IMPORTANT: The XIAO exposes battery via a resistor divider (ADC_MULTIPLIER = 3.0).
  66. // LPCOMP measures the divided voltage, not the battery voltage directly.
  67. // Vpin = VDD * (REFSEL fraction), and VBAT ≈ Vpin * ADC_MULTIPLIER.
  68. //
  69. // Using 3/8 VDD gives a wake threshold above the boot protection point:
  70. // - If VDD ≈ 3.0V: VBAT ≈ (3.0 * 3/8) * 3 ≈ 3375mV
  71. // - If VDD ≈ 3.3V: VBAT ≈ (3.3 * 3/8) * 3 ≈ 3712mV
  72. #define PWRMGT_LPCOMP_REFSEL 2 // 3/8 VDD (~3.38-3.71V)
  73. static const uint8_t A0 = PIN_A0;
  74. static const uint8_t A1 = PIN_A1;
  75. static const uint8_t A2 = PIN_A2;
  76. static const uint8_t A3 = PIN_A3;
  77. static const uint8_t A4 = PIN_A4;
  78. static const uint8_t A5 = PIN_A5;
  79. #define ADC_RESOLUTION (12)
  80. // Other pins
  81. #define PIN_NFC1 (30)
  82. #define PIN_NFC2 (31)
  83. // Serial interfaces
  84. #define PIN_SERIAL1_RX (7)
  85. #define PIN_SERIAL1_TX (6)
  86. // SPI Interfaces
  87. #define SPI_INTERFACES_COUNT (2)
  88. #define PIN_SPI_MISO (9)
  89. #define PIN_SPI_MOSI (10)
  90. #define PIN_SPI_SCK (8)
  91. #define PIN_SPI1_MISO (25)
  92. #define PIN_SPI1_MOSI (26)
  93. #define PIN_SPI1_SCK (29)
  94. // Lora SPI is on SPI0
  95. #define P_LORA_SCLK PIN_SPI_SCK
  96. #define P_LORA_MISO PIN_SPI_MISO
  97. #define P_LORA_MOSI PIN_SPI_MOSI
  98. // Wire Interfaces
  99. #define WIRE_INTERFACES_COUNT (1)
  100. // #define PIN_WIRE_SDA (17) // 4 and 5 are used for the sx1262 !
  101. // #define PIN_WIRE_SCL (16) // use WIRE1_SDA
  102. // static const uint8_t SDA = PIN_WIRE_SDA;
  103. // static const uint8_t SCL = PIN_WIRE_SCL;
  104. //#define PIN_WIRE1_SDA (17)
  105. //#define PIN_WIRE1_SCL (16)
  106. #define PIN_LSM6DS3TR_C_POWER (15)
  107. #define PIN_LSM6DS3TR_C_INT1 (18)
  108. // PDM Interfaces
  109. #define PIN_PDM_PWR (19)
  110. #define PIN_PDM_CLK (20)
  111. #define PIN_PDM_DIN (21)
  112. // QSPI Pins
  113. #define PIN_QSPI_SCK (24)
  114. #define PIN_QSPI_CS (25)
  115. #define PIN_QSPI_IO0 (26)
  116. #define PIN_QSPI_IO1 (27)
  117. #define PIN_QSPI_IO2 (28)
  118. #define PIN_QSPI_IO3 (29)
  119. // On-board QSPI Flash
  120. #define EXTERNAL_FLASH_DEVICES (P25Q16H)
  121. #define EXTERNAL_FLASH_USE_QSPI
  122. #ifdef __cplusplus
  123. }
  124. #endif
  125. /*----------------------------------------------------------------------------
  126. * Arduino objects - C++ only
  127. *----------------------------------------------------------------------------*/
  128. #endif