Skip to content

Commit d226dd2

Browse files
committed
cc3200: Add preliminary low power deep sleep support.
1 parent 0475de1 commit d226dd2

14 files changed

Lines changed: 951 additions & 27 deletions

cc3200/application.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ APP_MODS_SRC_C = $(addprefix mods/,\
9494
pybpin.c \
9595
pybrtc.c \
9696
pybsd.c \
97+
pybsleep.c \
9798
pybsystick.c \
9899
pybuart.c \
99100
pybwdt.c \

cc3200/boards/cc3200_prefix.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,21 @@
3434
#include "py/obj.h"
3535
#include "inc/hw_types.h"
3636
#include "inc/hw_memmap.h"
37+
#include "pin.h"
38+
#include "gpio.h"
3739
#include "pybpin.h"
3840

3941

4042
#define PIN(p_pin_name, p_port, p_bit, p_pin_num) \
4143
{ \
4244
{ &pin_type }, \
43-
.name = MP_QSTR_ ## p_pin_name, \
44-
.port = PORT_A ## p_port, \
45-
.bit = (p_bit), \
46-
.pin_num = (p_pin_num) \
45+
.name = MP_QSTR_ ## p_pin_name, \
46+
.port = PORT_A ## p_port, \
47+
.type = PIN_TYPE_STD, \
48+
.bit = (p_bit), \
49+
.pin_num = (p_pin_num), \
50+
.af = PIN_MODE_0, \
51+
.strength = PIN_STRENGTH_4MA, \
52+
.mode = GPIO_DIR_MODE_IN, \
53+
.used = false \
4754
}

cc3200/mods/modnetwork.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
///
3939
/// This module provides network drivers and routing configuration.
4040

41-
void mod_network_init(void) {
41+
void mod_network_init0(void) {
4242
mp_obj_list_init(&MP_STATE_PORT(mod_network_nic_list), 0);
4343
}
4444

cc3200/mods/modnetwork.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ typedef struct _mod_network_socket_obj_t {
7070

7171
extern const mod_network_nic_type_t mod_network_nic_type_wlan;
7272

73-
void mod_network_init(void);
73+
void mod_network_init0(void);
7474
void mod_network_register_nic(mp_obj_t nic);
7575
mp_obj_t mod_network_find_nic(const uint8_t *ip);
7676

cc3200/mods/pybadc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "rom_map.h"
4343
#include "interrupt.h"
4444
#include "pin.h"
45+
#include "gpio.h"
4546
#include "prcm.h"
4647
#include "adc.h"
4748
#include "pybadc.h"
@@ -117,7 +118,7 @@ STATIC mp_obj_t adc_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw,
117118
self->num = num;
118119

119120
// configure the pin in analog mode
120-
pin_config (pin, 0, 0, PIN_TYPE_ANALOG, PIN_STRENGTH_2MA);
121+
pin_config ((pin_obj_t *)pin, PIN_MODE_0, GPIO_DIR_MODE_IN, PYBPIN_ANALOG_TYPE, PIN_STRENGTH_2MA);
121122

122123
// enable the ADC channel
123124
MAP_ADCChannelEnable(ADC_BASE, channel);

cc3200/mods/pybextint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ extint_obj_t* extint_register(mp_obj_t pin_obj, uint32_t intmode, uint32_t pull,
303303
self->callback = NULL;
304304

305305
// before enabling the interrupt, configure the gpio pin
306-
pin_config(pin, PIN_MODE_0, GPIO_DIR_MODE_IN, pull, PIN_STRENGTH_4MA);
306+
pin_config ((pin_obj_t *)pin, PIN_MODE_0, GPIO_DIR_MODE_IN, pull, PIN_STRENGTH_4MA);
307307

308308
MAP_GPIOIntTypeSet(pin->port, pin->bit, intmode);
309309
switch (pin->port) {

cc3200/mods/pybpin.c

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "prcm.h"
4343
#include "gpio.h"
4444
#include "pybpin.h"
45+
#include "pybsleep.h"
4546
#include "mpexception.h"
4647

4748

@@ -78,7 +79,13 @@
7879
/// 2. Supply a string which matches a CPU pin name
7980
/// 3. Provide a pin number
8081

82+
83+
STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *pin, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args);
84+
STATIC void pin_obj_configure (const pin_obj_t *self);
85+
86+
8187
void pin_init0(void) {
88+
8289
}
8390

8491
// C API used to convert a user-supplied pin name into an ordinal pin number.
@@ -116,11 +123,26 @@ void pin_verify_af (uint af) {
116123
}
117124
}
118125

119-
void pin_config(const pin_obj_t *self, uint af, uint mode, uint type, uint strength) {
126+
void pin_config (pin_obj_t *self, uint af, uint mode, uint type, uint strength) {
127+
// configure the pin in analog mode
128+
((pin_obj_t *)self)->af = af;
129+
((pin_obj_t *)self)->mode = mode;
130+
((pin_obj_t *)self)->type = type;
131+
((pin_obj_t *)self)->strength = strength;
132+
pin_obj_configure ((const pin_obj_t *)self);
133+
// mark the pin as used
134+
((pin_obj_t *)self)->used = true;
135+
// register it with the sleep module
136+
pybsleep_add (self, (WakeUpCB_t)pin_obj_configure);
137+
}
138+
139+
STATIC void pin_obj_configure (const pin_obj_t *self) {
120140
// Skip all this if the pin is to be used in analog mode
121-
if (type != PIN_TYPE_ANALOG) {
122-
// PIN_MODE_0 means it stays as a Pin, else, another peripheral will take control of it
123-
if (af == PIN_MODE_0) {
141+
if (self->type != PYBPIN_ANALOG_TYPE) {
142+
// verify the alternate function
143+
pin_verify_af (self->af);
144+
// PIN_MODE_0 means it stays as a pin, else, another peripheral will take control of it
145+
if (self->af == PIN_MODE_0) {
124146
// enable the peripheral clock for the GPIO port of this pin
125147
switch (self->port) {
126148
case PORT_A0:
@@ -139,14 +161,12 @@ void pin_config(const pin_obj_t *self, uint af, uint mode, uint type, uint stren
139161
break;
140162
}
141163
// configure the direction
142-
MAP_GPIODirModeSet(self->port, self->bit, mode);
164+
MAP_GPIODirModeSet(self->port, self->bit, self->mode);
143165
}
144-
// verify the alternate function
145-
pin_verify_af (af);
146166
// now set the alternate function, strenght and type
147-
MAP_PinModeSet (self->pin_num, af);
167+
MAP_PinModeSet (self->pin_num, self->af);
148168
}
149-
MAP_PinConfigSet(self->pin_num, strength, type);
169+
MAP_PinConfigSet(self->pin_num, self->strength, self->type);
150170
}
151171

152172
/// \method print()
@@ -201,8 +221,6 @@ STATIC void pin_print(void (*print)(void *env, const char *fmt, ...), void *env,
201221
print(env, ", strength=Pin.%s)", qstr_str(str_qst));
202222
}
203223

204-
STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *pin, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args);
205-
206224
/// \classmethod \constructor(id, ...)
207225
/// Create a new Pin object associated with the id. If additional arguments are given,
208226
/// they are used to initialise the pin. See `init`.
@@ -280,7 +298,7 @@ STATIC mp_obj_t pin_obj_init_helper(const pin_obj_t *self, mp_uint_t n_args, con
280298
}
281299

282300
// configure the pin as requested
283-
pin_config (self, af, mode, type, strength);
301+
pin_config ((pin_obj_t *)self, af, mode, type, strength);
284302

285303
return mp_const_none;
286304
}

cc3200/mods/pybpin.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,19 @@
3030

3131
#include MICROPY_PIN_DEFS_PORT_H
3232

33+
#define PYBPIN_ANALOG_TYPE 0xFF
34+
3335
typedef struct {
3436
mp_obj_base_t base;
3537
qstr name;
3638
uint32_t port;
37-
uint32_t bit : 8;
38-
uint32_t pin_num : 7;
39+
uint16_t type;
40+
uint8_t bit;
41+
uint8_t pin_num;
42+
uint8_t af;
43+
uint8_t strength;
44+
uint8_t mode;
45+
bool used;
3946
} pin_obj_t;
4047

4148
extern const mp_obj_type_t pin_type;
@@ -58,7 +65,7 @@ MP_DECLARE_CONST_FUN_OBJ(pin_init_obj);
5865

5966
void pin_init0(void);
6067
void pin_verify_af (uint af);
61-
void pin_config(const pin_obj_t *self, uint af, uint mode, uint type, uint strength);
68+
void pin_config(pin_obj_t *self, uint af, uint mode, uint type, uint strength);
6269
const pin_obj_t *pin_find(mp_obj_t user_obj);
6370
const pin_obj_t *pin_find_named_pin(const mp_obj_dict_t *named_pins, mp_obj_t name);
6471
const pin_obj_t *pin_find_pin(const mp_obj_dict_t *named_pins, uint pin_num);

cc3200/mods/pybsd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ STATIC mp_obj_t pybsd_make_new (mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_
138138
// card detect pin was provided
139139
if (n_args == 7) {
140140
pybsd_obj.pin_sd_detect = (pin_obj_t *)pin_find(args[6]);
141-
pin_config(pybsd_obj.pin_sd_detect, PIN_MODE_0, GPIO_DIR_MODE_IN, PIN_TYPE_STD_PU, PIN_STRENGTH_4MA);
141+
pin_config (pybsd_obj.pin_sd_detect, PIN_MODE_0, GPIO_DIR_MODE_IN, PIN_TYPE_STD_PU, PIN_STRENGTH_4MA);
142142
}
143143
pybsd_obj.pinsset = true;
144144
}

0 commit comments

Comments
 (0)