add nimble uart

download "nimble connect" on your phone, connect to "Nimble Uart", send byte array or uint8 to the board through the app
This commit is contained in:
daishengdong
2019-11-15 15:37:06 +08:00
parent b56314d28f
commit bae04c6774
51 changed files with 94780 additions and 59846 deletions

View File

@@ -1,14 +1,25 @@
#ifndef _CONSOLE_H_
#define _CONSOLE_H_
#if 0
#include "tos.h"
#define console_printf tos_kprintf
// we need a console
#define console_init(...) -1
#define console_write(...)
#define console_write(...) printf(__VA_ARGS__);
#define console_read(...) -1
#endif
#define console_init(...) -1
int console_printf(const char *fmt, ...);
int console_read(char *str, int cnt, int *newline);
void console_write(const char *str, int cnt);
#endif

View File

@@ -0,0 +1,48 @@
#include "console/console.h"
#include "stdint.h"
#include "stdarg.h"
int console_printf(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
}
int console_read(char *str, int cnt, int *newline)
{
return 0;
}
char convert_int2ascii(int8_t n)
{
if (n < 10 && n >= 0) {
return n - 0 + '0';
} else if (n <= 15 && n >= 10) {
return n - 10 + 'A';
} else {
return '$';
}
}
void console_write(const char *str, int cnt)
{
int i;
if (cnt == 1 && str[0] == 10) {
printf("\n");
return;
}
printf("0x");
for (i = 0; i < cnt; ++i) {
printf("%c%c", convert_int2ascii(str[i] / 16), convert_int2ascii(str[i] % 16));
if (i != cnt - 1) {
printf("-");
}
}
}