Skip to content

Commit

Permalink
merge steno?
Browse files Browse the repository at this point in the history
until 21112243b0432ebd023709686e7dd30f89c3ea7b
  • Loading branch information
crides committed May 19, 2021
1 parent c6e1963 commit 77172fe
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
1 change: 1 addition & 0 deletions qmk/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ STENO_STROKE_DISPLAY = no
STENO_NOUNICODE = yes

STENO_DEBUG = # hist stroke flash dicted
STENO_FLASH_LOGGING = yes
55 changes: 55 additions & 0 deletions qmk/flog.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Utilities to provide flash-based logging
#include "eeprom.h"
#include "store.h"
#include "stroke.h"
#include "steno.h"
#include "sendchar.h"

#define LOG_ADDR_ADDR ((uint32_t *) 128)
static uint32_t log_addr = FLOG_START;
static uint32_t erased_till = FLOG_START + 0x1000;
static uint8_t buf[128] = {'!'};

// HACK uses private/platform specific interface
void flash_erase_4k(const uint32_t addr);

static int8_t flog_handle_char(uint8_t c) {
static uint8_t log_buf_size = 1;
sendchar(c);
buf[log_buf_size++] = c;
if (c == '\n') {
if (log_addr + log_buf_size >= STORE_END) {
log_addr = FLOG_START;
erased_till = log_addr;
}
const uint32_t cur_page_end = (log_addr & 0xFFFFFF00) + 0x100;
if (log_addr + log_buf_size > cur_page_end) {
log_addr = cur_page_end;
}
if (log_addr + log_buf_size > erased_till) {
flash_erase_4k(erased_till);
erased_till += 0x1000;
}
store_flush();
store_write_direct(log_addr, buf, log_buf_size);
log_addr += log_buf_size;
log_buf_size = 1;
store_flush();
}
return 0;
}

void flog_init(void) {
// Assuming storage is inited
const uint32_t stored = eeprom_read_dword(LOG_ADDR_ADDR);
if (stored >= FLOG_START && stored < STORE_END) {
log_addr = stored;
erased_till = (log_addr & 0xFFF000) + 0x1000;
}
print_set_sendchar(flog_handle_char);
}

void flog_finish_cycle(void) {
steno_debug_ln("log_addr: %06lX, erased_till: %06lX", log_addr, erased_till);
eeprom_update_dword(LOG_ADDR_ADDR, log_addr);
}
4 changes: 4 additions & 0 deletions qmk/flog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

void flog_init(void);
void flog_finish_cycle(void);
2 changes: 1 addition & 1 deletion qmk/ghostfat.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,6 @@ void fat_read_block(const uint32_t block_no, const uint8_t packet_num, uint8_t *
}
} else if (cluster_no < FILE_END) {
cluster_no -= FILE_START;
store_read((cluster_no * 8 + cluster_packet_num) * EPSIZE, data, EPSIZE);
store_read((cluster_no * PACKETS_PER_CLUSTER + cluster_packet_num) * EPSIZE, data, EPSIZE);
}
}
1 change: 1 addition & 0 deletions qmk/hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ state_t process_output(const uint8_t h_ind) {
if (stroke_to_string(hist->stroke, buf, &hist->len)) {
new_state.glue = 1;
}
hist->ortho_len = 1;
#ifdef STENO_DEBUG_HIST
steno_debug(" out: '");
#endif
Expand Down
8 changes: 6 additions & 2 deletions qmk/impl/qmk/flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static void flash_read_page(uint32_t addr, uint8_t *buf) {
unselect_card();
}

void flash_flush(void) {
static void flash_flush(void) {
select_card();
while (1) {
spi_send_byte(0x05); // read status reg
Expand Down Expand Up @@ -108,7 +108,11 @@ static void flash_write_page(const uint32_t addr, const uint8_t *const buf) {
unselect_card();
}

static void flash_erase_4k(const uint32_t addr) {
// HACK uses private/platform specific interface
#ifndef STENO_FLASH_LOGGING
static
#endif
void flash_erase_4k(const uint32_t addr) {
#ifdef STENO_DEBUG_FLASH
if (flash_debug_enable) {
steno_debug_ln("flash_erase_4k(@ 0x%06lX)", addr);
Expand Down
24 changes: 12 additions & 12 deletions qmk/orthography.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
#include <string.h>
#include <ctype.h>

static bool strneq(const char *a, const char *b, const uint8_t n) {
static bool strneq(const char *const a, const char *const b, const uint8_t n) {
return strncmp(a, b, n) == 0;
}

static bool chrin(const char *s, const char c) {
static bool chrin(const char *const s, const char c) {
return c != 0 && strchr(s, c);
}

// Returns how many chars to backspace, and what text (`output`) to append after
// NOTE assumes the suffix we get is valid, so no end of string checking
// Rules borrowed from https://github.com/nimble0/dotterel/blob/master/app/src/main/assets/orthography/english.regex.json
static int8_t regex_ortho(const char *word, const char *suffix, char *output) {
static int8_t regex_ortho(const char *const word, const char *const suffix, char *const output) {
const uint8_t word_len = strlen(word);
char rev[WORD_ENDING_SIZE];
// Invert `word` so that indexing is anchored to the end
Expand Down Expand Up @@ -57,10 +57,11 @@ static int8_t regex_ortho(const char *word, const char *suffix, char *output) {

// word: (s|sh|x|z|zh)
// ((?:oa|ea|i|ee|oo|au|ou|l|n|(?<![gin]a)r|t)ch)
// + s(\w|$) -> \1es\2
// ([bcdfghjklmnpqrstvwxz])y + s(\w|$) -> \1ies\2
if (suffix[0] == 's') {
if ((chrin("sxz", rev[0]) || (rev[1] == 'h' && (rev[2] == 's' || rev[2] == 'z')))
// + s([^\w]|$) -> \1es\2
// ([bcdfghjklmnpqrstvwxz])y + s([^\w]|$) -> \1ies\2
// End of string is just \0, which is not [[:alpha:]]
if (suffix[0] == 's' && !isalpha(suffix[1])) {
if ((chrin("sxz", rev[0]) || (rev[0] == 'h' && (rev[1] == 's' || rev[1] == 'z')))
|| (strneq("hc", rev, 2) && (chrin("ilnt", rev[2]) || strneq("ao", rev + 2, 2) || strneq("ae", rev + 2, 2)
|| strneq("ee", rev + 2, 2) || strneq("oo", rev + 2, 2)
|| strneq("ua", rev + 2, 2) || strneq("uo", rev + 2, 2)
Expand Down Expand Up @@ -145,7 +146,6 @@ static int8_t regex_ortho(const char *word, const char *suffix, char *output) {
return 0;
}

// XXX ((?:^|\\W)(?:[bcdfghjklmnprstvwxyz]+|[bcdfghjklmnprstvwxyz]*qu)[aeiou])([bdfgklmnprstz]) + (ed|en|er|ier|est|ing|y|ie|ies|iest|iness|ish|abl[ey]|ability|abilities) -> \1\2\2\3
// suffix: (ed|en|er|ier|est|in[g]|y|ie|ies|iest|iness|ish|abl[ey]|ability|abilities)
// word: ((?:[bcdfghjklmnprstvwxyz]+|[bcdfghjklmnprstvwxyz]*qu)[aeiou])([bdfgklmnprstz])
// ((?:[bcdfghjklmnprstvwxyz]|qu)a)([gbmptv])
Expand All @@ -162,7 +162,8 @@ static int8_t regex_ortho(const char *word, const char *suffix, char *output) {
|| suffix[0] == 'y') {
if ((rev[1] == 'a' && chrin("gbmptv", rev[0])) || (rev[1] == 'e' && chrin("gbpv", rev[0]))
|| (rev[1] == 'i' && chrin("gbmpv", rev[0])) || (rev[1] == 'o' && chrin("gbdlv", rev[0]))
|| (rev[1] == 'u' && chrin("gbdlmntv", rev[0]))) {
|| (rev[1] == 'u' && chrin("gbdlmntv", rev[0]))
|| (chrin("bdfgklmnprstz", rev[0]) && chrin("aeiou", rev[1]))) {
const bool junk = chrin("bcdfghjklmnprstvwxyz", rev[2]);
if (junk || (rev[1] != 'u' && strneq("uq", rev + 2, 2))) {
output[0] = rev[0];
Expand All @@ -171,7 +172,6 @@ static int8_t regex_ortho(const char *word, const char *suffix, char *output) {
}
}
}

return -1;
}

Expand All @@ -190,7 +190,7 @@ static uint32_t hash_str(const char *str) {
return hash;
}

static int8_t simple_ortho(const char *word, const char *suffix, char *output) {
static int8_t simple_ortho(const char *const word, const char *const suffix, char *const output) {
const uint8_t word_len = strlen(word);
const uint8_t suffix_len = strlen(suffix);
if (word_len > 13 || suffix_len > 9) { // None of the entries in the rules are that long
Expand Down Expand Up @@ -228,7 +228,7 @@ static int8_t simple_ortho(const char *word, const char *suffix, char *output) {
return -1;
}

int8_t process_ortho(const char *word, const char *suffix, char *output) {
int8_t process_ortho(const char *const word, const char *const suffix, char *const output) {
const int8_t ret = regex_ortho(word, suffix, output);
if (ret == -1) {
return simple_ortho(word, suffix, output);
Expand Down
6 changes: 6 additions & 0 deletions qmk/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ else
endif

ifeq ($(STENO_NOMSD),yes)
STENO_FLASH_LOGGING = no
CFLAGS += -DSTENO_NOMSD
MSC_ENABLE = no
else
Expand All @@ -32,6 +33,11 @@ ifeq ($(STENO_NOUNICODE), yes)
CFLAGS += -DSTENO_NOUNICODE
endif

ifeq ($(STENO_FLASH_LOGGING),yes)
SRC += flog.c
CFLAGS += -DSTENO_FLASH_LOGGING
endif

STENO_DEBUG := $(filter hist stroke flash dicted, $(STENO_DEBUG))

ifneq (, $(findstring hist, $(STENO_DEBUG)))
Expand Down
1 change: 1 addition & 0 deletions qmk/scsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ void fat_write_block(uint32_t block_no, uint8_t packet_num, uint8_t *data);
#define NUM_FILES 1
#define ROOT_DIR_CLUSTERS 1
#define PACKETS_PER_BLOCK (BLOCK_SIZE / EPSIZE)
#define PACKETS_PER_CLUSTER (PACKETS_PER_BLOCK * BLOCKS_PER_CLUSTER)

#define FILE_BLOCKS (FILE_SIZE / BLOCK_SIZE)
#define FILE_CLUSTERS (FILE_BLOCKS / BLOCKS_PER_CLUSTER)
Expand Down
9 changes: 9 additions & 0 deletions qmk/steno.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#ifndef STENO_NOUI
#include "disp.h"
#endif
#ifdef STENO_FLASH_LOGGING
#include "flog.h"
#endif

bool flashing = false;
char last_trans[128];
Expand All @@ -29,6 +32,9 @@ void ebd_steno_process_stroke(const uint32_t stroke) {
time = timer_read();
#endif
_ebd_steno_process_stroke(stroke);
#ifdef STENO_FLASH_LOGGING
flog_finish_cycle();
#endif
}

void _ebd_steno_process_stroke(const uint32_t stroke) {
Expand Down Expand Up @@ -131,4 +137,7 @@ void ebd_steno_init(void) { // to avoid clashing with `steno_init` in QMK
#ifndef STENO_NOUI
disp_init();
#endif
#ifdef STENO_FLASH_LOGGING
flog_init();
#endif
}
2 changes: 2 additions & 0 deletions qmk/stroke.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#define FREEMAP_START 0xF00000
#define SCRATCH_START 0xF22000
#define ORTHOGRAPHY_START 0xF30000
#define FLOG_START 0xF80000
#define STORE_END 0x1000000

#define BUCKET_GET_ENTRY_LEN(e) ((e >> 24) & 0xFF)
#define BUCKET_GET_STROKES_LEN(e) (e & 0x0F)
Expand Down

0 comments on commit 77172fe

Please sign in to comment.