From 28b23f09a4040b37356b486deca4ed7da6ff9fa6 Mon Sep 17 00:00:00 2001 From: mux Date: Wed, 22 Jan 2014 17:42:06 +0200 Subject: [PATCH 1/3] Add Generic Feature Macros to mpconfigport * Add some generic feature macros to mpconfigport * Move pin and port definitions from usrsw.c to mpconfigport --- stm/main.c | 6 ++--- stm/mpconfigport.h | 63 +++++++++++++++++++++++++++++++++++++++++----- stm/usrsw.c | 30 +--------------------- 3 files changed, 61 insertions(+), 38 deletions(-) diff --git a/stm/main.c b/stm/main.c index 8d2c2d6b3d..540f38df10 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 __HAVE_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); @@ -923,7 +923,7 @@ soft_reset: //pyb_usbh_init(); if (first_soft_reset) { -#if BOARD_HAS_MMA7660 +#if __HAVE_MMA7660 // MMA: init and reset address to zero mma_init(); #endif @@ -954,7 +954,7 @@ soft_reset: } -#if BOARD_HAS_MMA7660 +#if __HAVE_MMA7660 // HID example if (0) { uint8_t data[4]; diff --git a/stm/mpconfigport.h b/stm/mpconfigport.h index 75f6fe11b5..4d8db39e80 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 __HAVE_SWITCH (1) + #define __HAVE_SDCARD (1) + #define __HAVE_MMA7660 (1) + #define __HAVE_LIS3DSH (0) + #define __ENABLE_RNG (1) + #define __ENABLE_RTC (1) + #define __ENABLE_TIMER (1) + #define __ENABLE_SERVO (1) + #define __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 __HAVE_SWITCH (1) + #define __HAVE_SDCARD (1) + #define __HAVE_MMA7660 (1) + #define __HAVE_LIS3DSH (0) + #define __ENABLE_RNG (1) + #define __ENABLE_RTC (1) + #define __ENABLE_TIMER (1) + #define __ENABLE_SERVO (1) + #define __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 __HAVE_SWITCH (1) + #define __HAVE_SDCARD (0) + #define __HAVE_MMA7660 (0) + #define __HAVE_LIS3DSH (1) + #define __ENABLE_RNG (1) + #define __ENABLE_RTC (1) + #define __ENABLE_TIMER (1) + #define __ENABLE_SERVO (0) + #define __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; From 630d8ff89f6d2a950915c140cc6e420ab4d952cd Mon Sep 17 00:00:00 2001 From: mux Date: Wed, 22 Jan 2014 18:11:48 +0200 Subject: [PATCH 2/3] Remove Underscore from Macro Names --- stm/main.c | 6 +++--- stm/mpconfigport.h | 54 +++++++++++++++++++++++----------------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/stm/main.c b/stm/main.c index 540f38df10..fe363eb715 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 __HAVE_MMA7660 +#if HAVE_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); @@ -923,7 +923,7 @@ soft_reset: //pyb_usbh_init(); if (first_soft_reset) { -#if __HAVE_MMA7660 +#if HAVE_MMA7660 // MMA: init and reset address to zero mma_init(); #endif @@ -954,7 +954,7 @@ soft_reset: } -#if __HAVE_MMA7660 +#if HAVE_MMA7660 // HID example if (0) { uint8_t data[4]; diff --git a/stm/mpconfigport.h b/stm/mpconfigport.h index 4d8db39e80..0f11dd7371 100644 --- a/stm/mpconfigport.h +++ b/stm/mpconfigport.h @@ -28,15 +28,15 @@ machine_float_t machine_sqrt(machine_float_t x); //#define STM32F4DISC #if defined (PYBOARD) - #define __HAVE_SWITCH (1) - #define __HAVE_SDCARD (1) - #define __HAVE_MMA7660 (1) - #define __HAVE_LIS3DSH (0) - #define __ENABLE_RNG (1) - #define __ENABLE_RTC (1) - #define __ENABLE_TIMER (1) - #define __ENABLE_SERVO (1) - #define __ENABLE_AUDIO (0) + #define HAVE_SWITCH (1) + #define HAVE_SDCARD (1) + #define HAVE_MMA7660 (1) + #define HAVE_LIS3DSH (0) + #define ENABLE_RNG (1) + #define ENABLE_RTC (1) + #define ENABLE_TIMER (1) + #define ENABLE_SERVO (1) + #define ENABLE_AUDIO (0) #define USRSW_PORT (GPIOA) #define USRSW_PIN (GPIO_Pin_13) @@ -47,15 +47,15 @@ machine_float_t machine_sqrt(machine_float_t x); #define USRSW_EXTI_IRQN (EXTI15_10_IRQn) #define USRSW_EXTI_EDGE (EXTI_Trigger_Rising) #elif defined (PYBOARD4) - #define __HAVE_SWITCH (1) - #define __HAVE_SDCARD (1) - #define __HAVE_MMA7660 (1) - #define __HAVE_LIS3DSH (0) - #define __ENABLE_RNG (1) - #define __ENABLE_RTC (1) - #define __ENABLE_TIMER (1) - #define __ENABLE_SERVO (1) - #define __ENABLE_AUDIO (0) + #define HAVE_SWITCH (1) + #define HAVE_SDCARD (1) + #define HAVE_MMA7660 (1) + #define HAVE_LIS3DSH (0) + #define ENABLE_RNG (1) + #define ENABLE_RTC (1) + #define ENABLE_TIMER (1) + #define ENABLE_SERVO (1) + #define ENABLE_AUDIO (0) #define USRSW_PORT (GPIOB) #define USRSW_PIN (GPIO_Pin_3) @@ -66,15 +66,15 @@ machine_float_t machine_sqrt(machine_float_t x); #define USRSW_EXTI_IRQN (EXTI15_10_IRQn) #define USRSW_EXTI_EDGE (EXTI_Trigger_Rising) #elif defined (STM32F4DISC) - #define __HAVE_SWITCH (1) - #define __HAVE_SDCARD (0) - #define __HAVE_MMA7660 (0) - #define __HAVE_LIS3DSH (1) - #define __ENABLE_RNG (1) - #define __ENABLE_RTC (1) - #define __ENABLE_TIMER (1) - #define __ENABLE_SERVO (0) - #define __ENABLE_AUDIO (0) + #define HAVE_SWITCH (1) + #define HAVE_SDCARD (0) + #define HAVE_MMA7660 (0) + #define HAVE_LIS3DSH (1) + #define ENABLE_RNG (1) + #define ENABLE_RTC (1) + #define ENABLE_TIMER (1) + #define ENABLE_SERVO (0) + #define ENABLE_AUDIO (0) #define USRSW_PORT (GPIOA) #define USRSW_PIN (GPIO_Pin_0) From 3c7e71fb002c71ba8de30ed377e98dfddd478e67 Mon Sep 17 00:00:00 2001 From: mux Date: Wed, 22 Jan 2014 20:34:02 +0200 Subject: [PATCH 3/3] Fix Feature Macro Prefix --- stm/main.c | 6 +++--- stm/mpconfigport.h | 54 +++++++++++++++++++++++----------------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/stm/main.c b/stm/main.c index fe363eb715..4a16576f4d 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 HAVE_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); @@ -923,7 +923,7 @@ soft_reset: //pyb_usbh_init(); if (first_soft_reset) { -#if HAVE_MMA7660 +#if MICROPY_HW_HAS_MMA7660 // MMA: init and reset address to zero mma_init(); #endif @@ -954,7 +954,7 @@ soft_reset: } -#if HAVE_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 0f11dd7371..4bd7537807 100644 --- a/stm/mpconfigport.h +++ b/stm/mpconfigport.h @@ -28,15 +28,15 @@ machine_float_t machine_sqrt(machine_float_t x); //#define STM32F4DISC #if defined (PYBOARD) - #define HAVE_SWITCH (1) - #define HAVE_SDCARD (1) - #define HAVE_MMA7660 (1) - #define HAVE_LIS3DSH (0) - #define ENABLE_RNG (1) - #define ENABLE_RTC (1) - #define ENABLE_TIMER (1) - #define ENABLE_SERVO (1) - #define ENABLE_AUDIO (0) + #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) @@ -47,15 +47,15 @@ machine_float_t machine_sqrt(machine_float_t x); #define USRSW_EXTI_IRQN (EXTI15_10_IRQn) #define USRSW_EXTI_EDGE (EXTI_Trigger_Rising) #elif defined (PYBOARD4) - #define HAVE_SWITCH (1) - #define HAVE_SDCARD (1) - #define HAVE_MMA7660 (1) - #define HAVE_LIS3DSH (0) - #define ENABLE_RNG (1) - #define ENABLE_RTC (1) - #define ENABLE_TIMER (1) - #define ENABLE_SERVO (1) - #define ENABLE_AUDIO (0) + #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) @@ -66,15 +66,15 @@ machine_float_t machine_sqrt(machine_float_t x); #define USRSW_EXTI_IRQN (EXTI15_10_IRQn) #define USRSW_EXTI_EDGE (EXTI_Trigger_Rising) #elif defined (STM32F4DISC) - #define HAVE_SWITCH (1) - #define HAVE_SDCARD (0) - #define HAVE_MMA7660 (0) - #define HAVE_LIS3DSH (1) - #define ENABLE_RNG (1) - #define ENABLE_RTC (1) - #define ENABLE_TIMER (1) - #define ENABLE_SERVO (0) - #define ENABLE_AUDIO (0) + #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)