MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rtgui_touch_hw_init

Function rtgui_touch_hw_init

bsp/loongson/ls1cdev/drivers/touch.c:533–596  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

531
532
533rt_err_t rtgui_touch_hw_init(const char * spi_device_name)
534{
535 rt_uint32_t arg[2];
536 struct rt_device * spi_device;
537 struct rt_thread * touch_thread;
538 rt_err_t err;
539
540 rt_kprintf("spi1 cs0 start...\n");
541 spi_device = rt_device_find("spi10");
542 if(spi_device == RT_NULL)
543 {
544 rt_kprintf("Did not find spi1, exit thread....\n");
545 return;
546 }
547 err = rt_device_open(spi_device, RT_DEVICE_OFLAG_RDWR);
548 if(err != RT_EOK)
549 {
550 rt_kprintf("Open spi1 failed %08X, exit thread....\n", err);
551 return;
552 }
553
554 /* config spi */
555 {
556 struct rt_spi_configuration cfg;
557 cfg.data_width = 8;
558 cfg.mode = RT_SPI_MODE_0;
559 cfg.max_hz = 200 * 1000; /* 200K */
560 rt_spi_configure((struct rt_spi_device *)spi_device, &cfg);
561 }
562
563 touch = (struct rtgui_touch_device*)rt_malloc (sizeof(struct rtgui_touch_device));
564 if (touch == RT_NULL) return -RT_ENOMEM; /* no memory yet */
565
566 /* clear device structure */
567 rt_memset(&(touch->parent), 0, sizeof(struct rt_device));
568
569 rt_event_init(&touch->event, "touch", RT_IPC_FLAG_FIFO);
570
571 touch->spi_device = (struct rt_spi_device *)spi_device;
572 touch->calibrating = false;
573
574 touch->min_x = MIN_X_DEFAULT;
575 touch->max_x = MAX_X_DEFAULT;
576 touch->min_y = MIN_Y_DEFAULT;
577 touch->max_y = MAX_Y_DEFAULT;
578
579 /* init device structure */
580 touch->parent.type = RT_Device_Class_Miscellaneous;
581 touch->parent.init = rtgui_touch_init;
582 touch->parent.control = rtgui_touch_control;
583 touch->parent.user_data = RT_NULL;
584
585 /* register touch device to RT-Thread */
586 rt_device_register(&(touch->parent), "touch", RT_DEVICE_FLAG_RDWR);
587
588
589 touch_thread = rt_thread_create("touch_thread",
590 touch_thread_entry, RT_NULL,

Callers

nothing calls this directly

Calls 11

rt_kprintfFunction · 0.85
rt_device_findFunction · 0.85
rt_device_openFunction · 0.85
rt_spi_configureFunction · 0.85
rt_mallocFunction · 0.85
rt_memsetFunction · 0.85
rt_event_initFunction · 0.85
rt_device_registerFunction · 0.85
rt_thread_createFunction · 0.85
rt_thread_startupFunction · 0.85
rt_device_initFunction · 0.85

Tested by

no test coverage detected