77#include < Arduino.h>
88#include " zephyrInternal.h"
99
10+
1011namespace {
1112
1213struct device gpio0;
@@ -17,47 +18,40 @@ static constexpr uint32_t pins[] = {16u, 32u}; // exclusive-upper
1718static constexpr size_t NUM_PORTS = sizeof (gpios) / sizeof (gpios[0 ]);
1819
1920
20- constexpr pin_size_t local_gpio_pin (int ) {
21- return 0 ;
22- }
23-
2421/* グローバル → gpio* を探す */
25- constexpr const struct device *
26- local_gpio_port_recursive (size_t pin, const struct device *const *ctrl,
22+ constexpr const struct device * local_gpio_port_recursive (pin_size_t pin, const struct device *const *ctrl,
2723 const uint32_t *end, size_t n) {
2824 return (n == 0 ) ? nullptr
2925 : (pin < end[0 ]) ? ctrl[0 ]
3026 : local_gpio_port_recursive (pin, ctrl + 1 , end + 1 , n - 1 );
3127}
3228
33- constexpr const struct device *local_gpio_port (size_t pin ) {
34- return local_gpio_port_recursive (pin , gpios, pins, NUM_PORTS);
29+ constexpr const struct device *local_gpio_port (pin_size_t gpin ) {
30+ return local_gpio_port_recursive (gpin , gpios, pins, NUM_PORTS);
3531}
3632
3733/* ポートインデックスを取得(見つからなければ size_t(-1)) */
38- constexpr size_t port_index_recursive (const struct device *target,
34+ constexpr pin_size_t port_index_recursive (const struct device *target,
3935 const struct device *const *table,
40- size_t idx, size_t n) {
36+ pin_size_t idx, size_t n) {
4137 return (n == 0 ) ? size_t (-1 )
4238 : (target == table[0 ])
4339 ? idx
4440 : port_index_recursive (target, table + 1 , idx + 1 , n - 1 );
4541}
4642
47- pin_size_t global_gpio_pin (const struct device *port, size_t local_pin) noexcept {
48- size_t pidx = port_index_recursive (port, gpios, 0 , NUM_PORTS);
49- size_t base = (pidx == 0 ) ? 0 : pins[pidx - 1 ];
50- size_t width = pins[pidx] - base;
43+ constexpr pin_size_t local_gpio_pin (pin_size_t gpin) {
44+ return gpin - pins[port_index_recursive (local_gpio_port (gpin), gpios, 0 , NUM_PORTS)];
45+ }
5146
52- return ((local_pin < width) ? base + local_pin : size_t (-1 ));
47+ constexpr pin_size_t global_gpio_pin (const struct device *lport, pin_size_t lpin) noexcept {
48+ return pins[port_index_recursive (lport, gpios, 0 , NUM_PORTS)] + lpin;
5349}
5450
5551constexpr uint32_t local_gpio_dt_flags (int ) {
5652 return 0 ;
5753}
5854
59-
60-
6155template <class N , class Head > constexpr const N max_in_list (const N max, const Head &head)
6256{
6357 return (max >= head) ? max : head;
0 commit comments