示例#1
0
int log_putc(int c)
{
	if(last_update.trigger_value == 0)
		last_update = register_timer(LOG_TIMEOUT);

	if(log_buf && buf_size)
	{
		log_buf[buf_ptr++] = c;
		if(buf_ptr >= buf_size)
		{
			if((log_fp && log_fp->fflush_cb) || (last_update.rollover && compare_timer(last_update)))
			{
				log_fp->fflush_cb(log_fp);
				last_update = register_timer(LOG_TIMEOUT);
			}
			buf_ptr = 0;
		}
		return 0;
	}
	else if(log_fp)
	{
		// Disable output to the log for the write
		rpi_boot_output_state state = output_get_state();
		output_disable_log();

		// Write one character
		fwrite(&c, 1, 1, log_fp);

		// Restore saved output state
		output_restore_state(state);
		return 0;
	}
	return EOF;
}
示例#2
0
void main() {
    int x, y, c;
    struct timer_wait tw;
    int led_status = LOW;

    // Default screen resolution (set in config.txt or auto-detected)
    //fb_init(0, 0);

    // Sets a specific screen resolution
    fb_init(32 + 320 + 32, 32 + 200 + 32);

    fb_fill_rectangle(0, 0, fb_width - 1, fb_height - 1, BORDER_COLOR);

    initscr(40, 25);
    cur_fore = WHITE;
    cur_back = BACKGROUND_COLOR;
    clear();

    mvaddstr(1, 9, "**** RASPBERRY-PI ****");
    mvaddstr(3, 7, "BARE-METAL SYSTEM TEMPLATE\r\n");

    if (mount("sd:") != 0) {
        addstrf("\r\nSD CARD NOT MOUNTED (%s)\r\n", strerror(errno));
    }

    usb_init();
    if (keyboard_init() != 0) {
        addstr("\r\nNO KEYBOARD DETECTED\r\n");
    }

    pinMode(16, OUTPUT);
    register_timer(&tw, 250000);

    addstr("\r\nREADY\r\n");

    while(1) {
        if ((c = getch()) != -1) {
            switch(c) {
                case KEY_UP:
                    getyx(y, x);
                    move(y - 1, x);
                    break;
                case KEY_DOWN:
                    getyx(y, x);
                    move(y + 1, x);
                    break;
                case KEY_LEFT:
                    getyx(y, x);
                    x--;
                    if (x < 0) {
                        x = 39;
                        y--;
                    }
                    move(y, x);
                    break;
                case KEY_RIGHT:
                    getyx(y, x);
                    x++;
                    if (x >= 40) {
                        x = 0;
                        y++;
                    }
                    move(y, x);
                    break;
                case KEY_HOME:
                    getyx(y, x);
                    move(y, 0);
                    break;
                case KEY_PGUP:
                    move(0, 0);
                    break;
                case '\r':
                    addch(c);
                    addch('\n');
                    break;
                default:
                    if (c < 0x7F) {
                        addch(c);
                    }
                    break;
            }
        }

        if (compare_timer(&tw)) {
            led_status = led_status == LOW ? HIGH : LOW;
            digitalWrite(16, led_status);
            toggle_cursor();
        }

        refresh();
    }
}