diff --git a/KeywordHasher.h b/KeywordHasher.h index 4b1e0fb..fe85eb4 100644 --- a/KeywordHasher.h +++ b/KeywordHasher.h @@ -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 \ No newline at end of file diff --git a/Release - Architecture Doc/TM1638.md b/Release_Notes/TM1638.md similarity index 76% rename from Release - Architecture Doc/TM1638.md rename to Release_Notes/TM1638.md index a9b1660..adec7ae 100644 --- a/Release - Architecture Doc/TM1638.md +++ b/Release_Notes/TM1638.md @@ -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.