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.
This commit is contained in:
arturo182 2018-06-20 23:26:32 +02:00
parent ff918556cd
commit c2d4d0a10b
12 changed files with 102 additions and 337 deletions

View File

@ -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/)

View File

@ -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

1 A0,P0_02,ADC0_IN0 A0 P0_02
2 A1,P0_03,ADC0_IN1 A1 P0_03
3 A2,P0_04,ADC0_IN2 A2 P0_04
4 A3,P0_05,ADC0_IN3 A3 P0_05
5 TX,P0_06 TX P0_06
6 RX,P0_08 RX P0_08
7 NFC1,P0_09 NFC1 P0_09
18 SDA,P0_25 SDA P0_25
19 SCL,P0_26 SCL P0_26
20 D27,P0_27 D27 P0_27
21 A4,P0_28,ADC0_IN4 A4 P0_28
22 A5,P0_29,ADC0_IN5 A5 P0_29
23 A6,P0_30,ADC0_IN6 A6 P0_30
24 A7,P0_31,ADC0_IN7 A7 P0_31

View File

@ -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

1 P0_00,P0_00 P0_00 P0_00
2 P0_01,P0_01 P0_01 P0_01
3 P0_02,P0_02,ADC0_IN0 P0_02 P0_02
4 P0_03,P0_03,ADC0_IN1 P0_03 P0_03
5 P0_04,P0_04,ADC0_IN2 P0_04 P0_04
6 P0_05,P0_05,ADC0_IN3 P0_05 P0_05
7 P0_06,P0_06 P0_06 P0_06
8 P0_07,P0_07 P0_07 P0_07
9 P0_08,P0_08 P0_08 P0_08
26 P0_25,P0_25 P0_25 P0_25
27 P0_26,P0_26 P0_26 P0_26
28 P0_27,P0_27 P0_27 P0_27
29 P0_28,P0_28,ADC0_IN4 P0_28 P0_28
30 P0_29,P0_29,ADC0_IN5 P0_29 P0_29
31 P0_30,P0_30,ADC0_IN6 P0_30 P0_30
32 P0_31,P0_31,ADC0_IN7 P0_31 P0_31
33 P1_00,P1_00 P1_00 P1_00
34 P1_01,P1_01 P1_01 P1_01
35 P1_02,P1_02 P1_02 P1_02

View File

@ -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))

View File

@ -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), \
}

View File

@ -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

1 P0_00,PA0 P0_00 P0_01
2 P0_01,P0_01 P0_01 P0_01
3 P0_02,P0_02,ADC0_IN0 P0_02 P0_02
4 P0_03,P0_03,ADC0_IN1 P0_03 P0_03
5 P0_04,P0_04,ADC0_IN2 P0_04 P0_04
6 P0_05,P0_05,ADC0_IN3 P0_05 P0_05
7 P0_06,P0_06 P0_06 P0_06
8 P0_07,P0_07 P0_07 P0_07
9 P0_08,P0_08 P0_08 P0_08
26 P0_25,P0_25 P0_25 P0_25
27 P0_26,P0_26 P0_26 P0_26
28 P0_27,P0_27 P0_27 P0_27
29 P0_28,P0_28,ADC0_IN4 P0_28 P0_28
30 P0_29,P0_29,ADC0_IN5 P0_29 P0_29
31 P0_30,P0_30,ADC0_IN6 P0_30 P0_30
32 P0_31,P0_31,ADC0_IN7 P0_31 P0_31
33 P1_00,P1_00 P1_00 P1_00
34 P1_01,P1_01 P1_01 P1_01
35 P1_02,P1_02 P1_02 P1_02

View File

@ -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

View File

@ -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__

View File

@ -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

View File

@ -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

1 P0_00 P0_00
2 P0_01 P0_01
3 P0_02 P0_02,AIN0 P0_02
4 P0_03 P0_03,AIN1 P0_03
5 P0_04 P0_04,AIN2 P0_04
6 P0_05 P0_05,AIN3 P0_05
7 P0_06 P0_06
8 P0_07 P0_07
9 P0_08 P0_08
10 P0_09 P0_09
11 P0_10 P0_10
12 P0_11 P0_11
13 P0_12 P0_12
14 P0_13 P0_13
15 P0_14 P0_14
16 P0_15 P0_15
17 P0_16 P0_16
18 P0_17 P0_17
19 P0_18 P0_18
20 P0_19 P0_19
21 P0_20 P0_20
22 P0_21 P0_21
23 P0_22 P0_22
24 P0_23 P0_23
25 P0_24 P0_24
26 P0_25 P0_25
27 P0_26 P0_26
28 P0_27 P0_27
29 P0_28 P0_28,AIN4 P0_28
30 P0_29 P0_29,AIN5 P0_29
31 P0_30 P0_30,AIN6 P0_30
32 P0_31 P0_31,AIN7 P0_31
33 P1_00 P1_00
34 P1_01 P1_01
35 P1_02 P1_02
36 P1_03 P1_03
37 P1_04 P1_04
38 P1_05 P1_05
39 P1_06 P1_06
40 P1_07 P1_07
41 P1_08 P1_08
42 P1_09 P1_09
43 P1_10 P1_10
44 P1_11 P1_11
45 P1_12 P1_12
46 P1_13 P1_13
47 P1_14 P1_14
48 P1_15 P1_15

View File

@ -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__

View File

@ -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;
}
*/