You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

697 lines
22 KiB

OLED driver fixes (#10377) * Fix dirtying in oled_write_pixel() Set the dirty bit for the block only if oled_write_pixel() actually changed the buffer state. Without this check oled_write_pixel() could not be used inside the oled_task_user() code using the “redraw always” style, because the blocks touched by oled_write_pixel() would always appear dirty, and oled_render() would not proceed beyond the first such dirty block. * Fix oled_write_pixel() with 90/270 degree rotation Use oled_rotation_width instead of OLED_DISPLAY_WIDTH, so that a rotated display would be handled correctly. * Fix compilation with custom OLED_BLOCK_COUNT and OLED_BLOCK_SIZE Some OLED sizes (e.g., 64×48) may require a nonstandard value of OLED_BLOCK_COUNT. The documentation says that this value may be redefined in config.h, but actually trying to redefine it caused a compile error, because the macro was redefined in oled_driver.c. Make the OLED_BLOCK_COUNT definition in oled_driver.c respect any user override, and do the same for OLED_BLOCK_SIZE just in case. * Fix handling of out-of-range bits in oled_dirty If a custom OLED_BLOCK_COUNT value is specified, some bits in oled_dirty may not correspond to existing blocks; however, if those bits are set somewhere (e.g., by code with sets oled_dirty to ~0 or even -1), oled_render() would try to handle them and could access memory beyond oled_buffer and perform hardware operations with out of range values. Prevent this by masking off unused bits in oled_render(), and also avoid setting those bits in other functions. * Fix potentially wrong dirtying in oled_write_char() oled_write_char() tried to mark the position just beyond the written character as dirty; use (OLED_FONT_WIDTH - 1) to dirty the last position still belonging to the character instead. * Fix `#define OLED_BLOCK_TYPE uint32_t` on AVR Using uint32_t as OLED_BLOCK_TYPE did not work properly on AVR, because some bit shifts were performed using 16-bit int. Add explicit casts to OLED_BLOCK_TYPE to those shifts.
3 years ago
2020 November 28 Breaking Changes Update (#11053) * Branch point for 2020 November 28 Breaking Change * Remove matrix_col_t to allow MATRIX_ROWS > 32 (#10183) * Add support for soft serial to ATmega32U2 (#10204) * Change MIDI velocity implementation to allow direct control of velocity value (#9940) * Add ability to build a subset of all keyboards based on platform. * Actually use eeprom_driver_init(). * Make bootloader_jump weak for ChibiOS. (#10417) * Joystick 16-bit support (#10439) * Per-encoder resolutions (#10259) * Share button state from mousekey to pointing_device (#10179) * Add hotfix for chibios keyboards not wake (#10088) * Add advanced/efficient RGB Matrix Indicators (#8564) * Naming change. * Support for STM32 GPIOF,G,H,I,J,K (#10206) * Add milc as a dependency and remove the installed milc (#10563) * ChibiOS upgrade: early init conversions (#10214) * ChibiOS upgrade: configuration file migrator (#9952) * Haptic and solenoid cleanup (#9700) * XD75 cleanup (#10524) * OLED display update interval support (#10388) * Add definition based on currently-selected serial driver. (#10716) * New feature: Retro Tapping per key (#10622) * Allow for modification of output RGB values when using rgblight/rgb_matrix. (#10638) * Add housekeeping task callbacks so that keyboards/keymaps are capable of executing code for each main loop iteration. (#10530) * Rescale both ChibiOS and AVR backlighting. * Reduce Helix keyboard build variation (#8669) * Minor change to behavior allowing display updates to continue between task ticks (#10750) * Some GPIO manipulations in matrix.c change to atomic. (#10491) * qmk cformat (#10767) * [Keyboard] Update the Speedo firmware for v3.0 (#10657) * Maartenwut/Maarten namechange to evyd13/Evy (#10274) * [quantum] combine repeated lines of code (#10837) * Add step sequencer feature (#9703) * aeboards/ext65 refactor (#10820) * Refactor xelus/dawn60 for Rev2 later (#10584) * add DEBUG_MATRIX_SCAN_RATE_ENABLE to common_features.mk (#10824) * [Core] Added `add_oneshot_mods` & `del_oneshot_mods` (#10549) * update chibios os usb for the otg driver (#8893) * Remove HD44780 References, Part 4 (#10735) * [Keyboard] Add Valor FRL TKL (+refactor) (#10512) * Fix cursor position bug in oled_write_raw functions (#10800) * Fixup version.h writing when using SKIP_VERSION=yes (#10972) * Allow for certain code in the codebase assuming length of string. (#10974) * Add AT90USB support for serial.c (#10706) * Auto shift: support repeats and early registration (#9826) * Rename ledmatrix.h to match .c file (#7949) * Split RGB_MATRIX_ENABLE into _ENABLE and _DRIVER (#10231) * Split LED_MATRIX_ENABLE into _ENABLE and _DRIVER (#10840) * Merge point for 2020 Nov 28 Breaking Change
3 years ago
OLED driver fixes (#10377) * Fix dirtying in oled_write_pixel() Set the dirty bit for the block only if oled_write_pixel() actually changed the buffer state. Without this check oled_write_pixel() could not be used inside the oled_task_user() code using the “redraw always” style, because the blocks touched by oled_write_pixel() would always appear dirty, and oled_render() would not proceed beyond the first such dirty block. * Fix oled_write_pixel() with 90/270 degree rotation Use oled_rotation_width instead of OLED_DISPLAY_WIDTH, so that a rotated display would be handled correctly. * Fix compilation with custom OLED_BLOCK_COUNT and OLED_BLOCK_SIZE Some OLED sizes (e.g., 64×48) may require a nonstandard value of OLED_BLOCK_COUNT. The documentation says that this value may be redefined in config.h, but actually trying to redefine it caused a compile error, because the macro was redefined in oled_driver.c. Make the OLED_BLOCK_COUNT definition in oled_driver.c respect any user override, and do the same for OLED_BLOCK_SIZE just in case. * Fix handling of out-of-range bits in oled_dirty If a custom OLED_BLOCK_COUNT value is specified, some bits in oled_dirty may not correspond to existing blocks; however, if those bits are set somewhere (e.g., by code with sets oled_dirty to ~0 or even -1), oled_render() would try to handle them and could access memory beyond oled_buffer and perform hardware operations with out of range values. Prevent this by masking off unused bits in oled_render(), and also avoid setting those bits in other functions. * Fix potentially wrong dirtying in oled_write_char() oled_write_char() tried to mark the position just beyond the written character as dirty; use (OLED_FONT_WIDTH - 1) to dirty the last position still belonging to the character instead. * Fix `#define OLED_BLOCK_TYPE uint32_t` on AVR Using uint32_t as OLED_BLOCK_TYPE did not work properly on AVR, because some bit shifts were performed using 16-bit int. Add explicit casts to OLED_BLOCK_TYPE to those shifts.
3 years ago
OLED driver fixes (#10377) * Fix dirtying in oled_write_pixel() Set the dirty bit for the block only if oled_write_pixel() actually changed the buffer state. Without this check oled_write_pixel() could not be used inside the oled_task_user() code using the “redraw always” style, because the blocks touched by oled_write_pixel() would always appear dirty, and oled_render() would not proceed beyond the first such dirty block. * Fix oled_write_pixel() with 90/270 degree rotation Use oled_rotation_width instead of OLED_DISPLAY_WIDTH, so that a rotated display would be handled correctly. * Fix compilation with custom OLED_BLOCK_COUNT and OLED_BLOCK_SIZE Some OLED sizes (e.g., 64×48) may require a nonstandard value of OLED_BLOCK_COUNT. The documentation says that this value may be redefined in config.h, but actually trying to redefine it caused a compile error, because the macro was redefined in oled_driver.c. Make the OLED_BLOCK_COUNT definition in oled_driver.c respect any user override, and do the same for OLED_BLOCK_SIZE just in case. * Fix handling of out-of-range bits in oled_dirty If a custom OLED_BLOCK_COUNT value is specified, some bits in oled_dirty may not correspond to existing blocks; however, if those bits are set somewhere (e.g., by code with sets oled_dirty to ~0 or even -1), oled_render() would try to handle them and could access memory beyond oled_buffer and perform hardware operations with out of range values. Prevent this by masking off unused bits in oled_render(), and also avoid setting those bits in other functions. * Fix potentially wrong dirtying in oled_write_char() oled_write_char() tried to mark the position just beyond the written character as dirty; use (OLED_FONT_WIDTH - 1) to dirty the last position still belonging to the character instead. * Fix `#define OLED_BLOCK_TYPE uint32_t` on AVR Using uint32_t as OLED_BLOCK_TYPE did not work properly on AVR, because some bit shifts were performed using 16-bit int. Add explicit casts to OLED_BLOCK_TYPE to those shifts.
3 years ago
OLED driver fixes (#10377) * Fix dirtying in oled_write_pixel() Set the dirty bit for the block only if oled_write_pixel() actually changed the buffer state. Without this check oled_write_pixel() could not be used inside the oled_task_user() code using the “redraw always” style, because the blocks touched by oled_write_pixel() would always appear dirty, and oled_render() would not proceed beyond the first such dirty block. * Fix oled_write_pixel() with 90/270 degree rotation Use oled_rotation_width instead of OLED_DISPLAY_WIDTH, so that a rotated display would be handled correctly. * Fix compilation with custom OLED_BLOCK_COUNT and OLED_BLOCK_SIZE Some OLED sizes (e.g., 64×48) may require a nonstandard value of OLED_BLOCK_COUNT. The documentation says that this value may be redefined in config.h, but actually trying to redefine it caused a compile error, because the macro was redefined in oled_driver.c. Make the OLED_BLOCK_COUNT definition in oled_driver.c respect any user override, and do the same for OLED_BLOCK_SIZE just in case. * Fix handling of out-of-range bits in oled_dirty If a custom OLED_BLOCK_COUNT value is specified, some bits in oled_dirty may not correspond to existing blocks; however, if those bits are set somewhere (e.g., by code with sets oled_dirty to ~0 or even -1), oled_render() would try to handle them and could access memory beyond oled_buffer and perform hardware operations with out of range values. Prevent this by masking off unused bits in oled_render(), and also avoid setting those bits in other functions. * Fix potentially wrong dirtying in oled_write_char() oled_write_char() tried to mark the position just beyond the written character as dirty; use (OLED_FONT_WIDTH - 1) to dirty the last position still belonging to the character instead. * Fix `#define OLED_BLOCK_TYPE uint32_t` on AVR Using uint32_t as OLED_BLOCK_TYPE did not work properly on AVR, because some bit shifts were performed using 16-bit int. Add explicit casts to OLED_BLOCK_TYPE to those shifts.
3 years ago
OLED driver fixes (#10377) * Fix dirtying in oled_write_pixel() Set the dirty bit for the block only if oled_write_pixel() actually changed the buffer state. Without this check oled_write_pixel() could not be used inside the oled_task_user() code using the “redraw always” style, because the blocks touched by oled_write_pixel() would always appear dirty, and oled_render() would not proceed beyond the first such dirty block. * Fix oled_write_pixel() with 90/270 degree rotation Use oled_rotation_width instead of OLED_DISPLAY_WIDTH, so that a rotated display would be handled correctly. * Fix compilation with custom OLED_BLOCK_COUNT and OLED_BLOCK_SIZE Some OLED sizes (e.g., 64×48) may require a nonstandard value of OLED_BLOCK_COUNT. The documentation says that this value may be redefined in config.h, but actually trying to redefine it caused a compile error, because the macro was redefined in oled_driver.c. Make the OLED_BLOCK_COUNT definition in oled_driver.c respect any user override, and do the same for OLED_BLOCK_SIZE just in case. * Fix handling of out-of-range bits in oled_dirty If a custom OLED_BLOCK_COUNT value is specified, some bits in oled_dirty may not correspond to existing blocks; however, if those bits are set somewhere (e.g., by code with sets oled_dirty to ~0 or even -1), oled_render() would try to handle them and could access memory beyond oled_buffer and perform hardware operations with out of range values. Prevent this by masking off unused bits in oled_render(), and also avoid setting those bits in other functions. * Fix potentially wrong dirtying in oled_write_char() oled_write_char() tried to mark the position just beyond the written character as dirty; use (OLED_FONT_WIDTH - 1) to dirty the last position still belonging to the character instead. * Fix `#define OLED_BLOCK_TYPE uint32_t` on AVR Using uint32_t as OLED_BLOCK_TYPE did not work properly on AVR, because some bit shifts were performed using 16-bit int. Add explicit casts to OLED_BLOCK_TYPE to those shifts.
3 years ago
OLED driver fixes (#10377) * Fix dirtying in oled_write_pixel() Set the dirty bit for the block only if oled_write_pixel() actually changed the buffer state. Without this check oled_write_pixel() could not be used inside the oled_task_user() code using the “redraw always” style, because the blocks touched by oled_write_pixel() would always appear dirty, and oled_render() would not proceed beyond the first such dirty block. * Fix oled_write_pixel() with 90/270 degree rotation Use oled_rotation_width instead of OLED_DISPLAY_WIDTH, so that a rotated display would be handled correctly. * Fix compilation with custom OLED_BLOCK_COUNT and OLED_BLOCK_SIZE Some OLED sizes (e.g., 64×48) may require a nonstandard value of OLED_BLOCK_COUNT. The documentation says that this value may be redefined in config.h, but actually trying to redefine it caused a compile error, because the macro was redefined in oled_driver.c. Make the OLED_BLOCK_COUNT definition in oled_driver.c respect any user override, and do the same for OLED_BLOCK_SIZE just in case. * Fix handling of out-of-range bits in oled_dirty If a custom OLED_BLOCK_COUNT value is specified, some bits in oled_dirty may not correspond to existing blocks; however, if those bits are set somewhere (e.g., by code with sets oled_dirty to ~0 or even -1), oled_render() would try to handle them and could access memory beyond oled_buffer and perform hardware operations with out of range values. Prevent this by masking off unused bits in oled_render(), and also avoid setting those bits in other functions. * Fix potentially wrong dirtying in oled_write_char() oled_write_char() tried to mark the position just beyond the written character as dirty; use (OLED_FONT_WIDTH - 1) to dirty the last position still belonging to the character instead. * Fix `#define OLED_BLOCK_TYPE uint32_t` on AVR Using uint32_t as OLED_BLOCK_TYPE did not work properly on AVR, because some bit shifts were performed using 16-bit int. Add explicit casts to OLED_BLOCK_TYPE to those shifts.
3 years ago
OLED driver fixes (#10377) * Fix dirtying in oled_write_pixel() Set the dirty bit for the block only if oled_write_pixel() actually changed the buffer state. Without this check oled_write_pixel() could not be used inside the oled_task_user() code using the “redraw always” style, because the blocks touched by oled_write_pixel() would always appear dirty, and oled_render() would not proceed beyond the first such dirty block. * Fix oled_write_pixel() with 90/270 degree rotation Use oled_rotation_width instead of OLED_DISPLAY_WIDTH, so that a rotated display would be handled correctly. * Fix compilation with custom OLED_BLOCK_COUNT and OLED_BLOCK_SIZE Some OLED sizes (e.g., 64×48) may require a nonstandard value of OLED_BLOCK_COUNT. The documentation says that this value may be redefined in config.h, but actually trying to redefine it caused a compile error, because the macro was redefined in oled_driver.c. Make the OLED_BLOCK_COUNT definition in oled_driver.c respect any user override, and do the same for OLED_BLOCK_SIZE just in case. * Fix handling of out-of-range bits in oled_dirty If a custom OLED_BLOCK_COUNT value is specified, some bits in oled_dirty may not correspond to existing blocks; however, if those bits are set somewhere (e.g., by code with sets oled_dirty to ~0 or even -1), oled_render() would try to handle them and could access memory beyond oled_buffer and perform hardware operations with out of range values. Prevent this by masking off unused bits in oled_render(), and also avoid setting those bits in other functions. * Fix potentially wrong dirtying in oled_write_char() oled_write_char() tried to mark the position just beyond the written character as dirty; use (OLED_FONT_WIDTH - 1) to dirty the last position still belonging to the character instead. * Fix `#define OLED_BLOCK_TYPE uint32_t` on AVR Using uint32_t as OLED_BLOCK_TYPE did not work properly on AVR, because some bit shifts were performed using 16-bit int. Add explicit casts to OLED_BLOCK_TYPE to those shifts.
3 years ago
OLED driver fixes (#10377) * Fix dirtying in oled_write_pixel() Set the dirty bit for the block only if oled_write_pixel() actually changed the buffer state. Without this check oled_write_pixel() could not be used inside the oled_task_user() code using the “redraw always” style, because the blocks touched by oled_write_pixel() would always appear dirty, and oled_render() would not proceed beyond the first such dirty block. * Fix oled_write_pixel() with 90/270 degree rotation Use oled_rotation_width instead of OLED_DISPLAY_WIDTH, so that a rotated display would be handled correctly. * Fix compilation with custom OLED_BLOCK_COUNT and OLED_BLOCK_SIZE Some OLED sizes (e.g., 64×48) may require a nonstandard value of OLED_BLOCK_COUNT. The documentation says that this value may be redefined in config.h, but actually trying to redefine it caused a compile error, because the macro was redefined in oled_driver.c. Make the OLED_BLOCK_COUNT definition in oled_driver.c respect any user override, and do the same for OLED_BLOCK_SIZE just in case. * Fix handling of out-of-range bits in oled_dirty If a custom OLED_BLOCK_COUNT value is specified, some bits in oled_dirty may not correspond to existing blocks; however, if those bits are set somewhere (e.g., by code with sets oled_dirty to ~0 or even -1), oled_render() would try to handle them and could access memory beyond oled_buffer and perform hardware operations with out of range values. Prevent this by masking off unused bits in oled_render(), and also avoid setting those bits in other functions. * Fix potentially wrong dirtying in oled_write_char() oled_write_char() tried to mark the position just beyond the written character as dirty; use (OLED_FONT_WIDTH - 1) to dirty the last position still belonging to the character instead. * Fix `#define OLED_BLOCK_TYPE uint32_t` on AVR Using uint32_t as OLED_BLOCK_TYPE did not work properly on AVR, because some bit shifts were performed using 16-bit int. Add explicit casts to OLED_BLOCK_TYPE to those shifts.
3 years ago
OLED driver fixes (#10377) * Fix dirtying in oled_write_pixel() Set the dirty bit for the block only if oled_write_pixel() actually changed the buffer state. Without this check oled_write_pixel() could not be used inside the oled_task_user() code using the “redraw always” style, because the blocks touched by oled_write_pixel() would always appear dirty, and oled_render() would not proceed beyond the first such dirty block. * Fix oled_write_pixel() with 90/270 degree rotation Use oled_rotation_width instead of OLED_DISPLAY_WIDTH, so that a rotated display would be handled correctly. * Fix compilation with custom OLED_BLOCK_COUNT and OLED_BLOCK_SIZE Some OLED sizes (e.g., 64×48) may require a nonstandard value of OLED_BLOCK_COUNT. The documentation says that this value may be redefined in config.h, but actually trying to redefine it caused a compile error, because the macro was redefined in oled_driver.c. Make the OLED_BLOCK_COUNT definition in oled_driver.c respect any user override, and do the same for OLED_BLOCK_SIZE just in case. * Fix handling of out-of-range bits in oled_dirty If a custom OLED_BLOCK_COUNT value is specified, some bits in oled_dirty may not correspond to existing blocks; however, if those bits are set somewhere (e.g., by code with sets oled_dirty to ~0 or even -1), oled_render() would try to handle them and could access memory beyond oled_buffer and perform hardware operations with out of range values. Prevent this by masking off unused bits in oled_render(), and also avoid setting those bits in other functions. * Fix potentially wrong dirtying in oled_write_char() oled_write_char() tried to mark the position just beyond the written character as dirty; use (OLED_FONT_WIDTH - 1) to dirty the last position still belonging to the character instead. * Fix `#define OLED_BLOCK_TYPE uint32_t` on AVR Using uint32_t as OLED_BLOCK_TYPE did not work properly on AVR, because some bit shifts were performed using 16-bit int. Add explicit casts to OLED_BLOCK_TYPE to those shifts.
3 years ago
2020 November 28 Breaking Changes Update (#11053) * Branch point for 2020 November 28 Breaking Change * Remove matrix_col_t to allow MATRIX_ROWS > 32 (#10183) * Add support for soft serial to ATmega32U2 (#10204) * Change MIDI velocity implementation to allow direct control of velocity value (#9940) * Add ability to build a subset of all keyboards based on platform. * Actually use eeprom_driver_init(). * Make bootloader_jump weak for ChibiOS. (#10417) * Joystick 16-bit support (#10439) * Per-encoder resolutions (#10259) * Share button state from mousekey to pointing_device (#10179) * Add hotfix for chibios keyboards not wake (#10088) * Add advanced/efficient RGB Matrix Indicators (#8564) * Naming change. * Support for STM32 GPIOF,G,H,I,J,K (#10206) * Add milc as a dependency and remove the installed milc (#10563) * ChibiOS upgrade: early init conversions (#10214) * ChibiOS upgrade: configuration file migrator (#9952) * Haptic and solenoid cleanup (#9700) * XD75 cleanup (#10524) * OLED display update interval support (#10388) * Add definition based on currently-selected serial driver. (#10716) * New feature: Retro Tapping per key (#10622) * Allow for modification of output RGB values when using rgblight/rgb_matrix. (#10638) * Add housekeeping task callbacks so that keyboards/keymaps are capable of executing code for each main loop iteration. (#10530) * Rescale both ChibiOS and AVR backlighting. * Reduce Helix keyboard build variation (#8669) * Minor change to behavior allowing display updates to continue between task ticks (#10750) * Some GPIO manipulations in matrix.c change to atomic. (#10491) * qmk cformat (#10767) * [Keyboard] Update the Speedo firmware for v3.0 (#10657) * Maartenwut/Maarten namechange to evyd13/Evy (#10274) * [quantum] combine repeated lines of code (#10837) * Add step sequencer feature (#9703) * aeboards/ext65 refactor (#10820) * Refactor xelus/dawn60 for Rev2 later (#10584) * add DEBUG_MATRIX_SCAN_RATE_ENABLE to common_features.mk (#10824) * [Core] Added `add_oneshot_mods` & `del_oneshot_mods` (#10549) * update chibios os usb for the otg driver (#8893) * Remove HD44780 References, Part 4 (#10735) * [Keyboard] Add Valor FRL TKL (+refactor) (#10512) * Fix cursor position bug in oled_write_raw functions (#10800) * Fixup version.h writing when using SKIP_VERSION=yes (#10972) * Allow for certain code in the codebase assuming length of string. (#10974) * Add AT90USB support for serial.c (#10706) * Auto shift: support repeats and early registration (#9826) * Rename ledmatrix.h to match .c file (#7949) * Split RGB_MATRIX_ENABLE into _ENABLE and _DRIVER (#10231) * Split LED_MATRIX_ENABLE into _ENABLE and _DRIVER (#10840) * Merge point for 2020 Nov 28 Breaking Change
3 years ago
OLED driver fixes (#10377) * Fix dirtying in oled_write_pixel() Set the dirty bit for the block only if oled_write_pixel() actually changed the buffer state. Without this check oled_write_pixel() could not be used inside the oled_task_user() code using the “redraw always” style, because the blocks touched by oled_write_pixel() would always appear dirty, and oled_render() would not proceed beyond the first such dirty block. * Fix oled_write_pixel() with 90/270 degree rotation Use oled_rotation_width instead of OLED_DISPLAY_WIDTH, so that a rotated display would be handled correctly. * Fix compilation with custom OLED_BLOCK_COUNT and OLED_BLOCK_SIZE Some OLED sizes (e.g., 64×48) may require a nonstandard value of OLED_BLOCK_COUNT. The documentation says that this value may be redefined in config.h, but actually trying to redefine it caused a compile error, because the macro was redefined in oled_driver.c. Make the OLED_BLOCK_COUNT definition in oled_driver.c respect any user override, and do the same for OLED_BLOCK_SIZE just in case. * Fix handling of out-of-range bits in oled_dirty If a custom OLED_BLOCK_COUNT value is specified, some bits in oled_dirty may not correspond to existing blocks; however, if those bits are set somewhere (e.g., by code with sets oled_dirty to ~0 or even -1), oled_render() would try to handle them and could access memory beyond oled_buffer and perform hardware operations with out of range values. Prevent this by masking off unused bits in oled_render(), and also avoid setting those bits in other functions. * Fix potentially wrong dirtying in oled_write_char() oled_write_char() tried to mark the position just beyond the written character as dirty; use (OLED_FONT_WIDTH - 1) to dirty the last position still belonging to the character instead. * Fix `#define OLED_BLOCK_TYPE uint32_t` on AVR Using uint32_t as OLED_BLOCK_TYPE did not work properly on AVR, because some bit shifts were performed using 16-bit int. Add explicit casts to OLED_BLOCK_TYPE to those shifts.
3 years ago
OLED driver fixes (#10377) * Fix dirtying in oled_write_pixel() Set the dirty bit for the block only if oled_write_pixel() actually changed the buffer state. Without this check oled_write_pixel() could not be used inside the oled_task_user() code using the “redraw always” style, because the blocks touched by oled_write_pixel() would always appear dirty, and oled_render() would not proceed beyond the first such dirty block. * Fix oled_write_pixel() with 90/270 degree rotation Use oled_rotation_width instead of OLED_DISPLAY_WIDTH, so that a rotated display would be handled correctly. * Fix compilation with custom OLED_BLOCK_COUNT and OLED_BLOCK_SIZE Some OLED sizes (e.g., 64×48) may require a nonstandard value of OLED_BLOCK_COUNT. The documentation says that this value may be redefined in config.h, but actually trying to redefine it caused a compile error, because the macro was redefined in oled_driver.c. Make the OLED_BLOCK_COUNT definition in oled_driver.c respect any user override, and do the same for OLED_BLOCK_SIZE just in case. * Fix handling of out-of-range bits in oled_dirty If a custom OLED_BLOCK_COUNT value is specified, some bits in oled_dirty may not correspond to existing blocks; however, if those bits are set somewhere (e.g., by code with sets oled_dirty to ~0 or even -1), oled_render() would try to handle them and could access memory beyond oled_buffer and perform hardware operations with out of range values. Prevent this by masking off unused bits in oled_render(), and also avoid setting those bits in other functions. * Fix potentially wrong dirtying in oled_write_char() oled_write_char() tried to mark the position just beyond the written character as dirty; use (OLED_FONT_WIDTH - 1) to dirty the last position still belonging to the character instead. * Fix `#define OLED_BLOCK_TYPE uint32_t` on AVR Using uint32_t as OLED_BLOCK_TYPE did not work properly on AVR, because some bit shifts were performed using 16-bit int. Add explicit casts to OLED_BLOCK_TYPE to those shifts.
3 years ago
OLED driver fixes (#10377) * Fix dirtying in oled_write_pixel() Set the dirty bit for the block only if oled_write_pixel() actually changed the buffer state. Without this check oled_write_pixel() could not be used inside the oled_task_user() code using the “redraw always” style, because the blocks touched by oled_write_pixel() would always appear dirty, and oled_render() would not proceed beyond the first such dirty block. * Fix oled_write_pixel() with 90/270 degree rotation Use oled_rotation_width instead of OLED_DISPLAY_WIDTH, so that a rotated display would be handled correctly. * Fix compilation with custom OLED_BLOCK_COUNT and OLED_BLOCK_SIZE Some OLED sizes (e.g., 64×48) may require a nonstandard value of OLED_BLOCK_COUNT. The documentation says that this value may be redefined in config.h, but actually trying to redefine it caused a compile error, because the macro was redefined in oled_driver.c. Make the OLED_BLOCK_COUNT definition in oled_driver.c respect any user override, and do the same for OLED_BLOCK_SIZE just in case. * Fix handling of out-of-range bits in oled_dirty If a custom OLED_BLOCK_COUNT value is specified, some bits in oled_dirty may not correspond to existing blocks; however, if those bits are set somewhere (e.g., by code with sets oled_dirty to ~0 or even -1), oled_render() would try to handle them and could access memory beyond oled_buffer and perform hardware operations with out of range values. Prevent this by masking off unused bits in oled_render(), and also avoid setting those bits in other functions. * Fix potentially wrong dirtying in oled_write_char() oled_write_char() tried to mark the position just beyond the written character as dirty; use (OLED_FONT_WIDTH - 1) to dirty the last position still belonging to the character instead. * Fix `#define OLED_BLOCK_TYPE uint32_t` on AVR Using uint32_t as OLED_BLOCK_TYPE did not work properly on AVR, because some bit shifts were performed using 16-bit int. Add explicit casts to OLED_BLOCK_TYPE to those shifts.
3 years ago
OLED driver fixes (#10377) * Fix dirtying in oled_write_pixel() Set the dirty bit for the block only if oled_write_pixel() actually changed the buffer state. Without this check oled_write_pixel() could not be used inside the oled_task_user() code using the “redraw always” style, because the blocks touched by oled_write_pixel() would always appear dirty, and oled_render() would not proceed beyond the first such dirty block. * Fix oled_write_pixel() with 90/270 degree rotation Use oled_rotation_width instead of OLED_DISPLAY_WIDTH, so that a rotated display would be handled correctly. * Fix compilation with custom OLED_BLOCK_COUNT and OLED_BLOCK_SIZE Some OLED sizes (e.g., 64×48) may require a nonstandard value of OLED_BLOCK_COUNT. The documentation says that this value may be redefined in config.h, but actually trying to redefine it caused a compile error, because the macro was redefined in oled_driver.c. Make the OLED_BLOCK_COUNT definition in oled_driver.c respect any user override, and do the same for OLED_BLOCK_SIZE just in case. * Fix handling of out-of-range bits in oled_dirty If a custom OLED_BLOCK_COUNT value is specified, some bits in oled_dirty may not correspond to existing blocks; however, if those bits are set somewhere (e.g., by code with sets oled_dirty to ~0 or even -1), oled_render() would try to handle them and could access memory beyond oled_buffer and perform hardware operations with out of range values. Prevent this by masking off unused bits in oled_render(), and also avoid setting those bits in other functions. * Fix potentially wrong dirtying in oled_write_char() oled_write_char() tried to mark the position just beyond the written character as dirty; use (OLED_FONT_WIDTH - 1) to dirty the last position still belonging to the character instead. * Fix `#define OLED_BLOCK_TYPE uint32_t` on AVR Using uint32_t as OLED_BLOCK_TYPE did not work properly on AVR, because some bit shifts were performed using 16-bit int. Add explicit casts to OLED_BLOCK_TYPE to those shifts.
3 years ago
OLED driver fixes (#10377) * Fix dirtying in oled_write_pixel() Set the dirty bit for the block only if oled_write_pixel() actually changed the buffer state. Without this check oled_write_pixel() could not be used inside the oled_task_user() code using the “redraw always” style, because the blocks touched by oled_write_pixel() would always appear dirty, and oled_render() would not proceed beyond the first such dirty block. * Fix oled_write_pixel() with 90/270 degree rotation Use oled_rotation_width instead of OLED_DISPLAY_WIDTH, so that a rotated display would be handled correctly. * Fix compilation with custom OLED_BLOCK_COUNT and OLED_BLOCK_SIZE Some OLED sizes (e.g., 64×48) may require a nonstandard value of OLED_BLOCK_COUNT. The documentation says that this value may be redefined in config.h, but actually trying to redefine it caused a compile error, because the macro was redefined in oled_driver.c. Make the OLED_BLOCK_COUNT definition in oled_driver.c respect any user override, and do the same for OLED_BLOCK_SIZE just in case. * Fix handling of out-of-range bits in oled_dirty If a custom OLED_BLOCK_COUNT value is specified, some bits in oled_dirty may not correspond to existing blocks; however, if those bits are set somewhere (e.g., by code with sets oled_dirty to ~0 or even -1), oled_render() would try to handle them and could access memory beyond oled_buffer and perform hardware operations with out of range values. Prevent this by masking off unused bits in oled_render(), and also avoid setting those bits in other functions. * Fix potentially wrong dirtying in oled_write_char() oled_write_char() tried to mark the position just beyond the written character as dirty; use (OLED_FONT_WIDTH - 1) to dirty the last position still belonging to the character instead. * Fix `#define OLED_BLOCK_TYPE uint32_t` on AVR Using uint32_t as OLED_BLOCK_TYPE did not work properly on AVR, because some bit shifts were performed using 16-bit int. Add explicit casts to OLED_BLOCK_TYPE to those shifts.
3 years ago
2020 November 28 Breaking Changes Update (#11053) * Branch point for 2020 November 28 Breaking Change * Remove matrix_col_t to allow MATRIX_ROWS > 32 (#10183) * Add support for soft serial to ATmega32U2 (#10204) * Change MIDI velocity implementation to allow direct control of velocity value (#9940) * Add ability to build a subset of all keyboards based on platform. * Actually use eeprom_driver_init(). * Make bootloader_jump weak for ChibiOS. (#10417) * Joystick 16-bit support (#10439) * Per-encoder resolutions (#10259) * Share button state from mousekey to pointing_device (#10179) * Add hotfix for chibios keyboards not wake (#10088) * Add advanced/efficient RGB Matrix Indicators (#8564) * Naming change. * Support for STM32 GPIOF,G,H,I,J,K (#10206) * Add milc as a dependency and remove the installed milc (#10563) * ChibiOS upgrade: early init conversions (#10214) * ChibiOS upgrade: configuration file migrator (#9952) * Haptic and solenoid cleanup (#9700) * XD75 cleanup (#10524) * OLED display update interval support (#10388) * Add definition based on currently-selected serial driver. (#10716) * New feature: Retro Tapping per key (#10622) * Allow for modification of output RGB values when using rgblight/rgb_matrix. (#10638) * Add housekeeping task callbacks so that keyboards/keymaps are capable of executing code for each main loop iteration. (#10530) * Rescale both ChibiOS and AVR backlighting. * Reduce Helix keyboard build variation (#8669) * Minor change to behavior allowing display updates to continue between task ticks (#10750) * Some GPIO manipulations in matrix.c change to atomic. (#10491) * qmk cformat (#10767) * [Keyboard] Update the Speedo firmware for v3.0 (#10657) * Maartenwut/Maarten namechange to evyd13/Evy (#10274) * [quantum] combine repeated lines of code (#10837) * Add step sequencer feature (#9703) * aeboards/ext65 refactor (#10820) * Refactor xelus/dawn60 for Rev2 later (#10584) * add DEBUG_MATRIX_SCAN_RATE_ENABLE to common_features.mk (#10824) * [Core] Added `add_oneshot_mods` & `del_oneshot_mods` (#10549) * update chibios os usb for the otg driver (#8893) * Remove HD44780 References, Part 4 (#10735) * [Keyboard] Add Valor FRL TKL (+refactor) (#10512) * Fix cursor position bug in oled_write_raw functions (#10800) * Fixup version.h writing when using SKIP_VERSION=yes (#10972) * Allow for certain code in the codebase assuming length of string. (#10974) * Add AT90USB support for serial.c (#10706) * Auto shift: support repeats and early registration (#9826) * Rename ledmatrix.h to match .c file (#7949) * Split RGB_MATRIX_ENABLE into _ENABLE and _DRIVER (#10231) * Split LED_MATRIX_ENABLE into _ENABLE and _DRIVER (#10840) * Merge point for 2020 Nov 28 Breaking Change
3 years ago
OLED driver fixes (#10377) * Fix dirtying in oled_write_pixel() Set the dirty bit for the block only if oled_write_pixel() actually changed the buffer state. Without this check oled_write_pixel() could not be used inside the oled_task_user() code using the “redraw always” style, because the blocks touched by oled_write_pixel() would always appear dirty, and oled_render() would not proceed beyond the first such dirty block. * Fix oled_write_pixel() with 90/270 degree rotation Use oled_rotation_width instead of OLED_DISPLAY_WIDTH, so that a rotated display would be handled correctly. * Fix compilation with custom OLED_BLOCK_COUNT and OLED_BLOCK_SIZE Some OLED sizes (e.g., 64×48) may require a nonstandard value of OLED_BLOCK_COUNT. The documentation says that this value may be redefined in config.h, but actually trying to redefine it caused a compile error, because the macro was redefined in oled_driver.c. Make the OLED_BLOCK_COUNT definition in oled_driver.c respect any user override, and do the same for OLED_BLOCK_SIZE just in case. * Fix handling of out-of-range bits in oled_dirty If a custom OLED_BLOCK_COUNT value is specified, some bits in oled_dirty may not correspond to existing blocks; however, if those bits are set somewhere (e.g., by code with sets oled_dirty to ~0 or even -1), oled_render() would try to handle them and could access memory beyond oled_buffer and perform hardware operations with out of range values. Prevent this by masking off unused bits in oled_render(), and also avoid setting those bits in other functions. * Fix potentially wrong dirtying in oled_write_char() oled_write_char() tried to mark the position just beyond the written character as dirty; use (OLED_FONT_WIDTH - 1) to dirty the last position still belonging to the character instead. * Fix `#define OLED_BLOCK_TYPE uint32_t` on AVR Using uint32_t as OLED_BLOCK_TYPE did not work properly on AVR, because some bit shifts were performed using 16-bit int. Add explicit casts to OLED_BLOCK_TYPE to those shifts.
3 years ago
OLED driver fixes (#10377) * Fix dirtying in oled_write_pixel() Set the dirty bit for the block only if oled_write_pixel() actually changed the buffer state. Without this check oled_write_pixel() could not be used inside the oled_task_user() code using the “redraw always” style, because the blocks touched by oled_write_pixel() would always appear dirty, and oled_render() would not proceed beyond the first such dirty block. * Fix oled_write_pixel() with 90/270 degree rotation Use oled_rotation_width instead of OLED_DISPLAY_WIDTH, so that a rotated display would be handled correctly. * Fix compilation with custom OLED_BLOCK_COUNT and OLED_BLOCK_SIZE Some OLED sizes (e.g., 64×48) may require a nonstandard value of OLED_BLOCK_COUNT. The documentation says that this value may be redefined in config.h, but actually trying to redefine it caused a compile error, because the macro was redefined in oled_driver.c. Make the OLED_BLOCK_COUNT definition in oled_driver.c respect any user override, and do the same for OLED_BLOCK_SIZE just in case. * Fix handling of out-of-range bits in oled_dirty If a custom OLED_BLOCK_COUNT value is specified, some bits in oled_dirty may not correspond to existing blocks; however, if those bits are set somewhere (e.g., by code with sets oled_dirty to ~0 or even -1), oled_render() would try to handle them and could access memory beyond oled_buffer and perform hardware operations with out of range values. Prevent this by masking off unused bits in oled_render(), and also avoid setting those bits in other functions. * Fix potentially wrong dirtying in oled_write_char() oled_write_char() tried to mark the position just beyond the written character as dirty; use (OLED_FONT_WIDTH - 1) to dirty the last position still belonging to the character instead. * Fix `#define OLED_BLOCK_TYPE uint32_t` on AVR Using uint32_t as OLED_BLOCK_TYPE did not work properly on AVR, because some bit shifts were performed using 16-bit int. Add explicit casts to OLED_BLOCK_TYPE to those shifts.
3 years ago
2020 November 28 Breaking Changes Update (#11053) * Branch point for 2020 November 28 Breaking Change * Remove matrix_col_t to allow MATRIX_ROWS > 32 (#10183) * Add support for soft serial to ATmega32U2 (#10204) * Change MIDI velocity implementation to allow direct control of velocity value (#9940) * Add ability to build a subset of all keyboards based on platform. * Actually use eeprom_driver_init(). * Make bootloader_jump weak for ChibiOS. (#10417) * Joystick 16-bit support (#10439) * Per-encoder resolutions (#10259) * Share button state from mousekey to pointing_device (#10179) * Add hotfix for chibios keyboards not wake (#10088) * Add advanced/efficient RGB Matrix Indicators (#8564) * Naming change. * Support for STM32 GPIOF,G,H,I,J,K (#10206) * Add milc as a dependency and remove the installed milc (#10563) * ChibiOS upgrade: early init conversions (#10214) * ChibiOS upgrade: configuration file migrator (#9952) * Haptic and solenoid cleanup (#9700) * XD75 cleanup (#10524) * OLED display update interval support (#10388) * Add definition based on currently-selected serial driver. (#10716) * New feature: Retro Tapping per key (#10622) * Allow for modification of output RGB values when using rgblight/rgb_matrix. (#10638) * Add housekeeping task callbacks so that keyboards/keymaps are capable of executing code for each main loop iteration. (#10530) * Rescale both ChibiOS and AVR backlighting. * Reduce Helix keyboard build variation (#8669) * Minor change to behavior allowing display updates to continue between task ticks (#10750) * Some GPIO manipulations in matrix.c change to atomic. (#10491) * qmk cformat (#10767) * [Keyboard] Update the Speedo firmware for v3.0 (#10657) * Maartenwut/Maarten namechange to evyd13/Evy (#10274) * [quantum] combine repeated lines of code (#10837) * Add step sequencer feature (#9703) * aeboards/ext65 refactor (#10820) * Refactor xelus/dawn60 for Rev2 later (#10584) * add DEBUG_MATRIX_SCAN_RATE_ENABLE to common_features.mk (#10824) * [Core] Added `add_oneshot_mods` & `del_oneshot_mods` (#10549) * update chibios os usb for the otg driver (#8893) * Remove HD44780 References, Part 4 (#10735) * [Keyboard] Add Valor FRL TKL (+refactor) (#10512) * Fix cursor position bug in oled_write_raw functions (#10800) * Fixup version.h writing when using SKIP_VERSION=yes (#10972) * Allow for certain code in the codebase assuming length of string. (#10974) * Add AT90USB support for serial.c (#10706) * Auto shift: support repeats and early registration (#9826) * Rename ledmatrix.h to match .c file (#7949) * Split RGB_MATRIX_ENABLE into _ENABLE and _DRIVER (#10231) * Split LED_MATRIX_ENABLE into _ENABLE and _DRIVER (#10840) * Merge point for 2020 Nov 28 Breaking Change
3 years ago
2020 November 28 Breaking Changes Update (#11053) * Branch point for 2020 November 28 Breaking Change * Remove matrix_col_t to allow MATRIX_ROWS > 32 (#10183) * Add support for soft serial to ATmega32U2 (#10204) * Change MIDI velocity implementation to allow direct control of velocity value (#9940) * Add ability to build a subset of all keyboards based on platform. * Actually use eeprom_driver_init(). * Make bootloader_jump weak for ChibiOS. (#10417) * Joystick 16-bit support (#10439) * Per-encoder resolutions (#10259) * Share button state from mousekey to pointing_device (#10179) * Add hotfix for chibios keyboards not wake (#10088) * Add advanced/efficient RGB Matrix Indicators (#8564) * Naming change. * Support for STM32 GPIOF,G,H,I,J,K (#10206) * Add milc as a dependency and remove the installed milc (#10563) * ChibiOS upgrade: early init conversions (#10214) * ChibiOS upgrade: configuration file migrator (#9952) * Haptic and solenoid cleanup (#9700) * XD75 cleanup (#10524) * OLED display update interval support (#10388) * Add definition based on currently-selected serial driver. (#10716) * New feature: Retro Tapping per key (#10622) * Allow for modification of output RGB values when using rgblight/rgb_matrix. (#10638) * Add housekeeping task callbacks so that keyboards/keymaps are capable of executing code for each main loop iteration. (#10530) * Rescale both ChibiOS and AVR backlighting. * Reduce Helix keyboard build variation (#8669) * Minor change to behavior allowing display updates to continue between task ticks (#10750) * Some GPIO manipulations in matrix.c change to atomic. (#10491) * qmk cformat (#10767) * [Keyboard] Update the Speedo firmware for v3.0 (#10657) * Maartenwut/Maarten namechange to evyd13/Evy (#10274) * [quantum] combine repeated lines of code (#10837) * Add step sequencer feature (#9703) * aeboards/ext65 refactor (#10820) * Refactor xelus/dawn60 for Rev2 later (#10584) * add DEBUG_MATRIX_SCAN_RATE_ENABLE to common_features.mk (#10824) * [Core] Added `add_oneshot_mods` & `del_oneshot_mods` (#10549) * update chibios os usb for the otg driver (#8893) * Remove HD44780 References, Part 4 (#10735) * [Keyboard] Add Valor FRL TKL (+refactor) (#10512) * Fix cursor position bug in oled_write_raw functions (#10800) * Fixup version.h writing when using SKIP_VERSION=yes (#10972) * Allow for certain code in the codebase assuming length of string. (#10974) * Add AT90USB support for serial.c (#10706) * Auto shift: support repeats and early registration (#9826) * Rename ledmatrix.h to match .c file (#7949) * Split RGB_MATRIX_ENABLE into _ENABLE and _DRIVER (#10231) * Split LED_MATRIX_ENABLE into _ENABLE and _DRIVER (#10840) * Merge point for 2020 Nov 28 Breaking Change
3 years ago
  1. /*
  2. Copyright 2019 Ryan Caltabiano <https://github.com/XScorpion2>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "i2c_master.h"
  15. #include "oled_driver.h"
  16. #include OLED_FONT_H
  17. #include "timer.h"
  18. #include "print.h"
  19. #include <string.h>
  20. #include "progmem.h"
  21. // Used commands from spec sheet: https://cdn-shop.adafruit.com/datasheets/SSD1306.pdf
  22. // for SH1106: https://www.velleman.eu/downloads/29/infosheets/sh1106_datasheet.pdf
  23. // Fundamental Commands
  24. #define CONTRAST 0x81
  25. #define DISPLAY_ALL_ON 0xA5
  26. #define DISPLAY_ALL_ON_RESUME 0xA4
  27. #define NORMAL_DISPLAY 0xA6
  28. #define DISPLAY_ON 0xAF
  29. #define DISPLAY_OFF 0xAE
  30. #define NOP 0xE3
  31. // Scrolling Commands
  32. #define ACTIVATE_SCROLL 0x2F
  33. #define DEACTIVATE_SCROLL 0x2E
  34. #define SCROLL_RIGHT 0x26
  35. #define SCROLL_LEFT 0x27
  36. #define SCROLL_RIGHT_UP 0x29
  37. #define SCROLL_LEFT_UP 0x2A
  38. // Addressing Setting Commands
  39. #define MEMORY_MODE 0x20
  40. #define COLUMN_ADDR 0x21
  41. #define PAGE_ADDR 0x22
  42. #define PAM_SETCOLUMN_LSB 0x00
  43. #define PAM_SETCOLUMN_MSB 0x10
  44. #define PAM_PAGE_ADDR 0xB0 // 0xb0 -- 0xb7
  45. // Hardware Configuration Commands
  46. #define DISPLAY_START_LINE 0x40
  47. #define SEGMENT_REMAP 0xA0
  48. #define SEGMENT_REMAP_INV 0xA1
  49. #define MULTIPLEX_RATIO 0xA8
  50. #define COM_SCAN_INC 0xC0
  51. #define COM_SCAN_DEC 0xC8
  52. #define DISPLAY_OFFSET 0xD3
  53. #define COM_PINS 0xDA
  54. #define COM_PINS_SEQ 0x02
  55. #define COM_PINS_ALT 0x12
  56. #define COM_PINS_SEQ_LR 0x22
  57. #define COM_PINS_ALT_LR 0x32
  58. // Timing & Driving Commands
  59. #define DISPLAY_CLOCK 0xD5
  60. #define PRE_CHARGE_PERIOD 0xD9
  61. #define VCOM_DETECT 0xDB
  62. // Charge Pump Commands
  63. #define CHARGE_PUMP 0x8D
  64. // Misc defines
  65. #ifndef OLED_BLOCK_COUNT
  66. # define OLED_BLOCK_COUNT (sizeof(OLED_BLOCK_TYPE) * 8)
  67. #endif
  68. #ifndef OLED_BLOCK_SIZE
  69. # define OLED_BLOCK_SIZE (OLED_MATRIX_SIZE / OLED_BLOCK_COUNT)
  70. #endif
  71. #define OLED_ALL_BLOCKS_MASK (((((OLED_BLOCK_TYPE)1 << (OLED_BLOCK_COUNT - 1)) - 1) << 1) | 1)
  72. // i2c defines
  73. #define I2C_CMD 0x00
  74. #define I2C_DATA 0x40
  75. #if defined(__AVR__)
  76. # define I2C_TRANSMIT_P(data) i2c_transmit_P((OLED_DISPLAY_ADDRESS << 1), &data[0], sizeof(data), OLED_I2C_TIMEOUT)
  77. #else // defined(__AVR__)
  78. # define I2C_TRANSMIT_P(data) i2c_transmit((OLED_DISPLAY_ADDRESS << 1), &data[0], sizeof(data), OLED_I2C_TIMEOUT)
  79. #endif // defined(__AVR__)
  80. #define I2C_TRANSMIT(data) i2c_transmit((OLED_DISPLAY_ADDRESS << 1), &data[0], sizeof(data), OLED_I2C_TIMEOUT)
  81. #define I2C_WRITE_REG(mode, data, size) i2c_writeReg((OLED_DISPLAY_ADDRESS << 1), mode, data, size, OLED_I2C_TIMEOUT)
  82. #define HAS_FLAGS(bits, flags) ((bits & flags) == flags)
  83. // Display buffer's is the same as the OLED memory layout
  84. // this is so we don't end up with rounding errors with
  85. // parts of the display unusable or don't get cleared correctly
  86. // and also allows for drawing & inverting
  87. uint8_t oled_buffer[OLED_MATRIX_SIZE];
  88. uint8_t * oled_cursor;
  89. OLED_BLOCK_TYPE oled_dirty = 0;
  90. bool oled_initialized = false;
  91. bool oled_active = false;
  92. bool oled_scrolling = false;
  93. uint8_t oled_brightness = OLED_BRIGHTNESS;
  94. uint8_t oled_rotation = 0;
  95. uint8_t oled_rotation_width = 0;
  96. uint8_t oled_scroll_speed = 0; // this holds the speed after being remapped to ssd1306 internal values
  97. uint8_t oled_scroll_start = 0;
  98. uint8_t oled_scroll_end = 7;
  99. #if OLED_TIMEOUT > 0
  100. uint32_t oled_timeout;
  101. #endif
  102. #if OLED_SCROLL_TIMEOUT > 0
  103. uint32_t oled_scroll_timeout;
  104. #endif
  105. #if OLED_UPDATE_INTERVAL > 0
  106. uint16_t oled_update_timeout;
  107. #endif
  108. // Internal variables to reduce math instructions
  109. #if defined(__AVR__)
  110. // identical to i2c_transmit, but for PROGMEM since all initialization is in PROGMEM arrays currently
  111. // probably should move this into i2c_master...
  112. static i2c_status_t i2c_transmit_P(uint8_t address, const uint8_t *data, uint16_t length, uint16_t timeout) {
  113. i2c_status_t status = i2c_start(address | I2C_WRITE, timeout);
  114. for (uint16_t i = 0; i < length && status >= 0; i++) {
  115. status = i2c_write(pgm_read_byte((const char *)data++), timeout);
  116. if (status) break;
  117. }
  118. i2c_stop();
  119. return status;
  120. }
  121. #endif
  122. // Flips the rendering bits for a character at the current cursor position
  123. static void InvertCharacter(uint8_t *cursor) {
  124. const uint8_t *end = cursor + OLED_FONT_WIDTH;
  125. while (cursor < end) {
  126. *cursor = ~(*cursor);
  127. cursor++;
  128. }
  129. }
  130. bool oled_init(uint8_t rotation) {
  131. oled_rotation = oled_init_user(rotation);
  132. if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) {
  133. oled_rotation_width = OLED_DISPLAY_WIDTH;
  134. } else {
  135. oled_rotation_width = OLED_DISPLAY_HEIGHT;
  136. }
  137. i2c_init();
  138. static const uint8_t PROGMEM display_setup1[] = {
  139. I2C_CMD,
  140. DISPLAY_OFF,
  141. DISPLAY_CLOCK,
  142. 0x80,
  143. MULTIPLEX_RATIO,
  144. OLED_DISPLAY_HEIGHT - 1,
  145. DISPLAY_OFFSET,
  146. 0x00,
  147. DISPLAY_START_LINE | 0x00,
  148. CHARGE_PUMP,
  149. 0x14,
  150. #if (OLED_IC != OLED_IC_SH1106)
  151. // MEMORY_MODE is unsupported on SH1106 (Page Addressing only)
  152. MEMORY_MODE,
  153. 0x00, // Horizontal addressing mode
  154. #endif
  155. };
  156. if (I2C_TRANSMIT_P(display_setup1) != I2C_STATUS_SUCCESS) {
  157. print("oled_init cmd set 1 failed\n");
  158. return false;
  159. }
  160. if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_180)) {
  161. static const uint8_t PROGMEM display_normal[] = {I2C_CMD, SEGMENT_REMAP_INV, COM_SCAN_DEC};
  162. if (I2C_TRANSMIT_P(display_normal) != I2C_STATUS_SUCCESS) {
  163. print("oled_init cmd normal rotation failed\n");
  164. return false;
  165. }
  166. } else {
  167. static const uint8_t PROGMEM display_flipped[] = {I2C_CMD, SEGMENT_REMAP, COM_SCAN_INC};
  168. if (I2C_TRANSMIT_P(display_flipped) != I2C_STATUS_SUCCESS) {
  169. print("display_flipped failed\n");
  170. return false;
  171. }
  172. }
  173. static const uint8_t PROGMEM display_setup2[] = {I2C_CMD, COM_PINS, OLED_COM_PINS, CONTRAST, OLED_BRIGHTNESS, PRE_CHARGE_PERIOD, 0xF1, VCOM_DETECT, 0x20, DISPLAY_ALL_ON_RESUME, NORMAL_DISPLAY, DEACTIVATE_SCROLL, DISPLAY_ON};
  174. if (I2C_TRANSMIT_P(display_setup2) != I2C_STATUS_SUCCESS) {
  175. print("display_setup2 failed\n");
  176. return false;
  177. }
  178. #if OLED_TIMEOUT > 0
  179. oled_timeout = timer_read32() + OLED_TIMEOUT;
  180. #endif
  181. #if OLED_SCROLL_TIMEOUT > 0
  182. oled_scroll_timeout = timer_read32() + OLED_SCROLL_TIMEOUT;
  183. #endif
  184. oled_clear();
  185. oled_initialized = true;
  186. oled_active = true;
  187. oled_scrolling = false;
  188. return true;
  189. }
  190. __attribute__((weak)) oled_rotation_t oled_init_user(oled_rotation_t rotation) { return rotation; }
  191. void oled_clear(void) {
  192. memset(oled_buffer, 0, sizeof(oled_buffer));
  193. oled_cursor = &oled_buffer[0];
  194. oled_dirty = OLED_ALL_BLOCKS_MASK;
  195. }
  196. static void calc_bounds(uint8_t update_start, uint8_t *cmd_array) {
  197. // Calculate commands to set memory addressing bounds.
  198. uint8_t start_page = OLED_BLOCK_SIZE * update_start / OLED_DISPLAY_WIDTH;
  199. uint8_t start_column = OLED_BLOCK_SIZE * update_start % OLED_DISPLAY_WIDTH;
  200. #if (OLED_IC == OLED_IC_SH1106)
  201. // Commands for Page Addressing Mode. Sets starting page and column; has no end bound.
  202. // Column value must be split into high and low nybble and sent as two commands.
  203. cmd_array[0] = PAM_PAGE_ADDR | start_page;
  204. cmd_array[1] = PAM_SETCOLUMN_LSB | ((OLED_COLUMN_OFFSET + start_column) & 0x0f);
  205. cmd_array[2] = PAM_SETCOLUMN_MSB | ((OLED_COLUMN_OFFSET + start_column) >> 4 & 0x0f);
  206. cmd_array[3] = NOP;
  207. cmd_array[4] = NOP;
  208. cmd_array[5] = NOP;
  209. #else
  210. // Commands for use in Horizontal Addressing mode.
  211. cmd_array[1] = start_column;
  212. cmd_array[4] = start_page;
  213. cmd_array[2] = (OLED_BLOCK_SIZE + OLED_DISPLAY_WIDTH - 1) % OLED_DISPLAY_WIDTH + cmd_array[1];
  214. cmd_array[5] = (OLED_BLOCK_SIZE + OLED_DISPLAY_WIDTH - 1) / OLED_DISPLAY_WIDTH - 1;
  215. #endif
  216. }
  217. static void calc_bounds_90(uint8_t update_start, uint8_t *cmd_array) {
  218. cmd_array[1] = OLED_BLOCK_SIZE * update_start / OLED_DISPLAY_HEIGHT * 8;
  219. cmd_array[4] = OLED_BLOCK_SIZE * update_start % OLED_DISPLAY_HEIGHT;
  220. cmd_array[2] = (OLED_BLOCK_SIZE + OLED_DISPLAY_HEIGHT - 1) / OLED_DISPLAY_HEIGHT * 8 - 1 + cmd_array[1];
  221. ;
  222. cmd_array[5] = (OLED_BLOCK_SIZE + OLED_DISPLAY_HEIGHT - 1) % OLED_DISPLAY_HEIGHT / 8;
  223. }
  224. uint8_t crot(uint8_t a, int8_t n) {
  225. const uint8_t mask = 0x7;
  226. n &= mask;
  227. return a << n | a >> (-n & mask);
  228. }
  229. static void rotate_90(const uint8_t *src, uint8_t *dest) {
  230. for (uint8_t i = 0, shift = 7; i < 8; ++i, --shift) {
  231. uint8_t selector = (1 << i);
  232. for (uint8_t j = 0; j < 8; ++j) {
  233. dest[i] |= crot(src[j] & selector, shift - (int8_t)j);
  234. }
  235. }
  236. }
  237. void oled_render(void) {
  238. // Do we have work to do?
  239. oled_dirty &= OLED_ALL_BLOCKS_MASK;
  240. if (!oled_dirty || oled_scrolling) {
  241. return;
  242. }
  243. // Find first dirty block
  244. uint8_t update_start = 0;
  245. while (!(oled_dirty & ((OLED_BLOCK_TYPE)1 << update_start))) {
  246. ++update_start;
  247. }
  248. // Set column & page position
  249. static uint8_t display_start[] = {I2C_CMD, COLUMN_ADDR, 0, OLED_DISPLAY_WIDTH - 1, PAGE_ADDR, 0, OLED_DISPLAY_HEIGHT / 8 - 1};
  250. if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) {
  251. calc_bounds(update_start, &display_start[1]); // Offset from I2C_CMD byte at the start
  252. } else {
  253. calc_bounds_90(update_start, &display_start[1]); // Offset from I2C_CMD byte at the start
  254. }
  255. // Send column & page position
  256. if (I2C_TRANSMIT(display_start) != I2C_STATUS_SUCCESS) {
  257. print("oled_render offset command failed\n");
  258. return;
  259. }
  260. if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) {
  261. // Send render data chunk as is
  262. if (I2C_WRITE_REG(I2C_DATA, &oled_buffer[OLED_BLOCK_SIZE * update_start], OLED_BLOCK_SIZE) != I2C_STATUS_SUCCESS) {
  263. print("oled_render data failed\n");
  264. return;
  265. }
  266. } else {
  267. // Rotate the render chunks
  268. const static uint8_t source_map[] = OLED_SOURCE_MAP;
  269. const static uint8_t target_map[] = OLED_TARGET_MAP;
  270. static uint8_t temp_buffer[OLED_BLOCK_SIZE];
  271. memset(temp_buffer, 0, sizeof(temp_buffer));
  272. for (uint8_t i = 0; i < sizeof(source_map); ++i) {
  273. rotate_90(&oled_buffer[OLED_BLOCK_SIZE * update_start + source_map[i]], &temp_buffer[target_map[i]]);
  274. }
  275. // Send render data chunk after rotating
  276. if (I2C_WRITE_REG(I2C_DATA, &temp_buffer[0], OLED_BLOCK_SIZE) != I2C_STATUS_SUCCESS) {
  277. print("oled_render90 data failed\n");
  278. return;
  279. }
  280. }
  281. // Turn on display if it is off
  282. oled_on();
  283. // Clear dirty flag
  284. oled_dirty &= ~((OLED_BLOCK_TYPE)1 << update_start);
  285. }
  286. void oled_set_cursor(uint8_t col, uint8_t line) {
  287. uint16_t index = line * oled_rotation_width + col * OLED_FONT_WIDTH;
  288. // Out of bounds?
  289. if (index >= OLED_MATRIX_SIZE) {
  290. index = 0;
  291. }
  292. oled_cursor = &oled_buffer[index];
  293. }
  294. void oled_advance_page(bool clearPageRemainder) {
  295. uint16_t index = oled_cursor - &oled_buffer[0];
  296. uint8_t remaining = oled_rotation_width - (index % oled_rotation_width);
  297. if (clearPageRemainder) {
  298. // Remaining Char count
  299. remaining = remaining / OLED_FONT_WIDTH;
  300. // Write empty character until next line
  301. while (remaining--) oled_write_char(' ', false);
  302. } else {
  303. // Next page index out of bounds?
  304. if (index + remaining >= OLED_MATRIX_SIZE) {
  305. index = 0;
  306. remaining = 0;
  307. }
  308. oled_cursor = &oled_buffer[index + remaining];
  309. }
  310. }
  311. void oled_advance_char(void) {
  312. uint16_t nextIndex = oled_cursor - &oled_buffer[0] + OLED_FONT_WIDTH;
  313. uint8_t remainingSpace = oled_rotation_width - (nextIndex % oled_rotation_width);
  314. // Do we have enough space on the current line for the next character
  315. if (remainingSpace < OLED_FONT_WIDTH) {
  316. nextIndex += remainingSpace;
  317. }
  318. // Did we go out of bounds
  319. if (nextIndex >= OLED_MATRIX_SIZE) {
  320. nextIndex = 0;
  321. }
  322. // Update cursor position
  323. oled_cursor = &oled_buffer[nextIndex];
  324. }
  325. // Main handler that writes character data to the display buffer
  326. void oled_write_char(const char data, bool invert) {
  327. // Advance to the next line if newline
  328. if (data == '\n') {
  329. // Old source wrote ' ' until end of line...
  330. oled_advance_page(true);
  331. return;
  332. }
  333. if (data == '\r') {
  334. oled_advance_page(false);
  335. return;
  336. }
  337. // copy the current render buffer to check for dirty after
  338. static uint8_t oled_temp_buffer[OLED_FONT_WIDTH];
  339. memcpy(&oled_temp_buffer, oled_cursor, OLED_FONT_WIDTH);
  340. _Static_assert(sizeof(font) >= ((OLED_FONT_END + 1 - OLED_FONT_START) * OLED_FONT_WIDTH), "OLED_FONT_END references outside array");
  341. // set the reder buffer data
  342. uint8_t cast_data = (uint8_t)data; // font based on unsigned type for index
  343. if (cast_data < OLED_FONT_START || cast_data > OLED_FONT_END) {
  344. memset(oled_cursor, 0x00, OLED_FONT_WIDTH);
  345. } else {
  346. const uint8_t *glyph = &font[(cast_data - OLED_FONT_START) * OLED_FONT_WIDTH];
  347. memcpy_P(oled_cursor, glyph, OLED_FONT_WIDTH);
  348. }
  349. // Invert if needed
  350. if (invert) {
  351. InvertCharacter(oled_cursor);
  352. }
  353. // Dirty check
  354. if (memcmp(&oled_temp_buffer, oled_cursor, OLED_FONT_WIDTH)) {
  355. uint16_t index = oled_cursor - &oled_buffer[0];
  356. oled_dirty |= ((OLED_BLOCK_TYPE)1 << (index / OLED_BLOCK_SIZE));
  357. // Edgecase check if the written data spans the 2 chunks
  358. oled_dirty |= ((OLED_BLOCK_TYPE)1 << ((index + OLED_FONT_WIDTH - 1) / OLED_BLOCK_SIZE));
  359. }
  360. // Finally move to the next char
  361. oled_advance_char();
  362. }
  363. void oled_write(const char *data, bool invert) {
  364. const char *end = data + strlen(data);
  365. while (data < end) {
  366. oled_write_char(*data, invert);
  367. data++;
  368. }
  369. }
  370. void oled_write_ln(const char *data, bool invert) {
  371. oled_write(data, invert);
  372. oled_advance_page(true);
  373. }
  374. void oled_pan(bool left) {
  375. uint16_t i = 0;
  376. for (uint16_t y = 0; y < OLED_DISPLAY_HEIGHT / 8; y++) {
  377. if (left) {
  378. for (uint16_t x = 0; x < OLED_DISPLAY_WIDTH - 1; x++) {
  379. i = y * OLED_DISPLAY_WIDTH + x;
  380. oled_buffer[i] = oled_buffer[i + 1];
  381. }
  382. } else {
  383. for (uint16_t x = OLED_DISPLAY_WIDTH - 1; x > 0; x--) {
  384. i = y * OLED_DISPLAY_WIDTH + x;
  385. oled_buffer[i] = oled_buffer[i - 1];
  386. }
  387. }
  388. }
  389. oled_dirty = OLED_ALL_BLOCKS_MASK;
  390. }
  391. oled_buffer_reader_t oled_read_raw(uint16_t start_index) {
  392. if (start_index > OLED_MATRIX_SIZE) start_index = OLED_MATRIX_SIZE;
  393. oled_buffer_reader_t ret_reader;
  394. ret_reader.current_element = &oled_buffer[start_index];
  395. ret_reader.remaining_element_count = OLED_MATRIX_SIZE - start_index;
  396. return ret_reader;
  397. }
  398. void oled_write_raw_byte(const char data, uint16_t index) {
  399. if (index > OLED_MATRIX_SIZE) index = OLED_MATRIX_SIZE;
  400. if (oled_buffer[index] == data) return;
  401. oled_buffer[index] = data;
  402. oled_dirty |= ((OLED_BLOCK_TYPE)1 << (index / OLED_BLOCK_SIZE));
  403. }
  404. void oled_write_raw(const char *data, uint16_t size) {
  405. uint16_t cursor_start_index = oled_cursor - &oled_buffer[0];
  406. if ((size + cursor_start_index) > OLED_MATRIX_SIZE) size = OLED_MATRIX_SIZE - cursor_start_index;
  407. for (uint16_t i = cursor_start_index; i < cursor_start_index + size; i++) {
  408. if (oled_buffer[i] == data[i]) continue;
  409. oled_buffer[i] = data[i];
  410. oled_dirty |= ((OLED_BLOCK_TYPE)1 << (i / OLED_BLOCK_SIZE));
  411. }
  412. }
  413. void oled_write_pixel(uint8_t x, uint8_t y, bool on) {
  414. if (x >= oled_rotation_width) {
  415. return;
  416. }
  417. uint16_t index = x + (y / 8) * oled_rotation_width;
  418. if (index >= OLED_MATRIX_SIZE) {
  419. return;
  420. }
  421. uint8_t data = oled_buffer[index];
  422. if (on) {
  423. data |= (1 << (y % 8));
  424. } else {
  425. data &= ~(1 << (y % 8));
  426. }
  427. if (oled_buffer[index] != data) {
  428. oled_buffer[index] = data;
  429. oled_dirty |= ((OLED_BLOCK_TYPE)1 << (index / OLED_BLOCK_SIZE));
  430. }
  431. }
  432. #if defined(__AVR__)
  433. void oled_write_P(const char *data, bool invert) {
  434. uint8_t c = pgm_read_byte(data);
  435. while (c != 0) {
  436. oled_write_char(c, invert);
  437. c = pgm_read_byte(++data);
  438. }
  439. }
  440. void oled_write_ln_P(const char *data, bool invert) {
  441. oled_write_P(data, invert);
  442. oled_advance_page(true);
  443. }
  444. void oled_write_raw_P(const char *data, uint16_t size) {
  445. uint16_t cursor_start_index = oled_cursor - &oled_buffer[0];
  446. if ((size + cursor_start_index) > OLED_MATRIX_SIZE) size = OLED_MATRIX_SIZE - cursor_start_index;
  447. for (uint16_t i = cursor_start_index; i < cursor_start_index + size; i++) {
  448. uint8_t c = pgm_read_byte(data++);
  449. if (oled_buffer[i] == c) continue;
  450. oled_buffer[i] = c;
  451. oled_dirty |= ((OLED_BLOCK_TYPE)1 << (i / OLED_BLOCK_SIZE));
  452. }
  453. }
  454. #endif // defined(__AVR__)
  455. bool oled_on(void) {
  456. #if OLED_TIMEOUT > 0
  457. oled_timeout = timer_read32() + OLED_TIMEOUT;
  458. #endif
  459. static const uint8_t PROGMEM display_on[] = {I2C_CMD, DISPLAY_ON};
  460. if (!oled_active) {
  461. if (I2C_TRANSMIT_P(display_on) != I2C_STATUS_SUCCESS) {
  462. print("oled_on cmd failed\n");
  463. return oled_active;
  464. }
  465. oled_active = true;
  466. }
  467. return oled_active;
  468. }
  469. bool oled_off(void) {
  470. static const uint8_t PROGMEM display_off[] = {I2C_CMD, DISPLAY_OFF};
  471. if (oled_active) {
  472. if (I2C_TRANSMIT_P(display_off) != I2C_STATUS_SUCCESS) {
  473. print("oled_off cmd failed\n");
  474. return oled_active;
  475. }
  476. oled_active = false;
  477. }
  478. return !oled_active;
  479. }
  480. bool is_oled_on(void) { return oled_active; }
  481. uint8_t oled_set_brightness(uint8_t level) {
  482. uint8_t set_contrast[] = {I2C_CMD, CONTRAST, level};
  483. if (oled_brightness != level) {
  484. if (I2C_TRANSMIT(set_contrast) != I2C_STATUS_SUCCESS) {
  485. print("set_brightness cmd failed\n");
  486. return oled_brightness;
  487. }
  488. oled_brightness = level;
  489. }
  490. return oled_brightness;
  491. }
  492. uint8_t oled_get_brightness(void) { return oled_brightness; }
  493. // Set the specific 8 lines rows of the screen to scroll.
  494. // 0 is the default for start, and 7 for end, which is the entire
  495. // height of the screen. For 128x32 screens, rows 4-7 are not used.
  496. void oled_scroll_set_area(uint8_t start_line, uint8_t end_line) {
  497. oled_scroll_start = start_line;
  498. oled_scroll_end = end_line;
  499. }
  500. void oled_scroll_set_speed(uint8_t speed) {
  501. // Sets the speed for scrolling... does not take effect
  502. // until scrolling is either started or restarted
  503. // the ssd1306 supports 8 speeds
  504. // FrameRate2 speed = 7
  505. // FrameRate3 speed = 4
  506. // FrameRate4 speed = 5
  507. // FrameRate5 speed = 0
  508. // FrameRate25 speed = 6
  509. // FrameRate64 speed = 1
  510. // FrameRate128 speed = 2
  511. // FrameRate256 speed = 3
  512. // for ease of use these are remaped here to be in order
  513. static const uint8_t scroll_remap[8] = {7, 4, 5, 0, 6, 1, 2, 3};
  514. oled_scroll_speed = scroll_remap[speed];
  515. }
  516. bool oled_scroll_right(void) {
  517. // Dont enable scrolling if we need to update the display
  518. // This prevents scrolling of bad data from starting the scroll too early after init
  519. if (!oled_dirty && !oled_scrolling) {
  520. uint8_t display_scroll_right[] = {I2C_CMD, SCROLL_RIGHT, 0x00, oled_scroll_start, oled_scroll_speed, oled_scroll_end, 0x00, 0xFF, ACTIVATE_SCROLL};
  521. if (I2C_TRANSMIT(display_scroll_right) != I2C_STATUS_SUCCESS) {
  522. print("oled_scroll_right cmd failed\n");
  523. return oled_scrolling;
  524. }
  525. oled_scrolling = true;
  526. }
  527. return oled_scrolling;
  528. }
  529. bool oled_scroll_left(void) {
  530. // Dont enable scrolling if we need to update the display
  531. // This prevents scrolling of bad data from starting the scroll too early after init
  532. if (!oled_dirty && !oled_scrolling) {
  533. uint8_t display_scroll_left[] = {I2C_CMD, SCROLL_LEFT, 0x00, oled_scroll_start, oled_scroll_speed, oled_scroll_end, 0x00, 0xFF, ACTIVATE_SCROLL};
  534. if (I2C_TRANSMIT(display_scroll_left) != I2C_STATUS_SUCCESS) {
  535. print("oled_scroll_left cmd failed\n");
  536. return oled_scrolling;
  537. }
  538. oled_scrolling = true;
  539. }
  540. return oled_scrolling;
  541. }
  542. bool oled_scroll_off(void) {
  543. if (oled_scrolling) {
  544. static const uint8_t PROGMEM display_scroll_off[] = {I2C_CMD, DEACTIVATE_SCROLL};
  545. if (I2C_TRANSMIT_P(display_scroll_off) != I2C_STATUS_SUCCESS) {
  546. print("oled_scroll_off cmd failed\n");
  547. return oled_scrolling;
  548. }
  549. oled_scrolling = false;
  550. oled_dirty = OLED_ALL_BLOCKS_MASK;
  551. }
  552. return !oled_scrolling;
  553. }
  554. uint8_t oled_max_chars(void) {
  555. if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) {
  556. return OLED_DISPLAY_WIDTH / OLED_FONT_WIDTH;
  557. }
  558. return OLED_DISPLAY_HEIGHT / OLED_FONT_WIDTH;
  559. }
  560. uint8_t oled_max_lines(void) {
  561. if (!HAS_FLAGS(oled_rotation, OLED_ROTATION_90)) {
  562. return OLED_DISPLAY_HEIGHT / OLED_FONT_HEIGHT;
  563. }
  564. return OLED_DISPLAY_WIDTH / OLED_FONT_HEIGHT;
  565. }
  566. void oled_task(void) {
  567. if (!oled_initialized) {
  568. return;
  569. }
  570. #if OLED_UPDATE_INTERVAL > 0
  571. if (timer_elapsed(oled_update_timeout) >= OLED_UPDATE_INTERVAL) {
  572. oled_update_timeout = timer_read();
  573. oled_set_cursor(0, 0);
  574. oled_task_user();
  575. }
  576. #else
  577. oled_set_cursor(0, 0);
  578. oled_task_user();
  579. #endif
  580. #if OLED_SCROLL_TIMEOUT > 0
  581. if (oled_dirty && oled_scrolling) {
  582. oled_scroll_timeout = timer_read32() + OLED_SCROLL_TIMEOUT;
  583. oled_scroll_off();
  584. }
  585. #endif
  586. // Smart render system, no need to check for dirty
  587. oled_render();
  588. // Display timeout check
  589. #if OLED_TIMEOUT > 0
  590. if (oled_active && timer_expired32(timer_read32(), oled_timeout)) {
  591. oled_off();
  592. }
  593. #endif
  594. #if OLED_SCROLL_TIMEOUT > 0
  595. if (!oled_scrolling && timer_expired32(timer_read32(), oled_scroll_timeout)) {
  596. # ifdef OLED_SCROLL_TIMEOUT_RIGHT
  597. oled_scroll_right();
  598. # else
  599. oled_scroll_left();
  600. # endif
  601. }
  602. #endif
  603. }
  604. __attribute__((weak)) void oled_task_user(void) {}