add time info, 128Hz printk

This commit is contained in:
Babz 2021-09-10 23:12:01 +02:00
parent a439d1f60b
commit 10b1d237d7
4 changed files with 48 additions and 5 deletions

View File

@ -79,7 +79,7 @@ static void check_keyevents(void) {
timer_start(timer_redraw);
}
term_printf("[%d] key event: key=0x%x mod=%d shift=%d alpha=%d\n", tick_ctr, kev.key, kev.mod, kev.shift, kev.alpha);
term_kprintf("key event: key=0x%x mod=%d shift=%d alpha=%d", kev.key, kev.mod, kev.shift, kev.alpha);
if (kev.key == KEY_SHIFT)
shift_state = !shift_state;

View File

@ -1,7 +1,10 @@
#include "term.h"
#include <ctype.h>
#include <gint/cpu.h>
#include <gint/display.h>
#include <gint/rtc.h>
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
@ -140,8 +143,6 @@ static int term_print_opt(const char *str, int fg, int bg) {
}
int term_print(const char *str) { return term_print_opt(str, C_WHITE, C_BLACK); }
int term_eprint(const char *str) { return term_print_opt(str, C_RED, C_BLACK); }
int term_printf(const char *restrict format, ...) {
va_list argp;
va_start(argp, format);
@ -154,6 +155,7 @@ int term_printf(const char *restrict format, ...) {
return n;
}
int term_eprint(const char *str) { return term_print_opt(str, C_RED, C_BLACK); }
int term_eprintf(const char *restrict format, ...) {
va_list argp;
va_start(argp, format);
@ -162,6 +164,32 @@ int term_eprintf(const char *restrict format, ...) {
const int n = vsprintf(buf, format, argp);
term_eprint(buf);
va_end(argp);
return n;
}
int term_kprint(const char *str) {
cpu_atomic_start();
int t = rtc_ticks();
char kstr[256];
sprintf(kstr, "[%5d:%03d] %s\n", t / 128, t % 128, str);
const int ret = term_print_opt(kstr, C_RED | C_GREEN, C_BLACK);
cpu_atomic_end();
return ret;
}
int term_kprintf(const char *restrict format, ...) {
va_list argp;
va_start(argp, format);
char buf[1024];
const int n = vsprintf(buf, format, argp);
term_kprint(buf);
va_end(argp);
return n;
}

View File

@ -17,4 +17,8 @@ int term_printf(const char *restrict format, ...);
int term_eprint(const char *str);
int term_eprintf(const char *restrict format, ...);
// trace print (printk equivalent)
int term_kprint(const char *str);
int term_kprintf(const char *restrict format, ...);
#endif // #ifndef UNS_TERM_H

View File

@ -2,10 +2,18 @@
#include "term.h"
#include <gint/display.h>
#include <gint/rtc.h>
#include <stdio.h>
#include <string.h>
static void date_str(char *buf) {
rtc_time_t t;
rtc_get_time(&t);
sprintf(buf, "%04d-%02d-%02d %02d:%02d:%02d", t.year, t.month, t.week_day, t.hours, t.minutes, t.seconds);
}
void set_statusbar(int tick_ctr, int shift_state, int alpha_state, int battery) {
// set green bar
for (int i = 0; i < UNS_TERM_COLS; i++)
@ -14,9 +22,12 @@ void set_statusbar(int tick_ctr, int shift_state, int alpha_state, int battery)
char *shift_symbol = shift_state ? "" : " ";
char *alpha_symbol = alpha_state ? (shift_state ? "A" : "a") : "1";
char now[32];
date_str(now);
// then add actutal text
char statusbar[UNS_TERM_COLS + 1];
sprintf(statusbar, "%s%s t=%dk bat=%d", shift_symbol, alpha_symbol, tick_ctr / 1000, battery);
sprintf(statusbar, "%s%s t=%dk bat=%d %s", shift_symbol, alpha_symbol, tick_ctr / 1000, battery, now);
term_writeat(0, 0, C_BLACK, C_GREEN, statusbar);
}