mirror of
https://github.com/IcedRooibos/py32f0-template.git
synced 2025-10-28 16:32:05 -07:00
83 lines
1.4 KiB
C
83 lines
1.4 KiB
C
#include <sys/stat.h>
|
|
#include <unistd.h>
|
|
#include <errno.h>
|
|
|
|
#define UART_PRINTF_BAUDRATE 115200
|
|
|
|
const uint8_t HEX_TABLE[16] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
|
|
|
|
|
|
int __io_getchar(void)
|
|
{
|
|
//return USART_ReceiveData(USART1);
|
|
return 0;
|
|
}
|
|
|
|
int __io_putchar(int ch)
|
|
{
|
|
// UART_SendByte((uint8_t)ch);
|
|
return ch;
|
|
}
|
|
|
|
__attribute__((weak)) int _read(int file, char *ptr, int len)
|
|
{
|
|
(void)file;
|
|
int DataIdx;
|
|
for (DataIdx = 0; DataIdx < len; DataIdx++)
|
|
{
|
|
*ptr++ = __io_getchar();
|
|
}
|
|
return len;
|
|
}
|
|
|
|
__attribute__((weak)) int _write(int file, char *ptr, int len)
|
|
{
|
|
(void)file;
|
|
int DataIdx;
|
|
for (DataIdx = 0; DataIdx < len; DataIdx++)
|
|
{
|
|
__io_putchar(*ptr++);
|
|
}
|
|
return len;
|
|
}
|
|
|
|
|
|
__attribute__((weak)) int _isatty(int fd)
|
|
{
|
|
if (fd >= STDIN_FILENO && fd <= STDERR_FILENO)
|
|
return 1;
|
|
|
|
errno = EBADF;
|
|
return 0;
|
|
}
|
|
|
|
__attribute__((weak)) int _close(int fd)
|
|
{
|
|
if (fd >= STDIN_FILENO && fd <= STDERR_FILENO)
|
|
return 0;
|
|
|
|
errno = EBADF;
|
|
return -1;
|
|
}
|
|
|
|
__attribute__((weak)) int _lseek(int fd, int ptr, int dir)
|
|
{
|
|
(void)fd;
|
|
(void)ptr;
|
|
(void)dir;
|
|
|
|
errno = EBADF;
|
|
return -1;
|
|
}
|
|
|
|
__attribute__((weak)) int _fstat(int fd, struct stat *st)
|
|
{
|
|
if (fd >= STDIN_FILENO && fd <= STDERR_FILENO)
|
|
{
|
|
st->st_mode = S_IFCHR;
|
|
return 0;
|
|
}
|
|
|
|
errno = EBADF;
|
|
return 0;
|
|
} |