/*---------------------------------------------------------------------------*/ void board_init() { /* Disable global interrupts */ uint8_t int_disabled = ti_lib_int_master_disable(); power_domains_on(); /* Configure all clock domains to run at full speed */ ti_lib_prcm_clock_configure_set(PRCM_DOMAIN_SYSBUS, PRCM_CLOCK_DIV_1); ti_lib_prcm_clock_configure_set(PRCM_DOMAIN_CPU, PRCM_CLOCK_DIV_1); ti_lib_prcm_clock_configure_set(PRCM_DOMAIN_TIMER, PRCM_CLOCK_DIV_1); ti_lib_prcm_clock_configure_set(PRCM_DOMAIN_SERIAL, PRCM_CLOCK_DIV_1); ti_lib_prcm_clock_configure_set(PRCM_DOMAIN_PERIPH, PRCM_CLOCK_DIV_1); /* Enable GPIO peripheral */ ti_lib_prcm_peripheral_run_enable(PRCM_PERIPH_GPIO); /* Apply settings and wait for them to take effect */ ti_lib_prcm_load_set(); while(!ti_lib_prcm_load_get()); /* Enable GPT0 module - Wait for the clock to be enabled */ ti_lib_prcm_peripheral_run_enable(PRCM_PERIPH_TIMER0); ti_lib_prcm_load_set(); while(!ti_lib_prcm_load_get()); /* Keys (input pullup) */ ti_lib_rom_ioc_pin_type_gpio_input(BOARD_IOID_KEY_LEFT); ti_lib_rom_ioc_pin_type_gpio_input(BOARD_IOID_KEY_RIGHT); ti_lib_ioc_io_port_pull_set(BOARD_IOID_KEY_LEFT, IOC_IOPULL_UP); ti_lib_ioc_io_port_pull_set(BOARD_IOID_KEY_RIGHT, IOC_IOPULL_UP); /* I2C controller */ board_i2c_init(); /* Sensor interface */ ti_lib_rom_ioc_pin_type_gpio_input(BOARD_IOID_MPU_INT); ti_lib_ioc_io_port_pull_set(BOARD_IOID_MPU_INT, IOC_IOPULL_DOWN); ti_lib_rom_ioc_pin_type_gpio_input(BOARD_IOID_REED_RELAY); ti_lib_ioc_io_port_pull_set(BOARD_IOID_REED_RELAY, IOC_IOPULL_DOWN); ti_lib_rom_ioc_pin_type_gpio_output(BOARD_IOID_MPU_POWER); /* Flash interface */ ti_lib_rom_ioc_pin_type_gpio_output(BOARD_IOID_FLASH_CS); ti_lib_gpio_pin_write(BOARD_FLASH_CS, 1); buzzer_init(); lpm_register_module(&sensortag_module); /* Re-enable interrupt if initially enabled. */ if(!int_disabled) { ti_lib_int_master_enable(); } }
/** * \brief Configuration function for the button sensor for all buttons. * * \param type This function does nothing unless type == SENSORS_ACTIVE * \param c 0: disable the button, non-zero: enable * \param key: One of BOARD_KEY_LEFT, BOARD_KEY_RIGHT etc */ static void config_buttons(int type, int c, uint32_t key) { switch(type) { case SENSORS_HW_INIT: ti_lib_gpio_clear_event_dio(key); ti_lib_rom_ioc_pin_type_gpio_input(key); ti_lib_rom_ioc_port_configure_set(key, IOC_PORT_GPIO, BUTTON_GPIO_CFG); gpio_interrupt_register_handler(key, button_press_handler); break; case SENSORS_ACTIVE: if(c) { ti_lib_gpio_clear_event_dio(key); ti_lib_rom_ioc_pin_type_gpio_input(key); ti_lib_rom_ioc_port_configure_set(key, IOC_PORT_GPIO, BUTTON_GPIO_CFG); ti_lib_rom_ioc_int_enable(key); } else { ti_lib_rom_ioc_int_disable(key); } break; default: break; } }
/** * \brief Configuration function for the MPU9250 sensor. * * \param type Activate, enable or disable the sensor. See below * \param enable * * When type == SENSORS_HW_INIT we turn on the hardware * When type == SENSORS_ACTIVE and enable==1 we enable the sensor * When type == SENSORS_ACTIVE and enable==0 we disable the sensor */ static int configure(int type, int enable) { switch(type) { case SENSORS_HW_INIT: ti_lib_rom_ioc_pin_type_gpio_input(BOARD_IOID_MPU_INT); ti_lib_ioc_io_port_pull_set(BOARD_IOID_MPU_INT, IOC_IOPULL_DOWN); ti_lib_ioc_io_hyst_set(BOARD_IOID_MPU_INT, IOC_HYST_ENABLE); ti_lib_rom_ioc_pin_type_gpio_output(BOARD_IOID_MPU_POWER); ti_lib_ioc_io_drv_strength_set(BOARD_IOID_MPU_POWER, IOC_CURRENT_4MA, IOC_STRENGTH_MAX); ti_lib_gpio_clear_dio(BOARD_IOID_MPU_POWER); elements = MPU_9250_SENSOR_TYPE_NONE; break; case SENSORS_ACTIVE: if(((enable & MPU_9250_SENSOR_TYPE_ACC) != 0) || ((enable & MPU_9250_SENSOR_TYPE_GYRO) != 0)) { PRINTF("MPU: Enabling\n"); elements = enable & MPU_9250_SENSOR_TYPE_ALL; power_up(); state = SENSOR_STATE_BOOTING; } else { PRINTF("MPU: Disabling\n"); if(HWREG(GPIO_BASE + GPIO_O_DOUT31_0) & BOARD_MPU_POWER) { /* Then check our state */ elements = MPU_9250_SENSOR_TYPE_NONE; ctimer_stop(&startup_timer); sensor_sleep(); while(ti_lib_i2c_master_busy(I2C0_BASE)); state = SENSOR_STATE_DISABLED; ti_lib_gpio_clear_dio(BOARD_IOID_MPU_POWER); } } break; default: break; } return state; }