示例#1
0
/*
 * \brief Main entry point of Arduino application
 */
extern "C" void vm_main( void )
{
	VM_THREAD_HANDLE handle;

	/* Alloc DMA memory for SPI read and write, for SPI must be use non-cache memory, so we need use
	   vm_malloc_dma to alloc memory, but in arduino thread we cannot invoke this interface directly,
	   so use here to prepare memory, you can see its usage in SPI.transfer in SPI.cpp */
	spi_w_data = (unsigned char*)vm_malloc_dma(2);
	spi_r_data = (unsigned char*)vm_malloc_dma(2);

	/* Same reason like above, this is used for transferring large of data, like screen buffer, you
	   can see its usage in SPI.write in SPI.cpp  */
	spi_data_memory = (unsigned char*)vm_malloc_dma(64*1024);
	memset(spi_data_memory,0, 64*1024);

	/* only prepare something for rand, please don't delete this , otherwise arduino cannot use these
	   two interface */
	srand(0) ;
	rand();

	/* Register system event callback */
	vm_pmng_register_system_event_callback(__handle_sysevt);

	/* Register voice call event callback */
	vm_gsm_tel_call_reg_listener(__call_listener_func);

	/* Create arduino thread, and change its priority, please don't change the code, or it will effort
	   system stable */
	handle = vm_thread_create(__arduino_thread, NULL, 0);
	vm_thread_change_priority(handle, 245);
}
示例#2
0
/* Allocate memory for a single frame */
VMBOOL allocate_frame(vm_graphic_frame_t *frame) {
	if(frame == NULL) {
		return VM_FALSE;
	}

	/* We use 16-bit color, 2 bytes per pixel */
	frame->color_format = VM_GRAPHIC_COLOR_FORMAT_16_BIT;
	frame->width = SCREEN_WIDTH;
	frame->height =  SCREEN_HEIGHT;
	frame->buffer_length = SCREEN_WIDTH * SCREEN_HEIGHT * 2;
	frame->buffer = vm_malloc_dma(frame->buffer_length);
	if(frame->buffer == NULL) {
		return VM_FALSE;
	}

	return VM_TRUE;
}
示例#3
0
/* Set font and draw hello world text */
static void draw_hello(void) {
	VMWSTR string;
	vm_graphic_color_argb_t color;
	vm_graphic_frame_t frame;
	vm_graphic_frame_t* frame_group[1];
	VMWCHAR font_path[FONT_PATH_MAX_LENGTH + 1];
	VMWSTR font_paths_group[1];
	VM_RESULT result;
	VMUINT32 pool_size;
	VMUINT32 size;

	vm_graphic_point_t positions[1] = { 0, 0 };

	frame.buffer_length = SCREEN_WIDTH * SCREEN_HEIGHT * 2;
	frame.buffer = vm_malloc_dma(frame.buffer_length);
	if (frame.buffer == NULL) {
		return;
	}

	frame.color_format = VM_GRAPHIC_COLOR_FORMAT_16_BIT;
	frame.height = SCREEN_HEIGHT;
	frame.width = SCREEN_WIDTH;
	frame_group[0] = &frame;

	string = vm_res_get_string(STR_ID_HELLO, &size);
	color.a = 255;
	color.r = 243;
	color.g = 154;
	color.b = 30;
	vm_graphic_set_color(color);
	vm_graphic_draw_solid_rectangle(&frame, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

	result = vm_graphic_get_font_pool_size(EXTERNAL_FONT_SIZE, 1,
	FONT_CACHE_SIZE, &pool_size);
	if (VM_IS_SUCCEEDED(result)) {
		font_pool = vm_malloc(pool_size);
		if (NULL != font_pool) {
			result = vm_graphic_init_font_pool(font_pool, pool_size);
		} else {
			vm_log_info("allocate font pool memory failed");
			return;
		}
	}
	if (!(VM_IS_SUCCEEDED(result))) {
		vm_log_info("init font pool failed");
		return;
	}
	vm_chset_ascii_to_ucs2(font_path, (FONT_PATH_MAX_LENGTH + 1) * 2,
	EXTERNAL_FONT_PATH);
	font_paths_group[0] = font_path;
	vm_graphic_reset_font();
	result = vm_graphic_set_font(font_paths_group, 1);
	if (!(VM_IS_SUCCEEDED(result))) {
		vm_log_info("set font failed");
	}

	color.r = 255;
	color.g = 255;
	color.b = 255;
	vm_graphic_set_color(color);
	vm_graphic_set_font_size(VM_GRAPHIC_LARGE_FONT);
	vm_log_info("String: %d, %d, %d, %d, %d, %d", string[0], string[1],
			string[2], string[3], string[4], string[5]);
	vm_graphic_draw_text(&frame, 1, 1, string);
#if defined(__HDK_LINKIT_ASSIST_2502__)
	vm_graphic_blt_frame(frame_group, positions, 1);
#endif
	vm_free(frame.buffer);
	vm_free(font_pool);
	font_pool = NULL;
}