|
37 | 37 |
|
38 | 38 | #undef DIGITAL_PIN_CHECK_UNIQUE
|
39 | 39 |
|
| 40 | +#ifndef LED_BUILTIN |
| 41 | + |
| 42 | +/* Return the index of it if matched, oterwise return 0 */ |
| 43 | +#define LED_BUILTIN_INDEX_BY_REG_AND_PINNUM(n, p, i, dev, num) \ |
| 44 | + (DIGITAL_PIN_EXISTS(n, p, i, dev, num) ? i : 0) |
| 45 | + |
| 46 | +/* Only matched pin returns non-zero value, so the sum is matched pin's index */ |
| 47 | +#define LED_BUILTIN_FIND_DIGITAL_PIN(dev, pin) \ |
| 48 | + DT_FOREACH_PROP_ELEM_SEP_VARGS(DT_PATH(zephyr_user), digital_pin_gpios, \ |
| 49 | + LED_BUILTIN_INDEX_BY_REG_AND_PINNUM, (+), dev, pin) |
| 50 | + |
| 51 | +#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), builtin_led_gpios) && \ |
| 52 | + (DT_PROP_LEN(DT_PATH(zephyr_user), builtin_led_gpios) > 0) |
| 53 | + |
| 54 | +#if !(DT_FOREACH_PROP_ELEM_SEP_VARGS( \ |
| 55 | + DT_PATH(zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, (+), \ |
| 56 | + DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0)), \ |
| 57 | + DT_PHA_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0, pin)) > 0) |
| 58 | +#warning "pin not found in digital_pin_gpios" |
| 59 | +#else |
| 60 | +#define LED_BUILTIN \ |
| 61 | + LED_BUILTIN_FIND_DIGITAL_PIN( \ |
| 62 | + DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0)), \ |
| 63 | + DT_PHA_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0, pin)) |
| 64 | +#endif |
| 65 | + |
| 66 | +/* If digital-pin-gpios is not defined, tries to use the led0 alias */ |
| 67 | +#elif DT_NODE_EXISTS(DT_ALIAS(led0)) |
| 68 | + |
| 69 | +#if !(DT_FOREACH_PROP_ELEM_SEP_VARGS(DT_PATH(zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, \ |
| 70 | + (+), DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_ALIAS(led0), gpios, 0)), \ |
| 71 | + DT_PHA_BY_IDX(DT_ALIAS(led0), gpios, 0, pin)) > 0) |
| 72 | +#warning "pin not found in digital_pin_gpios" |
| 73 | +#else |
| 74 | +#define LED_BUILTIN \ |
| 75 | + LED_BUILTIN_FIND_DIGITAL_PIN(DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_ALIAS(led0), gpios, 0)), \ |
| 76 | + DT_PHA_BY_IDX(DT_ALIAS(led0), gpios, 0, pin)) |
| 77 | +#endif |
| 78 | + |
| 79 | +#endif // builtin_led_gpios |
| 80 | + |
| 81 | +#endif // LED_BUILTIN |
| 82 | + |
40 | 83 | #define DN_ENUMS(n, p, i) D##i = i
|
41 | 84 |
|
42 | 85 | /*
|
|
0 commit comments