diff --git a/Makefile b/Makefile index f74237b4..200002a3 100644 --- a/Makefile +++ b/Makefile @@ -18,8 +18,10 @@ SRCS += \ ./watch-library/hardware/watch/watch_buzzer.c \ ./watch-library/hardware/watch/watch_led.c \ ./watch-library/hardware/watch/watch_private.c \ + ./watch-library/hardware/watch/watch_slcd.c \ ./watch-library/hardware/watch/watch_usb_descriptors.c \ ./watch-library/hardware/watch/watch_usb_cdc.c \ + ./watch-library/shared/watch/watch_private_display.c \ INCLUDES += \ -I./tinyusb/src \ diff --git a/app.c b/app.c index ac38d5d5..6ba96030 100644 --- a/app.c +++ b/app.c @@ -49,18 +49,18 @@ void app_init(void) { } void app_setup(void) { - watch_enable_leds(); + watch_enable_display(); + watch_display_top_left("MO"); + watch_display_top_right("15"); + watch_display_main_line("123456"); + watch_set_colon(); + watch_set_indicator(WATCH_INDICATOR_PM); } bool app_loop(void) { - watch_set_led_yellow(); - delay_ms(500); - watch_set_led_off(); - delay_ms(500); - if (usb_is_enabled()) { yield(); } - return false; + return true; } diff --git a/watch-library/hardware/watch/watch_slcd.c b/watch-library/hardware/watch/watch_slcd.c new file mode 100644 index 00000000..2c6f2eac --- /dev/null +++ b/watch-library/hardware/watch/watch_slcd.c @@ -0,0 +1,137 @@ +/* + * MIT License + * + * Copyright (c) 2020-2024 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "pins.h" +#include "watch_slcd.h" +#include "watch_private_display.h" +#include "slcd.h" + + ////////////////////////////////////////////////////////////////////////////////////////// +// Segmented Display + +static uint16_t _slcd_framerate = 0; +static uint16_t _slcd_fc_min_ms_bypass = 0; + +void watch_enable_display(void) { + HAL_GPIO_SLCD0_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD1_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD2_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD3_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD4_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD5_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD6_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD7_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD8_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD9_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD10_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD11_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD12_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD13_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD14_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD15_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD16_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD17_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD18_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD19_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD20_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD21_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD22_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD23_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD24_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD25_pmuxen(HAL_GPIO_PMUX_B); + HAL_GPIO_SLCD26_pmuxen(HAL_GPIO_PMUX_B); + + // 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; + // 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); + + slcd_clear(); + slcd_set_contrast(6); + slcd_enable(); +} + +inline void watch_set_pixel(uint8_t com, uint8_t seg) { + slcd_set_segment(com, seg); +} + +inline void watch_clear_pixel(uint8_t com, uint8_t seg) { + slcd_clear_segment(com, seg); +} + +void watch_clear_display(void) { + slcd_clear(); +} + +void watch_start_character_blink(char character, uint32_t duration) { + slcd_set_frame_counter_enabled(0, false); + + if (duration <= _slcd_fc_min_ms_bypass) { + slcd_configure_frame_counter(0, (duration / (1000 / _slcd_framerate)) - 1, false); + } else { + slcd_configure_frame_counter(0, ((duration / (1000 / _slcd_framerate)) / 8 - 1), true); + } + slcd_set_frame_counter_enabled(0, true); + + watch_display_character(character, 7); + watch_clear_pixel(2, 10); // clear segment B of position 7 since it can't blink + + slcd_set_blink_enabled(false); + slcd_configure_blink(false, 0x07, 0x07, 0); + slcd_set_blink_enabled(true); +} + +void watch_stop_blink(void) { + slcd_set_frame_counter_enabled(0, false); + slcd_set_blink_enabled(false); +} + +void watch_start_tick_animation(uint32_t duration) { + watch_display_character(' ', 8); + + slcd_set_frame_counter_enabled(1, false); + slcd_set_circular_shift_animation_enabled(false); + + if (duration <= _slcd_fc_min_ms_bypass) { + slcd_configure_frame_counter(1, (duration / (1000 / _slcd_framerate)) - 1, false); + } else { + slcd_configure_frame_counter(1, ((duration / (1000 / _slcd_framerate)) / 8 - 1), true); + } + slcd_set_frame_counter_enabled(1, true); + + slcd_configure_circular_shift_animation(0b00000001, 2, SLCD_CSRSHIFT_LEFT, 1); + slcd_set_circular_shift_animation_enabled(true); +} + +bool watch_tick_animation_is_running(void) { + // TODO: wrap this in gossamer call + return SLCD->CTRLD.bit.CSREN; +} + +void watch_stop_tick_animation(void) { + slcd_set_circular_shift_animation_enabled(false); + watch_display_character(' ', 8); +} diff --git a/watch-library/shared/watch/watch.h b/watch-library/shared/watch/watch.h index 6edc3340..6a41c181 100644 --- a/watch-library/shared/watch/watch.h +++ b/watch-library/shared/watch/watch.h @@ -61,7 +61,7 @@ typedef void (*watch_cb_t)(void); // #include "watch_rtc.h" -// #include "watch_slcd.h" +#include "watch_slcd.h" // #include "watch_extint.h" #include "watch_led.h" #include "watch_buzzer.h" diff --git a/watch-library/shared/watch/watch_private_display.c b/watch-library/shared/watch/watch_private_display.c new file mode 100644 index 00000000..91ba50f4 --- /dev/null +++ b/watch-library/shared/watch/watch_private_display.c @@ -0,0 +1,185 @@ +/* + * MIT License + * + * Copyright (c) 2020 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "watch_slcd.h" +#include "watch_private_display.h" + +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 +}; + +void watch_display_character(uint8_t character, uint8_t position) { + // special cases for positions 4 and 6 + if (position == 4 || position == 6) { + if (character == '7') character = '&'; // "lowercase" 7 + else if (character == 'A') character = 'a'; // A needs to be lowercase + else if (character == 'o') character = 'O'; // O needs to be uppercase + else if (character == 'L') character = '!'; // L needs to be in top half + else if (character == 'M' || character == 'm' || character == 'N') character = 'n'; // M and uppercase N need to be lowercase n + else if (character == 'c') character = 'C'; // C needs to be uppercase + else if (character == 'J') character = 'j'; // same + else if (character == 'v' || character == 'V' || character == 'U' || character == 'W' || character == 'w') character = 'u'; // bottom segment duplicated, so show in top half + } else { + if (character == 'u') character = 'v'; // we can use the bottom segment; move to lower half + else if (character == 'j') character = 'J'; // same but just display a normal J + } + if (position > 1) { + if (character == 'T') character = 't'; // uppercase T only works in positions 0 and 1 + } + if (position == 1) { + if (character == 'a') character = 'A'; // A needs to be uppercase + else if (character == 'o') character = 'O'; // O needs to be uppercase + else if (character == 'i') character = 'l'; // I needs to be uppercase (use an l, it looks the same) + else if (character == 'n') character = 'N'; // N needs to be uppercase + else if (character == 'r') character = 'R'; // R needs to be uppercase + else if (character == 'd') character = 'D'; // D needs to be uppercase + else if (character == 'v' || character == 'V' || character == 'u') character = 'U'; // side segments shared, make uppercase + else if (character == 'b') character = 'B'; // B needs to be uppercase + else if (character == 'c') character = 'C'; // C needs to be uppercase + } else { + if (character == 'R') character = 'r'; // R needs to be lowercase almost everywhere + } + if (position == 0) { + watch_clear_pixel(0, 15); // clear funky ninth segment + } else { + if (character == 'I') character = 'l'; // uppercase I only works in position 0 + } + + uint64_t segmap = Segment_Map[position]; + uint64_t segdata = Character_Set[character - 0x20]; + + for (int i = 0; i < 8; i++) { + uint8_t com = (segmap & 0xFF) >> 6; + if (com > 2) { + // COM3 means no segment exists; skip it. + segmap = segmap >> 8; + segdata = segdata >> 1; + continue; + } + uint8_t seg = segmap & 0x3F; + + if (segdata & 1) + watch_set_pixel(com, seg); + else + watch_clear_pixel(com, seg); + + segmap = segmap >> 8; + segdata = segdata >> 1; + } + + if (character == 'T' && position == 1) watch_set_pixel(1, 12); // add descender + else if (position == 0 && (character == 'B' || character == 'D' || character == '@')) watch_set_pixel(0, 15); // add funky ninth segment + else if (position == 1 && (character == 'B' || character == 'D' || character == '@')) watch_set_pixel(0, 12); // add funky ninth segment +} + +void watch_display_character_lp_seconds(uint8_t character, uint8_t position) { + // Will only work for digits and for positions 8 and 9 - but less code & checks to reduce power consumption + + uint64_t segmap = Segment_Map[position]; + uint64_t segdata = Character_Set[character - 0x20]; + + for (int i = 0; i < 8; i++) { + uint8_t com = (segmap & 0xFF) >> 6; + if (com > 2) { + // COM3 means no segment exists; skip it. + segmap = segmap >> 8; + segdata = segdata >> 1; + continue; + } + uint8_t seg = segmap & 0x3F; + + if (segdata & 1) + watch_set_pixel(com, seg); + else + watch_clear_pixel(com, seg); + + segmap = segmap >> 8; + segdata = segdata >> 1; + } +} + +void watch_display_string(char *string, uint8_t position) { + size_t i = 0; + while(string[i] != 0) { + watch_display_character(string[i], position + i); + i++; + if (position + i >= 10) break; + } +} + +void watch_display_top_left(char *string) { + watch_display_character(string[0], 0); + if (string[1]) { + watch_display_character(string[1], 1); + } +} + +void watch_display_top_right(char *string) { + watch_display_character(string[0], 2); + if (string[1]) { + watch_display_character(string[1], 3); + } +} + +void watch_display_main_line(char *string) { + int i = 0; + while (string[i] != 0) { + watch_display_character(string[i], 4 + i); + i++; + } +} + +void watch_set_colon(void) { + watch_set_pixel(1, 16); +} + +void watch_clear_colon(void) { + watch_clear_pixel(1, 16); +} + +void watch_set_indicator(WatchIndicatorSegment indicator) { + uint32_t value = IndicatorSegments[indicator]; + uint8_t com = SLCD_COMNUM(value); + uint8_t seg = SLCD_SEGNUM(value); + watch_set_pixel(com, seg); +} + +void watch_clear_indicator(WatchIndicatorSegment indicator) { + uint32_t value = IndicatorSegments[indicator]; + uint8_t com = SLCD_COMNUM(value); + uint8_t seg = SLCD_SEGNUM(value); + watch_clear_pixel(com, seg); +} + +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); +} diff --git a/watch-library/shared/watch/watch_private_display.h b/watch-library/shared/watch/watch_private_display.h new file mode 100644 index 00000000..e059b33f --- /dev/null +++ b/watch-library/shared/watch/watch_private_display.h @@ -0,0 +1,139 @@ +/* + * MIT License + * + * Copyright (c) 2020 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#pragma once + +static const uint8_t Character_Set[] = +{ + 0b00000000, // + 0b01100000, // ! (L in the top half for positions 4 and 6) + 0b00100010, // " + 0b01100011, // # (degree symbol, hash mark doesn't fit) + 0b00101101, // $ (S without the center segment) + 0b00000000, // % (unused) + 0b01000100, // & ("lowercase 7" for positions 4 and 6) + 0b00100000, // ' + 0b00111001, // ( + 0b00001111, // ) + 0b11000000, // * (The + sign for use in position 0) + 0b01110000, // + (segments E, F and G; looks like ┣╸) + 0b00000100, // , + 0b01000000, // - + 0b01000000, // . (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 + 0b01111111, // B + 0b00111001, // C + 0b00111111, // D + 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 + 0b11110111, // R (only works in position 1) + 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 + 0b01000010, // j (appears as superscript to work in more positions) + 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 + 0b01100010, // u (appears in (u)pper half to work in more positions) + 0b00011100, // v (looks like u but in the lower half) + 0b10111110, // w (only works in position 0) + 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 uint64_t Segment_Map[] = { + 0x4e4f0e8e8f8d4d0d, // Position 0, mode + 0xc8c4c4c8b4b4b0b, // Position 1, mode (Segments B and C shared, as are segments E and F) + 0xc049c00a49890949, // Position 2, day of month (Segments A, D, G shared; missing segment F) + 0xc048088886874707, // Position 3, day of month + 0xc053921252139352, // Position 4, clock hours (Segments A and D shared) + 0xc054511415559594, // Position 5, clock hours + 0xc057965616179716, // Position 6, clock minutes (Segments A and D shared) + 0xc041804000018a81, // Position 7, clock minutes + 0xc043420203048382, // Position 8, clock seconds + 0xc045440506468584, // Position 9, clock seconds +}; + +void watch_display_character(uint8_t character, uint8_t position); +void watch_display_character_lp_seconds(uint8_t character, uint8_t position); diff --git a/watch-library/shared/watch/watch_slcd.h b/watch-library/shared/watch/watch_slcd.h new file mode 100644 index 00000000..83811366 --- /dev/null +++ b/watch-library/shared/watch/watch_slcd.h @@ -0,0 +1,175 @@ +/* + * MIT License + * + * Copyright (c) 2020 Joey Castillo + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +////< @file watch_slcd.h + +#include "watch.h" + +/** @addtogroup slcd Segment LCD Display + * @brief This section covers functions related to the Segment LCD display driver, which is responsible + * for displaying strings of characters and indicators on the main watch display. + * @details The segment LCD controller consumes about 3 microamperes of power with no segments on, and + * about 4 microamperes with all segments on. There is also a slight power impact associated + * with updating the screen (about 1 microampere to update at 1 Hz). For the absolute lowest + * power operation, update the display only when its contents have changed, and disable the + * SLCD peripheral when the screen is not in use. + * For a map of all common and segment pins, see segmap.html. You can + * hover over any segment in that diagram to view the common and segment pins associated with + * each segment of the display. + */ +/// @{ + +#define SLCD_SEGID(com, seg) (((com) << 16) | (seg)) +#define SLCD_COMNUM(segid) (((segid) >> 16) & 0xFF) +#define SLCD_SEGNUM(segid) ((segid)&0xFF) + +/// An enum listing the icons and indicators available on the watch. +typedef enum WatchIndicatorSegment { + WATCH_INDICATOR_SIGNAL = 0, ///< The hourly signal indicator; also useful for indicating that sensors are on. + 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. +} WatchIndicatorSegment; + +/** @brief Enables the Segment LCD display. + * Call this before attempting to set pixels or display strings. + */ +void watch_enable_display(void); + +/** @brief Sets a pixel. Use this to manually set a pixel with a given common and segment number. + * See segmap.html. + * @param com the common pin, numbered from 0-2. + * @param seg the segment pin, numbered from 0-23. + */ +void watch_set_pixel(uint8_t com, uint8_t seg); + +/** @brief Clears a pixel. Use this to manually clear a pixel with a given common and segment number. + * See segmap.html. + * @param com the common pin, numbered from 0-2. + * @param seg the segment pin, numbered from 0-23. + */ +void watch_clear_pixel(uint8_t com, uint8_t seg); + +/** @brief Clears all segments of the display, including incicators and the colon. + */ +void watch_clear_display(void); + +/** @brief Displays a string at the given position, starting from the top left. There are ten digits. + A space in any position will clear that digit. + * @deprecated This function is deprecated. Use + * @param string A null-terminated string. + * @param position The position where you wish to start displaying the string. The day of week digits + * are positions 0 and 1; the day of month digits are positions 2 and 3, and the main + * clock line occupies positions 4-9. + * @note This method does not clear the display; if for example you display a two-character string at + position 0, positions 2-9 will retain whatever state they were previously displaying. + */ +void watch_display_string(char *string, uint8_t position) __attribute__ ((deprecated("Use watch_display_top_left, watch_display_top_right and watch_display_main_line instead."))); + +/** + * @brief Displays a string at in the digits at the top left, which typically show the day of the week. + * @param string A null-terminated string with two characters to display. + */ +void watch_display_top_left(char *string); + +/** + * @brief Displays a string in the digits at the top right, which typically show the day of the month. + * @param string A null-terminated string with two characters to display. + */ +void watch_display_top_right(char *string); + +/** + * @brief Displays a string in the main line of the display, which typically shows the time. + * @param string A null-terminated string with six characters to display. Omit the colon; if you want + * the colon to appear, use watch_set_colon() to turn it on. + */ +void watch_display_main_line(char *string); + +/** @brief Turns the colon segment on. + */ +void watch_set_colon(void); + +/** @brief Turns the colon segment off. + */ +void watch_clear_colon(void); + +/** @brief Sets an indicator on the LCD. Use this to turn on one of the indicator segments. + * @param indicator One of the indicator segments from the enum. @see WatchIndicatorSegment + */ +void watch_set_indicator(WatchIndicatorSegment indicator); + +/** @brief Clears an indicator on the LCD. Use this to turn off one of the indicator segments. + * @param indicator One of the indicator segments from the enum. @see WatchIndicatorSegment + */ +void watch_clear_indicator(WatchIndicatorSegment indicator); + +/** @brief Clears all indicator segments. + * @see WatchIndicatorSegment + */ +void watch_clear_all_indicators(void); + +/** @brief Blinks a single character in position 7. Does not affect other positions. + * @details Six of the seven segments in position 7 (and only position 7) are capable of autonomous + * blinking. This blinking does not require any CPU resources, and will continue even in + * STANDBY and Sleep mode (but not Deep Sleep mode, since that mode turns off the LCD). + * @param character The character you wish to blink. + * @param duration The duration of the on/off cycle in milliseconds, from 50 to ~4250 ms. + * @note Segment B of position 7 cannot blink autonomously, so not all characters will work well. + * Supported characters for blinking: + * * Punctuation: underscore, apostrophe, comma, hyphen, equals sign, tilde (top segment only) + * * Numbers: 5, 6, ampersand (lowercase 7) + * * Letters: b, C, c, E, F, h, i, L, l, n, o, S, t + */ +void watch_start_character_blink(char character, uint32_t duration); + +/** @brief Stops and clears all blinking segments. + * @details This will stop all blinking in position 7, and clear all segments in that digit. + */ +void watch_stop_blink(void); + +/** @brief Begins a two-segment "tick-tock" animation in position 8. + * @details Six of the seven segments in position 8 (and only position 8) are capable of autonomous + * animation. This animation is very basic, and consists of moving a bit pattern forward + * or backward in a shift register whose positions map to fixed segments on the LCD. Given + * this constraint, an animation across all six segments does not make sense; so the watch + * library offers only a simple "tick/tock" in segments D and E. This animation does not + * require any CPU resources, and will continue even in STANDBY and Sleep mode (but not Deep + * Sleep mode, since that mode turns off the LCD). + * @param duration The duration of each frame in ms. 500 milliseconds produces a classic tick/tock. + */ +void watch_start_tick_animation(uint32_t duration); + +/** @brief Checks if the tick animation is currently running. + * @return true if the animation is running; false otherwise. + */ +bool watch_tick_animation_is_running(void); + +/** @brief Stops the tick/tock animation and clears all animating segments. + * @details This will stop the animation and clear all segments in position 8. + */ +void watch_stop_tick_animation(void); +/// @}