Skip to content

Commit

Permalink
add support for new custom LCD
Browse files Browse the repository at this point in the history
  • Loading branch information
joeycastillo committed Jul 17, 2024
1 parent 7930e84 commit 7f0dac8
Show file tree
Hide file tree
Showing 4 changed files with 288 additions and 6 deletions.
7 changes: 7 additions & 0 deletions watch-library/hardware/watch/watch_slcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,17 @@ void watch_enable_display(void) {
HAL_GPIO_SLCD25_pmuxen(HAL_GPIO_PMUX_B);
HAL_GPIO_SLCD26_pmuxen(HAL_GPIO_PMUX_B);

#ifdef USE_CUSTOM_LCD
// Original famous Casio LCD: 1/3 bias, 1/4 duty with a frame rate of 32 Hz
slcd_init(LCD_PIN_ENABLE, SLCD_BIAS_THIRD, SLCD_DUTY_4_COMMON, SLCD_PRESCALER_DIV64, SLCD_CLOCKDIV_4);
// exact frame rate is: 32768 / (4 * 64 * 4) ≈ 32 Hz
_slcd_framerate = 32;
#else
// Original famous Casio LCD: 1/3 bias, 1/3 duty with a frame rate of ~34 Hz
slcd_init(LCD_PIN_ENABLE, SLCD_BIAS_THIRD, SLCD_DUTY_3_COMMON, SLCD_PRESCALER_DIV64, SLCD_CLOCKDIV_5);
// exact frame rate is: 32768 / (3 * 64 * 5) ≈ 34.13 Hz
_slcd_framerate = 34;
#endif
// calculate the smallest duration we can time before we have to engage the frame counter prescaler bypass
_slcd_fc_min_ms_bypass = 32 * (1000 / _slcd_framerate);

Expand Down
38 changes: 33 additions & 5 deletions watch-library/shared/watch/watch_common_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,31 @@
#include "watch_slcd.h"
#include "watch_common_display.h"

#ifdef USE_CUSTOM_LCD
static const uint32_t IndicatorSegments[] = {
SLCD_SEGID(0, 21), // WATCH_INDICATOR_SIGNAL
SLCD_SEGID(1, 21), // WATCH_INDICATOR_BELL
SLCD_SEGID(3, 21), // WATCH_INDICATOR_PM
SLCD_SEGID(2, 21), // WATCH_INDICATOR_24H
SLCD_SEGID(1, 0), // WATCH_INDICATOR_LAP
SLCD_SEGID(2, 0), // WATCH_INDICATOR_BATTERY
SLCD_SEGID(3, 0), // WATCH_INDICATOR_SLEEP
};
#else
static const uint32_t IndicatorSegments[] = {
SLCD_SEGID(0, 17), // WATCH_INDICATOR_SIGNAL
SLCD_SEGID(0, 16), // WATCH_INDICATOR_BELL
SLCD_SEGID(2, 17), // WATCH_INDICATOR_PM
SLCD_SEGID(2, 16), // WATCH_INDICATOR_24H
SLCD_SEGID(1, 10), // WATCH_INDICATOR_LAP

// Aliases for indicators unavailable on the original F-91W LCD
SLCD_SEGID(1, 10), // WATCH_INDICATOR_BATTERY (same as LAP)
SLCD_SEGID(4, 0), // WATCH_INDICATOR_SLEEP (does not exist, will set in SDATAL4 which is harmless)
};

#endif

void watch_display_character(uint8_t character, uint8_t position) {
// special cases for positions 4 and 6
if (position == 4 || position == 6) {
Expand Down Expand Up @@ -155,11 +172,19 @@ void watch_display_main_line(char *string) {
}

void watch_set_colon(void) {
#ifdef USE_CUSTOM_LCD
watch_set_pixel(0, 0);
#else
watch_set_pixel(1, 16);
#endif
}

void watch_clear_colon(void) {
#ifdef USE_CUSTOM_LCD
watch_clear_pixel(0, 0);
#else
watch_clear_pixel(1, 16);
#endif
}

void watch_set_indicator(WatchIndicatorSegment indicator) {
Expand All @@ -177,9 +202,12 @@ void watch_clear_indicator(WatchIndicatorSegment indicator) {
}

void watch_clear_all_indicators(void) {
watch_clear_pixel(2, 17);
watch_clear_pixel(2, 16);
watch_clear_pixel(0, 17);
watch_clear_pixel(0, 16);
watch_clear_pixel(1, 10);
/// TODO: Optimize this? Can be 3-4 writes to SDATAL registers
watch_clear_indicator(WATCH_INDICATOR_SIGNAL);
watch_clear_indicator(WATCH_INDICATOR_BELL);
watch_clear_indicator(WATCH_INDICATOR_PM);
watch_clear_indicator(WATCH_INDICATOR_24H);
watch_clear_indicator(WATCH_INDICATOR_LAP);
watch_clear_indicator(WATCH_INDICATOR_BATTERY);
watch_clear_indicator(WATCH_INDICATOR_SLEEP);
}
243 changes: 243 additions & 0 deletions watch-library/shared/watch/watch_common_display.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,248 @@ typedef union digit_mapping_t {
uint64_t value;
} digit_mapping_t;

#ifdef USE_CUSTOM_LCD
// Custom extended LCD

// Character set is slightly different since we don't have to work around as much stuff.
static const uint8_t Watch_Character_Set[] =
{
0b00000000, // [space]
0b00000000, // ! (unused)
0b00100010, // "
0b01100011, // # (degree symbol, hash mark doesn't fit)
0b11101101, // $ (S with a downstroke)
0b00000000, // % (unused)
0b00000000, // & (unused)
0b00100000, // '
0b00111001, // (
0b00001111, // )
0b11000000, // * (The + sign for use in position 0)
0b01110000, // + (segments E, F and G; looks like ┣╸)
0b00000100, // ,
0b01000000, // -
0b00001000, // . (same as _, semantically most useful)
0b00010010, // /
0b00111111, // 0
0b00000110, // 1
0b01011011, // 2
0b01001111, // 3
0b01100110, // 4
0b01101101, // 5
0b01111101, // 6
0b00000111, // 7
0b01111111, // 8
0b01101111, // 9
0b00000000, // : (unused)
0b00000000, // ; (unused)
0b01011000, // <
0b01001000, // =
0b01001100, // >
0b01010011, // ?
0b11111111, // @ (all segments on)
0b01110111, // A
0b11001111, // B (with downstroke, only in weekday / seconds)
0b00111001, // C
0b10001111, // D (with downstroke, only in weekday / seconds)
0b01111001, // E
0b01110001, // F
0b00111101, // G
0b01110110, // H
0b10001001, // I (only works in position 0)
0b00001110, // J
0b01110101, // K
0b00111000, // L
0b10110111, // M (only works in position 0)
0b00110111, // N
0b00111111, // O
0b01110011, // P
0b01100111, // Q
0b01010000, // R (lowercase, this is the only capital we can't do)
0b01101101, // S
0b10000001, // T (only works in position 0; set (1, 12) to make it work in position 1)
0b00111110, // U
0b00111110, // V
0b10111110, // W (only works in position 0)
0b01111110, // X
0b01101110, // Y
0b00011011, // Z
0b00111001, // [
0b00100100, // backslash
0b00001111, // ]
0b00100011, // ^
0b00001000, // _
0b00000010, // `
0b01011111, // a
0b01111100, // b
0b01011000, // c
0b01011110, // d
0b01111011, // e
0b01110001, // f
0b01101111, // g
0b01110100, // h
0b00010000, // i
0b00001110, // j
0b01110101, // k
0b00110000, // l
0b10110111, // m (only works in position 0)
0b01010100, // n
0b01011100, // o
0b01110011, // p
0b01100111, // q
0b01010000, // r
0b01101101, // s
0b01111000, // t
0b00011100, // u
0b00011100, // v (looks like u)
0b10111110, // w
0b01111110, // x
0b01101110, // y
0b00011011, // z
0b00010110, // { (open brace doesn't really work; overriden to represent the two character ligature "il")
0b00110110, // | (overriden to represent the two character ligature "ll")
0b00110100, // } (overriden to represent the two character ligature "li")
0b00000001, // ~
};

static const digit_mapping_t Watch_Display_Mapping[] = {
{
.segment = {
{ .address = { .com = 0, .seg = 19 } }, // 0A
{ .address = { .com = 2, .seg = 19 } }, // 0B
{ .address = { .com = 3, .seg = 19 } }, // 0C
{ .address = { .com = 3, .seg = 20 } }, // 0D
{ .address = { .com = 2, .seg = 20 } }, // 0E
{ .address = { .com = 0, .seg = 20 } }, // 0F
{ .address = { .com = 1, .seg = 20 } }, // 0G
{ .address = { .com = 1, .seg = 19 } }, // 0H
},
},
{
.segment = {
{ .address = { .com = 0, .seg = 17 } }, // 1A
{ .address = { .com = 2, .seg = 17 } }, // 1B
{ .address = { .com = 3, .seg = 17 } }, // 1C
{ .address = { .com = 3, .seg = 18 } }, // 1D
{ .address = { .com = 2, .seg = 18 } }, // 1E
{ .address = { .com = 0, .seg = 18 } }, // 1F
{ .address = { .com = 1, .seg = 18 } }, // 1G
{ .address = { .com = 1, .seg = 17 } }, // 1H
},
},
{
.segment = {
{ .address = { .com = 0, .seg = 11 } }, // 2A
{ .address = { .com = 0, .seg = 10 } }, // 2B
{ .address = { .com = 2, .seg = 10 } }, // 2C
{ .address = { .com = 3, .seg = 11 } }, // 2D
{ .address = { .com = 2, .seg = 11 } }, // 2E
{ .address = { .com = 1, .seg = 11 } }, // 2F
{ .address = { .com = 1, .seg = 10 } }, // 2G
{ .value = segment_does_not_exist }, // 2H
},
},
{
.segment = {
{ .address = { .com = 0, .seg = 9 } }, // 3A
{ .address = { .com = 0, .seg = 8 } }, // 3B
{ .address = { .com = 2, .seg = 8 } }, // 3C
{ .address = { .com = 3, .seg = 9 } }, // 3D
{ .address = { .com = 2, .seg = 9 } }, // 3E
{ .address = { .com = 1, .seg = 9 } }, // 3F
{ .address = { .com = 1, .seg = 8 } }, // 3G
{ .value = segment_does_not_exist }, // 3H
},
},
{
.segment = {
{ .address = { .com = 3, .seg = 16 } }, // 4A
{ .address = { .com = 2, .seg = 16 } }, // 4B
{ .address = { .com = 1, .seg = 16 } }, // 4C
{ .address = { .com = 0, .seg = 16 } }, // 4D
{ .address = { .com = 1, .seg = 22 } }, // 4E
{ .address = { .com = 3, .seg = 22 } }, // 4F
{ .address = { .com = 2, .seg = 22 } }, // 4G
{ .value = segment_does_not_exist }, // 4H
},
},
{
.segment = {
{ .address = { .com = 3, .seg = 14 } }, // 5A
{ .address = { .com = 2, .seg = 14 } }, // 5B
{ .address = { .com = 1, .seg = 14 } }, // 5C
{ .address = { .com = 0, .seg = 15 } }, // 5D
{ .address = { .com = 1, .seg = 15 } }, // 5E
{ .address = { .com = 3, .seg = 15 } }, // 5F
{ .address = { .com = 2, .seg = 15 } }, // 5G
{ .value = segment_does_not_exist }, // 5H
},
},
{
.segment = {
{ .address = { .com = 3, .seg = 1 } }, // 6A
{ .address = { .com = 2, .seg = 2 } }, // 6B
{ .address = { .com = 0, .seg = 2 } }, // 6C
{ .address = { .com = 0, .seg = 1 } }, // 6D
{ .address = { .com = 1, .seg = 1 } }, // 6E
{ .address = { .com = 2, .seg = 1 } }, // 6F
{ .address = { .com = 1, .seg = 2 } }, // 6G
{ .value = segment_does_not_exist }, // 6H
},
},
{
.segment = {
{ .address = { .com = 3, .seg = 3 } }, // 7A
{ .address = { .com = 2, .seg = 4 } }, // 7B
{ .address = { .com = 0, .seg = 4 } }, // 7C
{ .address = { .com = 0, .seg = 3 } }, // 7D
{ .address = { .com = 1, .seg = 3 } }, // 7E
{ .address = { .com = 2, .seg = 3 } }, // 7F
{ .address = { .com = 1, .seg = 4 } }, // 7G
{ .value = segment_does_not_exist }, // 7H
},
},
{
.segment = {
{ .address = { .com = 3, .seg = 10 } }, // 8A
{ .address = { .com = 3, .seg = 8 } }, // 8B
{ .address = { .com = 0, .seg = 5 } }, // 8C
{ .address = { .com = 1, .seg = 5 } }, // 8D
{ .address = { .com = 3, .seg = 4 } }, // 8E
{ .address = { .com = 3, .seg = 2 } }, // 8F
{ .address = { .com = 2, .seg = 5 } }, // 8G
{ .address = { .com = 3, .seg = 5 } }, // 8H
},
},
{
.segment = {
{ .address = { .com = 3, .seg = 6 } }, // 9A
{ .address = { .com = 3, .seg = 7 } }, // 9B
{ .address = { .com = 2, .seg = 7 } }, // 9C
{ .address = { .com = 0, .seg = 7 } }, // 9D
{ .address = { .com = 0, .seg = 6 } }, // 9E
{ .address = { .com = 2, .seg = 6 } }, // 9F
{ .address = { .com = 1, .seg = 6 } }, // 9G
{ .address = { .com = 1, .seg = 7 } }, // 9H
},
},
// Position 10 is the third digit in the weekday, stashed at the end for backwards compatibility.
{
.segment = {
{ .address = { .com = 0, .seg = 12 } }, // 10A
{ .address = { .com = 2, .seg = 12 } }, // 10B
{ .address = { .com = 3, .seg = 12 } }, // 10C
{ .address = { .com = 3, .seg = 13 } }, // 10D
{ .address = { .com = 2, .seg = 13 } }, // 10E
{ .address = { .com = 0, .seg = 13 } }, // 10F
{ .address = { .com = 1, .seg = 13 } }, // 10G
{ .address = { .com = 1, .seg = 12 } }, // 10H
},
},
};

#else

// Original famous Casio LCD
static const uint8_t Watch_Character_Set[] =
{
0b00000000, //
Expand Down Expand Up @@ -266,6 +508,7 @@ static const digit_mapping_t Watch_Display_Mapping[] = {
},
},
};
#endif

void watch_display_character(uint8_t character, uint8_t position);
void watch_display_character_lp_seconds(uint8_t character, uint8_t position);
6 changes: 5 additions & 1 deletion watch-library/shared/watch/watch_slcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ typedef enum WatchIndicatorSegment {
WATCH_INDICATOR_BELL, ///< The small bell indicating that an alarm is set.
WATCH_INDICATOR_PM, ///< The PM indicator, indicating that a time is in the afternoon.
WATCH_INDICATOR_24H, ///< The 24H indicator, indicating that the watch is in a 24-hour mode.
WATCH_INDICATOR_LAP ///< The LAP indicator; the F-91W uses this in its stopwatch UI.
WATCH_INDICATOR_LAP, ///< The LAP indicator; the F-91W uses this in its stopwatch UI.

// These next indicators are only available on the new custom LCD:
WATCH_INDICATOR_BATTERY, ///< The battery indicator. Will fall back to the LAP icon on the original F-91W LCD.
WATCH_INDICATOR_SLEEP, ///< The sleep indicator. No fallback here; use the tick animation to indicate sleep.
} WatchIndicatorSegment;

/** @brief Enables the Segment LCD display.
Expand Down

0 comments on commit 7f0dac8

Please sign in to comment.