Esempio n. 1
0
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(&ltr553_ctx, LTR553_PS_DATA_L, &reg_data[0], I2C_DATA_LEN, I2C_OP_RETRIES);
    if (unlikely(ret)) {
        return -1;
    }
    ret = sensor_i2c_read(&ltr553_ctx, LTR553_PS_DATA_H, &reg_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;
}
Esempio n. 2
0
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
}
Esempio n. 3
0
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);
    }
}
Esempio n. 4
0
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);
    }
}
Esempio n. 5
0
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(&ltr553_ctx, LTR553_ALS_DATA1_L, &reg_ch1[0], I2C_DATA_LEN, I2C_OP_RETRIES);
    if (unlikely(ret)) {
        return -1;
    }
    ret = sensor_i2c_read(&ltr553_ctx, LTR553_ALS_DATA1_H, &reg_ch1[1], I2C_DATA_LEN, I2C_OP_RETRIES);
    if (unlikely(ret)) {
        return -1;
    }
    ret = sensor_i2c_read(&ltr553_ctx, LTR553_ALS_DATA0_L, &reg_ch0[0], I2C_DATA_LEN, I2C_OP_RETRIES);
    if (unlikely(ret)) {
        return -1;
    }
    ret = sensor_i2c_read(&ltr553_ctx, LTR553_ALS_DATA0_H, &reg_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;
}
Esempio n. 6
0
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,  &reg[0], I2C_REG_LEN, I2C_OP_RETRIES);
    ret |= sensor_i2c_read(&bma253_ctx, BMA253_X_AXIS_MSB_ADDR,  &reg[1], I2C_REG_LEN, I2C_OP_RETRIES);
    ret |= sensor_i2c_read(&bma253_ctx, BMA253_Y_AXIS_LSB_ADDR,  &reg[2], I2C_REG_LEN, I2C_OP_RETRIES);
    ret |= sensor_i2c_read(&bma253_ctx, BMA253_Y_AXIS_MSB_ADDR,  &reg[3], I2C_REG_LEN, I2C_OP_RETRIES);
    ret |= sensor_i2c_read(&bma253_ctx, BMA253_Z_AXIS_LSB_ADDR,  &reg[4], I2C_REG_LEN, I2C_OP_RETRIES);
    ret |= sensor_i2c_read(&bma253_ctx, BMA253_Z_AXIS_MSB_ADDR,  &reg[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;
}
Esempio n. 7
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");
    }
}
Esempio n. 8
0
int64_t k_uptime_get()
{
    return aos_now_ms();
}