/* * 如果已缓存, 则更新;否则,当有空闲空间时,插入新数据;其他情况返回失败 * */ int si_update_wl_collect_data(char *sn, union sinkinfo_ptc_ctc_st *data, rt_tick_t time_stamp) { struct sinkinfo_wl_data_item_st *p; rt_err_t ret; if (NULL==sn || NULL==data) { printf_syn("func:%s(), param is NULL\n", __FUNCTION__); return FAIL; } if (NULL == sink_wl_collect_data) { printf_syn("func:%s(), sink_wl_collect_data is NULL\n", __FUNCTION__); return FAIL; } ret = rt_sem_take(&sink_wl_data_sem, RT_WAITING_FOREVER); if (RT_EOK != ret) { printf_syn("take sink_wl_data_sem fail(%d)\n", ret); return SIE_FAIL; } sinki_debug_data(("func:%s(), line:%d, sn:%s\n", __FUNCTION__, __LINE__, sn)); p = si_lookup_item_in_wl_data(sn); if (NULL != p) { #if 0 enum sink_data_dev_type_e dev_type; dev_type = si_get_dev_type(sn); if (SDDT_PT == dev_type) { rt_memcpy(&p->item.ptc_data, &data->ptc_data, sizeof(p->item.ptc_data)); } else if (SDDT_PT == dev_type) { rt_memcpy(&p->item.ctc_data, &data->ctc_data, sizeof(p->item.ctc_data)); } else { /* mark by David */ } #else rt_memcpy(&p->item, data, sizeof(p->item)); #endif p->time_stamp = time_stamp; } else { si_insert_item_to_wl_data(sn, data, time_stamp); } rt_sem_release(&sink_wl_data_sem); return SUCC; }
static rt_err_t rt_tetris_update_brick(rt_tetris_t* thiz) { int index; RT_ASSERT(thiz != RT_NULL); index = (int)(7.0 * rand()/(RAND_MAX + 1.0)); rt_memcpy(thiz->brick, thiz->next_brick, 4 * sizeof(rt_uint32_t)); rt_memcpy(thiz->next_brick, g_brick[index], 4 * sizeof(rt_uint32_t)); /* update next brick on view */ thiz->view->update_next_brick(thiz->view, thiz); return RT_EOK; }
/* draw raw hline */ static void framebuffer_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y) { rt_uint8_t *dst; dst = GET_PIXEL(rtgui_graphic_get_device(), x1, y, rt_uint8_t); rt_memcpy(dst, pixels, (x2 - x1) * (rtgui_graphic_get_device()->bits_per_pixel/8)); }
rt_err_t rt_mq_recv (rt_mq_t *mq, void* buffer, rt_size_t size) { rt_err_t r; struct rt_mq_message *msg; /* mq is empty */ if (mq->entry == 0) { return -RT_ETIMEOUT; } /* get message from queue */ msg = (struct rt_mq_message*) mq->head; /* move message queue head */ mq->head = msg->next; /* reach queue tail, set to NULL */ if (mq->tail == msg) mq->tail = RT_NULL; /* decrease message entry */ mq->entry --; /* copy message */ rt_memcpy(buffer, msg + 1, size > mq->msg_size ? (mq->msg_size) : size); /* put message to free list */ msg->next = (struct rt_mq_message*)mq->free; mq->free = msg; return RT_EOK; }
/***************************************************************************//** * @brief * Configure OLED device * * @details * * @note * * @param[in] dev * Pointer to device descriptor * * @param[in] cmd * IIC control command * * @param[in] args * Arguments * * @return * Error code ******************************************************************************/ static rt_err_t miniStm32_oled_control(rt_device_t dev, int cmd, void *args) { switch (cmd) { case RTGRAPHIC_CTRL_RECT_UPDATE: // miniStm32_oled_update((struct rt_device_rect_info *)args); oled_debug("OLED: update\n"); break; case RTGRAPHIC_CTRL_POWERON: break; case RTGRAPHIC_CTRL_POWEROFF: break; case RTGRAPHIC_CTRL_GET_INFO: { struct rt_device_graphic_info oled_info = { RTGRAPHIC_PIXEL_FORMAT_MONO, // pixel_format 1, // bits_per_pixel 0, // reserved MINISTM32_OLED_WIDTH, // width MINISTM32_OLED_HEIGHT, // height RT_NULL // framebuffer }; rt_memcpy(args, &oled_info, sizeof(oled_info)); break; } case RTGRAPHIC_CTRL_SET_MODE: break; } return RT_EOK; }
/* transmit packet. */ rt_err_t rt_stm32_eth_tx( rt_device_t dev, struct pbuf* p) { rt_err_t ret; struct pbuf *q; uint32_t l = 0; u8 *buffer ; if (( ret = rt_sem_take(&tx_wait, netifGUARD_BLOCK_TIME) ) == RT_EOK) { buffer = (u8 *)(DMATxDescToSet->Buffer1Addr); for(q = p; q != NULL; q = q->next) { //show_frame(q); rt_memcpy((u8_t*)&buffer[l], q->payload, q->len); l = l + q->len; } if( ETH_Prepare_Transmit_Descriptors(l) == ETH_ERROR ) rt_kprintf("Tx Error\n"); //rt_sem_release(xTxSemaphore); rt_sem_release(&tx_wait); //rt_kprintf("Tx packet, len = %d\n", l); } else { rt_kprintf("Tx Timeout\n"); return ret; } /* Return SUCCESS */ return RT_EOK; }
struct rtgui_dc *rtgui_dc_buffer_create_from_dc(struct rtgui_dc* dc) { struct rtgui_dc_buffer *buffer; if (dc == RT_NULL) return RT_NULL; if (dc->type == RTGUI_DC_BUFFER) { struct rtgui_dc_buffer *d = (struct rtgui_dc_buffer*) dc; /* buffer clone */ buffer = (struct rtgui_dc_buffer*)rtgui_dc_buffer_create_pixformat(d->pixel_format, d->width, d->height); if (buffer != RT_NULL) { rt_memcpy(buffer->pixel, d->pixel, d->pitch * d->height); return RTGUI_DC(buffer); } } return RT_NULL; }
rt_err_t rtgui_recv_filter(rt_uint32_t type, rtgui_event_t *event, rt_size_t event_size) { rtgui_event_t *e; struct rtgui_app *app; RT_ASSERT(event != RT_NULL); RT_ASSERT(event_size != 0); app = (struct rtgui_app *)(rt_thread_self()->user_data); if (app == RT_NULL) return -RT_ERROR; e = (rtgui_event_t*)&app->event_buffer[0]; while (rt_mq_recv(app->mq, e, sizeof(union rtgui_event_generic), RT_WAITING_FOREVER) == RT_EOK) { if (e->type == type) { rt_memcpy(event, e, event_size); return RT_EOK; } else { if (RTGUI_OBJECT(app)->event_handler != RT_NULL) { RTGUI_OBJECT(app)->event_handler(RTGUI_OBJECT(app), e); } } } return -RT_ERROR; }
/* * 将新数据插入到下标最小的空位置 * */ static int si_insert_item_to_wl_data(char *sn, union sinkinfo_ptc_ctc_st *data, rt_tick_t time_stamp) { int i; struct sinkinfo_wl_data_item_st *p; /* 查找是否已存储到缓冲区 */ p = sink_wl_collect_data; for (i=0; i<SINKINFO_WL_DATA_ITEM_MAX_NO; ++i) { if ('\0' == p->pt_ct_sn[0]) break; ++p; } if (i < SINKINFO_WL_DATA_ITEM_MAX_NO) { rt_strncpy(p->pt_ct_sn, sn, sizeof(p->pt_ct_sn)); rt_memcpy(&p->item, data, sizeof(p->item)); p->time_stamp = time_stamp; sinki_debug_data(("func:%s(), inser data sn:%s\n", __FUNCTION__, sn)); } else { printf_syn("func:%s(), wl-data-buffer is full\n", __FUNCTION__); return FAIL; } return SUCC; }
/** * @brief This function tells firmware to send a NULL data packet. * * @param priv A pointer to wlan_private structure * @param flags Trasnit Pkt Flags * @return n/a */ int SendNullPacket(WlanCard *cardinfo, struct pbuf *packet, u8 flags) { WlanCard *card = cardinfo; TxPD txpd; int ret = WLAN_STATUS_SUCCESS; u8 *ptr = card->TmpTxBuf; if (card->MediaConnectStatus == WlanMediaStateDisconnected) { ret = WLAN_STATUS_FAILURE; WlanDebug(WlanErr,"NULL packet wlan did not connect\r\n"); goto done; } rt_memset(&txpd, 0, sizeof(TxPD)); txpd.TxControl = card->PktTxCtrl; txpd.Flags = flags; txpd.Priority = WMM_HIGHEST_PRIORITY; txpd.TxPacketLocation = sizeof(TxPD); rt_memcpy(ptr, &txpd, sizeof(TxPD)); ret = sbi_host_to_card(card, MVMS_DAT, card->TmpTxBuf, sizeof(TxPD)); if (ret != 0) { WlanDebug(WlanErr,"TX Error: SendNullPacket failed!\n"); goto done; } WlanDebug(WlanMsg,"Null data => FW\n"); done: return ret; }
int wlan_get_Mac_Address(WlanCard *cardinfo) { WlanCard *card = cardinfo; HostCmd_DS_COMMAND *CmdPtr = NULL; HostCmd_DS_GET_HW_SPEC *hwspec; int ret = WLAN_STATUS_SUCCESS; rt_memset(card->MyMacAddress, 0xff, MRVDRV_ETH_ADDR_LEN); CmdPtr = rt_malloc(sizeof(HostCmd_DS_COMMAND)); if (CmdPtr == NULL) { WlanDebug(WlanErr,"memory allocate failed for Get Mac\r\n"); return WLAN_STATUS_FAILURE; } /* Set sequence number, command and INT option */ card->SeqNum++; CmdPtr->SeqNum = card->SeqNum; CmdPtr->Command = HostCmd_CMD_GET_HW_SPEC; CmdPtr->Result = 0; hwspec = &CmdPtr->params.hwspec; CmdPtr->Size = sizeof(HostCmd_DS_GET_HW_SPEC) + S_DS_GEN; rt_memcpy(hwspec->PermanentAddr, card->MyMacAddress, MRVDRV_ETH_ADDR_LEN); ret = WlanExecuteCommand(cardinfo, CmdPtr); if (ret) { WlanDebug(WlanErr,"Falure for Get Mac\r\n"); ret = WLAN_STATUS_FAILURE; } rt_free(CmdPtr); return ret; }
int si_get_item_in_wl_data(char *sn, union sinkinfo_ptc_ctc_st *item, rt_tick_t *time_stamp) { rt_err_t sem_ret; struct sinkinfo_wl_data_item_st *p; int ret = SUCC; if (NULL==sn || NULL==item || NULL==time_stamp) { printf_syn("func:%s(), param is NULL\n", __FUNCTION__); return FAIL; } sem_ret = rt_sem_take(&sink_wl_data_sem, RT_WAITING_FOREVER); if (RT_EOK != sem_ret) { printf_syn("take sink_wl_data_sem fail(%d)\n", ret); return FAIL; } p = si_lookup_item_in_wl_data(sn); if (NULL == p) { ret = FAIL; } else { rt_memcpy(item, &p->item, sizeof(*item)); *time_stamp = p->time_stamp; } rt_sem_release(&sink_wl_data_sem); return ret; }
static rt_size_t rt_dram_write (rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size) { uint8_t *p; p = (uint8_t*)((uint32_t)DRAMStartAddr + pos * RAM_SECTOR_SIZE); rt_memcpy(p, buffer, size * RAM_SECTOR_SIZE); return size; }
int make_int32(char* ptr) { int ret = 0; int temp = 0;//(short)*ptr; rt_memcpy((char*)&temp,(char*)ptr,4); ret = (int)ntohl((u_int)temp); return ret; }
short make_int16(char* ptr) { short ret = 0; short temp = 0;//(short)*ptr; rt_memcpy((char*)&temp,(char*)ptr,2); ret = (short)ntohs((u_short)temp); return ret; }
int getForwardReply(int index,char* from, char* to,char* msg,int msgLen,send_data_t* sptr) { int len=0,dlen=0; char* p=NULL; //dlen = 2*MAX_NAME_LEN+strlen(fdReplyStr)+msgLen; dlen = 2*MAX_NAME_LEN+msgLen; len = 1+2+2+4+4+1+dlen; if((len>sptr->data_len) || sptr->data_ptr==NULL) { p = (char*)rt_malloc(len); if(p==NULL) { return -1; } sptr->data_ptr = p; sptr->data_len = len; rt_memset(p,0,len); } else { p = sptr->data_ptr; rt_memset(p,0,sptr->data_len); } *p = 0x02; p++; make_net16(p,0x0001); p+=2; make_net16(p,0x0004); p+=2; make_net32(p,index); p+=4; make_net32(p,dlen); p+=4; strcpy(p,to); p+=MAX_NAME_LEN; strcpy(p,from); p+=MAX_NAME_LEN; /* strcpy(p,fdReplyStr); p+=strlen(fdReplyStr); */ // strcpy(p,msg); rt_memcpy(p,msg,msgLen); p+=msgLen; *p = 0x03; return len; }
/** * This function will duplicate a string. * * @param s the string to be duplicated * * @return the duplicated string pointer */ char *rt_strdup(const char *s) { rt_size_t len = rt_strlen(s) + 1; char *tmp = (char *)rt_malloc(len); if (!tmp) return RT_NULL; rt_memcpy(tmp, s, len); return tmp; }
/* draw raw hline */ static void framebuffer_draw_raw_hline(rt_uint8_t *pixels, int x1, int x2, int y) { struct rtgui_graphic_driver *drv; rt_uint8_t *dst; drv = rtgui_graphic_get_device(); dst = GET_PIXEL(drv, x1, y, rt_uint8_t); rt_memcpy(dst, pixels, (x2 - x1) * _UI_BITBYTES(drv->bits_per_pixel)); }
void app_getGUID(void) { unsigned int inparam[4]={54,0}; unsigned int outparam[8]={0}; iap_entry = (IAP)IAP_LOCATION; iap_entry(inparam,outparam); inparam[0]=58; iap_entry(inparam,outparam); rt_memcpy(devguid,outparam+1,sizeof(devguid)); }
rt_err_t rt_mq_recv (rt_mq_t mq, void* buffer, rt_size_t size, rt_int32_t timeout) { rt_err_t r; struct rt_mq_message *msg; SDL_SemWait(hmq->mutex); /* mq is empty */ if (mq->entry == 0) { SDL_SemPost(hmq->mutex); if (timeout == RT_WAITING_FOREVER) { r = SDL_SemWait(hmq->msg); } else { r = SDL_SemWaitTimeout(hmq->msg, timeout * 10); } if (r != 0) return -RT_ERROR; SDL_SemWait(hmq->mutex); } else { /* take one message */ SDL_SemWait(hmq->msg); } /* get message from queue */ msg = (struct rt_mq_message*) mq->msg_queue_head; /* move message queue head */ mq->msg_queue_head = msg->next; /* reach queue tail, set to NULL */ if (mq->msg_queue_tail == msg) mq->msg_queue_tail = RT_NULL; /* copy message */ rt_memcpy(buffer, msg + 1, size > mq->msg_size? (unsigned short)(mq->msg_size) : (unsigned short)size); /* put message to free list */ msg->next = (struct rt_mq_message*)mq->msg_queue_free; mq->msg_queue_free = msg; /* decrease message entry */ mq->entry --; SDL_SemPost(hmq->mutex); return RT_EOK; }
/** * Calc hardware version's Integer value */ void calc_hardware_version(void) { char const *start_addr = NULL; char *match_addr = NULL; char c_value[4] = { 0 }; uint8_t c_length = 0, i = 0; start_addr = get_hardware_version(); match_addr = rt_strstr((char *) start_addr, "."); while (match_addr != NULL) { c_length = match_addr - start_addr; rt_memcpy(c_value, start_addr, c_length); hardware_version[i++] = atoi(c_value); match_addr++; start_addr = match_addr; match_addr = rt_strstr((char *) start_addr, "."); } c_length = rt_strlen(start_addr); rt_memcpy(c_value, start_addr, c_length); hardware_version[i] = atoi(c_value); }
static void rt_hw_vector_copy(void) { void *dst, *src; extern volatile rt_uint32_t Entry_Point; dst = (void*) (0xffff0000); src = (void*) (&Entry_Point); /* copy vector to 0xffff 0000 */ rt_memcpy(dst, src, 64); }
static rt_size_t rt_uart_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size) { int len; struct uart_device * uart_dev; _lock((struct uart_device *)dev); uart_dev = (struct uart_device*)dev; len = uart_dev->rx_len; rt_memcpy(buffer, uart_dev->rx_buf, len); uart_dev->rx_len = 0; _unlock((struct uart_device *)dev); return len; }
/* * 获取电压、电流波形采样数据, 每个点是4字节的有符号数据, 以网络序存储 * * 当返回值为SIE_OK时,非空指针指向的内存区域存储了返回值 */ enum sinkinfo_error_e get_sinkinfo_sample_data(int em_no, enum sinkinfo_cmd_e cmd, void *data_buf, int len) { enum sinkinfo_error_e ret = SIE_OK; if (len < SINK_INFO_PX_SAMPLE_BUF_SIZE) { printf_syn("func:%s, buf too small(%d)\n", __FUNCTION__, len); return SIE_BUF2SMALL; } // ret = rt_sem_take(&px_sample_data_sem, RT_WAITING_FOREVER); ret = rt_sem_take(&sinkinfo_sem, RT_WAITING_FOREVER); if (RT_EOK != ret) { printf_syn("take px_sample_data_sem fail(%d)\n", ret); return SIE_FAIL; } switch (cmd) { /* 以下命令返回数据量较大,大约(40*3+4)字节 */ case SIC_GET_PAV_SAMPLE_DATA: /* a相电压波形采样值 */ // conv_3bsinged_to_4bsinged(data_buf, len, sinkinfo_all_em[0].px_vi_sample.pa_vi_sample[0], SINK_INFO_PX_SAMPLE_BUF_SIZE); rt_memcpy(data_buf, sinkinfo_all_em[em_no].px_vi_sample.pa_vi_sample[0], len); break; case SIC_GET_PBV_SAMPLE_DATA: // conv_3bsinged_to_4bsinged(data_buf, len, sinkinfo_all_em[0].px_vi_sample.pb_vi_sample[0], SINK_INFO_PX_SAMPLE_BUF_SIZE); rt_memcpy(data_buf, sinkinfo_all_em[em_no].px_vi_sample.pb_vi_sample[0], len); break; case SIC_GET_PCV_SAMPLE_DATA: // conv_3bsinged_to_4bsinged(data_buf, len, sinkinfo_all_em[0].px_vi_sample.pc_vi_sample[0], SINK_INFO_PX_SAMPLE_BUF_SIZE); rt_memcpy(data_buf, sinkinfo_all_em[em_no].px_vi_sample.pc_vi_sample[0], len); break; case SIC_GET_PAI_SAMPLE_DATA: /* a相电流波形采样值 */ // conv_3bsinged_to_4bsinged(data_buf, len, sinkinfo_all_em[0].px_vi_sample.pa_vi_sample[1], SINK_INFO_PX_SAMPLE_BUF_SIZE); rt_memcpy(data_buf, sinkinfo_all_em[em_no].px_vi_sample.pa_vi_sample[1], len); break; case SIC_GET_PBI_SAMPLE_DATA: // conv_3bsinged_to_4bsinged(data_buf, len, sinkinfo_all_em[0].px_vi_sample.pb_vi_sample[1], SINK_INFO_PX_SAMPLE_BUF_SIZE); rt_memcpy(data_buf, sinkinfo_all_em[em_no].px_vi_sample.pb_vi_sample[1], len); break; case SIC_GET_PCI_SAMPLE_DATA: // conv_3bsinged_to_4bsinged(data_buf, len, sinkinfo_all_em[0].px_vi_sample.pc_vi_sample[1], SINK_INFO_PX_SAMPLE_BUF_SIZE); rt_memcpy(data_buf, sinkinfo_all_em[em_no].px_vi_sample.pc_vi_sample[1], len); break; default: ret = SIE_INVALID_CMD; printf_syn("func:%s, invalid cmd\n", __FUNCTION__); break; } // rt_sem_release(&px_sample_data_sem); rt_sem_release(&sinkinfo_sem); return ret; }
/* reception packet. */ struct pbuf *rt_dm9161_rx(rt_device_t dev) { unsigned int temp_rx_bd,address; rt_uint32_t i = 0; rt_uint32_t length; unsigned char *p_recv; struct pbuf* p = RT_NULL; /* lock DM9000 device */ rt_sem_take(&sem_lock, RT_WAITING_FOREVER); while (1) { address = MAC_TX_BD + (MAX_TX_DESCR + i) * 8; temp_rx_bd = sep_emac_read(address); if (!(temp_rx_bd & 0x8000)) { length = temp_rx_bd; length = length >> 16; p_recv = (unsigned char *)(ESRAM_BASE + (MAX_TX_DESCR + i) * 0x600); p = pbuf_alloc(PBUF_LINK,length,PBUF_RAM); if (p != RT_NULL) { struct pbuf *q; rt_int32_t len; for (q = p; q != RT_NULL; q = q->next) { rt_memcpy((rt_uint8_t *)(q->payload),p_recv,q->len); } } else { rt_kprintf("Droping %d packet \n",length); } if(i == (MAX_RX_DESCR-1)) { sep_emac_write(address,0xe000); i = 0; } else { sep_emac_write(address,0xc000); i++; } } else break;
uint32_t coap_blockSize(coap_option_t *opt) { coap_block_t block; uint32_t optLen = opt->len; uint32_t blockLen; rt_memcpy((&block + (3 - optLen)), opt->value, optLen); blockLen = block.szx << 4; LWIP_DEBUGF(COAP_DEBUG, ("block len: %i", blockLen)); return blockLen; }
static void frame_client_create_package_data(rt_uint8_t *pkt_data, struct frame_format_em *frame, rt_uint8_t *data) { rt_uint8_t *tx_pch; tx_pch = pkt_data; *tx_pch++ = frame->head1; *tx_pch++ = frame->head2; *tx_pch++ = frame->head3; *tx_pch++ = frame->head4; *tx_pch++ = frame->ctrl; *tx_pch++ = lwip_htons(frame->data_len) & 0xff; *tx_pch++ = lwip_htons(frame->data_len) >> 8; rt_memcpy(tx_pch, data, frame->data_len); }
rt_err_t rt_wlan_device_control(struct rt_wlan_device* device, rt_uint8_t cmd, void* arg) { rt_err_t result; RT_ASSERT(device != RT_NULL); result = RT_EOK; switch (cmd) { case WLAN_CTRL_SET_SSID: RT_ASSERT(arg != RT_NULL); if (rt_strlen((char*)arg) >= SSID_NAME_MAX) result = -RT_ERROR; else { rt_strncpy(device->ssid, (char*)arg, SSID_NAME_MAX); } break; case WLAN_CTRL_SET_PASSWORD: RT_ASSERT(arg != RT_NULL); if (rt_strlen((char*)arg) >= PASSWORD_LENGTH_MAX) result = -RT_ERROR; else { rt_strncpy(device->password, (char*)arg, PASSWORD_LENGTH_MAX); } break; case WLAN_CTRL_SET_SECURITY: RT_ASSERT(arg != RT_NULL); device->security = *(rt_uint8_t*)arg; break; case WLAN_CTRL_SET_MODE: RT_ASSERT(arg != RT_NULL); device->mode = *(rt_uint8_t*)arg; break; case WLAN_CTRL_SET_CHANNEL: device->channel = *(rt_uint8_t*)arg; break; case WLAN_CTRL_SET_BSADDR: rt_memcpy(device->bs_addr, (rt_uint8_t*) arg, MAC_LENGTH_MAX); break; } return result; }
void rtgui_textbox_set_line_length(struct rtgui_textbox* box, rt_size_t length) { rt_uint8_t* new_line; RT_ASSERT(box != RT_NULL); /* invalid length */ if (length <= 0) return; new_line = rtgui_malloc(length); if (length < box->line_length) { rt_memcpy(new_line, box->text, length - 1); new_line[length] = '\0'; } else { rt_memcpy(new_line, (const char*)box->text, rt_strlen((const char*)box->text)); } /* set line length */ box->line_length = length; }
struct rtgui_dc* rtgui_graphic_driver_get_rect_buffer(const struct rtgui_graphic_driver *driver, struct rtgui_rect *r) { int w, h; struct rtgui_dc_buffer *buffer; rt_uint8_t *pixel, *dst; struct rtgui_rect src, rect; /* use virtual framebuffer in default */ if (driver == RT_NULL) driver = _current_driver; if (r == RT_NULL) { rtgui_graphic_driver_get_rect(driver, &rect); } else { rtgui_graphic_driver_get_rect(driver, &src); rect = *r; rtgui_rect_intersect(&src, &rect); } w = rtgui_rect_width (rect); h = rtgui_rect_height(rect); if (!(w && h) || driver->framebuffer == RT_NULL) return RT_NULL; /* create buffer DC */ buffer = (struct rtgui_dc_buffer*)rtgui_dc_buffer_create_pixformat(driver->pixel_format, w, h); if (buffer == RT_NULL) return (struct rtgui_dc*)buffer; /* get source pixel */ pixel = (rt_uint8_t*)driver->framebuffer + rect.y1 * driver->pitch + rect.x1 * rtgui_color_get_bpp(driver->pixel_format); dst = buffer->pixel; while (h--) { rt_memcpy(dst, pixel, buffer->pitch); dst += buffer->pitch; pixel += driver->pitch; } return (struct rtgui_dc*)buffer; }