diff options
| author | arturo182 <arturo182@tlen.pl> | 2018-06-20 23:26:32 +0200 |
|---|---|---|
| committer | arturo182 <arturo182@tlen.pl> | 2018-06-20 23:26:32 +0200 |
| commit | c2d4d0a10bb97819ad94b7b770f59f8b9df64c41 (patch) | |
| tree | 845aa669e6a589de4f3306427e9ea53cde080d25 | |
| parent | ff918556cdde90119339c35093911d70eec43406 (diff) | |
nrf: Simplify pin generation and definition
This commit cleans up the pin generation code, all the pins and their
AF (only ADC, for now) are specified in nrf52_af.csv and board use their
own csv file to specify which pins are available on that board and if
they have any special names.
| -rw-r--r-- | ports/nrf/Makefile | 10 | ||||
| -rw-r--r-- | ports/nrf/boards/feather52832/pins.csv | 16 | ||||
| -rw-r--r-- | ports/nrf/boards/feather52840/pins.csv | 16 | ||||
| -rw-r--r-- | ports/nrf/boards/make-pins.py | 46 | ||||
| -rw-r--r-- | ports/nrf/boards/nrf52_prefix.c | 4 | ||||
| -rw-r--r-- | ports/nrf/boards/pca10056/pins.csv | 18 | ||||
| -rw-r--r-- | ports/nrf/common-hal/microcontroller/Pin.h | 5 | ||||
| -rw-r--r-- | ports/nrf/modules/machine/pin.h | 112 | ||||
| -rw-r--r-- | ports/nrf/mpconfigport.h | 1 | ||||
| -rw-r--r-- | ports/nrf/nrf52_af.csv | 96 | ||||
| -rw-r--r-- | ports/nrf/pin.h (renamed from ports/nrf/pin_defs_nrf5.h) | 23 | ||||
| -rw-r--r-- | ports/nrf/pin_named_pins.c | 92 |
12 files changed, 102 insertions, 337 deletions
diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index abc0e3365..74613397c 100644 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -47,7 +47,6 @@ INC += -I./device INC += -I./device/$(MCU_VARIANT) INC += -I./hal INC += -I./hal/$(MCU_VARIANT) -INC += -I./modules/machine INC += -I./modules/ubluepy INC += -I./modules/music INC += -I./modules/random @@ -109,7 +108,6 @@ SRC_HAL = $(addprefix hal/,\ SRC_C += \ mphalport.c \ help.c \ - pin_named_pins.c \ fatfs_port.c \ fifo.c \ tick.c \ @@ -295,10 +293,10 @@ SRC_QSTR_AUTO_DEPS += $(OBJ): | $(HEADER_BUILD)/pins.h # Use a pattern rule here so that make will only call make-pins.py once to make -# both pins_$(BOARD).c and pins.h -$(BUILD)/%_gen.c $(HEADER_BUILD)/%.h $(HEADER_BUILD)/%_af_const.h $(BUILD)/%_qstr.h: boards/$(BOARD)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD) +# both pins_g.c and pins.h +$(BUILD)/%_gen.c $(HEADER_BUILD)/%.h $(BUILD)/%_qstr.h: boards/$(BOARD)/%.csv $(MAKE_PINS) $(AF_FILE) $(PREFIX_FILE) | $(HEADER_BUILD) $(ECHO) "Create $@" - $(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE) --prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) --qstr $(GEN_PINS_QSTR) --af-const $(GEN_PINS_AF_CONST) --af-py $(GEN_PINS_AF_PY) > $(GEN_PINS_SRC) + $(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --af $(AF_FILE) --prefix $(PREFIX_FILE) --hdr $(GEN_PINS_HDR) --qstr $(GEN_PINS_QSTR) > $(GEN_PINS_SRC) $(BUILD)/pins_gen.o: $(BUILD)/pins_gen.c $(call compile_c) @@ -310,8 +308,6 @@ PREFIX_FILE = boards/$(MCU_VARIANT)_prefix.c GEN_PINS_SRC = $(BUILD)/pins_gen.c GEN_PINS_HDR = $(HEADER_BUILD)/pins.h GEN_PINS_QSTR = $(BUILD)/pins_qstr.h -GEN_PINS_AF_CONST = $(HEADER_BUILD)/pins_af_const.h -GEN_PINS_AF_PY = $(BUILD)/pins_af.py ifneq ($(FROZEN_DIR),) # To use frozen source modules, put your .py files in a subdirectory (eg scripts/) diff --git a/ports/nrf/boards/feather52832/pins.csv b/ports/nrf/boards/feather52832/pins.csv index 3ffab88d4..c04190064 100644 --- a/ports/nrf/boards/feather52832/pins.csv +++ b/ports/nrf/boards/feather52832/pins.csv @@ -1,7 +1,7 @@ -A0,P0_02,ADC0_IN0 -A1,P0_03,ADC0_IN1 -A2,P0_04,ADC0_IN2 -A3,P0_05,ADC0_IN3 +A0,P0_02 +A1,P0_03 +A2,P0_04 +A3,P0_05 TX,P0_06 RX,P0_08 NFC1,P0_09 @@ -18,7 +18,7 @@ DFU,P0_20 SDA,P0_25 SCL,P0_26 D27,P0_27 -A4,P0_28,ADC0_IN4 -A5,P0_29,ADC0_IN5 -A6,P0_30,ADC0_IN6 -A7,P0_31,ADC0_IN7 +A4,P0_28 +A5,P0_29 +A6,P0_30 +A7,P0_31 diff --git a/ports/nrf/boards/feather52840/pins.csv b/ports/nrf/boards/feather52840/pins.csv index 5611dc34b..284370d06 100644 --- a/ports/nrf/boards/feather52840/pins.csv +++ b/ports/nrf/boards/feather52840/pins.csv @@ -1,9 +1,9 @@ P0_00,P0_00 P0_01,P0_01 -P0_02,P0_02,ADC0_IN0 -P0_03,P0_03,ADC0_IN1 -P0_04,P0_04,ADC0_IN2 -P0_05,P0_05,ADC0_IN3 +P0_02,P0_02 +P0_03,P0_03 +P0_04,P0_04 +P0_05,P0_05 P0_06,P0_06 P0_07,P0_07 P0_08,P0_08 @@ -26,10 +26,10 @@ P0_24,P0_24 P0_25,P0_25 P0_26,P0_26 P0_27,P0_27 -P0_28,P0_28,ADC0_IN4 -P0_29,P0_29,ADC0_IN5 -P0_30,P0_30,ADC0_IN6 -P0_31,P0_31,ADC0_IN7 +P0_28,P0_28 +P0_29,P0_29 +P0_30,P0_30 +P0_31,P0_31 P1_00,P1_00 P1_01,P1_01 P1_02,P1_02 diff --git a/ports/nrf/boards/make-pins.py b/ports/nrf/boards/make-pins.py index 5fe600507..d1cfd5b70 100644 --- a/ports/nrf/boards/make-pins.py +++ b/ports/nrf/boards/make-pins.py @@ -23,18 +23,6 @@ def parse_port_pin(name_str): return (port, int(pin_str)) -def split_name_num(name_num): - num = None - for num_idx in range(len(name_num) - 1, -1, -1): - if not name_num[num_idx].isdigit(): - name = name_num[0:num_idx + 1] - num_str = name_num[num_idx + 1:] - if len(num_str) > 0: - num = int(num_str) - break - return name, num - - class Pin(object): """Holds the information associated with a pin.""" @@ -54,10 +42,9 @@ class Pin(object): self.board_pin = True def parse_adc(self, adc_str): - if (adc_str[:3] != 'ADC'): + if (adc_str[:3] != 'AIN'): return - (adc, channel) = adc_str.split('_IN') - self.adc_channel = 'SAADC_CH_PSELP_PSELP_AnalogInput%d' % int(channel) + self.adc_channel = 'SAADC_CH_PSELP_PSELP_AnalogInput%d' % int(adc_str[3]) def print(self): print('const pin_obj_t pin_{:s} = PIN({:s}, {:d}, {:d}, {:s});'.format( @@ -94,20 +81,17 @@ class Pins(object): if pin.port == port_num and pin.pin == pin_num: return pin - def parse_af_file(self, filename, pinname_col, af_col, af_col_end): + def parse_af_file(self, filename): with open(filename, 'r') as csvfile: rows = csv.reader(csvfile) for row in rows: try: - (port_num, pin_num) = parse_port_pin(row[pinname_col]) + (port_num, pin_num) = parse_port_pin(row[0]) except: continue pin = Pin(port_num, pin_num) - for af_idx in range(af_col, len(row)): - if af_idx < af_col_end: - pin.parse_af(af_idx - af_col, row[af_idx]) - elif af_idx == af_col_end: - pin.parse_adc(row[af_idx]) + if len(row) > 1: + pin.parse_adc(row[1]) self.cpu_pins.append(NamedPin(pin.cpu_pin_name(), pin)) def parse_board_file(self, filename): @@ -121,8 +105,6 @@ class Pins(object): pin = self.find_pin(port_num, pin_num) if pin: pin.set_is_board_pin() - if len(row) == 3: - pin.parse_adc(row[2]) self.board_pins.append(NamedPin(row[0], pin)) def print_named(self, label, named_pins): @@ -173,19 +155,7 @@ def main(): "-a", "--af", dest="af_filename", help="Specifies the alternate function file for the chip", - default="nrf.csv" - ) - parser.add_argument( - "--af-const", - dest="af_const_filename", - help="Specifies header file for alternate function constants.", - default="build/pins_af_const.h" - ) - parser.add_argument( - "--af-py", - dest="af_py_filename", - help="Specifies the filename for the python alternate function mappings.", - default="build/pins_af.py" + default="nrf_af.csv" ) parser.add_argument( "-b", "--board", @@ -218,7 +188,7 @@ def main(): print('//') if args.af_filename: print('// --af {:s}'.format(args.af_filename)) - pins.parse_af_file(args.af_filename, 1, 2, 2) + pins.parse_af_file(args.af_filename) if args.board_filename: print('// --board {:s}'.format(args.board_filename)) diff --git a/ports/nrf/boards/nrf52_prefix.c b/ports/nrf/boards/nrf52_prefix.c index f9b25a851..e6c622da7 100644 --- a/ports/nrf/boards/nrf52_prefix.c +++ b/ports/nrf/boards/nrf52_prefix.c @@ -10,7 +10,7 @@ { \ { &mcu_pin_type }, \ .name = MP_QSTR_ ## p_name, \ - .port = PORT_ ## p_port, \ + .port = (p_port), \ .pin = (p_pin), \ - .adc_channel = p_adc_channel, \ + .adc_channel = (p_adc_channel), \ } diff --git a/ports/nrf/boards/pca10056/pins.csv b/ports/nrf/boards/pca10056/pins.csv index a4e4e8d5d..52b7a15f6 100644 --- a/ports/nrf/boards/pca10056/pins.csv +++ b/ports/nrf/boards/pca10056/pins.csv @@ -1,9 +1,9 @@ -P0_00,PA0 +P0_00,P0_01 P0_01,P0_01 -P0_02,P0_02,ADC0_IN0 -P0_03,P0_03,ADC0_IN1 -P0_04,P0_04,ADC0_IN2 -P0_05,P0_05,ADC0_IN3 +P0_02,P0_02 +P0_03,P0_03 +P0_04,P0_04 +P0_05,P0_05 P0_06,P0_06 P0_07,P0_07 P0_08,P0_08 @@ -26,10 +26,10 @@ P0_24,P0_24 P0_25,P0_25 P0_26,P0_26 P0_27,P0_27 -P0_28,P0_28,ADC0_IN4 -P0_29,P0_29,ADC0_IN5 -P0_30,P0_30,ADC0_IN6 -P0_31,P0_31,ADC0_IN7 +P0_28,P0_28 +P0_29,P0_29 +P0_30,P0_30 +P0_31,P0_31 P1_00,P1_00 P1_01,P1_01 P1_02,P1_02 diff --git a/ports/nrf/common-hal/microcontroller/Pin.h b/ports/nrf/common-hal/microcontroller/Pin.h index d7994bc0c..b04151184 100644 --- a/ports/nrf/common-hal/microcontroller/Pin.h +++ b/ports/nrf/common-hal/microcontroller/Pin.h @@ -27,14 +27,11 @@ #ifndef MICROPY_INCLUDED_NRF_COMMON_HAL_MICROCONTROLLER_PIN_H #define MICROPY_INCLUDED_NRF_COMMON_HAL_MICROCONTROLLER_PIN_H +#include "pin.h" #include "py/mphal.h" -#include "modules/machine/pin.h" -//typedef pin_obj_t mcu_pin_obj_t; #define mcu_pin_obj_t pin_obj_t void reset_all_pins(void); void reset_pin(uint8_t pin); -//void claim_pin(const mcu_pin_obj_t* pin); - #endif // MICROPY_INCLUDED_NRF_COMMON_HAL_MICROCONTROLLER_PIN_H diff --git a/ports/nrf/modules/machine/pin.h b/ports/nrf/modules/machine/pin.h deleted file mode 100644 index c34726174..000000000 --- a/ports/nrf/modules/machine/pin.h +++ /dev/null @@ -1,112 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef __MICROPY_INCLUDED_NRF5_PIN_H__ -#define __MICROPY_INCLUDED_NRF5_PIN_H__ - -// This file requires pin_defs_xxx.h (which has port specific enums and -// defines, so we include it here. It should never be included directly - -#include MICROPY_PIN_DEFS_PORT_H -#include "py/obj.h" - -typedef struct { - mp_obj_base_t base; - qstr name; - uint8_t idx; - uint8_t fn; - uint8_t unit; - uint8_t type; - - union { - void *reg; - }; -} pin_af_obj_t; - -typedef struct { - mp_obj_base_t base; - qstr name; - - uint32_t port : 1; - uint32_t pin : 5; // Some ARM processors use 32 bits/PORT - uint32_t num_af : 4; - uint32_t adc_channel : 4; // 0 is no ADC, ADC channel from 1 to 8 - -// uint32_t pin_mask; - pin_gpio_t *gpio; - const pin_af_obj_t *af; - uint32_t pull; -} pin_obj_t; - -// Adafruit -extern const mp_obj_type_t mcu_pin_type; - -extern const mp_obj_type_t pin_type; -extern const mp_obj_type_t pin_af_type; - -typedef struct { - const char *name; - const pin_obj_t *pin; -} pin_named_pin_t; - -extern const pin_named_pin_t pin_board_pins[]; -extern const pin_named_pin_t pin_cpu_pins[]; - -//extern pin_map_obj_t pin_map_obj; - -typedef struct { - mp_obj_base_t base; - qstr name; - const pin_named_pin_t *named_pins; -} pin_named_pins_obj_t; - -extern const mp_obj_type_t pin_board_pins_obj_type; -extern const mp_obj_type_t pin_cpu_pins_obj_type; - -//extern const mp_obj_dict_t pin_cpu_pins_locals_dict; -//extern const mp_obj_dict_t pin_board_pins_locals_dict; - -// Adafruit modification for CircuitPython board module -extern const mp_obj_dict_t mcu_pin_globals; -extern const mp_obj_dict_t board_module_globals; - -#define pin_cpu_pins_locals_dict mcu_pin_globals -#define pin_board_pins_locals_dict board_module_globals - - -MP_DECLARE_CONST_FUN_OBJ_KW(pin_init_obj); - -void pin_init0(void); -uint32_t pin_get_mode(const pin_obj_t *pin); -uint32_t pin_get_pull(const pin_obj_t *pin); -uint32_t pin_get_af(const pin_obj_t *pin); -const pin_obj_t *pin_find(mp_obj_t user_obj); -const pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name); -const pin_af_obj_t *pin_find_af(const pin_obj_t *pin, uint8_t fn, uint8_t unit); -const pin_af_obj_t *pin_find_af_by_index(const pin_obj_t *pin, mp_uint_t af_idx); -const pin_af_obj_t *pin_find_af_by_name(const pin_obj_t *pin, const char *name); - -#endif // __MICROPY_INCLUDED_NRF5_PIN_H__ diff --git a/ports/nrf/mpconfigport.h b/ports/nrf/mpconfigport.h index 5bfc59238..f17010370 100644 --- a/ports/nrf/mpconfigport.h +++ b/ports/nrf/mpconfigport.h @@ -289,7 +289,6 @@ extern const struct _mp_obj_module_t ble_module; // We need to provide a declaration/definition of alloca() #include <alloca.h> -#define MICROPY_PIN_DEFS_PORT_H "pin_defs_nrf5.h" //#define CIRCUITPY_BOOT_OUTPUT_FILE "/boot_out.txt" #endif diff --git a/ports/nrf/nrf52_af.csv b/ports/nrf/nrf52_af.csv index 284370d06..272d9cd09 100644 --- a/ports/nrf/nrf52_af.csv +++ b/ports/nrf/nrf52_af.csv @@ -1,48 +1,48 @@ -P0_00,P0_00 -P0_01,P0_01 -P0_02,P0_02 -P0_03,P0_03 -P0_04,P0_04 -P0_05,P0_05 -P0_06,P0_06 -P0_07,P0_07 -P0_08,P0_08 -P0_09,P0_09 -P0_10,P0_10 -P0_11,P0_11 -P0_12,P0_12 -P0_13,P0_13 -P0_14,P0_14 -P0_15,P0_15 -P0_16,P0_16 -P0_17,P0_17 -P0_18,P0_18 -P0_19,P0_19 -P0_20,P0_20 -P0_21,P0_21 -P0_22,P0_22 -P0_23,P0_23 -P0_24,P0_24 -P0_25,P0_25 -P0_26,P0_26 -P0_27,P0_27 -P0_28,P0_28 -P0_29,P0_29 -P0_30,P0_30 -P0_31,P0_31 -P1_00,P1_00 -P1_01,P1_01 -P1_02,P1_02 -P1_03,P1_03 -P1_04,P1_04 -P1_05,P1_05 -P1_06,P1_06 -P1_07,P1_07 -P1_08,P1_08 -P1_09,P1_09 -P1_10,P1_10 -P1_11,P1_11 -P1_12,P1_12 -P1_13,P1_13 -P1_14,P1_14 -P1_15,P1_15 +P0_00 +P0_01 +P0_02,AIN0 +P0_03,AIN1 +P0_04,AIN2 +P0_05,AIN3 +P0_06 +P0_07 +P0_08 +P0_09 +P0_10 +P0_11 +P0_12 +P0_13 +P0_14 +P0_15 +P0_16 +P0_17 +P0_18 +P0_19 +P0_20 +P0_21 +P0_22 +P0_23 +P0_24 +P0_25 +P0_26 +P0_27 +P0_28,AIN4 +P0_29,AIN5 +P0_30,AIN6 +P0_31,AIN7 +P1_00 +P1_01 +P1_02 +P1_03 +P1_04 +P1_05 +P1_06 +P1_07 +P1_08 +P1_09 +P1_10 +P1_11 +P1_12 +P1_13 +P1_14 +P1_15 diff --git a/ports/nrf/pin_defs_nrf5.h b/ports/nrf/pin.h index 2c12045c1..7a0ebea78 100644 --- a/ports/nrf/pin_defs_nrf5.h +++ b/ports/nrf/pin.h @@ -4,7 +4,6 @@ * The MIT License (MIT) * * Copyright (c) 2013, 2014 Damien P. George - * Copyright (c) 2016 Glenn Ruben Bakke * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,12 +24,20 @@ * THE SOFTWARE. */ -// This file contains pin definitions that are specific to the nrf port. -// This file should only ever be #included by pin.h and not directly. +#ifndef __MICROPY_INCLUDED_NRF5_PIN_H__ +#define __MICROPY_INCLUDED_NRF5_PIN_H__ -enum { - PORT_0, - PORT_1, -}; +#include "py/obj.h" -typedef NRF_GPIO_Type pin_gpio_t; +typedef struct { + mp_obj_base_t base; + qstr name; + + uint32_t port : 1; + uint32_t pin : 5; // Some ARM processors use 32 bits/PORT + uint32_t adc_channel : 4; // 0 is no ADC, ADC channel from 1 to 8 +} pin_obj_t; + +extern const mp_obj_type_t mcu_pin_type; + +#endif // __MICROPY_INCLUDED_NRF5_PIN_H__ diff --git a/ports/nrf/pin_named_pins.c b/ports/nrf/pin_named_pins.c deleted file mode 100644 index e1d8736b9..000000000 --- a/ports/nrf/pin_named_pins.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2013, 2014 Damien P. George - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include <stdio.h> -#include <string.h> - -#include "py/runtime.h" -#include "py/mphal.h" -#include "pin.h" - -STATIC void pin_named_pins_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { - pin_named_pins_obj_t *self = self_in; - mp_printf(print, "<Pin.%q>", self->name); -} - -const mp_obj_type_t pin_cpu_pins_obj_type = { - { &mp_type_type }, - .name = MP_QSTR_cpu, - .print = pin_named_pins_obj_print, - .locals_dict = (mp_obj_t)&pin_cpu_pins_locals_dict, -}; - -const mp_obj_type_t pin_board_pins_obj_type = { - { &mp_type_type }, - .name = MP_QSTR_board, - .print = pin_named_pins_obj_print, - .locals_dict = (mp_obj_t)&pin_board_pins_locals_dict, -}; - -const pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name) { - mp_map_t *named_map = mp_obj_dict_get_map((mp_obj_t)named_pins); - mp_map_elem_t *named_elem = mp_map_lookup(named_map, name, MP_MAP_LOOKUP); - if (named_elem != NULL && named_elem->value != NULL) { - return named_elem->value; - } - return NULL; -} - -const pin_af_obj_t *pin_find_af(const pin_obj_t *pin, uint8_t fn, uint8_t unit) { - const pin_af_obj_t *af = pin->af; - for (mp_uint_t i = 0; i < pin->num_af; i++, af++) { - if (af->fn == fn && af->unit == unit) { - return af; - } - } - return NULL; -} - -const pin_af_obj_t *pin_find_af_by_index(const pin_obj_t *pin, mp_uint_t af_idx) { - const pin_af_obj_t *af = pin->af; - for (mp_uint_t i = 0; i < pin->num_af; i++, af++) { - if (af->idx == af_idx) { - return af; - } - } - return NULL; -} - -/* unused -const pin_af_obj_t *pin_find_af_by_name(const pin_obj_t *pin, const char *name) { - const pin_af_obj_t *af = pin->af; - for (mp_uint_t i = 0; i < pin->num_af; i++, af++) { - if (strcmp(name, qstr_str(af->name)) == 0) { - return af; - } - } - return NULL; -} -*/ |
