Skip to content

Commit af3de85

Browse files
committed
mimxrt: adc: rt117x: Support channel groups
Only kLPADC_SampleChannelSingleEndSideA is used during capture, while pin may be in side B. Detect the side based on the pin configuration. Change-Id: I207f4fa0503864519e5a7f88599e24b5f667d591 Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
1 parent ac1f306 commit af3de85

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

lib/nxp_driver

Submodule nxp_driver updated 221 files

ports/mimxrt/boards/make-pins.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,23 @@ def add_af(self, af_idx, af_name, af):
6161

6262
elif af_name == "ADC":
6363
adc_regex = r"ADC(?P<instance>\d*)_IN(?P<channel>\d*)"
64-
lpadc_regex = r"ADC(?P<instance>\d*)_CH(?P<channel>\d*)" # LPADC for MIMXRT11xx chips
64+
lpadc_regex = r"ADC(?P<instance>\d*)_CH(?P<channel>\d*)(?P<channel_group>.*)" # LPADC for MIMXRT11xx chips
6565

6666
matches = re.finditer(adc_regex, af, re.MULTILINE)
6767
for match in matches:
6868
self._adc_fns.append(
69-
(int(match.group("instance")), int(match.group("channel")), "ADC")
69+
(int(match.group("instance")), int(match.group("channel")), 0, "ADC")
7070
)
7171

7272
matches = re.finditer(lpadc_regex, af, re.MULTILINE)
7373
for match in matches:
7474
self._adc_fns.append(
75-
(int(match.group("instance")), int(match.group("channel")), "LPADC")
75+
(
76+
int(match.group("instance")),
77+
int(match.group("channel")),
78+
ord(match.group("channel_group")[0]) - ord("A"),
79+
"LPADC",
80+
)
7681
)
7782

7883
# Use the PIN() macro defined in samd_prefix.c for defining the pin
@@ -122,9 +127,11 @@ def print_source(self, out_source):
122127
"static const machine_pin_adc_obj_t pin_{:s}_adc[] = {{".format(self.name()),
123128
file=out_source,
124129
)
125-
for instance, channel, peripheral in self._adc_fns:
130+
for instance, channel, channel_group, peripheral in self._adc_fns:
126131
print(
127-
" PIN_ADC({:s}{:d}, {:d}),".format(peripheral, instance, channel),
132+
" PIN_ADC({:s}{:d}, {:d}, {:d}),".format(
133+
peripheral, instance, channel, channel_group
134+
),
128135
file=out_source,
129136
)
130137
print("};", file=out_source)

ports/mimxrt/boards/mimxrt_prefix.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616
.pad_config = (uint32_t)(_pad_config), \
1717
} \
1818

19-
#define PIN_ADC(_instance, _channel) \
19+
#define PIN_ADC(_instance, _channel, _channel_group) \
2020
{ \
2121
.instance = (_instance), \
22-
.channel = (_channel) \
22+
.channel = (_channel), \
23+
.channel_group = (_channel_group), \
2324
} \
2425

2526
#define PIN(_name, _gpio, _pin, _af_list, _adc_list_len, _adc_list) \

ports/mimxrt/machine_adc.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static void mp_machine_adc_print(const mp_print_t *print, mp_obj_t self_in, mp_p
6464
// Get ADC adc id
6565
for (int i = 1; i < sizeof(adc_bases) / sizeof(ADC_Type *); ++i) {
6666
if (adc_bases[i] == self->adc) {
67-
mp_printf(print, "ADC(%u, channel=%u)", i, self->channel);
67+
mp_printf(print, "ADC(%u, channel=%u, channel_group=%u)", i, self->channel, self->channel_group);
6868
break;
6969
}
7070
}
@@ -83,12 +83,13 @@ static mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args
8383
// Extract arguments
8484
ADC_Type *adc_instance = pin->adc_list[0].instance; // NOTE: we only use the first ADC assignment - multiple assignments are not supported for now
8585
uint8_t channel = pin->adc_list[0].channel;
86+
uint8_t channel_group = pin->adc_list[0].channel_group;
8687

8788
// Create ADC Instance
8889
machine_adc_obj_t *o = mp_obj_malloc(machine_adc_obj_t, &machine_adc_type);
8990
o->adc = adc_instance;
9091
o->channel = (uint8_t)channel;
91-
o->channel_group = 0;
92+
o->channel_group = channel_group;
9293
o->resolution = 4096; // NOTE: currently only 12bit resolution supported
9394

9495
return MP_OBJ_FROM_PTR(o);
@@ -104,6 +105,11 @@ static mp_int_t mp_machine_adc_read_u16(machine_adc_obj_t *self) {
104105
LPADC_GetDefaultConvCommandConfig(&adc_config);
105106
adc_config.channelNumber = self->channel;
106107
adc_config.sampleScaleMode = kLPADC_SamplePartScale;
108+
if (self->channel_group == 0) {
109+
adc_config.sampleChannelMode = kLPADC_SampleChannelSingleEndSideA;
110+
} else {
111+
adc_config.sampleChannelMode = kLPADC_SampleChannelSingleEndSideB;
112+
}
107113
LPADC_SetConvCommandConfig(self->adc, 1, &adc_config);
108114

109115
// Set Trigger mode

ports/mimxrt/pin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ typedef struct {
117117
typedef struct {
118118
ADC_Type *instance;
119119
uint8_t channel;
120+
uint8_t channel_group;
120121
} machine_pin_adc_obj_t;
121122

122123
typedef struct {

0 commit comments

Comments
 (0)