Exemple #1
0
void init(char *_i2c_bus)
{
   assert(_i2c_bus);
   if (initialized)
      return;
   i2c_bus_open(&i2c_bus, _i2c_bus);
   i2c_dev_init(&i2c_dev, &i2c_bus, 0x3d);
   ssd1306_init(&ssd, &i2c_dev);
   initialized = true;
}
Exemple #2
0
static void application_init()
{
    // Power on peripheral devices
    periph = new CPowerCtrl(POWER_CNTL_IO);
    periph->on();

    // Init I2C devices
    i2c_dev_init();

    // Init touch pad
    tp_left = new CTouchPad(TOUCH_PAD_LEFT);
    tp_left->add_cb(TOUCHPAD_CB_TAP, touch_press_1s_cb, tp_left);
    tp_left->add_custom_cb(2, touch_press_2s_cb, tp_left);
    tp_right = new CTouchPad(TOUCH_PAD_RIGHT);
    tp_right->add_cb(TOUCHPAD_CB_TAP, touch_press_1s_cb, tp_right);
    tp_right->add_custom_cb(2, touch_press_2s_cb, tp_right);

    // Set deep-sleep wake-up mode
    esp_deep_sleep_enable_touchpad_wakeup();
}
Exemple #3
0
int main_i2c(void)
{
   THROW_BEGIN();

   void *gps_socket = scl_get_socket("gps");
   THROW_IF(gps_socket == NULL, -EIO);
   int64_t hwm = 1;
   zmq_setsockopt(gps_socket, ZMQ_SNDHWM, &hwm, sizeof(hwm));

   void *sats_socket = scl_get_socket("sats");
   THROW_IF(sats_socket == NULL, -EIO);
 
   i2c_bus_t bus;
   i2c_dev_t device;

   uint8_t data_w[128];
   uint8_t data_r[128];   

   if (i2c_bus_open(&bus, "/dev/i2c-1"))
   {
      syslog(LOG_CRIT, "could not open i2c device");   
      exit(EXIT_FAILURE);
   }
   i2c_dev_init(&device, &bus, I2C_GPS_ADDRESS);
   
   msgpack_sbuffer *msgpack_buf = msgpack_sbuffer_new();
   THROW_IF(msgpack_buf == NULL, -ENOMEM);
   msgpack_packer *pk = msgpack_packer_new(msgpack_buf, msgpack_sbuffer_write);
   THROW_IF(pk == NULL, -ENOMEM);

   while (1)
   {
      msleep(200);

      data_w[0] = I2C_GPS_STATUS;
      i2c_xfer(&device, 1, data_w, 1, data_r);
      
      msgpack_sbuffer_clear(msgpack_buf);
      int status = data_r[0];
      int fix = 0;
      if (status & I2C_GPS_STATUS_2DFIX)
         fix = 2;
      if (status & I2C_GPS_STATUS_3DFIX)
         fix = 3;

      if (fix == 2)
         msgpack_pack_array(pk, 7); /* 2d fix */
      else if (fix == 3)
         msgpack_pack_array(pk, 9); /* 3d fix */
      else
         msgpack_pack_array(pk, 1); /* no fix */
 
      data_w[0] = I2C_GPS_TIME;
      i2c_xfer(&device, 1, data_w, 4, data_r);
      long time = (((long) data_r[3]) << 24)
                | (((long) data_r[2]) << 16) 
                | (((long) data_r[1]) << 8) 
                | (data_r[0]);
      time /= 1000;
      char *time_str = ctime(&time);
      size_t len = strlen(time_str);
      msgpack_pack_raw(pk, len);
      msgpack_pack_raw_body(pk, time_str, len); /* gps array index 0 */

      if (fix == 2 || fix == 3)
      {
         data_w[0] = I2C_GPS_LOCATION;
         i2c_xfer(&device, 1, data_w, 8, data_r);
         PACKD(( (((long) data_r[3]) << 24) 
               | (((long) data_r[2]) << 16) 
               | (((long) data_r[1]) << 8) 
               | (data_r[0])) / 10000000.0); /* latitude, gps array index 1 */

         PACKD(( (((long) data_r[7]) << 24) 
               | (((long) data_r[6]) << 16) 
               | (((long) data_r[5]) << 8) 
               | (data_r[4])) / 10000000.0); /* logitude, gps array index 2 */

         PACKI((status & I2C_GPS_STATUS_NUMSATS) >> 4); /* gps array index 3 */
         
         data_w[0] = I2C_GPS_GROUND_SPEED;
         i2c_xfer(&device, 1, data_w, 2, data_r);
         PACKF(((float)((data_r[1] << 8) | data_r[0])) / 100.0 * 1.94384); /* gps array index 4 */
         
         data_w[0] = I2C_GPS_GROUND_SPEED;
         i2c_xfer(&device, 1, data_w, 2, data_r);
         PACKF((data_r[1] << 8) | data_r[0]); /* gps array index 5 */
         
         PACKF(0 /* HDOP */); /* gps array index 6 */
      }

      if (fix == 3)
      {
         data_w[0] = I2C_GPS_ALTITUDE;
         i2c_xfer(&device, 1, data_w, 2, data_r);
         PACKF(((data_r[1]) << 8) | data_r[0]);  /* gps array index 7 */
         PACKF(0 /* VDOP */); /* gps array index 8 */
      }
            
      scl_copy_send_dynamic(gps_socket, msgpack_buf->data, msgpack_buf->size);
   }
Exemple #4
0
int __init i2c_dev_init(void)
{
	int res;

	printk(KERN_INFO "i2c-dev.o: i2c /dev entries driver module version %s (%s)\n", I2C_VERSION, I2C_DATE);

	i2cdev_initialized = 0;
#ifdef CONFIG_DEVFS_FS
	if (devfs_register_chrdev(I2C_MAJOR, "i2c", &i2cdev_fops)) {
#else
	if (register_chrdev(I2C_MAJOR,"i2c",&i2cdev_fops)) {
#endif
		printk(KERN_ERR "i2c-dev.o: unable to get major %d for i2c bus\n",
		       I2C_MAJOR);
		return -EIO;
	}
#ifdef CONFIG_DEVFS_FS
	devfs_handle = devfs_mk_dir(NULL, "i2c", NULL);
#endif
	i2cdev_initialized ++;

	if ((res = i2c_add_driver(&i2cdev_driver))) {
		printk(KERN_ERR "i2c-dev.o: Driver registration failed, module not inserted.\n");
		i2cdev_cleanup();
		return res;
	}
	i2cdev_initialized ++;
	return 0;
}

int i2cdev_cleanup(void)
{
	int res;

	if (i2cdev_initialized >= 2) {
		if ((res = i2c_del_driver(&i2cdev_driver))) {
			printk("i2c-dev.o: Driver deregistration failed, "
			       "module not removed.\n");
			return res;
		}
	i2cdev_initialized --;
	}

	if (i2cdev_initialized >= 1) {
#ifdef CONFIG_DEVFS_FS
		devfs_unregister(devfs_handle);
		if ((res = devfs_unregister_chrdev(I2C_MAJOR, "i2c"))) {
#else
		if ((res = unregister_chrdev(I2C_MAJOR,"i2c"))) {
#endif
			printk("i2c-dev.o: unable to release major %d for i2c bus\n",
			       I2C_MAJOR);
			return res;
		}
		i2cdev_initialized --;
	}
	return 0;
}

EXPORT_NO_SYMBOLS;

#ifdef MODULE

MODULE_AUTHOR("Frodo Looijaard <*****@*****.**> and Simon G. Vogl <*****@*****.**>");
MODULE_DESCRIPTION("I2C /dev entries driver");
MODULE_LICENSE("GPL");

int init_module(void)
{
	return i2c_dev_init();
}

int cleanup_module(void)
{
	return i2cdev_cleanup();
}
Exemple #5
0
int app_i2c_init(void)
{
    return i2c_dev_init(AioI2C);
}