summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJohn R. Lenton <jlenton@gmail.com>2014-01-06 00:08:21 +0000
committerJohn R. Lenton <jlenton@gmail.com>2014-01-06 00:08:21 +0000
commita10dba75090b38919790d1c3ad8bb9d2c126b7f4 (patch)
tree6750678d47844bb3918b4012a8af41cd989eeda5
parentba3f87c94776538fece5e87ff1d7de547930397a (diff)
parent8137b004b004d8e3a594eab90afccb72b779273a (diff)
downloadmicropython-a10dba75090b38919790d1c3ad8bb9d2c126b7f4.tar.gz
micropython-a10dba75090b38919790d1c3ad8bb9d2c126b7f4.zip
Merge remote-tracking branch 'upstream/master' into list_reverse
-rw-r--r--.gitignore21
-rw-r--r--py/objbool.c2
-rw-r--r--py/objboundmeth.c2
-rw-r--r--py/objcell.c2
-rw-r--r--py/objclass.c2
-rw-r--r--py/objclosure.c2
-rw-r--r--py/objcomplex.c2
-rw-r--r--py/objdict.c13
-rw-r--r--py/objexcept.c2
-rw-r--r--py/objfloat.c13
-rw-r--r--py/objfun.c6
-rw-r--r--py/objgenerator.c4
-rw-r--r--py/objinstance.c2
-rw-r--r--py/objint.c10
-rw-r--r--py/objlist.c38
-rw-r--r--py/objmodule.c2
-rw-r--r--py/objnone.c10
-rw-r--r--py/objrange.c4
-rw-r--r--py/objset.c2
-rw-r--r--py/objslice.c12
-rw-r--r--py/objstr.c22
-rw-r--r--py/objtuple.c23
-rw-r--r--py/objtype.c11
-rw-r--r--py/qstr.c4
-rw-r--r--stm/Makefile3
-rw-r--r--stm/i2c.c10
-rw-r--r--stm/led.c166
-rw-r--r--stm/led.h5
-rw-r--r--stm/main.c2
-rw-r--r--stm/servo.c10
-rw-r--r--stm/stm32fxxx_it.c6
-rw-r--r--stm/usrsw.c52
-rw-r--r--unix/main.c16
33 files changed, 272 insertions, 209 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000000..95be7bf651
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,21 @@
+# Compiled Sources
+###################
+*.o
+*.a
+*.elf
+*.bin
+*.map
+*.hex
+*.dis
+
+# Packages
+############
+
+# Logs and Databases
+######################
+*.log
+
+# VIM Swap Files
+######################
+*.swp
+
diff --git a/py/objbool.c b/py/objbool.c
index 1d94ee03be..77394dab99 100644
--- a/py/objbool.c
+++ b/py/objbool.c
@@ -41,7 +41,7 @@ const mp_obj_type_t bool_type = {
NULL, // binary_op
NULL, // getiter
NULL, // iternext
- {{NULL, NULL},}, // method list
+ .methods = {{NULL, NULL},},
};
static const mp_obj_bool_t false_obj = {{&bool_type}, false};
diff --git a/py/objboundmeth.c b/py/objboundmeth.c
index 264c2effd4..4e6d2e0103 100644
--- a/py/objboundmeth.c
+++ b/py/objboundmeth.c
@@ -43,7 +43,7 @@ const mp_obj_type_t bound_meth_type = {
NULL, // binary_op
NULL, // getiter
NULL, // iternext
- {{NULL, NULL},}, // method list
+ .methods = {{NULL, NULL},},
};
mp_obj_t mp_obj_new_bound_meth(mp_obj_t self, mp_obj_t meth) {
diff --git a/py/objcell.c b/py/objcell.c
index daaa340a7f..3465f99198 100644
--- a/py/objcell.c
+++ b/py/objcell.c
@@ -33,7 +33,7 @@ const mp_obj_type_t cell_type = {
NULL, // binary_op
NULL, // getiter
NULL, // iternext
- {{NULL, NULL},}, // method list
+ .methods = {{NULL, NULL},},
};
mp_obj_t mp_obj_new_cell(mp_obj_t obj) {
diff --git a/py/objclass.c b/py/objclass.c
index 197dfa7268..536abdf7e3 100644
--- a/py/objclass.c
+++ b/py/objclass.c
@@ -70,7 +70,7 @@ const mp_obj_type_t class_type = {
NULL, // binary_op
NULL, // getiter
NULL, // iternext
- {{NULL, NULL},}, // method list
+ .methods = {{NULL, NULL},},
};
mp_obj_t mp_obj_new_class(mp_map_t *class_locals) {
diff --git a/py/objclosure.c b/py/objclosure.c
index 550bb5067f..3317eb86f4 100644
--- a/py/objclosure.c
+++ b/py/objclosure.c
@@ -42,7 +42,7 @@ const mp_obj_type_t closure_type = {
NULL, // binary_op
NULL, // getiter
NULL, // iternext
- {{NULL, NULL},}, // method list
+ .methods = {{NULL, NULL},},
};
mp_obj_t mp_obj_new_closure(mp_obj_t fun, mp_obj_t closure_tuple) {
diff --git a/py/objcomplex.c b/py/objcomplex.c
index 5408d71cf2..fc32f96674 100644
--- a/py/objcomplex.c
+++ b/py/objcomplex.c
@@ -125,7 +125,7 @@ const mp_obj_type_t complex_type = {
complex_binary_op, // binary_op
NULL, // getiter
NULL, // iternext
- { { NULL, NULL }, }, // method list
+ .methods = { { NULL, NULL }, },
};
mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag) {
diff --git a/py/objdict.c b/py/objdict.c
index 3737f5eab0..b3e21aedd2 100644
--- a/py/objdict.c
+++ b/py/objdict.c
@@ -63,14 +63,11 @@ static mp_obj_t dict_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
const mp_obj_type_t dict_type = {
{ &mp_const_type },
"dict",
- dict_print, // print
- dict_make_new, // make_new
- NULL, // call_n
- NULL, // unary_op
- dict_binary_op, // binary_op
- NULL, // getiter
- NULL, // iternext
- {{NULL, NULL},}, // method list
+ .print = dict_print,
+ .make_new = dict_make_new,
+ .binary_op = dict_binary_op,
+ .getiter = NULL,
+ .methods = {{NULL, NULL},},
};
mp_obj_t mp_obj_new_dict(int n_args) {
diff --git a/py/objexcept.c b/py/objexcept.c
index ec03b9bf1a..22b8c58126 100644
--- a/py/objexcept.c
+++ b/py/objexcept.c
@@ -45,7 +45,7 @@ const mp_obj_type_t exception_type = {
NULL, // binary_op
NULL, // getiter
NULL, // iternext
- {{NULL, NULL},}, // method list
+ .methods = {{NULL, NULL},},
};
mp_obj_t mp_obj_new_exception(qstr id) {
diff --git a/py/objfloat.c b/py/objfloat.c
index 8fc925e0b6..0250172ad3 100644
--- a/py/objfloat.c
+++ b/py/objfloat.c
@@ -79,14 +79,11 @@ static mp_obj_t float_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
const mp_obj_type_t float_type = {
{ &mp_const_type },
"float",
- float_print,
- float_make_new, // make_new
- NULL, // call_n
- float_unary_op,
- float_binary_op,
- NULL, // getiter
- NULL, // iternext
- { { NULL, NULL }, }, // method list
+ .print = float_print,
+ .make_new = float_make_new,
+ .unary_op = float_unary_op,
+ .binary_op = float_binary_op,
+ .methods = { { NULL, NULL }, },
};
mp_obj_t mp_obj_new_float(mp_float_t value) {
diff --git a/py/objfun.c b/py/objfun.c
index 50de90bd1f..0db6459a39 100644
--- a/py/objfun.c
+++ b/py/objfun.c
@@ -79,7 +79,7 @@ const mp_obj_type_t fun_native_type = {
NULL, // binary_op
NULL, // getiter
NULL, // iternext
- { // method list
+ .methods = {
{NULL, NULL}, // end-of-list sentinel
},
};
@@ -181,7 +181,7 @@ const mp_obj_type_t fun_bc_type = {
NULL, // binary_op
NULL, // getiter
NULL, // iternext
- { // method list
+ .methods = {
{NULL, NULL}, // end-of-list sentinel
},
};
@@ -295,7 +295,7 @@ static const mp_obj_type_t fun_asm_type = {
NULL, // binary_op
NULL, // getiter
NULL, // iternext
- { // method list
+ .methods = {
{NULL, NULL}, // end-of-list sentinel
},
};
diff --git a/py/objgenerator.c b/py/objgenerator.c
index 7fbca075e2..a91b0d6fc6 100644
--- a/py/objgenerator.c
+++ b/py/objgenerator.c
@@ -46,7 +46,7 @@ const mp_obj_type_t gen_wrap_type = {
NULL, // binary_op
NULL, // getiter
NULL, // iternext
- {{NULL, NULL},}, // method list
+ .methods = {{NULL, NULL},},
};
mp_obj_t mp_obj_new_gen_wrap(uint n_locals, uint n_stack, mp_obj_t fun) {
@@ -101,7 +101,7 @@ const mp_obj_type_t gen_instance_type = {
NULL, // binary_op
gen_instance_getiter, // getiter
gen_instance_iternext, // iternext
- {{NULL, NULL},}, // method list
+ .methods = {{NULL, NULL},},
};
// args are in reverse order in the array
diff --git a/py/objinstance.c b/py/objinstance.c
index fd8cada7cb..8ef2773fd9 100644
--- a/py/objinstance.c
+++ b/py/objinstance.c
@@ -99,7 +99,7 @@ const mp_obj_type_t instance_type = {
NULL, // binary_op
NULL, // getiter
NULL, // iternext
- {{NULL, NULL},}, // method list
+ .methods = {{NULL, NULL},},
};
mp_obj_t mp_obj_new_instance(mp_obj_t class) {
diff --git a/py/objint.c b/py/objint.c
index 5bc747e8f0..8d69c4e7a7 100644
--- a/py/objint.c
+++ b/py/objint.c
@@ -33,14 +33,8 @@ static mp_obj_t int_make_new(mp_obj_t type_in, int n_args, const mp_obj_t *args)
const mp_obj_type_t int_type = {
{ &mp_const_type },
"int",
- NULL,
- int_make_new, // make_new
- NULL, // call_n
- NULL, // unary_op
- NULL, // binary_op
- NULL, // getiter
- NULL, // iternext
- { { NULL, NULL }, }, // method list
+ .make_new = int_make_new,
+ .methods = { { NULL, NULL }, },
};
mp_obj_t mp_obj_new_int(machine_int_t value) {
diff --git a/py/objlist.c b/py/objlist.c
index b0a04f0ad8..02a6b1525b 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -182,13 +182,17 @@ static mp_obj_t list_index(int n_args, const mp_obj_t *args) {
assert(MP_OBJ_IS_TYPE(args[0], &list_type));
mp_obj_list_t *self = args[0];
mp_obj_t *value = args[1];
+ uint start = 0;
+ uint stop = self->len;
- uint start = mp_get_index(self->base.type, self->len,
- n_args >= 3 ? args[2] : mp_obj_new_int(0));
- uint stop = mp_get_index(self->base.type, self->len,
- n_args >= 4 ? args[3] : mp_obj_new_int(-1));
+ if (n_args >= 3) {
+ start = mp_get_index(self->base.type, self->len, args[2]);
+ if (n_args >= 4) {
+ stop = mp_get_index(self->base.type, self->len, args[3]);
+ }
+ }
- for (uint i = start; i <= stop; i++) {
+ for (uint i = start; i < stop; i++) {
if (mp_obj_equal(self->items[i], value)) {
return mp_obj_new_int(i);
}
@@ -259,14 +263,12 @@ static MP_DEFINE_CONST_FUN_OBJ_2(list_sort_obj, list_sort);
const mp_obj_type_t list_type = {
{ &mp_const_type },
"list",
- list_print, // print
- list_make_new, // make_new
- NULL, // call_n
- NULL, // unary_op
- list_binary_op, // binary_op
- list_getiter, // getiter
- NULL, // iternext
- { // method list
+ .print = list_print,
+ .make_new = list_make_new,
+ .unary_op = NULL,
+ .binary_op = list_binary_op,
+ .getiter = list_getiter,
+ .methods = {
{ "append", &list_append_obj },
{ "clear", &list_clear_obj },
{ "copy", &list_copy_obj },
@@ -341,14 +343,8 @@ mp_obj_t list_it_iternext(mp_obj_t self_in) {
static const mp_obj_type_t list_it_type = {
{ &mp_const_type },
"list_iterator",
- NULL, // print
- NULL, // make_new
- NULL, // call_n
- NULL, // unary_op
- NULL, // binary_op
- NULL, // getiter
- list_it_iternext, // iternext
- { { NULL, NULL }, }, // method list
+ .iternext = list_it_iternext,
+ .methods = { { NULL, NULL }, },
};
mp_obj_t mp_obj_new_list_iterator(mp_obj_list_t *list, int cur) {
diff --git a/py/objmodule.c b/py/objmodule.c
index 9263eb44f0..2d6f9555e8 100644
--- a/py/objmodule.c
+++ b/py/objmodule.c
@@ -31,7 +31,7 @@ const mp_obj_type_t module_type = {
NULL, // binary_op
NULL, // getiter
NULL, // iternext
- {{NULL, NULL},}, // method list
+ .methods = {{NULL, NULL},},
};
mp_obj_t mp_obj_new_module(qstr module_name) {
diff --git a/py/objnone.c b/py/objnone.c
index 11dd4939b1..877e61fe5c 100644
--- a/py/objnone.c
+++ b/py/objnone.c
@@ -17,14 +17,8 @@ void none_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_ob
const mp_obj_type_t none_type = {
{ &mp_const_type },
"NoneType",
- none_print, // print
- NULL, // make_new
- NULL, // call_n
- NULL, // unary_op
- NULL, // binary_op
- NULL, // getiter
- NULL, // iternext
- {{NULL, NULL},}, // method list
+ .print = none_print,
+ .methods = {{NULL, NULL},},
};
static const mp_obj_none_t none_obj = {{&none_type}};
diff --git a/py/objrange.c b/py/objrange.c
index b163f779b8..1ef42673f4 100644
--- a/py/objrange.c
+++ b/py/objrange.c
@@ -32,7 +32,7 @@ static const mp_obj_type_t range_type = {
NULL, // binary_op
range_getiter,
NULL, // iternext
- {{NULL, NULL},}, // method list
+ .methods = {{NULL, NULL},},
};
// range is a class and instances are immutable sequence objects
@@ -77,7 +77,7 @@ static const mp_obj_type_t range_it_type = {
NULL, // binary_op
NULL, // getiter
range_it_iternext,
- {{NULL, NULL},}, // method list
+ .methods = {{NULL, NULL},},
};
mp_obj_t mp_obj_new_range_iterator(int cur, int stop, int step) {
diff --git a/py/objset.c b/py/objset.c
index 826f8bdc86..dd9a4d1e1d 100644
--- a/py/objset.c
+++ b/py/objset.c
@@ -64,7 +64,7 @@ const mp_obj_type_t set_type = {
NULL, // binary_op
NULL, // getiter
NULL, // iternext
- { { NULL, NULL }, }, // method list
+ .methods = { { NULL, NULL }, },
};
mp_obj_t mp_obj_new_set(int n_args, mp_obj_t *items) {
diff --git a/py/objslice.c b/py/objslice.c
index a624be9631..da69b92af2 100644
--- a/py/objslice.c
+++ b/py/objslice.c
@@ -30,7 +30,7 @@ const mp_obj_type_t ellipsis_type = {
NULL, // binary_op
NULL, // getiter
NULL, // iternext
- {{NULL, NULL},}, // method list
+ .methods = {{NULL, NULL},},
};
static const mp_obj_ellipsis_t ellipsis_obj = {{&ellipsis_type}};
@@ -57,14 +57,8 @@ void slice_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_o
const mp_obj_type_t slice_type = {
{ &mp_const_type },
"slice",
- slice_print,
- NULL, // call_n
- NULL, // make_new
- NULL, // unary_op
- NULL, // binary_op
- NULL, // getiter
- NULL, // iternext
- { { NULL, NULL }, }, // method list
+ .print = slice_print,
+ .methods = { { NULL, NULL }, },
};
// TODO: Make sure to handle "empty" values, which are signified by None in CPython
diff --git a/py/objstr.c b/py/objstr.c
index a1d139e83a..db3e0beca0 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -187,14 +187,10 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR(str_format_obj, 1, str_format);
const mp_obj_type_t str_type = {
{ &mp_const_type },
"str",
- str_print, // print
- NULL, // make_new
- NULL, // call_n
- NULL, // unary_op
- str_binary_op, // binary_op
- str_getiter, // getiter
- NULL, // iternext
- { // method list
+ .print = str_print,
+ .binary_op = str_binary_op,
+ .getiter = str_getiter,
+ .methods = {
{ "join", &str_join_obj },
{ "format", &str_format_obj },
{ NULL, NULL }, // end-of-list sentinel
@@ -238,14 +234,8 @@ mp_obj_t str_it_iternext(mp_obj_t self_in) {
static const mp_obj_type_t str_it_type = {
{ &mp_const_type },
"str_iterator",
- NULL, // print
- NULL, // make_new
- NULL, // call_n
- NULL, // unary_op
- NULL, // binary_op
- NULL, // getiter
- str_it_iternext, // iternext
- { { NULL, NULL }, }, // method str
+ .iternext = str_it_iternext,
+ .methods = { { NULL, NULL }, },
};
mp_obj_t mp_obj_new_str_iterator(mp_obj_str_t *str, int cur) {
diff --git a/py/objtuple.c b/py/objtuple.c
index d55259d1a6..ceca4200e4 100644
--- a/py/objtuple.c
+++ b/py/objtuple.c
@@ -99,14 +99,11 @@ static mp_obj_t tuple_getiter(mp_obj_t o_in) {
const mp_obj_type_t tuple_type = {
{ &mp_const_type },
"tuple",
- tuple_print, // print
- tuple_make_new, // make_new
- NULL, // call_n
- NULL, // unary_op
- tuple_binary_op, // binary_op
- tuple_getiter, // getiter
- NULL, // iternext
- {{NULL, NULL},}, // method list
+ .print = tuple_print,
+ .make_new = tuple_make_new,
+ .binary_op = tuple_binary_op,
+ .getiter = tuple_getiter,
+ .methods = {{NULL, NULL},},
};
// the zero-length tuple
@@ -168,14 +165,8 @@ static mp_obj_t tuple_it_iternext(mp_obj_t self_in) {
static const mp_obj_type_t tuple_it_type = {
{ &mp_const_type },
"tuple_iterator",
- NULL, // print
- NULL, // make_new
- NULL, // call_n
- NULL, // unary_op
- NULL, // binary_op
- NULL, // getiter
- tuple_it_iternext,
- {{NULL, NULL},}, // method list
+ .iternext = tuple_it_iternext,
+ .methods = {{NULL, NULL},},
};
static mp_obj_t mp_obj_new_tuple_iterator(mp_obj_tuple_t *tuple, int cur) {
diff --git a/py/objtype.c b/py/objtype.c
index aeeaebb95d..37d40b38f4 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -25,12 +25,7 @@ static mp_obj_t type_call_n(mp_obj_t self_in, int n_args, const mp_obj_t *args)
const mp_obj_type_t mp_const_type = {
{ &mp_const_type },
"type",
- type_print, // print
- NULL, // make_new
- type_call_n, // call_n
- NULL, // unary_op
- NULL, // binary_op
- NULL, // getiter
- NULL, // iternext
- {{NULL, NULL},}, // method list
+ .print = type_print,
+ .call_n = type_call_n,
+ .methods = {{NULL, NULL},},
};
diff --git a/py/qstr.c b/py/qstr.c
index 0ed7aa9a24..93ae3ab665 100644
--- a/py/qstr.c
+++ b/py/qstr.c
@@ -36,10 +36,10 @@ const static qstr_pool_t const_pool = {
},
};
-static qstr_pool_t *last_pool = (qstr_pool_t*)&const_pool; // we won't modify the const_pool since it has no allocated room left
+static qstr_pool_t *last_pool;
void qstr_init(void) {
- // nothing to do!
+ last_pool = (qstr_pool_t*)&const_pool; // we won't modify the const_pool since it has no allocated room left
}
static qstr qstr_add(const char *str) {
diff --git a/stm/Makefile b/stm/Makefile
index 93e87ec4af..cd998dd882 100644
--- a/stm/Makefile
+++ b/stm/Makefile
@@ -5,12 +5,13 @@ CC3KSRC=cc3k
PYSRC=../py
BUILD=build
DFU=../tools/dfu.py
+TARGET=PYBOARD
AS = arm-none-eabi-as
CC = arm-none-eabi-gcc
LD = arm-none-eabi-ld
CFLAGS_CORTEX_M4 = -mthumb -mtune=cortex-m4 -mabi=aapcs-linux -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant -Wdouble-promotion -DSTM32F40XX -DHSE_VALUE=8000000
-CFLAGS = -I. -I$(PYSRC) -I$(FATFSSRC) -I$(STMSRC) -Wall -ansi -std=gnu99 -Os -DNDEBUG $(CFLAGS_CORTEX_M4)
+CFLAGS = -I. -I$(PYSRC) -I$(FATFSSRC) -I$(STMSRC) -Wall -ansi -std=gnu99 -Os -DNDEBUG $(CFLAGS_CORTEX_M4) -D$(TARGET)
#CFLAGS += -I$(STMOTGSRC) -DUSE_HOST_MODE -DUSE_OTG_MODE
LDFLAGS = --nostdlib -T stm32f405.ld
diff --git a/stm/i2c.c b/stm/i2c.c
index 3f29f02c0c..9e25ff9839 100644
--- a/stm/i2c.c
+++ b/stm/i2c.c
@@ -329,14 +329,8 @@ static MP_DEFINE_CONST_FUN_OBJ_1(i2c_obj_stop_obj, i2c_obj_stop);
static const mp_obj_type_t i2c_obj_type = {
{ &mp_const_type },
"I2C",
- i2c_obj_print, // print
- NULL, // make_new
- NULL, // call_n
- NULL, // unary_op
- NULL, // binary_op
- NULL, // getiter
- NULL, // iternext
- { // method list
+ .print = i2c_obj_print,
+ .methods = {
{ "start", &i2c_obj_start_obj },
{ "write", &i2c_obj_write_obj },
{ "read", &i2c_obj_read_obj },
diff --git a/stm/led.c b/stm/led.c
index 9305716be9..9809c21771 100644
--- a/stm/led.c
+++ b/stm/led.c
@@ -7,66 +7,144 @@
#include "obj.h"
#include "led.h"
-#define PYB_LED_R_PORT (GPIOA)
-#define PYB_LED_R1_PIN (GPIO_Pin_8)
-#define PYB_LED_R2_PIN (GPIO_Pin_10)
-#define PYB_LED_G_PORT (GPIOC)
-#define PYB_LED_G1_PIN (GPIO_Pin_4)
-#define PYB_LED_G2_PIN (GPIO_Pin_5)
+/* LED numbers, used internally */
+#define PYB_LED_1 (0)
+#define PYB_LED_2 (1)
+#define PYB_LED_3 (2)
+#define PYB_LED_4 (3)
+
+#if defined(PYBOARD)
+ #define PYB_LED1_PORT (GPIOA)
+ #define PYB_LED1_PIN (GPIO_Pin_8)
+
+ #define PYB_LED2_PORT (GPIOA)
+ #define PYB_LED2_PIN (GPIO_Pin_10)
+
+ #define PYB_LED3_PORT (GPIOC)
+ #define PYB_LED3_PIN (GPIO_Pin_4)
+
+ #define PYB_LED4_PORT (GPIOC)
+ #define PYB_LED4_PIN (GPIO_Pin_5)
+
+ #define PYB_OTYPE (GPIO_OType_OD)
+
+ #define PYB_LED_ON(port, pin) (port->BSRRH = pin)
+ #define PYB_LED_OFF(port, pin) (port->BSRRL = pin)
+
+#elif defined(STM32F4DISC)
+ #define PYB_LED1_PORT (GPIOD)
+ #define PYB_LED1_PIN (GPIO_Pin_14)
+
+ #define PYB_LED2_PORT (GPIOD)
+ #define PYB_LED2_PIN (GPIO_Pin_12)
+
+ #define PYB_LED3_PORT (GPIOD)
+ #define PYB_LED3_PIN (GPIO_Pin_15)
+
+ #define PYB_LED4_PORT (GPIOD)
+ #define PYB_LED4_PIN (GPIO_Pin_13)
+
+ #define PYB_OTYPE (GPIO_OType_PP)
+
+ #define PYB_LED_ON(port, pin) (port->BSRRL = pin)
+ #define PYB_LED_OFF(port, pin) (port->BSRRH = pin)
+#endif
void led_init(void) {
- // set the output high (so LED is off)
- PYB_LED_R_PORT->BSRRL = PYB_LED_R1_PIN;
- PYB_LED_R_PORT->BSRRL = PYB_LED_R2_PIN;
- PYB_LED_G_PORT->BSRRL = PYB_LED_G1_PIN;
- PYB_LED_G_PORT->BSRRL = PYB_LED_G2_PIN;
- // make them open drain outputs
+ /* GPIO structure */
GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin = PYB_LED_R1_PIN | PYB_LED_R2_PIN;
+
+ /* Configure I/O speed, mode, output type and pull */
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_Init(PYB_LED_R_PORT, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = PYB_LED_G1_PIN | PYB_LED_G2_PIN;
- GPIO_Init(PYB_LED_G_PORT, &GPIO_InitStructure);
+ GPIO_InitStructure.GPIO_OType = PYB_OTYPE;
+
+ /* Turn off LEDs */
+ PYB_LED_OFF(PYB_LED1_PORT, PYB_LED1_PIN);
+ PYB_LED_OFF(PYB_LED2_PORT, PYB_LED2_PIN);
+ PYB_LED_OFF(PYB_LED3_PORT, PYB_LED1_PIN);
+ PYB_LED_OFF(PYB_LED4_PORT, PYB_LED2_PIN);
+
+ /* Initialize LEDs */
+ GPIO_InitStructure.GPIO_Pin = PYB_LED1_PIN;
+ GPIO_Init(PYB_LED1_PORT, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = PYB_LED2_PIN;
+ GPIO_Init(PYB_LED2_PORT, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = PYB_LED3_PIN;
+ GPIO_Init(PYB_LED3_PORT, &GPIO_InitStructure);
+
+ GPIO_InitStructure.GPIO_Pin = PYB_LED4_PIN;
+ GPIO_Init(PYB_LED4_PORT, &GPIO_InitStructure);
}
void led_state(pyb_led_t led, int state) {
GPIO_TypeDef *port;
uint32_t pin;
+
switch (led) {
- case PYB_LED_R1: port = PYB_LED_R_PORT; pin = PYB_LED_R1_PIN; break;
- case PYB_LED_R2: port = PYB_LED_R_PORT; pin = PYB_LED_R2_PIN; break;
- case PYB_LED_G1: port = PYB_LED_G_PORT; pin = PYB_LED_G1_PIN; break;
- case PYB_LED_G2: port = PYB_LED_G_PORT; pin = PYB_LED_G2_PIN; break;
- default: return;
+ case PYB_LED_1:
+ pin = PYB_LED1_PIN;
+ port = PYB_LED1_PORT;
+ break;
+ case PYB_LED_2:
+ pin = PYB_LED2_PIN;
+ port = PYB_LED2_PORT;
+ break;
+ case PYB_LED_3:
+ pin = PYB_LED3_PIN;
+ port = PYB_LED3_PORT;
+ break;
+ case PYB_LED_4:
+ pin = PYB_LED4_PIN;
+ port = PYB_LED4_PORT;
+ break;
+ default:
+ return;
}
+
if (state == 0) {
- // turn LED off (output is high)
- port->BSRRL = pin;
+ // turn LED off
+ PYB_LED_OFF(port, pin);
} else {
- // turn LED on (output is low)
- port->BSRRH = pin;
+ // turn LED on
+ PYB_LED_ON(port, pin);
}
}
void led_toggle(pyb_led_t led) {
GPIO_TypeDef *port;
uint32_t pin;
+
switch (led) {
- case PYB_LED_R1: port = PYB_LED_R_PORT; pin = PYB_LED_R1_PIN; break;
- case PYB_LED_R2: port = PYB_LED_R_PORT; pin = PYB_LED_R2_PIN; break;
- case PYB_LED_G1: port = PYB_LED_G_PORT; pin = PYB_LED_G1_PIN; break;
- case PYB_LED_G2: port = PYB_LED_G_PORT; pin = PYB_LED_G2_PIN; break;
- default: return;
+ case PYB_LED_1:
+ pin = PYB_LED1_PIN;
+ port = PYB_LED1_PORT;
+ break;
+ case PYB_LED_2:
+ pin = PYB_LED2_PIN;
+ port = PYB_LED2_PORT;
+ break;
+ case PYB_LED_3:
+ pin = PYB_LED3_PIN;
+ port = PYB_LED3_PORT;
+ break;
+ case PYB_LED_4:
+ pin = PYB_LED4_PIN;
+ port = PYB_LED4_PORT;
+ break;
+ default:
+ return;
}
+
if (!(port->ODR & pin)) {
- // turn LED off (output high)
- port->BSRRL = pin;
+ // turn LED off
+ PYB_LED_OFF(port, pin);
} else {
// turn LED on (output low)
- port->BSRRH = pin;
+ PYB_LED_ON(port, pin);
}
}
@@ -85,19 +163,13 @@ void led_obj_print(void (*print)(void *env, const char *fmt, ...), void *env, mp
mp_obj_t led_obj_on(mp_obj_t self_in) {
pyb_led_obj_t *self = self_in;
- switch (self->led_id) {
- case 1: led_state(PYB_LED_G1, 1); break;
- case 2: led_state(PYB_LED_G2, 1); break;
- }
+ led_state(self->led_id, 1);
return mp_const_none;
}
mp_obj_t led_obj_off(mp_obj_t self_in) {
pyb_led_obj_t *self = self_in;
- switch (self->led_id) {
- case 1: led_state(PYB_LED_G1, 0); break;
- case 2: led_state(PYB_LED_G2, 0); break;
- }
+ led_state(self->led_id, 0);
return mp_const_none;
}
@@ -107,14 +179,8 @@ static MP_DEFINE_CONST_FUN_OBJ_1(led_obj_off_obj, led_obj_off);
static const mp_obj_type_t led_obj_type = {
{ &mp_const_type },
"Led",
- led_obj_print, // print
- NULL, // make_new
- NULL, // call_n
- NULL, // unary_op
- NULL, // binary_op
- NULL, // getiter
- NULL, // iternext
- { // method list
+ .print = led_obj_print,
+ .methods = {
{ "on", &led_obj_on_obj },
{ "off", &led_obj_off_obj },
{ NULL, NULL },
diff --git a/stm/led.h b/stm/led.h
index e6d0c30bca..fcbfa17634 100644
--- a/stm/led.h
+++ b/stm/led.h
@@ -3,6 +3,11 @@ typedef enum {
PYB_LED_R2 = 1,
PYB_LED_G1 = 2,
PYB_LED_G2 = 3,
+ //STM32F4DISC
+ PYB_LED_R = 0,
+ PYB_LED_G = 1,
+ PYB_LED_B = 2,
+ PYB_LED_O = 3,
} pyb_led_t;
void led_init(void);
diff --git a/stm/main.c b/stm/main.c
index 2121742fd8..07c974eff8 100644
--- a/stm/main.c
+++ b/stm/main.c
@@ -699,7 +699,7 @@ static const mp_obj_type_t file_obj_type = {
NULL, // binary_op
NULL, // getiter
NULL, // iternext
- { // method list
+ .methods = {
{ "read", &file_obj_read_obj },
{ "write", &file_obj_write_obj },
{ "close", &file_obj_close_obj },
diff --git a/stm/servo.c b/stm/servo.c
index 1e31db5140..31190ce795 100644
--- a/stm/servo.c
+++ b/stm/servo.c
@@ -140,14 +140,8 @@ static MP_DEFINE_CONST_FUN_OBJ_2(servo_obj_angle_obj, servo_obj_angle);
static const mp_obj_type_t servo_obj_type = {
{ &mp_const_type },
"Servo",
- servo_obj_print, // print
- NULL, // make_new
- NULL, // call_n
- NULL, // unary_op
- NULL, // binary_op
- NULL, // getiter
- NULL, // iternext
- { // method list
+ .print = servo_obj_print,
+ .methods = {
{ "angle", &servo_obj_angle_obj },
{ NULL, NULL },
}
diff --git a/stm/stm32fxxx_it.c b/stm/stm32fxxx_it.c
index 4c185d0341..e254ccc899 100644
--- a/stm/stm32fxxx_it.c
+++ b/stm/stm32fxxx_it.c
@@ -298,4 +298,10 @@ void EXTI15_10_IRQHandler(void) {
}
}
+#if defined(STM32F4DISC)
+void EXTI0_IRQHandler(void) {
+ // clear pending interrupt bit
+ EXTI_ClearITPendingBit(EXTI_Line0);
+}
+#endif
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff --git a/stm/usrsw.c b/stm/usrsw.c
index 385547843f..9d1ee50ffb 100644
--- a/stm/usrsw.c
+++ b/stm/usrsw.c
@@ -9,36 +9,53 @@
#include "obj.h"
#include "usrsw.h"
-#define PYB_USRSW_PORT (GPIOA)
-#define PYB_USRSW_PIN (GPIO_Pin_13)
+#if defined (PYBOARD)
+ #define USRSW_PORT (GPIOA)
+ #define USRSW_PIN (GPIO_Pin_13)
+ #define USRSW_PUPD (GPIO_PuPd_UP)
+ #define USRSW_EXTI_PIN (EXTI_PinSource13)
+ #define USRSW_EXTI_PORT (EXTI_PortSourceGPIOA)
+ #define USRSW_EXTI_LINE (EXTI_Line13)
+ #define USRSW_EXTI_IRQN (EXTI15_10_IRQn)
+ #define USRSW_EXTI_EDGE (EXTI_Trigger_Rising)
+#elif defined (STM32F4DISC)
+ #define USRSW_PORT (GPIOA)
+ #define USRSW_PIN (GPIO_Pin_0)
+ #define USRSW_PUPD (GPIO_PuPd_NOPULL)
+ #define USRSW_EXTI_PIN (EXTI_PinSource0)
+ #define USRSW_EXTI_PORT (EXTI_PortSourceGPIOA)
+ #define USRSW_EXTI_LINE (EXTI_Line0)
+ #define USRSW_EXTI_IRQN (EXTI0_IRQn)
+ #define USRSW_EXTI_EDGE (EXTI_Trigger_Falling)
+#endif
void switch_init(void) {
// make it an input with pull-up
GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin = PYB_USRSW_PIN;
+ GPIO_InitStructure.GPIO_Pin = USRSW_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
- GPIO_Init(PYB_USRSW_PORT, &GPIO_InitStructure);
+ GPIO_InitStructure.GPIO_PuPd = USRSW_PUPD;
+ GPIO_Init(USRSW_PORT, &GPIO_InitStructure);
// the rest does the EXTI interrupt
/* Enable SYSCFG clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
- /* Connect EXTI Line13 to PA13 pin */
- SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource13);
+ /* Connect EXTI Line to GPIO pin */
+ SYSCFG_EXTILineConfig(USRSW_EXTI_PORT, USRSW_EXTI_PIN);
- /* Configure EXTI Line13, rising edge */
+ /* Configure EXTI Line */
EXTI_InitTypeDef EXTI_InitStructure;
- EXTI_InitStructure.EXTI_Line = EXTI_Line13;
+ EXTI_InitStructure.EXTI_Line = USRSW_EXTI_LINE;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
+ EXTI_InitStructure.EXTI_Trigger = USRSW_EXTI_EDGE;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable and set EXTI15_10 Interrupt to the lowest priority */
NVIC_InitTypeDef NVIC_InitStructure;
- NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn;
+ NVIC_InitStructure.NVIC_IRQChannel = USRSW_EXTI_IRQN;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
@@ -46,13 +63,24 @@ void switch_init(void) {
}
int switch_get(void) {
- if (PYB_USRSW_PORT->IDR & PYB_USRSW_PIN) {
+#if defined (PYBOARD)
+ if (USRSW_PORT->IDR & USRSW_PIN) {
// pulled high, so switch is not pressed
return 0;
} else {
// pulled low, so switch is pressed
return 1;
}
+#elif defined (STM32F4DISC)
+ /* switch pulled down */
+ if (USRSW_PORT->IDR & USRSW_PIN) {
+ // pulled high, so switch is pressed
+ return 1;
+ } else {
+ // pulled low, so switch is not pressed
+ return 0;
+ }
+#endif
}
/******************************************************************************/
diff --git a/unix/main.c b/unix/main.c
index 16fcf6ef8d..a06dc36791 100644
--- a/unix/main.c
+++ b/unix/main.c
@@ -191,14 +191,14 @@ static MP_DEFINE_CONST_FUN_OBJ_2(test_set_obj, test_set);
static const mp_obj_type_t test_type = {
{ &mp_const_type },
"Test",
- test_print, // print
- NULL, // make_new
- NULL, // call_n
- NULL, // unary_op
- NULL, // binary_op
- NULL, // getiter
- NULL, // iternext
- { // method list
+ .print = test_print,
+ .make_new = NULL,
+ .call_n = NULL,
+ .unary_op = NULL,
+ .binary_op = NULL,
+ .getiter = NULL,
+ .iternext = NULL,
+ .methods = {
{ "get", &test_get_obj },
{ "set", &test_set_obj },
{ NULL, NULL },