blob: c1499e4c9c0ed433712b0cff2d948348d5eadeff [file] [log] [blame]
/*
* Copyright (C) 2008 Advanced Micro Devices, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <usb/usb.h>
#include "drivers/console/console.h"
int putchar(unsigned int i)
{
unsigned char c = (unsigned char)i;
console_write(&c, 1);
return c;
}
int puts(const char *s)
{
size_t size = strlen(s);
console_write(s, size);
putchar('\n');
return size + 1;
}
static int _havekey(int trusted)
{
if (CONFIG_USB)
usb_poll();
return console_has_key(trusted) != NULL;
}
static int _getchar(int trusted)
{
ConsoleInputOps *console = NULL;
do {
if (CONFIG_USB)
usb_poll();
console = console_has_key(trusted);
} while (!console);
return console->getchar(console);
}
int havekey(void)
{
return _havekey(0);
}
int havekey_trusted(void)
{
return _havekey(1);
}
int getchar(void)
{
return _getchar(0);
}
int getchar_trusted(void)
{
return _getchar(1);
}