本文整理汇总了C++中rt_device_find函数的典型用法代码示例。如果您正苦于以下问题:C++ rt_device_find函数的具体用法?C++ rt_device_find怎么用?C++ rt_device_find使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rt_device_find函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: can_bus_hook
//.........这里部分代码省略.........
#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;
}
示例2: clock_settime
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;
}
示例3: save_handler
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);
}
}
示例4: led_thread_entry
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 );
}
}
示例5: rt_init_thread_entry
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 */
}
示例6: time
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;
}
示例7: finsh_set_device
/**
* @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);
}
}
示例8: ads7843_init
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;
}
示例9: log_trace_set_device
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;
}
示例10: wav
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);
}
}
示例11: rt_hw_lcd_init
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;
}
示例12: uip_sys_init
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;
}
示例13: rt_init_thread_entry
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
}
示例14: adc_thread_entry
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);
}
}
示例15: uart_thread_entry
//串口接收数据线程
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);
}
}
}
}