Thread *accRun(SPIDriver *spip, tprio_t prio) { Thread *tp; if (lsm303_init(spip) != 0) chSysHalt(); chThdSleepMilliseconds(200); lsm303_acc_update(spip); tp = chThdCreateFromHeap(NULL, ACC_WA_SIZE, prio, lsm303_acc_update_thread, (void*) spip); extChannelEnable(&EXTD1, GPIOA_AM_INT1); return tp; }
int main(void) { GPIO_InitTypeDef GPIO_InitStructure; SD_Error sderr; SD_CardInfo ci; // All GPIO clock enable RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB | RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD | RCC_AHB1Periph_GPIOE, ENABLE); // Configure LEDs in output pushpull mode GPIO_InitStructure.GPIO_Pin = LED_PIN_ALL; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(LED_GPIO, &GPIO_InitStructure); // Configure SysTick for 400ms period if(!tick_start(400.0)) { while(1); } /* if((SD_Init() == SD_OK) && SD_Detect()){ sderr = SD_GetCardInfo(&ci); if(sderr == SD_OK){ while(1); } } */ lsm303_init(); l3gd20_init(); while (1) { tick_wait(1); l3gd20_read_sync(); lsm303_read(); } }
static int magnetometer_lsm303_open(struct sol_flow_node *node, void *data, const struct sol_flow_node_options *options) { struct magnetometer_lsm303_data *mdata = data; const struct sol_flow_node_type_magnetometer_lsm303_options *opts; SOL_FLOW_NODE_OPTIONS_SUB_API_CHECK(options, SOL_FLOW_NODE_TYPE_MAGNETOMETER_LSM303_OPTIONS_API_VERSION, -EINVAL); opts = (const struct sol_flow_node_type_magnetometer_lsm303_options *)options; mdata->i2c = sol_i2c_open(opts->i2c_bus, SOL_I2C_SPEED_10KBIT); SOL_NULL_CHECK_MSG(mdata->i2c, -EINVAL, "Failed to open i2c bus"); mdata->slave = opts->i2c_slave; mdata->scale = opts->scale; mdata->node = node; lsm303_init(mdata); return 0; }