nrf/adc: Allow for external use of new and value read function.

This commit is contained in:
Glenn Ruben Bakke 2018-04-12 23:02:19 +02:00 committed by Damien George
parent 3209a13bf5
commit 434bd568fe
2 changed files with 16 additions and 5 deletions

View File

@ -148,10 +148,7 @@ STATIC mp_obj_t machine_adc_make_new(const mp_obj_type_t *type, size_t n_args, s
return MP_OBJ_FROM_PTR(self);
}
/// \method value()
/// Read adc level.
mp_obj_t machine_adc_value(mp_obj_t self_in) {
machine_adc_obj_t *self = self_in;
int16_t machine_adc_value_read(machine_adc_obj_t * adc_obj) {
#if NRF51
nrf_adc_value_t value = 0;
@ -168,8 +165,18 @@ mp_obj_t machine_adc_value(mp_obj_t self_in) {
#else // NRF52
nrf_saadc_value_t value = 0;
nrfx_saadc_sample_convert(self->id, &value);
nrfx_saadc_sample_convert(adc_obj->id, &value);
#endif
return value;
}
/// \method value()
/// Read adc level.
mp_obj_t machine_adc_value(mp_obj_t self_in) {
machine_adc_obj_t *self = self_in;
int16_t value = machine_adc_value_read(self);
return MP_OBJ_NEW_SMALL_INT(value);
}

View File

@ -27,8 +27,12 @@
#ifndef ADC_H__
#define ADC_H__
typedef struct _machine_adc_obj_t machine_adc_obj_t;
extern const mp_obj_type_t machine_adc_type;
void adc_init0(void);
int16_t machine_adc_value_read(machine_adc_obj_t * adc_obj);
#endif // ADC_H__