Skip to content

Commit 91441de

Browse files
committed
update i2c and spi examples to only have built in interfaces by default, custom interface can be tested by user defined pins
1 parent a494e3f commit 91441de

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

libraries/Apollo3/examples/I2C/I2C.ino

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
#include "Wire.h"
3838

39+
void testPortI2C(TwoWire &i2c);
40+
3941
// This thread will use the pre-defined SPI object if it exists
4042
#if VARIANT_WIRE_INTFCS > 0
4143
rtos::Thread wire_thread;
@@ -55,16 +57,18 @@ void wire1_thread_fn( void ){
5557
delay(100);
5658
Wire1.begin();
5759
while(1){
58-
testPortWire(Wire1);
60+
testPortI2C(Wire1);
5961
delay(1000);
6062
}
6163
}
6264
#endif
6365

6466
// This thread will create its own MbedI2C object using IOM pins
65-
#define mySDA D25
66-
#define mySCL D27
67-
MbedI2C myWire(mySDA, mySCL);
67+
// Define your own pins below to try it
68+
//#define mySDA D25
69+
//#define mySCL D27
70+
#if (defined mySDA) && (defined mySCL)
71+
TwoWire myWire(mySDA, mySCL);
6872
rtos::Thread mywire_thread;
6973
void mywire_thread_fn( void ){
7074
delay(200);
@@ -74,8 +78,9 @@ void mywire_thread_fn( void ){
7478
delay(1000);
7579
}
7680
}
81+
#endif
7782

78-
void testPortI2C(MbedI2C &i2c){
83+
void testPortI2C(TwoWire &i2c){
7984
Serial.printf("Scanning... (port: 0x%08X), time (ms): %d\n", (uint32_t)&i2c, millis());
8085

8186
uint8_t detected = 0;
@@ -111,12 +116,14 @@ void setup() {
111116
wire1_thread.start(wire1_thread_fn);
112117
#endif
113118

119+
#if (defined mySDA) && (defined mySCL)
114120
mywire_thread.start(mywire_thread_fn);
121+
#endif
115122
}
116123

117124
void loop() {
118125
digitalWrite(LED_BUILTIN, LOW);
119126
delay(1000);
120127
digitalWrite(LED_BUILTIN, HIGH);
121128
delay(1000);
122-
}
129+
}

libraries/Apollo3/examples/SPI/SPI.ino

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@
4646
// define pins to create a custom SPI port
4747
// using mbed PinNames or Arduino pin numbers
4848
// (must be all pins from one IOM module)
49-
#define mySDI D25
50-
#define mySDO D28
51-
#define myCLK D27
52-
49+
//#define mySDI D25
50+
//#define mySDO D28
51+
//#define myCLK D27
52+
#if (defined mySDI) && (defined mySDO) && (defined myCLK)
5353
MbedSPI mySPI(mySDI, mySDO, myCLK); // declare the custom MbedSPI object mySPI
54+
#endif
5455

5556
// define a macro to aid testing
5657
#define TEST_SPI_PORT(P) SERIAL_PORT.printf("testing %s\n\ttime (ms): %d\n\tbyte transer: %s\n\tbuffer transfer: %s\n\n", #P, millis(), ((test_byte_transfer(P) == 0) ? "pass" : "fail"), ((test_buffer_transfer(P) == 0) ? "pass" : "fail"))
@@ -68,7 +69,9 @@ void spi_thread_fn( void ){
6869
#endif
6970
}
7071

72+
7173
// this thread tests the custom mySPI object
74+
#if (defined mySDI) && (defined mySDO) && (defined myCLK)
7275
extern "C" SPIName spi_get_peripheral_name(PinName mosi, PinName miso, PinName sclk); // this mbed internal function determines the IOM module number for a set of pins
7376
rtos::Thread myspi_thread;
7477
void myspi_thread_fn( void ){
@@ -80,6 +83,7 @@ void myspi_thread_fn( void ){
8083
delay(500);
8184
}
8285
}
86+
#endif
8387

8488
int test_byte_transfer( SPIClass &spi ){
8589
uint8_t tx = random(1, 256);
@@ -125,7 +129,9 @@ void setup() {
125129
digitalWrite(CS_PIN, HIGH);
126130

127131
spi_thread.start(spi_thread_fn);
132+
#if (defined mySDI) && (defined mySDO) && (defined myCLK)
128133
myspi_thread.start(myspi_thread_fn);
134+
#endif
129135
}
130136

131137
void loop() {

0 commit comments

Comments
 (0)