1
+ /*
2
+ * This sketch is for CI build purpose.
3
+ * It allows to test build of built-in libraries
4
+ * and can not be executed.
5
+ */
6
+
7
+ #include < EEPROM.h>
8
+ #ifndef STM32MP1xx
9
+ #include < IWatchdog.h>
10
+ #endif
11
+ #ifdef TIMER_SERVO
12
+ #include < Servo.h>
13
+ #endif
14
+ #include < SPI.h>
15
+ #include < SoftwareSerial.h>
16
+ #include < Wire.h>
17
+
18
+ #ifndef USER_BTN
19
+ #define USER_BTN 2
20
+ #endif
21
+
22
+ #ifndef LED_BUILTIN
23
+ #define LED_BUILTIN 13
24
+ #endif
25
+
26
+ #ifndef PIN_SERIAL_RX
27
+ #define PIN_SERIAL_RX 0
28
+ #endif
29
+
30
+ #ifndef PIN_SERIAL_TX
31
+ #define PIN_SERIAL_TX 1
32
+ #endif
33
+
34
+ #ifndef Serial
35
+ HardwareSerial Serial (PIN_SERIAL_RX, PIN_SERIAL_TX);
36
+ #endif
37
+
38
+ #ifdef TIMER_SERVO
39
+ Servo servo;
40
+ #endif
41
+ SoftwareSerial swSerial (10 , 11 );
42
+
1
43
void setup () {
2
- // put your setup code here, to run once:
44
+ // Serial HW & SW
45
+ #if !defined(USBD_USE_CDC) && !defined(DISABLE_GENERIC_SERIALUSB)
46
+ Serial.setRx (PIN_SERIAL_RX);
47
+ Serial.setTx (digitalPinToPinName (PIN_SERIAL_TX));
48
+ #endif
49
+ Serial.begin (9600 ); // start serial for output
50
+ while (!Serial) {};
51
+
52
+ swSerial.begin (4800 );
53
+ swSerial.write (" x" );
54
+ if (!swSerial.isListening ()) {
55
+ swSerial.listen ();
56
+ if (swSerial.available ()) {
57
+ swSerial.read ();
58
+ }
59
+ }
60
+ swSerial.end ();
61
+
62
+ // EEPROM
63
+ byte value = EEPROM.read (0x01 );
64
+ EEPROM.write (EEPROM.length ()-1 , value);
65
+
66
+ #ifndef STM32MP1xx
67
+ // IWDG
68
+ if (!IWatchdog.isReset (true )) {
69
+ IWatchdog.begin (10000000 );
70
+ IWatchdog.isEnabled ();
71
+ }
72
+ IWatchdog.reload ();
73
+ #endif
3
74
75
+ #ifdef TIMER_SERVO
76
+ // Servo
77
+ servo.attach (3 , 900 , 2100 );
78
+ servo.write (1500 );
79
+ servo.detach ();
80
+ #endif
81
+
82
+ // SPI
83
+ SPISettings settings (SPI_SPEED_CLOCK_DEFAULT, MSBFIRST, SPI_MODE_0);
84
+ SPI.setMISO (PIN_SPI_MISO);
85
+ SPI.setMOSI (PIN_SPI_MOSI);
86
+ SPI.setSCLK (PIN_SPI_SCK);
87
+ SPI.setSSEL (digitalPinToPinName (PIN_SPI_SS));
88
+ SPI.begin (PIN_SPI_SS);
89
+ SPI.beginTransaction (1 , settings);
90
+ SPI.endTransaction ();
91
+ SPI.transfer (1 );
92
+ SPI.end ();
93
+
94
+ // Wire
95
+ Wire.setSCL (PIN_WIRE_SCL);
96
+ Wire.setSDA (digitalPinToPinName (PIN_WIRE_SDA));
97
+ Wire.setClock (400000 );
98
+ Wire.begin (4 );
99
+ Wire.onRequest (requestEvent);
100
+ Wire.onReceive (receiveEvent);
101
+ Wire.beginTransmission (4 );
102
+ Wire.endTransmission ();
103
+ Wire.requestFrom (2 , 1 );
104
+ Wire.end ();
4
105
}
5
106
6
107
void loop () {
7
- // put your main code here, to run repeatedly:
108
+ }
8
109
110
+ // Wire
111
+ // function that executes whenever data is received from master
112
+ // this function is registered as an event, see setup()
113
+ void receiveEvent (int ) {
114
+ while (1 < Wire.available ()) {
115
+ Wire.read ();
116
+ }
9
117
}
118
+ // function that executes whenever data is requested by master
119
+ // this function is registered as an event, see setup()
120
+ void requestEvent () {
121
+ Wire.write (" x" );
122
+ }
0 commit comments