static int drv_ps_liteon_ltr553_read(void *buf, size_t len) { int ret = 0; size_t size; uint8_t reg_data[2] = {0}; proximity_data_t* pdata = (proximity_data_t*)buf; int wait_time = 0; if(buf == NULL){ return -1; } size = sizeof(proximity_data_t); if(len < size){ return -1; } ret = sensor_i2c_read(<r553_ctx, LTR553_PS_DATA_L, ®_data[0], I2C_DATA_LEN, I2C_OP_RETRIES); if (unlikely(ret)) { return -1; } ret = sensor_i2c_read(<r553_ctx, LTR553_PS_DATA_H, ®_data[1], I2C_DATA_LEN, I2C_OP_RETRIES); if (unlikely(ret)) { return -1; } pdata->present = (uint32_t)(reg_data[1] << 8 | reg_data[0]); pdata->timestamp = aos_now_ms(); return (int)size; }
static void key_ps_func(void *arg) { #if 0 uint32_t level; uint64_t diff; hal_gpio_input_get(&gpio_key_ps, &level); if (level == 0) { aos_post_delayed_action(10, key_ps_func, NULL); } else { diff = aos_now_ms() - ps_time; if (diff > 40) { ps_time = 0; aos_post_event(EV_KEY, CODE_BOOT, VALUE_KEY_PSCLICK); }else if (diff > 2000) { /* short press */ elink_time = 0; aos_post_event(EV_KEY, CODE_BOOT, VALUE_KEY_LPSCLICK); } else { aos_post_delayed_action(10, key_ps_func, NULL); } } #endif }
static void handle_ps_key(void *arg) { uint32_t gpio_value; hal_gpio_input_get(&gpio_key_ps, &gpio_value); if (gpio_value == 0 && ps_time == 0) { ps_time = aos_now_ms(); aos_loop_schedule_work(0, key_ps_work, NULL, NULL, NULL); } }
static void handle_elink_key(void *arg) { uint32_t gpio_value; hal_gpio_input_get(&gpio_key_boot, &gpio_value); if (gpio_value == 0 && elink_time == 0) { elink_time = aos_now_ms(); aos_loop_schedule_work(0, key_proc_work, NULL, NULL, NULL); } }
static int drv_als_liteon_ltr553_read(void *buf, size_t len) { int ret = 0; size_t size; uint16_t als_raw[2] = {0}; uint8_t reg_ch0[2] = {0}; uint8_t reg_ch1[2] = {0}; als_data_t* pdata = (als_data_t*)buf; int wait_time = 0; if(buf == NULL){ return -1; } size = sizeof(als_data_t); if(len < size){ return -1; } ret = sensor_i2c_read(<r553_ctx, LTR553_ALS_DATA1_L, ®_ch1[0], I2C_DATA_LEN, I2C_OP_RETRIES); if (unlikely(ret)) { return -1; } ret = sensor_i2c_read(<r553_ctx, LTR553_ALS_DATA1_H, ®_ch1[1], I2C_DATA_LEN, I2C_OP_RETRIES); if (unlikely(ret)) { return -1; } ret = sensor_i2c_read(<r553_ctx, LTR553_ALS_DATA0_L, ®_ch0[0], I2C_DATA_LEN, I2C_OP_RETRIES); if (unlikely(ret)) { return -1; } ret = sensor_i2c_read(<r553_ctx, LTR553_ALS_DATA0_H, ®_ch0[1], I2C_DATA_LEN, I2C_OP_RETRIES); if (unlikely(ret)) { return -1; } als_raw[0] = (uint16_t)reg_ch0[1] << 8 | reg_ch0[0]; als_raw[1] = (uint16_t)reg_ch1[1] << 8 | reg_ch1[0]; pdata->lux = (uint32_t)((als_raw[0] + als_raw[1]) >> 1); pdata->timestamp = aos_now_ms(); return (int)size; }
static int drv_acc_bosch_bma253_read(void *buf, size_t len) { int ret = 0; uint8_t reg[6]; accel_data_t *accel = buf; if(buf == NULL){ return -1; } ret = sensor_i2c_read(&bma253_ctx, BMA253_X_AXIS_LSB_ADDR, ®[0], I2C_REG_LEN, I2C_OP_RETRIES); ret |= sensor_i2c_read(&bma253_ctx, BMA253_X_AXIS_MSB_ADDR, ®[1], I2C_REG_LEN, I2C_OP_RETRIES); ret |= sensor_i2c_read(&bma253_ctx, BMA253_Y_AXIS_LSB_ADDR, ®[2], I2C_REG_LEN, I2C_OP_RETRIES); ret |= sensor_i2c_read(&bma253_ctx, BMA253_Y_AXIS_MSB_ADDR, ®[3], I2C_REG_LEN, I2C_OP_RETRIES); ret |= sensor_i2c_read(&bma253_ctx, BMA253_Z_AXIS_LSB_ADDR, ®[4], I2C_REG_LEN, I2C_OP_RETRIES); ret |= sensor_i2c_read(&bma253_ctx, BMA253_Z_AXIS_MSB_ADDR, ®[5], I2C_REG_LEN, I2C_OP_RETRIES); if(unlikely(ret)){ return ret; } accel->data[DATA_AXIS_X] = (int16_t)((((int32_t)((int8_t)reg[1]))<< BMA253_SHIFT_EIGHT_BITS)|(reg[0] &BMA253_12_BIT_SHIFT)); accel->data[DATA_AXIS_X] = accel->data[DATA_AXIS_X] >> BMA253_SHIFT_FOUR_BITS; accel->data[DATA_AXIS_Y] = (int16_t)((((int32_t)((int8_t)reg[3]))<< BMA253_SHIFT_EIGHT_BITS)|(reg[2] &BMA253_12_BIT_SHIFT)); accel->data[DATA_AXIS_Y] = accel->data[DATA_AXIS_Y] >> BMA253_SHIFT_FOUR_BITS; accel->data[DATA_AXIS_Z] = (int16_t)((((int32_t)((int8_t)reg[5]))<< BMA253_SHIFT_EIGHT_BITS)|(reg[4]&BMA253_12_BIT_SHIFT)); accel->data[DATA_AXIS_Z] = accel->data[DATA_AXIS_Z] >> BMA253_SHIFT_FOUR_BITS; if(current_factor != 0){ // the unit of acc is mg, 1000 mg = 1 g. accel->data[DATA_AXIS_X] = accel->data[DATA_AXIS_X] * ACCELEROMETER_UNIT_FACTOR / current_factor; accel->data[DATA_AXIS_Y] = accel->data[DATA_AXIS_Y] * ACCELEROMETER_UNIT_FACTOR / current_factor; accel->data[DATA_AXIS_Z] = accel->data[DATA_AXIS_Z] * ACCELEROMETER_UNIT_FACTOR / current_factor; } accel->timestamp = aos_now_ms(); len = sizeof(accel_data_t); return 0; }
void k_timer_start(k_timer_t *timer, uint32_t timeout) { int ret; ASSERT(timer, "timer is NULL"); BT_DBG("timer %p,timeout %u", timer, timeout); timer->timeout = timeout; timer->start_ms = aos_now_ms(); ret = aos_timer_stop(&timer->timer); if (ret) { BT_DBG("fail to stop timer"); } ret = aos_timer_change(&timer->timer, timeout); if (ret) { BT_DBG("fail to change timeout"); } ret = aos_timer_start(&timer->timer); if (ret) { BT_DBG("fail to start timer"); } }
int64_t k_uptime_get() { return aos_now_ms(); }