Пример #1
0
int fgetc(int file)
{
	if (file < MAX_FILES) {
#if defined(CONFIG_CONSOLE_MUX)
		/*
		 * Effectively poll for input wherever it may be available.
		 */
		for (;;) {
			/*
			 * Upper layer may have already called tstc() so
			 * check for that first.
			 */
			if (tstcdev != NULL)
				return console_getc(file);
			console_tstc(file);
#ifdef CONFIG_WATCHDOG
			/*
			 * If the watchdog must be rate-limited then it should
			 * already be handled in board-specific code.
			 */
			 udelay(1);
#endif
		}
#else
		return console_getc(file);
#endif
	}

	return -1;
}
Пример #2
0
/*
 * int console_gets(char *s, int len)
 *
 * Wait for a string to be entered on the console, limited
 * support for editing characters (back space and delete)
 * end when a <CR> character is received.
 */
int console_gets(char *s, int len)
{
	char *t = s;
	char c;

	*t = '\000';
	/* read until a <CR> is received */
	while ((c = console_getc(1)) != '\r') {
		if ((c == '\010') || (c == '\127')) {
			if (t > s) {
				/* send ^H ^H to erase previous character */
				console_puts("\010 \010");
				t--;
			}
		} else {
			*t = c;
			console_putc(c);
			if ((t - s) < len) {
				t++;
			}
		}
		/* update end of string with NUL */
		*t = '\000';
	}
	return t - s;
}
Пример #3
0
void dbg_console_thread(void* param)
{
	for (;;)
	{
		switch(console_getc(_dbg_console))
		{
		case 'h':
			printf("dbg console help\n\r");
			printf("h - this text\n\r");
#if (KERNEL_PROFILING)
			printf("m - memory usage statistics\n\r");
			printf("p - process list\n\r");
			printf("s - system stack usage\n\r");
#endif //KERNEL_PROFILING
			break;
#if (KERNEL_PROFILING)
		case 'm':
			mem_stat();
			break;
		case 'p':
			thread_stat();
			break;
		case 's':
			stack_stat();
			break;
#endif //KERNEL_PROFILING
		}
	}
}
Пример #4
0
static ssize_t console_read(void *cookie, char *buf, size_t size)
{
	cookie = cookie;        /* -Wunused-parameter */
	size_t i;
	for (i = 0; i < size; i++) {
		char c = console_getc(1);
		buf[i] = c;
		if (c == '\r') {
			buf[i] = '\n';
			i++;
			break;
		}
	}
	return i;
}
Пример #5
0
int console_gets(char *s)
{
	int cnt = 0;
	char  c;

	while ((c = console_getc()) != CR) 
	{
		if (c != BS) {
			cnt++;
			*s++ = c;
			screen_putch(c);	//echo
		}
		else {
			if (cnt > 0) {
				cnt--; 
				*--s = '\0';
				console_puts("\b \b");
			}
		}
	}
	*s = 0;
	return cnt;
}
Пример #6
0
/*
 * This is the code for the simple DMA2D Demo
 *
 * Basically it lets you put display digits on the
 * screen manually or with the DMA2D peripheral. It
 * has various 'bling' levels, and it tracks performance
 * by measuring how long it takes to go from one frame
 * to the next.
 */
int
main(void) {
	int	i;
	uint32_t t1, t0;
	char buf[35];
	char *scr_opt;
	int f_ndx = 0;
	float avg_frame;
	int	can_switch;
	int	opt, ds;

	/* Enable the clock to the DMA2D device */
	rcc_periph_clock_enable(RCC_DMA2D);
	fprintf(stderr, "DMA2D Demo program : Digits Gone Wild\n");
	printf("Generate background\n");
	generate_background();
	printf("Generate digits\n");
	generate_digits();

	gfx_init(lcd_draw_pixel, 800, 480, GFX_FONT_LARGE);
	opt = 0; /* screen clearing mode */
	can_switch = 0; /* auto switching every 10 seconds */
	t0 = mtime();
	ds = 0;
	while (1) {
		switch (opt) {
		default:
		case 0:
			/* very slow way to clear the screen */
			scr_opt = "manual clear";
			gfx_fillScreen(0xffff);
			break;
		case 1:
			/* faster, using a tight loop */
			scr_opt = "dedicated loop";
			lcd_clear(0xff7f7f);
			break;
		case 2:
			/* fastest? Using DMA2D to fill screen */
			scr_opt = "DMA 2D Fill";
			dma2d_fill(0xff7fff7f);
			break;
		case 3:
			/* still fast, using DMA2D to pre-populate BG */
			scr_opt = "DMA 2D Background";
			dma2d_bgfill();
			break;
		case 4:
			/* Now render all of the digits with DMA2D */
			scr_opt = "DMA 2D Digits";
			ds = 0;
			dma2d_bgfill();
			break;
		case 5:
			/* still fast, using DMA2D to render drop shadows */
			scr_opt = "DMA 2D Shadowed Digits";
			ds = 1;
			dma2d_bgfill();
			break;
		}

		/* This little state machine implements an automatic switch
		 * every 10 seconds unless you've disabled it with the 'd'
		 * command.
		 */
		if (((t0 / 1000) % 10 == 0) && (can_switch > 0)) {
			opt = (opt + 1) % MAX_OPTS;
			can_switch = 0;
		} else  if (((t0 / 1000) % 10 != 0) && (can_switch == 0)) {
			can_switch = 1;
		}

		/*
		 * The first four options (0, 1, 2, 3) all render the digits
		 * in software every time, options 4 and 5 use the DMA2
		 * device to render the digits
		 */
		if (opt < 4) {
			display_clock(25, 20, mtime());
		} else {
			dma2d_clock(25, 20, mtime(), ds);
		}
		for (i = 0; i < 10; i++) {
			if (opt < 4) {
				draw_digit(25 + i * (DISP_WIDTH + 8), 350, i, GFX_COLOR_GREEN, GFX_COLOR_BLACK);
			} else {
				if (ds) {
					dma2d_digit(35 + i * (DISP_WIDTH + 8), 360, i, SHADOW, SHADOW);
				}
				dma2d_digit(25 + i * (DISP_WIDTH + 8), 350, i, 0xff40c040, 0xff000000);
			}
		}

		/* In both cases we write the notes using the graphics library */
		gfx_setTextColor(0, 0);
		gfx_setTextSize(3);
		gfx_setCursor(25, 30 + DISP_HEIGHT + gfx_getTextHeight() + 2);
		gfx_puts((unsigned char *)"Hello world for DMA2D!");
		lcd_flip(te_lock);
		t1 = mtime();

		/* this computes a running average of the last 10 frames */
		frame_times[f_ndx] = t1 - t0;
		f_ndx = (f_ndx + 1) % N_FRAMES;
		for (i = 0, avg_frame = 0; i < N_FRAMES; i++) {
			avg_frame += frame_times[i];
		}
		avg_frame = avg_frame / (float) N_FRAMES;
		snprintf(buf, 35, "FPS: %6.2f", 1000.0 / avg_frame);
		gfx_setCursor(25, 30 + DISP_HEIGHT + 2 * (gfx_getTextHeight() + 2));
		gfx_puts((unsigned char *)buf);
		gfx_puts((unsigned char *)" ");
		gfx_setCursor(25, 30 + DISP_HEIGHT + 3 * (gfx_getTextHeight() + 2));
		gfx_puts((unsigned char *)scr_opt);
		/*
		 * The demo runs continuously but it watches for characters
		 * typed at the console. There are a few options you can select.
		 */
		i = console_getc(0);
		switch (i) {
		case 's':
			opt = (opt + 1) % MAX_OPTS;
			printf("Switched to : %s\n", demo_options[opt]);
			break;
		case 'd':
			can_switch = -1;
			printf("Auto switching disabled\n");
			break;
		case 'e':
			can_switch = 0;
			printf("Auto switching enabled\n");
			break;
		case 't':
			te_lock = (te_lock == 0);
			printf("We are %s for the TE bit to be set\n", (te_lock) ? "WAITING" : "NOT WAITING");
			break;
		default:
			printf("Options:\n");
			printf("\ts - switch demo mode\n");
			printf("\td - disable auto-switching of demo mode\n");
			printf("\te - enable auto-switching of demo mode\n");
			printf("\tt - enable/disable Tearing effect lock wait\n");
		case 0:
			break;
		}
		t0 = t1;
	}
}
Пример #7
0
int linenoise_getline( int id, char* buffer, int buffer_size, const char* prompt )
{
    int ch;
    int line_position;
start:
    /* show prompt */
    console_puts(prompt);

    line_position = 0;
    memset(buffer, 0, buffer_size);
    while (1)
    {
        ch = console_getc();
        if (ch >= 0)
        {
            /* backspace key */
            if (ch == 0x7f || ch == 0x08)
            {
                if (line_position > 0)
                {
                    console_puts("\x08 \x08");
                    line_position--;
                }
                buffer[line_position] = 0;
                continue;
            }
            /* EOF(ctrl+d) */
            else if (ch == 0x04)
            {
                if (line_position == 0)
                    /* No input which makes lua interpreter close */
                    return 0;
                else
                    continue;
            }

            /* end of line */
            if (ch == '\r' || ch == '\n')
            {
                buffer[line_position] = 0;
                console_putc('\n');
                if (line_position == 0)
                {
                    /* Get a empty line, then go to get a new line */
                    goto start;
                }
                else
                {
                    return line_position;
                }
            }

            /* other control character or not an acsii character */
            if (ch < 0x20 || ch >= 0x80)
            {
                continue;
            }

            /* echo */
            console_putc(ch);
            buffer[line_position] = ch;
            ch = 0;
            line_position++;

            /* it's a large line, discard it */
            if (line_position >= buffer_size)
                line_position = 0;
       }
    }

}