Skip to content

Commit 58f1ade

Browse files
robert-hhdpgeorge
authored andcommitted
mimxrt/machine_adc: Add ADC.read_uv() method.
Matching the generic documentation. Signed-off-by: robert-hh <robert@hammelrath.com>
1 parent f1018ee commit 58f1ade

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

ports/mimxrt/machine_adc.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@
4141
// The ADC class doesn't have any constants for this port.
4242
#define MICROPY_PY_MACHINE_ADC_CLASS_CONSTANTS
4343

44+
#if defined(MIMXRT117x_SERIES)
45+
#define ADC_UV_FULL_RANGE (3840000)
46+
#else
47+
#define ADC_UV_FULL_RANGE (3300000)
48+
#endif
49+
4450
typedef struct _machine_adc_obj_t {
4551
mp_obj_base_t base;
4652
ADC_Type *adc;
@@ -78,15 +84,6 @@ static mp_obj_t mp_machine_adc_make_new(const mp_obj_type_t *type, size_t n_args
7884
ADC_Type *adc_instance = pin->adc_list[0].instance; // NOTE: we only use the first ADC assignment - multiple assignments are not supported for now
7985
uint8_t channel = pin->adc_list[0].channel;
8086

81-
#if 0 // done in adc_read_u16
82-
// Configure ADC peripheral channel
83-
adc_channel_config_t channel_config = {
84-
.channelNumber = (uint32_t)channel,
85-
.enableInterruptOnConversionCompleted = false,
86-
};
87-
ADC_SetChannelConfig(adc_instance, 0UL, &channel_config); // NOTE: we always choose channel group '0' since we only perform software triggered conversion
88-
#endif
89-
9087
// Create ADC Instance
9188
machine_adc_obj_t *o = mp_obj_malloc(machine_adc_obj_t, &machine_adc_type);
9289
o->adc = adc_instance;
@@ -169,3 +166,7 @@ void machine_adc_init(void) {
169166
}
170167
}
171168
#endif
169+
170+
static mp_int_t mp_machine_adc_read_uv(machine_adc_obj_t *self) {
171+
return (uint64_t)ADC_UV_FULL_RANGE * mp_machine_adc_read_u16(self) / 65536;
172+
}

ports/mimxrt/mpconfigport.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ uint32_t trng_random_u32(void);
8484
#define MICROPY_PY_MACHINE_DISABLE_IRQ_ENABLE_IRQ (1)
8585
#define MICROPY_PY_MACHINE_ADC (1)
8686
#define MICROPY_PY_MACHINE_ADC_INCLUDEFILE "ports/mimxrt/machine_adc.c"
87+
#define MICROPY_PY_MACHINE_ADC_READ_UV (1)
8788
#define MICROPY_PY_MACHINE_PIN_MAKE_NEW mp_pin_make_new
8889
#define MICROPY_PY_MACHINE_BITSTREAM (1)
8990
#define MICROPY_PY_MACHINE_DHT_READINTO (1)

0 commit comments

Comments
 (0)