Skip to content

Commit

Permalink
_s7 keyword generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Asbelos committed Oct 10, 2024
1 parent 8a7dc26 commit f138241
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
39 changes: 39 additions & 0 deletions KeywordHasher.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,43 @@ static_assert("MAIN"_hk == 11339,"Keyword hasher error");
static_assert("SLOW"_hk == -17209,"Keyword hasher error");
static_assert("SPEED28"_hk == -17064,"Keyword hasher error");
static_assert("SPEED128"_hk == 25816,"Keyword hasher error");

// Compile time converter from "abcd"_s7 to the 7 segment nearest equivalent

constexpr uint8_t seg7Digits[]={
0b00111111,0b00000110,0b01011011,0b01001111, // 0..3
0b01100110,0b01101101,0b01111101,0b00000111, // 4..7
0b01111111,0b01101111 // 8..9
};

constexpr uint8_t seg7Letters[]={
0b01110111,0b01111100,0b00111001,0b01011110, // ABCD
0b01111001,0b01110001,0b00111101,0b01110110, // EFGH
0b00000100,0b00011110,0b01110010,0b00111000, //IJKL
0b01010101,0b01010100,0b01011100,0b01110011, // MNOP
0b10111111,0b01010000,0b01101101,0b01111000, // QRST
0b00111110,0b00011100,0b01101010,0b01001001, //UVWX
0b01100110,0b01011011 //YZ
};
constexpr uint8_t seg7Space=0b00000000;
constexpr uint8_t seg7Minus=0b01000000;
constexpr uint8_t seg7Equals=0b01001000;


constexpr uint32_t CompiletimeSeg7(const char * sv, uint32_t running, size_t rlen) {
return (*sv==0 || rlen==0) ? running << (8*rlen) : CompiletimeSeg7(sv+1,
(*sv >= '0' && *sv <= '9') ? (running<<8) | seg7Digits[*sv-'0'] :
(*sv >= 'A' && *sv <= 'Z') ? (running<<8) | seg7Letters[*sv-'A'] :
(*sv >= 'a' && *sv <= 'z') ? (running<<8) | seg7Letters[*sv-'a'] :
(*sv == '-') ? (running<<8) | seg7Minus :
(*sv == '=') ? (running<<8) | seg7Equals :
(running<<8) | seg7Space,
rlen-1
); //
}

constexpr uint32_t operator""_s7(const char * keyword, size_t len)
{
return CompiletimeSeg7(keyword,0*len,4);
}
#endif
22 changes: 20 additions & 2 deletions Release - Architecture Doc/TM1638.md → Release_Notes/TM1638.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,24 @@ Format values:
SEG7(500,0xdeadbeef,8X)
writes dEAdbEEF to all 8 digits.

(RAW example to follow)
Writing raw segment patters requires knowledge of the bit pattern to segment relationship:
` 0
== 0 ==
5| | 1
== 6 ==
4 | | 2
== 3 ==
7=decimal point

Thus Letter A is segments 6 5 4 2 1 0, in bits that is (0 bit on right)
0b01110111 or 0x77
This is not easy to do my hand and thus a new string type suffix has been introduced to make simple text messages. Note that the HAL interface only has width for 32 bits which is only 4 symbols so writing 8 digits requires two calls.

e.g. SEG7(500,"Hell"_s7,4R) SEG7(504,"o"_s7,4R)
DELAY(1000)
SEG7(500,"Worl"_s7,4R) SEG7(504,"d"_s7,4R)

Note that some letters like k,m,v,x do not have particularly readable 7-segment representations.
Credit to https://github.com/dvarrel/TM1638 for the basic formulae.

0 comments on commit f138241

Please sign in to comment.