cc3200: Register ADC and I2C with the sleep module.
This commit is contained in:
parent
db0580d0a5
commit
b761ed2103
|
@ -47,6 +47,7 @@
|
|||
#include "adc.h"
|
||||
#include "pybadc.h"
|
||||
#include "pybpin.h"
|
||||
#include "pybsleep.h"
|
||||
#include "pins.h"
|
||||
#include "mpexception.h"
|
||||
|
||||
|
@ -70,6 +71,16 @@ typedef struct _pyb_obj_adc_t {
|
|||
} pyb_obj_adc_t;
|
||||
|
||||
|
||||
STATIC void pybadc_init (pyb_obj_adc_t *self) {
|
||||
// enable the ADC channel
|
||||
MAP_ADCChannelEnable(ADC_BASE, self->channel);
|
||||
// enable and configure the timer
|
||||
MAP_ADCTimerConfig(ADC_BASE, (1 << 17) - 1);
|
||||
MAP_ADCTimerEnable(ADC_BASE);
|
||||
// enable the ADC peripheral
|
||||
MAP_ADCEnable(ADC_BASE);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* Micro Python bindings : adc object */
|
||||
|
||||
|
@ -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,
|
|||
// configure the pin in analog mode
|
||||
pin_config ((pin_obj_t *)pin, PIN_MODE_0, GPIO_DIR_MODE_IN, PYBPIN_ANALOG_TYPE, PIN_STRENGTH_2MA);
|
||||
|
||||
// enable the ADC channel
|
||||
MAP_ADCChannelEnable(ADC_BASE, channel);
|
||||
// enable and configure the timer
|
||||
MAP_ADCTimerConfig(ADC_BASE, (1 << 17) - 1);
|
||||
MAP_ADCTimerEnable(ADC_BASE);
|
||||
// enable the ADC peripheral
|
||||
MAP_ADCEnable(ADC_BASE);
|
||||
// initialize it
|
||||
pybadc_init (self);
|
||||
|
||||
// register it with the sleep module
|
||||
pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)pybadc_init);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "i2c.h"
|
||||
#include "pybi2c.h"
|
||||
#include "mpexception.h"
|
||||
#include "pybsleep.h"
|
||||
|
||||
/// \moduleref pyb
|
||||
/// \class I2C - a two-wire serial protocol
|
||||
|
@ -119,19 +120,19 @@ typedef struct _pyb_i2c_obj_t {
|
|||
}
|
||||
|
||||
/******************************************************************************
|
||||
DEFINE PUBLIC FUNCTIONS
|
||||
DEFINE PRIVATE FUNCTIONS
|
||||
******************************************************************************/
|
||||
// only master mode is available for the moment
|
||||
void i2c_init (uint mode, uint slvaddr, uint baudrate) {
|
||||
STATIC void i2c_init (pyb_i2c_obj_t *self) {
|
||||
// Enable the I2C Peripheral
|
||||
MAP_PRCMPeripheralClkEnable(PRCM_I2CA0, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
|
||||
MAP_PRCMPeripheralReset(PRCM_I2CA0);
|
||||
|
||||
// Configure I2C module with the specified baudrate
|
||||
MAP_I2CMasterInitExpClk(I2CA0_BASE, baudrate);
|
||||
MAP_I2CMasterInitExpClk(I2CA0_BASE, self->baudrate);
|
||||
}
|
||||
|
||||
void i2c_deinit(void) {
|
||||
STATIC void i2c_deinit(void) {
|
||||
MAP_I2CMasterDisable(I2CA0_BASE);
|
||||
MAP_PRCMPeripheralClkDisable(PRCM_I2CA0, PRCM_RUN_MODE_CLK | PRCM_SLP_MODE_CLK);
|
||||
}
|
||||
|
@ -299,7 +300,10 @@ STATIC mp_obj_t pyb_i2c_init_helper(pyb_i2c_obj_t *self_in, mp_uint_t n_args, co
|
|||
}
|
||||
|
||||
// init the I2C bus
|
||||
i2c_init(self->mode, self->slvaddr, self->baudrate);
|
||||
i2c_init(self);
|
||||
|
||||
// register it with the sleep module
|
||||
pybsleep_add ((const mp_obj_t)self, (WakeUpCB_t)i2c_init);
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,9 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PYBI2C_H_
|
||||
#define PYBI2C_H_
|
||||
|
||||
extern const mp_obj_type_t pyb_i2c_type;
|
||||
|
||||
void i2c_init (uint mode, uint slvaddr, uint baudrate);
|
||||
void i2c_deinit(void);
|
||||
#endif // PYBI2C_H_
|
||||
|
|
|
@ -25,9 +25,14 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PYBRTC_H_
|
||||
#define PYBRTC_H_
|
||||
|
||||
#define RTC_U16MS_CYCLES(msec) ((msec * 1024) / 1000)
|
||||
#define RTC_CYCLES_U16MS(cycles) ((cycles * 1000) / 1024)
|
||||
|
||||
extern const mp_obj_type_t pyb_rtc_type;
|
||||
|
||||
void pybrtc_init(void);
|
||||
|
||||
#endif // PYBRTC_H_
|
||||
|
|
|
@ -25,6 +25,9 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef PYBUART_H_
|
||||
#define PYBUART_H_
|
||||
|
||||
typedef enum {
|
||||
PYB_UART_NONE = -1,
|
||||
PYB_UART_0 = 0,
|
||||
|
@ -43,3 +46,4 @@ bool uart_tx_char(pyb_uart_obj_t *self, int c);
|
|||
bool uart_tx_strn(pyb_uart_obj_t *uart_obj, const char *str, uint len);
|
||||
void uart_tx_strn_cooked(pyb_uart_obj_t *uart_obj, const char *str, uint len);
|
||||
|
||||
#endif // PYBUART_H_
|
||||
|
|
Loading…
Reference in New Issue