I'm working on the example program 'i2c/bus_scan/bus_scan.c' in the Pico SDK, and there's something I don't understand:
This section of code is included in 'main () { }' :
I think these are called preprocessor directives (??), and I was under the impression that preprocessor directives can go anywhere in the program.
At any rate, when I move this section of code outside of main, and try to compile it, I get many errors.
Why must this code be included in main? And, what must be done to move it outside of main so that it compiles successfully?
This section of code is included in 'main () { }' :
Code:
#if !defined(i2c_default) || !defined(PICO_DEFAULT_I2C_SDA_PIN) || !defined(PICO_DEFAULT_I2C_SCL_PIN)#warning i2c/bus_scan 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 (GP4, GP5 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));
I think these are called preprocessor directives (??), and I was under the impression that preprocessor directives can go anywhere in the program.
At any rate, when I move this section of code outside of main, and try to compile it, I get many errors.
Why must this code be included in main? And, what must be done to move it outside of main so that it compiles successfully?
Statistics: Posted by irishmonk-57 — Wed Jan 31, 2024 7:28 am — Replies 4 — Views 103