fixup examples based on default pin #define-s and also support them being undefined
This commit is contained in:
committed by
Graham Sanderson
parent
9c7e31b8e7
commit
82b6dc0576
@@ -22,6 +22,7 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include "pico/stdlib.h"
|
||||
#include "pico/binary_info.h"
|
||||
#include "hardware/i2c.h"
|
||||
|
||||
// I2C reserves some addresses for special purposes. We exclude these from the scan.
|
||||
@@ -33,13 +34,18 @@ bool reserved_addr(uint8_t addr) {
|
||||
int main() {
|
||||
// Enable UART so we can print status output
|
||||
stdio_init_all();
|
||||
|
||||
// This example will use I2C0 on GPIO4 (SDA) and GPIO5 (SCL)
|
||||
i2c_init(i2c0, 100 * 1000);
|
||||
gpio_set_function(4, GPIO_FUNC_I2C);
|
||||
gpio_set_function(5, GPIO_FUNC_I2C);
|
||||
gpio_pull_up(4);
|
||||
gpio_pull_up(5);
|
||||
#if !defined(i2c_default) || !defined(PICO_DEFAULT_I2C_SDA_PIN) || !defined(PICO_DEFAULT_I2C_SCL_PIN)
|
||||
#warning i2c/bus_scane example requires a board with I2C pins
|
||||
puts("Default I2C pins were not defined");
|
||||
#else
|
||||
// This example will use I2C0 on the default SDA and SCL pins (4, 5 on a Pico)
|
||||
i2c_init(i2c_default, 100 * 1000);
|
||||
gpio_set_function(PICO_DEFAULT_I2C_SDA_PIN, GPIO_FUNC_I2C);
|
||||
gpio_set_function(PICO_DEFAULT_I2C_SCL_PIN, GPIO_FUNC_I2C);
|
||||
gpio_pull_up(PICO_DEFAULT_I2C_SDA_PIN);
|
||||
gpio_pull_up(PICO_DEFAULT_I2C_SCL_PIN);
|
||||
// Make the I2C pins available to picotool
|
||||
bi_decl(bi_2pins_with_func(PICO_DEFAULT_I2C_SDA_PIN, PICO_DEFAULT_I2C_SCL_PIN, GPIO_FUNC_I2C));
|
||||
|
||||
printf("\nI2C Bus Scan\n");
|
||||
printf(" 0 1 2 3 4 5 6 7 8 9 A B C D E F\n");
|
||||
@@ -67,4 +73,5 @@ int main() {
|
||||
}
|
||||
printf("Done.\n");
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user