denko 0.13.1 → 0.13.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build_avr.yml +2 -4
  3. data/.github/workflows/build_esp32.yml +2 -3
  4. data/.github/workflows/build_esp8266.yml +2 -3
  5. data/.github/workflows/build_megaavr.yml +2 -4
  6. data/.github/workflows/build_ra4m1.yml +57 -0
  7. data/.github/workflows/build_rp2040.yml +2 -4
  8. data/.github/workflows/build_sam3x.yml +1 -3
  9. data/.github/workflows/build_samd.yml +2 -4
  10. data/CHANGELOG.md +60 -0
  11. data/DEPS_CLI.md +8 -6
  12. data/DEPS_IDE.md +9 -7
  13. data/HARDWARE.md +90 -74
  14. data/README.md +19 -28
  15. data/benchmarks/i2c_ssd1306_refresh.rb +74 -0
  16. data/examples/analog_io/ads1115.rb +57 -0
  17. data/examples/analog_io/ads1118.rb +8 -9
  18. data/examples/analog_io/dac_loopback.rb +6 -4
  19. data/examples/analog_io/input.rb +39 -36
  20. data/examples/connection/tcp.rb +1 -1
  21. data/examples/display/hd44780.rb +3 -3
  22. data/examples/display/ssd1306.rb +1 -1
  23. data/examples/pulse_io/buzzer.rb +40 -0
  24. data/lib/denko/analog_io/ads1115.rb +61 -0
  25. data/lib/denko/analog_io/ads1118.rb +10 -120
  26. data/lib/denko/analog_io/ads111x.rb +123 -0
  27. data/lib/denko/analog_io/output.rb +2 -1
  28. data/lib/denko/analog_io.rb +2 -0
  29. data/lib/denko/behaviors/reader.rb +14 -13
  30. data/lib/denko/behaviors/subcomponents.rb +2 -2
  31. data/lib/denko/board/core.rb +1 -1
  32. data/lib/denko/board/i2c.rb +1 -4
  33. data/lib/denko/board/map.rb +9 -0
  34. data/lib/denko/board/servo.rb +2 -6
  35. data/lib/denko/board.rb +32 -20
  36. data/lib/denko/connection/board_uart.rb +3 -3
  37. data/lib/denko/connection/flow_control.rb +10 -2
  38. data/lib/denko/digital_io/output.rb +1 -1
  39. data/lib/denko/display/hd44780.rb +18 -18
  40. data/lib/denko/led/seven_segment.rb +18 -19
  41. data/lib/denko/message.rb +6 -14
  42. data/lib/denko/pulse_io/ir_transmitter.rb +1 -2
  43. data/lib/denko/version.rb +1 -1
  44. data/lib/denko_cli/packages.rb +7 -1
  45. data/lib/denko_cli/targets.rb +8 -5
  46. data/lib/denko_cli/usage.txt +8 -4
  47. data/src/denko_ethernet.ino +15 -23
  48. data/src/denko_serial.ino +3 -14
  49. data/src/denko_wifi.ino +35 -50
  50. data/src/lib/Denko.cpp +23 -6
  51. data/src/lib/Denko.h +6 -16
  52. data/src/lib/DenkoCoreIO.cpp +3 -3
  53. data/src/lib/DenkoDefines.h +62 -16
  54. data/src/lib/DenkoEEPROM.cpp +9 -1
  55. data/src/lib/DenkoI2C.cpp +11 -9
  56. data/src/lib/DenkoLEDArray.cpp +1 -1
  57. data/target.yml +35 -1
  58. data/test/behaviors/reader_test.rb +8 -1
  59. data/test/board/helper_test.rb +0 -4
  60. data/test/display/hd44780_test.rb +10 -0
  61. data/test/led/seven_segment_test.rb +30 -8
  62. data/test/test_helper.rb +17 -2
  63. data/vendor/board-maps/.gitmodules +3 -0
  64. data/vendor/board-maps/BoardMap.h +40 -12
  65. data/vendor/board-maps/README.md +1 -0
  66. data/vendor/board-maps/lib/header_parser.rb +30 -5
  67. data/vendor/board-maps/run.rb +11 -1
  68. data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_ESP32S3.yml +6 -1
  69. data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_ESP32S3_NOPSRAM.yml +6 -1
  70. data/vendor/board-maps/yaml/ADAFRUIT_FEATHER_ESP32_V2.yml +5 -1
  71. data/vendor/board-maps/yaml/ADAFRUIT_QTPY_ESP32S3_N4R2.yml +20 -0
  72. data/vendor/board-maps/yaml/ADAFRUIT_QTPY_ESP32_PICO.yml +2 -1
  73. data/vendor/board-maps/yaml/ARTRONSHOP_RP2_NANO.yml +32 -0
  74. data/vendor/board-maps/yaml/AVR_CIRCUITPLAY.yml +1 -1
  75. data/vendor/board-maps/yaml/AVR_ESPLORA.yml +1 -1
  76. data/vendor/board-maps/yaml/AVR_INDUSTRIAL101.yml +1 -1
  77. data/vendor/board-maps/yaml/AVR_LEONARDO.yml +1 -1
  78. data/vendor/board-maps/yaml/AVR_LEONARDO_ETH.yml +1 -1
  79. data/vendor/board-maps/yaml/AVR_LILYPAD_USB.yml +1 -1
  80. data/vendor/board-maps/yaml/AVR_LININO_ONE.yml +1 -1
  81. data/vendor/board-maps/yaml/AVR_MICRO.yml +1 -1
  82. data/vendor/board-maps/yaml/AVR_ROBOT_CONTROL.yml +1 -1
  83. data/vendor/board-maps/yaml/AVR_ROBOT_MOTOR.yml +1 -1
  84. data/vendor/board-maps/yaml/AVR_YUN.yml +1 -1
  85. data/vendor/board-maps/yaml/AVR_YUNMINI.yml +1 -1
  86. data/vendor/board-maps/yaml/BPI_LEAF_S3.yml +11 -1
  87. data/vendor/board-maps/yaml/BeeMotionS3.yml +6 -1
  88. data/vendor/board-maps/yaml/Bee_Motion.yml +3 -0
  89. data/vendor/board-maps/yaml/Bee_S3.yml +1 -1
  90. data/vendor/board-maps/yaml/CHALLENGER_2040_WIFI6_BLE_RP2040.yml +42 -0
  91. data/vendor/board-maps/yaml/CYTRON_MAKER_FEATHER_AIOT_S3.yml +4 -1
  92. data/vendor/board-maps/yaml/CoreESP32.yml +5 -1
  93. data/vendor/board-maps/yaml/D1_MINI32.yml +10 -1
  94. data/vendor/board-maps/yaml/DENKY.yml +10 -1
  95. data/vendor/board-maps/yaml/DENKY_PICOV3.yml +10 -1
  96. data/vendor/board-maps/yaml/DENKY_WROOM32.yml +10 -1
  97. data/vendor/board-maps/yaml/DFROBOT_FIREBEETLE_2_ESP32E.yml +6 -1
  98. data/vendor/board-maps/yaml/DPU_ESP32.yml +10 -1
  99. data/vendor/board-maps/yaml/D_Duino_32.yml +9 -1
  100. data/vendor/board-maps/yaml/ESP32S2_DEV.yml +11 -1
  101. data/vendor/board-maps/yaml/ESP32S2_THING_PLUS.yml +11 -1
  102. data/vendor/board-maps/yaml/ESP32S2_USB.yml +11 -1
  103. data/vendor/board-maps/yaml/ESP32_DEV.yml +10 -1
  104. data/vendor/board-maps/yaml/ESP32_DEVKIT_LIPO.yml +10 -1
  105. data/vendor/board-maps/yaml/ESP32_IOT_REDBOARD.yml +10 -1
  106. data/vendor/board-maps/yaml/ESP32_PICO.yml +10 -1
  107. data/vendor/board-maps/yaml/ESP32_S3_BOX.yml +4 -1
  108. data/vendor/board-maps/yaml/ESP32_THING.yml +10 -1
  109. data/vendor/board-maps/yaml/ESP32_THING_PLUS.yml +4 -1
  110. data/vendor/board-maps/yaml/ESP32_THING_PLUS_C.yml +4 -1
  111. data/vendor/board-maps/yaml/ESP32_WROOM_DA.yml +10 -1
  112. data/vendor/board-maps/yaml/ESP32_WROVER_KIT.yml +10 -1
  113. data/vendor/board-maps/yaml/ESPECTRO32.yml +10 -1
  114. data/vendor/board-maps/yaml/ESPea32.yml +10 -1
  115. data/vendor/board-maps/yaml/ESPino32.yml +10 -1
  116. data/vendor/board-maps/yaml/FEATHERS2.yml +11 -1
  117. data/vendor/board-maps/yaml/FEATHERS2NEO.yml +2 -1
  118. data/vendor/board-maps/yaml/FEATHERS3.yml +3 -0
  119. data/vendor/board-maps/yaml/FEATHER_ESP32.yml +5 -1
  120. data/vendor/board-maps/yaml/FRANZININHO_WIFI.yml +11 -1
  121. data/vendor/board-maps/yaml/FRANZININHO_WIFI_MSC.yml +11 -1
  122. data/vendor/board-maps/yaml/FROG_ESP32.yml +10 -1
  123. data/vendor/board-maps/yaml/HEALTHYPI_4.yml +10 -1
  124. data/vendor/board-maps/yaml/HONEYLEMON.yml +10 -1
  125. data/vendor/board-maps/yaml/HORNBILL_ESP32_DEV.yml +10 -1
  126. data/vendor/board-maps/yaml/HORNBILL_ESP32_MINIMA.yml +4 -1
  127. data/vendor/board-maps/yaml/IMBRIOS_LOGSENS_V1P1.yml +5 -1
  128. data/vendor/board-maps/yaml/LILYGO_T_DISPLAY_S3.yml +7 -1
  129. data/vendor/board-maps/yaml/LOLIN32.yml +10 -1
  130. data/vendor/board-maps/yaml/LOLIN32_LITE.yml +10 -1
  131. data/vendor/board-maps/yaml/LOLIN_D32.yml +10 -1
  132. data/vendor/board-maps/yaml/LOLIN_D32_PRO.yml +10 -1
  133. data/vendor/board-maps/yaml/LOLIN_S2_MINI.yml +11 -1
  134. data/vendor/board-maps/yaml/LOLIN_S2_PICO.yml +11 -1
  135. data/vendor/board-maps/yaml/LOLIN_S3.yml +9 -1
  136. data/vendor/board-maps/yaml/LOLIN_S3_MINI.yml +9 -1
  137. data/vendor/board-maps/yaml/LOLIN_S3_PRO.yml +9 -1
  138. data/vendor/board-maps/yaml/LoPy.yml +11 -1
  139. data/vendor/board-maps/yaml/LoPy4.yml +11 -1
  140. data/vendor/board-maps/yaml/MAGTAG29_ESP32S2.yml +11 -1
  141. data/vendor/board-maps/yaml/METRO_ESP32S2.yml +11 -1
  142. data/vendor/board-maps/yaml/MGBOT_IOTIK32A.yml +10 -1
  143. data/vendor/board-maps/yaml/MGBOT_IOTIK32B.yml +10 -1
  144. data/vendor/board-maps/yaml/MH_ET_LIVE_ESP32DEVKIT.yml +10 -1
  145. data/vendor/board-maps/yaml/MH_ET_LIVE_ESP32MINIKIT.yml +10 -1
  146. data/vendor/board-maps/yaml/MICROS2.yml +11 -1
  147. data/vendor/board-maps/yaml/MINIMA.yml +15 -0
  148. data/vendor/board-maps/yaml/NANO32.yml +10 -1
  149. data/vendor/board-maps/yaml/Node32s.yml +10 -1
  150. data/vendor/board-maps/yaml/NodeMCU_32S.yml +10 -1
  151. data/vendor/board-maps/yaml/ONEHORSE_ESP32_DEV.yml +11 -1
  152. data/vendor/board-maps/yaml/PIMORONI_PLASMA2040.yml +29 -0
  153. data/vendor/board-maps/yaml/PORTENTA_C33.yml +28 -0
  154. data/vendor/board-maps/yaml/PROS3.yml +6 -1
  155. data/vendor/board-maps/yaml/PYCOM_GPY.yml +11 -1
  156. data/vendor/board-maps/yaml/Piranha.yml +7 -1
  157. data/vendor/board-maps/yaml/Pocket32.yml +10 -1
  158. data/vendor/board-maps/yaml/QUANTUM.yml +10 -1
  159. data/vendor/board-maps/yaml/REDPILL_ESP32S3.yml +11 -1
  160. data/vendor/board-maps/yaml/RMP.yml +11 -1
  161. data/vendor/board-maps/yaml/SAMD_CIRCUITPLAYGROUND_EXPRESS.yml +0 -1
  162. data/vendor/board-maps/yaml/SAM_DUE.yml +3 -1
  163. data/vendor/board-maps/yaml/SONOFF_DUALR3.yml +10 -1
  164. data/vendor/board-maps/yaml/TAMC_TERMOD_S3.yml +11 -1
  165. data/vendor/board-maps/yaml/TBEAM_USE_RADIO_SX1262.yml +6 -1
  166. data/vendor/board-maps/yaml/TBEAM_USE_RADIO_SX1268.yml +6 -1
  167. data/vendor/board-maps/yaml/TBEAM_USE_RADIO_SX1276.yml +6 -1
  168. data/vendor/board-maps/yaml/TBEAM_USE_RADIO_SX1278.yml +6 -1
  169. data/vendor/board-maps/yaml/TBEAM_USE_RADIO_SX1280.yml +6 -1
  170. data/vendor/board-maps/yaml/TBeam.yml +6 -1
  171. data/vendor/board-maps/yaml/TINYPICO.yml +10 -1
  172. data/vendor/board-maps/yaml/TINYS2.yml +11 -1
  173. data/vendor/board-maps/yaml/TTGO_LoRa32_V1.yml +11 -1
  174. data/vendor/board-maps/yaml/TTGO_LoRa32_V2.yml +11 -1
  175. data/vendor/board-maps/yaml/TTGO_LoRa32_v21new.yml +11 -1
  176. data/vendor/board-maps/yaml/TTGO_T1.yml +10 -1
  177. data/vendor/board-maps/yaml/TTGO_T7_V13_Mini32.yml +10 -1
  178. data/vendor/board-maps/yaml/TTGO_T7_V14_Mini32.yml +10 -1
  179. data/vendor/board-maps/yaml/TWATCH_2020_V1.yml +0 -1
  180. data/vendor/board-maps/yaml/TWATCH_2020_V2.yml +0 -1
  181. data/vendor/board-maps/yaml/TWATCH_2020_V3.yml +0 -1
  182. data/vendor/board-maps/yaml/TWATCH_BASE.yml +0 -1
  183. data/vendor/board-maps/yaml/TWatch.yml +0 -1
  184. data/vendor/board-maps/yaml/UBLOX_NINA_W10.yml +10 -1
  185. data/vendor/board-maps/yaml/UNOWIFIR4.yml +17 -0
  186. data/vendor/board-maps/yaml/WIPY3.yml +11 -1
  187. data/vendor/board-maps/yaml/XIAO_ESP32S3.yml +2 -1
  188. data/vendor/board-maps/yaml/connaxio_espoir.yml +7 -1
  189. data/vendor/board-maps/yaml/esp32vn_iot_uno.yml +10 -1
  190. data/vendor/board-maps/yaml/heltec_wifi_32_lora_V3.yml +11 -1
  191. data/vendor/board-maps/yaml/heltec_wifi_kit_32.yml +11 -1
  192. data/vendor/board-maps/yaml/heltec_wifi_kit_32_V3.yml +11 -1
  193. data/vendor/board-maps/yaml/heltec_wifi_lora_32.yml +10 -1
  194. data/vendor/board-maps/yaml/heltec_wifi_lora_32_V2.yml +10 -1
  195. data/vendor/board-maps/yaml/heltec_wireless_stick.yml +10 -1
  196. data/vendor/board-maps/yaml/heltec_wireless_stick_LITE.yml +10 -1
  197. data/vendor/board-maps/yaml/openkb.yml +11 -1
  198. data/vendor/board-maps/yaml/roboheart_hercules.yml +10 -1
  199. data/vendor/board-maps/yaml/sensesiot_weizen.yml +10 -1
  200. data/vendor/board-maps/yaml/uPesy_WROOM.yml +10 -1
  201. data/vendor/board-maps/yaml/uPesy_WROVER.yml +10 -1
  202. data/vendor/board-maps/yaml/unphone8.yml +11 -1
  203. data/vendor/board-maps/yaml/unphone9.yml +11 -1
  204. metadata +14 -2
data/src/lib/Denko.cpp CHANGED
@@ -36,7 +36,7 @@ void Denko::run(){
36
36
  parse(stream->read());
37
37
  rxBytes ++;
38
38
  // Acknowledge when we've received half as many bytes as the serial buffer.
39
- if (rxBytes >= rxNotifyLimit) rxNotify();
39
+ if (rxBytes >= DENKO_RX_ACK_INTERVAL) rxNotify();
40
40
  }
41
41
 
42
42
  #ifdef DENKO_UARTS
@@ -113,7 +113,7 @@ void Denko::process() {
113
113
  case 6: setListener (pin, val, auxMsg[0], auxMsg[1], false); break;
114
114
 
115
115
  // Implemented in DenkoEEPROM.cpp
116
- #ifdef EEPROM_PRESENT
116
+ #ifdef DENKO_EEPROM
117
117
  case 7: eepromRead (); break;
118
118
  case 8: eepromWrite (); break;
119
119
  #endif
@@ -198,6 +198,7 @@ void Denko::process() {
198
198
  case 90: handshake (); break;
199
199
  case 91: resetState (); break;
200
200
  case 92: sendReady (); break;
201
+ case 93: enumerate (); break;
201
202
  case 95: setRegisterDivider (); break;
202
203
  case 96: setAnalogWriteResolution (); break;
203
204
  case 97: setAnalogReadResolution (); break;
@@ -262,19 +263,27 @@ void Denko::handshake() {
262
263
  #ifdef DENKO_VERSION
263
264
  stream->print(DENKO_VERSION);
264
265
  #endif
266
+
267
+ // Third is serial buffer size.
268
+ stream->print(',');
269
+ stream->print(DENKO_SERIAL_BUFFER_SIZE);
265
270
 
266
- // Third is AUX_SIZE.
271
+ // Fourth is AUX_SIZE.
267
272
  stream->print(',');
268
273
  stream->print(AUX_SIZE);
269
274
 
270
- // Fourth is EEPROM size in bytes. None on Due or Zero.
275
+ // Fifth is EEPROM size. None on Due or Zero.
271
276
  stream->print(',');
272
277
  #if defined(EEPROM_EMULATED)
273
278
  stream->print(EMULATED_EEPROM_LENGTH);
274
279
  #elif defined(EEPROM_PRESENT)
275
280
  stream->print(EEPROM.length());
276
- #else
277
- stream->print('0');
281
+ #endif
282
+
283
+ // Sixth is I2C buffer size.
284
+ stream->print(',');
285
+ #ifdef DENKO_I2C
286
+ stream->print(DENKO_I2C_BUFFER_SIZE);
278
287
  #endif
279
288
 
280
289
  // End
@@ -297,6 +306,14 @@ void Denko::resetState() {
297
306
  lastTime = micros();
298
307
  }
299
308
 
309
+ // CMD = 93
310
+ void Denko::enumerate() {
311
+ stream->print("ENUMERATION:");
312
+ #ifdef A0
313
+ stream->println(A0);
314
+ #endif
315
+ }
316
+
300
317
  // CMD = 95
301
318
  // Set the register read divider. Powers of 2 up to 128 are valid.
302
319
  void Denko::setRegisterDivider() {
data/src/lib/Denko.h CHANGED
@@ -154,6 +154,8 @@ class Denko {
154
154
  void spiClearListeners ();
155
155
 
156
156
  // I2C
157
+ bool i2cStarted = false;
158
+ byte i2cSpeed = 0;
157
159
  void i2cBegin ();
158
160
  void i2cEnd ();
159
161
  void i2cSetSpeed (uint8_t code);
@@ -175,6 +177,7 @@ class Denko {
175
177
  //
176
178
  void handshake (); //cmd = 90
177
179
  void resetState (); //cmd = 91
180
+ void enumerate (); //cmd = 92
178
181
  void setRegisterDivider (); //cmd = 97
179
182
  void setAnalogWriteResolution (); //cmd = 96
180
183
  void setAnalogReadResolution (); //cmd = 97
@@ -205,30 +208,17 @@ class Denko {
205
208
  //
206
209
  // Flow control stuff.
207
210
  //
208
- // Notify the computer when the board has received half a serial buffer of bytes.
209
- //
211
+ // Notify computer that board has received bytes.
210
212
  void rxNotify();
211
213
  uint8_t rxBytes = 0;
212
- //
213
- // ESP32 uses a 128 byte FIFO buffer for UART Rx. Notify every 63 bytes instead of 32
214
- // so serial over native USB performs better.
215
- //
216
- // Using 63 instead of 64 since the ATmega32u4 (Leonardo) is limited to 63.
217
- //
218
- #ifdef ESP32
219
- uint8_t rxNotifyLimit = 63;
220
- #else
221
- uint8_t rxNotifyLimit = 32;
222
- #endif
223
-
224
214
  //
225
215
  // Tell the computer to halt or resume sending data to the board.
226
216
  //
227
- // Only use these if running a function on the board that disables interrupts for
217
+ // Use these if running a function on the board that disables interrupts for
228
218
  // longer than a single serial character (~85us at 115,200 baud).
229
219
  //
230
220
  // If the function was initiated by the computer (eg. writing to a WS2812 strip), do
231
- // not call sendHalt(). The computer should have halted transmission itself after sending
221
+ // not call sendHalt(). The computer should halt transmission itself after sending
232
222
  // the WS2812 command. Only call sendReady() after data is written out to the strip.
233
223
  //
234
224
  // If the function was initiated on the board (eg. New IR input triggered by an interrupt),
@@ -27,8 +27,8 @@ void Denko::setMode(byte p, byte m) {
27
27
  if (m != 0b100) dacDisable(p);
28
28
  #endif
29
29
 
30
- // On the SAMD21, mode needs to be INPUT when using the DAC.
31
- #ifdef __SAMD21G18A__
30
+ // On the SAMD21 and RA4M1, mode needs to be INPUT when using the DAC.
31
+ #if defined(__SAMD21G18A__) || defined(_RENESAS_RA_)
32
32
  if (m == 0b100){
33
33
  pinMode(p, INPUT);
34
34
  return;
@@ -196,7 +196,7 @@ void Denko::dacWrite(byte p, int v, boolean echo) {
196
196
  ::dacWrite(p, v);
197
197
  #endif
198
198
 
199
- #if defined(__SAM3X8E__) || defined(__SAMD21G18A__)
199
+ #if defined(__SAM3X8E__) || defined(__SAMD21G18A__) || defined(_RENESAS_RA_)
200
200
  analogWrite(p, v);
201
201
  #endif
202
202
  }
@@ -8,6 +8,7 @@
8
8
  #define DENKO_VERSION __VERSION__
9
9
 
10
10
  // Uncomment these to include features beyond core features.
11
+ // #define DENKO_EEPROM
11
12
  // #define DENKO_ONE_WIRE
12
13
  // #define DENKO_TONE
13
14
  // #define DENKO_SPI_BB
@@ -39,30 +40,24 @@
39
40
  #define PIN_COUNT 22
40
41
  #endif
41
42
 
42
- // No EEPROM on the Due or Zero.
43
- #if !defined(__SAM3X8E__) && !defined(__SAMD21G18A__)
44
- #define EEPROM_PRESENT
45
- #include <EEPROM.h>
46
- #endif
47
-
48
- // Emulate 512 bytes of EEPROM on ESP chips and the RP2040.
49
- #if defined(ESP8266) || defined(ESP32) || defined(ARDUINO_ARCH_RP2040)
50
- # define EEPROM_EMULATED
51
- # define EMULATED_EEPROM_LENGTH 512
52
- #endif
53
-
54
43
  // Figure out how many LEDC channels are available on ESP32 boards.
55
44
  #ifdef ESP32
56
- #define LEDC_CHANNEL_COUNT 16
45
+ #if CONFIG_IDF_TARGET_ESP32
46
+ #define LEDC_CHANNEL_COUNT 16
47
+ #elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
48
+ #define LEDC_CHANNEL_COUNT 8
49
+ #elif CONFIG_IDF_TARGET_ESP32C3
50
+ #define LEDC_CHANNEL_COUNT 6
51
+ #endif
57
52
  #endif
58
53
 
59
54
  // Filter for boards that can set their analog write resolution.
60
- #if defined(__SAM3X8E__) || defined(__SAMD21G18A__) || defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(ESP8266)
55
+ #if defined(__SAM3X8E__) || defined(__SAMD21G18A__) || defined(_RENESAS_RA_) || defined(ESP32) || defined(ARDUINO_ARCH_RP2040) || defined(ESP8266)
61
56
  #define WRITE_RESOLUTION_SETTER
62
57
  #endif
63
58
 
64
59
  // Filter for boards that can set their analog read resolution.
65
- #if defined(__SAM3X8E__) || defined(__SAMD21G18A__) || defined(ESP32) || defined(ARDUINO_ARCH_RP2040)
60
+ #if defined(__SAM3X8E__) || defined(__SAMD21G18A__) || defined(_RENESAS_RA_) || defined(ESP32) || defined(ARDUINO_ARCH_RP2040)
66
61
  #define READ_RESOLUTION_SETTER
67
62
  #endif
68
63
 
@@ -88,7 +83,7 @@
88
83
  #elif defined(ESP8266) && defined(SERIAL_PORT_HARDWARE_OPEN)
89
84
  #define DENKO_UARTS 1
90
85
 
91
- // This works for all the Atmel cores.
86
+ // This works for all the Atmel cores except RA4M1.
92
87
  #else
93
88
  #if defined(SERIAL_PORT_HARDWARE3)
94
89
  #define DENKO_UARTS 3
@@ -114,3 +109,54 @@
114
109
  #else
115
110
  #define AUX_SIZE 272
116
111
  #endif
112
+
113
+ // Define 'DENKO_SERIAL_IF' as the serial interface to use.
114
+ // Uses SerialUSB (left port), which is native USB, on Arduino Due & Zero, or Serial otherwise.
115
+ // On many boards, eg. Arduino Leonardo, RP2040, ESP32-S3, Serial is native USB regardless.
116
+ #if defined(__SAM3X8E__) || defined(__SAMD21G18A__)
117
+ #define DENKO_SERIAL_IF SerialUSB
118
+ #define DENKO_USB_CDC
119
+ // To use programming USB (right) on Due and Zero, comment 2 lines above, uncomment 1 line below.
120
+ // #define DENKO_SERIAL_IF Serial
121
+ #else
122
+ #define DENKO_SERIAL_IF Serial
123
+ #endif
124
+
125
+ // Figure out how much serial buffer we have, tell the computer, and set the ack interval.
126
+ // Best performance acknowledging at 64 bytes, or 32 if buffer is only 64.
127
+ //
128
+ // These are 256/64 regardless of whether native USB CDC or UART bridge.
129
+ #if defined(ARDUINO_ARCH_RP2040) || defined(ESP32) || defined(ESP8266) || defined(__SAM3X8E__)
130
+ #define DENKO_SERIAL_BUFFER_SIZE 256
131
+ #define DENKO_RX_ACK_INTERVAL 64
132
+ // RA4M1 has a 512 Serial buffer.
133
+ #elif defined(_RENESAS_RA_)
134
+ #define DENKO_SERIAL_BUFFER_SIZE 512
135
+ #define DENKO_RX_ACK_INTERVAL 64
136
+ // SAMD21 is 256/64 in native USB mode ONLY. Must use defaults on programming port to avoid data loss.
137
+ #elif defined(__SAMD21G18A__) && defined(DENKO_USB_CDC)
138
+ #define DENKO_SERIAL_BUFFER_SIZE 256
139
+ #define DENKO_RX_ACK_INTERVAL 64
140
+ // 32u4 is odd. Size is 63 instead of 64. Interval must be 31. 32 doesn't work at all. Off by 1 errors?
141
+ #elif defined(__AVR_ATmega32U4__)
142
+ #define DENKO_SERIAL_BUFFER_SIZE 63
143
+ #define DENKO_RX_ACK_INTERVAL 31
144
+ // Defaults
145
+ #else
146
+ #define DENKO_SERIAL_BUFFER_SIZE 64
147
+ #define DENKO_RX_ACK_INTERVAL 32
148
+ #endif
149
+
150
+ // Figure out how big the buffer is on the built-in Wire / I2C library.
151
+ #ifdef DENKO_I2C
152
+ // RP2040 and SAMD21 can do up to 256, but 255 since 1 byte for length.
153
+ #if defined(ARDUINO_ARCH_RP2040) || defined(__SAMD21G18A__)
154
+ #define DENKO_I2C_BUFFER_SIZE 255
155
+ // ESP32, ESP8266 and megaAVR can do up to 128.
156
+ #elif defined(ESP32) || defined(ESP8266) || defined(__AVR_ATmega4809__)
157
+ #define DENKO_I2C_BUFFER_SIZE 128
158
+ // Fall back to 32 bytes.
159
+ #else
160
+ #define DENKO_I2C_BUFFER_SIZE 32
161
+ #endif
162
+ #endif
@@ -3,7 +3,15 @@
3
3
  //
4
4
  #include "Denko.h"
5
5
 
6
- #ifdef EEPROM_PRESENT
6
+ #ifdef DENKO_EEPROM
7
+ #include <EEPROM.h>
8
+
9
+ // Emulate 512 bytes of EEPROM on ESP chips and the RP2040.
10
+ #if defined(ESP8266) || defined(ESP32) || defined(ARDUINO_ARCH_RP2040)
11
+ #define EEPROM_EMULATED
12
+ #define EMULATED_EEPROM_LENGTH 512
13
+ #endif
14
+
7
15
  // CMD = 6
8
16
  // Read from the microcontroller's EEPROM.
9
17
  //
data/src/lib/DenkoI2C.cpp CHANGED
@@ -6,20 +6,20 @@
6
6
 
7
7
  #include <Wire.h>
8
8
 
9
- bool i2cStarted = false;
10
-
11
9
  // Only start the I2C interface if not already started.
12
10
  // Lazy initialization in case user wants to use I2C pins for something else.
13
11
  void Denko::i2cBegin() {
14
12
  if (!i2cStarted) {
15
13
  Wire.begin();
16
14
  i2cStarted = true;
15
+ i2cSetSpeed(0);
17
16
  }
18
17
  }
19
18
 
20
19
  // End the I2C interface.
21
20
  // This is mostly used as a Reset in Denko::handshake.
22
21
  void Denko::i2cEnd(){
22
+ i2cSetSpeed(0);
23
23
  // ESP8266 core does not define Wire.end()
24
24
  #ifndef ESP8266
25
25
  Wire.end();
@@ -36,6 +36,7 @@ void Denko::i2cSetSpeed(uint8_t code) {
36
36
  case 3: Wire.setClock(3400000); break;
37
37
  default: Wire.setClock(100000); break;
38
38
  }
39
+ i2cSpeed = code;
39
40
  }
40
41
 
41
42
  // CMD = 33
@@ -43,7 +44,8 @@ void Denko::i2cSetSpeed(uint8_t code) {
43
44
  void Denko::i2cSearch() {
44
45
  byte error;
45
46
  uint8_t addr;
46
- i2cBegin();
47
+ if (!i2cStarted) i2cBegin();
48
+ i2cSetSpeed(0);
47
49
  stream->print(SDA);
48
50
 
49
51
  // Only addresses from 0x08 to 0x77 are usable (8 to 127).
@@ -77,10 +79,10 @@ void Denko::i2cWrite() {
77
79
  uint8_t dataLength = (uint8_t)val;
78
80
 
79
81
  // Limit to 32 bytes.
80
- if (dataLength > 32) dataLength = 32;
82
+ if (dataLength > DENKO_I2C_BUFFER_SIZE) dataLength = DENKO_I2C_BUFFER_SIZE;
81
83
 
82
- i2cBegin();
83
- i2cSetSpeed(auxMsg[0]);
84
+ if (!i2cStarted) i2cBegin();
85
+ if (i2cSpeed != auxMsg[0]) i2cSetSpeed(auxMsg[0]);
84
86
 
85
87
  Wire.beginTransmission(address);
86
88
  Wire.write(&auxMsg[1], dataLength);
@@ -116,10 +118,10 @@ void Denko::i2cRead() {
116
118
  uint8_t dataLength = (uint8_t)val;
117
119
 
118
120
  // Limit to 32 bytes.
119
- if (dataLength > 32) dataLength = 32;
121
+ if (dataLength > DENKO_I2C_BUFFER_SIZE) dataLength = DENKO_I2C_BUFFER_SIZE;
120
122
 
121
- i2cBegin();
122
- i2cSetSpeed(auxMsg[0]);
123
+ if (!i2cStarted) i2cBegin();
124
+ if (i2cSpeed != auxMsg[0]) i2cSetSpeed(auxMsg[0]);
123
125
 
124
126
  // Optionally write up to a 4 byte register address before reading.
125
127
  if ((auxMsg[1] > 0) && (auxMsg[1] < 5)) {
@@ -8,7 +8,7 @@
8
8
  // WS2812 / NeoPixel support using Adafruit library from:
9
9
  // https://github.com/adafruit/Adafruit_NeoPixel
10
10
  //
11
- # ifdef DENKO_LED_WS2812
11
+ #ifdef DENKO_LED_WS2812
12
12
  #include <Adafruit_NeoPixel.h>
13
13
  #endif
14
14
 
data/target.yml CHANGED
@@ -1,3 +1,37 @@
1
+ # name: rp2040
2
+ # fqbn: rp2040:rp2040:rpipicow
3
+ # port: /dev/cu.usbmodem14B01
4
+
5
+ # name: mega
6
+ # fqbn: arduino:avr:uno
7
+ # ort: /dev/cu.usbmodem14B01
8
+
9
+ # name: mega
10
+ # fqbn: arduino:avr:mega
11
+ # port: /dev/cu.usbmodem14C01
12
+
1
13
  name: mega
2
- fqbn: arduino:avr:uno
14
+ fqbn: arduino:avr:leonardo
3
15
  port: /dev/cu.usbmodem14B01
16
+
17
+ # name: esp32
18
+ # fqbn: esp32:esp32:esp32doit-devkit-v1
19
+ # port: /dev/cu.SLAB_USBtoUART
20
+
21
+ # name: esp8266
22
+ # fqbn: esp8266:esp8266:nodemcuv2
23
+ # port: /dev/cu.SLAB_USBtoUART
24
+
25
+ # name: sam3x
26
+ # fqbn: arduino:sam:arduino_due_x
27
+ # port: /dev/cu.usbmodem14C0
28
+
29
+ # name: samd
30
+ # fqbn: arduino:samd:arduino_zero_native
31
+ # port: /dev/cu.usbmodem14C01
32
+
33
+ # Native USB ESP32 shouldn't be used since this doesn't enable USB CDC on boot.
34
+
35
+ # name: esp32
36
+ # fqbn: esp32:esp32:lolin_s3
37
+ # port: /dev/cu.usbmodem14C01
@@ -51,13 +51,20 @@ class ReaderTest < Minitest::Test
51
51
  assert_equal part.read, 42
52
52
  end
53
53
 
54
- def test_read_using
54
+ def test_read_using_with_lambda
55
55
  inject(1)
56
56
  reader = MiniTest::Mock.new.expect :call, nil
57
57
  part.read_using -> { reader.call }
58
58
  reader.verify
59
59
  end
60
60
 
61
+ def test_read_using_with_method_and_args
62
+ inject(1)
63
+ reader = MiniTest::Mock.new.expect :call, nil, [10, 20], test_arg: 2
64
+ part.read_using reader, 10, 20, test_arg: 2
65
+ reader.verify
66
+ end
67
+
61
68
  def test_add_run_remove_callback
62
69
  cb = MiniTest::Mock.new.expect :call, nil
63
70
  inject(1)
@@ -20,10 +20,6 @@ class APIHelperTest < Minitest::Test
20
20
  assert_equal pack(:uint8, [25,26]), "\x19\x1A"
21
21
  end
22
22
 
23
- def test_padding
24
- assert_equal pack(:uint8, 25, pad: 2), "\x19\x00"
25
- end
26
-
27
23
  def test_min
28
24
  assert_raises(ArgumentError) { pack(:uint8, 25, min: 2) }
29
25
  end
@@ -20,4 +20,14 @@ class HD44780Test < MiniTest::Test
20
20
 
21
21
  end
22
22
  end
23
+
24
+ def test_write4
25
+ part.write4 "10100101"
26
+
27
+ # Pin states should match lower 4 bits, since they are sent last.
28
+ assert_equal 1, part.d4.state
29
+ assert_equal 0, part.d5.state
30
+ assert_equal 1, part.d6.state
31
+ assert_equal 0, part.d7.state
32
+ end
23
33
  end
@@ -60,14 +60,17 @@ class SevenSegmentLEDTest < MiniTest::Test
60
60
  end
61
61
 
62
62
  def test_scroll
63
- mock = MiniTest::Mock.new.expect :call, nil, ['foo']
64
- part.stub(:scroll, mock) do
65
- part.display('foo')
63
+ mock = MiniTest::Mock.new
64
+ mock.expect :call, nil, ['H']
65
+ mock.expect :call, nil, ['I']
66
+ part.stub(:write, mock) do
67
+ part.display('hi')
66
68
  end
67
69
  mock.verify
68
70
  end
69
71
 
70
72
  def test_display_ensures_on
73
+ part.off
71
74
  mock = MiniTest::Mock.new.expect :call, nil
72
75
  part.stub(:on, mock) do
73
76
  part.display(1)
@@ -75,12 +78,31 @@ class SevenSegmentLEDTest < MiniTest::Test
75
78
  mock.verify
76
79
  end
77
80
 
78
- def test_display_clears_if_unknown_char
79
- mock = MiniTest::Mock.new.expect :call, nil
80
- part.stub(:clear, mock) do
81
- part.display('+')
81
+ def test_write_clears_if_unknown_char
82
+ # Turn all the segments on.
83
+ part.display('8')
84
+
85
+ # Expect every segment to get #write(1). Inverted logic because anode.
86
+ mocks = []
87
+ part.segments.each do
88
+ mocks << MiniTest::Mock.new.expect(:call, nil, [1])
82
89
  end
83
- mock.verify
90
+ part.segments[0].stub(:write, mocks[0]) do
91
+ part.segments[1].stub(:write, mocks[1]) do
92
+ part.segments[2].stub(:write, mocks[2]) do
93
+ part.segments[3].stub(:write, mocks[3]) do
94
+ part.segments[4].stub(:write, mocks[4]) do
95
+ part.segments[5].stub(:write, mocks[5]) do
96
+ part.segments[6].stub(:write, mocks[6]) do
97
+ part.display('+')
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
105
+ mocks.each { |mock| mock.verify}
84
106
  end
85
107
  # Test with cathode
86
108
  end
data/test/test_helper.rb CHANGED
@@ -100,7 +100,12 @@ module Constants
100
100
  opts[:on].send(:remove_const, const) if self.class.const_defined?(const)
101
101
  opts[:on].const_set(const, value)
102
102
  end
103
- ACK = "SAMD_ZERO,0.13.0,528,1024"
103
+ # Imaginary handshake ack from the board. Not a real SAMD_ZERO device.
104
+ # Serial buffer = 256
105
+ # Aux size = 528
106
+ # EEPROM size = 1024
107
+ # I2C buffer = 32
108
+ ACK = "SAMD_ZERO,0.13.0,256,528,1024,32"
104
109
 
105
110
  # Some test redefine RUBY_PLATFORM. Save the original to reset it.
106
111
  ORIGINAL_RUBY_PLATFORM = RUBY_PLATFORM
@@ -137,6 +142,9 @@ class ConnectionMock
137
142
  def handshake
138
143
  Constants::ACK
139
144
  end
145
+ def remote_buffer_size=(size)
146
+ @remote_buffer_size = size
147
+ end
140
148
  end
141
149
 
142
150
  class BoardMock < Denko::Board
@@ -211,7 +219,7 @@ module TestPacker
211
219
  end
212
220
  end
213
221
 
214
- # Speed up one wire tests.
222
+ # Speed up tests which use long delays.
215
223
  module Denko
216
224
  module OneWire
217
225
  class Bus
@@ -220,4 +228,11 @@ module Denko
220
228
  end
221
229
  end
222
230
  end
231
+ module LED
232
+ class SevenSegment
233
+ def sleep(time)
234
+ super(0.001)
235
+ end
236
+ end
237
+ end
223
238
  end
@@ -19,3 +19,6 @@
19
19
  [submodule "cores/sam3x"]
20
20
  path = cores/sam3x
21
21
  url = https://github.com/arduino/ArduinoCore-sam
22
+ [submodule "cores/ra4m1"]
23
+ path = cores/ra4m1
24
+ url = https://github.com/arduino/ArduinoCore-renesas.git
@@ -378,18 +378,6 @@
378
378
  #define BOARD_MAP "ADAFRUIT_FEATHER_ESP32S2_REVTFT"
379
379
  #endif
380
380
 
381
- #ifdef ARDUINO_ADAFRUIT_QTPY_ESP32S2
382
- #define BOARD_MAP "ADAFRUIT_QTPY_ESP32S2"
383
- #endif
384
-
385
- #ifdef ARDUINO_ADAFRUIT_QTPY_ESP32C3
386
- #define BOARD_MAP "ADAFRUIT_QTPY_ESP32C3"
387
- #endif
388
-
389
- #ifdef ARDUINO_ADAFRUIT_QTPY_ESP32_PICO
390
- #define BOARD_MAP "ADAFRUIT_QTPY_ESP32_PICO"
391
- #endif
392
-
393
381
  #ifdef ARDUINO_ADAFRUIT_FEATHER_ESP32_V2
394
382
  #define BOARD_MAP "ADAFRUIT_FEATHER_ESP32_V2"
395
383
  #endif
@@ -410,10 +398,26 @@
410
398
  #define BOARD_MAP "ADAFRUIT_FEATHER_ESP32S3_REVTFT"
411
399
  #endif
412
400
 
401
+ #ifdef ARDUINO_ADAFRUIT_QTPY_ESP32_PICO
402
+ #define BOARD_MAP "ADAFRUIT_QTPY_ESP32_PICO"
403
+ #endif
404
+
405
+ #ifdef ARDUINO_ADAFRUIT_QTPY_ESP32C3
406
+ #define BOARD_MAP "ADAFRUIT_QTPY_ESP32C3"
407
+ #endif
408
+
409
+ #ifdef ARDUINO_ADAFRUIT_QTPY_ESP32S2
410
+ #define BOARD_MAP "ADAFRUIT_QTPY_ESP32S2"
411
+ #endif
412
+
413
413
  #ifdef ARDUINO_ADAFRUIT_QTPY_ESP32S3_NOPSRAM
414
414
  #define BOARD_MAP "ADAFRUIT_QTPY_ESP32S3_NOPSRAM"
415
415
  #endif
416
416
 
417
+ #ifdef ARDUINO_ADAFRUIT_QTPY_ESP32S3_N4R2
418
+ #define BOARD_MAP "ADAFRUIT_QTPY_ESP32S3_N4R2"
419
+ #endif
420
+
417
421
  #ifdef ARDUINO_ADAFRUIT_ITSYBITSY_ESP32
418
422
  #define BOARD_MAP "ADAFRUIT_ITSYBITSY_ESP32"
419
423
  #endif
@@ -1142,6 +1146,10 @@
1142
1146
  #define BOARD_MAP "NANO_RP2040_CONNECT"
1143
1147
  #endif
1144
1148
 
1149
+ #ifdef ARDUINO_ARTRONSHOP_RP2_NANO
1150
+ #define BOARD_MAP "ARTRONSHOP_RP2_NANO"
1151
+ #endif
1152
+
1145
1153
  #ifdef ARDUINO_BRIDGETEK_IDM2040-7A
1146
1154
  #define BOARD_MAP "BRIDGETEK_IDM2040-7A"
1147
1155
  #endif
@@ -1194,6 +1202,10 @@
1194
1202
  #define BOARD_MAP "CHALLENGER_2040_WIFI_BLE_RP2040"
1195
1203
  #endif
1196
1204
 
1205
+ #ifdef ARDUINO_CHALLENGER_2040_WIFI6_BLE_RP2040
1206
+ #define BOARD_MAP "CHALLENGER_2040_WIFI6_BLE_RP2040"
1207
+ #endif
1208
+
1197
1209
  #ifdef ARDUINO_CHALLENGER_NB_2040_WIFI_RP2040
1198
1210
  #define BOARD_MAP "CHALLENGER_NB_2040_WIFI_RP2040"
1199
1211
  #endif
@@ -1234,6 +1246,10 @@
1234
1246
  #define BOARD_MAP "PIMORONI_PGA2040"
1235
1247
  #endif
1236
1248
 
1249
+ #ifdef ARDUINO_PIMORONI_PLASMA2040
1250
+ #define BOARD_MAP "PIMORONI_PLASMA2040"
1251
+ #endif
1252
+
1237
1253
  #ifdef ARDUINO_SOLDERPARTY_RP2040_STAMP
1238
1254
  #define BOARD_MAP "SOLDERPARTY_RP2040_STAMP"
1239
1255
  #endif
@@ -1362,3 +1378,15 @@
1362
1378
  #define BOARD_MAP "SAMD_TIAN"
1363
1379
  #endif
1364
1380
 
1381
+ #ifdef ARDUINO_PORTENTA_C33
1382
+ #define BOARD_MAP "PORTENTA_C33"
1383
+ #endif
1384
+
1385
+ #ifdef ARDUINO_MINIMA
1386
+ #define BOARD_MAP "MINIMA"
1387
+ #endif
1388
+
1389
+ #ifdef ARDUINO_UNOWIFIR4
1390
+ #define BOARD_MAP "UNOWIFIR4"
1391
+ #endif
1392
+
@@ -18,6 +18,7 @@ This is the exact use case this was deisgned for, in support of the [denko](http
18
18
  - [megaavr](https://github.com/arduino/ArduinoCore-megaavr)
19
19
  - [sam](https://github.com/arduino/ArduinoCore-sam)
20
20
  - [samd](https://github.com/arduino/ArduinoCore-samd)
21
+ - [renesas](https://github.com/arduino/ArduinoCore-renesas)
21
22
  - [esp8266](https://github.com/esp8266/Arduino)
22
23
  - [esp32](https://github.com/espressif/arduino-esp32)
23
24
  - [rp2040](https://github.com/earlephilhower/arduino-pico)