|
23 | 23 | DT_FOREACH_PROP_ELEM_VARGS(DT_PATH(zephyr_user), gpio_ports, ZARD_ACCUM_NGPIOS, \
|
24 | 24 | DT_PHANDLE_BY_IDX(n, p, i)) \
|
25 | 25 | DT_PHA_BY_IDX(n, p, i, pin)
|
| 26 | +#define DIGITAL_PIN_EXISTS(n, p, i, dev, num) \ |
| 27 | + (((dev == DT_REG_ADDR(DT_PHANDLE_BY_IDX(n, p, i))) && \ |
| 28 | + (num == DT_PHA_BY_IDX(n, p, i, pin))) \ |
| 29 | + ? 1 \ |
| 30 | + : 0) |
| 31 | + |
| 32 | +/* Check all pins are defined only once */ |
| 33 | +#define DIGITAL_PIN_CHECK_UNIQUE(i, _) \ |
| 34 | + ((DT_FOREACH_PROP_ELEM_SEP_VARGS( \ |
| 35 | + DT_PATH(zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, (+), \ |
| 36 | + DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), digital_pin_gpios, i)), \ |
| 37 | + DT_PHA_BY_IDX(DT_PATH(zephyr_user), digital_pin_gpios, i, pin))) == 1) |
| 38 | + |
| 39 | +#if !LISTIFY(DT_PROP_LEN(DT_PATH(zephyr_user), digital_pin_gpios), DIGITAL_PIN_CHECK_UNIQUE, (&&)) |
| 40 | +#error "digital_pin_gpios has duplicate definition" |
| 41 | +#endif |
| 42 | + |
| 43 | +#undef DIGITAL_PIN_CHECK_UNIQUE |
26 | 44 |
|
27 | 45 | #ifndef LED_BUILTIN
|
| 46 | + |
| 47 | +/* Return the index of it if matched, oterwise return 0 */ |
| 48 | +#define LED_BUILTIN_INDEX_BY_REG_AND_PINNUM(n, p, i, dev, num) \ |
| 49 | + (DIGITAL_PIN_EXISTS(n, p, i, dev, num) ? i : 0) |
| 50 | + |
| 51 | +/* Only matched pin returns non-zero value, so the sum is matched pin's index */ |
| 52 | +#define DIGITAL_PIN_GPIOS_FIND_PIN(dev, pin) \ |
| 53 | + DT_FOREACH_PROP_ELEM_SEP_VARGS(DT_PATH(zephyr_user), digital_pin_gpios, \ |
| 54 | + LED_BUILTIN_INDEX_BY_REG_AND_PINNUM, (+), dev, pin) |
| 55 | + |
28 | 56 | #if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), builtin_led_gpios) && \
|
29 | 57 | (DT_PROP_LEN(DT_PATH(zephyr_user), builtin_led_gpios) > 0)
|
30 | 58 | #define LED_BUILTIN ZARD_GLOBAL_GPIO_NUM(DT_PATH(zephyr_user), builtin_led_gpios, 0)
|
|
0 commit comments