4747#include "adc.h"
4848#include "pybadc.h"
4949#include "pybpin.h"
50+ #include "pybsleep.h"
5051#include "pins.h"
5152#include "mpexception.h"
5253
@@ -70,6 +71,16 @@ typedef struct _pyb_obj_adc_t {
7071} pyb_obj_adc_t ;
7172
7273
74+ STATIC void pybadc_init (pyb_obj_adc_t * self ) {
75+ // enable the ADC channel
76+ MAP_ADCChannelEnable (ADC_BASE , self -> channel );
77+ // enable and configure the timer
78+ MAP_ADCTimerConfig (ADC_BASE , (1 << 17 ) - 1 );
79+ MAP_ADCTimerEnable (ADC_BASE );
80+ // enable the ADC peripheral
81+ MAP_ADCEnable (ADC_BASE );
82+ }
83+
7384/******************************************************************************/
7485/* Micro Python bindings : adc object */
7586
@@ -120,13 +131,11 @@ STATIC mp_obj_t adc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw,
120131 // configure the pin in analog mode
121132 pin_config ((pin_obj_t * )pin , PIN_MODE_0 , GPIO_DIR_MODE_IN , PYBPIN_ANALOG_TYPE , PIN_STRENGTH_2MA );
122133
123- // enable the ADC channel
124- MAP_ADCChannelEnable (ADC_BASE , channel );
125- // enable and configure the timer
126- MAP_ADCTimerConfig (ADC_BASE , (1 << 17 ) - 1 );
127- MAP_ADCTimerEnable (ADC_BASE );
128- // enable the ADC peripheral
129- MAP_ADCEnable (ADC_BASE );
134+ // initialize it
135+ pybadc_init (self );
136+
137+ // register it with the sleep module
138+ pybsleep_add ((const mp_obj_t )self , (WakeUpCB_t )pybadc_init );
130139
131140 return self ;
132141}
0 commit comments