forked from slviajero/tinybasic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhardware-arduino.h
More file actions
4701 lines (4321 loc) · 118 KB
/
hardware-arduino.h
File metadata and controls
4701 lines (4321 loc) · 118 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
*
* $Id: hardware-arduino.h,v 1.7 2022/12/15 06:19:42 stefan Exp stefan $
*
* Stefan's basic interpreter
*
* Playing around with frugal programming. See the licence file on
* https://github.com/slviajero/tinybasic for copyright/left.
* (GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007)
*
* Author: Stefan Lenz, sl001@serverfabrik.de
*
* Hardware definition file coming with TinybasicArduino.ino aka basic.c
*
* - ARDUINOLCD, ARDUINOTFT and LCDSHIELD active the LCD code,
* LCDSHIELD automatically defines the right settings for
* the classical shield modules
* - ARDUINOPS2 activates the PS2 code. Default pins are 2 and 3.
* If you use other pins the respective changes have to be made
* below.
* - _if_ and PS2 are both activated STANDALONE cause the Arduino
* to start with keyboard and lcd as standard devices.
* - ARDUINOEEPROM includes the EEPROM access code
* - ARDUINOEFS, ARDUINOSD, ESPSPIFFS, RP2040LITTLEFS activate filesystem code
* - activating Picoserial, Picoserial doesn't work on MEGA
*
* Architectures and the definitions from the Arduino IDE
*
* ARDUINO_ARCH_SAM: no tone command, dtostrf
* ARDUINO_ARCH_RP2040: dtostrf (for ARDUINO_NANO_RP2040_CONNECT)
* ARDUINO_ARCH_SAMD: dtostrf (for ARDUINO_SAMD_MKRWIFI1010, ARDUINO_SEEED_XIAO_M0)
* ARDUINO_ARCH_ESP8266: SPIFFS, dtostrf (ESP8266)
* ARDUINO_AVR_MEGA2560, ARDUARDUINO_SAM_DUE: second serial port is Serial1-3 - no software serial
* ARDUINO_SAM_DUE: hardware heuristics
* ARDUINO_ARCH_AVR: nothing
* ARDUINO_ARCH_LGT8F: EEPROM code for flash EEPROM - platform fully supported now, yet no call 0
* ARDUINO_ARCH_ESP32 and ARDUINO_TTGO_T7_V14_Mini32, no tone, no analogWrite, avr/xyz obsolete
*
* The code still contains hardware heuristics from my own projects,
* will be removed in the future
*
*/
#if defined(ARDUINO) && ! defined(__HARDWAREH__)
#define __HARDWAREH__
/*
* Arduino hardware settings , set here what you need or
* use one of the predefined configurations below
*
* input/output methods USERPICOSERIAL, ARDUINOPS2
* ARDUINOPRT, DISPLAYCANSCROLL, ARDUINOLCDI2C,
* ARDUINOTFT, ARDUINONOKIA51, ARDUINOILI9488,
* ARDUINOSSD1306, ARDUINOMCUFRIEND
* storage ARDUINOEEPROM, ARDUINOSD, ESPSPIFFS
* sensors ARDUINORTC, ARDUINOWIRE, ARDUINOSENSORS
* network ARDUINORF24, ARDUNIOMQTT
* memory ARDUINOSPIRAM
*
* leave this unset if you use the definitions below
*/
#undef USESPICOSERIAL
#undef ARDUINOPS2
#undef ARDUINOUSBKBD
#undef ARDUINOZX81KBD
#undef ARDUINOPRT
#undef DISPLAYCANSCROLL
#undef ARDUINOLCDI2C
#undef ARDUINONOKIA51
#undef ARDUINOILI9488
#undef ARDUINOSSD1306
#undef ARDUINOMCUFRIEND
#undef ARDUINOGRAPHDUMMY
#undef LCDSHIELD
#undef ARDUINOTFT
#undef ARDUINOVGA
#define ARDUINOEEPROM
#undef ARDUINOI2CEEPROM
#undef ARDUINOEFS
#undef ARDUINOSD
#undef ESPSPIFFS
#undef RP2040LITTLEFS
#undef ARDUINORTC
#undef ARDUINOWIRE
#undef ARDUINOWIRESLAVE
#undef ARDUINORF24
#undef ARDUINOETH
#undef ARDUINOMQTT
#undef ARDUINOSENSORS
#undef ARDUINOSPIRAM
#undef STANDALONE
#undef STANDALONESECONDSERIAL
/* experimental features, don't use unless you know the code */
/*
* this setting uses the EEPROM as program storage
* The idea is to create a virtual memory layout starting from 0 with the EEPROM
* from elength() and then adding the BASIC RAM to it. himem and top need to be
* handled carefully.
*/
#undef ARDUINOPGMEEPROM
/*
* Predefined hardware configurations, this assumes that all of the
* above are undef
*
* UNOPLAIN:
* a plain UNO with no peripherals
* AVRLCD:
* a AVR system with an LCD shield
* WEMOSSHIELD:
* a Wemos D1 with a modified simple datalogger shield
* optional keyboard and i2c display
* MEGASHIELD:
* an Arduino Mega with Ethernet Shield
* optional keyboard and i2c display
* TTGOVGA:
* TTGO VGA1.4 system with PS2 keyboard, standalone
* MEGATFT, DUETFT
* TFT 7inch screen systems, standalone
* NANOBOARD:
* Arduino Nano Every board with PS2 keyboard and sensor
* kit
* MEGABOARD:
* A board for the MEGA with 64 kB RAM, SD Card, and real time
* clock
* UNOBOARD:
* A board for an UNO with 64kB memory and EEPROM disk
* fits into an UNO flash only with integer
* ESP01BOARD:
* ESP01 based board as a sensor / MQTT interface
* RP2040BOARD:
* A ILI9488 hardware design based on an Arduino connect RP2040.
* RP2040BOARD2:
* like the one above but based on the Pi Pico core
* ESP32BOARD:
* same like above with an ESP32 core
* MKRBOARD:
* a digital signage and low energy board
*/
#undef UNOPLAIN
#undef AVRLCD
#undef WEMOSSHIELD
#undef MEGASHIELD
#undef TTGOVGA
#undef DUETFT
#undef MEGATFT
#undef NANOBOARD
#undef MEGABOARD
#undef UNOBOARD
#undef ESP01BOARD
#undef RP2040BOARD
#undef RP2040BOARD2
#undef ESP32BOARD
#undef MKR1010BOARD
/*
* PIN settings and I2C addresses for various hardware configurations
* used a few heuristics and then the hardware definitions above
*
* #define SDPIN sets the SD CS pin - can be left as a default for most HW configs
* TTGO needs it as default definitions in the board file are broken
* #define PS2DATAPIN, PS2IRQPIN sets PS2 pin
*/
/* PS2 Keyboard pins for AVR - use one interrupt pin 2 and one date pin
5 not 4 because 4 conflicts with SDPIN of the standard SD shield */
#define PS2DATAPIN 5
#define PS2IRQPIN 2
/* Ethernet - 10 is the default */
/* #define ETHPIN 10 */
/* The Pretzelboard definitions for Software Serial, conflicts with SPI */
#define SOFTSERIALRX 11
#define SOFTSERIALTX 12
/* near field pin settings for CE and CSN*/
#define RF24CEPIN 8
#define RF24CSNPIN 9
/* use standard I2C pins almost always */
#undef SDA_PIN
#undef SCL_PIN
/* set this is you want pin 4 on low interrupting the interpreter */
/* #define BREAKPIN 4 */
#undef BREAKPIN
/* the secondary serial port aka prt aka stream 4 */
#ifndef PRTSERIAL
#define PRTSERIAL Serial1
#endif
/*
* Pin settings for the ZX81 Keyboard
* first the 8 rows, then the 5 columns or the keyboard
*
* MEGAs have many pins and default is to use the odd pins on the side
* UNOs, NANOs, and others use the lower pins by default avoiding the
* pin 13 which is LED and doesn't work with standard schematics
*/
#ifdef ARDUINOZX81KBD
#ifdef ARDUINO_AVR_MEGA2560
const byte zx81pins[] = {37, 35, 33, 31, 29, 27, 25, 23, 47, 45, 43, 41, 39};
#else
const char zx81pins[] = {7, 8, 9, 10, 11, 12, A0, A1, 2, 3, 4, 5, 6 };
#endif
#endif
/*
* this is soft SPI for SD cards on MEGAs using
* pins 10-13, a patched SD library is needed
* for this: https://github.com/slviajero/SoftSD
* only needed for MEGA boards with an UNO shield
*/
#undef SOFTWARE_SPI_FOR_SD
/*
* list of default i2c addresses
*
* some clock modules do have their EEPROM at 0x57.
* 0x050 this is the default lowest adress of standard EEPROMs
* Configurable range is between 0x50 and 0x57 for modules with jumpers.
* Some clock modules do have their EEPROM at 0x57.
*
* Clock default for the size is 4096. Define your EFS EEPROM and I2C EEPROM
* size here. One parameter set is for EFS and one parameter set is for
* plain serial EEPROMs.
*
* RTCs are often at 0x68
*/
#define EFSEEPROMADDR 0x050
/* #define EFSEEPROMSIZE 32768 */
#define RTCI2CADDR 0x068
/* the size of the plain I2C EEPROM, typically a clock */
#define I2CEEPROMADDR 0x050
/* #define I2CEEPROMSIZE 4096 */
/* is the I2C EEPROM buffered */
#define ARDUINOI2CEEPROM_BUFFERED
/*
* Sensor library code - experimental
*/
#ifdef ARDUINOSENSORS
#undef ARDUINODHT
#define DHTTYPE DHT22
#define DHTPIN 2
#undef ARDUINOSHT
#ifdef ARDUINOSHT
#define ARDUINOWIRE
#endif
#undef ARDUINOMQ2
#define MQ2PIN A0
#undef ARDUINOLMS6
#undef ARDUINOAHT
#undef ARDUINOBMP280
#undef ARDUINOBME280
#endif
/*
* the hardware models
* These are predefined hardware configutations
*/
/* an AVR based Arduino with nothing else */
#if defined(UNOPLAIN)
#define ARDUINOEEPROM
#endif
/* an AVR ARDUINO (UNO or MEGA) with the classical LCD shield */
#if defined(AVRLCD)
#define ARDUINOEEPROM
#define DISPLAYCANSCROLL
#define LCDSHIELD
#endif
/*
* a Wemos ESP8266 with a mdified datalogger shield
* standalone capable, with Wire and MQTT.
*/
#if defined(WEMOSSHIELD)
#define ARDUINOEEPROM
#define ARDUINOPS2
#define DISPLAYCANSCROLL
#define ARDUINOLCDI2C
#define ARDUINOSD
#define ARDUINORTC
#define ARDUINOWIRE
#define SDPIN D8
#define PS2DATAPIN D2
#define PS2IRQPIN D9
#define ARDUINOMQTT
#endif
/*
* mega with a Ethernet shield
* standalone capable, Ethernet is not enabled by default
*/
#if defined(MEGASHIELD)
#define ARDUINOEEPROM
#define ARDUINOPS2
#define DISPLAYCANSCROLL
#define ARDUINOLCDI2C
#define ARDUINOSD
#define ARDUINOWIRE
#define ARDUINOPRT
#define SDPIN 4
#endif
/*
* VGA system with SD card, based on the TTGO VGA 1.4
* ESP32
* standalone by default, with MQTT
*/
#if defined(TTGOVGA)
#define ARDUINOEEPROM
#define ARDUINOVGA
#define ARDUINOSD
/* #define ARDUINOMQTT */
#define SDPIN 13
#define STANDALONE
#endif
/*
* MEGA with a TFT shield, standalone by default
*/
#if defined(MEGATFT)
#define ARDUINOEEPROM
#define ARDUINOPS2
#define DISPLAYCANSCROLL
#define ARDUINOTFT
#define ARDUINOSD
#define ARDUINOWIRE
#define ARDUINOPRT
#define PS2DATAPIN 18
#define PS2IRQPIN 19
#define SDPIN 53
#define STANDALONE
#endif
/*
* DUE with a TFT shield, standalone by default
*/
#if defined(DUETFT)
#undef ARDUINOEEPROM
#define ARDUINOPS2
#undef ARDUINOUSBKBD
#define DISPLAYCANSCROLL
#define ARDUINOTFT
#define ARDUINOSD
#define ARDUINOWIRE
#define ARDUINOPRT
#define ARDUINORTC
#define PS2DATAPIN 9
#define PS2IRQPIN 8
#define SDPIN 53
#define STANDALONE
#endif
#if defined(NANOBOARD)
#undef USESPICOSERIAL
#define ARDUINOPS2
#define DISPLAYCANSCROLL
#define ARDUINOLCDI2C
#define ARDUINOEEPROM
#define ARDUINOPRT
#define ARDUINOEFS
#define ARDUINORTC
#define ARDUINOWIRE
#define EFSEEPROMADDR 0x050 /* use clock EEPROM 0x057, set to 0x050 for external EEPROM */
#define STANDALONE
#endif
/* a UNO shield with memory and EFS EEPROM */
#if defined(UNOBOARD)
#define ARDUINOEEPROM
#define ARDUINOSPIRAM
#define ARDUINOEFS
#define ARDUINOWIRE
#define EFSEEPROMADDR 0x050
#define EFSEEPROMSIZE 65534
#endif
/* a MEGA shield with memory and SD card */
#if defined(MEGABOARD)
#undef USESPICOSERIAL
#define DISPLAYCANSCROLL
#define ARDUINOLCDI2C
#define ARDUINOEEPROM
#define ARDUINOPRT
#define ARDUINOSD
#define ARDUINOWIRE
#define ARDUINORTC
#define ARDUINOSPIRAM
#define RAMPIN 53
#define SDPIN 49
#endif
/* an ESP01 board, using the internal flash
* with the ESP01-8266 only pins 0 and 2 are usable freely
* on ESP01-ESP32C3 this is 9 and 2 while 2 is an analog pin
* 9 cannot be pulled on low by any peripheral on boot because this
* brings the board to flash mode
*/
#if defined(ESP01BOARD)
#undef ARDUINOEEPROM
#define ESPSPIFFS
#define ARDUINOMQTT
#define ARDUINOWIRE
#if defined(ARDUINOWIRE) && defined(ARDUINO_ARCH_ESP8266)
#define SDA_PIN 0
#define SCL_PIN 2
#endif
/* see: https://github.com/espressif/arduino-esp32/issues/6376
* nothing should block the port, e.g. DHT or anything
*/
#if defined(ARDUINOWIRE) && defined(ARDUINO_ARCH_ESP32)
#define SDA_PIN 9
#define SCL_PIN 2
#endif
/*
*
* Currently only 8=SDA and 9=SCL works / tested with AHT10
*/
#endif
/* an RP2040 based board with an ILI9488 display */
#if defined(RP2040BOARD)
#undef USESPICOSERIAL
#define DISPLAYCANSCROLL
#define ARDUINOILI9488
#undef ARDUINOEEPROM
#define ARDUINOI2CEEPROM
#define ARDUINOPRT
#define ARDUINOSD
#undef RP2040LITTLEFS
#define ARDUINOWIRE
#define ARDUINORTC
#define ARDUINOPS2
#define ARDUINOMQTT
#undef STANDALONE
#endif
/* an RP2040 Raspberry Pi Pico based board with an ILI9488 display */
#if defined(RP2040BOARD2)
#undef USESPICOSERIAL
#define DISPLAYCANSCROLL
#define ARDUINOILI9488
#undef ARDUINOEEPROM
#undef ARDUINOPRT
#undef ARDUINOSD
#define RP2040LITTLEFS
#undef ARDUINOWIRE
#undef ARDUINORTC
#undef ARDUINOPS2
#undef ARDUINOMQTT
#undef STANDALONE
#define ILI_LED A2
#define ILI_CS 15
#define ILI_RST 14
#define ILI_DC 13
#endif
/* an ESP32 board with an ILI9488 display,
some SD problems here with some hardware */
#if defined(ESP32BOARD)
#define ILI_CS 12
#define ILI_DC 27
#define ILI_RST 14
#define ILI_LED 26
#undef USESPICOSERIAL
#define ESPSPIFFS
#define DISPLAYCANSCROLL
#define ARDUINOILI9488
#define ARDUINOEEPROM
#define ARDUINOMQTT
#define ARDUINOWIRE
#endif
/* a board based on the Arduino MKR 1010 Wifi
* made for low energy games
*/
#if defined(MKR1010BOARD)
#define ILI_CS 7
#define ILI_DC 4
#define ILI_RST 6
#define ILI_LED A3
#undef USESPICOSERIAL
#define DISPLAYCANSCROLL
#define ARDUINOILI9488
#define ARDUINOEFS
#define ARDUINOMQTT
#define ARDUINOWIRE
/* careful with the setting, lockout possible easily */
#undef ARDUINOUSBKBD
#undef STANDALONE
#endif
/*
* defining the systype variable which informs BASIC about the platform at runtime
*/
#if defined(ARDUINO_ARCH_AVR)
const mem_t bsystype = SYSTYPE_AVR;
#elif defined(ARDUINO_ARCH_ESP8266)
const mem_t bsystype = SYSTYPE_ESP8266;
#elif defined(ARDUINO_ARCH_ESP32)
const mem_t bsystype = SYSTYPE_ESP32;
#elif defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_MBED_RP2040)
const mem_t bsystype = SYSTYPE_RP2040;
#elif defined(ARDUINO_ARCH_SAM) && defined(ARDUINO_ARCH_SAMD)
const mem_t bsystype = SYSTYPE_SAM;
#else
const mem_t bsystype = SYSTYPE_UNKNOWN;
#endif
/*
* the non AVR arcitectures - this is somehow raw
* the ARDUINO 100 definition is probably not needed anymore
*/
#if defined(ARDUINO_ARCH_SAM) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_MBED_RP2040)
#include <avr/dtostrf.h>
#define ARDUINO 100
#endif
/*
* Some settings, defaults, and dependencies
*
* NEEDSWIRE is set to start wire. Some libraries do this again.
*
* Handling Wire and SPI is tricky as some of the libraries
* also include and start SPI and Wire code.
*/
/* a clock needs wire */
#ifdef ARDUINORTC
#define NEEDSWIRE
#endif
/* a display needs wire */
#if defined(ARDUINOLCDI2C) || defined(ARDUINOSSD1306)
#define NEEDSWIRE
#endif
/* EEPROM storage needs wire */
#if defined(ARDUINOEFS)
#define NEEDSWIRE
#endif
/* external EEPROMs also need wire */
#if defined(ARDUINOI2CEEPROM)
#define NEEDSWIRE
#endif
/* plain Wire support also needs wire ;-) */
#if defined(ARDUINOWIRE)
#define NEEDSWIRE
#endif
/* radio needs SPI */
#ifdef ARDUINORF24
#define ARDUINOSPI
#endif
/* a filesystem needs SPI */
#if defined(ARDUINOSD) || defined(ESPSPIFFS)
#define ARDUINOSPI
#endif
/* networking may need SPI */
#ifdef ARDUINOMQTT
#define ARDUINOSPI
#endif
/* the NOKIA and ILI9488 display needs SPI */
#if defined(ARDUINONOKIA51) || defined(ARDUINOILI9488)
#define ARDUINOSPI
#endif
/* the RAM chips */
#if defined(ARDUINOSPIRAM)
#define ARDUINOSPI
#endif
/* Networking and keyboards need the background task capability */
#if defined(ARDUINOMQTT) || defined(ARDUINOETH) || defined(ARDUINOUSBKBD) || defined(ARDUINOZX81KBD)
#define ARDUINOBGTASK
#endif
/* picoserial is not a available on many platforms */
#ifdef USESPICOSERIAL
#ifndef UCSR0A
#undef USESPICOSERIAL
#endif
#endif
/*
* graphics adapter only when graphics hardware, overriding the
* language setting
* this is odd and can be removed later on
*/
#if !defined(ARDUINOTFT) && !defined(ARDUINOVGA) && !defined(ARDUINOILI9488) && !defined(ARDUINONOKIA51) && !defined(ARDUINOSSD1306) && !defined(ARDUINOMCUFRIEND) && !defined(ARDUINOGRAPHDUMMY)
#undef HASGRAPH
#endif
/*
* Keyboard library, on AVR systems Paul Stoffregens original
* PS2 library works.
* I recommend to use my patched version from
* https://github.com/slviajero/PS2Keyboard
* works with ESP, has keyboard.peek()
*/
#ifdef ARDUINOPS2
#include <PS2Keyboard.h>
#endif
/*
* The USB keyboard code - tested only on DUE and the like
* not really good
*/
#ifdef ARDUINOUSBKBD
#include <KeyboardController.h>
#endif
/*
* The ZX81 keyboard code - tested on AVR MEGA256
*/
#ifdef ARDUINOZX81KBD
#include <ZX81Keyboard.h>
#endif
/*
* ESPy stuff, pgmspace has changed location
*/
#ifdef ARDUINOPROGMEM
#ifdef ARDUINO_ARCH_ESP32
#include <pgmspace.h>
#else
#include <avr/pgmspace.h>
#endif
#endif
/*
* This works for AVR and ESP EEPROM dummy. Throws a
* compiler error for other platforms.
*/
#ifdef ARDUINOEEPROM
#include <EEPROM.h>
#endif
/* Standard SPI */
#ifdef ARDUINOSPI
#include <SPI.h>
#endif
/* Standard wire - triggered by the NEEDSWIRE macro now */
#ifdef NEEDSWIRE
#include <Wire.h>
#endif
/*
* the display library includes for LCD
*/
#ifdef LCDSHIELD
#include <LiquidCrystal.h>
#endif
/*
* I2C displays
*/
#ifdef ARDUINOLCDI2C
#include <LiquidCrystal_I2C.h>
#endif
/*
* This is the monochrome library of Oli Kraus
* https://github.com/olikraus/u8g2/wiki/u8g2reference
* It can harware scroll, but this is not yet implemented
*/
#if defined(ARDUINONOKIA51) || defined(ARDUINOSSD1306)
#include <U8g2lib.h>
#endif
/*
* This is the (old) ILI9488 library originally created by Jarett Burket
* https://github.com/slviajero/ILI9488
* It can hardware scroll (not yet used)
*/
#ifdef ARDUINOILI9488
#include <Adafruit_GFX.h>
#include <ILI9488.h>
#endif
/*
* This is the MCUFRIED library originally for parallel TFTs
* https://github.com/prenticedavid/MCUFRIEND_kbv
*
*/
#ifdef ARDUINOMCUFRIEND
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
#endif
/*
* For TFT we use the UTFT library
* http://www.rinkydinkelectronics.com/library.php?id=51
* please note the License, it is not GPL but NON COMMERCIAL
* Creative Commons.
*/
#ifdef ARDUINOTFT
#include <memorysaver.h>
#include <UTFT.h>
#endif
/*
* experimental networking code
* currently the standard Ethernet shield, ESP Wifi
* MKW Wifi, and RP2040 Wifi is supported. All of them
* with the standard library.
*
* In addition to this Pubsub is used
* https://github.com/slviajero/pubsubclient
* for MQTT
*/
#ifdef ARDUINOMQTT
#ifdef ARDUINOETH
#include <Ethernet.h>
#else
#ifdef ARDUINO_ARCH_ESP8266
#include <ESP8266WiFi.h>
#endif
#ifdef ARDUINO_ARCH_ESP32
#include <WiFi.h>
#endif
#if defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_SAMD)
#include <WiFiNINA.h>
#endif
#endif
#include <PubSubClient.h>
#endif
/*
* VGA is only implemented on one platform - TTGO VGA 1.4
* Needs https://github.com/slviajero/FabGL
*/
#if defined(ARDUINOVGA) && defined(ARDUINO_TTGO_T7_V14_Mini32)
#include <WiFi.h>
#include <fabgl.h>
#endif
/*
* SD filesystems with the standard SD driver
* for MEGA 256 a soft SPI solution is needed
* if standard shields are used, this is a patched
* SD library https://github.com/slviajero/SoftSD
*/
#ifdef ARDUINOSD
#define FILESYSTEMDRIVER
#if defined(SOFTWARE_SPI_FOR_SD)
#include <SoftSD.h>
#else
#include <SD.h>
#endif
#endif
/*
* ESPSPIFFS tested on ESP8266 and ESP32
* supports formating in BASIC
*/
#ifdef ESPSPIFFS
#define FILESYSTEMDRIVER
#ifdef ARDUINO_ARCH_ESP8266
#include <FS.h>
#endif
#ifdef ARDUINO_ARCH_ESP32
#include <FS.h>
#include <SPIFFS.h>
#endif
#endif
/*
* RP2040 internal filesystem
* This is test code from https://github.com/slviajero/littlefs
* and the main branch is actively developed
*/
#ifdef RP2040LITTLEFS
#define FILESYSTEMDRIVER
#define LFS_MBED_RP2040_VERSION_MIN_TARGET "LittleFS_Mbed_RP2040 v1.1.0"
#define LFS_MBED_RP2040_VERSION_MIN 1001000
#define _LFS_LOGLEVEL_ 1
#define RP2040_FS_SIZE_KB 1024
#define FORCE_REFORMAT false
#include <LittleFS_Mbed_RP2040.h>
#endif
/*
* external flash file systems override internal filesystems
* currently BASIC can only have one filesystem
*/
#ifdef ARDUINOSD
#undef ESPSPIFFS
#undef RP2040LITTLEFS
#endif
/*
* support for external EEPROMs as filesystem
* overriding all other filessystems. This is a minimalistic
* filesystem meant for very small systems with not enough
* memory for real filesystems
* https://github.com/slviajero/EepromFS
*/
#ifdef ARDUINOEFS
#undef ESPSPIFFS
#undef RP2040LITTLEFS
#undef ARDUINOSD
#define FILESYSTEMDRIVER
#endif
/* the EFS object is used for filesystems and raw EEPROM access */
#if (defined(ARDUINOI2CEEPROM) && defined(ARDUINOI2CEEPROM_BUFFERED)) || defined(ARDUINOEFS)
#include <EepromFS.h>
#endif
/* if there is an unbuffered I2C EEPROM, use an autodetect mechanism */
#if defined(ARDUINOI2CEEPROM)
unsigned int i2ceepromsize = 0;
#endif
/*
* Software SPI only on Mega2560
*/
#ifndef ARDUINO_AVR_MEGA2560
#undef SOFTWARE_SPI_FOR_SD
#endif
/*
* Arduino default serial baudrate and serial flags for the
* two supported serial interfaces. Serial is always active and
* connected to channel &1 with 9600 baud.
*
* channel 4 (ARDUINOPRT) can be either in character or block
* mode. Blockmode is set as default here. This means that all
* available characters are always loaded to a string -> inb()
*/
const int serial_baudrate = 9600;
mem_t sendcr = 0;
#ifdef ARDUINOPRT
int serial1_baudrate = 9600;
mem_t blockmode = 1;
#else
const int serial1_baudrate = 0;
mem_t blockmode = 0;
#endif
/* handling time - part of the Arduino core - only needed on POSIX OSes */
void timeinit() {}
/* starting wiring is only needed on raspberry */
void wiringbegin() {}
/*
* helper functions OS, heuristic on how much memory is
* available in BASIC
* Arduino information from
* data from https://docs.arduino.cc/learn/programming/memory-guide
*/
#if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_SAM)
extern "C" char* sbrk(int incr);
long freeRam() {
char top;
return &top - reinterpret_cast<char*>(sbrk(0));
}
#elif defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) || defined(ARDUINO_ARCH_LGT8F)
long freeRam() {
extern int __heap_start,*__brkval;
int v;
return (int)&v - (__brkval == 0
? (int)&__heap_start : (int) __brkval);
}
#elif defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
long freeRam() {
return ESP.getFreeHeap();
}
#else
long freeRam() {
return 0;
}
#endif
/*
* Heuristic Wifi systems reserve 4k by default, small 8 bit AVR try to guess sizes conservatively
* RP2040 cannot measure, we set to 16 bit full address space
*/
long freememorysize() {
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_SAMD)
return freeRam() - 4000;
#endif
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR) || defined(ARDUINO_ARCH_SAM) || defined(ARDUINO_ARCH_LGT8F)
int overhead=192;
#ifdef ARDUINOWIRE
overhead+=128;
#endif
#ifdef ARDUINORF24
overhead+=128;
#endif
#ifdef ARDUINOSD
overhead+=512;
#endif
#ifdef ARDUINOZX81KBD
overhead+=64;
#endif
#ifdef ARDUINOETH
overhead+=256;
#endif
#ifdef HASGRAPH
overhead+=256; /* a bit on the safe side */
#endif
return freeRam() - overhead;
#endif
#if defined(ARDUINO_NANO_RP2040_CONNECT) || defined(ARDUINO_RASPBERRY_PI_PICO)
return 65536;
#endif
return 0;
}
/*
* the sleep and restart functions - only implemented for some controllers
*/
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
void(* callzero)() = 0;
#endif
void restartsystem() {
eflush(); /* if there is a I2C eeprom dummy, flush the buffer */
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
ESP.restart();
#endif
#if defined(ARDUINO_ARCH_AVR) || defined(ARDUINO_ARCH_MEGAAVR)
callzero();
#endif
#if defined(ARDUINO_ARCH_LGT8F)
#endif
}
/*
* Used these two articles
* https://randomnerdtutorials.com/esp8266-deep-sleep-with-arduino-ide/
* https://randomnerdtutorials.com/esp32-deep-sleep-arduino-ide-wake-up-sources/
* for this very simple implementation - needs to be improved (pass data from sleep
* state to sleep state via EEPROM)
*/
#if defined(ARDUINO_ARCH_SAMD)
#include "RTCZero.h"
#include "ArduinoLowPower.h"
#endif
/* this is unfinished, don't use */
void rtcsqw();
#define LOWPOWERINTPIN 2
void aftersleepinterrupt(void) { }
void activatesleep(long t) {
eflush(); /* if there is a I2C eeprom dummy, flush the buffer */
#if defined(ARDUINO_ARCH_ESP8266)
ESP.deepSleep(t*1000);
#endif
#if defined(ARDUINO_ARCH_ESP32)
esp_sleep_enable_timer_wakeup(t*1000);
esp_deep_sleep_start();
#endif
#if defined(ARDUINO_ARCH_SAMD)
LowPower.sleep((int) t);
#endif
#if defined(ARDUINO_AVR_ATmega644)
/* unfinished, don't use, just test code
rtcsqw();
pinMode(LOWPOWERINTPIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(LOWPOWERINTPIN), aftersleepinterrupt, CHANGE);
sleepMode(SLEEP_POWER_SAVE);
sleep();
detachInterrupt(digitalPinToInterrupt(LOWPOWERINTPIN));
noSleep();
*/
#endif
}
/*