From c4808dae0ac4d84c1b7651c904a42cfc47313a91 Mon Sep 17 00:00:00 2001 From: mux Date: Thu, 23 Jan 2014 13:16:06 +0200 Subject: [PATCH] Add More Feature Test Macros * Add MICROPY_HW_HAS_LCD * Add MICROPY_HW_HAS_WLAN * Use feature test macros in main --- stm/main.c | 78 +++++++++++++++++++++++++++++++++------------- stm/mpconfigport.h | 6 ++++ 2 files changed, 63 insertions(+), 21 deletions(-) diff --git a/stm/main.c b/stm/main.c index 40831c9930..2865b3a986 100644 --- a/stm/main.c +++ b/stm/main.c @@ -62,8 +62,10 @@ void flash_error(int n) { } void __fatal_error(const char *msg) { +#if MICROPY_HW_HAS_LCD lcd_print_strn("\nFATAL ERROR:\n", 14); lcd_print_strn(msg, strlen(msg)); +#endif for (;;) { flash_error(1); } @@ -727,30 +729,35 @@ int main(void) { ; // configure SDIO pins to be high to start with (apparently makes it more robust) - { - GPIO_InitTypeDef GPIO_InitStructure; - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12; - GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz; - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; - GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; - GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; - GPIO_Init(GPIOC, &GPIO_InitStructure); +#if MICROPY_HW_HAS_SDCARD + GPIO_InitTypeDef GPIO_InitStructure; + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; + GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; + GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; + GPIO_Init(GPIOC, &GPIO_InitStructure); - // Configure PD.02 CMD line - GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; - GPIO_Init(GPIOD, &GPIO_InitStructure); - } + // Configure PD.02 CMD line + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; + GPIO_Init(GPIOD, &GPIO_InitStructure); +#endif // basic sub-system init sys_tick_init(); led_init(); + +#if MICROPY_HW_ENABLE_RTC rtc_init(); +#endif // turn on LED to indicate bootup led_state(PYB_LED_G1, 1); // more sub-system init +#if MICROPY_HW_HAS_SWITCH switch_init(); +#endif storage_init(); // uncomment these 2 lines if you want REPL on USART_6 (or another usart) as well as on USB VCP @@ -768,23 +775,31 @@ soft_reset: qstr_init(); rt_init(); +#if MICROPY_HW_HAS_LCD // LCD init - //lcd_init(); disabled while servos on PA0 PA1 + lcd_init(); /* disabled while servos on PA0 PA1 */ +#endif +#if MICROPY_HW_ENABLE_SERVO // servo servo_init(); +#endif +#if MICROPY_HW_ENABLE_AUDIO // audio - //audio_init(); + audio_init(); +#endif +#if MICROPY_HW_ENABLE_TIMER // timer timer_init(); +#endif +#if MICROPY_HW_ENABLE_RNG // RNG - if (1) { - RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE); - RNG_Cmd(ENABLE); - } + RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE); + RNG_Cmd(ENABLE); +#endif // add some functions to the python namespace { @@ -792,7 +807,9 @@ soft_reset: mp_obj_t m = mp_obj_new_module(MP_QSTR_pyb); rt_store_attr(m, MP_QSTR_info, rt_make_function_n(0, pyb_info)); +#if MICROPY_HW_HAS_SDCARD rt_store_attr(m, MP_QSTR_sd_test, rt_make_function_n(0, pyb_sd_test)); +#endif rt_store_attr(m, MP_QSTR_stop, rt_make_function_n(0, pyb_stop)); rt_store_attr(m, MP_QSTR_standby, rt_make_function_n(0, pyb_standby)); rt_store_attr(m, MP_QSTR_source_dir, rt_make_function_n(1, pyb_source_dir)); @@ -800,8 +817,12 @@ soft_reset: rt_store_attr(m, MP_QSTR_sync, rt_make_function_n(0, pyb_sync)); rt_store_attr(m, MP_QSTR_gc, rt_make_function_n(0, pyb_gc)); rt_store_attr(m, MP_QSTR_delay, rt_make_function_n(1, pyb_delay)); +#if MICROPY_HW_HAS_SWITCH rt_store_attr(m, MP_QSTR_switch, (mp_obj_t)&pyb_switch_obj); +#endif +#if MICROPY_HW_ENABLE_SERVO rt_store_attr(m, MP_QSTR_servo, rt_make_function_n(2, pyb_servo_set)); +#endif rt_store_attr(m, MP_QSTR_pwm, rt_make_function_n(2, pyb_pwm_set)); #if MICROPY_HW_HAS_MMA7660 rt_store_attr(m, MP_QSTR_accel, (mp_obj_t)&pyb_mma_read_obj); @@ -809,10 +830,16 @@ soft_reset: rt_store_attr(m, MP_QSTR_mma_mode, (mp_obj_t)&pyb_mma_write_mode_obj); #endif rt_store_attr(m, MP_QSTR_hid, rt_make_function_n(1, pyb_hid_send_report)); +#if MICROPY_HW_HAS_RTC rt_store_attr(m, MP_QSTR_time, rt_make_function_n(0, pyb_rtc_read)); +#endif +#if MICROPY_HW_ENABLE_RNG rt_store_attr(m, MP_QSTR_rand, rt_make_function_n(0, pyb_rng_get)); +#endif rt_store_attr(m, MP_QSTR_Led, (mp_obj_t)&pyb_Led_obj); +#if MICROPY_HW_ENABLE_SERVO rt_store_attr(m, MP_QSTR_Servo, rt_make_function_n(1, pyb_Servo)); +#endif rt_store_attr(m, MP_QSTR_I2C, rt_make_function_n(2, pyb_I2C)); rt_store_attr(m, MP_QSTR_gpio, (mp_obj_t)&pyb_gpio_obj); rt_store_attr(m, MP_QSTR_Usart, rt_make_function_n(2, pyb_Usart)); @@ -822,11 +849,14 @@ soft_reset: rt_store_name(MP_QSTR_open, rt_make_function_n(2, pyb_io_open)); } +#if MICROPY_HW_HAS_LCD // print a message to the LCD lcd_print_str(" micro py board\n"); +#endif // check if user switch held (initiates reset of filesystem) bool reset_filesystem = false; +#if MICROPY_HW_HAS_SWITCH if (switch_get()) { reset_filesystem = true; for (int i = 0; i < 50; i++) { @@ -837,7 +867,7 @@ soft_reset: sys_tick_delay_ms(10); } } - +#endif // local filesystem init { // try to mount the flash @@ -965,11 +995,15 @@ soft_reset: data[2] = -2; data[3] = 0; for (;;) { + #if MICROPY_HW_HAS_SWITCH if (switch_get()) { data[0] = 0x01; // 0x04 is middle, 0x02 is right } else { data[0] = 0x00; } + #else + data[0] = 0x00; + #endif mma_start(0x4c /* MMA_ADDR */, 1); mma_send_byte(0); mma_restart(0x4c /* MMA_ADDR */, 0); @@ -987,9 +1021,11 @@ soft_reset: } #endif +#if MICROPY_HW_HAS_WLAN // wifi - //pyb_wlan_init(); - //pyb_wlan_start(); + pyb_wlan_init(); + pyb_wlan_start(); +#endif do_repl(); diff --git a/stm/mpconfigport.h b/stm/mpconfigport.h index 4bd7537807..6a1856e521 100644 --- a/stm/mpconfigport.h +++ b/stm/mpconfigport.h @@ -32,6 +32,8 @@ machine_float_t machine_sqrt(machine_float_t x); #define MICROPY_HW_HAS_SDCARD (1) #define MICROPY_HW_HAS_MMA7660 (1) #define MICROPY_HW_HAS_LIS3DSH (0) + #define MICROPY_HW_HAS_LCD (0) + #define MICROPY_HW_HAS_WLAN (0) #define MICROPY_HW_ENABLE_RNG (1) #define MICROPY_HW_ENABLE_RTC (1) #define MICROPY_HW_ENABLE_TIMER (1) @@ -51,6 +53,8 @@ machine_float_t machine_sqrt(machine_float_t x); #define MICROPY_HW_HAS_SDCARD (1) #define MICROPY_HW_HAS_MMA7660 (1) #define MICROPY_HW_HAS_LIS3DSH (0) + #define MICROPY_HW_HAS_LCD (0) + #define MICROPY_HW_HAS_WLAN (0) #define MICROPY_HW_ENABLE_RNG (1) #define MICROPY_HW_ENABLE_RTC (1) #define MICROPY_HW_ENABLE_TIMER (1) @@ -70,6 +74,8 @@ machine_float_t machine_sqrt(machine_float_t x); #define MICROPY_HW_HAS_SDCARD (0) #define MICROPY_HW_HAS_MMA7660 (0) #define MICROPY_HW_HAS_LIS3DSH (1) + #define MICROPY_HW_HAS_LCD (0) + #define MICROPY_HW_HAS_WLAN (0) #define MICROPY_HW_ENABLE_RNG (1) #define MICROPY_HW_ENABLE_RTC (1) #define MICROPY_HW_ENABLE_TIMER (1)