/* * File : canapp.c * This file is part of RT-Thread RTOS * COPYRIGHT (C) 2006, RT-Thread Development Team * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at * http://www.rt-thread.org/license/LICENSE * * Change Logs: * Date Author Notes * 2015-05-14 [email protected] first version */ #include <board.h> #include <rtthread.h> #include <rtdevice.h> #include "gpio.h" #ifdef RT_USING_CAN #define CANRT1 8 #define CANERR1 9 #define CANRT2 37 #define CANERR2 38 static struct canledtype { struct stm32_hw_pin_userdata rtd; struct stm32_hw_pin_userdata err; } canled[] = { #ifdef USING_BXCAN1 { {CANRT1, PIN_MODE_OUTPUT,}, {CANERR1, PIN_MODE_OUTPUT,}, }, #endif /*USING_BXCAN1*/ #ifdef USING_BXCAN2 { {CANRT2, PIN_MODE_OUTPUT_OD,}, {CANERR2, PIN_MODE_OUTPUT_OD,}, }, #endif /*USING_BXCAN2*/ }; void can_bus_hook(struct rt_can_device *can, struct canledtype *led) { if (can->timerinitflag == 1) { rt_pin_write(led->rtd.pin, 0); } else { if (can->status.rcvchange == 1 || can->status.sndchange == 1) { can->status.rcvchange = 0; can->status.sndchange = 0; rt_pin_write(led->rtd.pin, rt_pin_read(led->rtd.pin) ? 0 : 1); } else { rt_pin_write(led->rtd.pin, 1); } } if (can->timerinitflag == 1) { rt_pin_write(led->err.pin, 0); } else { if (can->status.errcode) { rt_pin_write(led->err.pin, 0); } else { rt_pin_write(led->err.pin, 1); } } } #ifdef USING_BXCAN1 void can1_bus_hook(struct rt_can_device *can) { static rt_int32_t inited = 0; if (!inited) { inited = 1; rt_pin_mode(canled[0].rtd.pin, canled[0].rtd.mode); rt_pin_mode(canled[0].err.pin, canled[0].err.mode); } can_bus_hook(can, &canled[0]); } #endif /*USING_BXCAN1*/ #ifdef USING_BXCAN2 void can2_bus_hook(struct rt_can_device *can) { static rt_int32_t inited = 0; if (!inited) { inited = 1; rt_pin_mode(canled[1].rtd.pin, canled[1].rtd.mode); rt_pin_mode(canled[1].err.pin, canled[1].err.mode); } can_bus_hook(can, &canled[1]); } #endif /*USING_BXCAN2*/ int can_bus_hook_init(void) { rt_device_t candev; #ifdef USING_BXCAN1 candev = rt_device_find("bxcan1"); RT_ASSERT(candev); rt_device_control(candev, RT_CAN_CMD_SET_BUS_HOOK, (void *)can1_bus_hook); #endif /*USING_BXCAN1*/ #ifdef USING_BXCAN2 candev = rt_device_find("bxcan2"); RT_ASSERT(candev); rt_device_control(candev, RT_CAN_CMD_SET_BUS_HOOK, (void *)can2_bus_hook); #endif /*USING_BXCAN2*/ return RT_EOK; }
int clock_settime (clockid_t clockid, const struct timespec *tp) { int second; rt_tick_t tick; rt_device_t device; if ((clockid != CLOCK_REALTIME) || (tp == RT_NULL)) { rt_set_errno(EINVAL); return -1; } /* get second */ second = tp->tv_sec; /* get tick */ tick = rt_tick_get(); /* update timevalue */ _timevalue.tv_usec = MICROSECOND_PER_SECOND - (tick % RT_TICK_PER_SECOND) * MICROSECOND_PER_TICK; _timevalue.tv_sec = second - tick/RT_TICK_PER_SECOND - 1; /* update for RTC device */ device = rt_device_find("rtc"); if (device != RT_NULL) { /* set realtime seconds */ rt_device_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &second); } else return -1; return 0; }
static void save_handler(struct rtgui_widget* widget, rtgui_event_t* event) { extern void brightness_set(unsigned int value); rt_uint32_t vol, bri; vol = rtgui_slider_get_value(slider_volume); bri = rtgui_slider_get_value(slider_brightness); //更新背光 brightness_set(bri); //更新音量 { rt_device_t dev = RT_NULL; dev = rt_device_find("snd"); dev->control(dev, CODEC_CMD_VOLUME, &vol); } //保存配置 radio_setup.default_volume = vol; radio_setup.lcd_brightness = bri; save_setup(); //保存完毕,销毁本界面 { rtgui_view_t* view; rtgui_workbench_t* workbench; /* remove view in workbench */ view = RTGUI_VIEW(widget->parent); workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(view)->parent); rtgui_workbench_remove_view(workbench, view); rtgui_view_destroy(view); } }
static void led_thread_entry(void* parameter) { unsigned int count=0; rt_device_t led_dev=rt_device_find("led"); rt_uint8_t led_value=0; while (1) { /* led1 on */ #ifndef RT_USING_FINSH rt_kprintf("led on, count : %d\r\n",count); #endif count++; led_value=1; led_dev->write(led_dev,count%4,&led_value,1); rt_thread_delay( RT_TICK_PER_SECOND/2 ); /* sleep 0.5 second and switch to other thread */ /* led1 off */ #ifndef RT_USING_FINSH rt_kprintf("led off\r\n"); #endif led_value=0; led_dev->write(led_dev,count%4,&led_value,1); rt_thread_delay( RT_TICK_PER_SECOND/2 ); } }
void rt_init_thread_entry(void *parameter) { #ifdef RT_USING_COMPONENTS_INIT /* initialization RT-Thread Components */ rt_components_init(); #endif rt_platform_init(); /* Filesystem Initialization */ #ifdef RT_USING_DFS /* mount sd card fat partition 1 as root directory */ if (dfs_mount("sd0", "/", "elm", 0, 0) == 0) { rt_kprintf("File System initialized!\n"); } else rt_kprintf("File System initialzation failed!\n"); #endif #ifdef RT_USING_RTGUI gui_init(); picture_show(); /* initial touch. */ { rt_device_t device; device = rt_device_find("touch"); if (device != RT_NULL) { rt_device_init(device); } } #endif /* RT_USING_RTGUI */ }
time_t time(time_t* t) #endif { static rt_device_t device = RT_NULL; time_t time_now = 0; /* optimization: find rtc device only first. */ if (device == RT_NULL) { device = rt_device_find("rtc"); } /* read timestamp from RTC device. */ if (device != RT_NULL) { rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time_now); } /* if t is not NULL, write timestamp to *t */ if (t != RT_NULL) { *t = time_now; } return time_now; }
/** * @ingroup finsh * * This function sets the input device of finsh shell. * * @param device_name the name of new input device. */ void finsh_set_device(const char *device_name) { rt_device_t dev = RT_NULL; RT_ASSERT(shell != RT_NULL); dev = rt_device_find(device_name); if (dev == RT_NULL) { rt_kprintf("finsh: can not find device: %s\n", device_name); return; } /* check whether it's a same device */ if (dev == shell->device) return; /* open this device and set the new device in finsh shell */ if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX | \ RT_DEVICE_FLAG_STREAM) == RT_EOK) { if (shell->device != RT_NULL) { /* close old finsh device */ rt_device_close(shell->device); rt_device_set_rx_indicate(shell->device, RT_NULL); } /* clear line buffer before switch to new device */ memset(shell->line, 0, sizeof(shell->line)); shell->line_curpos = shell->line_position = 0; shell->device = dev; rt_device_set_rx_indicate(dev, finsh_rx_ind); } }
rt_err_t ads7843_init(const char * name, const char * spi_device_name) { rt_spi_device = (struct rt_spi_device *)rt_device_find(spi_device_name); if(rt_spi_device == RT_NULL) { rt_kprintf("spi device %s not found!\r\n", spi_device_name); return -RT_ENOSYS; } /* config spi */ { struct rt_spi_configuration cfg; cfg.data_width = 8; cfg.mode = RT_SPI_MODE_0 | RT_SPI_MSB; /* SPI Compatible: Mode 0 and Mode 3 */ cfg.max_hz = 2 * 1000 * 1000; rt_spi_configure(rt_spi_device, &cfg); } /* register device */ ads7843_device.type = RT_Device_Class_Block; ads7843_device.init = RT_NULL; ads7843_device.open = RT_NULL; ads7843_device.close = RT_NULL; ads7843_device.read = ads7843_read; ads7843_device.write = RT_NULL; ads7843_device.control = RT_NULL; /* no private */ ads7843_device.user_data = RT_NULL; rt_device_register(&ads7843_device, name, RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE); return RT_EOK; }
rt_err_t log_trace_set_device(const char *device_name) { struct rt_device *output_device; /* find out output device */ output_device = rt_device_find(device_name); if (output_device != RT_NULL) { rt_err_t result; /* open device */ result = rt_device_open(output_device, RT_DEVICE_FLAG_STREAM | RT_DEVICE_FLAG_RDWR); if (result != RT_EOK) { rt_kprintf("Open trace device failed.\n"); return -RT_ERROR; } } /* set trace out device */ if (_traceout_device != RT_NULL) rt_device_close(_traceout_device); _traceout_device = output_device; return RT_EOK; }
void wav(const char* filename) { int fd; rt_size_t block_size; block_size = sbuf_get_size(); block_size = (block_size / 512) * 512; fd = open(filename, O_RDONLY, 0); if (fd >= 0) { rt_uint8_t* buf; rt_size_t len; rt_device_t device; /* open audio device and set tx done call back */ device = rt_device_find("snd"); rt_device_set_tx_complete(device, wav_tx_done); rt_device_open(device, RT_DEVICE_OFLAG_WRONLY); do { buf = sbuf_alloc(); len = read(fd, (char*)buf, block_size); if (len > 0) rt_device_write(device, 0, buf, len); else sbuf_release(buf); } while (len != 0); /* close device and file */ rt_device_close(device); close(fd); } }
int rt_hw_lcd_init(const char *name) { struct lcd_device *dev; if(rt_device_find(name)) { return -RT_EIO; } dev = rt_malloc(sizeof(struct lcd_device)); if(!dev) { return RT_ENOMEM; } dev->rtdev.type = RT_Device_Class_Graphic; dev->rtdev.rx_indicate = RT_NULL; dev->rtdev.init = rt_lcd_init; dev->rtdev.open = RT_NULL; dev->rtdev.close = RT_NULL; dev->rtdev.read = RT_NULL; dev->rtdev.write = RT_NULL; dev->rtdev.control = rt_lcd_control; dev->rtdev.user_data = RT_NULL; /* initialize mutex */ rt_mutex_init(&dev->lock, name, RT_IPC_FLAG_FIFO); rt_device_register(&dev->rtdev, name, RT_DEVICE_FLAG_RDWR); return RT_EOK; }
void uip_sys_init(void) { struct rt_device *eth_dev; uip_ipaddr_t ipaddr; uip_init(); httpd_init(); /*#if HELLO_WORLD hello_world_init(); #elif TELNETD telnetd_init(); #elif WEBSERVER httpd_init(); printf("httpd_init\n\n"); #elif WEBCLIENT webclient_init(); resolv_init(); uip_ipaddr(ipaddr, 202,96,128,166); //set DNS server resolv_conf(ipaddr); resolv_query("www.rt-thread.org"); #else uip_listen(HTONS(1234)); uip_ipaddr(ipaddr, 192,168,2,244); uip_connect(&ipaddr, HTONS(5678)); #endif */ eth_dev = rt_device_find("e0"); RT_ASSERT(eth_dev != RT_NULL); return; }
void rt_init_thread_entry(void *parameter) { #ifdef RT_USING_RTGUI { rt_device_t dc; /* init Display Controller */ rt_hw_dc_init(); /* re-init device driver */ rt_device_init_all(); /* find Display Controller device */ dc = rt_device_find("dc"); /* set Display Controller device as rtgui graphic driver */ rtgui_graphic_set_device(dc); } #endif #ifdef RT_USING_COMPONENTS_INIT /* initialization RT-Thread Components */ rt_components_init(); #endif }
static void adc_thread_entry(void *parameter) { rt_device_t device; #ifdef RT_USING_RTGUI struct rtgui_event_command ecmd; RTGUI_EVENT_COMMAND_INIT(&ecmd); ecmd.type = RTGUI_CMD_USER_INT; ecmd.command_id = ADC_UPDATE; #else struct lcd_msg msg; #endif device = rt_device_find("adc"); while(1) { rt_device_control(device, RT_DEVICE_CTRL_ADC_START, RT_NULL); rt_device_control(device, RT_DEVICE_CTRL_ADC_RESULT, &adc_value); pwm_update(adc_value/3); #ifdef RT_USING_RTGUI rtgui_thread_send(info_tid, &ecmd.parent, sizeof(ecmd)); #else msg.type = ADC_MSG; msg.adc_value = adc_value; rt_mq_send(&mq, &msg, sizeof(msg)); #endif rt_thread_delay(20); } }
//串口接收数据线程 void uart_thread_entry(void* parameter) { char ch; device = rt_device_find("uart3"); if(device != RT_NULL) { rt_device_open(device, RT_DEVICE_OFLAG_RDWR); rt_kprintf("open device uart3 succeed!\r\n"); rt_sem_init(&rx_sem, "uartrx", 0, 0); rt_device_set_rx_indicate(device, uart_rx_ind); while(1) { if (rt_sem_take(&rx_sem, RT_WAITING_FOREVER) != RT_EOK) //默认情况线程挂起,有数据时,系统会调用uart_rx_ind函数,释放信号量,线程得以执行 continue; while(rt_device_read(device, 0, &ch, 1) == 1) { uartRecvProc(ch); } } } }
rt_err_t rt_spi_bus_attach_device(struct rt_spi_device *device, const char *name, const char *bus_name, void *user_data) { rt_err_t result; rt_device_t bus; /* get physical spi bus */ bus = rt_device_find(bus_name); if (bus != RT_NULL && bus->type == RT_Device_Class_SPIBUS) { device->bus = (struct rt_spi_bus *)bus; /* initialize spidev device */ result = rt_spidev_device_init(device, name); if (result != RT_EOK) return result; rt_memset(&device->config, 0, sizeof(device->config)); device->parent.user_data = user_data; return RT_EOK; } /* not found the host bus */ return -RT_ERROR; }
void uart1_rs485_set_device(void) { rt_device_t dev = RT_NULL; dev = rt_device_find("uart2"); if (dev == RT_NULL) { rt_kprintf("finsh: can not find device: %s\n", "uart1"); return; } /* check whether it's a same device */ if (dev == uart1_dev_my->device) return; if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX |\ RT_DEVICE_FLAG_STREAM) == RT_EOK) { if (uart1_dev_my->device != RT_NULL) { /* close old finsh device */ rt_device_close(uart1_dev_my->device); rt_device_set_rx_indicate(uart1_dev_my->device, RT_NULL); } uart1_dev_my->device = dev; rt_device_set_rx_indicate(dev, rs485_rx_ind); } }
u8 Device_RTC_set(TDateTime now) { rt_device_t device; RTC_DateStructure.RTC_Year = now.year; RTC_DateStructure.RTC_Month =now.month; RTC_DateStructure.RTC_Date = now.day; RTC_DateStructure.RTC_WeekDay=now.week; RTC_TimeStructure.RTC_Hours = now.hour; RTC_TimeStructure.RTC_Minutes = now.min; RTC_TimeStructure.RTC_Seconds = now.sec; device = rt_device_find("rtc"); if (device != RT_NULL) { rt_rtc_control(device, RT_DEVICE_CTRL_RTC_SET_DATE, &RTC_DateStructure); rt_rtc_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &RTC_TimeStructure); return 1; } return 0; }
void SetCurrentDateTime(CLOCK *clock) { time_t now; struct tm* ti; rt_device_t device; ti = RT_NULL; /* get current time */ time(&now); ti = localtime(&now); if (ti != RT_NULL) { ti->tm_year = BCD2Char(clock->year) +100; ti->tm_mon = BCD2Char(clock->month )- 1; /* ti->tm_mon = month; 0~11 */ ti->tm_mday = BCD2Char(clock->day); ti->tm_hour = BCD2Char(clock->hour); ti->tm_min = BCD2Char(clock->minute); ti->tm_sec = BCD2Char(clock->second); } now = mktime(ti); device = rt_device_find("rtc"); if (device != RT_NULL) { rt_rtc_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &now); } }
rt_err_t rt_hw_nRF24L01_init(const char * spi_device_name){ RF24L01_IO_Init(); rt_spi_device = (struct rt_spi_device *)rt_device_find(spi_device_name); if(rt_spi_device == RT_NULL) { FLASH_TRACE("spi device %s not found!\r\n", spi_device_name); return -RT_ENOSYS; } /* config spi */ { struct rt_spi_configuration cfg; cfg.data_width = 8; cfg.mode = RT_SPI_MODE_0 | RT_SPI_MSB; /* SPI Compatible: Mode 0 and Mode 3 */ cfg.max_hz = 9 * 1000 * 1000; /* 9M */ //cfg.max_hz = 50 * 1000 * 1000; /* 9M */ rt_spi_configure(rt_spi_device, &cfg); } // SPI_RF24L01_RW(0x5a); if(RF24L01_Check() == RT_EOK) { //这里直接启一个线程来处理相关数据。 rt_kprintf("nRF24L01 is connected !\n"); return RT_EOK; } else { rt_kprintf("nRF24L01 is not connected !\n"); return RT_ERROR ; //MCU与void RF24L01_Init(void)不正常连接 } }
void set_time(rt_uint32_t hour, rt_uint32_t minute, rt_uint32_t second) { time_t now; struct tm* ti; rt_device_t device; ti = RT_NULL; /* get current time */ time(&now); ti = localtime(&now); if (ti != RT_NULL) { ti->tm_hour = hour; ti->tm_min = minute; ti->tm_sec = second; } now = mktime(ti); device = rt_device_find("rtc"); if (device != RT_NULL) { rt_rtc_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &now); } }
void set_date(rt_uint32_t year, rt_uint32_t month, rt_uint32_t day) { time_t now; struct tm* ti; rt_device_t device; ti = RT_NULL; /* get current time */ time(&now); ti = localtime(&now); if (ti != RT_NULL) { ti->tm_year = year - 1900; ti->tm_mon = month - 1; /* ti->tm_mon = month; 0~11 */ ti->tm_mday = day; } now = mktime(ti); device = rt_device_find("rtc"); if (device != RT_NULL) { rt_rtc_control(device, RT_DEVICE_CTRL_RTC_SET_TIME, &now); } }
void calibration_init(void) { rt_thread_t tid; struct setup_items setup; if(setup_load(&setup) == RT_EOK) { struct calibration_data data; rt_device_t device; data.min_x = setup.touch_min_x; data.max_x = setup.touch_max_x; data.min_y = setup.touch_min_y; data.max_y = setup.touch_max_y; device = rt_device_find("touch"); if(device != RT_NULL) rt_device_control(device, RT_TOUCH_CALIBRATION_DATA, &data); return; } tid = rt_thread_create("cali", calibration_entry, RT_NULL, 1024, 20, 20); if (tid != RT_NULL) rt_thread_startup(tid); }
/** * @ingroup finsh * * This function sets the input device of finsh shell. * * @param device_name the name of new input device. */ void finsh_set_device(const char* device_name) { rt_device_t dev = RT_NULL; RT_ASSERT(shell != RT_NULL); dev = rt_device_find(device_name); if (dev == RT_NULL) { rt_kprintf("finsh: can not find device: %s\n", device_name); return; } /* check whether it's a same device */ if (dev == shell->device) return; /* open this device and set the new device in finsh shell */ if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR) == RT_EOK) { if (shell->device != RT_NULL) { /* close old finsh device */ rt_device_close(shell->device); rt_device_set_rx_indicate(dev, RT_NULL); } shell->device = dev; rt_device_set_rx_indicate(dev, finsh_rx_ind); } }
void rt_can_thread_entry(void *parameter) { struct rt_can_msg msg; struct can_app_struct *canpara = (struct can_app_struct *) parameter; rt_device_t candev; rt_uint32_t e; candev = rt_device_find(canpara->name); RT_ASSERT(candev); rt_event_init(&canpara->event, canpara->name, RT_IPC_FLAG_FIFO); rt_device_open(candev, (RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_INT_TX)); rt_device_control(candev, RT_CAN_CMD_SET_FILTER, canpara->filter); while (1) { if ( rt_event_recv(&canpara->event, ((1 << canpara->filter->items[0].hdr) | (1 << canpara->filter->items[1].hdr) | (1 << canpara->filter->items[2].hdr) | (1 << canpara->filter->items[3].hdr)), canpara->eventopt, RT_WAITING_FOREVER, &e) != RT_EOK ) { continue; } if (e & (1 << canpara->filter->items[0].hdr)) { msg.hdr = canpara->filter->items[0].hdr; while (rt_device_read(candev, 0, &msg, sizeof(msg)) == sizeof(msg)) { rt_device_write(candev, 0, &msg, sizeof(msg)); } } if (e & (1 << canpara->filter->items[1].hdr)) { msg.hdr = canpara->filter->items[1].hdr; while (rt_device_read(candev, 0, &msg, sizeof(msg)) == sizeof(msg)) { rt_device_write(candev, 0, &msg, sizeof(msg)); } } if (e & (1 << canpara->filter->items[2].hdr)) { msg.hdr = canpara->filter->items[2].hdr; while (rt_device_read(candev, 0, &msg, sizeof(msg)) == sizeof(msg)) { rt_device_write(candev, 0, &msg, sizeof(msg)); } } if (e & (1 << canpara->filter->items[3].hdr)) { msg.hdr = canpara->filter->items[3].hdr; while (rt_device_read(candev, 0, &msg, sizeof(msg)) == sizeof(msg)) { rt_device_write(candev, 0, &msg, sizeof(msg)); } } } }
void rcu_uart_set_device(char* uartStr) { static int isInited=0; rt_device_t dev = RT_NULL; if(isInited==1) return; dev = rt_device_find(uartStr); if (dev == RT_NULL) { hclog("finsh: can not find device: %s\n", uartStr); return; } if(dev == rcuDevice) return; /* open this device and set the new device */ if (rt_device_open(dev, RT_DEVICE_OFLAG_RDWR) == RT_EOK) { if (rcuDevice != RT_NULL) { /* close old device */ rt_device_close(rcuDevice); rt_device_set_rx_indicate(dev, RT_NULL); } rcuDevice = dev; rt_device_set_rx_indicate(dev, rcu_rx_ind); } isInited = 1; }
/** * This function will initialize the usb host stack, all the usb class driver and * host controller driver are also be initialized here. * * @return none. */ rt_err_t rt_usb_host_init(void) { ucd_t drv; rt_device_t uhc; #ifdef RT_USBH_HID uprotocal_t protocal; #endif uhc = rt_device_find(USB_HOST_CONTROLLER_NAME); if(uhc == RT_NULL) { rt_kprintf("can't find usb host controller %s\n", USB_HOST_CONTROLLER_NAME); return -RT_ERROR; } /* initialize usb hub */ rt_usbh_hub_init(); /* initialize class driver */ rt_usbh_class_driver_init(); #ifdef RT_USBH_MSTORAGE /* register mass storage class driver */ drv = rt_usbh_class_driver_storage(); rt_usbh_class_driver_register(drv); #endif #ifdef RT_USBH_HID /* register hid class driver */ drv = rt_usbh_class_driver_hid(); rt_usbh_class_driver_register(drv); #ifdef RT_USBH_HID_KEYBOARD /* register hid keyboard protocal */ protocal = rt_usbh_hid_protocal_kbd(); rt_usbh_hid_protocal_register(protocal); #endif #ifdef RT_USBH_HID_MOUSE /* register hid mouse protocal */ protocal = rt_usbh_hid_protocal_mouse(); rt_usbh_hid_protocal_register(protocal); #endif #endif #ifdef RT_USBH_ADK /* register adk class driver */ drv = rt_usbh_class_driver_adk(); rt_usbh_class_driver_register(drv); #endif /* register hub class driver */ drv = rt_usbh_class_driver_hub(); rt_usbh_class_driver_register(drv); /* initialize usb host controller */ rt_device_init(uhc); return RT_EOK; }
void calibration_entry(void* parameter) { rt_device_t device; struct rtgui_rect rect; struct setup_items setup; device = rt_device_find("touch"); if (device == RT_NULL) return; /* no this device */ calibration_ptr = (struct calibration_session*) rt_malloc(sizeof(struct calibration_session)); rt_memset(calibration_ptr, 0, sizeof(struct calibration_data)); calibration_ptr->device = device; rt_device_control(calibration_ptr->device, RT_TOUCH_CALIBRATION, (void*)calibration_data_post); rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &rect); /* set screen rect */ calibration_ptr->width = rect.x2; calibration_ptr->height = rect.y2; calibration_ptr->app = rtgui_app_create("calibration"); if (calibration_ptr->app != RT_NULL) { /* create calibration window */ calibration_ptr->win = rtgui_win_create(RT_NULL, "calibration", &rect, RTGUI_WIN_STYLE_NO_TITLE | RTGUI_WIN_STYLE_NO_BORDER | RTGUI_WIN_STYLE_ONTOP | RTGUI_WIN_STYLE_DESTROY_ON_CLOSE); if (calibration_ptr->win != RT_NULL) { rtgui_object_set_event_handler(RTGUI_OBJECT(calibration_ptr->win), calibration_event_handler); rtgui_win_show(calibration_ptr->win, RT_TRUE); } rtgui_app_destroy(calibration_ptr->app); } /* set calibration data */ rt_device_control(calibration_ptr->device, RT_TOUCH_CALIBRATION_DATA, &calibration_ptr->data); //save setup setup.touch_min_x = calibration_ptr->data.min_x; setup.touch_max_x = calibration_ptr->data.max_x; setup.touch_min_y = calibration_ptr->data.min_y; setup.touch_max_y = calibration_ptr->data.max_y; setup_save(&setup); /* recover to normal */ rt_device_control(calibration_ptr->device, RT_TOUCH_NORMAL, RT_NULL); /* release memory */ rt_free(calibration_ptr); calibration_ptr = RT_NULL; }
void control_init(void) { dev_pwm_init(); s_dev_pwm = rt_device_find("pwm"); RT_ASSERT(s_dev_pwm != RT_NULL); rt_device_open(s_dev_pwm, RT_DEVICE_OFLAG_WRONLY); }
void spi_m74hc595_Poll(void) { rt_size_t length = 3; //static char spi_MOSI_buf[3]; rt_device_t spi_device; spi_device = rt_device_find("SPI1"); rt_device_write(spi_device, 0, spi_MOSI_buf, length); }