Add More Feature Test Macros
* Add MICROPY_HW_HAS_LCD * Add MICROPY_HW_HAS_WLAN * Use feature test macros in main
This commit is contained in:
parent
c3e72a8cc8
commit
c4808dae0a
54
stm/main.c
54
stm/main.c
@ -62,8 +62,10 @@ void flash_error(int n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void __fatal_error(const char *msg) {
|
void __fatal_error(const char *msg) {
|
||||||
|
#if MICROPY_HW_HAS_LCD
|
||||||
lcd_print_strn("\nFATAL ERROR:\n", 14);
|
lcd_print_strn("\nFATAL ERROR:\n", 14);
|
||||||
lcd_print_strn(msg, strlen(msg));
|
lcd_print_strn(msg, strlen(msg));
|
||||||
|
#endif
|
||||||
for (;;) {
|
for (;;) {
|
||||||
flash_error(1);
|
flash_error(1);
|
||||||
}
|
}
|
||||||
@ -727,7 +729,7 @@ int main(void) {
|
|||||||
;
|
;
|
||||||
|
|
||||||
// configure SDIO pins to be high to start with (apparently makes it more robust)
|
// configure SDIO pins to be high to start with (apparently makes it more robust)
|
||||||
{
|
#if MICROPY_HW_HAS_SDCARD
|
||||||
GPIO_InitTypeDef GPIO_InitStructure;
|
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_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_Speed = GPIO_Speed_25MHz;
|
||||||
@ -739,18 +741,23 @@ int main(void) {
|
|||||||
// Configure PD.02 CMD line
|
// Configure PD.02 CMD line
|
||||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
|
||||||
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
GPIO_Init(GPIOD, &GPIO_InitStructure);
|
||||||
}
|
#endif
|
||||||
|
|
||||||
// basic sub-system init
|
// basic sub-system init
|
||||||
sys_tick_init();
|
sys_tick_init();
|
||||||
led_init();
|
led_init();
|
||||||
|
|
||||||
|
#if MICROPY_HW_ENABLE_RTC
|
||||||
rtc_init();
|
rtc_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
// turn on LED to indicate bootup
|
// turn on LED to indicate bootup
|
||||||
led_state(PYB_LED_G1, 1);
|
led_state(PYB_LED_G1, 1);
|
||||||
|
|
||||||
// more sub-system init
|
// more sub-system init
|
||||||
|
#if MICROPY_HW_HAS_SWITCH
|
||||||
switch_init();
|
switch_init();
|
||||||
|
#endif
|
||||||
storage_init();
|
storage_init();
|
||||||
|
|
||||||
// uncomment these 2 lines if you want REPL on USART_6 (or another usart) as well as on USB VCP
|
// 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();
|
qstr_init();
|
||||||
rt_init();
|
rt_init();
|
||||||
|
|
||||||
|
#if MICROPY_HW_HAS_LCD
|
||||||
// LCD init
|
// 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
|
||||||
servo_init();
|
servo_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MICROPY_HW_ENABLE_AUDIO
|
||||||
// audio
|
// audio
|
||||||
//audio_init();
|
audio_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MICROPY_HW_ENABLE_TIMER
|
||||||
// timer
|
// timer
|
||||||
timer_init();
|
timer_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if MICROPY_HW_ENABLE_RNG
|
||||||
// RNG
|
// RNG
|
||||||
if (1) {
|
|
||||||
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);
|
RCC_AHB2PeriphClockCmd(RCC_AHB2Periph_RNG, ENABLE);
|
||||||
RNG_Cmd(ENABLE);
|
RNG_Cmd(ENABLE);
|
||||||
}
|
#endif
|
||||||
|
|
||||||
// add some functions to the python namespace
|
// add some functions to the python namespace
|
||||||
{
|
{
|
||||||
@ -792,7 +807,9 @@ soft_reset:
|
|||||||
|
|
||||||
mp_obj_t m = mp_obj_new_module(MP_QSTR_pyb);
|
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));
|
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));
|
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_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_standby, rt_make_function_n(0, pyb_standby));
|
||||||
rt_store_attr(m, MP_QSTR_source_dir, rt_make_function_n(1, pyb_source_dir));
|
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_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_gc, rt_make_function_n(0, pyb_gc));
|
||||||
rt_store_attr(m, MP_QSTR_delay, rt_make_function_n(1, pyb_delay));
|
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);
|
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));
|
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));
|
rt_store_attr(m, MP_QSTR_pwm, rt_make_function_n(2, pyb_pwm_set));
|
||||||
#if MICROPY_HW_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_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);
|
rt_store_attr(m, MP_QSTR_mma_mode, (mp_obj_t)&pyb_mma_write_mode_obj);
|
||||||
#endif
|
#endif
|
||||||
rt_store_attr(m, MP_QSTR_hid, rt_make_function_n(1, pyb_hid_send_report));
|
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));
|
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));
|
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);
|
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));
|
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_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_gpio, (mp_obj_t)&pyb_gpio_obj);
|
||||||
rt_store_attr(m, MP_QSTR_Usart, rt_make_function_n(2, pyb_Usart));
|
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));
|
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
|
// print a message to the LCD
|
||||||
lcd_print_str(" micro py board\n");
|
lcd_print_str(" micro py board\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
// check if user switch held (initiates reset of filesystem)
|
// check if user switch held (initiates reset of filesystem)
|
||||||
bool reset_filesystem = false;
|
bool reset_filesystem = false;
|
||||||
|
#if MICROPY_HW_HAS_SWITCH
|
||||||
if (switch_get()) {
|
if (switch_get()) {
|
||||||
reset_filesystem = true;
|
reset_filesystem = true;
|
||||||
for (int i = 0; i < 50; i++) {
|
for (int i = 0; i < 50; i++) {
|
||||||
@ -837,7 +867,7 @@ soft_reset:
|
|||||||
sys_tick_delay_ms(10);
|
sys_tick_delay_ms(10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
// local filesystem init
|
// local filesystem init
|
||||||
{
|
{
|
||||||
// try to mount the flash
|
// try to mount the flash
|
||||||
@ -965,11 +995,15 @@ soft_reset:
|
|||||||
data[2] = -2;
|
data[2] = -2;
|
||||||
data[3] = 0;
|
data[3] = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
#if MICROPY_HW_HAS_SWITCH
|
||||||
if (switch_get()) {
|
if (switch_get()) {
|
||||||
data[0] = 0x01; // 0x04 is middle, 0x02 is right
|
data[0] = 0x01; // 0x04 is middle, 0x02 is right
|
||||||
} else {
|
} else {
|
||||||
data[0] = 0x00;
|
data[0] = 0x00;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
data[0] = 0x00;
|
||||||
|
#endif
|
||||||
mma_start(0x4c /* MMA_ADDR */, 1);
|
mma_start(0x4c /* MMA_ADDR */, 1);
|
||||||
mma_send_byte(0);
|
mma_send_byte(0);
|
||||||
mma_restart(0x4c /* MMA_ADDR */, 0);
|
mma_restart(0x4c /* MMA_ADDR */, 0);
|
||||||
@ -987,9 +1021,11 @@ soft_reset:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if MICROPY_HW_HAS_WLAN
|
||||||
// wifi
|
// wifi
|
||||||
//pyb_wlan_init();
|
pyb_wlan_init();
|
||||||
//pyb_wlan_start();
|
pyb_wlan_start();
|
||||||
|
#endif
|
||||||
|
|
||||||
do_repl();
|
do_repl();
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@ machine_float_t machine_sqrt(machine_float_t x);
|
|||||||
#define MICROPY_HW_HAS_SDCARD (1)
|
#define MICROPY_HW_HAS_SDCARD (1)
|
||||||
#define MICROPY_HW_HAS_MMA7660 (1)
|
#define MICROPY_HW_HAS_MMA7660 (1)
|
||||||
#define MICROPY_HW_HAS_LIS3DSH (0)
|
#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_RNG (1)
|
||||||
#define MICROPY_HW_ENABLE_RTC (1)
|
#define MICROPY_HW_ENABLE_RTC (1)
|
||||||
#define MICROPY_HW_ENABLE_TIMER (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_SDCARD (1)
|
||||||
#define MICROPY_HW_HAS_MMA7660 (1)
|
#define MICROPY_HW_HAS_MMA7660 (1)
|
||||||
#define MICROPY_HW_HAS_LIS3DSH (0)
|
#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_RNG (1)
|
||||||
#define MICROPY_HW_ENABLE_RTC (1)
|
#define MICROPY_HW_ENABLE_RTC (1)
|
||||||
#define MICROPY_HW_ENABLE_TIMER (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_SDCARD (0)
|
||||||
#define MICROPY_HW_HAS_MMA7660 (0)
|
#define MICROPY_HW_HAS_MMA7660 (0)
|
||||||
#define MICROPY_HW_HAS_LIS3DSH (1)
|
#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_RNG (1)
|
||||||
#define MICROPY_HW_ENABLE_RTC (1)
|
#define MICROPY_HW_ENABLE_RTC (1)
|
||||||
#define MICROPY_HW_ENABLE_TIMER (1)
|
#define MICROPY_HW_ENABLE_TIMER (1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user