summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-01-22 22:56:17 +0000
committerDamien George <damien.p.george@gmail.com>2014-01-22 22:56:17 +0000
commit8bcc52e8341368c73edf094e288a4f514b84028a (patch)
tree6344c33d8e82602818bb5f785c3eb740a23bab65
parentb5d13c309f00b0c959c0806c1ab11ba7a07c2cee (diff)
parent66db7bf69fdd94f8ff20b30698cffd111058b2bb (diff)
downloadmicropython-8bcc52e8341368c73edf094e288a4f514b84028a.tar.gz
micropython-8bcc52e8341368c73edf094e288a4f514b84028a.zip
Merge branch 'master' of github.com:micropython/micropython
-rw-r--r--py/stream.c16
-rw-r--r--stm/main.c6
-rw-r--r--stm/mpconfigport.h63
-rw-r--r--stm/usrsw.c30
4 files changed, 73 insertions, 42 deletions
diff --git a/py/stream.c b/py/stream.c
index d47d7e4196..c97c711f0f 100644
--- a/py/stream.c
+++ b/py/stream.c
@@ -130,7 +130,15 @@ static mp_obj_t stream_unbuffered_readline(uint n_args, const mp_obj_t *args) {
if (out_sz == -1) {
nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_OSError, "[Errno %d]", error));
}
- if (out_sz == 0 || *p == '\n') {
+ if (out_sz == 0) {
+ // Back out previously added byte
+ // TODO: This is a bit hacky, does it supported by vstr API contract?
+ // Consider, what's better - read a char and get OutOfMemory (so read
+ // char is lost), or allocate first as we do.
+ vstr_add_len(vstr, -1);
+ break;
+ }
+ if (*p == '\n') {
break;
}
}
@@ -141,9 +149,9 @@ static mp_obj_t stream_unbuffered_readline(uint n_args, const mp_obj_t *args) {
mp_obj_t mp_stream_unbuffered_iter(mp_obj_t self) {
mp_obj_t l_in = stream_unbuffered_readline(1, &self);
- const char *l = qstr_str(MP_OBJ_QSTR_VALUE(l_in));
- // TODO: \0
- if (*l != 0) {
+ uint sz;
+ mp_obj_str_get_data(l_in, &sz);
+ if (sz != 0) {
return l_in;
}
return mp_const_stop_iteration;
diff --git a/stm/main.c b/stm/main.c
index acb76b012d..40831c9930 100644
--- a/stm/main.c
+++ b/stm/main.c
@@ -803,7 +803,7 @@ soft_reset:
rt_store_attr(m, MP_QSTR_switch, (mp_obj_t)&pyb_switch_obj);
rt_store_attr(m, MP_QSTR_servo, rt_make_function_n(2, pyb_servo_set));
rt_store_attr(m, MP_QSTR_pwm, rt_make_function_n(2, pyb_pwm_set));
-#if BOARD_HAS_MMA7660
+#if MICROPY_HW_HAS_MMA7660
rt_store_attr(m, MP_QSTR_accel, (mp_obj_t)&pyb_mma_read_obj);
rt_store_attr(m, MP_QSTR_mma_read, (mp_obj_t)&pyb_mma_read_all_obj);
rt_store_attr(m, MP_QSTR_mma_mode, (mp_obj_t)&pyb_mma_write_mode_obj);
@@ -925,7 +925,7 @@ soft_reset:
//rt_store_name(qstr_from_str("u_c"), rt_make_function_n(0, pyb_usbh_connect));
if (first_soft_reset) {
-#if BOARD_HAS_MMA7660
+#if MICROPY_HW_HAS_MMA7660
// MMA: init and reset address to zero
mma_init();
#endif
@@ -956,7 +956,7 @@ soft_reset:
}
-#if BOARD_HAS_MMA7660
+#if MICROPY_HW_HAS_MMA7660
// HID example
if (0) {
uint8_t data[4];
diff --git a/stm/mpconfigport.h b/stm/mpconfigport.h
index 75f6fe11b5..4bd7537807 100644
--- a/stm/mpconfigport.h
+++ b/stm/mpconfigport.h
@@ -27,12 +27,63 @@ machine_float_t machine_sqrt(machine_float_t x);
#define PYBOARD4
//#define STM32F4DISC
-#if defined(PYBOARD) || defined(PYBOARD4)
-#define BOARD_HAS_MMA7660 (1)
-#define BOARD_HAS_LIS3DSH (0)
-#else
-#define BOARD_HAS_MMA7660 (0)
-#define BOARD_HAS_LIS3DSH (1)
+#if defined (PYBOARD)
+ #define MICROPY_HW_HAS_SWITCH (1)
+ #define MICROPY_HW_HAS_SDCARD (1)
+ #define MICROPY_HW_HAS_MMA7660 (1)
+ #define MICROPY_HW_HAS_LIS3DSH (0)
+ #define MICROPY_HW_ENABLE_RNG (1)
+ #define MICROPY_HW_ENABLE_RTC (1)
+ #define MICROPY_HW_ENABLE_TIMER (1)
+ #define MICROPY_HW_ENABLE_SERVO (1)
+ #define MICROPY_HW_ENABLE_AUDIO (0)
+
+ #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 (PYBOARD4)
+ #define MICROPY_HW_HAS_SWITCH (1)
+ #define MICROPY_HW_HAS_SDCARD (1)
+ #define MICROPY_HW_HAS_MMA7660 (1)
+ #define MICROPY_HW_HAS_LIS3DSH (0)
+ #define MICROPY_HW_ENABLE_RNG (1)
+ #define MICROPY_HW_ENABLE_RTC (1)
+ #define MICROPY_HW_ENABLE_TIMER (1)
+ #define MICROPY_HW_ENABLE_SERVO (1)
+ #define MICROPY_HW_ENABLE_AUDIO (0)
+
+ #define USRSW_PORT (GPIOB)
+ #define USRSW_PIN (GPIO_Pin_3)
+ #define USRSW_PUPD (GPIO_PuPd_UP)
+ #define USRSW_EXTI_PIN (EXTI_PinSource3)
+ #define USRSW_EXTI_PORT (EXTI_PortSourceGPIOB)
+ #define USRSW_EXTI_LINE (EXTI_Line3)
+ #define USRSW_EXTI_IRQN (EXTI15_10_IRQn)
+ #define USRSW_EXTI_EDGE (EXTI_Trigger_Rising)
+#elif defined (STM32F4DISC)
+ #define MICROPY_HW_HAS_SWITCH (1)
+ #define MICROPY_HW_HAS_SDCARD (0)
+ #define MICROPY_HW_HAS_MMA7660 (0)
+ #define MICROPY_HW_HAS_LIS3DSH (1)
+ #define MICROPY_HW_ENABLE_RNG (1)
+ #define MICROPY_HW_ENABLE_RTC (1)
+ #define MICROPY_HW_ENABLE_TIMER (1)
+ #define MICROPY_HW_ENABLE_SERVO (0)
+ #define MICROPY_HW_ENABLE_AUDIO (0)
+
+ #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
#define STM32F40_41xxx
diff --git a/stm/usrsw.c b/stm/usrsw.c
index 6450b74a7c..2aa21eef82 100644
--- a/stm/usrsw.c
+++ b/stm/usrsw.c
@@ -6,39 +6,11 @@
#include "misc.h"
#include "mpconfig.h"
+#include "mpconfigport.h"
#include "qstr.h"
#include "obj.h"
#include "usrsw.h"
-#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 (PYBOARD4)
- #define USRSW_PORT (GPIOB)
- #define USRSW_PIN (GPIO_Pin_3)
- #define USRSW_PUPD (GPIO_PuPd_UP)
- #define USRSW_EXTI_PIN (EXTI_PinSource3)
- #define USRSW_EXTI_PORT (EXTI_PortSourceGPIOB)
- #define USRSW_EXTI_LINE (EXTI_Line3)
- #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;