Skip to content

Commit b761ed2

Browse files
committed
cc3200: Register ADC and I2C with the sleep module.
1 parent db0580d commit b761ed2

5 files changed

Lines changed: 38 additions & 14 deletions

File tree

cc3200/mods/pybadc.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
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
}

cc3200/mods/pybi2c.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "i2c.h"
4343
#include "pybi2c.h"
4444
#include "mpexception.h"
45+
#include "pybsleep.h"
4546

4647
/// \moduleref pyb
4748
/// \class I2C - a two-wire serial protocol
@@ -119,19 +120,19 @@ typedef struct _pyb_i2c_obj_t {
119120
}
120121

121122
/******************************************************************************
122-
DEFINE PUBLIC FUNCTIONS
123+
DEFINE PRIVATE FUNCTIONS
123124
******************************************************************************/
124125
// only master mode is available for the moment
125-
void i2c_init (uint mode, uint slvaddr, uint baudrate) {
126+
STATIC void i2c_init (pyb_i2c_obj_t *self) {
126127
// Enable the I2C Peripheral
127128
MAP_PRCMPeripheralClkEnable(PRCM_I2CA0, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
128129
MAP_PRCMPeripheralReset(PRCM_I2CA0);
129130

130131
// Configure I2C module with the specified baudrate
131-
MAP_I2CMasterInitExpClk(I2CA0_BASE, baudrate);
132+
MAP_I2CMasterInitExpClk(I2CA0_BASE, self->baudrate);
132133
}
133134

134-
void i2c_deinit(void) {
135+
STATIC void i2c_deinit(void) {
135136
MAP_I2CMasterDisable(I2CA0_BASE);
136137
MAP_PRCMPeripheralClkDisable(PRCM_I2CA0, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
137138
}
@@ -299,7 +300,10 @@ STATIC mp_obj_t pyb_i2c_init_helper(pyb_i2c_obj_t *self_in, mp_uint_t n_args, co
299300
}
300301

301302
// init the I2C bus
302-
i2c_init(self->mode, self->slvaddr, self->baudrate);
303+
i2c_init(self);
304+
305+
// register it with the sleep module
306+
pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)i2c_init);
303307

304308
return mp_const_none;
305309
}

cc3200/mods/pybi2c.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
* THE SOFTWARE.
2626
*/
2727

28+
#ifndef PYBI2C_H_
29+
#define PYBI2C_H_
30+
2831
extern const mp_obj_type_t pyb_i2c_type;
2932

30-
void i2c_init (uint mode, uint slvaddr, uint baudrate);
31-
void i2c_deinit(void);
33+
#endif // PYBI2C_H_

cc3200/mods/pybrtc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@
2525
* THE SOFTWARE.
2626
*/
2727

28+
#ifndef PYBRTC_H_
29+
#define PYBRTC_H_
30+
2831
#define RTC_U16MS_CYCLES(msec) ((msec * 1024) / 1000)
2932
#define RTC_CYCLES_U16MS(cycles) ((cycles * 1000) / 1024)
3033

3134
extern const mp_obj_type_t pyb_rtc_type;
3235

3336
void pybrtc_init(void);
37+
38+
#endif // PYBRTC_H_

cc3200/mods/pybuart.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
* THE SOFTWARE.
2626
*/
2727

28+
#ifndef PYBUART_H_
29+
#define PYBUART_H_
30+
2831
typedef enum {
2932
PYB_UART_NONE = -1,
3033
PYB_UART_0 = 0,
@@ -43,3 +46,4 @@ bool uart_tx_char(pyb_uart_obj_t *self, int c);
4346
bool uart_tx_strn(pyb_uart_obj_t *uart_obj, const char *str, uint len);
4447
void uart_tx_strn_cooked(pyb_uart_obj_t *uart_obj, const char *str, uint len);
4548

49+
#endif // PYBUART_H_

0 commit comments

Comments
 (0)